Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * USB PhidgetInterfaceKit driver 1.0 |
| 3 | * |
Sean Young | 69165c2 | 2006-05-02 11:44:43 +0000 | [diff] [blame] | 4 | * Copyright (C) 2004, 2006 Sean Young <sean@mess.org> |
| 5 | * Copyright (C) 2005 Daniel Saakes <daniel@saakes.net> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6 | * Copyright (C) 2004 Greg Kroah-Hartman <greg@kroah.com> |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify |
| 9 | * it under the terms of the GNU General Public License as published by |
| 10 | * the Free Software Foundation; either version 2 of the License, or |
| 11 | * (at your option) any later version. |
| 12 | * |
| 13 | * This is a driver for the USB PhidgetInterfaceKit. |
| 14 | */ |
| 15 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16 | #include <linux/kernel.h> |
| 17 | #include <linux/errno.h> |
| 18 | #include <linux/init.h> |
| 19 | #include <linux/slab.h> |
| 20 | #include <linux/module.h> |
| 21 | #include <linux/usb.h> |
| 22 | |
Sean Young | 912b24c | 2006-07-10 09:56:25 +0000 | [diff] [blame] | 23 | #include "phidget.h" |
| 24 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 25 | #define DRIVER_AUTHOR "Sean Young <sean@mess.org>" |
| 26 | #define DRIVER_DESC "USB PhidgetInterfaceKit Driver" |
| 27 | |
| 28 | #define USB_VENDOR_ID_GLAB 0x06c2 |
| 29 | #define USB_DEVICE_ID_INTERFACEKIT004 0x0040 |
Sean Young | 69165c2 | 2006-05-02 11:44:43 +0000 | [diff] [blame] | 30 | #define USB_DEVICE_ID_INTERFACEKIT01616 0x0044 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 31 | #define USB_DEVICE_ID_INTERFACEKIT888 0x0045 |
| 32 | #define USB_DEVICE_ID_INTERFACEKIT047 0x0051 |
| 33 | #define USB_DEVICE_ID_INTERFACEKIT088 0x0053 |
| 34 | |
| 35 | #define USB_VENDOR_ID_WISEGROUP 0x0925 |
| 36 | #define USB_DEVICE_ID_INTERFACEKIT884 0x8201 |
| 37 | |
Sean Young | 69165c2 | 2006-05-02 11:44:43 +0000 | [diff] [blame] | 38 | #define MAX_INTERFACES 16 |
| 39 | |
| 40 | #define URB_INT_SIZE 8 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 | |
| 42 | struct driver_interfacekit { |
| 43 | int sensors; |
| 44 | int inputs; |
| 45 | int outputs; |
| 46 | int has_lcd; |
Sean Young | 238d0e7 | 2006-09-24 19:26:57 +0000 | [diff] [blame] | 47 | int amnesiac; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 48 | }; |
Sean Young | 238d0e7 | 2006-09-24 19:26:57 +0000 | [diff] [blame] | 49 | |
| 50 | #define ifkit(_sensors, _inputs, _outputs, _lcd, _amnesiac) \ |
| 51 | { \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | .sensors = _sensors, \ |
| 53 | .inputs = _inputs, \ |
| 54 | .outputs = _outputs, \ |
| 55 | .has_lcd = _lcd, \ |
Sean Young | 238d0e7 | 2006-09-24 19:26:57 +0000 | [diff] [blame] | 56 | .amnesiac = _amnesiac \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 57 | }; |
Sean Young | 238d0e7 | 2006-09-24 19:26:57 +0000 | [diff] [blame] | 58 | |
| 59 | static const struct driver_interfacekit ph_004 = ifkit(0, 0, 4, 0, 0); |
| 60 | static const struct driver_interfacekit ph_888n = ifkit(8, 8, 8, 0, 1); |
| 61 | static const struct driver_interfacekit ph_888o = ifkit(8, 8, 8, 0, 0); |
| 62 | static const struct driver_interfacekit ph_047 = ifkit(0, 4, 7, 1, 0); |
| 63 | static const struct driver_interfacekit ph_884 = ifkit(8, 8, 4, 0, 0); |
| 64 | static const struct driver_interfacekit ph_088 = ifkit(0, 8, 8, 1, 0); |
| 65 | static const struct driver_interfacekit ph_01616 = ifkit(0, 16, 16, 0, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 66 | |
Sean Young | 912b24c | 2006-07-10 09:56:25 +0000 | [diff] [blame] | 67 | static unsigned long device_no; |
| 68 | |
Sean Young | 69165c2 | 2006-05-02 11:44:43 +0000 | [diff] [blame] | 69 | struct interfacekit { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 70 | struct usb_device *udev; |
| 71 | struct usb_interface *intf; |
| 72 | struct driver_interfacekit *ifkit; |
Sean Young | 912b24c | 2006-07-10 09:56:25 +0000 | [diff] [blame] | 73 | struct device *dev; |
Sean Young | 69165c2 | 2006-05-02 11:44:43 +0000 | [diff] [blame] | 74 | unsigned long outputs; |
Sean Young | 912b24c | 2006-07-10 09:56:25 +0000 | [diff] [blame] | 75 | int dev_no; |
Sean Young | 69165c2 | 2006-05-02 11:44:43 +0000 | [diff] [blame] | 76 | u8 inputs[MAX_INTERFACES]; |
| 77 | u16 sensors[MAX_INTERFACES]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 78 | u8 lcd_files_on; |
| 79 | |
| 80 | struct urb *irq; |
| 81 | unsigned char *data; |
| 82 | dma_addr_t data_dma; |
Sean Young | 69165c2 | 2006-05-02 11:44:43 +0000 | [diff] [blame] | 83 | |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 84 | struct delayed_work do_notify; |
| 85 | struct delayed_work do_resubmit; |
Sean Young | 69165c2 | 2006-05-02 11:44:43 +0000 | [diff] [blame] | 86 | unsigned long input_events; |
| 87 | unsigned long sensor_events; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 88 | }; |
| 89 | |
| 90 | static struct usb_device_id id_table[] = { |
| 91 | {USB_DEVICE(USB_VENDOR_ID_GLAB, USB_DEVICE_ID_INTERFACEKIT004), |
| 92 | .driver_info = (kernel_ulong_t)&ph_004}, |
Sean Young | 238d0e7 | 2006-09-24 19:26:57 +0000 | [diff] [blame] | 93 | {USB_DEVICE_VER(USB_VENDOR_ID_GLAB, USB_DEVICE_ID_INTERFACEKIT888, 0, 0x814), |
| 94 | .driver_info = (kernel_ulong_t)&ph_888o}, |
| 95 | {USB_DEVICE_VER(USB_VENDOR_ID_GLAB, USB_DEVICE_ID_INTERFACEKIT888, 0x0815, 0xffff), |
| 96 | .driver_info = (kernel_ulong_t)&ph_888n}, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 97 | {USB_DEVICE(USB_VENDOR_ID_GLAB, USB_DEVICE_ID_INTERFACEKIT047), |
| 98 | .driver_info = (kernel_ulong_t)&ph_047}, |
| 99 | {USB_DEVICE(USB_VENDOR_ID_GLAB, USB_DEVICE_ID_INTERFACEKIT088), |
| 100 | .driver_info = (kernel_ulong_t)&ph_088}, |
Sean Young | 69165c2 | 2006-05-02 11:44:43 +0000 | [diff] [blame] | 101 | {USB_DEVICE(USB_VENDOR_ID_GLAB, USB_DEVICE_ID_INTERFACEKIT01616), |
| 102 | .driver_info = (kernel_ulong_t)&ph_01616}, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 103 | {USB_DEVICE(USB_VENDOR_ID_WISEGROUP, USB_DEVICE_ID_INTERFACEKIT884), |
| 104 | .driver_info = (kernel_ulong_t)&ph_884}, |
| 105 | {} |
| 106 | }; |
| 107 | MODULE_DEVICE_TABLE(usb, id_table); |
| 108 | |
Sean Young | 238d0e7 | 2006-09-24 19:26:57 +0000 | [diff] [blame] | 109 | static int set_outputs(struct interfacekit *kit) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 110 | { |
Sean Young | 69165c2 | 2006-05-02 11:44:43 +0000 | [diff] [blame] | 111 | u8 *buffer; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 112 | int retval; |
Sean Young | 69165c2 | 2006-05-02 11:44:43 +0000 | [diff] [blame] | 113 | |
Oliver Neukum | 1759084 | 2006-01-06 22:41:51 +0100 | [diff] [blame] | 114 | buffer = kzalloc(4, GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 115 | if (!buffer) { |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 116 | dev_err(&kit->udev->dev, "%s - out of memory\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 117 | return -ENOMEM; |
| 118 | } |
Sean Young | 69165c2 | 2006-05-02 11:44:43 +0000 | [diff] [blame] | 119 | buffer[0] = (u8)kit->outputs; |
| 120 | buffer[1] = (u8)(kit->outputs >> 8); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 121 | |
Sean Young | 69165c2 | 2006-05-02 11:44:43 +0000 | [diff] [blame] | 122 | dev_dbg(&kit->udev->dev, "sending data: 0x%04x\n", (u16)kit->outputs); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 123 | |
| 124 | retval = usb_control_msg(kit->udev, |
| 125 | usb_sndctrlpipe(kit->udev, 0), |
| 126 | 0x09, 0x21, 0x0200, 0x0000, buffer, 4, 2000); |
| 127 | |
| 128 | if (retval != 4) |
| 129 | dev_err(&kit->udev->dev, "usb_control_msg returned %d\n", |
| 130 | retval); |
| 131 | kfree(buffer); |
| 132 | |
Sean Young | 238d0e7 | 2006-09-24 19:26:57 +0000 | [diff] [blame] | 133 | if (kit->ifkit->amnesiac) |
| 134 | schedule_delayed_work(&kit->do_resubmit, HZ / 2); |
| 135 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 136 | return retval < 0 ? retval : 0; |
| 137 | } |
| 138 | |
Sean Young | 69165c2 | 2006-05-02 11:44:43 +0000 | [diff] [blame] | 139 | static int change_string(struct interfacekit *kit, const char *display, unsigned char row) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 140 | { |
| 141 | unsigned char *buffer; |
Sean Young | 69165c2 | 2006-05-02 11:44:43 +0000 | [diff] [blame] | 142 | unsigned char *form_buffer; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 143 | int retval = -ENOMEM; |
| 144 | int i,j, len, buf_ptr; |
| 145 | |
| 146 | buffer = kmalloc(8, GFP_KERNEL); |
| 147 | form_buffer = kmalloc(30, GFP_KERNEL); |
| 148 | if ((!buffer) || (!form_buffer)) { |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 149 | dev_err(&kit->udev->dev, "%s - out of memory\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 150 | goto exit; |
| 151 | } |
| 152 | |
| 153 | len = strlen(display); |
| 154 | if (len > 20) |
| 155 | len = 20; |
| 156 | |
| 157 | dev_dbg(&kit->udev->dev, "Setting LCD line %d to %s\n", row, display); |
| 158 | |
| 159 | form_buffer[0] = row * 0x40 + 0x80; |
| 160 | form_buffer[1] = 0x02; |
| 161 | buf_ptr = 2; |
| 162 | for (i = 0; i<len; i++) |
| 163 | form_buffer[buf_ptr++] = display[i]; |
| 164 | |
| 165 | for (i = 0; i < (20 - len); i++) |
| 166 | form_buffer[buf_ptr++] = 0x20; |
| 167 | form_buffer[buf_ptr++] = 0x01; |
| 168 | form_buffer[buf_ptr++] = row * 0x40 + 0x80 + strlen(display); |
| 169 | |
| 170 | for (i = 0; i < buf_ptr; i += 7) { |
| 171 | if ((buf_ptr - i) > 7) |
| 172 | len = 7; |
| 173 | else |
| 174 | len = (buf_ptr - i); |
| 175 | for (j = 0; j < len; j++) |
| 176 | buffer[j] = form_buffer[i + j]; |
| 177 | buffer[7] = len; |
| 178 | |
| 179 | retval = usb_control_msg(kit->udev, |
| 180 | usb_sndctrlpipe(kit->udev, 0), |
| 181 | 0x09, 0x21, 0x0200, 0x0000, buffer, 8, 2000); |
| 182 | if (retval < 0) |
| 183 | goto exit; |
| 184 | } |
| 185 | |
| 186 | retval = 0; |
| 187 | exit: |
| 188 | kfree(buffer); |
| 189 | kfree(form_buffer); |
| 190 | |
| 191 | return retval; |
| 192 | } |
| 193 | |
| 194 | #define set_lcd_line(number) \ |
Sean Young | 912b24c | 2006-07-10 09:56:25 +0000 | [diff] [blame] | 195 | static ssize_t lcd_line_##number(struct device *dev, \ |
| 196 | struct device_attribute *attr, \ |
| 197 | const char *buf, size_t count) \ |
| 198 | { \ |
| 199 | struct interfacekit *kit = dev_get_drvdata(dev); \ |
| 200 | change_string(kit, buf, number - 1); \ |
| 201 | return count; \ |
Sean Young | da308e8 | 2006-08-11 09:28:28 +0000 | [diff] [blame] | 202 | } |
| 203 | |
| 204 | #define lcd_line_attr(number) \ |
| 205 | __ATTR(lcd_line_##number, S_IWUGO, NULL, lcd_line_##number) |
| 206 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 207 | set_lcd_line(1); |
| 208 | set_lcd_line(2); |
| 209 | |
Yani Ioannou | 060b884 | 2005-05-17 06:44:04 -0400 | [diff] [blame] | 210 | static ssize_t set_backlight(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 211 | { |
Sean Young | 912b24c | 2006-07-10 09:56:25 +0000 | [diff] [blame] | 212 | struct interfacekit *kit = dev_get_drvdata(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 213 | int enabled; |
| 214 | unsigned char *buffer; |
| 215 | int retval = -ENOMEM; |
| 216 | |
Oliver Neukum | 1759084 | 2006-01-06 22:41:51 +0100 | [diff] [blame] | 217 | buffer = kzalloc(8, GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 218 | if (!buffer) { |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 219 | dev_err(&kit->udev->dev, "%s - out of memory\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 220 | goto exit; |
| 221 | } |
| 222 | |
| 223 | if (sscanf(buf, "%d", &enabled) < 1) { |
| 224 | retval = -EINVAL; |
| 225 | goto exit; |
| 226 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 227 | if (enabled) |
| 228 | buffer[0] = 0x01; |
| 229 | buffer[7] = 0x11; |
| 230 | |
| 231 | dev_dbg(&kit->udev->dev, "Setting backlight to %s\n", enabled ? "on" : "off"); |
| 232 | |
| 233 | retval = usb_control_msg(kit->udev, |
| 234 | usb_sndctrlpipe(kit->udev, 0), |
| 235 | 0x09, 0x21, 0x0200, 0x0000, buffer, 8, 2000); |
| 236 | if (retval < 0) |
| 237 | goto exit; |
| 238 | |
| 239 | retval = count; |
| 240 | exit: |
| 241 | kfree(buffer); |
| 242 | return retval; |
| 243 | } |
Sean Young | da308e8 | 2006-08-11 09:28:28 +0000 | [diff] [blame] | 244 | |
| 245 | static struct device_attribute dev_lcd_line_attrs[] = { |
| 246 | lcd_line_attr(1), |
| 247 | lcd_line_attr(2), |
| 248 | __ATTR(backlight, S_IWUGO, NULL, set_backlight) |
| 249 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 250 | |
Sean Young | 69165c2 | 2006-05-02 11:44:43 +0000 | [diff] [blame] | 251 | static void remove_lcd_files(struct interfacekit *kit) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 252 | { |
Sean Young | da308e8 | 2006-08-11 09:28:28 +0000 | [diff] [blame] | 253 | int i; |
| 254 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 255 | if (kit->lcd_files_on) { |
| 256 | dev_dbg(&kit->udev->dev, "Removing lcd files\n"); |
Sean Young | da308e8 | 2006-08-11 09:28:28 +0000 | [diff] [blame] | 257 | |
| 258 | for (i=0; i<ARRAY_SIZE(dev_lcd_line_attrs); i++) |
| 259 | device_remove_file(kit->dev, &dev_lcd_line_attrs[i]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 260 | } |
| 261 | } |
| 262 | |
Yani Ioannou | 060b884 | 2005-05-17 06:44:04 -0400 | [diff] [blame] | 263 | static ssize_t enable_lcd_files(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 264 | { |
Sean Young | 912b24c | 2006-07-10 09:56:25 +0000 | [diff] [blame] | 265 | struct interfacekit *kit = dev_get_drvdata(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 266 | int enable; |
Sean Young | da308e8 | 2006-08-11 09:28:28 +0000 | [diff] [blame] | 267 | int i, rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 268 | |
| 269 | if (kit->ifkit->has_lcd == 0) |
| 270 | return -ENODEV; |
| 271 | |
| 272 | if (sscanf(buf, "%d", &enable) < 1) |
| 273 | return -EINVAL; |
| 274 | |
| 275 | if (enable) { |
| 276 | if (!kit->lcd_files_on) { |
| 277 | dev_dbg(&kit->udev->dev, "Adding lcd files\n"); |
Sean Young | da308e8 | 2006-08-11 09:28:28 +0000 | [diff] [blame] | 278 | for (i=0; i<ARRAY_SIZE(dev_lcd_line_attrs); i++) { |
| 279 | rc = device_create_file(kit->dev, |
| 280 | &dev_lcd_line_attrs[i]); |
| 281 | if (rc) |
| 282 | goto out; |
| 283 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 284 | kit->lcd_files_on = 1; |
| 285 | } |
| 286 | } else { |
| 287 | if (kit->lcd_files_on) { |
| 288 | remove_lcd_files(kit); |
| 289 | kit->lcd_files_on = 0; |
| 290 | } |
| 291 | } |
| 292 | |
| 293 | return count; |
Sean Young | da308e8 | 2006-08-11 09:28:28 +0000 | [diff] [blame] | 294 | out: |
| 295 | while (i-- > 0) |
| 296 | device_remove_file(kit->dev, &dev_lcd_line_attrs[i]); |
| 297 | |
| 298 | return rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 299 | } |
Sean Young | da308e8 | 2006-08-11 09:28:28 +0000 | [diff] [blame] | 300 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 301 | static DEVICE_ATTR(lcd, S_IWUGO, NULL, enable_lcd_files); |
| 302 | |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 303 | static void interfacekit_irq(struct urb *urb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 304 | { |
Sean Young | 69165c2 | 2006-05-02 11:44:43 +0000 | [diff] [blame] | 305 | struct interfacekit *kit = urb->context; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 306 | unsigned char *buffer = kit->data; |
Sean Young | 69165c2 | 2006-05-02 11:44:43 +0000 | [diff] [blame] | 307 | int i, level, sensor; |
Greg Kroah-Hartman | 2fe8c3f | 2007-07-18 10:58:02 -0700 | [diff] [blame] | 308 | int retval; |
| 309 | int status = urb->status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 310 | |
Greg Kroah-Hartman | 2fe8c3f | 2007-07-18 10:58:02 -0700 | [diff] [blame] | 311 | switch (status) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 312 | case 0: /* success */ |
| 313 | break; |
| 314 | case -ECONNRESET: /* unlink */ |
| 315 | case -ENOENT: |
| 316 | case -ESHUTDOWN: |
| 317 | return; |
| 318 | /* -EPIPE: should clear the halt */ |
| 319 | default: /* error */ |
| 320 | goto resubmit; |
| 321 | } |
| 322 | |
Sean Young | 69165c2 | 2006-05-02 11:44:43 +0000 | [diff] [blame] | 323 | /* digital inputs */ |
| 324 | if (kit->ifkit->inputs == 16) { |
| 325 | for (i=0; i < 8; i++) { |
| 326 | level = (buffer[0] >> i) & 1; |
| 327 | if (kit->inputs[i] != level) { |
| 328 | kit->inputs[i] = level; |
| 329 | set_bit(i, &kit->input_events); |
| 330 | } |
| 331 | level = (buffer[1] >> i) & 1; |
| 332 | if (kit->inputs[8 + i] != level) { |
| 333 | kit->inputs[8 + i] = level; |
| 334 | set_bit(8 + i, &kit->input_events); |
| 335 | } |
| 336 | } |
| 337 | } |
| 338 | else if (kit->ifkit->inputs == 8) { |
| 339 | for (i=0; i < 8; i++) { |
| 340 | level = (buffer[1] >> i) & 1; |
| 341 | if (kit->inputs[i] != level) { |
| 342 | kit->inputs[i] = level; |
| 343 | set_bit(i, &kit->input_events); |
| 344 | } |
| 345 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 346 | } |
| 347 | |
Sean Young | 69165c2 | 2006-05-02 11:44:43 +0000 | [diff] [blame] | 348 | /* analog inputs */ |
| 349 | if (kit->ifkit->sensors) { |
| 350 | sensor = (buffer[0] & 1) ? 4 : 0; |
| 351 | |
| 352 | level = buffer[2] + (buffer[3] & 0x0f) * 256; |
| 353 | if (level != kit->sensors[sensor]) { |
| 354 | kit->sensors[sensor] = level; |
| 355 | set_bit(sensor, &kit->sensor_events); |
| 356 | } |
| 357 | sensor++; |
| 358 | level = buffer[4] + (buffer[3] & 0xf0) * 16; |
| 359 | if (level != kit->sensors[sensor]) { |
| 360 | kit->sensors[sensor] = level; |
| 361 | set_bit(sensor, &kit->sensor_events); |
| 362 | } |
| 363 | sensor++; |
| 364 | level = buffer[5] + (buffer[6] & 0x0f) * 256; |
| 365 | if (level != kit->sensors[sensor]) { |
| 366 | kit->sensors[sensor] = level; |
| 367 | set_bit(sensor, &kit->sensor_events); |
| 368 | } |
| 369 | sensor++; |
| 370 | level = buffer[7] + (buffer[6] & 0xf0) * 16; |
| 371 | if (level != kit->sensors[sensor]) { |
| 372 | kit->sensors[sensor] = level; |
| 373 | set_bit(sensor, &kit->sensor_events); |
| 374 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 375 | } |
| 376 | |
Sean Young | 69165c2 | 2006-05-02 11:44:43 +0000 | [diff] [blame] | 377 | if (kit->input_events || kit->sensor_events) |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 378 | schedule_delayed_work(&kit->do_notify, 0); |
Sean Young | 69165c2 | 2006-05-02 11:44:43 +0000 | [diff] [blame] | 379 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 380 | resubmit: |
Greg Kroah-Hartman | 2fe8c3f | 2007-07-18 10:58:02 -0700 | [diff] [blame] | 381 | retval = usb_submit_urb(urb, GFP_ATOMIC); |
| 382 | if (retval) |
| 383 | err("can't resubmit intr, %s-%s/interfacekit0, retval %d", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 384 | kit->udev->bus->bus_name, |
Greg Kroah-Hartman | 2fe8c3f | 2007-07-18 10:58:02 -0700 | [diff] [blame] | 385 | kit->udev->devpath, retval); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 386 | } |
| 387 | |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 388 | static void do_notify(struct work_struct *work) |
Sean Young | 69165c2 | 2006-05-02 11:44:43 +0000 | [diff] [blame] | 389 | { |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 390 | struct interfacekit *kit = |
| 391 | container_of(work, struct interfacekit, do_notify.work); |
Sean Young | 69165c2 | 2006-05-02 11:44:43 +0000 | [diff] [blame] | 392 | int i; |
| 393 | char sysfs_file[8]; |
| 394 | |
| 395 | for (i=0; i<kit->ifkit->inputs; i++) { |
| 396 | if (test_and_clear_bit(i, &kit->input_events)) { |
| 397 | sprintf(sysfs_file, "input%d", i + 1); |
Sean Young | 912b24c | 2006-07-10 09:56:25 +0000 | [diff] [blame] | 398 | sysfs_notify(&kit->dev->kobj, NULL, sysfs_file); |
Sean Young | 69165c2 | 2006-05-02 11:44:43 +0000 | [diff] [blame] | 399 | } |
| 400 | } |
| 401 | |
| 402 | for (i=0; i<kit->ifkit->sensors; i++) { |
| 403 | if (test_and_clear_bit(i, &kit->sensor_events)) { |
| 404 | sprintf(sysfs_file, "sensor%d", i + 1); |
Sean Young | 912b24c | 2006-07-10 09:56:25 +0000 | [diff] [blame] | 405 | sysfs_notify(&kit->dev->kobj, NULL, sysfs_file); |
Sean Young | 69165c2 | 2006-05-02 11:44:43 +0000 | [diff] [blame] | 406 | } |
| 407 | } |
| 408 | } |
| 409 | |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 410 | static void do_resubmit(struct work_struct *work) |
Sean Young | 238d0e7 | 2006-09-24 19:26:57 +0000 | [diff] [blame] | 411 | { |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 412 | struct interfacekit *kit = |
| 413 | container_of(work, struct interfacekit, do_resubmit.work); |
| 414 | set_outputs(kit); |
Sean Young | 238d0e7 | 2006-09-24 19:26:57 +0000 | [diff] [blame] | 415 | } |
| 416 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 417 | #define show_set_output(value) \ |
Sean Young | 912b24c | 2006-07-10 09:56:25 +0000 | [diff] [blame] | 418 | static ssize_t set_output##value(struct device *dev, \ |
| 419 | struct device_attribute *attr, \ |
| 420 | const char *buf, size_t count) \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 421 | { \ |
Sean Young | 912b24c | 2006-07-10 09:56:25 +0000 | [diff] [blame] | 422 | struct interfacekit *kit = dev_get_drvdata(dev); \ |
Sean Young | 238d0e7 | 2006-09-24 19:26:57 +0000 | [diff] [blame] | 423 | int enable; \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 424 | int retval; \ |
| 425 | \ |
Sean Young | 238d0e7 | 2006-09-24 19:26:57 +0000 | [diff] [blame] | 426 | if (sscanf(buf, "%d", &enable) < 1) \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 427 | return -EINVAL; \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 428 | \ |
Sean Young | 238d0e7 | 2006-09-24 19:26:57 +0000 | [diff] [blame] | 429 | if (enable) \ |
| 430 | set_bit(value - 1, &kit->outputs); \ |
| 431 | else \ |
| 432 | clear_bit(value - 1, &kit->outputs); \ |
| 433 | \ |
| 434 | retval = set_outputs(kit); \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 435 | \ |
| 436 | return retval ? retval : count; \ |
| 437 | } \ |
| 438 | \ |
Sean Young | 912b24c | 2006-07-10 09:56:25 +0000 | [diff] [blame] | 439 | static ssize_t show_output##value(struct device *dev, \ |
| 440 | struct device_attribute *attr, \ |
| 441 | char *buf) \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 442 | { \ |
Sean Young | 912b24c | 2006-07-10 09:56:25 +0000 | [diff] [blame] | 443 | struct interfacekit *kit = dev_get_drvdata(dev); \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 444 | \ |
Sean Young | 69165c2 | 2006-05-02 11:44:43 +0000 | [diff] [blame] | 445 | return sprintf(buf, "%d\n", !!test_bit(value - 1, &kit->outputs));\ |
Sean Young | da308e8 | 2006-08-11 09:28:28 +0000 | [diff] [blame] | 446 | } |
| 447 | |
| 448 | #define output_attr(value) \ |
| 449 | __ATTR(output##value, S_IWUGO | S_IRUGO, \ |
| 450 | show_output##value, set_output##value) |
| 451 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 452 | show_set_output(1); |
| 453 | show_set_output(2); |
| 454 | show_set_output(3); |
| 455 | show_set_output(4); |
| 456 | show_set_output(5); |
| 457 | show_set_output(6); |
| 458 | show_set_output(7); |
Sean Young | 69165c2 | 2006-05-02 11:44:43 +0000 | [diff] [blame] | 459 | show_set_output(8); |
| 460 | show_set_output(9); |
| 461 | show_set_output(10); |
| 462 | show_set_output(11); |
| 463 | show_set_output(12); |
| 464 | show_set_output(13); |
| 465 | show_set_output(14); |
| 466 | show_set_output(15); |
| 467 | show_set_output(16); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 468 | |
Sean Young | da308e8 | 2006-08-11 09:28:28 +0000 | [diff] [blame] | 469 | static struct device_attribute dev_output_attrs[] = { |
| 470 | output_attr(1), output_attr(2), output_attr(3), output_attr(4), |
| 471 | output_attr(5), output_attr(6), output_attr(7), output_attr(8), |
| 472 | output_attr(9), output_attr(10), output_attr(11), output_attr(12), |
| 473 | output_attr(13), output_attr(14), output_attr(15), output_attr(16) |
| 474 | }; |
| 475 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 476 | #define show_input(value) \ |
Sean Young | da308e8 | 2006-08-11 09:28:28 +0000 | [diff] [blame] | 477 | static ssize_t show_input##value(struct device *dev, \ |
| 478 | struct device_attribute *attr, char *buf) \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 479 | { \ |
Sean Young | 912b24c | 2006-07-10 09:56:25 +0000 | [diff] [blame] | 480 | struct interfacekit *kit = dev_get_drvdata(dev); \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 481 | \ |
Sean Young | 69165c2 | 2006-05-02 11:44:43 +0000 | [diff] [blame] | 482 | return sprintf(buf, "%d\n", (int)kit->inputs[value - 1]); \ |
Sean Young | da308e8 | 2006-08-11 09:28:28 +0000 | [diff] [blame] | 483 | } |
| 484 | |
| 485 | #define input_attr(value) \ |
| 486 | __ATTR(input##value, S_IRUGO, show_input##value, NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 487 | |
| 488 | show_input(1); |
| 489 | show_input(2); |
| 490 | show_input(3); |
| 491 | show_input(4); |
| 492 | show_input(5); |
| 493 | show_input(6); |
| 494 | show_input(7); |
Sean Young | 69165c2 | 2006-05-02 11:44:43 +0000 | [diff] [blame] | 495 | show_input(8); |
| 496 | show_input(9); |
| 497 | show_input(10); |
| 498 | show_input(11); |
| 499 | show_input(12); |
| 500 | show_input(13); |
| 501 | show_input(14); |
| 502 | show_input(15); |
| 503 | show_input(16); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 504 | |
Sean Young | da308e8 | 2006-08-11 09:28:28 +0000 | [diff] [blame] | 505 | static struct device_attribute dev_input_attrs[] = { |
| 506 | input_attr(1), input_attr(2), input_attr(3), input_attr(4), |
| 507 | input_attr(5), input_attr(6), input_attr(7), input_attr(8), |
| 508 | input_attr(9), input_attr(10), input_attr(11), input_attr(12), |
| 509 | input_attr(13), input_attr(14), input_attr(15), input_attr(16) |
| 510 | }; |
| 511 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 512 | #define show_sensor(value) \ |
Sean Young | 912b24c | 2006-07-10 09:56:25 +0000 | [diff] [blame] | 513 | static ssize_t show_sensor##value(struct device *dev, \ |
| 514 | struct device_attribute *attr, \ |
| 515 | char *buf) \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 516 | { \ |
Sean Young | 912b24c | 2006-07-10 09:56:25 +0000 | [diff] [blame] | 517 | struct interfacekit *kit = dev_get_drvdata(dev); \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 518 | \ |
Sean Young | 69165c2 | 2006-05-02 11:44:43 +0000 | [diff] [blame] | 519 | return sprintf(buf, "%d\n", (int)kit->sensors[value - 1]); \ |
Sean Young | da308e8 | 2006-08-11 09:28:28 +0000 | [diff] [blame] | 520 | } |
| 521 | |
| 522 | #define sensor_attr(value) \ |
| 523 | __ATTR(sensor##value, S_IRUGO, show_sensor##value, NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 524 | |
| 525 | show_sensor(1); |
| 526 | show_sensor(2); |
| 527 | show_sensor(3); |
| 528 | show_sensor(4); |
| 529 | show_sensor(5); |
| 530 | show_sensor(6); |
| 531 | show_sensor(7); |
Sean Young | 69165c2 | 2006-05-02 11:44:43 +0000 | [diff] [blame] | 532 | show_sensor(8); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 533 | |
Sean Young | da308e8 | 2006-08-11 09:28:28 +0000 | [diff] [blame] | 534 | static struct device_attribute dev_sensor_attrs[] = { |
| 535 | sensor_attr(1), sensor_attr(2), sensor_attr(3), sensor_attr(4), |
| 536 | sensor_attr(5), sensor_attr(6), sensor_attr(7), sensor_attr(8) |
| 537 | }; |
| 538 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 539 | static int interfacekit_probe(struct usb_interface *intf, const struct usb_device_id *id) |
| 540 | { |
| 541 | struct usb_device *dev = interface_to_usbdev(intf); |
| 542 | struct usb_host_interface *interface; |
| 543 | struct usb_endpoint_descriptor *endpoint; |
Sean Young | 69165c2 | 2006-05-02 11:44:43 +0000 | [diff] [blame] | 544 | struct interfacekit *kit; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 545 | struct driver_interfacekit *ifkit; |
Sean Young | 69165c2 | 2006-05-02 11:44:43 +0000 | [diff] [blame] | 546 | int pipe, maxp, rc = -ENOMEM; |
Sean Young | da308e8 | 2006-08-11 09:28:28 +0000 | [diff] [blame] | 547 | int bit, value, i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 548 | |
| 549 | ifkit = (struct driver_interfacekit *)id->driver_info; |
| 550 | if (!ifkit) |
| 551 | return -ENODEV; |
| 552 | |
| 553 | interface = intf->cur_altsetting; |
| 554 | if (interface->desc.bNumEndpoints != 1) |
| 555 | return -ENODEV; |
| 556 | |
| 557 | endpoint = &interface->endpoint[0].desc; |
Luiz Fernando N. Capitulino | 8419404 | 2006-10-26 13:02:56 -0300 | [diff] [blame] | 558 | if (!usb_endpoint_dir_in(endpoint)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 559 | return -ENODEV; |
| 560 | /* |
| 561 | * bmAttributes |
| 562 | */ |
| 563 | pipe = usb_rcvintpipe(dev, endpoint->bEndpointAddress); |
| 564 | maxp = usb_maxpacket(dev, pipe, usb_pipeout(pipe)); |
| 565 | |
Oliver Neukum | 1759084 | 2006-01-06 22:41:51 +0100 | [diff] [blame] | 566 | kit = kzalloc(sizeof(*kit), GFP_KERNEL); |
Sean Young | 69165c2 | 2006-05-02 11:44:43 +0000 | [diff] [blame] | 567 | if (!kit) |
| 568 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 569 | |
Sean Young | 912b24c | 2006-07-10 09:56:25 +0000 | [diff] [blame] | 570 | kit->dev_no = -1; |
Sean Young | 69165c2 | 2006-05-02 11:44:43 +0000 | [diff] [blame] | 571 | kit->ifkit = ifkit; |
Christoph Lameter | 54e6ecb | 2006-12-06 20:33:16 -0800 | [diff] [blame] | 572 | kit->data = usb_buffer_alloc(dev, URB_INT_SIZE, GFP_ATOMIC, &kit->data_dma); |
Sean Young | 69165c2 | 2006-05-02 11:44:43 +0000 | [diff] [blame] | 573 | if (!kit->data) |
| 574 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 575 | |
| 576 | kit->irq = usb_alloc_urb(0, GFP_KERNEL); |
Sean Young | 69165c2 | 2006-05-02 11:44:43 +0000 | [diff] [blame] | 577 | if (!kit->irq) |
| 578 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 579 | |
| 580 | kit->udev = usb_get_dev(dev); |
| 581 | kit->intf = intf; |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 582 | INIT_DELAYED_WORK(&kit->do_notify, do_notify); |
| 583 | INIT_DELAYED_WORK(&kit->do_resubmit, do_resubmit); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 584 | usb_fill_int_urb(kit->irq, kit->udev, pipe, kit->data, |
Sean Young | 69165c2 | 2006-05-02 11:44:43 +0000 | [diff] [blame] | 585 | maxp > URB_INT_SIZE ? URB_INT_SIZE : maxp, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 586 | interfacekit_irq, kit, endpoint->bInterval); |
| 587 | kit->irq->transfer_dma = kit->data_dma; |
| 588 | kit->irq->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; |
| 589 | |
| 590 | usb_set_intfdata(intf, kit); |
| 591 | |
Sean Young | 912b24c | 2006-07-10 09:56:25 +0000 | [diff] [blame] | 592 | do { |
| 593 | bit = find_first_zero_bit(&device_no, sizeof(device_no)); |
| 594 | value = test_and_set_bit(bit, &device_no); |
| 595 | } while(value); |
| 596 | kit->dev_no = bit; |
| 597 | |
| 598 | kit->dev = device_create(phidget_class, &kit->udev->dev, 0, |
| 599 | "interfacekit%d", kit->dev_no); |
| 600 | if (IS_ERR(kit->dev)) { |
| 601 | rc = PTR_ERR(kit->dev); |
| 602 | kit->dev = NULL; |
| 603 | goto out; |
| 604 | } |
| 605 | dev_set_drvdata(kit->dev, kit); |
| 606 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 607 | if (usb_submit_urb(kit->irq, GFP_KERNEL)) { |
Sean Young | 69165c2 | 2006-05-02 11:44:43 +0000 | [diff] [blame] | 608 | rc = -EIO; |
| 609 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 610 | } |
| 611 | |
Sean Young | da308e8 | 2006-08-11 09:28:28 +0000 | [diff] [blame] | 612 | for (i=0; i<ifkit->outputs; i++ ) { |
| 613 | rc = device_create_file(kit->dev, &dev_output_attrs[i]); |
| 614 | if (rc) |
| 615 | goto out2; |
Sean Young | 69165c2 | 2006-05-02 11:44:43 +0000 | [diff] [blame] | 616 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 617 | |
Sean Young | da308e8 | 2006-08-11 09:28:28 +0000 | [diff] [blame] | 618 | for (i=0; i<ifkit->inputs; i++ ) { |
| 619 | rc = device_create_file(kit->dev, &dev_input_attrs[i]); |
| 620 | if (rc) |
| 621 | goto out3; |
Sean Young | 69165c2 | 2006-05-02 11:44:43 +0000 | [diff] [blame] | 622 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 623 | |
Sean Young | da308e8 | 2006-08-11 09:28:28 +0000 | [diff] [blame] | 624 | for (i=0; i<ifkit->sensors; i++ ) { |
| 625 | rc = device_create_file(kit->dev, &dev_sensor_attrs[i]); |
| 626 | if (rc) |
| 627 | goto out4; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 628 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 629 | |
Sean Young | da308e8 | 2006-08-11 09:28:28 +0000 | [diff] [blame] | 630 | if (ifkit->has_lcd) { |
| 631 | rc = device_create_file(kit->dev, &dev_attr_lcd); |
| 632 | if (rc) |
| 633 | goto out4; |
| 634 | |
| 635 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 636 | |
| 637 | dev_info(&intf->dev, "USB PhidgetInterfaceKit %d/%d/%d attached\n", |
| 638 | ifkit->sensors, ifkit->inputs, ifkit->outputs); |
| 639 | |
| 640 | return 0; |
Sean Young | 69165c2 | 2006-05-02 11:44:43 +0000 | [diff] [blame] | 641 | |
Sean Young | da308e8 | 2006-08-11 09:28:28 +0000 | [diff] [blame] | 642 | out4: |
| 643 | while (i-- > 0) |
| 644 | device_remove_file(kit->dev, &dev_sensor_attrs[i]); |
| 645 | |
| 646 | i = ifkit->inputs; |
| 647 | out3: |
| 648 | while (i-- > 0) |
| 649 | device_remove_file(kit->dev, &dev_input_attrs[i]); |
| 650 | |
| 651 | i = ifkit->outputs; |
| 652 | out2: |
| 653 | while (i-- > 0) |
| 654 | device_remove_file(kit->dev, &dev_output_attrs[i]); |
Sean Young | 69165c2 | 2006-05-02 11:44:43 +0000 | [diff] [blame] | 655 | out: |
| 656 | if (kit) { |
Mariusz Kozlowski | df43121 | 2006-11-08 15:36:07 +0100 | [diff] [blame] | 657 | usb_free_urb(kit->irq); |
Sean Young | 69165c2 | 2006-05-02 11:44:43 +0000 | [diff] [blame] | 658 | if (kit->data) |
| 659 | usb_buffer_free(dev, URB_INT_SIZE, kit->data, kit->data_dma); |
Sean Young | 912b24c | 2006-07-10 09:56:25 +0000 | [diff] [blame] | 660 | if (kit->dev) |
| 661 | device_unregister(kit->dev); |
| 662 | if (kit->dev_no >= 0) |
| 663 | clear_bit(kit->dev_no, &device_no); |
| 664 | |
Sean Young | 69165c2 | 2006-05-02 11:44:43 +0000 | [diff] [blame] | 665 | kfree(kit); |
| 666 | } |
| 667 | |
| 668 | return rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 669 | } |
| 670 | |
| 671 | static void interfacekit_disconnect(struct usb_interface *interface) |
| 672 | { |
Sean Young | 69165c2 | 2006-05-02 11:44:43 +0000 | [diff] [blame] | 673 | struct interfacekit *kit; |
Sean Young | da308e8 | 2006-08-11 09:28:28 +0000 | [diff] [blame] | 674 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 675 | |
| 676 | kit = usb_get_intfdata(interface); |
| 677 | usb_set_intfdata(interface, NULL); |
| 678 | if (!kit) |
| 679 | return; |
| 680 | |
Sean Young | 69165c2 | 2006-05-02 11:44:43 +0000 | [diff] [blame] | 681 | usb_kill_urb(kit->irq); |
| 682 | usb_free_urb(kit->irq); |
| 683 | usb_buffer_free(kit->udev, URB_INT_SIZE, kit->data, kit->data_dma); |
| 684 | |
| 685 | cancel_delayed_work(&kit->do_notify); |
Sean Young | 238d0e7 | 2006-09-24 19:26:57 +0000 | [diff] [blame] | 686 | cancel_delayed_work(&kit->do_resubmit); |
Sean Young | 69165c2 | 2006-05-02 11:44:43 +0000 | [diff] [blame] | 687 | |
Sean Young | da308e8 | 2006-08-11 09:28:28 +0000 | [diff] [blame] | 688 | for (i=0; i<kit->ifkit->outputs; i++) |
| 689 | device_remove_file(kit->dev, &dev_output_attrs[i]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 690 | |
Sean Young | da308e8 | 2006-08-11 09:28:28 +0000 | [diff] [blame] | 691 | for (i=0; i<kit->ifkit->inputs; i++) |
| 692 | device_remove_file(kit->dev, &dev_input_attrs[i]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 693 | |
Sean Young | da308e8 | 2006-08-11 09:28:28 +0000 | [diff] [blame] | 694 | for (i=0; i<kit->ifkit->sensors; i++) |
| 695 | device_remove_file(kit->dev, &dev_sensor_attrs[i]); |
Sean Young | 69165c2 | 2006-05-02 11:44:43 +0000 | [diff] [blame] | 696 | |
Sean Young | da308e8 | 2006-08-11 09:28:28 +0000 | [diff] [blame] | 697 | if (kit->ifkit->has_lcd) { |
Sean Young | 912b24c | 2006-07-10 09:56:25 +0000 | [diff] [blame] | 698 | device_remove_file(kit->dev, &dev_attr_lcd); |
Sean Young | da308e8 | 2006-08-11 09:28:28 +0000 | [diff] [blame] | 699 | remove_lcd_files(kit); |
| 700 | } |
Sean Young | 912b24c | 2006-07-10 09:56:25 +0000 | [diff] [blame] | 701 | |
| 702 | device_unregister(kit->dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 703 | |
| 704 | dev_info(&interface->dev, "USB PhidgetInterfaceKit %d/%d/%d detached\n", |
| 705 | kit->ifkit->sensors, kit->ifkit->inputs, kit->ifkit->outputs); |
| 706 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 707 | usb_put_dev(kit->udev); |
Sean Young | 912b24c | 2006-07-10 09:56:25 +0000 | [diff] [blame] | 708 | clear_bit(kit->dev_no, &device_no); |
| 709 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 710 | kfree(kit); |
| 711 | } |
| 712 | |
| 713 | static struct usb_driver interfacekit_driver = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 714 | .name = "phidgetkit", |
| 715 | .probe = interfacekit_probe, |
| 716 | .disconnect = interfacekit_disconnect, |
| 717 | .id_table = id_table |
| 718 | }; |
| 719 | |
| 720 | static int __init interfacekit_init(void) |
| 721 | { |
| 722 | int retval = 0; |
| 723 | |
| 724 | retval = usb_register(&interfacekit_driver); |
| 725 | if (retval) |
| 726 | err("usb_register failed. Error number %d", retval); |
| 727 | |
| 728 | return retval; |
| 729 | } |
| 730 | |
| 731 | static void __exit interfacekit_exit(void) |
| 732 | { |
| 733 | usb_deregister(&interfacekit_driver); |
| 734 | } |
| 735 | |
| 736 | module_init(interfacekit_init); |
| 737 | module_exit(interfacekit_exit); |
| 738 | |
| 739 | MODULE_AUTHOR(DRIVER_AUTHOR); |
| 740 | MODULE_DESCRIPTION(DRIVER_DESC); |
| 741 | MODULE_LICENSE("GPL"); |