Pull bugzilla-5452 into release branch
[pandora-kernel.git] / drivers / media / dvb / ttusb-budget / dvb-ttusb-budget.c
index fd53d60..6ceae38 100644 (file)
@@ -19,7 +19,7 @@
 #include <linux/time.h>
 #include <linux/errno.h>
 #include <linux/jiffies.h>
-#include <asm/semaphore.h>
+#include <linux/mutex.h>
 
 #include "dvb_frontend.h"
 #include "dmxdev.h"
@@ -35,7 +35,6 @@
 #include <linux/dvb/dmx.h>
 #include <linux/pci.h>
 
-
 /*
   TTUSB_HWSECTIONS:
     the DSP supports filtering in hardware, however, since the "muxstream"
@@ -83,8 +82,8 @@ struct ttusb {
        struct dvb_net dvbnet;
 
        /* and one for USB access. */
-       struct semaphore semi2c;
-       struct semaphore semusb;
+       struct mutex semi2c;
+       struct mutex semusb;
 
        struct dvb_adapter adapter;
        struct usb_device *dev;
@@ -150,7 +149,7 @@ static int ttusb_cmd(struct ttusb *ttusb,
        printk("\n");
 #endif
 
-       if (down_interruptible(&ttusb->semusb) < 0)
+       if (mutex_lock_interruptible(&ttusb->semusb) < 0)
                return -EAGAIN;
 
        err = usb_bulk_msg(ttusb->dev, ttusb->bulk_out_pipe,
@@ -158,13 +157,13 @@ static int ttusb_cmd(struct ttusb *ttusb,
        if (err != 0) {
                dprintk("%s: usb_bulk_msg(send) failed, err == %i!\n",
                        __FUNCTION__, err);
-               up(&ttusb->semusb);
+               mutex_unlock(&ttusb->semusb);
                return err;
        }
        if (actual_len != len) {
                dprintk("%s: only wrote %d of %d bytes\n", __FUNCTION__,
                        actual_len, len);
-               up(&ttusb->semusb);
+               mutex_unlock(&ttusb->semusb);
                return -1;
        }
 
@@ -174,7 +173,7 @@ static int ttusb_cmd(struct ttusb *ttusb,
        if (err != 0) {
                printk("%s: failed, receive error %d\n", __FUNCTION__,
                       err);
-               up(&ttusb->semusb);
+               mutex_unlock(&ttusb->semusb);
                return err;
        }
 #if DEBUG >= 3
@@ -185,14 +184,14 @@ static int ttusb_cmd(struct ttusb *ttusb,
        printk("\n");
 #endif
        if (!needresult)
-               up(&ttusb->semusb);
+               mutex_unlock(&ttusb->semusb);
        return 0;
 }
 
 static int ttusb_result(struct ttusb *ttusb, u8 * data, int len)
 {
        memcpy(data, ttusb->last_result, len);
-       up(&ttusb->semusb);
+       mutex_unlock(&ttusb->semusb);
        return 0;
 }
 
@@ -225,8 +224,8 @@ static int ttusb_i2c_msg(struct ttusb *ttusb,
 
        err = ttusb_result(ttusb, b, 0x20);
 
-        /* check if the i2c transaction was successful */
-        if ((snd_len != b[5]) || (rcv_len != b[6])) return -EREMOTEIO;
+       /* check if the i2c transaction was successful */
+       if ((snd_len != b[5]) || (rcv_len != b[6])) return -EREMOTEIO;
 
        if (rcv_len > 0) {
 
@@ -250,7 +249,7 @@ static int master_xfer(struct i2c_adapter* adapter, struct i2c_msg *msg, int num
        int i = 0;
        int inc;
 
-       if (down_interruptible(&ttusb->semi2c) < 0)
+       if (mutex_lock_interruptible(&ttusb->semi2c) < 0)
                return -EAGAIN;
 
        while (i < num) {
@@ -284,7 +283,7 @@ static int master_xfer(struct i2c_adapter* adapter, struct i2c_msg *msg, int num
                i += inc;
        }
 
-       up(&ttusb->semi2c);
+       mutex_unlock(&ttusb->semi2c);
        return i;
 }
 
@@ -489,27 +488,27 @@ static int ttusb_send_diseqc(struct dvb_frontend* fe,
 
 static int lnbp21_set_voltage(struct dvb_frontend* fe, fe_sec_voltage_t voltage)
 {
-        struct  ttusb* ttusb = (struct ttusb*)  fe->dvb->priv;
-        int ret;
-        u8 data[1];
-        struct i2c_msg msg = { .addr = 0x08, .flags = 0, .buf = data, .len = sizeof(data) };
-
-        switch(voltage) {
-        case SEC_VOLTAGE_OFF:
-                data[0] = 0x00;
-                break;
-        case SEC_VOLTAGE_13:
-                data[0] = 0x44;
-                break;
-        case SEC_VOLTAGE_18:
-                data[0] = 0x4c;
-                break;
-        default:
-                return -EINVAL;
-        };
-
-        ret = i2c_transfer(&ttusb->i2c_adap, &msg, 1);
-        return (ret != 1) ? -EIO : 0;
+       struct  ttusb* ttusb = (struct ttusb*)  fe->dvb->priv;
+       int ret;
+       u8 data[1];
+       struct i2c_msg msg = { .addr = 0x08, .flags = 0, .buf = data, .len = sizeof(data) };
+
+       switch(voltage) {
+       case SEC_VOLTAGE_OFF:
+               data[0] = 0x00;
+               break;
+       case SEC_VOLTAGE_13:
+               data[0] = 0x44;
+               break;
+       case SEC_VOLTAGE_18:
+               data[0] = 0x4c;
+               break;
+       default:
+               return -EINVAL;
+       };
+
+       ret = i2c_transfer(&ttusb->i2c_adap, &msg, 1);
+       return (ret != 1) ? -EIO : 0;
 }
 
 static int ttusb_update_lnb(struct ttusb *ttusb)
@@ -689,8 +688,7 @@ static void ttusb_process_frame(struct ttusb *ttusb, u8 * data, int len)
                                memcpy(ttusb->muxpack + ttusb->muxpack_ptr,
                                       data, avail);
                                ttusb->muxpack_ptr += avail;
-                               if (ttusb->muxpack_ptr > 264)
-                                       BUG();
+                               BUG_ON(ttusb->muxpack_ptr > 264);
                                data += avail;
                                len -= avail;
                                /* determine length */
@@ -1184,45 +1182,45 @@ static struct tda1004x_config philips_tdm1316l_config = {
 };
 
 static u8 alps_bsbe1_inittab[] = {
-        0x01, 0x15,
-        0x02, 0x30,
-        0x03, 0x00,
-        0x04, 0x7d,             /* F22FR = 0x7d, F22 = f_VCO / 128 / 0x7d = 22 kHz */
-        0x05, 0x35,             /* I2CT = 0, SCLT = 1, SDAT = 1 */
-        0x06, 0x40,             /* DAC not used, set to high impendance mode */
-        0x07, 0x00,             /* DAC LSB */
-        0x08, 0x40,             /* DiSEqC off, LNB power on OP2/LOCK pin on */
-        0x09, 0x00,             /* FIFO */
-        0x0c, 0x51,             /* OP1 ctl = Normal, OP1 val = 1 (LNB Power ON) */
-        0x0d, 0x82,             /* DC offset compensation = ON, beta_agc1 = 2 */
-        0x0e, 0x23,             /* alpha_tmg = 2, beta_tmg = 3 */
-        0x10, 0x3f,             // AGC2  0x3d
-        0x11, 0x84,
-        0x12, 0xb9,
-        0x15, 0xc9,             // lock detector threshold
-        0x16, 0x00,
-        0x17, 0x00,
-        0x18, 0x00,
-        0x19, 0x00,
-        0x1a, 0x00,
-        0x1f, 0x50,
-        0x20, 0x00,
-        0x21, 0x00,
-        0x22, 0x00,
-        0x23, 0x00,
-        0x28, 0x00,             // out imp: normal  out type: parallel FEC mode:0
-        0x29, 0x1e,             // 1/2 threshold
-        0x2a, 0x14,             // 2/3 threshold
-        0x2b, 0x0f,             // 3/4 threshold
-        0x2c, 0x09,             // 5/6 threshold
-        0x2d, 0x05,             // 7/8 threshold
-        0x2e, 0x01,
-        0x31, 0x1f,             // test all FECs
-        0x32, 0x19,             // viterbi and synchro search
-        0x33, 0xfc,             // rs control
-        0x34, 0x93,             // error control
-        0x0f, 0x92,
-        0xff, 0xff
+       0x01, 0x15,
+       0x02, 0x30,
+       0x03, 0x00,
+       0x04, 0x7d,             /* F22FR = 0x7d, F22 = f_VCO / 128 / 0x7d = 22 kHz */
+       0x05, 0x35,             /* I2CT = 0, SCLT = 1, SDAT = 1 */
+       0x06, 0x40,             /* DAC not used, set to high impendance mode */
+       0x07, 0x00,             /* DAC LSB */
+       0x08, 0x40,             /* DiSEqC off, LNB power on OP2/LOCK pin on */
+       0x09, 0x00,             /* FIFO */
+       0x0c, 0x51,             /* OP1 ctl = Normal, OP1 val = 1 (LNB Power ON) */
+       0x0d, 0x82,             /* DC offset compensation = ON, beta_agc1 = 2 */
+       0x0e, 0x23,             /* alpha_tmg = 2, beta_tmg = 3 */
+       0x10, 0x3f,             // AGC2  0x3d
+       0x11, 0x84,
+       0x12, 0xb9,
+       0x15, 0xc9,             // lock detector threshold
+       0x16, 0x00,
+       0x17, 0x00,
+       0x18, 0x00,
+       0x19, 0x00,
+       0x1a, 0x00,
+       0x1f, 0x50,
+       0x20, 0x00,
+       0x21, 0x00,
+       0x22, 0x00,
+       0x23, 0x00,
+       0x28, 0x00,             // out imp: normal  out type: parallel FEC mode:0
+       0x29, 0x1e,             // 1/2 threshold
+       0x2a, 0x14,             // 2/3 threshold
+       0x2b, 0x0f,             // 3/4 threshold
+       0x2c, 0x09,             // 5/6 threshold
+       0x2d, 0x05,             // 7/8 threshold
+       0x2e, 0x01,
+       0x31, 0x1f,             // test all FECs
+       0x32, 0x19,             // viterbi and synchro search
+       0x33, 0xfc,             // rs control
+       0x34, 0x93,             // error control
+       0x0f, 0x92,
+       0xff, 0xff
 };
 
 static u8 alps_bsru6_inittab[] = {
@@ -1350,7 +1348,7 @@ static int ttusb_novas_grundig_29504_491_pll_set(struct dvb_frontend *fe, struct
        u32 div;
        struct i2c_msg msg = {.addr = 0x61,.flags = 0,.buf = buf,.len = sizeof(buf) };
 
-        div = params->frequency / 125;
+       div = params->frequency / 125;
 
        buf[0] = (div >> 8) & 0x7f;
        buf[1] = div & 0xff;
@@ -1487,18 +1485,19 @@ static int ttusb_probe(struct usb_interface *intf, const struct usb_device_id *i
 
        udev = interface_to_usbdev(intf);
 
-        if (intf->altsetting->desc.bInterfaceNumber != 1) return -ENODEV;
+       if (intf->altsetting->desc.bInterfaceNumber != 1) return -ENODEV;
 
-       if (!(ttusb = kmalloc(sizeof(struct ttusb), GFP_KERNEL)))
+       if (!(ttusb = kzalloc(sizeof(struct ttusb), GFP_KERNEL)))
                return -ENOMEM;
 
-       memset(ttusb, 0, sizeof(struct ttusb));
-
        ttusb->dev = udev;
        ttusb->c = 0;
        ttusb->mux_state = 0;
-       sema_init(&ttusb->semi2c, 0);
-       sema_init(&ttusb->semusb, 1);
+       mutex_init(&ttusb->semi2c);
+
+       mutex_lock(&ttusb->semi2c);
+
+       mutex_init(&ttusb->semusb);
 
        ttusb_setup_interfaces(ttusb);
 
@@ -1506,9 +1505,13 @@ static int ttusb_probe(struct usb_interface *intf, const struct usb_device_id *i
        if (ttusb_init_controller(ttusb))
                printk("ttusb_init_controller: error\n");
 
-       up(&ttusb->semi2c);
+       mutex_unlock(&ttusb->semi2c);
 
-       dvb_register_adapter(&ttusb->adapter, "Technotrend/Hauppauge Nova-USB", THIS_MODULE);
+       if ((result = dvb_register_adapter(&ttusb->adapter, "Technotrend/Hauppauge Nova-USB", THIS_MODULE)) < 0) {
+               ttusb_free_iso_urbs(ttusb);
+               kfree(ttusb);
+               return result;
+       }
        ttusb->adapter.priv = ttusb;
 
        /* i2c */