drivers/gpio/gpio-amdpt.c
Source file repositories/reference/linux-study-clean/drivers/gpio/gpio-amdpt.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/gpio/gpio-amdpt.c- Extension
.c- Size
- 3844 bytes
- Lines
- 148
- 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.
- 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/gpio/generic.hlinux/spinlock.hlinux/acpi.hlinux/platform_device.h
Detected Declarations
struct pt_gpio_chipfunction pt_gpio_requestfunction pt_gpio_freefunction pt_gpio_probe
Annotated Snippet
struct pt_gpio_chip {
struct gpio_generic_chip chip;
void __iomem *reg_base;
};
static int pt_gpio_request(struct gpio_chip *gc, unsigned offset)
{
struct gpio_generic_chip *gen_gc = to_gpio_generic_chip(gc);
struct pt_gpio_chip *pt_gpio = gpiochip_get_data(gc);
u32 using_pins;
dev_dbg(gc->parent, "pt_gpio_request offset=%x\n", offset);
guard(gpio_generic_lock_irqsave)(gen_gc);
using_pins = readl(pt_gpio->reg_base + PT_SYNC_REG);
if (using_pins & BIT(offset)) {
dev_warn(gc->parent, "PT GPIO pin %x reconfigured\n",
offset);
return -EINVAL;
}
writel(using_pins | BIT(offset), pt_gpio->reg_base + PT_SYNC_REG);
return 0;
}
static void pt_gpio_free(struct gpio_chip *gc, unsigned offset)
{
struct gpio_generic_chip *gen_gc = to_gpio_generic_chip(gc);
struct pt_gpio_chip *pt_gpio = gpiochip_get_data(gc);
u32 using_pins;
guard(gpio_generic_lock_irqsave)(gen_gc);
using_pins = readl(pt_gpio->reg_base + PT_SYNC_REG);
using_pins &= ~BIT(offset);
writel(using_pins, pt_gpio->reg_base + PT_SYNC_REG);
dev_dbg(gc->parent, "pt_gpio_free offset=%x\n", offset);
}
static int pt_gpio_probe(struct platform_device *pdev)
{
struct gpio_generic_chip_config config;
struct device *dev = &pdev->dev;
struct pt_gpio_chip *pt_gpio;
int ret = 0;
if (!ACPI_COMPANION(dev)) {
dev_err(dev, "PT GPIO device node not found\n");
return -ENODEV;
}
pt_gpio = devm_kzalloc(dev, sizeof(struct pt_gpio_chip), GFP_KERNEL);
if (!pt_gpio)
return -ENOMEM;
pt_gpio->reg_base = devm_platform_ioremap_resource(pdev, 0);
if (IS_ERR(pt_gpio->reg_base)) {
dev_err(dev, "Failed to map MMIO resource for PT GPIO.\n");
return PTR_ERR(pt_gpio->reg_base);
}
config = (struct gpio_generic_chip_config) {
.dev = dev,
.sz = 4,
.dat = pt_gpio->reg_base + PT_INPUTDATA_REG,
.set = pt_gpio->reg_base + PT_OUTPUTDATA_REG,
.dirout = pt_gpio->reg_base + PT_DIRECTION_REG,
.flags = GPIO_GENERIC_READ_OUTPUT_REG_SET,
};
ret = gpio_generic_chip_init(&pt_gpio->chip, &config);
if (ret) {
dev_err(dev, "failed to initialize the generic GPIO chip\n");
return ret;
}
pt_gpio->chip.gc.owner = THIS_MODULE;
pt_gpio->chip.gc.request = pt_gpio_request;
pt_gpio->chip.gc.free = pt_gpio_free;
pt_gpio->chip.gc.ngpio = (uintptr_t)device_get_match_data(dev);
ret = devm_gpiochip_add_data(dev, &pt_gpio->chip.gc, pt_gpio);
if (ret) {
dev_err(dev, "Failed to register GPIO lib\n");
return ret;
}
Annotation
- Immediate include surface: `linux/kernel.h`, `linux/module.h`, `linux/gpio/driver.h`, `linux/gpio/generic.h`, `linux/spinlock.h`, `linux/acpi.h`, `linux/platform_device.h`.
- Detected declarations: `struct pt_gpio_chip`, `function pt_gpio_request`, `function pt_gpio_free`, `function pt_gpio_probe`.
- Atlas domain: Driver Families / drivers/gpio.
- Implementation status: source implementation candidate.
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.