All of lore.kernel.org
 help / color / mirror / Atom feed
From: Gerd Knorr <kraxel@bytesex.org>
To: Linus Torvalds <torvalds@transmeta.com>, Greg KH <greg@kroah.com>,
	Frank Davis <fdavis@si.rr.com>,
	Kernel List <linux-kernel@vger.kernel.org>,
	Ronald Bultje <R.S.Bultje@pharm.uu.nl>
Subject: [patch] i2c #2/3: add i2c_clients_command
Date: Tue, 6 May 2003 21:40:18 +0200	[thread overview]
Message-ID: <20030506194018.GB865@bytesex.org> (raw)
In-Reply-To: <20030506193430.GA865@bytesex.org>

  Hi,

This is the second of three patches for i2c.

Changes:

  * adds a i2c_clients_command() function to i2c-core which calls
    the ->command() callback of all clients attached to a adapter.
  * make bttv + saa7134 drivers use that function instead of mucking
    with the i2c_adapter struct themself.

Please apply,

  Gerd

diff -urN -X /home/kraxel/.kdontdiff linux-i2c-1-2.5.69/drivers/i2c/i2c-core.c linux-i2c-2-2.5.69/drivers/i2c/i2c-core.c
--- linux-i2c-1-2.5.69/drivers/i2c/i2c-core.c	2003-05-06 13:42:07.000000000 +0200
+++ linux-i2c-2-2.5.69/drivers/i2c/i2c-core.c	2003-05-06 16:25:40.000000000 +0200
@@ -411,6 +411,27 @@
 	return 0;
 }
 
+void i2c_clients_command(struct i2c_adapter *adap, unsigned int cmd, void *arg)
+{
+	struct list_head  *item;
+	struct i2c_client *client;
+
+	down(&adap->clist_lock);
+	list_for_each(item,&adap->clients) {
+		client = list_entry(item, struct i2c_client, list);
+		if (!try_module_get(client->driver->owner))
+			continue;
+		if (NULL != client->driver->command) {
+			up(&adap->clist_lock);
+			client->driver->command(client,cmd,arg);
+			down(&adap->clist_lock);
+		}
+		module_put(client->driver->owner);
+       }
+       up(&adap->clist_lock);
+}
+
+
 /* match always succeeds, as we want the probe() to tell if we really accept this match */
 static int i2c_device_match(struct device *dev, struct device_driver *drv)
 {
@@ -1183,6 +1204,7 @@
 EXPORT_SYMBOL(i2c_detach_client);
 EXPORT_SYMBOL(i2c_use_client);
 EXPORT_SYMBOL(i2c_release_client);
+EXPORT_SYMBOL(i2c_clients_command);
 EXPORT_SYMBOL(i2c_check_addr);
 
 EXPORT_SYMBOL(i2c_master_send);
diff -urN -X /home/kraxel/.kdontdiff linux-i2c-1-2.5.69/drivers/media/video/bttv-if.c linux-i2c-2-2.5.69/drivers/media/video/bttv-if.c
--- linux-i2c-1-2.5.69/drivers/media/video/bttv-if.c	2003-05-06 10:22:00.000000000 +0200
+++ linux-i2c-2-2.5.69/drivers/media/video/bttv-if.c	2003-05-06 16:57:13.000000000 +0200
@@ -7,7 +7,7 @@
 
     Copyright (C) 1996,97,98 Ralph  Metzler (rjkm@thp.uni-koeln.de)
                            & Marcus Metzler (mocm@thp.uni-koeln.de)
-    (c) 1999,2000 Gerd Knorr <kraxel@goldbach.in-berlin.de>
+    (c) 1999-2003 Gerd Knorr <kraxel@bytesex.org>
 
     This program is free software; you can redistribute it and/or modify
     it under the terms of the GNU General Public License as published by
@@ -195,51 +195,21 @@
 static int attach_inform(struct i2c_client *client)
 {
         struct bttv *btv = i2c_get_adapdata(client->adapter);
-	int i;
 
-	for (i = 0; i < I2C_CLIENTS_MAX; i++) {
-		if (btv->i2c_clients[i] == NULL) {
-			btv->i2c_clients[i] = client;
-			break;
-		}
-	}
-	if (btv->tuner_type != -1)
+	if (btv->tuner_type != UNSET)
 		bttv_call_i2c_clients(btv,TUNER_SET_TYPE,&btv->tuner_type);
-        if (bttv_verbose)
-		printk("bttv%d: i2c attach [client=%s,%s]\n",btv->nr,
-		       client->dev.name, (i < I2C_CLIENTS_MAX) ?  "ok" : "failed");
-        return 0;
-}
-
-static int detach_inform(struct i2c_client *client)
-{
-        struct bttv *btv = i2c_get_adapdata(client->adapter);
-	int i;
 
-	for (i = 0; i < I2C_CLIENTS_MAX; i++) {
-		if (btv->i2c_clients[i] == client) {
-			btv->i2c_clients[i] = NULL;
-			break;
-		}
-	}
-        if (bttv_verbose)
-		printk("bttv%d: i2c detach [client=%s,%s]\n",btv->nr,
-		       client->dev.name, (i < I2C_CLIENTS_MAX) ?  "ok" : "failed");
+        if (bttv_debug)
+		printk("bttv%d: i2c attach [client=%s]\n",
+		       btv->nr, i2c_clientname(client));
         return 0;
 }
 
 void bttv_call_i2c_clients(struct bttv *btv, unsigned int cmd, void *arg)
 {
-	int i;
-	
-	for (i = 0; i < I2C_CLIENTS_MAX; i++) {
-		if (NULL == btv->i2c_clients[i])
-			continue;
-		if (NULL == btv->i2c_clients[i]->driver->command)
-			continue;
-		btv->i2c_clients[i]->driver->command(
-			btv->i2c_clients[i],cmd,arg);
-	}
+	if (0 != btv->i2c_rc)
+		return;
+	i2c_clients_command(&btv->i2c_adap, cmd, arg);
 }
 
 void bttv_i2c_call(unsigned int card, unsigned int cmd, void *arg)
@@ -260,20 +230,15 @@
 };
 
 static struct i2c_adapter bttv_i2c_adap_template = {
-	.owner          = THIS_MODULE,
+	.owner             = THIS_MODULE,
+	I2C_DEVNAME("bt848"),
 	.id                = I2C_HW_B_BT848,
 	.client_register   = attach_inform,
-	.client_unregister = detach_inform,
-	.dev		= {
-		.name	= "bt848",
-	},
 };
 
 static struct i2c_client bttv_i2c_client_template = {
-        .id	= -1,
-        .dev	= {
-		.name = "bttv internal",
-	},
+	I2C_DEVNAME("bttv internal"),
+        .id       = -1,
 };
 
 
@@ -347,8 +312,8 @@
 	memcpy(&btv->i2c_client, &bttv_i2c_client_template,
 	       sizeof(struct i2c_client));
 
-	sprintf(btv->i2c_adap.dev.name+strlen(btv->i2c_adap.dev.name),
-		" #%d", btv->nr);
+	sprintf(btv->i2c_adap.dev.name, "bt848 #%d", btv->nr);
+
         btv->i2c_algo.data = btv;
         i2c_set_adapdata(&btv->i2c_adap, btv);
         btv->i2c_adap.algo_data = &btv->i2c_algo;
diff -urN -X /home/kraxel/.kdontdiff linux-i2c-1-2.5.69/drivers/media/video/bttv.h linux-i2c-2-2.5.69/drivers/media/video/bttv.h
--- linux-i2c-1-2.5.69/drivers/media/video/bttv.h	2003-05-06 10:22:00.000000000 +0200
+++ linux-i2c-2-2.5.69/drivers/media/video/bttv.h	2003-05-06 17:00:34.000000000 +0200
@@ -243,7 +243,6 @@
 
 
 /* i2c */
-#define I2C_CLIENTS_MAX 16
 extern void bttv_bit_setscl(void *data, int state);
 extern void bttv_bit_setsda(void *data, int state);
 extern void bttv_call_i2c_clients(struct bttv *btv, unsigned int cmd, void *arg);
diff -urN -X /home/kraxel/.kdontdiff linux-i2c-1-2.5.69/drivers/media/video/bttvp.h linux-i2c-2-2.5.69/drivers/media/video/bttvp.h
--- linux-i2c-1-2.5.69/drivers/media/video/bttvp.h	2003-05-06 10:22:26.000000000 +0200
+++ linux-i2c-2-2.5.69/drivers/media/video/bttvp.h	2003-05-06 16:55:01.000000000 +0200
@@ -62,6 +62,8 @@
 #define RAW_LINES            640
 #define RAW_BPL             1024
 
+#define UNSET (-1U)
+
 /* ---------------------------------------------------------- */
 
 struct bttv_tvnorm 
@@ -276,7 +278,6 @@
 	struct i2c_algo_bit_data   i2c_algo;
 	struct i2c_client          i2c_client;
 	int                        i2c_state, i2c_rc;
-	struct i2c_client         *i2c_clients[I2C_CLIENTS_MAX];
 
 	/* video4linux (1) */
 	struct video_device video_dev;
diff -urN -X /home/kraxel/.kdontdiff linux-i2c-1-2.5.69/drivers/media/video/saa7134/saa7134-i2c.c linux-i2c-2-2.5.69/drivers/media/video/saa7134/saa7134-i2c.c
--- linux-i2c-1-2.5.69/drivers/media/video/saa7134/saa7134-i2c.c	2003-05-06 10:22:02.000000000 +0200
+++ linux-i2c-2-2.5.69/drivers/media/video/saa7134/saa7134-i2c.c	2003-05-06 16:51:55.000000000 +0200
@@ -334,19 +334,15 @@
 
 static struct i2c_adapter saa7134_adap_template = {
 	.owner         = THIS_MODULE,
+	I2C_DEVNAME("saa7134"),
 	.id            = I2C_ALGO_SAA7134,
 	.algo          = &saa7134_algo,
 	.client_register = attach_inform,
-	.dev		= {
-		.name	= "saa7134",
-	},
 };
 
 static struct i2c_client saa7134_client_template = {
-        .id   = -1,
-	.dev	= {
-		.name	= "saa7134 internal",
-	},
+	I2C_DEVNAME("saa7134 internal"),
+        .id        = -1,
 };
 
 /* ----------------------------------------------------------- */
@@ -399,22 +395,13 @@
 void saa7134_i2c_call_clients(struct saa7134_dev *dev,
 			      unsigned int cmd, void *arg)
 {
-	int i;
-
-	for (i = 0; i < I2C_CLIENT_MAX; i++) {
-		if (NULL == dev->i2c_adap.clients[i])
-			continue;
-		if (NULL == dev->i2c_adap.clients[i]->driver->command)
-			continue;
-		dev->i2c_adap.clients[i]->driver->command
-			(dev->i2c_adap.clients[i],cmd,arg);
-	}
+	i2c_clients_command(&dev->i2c_adap, cmd, arg);
 }
 
 int saa7134_i2c_register(struct saa7134_dev *dev)
 {
 	dev->i2c_adap = saa7134_adap_template;
-	strncpy(dev->i2c_adap.dev.name, dev->name, DEVICE_NAME_SIZE);
+	strcpy(dev->i2c_adap.dev.name,dev->name);
 	dev->i2c_adap.algo_data = dev;
 	i2c_add_adapter(&dev->i2c_adap);
 	
diff -urN -X /home/kraxel/.kdontdiff linux-i2c-1-2.5.69/include/linux/i2c.h linux-i2c-2-2.5.69/include/linux/i2c.h
--- linux-i2c-1-2.5.69/include/linux/i2c.h	2003-05-06 13:41:07.000000000 +0200
+++ linux-i2c-2-2.5.69/include/linux/i2c.h	2003-05-06 14:03:04.000000000 +0200
@@ -334,6 +334,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! */

  reply	other threads:[~2003-05-06 19:42 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-05-06 19:34 [patch] i2c #1/3: listify i2c core Gerd Knorr
2003-05-06 19:40 ` Gerd Knorr [this message]
2003-05-06 19:51   ` [patch] i2c #3/3: add class field to i2c_adapter Gerd Knorr
2003-05-07 10:12     ` Mark McClelland
2003-05-09 22:00       ` Greg KH
2003-05-07  0:17 ` [patch] i2c #1/3: listify i2c core Greg KH

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20030506194018.GB865@bytesex.org \
    --to=kraxel@bytesex.org \
    --cc=R.S.Bultje@pharm.uu.nl \
    --cc=fdavis@si.rr.com \
    --cc=greg@kroah.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=torvalds@transmeta.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.