sd: add sd_uart to g12a.
authorNan Li <nan.li@amlogic.com>
Mon, 7 May 2018 09:11:24 +0000 (17:11 +0800)
committerYixun Lan <yixun.lan@amlogic.com>
Tue, 8 May 2018 11:53:18 +0000 (04:53 -0700)
PD#165584: add sd_uart on g12a.
test on u211.

Change-Id: Ia8e5cde6c60b3019329324445593d82cf2543afe
Signed-off-by: Nan Li <nan.li@amlogic.com>
arch/arm64/boot/dts/amlogic/mesong12a.dtsi
drivers/amlogic/mmc/amlsd.c
include/linux/amlogic/sd.h

index 8b400cd..f56b18e 100644 (file)
                                xtal_tick_en = <1>;
                                fifosize = < 64 >;
                                pinctrl-names = "default";
-                               pinctrl-0 = <&ao_uart_pins>;
+                               /*pinctrl-0 = <&ao_uart_pins>;*/
                                support-sysrq = <0>;  /* 0 not support*/
                        };
 
                        pinname = "sd";
                        ocr_avail = <0x200080>; /**VDD voltage 3.3 ~ 3.4 */
                        max_req_size = <0x20000>; /**128KB*/
-                       gpio_dat3 = <&gpio GPIOC_4 GPIO_ACTIVE_HIGH>;
+                       gpio_dat3 = <&gpio GPIOC_3 GPIO_ACTIVE_HIGH>;
                        jtag_pin = <&gpio GPIOC_0 GPIO_ACTIVE_HIGH>;
                        gpio_cd = <&gpio GPIOC_6 GPIO_ACTIVE_HIGH>;
                        card_type = <5>;
 
                pinctrl-names = "sd_all_pins",
                        "sd_clk_cmd_pins",
+                       "sd_1bit_pins",
+                       "sd_clk_cmd_uart_pins",
+                       "sd_1bit_uart_pins",
+                       "sd_to_ao_uart_pins",
+                       "ao_to_sd_uart_pins",
+                       "sd_to_ao_jtag_pins",
+                       "ao_to_sd_jtag_pins",
+                       "sdio_noclr_all_pins",
+                       "sdio_noclr_clk_cmd_pins",
                        "sdio_all_pins",
                        "sdio_clk_cmd_pins";
                pinctrl-0 = <&sdio_x_clr_pins &sd_all_pins>;
                pinctrl-1 = <&sdio_x_clr_pins &sd_clk_cmd_pins>;
-               pinctrl-2 = <&sd_clr_all_pins
+               pinctrl-2 = <&sdio_x_clr_pins &sd_1bit_pins>;
+               pinctrl-3 = <&sdio_x_clr_pins &sd_to_ao_uart_clr_pins
+                       &sd_clk_cmd_pins &ao_to_sd_uart_pins>;
+               pinctrl-4 = <&sdio_x_clr_pins &sd_to_ao_uart_clr_pins
+                       &sd_1bit_pins &ao_to_sd_uart_pins>;
+               pinctrl-5 = <&sdio_x_clr_pins
+                       &sd_all_pins &sd_to_ao_uart_pins>;
+               pinctrl-6 = <&sdio_x_en_pins &sd_to_ao_uart_clr_pins
+                       &sd_clr_noall_pins &ao_to_sd_uart_pins>;
+               pinctrl-7 = <&sdio_x_en_pins
+                       &sd_clr_all_pins &sd_to_ao_uart_pins>;
+               pinctrl-8 = <&sdio_x_en_pins &sd_to_ao_uart_clr_pins
+                       &sd_clr_noall_pins &ao_to_sd_uart_pins>;
+               pinctrl-9 = <&sd_clr_noall_pins
+                       &sdio_x_en_pins &sdio_x_all_pins>;
+               pinctrl-10 = <&sd_clr_noall_pins
+                       &sdio_x_en_pins &sdio_x_clk_cmd_pins>;
+               pinctrl-11 = <&sd_clr_all_pins
                         &sdio_x_en_pins &sdio_x_all_pins>;
-               pinctrl-3 = <&sd_clr_all_pins
+               pinctrl-12 = <&sd_clr_all_pins
                         &sdio_x_en_pins &sdio_x_clk_cmd_pins>;
 
                clocks = <&clkc CLKID_SD_EMMC_B>,
                        pinname = "sd";
                        ocr_avail = <0x200080>; /**VDD voltage 3.3 ~ 3.4 */
                        max_req_size = <0x20000>; /**128KB*/
-                       gpio_dat3 = <&gpio GPIOC_4 GPIO_ACTIVE_HIGH>;
+                       gpio_dat3 = <&gpio GPIOC_3 GPIO_ACTIVE_HIGH>;
                        jtag_pin = <&gpio GPIOC_0 GPIO_ACTIVE_HIGH>;
                        gpio_cd = <&gpio GPIOC_6 GPIO_ACTIVE_HIGH>;
                        card_type = <5>;
 };/* end of / */
 
 &pinctrl_aobus {
+       sd_to_ao_uart_clr_pins:sd_to_ao_uart_clr_pins {
+               mux {
+                       groups = "GPIOAO_0",
+                                  "GPIOAO_1";
+                       function = "gpio_aobus";
+               };
+       };
+
+       sd_to_ao_uart_pins:sd_to_ao_uart_pins {
+               mux {
+                       groups = "uart_ao_tx_a",
+                                  "uart_ao_rx_a";
+                                  function = "uart_ao_a";
+                                  bias-pull-up;
+                                  input-enable;
+               };
+       };
+
        ao_uart_pins:ao_uart {
                mux {
                        groups = "uart_ao_tx_a",
                };
        };
 
+       sd_1bit_pins:sd_1bit_pins {
+               mux {
+                       groups = "sdcard_d0_c",
+                                       "sdcard_cmd_c";
+                       function = "sdcard";
+                       input-enable;
+                       bias-pull-up;
+                       drive-strength = <3>;
+               };
+               mux1 {
+                       groups = "sdcard_clk_c";
+                       function = "sdcard";
+                       bias-pull-up;
+                       output-high;
+                       drive-strength = <3>;
+               };
+       };
+
        sd_clr_all_pins:sd_clr_all_pins {
                mux {
                        groups = "GPIOC_0",
                };
        };
 
-       sd_1bit_pins:sd_1bit_pins {
+       sd_clr_noall_pins:sd_clr_noall_pins {
                mux {
-                       groups = "sdcard_d0_c",
-                                       "sdcard_cmd_c",
-                                       "sdcard_clk_c";
-                       function = "sdcard";
-                       input-enable;
-                       bias-pull-up;
+                       groups = "GPIOC_0",
+                                  "GPIOC_1",
+                                  "GPIOC_4",
+                                  "GPIOC_5";
+                       function = "gpio_periphs";
+                       output-high;
                };
        };
 
        ao_to_sd_uart_pins:ao_to_sd_uart_pins {
                mux {
-                       groups = "uart_tx_ao_a_c4",
-                                       "uart_rx_ao_a_c5";
+                       groups = "uart_ao_tx_a_c3",
+                                       "uart_ao_rx_a_c2";
                        function = "uart_ao_a_ee";
                        bias-pull-up;
                        input-enable;
                };
        };
+
        /* sdemmc portA */
        sdio_clk_cmd_pins:sdio_clk_cmd_pins {
                mux {
index c68c238..c7e05dc 100644 (file)
@@ -414,6 +414,9 @@ static struct pinctrl * __must_check aml_devm_pinctrl_get_select(
                devm_pinctrl_put(p);
                return ERR_PTR(ret);
        }
+       if ((host->mem->start == host->data->port_b_base)
+                       && (host->data->chip_type == MMC_CHIP_G12A))
+               strlcpy(host->pinctrl_name, name, sizeof(host->pinctrl_name));
        return p;
 }
 #else /* SD_EMMC_PIN_CTRL */
@@ -463,9 +466,16 @@ void of_amlsd_xfer_pre(struct amlsd_platform *pdata)
        if (mmc->ios.chip_select == MMC_CS_DONTCARE) {
                if ((mmc->caps & MMC_CAP_4_BIT_DATA)
                || (strcmp(pdata->pinname, "sd"))
-               || (mmc->caps & MMC_CAP_8_BIT_DATA))
-                       aml_snprint(&p, &size, "%s_all_pins", pdata->pinname);
-               else {
+               || (mmc->caps & MMC_CAP_8_BIT_DATA)) {
+                       if (aml_card_type_sdio(pdata)
+                               && (host->data->chip_type == MMC_CHIP_G12A)
+                               && host->is_sduart)
+                               aml_snprint(&p, &size,
+                                       "%s_noclr_all_pins", pdata->pinname);
+                       else
+                               aml_snprint(&p, &size,
+                                               "%s_all_pins", pdata->pinname);
+               } else {
                        if (pdata->is_sduart && (!strcmp(pdata->pinname, "sd")))
                                aml_snprint(&p, &size,
                                                "%s_1bit_uart_pins",
@@ -479,7 +489,14 @@ void of_amlsd_xfer_pre(struct amlsd_platform *pdata)
                        aml_snprint(&p, &size,
                                        "%s_clk_cmd_uart_pins", pdata->pinname);
                } else {
-                       aml_snprint(&p, &size,
+                       if (aml_card_type_sdio(pdata)
+                               && (host->data->chip_type == MMC_CHIP_G12A)
+                               && host->is_sduart)
+                               aml_snprint(&p, &size,
+                                               "%s_noclr_clk_cmd_pins",
+                                               pdata->pinname);
+                       else
+                               aml_snprint(&p, &size,
                                        "%s_clk_cmd_pins", pdata->pinname);
                }
        }
@@ -617,9 +634,13 @@ static int aml_is_sdjtag(struct amlsd_platform *pdata)
        int in = 0, i;
        int high_cnt = 0, low_cnt = 0;
        u32 vstat = 0;
+       struct pinctrl *pc;
        struct amlsd_host *host = pdata->host;
        struct sd_emmc_status *ista = (struct sd_emmc_status *)&vstat;
 
+       mutex_lock(&host->pinmux_lock);
+       pc = aml_devm_pinctrl_get_select(host, "sd_to_ao_uart_pins");
+
        for (i = 0; ; i++) {
                mdelay(1);
                vstat = readl(host->base + SD_EMMC_STATUS) & 0xffffffff;
@@ -636,6 +657,7 @@ static int aml_is_sdjtag(struct amlsd_platform *pdata)
 
        if (low_cnt > 50)
                in = 1;
+       mutex_unlock(&host->pinmux_lock);
        return !in;
 }
 
@@ -821,6 +843,8 @@ int aml_sd_uart_detect(struct amlsd_platform *pdata)
 {
        static bool is_jtag;
        struct mmc_host *mmc  = pdata->mmc;
+       struct amlsd_host *host = pdata->host;
+
        if (aml_is_card_insert(pdata)) {
                if (pdata->is_in)
                        return 1;
@@ -830,6 +854,8 @@ int aml_sd_uart_detect(struct amlsd_platform *pdata)
                        aml_uart_switch(pdata, 1);
                        pr_info("Uart in\n");
                        mmc->caps &= ~MMC_CAP_4_BIT_DATA;
+                       if (host->data->chip_type == MMC_CHIP_G12A)
+                               host->is_sduart = 1;
                        if (aml_is_sdjtag(pdata)) {
                                aml_jtag_switch_sd(pdata);
                                is_jtag = true;
@@ -918,6 +944,11 @@ static int meson_cd_op(void *data)
        struct amlsd_host *host = pdata->host;
        int ret = 0;
 
+#ifdef AML_MMC_TDMA
+       if ((host->mem->start == host->data->port_b_base)
+                       && (host->data->chip_type == MMC_CHIP_G12A))
+               wait_for_completion(&host->drv_completion);
+#endif
        mutex_lock(&pdata->in_out_lock);
        if (card_dealed == 1) {
                card_dealed = 0;
@@ -940,6 +971,11 @@ static int meson_cd_op(void *data)
                mmc_detect_change(mmc, msecs_to_jiffies(0));
 
        card_dealed = 0;
+#ifdef AML_MMC_TDMA
+       if ((host->mem->start == host->data->port_b_base)
+                       && (host->data->chip_type == MMC_CHIP_G12A))
+               complete(&host->drv_completion);
+#endif
        return 0;
 }
 
index 6bd9af6..4200b51 100644 (file)
@@ -413,6 +413,7 @@ struct amlsd_host {
        char is_tunning;
        char is_timming;
        char tuning_mode;
+       unsigned int is_sduart;
        unsigned int irq;
        unsigned int irq_in;
        unsigned int irq_out;