22 #include <linux/module.h>
36 static unsigned int i2c_scan;
40 #define dprintk(level, fmt, arg...)\
41 do { if (i2c_debug >= level)\
42 printk(KERN_DEBUG "%s/0: " fmt, dev->name, ## arg);\
45 #define I2C_WAIT_DELAY 32
46 #define I2C_WAIT_RETRY 64
48 #define I2C_EXTEND (1 << 3)
49 #define I2C_NOSTOP (1 << 4)
51 static inline int i2c_slave_did_ack(
struct i2c_adapter *i2c_adap)
58 static inline int i2c_is_busy(
struct i2c_adapter *i2c_adap)
65 static int i2c_wait_done(
struct i2c_adapter *i2c_adap)
70 if (!i2c_is_busy(i2c_adap))
75 if (I2C_WAIT_RETRY == count)
81 static int i2c_sendbytes(
struct i2c_adapter *i2c_adap,
90 dprintk(1,
"%s(msg->wlen=%d, nextmsg->rlen=%d)\n", __func__,
91 msg->
len, joined_rlen);
93 dprintk(1,
"%s(msg->len=%d)\n", __func__, msg->
len);
99 if (!i2c_wait_done(i2c_adap))
101 if (!i2c_slave_did_ack(i2c_adap))
104 dprintk(1,
"%s() returns 0\n", __func__);
110 addr = (msg->
addr << 25) | msg->
buf[0];
112 ctrl = bus->
i2c_period | (1 << 12) | (1 << 2);
116 else if (joined_rlen)
123 if (!i2c_wait_done(i2c_adap))
131 for (cnt = 1; cnt < msg->
len; cnt++) {
134 ctrl = bus->
i2c_period | (1 << 12) | (1 << 2);
136 if (cnt < msg->len - 1)
138 else if (joined_rlen)
145 if (!i2c_wait_done(i2c_adap))
162 static int i2c_readbytes(
struct i2c_adapter *i2c_adap,
163 const struct i2c_msg *msg,
int joined)
172 dprintk(1,
"%s(msg->len=%d)\n", __func__, msg->
len);
178 if (!i2c_wait_done(i2c_adap))
180 if (!i2c_slave_did_ack(i2c_adap))
184 dprintk(1,
"%s() returns 0\n", __func__);
195 for (cnt = 0; cnt < msg->
len; cnt++) {
197 ctrl = bus->
i2c_period | (1 << 12) | (1 << 2) | 1;
199 if (cnt < msg->len - 1)
205 if (!i2c_wait_done(i2c_adap))
230 dprintk(1,
"%s(num = %d)\n", __func__, num);
232 for (i = 0 ; i < num; i++) {
233 dprintk(1,
"%s(num = %d) addr = 0x%02x len = 0x%x\n",
234 __func__, num, msgs[i].addr, msgs[i].len);
237 retval = i2c_readbytes(i2c_adap, &msgs[i], 0);
238 }
else if (i + 1 < num && (msgs[i + 1].
flags & I2C_M_RD) &&
239 msgs[i].addr == msgs[i + 1].addr) {
241 retval = i2c_sendbytes(i2c_adap, &msgs[i],
246 retval = i2c_readbytes(i2c_adap, &msgs[i], 1);
249 retval = i2c_sendbytes(i2c_adap, &msgs[i], 0);
266 .master_xfer = i2c_xfer,
267 .functionality = cx23885_functionality,
272 static struct i2c_adapter cx23885_i2c_adap_template = {
275 .algo = &cx23885_i2c_algo_template,
278 static struct i2c_client cx23885_i2c_client_template = {
279 .name =
"cx23885 internal",
283 [0x10 >> 1] =
"tda10048",
284 [0x12 >> 1] =
"dib7000pc",
285 [0x1c >> 1] =
"lgdt3303",
286 [0x86 >> 1] =
"tda9887",
287 [0x32 >> 1] =
"cx24227",
288 [0x88 >> 1] =
"cx25837",
289 [0x84 >> 1] =
"tda8295",
290 [0x98 >> 1] =
"flatiron",
291 [0xa0 >> 1] =
"eeprom",
292 [0xc0 >> 1] =
"tuner/mt2131/tda8275",
293 [0xc2 >> 1] =
"tuner/mt2131/tda8275/xc5000/xc3028",
294 [0xc8 >> 1] =
"tuner/xc3028L",
302 for (i = 0; i < 128; i++) {
308 name, i << 1, i2c_devs[i] ? i2c_devs[i] :
"???");
317 dprintk(1,
"%s(bus = %d)\n", __func__, bus->
nr);
319 bus->
i2c_adap = cx23885_i2c_adap_template;
320 bus->
i2c_client = cx23885_i2c_client_template;
333 dprintk(1,
"%s: i2c bus %d registered\n", dev->
name, bus->
nr);
346 const unsigned short addr_list[] = {
372 dprintk(1,
"%s(enabled = %d)\n", __func__, enable);
387 i2c_xfer(&dev->
i2c_bus[2].i2c_adap, &msg, 1);