Diff markup
1 /* 1 /*
2 2
3 bttv-i2c.c -- all the i2c code is here 3 bttv-i2c.c -- all the i2c code is here
4 4
5 bttv - Bt848 frame grabber driver 5 bttv - Bt848 frame grabber driver
6 6
7 Copyright (C) 1996,97,98 Ralph Metzler (r 7 Copyright (C) 1996,97,98 Ralph Metzler (rjkm@thp.uni-koeln.de)
8 & Marcus Metzler (m 8 & Marcus Metzler (mocm@thp.uni-koeln.de)
9 (c) 1999-2003 Gerd Knorr <kraxel@bytesex.o 9 (c) 1999-2003 Gerd Knorr <kraxel@bytesex.org>
10 10
11 (c) 2005 Mauro Carvalho Chehab <mchehab@in 11 (c) 2005 Mauro Carvalho Chehab <mchehab@infradead.org>
12 - Multituner support and i2c address b 12 - Multituner support and i2c address binding
13 13
14 This program is free software; you can red 14 This program is free software; you can redistribute it and/or modify
15 it under the terms of the GNU General Publ 15 it under the terms of the GNU General Public License as published by
16 the Free Software Foundation; either versi 16 the Free Software Foundation; either version 2 of the License, or
17 (at your option) any later version. 17 (at your option) any later version.
18 18
19 This program is distributed in the hope th 19 This program is distributed in the hope that it will be useful,
20 but WITHOUT ANY WARRANTY; without even the 20 but WITHOUT ANY WARRANTY; without even the implied warranty of
21 MERCHANTABILITY or FITNESS FOR A PARTICULA 21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 GNU General Public License for more detail 22 GNU General Public License for more details.
23 23
24 You should have received a copy of the GNU 24 You should have received a copy of the GNU General Public License
25 along with this program; if not, write to 25 along with this program; if not, write to the Free Software
26 Foundation, Inc., 675 Mass Ave, Cambridge, 26 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
27 27
28 */ 28 */
29 29
30 #include <linux/module.h> 30 #include <linux/module.h>
31 #include <linux/init.h> 31 #include <linux/init.h>
32 #include <linux/delay.h> 32 #include <linux/delay.h>
33 33
34 #include "bttvp.h" 34 #include "bttvp.h"
35 #include <media/v4l2-common.h> 35 #include <media/v4l2-common.h>
36 #include <linux/jiffies.h> 36 #include <linux/jiffies.h>
37 #include <asm/io.h> 37 #include <asm/io.h>
38 38
39 static struct i2c_algo_bit_data bttv_i2c_algo_ <<
40 static struct i2c_adapter bttv_i2c_adap_sw_tem <<
41 static struct i2c_adapter bttv_i2c_adap_hw_tem <<
42 static struct i2c_client bttv_i2c_client_templ <<
43 <<
44 static int attach_inform(struct i2c_client *cl <<
45 <<
46 static int i2c_debug; 39 static int i2c_debug;
47 static int i2c_hw; 40 static int i2c_hw;
48 static int i2c_scan; 41 static int i2c_scan;
49 module_param(i2c_debug, int, 0644); 42 module_param(i2c_debug, int, 0644);
50 MODULE_PARM_DESC(i2c_hw,"configure i2c debug l 43 MODULE_PARM_DESC(i2c_hw,"configure i2c debug level");
51 module_param(i2c_hw, int, 0444); 44 module_param(i2c_hw, int, 0444);
52 MODULE_PARM_DESC(i2c_hw,"force use of hardware 45 MODULE_PARM_DESC(i2c_hw,"force use of hardware i2c support, "
53 "instead of software b 46 "instead of software bitbang");
54 module_param(i2c_scan, int, 0444); 47 module_param(i2c_scan, int, 0444);
55 MODULE_PARM_DESC(i2c_scan,"scan i2c bus at ins 48 MODULE_PARM_DESC(i2c_scan,"scan i2c bus at insmod time");
56 49
57 static unsigned int i2c_udelay = 5; 50 static unsigned int i2c_udelay = 5;
58 module_param(i2c_udelay, int, 0444); 51 module_param(i2c_udelay, int, 0444);
59 MODULE_PARM_DESC(i2c_udelay,"soft i2c delay at 52 MODULE_PARM_DESC(i2c_udelay,"soft i2c delay at insmod time, in usecs "
60 "(should be 5 or higher). Lowe 53 "(should be 5 or higher). Lower value means higher bus speed.");
61 54
62 /* ------------------------------------------- 55 /* ----------------------------------------------------------------------- */
63 /* I2C functions - bitbanging adapter (softwar 56 /* I2C functions - bitbanging adapter (software i2c) */
64 57
65 static void bttv_bit_setscl(void *data, int st 58 static void bttv_bit_setscl(void *data, int state)
66 { 59 {
67 struct bttv *btv = (struct bttv*)data; 60 struct bttv *btv = (struct bttv*)data;
68 61
69 if (state) 62 if (state)
70 btv->i2c_state |= 0x02; 63 btv->i2c_state |= 0x02;
71 else 64 else
72 btv->i2c_state &= ~0x02; 65 btv->i2c_state &= ~0x02;
73 btwrite(btv->i2c_state, BT848_I2C); 66 btwrite(btv->i2c_state, BT848_I2C);
74 btread(BT848_I2C); 67 btread(BT848_I2C);
75 } 68 }
76 69
77 static void bttv_bit_setsda(void *data, int st 70 static void bttv_bit_setsda(void *data, int state)
78 { 71 {
79 struct bttv *btv = (struct bttv*)data; 72 struct bttv *btv = (struct bttv*)data;
80 73
81 if (state) 74 if (state)
82 btv->i2c_state |= 0x01; 75 btv->i2c_state |= 0x01;
83 else 76 else
84 btv->i2c_state &= ~0x01; 77 btv->i2c_state &= ~0x01;
85 btwrite(btv->i2c_state, BT848_I2C); 78 btwrite(btv->i2c_state, BT848_I2C);
86 btread(BT848_I2C); 79 btread(BT848_I2C);
87 } 80 }
88 81
89 static int bttv_bit_getscl(void *data) 82 static int bttv_bit_getscl(void *data)
90 { 83 {
91 struct bttv *btv = (struct bttv*)data; 84 struct bttv *btv = (struct bttv*)data;
92 int state; 85 int state;
93 86
94 state = btread(BT848_I2C) & 0x02 ? 1 : 87 state = btread(BT848_I2C) & 0x02 ? 1 : 0;
95 return state; 88 return state;
96 } 89 }
97 90
98 static int bttv_bit_getsda(void *data) 91 static int bttv_bit_getsda(void *data)
99 { 92 {
100 struct bttv *btv = (struct bttv*)data; 93 struct bttv *btv = (struct bttv*)data;
101 int state; 94 int state;
102 95
103 state = btread(BT848_I2C) & 0x01; 96 state = btread(BT848_I2C) & 0x01;
104 return state; 97 return state;
105 } 98 }
106 99
107 static struct i2c_algo_bit_data bttv_i2c_algo_ !! 100 static struct i2c_algo_bit_data __devinitdata bttv_i2c_algo_bit_template = {
108 .setsda = bttv_bit_setsda, 101 .setsda = bttv_bit_setsda,
109 .setscl = bttv_bit_setscl, 102 .setscl = bttv_bit_setscl,
110 .getsda = bttv_bit_getsda, 103 .getsda = bttv_bit_getsda,
111 .getscl = bttv_bit_getscl, 104 .getscl = bttv_bit_getscl,
112 .udelay = 16, 105 .udelay = 16,
113 .timeout = 200, 106 .timeout = 200,
114 }; 107 };
115 108
116 static struct i2c_adapter bttv_i2c_adap_sw_tem <<
117 .owner = THIS_MODULE, <<
118 .class = I2C_CLASS_TV_ANAL <<
119 .name = "bttv", <<
120 .id = I2C_HW_B_BT848, <<
121 .client_register = attach_inform, <<
122 }; <<
123 <<
124 /* ------------------------------------------- 109 /* ----------------------------------------------------------------------- */
125 /* I2C functions - hardware i2c 110 /* I2C functions - hardware i2c */
126 111
127 static u32 functionality(struct i2c_adapter *a 112 static u32 functionality(struct i2c_adapter *adap)
128 { 113 {
129 return I2C_FUNC_SMBUS_EMUL; 114 return I2C_FUNC_SMBUS_EMUL;
130 } 115 }
131 116
132 static int 117 static int
133 bttv_i2c_wait_done(struct bttv *btv) 118 bttv_i2c_wait_done(struct bttv *btv)
134 { 119 {
135 int rc = 0; 120 int rc = 0;
136 121
137 /* timeout */ 122 /* timeout */
138 if (wait_event_interruptible_timeout(b 123 if (wait_event_interruptible_timeout(btv->i2c_queue,
139 btv->i2c_done, msecs_to_jiffie 124 btv->i2c_done, msecs_to_jiffies(85)) == -ERESTARTSYS)
140 125
141 rc = -EIO; 126 rc = -EIO;
142 127
143 if (btv->i2c_done & BT848_INT_RACK) 128 if (btv->i2c_done & BT848_INT_RACK)
144 rc = 1; 129 rc = 1;
145 btv->i2c_done = 0; 130 btv->i2c_done = 0;
146 return rc; 131 return rc;
147 } 132 }
148 133
149 #define I2C_HW (BT878_I2C_MODE | BT848_I2C_SY 134 #define I2C_HW (BT878_I2C_MODE | BT848_I2C_SYNC |\
150 BT848_I2C_SCL | BT848_I2C_SDA) 135 BT848_I2C_SCL | BT848_I2C_SDA)
151 136
152 static int 137 static int
153 bttv_i2c_sendbytes(struct bttv *btv, const str 138 bttv_i2c_sendbytes(struct bttv *btv, const struct i2c_msg *msg, int last)
154 { 139 {
155 u32 xmit; 140 u32 xmit;
156 int retval,cnt; 141 int retval,cnt;
157 142
158 /* sanity checks */ 143 /* sanity checks */
159 if (0 == msg->len) 144 if (0 == msg->len)
160 return -EINVAL; 145 return -EINVAL;
161 146
162 /* start, address + first byte */ 147 /* start, address + first byte */
163 xmit = (msg->addr << 25) | (msg->buf[0 148 xmit = (msg->addr << 25) | (msg->buf[0] << 16) | I2C_HW;
164 if (msg->len > 1 || !last) 149 if (msg->len > 1 || !last)
165 xmit |= BT878_I2C_NOSTOP; 150 xmit |= BT878_I2C_NOSTOP;
166 btwrite(xmit, BT848_I2C); 151 btwrite(xmit, BT848_I2C);
167 retval = bttv_i2c_wait_done(btv); 152 retval = bttv_i2c_wait_done(btv);
168 if (retval < 0) 153 if (retval < 0)
169 goto err; 154 goto err;
170 if (retval == 0) 155 if (retval == 0)
171 goto eio; 156 goto eio;
172 if (i2c_debug) { 157 if (i2c_debug) {
173 printk(" <W %02x %02x", msg->a 158 printk(" <W %02x %02x", msg->addr << 1, msg->buf[0]);
174 if (!(xmit & BT878_I2C_NOSTOP) 159 if (!(xmit & BT878_I2C_NOSTOP))
175 printk(" >\n"); 160 printk(" >\n");
176 } 161 }
177 162
178 for (cnt = 1; cnt < msg->len; cnt++ ) 163 for (cnt = 1; cnt < msg->len; cnt++ ) {
179 /* following bytes */ 164 /* following bytes */
180 xmit = (msg->buf[cnt] << 24) | 165 xmit = (msg->buf[cnt] << 24) | I2C_HW | BT878_I2C_NOSTART;
181 if (cnt < msg->len-1 || !last) 166 if (cnt < msg->len-1 || !last)
182 xmit |= BT878_I2C_NOST 167 xmit |= BT878_I2C_NOSTOP;
183 btwrite(xmit, BT848_I2C); 168 btwrite(xmit, BT848_I2C);
184 retval = bttv_i2c_wait_done(bt 169 retval = bttv_i2c_wait_done(btv);
185 if (retval < 0) 170 if (retval < 0)
186 goto err; 171 goto err;
187 if (retval == 0) 172 if (retval == 0)
188 goto eio; 173 goto eio;
189 if (i2c_debug) { 174 if (i2c_debug) {
190 printk(" %02x", msg->b 175 printk(" %02x", msg->buf[cnt]);
191 if (!(xmit & BT878_I2C 176 if (!(xmit & BT878_I2C_NOSTOP))
192 printk(" >\n") 177 printk(" >\n");
193 } 178 }
194 } 179 }
195 return msg->len; 180 return msg->len;
196 181
197 eio: 182 eio:
198 retval = -EIO; 183 retval = -EIO;
199 err: 184 err:
200 if (i2c_debug) 185 if (i2c_debug)
201 printk(" ERR: %d\n",retval); 186 printk(" ERR: %d\n",retval);
202 return retval; 187 return retval;
203 } 188 }
204 189
205 static int 190 static int
206 bttv_i2c_readbytes(struct bttv *btv, const str 191 bttv_i2c_readbytes(struct bttv *btv, const struct i2c_msg *msg, int last)
207 { 192 {
208 u32 xmit; 193 u32 xmit;
209 u32 cnt; 194 u32 cnt;
210 int retval; 195 int retval;
211 196
212 for(cnt = 0; cnt < msg->len; cnt++) { 197 for(cnt = 0; cnt < msg->len; cnt++) {
213 xmit = (msg->addr << 25) | (1 198 xmit = (msg->addr << 25) | (1 << 24) | I2C_HW;
214 if (cnt < msg->len-1) 199 if (cnt < msg->len-1)
215 xmit |= BT848_I2C_W3B; 200 xmit |= BT848_I2C_W3B;
216 if (cnt < msg->len-1 || !last) 201 if (cnt < msg->len-1 || !last)
217 xmit |= BT878_I2C_NOST 202 xmit |= BT878_I2C_NOSTOP;
218 if (cnt) 203 if (cnt)
219 xmit |= BT878_I2C_NOST 204 xmit |= BT878_I2C_NOSTART;
220 btwrite(xmit, BT848_I2C); 205 btwrite(xmit, BT848_I2C);
221 retval = bttv_i2c_wait_done(bt 206 retval = bttv_i2c_wait_done(btv);
222 if (retval < 0) 207 if (retval < 0)
223 goto err; 208 goto err;
224 if (retval == 0) 209 if (retval == 0)
225 goto eio; 210 goto eio;
226 msg->buf[cnt] = ((u32)btread(B 211 msg->buf[cnt] = ((u32)btread(BT848_I2C) >> 8) & 0xff;
227 if (i2c_debug) { 212 if (i2c_debug) {
228 if (!(xmit & BT878_I2C 213 if (!(xmit & BT878_I2C_NOSTART))
229 printk(" <R %0 214 printk(" <R %02x", (msg->addr << 1) +1);
230 printk(" =%02x", msg-> 215 printk(" =%02x", msg->buf[cnt]);
231 if (!(xmit & BT878_I2C 216 if (!(xmit & BT878_I2C_NOSTOP))
232 printk(" >\n") 217 printk(" >\n");
233 } 218 }
234 } 219 }
235 return msg->len; 220 return msg->len;
236 221
237 eio: 222 eio:
238 retval = -EIO; 223 retval = -EIO;
239 err: 224 err:
240 if (i2c_debug) 225 if (i2c_debug)
241 printk(" ERR: %d\n",retval); 226 printk(" ERR: %d\n",retval);
242 return retval; 227 return retval;
243 } 228 }
244 229
245 static int bttv_i2c_xfer(struct i2c_adapter *i 230 static int bttv_i2c_xfer(struct i2c_adapter *i2c_adap, struct i2c_msg *msgs, int num)
246 { 231 {
247 struct bttv *btv = i2c_get_adapdata(i2 !! 232 struct v4l2_device *v4l2_dev = i2c_get_adapdata(i2c_adap);
>> 233 struct bttv *btv = to_bttv(v4l2_dev);
248 int retval = 0; 234 int retval = 0;
249 int i; 235 int i;
250 236
251 if (i2c_debug) 237 if (i2c_debug)
252 printk("bt-i2c:"); 238 printk("bt-i2c:");
253 btwrite(BT848_INT_I2CDONE|BT848_INT_RA 239 btwrite(BT848_INT_I2CDONE|BT848_INT_RACK, BT848_INT_STAT);
254 for (i = 0 ; i < num; i++) { 240 for (i = 0 ; i < num; i++) {
255 if (msgs[i].flags & I2C_M_RD) 241 if (msgs[i].flags & I2C_M_RD) {
256 /* read */ 242 /* read */
257 retval = bttv_i2c_read 243 retval = bttv_i2c_readbytes(btv, &msgs[i], i+1 == num);
258 if (retval < 0) 244 if (retval < 0)
259 goto err; 245 goto err;
260 } else { 246 } else {
261 /* write */ 247 /* write */
262 retval = bttv_i2c_send 248 retval = bttv_i2c_sendbytes(btv, &msgs[i], i+1 == num);
263 if (retval < 0) 249 if (retval < 0)
264 goto err; 250 goto err;
265 } 251 }
266 } 252 }
267 return num; 253 return num;
268 254
269 err: 255 err:
270 return retval; 256 return retval;
271 } 257 }
272 258
273 static struct i2c_algorithm bttv_algo = { !! 259 static const struct i2c_algorithm bttv_algo = {
274 .master_xfer = bttv_i2c_xfer, 260 .master_xfer = bttv_i2c_xfer,
275 .functionality = functionality, 261 .functionality = functionality,
276 }; 262 };
277 263
278 static struct i2c_adapter bttv_i2c_adap_hw_tem <<
279 .owner = THIS_MODULE, <<
280 .class = I2C_CLASS_TV_ANALOG, <<
281 .name = "bt878", <<
282 .id = I2C_HW_B_BT848 /* FIX <<
283 .algo = &bttv_algo, <<
284 .client_register = attach_inform, <<
285 }; <<
286 <<
287 /* ------------------------------------------- 264 /* ----------------------------------------------------------------------- */
288 /* I2C functions - common stuff 265 /* I2C functions - common stuff */
289 266
290 static int attach_inform(struct i2c_client *cl <<
291 { <<
292 struct bttv *btv = i2c_get_adapdata(cl <<
293 int addr=ADDR_UNSET; <<
294 <<
295 <<
296 if (ADDR_UNSET != bttv_tvcards[btv->c. <<
297 addr = bttv_tvcards[btv->c.typ <<
298 <<
299 <<
300 if (bttv_debug) <<
301 printk(KERN_DEBUG "bttv%d: %s <<
302 btv->c.nr, client->dri <<
303 client->name); <<
304 if (!client->driver->command) <<
305 return 0; <<
306 <<
307 if (client->driver->id == I2C_DRIVERID <<
308 btv->i2c_msp34xx_client = clie <<
309 if (client->driver->id == I2C_DRIVERID <<
310 btv->i2c_tvaudio_client = clie <<
311 if (btv->tuner_type != UNSET) { <<
312 struct tuner_setup tun_setup; <<
313 <<
314 if ((addr==ADDR_UNSET) || <<
315 (addr==client- <<
316 <<
317 tun_setup.mode_mask = <<
318 tun_setup.type = btv-> <<
319 tun_setup.addr = addr; <<
320 bttv_call_i2c_clients( <<
321 } <<
322 <<
323 } <<
324 <<
325 return 0; <<
326 } <<
327 <<
328 void bttv_call_i2c_clients(struct bttv *btv, u <<
329 { <<
330 if (0 != btv->i2c_rc) <<
331 return; <<
332 i2c_clients_command(&btv->c.i2c_adap, <<
333 } <<
334 <<
335 static struct i2c_client bttv_i2c_client_templ <<
336 .name = "bttv internal", <<
337 }; <<
338 <<
339 <<
340 /* read I2C */ 267 /* read I2C */
341 int bttv_I2CRead(struct bttv *btv, unsigned ch 268 int bttv_I2CRead(struct bttv *btv, unsigned char addr, char *probe_for)
342 { 269 {
343 unsigned char buffer = 0; 270 unsigned char buffer = 0;
344 271
345 if (0 != btv->i2c_rc) 272 if (0 != btv->i2c_rc)
346 return -1; 273 return -1;
347 if (bttv_verbose && NULL != probe_for) 274 if (bttv_verbose && NULL != probe_for)
348 printk(KERN_INFO "bttv%d: i2c: 275 printk(KERN_INFO "bttv%d: i2c: checking for %s @ 0x%02x... ",
349 btv->c.nr,probe_for,add 276 btv->c.nr,probe_for,addr);
350 btv->i2c_client.addr = addr >> 1; 277 btv->i2c_client.addr = addr >> 1;
351 if (1 != i2c_master_recv(&btv->i2c_cli 278 if (1 != i2c_master_recv(&btv->i2c_client, &buffer, 1)) {
352 if (NULL != probe_for) { 279 if (NULL != probe_for) {
353 if (bttv_verbose) 280 if (bttv_verbose)
354 printk("not fo 281 printk("not found\n");
355 } else 282 } else
356 printk(KERN_WARNING "b 283 printk(KERN_WARNING "bttv%d: i2c read 0x%x: error\n",
357 btv->c.nr,addr) 284 btv->c.nr,addr);
358 return -1; 285 return -1;
359 } 286 }
360 if (bttv_verbose && NULL != probe_for) 287 if (bttv_verbose && NULL != probe_for)
361 printk("found\n"); 288 printk("found\n");
362 return buffer; 289 return buffer;
363 } 290 }
364 291
365 /* write I2C */ 292 /* write I2C */
366 int bttv_I2CWrite(struct bttv *btv, unsigned c 293 int bttv_I2CWrite(struct bttv *btv, unsigned char addr, unsigned char b1,
367 unsigned char b2, int both 294 unsigned char b2, int both)
368 { 295 {
369 unsigned char buffer[2]; 296 unsigned char buffer[2];
370 int bytes = both ? 2 : 1; 297 int bytes = both ? 2 : 1;
371 298
372 if (0 != btv->i2c_rc) 299 if (0 != btv->i2c_rc)
373 return -1; 300 return -1;
374 btv->i2c_client.addr = addr >> 1; 301 btv->i2c_client.addr = addr >> 1;
375 buffer[0] = b1; 302 buffer[0] = b1;
376 buffer[1] = b2; 303 buffer[1] = b2;
377 if (bytes != i2c_master_send(&btv->i2c 304 if (bytes != i2c_master_send(&btv->i2c_client, buffer, bytes))
378 return -1; 305 return -1;
379 return 0; 306 return 0;
380 } 307 }
381 308
382 /* read EEPROM content */ 309 /* read EEPROM content */
383 void __devinit bttv_readee(struct bttv *btv, u 310 void __devinit bttv_readee(struct bttv *btv, unsigned char *eedata, int addr)
384 { 311 {
385 memset(eedata, 0, 256); 312 memset(eedata, 0, 256);
386 if (0 != btv->i2c_rc) 313 if (0 != btv->i2c_rc)
387 return; 314 return;
388 btv->i2c_client.addr = addr >> 1; 315 btv->i2c_client.addr = addr >> 1;
389 tveeprom_read(&btv->i2c_client, eedata 316 tveeprom_read(&btv->i2c_client, eedata, 256);
390 } 317 }
391 318
392 static char *i2c_devs[128] = { 319 static char *i2c_devs[128] = {
393 [ 0x1c >> 1 ] = "lgdt330x", 320 [ 0x1c >> 1 ] = "lgdt330x",
394 [ 0x30 >> 1 ] = "IR (hauppauge)", 321 [ 0x30 >> 1 ] = "IR (hauppauge)",
395 [ 0x80 >> 1 ] = "msp34xx", 322 [ 0x80 >> 1 ] = "msp34xx",
396 [ 0x86 >> 1 ] = "tda9887", 323 [ 0x86 >> 1 ] = "tda9887",
397 [ 0xa0 >> 1 ] = "eeprom", 324 [ 0xa0 >> 1 ] = "eeprom",
398 [ 0xc0 >> 1 ] = "tuner (analog)", 325 [ 0xc0 >> 1 ] = "tuner (analog)",
399 [ 0xc2 >> 1 ] = "tuner (analog)", 326 [ 0xc2 >> 1 ] = "tuner (analog)",
400 }; 327 };
401 328
402 static void do_i2c_scan(char *name, struct i2c 329 static void do_i2c_scan(char *name, struct i2c_client *c)
403 { 330 {
404 unsigned char buf; 331 unsigned char buf;
405 int i,rc; 332 int i,rc;
406 333
407 for (i = 0; i < ARRAY_SIZE(i2c_devs); 334 for (i = 0; i < ARRAY_SIZE(i2c_devs); i++) {
408 c->addr = i; 335 c->addr = i;
409 rc = i2c_master_recv(c,&buf,0) 336 rc = i2c_master_recv(c,&buf,0);
410 if (rc < 0) 337 if (rc < 0)
411 continue; 338 continue;
412 printk("%s: i2c scan: found de 339 printk("%s: i2c scan: found device @ 0x%x [%s]\n",
413 name, i << 1, i2c_devs[ 340 name, i << 1, i2c_devs[i] ? i2c_devs[i] : "???");
414 } 341 }
415 } 342 }
416 343
417 /* init + register i2c algo-bit adapter */ 344 /* init + register i2c algo-bit adapter */
418 int __devinit init_bttv_i2c(struct bttv *btv) 345 int __devinit init_bttv_i2c(struct bttv *btv)
419 { 346 {
420 memcpy(&btv->i2c_client, &bttv_i2c_cli !! 347 strlcpy(btv->i2c_client.name, "bttv internal", I2C_NAME_SIZE);
421 sizeof(bttv_i2c_client_template <<
422 348
423 if (i2c_hw) 349 if (i2c_hw)
424 btv->use_i2c_hw = 1; 350 btv->use_i2c_hw = 1;
425 if (btv->use_i2c_hw) { 351 if (btv->use_i2c_hw) {
426 /* bt878 */ 352 /* bt878 */
427 memcpy(&btv->c.i2c_adap, &bttv !! 353 strlcpy(btv->c.i2c_adap.name, "bt878",
428 sizeof(bttv_i2c_adap_hw !! 354 sizeof(btv->c.i2c_adap.name));
>> 355 btv->c.i2c_adap.id = I2C_HW_B_BT848; /* FIXME */
>> 356 btv->c.i2c_adap.algo = &bttv_algo;
429 } else { 357 } else {
430 /* bt848 */ 358 /* bt848 */
431 /* Prevents usage of invalid delay val 359 /* Prevents usage of invalid delay values */
432 if (i2c_udelay<5) 360 if (i2c_udelay<5)
433 i2c_udelay=5; 361 i2c_udelay=5;
434 bttv_i2c_algo_bit_template.ude <<
435 362
436 memcpy(&btv->c.i2c_adap, &bttv !! 363 strlcpy(btv->c.i2c_adap.name, "bttv",
437 sizeof(bttv_i2c_adap_sw !! 364 sizeof(btv->c.i2c_adap.name));
>> 365 btv->c.i2c_adap.id = I2C_HW_B_BT848;
438 memcpy(&btv->i2c_algo, &bttv_i 366 memcpy(&btv->i2c_algo, &bttv_i2c_algo_bit_template,
439 sizeof(bttv_i2c_algo_bi 367 sizeof(bttv_i2c_algo_bit_template));
>> 368 btv->i2c_algo.udelay = i2c_udelay;
440 btv->i2c_algo.data = btv; 369 btv->i2c_algo.data = btv;
441 btv->c.i2c_adap.algo_data = &b 370 btv->c.i2c_adap.algo_data = &btv->i2c_algo;
442 } 371 }
>> 372 btv->c.i2c_adap.owner = THIS_MODULE;
443 373
444 btv->c.i2c_adap.dev.parent = &btv->c.p 374 btv->c.i2c_adap.dev.parent = &btv->c.pci->dev;
445 snprintf(btv->c.i2c_adap.name, sizeof( 375 snprintf(btv->c.i2c_adap.name, sizeof(btv->c.i2c_adap.name),
446 "bt%d #%d [%s]", btv->id, btv 376 "bt%d #%d [%s]", btv->id, btv->c.nr,
447 btv->use_i2c_hw ? "hw" : "sw" 377 btv->use_i2c_hw ? "hw" : "sw");
448 378
449 i2c_set_adapdata(&btv->c.i2c_adap, btv !! 379 i2c_set_adapdata(&btv->c.i2c_adap, &btv->c.v4l2_dev);
450 btv->i2c_client.adapter = &btv->c.i2c_ 380 btv->i2c_client.adapter = &btv->c.i2c_adap;
451 381
452 if (bttv_tvcards[btv->c.type].no_video <<
453 btv->c.i2c_adap.class &= ~I2C_ <<
454 if (bttv_tvcards[btv->c.type].has_dvb) <<
455 btv->c.i2c_adap.class |= I2C_C <<
456 382
457 if (btv->use_i2c_hw) { 383 if (btv->use_i2c_hw) {
458 btv->i2c_rc = i2c_add_adapter( 384 btv->i2c_rc = i2c_add_adapter(&btv->c.i2c_adap);
459 } else { 385 } else {
460 bttv_bit_setscl(btv,1); 386 bttv_bit_setscl(btv,1);
461 bttv_bit_setsda(btv,1); 387 bttv_bit_setsda(btv,1);
462 btv->i2c_rc = i2c_bit_add_bus( 388 btv->i2c_rc = i2c_bit_add_bus(&btv->c.i2c_adap);
463 } 389 }
464 if (0 == btv->i2c_rc && i2c_scan) 390 if (0 == btv->i2c_rc && i2c_scan)
465 do_i2c_scan(btv->c.name,&btv-> !! 391 do_i2c_scan(btv->c.v4l2_dev.name, &btv->i2c_client);
>> 392
>> 393 /* Instantiate the IR receiver device, if present */
>> 394 if (0 == btv->i2c_rc) {
>> 395 struct i2c_board_info info;
>> 396 /* The external IR receiver is at i2c address 0x34 (0x35 for
>> 397 reads). Future Hauppauge cards will have an internal
>> 398 receiver at 0x30 (0x31 for reads). In theory, both can be
>> 399 fitted, and Hauppauge suggest an external overrides an
>> 400 internal.
>> 401
>> 402 That's why we probe 0x1a (~0x34) first. CB
>> 403 */
>> 404 const unsigned short addr_list[] = {
>> 405 0x1a, 0x18, 0x4b, 0x64, 0x30,
>> 406 I2C_CLIENT_END
>> 407 };
>> 408
>> 409 memset(&info, 0, sizeof(struct i2c_board_info));
>> 410 strlcpy(info.type, "ir_video", I2C_NAME_SIZE);
>> 411 i2c_new_probed_device(&btv->c.i2c_adap, &info, addr_list);
>> 412 }
466 return btv->i2c_rc; 413 return btv->i2c_rc;
467 } 414 }
468 415
469 int __devexit fini_bttv_i2c(struct bttv *btv) 416 int __devexit fini_bttv_i2c(struct bttv *btv)
470 { 417 {
471 if (0 != btv->i2c_rc) 418 if (0 != btv->i2c_rc)
472 return 0; 419 return 0;
473 420
474 return i2c_del_adapter(&btv->c.i2c_ada 421 return i2c_del_adapter(&btv->c.i2c_adap);
475 } 422 }
476 423
477 /* 424 /*
478 * Local variables: 425 * Local variables:
479 * c-basic-offset: 8 426 * c-basic-offset: 8
480 * End: 427 * End:
481 */ 428 */
482 429
|
This page was automatically generated by the
LXR engine.
|