18 #include <linux/module.h>
21 #include <linux/sched.h>
22 #include <linux/list.h>
24 #include <linux/time.h>
25 #include <linux/device.h>
26 #include <linux/i2c.h>
37 #define SPI_I2C_ADDR_BASE 0x1400
38 #define STATUS_REG_ADDR (SPI_I2C_ADDR_BASE + 0x2)
39 #define I2C_CTRL_REG_ADDR (SPI_I2C_ADDR_BASE + 0x6)
40 #define I2C_DEV_UP_ADDR_REG_ADDR (SPI_I2C_ADDR_BASE + 0x7)
41 #define I2C_LO_ADDR_REG_ADDR (SPI_I2C_ADDR_BASE + 0x8)
42 #define I2C_DATA_REG_ADDR (SPI_I2C_ADDR_BASE + 0x9)
43 #define I2C_CLKFREQ_REG_ADDR (SPI_I2C_ADDR_BASE + 0xa)
45 #define I2C_STATE_MASK 0x0007
46 #define I2C_READ_READY_MASK 0x0008
58 if (go->
status == STATUS_SHUTDOWN)
61 #ifdef GO7007_I2C_DEBUG
67 "go7007-i2c: writing 0x%02x to 0x%02x on 0x%02x\n",
68 *data, command, addr);
80 for (i = 0; i < 10; ++
i) {
100 (addr << 9) | (command >> 8));
111 (addr << 9) | 0x0100 | (command >> 8));
114 for (i = 0; i < 10; ++
i) {
143 unsigned short flags,
char read_write,
146 struct go7007 *go = i2c_get_adapdata(adapter);
150 return go7007_i2c_xfer(go, addr, read_write ==
I2C_SMBUS_READ, command,
159 static int go7007_i2c_master_xfer(
struct i2c_adapter *adapter,
160 struct i2c_msg msgs[],
int num)
162 struct go7007 *go = i2c_get_adapdata(adapter);
165 for (i = 0; i < num; ++
i) {
168 if (msgs[i].len == 2) {
169 if (i + 1 == num || msgs[i].addr != msgs[i + 1].addr ||
171 !(msgs[i + 1].flags & I2C_M_RD) ||
172 msgs[i + 1].len != 1)
174 if (go7007_i2c_xfer(go, msgs[i].addr, 1,
175 (msgs[i].
buf[0] << 8) | msgs[i].
buf[1],
176 0x01, &msgs[i + 1].buf[0]) < 0)
179 }
else if (msgs[i].len == 3) {
180 if (msgs[i].flags & I2C_M_RD)
182 if (msgs[i].len != 3)
184 if (go7007_i2c_xfer(go, msgs[i].addr, 0,
185 (msgs[i].
buf[0] << 8) | msgs[i].
buf[1],
186 0x01, &msgs[i].buf[2]) < 0)
201 .smbus_xfer = go7007_smbus_xfer,
202 .master_xfer = go7007_i2c_master_xfer,
203 .functionality = go7007_functionality,
208 .name =
"WIS GO7007SB",
209 .algo = &go7007_algo,
215 sizeof(go7007_adap_templ));
220 "go7007-i2c: error: i2c_add_adapter failed\n");