23 #include <linux/module.h>
24 #include <linux/kernel.h>
26 #include <linux/i2c.h>
34 static unsigned int i2c_scan;
42 #define dprintk1(lvl, fmt, args...) \
44 if (i2c_debug >= lvl) { \
45 printk(fmt, ##args); \
49 #define dprintk2(lvl, fmt, args...) \
51 if (i2c_debug >= lvl) { \
52 printk(KERN_DEBUG "%s at %s: " fmt, \
53 dev->name, __func__ , ##args); \
60 if (bus->
nr != dev->
board.tuner_i2c_master)
89 if (is_tuner(dev, bus, msg, TUNER_XC5000)) {
96 }
else if (size == 4) {
98 saddr = msg->
buf[0] << 8 | msg->
buf[1];
99 else if (msg->
len == 1)
122 "GPIO WRITE: addr 0x%x, len %d, saddr 0x%x\n",
137 buf_ptr = (
u8 *) (msg->
buf + 1);
146 req_data.
p_buffer = (
u8 *) (buf_ptr + loop * 16);
179 return status < 0 ? status : 0;
186 static int cx231xx_i2c_recv_bytes(
struct i2c_adapter *i2c_adap,
196 if (is_tuner(dev, bus, msg, TUNER_XC5000)) {
198 saddr = msg->
buf[0] << 8 | msg->
buf[1];
199 else if (msg->
len == 1)
207 "GPIO R E A D: Special case BUSY check \n");
224 "GPIO R E A D: addr 0x%x, len %d, saddr 0x%x\n",
226 msg->
buf[0] << 8 | msg->
buf[1]);
241 req_data.dev_addr = msg->
addr;
242 req_data.direction = msg->
flags;
243 req_data.saddr_len = msg->
len;
244 req_data.saddr_dat = msg->
buf[0] << 8 | msg->
buf[1];
245 req_data.buf_size = msg->
len;
246 req_data.p_buffer = msg->
buf;
254 req_data.dev_addr = msg->
addr;
255 req_data.direction = msg->
flags;
256 req_data.saddr_len = 0;
257 req_data.saddr_dat = 0;
258 req_data.buf_size = msg->
len;
259 req_data.p_buffer = msg->
buf;
265 return status < 0 ? status : 0;
272 static int cx231xx_i2c_recv_bytes_with_saddr(
struct i2c_adapter *i2c_adap,
284 saddr = msg1->
buf[0] << 8 | msg1->
buf[1];
285 else if (msg1->
len == 1)
286 saddr = msg1->
buf[0];
288 if (is_tuner(dev, bus, msg2, TUNER_XC5000)) {
289 if ((msg2->
len < 16)) {
292 "i2c_read: addr 0x%x, len %d, saddr 0x%x, len %d\n",
319 req_data.dev_addr = msg2->
addr;
320 req_data.direction = msg2->
flags;
321 req_data.saddr_len = msg1->
len;
322 req_data.saddr_dat =
saddr;
323 req_data.buf_size = msg2->
len;
324 req_data.p_buffer = msg2->
buf;
329 return status < 0 ? status : 0;
336 static int cx231xx_i2c_check_for_device(
struct i2c_adapter *i2c_adap,
346 req_data.direction = msg->
flags;
347 req_data.saddr_len = 0;
348 req_data.saddr_dat = 0;
349 req_data.buf_size = 0;
350 req_data.p_buffer =
NULL;
355 return status < 0 ? status : 0;
362 static int cx231xx_i2c_xfer(
struct i2c_adapter *i2c_adap,
363 struct i2c_msg msgs[],
int num)
372 for (i = 0; i < num; i++) {
374 addr = msgs[
i].
addr >> 1;
376 dprintk2(2,
"%s %s addr=%x len=%d:",
378 i == num - 1 ?
"stop" :
"nonstop", addr, msgs[i].len);
381 rc = cx231xx_i2c_check_for_device(i2c_adap, &msgs[i]);
390 rc = cx231xx_i2c_recv_bytes(i2c_adap, &msgs[i]);
392 for (byte = 0; byte < msgs[
i].
len; byte++)
395 }
else if (i + 1 < num && (msgs[i + 1].
flags & I2C_M_RD) &&
396 msgs[i].addr == msgs[i + 1].addr
397 && (msgs[i].len <= 2) && (bus->
nr < 3)) {
399 rc = cx231xx_i2c_recv_bytes_with_saddr(i2c_adap,
403 for (byte = 0; byte < msgs[
i].
len; byte++)
410 for (byte = 0; byte < msgs[
i].
len; byte++)
439 .master_xfer = cx231xx_i2c_xfer,
443 static struct i2c_adapter cx231xx_adap_template = {
446 .algo = &cx231xx_algo,
449 static struct i2c_client cx231xx_client_template = {
450 .name =
"cx231xx internal",
460 [0x60 >> 1] =
"colibri",
461 [0x88 >> 1] =
"hammerhead",
463 [0x32 >> 1] =
"GeminiIII",
464 [0x02 >> 1] =
"Aquarius",
465 [0xa0 >> 1] =
"eeprom",
466 [0xc0 >> 1] =
"tuner",
467 [0xc2 >> 1] =
"tuner",
480 for (i = 0; i < 128; i++) {
485 cx231xx_info(
"%s: i2c scan: found device @ 0x%x [%s]\n",
487 i2c_devs[i] ? i2c_devs[i] :
"???");
489 cx231xx_info(
": Completed Checking for I2C devices.\n");
502 bus->
i2c_adap = cx231xx_adap_template;