2 * This program is free software; you can redistribute it and/or modify it
3 * under the terms of the GNU General Public License as published by the
4 * Free Software Foundation; either version 2 of the License, or (at your
5 * option) any later version.
11 #if defined(CONFIG_JZ4730) || defined(CONFIG_JZ4740) || defined(CONFIG_JZ5730)
18 #if defined(CONFIG_JZ4730)
19 #include <asm/jz4730.h>
21 #if defined(CONFIG_JZ4740)
22 #include <asm/jz4740.h>
24 #if defined(CONFIG_JZ5730)
25 #include <asm/jz5730.h>
38 static inline void my_udelay(int n
)
48 * I2C bus protocol basic routines
50 static int i2c_put_data(unsigned char data
)
52 unsigned int timeout
= TIMEOUT
*10;
56 while (__i2c_check_drf() != 0);
57 while (!__i2c_transmit_ended());
58 while (!__i2c_received_ack() && timeout
)
67 static int i2c_get_data(unsigned char *data
, int ack
)
69 int timeout
= TIMEOUT
*10;
76 while (__i2c_check_drf() == 0 && timeout
)
94 __i2c_set_clk(CFG_EXTAL
, 10000); /* default 10 KHz */
100 my_udelay(300); /* wait for STOP goes over. */
104 void i2c_setclk(unsigned int i2cclk
)
106 __i2c_set_clk(CFG_EXTAL
, i2cclk
);
109 int i2c_lseek(unsigned char device
, unsigned char offset
)
111 __i2c_send_nack(); /* Master does not send ACK, slave sends it */
113 if (i2c_put_data( (device
<< 1) | I2C_WRITE
) < 0)
115 if (i2c_put_data(offset
) < 0)
119 printf("No I2C device (0x%02x) installed.\n", device
);
123 printf("No I2C device (0x%02x) response.\n", device
);
128 int i2c_read(unsigned char device
, unsigned char *buf
,
129 unsigned char address
, int count
)
139 __i2c_send_nack(); /* Master does not send ACK, slave sends it */
141 if (i2c_put_data( (device
<< 1) | I2C_WRITE
) < 0)
143 if (i2c_put_data(address
) < 0)
147 if (i2c_put_data( (device
<< 1) | I2C_READ
) < 0)
149 __i2c_send_ack(); /* Master sends ACK for continue reading */
152 if (i2c_get_data(buf
, 0) < 0)
155 if (i2c_get_data(buf
, 1) < 0)
173 printf("Read I2C device 0x%2x failed.\n", device
);
177 int i2c_write(unsigned char device
, unsigned char *buf
,
178 unsigned char address
, int count
)
183 unsigned char *tmpbuf
;
184 unsigned char tmpaddr
;
186 __i2c_send_nack(); /* Master does not send ACK, slave sends it */
193 tmpbuf
= (unsigned char *)buf
;
199 if (i2c_put_data( (device
<< 1) | I2C_WRITE
) < 0)
201 if (i2c_put_data(tmpaddr
) < 0)
204 if (++cnt_in_pg
> 8) {
208 goto start_write_page
;
210 if (i2c_put_data(*tmpbuf
) < 0)
224 printf("Write I2C device 0x%2x failed.\n", device
);
229 #endif /* CONFIG_JZ4730 || CONFIG_JZ4740 || CONFIG_JZ5730 */