drivers/gpio/gpio-loongson-64bit.c
Source file repositories/reference/linux-study-clean/drivers/gpio/gpio-loongson-64bit.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/gpio/gpio-loongson-64bit.c- Extension
.c- Size
- 15579 bytes
- Lines
- 580
- Domain
- Driver Families
- Bucket
- drivers/gpio
- Inferred role
- Driver Families: exported/initcall integration point
- Status
- integration 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.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- 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/init.hlinux/irq.hlinux/irqdesc.hlinux/module.hlinux/spinlock.hlinux/err.hlinux/gpio/driver.hlinux/gpio/generic.hlinux/platform_device.hlinux/bitops.hlinux/reset.hasm/types.h
Detected Declarations
struct loongson_gpio_chip_datastruct loongson_gpio_chipenum loongson_gpio_modefunction loongson_commit_directionfunction loongson_commit_levelfunction loongson_gpio_direction_inputfunction loongson_gpio_direction_outputfunction loongson_gpio_getfunction loongson_gpio_get_directionfunction loongson_gpio_setfunction loongson_gpio_to_irqfunction loongson_gpio_irq_ackfunction loongson_gpio_irq_maskfunction loongson_gpio_irq_unmaskfunction loongson_gpio_irq_set_typefunction loongson_gpio_ls2k0300_irq_handlerfunction loongson_gpio_init_irqchipfunction loongson_gpio_initfunction loongson_gpio_probefunction loongson_gpio_setup
Annotated Snippet
struct loongson_gpio_chip_data {
const char *label;
enum loongson_gpio_mode mode;
unsigned int conf_offset;
unsigned int out_offset;
unsigned int in_offset;
unsigned int inten_offset;
unsigned int intpol_offset;
unsigned int intedge_offset;
unsigned int intclr_offset;
unsigned int intsts_offset;
unsigned int intdual_offset;
unsigned int intr_num;
irq_flow_handler_t irq_handler;
const struct irq_chip *girqchip;
};
struct loongson_gpio_chip {
struct gpio_generic_chip chip;
spinlock_t lock;
void __iomem *reg_base;
const struct loongson_gpio_chip_data *chip_data;
};
static inline struct loongson_gpio_chip *to_loongson_gpio_chip(struct gpio_chip *chip)
{
return container_of(to_gpio_generic_chip(chip),
struct loongson_gpio_chip, chip);
}
static inline void loongson_commit_direction(struct loongson_gpio_chip *lgpio, unsigned int pin,
int input)
{
u8 bval = input ? 1 : 0;
writeb(bval, lgpio->reg_base + lgpio->chip_data->conf_offset + pin);
}
static void loongson_commit_level(struct loongson_gpio_chip *lgpio, unsigned int pin, int high)
{
u8 bval = high ? 1 : 0;
writeb(bval, lgpio->reg_base + lgpio->chip_data->out_offset + pin);
}
static int loongson_gpio_direction_input(struct gpio_chip *chip, unsigned int pin)
{
unsigned long flags;
struct loongson_gpio_chip *lgpio = to_loongson_gpio_chip(chip);
spin_lock_irqsave(&lgpio->lock, flags);
loongson_commit_direction(lgpio, pin, 1);
spin_unlock_irqrestore(&lgpio->lock, flags);
return 0;
}
static int loongson_gpio_direction_output(struct gpio_chip *chip, unsigned int pin, int value)
{
unsigned long flags;
struct loongson_gpio_chip *lgpio = to_loongson_gpio_chip(chip);
spin_lock_irqsave(&lgpio->lock, flags);
loongson_commit_level(lgpio, pin, value);
loongson_commit_direction(lgpio, pin, 0);
spin_unlock_irqrestore(&lgpio->lock, flags);
return 0;
}
static int loongson_gpio_get(struct gpio_chip *chip, unsigned int pin)
{
u8 bval;
int val;
struct loongson_gpio_chip *lgpio = to_loongson_gpio_chip(chip);
bval = readb(lgpio->reg_base + lgpio->chip_data->in_offset + pin);
val = bval & 1;
return val;
}
static int loongson_gpio_get_direction(struct gpio_chip *chip, unsigned int pin)
{
u8 bval;
struct loongson_gpio_chip *lgpio = to_loongson_gpio_chip(chip);
bval = readb(lgpio->reg_base + lgpio->chip_data->conf_offset + pin);
if (bval & 1)
return GPIO_LINE_DIRECTION_IN;
Annotation
- Immediate include surface: `linux/kernel.h`, `linux/init.h`, `linux/irq.h`, `linux/irqdesc.h`, `linux/module.h`, `linux/spinlock.h`, `linux/err.h`, `linux/gpio/driver.h`.
- Detected declarations: `struct loongson_gpio_chip_data`, `struct loongson_gpio_chip`, `enum loongson_gpio_mode`, `function loongson_commit_direction`, `function loongson_commit_level`, `function loongson_gpio_direction_input`, `function loongson_gpio_direction_output`, `function loongson_gpio_get`, `function loongson_gpio_get_direction`, `function loongson_gpio_set`.
- Atlas domain: Driver Families / drivers/gpio.
- Implementation status: integration 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.