From patchwork Tue Dec 18 19:19:23 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pratik Patel X-Patchwork-Id: 1906391 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) by patchwork1.kernel.org (Postfix) with ESMTP id A2EE03FCA5 for ; Sat, 22 Dec 2012 20:49:40 +0000 (UTC) Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.76 #1 (Red Hat Linux)) id 1TmVxY-0007Ms-Gn; Sat, 22 Dec 2012 20:46:16 +0000 Received: from wolverine01.qualcomm.com ([199.106.114.254]) by merlin.infradead.org with esmtps (Exim 4.76 #1 (Red Hat Linux)) id 1Tl2nZ-0002nS-Ft for linux-arm-kernel@lists.infradead.org; Tue, 18 Dec 2012 19:25:57 +0000 X-IronPort-AV: E=Sophos;i="4.84,310,1355126400"; d="scan'208";a="14924757" Received: from pdmz-ns-snip_115.254.qualcomm.com (HELO mostmsg01.qualcomm.com) ([199.106.115.254]) by wolverine01.qualcomm.com with ESMTP/TLS/DHE-RSA-AES256-SHA; 18 Dec 2012 11:25:39 -0800 Received: from codeaurora.org (pdmz-ns-snip_218_1.qualcomm.com [192.168.218.1]) by mostmsg01.qualcomm.com (Postfix) with ESMTPA id 2032310004B4; Tue, 18 Dec 2012 11:25:39 -0800 (PST) From: pratikp@codeaurora.org To: linux-arm-kernel@lists.infradead.org Subject: [RFC 6/8] coresight: add CoreSight Replicator driver Date: Tue, 18 Dec 2012 11:19:23 -0800 Message-Id: <1355858365-11849-7-git-send-email-pratikp@codeaurora.org> X-Mailer: git-send-email 1.7.8.3 In-Reply-To: <1355858365-11849-1-git-send-email-pratikp@codeaurora.org> References: <1355858365-11849-1-git-send-email-pratikp@codeaurora.org> X-Bad-Reply: References and In-Reply-To but no 'Re:' in Subject. X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20121218_142553_950203_9FA62538 X-CRM114-Status: GOOD ( 17.24 ) X-Spam-Score: -1.2 (-) X-Spam-Report: SpamAssassin version 3.3.2 on merlin.infradead.org summary: Content analysis details: (-1.2 points) pts rule name description ---- ---------------------- -------------------------------------------------- -2.3 RCVD_IN_DNSWL_MED RBL: Sender listed at http://www.dnswl.org/, medium trust [199.106.114.254 listed in list.dnswl.org] 3.0 KHOP_BIG_TO_CC Sent to 10+ recipients instaed of Bcc or a list -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] X-Mailman-Approved-At: Sat, 22 Dec 2012 15:44:39 -0500 Cc: linux@arm.linux.org.uk, linus.walleij@linaro.org, will.deacon@arm.com, magnus.p.persson@stericsson.com, david.rusling@linaro.org, arve@android.com, dsaxena@linaro.org, john.stultz@linaro.org, jon-hunter@ti.com, d-deao@ti.com, christian.bejram@stericsson.com, Pratik Patel , devicetree-discuss@lists.ozlabs.org X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: linux-arm-kernel-bounces@lists.infradead.org Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org From: Pratik Patel This driver manages CoreSight Replicator that takes single input trace data stream and replicates it to produce two identical trace data output streams. Replicators are typically used to route single interleaved trace data stream to two or more sinks. Signed-off-by: Pratik Patel --- drivers/coresight/Makefile | 2 +- drivers/coresight/coresight-replicator.c | 211 ++++++++++++++++++++++++++++++ 2 files changed, 212 insertions(+), 1 deletions(-) create mode 100644 drivers/coresight/coresight-replicator.c diff --git a/drivers/coresight/Makefile b/drivers/coresight/Makefile index 9f84ad0..b385e81 100644 --- a/drivers/coresight/Makefile +++ b/drivers/coresight/Makefile @@ -3,4 +3,4 @@ # obj-$(CONFIG_CORESIGHT) += coresight.o obj-$(CONFIG_OF) += of_coresight.o -obj-$(CONFIG_CORESIGHT_LINKS_AND_SINKS) += coresight-tmc.o coresight-tpiu.o coresight-etb.o coresight-funnel.o +obj-$(CONFIG_CORESIGHT_LINKS_AND_SINKS) += coresight-tmc.o coresight-tpiu.o coresight-etb.o coresight-funnel.o coresight-replicator.o diff --git a/drivers/coresight/coresight-replicator.c b/drivers/coresight/coresight-replicator.c new file mode 100644 index 0000000..fe37e5e --- /dev/null +++ b/drivers/coresight/coresight-replicator.c @@ -0,0 +1,211 @@ +/* Copyright (c) 2011-2012, The Linux Foundation. All rights reserved. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 and + * only version 2 as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "coresight-priv.h" + +#define replicator_writel(drvdata, val, off) \ + __raw_writel((val), drvdata->base + off) +#define replicator_readl(drvdata, off) \ + __raw_readl(drvdata->base + off) + +#define REPLICATOR_LOCK(drvdata) \ +do { \ + mb(); \ + replicator_writel(drvdata, 0x0, CORESIGHT_LAR); \ +} while (0) +#define REPLICATOR_UNLOCK(drvdata) \ +do { \ + replicator_writel(drvdata, CORESIGHT_UNLOCK, CORESIGHT_LAR); \ + mb(); \ +} while (0) + +#define REPLICATOR_IDFILTER0 (0x000) +#define REPLICATOR_IDFILTER1 (0x004) +#define REPLICATOR_ITATBCTR0 (0xEFC) +#define REPLICATOR_ITATBCTR1 (0xEF8) + +struct replicator_drvdata { + void __iomem *base; + struct device *dev; + struct coresight_device *csdev; + struct clk *clk; +}; + +static void __replicator_enable(struct replicator_drvdata *drvdata, int outport) +{ + REPLICATOR_UNLOCK(drvdata); + + if (outport == 0) { + replicator_writel(drvdata, 0x0, REPLICATOR_IDFILTER0); + replicator_writel(drvdata, 0xFF, REPLICATOR_IDFILTER1); + } else { + replicator_writel(drvdata, 0x0, REPLICATOR_IDFILTER1); + replicator_writel(drvdata, 0xFF, REPLICATOR_IDFILTER0); + } + + REPLICATOR_LOCK(drvdata); +} + +static int replicator_enable(struct coresight_device *csdev, int inport, + int outport) +{ + struct replicator_drvdata *drvdata = dev_get_drvdata(csdev->dev.parent); + int ret; + + ret = clk_prepare_enable(drvdata->clk); + if (ret) + return ret; + + __replicator_enable(drvdata, outport); + + dev_info(drvdata->dev, "REPLICATOR enabled\n"); + return 0; +} + +static void __replicator_disable(struct replicator_drvdata *drvdata, + int outport) +{ + REPLICATOR_UNLOCK(drvdata); + + if (outport == 0) + replicator_writel(drvdata, 0xFF, REPLICATOR_IDFILTER0); + else + replicator_writel(drvdata, 0xFF, REPLICATOR_IDFILTER1); + + REPLICATOR_LOCK(drvdata); +} + +static void replicator_disable(struct coresight_device *csdev, int inport, + int outport) +{ + struct replicator_drvdata *drvdata = dev_get_drvdata(csdev->dev.parent); + + __replicator_disable(drvdata, outport); + + clk_disable_unprepare(drvdata->clk); + + dev_info(drvdata->dev, "REPLICATOR disabled\n"); +} + +static const struct coresight_ops_link replicator_link_ops = { + .enable = replicator_enable, + .disable = replicator_disable, +}; + +static const struct coresight_ops replicator_cs_ops = { + .link_ops = &replicator_link_ops, +}; + +static int __devinit replicator_probe(struct platform_device *pdev) +{ + int ret; + struct device *dev = &pdev->dev; + struct coresight_platform_data *pdata; + struct replicator_drvdata *drvdata; + struct resource *res; + struct coresight_desc *desc; + + if (pdev->dev.of_node) { + pdata = of_get_coresight_platform_data(dev, pdev->dev.of_node); + if (IS_ERR(pdata)) + return PTR_ERR(pdata); + pdev->dev.platform_data = pdata; + } + + drvdata = devm_kzalloc(dev, sizeof(*drvdata), GFP_KERNEL); + if (!drvdata) + return -ENOMEM; + drvdata->dev = &pdev->dev; + platform_set_drvdata(pdev, drvdata); + + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); + if (!res) + return -ENODEV; + + drvdata->base = devm_ioremap(dev, res->start, resource_size(res)); + if (!drvdata->base) + return -ENOMEM; + + drvdata->clk = devm_clk_get(dev, "core_clk"); + if (IS_ERR(drvdata->clk)) + return PTR_ERR(drvdata->clk); + + ret = clk_set_rate(drvdata->clk, CORESIGHT_CLK_RATE_TRACE); + if (ret) + return ret; + + desc = devm_kzalloc(dev, sizeof(*desc), GFP_KERNEL); + if (!desc) + return -ENOMEM; + desc->type = CORESIGHT_DEV_TYPE_LINK; + desc->subtype.sink_subtype = CORESIGHT_DEV_SUBTYPE_LINK_SPLIT; + desc->ops = &replicator_cs_ops; + desc->pdata = pdev->dev.platform_data; + desc->dev = &pdev->dev; + desc->owner = THIS_MODULE; + drvdata->csdev = coresight_register(desc); + if (IS_ERR(drvdata->csdev)) + return PTR_ERR(drvdata->csdev); + + dev_info(dev, "REPLICATOR initialized\n"); + return 0; +} + +static int __devexit replicator_remove(struct platform_device *pdev) +{ + struct replicator_drvdata *drvdata = platform_get_drvdata(pdev); + + coresight_unregister(drvdata->csdev); + return 0; +} + +static struct of_device_id replicator_match[] = { + {.compatible = "qcom,coresight-replicator"}, + {} +}; + +static struct platform_driver replicator_driver = { + .probe = replicator_probe, + .remove = __devexit_p(replicator_remove), + .driver = { + .name = "coresight-replicator", + .owner = THIS_MODULE, + .of_match_table = replicator_match, + }, +}; + +static int __init replicator_init(void) +{ + return platform_driver_register(&replicator_driver); +} +module_init(replicator_init); + +static void __exit replicator_exit(void) +{ + platform_driver_unregister(&replicator_driver); +} +module_exit(replicator_exit); + +MODULE_LICENSE("GPL v2"); +MODULE_DESCRIPTION("CoreSight Replicator driver");