Skip to contentSkip to conversation

mmc: stm32_sdmmc2: Add support for probing bus voltage level translator

PATCH In review Marek Vasut 3 participants 5 messages Nov 13, 2021 – Nov 30, 2021

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 1/2 mmc: stm32_sdmmc2: Add support for probing bus voltage level translator

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.

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.

Cc Patrice Chotard <[email protected]>
Cc Patrick Delaunay <[email protected]>
---
 drivers/mmc/stm32_sdmmc2.c | 63 +++++++++++++++++++++++++++++++++++++-
 1 file changed, 62 insertions(+), 1 deletion(-)
drivers/mmc/stm32_sdmmc2.c +62 -1
index a3cdf7bcd9f..44bfc911af2 100644
@@ -16,6 +16,7 @@
 #include <asm/bitops.h>
 #include <asm/cache.h>
 #include <dm/device_compat.h>
+#include <dm/pinctrl.h>
 #include <linux/bitops.h>
 #include <linux/delay.h>
 #include <linux/libfdt.h>
@@ -645,6 +646,66 @@ static const struct dm_mmc_ops stm32_sdmmc2_ops = {
 	.host_power_cycle = stm32_sdmmc2_host_power_cycle,
 };
 
+static int stm32_sdmmc2_probe_level_translator(struct udevice *dev)
+{
+	struct stm32_sdmmc2_priv *priv = dev_get_priv(dev);
+	struct gpio_desc cmd_gpio;
+	struct gpio_desc ck_gpio;
+	struct gpio_desc ckin_gpio;
+	int clk_hi, clk_lo, ret;
+
+	/*
+	 * Assume the level translator is present if st,use-ckin is set.
+	 * This is to cater for DTs which do not implement this test.
+	 */
+	priv->clk_reg_msk |= SDMMC_CLKCR_SELCLKRX_CKIN;
+
+	ret = gpio_request_by_name(dev, "st,cmd-gpios", 0, &cmd_gpio,
+				   GPIOD_IS_OUT | GPIOD_IS_OUT_ACTIVE);
+	if (ret)
+		goto exit_cmd;
+
+	ret = gpio_request_by_name(dev, "st,ck-gpios", 0, &ck_gpio,
+				   GPIOD_IS_OUT | GPIOD_IS_OUT_ACTIVE);
+	if (ret)
+		goto exit_ck;
+
+	ret = gpio_request_by_name(dev, "st,ckin-gpios", 0, &ckin_gpio,
+				   GPIOD_IS_IN);
+	if (ret)
+		goto exit_ckin;
+
+	/* All GPIOs are valid, test whether level translator works */
+
+	/* Sample CKIN */
+	clk_hi = !!dm_gpio_get_value(&ckin_gpio);
+
+	/* Set CK low */
+	dm_gpio_set_value(&ck_gpio, 0);
+
+	/* Sample CKIN */
+	clk_lo = !!dm_gpio_get_value(&ckin_gpio);
+
+	/* Tristate all */
+	dm_gpio_set_dir_flags(&cmd_gpio, GPIOD_IS_IN);
+	dm_gpio_set_dir_flags(&ck_gpio, GPIOD_IS_IN);
+
+	/* Level translator is present if CK signal is propagated to CKIN */
+	if (!clk_hi || clk_lo)
+		priv->clk_reg_msk &= ~SDMMC_CLKCR_SELCLKRX_CKIN;
+
+	dm_gpio_free(dev, &ckin_gpio);
+
+exit_ckin:
+	dm_gpio_free(dev, &ck_gpio);
+exit_ck:
+	dm_gpio_free(dev, &cmd_gpio);
+exit_cmd:
+	pinctrl_select_state(dev, "default");
+
+	return 0;
+}
+
 static int stm32_sdmmc2_probe(struct udevice *dev)
 {
 	struct mmc_uclass_priv *upriv = dev_get_uclass_priv(dev);
@@ -662,7 +723,7 @@ static int stm32_sdmmc2_probe(struct udevice *dev)
 	if (dev_read_bool(dev, "st,sig-dir"))
 		priv->pwr_reg_msk |= SDMMC_POWER_DIRPOL;
 	if (dev_read_bool(dev, "st,use-ckin"))
-		priv->clk_reg_msk |= SDMMC_CLKCR_SELCLKRX_CKIN;
+		stm32_sdmmc2_probe_level_translator(dev);
 
 	ret = clk_get_by_index(dev, 0, &priv->clk);
 	if (ret)
Signature · 1 line
2.33.0
#1 lore raw

PATCH 2/2 ARM: dts: stm32: Auto-detect DHSOM with uSD level translator

The uSD level translator on DHSOM and Avenger96 are optional, however it is possible to auto-detect it. This is done by setting SD CMD line high, and then testing whether signal level on CK line matches the signal level on CKIN line. If so, the uSD level translator is present, otherwise it is not populated.

Cc Patrice Chotard <[email protected]>
Cc Patrick Delaunay <[email protected]>
---
 arch/arm/dts/stm32mp15xx-dhcom-u-boot.dtsi           | 4 ++++
 arch/arm/dts/stm32mp15xx-dhcor-avenger96-u-boot.dtsi | 4 ++++
 2 files changed, 8 insertions(+)
arch/arm/dts/stm32mp15xx-dhcom-u-boot.dtsi +4 -0
index 71b0486f02a..5b2b09bcfb9 100644
@@ -216,6 +216,10 @@
 
 &sdmmc1 {
 	u-boot,dm-spl;
+	st,use-ckin;
+	st,cmd-gpios = <&gpiod 2 0>;
+	st,ck-gpios = <&gpioc 12 0>;
+	st,ckin-gpios = <&gpioe 4 0>;
 };
 
 &sdmmc1_b4_pins_a {
arch/arm/dts/stm32mp15xx-dhcor-avenger96-u-boot.dtsi +4 -0
index 4b1dbf08387..c96eba99c5e 100644
@@ -32,6 +32,10 @@
 
 &sdmmc1 {
 	u-boot,dm-spl;
+	st,use-ckin;
+	st,cmd-gpios = <&gpiod 2 0>;
+	st,ck-gpios = <&gpioc 12 0>;
+	st,ckin-gpios = <&gpioe 4 0>;
 };
 
 &sdmmc1_b4_pins_a {
Signature · 1 line
2.33.0
Reviewed-by on v1 2/2
#2 lore raw

Re: [PATCH 2/2] ARM: dts: stm32: Auto-detect DHSOM with uSD level translator

Hi Marek

Quoted 35 lines · Marek Vasut

The uSD level translator on DHSOM and Avenger96 are optional, however it is possible to auto-detect it. This is done by setting SD CMD line high, and then testing whether signal level on CK line matches the signal level on CKIN line. If so, the uSD level translator is present, otherwise it is not populated.

Cc Patrice Chotard <[email protected]>
Cc Patrick Delaunay <[email protected]>
---
 arch/arm/dts/stm32mp15xx-dhcom-u-boot.dtsi           | 4 ++++
 arch/arm/dts/stm32mp15xx-dhcor-avenger96-u-boot.dtsi | 4 ++++
 2 files changed, 8 insertions(+)
arch/arm/dts/stm32mp15xx-dhcom-u-boot.dtsi +4 -0
index 71b0486f02a..5b2b09bcfb9 100644
@@ -216,6 +216,10 @@
 
 &sdmmc1 {
 	u-boot,dm-spl;
+	st,use-ckin;
+	st,cmd-gpios = <&gpiod 2 0>;
+	st,ck-gpios = <&gpioc 12 0>;
+	st,ckin-gpios = <&gpioe 4 0>;
 };
 
 &sdmmc1_b4_pins_a {
arch/arm/dts/stm32mp15xx-dhcor-avenger96-u-boot.dtsi +0 -0
index 4b1dbf08387..c96eba99c5e 100644

arch/arm/dts/stm32mp15xx-dhcor-avenger96-u-boot.dtsi line 41

Quoted 10 lines
arch/arm/dts/stm32mp15xx-dhcor-avenger96-u-boot.dtsi +4 -0
@@ -32,6 +32,10 @@
 
 &sdmmc1 {
 	u-boot,dm-spl;
+	st,use-ckin;
+	st,cmd-gpios = <&gpiod 2 0>;
+	st,ck-gpios = <&gpioc 12 0>;
+	st,ckin-gpios = <&gpioe 4 0>;
 };
 
 &sdmmc1_b4_pins_a {

Thanks
Patrice

Reviewed-by on v1 1/2
#3 lore raw
In reply to Marek Vasut
Quoted 6 lines · Marek Vasut

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.

Quoted 8 lines

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.

Cc Patrice Chotard<[email protected]>
Cc Patrick Delaunay<[email protected]>

Hi Marek,

Best regards,
Yann

#4 lore raw
In reply to Marek Vasut

Hi Marek

Quoted 99 lines · Marek Vasut

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.

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.

Cc Patrice Chotard <[email protected]>
Cc Patrick Delaunay <[email protected]>
---
 drivers/mmc/stm32_sdmmc2.c | 63 +++++++++++++++++++++++++++++++++++++-
 1 file changed, 62 insertions(+), 1 deletion(-)
drivers/mmc/stm32_sdmmc2.c +61 -0
index a3cdf7bcd9f..44bfc911af2 100644
@@ -16,6 +16,7 @@
 #include <asm/bitops.h>
 #include <asm/cache.h>
 #include <dm/device_compat.h>
+#include <dm/pinctrl.h>
 #include <linux/bitops.h>
 #include <linux/delay.h>
 #include <linux/libfdt.h>
@@ -645,6 +646,66 @@ static const struct dm_mmc_ops stm32_sdmmc2_ops = {
 	.host_power_cycle = stm32_sdmmc2_host_power_cycle,
 };
 
+static int stm32_sdmmc2_probe_level_translator(struct udevice *dev)
+{
+	struct stm32_sdmmc2_priv *priv = dev_get_priv(dev);
+	struct gpio_desc cmd_gpio;
+	struct gpio_desc ck_gpio;
+	struct gpio_desc ckin_gpio;
+	int clk_hi, clk_lo, ret;
+
+	/*
+	 * Assume the level translator is present if st,use-ckin is set.
+	 * This is to cater for DTs which do not implement this test.
+	 */
+	priv->clk_reg_msk |= SDMMC_CLKCR_SELCLKRX_CKIN;
+
+	ret = gpio_request_by_name(dev, "st,cmd-gpios", 0, &cmd_gpio,
+				   GPIOD_IS_OUT | GPIOD_IS_OUT_ACTIVE);
+	if (ret)
+		goto exit_cmd;
+
+	ret = gpio_request_by_name(dev, "st,ck-gpios", 0, &ck_gpio,
+				   GPIOD_IS_OUT | GPIOD_IS_OUT_ACTIVE);
+	if (ret)
+		goto exit_ck;
+
+	ret = gpio_request_by_name(dev, "st,ckin-gpios", 0, &ckin_gpio,
+				   GPIOD_IS_IN);
+	if (ret)
+		goto exit_ckin;
+
+	/* All GPIOs are valid, test whether level translator works */
+
+	/* Sample CKIN */
+	clk_hi = !!dm_gpio_get_value(&ckin_gpio);
+
+	/* Set CK low */
+	dm_gpio_set_value(&ck_gpio, 0);
+
+	/* Sample CKIN */
+	clk_lo = !!dm_gpio_get_value(&ckin_gpio);
+
+	/* Tristate all */
+	dm_gpio_set_dir_flags(&cmd_gpio, GPIOD_IS_IN);
+	dm_gpio_set_dir_flags(&ck_gpio, GPIOD_IS_IN);
+
+	/* Level translator is present if CK signal is propagated to CKIN */
+	if (!clk_hi || clk_lo)
+		priv->clk_reg_msk &= ~SDMMC_CLKCR_SELCLKRX_CKIN;
+
+	dm_gpio_free(dev, &ckin_gpio);
+
+exit_ckin:
+	dm_gpio_free(dev, &ck_gpio);
+exit_ck:
+	dm_gpio_free(dev, &cmd_gpio);
+exit_cmd:
+	pinctrl_select_state(dev, "default");
+
+	return 0;
+}
+
 static int stm32_sdmmc2_probe(struct udevice *dev)
 {
 	struct mmc_uclass_priv *upriv = dev_get_uclass_priv(dev);

drivers/mmc/stm32_sdmmc2.c static int stm32_sdmmc2_probe(struct udevice *dev) · line 729

Quoted 8 lines
drivers/mmc/stm32_sdmmc2.c +1 -1
@@ -662,7 +723,7 @@ static int stm32_sdmmc2_probe(struct udevice *dev)
 	if (dev_read_bool(dev, "st,sig-dir"))
 		priv->pwr_reg_msk |= SDMMC_POWER_DIRPOL;
 	if (dev_read_bool(dev, "st,use-ckin"))
-		priv->clk_reg_msk |= SDMMC_CLKCR_SELCLKRX_CKIN;
+		stm32_sdmmc2_probe_level_translator(dev);
 
 	ret = clk_get_by_index(dev, 0, &priv->clk);
 	if (ret)

For the series, applied to u-boot-stm32/next

Thanks
Patrice