drivers/gpio/gpio-vx855.c
Source file repositories/reference/linux-study-clean/drivers/gpio/gpio-vx855.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/gpio/gpio-vx855.c- Extension
.c- Size
- 7246 bytes
- Lines
- 285
- 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/gpio/driver.hlinux/slab.hlinux/device.hlinux/platform_device.hlinux/pci.hlinux/io.h
Detected Declarations
struct vx855_gpiofunction gpi_i_bitfunction gpo_o_bitfunction gpio_i_bitfunction gpio_o_bitfunction vx855gpio_direction_inputfunction vx855gpio_getfunction vx855gpio_setfunction vx855gpio_direction_outputfunction vx855gpio_set_configfunction vx855gpio_gpio_setupfunction vx855gpio_probe
Annotated Snippet
struct vx855_gpio {
struct gpio_chip gpio;
spinlock_t lock;
u32 io_gpi;
u32 io_gpo;
};
/* resolve a GPIx into the corresponding bit position */
static inline u_int32_t gpi_i_bit(int i)
{
if (i < 10)
return 1 << i;
else
return 1 << (i + 14);
}
static inline u_int32_t gpo_o_bit(int i)
{
if (i < 11)
return 1 << i;
else
return 1 << (i + 14);
}
static inline u_int32_t gpio_i_bit(int i)
{
if (i < 14)
return 1 << (i + 10);
else
return 1 << (i + 14);
}
static inline u_int32_t gpio_o_bit(int i)
{
if (i < 14)
return 1 << (i + 11);
else
return 1 << (i + 13);
}
/* Mapping between numeric GPIO ID and the actual GPIO hardware numbering:
* 0..13 GPI 0..13
* 14..26 GPO 0..12
* 27..41 GPIO 0..14
*/
static int vx855gpio_direction_input(struct gpio_chip *gpio,
unsigned int nr)
{
struct vx855_gpio *vg = gpiochip_get_data(gpio);
unsigned long flags;
u_int32_t reg_out;
/* Real GPI bits are always in input direction */
if (nr < NR_VX855_GPI)
return 0;
/* Real GPO bits cannot be put in output direction */
if (nr < NR_VX855_GPInO)
return -EINVAL;
/* Open Drain GPIO have to be set to one */
spin_lock_irqsave(&vg->lock, flags);
reg_out = inl(vg->io_gpo);
reg_out |= gpio_o_bit(nr - NR_VX855_GPInO);
outl(reg_out, vg->io_gpo);
spin_unlock_irqrestore(&vg->lock, flags);
return 0;
}
static int vx855gpio_get(struct gpio_chip *gpio, unsigned int nr)
{
struct vx855_gpio *vg = gpiochip_get_data(gpio);
u_int32_t reg_in;
int ret = 0;
if (nr < NR_VX855_GPI) {
reg_in = inl(vg->io_gpi);
if (reg_in & gpi_i_bit(nr))
ret = 1;
} else if (nr < NR_VX855_GPInO) {
/* GPO don't have an input bit, we need to read it
* back from the output register */
reg_in = inl(vg->io_gpo);
if (reg_in & gpo_o_bit(nr - NR_VX855_GPI))
ret = 1;
} else {
reg_in = inl(vg->io_gpi);
if (reg_in & gpio_i_bit(nr - NR_VX855_GPInO))
Annotation
- Immediate include surface: `linux/kernel.h`, `linux/module.h`, `linux/gpio/driver.h`, `linux/slab.h`, `linux/device.h`, `linux/platform_device.h`, `linux/pci.h`, `linux/io.h`.
- Detected declarations: `struct vx855_gpio`, `function gpi_i_bit`, `function gpo_o_bit`, `function gpio_i_bit`, `function gpio_o_bit`, `function vx855gpio_direction_input`, `function vx855gpio_get`, `function vx855gpio_set`, `function vx855gpio_direction_output`, `function vx855gpio_set_config`.
- 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.