drivers/gpio/gpio-loongson1.c
Source file repositories/reference/linux-study-clean/drivers/gpio/gpio-loongson1.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/gpio/gpio-loongson1.c- Extension
.c- Size
- 2859 bytes
- Lines
- 117
- 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/bitops.hlinux/module.hlinux/gpio/driver.hlinux/gpio/generic.hlinux/platform_device.h
Detected Declarations
struct ls1x_gpio_chipfunction ls1x_gpio_requestfunction ls1x_gpio_freefunction ls1x_gpio_probe
Annotated Snippet
struct ls1x_gpio_chip {
struct gpio_generic_chip chip;
void __iomem *reg_base;
};
static int ls1x_gpio_request(struct gpio_chip *gc, unsigned int offset)
{
struct ls1x_gpio_chip *ls1x_gc = gpiochip_get_data(gc);
guard(gpio_generic_lock_irqsave)(&ls1x_gc->chip);
__raw_writel(__raw_readl(ls1x_gc->reg_base + GPIO_CFG) | BIT(offset),
ls1x_gc->reg_base + GPIO_CFG);
return 0;
}
static void ls1x_gpio_free(struct gpio_chip *gc, unsigned int offset)
{
struct ls1x_gpio_chip *ls1x_gc = gpiochip_get_data(gc);
guard(gpio_generic_lock_irqsave)(&ls1x_gc->chip);
__raw_writel(__raw_readl(ls1x_gc->reg_base + GPIO_CFG) & ~BIT(offset),
ls1x_gc->reg_base + GPIO_CFG);
}
static int ls1x_gpio_probe(struct platform_device *pdev)
{
struct gpio_generic_chip_config config;
struct device *dev = &pdev->dev;
struct ls1x_gpio_chip *ls1x_gc;
int ret;
ls1x_gc = devm_kzalloc(dev, sizeof(*ls1x_gc), GFP_KERNEL);
if (!ls1x_gc)
return -ENOMEM;
ls1x_gc->reg_base = devm_platform_ioremap_resource(pdev, 0);
if (IS_ERR(ls1x_gc->reg_base))
return PTR_ERR(ls1x_gc->reg_base);
config = (struct gpio_generic_chip_config) {
.dev = dev,
.sz = 4,
.dat = ls1x_gc->reg_base + GPIO_DATA,
.set = ls1x_gc->reg_base + GPIO_OUTPUT,
.dirin = ls1x_gc->reg_base + GPIO_DIR,
};
ret = gpio_generic_chip_init(&ls1x_gc->chip, &config);
if (ret)
goto err;
ls1x_gc->chip.gc.owner = THIS_MODULE;
ls1x_gc->chip.gc.request = ls1x_gpio_request;
ls1x_gc->chip.gc.free = ls1x_gpio_free;
/*
* Clear ngpio to let gpiolib get the correct number
* by reading ngpios property
*/
ls1x_gc->chip.gc.ngpio = 0;
ret = devm_gpiochip_add_data(dev, &ls1x_gc->chip.gc, ls1x_gc);
if (ret)
goto err;
platform_set_drvdata(pdev, ls1x_gc);
dev_info(dev, "GPIO controller registered with %d pins\n",
ls1x_gc->chip.gc.ngpio);
return 0;
err:
dev_err(dev, "failed to register GPIO controller\n");
return ret;
}
static const struct of_device_id ls1x_gpio_dt_ids[] = {
{ .compatible = "loongson,ls1x-gpio" },
{ /* sentinel */ }
};
MODULE_DEVICE_TABLE(of, ls1x_gpio_dt_ids);
static struct platform_driver ls1x_gpio_driver = {
.probe = ls1x_gpio_probe,
.driver = {
.name = "ls1x-gpio",
.of_match_table = ls1x_gpio_dt_ids,
},
Annotation
- Immediate include surface: `linux/bitops.h`, `linux/module.h`, `linux/gpio/driver.h`, `linux/gpio/generic.h`, `linux/platform_device.h`.
- Detected declarations: `struct ls1x_gpio_chip`, `function ls1x_gpio_request`, `function ls1x_gpio_free`, `function ls1x_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.