linux-gpio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Sander Vanheule <sander@svanheule.net>
To: Lee Jones <lee@kernel.org>
Cc: Michael Walle <mwalle@kernel.org>,
	Linus Walleij <linus.walleij@linaro.org>,
	 Bartosz Golaszewski	 <brgl@bgdev.pl>,
	linux-gpio@vger.kernel.org, Pavel Machek <pavel@kernel.org>,
	 Rob Herring <robh@kernel.org>,
	Krzysztof Kozlowski <krzk+dt@kernel.org>,
	Conor Dooley <conor+dt@kernel.org>,
		linux-leds@vger.kernel.org, devicetree@vger.kernel.org,
		linux-kernel@vger.kernel.org
Subject: Re: [PATCH v6 5/8] mfd: Add RTL8231 core device
Date: Thu, 13 Nov 2025 22:25:48 +0100	[thread overview]
Message-ID: <d50db8a305d92b20a972a590f2082f39a8027edc.camel@svanheule.net> (raw)
In-Reply-To: <20251106163316.GV8064@google.com>

Hi Lee,

On Thu, 2025-11-06 at 16:33 +0000, Lee Jones wrote:
> On Tue, 21 Oct 2025, Sander Vanheule wrote:
> > @@ -0,0 +1,193 @@
> > +// SPDX-License-Identifier: GPL-2.0-only
> > +
> > +#include <linux/bits.h>
> > +#include <linux/bitfield.h>
> > +#include <linux/delay.h>
> > +#include <linux/gpio/consumer.h>
> > +#include <linux/mfd/core.h>
> > +#include <linux/mdio.h>
> > +#include <linux/module.h>
> > +#include <linux/platform_device.h>
> > +#include <linux/property.h>
> > +#include <linux/regmap.h>
> 
> Alphabetical please.

Ack

> > +static const struct reg_field RTL8231_FIELD_LED_START =
> > REG_FIELD(RTL8231_REG_FUNC0, 1, 1);
> 
> Why does this have to be global?
> 
> Variables should be lowercase.

Moving it to the one place where it's used.

> > +static const struct mfd_cell rtl8231_cells[] = {
> > +	{
> > +		.name = "rtl8231-pinctrl",
> > +	},
> > +	{
> > +		.name = "rtl8231-leds",
> > +		.of_compatible = "realtek,rtl8231-leds",
> > +	},
> > +};
> 
> This is a pretty tenuous MFD!

I suppose two functions is the minimum to count as multi-functional :-)

I need a place to perform chip detection and to start the output drivers. The
latter could be part of a pinctrl driver, but making the led driver depend on
the pinctrl driver doesn't sit too well with me. Now the functionality is
cleanly split across the MFD core driver and pinctrl/led drivers.

> > +static int rtl8231_soft_reset(struct regmap *map)
> 
> s/map/regmap/

Ack, replaced throughout the driver.

> > +{
> > +	const unsigned int all_pins_mask = GENMASK(RTL8231_BITS_VAL - 1,
> > 0);
> > +	unsigned int val;
> > +	int err;
> > +
> > +	/* SOFT_RESET bit self-clears when done */
> > +	regmap_write_bits(map, RTL8231_REG_PIN_HI_CFG,
> > +		RTL8231_PIN_HI_CFG_SOFT_RESET,
> > RTL8231_PIN_HI_CFG_SOFT_RESET);
> > +	err = regmap_read_poll_timeout(map, RTL8231_REG_PIN_HI_CFG, val,
> > +		!(val & RTL8231_PIN_HI_CFG_SOFT_RESET), 50, 1000);
> > +	if (err)
> > +		return err;
> 
> Do we have to scrunch these calls together?

Made it a bit less claustrophobic.

> > +	regcache_mark_dirty(map);

This marks the device register state as invalid, which isn't what I wanted here.
After a reset, the cache should be repopulated, so this is now:

	regcache_drop_region(0, RTL8231_REG_COUNT - 1);

> > +static int rtl8231_init(struct device *dev, struct regmap *map)
> > +{
> > +	struct regmap_field *led_start;
> > +	unsigned int started;
> > +	unsigned int val;
> 
> If this is used for only one thing, it makes sense to use better
> nomenclature that refers to that thing.

Ack, updated the naming a bit.

> > +	led_start = dev_get_drvdata(dev);
> > +	err = regmap_field_read(led_start, &started);
> > +	if (err)
> > +		return err;
> > +
> > +	if (!started) {
> 
> Reverse the logic and exit early if 'started'.

Ack

> 
> > +		err = rtl8231_soft_reset(map);
> > +		if (err)
> > +			return err;
> 
> '\n' here.

Ack

> > +		/* LED_START enables power to output pins, and starts the
> > LED engine */
> > +		err = regmap_field_force_write(led_start, 1);

This is in a volatile register, so the driver doesn't need to force anything to
write to the device and will now use regmap_field_write().

> > +	led_start = devm_regmap_field_alloc(dev, map,
> > RTL8231_FIELD_LED_START);
> > +	if (IS_ERR(led_start))
> > +		return PTR_ERR(led_start);
> 
> Why do we need to do LED specific actions in the core driver?

The is naming taken from the datasheet. Setting LED_START actually enables both
the LED scanning output engine and the output drivers. So this is needed for
proper functioning of the GPIO functionality too.


> > +	return devm_mfd_add_devices(dev, PLATFORM_DEVID_AUTO,
> > rtl8231_cells,
> > +		ARRAY_SIZE(rtl8231_cells), NULL, 0, NULL);
> 
> Odd tabbing.  Please line-up with the '(' like usual.

Ack

> > +__maybe_unused static int rtl8231_suspend(struct device *dev)
> 
> The __maybe_unused comes after the "static int" part.

Ack.

C11 attributes like [[maybe_unused]] must come before the "static int" part, but
that doesn't line up with how most of the kernel uses the attributes.


Best,
Sander

  reply	other threads:[~2025-11-13 21:33 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-10-21 14:23 [PATCH v6 0/8] RTL8231 GPIO expander support Sander Vanheule
2025-10-21 14:23 ` [PATCH v6 1/8] gpio: regmap: Force writes for aliased data regs Sander Vanheule
2025-10-21 14:23 ` [PATCH v6 2/8] gpio: regmap: Bypass cache for aliased inputs Sander Vanheule
2025-10-23 12:06   ` Bartosz Golaszewski
2025-10-21 14:23 ` [PATCH v6 3/8] dt-bindings: leds: Binding for RTL8231 scan matrix Sander Vanheule
2025-10-26 21:59   ` Rob Herring
2025-10-27 17:12     ` Sander Vanheule
2025-10-21 14:23 ` [PATCH v6 4/8] dt-bindings: mfd: Binding for RTL8231 Sander Vanheule
2025-10-26 22:04   ` Rob Herring
2025-10-21 14:24 ` [PATCH v6 5/8] mfd: Add RTL8231 core device Sander Vanheule
2025-11-06 16:33   ` Lee Jones
2025-11-13 21:25     ` Sander Vanheule [this message]
2025-10-21 14:24 ` [PATCH v6 6/8] pinctrl: Add RTL8231 pin control and GPIO support Sander Vanheule
2025-10-22  1:47   ` kernel test robot
2025-10-22  5:01   ` kernel test robot
2025-10-22  7:42   ` Linus Walleij
2025-10-22  7:52     ` Linus Walleij
2025-10-22  8:24     ` Sander Vanheule
2025-10-21 14:24 ` [PATCH v6 7/8] leds: Add support for RTL8231 LED scan matrix Sander Vanheule
2025-10-21 14:24 ` [PATCH v6 8/8] MAINTAINERS: Add RTL8231 MFD driver Sander Vanheule
2025-10-23  9:05 ` [PATCH v6 0/8] RTL8231 GPIO expander support Bartosz Golaszewski
2025-10-23  9:09   ` Sander Vanheule
2025-10-23 12:05 ` (subset) " Bartosz Golaszewski

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=d50db8a305d92b20a972a590f2082f39a8027edc.camel@svanheule.net \
    --to=sander@svanheule.net \
    --cc=brgl@bgdev.pl \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=krzk+dt@kernel.org \
    --cc=lee@kernel.org \
    --cc=linus.walleij@linaro.org \
    --cc=linux-gpio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-leds@vger.kernel.org \
    --cc=mwalle@kernel.org \
    --cc=pavel@kernel.org \
    --cc=robh@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).