blob: 7d97431e132f2f76fbc22e1e8d693d7c0e58b017 [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 */
38I2C_CLIENT_INSMOD_2(thmc50, adm1022);
39I2C_CLIENT_MODULE_PARM(adm1022_temp3, "List of adapter,address pairs "
40 "to enable 3rd temperature (ADM1022 only)");
41
42/* Many THMC50 constants specified below */
43
44/* The THMC50 registers */
45#define THMC50_REG_CONF 0x40
46#define THMC50_REG_COMPANY_ID 0x3E
47#define THMC50_REG_DIE_CODE 0x3F
48#define THMC50_REG_ANALOG_OUT 0x19
Krzysztof Heltdcf3b5f2007-08-22 14:05:22 -040049/*
Krzysztof Heltbba891c2007-09-09 17:35:34 +020050 * The mirror status register cannot be used as
51 * reading it does not clear alarms.
Krzysztof Heltdcf3b5f2007-08-22 14:05:22 -040052 */
Krzysztof Heltbba891c2007-09-09 17:35:34 +020053#define THMC50_REG_INTR 0x41
Krzysztof Heltadd77c62007-07-08 22:43:00 +020054
Tobias Klauser5910a9b2008-02-17 15:39:24 +010055static const u8 THMC50_REG_TEMP[] = { 0x27, 0x26, 0x20 };
56static const u8 THMC50_REG_TEMP_MIN[] = { 0x3A, 0x38, 0x2C };
57static const u8 THMC50_REG_TEMP_MAX[] = { 0x39, 0x37, 0x2B };
Krzysztof Helt84f768c2008-08-06 22:41:05 +020058static const u8 THMC50_REG_TEMP_CRITICAL[] = { 0x13, 0x14, 0x14 };
59static const u8 THMC50_REG_TEMP_DEFAULT[] = { 0x17, 0x18, 0x18 };
Krzysztof Heltadd77c62007-07-08 22:43:00 +020060
61#define THMC50_REG_CONF_nFANOFF 0x20
Krzysztof Helt84f768c2008-08-06 22:41:05 +020062#define THMC50_REG_CONF_PROGRAMMED 0x08
Krzysztof Heltadd77c62007-07-08 22:43:00 +020063
64/* Each client has this additional data */
65struct thmc50_data {
Tony Jones1beeffe2007-08-20 13:46:20 -070066 struct device *hwmon_dev;
Krzysztof Heltadd77c62007-07-08 22:43:00 +020067
68 struct mutex update_lock;
69 enum chips type;
70 unsigned long last_updated; /* In jiffies */
71 char has_temp3; /* !=0 if it is ADM1022 in temp3 mode */
72 char valid; /* !=0 if following fields are valid */
73
74 /* Register values */
75 s8 temp_input[3];
76 s8 temp_max[3];
77 s8 temp_min[3];
Krzysztof Helt84f768c2008-08-06 22:41:05 +020078 s8 temp_critical[3];
Krzysztof Heltadd77c62007-07-08 22:43:00 +020079 u8 analog_out;
Krzysztof Heltdcf3b5f2007-08-22 14:05:22 -040080 u8 alarms;
Krzysztof Heltadd77c62007-07-08 22:43:00 +020081};
82
Jean Delvareccf37482008-07-16 19:30:16 +020083static int thmc50_detect(struct i2c_client *client, int kind,
84 struct i2c_board_info *info);
85static int thmc50_probe(struct i2c_client *client,
86 const struct i2c_device_id *id);
87static int thmc50_remove(struct i2c_client *client);
Krzysztof Heltadd77c62007-07-08 22:43:00 +020088static void thmc50_init_client(struct i2c_client *client);
89static struct thmc50_data *thmc50_update_device(struct device *dev);
90
Jean Delvareccf37482008-07-16 19:30:16 +020091static const struct i2c_device_id thmc50_id[] = {
92 { "adm1022", adm1022 },
93 { "thmc50", thmc50 },
94 { }
95};
96MODULE_DEVICE_TABLE(i2c, thmc50_id);
97
Krzysztof Heltadd77c62007-07-08 22:43:00 +020098static struct i2c_driver thmc50_driver = {
Jean Delvareccf37482008-07-16 19:30:16 +020099 .class = I2C_CLASS_HWMON,
Krzysztof Heltadd77c62007-07-08 22:43:00 +0200100 .driver = {
101 .name = "thmc50",
102 },
Jean Delvareccf37482008-07-16 19:30:16 +0200103 .probe = thmc50_probe,
104 .remove = thmc50_remove,
105 .id_table = thmc50_id,
106 .detect = thmc50_detect,
107 .address_data = &addr_data,
Krzysztof Heltadd77c62007-07-08 22:43:00 +0200108};
109
110static ssize_t show_analog_out(struct device *dev,
111 struct device_attribute *attr, char *buf)
112{
113 struct thmc50_data *data = thmc50_update_device(dev);
114 return sprintf(buf, "%d\n", data->analog_out);
115}
116
117static ssize_t set_analog_out(struct device *dev,
118 struct device_attribute *attr,
119 const char *buf, size_t count)
120{
121 struct i2c_client *client = to_i2c_client(dev);
122 struct thmc50_data *data = i2c_get_clientdata(client);
123 int tmp = simple_strtoul(buf, NULL, 10);
124 int config;
125
126 mutex_lock(&data->update_lock);
127 data->analog_out = SENSORS_LIMIT(tmp, 0, 255);
128 i2c_smbus_write_byte_data(client, THMC50_REG_ANALOG_OUT,
129 data->analog_out);
130
131 config = i2c_smbus_read_byte_data(client, THMC50_REG_CONF);
132 if (data->analog_out == 0)
133 config &= ~THMC50_REG_CONF_nFANOFF;
134 else
135 config |= THMC50_REG_CONF_nFANOFF;
136 i2c_smbus_write_byte_data(client, THMC50_REG_CONF, config);
137
138 mutex_unlock(&data->update_lock);
139 return count;
140}
141
142/* There is only one PWM mode = DC */
143static ssize_t show_pwm_mode(struct device *dev, struct device_attribute *attr,
144 char *buf)
145{
146 return sprintf(buf, "0\n");
147}
148
149/* Temperatures */
150static ssize_t show_temp(struct device *dev, struct device_attribute *attr,
151 char *buf)
152{
153 int nr = to_sensor_dev_attr(attr)->index;
154 struct thmc50_data *data = thmc50_update_device(dev);
155 return sprintf(buf, "%d\n", data->temp_input[nr] * 1000);
156}
157
158static ssize_t show_temp_min(struct device *dev, struct device_attribute *attr,
159 char *buf)
160{
161 int nr = to_sensor_dev_attr(attr)->index;
162 struct thmc50_data *data = thmc50_update_device(dev);
163 return sprintf(buf, "%d\n", data->temp_min[nr] * 1000);
164}
165
166static ssize_t set_temp_min(struct device *dev, struct device_attribute *attr,
167 const char *buf, size_t count)
168{
169 int nr = to_sensor_dev_attr(attr)->index;
170 struct i2c_client *client = to_i2c_client(dev);
171 struct thmc50_data *data = i2c_get_clientdata(client);
172 int val = simple_strtol(buf, NULL, 10);
173
174 mutex_lock(&data->update_lock);
175 data->temp_min[nr] = SENSORS_LIMIT(val / 1000, -128, 127);
176 i2c_smbus_write_byte_data(client, THMC50_REG_TEMP_MIN[nr],
177 data->temp_min[nr]);
178 mutex_unlock(&data->update_lock);
179 return count;
180}
181
182static ssize_t show_temp_max(struct device *dev, struct device_attribute *attr,
183 char *buf)
184{
185 int nr = to_sensor_dev_attr(attr)->index;
186 struct thmc50_data *data = thmc50_update_device(dev);
187 return sprintf(buf, "%d\n", data->temp_max[nr] * 1000);
188}
189
190static ssize_t set_temp_max(struct device *dev, struct device_attribute *attr,
191 const char *buf, size_t count)
192{
193 int nr = to_sensor_dev_attr(attr)->index;
194 struct i2c_client *client = to_i2c_client(dev);
195 struct thmc50_data *data = i2c_get_clientdata(client);
196 int val = simple_strtol(buf, NULL, 10);
197
198 mutex_lock(&data->update_lock);
199 data->temp_max[nr] = SENSORS_LIMIT(val / 1000, -128, 127);
200 i2c_smbus_write_byte_data(client, THMC50_REG_TEMP_MAX[nr],
201 data->temp_max[nr]);
202 mutex_unlock(&data->update_lock);
203 return count;
204}
205
Krzysztof Helt84f768c2008-08-06 22:41:05 +0200206static ssize_t show_temp_critical(struct device *dev,
207 struct device_attribute *attr,
208 char *buf)
209{
210 int nr = to_sensor_dev_attr(attr)->index;
211 struct thmc50_data *data = thmc50_update_device(dev);
212 return sprintf(buf, "%d\n", data->temp_critical[nr] * 1000);
213}
214
Krzysztof Heltdcf3b5f2007-08-22 14:05:22 -0400215static ssize_t show_alarm(struct device *dev, struct device_attribute *attr,
216 char *buf)
217{
218 int index = to_sensor_dev_attr(attr)->index;
219 struct thmc50_data *data = thmc50_update_device(dev);
220
221 return sprintf(buf, "%u\n", (data->alarms >> index) & 1);
222}
223
Krzysztof Heltadd77c62007-07-08 22:43:00 +0200224#define temp_reg(offset) \
225static SENSOR_DEVICE_ATTR(temp##offset##_input, S_IRUGO, show_temp, \
226 NULL, offset - 1); \
227static SENSOR_DEVICE_ATTR(temp##offset##_min, S_IRUGO | S_IWUSR, \
228 show_temp_min, set_temp_min, offset - 1); \
229static SENSOR_DEVICE_ATTR(temp##offset##_max, S_IRUGO | S_IWUSR, \
Krzysztof Helt84f768c2008-08-06 22:41:05 +0200230 show_temp_max, set_temp_max, offset - 1); \
231static SENSOR_DEVICE_ATTR(temp##offset##_crit, S_IRUGO, \
232 show_temp_critical, NULL, offset - 1);
Krzysztof Heltadd77c62007-07-08 22:43:00 +0200233
234temp_reg(1);
235temp_reg(2);
236temp_reg(3);
237
Krzysztof Heltdcf3b5f2007-08-22 14:05:22 -0400238static SENSOR_DEVICE_ATTR(temp1_alarm, S_IRUGO, show_alarm, NULL, 0);
239static SENSOR_DEVICE_ATTR(temp2_alarm, S_IRUGO, show_alarm, NULL, 5);
240static SENSOR_DEVICE_ATTR(temp3_alarm, S_IRUGO, show_alarm, NULL, 1);
241static SENSOR_DEVICE_ATTR(temp2_fault, S_IRUGO, show_alarm, NULL, 7);
242static SENSOR_DEVICE_ATTR(temp3_fault, S_IRUGO, show_alarm, NULL, 2);
243
Krzysztof Heltadd77c62007-07-08 22:43:00 +0200244static SENSOR_DEVICE_ATTR(pwm1, S_IRUGO | S_IWUSR, show_analog_out,
245 set_analog_out, 0);
246static SENSOR_DEVICE_ATTR(pwm1_mode, S_IRUGO, show_pwm_mode, NULL, 0);
247
248static struct attribute *thmc50_attributes[] = {
249 &sensor_dev_attr_temp1_max.dev_attr.attr,
250 &sensor_dev_attr_temp1_min.dev_attr.attr,
251 &sensor_dev_attr_temp1_input.dev_attr.attr,
Krzysztof Helt84f768c2008-08-06 22:41:05 +0200252 &sensor_dev_attr_temp1_crit.dev_attr.attr,
Krzysztof Heltdcf3b5f2007-08-22 14:05:22 -0400253 &sensor_dev_attr_temp1_alarm.dev_attr.attr,
Krzysztof Heltadd77c62007-07-08 22:43:00 +0200254 &sensor_dev_attr_temp2_max.dev_attr.attr,
255 &sensor_dev_attr_temp2_min.dev_attr.attr,
256 &sensor_dev_attr_temp2_input.dev_attr.attr,
Krzysztof Helt84f768c2008-08-06 22:41:05 +0200257 &sensor_dev_attr_temp2_crit.dev_attr.attr,
Krzysztof Heltdcf3b5f2007-08-22 14:05:22 -0400258 &sensor_dev_attr_temp2_alarm.dev_attr.attr,
259 &sensor_dev_attr_temp2_fault.dev_attr.attr,
Krzysztof Heltadd77c62007-07-08 22:43:00 +0200260 &sensor_dev_attr_pwm1.dev_attr.attr,
261 &sensor_dev_attr_pwm1_mode.dev_attr.attr,
262 NULL
263};
264
265static const struct attribute_group thmc50_group = {
266 .attrs = thmc50_attributes,
267};
268
269/* for ADM1022 3rd temperature mode */
Jean Delvare894c00c2007-09-18 18:44:42 +0200270static struct attribute *temp3_attributes[] = {
Krzysztof Heltadd77c62007-07-08 22:43:00 +0200271 &sensor_dev_attr_temp3_max.dev_attr.attr,
272 &sensor_dev_attr_temp3_min.dev_attr.attr,
273 &sensor_dev_attr_temp3_input.dev_attr.attr,
Krzysztof Helt84f768c2008-08-06 22:41:05 +0200274 &sensor_dev_attr_temp3_crit.dev_attr.attr,
Krzysztof Heltdcf3b5f2007-08-22 14:05:22 -0400275 &sensor_dev_attr_temp3_alarm.dev_attr.attr,
276 &sensor_dev_attr_temp3_fault.dev_attr.attr,
Krzysztof Heltadd77c62007-07-08 22:43:00 +0200277 NULL
278};
279
Jean Delvare894c00c2007-09-18 18:44:42 +0200280static const struct attribute_group temp3_group = {
281 .attrs = temp3_attributes,
Krzysztof Heltadd77c62007-07-08 22:43:00 +0200282};
283
Jean Delvareccf37482008-07-16 19:30:16 +0200284/* Return 0 if detection is successful, -ENODEV otherwise */
285static int thmc50_detect(struct i2c_client *client, int kind,
286 struct i2c_board_info *info)
Krzysztof Heltadd77c62007-07-08 22:43:00 +0200287{
288 unsigned company;
289 unsigned revision;
290 unsigned config;
Jean Delvareccf37482008-07-16 19:30:16 +0200291 struct i2c_adapter *adapter = client->adapter;
Krzysztof Heltadd77c62007-07-08 22:43:00 +0200292 int err = 0;
Jean Delvarecc28a612007-09-18 18:48:16 +0200293 const char *type_name;
Krzysztof Heltadd77c62007-07-08 22:43:00 +0200294
295 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) {
296 pr_debug("thmc50: detect failed, "
297 "smbus byte data not supported!\n");
Jean Delvareccf37482008-07-16 19:30:16 +0200298 return -ENODEV;
Krzysztof Heltadd77c62007-07-08 22:43:00 +0200299 }
300
Krzysztof Heltadd77c62007-07-08 22:43:00 +0200301 pr_debug("thmc50: Probing for THMC50 at 0x%2X on bus %d\n",
302 client->addr, i2c_adapter_id(client->adapter));
303
304 /* Now, we do the remaining detection. */
305 company = i2c_smbus_read_byte_data(client, THMC50_REG_COMPANY_ID);
306 revision = i2c_smbus_read_byte_data(client, THMC50_REG_DIE_CODE);
307 config = i2c_smbus_read_byte_data(client, THMC50_REG_CONF);
308
309 if (kind == 0)
310 kind = thmc50;
311 else if (kind < 0) {
312 err = -ENODEV;
313 if (revision >= 0xc0 && ((config & 0x10) == 0)) {
314 if (company == 0x49) {
315 kind = thmc50;
316 err = 0;
317 } else if (company == 0x41) {
318 kind = adm1022;
319 err = 0;
320 }
321 }
322 }
323 if (err == -ENODEV) {
324 pr_debug("thmc50: Detection of THMC50/ADM1022 failed\n");
Jean Delvareccf37482008-07-16 19:30:16 +0200325 return err;
Krzysztof Heltadd77c62007-07-08 22:43:00 +0200326 }
Krzysztof Heltadd77c62007-07-08 22:43:00 +0200327
Jean Delvarecc28a612007-09-18 18:48:16 +0200328 if (kind == adm1022) {
Krzysztof Heltadd77c62007-07-08 22:43:00 +0200329 int id = i2c_adapter_id(client->adapter);
330 int i;
331
332 type_name = "adm1022";
Krzysztof Heltadd77c62007-07-08 22:43:00 +0200333 for (i = 0; i + 1 < adm1022_temp3_num; i += 2)
334 if (adm1022_temp3[i] == id &&
Jean Delvareccf37482008-07-16 19:30:16 +0200335 adm1022_temp3[i + 1] == client->addr) {
Krzysztof Heltadd77c62007-07-08 22:43:00 +0200336 /* enable 2nd remote temp */
Jean Delvareccf37482008-07-16 19:30:16 +0200337 config |= (1 << 7);
338 i2c_smbus_write_byte_data(client,
339 THMC50_REG_CONF,
340 config);
Krzysztof Heltadd77c62007-07-08 22:43:00 +0200341 break;
342 }
Jean Delvarecc28a612007-09-18 18:48:16 +0200343 } else {
344 type_name = "thmc50";
Krzysztof Heltadd77c62007-07-08 22:43:00 +0200345 }
Jean Delvarecc28a612007-09-18 18:48:16 +0200346 pr_debug("thmc50: Detected %s (version %x, revision %x)\n",
347 type_name, (revision >> 4) - 0xc, revision & 0xf);
Krzysztof Heltadd77c62007-07-08 22:43:00 +0200348
Jean Delvareccf37482008-07-16 19:30:16 +0200349 strlcpy(info->type, type_name, I2C_NAME_SIZE);
Krzysztof Heltadd77c62007-07-08 22:43:00 +0200350
Jean Delvareccf37482008-07-16 19:30:16 +0200351 return 0;
352}
353
354static int thmc50_probe(struct i2c_client *client,
355 const struct i2c_device_id *id)
356{
357 struct thmc50_data *data;
358 int err;
359
360 data = kzalloc(sizeof(struct thmc50_data), GFP_KERNEL);
361 if (!data) {
362 pr_debug("thmc50: detect failed, kzalloc failed!\n");
363 err = -ENOMEM;
364 goto exit;
365 }
366
367 i2c_set_clientdata(client, data);
368 data->type = id->driver_data;
369 mutex_init(&data->update_lock);
Krzysztof Heltadd77c62007-07-08 22:43:00 +0200370
371 thmc50_init_client(client);
372
373 /* Register sysfs hooks */
374 if ((err = sysfs_create_group(&client->dev.kobj, &thmc50_group)))
Jean Delvareccf37482008-07-16 19:30:16 +0200375 goto exit_free;
Krzysztof Heltadd77c62007-07-08 22:43:00 +0200376
377 /* Register ADM1022 sysfs hooks */
Jean Delvare894c00c2007-09-18 18:44:42 +0200378 if (data->has_temp3)
Krzysztof Heltadd77c62007-07-08 22:43:00 +0200379 if ((err = sysfs_create_group(&client->dev.kobj,
Jean Delvare894c00c2007-09-18 18:44:42 +0200380 &temp3_group)))
Krzysztof Heltadd77c62007-07-08 22:43:00 +0200381 goto exit_remove_sysfs_thmc50;
382
383 /* Register a new directory entry with module sensors */
Tony Jones1beeffe2007-08-20 13:46:20 -0700384 data->hwmon_dev = hwmon_device_register(&client->dev);
385 if (IS_ERR(data->hwmon_dev)) {
386 err = PTR_ERR(data->hwmon_dev);
Krzysztof Heltadd77c62007-07-08 22:43:00 +0200387 goto exit_remove_sysfs;
388 }
389
390 return 0;
391
392exit_remove_sysfs:
Jean Delvare894c00c2007-09-18 18:44:42 +0200393 if (data->has_temp3)
394 sysfs_remove_group(&client->dev.kobj, &temp3_group);
Krzysztof Heltadd77c62007-07-08 22:43:00 +0200395exit_remove_sysfs_thmc50:
396 sysfs_remove_group(&client->dev.kobj, &thmc50_group);
Krzysztof Heltadd77c62007-07-08 22:43:00 +0200397exit_free:
398 kfree(data);
399exit:
400 return err;
401}
402
Jean Delvareccf37482008-07-16 19:30:16 +0200403static int thmc50_remove(struct i2c_client *client)
Krzysztof Heltadd77c62007-07-08 22:43:00 +0200404{
405 struct thmc50_data *data = i2c_get_clientdata(client);
Krzysztof Heltadd77c62007-07-08 22:43:00 +0200406
Tony Jones1beeffe2007-08-20 13:46:20 -0700407 hwmon_device_unregister(data->hwmon_dev);
Krzysztof Heltadd77c62007-07-08 22:43:00 +0200408 sysfs_remove_group(&client->dev.kobj, &thmc50_group);
Jean Delvare894c00c2007-09-18 18:44:42 +0200409 if (data->has_temp3)
410 sysfs_remove_group(&client->dev.kobj, &temp3_group);
Krzysztof Heltadd77c62007-07-08 22:43:00 +0200411
Krzysztof Heltadd77c62007-07-08 22:43:00 +0200412 kfree(data);
413
414 return 0;
415}
416
417static void thmc50_init_client(struct i2c_client *client)
418{
419 struct thmc50_data *data = i2c_get_clientdata(client);
420 int config;
421
422 data->analog_out = i2c_smbus_read_byte_data(client,
423 THMC50_REG_ANALOG_OUT);
424 /* set up to at least 1 */
425 if (data->analog_out == 0) {
426 data->analog_out = 1;
427 i2c_smbus_write_byte_data(client, THMC50_REG_ANALOG_OUT,
428 data->analog_out);
429 }
430 config = i2c_smbus_read_byte_data(client, THMC50_REG_CONF);
431 config |= 0x1; /* start the chip if it is in standby mode */
Jean Delvareccf37482008-07-16 19:30:16 +0200432 if (data->type == adm1022 && (config & (1 << 7)))
433 data->has_temp3 = 1;
Krzysztof Heltadd77c62007-07-08 22:43:00 +0200434 i2c_smbus_write_byte_data(client, THMC50_REG_CONF, config);
435}
436
437static struct thmc50_data *thmc50_update_device(struct device *dev)
438{
439 struct i2c_client *client = to_i2c_client(dev);
440 struct thmc50_data *data = i2c_get_clientdata(client);
441 int timeout = HZ / 5 + (data->type == thmc50 ? HZ : 0);
442
443 mutex_lock(&data->update_lock);
444
445 if (time_after(jiffies, data->last_updated + timeout)
446 || !data->valid) {
447
448 int temps = data->has_temp3 ? 3 : 2;
449 int i;
Krzysztof Helt84f768c2008-08-06 22:41:05 +0200450 int prog = i2c_smbus_read_byte_data(client, THMC50_REG_CONF);
451
452 prog &= THMC50_REG_CONF_PROGRAMMED;
453
Krzysztof Heltadd77c62007-07-08 22:43:00 +0200454 for (i = 0; i < temps; i++) {
455 data->temp_input[i] = i2c_smbus_read_byte_data(client,
456 THMC50_REG_TEMP[i]);
457 data->temp_max[i] = i2c_smbus_read_byte_data(client,
458 THMC50_REG_TEMP_MAX[i]);
459 data->temp_min[i] = i2c_smbus_read_byte_data(client,
460 THMC50_REG_TEMP_MIN[i]);
Krzysztof Helt84f768c2008-08-06 22:41:05 +0200461 data->temp_critical[i] =
462 i2c_smbus_read_byte_data(client,
463 prog ? THMC50_REG_TEMP_CRITICAL[i]
464 : THMC50_REG_TEMP_DEFAULT[i]);
Krzysztof Heltadd77c62007-07-08 22:43:00 +0200465 }
466 data->analog_out =
467 i2c_smbus_read_byte_data(client, THMC50_REG_ANALOG_OUT);
Krzysztof Heltdcf3b5f2007-08-22 14:05:22 -0400468 data->alarms =
Krzysztof Heltbba891c2007-09-09 17:35:34 +0200469 i2c_smbus_read_byte_data(client, THMC50_REG_INTR);
Krzysztof Heltadd77c62007-07-08 22:43:00 +0200470 data->last_updated = jiffies;
471 data->valid = 1;
472 }
473
474 mutex_unlock(&data->update_lock);
475
476 return data;
477}
478
479static int __init sm_thmc50_init(void)
480{
481 return i2c_add_driver(&thmc50_driver);
482}
483
484static void __exit sm_thmc50_exit(void)
485{
486 i2c_del_driver(&thmc50_driver);
487}
488
489MODULE_AUTHOR("Krzysztof Helt <krzysztof.h1@wp.pl>");
490MODULE_DESCRIPTION("THMC50 driver");
491
492module_init(sm_thmc50_init);
493module_exit(sm_thmc50_exit);