SD Card doesn't up on custom carrier board

Hiya,

I’ve a custom carrier board that takes a micro sd card. My kernel (R32.1) works ok sd card wise on the dev kit but it doesn’t on my board. The only difference between the two (ignoring sd card vs micro sd card write protect issues, not a problem here) is the power enable pin has been moved from the SOM to an external gpio expander.

I can see from dmesg that the gpio expander comes up & is set after the sdhci driver does it’s thing on start up. If I unbind sdhci.3400000 & then bind it again, voila! The sd card comes up & mounts ok.

How might I control when the driver attempts to mount the sd card on startup as this seems to be a timing/power tree issue?

The sdhci should be able to control the regulator (gpio) from software.

Do you put your gpio pin to the device tree?

-> /t18x-common-platforms/tegra186-quill-power-tree-p3310-1000-a00-00.dtsi

sdhci@3400000 {
                  vqmmc-supply = <&spmic_ldo3>;
                  vmmc-supply = <&en_vdd_sdcard1>;
         };

Yes I edited en_vdd_sdcard1 to use the gpio expanders pin.

Does the driver find this regulator? Could you share the dmesg?
Do you mean the whole gpio expander is initiated after the sdhci driver?

with no changes dmesg says:

[    0.566107] vddio-sdmmc1: 1800 <--> 3300 mV at 3300 mV 
[    0.592623] en-vdd-sd: 3300 mV 
[    1.314390] sdhci: Secure Digital Host Controller Interface driver
[    1.314394] sdhci: Copyright(c) Pierre Ossman
[    1.314396] sdhci-pltfm: SDHCI platform and OF driver helper
[    1.316033] sdhci-tegra 3460000.sdhci: Client registration for eMC Successful
[    1.321924] sdhci-tegra 3440000.sdhci: Client registration for eMC Successful
[    1.326735] sdhci-tegra 3400000.sdhci: Got CD GPIO
[    1.327321] sdhci-tegra 3400000.sdhci: Client registration for eMC Successful
[    1.329069] sdhci-tegra 3400000.sdhci: wakeup init done, cdirq 256
[    1.362658] mmc0: SDHCI controller on 3460000.sdhci [3460000.sdhci] using ADMA 64-bit with 64 bit addr
[    1.366914] mmc1: SDHCI controller on 3440000.sdhci [3440000.sdhci] using ADMA 64-bit with 64 bit addr
[    1.378708] mmc2: SDHCI controller on 3400000.sdhci [3400000.sdhci] using ADMA 64-bit with 64 bit addr
[    1.446343] mmc0: periodic cache flush enabled
[    1.446357] mmc0: new HS400 Enhanced strobe MMC card at address 0001
[    1.446885] mmcblk0: mmc0:0001 032G34 29.1 GiB 
[    1.447081] mmcblk0boot0: mmc0:0001 032G34 partition 1 4.00 MiB
[    1.447280] mmcblk0boot1: mmc0:0001 032G34 partition 2 4.00 MiB
[    1.447446] mmcblk0rpmb: mmc0:0001 032G34 partition 3 4.00 MiB
[    1.451746]  mmcblk0: p1 p2 p3 p4 p5 p6 p7 p8 p9 p10 p11 p12 p13 p14 p15 p16 p17 p18 p19 p20 p21 p22 p23 p24 p25 p26 p27 p28 p29 p30 p31
[    1.623688] mmc1: Applying tuning correction
[    1.623720] mmc1: Tap value after applying correction 68
[    1.623728] mmc1: hw tuning done ...
[    1.630734] mmc1: new ultra high speed SDR104 SDIO card at address 0001
[    2.052020] mmcblk mmc0:0001: Card claimed for testing.
[    2.095303] en-vdd-sd: disabling
[    2.133721] Root device found: mmcblk0p1
[    2.135424] Found dev node: /dev/mmcblk0p1
[    2.160436] EXT4-fs (mmcblk0p1): mounted filesystem with ordered data mode. Opts: (null)
[    2.161866] Rootfs mounted over mmcblk0p1
[    2.800945] EXT4-fs (mmcblk0p1): re-mounted. Opts: (null)
[    4.511339] sdhci-tegra 3440000.sdhci: Tuning done, restoring the best tap value : 68
[    5.755750] sdhci-tegra 3440000.sdhci: could not set regulator OCR (-1)
[    5.787876] sdhci-tegra 3440000.sdhci: could not set regulator OCR (-1)
[    5.820640] sdhci-tegra 3440000.sdhci: could not set regulator OCR (-1)
[    5.836293] sdhci-tegra 3440000.sdhci: could not set regulator OCR (-1)
[    5.958507] sdhci-tegra 3440000.sdhci: could not set regulator OCR (-1)
[    5.974737] sdhci-tegra 3440000.sdhci: could not set regulator OCR (-1)
[    5.996164] sdhci-tegra 3440000.sdhci: could not set regulator OCR (-1)
[    6.006566] sdhci-tegra 3440000.sdhci: Tuning done, restoring the best tap value : 68

If you track en-vdd-sd through that you see it’s enabled before sdhci probing & disabled after, no mmcblk1 shows up (but something happens with mmc2, which is what we want). On this hardware the usual gpio to en-vdd-sd is disconnected from everything. The micro SD is actually powered later on which we can see when we…

with en-vdd-sd dt change:

regulator@1 {
	vin-supply = <&my3V3Bus>;
	gpio = <&myNewGpioExp 0 0x0>;
};

dmesg said this:

[    0.574090] vddio-sdmmc1: 1800 <--> 3300 mV at 3300 mV 
[    1.342528] sdhci: Secure Digital Host Controller Interface driver
[    1.342532] sdhci: Copyright(c) Pierre Ossman
[    1.342535] sdhci-pltfm: SDHCI platform and OF driver helper
[    1.344060] sdhci-tegra 3460000.sdhci: Client registration for eMC Successful
[    1.349729] sdhci-tegra 3440000.sdhci: Client registration for eMC Successful
[    1.354873] sdhci-tegra 3400000.sdhci: Got CD GPIO
[    1.355507] sdhci-tegra 3400000.sdhci: Client registration for eMC Successful
[    1.357274] sdhci-tegra 3400000.sdhci: wakeup init done, cdirq 256
[    1.389740] mmc0: SDHCI controller on 3460000.sdhci [3460000.sdhci] using ADMA 64-bit with 64 bit addr
[    1.394026] mmc1: SDHCI controller on 3440000.sdhci [3440000.sdhci] using ADMA 64-bit with 64 bit addr
[    1.479663] mmc0: periodic cache flush enabled
[    1.479678] mmc0: new HS400 Enhanced strobe MMC card at address 0001
[    1.480107] mmcblk0: mmc0:0001 032G34 29.1 GiB 
[    1.480358] mmcblk0boot0: mmc0:0001 032G34 partition 1 4.00 MiB
[    1.484574] mmcblk0boot1: mmc0:0001 032G34 partition 2 4.00 MiB
[    1.484775] mmcblk0rpmb: mmc0:0001 032G34 partition 3 4.00 MiB
[    1.486981]  mmcblk0: p1 p2 p3 p4 p5 p6 p7 p8 p9 p10 p11 p12 p13 p14 p15 p16 p17 p18 p19 p20 p21 p22 p23 p24 p25 p26 p27 p28 p29 p30 p31
[    1.666172] mmc1: Applying tuning correction
[    1.666204] mmc1: Tap value after applying correction 68
[    1.666212] mmc1: hw tuning done ...
[    1.673241] mmc1: new ultra high speed SDR104 SDIO card at address 0001
[    1.827285] en-vdd-sd: supplied by my3V3Bus-core-en
[    1.827310] en-vdd-sd: 3300 mV 
[    2.199287] mmcblk mmc0:0001: Card claimed for testing.
[    2.242779] vddio-sdmmc1: disabling
[    2.242958] en-vdd-sd: disabling
[    2.284924] Root device found: mmcblk0p1
[    2.287342] Found dev node: /dev/mmcblk0p1
[    2.312498] EXT4-fs (mmcblk0p1): mounted filesystem with ordered data mode. Opts: (null)
[    2.313650] Rootfs mounted over mmcblk0p1
[    2.993622] EXT4-fs (mmcblk0p1): re-mounted. Opts: (null)
[    4.761287] sdhci-tegra 3440000.sdhci: Tuning done, restoring the best tap value : 68
[    5.665632] sdhci-tegra 3440000.sdhci: could not set regulator OCR (-1)
[    5.699072] sdhci-tegra 3440000.sdhci: could not set regulator OCR (-1)
[    5.724668] sdhci-tegra 3440000.sdhci: could not set regulator OCR (-1)
[    5.743261] sdhci-tegra 3440000.sdhci: could not set regulator OCR (-1)
[    5.884528] sdhci-tegra 3440000.sdhci: could not set regulator OCR (-1)
[    5.898336] sdhci-tegra 3440000.sdhci: could not set regulator OCR (-1)
[    5.914790] sdhci-tegra 3440000.sdhci: could not set regulator OCR (-1)
[    5.921750] sdhci-tegra 3440000.sdhci: Tuning done, restoring the best tap value : 68

Now en-vdd-sd is tracking the right gpio, it’s on when we believe it to be on, but mmc2 is a no show now. 3400000.sdhci seems to start at about 1.3s into things but does no more & the power to the card is set at 1.8s later. Additionally, the supplies seem to immediately disable themselves, presumably because they’ve nothing to stay on for.

Finally with boot delay dt change:

sdhci@3400000 {
	nvidia,boot-detect-delay = <600>;
};

dmesg said this!

[    0.566456] vddio-sdmmc1: 1800 <--> 3300 mV at 3300 mV 
[    1.337675] sdhci: Secure Digital Host Controller Interface driver
[    1.337679] sdhci: Copyright(c) Pierre Ossman
[    1.337682] sdhci-pltfm: SDHCI platform and OF driver helper
[    1.339339] sdhci-tegra 3460000.sdhci: Client registration for eMC Successful
[    1.344186] sdhci-tegra 3440000.sdhci: Client registration for eMC Successful
[    1.348018] sdhci-tegra 3400000.sdhci: Got CD GPIO
[    1.348618] sdhci-tegra 3400000.sdhci: Client registration for eMC Successful
[    1.350295] sdhci-tegra 3400000.sdhci: wakeup init done, cdirq 256
[    1.386765] mmc0: SDHCI controller on 3460000.sdhci [3460000.sdhci] using ADMA 64-bit with 64 bit addr
[    1.391048] mmc1: SDHCI controller on 3440000.sdhci [3440000.sdhci] using ADMA 64-bit with 64 bit addr
[    1.449928] mmc0: periodic cache flush enabled
[    1.449942] mmc0: new HS400 Enhanced strobe MMC card at address 0001
[    1.454467] mmcblk0: mmc0:0001 032G34 29.1 GiB 
[    1.454654] mmcblk0boot0: mmc0:0001 032G34 partition 1 4.00 MiB
[    1.455065] mmcblk0boot1: mmc0:0001 032G34 partition 2 4.00 MiB
[    1.455282] mmcblk0rpmb: mmc0:0001 032G34 partition 3 4.00 MiB
[    1.457196]  mmcblk0: p1 p2 p3 p4 p5 p6 p7 p8 p9 p10 p11 p12 p13 p14 p15 p16 p17 p18 p19 p20 p21 p22 p23 p24 p25 p26 p27 p28 p29 p30 p31
[    1.659574] mmc1: Applying tuning correction
[    1.659606] mmc1: Tap value after applying correction 68
[    1.659617] mmc1: hw tuning done ...
[    1.666589] mmc1: new ultra high speed SDR104 SDIO card at address 0001
[    1.824454] en-vdd-sd: supplied by +3v4-core-en
[    1.824482] en-vdd-sd: 3300 mV 
[    2.018879] mmc2: SDHCI controller on 3400000.sdhci [3400000.sdhci] using ADMA 64-bit with 64 bit addr
[    2.192328] mmcblk mmc0:0001: Card claimed for testing.
[    2.243818] mmc2: host does not support reading read-only switch, assuming write-enable
[    2.276310] Root device found: mmcblk0p1
[    2.278206] Found dev node: /dev/mmcblk0p1
[    2.325341] EXT4-fs (mmcblk0p1): mounted filesystem with ordered data mode. Opts: (null)
[    2.326393] Rootfs mounted over mmcblk0p1
[    2.383890] mmc2: hw tuning done ...
[    2.383935] mmc2: new ultra high speed SDR104 SDXC card at address aaaa
[    2.384284] mmcblk2: mmc2:aaaa SC400 367 GiB 
[    2.387181]  mmcblk2: p1
[    3.005811] EXT4-fs (mmcblk0p1): re-mounted. Opts: (null)
[    4.816647] sdhci-tegra 3440000.sdhci: Tuning done, restoring the best tap value : 68
[   12.480831] sdhci-tegra 3440000.sdhci: could not set regulator OCR (-1)
[   12.512842] sdhci-tegra 3440000.sdhci: could not set regulator OCR (-1)
[   12.544885] sdhci-tegra 3440000.sdhci: could not set regulator OCR (-1)
[   12.559164] sdhci-tegra 3440000.sdhci: could not set regulator OCR (-1)
[   12.677350] sdhci-tegra 3440000.sdhci: could not set regulator OCR (-1)
[   12.697224] sdhci-tegra 3440000.sdhci: could not set regulator OCR (-1)
[   12.712886] sdhci-tegra 3440000.sdhci: could not set regulator OCR (-1)
[   12.722140] sdhci-tegra 3440000.sdhci: Tuning done, restoring the best tap value : 68

So whilst a delay appeared to work I’m a little dubious that it’ll work across multiple units, what if the delays vary from device to device? It’d be nicer if the driver only probed once the gpio expander was seen to be working.

NB other experiments that lead no-where were: “nvidia,vqmmc-always-on”, “nvidia,vmmc-always-on”, “power-gpios” & trying to use “vin-supply” on anything sdhci related.

Would you mind sharing the full dmesg and device tree here?

Can you connect a scope or halt execution here ([ 1.824482] en-vdd-sd: 3300 mV ) and check if 3v3 is seen on the socket?

That GPIO may have a rampup delay. you need to add that in the regulator. you can do so in the DT regulator node