.. | .. |
---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-or-later |
---|
1 | 2 | /* |
---|
2 | 3 | * lm75.c - Part of lm_sensors, Linux kernel modules for hardware |
---|
3 | 4 | * monitoring |
---|
4 | 5 | * 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. |
---|
19 | 6 | */ |
---|
20 | 7 | |
---|
21 | 8 | #include <linux/module.h> |
---|
.. | .. |
---|
29 | 16 | #include <linux/of_device.h> |
---|
30 | 17 | #include <linux/of.h> |
---|
31 | 18 | #include <linux/regmap.h> |
---|
| 19 | +#include <linux/util_macros.h> |
---|
| 20 | +#include <linux/regulator/consumer.h> |
---|
32 | 21 | #include "lm75.h" |
---|
33 | | - |
---|
34 | 22 | |
---|
35 | 23 | /* |
---|
36 | 24 | * This driver handles the LM75 and compatible digital temperature sensors. |
---|
.. | .. |
---|
47 | 35 | lm75b, |
---|
48 | 36 | max6625, |
---|
49 | 37 | max6626, |
---|
| 38 | + max31725, |
---|
50 | 39 | mcp980x, |
---|
| 40 | + pct2075, |
---|
51 | 41 | stds75, |
---|
| 42 | + stlm75, |
---|
52 | 43 | tcn75, |
---|
53 | 44 | tmp100, |
---|
54 | 45 | tmp101, |
---|
.. | .. |
---|
57 | 48 | tmp175, |
---|
58 | 49 | tmp275, |
---|
59 | 50 | tmp75, |
---|
| 51 | + tmp75b, |
---|
60 | 52 | 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; |
---|
61 | 88 | }; |
---|
62 | 89 | |
---|
63 | 90 | /* Addresses scanned */ |
---|
64 | 91 | static const unsigned short normal_i2c[] = { 0x48, 0x49, 0x4a, 0x4b, 0x4c, |
---|
65 | 92 | 0x4d, 0x4e, 0x4f, I2C_CLIENT_END }; |
---|
66 | 93 | |
---|
67 | | - |
---|
68 | 94 | /* The LM75 registers */ |
---|
69 | 95 | #define LM75_REG_TEMP 0x00 |
---|
70 | 96 | #define LM75_REG_CONF 0x01 |
---|
71 | 97 | #define LM75_REG_HYST 0x02 |
---|
72 | 98 | #define LM75_REG_MAX 0x03 |
---|
| 99 | +#define PCT2075_REG_IDLE 0x04 |
---|
73 | 100 | |
---|
74 | 101 | /* Each client has this additional data */ |
---|
75 | 102 | 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; |
---|
82 | 112 | }; |
---|
83 | 113 | |
---|
84 | 114 | /*-----------------------------------------------------------------------*/ |
---|
85 | 115 | |
---|
| 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 | + |
---|
86 | 299 | static inline long lm75_reg_to_mc(s16 temp, u8 resolution) |
---|
87 | 300 | { |
---|
88 | 301 | 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; |
---|
89 | 323 | } |
---|
90 | 324 | |
---|
91 | 325 | static int lm75_read(struct device *dev, enum hwmon_sensor_types type, |
---|
.. | .. |
---|
131 | 365 | return 0; |
---|
132 | 366 | } |
---|
133 | 367 | |
---|
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) |
---|
136 | 369 | { |
---|
137 | 370 | struct lm75_data *data = dev_get_drvdata(dev); |
---|
138 | 371 | u8 resolution; |
---|
139 | 372 | int reg; |
---|
140 | | - |
---|
141 | | - if (type != hwmon_temp) |
---|
142 | | - return -EINVAL; |
---|
143 | 373 | |
---|
144 | 374 | switch (attr) { |
---|
145 | 375 | case hwmon_temp_max: |
---|
.. | .. |
---|
156 | 386 | * Resolution of limit registers is assumed to be the same as the |
---|
157 | 387 | * temperature input register resolution unless given explicitly. |
---|
158 | 388 | */ |
---|
159 | | - if (data->resolution_limits) |
---|
160 | | - resolution = data->resolution_limits; |
---|
| 389 | + if (data->params->resolution_limits) |
---|
| 390 | + resolution = data->params->resolution_limits; |
---|
161 | 391 | else |
---|
162 | 392 | resolution = data->resolution; |
---|
163 | 393 | |
---|
.. | .. |
---|
168 | 398 | return regmap_write(data->regmap, reg, (u16)temp); |
---|
169 | 399 | } |
---|
170 | 400 | |
---|
| 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, ®); |
---|
| 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 | + |
---|
171 | 469 | static umode_t lm75_is_visible(const void *data, enum hwmon_sensor_types type, |
---|
172 | 470 | u32 attr, int channel) |
---|
173 | 471 | { |
---|
| 472 | + const struct lm75_data *config_data = data; |
---|
| 473 | + |
---|
174 | 474 | switch (type) { |
---|
175 | 475 | case hwmon_chip: |
---|
176 | 476 | switch (attr) { |
---|
177 | 477 | case hwmon_chip_update_interval: |
---|
178 | | - return S_IRUGO; |
---|
| 478 | + if (config_data->params->num_sample_times > 1) |
---|
| 479 | + return 0644; |
---|
| 480 | + return 0444; |
---|
179 | 481 | } |
---|
180 | 482 | break; |
---|
181 | 483 | case hwmon_temp: |
---|
182 | 484 | switch (attr) { |
---|
183 | 485 | case hwmon_temp_input: |
---|
184 | | - return S_IRUGO; |
---|
| 486 | + return 0444; |
---|
185 | 487 | case hwmon_temp_max: |
---|
186 | 488 | case hwmon_temp_max_hyst: |
---|
187 | | - return S_IRUGO | S_IWUSR; |
---|
| 489 | + return 0644; |
---|
188 | 490 | } |
---|
189 | 491 | break; |
---|
190 | 492 | default: |
---|
.. | .. |
---|
193 | 495 | return 0; |
---|
194 | 496 | } |
---|
195 | 497 | |
---|
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 | | - |
---|
222 | 498 | 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), |
---|
225 | 503 | NULL |
---|
226 | 504 | }; |
---|
227 | 505 | |
---|
.. | .. |
---|
243 | 521 | |
---|
244 | 522 | static bool lm75_is_volatile_reg(struct device *dev, unsigned int reg) |
---|
245 | 523 | { |
---|
246 | | - return reg == LM75_REG_TEMP; |
---|
| 524 | + return reg == LM75_REG_TEMP || reg == LM75_REG_CONF; |
---|
247 | 525 | } |
---|
248 | 526 | |
---|
249 | 527 | static const struct regmap_config lm75_regmap_config = { |
---|
250 | 528 | .reg_bits = 8, |
---|
251 | 529 | .val_bits = 16, |
---|
252 | | - .max_register = LM75_REG_MAX, |
---|
| 530 | + .max_register = PCT2075_REG_IDLE, |
---|
253 | 531 | .writeable_reg = lm75_is_writeable_reg, |
---|
254 | 532 | .volatile_reg = lm75_is_volatile_reg, |
---|
255 | 533 | .val_format_endian = REGMAP_ENDIAN_BIG, |
---|
256 | 534 | .cache_type = REGCACHE_RBTREE, |
---|
257 | | - .use_single_rw = true, |
---|
| 535 | + .use_single_read = true, |
---|
| 536 | + .use_single_write = true, |
---|
258 | 537 | }; |
---|
| 538 | + |
---|
| 539 | +static void lm75_disable_regulator(void *data) |
---|
| 540 | +{ |
---|
| 541 | + struct lm75_data *lm75 = data; |
---|
| 542 | + |
---|
| 543 | + regulator_disable(lm75->vs); |
---|
| 544 | +} |
---|
259 | 545 | |
---|
260 | 546 | static void lm75_remove(void *data) |
---|
261 | 547 | { |
---|
.. | .. |
---|
265 | 551 | i2c_smbus_write_byte_data(client, LM75_REG_CONF, lm75->orig_conf); |
---|
266 | 552 | } |
---|
267 | 553 | |
---|
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) |
---|
270 | 557 | { |
---|
271 | 558 | struct device *dev = &client->dev; |
---|
272 | 559 | struct device *hwmon_dev; |
---|
273 | 560 | struct lm75_data *data; |
---|
274 | 561 | int status, err; |
---|
275 | | - u8 set_mask, clr_mask; |
---|
276 | | - int new; |
---|
277 | 562 | enum lm75_type kind; |
---|
278 | 563 | |
---|
279 | 564 | if (client->dev.of_node) |
---|
280 | 565 | kind = (enum lm75_type)of_device_get_match_data(&client->dev); |
---|
281 | 566 | else |
---|
282 | | - kind = id->driver_data; |
---|
| 567 | + kind = i2c_match_id(lm75_ids, client)->driver_data; |
---|
283 | 568 | |
---|
284 | 569 | if (!i2c_check_functionality(client->adapter, |
---|
285 | 570 | I2C_FUNC_SMBUS_BYTE_DATA | I2C_FUNC_SMBUS_WORD_DATA)) |
---|
.. | .. |
---|
290 | 575 | return -ENOMEM; |
---|
291 | 576 | |
---|
292 | 577 | 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); |
---|
293 | 583 | |
---|
294 | 584 | data->regmap = devm_regmap_init_i2c(client, &lm75_regmap_config); |
---|
295 | 585 | if (IS_ERR(data->regmap)) |
---|
.. | .. |
---|
298 | 588 | /* Set to LM75 resolution (9 bits, 1/2 degree C) and range. |
---|
299 | 589 | * Then tweak to be more precise when appropriate. |
---|
300 | 590 | */ |
---|
301 | | - set_mask = 0; |
---|
302 | | - clr_mask = LM75_SHUTDOWN; /* continuous conversions */ |
---|
303 | 591 | |
---|
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; |
---|
376 | 603 | } |
---|
377 | 604 | |
---|
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 */ |
---|
379 | 610 | status = i2c_smbus_read_byte_data(client, LM75_REG_CONF); |
---|
380 | 611 | if (status < 0) { |
---|
381 | 612 | dev_dbg(dev, "Can't read config? %d\n", status); |
---|
382 | 613 | return status; |
---|
383 | 614 | } |
---|
384 | 615 | 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; |
---|
389 | 622 | |
---|
390 | 623 | err = devm_add_action_or_reset(dev, lm75_remove, data); |
---|
391 | 624 | if (err) |
---|
392 | 625 | return err; |
---|
393 | | - |
---|
394 | | - dev_dbg(dev, "Config %02x\n", new); |
---|
395 | 626 | |
---|
396 | 627 | hwmon_dev = devm_hwmon_device_register_with_info(dev, client->name, |
---|
397 | 628 | data, &lm75_chip_info, |
---|
.. | .. |
---|
415 | 646 | { "lm75b", lm75b, }, |
---|
416 | 647 | { "max6625", max6625, }, |
---|
417 | 648 | { "max6626", max6626, }, |
---|
| 649 | + { "max31725", max31725, }, |
---|
| 650 | + { "max31726", max31725, }, |
---|
418 | 651 | { "mcp980x", mcp980x, }, |
---|
| 652 | + { "pct2075", pct2075, }, |
---|
419 | 653 | { "stds75", stds75, }, |
---|
| 654 | + { "stlm75", stlm75, }, |
---|
420 | 655 | { "tcn75", tcn75, }, |
---|
421 | 656 | { "tmp100", tmp100, }, |
---|
422 | 657 | { "tmp101", tmp101, }, |
---|
.. | .. |
---|
425 | 660 | { "tmp175", tmp175, }, |
---|
426 | 661 | { "tmp275", tmp275, }, |
---|
427 | 662 | { "tmp75", tmp75, }, |
---|
| 663 | + { "tmp75b", tmp75b, }, |
---|
428 | 664 | { "tmp75c", tmp75c, }, |
---|
429 | 665 | { /* LIST END */ } |
---|
430 | 666 | }; |
---|
431 | 667 | MODULE_DEVICE_TABLE(i2c, lm75_ids); |
---|
432 | 668 | |
---|
433 | | -static const struct of_device_id lm75_of_match[] = { |
---|
| 669 | +static const struct of_device_id __maybe_unused lm75_of_match[] = { |
---|
434 | 670 | { |
---|
435 | 671 | .compatible = "adi,adt75", |
---|
436 | 672 | .data = (void *)adt75 |
---|
.. | .. |
---|
472 | 708 | .data = (void *)max6626 |
---|
473 | 709 | }, |
---|
474 | 710 | { |
---|
| 711 | + .compatible = "maxim,max31725", |
---|
| 712 | + .data = (void *)max31725 |
---|
| 713 | + }, |
---|
| 714 | + { |
---|
| 715 | + .compatible = "maxim,max31726", |
---|
| 716 | + .data = (void *)max31725 |
---|
| 717 | + }, |
---|
| 718 | + { |
---|
475 | 719 | .compatible = "maxim,mcp980x", |
---|
476 | 720 | .data = (void *)mcp980x |
---|
477 | 721 | }, |
---|
478 | 722 | { |
---|
| 723 | + .compatible = "nxp,pct2075", |
---|
| 724 | + .data = (void *)pct2075 |
---|
| 725 | + }, |
---|
| 726 | + { |
---|
479 | 727 | .compatible = "st,stds75", |
---|
480 | 728 | .data = (void *)stds75 |
---|
| 729 | + }, |
---|
| 730 | + { |
---|
| 731 | + .compatible = "st,stlm75", |
---|
| 732 | + .data = (void *)stlm75 |
---|
481 | 733 | }, |
---|
482 | 734 | { |
---|
483 | 735 | .compatible = "microchip,tcn75", |
---|
.. | .. |
---|
510 | 762 | { |
---|
511 | 763 | .compatible = "ti,tmp75", |
---|
512 | 764 | .data = (void *)tmp75 |
---|
| 765 | + }, |
---|
| 766 | + { |
---|
| 767 | + .compatible = "ti,tmp75b", |
---|
| 768 | + .data = (void *)tmp75b |
---|
513 | 769 | }, |
---|
514 | 770 | { |
---|
515 | 771 | .compatible = "ti,tmp75c", |
---|
.. | .. |
---|
566 | 822 | |
---|
567 | 823 | /* First check for LM75A */ |
---|
568 | 824 | 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 | + */ |
---|
571 | 829 | if (i2c_smbus_read_byte_data(new_client, 4) != 0xff |
---|
572 | 830 | || i2c_smbus_read_byte_data(new_client, 5) != 0xff |
---|
573 | 831 | || i2c_smbus_read_byte_data(new_client, 6) != 0xff) |
---|
.. | .. |
---|
618 | 876 | { |
---|
619 | 877 | int status; |
---|
620 | 878 | struct i2c_client *client = to_i2c_client(dev); |
---|
| 879 | + |
---|
621 | 880 | status = i2c_smbus_read_byte_data(client, LM75_REG_CONF); |
---|
622 | 881 | if (status < 0) { |
---|
623 | 882 | dev_dbg(&client->dev, "Can't read config? %d\n", status); |
---|
.. | .. |
---|
632 | 891 | { |
---|
633 | 892 | int status; |
---|
634 | 893 | struct i2c_client *client = to_i2c_client(dev); |
---|
| 894 | + |
---|
635 | 895 | status = i2c_smbus_read_byte_data(client, LM75_REG_CONF); |
---|
636 | 896 | if (status < 0) { |
---|
637 | 897 | dev_dbg(&client->dev, "Can't read config? %d\n", status); |
---|
.. | .. |
---|
658 | 918 | .of_match_table = of_match_ptr(lm75_of_match), |
---|
659 | 919 | .pm = LM75_DEV_PM_OPS, |
---|
660 | 920 | }, |
---|
661 | | - .probe = lm75_probe, |
---|
| 921 | + .probe_new = lm75_probe, |
---|
662 | 922 | .id_table = lm75_ids, |
---|
663 | 923 | .detect = lm75_detect, |
---|
664 | 924 | .address_list = normal_i2c, |
---|