22 #include <linux/module.h>
36 #define I2C_WAIT_DELAY 25
37 #define I2C_WAIT_RETRY 1000
39 static inline int i2c_slave_did_write_ack(
struct i2c_adapter *i2c_adap)
58 if (!i2c_slave_did_read_ack(i2c_adap))
63 if (I2C_WAIT_RETRY == count)
69 static inline int i2c_is_read_busy(
struct i2c_adapter *i2c_adap)
76 static int i2c_wait_read_done(
struct i2c_adapter *i2c_adap)
81 if (!i2c_is_read_busy(i2c_adap))
86 if (I2C_WAIT_RETRY == count)
92 static inline int i2c_is_write_done(
struct i2c_adapter *i2c_adap)
99 static int i2c_wait_write_done(
struct i2c_adapter *i2c_adap)
104 if (i2c_is_write_done(i2c_adap))
109 if (I2C_WAIT_RETRY == count)
115 static inline int i2c_is_busy(
struct i2c_adapter *i2c_adap)
122 static int i2c_wait_done(
struct i2c_adapter *i2c_adap)
127 if (!i2c_is_busy(i2c_adap))
132 if (I2C_WAIT_RETRY == count)
139 static int i2c_sendbytes(
struct i2c_adapter *i2c_adap,
145 dprintk(4,
"%s()\n", __func__);
150 if (((dev->
board.tuner_type == TUNER_XC5000) ||
151 (dev->
board.tuner_type == TUNER_XC5000C)) &&
161 dev->
board.i2c_clk_divider);
180 if (!i2c_wait_done(i2c_adap))
183 if (i2c_wait_read_ack(i2c_adap))
189 for (i = 0; i < msg->
len;) {
198 if ((strobe >= 4) || (i >= msg->
len)) {
212 if (!i2c_wait_write_done(i2c_adap))
218 if (!i2c_wait_done(i2c_adap))
227 static int i2c_readbytes(
struct i2c_adapter *i2c_adap,
228 const struct i2c_msg *msg,
int joined)
233 dprintk(4,
"%s()\n", __func__);
239 dev->
board.i2c_clk_divider);
251 if (i2c_wait_read_ack(i2c_adap))
256 for (i = 0; i < msg->
len;) {
268 if (!i2c_wait_read_done(i2c_adap))
276 if (!i2c_wait_done(i2c_adap))
289 dprintk(4,
"%s(num = %d)\n", __func__, num);
291 for (i = 0; i < num; i++) {
292 dprintk(4,
"%s(num = %d) addr = 0x%02x len = 0x%x\n",
293 __func__, num, msgs[i].
addr, msgs[i].len);
296 retval = i2c_readbytes(i2c_adap, &msgs[i], 0);
297 }
else if (i + 1 < num && (msgs[i + 1].
flags & I2C_M_RD) &&
300 retval = i2c_sendbytes(i2c_adap, &msgs[i],
305 retval = i2c_readbytes(i2c_adap, &msgs[i], 1);
308 retval = i2c_sendbytes(i2c_adap, &msgs[i], 0);
325 .master_xfer = i2c_xfer,
326 .functionality = au0828_functionality,
331 static struct i2c_adapter au0828_i2c_adap_template = {
334 .algo = &au0828_i2c_algo_template,
337 static struct i2c_client au0828_i2c_client_template = {
338 .name =
"au0828 internal",
342 [0x8e >> 1] =
"au8522",
343 [0xa0 >> 1] =
"eeprom",
344 [0xc2 >> 1] =
"tuner/xc5000",
352 for (i = 0; i < 128; i++) {
358 name, i << 1, i2c_devs[i] ? i2c_devs[i] :
"???");
365 dprintk(1,
"%s()\n", __func__);