sd: add sd power cycle for sd3.0 [1/1]
authorNan Li <nan.li@amlogic.com>
Thu, 10 Oct 2019 07:31:59 +0000 (15:31 +0800)
committerzihuan.ling <zihuan.ling@amlogic.com>
Tue, 15 Oct 2019 07:04:01 +0000 (03:04 -0400)
PD#SWPL-14953

Problem:
SD card 3.0 mode requires power cycle.
if not, the initialization of SD card will be affected.

Solution:
add SD power cycle supported.

Verify:
sm1_ac200

Change-Id: Ic8aecadf3b63660adb74ff4ecf0a5d38037b579f
Signed-off-by: Nan Li <nan.li@amlogic.com>
arch/arm/boot/dts/amlogic/mesonsm1.dtsi
arch/arm64/boot/dts/amlogic/mesonsm1.dtsi
drivers/amlogic/mmc/aml_sd_emmc.c
drivers/amlogic/mmc/aml_sd_emmc_v3.c
drivers/amlogic/mmc/amlsd.c

index e6833019a7970fa567b63608a998a50791ff343c..65ec5294ad683db0b0bd8619d44a5ee1f2926488 100644 (file)
                        "sd_to_ao_uart_pins",
                        "ao_to_sd_uart_pins",
                        "sd_to_ao_jtag_pins",
-                       "ao_to_sd_jtag_pins";
+                       "ao_to_sd_jtag_pins",
+                       "sd_all_pd_pins";
 
                pinctrl-0 = <&sd_all_pins>;
                pinctrl-1 = <&sd_clk_cmd_pins>;
                pinctrl-7 = <&sd_all_pins &sd_to_ao_uart_pins>;
                pinctrl-8 = <&sd_to_ao_uart_clr_pins
                        &ao_to_sd_uart_pins>;
+               pinctrl-9 = <&sd_all_pd_pins>;
 
                clocks = <&clkc CLKID_SD_EMMC_B>,
                        <&clkc CLKID_SD_EMMC_B_P0_COMP>,
                };
        };
 
+       sd_all_pd_pins:sd_all_pd_pins {
+               mux {
+                       groups = "GPIOC_0",
+                                  "GPIOC_1",
+                                  "GPIOC_2",
+                                  "GPIOC_3",
+                                  "GPIOC_4",
+                                  "GPIOC_5";
+                       function = "gpio_periphs";
+                       bias-pull-down;
+                       output-low;
+               };
+       };
+
        sd_1bit_pins:sd_1bit_pins {
                mux {
                        groups = "sdcard_d0_c",
index b765723d66461e77221d09deab3ddea31a51c01f..24fefc856d3bb27a0764f924ae072a9f9f8f2535 100644 (file)
                        "sd_to_ao_uart_pins",
                        "ao_to_sd_uart_pins",
                        "sd_to_ao_jtag_pins",
-                       "ao_to_sd_jtag_pins";
+                       "ao_to_sd_jtag_pins",
+                       "sd_all_pd_pins";
 
                pinctrl-0 = <&sd_all_pins>;
                pinctrl-1 = <&sd_clk_cmd_pins>;
                pinctrl-7 = <&sd_all_pins &sd_to_ao_uart_pins>;
                pinctrl-8 = <&sd_to_ao_uart_clr_pins
                        &ao_to_sd_uart_pins>;
+                       pinctrl-8 = <&sd_all_pd_pins>;
 
                clocks = <&clkc CLKID_SD_EMMC_B>,
                        <&clkc CLKID_SD_EMMC_B_P0_COMP>,
                };
        };
 
+       sd_all_pd_pins:sd_all_pd_pins {
+               mux {
+                       groups = "GPIOC_0",
+                                  "GPIOC_1",
+                                  "GPIOC_2",
+                                  "GPIOC_3",
+                                  "GPIOC_4",
+                                  "GPIOC_5";
+                       function = "gpio_periphs";
+                       bias-pull-down;
+                       output-low;
+               };
+       };
+
        sd_1bit_pins:sd_1bit_pins {
                mux {
                        groups = "sdcard_d0_c",
index 2270071184572b37ad59a5bf72874f1be06d9031..32e6f58797a5f166eb2732f9e89594adc31b1eaf 100644 (file)
@@ -3256,6 +3256,7 @@ static int meson_mmc_probe(struct platform_device *pdev)
                mmc->f_max = pdata->f_max;
                mmc->max_current_180 = 300; /* 300 mA in 1.8V */
                mmc->max_current_330 = 300; /* 300 mA in 3.3V */
+               pdata->signal_voltage = 0xff;
 
                if (aml_card_type_sdio(pdata)) { /* if sdio_wifi */
                        /*      mmc->host_rescan_disable = true;*/
index 16b1335870a524a1087bbbc42d2df21da6a82d02..264da6a4b08cf26087252b1e2236623a8e65fe6c 100644 (file)
@@ -472,6 +472,10 @@ static void aml_sd_emmc_set_power_v3(struct amlsd_platform *pdata,
                        pdata->pwr_on(pdata);
                break;
        case MMC_POWER_UP:
+               if (aml_card_type_non_sdio(pdata)) {
+                       of_amlsd_pwr_off(pdata);
+                       of_amlsd_pwr_on(pdata);
+               }
                break;
        case MMC_POWER_OFF:
                writel(0, host->base + SD_EMMC_DELAY1_V3);
index 9ea8262db1d9ddc033b621e4f2254865840f15cd..693bfa947bab863b6f1383fcc1da41338a1f6f63 100644 (file)
@@ -335,18 +335,6 @@ void of_amlsd_pwr_prepare(struct amlsd_platform *pdata)
 {
 }
 
-void of_amlsd_pwr_on(struct amlsd_platform *pdata)
-{
-       if (pdata->gpio_power)
-               gpio_set_value(pdata->gpio_power, pdata->power_level);
-}
-
-void of_amlsd_pwr_off(struct amlsd_platform *pdata)
-{
-       if (pdata->gpio_power)
-               gpio_set_value(pdata->gpio_power, !pdata->power_level);
-}
-
 #ifdef CARD_DETECT_IRQ
 void of_amlsd_irq_init(struct amlsd_platform *pdata)
 {
@@ -383,7 +371,8 @@ int of_amlsd_init(struct amlsd_platform *pdata)
        }
 #endif
        if (pdata->gpio_power) {
-               if (pdata->power_level) {
+               if (pdata->power_level &&
+                   !aml_card_type_non_sdio(pdata)) {
                        ret = gpio_request_one(pdata->gpio_power,
                                        GPIOF_OUT_INIT_LOW, MODULE_NAME);
                        CHECK_RET(ret);
@@ -431,14 +420,14 @@ static struct pinctrl * __must_check aml_devm_pinctrl_get_select(
        s = pinctrl_lookup_state(p, name);
        if (IS_ERR(s)) {
                pr_err("lookup %s fail\n", name);
-               devm_pinctrl_put(p);
+               aml_devm_pinctrl_put(host);
                return ERR_CAST(s);
        }
 
        ret = pinctrl_select_state(p, s);
        if (ret < 0) {
                pr_err("select %s fail\n", name);
-               devm_pinctrl_put(p);
+               aml_devm_pinctrl_put(host);
                return ERR_PTR(ret);
        }
        if ((host->mem->start == host->data->port_b_base)
@@ -475,6 +464,47 @@ static struct pinctrl * __must_check aml_devm_pinctrl_get_select(
 }
 #endif /* SD_EMMC_PIN_CTRL */
 
+#define sd3_pwr_dbg 1
+void of_amlsd_pwr_on(struct amlsd_platform *pdata)
+{
+#if sd3_pwr_dbg
+       struct pinctrl *p = NULL;
+       struct amlsd_host *host = pdata->host;
+#endif
+
+       if (pdata->gpio_power) {
+               gpio_set_value(pdata->gpio_power, pdata->power_level);
+#if sd3_pwr_dbg
+               if (aml_card_type_non_sdio(pdata)) {
+                       mutex_lock(&host->pinmux_lock);
+                       p = aml_devm_pinctrl_get_select(host, "sd_all_pins");
+                       mutex_unlock(&host->pinmux_lock);
+               }
+#endif
+       }
+}
+
+void of_amlsd_pwr_off(struct amlsd_platform *pdata)
+{
+#if sd3_pwr_dbg
+       struct pinctrl *p = NULL;
+       struct amlsd_host *host = pdata->host;
+#endif
+
+       if (pdata->gpio_power) {
+               gpio_set_value(pdata->gpio_power, !pdata->power_level);
+
+#if sd3_pwr_dbg
+               if (aml_card_type_non_sdio(pdata)) {
+                       mutex_lock(&host->pinmux_lock);
+                       p = aml_devm_pinctrl_get_select(host, "sd_all_pd_pins");
+                       mutex_unlock(&host->pinmux_lock);
+                       mdelay(200);    //pull down need 200ms.
+               }
+#endif
+       }
+}
+
 void of_amlsd_xfer_pre(struct amlsd_platform *pdata)
 {
        struct amlsd_host *host = pdata->host;