Linux Hardware Monitor development
 help / color / mirror / Atom feed
From: "Nuno Sá" <noname.nuno@gmail.com>
To: Linus Walleij <linus.walleij@linaro.org>, nuno.sa@analog.com
Cc: linux-hwmon@vger.kernel.org, devicetree@vger.kernel.org,
	 linux-doc@vger.kernel.org, Jean Delvare <jdelvare@suse.com>,
	Guenter Roeck <linux@roeck-us.net>,
	Rob Herring <robh+dt@kernel.org>,
	Krzysztof Kozlowski <krzysztof.kozlowski+dt@linaro.org>,
	Conor Dooley <conor+dt@kernel.org>,
	 Jonathan Corbet <corbet@lwn.net>,
	Bartosz Golaszewski <brgl@bgdev.pl>,
	Andy Shevchenko <andy@kernel.org>
Subject: Re: [PATCH v2 2/2] hwmon: ltc4282: add support for the LTC4282 chip
Date: Wed, 29 Nov 2023 17:08:41 +0100	[thread overview]
Message-ID: <6384831c05b8ceeaf4a16cf9229770252989b762.camel@gmail.com> (raw)
In-Reply-To: <CACRpkdaksfS4WLNQ6ohauAPq3z2LPG2uF37_jWtm0brQHaDtNw@mail.gmail.com>

On Wed, 2023-11-29 at 15:49 +0100, Linus Walleij wrote:
> Hi Nuno,
> 
> GPIO-related review as requested! Thanks for your patch!
> 
> On Fri, Nov 24, 2023 at 3:18 PM Nuno Sa via B4 Relay
> <devnull+nuno.sa.analog.com@kernel.org> wrote:
> 
> > +config SENSORS_LTC4282
> > +       tristate "Analog Devices LTC4282"
> > +       depends on I2C
> > +       select REGMAP_I2C
> 
> select GPIOLIB
> 

Hmm alright, the only reason why I didn't do this is because gpiochip is an optional
feature for the driver. So I have an '!IS_ENABLED(CONFOG_GPIOLIB)' guard in the
beginning of the function. But yeah, will just do this. Odds are that gpio is already
enabled anyways.

> potentially also
> 
> select GPIO_REGMAP, see below.
> 
> > +struct ltc4282_gpio {
> > +       const char * const *funcs;
> > +       u32 out_reg;
> > +       u32 out_mask;
> > +       u32 in_reg;
> > +       u32 in_mask;
> > +       bool active_high;
> > +       u8 n_funcs;
> > +};
> 
> So pretty simple dedicated bits.
> 
> > +static int ltc4282_gpio_input_set(struct gpio_chip *chip, unsigned int offset)
> > +{
> > +       struct ltc4282_state *st = gpiochip_get_data(chip);
> > +
> > +       /* we can only control this for GPIO_1 */
> > +       if (offset != LTC4282_GPIO_1)
> > +               return 0;
> > +
> > +       return regmap_set_bits(st->map, LTC4282_GPIO_CONFIG,
> > +                              LTC4282_GPIO_1_CONFIG_MASK);
> > +}
> > +
> > +static int ltc4282_gpio_output_set(struct gpio_chip *chip, unsigned int offset,
> > +                                  int val)
> > +{
> > +       struct ltc4282_state *st = gpiochip_get_data(chip);
> > +       const struct ltc4282_gpio *gpio = &ltc4282_gpios[offset];
> > +
> > +       guard(mutex)(&st->lock);
> > +       /*
> > +        * Explicitly setting the pin as output can only be done for GPIO_1. For
> > +        * the other pins we just pull the line down or high-z.
> > +        */
> > +       if (offset == LTC4282_GPIO_1) {
> > +               int ret;
> > +
> > +               ret = regmap_update_bits(st->map, LTC4282_GPIO_CONFIG,
> > +                                        LTC4282_GPIO_1_CONFIG_MASK,
> > +                                        FIELD_PREP(LTC4282_GPIO_1_CONFIG_MASK,
> > 2));
> > +               if (ret)
> > +                       return ret;
> > +       }
> > +
> > +       /*
> > +        * GPIO_2,3 and the ALERT pin require setting the bit to 1 to pull down
> > +        * the line
> > +        */
> > +       if (!gpio->active_high)
> > +               val = !val;
> > +
> > +       return regmap_update_bits(st->map, gpio->out_reg, gpio->out_mask,
> > +                                 field_prep(gpio->out_mask, val));
> > +}
> > +
> > +static void ltc4282_gpio_set(struct gpio_chip *chip, unsigned int offset,
> > +                            int val)
> > +{
> > +       struct ltc4282_state *st = gpiochip_get_data(chip);
> > +       const struct ltc4282_gpio *gpio = &ltc4282_gpios[offset];
> > +
> > +       if (!gpio->active_high)
> > +               val = !val;
> > +
> > +       regmap_update_bits(st->map, gpio->out_reg, gpio->out_mask,
> > +                          field_prep(gpio->out_mask, val));
> > +}
> > +
> > +static int ltc4282_gpio_get(struct gpio_chip *chip, unsigned int offset)
> > +{
> > +       struct ltc4282_state *st = gpiochip_get_data(chip);
> > +       const struct ltc4282_gpio *gpio = &ltc4282_gpios[offset];
> > +       int ret;
> > +       u32 val;
> > +
> > +       ret = regmap_read(st->map, gpio->in_reg, &val);
> > +       if (ret)
> > +               return ret;
> > +
> > +       return !!(val & gpio->in_mask);
> > +}
> > +
> > +static int ltc4282_gpio_valid_mask(struct gpio_chip *chip,
> > +                                  unsigned long *valid_mask,
> > +                                  unsigned int ngpios)
> > +{
> > +       struct ltc4282_state *st = gpiochip_get_data(chip);
> > +
> > +       *valid_mask = st->valid_mask;
> > +       return 0;
> > +}
> 
> Some of this looks like it could use GPIO_REGMAP, look into other
> drivers using these helpers such as
> drivers/gpio/gpio-ds4520.c and see how small it becomes.
> 
> It may or may not help you. But take a look.
> 

Ok, will look at it.

> Other than that it looks fine.
> 

Cool, I actually thought that having the direction + get/set stuff would be weird
given the fact that we can only PULL_LOW or HIGH_Z the pins.

Thanks!
- Nuno Sá


  reply	other threads:[~2023-11-29 16:08 UTC|newest]

Thread overview: 55+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-11-24 14:18 [PATCH v2 0/2] Add support for LTC4282 Nuno Sa via B4 Relay
2023-11-24 14:18 ` [PATCH v2 1/2] dt-bindings: hwmon: Add LTC4282 bindings Nuno Sa via B4 Relay
2023-11-25 11:56   ` Conor Dooley
2023-11-27  7:56     ` Nuno Sá
2023-11-27 17:33       ` Conor Dooley
2023-11-28 15:37   ` Rob Herring
2023-11-28 15:49     ` Nuno Sá
2023-11-24 14:18 ` [PATCH v2 2/2] hwmon: ltc4282: add support for the LTC4282 chip Nuno Sa via B4 Relay
2023-11-24 21:54   ` kernel test robot
2023-11-24 23:39   ` kernel test robot
2023-11-27  7:53     ` Nuno Sá
2023-11-27  8:10       ` Krzysztof Kozlowski
2023-11-27  8:12         ` Krzysztof Kozlowski
2023-11-27  8:44           ` Nuno Sá
2023-11-27 16:03           ` Andy Shevchenko
2023-11-28 16:50             ` Krzysztof Kozlowski
2023-11-28 17:01               ` Andy Shevchenko
2023-11-28 18:03               ` Guenter Roeck
2023-11-29  8:35                 ` Nuno Sá
2023-11-29  8:45                   ` Krzysztof Kozlowski
2023-11-29  8:56                     ` Nuno Sá
2023-11-29 14:10                     ` Linus Walleij
2023-11-29 14:13                       ` Krzysztof Kozlowski
2023-11-29 14:29                       ` Nuno Sá
2023-11-29 14:47                   ` Guenter Roeck
2023-11-29 16:09                     ` Nuno Sá
2023-11-27 10:20   ` kernel test robot
2023-11-29 14:49   ` Linus Walleij
2023-11-29 16:08     ` Nuno Sá [this message]
2023-11-29 16:18       ` Andy Shevchenko
2023-11-29 16:21         ` Nuno Sá
2023-11-29 17:07           ` Andy Shevchenko
2023-11-29 20:55       ` Linus Walleij
2023-11-30 10:20         ` Nuno Sá
2023-11-30 13:36           ` Andy Shevchenko
2023-11-30 14:39             ` Guenter Roeck
2023-11-30 15:20             ` Nuno Sá
2023-11-30 16:28               ` Guenter Roeck
2023-11-30 20:15               ` Linus Walleij
2023-12-01 12:34                 ` Nuno Sá
2023-12-01 13:40                   ` Linus Walleij
2023-12-01 15:24                     ` Nuno Sá
2023-12-01 15:47                       ` Andy Shevchenko
2023-12-01 16:04                         ` Guenter Roeck
2023-12-01 16:24                           ` Andy Shevchenko
2023-12-01 16:36                             ` Guenter Roeck
2023-12-01 16:29                           ` Nuno Sá
2023-12-01 16:46                             ` Guenter Roeck
2023-12-02  9:42                               ` Nuno Sá
2023-12-03 23:08                                 ` Linus Walleij
2023-12-04  8:20                                   ` Bartosz Golaszewski
2023-12-01 16:19                         ` Nuno Sá
2023-12-01 16:23                           ` Andy Shevchenko
2023-12-03 23:03                       ` Linus Walleij
2023-12-04  8:53                         ` Nuno Sá

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=6384831c05b8ceeaf4a16cf9229770252989b762.camel@gmail.com \
    --to=noname.nuno@gmail.com \
    --cc=andy@kernel.org \
    --cc=brgl@bgdev.pl \
    --cc=conor+dt@kernel.org \
    --cc=corbet@lwn.net \
    --cc=devicetree@vger.kernel.org \
    --cc=jdelvare@suse.com \
    --cc=krzysztof.kozlowski+dt@linaro.org \
    --cc=linus.walleij@linaro.org \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-hwmon@vger.kernel.org \
    --cc=linux@roeck-us.net \
    --cc=nuno.sa@analog.com \
    --cc=robh+dt@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox