* [PATCH] hwmon: (adm1031) Convert to a new-style i2c driver
@ 2008-07-16 12:51 Jean Delvare
[not found] ` <20080716145157.0187af72-ig7AzVSIIG7kN2dkZ6Wm7A@public.gmane.org>
0 siblings, 1 reply; 2+ messages in thread
From: Jean Delvare @ 2008-07-16 12:51 UTC (permalink / raw)
To: Linux I2C, LM Sensors; +Cc: Alexandre d'Alton
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>
---
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;
}
--
Jean Delvare
_______________________________________________
i2c mailing list
i2c-GZX6beZjE8VD60Wz+7aTrA@public.gmane.org
http://lists.lm-sensors.org/mailman/listinfo/i2c
^ permalink raw reply [flat|nested] 2+ messages in thread[parent not found: <20080716145157.0187af72-ig7AzVSIIG7kN2dkZ6Wm7A@public.gmane.org>]
* Re: [lm-sensors] [PATCH] hwmon: (adm1031) Convert to a new-style i2c driver [not found] ` <20080716145157.0187af72-ig7AzVSIIG7kN2dkZ6Wm7A@public.gmane.org> @ 2008-07-16 18:14 ` Hans de Goede 0 siblings, 0 replies; 2+ messages in thread From: Hans de Goede @ 2008-07-16 18:14 UTC (permalink / raw) To: Jean Delvare; +Cc: Alexandre d'Alton, Linux I2C, LM Sensors 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 ^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2008-07-16 18:14 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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 ` [lm-sensors] " Hans de Goede
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox