diff options
author | Michael Walle <michael@walle.cc> | 2016-12-15 12:38:17 -0500 |
---|---|---|
committer | Guenter Roeck <linux@roeck-us.net> | 2017-01-02 13:19:45 -0500 |
commit | 9bb2d47d744dcb33ca896a023ee8fffc0bdbb3cf (patch) | |
tree | 4dbf6cab643b76c77d8c4f7c6c681ef3557785d2 /drivers/hwmon/adt7411.c | |
parent | 5da99328f2595d2b376fcd2a87974b658f396da8 (diff) |
hwmon: (adt7411) add min, max and alarm attributes
This patch adds support for the min, max and alarm attributes of the
voltage and temperature channels. Additionally, the temp2_fault attribute
is supported which indicates a fault of the external temperature diode.
Signed-off-by: Michael Walle <michael@walle.cc>
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Diffstat (limited to 'drivers/hwmon/adt7411.c')
-rw-r--r-- | drivers/hwmon/adt7411.c | 361 |
1 files changed, 316 insertions, 45 deletions
diff --git a/drivers/hwmon/adt7411.c b/drivers/hwmon/adt7411.c index bdeaece9641d..b939f8a115ba 100644 --- a/drivers/hwmon/adt7411.c +++ b/drivers/hwmon/adt7411.c | |||
@@ -21,6 +21,21 @@ | |||
21 | #include <linux/hwmon-sysfs.h> | 21 | #include <linux/hwmon-sysfs.h> |
22 | #include <linux/slab.h> | 22 | #include <linux/slab.h> |
23 | 23 | ||
24 | #define ADT7411_REG_STAT_1 0x00 | ||
25 | #define ADT7411_STAT_1_INT_TEMP_HIGH BIT(0) | ||
26 | #define ADT7411_STAT_1_INT_TEMP_LOW BIT(1) | ||
27 | #define ADT7411_STAT_1_EXT_TEMP_HIGH_AIN1 BIT(2) | ||
28 | #define ADT7411_STAT_1_EXT_TEMP_LOW BIT(3) | ||
29 | #define ADT7411_STAT_1_EXT_TEMP_FAULT BIT(4) | ||
30 | #define ADT7411_STAT_1_AIN2 BIT(5) | ||
31 | #define ADT7411_STAT_1_AIN3 BIT(6) | ||
32 | #define ADT7411_STAT_1_AIN4 BIT(7) | ||
33 | #define ADT7411_REG_STAT_2 0x01 | ||
34 | #define ADT7411_STAT_2_AIN5 BIT(0) | ||
35 | #define ADT7411_STAT_2_AIN6 BIT(1) | ||
36 | #define ADT7411_STAT_2_AIN7 BIT(2) | ||
37 | #define ADT7411_STAT_2_AIN8 BIT(3) | ||
38 | #define ADT7411_STAT_2_VDD BIT(4) | ||
24 | #define ADT7411_REG_INT_TEMP_VDD_LSB 0x03 | 39 | #define ADT7411_REG_INT_TEMP_VDD_LSB 0x03 |
25 | #define ADT7411_REG_EXT_TEMP_AIN14_LSB 0x04 | 40 | #define ADT7411_REG_EXT_TEMP_AIN14_LSB 0x04 |
26 | #define ADT7411_REG_VDD_MSB 0x06 | 41 | #define ADT7411_REG_VDD_MSB 0x06 |
@@ -28,20 +43,31 @@ | |||
28 | #define ADT7411_REG_EXT_TEMP_AIN1_MSB 0x08 | 43 | #define ADT7411_REG_EXT_TEMP_AIN1_MSB 0x08 |
29 | 44 | ||
30 | #define ADT7411_REG_CFG1 0x18 | 45 | #define ADT7411_REG_CFG1 0x18 |
31 | #define ADT7411_CFG1_START_MONITOR (1 << 0) | 46 | #define ADT7411_CFG1_START_MONITOR BIT(0) |
32 | #define ADT7411_CFG1_RESERVED_BIT1 (1 << 1) | 47 | #define ADT7411_CFG1_RESERVED_BIT1 BIT(1) |
33 | #define ADT7411_CFG1_EXT_TDM (1 << 2) | 48 | #define ADT7411_CFG1_EXT_TDM BIT(2) |
34 | #define ADT7411_CFG1_RESERVED_BIT3 (1 << 3) | 49 | #define ADT7411_CFG1_RESERVED_BIT3 BIT(3) |
35 | 50 | ||
36 | #define ADT7411_REG_CFG2 0x19 | 51 | #define ADT7411_REG_CFG2 0x19 |
37 | #define ADT7411_CFG2_DISABLE_AVG (1 << 5) | 52 | #define ADT7411_CFG2_DISABLE_AVG BIT(5) |
38 | 53 | ||
39 | #define ADT7411_REG_CFG3 0x1a | 54 | #define ADT7411_REG_CFG3 0x1a |
40 | #define ADT7411_CFG3_ADC_CLK_225 (1 << 0) | 55 | #define ADT7411_CFG3_ADC_CLK_225 BIT(0) |
41 | #define ADT7411_CFG3_RESERVED_BIT1 (1 << 1) | 56 | #define ADT7411_CFG3_RESERVED_BIT1 BIT(1) |
42 | #define ADT7411_CFG3_RESERVED_BIT2 (1 << 2) | 57 | #define ADT7411_CFG3_RESERVED_BIT2 BIT(2) |
43 | #define ADT7411_CFG3_RESERVED_BIT3 (1 << 3) | 58 | #define ADT7411_CFG3_RESERVED_BIT3 BIT(3) |
44 | #define ADT7411_CFG3_REF_VDD (1 << 4) | 59 | #define ADT7411_CFG3_REF_VDD BIT(4) |
60 | |||
61 | #define ADT7411_REG_VDD_HIGH 0x23 | ||
62 | #define ADT7411_REG_VDD_LOW 0x24 | ||
63 | #define ADT7411_REG_TEMP_HIGH(nr) (0x25 + 2 * (nr)) | ||
64 | #define ADT7411_REG_TEMP_LOW(nr) (0x26 + 2 * (nr)) | ||
65 | #define ADT7411_REG_IN_HIGH(nr) ((nr) > 1 \ | ||
66 | ? 0x2b + 2 * ((nr)-2) \ | ||
67 | : 0x27) | ||
68 | #define ADT7411_REG_IN_LOW(nr) ((nr) > 1 \ | ||
69 | ? 0x2c + 2 * ((nr)-2) \ | ||
70 | : 0x28) | ||
45 | 71 | ||
46 | #define ADT7411_REG_DEVICE_ID 0x4d | 72 | #define ADT7411_REG_DEVICE_ID 0x4d |
47 | #define ADT7411_REG_MANUFACTURER_ID 0x4e | 73 | #define ADT7411_REG_MANUFACTURER_ID 0x4e |
@@ -51,6 +77,30 @@ | |||
51 | 77 | ||
52 | static const unsigned short normal_i2c[] = { 0x48, 0x4a, 0x4b, I2C_CLIENT_END }; | 78 | static const unsigned short normal_i2c[] = { 0x48, 0x4a, 0x4b, I2C_CLIENT_END }; |
53 | 79 | ||
80 | static const u8 adt7411_in_alarm_reg[] = { | ||
81 | ADT7411_REG_STAT_2, | ||
82 | ADT7411_REG_STAT_1, | ||
83 | ADT7411_REG_STAT_1, | ||
84 | ADT7411_REG_STAT_1, | ||
85 | ADT7411_REG_STAT_1, | ||
86 | ADT7411_REG_STAT_2, | ||
87 | ADT7411_REG_STAT_2, | ||
88 | ADT7411_REG_STAT_2, | ||
89 | ADT7411_REG_STAT_2, | ||
90 | }; | ||
91 | |||
92 | static const u8 adt7411_in_alarm_bits[] = { | ||
93 | ADT7411_STAT_2_VDD, | ||
94 | ADT7411_STAT_1_EXT_TEMP_HIGH_AIN1, | ||
95 | ADT7411_STAT_1_AIN2, | ||
96 | ADT7411_STAT_1_AIN3, | ||
97 | ADT7411_STAT_1_AIN4, | ||
98 | ADT7411_STAT_2_AIN5, | ||
99 | ADT7411_STAT_2_AIN6, | ||
100 | ADT7411_STAT_2_AIN7, | ||
101 | ADT7411_STAT_2_AIN8, | ||
102 | }; | ||
103 | |||
54 | struct adt7411_data { | 104 | struct adt7411_data { |
55 | struct mutex device_lock; /* for "atomic" device accesses */ | 105 | struct mutex device_lock; /* for "atomic" device accesses */ |
56 | struct mutex update_lock; | 106 | struct mutex update_lock; |
@@ -165,6 +215,19 @@ static struct attribute *adt7411_attrs[] = { | |||
165 | }; | 215 | }; |
166 | ATTRIBUTE_GROUPS(adt7411); | 216 | ATTRIBUTE_GROUPS(adt7411); |
167 | 217 | ||
218 | static int adt7411_read_in_alarm(struct device *dev, int channel, long *val) | ||
219 | { | ||
220 | struct adt7411_data *data = dev_get_drvdata(dev); | ||
221 | struct i2c_client *client = data->client; | ||
222 | int ret; | ||
223 | |||
224 | ret = i2c_smbus_read_byte_data(client, adt7411_in_alarm_reg[channel]); | ||
225 | if (ret < 0) | ||
226 | return ret; | ||
227 | *val = !!(ret & adt7411_in_alarm_bits[channel]); | ||
228 | return 0; | ||
229 | } | ||
230 | |||
168 | static int adt7411_read_in_vdd(struct device *dev, u32 attr, long *val) | 231 | static int adt7411_read_in_vdd(struct device *dev, u32 attr, long *val) |
169 | { | 232 | { |
170 | struct adt7411_data *data = dev_get_drvdata(dev); | 233 | struct adt7411_data *data = dev_get_drvdata(dev); |
@@ -179,32 +242,41 @@ static int adt7411_read_in_vdd(struct device *dev, u32 attr, long *val) | |||
179 | return ret; | 242 | return ret; |
180 | *val = ret * 7000 / 1024; | 243 | *val = ret * 7000 / 1024; |
181 | return 0; | 244 | return 0; |
245 | case hwmon_in_min: | ||
246 | ret = i2c_smbus_read_byte_data(client, ADT7411_REG_VDD_LOW); | ||
247 | if (ret < 0) | ||
248 | return ret; | ||
249 | *val = ret * 7000 / 256; | ||
250 | return 0; | ||
251 | case hwmon_in_max: | ||
252 | ret = i2c_smbus_read_byte_data(client, ADT7411_REG_VDD_HIGH); | ||
253 | if (ret < 0) | ||
254 | return ret; | ||
255 | *val = ret * 7000 / 256; | ||
256 | return 0; | ||
257 | case hwmon_in_alarm: | ||
258 | return adt7411_read_in_alarm(dev, 0, val); | ||
182 | default: | 259 | default: |
183 | return -EOPNOTSUPP; | 260 | return -EOPNOTSUPP; |
184 | } | 261 | } |
185 | } | 262 | } |
186 | 263 | ||
187 | static int adt7411_read_in_chan(struct device *dev, u32 attr, int channel, | 264 | static int adt7411_update_vref(struct device *dev) |
188 | long *val) | ||
189 | { | 265 | { |
190 | struct adt7411_data *data = dev_get_drvdata(dev); | 266 | struct adt7411_data *data = dev_get_drvdata(dev); |
191 | struct i2c_client *client = data->client; | 267 | struct i2c_client *client = data->client; |
268 | int val; | ||
192 | 269 | ||
193 | int ret; | ||
194 | int lsb_reg, lsb_shift; | ||
195 | int nr = channel - 1; | ||
196 | |||
197 | mutex_lock(&data->update_lock); | ||
198 | if (time_after_eq(jiffies, data->next_update)) { | 270 | if (time_after_eq(jiffies, data->next_update)) { |
199 | ret = i2c_smbus_read_byte_data(client, ADT7411_REG_CFG3); | 271 | val = i2c_smbus_read_byte_data(client, ADT7411_REG_CFG3); |
200 | if (ret < 0) | 272 | if (val < 0) |
201 | goto exit_unlock; | 273 | return val; |
202 | 274 | ||
203 | if (ret & ADT7411_CFG3_REF_VDD) { | 275 | if (val & ADT7411_CFG3_REF_VDD) { |
204 | ret = adt7411_read_in_vdd(dev, hwmon_in_input, | 276 | val = adt7411_read_in_vdd(dev, hwmon_in_input, |
205 | &data->vref_cached); | 277 | &data->vref_cached); |
206 | if (ret < 0) | 278 | if (val < 0) |
207 | goto exit_unlock; | 279 | return val; |
208 | } else { | 280 | } else { |
209 | data->vref_cached = 2250; | 281 | data->vref_cached = 2250; |
210 | } | 282 | } |
@@ -212,6 +284,24 @@ static int adt7411_read_in_chan(struct device *dev, u32 attr, int channel, | |||
212 | data->next_update = jiffies + HZ; | 284 | data->next_update = jiffies + HZ; |
213 | } | 285 | } |
214 | 286 | ||
287 | return 0; | ||
288 | } | ||
289 | |||
290 | static int adt7411_read_in_chan(struct device *dev, u32 attr, int channel, | ||
291 | long *val) | ||
292 | { | ||
293 | struct adt7411_data *data = dev_get_drvdata(dev); | ||
294 | struct i2c_client *client = data->client; | ||
295 | |||
296 | int ret; | ||
297 | int reg, lsb_reg, lsb_shift; | ||
298 | int nr = channel - 1; | ||
299 | |||
300 | mutex_lock(&data->update_lock); | ||
301 | ret = adt7411_update_vref(dev); | ||
302 | if (ret < 0) | ||
303 | goto exit_unlock; | ||
304 | |||
215 | switch (attr) { | 305 | switch (attr) { |
216 | case hwmon_in_input: | 306 | case hwmon_in_input: |
217 | lsb_reg = ADT7411_REG_EXT_TEMP_AIN14_LSB + (nr >> 2); | 307 | lsb_reg = ADT7411_REG_EXT_TEMP_AIN14_LSB + (nr >> 2); |
@@ -224,6 +314,20 @@ static int adt7411_read_in_chan(struct device *dev, u32 attr, int channel, | |||
224 | *val = ret * data->vref_cached / 1024; | 314 | *val = ret * data->vref_cached / 1024; |
225 | ret = 0; | 315 | ret = 0; |
226 | break; | 316 | break; |
317 | case hwmon_in_min: | ||
318 | case hwmon_in_max: | ||
319 | reg = (attr == hwmon_in_min) | ||
320 | ? ADT7411_REG_IN_LOW(channel) | ||
321 | : ADT7411_REG_IN_HIGH(channel); | ||
322 | ret = i2c_smbus_read_byte_data(client, reg); | ||
323 | if (ret < 0) | ||
324 | goto exit_unlock; | ||
325 | *val = ret * data->vref_cached / 256; | ||
326 | ret = 0; | ||
327 | break; | ||
328 | case hwmon_in_alarm: | ||
329 | ret = adt7411_read_in_alarm(dev, channel, val); | ||
330 | break; | ||
227 | default: | 331 | default: |
228 | ret = -EOPNOTSUPP; | 332 | ret = -EOPNOTSUPP; |
229 | break; | 333 | break; |
@@ -242,12 +346,44 @@ static int adt7411_read_in(struct device *dev, u32 attr, int channel, | |||
242 | return adt7411_read_in_chan(dev, attr, channel, val); | 346 | return adt7411_read_in_chan(dev, attr, channel, val); |
243 | } | 347 | } |
244 | 348 | ||
349 | |||
350 | static int adt7411_read_temp_alarm(struct device *dev, u32 attr, int channel, | ||
351 | long *val) | ||
352 | { | ||
353 | struct adt7411_data *data = dev_get_drvdata(dev); | ||
354 | struct i2c_client *client = data->client; | ||
355 | int ret, bit; | ||
356 | |||
357 | ret = i2c_smbus_read_byte_data(client, ADT7411_REG_STAT_1); | ||
358 | if (ret < 0) | ||
359 | return ret; | ||
360 | |||
361 | switch (attr) { | ||
362 | case hwmon_temp_min_alarm: | ||
363 | bit = channel ? ADT7411_STAT_1_EXT_TEMP_LOW | ||
364 | : ADT7411_STAT_1_INT_TEMP_LOW; | ||
365 | break; | ||
366 | case hwmon_temp_max_alarm: | ||
367 | bit = channel ? ADT7411_STAT_1_EXT_TEMP_HIGH_AIN1 | ||
368 | : ADT7411_STAT_1_INT_TEMP_HIGH; | ||
369 | break; | ||
370 | case hwmon_temp_fault: | ||
371 | bit = ADT7411_STAT_1_EXT_TEMP_FAULT; | ||
372 | break; | ||
373 | default: | ||
374 | return -EOPNOTSUPP; | ||
375 | } | ||
376 | |||
377 | *val = !!(ret & bit); | ||
378 | return 0; | ||
379 | } | ||
380 | |||
245 | static int adt7411_read_temp(struct device *dev, u32 attr, int channel, | 381 | static int adt7411_read_temp(struct device *dev, u32 attr, int channel, |
246 | long *val) | 382 | long *val) |
247 | { | 383 | { |
248 | struct adt7411_data *data = dev_get_drvdata(dev); | 384 | struct adt7411_data *data = dev_get_drvdata(dev); |
249 | struct i2c_client *client = data->client; | 385 | struct i2c_client *client = data->client; |
250 | int ret, regl, regh; | 386 | int ret, reg, regl, regh; |
251 | 387 | ||
252 | switch (attr) { | 388 | switch (attr) { |
253 | case hwmon_temp_input: | 389 | case hwmon_temp_input: |
@@ -261,6 +397,21 @@ static int adt7411_read_temp(struct device *dev, u32 attr, int channel, | |||
261 | ret = ret & 0x200 ? ret - 0x400 : ret; /* 10 bit signed */ | 397 | ret = ret & 0x200 ? ret - 0x400 : ret; /* 10 bit signed */ |
262 | *val = ret * 250; | 398 | *val = ret * 250; |
263 | return 0; | 399 | return 0; |
400 | case hwmon_temp_min: | ||
401 | case hwmon_temp_max: | ||
402 | reg = (attr == hwmon_temp_min) | ||
403 | ? ADT7411_REG_TEMP_LOW(channel) | ||
404 | : ADT7411_REG_TEMP_HIGH(channel); | ||
405 | ret = i2c_smbus_read_byte_data(client, reg); | ||
406 | if (ret < 0) | ||
407 | return ret; | ||
408 | ret = ret & 0x80 ? ret - 0x100 : ret; /* 8 bit signed */ | ||
409 | *val = ret * 1000; | ||
410 | return 0; | ||
411 | case hwmon_temp_min_alarm: | ||
412 | case hwmon_temp_max_alarm: | ||
413 | case hwmon_temp_fault: | ||
414 | return adt7411_read_temp_alarm(dev, attr, channel, val); | ||
264 | default: | 415 | default: |
265 | return -EOPNOTSUPP; | 416 | return -EOPNOTSUPP; |
266 | } | 417 | } |
@@ -279,26 +430,143 @@ static int adt7411_read(struct device *dev, enum hwmon_sensor_types type, | |||
279 | } | 430 | } |
280 | } | 431 | } |
281 | 432 | ||
433 | static int adt7411_write_in_vdd(struct device *dev, u32 attr, long val) | ||
434 | { | ||
435 | struct adt7411_data *data = dev_get_drvdata(dev); | ||
436 | struct i2c_client *client = data->client; | ||
437 | int reg; | ||
438 | |||
439 | val = clamp_val(val, 0, 255 * 7000 / 256); | ||
440 | val = DIV_ROUND_CLOSEST(val * 256, 7000); | ||
441 | |||
442 | switch (attr) { | ||
443 | case hwmon_in_min: | ||
444 | reg = ADT7411_REG_VDD_LOW; | ||
445 | break; | ||
446 | case hwmon_in_max: | ||
447 | reg = ADT7411_REG_VDD_HIGH; | ||
448 | break; | ||
449 | default: | ||
450 | return -EOPNOTSUPP; | ||
451 | } | ||
452 | |||
453 | return i2c_smbus_write_byte_data(client, reg, val); | ||
454 | } | ||
455 | |||
456 | static int adt7411_write_in_chan(struct device *dev, u32 attr, int channel, | ||
457 | long val) | ||
458 | { | ||
459 | struct adt7411_data *data = dev_get_drvdata(dev); | ||
460 | struct i2c_client *client = data->client; | ||
461 | int ret, reg; | ||
462 | |||
463 | mutex_lock(&data->update_lock); | ||
464 | ret = adt7411_update_vref(dev); | ||
465 | if (ret < 0) | ||
466 | goto exit_unlock; | ||
467 | val = clamp_val(val, 0, 255 * data->vref_cached / 256); | ||
468 | val = DIV_ROUND_CLOSEST(val * 256, data->vref_cached); | ||
469 | |||
470 | switch (attr) { | ||
471 | case hwmon_in_min: | ||
472 | reg = ADT7411_REG_IN_LOW(channel); | ||
473 | break; | ||
474 | case hwmon_in_max: | ||
475 | reg = ADT7411_REG_IN_HIGH(channel); | ||
476 | break; | ||
477 | default: | ||
478 | ret = -EOPNOTSUPP; | ||
479 | goto exit_unlock; | ||
480 | } | ||
481 | |||
482 | ret = i2c_smbus_write_byte_data(client, reg, val); | ||
483 | exit_unlock: | ||
484 | mutex_unlock(&data->update_lock); | ||
485 | return ret; | ||
486 | } | ||
487 | |||
488 | static int adt7411_write_in(struct device *dev, u32 attr, int channel, | ||
489 | long val) | ||
490 | { | ||
491 | if (channel == 0) | ||
492 | return adt7411_write_in_vdd(dev, attr, val); | ||
493 | else | ||
494 | return adt7411_write_in_chan(dev, attr, channel, val); | ||
495 | } | ||
496 | |||
497 | static int adt7411_write_temp(struct device *dev, u32 attr, int channel, | ||
498 | long val) | ||
499 | { | ||
500 | struct adt7411_data *data = dev_get_drvdata(dev); | ||
501 | struct i2c_client *client = data->client; | ||
502 | int reg; | ||
503 | |||
504 | val = clamp_val(val, -128000, 127000); | ||
505 | val = DIV_ROUND_CLOSEST(val, 1000); | ||
506 | |||
507 | switch (attr) { | ||
508 | case hwmon_temp_min: | ||
509 | reg = ADT7411_REG_TEMP_LOW(channel); | ||
510 | break; | ||
511 | case hwmon_temp_max: | ||
512 | reg = ADT7411_REG_TEMP_HIGH(channel); | ||
513 | break; | ||
514 | default: | ||
515 | return -EOPNOTSUPP; | ||
516 | } | ||
517 | |||
518 | return i2c_smbus_write_byte_data(client, reg, val); | ||
519 | } | ||
520 | |||
521 | static int adt7411_write(struct device *dev, enum hwmon_sensor_types type, | ||
522 | u32 attr, int channel, long val) | ||
523 | { | ||
524 | switch (type) { | ||
525 | case hwmon_in: | ||
526 | return adt7411_write_in(dev, attr, channel, val); | ||
527 | case hwmon_temp: | ||
528 | return adt7411_write_temp(dev, attr, channel, val); | ||
529 | default: | ||
530 | return -EOPNOTSUPP; | ||
531 | } | ||
532 | } | ||
533 | |||
282 | static umode_t adt7411_is_visible(const void *_data, | 534 | static umode_t adt7411_is_visible(const void *_data, |
283 | enum hwmon_sensor_types type, | 535 | enum hwmon_sensor_types type, |
284 | u32 attr, int channel) | 536 | u32 attr, int channel) |
285 | { | 537 | { |
286 | const struct adt7411_data *data = _data; | 538 | const struct adt7411_data *data = _data; |
539 | bool visible; | ||
287 | 540 | ||
288 | switch (type) { | 541 | switch (type) { |
289 | case hwmon_in: | 542 | case hwmon_in: |
290 | if (channel > 0 && channel < 3) | 543 | visible = channel == 0 || channel >= 3 || !data->use_ext_temp; |
291 | return data->use_ext_temp ? 0 : S_IRUGO; | 544 | switch (attr) { |
292 | else | 545 | case hwmon_in_input: |
293 | return S_IRUGO; | 546 | case hwmon_in_alarm: |
547 | return visible ? S_IRUGO : 0; | ||
548 | case hwmon_in_min: | ||
549 | case hwmon_in_max: | ||
550 | return visible ? S_IRUGO | S_IWUSR : 0; | ||
551 | } | ||
552 | break; | ||
294 | case hwmon_temp: | 553 | case hwmon_temp: |
295 | if (channel == 1) | 554 | visible = channel == 0 || data->use_ext_temp; |
296 | return data->use_ext_temp ? S_IRUGO : 0; | 555 | switch (attr) { |
297 | else | 556 | case hwmon_temp_input: |
298 | return S_IRUGO; | 557 | case hwmon_temp_min_alarm: |
558 | case hwmon_temp_max_alarm: | ||
559 | case hwmon_temp_fault: | ||
560 | return visible ? S_IRUGO : 0; | ||
561 | case hwmon_temp_min: | ||
562 | case hwmon_temp_max: | ||
563 | return visible ? S_IRUGO | S_IWUSR : 0; | ||
564 | } | ||
565 | break; | ||
299 | default: | 566 | default: |
300 | return 0; | 567 | break; |
301 | } | 568 | } |
569 | return 0; | ||
302 | } | 570 | } |
303 | 571 | ||
304 | static int adt7411_detect(struct i2c_client *client, | 572 | static int adt7411_detect(struct i2c_client *client, |
@@ -372,15 +640,15 @@ static int adt7411_init_device(struct adt7411_data *data) | |||
372 | } | 640 | } |
373 | 641 | ||
374 | static const u32 adt7411_in_config[] = { | 642 | static const u32 adt7411_in_config[] = { |
375 | HWMON_I_INPUT, | 643 | HWMON_I_INPUT | HWMON_I_MIN | HWMON_I_MAX | HWMON_I_ALARM, |
376 | HWMON_I_INPUT, | 644 | HWMON_I_INPUT | HWMON_I_MIN | HWMON_I_MAX | HWMON_I_ALARM, |
377 | HWMON_I_INPUT, | 645 | HWMON_I_INPUT | HWMON_I_MIN | HWMON_I_MAX | HWMON_I_ALARM, |
378 | HWMON_I_INPUT, | 646 | HWMON_I_INPUT | HWMON_I_MIN | HWMON_I_MAX | HWMON_I_ALARM, |
379 | HWMON_I_INPUT, | 647 | HWMON_I_INPUT | HWMON_I_MIN | HWMON_I_MAX | HWMON_I_ALARM, |
380 | HWMON_I_INPUT, | 648 | HWMON_I_INPUT | HWMON_I_MIN | HWMON_I_MAX | HWMON_I_ALARM, |
381 | HWMON_I_INPUT, | 649 | HWMON_I_INPUT | HWMON_I_MIN | HWMON_I_MAX | HWMON_I_ALARM, |
382 | HWMON_I_INPUT, | 650 | HWMON_I_INPUT | HWMON_I_MIN | HWMON_I_MAX | HWMON_I_ALARM, |
383 | HWMON_I_INPUT, | 651 | HWMON_I_INPUT | HWMON_I_MIN | HWMON_I_MAX | HWMON_I_ALARM, |
384 | 0 | 652 | 0 |
385 | }; | 653 | }; |
386 | 654 | ||
@@ -390,8 +658,10 @@ static const struct hwmon_channel_info adt7411_in = { | |||
390 | }; | 658 | }; |
391 | 659 | ||
392 | static const u32 adt7411_temp_config[] = { | 660 | static const u32 adt7411_temp_config[] = { |
393 | HWMON_T_INPUT, | 661 | HWMON_T_INPUT | HWMON_T_MIN | HWMON_T_MIN_ALARM | |
394 | HWMON_T_INPUT, | 662 | HWMON_T_MAX | HWMON_T_MAX_ALARM, |
663 | HWMON_T_INPUT | HWMON_T_MIN | HWMON_T_MIN_ALARM | | ||
664 | HWMON_T_MAX | HWMON_T_MAX_ALARM | HWMON_T_FAULT, | ||
395 | 0 | 665 | 0 |
396 | }; | 666 | }; |
397 | 667 | ||
@@ -409,6 +679,7 @@ static const struct hwmon_channel_info *adt7411_info[] = { | |||
409 | static const struct hwmon_ops adt7411_hwmon_ops = { | 679 | static const struct hwmon_ops adt7411_hwmon_ops = { |
410 | .is_visible = adt7411_is_visible, | 680 | .is_visible = adt7411_is_visible, |
411 | .read = adt7411_read, | 681 | .read = adt7411_read, |
682 | .write = adt7411_write, | ||
412 | }; | 683 | }; |
413 | 684 | ||
414 | static const struct hwmon_chip_info adt7411_chip_info = { | 685 | static const struct hwmon_chip_info adt7411_chip_info = { |