Skip to contentSkip to conversation

add i2c_clients_command()

PATCH In review Gerd Knorr 2 participants 3 messages Apr 2, 2003 – Apr 3, 2003 I2C

lore
Share & tools
lore

Gerd Knorr

author
#0 lore raw

PATCH 1/1 add i2c_clients_command()

Hi,

This patch adds a function which loops over all i2c clients attached to some i2c adapter and calls the ->command function of the driver.

Currently the bttv and saa7134 drivers have simliar functions, but (currently) without sane locking and module handling. Newer versions will switch to this function. Updates for the two drivers which are actually using this new function are available from
http://bytesex.org/patches/wip/

Gerd

drivers/i2c/i2c-core.c +22 -0
diff -u linux-2.5.66/drivers/i2c/i2c-core.c linux/drivers/i2c/i2c-core.c
@@ -494,6 +494,27 @@
 	return 0;
 }
 
+void i2c_clients_command(struct i2c_adapter *adap, unsigned int cmd, void *arg)
+{
+	int i;
+
+	down(&adap->list);
+	for (i = 0; i < I2C_CLIENT_MAX; i++) {
+		if (NULL == adap->clients[i])
+			continue;
+		if (!try_module_get(adap->clients[i]->driver->owner))
+			continue;
+		if (NULL == adap->clients[i]->driver->command)
+			continue;
+		
+		up(&adap->list);
+		adap->clients[i]->driver->command(adap->clients[i],cmd,arg);
+		module_put(adap->clients[i]->driver->owner);
+		down(&adap->list);
+	}
+	up(&adap->list);
+}
+
 #ifdef CONFIG_PROC_FS
 /* This function generates the output for /proc/bus/i2c-? */
 static ssize_t i2cproc_bus_read(struct file *file, char *buf,
@@ -1417,6 +1438,7 @@
 EXPORT_SYMBOL(i2c_use_client);
 EXPORT_SYMBOL(i2c_release_client);
 EXPORT_SYMBOL(i2c_check_addr);
+EXPORT_SYMBOL(i2c_clients_command);
 
 EXPORT_SYMBOL(i2c_master_send);
 EXPORT_SYMBOL(i2c_master_recv);
include/linux/i2c.h +5 -0
diff -u linux-2.5.66/include/linux/i2c.h linux/include/linux/i2c.h
@@ -329,6 +329,11 @@
 extern int i2c_use_client(struct i2c_client *);
 extern int i2c_release_client(struct i2c_client *);
 
+/* call the i2c_client->command() of all attached clients with
+ * the given arguments */
+extern void i2c_clients_command(struct i2c_adapter *adap,
+				unsigned int cmd, void *arg);
+
 /* returns -EBUSY if address has been taken, 0 if not. Note that the only
    other place at which this is called is within i2c_attach_client; so
    you can cheat by simply not registering. Not recommended, of course! */
Signature · 1 line
Michael Moore for president!
#1 lore raw
Quoted 29 lines · Gerd Knorr

Hi,

This patch adds a function which loops over all i2c clients attached to some i2c adapter and calls the ->command function of the driver.

Currently the bttv and saa7134 drivers have simliar functions, but (currently) without sane locking and module handling. Newer versions will switch to this function. Updates for the two drivers which are actually using this new function are available from
http://bytesex.org/patches/wip/

Gerd

diff -u linux-2.5.66/drivers/i2c/i2c-core.c linux/drivers/i2c/i2c-core.c

drivers/i2c/i2c-core.c +9 -0
@@ -494,6 +494,27 @@
 	return 0;
 }
 
+void i2c_clients_command(struct i2c_adapter *adap, unsigned int cmd, void *arg)
+{
+	int i;
+
+	down(&adap->list);
+	for (i = 0; i < I2C_CLIENT_MAX; i++) {
+		if (NULL == adap->clients[i])
+			continue;
+		if (!try_module_get(adap->clients[i]->driver->owner))

drivers/i2c/i2c-core.c line 515

Quoted 10 lines
drivers/i2c/i2c-core.c +10 -0
+			continue;
+		if (NULL == adap->clients[i]->driver->command)
+			continue;
+		
+		up(&adap->list);
+		adap->clients[i]->driver->command(adap->clients[i],cmd,arg);
+		module_put(adap->clients[i]->driver->owner);
+		down(&adap->list);
+	}
+	up(&adap->list);

This is a horrible algorithm! Please introduce a per-adapter client lists.

author
#2 lore raw
Quoted 11 lines · Christoph Hellwig

drivers/i2c/i2c-core.c line 504

Quoted 8 lines
drivers/i2c/i2c-core.c +8 -0
+void i2c_clients_command(struct i2c_adapter *adap, unsigned int cmd, void *arg)
+{
+	int i;
+
+	down(&adap->list);
+	for (i = 0; i < I2C_CLIENT_MAX; i++) {
+		if (NULL == adap->clients[i])
+			continue;

This is a horrible algorithm! Please introduce a per-adapter client lists.

Well, I can't easily fix that single function. The whole i2c core manages the clients that way, i.e. the whole i2c subsystem would need a rewrite ...

Gerd

Signature · 1 line
Michael Moore for president!