All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/2] mmc: jz4740: Work around bug on JZ4760(B)
@ 2023-01-31 21:02 Paul Cercueil
  2023-01-31 21:02 ` [PATCH 2/2] mmc: jz4740: Add support for vqmmc power supply Paul Cercueil
  2023-02-13 23:48 ` [PATCH 1/2] mmc: jz4740: Work around bug on JZ4760(B) Ulf Hansson
  0 siblings, 2 replies; 4+ messages in thread
From: Paul Cercueil @ 2023-01-31 21:02 UTC (permalink / raw)
  To: Ulf Hansson; +Cc: linux-mips, linux-mmc, linux-kernel, list, Paul Cercueil

On JZ4760 and JZ4760B, SD cards fail to run if the maximum clock
rate is set to 50 MHz, even though the controller officially does
support it.

Until the actual bug is found and fixed, limit the maximum clock rate to
24 MHz.

Signed-off-by: Paul Cercueil <paul@crapouillou.net>
---
 drivers/mmc/host/jz4740_mmc.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/drivers/mmc/host/jz4740_mmc.c b/drivers/mmc/host/jz4740_mmc.c
index 319a2a79c9a0..eb8e9607b086 100644
--- a/drivers/mmc/host/jz4740_mmc.c
+++ b/drivers/mmc/host/jz4740_mmc.c
@@ -1104,6 +1104,16 @@ static int jz4740_mmc_probe(struct platform_device* pdev)
 	mmc->ops = &jz4740_mmc_ops;
 	if (!mmc->f_max)
 		mmc->f_max = JZ_MMC_CLK_RATE;
+
+	/*
+	 * There seems to be a problem with this driver on the JZ4760 and
+	 * JZ4760B SoCs. There, when using the maximum rate supported (50 MHz),
+	 * the communication fails with many SD cards.
+	 * Until this bug is sorted out, limit the maximum rate to 24 MHz.
+	 */
+	if (host->version == JZ_MMC_JZ4760 && mmc->f_max > JZ_MMC_CLK_RATE)
+		mmc->f_max = JZ_MMC_CLK_RATE;
+
 	mmc->f_min = mmc->f_max / 128;
 	mmc->ocr_avail = MMC_VDD_32_33 | MMC_VDD_33_34;
 
-- 
2.39.1


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

* [PATCH 2/2] mmc: jz4740: Add support for vqmmc power supply
  2023-01-31 21:02 [PATCH 1/2] mmc: jz4740: Work around bug on JZ4760(B) Paul Cercueil
@ 2023-01-31 21:02 ` Paul Cercueil
  2023-02-13 23:48   ` Ulf Hansson
  2023-02-13 23:48 ` [PATCH 1/2] mmc: jz4740: Work around bug on JZ4760(B) Ulf Hansson
  1 sibling, 1 reply; 4+ messages in thread
From: Paul Cercueil @ 2023-01-31 21:02 UTC (permalink / raw)
  To: Ulf Hansson; +Cc: linux-mips, linux-mmc, linux-kernel, list, Paul Cercueil

Support enabling / disabling the vqmmc power supply if it was provided
by the firmware.

Provide the .start_signal_voltage_switch callback to change the voltage
of the external vqmmc power supply.

Signed-off-by: Paul Cercueil <paul@crapouillou.net>
---
 drivers/mmc/host/jz4740_mmc.c | 38 ++++++++++++++++++++++++++++++++++-
 1 file changed, 37 insertions(+), 1 deletion(-)

diff --git a/drivers/mmc/host/jz4740_mmc.c b/drivers/mmc/host/jz4740_mmc.c
index eb8e9607b086..ccd2c3aed0f0 100644
--- a/drivers/mmc/host/jz4740_mmc.c
+++ b/drivers/mmc/host/jz4740_mmc.c
@@ -21,6 +21,7 @@
 #include <linux/of_device.h>
 #include <linux/pinctrl/consumer.h>
 #include <linux/platform_device.h>
+#include <linux/regulator/consumer.h>
 #include <linux/rwsem.h>
 #include <linux/scatterlist.h>
 
@@ -162,6 +163,8 @@ struct jz4740_mmc_host {
 	struct mmc_request *req;
 	struct mmc_command *cmd;
 
+	bool vqmmc_enabled;
+
 	unsigned long waiting;
 
 	uint32_t cmdat;
@@ -943,6 +946,8 @@ static void jz4740_mmc_request(struct mmc_host *mmc, struct mmc_request *req)
 static void jz4740_mmc_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
 {
 	struct jz4740_mmc_host *host = mmc_priv(mmc);
+	int ret;
+
 	if (ios->clock)
 		jz4740_mmc_set_clock_rate(host, ios->clock);
 
@@ -955,12 +960,25 @@ static void jz4740_mmc_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
 		clk_prepare_enable(host->clk);
 		break;
 	case MMC_POWER_ON:
+		if (!IS_ERR(mmc->supply.vqmmc) && !host->vqmmc_enabled) {
+			ret = regulator_enable(mmc->supply.vqmmc);
+			if (ret)
+				dev_err(&host->pdev->dev, "Failed to set vqmmc power!\n");
+			else
+				host->vqmmc_enabled = true;
+		}
 		break;
-	default:
+	case MMC_POWER_OFF:
 		if (!IS_ERR(mmc->supply.vmmc))
 			mmc_regulator_set_ocr(mmc, mmc->supply.vmmc, 0);
+		if (!IS_ERR(mmc->supply.vqmmc) && host->vqmmc_enabled) {
+			regulator_disable(mmc->supply.vqmmc);
+			host->vqmmc_enabled = false;
+		}
 		clk_disable_unprepare(host->clk);
 		break;
+	default:
+		break;
 	}
 
 	switch (ios->bus_width) {
@@ -986,6 +1004,23 @@ static void jz4740_mmc_enable_sdio_irq(struct mmc_host *mmc, int enable)
 	jz4740_mmc_set_irq_enabled(host, JZ_MMC_IRQ_SDIO, enable);
 }
 
+static int jz4740_voltage_switch(struct mmc_host *mmc, struct mmc_ios *ios)
+{
+	int ret;
+
+	/* vqmmc regulator is available */
+	if (!IS_ERR(mmc->supply.vqmmc)) {
+		ret = mmc_regulator_set_vqmmc(mmc, ios);
+		return ret < 0 ? ret : 0;
+	}
+
+	/* no vqmmc regulator, assume fixed regulator at 3/3.3V */
+	if (ios->signal_voltage == MMC_SIGNAL_VOLTAGE_330)
+		return 0;
+
+	return -EINVAL;
+}
+
 static const struct mmc_host_ops jz4740_mmc_ops = {
 	.request	= jz4740_mmc_request,
 	.pre_req	= jz4740_mmc_pre_request,
@@ -994,6 +1029,7 @@ static const struct mmc_host_ops jz4740_mmc_ops = {
 	.get_ro		= mmc_gpio_get_ro,
 	.get_cd		= mmc_gpio_get_cd,
 	.enable_sdio_irq = jz4740_mmc_enable_sdio_irq,
+	.start_signal_voltage_switch = jz4740_voltage_switch,
 };
 
 static inline struct jz4740_mmc_host *
-- 
2.39.1


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

* Re: [PATCH 1/2] mmc: jz4740: Work around bug on JZ4760(B)
  2023-01-31 21:02 [PATCH 1/2] mmc: jz4740: Work around bug on JZ4760(B) Paul Cercueil
  2023-01-31 21:02 ` [PATCH 2/2] mmc: jz4740: Add support for vqmmc power supply Paul Cercueil
@ 2023-02-13 23:48 ` Ulf Hansson
  1 sibling, 0 replies; 4+ messages in thread
From: Ulf Hansson @ 2023-02-13 23:48 UTC (permalink / raw)
  To: Paul Cercueil; +Cc: linux-mips, linux-mmc, linux-kernel, list

On Tue, 31 Jan 2023 at 22:02, Paul Cercueil <paul@crapouillou.net> wrote:
>
> On JZ4760 and JZ4760B, SD cards fail to run if the maximum clock
> rate is set to 50 MHz, even though the controller officially does
> support it.
>
> Until the actual bug is found and fixed, limit the maximum clock rate to
> 24 MHz.
>
> Signed-off-by: Paul Cercueil <paul@crapouillou.net>

Applied for fixes and by adding a stable tag, thanks!

Kind regards
Uffe


> ---
>  drivers/mmc/host/jz4740_mmc.c | 10 ++++++++++
>  1 file changed, 10 insertions(+)
>
> diff --git a/drivers/mmc/host/jz4740_mmc.c b/drivers/mmc/host/jz4740_mmc.c
> index 319a2a79c9a0..eb8e9607b086 100644
> --- a/drivers/mmc/host/jz4740_mmc.c
> +++ b/drivers/mmc/host/jz4740_mmc.c
> @@ -1104,6 +1104,16 @@ static int jz4740_mmc_probe(struct platform_device* pdev)
>         mmc->ops = &jz4740_mmc_ops;
>         if (!mmc->f_max)
>                 mmc->f_max = JZ_MMC_CLK_RATE;
> +
> +       /*
> +        * There seems to be a problem with this driver on the JZ4760 and
> +        * JZ4760B SoCs. There, when using the maximum rate supported (50 MHz),
> +        * the communication fails with many SD cards.
> +        * Until this bug is sorted out, limit the maximum rate to 24 MHz.
> +        */
> +       if (host->version == JZ_MMC_JZ4760 && mmc->f_max > JZ_MMC_CLK_RATE)
> +               mmc->f_max = JZ_MMC_CLK_RATE;
> +
>         mmc->f_min = mmc->f_max / 128;
>         mmc->ocr_avail = MMC_VDD_32_33 | MMC_VDD_33_34;
>
> --
> 2.39.1
>

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

* Re: [PATCH 2/2] mmc: jz4740: Add support for vqmmc power supply
  2023-01-31 21:02 ` [PATCH 2/2] mmc: jz4740: Add support for vqmmc power supply Paul Cercueil
@ 2023-02-13 23:48   ` Ulf Hansson
  0 siblings, 0 replies; 4+ messages in thread
From: Ulf Hansson @ 2023-02-13 23:48 UTC (permalink / raw)
  To: Paul Cercueil; +Cc: linux-mips, linux-mmc, linux-kernel, list

On Tue, 31 Jan 2023 at 22:02, Paul Cercueil <paul@crapouillou.net> wrote:
>
> Support enabling / disabling the vqmmc power supply if it was provided
> by the firmware.
>
> Provide the .start_signal_voltage_switch callback to change the voltage
> of the external vqmmc power supply.
>
> Signed-off-by: Paul Cercueil <paul@crapouillou.net>

Applied for next, thanks!

Kind regards
Uffe


> ---
>  drivers/mmc/host/jz4740_mmc.c | 38 ++++++++++++++++++++++++++++++++++-
>  1 file changed, 37 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/mmc/host/jz4740_mmc.c b/drivers/mmc/host/jz4740_mmc.c
> index eb8e9607b086..ccd2c3aed0f0 100644
> --- a/drivers/mmc/host/jz4740_mmc.c
> +++ b/drivers/mmc/host/jz4740_mmc.c
> @@ -21,6 +21,7 @@
>  #include <linux/of_device.h>
>  #include <linux/pinctrl/consumer.h>
>  #include <linux/platform_device.h>
> +#include <linux/regulator/consumer.h>
>  #include <linux/rwsem.h>
>  #include <linux/scatterlist.h>
>
> @@ -162,6 +163,8 @@ struct jz4740_mmc_host {
>         struct mmc_request *req;
>         struct mmc_command *cmd;
>
> +       bool vqmmc_enabled;
> +
>         unsigned long waiting;
>
>         uint32_t cmdat;
> @@ -943,6 +946,8 @@ static void jz4740_mmc_request(struct mmc_host *mmc, struct mmc_request *req)
>  static void jz4740_mmc_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
>  {
>         struct jz4740_mmc_host *host = mmc_priv(mmc);
> +       int ret;
> +
>         if (ios->clock)
>                 jz4740_mmc_set_clock_rate(host, ios->clock);
>
> @@ -955,12 +960,25 @@ static void jz4740_mmc_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
>                 clk_prepare_enable(host->clk);
>                 break;
>         case MMC_POWER_ON:
> +               if (!IS_ERR(mmc->supply.vqmmc) && !host->vqmmc_enabled) {
> +                       ret = regulator_enable(mmc->supply.vqmmc);
> +                       if (ret)
> +                               dev_err(&host->pdev->dev, "Failed to set vqmmc power!\n");
> +                       else
> +                               host->vqmmc_enabled = true;
> +               }
>                 break;
> -       default:
> +       case MMC_POWER_OFF:
>                 if (!IS_ERR(mmc->supply.vmmc))
>                         mmc_regulator_set_ocr(mmc, mmc->supply.vmmc, 0);
> +               if (!IS_ERR(mmc->supply.vqmmc) && host->vqmmc_enabled) {
> +                       regulator_disable(mmc->supply.vqmmc);
> +                       host->vqmmc_enabled = false;
> +               }
>                 clk_disable_unprepare(host->clk);
>                 break;
> +       default:
> +               break;
>         }
>
>         switch (ios->bus_width) {
> @@ -986,6 +1004,23 @@ static void jz4740_mmc_enable_sdio_irq(struct mmc_host *mmc, int enable)
>         jz4740_mmc_set_irq_enabled(host, JZ_MMC_IRQ_SDIO, enable);
>  }
>
> +static int jz4740_voltage_switch(struct mmc_host *mmc, struct mmc_ios *ios)
> +{
> +       int ret;
> +
> +       /* vqmmc regulator is available */
> +       if (!IS_ERR(mmc->supply.vqmmc)) {
> +               ret = mmc_regulator_set_vqmmc(mmc, ios);
> +               return ret < 0 ? ret : 0;
> +       }
> +
> +       /* no vqmmc regulator, assume fixed regulator at 3/3.3V */
> +       if (ios->signal_voltage == MMC_SIGNAL_VOLTAGE_330)
> +               return 0;
> +
> +       return -EINVAL;
> +}
> +
>  static const struct mmc_host_ops jz4740_mmc_ops = {
>         .request        = jz4740_mmc_request,
>         .pre_req        = jz4740_mmc_pre_request,
> @@ -994,6 +1029,7 @@ static const struct mmc_host_ops jz4740_mmc_ops = {
>         .get_ro         = mmc_gpio_get_ro,
>         .get_cd         = mmc_gpio_get_cd,
>         .enable_sdio_irq = jz4740_mmc_enable_sdio_irq,
> +       .start_signal_voltage_switch = jz4740_voltage_switch,
>  };
>
>  static inline struct jz4740_mmc_host *
> --
> 2.39.1
>

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

end of thread, other threads:[~2023-02-13 23:50 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-01-31 21:02 [PATCH 1/2] mmc: jz4740: Work around bug on JZ4760(B) Paul Cercueil
2023-01-31 21:02 ` [PATCH 2/2] mmc: jz4740: Add support for vqmmc power supply Paul Cercueil
2023-02-13 23:48   ` Ulf Hansson
2023-02-13 23:48 ` [PATCH 1/2] mmc: jz4740: Work around bug on JZ4760(B) Ulf Hansson

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.