mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Jerome Brunet <jbrunet@baylibre.com>
To: Luca Weiss <luca@lucaweiss.eu>
Cc: Liam Girdwood <lgirdwood@gmail.com>,
	 Mark Brown <broonie@kernel.org>,
	linux-kernel@vger.kernel.org,  Guenter Roeck <linux@roeck-us.net>
Subject: Re: [PATCH v2 1/3] regulator: core: do not silently ignore provided init_data
Date: Sun, 09 Feb 2025 20:05:05 +0100	[thread overview]
Message-ID: <1jwmdz0wim.fsf@starbuckisacylon.baylibre.com> (raw)
In-Reply-To: <5857103.DvuYhMxLoT@lucaweiss.eu> (Luca Weiss's message of "Sun, 09 Feb 2025 15:16:17 +0100")

On Sun 09 Feb 2025 at 15:16, Luca Weiss <luca@lucaweiss.eu> wrote:

> On dinsdag 8 oktober 2024 18:07:01 Midden-Europese standaardtijd Jerome Brunet wrote:
>> On DT platforms, if a regulator init_data is provided in config, it is
>> silently ignored in favor of the DT parsing done by the framework, if
>> of_match is set.
>> 
>> of_match is an indication that init_data is expected to be set based on DT
>> and the parsing should be done by the regulator framework.
>> 
>> If the regulator provider passed init_data it must be because it is useful
>> somehow, in such case of_match should be clear.
>> 
>> If the driver expects the framework to initialize this data on its
>> own, it should leave init_data clear.
>> 
>> Warn if both init_data and of_match are set, then default to the provided
>> init_data.
>
> Hi Jerome,
>
> This commit is breaking USB on qcom-msm8974-lge-nexus5-hammerhead for me.
>
> I can't easily provide the full log since USB is breaking with this but in
> effect it looks like in drivers/usb/chipidea/core.c in ci_get_platdata()
> the call devm_regulator_get_optional(dev, "vbus"); is always returning
> EPROBE_DEFER, so USB never initializes.

Sorry about that.

>
> This vbus regulator is provided by ti,bq24192 so the bq24190_charger.c
> driver. While the driver does seem to probe correctly, I do also see that
> warning "Using provided init data - OF match ignored" in dmesg.

Well the driver does this funny thing of passing init_data but also
setting the of_match.

Looking at it more, your driver provide init_data/constraint here:

https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/drivers/power/supply/bq24190_charger.c?h=v6.12.13#n718

Apparently this constraint is only meant as a backup/default in case
nothing is matched by the platform, which would explain why your
platform through the trouble of passing an empty regulator node to
override it.

https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/arch/arm/boot/dts/qcom/qcom-msm8974-lge-nexus5-hammerhead.dts#n116

I did not really expect that but it seems intended indeed.
Revert is probably the sane thing to do but it would be nice to have
comment about that and maybe a debug print.

Mark, do you want to revert this directly or shall I submit the change
for you to apply ?

>
> Reverting this patch on top of v6.13.2 fixes the issue and makes USB work
> again.
>
> Regards
> Luca
>
>> 
>> Signed-off-by: Jerome Brunet <jbrunet@baylibre.com>
>> ---
>>  drivers/regulator/core.c | 57 +++++++++++++++++++++++++++++-------------------
>>  1 file changed, 34 insertions(+), 23 deletions(-)
>> 
>> diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
>> index d0b3879f2746..a58a9db3d9c7 100644
>> --- a/drivers/regulator/core.c
>> +++ b/drivers/regulator/core.c
>> @@ -5681,32 +5681,43 @@ regulator_register(struct device *dev,
>>  		goto clean;
>>  	}
>>  
>> -	init_data = regulator_of_get_init_data(dev, regulator_desc, config,
>> -					       &rdev->dev.of_node);
>> -
>> -	/*
>> -	 * Sometimes not all resources are probed already so we need to take
>> -	 * that into account. This happens most the time if the ena_gpiod comes
>> -	 * from a gpio extender or something else.
>> -	 */
>> -	if (PTR_ERR(init_data) == -EPROBE_DEFER) {
>> -		ret = -EPROBE_DEFER;
>> -		goto clean;
>> -	}
>> +	if (config->init_data) {
>> +		/*
>> +		 * Providing of_match means the framework is expected to parse
>> +		 * DT to get the init_data. This would conflict with provided
>> +		 * init_data, if set. Warn if it happens.
>> +		 */
>> +		if (regulator_desc->of_match)
>> +			dev_warn(dev, "Using provided init data - OF match ignored\n");
>>  
>> -	/*
>> -	 * We need to keep track of any GPIO descriptor coming from the
>> -	 * device tree until we have handled it over to the core. If the
>> -	 * config that was passed in to this function DOES NOT contain
>> -	 * a descriptor, and the config after this call DOES contain
>> -	 * a descriptor, we definitely got one from parsing the device
>> -	 * tree.
>> -	 */
>> -	if (!cfg->ena_gpiod && config->ena_gpiod)
>> -		dangling_of_gpiod = true;
>> -	if (!init_data) {
>>  		init_data = config->init_data;
>>  		rdev->dev.of_node = of_node_get(config->of_node);
>> +
>> +	} else {
>> +		init_data = regulator_of_get_init_data(dev, regulator_desc,
>> +						       config,
>> +						       &rdev->dev.of_node);
>> +
>> +		/*
>> +		 * Sometimes not all resources are probed already so we need to
>> +		 * take that into account. This happens most the time if the
>> +		 * ena_gpiod comes from a gpio extender or something else.
>> +		 */
>> +		if (PTR_ERR(init_data) == -EPROBE_DEFER) {
>> +			ret = -EPROBE_DEFER;
>> +			goto clean;
>> +		}
>> +
>> +		/*
>> +		 * We need to keep track of any GPIO descriptor coming from the
>> +		 * device tree until we have handled it over to the core. If the
>> +		 * config that was passed in to this function DOES NOT contain a
>> +		 * descriptor, and the config after this call DOES contain a
>> +		 * descriptor, we definitely got one from parsing the device
>> +		 * tree.
>> +		 */
>> +		if (!cfg->ena_gpiod && config->ena_gpiod)
>> +			dangling_of_gpiod = true;
>>  	}
>>  
>>  	ww_mutex_init(&rdev->mutex, &regulator_ww_class);
>> 
>> 

-- 
Jerome

  reply	other threads:[~2025-02-09 19:05 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-10-08 16:07 [PATCH v2 0/3] regulator: init_data handling update Jerome Brunet
2024-10-08 16:07 ` [PATCH v2 1/3] regulator: core: do not silently ignore provided init_data Jerome Brunet
2025-02-09 14:16   ` Luca Weiss
2025-02-09 19:05     ` Jerome Brunet [this message]
2025-02-10 13:06       ` Mark Brown
2024-10-08 16:07 ` [PATCH v2 2/3] regulator: core: add callback to perform runtime init Jerome Brunet
2024-10-08 16:07 ` [PATCH v2 3/3] regulator: core: remove machine init callback from config Jerome Brunet
2024-10-22 23:04 ` [PATCH v2 0/3] regulator: init_data handling update Mark Brown

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=1jwmdz0wim.fsf@starbuckisacylon.baylibre.com \
    --to=jbrunet@baylibre.com \
    --cc=broonie@kernel.org \
    --cc=lgirdwood@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@roeck-us.net \
    --cc=luca@lucaweiss.eu \
    /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

all inboxes | Powered by JetHome®