Skip to content

Commit 423baf8

Browse files
Jason KridnerRobertCNelson
authored andcommitted
uio: add uio_pruss_shmem driver
Signed-off-by: Jason Kridner <[email protected]>
1 parent 9b8ff56 commit 423baf8

File tree

3 files changed

+172
-0
lines changed

3 files changed

+172
-0
lines changed

drivers/uio/Kconfig

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,14 @@ config UIO_PRUSS
142142
To compile this driver as a module, choose M here: the module
143143
will be called uio_pruss.
144144

145+
config UIO_PRUSS_SHMEM
146+
tristate "Texas Instruments PRUSS_SHMEM driver"
147+
help
148+
PRUSS SHMEM driver for AM3X and AM5X devices
149+
150+
To compile this driver as a module, choose M here: the module
151+
will be called uio_pruss_shmem.
152+
145153
config UIO_MF624
146154
tristate "Humusoft MF624 DAQ PCI card driver"
147155
depends on PCI

drivers/uio/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ obj-$(CONFIG_UIO_SERCOS3) += uio_sercos3.o
88
obj-$(CONFIG_UIO_PCI_GENERIC) += uio_pci_generic.o
99
obj-$(CONFIG_UIO_NETX) += uio_netx.o
1010
obj-$(CONFIG_UIO_PRUSS) += uio_pruss.o
11+
obj-$(CONFIG_UIO_PRUSS_SHMEM) += uio_pruss_shmem.o
1112
obj-$(CONFIG_UIO_MF624) += uio_mf624.o
1213
obj-$(CONFIG_UIO_FSL_ELBC_GPCM) += uio_fsl_elbc_gpcm.o
1314
obj-$(CONFIG_UIO_HV_GENERIC) += uio_hv_generic.o

drivers/uio/uio_pruss_shmem.c

Lines changed: 163 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,163 @@
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/io.h>
24+
#include <linux/clk.h>
25+
#include <linux/dma-mapping.h>
26+
#include <linux/sizes.h>
27+
#include <linux/slab.h>
28+
#include <linux/genalloc.h>
29+
#include <linux/of_address.h>
30+
#include <linux/of_device.h>
31+
32+
#define DRV_NAME "pruss_uio_shmem"
33+
#define DRV_VERSION "1.0"
34+
35+
struct uio_pruss_shmem_dev {
36+
struct uio_info *info;
37+
void __iomem *prussio_vaddr;
38+
};
39+
40+
static void pruss_shmem_cleanup(struct device *dev, struct uio_pruss_shmem_dev *gdev)
41+
{
42+
struct uio_info *p = gdev->info;
43+
44+
uio_unregister_device(p);
45+
iounmap(gdev->prussio_vaddr);
46+
kfree(gdev->info);
47+
kfree(gdev);
48+
}
49+
50+
static int pruss_shmem_probe(struct platform_device *pdev)
51+
{
52+
struct uio_pruss_shmem_dev *gdev;
53+
struct resource *regs_prussio;
54+
struct resource res;
55+
struct device *dev = &pdev->dev;
56+
int ret, len;
57+
struct uio_info *p;
58+
59+
dev_info(dev, "Allocating gdev\n");
60+
gdev = kzalloc(sizeof(struct uio_pruss_shmem_dev), GFP_KERNEL);
61+
if (!gdev)
62+
return -ENOMEM;
63+
64+
dev_info(dev, "Allocating info\n");
65+
gdev->info = kzalloc(sizeof(struct uio_info), GFP_KERNEL);
66+
if (!gdev->info) {
67+
ret = -ENOMEM;
68+
goto err_free_gdev;
69+
}
70+
71+
dev_info(dev, "Requesting resource\n");
72+
if (dev->of_node) {
73+
ret = of_address_to_resource(dev->of_node, 0, &res);
74+
if (IS_ERR_VALUE(ret)) {
75+
dev_err(dev, "Failed to parse DT reg\n");
76+
goto err_free_info;
77+
}
78+
regs_prussio = &res;
79+
} else {
80+
regs_prussio = platform_get_resource(pdev, IORESOURCE_MEM, 0);
81+
if (!regs_prussio) {
82+
dev_err(dev, "No PRUSS I/O resource specified\n");
83+
goto err_free_info;
84+
}
85+
}
86+
if (!regs_prussio) {
87+
dev_err(dev, "No PRUSS I/O resource specified\n");
88+
ret = -EIO;
89+
goto err_free_info;
90+
}
91+
if (!regs_prussio->start) {
92+
dev_err(dev, "Invalid memory resource\n");
93+
ret = -EIO;
94+
goto err_free_info;
95+
}
96+
dev_info(dev, "Mapping resource\n");
97+
len = resource_size(regs_prussio);
98+
gdev->prussio_vaddr = ioremap(regs_prussio->start, len);
99+
if (!gdev->prussio_vaddr) {
100+
dev_err(dev, "Can't remap PRUSS I/O address range\n");
101+
ret = -ENOMEM;
102+
goto err_free_info;
103+
}
104+
105+
p = gdev->info;
106+
p->mem[0].addr = regs_prussio->start;
107+
p->mem[0].size = resource_size(regs_prussio);
108+
p->mem[0].memtype = UIO_MEM_PHYS;
109+
110+
p->name = "pruss_shmem";
111+
p->version = DRV_VERSION;
112+
113+
dev_info(dev, "Registering with uio driver\n");
114+
ret = uio_register_device(dev, p);
115+
if (ret < 0) {
116+
goto err_free_register;
117+
}
118+
119+
dev_info(dev, "Saving platform data\n");
120+
platform_set_drvdata(pdev, gdev);
121+
return 0;
122+
123+
err_free_register:
124+
uio_unregister_device(p);
125+
iounmap(gdev->prussio_vaddr);
126+
err_free_info:
127+
kfree(gdev->info);
128+
err_free_gdev:
129+
kfree(gdev);
130+
131+
return ret;
132+
}
133+
134+
static int pruss_shmem_remove(struct platform_device *dev)
135+
{
136+
struct uio_pruss_shmem_dev *gdev = platform_get_drvdata(dev);
137+
138+
pruss_shmem_cleanup(&dev->dev, gdev);
139+
return 0;
140+
}
141+
142+
static const struct of_device_id pruss_shmem_dt_ids[] = {
143+
{ .compatible = "ti,pruss-shmem", .data = NULL, },
144+
{},
145+
};
146+
MODULE_DEVICE_TABLE(of, pruss_shmem_dt_ids);
147+
148+
static struct platform_driver pruss_shmem_driver = {
149+
.probe = pruss_shmem_probe,
150+
.remove = pruss_shmem_remove,
151+
.driver = {
152+
.name = DRV_NAME,
153+
.of_match_table = pruss_shmem_dt_ids,
154+
},
155+
};
156+
157+
module_platform_driver(pruss_shmem_driver);
158+
159+
MODULE_LICENSE("GPL v2");
160+
MODULE_VERSION(DRV_VERSION);
161+
MODULE_AUTHOR("Amit Chatterjee <[email protected]>");
162+
MODULE_AUTHOR("Pratheesh Gangadhar <[email protected]>");
163+
MODULE_AUTHOR("Jason Kridner <[email protected]>");

0 commit comments

Comments
 (0)