Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp1476381pxa; Thu, 6 Aug 2020 08:27:38 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwf6OW52Dl0EYnsXj/RWoiRnoBNwNYv5VSGilqemIG4b3MbMcB6IMdEx1Dk6JtbDMLrqDoK X-Received: by 2002:a17:906:8050:: with SMTP id x16mr4759923ejw.441.1596727658646; Thu, 06 Aug 2020 08:27:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1596727658; cv=none; d=google.com; s=arc-20160816; b=bclqCeTpbbdmzxPWToKaqu4rL91F+jftFhqSGFQQrkPZjQnFknQYCCp81yKALhQgvu J4qMDr2tFe7SLABX4GuGXhtznoWqVk6KsDQmd216Bw0acuNMiLBAQEJFg6/8rld4QGdH bUnRwHE49nrUui8HXBY17ee8j7AzMLJ/DHdm9pIxqafHVn9ffuO2rMgohU9SJsuiVOda rL1d8Ndv8Ej6T4w02gWhgfG/U4UgtLOQXiBz12WZArWMJ2Z44PFCZmWTMOoKgfvi1Zpe QZapbe2V4x/bbgMyw59oJD6/dDoqmGyr50woRtw2hKAKy0IEzoIA3BRrE3Y/Omn2PTAl CWZQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-language :content-transfer-encoding:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:dkim-signature; bh=D2nPuh6+PfL0pW7ynAT+SzMECoPzN1zrqCQoSJsgD8I=; b=ZHjdRATlbxd4aEG8XMoKV4B157FkwEa/9aNwMl6KKt9in+RgXGff5pw1UahLU6jVCj lcuoWgS7XGFfJbnFBmGL9w3EP0QTkkrZ58AY6Hhmujdb8bXwEvS7znXAC4ydeFDi/pJp etihCf99njFBt3Xhg2s18dptlL5Crcu63aPjQvGLCQu4b1FpCJmkNumN2rO49+v4Y94f FzHVhYFe7RmPabyLNJTcWsQpxiPhp3Ubrw3mcbCHvzX61EsaAmp4gPIsgaO9QoHtAwcz NSSdIh8mAiFzhYGah4kyHE55DfM5LFNQqM2UAPHFh2JtL+8xNze5cR76klXLzv1lz209 B3ng== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@baylibre-com.20150623.gappssmtp.com header.s=20150623 header.b=r5Rp1ZyQ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id bi20si3450310ejb.365.2020.08.06.08.26.50; Thu, 06 Aug 2020 08:27:38 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@baylibre-com.20150623.gappssmtp.com header.s=20150623 header.b=r5Rp1ZyQ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729180AbgHFPEU (ORCPT + 99 others); Thu, 6 Aug 2020 11:04:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48132 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726403AbgHFOUR (ORCPT ); Thu, 6 Aug 2020 10:20:17 -0400 Received: from mail-wm1-x341.google.com (mail-wm1-x341.google.com [IPv6:2a00:1450:4864:20::341]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9C280C0A3BD0 for ; Thu, 6 Aug 2020 06:50:00 -0700 (PDT) Received: by mail-wm1-x341.google.com with SMTP id t14so9772119wmi.3 for ; Thu, 06 Aug 2020 06:50:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20150623.gappssmtp.com; s=20150623; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-transfer-encoding:content-language; bh=D2nPuh6+PfL0pW7ynAT+SzMECoPzN1zrqCQoSJsgD8I=; b=r5Rp1ZyQLReNIQzLJnzNIwfTUQ2LL3PCoGanIuiyoHll/QnJXJrqFFw5jOcck2mM+v L7IMLj4cPILDecQWjxOXKfxnlp37Rrn2Hkl6KflsSK+lZY8N1cipRb0fiPzy++JDQqt6 l8t8g1L6iwhDQjazMh+Ay4NJ6VNloCD+tdnAogxjSHEho40vqMhitBoJQcuxt7l/ONws U0mzNbRE4E5OGJEnAawJUHfVaTTNL8KbpdA28hJ1IBahnFIug2GGzLTiXvRGiGlJf4Cu cM+roV5Uvye60/uRXodWvu0Og3luLHWs9GmuZlcfs5drdGBkDLqBTI8QCwKifYnnshMK JG5Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding :content-language; bh=D2nPuh6+PfL0pW7ynAT+SzMECoPzN1zrqCQoSJsgD8I=; b=ctscdqkzC27dX0Qs0dPA+AHSrBtlxwe/eFtaLVB0t6UOKICYDJMKxJfSSazNtXitP3 qZN+NBOpysRt6GQY+Yt8N7Lndb38NW49IKMIoBATV8hKRC0pCbWU/QWbtog/t3xgJuXp xdhLVbq3qr5Fb/VYG3u7t5e9HzM/WhZ/l8+eux7E7ZfUqU2lGkiHuhcsHkeRT9mWEggh dR1oA0tq3a3y35T7hsabGYAPu7lyiyGnge3k1RNCIr2Sn8yUP2PiJMKw7Xp6v5Z6yqmn LfIaFuD8Nb/ZdfB+7/uJBCXFDyr/1hFwvTJ+zoYxhxqU0HRCZq2/M9257ppwP/c5OM9J sCEQ== X-Gm-Message-State: AOAM530LKwGVORtF5HLV4jDdkcy1UQhgMaqhBM+lunJLE7yA1VgBNicG f8kmk6vbvXxBoUreGYMhPVHXQ1LoqSb45Q== X-Received: by 2002:a1c:28c4:: with SMTP id o187mr7776064wmo.62.1596721788974; Thu, 06 Aug 2020 06:49:48 -0700 (PDT) Received: from linux.local (laubervilliers-658-1-213-31.w90-63.abo.wanadoo.fr. [90.63.244.31]) by smtp.gmail.com with ESMTPSA id h11sm6535503wrb.68.2020.08.06.06.49.47 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 06 Aug 2020 06:49:48 -0700 (PDT) Subject: Re: [PATCH 3/6] remoteproc: mtk_vpu_rproc: Add support of JTAG To: Mathieu Poirier Cc: ohad@wizery.com, bjorn.andersson@linaro.org, robh+dt@kernel.org, matthias.bgg@gmail.com, linux-remoteproc@vger.kernel.org, devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, linux-kernel@vger.kernel.org References: <20200713132927.24925-1-abailon@baylibre.com> <20200713132927.24925-4-abailon@baylibre.com> <20200721195231.GA1227776@xps15> From: Alexandre Bailon Message-ID: Date: Thu, 6 Aug 2020 15:49:49 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.11.0 MIME-Version: 1.0 In-Reply-To: <20200721195231.GA1227776@xps15> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Content-Language: en-US Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 7/21/20 9:52 PM, Mathieu Poirier wrote: > On Mon, Jul 13, 2020 at 03:29:24PM +0200, Alexandre Bailon wrote: >> The DSP could be debugged using JTAG. >> The support of JTAG could enabled at build time and it could be enabled >> using debugfs. >> >> Signed-off-by: Alexandre Bailon >> --- >> drivers/remoteproc/Kconfig | 9 ++ >> drivers/remoteproc/mtk_apu_rproc.c | 156 ++++++++++++++++++++++++++++- >> 2 files changed, 162 insertions(+), 3 deletions(-) >> >> diff --git a/drivers/remoteproc/Kconfig b/drivers/remoteproc/Kconfig >> index e116d4a12ac3..e1158563e2e8 100644 >> --- a/drivers/remoteproc/Kconfig >> +++ b/drivers/remoteproc/Kconfig >> @@ -52,6 +52,15 @@ config MTK_APU >> >> It's safe to say N here. >> >> +config MTK_APU_JTAG >> + bool "Enable support of JTAG" >> + depends on MTK_APU >> + help >> + Say y to enable support of JTAG. >> + By default, JTAG will remain disabled until it is enabled using >> + debugfs: remoteproc/remoteproc0/jtag. Write 1 to enable it and >> + 0 to disable it. >> + >> config OMAP_REMOTEPROC >> tristate "OMAP remoteproc support" >> depends on ARCH_OMAP4 || SOC_OMAP5 || SOC_DRA7XX >> diff --git a/drivers/remoteproc/mtk_apu_rproc.c b/drivers/remoteproc/mtk_apu_rproc.c >> index fb416a817ef3..f2342b747a35 100644 >> --- a/drivers/remoteproc/mtk_apu_rproc.c >> +++ b/drivers/remoteproc/mtk_apu_rproc.c >> @@ -5,6 +5,7 @@ >> >> #include >> #include >> +#include >> #include >> #include >> #include >> @@ -14,6 +15,7 @@ >> #include >> #include >> #include >> +#include >> #include >> #include >> >> @@ -48,6 +50,11 @@ >> #define CORE_DEFAULT1 (0x00000140) >> #define CORE_DEFAULT0_ARUSER_IDMA_USE_IOMMU (0x10 << 0) >> #define CORE_DEFAULT0_AWUSER_IDMA_USE_IOMMU (0x10 << 5) >> +#define CORE_DEFAULT2 (0x00000144) >> +#define CORE_DEFAULT2_DBG_EN BIT(3) >> +#define CORE_DEFAULT2_NIDEN BIT(2) >> +#define CORE_DEFAULT2_SPNIDEN BIT(1) >> +#define CORE_DEFAULT2_SPIDEN BIT(0) >> #define CORE_XTENSA_ALTRESETVEC (0x000001F8) >> >> struct mtk_vpu_rproc { >> @@ -59,6 +66,13 @@ struct mtk_vpu_rproc { >> struct clk *axi; >> struct clk *ipu; >> struct clk *jtag; >> + >> +#ifdef CONFIG_MTK_APU_JTAG >> + struct pinctrl *pinctrl; >> + struct pinctrl_state *pinctrl_default; >> + struct pinctrl_state *pinctrl_jtag; >> + bool jtag_enabled; >> +#endif >> }; >> >> static u32 vpu_read32(struct mtk_vpu_rproc *vpu_rproc, u32 off) >> @@ -149,6 +163,133 @@ static irqreturn_t handle_event(int irq, void *data) >> return IRQ_HANDLED; >> } >> >> +#ifdef CONFIG_MTK_APU_JTAG >> + >> +static int vpu_enable_jtag(struct mtk_vpu_rproc *vpu_rproc) >> +{ >> + int ret = 0; >> + >> + if (vpu_rproc->jtag_enabled) >> + return -EINVAL; >> + >> + ret = pinctrl_select_state(vpu_rproc->pinctrl, >> + vpu_rproc->pinctrl_jtag); >> + if (ret < 0) { >> + dev_err(vpu_rproc->dev, "Failed to configure pins for JTAG\n"); >> + return ret; >> + } >> + >> + vpu_write32(vpu_rproc, CORE_DEFAULT2, >> + CORE_DEFAULT2_SPNIDEN | CORE_DEFAULT2_SPIDEN | >> + CORE_DEFAULT2_NIDEN | CORE_DEFAULT2_DBG_EN); >> + >> + vpu_rproc->jtag_enabled = 1; > There should be mutex that gets taken at the beginning and released at the end of > this function. > >> + >> + return ret; >> +} >> + >> +static int vpu_disable_jtag(struct mtk_vpu_rproc *vpu_rproc) >> +{ >> + int ret = 0; >> + >> + if (!vpu_rproc->jtag_enabled) >> + return -EINVAL; >> + >> + vpu_write32(vpu_rproc, CORE_DEFAULT2, 0); >> + >> + ret = pinctrl_select_state(vpu_rproc->pinctrl, >> + vpu_rproc->pinctrl_default); >> + if (ret < 0) { >> + dev_err(vpu_rproc->dev, >> + "Failed to configure pins to default\n"); >> + return ret; >> + } >> + >> + vpu_rproc->jtag_enabled = 0; > Same comment as above. > >> + >> + return ret; >> +} >> + >> +static ssize_t rproc_jtag_read(struct file *filp, char __user *userbuf, >> + size_t count, loff_t *ppos) >> +{ >> + struct rproc *rproc = filp->private_data; >> + struct mtk_vpu_rproc *vpu_rproc = (struct mtk_vpu_rproc *)rproc->priv; >> + char *buf = vpu_rproc->jtag_enabled ? "enabled\n" : "disabled\n"; >> + >> + return simple_read_from_buffer(userbuf, count, ppos, buf, strlen(buf)); >> +} >> + >> +static ssize_t rproc_jtag_write(struct file *filp, const char __user *user_buf, >> + size_t count, loff_t *ppos) >> +{ >> + struct rproc *rproc = filp->private_data; >> + struct mtk_vpu_rproc *vpu_rproc = (struct mtk_vpu_rproc *)rproc->priv; >> + char buf[10]; >> + int ret; >> + >> + if (count < 1 || count > sizeof(buf)) >> + return -EINVAL; >> + >> + ret = copy_from_user(buf, user_buf, count); >> + if (ret) >> + return -EFAULT; >> + >> + /* remove end of line */ >> + if (buf[count - 1] == '\n') >> + buf[count - 1] = '\0'; >> + >> + if (!strncmp(buf, "1", count) || !strncmp(buf, "enabled", count)) >> + ret = vpu_enable_jtag(vpu_rproc); >> + else if (!strncmp(buf, "0", count) || !strncmp(buf, "disabled", count)) >> + ret = vpu_disable_jtag(vpu_rproc); >> + else >> + return -EINVAL; > I think we should simply stick with "enabled" and "disabled" to be in line with > what is done in rproc_recovery_write(). > >> + >> + return ret ? ret : count; >> +} >> + >> +static const struct file_operations rproc_jtag_ops = { >> + .read = rproc_jtag_read, >> + .write = rproc_jtag_write, >> + .open = simple_open, >> +}; >> + >> +static int vpu_jtag_probe(struct mtk_vpu_rproc *vpu_rproc) >> +{ >> + int ret; >> + >> + if (!vpu_rproc->rproc->dbg_dir) >> + return -ENODEV; >> + >> + vpu_rproc->pinctrl = devm_pinctrl_get(vpu_rproc->dev); >> + if (IS_ERR(vpu_rproc->pinctrl)) { >> + dev_warn(vpu_rproc->dev, "Failed to find JTAG pinctrl\n"); >> + return PTR_ERR(vpu_rproc->pinctrl); >> + } >> + >> + vpu_rproc->pinctrl_default = pinctrl_lookup_state(vpu_rproc->pinctrl, >> + PINCTRL_STATE_DEFAULT); > Indentation problem. > >> + if (IS_ERR(vpu_rproc->pinctrl_default)) >> + return PTR_ERR(vpu_rproc->pinctrl_default); >> + >> + vpu_rproc->pinctrl_jtag = pinctrl_lookup_state(vpu_rproc->pinctrl, >> + "jtag"); >> + if (IS_ERR(vpu_rproc->pinctrl_jtag)) >> + return PTR_ERR(vpu_rproc->pinctrl_jtag); >> + >> + ret = pinctrl_select_state(vpu_rproc->pinctrl, >> + vpu_rproc->pinctrl_default); > What is the default configuration for? It does not seem to be needed to > properly boot the remote processor since it is not part of the example in the > bindings or dts patch included in this set. Moreover it is part of a > configuration option so I really don't understand what it does. I have a poor knowledge of pinctrl framework so I may have done things wrong here. This is not really needed for the remote processor. By default, I don't want pin to be configured for JTAG until we enable it and I want to be able to revert it the default state. May be this is too much and I should assume that if we build the driver with JTAG enabled then we want the pins to be configured for JTAG by default. > > > >> + if (ret < 0) >> + return ret; >> + >> + debugfs_create_file("jtag", 0600, vpu_rproc->rproc->dbg_dir, >> + vpu_rproc->rproc, &rproc_jtag_ops); >> + >> + return 0; >> +} >> +#endif /* CONFIG_MTK_APU_JTAG */ >> + >> static int mtk_vpu_rproc_probe(struct platform_device *pdev) >> { >> struct device *dev = &pdev->dev; >> @@ -228,16 +369,16 @@ static int mtk_vpu_rproc_probe(struct platform_device *pdev) >> goto clk_disable_ipu; >> } >> >> - vpu_rproc->jtag = devm_clk_get_optional(dev, "jtag"); >> + vpu_rproc->jtag = devm_clk_get(vpu_rproc->dev, "jtag"); > As I remarked in my comments on the previous patch, this should have been > devm_clk_get() from the start. Either that or the bindings are wrong. I should have not made the change in this patch. I will fix it. Thanks, Alexandre > >> if (IS_ERR(vpu_rproc->jtag)) { >> - dev_err(dev, "Failed to enable jtag clock\n"); >> + dev_err(vpu_rproc->dev, "Failed to get jtag clock\n"); > Why go from dev to vpu_rproc->dev? > >> ret = PTR_ERR(vpu_rproc->jtag); >> goto clk_disable_axi; >> } >> >> ret = clk_prepare_enable(vpu_rproc->jtag); >> if (ret) { >> - dev_err(dev, "Failed to enable jtag clock\n"); >> + dev_err(vpu_rproc->dev, "Failed to enable jtag clock\n"); > Same here. > >> goto clk_disable_axi; >> } >> >> @@ -253,6 +394,12 @@ static int mtk_vpu_rproc_probe(struct platform_device *pdev) >> goto free_mem; >> } >> >> +#ifdef CONFIG_MTK_APU_JTAG >> + ret = vpu_jtag_probe(vpu_rproc); >> + if (ret) >> + dev_warn(dev, "Failed to configure jtag\n"); >> +#endif > Please don't use #ifdefs in the code like that. It is better to introduce a > #else (above) with stubs that don't do anything. > >> + >> return 0; >> >> free_mem: >> @@ -277,6 +424,9 @@ static int mtk_vpu_rproc_remove(struct platform_device *pdev) >> >> disable_irq(vpu_rproc->irq); >> >> +#ifdef CONFIG_MTK_APU_JTAG >> + vpu_disable_jtag(vpu_rproc); >> +#endif >> rproc_del(rproc); >> of_reserved_mem_device_release(dev); >> clk_disable_unprepare(vpu_rproc->jtag); >> -- >> 2.26.2 >>