All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH V2 1/4] mmc: mmci: Add bindings to operate CMD, CK, CKIN pins as GPIO
@ 2021-01-24 17:02 Marek Vasut
  2021-01-24 17:02 ` [PATCH V2 2/4] mmc: mmci: Add support for probing bus voltage level translator Marek Vasut
                   ` (4 more replies)
  0 siblings, 5 replies; 8+ messages in thread
From: Marek Vasut @ 2021-01-24 17:02 UTC (permalink / raw)
  To: linux-mmc
  Cc: Marek Vasut, Alexandre Torgue, Linus Walleij, Ludovic Barre,
	Rob Herring, Ulf Hansson, linux-stm32, devicetree

Add DT bindings to describe GPIO line associated with CMD, CK, CKIN pins.

Signed-off-by: Marek Vasut <marex@denx.de>
Cc: Alexandre Torgue <alexandre.torgue@st.com>
Cc: Linus Walleij <linus.walleij@linaro.org>
Cc: Ludovic Barre <ludovic.barre@st.com>
Cc: Rob Herring <robh+dt@kernel.org>
Cc: Ulf Hansson <ulf.hansson@linaro.org>
Cc: linux-stm32@st-md-mailman.stormreply.com
Cc: devicetree@vger.kernel.org
---
V2: Rebase on next-20210122
---
 .../devicetree/bindings/mmc/arm,pl18x.yaml    | 20 +++++++++++++++++++
 1 file changed, 20 insertions(+)

diff --git a/Documentation/devicetree/bindings/mmc/arm,pl18x.yaml b/Documentation/devicetree/bindings/mmc/arm,pl18x.yaml
index eddc1f6bdbe5..47595cb483be 100644
--- a/Documentation/devicetree/bindings/mmc/arm,pl18x.yaml
+++ b/Documentation/devicetree/bindings/mmc/arm,pl18x.yaml
@@ -127,6 +127,26 @@ properties:
       driver to sample the receive data (for example with a voltage switch
       transceiver).
 
+  st,cmd-gpios:
+    maxItems: 1
+    description:
+      The GPIO matching the CMD pin.
+
+  st,ck-gpios:
+    maxItems: 1
+    description:
+      The GPIO matching the CK pin.
+
+  st,ckin-gpios:
+    maxItems: 1
+    description:
+      The GPIO matching the CKIN pin.
+
+dependencies:
+  st,cmd-gpios: [ "st,use-ckin" ]
+  st,ck-gpios: [ "st,use-ckin" ]
+  st,ckin-gpios: [ "st,use-ckin" ]
+
 unevaluatedProperties: false
 
 required:
-- 
2.29.2


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

* [PATCH V2 2/4] mmc: mmci: Add support for probing bus voltage level translator
  2021-01-24 17:02 [PATCH V2 1/4] mmc: mmci: Add bindings to operate CMD, CK, CKIN pins as GPIO Marek Vasut
@ 2021-01-24 17:02 ` Marek Vasut
  2021-01-26  9:58   ` Ulf Hansson
  2021-01-24 17:02 ` [PATCH V2 3/4] ARM: dts: stm32: Add additional init state for SDMMC1 pins Marek Vasut
                   ` (3 subsequent siblings)
  4 siblings, 1 reply; 8+ messages in thread
From: Marek Vasut @ 2021-01-24 17:02 UTC (permalink / raw)
  To: linux-mmc
  Cc: Marek Vasut, Yann Gautier, Linus Walleij, Alexandre Torgue,
	Ludovic Barre, Ulf Hansson, linux-stm32

Add support for testing whether bus voltage level translator is present
and operational. This is useful on systems where the bus voltage level
translator is optional, as the translator can be auto-detected by the
driver and the feedback clock functionality can be disabled if it is
not present.

This requires additional pinmux state, "init", where the CMD, CK, CKIN
lines are not configured, so they can be claimed as GPIOs early on in
probe(). The translator test sets CMD high to avoid interfering with a
card, and then verifies whether signal set on CK is detected on CKIN.
If the signal is detected, translator is present, otherwise the CKIN
feedback clock are disabled.

Tested-by: Yann Gautier <yann.gautier@foss.st.com>
Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Marek Vasut <marex@denx.de>
Cc: Alexandre Torgue <alexandre.torgue@st.com>
Cc: Linus Walleij <linus.walleij@linaro.org>
Cc: Ludovic Barre <ludovic.barre@st.com>
Cc: Ulf Hansson <ulf.hansson@linaro.org>
Cc: linux-stm32@st-md-mailman.stormreply.com
---
V2: Rebase on next-20210122, add TB and RB
---
 drivers/mmc/host/mmci.c | 70 ++++++++++++++++++++++++++++++++++++++---
 1 file changed, 65 insertions(+), 5 deletions(-)

diff --git a/drivers/mmc/host/mmci.c b/drivers/mmc/host/mmci.c
index b5a41a7ce165..1bc674577ff9 100644
--- a/drivers/mmc/host/mmci.c
+++ b/drivers/mmc/host/mmci.c
@@ -36,6 +36,7 @@
 #include <linux/types.h>
 #include <linux/pinctrl/consumer.h>
 #include <linux/reset.h>
+#include <linux/gpio/consumer.h>
 
 #include <asm/div64.h>
 #include <asm/io.h>
@@ -1888,6 +1889,65 @@ static struct mmc_host_ops mmci_ops = {
 	.start_signal_voltage_switch = mmci_sig_volt_switch,
 };
 
+static void mmci_probe_level_translator(struct mmc_host *mmc)
+{
+	struct device *dev = mmc_dev(mmc);
+	struct mmci_host *host = mmc_priv(mmc);
+	struct gpio_desc *cmd_gpio;
+	struct gpio_desc *ck_gpio;
+	struct gpio_desc *ckin_gpio;
+	int clk_hi, clk_lo;
+
+	/*
+	 * Assume the level translator is present if st,use-ckin is set.
+	 * This is to cater for DTs which do not implement this test.
+	 */
+	host->clk_reg_add |= MCI_STM32_CLK_SELCKIN;
+
+	cmd_gpio = gpiod_get(dev, "st,cmd", GPIOD_OUT_HIGH);
+	if (IS_ERR(cmd_gpio))
+		goto exit_cmd;
+
+	ck_gpio = gpiod_get(dev, "st,ck", GPIOD_OUT_HIGH);
+	if (IS_ERR(ck_gpio))
+		goto exit_ck;
+
+	ckin_gpio = gpiod_get(dev, "st,ckin", GPIOD_IN);
+	if (IS_ERR(ckin_gpio))
+		goto exit_ckin;
+
+	/* All GPIOs are valid, test whether level translator works */
+
+	/* Sample CKIN */
+	clk_hi = !!gpiod_get_value(ckin_gpio);
+
+	/* Set CK low */
+	gpiod_set_value(ck_gpio, 0);
+
+	/* Sample CKIN */
+	clk_lo = !!gpiod_get_value(ckin_gpio);
+
+	/* Tristate all */
+	gpiod_direction_input(cmd_gpio);
+	gpiod_direction_input(ck_gpio);
+
+	/* Level translator is present if CK signal is propagated to CKIN */
+	if (!clk_hi || clk_lo) {
+		host->clk_reg_add &= ~MCI_STM32_CLK_SELCKIN;
+		dev_warn(dev,
+			 "Level translator inoperable, CK signal not detected on CKIN, disabling.\n");
+	}
+
+	gpiod_put(ckin_gpio);
+
+exit_ckin:
+	gpiod_put(ck_gpio);
+exit_ck:
+	gpiod_put(cmd_gpio);
+exit_cmd:
+	pinctrl_select_default_state(dev);
+}
+
 static int mmci_of_parse(struct device_node *np, struct mmc_host *mmc)
 {
 	struct mmci_host *host = mmc_priv(mmc);
@@ -1913,7 +1973,7 @@ static int mmci_of_parse(struct device_node *np, struct mmc_host *mmc)
 	if (of_get_property(np, "st,neg-edge", NULL))
 		host->clk_reg_add |= MCI_STM32_CLK_NEGEDGE;
 	if (of_get_property(np, "st,use-ckin", NULL))
-		host->clk_reg_add |= MCI_STM32_CLK_SELCKIN;
+		mmci_probe_level_translator(mmc);
 
 	if (of_get_property(np, "mmc-cap-mmc-highspeed", NULL))
 		mmc->caps |= MMC_CAP_MMC_HIGHSPEED;
@@ -1949,15 +2009,15 @@ static int mmci_probe(struct amba_device *dev,
 	if (!mmc)
 		return -ENOMEM;
 
-	ret = mmci_of_parse(np, mmc);
-	if (ret)
-		goto host_free;
-
 	host = mmc_priv(mmc);
 	host->mmc = mmc;
 	host->mmc_ops = &mmci_ops;
 	mmc->ops = &mmci_ops;
 
+	ret = mmci_of_parse(np, mmc);
+	if (ret)
+		goto host_free;
+
 	/*
 	 * Some variant (STM32) doesn't have opendrain bit, nevertheless
 	 * pins can be set accordingly using pinctrl
-- 
2.29.2


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

* [PATCH V2 3/4] ARM: dts: stm32: Add additional init state for SDMMC1 pins
  2021-01-24 17:02 [PATCH V2 1/4] mmc: mmci: Add bindings to operate CMD, CK, CKIN pins as GPIO Marek Vasut
  2021-01-24 17:02 ` [PATCH V2 2/4] mmc: mmci: Add support for probing bus voltage level translator Marek Vasut
@ 2021-01-24 17:02 ` Marek Vasut
  2021-01-24 17:02 ` [PATCH V2 4/4] ARM: dts: stm32: Enable voltage translator auto-detection on DHCOM Marek Vasut
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 8+ messages in thread
From: Marek Vasut @ 2021-01-24 17:02 UTC (permalink / raw)
  To: linux-mmc
  Cc: Marek Vasut, Alexandre Torgue, Linus Walleij, Ludovic Barre,
	Ulf Hansson, linux-stm32

Add "init" mux option for SDMMC1, where the CMD, CK, CKIN lines are not
configured, so they can be claimed as GPIOs early on in driver probe().
This is used for probing optional voltage level translator.

Signed-off-by: Marek Vasut <marex@denx.de>
Cc: Alexandre Torgue <alexandre.torgue@st.com>
Cc: Linus Walleij <linus.walleij@linaro.org>
Cc: Ludovic Barre <ludovic.barre@st.com>
Cc: Ulf Hansson <ulf.hansson@linaro.org>
Cc: linux-stm32@st-md-mailman.stormreply.com
---
V2: Rebase on next-20210122
---
 arch/arm/boot/dts/stm32mp15-pinctrl.dtsi | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)

diff --git a/arch/arm/boot/dts/stm32mp15-pinctrl.dtsi b/arch/arm/boot/dts/stm32mp15-pinctrl.dtsi
index d8297dfff3e6..687f3534ba22 100644
--- a/arch/arm/boot/dts/stm32mp15-pinctrl.dtsi
+++ b/arch/arm/boot/dts/stm32mp15-pinctrl.dtsi
@@ -1385,6 +1385,18 @@ pins {
 		};
 	};
 
+	sdmmc1_b4_init_pins_a: sdmmc1-b4-init-0 {
+		pins1 {
+			pinmux = <STM32_PINMUX('C', 8, AF12)>, /* SDMMC1_D0 */
+				 <STM32_PINMUX('C', 9, AF12)>, /* SDMMC1_D1 */
+				 <STM32_PINMUX('C', 10, AF12)>, /* SDMMC1_D2 */
+				 <STM32_PINMUX('C', 11, AF12)>; /* SDMMC1_D3 */
+			slew-rate = <1>;
+			drive-push-pull;
+			bias-disable;
+		};
+	};
+
 	sdmmc1_dir_pins_a: sdmmc1-dir-0 {
 		pins1 {
 			pinmux = <STM32_PINMUX('F', 2, AF11)>, /* SDMMC1_D0DIR */
@@ -1409,6 +1421,17 @@ pins {
 		};
 	};
 
+	sdmmc1_dir_init_pins_a: sdmmc1-dir-init-0 {
+		pins1 {
+			pinmux = <STM32_PINMUX('F', 2, AF11)>, /* SDMMC1_D0DIR */
+				 <STM32_PINMUX('C', 7, AF8)>, /* SDMMC1_D123DIR */
+				 <STM32_PINMUX('B', 9, AF11)>; /* SDMMC1_CDIR */
+			slew-rate = <1>;
+			drive-push-pull;
+			bias-pull-up;
+		};
+	};
+
 	sdmmc1_dir_pins_b: sdmmc1-dir-1 {
 		pins1 {
 			pinmux = <STM32_PINMUX('F', 2, AF11)>, /* SDMMC1_D0DIR */
-- 
2.29.2


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

* [PATCH V2 4/4] ARM: dts: stm32: Enable voltage translator auto-detection on DHCOM
  2021-01-24 17:02 [PATCH V2 1/4] mmc: mmci: Add bindings to operate CMD, CK, CKIN pins as GPIO Marek Vasut
  2021-01-24 17:02 ` [PATCH V2 2/4] mmc: mmci: Add support for probing bus voltage level translator Marek Vasut
  2021-01-24 17:02 ` [PATCH V2 3/4] ARM: dts: stm32: Add additional init state for SDMMC1 pins Marek Vasut
@ 2021-01-24 17:02 ` Marek Vasut
  2021-01-25 14:19   ` Alexandre TORGUE
  2021-01-24 22:51 ` [PATCH V2 1/4] mmc: mmci: Add bindings to operate CMD, CK, CKIN pins as GPIO Linus Walleij
  2021-01-26  9:58 ` Ulf Hansson
  4 siblings, 1 reply; 8+ messages in thread
From: Marek Vasut @ 2021-01-24 17:02 UTC (permalink / raw)
  To: linux-mmc
  Cc: Marek Vasut, Alexandre Torgue, Linus Walleij, Ludovic Barre,
	Ulf Hansson, linux-stm32

The DHCOM SoM uSD slot has an optional voltage level translator, add
DT bindings which permit the MMCI driver to detect the translator
automatically.

Signed-off-by: Marek Vasut <marex@denx.de>
Cc: Alexandre Torgue <alexandre.torgue@st.com>
Cc: Linus Walleij <linus.walleij@linaro.org>
Cc: Ludovic Barre <ludovic.barre@st.com>
Cc: Ulf Hansson <ulf.hansson@linaro.org>
Cc: linux-stm32@st-md-mailman.stormreply.com
---
V2: Rebase on next-20210122
---
 arch/arm/boot/dts/stm32mp15xx-dhcom-som.dtsi | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/arch/arm/boot/dts/stm32mp15xx-dhcom-som.dtsi b/arch/arm/boot/dts/stm32mp15xx-dhcom-som.dtsi
index ff70bd03a017..661d8d071296 100644
--- a/arch/arm/boot/dts/stm32mp15xx-dhcom-som.dtsi
+++ b/arch/arm/boot/dts/stm32mp15xx-dhcom-som.dtsi
@@ -408,14 +408,19 @@ &rtc {
 };
 
 &sdmmc1 {
-	pinctrl-names = "default", "opendrain", "sleep";
+	pinctrl-names = "default", "opendrain", "sleep", "init";
 	pinctrl-0 = <&sdmmc1_b4_pins_a &sdmmc1_dir_pins_a>;
 	pinctrl-1 = <&sdmmc1_b4_od_pins_a &sdmmc1_dir_pins_a>;
 	pinctrl-2 = <&sdmmc1_b4_sleep_pins_a &sdmmc1_dir_sleep_pins_a>;
+	pinctrl-3 = <&sdmmc1_b4_init_pins_a &sdmmc1_dir_init_pins_a>;
 	cd-gpios = <&gpiog 1 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)>;
 	disable-wp;
 	st,sig-dir;
 	st,neg-edge;
+	st,use-ckin;
+	st,cmd-gpios = <&gpiod 2 0>;
+	st,ck-gpios = <&gpioc 12 0>;
+	st,ckin-gpios = <&gpioe 4 0>;
 	bus-width = <4>;
 	vmmc-supply = <&vdd_sd>;
 	status = "okay";
-- 
2.29.2


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

* Re: [PATCH V2 1/4] mmc: mmci: Add bindings to operate CMD, CK, CKIN pins as GPIO
  2021-01-24 17:02 [PATCH V2 1/4] mmc: mmci: Add bindings to operate CMD, CK, CKIN pins as GPIO Marek Vasut
                   ` (2 preceding siblings ...)
  2021-01-24 17:02 ` [PATCH V2 4/4] ARM: dts: stm32: Enable voltage translator auto-detection on DHCOM Marek Vasut
@ 2021-01-24 22:51 ` Linus Walleij
  2021-01-26  9:58 ` Ulf Hansson
  4 siblings, 0 replies; 8+ messages in thread
From: Linus Walleij @ 2021-01-24 22:51 UTC (permalink / raw)
  To: Marek Vasut
  Cc: linux-mmc, Alexandre Torgue, Ludovic Barre, Rob Herring,
	Ulf Hansson, linux-stm32,
	open list:OPEN FIRMWARE AND FLATTENED DEVICE TREE BINDINGS

On Sun, Jan 24, 2021 at 6:03 PM Marek Vasut <marex@denx.de> wrote:

> Add DT bindings to describe GPIO line associated with CMD, CK, CKIN pins.
>
> Signed-off-by: Marek Vasut <marex@denx.de>
> Cc: Alexandre Torgue <alexandre.torgue@st.com>
> Cc: Linus Walleij <linus.walleij@linaro.org>
> Cc: Ludovic Barre <ludovic.barre@st.com>
> Cc: Rob Herring <robh+dt@kernel.org>
> Cc: Ulf Hansson <ulf.hansson@linaro.org>
> Cc: linux-stm32@st-md-mailman.stormreply.com
> Cc: devicetree@vger.kernel.org
> ---
> V2: Rebase on next-20210122

Reviewed-by: Linus Walleij <linus.walleij@linaro.org>

I would probably add an example as well, but that can be
done separately and isn't super-important.

Yours,
Linus Walleij

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

* Re: [PATCH V2 4/4] ARM: dts: stm32: Enable voltage translator auto-detection on DHCOM
  2021-01-24 17:02 ` [PATCH V2 4/4] ARM: dts: stm32: Enable voltage translator auto-detection on DHCOM Marek Vasut
@ 2021-01-25 14:19   ` Alexandre TORGUE
  0 siblings, 0 replies; 8+ messages in thread
From: Alexandre TORGUE @ 2021-01-25 14:19 UTC (permalink / raw)
  To: Marek Vasut, linux-mmc
  Cc: Alexandre Torgue, Linus Walleij, Ludovic Barre, Ulf Hansson, linux-stm32

Hi Marek

On 1/24/21 6:02 PM, Marek Vasut wrote:
> The DHCOM SoM uSD slot has an optional voltage level translator, add
> DT bindings which permit the MMCI driver to detect the translator
> automatically.
> 
> Signed-off-by: Marek Vasut <marex@denx.de>
> Cc: Alexandre Torgue <alexandre.torgue@st.com>
> Cc: Linus Walleij <linus.walleij@linaro.org>
> Cc: Ludovic Barre <ludovic.barre@st.com>
> Cc: Ulf Hansson <ulf.hansson@linaro.org>
> Cc: linux-stm32@st-md-mailman.stormreply.com
> ---
> V2: Rebase on next-20210122
> ---
>   arch/arm/boot/dts/stm32mp15xx-dhcom-som.dtsi | 7 ++++++-
>   1 file changed, 6 insertions(+), 1 deletion(-)
> 
> diff --git a/arch/arm/boot/dts/stm32mp15xx-dhcom-som.dtsi b/arch/arm/boot/dts/stm32mp15xx-dhcom-som.dtsi
> index ff70bd03a017..661d8d071296 100644
> --- a/arch/arm/boot/dts/stm32mp15xx-dhcom-som.dtsi
> +++ b/arch/arm/boot/dts/stm32mp15xx-dhcom-som.dtsi
> @@ -408,14 +408,19 @@ &rtc {
>   };
>   
>   &sdmmc1 {
> -	pinctrl-names = "default", "opendrain", "sleep";
> +	pinctrl-names = "default", "opendrain", "sleep", "init";
>   	pinctrl-0 = <&sdmmc1_b4_pins_a &sdmmc1_dir_pins_a>;
>   	pinctrl-1 = <&sdmmc1_b4_od_pins_a &sdmmc1_dir_pins_a>;
>   	pinctrl-2 = <&sdmmc1_b4_sleep_pins_a &sdmmc1_dir_sleep_pins_a>;
> +	pinctrl-3 = <&sdmmc1_b4_init_pins_a &sdmmc1_dir_init_pins_a>;
>   	cd-gpios = <&gpiog 1 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)>;
>   	disable-wp;
>   	st,sig-dir;
>   	st,neg-edge;
> +	st,use-ckin;
> +	st,cmd-gpios = <&gpiod 2 0>;
> +	st,ck-gpios = <&gpioc 12 0>;
> +	st,ckin-gpios = <&gpioe 4 0>;
>   	bus-width = <4>;
>   	vmmc-supply = <&vdd_sd>;
>   	status = "okay";
> 

DT patches applied on stm32-next.

Thanks
Alex

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

* Re: [PATCH V2 1/4] mmc: mmci: Add bindings to operate CMD, CK, CKIN pins as GPIO
  2021-01-24 17:02 [PATCH V2 1/4] mmc: mmci: Add bindings to operate CMD, CK, CKIN pins as GPIO Marek Vasut
                   ` (3 preceding siblings ...)
  2021-01-24 22:51 ` [PATCH V2 1/4] mmc: mmci: Add bindings to operate CMD, CK, CKIN pins as GPIO Linus Walleij
@ 2021-01-26  9:58 ` Ulf Hansson
  4 siblings, 0 replies; 8+ messages in thread
From: Ulf Hansson @ 2021-01-26  9:58 UTC (permalink / raw)
  To: Marek Vašut
  Cc: linux-mmc, Alexandre Torgue, Linus Walleij, Ludovic Barre,
	Rob Herring, linux-stm32, DTML

On Sun, 24 Jan 2021 at 18:03, Marek Vasut <marex@denx.de> wrote:
>
> Add DT bindings to describe GPIO line associated with CMD, CK, CKIN pins.
>
> Signed-off-by: Marek Vasut <marex@denx.de>
> Cc: Alexandre Torgue <alexandre.torgue@st.com>
> Cc: Linus Walleij <linus.walleij@linaro.org>
> Cc: Ludovic Barre <ludovic.barre@st.com>
> Cc: Rob Herring <robh+dt@kernel.org>
> Cc: Ulf Hansson <ulf.hansson@linaro.org>
> Cc: linux-stm32@st-md-mailman.stormreply.com
> Cc: devicetree@vger.kernel.org

Applied for next, thanks!

Kind regards
Uffe


> ---
> V2: Rebase on next-20210122
> ---
>  .../devicetree/bindings/mmc/arm,pl18x.yaml    | 20 +++++++++++++++++++
>  1 file changed, 20 insertions(+)
>
> diff --git a/Documentation/devicetree/bindings/mmc/arm,pl18x.yaml b/Documentation/devicetree/bindings/mmc/arm,pl18x.yaml
> index eddc1f6bdbe5..47595cb483be 100644
> --- a/Documentation/devicetree/bindings/mmc/arm,pl18x.yaml
> +++ b/Documentation/devicetree/bindings/mmc/arm,pl18x.yaml
> @@ -127,6 +127,26 @@ properties:
>        driver to sample the receive data (for example with a voltage switch
>        transceiver).
>
> +  st,cmd-gpios:
> +    maxItems: 1
> +    description:
> +      The GPIO matching the CMD pin.
> +
> +  st,ck-gpios:
> +    maxItems: 1
> +    description:
> +      The GPIO matching the CK pin.
> +
> +  st,ckin-gpios:
> +    maxItems: 1
> +    description:
> +      The GPIO matching the CKIN pin.
> +
> +dependencies:
> +  st,cmd-gpios: [ "st,use-ckin" ]
> +  st,ck-gpios: [ "st,use-ckin" ]
> +  st,ckin-gpios: [ "st,use-ckin" ]
> +
>  unevaluatedProperties: false
>
>  required:
> --
> 2.29.2
>

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

* Re: [PATCH V2 2/4] mmc: mmci: Add support for probing bus voltage level translator
  2021-01-24 17:02 ` [PATCH V2 2/4] mmc: mmci: Add support for probing bus voltage level translator Marek Vasut
@ 2021-01-26  9:58   ` Ulf Hansson
  0 siblings, 0 replies; 8+ messages in thread
From: Ulf Hansson @ 2021-01-26  9:58 UTC (permalink / raw)
  To: Marek Vašut
  Cc: linux-mmc, Yann Gautier, Linus Walleij, Alexandre Torgue,
	Ludovic Barre, linux-stm32

On Sun, 24 Jan 2021 at 18:03, Marek Vasut <marex@denx.de> wrote:
>
> Add support for testing whether bus voltage level translator is present
> and operational. This is useful on systems where the bus voltage level
> translator is optional, as the translator can be auto-detected by the
> driver and the feedback clock functionality can be disabled if it is
> not present.
>
> This requires additional pinmux state, "init", where the CMD, CK, CKIN
> lines are not configured, so they can be claimed as GPIOs early on in
> probe(). The translator test sets CMD high to avoid interfering with a
> card, and then verifies whether signal set on CK is detected on CKIN.
> If the signal is detected, translator is present, otherwise the CKIN
> feedback clock are disabled.
>
> Tested-by: Yann Gautier <yann.gautier@foss.st.com>
> Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
> Signed-off-by: Marek Vasut <marex@denx.de>
> Cc: Alexandre Torgue <alexandre.torgue@st.com>
> Cc: Linus Walleij <linus.walleij@linaro.org>
> Cc: Ludovic Barre <ludovic.barre@st.com>
> Cc: Ulf Hansson <ulf.hansson@linaro.org>
> Cc: linux-stm32@st-md-mailman.stormreply.com

Applied for next, thanks!

Kind regards
Uffe


> ---
> V2: Rebase on next-20210122, add TB and RB
> ---
>  drivers/mmc/host/mmci.c | 70 ++++++++++++++++++++++++++++++++++++++---
>  1 file changed, 65 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/mmc/host/mmci.c b/drivers/mmc/host/mmci.c
> index b5a41a7ce165..1bc674577ff9 100644
> --- a/drivers/mmc/host/mmci.c
> +++ b/drivers/mmc/host/mmci.c
> @@ -36,6 +36,7 @@
>  #include <linux/types.h>
>  #include <linux/pinctrl/consumer.h>
>  #include <linux/reset.h>
> +#include <linux/gpio/consumer.h>
>
>  #include <asm/div64.h>
>  #include <asm/io.h>
> @@ -1888,6 +1889,65 @@ static struct mmc_host_ops mmci_ops = {
>         .start_signal_voltage_switch = mmci_sig_volt_switch,
>  };
>
> +static void mmci_probe_level_translator(struct mmc_host *mmc)
> +{
> +       struct device *dev = mmc_dev(mmc);
> +       struct mmci_host *host = mmc_priv(mmc);
> +       struct gpio_desc *cmd_gpio;
> +       struct gpio_desc *ck_gpio;
> +       struct gpio_desc *ckin_gpio;
> +       int clk_hi, clk_lo;
> +
> +       /*
> +        * Assume the level translator is present if st,use-ckin is set.
> +        * This is to cater for DTs which do not implement this test.
> +        */
> +       host->clk_reg_add |= MCI_STM32_CLK_SELCKIN;
> +
> +       cmd_gpio = gpiod_get(dev, "st,cmd", GPIOD_OUT_HIGH);
> +       if (IS_ERR(cmd_gpio))
> +               goto exit_cmd;
> +
> +       ck_gpio = gpiod_get(dev, "st,ck", GPIOD_OUT_HIGH);
> +       if (IS_ERR(ck_gpio))
> +               goto exit_ck;
> +
> +       ckin_gpio = gpiod_get(dev, "st,ckin", GPIOD_IN);
> +       if (IS_ERR(ckin_gpio))
> +               goto exit_ckin;
> +
> +       /* All GPIOs are valid, test whether level translator works */
> +
> +       /* Sample CKIN */
> +       clk_hi = !!gpiod_get_value(ckin_gpio);
> +
> +       /* Set CK low */
> +       gpiod_set_value(ck_gpio, 0);
> +
> +       /* Sample CKIN */
> +       clk_lo = !!gpiod_get_value(ckin_gpio);
> +
> +       /* Tristate all */
> +       gpiod_direction_input(cmd_gpio);
> +       gpiod_direction_input(ck_gpio);
> +
> +       /* Level translator is present if CK signal is propagated to CKIN */
> +       if (!clk_hi || clk_lo) {
> +               host->clk_reg_add &= ~MCI_STM32_CLK_SELCKIN;
> +               dev_warn(dev,
> +                        "Level translator inoperable, CK signal not detected on CKIN, disabling.\n");
> +       }
> +
> +       gpiod_put(ckin_gpio);
> +
> +exit_ckin:
> +       gpiod_put(ck_gpio);
> +exit_ck:
> +       gpiod_put(cmd_gpio);
> +exit_cmd:
> +       pinctrl_select_default_state(dev);
> +}
> +
>  static int mmci_of_parse(struct device_node *np, struct mmc_host *mmc)
>  {
>         struct mmci_host *host = mmc_priv(mmc);
> @@ -1913,7 +1973,7 @@ static int mmci_of_parse(struct device_node *np, struct mmc_host *mmc)
>         if (of_get_property(np, "st,neg-edge", NULL))
>                 host->clk_reg_add |= MCI_STM32_CLK_NEGEDGE;
>         if (of_get_property(np, "st,use-ckin", NULL))
> -               host->clk_reg_add |= MCI_STM32_CLK_SELCKIN;
> +               mmci_probe_level_translator(mmc);
>
>         if (of_get_property(np, "mmc-cap-mmc-highspeed", NULL))
>                 mmc->caps |= MMC_CAP_MMC_HIGHSPEED;
> @@ -1949,15 +2009,15 @@ static int mmci_probe(struct amba_device *dev,
>         if (!mmc)
>                 return -ENOMEM;
>
> -       ret = mmci_of_parse(np, mmc);
> -       if (ret)
> -               goto host_free;
> -
>         host = mmc_priv(mmc);
>         host->mmc = mmc;
>         host->mmc_ops = &mmci_ops;
>         mmc->ops = &mmci_ops;
>
> +       ret = mmci_of_parse(np, mmc);
> +       if (ret)
> +               goto host_free;
> +
>         /*
>          * Some variant (STM32) doesn't have opendrain bit, nevertheless
>          * pins can be set accordingly using pinctrl
> --
> 2.29.2
>

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

end of thread, other threads:[~2021-01-26 19:13 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-01-24 17:02 [PATCH V2 1/4] mmc: mmci: Add bindings to operate CMD, CK, CKIN pins as GPIO Marek Vasut
2021-01-24 17:02 ` [PATCH V2 2/4] mmc: mmci: Add support for probing bus voltage level translator Marek Vasut
2021-01-26  9:58   ` Ulf Hansson
2021-01-24 17:02 ` [PATCH V2 3/4] ARM: dts: stm32: Add additional init state for SDMMC1 pins Marek Vasut
2021-01-24 17:02 ` [PATCH V2 4/4] ARM: dts: stm32: Enable voltage translator auto-detection on DHCOM Marek Vasut
2021-01-25 14:19   ` Alexandre TORGUE
2021-01-24 22:51 ` [PATCH V2 1/4] mmc: mmci: Add bindings to operate CMD, CK, CKIN pins as GPIO Linus Walleij
2021-01-26  9:58 ` 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.