Re: [PATCH v4 3/3] gpio: ws16c48: Migrate to the regmap API

From: Andy Shevchenko
Date: Wed Mar 08 2023 - 08:10:46 EST


On Tue, Mar 07, 2023 at 09:51:26PM -0500, William Breathitt Gray wrote:
> On Mon, Mar 06, 2023 at 04:20:03PM +0200, Andy Shevchenko wrote:
> > On Mon, Mar 06, 2023 at 07:59:53AM -0500, William Breathitt Gray wrote:

...

> > > - raw_spinlock_t lock;
> > > + spinlock_t lock;
> >
> > This is a regression.
> > That said, do we need a support of raw spin locks in the regmap IRQ?
>
> So this code has a similar need as the gpio-pcie-idio-24 patch: guard
> registers between handle_mask_sync() and set_type_config(); however, now
> we also need to protect registers in regmap_irq_thread(). We can't use a
> mutex here because regmap_irq_thread() is executed in an interrupt
> context so we cannot sleep.
>
> This might be a mistake in my understanding: I chose spinlock_t here
> because I believed it to map out to a raw_spinlock_t anyway underneath,
> whereas on RT kernels it would map out to whatever the equivalent is. I
> suspect this is not actually the case. Would using raw_spinlock_t
> explicitly be the correct way to go for this particular case?

You may read the commit message of the 27d9098cff6e ("pinctrl: intel:
Use raw_spinlock for locking"). TL;DR: this is only affects IRQ chips,
so if your GPIO controller is _not_ an IRQ chip, you are fine.

WRT the other driver, can_sleep may reduce scope of the use of GPIOs
and even make a regression if any consumer don't want that behaviour
and currently works.

> > > + u8 irq_mask[WS16C48_NUM_IRQS / WS16C48_NGPIO_PER_REG];
> >
> > Can this be a bitmap? Or is it too over engineered with it?
>
> I also considered a bitmap at first, but I believe it adds an
> unnecessary abstraction in this particular case: irq_mask is just a
> buffer to hold the previous mask_buf state to check if it's changed when
> ws16c48_handle_mask_sync() is called. Since all we do with it is save
> the mask_buf directly, using the bitmap API seems like overkill.

Thanks for elaboration!

--
With Best Regards,
Andy Shevchenko