adt7470.c (2f22d5dff6f95d777c4cb217b99bfdf1fe306128) adt7470.c (89fac11cb3e7c5860c425dba14845c09ccede39d)
1/*
2 * A hwmon driver for the Analog Devices ADT7470
3 * Copyright (C) 2007 IBM
4 *
5 * Author: Darrick J. Wong <djwong@us.ibm.com>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by

--- 14 unchanged lines hidden (view full) ---

23#include <linux/jiffies.h>
24#include <linux/i2c.h>
25#include <linux/hwmon.h>
26#include <linux/hwmon-sysfs.h>
27#include <linux/err.h>
28#include <linux/mutex.h>
29#include <linux/delay.h>
30#include <linux/log2.h>
1/*
2 * A hwmon driver for the Analog Devices ADT7470
3 * Copyright (C) 2007 IBM
4 *
5 * Author: Darrick J. Wong <djwong@us.ibm.com>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by

--- 14 unchanged lines hidden (view full) ---

23#include <linux/jiffies.h>
24#include <linux/i2c.h>
25#include <linux/hwmon.h>
26#include <linux/hwmon-sysfs.h>
27#include <linux/err.h>
28#include <linux/mutex.h>
29#include <linux/delay.h>
30#include <linux/log2.h>
31#include <linux/kthread.h>
31
32/* Addresses to scan */
33static const unsigned short normal_i2c[] = { 0x2C, 0x2E, 0x2F, I2C_CLIENT_END };
34
35/* Insmod parameters */
36I2C_CLIENT_INSMOD_1(adt7470);
37
38/* ADT7470 registers */

--- 88 unchanged lines hidden (view full) ---

127#define SENSOR_REFRESH_INTERVAL (5 * HZ)
128
129/* How often do we reread sensor limit values? (In jiffies) */
130#define LIMIT_REFRESH_INTERVAL (60 * HZ)
131
132/* Wait at least 200ms per sensor for 10 sensors */
133#define TEMP_COLLECTION_TIME 2000
134
32
33/* Addresses to scan */
34static const unsigned short normal_i2c[] = { 0x2C, 0x2E, 0x2F, I2C_CLIENT_END };
35
36/* Insmod parameters */
37I2C_CLIENT_INSMOD_1(adt7470);
38
39/* ADT7470 registers */

--- 88 unchanged lines hidden (view full) ---

128#define SENSOR_REFRESH_INTERVAL (5 * HZ)
129
130/* How often do we reread sensor limit values? (In jiffies) */
131#define LIMIT_REFRESH_INTERVAL (60 * HZ)
132
133/* Wait at least 200ms per sensor for 10 sensors */
134#define TEMP_COLLECTION_TIME 2000
135
136/* auto update thing won't fire more than every 2s */
137#define AUTO_UPDATE_INTERVAL 2000
138
135/* datasheet says to divide this number by the fan reading to get fan rpm */
136#define FAN_PERIOD_TO_RPM(x) ((90000 * 60) / (x))
137#define FAN_RPM_TO_PERIOD FAN_PERIOD_TO_RPM
138#define FAN_PERIOD_INVALID 65535
139#define FAN_DATA_VALID(x) ((x) && (x) != FAN_PERIOD_INVALID)
140
141struct adt7470_data {
142 struct device *hwmon_dev;
143 struct attribute_group attrs;
144 struct mutex lock;
145 char sensors_valid;
146 char limits_valid;
147 unsigned long sensors_last_updated; /* In jiffies */
148 unsigned long limits_last_updated; /* In jiffies */
149
150 int num_temp_sensors; /* -1 = probe */
139/* datasheet says to divide this number by the fan reading to get fan rpm */
140#define FAN_PERIOD_TO_RPM(x) ((90000 * 60) / (x))
141#define FAN_RPM_TO_PERIOD FAN_PERIOD_TO_RPM
142#define FAN_PERIOD_INVALID 65535
143#define FAN_DATA_VALID(x) ((x) && (x) != FAN_PERIOD_INVALID)
144
145struct adt7470_data {
146 struct device *hwmon_dev;
147 struct attribute_group attrs;
148 struct mutex lock;
149 char sensors_valid;
150 char limits_valid;
151 unsigned long sensors_last_updated; /* In jiffies */
152 unsigned long limits_last_updated; /* In jiffies */
153
154 int num_temp_sensors; /* -1 = probe */
155 int temperatures_probed;
151
152 s8 temp[ADT7470_TEMP_COUNT];
153 s8 temp_min[ADT7470_TEMP_COUNT];
154 s8 temp_max[ADT7470_TEMP_COUNT];
155 u16 fan[ADT7470_FAN_COUNT];
156 u16 fan_min[ADT7470_FAN_COUNT];
157 u16 fan_max[ADT7470_FAN_COUNT];
158 u16 alarm;
159 u16 alarms_mask;
160 u8 force_pwm_max;
161 u8 pwm[ADT7470_PWM_COUNT];
162 u8 pwm_max[ADT7470_PWM_COUNT];
163 u8 pwm_automatic[ADT7470_PWM_COUNT];
164 u8 pwm_min[ADT7470_PWM_COUNT];
165 s8 pwm_tmin[ADT7470_PWM_COUNT];
166 u8 pwm_auto_temp[ADT7470_PWM_COUNT];
156
157 s8 temp[ADT7470_TEMP_COUNT];
158 s8 temp_min[ADT7470_TEMP_COUNT];
159 s8 temp_max[ADT7470_TEMP_COUNT];
160 u16 fan[ADT7470_FAN_COUNT];
161 u16 fan_min[ADT7470_FAN_COUNT];
162 u16 fan_max[ADT7470_FAN_COUNT];
163 u16 alarm;
164 u16 alarms_mask;
165 u8 force_pwm_max;
166 u8 pwm[ADT7470_PWM_COUNT];
167 u8 pwm_max[ADT7470_PWM_COUNT];
168 u8 pwm_automatic[ADT7470_PWM_COUNT];
169 u8 pwm_min[ADT7470_PWM_COUNT];
170 s8 pwm_tmin[ADT7470_PWM_COUNT];
171 u8 pwm_auto_temp[ADT7470_PWM_COUNT];
172
173 struct task_struct *auto_update;
174 struct completion auto_update_stop;
175 unsigned int auto_update_interval;
167};
168
169static int adt7470_probe(struct i2c_client *client,
170 const struct i2c_device_id *id);
171static int adt7470_detect(struct i2c_client *client, int kind,
172 struct i2c_board_info *info);
173static int adt7470_remove(struct i2c_client *client);
174

--- 41 unchanged lines hidden (view full) ---

216 if (reg < 0) {
217 dev_err(&client->dev, "cannot read configuration register\n");
218 } else {
219 /* start monitoring (and do a self-test) */
220 i2c_smbus_write_byte_data(client, ADT7470_REG_CFG, reg | 3);
221 }
222}
223
176};
177
178static int adt7470_probe(struct i2c_client *client,
179 const struct i2c_device_id *id);
180static int adt7470_detect(struct i2c_client *client, int kind,
181 struct i2c_board_info *info);
182static int adt7470_remove(struct i2c_client *client);
183

--- 41 unchanged lines hidden (view full) ---

225 if (reg < 0) {
226 dev_err(&client->dev, "cannot read configuration register\n");
227 } else {
228 /* start monitoring (and do a self-test) */
229 i2c_smbus_write_byte_data(client, ADT7470_REG_CFG, reg | 3);
230 }
231}
232
224static struct adt7470_data *adt7470_update_device(struct device *dev)
233/* Probe for temperature sensors. Assumes lock is held */
234static int adt7470_read_temperatures(struct i2c_client *client,
235 struct adt7470_data *data)
225{
236{
226 struct i2c_client *client = to_i2c_client(dev);
227 struct adt7470_data *data = i2c_get_clientdata(client);
228 unsigned long local_jiffies = jiffies;
229 u8 cfg, pwm[4], pwm_cfg[2];
237 unsigned long res;
230 int i;
238 int i;
239 u8 cfg, pwm[4], pwm_cfg[2];
231
240
232 mutex_lock(&data->lock);
233 if (time_before(local_jiffies, data->sensors_last_updated +
234 SENSOR_REFRESH_INTERVAL)
235 && data->sensors_valid)
236 goto no_sensor_update;
237
238 /* save pwm[1-4] config register */
239 pwm_cfg[0] = i2c_smbus_read_byte_data(client, ADT7470_REG_PWM_CFG(0));
240 pwm_cfg[1] = i2c_smbus_read_byte_data(client, ADT7470_REG_PWM_CFG(2));
241
242 /* set manual pwm to whatever it is set to now */
243 for (i = 0; i < ADT7470_FAN_COUNT; i++)
244 pwm[i] = i2c_smbus_read_byte_data(client, ADT7470_REG_PWM(i));
245

--- 8 unchanged lines hidden (view full) ---

254 i2c_smbus_write_byte_data(client, ADT7470_REG_PWM(i), pwm[i]);
255
256 /* start reading temperature sensors */
257 cfg = i2c_smbus_read_byte_data(client, ADT7470_REG_CFG);
258 cfg |= 0x80;
259 i2c_smbus_write_byte_data(client, ADT7470_REG_CFG, cfg);
260
261 /* Delay is 200ms * number of temp sensors. */
241 /* save pwm[1-4] config register */
242 pwm_cfg[0] = i2c_smbus_read_byte_data(client, ADT7470_REG_PWM_CFG(0));
243 pwm_cfg[1] = i2c_smbus_read_byte_data(client, ADT7470_REG_PWM_CFG(2));
244
245 /* set manual pwm to whatever it is set to now */
246 for (i = 0; i < ADT7470_FAN_COUNT; i++)
247 pwm[i] = i2c_smbus_read_byte_data(client, ADT7470_REG_PWM(i));
248

--- 8 unchanged lines hidden (view full) ---

257 i2c_smbus_write_byte_data(client, ADT7470_REG_PWM(i), pwm[i]);
258
259 /* start reading temperature sensors */
260 cfg = i2c_smbus_read_byte_data(client, ADT7470_REG_CFG);
261 cfg |= 0x80;
262 i2c_smbus_write_byte_data(client, ADT7470_REG_CFG, cfg);
263
264 /* Delay is 200ms * number of temp sensors. */
262 msleep((data->num_temp_sensors >= 0 ?
263 data->num_temp_sensors * 200 :
264 TEMP_COLLECTION_TIME));
265 res = msleep_interruptible((data->num_temp_sensors >= 0 ?
266 data->num_temp_sensors * 200 :
267 TEMP_COLLECTION_TIME));
265
266 /* done reading temperature sensors */
267 cfg = i2c_smbus_read_byte_data(client, ADT7470_REG_CFG);
268 cfg &= ~0x80;
269 i2c_smbus_write_byte_data(client, ADT7470_REG_CFG, cfg);
270
271 /* restore pwm[1-4] config registers */
272 i2c_smbus_write_byte_data(client, ADT7470_REG_PWM_CFG(0), pwm_cfg[0]);
273 i2c_smbus_write_byte_data(client, ADT7470_REG_PWM_CFG(2), pwm_cfg[1]);
274
268
269 /* done reading temperature sensors */
270 cfg = i2c_smbus_read_byte_data(client, ADT7470_REG_CFG);
271 cfg &= ~0x80;
272 i2c_smbus_write_byte_data(client, ADT7470_REG_CFG, cfg);
273
274 /* restore pwm[1-4] config registers */
275 i2c_smbus_write_byte_data(client, ADT7470_REG_PWM_CFG(0), pwm_cfg[0]);
276 i2c_smbus_write_byte_data(client, ADT7470_REG_PWM_CFG(2), pwm_cfg[1]);
277
275 for (i = 0; i < ADT7470_TEMP_COUNT; i++)
278 if (res) {
279 printk(KERN_ERR "ha ha, interrupted");
280 return -EAGAIN;
281 }
282
283 /* Only count fans if we have to */
284 if (data->num_temp_sensors >= 0)
285 return 0;
286
287 for (i = 0; i < ADT7470_TEMP_COUNT; i++) {
276 data->temp[i] = i2c_smbus_read_byte_data(client,
277 ADT7470_TEMP_REG(i));
288 data->temp[i] = i2c_smbus_read_byte_data(client,
289 ADT7470_TEMP_REG(i));
290 if (data->temp[i])
291 data->num_temp_sensors = i + 1;
292 }
293 data->temperatures_probed = 1;
294 return 0;
295}
278
296
279 /* Figure out the number of temp sensors */
280 if (data->num_temp_sensors < 0)
297static int adt7470_update_thread(void *p)
298{
299 struct i2c_client *client = p;
300 struct adt7470_data *data = i2c_get_clientdata(client);
301
302 while (!kthread_should_stop()) {
303 mutex_lock(&data->lock);
304 adt7470_read_temperatures(client, data);
305 mutex_unlock(&data->lock);
306 if (kthread_should_stop())
307 break;
308 msleep_interruptible(data->auto_update_interval);
309 }
310
311 complete_all(&data->auto_update_stop);
312 return 0;
313}
314
315static struct adt7470_data *adt7470_update_device(struct device *dev)
316{
317 struct i2c_client *client = to_i2c_client(dev);
318 struct adt7470_data *data = i2c_get_clientdata(client);
319 unsigned long local_jiffies = jiffies;
320 u8 cfg;
321 int i;
322 int need_sensors = 1;
323 int need_limits = 1;
324
325 /*
326 * Figure out if we need to update the shadow registers.
327 * Lockless means that we may occasionally report out of
328 * date data.
329 */
330 if (time_before(local_jiffies, data->sensors_last_updated +
331 SENSOR_REFRESH_INTERVAL) &&
332 data->sensors_valid)
333 need_sensors = 0;
334
335 if (time_before(local_jiffies, data->limits_last_updated +
336 LIMIT_REFRESH_INTERVAL) &&
337 data->limits_valid)
338 need_limits = 0;
339
340 if (!need_sensors && !need_limits)
341 return data;
342
343 mutex_lock(&data->lock);
344 if (!need_sensors)
345 goto no_sensor_update;
346
347 if (!data->temperatures_probed)
348 adt7470_read_temperatures(client, data);
349 else
281 for (i = 0; i < ADT7470_TEMP_COUNT; i++)
350 for (i = 0; i < ADT7470_TEMP_COUNT; i++)
282 if (data->temp[i])
283 data->num_temp_sensors = i + 1;
351 data->temp[i] = i2c_smbus_read_byte_data(client,
352 ADT7470_TEMP_REG(i));
284
285 for (i = 0; i < ADT7470_FAN_COUNT; i++)
286 data->fan[i] = adt7470_read_word_data(client,
287 ADT7470_REG_FAN(i));
288
289 for (i = 0; i < ADT7470_PWM_COUNT; i++) {
290 int reg;
291 int reg_mask;

--- 32 unchanged lines hidden (view full) ---

324 ADT7470_REG_ALARM2));
325 data->alarms_mask = adt7470_read_word_data(client,
326 ADT7470_REG_ALARM1_MASK);
327
328 data->sensors_last_updated = local_jiffies;
329 data->sensors_valid = 1;
330
331no_sensor_update:
353
354 for (i = 0; i < ADT7470_FAN_COUNT; i++)
355 data->fan[i] = adt7470_read_word_data(client,
356 ADT7470_REG_FAN(i));
357
358 for (i = 0; i < ADT7470_PWM_COUNT; i++) {
359 int reg;
360 int reg_mask;

--- 32 unchanged lines hidden (view full) ---

393 ADT7470_REG_ALARM2));
394 data->alarms_mask = adt7470_read_word_data(client,
395 ADT7470_REG_ALARM1_MASK);
396
397 data->sensors_last_updated = local_jiffies;
398 data->sensors_valid = 1;
399
400no_sensor_update:
332 if (time_before(local_jiffies, data->limits_last_updated +
333 LIMIT_REFRESH_INTERVAL)
334 && data->limits_valid)
401 if (!need_limits)
335 goto out;
336
337 for (i = 0; i < ADT7470_TEMP_COUNT; i++) {
338 data->temp_min[i] = i2c_smbus_read_byte_data(client,
339 ADT7470_TEMP_MIN_REG(i));
340 data->temp_max[i] = i2c_smbus_read_byte_data(client,
341 ADT7470_TEMP_MAX_REG(i));
342 }

--- 17 unchanged lines hidden (view full) ---

360 data->limits_last_updated = local_jiffies;
361 data->limits_valid = 1;
362
363out:
364 mutex_unlock(&data->lock);
365 return data;
366}
367
402 goto out;
403
404 for (i = 0; i < ADT7470_TEMP_COUNT; i++) {
405 data->temp_min[i] = i2c_smbus_read_byte_data(client,
406 ADT7470_TEMP_MIN_REG(i));
407 data->temp_max[i] = i2c_smbus_read_byte_data(client,
408 ADT7470_TEMP_MAX_REG(i));
409 }

--- 17 unchanged lines hidden (view full) ---

427 data->limits_last_updated = local_jiffies;
428 data->limits_valid = 1;
429
430out:
431 mutex_unlock(&data->lock);
432 return data;
433}
434
435static ssize_t show_auto_update_interval(struct device *dev,
436 struct device_attribute *devattr,
437 char *buf)
438{
439 struct adt7470_data *data = adt7470_update_device(dev);
440 return sprintf(buf, "%d\n", data->auto_update_interval);
441}
442
443static ssize_t set_auto_update_interval(struct device *dev,
444 struct device_attribute *devattr,
445 const char *buf,
446 size_t count)
447{
448 struct i2c_client *client = to_i2c_client(dev);
449 struct adt7470_data *data = i2c_get_clientdata(client);
450 long temp;
451
452 if (strict_strtol(buf, 10, &temp))
453 return -EINVAL;
454
455 temp = SENSORS_LIMIT(temp, 0, 60000);
456
457 mutex_lock(&data->lock);
458 data->auto_update_interval = temp;
459 mutex_unlock(&data->lock);
460
461 return count;
462}
463
368static ssize_t show_num_temp_sensors(struct device *dev,
369 struct device_attribute *devattr,
370 char *buf)
371{
372 struct adt7470_data *data = adt7470_update_device(dev);
373 return sprintf(buf, "%d\n", data->num_temp_sensors);
374}
375

--- 8 unchanged lines hidden (view full) ---

384
385 if (strict_strtol(buf, 10, &temp))
386 return -EINVAL;
387
388 temp = SENSORS_LIMIT(temp, -1, 10);
389
390 mutex_lock(&data->lock);
391 data->num_temp_sensors = temp;
464static ssize_t show_num_temp_sensors(struct device *dev,
465 struct device_attribute *devattr,
466 char *buf)
467{
468 struct adt7470_data *data = adt7470_update_device(dev);
469 return sprintf(buf, "%d\n", data->num_temp_sensors);
470}
471

--- 8 unchanged lines hidden (view full) ---

480
481 if (strict_strtol(buf, 10, &temp))
482 return -EINVAL;
483
484 temp = SENSORS_LIMIT(temp, -1, 10);
485
486 mutex_lock(&data->lock);
487 data->num_temp_sensors = temp;
488 if (temp < 0)
489 data->temperatures_probed = 0;
392 mutex_unlock(&data->lock);
393
394 return count;
395}
396
397static ssize_t show_temp_min(struct device *dev,
398 struct device_attribute *devattr,
399 char *buf)

--- 457 unchanged lines hidden (view full) ---

857 return sprintf(buf, "1\n");
858 else
859 return sprintf(buf, "0\n");
860}
861
862static DEVICE_ATTR(alarm_mask, S_IRUGO, show_alarm_mask, NULL);
863static DEVICE_ATTR(num_temp_sensors, S_IWUSR | S_IRUGO, show_num_temp_sensors,
864 set_num_temp_sensors);
490 mutex_unlock(&data->lock);
491
492 return count;
493}
494
495static ssize_t show_temp_min(struct device *dev,
496 struct device_attribute *devattr,
497 char *buf)

--- 457 unchanged lines hidden (view full) ---

955 return sprintf(buf, "1\n");
956 else
957 return sprintf(buf, "0\n");
958}
959
960static DEVICE_ATTR(alarm_mask, S_IRUGO, show_alarm_mask, NULL);
961static DEVICE_ATTR(num_temp_sensors, S_IWUSR | S_IRUGO, show_num_temp_sensors,
962 set_num_temp_sensors);
963static DEVICE_ATTR(auto_update_interval, S_IWUSR | S_IRUGO,
964 show_auto_update_interval, set_auto_update_interval);
865
866static SENSOR_DEVICE_ATTR(temp1_max, S_IWUSR | S_IRUGO, show_temp_max,
867 set_temp_max, 0);
868static SENSOR_DEVICE_ATTR(temp2_max, S_IWUSR | S_IRUGO, show_temp_max,
869 set_temp_max, 1);
870static SENSOR_DEVICE_ATTR(temp3_max, S_IWUSR | S_IRUGO, show_temp_max,
871 set_temp_max, 2);
872static SENSOR_DEVICE_ATTR(temp4_max, S_IWUSR | S_IRUGO, show_temp_max,

--- 157 unchanged lines hidden (view full) ---

1030 show_pwm_auto_temp, set_pwm_auto_temp, 2);
1031static SENSOR_DEVICE_ATTR(pwm4_auto_channels_temp, S_IWUSR | S_IRUGO,
1032 show_pwm_auto_temp, set_pwm_auto_temp, 3);
1033
1034static struct attribute *adt7470_attr[] =
1035{
1036 &dev_attr_alarm_mask.attr,
1037 &dev_attr_num_temp_sensors.attr,
965
966static SENSOR_DEVICE_ATTR(temp1_max, S_IWUSR | S_IRUGO, show_temp_max,
967 set_temp_max, 0);
968static SENSOR_DEVICE_ATTR(temp2_max, S_IWUSR | S_IRUGO, show_temp_max,
969 set_temp_max, 1);
970static SENSOR_DEVICE_ATTR(temp3_max, S_IWUSR | S_IRUGO, show_temp_max,
971 set_temp_max, 2);
972static SENSOR_DEVICE_ATTR(temp4_max, S_IWUSR | S_IRUGO, show_temp_max,

--- 157 unchanged lines hidden (view full) ---

1130 show_pwm_auto_temp, set_pwm_auto_temp, 2);
1131static SENSOR_DEVICE_ATTR(pwm4_auto_channels_temp, S_IWUSR | S_IRUGO,
1132 show_pwm_auto_temp, set_pwm_auto_temp, 3);
1133
1134static struct attribute *adt7470_attr[] =
1135{
1136 &dev_attr_alarm_mask.attr,
1137 &dev_attr_num_temp_sensors.attr,
1138 &dev_attr_auto_update_interval.attr,
1038 &sensor_dev_attr_temp1_max.dev_attr.attr,
1039 &sensor_dev_attr_temp2_max.dev_attr.attr,
1040 &sensor_dev_attr_temp3_max.dev_attr.attr,
1041 &sensor_dev_attr_temp4_max.dev_attr.attr,
1042 &sensor_dev_attr_temp5_max.dev_attr.attr,
1043 &sensor_dev_attr_temp6_max.dev_attr.attr,
1044 &sensor_dev_attr_temp7_max.dev_attr.attr,
1045 &sensor_dev_attr_temp8_max.dev_attr.attr,

--- 117 unchanged lines hidden (view full) ---

1163
1164 data = kzalloc(sizeof(struct adt7470_data), GFP_KERNEL);
1165 if (!data) {
1166 err = -ENOMEM;
1167 goto exit;
1168 }
1169
1170 data->num_temp_sensors = -1;
1139 &sensor_dev_attr_temp1_max.dev_attr.attr,
1140 &sensor_dev_attr_temp2_max.dev_attr.attr,
1141 &sensor_dev_attr_temp3_max.dev_attr.attr,
1142 &sensor_dev_attr_temp4_max.dev_attr.attr,
1143 &sensor_dev_attr_temp5_max.dev_attr.attr,
1144 &sensor_dev_attr_temp6_max.dev_attr.attr,
1145 &sensor_dev_attr_temp7_max.dev_attr.attr,
1146 &sensor_dev_attr_temp8_max.dev_attr.attr,

--- 117 unchanged lines hidden (view full) ---

1264
1265 data = kzalloc(sizeof(struct adt7470_data), GFP_KERNEL);
1266 if (!data) {
1267 err = -ENOMEM;
1268 goto exit;
1269 }
1270
1271 data->num_temp_sensors = -1;
1272 data->auto_update_interval = AUTO_UPDATE_INTERVAL;
1171
1172 i2c_set_clientdata(client, data);
1173 mutex_init(&data->lock);
1174
1175 dev_info(&client->dev, "%s chip found\n", client->name);
1176
1177 /* Initialize the ADT7470 chip */
1178 adt7470_init_client(client);

--- 4 unchanged lines hidden (view full) ---

1183 goto exit_free;
1184
1185 data->hwmon_dev = hwmon_device_register(&client->dev);
1186 if (IS_ERR(data->hwmon_dev)) {
1187 err = PTR_ERR(data->hwmon_dev);
1188 goto exit_remove;
1189 }
1190
1273
1274 i2c_set_clientdata(client, data);
1275 mutex_init(&data->lock);
1276
1277 dev_info(&client->dev, "%s chip found\n", client->name);
1278
1279 /* Initialize the ADT7470 chip */
1280 adt7470_init_client(client);

--- 4 unchanged lines hidden (view full) ---

1285 goto exit_free;
1286
1287 data->hwmon_dev = hwmon_device_register(&client->dev);
1288 if (IS_ERR(data->hwmon_dev)) {
1289 err = PTR_ERR(data->hwmon_dev);
1290 goto exit_remove;
1291 }
1292
1293 init_completion(&data->auto_update_stop);
1294 data->auto_update = kthread_run(adt7470_update_thread, client,
1295 dev_name(data->hwmon_dev));
1296 if (IS_ERR(data->auto_update))
1297 goto exit_unregister;
1298
1191 return 0;
1192
1299 return 0;
1300
1301exit_unregister:
1302 hwmon_device_unregister(data->hwmon_dev);
1193exit_remove:
1194 sysfs_remove_group(&client->dev.kobj, &data->attrs);
1195exit_free:
1196 kfree(data);
1197exit:
1198 return err;
1199}
1200
1201static int adt7470_remove(struct i2c_client *client)
1202{
1203 struct adt7470_data *data = i2c_get_clientdata(client);
1204
1303exit_remove:
1304 sysfs_remove_group(&client->dev.kobj, &data->attrs);
1305exit_free:
1306 kfree(data);
1307exit:
1308 return err;
1309}
1310
1311static int adt7470_remove(struct i2c_client *client)
1312{
1313 struct adt7470_data *data = i2c_get_clientdata(client);
1314
1315 kthread_stop(data->auto_update);
1316 wait_for_completion(&data->auto_update_stop);
1205 hwmon_device_unregister(data->hwmon_dev);
1206 sysfs_remove_group(&client->dev.kobj, &data->attrs);
1207 kfree(data);
1208 return 0;
1209}
1210
1211static int __init adt7470_init(void)
1212{

--- 14 unchanged lines hidden ---
1317 hwmon_device_unregister(data->hwmon_dev);
1318 sysfs_remove_group(&client->dev.kobj, &data->attrs);
1319 kfree(data);
1320 return 0;
1321}
1322
1323static int __init adt7470_init(void)
1324{

--- 14 unchanged lines hidden ---