From c8ba8b60275ff99f5103142db5b167354c5b94c0 Mon Sep 17 00:00:00 2001 From: Yingyuan Zhu Date: Wed, 24 Apr 2019 17:50:29 +0800 Subject: [PATCH] tm2: add SWD interface [3/3] 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 --- arch/arm/boot/dts/amlogic/mesontm2.dtsi | 13 +++++++++++-- arch/arm64/boot/dts/amlogic/mesontm2.dtsi | 13 +++++++++++-- drivers/amlogic/jtag/meson_jtag.c | 22 ++++++++++++++++++++-- include/linux/amlogic/jtag.h | 1 + 4 files changed, 43 insertions(+), 6 deletions(-) diff --git a/arch/arm/boot/dts/amlogic/mesontm2.dtsi b/arch/arm/boot/dts/amlogic/mesontm2.dtsi index 6d195d2..c15290f 100644 --- a/arch/arm/boot/dts/amlogic/mesontm2.dtsi +++ b/arch/arm/boot/dts/amlogic/mesontm2.dtsi @@ -523,9 +523,10 @@ 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 { @@ -1814,6 +1815,14 @@ function = "jtag_a"; }; }; + + jtag_swd_apao_pins:swd_apao_pin { + mux { + groups = "swclk", + "swdio"; + function = "sw"; + }; + }; }; &pinctrl_periphs { diff --git a/arch/arm64/boot/dts/amlogic/mesontm2.dtsi b/arch/arm64/boot/dts/amlogic/mesontm2.dtsi index 5690f3d..bcbb4356 100644 --- a/arch/arm64/boot/dts/amlogic/mesontm2.dtsi +++ b/arch/arm64/boot/dts/amlogic/mesontm2.dtsi @@ -512,9 +512,10 @@ 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 { @@ -1803,6 +1804,14 @@ function = "jtag_a"; }; }; + + jtag_swd_apao_pins:swd_apao_pin { + mux { + groups = "swclk", + "swdio"; + function = "sw"; + }; + }; }; &pinctrl_periphs { diff --git a/drivers/amlogic/jtag/meson_jtag.c b/drivers/amlogic/jtag/meson_jtag.c index a080ef5..be0f0ce 100644 --- a/drivers/amlogic/jtag/meson_jtag.c +++ b/drivers/amlogic/jtag/meson_jtag.c @@ -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; diff --git a/include/linux/amlogic/jtag.h b/include/linux/amlogic/jtag.h index 8497f5c..6db6e26 100644 --- a/include/linux/amlogic/jtag.h +++ b/include/linux/amlogic/jtag.h @@ -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 -- 2.7.4