24 #include <linux/list.h>
25 #include <linux/module.h>
26 #include <linux/kernel.h>
39 static unsigned int i2c_scan;
43 #define d1printk if (1 == i2c_debug) printk
44 #define d2printk if (2 == i2c_debug) printk
46 #define I2C_WAIT_DELAY 32
47 #define I2C_WAIT_RETRY 16
51 static char *str_i2c_status[] = {
52 "IDLE",
"DONE_STOP",
"BUSY",
"TO_SCL",
"TO_ARB",
"DONE_WRITE",
53 "DONE_READ",
"DONE_WRITE_TO",
"DONE_READ_TO",
"NO_DEVICE",
54 "NO_ACKN",
"BUS_ERR",
"ARB_LOST",
"SEQ_ERR",
"ST_ERR",
"SW_ERR"
76 static char *str_i2c_attr[] = {
77 "NOP",
"STOP",
"CONTINUE",
"START"
93 str_i2c_status[status]);
101 str_i2c_status[status]);
127 static inline int i2c_is_idle(
enum i2c_status status)
138 static inline int i2c_is_busy(
enum i2c_status status)
156 status = i2c_get_status(dev);
157 if (!i2c_is_busy(status))
161 if (I2C_WAIT_RETRY == count)
172 status = i2c_get_status(dev);
173 if (!i2c_is_error(status))
175 i2c_set_status(dev,status);
178 status = i2c_get_status(dev);
179 if (!i2c_is_error(status))
183 if (I2C_WAIT_RETRY == count)
186 if (!i2c_is_idle(status))
189 i2c_set_attr(dev,
NOP);
193 static inline int i2c_send_byte(
struct saa7134_dev *dev,
203 dword |= (attr << 6);
204 dword |= ((
__u32)data << 8);
211 if (!i2c_is_busy_wait(dev))
213 status = i2c_get_status(dev);
214 if (i2c_is_error(status))
219 static inline int i2c_recv_byte(
struct saa7134_dev *dev)
225 if (!i2c_is_busy_wait(dev))
227 status = i2c_get_status(dev);
228 if (i2c_is_error(status))
235 static int saa7134_i2c_xfer(
struct i2c_adapter *i2c_adap,
243 status = i2c_get_status(dev);
244 if (!i2c_is_idle(status))
250 for (i = 0; i < num; i++) {
254 addr = msgs[
i].
addr << 1;
257 if (i > 0 && msgs[i].
flags &
258 I2C_M_RD && msgs[i].addr != 0x40 &&
259 msgs[i].addr != 0x19) {
265 i2c_send_byte(dev,
START,quirk);
269 rc = i2c_send_byte(dev,
START,addr);
273 if (msgs[i].
flags & I2C_M_RD) {
276 for (byte = 0; byte < msgs[
i].
len; byte++) {
278 rc = i2c_recv_byte(dev);
287 if (0x19 == msgs[i].addr) {
289 rc = i2c_recv_byte(dev);
297 for (byte = 0; byte < msgs[
i].
len; byte++) {
300 rc = i2c_send_byte(dev,
CONTINUE,data);
308 i2c_set_attr(dev,
STOP);
310 if (!i2c_is_busy_wait(dev))
312 status = i2c_get_status(dev);
313 if (i2c_is_error(status))
322 status = i2c_get_status(dev);
323 printk(
" ERROR: %s\n",str_i2c_status[status]);
336 .master_xfer = saa7134_i2c_xfer,
340 static struct i2c_adapter saa7134_adap_template = {
343 .algo = &saa7134_algo,
346 static struct i2c_client saa7134_client_template = {
347 .name =
"saa7134 internal",
353 saa7134_i2c_eeprom(
struct saa7134_dev *dev,
unsigned char *eedata,
int len)
370 for (i = 0; i < len; i++) {
373 printk(
" %02x",eedata[i]);
381 [ 0x20 ] =
"mpeg encoder (saa6752hs)",
382 [ 0xa0 >> 1 ] =
"eeprom",
383 [ 0xc0 >> 1 ] =
"tuner (analog)",
384 [ 0x86 >> 1 ] =
"tda9887",
385 [ 0x5a >> 1 ] =
"remote control",
398 printk(
"%s: i2c scan: found device @ 0x%x [%s]\n",
399 name, i << 1, i2c_devs[i] ? i2c_devs[i] :
"???");
405 dev->
i2c_adap = saa7134_adap_template;
415 saa7134_i2c_eeprom(dev,dev->
eedata,
sizeof(dev->
eedata));