fedora core 6 1.2949 + vserver 2.2.0
[linux-2.6.git] / drivers / usb / misc / cytherm.c
index 8ea6a74..04e87ac 100644 (file)
@@ -14,7 +14,6 @@
  */
 
 
-#include <linux/config.h>
 #include <linux/kernel.h>
 #include <linux/errno.h>
 #include <linux/init.h>
@@ -46,14 +45,10 @@ struct usb_cytherm {
 static int cytherm_probe(struct usb_interface *interface, 
                         const struct usb_device_id *id);
 static void cytherm_disconnect(struct usb_interface *interface);
-int vendor_command(struct usb_device *dev, unsigned char request, 
-                  unsigned char value, unsigned char index,
-                  void *buf, int size);
 
 
 /* usb specific object needed to register this driver with the usb subsystem */
 static struct usb_driver cytherm_driver = {
-       .owner =        THIS_MODULE,
        .name =         "cytherm",
        .probe =        cytherm_probe,
        .disconnect =   cytherm_disconnect,
@@ -71,16 +66,16 @@ static struct usb_driver cytherm_driver = {
 
 
 /* Send a vendor command to device */
-int vendor_command(struct usb_device *dev, unsigned char request, 
-                  unsigned char value, unsigned char index,
-                  void *buf, int size)
+static int vendor_command(struct usb_device *dev, unsigned char request, 
+                         unsigned char value, unsigned char index,
+                         void *buf, int size)
 {
        return usb_control_msg(dev, usb_rcvctrlpipe(dev, 0),
                               request, 
                               USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_OTHER,
                               value, 
                               index, buf, size,
-                              HZ * USB_CTRL_GET_TIMEOUT);
+                              USB_CTRL_GET_TIMEOUT);
 }
 
 
@@ -88,7 +83,7 @@ int vendor_command(struct usb_device *dev, unsigned char request,
 #define BRIGHTNESS 0x2c     /* RAM location for brightness value */
 #define BRIGHTNESS_SEM 0x2b /* RAM location for brightness semaphore */
 
-static ssize_t show_brightness(struct device *dev, char *buf)
+static ssize_t show_brightness(struct device *dev, struct device_attribute *attr, char *buf)
 {
        struct usb_interface *intf = to_usb_interface(dev);    
        struct usb_cytherm *cytherm = usb_get_intfdata(intf);     
@@ -96,7 +91,7 @@ static ssize_t show_brightness(struct device *dev, char *buf)
        return sprintf(buf, "%i", cytherm->brightness);
 }
 
-static ssize_t set_brightness(struct device *dev, const char *buf, 
+static ssize_t set_brightness(struct device *dev, struct device_attribute *attr, const char *buf,
                              size_t count)
 {
        struct usb_interface *intf = to_usb_interface(dev);
@@ -122,12 +117,12 @@ static ssize_t set_brightness(struct device *dev, const char *buf,
        retval = vendor_command(cytherm->udev, WRITE_RAM, BRIGHTNESS, 
                                cytherm->brightness, buffer, 8);
        if (retval)
-               dev_dbg(&led->udev->dev, "retval = %d\n", retval);
+               dev_dbg(&cytherm->udev->dev, "retval = %d\n", retval);
        /* Inform µC that we have changed the brightness setting */
        retval = vendor_command(cytherm->udev, WRITE_RAM, BRIGHTNESS_SEM,
                                0x01, buffer, 8);
        if (retval)
-               dev_dbg(&led->udev->dev, "retval = %d\n", retval);
+               dev_dbg(&cytherm->udev->dev, "retval = %d\n", retval);
    
        kfree(buffer);
    
@@ -141,7 +136,7 @@ static DEVICE_ATTR(brightness, S_IRUGO | S_IWUSR | S_IWGRP,
 #define TEMP 0x33 /* RAM location for temperature */
 #define SIGN 0x34 /* RAM location for temperature sign */
 
-static ssize_t show_temp(struct device *dev, char *buf)
+static ssize_t show_temp(struct device *dev, struct device_attribute *attr, char *buf)
 {
 
        struct usb_interface *intf = to_usb_interface(dev);
@@ -161,13 +156,13 @@ static ssize_t show_temp(struct device *dev, char *buf)
        /* read temperature */
        retval = vendor_command(cytherm->udev, READ_RAM, TEMP, 0, buffer, 8);
        if (retval)
-               dev_dbg(&led->udev->dev, "retval = %d\n", retval);
+               dev_dbg(&cytherm->udev->dev, "retval = %d\n", retval);
        temp = buffer[1];
    
        /* read sign */
        retval = vendor_command(cytherm->udev, READ_RAM, SIGN, 0, buffer, 8);
        if (retval)
-               dev_dbg(&led->udev->dev, "retval = %d\n", retval);
+               dev_dbg(&cytherm->udev->dev, "retval = %d\n", retval);
        sign = buffer[1];
 
        kfree(buffer);
@@ -177,7 +172,7 @@ static ssize_t show_temp(struct device *dev, char *buf)
 }
 
 
-static ssize_t set_temp(struct device *dev, const char *buf, size_t count)
+static ssize_t set_temp(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
 {
        return count;
 }
@@ -187,7 +182,7 @@ static DEVICE_ATTR(temp, S_IRUGO, show_temp, set_temp);
 
 #define BUTTON 0x7a
 
-static ssize_t show_button(struct device *dev, char *buf)
+static ssize_t show_button(struct device *dev, struct device_attribute *attr, char *buf)
 {
 
        struct usb_interface *intf = to_usb_interface(dev);
@@ -205,7 +200,7 @@ static ssize_t show_button(struct device *dev, char *buf)
        /* check button */
        retval = vendor_command(cytherm->udev, READ_RAM, BUTTON, 0, buffer, 8);
        if (retval)
-               dev_dbg(&led->udev->dev, "retval = %d\n", retval);
+               dev_dbg(&cytherm->udev->dev, "retval = %d\n", retval);
    
        retval = buffer[1];
 
@@ -218,7 +213,7 @@ static ssize_t show_button(struct device *dev, char *buf)
 }
 
 
-static ssize_t set_button(struct device *dev, const char *buf, size_t count)
+static ssize_t set_button(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
 {
        return count;
 }
@@ -226,7 +221,7 @@ static ssize_t set_button(struct device *dev, const char *buf, size_t count)
 static DEVICE_ATTR(button, S_IRUGO, show_button, set_button);
 
 
-static ssize_t show_port0(struct device *dev, char *buf)
+static ssize_t show_port0(struct device *dev, struct device_attribute *attr, char *buf)
 {
        struct usb_interface *intf = to_usb_interface(dev);
        struct usb_cytherm *cytherm = usb_get_intfdata(intf);
@@ -242,7 +237,7 @@ static ssize_t show_port0(struct device *dev, char *buf)
 
        retval = vendor_command(cytherm->udev, READ_PORT, 0, 0, buffer, 8);
        if (retval)
-               dev_dbg(&led->udev->dev, "retval = %d\n", retval);
+               dev_dbg(&cytherm->udev->dev, "retval = %d\n", retval);
 
        retval = buffer[1];
 
@@ -252,7 +247,7 @@ static ssize_t show_port0(struct device *dev, char *buf)
 }
 
 
-static ssize_t set_port0(struct device *dev, const char *buf, size_t count)
+static ssize_t set_port0(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
 {
        struct usb_interface *intf = to_usb_interface(dev);
        struct usb_cytherm *cytherm = usb_get_intfdata(intf);
@@ -277,7 +272,7 @@ static ssize_t set_port0(struct device *dev, const char *buf, size_t count)
        retval = vendor_command(cytherm->udev, WRITE_PORT, 0,
                                tmp, buffer, 8);
        if (retval)
-               dev_dbg(&led->udev->dev, "retval = %d\n", retval);
+               dev_dbg(&cytherm->udev->dev, "retval = %d\n", retval);
 
        kfree(buffer);
 
@@ -286,7 +281,7 @@ static ssize_t set_port0(struct device *dev, const char *buf, size_t count)
 
 static DEVICE_ATTR(port0, S_IRUGO | S_IWUSR | S_IWGRP, show_port0, set_port0);
 
-static ssize_t show_port1(struct device *dev, char *buf)
+static ssize_t show_port1(struct device *dev, struct device_attribute *attr, char *buf)
 {
        struct usb_interface *intf = to_usb_interface(dev);
        struct usb_cytherm *cytherm = usb_get_intfdata(intf);
@@ -302,7 +297,7 @@ static ssize_t show_port1(struct device *dev, char *buf)
 
        retval = vendor_command(cytherm->udev, READ_PORT, 1, 0, buffer, 8);
        if (retval)
-               dev_dbg(&led->udev->dev, "retval = %d\n", retval);
+               dev_dbg(&cytherm->udev->dev, "retval = %d\n", retval);
    
        retval = buffer[1];
 
@@ -312,7 +307,7 @@ static ssize_t show_port1(struct device *dev, char *buf)
 }
 
 
-static ssize_t set_port1(struct device *dev, const char *buf, size_t count)
+static ssize_t set_port1(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
 {
        struct usb_interface *intf = to_usb_interface(dev);
        struct usb_cytherm *cytherm = usb_get_intfdata(intf);
@@ -337,7 +332,7 @@ static ssize_t set_port1(struct device *dev, const char *buf, size_t count)
        retval = vendor_command(cytherm->udev, WRITE_PORT, 1,
                                tmp, buffer, 8);
        if (retval)
-               dev_dbg(&led->udev->dev, "retval = %d\n", retval);
+               dev_dbg(&cytherm->udev->dev, "retval = %d\n", retval);
 
        kfree(buffer);
 
@@ -355,12 +350,11 @@ static int cytherm_probe(struct usb_interface *interface,
        struct usb_cytherm *dev = NULL;
        int retval = -ENOMEM;
 
-       dev = kmalloc (sizeof(struct usb_cytherm), GFP_KERNEL);
+       dev = kzalloc (sizeof(struct usb_cytherm), GFP_KERNEL);
        if (dev == NULL) {
                dev_err (&interface->dev, "Out of memory\n");
-               goto error;
+               goto error_mem;
        }
-       memset (dev, 0x00, sizeof (*dev));
 
        dev->udev = usb_get_dev(udev);
 
@@ -368,18 +362,35 @@ static int cytherm_probe(struct usb_interface *interface,
 
        dev->brightness = 0xFF;
 
-       device_create_file(&interface->dev, &dev_attr_brightness);   
-       device_create_file(&interface->dev, &dev_attr_temp);
-       device_create_file(&interface->dev, &dev_attr_button);
-       device_create_file(&interface->dev, &dev_attr_port0);
-       device_create_file(&interface->dev, &dev_attr_port1);
+       retval = device_create_file(&interface->dev, &dev_attr_brightness);
+       if (retval)
+               goto error;
+       retval = device_create_file(&interface->dev, &dev_attr_temp);
+       if (retval)
+               goto error;
+       retval = device_create_file(&interface->dev, &dev_attr_button);
+       if (retval)
+               goto error;
+       retval = device_create_file(&interface->dev, &dev_attr_port0);
+       if (retval)
+               goto error;
+       retval = device_create_file(&interface->dev, &dev_attr_port1);
+       if (retval)
+               goto error;
 
-       dev_info (&interface->dev, 
+       dev_info (&interface->dev,
                  "Cypress thermometer device now attached\n");
        return 0;
-
- error:
+error:
+       device_remove_file(&interface->dev, &dev_attr_brightness);
+       device_remove_file(&interface->dev, &dev_attr_temp);
+       device_remove_file(&interface->dev, &dev_attr_button);
+       device_remove_file(&interface->dev, &dev_attr_port0);
+       device_remove_file(&interface->dev, &dev_attr_port1);
+       usb_set_intfdata (interface, NULL);
+       usb_put_dev(dev->udev);
        kfree(dev);
+error_mem:
        return retval;
 }