public inbox for linux-i2c@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/4] i2c: Introduce i2c listeners
@ 2008-06-04 18:13 Jean Delvare
       [not found] ` <20080604201334.19636f30-ig7AzVSIIG7kN2dkZ6Wm7A@public.gmane.org>
  0 siblings, 1 reply; 38+ messages in thread
From: Jean Delvare @ 2008-06-04 18:13 UTC (permalink / raw)
  To: Linux I2C; +Cc: David Brownell

Hi all,

This patch set demonstrates a new concept which I would like to add to
the i2c subsystem. It is named "i2c listeners" and is based on the
following structure:

/**
 * struct i2c_listener - Be informed of adapter addition and removal
 * @class: What kind of i2c device the listener may instantiate
 * @attach_adapter: Called after adapter addition (unimplemented)
 * @detach_adapter: Called before adapter removal (unimplemented)
 * @address_data: The I2C addresses to probe, ignore or force
 * @detect: Callback for device detection
 * @clients: List of detected clients we created
 *
 * The @detect callback returns an i2c_board_info structure for device
 * creation if the detection was successful, NULL otherwise.
 *
 * The @clients list is handled by i2c-core.
 */
struct i2c_listener {
	unsigned int class;

	int (*attach_adapter)(struct i2c_adapter *);
	int (*detach_adapter)(struct i2c_adapter *);

	const struct i2c_client_address_data *address_data;
	int (*detect)(struct i2c_adapter *, int address, int kind,
		      struct i2c_board_info *);
	struct list_head clients;

	struct list_head list;
};

The goal is to replace legacy i2c drivers. The functional differences
between legacy drivers and new-style ones are that legacy drivers get
notified when i2c adapters are created or deleted, they create their
own devices, and they can probe the hardware before they do so. There
are cases where we want to be able to do this (e.g. for hardware
monitoring devices on PC motherboards) so we can't just switch to
new-style everywhere. Still, legacy drivers are a pain to handle, they
cause headaches to developers because their locking model is weird, and
they duplicate a lot of code.

By implementing the needed functionality, almost unchanged, outside of
the drivers, my hope is to be able to convert all legacy drivers to
new-style drivers in a matter of months. Without it, it would take
years... or even never happen at all.

There are two distinct parts in i2c_listener: the notification
callbacks, and the device detection callback. The notification
callbacks are exactly the same as what legacy i2c drivers already have.
I did not implement them yet, as I have no immediate need for them, but
I suspect I will have to for the V4L/DVB drivers (if not I'll just
remove them.) The device detection part is implemented in patch 1/4.

The mechanism behind the device detection callback is as follows:
* When a new i2c_notifier is added, for each existing i2c_adapter,
  address_data (those format is the same as what i2c_probe() is already
  using for legacy drivers) is processed by i2c-core. For each relevant
  address, the detect callback will be called, with a pointer to an
  empty struct i2c_board_info address as the last parameter. The detect
  callback will attempt to detect a supported device at the given
  address, and if successful, it will fill the struct i2c_board_info
  with the parameters required to instantiate a new-style i2c device.
* When a new i2c_adapter is added, for each existing i2c_notifier, the
  same happens.
* When it gets a filled struct i2c_board_info from a detect callback,
  i2c-core will instantiate it. If a new-style driver exists for the
  device, it will be able to bind with the device.
* We keep track of the devices created that way, in a per-listener list.
* When an i2c_listener is removed, all devices that originate from it
  are destroyed.
* When an i2c_adapter is removed, all devices on it that were created
  by an i2c_listener are destroyed.

So, drivers which currently implement both a new-style i2c_driver and a
legacy i2c_driver (or drivers which would be converted that way soon) can
instead implement a new-style i2c_driver and an i2c_listener. There are
two major advantages in doing so:
* All i2c drivers become new-style drivers. We get rid of legacy
  drivers altogether, allowing for long awaited cleanups in i2c-core.
* The code needed in each driver to implement an i2c_listener is way
  smaller than the code needed to implement a legacy driver, even when
  we were sharing as much code as possible between the new-style driver
  and the legacy driver. This is very visible in patches 3/4 and 4/4,
  which remove ~35 lines of code per driver.

I would appreciate feedback on both the concept and the implementation.
David, I am particularly interested in your feedback, of course.

Patch 1/4 implements the mechanism, then patches 2/4, 3/4 and 4/4
demonstrate its use in 3 hardware monitoring drivers (lm90, f75375s and
lm75, respectively.) The patches go on top of 2.6.26-rc4 with some
additional dependencies listed in each patch. Testers welcome!

-- 
Jean Delvare

_______________________________________________
i2c mailing list
i2c-GZX6beZjE8VD60Wz+7aTrA@public.gmane.org
http://lists.lm-sensors.org/mailman/listinfo/i2c

^ permalink raw reply	[flat|nested] 38+ messages in thread
* [PATCH 0/4] i2c: Add detection capability to new-style drivers
@ 2008-06-06 12:52 Jean Delvare
       [not found] ` <20080606145212.76f95d52-ig7AzVSIIG7kN2dkZ6Wm7A@public.gmane.org>
  0 siblings, 1 reply; 38+ messages in thread
From: Jean Delvare @ 2008-06-06 12:52 UTC (permalink / raw)
  To: Linux I2C; +Cc: David Brownell

Hi all,

This is an update of the patch set named "i2c: Introduce i2c listeners"
which I posted 2 days ago. The only change if that the detect callback
is no longer in a separate i2c_listener structure, but instead is added
to struct i2c_driver (for new-style drivers only.) This makes things
much more simple.

The goal is to replace legacy i2c drivers. The functional differences
between legacy drivers and new-style ones are that legacy drivers get
notified when i2c adapters are created or deleted, they create their
own devices, and they can probe the hardware before they do so. There
are cases where we want to be able to do this (e.g. for hardware
monitoring devices on PC motherboards) so we can't just switch to
new-style everywhere. Still, legacy drivers are a pain to handle, they
cause headaches to developers because their locking model is weird, and
they duplicate a lot of code.

By implementing the needed functionality, almost unchanged, in a way
which is compatible with the new i2c device/driver binding model, my
hope is to be able to convert all legacy drivers to new-style drivers
in a matter of months. Without it, it would take years... or even never
happen at all. This patch set attempts to cover the device detection
part. The notification of additional/removal of adapters will be dealt
with later.

The mechanism behind the device detection callback is as follows:
* When a new-style i2c_driver is added, for each existing i2c_adapter,
  address_data (those format is the same as what i2c_probe() is already
  using for legacy drivers) is processed by i2c-core. For each relevant
  address, the detect callback will be called, with a pointer to an
  empty struct i2c_board_info address as the last parameter. The detect
  callback will attempt to identify a supported device at the given
  address, and if successful, it will fill the struct i2c_board_info
  with the parameters required to instantiate a new-style i2c device.
* When a new i2c_adapter is added, for each existing new-style
  i2c_driver, the same happens.
* When it gets a filled struct i2c_board_info from a detect callback,
  i2c-core will instantiate it. If a new-style driver exists for the
  device, it will be able to bind with the device.
* We keep track of the devices created that way, in a per-driver list.
* When a new-style i2c_driver is removed, all devices that originate
  from it are destroyed.
* When an i2c_adapter is removed, all devices on it that were created
  as the result of calling a detect callback, are destroyed.

So, drivers which currently implement both a new-style i2c_driver and a
legacy i2c_driver (or drivers which would be converted that way soon) can
instead implement a detect callback in their new-style i2c_driver.
There are two major advantages in doing so:
* All i2c drivers become new-style drivers. We get rid of legacy
  drivers altogether, allowing for long awaited cleanups in i2c-core.
* The code needed in each driver to implement a detect callback is way
  smaller than the code needed to implement a legacy driver, even when
  we were sharing as much code as possible between the new-style driver
  and the legacy driver. This is very visible in patches 3/4 and 4/4,
  which remove 50 lines of code per driver.

I would appreciate feedback on both the concept and the implementation.
David, I am particularly interested in your feedback, of course.

Patch 1/4 implements the mechanism, then patches 2/4, 3/4 and 4/4
demonstrate its use in 3 hardware monitoring drivers (lm90, f75375s and
lm75, respectively.) The patches go on top of 2.6.26-rc4 with some
additional dependencies listed in each patch. Testers welcome!

-- 
Jean Delvare

_______________________________________________
i2c mailing list
i2c-GZX6beZjE8VD60Wz+7aTrA@public.gmane.org
http://lists.lm-sensors.org/mailman/listinfo/i2c

^ permalink raw reply	[flat|nested] 38+ messages in thread

end of thread, other threads:[~2008-06-06 14:09 UTC | newest]

Thread overview: 38+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-06-04 18:13 [PATCH 0/4] i2c: Introduce i2c listeners Jean Delvare
     [not found] ` <20080604201334.19636f30-ig7AzVSIIG7kN2dkZ6Wm7A@public.gmane.org>
2008-06-04 18:18   ` [PATCH 1/4] " Jean Delvare
2008-06-04 18:31   ` [PATCH 2/4] i2c: Convert the lm90 driver to a new-style i2c driver Jean Delvare
2008-06-04 18:33   ` [PATCH 3/4] i2c: Use i2c_listener in driver f75375s Jean Delvare
     [not found]     ` <20080604203322.472f8653-ig7AzVSIIG7kN2dkZ6Wm7A@public.gmane.org>
2008-06-05  8:33       ` Riku Voipio
     [not found]         ` <4847A4E2.9040406-WgUW+8SLYMv1KXRcyAk9cg@public.gmane.org>
2008-06-05  9:06           ` Jean Delvare
     [not found]             ` <20080605110659.3456fbe4-ig7AzVSIIG7kN2dkZ6Wm7A@public.gmane.org>
2008-06-06 10:21               ` Riku Voipio
     [not found]                 ` <48490FA3.8020702-WgUW+8SLYMv1KXRcyAk9cg@public.gmane.org>
2008-06-06 11:38                   ` Jean Delvare
2008-06-04 18:35   ` [PATCH 4/4] i2c: Use i2c_listener in driver lm75 Jean Delvare
2008-06-04 18:55   ` [PATCH 0/4] i2c: Introduce i2c listeners Jon Smirl
     [not found]     ` <9e4733910806041155n7551ac74lf29c8a32163ec09a-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2008-06-04 19:28       ` Jon Smirl
     [not found]         ` <9e4733910806041228i330e145q439d3ee43494f4c4-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2008-06-04 21:33           ` Jean Delvare
     [not found]             ` <20080604233335.13459512-ig7AzVSIIG7kN2dkZ6Wm7A@public.gmane.org>
2008-06-04 23:11               ` Jon Smirl
     [not found]                 ` <9e4733910806041611l41832e07p4f55424be0ef5ea0-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2008-06-05  0:10                   ` David Brownell
     [not found]                     ` <200806041710.59338.david-b-yBeKhBN/0LDR7s880joybQ@public.gmane.org>
2008-06-05  0:42                       ` Jon Smirl
     [not found]                         ` <9e4733910806041742va67401en608c8c4b8c4c11b9-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2008-06-05  2:21                           ` David Brownell
     [not found]                             ` <200806041921.26293.david-b-yBeKhBN/0LDR7s880joybQ@public.gmane.org>
2008-06-05  4:04                               ` Jon Smirl
     [not found]                                 ` <9e4733910806042104l70cf8a30sc6329b1c3016c879-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2008-06-05  8:18                                   ` David Brownell
     [not found]                                     ` <200806050118.23706.david-b-yBeKhBN/0LDR7s880joybQ@public.gmane.org>
2008-06-05 14:55                                       ` Jon Smirl
     [not found]                                         ` <9e4733910806050755n3835d20xfc4d018c2222d5d3-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2008-06-05 17:00                                           ` Jean Delvare
     [not found]                                             ` <20080605190034.16f06604-ig7AzVSIIG7kN2dkZ6Wm7A@public.gmane.org>
2008-06-05 17:34                                               ` Jon Smirl
     [not found]                                                 ` <9e4733910806051034k2e40082focaaa03b124fcd4ad-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2008-06-05 18:29                                                   ` Jean Delvare
2008-06-05  8:49                                   ` Jean Delvare
     [not found]                                     ` <20080605104914.2dd622b2-ig7AzVSIIG7kN2dkZ6Wm7A@public.gmane.org>
2008-06-05 14:30                                       ` Jon Smirl
2008-06-05  8:38                           ` Jean Delvare
2008-06-05  9:05                   ` Jean Delvare
     [not found]                     ` <20080605110502.76f0f606-ig7AzVSIIG7kN2dkZ6Wm7A@public.gmane.org>
2008-06-05 14:59                       ` Jon Smirl
2008-06-05  0:03               ` Trent Piepho
     [not found]                 ` <Pine.LNX.4.58.0806041638080.10290-13q4cmjDBaTP3RPoUHIrnuTW4wlIGRCZ@public.gmane.org>
2008-06-05  0:27                   ` David Brownell
     [not found]                     ` <200806041727.51746.david-b-yBeKhBN/0LDR7s880joybQ@public.gmane.org>
2008-06-05  0:40                       ` Trent Piepho
     [not found]                         ` <Pine.LNX.4.58.0806041731250.10290-13q4cmjDBaTP3RPoUHIrnuTW4wlIGRCZ@public.gmane.org>
2008-06-05  2:14                           ` David Brownell
     [not found]                             ` <200806041914.27291.david-b-yBeKhBN/0LDR7s880joybQ@public.gmane.org>
2008-06-05  7:08                               ` Trent Piepho
     [not found]                                 ` <Pine.LNX.4.58.0806042349251.10290-13q4cmjDBaTP3RPoUHIrnuTW4wlIGRCZ@public.gmane.org>
2008-06-05  8:15                                   ` David Brownell
2008-06-05  8:16                           ` Jean Delvare
2008-06-05  0:45                       ` Jon Smirl
2008-06-04 21:12       ` Jean Delvare
2008-06-06  2:47   ` David Brownell
  -- strict thread matches above, loose matches on Subject: below --
2008-06-06 12:52 [PATCH 0/4] i2c: Add detection capability to new-style drivers Jean Delvare
     [not found] ` <20080606145212.76f95d52-ig7AzVSIIG7kN2dkZ6Wm7A@public.gmane.org>
2008-06-06 14:09   ` [PATCH 2/4] i2c: Convert the lm90 driver to a new-style i2c driver Jean Delvare

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