From: "Mathieu Dubois-Briand" <mathieu.dubois-briand@bootlin.com>
To: "Lee Jones" <lee@kernel.org>
Cc: "Rob Herring" <robh@kernel.org>,
"Krzysztof Kozlowski" <krzk+dt@kernel.org>,
"Conor Dooley" <conor+dt@kernel.org>,
"Kamel Bouhara" <kamel.bouhara@bootlin.com>,
"Linus Walleij" <linus.walleij@linaro.org>,
"Bartosz Golaszewski" <brgl@bgdev.pl>,
"Dmitry Torokhov" <dmitry.torokhov@gmail.com>,
"Uwe Kleine-König" <ukleinek@kernel.org>,
devicetree@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-gpio@vger.kernel.org, linux-input@vger.kernel.org,
linux-pwm@vger.kernel.org,
"Grégory Clement" <gregory.clement@bootlin.com>,
"Thomas Petazzoni" <thomas.petazzoni@bootlin.com>
Subject: Re: [PATCH v3 2/7] mfd: Add max7360 support
Date: Fri, 17 Jan 2025 11:38:27 +0100 [thread overview]
Message-ID: <D74A7MIVLFS2.HYUXZ072NCTQ@bootlin.com> (raw)
In-Reply-To: <20250115154252.GK6763@google.com>
On Wed Jan 15, 2025 at 4:42 PM CET, Lee Jones wrote:
> On Mon, 13 Jan 2025, mathieu.dubois-briand@bootlin.com wrote:
>
> > From: Kamel Bouhara <kamel.bouhara@bootlin.com>
> >
> > Add core driver to support MAX7360 i2c chip, multi function device
> > with keypad, gpio, pwm, gpo and rotary encoder submodules.
> >
> > Signed-off-by: Kamel Bouhara <kamel.bouhara@bootlin.com>
> > Co-developed-by: Mathieu Dubois-Briand <mathieu.dubois-briand@bootlin.com>
> > Signed-off-by: Mathieu Dubois-Briand <mathieu.dubois-briand@bootlin.com>
> > ---
...
> > +static int max7360_set_gpos_count(struct max7360_mfd *max7360_mfd)
> > +{
> > + /*
> > + * Max7360 COL0 to COL7 pins can be used either as keypad columns,
> > + * general purpose output or a mix of both.
> > + * Get the number of pins requested by the corresponding drivers, ensure
> > + * they are compatible with each others and apply the corresponding
> > + * configuration.
> > + */
> > + struct device_node *np;
> > + u32 gpos = 0;
> > + u32 columns = 0;
> > + unsigned int val;
> > + int ret;
> > +
> > + np = of_get_compatible_child(max7360_mfd->dev->of_node, GPO_COMPATIBLE);
>
> Why don't you do all of this in the GPO driver?
>
I first did this here, so the configuration was still done if the GPO
driver was missing. But on a second thought, we can just set the GPO
count to 0 here, and let the GPO driver handle all of this.
I will move this function to the GPO driver.
> > + if (np) {
> > + ret = of_property_read_u32(np, "ngpios", &gpos);
> > + if (ret < 0) {
> > + dev_err(max7360_mfd->dev, "Failed to read gpos count\n");
> > + return ret;
> > + }
> > + }
> > +
> > + ret = device_property_read_u32(max7360_mfd->dev,
> > + "keypad,num-columns", &columns);
> > + if (ret < 0) {
> > + dev_err(max7360_mfd->dev, "Failed to read columns count\n");
> > + return ret;
> > + }
> > +
> > + if (gpos > MAX7360_MAX_GPO ||
> > + (gpos + columns > MAX7360_MAX_KEY_COLS)) {
> > + dev_err(max7360_mfd->dev,
> > + "Incompatible gpos and columns count (%u, %u)\n",
> > + gpos, columns);
> > + return -EINVAL;
> > + }
> > +
> > + /*
> > + * MAX7360_REG_DEBOUNCE contains configuration both for keypad debounce
> > + * timings and gpos/keypad columns repartition. Only the later is
> > + * modified here.
> > + */
> > + val = FIELD_PREP(MAX7360_PORTS, gpos);
> > + ret = regmap_write_bits(max7360_mfd->regmap, MAX7360_REG_DEBOUNCE,
> > + MAX7360_PORTS, val);
> > + if (ret) {
> > + dev_err(max7360_mfd->dev,
> > + "Failed to write max7360 columns/gpos configuration");
> > + return ret;
> > + }
> > +
> > + return 0;
> > +}
> > +
> > +int max7360_port_pin_request(struct device *dev, unsigned int pin, bool request)
>
> This whole function is rough. What are you trying to achieve?
>
Some pins can be used either for PWM, rotary encoder or GPIO. The goal
here is to allow corresponding drivers to request the pin, making sure
only one driver use a given pin at some point.
> > +{
> > + struct i2c_client *client;
> > + struct max7360_mfd *max7360_mfd;
> > + unsigned long flags;
> > + int ret = 0;
> > +
> > + client = to_i2c_client(dev);
> > + max7360_mfd = i2c_get_clientdata(client);
> > +
> > + spin_lock_irqsave(&request_lock, flags);
> > + if (request) {
> > + if (max7360_mfd->requested_ports & BIT(pin))
> > + ret = -EBUSY;
> > + else
> > + max7360_mfd->requested_ports |= BIT(pin);
> > + } else {
> > + max7360_mfd->requested_ports &= ~BIT(pin);
> > + }
> > + spin_unlock_irqrestore(&request_lock, flags);
> > +
> > + return ret;
> > +}
> > +EXPORT_SYMBOL_GPL(max7360_port_pin_request);
...
> > +static int max7360_reset(struct max7360_mfd *max7360_mfd)
> > +{
> > + int err;
> > +
> > + /*
> > + * Set back the default values.
> > + * We do not use GPIO reset function here, as it does not work reliably.
>
> Why? What's wrong with it?
>
I was going to update this comment to add details, but after some extra
testing, this was wrong actually. Reset function of the chip is working
correctly, it was just a caching issue. I will rework the whole
function.
> > + */
> > + err = regmap_write(max7360_mfd->regmap, MAX7360_REG_GPIODEB, 0x00);
> > + if (err) {
> > + dev_err(max7360_mfd->dev, "Failed to set configuration\n");
> > --
> > 2.39.5
> >
Thanks for your review. I fixed all other points listed in your mail.
--
Mathieu Dubois-Briand, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
next prev parent reply other threads:[~2025-01-17 10:38 UTC|newest]
Thread overview: 33+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-01-13 12:42 [PATCH v3 0/7] Add support for MAX7360 Mathieu Dubois-Briand
2025-01-13 12:42 ` [PATCH v3 1/7] dt-bindings: mfd: gpio: Add MAX7360 Mathieu Dubois-Briand
2025-01-14 8:11 ` Krzysztof Kozlowski
2025-01-14 13:02 ` Mathieu Dubois-Briand
2025-01-13 12:42 ` [PATCH v3 2/7] mfd: Add max7360 support mathieu.dubois-briand
2025-01-15 15:42 ` Lee Jones
2025-01-17 10:38 ` Mathieu Dubois-Briand [this message]
2025-01-13 12:42 ` [PATCH v3 3/7] pwm: max7360: Add MAX7360 PWM support mathieu.dubois-briand
2025-01-17 9:33 ` Uwe Kleine-König
2025-01-17 14:11 ` Mathieu Dubois-Briand
2025-01-17 14:40 ` Uwe Kleine-König
2025-01-17 15:47 ` Mathieu Dubois-Briand
2025-01-20 14:13 ` Uwe Kleine-König
2025-01-22 12:37 ` Mathieu Dubois-Briand
2025-01-13 12:42 ` [PATCH v3 4/7] gpio: max7360: Add MAX7360 gpio support Mathieu Dubois-Briand
2025-01-14 14:33 ` Linus Walleij
2025-01-14 17:57 ` Mathieu Dubois-Briand
2025-01-17 15:22 ` Mathieu Dubois-Briand
2025-01-22 13:18 ` Linus Walleij
2025-01-27 12:52 ` Andy Shevchenko
2025-01-27 13:07 ` Andy Shevchenko
2025-02-12 12:57 ` Mathieu Dubois-Briand
2025-02-12 15:14 ` Andy Shevchenko
2025-02-12 16:08 ` Mathieu Dubois-Briand
2025-02-12 16:17 ` Andy Shevchenko
2025-02-13 10:59 ` Mathieu Dubois-Briand
2025-02-13 13:45 ` Mathieu Dubois-Briand
2025-02-13 19:47 ` Andy Shevchenko
2025-02-14 8:42 ` Mathieu Dubois-Briand
2025-01-13 12:42 ` [PATCH v3 5/7] input: keyboard: Add support for MAX7360 keypad Mathieu Dubois-Briand
2025-01-13 12:42 ` [PATCH v3 6/7] input: misc: Add support for MAX7360 rotary Mathieu Dubois-Briand
2025-01-14 13:16 ` Mathieu Dubois-Briand
2025-01-13 12:42 ` [PATCH v3 7/7] MAINTAINERS: Add entry on MAX7360 driver Mathieu Dubois-Briand
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=D74A7MIVLFS2.HYUXZ072NCTQ@bootlin.com \
--to=mathieu.dubois-briand@bootlin.com \
--cc=brgl@bgdev.pl \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=dmitry.torokhov@gmail.com \
--cc=gregory.clement@bootlin.com \
--cc=kamel.bouhara@bootlin.com \
--cc=krzk+dt@kernel.org \
--cc=lee@kernel.org \
--cc=linus.walleij@linaro.org \
--cc=linux-gpio@vger.kernel.org \
--cc=linux-input@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pwm@vger.kernel.org \
--cc=robh@kernel.org \
--cc=thomas.petazzoni@bootlin.com \
--cc=ukleinek@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;
as well as URLs for NNTP newsgroup(s).