From patchwork Fri Mar 7 12:16:12 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: R Sricharan X-Patchwork-Id: 3790541 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 03B3A9F369 for ; Fri, 7 Mar 2014 12:21:11 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id BC8DC201BA for ; Fri, 7 Mar 2014 12:21:09 +0000 (UTC) Received: from casper.infradead.org (casper.infradead.org [85.118.1.10]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 28B24202C8 for ; Fri, 7 Mar 2014 12:21:08 +0000 (UTC) Received: from merlin.infradead.org ([2001:4978:20e::2]) by casper.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1WLtjs-0004uV-9E; Fri, 07 Mar 2014 12:18:57 +0000 Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1WLtjO-00076e-4g; Fri, 07 Mar 2014 12:18:26 +0000 Received: from casper.infradead.org ([2001:770:15f::2]) by merlin.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1WLtim-000721-Lo for linux-arm-kernel@merlin.infradead.org; Fri, 07 Mar 2014 12:17:48 +0000 Received: from comal.ext.ti.com ([198.47.26.152]) by casper.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1WLtic-00048p-7z for linux-arm-kernel@lists.infradead.org; Fri, 07 Mar 2014 12:17:40 +0000 Received: from dflxv15.itg.ti.com ([128.247.5.124]) by comal.ext.ti.com (8.13.7/8.13.7) with ESMTP id s27CHAtt032206; Fri, 7 Mar 2014 06:17:10 -0600 Received: from DFLE73.ent.ti.com (dfle73.ent.ti.com [128.247.5.110]) by dflxv15.itg.ti.com (8.14.3/8.13.8) with ESMTP id s27CHA9Z001384; Fri, 7 Mar 2014 06:17:10 -0600 Received: from dflp32.itg.ti.com (10.64.6.15) by DFLE73.ent.ti.com (128.247.5.110) with Microsoft SMTP Server id 14.3.174.1; Fri, 7 Mar 2014 06:17:09 -0600 Received: from localhost.localdomain (ileax41-snat.itg.ti.com [10.172.224.153]) by dflp32.itg.ti.com (8.14.3/8.13.8) with ESMTP id s27CGhw2003967; Fri, 7 Mar 2014 06:17:06 -0600 From: Sricharan R To: , , , , , Subject: [RFC PATCH 5/9] drivers: dma: Add dma crossbar driver Date: Fri, 7 Mar 2014 17:46:12 +0530 Message-ID: <1394194576-23741-6-git-send-email-r.sricharan@ti.com> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1394194576-23741-1-git-send-email-r.sricharan@ti.com> References: <1394194576-23741-1-git-send-email-r.sricharan@ti.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20140307_121738_713542_C86DAFAC X-CRM114-Status: GOOD ( 27.30 ) X-Spam-Score: -6.9 (------) Cc: nm@ti.com, linux@arm.linux.org.uk, tony@atomide.com, rnayak@ti.com, nsekhar@ti.com, vinod.koul@intel.com, santosh.shilimkar@ti.com, dan.j.williams@intel.com X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP DRA7XX dma controller IP's are preceded by a crossbar which routes the dma requests from the peripherals to the dma request input lines of the appropriate dma controller. With this the dma controller's available request lines are shared between the peripherals. The driver maintains a list of free dma request lines and allocates one during the map callback which is invoked as a part the dma engine driver's device_alloc_chan_resources callback. The allocated request line is freed during the device_free_chan_resources. Signed-off-by: Sricharan R --- .../devicetree/bindings/arm/omap/dma-crossbar.txt | 26 +++ drivers/dma/Kconfig | 7 + drivers/dma/Makefile | 1 + drivers/dma/omap-dma-xbar.c | 219 ++++++++++++++++++++ drivers/dma/omap-dma-xbar.h | 32 +++ drivers/dma/omap-dma.c | 1 + 6 files changed, 286 insertions(+) create mode 100644 Documentation/devicetree/bindings/arm/omap/dma-crossbar.txt create mode 100644 drivers/dma/omap-dma-xbar.c create mode 100644 drivers/dma/omap-dma-xbar.h diff --git a/Documentation/devicetree/bindings/arm/omap/dma-crossbar.txt b/Documentation/devicetree/bindings/arm/omap/dma-crossbar.txt new file mode 100644 index 0000000..feac013 --- /dev/null +++ b/Documentation/devicetree/bindings/arm/omap/dma-crossbar.txt @@ -0,0 +1,26 @@ +Some socs have a crossbar ip which muxes the dma requests +from the peripherals to the dma request input lines of the +appropriate dma controller. With this the dma controller's +available request lines are shared between the peripherals + +Required properties: +- compatible : Should be "ti,dma-crossbar" +- reg: Base address and the size of the crossbar registers. +- ti,dma-reqs: Total number of dma request lines available at dma controller. +- ti,reg-size: Size of a individual register in bytes. Every individual + register is assumed to be of same size. Valid sizes are 1, 2, 4. +- ti,dmas-reserved: List of the reserved dma lines that are not muxed using + crossbar. These dma lines are reserved in the soc, + so crossbar bar driver should not consider them as free + lines. This is a table of dma request-number and a count of + reserved values from that number. + +Examples: + crossbar_dma: crossbar@4a020000 { + compatible = "ti,dma-crossbar"; + reg = <0x4a002b78 0x100>; + ti,dma-reqs = <160>; + ti,reg-size = <2>; + ti,dmas-reserved = < 2, 5, + 10, 2 >; + }; diff --git a/drivers/dma/Kconfig b/drivers/dma/Kconfig index 9bed1a2..7e8d3f4 100644 --- a/drivers/dma/Kconfig +++ b/drivers/dma/Kconfig @@ -400,4 +400,11 @@ config DMATEST config DMA_ENGINE_RAID bool +config OMAP_DMA_CROSSBAR + bool "OMAP dma crossbar support" + depends on DMA_OMAP + help + This enables the dma crossbar ip support to dynamically map the + peripheral dma request lines to the dma controller's input. + endif diff --git a/drivers/dma/Makefile b/drivers/dma/Makefile index a029d0f4..d84190e 100644 --- a/drivers/dma/Makefile +++ b/drivers/dma/Makefile @@ -44,3 +44,4 @@ obj-$(CONFIG_DMA_JZ4740) += dma-jz4740.o obj-$(CONFIG_TI_CPPI41) += cppi41.o obj-$(CONFIG_K3_DMA) += k3dma.o obj-$(CONFIG_MOXART_DMA) += moxart-dma.o +obj-$(CONFIG_OMAP_DMA_CROSSBAR) += omap-dma-xbar.o diff --git a/drivers/dma/omap-dma-xbar.c b/drivers/dma/omap-dma-xbar.c new file mode 100644 index 0000000..bed2923 --- /dev/null +++ b/drivers/dma/omap-dma-xbar.c @@ -0,0 +1,219 @@ +/* + * Copyright (C) 2014 Texas Instruments Incorporated - http://www.ti.com + * Author: Sricharan R + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + */ +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "omap-dma-xbar.h" + +static struct platform_device *pd_xbar; + +static void dma_xbar_writeb(int dma_sig, int dma_xbar, + struct dma_xbar_device *xbar) +{ + writeb(dma_xbar, xbar->dma_xbar_base + xbar->reg_offs[dma_sig]); +} + +static void dma_xbar_writew(int dma_sig, int dma_xbar, + struct dma_xbar_device *xbar) +{ + writew(dma_xbar, xbar->dma_xbar_base + xbar->reg_offs[dma_sig]); +} + +static void dma_xbar_writel(int dma_sig, int dma_xbar, + struct dma_xbar_device *xbar) +{ + writel(dma_xbar, xbar->dma_xbar_base + xbar->reg_offs[dma_sig]); +} + +static uint32_t dma_xbar_map(uint32_t dma_xbar, struct dma_xbar_device *xbar) +{ + struct dma_req *r; + uint32_t dma_sig; + + if (!list_empty(&xbar->free_reqs)) + r = list_first_entry(&xbar->free_reqs, struct dma_req, node); + else + return -ENODEV; + + dma_sig = r->req_line; + list_del(&r->node); + + xbar->write(dma_sig - 1, dma_xbar, xbar); + + return dma_sig; +} + +static void dma_xbar_unmap(uint32_t dma_sig, struct dma_xbar_device *xbar) +{ + struct dma_req *r; + + r = devm_kzalloc(&pd_xbar->dev, sizeof(*r), GFP_KERNEL); + r->req_line = dma_sig; + + list_add_tail(&r->node, &xbar->free_reqs); +} + +const struct xbar_ops dma_xbar_ops = { + .map = dma_xbar_map, + .unmap = dma_xbar_unmap, +}; + +static int __init omap_dma_xbar_probe(struct platform_device *pdev) +{ + int i, j, reserved = 0; + const __be32 *dmar; + uint32_t *dma_map, max, size, entry, range; + struct dma_req *p; + struct resource *res; + struct dma_xbar_device *xbar; + + pd_xbar = pdev; + + xbar = devm_kzalloc(&pdev->dev, sizeof(*xbar), GFP_KERNEL); + if (!xbar) + return -ENOMEM; + + xbar->ops = &dma_xbar_ops; + + INIT_LIST_HEAD(&xbar->free_reqs); + + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); + xbar->dma_xbar_base = devm_ioremap_resource(&pdev->dev, res); + if (IS_ERR(xbar->dma_xbar_base)) + return PTR_ERR(xbar->dma_xbar_base); + + of_property_read_u32(pdev->dev.of_node, "ti,dma-reqs", &max); + dma_map = kzalloc(max * sizeof(*dma_map), GFP_KERNEL); + if (!dma_map) + return -ENOMEM; + + /* Get and mark reserved dma req lines */ + dmar = of_get_property(pdev->dev.of_node, "ti,dmas-reserved", &size); + if (dmar) { + size /= sizeof(__be32); + + for (i = 0; i < size; i++) { + of_property_read_u32_index(pdev->dev.of_node, + "ti,dmas-reserved", + i++, &entry); + of_property_read_u32_index(pdev->dev.of_node, + "ti,dmas-reserved", + i, &range); + if ((entry + range > max) || + ((entry + range) <= entry)) { + pr_err("Invalid reserved entry\n"); + return -ENODEV; + } + + for (j = entry; j <= range; j++) + dma_map[j] = 1; + + /* For a single entry */ + if (!range) + dma_map[entry] = 1; + } + } + + /* Add the free dma req lines to free list */ + for (j = 1; j < max; j++) { + if (!dma_map[j]) { + p = devm_kzalloc(&pdev->dev, sizeof(*p), GFP_KERNEL); + p->req_line = j; + list_add_tail(&p->node, &xbar->free_reqs); + } + } + + xbar->reg_offs = devm_kzalloc(&pdev->dev, max * sizeof(int), + GFP_KERNEL); + if (!xbar->reg_offs) + return -ENOMEM; + + of_property_read_u32(pdev->dev.of_node, "ti,reg-size", &size); + + switch (size) { + case 1: + xbar->write = dma_xbar_writeb; + break; + case 2: + xbar->write = dma_xbar_writew; + break; + case 4: + xbar->write = dma_xbar_writel; + break; + default: + pr_err("Invalid reg-size property\n"); + return -ENODEV; + break; + } + + /* + * Register offsets are not linear because of the + * reserved lines. so find and store the offsets once. + */ + for (i = 0; i < max; i++) { + if (dma_map[i]) + continue; + + xbar->reg_offs[i] = reserved; + reserved += size; + } + + if (of_dma_router_register(pdev->dev.of_node, xbar)) + return -ENODEV; + + kfree(dma_map); + return 0; +} + +static int omap_dma_xbar_remove(struct platform_device *pdev) +{ + if (pdev->dev.of_node) + of_dma_router_free(pdev->dev.of_node); + + return 0; +} + +static const struct of_device_id dma_xbar_match[] __initconst = { + { .compatible = "ti,dma-xbar" }, + {}, +}; + +static struct platform_driver omap_dma_xbar_driver = { + .probe = omap_dma_xbar_probe, + .remove = omap_dma_xbar_remove, + .driver = { + .name = "omap-dma-xbar", + .owner = THIS_MODULE, + .of_match_table = of_match_ptr(dma_xbar_match), + }, +}; + +int __init omap_dmaxbar_init(void) +{ + return platform_driver_register(&omap_dma_xbar_driver); +} +arch_initcall(omap_dmaxbar_init); + +static void __exit omap_dmaxbar_exit(void) +{ + platform_driver_unregister(&omap_dma_xbar_driver); +} +module_exit(omap_dmaxbar_exit); + +MODULE_DESCRIPTION("OMAP DMA XBAR"); +MODULE_AUTHOR("Sricharan R"); +MODULE_LICENSE("GPL"); diff --git a/drivers/dma/omap-dma-xbar.h b/drivers/dma/omap-dma-xbar.h new file mode 100644 index 0000000..bd0b208 --- /dev/null +++ b/drivers/dma/omap-dma-xbar.h @@ -0,0 +1,32 @@ +/* + * Copyright (C) 2014 Texas Instruments Incorporated - http://www.ti.com + * Author: Sricharan R + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + */ +struct dma_req { + uint32_t req_line; + struct list_head node; +}; + +/* + * @crossbar_base: crossbar base address + * @register_offsets: offsets for each dma request number + * @write: function to write in to the dma crossbar + * @free_reqs: list of free dma request lines + */ +struct dma_xbar_device { + void __iomem *dma_xbar_base; + int *reg_offs; + void (*write)(int, int, struct dma_xbar_device *); + struct list_head free_reqs; + const struct xbar_ops *ops; +}; + +struct xbar_ops { + uint32_t (*map)(uint32_t, struct dma_xbar_device *); + void (*unmap)(uint32_t, struct dma_xbar_device *); +}; diff --git a/drivers/dma/omap-dma.c b/drivers/dma/omap-dma.c index 05ac480..b527bed 100644 --- a/drivers/dma/omap-dma.c +++ b/drivers/dma/omap-dma.c @@ -21,6 +21,7 @@ #include #include "virt-dma.h" +#include "omap-dma-xbar.h" struct omap_dmadev { struct dma_device ddev;