[i2c] [patch 2.6.21-rc3-git +i2c 5/5] i2c_add_numbered_adapter()

Jean Delvare khali at linux-fr.org
Sun Mar 18 13:18:03 CET 2007


Hi David,

On Wed, 14 Mar 2007 13:17:00 -0700, David Brownell wrote:
> UPDATED by moving one patch fragment to the previous patch,
> where it actually belonged
> 
> ==============
> This adds a new call, i2c_add_numbered_adapter(), to register an I2C adapter
> using a specific bus number and then create I2C device nodes for any
> pre-declared devices on that bus.  It builds on previous patches adding
> I2C probe() and remove() support, and pre-declaration of devices.
> 
> This completes the basic support for "new style" I2C device drivers.
> Those follow the standard driver model for binding devices to drivers
> (using probe and remove methods) rather than a legacy model (where the
> driver tries to autoconfigure each bus, and registers devices itself).
> 
> Signed-off-by: David Brownell <dbrownell at users.sourceforge.net>

Alessandro Zummo spotted what I think is a bug in this patch:

> --- at91.orig/include/linux/i2c.h	2007-03-14 12:59:12.000000000 -0700
> +++ at91/include/linux/i2c.h	2007-03-14 13:05:50.000000000 -0700
> @@ -363,6 +363,7 @@ struct i2c_client_address_data {
>   */
>  extern int i2c_add_adapter(struct i2c_adapter *);
>  extern int i2c_del_adapter(struct i2c_adapter *);
> +extern int i2c_add_numbered_adapter(struct i2c_adapter *);
>  
>  extern int i2c_register_driver(struct module *, struct i2c_driver *);
>  extern int i2c_del_driver(struct i2c_driver *);
> --- at91.orig/drivers/i2c/i2c-core.c	2007-03-14 13:04:55.000000000 -0700
> +++ at91/drivers/i2c/i2c-core.c	2007-03-14 13:05:50.000000000 -0700
> @@ -319,38 +319,19 @@ static void i2c_scan_static_board_info(s
>  	mutex_unlock(&__i2c_board_lock);
>  }
>  
> -
> -/* -----
> - * i2c_add_adapter is called from within the algorithm layer,
> - * when a new hw adapter registers. A new device is register to be
> - * available for clients.
> - */
> -int i2c_add_adapter(struct i2c_adapter *adap)
> +static int i2c_register_adapter(struct i2c_adapter *adap)
>  {
> -	int id, res = 0;
> +	int res = 0;
>  	struct list_head   *item;
>  	struct i2c_driver  *driver;
>  
> -	mutex_lock(&core_lists);
> -
> -	if (idr_pre_get(&i2c_adapter_idr, GFP_KERNEL) == 0) {
> -		res = -ENOMEM;
> -		goto out_unlock;
> -	}
> -
> -	res = idr_get_new(&i2c_adapter_idr, adap, &id);
> -	if (res < 0) {
> -		if (res == -EAGAIN)
> -			res = -ENOMEM;
> -		goto out_unlock;
> -	}
> -
> -	adap->nr =  id & MAX_ID_MASK;
>  	mutex_init(&adap->bus_lock);
>  	mutex_init(&adap->clist_lock);
> -	list_add_tail(&adap->list,&adapters);
>  	INIT_LIST_HEAD(&adap->clients);
>  
> +	mutex_lock(&core_lists);
> +	list_add_tail(&adap->list, &adapters);
> +
>  	/* Add the adapter to the driver core.
>  	 * If the parent pointer is not set up,
>  	 * we add this adapter to the host bus.
> @@ -370,6 +351,10 @@ int i2c_add_adapter(struct i2c_adapter *
>  
>  	dev_dbg(&adap->dev, "adapter [%s] registered\n", adap->name);
>  
> +	/* create pre-declared device nodes for new-style drivers */
> +	if (adap->id < __i2c_first_dynamic_bus_num)
> +		i2c_scan_static_board_info(adap);

You really mean adap->nr here, not adap->id?

> +
>  	/* let legacy drivers scan this bus for matching devices */
>  	list_for_each(item,&drivers) {
>  		driver = list_entry(item, struct i2c_driver, list);

Thanks,
-- 
Jean Delvare



More information about the i2c mailing list