Lines Matching +full:always +full:- +full:wait +full:- +full:for +full:- +full:ack

1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * i2c-algo-pcf.c i2c driver algorithms for PCF8584 adapters
5 * Copyright (C) 1995-1997 Simon G. Vogl
6 * 1998-2000 Hans Berglund
10 * <mbailey@littlefeet-inc.com>
21 #include <linux/i2c-algo-pcf.h>
22 #include "i2c-algo-pcf.h"
38 #define set_pcf(adap, ctl, val) adap->setpcf(adap->data, ctl, val)
39 #define get_pcf(adap, ctl) adap->getpcf(adap->data, ctl)
40 #define get_own(adap) adap->getown(adap->data)
41 #define get_clock(adap) adap->getclock(adap->data)
42 #define i2c_outb(adap, val) adap->setpcf(adap->data, 0, val)
43 #define i2c_inb(adap) adap->getpcf(adap->data, 0)
68 "i2c-algo-pcf.o: lost arbitration (CSR 0x%02x)\n", in handle_lab()
71 * Cleanup from LAB -- reset and enable ESO. in handle_lab()
79 * We pause for a time period sufficient for any running in handle_lab()
80 * I2C transaction to complete -- the arbitration logic won't in handle_lab()
87 if (adap->lab_mdelay) in handle_lab()
88 mdelay(adap->lab_mdelay); in handle_lab()
91 "i2c-algo-pcf.o: reset LAB condition (CSR 0x%02x)\n", in handle_lab()
103 while (!(status & I2C_PCF_BB) && --timeout) { in wait_for_bb()
104 udelay(100); /* wait for 100 us */ in wait_for_bb()
109 printk(KERN_ERR "Timeout waiting for Bus Busy\n"); in wait_for_bb()
110 return -ETIMEDOUT; in wait_for_bb()
123 while ((*status & I2C_PCF_PIN) && --timeout) { in wait_for_pin()
124 adap->waitforpin(adap->data); in wait_for_pin()
129 return -EINTR; in wait_for_pin()
133 return -ETIMEDOUT; in wait_for_pin()
141 * There should be a 30 clock cycle wait after reset, I assume this
144 * to synchronize the BB-bit (in multimaster systems). How long is
145 * this? I assume 1 second is always long enough.
147 * vdovikin: added detect code for PCF8584
153 DEB3(printk(KERN_DEBUG "i2c-algo-pcf.o: PCF state 0x%02x\n", in pcf_init_8584()
159 * check to see S1 now used as R/W ctrl - in pcf_init_8584()
163 …DEB2(printk(KERN_ERR "i2c-algo-pcf.o: PCF detection failed -- can't select S0 (0x%02x).\n", temp)); in pcf_init_8584()
164 return -ENXIO; /* definitely not PCF8584 */ in pcf_init_8584()
171 DEB2(printk(KERN_ERR "i2c-algo-pcf.o: PCF detection failed -- can't set S0 (0x%02x).\n", temp)); in pcf_init_8584()
172 return -ENXIO; in pcf_init_8584()
179 …DEB2(printk(KERN_ERR "i2c-algo-pcf.o: PCF detection failed -- can't select S2 (0x%02x).\n", temp)); in pcf_init_8584()
180 return -ENXIO; in pcf_init_8584()
187 DEB2(printk(KERN_ERR "i2c-algo-pcf.o: PCF detection failed -- can't set S2 (0x%02x).\n", temp)); in pcf_init_8584()
188 return -ENXIO; in pcf_init_8584()
196 …DEB2(printk(KERN_ERR "i2c-algo-pcf.o: PCF detection failed -- can't select S1` (0x%02x).\n", temp)… in pcf_init_8584()
197 return -ENXIO; in pcf_init_8584()
200 printk(KERN_DEBUG "i2c-algo-pcf.o: detected and initialized PCF8584.\n"); in pcf_init_8584()
208 struct i2c_algo_pcf_data *adap = i2c_adap->algo_data; in pcf_sendbytes()
211 for (wrcount=0; wrcount<count; ++wrcount) { in pcf_sendbytes()
212 DEB2(dev_dbg(&i2c_adap->dev, "i2c_write: writing %2.2X\n", in pcf_sendbytes()
217 if (timeout == -EINTR) in pcf_sendbytes()
218 return -EINTR; /* arbitration lost */ in pcf_sendbytes()
221 dev_err(&i2c_adap->dev, "i2c_write: error - timeout.\n"); in pcf_sendbytes()
222 return -EREMOTEIO; /* got a better one ?? */ in pcf_sendbytes()
226 dev_err(&i2c_adap->dev, "i2c_write: error - no ack.\n"); in pcf_sendbytes()
227 return -EREMOTEIO; /* got a better one ?? */ in pcf_sendbytes()
242 struct i2c_algo_pcf_data *adap = i2c_adap->algo_data; in pcf_readbytes()
245 /* increment number of bytes to read by one -- read dummy byte */ in pcf_readbytes()
246 for (i = 0; i <= count; i++) { in pcf_readbytes()
249 if (wfp == -EINTR) in pcf_readbytes()
250 return -EINTR; /* arbitration lost */ in pcf_readbytes()
253 dev_err(&i2c_adap->dev, "pcf_readbytes timed out.\n"); in pcf_readbytes()
254 return -1; in pcf_readbytes()
259 dev_err(&i2c_adap->dev, "i2c_read: i2c_inb, No ack.\n"); in pcf_readbytes()
260 return -1; in pcf_readbytes()
263 if (i == count - 1) { in pcf_readbytes()
273 buf[i - 1] = i2c_inb(adap); in pcf_readbytes()
278 return i - 1; in pcf_readbytes()
287 if (msg->flags & I2C_M_REV_DIR_ADDR) in pcf_doAddress()
298 struct i2c_algo_pcf_data *adap = i2c_adap->algo_data; in pcf_xfer()
303 if (adap->xfer_begin) in pcf_xfer()
304 adap->xfer_begin(adap->data); in pcf_xfer()
306 /* Check for bus busy */ in pcf_xfer()
309 DEB2(printk(KERN_ERR "i2c-algo-pcf.o: " in pcf_xfer()
310 "Timeout waiting for BB in pcf_xfer\n");) in pcf_xfer()
311 i = -EIO; in pcf_xfer()
315 for (i = 0;ret >= 0 && i < num; i++) { in pcf_xfer()
318 DEB2(printk(KERN_DEBUG "i2c-algo-pcf.o: Doing %s %d bytes to 0x%02x - %d of %d messages\n", in pcf_xfer()
319 pmsg->flags & I2C_M_RD ? "read" : "write", in pcf_xfer()
320 pmsg->len, pmsg->addr, i + 1, num);) in pcf_xfer()
328 /* Wait for PIN (pending interrupt NOT) */ in pcf_xfer()
331 if (timeout == -EINTR) { in pcf_xfer()
333 i = -EINTR; in pcf_xfer()
337 DEB2(printk(KERN_ERR "i2c-algo-pcf.o: Timeout waiting " in pcf_xfer()
338 "for PIN(1) in pcf_xfer\n");) in pcf_xfer()
339 i = -EREMOTEIO; in pcf_xfer()
343 /* Check LRB (last rcvd bit - slave ack) */ in pcf_xfer()
346 DEB2(printk(KERN_ERR "i2c-algo-pcf.o: No LRB(1) in pcf_xfer\n");) in pcf_xfer()
347 i = -EREMOTEIO; in pcf_xfer()
351 DEB3(printk(KERN_DEBUG "i2c-algo-pcf.o: Msg %d, addr=0x%x, flags=0x%x, len=%d\n", in pcf_xfer()
354 if (pmsg->flags & I2C_M_RD) { in pcf_xfer()
355 ret = pcf_readbytes(i2c_adap, pmsg->buf, pmsg->len, in pcf_xfer()
358 if (ret != pmsg->len) { in pcf_xfer()
359 DEB2(printk(KERN_DEBUG "i2c-algo-pcf.o: fail: " in pcf_xfer()
362 DEB2(printk(KERN_DEBUG "i2c-algo-pcf.o: read %d bytes.\n",ret)); in pcf_xfer()
365 ret = pcf_sendbytes(i2c_adap, pmsg->buf, pmsg->len, in pcf_xfer()
368 if (ret != pmsg->len) { in pcf_xfer()
369 DEB2(printk(KERN_DEBUG "i2c-algo-pcf.o: fail: " in pcf_xfer()
372 DEB2(printk(KERN_DEBUG "i2c-algo-pcf.o: wrote %d bytes.\n",ret)); in pcf_xfer()
378 if (adap->xfer_end) in pcf_xfer()
379 adap->xfer_end(adap->data); in pcf_xfer()
400 struct i2c_algo_pcf_data *pcf_adap = adap->algo_data; in i2c_pcf_add_bus()
403 DEB2(dev_dbg(&adap->dev, "hw routines registered.\n")); in i2c_pcf_add_bus()
406 adap->algo = &pcf_algo; in i2c_pcf_add_bus()
418 MODULE_DESCRIPTION("I2C-Bus PCF8584 algorithm");
423 "debug level - 0 off; 1 normal; 2,3 more verbose; 9 pcf-protocol");