* [PATCH] hwmon: (adm9240) Convert to a new-style i2c driver
@ 2008-07-16 14:32 Jean Delvare
[not found] ` <20080716163257.107e9340-ig7AzVSIIG7kN2dkZ6Wm7A@public.gmane.org>
0 siblings, 1 reply; 3+ messages in thread
From: Jean Delvare @ 2008-07-16 14:32 UTC (permalink / raw)
To: Linux I2C, LM Sensors; +Cc: Grant Coady
The new-style adm9240 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: Grant Coady <gcoady.lk-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
---
drivers/hwmon/adm9240.c | 93 +++++++++++++++++++++++------------------------
1 file changed, 46 insertions(+), 47 deletions(-)
--- linux-2.6.26-rc9.orig/drivers/hwmon/adm9240.c 2008-07-12 09:20:31.000000000 +0200
+++ linux-2.6.26-rc9/drivers/hwmon/adm9240.c 2008-07-12 10:27:31.000000000 +0200
@@ -130,25 +130,37 @@ static inline unsigned int AOUT_FROM_REG
return SCALE(reg, 1250, 255);
}
-static int adm9240_attach_adapter(struct i2c_adapter *adapter);
-static int adm9240_detect(struct i2c_adapter *adapter, int address, int kind);
+static int adm9240_probe(struct i2c_client *client,
+ const struct i2c_device_id *id);
+static int adm9240_detect(struct i2c_client *client, int kind,
+ struct i2c_board_info *info);
static void adm9240_init_client(struct i2c_client *client);
-static int adm9240_detach_client(struct i2c_client *client);
+static int adm9240_remove(struct i2c_client *client);
static struct adm9240_data *adm9240_update_device(struct device *dev);
/* driver data */
+static const struct i2c_device_id adm9240_id[] = {
+ { "adm9240", adm9240 },
+ { "ds1780", ds1780 },
+ { "lm81", lm81 },
+ { }
+};
+MODULE_DEVICE_TABLE(i2c, adm9240_id);
+
static struct i2c_driver adm9240_driver = {
+ .class = I2C_CLASS_HWMON,
.driver = {
.name = "adm9240",
},
- .attach_adapter = adm9240_attach_adapter,
- .detach_client = adm9240_detach_client,
+ .probe = adm9240_probe,
+ .remove = adm9240_remove,
+ .id_table = adm9240_id,
+ .detect = adm9240_detect,
+ .address_data = &addr_data,
};
/* per client data */
struct adm9240_data {
- enum chips type;
- struct i2c_client client;
struct device *hwmon_dev;
struct mutex update_lock;
char valid;
@@ -532,28 +544,17 @@ static const struct attribute_group adm9
/*** sensor chip detect and driver install ***/
-static int adm9240_detect(struct i2c_adapter *adapter, int address, int kind)
+/* Return 0 if detection is successful, -ENODEV otherwise */
+static int adm9240_detect(struct i2c_client *new_client, int kind,
+ struct i2c_board_info *info)
{
- struct i2c_client *new_client;
- struct adm9240_data *data;
- int err = 0;
+ struct i2c_adapter *adapter = new_client->adapter;
const char *name = "";
+ int address = new_client->addr;
u8 man_id, die_rev;
if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA))
- goto exit;
-
- if (!(data = kzalloc(sizeof(*data), GFP_KERNEL))) {
- err = -ENOMEM;
- goto exit;
- }
-
- new_client = &data->client;
- i2c_set_clientdata(new_client, data);
- new_client->addr = address;
- new_client->adapter = adapter;
- new_client->driver = &adm9240_driver;
- new_client->flags = 0;
+ return -ENODEV;
if (kind == 0) {
kind = adm9240;
@@ -566,7 +567,7 @@ static int adm9240_detect(struct i2c_ada
!= address) {
dev_err(&adapter->dev, "detect fail: address match, "
"0x%02x\n", address);
- goto exit_free;
+ return -ENODEV;
}
/* check known chip manufacturer */
@@ -581,7 +582,7 @@ static int adm9240_detect(struct i2c_ada
} else {
dev_err(&adapter->dev, "detect fail: unknown manuf, "
"0x%02x\n", man_id);
- goto exit_free;
+ return -ENODEV;
}
/* successful detect, print chip info */
@@ -600,20 +601,31 @@ static int adm9240_detect(struct i2c_ada
} else if (kind == lm81) {
name = "lm81";
}
+ strlcpy(info->type, name, I2C_NAME_SIZE);
- /* fill in the remaining client fields and attach */
- strlcpy(new_client->name, name, I2C_NAME_SIZE);
- data->type = kind;
- mutex_init(&data->update_lock);
+ return 0;
+}
- if ((err = i2c_attach_client(new_client)))
- goto exit_free;
+static int adm9240_probe(struct i2c_client *new_client,
+ const struct i2c_device_id *id)
+{
+ struct adm9240_data *data;
+ int err;
+
+ data = kzalloc(sizeof(*data), GFP_KERNEL);
+ if (!data) {
+ err = -ENOMEM;
+ goto exit;
+ }
+
+ i2c_set_clientdata(new_client, data);
+ mutex_init(&data->update_lock);
adm9240_init_client(new_client);
/* populate sysfs filesystem */
if ((err = sysfs_create_group(&new_client->dev.kobj, &adm9240_group)))
- goto exit_detach;
+ goto exit_free;
data->hwmon_dev = hwmon_device_register(&new_client->dev);
if (IS_ERR(data->hwmon_dev)) {
@@ -625,32 +637,19 @@ static int adm9240_detect(struct i2c_ada
exit_remove:
sysfs_remove_group(&new_client->dev.kobj, &adm9240_group);
-exit_detach:
- i2c_detach_client(new_client);
exit_free:
kfree(data);
exit:
return err;
}
-static int adm9240_attach_adapter(struct i2c_adapter *adapter)
-{
- if (!(adapter->class & I2C_CLASS_HWMON))
- return 0;
- return i2c_probe(adapter, &addr_data, adm9240_detect);
-}
-
-static int adm9240_detach_client(struct i2c_client *client)
+static int adm9240_remove(struct i2c_client *client)
{
struct adm9240_data *data = i2c_get_clientdata(client);
- int err;
hwmon_device_unregister(data->hwmon_dev);
sysfs_remove_group(&client->dev.kobj, &adm9240_group);
- if ((err = i2c_detach_client(client)))
- return err;
-
kfree(data);
return 0;
}
--
Jean Delvare
_______________________________________________
i2c mailing list
i2c-GZX6beZjE8VD60Wz+7aTrA@public.gmane.org
http://lists.lm-sensors.org/mailman/listinfo/i2c
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [lm-sensors] [PATCH] hwmon: (adm9240) Convert to a new-style i2c driver
[not found] ` <20080716163257.107e9340-ig7AzVSIIG7kN2dkZ6Wm7A@public.gmane.org>
@ 2008-07-16 18:16 ` Hans de Goede
2008-07-18 1:17 ` Grant Coady
1 sibling, 0 replies; 3+ messages in thread
From: Hans de Goede @ 2008-07-16 18:16 UTC (permalink / raw)
To: Jean Delvare; +Cc: Grant Coady, Linux I2C, LM Sensors
Jean Delvare wrote:
> The new-style adm9240 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: Grant Coady <gcoady.lk-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
Looks good,
Acked-by: Hans de Goede <j.w.r.degoede-fbo2DhPpy/Q@public.gmane.org>
Regards,
Hans
> ---
> drivers/hwmon/adm9240.c | 93 +++++++++++++++++++++++------------------------
> 1 file changed, 46 insertions(+), 47 deletions(-)
>
> --- linux-2.6.26-rc9.orig/drivers/hwmon/adm9240.c 2008-07-12 09:20:31.000000000 +0200
> +++ linux-2.6.26-rc9/drivers/hwmon/adm9240.c 2008-07-12 10:27:31.000000000 +0200
> @@ -130,25 +130,37 @@ static inline unsigned int AOUT_FROM_REG
> return SCALE(reg, 1250, 255);
> }
>
> -static int adm9240_attach_adapter(struct i2c_adapter *adapter);
> -static int adm9240_detect(struct i2c_adapter *adapter, int address, int kind);
> +static int adm9240_probe(struct i2c_client *client,
> + const struct i2c_device_id *id);
> +static int adm9240_detect(struct i2c_client *client, int kind,
> + struct i2c_board_info *info);
> static void adm9240_init_client(struct i2c_client *client);
> -static int adm9240_detach_client(struct i2c_client *client);
> +static int adm9240_remove(struct i2c_client *client);
> static struct adm9240_data *adm9240_update_device(struct device *dev);
>
> /* driver data */
> +static const struct i2c_device_id adm9240_id[] = {
> + { "adm9240", adm9240 },
> + { "ds1780", ds1780 },
> + { "lm81", lm81 },
> + { }
> +};
> +MODULE_DEVICE_TABLE(i2c, adm9240_id);
> +
> static struct i2c_driver adm9240_driver = {
> + .class = I2C_CLASS_HWMON,
> .driver = {
> .name = "adm9240",
> },
> - .attach_adapter = adm9240_attach_adapter,
> - .detach_client = adm9240_detach_client,
> + .probe = adm9240_probe,
> + .remove = adm9240_remove,
> + .id_table = adm9240_id,
> + .detect = adm9240_detect,
> + .address_data = &addr_data,
> };
>
> /* per client data */
> struct adm9240_data {
> - enum chips type;
> - struct i2c_client client;
> struct device *hwmon_dev;
> struct mutex update_lock;
> char valid;
> @@ -532,28 +544,17 @@ static const struct attribute_group adm9
>
> /*** sensor chip detect and driver install ***/
>
> -static int adm9240_detect(struct i2c_adapter *adapter, int address, int kind)
> +/* Return 0 if detection is successful, -ENODEV otherwise */
> +static int adm9240_detect(struct i2c_client *new_client, int kind,
> + struct i2c_board_info *info)
> {
> - struct i2c_client *new_client;
> - struct adm9240_data *data;
> - int err = 0;
> + struct i2c_adapter *adapter = new_client->adapter;
> const char *name = "";
> + int address = new_client->addr;
> u8 man_id, die_rev;
>
> if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA))
> - goto exit;
> -
> - if (!(data = kzalloc(sizeof(*data), GFP_KERNEL))) {
> - err = -ENOMEM;
> - goto exit;
> - }
> -
> - new_client = &data->client;
> - i2c_set_clientdata(new_client, data);
> - new_client->addr = address;
> - new_client->adapter = adapter;
> - new_client->driver = &adm9240_driver;
> - new_client->flags = 0;
> + return -ENODEV;
>
> if (kind == 0) {
> kind = adm9240;
> @@ -566,7 +567,7 @@ static int adm9240_detect(struct i2c_ada
> != address) {
> dev_err(&adapter->dev, "detect fail: address match, "
> "0x%02x\n", address);
> - goto exit_free;
> + return -ENODEV;
> }
>
> /* check known chip manufacturer */
> @@ -581,7 +582,7 @@ static int adm9240_detect(struct i2c_ada
> } else {
> dev_err(&adapter->dev, "detect fail: unknown manuf, "
> "0x%02x\n", man_id);
> - goto exit_free;
> + return -ENODEV;
> }
>
> /* successful detect, print chip info */
> @@ -600,20 +601,31 @@ static int adm9240_detect(struct i2c_ada
> } else if (kind == lm81) {
> name = "lm81";
> }
> + strlcpy(info->type, name, I2C_NAME_SIZE);
>
> - /* fill in the remaining client fields and attach */
> - strlcpy(new_client->name, name, I2C_NAME_SIZE);
> - data->type = kind;
> - mutex_init(&data->update_lock);
> + return 0;
> +}
>
> - if ((err = i2c_attach_client(new_client)))
> - goto exit_free;
> +static int adm9240_probe(struct i2c_client *new_client,
> + const struct i2c_device_id *id)
> +{
> + struct adm9240_data *data;
> + int err;
> +
> + data = kzalloc(sizeof(*data), GFP_KERNEL);
> + if (!data) {
> + err = -ENOMEM;
> + goto exit;
> + }
> +
> + i2c_set_clientdata(new_client, data);
> + mutex_init(&data->update_lock);
>
> adm9240_init_client(new_client);
>
> /* populate sysfs filesystem */
> if ((err = sysfs_create_group(&new_client->dev.kobj, &adm9240_group)))
> - goto exit_detach;
> + goto exit_free;
>
> data->hwmon_dev = hwmon_device_register(&new_client->dev);
> if (IS_ERR(data->hwmon_dev)) {
> @@ -625,32 +637,19 @@ static int adm9240_detect(struct i2c_ada
>
> exit_remove:
> sysfs_remove_group(&new_client->dev.kobj, &adm9240_group);
> -exit_detach:
> - i2c_detach_client(new_client);
> exit_free:
> kfree(data);
> exit:
> return err;
> }
>
> -static int adm9240_attach_adapter(struct i2c_adapter *adapter)
> -{
> - if (!(adapter->class & I2C_CLASS_HWMON))
> - return 0;
> - return i2c_probe(adapter, &addr_data, adm9240_detect);
> -}
> -
> -static int adm9240_detach_client(struct i2c_client *client)
> +static int adm9240_remove(struct i2c_client *client)
> {
> struct adm9240_data *data = i2c_get_clientdata(client);
> - int err;
>
> hwmon_device_unregister(data->hwmon_dev);
> sysfs_remove_group(&client->dev.kobj, &adm9240_group);
>
> - if ((err = i2c_detach_client(client)))
> - return err;
> -
> kfree(data);
> return 0;
> }
>
>
_______________________________________________
i2c mailing list
i2c-GZX6beZjE8VD60Wz+7aTrA@public.gmane.org
http://lists.lm-sensors.org/mailman/listinfo/i2c
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] hwmon: (adm9240) Convert to a new-style i2c driver
[not found] ` <20080716163257.107e9340-ig7AzVSIIG7kN2dkZ6Wm7A@public.gmane.org>
2008-07-16 18:16 ` [lm-sensors] " Hans de Goede
@ 2008-07-18 1:17 ` Grant Coady
1 sibling, 0 replies; 3+ messages in thread
From: Grant Coady @ 2008-07-18 1:17 UTC (permalink / raw)
To: Jean Delvare; +Cc: Grant Coady, Linux I2C, LM Sensors
On Wed, 16 Jul 2008 16:32:57 +0200, Jean Delvare <khali-PUYAD+kWke1g9hUCZPvPmw@public.gmane.org> wrote:
>The new-style adm9240 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: Grant Coady <gcoady.lk-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
Tested both as compiled in, and as modules, with 2.6.26-git6, no problems
found, userspace:
~$ sensors --version
sensors version 3.0.2 with libsensors version 3.0.2
sensors-detect, sensors and 'sensors -s' behaved as expected.
Acked-by: Grant Coady <gcoady.lk-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
>---
> drivers/hwmon/adm9240.c | 93 +++++++++++++++++++++++------------------------
> 1 file changed, 46 insertions(+), 47 deletions(-)
>
>--- linux-2.6.26-rc9.orig/drivers/hwmon/adm9240.c 2008-07-12 09:20:31.000000000 +0200
>+++ linux-2.6.26-rc9/drivers/hwmon/adm9240.c 2008-07-12 10:27:31.000000000 +0200
>@@ -130,25 +130,37 @@ static inline unsigned int AOUT_FROM_REG
> return SCALE(reg, 1250, 255);
> }
>
>-static int adm9240_attach_adapter(struct i2c_adapter *adapter);
>-static int adm9240_detect(struct i2c_adapter *adapter, int address, int kind);
>+static int adm9240_probe(struct i2c_client *client,
>+ const struct i2c_device_id *id);
>+static int adm9240_detect(struct i2c_client *client, int kind,
>+ struct i2c_board_info *info);
> static void adm9240_init_client(struct i2c_client *client);
>-static int adm9240_detach_client(struct i2c_client *client);
>+static int adm9240_remove(struct i2c_client *client);
> static struct adm9240_data *adm9240_update_device(struct device *dev);
>
> /* driver data */
>+static const struct i2c_device_id adm9240_id[] = {
>+ { "adm9240", adm9240 },
>+ { "ds1780", ds1780 },
>+ { "lm81", lm81 },
>+ { }
>+};
>+MODULE_DEVICE_TABLE(i2c, adm9240_id);
>+
> static struct i2c_driver adm9240_driver = {
>+ .class = I2C_CLASS_HWMON,
> .driver = {
> .name = "adm9240",
> },
>- .attach_adapter = adm9240_attach_adapter,
>- .detach_client = adm9240_detach_client,
>+ .probe = adm9240_probe,
>+ .remove = adm9240_remove,
>+ .id_table = adm9240_id,
>+ .detect = adm9240_detect,
>+ .address_data = &addr_data,
> };
>
> /* per client data */
> struct adm9240_data {
>- enum chips type;
>- struct i2c_client client;
> struct device *hwmon_dev;
> struct mutex update_lock;
> char valid;
>@@ -532,28 +544,17 @@ static const struct attribute_group adm9
>
> /*** sensor chip detect and driver install ***/
>
>-static int adm9240_detect(struct i2c_adapter *adapter, int address, int kind)
>+/* Return 0 if detection is successful, -ENODEV otherwise */
>+static int adm9240_detect(struct i2c_client *new_client, int kind,
>+ struct i2c_board_info *info)
> {
>- struct i2c_client *new_client;
>- struct adm9240_data *data;
>- int err = 0;
>+ struct i2c_adapter *adapter = new_client->adapter;
> const char *name = "";
>+ int address = new_client->addr;
> u8 man_id, die_rev;
>
> if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA))
>- goto exit;
>-
>- if (!(data = kzalloc(sizeof(*data), GFP_KERNEL))) {
>- err = -ENOMEM;
>- goto exit;
>- }
>-
>- new_client = &data->client;
>- i2c_set_clientdata(new_client, data);
>- new_client->addr = address;
>- new_client->adapter = adapter;
>- new_client->driver = &adm9240_driver;
>- new_client->flags = 0;
>+ return -ENODEV;
>
> if (kind == 0) {
> kind = adm9240;
>@@ -566,7 +567,7 @@ static int adm9240_detect(struct i2c_ada
> != address) {
> dev_err(&adapter->dev, "detect fail: address match, "
> "0x%02x\n", address);
>- goto exit_free;
>+ return -ENODEV;
> }
>
> /* check known chip manufacturer */
>@@ -581,7 +582,7 @@ static int adm9240_detect(struct i2c_ada
> } else {
> dev_err(&adapter->dev, "detect fail: unknown manuf, "
> "0x%02x\n", man_id);
>- goto exit_free;
>+ return -ENODEV;
> }
>
> /* successful detect, print chip info */
>@@ -600,20 +601,31 @@ static int adm9240_detect(struct i2c_ada
> } else if (kind == lm81) {
> name = "lm81";
> }
>+ strlcpy(info->type, name, I2C_NAME_SIZE);
>
>- /* fill in the remaining client fields and attach */
>- strlcpy(new_client->name, name, I2C_NAME_SIZE);
>- data->type = kind;
>- mutex_init(&data->update_lock);
>+ return 0;
>+}
>
>- if ((err = i2c_attach_client(new_client)))
>- goto exit_free;
>+static int adm9240_probe(struct i2c_client *new_client,
>+ const struct i2c_device_id *id)
>+{
>+ struct adm9240_data *data;
>+ int err;
>+
>+ data = kzalloc(sizeof(*data), GFP_KERNEL);
>+ if (!data) {
>+ err = -ENOMEM;
>+ goto exit;
>+ }
>+
>+ i2c_set_clientdata(new_client, data);
>+ mutex_init(&data->update_lock);
>
> adm9240_init_client(new_client);
>
> /* populate sysfs filesystem */
> if ((err = sysfs_create_group(&new_client->dev.kobj, &adm9240_group)))
>- goto exit_detach;
>+ goto exit_free;
>
> data->hwmon_dev = hwmon_device_register(&new_client->dev);
> if (IS_ERR(data->hwmon_dev)) {
>@@ -625,32 +637,19 @@ static int adm9240_detect(struct i2c_ada
>
> exit_remove:
> sysfs_remove_group(&new_client->dev.kobj, &adm9240_group);
>-exit_detach:
>- i2c_detach_client(new_client);
> exit_free:
> kfree(data);
> exit:
> return err;
> }
>
>-static int adm9240_attach_adapter(struct i2c_adapter *adapter)
>-{
>- if (!(adapter->class & I2C_CLASS_HWMON))
>- return 0;
>- return i2c_probe(adapter, &addr_data, adm9240_detect);
>-}
>-
>-static int adm9240_detach_client(struct i2c_client *client)
>+static int adm9240_remove(struct i2c_client *client)
> {
> struct adm9240_data *data = i2c_get_clientdata(client);
>- int err;
>
> hwmon_device_unregister(data->hwmon_dev);
> sysfs_remove_group(&client->dev.kobj, &adm9240_group);
>
>- if ((err = i2c_detach_client(client)))
>- return err;
>-
> kfree(data);
> return 0;
> }
_______________________________________________
i2c mailing list
i2c-GZX6beZjE8VD60Wz+7aTrA@public.gmane.org
http://lists.lm-sensors.org/mailman/listinfo/i2c
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2008-07-18 1:17 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-07-16 14:32 [PATCH] hwmon: (adm9240) Convert to a new-style i2c driver Jean Delvare
[not found] ` <20080716163257.107e9340-ig7AzVSIIG7kN2dkZ6Wm7A@public.gmane.org>
2008-07-16 18:16 ` [lm-sensors] " Hans de Goede
2008-07-18 1:17 ` Grant Coady
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox