30 #include <linux/kernel.h>
31 #include <linux/module.h>
34 #include <linux/errno.h>
35 #include <linux/i2c.h>
40 #define DEB2(x) if (i2c_debug >= 2) x
41 #define DEB3(x) if (i2c_debug >= 3) x
42 #define DEBPROTO(x) if (i2c_debug >= 9) x;
44 #define DEF_TIMEOUT 16
53 #define set_pcf(adap, ctl, val) adap->setpcf(adap->data, ctl, val)
54 #define get_pcf(adap, ctl) adap->getpcf(adap->data, ctl)
55 #define get_own(adap) adap->getown(adap->data)
56 #define get_clock(adap) adap->getclock(adap->data)
57 #define i2c_outb(adap, val) adap->setpcf(adap->data, 0, val)
58 #define i2c_inb(adap) adap->getpcf(adap->data, 0)
83 "i2c-algo-pcf.o: lost arbitration (CSR 0x%02x)\n",
106 "i2c-algo-pcf.o: reset LAB condition (CSR 0x%02x)\n",
143 handle_lab(adap, status);
177 if (((temp =
get_pcf(adap, 1)) & 0x7f) != (0)) {
178 DEB2(
printk(
KERN_ERR "i2c-algo-pcf.o: PCF detection failed -- can't select S0 (0x%02x).\n", temp));
186 DEB2(
printk(
KERN_ERR "i2c-algo-pcf.o: PCF detection failed -- can't set S0 (0x%02x).\n", temp));
194 DEB2(
printk(
KERN_ERR "i2c-algo-pcf.o: PCF detection failed -- can't select S2 (0x%02x).\n", temp));
202 DEB2(
printk(
KERN_ERR "i2c-algo-pcf.o: PCF detection failed -- can't set S2 (0x%02x).\n", temp));
210 if ((temp =
get_pcf(adap, 1)) != (I2C_PCF_PIN | I2C_PCF_BB)) {
211 DEB2(
printk(
KERN_ERR "i2c-algo-pcf.o: PCF detection failed -- can't select S1` (0x%02x).\n", temp));
220 static int pcf_sendbytes(
struct i2c_adapter *i2c_adap,
const char *
buf,
224 int wrcount,
status, timeout;
226 for (wrcount=0; wrcount<
count; ++wrcount) {
228 buf[wrcount] & 0xff));
230 timeout = wait_for_pin(adap, &status);
232 if (timeout == -
EINTR)
236 dev_err(&i2c_adap->
dev,
"i2c_write: error - timeout.\n");
241 dev_err(&i2c_adap->
dev,
"i2c_write: error - no ack.\n");
253 static int pcf_readbytes(
struct i2c_adapter *i2c_adap,
char *buf,
261 for (i = 0; i <=
count; i++) {
263 if ((wfp = wait_for_pin(adap, &status))) {
268 dev_err(&i2c_adap->
dev,
"pcf_readbytes timed out.\n");
274 dev_err(&i2c_adap->
dev,
"i2c_read: i2c_inb, No ack.\n");
278 if (i == count - 1) {
280 }
else if (i == count) {
303 addr = msg->
addr << 1;
326 timeout = wait_for_bb(adap);
329 "Timeout waiting for BB in pcf_xfer\n");)
334 for (i = 0;ret >= 0 && i < num; i++) {
338 pmsg->
flags & I2C_M_RD ?
"read" :
"write",
339 pmsg->
len, pmsg->
addr, i + 1, num);)
341 ret = pcf_doAddress(adap, pmsg);
348 timeout = wait_for_pin(adap, &status);
350 if (timeout == -
EINTR) {
357 "for PIN(1) in pcf_xfer\n");)
363 if (status & I2C_PCF_LRB) {
371 i, msgs[i].addr, msgs[i].flags, msgs[i].
len);)
373 if (pmsg->flags & I2C_M_RD) {
374 ret = pcf_readbytes(i2c_adap, pmsg->buf, pmsg->len,
377 if (ret != pmsg->len) {
379 "only read %d bytes.\n",ret));
384 ret = pcf_sendbytes(i2c_adap, pmsg->buf, pmsg->len,
387 if (ret != pmsg->len) {
389 "only wrote %d bytes.\n",ret));
398 adap->xfer_end(adap->data);
410 .master_xfer = pcf_xfer,
411 .functionality = pcf_func,
425 adap->
algo = &pcf_algo;
427 if ((rval = pcf_init_8584(pcf_adap)))
442 "debug level - 0 off; 1 normal; 2,3 more verbose; 9 pcf-protocol");