Add iic2errno(), a helper function to translate IIC_Exxxxx status values to

errno values that are at least vaguely equivelent.  Also add a new status
value, IIC_ERESOURCE, to indicate a failure to acquire memory or other
required resources to complete a transaction.

The IIC_Exxxxxx values are supposed to communicate low-level details of the
i2c transaction status between the lowest-layer hardware driver and
higher-layer bus protocol and device drivers for slave devices on the bus.
Most of those slave drivers just return all status values from the lower
layers directly to their callers, resulting in crazy error reporting from a
user's point of view (things like timeouts being reported as "no such
process").  Now there's a helper function to make it easier to start
cleaning up all those drivers.
This commit is contained in:
Ian Lepore 2015-10-09 23:20:08 +00:00
parent 4b3d93d38a
commit df38292a85
2 changed files with 24 additions and 0 deletions

View File

@ -39,6 +39,28 @@ __FBSDID("$FreeBSD$");
#include <dev/iicbus/iicbus.h>
#include "iicbus_if.h"
/*
* Translate IIC_Exxxxx status values to vaguely-equivelent errno values.
*/
int
iic2errno(int iic_status)
{
switch (iic_status) {
case IIC_NOERR: return (0);
case IIC_EBUSERR: return (EALREADY);
case IIC_ENOACK: return (EIO);
case IIC_ETIMEOUT: return (ETIMEDOUT);
case IIC_EBUSBSY: return (EWOULDBLOCK);
case IIC_ESTATUS: return (EPROTO);
case IIC_EUNDERFLOW: return (EIO);
case IIC_EOVERFLOW: return (EOVERFLOW);
case IIC_ENOTSUPP: return (EOPNOTSUPP);
case IIC_ENOADDR: return (EADDRNOTAVAIL);
case IIC_ERESOURCE: return (ENOMEM);
default: return (EIO);
}
}
/*
* iicbus_intr()
*/

View File

@ -91,7 +91,9 @@
#define IIC_EOVERFLOW 0x7 /* too much data */
#define IIC_ENOTSUPP 0x8 /* request not supported */
#define IIC_ENOADDR 0x9 /* no address assigned to the interface */
#define IIC_ERESOURCE 0xa /* resources (memory, whatever) unavailable */
extern int iic2errno(int);
extern int iicbus_request_bus(device_t, device_t, int);
extern int iicbus_release_bus(device_t, device_t);
extern device_t iicbus_alloc_bus(device_t);