Lines Matching +full:i2c +full:- +full:sda +full:- +full:delay
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>
76 u_int udelay; /* signal toggle delay in usec */
137 device_set_desc(dev, "I2C bit-banging driver");
147 sc->iicbus = device_add_child(dev, "iicbus", DEVICE_UNIT_ANY);
148 if (!sc->iicbus)
151 sc->scl_low_timeout = DEFAULT_SCL_LOW_TIMEOUT;
155 "delay", CTLFLAG_RD, &sc->udelay,
156 0, "Signal change delay controlled by bus frequency, microseconds");
160 "scl_low_timeout", CTLFLAG_RWTUN, &sc->scl_low_timeout,
164 "io_latency", CTLFLAG_RWTUN, &sc->io_latency,
186 /* We only have one child, the I2C bus, which needs our own node. */
196 if (child == sc->iicbus)
197 sc->iicbus = NULL;
208 /* retrieve the interface I2C address */
211 retval += printf(" on %s master-only\n",
230 &i2c_debug, 0, "Enable i2c bit-banging driver debug");
254 timeout = now + sc->scl_low_timeout * SBT_1US;
263 pause_sbt("iicbb-scl-low", SBT_1MS, 0, C_PREL(2));
275 iicbb_clockin(device_t dev, int sda)
281 * - set SDA to the value;
282 * - release SCL and wait until it's high.
285 * There should be a data set-up time, 250 ns minimum, between setting
286 * SDA and raising SCL. It's expected that the I/O access latency will
287 * naturally provide that delay.
289 I2C_SETSDA(dev, sda);
306 * - pull SCL low and hold for udelay.
309 DELAY(sc->udelay);
321 DELAY(sc->udelay);
338 * line low and then the SLAVE will release the SDA (data) line.
347 /* Release SDA so that the slave can drive it. */
354 /* Sample SDA until ACK (low) or udelay runs out. */
355 for (t = 0; t < sc->udelay; t++) {
359 DELAY(1);
362 DELAY(sc->udelay - t);
365 I2C_DEBUG(printf("%c ", noack ? '-' : '+'));
374 for (i = 7; i >= 0; i--) {
392 * Release SDA so that the slave can drive it.
393 * We do not use iicbb_clockin() here because we need to release SDA
398 for (i = 7; i >= 0; i--) {
405 DELAY((sc->udelay + 1) / 2);
408 DELAY((sc->udelay + 1) / 2);
413 * Send master->slave ACK (low) for more data,
417 I2C_DEBUG(printf("r%02x%c ", *data, last ? '-' : '+'));
454 /* SDA will go low in the middle of the SCL high phase. */
455 DELAY((sc->udelay + 1) / 2);
459 * SDA must be high after the earlier stop condition or the end
467 /* Start: SDA high->low. */
471 DELAY((sc->udelay + 1) / 2);
508 * Stop: SDA goes from low to high in the middle of the SCL high phase.
513 DELAY((sc->udelay + 1) / 2);
515 DELAY((sc->udelay + 1) / 2);
538 len--;
545 /* NB: whatever delay is, it's ignored. */
547 iicbb_read(device_t dev, char *buf, int len, int *read, int last, int delay)
559 len--;
590 busfreq = IICBUS_GET_FREQUENCY(sc->iicbus, speed);
591 period = 1000000 / 2 / busfreq; /* Hz -> uS */
592 period -= sc->io_latency;
593 sc->udelay = MAX(period, 1);