drivers/pinctrl/bcm/pinctrl-nsp-gpio.c
Source file repositories/reference/linux-study-clean/drivers/pinctrl/bcm/pinctrl-nsp-gpio.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/pinctrl/bcm/pinctrl-nsp-gpio.c- Extension
.c- Size
- 18393 bytes
- Lines
- 716
- Domain
- Driver Families
- Bucket
- drivers/pinctrl
- 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.
- Touches IRQ or DMA behavior; this matters for the representative real-device path.
- 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/gpio/driver.hlinux/interrupt.hlinux/io.hlinux/ioport.hlinux/kernel.hlinux/of.hlinux/pinctrl/pinconf.hlinux/pinctrl/pinconf-generic.hlinux/pinctrl/pinctrl.hlinux/platform_device.hlinux/slab.hlinux/string_choices.h../pinctrl-utils.h
Detected Declarations
struct nsp_gpioenum base_typefunction nsp_pin_to_gpiofunction nsp_set_bitfunction nsp_get_bitfunction nsp_gpio_irq_handlerfunction nsp_gpio_irq_ackfunction nsp_gpio_irq_set_maskfunction nsp_gpio_irq_maskfunction nsp_gpio_irq_unmaskfunction nsp_gpio_irq_set_typefunction nsp_gpio_direction_inputfunction nsp_gpio_direction_outputfunction nsp_gpio_get_directionfunction nsp_gpio_setfunction nsp_gpio_getfunction nsp_get_groups_countfunction nsp_gpio_set_slewfunction nsp_gpio_set_pullfunction nsp_gpio_get_pullfunction nsp_gpio_set_strengthfunction nsp_gpio_get_strengthfunction nsp_pin_config_group_getfunction nsp_pin_config_group_setfunction nsp_pin_config_getfunction nsp_pin_config_setfunction nsp_gpio_register_pinconffunction nsp_gpio_probefunction nsp_gpio_init
Annotated Snippet
struct nsp_gpio {
struct device *dev;
void __iomem *base;
void __iomem *io_ctrl;
struct gpio_chip gc;
struct pinctrl_dev *pctl;
struct pinctrl_desc pctldesc;
raw_spinlock_t lock;
};
enum base_type {
REG,
IO_CTRL
};
/*
* Mapping from PINCONF pins to GPIO pins is 1-to-1
*/
static inline unsigned nsp_pin_to_gpio(unsigned pin)
{
return pin;
}
/*
* nsp_set_bit - set or clear one bit (corresponding to the GPIO pin) in a
* nsp GPIO register
*
* @nsp_gpio: nsp GPIO device
* @base_type: reg base to modify
* @reg: register offset
* @gpio: GPIO pin
* @set: set or clear
*/
static inline void nsp_set_bit(struct nsp_gpio *chip, enum base_type address,
unsigned int reg, unsigned gpio, bool set)
{
u32 val;
void __iomem *base_address;
if (address == IO_CTRL)
base_address = chip->io_ctrl;
else
base_address = chip->base;
val = readl(base_address + reg);
if (set)
val |= BIT(gpio);
else
val &= ~BIT(gpio);
writel(val, base_address + reg);
}
/*
* nsp_get_bit - get one bit (corresponding to the GPIO pin) in a
* nsp GPIO register
*/
static inline bool nsp_get_bit(struct nsp_gpio *chip, enum base_type address,
unsigned int reg, unsigned gpio)
{
if (address == IO_CTRL)
return !!(readl(chip->io_ctrl + reg) & BIT(gpio));
else
return !!(readl(chip->base + reg) & BIT(gpio));
}
static irqreturn_t nsp_gpio_irq_handler(int irq, void *data)
{
struct gpio_chip *gc = (struct gpio_chip *)data;
struct nsp_gpio *chip = gpiochip_get_data(gc);
int bit;
unsigned long int_bits = 0;
u32 int_status;
/* go through the entire GPIOs and handle all interrupts */
int_status = readl(chip->base + NSP_CHIP_A_INT_STATUS);
if (int_status & NSP_CHIP_A_GPIO_INT_BIT) {
unsigned int event, level;
/* Get level and edge interrupts */
event = readl(chip->base + NSP_GPIO_EVENT_INT_MASK) &
readl(chip->base + NSP_GPIO_EVENT);
level = readl(chip->base + NSP_GPIO_DATA_IN) ^
readl(chip->base + NSP_GPIO_INT_POLARITY);
level &= readl(chip->base + NSP_GPIO_INT_MASK);
int_bits = level | event;
for_each_set_bit(bit, &int_bits, gc->ngpio)
generic_handle_domain_irq(gc->irq.domain, bit);
}
Annotation
- Immediate include surface: `linux/gpio/driver.h`, `linux/interrupt.h`, `linux/io.h`, `linux/ioport.h`, `linux/kernel.h`, `linux/of.h`, `linux/pinctrl/pinconf.h`, `linux/pinctrl/pinconf-generic.h`.
- Detected declarations: `struct nsp_gpio`, `enum base_type`, `function nsp_pin_to_gpio`, `function nsp_set_bit`, `function nsp_get_bit`, `function nsp_gpio_irq_handler`, `function nsp_gpio_irq_ack`, `function nsp_gpio_irq_set_mask`, `function nsp_gpio_irq_mask`, `function nsp_gpio_irq_unmask`.
- Atlas domain: Driver Families / drivers/pinctrl.
- Implementation status: source implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
- IRQ or DMA behavior appears here, which is relevant to the selected PCIe/NVMe device path.
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.