tm2: add SWD interface [3/3]
authorYingyuan Zhu <yingyuan.zhu@amlogic.com>
Wed, 24 Apr 2019 09:50:29 +0000 (17:50 +0800)
committerTao Zeng <tao.zeng@amlogic.com>
Thu, 9 May 2019 02:21:44 +0000 (19:21 -0700)
PD#SWPL-5647

Problem:
tm2 does not support SWD mode.

Solution:
add code to support SWD mode.

Verify:
test pass on ab311

Change-Id: If85a050b5033242200dd7163a8391e71960621f0
Signed-off-by: Yingyuan Zhu <yingyuan.zhu@amlogic.com>
arch/arm/boot/dts/amlogic/mesontm2.dtsi
arch/arm64/boot/dts/amlogic/mesontm2.dtsi
drivers/amlogic/jtag/meson_jtag.c
include/linux/amlogic/jtag.h

index 6d195d2..c15290f 100644 (file)
        jtag {
                compatible = "amlogic, jtag";
                status = "okay";
-               select = "disable"; /* disable/apao */
-               pinctrl-names="jtag_apao_pins";
+               select = "disable"; /* disable/apao/swd_apao */
+               pinctrl-names="jtag_apao_pins", "jtag_swd_apao_pins";
                pinctrl-0=<&jtag_apao_pins>;
+               pinctrl-1=<&jtag_swd_apao_pins>;
        };
 
        saradc:saradc {
                        function = "jtag_a";
                };
        };
+
+       jtag_swd_apao_pins:swd_apao_pin {
+               mux {
+                       groups = "swclk",
+                       "swdio";
+                       function = "sw";
+               };
+       };
 };
 
 &pinctrl_periphs {
index 5690f3d..bcbb435 100644 (file)
        jtag {
                compatible = "amlogic, jtag";
                status = "okay";
-               select = "disable"; /* disable/apao */
-               pinctrl-names="jtag_apao_pins";
+               select = "disable"; /* disable/apao/swd_apao */
+               pinctrl-names="jtag_apao_pins", "jtag_swd_apao_pins";
                pinctrl-0=<&jtag_apao_pins>;
+               pinctrl-1=<&jtag_swd_apao_pins>;
        };
 
        saradc:saradc {
                        function = "jtag_a";
                };
        };
+
+       jtag_swd_apao_pins:swd_apao_pin {
+               mux {
+                       groups = "swclk",
+                       "swdio";
+                       function = "sw";
+               };
+       };
 };
 
 &pinctrl_periphs {
index a080ef5..be0f0ce 100644 (file)
@@ -96,6 +96,8 @@ static inline char *select_to_name(int select)
                return "apao";
        case AMLOGIC_JTAG_APEE:
                return "apee";
+       case AMLOGIC_SWD_APAO:
+               return "swd_apao";
        default:
                return "disable";
        }
@@ -111,6 +113,8 @@ static inline int name_to_select(const char *s)
                select = AMLOGIC_JTAG_APAO;
        else if (!strncmp(s, "apee", 4))
                select = AMLOGIC_JTAG_APEE;
+       else if (!strncmp(s, "swd_apao", 8))
+               select = AMLOGIC_SWD_APAO;
        else {
                pr_err("unknown select: %s\n", s);
                select = AMLOGIC_JTAG_DISABLE;
@@ -168,7 +172,7 @@ static int __init setup_jtag(char *p)
 }
 
 /*
- * jtag=[apao|apee]
+ * jtag=[apao|apee|swd_apao]
  * jtag=[apao|apee]{,[0|1]}
  *
  * [apao|apee]: jtag domain
@@ -356,6 +360,20 @@ static int aml_jtag_setup(struct aml_jtag_dev *jdev)
                        return -EINVAL;
                }
                break;
+       case AMLOGIC_SWD_APAO:
+               s = pinctrl_lookup_state(jdev->jtag_pinctrl,
+                                        "jtag_swd_apao_pins");
+               if (IS_ERR_OR_NULL(s)) {
+                       dev_err(&jdev->pdev->dev,
+                                       "could not get swd_apao_pins state\n");
+                       return -EINVAL;
+               }
+               ret = pinctrl_select_state(jdev->jtag_pinctrl, s);
+               if (ret) {
+                       dev_err(&jdev->pdev->dev, "failed to set pinctrl\n");
+                       return -EINVAL;
+               }
+               break;
        default:
                if (old_select != AMLOGIC_JTAG_DISABLE) {
                        devm_pinctrl_put(jdev->jtag_pinctrl);
@@ -380,7 +398,7 @@ static ssize_t jtag_select_show(struct class *cls,
        len += sprintf(buf + len, "current select: %s\n\n",
                        select_to_name(global_select));
        len += sprintf(buf + len, "usage:\n");
-       len += sprintf(buf + len, "    echo [apao|apee] > select\n");
+       len += sprintf(buf + len, "    echo [apao|apee|swd_apao] > select\n");
        len += sprintf(buf + len, "    echo [apao|apee]{,[0|1]} > select\n");
 
        return len;
index 8497f5c..6db6e26 100644 (file)
@@ -26,6 +26,7 @@
 #define AMLOGIC_JTAG_DISABLE           (-1)
 #define AMLOGIC_JTAG_APAO                      2
 #define AMLOGIC_JTAG_APEE                      3
+#define AMLOGIC_SWD_APAO                       10
 
 #define AMLOGIC_JTAG_ON                        0x82000040
 #define AMLOGIC_JTAG_OFF               0x82000041