From patchwork Tue Dec 18 19:19:22 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pratik Patel X-Patchwork-Id: 1906361 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) by patchwork2.kernel.org (Postfix) with ESMTP id 430FCDFB79 for ; Sat, 22 Dec 2012 20:49:10 +0000 (UTC) Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.76 #1 (Red Hat Linux)) id 1TmVx7-00077H-Bx; Sat, 22 Dec 2012 20:45:49 +0000 Received: from wolverine01.qualcomm.com ([199.106.114.254]) by merlin.infradead.org with esmtps (Exim 4.76 #1 (Red Hat Linux)) id 1Tl2nP-0002oS-WE 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="14924755" Received: from pdmz-ns-mip.qualcomm.com (HELO mostmsg01.qualcomm.com) ([199.106.114.10]) 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 D731A10004D7; Tue, 18 Dec 2012 11:25:38 -0800 (PST) From: pratikp@codeaurora.org To: linux-arm-kernel@lists.infradead.org Subject: [RFC 5/8] coresight: add CoreSight Funnel driver Date: Tue, 18 Dec 2012 11:19:22 -0800 Message-Id: <1355858365-11849-6-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_142544_451245_8C09836B X-CRM114-Status: GOOD ( 16.59 ) 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 Funnel which acts as a link. Funnels have multiple input ports (typically 8) each of which represents an input trace data stream. These multiple input trace data streams are interleaved into a single output stream coming out of the Funnel. Signed-off-by: Pratik Patel --- drivers/coresight/Makefile | 2 +- drivers/coresight/coresight-funnel.c | 260 ++++++++++++++++++++++++++++++++++ 2 files changed, 261 insertions(+), 1 deletions(-) create mode 100644 drivers/coresight/coresight-funnel.c diff --git a/drivers/coresight/Makefile b/drivers/coresight/Makefile index 3c1debc..9f84ad0 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 +obj-$(CONFIG_CORESIGHT_LINKS_AND_SINKS) += coresight-tmc.o coresight-tpiu.o coresight-etb.o coresight-funnel.o diff --git a/drivers/coresight/coresight-funnel.c b/drivers/coresight/coresight-funnel.c new file mode 100644 index 0000000..7f39a3e --- /dev/null +++ b/drivers/coresight/coresight-funnel.c @@ -0,0 +1,260 @@ +/* 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 + +#include "coresight-priv.h" + +#define funnel_writel(drvdata, val, off) \ + __raw_writel((val), drvdata->base + off) +#define funnel_readl(drvdata, off) \ + __raw_readl(drvdata->base + off) + +#define FUNNEL_LOCK(drvdata) \ +do { \ + mb(); \ + funnel_writel(drvdata, 0x0, CORESIGHT_LAR); \ +} while (0) +#define FUNNEL_UNLOCK(drvdata) \ +do { \ + funnel_writel(drvdata, CORESIGHT_UNLOCK, CORESIGHT_LAR); \ + mb(); \ +} while (0) + +#define FUNNEL_FUNCTL (0x000) +#define FUNNEL_PRICTL (0x004) +#define FUNNEL_ITATBDATA0 (0xEEC) +#define FUNNEL_ITATBCTR2 (0xEF0) +#define FUNNEL_ITATBCTR1 (0xEF4) +#define FUNNEL_ITATBCTR0 (0xEF8) + +#define FUNNEL_HOLDTIME_MASK (0xF00) +#define FUNNEL_HOLDTIME_SHFT (0x8) +#define FUNNEL_HOLDTIME (0x7 << FUNNEL_HOLDTIME_SHFT) + +struct funnel_drvdata { + void __iomem *base; + struct device *dev; + struct coresight_device *csdev; + struct clk *clk; + uint32_t priority; +}; + +static void __funnel_enable(struct funnel_drvdata *drvdata, int port) +{ + uint32_t functl; + + FUNNEL_UNLOCK(drvdata); + + functl = funnel_readl(drvdata, FUNNEL_FUNCTL); + functl &= ~FUNNEL_HOLDTIME_MASK; + functl |= FUNNEL_HOLDTIME; + functl |= (1 << port); + funnel_writel(drvdata, functl, FUNNEL_FUNCTL); + funnel_writel(drvdata, drvdata->priority, FUNNEL_PRICTL); + + FUNNEL_LOCK(drvdata); +} + +static int funnel_enable(struct coresight_device *csdev, int inport, + int outport) +{ + struct funnel_drvdata *drvdata = dev_get_drvdata(csdev->dev.parent); + int ret; + + ret = clk_prepare_enable(drvdata->clk); + if (ret) + return ret; + + __funnel_enable(drvdata, inport); + + dev_info(drvdata->dev, "FUNNEL inport %d enabled\n", inport); + return 0; +} + +static void __funnel_disable(struct funnel_drvdata *drvdata, int inport) +{ + uint32_t functl; + + FUNNEL_UNLOCK(drvdata); + + functl = funnel_readl(drvdata, FUNNEL_FUNCTL); + functl &= ~(1 << inport); + funnel_writel(drvdata, functl, FUNNEL_FUNCTL); + + FUNNEL_LOCK(drvdata); +} + +static void funnel_disable(struct coresight_device *csdev, int inport, + int outport) +{ + struct funnel_drvdata *drvdata = dev_get_drvdata(csdev->dev.parent); + + __funnel_disable(drvdata, inport); + + clk_disable_unprepare(drvdata->clk); + + dev_info(drvdata->dev, "FUNNEL inport %d disabled\n", inport); +} + +static const struct coresight_ops_link funnel_link_ops = { + .enable = funnel_enable, + .disable = funnel_disable, +}; + +static const struct coresight_ops funnel_cs_ops = { + .link_ops = &funnel_link_ops, +}; + +static ssize_t funnel_show_priority(struct device *dev, + struct device_attribute *attr, char *buf) +{ + struct funnel_drvdata *drvdata = dev_get_drvdata(dev->parent); + unsigned long val = drvdata->priority; + + return scnprintf(buf, PAGE_SIZE, "%#lx\n", val); +} + +static ssize_t funnel_store_priority(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t size) +{ + struct funnel_drvdata *drvdata = dev_get_drvdata(dev->parent); + unsigned long val; + + if (sscanf(buf, "%lx", &val) != 1) + return -EINVAL; + + drvdata->priority = val; + return size; +} +static DEVICE_ATTR(priority, S_IRUGO | S_IWUSR, funnel_show_priority, + funnel_store_priority); + +static struct attribute *funnel_attrs[] = { + &dev_attr_priority.attr, + NULL, +}; + +static struct attribute_group funnel_attr_grp = { + .attrs = funnel_attrs, +}; + +static const struct attribute_group *funnel_attr_grps[] = { + &funnel_attr_grp, + NULL, +}; + +static int __devinit funnel_probe(struct platform_device *pdev) +{ + int ret; + struct device *dev = &pdev->dev; + struct coresight_platform_data *pdata; + struct funnel_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.link_subtype = CORESIGHT_DEV_SUBTYPE_LINK_MERG; + desc->ops = &funnel_cs_ops; + desc->pdata = pdev->dev.platform_data; + desc->dev = &pdev->dev; + desc->groups = funnel_attr_grps; + desc->owner = THIS_MODULE; + drvdata->csdev = coresight_register(desc); + if (IS_ERR(drvdata->csdev)) + return PTR_ERR(drvdata->csdev); + + dev_info(dev, "FUNNEL initialized\n"); + return 0; +} + +static int __devexit funnel_remove(struct platform_device *pdev) +{ + struct funnel_drvdata *drvdata = platform_get_drvdata(pdev); + + coresight_unregister(drvdata->csdev); + return 0; +} + +static struct of_device_id funnel_match[] = { + {.compatible = "arm,coresight-funnel"}, + {} +}; + +static struct platform_driver funnel_driver = { + .probe = funnel_probe, + .remove = __devexit_p(funnel_remove), + .driver = { + .name = "coresight-funnel", + .owner = THIS_MODULE, + .of_match_table = funnel_match, + }, +}; + +static int __init funnel_init(void) +{ + return platform_driver_register(&funnel_driver); +} +module_init(funnel_init); + +static void __exit funnel_exit(void) +{ + platform_driver_unregister(&funnel_driver); +} +module_exit(funnel_exit); + +MODULE_LICENSE("GPL v2"); +MODULE_DESCRIPTION("CoreSight Funnel driver");