Received: by 2002:a05:6a10:9afc:0:0:0:0 with SMTP id t28csp2264313pxm; Fri, 4 Mar 2022 12:38:37 -0800 (PST) X-Google-Smtp-Source: ABdhPJw8StIAWQ9DVFkLaryqWhQJSeYINXI6Jp1AGUU1vtzLbD3UFRQpdCEauT+aRcUGxFbPfhTP X-Received: by 2002:a63:9043:0:b0:37d:92b9:aa6b with SMTP id a64-20020a639043000000b0037d92b9aa6bmr167079pge.406.1646426317743; Fri, 04 Mar 2022 12:38:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646426317; cv=none; d=google.com; s=arc-20160816; b=pG8vn+119DpJ7OU/NnXHSg+IY+IwrxseZRk94jZHqg0DXQPUYFrENjP8F/WXcwk159 9lSRNCihKuUeByylpo79oL/2kQiXYGt8l2WMRGPBsdzqIh1qLQiC1EKM2fdIIvoGL5xP weEklr/7O2qqpiQJUacm/8rstWbcXsbeMUBrXqP/zsCnPdLwOR6ZyLIwcY3nXw4hjzuJ uQ7zk7nk7nf2HcZhSLIs/Yo/kxnBWDs4Rp63qG72KO5sN4Rxch23SlYoUtDiFb6IqqbB 8497a8xBJ/CG2wzaA4Vk8tiRJeTVp5rvDgW6+n1SRj+9JRV6dp/1r6oHcjxVxDhtgRMp JipA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=DFsuyCOMy/pl+DrmLQk2yMUaSrmiytEYHpzUyHLsV8M=; b=bTiXx88CyO3+hA+FELl6wYKsWCkT3zoSfPaGHDwHpSuLk1ZN73gOGYg/RHoV+kz5in 8ts8e/fdyuNRhSS0POIDrSb6Xeak7c0+7okUEB6bEvGiM3kPKVLbeRi+6mTLV5bULIqQ EUM4M3M+a6f8w2HO1+O/AsiCpYrpMaAp1q8dqy2MeIdOGjvbd7fm4rlxral1hOxOCDyw ZnIXjoeQ+LSClUdZKRzFa5j69cNhPMJEVl5H1hUW/NCM9Qd1V4HAJuteHrXQpTbRB/kU tCEyqc18BtH1R8Zuz0EDgFGVuvwPPIkJpy++BPykPh2fW1Q4KuVaJA3u6j2X1te4GZda yYRg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@baylibre-com.20210112.gappssmtp.com header.s=20210112 header.b=MfM51jgP; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id t9-20020a17090a1c8900b001bef5f19d9dsi439465pjt.38.2022.03.04.12.38.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Mar 2022 12:38:37 -0800 (PST) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@baylibre-com.20210112.gappssmtp.com header.s=20210112 header.b=MfM51jgP; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 6DDE21E3744; Fri, 4 Mar 2022 11:38:25 -0800 (PST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240756AbiCDQQb (ORCPT + 99 others); Fri, 4 Mar 2022 11:16:31 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56368 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240716AbiCDQQT (ORCPT ); Fri, 4 Mar 2022 11:16:19 -0500 Received: from mail-wm1-x32b.google.com (mail-wm1-x32b.google.com [IPv6:2a00:1450:4864:20::32b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4809A1B8CA6 for ; Fri, 4 Mar 2022 08:15:31 -0800 (PST) Received: by mail-wm1-x32b.google.com with SMTP id r187-20020a1c2bc4000000b003810e6b192aso5394036wmr.1 for ; Fri, 04 Mar 2022 08:15:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=DFsuyCOMy/pl+DrmLQk2yMUaSrmiytEYHpzUyHLsV8M=; b=MfM51jgPq7iaGaLlQsyEHm/9ew1UFuusyy1unUC+zh3q+Nmf1L3n9YE7xcAwnx9FCJ XjtkR6AKg8+cAcFPWYX11uhdoCZKFxdDbKBnWuA2daTUlTHTqk86YT+PSJaC/tniMNdH NMr5Cu842/zTYHMn7BZe8/XaTj11PTamnDTomm4/kLFCTM24KBVCEJIiDCGe6yQwZtV9 CaNd7/iKn+K2+Pse/Ff5skhlz4Dk+neOVxd4jbOOX9w+pMODz5V+jzlNFm3NxSOLHR8Q OqpES/+l3HarKWoFkFL3upi6aue2PIPgM1lNOAPpJM+EfwpXtKiA3095r/sMi/nGfNDm DKQg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=DFsuyCOMy/pl+DrmLQk2yMUaSrmiytEYHpzUyHLsV8M=; b=SxuhRPP+1i39VUYLtCd2axusNArVA6bXssQYfSRTLRnkOOTiGbV6IJa7cRYxMYy9ym G8OjS18oPVXzuE7g2UdedkeZVw552uzg8f2PsSgp0GWqa2MvW1FejLK/KP3wPo39cusu apPSNGJE4iTBMWy6x5zwrqUiDYfCZ5rAL2XvSqp0GU64tot2BVfJ1grBGpJtUAAcfSl1 LijvPk7+8bpjsSy1B2n7i0AA5uJqVYCuoikiGN3ZY1qMaCOZk8cBrW3U4qUqhaJx/h3I OHBBPD5pMfYK4UqtQfSQvnL+BcwQZCP/SbbFk0epjlFJKFeZRFUCB0Ar0I4wi1nHxNdN cFNA== X-Gm-Message-State: AOAM5323UDY4XpZaCN1Dyb63lm+/oxBoV4nnDb7SgRvzYyE/ybO0itUH lMI8eLuaUsjWRZ6bMdI3KtshTw== X-Received: by 2002:a05:600c:3c9b:b0:380:be98:6204 with SMTP id bg27-20020a05600c3c9b00b00380be986204mr8063300wmb.121.1646410529792; Fri, 04 Mar 2022 08:15:29 -0800 (PST) Received: from xps-9300.baylibre (laubervilliers-658-1-213-31.w90-63.abo.wanadoo.fr. [90.63.244.31]) by smtp.gmail.com with ESMTPSA id g6-20020a5d5406000000b001f049726044sm4937307wrv.79.2022.03.04.08.15.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Mar 2022 08:15:29 -0800 (PST) From: Alexandre Bailon To: ohad@wizery.com, bjorn.andersson@linaro.org, mathieu.poirier@linaro.org, robh+dt@kernel.or Cc: 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, stephane.leprovost@mediatek.com, khilman@baylibre.com, Alexandre Bailon Subject: [PATCH v4 4/7] remoteproc: mtk_apu: Add support of JTAG Date: Fri, 4 Mar 2022 17:15:11 +0100 Message-Id: <20220304161514.994128-5-abailon@baylibre.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220304161514.994128-1-abailon@baylibre.com> References: <20220304161514.994128-1-abailon@baylibre.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RDNS_NONE, SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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.c | 147 ++++++++++++++++++++++++++++++++++- 2 files changed, 155 insertions(+), 1 deletion(-) diff --git a/drivers/remoteproc/Kconfig b/drivers/remoteproc/Kconfig index 959d24e9492c..28140cf04d8a 100644 --- a/drivers/remoteproc/Kconfig +++ b/drivers/remoteproc/Kconfig @@ -74,6 +74,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.c b/drivers/remoteproc/mtk_apu.c index 867b4682b507..3905eb5b7174 100644 --- a/drivers/remoteproc/mtk_apu.c +++ b/drivers/remoteproc/mtk_apu.c @@ -5,12 +5,14 @@ #include #include +#include #include #include #include #include #include #include +#include #include #include #include @@ -45,6 +47,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) #define VDEV_MEM_COUNT (3) @@ -59,6 +66,13 @@ struct mtk_apu_rproc { struct clk_bulk_data *clks; struct iommu_domain *domain; struct list_head mappings; + +#ifdef CONFIG_MTK_APU_JTAG + struct pinctrl *pinctrl; + struct pinctrl_state *pinctrl_jtag; + bool jtag_enabled; + struct mutex jtag_mutex; +#endif }; static const char * const mt8183_clk_names[] = { @@ -355,6 +369,133 @@ static irqreturn_t mtk_apu_rproc_callback(int irq, void *data) return IRQ_WAKE_THREAD; } +#ifdef CONFIG_MTK_APU_JTAG + +static int apu_enable_jtag(struct mtk_apu_rproc *apu_rproc) +{ + int ret = 0; + + mutex_lock(&apu_rproc->jtag_mutex); + if (apu_rproc->jtag_enabled) + goto err_mutex_unlock; + + writel(CORE_DEFAULT2_SPNIDEN | CORE_DEFAULT2_SPIDEN | + CORE_DEFAULT2_NIDEN | CORE_DEFAULT2_DBG_EN, + apu_rproc->base + CORE_DEFAULT2); + + apu_rproc->jtag_enabled = 1; + +err_mutex_unlock: + mutex_unlock(&apu_rproc->jtag_mutex); + + return ret; +} + +static int apu_disable_jtag(struct mtk_apu_rproc *apu_rproc) +{ + int ret = 0; + + mutex_lock(&apu_rproc->jtag_mutex); + if (!apu_rproc->jtag_enabled) + goto err_mutex_unlock; + + writel(0, apu_rproc->base + CORE_DEFAULT2); + + apu_rproc->jtag_enabled = 0; + +err_mutex_unlock: + mutex_unlock(&apu_rproc->jtag_mutex); + + 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_apu_rproc *apu_rproc = (struct mtk_apu_rproc *)rproc->priv; + char *buf = apu_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_apu_rproc *apu_rproc = (struct mtk_apu_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, "enabled", count)) + ret = apu_enable_jtag(apu_rproc); + else if (!strncmp(buf, "disabled", count)) + ret = apu_disable_jtag(apu_rproc); + else + return -EINVAL; + + 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 apu_jtag_probe(struct mtk_apu_rproc *apu_rproc) +{ + int ret; + + if (!apu_rproc->rproc->dbg_dir) + return -ENODEV; + + apu_rproc->pinctrl = devm_pinctrl_get(apu_rproc->dev); + if (IS_ERR(apu_rproc->pinctrl)) { + dev_warn(apu_rproc->dev, "Failed to find JTAG pinctrl\n"); + return PTR_ERR(apu_rproc->pinctrl); + } + + apu_rproc->pinctrl_jtag = pinctrl_lookup_state(apu_rproc->pinctrl, + "jtag"); + if (IS_ERR(apu_rproc->pinctrl_jtag)) + return PTR_ERR(apu_rproc->pinctrl_jtag); + + ret = pinctrl_select_state(apu_rproc->pinctrl, + apu_rproc->pinctrl_jtag); + if (ret < 0) + return ret; + + mutex_init(&apu_rproc->jtag_mutex); + + debugfs_create_file("jtag", 0600, apu_rproc->rproc->dbg_dir, + apu_rproc->rproc, &rproc_jtag_ops); + + return 0; +} +#else +static int apu_jtag_probe(struct mtk_apu_rproc *apu_rproc) +{ + return 0; +} + +static int apu_disable_jtag(struct mtk_apu_rproc *apu_rproc) +{ + return 0; +} +#endif /* CONFIG_MTK_APU_JTAG */ + static int mtk_apu_rproc_probe(struct platform_device *pdev) { struct device *dev = &pdev->dev; @@ -442,6 +583,10 @@ static int mtk_apu_rproc_probe(struct platform_device *pdev) goto free_rproc; } + ret = apu_jtag_probe(apu_rproc); + if (ret) + dev_warn(dev, "Failed to configure jtag\n"); + return 0; free_rproc: @@ -457,7 +602,7 @@ static int mtk_apu_rproc_remove(struct platform_device *pdev) struct device *dev = &pdev->dev; disable_irq(apu_rproc->irq); - + apu_disable_jtag(apu_rproc); rproc_del(rproc); of_reserved_mem_device_release(dev); rproc_free(rproc); -- 2.34.1