aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/hwmon/adt7473.c
diff options
context:
space:
mode:
authorJean Delvare <khali@linux-fr.org>2008-07-16 13:30:10 -0400
committerJean Delvare <khali@mahadeva.delvare>2008-07-16 13:30:10 -0400
commiteea54766c6e3f9850affa91061164aeb6bba44b6 (patch)
tree9475152073115b24aea648471eb8254bf3610e30 /drivers/hwmon/adt7473.c
parent008f1ca51e4a25ee3e34b8faa901dbeefaf0081a (diff)
hwmon: (adt7473) Convert to a new-style i2c driver
The new-style adt7473 driver implements the optional detect() callback to cover the use cases of the legacy driver. Signed-off-by: Jean Delvare <khali@linux-fr.org> Cc: Darrick J. Wong <djwong@us.ibm.com>
Diffstat (limited to 'drivers/hwmon/adt7473.c')
-rw-r--r--drivers/hwmon/adt7473.c102
1 files changed, 48 insertions, 54 deletions
diff --git a/drivers/hwmon/adt7473.c b/drivers/hwmon/adt7473.c
index 93dbf5e7ff8a..ce4a7cb5a116 100644
--- a/drivers/hwmon/adt7473.c
+++ b/drivers/hwmon/adt7473.c
@@ -143,7 +143,6 @@ I2C_CLIENT_INSMOD_1(adt7473);
143#define FAN_DATA_VALID(x) ((x) && (x) != FAN_PERIOD_INVALID) 143#define FAN_DATA_VALID(x) ((x) && (x) != FAN_PERIOD_INVALID)
144 144
145struct adt7473_data { 145struct adt7473_data {
146 struct i2c_client client;
147 struct device *hwmon_dev; 146 struct device *hwmon_dev;
148 struct attribute_group attrs; 147 struct attribute_group attrs;
149 struct mutex lock; 148 struct mutex lock;
@@ -178,16 +177,28 @@ struct adt7473_data {
178 u8 max_duty_at_overheat; 177 u8 max_duty_at_overheat;
179}; 178};
180 179
181static int adt7473_attach_adapter(struct i2c_adapter *adapter); 180static int adt7473_probe(struct i2c_client *client,
182static int adt7473_detect(struct i2c_adapter *adapter, int address, int kind); 181 const struct i2c_device_id *id);
183static int adt7473_detach_client(struct i2c_client *client); 182static int adt7473_detect(struct i2c_client *client, int kind,
183 struct i2c_board_info *info);
184static int adt7473_remove(struct i2c_client *client);
185
186static const struct i2c_device_id adt7473_id[] = {
187 { "adt7473", adt7473 },
188 { }
189};
190MODULE_DEVICE_TABLE(i2c, adt7473_id);
184 191
185static struct i2c_driver adt7473_driver = { 192static struct i2c_driver adt7473_driver = {
193 .class = I2C_CLASS_HWMON,
186 .driver = { 194 .driver = {
187 .name = "adt7473", 195 .name = "adt7473",
188 }, 196 },
189 .attach_adapter = adt7473_attach_adapter, 197 .probe = adt7473_probe,
190 .detach_client = adt7473_detach_client, 198 .remove = adt7473_remove,
199 .id_table = adt7473_id,
200 .detect = adt7473_detect,
201 .address_data = &addr_data,
191}; 202};
192 203
193/* 204/*
@@ -1042,66 +1053,52 @@ static struct attribute *adt7473_attr[] =
1042 NULL 1053 NULL
1043}; 1054};
1044 1055
1045static int adt7473_attach_adapter(struct i2c_adapter *adapter) 1056/* Return 0 if detection is successful, -ENODEV otherwise */
1057static int adt7473_detect(struct i2c_client *client, int kind,
1058 struct i2c_board_info *info)
1046{ 1059{
1047 if (!(adapter->class & I2C_CLASS_HWMON)) 1060 struct i2c_adapter *adapter = client->adapter;
1048 return 0;
1049 return i2c_probe(adapter, &addr_data, adt7473_detect);
1050}
1051
1052static int adt7473_detect(struct i2c_adapter *adapter, int address, int kind)
1053{
1054 struct i2c_client *client;
1055 struct adt7473_data *data;
1056 int err = 0;
1057 1061
1058 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) 1062 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA))
1059 goto exit; 1063 return -ENODEV;
1060
1061 data = kzalloc(sizeof(struct adt7473_data), GFP_KERNEL);
1062 if (!data) {
1063 err = -ENOMEM;
1064 goto exit;
1065 }
1066
1067 client = &data->client;
1068 client->addr = address;
1069 client->adapter = adapter;
1070 client->driver = &adt7473_driver;
1071
1072 i2c_set_clientdata(client, data);
1073
1074 mutex_init(&data->lock);
1075 1064
1076 if (kind <= 0) { 1065 if (kind <= 0) {
1077 int vendor, device, revision; 1066 int vendor, device, revision;
1078 1067
1079 vendor = i2c_smbus_read_byte_data(client, ADT7473_REG_VENDOR); 1068 vendor = i2c_smbus_read_byte_data(client, ADT7473_REG_VENDOR);
1080 if (vendor != ADT7473_VENDOR) { 1069 if (vendor != ADT7473_VENDOR)
1081 err = -ENODEV; 1070 return -ENODEV;
1082 goto exit_free;
1083 }
1084 1071
1085 device = i2c_smbus_read_byte_data(client, ADT7473_REG_DEVICE); 1072 device = i2c_smbus_read_byte_data(client, ADT7473_REG_DEVICE);
1086 if (device != ADT7473_DEVICE) { 1073 if (device != ADT7473_DEVICE)
1087 err = -ENODEV; 1074 return -ENODEV;
1088 goto exit_free;
1089 }
1090 1075
1091 revision = i2c_smbus_read_byte_data(client, 1076 revision = i2c_smbus_read_byte_data(client,
1092 ADT7473_REG_REVISION); 1077 ADT7473_REG_REVISION);
1093 if (revision != ADT7473_REV_68 && revision != ADT7473_REV_69) { 1078 if (revision != ADT7473_REV_68 && revision != ADT7473_REV_69)
1094 err = -ENODEV; 1079 return -ENODEV;
1095 goto exit_free;
1096 }
1097 } else 1080 } else
1098 dev_dbg(&adapter->dev, "detection forced\n"); 1081 dev_dbg(&adapter->dev, "detection forced\n");
1099 1082
1100 strlcpy(client->name, "adt7473", I2C_NAME_SIZE); 1083 strlcpy(info->type, "adt7473", I2C_NAME_SIZE);
1101 1084
1102 err = i2c_attach_client(client); 1085 return 0;
1103 if (err) 1086}
1104 goto exit_free; 1087
1088static int adt7473_probe(struct i2c_client *client,
1089 const struct i2c_device_id *id)
1090{
1091 struct adt7473_data *data;
1092 int err;
1093
1094 data = kzalloc(sizeof(struct adt7473_data), GFP_KERNEL);
1095 if (!data) {
1096 err = -ENOMEM;
1097 goto exit;
1098 }
1099
1100 i2c_set_clientdata(client, data);
1101 mutex_init(&data->lock);
1105 1102
1106 dev_info(&client->dev, "%s chip found\n", client->name); 1103 dev_info(&client->dev, "%s chip found\n", client->name);
1107 1104
@@ -1112,7 +1109,7 @@ static int adt7473_detect(struct i2c_adapter *adapter, int address, int kind)
1112 data->attrs.attrs = adt7473_attr; 1109 data->attrs.attrs = adt7473_attr;
1113 err = sysfs_create_group(&client->dev.kobj, &data->attrs); 1110 err = sysfs_create_group(&client->dev.kobj, &data->attrs);
1114 if (err) 1111 if (err)
1115 goto exit_detach; 1112 goto exit_free;
1116 1113
1117 data->hwmon_dev = hwmon_device_register(&client->dev); 1114 data->hwmon_dev = hwmon_device_register(&client->dev);
1118 if (IS_ERR(data->hwmon_dev)) { 1115 if (IS_ERR(data->hwmon_dev)) {
@@ -1124,21 +1121,18 @@ static int adt7473_detect(struct i2c_adapter *adapter, int address, int kind)
1124 1121
1125exit_remove: 1122exit_remove:
1126 sysfs_remove_group(&client->dev.kobj, &data->attrs); 1123 sysfs_remove_group(&client->dev.kobj, &data->attrs);
1127exit_detach:
1128 i2c_detach_client(client);
1129exit_free: 1124exit_free:
1130 kfree(data); 1125 kfree(data);
1131exit: 1126exit:
1132 return err; 1127 return err;
1133} 1128}
1134 1129
1135static int adt7473_detach_client(struct i2c_client *client) 1130static int adt7473_remove(struct i2c_client *client)
1136{ 1131{
1137 struct adt7473_data *data = i2c_get_clientdata(client); 1132 struct adt7473_data *data = i2c_get_clientdata(client);
1138 1133
1139 hwmon_device_unregister(data->hwmon_dev); 1134 hwmon_device_unregister(data->hwmon_dev);
1140 sysfs_remove_group(&client->dev.kobj, &data->attrs); 1135 sysfs_remove_group(&client->dev.kobj, &data->attrs);
1141 i2c_detach_client(client);
1142 kfree(data); 1136 kfree(data);
1143 return 0; 1137 return 0;
1144} 1138}