aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/media
diff options
context:
space:
mode:
authorDevin Heitmueller <devin.heitmueller@gmail.com>2008-09-06 12:45:27 -0400
committerMauro Carvalho Chehab <mchehab@redhat.com>2008-10-12 07:37:08 -0400
commitbdc203e156ce938e12d957912bd29ca53d160540 (patch)
tree8fc2b01bc6f584dc71f506e0c6a25f96c515e184 /drivers/media
parent17a370bcca661a849c9af07feae86f42d0c6dfd1 (diff)
V4L/DVB (9039): Add support for new i2c API provided in firmware version 1.20
The Pinnacle PCTV HD Pro has an xc5000, which exposed a bug in the dib0700's i2c implementation where it did not properly support a single i2c read request (sending it as an i2c write request instead). Version 1.20 of the firmware added support for a new i2c API which supported such requests. This change defaults to fw 1.20 for all devices, but does not default to using the new i2c API (since initial testing suggests problems interacting with the mt2060). Maintainers can enable the use of the new i2c API by putting the following into their frontend initialization: struct dib0700_state *st = adap->dev->priv; st->fw_use_new_i2c_api = 1; Also note that the code expects i2c repeated start to be supported. If the i2c slave does not support repeated start, i2c messsages should have the I2C_M_NOSTART flag set. Thanks to Patrick Boettcher <patrick.boettcher@desy.de> for providing new firmware fixing the issue as well as example i2c code utilizing the interface. Signed-off-by: Devin Heitmueller <devin.heitmueller@gmail.com> Signed-off-by: Patrick Boettcher <pb@linuxtv.org> Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
Diffstat (limited to 'drivers/media')
-rw-r--r--drivers/media/dvb/dvb-usb/dib0700.h3
-rw-r--r--drivers/media/dvb/dvb-usb/dib0700_core.c108
-rw-r--r--drivers/media/dvb/dvb-usb/dib0700_devices.c2
3 files changed, 110 insertions, 3 deletions
diff --git a/drivers/media/dvb/dvb-usb/dib0700.h b/drivers/media/dvb/dvb-usb/dib0700.h
index 66d4dc6ba46f..cc0c51d82f2c 100644
--- a/drivers/media/dvb/dvb-usb/dib0700.h
+++ b/drivers/media/dvb/dvb-usb/dib0700.h
@@ -31,6 +31,8 @@ extern int dvb_usb_dib0700_debug;
31 // 2 Byte: MPEG2 mode: 4MSB(1 = Master Mode, 0 = Slave Mode) 4LSB(Channel 1 = bit0, Channel 2 = bit1) 31 // 2 Byte: MPEG2 mode: 4MSB(1 = Master Mode, 0 = Slave Mode) 4LSB(Channel 1 = bit0, Channel 2 = bit1)
32 // 2 Byte: Analog mode: 4MSB(0 = 625 lines, 1 = 525 lines) 4LSB( " " ) 32 // 2 Byte: Analog mode: 4MSB(0 = 625 lines, 1 = 525 lines) 4LSB( " " )
33#define REQUEST_SET_RC 0x11 33#define REQUEST_SET_RC 0x11
34#define REQUEST_NEW_I2C_READ 0x12
35#define REQUEST_NEW_I2C_WRITE 0x13
34#define REQUEST_GET_VERSION 0x15 36#define REQUEST_GET_VERSION 0x15
35 37
36struct dib0700_state { 38struct dib0700_state {
@@ -39,6 +41,7 @@ struct dib0700_state {
39 u8 rc_toggle; 41 u8 rc_toggle;
40 u8 rc_counter; 42 u8 rc_counter;
41 u8 is_dib7000pc; 43 u8 is_dib7000pc;
44 u8 fw_use_new_i2c_api;
42}; 45};
43 46
44extern int dib0700_set_gpio(struct dvb_usb_device *, enum dib07x0_gpios gpio, u8 gpio_dir, u8 gpio_val); 47extern int dib0700_set_gpio(struct dvb_usb_device *, enum dib07x0_gpios gpio, u8 gpio_dir, u8 gpio_val);
diff --git a/drivers/media/dvb/dvb-usb/dib0700_core.c b/drivers/media/dvb/dvb-usb/dib0700_core.c
index 595a04696c87..4daac8642006 100644
--- a/drivers/media/dvb/dvb-usb/dib0700_core.c
+++ b/drivers/media/dvb/dvb-usb/dib0700_core.c
@@ -82,9 +82,98 @@ int dib0700_set_gpio(struct dvb_usb_device *d, enum dib07x0_gpios gpio, u8 gpio_
82} 82}
83 83
84/* 84/*
85 * I2C master xfer function 85 * I2C master xfer function (supported in 1.20 firmware)
86 */ 86 */
87static int dib0700_i2c_xfer(struct i2c_adapter *adap,struct i2c_msg *msg,int num) 87static int dib0700_i2c_xfer_new(struct i2c_adapter *adap, struct i2c_msg *msg,
88 int num)
89{
90 /* The new i2c firmware messages are more reliable and in particular
91 properly support i2c read calls not preceded by a write */
92
93 struct dvb_usb_device *d = i2c_get_adapdata(adap);
94 uint8_t bus_mode = 1; /* 0=eeprom bus, 1=frontend bus */
95 uint8_t gen_mode = 0; /* 0=master i2c, 1=gpio i2c */
96 uint8_t en_start = 0;
97 uint8_t en_stop = 0;
98 uint8_t buf[255]; /* TBV: malloc ? */
99 int result, i;
100
101 /* Ensure nobody else hits the i2c bus while we're sending our
102 sequence of messages, (such as the remote control thread) */
103 if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
104 return -EAGAIN;
105
106 for (i = 0; i < num; i++) {
107 if (i == 0) {
108 /* First message in the transaction */
109 en_start = 1;
110 } else if (!(msg[i].flags & I2C_M_NOSTART)) {
111 /* Device supports repeated-start */
112 en_start = 1;
113 } else {
114 /* Not the first packet and device doesn't support
115 repeated start */
116 en_start = 0;
117 }
118 if (i == (num - 1)) {
119 /* Last message in the transaction */
120 en_stop = 1;
121 }
122
123 if (msg[i].flags & I2C_M_RD) {
124 /* Read request */
125 u16 index, value;
126 uint8_t i2c_dest;
127
128 i2c_dest = (msg[i].addr << 1);
129 value = ((en_start << 7) | (en_stop << 6) |
130 (msg[i].len & 0x3F)) << 8 | i2c_dest;
131 /* I2C ctrl + FE bus; */
132 index = ((gen_mode<<6)&0xC0) | ((bus_mode<<4)&0x30);
133
134 result = usb_control_msg(d->udev,
135 usb_rcvctrlpipe(d->udev, 0),
136 REQUEST_NEW_I2C_READ,
137 USB_TYPE_VENDOR | USB_DIR_IN,
138 value, index, msg[i].buf,
139 msg[i].len,
140 USB_CTRL_GET_TIMEOUT);
141 if (result < 0) {
142 err("i2c read error (status = %d)\n", result);
143 break;
144 }
145 } else {
146 /* Write request */
147 buf[0] = REQUEST_NEW_I2C_WRITE;
148 buf[1] = (msg[i].addr << 1);
149 buf[2] = (en_start << 7) | (en_stop << 6) |
150 (msg[i].len & 0x3F);
151 /* I2C ctrl + FE bus; */
152 buf[3] = ((gen_mode<<6)&0xC0) | ((bus_mode<<4)&0x30);
153 /* The Actual i2c payload */
154 memcpy(&buf[4], msg[i].buf, msg[i].len);
155
156 result = usb_control_msg(d->udev,
157 usb_sndctrlpipe(d->udev, 0),
158 REQUEST_NEW_I2C_WRITE,
159 USB_TYPE_VENDOR | USB_DIR_OUT,
160 0, 0, buf, msg[i].len + 4,
161 USB_CTRL_GET_TIMEOUT);
162 if (result < 0) {
163 err("i2c write error (status = %d)\n", result);
164 break;
165 }
166 }
167 }
168 mutex_unlock(&d->i2c_mutex);
169 return i;
170}
171
172/*
173 * I2C master xfer function (pre-1.20 firmware)
174 */
175static int dib0700_i2c_xfer_legacy(struct i2c_adapter *adap,
176 struct i2c_msg *msg, int num)
88{ 177{
89 struct dvb_usb_device *d = i2c_get_adapdata(adap); 178 struct dvb_usb_device *d = i2c_get_adapdata(adap);
90 int i,len; 179 int i,len;
@@ -124,6 +213,21 @@ static int dib0700_i2c_xfer(struct i2c_adapter *adap,struct i2c_msg *msg,int num
124 return i; 213 return i;
125} 214}
126 215
216static int dib0700_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg *msg,
217 int num)
218{
219 struct dvb_usb_device *d = i2c_get_adapdata(adap);
220 struct dib0700_state *st = d->priv;
221
222 if (st->fw_use_new_i2c_api == 1) {
223 /* User running at least fw 1.20 */
224 return dib0700_i2c_xfer_new(adap, msg, num);
225 } else {
226 /* Use legacy calls */
227 return dib0700_i2c_xfer_legacy(adap, msg, num);
228 }
229}
230
127static u32 dib0700_i2c_func(struct i2c_adapter *adapter) 231static u32 dib0700_i2c_func(struct i2c_adapter *adapter)
128{ 232{
129 return I2C_FUNC_I2C; 233 return I2C_FUNC_I2C;
diff --git a/drivers/media/dvb/dvb-usb/dib0700_devices.c b/drivers/media/dvb/dvb-usb/dib0700_devices.c
index 110d9344bc92..2555e53b31dd 100644
--- a/drivers/media/dvb/dvb-usb/dib0700_devices.c
+++ b/drivers/media/dvb/dvb-usb/dib0700_devices.c
@@ -1127,7 +1127,7 @@ MODULE_DEVICE_TABLE(usb, dib0700_usb_id_table);
1127#define DIB0700_DEFAULT_DEVICE_PROPERTIES \ 1127#define DIB0700_DEFAULT_DEVICE_PROPERTIES \
1128 .caps = DVB_USB_IS_AN_I2C_ADAPTER, \ 1128 .caps = DVB_USB_IS_AN_I2C_ADAPTER, \
1129 .usb_ctrl = DEVICE_SPECIFIC, \ 1129 .usb_ctrl = DEVICE_SPECIFIC, \
1130 .firmware = "dvb-usb-dib0700-1.10.fw", \ 1130 .firmware = "dvb-usb-dib0700-1.20.fw", \
1131 .download_firmware = dib0700_download_firmware, \ 1131 .download_firmware = dib0700_download_firmware, \
1132 .no_reconnect = 1, \ 1132 .no_reconnect = 1, \
1133 .size_of_priv = sizeof(struct dib0700_state), \ 1133 .size_of_priv = sizeof(struct dib0700_state), \