Lines Matching +full:i2c +full:- +full:sda +full:- +full:hold +full:- +full:time +full:- +full:ns
1 /*-
2 * SPDX-License-Identifier: BSD-2-Clause
31 * Generic I2C bit-banging code
41 * From Linux I2C generic interface
42 * (c) 1998 Gerd Knorr <kraxel@cs.tu-berlin.de>
136 device_set_desc(dev, "I2C bit-banging driver");
146 sc->iicbus = device_add_child(dev, "iicbus", DEVICE_UNIT_ANY);
147 if (!sc->iicbus)
150 sc->scl_low_timeout = DEFAULT_SCL_LOW_TIMEOUT;
154 "delay", CTLFLAG_RD, &sc->udelay,
159 "scl_low_timeout", CTLFLAG_RWTUN, &sc->scl_low_timeout,
163 "io_latency", CTLFLAG_RWTUN, &sc->io_latency,
175 /* We only have one child, the I2C bus, which needs our own node. */
185 if (child == sc->iicbus)
186 sc->iicbus = NULL;
197 /* retrieve the interface I2C address */
200 retval += printf(" on %s master-only\n",
219 &i2c_debug, 0, "Enable i2c bit-banging driver debug");
243 timeout = now + sc->scl_low_timeout * SBT_1US;
252 pause_sbt("iicbb-scl-low", SBT_1MS, 0, C_PREL(2));
264 iicbb_clockin(device_t dev, int sda)
270 * - set SDA to the value;
271 * - release SCL and wait until it's high.
274 * There should be a data set-up time, 250 ns minimum, between setting
275 * SDA and raising SCL. It's expected that the I/O access latency will
278 I2C_SETSDA(dev, sda);
295 * - pull SCL low and hold for udelay.
298 DELAY(sc->udelay);
310 DELAY(sc->udelay);
327 * line low and then the SLAVE will release the SDA (data) line.
336 /* Release SDA so that the slave can drive it. */
343 /* Sample SDA until ACK (low) or udelay runs out. */
344 for (t = 0; t < sc->udelay; t++) {
351 DELAY(sc->udelay - t);
354 I2C_DEBUG(printf("%c ", noack ? '-' : '+'));
363 for (i = 7; i >= 0; i--) {
381 * Release SDA so that the slave can drive it.
382 * We do not use iicbb_clockin() here because we need to release SDA
387 for (i = 7; i >= 0; i--) {
394 DELAY((sc->udelay + 1) / 2);
397 DELAY((sc->udelay + 1) / 2);
402 * Send master->slave ACK (low) for more data,
406 I2C_DEBUG(printf("r%02x%c ", *data, last ? '-' : '+'));
443 /* SDA will go low in the middle of the SCL high phase. */
444 DELAY((sc->udelay + 1) / 2);
448 * SDA must be high after the earlier stop condition or the end
456 /* Start: SDA high->low. */
460 DELAY((sc->udelay + 1) / 2);
497 * Stop: SDA goes from low to high in the middle of the SCL high phase.
502 DELAY((sc->udelay + 1) / 2);
504 DELAY((sc->udelay + 1) / 2);
527 len--;
548 len--;
579 busfreq = IICBUS_GET_FREQUENCY(sc->iicbus, speed);
580 period = 1000000 / 2 / busfreq; /* Hz -> uS */
581 period -= sc->io_latency;
582 sc->udelay = MAX(period, 1);