Re: [PATCH 4/5] gpio: adp5585: Add Analog Devices ADP5585 support

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tue, May 28, 2024 at 03:27:34PM +0300, Laurent Pinchart wrote:
> Hi Linus,
> 
> On Tue, May 28, 2024 at 01:54:29PM +0200, Linus Walleij wrote:
> > On Mon, May 20, 2024 at 9:59 PM Laurent Pinchart wrote:
> > 
> > > From: Haibo Chen <haibo.chen@xxxxxxx>
> > >
> > > The ADP5585 is a 10/11 input/output port expander with a built in keypad
> > > matrix decoder, programmable logic, reset generator, and PWM generator.
> > > This driver supports the GPIO function using the platform device
> > > registered by the core MFD driver.
> > >
> > > The driver is derived from an initial implementation from NXP, available
> > > in commit 451f61b46b76 ("MLK-25917-2 gpio: adp5585-gpio: add
> > > adp5585-gpio support") in their BSP kernel tree. It has been extensively
> > > rewritten.
> > >
> > > Signed-off-by: Haibo Chen <haibo.chen@xxxxxxx>
> > > Signed-off-by: Laurent Pinchart <laurent.pinchart@xxxxxxxxxxxxxxxx>
> > 
> > (...)
> > 
> > > +static int adp5585_gpio_direction_input(struct gpio_chip *chip, unsigned int off)
> > > +{
> > > +       struct adp5585_gpio_dev *adp5585_gpio = gpiochip_get_data(chip);
> > > +       unsigned int bank = ADP5585_BANK(off);
> > > +       unsigned int bit = ADP5585_BIT(off);
> > > +
> > > +       guard(mutex)(&adp5585_gpio->lock);
> > > +
> > > +       return regmap_update_bits(adp5585_gpio->regmap,
> > > +                                 ADP5585_GPIO_DIRECTION_A + bank,
> > > +                                 bit, 0);
> > 
> > First, I love the guarded mutex!
> 
> Yes, it's neat :-)
> 
> > But doesn't regmap already contain a mutex? Or is this one of those
> > cases where regmap has been instantiated without a lock?
> 
> regmap indeed includes a lock, but it will lock each register access
> independently. In adp5585_gpio_get_value() we need to read two
> registers atomically, so we need to cover them by a single lock.
> 
> I could drop the lock from regmap, but I would then likely need to
> introduce a lock in the parent mfd device that both the PWM and GPIO
> children would use to protect bus access. That may make sense in the
> future, but is a bit overkill for now I think.

Actually, I think I can drop the lock. Concurrent access to the
registers from different GPIOs are protected by the regmap lock, and
concurrent access to groups of registers for the same GPIO isn't a valid
use case as callers shouldn't do that.

> > > +       gc = &adp5585_gpio->gpio_chip;
> > > +       gc->parent = dev;
> > > +       gc->direction_input  = adp5585_gpio_direction_input;
> > > +       gc->direction_output = adp5585_gpio_direction_output;
> > 
> > And chance to implemen ->get_direction()?
> 
> Sure, I'll add that to v2.
> 
> > Other than this I think the driver is ready for merge, so with the
> > comments fixed or addressed:
> > Reviewed-by: Linus Walleij <linus.walleij@xxxxxxxxxx>
> 
> Thank you.

-- 
Regards,

Laurent Pinchart




[Index of Archives]     [Device Tree Compilter]     [Device Tree Spec]     [Linux Driver Backports]     [Video for Linux]     [Linux USB Devel]     [Linux PCI Devel]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [XFree86]     [Yosemite Backpacking]


  Powered by Linux