drivers/gpio/gpio-mpfs.c
Source file repositories/reference/linux-study-clean/drivers/gpio/gpio-mpfs.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/gpio/gpio-mpfs.c- Extension
.c- Size
- 8539 bytes
- Lines
- 308
- 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/clk.hlinux/device.hlinux/errno.hlinux/gpio/driver.hlinux/interrupt.hlinux/mod_devicetable.hlinux/of_irq.hlinux/platform_device.hlinux/property.hlinux/regmap.hlinux/spinlock.h
Detected Declarations
struct mpfs_gpio_reg_offsetsstruct mpfs_gpio_chipfunction mpfs_gpio_direction_inputfunction mpfs_gpio_direction_outputfunction mpfs_gpio_get_directionfunction mpfs_gpio_getfunction mpfs_gpio_setfunction mpfs_gpio_irq_set_typefunction mpfs_gpio_irq_unmaskfunction mpfs_gpio_irq_maskfunction mpfs_gpio_irq_handlerfunction mpfs_gpio_probe
Annotated Snippet
struct mpfs_gpio_reg_offsets {
u8 inp;
u8 outp;
};
struct mpfs_gpio_chip {
struct regmap *regs;
const struct mpfs_gpio_reg_offsets *offsets;
struct gpio_chip gc;
};
static const struct regmap_config mpfs_gpio_regmap_config = {
.reg_bits = 32,
.reg_stride = 4,
.val_bits = 32,
.use_raw_spinlock = true,
};
static int mpfs_gpio_direction_input(struct gpio_chip *gc, unsigned int gpio_index)
{
struct mpfs_gpio_chip *mpfs_gpio = gpiochip_get_data(gc);
regmap_update_bits(mpfs_gpio->regs, MPFS_GPIO_CTRL(gpio_index),
MPFS_GPIO_DIR_MASK, MPFS_GPIO_EN_IN);
return 0;
}
static int mpfs_gpio_direction_output(struct gpio_chip *gc, unsigned int gpio_index, int value)
{
struct mpfs_gpio_chip *mpfs_gpio = gpiochip_get_data(gc);
regmap_update_bits(mpfs_gpio->regs, MPFS_GPIO_CTRL(gpio_index),
MPFS_GPIO_DIR_MASK, MPFS_GPIO_EN_OUT | MPFS_GPIO_EN_OUT_BUF);
regmap_update_bits(mpfs_gpio->regs, mpfs_gpio->offsets->outp, BIT(gpio_index),
value << gpio_index);
return 0;
}
static int mpfs_gpio_get_direction(struct gpio_chip *gc,
unsigned int gpio_index)
{
struct mpfs_gpio_chip *mpfs_gpio = gpiochip_get_data(gc);
unsigned int gpio_cfg;
regmap_read(mpfs_gpio->regs, MPFS_GPIO_CTRL(gpio_index), &gpio_cfg);
if (gpio_cfg & MPFS_GPIO_EN_IN)
return GPIO_LINE_DIRECTION_IN;
return GPIO_LINE_DIRECTION_OUT;
}
static int mpfs_gpio_get(struct gpio_chip *gc, unsigned int gpio_index)
{
struct mpfs_gpio_chip *mpfs_gpio = gpiochip_get_data(gc);
if (mpfs_gpio_get_direction(gc, gpio_index) == GPIO_LINE_DIRECTION_OUT)
return regmap_test_bits(mpfs_gpio->regs, mpfs_gpio->offsets->outp, BIT(gpio_index));
else
return regmap_test_bits(mpfs_gpio->regs, mpfs_gpio->offsets->inp, BIT(gpio_index));
}
static int mpfs_gpio_set(struct gpio_chip *gc, unsigned int gpio_index, int value)
{
struct mpfs_gpio_chip *mpfs_gpio = gpiochip_get_data(gc);
int ret;
mpfs_gpio_get(gc, gpio_index);
ret = regmap_update_bits(mpfs_gpio->regs, mpfs_gpio->offsets->outp,
BIT(gpio_index), value << gpio_index);
mpfs_gpio_get(gc, gpio_index);
return ret;
}
static int mpfs_gpio_irq_set_type(struct irq_data *data, unsigned int type)
{
struct gpio_chip *gc = irq_data_get_irq_chip_data(data);
struct mpfs_gpio_chip *mpfs_gpio = gpiochip_get_data(gc);
int gpio_index = irqd_to_hwirq(data) % 32;
u32 interrupt_type;
switch (type) {
case IRQ_TYPE_EDGE_BOTH:
interrupt_type = MPFS_GPIO_TYPE_INT_EDGE_BOTH;
break;
case IRQ_TYPE_EDGE_FALLING:
Annotation
- Immediate include surface: `linux/clk.h`, `linux/device.h`, `linux/errno.h`, `linux/gpio/driver.h`, `linux/interrupt.h`, `linux/mod_devicetable.h`, `linux/of_irq.h`, `linux/platform_device.h`.
- Detected declarations: `struct mpfs_gpio_reg_offsets`, `struct mpfs_gpio_chip`, `function mpfs_gpio_direction_input`, `function mpfs_gpio_direction_output`, `function mpfs_gpio_get_direction`, `function mpfs_gpio_get`, `function mpfs_gpio_set`, `function mpfs_gpio_irq_set_type`, `function mpfs_gpio_irq_unmask`, `function mpfs_gpio_irq_mask`.
- 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.