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.
- 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.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/bitops.hlinux/gpio/consumer.hlinux/kernel.hlinux/module.hlinux/mutex.hlinux/of_platform.hlinux/platform_device.hlinux/pwm.hlinux/ts-nbus.h
Detected Declarations
struct ts_nbusfunction ts_nbus_init_pdatafunction ts_nbus_set_directionfunction ts_nbus_reset_busfunction ts_nbus_start_transactionfunction ts_nbus_read_bytefunction ts_nbus_write_bytefunction ts_nbus_read_busfunction commandfunction ts_nbus_readfunction ts_nbus_writefunction ts_nbus_probefunction ts_nbus_removeexport ts_nbus_readexport ts_nbus_write
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
- Immediate include surface: `linux/bitops.h`, `linux/gpio/consumer.h`, `linux/kernel.h`, `linux/module.h`, `linux/mutex.h`, `linux/of_platform.h`, `linux/platform_device.h`, `linux/pwm.h`.
- Detected declarations: `struct ts_nbus`, `function ts_nbus_init_pdata`, `function ts_nbus_set_direction`, `function ts_nbus_reset_bus`, `function ts_nbus_start_transaction`, `function ts_nbus_read_byte`, `function ts_nbus_write_byte`, `function ts_nbus_read_bus`, `function command`, `function ts_nbus_read`.
- Atlas domain: Driver Families / drivers/bus.
- Implementation status: integration implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.