Lines Matching refs:sc

139 clear_ipend(struct i2c_softc *sc)
143 reg = READ1(sc, I2CCON);
145 WRITE1(sc, I2CCON, reg);
153 struct i2c_softc *sc;
156 sc = device_get_softc(dev);
157 sc->dev = dev;
159 mtx_init(&sc->mutex, device_get_nameunit(dev), "I2C", MTX_DEF);
161 if (bus_alloc_resources(dev, i2c_spec, sc->res)) {
167 sc->bst = rman_get_bustag(sc->res[0]);
168 sc->bsh = rman_get_bushandle(sc->res[0]);
170 sc->iicbus = device_add_child(dev, "iicbus", -1);
171 if (sc->iicbus == NULL) {
173 mtx_destroy(&sc->mutex);
177 WRITE1(sc, I2CSTAT, 0);
178 WRITE1(sc, I2CADD, 0x00);
183 WRITE1(sc, I2CSTAT, reg);
191 wait_for_iif(struct i2c_softc *sc)
198 reg = READ1(sc, I2CCON);
209 wait_for_nibb(struct i2c_softc *sc)
215 if ((READ1(sc, I2CSTAT) & I2CSTAT_BSY) == 0)
224 is_ack(struct i2c_softc *sc)
228 stat = READ1(sc, I2CSTAT);
240 struct i2c_softc *sc;
244 sc = device_get_softc(dev);
248 mtx_lock(&sc->mutex);
251 DPRINTF("I2CCON == 0x%08x\n", READ1(sc, I2CCON));
252 DPRINTF("I2CSTAT == 0x%08x\n", READ1(sc, I2CSTAT));
263 error = wait_for_nibb(sc);
265 mtx_unlock(&sc->mutex);
270 reg = READ1(sc, I2CCON);
272 WRITE1(sc, I2CCON, reg);
274 WRITE1(sc, I2CDS, slave);
280 WRITE1(sc, I2CSTAT, reg);
282 error = wait_for_iif(sc);
286 mtx_unlock(&sc->mutex);
290 if (!is_ack(sc)) {
293 mtx_unlock(&sc->mutex);
297 mtx_unlock(&sc->mutex);
304 struct i2c_softc *sc;
308 sc = device_get_softc(dev);
312 mtx_lock(&sc->mutex);
314 reg = READ1(sc, I2CSTAT);
319 WRITE1(sc, I2CSTAT, reg);
321 clear_ipend(sc);
323 error = wait_for_nibb(sc);
329 mtx_unlock(&sc->mutex);
336 struct i2c_softc *sc;
338 sc = device_get_softc(dev);
342 mtx_lock(&sc->mutex);
346 mtx_unlock(&sc->mutex);
355 struct i2c_softc *sc;
360 sc = device_get_softc(dev);
367 WRITE1(sc, I2CSTAT, reg);
370 mtx_lock(&sc->mutex);
373 clear_ipend(sc);
374 error = wait_for_iif(sc);
377 mtx_unlock(&sc->mutex);
380 READ1(sc, I2CDS);
387 reg = READ1(sc, I2CCON);
389 WRITE1(sc, I2CCON, reg);
392 clear_ipend(sc);
394 error = wait_for_iif(sc);
397 mtx_unlock(&sc->mutex);
401 d = READ1(sc, I2CDS);
408 mtx_unlock(&sc->mutex);
415 struct i2c_softc *sc;
418 sc = device_get_softc(dev);
424 mtx_lock(&sc->mutex);
431 WRITE1(sc, I2CDS, d);
434 clear_ipend(sc);
436 error = wait_for_iif(sc);
439 mtx_unlock(&sc->mutex);
443 if (!is_ack(sc)) {
445 mtx_unlock(&sc->mutex);
453 mtx_unlock(&sc->mutex);