Add Polarfire SoC GPIO support
Subsystems (3)
v3 cover Add Polarfire SoC GPIO support
From: Lewis Hanly <[email protected]>
Add a driver to support the Polarfire SoC gpio controller. Tested with 5.19-rc5
MPFS gpio interrupts can be configured as direct or
non direct connections to the PLIC (Platform Level Interrupt Controller). GPIO_INTERRUPT_FAB_CR(31:0) system register will enable GPIO2(31:0) corresponding interrupt on PLIC. e.g. If GPIO_INTERRUPT_FAB_CR bit0 is set then GPIO2 bit0 interrupt is available on the direct input pin on the PLIC.
Changes in v3:
Changed order in kconfig.
Removed blank lines in driver header/source file.
Removed BYTE_BOUNDARY variable and use macro to do *4. mpfs_gpio_assign_bit parameter uses macro instead of (i * BYTE_BOUNDARY). Add correct definitions for direction.
Change order of variables in mpfs_gpio_irq_set_type function. Return dev_err_probe instead of dev_err.
Remove noise of dev_inf.
Avoid using of_match_ptr.
use devm_gpiochip_add_data(..)
Update mpfs_gpio_remove.
Changes in v2:
Use raw_spinlock.
Use __assign_bit() to assign bit, added a bool variable for value. Remove unnecessary checking gpio_index.
Remove default from switch statement.
Use const for irq_chip, name updated and use mask/unmask. Use latest kernel api irq set_chip.
Implemented hierarchical interrupt chip support, although suggested to use chained interrupt flow I believe this fits better.
Lewis Hanly (1):
gpio: mpfs: add polarfire soc gpio support
drivers/gpio/Kconfig | 9 + drivers/gpio/Makefile | 1 + drivers/gpio/gpio-mpfs.c | 361 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 371 insertions(+) create mode 100644 drivers/gpio/gpio-mpfs.c
Signature · 1 line
2.25.1
PATCH v3 1/1 gpio: mpfs: add polarfire soc gpio support
From: Lewis Hanly <[email protected]>
Add a driver to support the Polarfire SoC gpio controller.
--- drivers/gpio/Kconfig | 9 + drivers/gpio/Makefile | 1 + drivers/gpio/gpio-mpfs.c | 361 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 371 insertions(+) create mode 100644 drivers/gpio/gpio-mpfs.c
drivers/gpio/Kconfig +9 -0
@@ -490,6 +490,15 @@ config GPIO_PMIC_EIC_SPRD help Say yes here to support Spreadtrum PMIC EIC device. +config GPIO_POLARFIRE_SOC + bool "Microchip FPGA GPIO support" + depends on OF_GPIO + select IRQ_DOMAIN_HIERARCHY + select GPIOLIB_IRQCHIP + select GPIO_GENERIC + help + Say yes here to support the GPIO device on Microchip FPGAs. + config GPIO_PXA bool "PXA GPIO support" depends on ARCH_PXA || ARCH_MMP || COMPILE_TEST
drivers/gpio/Makefile +1 -0
@@ -119,6 +119,7 @@ obj-$(CONFIG_GPIO_PCI_IDIO_16) += gpio-pci-idio-16.o obj-$(CONFIG_GPIO_PISOSR) += gpio-pisosr.o obj-$(CONFIG_GPIO_PL061) += gpio-pl061.o obj-$(CONFIG_GPIO_PMIC_EIC_SPRD) += gpio-pmic-eic-sprd.o +obj-$(CONFIG_GPIO_POLARFIRE_SOC) += gpio-mpfs.o obj-$(CONFIG_GPIO_PXA) += gpio-pxa.o obj-$(CONFIG_GPIO_RASPBERRYPI_EXP) += gpio-raspberrypi-exp.o obj-$(CONFIG_GPIO_RC5T583) += gpio-rc5t583.o
drivers/gpio/gpio-mpfs.c new file +361 -0
361 lines not on this page · raw message
Signature · 1 line
2.25.1
Re: [PATCH v3 1/1] gpio: mpfs: add polarfire soc gpio support
Quoted 6 lines · On Sat, 16 Jul 2022 08:11:13 +0100, <[email protected]> wrote:
From: Lewis Hanly <[email protected]>
Add a driver to support the Polarfire SoC gpio controller.
Signed-off-by Lewis Hanly <[email protected]>
[...]
drivers/gpio/gpio-mpfs.c line 244
Quoted 8 lines
drivers/gpio/gpio-mpfs.c new file +8
-0+static int mpfs_gpio_child_to_parent_hwirq (struct gpio_chip *gc, +unsigned int child, +unsigned int child_type, +unsigned int *parent, +unsigned int *parent_type) +{ +struct mpfs_gpio_chip *mpfs_gpio =gpiochip_get_data (gc); +struct irq_data *d =irq_get_irq_data (mpfs_gpio->irq_number[child]);
This looks totally wrong. It means that you have already instantiated part of the hierarchy, and it is likely that you will get multiple hierarchy sharing some levels, which isn't intended.
Quoted 46 lines
drivers/gpio/gpio-mpfs.c new file +46
-0+ *parent_type =IRQ_TYPE_NONE ; + *parent =irqd_to_hwirq (d); + +return 0 ; +} + +static int mpfs_gpio_probe (struct platform_device *pdev) +{ +struct clk *clk; +struct device *dev = &pdev->dev; +struct device_node *node = pdev->dev.of_node; +struct device_node *irq_parent; +struct gpio_irq_chip *girq; +struct irq_domain *parent; +struct mpfs_gpio_chip *mpfs_gpio; +int i, ret, ngpio; + + mpfs_gpio =devm_kzalloc (dev,sizeof (*mpfs_gpio),GFP_KERNEL ); +if (!mpfs_gpio) +return -ENOMEM ; + + mpfs_gpio->base =devm_platform_ioremap_resource (pdev,0 ); +if (IS_ERR (mpfs_gpio->base)) +return dev_err_probe (dev,PTR_ERR (mpfs_gpio->clk),"input clock not found.\n" ); + + clk =devm_clk_get (dev,NULL ); +if (IS_ERR (clk)) +return dev_err_probe (dev,PTR_ERR (clk),"devm_clk_get failed\n" ); + + ret =clk_prepare_enable (clk); +if (ret) +return dev_err_probe (dev, ret,"failed to enable clock\n" ); + + mpfs_gpio->clk = clk; + + ngpio =of_irq_count (node); +if (ngpio >NUM_GPIO ) { + ret = -ENXIO ; + goto cleanup_clock; + } + + irq_parent =of_irq_find_parent (node); +if (!irq_parent) { + ret = -ENODEV ; + goto cleanup_clock; + }
drivers/gpio/gpio-mpfs.c line 300
Quoted 10 lines
drivers/gpio/gpio-mpfs.c new file +10
-0+ parent =irq_find_host (irq_parent); +if (!parent) { + ret = -ENODEV ; + goto cleanup_clock; + } + +/* Get the interrupt numbers. */ +/* Clear/Disable All interrupts before enabling parent interrupts. */ +for (i =0 ; i < ngpio; i++) { + mpfs_gpio->irq_number[i] =platform_get_irq (pdev, i);
Bingo. You are allocating the interrupt for the level below. You really shouldn't do that.
If you need to retrieve the *hwirq* for the level below, you need to parse the DT without triggering an IRQ allocation (of_irq_parse_one() and co).
M.
Signature · 1 line
Without deviation from the norm, progress is not possible.
Re: [PATCH v3 1/1] gpio: mpfs: add polarfire soc gpio support
Thanks Marc,
Quoted 21 lines · Marc Zyngier
EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe
Quoted 5 lines · On Sat, 16 Jul 2022 08:11:13 +0100, <[email protected]> wrote:
From: Lewis Hanly <[email protected]>
Add a driver to support the Polarfire SoC gpio controller.
Signed-off-by Lewis Hanly <[email protected]>[...]
Quoted 8 lines
drivers/gpio/gpio-mpfs.c new file +8
-0+static int mpfs_gpio_child_to_parent_hwirq (struct gpio_chip *gc, +unsigned int child, +unsigned int child_type, +unsigned int *parent, +unsigned int *parent_type) +{ +struct mpfs_gpio_chip *mpfs_gpio =gpiochip_get_data (gc); + struct irq_data *d = irq_get_irq_data(mpfs_gpio-
Quoted 5 lines
Quoted 1 line
Quoted 1 line
irq_number[child]);
This looks totally wrong. It means that you have already instantiated part of the hierarchy, and it is likely that you will get multiple hierarchy sharing some levels, which isn't intended.
Some background why I use the above.
We need to support both direct and non-direct IRQ connections to the PLIC.
In direct mode the GPIO IRQ's are connected directly to the PLIC and certainly no need for the above. GPIO's can also be configured in non- direct, which means they use a shared IRQ, hence the above.
Quoted 74 lines
Quoted 60 lines
drivers/gpio/gpio-mpfs.c new file +18
-0+ *parent_type =IRQ_TYPE_NONE ; + *parent =irqd_to_hwirq (d); + +return 0 ; +} + +static int mpfs_gpio_probe (struct platform_device *pdev) +{ +struct clk *clk; +struct device *dev = &pdev->dev; +struct device_node *node = pdev->dev.of_node; +struct device_node *irq_parent; +struct gpio_irq_chip *girq; +struct irq_domain *parent; +struct mpfs_gpio_chip *mpfs_gpio; +int i, ret, ngpio; + + mpfs_gpio = devm_kzalloc(dev, sizeof(*mpfs_gpio),
GFP_KERNEL);drivers/gpio/gpio-mpfs.c new file +6
-0+if (!mpfs_gpio) +return -ENOMEM ; + + mpfs_gpio->base =devm_platform_ioremap_resource (pdev,0 ); +if (IS_ERR (mpfs_gpio->base)) + return dev_err_probe(dev, PTR_ERR(mpfs_gpio->clk),"input clock not found.\n");
drivers/gpio/gpio-mpfs.c new file +4
-0+ + clk =devm_clk_get (dev,NULL ); +if (IS_ERR (clk)) + return dev_err_probe(dev, PTR_ERR(clk), "devm_clk_getfailed\n");
drivers/gpio/gpio-mpfs.c new file +4
-0+ + ret =clk_prepare_enable (clk); +if (ret) + return dev_err_probe(dev, ret, "failed to enableclock\n");
drivers/gpio/gpio-mpfs.c new file +22
-0+ + mpfs_gpio->clk = clk; + + ngpio =of_irq_count (node); +if (ngpio >NUM_GPIO ) { + ret = -ENXIO ; + goto cleanup_clock; + } + + irq_parent =of_irq_find_parent (node); +if (!irq_parent) { + ret = -ENODEV ; + goto cleanup_clock; + } + parent =irq_find_host (irq_parent); +if (!parent) { + ret = -ENODEV ; + goto cleanup_clock; + } + +/* Get the interrupt numbers. */ +/* Clear/Disable All interrupts before enabling parent interrupts. */
drivers/gpio/gpio-mpfs.c line 300
Quoted 2 lines
drivers/gpio/gpio-mpfs.c new file +2
-0+for (i =0 ; i < ngpio; i++) { + mpfs_gpio->irq_number[i] =platform_get_irq (pdev, i);Bingo. You are allocating the interrupt for the level below. You really shouldn't do that.
If you need to retrieve the *hwirq* for the level below, you need to parse the DT without triggering an IRQ allocation (
of_irq_parse_one()and co).M.--
Without deviation from the norm, progress is not possible.
Re: [PATCH v3 1/1] gpio: mpfs: add polarfire soc gpio support
Quoted 31 lines · On Sat, 16 Jul 2022 16:21:48 +0100, <[email protected]> wrote:
Thanks Marc,
Quoted 21 lines · Marc Zyngier
EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe
Quoted 5 lines · On Sat, 16 Jul 2022 08:11:13 +0100, <[email protected]> wrote:
From: Lewis Hanly <[email protected]>
Add a driver to support the Polarfire SoC gpio controller.
Signed-off-by Lewis Hanly <[email protected]>[...]
Quoted 8 lines
drivers/gpio/gpio-mpfs.c new file +8
-0+static int mpfs_gpio_child_to_parent_hwirq (struct gpio_chip *gc, +unsigned int child, +unsigned int child_type, +unsigned int *parent, +unsigned int *parent_type) +{ +struct mpfs_gpio_chip *mpfs_gpio =gpiochip_get_data (gc); + struct irq_data *d = irq_get_irq_data(mpfs_gpio-Quoted 5 lines
Quoted 1 line
Quoted 1 line
irq_number[child]);
This looks totally wrong. It means that you have already instantiated part of the hierarchy, and it is likely that you will get multiple hierarchy sharing some levels, which isn't intended.
Quoted 6 lines
Some background why I use the above.
We need to support both direct and non-direct IRQ connections to the PLIC.
In direct mode the GPIO IRQ's are connected directly to the PLIC and certainly no need for the above. GPIO's can also be configured in non- direct, which means they use a shared IRQ, hence the above.
That's unfortunately not acceptable. You need to distinguish which one is which, and separate them. Your non-direct mode certainly requires special handling, and is not fit for a hierarchical mode.
M.
Signature · 1 line
Without deviation from the norm, progress is not possible.
[email protected]
maintainerRe: [PATCH v3 1/1] gpio: mpfs: add polarfire soc gpio support
Quoted 40 lines · Marc Zyngier
Quoted 31 lines · On Sat, 16 Jul 2022 16:21:48 +0100, <[email protected]> wrote:
Thanks Marc,
Quoted 21 lines · Marc Zyngier
EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe
Quoted 5 lines · On Sat, 16 Jul 2022 08:11:13 +0100, <[email protected]> wrote:
From: Lewis Hanly <[email protected]>
Add a driver to support the Polarfire SoC gpio controller.
Signed-off-by Lewis Hanly <[email protected]>[...]
Quoted 8 lines
drivers/gpio/gpio-mpfs.c new file +8
-0+static int mpfs_gpio_child_to_parent_hwirq (struct gpio_chip *gc, +unsigned int child, +unsigned int child_type, +unsigned int *parent, +unsigned int *parent_type) +{ +struct mpfs_gpio_chip *mpfs_gpio =gpiochip_get_data (gc); + struct irq_data *d = irq_get_irq_data(mpfs_gpio-Quoted 5 lines
Quoted 1 line
Quoted 1 line
irq_number[child]);
This looks totally wrong. It means that you have already instantiated part of the hierarchy, and it is likely that you will get multiple hierarchy sharing some levels, which isn't intended.
Quoted 6 lines
Some background why I use the above.
We need to support both direct and non-direct IRQ connections to the PLIC.
In direct mode the GPIO IRQ's are connected directly to the PLIC and certainly no need for the above. GPIO's can also be configured in non- direct, which means they use a shared IRQ, hence the above.
Quoted 3 lines
That's unfortunately not acceptable. You need to distinguish which one is which, and separate them. Your non-direct mode certainly requires special handling, and is not fit for a hierarchical mode.
Unfortunately, the configuration is not fixed on the silicon level. The SoC has 3 GPIOs (with 32 lines each). The interrupt configuration looks something like the below:
GPIO# width IRQ#
==================================
gpio0/2 14 [26:13] gpio1/2 24 [50:27] gpio0_non_direct 1 51 gpio1_non_direct 1 52 gpio2_non_direct 1 53
Depending on what the bootloader/firmware does, these can be configured differently (done prior to linux starting). By default, 14 GPIOs from GPIO0 are fed into their own interrupt lines & ditto for 24 from GPIO1. The remaining GPIO0 & GPIO1 lines go into the corresponding non-direct interrupt. If they bootloader/firmware configures something different, a "direct" interrupt line can be switched to a GPIO2 line instead.
Something like the following (the interrupts are offset by 13 here, as the global interrupts feed into the PLIC at an offset):
* global int GPIO_INTERRUPT_FAB_CR
0 1
0 GPIO0 bit 0 GPIO2 bit 0
1 GPIO0 bit 1 GPIO2 bit 1
.
.
12 GPIO0 bit 12 GPIO2 bit 12
13 GPIO0 bit 13 GPIO2 bit 13
14 GPIO1 bit 0 GPIO2 bit 14
15 GPIO1 bit 1 GPIO2 bit 15
.
.
.
30 GPIO1 bit 16 GPIO2 bit 30
31 GPIO1 bit 17 GPIO2 bit 31
32 GPIO1 bit 18
33 GPIO1 bit 19
34 GPIO1 bit 20
35 GPIO1 bit 21
36 GPIO1 bit 22
37 GPIO1 bit 23
38 Or of all GPIO0 interrupts who do not have a direct connection enabled 39 Or of all GPIO1 interrupts who do not have a direct connection enabled 40 Or of all GPIO2 interrupts who do not have a direct connection enabled
Since we can tell based on the interrupt number in the device tree whether a line is in direct mode - can you suggest what the most appropriate irq structure for the driver?
Although for extending this driver to the "soft" IP core, it may be easier to just create a "microchip,gpio-direct-mode-mask" property or similar and use that to figure out what configuration a line is in.
Thanks,
Conor.
Re: [PATCH v3 1/1] gpio: mpfs: add polarfire soc gpio support
Quoted 42 lines · On Sat, 16 Jul 2022 19:32:20 +0100, <[email protected]> wrote:
Quoted 40 lines · Marc Zyngier
Quoted 37 lines · On Sat, 16 Jul 2022 16:21:48 +0100, <[email protected]> wrote:
Thanks Marc,
Quoted 21 lines · Marc Zyngier
EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe
Quoted 5 lines · On Sat, 16 Jul 2022 08:11:13 +0100, <[email protected]> wrote:
From: Lewis Hanly <[email protected]>
Add a driver to support the Polarfire SoC gpio controller.
Signed-off-by Lewis Hanly <[email protected]>[...]
Quoted 8 lines
drivers/gpio/gpio-mpfs.c new file +8
-0+static int mpfs_gpio_child_to_parent_hwirq (struct gpio_chip *gc, +unsigned int child, +unsigned int child_type, +unsigned int *parent, +unsigned int *parent_type) +{ +struct mpfs_gpio_chip *mpfs_gpio =gpiochip_get_data (gc); + struct irq_data *d = irq_get_irq_data(mpfs_gpio-Quoted 5 lines
Quoted 1 line
Quoted 1 line
irq_number[child]);
This looks totally wrong. It means that you have already instantiated part of the hierarchy, and it is likely that you will get multiple hierarchy sharing some levels, which isn't intended.
Some background why I use the above.
We need to support both direct and non-direct IRQ connections to the PLIC.
In direct mode the GPIO IRQ's are connected directly to the PLIC and certainly no need for the above. GPIO's can also be configured in non- direct, which means they use a shared IRQ, hence the above.
Quoted 6 lines
Quoted 3 lines
That's unfortunately not acceptable. You need to distinguish which one is which, and separate them. Your non-direct mode certainly requires special handling, and is not fit for a hierarchical mode.
Unfortunately, the configuration is not fixed on the silicon level. The SoC has 3 GPIOs (with 32 lines each). The interrupt configuration looks
Let's start with a bit of terminology so that we can understand each other:
- GPIO: a single piece of wire
- GPIO block: a set of wires with a common programming interface
As I understand it, you have 3 GPIO blocks, each with 32 GPIOs, for a total of 96 external lines. Correct?
Quoted 9 lines
something like the below:
GPIO# width IRQ#
==================================gpio0/2 14 [26:13] gpio1/2 24 [50:27] gpio0_non_direct 1 51 gpio1_non_direct 1 52 gpio2_non_direct 1 53
Quoted 6 lines
Depending on what the bootloader/firmware does, these can be configured differently (done prior to linux starting). By default, 14 GPIOs from GPIO0 are fed into their own interrupt lines & ditto for 24 from GPIO1. The remaining GPIO0 & GPIO1 lines go into the corresponding non-direct interrupt. If they bootloader/firmware configures something different, a "direct" interrupt line can be switched to a GPIO2 line instead.
What does non-direct mean? Multiplexing inputs into a single output? Can you individually mask/unmask the input lines that are in this mode (the kernel calls this a "chained irqchip")?
How does this switch between direct and non-direct happen? Do you have some sort of external pad to GPIO line routing? It would really help if you could point people at an actual specification for these blocks rather than paraphrasing things.
Quoted 29 lines
Something like the following (the interrupts are offset by 13 here, as the global interrupts feed into the PLIC at an offset):
* global int
GPIO_INTERRUPT_FAB_CR
0 1
0 GPIO0 bit 0 GPIO2 bit 0
1 GPIO0 bit 1 GPIO2 bit 1
.
.
12 GPIO0 bit 12 GPIO2 bit 12
13 GPIO0 bit 13 GPIO2 bit 13
14 GPIO1 bit 0 GPIO2 bit 14
15 GPIO1 bit 1 GPIO2 bit 15
.
.
.
30 GPIO1 bit 16 GPIO2 bit 30
31 GPIO1 bit 17 GPIO2 bit 31
32 GPIO1 bit 18
33 GPIO1 bit 19
34 GPIO1 bit 20
35 GPIO1 bit 21
36 GPIO1 bit 22
37 GPIO1 bit 23
38 Or of all GPIO0 interrupts who do not have a direct connection enabled 39 Or of all GPIO1 interrupts who do not have a direct connection enabled 40 Or of all GPIO2 interrupts who do not have a direct connection enabled
Quoted 3 lines
Since we can tell based on the interrupt number in the device tree whether a line is in direct mode - can you suggest what the most appropriate irq structure for the driver?
The topology must be described in DT one way or another, and I don't really want to rely on a fixed interrupt number that will change from one version to another.
In any case:
- direct interrupts should be handled as a hierarchy, mostly like the code currently does, but definitely without the probing hack.
- muxed interrupts (non-direct?) should be handled via a chained irqchip, using a different irqdomain, as the topology is radically different.
Quoted 3 lines
Although for extending this driver to the "soft" IP core, it may be easier to just create a "microchip,gpio-direct-mode-mask" property or similar and use that to figure out what configuration a line is in.
My guts feeling is that this will eventually end-up biting you, as people will want to change the direct/non-direct status of an interrupt at boot time, without depending on the FW to do that on their behalf.
I'm not necessarily advocating for this as this is a lot more code and it could totally invalidate the existing binding, but this is worth keeping in mind.
In any case, this driver needs some serious rewriting.
Thanks,
M.
Signature · 1 line
Without deviation from the norm, progress is not possible.
[email protected]
maintainerRe: [PATCH v3 1/1] gpio: mpfs: add polarfire soc gpio support
Quoted 51 lines · Marc Zyngier
Quoted 42 lines · On Sat, 16 Jul 2022 19:32:20 +0100, <[email protected]> wrote:
Quoted 40 lines · Marc Zyngier
Quoted 37 lines · On Sat, 16 Jul 2022 16:21:48 +0100, <[email protected]> wrote:
Thanks Marc,
Quoted 21 lines · Marc Zyngier
EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe
Quoted 5 lines · On Sat, 16 Jul 2022 08:11:13 +0100, <[email protected]> wrote:
From: Lewis Hanly <[email protected]>
Add a driver to support the Polarfire SoC gpio controller.
Signed-off-by Lewis Hanly <[email protected]>[...]
Quoted 8 lines
drivers/gpio/gpio-mpfs.c new file +8
-0+static int mpfs_gpio_child_to_parent_hwirq (struct gpio_chip *gc, +unsigned int child, +unsigned int child_type, +unsigned int *parent, +unsigned int *parent_type) +{ +struct mpfs_gpio_chip *mpfs_gpio =gpiochip_get_data (gc); + struct irq_data *d = irq_get_irq_data(mpfs_gpio-Quoted 5 lines
Quoted 1 line
Quoted 1 line
irq_number[child]);
This looks totally wrong. It means that you have already instantiated part of the hierarchy, and it is likely that you will get multiple hierarchy sharing some levels, which isn't intended.
Some background why I use the above.
We need to support both direct and non-direct IRQ connections to the PLIC.
In direct mode the GPIO IRQ's are connected directly to the PLIC and certainly no need for the above. GPIO's can also be configured in non- direct, which means they use a shared IRQ, hence the above.Quoted 6 lines
Quoted 3 lines
That's unfortunately not acceptable. You need to distinguish which one is which, and separate them. Your non-direct mode certainly requires special handling, and is not fit for a hierarchical mode.
Unfortunately, the configuration is not fixed on the silicon level. The SoC has 3 GPIOs (with 32 lines each). The interrupt configuration looks
Quoted 7 lines
Let's start with a bit of terminology so that we can understand each other:
- GPIO: a single piece of wire
- GPIO block: a set of wires with a common programming interfaceAs I understand it, you have 3 GPIO blocks, each with 32 GPIOs, for a total of 96 external lines. Correct?
Correct.
Quoted 10 lines
Quoted 10 lines
something like the below:
GPIO# width IRQ#
==================================gpio0/2 14 [26:13] gpio1/2 24 [50:27] gpio0_non_direct 1 51 gpio1_non_direct 1 52 gpio2_non_direct 1 53
Quoted 8 lines
Quoted 6 lines
Depending on what the bootloader/firmware does, these can be configured differently (done prior to linux starting). By default, 14 GPIOs from GPIO0 are fed into their own interrupt lines & ditto for 24 from GPIO1. The remaining GPIO0 & GPIO1 lines go into the corresponding non-direct interrupt. If they bootloader/firmware configures something different, a "direct" interrupt line can be switched to a GPIO2 line instead.
What does non-direct mean? Multiplexing inputs into a single output?
non-direct being "not directly connected to the PLIC", so yes. The interrupts without a direct connection are muxed into a per GPIO block interrupt.
Quoted 2 lines
Can you individually mask/unmask the input lines that are in this mode (the kernel calls this a "chained irqchip")?
Each GPIO line has an interrupt enable bit in it's config register.
Quoted 5 lines
How does this switch between direct and non-direct happen? Do you have some sort of external pad to GPIO line routing? It would really help if you could point people at an actual specification for these blocks rather than paraphrasing things.
GPIO is discussed on page 85 of the TRM:
https://www.microsemi.com/document-portal/doc_download/1245725-polarfire-soc-fpga-mss-technical-reference-manual
The register map is here:
https://ww1.microchip.com/downloads/aemDocuments/documents/FPGA/ProductDocuments/SupportingCollateral/V1_4_Register_Map.zip
PFSOC_MSS_TOP_SYSREG/GPIO_INTERRUPT_FAB_CR is the register that can switch a line between direct/non-direct mode.
GPIO_*_LO are as you might expect are the GPIO block registers
Quoted 30 lines
Quoted 30 lines
Something like the following (the interrupts are offset by 13 here, as the global interrupts feed into the PLIC at an offset):
* global int
GPIO_INTERRUPT_FAB_CR
0 1
0 GPIO0 bit 0 GPIO2 bit 0
1 GPIO0 bit 1 GPIO2 bit 1
.
.
12 GPIO0 bit 12 GPIO2 bit 12
13 GPIO0 bit 13 GPIO2 bit 13
14 GPIO1 bit 0 GPIO2 bit 14
15 GPIO1 bit 1 GPIO2 bit 15
.
.
.
30 GPIO1 bit 16 GPIO2 bit 30
31 GPIO1 bit 17 GPIO2 bit 31
32 GPIO1 bit 18
33 GPIO1 bit 19
34 GPIO1 bit 20
35 GPIO1 bit 21
36 GPIO1 bit 22
37 GPIO1 bit 23
38 Or of all GPIO0 interrupts who do not have a direct connection enabled 39 Or of all GPIO1 interrupts who do not have a direct connection enabled 40 Or of all GPIO2 interrupts who do not have a direct connection enabled
Quoted 7 lines
Quoted 3 lines
Since we can tell based on the interrupt number in the device tree whether a line is in direct mode - can you suggest what the most appropriate irq structure for the driver?
The topology must be described in DT one way or another, and I don't really want to rely on a fixed interrupt number that will change from one version to another.
Yeah, that was my gut feeling too.
Quoted 9 lines
In any case:
- direct interrupts should be handled as a hierarchy, mostly like the code currently does, but definitely without the probing hack.
- muxed interrupts (non-direct?) should be handled via a chained irqchip, using a different irqdomain, as the topology is radically different.
Thanks.
Quoted 9 lines
Quoted 4 lines
Although for extending this driver to the "soft" IP core, it may be easier to just create a "microchip,gpio-direct-mode-mask" property or similar and use that to figure out what configuration a line is in.
My guts feeling is that this will eventually end-up biting you, as people will want to change the direct/non-direct status of an interrupt at boot time, without depending on the FW to do that on their behalf.
I am inclined to not allow that in all honesty. Because this is an FPGA, there's configuration based on the contents of the FPGA fabric that has to be done by something before an OS can be brought up & we have to draw a line somewhere for what's reasonable for Linux to do.
Quoted 2 lines
In any case, this driver needs some serious rewriting.
Thanks for your help Marc.
Re: [PATCH v3 1/1] gpio: mpfs: add polarfire soc gpio support
In reply to Marc ZyngierQuoted 21 lines · Marc Zyngier
EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe
Quoted 5 lines · On Sat, 16 Jul 2022 08:11:13 +0100, <[email protected]> wrote:
From: Lewis Hanly <[email protected]>
Add a driver to support the Polarfire SoC gpio controller.
Signed-off-by Lewis Hanly <[email protected]>[...]
Quoted 8 lines
drivers/gpio/gpio-mpfs.c new file +8
-0+static int mpfs_gpio_child_to_parent_hwirq (struct gpio_chip *gc, +unsigned int child, +unsigned int child_type, +unsigned int *parent, +unsigned int *parent_type) +{ +struct mpfs_gpio_chip *mpfs_gpio =gpiochip_get_data (gc); + struct irq_data *d = irq_get_irq_data(mpfs_gpio-
Quoted 5 lines
Quoted 1 line
Quoted 1 line
irq_number[child]);
This looks totally wrong. It means that you have already instantiated part of the hierarchy, and it is likely that you will get multiple hierarchy sharing some levels, which isn't intended.
Thanks Marc, as you have pointed out the hierarchical interrupt flow is not fitting our hw. I am in the process of reworking the driver to implement chained interrupt flow as you pointed out before.
Quoted 74 lines
Quoted 60 lines
drivers/gpio/gpio-mpfs.c new file +18
-0+ *parent_type =IRQ_TYPE_NONE ; + *parent =irqd_to_hwirq (d); + +return 0 ; +} + +static int mpfs_gpio_probe (struct platform_device *pdev) +{ +struct clk *clk; +struct device *dev = &pdev->dev; +struct device_node *node = pdev->dev.of_node; +struct device_node *irq_parent; +struct gpio_irq_chip *girq; +struct irq_domain *parent; +struct mpfs_gpio_chip *mpfs_gpio; +int i, ret, ngpio; + + mpfs_gpio = devm_kzalloc(dev, sizeof(*mpfs_gpio),
GFP_KERNEL);drivers/gpio/gpio-mpfs.c new file +6
-0+if (!mpfs_gpio) +return -ENOMEM ; + + mpfs_gpio->base =devm_platform_ioremap_resource (pdev,0 ); +if (IS_ERR (mpfs_gpio->base)) + return dev_err_probe(dev, PTR_ERR(mpfs_gpio->clk),"input clock not found.\n");
drivers/gpio/gpio-mpfs.c new file +4
-0+ + clk =devm_clk_get (dev,NULL ); +if (IS_ERR (clk)) + return dev_err_probe(dev, PTR_ERR(clk), "devm_clk_getfailed\n");
drivers/gpio/gpio-mpfs.c new file +4
-0+ + ret =clk_prepare_enable (clk); +if (ret) + return dev_err_probe(dev, ret, "failed to enableclock\n");
drivers/gpio/gpio-mpfs.c new file +22
-0+ + mpfs_gpio->clk = clk; + + ngpio =of_irq_count (node); +if (ngpio >NUM_GPIO ) { + ret = -ENXIO ; + goto cleanup_clock; + } + + irq_parent =of_irq_find_parent (node); +if (!irq_parent) { + ret = -ENODEV ; + goto cleanup_clock; + } + parent =irq_find_host (irq_parent); +if (!parent) { + ret = -ENODEV ; + goto cleanup_clock; + } + +/* Get the interrupt numbers. */ +/* Clear/Disable All interrupts before enabling parent interrupts. */
drivers/gpio/gpio-mpfs.c line 300
Quoted 2 lines
drivers/gpio/gpio-mpfs.c new file +2
-0+for (i =0 ; i < ngpio; i++) { + mpfs_gpio->irq_number[i] =platform_get_irq (pdev, i);Bingo. You are allocating the interrupt for the level below. You really shouldn't do that.
If you need to retrieve the *hwirq* for the level below, you need to parse the DT without triggering an IRQ allocation (
of_irq_parse_one()and co).M.--
Without deviation from the norm, progress is not possible.
Re: [PATCH v3 1/1] gpio: mpfs: add polarfire soc gpio support
In reply to [email protected]Quoted 5 lines · On Sat, 16 Jul 2022 08:11:13 +0100, <[email protected]> wrote:
From: Lewis Hanly <[email protected]>
Add a driver to support the Polarfire SoC gpio controller.
Quoted 7 lines
Signed-off-by Lewis Hanly <[email protected]>--- drivers/gpio/Kconfig | 9 + drivers/gpio/Makefile | 1 + drivers/gpio/gpio-mpfs.c | 361 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 371 insertions(+) create mode 100644 drivers/gpio/gpio-mpfs.c
A couple of other nits:
drivers/gpio/gpio-mpfs.c line 349
Quoted 2 lines
drivers/gpio/gpio-mpfs.c new file +2
-0+static const struct of_device_id mpfs_of_ids[] = { + { .compatible ="microchip,mpfs-gpio" , },
Where is the DT binding for this?
drivers/gpio/gpio-mpfs.c line 359
Quoted 10 lines
drivers/gpio/gpio-mpfs.c new file +10
-0+ {/* end of list */ } +}; + +static struct platform_driver mpfs_gpio_driver = { + .probe = mpfs_gpio_probe, + .driver = { + .name ="microchip,mpfs-gpio" , + .of_match_table = mpfs_of_ids, + }, + .remove = mpfs_gpio_remove,
No, please. You cannot enforce that there are no interrupts being used (and nothing checks for this), and you're pretty much guaranteed that the system will catch fire on the first interrupt being delivered. Moreover, your "remove" callback only turns the clock off, which is yet another nail on that coffin.
M.
Signature · 1 line
Without deviation from the norm, progress is not possible.
Re: [PATCH v3 1/1] gpio: mpfs: add polarfire soc gpio support
Quoted 17 lines · Marc Zyngier
EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe
Quoted 5 lines · On Sat, 16 Jul 2022 08:11:13 +0100, <[email protected]> wrote:
From: Lewis Hanly <[email protected]>
Add a driver to support the Polarfire SoC gpio controller.
Quoted 7 lines
Signed-off-by Lewis Hanly <[email protected]>--- drivers/gpio/Kconfig | 9 + drivers/gpio/Makefile | 1 + drivers/gpio/gpio-mpfs.c | 361 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 371 insertions(+)create mode 100644
drivers/gpio/gpio-mpfs.c
Quoted 6 lines
A couple of other nits:
drivers/gpio/gpio-mpfs.c line 349
Quoted 2 lines
drivers/gpio/gpio-mpfs.c new file +2
-0+static const struct of_device_id mpfs_of_ids[] = { + { .compatible ="microchip,mpfs-gpio" , },Where is the DT binding for this?
Already upstream, Documentation/devicetree/bindings/gpio/microchip%2Cmpfs-gpio.yaml
Quoted 17 lines
drivers/gpio/gpio-mpfs.c line 359
Quoted 11 lines
drivers/gpio/gpio-mpfs.c new file +10
-0+ {/* end of list */ } +}; + +static struct platform_driver mpfs_gpio_driver = { + .probe = mpfs_gpio_probe, + .driver = { + .name ="microchip,mpfs-gpio" , + .of_match_table = mpfs_of_ids, + }, + .remove = mpfs_gpio_remove,No, please. You cannot enforce that there are no interrupts being used (and nothing checks for this), and you're pretty much guaranteed that the system will catch fire on the first interrupt being delivered. Moreover, your "remove" callback only turns the clock off, which is yet another nail on that coffin.
Will remove.
Quoted 5 lines
M.--
Without deviation from the norm, progress is not possible.
[email protected]
maintainerRe: [PATCH v3 1/1] gpio: mpfs: add polarfire soc gpio support
In reply to Marc ZyngierQuoted 8 lines · Marc Zyngier
EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe A couple of other nits:
drivers/gpio/gpio-mpfs.c line 349
Quoted 2 lines
drivers/gpio/gpio-mpfs.c new file +2
-0+static const struct of_device_id mpfs_of_ids[] = { + { .compatible ="microchip,mpfs-gpio" , },Where is the DT binding for this?
Upstreamed with the device tree entry in 5.18:Documentation/devicetree/bindings/gpio/microchip,mpfs-gpio.yaml
Lewis: might be worth mentioning that in your cover letters.
Thanks,
Conor.
_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv