Re: [PATCH 2/3] gpio: atcgpio100: Add ATCGPIO100 GPIO driver

From: Bartosz Golaszewski

Date: Tue Nov 17 2026 - 08:54:14 EST


On Mon, Nov 16, 2026 at 12:09:13PM +0800, CL Wang wrote:
> Add a driver for the Andes ATCGPIO100 GPIO controller, found on
> AndesCore-based platforms such as AE350.
>
> The controller provides up to 32 lines. The data path is built on the
> generic MMIO GPIO library (gpio-mmio), and the number of lines and the
> optional pull, interrupt and debounce features are read from the
> configuration register at probe time.
>
> The driver supports:
> - Input and output, reading the output latch back for output lines
> - Pull-up and pull-down bias
> - Edge (rising, falling, both) and level (high, low) interrupts
> - Hardware input debounce with a period shared by all lines
> - Wakeup through the parent interrupt for lines that their consumers
> mark as wakeup sources
> - System suspend and resume
>
> Signed-off-by: CL Wang <cl634@xxxxxxxxxxxxx>
> ---

...

> +
> +#include <linux/bitfield.h>
> +#include <linux/bits.h>
> +#include <linux/clk.h>
> +#include <linux/dev_printk.h>
> +#include <linux/err.h>
> +#include <linux/find.h>
> +#include <linux/gpio/driver.h>
> +#include <linux/gpio/generic.h>
> +#include <linux/interrupt.h>
> +#include <linux/io.h>
> +#include <linux/irq.h>
> +#include <linux/irqchip/chained_irq.h>
> +#include <linux/math.h>
> +#include <linux/minmax.h>
> +#include <linux/mod_devicetable.h>

Uwe would probably say you should only pull in the individual headers
that you require from include/linux/device-id/.

...

> +
> + config = (struct gpio_generic_chip_config) {
> + .dev = &priv->pdev->dev,
> + .sz = 4,
> + .dat = priv->base + REG_DATA_IN,
> + .set = priv->base + REG_DATA_OUT,
> + .dirout = priv->base + REG_CHAN_DIR,
> + .flags = GPIO_GENERIC_READ_OUTPUT_REG_SET,
> + };

I think you could save even more code by using the gpio-regmap helper
here instead. Could you see if that's possible here?

> +
> + ret = gpio_generic_chip_init(&priv->chip, &config);
> + if (ret)
> + return dev_err_probe(&priv->pdev->dev, ret,
> + "Failed to init generic GPIO chip\n");
> +
> + return 0;
> +}
> +
> +static void atcgpio_init_controller(struct atcgpio_priv *priv)
> +{
> + u32 cfg;
> +
> + cfg = atcgpio_read(priv, REG_CONFIG);
> + priv->pull_option = !!(cfg & CONFIG_PULL_OPTION);
> + priv->int_option = !!(cfg & CONFIG_INT_OPTION);
> + priv->debounce_option = !!(cfg & CONFIG_DEBOUNCE_OPTION);
> + priv->chan_num = CONFIG_CHAN_NUM_GET(cfg);
> + if (priv->chan_num > ATCGPIO_CHAN_NUM_MAX || !priv->chan_num) {
> + dev_warn(&priv->pdev->dev,

Use a local variable to store the adress of dev for better readability.

> + "Invalid hardware GPIO number %d, forcing to %d\n",
> + priv->chan_num,
> + ATCGPIO_CHAN_NUM_MAX);
> + priv->chan_num = ATCGPIO_CHAN_NUM_MAX;
> + }
> +
> + if (!priv->extclk_rate && !priv->pclk_rate) {
> + dev_warn(&priv->pdev->dev,
> + "Disabling debounce: missing reference clock\n");
> + priv->debounce_option = 0;
> + }
> +
> + if (priv->debounce_option)
> + atcgpio_write(priv, REG_DEBOUNCE_EN, 0);
> +
> + if (priv->int_option) {
> + atcgpio_write(priv, REG_CHAN_INT_EN, 0);
> + atcgpio_write(priv, REG_INT_MODE0, 0);
> + atcgpio_write(priv, REG_INT_MODE1, 0);
> + atcgpio_write(priv, REG_INT_MODE2, 0);
> + atcgpio_write(priv, REG_INT_MODE3, 0);
> + atcgpio_write(priv, REG_CHAN_INT_STATE, GENMASK(31, 0));
> + }
> +}
> +
> +static int atcgpio_probe(struct platform_device *pdev)
> +{
> + struct device *dev = &pdev->dev;
> + struct gpio_irq_chip *gc_irq;
> + struct atcgpio_priv *priv;
> + struct gpio_chip *gc;
> + int ret;
> +
> + priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);

Use devm_kzalloc_obj(). Same elsewhere.

Bart