[PATCH v7 2/8] mfd: simple-mfd-i2c: specify max_register
Alex Elder
elder at riscstar.com
Thu Jul 10 05:21:27 PDT 2025
On 7/10/25 4:24 AM, Lee Jones wrote:
> On Wed, 02 Jul 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 custom configuration, but no existing
>> device uses it.
>>
>> Rather than specify a "full" regmap configuration to use this
>> option, Lee Jones suggested allowing just the max_register value
>> to be specified in the simple_mfd_data structure.
>>
>> Signed-off-by: Alex Elder <elder at riscstar.com>
>> Suggested-by: Lee Jones <lee at kernel.org>
>> ---
>> v2: - Allow max_register *and* regmap_config to be supplied
>>
>> drivers/mfd/simple-mfd-i2c.c | 15 ++++++++++++---
>> drivers/mfd/simple-mfd-i2c.h | 1 +
>> 2 files changed, 13 insertions(+), 3 deletions(-)
>>
>> diff --git a/drivers/mfd/simple-mfd-i2c.c b/drivers/mfd/simple-mfd-i2c.c
>> index 22159913bea03..3f959f4f98261 100644
>> --- a/drivers/mfd/simple-mfd-i2c.c
>> +++ b/drivers/mfd/simple-mfd-i2c.c
>> @@ -33,16 +33,25 @@ 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 config;
>
> Why do we need another regmap_config?
>
> Can't we just remove the const and make use of the one above?
If we change the global one, it changes for all users.
In my next version I will modify the global one temporarily and
zero the max_register field again after the devm_regmap_init_i2c()
call. That doesn't protect against concurrent probes but I don't
think that's a problem.
>> 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)
>> + if (simple_mfd_data) {
>> + if (simple_mfd_data->regmap_config)
>> + config = *simple_mfd_data->regmap_config;
>
> regmap_config = simple_mfd_data->regmap_config;
>
>> + else
>> + config = regmap_config_8r_8v;
>
> regmap_config = ®map_config_8r_8v;
>> +
>> + if (simple_mfd_data->max_register)
>> + config.max_register = simple_mfd_data->max_register;
>> + regmap_config = &config;
>> + } else {
>> regmap_config = ®map_config_8r_8v;
>
> I suspect we don't need to have this line twice.
>
> Either re-jig the if () above (I suspect this explains the existing
> complexity [multiple conditions]) or pre-set regmap_config to
> regmap_config_8r_8v and only over-write it if the conditions are met.
Sure, that would work, but it won't be needed if I just use
the (non-const) global config.
Thanks for the review.
-Alex
>
>> - else - regmap_config = simple_mfd_data->regmap_config;
>> + }
>>
>> regmap = devm_regmap_init_i2c(i2c, regmap_config); if
>> (IS_ERR(regmap)) diff --git a/drivers/mfd/simple-mfd-i2c.h
>> b/drivers/mfd/simple-mfd-i2c.h index
>> 7cb2bdd347d97..706b6f53155ff 100644 ---
>> a/drivers/mfd/simple-mfd-i2c.h +++
>> b/drivers/mfd/simple-mfd-i2c.h @@ -27,6 +27,7 @@ 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
>>
>
More information about the linux-riscv
mailing list