static int iicread(dev_t dev, struct uio * uio, int ioflag) { device_t iicdev = IIC_DEVICE(minor(dev)); struct iic_softc *sc = IIC_SOFTC(minor(dev)); int len, error = 0; int bufsize; if (!sc || !iicdev || !sc->sc_addr) return (EINVAL); if (sc->sc_count == 0) return (EINVAL); if ((error = iicbus_request_bus(device_get_parent(iicdev), iicdev, IIC_DONTWAIT))) return (error); /* max amount of data to read */ len = min(uio->uio_resid, BUFSIZE); if ((error = iicbus_block_read(device_get_parent(iicdev), sc->sc_addr, sc->sc_inbuf, len, &bufsize))) return (error); if (bufsize > uio->uio_resid) panic("%s: too much data read!", __func__); iicbus_release_bus(device_get_parent(iicdev), iicdev); return (uiomove(sc->sc_inbuf, bufsize, uio)); }
static int iic_probe_device(device_t dev, u_char addr) { int count; char byte; if ((addr & 1) == 0) { /* is device writable? */ if (!iicbus_start(dev, (u_char)addr, 0)) { iicbus_stop(dev); return (1); } } else { /* is device readable? */ if (!iicbus_block_read(dev, (u_char)addr, &byte, 1, &count)) return (1); } return (0); }
/* * Generic version of iicbus_transfer that calls the appropriate * routines to accomplish this. See note above about acceptable * buffer addresses. */ int iicbus_transfer_gen(device_t dev, struct iic_msg *msgs, uint32_t nmsgs) { int i, error, lenread, lenwrote, nkid; device_t *children, bus; if ((error = device_get_children(dev, &children, &nkid)) != 0) return (error); if (nkid != 1) { free(children, M_TEMP); return (EIO); } bus = children[0]; free(children, M_TEMP); for (i = 0, error = 0; i < nmsgs && error == 0; i++) { if (msgs[i].flags & IIC_M_RD) error = iicbus_block_read(bus, msgs[i].slave, msgs[i].buf, msgs[i].len, &lenread); else error = iicbus_block_write(bus, msgs[i].slave, msgs[i].buf, msgs[i].len, &lenwrote); } return (error); }