aboutsummaryrefslogtreecommitdiffstats
path: root/arch/mips/basler/excite/excite_iodev.c
diff options
context:
space:
mode:
authorRalf Baechle <ralf@linux-mips.org>2006-06-18 11:39:46 -0400
committerRalf Baechle <ralf@linux-mips.org>2006-06-19 12:39:26 -0400
commit35189fad3cb5f6e3ab66c8321928a851de0cd2b1 (patch)
tree70dcd11a08d964da9ee27bc716b2205f250b42dd /arch/mips/basler/excite/excite_iodev.c
parent355c471f2ff324c21f8a1fb8e2e242a0f2a4aa68 (diff)
[MIPS] Support for the RM9000-based Basler eXcite smart camera platform.
Signed-off-by: Thomas Koeller <thomas.koeller@baslerweb.com> Signed-off-by: Ralf Baechle <ralf@linux-mips.org>
Diffstat (limited to 'arch/mips/basler/excite/excite_iodev.c')
-rw-r--r--arch/mips/basler/excite/excite_iodev.c183
1 files changed, 183 insertions, 0 deletions
diff --git a/arch/mips/basler/excite/excite_iodev.c b/arch/mips/basler/excite/excite_iodev.c
new file mode 100644
index 000000000000..91121e523043
--- /dev/null
+++ b/arch/mips/basler/excite/excite_iodev.c
@@ -0,0 +1,183 @@
1/*
2 * Copyright (C) 2005 by Basler Vision Technologies AG
3 * Author: Thomas Koeller <thomas.koeller@baslerweb.com>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 */
19
20#include <linux/config.h>
21#include <linux/compiler.h>
22#include <linux/init.h>
23#include <linux/module.h>
24#include <linux/sched.h>
25#include <linux/wait.h>
26#include <linux/poll.h>
27#include <linux/interrupt.h>
28#include <linux/platform_device.h>
29#include <linux/miscdevice.h>
30
31#include "excite_iodev.h"
32
33
34
35static const struct resource *iodev_get_resource(struct platform_device *, const char *, unsigned int);
36static int __init iodev_probe(struct device *);
37static int __exit iodev_remove(struct device *);
38static int iodev_open(struct inode *, struct file *);
39static int iodev_release(struct inode *, struct file *);
40static ssize_t iodev_read(struct file *, char __user *, size_t s, loff_t *);
41static unsigned int iodev_poll(struct file *, struct poll_table_struct *);
42static irqreturn_t iodev_irqhdl(int, void *, struct pt_regs *);
43
44
45
46static const char iodev_name[] = "iodev";
47static unsigned int iodev_irq;
48static DECLARE_WAIT_QUEUE_HEAD(wq);
49
50
51
52static struct file_operations fops =
53{
54 .owner = THIS_MODULE,
55 .open = iodev_open,
56 .release = iodev_release,
57 .read = iodev_read,
58 .poll = iodev_poll
59};
60
61static struct miscdevice miscdev =
62{
63 .minor = MISC_DYNAMIC_MINOR,
64 .name = iodev_name,
65 .fops = &fops
66};
67
68static struct device_driver iodev_driver =
69{
70 .name = (char *) iodev_name,
71 .bus = &platform_bus_type,
72 .owner = THIS_MODULE,
73 .probe = iodev_probe,
74 .remove = __exit_p(iodev_remove)
75};
76
77
78
79static const struct resource *
80iodev_get_resource(struct platform_device *pdv, const char *name,
81 unsigned int type)
82{
83 char buf[80];
84 if (snprintf(buf, sizeof buf, "%s_0", name) >= sizeof buf)
85 return NULL;
86 return platform_get_resource_byname(pdv, type, buf);
87}
88
89
90
91/* No hotplugging on the platform bus - use __init */
92static int __init iodev_probe(struct device *dev)
93{
94 struct platform_device * const pdv = to_platform_device(dev);
95 const struct resource * const ri =
96 iodev_get_resource(pdv, IODEV_RESOURCE_IRQ, IORESOURCE_IRQ);
97
98 if (unlikely(!ri))
99 return -ENXIO;
100
101 iodev_irq = ri->start;
102 return misc_register(&miscdev);
103}
104
105
106
107static int __exit iodev_remove(struct device *dev)
108{
109 return misc_deregister(&miscdev);
110}
111
112
113
114static int iodev_open(struct inode *i, struct file *f)
115{
116 return request_irq(iodev_irq, iodev_irqhdl, SA_INTERRUPT,
117 iodev_name, &miscdev);
118}
119
120
121
122static int iodev_release(struct inode *i, struct file *f)
123{
124 free_irq(iodev_irq, &miscdev);
125 return 0;
126}
127
128
129
130
131static ssize_t
132iodev_read(struct file *f, char __user *d, size_t s, loff_t *o)
133{
134 ssize_t ret;
135 DEFINE_WAIT(w);
136
137 prepare_to_wait(&wq, &w, TASK_INTERRUPTIBLE);
138 if (!signal_pending(current))
139 schedule();
140 ret = signal_pending(current) ? -ERESTARTSYS : 0;
141 finish_wait(&wq, &w);
142 return ret;
143}
144
145
146static unsigned int iodev_poll(struct file *f, struct poll_table_struct *p)
147{
148 poll_wait(f, &wq, p);
149 return POLLOUT | POLLWRNORM;
150}
151
152
153
154
155static irqreturn_t iodev_irqhdl(int irq, void *ctxt, struct pt_regs *regs)
156{
157 wake_up(&wq);
158 return IRQ_HANDLED;
159}
160
161
162
163static int __init iodev_init_module(void)
164{
165 return driver_register(&iodev_driver);
166}
167
168
169
170static void __exit iodev_cleanup_module(void)
171{
172 driver_unregister(&iodev_driver);
173}
174
175module_init(iodev_init_module);
176module_exit(iodev_cleanup_module);
177
178
179
180MODULE_AUTHOR("Thomas Koeller <thomas.koeller@baslerweb.com>");
181MODULE_DESCRIPTION("Basler eXcite i/o interrupt handler");
182MODULE_VERSION("0.0");
183MODULE_LICENSE("GPL");