drivers/gpio/gpio-janz-ttl.c
Source file repositories/reference/linux-study-clean/drivers/gpio/gpio-janz-ttl.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/gpio/gpio-janz-ttl.c- Extension
.c- Size
- 4440 bytes
- Lines
- 203
- 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/init.hlinux/interrupt.hlinux/delay.hlinux/platform_device.hlinux/io.hlinux/gpio/driver.hlinux/slab.hlinux/bitops.hlinux/mfd/janz.h
Detected Declarations
struct ttl_control_regsstruct ttl_modulefunction ttl_get_valuefunction ttl_set_valuefunction ttl_write_regfunction ttl_setup_devicefunction ttl_probe
Annotated Snippet
struct ttl_control_regs {
__be16 portc;
__be16 portb;
__be16 porta;
__be16 control;
};
struct ttl_module {
struct gpio_chip gpio;
/* base address of registers */
struct ttl_control_regs __iomem *regs;
u8 portc_shadow;
u8 portb_shadow;
u8 porta_shadow;
spinlock_t lock;
};
static int ttl_get_value(struct gpio_chip *gpio, unsigned offset)
{
struct ttl_module *mod = dev_get_drvdata(gpio->parent);
u8 *shadow;
int ret;
if (offset < 8) {
shadow = &mod->porta_shadow;
} else if (offset < 16) {
shadow = &mod->portb_shadow;
offset -= 8;
} else {
shadow = &mod->portc_shadow;
offset -= 16;
}
spin_lock(&mod->lock);
ret = *shadow & BIT(offset);
spin_unlock(&mod->lock);
return !!ret;
}
static int ttl_set_value(struct gpio_chip *gpio, unsigned int offset, int value)
{
struct ttl_module *mod = dev_get_drvdata(gpio->parent);
void __iomem *port;
u8 *shadow;
if (offset < 8) {
port = &mod->regs->porta;
shadow = &mod->porta_shadow;
} else if (offset < 16) {
port = &mod->regs->portb;
shadow = &mod->portb_shadow;
offset -= 8;
} else {
port = &mod->regs->portc;
shadow = &mod->portc_shadow;
offset -= 16;
}
spin_lock(&mod->lock);
if (value)
*shadow |= BIT(offset);
else
*shadow &= ~BIT(offset);
iowrite16be(*shadow, port);
spin_unlock(&mod->lock);
return 0;
}
static void ttl_write_reg(struct ttl_module *mod, u8 reg, u16 val)
{
iowrite16be(reg, &mod->regs->control);
iowrite16be(val, &mod->regs->control);
}
static void ttl_setup_device(struct ttl_module *mod)
{
/* reset the device to a known state */
iowrite16be(0x0000, &mod->regs->control);
iowrite16be(0x0001, &mod->regs->control);
iowrite16be(0x0000, &mod->regs->control);
/* put all ports in open-drain mode */
ttl_write_reg(mod, PORTA_IOCTL, 0x00ff);
ttl_write_reg(mod, PORTB_IOCTL, 0x00ff);
ttl_write_reg(mod, PORTC_IOCTL, 0x000f);
Annotation
- Immediate include surface: `linux/kernel.h`, `linux/module.h`, `linux/init.h`, `linux/interrupt.h`, `linux/delay.h`, `linux/platform_device.h`, `linux/io.h`, `linux/gpio/driver.h`.
- Detected declarations: `struct ttl_control_regs`, `struct ttl_module`, `function ttl_get_value`, `function ttl_set_value`, `function ttl_write_reg`, `function ttl_setup_device`, `function ttl_probe`.
- 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.