[media] dvb-usb/it913x: multi firmware loader
authorMalcolm Priestley <tvboxspy@gmail.com>
Wed, 30 Nov 2011 20:14:47 +0000 (17:14 -0300)
committerMauro Carvalho Chehab <mchehab@redhat.com>
Sun, 11 Dec 2011 10:55:27 +0000 (08:55 -0200)
Multi firmware loader
 This uses scatter write firmware headers
 The firmware must start with 03 XX 00
 and be the extract firmware length.

 I have tried all available firmwares with this loader.

Signed-off-by: Malcolm Priestley <tvboxspy@gmail.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
drivers/media/dvb/dvb-usb/it913x.c

index 394bbf44e3d72ebd3db5babb7fc77036b7aa102e..c7bf03c3a6de8cda246f9d737ad594c827abc793 100644 (file)
@@ -485,35 +485,40 @@ static int it913x_streaming_ctrl(struct dvb_usb_adapter *adap, int onoff)
        return ret;
 }
 
-
 static int it913x_download_firmware(struct usb_device *udev,
                                        const struct firmware *fw)
 {
-       int ret = 0, i;
-       u8 packet_size, dlen;
+       int ret = 0, i = 0, pos = 0;
+       u8 packet_size;
        u8 *fw_data;
 
-       packet_size = 0x29;
-
        ret = it913x_wr_reg(udev, DEV_0,  I2C_CLK, I2C_CLK_100);
 
        info("FRM Starting Firmware Download");
-       /* This uses scatter write firmware headers follow */
-       /* 03 XX 00     XX = chip number? */ 
-
-       for (i = 0; i < fw->size; i += packet_size) {
-                       if (i > 0)
-                               packet_size = 0x39;
-                       fw_data = (u8 *)(fw->data + i);
-                       dlen = ((i + packet_size) > fw->size)
-                               ? (fw->size - i) : packet_size;
-                       ret |= it913x_io(udev, WRITE_DATA, DEV_0,
-                               CMD_SCATTER_WRITE, 0, 0, fw_data, dlen);
-                       udelay(1000);
+
+       /* Multi firmware loader */
+       /* This uses scatter write firmware headers */
+       /* The firmware must start with 03 XX 00 */
+       /* and be the extact firmware length */
+
+       while (i <= fw->size) {
+               if (((fw->data[i] == 0x3) && (fw->data[i + 2] == 0x0))
+                       || (i == fw->size)) {
+                       packet_size = i - pos;
+                       if ((packet_size > 0x19) || (i == fw->size)) {
+                               fw_data = (u8 *)(fw->data + pos);
+                               pos += packet_size;
+                               if (packet_size > 0)
+                                       ret |= it913x_io(udev, WRITE_DATA,
+                                               DEV_0, CMD_SCATTER_WRITE, 0,
+                                               0, fw_data, packet_size);
+                               udelay(1000);
+                       }
+               }
+               i++;
        }
 
-       ret |= it913x_io(udev, WRITE_CMD, DEV_0,
-                       CMD_BOOT, 0, 0, NULL, 0);
+       ret |= it913x_io(udev, WRITE_CMD, DEV_0, CMD_BOOT, 0, 0, NULL, 0);
 
        msleep(100);