Skip to contentSkip to conversation

x86: tangier: Enable support for SD/SDIO family in the pinmux driver

PATCH Superseded Andy Shevchenko 4 participants 12 messages Oct 15, 2021 – Oct 27, 2021 x86

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#1 lore raw

PATCH 2/2 x86: edison: Don't take SD card detect pin into consideration

In reply to Andy Shevchenko

There are two PCB designs in the wild which use the opposite signaling for SD card detect. This makes U-Boot working in one case and failing in the other. Quirk this out by disconnecting SD card detect pin from the PCB by switching to mode 3.

---
 arch/x86/dts/edison.dts | 12 ++++++++++++
 1 file changed, 12 insertions(+)
arch/x86/dts/edison.dts +12 -0
index 2c8cf6c07102..04e8a4e457c8 100644
@@ -94,6 +94,7 @@
 	sdcard: mmc@ff3fa000 {
 		compatible = "intel,sdhci-tangier";
 		reg = <0xff3fa000 0x1000>;
+		cd-inverted;
 	};
 
 	pmu: power@ff00b000 {
@@ -131,6 +132,17 @@
 		compatible = "intel,pinctrl-tangier";
 		reg = <0xff0c0000 0x8000>;
 
+		/*
+		 * Disconnect SD card detect, so it won't affect the reality
+		 * on two different PCB designs where it's using the opposite
+		 * signaling: Edison/Arduino uses Active Low, while SparkFun
+		 * went with Active High.
+		 */
+		sd_cd@0 {
+			pad-offset = <37>;
+			mode-func = <3>;
+		};
+
 		/*
 		 * Initial configuration came from the firmware.
 		 * Which quite likely has been used in the phones, where I2C #8,
Signature · 1 line
2.33.0
#0 lore raw

PATCH 1/2 x86: tangier: Enable support for SD/SDIO family in the pinmux driver

We would need to quirk out Card Detect case and for that we allow configuring SD/SDIO family of pins.

---
 arch/x86/cpu/tangier/pinmux.c | 39 ++++++++++++++++++++++++++++++-----
 1 file changed, 34 insertions(+), 5 deletions(-)
arch/x86/cpu/tangier/pinmux.c +34 -5
index acf97e3af51d..8385167b2b6b 100644
@@ -37,8 +37,9 @@ struct mrfld_family {
 		.npins = (e) - (s) + 1,			\
 	}
 
-/* Now we only support I2C family of pins */
+/* Now we only support SD/SDIO and I2C families of pins */
 static struct mrfld_family mrfld_families[] = {
+	MRFLD_FAMILY(3, 37, 56),
 	MRFLD_FAMILY(7, 101, 114),
 };
 
@@ -125,6 +126,34 @@ static int mrfld_pinconfig_protected(unsigned int pin, u32 mask, u32 bits)
 	return ret;
 }
 
+static int mrfld_pinconfig(unsigned int pin, u32 mask, u32 bits)
+{
+	struct mrfld_pinctrl *pinctrl;
+	struct udevice *dev;
+	void __iomem *bufcfg;
+	u32 v, value;
+	int ret;
+
+	ret = syscon_get_by_driver_data(X86_SYSCON_PINCONF, &dev);
+	if (ret)
+		return ret;
+
+	pinctrl = dev_get_priv(dev);
+
+	bufcfg = mrfld_get_bufcfg(pinctrl, pin);
+	if (!bufcfg)
+		return -EINVAL;
+
+	value = readl(bufcfg);
+	v = (value & ~mask) | (bits & mask);
+	writel(v, bufcfg);
+
+	debug("v: 0x%x p: 0x%x bits: %d, mask: %d bufcfg: 0x%p\n",
+	      v, (u32)bufcfg, bits, mask, bufcfg);
+
+	return 0;
+}
+
 static int mrfld_pinctrl_cfg_pin(ofnode pin_node)
 {
 	bool is_protected;
@@ -133,10 +162,7 @@ static int mrfld_pinctrl_cfg_pin(ofnode pin_node)
 	u32 mask;
 	int ret;
 
-	/* For now we only support just protected Family of pins */
 	is_protected = ofnode_read_bool(pin_node, "protected");
-	if (!is_protected)
-		return -ENOTSUPP;
 
 	pad_offset = ofnode_read_s32_default(pin_node, "pad-offset", -1);
 	if (pad_offset == -1)
@@ -152,7 +178,10 @@ static int mrfld_pinctrl_cfg_pin(ofnode pin_node)
 	if (mode & ~mask)
 		return -ENOTSUPP;
 
-	ret = mrfld_pinconfig_protected(pad_offset, mask, mode);
+	if (is_protected)
+		ret = mrfld_pinconfig_protected(pad_offset, mask, mode);
+	else
+		ret = mrfld_pinconfig(pad_offset, mask, mode);
 
 	return ret;
 }
Signature · 1 line
2.33.0
Tested-by on v1 2/2
#2 lore raw

Re: [PATCH v1 2/2] x86: edison: Don't take SD card detect pin into consideration

In reply to Andy Shevchenko

Hi,
Op 15-10-2021 om 19:11 schreef Andy Shevchenko:

Quoted 5 lines

There are two PCB designs in the wild which use the opposite signaling for SD card detect. This makes U-Boot working in one case and failing in the other. Quirk this out by disconnecting SD card detect pin from the PCB by switching to mode 3.

Quoted 37 lines
---
  arch/x86/dts/edison.dts | 12 ++++++++++++
  1 file changed, 12 insertions(+)
arch/x86/dts/edison.dts +12 -0
index 2c8cf6c07102..04e8a4e457c8 100644
@@ -94,6 +94,7 @@
  	sdcard: mmc@ff3fa000 {
  		compatible = "intel,sdhci-tangier";
  		reg = <0xff3fa000 0x1000>;
+		cd-inverted;
  	};
 
  	pmu: power@ff00b000 {
@@ -131,6 +132,17 @@
  		compatible = "intel,pinctrl-tangier";
  		reg = <0xff0c0000 0x8000>;
 
+		/*
+		 * Disconnect SD card detect, so it won't affect the reality
+		 * on two different PCB designs where it's using the opposite
+		 * signaling: Edison/Arduino uses Active Low, while SparkFun
+		 * went with Active High.
+		 */
+		sd_cd@0 {
+			pad-offset = <37>;
+			mode-func = <3>;
+		};
+
  		/*
  		 * Initial configuration came from the firmware.
  		 * Which quite likely has been used in the phones, where I2C #8,
#3 lore raw

Re: [PATCH v1 2/2] x86: edison: Don't take SD card detect pin into consideration

Quoted 7 lines · Ferry Toth

Op 15-10-2021 om 19:11 schreef Andy Shevchenko:

Quoted 5 lines

There are two PCB designs in the wild which use the opposite signaling for SD card detect. This makes U-Boot working in one case and failing in the other. Quirk this out by disconnecting SD card detect pin from the PCB by switching to mode 3.

Thank you, Ferry. And AFAICS the original reporter had confirmed that this fixes the issue on his SparkFun board.

Bin, can this be reviewed and applied?

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#8 lore raw
In reply to Andy Shevchenko

Hi Andy,

Quoted 44 lines · Andy Shevchenko

We would need to quirk out Card Detect case and for that we allow configuring SD/SDIO family of pins.

---
 arch/x86/cpu/tangier/pinmux.c | 39 ++++++++++++++++++++++++++++++-----
 1 file changed, 34 insertions(+), 5 deletions(-)
arch/x86/cpu/tangier/pinmux.c +18 -1
index acf97e3af51d..8385167b2b6b 100644
@@ -37,8 +37,9 @@ struct mrfld_family {
                .npins = (e) - (s) + 1,                 \
        }
 
-/* Now we only support I2C family of pins */
+/* Now we only support SD/SDIO and I2C families of pins */
 static struct mrfld_family mrfld_families[] = {
+       MRFLD_FAMILY(3, 37, 56),
        MRFLD_FAMILY(7, 101, 114),
 };
 
@@ -125,6 +126,34 @@ static int mrfld_pinconfig_protected(unsigned int pin, u32 mask, u32 bits)
        return ret;
 }
 
+static int mrfld_pinconfig(unsigned int pin, u32 mask, u32 bits)
+{
+       struct mrfld_pinctrl *pinctrl;
+       struct udevice *dev;
+       void __iomem *bufcfg;
+       u32 v, value;
+       int ret;
+
+       ret = syscon_get_by_driver_data(X86_SYSCON_PINCONF, &dev);
+       if (ret)
+               return ret;
+
+       pinctrl = dev_get_priv(dev);
+
+       bufcfg = mrfld_get_bufcfg(pinctrl, pin);
+       if (!bufcfg)

arch/x86/cpu/tangier/pinmux.c static int mrfld_pinconfig_protected(unsigned int pin, u32 mask, u32 bits) · line 154

Quoted 10 lines
arch/x86/cpu/tangier/pinmux.c +10 -0
+               return -EINVAL;
+
+       value = readl(bufcfg);
+       v = (value & ~mask) | (bits & mask);
+       writel(v, bufcfg);
+
+       debug("v: 0x%x p: 0x%x bits: %d, mask: %d bufcfg: 0x%p\n",
+             v, (u32)bufcfg, bits, mask, bufcfg);
+
+       return 0;

This function can be consolidated with mrfld_pinconfig_protected(),
ie: updating mrfld_pinconfig_protected() to call mrfld_pinconfig().

Quoted 18 lines
arch/x86/cpu/tangier/pinmux.c +2 -3
+}
+
 static int mrfld_pinctrl_cfg_pin(ofnode pin_node)
 {
        bool is_protected;
@@ -133,10 +162,7 @@ static int mrfld_pinctrl_cfg_pin(ofnode pin_node)
        u32 mask;
        int ret;
 
-       /* For now we only support just protected Family of pins */
        is_protected = ofnode_read_bool(pin_node, "protected");
-       if (!is_protected)
-               return -ENOTSUPP;
 
        pad_offset = ofnode_read_s32_default(pin_node, "pad-offset", -1);
        if (pad_offset == -1)
@@ -152,7 +178,10 @@ static int mrfld_pinctrl_cfg_pin(ofnode pin_node)
        if (mode & ~mask)

arch/x86/cpu/tangier/pinmux.c static int mrfld_pinctrl_cfg_pin(ofnode pin_node) · line 187

Quoted 10 lines
arch/x86/cpu/tangier/pinmux.c +4 -1
                return -ENOTSUPP;
 
-       ret = mrfld_pinconfig_protected(pad_offset, mask, mode);
+       if (is_protected)
+               ret = mrfld_pinconfig_protected(pad_offset, mask, mode);
+       else
+               ret = mrfld_pinconfig(pad_offset, mask, mode);
 
        return ret;
 }

Regards,
Bin

#4 lore raw

Re: [PATCH v1 2/2] x86: edison: Don't take SD card detect pin into consideration

In reply to Andy Shevchenko

Hi Andy,

Quoted 17 lines · Andy Shevchenko

There are two PCB designs in the wild which use the opposite signaling for SD card detect. This makes U-Boot working in one case and failing in the other. Quirk this out by disconnecting SD card detect pin from the PCB by switching to mode 3.

---
 arch/x86/dts/edison.dts | 12 ++++++++++++
 1 file changed, 12 insertions(+)
arch/x86/dts/edison.dts +0 -0
index 2c8cf6c07102..04e8a4e457c8 100644

arch/x86/dts/edison.dts line 97

Quoted 4 lines
arch/x86/dts/edison.dts +1 -0
@@ -94,6 +94,7 @@
        sdcard: mmc@ff3fa000 {
                compatible = "intel,sdhci-tangier";
                reg = <0xff3fa000 0x1000>;
+               cd-inverted;

So I wonder how sd card ever worked without the "cd-inverted" property?

Quoted 12 lines
arch/x86/dts/edison.dts +5 -0
        };
 
        pmu: power@ff00b000 {
@@ -131,6 +132,17 @@
                compatible = "intel,pinctrl-tangier";
                reg = <0xff0c0000 0x8000>;
 
+               /*
+                * Disconnect SD card detect, so it won't affect the reality
+                * on two different PCB designs where it's using the opposite
+                * signaling: Edison/Arduino uses Active Low, while SparkFun
+                * went with Active High.

arch/x86/dts/edison.dts

Quoted 10 lines
arch/x86/dts/edison.dts +6 -1
+                */
+               sd_cd@0 {
+                       pad-offset = <37>;
+                       mode-func = <3>;
+               };
+
                /*
                 * Initial configuration came from the firmware.
                 * Which quite likely has been used in the phones, where I2C #8,
--

Regards,
Bin

#5 lore raw

Re: [PATCH v1 2/2] x86: edison: Don't take SD card detect pin into consideration

Quoted 9 lines · Bin Meng
Quoted 7 lines · Andy Shevchenko

There are two PCB designs in the wild which use the opposite signaling for SD card detect. This makes U-Boot working in one case and failing in the other. Quirk this out by disconnecting SD card detect pin from the PCB by switching to mode 3.

...

Quoted 6 lines
Quoted 4 lines
        sdcard: mmc@ff3fa000 {
                compatible = "intel,sdhci-tangier";
                reg = <0xff3fa000 0x1000>;

+ cd-inverted;

So I wonder how sd card ever worked without the "cd-inverted" property?

TL;DR: it worked on one PCB design and did not work on the other. When we disconnect the pin the read value is always the same and inverted to what we expected in the code.

Have you read the commit message and the comment below? Have you read the bug report?

Quoted 6 lines
Quoted 6 lines
arch/x86/dts/edison.dts +6 -0
+               /*
+                * Disconnect SD card detect, so it won't affect the reality
+                * on two different PCB designs where it's using the opposite
+                * signaling: Edison/Arduino uses Active Low, while SparkFun
+                * went with Active High.
+                */
Signature · 2 lines
With Best Regards,
Andy Shevchenko
#9 lore raw
In reply to Bin Meng
Quoted 5 lines · Bin Meng
Quoted 3 lines · Andy Shevchenko

We would need to quirk out Card Detect case and for that we allow configuring SD/SDIO family of pins.

...

Quoted 5 lines

arch/x86/cpu/tangier/pinmux.c static int mrfld_pinconfig_protected(unsigned int pin, u32 mask, u32 bits) · line 130

Quoted 2 lines
arch/x86/cpu/tangier/pinmux.c +2 -0
+static int mrfld_pinconfig(unsigned int pin, u32 mask, u32 bits)
+{

This function can be consolidated with mrfld_pinconfig_protected(),
ie: updating mrfld_pinconfig_protected() to call mrfld_pinconfig().

Can it be done in a separate patch? This is a fix related and tested, it will take time to retest this by all parties.

Quoted 1 line
Quoted 1 line

+}

Signature · 2 lines
With Best Regards,
Andy Shevchenko
Reviewed-by
#6 lore raw

Re: [PATCH v1 2/2] x86: edison: Don't take SD card detect pin into consideration

In reply to Andy Shevchenko
Quoted 19 lines · Andy Shevchenko
Quoted 9 lines · Bin Meng
Quoted 7 lines · Andy Shevchenko

There are two PCB designs in the wild which use the opposite signaling for SD card detect. This makes U-Boot working in one case and failing in the other. Quirk this out by disconnecting SD card detect pin from the PCB by switching to mode 3.

...

Quoted 5 lines
Quoted 4 lines
        sdcard: mmc@ff3fa000 {
                compatible = "intel,sdhci-tangier";
                reg = <0xff3fa000 0x1000>;

+ cd-inverted;

Quoted 5 lines
Quoted 1 line

So I wonder how sd card ever worked without the "cd-inverted" property?

TL;DR: it worked on one PCB design and did not work on the other. When we disconnect the pin the read value is always the same and inverted to what we expected in the code.

Great. That explains. Although I read the below comments a couple of times, it just did not come to my head that "when we disconnect the pin the read value is always the same and inverted to what we expected in the code."

Quoted 3 lines

Have you read the commit message and the comment below? Have you read the bug report?

Yes, but it's not crystal clear hence the ask. So maybe we can update the comments to make such clearer?

Quoted 7 lines
Quoted 7 lines

arch/x86/dts/edison.dts line 140

Quoted 7 lines
arch/x86/dts/edison.dts +6 -0
+               /*
+                * Disconnect SD card detect, so it won't affect the reality
+                * on two different PCB designs where it's using the opposite
+                * signaling: Edison/Arduino uses Active Low, while SparkFun
+                * went with Active High.
+                */

FWIW,

Regards,
Bin

Reviewed-by
#10 lore raw
In reply to Andy Shevchenko
Quoted 10 lines · Andy Shevchenko
Quoted 5 lines · Bin Meng
Quoted 3 lines · Andy Shevchenko

We would need to quirk out Card Detect case and for that we allow configuring SD/SDIO family of pins.

...

Quoted 9 lines
Quoted 5 lines

arch/x86/cpu/tangier/pinmux.c static int mrfld_pinconfig_protected(unsigned int pin, u32 mask, u32 bits) · line 130

Quoted 2 lines
arch/x86/cpu/tangier/pinmux.c +2 -0
+static int mrfld_pinconfig(unsigned int pin, u32 mask, u32 bits)
+{

This function can be consolidated with mrfld_pinconfig_protected(),
ie: updating mrfld_pinconfig_protected() to call mrfld_pinconfig().

Can it be done in a separate patch? This is a fix related and tested, it will take time to retest this by all parties.

Sure please send a follow-up patch when you are free.

Regards,
Bin

#11 lore raw
Quoted 5 lines · Bin Meng
Quoted 3 lines · Andy Shevchenko
Quoted 2 lines · Bin Meng

On Sat, Oct 16, 2021 at 1:27 AM Andy Shevchenko
<[email protected]> wrote:

...

Quoted 7 lines
Quoted 5 lines
Quoted 2 lines

This function can be consolidated with mrfld_pinconfig_protected(),
ie: updating mrfld_pinconfig_protected() to call mrfld_pinconfig().

Can it be done in a separate patch? This is a fix related and tested, it will take time to retest this by all parties.

Sure please send a follow-up patch when you are free.

I will do it later on.

Quoted 1 line

Thanks!

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#7 lore raw

Re: [PATCH v1 2/2] x86: edison: Don't take SD card detect pin into consideration

In reply to Bin Meng
Quoted 5 lines · Bin Meng
Quoted 3 lines · Andy Shevchenko
Quoted 2 lines · Bin Meng

On Sat, Oct 16, 2021 at 1:27 AM Andy Shevchenko
<[email protected]> wrote:

...

Quoted 4 lines
Quoted 4 lines
Quoted 3 lines
Quoted 1 line

+ cd-inverted;

So I wonder how sd card ever worked without the "cd-inverted" property?

Quoted 8 lines
Quoted 3 lines

TL;DR: it worked on one PCB design and did not work on the other. When we disconnect the pin the read value is always the same and inverted to what we expected in the code.

Great. That explains. Although I read the below comments a couple of times, it just did not come to my head that "when we disconnect the pin the read value is always the same and inverted to what we expected in the code."

Sure!

Quoted 5 lines
Quoted 2 lines

Have you read the commit message and the comment below? Have you read the bug report?

Yes, but it's not crystal clear hence the ask. So maybe we can update the comments to make such clearer?

Yep, I'll do it for the next version.

Quoted 9 lines
Quoted 6 lines
Quoted 6 lines

arch/x86/dts/edison.dts line 140

Quoted 6 lines
arch/x86/dts/edison.dts +6 -0
+               /*
+                * Disconnect SD card detect, so it won't affect the reality
+                * on two different PCB designs where it's using the opposite
+                * signaling: Edison/Arduino uses Active Low, while SparkFun
+                * went with Active High.
+                */

FWIW,

Thanks!

Signature · 2 lines
With Best Regards,
Andy Shevchenko