Re: [PATCH v2 2/3] gpio: atcgpio100: Add ATCGPIO100 GPIO driver
From: Linus Walleij
Date: Fri Dec 04 2026 - 17:09:07 EST
Hi CL,
thanks for your patch!
On Wed, Dec 2, 2026 at 1:47 AM CL Wang <cl634@xxxxxxxxxxxxx> wrote:
> Add driver for the Andes ATCGPIO100 GPIO controller.
>
> This controller supports:
> - Up to 32 GPIOs
> - Input/Output modes
> - Debounce configuration
> - Interrupt generation
> - System suspend and resume
>
> Signed-off-by: CL Wang <cl634@xxxxxxxxxxxxx>
OK terse but to the point.
> +static u32 atcgpio_read(struct atcgpio_priv *priv, unsigned int reg)
> +{
> + return readl(priv->base + reg);
> +}
> +
> +static void atcgpio_write(struct atcgpio_priv *priv, unsigned int reg, u32 val)
> +{
> + writel(val, priv->base + reg);
> +}
Why this indirection?
Just inline readl() writel() everywhere, this indirection has no purpose.
> +static void atcgpio_update_bits(struct atcgpio_priv *priv, unsigned int reg,
> + u32 mask, u32 val)
> +{
> + u32 tmp;
> +
> + tmp = atcgpio_read(priv, reg);
> + tmp = (tmp & ~mask) | (val & mask);
> + atcgpio_write(priv, reg, tmp);
> +}
If you want this kind of helper use regmap-mmio and use
the standard helper regmap_update_bits(). Otherwise I'd just
inline this kind of stuff.
> +static u64 atcgpio_calc_cycles(u32 clk_rate, u32 debounce_us)
> +{
> + if (!clk_rate)
> + return 0;
Isn't this an error?
> + return DIV_ROUND_UP_ULL((u64)debounce_us * clk_rate, 1000000);
In that case just inline this into set_debounce() after a bailout
for !clk_rate.
> +static int atcgpio_set_debounce(struct atcgpio_priv *priv,
> + unsigned int gpio,
> + unsigned int debounce_us)
> +{
> + unsigned long flags;
> + u64 ext_cycles, pclk_cycles, cycles;
> + u32 ctrl_val;
> + u32 active_users, current_ctrl;
> +
> + if (!debounce_us) {
> + gpio_generic_chip_lock_irqsave(&priv->chip, flags);
> + atcgpio_update_bits(priv, REG_DEBOUNCE_EN, BIT(gpio), 0);
> + gpio_generic_chip_unlock_irqrestore(&priv->chip, flags);
> + return 0;
If you instead use regmap_update_bits() I think regmap can manage the
locking as well with its own lock or a custom lock or callback, look into it.
Otherwise nice that you implemented .set_config()!
I don't know how well regmap-mmio will blend with GPIO_GENERIC
but I'd say give it a try. There is also GPIO_REGMAP for regmap-oriented
GPIO drivers, but these typically have one register på GPIO line
though it can deal with individual bits as well.
Yours,
Linus Walleij