linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] mmc: sunxi-mmc: check ocr_avail on resource request
@ 2022-01-04  6:03 Michael Wu
  2022-01-12  9:34 ` Maxime Ripard
  0 siblings, 1 reply; 3+ messages in thread
From: Michael Wu @ 2022-01-04  6:03 UTC (permalink / raw)
  To: ulf.hansson, mripard, wens, samuel, andre.przywara
  Cc: jernej.skrabec, linux-mmc, linux-arm-kernel, linux-sunxi,
	linux-kernel, Michael Wu

Some platforms have no regulator, discrete power devices are used instead.
However, sunxi_mmc_probe does not catch this exception when regulator is
absent in DTS. This leads to sd or eMMC init failure.

To solve this, a fixed vmmc regulator must be hooked up in DTS, like this:
reg_dummy_vmmc: dummy_vmmc {
	compatible = "regulator-fixed";
	regulator-name = "dummy-vmmc";
	regulator-min-microvolt = <3300000>;
	regulator-max-microvolt = <3300000>;
};

mmc0:mmc@4020000 {
	compatible = "allwinner,sun50i-a100-emmc";
	device_type = "mmc0";
	vmmc-supply = <&reg_dummy_vmmc>;
}

In this patch, we print an error message and abort the probe process if
the regulator is not specified in DTS.

Signed-off-by: Michael Wu <michael@allwinnertech.com>
---
 drivers/mmc/host/sunxi-mmc.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/drivers/mmc/host/sunxi-mmc.c b/drivers/mmc/host/sunxi-mmc.c
index 2702736a1c57..0da74bddaf87 100644
--- a/drivers/mmc/host/sunxi-mmc.c
+++ b/drivers/mmc/host/sunxi-mmc.c
@@ -1300,6 +1300,11 @@ static int sunxi_mmc_resource_request(struct sunxi_mmc_host *host,
 	if (ret)
 		return ret;
 
+	if (!host->mmc->ocr_avail) {
+		dev_err(&pdev->dev, "Could not get mmc regulator\n");
+		return -EINVAL;
+	}
+
 	host->reg_base = devm_platform_ioremap_resource(pdev, 0);
 	if (IS_ERR(host->reg_base))
 		return PTR_ERR(host->reg_base);
-- 
2.29.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH v2] mmc: sunxi-mmc: check ocr_avail on resource request
  2022-01-04  6:03 [PATCH v2] mmc: sunxi-mmc: check ocr_avail on resource request Michael Wu
@ 2022-01-12  9:34 ` Maxime Ripard
  2022-01-12 10:37   ` Ulf Hansson
  0 siblings, 1 reply; 3+ messages in thread
From: Maxime Ripard @ 2022-01-12  9:34 UTC (permalink / raw)
  To: Michael Wu
  Cc: ulf.hansson, wens, samuel, andre.przywara, jernej.skrabec,
	linux-mmc, linux-arm-kernel, linux-sunxi, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 1731 bytes --]

Hi,

On Tue, Jan 04, 2022 at 02:03:25PM +0800, Michael Wu wrote:
> Some platforms have no regulator, discrete power devices are used instead.

Is it really the case? vmmc at least should be mandatory so a platform
not having a regulator would violate the binding itself.

> However, sunxi_mmc_probe does not catch this exception when regulator is
> absent in DTS. This leads to sd or eMMC init failure.

This will still happen with your patch though?

> To solve this, a fixed vmmc regulator must be hooked up in DTS, like this:
> reg_dummy_vmmc: dummy_vmmc {
> 	compatible = "regulator-fixed";
> 	regulator-name = "dummy-vmmc";
> 	regulator-min-microvolt = <3300000>;
> 	regulator-max-microvolt = <3300000>;
> };
> 
> mmc0:mmc@4020000 {
> 	compatible = "allwinner,sun50i-a100-emmc";
> 	device_type = "mmc0";
> 	vmmc-supply = <&reg_dummy_vmmc>;
> }
> 
> In this patch, we print an error message and abort the probe process if
> the regulator is not specified in DTS.

I'm fine with the patch itself, but it's really not clear to me what
situation is being fixed or improved here.

You're first mentioning that this is fixing the driver probing even if a
regulator is absent, but then states (rightfully) that in such a case we
should use a fixed regulator. So we should always have a regulator then?

I assume that you want the driver to properly error out instead of going
on if either a regulator is missing or if its voltages are out of range?

If the former, then we should probably check if host->mmc->supply.vmmc
returned an error. If the latter, then yes, checking ocr_avail is
probably fine but we should make it clearer in the error message that
it's what it's about.

Maxime

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH v2] mmc: sunxi-mmc: check ocr_avail on resource request
  2022-01-12  9:34 ` Maxime Ripard
@ 2022-01-12 10:37   ` Ulf Hansson
  0 siblings, 0 replies; 3+ messages in thread
From: Ulf Hansson @ 2022-01-12 10:37 UTC (permalink / raw)
  To: Maxime Ripard, Michael Wu
  Cc: wens, samuel, andre.przywara, jernej.skrabec, linux-mmc,
	linux-arm-kernel, linux-sunxi, linux-kernel

On Wed, 12 Jan 2022 at 10:34, Maxime Ripard <maxime@cerno.tech> wrote:
>
> Hi,
>
> On Tue, Jan 04, 2022 at 02:03:25PM +0800, Michael Wu wrote:
> > Some platforms have no regulator, discrete power devices are used instead.
>
> Is it really the case? vmmc at least should be mandatory so a platform
> not having a regulator would violate the binding itself.
>
> > However, sunxi_mmc_probe does not catch this exception when regulator is
> > absent in DTS. This leads to sd or eMMC init failure.
>
> This will still happen with your patch though?
>
> > To solve this, a fixed vmmc regulator must be hooked up in DTS, like this:
> > reg_dummy_vmmc: dummy_vmmc {
> >       compatible = "regulator-fixed";
> >       regulator-name = "dummy-vmmc";
> >       regulator-min-microvolt = <3300000>;
> >       regulator-max-microvolt = <3300000>;
> > };
> >
> > mmc0:mmc@4020000 {
> >       compatible = "allwinner,sun50i-a100-emmc";
> >       device_type = "mmc0";
> >       vmmc-supply = <&reg_dummy_vmmc>;
> > }
> >
> > In this patch, we print an error message and abort the probe process if
> > the regulator is not specified in DTS.
>
> I'm fine with the patch itself, but it's really not clear to me what
> situation is being fixed or improved here.
>
> You're first mentioning that this is fixing the driver probing even if a
> regulator is absent, but then states (rightfully) that in such a case we
> should use a fixed regulator. So we should always have a regulator then?
>
> I assume that you want the driver to properly error out instead of going
> on if either a regulator is missing or if its voltages are out of range?
>
> If the former, then we should probably check if host->mmc->supply.vmmc
> returned an error. If the latter, then yes, checking ocr_avail is
> probably fine but we should make it clearer in the error message that
> it's what it's about.

Just wanted to mention that I just had a very similar discussion
around another patch [1]. Please have a look at that discussion to get
my opinion on this.

Kind regards
Uffe

[1]
https://patchwork.kernel.org/project/linux-mmc/patch/20211215130711.111186-4-gsomlo@gmail.com/

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-01-12 10:38 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-01-04  6:03 [PATCH v2] mmc: sunxi-mmc: check ocr_avail on resource request Michael Wu
2022-01-12  9:34 ` Maxime Ripard
2022-01-12 10:37   ` Ulf Hansson

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).