Commit 912b24c3 authored by Sean Young's avatar Sean Young Committed by Greg Kroah-Hartman

USB: Put phidgets driver in a sysfs class

This patch creates a device class phidget and add the phidget drivers to 
them.
Signed-off-by: default avatarSean Young <sean@mess.org>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@suse.de>
parent d5176b41
...@@ -115,9 +115,16 @@ config USB_CYTHERM ...@@ -115,9 +115,16 @@ config USB_CYTHERM
To compile this driver as a module, choose M here: the To compile this driver as a module, choose M here: the
module will be called cytherm. module will be called cytherm.
config USB_PHIDGET
tristate "USB Phidgets drivers"
depends on USB
help
Say Y here to enable the various drivers for devices from
Phidgets inc.
config USB_PHIDGETKIT config USB_PHIDGETKIT
tristate "USB PhidgetInterfaceKit support" tristate "USB PhidgetInterfaceKit support"
depends on USB depends on USB_PHIDGET
help help
Say Y here if you want to connect a PhidgetInterfaceKit USB device Say Y here if you want to connect a PhidgetInterfaceKit USB device
from Phidgets Inc. from Phidgets Inc.
...@@ -127,7 +134,7 @@ config USB_PHIDGETKIT ...@@ -127,7 +134,7 @@ config USB_PHIDGETKIT
config USB_PHIDGETMOTORCONTROL config USB_PHIDGETMOTORCONTROL
tristate "USB PhidgetMotorControl support" tristate "USB PhidgetMotorControl support"
depends on USB depends on USB_PHIDGET
help help
Say Y here if you want to connect a PhidgetMotorControl USB device Say Y here if you want to connect a PhidgetMotorControl USB device
from Phidgets Inc. from Phidgets Inc.
...@@ -137,7 +144,7 @@ config USB_PHIDGETMOTORCONTROL ...@@ -137,7 +144,7 @@ config USB_PHIDGETMOTORCONTROL
config USB_PHIDGETSERVO config USB_PHIDGETSERVO
tristate "USB PhidgetServo support" tristate "USB PhidgetServo support"
depends on USB depends on USB_PHIDGET
help help
Say Y here if you want to connect an 1 or 4 Motor PhidgetServo Say Y here if you want to connect an 1 or 4 Motor PhidgetServo
servo controller version 2.0 or 3.0. servo controller version 2.0 or 3.0.
......
...@@ -13,6 +13,7 @@ obj-$(CONFIG_USB_LCD) += usblcd.o ...@@ -13,6 +13,7 @@ obj-$(CONFIG_USB_LCD) += usblcd.o
obj-$(CONFIG_USB_LD) += ldusb.o obj-$(CONFIG_USB_LD) += ldusb.o
obj-$(CONFIG_USB_LED) += usbled.o obj-$(CONFIG_USB_LED) += usbled.o
obj-$(CONFIG_USB_LEGOTOWER) += legousbtower.o obj-$(CONFIG_USB_LEGOTOWER) += legousbtower.o
obj-$(CONFIG_USB_PHIDGET) += phidget.o
obj-$(CONFIG_USB_PHIDGETKIT) += phidgetkit.o obj-$(CONFIG_USB_PHIDGETKIT) += phidgetkit.o
obj-$(CONFIG_USB_PHIDGETMOTORCONTROL) += phidgetmotorcontrol.o obj-$(CONFIG_USB_PHIDGETMOTORCONTROL) += phidgetmotorcontrol.o
obj-$(CONFIG_USB_PHIDGETSERVO) += phidgetservo.o obj-$(CONFIG_USB_PHIDGETSERVO) += phidgetservo.o
......
/*
* USB Phidgets class
*
* Copyright (C) 2006 Sean Young <sean@mess.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*/
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/init.h>
#include <linux/err.h>
#include <linux/device.h>
struct class *phidget_class;
static int __init init_phidget(void)
{
phidget_class = class_create(THIS_MODULE, "phidget");
if (IS_ERR(phidget_class))
return PTR_ERR(phidget_class);
return 0;
}
static void __exit cleanup_phidget(void)
{
class_destroy(phidget_class);
}
EXPORT_SYMBOL_GPL(phidget_class);
module_init(init_phidget);
module_exit(cleanup_phidget);
MODULE_LICENSE("GPL");
MODULE_AUTHOR("Sean Young <sean@mess.org>");
MODULE_DESCRIPTION("Container module for phidget class");
/*
* USB Phidgets class
*
* Copyright (C) 2006 Sean Young <sean@mess.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*/
extern struct class *phidget_class;
This diff is collapsed.
...@@ -15,6 +15,8 @@ ...@@ -15,6 +15,8 @@
#include <linux/module.h> #include <linux/module.h>
#include <linux/usb.h> #include <linux/usb.h>
#include "phidget.h"
#define DRIVER_AUTHOR "Sean Young <sean@mess.org>" #define DRIVER_AUTHOR "Sean Young <sean@mess.org>"
#define DRIVER_DESC "USB PhidgetMotorControl Driver" #define DRIVER_DESC "USB PhidgetMotorControl Driver"
...@@ -23,9 +25,13 @@ ...@@ -23,9 +25,13 @@
#define URB_INT_SIZE 8 #define URB_INT_SIZE 8
static unsigned long device_no;
struct motorcontrol { struct motorcontrol {
struct usb_device *udev; struct usb_device *udev;
struct usb_interface *intf; struct usb_interface *intf;
struct device *dev;
int dev_no;
u8 inputs[4]; u8 inputs[4];
s8 desired_speed[2]; s8 desired_speed[2];
s8 speed[2]; s8 speed[2];
...@@ -162,14 +168,14 @@ static void do_notify(void *data) ...@@ -162,14 +168,14 @@ static void do_notify(void *data)
for (i=0; i<4; i++) { for (i=0; i<4; i++) {
if (test_and_clear_bit(i, &mc->input_events)) { if (test_and_clear_bit(i, &mc->input_events)) {
sprintf(sysfs_file, "input%d", i); sprintf(sysfs_file, "input%d", i);
sysfs_notify(&mc->intf->dev.kobj, NULL, sysfs_file); sysfs_notify(&mc->dev->kobj, NULL, sysfs_file);
} }
} }
for (i=0; i<2; i++) { for (i=0; i<2; i++) {
if (test_and_clear_bit(i, &mc->speed_events)) { if (test_and_clear_bit(i, &mc->speed_events)) {
sprintf(sysfs_file, "speed%d", i); sprintf(sysfs_file, "speed%d", i);
sysfs_notify(&mc->intf->dev.kobj, NULL, sysfs_file); sysfs_notify(&mc->dev->kobj, NULL, sysfs_file);
} }
} }
...@@ -182,10 +188,10 @@ static void do_notify(void *data) ...@@ -182,10 +188,10 @@ static void do_notify(void *data)
#define show_set_speed(value) \ #define show_set_speed(value) \
static ssize_t set_speed##value(struct device *dev, \ static ssize_t set_speed##value(struct device *dev, \
struct device_attribute *attr, const char *buf, size_t count) \ struct device_attribute *attr, \
const char *buf, size_t count) \
{ \ { \
struct usb_interface *intf = to_usb_interface(dev); \ struct motorcontrol *mc = dev_get_drvdata(dev); \
struct motorcontrol *mc = usb_get_intfdata(intf); \
int speed; \ int speed; \
int retval; \ int retval; \
\ \
...@@ -203,10 +209,10 @@ static ssize_t set_speed##value(struct device *dev, \ ...@@ -203,10 +209,10 @@ static ssize_t set_speed##value(struct device *dev, \
} \ } \
\ \
static ssize_t show_speed##value(struct device *dev, \ static ssize_t show_speed##value(struct device *dev, \
struct device_attribute *attr, char *buf) \ struct device_attribute *attr, \
char *buf) \
{ \ { \
struct usb_interface *intf = to_usb_interface(dev); \ struct motorcontrol *mc = dev_get_drvdata(dev); \
struct motorcontrol *mc = usb_get_intfdata(intf); \
\ \
return sprintf(buf, "%d\n", mc->speed[value]); \ return sprintf(buf, "%d\n", mc->speed[value]); \
} \ } \
...@@ -217,10 +223,10 @@ show_set_speed(1); ...@@ -217,10 +223,10 @@ show_set_speed(1);
#define show_set_acceleration(value) \ #define show_set_acceleration(value) \
static ssize_t set_acceleration##value(struct device *dev, \ static ssize_t set_acceleration##value(struct device *dev, \
struct device_attribute *attr, const char *buf, size_t count) \ struct device_attribute *attr, \
const char *buf, size_t count) \
{ \ { \
struct usb_interface *intf = to_usb_interface(dev); \ struct motorcontrol *mc = dev_get_drvdata(dev); \
struct motorcontrol *mc = usb_get_intfdata(intf); \
int acceleration; \ int acceleration; \
int retval; \ int retval; \
\ \
...@@ -238,10 +244,10 @@ static ssize_t set_acceleration##value(struct device *dev, \ ...@@ -238,10 +244,10 @@ static ssize_t set_acceleration##value(struct device *dev, \
} \ } \
\ \
static ssize_t show_acceleration##value(struct device *dev, \ static ssize_t show_acceleration##value(struct device *dev, \
struct device_attribute *attr, char *buf) \ struct device_attribute *attr, \
char *buf) \
{ \ { \
struct usb_interface *intf = to_usb_interface(dev); \ struct motorcontrol *mc = dev_get_drvdata(dev); \
struct motorcontrol *mc = usb_get_intfdata(intf); \
\ \
return sprintf(buf, "%d\n", mc->acceleration[value]); \ return sprintf(buf, "%d\n", mc->acceleration[value]); \
} \ } \
...@@ -252,10 +258,10 @@ show_set_acceleration(1); ...@@ -252,10 +258,10 @@ show_set_acceleration(1);
#define show_current(value) \ #define show_current(value) \
static ssize_t show_current##value(struct device *dev, \ static ssize_t show_current##value(struct device *dev, \
struct device_attribute *attr, char *buf) \ struct device_attribute *attr, \
char *buf) \
{ \ { \
struct usb_interface *intf = to_usb_interface(dev); \ struct motorcontrol *mc = dev_get_drvdata(dev); \
struct motorcontrol *mc = usb_get_intfdata(intf); \
\ \
return sprintf(buf, "%dmA\n", (int)mc->_current[value]); \ return sprintf(buf, "%dmA\n", (int)mc->_current[value]); \
} \ } \
...@@ -266,10 +272,10 @@ show_current(1); ...@@ -266,10 +272,10 @@ show_current(1);
#define show_input(value) \ #define show_input(value) \
static ssize_t show_input##value(struct device *dev, \ static ssize_t show_input##value(struct device *dev, \
struct device_attribute *attr, char *buf) \ struct device_attribute *attr, \
char *buf) \
{ \ { \
struct usb_interface *intf = to_usb_interface(dev); \ struct motorcontrol *mc = dev_get_drvdata(dev); \
struct motorcontrol *mc = usb_get_intfdata(intf); \
\ \
return sprintf(buf, "%d\n", (int)mc->inputs[value]); \ return sprintf(buf, "%d\n", (int)mc->inputs[value]); \
} \ } \
...@@ -287,6 +293,7 @@ static int motorcontrol_probe(struct usb_interface *intf, const struct usb_devic ...@@ -287,6 +293,7 @@ static int motorcontrol_probe(struct usb_interface *intf, const struct usb_devic
struct usb_endpoint_descriptor *endpoint; struct usb_endpoint_descriptor *endpoint;
struct motorcontrol *mc; struct motorcontrol *mc;
int pipe, maxp, rc = -ENOMEM; int pipe, maxp, rc = -ENOMEM;
int bit, value;
interface = intf->cur_altsetting; interface = intf->cur_altsetting;
if (interface->desc.bNumEndpoints != 1) if (interface->desc.bNumEndpoints != 1)
...@@ -306,6 +313,7 @@ static int motorcontrol_probe(struct usb_interface *intf, const struct usb_devic ...@@ -306,6 +313,7 @@ static int motorcontrol_probe(struct usb_interface *intf, const struct usb_devic
if (!mc) if (!mc)
goto out; goto out;
mc->dev_no = -1;
mc->data = usb_buffer_alloc(dev, URB_INT_SIZE, SLAB_ATOMIC, &mc->data_dma); mc->data = usb_buffer_alloc(dev, URB_INT_SIZE, SLAB_ATOMIC, &mc->data_dma);
if (!mc->data) if (!mc->data)
goto out; goto out;
...@@ -326,26 +334,42 @@ static int motorcontrol_probe(struct usb_interface *intf, const struct usb_devic ...@@ -326,26 +334,42 @@ static int motorcontrol_probe(struct usb_interface *intf, const struct usb_devic
usb_set_intfdata(intf, mc); usb_set_intfdata(intf, mc);
do {
bit = find_first_zero_bit(&device_no, sizeof(device_no));
value = test_and_set_bit(bit, &device_no);
} while(value);
mc->dev_no = bit;
mc->dev = device_create(phidget_class, &mc->udev->dev, 0,
"motorcontrol%d", mc->dev_no);
if (IS_ERR(mc->dev)) {
rc = PTR_ERR(mc->dev);
mc->dev = NULL;
goto out;
}
dev_set_drvdata(mc->dev, mc);
if (usb_submit_urb(mc->irq, GFP_KERNEL)) { if (usb_submit_urb(mc->irq, GFP_KERNEL)) {
rc = -EIO; rc = -EIO;
goto out; goto out;
} }
device_create_file(&intf->dev, &dev_attr_input0); device_create_file(mc->dev, &dev_attr_input0);
device_create_file(&intf->dev, &dev_attr_input1); device_create_file(mc->dev, &dev_attr_input1);
device_create_file(&intf->dev, &dev_attr_input2); device_create_file(mc->dev, &dev_attr_input2);
device_create_file(&intf->dev, &dev_attr_input3); device_create_file(mc->dev, &dev_attr_input3);
device_create_file(&intf->dev, &dev_attr_speed0); device_create_file(mc->dev, &dev_attr_speed0);
device_create_file(&intf->dev, &dev_attr_speed1); device_create_file(mc->dev, &dev_attr_speed1);
device_create_file(&intf->dev, &dev_attr_acceleration0); device_create_file(mc->dev, &dev_attr_acceleration0);
device_create_file(&intf->dev, &dev_attr_acceleration1); device_create_file(mc->dev, &dev_attr_acceleration1);
device_create_file(&intf->dev, &dev_attr_current0); device_create_file(mc->dev, &dev_attr_current0);
device_create_file(&intf->dev, &dev_attr_current1); device_create_file(mc->dev, &dev_attr_current1);
dev_info(&intf->dev, "USB Phidget MotorControl attached\n"); dev_info(&intf->dev, "USB PhidgetMotorControl attached\n");
return 0; return 0;
...@@ -355,6 +379,11 @@ out: ...@@ -355,6 +379,11 @@ out:
usb_free_urb(mc->irq); usb_free_urb(mc->irq);
if (mc->data) if (mc->data)
usb_buffer_free(dev, URB_INT_SIZE, mc->data, mc->data_dma); usb_buffer_free(dev, URB_INT_SIZE, mc->data, mc->data_dma);
if (mc->dev)
device_unregister(mc->dev);
if (mc->dev_no >= 0)
clear_bit(mc->dev_no, &device_no);
kfree(mc); kfree(mc);
} }
...@@ -376,24 +405,27 @@ static void motorcontrol_disconnect(struct usb_interface *interface) ...@@ -376,24 +405,27 @@ static void motorcontrol_disconnect(struct usb_interface *interface)
cancel_delayed_work(&mc->do_notify); cancel_delayed_work(&mc->do_notify);
device_remove_file(&interface->dev, &dev_attr_input0); device_remove_file(mc->dev, &dev_attr_input0);
device_remove_file(&interface->dev, &dev_attr_input1); device_remove_file(mc->dev, &dev_attr_input1);
device_remove_file(&interface->dev, &dev_attr_input2); device_remove_file(mc->dev, &dev_attr_input2);
device_remove_file(&interface->dev, &dev_attr_input3); device_remove_file(mc->dev, &dev_attr_input3);
device_remove_file(&interface->dev, &dev_attr_speed0); device_remove_file(mc->dev, &dev_attr_speed0);
device_remove_file(&interface->dev, &dev_attr_speed1); device_remove_file(mc->dev, &dev_attr_speed1);
device_remove_file(&interface->dev, &dev_attr_acceleration0); device_remove_file(mc->dev, &dev_attr_acceleration0);
device_remove_file(&interface->dev, &dev_attr_acceleration1); device_remove_file(mc->dev, &dev_attr_acceleration1);
device_remove_file(&interface->dev, &dev_attr_current0); device_remove_file(mc->dev, &dev_attr_current0);
device_remove_file(&interface->dev, &dev_attr_current1); device_remove_file(mc->dev, &dev_attr_current1);
dev_info(&interface->dev, "USB Phidget MotorControl disconnected\n"); device_unregister(mc->dev);
usb_put_dev(mc->udev); usb_put_dev(mc->udev);
clear_bit(mc->dev_no, &device_no);
kfree(mc); kfree(mc);
dev_info(&interface->dev, "USB PhidgetMotorControl detached\n");
} }
static struct usb_driver motorcontrol_driver = { static struct usb_driver motorcontrol_driver = {
......
...@@ -15,14 +15,6 @@ ...@@ -15,14 +15,6 @@
* *
* CAUTION: Generally you should use 0 < degrees < 180 as anything else * CAUTION: Generally you should use 0 < degrees < 180 as anything else
* is probably beyond the range of your servo and may damage it. * is probably beyond the range of your servo and may damage it.
*
* Jun 16, 2004: Sean Young <sean@mess.org>
* - cleanups
* - was using memory after kfree()
* Aug 8, 2004: Sean Young <sean@mess.org>
* - set the highest angle as high as the hardware allows, there are
* some odd servos out there
*
*/ */
#include <linux/kernel.h> #include <linux/kernel.h>
...@@ -32,6 +24,8 @@ ...@@ -32,6 +24,8 @@
#include <linux/module.h> #include <linux/module.h>
#include <linux/usb.h> #include <linux/usb.h>
#include "phidget.h"
#define DRIVER_AUTHOR "Sean Young <sean@mess.org>" #define DRIVER_AUTHOR "Sean Young <sean@mess.org>"
#define DRIVER_DESC "USB PhidgetServo Driver" #define DRIVER_DESC "USB PhidgetServo Driver"
...@@ -70,8 +64,12 @@ static struct usb_device_id id_table[] = { ...@@ -70,8 +64,12 @@ static struct usb_device_id id_table[] = {
MODULE_DEVICE_TABLE(usb, id_table); MODULE_DEVICE_TABLE(usb, id_table);
static int unsigned long device_no;
struct phidget_servo { struct phidget_servo {
struct usb_device *udev; struct usb_device *udev;
struct device *dev;
int dev_no;
ulong type; ulong type;
int pulse[4]; int pulse[4];
int degrees[4]; int degrees[4];
...@@ -203,16 +201,16 @@ change_position_v20(struct phidget_servo *servo, int servo_no, int degrees, ...@@ -203,16 +201,16 @@ change_position_v20(struct phidget_servo *servo, int servo_no, int degrees,
} }
#define show_set(value) \ #define show_set(value) \
static ssize_t set_servo##value (struct device *dev, struct device_attribute *attr, \ static ssize_t set_servo##value (struct device *dev, \
struct device_attribute *attr, \
const char *buf, size_t count) \ const char *buf, size_t count) \
{ \ { \
int degrees, minutes, retval; \ int degrees, minutes, retval; \
struct usb_interface *intf = to_usb_interface (dev); \ struct phidget_servo *servo = dev_get_drvdata(dev); \
struct phidget_servo *servo = usb_get_intfdata (intf); \
\ \
minutes = 0; \ minutes = 0; \
/* must at least convert degrees */ \ /* must at least convert degrees */ \
if (sscanf (buf, "%d.%d", &degrees, &minutes) < 1) { \ if (sscanf(buf, "%d.%d", &degrees, &minutes) < 1) { \
return -EINVAL; \ return -EINVAL; \
} \ } \
\ \
...@@ -220,21 +218,22 @@ static ssize_t set_servo##value (struct device *dev, struct device_attribute *at ...@@ -220,21 +218,22 @@ static ssize_t set_servo##value (struct device *dev, struct device_attribute *at
return -EINVAL; \ return -EINVAL; \
\ \
if (servo->type & SERVO_VERSION_30) \ if (servo->type & SERVO_VERSION_30) \
retval = change_position_v30 (servo, value, degrees, \ retval = change_position_v30(servo, value, degrees, \
minutes); \ minutes); \
else \ else \
retval = change_position_v20 (servo, value, degrees, \ retval = change_position_v20(servo, value, degrees, \
minutes); \ minutes); \
\ \
return retval < 0 ? retval : count; \ return retval < 0 ? retval : count; \
} \ } \
\ \
static ssize_t show_servo##value (struct device *dev, struct device_attribute *attr, char *buf) \ static ssize_t show_servo##value (struct device *dev, \
struct device_attribute *attr, \
char *buf) \
{ \ { \
struct usb_interface *intf = to_usb_interface (dev); \ struct phidget_servo *servo = dev_get_drvdata(dev); \
struct phidget_servo *servo = usb_get_intfdata (intf); \
\ \
return sprintf (buf, "%d.%02d\n", servo->degrees[value], \ return sprintf(buf, "%d.%02d\n", servo->degrees[value], \
servo->minutes[value]); \ servo->minutes[value]); \
} \ } \
static DEVICE_ATTR(servo##value, S_IWUGO | S_IRUGO, \ static DEVICE_ATTR(servo##value, S_IWUGO | S_IRUGO, \
...@@ -250,6 +249,7 @@ servo_probe(struct usb_interface *interface, const struct usb_device_id *id) ...@@ -250,6 +249,7 @@ servo_probe(struct usb_interface *interface, const struct usb_device_id *id)
{ {
struct usb_device *udev = interface_to_usbdev(interface); struct usb_device *udev = interface_to_usbdev(interface);
struct phidget_servo *dev; struct phidget_servo *dev;
int bit, value;
dev = kzalloc(sizeof (struct phidget_servo), GFP_KERNEL); dev = kzalloc(sizeof (struct phidget_servo), GFP_KERNEL);
if (dev == NULL) { if (dev == NULL) {
...@@ -261,18 +261,33 @@ servo_probe(struct usb_interface *interface, const struct usb_device_id *id) ...@@ -261,18 +261,33 @@ servo_probe(struct usb_interface *interface, const struct usb_device_id *id)
dev->type = id->driver_info; dev->type = id->driver_info;
usb_set_intfdata(interface, dev); usb_set_intfdata(interface, dev);
device_create_file(&interface->dev, &dev_attr_servo0); do {
bit = find_first_zero_bit(&device_no, sizeof(device_no));
value = test_and_set_bit(bit, &device_no);
} while(value);
dev->dev_no = bit;
dev->dev = device_create(phidget_class, &dev->udev->dev, 0,
"servo%d", dev->dev_no);
if (IS_ERR(dev->dev)) {
int rc = PTR_ERR(dev->dev);
clear_bit(dev->dev_no, &device_no);
kfree(dev);
return rc;
}
device_create_file(dev->dev, &dev_attr_servo0);
if (dev->type & SERVO_COUNT_QUAD) { if (dev->type & SERVO_COUNT_QUAD) {
device_create_file(&interface->dev, &dev_attr_servo1); device_create_file(dev->dev, &dev_attr_servo1);
device_create_file(&interface->dev, &dev_attr_servo2); device_create_file(dev->dev, &dev_attr_servo2);
device_create_file(&interface->dev, &dev_attr_servo3); device_create_file(dev->dev, &dev_attr_servo3);
} }
dev_info(&interface->dev, "USB %d-Motor PhidgetServo v%d.0 attached\n", dev_info(&interface->dev, "USB %d-Motor PhidgetServo v%d.0 attached\n",
dev->type & SERVO_COUNT_QUAD ? 4 : 1, dev->type & SERVO_COUNT_QUAD ? 4 : 1,
dev->type & SERVO_VERSION_30 ? 3 : 2); dev->type & SERVO_VERSION_30 ? 3 : 2);
if(!(dev->type & SERVO_VERSION_30)) if (!(dev->type & SERVO_VERSION_30))
dev_info(&interface->dev, dev_info(&interface->dev,
"WARNING: v2.0 not tested! Please report if it works.\n"); "WARNING: v2.0 not tested! Please report if it works.\n");
...@@ -287,19 +302,21 @@ servo_disconnect(struct usb_interface *interface) ...@@ -287,19 +302,21 @@ servo_disconnect(struct usb_interface *interface)
dev = usb_get_intfdata(interface); dev = usb_get_intfdata(interface);
usb_set_intfdata(interface, NULL); usb_set_intfdata(interface, NULL);
device_remove_file(&interface->dev, &dev_attr_servo0); device_remove_file(dev->dev, &dev_attr_servo0);
if (dev->type & SERVO_COUNT_QUAD) { if (dev->type & SERVO_COUNT_QUAD) {
device_remove_file(&interface->dev, &dev_attr_servo1); device_remove_file(dev->dev, &dev_attr_servo1);
device_remove_file(&interface->dev, &dev_attr_servo2); device_remove_file(dev->dev, &dev_attr_servo2);
device_remove_file(&interface->dev, &dev_attr_servo3); device_remove_file(dev->dev, &dev_attr_servo3);
} }
device_unregister(dev->dev);
usb_put_dev(dev->udev); usb_put_dev(dev->udev);
dev_info(&interface->dev, "USB %d-Motor PhidgetServo v%d.0 detached\n", dev_info(&interface->dev, "USB %d-Motor PhidgetServo v%d.0 detached\n",
dev->type & SERVO_COUNT_QUAD ? 4 : 1, dev->type & SERVO_COUNT_QUAD ? 4 : 1,
dev->type & SERVO_VERSION_30 ? 3 : 2); dev->type & SERVO_VERSION_30 ? 3 : 2);
clear_bit(dev->dev_no, &device_no);
kfree(dev); kfree(dev);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment