linux-gpio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Matti Vaittinen <mazziesaccount@gmail.com>
To: Andreas Kemnade <andreas@kemnade.info>
Cc: Lee Jones <lee@kernel.org>,
	Matti Vaittinen <matti.vaittinen@fi.rohmeurope.com>,
	Pavel Machek <pavel@kernel.org>, Rob Herring <robh@kernel.org>,
	Krzysztof Kozlowski <krzk+dt@kernel.org>,
	Conor Dooley <conor+dt@kernel.org>,
	Sebastian Reichel <sre@kernel.org>,
	Liam Girdwood <lgirdwood@gmail.com>,
	Mark Brown <broonie@kernel.org>,
	Linus Walleij <linus.walleij@linaro.org>,
	Bartosz Golaszewski <brgl@bgdev.pl>,
	linux-leds@vger.kernel.org, devicetree@vger.kernel.org,
	linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org,
	linux-gpio@vger.kernel.org
Subject: Re: [RFC PATCH 06/13] mfd: bd71828: Support ROHM BD72720
Date: Tue, 14 Oct 2025 08:41:55 +0300	[thread overview]
Message-ID: <5ef55577-b8ae-4c8d-a965-ee356c47c691@gmail.com> (raw)
In-Reply-To: <20251013151900.3e4cc69f@kemnade.info>

On 13/10/2025 16:19, Andreas Kemnade wrote:
> On Mon, 13 Oct 2025 12:27:33 +0300
> Matti Vaittinen <mazziesaccount@gmail.com> wrote:
> 
>> Hi Andreas!
>>
>> First of all, thanks for taking a look at this!
>>
>> On 10/10/2025 16:03, Andreas Kemnade wrote:
>>> On Fri, 10 Oct 2025 15:09:07 +0300
>>> Matti Vaittinen <mazziesaccount@gmail.com> wrote:
>>>    
>>>>>> +static int bd72720_get_secondary_regmap(struct i2c_client *i2c,
>>>>>
>>>>> Does this 'secondary' have a specific purpose or a better name?
>>>>
>>>> I am not entirely sure. When I asked this from the designers they just
>>>> told me that they needed more than 255 registers so they added another
>>>> slave address... (I'm not sure what would have been wrong with using a
>>>> page register). So, I assume they just placed stuff that didn't fit in
>>>> first 255 register there. But yeah, it looks like most of the registers
>>>> there are related to the charger. So, perhaps it isn't completely
>>>> misleading to use "charger regmap"? The data-sheet seems to be just
>>>> using "Register map 1" and "Register map 2" in the tables listing these
>>>> registers. I kind of like using something which maps easily to the
>>>> data-sheet, but I really have no strong opinion on this.
>>>
>>> just another idea: What about one regmap with custom functions covering
>>> both these adresses? Maybe that could even be added to the regmap
>>> functionality, maybe with a 0x100 offset for the second range.
>>> That way the rest of the code only needs to real with one regmap
>>> and properly defined registers.
>>
>> Interesting idea.
>>
>> I suppose you mean something like implementing custom remap_read() and
>> regmap_write() - which would practically select the I2C adapter to use
>> based on the register address - and then doing same thing as the
>> regmap_i2c_smbus_i2c_write() / regmap_i2c_smbus_i2c_read() do?
>>
>> I suppose this would mean duplicating the functionality provided by the
>> regmap_i2c_smbus_i2c_write() and the regmap_i2c_smbus_i2c_read(), which
>> are static. It'd also mean we'll lose the 1 to 1 mapping between the
>> register addresses in driver and addresses in the data-sheet. I agree
>> this wouldn't be such a huge thing if we used offset like 0x100 though.
>>
> Well, you could also stack regmaps like ntxec.c is doing (but there
> for some very weird reason). That would avoid duplicating code.

Ah. I suppose you suggest I'd try something like:

/* untested, not compiled, pseudo-code */

struct bd72720_regmaps {
	struct regmap *map1_4b;
	struct regmap *map2_4c;
};

static int regmap_write_wrapper(void *context,
				unsigned int reg, unsigned int val)
{
	struct bd72720_regmaps *maps = context;

	if (reg >= 0x100)
		return regmap_write(maps->map2_4c, reg, val);

	return regmap_write(maps->map1_4b, reg, val);
}

static int regmap_read_wrapper(void *context, unsigned int reg,
				unsigned int *val)
{
	if (reg >= 0x100)
		return regmap_read(maps->map2_4c, reg, val);

	return regmap_read(maps->map1_4b, reg, val);

}

static const struct regmap_config wrapper_map_config {
	.name = 
"Maybe_a_descriptive_name_here_Which_devices_can_use_to_get_this_instead_of_map1_4b",
	...
	.reg_write = regmap_write_wrapper,
	.reg_read = regmap_read_wrapper,
}

probe()
{
	struct bd72720_regmaps *maps;
	struct regmap *the_map_we_use_from_all_the_devices;
...
	maps->map1_4b = devm_regmap_init_i2c(i2c, &bd72720_regmap_4b);
	maps->map2_4c = devm_regmap_init_i2c(i2c2, &bd72720_regmap_4c);

	/* Init wrapper map */
	the_map_we_use_from_all_the_devices = devm_regmap_init(dev,
		NULL, maps, wrapper_map_config);
}

If this works, then I kind of like this. It avoids using the platform 
data and simplifies the regmap getting in the power_supply driver. 
Thanks for the good idea Andreas!

Lee, objections to this?

Yours,
	-- Matti

  reply	other threads:[~2025-10-14  5:41 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-10-07  8:32 [RFC PATCH 00/13] Support ROHM BD72720 PMIC Matti Vaittinen
2025-10-07  8:32 ` [RFC PATCH 01/13] dt-bindings: regulator: ROHM BD72720 Matti Vaittinen
2025-10-07  8:33 ` [RFC PATCH 02/13] dt-bindings: Add trickle-charge upper limit Matti Vaittinen
2025-10-13 12:31   ` Linus Walleij
2025-10-07  8:33 ` [RFC PATCH 03/13] dt-bindings: power: supply: BD72720 managed battery Matti Vaittinen
2025-10-13 12:45   ` Linus Walleij
2025-10-13 13:00     ` Matti Vaittinen
2025-10-14 10:29       ` Linus Walleij
2025-10-07  8:33 ` [RFC PATCH 04/13] dt-bindings: mfd: ROHM BD72720 Matti Vaittinen
2025-10-13 12:58   ` Linus Walleij
2025-10-14 12:11     ` Matti Vaittinen
2025-10-14 12:58       ` Linus Walleij
2025-10-07  8:33 ` [RFC PATCH 05/13] dt-bindings: leds: bd72720: Add BD72720 Matti Vaittinen
2025-10-07  8:33 ` [RFC PATCH 06/13] mfd: bd71828: Support ROHM BD72720 Matti Vaittinen
2025-10-09 16:18   ` Lee Jones
2025-10-10 12:09     ` Matti Vaittinen
2025-10-10 13:03       ` Andreas Kemnade
2025-10-13  9:27         ` Matti Vaittinen
2025-10-13 13:19           ` Andreas Kemnade
2025-10-14  5:41             ` Matti Vaittinen [this message]
2025-10-15  7:46               ` Matti Vaittinen
2025-10-10 14:45       ` Lee Jones
2025-10-13 12:28         ` Matti Vaittinen
2025-10-16 15:27           ` Lee Jones
2025-10-07  8:34 ` [RFC PATCH 07/13] regulator: bd71828: rename IC specific entities Matti Vaittinen
2025-10-07  8:34 ` [RFC PATCH 08/13] regulator: bd71828: Support ROHM BD72720 Matti Vaittinen
2025-10-07  8:34 ` [RFC PATCH 09/13] gpio: Support ROHM BD72720 gpios Matti Vaittinen
2025-10-13 12:54   ` Linus Walleij
2025-10-16 11:04   ` Bartosz Golaszewski
2025-10-07  8:34 ` [RFC PATCH 10/13] clk: clk-bd718x7: Support BD72720 clk gate Matti Vaittinen
2025-10-07  8:34 ` [RFC PATCH 11/13] rtc: bd70528: Support BD72720 rtc Matti Vaittinen
2025-10-07  8:35 ` [RFC PATCH 12/13] power: supply: bd71828-power: Support ROHM BD72720 Matti Vaittinen
2025-10-07  8:35 ` [RFC PATCH 13/13] MAINTAINERS: Add ROHM BD72720 PMIC Matti Vaittinen

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=5ef55577-b8ae-4c8d-a965-ee356c47c691@gmail.com \
    --to=mazziesaccount@gmail.com \
    --cc=andreas@kemnade.info \
    --cc=brgl@bgdev.pl \
    --cc=broonie@kernel.org \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=krzk+dt@kernel.org \
    --cc=lee@kernel.org \
    --cc=lgirdwood@gmail.com \
    --cc=linus.walleij@linaro.org \
    --cc=linux-gpio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-leds@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=matti.vaittinen@fi.rohmeurope.com \
    --cc=pavel@kernel.org \
    --cc=robh@kernel.org \
    --cc=sre@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).