aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/usb/misc
diff options
context:
space:
mode:
authorGreg Kroah-Hartman <gregkh@suse.de>2009-03-04 19:23:31 -0500
committerGreg Kroah-Hartman <gregkh@suse.de>2009-03-24 19:20:37 -0400
commit77aa2b5878f48d6ab6e0c412cc9214c845483475 (patch)
treecdd7dd8d0cf059971c4c5f5cad17c1b8e0694edb /drivers/usb/misc
parent8c209e6782ca0e3046803fc04a5ac01c8c10437a (diff)
USB: remove phidget drivers from kernel tree.
These devices are better controlled with the LGPL userspace library found at: http://www.phidgets.com/downloads.php?os_id=3 and full documentation at: http://www.phidgets.com/documentation/web/cdoc/index.html Cc: Chester Fitchett <fitchett@phidgets.com> Acked-by: Sean Young <sean@mess.org> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'drivers/usb/misc')
-rw-r--r--drivers/usb/misc/Kconfig39
-rw-r--r--drivers/usb/misc/Makefile4
-rw-r--r--drivers/usb/misc/phidget.c43
-rw-r--r--drivers/usb/misc/phidget.h12
-rw-r--r--drivers/usb/misc/phidgetkit.c740
-rw-r--r--drivers/usb/misc/phidgetmotorcontrol.c465
-rw-r--r--drivers/usb/misc/phidgetservo.c375
7 files changed, 0 insertions, 1678 deletions
diff --git a/drivers/usb/misc/Kconfig b/drivers/usb/misc/Kconfig
index e463db5d8188..a68d91a11bee 100644
--- a/drivers/usb/misc/Kconfig
+++ b/drivers/usb/misc/Kconfig
@@ -135,45 +135,6 @@ config USB_CYTHERM
135 To compile this driver as a module, choose M here: the 135 To compile this driver as a module, choose M here: the
136 module will be called cytherm. 136 module will be called cytherm.
137 137
138config USB_PHIDGET
139 tristate "USB Phidgets drivers"
140 depends on USB
141 help
142 Say Y here to enable the various drivers for devices from
143 Phidgets inc.
144
145config USB_PHIDGETKIT
146 tristate "USB PhidgetInterfaceKit support"
147 depends on USB_PHIDGET
148 help
149 Say Y here if you want to connect a PhidgetInterfaceKit USB device
150 from Phidgets Inc.
151
152 To compile this driver as a module, choose M here: the
153 module will be called phidgetkit.
154
155config USB_PHIDGETMOTORCONTROL
156 tristate "USB PhidgetMotorControl support"
157 depends on USB_PHIDGET
158 help
159 Say Y here if you want to connect a PhidgetMotorControl USB device
160 from Phidgets Inc.
161
162 To compile this driver as a module, choose M here: the
163 module will be called phidgetmotorcontrol.
164
165config USB_PHIDGETSERVO
166 tristate "USB PhidgetServo support"
167 depends on USB_PHIDGET
168 help
169 Say Y here if you want to connect an 1 or 4 Motor PhidgetServo
170 servo controller version 2.0 or 3.0.
171
172 Phidgets Inc. has a web page at <http://www.phidgets.com/>.
173
174 To compile this driver as a module, choose M here: the
175 module will be called phidgetservo.
176
177config USB_IDMOUSE 138config USB_IDMOUSE
178 tristate "Siemens ID USB Mouse Fingerprint sensor support" 139 tristate "Siemens ID USB Mouse Fingerprint sensor support"
179 depends on USB 140 depends on USB
diff --git a/drivers/usb/misc/Makefile b/drivers/usb/misc/Makefile
index 1334f7bdd7be..0826aab8303f 100644
--- a/drivers/usb/misc/Makefile
+++ b/drivers/usb/misc/Makefile
@@ -18,10 +18,6 @@ obj-$(CONFIG_USB_LCD) += usblcd.o
18obj-$(CONFIG_USB_LD) += ldusb.o 18obj-$(CONFIG_USB_LD) += ldusb.o
19obj-$(CONFIG_USB_LED) += usbled.o 19obj-$(CONFIG_USB_LED) += usbled.o
20obj-$(CONFIG_USB_LEGOTOWER) += legousbtower.o 20obj-$(CONFIG_USB_LEGOTOWER) += legousbtower.o
21obj-$(CONFIG_USB_PHIDGET) += phidget.o
22obj-$(CONFIG_USB_PHIDGETKIT) += phidgetkit.o
23obj-$(CONFIG_USB_PHIDGETMOTORCONTROL) += phidgetmotorcontrol.o
24obj-$(CONFIG_USB_PHIDGETSERVO) += phidgetservo.o
25obj-$(CONFIG_USB_RIO500) += rio500.o 21obj-$(CONFIG_USB_RIO500) += rio500.o
26obj-$(CONFIG_USB_TEST) += usbtest.o 22obj-$(CONFIG_USB_TEST) += usbtest.o
27obj-$(CONFIG_USB_TRANCEVIBRATOR) += trancevibrator.o 23obj-$(CONFIG_USB_TRANCEVIBRATOR) += trancevibrator.o
diff --git a/drivers/usb/misc/phidget.c b/drivers/usb/misc/phidget.c
deleted file mode 100644
index 735ed33f4f7f..000000000000
--- a/drivers/usb/misc/phidget.c
+++ /dev/null
@@ -1,43 +0,0 @@
1/*
2 * USB Phidgets class
3 *
4 * Copyright (C) 2006 Sean Young <sean@mess.org>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 */
11
12#include <linux/kernel.h>
13#include <linux/module.h>
14#include <linux/init.h>
15#include <linux/err.h>
16#include <linux/device.h>
17
18struct class *phidget_class;
19
20static int __init init_phidget(void)
21{
22 phidget_class = class_create(THIS_MODULE, "phidget");
23
24 if (IS_ERR(phidget_class))
25 return PTR_ERR(phidget_class);
26
27 return 0;
28}
29
30static void __exit cleanup_phidget(void)
31{
32 class_destroy(phidget_class);
33}
34
35EXPORT_SYMBOL_GPL(phidget_class);
36
37module_init(init_phidget);
38module_exit(cleanup_phidget);
39
40MODULE_LICENSE("GPL");
41MODULE_AUTHOR("Sean Young <sean@mess.org>");
42MODULE_DESCRIPTION("Container module for phidget class");
43
diff --git a/drivers/usb/misc/phidget.h b/drivers/usb/misc/phidget.h
deleted file mode 100644
index c4011907d431..000000000000
--- a/drivers/usb/misc/phidget.h
+++ /dev/null
@@ -1,12 +0,0 @@
1/*
2 * USB Phidgets class
3 *
4 * Copyright (C) 2006 Sean Young <sean@mess.org>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 */
11
12extern struct class *phidget_class;
diff --git a/drivers/usb/misc/phidgetkit.c b/drivers/usb/misc/phidgetkit.c
deleted file mode 100644
index cc8e0a926f99..000000000000
--- a/drivers/usb/misc/phidgetkit.c
+++ /dev/null
@@ -1,740 +0,0 @@
1/*
2 * USB PhidgetInterfaceKit driver 1.0
3 *
4 * Copyright (C) 2004, 2006 Sean Young <sean@mess.org>
5 * Copyright (C) 2005 Daniel Saakes <daniel@saakes.net>
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
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
23#include "phidget.h"
24
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
30#define USB_DEVICE_ID_INTERFACEKIT01616 0x0044
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
38#define MAX_INTERFACES 16
39
40#define URB_INT_SIZE 8
41
42struct driver_interfacekit {
43 int sensors;
44 int inputs;
45 int outputs;
46 int has_lcd;
47 int amnesiac;
48};
49
50#define ifkit(_sensors, _inputs, _outputs, _lcd, _amnesiac) \
51{ \
52 .sensors = _sensors, \
53 .inputs = _inputs, \
54 .outputs = _outputs, \
55 .has_lcd = _lcd, \
56 .amnesiac = _amnesiac \
57};
58
59static const struct driver_interfacekit ph_004 = ifkit(0, 0, 4, 0, 0);
60static const struct driver_interfacekit ph_888n = ifkit(8, 8, 8, 0, 1);
61static const struct driver_interfacekit ph_888o = ifkit(8, 8, 8, 0, 0);
62static const struct driver_interfacekit ph_047 = ifkit(0, 4, 7, 1, 0);
63static const struct driver_interfacekit ph_884 = ifkit(8, 8, 4, 0, 0);
64static const struct driver_interfacekit ph_088 = ifkit(0, 8, 8, 1, 0);
65static const struct driver_interfacekit ph_01616 = ifkit(0, 16, 16, 0, 0);
66
67static unsigned long device_no;
68
69struct interfacekit {
70 struct usb_device *udev;
71 struct usb_interface *intf;
72 struct driver_interfacekit *ifkit;
73 struct device *dev;
74 unsigned long outputs;
75 int dev_no;
76 u8 inputs[MAX_INTERFACES];
77 u16 sensors[MAX_INTERFACES];
78 u8 lcd_files_on;
79
80 struct urb *irq;
81 unsigned char *data;
82 dma_addr_t data_dma;
83
84 struct delayed_work do_notify;
85 struct delayed_work do_resubmit;
86 unsigned long input_events;
87 unsigned long sensor_events;
88};
89
90static 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},
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},
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},
101 {USB_DEVICE(USB_VENDOR_ID_GLAB, USB_DEVICE_ID_INTERFACEKIT01616),
102 .driver_info = (kernel_ulong_t)&ph_01616},
103 {USB_DEVICE(USB_VENDOR_ID_WISEGROUP, USB_DEVICE_ID_INTERFACEKIT884),
104 .driver_info = (kernel_ulong_t)&ph_884},
105 {}
106};
107MODULE_DEVICE_TABLE(usb, id_table);
108
109static int set_outputs(struct interfacekit *kit)
110{
111 u8 *buffer;
112 int retval;
113
114 buffer = kzalloc(4, GFP_KERNEL);
115 if (!buffer) {
116 dev_err(&kit->udev->dev, "%s - out of memory\n", __func__);
117 return -ENOMEM;
118 }
119 buffer[0] = (u8)kit->outputs;
120 buffer[1] = (u8)(kit->outputs >> 8);
121
122 dev_dbg(&kit->udev->dev, "sending data: 0x%04x\n", (u16)kit->outputs);
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
133 if (kit->ifkit->amnesiac)
134 schedule_delayed_work(&kit->do_resubmit, HZ / 2);
135
136 return retval < 0 ? retval : 0;
137}
138
139static int change_string(struct interfacekit *kit, const char *display, unsigned char row)
140{
141 unsigned char *buffer;
142 unsigned char *form_buffer;
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)) {
149 dev_err(&kit->udev->dev, "%s - out of memory\n", __func__);
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;
187exit:
188 kfree(buffer);
189 kfree(form_buffer);
190
191 return retval;
192}
193
194#define set_lcd_line(number) \
195static 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; \
202}
203
204#define lcd_line_attr(number) \
205 __ATTR(lcd_line_##number, S_IWUGO, NULL, lcd_line_##number)
206
207set_lcd_line(1);
208set_lcd_line(2);
209
210static ssize_t set_backlight(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
211{
212 struct interfacekit *kit = dev_get_drvdata(dev);
213 int enabled;
214 unsigned char *buffer;
215 int retval = -ENOMEM;
216
217 buffer = kzalloc(8, GFP_KERNEL);
218 if (!buffer) {
219 dev_err(&kit->udev->dev, "%s - out of memory\n", __func__);
220 goto exit;
221 }
222
223 if (sscanf(buf, "%d", &enabled) < 1) {
224 retval = -EINVAL;
225 goto exit;
226 }
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;
240exit:
241 kfree(buffer);
242 return retval;
243}
244
245static 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};
250
251static void remove_lcd_files(struct interfacekit *kit)
252{
253 int i;
254
255 if (kit->lcd_files_on) {
256 dev_dbg(&kit->udev->dev, "Removing lcd files\n");
257
258 for (i=0; i<ARRAY_SIZE(dev_lcd_line_attrs); i++)
259 device_remove_file(kit->dev, &dev_lcd_line_attrs[i]);
260 }
261}
262
263static ssize_t enable_lcd_files(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
264{
265 struct interfacekit *kit = dev_get_drvdata(dev);
266 int enable;
267 int i, rc;
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");
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 }
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;
294out:
295 while (i-- > 0)
296 device_remove_file(kit->dev, &dev_lcd_line_attrs[i]);
297
298 return rc;
299}
300
301static DEVICE_ATTR(lcd, S_IWUGO, NULL, enable_lcd_files);
302
303static void interfacekit_irq(struct urb *urb)
304{
305 struct interfacekit *kit = urb->context;
306 unsigned char *buffer = kit->data;
307 int i, level, sensor;
308 int retval;
309 int status = urb->status;
310
311 switch (status) {
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
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 }
346 }
347
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 }
375 }
376
377 if (kit->input_events || kit->sensor_events)
378 schedule_delayed_work(&kit->do_notify, 0);
379
380resubmit:
381 retval = usb_submit_urb(urb, GFP_ATOMIC);
382 if (retval)
383 err("can't resubmit intr, %s-%s/interfacekit0, retval %d",
384 kit->udev->bus->bus_name,
385 kit->udev->devpath, retval);
386}
387
388static void do_notify(struct work_struct *work)
389{
390 struct interfacekit *kit =
391 container_of(work, struct interfacekit, do_notify.work);
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);
398 sysfs_notify(&kit->dev->kobj, NULL, sysfs_file);
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);
405 sysfs_notify(&kit->dev->kobj, NULL, sysfs_file);
406 }
407 }
408}
409
410static void do_resubmit(struct work_struct *work)
411{
412 struct interfacekit *kit =
413 container_of(work, struct interfacekit, do_resubmit.work);
414 set_outputs(kit);
415}
416
417#define show_set_output(value) \
418static ssize_t set_output##value(struct device *dev, \
419 struct device_attribute *attr, \
420 const char *buf, size_t count) \
421{ \
422 struct interfacekit *kit = dev_get_drvdata(dev); \
423 int enable; \
424 int retval; \
425 \
426 if (sscanf(buf, "%d", &enable) < 1) \
427 return -EINVAL; \
428 \
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); \
435 \
436 return retval ? retval : count; \
437} \
438 \
439static ssize_t show_output##value(struct device *dev, \
440 struct device_attribute *attr, \
441 char *buf) \
442{ \
443 struct interfacekit *kit = dev_get_drvdata(dev); \
444 \
445 return sprintf(buf, "%d\n", !!test_bit(value - 1, &kit->outputs));\
446}
447
448#define output_attr(value) \
449 __ATTR(output##value, S_IWUGO | S_IRUGO, \
450 show_output##value, set_output##value)
451
452show_set_output(1);
453show_set_output(2);
454show_set_output(3);
455show_set_output(4);
456show_set_output(5);
457show_set_output(6);
458show_set_output(7);
459show_set_output(8);
460show_set_output(9);
461show_set_output(10);
462show_set_output(11);
463show_set_output(12);
464show_set_output(13);
465show_set_output(14);
466show_set_output(15);
467show_set_output(16);
468
469static 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
476#define show_input(value) \
477static ssize_t show_input##value(struct device *dev, \
478 struct device_attribute *attr, char *buf) \
479{ \
480 struct interfacekit *kit = dev_get_drvdata(dev); \
481 \
482 return sprintf(buf, "%d\n", (int)kit->inputs[value - 1]); \
483}
484
485#define input_attr(value) \
486 __ATTR(input##value, S_IRUGO, show_input##value, NULL)
487
488show_input(1);
489show_input(2);
490show_input(3);
491show_input(4);
492show_input(5);
493show_input(6);
494show_input(7);
495show_input(8);
496show_input(9);
497show_input(10);
498show_input(11);
499show_input(12);
500show_input(13);
501show_input(14);
502show_input(15);
503show_input(16);
504
505static 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
512#define show_sensor(value) \
513static ssize_t show_sensor##value(struct device *dev, \
514 struct device_attribute *attr, \
515 char *buf) \
516{ \
517 struct interfacekit *kit = dev_get_drvdata(dev); \
518 \
519 return sprintf(buf, "%d\n", (int)kit->sensors[value - 1]); \
520}
521
522#define sensor_attr(value) \
523 __ATTR(sensor##value, S_IRUGO, show_sensor##value, NULL)
524
525show_sensor(1);
526show_sensor(2);
527show_sensor(3);
528show_sensor(4);
529show_sensor(5);
530show_sensor(6);
531show_sensor(7);
532show_sensor(8);
533
534static 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
539static 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;
544 struct interfacekit *kit;
545 struct driver_interfacekit *ifkit;
546 int pipe, maxp, rc = -ENOMEM;
547 int bit, value, i;
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;
558 if (!usb_endpoint_dir_in(endpoint))
559 return -ENODEV;
560 /*
561 * bmAttributes
562 */
563 pipe = usb_rcvintpipe(dev, endpoint->bEndpointAddress);
564 maxp = usb_maxpacket(dev, pipe, usb_pipeout(pipe));
565
566 kit = kzalloc(sizeof(*kit), GFP_KERNEL);
567 if (!kit)
568 goto out;
569
570 kit->dev_no = -1;
571 kit->ifkit = ifkit;
572 kit->data = usb_buffer_alloc(dev, URB_INT_SIZE, GFP_ATOMIC, &kit->data_dma);
573 if (!kit->data)
574 goto out;
575
576 kit->irq = usb_alloc_urb(0, GFP_KERNEL);
577 if (!kit->irq)
578 goto out;
579
580 kit->udev = usb_get_dev(dev);
581 kit->intf = intf;
582 INIT_DELAYED_WORK(&kit->do_notify, do_notify);
583 INIT_DELAYED_WORK(&kit->do_resubmit, do_resubmit);
584 usb_fill_int_urb(kit->irq, kit->udev, pipe, kit->data,
585 maxp > URB_INT_SIZE ? URB_INT_SIZE : maxp,
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
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, MKDEV(0, 0),
599 kit, "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
606 if (usb_submit_urb(kit->irq, GFP_KERNEL)) {
607 rc = -EIO;
608 goto out;
609 }
610
611 for (i=0; i<ifkit->outputs; i++ ) {
612 rc = device_create_file(kit->dev, &dev_output_attrs[i]);
613 if (rc)
614 goto out2;
615 }
616
617 for (i=0; i<ifkit->inputs; i++ ) {
618 rc = device_create_file(kit->dev, &dev_input_attrs[i]);
619 if (rc)
620 goto out3;
621 }
622
623 for (i=0; i<ifkit->sensors; i++ ) {
624 rc = device_create_file(kit->dev, &dev_sensor_attrs[i]);
625 if (rc)
626 goto out4;
627 }
628
629 if (ifkit->has_lcd) {
630 rc = device_create_file(kit->dev, &dev_attr_lcd);
631 if (rc)
632 goto out4;
633
634 }
635
636 dev_info(&intf->dev, "USB PhidgetInterfaceKit %d/%d/%d attached\n",
637 ifkit->sensors, ifkit->inputs, ifkit->outputs);
638
639 return 0;
640
641out4:
642 while (i-- > 0)
643 device_remove_file(kit->dev, &dev_sensor_attrs[i]);
644
645 i = ifkit->inputs;
646out3:
647 while (i-- > 0)
648 device_remove_file(kit->dev, &dev_input_attrs[i]);
649
650 i = ifkit->outputs;
651out2:
652 while (i-- > 0)
653 device_remove_file(kit->dev, &dev_output_attrs[i]);
654out:
655 if (kit) {
656 usb_free_urb(kit->irq);
657 if (kit->data)
658 usb_buffer_free(dev, URB_INT_SIZE, kit->data, kit->data_dma);
659 if (kit->dev)
660 device_unregister(kit->dev);
661 if (kit->dev_no >= 0)
662 clear_bit(kit->dev_no, &device_no);
663
664 kfree(kit);
665 }
666
667 return rc;
668}
669
670static void interfacekit_disconnect(struct usb_interface *interface)
671{
672 struct interfacekit *kit;
673 int i;
674
675 kit = usb_get_intfdata(interface);
676 usb_set_intfdata(interface, NULL);
677 if (!kit)
678 return;
679
680 usb_kill_urb(kit->irq);
681 usb_free_urb(kit->irq);
682 usb_buffer_free(kit->udev, URB_INT_SIZE, kit->data, kit->data_dma);
683
684 cancel_delayed_work(&kit->do_notify);
685 cancel_delayed_work(&kit->do_resubmit);
686
687 for (i=0; i<kit->ifkit->outputs; i++)
688 device_remove_file(kit->dev, &dev_output_attrs[i]);
689
690 for (i=0; i<kit->ifkit->inputs; i++)
691 device_remove_file(kit->dev, &dev_input_attrs[i]);
692
693 for (i=0; i<kit->ifkit->sensors; i++)
694 device_remove_file(kit->dev, &dev_sensor_attrs[i]);
695
696 if (kit->ifkit->has_lcd) {
697 device_remove_file(kit->dev, &dev_attr_lcd);
698 remove_lcd_files(kit);
699 }
700
701 device_unregister(kit->dev);
702
703 dev_info(&interface->dev, "USB PhidgetInterfaceKit %d/%d/%d detached\n",
704 kit->ifkit->sensors, kit->ifkit->inputs, kit->ifkit->outputs);
705
706 usb_put_dev(kit->udev);
707 clear_bit(kit->dev_no, &device_no);
708
709 kfree(kit);
710}
711
712static struct usb_driver interfacekit_driver = {
713 .name = "phidgetkit",
714 .probe = interfacekit_probe,
715 .disconnect = interfacekit_disconnect,
716 .id_table = id_table
717};
718
719static int __init interfacekit_init(void)
720{
721 int retval = 0;
722
723 retval = usb_register(&interfacekit_driver);
724 if (retval)
725 err("usb_register failed. Error number %d", retval);
726
727 return retval;
728}
729
730static void __exit interfacekit_exit(void)
731{
732 usb_deregister(&interfacekit_driver);
733}
734
735module_init(interfacekit_init);
736module_exit(interfacekit_exit);
737
738MODULE_AUTHOR(DRIVER_AUTHOR);
739MODULE_DESCRIPTION(DRIVER_DESC);
740MODULE_LICENSE("GPL");
diff --git a/drivers/usb/misc/phidgetmotorcontrol.c b/drivers/usb/misc/phidgetmotorcontrol.c
deleted file mode 100644
index 38088b44349e..000000000000
--- a/drivers/usb/misc/phidgetmotorcontrol.c
+++ /dev/null
@@ -1,465 +0,0 @@
1/*
2 * USB Phidget MotorControl driver
3 *
4 * Copyright (C) 2006 Sean Young <sean@mess.org>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 */
11
12#include <linux/kernel.h>
13#include <linux/errno.h>
14#include <linux/init.h>
15#include <linux/module.h>
16#include <linux/usb.h>
17
18#include "phidget.h"
19
20#define DRIVER_AUTHOR "Sean Young <sean@mess.org>"
21#define DRIVER_DESC "USB PhidgetMotorControl Driver"
22
23#define USB_VENDOR_ID_GLAB 0x06c2
24#define USB_DEVICE_ID_MOTORCONTROL 0x0058
25
26#define URB_INT_SIZE 8
27
28static unsigned long device_no;
29
30struct motorcontrol {
31 struct usb_device *udev;
32 struct usb_interface *intf;
33 struct device *dev;
34 int dev_no;
35 u8 inputs[4];
36 s8 desired_speed[2];
37 s8 speed[2];
38 s16 _current[2];
39 s8 acceleration[2];
40 struct urb *irq;
41 unsigned char *data;
42 dma_addr_t data_dma;
43
44 struct delayed_work do_notify;
45 unsigned long input_events;
46 unsigned long speed_events;
47 unsigned long exceed_events;
48};
49
50static struct usb_device_id id_table[] = {
51 { USB_DEVICE(USB_VENDOR_ID_GLAB, USB_DEVICE_ID_MOTORCONTROL) },
52 {}
53};
54MODULE_DEVICE_TABLE(usb, id_table);
55
56static int set_motor(struct motorcontrol *mc, int motor)
57{
58 u8 *buffer;
59 int speed, speed2, acceleration;
60 int retval;
61
62 buffer = kzalloc(8, GFP_KERNEL);
63 if (!buffer) {
64 dev_err(&mc->intf->dev, "%s - out of memory\n", __func__);
65 return -ENOMEM;
66 }
67
68 acceleration = mc->acceleration[motor] * 10;
69 /* -127 <= speed <= 127 */
70 speed = (mc->desired_speed[motor] * 127) / 100;
71 /* -0x7300 <= speed2 <= 0x7300 */
72 speed2 = (mc->desired_speed[motor] * 230 * 128) / 100;
73
74 buffer[0] = motor;
75 buffer[1] = speed;
76 buffer[2] = acceleration >> 8;
77 buffer[3] = acceleration;
78 buffer[4] = speed2 >> 8;
79 buffer[5] = speed2;
80
81 retval = usb_control_msg(mc->udev,
82 usb_sndctrlpipe(mc->udev, 0),
83 0x09, 0x21, 0x0200, 0x0000, buffer, 8, 2000);
84
85 if (retval != 8)
86 dev_err(&mc->intf->dev, "usb_control_msg returned %d\n",
87 retval);
88 kfree(buffer);
89
90 return retval < 0 ? retval : 0;
91}
92
93static void motorcontrol_irq(struct urb *urb)
94{
95 struct motorcontrol *mc = urb->context;
96 unsigned char *buffer = mc->data;
97 int i, level;
98 int retval;
99 int status = urb->status;;
100
101 switch (status) {
102 case 0: /* success */
103 break;
104 case -ECONNRESET: /* unlink */
105 case -ENOENT:
106 case -ESHUTDOWN:
107 return;
108 /* -EPIPE: should clear the halt */
109 default: /* error */
110 goto resubmit;
111 }
112
113 /* digital inputs */
114 for (i=0; i<4; i++) {
115 level = (buffer[0] >> i) & 1;
116 if (mc->inputs[i] != level) {
117 mc->inputs[i] = level;
118 set_bit(i, &mc->input_events);
119 }
120 }
121
122 /* motor speed */
123 if (buffer[2] == 0) {
124 for (i=0; i<2; i++) {
125 level = ((s8)buffer[4+i]) * 100 / 127;
126 if (mc->speed[i] != level) {
127 mc->speed[i] = level;
128 set_bit(i, &mc->speed_events);
129 }
130 }
131 } else {
132 int index = buffer[3] & 1;
133
134 level = ((s8)buffer[4] << 8) | buffer[5];
135 level = level * 100 / 29440;
136 if (mc->speed[index] != level) {
137 mc->speed[index] = level;
138 set_bit(index, &mc->speed_events);
139 }
140
141 level = ((s8)buffer[6] << 8) | buffer[7];
142 mc->_current[index] = level * 100 / 1572;
143 }
144
145 if (buffer[1] & 1)
146 set_bit(0, &mc->exceed_events);
147
148 if (buffer[1] & 2)
149 set_bit(1, &mc->exceed_events);
150
151 if (mc->input_events || mc->exceed_events || mc->speed_events)
152 schedule_delayed_work(&mc->do_notify, 0);
153
154resubmit:
155 retval = usb_submit_urb(urb, GFP_ATOMIC);
156 if (retval)
157 dev_err(&mc->intf->dev,
158 "can't resubmit intr, %s-%s/motorcontrol0, retval %d\n",
159 mc->udev->bus->bus_name,
160 mc->udev->devpath, retval);
161}
162
163static void do_notify(struct work_struct *work)
164{
165 struct motorcontrol *mc =
166 container_of(work, struct motorcontrol, do_notify.work);
167 int i;
168 char sysfs_file[8];
169
170 for (i=0; i<4; i++) {
171 if (test_and_clear_bit(i, &mc->input_events)) {
172 sprintf(sysfs_file, "input%d", i);
173 sysfs_notify(&mc->dev->kobj, NULL, sysfs_file);
174 }
175 }
176
177 for (i=0; i<2; i++) {
178 if (test_and_clear_bit(i, &mc->speed_events)) {
179 sprintf(sysfs_file, "speed%d", i);
180 sysfs_notify(&mc->dev->kobj, NULL, sysfs_file);
181 }
182 }
183
184 for (i=0; i<2; i++) {
185 if (test_and_clear_bit(i, &mc->exceed_events))
186 dev_warn(&mc->intf->dev,
187 "motor #%d exceeds 1.5 Amp current limit\n", i);
188 }
189}
190
191#define show_set_speed(value) \
192static ssize_t set_speed##value(struct device *dev, \
193 struct device_attribute *attr, \
194 const char *buf, size_t count) \
195{ \
196 struct motorcontrol *mc = dev_get_drvdata(dev); \
197 int speed; \
198 int retval; \
199 \
200 if (sscanf(buf, "%d", &speed) < 1) \
201 return -EINVAL; \
202 \
203 if (speed < -100 || speed > 100) \
204 return -EINVAL; \
205 \
206 mc->desired_speed[value] = speed; \
207 \
208 retval = set_motor(mc, value); \
209 \
210 return retval ? retval : count; \
211} \
212 \
213static ssize_t show_speed##value(struct device *dev, \
214 struct device_attribute *attr, \
215 char *buf) \
216{ \
217 struct motorcontrol *mc = dev_get_drvdata(dev); \
218 \
219 return sprintf(buf, "%d\n", mc->speed[value]); \
220}
221
222#define speed_attr(value) \
223 __ATTR(speed##value, S_IWUGO | S_IRUGO, \
224 show_speed##value, set_speed##value)
225
226show_set_speed(0);
227show_set_speed(1);
228
229#define show_set_acceleration(value) \
230static ssize_t set_acceleration##value(struct device *dev, \
231 struct device_attribute *attr, \
232 const char *buf, size_t count) \
233{ \
234 struct motorcontrol *mc = dev_get_drvdata(dev); \
235 int acceleration; \
236 int retval; \
237 \
238 if (sscanf(buf, "%d", &acceleration) < 1) \
239 return -EINVAL; \
240 \
241 if (acceleration < 0 || acceleration > 100) \
242 return -EINVAL; \
243 \
244 mc->acceleration[value] = acceleration; \
245 \
246 retval = set_motor(mc, value); \
247 \
248 return retval ? retval : count; \
249} \
250 \
251static ssize_t show_acceleration##value(struct device *dev, \
252 struct device_attribute *attr, \
253 char *buf) \
254{ \
255 struct motorcontrol *mc = dev_get_drvdata(dev); \
256 \
257 return sprintf(buf, "%d\n", mc->acceleration[value]); \
258}
259
260#define acceleration_attr(value) \
261 __ATTR(acceleration##value, S_IWUGO | S_IRUGO, \
262 show_acceleration##value, set_acceleration##value)
263
264show_set_acceleration(0);
265show_set_acceleration(1);
266
267#define show_current(value) \
268static ssize_t show_current##value(struct device *dev, \
269 struct device_attribute *attr, \
270 char *buf) \
271{ \
272 struct motorcontrol *mc = dev_get_drvdata(dev); \
273 \
274 return sprintf(buf, "%dmA\n", (int)mc->_current[value]); \
275}
276
277#define current_attr(value) \
278 __ATTR(current##value, S_IRUGO, show_current##value, NULL)
279
280show_current(0);
281show_current(1);
282
283#define show_input(value) \
284static ssize_t show_input##value(struct device *dev, \
285 struct device_attribute *attr, \
286 char *buf) \
287{ \
288 struct motorcontrol *mc = dev_get_drvdata(dev); \
289 \
290 return sprintf(buf, "%d\n", (int)mc->inputs[value]); \
291}
292
293#define input_attr(value) \
294 __ATTR(input##value, S_IRUGO, show_input##value, NULL)
295
296show_input(0);
297show_input(1);
298show_input(2);
299show_input(3);
300
301static struct device_attribute dev_attrs[] = {
302 input_attr(0),
303 input_attr(1),
304 input_attr(2),
305 input_attr(3),
306 speed_attr(0),
307 speed_attr(1),
308 acceleration_attr(0),
309 acceleration_attr(1),
310 current_attr(0),
311 current_attr(1)
312};
313
314static int motorcontrol_probe(struct usb_interface *intf, const struct usb_device_id *id)
315{
316 struct usb_device *dev = interface_to_usbdev(intf);
317 struct usb_host_interface *interface;
318 struct usb_endpoint_descriptor *endpoint;
319 struct motorcontrol *mc;
320 int pipe, maxp, rc = -ENOMEM;
321 int bit, value, i;
322
323 interface = intf->cur_altsetting;
324 if (interface->desc.bNumEndpoints != 1)
325 return -ENODEV;
326
327 endpoint = &interface->endpoint[0].desc;
328 if (!usb_endpoint_dir_in(endpoint))
329 return -ENODEV;
330
331 /*
332 * bmAttributes
333 */
334 pipe = usb_rcvintpipe(dev, endpoint->bEndpointAddress);
335 maxp = usb_maxpacket(dev, pipe, usb_pipeout(pipe));
336
337 mc = kzalloc(sizeof(*mc), GFP_KERNEL);
338 if (!mc)
339 goto out;
340
341 mc->dev_no = -1;
342 mc->data = usb_buffer_alloc(dev, URB_INT_SIZE, GFP_ATOMIC, &mc->data_dma);
343 if (!mc->data)
344 goto out;
345
346 mc->irq = usb_alloc_urb(0, GFP_KERNEL);
347 if (!mc->irq)
348 goto out;
349
350 mc->udev = usb_get_dev(dev);
351 mc->intf = intf;
352 mc->acceleration[0] = mc->acceleration[1] = 10;
353 INIT_DELAYED_WORK(&mc->do_notify, do_notify);
354 usb_fill_int_urb(mc->irq, mc->udev, pipe, mc->data,
355 maxp > URB_INT_SIZE ? URB_INT_SIZE : maxp,
356 motorcontrol_irq, mc, endpoint->bInterval);
357 mc->irq->transfer_dma = mc->data_dma;
358 mc->irq->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
359
360 usb_set_intfdata(intf, mc);
361
362 do {
363 bit = find_first_zero_bit(&device_no, sizeof(device_no));
364 value = test_and_set_bit(bit, &device_no);
365 } while(value);
366 mc->dev_no = bit;
367
368 mc->dev = device_create(phidget_class, &mc->udev->dev, MKDEV(0, 0), mc,
369 "motorcontrol%d", mc->dev_no);
370 if (IS_ERR(mc->dev)) {
371 rc = PTR_ERR(mc->dev);
372 mc->dev = NULL;
373 goto out;
374 }
375
376 if (usb_submit_urb(mc->irq, GFP_KERNEL)) {
377 rc = -EIO;
378 goto out;
379 }
380
381 for (i=0; i<ARRAY_SIZE(dev_attrs); i++) {
382 rc = device_create_file(mc->dev, &dev_attrs[i]);
383 if (rc)
384 goto out2;
385 }
386
387 dev_info(&intf->dev, "USB PhidgetMotorControl attached\n");
388
389 return 0;
390out2:
391 while (i-- > 0)
392 device_remove_file(mc->dev, &dev_attrs[i]);
393out:
394 if (mc) {
395 usb_free_urb(mc->irq);
396 if (mc->data)
397 usb_buffer_free(dev, URB_INT_SIZE, mc->data, mc->data_dma);
398 if (mc->dev)
399 device_unregister(mc->dev);
400 if (mc->dev_no >= 0)
401 clear_bit(mc->dev_no, &device_no);
402
403 kfree(mc);
404 }
405
406 return rc;
407}
408
409static void motorcontrol_disconnect(struct usb_interface *interface)
410{
411 struct motorcontrol *mc;
412 int i;
413
414 mc = usb_get_intfdata(interface);
415 usb_set_intfdata(interface, NULL);
416 if (!mc)
417 return;
418
419 usb_kill_urb(mc->irq);
420 usb_free_urb(mc->irq);
421 usb_buffer_free(mc->udev, URB_INT_SIZE, mc->data, mc->data_dma);
422
423 cancel_delayed_work(&mc->do_notify);
424
425 for (i=0; i<ARRAY_SIZE(dev_attrs); i++)
426 device_remove_file(mc->dev, &dev_attrs[i]);
427
428 device_unregister(mc->dev);
429
430 usb_put_dev(mc->udev);
431 clear_bit(mc->dev_no, &device_no);
432 kfree(mc);
433
434 dev_info(&interface->dev, "USB PhidgetMotorControl detached\n");
435}
436
437static struct usb_driver motorcontrol_driver = {
438 .name = "phidgetmotorcontrol",
439 .probe = motorcontrol_probe,
440 .disconnect = motorcontrol_disconnect,
441 .id_table = id_table
442};
443
444static int __init motorcontrol_init(void)
445{
446 int retval = 0;
447
448 retval = usb_register(&motorcontrol_driver);
449 if (retval)
450 err("usb_register failed. Error number %d", retval);
451
452 return retval;
453}
454
455static void __exit motorcontrol_exit(void)
456{
457 usb_deregister(&motorcontrol_driver);
458}
459
460module_init(motorcontrol_init);
461module_exit(motorcontrol_exit);
462
463MODULE_AUTHOR(DRIVER_AUTHOR);
464MODULE_DESCRIPTION(DRIVER_DESC);
465MODULE_LICENSE("GPL");
diff --git a/drivers/usb/misc/phidgetservo.c b/drivers/usb/misc/phidgetservo.c
deleted file mode 100644
index bef6fe16364b..000000000000
--- a/drivers/usb/misc/phidgetservo.c
+++ /dev/null
@@ -1,375 +0,0 @@
1/*
2 * USB PhidgetServo driver 1.0
3 *
4 * Copyright (C) 2004, 2006 Sean Young <sean@mess.org>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This is a driver for the USB PhidgetServo version 2.0 and 3.0 servo
12 * controllers available at: http://www.phidgets.com/
13 *
14 * Note that the driver takes input as: degrees.minutes
15 *
16 * CAUTION: Generally you should use 0 < degrees < 180 as anything else
17 * is probably beyond the range of your servo and may damage it.
18 */
19
20#include <linux/kernel.h>
21#include <linux/errno.h>
22#include <linux/init.h>
23#include <linux/slab.h>
24#include <linux/module.h>
25#include <linux/usb.h>
26
27#include "phidget.h"
28
29#define DRIVER_AUTHOR "Sean Young <sean@mess.org>"
30#define DRIVER_DESC "USB PhidgetServo Driver"
31
32#define VENDOR_ID_GLAB 0x06c2
33#define DEVICE_ID_GLAB_PHIDGETSERVO_QUAD 0x0038
34#define DEVICE_ID_GLAB_PHIDGETSERVO_UNI 0x0039
35
36#define VENDOR_ID_WISEGROUP 0x0925
37#define VENDOR_ID_WISEGROUP_PHIDGETSERVO_QUAD 0x8101
38#define VENDOR_ID_WISEGROUP_PHIDGETSERVO_UNI 0x8104
39
40#define SERVO_VERSION_30 0x01
41#define SERVO_COUNT_QUAD 0x02
42
43static struct usb_device_id id_table[] = {
44 {
45 USB_DEVICE(VENDOR_ID_GLAB, DEVICE_ID_GLAB_PHIDGETSERVO_QUAD),
46 .driver_info = SERVO_VERSION_30 | SERVO_COUNT_QUAD
47 },
48 {
49 USB_DEVICE(VENDOR_ID_GLAB, DEVICE_ID_GLAB_PHIDGETSERVO_UNI),
50 .driver_info = SERVO_VERSION_30
51 },
52 {
53 USB_DEVICE(VENDOR_ID_WISEGROUP,
54 VENDOR_ID_WISEGROUP_PHIDGETSERVO_QUAD),
55 .driver_info = SERVO_COUNT_QUAD
56 },
57 {
58 USB_DEVICE(VENDOR_ID_WISEGROUP,
59 VENDOR_ID_WISEGROUP_PHIDGETSERVO_UNI),
60 .driver_info = 0
61 },
62 {}
63};
64
65MODULE_DEVICE_TABLE(usb, id_table);
66
67static int unsigned long device_no;
68
69struct phidget_servo {
70 struct usb_device *udev;
71 struct device *dev;
72 int dev_no;
73 ulong type;
74 int pulse[4];
75 int degrees[4];
76 int minutes[4];
77};
78
79static int
80change_position_v30(struct phidget_servo *servo, int servo_no, int degrees,
81 int minutes)
82{
83 int retval;
84 unsigned char *buffer;
85
86 if (degrees < -23 || degrees > 362)
87 return -EINVAL;
88
89 buffer = kmalloc(6, GFP_KERNEL);
90 if (!buffer) {
91 dev_err(&servo->udev->dev, "%s - out of memory\n",
92 __func__);
93 return -ENOMEM;
94 }
95
96 /*
97 * pulse = 0 - 4095
98 * angle = 0 - 180 degrees
99 *
100 * pulse = angle * 10.6 + 243.8
101 */
102 servo->pulse[servo_no] = ((degrees*60 + minutes)*106 + 2438*60)/600;
103 servo->degrees[servo_no]= degrees;
104 servo->minutes[servo_no]= minutes;
105
106 /*
107 * The PhidgetServo v3.0 is controlled by sending 6 bytes,
108 * 4 * 12 bits for each servo.
109 *
110 * low = lower 8 bits pulse
111 * high = higher 4 bits pulse
112 *
113 * offset bits
114 * +---+-----------------+
115 * | 0 | low 0 |
116 * +---+--------+--------+
117 * | 1 | high 1 | high 0 |
118 * +---+--------+--------+
119 * | 2 | low 1 |
120 * +---+-----------------+
121 * | 3 | low 2 |
122 * +---+--------+--------+
123 * | 4 | high 3 | high 2 |
124 * +---+--------+--------+
125 * | 5 | low 3 |
126 * +---+-----------------+
127 */
128
129 buffer[0] = servo->pulse[0] & 0xff;
130 buffer[1] = (servo->pulse[0] >> 8 & 0x0f)
131 | (servo->pulse[1] >> 4 & 0xf0);
132 buffer[2] = servo->pulse[1] & 0xff;
133 buffer[3] = servo->pulse[2] & 0xff;
134 buffer[4] = (servo->pulse[2] >> 8 & 0x0f)
135 | (servo->pulse[3] >> 4 & 0xf0);
136 buffer[5] = servo->pulse[3] & 0xff;
137
138 dev_dbg(&servo->udev->dev,
139 "data: %02x %02x %02x %02x %02x %02x\n",
140 buffer[0], buffer[1], buffer[2],
141 buffer[3], buffer[4], buffer[5]);
142
143 retval = usb_control_msg(servo->udev,
144 usb_sndctrlpipe(servo->udev, 0),
145 0x09, 0x21, 0x0200, 0x0000, buffer, 6, 2000);
146
147 kfree(buffer);
148
149 return retval;
150}
151
152static int
153change_position_v20(struct phidget_servo *servo, int servo_no, int degrees,
154 int minutes)
155{
156 int retval;
157 unsigned char *buffer;
158
159 if (degrees < -23 || degrees > 278)
160 return -EINVAL;
161
162 buffer = kmalloc(2, GFP_KERNEL);
163 if (!buffer) {
164 dev_err(&servo->udev->dev, "%s - out of memory\n",
165 __func__);
166 return -ENOMEM;
167 }
168
169 /*
170 * angle = 0 - 180 degrees
171 * pulse = angle + 23
172 */
173 servo->pulse[servo_no]= degrees + 23;
174 servo->degrees[servo_no]= degrees;
175 servo->minutes[servo_no]= 0;
176
177 /*
178 * The PhidgetServo v2.0 is controlled by sending two bytes. The
179 * first byte is the servo number xor'ed with 2:
180 *
181 * servo 0 = 2
182 * servo 1 = 3
183 * servo 2 = 0
184 * servo 3 = 1
185 *
186 * The second byte is the position.
187 */
188
189 buffer[0] = servo_no ^ 2;
190 buffer[1] = servo->pulse[servo_no];
191
192 dev_dbg(&servo->udev->dev, "data: %02x %02x\n", buffer[0], buffer[1]);
193
194 retval = usb_control_msg(servo->udev,
195 usb_sndctrlpipe(servo->udev, 0),
196 0x09, 0x21, 0x0200, 0x0000, buffer, 2, 2000);
197
198 kfree(buffer);
199
200 return retval;
201}
202
203#define show_set(value) \
204static ssize_t set_servo##value (struct device *dev, \
205 struct device_attribute *attr, \
206 const char *buf, size_t count) \
207{ \
208 int degrees, minutes, retval; \
209 struct phidget_servo *servo = dev_get_drvdata(dev); \
210 \
211 minutes = 0; \
212 /* must at least convert degrees */ \
213 if (sscanf(buf, "%d.%d", &degrees, &minutes) < 1) { \
214 return -EINVAL; \
215 } \
216 \
217 if (minutes < 0 || minutes > 59) \
218 return -EINVAL; \
219 \
220 if (servo->type & SERVO_VERSION_30) \
221 retval = change_position_v30(servo, value, degrees, \
222 minutes); \
223 else \
224 retval = change_position_v20(servo, value, degrees, \
225 minutes); \
226 \
227 return retval < 0 ? retval : count; \
228} \
229 \
230static ssize_t show_servo##value (struct device *dev, \
231 struct device_attribute *attr, \
232 char *buf) \
233{ \
234 struct phidget_servo *servo = dev_get_drvdata(dev); \
235 \
236 return sprintf(buf, "%d.%02d\n", servo->degrees[value], \
237 servo->minutes[value]); \
238}
239
240#define servo_attr(value) \
241 __ATTR(servo##value, S_IWUGO | S_IRUGO, \
242 show_servo##value, set_servo##value)
243show_set(0);
244show_set(1);
245show_set(2);
246show_set(3);
247
248static struct device_attribute dev_attrs[] = {
249 servo_attr(0), servo_attr(1), servo_attr(2), servo_attr(3)
250};
251
252static int
253servo_probe(struct usb_interface *interface, const struct usb_device_id *id)
254{
255 struct usb_device *udev = interface_to_usbdev(interface);
256 struct phidget_servo *dev;
257 int bit, value, rc;
258 int servo_count, i;
259
260 dev = kzalloc(sizeof (struct phidget_servo), GFP_KERNEL);
261 if (dev == NULL) {
262 dev_err(&interface->dev, "%s - out of memory\n", __func__);
263 rc = -ENOMEM;
264 goto out;
265 }
266
267 dev->udev = usb_get_dev(udev);
268 dev->type = id->driver_info;
269 dev->dev_no = -1;
270 usb_set_intfdata(interface, dev);
271
272 do {
273 bit = find_first_zero_bit(&device_no, sizeof(device_no));
274 value = test_and_set_bit(bit, &device_no);
275 } while (value);
276 dev->dev_no = bit;
277
278 dev->dev = device_create(phidget_class, &dev->udev->dev, MKDEV(0, 0),
279 dev, "servo%d", dev->dev_no);
280 if (IS_ERR(dev->dev)) {
281 rc = PTR_ERR(dev->dev);
282 dev->dev = NULL;
283 goto out;
284 }
285
286 servo_count = dev->type & SERVO_COUNT_QUAD ? 4 : 1;
287
288 for (i=0; i<servo_count; i++) {
289 rc = device_create_file(dev->dev, &dev_attrs[i]);
290 if (rc)
291 goto out2;
292 }
293
294 dev_info(&interface->dev, "USB %d-Motor PhidgetServo v%d.0 attached\n",
295 servo_count, dev->type & SERVO_VERSION_30 ? 3 : 2);
296
297 if (!(dev->type & SERVO_VERSION_30))
298 dev_info(&interface->dev,
299 "WARNING: v2.0 not tested! Please report if it works.\n");
300
301 return 0;
302out2:
303 while (i-- > 0)
304 device_remove_file(dev->dev, &dev_attrs[i]);
305out:
306 if (dev) {
307 if (dev->dev)
308 device_unregister(dev->dev);
309 if (dev->dev_no >= 0)
310 clear_bit(dev->dev_no, &device_no);
311
312 kfree(dev);
313 }
314
315 return rc;
316}
317
318static void
319servo_disconnect(struct usb_interface *interface)
320{
321 struct phidget_servo *dev;
322 int servo_count, i;
323
324 dev = usb_get_intfdata(interface);
325 usb_set_intfdata(interface, NULL);
326
327 if (!dev)
328 return;
329
330 servo_count = dev->type & SERVO_COUNT_QUAD ? 4 : 1;
331
332 for (i=0; i<servo_count; i++)
333 device_remove_file(dev->dev, &dev_attrs[i]);
334
335 device_unregister(dev->dev);
336 usb_put_dev(dev->udev);
337
338 dev_info(&interface->dev, "USB %d-Motor PhidgetServo v%d.0 detached\n",
339 servo_count, dev->type & SERVO_VERSION_30 ? 3 : 2);
340
341 clear_bit(dev->dev_no, &device_no);
342 kfree(dev);
343}
344
345static struct usb_driver servo_driver = {
346 .name = "phidgetservo",
347 .probe = servo_probe,
348 .disconnect = servo_disconnect,
349 .id_table = id_table
350};
351
352static int __init
353phidget_servo_init(void)
354{
355 int retval;
356
357 retval = usb_register(&servo_driver);
358 if (retval)
359 err("usb_register failed. Error number %d", retval);
360
361 return retval;
362}
363
364static void __exit
365phidget_servo_exit(void)
366{
367 usb_deregister(&servo_driver);
368}
369
370module_init(phidget_servo_init);
371module_exit(phidget_servo_exit);
372
373MODULE_AUTHOR(DRIVER_AUTHOR);
374MODULE_DESCRIPTION(DRIVER_DESC);
375MODULE_LICENSE("GPL");