svn commit: r289095 - head/sys/dev/iicbus

Ian Lepore ian at FreeBSD.org
Fri Oct 9 23:20:09 UTC 2015


Author: ian
Date: Fri Oct  9 23:20:08 2015
New Revision: 289095
URL: https://svnweb.freebsd.org/changeset/base/289095

Log:
  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.

Modified:
  head/sys/dev/iicbus/iiconf.c
  head/sys/dev/iicbus/iiconf.h

Modified: head/sys/dev/iicbus/iiconf.c
==============================================================================
--- head/sys/dev/iicbus/iiconf.c	Fri Oct  9 23:19:29 2015	(r289094)
+++ head/sys/dev/iicbus/iiconf.c	Fri Oct  9 23:20:08 2015	(r289095)
@@ -40,6 +40,28 @@ __FBSDID("$FreeBSD$");
 #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()
  */
 void

Modified: head/sys/dev/iicbus/iiconf.h
==============================================================================
--- head/sys/dev/iicbus/iiconf.h	Fri Oct  9 23:19:29 2015	(r289094)
+++ head/sys/dev/iicbus/iiconf.h	Fri Oct  9 23:20:08 2015	(r289095)
@@ -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);


More information about the svn-src-all mailing list