diff options
author | Mauro Carvalho Chehab <mchehab@redhat.com> | 2009-03-03 04:14:34 -0500 |
---|---|---|
committer | Mauro Carvalho Chehab <mchehab@redhat.com> | 2009-04-06 20:44:01 -0400 |
commit | 84b5dbf39ed2f51224841bbbf08439158d69d427 (patch) | |
tree | b24963462dc1ad93860645d8729d1ddfc6ce526e /drivers/media/video/cx231xx/cx231xx-i2c.c | |
parent | e0d3bafd02586cfde286c320f56906fd9fa8d256 (diff) |
V4L/DVB (10955): cx231xx: CodingStyle automatic fixes with Lindent
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
Diffstat (limited to 'drivers/media/video/cx231xx/cx231xx-i2c.c')
-rw-r--r-- | drivers/media/video/cx231xx/cx231xx-i2c.c | 567 |
1 files changed, 294 insertions, 273 deletions
diff --git a/drivers/media/video/cx231xx/cx231xx-i2c.c b/drivers/media/video/cx231xx/cx231xx-i2c.c index d75ed6c3c8d7..c250ad27e1d2 100644 --- a/drivers/media/video/cx231xx/cx231xx-i2c.c +++ b/drivers/media/video/cx231xx/cx231xx-i2c.c | |||
@@ -2,8 +2,8 @@ | |||
2 | cx231xx-i2c.c - driver for Conexant Cx23100/101/102 USB video capture devices | 2 | cx231xx-i2c.c - driver for Conexant Cx23100/101/102 USB video capture devices |
3 | 3 | ||
4 | Copyright (C) 2008 <srinivasa.deevi at conexant dot com> | 4 | Copyright (C) 2008 <srinivasa.deevi at conexant dot com> |
5 | Based on em28xx driver | 5 | Based on em28xx driver |
6 | Based on Cx23885 driver | 6 | Based on Cx23885 driver |
7 | 7 | ||
8 | This program is free software; you can redistribute it and/or modify | 8 | This program is free software; you can redistribute it and/or modify |
9 | it under the terms of the GNU General Public License as published by | 9 | it under the terms of the GNU General Public License as published by |
@@ -29,7 +29,6 @@ | |||
29 | 29 | ||
30 | #include "cx231xx.h" | 30 | #include "cx231xx.h" |
31 | 31 | ||
32 | |||
33 | /* ----------------------------------------------------------- */ | 32 | /* ----------------------------------------------------------- */ |
34 | 33 | ||
35 | static unsigned int i2c_scan; | 34 | static unsigned int i2c_scan; |
@@ -40,7 +39,6 @@ static unsigned int i2c_debug; | |||
40 | module_param(i2c_debug, int, 0644); | 39 | module_param(i2c_debug, int, 0644); |
41 | MODULE_PARM_DESC(i2c_debug, "enable debug messages [i2c]"); | 40 | MODULE_PARM_DESC(i2c_debug, "enable debug messages [i2c]"); |
42 | 41 | ||
43 | |||
44 | #define dprintk1(lvl, fmt, args...) \ | 42 | #define dprintk1(lvl, fmt, args...) \ |
45 | do { \ | 43 | do { \ |
46 | if (i2c_debug >= lvl) { \ | 44 | if (i2c_debug >= lvl) { \ |
@@ -56,116 +54,119 @@ do { \ | |||
56 | } \ | 54 | } \ |
57 | } while (0) | 55 | } while (0) |
58 | 56 | ||
59 | |||
60 | /* | 57 | /* |
61 | * cx231xx_i2c_send_bytes() | 58 | * cx231xx_i2c_send_bytes() |
62 | */ | 59 | */ |
63 | int cx231xx_i2c_send_bytes(struct i2c_adapter *i2c_adap, | 60 | int cx231xx_i2c_send_bytes(struct i2c_adapter *i2c_adap, |
64 | const struct i2c_msg *msg) | 61 | const struct i2c_msg *msg) |
65 | { | 62 | { |
66 | struct cx231xx_i2c *bus = i2c_adap->algo_data; | 63 | struct cx231xx_i2c *bus = i2c_adap->algo_data; |
67 | struct cx231xx *dev = bus->dev; | 64 | struct cx231xx *dev = bus->dev; |
68 | struct cx231xx_i2c_xfer_data req_data; | 65 | struct cx231xx_i2c_xfer_data req_data; |
69 | int status = 0; | 66 | int status = 0; |
70 | u16 size = 0; | 67 | u16 size = 0; |
71 | u8 loop = 0; | 68 | u8 loop = 0; |
72 | u8 saddr_len = 1; | 69 | u8 saddr_len = 1; |
73 | u8 *buf_ptr = NULL; | 70 | u8 *buf_ptr = NULL; |
74 | u16 saddr = 0; | 71 | u16 saddr = 0; |
75 | u8 need_gpio = 0; | 72 | u8 need_gpio = 0; |
76 | 73 | ||
77 | 74 | if ((bus->nr == 1) && (msg->addr == 0x61) | |
78 | if( (bus->nr ==1) && (msg->addr == 0x61) && (dev->tuner_type == TUNER_XC5000) ) { | 75 | && (dev->tuner_type == TUNER_XC5000)) { |
79 | 76 | ||
80 | size = msg->len; | 77 | size = msg->len; |
81 | 78 | ||
82 | if( size == 2 ) { /* register write sub addr*/ | 79 | if (size == 2) { /* register write sub addr */ |
83 | 80 | ||
84 | /* Just writing sub address will cause problem to XC5000 | 81 | /* Just writing sub address will cause problem to XC5000 |
85 | So ignore the request */ | 82 | So ignore the request */ |
86 | return 0; | 83 | return 0; |
87 | 84 | ||
88 | } else if( size == 4 ) { /* register write with sub addr*/ | 85 | } else if (size == 4) { /* register write with sub addr */ |
89 | 86 | ||
90 | if(msg->len >= 2 ) | 87 | if (msg->len >= 2) |
91 | saddr = msg->buf[0] << 8 | msg->buf[1]; | 88 | saddr = msg->buf[0] << 8 | msg->buf[1]; |
92 | else if ( msg->len == 1 ) | 89 | else if (msg->len == 1) |
93 | saddr = msg->buf[0]; | 90 | saddr = msg->buf[0]; |
94 | 91 | ||
95 | switch(saddr) { | 92 | switch (saddr) { |
96 | case 0x0000: /* start tuner calibration mode */ | 93 | case 0x0000: /* start tuner calibration mode */ |
97 | need_gpio = 1; | 94 | need_gpio = 1; |
98 | dev->xc_fw_load_done = 1; /* FW Loading is done */ | 95 | dev->xc_fw_load_done = 1; /* FW Loading is done */ |
99 | break; | 96 | break; |
100 | case 0x000D: /* Set signal source */ | 97 | case 0x000D: /* Set signal source */ |
101 | case 0x0001: /* Set TV standard - Video */ | 98 | case 0x0001: /* Set TV standard - Video */ |
102 | case 0x0002: /* Set TV standard - Audio */ | 99 | case 0x0002: /* Set TV standard - Audio */ |
103 | case 0x0003: /* Set RF Frequency */ | 100 | case 0x0003: /* Set RF Frequency */ |
104 | need_gpio = 1; | 101 | need_gpio = 1; |
105 | break; | 102 | break; |
106 | default: | 103 | default: |
107 | if(dev->xc_fw_load_done) | 104 | if (dev->xc_fw_load_done) |
108 | need_gpio = 1; | 105 | need_gpio = 1; |
109 | break; | 106 | break; |
110 | } | 107 | } |
111 | 108 | ||
112 | if(need_gpio ) { | 109 | if (need_gpio) { |
113 | dprintk1(1, " GPIO W R I T E : addr 0x%x, len %d, saddr 0x%x\n", | 110 | dprintk1(1, |
114 | msg->addr, msg->len, saddr); | 111 | " GPIO W R I T E : addr 0x%x, len %d, saddr 0x%x\n", |
115 | 112 | msg->addr, msg->len, saddr); | |
116 | return dev->cx231xx_gpio_i2c_write(dev, msg->addr, msg->buf, msg->len); | 113 | |
117 | } | 114 | return dev->cx231xx_gpio_i2c_write(dev, |
118 | 115 | msg->addr, | |
119 | } | 116 | msg->buf, |
120 | 117 | msg->len); | |
121 | /* special case for Xc5000 tuner case */ | 118 | } |
122 | saddr_len = 1; | 119 | |
123 | 120 | } | |
124 | /* adjust the length to correct length */ | 121 | |
125 | size -= saddr_len; | 122 | /* special case for Xc5000 tuner case */ |
126 | buf_ptr = (u8*) (msg->buf + 1 ); | 123 | saddr_len = 1; |
127 | 124 | ||
128 | do { | 125 | /* adjust the length to correct length */ |
129 | /* prepare xfer_data struct */ | 126 | size -= saddr_len; |
130 | req_data.dev_addr = msg->addr; | 127 | buf_ptr = (u8 *) (msg->buf + 1); |
131 | req_data.direction = msg->flags; | 128 | |
132 | req_data.saddr_len = saddr_len; | 129 | do { |
133 | req_data.saddr_dat = msg->buf[0]; | 130 | /* prepare xfer_data struct */ |
134 | req_data.buf_size = size > 16 ? 16: size; | 131 | req_data.dev_addr = msg->addr; |
135 | req_data.p_buffer = (u8*)(buf_ptr + loop * 16); | 132 | req_data.direction = msg->flags; |
136 | 133 | req_data.saddr_len = saddr_len; | |
137 | bus->i2c_nostop = (size > 16) ? 1: 0; | 134 | req_data.saddr_dat = msg->buf[0]; |
138 | bus->i2c_reserve = (loop == 0) ? 0: 1; | 135 | req_data.buf_size = size > 16 ? 16 : size; |
139 | 136 | req_data.p_buffer = (u8 *) (buf_ptr + loop * 16); | |
140 | /* usb send command */ | 137 | |
141 | status = dev->cx231xx_send_usb_command(bus, &req_data); | 138 | bus->i2c_nostop = (size > 16) ? 1 : 0; |
142 | loop++; | 139 | bus->i2c_reserve = (loop == 0) ? 0 : 1; |
143 | 140 | ||
144 | if( size >= 16 ) | 141 | /* usb send command */ |
145 | size -= 16; | 142 | status = dev->cx231xx_send_usb_command(bus, &req_data); |
146 | else | 143 | loop++; |
147 | size = 0; | 144 | |
148 | 145 | if (size >= 16) | |
149 | }while( size > 0 ); | 146 | size -= 16; |
150 | 147 | else | |
151 | bus->i2c_nostop = 0; | 148 | size = 0; |
152 | bus->i2c_reserve = 0; | 149 | |
153 | 150 | } while (size > 0); | |
154 | } else { /* regular case */ | 151 | |
155 | 152 | bus->i2c_nostop = 0; | |
156 | /* prepare xfer_data struct */ | 153 | bus->i2c_reserve = 0; |
157 | req_data.dev_addr = msg->addr; | 154 | |
158 | req_data.direction = msg->flags; | 155 | } else { /* regular case */ |
159 | req_data.saddr_len = 0; | 156 | |
160 | req_data.saddr_dat = 0; | 157 | /* prepare xfer_data struct */ |
161 | req_data.buf_size = msg->len; | 158 | req_data.dev_addr = msg->addr; |
162 | req_data.p_buffer = msg->buf; | 159 | req_data.direction = msg->flags; |
163 | 160 | req_data.saddr_len = 0; | |
164 | /* usb send command */ | 161 | req_data.saddr_dat = 0; |
165 | status = dev->cx231xx_send_usb_command(bus, &req_data); | 162 | req_data.buf_size = msg->len; |
166 | } | 163 | req_data.p_buffer = msg->buf; |
167 | 164 | ||
168 | return status < 0 ? status: 0; | 165 | /* usb send command */ |
166 | status = dev->cx231xx_send_usb_command(bus, &req_data); | ||
167 | } | ||
168 | |||
169 | return status < 0 ? status : 0; | ||
169 | } | 170 | } |
170 | 171 | ||
171 | /* | 172 | /* |
@@ -173,75 +174,85 @@ int cx231xx_i2c_send_bytes(struct i2c_adapter *i2c_adap, | |||
173 | * read a byte from the i2c device | 174 | * read a byte from the i2c device |
174 | */ | 175 | */ |
175 | static int cx231xx_i2c_recv_bytes(struct i2c_adapter *i2c_adap, | 176 | static int cx231xx_i2c_recv_bytes(struct i2c_adapter *i2c_adap, |
176 | const struct i2c_msg *msg) | 177 | const struct i2c_msg *msg) |
177 | { | 178 | { |
178 | struct cx231xx_i2c *bus = i2c_adap->algo_data; | 179 | struct cx231xx_i2c *bus = i2c_adap->algo_data; |
179 | struct cx231xx *dev = bus->dev; | 180 | struct cx231xx *dev = bus->dev; |
180 | struct cx231xx_i2c_xfer_data req_data; | 181 | struct cx231xx_i2c_xfer_data req_data; |
181 | int status = 0; | 182 | int status = 0; |
182 | u16 saddr = 0; | 183 | u16 saddr = 0; |
183 | u8 need_gpio = 0; | 184 | u8 need_gpio = 0; |
184 | 185 | ||
185 | if((bus->nr ==1) && (msg->addr == 0x61) && dev->tuner_type == TUNER_XC5000) { | 186 | if ((bus->nr == 1) && (msg->addr == 0x61) |
186 | 187 | && dev->tuner_type == TUNER_XC5000) { | |
187 | if(msg->len == 2 ) | 188 | |
188 | saddr = msg->buf[0] << 8 | msg->buf[1]; | 189 | if (msg->len == 2) |
189 | else if ( msg->len == 1 ) | 190 | saddr = msg->buf[0] << 8 | msg->buf[1]; |
190 | saddr = msg->buf[0]; | 191 | else if (msg->len == 1) |
191 | 192 | saddr = msg->buf[0]; | |
192 | if( dev->xc_fw_load_done) { | 193 | |
193 | 194 | if (dev->xc_fw_load_done) { | |
194 | switch(saddr) { | 195 | |
195 | case 0x0009: /* BUSY check */ | 196 | switch (saddr) { |
196 | dprintk1(1, " GPIO R E A D : Special case BUSY check \n"); | 197 | case 0x0009: /* BUSY check */ |
197 | /* Try to read BUSY register, just set it to zero */ | 198 | dprintk1(1, |
198 | msg->buf[0] = 0; | 199 | " GPIO R E A D : Special case BUSY check \n"); |
199 | if(msg->len == 2 ) | 200 | /* Try to read BUSY register, just set it to zero */ |
200 | msg->buf[1] = 0; | 201 | msg->buf[0] = 0; |
201 | return 0; | 202 | if (msg->len == 2) |
202 | case 0x0004: /* read Lock status */ | 203 | msg->buf[1] = 0; |
203 | need_gpio = 1; | 204 | return 0; |
204 | break; | 205 | case 0x0004: /* read Lock status */ |
205 | 206 | need_gpio = 1; | |
206 | } | 207 | break; |
207 | 208 | ||
208 | if(need_gpio) { | 209 | } |
209 | /* this is a special case to handle Xceive tuner clock stretch issue | 210 | |
210 | with gpio based I2C interface */ | 211 | if (need_gpio) { |
211 | dprintk1(1, " GPIO R E A D : addr 0x%x, len %d, saddr 0x%x\n", | 212 | /* this is a special case to handle Xceive tuner clock stretch issue |
212 | msg->addr, msg->len, msg->buf[0] << 8| msg->buf[1]); | 213 | with gpio based I2C interface */ |
213 | status = dev->cx231xx_gpio_i2c_write(dev, msg->addr, msg->buf, msg->len); | 214 | dprintk1(1, |
214 | status = dev->cx231xx_gpio_i2c_read(dev, msg->addr, msg->buf, msg->len); | 215 | " GPIO R E A D : addr 0x%x, len %d, saddr 0x%x\n", |
215 | return status; | 216 | msg->addr, msg->len, |
216 | } | 217 | msg->buf[0] << 8 | msg->buf[1]); |
217 | } | 218 | status = |
218 | 219 | dev->cx231xx_gpio_i2c_write(dev, msg->addr, | |
219 | /* prepare xfer_data struct */ | 220 | msg->buf, |
220 | req_data.dev_addr = msg->addr; | 221 | msg->len); |
221 | req_data.direction = msg->flags; | 222 | status = |
222 | req_data.saddr_len = msg->len; | 223 | dev->cx231xx_gpio_i2c_read(dev, msg->addr, |
223 | req_data.saddr_dat = msg->buf[0] << 8 | msg->buf[1]; | 224 | msg->buf, |
224 | req_data.buf_size = msg->len; | 225 | msg->len); |
225 | req_data.p_buffer = msg->buf; | 226 | return status; |
226 | 227 | } | |
227 | /* usb send command */ | 228 | } |
228 | status = dev->cx231xx_send_usb_command(bus, &req_data); | 229 | |
229 | 230 | /* prepare xfer_data struct */ | |
230 | } else { | 231 | req_data.dev_addr = msg->addr; |
231 | 232 | req_data.direction = msg->flags; | |
232 | /* prepare xfer_data struct */ | 233 | req_data.saddr_len = msg->len; |
233 | req_data.dev_addr = msg->addr; | 234 | req_data.saddr_dat = msg->buf[0] << 8 | msg->buf[1]; |
234 | req_data.direction = msg->flags; | 235 | req_data.buf_size = msg->len; |
235 | req_data.saddr_len = 0; | 236 | req_data.p_buffer = msg->buf; |
236 | req_data.saddr_dat = 0; | 237 | |
237 | req_data.buf_size = msg->len; | 238 | /* usb send command */ |
238 | req_data.p_buffer = msg->buf; | 239 | status = dev->cx231xx_send_usb_command(bus, &req_data); |
239 | 240 | ||
240 | /* usb send command */ | 241 | } else { |
241 | status = dev->cx231xx_send_usb_command(bus, &req_data); | 242 | |
242 | } | 243 | /* prepare xfer_data struct */ |
243 | 244 | req_data.dev_addr = msg->addr; | |
244 | return status < 0 ? status: 0; | 245 | req_data.direction = msg->flags; |
246 | req_data.saddr_len = 0; | ||
247 | req_data.saddr_dat = 0; | ||
248 | req_data.buf_size = msg->len; | ||
249 | req_data.p_buffer = msg->buf; | ||
250 | |||
251 | /* usb send command */ | ||
252 | status = dev->cx231xx_send_usb_command(bus, &req_data); | ||
253 | } | ||
254 | |||
255 | return status < 0 ? status : 0; | ||
245 | } | 256 | } |
246 | 257 | ||
247 | /* | 258 | /* |
@@ -249,56 +260,65 @@ static int cx231xx_i2c_recv_bytes(struct i2c_adapter *i2c_adap, | |||
249 | * read a byte from the i2c device | 260 | * read a byte from the i2c device |
250 | */ | 261 | */ |
251 | static int cx231xx_i2c_recv_bytes_with_saddr(struct i2c_adapter *i2c_adap, | 262 | static int cx231xx_i2c_recv_bytes_with_saddr(struct i2c_adapter *i2c_adap, |
252 | const struct i2c_msg *msg1, const struct i2c_msg *msg2) | 263 | const struct i2c_msg *msg1, |
264 | const struct i2c_msg *msg2) | ||
253 | { | 265 | { |
254 | struct cx231xx_i2c *bus = i2c_adap->algo_data; | 266 | struct cx231xx_i2c *bus = i2c_adap->algo_data; |
255 | struct cx231xx *dev = bus->dev; | 267 | struct cx231xx *dev = bus->dev; |
256 | struct cx231xx_i2c_xfer_data req_data; | 268 | struct cx231xx_i2c_xfer_data req_data; |
257 | int status = 0; | 269 | int status = 0; |
258 | u16 saddr = 0; | 270 | u16 saddr = 0; |
259 | u8 need_gpio = 0; | 271 | u8 need_gpio = 0; |
260 | 272 | ||
261 | if(msg1->len == 2 ) | 273 | if (msg1->len == 2) |
262 | saddr = msg1->buf[0] << 8 | msg1->buf[1]; | 274 | saddr = msg1->buf[0] << 8 | msg1->buf[1]; |
263 | else if ( msg1->len == 1 ) | 275 | else if (msg1->len == 1) |
264 | saddr = msg1->buf[0]; | 276 | saddr = msg1->buf[0]; |
265 | 277 | ||
266 | if ( (bus->nr ==1) && (msg2->addr == 0x61) && dev->tuner_type == TUNER_XC5000) { | 278 | if ((bus->nr == 1) && (msg2->addr == 0x61) |
267 | 279 | && dev->tuner_type == TUNER_XC5000) { | |
268 | if( (msg2->len < 16) ) { | 280 | |
269 | 281 | if ((msg2->len < 16)) { | |
270 | dprintk1(1, " i2c_read : addr 0x%x, len %d, subaddr 0x%x, leng %d\n", | 282 | |
271 | msg2->addr, msg2->len, saddr, msg1->len); | 283 | dprintk1(1, |
272 | 284 | " i2c_read : addr 0x%x, len %d, subaddr 0x%x, leng %d\n", | |
273 | switch(saddr) { | 285 | msg2->addr, msg2->len, saddr, msg1->len); |
274 | case 0x0008: /* read FW load status */ | 286 | |
275 | need_gpio = 1; | 287 | switch (saddr) { |
276 | break; | 288 | case 0x0008: /* read FW load status */ |
277 | case 0x0004: /* read Lock status */ | 289 | need_gpio = 1; |
278 | need_gpio = 1; | 290 | break; |
279 | break; | 291 | case 0x0004: /* read Lock status */ |
280 | } | 292 | need_gpio = 1; |
281 | 293 | break; | |
282 | if(need_gpio ) { | 294 | } |
283 | status = dev->cx231xx_gpio_i2c_write(dev, msg1->addr, msg1->buf, msg1->len); | 295 | |
284 | status = dev->cx231xx_gpio_i2c_read(dev, msg2->addr, msg2->buf, msg2->len); | 296 | if (need_gpio) { |
285 | return status; | 297 | status = |
286 | } | 298 | dev->cx231xx_gpio_i2c_write(dev, msg1->addr, |
287 | } | 299 | msg1->buf, |
288 | } | 300 | msg1->len); |
289 | 301 | status = | |
290 | /* prepare xfer_data struct */ | 302 | dev->cx231xx_gpio_i2c_read(dev, msg2->addr, |
291 | req_data.dev_addr = msg2->addr; | 303 | msg2->buf, |
292 | req_data.direction = msg2->flags; | 304 | msg2->len); |
293 | req_data.saddr_len = msg1->len; | 305 | return status; |
294 | req_data.saddr_dat = saddr; | 306 | } |
295 | req_data.buf_size = msg2->len; | 307 | } |
296 | req_data.p_buffer = msg2->buf; | 308 | } |
297 | 309 | ||
298 | /* usb send command */ | 310 | /* prepare xfer_data struct */ |
299 | status = dev->cx231xx_send_usb_command(bus, &req_data); | 311 | req_data.dev_addr = msg2->addr; |
300 | 312 | req_data.direction = msg2->flags; | |
301 | return status < 0 ? status: 0; | 313 | req_data.saddr_len = msg1->len; |
314 | req_data.saddr_dat = saddr; | ||
315 | req_data.buf_size = msg2->len; | ||
316 | req_data.p_buffer = msg2->buf; | ||
317 | |||
318 | /* usb send command */ | ||
319 | status = dev->cx231xx_send_usb_command(bus, &req_data); | ||
320 | |||
321 | return status < 0 ? status : 0; | ||
302 | } | 322 | } |
303 | 323 | ||
304 | /* | 324 | /* |
@@ -306,25 +326,25 @@ static int cx231xx_i2c_recv_bytes_with_saddr(struct i2c_adapter *i2c_adap, | |||
306 | * check if there is a i2c_device at the supplied address | 326 | * check if there is a i2c_device at the supplied address |
307 | */ | 327 | */ |
308 | static int cx231xx_i2c_check_for_device(struct i2c_adapter *i2c_adap, | 328 | static int cx231xx_i2c_check_for_device(struct i2c_adapter *i2c_adap, |
309 | const struct i2c_msg *msg) | 329 | const struct i2c_msg *msg) |
310 | { | 330 | { |
311 | struct cx231xx_i2c *bus = i2c_adap->algo_data; | 331 | struct cx231xx_i2c *bus = i2c_adap->algo_data; |
312 | struct cx231xx *dev = bus->dev; | 332 | struct cx231xx *dev = bus->dev; |
313 | struct cx231xx_i2c_xfer_data req_data; | 333 | struct cx231xx_i2c_xfer_data req_data; |
314 | int status = 0; | 334 | int status = 0; |
315 | 335 | ||
316 | /* prepare xfer_data struct */ | 336 | /* prepare xfer_data struct */ |
317 | req_data.dev_addr = msg->addr; | 337 | req_data.dev_addr = msg->addr; |
318 | req_data.direction = msg->flags; | 338 | req_data.direction = msg->flags; |
319 | req_data.saddr_len = 0; | 339 | req_data.saddr_len = 0; |
320 | req_data.saddr_dat = 0; | 340 | req_data.saddr_dat = 0; |
321 | req_data.buf_size = 0; | 341 | req_data.buf_size = 0; |
322 | req_data.p_buffer = NULL; | 342 | req_data.p_buffer = NULL; |
323 | 343 | ||
324 | /* usb send command */ | 344 | /* usb send command */ |
325 | status = dev->cx231xx_send_usb_command(bus, &req_data); | 345 | status = dev->cx231xx_send_usb_command(bus, &req_data); |
326 | 346 | ||
327 | return status < 0 ? status: 0; | 347 | return status < 0 ? status : 0; |
328 | } | 348 | } |
329 | 349 | ||
330 | /* | 350 | /* |
@@ -332,7 +352,7 @@ static int cx231xx_i2c_check_for_device(struct i2c_adapter *i2c_adap, | |||
332 | * the main i2c transfer function | 352 | * the main i2c transfer function |
333 | */ | 353 | */ |
334 | static int cx231xx_i2c_xfer(struct i2c_adapter *i2c_adap, | 354 | static int cx231xx_i2c_xfer(struct i2c_adapter *i2c_adap, |
335 | struct i2c_msg msgs[], int num) | 355 | struct i2c_msg msgs[], int num) |
336 | { | 356 | { |
337 | struct cx231xx_i2c *bus = i2c_adap->algo_data; | 357 | struct cx231xx_i2c *bus = i2c_adap->algo_data; |
338 | struct cx231xx *dev = bus->dev; | 358 | struct cx231xx *dev = bus->dev; |
@@ -348,7 +368,7 @@ static int cx231xx_i2c_xfer(struct i2c_adapter *i2c_adap, | |||
348 | dprintk2(2, "%s %s addr=%x len=%d:", | 368 | dprintk2(2, "%s %s addr=%x len=%d:", |
349 | (msgs[i].flags & I2C_M_RD) ? "read" : "write", | 369 | (msgs[i].flags & I2C_M_RD) ? "read" : "write", |
350 | i == num - 1 ? "stop" : "nonstop", addr, msgs[i].len); | 370 | i == num - 1 ? "stop" : "nonstop", addr, msgs[i].len); |
351 | if (!msgs[i].len) { /* no len: check only for device presence */ | 371 | if (!msgs[i].len) { /* no len: check only for device presence */ |
352 | rc = cx231xx_i2c_check_for_device(i2c_adap, &msgs[i]); | 372 | rc = cx231xx_i2c_check_for_device(i2c_adap, &msgs[i]); |
353 | if (rc < 0) { | 373 | if (rc < 0) { |
354 | dprintk2(2, " no device\n"); | 374 | dprintk2(2, " no device\n"); |
@@ -363,21 +383,24 @@ static int cx231xx_i2c_xfer(struct i2c_adapter *i2c_adap, | |||
363 | printk(" %02x", msgs[i].buf[byte]); | 383 | printk(" %02x", msgs[i].buf[byte]); |
364 | } | 384 | } |
365 | } else if (i + 1 < num && (msgs[i + 1].flags & I2C_M_RD) && | 385 | } else if (i + 1 < num && (msgs[i + 1].flags & I2C_M_RD) && |
366 | msgs[i].addr == msgs[i + 1].addr && (msgs[i].len <= 2) && (bus->nr < 2)) { | 386 | msgs[i].addr == msgs[i + 1].addr |
387 | && (msgs[i].len <= 2) && (bus->nr < 2)) { | ||
367 | /* read bytes */ | 388 | /* read bytes */ |
368 | rc = cx231xx_i2c_recv_bytes_with_saddr(i2c_adap, &msgs[i], &msgs[i+1]); | 389 | rc = cx231xx_i2c_recv_bytes_with_saddr(i2c_adap, |
390 | &msgs[i], | ||
391 | &msgs[i + 1]); | ||
369 | if (i2c_debug >= 2) { | 392 | if (i2c_debug >= 2) { |
370 | for (byte = 0; byte < msgs[i].len; byte++) | 393 | for (byte = 0; byte < msgs[i].len; byte++) |
371 | printk(" %02x", msgs[i].buf[byte]); | 394 | printk(" %02x", msgs[i].buf[byte]); |
372 | } | 395 | } |
373 | i++; | 396 | i++; |
374 | } else { | 397 | } else { |
375 | /* write bytes */ | 398 | /* write bytes */ |
376 | if (i2c_debug >= 2) { | 399 | if (i2c_debug >= 2) { |
377 | for (byte = 0; byte < msgs[i].len; byte++) | 400 | for (byte = 0; byte < msgs[i].len; byte++) |
378 | printk(" %02x", msgs[i].buf[byte]); | 401 | printk(" %02x", msgs[i].buf[byte]); |
379 | } | 402 | } |
380 | rc = cx231xx_i2c_send_bytes(i2c_adap,&msgs[i]); | 403 | rc = cx231xx_i2c_send_bytes(i2c_adap, &msgs[i]); |
381 | } | 404 | } |
382 | if (rc < 0) | 405 | if (rc < 0) |
383 | goto err; | 406 | goto err; |
@@ -386,7 +409,7 @@ static int cx231xx_i2c_xfer(struct i2c_adapter *i2c_adap, | |||
386 | } | 409 | } |
387 | 410 | ||
388 | return num; | 411 | return num; |
389 | err: | 412 | err: |
390 | dprintk2(2, " ERROR: %i\n", rc); | 413 | dprintk2(2, " ERROR: %i\n", rc); |
391 | return rc; | 414 | return rc; |
392 | } | 415 | } |
@@ -408,7 +431,7 @@ static u32 functionality(struct i2c_adapter *adap) | |||
408 | */ | 431 | */ |
409 | static int attach_inform(struct i2c_client *client) | 432 | static int attach_inform(struct i2c_client *client) |
410 | { | 433 | { |
411 | struct cx231xx_i2c *bus = i2c_get_adapdata(client->adapter); | 434 | struct cx231xx_i2c *bus = i2c_get_adapdata(client->adapter); |
412 | struct cx231xx *dev = bus->dev; | 435 | struct cx231xx *dev = bus->dev; |
413 | 436 | ||
414 | switch (client->addr << 1) { | 437 | switch (client->addr << 1) { |
@@ -422,16 +445,16 @@ static int attach_inform(struct i2c_client *client) | |||
422 | dprintk1(1, "attach_inform: eeprom detected.\n"); | 445 | dprintk1(1, "attach_inform: eeprom detected.\n"); |
423 | break; | 446 | break; |
424 | case 0x60: | 447 | case 0x60: |
425 | dprintk1(1, "attach_inform: Colibri detected.\n"); | 448 | dprintk1(1, "attach_inform: Colibri detected.\n"); |
426 | break; | ||
427 | case 0x8e: | ||
428 | { | ||
429 | struct IR_i2c *ir = i2c_get_clientdata(client); | ||
430 | dprintk1(1, "attach_inform: IR detected (%s).\n", | ||
431 | ir->phys); | ||
432 | cx231xx_set_ir(dev, ir); | ||
433 | break; | 449 | break; |
434 | } | 450 | case 0x8e: |
451 | { | ||
452 | struct IR_i2c *ir = i2c_get_clientdata(client); | ||
453 | dprintk1(1, "attach_inform: IR detected (%s).\n", | ||
454 | ir->phys); | ||
455 | cx231xx_set_ir(dev, ir); | ||
456 | break; | ||
457 | } | ||
435 | case 0x80: | 458 | case 0x80: |
436 | case 0x88: | 459 | case 0x88: |
437 | dprintk1(1, "attach_inform: Hammerhead detected.\n"); | 460 | dprintk1(1, "attach_inform: Hammerhead detected.\n"); |
@@ -442,7 +465,7 @@ static int attach_inform(struct i2c_client *client) | |||
442 | dev->tuner_addr = client->addr; | 465 | dev->tuner_addr = client->addr; |
443 | 466 | ||
444 | dprintk1(1, "attach inform: detected I2C address %x\n", | 467 | dprintk1(1, "attach inform: detected I2C address %x\n", |
445 | client->addr << 1); | 468 | client->addr << 1); |
446 | } | 469 | } |
447 | 470 | ||
448 | return 0; | 471 | return 0; |
@@ -454,9 +477,8 @@ static int detach_inform(struct i2c_client *client) | |||
454 | return 0; | 477 | return 0; |
455 | } | 478 | } |
456 | 479 | ||
457 | |||
458 | static struct i2c_algorithm cx231xx_algo = { | 480 | static struct i2c_algorithm cx231xx_algo = { |
459 | .master_xfer = cx231xx_i2c_xfer, | 481 | .master_xfer = cx231xx_i2c_xfer, |
460 | .functionality = functionality, | 482 | .functionality = functionality, |
461 | }; | 483 | }; |
462 | 484 | ||
@@ -466,7 +488,7 @@ static struct i2c_adapter cx231xx_adap_template = { | |||
466 | .name = "cx231xx", | 488 | .name = "cx231xx", |
467 | .id = I2C_HW_B_CX231XX, | 489 | .id = I2C_HW_B_CX231XX, |
468 | .algo = &cx231xx_algo, | 490 | .algo = &cx231xx_algo, |
469 | .client_register = attach_inform, | 491 | .client_register = attach_inform, |
470 | .client_unregister = detach_inform, | 492 | .client_unregister = detach_inform, |
471 | }; | 493 | }; |
472 | 494 | ||
@@ -483,9 +505,9 @@ static struct i2c_client cx231xx_client_template = { | |||
483 | static char *i2c_devs[128] = { | 505 | static char *i2c_devs[128] = { |
484 | [0x60 >> 1] = "colibri", | 506 | [0x60 >> 1] = "colibri", |
485 | [0x88 >> 1] = "hammerhead", | 507 | [0x88 >> 1] = "hammerhead", |
486 | [0x8e >> 1] = "CIR", | 508 | [0x8e >> 1] = "CIR", |
487 | [0x32 >> 1] = "GeminiIII", | 509 | [0x32 >> 1] = "GeminiIII", |
488 | [0x02 >> 1] = "Aquarius", | 510 | [0x02 >> 1] = "Aquarius", |
489 | [0xa0 >> 1] = "eeprom", | 511 | [0xa0 >> 1] = "eeprom", |
490 | [0xc0 >> 1] = "tuner/XC3028", | 512 | [0xc0 >> 1] = "tuner/XC3028", |
491 | [0xc2 >> 1] = "tuner/XC5000", | 513 | [0xc2 >> 1] = "tuner/XC5000", |
@@ -500,23 +522,25 @@ void cx231xx_do_i2c_scan(struct cx231xx *dev, struct i2c_client *c) | |||
500 | unsigned char buf; | 522 | unsigned char buf; |
501 | int i, rc; | 523 | int i, rc; |
502 | 524 | ||
503 | cx231xx_info(": Checking for I2C devices ..\n"); | 525 | cx231xx_info(": Checking for I2C devices ..\n"); |
504 | for (i = 0; i < 128; i++) { | 526 | for (i = 0; i < 128; i++) { |
505 | c->addr = i; | 527 | c->addr = i; |
506 | rc = i2c_master_recv(c, &buf, 0); | 528 | rc = i2c_master_recv(c, &buf, 0); |
507 | if (rc < 0) | 529 | if (rc < 0) |
508 | continue; | 530 | continue; |
509 | cx231xx_info("%s: i2c scan: found device @ 0x%x [%s]\n", | 531 | cx231xx_info("%s: i2c scan: found device @ 0x%x [%s]\n", |
510 | dev->name, i << 1, i2c_devs[i] ? i2c_devs[i] : "???"); | 532 | dev->name, i << 1, |
533 | i2c_devs[i] ? i2c_devs[i] : "???"); | ||
511 | } | 534 | } |
512 | cx231xx_info(": Completed Checking for I2C devices.\n"); | 535 | cx231xx_info(": Completed Checking for I2C devices.\n"); |
513 | } | 536 | } |
514 | 537 | ||
515 | /* | 538 | /* |
516 | * cx231xx_i2c_call_clients() | 539 | * cx231xx_i2c_call_clients() |
517 | * send commands to all attached i2c devices | 540 | * send commands to all attached i2c devices |
518 | */ | 541 | */ |
519 | void cx231xx_i2c_call_clients(struct cx231xx_i2c *bus, unsigned int cmd, void *arg) | 542 | void cx231xx_i2c_call_clients(struct cx231xx_i2c *bus, unsigned int cmd, |
543 | void *arg) | ||
520 | { | 544 | { |
521 | /* struct cx231xx *dev = bus->dev; */ | 545 | /* struct cx231xx *dev = bus->dev; */ |
522 | 546 | ||
@@ -530,23 +554,20 @@ void cx231xx_i2c_call_clients(struct cx231xx_i2c *bus, unsigned int cmd, void *a | |||
530 | */ | 554 | */ |
531 | int cx231xx_i2c_register(struct cx231xx_i2c *bus) | 555 | int cx231xx_i2c_register(struct cx231xx_i2c *bus) |
532 | { | 556 | { |
533 | struct cx231xx *dev = bus->dev; | 557 | struct cx231xx *dev = bus->dev; |
534 | 558 | ||
535 | BUG_ON(!dev->cx231xx_send_usb_command); | 559 | BUG_ON(!dev->cx231xx_send_usb_command); |
536 | 560 | ||
537 | cx231xx_info("%s(bus = %d)\n", __func__, bus->nr); | 561 | cx231xx_info("%s(bus = %d)\n", __func__, bus->nr); |
538 | 562 | ||
539 | memcpy(&bus->i2c_adap, &cx231xx_adap_template, | 563 | memcpy(&bus->i2c_adap, &cx231xx_adap_template, sizeof(bus->i2c_adap)); |
540 | sizeof(bus->i2c_adap)); | 564 | memcpy(&bus->i2c_algo, &cx231xx_algo, sizeof(bus->i2c_algo)); |
541 | memcpy(&bus->i2c_algo, &cx231xx_algo, | ||
542 | sizeof(bus->i2c_algo)); | ||
543 | memcpy(&bus->i2c_client, &cx231xx_client_template, | 565 | memcpy(&bus->i2c_client, &cx231xx_client_template, |
544 | sizeof(bus->i2c_client)); | 566 | sizeof(bus->i2c_client)); |
545 | 567 | ||
546 | bus->i2c_adap.dev.parent = &dev->udev->dev; | 568 | bus->i2c_adap.dev.parent = &dev->udev->dev; |
547 | 569 | ||
548 | strlcpy(bus->i2c_adap.name, bus->dev->name, | 570 | strlcpy(bus->i2c_adap.name, bus->dev->name, sizeof(bus->i2c_adap.name)); |
549 | sizeof(bus->i2c_adap.name)); | ||
550 | 571 | ||
551 | bus->i2c_algo.data = bus; | 572 | bus->i2c_algo.data = bus; |
552 | bus->i2c_adap.algo_data = bus; | 573 | bus->i2c_adap.algo_data = bus; |
@@ -561,7 +582,7 @@ int cx231xx_i2c_register(struct cx231xx_i2c *bus) | |||
561 | cx231xx_do_i2c_scan(dev, &bus->i2c_client); | 582 | cx231xx_do_i2c_scan(dev, &bus->i2c_client); |
562 | } else | 583 | } else |
563 | cx231xx_warn("%s: i2c bus %d register FAILED\n", | 584 | cx231xx_warn("%s: i2c bus %d register FAILED\n", |
564 | dev->name, bus->nr); | 585 | dev->name, bus->nr); |
565 | 586 | ||
566 | return bus->i2c_rc; | 587 | return bus->i2c_rc; |
567 | } | 588 | } |