linux-i2c.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 2/2] V4L/DVB: Use custom I2C probing function mechanism
@ 2010-04-04 14:14 Jean Delvare
  2010-04-05  1:54 ` Andy Walls
  2010-04-05 18:26 ` Mauro Carvalho Chehab
  0 siblings, 2 replies; 12+ messages in thread
From: Jean Delvare @ 2010-04-04 14:14 UTC (permalink / raw)
  To: Linux I2C, LMML

Now that i2c-core offers the possibility to provide custom probing
function for I2C devices, let's make use of it.

Signed-off-by: Jean Delvare <khali-PUYAD+kWke1g9hUCZPvPmw@public.gmane.org>
---
I wasn't too sure where to put the custom probe function: in each driver,
in the ir-common module or in the v4l2-common module. I went for the
second option as a middle ground, but am ready to discuss it if anyone
objects.

 drivers/media/IR/ir-functions.c           |   12 ++++++++++++
 drivers/media/video/cx23885/cx23885-i2c.c |   14 +++-----------
 drivers/media/video/cx88/cx88-i2c.c       |   18 +++---------------
 include/media/ir-common.h                 |    5 +++++
 4 files changed, 23 insertions(+), 26 deletions(-)

--- linux-2.6.34-rc3.orig/drivers/media/video/cx23885/cx23885-i2c.c	2010-04-04 09:06:38.000000000 +0200
+++ linux-2.6.34-rc3/drivers/media/video/cx23885/cx23885-i2c.c	2010-04-04 13:34:34.000000000 +0200
@@ -28,6 +28,7 @@
 #include "cx23885.h"
 
 #include <media/v4l2-common.h>
+#include <media/ir-common.h>
 
 static unsigned int i2c_debug;
 module_param(i2c_debug, int, 0644);
@@ -365,17 +366,8 @@ int cx23885_i2c_register(struct cx23885_
 
 		memset(&info, 0, sizeof(struct i2c_board_info));
 		strlcpy(info.type, "ir_video", I2C_NAME_SIZE);
-		/*
-		 * We can't call i2c_new_probed_device() because it uses
-		 * quick writes for probing and the IR receiver device only
-		 * replies to reads.
-		 */
-		if (i2c_smbus_xfer(&bus->i2c_adap, addr_list[0], 0,
-				   I2C_SMBUS_READ, 0, I2C_SMBUS_QUICK,
-				   NULL) >= 0) {
-			info.addr = addr_list[0];
-			i2c_new_device(&bus->i2c_adap, &info);
-		}
+		i2c_new_probed_device(&bus->i2c_adap, &info, addr_list,
+				      ir_i2c_probe);
 	}
 
 	return bus->i2c_rc;
--- linux-2.6.34-rc3.orig/drivers/media/video/cx88/cx88-i2c.c	2010-04-04 09:06:38.000000000 +0200
+++ linux-2.6.34-rc3/drivers/media/video/cx88/cx88-i2c.c	2010-04-04 13:34:34.000000000 +0200
@@ -34,6 +34,7 @@
 
 #include "cx88.h"
 #include <media/v4l2-common.h>
+#include <media/ir-common.h>
 
 static unsigned int i2c_debug;
 module_param(i2c_debug, int, 0644);
@@ -188,24 +189,11 @@ int cx88_i2c_init(struct cx88_core *core
 			0x18, 0x6b, 0x71,
 			I2C_CLIENT_END
 		};
-		const unsigned short *addrp;
 
 		memset(&info, 0, sizeof(struct i2c_board_info));
 		strlcpy(info.type, "ir_video", I2C_NAME_SIZE);
-		/*
-		 * We can't call i2c_new_probed_device() because it uses
-		 * quick writes for probing and at least some R receiver
-		 * devices only reply to reads.
-		 */
-		for (addrp = addr_list; *addrp != I2C_CLIENT_END; addrp++) {
-			if (i2c_smbus_xfer(&core->i2c_adap, *addrp, 0,
-					   I2C_SMBUS_READ, 0,
-					   I2C_SMBUS_QUICK, NULL) >= 0) {
-				info.addr = *addrp;
-				i2c_new_device(&core->i2c_adap, &info);
-				break;
-			}
-		}
+		i2c_new_probed_device(&core->i2c_adap, &info, addr_list,
+				      ir_i2c_probe);
 	}
 	return core->i2c_rc;
 }
--- linux-2.6.34-rc3.orig/drivers/media/IR/ir-functions.c	2010-03-18 17:06:30.000000000 +0100
+++ linux-2.6.34-rc3/drivers/media/IR/ir-functions.c	2010-04-04 14:30:29.000000000 +0200
@@ -23,6 +23,7 @@
 #include <linux/module.h>
 #include <linux/string.h>
 #include <linux/jiffies.h>
+#include <linux/i2c.h>
 #include <media/ir-common.h>
 
 /* -------------------------------------------------------------------------- */
@@ -353,3 +354,14 @@ void ir_rc5_timer_keyup(unsigned long da
 	ir_input_nokey(ir->dev, &ir->ir);
 }
 EXPORT_SYMBOL_GPL(ir_rc5_timer_keyup);
+
+/* Some functions only needed for I2C devices */
+#if defined CONFIG_I2C || defined CONFIG_I2C_MODULE
+/* use quick read command for probe, some IR chips don't support writes */
+int ir_i2c_probe(struct i2c_adapter *i2c, unsigned short addr)
+{
+	return i2c_smbus_xfer(i2c, addr, 0, I2C_SMBUS_READ, 0,
+			      I2C_SMBUS_QUICK, NULL) >= 0;
+}
+EXPORT_SYMBOL_GPL(ir_i2c_probe);
+#endif
--- linux-2.6.34-rc3.orig/include/media/ir-common.h	2010-03-18 17:06:30.000000000 +0100
+++ linux-2.6.34-rc3/include/media/ir-common.h	2010-04-04 14:29:54.000000000 +0200
@@ -97,6 +97,11 @@ u32  ir_rc5_decode(unsigned int code);
 void ir_rc5_timer_end(unsigned long data);
 void ir_rc5_timer_keyup(unsigned long data);
 
+#if defined CONFIG_I2C || defined CONFIG_I2C_MODULE
+struct i2c_adapter;
+int ir_i2c_probe(struct i2c_adapter *i2c, unsigned short addr);
+#endif
+
 /* scancode->keycode map tables from ir-keymaps.c */
 
 extern struct ir_scancode_table ir_codes_empty_table;


-- 
Jean Delvare

^ permalink raw reply	[flat|nested] 12+ messages in thread
* [PATCH 2/2] V4L/DVB: Use custom I2C probing function mechanism
@ 2010-06-08  8:01 Jean Delvare
       [not found] ` <20100608100100.35bdae0f-ig7AzVSIIG7kN2dkZ6Wm7A@public.gmane.org>
  0 siblings, 1 reply; 12+ messages in thread
From: Jean Delvare @ 2010-06-08  8:01 UTC (permalink / raw)
  To: Linux I2C, LMML; +Cc: Mauro Carvalho Chehab

Now that i2c-core offers the possibility to provide custom probing
function for I2C devices, let's make use of it.

Signed-off-by: Jean Delvare <khali-PUYAD+kWke1g9hUCZPvPmw@public.gmane.org>
Acked-by: Mauro Carvalho Chehab <mchehab-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
---
 drivers/i2c/i2c-core.c                    |    7 +++++++
 drivers/media/video/cx23885/cx23885-i2c.c |   15 ++++-----------
 drivers/media/video/cx88/cx88-i2c.c       |   19 ++++---------------
 include/linux/i2c.h                       |    3 +++
 4 files changed, 18 insertions(+), 26 deletions(-)

--- linux-2.6.35-rc2.orig/drivers/media/video/cx23885/cx23885-i2c.c	2010-06-07 16:12:38.000000000 +0200
+++ linux-2.6.35-rc2/drivers/media/video/cx23885/cx23885-i2c.c	2010-06-08 09:17:06.000000000 +0200
@@ -365,17 +365,10 @@ int cx23885_i2c_register(struct cx23885_
 
 		memset(&info, 0, sizeof(struct i2c_board_info));
 		strlcpy(info.type, "ir_video", I2C_NAME_SIZE);
-		/*
-		 * We can't call i2c_new_probed_device() because it uses
-		 * quick writes for probing and the IR receiver device only
-		 * replies to reads.
-		 */
-		if (i2c_smbus_xfer(&bus->i2c_adap, addr_list[0], 0,
-				   I2C_SMBUS_READ, 0, I2C_SMBUS_QUICK,
-				   NULL) >= 0) {
-			info.addr = addr_list[0];
-			i2c_new_device(&bus->i2c_adap, &info);
-		}
+		/* Use quick read command for probe, some IR chips don't
+		 * support writes */
+		i2c_new_probed_device(&bus->i2c_adap, &info, addr_list,
+				      i2c_probe_func_quick_read);
 	}
 
 	return bus->i2c_rc;
--- linux-2.6.35-rc2.orig/drivers/media/video/cx88/cx88-i2c.c	2010-06-07 16:12:38.000000000 +0200
+++ linux-2.6.35-rc2/drivers/media/video/cx88/cx88-i2c.c	2010-06-08 09:17:06.000000000 +0200
@@ -188,24 +188,13 @@ int cx88_i2c_init(struct cx88_core *core
 			0x18, 0x6b, 0x71,
 			I2C_CLIENT_END
 		};
-		const unsigned short *addrp;
 
 		memset(&info, 0, sizeof(struct i2c_board_info));
 		strlcpy(info.type, "ir_video", I2C_NAME_SIZE);
-		/*
-		 * We can't call i2c_new_probed_device() because it uses
-		 * quick writes for probing and at least some R receiver
-		 * devices only reply to reads.
-		 */
-		for (addrp = addr_list; *addrp != I2C_CLIENT_END; addrp++) {
-			if (i2c_smbus_xfer(&core->i2c_adap, *addrp, 0,
-					   I2C_SMBUS_READ, 0,
-					   I2C_SMBUS_QUICK, NULL) >= 0) {
-				info.addr = *addrp;
-				i2c_new_device(&core->i2c_adap, &info);
-				break;
-			}
-		}
+		/* Use quick read command for probe, some IR chips don't
+		 * support writes */
+		i2c_new_probed_device(&core->i2c_adap, &info, addr_list,
+				      i2c_probe_func_quick_read);
 	}
 	return core->i2c_rc;
 }
--- linux-2.6.35-rc2.orig/drivers/i2c/i2c-core.c	2010-06-07 16:12:38.000000000 +0200
+++ linux-2.6.35-rc2/drivers/i2c/i2c-core.c	2010-06-08 09:17:06.000000000 +0200
@@ -1453,6 +1453,13 @@ static int i2c_detect(struct i2c_adapter
 	return err;
 }
 
+int i2c_probe_func_quick_read(struct i2c_adapter *adap, unsigned short addr)
+{
+	return i2c_smbus_xfer(adap, addr, 0, I2C_SMBUS_READ, 0,
+			      I2C_SMBUS_QUICK, NULL) >= 0;
+}
+EXPORT_SYMBOL_GPL(i2c_probe_func_quick_read);
+
 struct i2c_client *
 i2c_new_probed_device(struct i2c_adapter *adap,
 		      struct i2c_board_info *info,
--- linux-2.6.35-rc2.orig/include/linux/i2c.h	2010-06-07 16:15:10.000000000 +0200
+++ linux-2.6.35-rc2/include/linux/i2c.h	2010-06-08 09:19:07.000000000 +0200
@@ -292,6 +292,9 @@ i2c_new_probed_device(struct i2c_adapter
 		      unsigned short const *addr_list,
 		      int (*probe)(struct i2c_adapter *, unsigned short addr));
 
+/* Common custom probe functions */
+extern int i2c_probe_func_quick_read(struct i2c_adapter *, unsigned short addr);
+
 /* For devices that use several addresses, use i2c_new_dummy() to make
  * client handles for the extra addresses.
  */


-- 
Jean Delvare

^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2010-06-09 17:39 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-04-04 14:14 [PATCH 2/2] V4L/DVB: Use custom I2C probing function mechanism Jean Delvare
2010-04-05  1:54 ` Andy Walls
     [not found]   ` <1270432479.3506.31.camel-xioobY1GIEhKttHedORAlB2eb7JE58TQ@public.gmane.org>
2010-04-05  8:30     ` Jean Delvare
2010-04-05 18:26 ` Mauro Carvalho Chehab
     [not found]   ` <4BBA2B58.4000007-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2010-04-05 21:06     ` Jean Delvare
     [not found]       ` <20100405230616.443792ac-ig7AzVSIIG7kN2dkZ6Wm7A@public.gmane.org>
2010-04-06  5:34         ` Mauro Carvalho Chehab
     [not found]           ` <4BBAC7F6.5030807-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2010-04-06 16:25             ` Jean Delvare
     [not found]               ` <20100406182511.62894659-ig7AzVSIIG7kN2dkZ6Wm7A@public.gmane.org>
2010-04-09  4:09                 ` Mauro Carvalho Chehab
     [not found]                   ` <4BBEA864.9090702-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2010-04-09  7:12                     ` Jean Delvare
  -- strict thread matches above, loose matches on Subject: below --
2010-06-08  8:01 Jean Delvare
     [not found] ` <20100608100100.35bdae0f-ig7AzVSIIG7kN2dkZ6Wm7A@public.gmane.org>
2010-06-09 15:05   ` Wolfram Sang
     [not found]     ` <20100609150540.GB31319-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org>
2010-06-09 17:39       ` Jean Delvare

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).