Re: [PATCH 2/2] gpio: Support ON Semi CAT9532
From: Bartosz Golaszewski
Date: Wed Sep 16 2026 - 05:09:26 EST
On Tue, 15 Sep 2026 15:48:02 +0200, Alban Bedel <alban.bedel@xxxxxxxxxx> said:
> On Tue, 15 Sep 2026 11:57:51 +0200
> Bartosz Golaszewski <brgl@xxxxxxxxxx> wrote:
>
>> On Tue, Sep 15, 2026 at 11:51 AM Bartosz Golaszewski <brgl@xxxxxxxxxx> wrote:
>> >
>> > On Tue, 15 Sep 2026 11:20:46 +0200, Alban Bedel <alban.bedel@xxxxxxxxxx> said:
>> > > Add support for the CAT9532 LED dimmer from On Semiconductor. Altought
>> > > marketed as an LED dimmer it is a bit limited in this regard as it
>> > > only has 2 PWM for 16 pins. As explained in the datasheet it can also
>> > > be used as an open-drain GPIO controller, and that's how it is used on
>> > > the hardware I have at hand. This chip doesn't really map to what the
>> > > gpio-regmap driver expect so it is implemented as it own driver. This
>> > > approch also allow to later add support for the LED dimmer if desired.
>> > >
>> > > Signed-off-by: Alban Bedel <alban.bedel@xxxxxxxxxx>
>> > > ---
>> > > drivers/gpio/Kconfig | 10 +++
>> > > drivers/gpio/Makefile | 1 +
>> > > drivers/gpio/gpio-cat9532.c | 173 ++++++++++++++++++++++++++++++++++++
>> > > 3 files changed, 184 insertions(+)
>> > > create mode 100644 drivers/gpio/gpio-cat9532.c
>> > >
>> > > diff --git a/drivers/gpio/Kconfig b/drivers/gpio/Kconfig
>> > > index a48586bb8edba..05b7af675677b 100644
>> > > --- a/drivers/gpio/Kconfig
>> > > +++ b/drivers/gpio/Kconfig
>> > > @@ -1180,6 +1180,16 @@ config GPIO_ADNP
>> > > enough to represent all pins, but the driver will assume a
>> > > register layout for 64 pins (8 registers).
>> > >
>> > > +config GPIO_CAT9532
>> > > + tristate "CAT9532 GPIO support"
>> > > + select REGMAP_I2C
>> > > + help
>> > > + GPIO driver for ON Semiconductor CAT9532 LED dimmer.
>> > > + Say yes here to enable the GPIO driver for the CAT9532 chip.
>> > > +
>> > > + To compile this driver as a module, choose M here: the module will
>> > > + be called gpio-cat9532.
>> > > +
>> > > config GPIO_FXL6408
>> > > tristate "FXL6408 I2C GPIO expander"
>> > > select GPIO_REGMAP
>> > > diff --git a/drivers/gpio/Makefile b/drivers/gpio/Makefile
>> > > index dc9e6d643b5bc..e94d2f57a1f93 100644
>> > > --- a/drivers/gpio/Makefile
>> > > +++ b/drivers/gpio/Makefile
>> > > @@ -51,6 +51,7 @@ obj-$(CONFIG_GPIO_BRCMSTB) += gpio-brcmstb.o
>> > > obj-$(CONFIG_GPIO_BT8XX) += gpio-bt8xx.o
>> > > obj-$(CONFIG_GPIO_BY_PINCTRL) += gpio-by-pinctrl.o
>> > > obj-$(CONFIG_GPIO_CADENCE) += gpio-cadence.o
>> > > +obj-$(CONFIG_GPIO_CAT9532) += gpio-cat9532.o
>> > > obj-$(CONFIG_GPIO_CGBC) += gpio-cgbc.o
>> > > obj-$(CONFIG_GPIO_CLPS711X) += gpio-clps711x.o
>> > > obj-$(CONFIG_GPIO_SNPS_CREG) += gpio-creg-snps.o
>> > > diff --git a/drivers/gpio/gpio-cat9532.c b/drivers/gpio/gpio-cat9532.c
>> > > new file mode 100644
>> > > index 0000000000000..973ff74a15b89
>> > > --- /dev/null
>> > > +++ b/drivers/gpio/gpio-cat9532.c
>> > > @@ -0,0 +1,173 @@
>> > > +// SPDX-License-Identifier: GPL-2.0-or-later
>> > > +#include <linux/gpio/driver.h>
>> > > +#include <linux/i2c.h>
>> > > +#include <linux/module.h>
>> > > +#include <linux/regmap.h>
>> > > +#include <linux/spinlock.h>
>> > > +
>> > > +struct cat9532 {
>> > > + struct regmap *regmap;
>> > > + struct gpio_chip gpio;
>> > > +
>> > > + spinlock_t lock;
>> > > + unsigned int direction;
>> > > +};
>> > > +
>> > > +#define CAT9532_REG_INPUT0 0
>> > > +#define CAT9532_REG_LS0 6
>> > > +
>> > > +/* Set output to Hi-Z, LED is OFF */
>> > > +#define CAT9532_LED_OUT_HIZ 0
>> > > +/* Set output low */
>> > > +#define CAT9532_LED_OUT_LOW 1
>> > > +#define CAT9532_LED_OUT_MASK 3
>> > > +
>> > > +static const struct regmap_config cat9532_regmap_cfg = {
>> > > + .reg_bits = 8,
>> > > + .val_bits = 8,
>> > > + .max_register = 9,
>> > > + /*
>> > > + * Auto increment can be enabled by setting bit 4 in the
>> > > + * register address, but we don't really need bulk access.
>> > > + */
>> > > + .use_single_read = true,
>> > > + .use_single_write = true,
>> > > + .can_sleep = true,
>> > > +};
>> >
>> > This looks like it would perfectly fit the gpio-regmap helper and allow for
>> > code reuse. Maybe except for the locally tracked direction. How reliable is it?
>> > What if the GPIOs were put into some specific state by the bootloader?
>> >
>> > Bart
>>
>> Ah, nevermind, you commented on not being able to use it. My question
>> still stands, how reliable is direction tracking here? Does reading
>> back the registers you write in direction setters not give you
>> anything?
>
> This is an exclusively open-drain chip, you can either driver the line
> low or leave it in hi-z mode to be driven by an external circuit. There
> is no direction register, the input register just report the current
> line state. As such the direction is only something that exists in the
> driver.
>
Yes, I skimmed over it quickly at the airport, should have paid more attention
to what I'm looking at.
Thanks,
Bartosz