]> git.karo-electronics.de Git - karo-tx-linux.git/blob - drivers/hwmon/tmp401.c
hwmon: (tmp401) Use constants for sysfs file permissions
[karo-tx-linux.git] / drivers / hwmon / tmp401.c
1 /* tmp401.c
2  *
3  * Copyright (C) 2007,2008 Hans de Goede <hdegoede@redhat.com>
4  * Preliminary tmp411 support by:
5  * Gabriel Konat, Sander Leget, Wouter Willems
6  * Copyright (C) 2009 Andre Prendel <andre.prendel@gmx.de>
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 /*
24  * Driver for the Texas Instruments TMP401 SMBUS temperature sensor IC.
25  *
26  * Note this IC is in some aspect similar to the LM90, but it has quite a
27  * few differences too, for example the local temp has a higher resolution
28  * and thus has 16 bits registers for its value and limit instead of 8 bits.
29  */
30
31 #include <linux/module.h>
32 #include <linux/init.h>
33 #include <linux/slab.h>
34 #include <linux/jiffies.h>
35 #include <linux/i2c.h>
36 #include <linux/hwmon.h>
37 #include <linux/hwmon-sysfs.h>
38 #include <linux/err.h>
39 #include <linux/mutex.h>
40 #include <linux/sysfs.h>
41
42 /* Addresses to scan */
43 static const unsigned short normal_i2c[] = { 0x4c, I2C_CLIENT_END };
44
45 enum chips { tmp401, tmp411 };
46
47 /*
48  * The TMP401 registers, note some registers have different addresses for
49  * reading and writing
50  */
51 #define TMP401_STATUS                           0x02
52 #define TMP401_CONFIG_READ                      0x03
53 #define TMP401_CONFIG_WRITE                     0x09
54 #define TMP401_CONVERSION_RATE_READ             0x04
55 #define TMP401_CONVERSION_RATE_WRITE            0x0A
56 #define TMP401_TEMP_CRIT_HYST                   0x21
57 #define TMP401_CONSECUTIVE_ALERT                0x22
58 #define TMP401_MANUFACTURER_ID_REG              0xFE
59 #define TMP401_DEVICE_ID_REG                    0xFF
60 #define TMP411_N_FACTOR_REG                     0x18
61
62 static const u8 TMP401_TEMP_MSB[2]                      = { 0x00, 0x01 };
63 static const u8 TMP401_TEMP_LSB[2]                      = { 0x15, 0x10 };
64 static const u8 TMP401_TEMP_LOW_LIMIT_MSB_READ[2]       = { 0x06, 0x08 };
65 static const u8 TMP401_TEMP_LOW_LIMIT_MSB_WRITE[2]      = { 0x0C, 0x0E };
66 static const u8 TMP401_TEMP_LOW_LIMIT_LSB[2]            = { 0x17, 0x14 };
67 static const u8 TMP401_TEMP_HIGH_LIMIT_MSB_READ[2]      = { 0x05, 0x07 };
68 static const u8 TMP401_TEMP_HIGH_LIMIT_MSB_WRITE[2]     = { 0x0B, 0x0D };
69 static const u8 TMP401_TEMP_HIGH_LIMIT_LSB[2]           = { 0x16, 0x13 };
70 /* These are called the THERM limit / hysteresis / mask in the datasheet */
71 static const u8 TMP401_TEMP_CRIT_LIMIT[2]               = { 0x20, 0x19 };
72
73 static const u8 TMP411_TEMP_LOWEST_MSB[2]               = { 0x30, 0x34 };
74 static const u8 TMP411_TEMP_LOWEST_LSB[2]               = { 0x31, 0x35 };
75 static const u8 TMP411_TEMP_HIGHEST_MSB[2]              = { 0x32, 0x36 };
76 static const u8 TMP411_TEMP_HIGHEST_LSB[2]              = { 0x33, 0x37 };
77
78 /* Flags */
79 #define TMP401_CONFIG_RANGE             0x04
80 #define TMP401_CONFIG_SHUTDOWN          0x40
81 #define TMP401_STATUS_LOCAL_CRIT                0x01
82 #define TMP401_STATUS_REMOTE_CRIT               0x02
83 #define TMP401_STATUS_REMOTE_OPEN               0x04
84 #define TMP401_STATUS_REMOTE_LOW                0x08
85 #define TMP401_STATUS_REMOTE_HIGH               0x10
86 #define TMP401_STATUS_LOCAL_LOW         0x20
87 #define TMP401_STATUS_LOCAL_HIGH                0x40
88
89 /* Manufacturer / Device ID's */
90 #define TMP401_MANUFACTURER_ID                  0x55
91 #define TMP401_DEVICE_ID                        0x11
92 #define TMP411_DEVICE_ID                        0x12
93
94 /*
95  * Functions declarations
96  */
97
98 static int tmp401_probe(struct i2c_client *client,
99                         const struct i2c_device_id *id);
100 static int tmp401_detect(struct i2c_client *client,
101                          struct i2c_board_info *info);
102 static int tmp401_remove(struct i2c_client *client);
103 static struct tmp401_data *tmp401_update_device(struct device *dev);
104
105 /*
106  * Driver data (common to all clients)
107  */
108
109 static const struct i2c_device_id tmp401_id[] = {
110         { "tmp401", tmp401 },
111         { "tmp411", tmp411 },
112         { }
113 };
114 MODULE_DEVICE_TABLE(i2c, tmp401_id);
115
116 static struct i2c_driver tmp401_driver = {
117         .class          = I2C_CLASS_HWMON,
118         .driver = {
119                 .name   = "tmp401",
120         },
121         .probe          = tmp401_probe,
122         .remove         = tmp401_remove,
123         .id_table       = tmp401_id,
124         .detect         = tmp401_detect,
125         .address_list   = normal_i2c,
126 };
127
128 /*
129  * Client data (each client gets its own)
130  */
131
132 struct tmp401_data {
133         struct device *hwmon_dev;
134         struct mutex update_lock;
135         char valid; /* zero until following fields are valid */
136         unsigned long last_updated; /* in jiffies */
137         enum chips kind;
138
139         /* register values */
140         u8 status;
141         u8 config;
142         u16 temp[2];
143         u16 temp_low[2];
144         u16 temp_high[2];
145         u8 temp_crit[2];
146         u8 temp_crit_hyst;
147         u16 temp_lowest[2];
148         u16 temp_highest[2];
149 };
150
151 /*
152  * Sysfs attr show / store functions
153  */
154
155 static int tmp401_register_to_temp(u16 reg, u8 config)
156 {
157         int temp = reg;
158
159         if (config & TMP401_CONFIG_RANGE)
160                 temp -= 64 * 256;
161
162         return (temp * 625 + 80) / 160;
163 }
164
165 static u16 tmp401_temp_to_register(long temp, u8 config)
166 {
167         if (config & TMP401_CONFIG_RANGE) {
168                 temp = SENSORS_LIMIT(temp, -64000, 191000);
169                 temp += 64000;
170         } else
171                 temp = SENSORS_LIMIT(temp, 0, 127000);
172
173         return (temp * 160 + 312) / 625;
174 }
175
176 static int tmp401_crit_register_to_temp(u8 reg, u8 config)
177 {
178         int temp = reg;
179
180         if (config & TMP401_CONFIG_RANGE)
181                 temp -= 64;
182
183         return temp * 1000;
184 }
185
186 static u8 tmp401_crit_temp_to_register(long temp, u8 config)
187 {
188         if (config & TMP401_CONFIG_RANGE) {
189                 temp = SENSORS_LIMIT(temp, -64000, 191000);
190                 temp += 64000;
191         } else
192                 temp = SENSORS_LIMIT(temp, 0, 127000);
193
194         return (temp + 500) / 1000;
195 }
196
197 static ssize_t show_temp_value(struct device *dev,
198         struct device_attribute *devattr, char *buf)
199 {
200         int index = to_sensor_dev_attr(devattr)->index;
201         struct tmp401_data *data = tmp401_update_device(dev);
202
203         return sprintf(buf, "%d\n",
204                 tmp401_register_to_temp(data->temp[index], data->config));
205 }
206
207 static ssize_t show_temp_min(struct device *dev,
208         struct device_attribute *devattr, char *buf)
209 {
210         int index = to_sensor_dev_attr(devattr)->index;
211         struct tmp401_data *data = tmp401_update_device(dev);
212
213         return sprintf(buf, "%d\n",
214                 tmp401_register_to_temp(data->temp_low[index], data->config));
215 }
216
217 static ssize_t show_temp_max(struct device *dev,
218         struct device_attribute *devattr, char *buf)
219 {
220         int index = to_sensor_dev_attr(devattr)->index;
221         struct tmp401_data *data = tmp401_update_device(dev);
222
223         return sprintf(buf, "%d\n",
224                 tmp401_register_to_temp(data->temp_high[index], data->config));
225 }
226
227 static ssize_t show_temp_crit(struct device *dev,
228         struct device_attribute *devattr, char *buf)
229 {
230         int index = to_sensor_dev_attr(devattr)->index;
231         struct tmp401_data *data = tmp401_update_device(dev);
232
233         return sprintf(buf, "%d\n",
234                         tmp401_crit_register_to_temp(data->temp_crit[index],
235                                                         data->config));
236 }
237
238 static ssize_t show_temp_crit_hyst(struct device *dev,
239         struct device_attribute *devattr, char *buf)
240 {
241         int temp, index = to_sensor_dev_attr(devattr)->index;
242         struct tmp401_data *data = tmp401_update_device(dev);
243
244         mutex_lock(&data->update_lock);
245         temp = tmp401_crit_register_to_temp(data->temp_crit[index],
246                                                 data->config);
247         temp -= data->temp_crit_hyst * 1000;
248         mutex_unlock(&data->update_lock);
249
250         return sprintf(buf, "%d\n", temp);
251 }
252
253 static ssize_t show_temp_lowest(struct device *dev,
254         struct device_attribute *devattr, char *buf)
255 {
256         int index = to_sensor_dev_attr(devattr)->index;
257         struct tmp401_data *data = tmp401_update_device(dev);
258
259         return sprintf(buf, "%d\n",
260                 tmp401_register_to_temp(data->temp_lowest[index],
261                                         data->config));
262 }
263
264 static ssize_t show_temp_highest(struct device *dev,
265         struct device_attribute *devattr, char *buf)
266 {
267         int index = to_sensor_dev_attr(devattr)->index;
268         struct tmp401_data *data = tmp401_update_device(dev);
269
270         return sprintf(buf, "%d\n",
271                 tmp401_register_to_temp(data->temp_highest[index],
272                                         data->config));
273 }
274
275 static ssize_t show_status(struct device *dev,
276         struct device_attribute *devattr, char *buf)
277 {
278         int mask = to_sensor_dev_attr(devattr)->index;
279         struct tmp401_data *data = tmp401_update_device(dev);
280
281         if (data->status & mask)
282                 return sprintf(buf, "1\n");
283         else
284                 return sprintf(buf, "0\n");
285 }
286
287 static ssize_t store_temp_min(struct device *dev, struct device_attribute
288         *devattr, const char *buf, size_t count)
289 {
290         int index = to_sensor_dev_attr(devattr)->index;
291         struct tmp401_data *data = tmp401_update_device(dev);
292         long val;
293         u16 reg;
294
295         if (strict_strtol(buf, 10, &val))
296                 return -EINVAL;
297
298         reg = tmp401_temp_to_register(val, data->config);
299
300         mutex_lock(&data->update_lock);
301
302         i2c_smbus_write_byte_data(to_i2c_client(dev),
303                 TMP401_TEMP_LOW_LIMIT_MSB_WRITE[index], reg >> 8);
304         i2c_smbus_write_byte_data(to_i2c_client(dev),
305                 TMP401_TEMP_LOW_LIMIT_LSB[index], reg & 0xFF);
306
307         data->temp_low[index] = reg;
308
309         mutex_unlock(&data->update_lock);
310
311         return count;
312 }
313
314 static ssize_t store_temp_max(struct device *dev, struct device_attribute
315         *devattr, const char *buf, size_t count)
316 {
317         int index = to_sensor_dev_attr(devattr)->index;
318         struct tmp401_data *data = tmp401_update_device(dev);
319         long val;
320         u16 reg;
321
322         if (strict_strtol(buf, 10, &val))
323                 return -EINVAL;
324
325         reg = tmp401_temp_to_register(val, data->config);
326
327         mutex_lock(&data->update_lock);
328
329         i2c_smbus_write_byte_data(to_i2c_client(dev),
330                 TMP401_TEMP_HIGH_LIMIT_MSB_WRITE[index], reg >> 8);
331         i2c_smbus_write_byte_data(to_i2c_client(dev),
332                 TMP401_TEMP_HIGH_LIMIT_LSB[index], reg & 0xFF);
333
334         data->temp_high[index] = reg;
335
336         mutex_unlock(&data->update_lock);
337
338         return count;
339 }
340
341 static ssize_t store_temp_crit(struct device *dev, struct device_attribute
342         *devattr, const char *buf, size_t count)
343 {
344         int index = to_sensor_dev_attr(devattr)->index;
345         struct tmp401_data *data = tmp401_update_device(dev);
346         long val;
347         u8 reg;
348
349         if (strict_strtol(buf, 10, &val))
350                 return -EINVAL;
351
352         reg = tmp401_crit_temp_to_register(val, data->config);
353
354         mutex_lock(&data->update_lock);
355
356         i2c_smbus_write_byte_data(to_i2c_client(dev),
357                 TMP401_TEMP_CRIT_LIMIT[index], reg);
358
359         data->temp_crit[index] = reg;
360
361         mutex_unlock(&data->update_lock);
362
363         return count;
364 }
365
366 static ssize_t store_temp_crit_hyst(struct device *dev, struct device_attribute
367         *devattr, const char *buf, size_t count)
368 {
369         int temp, index = to_sensor_dev_attr(devattr)->index;
370         struct tmp401_data *data = tmp401_update_device(dev);
371         long val;
372         u8 reg;
373
374         if (strict_strtol(buf, 10, &val))
375                 return -EINVAL;
376
377         if (data->config & TMP401_CONFIG_RANGE)
378                 val = SENSORS_LIMIT(val, -64000, 191000);
379         else
380                 val = SENSORS_LIMIT(val, 0, 127000);
381
382         mutex_lock(&data->update_lock);
383         temp = tmp401_crit_register_to_temp(data->temp_crit[index],
384                                                 data->config);
385         val = SENSORS_LIMIT(val, temp - 255000, temp);
386         reg = ((temp - val) + 500) / 1000;
387
388         i2c_smbus_write_byte_data(to_i2c_client(dev),
389                 TMP401_TEMP_CRIT_HYST, reg);
390
391         data->temp_crit_hyst = reg;
392
393         mutex_unlock(&data->update_lock);
394
395         return count;
396 }
397
398 /*
399  * Resets the historical measurements of minimum and maximum temperatures.
400  * This is done by writing any value to any of the minimum/maximum registers
401  * (0x30-0x37).
402  */
403 static ssize_t reset_temp_history(struct device *dev,
404         struct device_attribute *devattr, const char *buf, size_t count)
405 {
406         long val;
407
408         if (strict_strtol(buf, 10, &val))
409                 return -EINVAL;
410
411         if (val != 1) {
412                 dev_err(dev, "temp_reset_history value %ld not"
413                         " supported. Use 1 to reset the history!\n", val);
414                 return -EINVAL;
415         }
416         i2c_smbus_write_byte_data(to_i2c_client(dev),
417                 TMP411_TEMP_LOWEST_MSB[0], val);
418
419         return count;
420 }
421
422 static struct sensor_device_attribute tmp401_attr[] = {
423         SENSOR_ATTR(temp1_input, S_IRUGO, show_temp_value, NULL, 0),
424         SENSOR_ATTR(temp1_min, S_IWUSR | S_IRUGO, show_temp_min,
425                     store_temp_min, 0),
426         SENSOR_ATTR(temp1_max, S_IWUSR | S_IRUGO, show_temp_max,
427                     store_temp_max, 0),
428         SENSOR_ATTR(temp1_crit, S_IWUSR | S_IRUGO, show_temp_crit,
429                     store_temp_crit, 0),
430         SENSOR_ATTR(temp1_crit_hyst, S_IWUSR | S_IRUGO, show_temp_crit_hyst,
431                     store_temp_crit_hyst, 0),
432         SENSOR_ATTR(temp1_min_alarm, S_IRUGO, show_status, NULL,
433                     TMP401_STATUS_LOCAL_LOW),
434         SENSOR_ATTR(temp1_max_alarm, S_IRUGO, show_status, NULL,
435                     TMP401_STATUS_LOCAL_HIGH),
436         SENSOR_ATTR(temp1_crit_alarm, S_IRUGO, show_status, NULL,
437                     TMP401_STATUS_LOCAL_CRIT),
438         SENSOR_ATTR(temp2_input, S_IRUGO, show_temp_value, NULL, 1),
439         SENSOR_ATTR(temp2_min, S_IWUSR | S_IRUGO, show_temp_min,
440                     store_temp_min, 1),
441         SENSOR_ATTR(temp2_max, S_IWUSR | S_IRUGO, show_temp_max,
442                     store_temp_max, 1),
443         SENSOR_ATTR(temp2_crit, S_IWUSR | S_IRUGO, show_temp_crit,
444                     store_temp_crit, 1),
445         SENSOR_ATTR(temp2_crit_hyst, S_IRUGO, show_temp_crit_hyst, NULL, 1),
446         SENSOR_ATTR(temp2_fault, S_IRUGO, show_status, NULL,
447                     TMP401_STATUS_REMOTE_OPEN),
448         SENSOR_ATTR(temp2_min_alarm, S_IRUGO, show_status, NULL,
449                     TMP401_STATUS_REMOTE_LOW),
450         SENSOR_ATTR(temp2_max_alarm, S_IRUGO, show_status, NULL,
451                     TMP401_STATUS_REMOTE_HIGH),
452         SENSOR_ATTR(temp2_crit_alarm, S_IRUGO, show_status, NULL,
453                     TMP401_STATUS_REMOTE_CRIT),
454 };
455
456 /*
457  * Additional features of the TMP411 chip.
458  * The TMP411 stores the minimum and maximum
459  * temperature measured since power-on, chip-reset, or
460  * minimum and maximum register reset for both the local
461  * and remote channels.
462  */
463 static struct sensor_device_attribute tmp411_attr[] = {
464         SENSOR_ATTR(temp1_highest, S_IRUGO, show_temp_highest, NULL, 0),
465         SENSOR_ATTR(temp1_lowest, S_IRUGO, show_temp_lowest, NULL, 0),
466         SENSOR_ATTR(temp2_highest, S_IRUGO, show_temp_highest, NULL, 1),
467         SENSOR_ATTR(temp2_lowest, S_IRUGO, show_temp_lowest, NULL, 1),
468         SENSOR_ATTR(temp_reset_history, S_IWUSR, NULL, reset_temp_history, 0),
469 };
470
471 /*
472  * Begin non sysfs callback code (aka Real code)
473  */
474
475 static void tmp401_init_client(struct i2c_client *client)
476 {
477         int config, config_orig;
478
479         /* Set the conversion rate to 2 Hz */
480         i2c_smbus_write_byte_data(client, TMP401_CONVERSION_RATE_WRITE, 5);
481
482         /* Start conversions (disable shutdown if necessary) */
483         config = i2c_smbus_read_byte_data(client, TMP401_CONFIG_READ);
484         if (config < 0) {
485                 dev_warn(&client->dev, "Initialization failed!\n");
486                 return;
487         }
488
489         config_orig = config;
490         config &= ~TMP401_CONFIG_SHUTDOWN;
491
492         if (config != config_orig)
493                 i2c_smbus_write_byte_data(client, TMP401_CONFIG_WRITE, config);
494 }
495
496 static int tmp401_detect(struct i2c_client *client,
497                          struct i2c_board_info *info)
498 {
499         enum chips kind;
500         struct i2c_adapter *adapter = client->adapter;
501         u8 reg;
502
503         if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA))
504                 return -ENODEV;
505
506         /* Detect and identify the chip */
507         reg = i2c_smbus_read_byte_data(client, TMP401_MANUFACTURER_ID_REG);
508         if (reg != TMP401_MANUFACTURER_ID)
509                 return -ENODEV;
510
511         reg = i2c_smbus_read_byte_data(client, TMP401_DEVICE_ID_REG);
512
513         switch (reg) {
514         case TMP401_DEVICE_ID:
515                 kind = tmp401;
516                 break;
517         case TMP411_DEVICE_ID:
518                 kind = tmp411;
519                 break;
520         default:
521                 return -ENODEV;
522         }
523
524         reg = i2c_smbus_read_byte_data(client, TMP401_CONFIG_READ);
525         if (reg & 0x1b)
526                 return -ENODEV;
527
528         reg = i2c_smbus_read_byte_data(client, TMP401_CONVERSION_RATE_READ);
529         /* Datasheet says: 0x1-0x6 */
530         if (reg > 15)
531                 return -ENODEV;
532
533         strlcpy(info->type, tmp401_id[kind].name, I2C_NAME_SIZE);
534
535         return 0;
536 }
537
538 static int tmp401_probe(struct i2c_client *client,
539                         const struct i2c_device_id *id)
540 {
541         int i, err = 0;
542         struct tmp401_data *data;
543         const char *names[] = { "TMP401", "TMP411" };
544
545         data = kzalloc(sizeof(struct tmp401_data), GFP_KERNEL);
546         if (!data)
547                 return -ENOMEM;
548
549         i2c_set_clientdata(client, data);
550         mutex_init(&data->update_lock);
551         data->kind = id->driver_data;
552
553         /* Initialize the TMP401 chip */
554         tmp401_init_client(client);
555
556         /* Register sysfs hooks */
557         for (i = 0; i < ARRAY_SIZE(tmp401_attr); i++) {
558                 err = device_create_file(&client->dev,
559                                          &tmp401_attr[i].dev_attr);
560                 if (err)
561                         goto exit_remove;
562         }
563
564         /* Register aditional tmp411 sysfs hooks */
565         if (data->kind == tmp411) {
566                 for (i = 0; i < ARRAY_SIZE(tmp411_attr); i++) {
567                         err = device_create_file(&client->dev,
568                                                  &tmp411_attr[i].dev_attr);
569                         if (err)
570                                 goto exit_remove;
571                 }
572         }
573
574         data->hwmon_dev = hwmon_device_register(&client->dev);
575         if (IS_ERR(data->hwmon_dev)) {
576                 err = PTR_ERR(data->hwmon_dev);
577                 data->hwmon_dev = NULL;
578                 goto exit_remove;
579         }
580
581         dev_info(&client->dev, "Detected TI %s chip\n", names[data->kind]);
582
583         return 0;
584
585 exit_remove:
586         tmp401_remove(client); /* will also free data for us */
587         return err;
588 }
589
590 static int tmp401_remove(struct i2c_client *client)
591 {
592         struct tmp401_data *data = i2c_get_clientdata(client);
593         int i;
594
595         if (data->hwmon_dev)
596                 hwmon_device_unregister(data->hwmon_dev);
597
598         for (i = 0; i < ARRAY_SIZE(tmp401_attr); i++)
599                 device_remove_file(&client->dev, &tmp401_attr[i].dev_attr);
600
601         if (data->kind == tmp411) {
602                 for (i = 0; i < ARRAY_SIZE(tmp411_attr); i++)
603                         device_remove_file(&client->dev,
604                                            &tmp411_attr[i].dev_attr);
605         }
606
607         kfree(data);
608         return 0;
609 }
610
611 static struct tmp401_data *tmp401_update_device_reg16(
612         struct i2c_client *client, struct tmp401_data *data)
613 {
614         int i;
615
616         for (i = 0; i < 2; i++) {
617                 /*
618                  * High byte must be read first immediately followed
619                  * by the low byte
620                  */
621                 data->temp[i] = i2c_smbus_read_byte_data(client,
622                         TMP401_TEMP_MSB[i]) << 8;
623                 data->temp[i] |= i2c_smbus_read_byte_data(client,
624                         TMP401_TEMP_LSB[i]);
625                 data->temp_low[i] = i2c_smbus_read_byte_data(client,
626                         TMP401_TEMP_LOW_LIMIT_MSB_READ[i]) << 8;
627                 data->temp_low[i] |= i2c_smbus_read_byte_data(client,
628                         TMP401_TEMP_LOW_LIMIT_LSB[i]);
629                 data->temp_high[i] = i2c_smbus_read_byte_data(client,
630                         TMP401_TEMP_HIGH_LIMIT_MSB_READ[i]) << 8;
631                 data->temp_high[i] |= i2c_smbus_read_byte_data(client,
632                         TMP401_TEMP_HIGH_LIMIT_LSB[i]);
633                 data->temp_crit[i] = i2c_smbus_read_byte_data(client,
634                         TMP401_TEMP_CRIT_LIMIT[i]);
635
636                 if (data->kind == tmp411) {
637                         data->temp_lowest[i] = i2c_smbus_read_byte_data(client,
638                                 TMP411_TEMP_LOWEST_MSB[i]) << 8;
639                         data->temp_lowest[i] |= i2c_smbus_read_byte_data(
640                                 client, TMP411_TEMP_LOWEST_LSB[i]);
641
642                         data->temp_highest[i] = i2c_smbus_read_byte_data(
643                                 client, TMP411_TEMP_HIGHEST_MSB[i]) << 8;
644                         data->temp_highest[i] |= i2c_smbus_read_byte_data(
645                                 client, TMP411_TEMP_HIGHEST_LSB[i]);
646                 }
647         }
648         return data;
649 }
650
651 static struct tmp401_data *tmp401_update_device(struct device *dev)
652 {
653         struct i2c_client *client = to_i2c_client(dev);
654         struct tmp401_data *data = i2c_get_clientdata(client);
655
656         mutex_lock(&data->update_lock);
657
658         if (time_after(jiffies, data->last_updated + HZ) || !data->valid) {
659                 data->status = i2c_smbus_read_byte_data(client, TMP401_STATUS);
660                 data->config = i2c_smbus_read_byte_data(client,
661                                                 TMP401_CONFIG_READ);
662                 tmp401_update_device_reg16(client, data);
663
664                 data->temp_crit_hyst = i2c_smbus_read_byte_data(client,
665                                                 TMP401_TEMP_CRIT_HYST);
666
667                 data->last_updated = jiffies;
668                 data->valid = 1;
669         }
670
671         mutex_unlock(&data->update_lock);
672
673         return data;
674 }
675
676 static int __init tmp401_init(void)
677 {
678         return i2c_add_driver(&tmp401_driver);
679 }
680
681 static void __exit tmp401_exit(void)
682 {
683         i2c_del_driver(&tmp401_driver);
684 }
685
686 MODULE_AUTHOR("Hans de Goede <hdegoede@redhat.com>");
687 MODULE_DESCRIPTION("Texas Instruments TMP401 temperature sensor driver");
688 MODULE_LICENSE("GPL");
689
690 module_init(tmp401_init);
691 module_exit(tmp401_exit);