Lines Matching +full:wait +full:- +full:delay
1 /*-
2 * SPDX-License-Identifier: BSD-2-Clause
31 * Generic I2C bit-banging code
42 * (c) 1998 Gerd Knorr <kraxel@cs.tu-berlin.de>
76 u_int udelay; /* signal toggle delay in usec */
137 device_set_desc(dev, "I2C bit-banging driver"); in iicbb_probe()
147 sc->iicbus = device_add_child(dev, "iicbus", DEVICE_UNIT_ANY); in iicbb_attach()
148 if (!sc->iicbus) in iicbb_attach()
151 sc->scl_low_timeout = DEFAULT_SCL_LOW_TIMEOUT; in iicbb_attach()
155 "delay", CTLFLAG_RD, &sc->udelay, in iicbb_attach()
156 0, "Signal change delay controlled by bus frequency, microseconds"); in iicbb_attach()
160 "scl_low_timeout", CTLFLAG_RWTUN, &sc->scl_low_timeout, in iicbb_attach()
164 "io_latency", CTLFLAG_RWTUN, &sc->io_latency, in iicbb_attach()
196 if (child == sc->iicbus) in iicbb_child_detached()
197 sc->iicbus = NULL; in iicbb_child_detached()
211 retval += printf(" on %s master-only\n", in iicbb_print_child()
230 &i2c_debug, 0, "Enable i2c bit-banging driver debug");
254 timeout = now + sc->scl_low_timeout * SBT_1US; in iicbb_waitforscl()
263 pause_sbt("iicbb-scl-low", SBT_1MS, 0, C_PREL(2)); in iicbb_waitforscl()
281 * - set SDA to the value; in iicbb_clockin()
282 * - release SCL and wait until it's high. in iicbb_clockin()
285 * There should be a data set-up time, 250 ns minimum, between setting in iicbb_clockin()
287 * naturally provide that delay. in iicbb_clockin()
295 * End the high phase of the clock and wait out the low phase
306 * - pull SCL low and hold for udelay. in iicbb_clockout()
309 DELAY(sc->udelay); in iicbb_clockout()
321 DELAY(sc->udelay); in iicbb_sendbit()
332 * Now it must wait for the SLAVE to pull the DATA line low.
355 for (t = 0; t < sc->udelay; t++) { in iicbb_getack()
359 DELAY(1); in iicbb_getack()
362 DELAY(sc->udelay - t); in iicbb_getack()
365 I2C_DEBUG(printf("%c ", noack ? '-' : '+')); in iicbb_getack()
374 for (i = 7; i >= 0; i--) { in iicbb_sendbyte()
398 for (i = 7; i >= 0; i--) { in iicbb_readbyte()
405 DELAY((sc->udelay + 1) / 2); in iicbb_readbyte()
408 DELAY((sc->udelay + 1) / 2); in iicbb_readbyte()
413 * Send master->slave ACK (low) for more data, in iicbb_readbyte()
417 I2C_DEBUG(printf("r%02x%c ", *data, last ? '-' : '+')); in iicbb_readbyte()
455 DELAY((sc->udelay + 1) / 2); in iicbb_start_impl()
467 /* Start: SDA high->low. */ in iicbb_start_impl()
470 /* Wait the second half of the SCL high phase. */ in iicbb_start_impl()
471 DELAY((sc->udelay + 1) / 2); in iicbb_start_impl()
513 DELAY((sc->udelay + 1) / 2); in iicbb_stop()
515 DELAY((sc->udelay + 1) / 2); in iicbb_stop()
538 len--; in iicbb_write()
545 /* NB: whatever delay is, it's ignored. */
547 iicbb_read(device_t dev, char *buf, int len, int *read, int last, int delay) in iicbb_read() argument
559 len--; in iicbb_read()
590 busfreq = IICBUS_GET_FREQUENCY(sc->iicbus, speed); in iicbb_set_speed()
591 period = 1000000 / 2 / busfreq; /* Hz -> uS */ in iicbb_set_speed()
592 period -= sc->io_latency; in iicbb_set_speed()
593 sc->udelay = MAX(period, 1); in iicbb_set_speed()