Return only IIC_Exxxx status values from iicbus-layer functions. Most of

these functions are thin wrappers around calling the hardware-layer driver,
but some of them do sanity checks and return an error.  Since the hardware
layer can only return IIC_Exxxxx status values, the iicbus helper functions
must also adhere to that, so that drivers at higher layers can assume that
any non-zero status value is an IIC_Exxxx value that provides details about
what happened at the hardware layer (sometimes those details are important
for certain slave drivers).
This commit is contained in:
ian 2015-10-09 23:58:19 +00:00
parent bf3b00c72d
commit 2234128067
2 changed files with 22 additions and 7 deletions

View File

@ -207,7 +207,7 @@ iicbus_start(device_t bus, u_char slave, int timeout)
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;
@ -229,7 +229,7 @@ iicbus_repeated_start(device_t bus, u_char slave, int timeout)
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;
@ -251,7 +251,7 @@ iicbus_stop(device_t bus)
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));
@ -274,7 +274,7 @@ iicbus_write(device_t bus, const char *buf, int len, int *sent, int timeout)
/* 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));
}
@ -292,7 +292,7 @@ iicbus_read(device_t bus, char *buf, int len, int *read, int last, int delay)
/* 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));
}
@ -305,9 +305,14 @@ iicbus_read(device_t bus, char *buf, int len, int *read, int last, int 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));
}
@ -319,8 +324,13 @@ iicbus_write_byte(device_t bus, char byte, int 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));
}
@ -381,6 +391,7 @@ iicbus_block_read(device_t bus, u_char slave, char *buf, int len, int *read)
int
iicbus_transfer(device_t bus, struct iic_msg *msgs, uint32_t nmsgs)
{
return (IICBUS_TRANSFER(device_get_parent(bus), msgs, nmsgs));
}
@ -397,10 +408,10 @@ iicbus_transfer_gen(device_t dev, struct iic_msg *msgs, uint32_t 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;

View File

@ -93,6 +93,10 @@
#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);