2 * Copyright (C) 2005 by Basler Vision Technologies AG
3 * Author: Thomas Koeller <thomas.koeller@baslerweb.com>
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.
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.
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
20 #include <linux/compiler.h>
21 #include <linux/init.h>
22 #include <linux/module.h>
23 #include <linux/sched.h>
24 #include <linux/wait.h>
25 #include <linux/poll.h>
26 #include <linux/interrupt.h>
27 #include <linux/platform_device.h>
28 #include <linux/miscdevice.h>
29 #include <linux/smp_lock.h>
31 #include "excite_iodev.h"
35 static const struct resource
*iodev_get_resource(struct platform_device
*, const char *, unsigned int);
36 static int __init
iodev_probe(struct platform_device
*);
37 static int __exit
iodev_remove(struct platform_device
*);
38 static int iodev_open(struct inode
*, struct file
*);
39 static int iodev_release(struct inode
*, struct file
*);
40 static ssize_t
iodev_read(struct file
*, char __user
*, size_t s
, loff_t
*);
41 static unsigned int iodev_poll(struct file
*, struct poll_table_struct
*);
42 static irqreturn_t
iodev_irqhdl(int, void *);
46 static const char iodev_name
[] = "iodev";
47 static unsigned int iodev_irq
;
48 static DECLARE_WAIT_QUEUE_HEAD(wq
);
52 static const struct file_operations fops
=
56 .release
= iodev_release
,
61 static struct miscdevice miscdev
=
63 .minor
= MISC_DYNAMIC_MINOR
,
68 static struct platform_driver iodev_driver
= {
74 .remove
= __devexit_p(iodev_remove
),
79 static const struct resource
*
80 iodev_get_resource(struct platform_device
*pdv
, const char *name
,
84 if (snprintf(buf
, sizeof buf
, "%s_0", name
) >= sizeof buf
)
86 return platform_get_resource_byname(pdv
, type
, buf
);
91 /* No hotplugging on the platform bus - use __init */
92 static int __init
iodev_probe(struct platform_device
*dev
)
94 const struct resource
* const ri
=
95 iodev_get_resource(dev
, IODEV_RESOURCE_IRQ
, IORESOURCE_IRQ
);
100 iodev_irq
= ri
->start
;
101 return misc_register(&miscdev
);
106 static int __exit
iodev_remove(struct platform_device
*dev
)
108 return misc_deregister(&miscdev
);
111 static int iodev_open(struct inode
*i
, struct file
*f
)
115 ret
= request_irq(iodev_irq
, iodev_irqhdl
, IRQF_DISABLED
,
116 iodev_name
, &miscdev
);
121 static int iodev_release(struct inode
*i
, struct file
*f
)
123 free_irq(iodev_irq
, &miscdev
);
131 iodev_read(struct file
*f
, char __user
*d
, size_t s
, loff_t
*o
)
136 prepare_to_wait(&wq
, &w
, TASK_INTERRUPTIBLE
);
137 if (!signal_pending(current
))
139 ret
= signal_pending(current
) ? -ERESTARTSYS
: 0;
140 finish_wait(&wq
, &w
);
145 static unsigned int iodev_poll(struct file
*f
, struct poll_table_struct
*p
)
147 poll_wait(f
, &wq
, p
);
148 return POLLOUT
| POLLWRNORM
;
151 static irqreturn_t
iodev_irqhdl(int irq
, void *ctxt
)
158 static int __init
iodev_init_module(void)
160 return platform_driver_register(&iodev_driver
);
165 static void __exit
iodev_cleanup_module(void)
167 platform_driver_unregister(&iodev_driver
);
170 module_init(iodev_init_module
);
171 module_exit(iodev_cleanup_module
);
175 MODULE_AUTHOR("Thomas Koeller <thomas.koeller@baslerweb.com>");
176 MODULE_DESCRIPTION("Basler eXcite i/o interrupt handler");
177 MODULE_VERSION("0.0");
178 MODULE_LICENSE("GPL");