include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit...
[linux-3.10.git] / drivers / media / video / au0828 / au0828-core.c
index 0bc85b7..ca342e4 100644 (file)
@@ -20,6 +20,7 @@
  */
 
 #include <linux/module.h>
+#include <linux/slab.h>
 #include <linux/videodev2.h>
 #include <media/v4l2-common.h>
 #include <linux/mutex.h>
@@ -36,6 +37,11 @@ int au0828_debug;
 module_param_named(debug, au0828_debug, int, 0644);
 MODULE_PARM_DESC(debug, "enable debug messages");
 
+static unsigned int disable_usb_speed_check;
+module_param(disable_usb_speed_check, int, 0444);
+MODULE_PARM_DESC(disable_usb_speed_check,
+                "override min bandwidth requirement of 480M bps");
+
 #define _AU0828_BULKPIPE 0x03
 #define _BULKPIPESIZE 0xffff
 
@@ -51,13 +57,13 @@ static int recv_control_msg(struct au0828_dev *dev, u16 request, u32 value,
 u32 au0828_readreg(struct au0828_dev *dev, u16 reg)
 {
        recv_control_msg(dev, CMD_REQUEST_IN, 0, reg, dev->ctrlmsg, 1);
-       dprintk(8, "%s(0x%x) = 0x%x\n", __func__, reg, dev->ctrlmsg[0]);
+       dprintk(8, "%s(0x%04x) = 0x%02x\n", __func__, reg, dev->ctrlmsg[0]);
        return dev->ctrlmsg[0];
 }
 
 u32 au0828_writereg(struct au0828_dev *dev, u16 reg, u32 val)
 {
-       dprintk(8, "%s(0x%x, 0x%x)\n", __func__, reg, val);
+       dprintk(8, "%s(0x%04x, 0x%02x)\n", __func__, reg, val);
        return send_control_msg(dev, CMD_REQUEST_OUT, val, reg,
                                dev->ctrlmsg, 0);
 }
@@ -146,12 +152,14 @@ static void au0828_usb_disconnect(struct usb_interface *interface)
        /* Digital TV */
        au0828_dvb_unregister(dev);
 
-       if (dev->board.input != NULL)
+       if (AUVI_INPUT(0).type != AU0828_VMUX_UNDEFINED)
                au0828_analog_unregister(dev);
 
        /* I2C */
        au0828_i2c_unregister(dev);
 
+       v4l2_device_unregister(&dev->v4l2_dev);
+
        usb_set_intfdata(interface, NULL);
 
        mutex_lock(&dev->mutex);
@@ -165,11 +173,9 @@ static void au0828_usb_disconnect(struct usb_interface *interface)
 static int au0828_usb_probe(struct usb_interface *interface,
        const struct usb_device_id *id)
 {
-       int ifnum, i;
+       int ifnum, retval;
        struct au0828_dev *dev;
        struct usb_device *usbdev = interface_to_usbdev(interface);
-       struct usb_host_interface *iface_desc;
-       struct usb_endpoint_descriptor *endpoint;
 
        ifnum = interface->altsetting->desc.bInterfaceNumber;
 
@@ -181,6 +187,18 @@ static int au0828_usb_probe(struct usb_interface *interface,
                le16_to_cpu(usbdev->descriptor.idProduct),
                ifnum);
 
+       /*
+        * Make sure we have 480 Mbps of bandwidth, otherwise things like
+        * video stream wouldn't likely work, since 12 Mbps is generally
+        * not enough even for most Digital TV streams.
+        */
+       if (usbdev->speed != USB_SPEED_HIGH && disable_usb_speed_check == 0) {
+               printk(KERN_ERR "au0828: Device initialization failed.\n");
+               printk(KERN_ERR "au0828: Device must be connected to a "
+                      "high-speed USB 2.0 port.\n");
+               return -ENODEV;
+       }
+
        dev = kzalloc(sizeof(*dev), GFP_KERNEL);
        if (dev == NULL) {
                printk(KERN_ERR "%s() Unable to allocate memory\n", __func__);
@@ -192,32 +210,15 @@ static int au0828_usb_probe(struct usb_interface *interface,
        dev->usbdev = usbdev;
        dev->boardnr = id->driver_info;
 
-       usb_set_intfdata(interface, dev);
-
-       /* set au0828 usb interface0 to as5 */
-       usb_set_interface(usbdev,
-                         interface->cur_altsetting->desc.bInterfaceNumber, 5);
-
-       /* Figure out which endpoint has the isoc interface */
-       iface_desc = interface->cur_altsetting;
-       for(i = 0; i < iface_desc->desc.bNumEndpoints; i++){
-               endpoint = &iface_desc->endpoint[i].desc;
-               if(((endpoint->bEndpointAddress & USB_ENDPOINT_DIR_MASK) == USB_DIR_IN) &&
-                  ((endpoint->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) == USB_ENDPOINT_XFER_ISOC)){
-
-                       /* we find our isoc in endpoint */
-                       u16 tmp = le16_to_cpu(endpoint->wMaxPacketSize);
-                       dev->max_pkt_size = (tmp & 0x07ff) * (((tmp & 0x1800) >> 11) + 1);
-                       dev->isoc_in_endpointaddr = endpoint->bEndpointAddress;
-               }
-       }
-       if(!(dev->isoc_in_endpointaddr)) {
-               printk("Could not locate isoc endpoint\n");
+       /* Create the v4l2_device */
+       retval = v4l2_device_register(&interface->dev, &dev->v4l2_dev);
+       if (retval) {
+               printk(KERN_ERR "%s() v4l2_device_register failed\n",
+                      __func__);
                kfree(dev);
-               return -ENODEV;
+               return -EIO;
        }
 
-
        /* Power Up the bridge */
        au0828_write(dev, REG_600, 1 << 4);
 
@@ -231,12 +232,16 @@ static int au0828_usb_probe(struct usb_interface *interface,
        au0828_card_setup(dev);
 
        /* Analog TV */
-       if (dev->board.input != NULL)
-               au0828_analog_register(dev);
+       if (AUVI_INPUT(0).type != AU0828_VMUX_UNDEFINED)
+               au0828_analog_register(dev, interface);
 
        /* Digital TV */
        au0828_dvb_register(dev);
 
+       /* Store the pointer to the au0828_dev so it can be accessed in
+          au0828_usb_disconnect */
+       usb_set_intfdata(interface, dev);
+
        printk(KERN_INFO "Registered device AU0828 [%s]\n",
                dev->board.name == NULL ? "Unset" : dev->board.name);