Lines Matching +full:read +full:- +full:delay
1 /*-
2 * SPDX-License-Identifier: BSD-2-Clause
4 * Copyright (C) 2008-2009 Semihalf, Michal Hajduk
56 #define I2C_ENABLE 0x80 /* Module enable - interrupt disable */
62 #define I2CSR_SRW (1<<2) /* Slave read/write */
97 static int i2c_read(device_t dev, char *buf, int len, int *read, int last, int delay);
130 bus_space_write_1(sc->bst, sc->bsh, off, val); in i2c_write_reg()
137 return (bus_space_read_1(sc->bst, sc->bsh, off)); in i2c_read_reg()
189 if (!ofw_bus_is_compatible(dev, "fsl-i2c")) in i2c_probe()
193 sc->rid = 0; in i2c_probe()
195 sc->res = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &sc->rid, in i2c_probe()
197 if (sc->res == NULL) { in i2c_probe()
202 sc->bst = rman_get_bustag(sc->res); in i2c_probe()
203 sc->bsh = rman_get_bushandle(sc->res); in i2c_probe()
207 bus_release_resource(dev, SYS_RES_MEMORY, sc->rid, sc->res); in i2c_probe()
219 sc->dev = dev; in i2c_attach()
220 sc->rid = 0; in i2c_attach()
222 mtx_init(&sc->mutex, device_get_nameunit(dev), "I2C", MTX_DEF); in i2c_attach()
224 sc->res = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &sc->rid, in i2c_attach()
226 if (sc->res == NULL) { in i2c_attach()
228 mtx_destroy(&sc->mutex); in i2c_attach()
232 sc->bst = rman_get_bustag(sc->res); in i2c_attach()
233 sc->bsh = rman_get_bushandle(sc->res); in i2c_attach()
235 sc->iicbus = device_add_child(dev, "iicbus", DEVICE_UNIT_ANY); in i2c_attach()
236 if (sc->iicbus == NULL) { in i2c_attach()
238 mtx_destroy(&sc->mutex); in i2c_attach()
253 mtx_lock(&sc->mutex); in i2c_repeated_start()
256 /* Write target address - LSB is R/W bit */ in i2c_repeated_start()
258 DELAY(1250); in i2c_repeated_start()
261 mtx_unlock(&sc->mutex); in i2c_repeated_start()
277 DELAY(1000); in i2c_start()
279 mtx_lock(&sc->mutex); in i2c_start()
284 mtx_unlock(&sc->mutex); in i2c_start()
291 /* Write target address - LSB is R/W bit */ in i2c_start()
293 DELAY(1250); in i2c_start()
297 mtx_unlock(&sc->mutex); in i2c_start()
310 mtx_lock(&sc->mutex); in i2c_stop()
312 DELAY(1000); in i2c_stop()
313 mtx_unlock(&sc->mutex); in i2c_stop()
338 mtx_lock(&sc->mutex); in i2c_reset()
341 DELAY(1000); in i2c_reset()
345 DELAY(1000); in i2c_reset()
346 mtx_unlock(&sc->mutex); in i2c_reset()
352 i2c_read(device_t dev, char *buf, int len, int *read, int last, int delay) in i2c_read() argument
358 *read = 0; in i2c_read()
360 mtx_lock(&sc->mutex); in i2c_read()
370 /* dummy read */ in i2c_read()
372 DELAY(1000); in i2c_read()
375 while (*read < len) { in i2c_read()
376 DELAY(1000); in i2c_read()
379 mtx_unlock(&sc->mutex); in i2c_read()
382 if ((*read == len - 2) && last) { in i2c_read()
387 if ((*read == len - 1) && last) { in i2c_read()
393 (*read)++; in i2c_read()
394 DELAY(1250); in i2c_read()
396 mtx_unlock(&sc->mutex); in i2c_read()
410 mtx_lock(&sc->mutex); in i2c_write()
413 DELAY(1250); in i2c_write()
417 mtx_unlock(&sc->mutex); in i2c_write()
423 mtx_unlock(&sc->mutex); in i2c_write()