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

1 /*-
2 * SPDX-License-Identifier: BSD-2-Clause
4 * Copyright (C) 2008-2009 Semihalf, Michal Hajduk
50 #define I2C_ADDR_REG 0x00 /* I2C slave address register */
51 #define I2C_FDR_REG 0x04 /* I2C frequency divider register */
52 #define I2C_CONTROL_REG 0x08 /* I2C control register */
53 #define I2C_STATUS_REG 0x0C /* I2C status register */
54 #define I2C_DATA_REG 0x10 /* I2C data register */
55 #define I2C_DFSRR_REG 0x14 /* I2C Digital Filter Sampling rate */
56 #define I2C_ENABLE 0x80 /* Module enable - interrupt disable */
59 #define I2CSR_MASS (1<<6) /* Addressed as a slave */
62 #define I2CSR_SRW (1<<2) /* Slave read/write */
65 #define I2CCR_MSTA (1<<5) /* Master/slave mode */
93 static int i2c_repeated_start(device_t dev, u_char slave, int timeout);
94 static int i2c_start(device_t dev, u_char slave, int timeout);
96 static int i2c_reset(device_t dev, u_char speed, u_char addr, u_char *oldaddr);
123 DRIVER_MODULE(i2c, simplebus, i2c_driver, 0, 0);
124 DRIVER_MODULE(iicbus, i2c, iicbus_driver, 0, 0);
130 bus_space_write_1(sc->bst, sc->bsh, off, val);
137 return (bus_space_read_1(sc->bst, sc->bsh, off));
160 "after sending slave address" : "");
189 if (!ofw_bus_is_compatible(dev, "fsl-i2c"))
193 sc->rid = 0;
195 sc->res = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &sc->rid,
197 if (sc->res == NULL) {
202 sc->bst = rman_get_bustag(sc->res);
203 sc->bsh = rman_get_bushandle(sc->res);
205 /* Enable I2C */
207 bus_release_resource(dev, SYS_RES_MEMORY, sc->rid, sc->res);
208 device_set_desc(dev, "I2C bus controller");
219 sc->dev = dev;
220 sc->rid = 0;
222 mtx_init(&sc->mutex, device_get_nameunit(dev), "I2C", MTX_DEF);
224 sc->res = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &sc->rid,
226 if (sc->res == NULL) {
228 mtx_destroy(&sc->mutex);
232 sc->bst = rman_get_bustag(sc->res);
233 sc->bsh = rman_get_bushandle(sc->res);
235 sc->iicbus = device_add_child(dev, "iicbus", DEVICE_UNIT_ANY);
236 if (sc->iicbus == NULL) {
238 mtx_destroy(&sc->mutex);
246 i2c_repeated_start(device_t dev, u_char slave, int timeout)
253 mtx_lock(&sc->mutex);
256 /* Write target address - LSB is R/W bit */
257 i2c_write_reg(sc, I2C_DATA_REG, slave);
261 mtx_unlock(&sc->mutex);
270 i2c_start(device_t dev, u_char slave, int timeout)
279 mtx_lock(&sc->mutex);
284 mtx_unlock(&sc->mutex);
291 /* Write target address - LSB is R/W bit */
292 i2c_write_reg(sc, I2C_DATA_REG, slave);
297 mtx_unlock(&sc->mutex);
310 mtx_lock(&sc->mutex);
313 mtx_unlock(&sc->mutex);
319 i2c_reset(device_t dev, u_char speed, u_char addr, u_char *oldadr)
338 mtx_lock(&sc->mutex);
346 mtx_unlock(&sc->mutex);
360 mtx_lock(&sc->mutex);
379 mtx_unlock(&sc->mutex);
382 if ((*read == len - 2) && last) {
387 if ((*read == len - 1) && last) {
396 mtx_unlock(&sc->mutex);
410 mtx_lock(&sc->mutex);
417 mtx_unlock(&sc->mutex);
423 mtx_unlock(&sc->mutex);