24 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
27 #include <linux/i2c.h>
33 static unsigned int i2c_scan;
37 #define dprintk(level, fmt, arg...) \
39 if (i2c_debug >= level) \
40 printk(KERN_DEBUG "%s/0: " fmt, dev->name, ##arg); \
43 #define I2C_WAIT_DELAY 32
44 #define I2C_WAIT_RETRY 64
46 #define I2C_EXTEND (1 << 3)
47 #define I2C_NOSTOP (1 << 4)
49 static inline int i2c_slave_did_ack(
struct i2c_adapter *i2c_adap)
56 static inline int i2c_is_busy(
struct i2c_adapter *i2c_adap)
63 static int i2c_wait_done(
struct i2c_adapter *i2c_adap)
68 if (!i2c_is_busy(i2c_adap))
73 if (I2C_WAIT_RETRY == count)
79 static int i2c_sendbytes(
struct i2c_adapter *i2c_adap,
88 dprintk(1,
"%s(msg->wlen=%d, nextmsg->rlen=%d)\n", __func__,
89 msg->
len, joined_rlen);
91 dprintk(1,
"%s(msg->len=%d)\n", __func__, msg->
len);
98 if (!i2c_wait_done(i2c_adap))
101 if (!i2c_slave_did_ack(i2c_adap))
104 dprintk(1,
"%s(): returns 0\n", __func__);
109 addr = (msg->
addr << 25) | msg->
buf[0];
112 ctrl = bus->
i2c_period | (1 << 12) | (1 << 2);
116 else if (joined_rlen)
123 retval = i2c_wait_done(i2c_adap);
135 for (cnt = 1; cnt < msg->
len; cnt++) {
138 ctrl = bus->
i2c_period | (1 << 12) | (1 << 2);
140 if (cnt < msg->len - 1)
142 else if (joined_rlen)
149 retval = i2c_wait_done(i2c_adap);
169 pr_err(
" ERR: %d\n", retval);
173 static int i2c_readbytes(
struct i2c_adapter *i2c_adap,
174 const struct i2c_msg *msg,
int joined)
182 dprintk(1,
"6-%s(msg->len=%d)\n", __func__, msg->
len);
188 if (!i2c_wait_done(i2c_adap))
190 if (!i2c_slave_did_ack(i2c_adap))
193 dprintk(1,
"%s(): returns 0\n", __func__);
204 for (cnt = 0; cnt < msg->
len; cnt++) {
206 ctrl = bus->
i2c_period | (1 << 12) | (1 << 2) | 1;
208 if (cnt < msg->len - 1)
214 retval = i2c_wait_done(i2c_adap);
233 pr_err(
" ERR: %d\n", retval);
243 dprintk(1,
"%s(num = %d)\n", __func__, num);
245 for (i = 0; i < num; i++) {
246 dprintk(1,
"%s(num = %d) addr = 0x%02x len = 0x%x\n",
247 __func__, num, msgs[i].addr, msgs[i].len);
251 retval = i2c_readbytes(i2c_adap, &msgs[i], 0);
252 }
else if (i + 1 < num && (msgs[i + 1].
flags & I2C_M_RD) &&
253 msgs[i].addr == msgs[i + 1].addr) {
255 retval = i2c_sendbytes(i2c_adap, &msgs[i],
261 retval = i2c_readbytes(i2c_adap, &msgs[i], 1);
264 retval = i2c_sendbytes(i2c_adap, &msgs[i], 0);
284 .master_xfer = i2c_xfer,
285 .functionality = cx25821_functionality,
286 #ifdef NEED_ALGO_CONTROL
287 .algo_control = dummy_algo_control,
291 static struct i2c_adapter cx25821_i2c_adap_template = {
294 .algo = &cx25821_i2c_algo_template,
297 static struct i2c_client cx25821_i2c_client_template = {
298 .name =
"cx25821 internal",
306 dprintk(1,
"%s(bus = %d)\n", __func__, bus->
nr);
308 bus->
i2c_adap = cx25821_i2c_adap_template;
309 bus->
i2c_client = cx25821_i2c_client_template;
337 dprintk(1,
"%s(enabled = %d)\n", __func__, enable);
352 i2c_xfer(&dev->
i2c_bus[0].i2c_adap, &msg, 1);
359 u8 addr[2] = { 0, 0 };
360 u8 buf[4] = { 0, 0, 0, 0 };
376 addr[0] = (reg_addr >> 8);
377 addr[1] = (reg_addr & 0xff);
381 i2c_xfer(client->
adapter, msgs, 2);
383 v = (buf[3] << 24) | (buf[2] << 16) | (buf[1] << 8) | buf[0];
393 u8 buf[6] = { 0, 0, 0, 0, 0, 0 };
404 buf[0] = reg_addr >> 8;
405 buf[1] = reg_addr & 0xff;
406 buf[5] = (value >> 24) & 0xff;
407 buf[4] = (value >> 16) & 0xff;
408 buf[3] = (value >> 8) & 0xff;
409 buf[2] = value & 0xff;
413 retval = i2c_xfer(client->
adapter, msgs, 1);