[PATCH 1/2] gpio: cadence: Add quirk for Axiado AX3000 platform

Swark Yang posted 2 patches 1 month, 2 weeks ago
There is a newer version of this series
[PATCH 1/2] gpio: cadence: Add quirk for Axiado AX3000 platform
Posted by Swark Yang 1 month, 2 weeks ago
On the Axiado AX3000 platform, pinmux and pin configuration (such as
direction and output enable) are configured by the hardware/firmware
at boot time before Linux boots.

To prevent conflicts, introduce a platform-specific quirk triggered by
the "axiado,ax3000-gpio" compatible string.

When this quirk is active, the driver will skip its default
initialization of pinmux configuration and direction settings during
probe.

Co-developed-by: Tzu-Hao Wei <twei@axiado.com>
Signed-off-by: Tzu-Hao Wei <twei@axiado.com>
Signed-off-by: Swark Yang <syang@axiado.com>
Signed-off-by: Prasad Bolisetty <pbolisetty@axiado.com>
---
 drivers/gpio/gpio-cadence.c | 53 +++++++++++++++++++++++++++++++++++----------
 1 file changed, 42 insertions(+), 11 deletions(-)

diff --git a/drivers/gpio/gpio-cadence.c b/drivers/gpio/gpio-cadence.c
index b75734ca22dd..b9f39566b0f9 100644
--- a/drivers/gpio/gpio-cadence.c
+++ b/drivers/gpio/gpio-cadence.c
@@ -6,6 +6,9 @@
  * Authors:
  *  Jan Kotas <jank@cadence.com>
  *  Boris Brezillon <boris.brezillon@free-electrons.com>
+ *
+ * Copyright (C) 2025 Axiado Corporation.
+ *
  */
 
 #include <linux/cleanup.h>
@@ -31,12 +34,18 @@
 #define CDNS_GPIO_IRQ_VALUE		0x28
 #define CDNS_GPIO_IRQ_ANY_EDGE		0x2c
 
+#define CDNS_GPIO_QUIRKS_SKIP_PINMUX_CFG	BIT(1)
+
 struct cdns_gpio_chip {
 	struct gpio_generic_chip gen_gc;
 	void __iomem *regs;
 	u32 bypass_orig;
 };
 
+struct cdns_platform_data {
+	u32 quirks;
+};
+
 static int cdns_gpio_request(struct gpio_chip *chip, unsigned int offset)
 {
 	struct cdns_gpio_chip *cgpio = gpiochip_get_data(chip);
@@ -141,6 +150,16 @@ static const struct irq_chip cdns_gpio_irqchip = {
 	GPIOCHIP_IRQ_RESOURCE_HELPERS,
 };
 
+static const struct cdns_platform_data ax3000_gpio_def = {
+	.quirks = CDNS_GPIO_QUIRKS_SKIP_PINMUX_CFG, };
+
+static const struct of_device_id cdns_of_ids[] = {
+	{ .compatible = "axiado,ax3000-gpio", .data = &ax3000_gpio_def },
+	{ .compatible = "cdns,gpio-r1p02" },
+	{ /* sentinel */ },
+};
+MODULE_DEVICE_TABLE(of, cdns_of_ids);
+
 static int cdns_gpio_probe(struct platform_device *pdev)
 {
 	struct gpio_generic_chip_config config = { };
@@ -148,6 +167,8 @@ static int cdns_gpio_probe(struct platform_device *pdev)
 	int ret, irq;
 	u32 dir_prev;
 	u32 num_gpios = 32;
+	bool skip_pinmux_cfg = false;
+	const struct of_device_id *match;
 	struct clk *clk;
 
 	cgpio = devm_kzalloc(&pdev->dev, sizeof(*cgpio), GFP_KERNEL);
@@ -165,6 +186,13 @@ static int cdns_gpio_probe(struct platform_device *pdev)
 		return -EINVAL;
 	}
 
+	match = of_match_node(cdns_of_ids, pdev->dev.of_node);
+	if (match && match->data) {
+		const struct cdns_platform_data *data = match->data;
+
+		skip_pinmux_cfg = data->quirks & CDNS_GPIO_QUIRKS_SKIP_PINMUX_CFG;
+	}
+
 	/*
 	 * Set all pins as inputs by default, otherwise:
 	 * gpiochip_lock_as_irq:
@@ -173,8 +201,15 @@ static int cdns_gpio_probe(struct platform_device *pdev)
 	 * so it needs to be changed before gpio_generic_chip_init() is called.
 	 */
 	dir_prev = ioread32(cgpio->regs + CDNS_GPIO_DIRECTION_MODE);
-	iowrite32(GENMASK(num_gpios - 1, 0),
-		  cgpio->regs + CDNS_GPIO_DIRECTION_MODE);
+
+	/*
+	 * The AX3000 platform performs the required configuration at boot time
+	 * before Linux boots, so this quirk disables pinmux initialization.
+	 */
+	if (!skip_pinmux_cfg) {
+		iowrite32(GENMASK(num_gpios - 1, 0),
+			  cgpio->regs + CDNS_GPIO_DIRECTION_MODE);
+	}
 
 	config.dev = &pdev->dev;
 	config.sz = 4;
@@ -240,9 +275,11 @@ static int cdns_gpio_probe(struct platform_device *pdev)
 	/*
 	 * Enable gpio outputs, ignored for input direction
 	 */
-	iowrite32(GENMASK(num_gpios - 1, 0),
-		  cgpio->regs + CDNS_GPIO_OUTPUT_EN);
-	iowrite32(0, cgpio->regs + CDNS_GPIO_BYPASS_MODE);
+	if (!skip_pinmux_cfg) {
+		iowrite32(GENMASK(num_gpios - 1, 0),
+			  cgpio->regs + CDNS_GPIO_OUTPUT_EN);
+		iowrite32(0, cgpio->regs + CDNS_GPIO_BYPASS_MODE);
+	}
 
 	platform_set_drvdata(pdev, cgpio);
 	return 0;
@@ -260,12 +297,6 @@ static void cdns_gpio_remove(struct platform_device *pdev)
 	iowrite32(cgpio->bypass_orig, cgpio->regs + CDNS_GPIO_BYPASS_MODE);
 }
 
-static const struct of_device_id cdns_of_ids[] = {
-	{ .compatible = "cdns,gpio-r1p02" },
-	{ /* sentinel */ },
-};
-MODULE_DEVICE_TABLE(of, cdns_of_ids);
-
 static struct platform_driver cdns_gpio_driver = {
 	.driver = {
 		.name = "cdns-gpio",

-- 
2.25.1
Re: [PATCH 1/2] gpio: cadence: Add quirk for Axiado AX3000 platform
Posted by Linus Walleij 1 month, 1 week ago
Hi Swark,

thanks for your patch!

On Tue, Dec 23, 2025 at 8:30 AM Swark Yang <syang@axiado.com> wrote:

> On the Axiado AX3000 platform, pinmux and pin configuration (such as
> direction and output enable) are configured by the hardware/firmware
> at boot time before Linux boots.
>
> To prevent conflicts, introduce a platform-specific quirk triggered by
> the "axiado,ax3000-gpio" compatible string.
>
> When this quirk is active, the driver will skip its default
> initialization of pinmux configuration and direction settings during
> probe.
>
> Co-developed-by: Tzu-Hao Wei <twei@axiado.com>
> Signed-off-by: Tzu-Hao Wei <twei@axiado.com>
> Signed-off-by: Swark Yang <syang@axiado.com>
> Signed-off-by: Prasad Bolisetty <pbolisetty@axiado.com>

> +#define CDNS_GPIO_QUIRKS_SKIP_PINMUX_CFG       BIT(1)

This is just using bits and copying stuff unnecessarily.

Do this:

struct cdns_gpio_quirks {
    bool skip_init;
};

>  struct cdns_gpio_chip {
>         struct gpio_generic_chip gen_gc;
>         void __iomem *regs;
>         u32 bypass_orig;

In this struct add:

struct cdns_gpio_quirks *quirks;

And assign it in probe.

> +struct cdns_platform_data {
> +       u32 quirks;
> +};

Skip this double-translated thing.

>  static int cdns_gpio_request(struct gpio_chip *chip, unsigned int offset)
>  {
>         struct cdns_gpio_chip *cgpio = gpiochip_get_data(chip);
> @@ -141,6 +150,16 @@ static const struct irq_chip cdns_gpio_irqchip = {
>         GPIOCHIP_IRQ_RESOURCE_HELPERS,
>  };
>
> +static const struct cdns_platform_data ax3000_gpio_def = {
> +       .quirks = CDNS_GPIO_QUIRKS_SKIP_PINMUX_CFG, };

static const struct cdns_gpio_quirks cdns_default_quirks = {
    .skip_init = true,
};

static const struct cdns_gpio_quirks ax300_gpio_quirks = {
    .skip_init = true,
};

> +static const struct of_device_id cdns_of_ids[] = {
> +       { .compatible = "axiado,ax3000-gpio", .data = &ax3000_gpio_def },

.data = &ax3000_gpio_quirks,

> +       { .compatible = "cdns,gpio-r1p02" },

.data = &cdns_default_quirks,

This becomes more manageable, as I know there is *at least* one
more variant arriving, which is for CIX semiconductors and who knows
how many quirks we will have to carry in the future.

>  static int cdns_gpio_probe(struct platform_device *pdev)
>  {
>         struct gpio_generic_chip_config config = { };
> @@ -148,6 +167,8 @@ static int cdns_gpio_probe(struct platform_device *pdev)
>         int ret, irq;
>         u32 dir_prev;
>         u32 num_gpios = 32;
> +       bool skip_pinmux_cfg = false;

Nah, just reference the quirk.

> +       const struct of_device_id *match;
>         struct clk *clk;
>
>         cgpio = devm_kzalloc(&pdev->dev, sizeof(*cgpio), GFP_KERNEL);
> @@ -165,6 +186,13 @@ static int cdns_gpio_probe(struct platform_device *pdev)
>                 return -EINVAL;
>         }
>
> +       match = of_match_node(cdns_of_ids, pdev->dev.of_node);
> +       if (match && match->data) {
> +               const struct cdns_platform_data *data = match->data;
> +
> +               skip_pinmux_cfg = data->quirks & CDNS_GPIO_QUIRKS_SKIP_PINMUX_CFG;
> +       }

Instead do:

cgpio->quirks = device_get_match_data() like Bartosz suggests.

>         dir_prev = ioread32(cgpio->regs + CDNS_GPIO_DIRECTION_MODE);
> -       iowrite32(GENMASK(num_gpios - 1, 0),
> -                 cgpio->regs + CDNS_GPIO_DIRECTION_MODE);
> +
> +       /*
> +        * The AX3000 platform performs the required configuration at boot time
> +        * before Linux boots, so this quirk disables pinmux initialization.
> +        */

> +       if (!skip_pinmux_cfg) {

Here:
if (cgpio->quirks->skip_init) {

> +               iowrite32(GENMASK(num_gpios - 1, 0),
> +                         cgpio->regs + CDNS_GPIO_DIRECTION_MODE);
> +       }
>
>         config.dev = &pdev->dev;
>         config.sz = 4;
> @@ -240,9 +275,11 @@ static int cdns_gpio_probe(struct platform_device *pdev)
>         /*
>          * Enable gpio outputs, ignored for input direction
>          */
> -       iowrite32(GENMASK(num_gpios - 1, 0),
> -                 cgpio->regs + CDNS_GPIO_OUTPUT_EN);
> -       iowrite32(0, cgpio->regs + CDNS_GPIO_BYPASS_MODE);
> +       if (!skip_pinmux_cfg) {

if (cgpio->quirks->skip_init) {

> +               iowrite32(GENMASK(num_gpios - 1, 0),
> +                         cgpio->regs + CDNS_GPIO_OUTPUT_EN);

This has nothing to do with pinmux whatsoever so it is better to call
this quirk "skip_init"

> +               iowrite32(0, cgpio->regs + CDNS_GPIO_BYPASS_MODE);

This affects the pinmuxing though. But the muxing happens outside
of the GPIO block itself.

Yours,
Linus Walleij
Re: [PATCH 1/2] gpio: cadence: Add quirk for Axiado AX3000 platform
Posted by Bartosz Golaszewski 1 month, 1 week ago
On Tue, Dec 23, 2025 at 8:30 AM Swark Yang <syang@axiado.com> wrote:
>
> On the Axiado AX3000 platform, pinmux and pin configuration (such as
> direction and output enable) are configured by the hardware/firmware
> at boot time before Linux boots.
>
> To prevent conflicts, introduce a platform-specific quirk triggered by
> the "axiado,ax3000-gpio" compatible string.
>
> When this quirk is active, the driver will skip its default
> initialization of pinmux configuration and direction settings during
> probe.
>
> Co-developed-by: Tzu-Hao Wei <twei@axiado.com>
> Signed-off-by: Tzu-Hao Wei <twei@axiado.com>
> Signed-off-by: Swark Yang <syang@axiado.com>
> Signed-off-by: Prasad Bolisetty <pbolisetty@axiado.com>
> ---
>  drivers/gpio/gpio-cadence.c | 53 +++++++++++++++++++++++++++++++++++----------
>  1 file changed, 42 insertions(+), 11 deletions(-)
>
> diff --git a/drivers/gpio/gpio-cadence.c b/drivers/gpio/gpio-cadence.c
> index b75734ca22dd..b9f39566b0f9 100644
> --- a/drivers/gpio/gpio-cadence.c
> +++ b/drivers/gpio/gpio-cadence.c
> @@ -6,6 +6,9 @@
>   * Authors:
>   *  Jan Kotas <jank@cadence.com>
>   *  Boris Brezillon <boris.brezillon@free-electrons.com>
> + *
> + * Copyright (C) 2025 Axiado Corporation.

Move this to where the original copyright is.

> + *
>   */
>
>  #include <linux/cleanup.h>
> @@ -31,12 +34,18 @@
>  #define CDNS_GPIO_IRQ_VALUE            0x28
>  #define CDNS_GPIO_IRQ_ANY_EDGE         0x2c
>
> +#define CDNS_GPIO_QUIRKS_SKIP_PINMUX_CFG       BIT(1)
> +
>  struct cdns_gpio_chip {
>         struct gpio_generic_chip gen_gc;
>         void __iomem *regs;
>         u32 bypass_orig;
>  };
>
> +struct cdns_platform_data {
> +       u32 quirks;
> +};
> +
>  static int cdns_gpio_request(struct gpio_chip *chip, unsigned int offset)
>  {
>         struct cdns_gpio_chip *cgpio = gpiochip_get_data(chip);
> @@ -141,6 +150,16 @@ static const struct irq_chip cdns_gpio_irqchip = {
>         GPIOCHIP_IRQ_RESOURCE_HELPERS,
>  };
>
> +static const struct cdns_platform_data ax3000_gpio_def = {
> +       .quirks = CDNS_GPIO_QUIRKS_SKIP_PINMUX_CFG, };

Didn't checkpatch complain about the trailing bracket? Please move it
to the next line.

> +
> +static const struct of_device_id cdns_of_ids[] = {
> +       { .compatible = "axiado,ax3000-gpio", .data = &ax3000_gpio_def },
> +       { .compatible = "cdns,gpio-r1p02" },
> +       { /* sentinel */ },
> +};
> +MODULE_DEVICE_TABLE(of, cdns_of_ids);
> +
>  static int cdns_gpio_probe(struct platform_device *pdev)
>  {
>         struct gpio_generic_chip_config config = { };
> @@ -148,6 +167,8 @@ static int cdns_gpio_probe(struct platform_device *pdev)
>         int ret, irq;
>         u32 dir_prev;
>         u32 num_gpios = 32;
> +       bool skip_pinmux_cfg = false;
> +       const struct of_device_id *match;
>         struct clk *clk;
>
>         cgpio = devm_kzalloc(&pdev->dev, sizeof(*cgpio), GFP_KERNEL);
> @@ -165,6 +186,13 @@ static int cdns_gpio_probe(struct platform_device *pdev)
>                 return -EINVAL;
>         }
>
> +       match = of_match_node(cdns_of_ids, pdev->dev.of_node);

Just use device_get_match_data().

> +       if (match && match->data) {
> +               const struct cdns_platform_data *data = match->data;
> +
> +               skip_pinmux_cfg = data->quirks & CDNS_GPIO_QUIRKS_SKIP_PINMUX_CFG;
> +       }
> +
>         /*
>          * Set all pins as inputs by default, otherwise:
>          * gpiochip_lock_as_irq:
> @@ -173,8 +201,15 @@ static int cdns_gpio_probe(struct platform_device *pdev)
>          * so it needs to be changed before gpio_generic_chip_init() is called.
>          */
>         dir_prev = ioread32(cgpio->regs + CDNS_GPIO_DIRECTION_MODE);
> -       iowrite32(GENMASK(num_gpios - 1, 0),
> -                 cgpio->regs + CDNS_GPIO_DIRECTION_MODE);
> +
> +       /*
> +        * The AX3000 platform performs the required configuration at boot time
> +        * before Linux boots, so this quirk disables pinmux initialization.
> +        */
> +       if (!skip_pinmux_cfg) {
> +               iowrite32(GENMASK(num_gpios - 1, 0),
> +                         cgpio->regs + CDNS_GPIO_DIRECTION_MODE);
> +       }
>
>         config.dev = &pdev->dev;
>         config.sz = 4;
> @@ -240,9 +275,11 @@ static int cdns_gpio_probe(struct platform_device *pdev)
>         /*
>          * Enable gpio outputs, ignored for input direction
>          */
> -       iowrite32(GENMASK(num_gpios - 1, 0),
> -                 cgpio->regs + CDNS_GPIO_OUTPUT_EN);
> -       iowrite32(0, cgpio->regs + CDNS_GPIO_BYPASS_MODE);
> +       if (!skip_pinmux_cfg) {
> +               iowrite32(GENMASK(num_gpios - 1, 0),
> +                         cgpio->regs + CDNS_GPIO_OUTPUT_EN);
> +               iowrite32(0, cgpio->regs + CDNS_GPIO_BYPASS_MODE);
> +       }
>
>         platform_set_drvdata(pdev, cgpio);
>         return 0;
> @@ -260,12 +297,6 @@ static void cdns_gpio_remove(struct platform_device *pdev)
>         iowrite32(cgpio->bypass_orig, cgpio->regs + CDNS_GPIO_BYPASS_MODE);
>  }
>
> -static const struct of_device_id cdns_of_ids[] = {
> -       { .compatible = "cdns,gpio-r1p02" },
> -       { /* sentinel */ },
> -};
> -MODULE_DEVICE_TABLE(of, cdns_of_ids);
> -
>  static struct platform_driver cdns_gpio_driver = {
>         .driver = {
>                 .name = "cdns-gpio",
>
> --
> 2.25.1
>

Bart