30 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
32 #include <linux/module.h>
48 "instead of software bitbang");
52 static unsigned int i2c_udelay = 5;
55 "(should be 5 or higher). Lower value means higher bus speed.");
60 static void bttv_bit_setscl(
void *
data,
int state)
62 struct bttv *btv = (
struct bttv*)data;
65 btv->i2c_state |= 0x02;
67 btv->i2c_state &= ~0x02;
72 static void bttv_bit_setsda(
void *data,
int state)
74 struct bttv *btv = (
struct bttv*)data;
77 btv->i2c_state |= 0x01;
79 btv->i2c_state &= ~0x01;
84 static int bttv_bit_getscl(
void *data)
86 struct bttv *btv = (
struct bttv*)data;
93 static int bttv_bit_getsda(
void *data)
95 struct bttv *btv = (
struct bttv*)data;
103 .setsda = bttv_bit_setsda,
104 .setscl = bttv_bit_setscl,
105 .getsda = bttv_bit_getsda,
106 .getscl = bttv_bit_getscl,
120 bttv_i2c_wait_done(
struct bttv *btv)
135 #define I2C_HW (BT878_I2C_MODE | BT848_I2C_SYNC |\
136 BT848_I2C_SCL | BT848_I2C_SDA)
139 bttv_i2c_sendbytes(
struct bttv *btv,
const struct i2c_msg *
msg,
int last)
150 if (msg->
len > 1 || !last)
153 retval = bttv_i2c_wait_done(btv);
162 for (cnt = 1; cnt < msg->
len; cnt++ ) {
165 if (cnt < msg->
len-1 || !last)
168 retval = bttv_i2c_wait_done(btv);
189 bttv_i2c_readbytes(
struct bttv *btv,
const struct i2c_msg *
msg,
int last)
195 for (cnt = 0; cnt < msg->
len; cnt++) {
196 xmit = (msg->
addr << 25) | (1 << 24) |
I2C_HW;
197 if (cnt < msg->len-1)
199 if (cnt < msg->len-1 || !last)
210 retval = bttv_i2c_wait_done(btv);
236 struct v4l2_device *v4l2_dev = i2c_get_adapdata(i2c_adap);
237 struct bttv *btv = to_bttv(v4l2_dev);
245 for (i = 0 ; i < num; i++) {
248 retval = bttv_i2c_readbytes(btv, &msgs[i], i+1 == num);
253 retval = bttv_i2c_sendbytes(btv, &msgs[i], i+1 == num);
265 .master_xfer = bttv_i2c_xfer,
277 if (0 != btv->i2c_rc)
280 pr_info(
"%d: i2c: checking for %s @ 0x%02x... ",
281 btv->c.nr, probe_for, addr);
282 btv->i2c_client.addr = addr >> 1;
284 if (
NULL != probe_for) {
288 pr_warn(
"%d: i2c read 0x%x: error\n",
299 unsigned char b2,
int both)
302 int bytes = both ? 2 : 1;
304 if (0 != btv->i2c_rc)
306 btv->i2c_client.addr = addr >> 1;
318 if (0 != btv->i2c_rc)
320 btv->i2c_client.addr = addr >> 1;
325 [ 0x1c >> 1 ] =
"lgdt330x",
326 [ 0x30 >> 1 ] =
"IR (hauppauge)",
327 [ 0x80 >> 1 ] =
"msp34xx",
328 [ 0x86 >> 1 ] =
"tda9887",
329 [ 0xa0 >> 1 ] =
"eeprom",
330 [ 0xc0 >> 1 ] =
"tuner (analog)",
331 [ 0xc2 >> 1 ] =
"tuner (analog)",
344 pr_info(
"%s: i2c scan: found device @ 0x%x [%s]\n",
345 name, i << 1, i2c_devs[i] ? i2c_devs[i] :
"???");
356 if (btv->use_i2c_hw) {
358 strlcpy(btv->c.i2c_adap.name,
"bt878",
359 sizeof(btv->c.i2c_adap.name));
360 btv->c.i2c_adap.algo = &bttv_algo;
367 strlcpy(btv->c.i2c_adap.name,
"bttv",
368 sizeof(btv->c.i2c_adap.name));
369 memcpy(&btv->i2c_algo, &bttv_i2c_algo_bit_template,
370 sizeof(bttv_i2c_algo_bit_template));
371 btv->i2c_algo.udelay = i2c_udelay;
372 btv->i2c_algo.data = btv;
373 btv->c.i2c_adap.algo_data = &btv->i2c_algo;
377 btv->c.i2c_adap.dev.parent = &btv->c.pci->dev;
378 snprintf(btv->c.i2c_adap.name,
sizeof(btv->c.i2c_adap.name),
379 "bt%d #%d [%s]", btv->id, btv->c.nr,
380 btv->use_i2c_hw ?
"hw" :
"sw");
382 i2c_set_adapdata(&btv->c.i2c_adap, &btv->c.v4l2_dev);
383 btv->i2c_client.adapter = &btv->c.i2c_adap;
386 if (btv->use_i2c_hw) {
389 bttv_bit_setscl(btv,1);
390 bttv_bit_setsda(btv,1);
393 if (0 == btv->i2c_rc && i2c_scan)
394 do_i2c_scan(btv->c.v4l2_dev.name, &btv->i2c_client);