hc
2024-02-20 102a0743326a03cd1a1202ceda21e175b7d3575c
kernel/drivers/hwmon/lm75.c
....@@ -1,21 +1,8 @@
1
+// SPDX-License-Identifier: GPL-2.0-or-later
12 /*
23 * lm75.c - Part of lm_sensors, Linux kernel modules for hardware
34 * monitoring
45 * Copyright (c) 1998, 1999 Frodo Looijaard <frodol@dds.nl>
5
- *
6
- * This program is free software; you can redistribute it and/or modify
7
- * it under the terms of the GNU General Public License as published by
8
- * the Free Software Foundation; either version 2 of the License, or
9
- * (at your option) any later version.
10
- *
11
- * This program is distributed in the hope that it will be useful,
12
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
- * GNU General Public License for more details.
15
- *
16
- * You should have received a copy of the GNU General Public License
17
- * along with this program; if not, write to the Free Software
18
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
196 */
207
218 #include <linux/module.h>
....@@ -29,8 +16,9 @@
2916 #include <linux/of_device.h>
3017 #include <linux/of.h>
3118 #include <linux/regmap.h>
19
+#include <linux/util_macros.h>
20
+#include <linux/regulator/consumer.h>
3221 #include "lm75.h"
33
-
3422
3523 /*
3624 * This driver handles the LM75 and compatible digital temperature sensors.
....@@ -47,8 +35,11 @@
4735 lm75b,
4836 max6625,
4937 max6626,
38
+ max31725,
5039 mcp980x,
40
+ pct2075,
5141 stds75,
42
+ stlm75,
5243 tcn75,
5344 tmp100,
5445 tmp101,
....@@ -57,35 +48,278 @@
5748 tmp175,
5849 tmp275,
5950 tmp75,
51
+ tmp75b,
6052 tmp75c,
53
+};
54
+
55
+/**
56
+ * struct lm75_params - lm75 configuration parameters.
57
+ * @set_mask: Bits to set in configuration register when configuring
58
+ * the chip.
59
+ * @clr_mask: Bits to clear in configuration register when configuring
60
+ * the chip.
61
+ * @default_resolution: Default number of bits to represent the temperature
62
+ * value.
63
+ * @resolution_limits: Limit register resolution. Optional. Should be set if
64
+ * the resolution of limit registers does not match the
65
+ * resolution of the temperature register.
66
+ * @resolutions: List of resolutions associated with sample times.
67
+ * Optional. Should be set if num_sample_times is larger
68
+ * than 1, and if the resolution changes with sample times.
69
+ * If set, number of entries must match num_sample_times.
70
+ * @default_sample_time:Sample time to be set by default.
71
+ * @num_sample_times: Number of possible sample times to be set. Optional.
72
+ * Should be set if the number of sample times is larger
73
+ * than one.
74
+ * @sample_times: All the possible sample times to be set. Mandatory if
75
+ * num_sample_times is larger than 1. If set, number of
76
+ * entries must match num_sample_times.
77
+ */
78
+
79
+struct lm75_params {
80
+ u8 set_mask;
81
+ u8 clr_mask;
82
+ u8 default_resolution;
83
+ u8 resolution_limits;
84
+ const u8 *resolutions;
85
+ unsigned int default_sample_time;
86
+ u8 num_sample_times;
87
+ const unsigned int *sample_times;
6188 };
6289
6390 /* Addresses scanned */
6491 static const unsigned short normal_i2c[] = { 0x48, 0x49, 0x4a, 0x4b, 0x4c,
6592 0x4d, 0x4e, 0x4f, I2C_CLIENT_END };
6693
67
-
6894 /* The LM75 registers */
6995 #define LM75_REG_TEMP 0x00
7096 #define LM75_REG_CONF 0x01
7197 #define LM75_REG_HYST 0x02
7298 #define LM75_REG_MAX 0x03
99
+#define PCT2075_REG_IDLE 0x04
73100
74101 /* Each client has this additional data */
75102 struct lm75_data {
76
- struct i2c_client *client;
77
- struct regmap *regmap;
78
- u8 orig_conf;
79
- u8 resolution; /* In bits, between 9 and 12 */
80
- u8 resolution_limits;
81
- unsigned int sample_time; /* In ms */
103
+ struct i2c_client *client;
104
+ struct regmap *regmap;
105
+ struct regulator *vs;
106
+ u8 orig_conf;
107
+ u8 current_conf;
108
+ u8 resolution; /* In bits, 9 to 16 */
109
+ unsigned int sample_time; /* In ms */
110
+ enum lm75_type kind;
111
+ const struct lm75_params *params;
82112 };
83113
84114 /*-----------------------------------------------------------------------*/
85115
116
+static const u8 lm75_sample_set_masks[] = { 0 << 5, 1 << 5, 2 << 5, 3 << 5 };
117
+
118
+#define LM75_SAMPLE_CLEAR_MASK (3 << 5)
119
+
120
+/* The structure below stores the configuration values of the supported devices.
121
+ * In case of being supported multiple configurations, the default one must
122
+ * always be the first element of the array
123
+ */
124
+static const struct lm75_params device_params[] = {
125
+ [adt75] = {
126
+ .clr_mask = 1 << 5, /* not one-shot mode */
127
+ .default_resolution = 12,
128
+ .default_sample_time = MSEC_PER_SEC / 10,
129
+ },
130
+ [ds1775] = {
131
+ .clr_mask = 3 << 5,
132
+ .set_mask = 2 << 5, /* 11-bit mode */
133
+ .default_resolution = 11,
134
+ .default_sample_time = 500,
135
+ .num_sample_times = 4,
136
+ .sample_times = (unsigned int []){ 125, 250, 500, 1000 },
137
+ .resolutions = (u8 []) {9, 10, 11, 12 },
138
+ },
139
+ [ds75] = {
140
+ .clr_mask = 3 << 5,
141
+ .set_mask = 2 << 5, /* 11-bit mode */
142
+ .default_resolution = 11,
143
+ .default_sample_time = 600,
144
+ .num_sample_times = 4,
145
+ .sample_times = (unsigned int []){ 150, 300, 600, 1200 },
146
+ .resolutions = (u8 []) {9, 10, 11, 12 },
147
+ },
148
+ [stds75] = {
149
+ .clr_mask = 3 << 5,
150
+ .set_mask = 2 << 5, /* 11-bit mode */
151
+ .default_resolution = 11,
152
+ .default_sample_time = 600,
153
+ .num_sample_times = 4,
154
+ .sample_times = (unsigned int []){ 150, 300, 600, 1200 },
155
+ .resolutions = (u8 []) {9, 10, 11, 12 },
156
+ },
157
+ [stlm75] = {
158
+ .default_resolution = 9,
159
+ .default_sample_time = MSEC_PER_SEC / 6,
160
+ },
161
+ [ds7505] = {
162
+ .set_mask = 3 << 5, /* 12-bit mode*/
163
+ .default_resolution = 12,
164
+ .default_sample_time = 200,
165
+ .num_sample_times = 4,
166
+ .sample_times = (unsigned int []){ 25, 50, 100, 200 },
167
+ .resolutions = (u8 []) {9, 10, 11, 12 },
168
+ },
169
+ [g751] = {
170
+ .default_resolution = 9,
171
+ .default_sample_time = MSEC_PER_SEC / 10,
172
+ },
173
+ [lm75] = {
174
+ .default_resolution = 9,
175
+ .default_sample_time = MSEC_PER_SEC / 10,
176
+ },
177
+ [lm75a] = {
178
+ .default_resolution = 9,
179
+ .default_sample_time = MSEC_PER_SEC / 10,
180
+ },
181
+ [lm75b] = {
182
+ .default_resolution = 11,
183
+ .default_sample_time = MSEC_PER_SEC / 10,
184
+ },
185
+ [max6625] = {
186
+ .default_resolution = 9,
187
+ .default_sample_time = MSEC_PER_SEC / 7,
188
+ },
189
+ [max6626] = {
190
+ .default_resolution = 12,
191
+ .default_sample_time = MSEC_PER_SEC / 7,
192
+ .resolution_limits = 9,
193
+ },
194
+ [max31725] = {
195
+ .default_resolution = 16,
196
+ .default_sample_time = MSEC_PER_SEC / 20,
197
+ },
198
+ [tcn75] = {
199
+ .default_resolution = 9,
200
+ .default_sample_time = MSEC_PER_SEC / 18,
201
+ },
202
+ [pct2075] = {
203
+ .default_resolution = 11,
204
+ .default_sample_time = MSEC_PER_SEC / 10,
205
+ .num_sample_times = 31,
206
+ .sample_times = (unsigned int []){ 100, 200, 300, 400, 500, 600,
207
+ 700, 800, 900, 1000, 1100, 1200, 1300, 1400, 1500, 1600, 1700,
208
+ 1800, 1900, 2000, 2100, 2200, 2300, 2400, 2500, 2600, 2700,
209
+ 2800, 2900, 3000, 3100 },
210
+ },
211
+ [mcp980x] = {
212
+ .set_mask = 3 << 5, /* 12-bit mode */
213
+ .clr_mask = 1 << 7, /* not one-shot mode */
214
+ .default_resolution = 12,
215
+ .resolution_limits = 9,
216
+ .default_sample_time = 240,
217
+ .num_sample_times = 4,
218
+ .sample_times = (unsigned int []){ 30, 60, 120, 240 },
219
+ .resolutions = (u8 []) {9, 10, 11, 12 },
220
+ },
221
+ [tmp100] = {
222
+ .set_mask = 3 << 5, /* 12-bit mode */
223
+ .clr_mask = 1 << 7, /* not one-shot mode */
224
+ .default_resolution = 12,
225
+ .default_sample_time = 320,
226
+ .num_sample_times = 4,
227
+ .sample_times = (unsigned int []){ 40, 80, 160, 320 },
228
+ .resolutions = (u8 []) {9, 10, 11, 12 },
229
+ },
230
+ [tmp101] = {
231
+ .set_mask = 3 << 5, /* 12-bit mode */
232
+ .clr_mask = 1 << 7, /* not one-shot mode */
233
+ .default_resolution = 12,
234
+ .default_sample_time = 320,
235
+ .num_sample_times = 4,
236
+ .sample_times = (unsigned int []){ 40, 80, 160, 320 },
237
+ .resolutions = (u8 []) {9, 10, 11, 12 },
238
+ },
239
+ [tmp105] = {
240
+ .set_mask = 3 << 5, /* 12-bit mode */
241
+ .clr_mask = 1 << 7, /* not one-shot mode*/
242
+ .default_resolution = 12,
243
+ .default_sample_time = 220,
244
+ .num_sample_times = 4,
245
+ .sample_times = (unsigned int []){ 28, 55, 110, 220 },
246
+ .resolutions = (u8 []) {9, 10, 11, 12 },
247
+ },
248
+ [tmp112] = {
249
+ .set_mask = 3 << 5, /* 8 samples / second */
250
+ .clr_mask = 1 << 7, /* no one-shot mode*/
251
+ .default_resolution = 12,
252
+ .default_sample_time = 125,
253
+ .num_sample_times = 4,
254
+ .sample_times = (unsigned int []){ 125, 250, 1000, 4000 },
255
+ },
256
+ [tmp175] = {
257
+ .set_mask = 3 << 5, /* 12-bit mode */
258
+ .clr_mask = 1 << 7, /* not one-shot mode*/
259
+ .default_resolution = 12,
260
+ .default_sample_time = 220,
261
+ .num_sample_times = 4,
262
+ .sample_times = (unsigned int []){ 28, 55, 110, 220 },
263
+ .resolutions = (u8 []) {9, 10, 11, 12 },
264
+ },
265
+ [tmp275] = {
266
+ .set_mask = 3 << 5, /* 12-bit mode */
267
+ .clr_mask = 1 << 7, /* not one-shot mode*/
268
+ .default_resolution = 12,
269
+ .default_sample_time = 220,
270
+ .num_sample_times = 4,
271
+ .sample_times = (unsigned int []){ 28, 55, 110, 220 },
272
+ .resolutions = (u8 []) {9, 10, 11, 12 },
273
+ },
274
+ [tmp75] = {
275
+ .set_mask = 3 << 5, /* 12-bit mode */
276
+ .clr_mask = 1 << 7, /* not one-shot mode*/
277
+ .default_resolution = 12,
278
+ .default_sample_time = 220,
279
+ .num_sample_times = 4,
280
+ .sample_times = (unsigned int []){ 28, 55, 110, 220 },
281
+ .resolutions = (u8 []) {9, 10, 11, 12 },
282
+ },
283
+ [tmp75b] = { /* not one-shot mode, Conversion rate 37Hz */
284
+ .clr_mask = 1 << 7 | 3 << 5,
285
+ .default_resolution = 12,
286
+ .default_sample_time = MSEC_PER_SEC / 37,
287
+ .sample_times = (unsigned int []){ MSEC_PER_SEC / 37,
288
+ MSEC_PER_SEC / 18,
289
+ MSEC_PER_SEC / 9, MSEC_PER_SEC / 4 },
290
+ .num_sample_times = 4,
291
+ },
292
+ [tmp75c] = {
293
+ .clr_mask = 1 << 5, /*not one-shot mode*/
294
+ .default_resolution = 12,
295
+ .default_sample_time = MSEC_PER_SEC / 12,
296
+ }
297
+};
298
+
86299 static inline long lm75_reg_to_mc(s16 temp, u8 resolution)
87300 {
88301 return ((temp >> (16 - resolution)) * 1000) >> (resolution - 8);
302
+}
303
+
304
+static int lm75_write_config(struct lm75_data *data, u8 set_mask,
305
+ u8 clr_mask)
306
+{
307
+ u8 value;
308
+
309
+ clr_mask |= LM75_SHUTDOWN;
310
+ value = data->current_conf & ~clr_mask;
311
+ value |= set_mask;
312
+
313
+ if (data->current_conf != value) {
314
+ s32 err;
315
+
316
+ err = i2c_smbus_write_byte_data(data->client, LM75_REG_CONF,
317
+ value);
318
+ if (err)
319
+ return err;
320
+ data->current_conf = value;
321
+ }
322
+ return 0;
89323 }
90324
91325 static int lm75_read(struct device *dev, enum hwmon_sensor_types type,
....@@ -131,15 +365,11 @@
131365 return 0;
132366 }
133367
134
-static int lm75_write(struct device *dev, enum hwmon_sensor_types type,
135
- u32 attr, int channel, long temp)
368
+static int lm75_write_temp(struct device *dev, u32 attr, long temp)
136369 {
137370 struct lm75_data *data = dev_get_drvdata(dev);
138371 u8 resolution;
139372 int reg;
140
-
141
- if (type != hwmon_temp)
142
- return -EINVAL;
143373
144374 switch (attr) {
145375 case hwmon_temp_max:
....@@ -156,8 +386,8 @@
156386 * Resolution of limit registers is assumed to be the same as the
157387 * temperature input register resolution unless given explicitly.
158388 */
159
- if (data->resolution_limits)
160
- resolution = data->resolution_limits;
389
+ if (data->params->resolution_limits)
390
+ resolution = data->params->resolution_limits;
161391 else
162392 resolution = data->resolution;
163393
....@@ -168,23 +398,95 @@
168398 return regmap_write(data->regmap, reg, (u16)temp);
169399 }
170400
401
+static int lm75_update_interval(struct device *dev, long val)
402
+{
403
+ struct lm75_data *data = dev_get_drvdata(dev);
404
+ unsigned int reg;
405
+ u8 index;
406
+ s32 err;
407
+
408
+ index = find_closest(val, data->params->sample_times,
409
+ (int)data->params->num_sample_times);
410
+
411
+ switch (data->kind) {
412
+ default:
413
+ err = lm75_write_config(data, lm75_sample_set_masks[index],
414
+ LM75_SAMPLE_CLEAR_MASK);
415
+ if (err)
416
+ return err;
417
+
418
+ data->sample_time = data->params->sample_times[index];
419
+ if (data->params->resolutions)
420
+ data->resolution = data->params->resolutions[index];
421
+ break;
422
+ case tmp112:
423
+ err = regmap_read(data->regmap, LM75_REG_CONF, &reg);
424
+ if (err < 0)
425
+ return err;
426
+ reg &= ~0x00c0;
427
+ reg |= (3 - index) << 6;
428
+ err = regmap_write(data->regmap, LM75_REG_CONF, reg);
429
+ if (err < 0)
430
+ return err;
431
+ data->sample_time = data->params->sample_times[index];
432
+ break;
433
+ case pct2075:
434
+ err = i2c_smbus_write_byte_data(data->client, PCT2075_REG_IDLE,
435
+ index + 1);
436
+ if (err)
437
+ return err;
438
+ data->sample_time = data->params->sample_times[index];
439
+ break;
440
+ }
441
+ return 0;
442
+}
443
+
444
+static int lm75_write_chip(struct device *dev, u32 attr, long val)
445
+{
446
+ switch (attr) {
447
+ case hwmon_chip_update_interval:
448
+ return lm75_update_interval(dev, val);
449
+ default:
450
+ return -EINVAL;
451
+ }
452
+ return 0;
453
+}
454
+
455
+static int lm75_write(struct device *dev, enum hwmon_sensor_types type,
456
+ u32 attr, int channel, long val)
457
+{
458
+ switch (type) {
459
+ case hwmon_chip:
460
+ return lm75_write_chip(dev, attr, val);
461
+ case hwmon_temp:
462
+ return lm75_write_temp(dev, attr, val);
463
+ default:
464
+ return -EINVAL;
465
+ }
466
+ return 0;
467
+}
468
+
171469 static umode_t lm75_is_visible(const void *data, enum hwmon_sensor_types type,
172470 u32 attr, int channel)
173471 {
472
+ const struct lm75_data *config_data = data;
473
+
174474 switch (type) {
175475 case hwmon_chip:
176476 switch (attr) {
177477 case hwmon_chip_update_interval:
178
- return S_IRUGO;
478
+ if (config_data->params->num_sample_times > 1)
479
+ return 0644;
480
+ return 0444;
179481 }
180482 break;
181483 case hwmon_temp:
182484 switch (attr) {
183485 case hwmon_temp_input:
184
- return S_IRUGO;
486
+ return 0444;
185487 case hwmon_temp_max:
186488 case hwmon_temp_max_hyst:
187
- return S_IRUGO | S_IWUSR;
489
+ return 0644;
188490 }
189491 break;
190492 default:
....@@ -193,35 +495,11 @@
193495 return 0;
194496 }
195497
196
-/*-----------------------------------------------------------------------*/
197
-
198
-/* device probe and removal */
199
-
200
-/* chip configuration */
201
-
202
-static const u32 lm75_chip_config[] = {
203
- HWMON_C_REGISTER_TZ | HWMON_C_UPDATE_INTERVAL,
204
- 0
205
-};
206
-
207
-static const struct hwmon_channel_info lm75_chip = {
208
- .type = hwmon_chip,
209
- .config = lm75_chip_config,
210
-};
211
-
212
-static const u32 lm75_temp_config[] = {
213
- HWMON_T_INPUT | HWMON_T_MAX | HWMON_T_MAX_HYST,
214
- 0
215
-};
216
-
217
-static const struct hwmon_channel_info lm75_temp = {
218
- .type = hwmon_temp,
219
- .config = lm75_temp_config,
220
-};
221
-
222498 static const struct hwmon_channel_info *lm75_info[] = {
223
- &lm75_chip,
224
- &lm75_temp,
499
+ HWMON_CHANNEL_INFO(chip,
500
+ HWMON_C_REGISTER_TZ | HWMON_C_UPDATE_INTERVAL),
501
+ HWMON_CHANNEL_INFO(temp,
502
+ HWMON_T_INPUT | HWMON_T_MAX | HWMON_T_MAX_HYST),
225503 NULL
226504 };
227505
....@@ -243,19 +521,27 @@
243521
244522 static bool lm75_is_volatile_reg(struct device *dev, unsigned int reg)
245523 {
246
- return reg == LM75_REG_TEMP;
524
+ return reg == LM75_REG_TEMP || reg == LM75_REG_CONF;
247525 }
248526
249527 static const struct regmap_config lm75_regmap_config = {
250528 .reg_bits = 8,
251529 .val_bits = 16,
252
- .max_register = LM75_REG_MAX,
530
+ .max_register = PCT2075_REG_IDLE,
253531 .writeable_reg = lm75_is_writeable_reg,
254532 .volatile_reg = lm75_is_volatile_reg,
255533 .val_format_endian = REGMAP_ENDIAN_BIG,
256534 .cache_type = REGCACHE_RBTREE,
257
- .use_single_rw = true,
535
+ .use_single_read = true,
536
+ .use_single_write = true,
258537 };
538
+
539
+static void lm75_disable_regulator(void *data)
540
+{
541
+ struct lm75_data *lm75 = data;
542
+
543
+ regulator_disable(lm75->vs);
544
+}
259545
260546 static void lm75_remove(void *data)
261547 {
....@@ -265,21 +551,20 @@
265551 i2c_smbus_write_byte_data(client, LM75_REG_CONF, lm75->orig_conf);
266552 }
267553
268
-static int
269
-lm75_probe(struct i2c_client *client, const struct i2c_device_id *id)
554
+static const struct i2c_device_id lm75_ids[];
555
+
556
+static int lm75_probe(struct i2c_client *client)
270557 {
271558 struct device *dev = &client->dev;
272559 struct device *hwmon_dev;
273560 struct lm75_data *data;
274561 int status, err;
275
- u8 set_mask, clr_mask;
276
- int new;
277562 enum lm75_type kind;
278563
279564 if (client->dev.of_node)
280565 kind = (enum lm75_type)of_device_get_match_data(&client->dev);
281566 else
282
- kind = id->driver_data;
567
+ kind = i2c_match_id(lm75_ids, client)->driver_data;
283568
284569 if (!i2c_check_functionality(client->adapter,
285570 I2C_FUNC_SMBUS_BYTE_DATA | I2C_FUNC_SMBUS_WORD_DATA))
....@@ -290,6 +575,11 @@
290575 return -ENOMEM;
291576
292577 data->client = client;
578
+ data->kind = kind;
579
+
580
+ data->vs = devm_regulator_get(dev, "vs");
581
+ if (IS_ERR(data->vs))
582
+ return PTR_ERR(data->vs);
293583
294584 data->regmap = devm_regmap_init_i2c(client, &lm75_regmap_config);
295585 if (IS_ERR(data->regmap))
....@@ -298,100 +588,41 @@
298588 /* Set to LM75 resolution (9 bits, 1/2 degree C) and range.
299589 * Then tweak to be more precise when appropriate.
300590 */
301
- set_mask = 0;
302
- clr_mask = LM75_SHUTDOWN; /* continuous conversions */
303591
304
- switch (kind) {
305
- case adt75:
306
- clr_mask |= 1 << 5; /* not one-shot mode */
307
- data->resolution = 12;
308
- data->sample_time = MSEC_PER_SEC / 8;
309
- break;
310
- case ds1775:
311
- case ds75:
312
- case stds75:
313
- clr_mask |= 3 << 5;
314
- set_mask |= 2 << 5; /* 11-bit mode */
315
- data->resolution = 11;
316
- data->sample_time = MSEC_PER_SEC;
317
- break;
318
- case ds7505:
319
- set_mask |= 3 << 5; /* 12-bit mode */
320
- data->resolution = 12;
321
- data->sample_time = MSEC_PER_SEC / 4;
322
- break;
323
- case g751:
324
- case lm75:
325
- case lm75a:
326
- data->resolution = 9;
327
- data->sample_time = MSEC_PER_SEC / 2;
328
- break;
329
- case lm75b:
330
- data->resolution = 11;
331
- data->sample_time = MSEC_PER_SEC / 4;
332
- break;
333
- case max6625:
334
- data->resolution = 9;
335
- data->sample_time = MSEC_PER_SEC / 4;
336
- break;
337
- case max6626:
338
- data->resolution = 12;
339
- data->resolution_limits = 9;
340
- data->sample_time = MSEC_PER_SEC / 4;
341
- break;
342
- case tcn75:
343
- data->resolution = 9;
344
- data->sample_time = MSEC_PER_SEC / 8;
345
- break;
346
- case mcp980x:
347
- data->resolution_limits = 9;
348
- /* fall through */
349
- case tmp100:
350
- case tmp101:
351
- set_mask |= 3 << 5; /* 12-bit mode */
352
- data->resolution = 12;
353
- data->sample_time = MSEC_PER_SEC;
354
- clr_mask |= 1 << 7; /* not one-shot mode */
355
- break;
356
- case tmp112:
357
- set_mask |= 3 << 5; /* 12-bit mode */
358
- clr_mask |= 1 << 7; /* not one-shot mode */
359
- data->resolution = 12;
360
- data->sample_time = MSEC_PER_SEC / 4;
361
- break;
362
- case tmp105:
363
- case tmp175:
364
- case tmp275:
365
- case tmp75:
366
- set_mask |= 3 << 5; /* 12-bit mode */
367
- clr_mask |= 1 << 7; /* not one-shot mode */
368
- data->resolution = 12;
369
- data->sample_time = MSEC_PER_SEC / 2;
370
- break;
371
- case tmp75c:
372
- clr_mask |= 1 << 5; /* not one-shot mode */
373
- data->resolution = 12;
374
- data->sample_time = MSEC_PER_SEC / 4;
375
- break;
592
+ data->params = &device_params[data->kind];
593
+
594
+ /* Save default sample time and resolution*/
595
+ data->sample_time = data->params->default_sample_time;
596
+ data->resolution = data->params->default_resolution;
597
+
598
+ /* Enable the power */
599
+ err = regulator_enable(data->vs);
600
+ if (err) {
601
+ dev_err(dev, "failed to enable regulator: %d\n", err);
602
+ return err;
376603 }
377604
378
- /* configure as specified */
605
+ err = devm_add_action_or_reset(dev, lm75_disable_regulator, data);
606
+ if (err)
607
+ return err;
608
+
609
+ /* Cache original configuration */
379610 status = i2c_smbus_read_byte_data(client, LM75_REG_CONF);
380611 if (status < 0) {
381612 dev_dbg(dev, "Can't read config? %d\n", status);
382613 return status;
383614 }
384615 data->orig_conf = status;
385
- new = status & ~clr_mask;
386
- new |= set_mask;
387
- if (status != new)
388
- i2c_smbus_write_byte_data(client, LM75_REG_CONF, new);
616
+ data->current_conf = status;
617
+
618
+ err = lm75_write_config(data, data->params->set_mask,
619
+ data->params->clr_mask);
620
+ if (err)
621
+ return err;
389622
390623 err = devm_add_action_or_reset(dev, lm75_remove, data);
391624 if (err)
392625 return err;
393
-
394
- dev_dbg(dev, "Config %02x\n", new);
395626
396627 hwmon_dev = devm_hwmon_device_register_with_info(dev, client->name,
397628 data, &lm75_chip_info,
....@@ -415,8 +646,12 @@
415646 { "lm75b", lm75b, },
416647 { "max6625", max6625, },
417648 { "max6626", max6626, },
649
+ { "max31725", max31725, },
650
+ { "max31726", max31725, },
418651 { "mcp980x", mcp980x, },
652
+ { "pct2075", pct2075, },
419653 { "stds75", stds75, },
654
+ { "stlm75", stlm75, },
420655 { "tcn75", tcn75, },
421656 { "tmp100", tmp100, },
422657 { "tmp101", tmp101, },
....@@ -425,12 +660,13 @@
425660 { "tmp175", tmp175, },
426661 { "tmp275", tmp275, },
427662 { "tmp75", tmp75, },
663
+ { "tmp75b", tmp75b, },
428664 { "tmp75c", tmp75c, },
429665 { /* LIST END */ }
430666 };
431667 MODULE_DEVICE_TABLE(i2c, lm75_ids);
432668
433
-static const struct of_device_id lm75_of_match[] = {
669
+static const struct of_device_id __maybe_unused lm75_of_match[] = {
434670 {
435671 .compatible = "adi,adt75",
436672 .data = (void *)adt75
....@@ -472,12 +708,28 @@
472708 .data = (void *)max6626
473709 },
474710 {
711
+ .compatible = "maxim,max31725",
712
+ .data = (void *)max31725
713
+ },
714
+ {
715
+ .compatible = "maxim,max31726",
716
+ .data = (void *)max31725
717
+ },
718
+ {
475719 .compatible = "maxim,mcp980x",
476720 .data = (void *)mcp980x
477721 },
478722 {
723
+ .compatible = "nxp,pct2075",
724
+ .data = (void *)pct2075
725
+ },
726
+ {
479727 .compatible = "st,stds75",
480728 .data = (void *)stds75
729
+ },
730
+ {
731
+ .compatible = "st,stlm75",
732
+ .data = (void *)stlm75
481733 },
482734 {
483735 .compatible = "microchip,tcn75",
....@@ -510,6 +762,10 @@
510762 {
511763 .compatible = "ti,tmp75",
512764 .data = (void *)tmp75
765
+ },
766
+ {
767
+ .compatible = "ti,tmp75b",
768
+ .data = (void *)tmp75b
513769 },
514770 {
515771 .compatible = "ti,tmp75c",
....@@ -566,8 +822,10 @@
566822
567823 /* First check for LM75A */
568824 if (i2c_smbus_read_byte_data(new_client, 7) == LM75A_ID) {
569
- /* LM75A returns 0xff on unused registers so
570
- just to be sure we check for that too. */
825
+ /*
826
+ * LM75A returns 0xff on unused registers so
827
+ * just to be sure we check for that too.
828
+ */
571829 if (i2c_smbus_read_byte_data(new_client, 4) != 0xff
572830 || i2c_smbus_read_byte_data(new_client, 5) != 0xff
573831 || i2c_smbus_read_byte_data(new_client, 6) != 0xff)
....@@ -618,6 +876,7 @@
618876 {
619877 int status;
620878 struct i2c_client *client = to_i2c_client(dev);
879
+
621880 status = i2c_smbus_read_byte_data(client, LM75_REG_CONF);
622881 if (status < 0) {
623882 dev_dbg(&client->dev, "Can't read config? %d\n", status);
....@@ -632,6 +891,7 @@
632891 {
633892 int status;
634893 struct i2c_client *client = to_i2c_client(dev);
894
+
635895 status = i2c_smbus_read_byte_data(client, LM75_REG_CONF);
636896 if (status < 0) {
637897 dev_dbg(&client->dev, "Can't read config? %d\n", status);
....@@ -658,7 +918,7 @@
658918 .of_match_table = of_match_ptr(lm75_of_match),
659919 .pm = LM75_DEV_PM_OPS,
660920 },
661
- .probe = lm75_probe,
921
+ .probe_new = lm75_probe,
662922 .id_table = lm75_ids,
663923 .detect = lm75_detect,
664924 .address_list = normal_i2c,