drivers/gpio/gpio-timberdale.c
Source file repositories/reference/linux-study-clean/drivers/gpio/gpio-timberdale.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/gpio/gpio-timberdale.c- Extension
.c- Size
- 7213 bytes
- Lines
- 296
- 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/init.hlinux/gpio/driver.hlinux/platform_device.hlinux/irq.hlinux/io.hlinux/interrupt.hlinux/slab.h
Detected Declarations
struct timbgpiofunction timbgpio_update_bitfunction timbgpio_gpio_direction_inputfunction timbgpio_gpio_getfunction timbgpio_gpio_direction_outputfunction timbgpio_gpio_setfunction timbgpio_to_irqfunction timbgpio_irq_disablefunction timbgpio_irq_enablefunction timbgpio_irq_typefunction timbgpio_irqfunction timbgpio_probe
Annotated Snippet
struct timbgpio {
void __iomem *membase;
spinlock_t lock; /* mutual exclusion */
struct gpio_chip gpio;
int irq_base;
unsigned long last_ier;
};
static int timbgpio_update_bit(struct gpio_chip *gpio, unsigned index,
unsigned offset, bool enabled)
{
struct timbgpio *tgpio = gpiochip_get_data(gpio);
unsigned long flags;
u32 reg;
spin_lock_irqsave(&tgpio->lock, flags);
reg = ioread32(tgpio->membase + offset);
if (enabled)
reg |= (1 << index);
else
reg &= ~(1 << index);
iowrite32(reg, tgpio->membase + offset);
spin_unlock_irqrestore(&tgpio->lock, flags);
return 0;
}
static int timbgpio_gpio_direction_input(struct gpio_chip *gpio, unsigned nr)
{
return timbgpio_update_bit(gpio, nr, TGPIODIR, true);
}
static int timbgpio_gpio_get(struct gpio_chip *gpio, unsigned nr)
{
struct timbgpio *tgpio = gpiochip_get_data(gpio);
u32 value;
value = ioread32(tgpio->membase + TGPIOVAL);
return (value & (1 << nr)) ? 1 : 0;
}
static int timbgpio_gpio_direction_output(struct gpio_chip *gpio,
unsigned nr, int val)
{
return timbgpio_update_bit(gpio, nr, TGPIODIR, false);
}
static int timbgpio_gpio_set(struct gpio_chip *gpio, unsigned int nr, int val)
{
return timbgpio_update_bit(gpio, nr, TGPIOVAL, val != 0);
}
static int timbgpio_to_irq(struct gpio_chip *gpio, unsigned offset)
{
struct timbgpio *tgpio = gpiochip_get_data(gpio);
if (tgpio->irq_base <= 0)
return -EINVAL;
return tgpio->irq_base + offset;
}
/*
* GPIO IRQ
*/
static void timbgpio_irq_disable(struct irq_data *d)
{
struct timbgpio *tgpio = irq_data_get_irq_chip_data(d);
int offset = d->irq - tgpio->irq_base;
irq_hw_number_t hwirq = irqd_to_hwirq(d);
unsigned long flags;
spin_lock_irqsave(&tgpio->lock, flags);
tgpio->last_ier &= ~(1UL << offset);
iowrite32(tgpio->last_ier, tgpio->membase + TGPIO_IER);
spin_unlock_irqrestore(&tgpio->lock, flags);
gpiochip_disable_irq(&tgpio->gpio, hwirq);
}
static void timbgpio_irq_enable(struct irq_data *d)
{
struct timbgpio *tgpio = irq_data_get_irq_chip_data(d);
int offset = d->irq - tgpio->irq_base;
irq_hw_number_t hwirq = irqd_to_hwirq(d);
unsigned long flags;
gpiochip_enable_irq(&tgpio->gpio, hwirq);
Annotation
- Immediate include surface: `linux/init.h`, `linux/gpio/driver.h`, `linux/platform_device.h`, `linux/irq.h`, `linux/io.h`, `linux/interrupt.h`, `linux/slab.h`.
- Detected declarations: `struct timbgpio`, `function timbgpio_update_bit`, `function timbgpio_gpio_direction_input`, `function timbgpio_gpio_get`, `function timbgpio_gpio_direction_output`, `function timbgpio_gpio_set`, `function timbgpio_to_irq`, `function timbgpio_irq_disable`, `function timbgpio_irq_enable`, `function timbgpio_irq_type`.
- 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.