summaryrefslogtreecommitdiffstats
path: root/drivers/hwmon/f75375s.c
diff options
context:
space:
mode:
authorRiku Voipio <riku.voipio@movial.fi>2007-10-16 12:46:49 +0300
committerMark M. Hoffman <mhoffman@lightlink.com>2007-11-08 08:42:46 -0500
commit620c142db20477149bf04c7e8e8fde70d608e8c7 (patch)
tree83a9a490e854d1604205d567f3f1375ce210e5d7 /drivers/hwmon/f75375s.c
parent4bfe66048e97d29ab229519e9a821dbd4d929bd9 (diff)
downloadlinux-620c142db20477149bf04c7e8e8fde70d608e8c7.tar.gz
linux-620c142db20477149bf04c7e8e8fde70d608e8c7.tar.bz2
linux-620c142db20477149bf04c7e8e8fde70d608e8c7.zip
hwmon: (f75375s) Add new style bindings
Following the example of David Brownell's work on lm75: - Create a second driver struct, using new-style driver binding methods. - Rename the old driver struct as f75375_legacy_driver. - Make the legacy bind/unbind logic delegate all its work. Signed-off-by: Riku Voipio <riku.voipio@movial.fi> Signed-off-by: Mark M. Hoffman <mhoffman@lightlink.com>
Diffstat (limited to 'drivers/hwmon/f75375s.c')
-rw-r--r--drivers/hwmon/f75375s.c109
1 files changed, 83 insertions, 26 deletions
diff --git a/drivers/hwmon/f75375s.c b/drivers/hwmon/f75375s.c
index 59a3470d6cf9..19b3427b5e9e 100644
--- a/drivers/hwmon/f75375s.c
+++ b/drivers/hwmon/f75375s.c
@@ -86,7 +86,7 @@ I2C_CLIENT_INSMOD_2(f75373, f75375);
struct f75375_data {
unsigned short addr;
- struct i2c_client client;
+ struct i2c_client *client;
struct device *hwmon_dev;
const char *name;
@@ -116,15 +116,25 @@ struct f75375_data {
static int f75375_attach_adapter(struct i2c_adapter *adapter);
static int f75375_detect(struct i2c_adapter *adapter, int address, int kind);
static int f75375_detach_client(struct i2c_client *client);
+static int f75375_probe(struct i2c_client *client);
+static int f75375_remove(struct i2c_client *client);
-static struct i2c_driver f75375_driver = {
+static struct i2c_driver f75375_legacy_driver = {
.driver = {
- .name = "f75375",
+ .name = "f75375_legacy",
},
.attach_adapter = f75375_attach_adapter,
.detach_client = f75375_detach_client,
};
+static struct i2c_driver f75375_driver = {
+ .driver = {
+ .name = "f75375",
+ },
+ .probe = f75375_probe,
+ .remove = f75375_remove,
+};
+
static inline int f75375_read8(struct i2c_client *client, u8 reg)
{
return i2c_smbus_read_byte_data(client, reg);
@@ -580,12 +590,9 @@ static const struct attribute_group f75375_group = {
static int f75375_detach_client(struct i2c_client *client)
{
- struct f75375_data *data = i2c_get_clientdata(client);
int err;
- hwmon_device_unregister(data->hwmon_dev);
- sysfs_remove_group(&client->dev.kobj, &f75375_group);
-
+ f75375_remove(client);
err = i2c_detach_client(client);
if (err) {
dev_err(&client->dev,
@@ -593,7 +600,60 @@ static int f75375_detach_client(struct i2c_client *client)
"client not detached.\n");
return err;
}
+ kfree(client);
+ return 0;
+}
+
+static int f75375_probe(struct i2c_client *client)
+{
+ struct f75375_data *data = i2c_get_clientdata(client);
+ int err;
+
+ if (!i2c_check_functionality(client->adapter,
+ I2C_FUNC_SMBUS_BYTE_DATA))
+ return -EIO;
+ if (!(data = kzalloc(sizeof(struct f75375_data), GFP_KERNEL)))
+ return -ENOMEM;
+
+ i2c_set_clientdata(client, data);
+ data->client = client;
+ mutex_init(&data->update_lock);
+
+ if (strcmp(client->name, "f75375") == 0)
+ data->kind = f75375;
+ else if (strcmp(client->name, "f75373") == 0)
+ data->kind = f75373;
+ else {
+ dev_err(&client->dev, "Unsupported device: %s\n", client->name);
+ return -ENODEV;
+ }
+
+ if ((err = sysfs_create_group(&client->dev.kobj, &f75375_group)))
+ goto exit_free;
+
+ data->hwmon_dev = hwmon_device_register(&client->dev);
+ if (IS_ERR(data->hwmon_dev)) {
+ err = PTR_ERR(data->hwmon_dev);
+ goto exit_remove;
+ }
+
+ return 0;
+
+exit_remove:
+ sysfs_remove_group(&client->dev.kobj, &f75375_group);
+exit_free:
+ kfree(data);
+ i2c_set_clientdata(client, NULL);
+ return err;
+}
+
+static int f75375_remove(struct i2c_client *client)
+{
+ struct f75375_data *data = i2c_get_clientdata(client);
+ hwmon_device_unregister(data->hwmon_dev);
+ sysfs_remove_group(&client->dev.kobj, &f75375_group);
kfree(data);
+ i2c_set_clientdata(client, NULL);
return 0;
}
@@ -608,20 +668,17 @@ static int f75375_attach_adapter(struct i2c_adapter *adapter)
static int f75375_detect(struct i2c_adapter *adapter, int address, int kind)
{
struct i2c_client *client;
- struct f75375_data *data;
u8 version = 0;
int err = 0;
const char *name = "";
- if (!(data = kzalloc(sizeof(struct f75375_data), GFP_KERNEL))) {
+ if (!(client = kzalloc(sizeof(*client), GFP_KERNEL))) {
err = -ENOMEM;
goto exit;
}
- client = &data->client;
- i2c_set_clientdata(client, data);
client->addr = address;
client->adapter = adapter;
- client->driver = &f75375_driver;
+ client->driver = &f75375_legacy_driver;
if (kind < 0) {
u16 vendid = f75375_read16(client, F75375_REG_VENDOR);
@@ -644,42 +701,42 @@ static int f75375_detect(struct i2c_adapter *adapter, int address, int kind)
} else if (kind == f75373) {
name = "f75373";
}
-
dev_info(&adapter->dev, "found %s version: %02X\n", name, version);
strlcpy(client->name, name, I2C_NAME_SIZE);
- data->kind = kind;
- mutex_init(&data->update_lock);
+
if ((err = i2c_attach_client(client)))
goto exit_free;
- if ((err = sysfs_create_group(&client->dev.kobj, &f75375_group)))
+ if ((err = f75375_probe(client)) < 0)
goto exit_detach;
- data->hwmon_dev = hwmon_device_register(&client->dev);
- if (IS_ERR(data->hwmon_dev)) {
- err = PTR_ERR(data->hwmon_dev);
- goto exit_remove;
- }
-
return 0;
-exit_remove:
- sysfs_remove_group(&client->dev.kobj, &f75375_group);
exit_detach:
i2c_detach_client(client);
exit_free:
- kfree(data);
+ kfree(client);
exit:
return err;
}
static int __init sensors_f75375_init(void)
{
- return i2c_add_driver(&f75375_driver);
+ int status;
+ status = i2c_add_driver(&f75375_driver);
+ if (status)
+ return status;
+
+ status = i2c_add_driver(&f75375_legacy_driver);
+ if (status)
+ i2c_del_driver(&f75375_driver);
+
+ return status;
}
static void __exit sensors_f75375_exit(void)
{
+ i2c_del_driver(&f75375_legacy_driver);
i2c_del_driver(&f75375_driver);
}