Index: /i2c/trunk/kernel/i2c-core.c
===================================================================
--- /i2c/trunk/kernel/i2c-core.c	(revision 3453)
+++ /i2c/trunk/kernel/i2c-core.c	(revision 3469)
@@ -380,4 +380,8 @@
 	DEB(printk("i2c-core.o: client [%s] registered to adapter [%s](pos. %d).\n",
 		client->name, adapter->name,i));
+
+	if(client->flags & I2C_CLIENT_ALLOW_USE)
+		client->usage_count = 0;
+	
 	return 0;
 }
@@ -397,5 +401,9 @@
 		return -ENODEV;
 	}
-
+	
+	if( (client->flags & I2C_CLIENT_ALLOW_USE) && 
+	    (client->usage_count>0))
+		return -EBUSY;
+	
 	if (adapter->client_unregister != NULL) 
 		adapter->client_unregister(client);
@@ -422,5 +430,5 @@
 void i2c_dec_use_client(struct i2c_client *client)
 {
-
+	
 	if (client->driver->dec_use != NULL)
 		client->driver->dec_use(client);
@@ -428,4 +436,103 @@
 	if (client->adapter->dec_use != NULL)
 		client->adapter->dec_use(client->adapter);
+}
+
+struct i2c_client *i2c_get_client(int driver_id, int adapter_id, 
+					struct i2c_client *prev)
+{
+	int i,j;
+	struct i2c_adapter *adapter=0;
+	
+	/* Will iterate through the list of clients in each adapter of adapters-list
+	   in search for a client that matches the search criteria. driver_id or 
+	   adapter_id are ignored if set to 0. If both are ignored this returns 
+	   first client found. */
+	
+	i = j = 0;  
+	
+	/* set starting point */ 
+	if(prev)
+	{
+		if(!(prev->adapter))
+			return (struct i2c_client *) -EINVAL;
+		
+		for(j=0; j < I2C_ADAP_MAX; j++)
+			if(prev->adapter == adapters[j])
+				break;
+		
+		/* invalid starting point? */
+		if (I2C_ADAP_MAX == j) {
+			printk(KERN_WARNING " i2c-core.o: get_client adapter for client:[%s] not found\n",
+				prev->name);
+			return (struct i2c_client *) -ENODEV;
+		}	
+		
+		for(i=0; i < I2C_CLIENT_MAX; i++)
+			if(prev == adapters[j]->clients[i])
+				break;
+		
+		/* invalid starting point? */
+		if (I2C_CLIENT_MAX == i) {
+			printk(KERN_WARNING " i2c-core.o: get_client client:[%s] not found\n",
+				prev->name);
+			return (struct i2c_client *) -ENODEV;
+		}	
+		
+		i++; /* start from one after prev */
+	}
+	
+	for(; j < I2C_ADAP_MAX; j++)
+	{
+		if(!adapters[j])
+			continue;
+			
+		if(adapter_id && (adapters[j]->id != adapter_id))
+			continue;
+		
+		for(; i < I2C_CLIENT_MAX; i++)
+		{
+			if(!adapters[j]->clients[i])
+				continue;
+				
+			if(driver_id && (adapters[j]->clients[i]->driver->id != driver_id))
+				continue;
+			if(adapters[j]->clients[i]->flags & I2C_CLIENT_ALLOW_USE)	
+				return adapters[j]->clients[i];
+		}
+	}
+
+	return 0;
+}
+
+int i2c_use_client(struct i2c_client *client)
+{
+	if(client->flags & I2C_CLIENT_ALLOW_USE)
+		if (client->flags & I2C_CLIENT_ALLOW_MULTIPLE_USE) 
+			client->usage_count++;
+		else
+			if(client->usage_count > 0)
+				return -EBUSY;
+			else
+				client->usage_count++;
+
+	i2c_inc_use_client(client);
+
+	return 0;
+}
+
+int i2c_release_client(struct i2c_client *client)
+{
+	if(client->flags & I2C_CLIENT_ALLOW_USE)
+		if(client->usage_count>0)
+			client->usage_count--;
+		else
+		{
+			printk(KERN_WARNING " i2c-core.o: dec_use_client used one too many times\n");
+			return -EPERM;
+		}
+	
+	i2c_dec_use_client(client);
+	
+	return 0;
 }
 
@@ -1187,4 +1294,7 @@
 EXPORT_SYMBOL(i2c_inc_use_client);
 EXPORT_SYMBOL(i2c_dec_use_client);
+EXPORT_SYMBOL(i2c_get_client);
+EXPORT_SYMBOL(i2c_use_client);
+EXPORT_SYMBOL(i2c_release_client);
 EXPORT_SYMBOL(i2c_check_addr);
 
Index: /i2c/trunk/kernel/i2c.h
===================================================================
--- /i2c/trunk/kernel/i2c.h	(revision 3450)
+++ /i2c/trunk/kernel/i2c.h	(revision 3469)
@@ -199,4 +199,6 @@
 	struct i2c_driver *driver;	/* and our access routines	*/
 	void *data;			/* for the clients		*/
+	int usage_count;		/* How many accesses currently  */
+					/* to the client		*/
 };
 
@@ -284,4 +286,9 @@
 #define I2C_DF_DUMMY	0x02		/* do not connect any clients */
 
+/*flags for the client struct: */
+#define I2C_CLIENT_ALLOW_USE		0x01	/* Client allows access */
+#define I2C_CLIENT_ALLOW_MULTIPLE_USE 	0x02  	/* Allow multiple access-locks */
+						/* on an i2c_client */
+
 /* i2c_client_address_data is the struct for holding default client
  * addresses for a driver and for the parameters supplied on the
@@ -326,4 +333,21 @@
 extern void i2c_inc_use_client(struct i2c_client *);
 extern void i2c_dec_use_client(struct i2c_client *);
+
+/* New function: This is to get an i2c_client-struct for controlling the 
+   client either by using i2c_control-function or having the 
+   client-module export functions that can be used with the i2c_client
+   -struct. */
+extern struct i2c_client *i2c_get_client(int driver_id, int adapter_id, 
+					struct i2c_client *prev);
+
+/* Should be used with new function
+   extern struct i2c_client *i2c_get_client(int,int,struct i2c_client *);
+   to make sure that client-struct is valid and that it is okay to access
+   the i2c-client. 
+   returns -EACCES if client doesn't allow use (default)
+   returns -EBUSY if client doesn't allow multiple use (default) and 
+   usage_count >0 */
+extern int i2c_use_client(struct i2c_client *);
+extern int i2c_release_client(struct i2c_client *);
 
 /* returns -EBUSY if address has been taken, 0 if not. Note that the only
