drivers/siox/siox-bus-gpio.c
Source file repositories/reference/linux-study-clean/drivers/siox/siox-bus-gpio.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/siox/siox-bus-gpio.c- Extension
.c- Size
- 3963 bytes
- Lines
- 153
- Domain
- Driver Families
- Bucket
- drivers/siox
- Inferred role
- Driver Families: implementation source
- Status
- source 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.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/gpio/consumer.hlinux/module.hlinux/mod_devicetable.hlinux/platform_device.hlinux/delay.hsiox.h
Detected Declarations
struct siox_gpio_ddatafunction siox_gpio_pushpullfunction siox_gpio_probe
Annotated Snippet
struct siox_gpio_ddata {
struct gpio_desc *din;
struct gpio_desc *dout;
struct gpio_desc *dclk;
struct gpio_desc *dld;
};
static unsigned int siox_clkhigh_ns = 1000;
static unsigned int siox_loadhigh_ns;
static unsigned int siox_bytegap_ns;
static int siox_gpio_pushpull(struct siox_master *smaster,
size_t setbuf_len, const u8 setbuf[],
size_t getbuf_len, u8 getbuf[])
{
struct siox_gpio_ddata *ddata = siox_master_get_devdata(smaster);
size_t i;
size_t cycles = max(setbuf_len, getbuf_len);
/* reset data and clock */
gpiod_set_value_cansleep(ddata->dout, 0);
gpiod_set_value_cansleep(ddata->dclk, 0);
gpiod_set_value_cansleep(ddata->dld, 1);
ndelay(siox_loadhigh_ns);
gpiod_set_value_cansleep(ddata->dld, 0);
for (i = 0; i < cycles; ++i) {
u8 set = 0, get = 0;
size_t j;
if (i >= cycles - setbuf_len)
set = setbuf[i - (cycles - setbuf_len)];
for (j = 0; j < 8; ++j) {
get <<= 1;
if (gpiod_get_value_cansleep(ddata->din))
get |= 1;
/* DOUT is logically inverted */
gpiod_set_value_cansleep(ddata->dout, !(set & 0x80));
set <<= 1;
gpiod_set_value_cansleep(ddata->dclk, 1);
ndelay(siox_clkhigh_ns);
gpiod_set_value_cansleep(ddata->dclk, 0);
}
if (i < getbuf_len)
getbuf[i] = get;
ndelay(siox_bytegap_ns);
}
gpiod_set_value_cansleep(ddata->dld, 1);
ndelay(siox_loadhigh_ns);
gpiod_set_value_cansleep(ddata->dld, 0);
/*
* Resetting dout isn't necessary protocol wise, but it makes the
* signals more pretty because the dout level is deterministic between
* cycles. Note that this only affects dout between the master and the
* first siox device. dout for the later devices depend on the output of
* the previous siox device.
*/
gpiod_set_value_cansleep(ddata->dout, 0);
return 0;
}
static int siox_gpio_probe(struct platform_device *pdev)
{
struct device *dev = &pdev->dev;
struct siox_gpio_ddata *ddata;
int ret;
struct siox_master *smaster;
smaster = devm_siox_master_alloc(dev, sizeof(*ddata));
if (!smaster)
return -ENOMEM;
platform_set_drvdata(pdev, smaster);
ddata = siox_master_get_devdata(smaster);
ddata->din = devm_gpiod_get(dev, "din", GPIOD_IN);
if (IS_ERR(ddata->din))
return dev_err_probe(dev, PTR_ERR(ddata->din),
"Failed to get din GPIO\n");
ddata->dout = devm_gpiod_get(dev, "dout", GPIOD_OUT_LOW);
Annotation
- Immediate include surface: `linux/gpio/consumer.h`, `linux/module.h`, `linux/mod_devicetable.h`, `linux/platform_device.h`, `linux/delay.h`, `siox.h`.
- Detected declarations: `struct siox_gpio_ddata`, `function siox_gpio_pushpull`, `function siox_gpio_probe`.
- Atlas domain: Driver Families / drivers/siox.
- Implementation status: source implementation candidate.
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.