Re: [PATCH][UPDATE] i2c: Add support for virtual I2C adapters

2006-11-28 Thread Sujoy Gupta

Is there a reason why the files and config options have been renamed
from i2c-virtual to i2c-virt?

On 4/7/06, Kumar Gala <[EMAIL PROTECTED]> wrote:

Any comments or acceptance of this patch?

- k

On Mar 30, 2006, at 5:05 PM, Kumar Gala wrote:

> Virtual adapters are useful to handle multiplexed I2C bus
> topologies, by
> presenting each multiplexed segment as a I2C adapter.  Typically,
> either
> a mux (or switch) exists which is an I2C device on the parent bus.
> One
> selects a given child bus via programming the mux and then all the
> devices
> on that bus become present on the parent bus.  The intent is to allow
> multiple devices of the same type to exist in a system which would
> normally
> have address conflicts.
>
> Since virtual adapters will get registered in an I2C client's detect
> function we have to expose versions of i2c_{add,del}_adapter for
> i2c_{add,del}_virt_adapter to call that don't lock.
>
> Additionally, i2c_virt_master_xfer (and i2c_virt_smbus_xfer) acquire
> the parent->bus_lock and call the parent's master_xfer directly.  This
> is because on a i2c_virt_master_xfer we have issue an i2c write on
> the parent bus to select the given virtual adapter, then do the i2c
> operation on the parent bus, followed by another i2c write on the
> parent to deslect the virtual adapter.
>
> Signed-off-by: Kumar Gala <[EMAIL PROTECTED]>
>
> ---
> commit 862cbc263e3d3e44028d7465a912847cf5366163
> tree 2c91bad8eb66cab9727f3071831a916ada41edf8
> parent 5d4fe2c1ce83c3e967ccc1ba3d580c1a5603a866
> author Kumar Gala <[EMAIL PROTECTED]> Thu, 30 Mar 2006
> 17:03:42 -0600
> committer Kumar Gala <[EMAIL PROTECTED]> Thu, 30 Mar 2006
> 17:03:42 -0600
>
>  drivers/i2c/Kconfig|9 ++
>  drivers/i2c/Makefile   |1
>  drivers/i2c/i2c-core.c |   42 
>  drivers/i2c/i2c-virt.c |  173 +
> +++
>  include/linux/i2c-id.h |2 +
>  include/linux/i2c.h|   20 ++
>  6 files changed, 234 insertions(+), 13 deletions(-)
>
> diff --git a/drivers/i2c/Kconfig b/drivers/i2c/Kconfig
> index 24383af..b8a8fc1 100644
> --- a/drivers/i2c/Kconfig
> +++ b/drivers/i2c/Kconfig
> @@ -34,6 +34,15 @@ config I2C_CHARDEV
> This support is also available as a module.  If so, the module
> will be called i2c-dev.
>
> +config I2C_VIRT
> + tristate "I2C virtual adapter support"
> + depends on I2C
> + help
> +   Say Y here if you want the I2C core to support the ability to have
> +   virtual adapters. Virtual adapters are useful to handle
> multiplexed
> +   I2C bus topologies, by presenting each multiplexed segment as a
> +   I2C adapter.
> +
>  source drivers/i2c/algos/Kconfig
>  source drivers/i2c/busses/Kconfig
>  source drivers/i2c/chips/Kconfig
> diff --git a/drivers/i2c/Makefile b/drivers/i2c/Makefile
> index 71c5a85..4467db2 100644
> --- a/drivers/i2c/Makefile
> +++ b/drivers/i2c/Makefile
> @@ -3,6 +3,7 @@
>  #
>
>  obj-$(CONFIG_I2C)+= i2c-core.o
> +obj-$(CONFIG_I2C_VIRT)   += i2c-virt.o
>  obj-$(CONFIG_I2C_CHARDEV)+= i2c-dev.o
>  obj-y+= busses/ chips/ algos/
>
> diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c
> index 45e2cdf..64c1c9e 100644
> --- a/drivers/i2c/i2c-core.c
> +++ b/drivers/i2c/i2c-core.c
> @@ -150,22 +150,31 @@ static struct device_attribute dev_attr_
>   */
>  int i2c_add_adapter(struct i2c_adapter *adap)
>  {
> + int res;
> +
> + mutex_lock(_lists);
> + res = i2c_add_adapter_nolock(adap);
> + mutex_unlock(_lists);
> +
> + return res;
> +}
> +
> +int i2c_add_adapter_nolock(struct i2c_adapter *adap)
> +{
>   int id, res = 0;
>   struct list_head   *item;
>   struct i2c_driver  *driver;
>
> - mutex_lock(_lists);
> -
>   if (idr_pre_get(_adapter_idr, GFP_KERNEL) == 0) {
>   res = -ENOMEM;
> - goto out_unlock;
> + goto out;
>   }
>
>   res = idr_get_new(_adapter_idr, adap, );
>   if (res < 0) {
>   if (res == -EAGAIN)
>   res = -ENOMEM;
> - goto out_unlock;
> + goto out;
>   }
>
>   adap->nr =  id & MAX_ID_MASK;
> @@ -203,21 +212,29 @@ int i2c_add_adapter(struct i2c_adapter *
>   driver->attach_adapter(adap);
>   }
>
> -out_unlock:
> - mutex_unlock(_lists);
> +out:
>   return res;
>  }
>
> -
>  int i2c_del_adapter(struct i2c_adapter *adap)
>  {
> + int res;
> +
> + mutex_lock(_lists);
> + res = i2c_del_adapter_nolock(adap);
> + mutex_unlock(_lists);
> +
> + return res;
> +}
> +
> +int i2c_del_adapter_nolock(struct i2c_adapter *adap)
> +{
>   struct list_head  *item, *_n;
>   struct i2c_adapter *adap_from_list;
>   struct i2c_driver *driver;
>   struct i2c_client *client;
>   int res = 0;
>
> - mutex_lock(_lists);
>
>   /* First make sure that this adapter was ever added */
>   

Re: [PATCH][UPDATE] i2c: Add support for virtual I2C adapters

2006-11-28 Thread Sujoy Gupta

Is there a reason why the files and config options have been renamed
from i2c-virtual to i2c-virt?

On 4/7/06, Kumar Gala [EMAIL PROTECTED] wrote:

Any comments or acceptance of this patch?

- k

On Mar 30, 2006, at 5:05 PM, Kumar Gala wrote:

 Virtual adapters are useful to handle multiplexed I2C bus
 topologies, by
 presenting each multiplexed segment as a I2C adapter.  Typically,
 either
 a mux (or switch) exists which is an I2C device on the parent bus.
 One
 selects a given child bus via programming the mux and then all the
 devices
 on that bus become present on the parent bus.  The intent is to allow
 multiple devices of the same type to exist in a system which would
 normally
 have address conflicts.

 Since virtual adapters will get registered in an I2C client's detect
 function we have to expose versions of i2c_{add,del}_adapter for
 i2c_{add,del}_virt_adapter to call that don't lock.

 Additionally, i2c_virt_master_xfer (and i2c_virt_smbus_xfer) acquire
 the parent-bus_lock and call the parent's master_xfer directly.  This
 is because on a i2c_virt_master_xfer we have issue an i2c write on
 the parent bus to select the given virtual adapter, then do the i2c
 operation on the parent bus, followed by another i2c write on the
 parent to deslect the virtual adapter.

 Signed-off-by: Kumar Gala [EMAIL PROTECTED]

 ---
 commit 862cbc263e3d3e44028d7465a912847cf5366163
 tree 2c91bad8eb66cab9727f3071831a916ada41edf8
 parent 5d4fe2c1ce83c3e967ccc1ba3d580c1a5603a866
 author Kumar Gala [EMAIL PROTECTED] Thu, 30 Mar 2006
 17:03:42 -0600
 committer Kumar Gala [EMAIL PROTECTED] Thu, 30 Mar 2006
 17:03:42 -0600

  drivers/i2c/Kconfig|9 ++
  drivers/i2c/Makefile   |1
  drivers/i2c/i2c-core.c |   42 
  drivers/i2c/i2c-virt.c |  173 +
 +++
  include/linux/i2c-id.h |2 +
  include/linux/i2c.h|   20 ++
  6 files changed, 234 insertions(+), 13 deletions(-)

 diff --git a/drivers/i2c/Kconfig b/drivers/i2c/Kconfig
 index 24383af..b8a8fc1 100644
 --- a/drivers/i2c/Kconfig
 +++ b/drivers/i2c/Kconfig
 @@ -34,6 +34,15 @@ config I2C_CHARDEV
 This support is also available as a module.  If so, the module
 will be called i2c-dev.

 +config I2C_VIRT
 + tristate I2C virtual adapter support
 + depends on I2C
 + help
 +   Say Y here if you want the I2C core to support the ability to have
 +   virtual adapters. Virtual adapters are useful to handle
 multiplexed
 +   I2C bus topologies, by presenting each multiplexed segment as a
 +   I2C adapter.
 +
  source drivers/i2c/algos/Kconfig
  source drivers/i2c/busses/Kconfig
  source drivers/i2c/chips/Kconfig
 diff --git a/drivers/i2c/Makefile b/drivers/i2c/Makefile
 index 71c5a85..4467db2 100644
 --- a/drivers/i2c/Makefile
 +++ b/drivers/i2c/Makefile
 @@ -3,6 +3,7 @@
  #

  obj-$(CONFIG_I2C)+= i2c-core.o
 +obj-$(CONFIG_I2C_VIRT)   += i2c-virt.o
  obj-$(CONFIG_I2C_CHARDEV)+= i2c-dev.o
  obj-y+= busses/ chips/ algos/

 diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c
 index 45e2cdf..64c1c9e 100644
 --- a/drivers/i2c/i2c-core.c
 +++ b/drivers/i2c/i2c-core.c
 @@ -150,22 +150,31 @@ static struct device_attribute dev_attr_
   */
  int i2c_add_adapter(struct i2c_adapter *adap)
  {
 + int res;
 +
 + mutex_lock(core_lists);
 + res = i2c_add_adapter_nolock(adap);
 + mutex_unlock(core_lists);
 +
 + return res;
 +}
 +
 +int i2c_add_adapter_nolock(struct i2c_adapter *adap)
 +{
   int id, 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;
 + goto out;
   }

   res = idr_get_new(i2c_adapter_idr, adap, id);
   if (res  0) {
   if (res == -EAGAIN)
   res = -ENOMEM;
 - goto out_unlock;
 + goto out;
   }

   adap-nr =  id  MAX_ID_MASK;
 @@ -203,21 +212,29 @@ int i2c_add_adapter(struct i2c_adapter *
   driver-attach_adapter(adap);
   }

 -out_unlock:
 - mutex_unlock(core_lists);
 +out:
   return res;
  }

 -
  int i2c_del_adapter(struct i2c_adapter *adap)
  {
 + int res;
 +
 + mutex_lock(core_lists);
 + res = i2c_del_adapter_nolock(adap);
 + mutex_unlock(core_lists);
 +
 + return res;
 +}
 +
 +int i2c_del_adapter_nolock(struct i2c_adapter *adap)
 +{
   struct list_head  *item, *_n;
   struct i2c_adapter *adap_from_list;
   struct i2c_driver *driver;
   struct i2c_client *client;
   int res = 0;

 - mutex_lock(core_lists);

   /* First make sure that this adapter was ever added */
   list_for_each_entry(adap_from_list, adapters, list) {
 @@ -228,7 +245,7 @@ int i2c_del_adapter(struct i2c_adapter *
   pr_debug(i2c-core: attempting