[PATCH v1 3/4] gpio: phytium: switch PCI driver to immutable irq_chip
From: Zhu Ling
Date: Sun Mar 01 2026 - 20:48:33 EST
Use a static immutable irq_chip and gpio_irq_chip_set_chip() in the
PCI frontend and align interrupt init/restore flow with the core and
platform driver paths.
Signed-off-by: Zhu Ling <1536943441@xxxxxx>
---
drivers/gpio/gpio-phytium-pci.c | 43 ++++++++++++++++++++++-----------
1 file changed, 29 insertions(+), 14 deletions(-)
diff --git a/drivers/gpio/gpio-phytium-pci.c b/drivers/gpio/gpio-phytium-pci.c
index a760ad793..73f90c495 100644
--- a/drivers/gpio/gpio-phytium-pci.c
+++ b/drivers/gpio/gpio-phytium-pci.c
@@ -13,6 +13,20 @@
#include "gpio-phytium-core.h"
+static const struct irq_chip phytium_gpio_irq_chip = {
+ .irq_ack = phytium_gpio_irq_ack,
+ .irq_mask = phytium_gpio_irq_mask,
+ .irq_unmask = phytium_gpio_irq_unmask,
+ .irq_set_type = phytium_gpio_irq_set_type,
+ .irq_print_chip = phytium_gpio_irq_print_chip,
+ .irq_enable = phytium_gpio_irq_enable,
+ .irq_disable = phytium_gpio_irq_disable,
+ .irq_set_wake = phytium_gpio_irq_set_wake,
+ .irq_set_affinity = phytium_gpio_irq_set_affinity,
+ .flags = IRQCHIP_IMMUTABLE,
+ GPIOCHIP_IRQ_RESOURCE_HELPERS,
+};
+
static int phytium_gpio_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)
{
struct device *dev = &pdev->dev;
@@ -50,23 +64,18 @@ static int phytium_gpio_pci_probe(struct pci_dev *pdev, const struct pci_device_
pci_set_master(pdev);
gpio->irq[0] = pdev->irq;
- if (gpio->irq < 0)
+ if (gpio->irq[0] < 0)
dev_warn(dev, "no irq is found.\n");
/* There is only one group of Pins at the moment. */
gpio->ngpio[0] = NGPIO_MAX;
/* irq_chip support */
- gpio->irq_chip.name = dev_name(dev);
- gpio->irq_chip.irq_ack = phytium_gpio_irq_ack;
- gpio->irq_chip.irq_mask = phytium_gpio_irq_mask;
- gpio->irq_chip.irq_unmask = phytium_gpio_irq_unmask;
- gpio->irq_chip.irq_set_type = phytium_gpio_irq_set_type;
- gpio->irq_chip.irq_enable = phytium_gpio_irq_enable;
- gpio->irq_chip.irq_disable = phytium_gpio_irq_disable;
-
raw_spin_lock_init(&gpio->lock);
+ writel(0, gpio->regs + GPIO_INTEN);
+ writel(GPIO_CLEAR_IRQ, gpio->regs + GPIO_PORTA_EOI);
+
gpio->gc.base = -1;
gpio->gc.get_direction = phytium_gpio_get_direction;
gpio->gc.direction_input = phytium_gpio_direction_input;
@@ -90,14 +99,14 @@ static int phytium_gpio_pci_probe(struct pci_dev *pdev, const struct pci_device_
girq->parents[0] = gpio->irq[0];
girq->parent_handler = phytium_gpio_irq_handler;
- girq->chip = &gpio->irq_chip;
+ gpio_irq_chip_set_chip(girq, &phytium_gpio_irq_chip);
err = devm_gpiochip_add_data(dev, &gpio->gc, gpio);
if (err)
goto out;
dev_info(dev, "Phytium PCI GPIO controller @%pa registered\n",
- &gpio->regs);
+ &pdev->resource[0].start);
pci_set_drvdata(pdev, gpio);
@@ -128,11 +137,14 @@ static int phytium_gpio_pci_suspend(struct device *dev)
gpio->ctx.ext_portb = readl(gpio->regs + GPIO_EXT_PORTB);
gpio->ctx.inten = readl(gpio->regs + GPIO_INTEN);
+ gpio->is_resuming = 1;
gpio->ctx.intmask = readl(gpio->regs + GPIO_INTMASK);
gpio->ctx.inttype_level = readl(gpio->regs + GPIO_INTTYPE_LEVEL);
gpio->ctx.int_polarity = readl(gpio->regs + GPIO_INT_POLARITY);
gpio->ctx.debounce = readl(gpio->regs + GPIO_DEBOUNCE);
+ writel(~gpio->ctx.wake_en, gpio->regs + GPIO_INTMASK);
+ writel(gpio->ctx.wake_en, gpio->regs + GPIO_INTEN);
raw_spin_unlock_irqrestore(&gpio->lock, flags);
return 0;
@@ -153,13 +165,15 @@ static int phytium_gpio_pci_resume(struct device *dev)
writel(gpio->ctx.swportb_ddr, gpio->regs + GPIO_SWPORTB_DDR);
writel(gpio->ctx.ext_portb, gpio->regs + GPIO_EXT_PORTB);
- writel(gpio->ctx.inten, gpio->regs + GPIO_INTEN);
writel(gpio->ctx.intmask, gpio->regs + GPIO_INTMASK);
writel(gpio->ctx.inttype_level, gpio->regs + GPIO_INTTYPE_LEVEL);
writel(gpio->ctx.int_polarity, gpio->regs + GPIO_INT_POLARITY);
writel(gpio->ctx.debounce, gpio->regs + GPIO_DEBOUNCE);
- writel(0xffffffff, gpio->regs + GPIO_PORTA_EOI);
+ writel(GPIO_CLEAR_IRQ, gpio->regs + GPIO_PORTA_EOI);
+
+ writel(gpio->ctx.inten, gpio->regs + GPIO_INTEN);
+ gpio->is_resuming = 0;
raw_spin_unlock_irqrestore(&gpio->lock, flags);
@@ -182,6 +196,7 @@ static struct pci_driver phytium_gpio_pci_driver = {
module_pci_driver(phytium_gpio_pci_driver);
-MODULE_LICENSE("GPL v2");
+MODULE_LICENSE("GPL");
MODULE_AUTHOR("Cheng Quan <chengquan@xxxxxxxxxxxxxx>");
MODULE_DESCRIPTION("Phytium GPIO PCI Driver");
+MODULE_VERSION(PHYTIUM_GPIO_DRIVER_VERSION);
--
2.34.1