drivers/bus/ts-nbus.c

Source file repositories/reference/linux-study-clean/drivers/bus/ts-nbus.c

File Facts

System
Linux kernel
Corpus path
drivers/bus/ts-nbus.c
Extension
.c
Size
9014 bytes
Lines
352
Domain
Driver Families
Bucket
drivers/bus
Inferred role
Driver Families: exported/initcall integration point
Status
integration implementation candidate

Why This File Exists

Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.

Dependency Surface

Detected Declarations

Annotated Snippet

struct ts_nbus {
	struct pwm_device *pwm;
	struct gpio_descs *data;
	struct gpio_desc *csn;
	struct gpio_desc *txrx;
	struct gpio_desc *strobe;
	struct gpio_desc *ale;
	struct gpio_desc *rdy;
	struct mutex lock;
};

/*
 * request all gpios required by the bus.
 */
static int ts_nbus_init_pdata(struct platform_device *pdev,
			      struct ts_nbus *ts_nbus)
{
	ts_nbus->data = devm_gpiod_get_array(&pdev->dev, "ts,data",
			GPIOD_OUT_HIGH);
	if (IS_ERR(ts_nbus->data))
		return dev_err_probe(&pdev->dev, PTR_ERR(ts_nbus->data),
				     "failed to retrieve ts,data-gpio from dts\n");

	ts_nbus->csn = devm_gpiod_get(&pdev->dev, "ts,csn", GPIOD_OUT_HIGH);
	if (IS_ERR(ts_nbus->csn))
		return dev_err_probe(&pdev->dev, PTR_ERR(ts_nbus->csn),
			      "failed to retrieve ts,csn-gpio from dts\n");

	ts_nbus->txrx = devm_gpiod_get(&pdev->dev, "ts,txrx", GPIOD_OUT_HIGH);
	if (IS_ERR(ts_nbus->txrx))
		return dev_err_probe(&pdev->dev, PTR_ERR(ts_nbus->txrx),
				     "failed to retrieve ts,txrx-gpio from dts\n");

	ts_nbus->strobe = devm_gpiod_get(&pdev->dev, "ts,strobe", GPIOD_OUT_HIGH);
	if (IS_ERR(ts_nbus->strobe))
		return dev_err_probe(&pdev->dev, PTR_ERR(ts_nbus->strobe),
				     "failed to retrieve ts,strobe-gpio from dts\n");

	ts_nbus->ale = devm_gpiod_get(&pdev->dev, "ts,ale", GPIOD_OUT_HIGH);
	if (IS_ERR(ts_nbus->ale))
		return dev_err_probe(&pdev->dev, PTR_ERR(ts_nbus->ale),
				     "failed to retrieve ts,ale-gpio from dts\n");

	ts_nbus->rdy = devm_gpiod_get(&pdev->dev, "ts,rdy", GPIOD_IN);
	if (IS_ERR(ts_nbus->rdy))
		return dev_err_probe(&pdev->dev, PTR_ERR(ts_nbus->rdy),
				     "failed to retrieve ts,rdy-gpio from dts\n");

	return 0;
}

/*
 * the data gpios are used for reading and writing values, their directions
 * should be adjusted accordingly.
 */
static void ts_nbus_set_direction(struct ts_nbus *ts_nbus, int direction)
{
	int i;

	for (i = 0; i < 8; i++) {
		if (direction == TS_NBUS_DIRECTION_IN)
			gpiod_direction_input(ts_nbus->data->desc[i]);
		else
			/* when used as output the default state of the data
			 * lines are set to high */
			gpiod_direction_output(ts_nbus->data->desc[i], 1);
	}
}

/*
 * reset the bus in its initial state.
 * The data, csn, strobe and ale lines must be zero'ed to let the FPGA knows a
 * new transaction can be process.
 */
static void ts_nbus_reset_bus(struct ts_nbus *ts_nbus)
{
	DECLARE_BITMAP(values, 8);

	values[0] = 0;

	gpiod_set_array_value_cansleep(8, ts_nbus->data->desc,
				       ts_nbus->data->info, values);
	gpiod_set_value_cansleep(ts_nbus->csn, 0);
	gpiod_set_value_cansleep(ts_nbus->strobe, 0);
	gpiod_set_value_cansleep(ts_nbus->ale, 0);
}

/*
 * let the FPGA knows it can process.
 */

Annotation

Implementation Notes