[PATCH 03/18] compat: backport __i2c_transfer()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: "Luis R. Rodriguez" <mcgrof@xxxxxxxxxxxxxxxx>

mcgrof@frijol ~/linux-stable (git::master)$ git describe --contains b37d2a3a
v3.6-rc1~28^2~265

commit b37d2a3a75cb0e72e18c29336cb2095b63dabfc8
Author: Jean Delvare <khali@xxxxxxxxxxxx>
Date:   Fri Jun 29 07:47:19 2012 -0300

    [media] i2c: Export an unlocked flavor of i2c_transfer

    Some drivers (in particular for TV cards) need exclusive access to
    their I2C buses for specific operations. Export an unlocked flavor
    of i2c_transfer to give them full control.

    The unlocked flavor has the following limitations:
    * Obviously, caller must hold the i2c adapter lock.
    * No debug messages are logged. We don't want to log messages while
      holding a rt_mutex.
    * No check is done on the existence of adap->algo->master_xfer. It
      is thus the caller's responsibility to ensure that the function is
      OK to call.

    Signed-off-by: Jean Delvare <khali@xxxxxxxxxxxx>
    Signed-off-by: Mauro Carvalho Chehab <mchehab@xxxxxxxxxx>

Signed-off-by: Luis R. Rodriguez <mcgrof@xxxxxxxxxxxxxxxx>
---
 backport/compat/compat-3.6.c        |   34 ++++++++++++++++++++++++++++++++++
 backport/include/linux/compat-3.6.h |    9 +++++++++
 2 files changed, 43 insertions(+)

diff --git a/backport/compat/compat-3.6.c b/backport/compat/compat-3.6.c
index a50fc98..05954d4 100644
--- a/backport/compat/compat-3.6.c
+++ b/backport/compat/compat-3.6.c
@@ -13,6 +13,40 @@
 #include <linux/export.h>
 #include <linux/bug.h>
 #include <linux/bitmap.h>
+#include <linux/i2c.h>
+
+#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,2,0))
+/**
+ * __i2c_transfer - unlocked flavor of i2c_transfer
+ * @adap: Handle to I2C bus
+ * @msgs: One or more messages to execute before STOP is issued to
+ *     terminate the operation; each message begins with a START.
+ * @num: Number of messages to be executed.
+ *
+ * Returns negative errno, else the number of messages executed.
+ *
+ * Adapter lock must be held when calling this function. No debug logging
+ * takes place. adap->algo->master_xfer existence isn't checked.
+ */
+int __i2c_transfer(struct i2c_adapter *adap, struct i2c_msg *msgs, int num)
+{
+	unsigned long orig_jiffies;
+	int ret, try;
+
+	/* Retry automatically on arbitration loss */
+	orig_jiffies = jiffies;
+	for (ret = 0, try = 0; try <= adap->retries; try++) {
+		ret = adap->algo->master_xfer(adap, msgs, num);
+		if (ret != -EAGAIN)
+			break;
+		if (time_after(jiffies, orig_jiffies + adap->timeout))
+			break;
+	}
+
+	return ret;
+}
+EXPORT_SYMBOL(__i2c_transfer);
+#endif
 
 /**
  * memweight - count the total number of bits set in memory area
diff --git a/backport/include/linux/compat-3.6.h b/backport/include/linux/compat-3.6.h
index bef0503..8fddd31 100644
--- a/backport/include/linux/compat-3.6.h
+++ b/backport/include/linux/compat-3.6.h
@@ -7,6 +7,15 @@
 
 #include <linux/scatterlist.h>
 
+#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,2,0))
+#include <linux/i2c.h>
+/* Unlocked flavor */
+#define __i2c_transfer LINUX_BACKPORT(__i2c_transfer)
+extern int __i2c_transfer(struct i2c_adapter *adap, struct i2c_msg *msgs,
+			  int num);
+#endif
+
+
 #define memweight LINUX_BACKPORT(memweight)
 extern size_t memweight(const void *ptr, size_t bytes);
 
-- 
1.7.10.4

--
To unsubscribe from this list: send the line "unsubscribe backports" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html




[Index of Archives]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Security]     [Bugtraq]     [Linux]     [Linux OMAP]     [Linux MIPS]     [ECOS]     [Asterisk Internet PBX]     [Linux API]

  Powered by Linux