From: Hans de Goede <j.w.r.degoede-fbo2DhPpy/Q@public.gmane.org>
To: Jean Delvare <khali-PUYAD+kWke1g9hUCZPvPmw@public.gmane.org>
Cc: Alexandre d'Alton <alex-jojFES6RfZNxtahE/wReCQ@public.gmane.org>,
Linux I2C <i2c-GZX6beZjE8VD60Wz+7aTrA@public.gmane.org>,
LM Sensors <lm-sensors-GZX6beZjE8VD60Wz+7aTrA@public.gmane.org>
Subject: Re: [lm-sensors] [PATCH] hwmon: (adm1031) Convert to a new-style i2c driver
Date: Wed, 16 Jul 2008 20:14:18 +0200 [thread overview]
Message-ID: <487E3A7A.9070705@hhs.nl> (raw)
In-Reply-To: <20080716145157.0187af72-ig7AzVSIIG7kN2dkZ6Wm7A@public.gmane.org>
Jean Delvare wrote:
> The new-style adm1031 driver implements the optional detect() callback
> to cover the use cases of the legacy driver.
>
> Signed-off-by: Jean Delvare <khali-PUYAD+kWke1g9hUCZPvPmw@public.gmane.org>
> Cc: Alexandre d'Alton <alex-jojFES6RfZNxtahE/wReCQ@public.gmane.org>
Looks good,
Acked-by: Hans de Goede <j.w.r.degoede-fbo2DhPpy/Q@public.gmane.org>
Regards,
Hans
> ---
> drivers/hwmon/adm1031.c | 96 +++++++++++++++++++++++------------------------
> 1 file changed, 49 insertions(+), 47 deletions(-)
>
> --- linux-2.6.26-rc9.orig/drivers/hwmon/adm1031.c 2008-07-12 09:20:31.000000000 +0200
> +++ linux-2.6.26-rc9/drivers/hwmon/adm1031.c 2008-07-12 10:27:32.000000000 +0200
> @@ -70,7 +70,6 @@ typedef u8 auto_chan_table_t[8][2];
>
> /* Each client has this additional data */
> struct adm1031_data {
> - struct i2c_client client;
> struct device *hwmon_dev;
> struct mutex update_lock;
> int chip_type;
> @@ -99,19 +98,32 @@ struct adm1031_data {
> s8 temp_crit[3];
> };
>
> -static int adm1031_attach_adapter(struct i2c_adapter *adapter);
> -static int adm1031_detect(struct i2c_adapter *adapter, int address, int kind);
> +static int adm1031_probe(struct i2c_client *client,
> + const struct i2c_device_id *id);
> +static int adm1031_detect(struct i2c_client *client, int kind,
> + struct i2c_board_info *info);
> static void adm1031_init_client(struct i2c_client *client);
> -static int adm1031_detach_client(struct i2c_client *client);
> +static int adm1031_remove(struct i2c_client *client);
> static struct adm1031_data *adm1031_update_device(struct device *dev);
>
> +static const struct i2c_device_id adm1031_id[] = {
> + { "adm1030", adm1030 },
> + { "adm1031", adm1031 },
> + { }
> +};
> +MODULE_DEVICE_TABLE(i2c, adm1031_id);
> +
> /* This is the driver that will be inserted */
> static struct i2c_driver adm1031_driver = {
> + .class = I2C_CLASS_HWMON,
> .driver = {
> .name = "adm1031",
> },
> - .attach_adapter = adm1031_attach_adapter,
> - .detach_client = adm1031_detach_client,
> + .probe = adm1031_probe,
> + .remove = adm1031_remove,
> + .id_table = adm1031_id,
> + .detect = adm1031_detect,
> + .address_data = &addr_data,
> };
>
> static inline u8 adm1031_read_value(struct i2c_client *client, u8 reg)
> @@ -693,13 +705,6 @@ static SENSOR_DEVICE_ATTR(temp3_crit_ala
> static SENSOR_DEVICE_ATTR(temp3_fault, S_IRUGO, show_alarm, NULL, 13);
> static SENSOR_DEVICE_ATTR(temp1_crit_alarm, S_IRUGO, show_alarm, NULL, 14);
>
> -static int adm1031_attach_adapter(struct i2c_adapter *adapter)
> -{
> - if (!(adapter->class & I2C_CLASS_HWMON))
> - return 0;
> - return i2c_probe(adapter, &addr_data, adm1031_detect);
> -}
> -
> static struct attribute *adm1031_attributes[] = {
> &sensor_dev_attr_fan1_input.dev_attr.attr,
> &sensor_dev_attr_fan1_div.dev_attr.attr,
> @@ -770,27 +775,15 @@ static const struct attribute_group adm1
> .attrs = adm1031_attributes_opt,
> };
>
> -/* This function is called by i2c_probe */
> -static int adm1031_detect(struct i2c_adapter *adapter, int address, int kind)
> +/* Return 0 if detection is successful, -ENODEV otherwise */
> +static int adm1031_detect(struct i2c_client *client, int kind,
> + struct i2c_board_info *info)
> {
> - struct i2c_client *client;
> - struct adm1031_data *data;
> - int err = 0;
> + struct i2c_adapter *adapter = client->adapter;
> const char *name = "";
>
> if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA))
> - goto exit;
> -
> - if (!(data = kzalloc(sizeof(struct adm1031_data), GFP_KERNEL))) {
> - err = -ENOMEM;
> - goto exit;
> - }
> -
> - client = &data->client;
> - i2c_set_clientdata(client, data);
> - client->addr = address;
> - client->adapter = adapter;
> - client->driver = &adm1031_driver;
> + return -ENODEV;
>
> if (kind < 0) {
> int id, co;
> @@ -798,7 +791,7 @@ static int adm1031_detect(struct i2c_ada
> co = i2c_smbus_read_byte_data(client, 0x3e);
>
> if (!((id == 0x31 || id == 0x30) && co == 0x41))
> - goto exit_free;
> + return -ENODEV;
> kind = (id == 0x30) ? adm1030 : adm1031;
> }
>
> @@ -809,28 +802,43 @@ static int adm1031_detect(struct i2c_ada
> * auto fan control helper table. */
> if (kind == adm1030) {
> name = "adm1030";
> - data->chan_select_table = &auto_channel_select_table_adm1030;
> } else if (kind == adm1031) {
> name = "adm1031";
> - data->chan_select_table = &auto_channel_select_table_adm1031;
> }
> - data->chip_type = kind;
> + strlcpy(info->type, name, I2C_NAME_SIZE);
>
> - strlcpy(client->name, name, I2C_NAME_SIZE);
> + return 0;
> +}
> +
> +static int adm1031_probe(struct i2c_client *client,
> + const struct i2c_device_id *id)
> +{
> + struct adm1031_data *data;
> + int err;
> +
> + data = kzalloc(sizeof(struct adm1031_data), GFP_KERNEL);
> + if (!data) {
> + err = -ENOMEM;
> + goto exit;
> + }
> +
> + i2c_set_clientdata(client, data);
> + data->chip_type = id->driver_data;
> mutex_init(&data->update_lock);
>
> - /* Tell the I2C layer a new client has arrived */
> - if ((err = i2c_attach_client(client)))
> - goto exit_free;
> + if (data->chip_type == adm1030)
> + data->chan_select_table = &auto_channel_select_table_adm1030;
> + else
> + data->chan_select_table = &auto_channel_select_table_adm1031;
>
> /* Initialize the ADM1031 chip */
> adm1031_init_client(client);
>
> /* Register sysfs hooks */
> if ((err = sysfs_create_group(&client->dev.kobj, &adm1031_group)))
> - goto exit_detach;
> + goto exit_free;
>
> - if (kind == adm1031) {
> + if (data->chip_type == adm1031) {
> if ((err = sysfs_create_group(&client->dev.kobj,
> &adm1031_group_opt)))
> goto exit_remove;
> @@ -847,25 +855,19 @@ static int adm1031_detect(struct i2c_ada
> exit_remove:
> sysfs_remove_group(&client->dev.kobj, &adm1031_group);
> sysfs_remove_group(&client->dev.kobj, &adm1031_group_opt);
> -exit_detach:
> - i2c_detach_client(client);
> exit_free:
> kfree(data);
> exit:
> return err;
> }
>
> -static int adm1031_detach_client(struct i2c_client *client)
> +static int adm1031_remove(struct i2c_client *client)
> {
> struct adm1031_data *data = i2c_get_clientdata(client);
> - int ret;
>
> hwmon_device_unregister(data->hwmon_dev);
> sysfs_remove_group(&client->dev.kobj, &adm1031_group);
> sysfs_remove_group(&client->dev.kobj, &adm1031_group_opt);
> - if ((ret = i2c_detach_client(client)) != 0) {
> - return ret;
> - }
> kfree(data);
> return 0;
> }
>
>
_______________________________________________
i2c mailing list
i2c-GZX6beZjE8VD60Wz+7aTrA@public.gmane.org
http://lists.lm-sensors.org/mailman/listinfo/i2c
prev parent reply other threads:[~2008-07-16 18:14 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-07-16 12:51 [PATCH] hwmon: (adm1031) Convert to a new-style i2c driver Jean Delvare
[not found] ` <20080716145157.0187af72-ig7AzVSIIG7kN2dkZ6Wm7A@public.gmane.org>
2008-07-16 18:14 ` Hans de Goede [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=487E3A7A.9070705@hhs.nl \
--to=j.w.r.degoede-fbo2dhppy/q@public.gmane.org \
--cc=alex-jojFES6RfZNxtahE/wReCQ@public.gmane.org \
--cc=i2c-GZX6beZjE8VD60Wz+7aTrA@public.gmane.org \
--cc=khali-PUYAD+kWke1g9hUCZPvPmw@public.gmane.org \
--cc=lm-sensors-GZX6beZjE8VD60Wz+7aTrA@public.gmane.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox