diff options
Diffstat (limited to 'drivers/usb/misc/phidgetmotorcontrol.c')
-rw-r--r-- | drivers/usb/misc/phidgetmotorcontrol.c | 83 |
1 files changed, 45 insertions, 38 deletions
diff --git a/drivers/usb/misc/phidgetmotorcontrol.c b/drivers/usb/misc/phidgetmotorcontrol.c index d9ac7f97f8c8..6b59b620d616 100644 --- a/drivers/usb/misc/phidgetmotorcontrol.c +++ b/drivers/usb/misc/phidgetmotorcontrol.c | |||
@@ -215,9 +215,12 @@ static ssize_t show_speed##value(struct device *dev, \ | |||
215 | struct motorcontrol *mc = dev_get_drvdata(dev); \ | 215 | struct motorcontrol *mc = dev_get_drvdata(dev); \ |
216 | \ | 216 | \ |
217 | return sprintf(buf, "%d\n", mc->speed[value]); \ | 217 | return sprintf(buf, "%d\n", mc->speed[value]); \ |
218 | } \ | 218 | } |
219 | static DEVICE_ATTR(speed##value, S_IWUGO | S_IRUGO, \ | 219 | |
220 | show_speed##value, set_speed##value); | 220 | #define speed_attr(value) \ |
221 | __ATTR(speed##value, S_IWUGO | S_IRUGO, \ | ||
222 | show_speed##value, set_speed##value) | ||
223 | |||
221 | show_set_speed(0); | 224 | show_set_speed(0); |
222 | show_set_speed(1); | 225 | show_set_speed(1); |
223 | 226 | ||
@@ -250,9 +253,12 @@ static ssize_t show_acceleration##value(struct device *dev, \ | |||
250 | struct motorcontrol *mc = dev_get_drvdata(dev); \ | 253 | struct motorcontrol *mc = dev_get_drvdata(dev); \ |
251 | \ | 254 | \ |
252 | return sprintf(buf, "%d\n", mc->acceleration[value]); \ | 255 | return sprintf(buf, "%d\n", mc->acceleration[value]); \ |
253 | } \ | 256 | } |
254 | static DEVICE_ATTR(acceleration##value, S_IWUGO | S_IRUGO, \ | 257 | |
255 | show_acceleration##value, set_acceleration##value); | 258 | #define acceleration_attr(value) \ |
259 | __ATTR(acceleration##value, S_IWUGO | S_IRUGO, \ | ||
260 | show_acceleration##value, set_acceleration##value) | ||
261 | |||
256 | show_set_acceleration(0); | 262 | show_set_acceleration(0); |
257 | show_set_acceleration(1); | 263 | show_set_acceleration(1); |
258 | 264 | ||
@@ -264,8 +270,10 @@ static ssize_t show_current##value(struct device *dev, \ | |||
264 | struct motorcontrol *mc = dev_get_drvdata(dev); \ | 270 | struct motorcontrol *mc = dev_get_drvdata(dev); \ |
265 | \ | 271 | \ |
266 | return sprintf(buf, "%dmA\n", (int)mc->_current[value]); \ | 272 | return sprintf(buf, "%dmA\n", (int)mc->_current[value]); \ |
267 | } \ | 273 | } |
268 | static DEVICE_ATTR(current##value, S_IRUGO, show_current##value, NULL); | 274 | |
275 | #define current_attr(value) \ | ||
276 | __ATTR(current##value, S_IRUGO, show_current##value, NULL) | ||
269 | 277 | ||
270 | show_current(0); | 278 | show_current(0); |
271 | show_current(1); | 279 | show_current(1); |
@@ -278,14 +286,29 @@ static ssize_t show_input##value(struct device *dev, \ | |||
278 | struct motorcontrol *mc = dev_get_drvdata(dev); \ | 286 | struct motorcontrol *mc = dev_get_drvdata(dev); \ |
279 | \ | 287 | \ |
280 | return sprintf(buf, "%d\n", (int)mc->inputs[value]); \ | 288 | return sprintf(buf, "%d\n", (int)mc->inputs[value]); \ |
281 | } \ | 289 | } |
282 | static DEVICE_ATTR(input##value, S_IRUGO, show_input##value, NULL); | 290 | |
291 | #define input_attr(value) \ | ||
292 | __ATTR(input##value, S_IRUGO, show_input##value, NULL) | ||
283 | 293 | ||
284 | show_input(0); | 294 | show_input(0); |
285 | show_input(1); | 295 | show_input(1); |
286 | show_input(2); | 296 | show_input(2); |
287 | show_input(3); | 297 | show_input(3); |
288 | 298 | ||
299 | static struct device_attribute dev_attrs[] = { | ||
300 | input_attr(0), | ||
301 | input_attr(1), | ||
302 | input_attr(2), | ||
303 | input_attr(3), | ||
304 | speed_attr(0), | ||
305 | speed_attr(1), | ||
306 | acceleration_attr(0), | ||
307 | acceleration_attr(1), | ||
308 | current_attr(0), | ||
309 | current_attr(1) | ||
310 | }; | ||
311 | |||
289 | static int motorcontrol_probe(struct usb_interface *intf, const struct usb_device_id *id) | 312 | static int motorcontrol_probe(struct usb_interface *intf, const struct usb_device_id *id) |
290 | { | 313 | { |
291 | struct usb_device *dev = interface_to_usbdev(intf); | 314 | struct usb_device *dev = interface_to_usbdev(intf); |
@@ -293,7 +316,7 @@ static int motorcontrol_probe(struct usb_interface *intf, const struct usb_devic | |||
293 | struct usb_endpoint_descriptor *endpoint; | 316 | struct usb_endpoint_descriptor *endpoint; |
294 | struct motorcontrol *mc; | 317 | struct motorcontrol *mc; |
295 | int pipe, maxp, rc = -ENOMEM; | 318 | int pipe, maxp, rc = -ENOMEM; |
296 | int bit, value; | 319 | int bit, value, i; |
297 | 320 | ||
298 | interface = intf->cur_altsetting; | 321 | interface = intf->cur_altsetting; |
299 | if (interface->desc.bNumEndpoints != 1) | 322 | if (interface->desc.bNumEndpoints != 1) |
@@ -355,24 +378,18 @@ static int motorcontrol_probe(struct usb_interface *intf, const struct usb_devic | |||
355 | goto out; | 378 | goto out; |
356 | } | 379 | } |
357 | 380 | ||
358 | device_create_file(mc->dev, &dev_attr_input0); | 381 | for (i=0; i<ARRAY_SIZE(dev_attrs); i++) { |
359 | device_create_file(mc->dev, &dev_attr_input1); | 382 | rc = device_create_file(mc->dev, &dev_attrs[i]); |
360 | device_create_file(mc->dev, &dev_attr_input2); | 383 | if (rc) |
361 | device_create_file(mc->dev, &dev_attr_input3); | 384 | goto out2; |
362 | 385 | } | |
363 | device_create_file(mc->dev, &dev_attr_speed0); | ||
364 | device_create_file(mc->dev, &dev_attr_speed1); | ||
365 | |||
366 | device_create_file(mc->dev, &dev_attr_acceleration0); | ||
367 | device_create_file(mc->dev, &dev_attr_acceleration1); | ||
368 | |||
369 | device_create_file(mc->dev, &dev_attr_current0); | ||
370 | device_create_file(mc->dev, &dev_attr_current1); | ||
371 | 386 | ||
372 | dev_info(&intf->dev, "USB PhidgetMotorControl attached\n"); | 387 | dev_info(&intf->dev, "USB PhidgetMotorControl attached\n"); |
373 | 388 | ||
374 | return 0; | 389 | return 0; |
375 | 390 | out2: | |
391 | while (i-- > 0) | ||
392 | device_remove_file(mc->dev, &dev_attrs[i]); | ||
376 | out: | 393 | out: |
377 | if (mc) { | 394 | if (mc) { |
378 | if (mc->irq) | 395 | if (mc->irq) |
@@ -393,6 +410,7 @@ out: | |||
393 | static void motorcontrol_disconnect(struct usb_interface *interface) | 410 | static void motorcontrol_disconnect(struct usb_interface *interface) |
394 | { | 411 | { |
395 | struct motorcontrol *mc; | 412 | struct motorcontrol *mc; |
413 | int i; | ||
396 | 414 | ||
397 | mc = usb_get_intfdata(interface); | 415 | mc = usb_get_intfdata(interface); |
398 | usb_set_intfdata(interface, NULL); | 416 | usb_set_intfdata(interface, NULL); |
@@ -405,19 +423,8 @@ static void motorcontrol_disconnect(struct usb_interface *interface) | |||
405 | 423 | ||
406 | cancel_delayed_work(&mc->do_notify); | 424 | cancel_delayed_work(&mc->do_notify); |
407 | 425 | ||
408 | device_remove_file(mc->dev, &dev_attr_input0); | 426 | for (i=0; i<ARRAY_SIZE(dev_attrs); i++) |
409 | device_remove_file(mc->dev, &dev_attr_input1); | 427 | device_remove_file(mc->dev, &dev_attrs[i]); |
410 | device_remove_file(mc->dev, &dev_attr_input2); | ||
411 | device_remove_file(mc->dev, &dev_attr_input3); | ||
412 | |||
413 | device_remove_file(mc->dev, &dev_attr_speed0); | ||
414 | device_remove_file(mc->dev, &dev_attr_speed1); | ||
415 | |||
416 | device_remove_file(mc->dev, &dev_attr_acceleration0); | ||
417 | device_remove_file(mc->dev, &dev_attr_acceleration1); | ||
418 | |||
419 | device_remove_file(mc->dev, &dev_attr_current0); | ||
420 | device_remove_file(mc->dev, &dev_attr_current1); | ||
421 | 428 | ||
422 | device_unregister(mc->dev); | 429 | device_unregister(mc->dev); |
423 | 430 | ||