aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/hwmon/adt7473.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/hwmon/adt7473.c')
-rw-r--r--drivers/hwmon/adt7473.c105
1 files changed, 51 insertions, 54 deletions
diff --git a/drivers/hwmon/adt7473.c b/drivers/hwmon/adt7473.c
index c1009d6f9796..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/*
@@ -309,6 +320,9 @@ no_sensor_update:
309 ADT7473_REG_PWM_BHVR(i)); 320 ADT7473_REG_PWM_BHVR(i));
310 } 321 }
311 322
323 i = i2c_smbus_read_byte_data(client, ADT7473_REG_CFG4);
324 data->max_duty_at_overheat = !!(i & ADT7473_CFG4_MAX_DUTY_AT_OVT);
325
312 data->limits_last_updated = local_jiffies; 326 data->limits_last_updated = local_jiffies;
313 data->limits_valid = 1; 327 data->limits_valid = 1;
314 328
@@ -1039,66 +1053,52 @@ static struct attribute *adt7473_attr[] =
1039 NULL 1053 NULL
1040}; 1054};
1041 1055
1042static 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)
1043{ 1059{
1044 if (!(adapter->class & I2C_CLASS_HWMON)) 1060 struct i2c_adapter *adapter = client->adapter;
1045 return 0;
1046 return i2c_probe(adapter, &addr_data, adt7473_detect);
1047}
1048
1049static int adt7473_detect(struct i2c_adapter *adapter, int address, int kind)
1050{
1051 struct i2c_client *client;
1052 struct adt7473_data *data;
1053 int err = 0;
1054 1061
1055 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) 1062 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA))
1056 goto exit; 1063 return -ENODEV;
1057
1058 data = kzalloc(sizeof(struct adt7473_data), GFP_KERNEL);
1059 if (!data) {
1060 err = -ENOMEM;
1061 goto exit;
1062 }
1063
1064 client = &data->client;
1065 client->addr = address;
1066 client->adapter = adapter;
1067 client->driver = &adt7473_driver;
1068
1069 i2c_set_clientdata(client, data);
1070
1071 mutex_init(&data->lock);
1072 1064
1073 if (kind <= 0) { 1065 if (kind <= 0) {
1074 int vendor, device, revision; 1066 int vendor, device, revision;
1075 1067
1076 vendor = i2c_smbus_read_byte_data(client, ADT7473_REG_VENDOR); 1068 vendor = i2c_smbus_read_byte_data(client, ADT7473_REG_VENDOR);
1077 if (vendor != ADT7473_VENDOR) { 1069 if (vendor != ADT7473_VENDOR)
1078 err = -ENODEV; 1070 return -ENODEV;
1079 goto exit_free;
1080 }
1081 1071
1082 device = i2c_smbus_read_byte_data(client, ADT7473_REG_DEVICE); 1072 device = i2c_smbus_read_byte_data(client, ADT7473_REG_DEVICE);
1083 if (device != ADT7473_DEVICE) { 1073 if (device != ADT7473_DEVICE)
1084 err = -ENODEV; 1074 return -ENODEV;
1085 goto exit_free;
1086 }
1087 1075
1088 revision = i2c_smbus_read_byte_data(client, 1076 revision = i2c_smbus_read_byte_data(client,
1089 ADT7473_REG_REVISION); 1077 ADT7473_REG_REVISION);
1090 if (revision != ADT7473_REV_68 && revision != ADT7473_REV_69) { 1078 if (revision != ADT7473_REV_68 && revision != ADT7473_REV_69)
1091 err = -ENODEV; 1079 return -ENODEV;
1092 goto exit_free;
1093 }
1094 } else 1080 } else
1095 dev_dbg(&adapter->dev, "detection forced\n"); 1081 dev_dbg(&adapter->dev, "detection forced\n");
1096 1082
1097 strlcpy(client->name, "adt7473", I2C_NAME_SIZE); 1083 strlcpy(info->type, "adt7473", I2C_NAME_SIZE);
1098 1084
1099 err = i2c_attach_client(client); 1085 return 0;
1100 if (err) 1086}
1101 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);
1102 1102
1103 dev_info(&client->dev, "%s chip found\n", client->name); 1103 dev_info(&client->dev, "%s chip found\n", client->name);
1104 1104
@@ -1109,7 +1109,7 @@ static int adt7473_detect(struct i2c_adapter *adapter, int address, int kind)
1109 data->attrs.attrs = adt7473_attr; 1109 data->attrs.attrs = adt7473_attr;
1110 err = sysfs_create_group(&client->dev.kobj, &data->attrs); 1110 err = sysfs_create_group(&client->dev.kobj, &data->attrs);
1111 if (err) 1111 if (err)
1112 goto exit_detach; 1112 goto exit_free;
1113 1113
1114 data->hwmon_dev = hwmon_device_register(&client->dev); 1114 data->hwmon_dev = hwmon_device_register(&client->dev);
1115 if (IS_ERR(data->hwmon_dev)) { 1115 if (IS_ERR(data->hwmon_dev)) {
@@ -1121,21 +1121,18 @@ static int adt7473_detect(struct i2c_adapter *adapter, int address, int kind)
1121 1121
1122exit_remove: 1122exit_remove:
1123 sysfs_remove_group(&client->dev.kobj, &data->attrs); 1123 sysfs_remove_group(&client->dev.kobj, &data->attrs);
1124exit_detach:
1125 i2c_detach_client(client);
1126exit_free: 1124exit_free:
1127 kfree(data); 1125 kfree(data);
1128exit: 1126exit:
1129 return err; 1127 return err;
1130} 1128}
1131 1129
1132static int adt7473_detach_client(struct i2c_client *client) 1130static int adt7473_remove(struct i2c_client *client)
1133{ 1131{
1134 struct adt7473_data *data = i2c_get_clientdata(client); 1132 struct adt7473_data *data = i2c_get_clientdata(client);
1135 1133
1136 hwmon_device_unregister(data->hwmon_dev); 1134 hwmon_device_unregister(data->hwmon_dev);
1137 sysfs_remove_group(&client->dev.kobj, &data->attrs); 1135 sysfs_remove_group(&client->dev.kobj, &data->attrs);
1138 i2c_detach_client(client);
1139 kfree(data); 1136 kfree(data);
1140 return 0; 1137 return 0;
1141} 1138}