25 #define MV64x60_I2C_REG_SLAVE_ADDR 0x00
26 #define MV64x60_I2C_REG_DATA 0x04
27 #define MV64x60_I2C_REG_CONTROL 0x08
28 #define MV64x60_I2C_REG_STATUS 0x0c
29 #define MV64x60_I2C_REG_BAUD 0x0c
30 #define MV64x60_I2C_REG_EXT_SLAVE_ADDR 0x10
31 #define MV64x60_I2C_REG_SOFT_RESET 0x1c
33 #define MV64x60_I2C_CONTROL_ACK 0x04
34 #define MV64x60_I2C_CONTROL_IFLG 0x08
35 #define MV64x60_I2C_CONTROL_STOP 0x10
36 #define MV64x60_I2C_CONTROL_START 0x20
37 #define MV64x60_I2C_CONTROL_TWSIEN 0x40
38 #define MV64x60_I2C_CONTROL_INTEN 0x80
40 #define MV64x60_I2C_STATUS_BUS_ERR 0x00
41 #define MV64x60_I2C_STATUS_MAST_START 0x08
42 #define MV64x60_I2C_STATUS_MAST_REPEAT_START 0x10
43 #define MV64x60_I2C_STATUS_MAST_WR_ADDR_ACK 0x18
44 #define MV64x60_I2C_STATUS_MAST_WR_ADDR_NO_ACK 0x20
45 #define MV64x60_I2C_STATUS_MAST_WR_ACK 0x28
46 #define MV64x60_I2C_STATUS_MAST_WR_NO_ACK 0x30
47 #define MV64x60_I2C_STATUS_MAST_LOST_ARB 0x38
48 #define MV64x60_I2C_STATUS_MAST_RD_ADDR_ACK 0x40
49 #define MV64x60_I2C_STATUS_MAST_RD_ADDR_NO_ACK 0x48
50 #define MV64x60_I2C_STATUS_MAST_RD_DATA_ACK 0x50
51 #define MV64x60_I2C_STATUS_MAST_RD_DATA_NO_ACK 0x58
52 #define MV64x60_I2C_STATUS_MAST_WR_ADDR_2_ACK 0xd0
53 #define MV64x60_I2C_STATUS_MAST_WR_ADDR_2_NO_ACK 0xd8
54 #define MV64x60_I2C_STATUS_MAST_RD_ADDR_2_ACK 0xe0
55 #define MV64x60_I2C_STATUS_MAST_RD_ADDR_2_NO_ACK 0xe8
56 #define MV64x60_I2C_STATUS_NO_STATUS 0xf8
60 static int mv64x60_i2c_wait_for_status(
int wanted)
65 for (i=0; i<1000; i++) {
78 return mv64x60_i2c_wait_for_status(status);
81 static int mv64x60_i2c_read_byte(
int control,
int status)
84 if (mv64x60_i2c_wait_for_status(status) < 0)
89 static int mv64x60_i2c_write_byte(
int data,
int control,
int status)
93 return mv64x60_i2c_wait_for_status(status);
104 if (ctlr_base ==
NULL)
120 if (mv64x60_i2c_control(control, status) < 0)
124 data = devaddr & ~0x1;
127 if (mv64x60_i2c_write_byte(data, control, status) < 0)
133 if (offset_size > 1) {
134 if (mv64x60_i2c_write_byte(offset >> 8, control, status) < 0)
137 if (mv64x60_i2c_write_byte(offset, control, status) < 0)
143 if (mv64x60_i2c_control(control, status) < 0)
147 data = devaddr | 0x1;
150 if (mv64x60_i2c_write_byte(data, control, status) < 0)
157 for (i=1; i<
count; i++) {
158 data = mv64x60_i2c_read_byte(control, status);
160 printf(
"errors on iteration %d\n", i);
169 data = mv64x60_i2c_read_byte(control, status);
177 if (mv64x60_i2c_control(control, status) < 0)
188 devp = find_node_by_compatible(
NULL,
"marvell,mv64360-i2c");
191 if (getprop(devp,
"virtual-reg", &v,
sizeof(v)) !=
sizeof(v))