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