14 #include <linux/module.h>
17 #include <linux/i2c.h>
22 #include <linux/slab.h>
25 #define SMCR_START (1 << 0)
26 #define SMCR_IRIC (1 << 1)
27 #define SMCR_BBSY (1 << 2)
28 #define SMCR_ACKE (1 << 3)
29 #define SMCR_RST (1 << 4)
30 #define SMCR_IEIC (1 << 6)
35 #define SMMR_MODE0 (1 << 0)
36 #define SMMR_MODE1 (1 << 1)
37 #define SMMR_CAP (1 << 3)
38 #define SMMR_TMMD (1 << 4)
39 #define SMMR_SP (1 << 7)
55 static bool iic_force_poll, iic_force_normal;
56 static int iic_timeout = 1000, iic_read_delay;
93 static void smbus_write_data(
u8 *
src,
u16 *
dst,
int len)
95 for (; len > 1; len -= 2) {
104 static void smbus_read_data(
u16 *src,
u8 *dst,
int len)
106 for (; len > 1; len -= 2) {
119 u16 cmd = (command << 8) | command;
121 for (i = 0; i < len; i += 2) {
125 dev_dbg(dev->
dev,
"command data[%x] 0x%04x\n", i/2, cmd);
136 dev_warn(dev->
dev,
"timeout waiting for bus ready\n");
149 return highlander_i2c_wait_for_bbsy(dev);
158 return highlander_i2c_reset(dev);
168 highlander_i2c_done(dev);
176 unsigned long timeout;
208 highlander_i2c_poll(dev);
210 return highlander_i2c_wait_for_ack(dev);
218 if (highlander_i2c_wait_for_bbsy(dev))
221 highlander_i2c_start(dev);
223 if (highlander_i2c_wait_xfer_done(dev)) {
246 for (i = 0; i <
cnt; i++) {
248 dev_dbg(dev->
dev,
"read data[%x] 0x%04x\n", i, data[i]);
251 smbus_read_data(data, dev->
buf, dev->
buf_len);
263 smbus_write_data(dev->
buf, data, dev->
buf_len);
266 for (i = 0; i <
cnt; i++) {
268 dev_dbg(dev->
dev,
"write data[%x] 0x%04x\n", i, data[i]);
271 if (highlander_i2c_wait_for_bbsy(dev))
274 highlander_i2c_start(dev);
276 return highlander_i2c_wait_xfer_done(dev);
280 unsigned short flags,
char read_write,
289 dev_dbg(dev->
dev,
"addr %04x, command %02x, read_write %d, size %d\n",
290 addr, command, read_write, size);
305 dev_err(dev->
dev,
"unsupported command %d\n", size);
336 highlander_i2c_done(dev);
341 highlander_i2c_command(dev, command, dev->
buf_len);
344 return highlander_i2c_read(dev);
346 return highlander_i2c_write(dev);
355 .smbus_xfer = highlander_i2c_smbus_xfer,
356 .functionality = highlander_i2c_func,
383 platform_set_drvdata(pdev, dev);
395 highlander_i2c_irq_enable(dev);
397 dev_notice(&pdev->
dev,
"no IRQ, using polling mode\n");
398 highlander_i2c_irq_disable(dev);
403 highlander_i2c_setup(dev);
406 i2c_set_adapdata(adap, dev);
410 adap->
algo = &highlander_i2c_algo;
411 adap->
dev.parent = &pdev->
dev;
417 ret = highlander_i2c_reset(dev);
419 dev_err(&pdev->
dev,
"controller didn't come up\n");
425 dev_err(&pdev->
dev,
"failure adding adapter\n");
439 platform_set_drvdata(pdev,
NULL);
456 platform_set_drvdata(pdev,
NULL);
463 .name =
"i2c-highlander",
467 .probe = highlander_i2c_probe,
484 "Force normal mode (100 kHz), default is fast mode (400 kHz)");
485 MODULE_PARM_DESC(iic_timeout,
"Set timeout value in msecs (default 1000 ms)");
487 "Delay between data read cycles (default 0 ms)");