int error = 0;
if (sc->started)
- return (EINVAL); /* bus already started */
+ return (IIC_ESTATUS); /* protocol error, bus already started */
if (!(error = IICBUS_START(device_get_parent(bus), slave, timeout)))
sc->started = slave;
int error = 0;
if (!sc->started)
- return (EINVAL); /* bus should have been already started */
+ return (IIC_ESTATUS); /* protocol error, bus not started */
if (!(error = IICBUS_REPEATED_START(device_get_parent(bus), slave, timeout)))
sc->started = slave;
int error = 0;
if (!sc->started)
- return (EINVAL); /* bus not started */
+ return (IIC_ESTATUS); /* protocol error, bus not started */
error = IICBUS_STOP(device_get_parent(bus));
/* a slave must have been started for writing */
if (sc->started == 0 || (sc->strict != 0 && (sc->started & LSB) != 0))
- return (EINVAL);
+ return (IIC_ESTATUS);
return (IICBUS_WRITE(device_get_parent(bus), buf, len, sent, timeout));
}
/* a slave must have been started for reading */
if (sc->started == 0 || (sc->strict != 0 && (sc->started & LSB) == 0))
- return (EINVAL);
+ return (IIC_ESTATUS);
return (IICBUS_READ(device_get_parent(bus), buf, len, read, last, delay));
}
int
iicbus_write_byte(device_t bus, char byte, int timeout)
{
+ struct iicbus_softc *sc = device_get_softc(bus);
char data = byte;
int sent;
+ /* a slave must have been started for writing */
+ if (sc->started == 0 || (sc->strict != 0 && (sc->started & LSB) != 0))
+ return (IIC_ESTATUS);
+
return (iicbus_write(bus, &data, 1, &sent, timeout));
}
int
iicbus_read_byte(device_t bus, char *byte, int timeout)
{
+ struct iicbus_softc *sc = device_get_softc(bus);
int read;
+ /* a slave must have been started for reading */
+ if (sc->started == 0 || (sc->strict != 0 && (sc->started & LSB) == 0))
+ return (IIC_ESTATUS);
+
return (iicbus_read(bus, byte, 1, &read, IIC_LAST_READ, timeout));
}
int
iicbus_transfer(device_t bus, struct iic_msg *msgs, uint32_t nmsgs)
{
+
return (IICBUS_TRANSFER(device_get_parent(bus), msgs, nmsgs));
}
bool nostop;
if ((error = device_get_children(dev, &children, &nkid)) != 0)
- return (error);
+ return (IIC_ERESOURCE);
if (nkid != 1) {
free(children, M_TEMP);
- return (EIO);
+ return (IIC_ENOTSUPP);
}
bus = children[0];
rpstart = 0;
#define IIC_ENOADDR 0x9 /* no address assigned to the interface */
#define IIC_ERESOURCE 0xa /* resources (memory, whatever) unavailable */
+/*
+ * Note that all iicbus functions return IIC_Exxxxx status values,
+ * except iic2errno() (obviously) and iicbus_started() (returns bool).
+ */
extern int iic2errno(int);
extern int iicbus_request_bus(device_t, device_t, int);
extern int iicbus_release_bus(device_t, device_t);