hc
2024-02-19 1c055e55a242a33e574e48be530e06770a210dcd
kernel/drivers/hwmon/lm90.c
....@@ -1,3 +1,4 @@
1
+// SPDX-License-Identifier: GPL-2.0-or-later
12 /*
23 * lm90.c - Part of lm_sensors, Linux kernel modules for hardware
34 * monitoring
....@@ -34,6 +35,15 @@
3435 * explicitly as max6659, or if its address is not 0x4c.
3536 * These chips lack the remote temperature offset feature.
3637 *
38
+ * This driver also supports the MAX6654 chip made by Maxim. This chip can be
39
+ * at 9 different addresses, similar to MAX6680/MAX6681. The MAX6654 is similar
40
+ * to MAX6657/MAX6658/MAX6659, but does not support critical temperature
41
+ * limits. Extended range is available by setting the configuration register
42
+ * accordingly, and is done during initialization. Extended precision is only
43
+ * available at conversion rates of 1 Hz and slower. Note that extended
44
+ * precision is not enabled by default, as this driver initializes all chips
45
+ * to 2 Hz by design.
46
+ *
3747 * This driver also supports the MAX6646, MAX6647, MAX6648, MAX6649 and
3848 * MAX6692 chips made by Maxim. These are again similar to the LM86,
3949 * but they use unsigned temperature values and can report temperatures
....@@ -60,28 +70,14 @@
6070 * This driver also supports the G781 from GMT. This device is compatible
6171 * with the ADM1032.
6272 *
63
- * This driver also supports TMP451 from Texas Instruments. This device is
64
- * supported in both compatibility and extended mode. It's mostly compatible
65
- * with ADT7461 except for local temperature low byte register and max
66
- * conversion rate.
73
+ * This driver also supports TMP451 and TMP461 from Texas Instruments.
74
+ * Those devices are supported in both compatibility and extended mode.
75
+ * They are mostly compatible with ADT7461 except for local temperature
76
+ * low byte register and max conversion rate.
6777 *
6878 * Since the LM90 was the first chipset supported by this driver, most
6979 * comments will refer to this chipset, but are actually general and
7080 * concern all supported chipsets, unless mentioned otherwise.
71
- *
72
- * This program is free software; you can redistribute it and/or modify
73
- * it under the terms of the GNU General Public License as published by
74
- * the Free Software Foundation; either version 2 of the License, or
75
- * (at your option) any later version.
76
- *
77
- * This program is distributed in the hope that it will be useful,
78
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
79
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
80
- * GNU General Public License for more details.
81
- *
82
- * You should have received a copy of the GNU General Public License
83
- * along with this program; if not, write to the Free Software
84
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
8581 */
8682
8783 #include <linux/module.h>
....@@ -107,8 +103,8 @@
107103 * have address 0x4d.
108104 * MAX6647 has address 0x4e.
109105 * MAX6659 can have address 0x4c, 0x4d or 0x4e.
110
- * MAX6680 and MAX6681 can have address 0x18, 0x19, 0x1a, 0x29, 0x2a, 0x2b,
111
- * 0x4c, 0x4d or 0x4e.
106
+ * MAX6654, MAX6680, and MAX6681 can have address 0x18, 0x19, 0x1a, 0x29,
107
+ * 0x2a, 0x2b, 0x4c, 0x4d or 0x4e.
112108 * SA56004 can have address 0x48 through 0x4F.
113109 */
114110
....@@ -117,7 +113,7 @@
117113 0x4d, 0x4e, 0x4f, I2C_CLIENT_END };
118114
119115 enum chips { lm90, adm1032, lm99, lm86, max6657, max6659, adt7461, max6680,
120
- max6646, w83l771, max6696, sa56004, g781, tmp451 };
116
+ max6646, w83l771, max6696, sa56004, g781, tmp451, tmp461, max6654 };
121117
122118 /*
123119 * The LM90 registers
....@@ -158,7 +154,7 @@
158154 #define LM90_REG_R_TCRIT_HYST 0x21
159155 #define LM90_REG_W_TCRIT_HYST 0x21
160156
161
-/* MAX6646/6647/6649/6657/6658/6659/6695/6696 registers */
157
+/* MAX6646/6647/6649/6654/6657/6658/6659/6695/6696 registers */
162158
163159 #define MAX6657_REG_R_LOCAL_TEMPL 0x11
164160 #define MAX6696_REG_R_STATUS2 0x12
....@@ -173,8 +169,12 @@
173169
174170 #define LM90_MAX_CONVRATE_MS 16000 /* Maximum conversion rate in ms */
175171
176
-/* TMP451 registers */
172
+/* TMP451/TMP461 registers */
177173 #define TMP451_REG_R_LOCAL_TEMPL 0x15
174
+#define TMP451_REG_CONALERT 0x22
175
+
176
+#define TMP461_REG_CHEN 0x16
177
+#define TMP461_REG_DFC 0x24
178178
179179 /*
180180 * Device flags
....@@ -187,7 +187,10 @@
187187 #define LM90_HAVE_EMERGENCY_ALARM (1 << 5)/* emergency alarm */
188188 #define LM90_HAVE_TEMP3 (1 << 6) /* 3rd temperature sensor */
189189 #define LM90_HAVE_BROKEN_ALERT (1 << 7) /* Broken alert */
190
-#define LM90_PAUSE_FOR_CONFIG (1 << 8) /* Pause conversion for config */
190
+#define LM90_HAVE_EXTENDED_TEMP (1 << 8) /* extended temperature support*/
191
+#define LM90_PAUSE_FOR_CONFIG (1 << 9) /* Pause conversion for config */
192
+#define LM90_HAVE_CRIT (1 << 10)/* Chip supports CRIT/OVERT register */
193
+#define LM90_HAVE_CRIT_ALRM_SWP (1 << 11)/* critical alarm bits swapped */
191194
192195 /* LM90 status */
193196 #define LM90_STATUS_LTHRM (1 << 0) /* local THERM limit tripped */
....@@ -223,6 +226,7 @@
223226 { "max6646", max6646 },
224227 { "max6647", max6646 },
225228 { "max6649", max6646 },
229
+ { "max6654", max6654 },
226230 { "max6657", max6657 },
227231 { "max6658", max6657 },
228232 { "max6659", max6659 },
....@@ -234,11 +238,12 @@
234238 { "w83l771", w83l771 },
235239 { "sa56004", sa56004 },
236240 { "tmp451", tmp451 },
241
+ { "tmp461", tmp461 },
237242 { }
238243 };
239244 MODULE_DEVICE_TABLE(i2c, lm90_id);
240245
241
-static const struct of_device_id lm90_of_match[] = {
246
+static const struct of_device_id __maybe_unused lm90_of_match[] = {
242247 {
243248 .compatible = "adi,adm1032",
244249 .data = (void *)adm1032
....@@ -284,6 +289,10 @@
284289 .data = (void *)max6646
285290 },
286291 {
292
+ .compatible = "dallas,max6654",
293
+ .data = (void *)max6654
294
+ },
295
+ {
287296 .compatible = "dallas,max6657",
288297 .data = (void *)max6657
289298 },
....@@ -327,6 +336,10 @@
327336 .compatible = "ti,tmp451",
328337 .data = (void *)tmp451
329338 },
339
+ {
340
+ .compatible = "ti,tmp461",
341
+ .data = (void *)tmp461
342
+ },
330343 { },
331344 };
332345 MODULE_DEVICE_TABLE(of, lm90_of_match);
....@@ -345,80 +358,99 @@
345358 static const struct lm90_params lm90_params[] = {
346359 [adm1032] = {
347360 .flags = LM90_HAVE_OFFSET | LM90_HAVE_REM_LIMIT_EXT
348
- | LM90_HAVE_BROKEN_ALERT,
361
+ | LM90_HAVE_BROKEN_ALERT | LM90_HAVE_CRIT,
349362 .alert_alarms = 0x7c,
350363 .max_convrate = 10,
351364 },
352365 [adt7461] = {
353366 .flags = LM90_HAVE_OFFSET | LM90_HAVE_REM_LIMIT_EXT
354
- | LM90_HAVE_BROKEN_ALERT,
367
+ | LM90_HAVE_BROKEN_ALERT | LM90_HAVE_EXTENDED_TEMP
368
+ | LM90_HAVE_CRIT,
355369 .alert_alarms = 0x7c,
356370 .max_convrate = 10,
357371 },
358372 [g781] = {
359373 .flags = LM90_HAVE_OFFSET | LM90_HAVE_REM_LIMIT_EXT
360
- | LM90_HAVE_BROKEN_ALERT,
374
+ | LM90_HAVE_BROKEN_ALERT | LM90_HAVE_CRIT,
361375 .alert_alarms = 0x7c,
362376 .max_convrate = 7,
363377 },
364378 [lm86] = {
365
- .flags = LM90_HAVE_OFFSET | LM90_HAVE_REM_LIMIT_EXT,
379
+ .flags = LM90_HAVE_OFFSET | LM90_HAVE_REM_LIMIT_EXT
380
+ | LM90_HAVE_CRIT,
366381 .alert_alarms = 0x7b,
367382 .max_convrate = 9,
368383 },
369384 [lm90] = {
370
- .flags = LM90_HAVE_OFFSET | LM90_HAVE_REM_LIMIT_EXT,
385
+ .flags = LM90_HAVE_OFFSET | LM90_HAVE_REM_LIMIT_EXT
386
+ | LM90_HAVE_CRIT,
371387 .alert_alarms = 0x7b,
372388 .max_convrate = 9,
373389 },
374390 [lm99] = {
375
- .flags = LM90_HAVE_OFFSET | LM90_HAVE_REM_LIMIT_EXT,
391
+ .flags = LM90_HAVE_OFFSET | LM90_HAVE_REM_LIMIT_EXT
392
+ | LM90_HAVE_CRIT,
376393 .alert_alarms = 0x7b,
377394 .max_convrate = 9,
378395 },
379396 [max6646] = {
397
+ .flags = LM90_HAVE_CRIT | LM90_HAVE_BROKEN_ALERT,
380398 .alert_alarms = 0x7c,
381399 .max_convrate = 6,
382400 .reg_local_ext = MAX6657_REG_R_LOCAL_TEMPL,
383401 },
402
+ [max6654] = {
403
+ .flags = LM90_HAVE_BROKEN_ALERT,
404
+ .alert_alarms = 0x7c,
405
+ .max_convrate = 7,
406
+ .reg_local_ext = MAX6657_REG_R_LOCAL_TEMPL,
407
+ },
384408 [max6657] = {
385
- .flags = LM90_PAUSE_FOR_CONFIG,
409
+ .flags = LM90_PAUSE_FOR_CONFIG | LM90_HAVE_CRIT,
386410 .alert_alarms = 0x7c,
387411 .max_convrate = 8,
388412 .reg_local_ext = MAX6657_REG_R_LOCAL_TEMPL,
389413 },
390414 [max6659] = {
391
- .flags = LM90_HAVE_EMERGENCY,
415
+ .flags = LM90_HAVE_EMERGENCY | LM90_HAVE_CRIT,
392416 .alert_alarms = 0x7c,
393417 .max_convrate = 8,
394418 .reg_local_ext = MAX6657_REG_R_LOCAL_TEMPL,
395419 },
396420 [max6680] = {
397
- .flags = LM90_HAVE_OFFSET,
421
+ .flags = LM90_HAVE_OFFSET | LM90_HAVE_CRIT
422
+ | LM90_HAVE_CRIT_ALRM_SWP | LM90_HAVE_BROKEN_ALERT,
398423 .alert_alarms = 0x7c,
399424 .max_convrate = 7,
400425 },
401426 [max6696] = {
402427 .flags = LM90_HAVE_EMERGENCY
403
- | LM90_HAVE_EMERGENCY_ALARM | LM90_HAVE_TEMP3,
428
+ | LM90_HAVE_EMERGENCY_ALARM | LM90_HAVE_TEMP3 | LM90_HAVE_CRIT,
404429 .alert_alarms = 0x1c7c,
405430 .max_convrate = 6,
406431 .reg_local_ext = MAX6657_REG_R_LOCAL_TEMPL,
407432 },
408433 [w83l771] = {
409
- .flags = LM90_HAVE_OFFSET | LM90_HAVE_REM_LIMIT_EXT,
434
+ .flags = LM90_HAVE_OFFSET | LM90_HAVE_REM_LIMIT_EXT | LM90_HAVE_CRIT,
410435 .alert_alarms = 0x7c,
411436 .max_convrate = 8,
412437 },
413438 [sa56004] = {
414
- .flags = LM90_HAVE_OFFSET | LM90_HAVE_REM_LIMIT_EXT,
439
+ .flags = LM90_HAVE_OFFSET | LM90_HAVE_REM_LIMIT_EXT | LM90_HAVE_CRIT,
415440 .alert_alarms = 0x7b,
416441 .max_convrate = 9,
417442 .reg_local_ext = SA56004_REG_R_LOCAL_TEMPL,
418443 },
419444 [tmp451] = {
420445 .flags = LM90_HAVE_OFFSET | LM90_HAVE_REM_LIMIT_EXT
421
- | LM90_HAVE_BROKEN_ALERT,
446
+ | LM90_HAVE_BROKEN_ALERT | LM90_HAVE_EXTENDED_TEMP | LM90_HAVE_CRIT,
447
+ .alert_alarms = 0x7c,
448
+ .max_convrate = 9,
449
+ .reg_local_ext = TMP451_REG_R_LOCAL_TEMPL,
450
+ },
451
+ [tmp461] = {
452
+ .flags = LM90_HAVE_OFFSET | LM90_HAVE_REM_LIMIT_EXT
453
+ | LM90_HAVE_BROKEN_ALERT | LM90_HAVE_EXTENDED_TEMP | LM90_HAVE_CRIT,
422454 .alert_alarms = 0x7c,
423455 .max_convrate = 9,
424456 .reg_local_ext = TMP451_REG_R_LOCAL_TEMPL,
....@@ -473,6 +505,7 @@
473505
474506 unsigned int update_interval; /* in milliseconds */
475507
508
+ u8 config; /* Current configuration register value */
476509 u8 config_orig; /* Original configuration register value */
477510 u8 convrate_orig; /* Original conversion rate register value */
478511 u16 alert_alarms; /* Which alarm bits trigger ALERT# */
....@@ -556,6 +589,21 @@
556589 return (newh << 8) | l;
557590 }
558591
592
+static int lm90_update_confreg(struct lm90_data *data, u8 config)
593
+{
594
+ if (data->config != config) {
595
+ int err;
596
+
597
+ err = i2c_smbus_write_byte_data(data->client,
598
+ LM90_REG_W_CONFIG1,
599
+ config);
600
+ if (err)
601
+ return err;
602
+ data->config = config;
603
+ }
604
+ return 0;
605
+}
606
+
559607 /*
560608 * client->update_lock must be held when calling this function (unless we are
561609 * in detection or initialization steps), and while a remote channel other
....@@ -564,53 +612,37 @@
564612 * various registers have different meanings as a result of selecting a
565613 * non-default remote channel.
566614 */
567
-static inline int lm90_select_remote_channel(struct i2c_client *client,
568
- struct lm90_data *data,
569
- int channel)
615
+static int lm90_select_remote_channel(struct lm90_data *data, int channel)
570616 {
571
- int config;
617
+ int err = 0;
572618
573619 if (data->kind == max6696) {
574
- config = lm90_read_reg(client, LM90_REG_R_CONFIG1);
575
- if (config < 0)
576
- return config;
577
- config &= ~0x08;
620
+ u8 config = data->config & ~0x08;
621
+
578622 if (channel)
579623 config |= 0x08;
580
- i2c_smbus_write_byte_data(client, LM90_REG_W_CONFIG1,
581
- config);
624
+ err = lm90_update_confreg(data, config);
582625 }
583
- return 0;
626
+ return err;
584627 }
585628
586
-static int lm90_write_convrate(struct i2c_client *client,
587
- struct lm90_data *data, int val)
629
+static int lm90_write_convrate(struct lm90_data *data, int val)
588630 {
631
+ u8 config = data->config;
589632 int err;
590
- int config_orig, config_stop;
591633
592634 /* Save config and pause conversion */
593635 if (data->flags & LM90_PAUSE_FOR_CONFIG) {
594
- config_orig = lm90_read_reg(client, LM90_REG_R_CONFIG1);
595
- if (config_orig < 0)
596
- return config_orig;
597
- config_stop = config_orig | 0x40;
598
- if (config_orig != config_stop) {
599
- err = i2c_smbus_write_byte_data(client,
600
- LM90_REG_W_CONFIG1,
601
- config_stop);
602
- if (err < 0)
603
- return err;
604
- }
636
+ err = lm90_update_confreg(data, config | 0x40);
637
+ if (err < 0)
638
+ return err;
605639 }
606640
607641 /* Set conv rate */
608
- err = i2c_smbus_write_byte_data(client, LM90_REG_W_CONVRATE, val);
642
+ err = i2c_smbus_write_byte_data(data->client, LM90_REG_W_CONVRATE, val);
609643
610644 /* Revert change to config */
611
- if (data->flags & LM90_PAUSE_FOR_CONFIG && config_orig != config_stop)
612
- i2c_smbus_write_byte_data(client, LM90_REG_W_CONFIG1,
613
- config_orig);
645
+ lm90_update_confreg(data, config);
614646
615647 return err;
616648 }
....@@ -635,7 +667,7 @@
635667 if (interval >= update_interval * 3 / 4)
636668 break;
637669
638
- err = lm90_write_convrate(client, data, i);
670
+ err = lm90_write_convrate(data, i);
639671 data->update_interval = DIV_ROUND_CLOSEST(update_interval, 64);
640672 return err;
641673 }
....@@ -646,20 +678,22 @@
646678 struct i2c_client *client = data->client;
647679 int val;
648680
649
- val = lm90_read_reg(client, LM90_REG_R_LOCAL_CRIT);
650
- if (val < 0)
651
- return val;
652
- data->temp8[LOCAL_CRIT] = val;
681
+ if (data->flags & LM90_HAVE_CRIT) {
682
+ val = lm90_read_reg(client, LM90_REG_R_LOCAL_CRIT);
683
+ if (val < 0)
684
+ return val;
685
+ data->temp8[LOCAL_CRIT] = val;
653686
654
- val = lm90_read_reg(client, LM90_REG_R_REMOTE_CRIT);
655
- if (val < 0)
656
- return val;
657
- data->temp8[REMOTE_CRIT] = val;
687
+ val = lm90_read_reg(client, LM90_REG_R_REMOTE_CRIT);
688
+ if (val < 0)
689
+ return val;
690
+ data->temp8[REMOTE_CRIT] = val;
658691
659
- val = lm90_read_reg(client, LM90_REG_R_TCRIT_HYST);
660
- if (val < 0)
661
- return val;
662
- data->temp_hyst = val;
692
+ val = lm90_read_reg(client, LM90_REG_R_TCRIT_HYST);
693
+ if (val < 0)
694
+ return val;
695
+ data->temp_hyst = val;
696
+ }
663697
664698 val = lm90_read_reg(client, LM90_REG_R_REMOTE_LOWH);
665699 if (val < 0)
....@@ -706,7 +740,7 @@
706740 }
707741
708742 if (data->kind == max6696) {
709
- val = lm90_select_remote_channel(client, data, 1);
743
+ val = lm90_select_remote_channel(data, 1);
710744 if (val < 0)
711745 return val;
712746
....@@ -730,7 +764,7 @@
730764 return val;
731765 data->temp11[REMOTE2_HIGH] = val << 8;
732766
733
- lm90_select_remote_channel(client, data, 0);
767
+ lm90_select_remote_channel(data, 0);
734768 }
735769
736770 return 0;
....@@ -790,19 +824,19 @@
790824 data->alarms = val & ~LM90_STATUS_BUSY;
791825
792826 if (data->kind == max6696) {
793
- val = lm90_select_remote_channel(client, data, 1);
827
+ val = lm90_select_remote_channel(data, 1);
794828 if (val < 0)
795829 return val;
796830
797831 val = lm90_read16(client, LM90_REG_R_REMOTE_TEMPH,
798832 LM90_REG_R_REMOTE_TEMPL);
799833 if (val < 0) {
800
- lm90_select_remote_channel(client, data, 0);
834
+ lm90_select_remote_channel(data, 0);
801835 return val;
802836 }
803837 data->temp11[REMOTE2_TEMP] = val;
804838
805
- lm90_select_remote_channel(client, data, 0);
839
+ lm90_select_remote_channel(data, 0);
806840
807841 val = lm90_read_reg(client, MAX6696_REG_R_STATUS2);
808842 if (val < 0)
....@@ -816,15 +850,9 @@
816850 */
817851 if (!(data->config_orig & 0x80) &&
818852 !(data->alarms & data->alert_alarms)) {
819
- val = lm90_read_reg(client, LM90_REG_R_CONFIG1);
820
- if (val < 0)
821
- return val;
822
-
823
- if (val & 0x80) {
853
+ if (data->config & 0x80) {
824854 dev_dbg(&client->dev, "Re-enabling ALERT#\n");
825
- i2c_smbus_write_byte_data(client,
826
- LM90_REG_W_CONFIG1,
827
- val & ~0x80);
855
+ lm90_update_confreg(data, data->config & ~0x80);
828856 }
829857 }
830858
....@@ -999,7 +1027,7 @@
9991027 s16 temp11 = data->temp11[index];
10001028 int temp;
10011029
1002
- if (data->kind == adt7461 || data->kind == tmp451)
1030
+ if (data->flags & LM90_HAVE_EXTENDED_TEMP)
10031031 temp = temp_from_u16_adt7461(data, temp11);
10041032 else if (data->kind == max6646)
10051033 temp = temp_from_u16(temp11);
....@@ -1033,7 +1061,7 @@
10331061 if (data->kind == lm99 && index <= 2)
10341062 val -= 16000;
10351063
1036
- if (data->kind == adt7461 || data->kind == tmp451)
1064
+ if (data->flags & LM90_HAVE_EXTENDED_TEMP)
10371065 data->temp11[index] = temp_to_u16_adt7461(data, val);
10381066 else if (data->kind == max6646)
10391067 data->temp11[index] = temp_to_u8(val) << 8;
....@@ -1042,7 +1070,7 @@
10421070 else
10431071 data->temp11[index] = temp_to_s8(val) << 8;
10441072
1045
- lm90_select_remote_channel(client, data, index >= 3);
1073
+ lm90_select_remote_channel(data, index >= 3);
10461074 err = i2c_smbus_write_byte_data(client, regp->high,
10471075 data->temp11[index] >> 8);
10481076 if (err < 0)
....@@ -1051,7 +1079,7 @@
10511079 err = i2c_smbus_write_byte_data(client, regp->low,
10521080 data->temp11[index] & 0xff);
10531081
1054
- lm90_select_remote_channel(client, data, 0);
1082
+ lm90_select_remote_channel(data, 0);
10551083 return err;
10561084 }
10571085
....@@ -1060,7 +1088,7 @@
10601088 s8 temp8 = data->temp8[index];
10611089 int temp;
10621090
1063
- if (data->kind == adt7461 || data->kind == tmp451)
1091
+ if (data->flags & LM90_HAVE_EXTENDED_TEMP)
10641092 temp = temp_from_u8_adt7461(data, temp8);
10651093 else if (data->kind == max6646)
10661094 temp = temp_from_u8(temp8);
....@@ -1093,16 +1121,16 @@
10931121 if (data->kind == lm99 && index == 3)
10941122 val -= 16000;
10951123
1096
- if (data->kind == adt7461 || data->kind == tmp451)
1124
+ if (data->flags & LM90_HAVE_EXTENDED_TEMP)
10971125 data->temp8[index] = temp_to_u8_adt7461(data, val);
10981126 else if (data->kind == max6646)
10991127 data->temp8[index] = temp_to_u8(val);
11001128 else
11011129 data->temp8[index] = temp_to_s8(val);
11021130
1103
- lm90_select_remote_channel(client, data, index >= 6);
1131
+ lm90_select_remote_channel(data, index >= 6);
11041132 err = i2c_smbus_write_byte_data(client, reg[index], data->temp8[index]);
1105
- lm90_select_remote_channel(client, data, 0);
1133
+ lm90_select_remote_channel(data, 0);
11061134
11071135 return err;
11081136 }
....@@ -1111,7 +1139,7 @@
11111139 {
11121140 int temp;
11131141
1114
- if (data->kind == adt7461 || data->kind == tmp451)
1142
+ if (data->flags & LM90_HAVE_EXTENDED_TEMP)
11151143 temp = temp_from_u8_adt7461(data, data->temp8[index]);
11161144 else if (data->kind == max6646)
11171145 temp = temp_from_u8(data->temp8[index]);
....@@ -1131,7 +1159,7 @@
11311159 int temp;
11321160 int err;
11331161
1134
- if (data->kind == adt7461 || data->kind == tmp451)
1162
+ if (data->flags & LM90_HAVE_EXTENDED_TEMP)
11351163 temp = temp_from_u8_adt7461(data, data->temp8[LOCAL_CRIT]);
11361164 else if (data->kind == max6646)
11371165 temp = temp_from_u8(data->temp8[LOCAL_CRIT]);
....@@ -1167,6 +1195,7 @@
11671195 static const u8 lm90_min_alarm_bits[3] = { 5, 3, 11 };
11681196 static const u8 lm90_max_alarm_bits[3] = { 6, 4, 12 };
11691197 static const u8 lm90_crit_alarm_bits[3] = { 0, 1, 9 };
1198
+static const u8 lm90_crit_alarm_bits_swapped[3] = { 1, 0, 9 };
11701199 static const u8 lm90_emergency_alarm_bits[3] = { 15, 13, 14 };
11711200 static const u8 lm90_fault_bits[3] = { 0, 2, 10 };
11721201
....@@ -1192,7 +1221,10 @@
11921221 *val = (data->alarms >> lm90_max_alarm_bits[channel]) & 1;
11931222 break;
11941223 case hwmon_temp_crit_alarm:
1195
- *val = (data->alarms >> lm90_crit_alarm_bits[channel]) & 1;
1224
+ if (data->flags & LM90_HAVE_CRIT_ALRM_SWP)
1225
+ *val = (data->alarms >> lm90_crit_alarm_bits_swapped[channel]) & 1;
1226
+ else
1227
+ *val = (data->alarms >> lm90_crit_alarm_bits[channel]) & 1;
11961228 break;
11971229 case hwmon_temp_emergency_alarm:
11981230 *val = (data->alarms >> lm90_emergency_alarm_bits[channel]) & 1;
....@@ -1301,17 +1333,17 @@
13011333 case hwmon_temp_emergency_alarm:
13021334 case hwmon_temp_emergency_hyst:
13031335 case hwmon_temp_fault:
1304
- return S_IRUGO;
1336
+ return 0444;
13051337 case hwmon_temp_min:
13061338 case hwmon_temp_max:
13071339 case hwmon_temp_crit:
13081340 case hwmon_temp_emergency:
13091341 case hwmon_temp_offset:
1310
- return S_IRUGO | S_IWUSR;
1342
+ return 0644;
13111343 case hwmon_temp_crit_hyst:
13121344 if (channel == 0)
1313
- return S_IRUGO | S_IWUSR;
1314
- return S_IRUGO;
1345
+ return 0644;
1346
+ return 0444;
13151347 default:
13161348 return 0;
13171349 }
....@@ -1373,9 +1405,9 @@
13731405 {
13741406 switch (attr) {
13751407 case hwmon_chip_update_interval:
1376
- return S_IRUGO | S_IWUSR;
1408
+ return 0644;
13771409 case hwmon_chip_alarms:
1378
- return S_IRUGO;
1410
+ return 0444;
13791411 default:
13801412 return 0;
13811413 }
....@@ -1576,6 +1608,16 @@
15761608 && (config1 & 0x3f) == 0x00
15771609 && convrate <= 0x07) {
15781610 name = "max6646";
1611
+ } else
1612
+ /*
1613
+ * The chip_id of the MAX6654 holds the revision of the chip.
1614
+ * The lowest 3 bits of the config1 register are unused and
1615
+ * should return zero when read.
1616
+ */
1617
+ if (chip_id == 0x08
1618
+ && (config1 & 0x07) == 0x00
1619
+ && convrate <= 0x07) {
1620
+ name = "max6654";
15791621 }
15801622 } else
15811623 if (address == 0x4C
....@@ -1608,18 +1650,26 @@
16081650 && convrate <= 0x08)
16091651 name = "g781";
16101652 } else
1611
- if (address == 0x4C
1612
- && man_id == 0x55) { /* Texas Instruments */
1613
- int local_ext;
1653
+ if (man_id == 0x55 && chip_id == 0x00 &&
1654
+ (config1 & 0x1B) == 0x00 && convrate <= 0x09) {
1655
+ int local_ext, conalert, chen, dfc;
16141656
16151657 local_ext = i2c_smbus_read_byte_data(client,
16161658 TMP451_REG_R_LOCAL_TEMPL);
1659
+ conalert = i2c_smbus_read_byte_data(client,
1660
+ TMP451_REG_CONALERT);
1661
+ chen = i2c_smbus_read_byte_data(client, TMP461_REG_CHEN);
1662
+ dfc = i2c_smbus_read_byte_data(client, TMP461_REG_DFC);
16171663
1618
- if (chip_id == 0x00 /* TMP451 */
1619
- && (config1 & 0x1B) == 0x00
1620
- && convrate <= 0x09
1621
- && (local_ext & 0x0F) == 0x00)
1622
- name = "tmp451";
1664
+ if ((local_ext & 0x0F) == 0x00 &&
1665
+ (conalert & 0xf1) == 0x01 &&
1666
+ (chen & 0xfc) == 0x00 &&
1667
+ (dfc & 0xfc) == 0x00) {
1668
+ if (address == 0x4c && !(chen & 0x03))
1669
+ name = "tmp451";
1670
+ else if (address >= 0x48 && address <= 0x4f)
1671
+ name = "tmp461";
1672
+ }
16231673 }
16241674
16251675 if (!name) { /* identification failed */
....@@ -1640,7 +1690,7 @@
16401690 struct i2c_client *client = data->client;
16411691
16421692 /* Restore initial configuration */
1643
- lm90_write_convrate(client, data, data->convrate_orig);
1693
+ lm90_write_convrate(data, data->convrate_orig);
16441694 i2c_smbus_write_byte_data(client, LM90_REG_W_CONFIG1,
16451695 data->config_orig);
16461696 }
....@@ -1661,11 +1711,12 @@
16611711 if (config < 0)
16621712 return config;
16631713 data->config_orig = config;
1714
+ data->config = config;
16641715
16651716 lm90_set_convrate(client, data, 500); /* 500ms; 2Hz conversion rate */
16661717
16671718 /* Check Temperature Range Select */
1668
- if (data->kind == adt7461 || data->kind == tmp451) {
1719
+ if (data->flags & LM90_HAVE_EXTENDED_TEMP) {
16691720 if (config & 0x04)
16701721 data->flags |= LM90_FLAG_ADT7461_EXT;
16711722 }
....@@ -1679,14 +1730,22 @@
16791730 config |= 0x18;
16801731
16811732 /*
1733
+ * Put MAX6654 into extended range (0x20, extend minimum range from
1734
+ * 0 degrees to -64 degrees). Note that extended resolution is not
1735
+ * possible on the MAX6654 unless conversion rate is set to 1 Hz or
1736
+ * slower, which is intentionally not done by default.
1737
+ */
1738
+ if (data->kind == max6654)
1739
+ config |= 0x20;
1740
+
1741
+ /*
16821742 * Select external channel 0 for max6695/96
16831743 */
16841744 if (data->kind == max6696)
16851745 config &= ~0x08;
16861746
16871747 config &= 0xBF; /* run */
1688
- if (config != data->config_orig) /* Only write if changed */
1689
- i2c_smbus_write_byte_data(client, LM90_REG_W_CONFIG1, config);
1748
+ lm90_update_confreg(data, config);
16901749
16911750 return devm_add_action_or_reset(&client->dev, lm90_restore_conf, data);
16921751 }
....@@ -1754,16 +1813,6 @@
17541813 regulator_disable(regulator);
17551814 }
17561815
1757
-static const u32 lm90_chip_config[] = {
1758
- HWMON_C_REGISTER_TZ | HWMON_C_UPDATE_INTERVAL | HWMON_C_ALARMS,
1759
- 0
1760
-};
1761
-
1762
-static const struct hwmon_channel_info lm90_chip_info = {
1763
- .type = hwmon_chip,
1764
- .config = lm90_chip_config,
1765
-};
1766
-
17671816
17681817 static const struct hwmon_ops lm90_ops = {
17691818 .is_visible = lm90_is_visible,
....@@ -1771,11 +1820,10 @@
17711820 .write = lm90_write,
17721821 };
17731822
1774
-static int lm90_probe(struct i2c_client *client,
1775
- const struct i2c_device_id *id)
1823
+static int lm90_probe(struct i2c_client *client)
17761824 {
17771825 struct device *dev = &client->dev;
1778
- struct i2c_adapter *adapter = to_i2c_adapter(dev->parent);
1826
+ struct i2c_adapter *adapter = client->adapter;
17791827 struct hwmon_channel_info *info;
17801828 struct regulator *regulator;
17811829 struct device *hwmon_dev;
....@@ -1808,7 +1856,7 @@
18081856 if (client->dev.of_node)
18091857 data->kind = (enum chips)of_device_get_match_data(&client->dev);
18101858 else
1811
- data->kind = id->driver_data;
1859
+ data->kind = i2c_match_id(lm90_id, client)->driver_data;
18121860 if (data->kind == adm1032) {
18131861 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE))
18141862 client->flags &= ~I2C_CLIENT_PEC;
....@@ -1826,7 +1874,8 @@
18261874 data->chip.ops = &lm90_ops;
18271875 data->chip.info = data->info;
18281876
1829
- data->info[0] = &lm90_chip_info;
1877
+ data->info[0] = HWMON_CHANNEL_INFO(chip,
1878
+ HWMON_C_REGISTER_TZ | HWMON_C_UPDATE_INTERVAL | HWMON_C_ALARMS);
18301879 data->info[1] = &data->temp_info;
18311880
18321881 info = &data->temp_info;
....@@ -1834,11 +1883,14 @@
18341883 info->config = data->channel_config;
18351884
18361885 data->channel_config[0] = HWMON_T_INPUT | HWMON_T_MIN | HWMON_T_MAX |
1837
- HWMON_T_CRIT | HWMON_T_CRIT_HYST | HWMON_T_MIN_ALARM |
1838
- HWMON_T_MAX_ALARM | HWMON_T_CRIT_ALARM;
1886
+ HWMON_T_MIN_ALARM | HWMON_T_MAX_ALARM;
18391887 data->channel_config[1] = HWMON_T_INPUT | HWMON_T_MIN | HWMON_T_MAX |
1840
- HWMON_T_CRIT | HWMON_T_CRIT_HYST | HWMON_T_MIN_ALARM |
1841
- HWMON_T_MAX_ALARM | HWMON_T_CRIT_ALARM | HWMON_T_FAULT;
1888
+ HWMON_T_MIN_ALARM | HWMON_T_MAX_ALARM | HWMON_T_FAULT;
1889
+
1890
+ if (data->flags & LM90_HAVE_CRIT) {
1891
+ data->channel_config[0] |= HWMON_T_CRIT | HWMON_T_CRIT_ALARM | HWMON_T_CRIT_HYST;
1892
+ data->channel_config[1] |= HWMON_T_CRIT | HWMON_T_CRIT_ALARM | HWMON_T_CRIT_HYST;
1893
+ }
18421894
18431895 if (data->flags & LM90_HAVE_OFFSET)
18441896 data->channel_config[1] |= HWMON_T_OFFSET;
....@@ -1929,14 +1981,8 @@
19291981
19301982 if ((data->flags & LM90_HAVE_BROKEN_ALERT) &&
19311983 (alarms & data->alert_alarms)) {
1932
- int config;
1933
-
19341984 dev_dbg(&client->dev, "Disabling ALERT#\n");
1935
- config = lm90_read_reg(client, LM90_REG_R_CONFIG1);
1936
- if (config >= 0)
1937
- i2c_smbus_write_byte_data(client,
1938
- LM90_REG_W_CONFIG1,
1939
- config | 0x80);
1985
+ lm90_update_confreg(data, data->config | 0x80);
19401986 }
19411987 } else {
19421988 dev_info(&client->dev, "Everything OK\n");
....@@ -1949,7 +1995,7 @@
19491995 .name = "lm90",
19501996 .of_match_table = of_match_ptr(lm90_of_match),
19511997 },
1952
- .probe = lm90_probe,
1998
+ .probe_new = lm90_probe,
19531999 .alert = lm90_alert,
19542000 .id_table = lm90_id,
19552001 .detect = lm90_detect,