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 requiring a "full" regmap configuration to be provided to
change only the max_register value, Lee Jones suggested allowing
max_register to be specified in the simple_mfd_data structure. The
8-bit register 8-bit configuration is still used by default, but
max_register is also applied if it is non-zero.
If both regmap_config and max_register are provided, the max_register
field in the regmap_config structure is ignored.
Signed-off-by: Alex Elder <elder@riscstar.com>
Suggested-by: Lee Jones <lee@kernel.org>
---
v10: - Rename simple_regmap_config() -> simple_regmap_config_get()
- Introduce simple_regmap_config_put() to free regmap_config
drivers/mfd/simple-mfd-i2c.c | 45 ++++++++++++++++++++++++++++++++----
drivers/mfd/simple-mfd-i2c.h | 5 +---
2 files changed, 41 insertions(+), 9 deletions(-)
diff --git a/drivers/mfd/simple-mfd-i2c.c b/drivers/mfd/simple-mfd-i2c.c
index 22159913bea03..3622f189c8342 100644
--- a/drivers/mfd/simple-mfd-i2c.c
+++ b/drivers/mfd/simple-mfd-i2c.c
@@ -29,6 +29,40 @@ static const struct regmap_config regmap_config_8r_8v = {
.val_bits = 8,
};
+static const struct regmap_config *
+simple_regmap_config_get(const struct simple_mfd_data *data)
+{
+ struct regmap_config *regmap_config;
+ const struct regmap_config *source;
+
+ if (!data)
+ return ®map_config_8r_8v;
+
+ source = data->regmap_config ? : ®map_config_8r_8v;
+
+ if (!data->max_register)
+ return source;
+
+ regmap_config = kmemdup(source, sizeof(*regmap_config), GFP_KERNEL);
+ if (regmap_config)
+ regmap_config->max_register = data->max_register;
+
+ return regmap_config;
+}
+
+static void simple_regmap_config_put(const struct simple_mfd_data *data,
+ const struct regmap_config *regmap_config)
+{
+ /* This condition holds if data is null */
+ if (regmap_config == ®map_config_8r_8v)
+ return;
+
+ if (regmap_config == data->regmap_config)
+ return;
+
+ kfree(regmap_config);
+}
+
static int simple_mfd_i2c_probe(struct i2c_client *i2c)
{
const struct simple_mfd_data *simple_mfd_data;
@@ -38,13 +72,14 @@ static int simple_mfd_i2c_probe(struct i2c_client *i2c)
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 = simple_regmap_config_get(simple_mfd_data);
+ if (!regmap_config)
+ return -ENOMEM;
regmap = devm_regmap_init_i2c(i2c, regmap_config);
+
+ simple_regmap_config_put(simple_mfd_data, 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..6fa36b3d7a217 100644
--- a/drivers/mfd/simple-mfd-i2c.h
+++ b/drivers/mfd/simple-mfd-i2c.h
@@ -8,10 +8,6 @@
* shared by all sub-devices. Children can use their parent's device structure
* (dev.parent) in order to reference it.
*
- * This driver creates a single register map with the intention for it to be
- * shared by all sub-devices. Children can use their parent's device structure
- * (dev.parent) in order to reference it.
- *
* Once the register map has been successfully initialised, any sub-devices
* represented by child nodes in Device Tree or via the MFD cells in the
* associated C file will be subsequently registered.
@@ -25,6 +21,7 @@
struct simple_mfd_data {
const struct regmap_config *regmap_config;
+ unsigned int max_register;
const struct mfd_cell *mfd_cell;
size_t mfd_cell_size;
};
--
2.48.1
On Sat, 26 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 requiring a "full" regmap configuration to be provided to > change only the max_register value, Lee Jones suggested allowing > max_register to be specified in the simple_mfd_data structure. The > 8-bit register 8-bit configuration is still used by default, but > max_register is also applied if it is non-zero. > > If both regmap_config and max_register are provided, the max_register > field in the regmap_config structure is ignored. > > Signed-off-by: Alex Elder <elder@riscstar.com> > Suggested-by: Lee Jones <lee@kernel.org> > --- > v10: - Rename simple_regmap_config() -> simple_regmap_config_get() > - Introduce simple_regmap_config_put() to free regmap_config > > drivers/mfd/simple-mfd-i2c.c | 45 ++++++++++++++++++++++++++++++++---- > drivers/mfd/simple-mfd-i2c.h | 5 +--- > 2 files changed, 41 insertions(+), 9 deletions(-) This has gone from an in-function 11 line change to 50 lines and the inclusion of 2 new functions. As much as I _really_ appreciate the time and effort you have put into this [0], the added complexity being added here doesn't sit right with me. How would you like to go back to your v4 idea of providing a bespoke regmap_config for for device? [0] Beers on me for sending you down this path! -- Lee Jones [李琼斯]
On 7/31/25 8:18 AM, Lee Jones wrote: > On Sat, 26 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 requiring a "full" regmap configuration to be provided to >> change only the max_register value, Lee Jones suggested allowing >> max_register to be specified in the simple_mfd_data structure. The >> 8-bit register 8-bit configuration is still used by default, but >> max_register is also applied if it is non-zero. >> >> If both regmap_config and max_register are provided, the max_register >> field in the regmap_config structure is ignored. >> >> Signed-off-by: Alex Elder <elder@riscstar.com> >> Suggested-by: Lee Jones <lee@kernel.org> >> --- >> v10: - Rename simple_regmap_config() -> simple_regmap_config_get() >> - Introduce simple_regmap_config_put() to free regmap_config >> >> drivers/mfd/simple-mfd-i2c.c | 45 ++++++++++++++++++++++++++++++++---- >> drivers/mfd/simple-mfd-i2c.h | 5 +--- >> 2 files changed, 41 insertions(+), 9 deletions(-) > > This has gone from an in-function 11 line change to 50 lines and the > inclusion of 2 new functions. As much as I _really_ appreciate the time > and effort you have put into this [0], the added complexity being added > here doesn't sit right with me. How would you like to go back to your > v4 idea of providing a bespoke regmap_config for for device? I LOVE this suggestion. I will send v11 shortly and it will be very much like v6 (or something like that). > [0] Beers on me for sending you down this path! I'm looking forward to seeing you again, beer or not. Thanks Lee. -Alex
On Thu, 31 Jul 2025, Alex Elder wrote: > On 7/31/25 8:18 AM, Lee Jones wrote: > > On Sat, 26 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 requiring a "full" regmap configuration to be provided to > > > change only the max_register value, Lee Jones suggested allowing > > > max_register to be specified in the simple_mfd_data structure. The > > > 8-bit register 8-bit configuration is still used by default, but > > > max_register is also applied if it is non-zero. > > > > > > If both regmap_config and max_register are provided, the max_register > > > field in the regmap_config structure is ignored. > > > > > > Signed-off-by: Alex Elder <elder@riscstar.com> > > > Suggested-by: Lee Jones <lee@kernel.org> > > > --- > > > v10: - Rename simple_regmap_config() -> simple_regmap_config_get() > > > - Introduce simple_regmap_config_put() to free regmap_config > > > > > > drivers/mfd/simple-mfd-i2c.c | 45 ++++++++++++++++++++++++++++++++---- > > > drivers/mfd/simple-mfd-i2c.h | 5 +--- > > > 2 files changed, 41 insertions(+), 9 deletions(-) > > > > This has gone from an in-function 11 line change to 50 lines and the > > inclusion of 2 new functions. As much as I _really_ appreciate the time > > and effort you have put into this [0], the added complexity being added > > here doesn't sit right with me. How would you like to go back to your > > v4 idea of providing a bespoke regmap_config for for device? > > I LOVE this suggestion. I will send v11 shortly and it will > be very much like v6 (or something like that). > > > [0] Beers on me for sending you down this path! > > I'm looking forward to seeing you again, beer or not. Likewise! =:-) -- Lee Jones [李琼斯]
© 2016 - 2026 Red Hat, Inc.