From patchwork Fri May 30 13:43:03 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Poirier X-Patchwork-Id: 31182 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ob0-f200.google.com (mail-ob0-f200.google.com [209.85.214.200]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 0DE3C20671 for ; Fri, 30 May 2014 13:43:49 +0000 (UTC) Received: by mail-ob0-f200.google.com with SMTP id wo20sf8618523obc.11 for ; Fri, 30 May 2014 06:43:49 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:in-reply-to:references:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :list-post:list-help:list-archive:list-unsubscribe; bh=tQNN99XlX7nWEn8FgPVlFZlQbk1QGhwarBywKkxOT5Y=; b=jO8cPeXrH2gUdAPbFPBut3Ql64pxjN1TDOhXw+L71+VT0XVgMb+lM/1sPMfl31zG/V U/eMIl/SGvipREWqJ/eknHJ7pgvSyvGLsWq9TFyPbo4SPIAUVUeXKueLZC8eo+4v+uHg uNE4Ww7fPCOKyK1JfSdVAb0tXJ1M0x0W6+wjB8IGLtccGSUJoNpqve7is6NsqImng9lQ Y55yBNL+LeHzzDxPlQkvmZZg7SU3ZSGI3YEkh9ND+X0bNv7ETDb4KZe761ebCgEyVSym H9MXKR2cTLjs+flEdqHH4B8LKZJngD06N+W98UxU5DJjusYO9aJTHVGQqLFBM1xXl1vj w4eQ== X-Gm-Message-State: ALoCoQnAim5pZizjmzuRKIneo2X5y1rFVZK4dRpPzMnOfx26nC2h+f9ybbHR8qgHH7fvUVTXyAYB X-Received: by 10.182.19.231 with SMTP id i7mr6398285obe.25.1401457429595; Fri, 30 May 2014 06:43:49 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.23.7 with SMTP id 7ls1007036qgo.60.gmail; Fri, 30 May 2014 06:43:49 -0700 (PDT) X-Received: by 10.221.42.135 with SMTP id ty7mr13996495vcb.14.1401457429459; Fri, 30 May 2014 06:43:49 -0700 (PDT) Received: from mail-ve0-f179.google.com (mail-ve0-f179.google.com [209.85.128.179]) by mx.google.com with ESMTPS id ek8si3052709vdc.87.2014.05.30.06.43.49 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 30 May 2014 06:43:49 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.128.179 as permitted sender) client-ip=209.85.128.179; Received: by mail-ve0-f179.google.com with SMTP id oy12so2097716veb.24 for ; Fri, 30 May 2014 06:43:49 -0700 (PDT) X-Received: by 10.58.2.74 with SMTP id 10mr1227319ves.61.1401457429369; Fri, 30 May 2014 06:43:49 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patches@linaro.org Received: by 10.220.221.72 with SMTP id ib8csp113429vcb; Fri, 30 May 2014 06:43:48 -0700 (PDT) X-Received: by 10.67.1.39 with SMTP id bd7mr19014832pad.15.1401457428575; Fri, 30 May 2014 06:43:48 -0700 (PDT) Received: from mail-pb0-f54.google.com (mail-pb0-f54.google.com [209.85.160.54]) by mx.google.com with ESMTPS id pk9si5629405pac.234.2014.05.30.06.43.48 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 30 May 2014 06:43:48 -0700 (PDT) Received-SPF: pass (google.com: domain of mathieu.poirier@linaro.org designates 209.85.160.54 as permitted sender) client-ip=209.85.160.54; Received: by mail-pb0-f54.google.com with SMTP id jt11so1752410pbb.27 for ; Fri, 30 May 2014 06:43:48 -0700 (PDT) X-Received: by 10.68.113.68 with SMTP id iw4mr18114858pbb.119.1401457428179; Fri, 30 May 2014 06:43:48 -0700 (PDT) Received: from t430.cg.shawcable.net (S0106002369de4dac.cg.shawcable.net. [70.73.24.112]) by mx.google.com with ESMTPSA id fe2sm6533558pbc.68.2014.05.30.06.43.45 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 30 May 2014 06:43:47 -0700 (PDT) From: mathieu.poirier@linaro.org To: linus.walleij@linaro.org, will.deacon@arm.com Cc: mathieu.poirier@linaro.org, arve@android.com, john.stultz@linaro.org, pratikp@codeaurora.org, varshney@ti.com, Al.Grant@arm.com, jonas.svennebring@avagotech.com, james.king@linaro.org, panchaxari.prasannamurthy@linaro.org, arnd@linaro.org, marcin.jabrzyk@gmail.com, r.sengupta@samsung.com, robbelibobban@gmail.com, patches@linaro.org, linux@arm.linux.org.uk, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, daniel.thompson@linaro.org Subject: [RFC PATCH 03/11] coresight: add CoreSight TPIU driver Date: Fri, 30 May 2014 07:43:03 -0600 Message-Id: <1401457391-12242-4-git-send-email-mathieu.poirier@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1401457391-12242-1-git-send-email-mathieu.poirier@linaro.org> References: <1401457391-12242-1-git-send-email-mathieu.poirier@linaro.org> X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: mathieu.poirier@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.128.179 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Precedence: list Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org List-ID: X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , From: Pratik Patel This driver manages CoreSight TPIU (Trace Port Interface Unit) which acts as a sink. TPIU is typically connected to some offchip hardware hosting a storage buffer. Signed-off-by: Pratik Patel Signed-off-by: Panchaxari Prasannamurthy Signed-off-by: Mathieu Poirier --- drivers/coresight/Makefile | 2 +- drivers/coresight/coresight-tpiu.c | 229 +++++++++++++++++++++++++++++++++++++ 2 files changed, 230 insertions(+), 1 deletion(-) create mode 100644 drivers/coresight/coresight-tpiu.c diff --git a/drivers/coresight/Makefile b/drivers/coresight/Makefile index 16e26c5..540df99 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 +obj-$(CONFIG_CORESIGHT_LINKS_AND_SINKS) += coresight-tmc.o coresight-tpiu.o diff --git a/drivers/coresight/coresight-tpiu.c b/drivers/coresight/coresight-tpiu.c new file mode 100644 index 0000000..b552d1e --- /dev/null +++ b/drivers/coresight/coresight-tpiu.c @@ -0,0 +1,229 @@ +/* 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 tpiu_writel(drvdata, val, off) __raw_writel((val), drvdata->base + off) +#define tpiu_readl(drvdata, off) __raw_readl(drvdata->base + off) + +#define TPIU_LOCK(drvdata) \ +do { \ + /* wait for things to settle */ \ + mb(); \ + tpiu_writel(drvdata, 0x0, CORESIGHT_LAR); \ +} while (0) +#define TPIU_UNLOCK(drvdata) \ +do { \ + tpiu_writel(drvdata, CORESIGHT_UNLOCK, CORESIGHT_LAR); \ + /* make sure everyone has seen this */ \ + mb(); \ +} while (0) + +#define TPIU_SUPP_PORTSZ (0x000) +#define TPIU_CURR_PORTSZ (0x004) +#define TPIU_SUPP_TRIGMODES (0x100) +#define TPIU_TRIG_CNTRVAL (0x104) +#define TPIU_TRIG_MULT (0x108) +#define TPIU_SUPP_TESTPATM (0x200) +#define TPIU_CURR_TESTPATM (0x204) +#define TPIU_TEST_PATREPCNTR (0x208) +#define TPIU_FFSR (0x300) +#define TPIU_FFCR (0x304) +#define TPIU_FSYNC_CNTR (0x308) +#define TPIU_EXTCTL_INPORT (0x400) +#define TPIU_EXTCTL_OUTPORT (0x404) +#define TPIU_ITTRFLINACK (0xEE4) +#define TPIU_ITTRFLIN (0xEE8) +#define TPIU_ITATBDATA0 (0xEEC) +#define TPIU_ITATBCTR2 (0xEF0) +#define TPIU_ITATBCTR1 (0xEF4) +#define TPIU_ITATBCTR0 (0xEF8) + +struct tpiu_drvdata { + void __iomem *base; + struct device *dev; + struct coresight_device *csdev; + struct clk *clk; +}; + +static void __tpiu_enable(struct tpiu_drvdata *drvdata) +{ + TPIU_UNLOCK(drvdata); + + /* TODO: fill this up */ + + TPIU_LOCK(drvdata); +} + +static int tpiu_enable(struct coresight_device *csdev) +{ + struct tpiu_drvdata *drvdata = dev_get_drvdata(csdev->dev.parent); + int ret; + + ret = clk_prepare_enable(drvdata->clk); + if (ret) + return ret; + + __tpiu_enable(drvdata); + + dev_info(drvdata->dev, "TPIU enabled\n"); + return 0; +} + +static void __tpiu_disable(struct tpiu_drvdata *drvdata) +{ + TPIU_UNLOCK(drvdata); + + tpiu_writel(drvdata, 0x3000, TPIU_FFCR); + tpiu_writel(drvdata, 0x3040, TPIU_FFCR); + + TPIU_LOCK(drvdata); +} + +static void tpiu_disable(struct coresight_device *csdev) +{ + struct tpiu_drvdata *drvdata = dev_get_drvdata(csdev->dev.parent); + + __tpiu_disable(drvdata); + + clk_disable_unprepare(drvdata->clk); + + dev_info(drvdata->dev, "TPIU disabled\n"); +} + +static void tpiu_abort(struct coresight_device *csdev) +{ + struct tpiu_drvdata *drvdata = dev_get_drvdata(csdev->dev.parent); + + __tpiu_disable(drvdata); + + dev_info(drvdata->dev, "TPIU aborted\n"); +} + +static const struct coresight_ops_sink tpiu_sink_ops = { + .enable = tpiu_enable, + .disable = tpiu_disable, + .abort = tpiu_abort, +}; + +static const struct coresight_ops tpiu_cs_ops = { + .sink_ops = &tpiu_sink_ops, +}; + +static int tpiu_probe(struct platform_device *pdev) +{ + int ret; + struct device *dev = &pdev->dev; + struct coresight_platform_data *pdata = NULL; + struct tpiu_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; + + if (pdata && pdata->clk) { + drvdata->clk = pdata->clk; + ret = clk_prepare_enable(drvdata->clk); + if (ret) + return ret; + } + + /* Disable tpiu to support older devices */ + __tpiu_disable(drvdata); + + clk_disable_unprepare(drvdata->clk); + + desc = devm_kzalloc(dev, sizeof(*desc), GFP_KERNEL); + if (!desc) + return -ENOMEM; + desc->type = CORESIGHT_DEV_TYPE_SINK; + desc->subtype.sink_subtype = CORESIGHT_DEV_SUBTYPE_SINK_PORT; + desc->ops = &tpiu_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, "TPIU initialized\n"); + return 0; +} + +static int tpiu_remove(struct platform_device *pdev) +{ + struct tpiu_drvdata *drvdata = platform_get_drvdata(pdev); + + coresight_unregister(drvdata->csdev); + return 0; +} + +static struct of_device_id tpiu_match[] = { + {.compatible = "arm,coresight-tpiu"}, + {} +}; + +static struct platform_driver tpiu_driver = { + .probe = tpiu_probe, + .remove = tpiu_remove, + .driver = { + .name = "coresight-tpiu", + .owner = THIS_MODULE, + .of_match_table = tpiu_match, + }, +}; + +static int __init tpiu_init(void) +{ + return platform_driver_register(&tpiu_driver); +} +module_init(tpiu_init); + +static void __exit tpiu_exit(void) +{ + platform_driver_unregister(&tpiu_driver); +} +module_exit(tpiu_exit); + +MODULE_LICENSE("GPL v2"); +MODULE_DESCRIPTION("CoreSight Trace Port Interface Unit driver");