blob: 7dfb4dec4c5f6ca3fb60d91e398446b1456d3423 [file] [log] [blame]
Krzysztof Heltadd77c62007-07-08 22:43:00 +02001/*
2 thmc50.c - Part of lm_sensors, Linux kernel modules for hardware
3 monitoring
4 Copyright (C) 2007 Krzysztof Helt <krzysztof.h1@wp.pl>
5 Based on 2.4 driver by Frodo Looijaard <frodol@dds.nl> and
6 Philip Edelbrock <phil@netroedge.com>
7
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
12
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21*/
22
23#include <linux/module.h>
24#include <linux/init.h>
25#include <linux/slab.h>
26#include <linux/i2c.h>
27#include <linux/hwmon.h>
28#include <linux/hwmon-sysfs.h>
29#include <linux/err.h>
30#include <linux/mutex.h>
31
32MODULE_LICENSE("GPL");
33
34/* Addresses to scan */
Mark M. Hoffman25e9c862008-02-17 22:28:03 -050035static const unsigned short normal_i2c[] = { 0x2c, 0x2d, 0x2e, I2C_CLIENT_END };
Krzysztof Heltadd77c62007-07-08 22:43:00 +020036
37/* Insmod parameters */
Jean Delvaree5e9f442009-12-14 21:17:27 +010038enum chips { thmc50, adm1022 };
Jean Delvaref95f0b42009-12-09 20:35:59 +010039
40static unsigned short adm1022_temp3[16];
41static unsigned int adm1022_temp3_num;
42module_param_array(adm1022_temp3, ushort, &adm1022_temp3_num, 0);
43MODULE_PARM_DESC(adm1022_temp3, "List of adapter,address pairs "
Krzysztof Heltadd77c62007-07-08 22:43:00 +020044 "to enable 3rd temperature (ADM1022 only)");
45
46/* Many THMC50 constants specified below */
47
48/* The THMC50 registers */
49#define THMC50_REG_CONF 0x40
50#define THMC50_REG_COMPANY_ID 0x3E
51#define THMC50_REG_DIE_CODE 0x3F
52#define THMC50_REG_ANALOG_OUT 0x19
Krzysztof Heltdcf3b5f2007-08-22 14:05:22 -040053/*
Krzysztof Heltbba891c2007-09-09 17:35:34 +020054 * The mirror status register cannot be used as
55 * reading it does not clear alarms.
Krzysztof Heltdcf3b5f2007-08-22 14:05:22 -040056 */
Krzysztof Heltbba891c2007-09-09 17:35:34 +020057#define THMC50_REG_INTR 0x41
Krzysztof Heltadd77c62007-07-08 22:43:00 +020058
Tobias Klauser5910a9b2008-02-17 15:39:24 +010059static const u8 THMC50_REG_TEMP[] = { 0x27, 0x26, 0x20 };
60static const u8 THMC50_REG_TEMP_MIN[] = { 0x3A, 0x38, 0x2C };
61static const u8 THMC50_REG_TEMP_MAX[] = { 0x39, 0x37, 0x2B };
Krzysztof Helt84f768c2008-08-06 22:41:05 +020062static const u8 THMC50_REG_TEMP_CRITICAL[] = { 0x13, 0x14, 0x14 };
63static const u8 THMC50_REG_TEMP_DEFAULT[] = { 0x17, 0x18, 0x18 };
Krzysztof Heltadd77c62007-07-08 22:43:00 +020064
65#define THMC50_REG_CONF_nFANOFF 0x20
Krzysztof Helt84f768c2008-08-06 22:41:05 +020066#define THMC50_REG_CONF_PROGRAMMED 0x08
Krzysztof Heltadd77c62007-07-08 22:43:00 +020067
68/* Each client has this additional data */
69struct thmc50_data {
Tony Jones1beeffe2007-08-20 13:46:20 -070070 struct device *hwmon_dev;
Krzysztof Heltadd77c62007-07-08 22:43:00 +020071
72 struct mutex update_lock;
73 enum chips type;
74 unsigned long last_updated; /* In jiffies */
75 char has_temp3; /* !=0 if it is ADM1022 in temp3 mode */
76 char valid; /* !=0 if following fields are valid */
77
78 /* Register values */
79 s8 temp_input[3];
80 s8 temp_max[3];
81 s8 temp_min[3];
Krzysztof Helt84f768c2008-08-06 22:41:05 +020082 s8 temp_critical[3];
Krzysztof Heltadd77c62007-07-08 22:43:00 +020083 u8 analog_out;
Krzysztof Heltdcf3b5f2007-08-22 14:05:22 -040084 u8 alarms;
Krzysztof Heltadd77c62007-07-08 22:43:00 +020085};
86
Jean Delvare310ec792009-12-14 21:17:23 +010087static int thmc50_detect(struct i2c_client *client,
Jean Delvareccf37482008-07-16 19:30:16 +020088 struct i2c_board_info *info);
89static int thmc50_probe(struct i2c_client *client,
90 const struct i2c_device_id *id);
91static int thmc50_remove(struct i2c_client *client);
Krzysztof Heltadd77c62007-07-08 22:43:00 +020092static void thmc50_init_client(struct i2c_client *client);
93static struct thmc50_data *thmc50_update_device(struct device *dev);
94
Jean Delvareccf37482008-07-16 19:30:16 +020095static const struct i2c_device_id thmc50_id[] = {
96 { "adm1022", adm1022 },
97 { "thmc50", thmc50 },
98 { }
99};
100MODULE_DEVICE_TABLE(i2c, thmc50_id);
101
Krzysztof Heltadd77c62007-07-08 22:43:00 +0200102static struct i2c_driver thmc50_driver = {
Jean Delvareccf37482008-07-16 19:30:16 +0200103 .class = I2C_CLASS_HWMON,
Krzysztof Heltadd77c62007-07-08 22:43:00 +0200104 .driver = {
105 .name = "thmc50",
106 },
Jean Delvareccf37482008-07-16 19:30:16 +0200107 .probe = thmc50_probe,
108 .remove = thmc50_remove,
109 .id_table = thmc50_id,
110 .detect = thmc50_detect,
Jean Delvarec3813d62009-12-14 21:17:25 +0100111 .address_list = normal_i2c,
Krzysztof Heltadd77c62007-07-08 22:43:00 +0200112};
113
114static ssize_t show_analog_out(struct device *dev,
115 struct device_attribute *attr, char *buf)
116{
117 struct thmc50_data *data = thmc50_update_device(dev);
118 return sprintf(buf, "%d\n", data->analog_out);
119}
120
121static ssize_t set_analog_out(struct device *dev,
122 struct device_attribute *attr,
123 const char *buf, size_t count)
124{
125 struct i2c_client *client = to_i2c_client(dev);
126 struct thmc50_data *data = i2c_get_clientdata(client);
127 int tmp = simple_strtoul(buf, NULL, 10);
128 int config;
129
130 mutex_lock(&data->update_lock);
131 data->analog_out = SENSORS_LIMIT(tmp, 0, 255);
132 i2c_smbus_write_byte_data(client, THMC50_REG_ANALOG_OUT,
133 data->analog_out);
134
135 config = i2c_smbus_read_byte_data(client, THMC50_REG_CONF);
136 if (data->analog_out == 0)
137 config &= ~THMC50_REG_CONF_nFANOFF;
138 else
139 config |= THMC50_REG_CONF_nFANOFF;
140 i2c_smbus_write_byte_data(client, THMC50_REG_CONF, config);
141
142 mutex_unlock(&data->update_lock);
143 return count;
144}
145
146/* There is only one PWM mode = DC */
147static ssize_t show_pwm_mode(struct device *dev, struct device_attribute *attr,
148 char *buf)
149{
150 return sprintf(buf, "0\n");
151}
152
153/* Temperatures */
154static ssize_t show_temp(struct device *dev, struct device_attribute *attr,
155 char *buf)
156{
157 int nr = to_sensor_dev_attr(attr)->index;
158 struct thmc50_data *data = thmc50_update_device(dev);
159 return sprintf(buf, "%d\n", data->temp_input[nr] * 1000);
160}
161
162static ssize_t show_temp_min(struct device *dev, struct device_attribute *attr,
163 char *buf)
164{
165 int nr = to_sensor_dev_attr(attr)->index;
166 struct thmc50_data *data = thmc50_update_device(dev);
167 return sprintf(buf, "%d\n", data->temp_min[nr] * 1000);
168}
169
170static ssize_t set_temp_min(struct device *dev, struct device_attribute *attr,
171 const char *buf, size_t count)
172{
173 int nr = to_sensor_dev_attr(attr)->index;
174 struct i2c_client *client = to_i2c_client(dev);
175 struct thmc50_data *data = i2c_get_clientdata(client);
176 int val = simple_strtol(buf, NULL, 10);
177
178 mutex_lock(&data->update_lock);
179 data->temp_min[nr] = SENSORS_LIMIT(val / 1000, -128, 127);
180 i2c_smbus_write_byte_data(client, THMC50_REG_TEMP_MIN[nr],
181 data->temp_min[nr]);
182 mutex_unlock(&data->update_lock);
183 return count;
184}
185
186static ssize_t show_temp_max(struct device *dev, struct device_attribute *attr,
187 char *buf)
188{
189 int nr = to_sensor_dev_attr(attr)->index;
190 struct thmc50_data *data = thmc50_update_device(dev);
191 return sprintf(buf, "%d\n", data->temp_max[nr] * 1000);
192}
193
194static ssize_t set_temp_max(struct device *dev, struct device_attribute *attr,
195 const char *buf, size_t count)
196{
197 int nr = to_sensor_dev_attr(attr)->index;
198 struct i2c_client *client = to_i2c_client(dev);
199 struct thmc50_data *data = i2c_get_clientdata(client);
200 int val = simple_strtol(buf, NULL, 10);
201
202 mutex_lock(&data->update_lock);
203 data->temp_max[nr] = SENSORS_LIMIT(val / 1000, -128, 127);
204 i2c_smbus_write_byte_data(client, THMC50_REG_TEMP_MAX[nr],
205 data->temp_max[nr]);
206 mutex_unlock(&data->update_lock);
207 return count;
208}
209
Krzysztof Helt84f768c2008-08-06 22:41:05 +0200210static ssize_t show_temp_critical(struct device *dev,
211 struct device_attribute *attr,
212 char *buf)
213{
214 int nr = to_sensor_dev_attr(attr)->index;
215 struct thmc50_data *data = thmc50_update_device(dev);
216 return sprintf(buf, "%d\n", data->temp_critical[nr] * 1000);
217}
218
Krzysztof Heltdcf3b5f2007-08-22 14:05:22 -0400219static ssize_t show_alarm(struct device *dev, struct device_attribute *attr,
220 char *buf)
221{
222 int index = to_sensor_dev_attr(attr)->index;
223 struct thmc50_data *data = thmc50_update_device(dev);
224
225 return sprintf(buf, "%u\n", (data->alarms >> index) & 1);
226}
227
Krzysztof Heltadd77c62007-07-08 22:43:00 +0200228#define temp_reg(offset) \
229static SENSOR_DEVICE_ATTR(temp##offset##_input, S_IRUGO, show_temp, \
230 NULL, offset - 1); \
231static SENSOR_DEVICE_ATTR(temp##offset##_min, S_IRUGO | S_IWUSR, \
232 show_temp_min, set_temp_min, offset - 1); \
233static SENSOR_DEVICE_ATTR(temp##offset##_max, S_IRUGO | S_IWUSR, \
Krzysztof Helt84f768c2008-08-06 22:41:05 +0200234 show_temp_max, set_temp_max, offset - 1); \
235static SENSOR_DEVICE_ATTR(temp##offset##_crit, S_IRUGO, \
236 show_temp_critical, NULL, offset - 1);
Krzysztof Heltadd77c62007-07-08 22:43:00 +0200237
238temp_reg(1);
239temp_reg(2);
240temp_reg(3);
241
Krzysztof Heltdcf3b5f2007-08-22 14:05:22 -0400242static SENSOR_DEVICE_ATTR(temp1_alarm, S_IRUGO, show_alarm, NULL, 0);
243static SENSOR_DEVICE_ATTR(temp2_alarm, S_IRUGO, show_alarm, NULL, 5);
244static SENSOR_DEVICE_ATTR(temp3_alarm, S_IRUGO, show_alarm, NULL, 1);
245static SENSOR_DEVICE_ATTR(temp2_fault, S_IRUGO, show_alarm, NULL, 7);
246static SENSOR_DEVICE_ATTR(temp3_fault, S_IRUGO, show_alarm, NULL, 2);
247
Krzysztof Heltadd77c62007-07-08 22:43:00 +0200248static SENSOR_DEVICE_ATTR(pwm1, S_IRUGO | S_IWUSR, show_analog_out,
249 set_analog_out, 0);
250static SENSOR_DEVICE_ATTR(pwm1_mode, S_IRUGO, show_pwm_mode, NULL, 0);
251
252static struct attribute *thmc50_attributes[] = {
253 &sensor_dev_attr_temp1_max.dev_attr.attr,
254 &sensor_dev_attr_temp1_min.dev_attr.attr,
255 &sensor_dev_attr_temp1_input.dev_attr.attr,
Krzysztof Helt84f768c2008-08-06 22:41:05 +0200256 &sensor_dev_attr_temp1_crit.dev_attr.attr,
Krzysztof Heltdcf3b5f2007-08-22 14:05:22 -0400257 &sensor_dev_attr_temp1_alarm.dev_attr.attr,
Krzysztof Heltadd77c62007-07-08 22:43:00 +0200258 &sensor_dev_attr_temp2_max.dev_attr.attr,
259 &sensor_dev_attr_temp2_min.dev_attr.attr,
260 &sensor_dev_attr_temp2_input.dev_attr.attr,
Krzysztof Helt84f768c2008-08-06 22:41:05 +0200261 &sensor_dev_attr_temp2_crit.dev_attr.attr,
Krzysztof Heltdcf3b5f2007-08-22 14:05:22 -0400262 &sensor_dev_attr_temp2_alarm.dev_attr.attr,
263 &sensor_dev_attr_temp2_fault.dev_attr.attr,
Krzysztof Heltadd77c62007-07-08 22:43:00 +0200264 &sensor_dev_attr_pwm1.dev_attr.attr,
265 &sensor_dev_attr_pwm1_mode.dev_attr.attr,
266 NULL
267};
268
269static const struct attribute_group thmc50_group = {
270 .attrs = thmc50_attributes,
271};
272
273/* for ADM1022 3rd temperature mode */
Jean Delvare894c00c2007-09-18 18:44:42 +0200274static struct attribute *temp3_attributes[] = {
Krzysztof Heltadd77c62007-07-08 22:43:00 +0200275 &sensor_dev_attr_temp3_max.dev_attr.attr,
276 &sensor_dev_attr_temp3_min.dev_attr.attr,
277 &sensor_dev_attr_temp3_input.dev_attr.attr,
Krzysztof Helt84f768c2008-08-06 22:41:05 +0200278 &sensor_dev_attr_temp3_crit.dev_attr.attr,
Krzysztof Heltdcf3b5f2007-08-22 14:05:22 -0400279 &sensor_dev_attr_temp3_alarm.dev_attr.attr,
280 &sensor_dev_attr_temp3_fault.dev_attr.attr,
Krzysztof Heltadd77c62007-07-08 22:43:00 +0200281 NULL
282};
283
Jean Delvare894c00c2007-09-18 18:44:42 +0200284static const struct attribute_group temp3_group = {
285 .attrs = temp3_attributes,
Krzysztof Heltadd77c62007-07-08 22:43:00 +0200286};
287
Jean Delvareccf37482008-07-16 19:30:16 +0200288/* Return 0 if detection is successful, -ENODEV otherwise */
Jean Delvare310ec792009-12-14 21:17:23 +0100289static int thmc50_detect(struct i2c_client *client,
Jean Delvareccf37482008-07-16 19:30:16 +0200290 struct i2c_board_info *info)
Krzysztof Heltadd77c62007-07-08 22:43:00 +0200291{
292 unsigned company;
293 unsigned revision;
294 unsigned config;
Jean Delvareccf37482008-07-16 19:30:16 +0200295 struct i2c_adapter *adapter = client->adapter;
Jean Delvarecc28a612007-09-18 18:48:16 +0200296 const char *type_name;
Krzysztof Heltadd77c62007-07-08 22:43:00 +0200297
298 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) {
299 pr_debug("thmc50: detect failed, "
300 "smbus byte data not supported!\n");
Jean Delvareccf37482008-07-16 19:30:16 +0200301 return -ENODEV;
Krzysztof Heltadd77c62007-07-08 22:43:00 +0200302 }
303
Krzysztof Heltadd77c62007-07-08 22:43:00 +0200304 pr_debug("thmc50: Probing for THMC50 at 0x%2X on bus %d\n",
305 client->addr, i2c_adapter_id(client->adapter));
306
Krzysztof Heltadd77c62007-07-08 22:43:00 +0200307 company = i2c_smbus_read_byte_data(client, THMC50_REG_COMPANY_ID);
308 revision = i2c_smbus_read_byte_data(client, THMC50_REG_DIE_CODE);
309 config = i2c_smbus_read_byte_data(client, THMC50_REG_CONF);
Jean Delvare52df6442009-12-09 20:35:57 +0100310 if (revision < 0xc0 || (config & 0x10))
311 return -ENODEV;
Krzysztof Heltadd77c62007-07-08 22:43:00 +0200312
Jean Delvare52df6442009-12-09 20:35:57 +0100313 if (company == 0x41) {
Krzysztof Heltadd77c62007-07-08 22:43:00 +0200314 int id = i2c_adapter_id(client->adapter);
315 int i;
316
317 type_name = "adm1022";
Krzysztof Heltadd77c62007-07-08 22:43:00 +0200318 for (i = 0; i + 1 < adm1022_temp3_num; i += 2)
319 if (adm1022_temp3[i] == id &&
Jean Delvareccf37482008-07-16 19:30:16 +0200320 adm1022_temp3[i + 1] == client->addr) {
Krzysztof Heltadd77c62007-07-08 22:43:00 +0200321 /* enable 2nd remote temp */
Jean Delvareccf37482008-07-16 19:30:16 +0200322 config |= (1 << 7);
323 i2c_smbus_write_byte_data(client,
324 THMC50_REG_CONF,
325 config);
Krzysztof Heltadd77c62007-07-08 22:43:00 +0200326 break;
327 }
Jean Delvare52df6442009-12-09 20:35:57 +0100328 } else if (company == 0x49) {
Jean Delvarecc28a612007-09-18 18:48:16 +0200329 type_name = "thmc50";
Jean Delvare52df6442009-12-09 20:35:57 +0100330 } else {
331 pr_debug("thmc50: Detection of THMC50/ADM1022 failed\n");
332 return -ENODEV;
Krzysztof Heltadd77c62007-07-08 22:43:00 +0200333 }
Jean Delvare52df6442009-12-09 20:35:57 +0100334
Jean Delvarecc28a612007-09-18 18:48:16 +0200335 pr_debug("thmc50: Detected %s (version %x, revision %x)\n",
336 type_name, (revision >> 4) - 0xc, revision & 0xf);
Krzysztof Heltadd77c62007-07-08 22:43:00 +0200337
Jean Delvareccf37482008-07-16 19:30:16 +0200338 strlcpy(info->type, type_name, I2C_NAME_SIZE);
Krzysztof Heltadd77c62007-07-08 22:43:00 +0200339
Jean Delvareccf37482008-07-16 19:30:16 +0200340 return 0;
341}
342
343static int thmc50_probe(struct i2c_client *client,
344 const struct i2c_device_id *id)
345{
346 struct thmc50_data *data;
347 int err;
348
349 data = kzalloc(sizeof(struct thmc50_data), GFP_KERNEL);
350 if (!data) {
351 pr_debug("thmc50: detect failed, kzalloc failed!\n");
352 err = -ENOMEM;
353 goto exit;
354 }
355
356 i2c_set_clientdata(client, data);
357 data->type = id->driver_data;
358 mutex_init(&data->update_lock);
Krzysztof Heltadd77c62007-07-08 22:43:00 +0200359
360 thmc50_init_client(client);
361
362 /* Register sysfs hooks */
363 if ((err = sysfs_create_group(&client->dev.kobj, &thmc50_group)))
Jean Delvareccf37482008-07-16 19:30:16 +0200364 goto exit_free;
Krzysztof Heltadd77c62007-07-08 22:43:00 +0200365
366 /* Register ADM1022 sysfs hooks */
Jean Delvare894c00c2007-09-18 18:44:42 +0200367 if (data->has_temp3)
Krzysztof Heltadd77c62007-07-08 22:43:00 +0200368 if ((err = sysfs_create_group(&client->dev.kobj,
Jean Delvare894c00c2007-09-18 18:44:42 +0200369 &temp3_group)))
Krzysztof Heltadd77c62007-07-08 22:43:00 +0200370 goto exit_remove_sysfs_thmc50;
371
372 /* Register a new directory entry with module sensors */
Tony Jones1beeffe2007-08-20 13:46:20 -0700373 data->hwmon_dev = hwmon_device_register(&client->dev);
374 if (IS_ERR(data->hwmon_dev)) {
375 err = PTR_ERR(data->hwmon_dev);
Krzysztof Heltadd77c62007-07-08 22:43:00 +0200376 goto exit_remove_sysfs;
377 }
378
379 return 0;
380
381exit_remove_sysfs:
Jean Delvare894c00c2007-09-18 18:44:42 +0200382 if (data->has_temp3)
383 sysfs_remove_group(&client->dev.kobj, &temp3_group);
Krzysztof Heltadd77c62007-07-08 22:43:00 +0200384exit_remove_sysfs_thmc50:
385 sysfs_remove_group(&client->dev.kobj, &thmc50_group);
Krzysztof Heltadd77c62007-07-08 22:43:00 +0200386exit_free:
387 kfree(data);
388exit:
389 return err;
390}
391
Jean Delvareccf37482008-07-16 19:30:16 +0200392static int thmc50_remove(struct i2c_client *client)
Krzysztof Heltadd77c62007-07-08 22:43:00 +0200393{
394 struct thmc50_data *data = i2c_get_clientdata(client);
Krzysztof Heltadd77c62007-07-08 22:43:00 +0200395
Tony Jones1beeffe2007-08-20 13:46:20 -0700396 hwmon_device_unregister(data->hwmon_dev);
Krzysztof Heltadd77c62007-07-08 22:43:00 +0200397 sysfs_remove_group(&client->dev.kobj, &thmc50_group);
Jean Delvare894c00c2007-09-18 18:44:42 +0200398 if (data->has_temp3)
399 sysfs_remove_group(&client->dev.kobj, &temp3_group);
Krzysztof Heltadd77c62007-07-08 22:43:00 +0200400
Krzysztof Heltadd77c62007-07-08 22:43:00 +0200401 kfree(data);
402
403 return 0;
404}
405
406static void thmc50_init_client(struct i2c_client *client)
407{
408 struct thmc50_data *data = i2c_get_clientdata(client);
409 int config;
410
411 data->analog_out = i2c_smbus_read_byte_data(client,
412 THMC50_REG_ANALOG_OUT);
413 /* set up to at least 1 */
414 if (data->analog_out == 0) {
415 data->analog_out = 1;
416 i2c_smbus_write_byte_data(client, THMC50_REG_ANALOG_OUT,
417 data->analog_out);
418 }
419 config = i2c_smbus_read_byte_data(client, THMC50_REG_CONF);
420 config |= 0x1; /* start the chip if it is in standby mode */
Jean Delvareccf37482008-07-16 19:30:16 +0200421 if (data->type == adm1022 && (config & (1 << 7)))
422 data->has_temp3 = 1;
Krzysztof Heltadd77c62007-07-08 22:43:00 +0200423 i2c_smbus_write_byte_data(client, THMC50_REG_CONF, config);
424}
425
426static struct thmc50_data *thmc50_update_device(struct device *dev)
427{
428 struct i2c_client *client = to_i2c_client(dev);
429 struct thmc50_data *data = i2c_get_clientdata(client);
430 int timeout = HZ / 5 + (data->type == thmc50 ? HZ : 0);
431
432 mutex_lock(&data->update_lock);
433
434 if (time_after(jiffies, data->last_updated + timeout)
435 || !data->valid) {
436
437 int temps = data->has_temp3 ? 3 : 2;
438 int i;
Krzysztof Helt84f768c2008-08-06 22:41:05 +0200439 int prog = i2c_smbus_read_byte_data(client, THMC50_REG_CONF);
440
441 prog &= THMC50_REG_CONF_PROGRAMMED;
442
Krzysztof Heltadd77c62007-07-08 22:43:00 +0200443 for (i = 0; i < temps; i++) {
444 data->temp_input[i] = i2c_smbus_read_byte_data(client,
445 THMC50_REG_TEMP[i]);
446 data->temp_max[i] = i2c_smbus_read_byte_data(client,
447 THMC50_REG_TEMP_MAX[i]);
448 data->temp_min[i] = i2c_smbus_read_byte_data(client,
449 THMC50_REG_TEMP_MIN[i]);
Krzysztof Helt84f768c2008-08-06 22:41:05 +0200450 data->temp_critical[i] =
451 i2c_smbus_read_byte_data(client,
452 prog ? THMC50_REG_TEMP_CRITICAL[i]
453 : THMC50_REG_TEMP_DEFAULT[i]);
Krzysztof Heltadd77c62007-07-08 22:43:00 +0200454 }
455 data->analog_out =
456 i2c_smbus_read_byte_data(client, THMC50_REG_ANALOG_OUT);
Krzysztof Heltdcf3b5f2007-08-22 14:05:22 -0400457 data->alarms =
Krzysztof Heltbba891c2007-09-09 17:35:34 +0200458 i2c_smbus_read_byte_data(client, THMC50_REG_INTR);
Krzysztof Heltadd77c62007-07-08 22:43:00 +0200459 data->last_updated = jiffies;
460 data->valid = 1;
461 }
462
463 mutex_unlock(&data->update_lock);
464
465 return data;
466}
467
468static int __init sm_thmc50_init(void)
469{
470 return i2c_add_driver(&thmc50_driver);
471}
472
473static void __exit sm_thmc50_exit(void)
474{
475 i2c_del_driver(&thmc50_driver);
476}
477
478MODULE_AUTHOR("Krzysztof Helt <krzysztof.h1@wp.pl>");
479MODULE_DESCRIPTION("THMC50 driver");
480
481module_init(sm_thmc50_init);
482module_exit(sm_thmc50_exit);