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.
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 = ®map_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, ®map_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
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 = ®map_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, ®map_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 [李琼斯]
On 7/2/25 10:26 AM, Lee Jones wrote:
> 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.
OK, sorry I misunderstood. I'll send another new version today
that does what you suggest.
Thanks a lot.
-Alex
> 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 = ®map_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, ®map_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
>>
>
On Wed, 02 Jul 2025, Alex Elder wrote: > On 7/2/25 10:26 AM, Lee Jones wrote: > > 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. > > OK, sorry I misunderstood. I'll send another new version today > that does what you suggest. No worries. Perhaps I wasn't clear enough. -- Lee Jones [李琼斯]
© 2016 - 2026 Red Hat, Inc.