public inbox for linux-i2c@vger.kernel.org
 help / color / mirror / Atom feed
  • [parent not found: <200712281230.17840.david-b@pacbell.net>]
  • * Re: [patch 2.6.24-rc5-git] add i2c_new_dummy() utility
    @ 2007-12-22 17:31 Jean Delvare
           [not found] ` <kOXVGr9s.1198344701.9162110.khali-IO4AeUl/lkuWVfeAwA7xHQ@public.gmane.org>
      0 siblings, 1 reply; 43+ messages in thread
    From: Jean Delvare @ 2007-12-22 17:31 UTC (permalink / raw)
      To: david-b-yBeKhBN/0LDR7s880joybQ; +Cc: i2c-GZX6beZjE8VD60Wz+7aTrA
    
    
    Hi David,
    
    Sorry for the non-threaded reply, I do not have access to the original
    post at the moment.
    
    David Brownell wrote:
    > This adds a i2c_new_dummy() primitive to help work with devices
    > that consume multiple addresses, which include many I2C eeproms
    > and at least one RTC.
    > 
    > Signed-off-by: David Brownell <dbrownell-Rn4VEauK+AKRv+LV9MX5uipxlwaOVQ5f@public.gmane.org>
    > ---
    > [ Apologies for the duplicate message some of you may have seen. ]
    > 
    > Tested with a 24c00 EEPROM ... that's the 16-byte one, which
    > ignores a0/a1/a2 and thus consumes 8 addresses.
    > 
    >  drivers/i2c/i2c-core.c |   60 ++++++++++++++++++++++++++++++++++++++++++++++++-
    >  include/linux/i2c.h    |    6 ++++
    >  2 files changed, 65 insertions(+), 1 deletion(-)
    > 
    > --- a/drivers/i2c/i2c-core.c	2007-12-15 20:57:54.000000000 -0800
    > +++ b/drivers/i2c/i2c-core.c	2007-12-15 21:01:22.000000000 -0800
    > @@ -276,6 +276,51 @@ void i2c_unregister_device(struct i2c_cl
    >  EXPORT_SYMBOL_GPL(i2c_unregister_device);
    >  
    >  
    > +static int dummy_nop(struct i2c_client *client)
    > +{
    > +	return 0;
    > +}
    > +
    > +static struct i2c_driver dummy_driver = {
    > +	.driver.name	= "dummy",
    > +	.probe		= dummy_nop,
    > +	.remove		= dummy_nop,
    > +};
    > +
    > +
    > +/**
    > + * i2c_new_dummy - return a new i2c device bound to a dummy driver
    > + * @adapter: the adapter managing the device
    > + * @address: seven bit address to be used
    > + * @type: optional label used for i2c_client.name
    
    Do you have a use case in mind for this feature?
    
    > + * Context: can sleep
    > + *
    > + * This returns an I2C client bound to the "dummy" driver, intended for use
    > + * with devices that consume multiple addresses.  Examples of such chips
    > + * include various EEPROMS (like 24c04 and 24c08 models).
    > + *
    > + * These dummy devices have two main uses.  First, most I2C and SMBus calls
    > + * except i2c_transfer() need a client handle; the dummy will be that handle.
    > + * And second, this prevents the specified address from being bound to a
    > + * different driver.
    > + *
    > + * This returns the new i2c client, which may be saved for later use with
    > + * i2c_unregister_device(); or NULL to indicate an error.
    
    I'd say it _should_ be saved. Calling i2c_unregister_device() is pretty
    much mandatory, unless the driver can't be built as a module.
    
    > + */
    > +struct i2c_client *
    > +i2c_new_dummy(struct i2c_adapter *adapter, unsigned address, const char *type)
    
    The rest of i2c-core uses an unsigned short for addresses, maybe do the
    same here for consistency?
    
    > +{
    > +	struct i2c_board_info info = {
    > +		.driver_name	= "dummy",
    > +		.addr		= address,
    > +	};
    > +
    > +	if (type)
    > +		strncpy(info.type, type, sizeof info.type);
    
    Please use strlcpy() instead, strncpy() is error-prone.
    
    > +	return i2c_new_device(adapter, &info);
    > +}
    > +EXPORT_SYMBOL_GPL(i2c_new_dummy);
    > +
    >  /* ------------------------------------------------------------------------- */
    >  
    >  /* I2C bus adapters -- one roots each I2C or SMBUS segment */
    > @@ -848,11 +893,24 @@ static int __init i2c_init(void)
    >  	retval = bus_register(&i2c_bus_type);
    >  	if (retval)
    >  		return retval;
    > -	return class_register(&i2c_adapter_class);
    > +	retval = class_register(&i2c_adapter_class);
    > +	if (retval)
    > +		goto bus_err;
    > +	retval = i2c_add_driver(&dummy_driver);
    > +	if (retval)
    > +		goto class_err;
    > +	return 0;
    > +
    > +class_err:
    > +	class_unregister(&i2c_adapter_class);
    > +bus_err:
    > +	bus_unregister(&i2c_bus_type);
    > +	return retval;
    >  }
    
    Thanks for fixing a broken error path...
    
    >  
    >  static void __exit i2c_exit(void)
    >  {
    > +	i2c_del_driver(&dummy_driver);
    >  	class_unregister(&i2c_adapter_class);
    >  	bus_unregister(&i2c_bus_type);
    >  }
    > --- a/include/linux/i2c.h	2007-12-15 20:57:54.000000000 -0800
    > +++ b/include/linux/i2c.h	2007-12-15 21:01:22.000000000 -0800
    > @@ -261,6 +261,12 @@ i2c_new_probed_device(struct i2c_adapter
    >  		      struct i2c_board_info *info,
    >  		      unsigned short const *addr_list);
    >  
    > +/* For devices that use several addresses, use i2c_new_dummy() to make
    > + * client handles for the exta addresses.
    
    Typo: extra.
    
    > + */
    > +extern struct i2c_client *
    > +i2c_new_dummy(struct i2c_adapter *adap, unsigned address, const char *type);
    > +
    >  extern void i2c_unregister_device(struct i2c_client *);
    >  
    >  /* Mainboard arch_initcall() code should register all its I2C devices.
    > 
    
    Other than that the patch looks just fine. Please respin it and I'll
    apply it.
    
    Thanks,
    --
    Jean Delvare
    
    ^ permalink raw reply	[flat|nested] 43+ messages in thread

    end of thread, other threads:[~2008-01-18 12:10 UTC | newest]
    
    Thread overview: 43+ messages (download: mbox.gz follow: Atom feed
    -- links below jump to the message on this page --
         [not found] <20071216052308.A0FB11668D7@adsl-69-226-248-13.dsl.pltn13.pacbell.net>
         [not found] ` <20071216052308.A0FB11668D7-ZcXrCSuhvln6VZ3dlLfH/g4gEjPzgfUyLrfjE7I9kuVHxeISYlDBzl6hYfS7NtTn@public.gmane.org>
    2007-12-27 20:58   ` [patch 2.6.24-rc5-git] add i2c_new_dummy() utility Byron Bradley
         [not found]     ` <57e2b00712271258l6ea661ai2bfd6b9e099c71be-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
    2007-12-27 21:53       ` David Brownell
         [not found]         ` <200712271353.05857.david-b-yBeKhBN/0LDR7s880joybQ@public.gmane.org>
    2007-12-27 22:09           ` Byron Bradley
         [not found]             ` <57e2b00712271409n6c98f76o45116cd92b01f396-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
    2007-12-27 23:06               ` David Brownell
         [not found]                 ` <200712271506.43069.david-b-yBeKhBN/0LDR7s880joybQ@public.gmane.org>
    2007-12-27 23:37                   ` Byron Bradley
    2007-12-27 23:59                   ` David Brownell
         [not found] ` <200712281230.17840.david-b@pacbell.net>
         [not found]   ` <57e2b00712281645y70f6ec74s57945dc53f113ec8@mail.gmail.com>
         [not found]     ` <57e2b00712281645y70f6ec74s57945dc53f113ec8-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
    2007-12-30  3:05       ` David Brownell
         [not found]         ` <200712291905.15160.david-b-yBeKhBN/0LDR7s880joybQ@public.gmane.org>
    2008-01-04 22:16           ` Jean Delvare
         [not found]             ` <20080104231633.135f2875-ig7AzVSIIG7kN2dkZ6Wm7A@public.gmane.org>
    2008-01-04 23:48               ` David Brownell
         [not found]                 ` <200801041548.54825.david-b-yBeKhBN/0LDR7s880joybQ@public.gmane.org>
    2008-01-06  9:57                   ` Jean Delvare
    2008-01-06 11:23           ` i2c-remove-redundant-i2c_client-list.patch Jean Delvare
         [not found]             ` <20080106122356.78556b8a-ig7AzVSIIG7kN2dkZ6Wm7A@public.gmane.org>
    2008-01-06 19:30               ` i2c-remove-redundant-i2c_client-list.patch David Brownell
         [not found]                 ` <200801061130.31774.david-b-yBeKhBN/0LDR7s880joybQ@public.gmane.org>
    2008-01-08 14:18                   ` i2c-remove-redundant-i2c_client-list.patch Jean Delvare
         [not found]                     ` <20080108151817.35e05c6c-ig7AzVSIIG7kN2dkZ6Wm7A@public.gmane.org>
    2008-01-08 16:20                       ` i2c-remove-redundant-i2c_client-list.patch Jean Delvare
         [not found]                         ` <20080108172001.33de6afc-ig7AzVSIIG7kN2dkZ6Wm7A@public.gmane.org>
    2008-01-08 19:12                           ` i2c-remove-redundant-i2c_client-list.patch David Brownell
         [not found]                             ` <200801081112.46972.david-b-yBeKhBN/0LDR7s880joybQ@public.gmane.org>
    2008-01-08 20:50                               ` i2c-remove-redundant-i2c_client-list.patch Jean Delvare
         [not found]                                 ` <20080108215042.534e32fa-ig7AzVSIIG7kN2dkZ6Wm7A@public.gmane.org>
    2008-01-08 21:44                                   ` i2c-remove-redundant-i2c_client-list.patch David Brownell
         [not found]                                     ` <200801081344.45544.david-b-yBeKhBN/0LDR7s880joybQ@public.gmane.org>
    2008-01-08 22:04                                       ` i2c-remove-redundant-i2c_client-list.patch Greg KH
         [not found]                                         ` <20080108220445.GB3873-U8xfFu+wG4EAvxtiuMwx3w@public.gmane.org>
    2008-01-08 22:27                                           ` i2c-remove-redundant-i2c_client-list.patch David Brownell
    2008-01-09 13:29                                       ` i2c-remove-redundant-i2c_client-list.patch Jean Delvare
         [not found]                                         ` <20080109142906.23a55f5f-ig7AzVSIIG7kN2dkZ6Wm7A@public.gmane.org>
    2008-01-09 16:19                                           ` i2c-remove-redundant-i2c_client-list.patch Jean Delvare
         [not found]                                             ` <20080109171934.4f894bdc-ig7AzVSIIG7kN2dkZ6Wm7A@public.gmane.org>
    2008-01-09 21:21                                               ` i2c-remove-redundant-i2c_client-list.patch David Brownell
         [not found]                                                 ` <200801091321.29212.david-b-yBeKhBN/0LDR7s880joybQ@public.gmane.org>
    2008-01-10 13:31                                                   ` i2c-remove-redundant-i2c_client-list.patch Jean Delvare
         [not found]                                                     ` <20080110143105.456ddaf0-ig7AzVSIIG7kN2dkZ6Wm7A@public.gmane.org>
    2008-01-14 22:20                                                       ` i2c-remove-redundant-i2c_client-list.patch David Brownell
         [not found]                                                         ` <200801141420.49274.david-b-yBeKhBN/0LDR7s880joybQ@public.gmane.org>
    2008-01-17 22:02                                                           ` i2c-remove-redundant-i2c_client-list.patch Jean Delvare
    2008-01-18 10:14                                                           ` i2c-remove-redundant-i2c_client-list.patch Jean Delvare
         [not found]                                                             ` <20080118111401.7ffdccc5-ig7AzVSIIG7kN2dkZ6Wm7A@public.gmane.org>
    2008-01-18 10:30                                                               ` i2c-remove-redundant-i2c_client-list.patch David Brownell
    2008-01-14 22:42                                                       ` i2c-remove-redundant-i2c_client-list.patch David Brownell
    2008-01-17 19:35                                                   ` i2c-remove-redundant-i2c_client-list.patch David Brownell
         [not found]                                                     ` <200801171135.45797.david-b-yBeKhBN/0LDR7s880joybQ@public.gmane.org>
    2008-01-17 19:59                                                       ` i2c-remove-redundant-i2c_client-list.patch David Brownell
         [not found]                                                         ` <200801171159.00291.david-b-yBeKhBN/0LDR7s880joybQ@public.gmane.org>
    2008-01-18  9:32                                                           ` i2c-remove-redundant-i2c_client-list.patch Jean Delvare
         [not found]                                                             ` <20080118103209.4b92ac76-ig7AzVSIIG7kN2dkZ6Wm7A@public.gmane.org>
    2008-01-18 10:16                                                               ` i2c-remove-redundant-i2c_client-list.patch David Brownell
         [not found]                                                                 ` <200801180216.22363.david-b-yBeKhBN/0LDR7s880joybQ@public.gmane.org>
    2008-01-18 12:10                                                                   ` i2c-remove-redundant-i2c_client-list.patch Jean Delvare
    2008-01-08 18:52                       ` i2c-remove-redundant-i2c_client-list.patch David Brownell
         [not found]                         ` <200801081052.31413.david-b-yBeKhBN/0LDR7s880joybQ@public.gmane.org>
    2008-01-08 19:57                           ` i2c-remove-redundant-i2c_client-list.patch Jean Delvare
    2008-01-09 16:09                       ` i2c-remove-redundant-i2c_client-list.patch Jean Delvare
    2008-01-06 19:43               ` i2c-remove-redundant-i2c_client-list.patch David Brownell
         [not found]                 ` <200801061143.34020.david-b-yBeKhBN/0LDR7s880joybQ@public.gmane.org>
    2008-01-08 14:21                   ` i2c-remove-redundant-i2c_client-list.patch Jean Delvare
    2008-01-17 22:24           ` [patch 2.6.24-rc5-git] add i2c_new_dummy() utility David Brownell
    2007-12-22 17:31 Jean Delvare
         [not found] ` <kOXVGr9s.1198344701.9162110.khali-IO4AeUl/lkuWVfeAwA7xHQ@public.gmane.org>
    2007-12-23  5:08   ` David Brownell
         [not found]     ` <200712222108.51292.david-b-yBeKhBN/0LDR7s880joybQ@public.gmane.org>
    2007-12-23  5:11       ` David Brownell
         [not found]         ` <200712222111.09471.david-b-yBeKhBN/0LDR7s880joybQ@public.gmane.org>
    2007-12-23  9:03           ` Jean Delvare
    

    This is a public inbox, see mirroring instructions
    for how to clone and mirror all data and code used for this inbox