All of lore.kernel.org
 help / color / mirror / Atom feed
From: Lee Jones <lee@kernel.org>
To: Alex Elder <elder@riscstar.com>
Cc: lgirdwood@gmail.com, broonie@kernel.org,
	alexandre.belloni@bootlin.com, robh@kernel.org,
	krzk+dt@kernel.org, conor+dt@kernel.org, mat.jonczyk@o2.pl,
	dlan@gentoo.org, paul.walmsley@sifive.com, palmer@dabbelt.com,
	aou@eecs.berkeley.edu, alex@ghiti.fr, troymitchell988@gmail.com,
	guodong@riscstar.com, linux-rtc@vger.kernel.org,
	devicetree@vger.kernel.org, linux-riscv@lists.infradead.org,
	spacemit@lists.linux.dev, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v6 2/8] mfd: simple-mfd-i2c: specify max_register
Date: Wed, 2 Jul 2025 16:26:18 +0100	[thread overview]
Message-ID: <20250702152618.GU10134@google.com> (raw)
In-Reply-To: <20250627142309.1444135-3-elder@riscstar.com>

On Fri, 27 Jun 2025, Alex Elder wrote:

> All devices supported by simple MFD use the same 8-bit register
> 8-bit value regmap configuration.  There is an option available
> for a device to specify a custome configuration, but no existing
> device uses it.
> 
> Lee Jones suggested modifying the simple MFD implementation to
> remove the generality of the full regmap configuration and add a
> max_register value to the simple_mfd_data structure.  This can
> be used in the regmap configuration to limit the valid register
> addresses if desired.  It's simpler, and covers all existing and
> anticipated device types.

Woah, not like this.  I wanted to make the framework _more_ flexible.

Just this should do what you want:

diff --git a/drivers/mfd/simple-mfd-i2c.c b/drivers/mfd/simple-mfd-i2c.c
index 22159913bea0..f43be10c0e60 100644
--- a/drivers/mfd/simple-mfd-i2c.c
+++ b/drivers/mfd/simple-mfd-i2c.c
@@ -44,6 +44,9 @@ static int simple_mfd_i2c_probe(struct i2c_client *i2c)
        else
                regmap_config = simple_mfd_data->regmap_config;
 
+       if (simple_mfd_data->max_register)
+               regmap_config->max_register = simple_mfd_data->max_register;
+
        regmap = devm_regmap_init_i2c(i2c, regmap_config);
        if (IS_ERR(regmap))
                return PTR_ERR(regmap);

Plus the one line change in drivers/mfd/simple-mfd-i2c.h.

> Signed-off-by: Alex Elder <elder@riscstar.com>
> Suggested-by: Lee Jones <lee@kernel.org>
> ---
> v6: - New patch, changing the simple MFD functionality
> 
>  drivers/mfd/simple-mfd-i2c.c | 18 ++++++------------
>  drivers/mfd/simple-mfd-i2c.h |  2 +-
>  2 files changed, 7 insertions(+), 13 deletions(-)
> 
> diff --git a/drivers/mfd/simple-mfd-i2c.c b/drivers/mfd/simple-mfd-i2c.c
> index 22159913bea03..c1dc315d44dcf 100644
> --- a/drivers/mfd/simple-mfd-i2c.c
> +++ b/drivers/mfd/simple-mfd-i2c.c
> @@ -24,27 +24,21 @@
>  
>  #include "simple-mfd-i2c.h"
>  
> -static const struct regmap_config regmap_config_8r_8v = {
> -	.reg_bits = 8,
> -	.val_bits = 8,
> -};
> -
>  static int simple_mfd_i2c_probe(struct i2c_client *i2c)
>  {
>  	const struct simple_mfd_data *simple_mfd_data;
> -	const struct regmap_config *regmap_config;
> +	struct regmap_config regmap_config = { };
>  	struct regmap *regmap;
>  	int ret;
>  
>  	simple_mfd_data = device_get_match_data(&i2c->dev);
>  
> -	/* If no regmap_config is specified, use the default 8reg and 8val bits */
> -	if (!simple_mfd_data || !simple_mfd_data->regmap_config)
> -		regmap_config = &regmap_config_8r_8v;
> -	else
> -		regmap_config = simple_mfd_data->regmap_config;
> +	regmap_config.reg_bits = 8;
> +	regmap_config.val_bits = 8;
> +	if (simple_mfd_data)
> +		regmap_config.max_register = simple_mfd_data->max_register;
>  
> -	regmap = devm_regmap_init_i2c(i2c, regmap_config);
> +	regmap = devm_regmap_init_i2c(i2c, &regmap_config);
>  	if (IS_ERR(regmap))
>  		return PTR_ERR(regmap);
>  
> diff --git a/drivers/mfd/simple-mfd-i2c.h b/drivers/mfd/simple-mfd-i2c.h
> index 7cb2bdd347d97..4121fe1bc1d70 100644
> --- a/drivers/mfd/simple-mfd-i2c.h
> +++ b/drivers/mfd/simple-mfd-i2c.h
> @@ -24,9 +24,9 @@
>  #include <linux/regmap.h>
>  
>  struct simple_mfd_data {
> -	const struct regmap_config *regmap_config;
>  	const struct mfd_cell *mfd_cell;
>  	size_t mfd_cell_size;
> +	unsigned int max_register;
>  };
>  
>  #endif /* __MFD_SIMPLE_MFD_I2C_H */
> -- 
> 2.45.2
> 

-- 
Lee Jones [李琼斯]

WARNING: multiple messages have this Message-ID (diff)
From: Lee Jones <lee@kernel.org>
To: Alex Elder <elder@riscstar.com>
Cc: lgirdwood@gmail.com, broonie@kernel.org,
	alexandre.belloni@bootlin.com, robh@kernel.org,
	krzk+dt@kernel.org, conor+dt@kernel.org, mat.jonczyk@o2.pl,
	dlan@gentoo.org, paul.walmsley@sifive.com, palmer@dabbelt.com,
	aou@eecs.berkeley.edu, alex@ghiti.fr, troymitchell988@gmail.com,
	guodong@riscstar.com, linux-rtc@vger.kernel.org,
	devicetree@vger.kernel.org, linux-riscv@lists.infradead.org,
	spacemit@lists.linux.dev, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v6 2/8] mfd: simple-mfd-i2c: specify max_register
Date: Wed, 2 Jul 2025 16:26:18 +0100	[thread overview]
Message-ID: <20250702152618.GU10134@google.com> (raw)
In-Reply-To: <20250627142309.1444135-3-elder@riscstar.com>

On Fri, 27 Jun 2025, Alex Elder wrote:

> All devices supported by simple MFD use the same 8-bit register
> 8-bit value regmap configuration.  There is an option available
> for a device to specify a custome configuration, but no existing
> device uses it.
> 
> Lee Jones suggested modifying the simple MFD implementation to
> remove the generality of the full regmap configuration and add a
> max_register value to the simple_mfd_data structure.  This can
> be used in the regmap configuration to limit the valid register
> addresses if desired.  It's simpler, and covers all existing and
> anticipated device types.

Woah, not like this.  I wanted to make the framework _more_ flexible.

Just this should do what you want:

diff --git a/drivers/mfd/simple-mfd-i2c.c b/drivers/mfd/simple-mfd-i2c.c
index 22159913bea0..f43be10c0e60 100644
--- a/drivers/mfd/simple-mfd-i2c.c
+++ b/drivers/mfd/simple-mfd-i2c.c
@@ -44,6 +44,9 @@ static int simple_mfd_i2c_probe(struct i2c_client *i2c)
        else
                regmap_config = simple_mfd_data->regmap_config;
 
+       if (simple_mfd_data->max_register)
+               regmap_config->max_register = simple_mfd_data->max_register;
+
        regmap = devm_regmap_init_i2c(i2c, regmap_config);
        if (IS_ERR(regmap))
                return PTR_ERR(regmap);

Plus the one line change in drivers/mfd/simple-mfd-i2c.h.

> Signed-off-by: Alex Elder <elder@riscstar.com>
> Suggested-by: Lee Jones <lee@kernel.org>
> ---
> v6: - New patch, changing the simple MFD functionality
> 
>  drivers/mfd/simple-mfd-i2c.c | 18 ++++++------------
>  drivers/mfd/simple-mfd-i2c.h |  2 +-
>  2 files changed, 7 insertions(+), 13 deletions(-)
> 
> diff --git a/drivers/mfd/simple-mfd-i2c.c b/drivers/mfd/simple-mfd-i2c.c
> index 22159913bea03..c1dc315d44dcf 100644
> --- a/drivers/mfd/simple-mfd-i2c.c
> +++ b/drivers/mfd/simple-mfd-i2c.c
> @@ -24,27 +24,21 @@
>  
>  #include "simple-mfd-i2c.h"
>  
> -static const struct regmap_config regmap_config_8r_8v = {
> -	.reg_bits = 8,
> -	.val_bits = 8,
> -};
> -
>  static int simple_mfd_i2c_probe(struct i2c_client *i2c)
>  {
>  	const struct simple_mfd_data *simple_mfd_data;
> -	const struct regmap_config *regmap_config;
> +	struct regmap_config regmap_config = { };
>  	struct regmap *regmap;
>  	int ret;
>  
>  	simple_mfd_data = device_get_match_data(&i2c->dev);
>  
> -	/* If no regmap_config is specified, use the default 8reg and 8val bits */
> -	if (!simple_mfd_data || !simple_mfd_data->regmap_config)
> -		regmap_config = &regmap_config_8r_8v;
> -	else
> -		regmap_config = simple_mfd_data->regmap_config;
> +	regmap_config.reg_bits = 8;
> +	regmap_config.val_bits = 8;
> +	if (simple_mfd_data)
> +		regmap_config.max_register = simple_mfd_data->max_register;
>  
> -	regmap = devm_regmap_init_i2c(i2c, regmap_config);
> +	regmap = devm_regmap_init_i2c(i2c, &regmap_config);
>  	if (IS_ERR(regmap))
>  		return PTR_ERR(regmap);
>  
> diff --git a/drivers/mfd/simple-mfd-i2c.h b/drivers/mfd/simple-mfd-i2c.h
> index 7cb2bdd347d97..4121fe1bc1d70 100644
> --- a/drivers/mfd/simple-mfd-i2c.h
> +++ b/drivers/mfd/simple-mfd-i2c.h
> @@ -24,9 +24,9 @@
>  #include <linux/regmap.h>
>  
>  struct simple_mfd_data {
> -	const struct regmap_config *regmap_config;
>  	const struct mfd_cell *mfd_cell;
>  	size_t mfd_cell_size;
> +	unsigned int max_register;
>  };
>  
>  #endif /* __MFD_SIMPLE_MFD_I2C_H */
> -- 
> 2.45.2
> 

-- 
Lee Jones [李琼斯]

_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv

  reply	other threads:[~2025-07-02 15:26 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-06-27 14:22 [PATCH v6 0/8] spacemit: introduce P1 PMIC support Alex Elder
2025-06-27 14:22 ` Alex Elder
2025-06-27 14:23 ` [PATCH v6 1/8] dt-bindings: mfd: add support the SpacemiT P1 PMIC Alex Elder
2025-06-27 14:23   ` Alex Elder
2025-06-27 14:23 ` [PATCH v6 2/8] mfd: simple-mfd-i2c: specify max_register Alex Elder
2025-06-27 14:23   ` Alex Elder
2025-07-02 15:26   ` Lee Jones [this message]
2025-07-02 15:26     ` Lee Jones
2025-07-02 15:35     ` Alex Elder
2025-07-02 15:35       ` Alex Elder
2025-07-02 16:26       ` Lee Jones
2025-07-02 16:26         ` Lee Jones
2025-06-27 14:23 ` [PATCH v6 3/8] mfd: simple-mfd-i2c: add SpacemiT P1 support Alex Elder
2025-06-27 14:23   ` Alex Elder
2025-06-27 14:23 ` [PATCH v6 4/8] regulator: spacemit: support SpacemiT P1 regulators Alex Elder
2025-06-27 14:23   ` Alex Elder
2025-06-27 14:23 ` [PATCH v6 5/8] rtc: spacemit: support the SpacemiT P1 RTC Alex Elder
2025-06-27 14:23   ` Alex Elder
2025-06-27 14:23 ` [PATCH v6 6/8] riscv: dts: spacemit: enable the i2c8 adapter Alex Elder
2025-06-27 14:23   ` Alex Elder
2025-06-27 14:23 ` [PATCH v6 7/8] riscv: dts: spacemit: define fixed regulators Alex Elder
2025-06-27 14:23   ` Alex Elder
2025-06-27 14:23 ` [PATCH v6 8/8] riscv: dts: spacemit: define regulator constraints Alex Elder
2025-06-27 14:23   ` Alex Elder

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=20250702152618.GU10134@google.com \
    --to=lee@kernel.org \
    --cc=alex@ghiti.fr \
    --cc=alexandre.belloni@bootlin.com \
    --cc=aou@eecs.berkeley.edu \
    --cc=broonie@kernel.org \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=dlan@gentoo.org \
    --cc=elder@riscstar.com \
    --cc=guodong@riscstar.com \
    --cc=krzk+dt@kernel.org \
    --cc=lgirdwood@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-riscv@lists.infradead.org \
    --cc=linux-rtc@vger.kernel.org \
    --cc=mat.jonczyk@o2.pl \
    --cc=palmer@dabbelt.com \
    --cc=paul.walmsley@sifive.com \
    --cc=robh@kernel.org \
    --cc=spacemit@lists.linux.dev \
    --cc=troymitchell988@gmail.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.