drivers/gpio/gpio-dln2.c
Source file repositories/reference/linux-study-clean/drivers/gpio/gpio-dln2.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/gpio/gpio-dln2.c- Extension
.c- Size
- 13104 bytes
- Lines
- 525
- Domain
- Driver Families
- Bucket
- drivers/gpio
- 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.
- 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/kernel.hlinux/module.hlinux/slab.hlinux/types.hlinux/irqdomain.hlinux/irq.hlinux/irqchip/chained_irq.hlinux/gpio/driver.hlinux/platform_device.hlinux/mfd/dln2.h
Detected Declarations
struct dln2_gpiostruct dln2_gpio_pinstruct dln2_gpio_pin_valfunction dln2_gpio_get_pin_countfunction dln2_gpio_pin_cmdfunction dln2_gpio_pin_valfunction dln2_gpio_pin_get_in_valfunction dln2_gpio_pin_get_out_valfunction dln2_gpio_pin_set_out_valfunction dln2_gpio_requestfunction dln2_gpio_freefunction dln2_gpio_get_directionfunction dln2_gpio_getfunction dln2_gpio_setfunction dln2_gpio_set_directionfunction dln2_gpio_direction_inputfunction dln2_gpio_direction_outputfunction dln2_gpio_set_configfunction dln2_gpio_set_event_cfgfunction dln2_irq_unmaskfunction dln2_irq_maskfunction dln2_irq_set_typefunction dln2_irq_bus_lockfunction dln2_irq_bus_unlockfunction dln2_gpio_eventfunction dln2_gpio_probefunction dln2_gpio_remove
Annotated Snippet
struct dln2_gpio {
struct platform_device *pdev;
struct gpio_chip gpio;
/*
* Cache pin direction to save us one transfer, since the hardware has
* separate commands to read the in and out values.
*/
DECLARE_BITMAP(output_enabled, DLN2_GPIO_MAX_PINS);
/* active IRQs - not synced to hardware */
DECLARE_BITMAP(unmasked_irqs, DLN2_GPIO_MAX_PINS);
/* active IRQS - synced to hardware */
DECLARE_BITMAP(enabled_irqs, DLN2_GPIO_MAX_PINS);
int irq_type[DLN2_GPIO_MAX_PINS];
struct mutex irq_lock;
};
struct dln2_gpio_pin {
__le16 pin;
};
struct dln2_gpio_pin_val {
__le16 pin __packed;
u8 value;
};
static int dln2_gpio_get_pin_count(struct platform_device *pdev)
{
int ret;
__le16 count;
int len = sizeof(count);
ret = dln2_transfer_rx(pdev, DLN2_GPIO_GET_PIN_COUNT, &count, &len);
if (ret < 0)
return ret;
if (len < sizeof(count))
return -EPROTO;
return le16_to_cpu(count);
}
static int dln2_gpio_pin_cmd(struct dln2_gpio *dln2, int cmd, unsigned pin)
{
struct dln2_gpio_pin req = {
.pin = cpu_to_le16(pin),
};
return dln2_transfer_tx(dln2->pdev, cmd, &req, sizeof(req));
}
static int dln2_gpio_pin_val(struct dln2_gpio *dln2, int cmd, unsigned int pin)
{
int ret;
struct dln2_gpio_pin req = {
.pin = cpu_to_le16(pin),
};
struct dln2_gpio_pin_val rsp;
int len = sizeof(rsp);
ret = dln2_transfer(dln2->pdev, cmd, &req, sizeof(req), &rsp, &len);
if (ret < 0)
return ret;
if (len < sizeof(rsp) || req.pin != rsp.pin)
return -EPROTO;
return rsp.value;
}
static int dln2_gpio_pin_get_in_val(struct dln2_gpio *dln2, unsigned int pin)
{
int ret;
ret = dln2_gpio_pin_val(dln2, DLN2_GPIO_PIN_GET_VAL, pin);
if (ret < 0)
return ret;
return !!ret;
}
static int dln2_gpio_pin_get_out_val(struct dln2_gpio *dln2, unsigned int pin)
{
int ret;
ret = dln2_gpio_pin_val(dln2, DLN2_GPIO_PIN_GET_OUT_VAL, pin);
if (ret < 0)
return ret;
return !!ret;
}
static int dln2_gpio_pin_set_out_val(struct dln2_gpio *dln2,
Annotation
- Immediate include surface: `linux/kernel.h`, `linux/module.h`, `linux/slab.h`, `linux/types.h`, `linux/irqdomain.h`, `linux/irq.h`, `linux/irqchip/chained_irq.h`, `linux/gpio/driver.h`.
- Detected declarations: `struct dln2_gpio`, `struct dln2_gpio_pin`, `struct dln2_gpio_pin_val`, `function dln2_gpio_get_pin_count`, `function dln2_gpio_pin_cmd`, `function dln2_gpio_pin_val`, `function dln2_gpio_pin_get_in_val`, `function dln2_gpio_pin_get_out_val`, `function dln2_gpio_pin_set_out_val`, `function dln2_gpio_request`.
- Atlas domain: Driver Families / drivers/gpio.
- Implementation status: source 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.