[i2c] [patch 1/5] i2c stack can probe()

Jean Delvare khali at linux-fr.org
Fri Mar 2 21:15:42 CET 2007


Oh, BTW...

On Thu, 15 Feb 2007 00:41:37 -0800, David Brownell wrote:
>  static int i2c_device_match(struct device *dev, struct device_driver *drv)
>  {
> -	return 1;
> +	struct i2c_client	*client = to_i2c_client(dev);
> +	struct i2c_driver	*driver = to_i2c_driver(drv);
> +
> +	/* legacy i2c drivers bypass driver model probing entirely;
> +	 * such drivers scan each i2c adapter/bus themselves.
> +	 */
> +	if (!driver->probe)
> +		return 0;
> +
> +	/* new style drivers use the same driver matching policy as
> +	 * platform devices or SPI:  compare device and driver names.
> +	 */
> +	return strcmp(client->name, drv->name) == 0;
>  }

We still need to discuss this. I think this approach is too simplistic
for some of our i2c drivers. Many of them support several device types,
and so far we have used a different client name for each of them (in
most cases.) In order to match this model, each i2c driver should embed
a null-terminated list of devices it supports and this match() function
should walk the list searching for an entry matching the client name.

I seem to remember that you objected to this approach, but I can't
remember what you offered as an alternative for drivers supporting
several devices.

Another (possibly related) thing to consider here is that we will need
a way to instantiate i2c clients from user-space. The hardware
monitoring drivers let us do that at the moment, this is very useful
when detection doesn't work for any reason, and I don't want to lose
the functionality in the migration. How do you plan to implement that
in the new model (if you thought about it at all)?

> +static ssize_t show_client_name(struct device *dev, struct device_attribute *attr, char *buf)
> +{
> +	struct i2c_client *client = to_i2c_client(dev);
> +	return sprintf(buf, "%s\n", client->name);
> +}
> +
> +static /*const*/ struct device_attribute i2c_dev_attrs[] = {
> +	__ATTR(name, S_IRUGO, show_client_name, NULL),
> +	/* modalias helps coldplug:  modprobe $(cat .../modalias) */
> +	__ATTR(modalias, S_IRUGO, show_client_name, NULL),
> +	{ },
> +};

Which makes me realize that here you assume that client name == driver
name, which is true in your design, but as I underlined above, not in
the reality for many current i2c drivers.

-- 
Jean Delvare



More information about the i2c mailing list