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

1 /*-
2 * SPDX-License-Identifier: BSD-2-Clause
59 uint8_t addr;
64 uint16_t slave;
71 u_char slave;
87 #define IIC_LOCK(cdp) sx_xlock(&(cdp)->lock)
88 #define IIC_UNLOCK(cdp) sx_xunlock(&(cdp)->lock)
136 if (device_find_child(parent, "iic", -1) == NULL)
157 sc->sc_dev = dev;
158 sc->sc_devnode = make_dev(&iic_cdevsw, device_get_unit(dev),
161 if (sc->sc_devnode == NULL) {
165 sc->sc_devnode->si_drv1 = sc;
177 if (sc->sc_devnode)
178 destroy_dev(sc->sc_devnode);
191 sx_init(&priv->lock, "iic");
192 priv->sc = dev->si_drv1;
210 iicdev = priv->sc->sc_dev;
213 if (priv->started) {
219 sx_destroy(&priv->lock);
230 parent = device_get_parent(priv->sc->sc_dev);
237 while ((error == 0) && (uio->uio_resid > 0)) {
239 num_bytes = MIN(uio->uio_resid, sizeof(buffer));
242 switch (uio->uio_rw) {
249 num_bytes - transferred_bytes, &written_bytes, 0);
256 ((uio->uio_resid <= sizeof(buffer)) ? last : 0), 0);
272 uint8_t addr;
282 if (priv->started || (priv->addr == 0)) {
286 parent = device_get_parent(priv->sc->sc_dev);
288 error = iicbus_request_bus(parent, priv->sc->sc_dev,
295 switch (uio->uio_rw) {
297 addr = priv->addr | LSB;
300 addr = priv->addr & ~LSB;
304 error = iicbus_start(parent, addr, 0);
307 iicbus_release_bus(parent, priv->sc->sc_dev);
315 iicbus_release_bus(parent, priv->sc->sc_dev);
328 m32 = (struct iic_msg32 *)d->msgs;
329 for (i = 0; i < d->nmsgs; i++) {
333 CP(msg32, buf[i], slave);
356 iicdev = priv->sc->sc_dev;
368 if (d->nmsgs > IIC_RDRW_MAX_MSGS)
371 buf = malloc(sizeof(*d->msgs) * d->nmsgs, M_IIC, M_WAITOK);
378 error = copyin(d->msgs, buf, sizeof(*d->msgs) * d->nmsgs);
385 usrbufs = malloc(sizeof(void *) * d->nmsgs, M_IIC, M_WAITOK | M_ZERO);
387 for (i = 0; i < d->nmsgs; i++) {
389 usrbufs[i] = m->buf;
393 * If the copyin() to buf failed, don't try to malloc bogus m->len.
395 m->buf = NULL;
399 /* m->len is uint16_t, so allocation size is capped at 64K. */
400 m->buf = malloc(m->len, M_IIC, M_WAITOK);
401 if (!(m->flags & IIC_M_RD))
402 error = copyin(usrbufs[i], m->buf, m->len);
410 error = iicbus_transfer(iicdev, buf, d->nmsgs);
415 for (i = 0; i < d->nmsgs; i++) {
417 if ((error == 0) && (m->flags & IIC_M_RD))
418 error = copyout(m->buf, usrbufs[i], m->len);
419 free(m->buf, M_IIC);
454 iicdev = priv->sc->sc_dev;
462 CP(*s32, iicswab, slave);
475 if (priv->started) {
483 error = iicbus_start(parent, s->slave, 0);
486 priv->addr = s->slave;
487 priv->started = true;
494 if (priv->started) {
497 priv->started = false;
505 * We allow the bus to be already owned as the result of an in-progress
508 if (!priv->started)
515 * Ignore IIC_ENOADDR as it only means we have a master-only
522 priv->started = false;
530 if (!priv->started) {
534 uvec.iov_base = s->buf;
535 uvec.iov_len = s->count;
540 ubuf.uio_resid = s->count;
550 if (!priv->started) {
554 uvec.iov_base = s->buf;
555 uvec.iov_len = s->count;
560 ubuf.uio_resid = s->count;
563 error = iicuio_move(priv, &ubuf, s->last);
571 * The rdwr list should be a self-contained set of
574 if (priv->started) {
590 if (!priv->started) {
594 error = iicbus_repeated_start(parent, s->slave, 0);
598 priv->addr = *((uint8_t*)data);