[i2c] [patch 2.6.21-rc3-git +i2c 4/5] i2c board_info and i2c_new_device()
Jean Delvare
khali at linux-fr.org
Sun Mar 18 20:15:28 CET 2007
Hi David,
On Thu, 15 Mar 2007 16:12:33 -0700, David Brownell wrote:
> +/**
> + * i2c_new_device - instantiate an i2c device for use with a new style driver
> + * @adap: the adapter managing the device
> + * @info: describes one I2C device; bus_num is ignored
> + *
> + * Create a device to work with a new style i2c driver, where binding is
> + * handled through driver model probe()/remove() methods. This call is not
> + * appropriate for use by mainboad initialization logic, which usually runs
> + * during an arch_initcall() long before any i2c_adapter could exist.
> + *
> + * This returns the new i2c client, which may be saved for later use with
> + * i2c_unregister_device(); or NULL to indicate an error.
> + */
> +struct i2c_client *
> +i2c_new_device(struct i2c_adapter *adap, struct i2c_board_info const *info)
> +{
> + struct i2c_client *client;
> + int status;
> +
> + client = kzalloc(sizeof *client, GFP_KERNEL);
> + if (!client)
> + return NULL;
> +
> + client->adapter = adap;
> +
> + client->driver_name = info->driver_name;
> + client->dev.platform_data = info->platform_data;
> + client->flags = info->flags;
> + client->addr = info->addr;
> + client->irq = info->irq;
> +
> + strlcpy(client->name, info->type, sizeof(adap->name));
I changed that to:
strlcpy(client->name, info->type, sizeof(client->name));
Hope you don't mind ;)
> +
> + /* a new style driver may be bound to this device when we
> + * return from this function, or any later moment (e.g. maybe
> + * hotplugging will load the driver module). and the device
> + * refcount model is the standard driver model one.
> + */
> + status = i2c_attach_client(client);
> + if (status < 0) {
> + kfree(client);
> + client = NULL;
> + }
> + return client;
> +}
> +EXPORT_SYMBOL_GPL(i2c_new_device);
--
Jean Delvare
More information about the i2c
mailing list