[media] cx24116: add config option to split firmware download
authorAntti Palosaari <crope@iki.fi>
Thu, 28 Apr 2011 00:03:07 +0000 (21:03 -0300)
committerMauro Carvalho Chehab <mchehab@redhat.com>
Fri, 20 May 2011 12:30:00 +0000 (09:30 -0300)
It is very rare I2C adapter hardware which can provide 32kB I2C write
as one write. Add .i2c_wr_max option to set desired max packet size.
Split transaction to smaller pieces according to that option.

Signed-off-by: Antti Palosaari <crope@iki.fi>
Cc: Steven Toth <stoth@hauppauge.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
drivers/media/dvb/frontends/cx24116.c
drivers/media/dvb/frontends/cx24116.h

index cf1ec6c82042f862472b99ffa39bc171e47fcf5b..26e65a66719a75efa24c0f35280dc805fff1bf46 100644 (file)
@@ -566,7 +566,7 @@ static int cx24116_load_firmware(struct dvb_frontend *fe,
 {
        struct cx24116_state *state = fe->demodulator_priv;
        struct cx24116_cmd cmd;
-       int i, ret;
+       int i, ret, len, remaining;
        unsigned char vers[4];
 
        dprintk("%s\n", __func__);
@@ -603,8 +603,19 @@ static int cx24116_load_firmware(struct dvb_frontend *fe,
        cx24116_writereg(state, 0xF5, 0x00);
        cx24116_writereg(state, 0xF6, 0x00);
 
-       /* write the entire firmware as one transaction */
-       cx24116_writeregN(state, 0xF7, fw->data, fw->size);
+       /* Split firmware to the max I2C write len and write.
+        * This overflows 16 bit intentionally in order to get max write
+        * len when i2c_wr_max is set to 0. */
+       for (remaining = fw->size; remaining > 0;
+               remaining -= (u16) (state->config->i2c_wr_max - 1)) {
+
+               len = remaining;
+               if (len > (u16) (state->config->i2c_wr_max - 1))
+                       len = (u16) (state->config->i2c_wr_max - 1);
+
+               cx24116_writeregN(state, 0xF7, &fw->data[fw->size - remaining],
+                       len);
+       }
 
        cx24116_writereg(state, 0xF4, 0x10);
        cx24116_writereg(state, 0xF0, 0x00);
index b1b76b47a14cf2c97941a0e5721c85541742c645..7d90ab949c03f8c51f6a39a7a2795a1a9a3f85ff 100644 (file)
@@ -35,6 +35,9 @@ struct cx24116_config {
 
        /* Need to set MPEG parameters */
        u8 mpg_clk_pos_pol:0x02;
+
+       /* max bytes I2C provider can write at once */
+       u16 i2c_wr_max;
 };
 
 #if defined(CONFIG_DVB_CX24116) || \