mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
To: Philipp Zabel <p.zabel@pengutronix.de>,
	Srinivas Kandagatla <srinivas.kandagatla@linaro.org>,
	Banajit Goswami <bgoswami@quicinc.com>,
	Bjorn Andersson <andersson@kernel.org>,
	Konrad Dybcio <konrad.dybcio@linaro.org>,
	Liam Girdwood <lgirdwood@gmail.com>,
	Mark Brown <broonie@kernel.org>, Rob Herring <robh+dt@kernel.org>,
	Krzysztof Kozlowski <krzysztof.kozlowski+dt@linaro.org>,
	Conor Dooley <conor+dt@kernel.org>,
	Jaroslav Kysela <perex@perex.cz>, Takashi Iwai <tiwai@suse.com>,
	alsa-devel@alsa-project.org, linux-arm-msm@vger.kernel.org,
	linux-sound@vger.kernel.org, devicetree@vger.kernel.org,
	linux-kernel@vger.kernel.org
Cc: Bartosz Golaszewski <brgl@bgdev.pl>,
	Sean Anderson <sean.anderson@seco.com>
Subject: Re: [PATCH v2 2/4] reset: Instantiate reset GPIO controller for shared reset-gpios
Date: Thu, 11 Jan 2024 10:48:06 +0100	[thread overview]
Message-ID: <fe7c0524-cbe9-4b02-bfec-5c5b5491cf17@linaro.org> (raw)
In-Reply-To: <fda63ae95d050e46dcb2446f0d841e01354a8643.camel@pengutronix.de>

On 09/01/2024 12:58, Philipp Zabel wrote:
>>>> +	/* Not freed in normal path, persisent subsyst data */
>>>> +	rgpio_dev = kzalloc(sizeof(*rgpio_dev), GFP_KERNEL);
>>>
>>> Since this is persistent, instead of letting the reset-gpio driver call
>>> of_parse_phandle_with_args() again, this could be passed in via
>>> platform data. Is there a reason not to do that instead?
>>
>> We can pass it as read only platform data, but we cannot pass the
>> ownership. This is associated with registered platform device, not with
>> bound one device->driver.
>>
>> Imagine case:
>> 1. modprobe reset-gpio,
>> 2. Driver is bound to the device,
>> 3. unbind  (echo > unbind)
>> 4. rmmod
>> 5. goto 1
> 
> Keeping ownership on the list is fine, the reset-gpio driver makes its
> own copy of of_phandle_args anyway. I was just wondering whether it
> could make this copy from platform data instead of from the
> of_parse_phandle_with_args() return value.

Looks like it could. This could save us few lines of code in
reset-gpio.c. I'll try it.

> 
> [...]
>>>
>>>> @@ -839,21 +960,50 @@ __of_reset_control_get(struct device_node *node, const char *id, int index,
>>>>  					 index, &args);
>>>>  	if (ret == -EINVAL)
>>>>  		return ERR_PTR(ret);
>>>> -	if (ret)
>>>> -		return optional ? NULL : ERR_PTR(ret);
>>>> +	if (ret) {
>>>> +		/*
>>>> +		 * There can be only one reset-gpio for regular devices, so
>>>> +		 * don't bother with GPIO index.
>>>> +		 */
>>>
>>> I don't understand this comment. The GPIO index should be checked as
>>> part of __reset_gpios_args_match(), or should it not?
>>
>> This and earlier comment are result of a bit hacky approach to the
>> problem: how to find reset controllers for that GPIO?
>>
>> The point is that our reset gpio controller has only 1 reset, thus
>> of_reset_n_cells=1. However args_count from of_parse_handle is >0, which
>> later is compared in reset core:
>>
>> https://elixir.bootlin.com/linux/latest/source/drivers/reset/core.c#L859
>>
>> That part we need to match.
>>
>> I could make the reset-gpio driver to have of_reset_n_cells=2, but what
>> would be the point? The rest of the cells are not really relevant,
>> because you cannot refer to this reset gpio controller with any other
>> arguments.
>>
>> To remind: my solution spawns one reset-gpio controller for one GPIO.
> 
> Thank you. I think we could also just make that check
> 
> 	if (WARN_ON(!rcdev->of_args && ...))
> 
> instead and skip the of_xlate call in that case (or implement of_xlate
> in the reset-gpio driver to make this more explicit).

Ack

> 
>>>
>>>> +		ret = of_parse_phandle_with_args(node, "reset-gpios", "#gpio-cells",
>>>> +						 0, &args);
>>>> +		if (ret)
>>>> +			return optional ? NULL : ERR_PTR(ret);
>>>>  
>>>> -	mutex_lock(&reset_list_mutex);
>>>> -	rcdev = NULL;
>>>> -	list_for_each_entry(r, &reset_controller_list, list) {
>>>> -		if (args.np == r->of_node) {
>>>> -			rcdev = r;
>>>> -			break;
>>>> -		}
>>>> +		gpio_fallback = true;
>>>
>>> Is there a reason not just call __reset_add_reset_gpio_device() here?
>>> With that, there should be no need to call __reset_find_rcdev() twice.
>>
>> Hm, could be, although not sure if code would be simpler.
>>
>> This entire function handles two cases:
>> 1. Get normal reset controller ("resets" OF property),
>> 2. If above fails, get reset-gpio controller ("reset-gpios" OF property)
>>
>> Therefore the entire solution is following approach:
>> 1. of_parse_phandle(resets)
>> 1b. error? Then of_parse_phandle(reset-gpios)
>> 2. Find reset-controller based on any of above phandles.
>> 3. error? Check if we created reset-gpios platform device. If not:
>> create new reset-gpios platform device/
>> 3b. Platform device could probe, so lookup again for reset controller or
>> defer probe.
>>
>> What type of flow do you propose?
> 
> I propose to reorder after parsing the phandles: check/create the gpio
> platform device right after parsing the gpio handle. Only then lock
> reset_list_mutex look for the rcdev.
> 
> 1. of_parse_phandle(resets)
> 1b. error? Then of_parse_phandle(reset-gpios)
> 2b. gpio? Then check if we created reset-gpios platform device. If not:
> create new reset-gpios platform device/, defer if probe failed
> 3. Lock reset_list_mutex, find reset-controller based on any of above
> phandles.

Could work, let me try. I have impression this was my first approach
which resulted in a bit more complicated code, but I don't remember the
details now.

> 
>>
>>>
>>>>  	}
>>>>  
>>>> +	mutex_lock(&reset_list_mutex);
>>>> +	rcdev = __reset_find_rcdev(&args, gpio_fallback, NULL);
>>>
>>> This gets called with args as parsed. If there is a match, this will 
>>> overwrite args (in the gpio_fallback case) and return NULL.
>>
>> Overwrite not complete. It will only overwrite args_count and return a
>> valid rcdev.
>> I do not see overwriting in case of returning NULL.
> 
> Sorry, I meant to write
> 
> "This gets called with args as parsed. If there is a match, this will 
>  overwrite args (in the gpio_fallback case) _or_ return NULL."
> 
> at least at the end, when I understood the following.
> 
>>>
>>>> +
>>>>  	if (!rcdev) {
> 
> So in this non-NULL branch there was no overwriting.
> 
>>>> -		rstc = ERR_PTR(-EPROBE_DEFER);
>>>> -		goto out;
>>>> +		if (gpio_fallback) {
>>>> +			/*
>>>> +			 * Registering reset-gpio device might cause immediate
>>>> +			 * bind, thus taking reset_list_mutex lock via
>>>> +			 * reset_controller_register().
>>>> +			 */
>>>> +			mutex_unlock(&reset_list_mutex);
>>>> +			ret = __reset_add_reset_gpio_device(node, &args);
>>>
>>> So this will also be called with args as parsed.
>>>
>>>> +			mutex_lock(&reset_list_mutex);
>>>> +			if (ret) {
>>>> +				rstc = ERR_PTR(ret);
>>>> +				goto out;
>>>> +			}
>>>> +			/*
>>>> +			 * Success: reset-gpio could probe immediately, so
>>>> +			 * re-check the lookup.
>>>> +			 */
>>>> +			rcdev = __reset_find_rcdev(&args, gpio_fallback, NULL);
>>>
>>> And this will again be called with args as parsed and overwrite args
>>> again.>
>>>> +			if (!rcdev) {
>>>> +				rstc = ERR_PTR(-EPROBE_DEFER);
>>>> +				goto out;
>>>> +			}
>>>> +			/* Success, rcdev is valid thus do not bail out */
>>>> +		} else {
>>>> +			rstc = ERR_PTR(-EPROBE_DEFER);
>>>> +			goto out;
>>>> +		}
>>>>  	}
>>>
>>> So at this point args is overwritten in the gpio_fallback case. I would
>>> find it much clearer to just overwrite args here and make the first
>>> parameter to __reset_find_rcdev() const.
>>
>> I think I get your point. Overwriting happens after we store the
>> original of_args, but the code is indeed not intuitive. I think I can
>> move it further, as you suggested.
> 
> Now I think we can skip the overwriting altogether and just adapt the
> following of_reset_n_cells check ad of_xlate call as mentioned above.


Yep!

Best regards,
Krzysztof


  reply	other threads:[~2024-01-11  9:48 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-01-05 15:59 [PATCH v2 0/4] reset: gpio: ASoC: shared GPIO resets Krzysztof Kozlowski
2024-01-05 15:59 ` [PATCH v2 1/4] reset: gpio: Add GPIO-based reset controller Krzysztof Kozlowski
2024-01-05 16:39   ` Biju Das
2024-01-06 15:28     ` Krzysztof Kozlowski
2024-01-07 10:46       ` Biju Das
2024-01-07 11:56         ` Krzysztof Kozlowski
2024-01-08 12:21   ` Philipp Zabel
2024-01-09 11:00     ` Krzysztof Kozlowski
2024-01-05 15:59 ` [PATCH v2 2/4] reset: Instantiate reset GPIO controller for shared reset-gpios Krzysztof Kozlowski
2024-01-08 12:17   ` Philipp Zabel
2024-01-09 10:59     ` Krzysztof Kozlowski
2024-01-09 11:58       ` Philipp Zabel
2024-01-11  9:48         ` Krzysztof Kozlowski [this message]
2024-01-05 15:59 ` [PATCH v2 3/4] ASoC: dt-bindings: qcom,wsa8840: Add reset-gpios for shared line Krzysztof Kozlowski
2024-01-05 15:59 ` [PATCH v2 4/4] ASoC: codecs: wsa884x: Allow sharing reset GPIO Krzysztof Kozlowski
     [not found] ` <d86f0d2c-40fc-44d2-94f6-e67068e55594@alliedtelesis.co.nz>
2024-01-08  9:44   ` [PATCH v2 0/4] reset: gpio: ASoC: shared GPIO resets Krzysztof Kozlowski

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=fe7c0524-cbe9-4b02-bfec-5c5b5491cf17@linaro.org \
    --to=krzysztof.kozlowski@linaro.org \
    --cc=alsa-devel@alsa-project.org \
    --cc=andersson@kernel.org \
    --cc=bgoswami@quicinc.com \
    --cc=brgl@bgdev.pl \
    --cc=broonie@kernel.org \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=konrad.dybcio@linaro.org \
    --cc=krzysztof.kozlowski+dt@linaro.org \
    --cc=lgirdwood@gmail.com \
    --cc=linux-arm-msm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-sound@vger.kernel.org \
    --cc=p.zabel@pengutronix.de \
    --cc=perex@perex.cz \
    --cc=robh+dt@kernel.org \
    --cc=sean.anderson@seco.com \
    --cc=srinivas.kandagatla@linaro.org \
    --cc=tiwai@suse.com \
    /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®