[media] DiB0700: add function to change I2C-speed
authorOlivier Grenie <olivier.grenie@dibcom.fr>
Mon, 3 Jan 2011 18:30:14 +0000 (15:30 -0300)
committerMauro Carvalho Chehab <mchehab@redhat.com>
Mon, 21 Mar 2011 23:31:41 +0000 (20:31 -0300)
This commit adds a function to the DiB0700 USB driver which allows
drivers to change the I2C clock speed.

Signed-off-by: Olivier Grenie <olivier.grenie@dibcom.fr>
Signed-off-by: Patrick Boettcher <patrick.boettcher@dibcom.fr>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
drivers/media/dvb/dvb-usb/dib0700.h
drivers/media/dvb/dvb-usb/dib0700_core.c

index 3537d65c04bc02ad6a417b94eeba872cb3a82b2f..b2a87f2c2c3e43f8bf73c42e9915d6249533e260 100644 (file)
@@ -32,6 +32,7 @@ extern int dvb_usb_dib0700_debug;
        // 1 Byte: 4MSB(1 = enable streaming, 0 = disable streaming) 4LSB(Video Mode: 0 = MPEG2 188Bytes, 1 = Analog)
        // 2 Byte: MPEG2 mode:  4MSB(1 = Master Mode, 0 = Slave Mode) 4LSB(Channel 1 = bit0, Channel 2 = bit1)
        // 2 Byte: Analog mode: 4MSB(0 = 625 lines, 1 = 525 lines)    4LSB(     "                "           )
+#define REQUEST_SET_I2C_PARAM       0x10
 #define REQUEST_SET_RC              0x11
 #define REQUEST_NEW_I2C_READ        0x12
 #define REQUEST_NEW_I2C_WRITE       0x13
@@ -61,6 +62,7 @@ extern struct i2c_algorithm dib0700_i2c_algo;
 extern int dib0700_identify_state(struct usb_device *udev, struct dvb_usb_device_properties *props,
                        struct dvb_usb_device_description **desc, int *cold);
 extern int dib0700_change_protocol(struct rc_dev *dev, u64 rc_type);
+extern int dib0700_set_i2c_speed(struct dvb_usb_device *d, u16 scl_kHz);
 
 extern int dib0700_device_count;
 extern int dvb_usb_dib0700_ir_proto;
index 98ffb40728e34eeaed9f90e981950cae3610630e..ebda77dde97eff0cff7802d48774d1d8de055a7c 100644 (file)
@@ -328,6 +328,30 @@ static int dib0700_set_clock(struct dvb_usb_device *d, u8 en_pll,
        return dib0700_ctrl_wr(d, b, 10);
 }
 
+int dib0700_set_i2c_speed(struct dvb_usb_device *d, u16 scl_kHz)
+{
+       u16 divider;
+       u8 b[8];
+
+       if (scl_kHz == 0)
+               return -EINVAL;
+
+       b[0] = REQUEST_SET_I2C_PARAM;
+       divider = (u16) (30000 / scl_kHz);
+       b[2] = (u8) (divider >> 8);
+       b[3] = (u8) (divider & 0xff);
+       divider = (u16) (72000 / scl_kHz);
+       b[4] = (u8) (divider >> 8);
+       b[5] = (u8) (divider & 0xff);
+       divider = (u16) (72000 / scl_kHz); /* clock: 72MHz */
+       b[6] = (u8) (divider >> 8);
+       b[7] = (u8) (divider & 0xff);
+
+       deb_info("setting I2C speed: %04x %04x %04x (%d kHz).", (b[2] << 8) | (b[3]), (b[4] << 8) | b[5], (b[6] << 8) | b[7], scl_kHz);
+       return dib0700_ctrl_wr(d, b, 8);
+}
+
+
 int dib0700_ctrl_clock(struct dvb_usb_device *d, u32 clk_MHz, u8 clock_out_gp3)
 {
        switch (clk_MHz) {
@@ -459,10 +483,20 @@ int dib0700_streaming_ctrl(struct dvb_usb_adapter *adap, int onoff)
 
        deb_info("modifying (%d) streaming state for %d\n", onoff, adap->id);
 
-       if (onoff)
-               st->channel_state |=   1 << adap->id;
-       else
-               st->channel_state &= ~(1 << adap->id);
+       st->channel_state &= ~0x3;
+       if ((adap->stream.props.endpoint != 2) && (adap->stream.props.endpoint != 3)) {
+               deb_info("the endpoint number (%i) is not correct, use the adapter id instead", adap->stream.props.endpoint);
+               if (onoff)
+                       st->channel_state |=    1 << (adap->id);
+               else
+                       st->channel_state |=    1 << ~(adap->id);
+       }
+       else {
+               if (onoff)
+                       st->channel_state |=    1 << (adap->stream.props.endpoint-2);
+               else
+                       st->channel_state |=    1 << (3-adap->stream.props.endpoint);
+       }
 
        b[2] |= st->channel_state;