drivers/gpio/gpio-amd-fch.c
Source file repositories/reference/linux-study-clean/drivers/gpio/gpio-amd-fch.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/gpio/gpio-amd-fch.c- Extension
.c- Size
- 5006 bytes
- Lines
- 195
- 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/bitfield.hlinux/err.hlinux/io.hlinux/kernel.hlinux/module.hlinux/platform_device.hlinux/gpio/driver.hlinux/platform_data/gpio/gpio-amd-fch.hlinux/spinlock.h
Detected Declarations
struct amd_fch_gpio_privfunction amd_fch_gpio_direction_inputfunction amd_fch_gpio_direction_outputfunction amd_fch_gpio_get_directionfunction amd_fch_gpio_setfunction amd_fch_gpio_getfunction amd_fch_gpio_requestfunction amd_fch_gpio_probe
Annotated Snippet
struct amd_fch_gpio_priv {
struct gpio_chip gc;
void __iomem *base;
struct amd_fch_gpio_pdata *pdata;
spinlock_t lock;
};
static void __iomem *amd_fch_gpio_addr(struct amd_fch_gpio_priv *priv,
unsigned int gpio)
{
return priv->base + priv->pdata->gpio_reg[gpio]*sizeof(u32);
}
static int amd_fch_gpio_direction_input(struct gpio_chip *gc,
unsigned int offset)
{
unsigned long flags;
struct amd_fch_gpio_priv *priv = gpiochip_get_data(gc);
void __iomem *ptr = amd_fch_gpio_addr(priv, offset);
spin_lock_irqsave(&priv->lock, flags);
writel_relaxed(readl_relaxed(ptr) & ~AMD_FCH_GPIO_FLAG_DIRECTION, ptr);
spin_unlock_irqrestore(&priv->lock, flags);
return 0;
}
static int amd_fch_gpio_direction_output(struct gpio_chip *gc,
unsigned int gpio, int value)
{
unsigned long flags;
struct amd_fch_gpio_priv *priv = gpiochip_get_data(gc);
void __iomem *ptr = amd_fch_gpio_addr(priv, gpio);
u32 val;
spin_lock_irqsave(&priv->lock, flags);
val = readl_relaxed(ptr);
if (value)
val |= AMD_FCH_GPIO_FLAG_WRITE;
else
val &= ~AMD_FCH_GPIO_FLAG_WRITE;
writel_relaxed(val | AMD_FCH_GPIO_FLAG_DIRECTION, ptr);
spin_unlock_irqrestore(&priv->lock, flags);
return 0;
}
static int amd_fch_gpio_get_direction(struct gpio_chip *gc, unsigned int gpio)
{
int ret;
unsigned long flags;
struct amd_fch_gpio_priv *priv = gpiochip_get_data(gc);
void __iomem *ptr = amd_fch_gpio_addr(priv, gpio);
spin_lock_irqsave(&priv->lock, flags);
ret = (readl_relaxed(ptr) & AMD_FCH_GPIO_FLAG_DIRECTION);
spin_unlock_irqrestore(&priv->lock, flags);
return ret ? GPIO_LINE_DIRECTION_OUT : GPIO_LINE_DIRECTION_IN;
}
static int amd_fch_gpio_set(struct gpio_chip *gc, unsigned int gpio, int value)
{
unsigned long flags;
struct amd_fch_gpio_priv *priv = gpiochip_get_data(gc);
void __iomem *ptr = amd_fch_gpio_addr(priv, gpio);
u32 mask;
spin_lock_irqsave(&priv->lock, flags);
mask = readl_relaxed(ptr);
if (value)
mask |= AMD_FCH_GPIO_FLAG_WRITE;
else
mask &= ~AMD_FCH_GPIO_FLAG_WRITE;
writel_relaxed(mask, ptr);
spin_unlock_irqrestore(&priv->lock, flags);
return 0;
}
static int amd_fch_gpio_get(struct gpio_chip *gc,
unsigned int offset)
{
unsigned long flags;
u32 val;
Annotation
- Immediate include surface: `linux/bitfield.h`, `linux/err.h`, `linux/io.h`, `linux/kernel.h`, `linux/module.h`, `linux/platform_device.h`, `linux/gpio/driver.h`, `linux/platform_data/gpio/gpio-amd-fch.h`.
- Detected declarations: `struct amd_fch_gpio_priv`, `function amd_fch_gpio_direction_input`, `function amd_fch_gpio_direction_output`, `function amd_fch_gpio_get_direction`, `function amd_fch_gpio_set`, `function amd_fch_gpio_get`, `function amd_fch_gpio_request`, `function amd_fch_gpio_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.