aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPratheesh Gangadhar <pratheesh@ti.com>2011-03-04 18:00:17 -0500
committerGreg Kroah-Hartman <gregkh@suse.de>2011-03-07 16:10:27 -0500
commitf1a304e7941cc76353363a139cbb6a4b1ca7c737 (patch)
treeac29bd04bc7c16ddcf612d10efbf7db14b3d5fb9
parentb7e14fea4413440b9054b7fb1628bb9c545c509c (diff)
UIO: add PRUSS UIO driver support
This patch implements PRUSS (Programmable Real-time Unit Sub System) UIO driver which exports SOC resources associated with PRUSS like I/O, memories and IRQs to user space. PRUSS is dual 32-bit RISC processors which is efficient in performing embedded tasks that require manipulation of packed memory mapped data structures and handling system events that have tight real time constraints. This driver is currently supported on Texas Instruments DA850, AM18xx and OMAP-L138 devices. For example, PRUSS runs firmware for real-time critical industrial communication data link layer and communicates with application stack running in user space via shared memory and IRQs. Signed-off-by: Pratheesh Gangadhar <pratheesh@ti.com> Reviewed-by: Thomas Gleixner <tglx@linutronix.de> Reviewed-by: Arnd Bergmann <arnd@arndb.de> Signed-off-by: Hans J. Koch <hjk@hansjkoch.de> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
-rw-r--r--drivers/uio/Kconfig17
-rw-r--r--drivers/uio/Makefile1
-rw-r--r--drivers/uio/uio_pruss.c247
-rw-r--r--include/linux/platform_data/uio_pruss.h25
4 files changed, 290 insertions, 0 deletions
diff --git a/drivers/uio/Kconfig b/drivers/uio/Kconfig
index bb440792a1b7..6f3ea9bbc818 100644
--- a/drivers/uio/Kconfig
+++ b/drivers/uio/Kconfig
@@ -94,4 +94,21 @@ config UIO_NETX
94 To compile this driver as a module, choose M here; the module 94 To compile this driver as a module, choose M here; the module
95 will be called uio_netx. 95 will be called uio_netx.
96 96
97config UIO_PRUSS
98 tristate "Texas Instruments PRUSS driver"
99 depends on ARCH_DAVINCI_DA850
100 help
101 PRUSS driver for OMAPL138/DA850/AM18XX devices
102 PRUSS driver requires user space components, examples and user space
103 driver is available from below SVN repo - you may use anonymous login
104
105 https://gforge.ti.com/gf/project/pru_sw/
106
107 More info on API is available at below wiki
108
109 http://processors.wiki.ti.com/index.php/PRU_Linux_Application_Loader
110
111 To compile this driver as a module, choose M here: the module
112 will be called uio_pruss.
113
97endif 114endif
diff --git a/drivers/uio/Makefile b/drivers/uio/Makefile
index 18fd818c5b97..d4dd9a5552f8 100644
--- a/drivers/uio/Makefile
+++ b/drivers/uio/Makefile
@@ -6,3 +6,4 @@ obj-$(CONFIG_UIO_AEC) += uio_aec.o
6obj-$(CONFIG_UIO_SERCOS3) += uio_sercos3.o 6obj-$(CONFIG_UIO_SERCOS3) += uio_sercos3.o
7obj-$(CONFIG_UIO_PCI_GENERIC) += uio_pci_generic.o 7obj-$(CONFIG_UIO_PCI_GENERIC) += uio_pci_generic.o
8obj-$(CONFIG_UIO_NETX) += uio_netx.o 8obj-$(CONFIG_UIO_NETX) += uio_netx.o
9obj-$(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 000000000000..daf6e77de2b1
--- /dev/null
+++ b/drivers/uio/uio_pruss.c
@@ -0,0 +1,247 @@
1/*
2 * Programmable Real-Time Unit Sub System (PRUSS) UIO driver (uio_pruss)
3 *
4 * This driver exports PRUSS host event out interrupts and PRUSS, L3 RAM,
5 * and DDR RAM to user space for applications interacting with PRUSS firmware
6 *
7 * Copyright (C) 2010-11 Texas Instruments Incorporated - http://www.ti.com/
8 *
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License as
11 * published by the Free Software Foundation version 2.
12 *
13 * This program is distributed "as is" WITHOUT ANY WARRANTY of any
14 * kind, whether express or implied; without even the implied warranty
15 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 */
18#include <linux/device.h>
19#include <linux/module.h>
20#include <linux/moduleparam.h>
21#include <linux/platform_device.h>
22#include <linux/uio_driver.h>
23#include <linux/platform_data/uio_pruss.h>
24#include <linux/io.h>
25#include <linux/clk.h>
26#include <linux/dma-mapping.h>
27#include <linux/slab.h>
28#include <mach/sram.h>
29
30#define DRV_NAME "pruss_uio"
31#define DRV_VERSION "1.0"
32
33static int sram_pool_sz = SZ_16K;
34module_param(sram_pool_sz, int, 0);
35MODULE_PARM_DESC(sram_pool_sz, "sram pool size to allocate ");
36
37static int extram_pool_sz = SZ_256K;
38module_param(extram_pool_sz, int, 0);
39MODULE_PARM_DESC(extram_pool_sz, "external ram pool size to allocate");
40
41/*
42 * Host event IRQ numbers from PRUSS - PRUSS can generate upto 8 interrupt
43 * events to AINTC of ARM host processor - which can be used for IPC b/w PRUSS
44 * firmware and user space application, async notification from PRU firmware
45 * to user space application
46 * 3 PRU_EVTOUT0
47 * 4 PRU_EVTOUT1
48 * 5 PRU_EVTOUT2
49 * 6 PRU_EVTOUT3
50 * 7 PRU_EVTOUT4
51 * 8 PRU_EVTOUT5
52 * 9 PRU_EVTOUT6
53 * 10 PRU_EVTOUT7
54*/
55#define MAX_PRUSS_EVT 8
56
57#define PINTC_HIDISR 0x0038
58#define PINTC_HIPIR 0x0900
59#define HIPIR_NOPEND 0x80000000
60#define PINTC_HIER 0x1500
61
62struct uio_pruss_dev {
63 struct uio_info *info;
64 struct clk *pruss_clk;
65 dma_addr_t sram_paddr;
66 dma_addr_t ddr_paddr;
67 void __iomem *prussio_vaddr;
68 void *sram_vaddr;
69 void *ddr_vaddr;
70 unsigned int hostirq_start;
71 unsigned int pintc_base;
72};
73
74static irqreturn_t pruss_handler(int irq, struct uio_info *info)
75{
76 struct uio_pruss_dev *gdev = info->priv;
77 int intr_bit = (irq - gdev->hostirq_start + 2);
78 int val, intr_mask = (1 << intr_bit);
79 void __iomem *base = gdev->prussio_vaddr + gdev->pintc_base;
80 void __iomem *intren_reg = base + PINTC_HIER;
81 void __iomem *intrdis_reg = base + PINTC_HIDISR;
82 void __iomem *intrstat_reg = base + PINTC_HIPIR + (intr_bit << 2);
83
84 val = ioread32(intren_reg);
85 /* Is interrupt enabled and active ? */
86 if (!(val & intr_mask) && (ioread32(intrstat_reg) & HIPIR_NOPEND))
87 return IRQ_NONE;
88 /* Disable interrupt */
89 iowrite32(intr_bit, intrdis_reg);
90 return IRQ_HANDLED;
91}
92
93static void pruss_cleanup(struct platform_device *dev,
94 struct uio_pruss_dev *gdev)
95{
96 int cnt;
97 struct uio_info *p = gdev->info;
98
99 for (cnt = 0; cnt < MAX_PRUSS_EVT; cnt++, p++) {
100 uio_unregister_device(p);
101 kfree(p->name);
102 }
103 iounmap(gdev->prussio_vaddr);
104 if (gdev->ddr_vaddr) {
105 dma_free_coherent(&dev->dev, extram_pool_sz, gdev->ddr_vaddr,
106 gdev->ddr_paddr);
107 }
108 if (gdev->sram_vaddr)
109 sram_free(gdev->sram_vaddr, sram_pool_sz);
110 kfree(gdev->info);
111 clk_put(gdev->pruss_clk);
112 kfree(gdev);
113}
114
115static int __devinit pruss_probe(struct platform_device *dev)
116{
117 struct uio_info *p;
118 struct uio_pruss_dev *gdev;
119 struct resource *regs_prussio;
120 int ret = -ENODEV, cnt = 0, len;
121 struct uio_pruss_pdata *pdata = dev->dev.platform_data;
122
123 gdev = kzalloc(sizeof(struct uio_pruss_dev), GFP_KERNEL);
124 if (!gdev)
125 return -ENOMEM;
126
127 gdev->info = kzalloc(sizeof(*p) * MAX_PRUSS_EVT, GFP_KERNEL);
128 if (!gdev->info) {
129 kfree(gdev);
130 return -ENOMEM;
131 }
132 /* Power on PRU in case its not done as part of boot-loader */
133 gdev->pruss_clk = clk_get(&dev->dev, "pruss");
134 if (IS_ERR(gdev->pruss_clk)) {
135 dev_err(&dev->dev, "Failed to get clock\n");
136 kfree(gdev->info);
137 kfree(gdev);
138 ret = PTR_ERR(gdev->pruss_clk);
139 return ret;
140 } else {
141 clk_enable(gdev->pruss_clk);
142 }
143
144 regs_prussio = platform_get_resource(dev, IORESOURCE_MEM, 0);
145 if (!regs_prussio) {
146 dev_err(&dev->dev, "No PRUSS I/O resource specified\n");
147 goto out_free;
148 }
149
150 if (!regs_prussio->start) {
151 dev_err(&dev->dev, "Invalid memory resource\n");
152 goto out_free;
153 }
154
155 gdev->sram_vaddr = sram_alloc(sram_pool_sz, &(gdev->sram_paddr));
156 if (!gdev->sram_vaddr) {
157 dev_err(&dev->dev, "Could not allocate SRAM pool\n");
158 goto out_free;
159 }
160
161 gdev->ddr_vaddr = dma_alloc_coherent(&dev->dev, extram_pool_sz,
162 &(gdev->ddr_paddr), GFP_KERNEL | GFP_DMA);
163 if (!gdev->ddr_vaddr) {
164 dev_err(&dev->dev, "Could not allocate external memory\n");
165 goto out_free;
166 }
167
168 len = resource_size(regs_prussio);
169 gdev->prussio_vaddr = ioremap(regs_prussio->start, len);
170 if (!gdev->prussio_vaddr) {
171 dev_err(&dev->dev, "Can't remap PRUSS I/O address range\n");
172 goto out_free;
173 }
174
175 gdev->pintc_base = pdata->pintc_base;
176 gdev->hostirq_start = platform_get_irq(dev, 0);
177
178 for (cnt = 0, p = gdev->info; cnt < MAX_PRUSS_EVT; cnt++, p++) {
179 p->mem[0].addr = regs_prussio->start;
180 p->mem[0].size = resource_size(regs_prussio);
181 p->mem[0].memtype = UIO_MEM_PHYS;
182
183 p->mem[1].addr = gdev->sram_paddr;
184 p->mem[1].size = sram_pool_sz;
185 p->mem[1].memtype = UIO_MEM_PHYS;
186
187 p->mem[2].addr = gdev->ddr_paddr;
188 p->mem[2].size = extram_pool_sz;
189 p->mem[2].memtype = UIO_MEM_PHYS;
190
191 p->name = kasprintf(GFP_KERNEL, "pruss_evt%d", cnt);
192 p->version = DRV_VERSION;
193
194 /* Register PRUSS IRQ lines */
195 p->irq = gdev->hostirq_start + cnt;
196 p->handler = pruss_handler;
197 p->priv = gdev;
198
199 ret = uio_register_device(&dev->dev, p);
200 if (ret < 0)
201 goto out_free;
202 }
203
204 platform_set_drvdata(dev, gdev);
205 return 0;
206
207out_free:
208 pruss_cleanup(dev, gdev);
209 return ret;
210}
211
212static int __devexit pruss_remove(struct platform_device *dev)
213{
214 struct uio_pruss_dev *gdev = platform_get_drvdata(dev);
215
216 pruss_cleanup(dev, gdev);
217 platform_set_drvdata(dev, NULL);
218 return 0;
219}
220
221static struct platform_driver pruss_driver = {
222 .probe = pruss_probe,
223 .remove = __devexit_p(pruss_remove),
224 .driver = {
225 .name = DRV_NAME,
226 .owner = THIS_MODULE,
227 },
228};
229
230static int __init pruss_init_module(void)
231{
232 return platform_driver_register(&pruss_driver);
233}
234
235module_init(pruss_init_module);
236
237static void __exit pruss_exit_module(void)
238{
239 platform_driver_unregister(&pruss_driver);
240}
241
242module_exit(pruss_exit_module);
243
244MODULE_LICENSE("GPL v2");
245MODULE_VERSION(DRV_VERSION);
246MODULE_AUTHOR("Amit Chatterjee <amit.chatterjee@ti.com>");
247MODULE_AUTHOR("Pratheesh Gangadhar <pratheesh@ti.com>");
diff --git a/include/linux/platform_data/uio_pruss.h b/include/linux/platform_data/uio_pruss.h
new file mode 100644
index 000000000000..f39140aabc6f
--- /dev/null
+++ b/include/linux/platform_data/uio_pruss.h
@@ -0,0 +1,25 @@
1/*
2 * include/linux/platform_data/uio_pruss.h
3 *
4 * Platform data for uio_pruss driver
5 *
6 * Copyright (C) 2010-11 Texas Instruments Incorporated - http://www.ti.com/
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation version 2.
11 *
12 * This program is distributed "as is" WITHOUT ANY WARRANTY of any
13 * kind, whether express or implied; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 */
17
18#ifndef _UIO_PRUSS_H_
19#define _UIO_PRUSS_H_
20
21/* To configure the PRUSS INTC base offset for UIO driver */
22struct uio_pruss_pdata {
23 u32 pintc_base;
24};
25#endif /* _UIO_PRUSS_H_ */