From patchwork Fri Feb 25 08:45:29 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pratheesh Gangadhar X-Patchwork-Id: 589611 Received: from bear.ext.ti.com (bear.ext.ti.com [192.94.94.41]) by demeter1.kernel.org (8.14.4/8.14.3) with ESMTP id p1P8lagK012096 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Fri, 25 Feb 2011 08:47:56 GMT Received: from dlep33.itg.ti.com ([157.170.170.112]) by bear.ext.ti.com (8.13.7/8.13.7) with ESMTP id p1P8jktj028055 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Fri, 25 Feb 2011 02:45:46 -0600 Received: from linux.omap.com (localhost [127.0.0.1]) by dlep33.itg.ti.com (8.13.7/8.13.7) with ESMTP id p1P8jkj3006103; Fri, 25 Feb 2011 02:45:46 -0600 (CST) Received: from linux.omap.com (localhost [127.0.0.1]) by linux.omap.com (Postfix) with ESMTP id 14A4480627; Fri, 25 Feb 2011 02:45:44 -0600 (CST) X-Original-To: davinci-linux-open-source@linux.davincidsp.com Delivered-To: davinci-linux-open-source@linux.davincidsp.com Received: from dbdp31.itg.ti.com (dbdp31.itg.ti.com [172.24.170.98]) by linux.omap.com (Postfix) with ESMTP id AE3F480626 for ; Fri, 25 Feb 2011 02:45:40 -0600 (CST) Received: from psplinux051.india.ti.com (localhost [127.0.0.1]) by dbdp31.itg.ti.com (8.13.8/8.13.8) with ESMTP id p1P8jXnj010420; Fri, 25 Feb 2011 14:15:33 +0530 (IST) Received: from psplinux051.india.ti.com (localhost [127.0.0.1]) by psplinux051.india.ti.com (8.13.1/8.13.1) with ESMTP id p1P8jWph010511; Fri, 25 Feb 2011 14:15:32 +0530 Received: (from a0875542@localhost) by psplinux051.india.ti.com (8.13.1/8.13.1/Submit) id p1P8jWW9010508; Fri, 25 Feb 2011 14:15:32 +0530 From: Pratheesh Gangadhar To: davinci-linux-open-source@linux.davincidsp.com Subject: [PATCH v5 1/2] PRUSS UIO driver support Date: Fri, 25 Feb 2011 14:15:29 +0530 Message-Id: <1298623530-10294-2-git-send-email-pratheesh@ti.com> X-Mailer: git-send-email 1.6.2.4 In-Reply-To: <1298623530-10294-1-git-send-email-pratheesh@ti.com> References: <1298623530-10294-1-git-send-email-pratheesh@ti.com> Cc: sshtylyov@mvista.com, arnd@arndb.de, amit.chatterjee@ti.com, gregkh@suse.de, linux-kernel@vger.kernel.org, hjk@hansjkoch.de, tglx@linutronix.de, linux-arm-kernel@lists.infradead.org X-BeenThere: davinci-linux-open-source@linux.davincidsp.com X-Mailman-Version: 2.1.12 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: davinci-linux-open-source-bounces@linux.davincidsp.com Errors-To: davinci-linux-open-source-bounces@linux.davincidsp.com X-Greylist: Sender succeeded STARTTLS authentication, not delayed by milter-greylist-4.2.6 (demeter1.kernel.org [140.211.167.41]); Fri, 25 Feb 2011 08:47:57 +0000 (UTC) diff --git a/drivers/uio/Kconfig b/drivers/uio/Kconfig index bb44079..6f3ea9b 100644 --- a/drivers/uio/Kconfig +++ b/drivers/uio/Kconfig @@ -94,4 +94,21 @@ config UIO_NETX To compile this driver as a module, choose M here; the module will be called uio_netx. +config UIO_PRUSS + tristate "Texas Instruments PRUSS driver" + depends on ARCH_DAVINCI_DA850 + help + PRUSS driver for OMAPL138/DA850/AM18XX devices + PRUSS driver requires user space components, examples and user space + driver is available from below SVN repo - you may use anonymous login + + https://gforge.ti.com/gf/project/pru_sw/ + + More info on API is available at below wiki + + http://processors.wiki.ti.com/index.php/PRU_Linux_Application_Loader + + To compile this driver as a module, choose M here: the module + will be called uio_pruss. + endif diff --git a/drivers/uio/Makefile b/drivers/uio/Makefile index 18fd818..d4dd9a5 100644 --- a/drivers/uio/Makefile +++ b/drivers/uio/Makefile @@ -6,3 +6,4 @@ obj-$(CONFIG_UIO_AEC) += uio_aec.o obj-$(CONFIG_UIO_SERCOS3) += uio_sercos3.o obj-$(CONFIG_UIO_PCI_GENERIC) += uio_pci_generic.o obj-$(CONFIG_UIO_NETX) += uio_netx.o +obj-$(CONFIG_UIO_PRUSS) += uio_pruss.o diff --git a/drivers/uio/uio_pruss.c b/drivers/uio/uio_pruss.c new file mode 100644 index 0000000..d17d3aa --- /dev/null +++ b/drivers/uio/uio_pruss.c @@ -0,0 +1,217 @@ +/* + * Programmable Real-Time Unit Sub System (PRUSS) UIO driver (uio_pruss) + * + * This driver exports PRUSS host event out interrupts and PRUSS, L3 RAM, + * and DDR RAM to user space for applications interacting with PRUSS firmware + * + * Copyright (C) 2010-11 Texas Instruments Incorporated - http://www.ti.com/ + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation version 2. + * + * This program is distributed "as is" WITHOUT ANY WARRANTY of any + * kind, whether express or implied; 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 + +#define DRV_NAME "pruss" +#define DRV_VERSION "0.50" + +/* + * Host event IRQ numbers from PRUSS - PRUSS can generate upto 8 interrupt + * events to AINTC of ARM host processor - which can be used for IPC b/w PRUSS + * firmware and user space application, async notification from PRU firmware + * to user space application + * 3 PRU_EVTOUT0 + * 4 PRU_EVTOUT1 + * 5 PRU_EVTOUT2 + * 6 PRU_EVTOUT3 + * 7 PRU_EVTOUT4 + * 8 PRU_EVTOUT5 + * 9 PRU_EVTOUT6 + * 10 PRU_EVTOUT7 +*/ + +#define MAX_PRUSS_EVT 8 + +#define PINTC_HIPIR 0x4900 +#define HIPIR_NOPEND 0x80000000 +#define PINTC_HIER 0x5500 + +static struct clk *pruss_clk; +static struct uio_info *info; +static dma_addr_t ddr_paddr; +static void *ddr_vaddr, *prussio_vaddr; + +static irqreturn_t pruss_handler(int irq, struct uio_info *dev_info) +{ + void __iomem *base = dev_info->mem[0].internal_addr; + void __iomem *intren_reg = base + PINTC_HIER; + void __iomem *intrstat_reg = base + PINTC_HIPIR + ((irq - 1) << 2); + int val = ioread32(intren_reg), intr_mask = (1 << (irq - 1)); + + /* Is interrupt enabled and active ? */ + if (!(val & intr_mask) && (ioread32(intrstat_reg) & HIPIR_NOPEND)) + return IRQ_NONE; + + /* Disable interrupt */ + iowrite32((val & ~intr_mask), intren_reg); + return IRQ_HANDLED; +} + +static void pruss_cleanup(struct platform_device *dev, struct uio_info *info) +{ + struct uio_info *p = info; + int cnt; + + for (cnt = 0; cnt < MAX_PRUSS_EVT; cnt++, p++) { + uio_unregister_device(p); + kfree(p->name); + } + iounmap(prussio_vaddr); + if (ddr_vaddr) { + dma_free_coherent(&dev->dev, info->mem[2].size, + info->mem[2].internal_addr, info->mem[2].addr); + } + kfree(info); + clk_put(pruss_clk); +} + +static int __devinit pruss_probe(struct platform_device *dev) +{ + struct uio_info *p; + int ret = -ENODEV, cnt = 0, len; + struct resource *regs_prussio, *regs_l3ram, *regs_ddr; + + info = kzalloc(sizeof(struct uio_info) * MAX_PRUSS_EVT, GFP_KERNEL); + if (!info) + return -ENOMEM; + /* Power on PRU in case its not done as part of boot-loader */ + pruss_clk = clk_get(&dev->dev, "pruss"); + if (IS_ERR(pruss_clk)) { + dev_err(&dev->dev, "Failed to get clock\n"); + kfree(info); + ret = PTR_ERR(pruss_clk); + return ret; + } else { + clk_enable(pruss_clk); + } + + regs_prussio = platform_get_resource(dev, IORESOURCE_MEM, 0); + if (!regs_prussio) { + dev_err(&dev->dev, "No PRUSS I/O resource specified\n"); + goto out_free; + } + + regs_l3ram = platform_get_resource(dev, IORESOURCE_MEM, 1); + if (!regs_l3ram) { + dev_err(&dev->dev, "No L3 RAM resource specified\n"); + goto out_free; + } + + regs_ddr = platform_get_resource(dev, IORESOURCE_MEM, 2); + if (!regs_ddr) { + dev_err(&dev->dev, "No External RAM resource specified\n"); + goto out_free; + } + + if (!regs_prussio->start || !regs_l3ram->start) { + dev_err(&dev->dev, "Invalid memory resource\n"); + goto out_free; + } + len = resource_size(regs_ddr); + ddr_vaddr = dma_alloc_coherent(&dev->dev, len, &ddr_paddr, + GFP_KERNEL | GFP_DMA); + if (!ddr_vaddr) { + dev_err(&dev->dev, "Could not allocate external memory\n"); + goto out_free; + } + len = resource_size(regs_prussio); + prussio_vaddr = ioremap(regs_prussio->start, len); + if (!prussio_vaddr) { + dev_err(&dev->dev, "Can't remap PRUSS I/O address range\n"); + goto out_free; + } + + for (cnt = 0, p = info; cnt < MAX_PRUSS_EVT; cnt++, p++) { + p->mem[0].internal_addr = prussio_vaddr; + p->mem[0].addr = regs_prussio->start; + p->mem[0].size = resource_size(regs_prussio); + p->mem[0].memtype = UIO_MEM_PHYS; + + p->mem[1].addr = regs_l3ram->start; + p->mem[1].size = resource_size(regs_l3ram); + p->mem[1].memtype = UIO_MEM_PHYS; + + p->mem[2].internal_addr = ddr_vaddr; + p->mem[2].addr = ddr_paddr; + p->mem[2].size = resource_size(regs_ddr); + p->mem[2].memtype = UIO_MEM_PHYS; + + p->name = kasprintf(GFP_KERNEL, "pruss_evt%d", cnt); + p->version = "0.50"; + + /* Register PRUSS IRQ lines */ + p->irq = IRQ_DA8XX_EVTOUT0 + cnt; + p->handler = pruss_handler; + + ret = uio_register_device(&dev->dev, p); + + if (ret < 0) + goto out_free; + } + + platform_set_drvdata(dev, info); + return 0; + +out_free: + pruss_cleanup(dev, info); + return ret; +} + +static int __devexit pruss_remove(struct platform_device *dev) +{ + struct uio_info *info = platform_get_drvdata(dev); + + pruss_cleanup(dev, info); + platform_set_drvdata(dev, NULL); + return 0; +} + +static struct platform_driver pruss_driver = { + .probe = pruss_probe, + .remove = __devexit_p(pruss_remove), + .driver = { + .name = DRV_NAME, + .owner = THIS_MODULE, + }, +}; + +static int __init pruss_init_module(void) +{ + return platform_driver_register(&pruss_driver); +} + +module_init(pruss_init_module); + +static void __exit pruss_exit_module(void) +{ + platform_driver_unregister(&pruss_driver); +} + +module_exit(pruss_exit_module); + +MODULE_LICENSE("GPL v2"); +MODULE_VERSION(DRV_VERSION); +MODULE_AUTHOR("Amit Chatterjee "); +MODULE_AUTHOR("Pratheesh Gangadhar ");