To properly support multiple devices (including fishing rods :-> ):
--- /home/Adrian/sounddc/purupuru.c Thu Mar 7 00:31:51 2002
+++ ./purupuru.c Thu Mar 7 00:24:13 2002
@@ -19,6 +19,7 @@
/*
* First posted 18 Feburary 2002
*
+ * Multiple device support fixed 7 March 2003
*/
#include <linux/kernel.h>
@@ -37,7 +38,7 @@
#define PURU_MINOR_BASE 64
#define PPP_VERSION 1
-#define _DEBUG_
+/*#define _DEBUG_ */
#ifdef _DEBUG_
#define DEBGM(fmt, args...) (printk(KERN_ERR fmt, ##args))
@@ -111,9 +112,7 @@
puru->dev.idbus = BUS_MAPLE;
input_register_device(&puru->dev);
input_register_handler(&purupuru_handler);
- puru->minor = ((puru->dev.handle)->handler)->minor;
- /* Add this device to the list */
- list_add_tail(&puru->list, &devices_list);
+
return 0;
}
@@ -368,6 +367,7 @@
void dc_purupuru_wake(struct maple_driver_data *data)
{
+
if (last_jiffies == -1) {
last_jiffies = jiffies;
return;
@@ -405,10 +405,21 @@
struct input_dev *dev)
{
struct input_handle *handle;
+ struct list_head *lst;
+ struct dc_purupuru *device;
+ /* tasklet_enable(&switchoff_tasklet); */
/* Is this a Puru Puru device? */
if (dev->open != dc_puru_open)
return NULL;
+ /* Have we already added this device? */
+ list_for_each(lst, &devices_list) {
+ device = list_entry(lst, struct dc_purupuru, list);
+ if (device->minor == (PURU_MINOR_BASE + dev->number)) {
+ return NULL;
+ }
+ }
+
if (!(handle = kmalloc(sizeof(struct input_handle), GFP_KERNEL)))
return NULL;
memset(handle, 0, sizeof(struct input_handle));
@@ -420,9 +431,14 @@
printk(KERN_INFO "purupuru.c: adding Puru Puru Pack input%d\n",
dev->number);
- tasklet_enable(&switchoff_tasklet);
+
handler->minor = PURU_MINOR_BASE + dev->number;
+
+ /* Add to list */
+ struct dc_purupuru *dcp = dev->private;
+ dcp->minor = handler->minor;
+ list_add_tail(&dcp->list, &devices_list);
return handle;
@@ -430,6 +446,19 @@
static void purupuru_disconnect(struct input_handle *handle)
{
+ /* Remove from list of devices */
+ struct list_head *ptr = NULL;
+ struct list_head *nxt = NULL;
+ struct dc_purupuru *device;
+
+ list_for_each_safe(ptr, nxt, &devices_list) {
+ device = list_entry(ptr, struct dc_purupuru, list);
+ if (device->minor == handle->handler->minor) {
+ list_del(&device->list);
+ kfree(device);
+ }
+ }
+
input_close_device(handle);
kfree(handle);
}
@@ -447,7 +476,7 @@
maple_register_driver(&dc_purupuru_driver);
printk("Puru Puru Pack driver for Dreamcast Linux version 0.1\n");
- tasklet_disable(&switchoff_tasklet);
+ /* tasklet_disable(&switchoff_tasklet); */
return 0;
}
|