Lines Matching +full:i2c +full:- +full:slave +full:- +full:addr

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>
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,
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",
217 retval += printf(" on %s addr 0x%x\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));
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
306 * - pull SCL low and hold for udelay.
309 DELAY(sc->udelay);
321 DELAY(sc->udelay);
332 * Now it must wait for the SLAVE to pull the DATA line low.
337 * When the SLAVE has pulled this line low the MASTER will take the CLOCK
338 * line low and then the SLAVE will release the SDA (data) line.
347 /* Release SDA so that the slave can drive it. */
355 for (t = 0; t < sc->udelay; t++) {
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.
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 ? '-' : '+'));
428 iicbb_reset(device_t dev, u_char speed, u_char addr, u_char *oldaddr)
431 return (IICBB_RESET(device_get_parent(dev), speed, addr, oldaddr));
435 iicbb_start_impl(device_t dev, u_char slave, bool repstart)
455 DELAY((sc->udelay + 1) / 2);
467 /* Start: SDA high->low. */
471 DELAY((sc->udelay + 1) / 2);
477 error = iicbb_sendbyte(dev, slave);
489 iicbb_start(device_t dev, u_char slave, int timeout)
491 return (iicbb_start_impl(dev, slave, false));
496 iicbb_repstart(device_t dev, u_char slave, int timeout)
498 return (iicbb_start_impl(dev, slave, true));
513 DELAY((sc->udelay + 1) / 2);
515 DELAY((sc->udelay + 1) / 2);
538 len--;
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);