Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 9 Oct 2015 23:58:19 +0000 (UTC)
From:      Ian Lepore <ian@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r289097 - head/sys/dev/iicbus
Message-ID:  <201510092358.t99NwJnm057572@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: ian
Date: Fri Oct  9 23:58:19 2015
New Revision: 289097
URL: https://svnweb.freebsd.org/changeset/base/289097

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

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:57:07 2015	(r289096)
+++ head/sys/dev/iicbus/iiconf.c	Fri Oct  9 23:58:19 2015	(r289097)
@@ -207,7 +207,7 @@ iicbus_start(device_t bus, u_char slave,
 	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_ch
 	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 *b
 	
 	/* 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
 	
 	/* 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
 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 byt
 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 s
 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
 	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;

Modified: head/sys/dev/iicbus/iiconf.h
==============================================================================
--- head/sys/dev/iicbus/iiconf.h	Fri Oct  9 23:57:07 2015	(r289096)
+++ head/sys/dev/iicbus/iiconf.h	Fri Oct  9 23:58:19 2015	(r289097)
@@ -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);



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201510092358.t99NwJnm057572>