Thomas Gleixner | 74ba920 | 2019-05-20 09:19:02 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-or-later |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | /* |
Guenter Roeck | 09770b2 | 2012-01-14 20:47:36 -0800 | [diff] [blame] | 3 | * lm85.c - Part of lm_sensors, Linux kernel modules for hardware |
| 4 | * monitoring |
| 5 | * Copyright (c) 1998, 1999 Frodo Looijaard <frodol@dds.nl> |
| 6 | * Copyright (c) 2002, 2003 Philip Pokorny <ppokorny@penguincomputing.com> |
| 7 | * Copyright (c) 2003 Margit Schubert-While <margitsw@t-online.de> |
| 8 | * Copyright (c) 2004 Justin Thiessen <jthiessen@penguincomputing.com> |
Jean Delvare | 590e853 | 2014-06-11 18:35:56 +0200 | [diff] [blame] | 9 | * Copyright (C) 2007--2014 Jean Delvare <jdelvare@suse.de> |
Guenter Roeck | 09770b2 | 2012-01-14 20:47:36 -0800 | [diff] [blame] | 10 | * |
| 11 | * Chip details at <http://www.national.com/ds/LM/LM85.pdf> |
Guenter Roeck | 09770b2 | 2012-01-14 20:47:36 -0800 | [diff] [blame] | 12 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14 | #include <linux/module.h> |
Javier Martinez Canillas | 00c0f9d | 2017-02-24 10:13:03 -0300 | [diff] [blame] | 15 | #include <linux/of_device.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16 | #include <linux/init.h> |
| 17 | #include <linux/slab.h> |
| 18 | #include <linux/jiffies.h> |
| 19 | #include <linux/i2c.h> |
Mark M. Hoffman | 943b083 | 2005-07-15 21:39:18 -0400 | [diff] [blame] | 20 | #include <linux/hwmon.h> |
Jean Delvare | 303760b | 2005-07-31 21:52:01 +0200 | [diff] [blame] | 21 | #include <linux/hwmon-vid.h> |
Jean Delvare | b353a48 | 2007-07-05 20:36:12 +0200 | [diff] [blame] | 22 | #include <linux/hwmon-sysfs.h> |
Mark M. Hoffman | 943b083 | 2005-07-15 21:39:18 -0400 | [diff] [blame] | 23 | #include <linux/err.h> |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 24 | #include <linux/mutex.h> |
Bartosz Golaszewski | 0f3721c | 2015-04-16 12:43:36 -0700 | [diff] [blame] | 25 | #include <linux/util_macros.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 | |
| 27 | /* Addresses to scan */ |
Mark M. Hoffman | 25e9c86 | 2008-02-17 22:28:03 -0500 | [diff] [blame] | 28 | static const unsigned short normal_i2c[] = { 0x2c, 0x2d, 0x2e, I2C_CLIENT_END }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 29 | |
Jean Delvare | e5e9f44 | 2009-12-14 21:17:27 +0100 | [diff] [blame] | 30 | enum chips { |
Jeremy Gebben | 11650cf | 2019-02-04 13:19:05 -0700 | [diff] [blame] | 31 | lm85, lm96000, |
Jean Delvare | e5e9f44 | 2009-12-14 21:17:27 +0100 | [diff] [blame] | 32 | adm1027, adt7463, adt7468, |
Guenter Roeck | 06923f8 | 2011-02-19 08:27:47 -0800 | [diff] [blame] | 33 | emc6d100, emc6d102, emc6d103, emc6d103s |
Jean Delvare | e5e9f44 | 2009-12-14 21:17:27 +0100 | [diff] [blame] | 34 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | |
| 36 | /* The LM85 registers */ |
| 37 | |
Guenter Roeck | 09770b2 | 2012-01-14 20:47:36 -0800 | [diff] [blame] | 38 | #define LM85_REG_IN(nr) (0x20 + (nr)) |
| 39 | #define LM85_REG_IN_MIN(nr) (0x44 + (nr) * 2) |
| 40 | #define LM85_REG_IN_MAX(nr) (0x45 + (nr) * 2) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 | |
Guenter Roeck | 09770b2 | 2012-01-14 20:47:36 -0800 | [diff] [blame] | 42 | #define LM85_REG_TEMP(nr) (0x25 + (nr)) |
| 43 | #define LM85_REG_TEMP_MIN(nr) (0x4e + (nr) * 2) |
| 44 | #define LM85_REG_TEMP_MAX(nr) (0x4f + (nr) * 2) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | |
| 46 | /* Fan speeds are LSB, MSB (2 bytes) */ |
Guenter Roeck | 09770b2 | 2012-01-14 20:47:36 -0800 | [diff] [blame] | 47 | #define LM85_REG_FAN(nr) (0x28 + (nr) * 2) |
| 48 | #define LM85_REG_FAN_MIN(nr) (0x54 + (nr) * 2) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 49 | |
Guenter Roeck | 09770b2 | 2012-01-14 20:47:36 -0800 | [diff] [blame] | 50 | #define LM85_REG_PWM(nr) (0x30 + (nr)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | |
Guenter Roeck | 09770b2 | 2012-01-14 20:47:36 -0800 | [diff] [blame] | 52 | #define LM85_REG_COMPANY 0x3e |
| 53 | #define LM85_REG_VERSTEP 0x3f |
Darrick J. Wong | 79b92f2 | 2008-11-12 13:26:59 -0800 | [diff] [blame] | 54 | |
Guenter Roeck | 09770b2 | 2012-01-14 20:47:36 -0800 | [diff] [blame] | 55 | #define ADT7468_REG_CFG5 0x7c |
| 56 | #define ADT7468_OFF64 (1 << 0) |
| 57 | #define ADT7468_HFPWM (1 << 1) |
| 58 | #define IS_ADT7468_OFF64(data) \ |
Darrick J. Wong | 79b92f2 | 2008-11-12 13:26:59 -0800 | [diff] [blame] | 59 | ((data)->type == adt7468 && !((data)->cfg5 & ADT7468_OFF64)) |
Guenter Roeck | 09770b2 | 2012-01-14 20:47:36 -0800 | [diff] [blame] | 60 | #define IS_ADT7468_HFPWM(data) \ |
Jean Delvare | f6c61cf | 2010-10-28 20:31:50 +0200 | [diff] [blame] | 61 | ((data)->type == adt7468 && !((data)->cfg5 & ADT7468_HFPWM)) |
Darrick J. Wong | 79b92f2 | 2008-11-12 13:26:59 -0800 | [diff] [blame] | 62 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 63 | /* These are the recognized values for the above regs */ |
Guenter Roeck | 09770b2 | 2012-01-14 20:47:36 -0800 | [diff] [blame] | 64 | #define LM85_COMPANY_NATIONAL 0x01 |
| 65 | #define LM85_COMPANY_ANALOG_DEV 0x41 |
| 66 | #define LM85_COMPANY_SMSC 0x5c |
Guenter Roeck | 09770b2 | 2012-01-14 20:47:36 -0800 | [diff] [blame] | 67 | #define LM85_VERSTEP_LM85C 0x60 |
| 68 | #define LM85_VERSTEP_LM85B 0x62 |
| 69 | #define LM85_VERSTEP_LM96000_1 0x68 |
| 70 | #define LM85_VERSTEP_LM96000_2 0x69 |
| 71 | #define LM85_VERSTEP_ADM1027 0x60 |
| 72 | #define LM85_VERSTEP_ADT7463 0x62 |
| 73 | #define LM85_VERSTEP_ADT7463C 0x6A |
| 74 | #define LM85_VERSTEP_ADT7468_1 0x71 |
| 75 | #define LM85_VERSTEP_ADT7468_2 0x72 |
| 76 | #define LM85_VERSTEP_EMC6D100_A0 0x60 |
| 77 | #define LM85_VERSTEP_EMC6D100_A1 0x61 |
| 78 | #define LM85_VERSTEP_EMC6D102 0x65 |
| 79 | #define LM85_VERSTEP_EMC6D103_A0 0x68 |
| 80 | #define LM85_VERSTEP_EMC6D103_A1 0x69 |
| 81 | #define LM85_VERSTEP_EMC6D103S 0x6A /* Also known as EMC6D103:A2 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 82 | |
Guenter Roeck | 09770b2 | 2012-01-14 20:47:36 -0800 | [diff] [blame] | 83 | #define LM85_REG_CONFIG 0x40 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 84 | |
Guenter Roeck | 09770b2 | 2012-01-14 20:47:36 -0800 | [diff] [blame] | 85 | #define LM85_REG_ALARM1 0x41 |
| 86 | #define LM85_REG_ALARM2 0x42 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 87 | |
Guenter Roeck | 09770b2 | 2012-01-14 20:47:36 -0800 | [diff] [blame] | 88 | #define LM85_REG_VID 0x43 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 89 | |
| 90 | /* Automated FAN control */ |
Guenter Roeck | 09770b2 | 2012-01-14 20:47:36 -0800 | [diff] [blame] | 91 | #define LM85_REG_AFAN_CONFIG(nr) (0x5c + (nr)) |
| 92 | #define LM85_REG_AFAN_RANGE(nr) (0x5f + (nr)) |
| 93 | #define LM85_REG_AFAN_SPIKE1 0x62 |
| 94 | #define LM85_REG_AFAN_MINPWM(nr) (0x64 + (nr)) |
| 95 | #define LM85_REG_AFAN_LIMIT(nr) (0x67 + (nr)) |
| 96 | #define LM85_REG_AFAN_CRITICAL(nr) (0x6a + (nr)) |
| 97 | #define LM85_REG_AFAN_HYST1 0x6d |
| 98 | #define LM85_REG_AFAN_HYST2 0x6e |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 99 | |
Guenter Roeck | 09770b2 | 2012-01-14 20:47:36 -0800 | [diff] [blame] | 100 | #define ADM1027_REG_EXTEND_ADC1 0x76 |
| 101 | #define ADM1027_REG_EXTEND_ADC2 0x77 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 102 | |
| 103 | #define EMC6D100_REG_ALARM3 0x7d |
| 104 | /* IN5, IN6 and IN7 */ |
Guenter Roeck | 09770b2 | 2012-01-14 20:47:36 -0800 | [diff] [blame] | 105 | #define EMC6D100_REG_IN(nr) (0x70 + ((nr) - 5)) |
| 106 | #define EMC6D100_REG_IN_MIN(nr) (0x73 + ((nr) - 5) * 2) |
| 107 | #define EMC6D100_REG_IN_MAX(nr) (0x74 + ((nr) - 5) * 2) |
| 108 | #define EMC6D102_REG_EXTEND_ADC1 0x85 |
| 109 | #define EMC6D102_REG_EXTEND_ADC2 0x86 |
| 110 | #define EMC6D102_REG_EXTEND_ADC3 0x87 |
| 111 | #define EMC6D102_REG_EXTEND_ADC4 0x88 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 112 | |
Guenter Roeck | 09770b2 | 2012-01-14 20:47:36 -0800 | [diff] [blame] | 113 | /* |
| 114 | * Conversions. Rounding and limit checking is only done on the TO_REG |
| 115 | * variants. Note that you should be a bit careful with which arguments |
| 116 | * these macros are called: arguments may be evaluated more than once. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 117 | */ |
| 118 | |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 119 | /* IN are scaled according to built-in resistors */ |
Jean Delvare | e89e22b | 2008-06-25 08:47:35 -0400 | [diff] [blame] | 120 | static const int lm85_scaling[] = { /* .001 Volts */ |
Jean Delvare | 1f44809 | 2008-04-29 14:03:37 +0200 | [diff] [blame] | 121 | 2500, 2250, 3300, 5000, 12000, |
| 122 | 3300, 1500, 1800 /*EMC6D100*/ |
| 123 | }; |
| 124 | #define SCALE(val, from, to) (((val) * (to) + ((from) / 2)) / (from)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 125 | |
Jean Delvare | 1f44809 | 2008-04-29 14:03:37 +0200 | [diff] [blame] | 126 | #define INS_TO_REG(n, val) \ |
Guenter Roeck | 67b2003 | 2016-12-04 18:16:48 -0800 | [diff] [blame] | 127 | SCALE(clamp_val(val, 0, 255 * lm85_scaling[n] / 192), \ |
| 128 | lm85_scaling[n], 192) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 129 | |
Jean Delvare | 1f44809 | 2008-04-29 14:03:37 +0200 | [diff] [blame] | 130 | #define INSEXT_FROM_REG(n, val, ext) \ |
Jean Delvare | 5a4d3ef | 2007-07-05 20:38:32 +0200 | [diff] [blame] | 131 | SCALE(((val) << 4) + (ext), 192 << 4, lm85_scaling[n]) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 132 | |
Jean Delvare | 1f44809 | 2008-04-29 14:03:37 +0200 | [diff] [blame] | 133 | #define INS_FROM_REG(n, val) SCALE((val), 192, lm85_scaling[n]) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 134 | |
| 135 | /* FAN speed is measured using 90kHz clock */ |
Jean Delvare | 63f281a | 2007-07-05 20:39:40 +0200 | [diff] [blame] | 136 | static inline u16 FAN_TO_REG(unsigned long val) |
| 137 | { |
| 138 | if (!val) |
| 139 | return 0xffff; |
Guenter Roeck | 2a844c1 | 2013-01-09 08:09:34 -0800 | [diff] [blame] | 140 | return clamp_val(5400000 / val, 1, 0xfffe); |
Jean Delvare | 63f281a | 2007-07-05 20:39:40 +0200 | [diff] [blame] | 141 | } |
Jean Delvare | 1f44809 | 2008-04-29 14:03:37 +0200 | [diff] [blame] | 142 | #define FAN_FROM_REG(val) ((val) == 0 ? -1 : (val) == 0xffff ? 0 : \ |
| 143 | 5400000 / (val)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 144 | |
| 145 | /* Temperature is reported in .001 degC increments */ |
| 146 | #define TEMP_TO_REG(val) \ |
Guenter Roeck | 3248c3b | 2014-07-29 22:23:12 -0700 | [diff] [blame] | 147 | DIV_ROUND_CLOSEST(clamp_val((val), -127000, 127000), 1000) |
Jean Delvare | 1f44809 | 2008-04-29 14:03:37 +0200 | [diff] [blame] | 148 | #define TEMPEXT_FROM_REG(val, ext) \ |
Jean Delvare | 5a4d3ef | 2007-07-05 20:38:32 +0200 | [diff] [blame] | 149 | SCALE(((val) << 4) + (ext), 16, 1000) |
| 150 | #define TEMP_FROM_REG(val) ((val) * 1000) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 151 | |
Guenter Roeck | 2a844c1 | 2013-01-09 08:09:34 -0800 | [diff] [blame] | 152 | #define PWM_TO_REG(val) clamp_val(val, 0, 255) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 153 | #define PWM_FROM_REG(val) (val) |
| 154 | |
Guenter Roeck | 09770b2 | 2012-01-14 20:47:36 -0800 | [diff] [blame] | 155 | /* |
| 156 | * ZONEs have the following parameters: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 157 | * Limit (low) temp, 1. degC |
| 158 | * Hysteresis (below limit), 1. degC (0-15) |
| 159 | * Range of speed control, .1 degC (2-80) |
| 160 | * Critical (high) temp, 1. degC |
| 161 | * |
| 162 | * FAN PWMs have the following parameters: |
| 163 | * Reference Zone, 1, 2, 3, etc. |
| 164 | * Spinup time, .05 sec |
| 165 | * PWM value at limit/low temp, 1 count |
| 166 | * PWM Frequency, 1. Hz |
| 167 | * PWM is Min or OFF below limit, flag |
| 168 | * Invert PWM output, flag |
| 169 | * |
| 170 | * Some chips filter the temp, others the fan. |
| 171 | * Filter constant (or disabled) .1 seconds |
| 172 | */ |
| 173 | |
| 174 | /* These are the zone temperature range encodings in .001 degree C */ |
Jean Delvare | e89e22b | 2008-06-25 08:47:35 -0400 | [diff] [blame] | 175 | static const int lm85_range_map[] = { |
Jean Delvare | 1f44809 | 2008-04-29 14:03:37 +0200 | [diff] [blame] | 176 | 2000, 2500, 3300, 4000, 5000, 6600, 8000, 10000, |
| 177 | 13300, 16000, 20000, 26600, 32000, 40000, 53300, 80000 |
| 178 | }; |
| 179 | |
Guenter Roeck | 3248c3b | 2014-07-29 22:23:12 -0700 | [diff] [blame] | 180 | static int RANGE_TO_REG(long range) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 181 | { |
Bartosz Golaszewski | 0f3721c | 2015-04-16 12:43:36 -0700 | [diff] [blame] | 182 | return find_closest(range, lm85_range_map, ARRAY_SIZE(lm85_range_map)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 183 | } |
Jean Delvare | 1f44809 | 2008-04-29 14:03:37 +0200 | [diff] [blame] | 184 | #define RANGE_FROM_REG(val) lm85_range_map[(val) & 0x0f] |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 185 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 186 | /* These are the PWM frequency encodings */ |
Jeremy Gebben | 57bc301 | 2019-02-04 13:19:03 -0700 | [diff] [blame] | 187 | static const int lm85_freq_map[] = { /* 1 Hz */ |
Jean Delvare | 8a0795d | 2008-10-17 17:51:14 +0200 | [diff] [blame] | 188 | 10, 15, 23, 30, 38, 47, 61, 94 |
| 189 | }; |
Jeremy Gebben | 57bc301 | 2019-02-04 13:19:03 -0700 | [diff] [blame] | 190 | |
Jeremy Gebben | e9b9548 | 2019-02-04 13:19:06 -0700 | [diff] [blame] | 191 | static const int lm96000_freq_map[] = { /* 1 Hz */ |
| 192 | 10, 15, 23, 30, 38, 47, 61, 94, |
| 193 | 22500, 24000, 25700, 25700, 27700, 27700, 30000, 30000 |
| 194 | }; |
| 195 | |
Jeremy Gebben | 57bc301 | 2019-02-04 13:19:03 -0700 | [diff] [blame] | 196 | static const int adm1027_freq_map[] = { /* 1 Hz */ |
Jean Delvare | 8a0795d | 2008-10-17 17:51:14 +0200 | [diff] [blame] | 197 | 11, 15, 22, 29, 35, 44, 59, 88 |
Jean Delvare | 1f44809 | 2008-04-29 14:03:37 +0200 | [diff] [blame] | 198 | }; |
| 199 | |
Bartosz Golaszewski | 0f3721c | 2015-04-16 12:43:36 -0700 | [diff] [blame] | 200 | static int FREQ_TO_REG(const int *map, |
| 201 | unsigned int map_size, unsigned long freq) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 202 | { |
Bartosz Golaszewski | 0f3721c | 2015-04-16 12:43:36 -0700 | [diff] [blame] | 203 | return find_closest(freq, map, map_size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 204 | } |
Jean Delvare | 8a0795d | 2008-10-17 17:51:14 +0200 | [diff] [blame] | 205 | |
Jeremy Gebben | 57bc301 | 2019-02-04 13:19:03 -0700 | [diff] [blame] | 206 | static int FREQ_FROM_REG(const int *map, unsigned int map_size, u8 reg) |
Jean Delvare | 8a0795d | 2008-10-17 17:51:14 +0200 | [diff] [blame] | 207 | { |
Jeremy Gebben | 57bc301 | 2019-02-04 13:19:03 -0700 | [diff] [blame] | 208 | return map[reg % map_size]; |
Jean Delvare | 8a0795d | 2008-10-17 17:51:14 +0200 | [diff] [blame] | 209 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 210 | |
Guenter Roeck | 09770b2 | 2012-01-14 20:47:36 -0800 | [diff] [blame] | 211 | /* |
| 212 | * Since we can't use strings, I'm abusing these numbers |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 213 | * to stand in for the following meanings: |
| 214 | * 1 -- PWM responds to Zone 1 |
| 215 | * 2 -- PWM responds to Zone 2 |
| 216 | * 3 -- PWM responds to Zone 3 |
| 217 | * 23 -- PWM responds to the higher temp of Zone 2 or 3 |
| 218 | * 123 -- PWM responds to highest of Zone 1, 2, or 3 |
| 219 | * 0 -- PWM is always at 0% (ie, off) |
| 220 | * -1 -- PWM is always at 100% |
| 221 | * -2 -- PWM responds to manual control |
| 222 | */ |
| 223 | |
Jean Delvare | e89e22b | 2008-06-25 08:47:35 -0400 | [diff] [blame] | 224 | static const int lm85_zone_map[] = { 1, 2, 3, -1, 0, 23, 123, -2 }; |
| 225 | #define ZONE_FROM_REG(val) lm85_zone_map[(val) >> 5] |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 226 | |
Jean Delvare | 1f44809 | 2008-04-29 14:03:37 +0200 | [diff] [blame] | 227 | static int ZONE_TO_REG(int zone) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 228 | { |
| 229 | int i; |
| 230 | |
Jean Delvare | 1f44809 | 2008-04-29 14:03:37 +0200 | [diff] [blame] | 231 | for (i = 0; i <= 7; ++i) |
| 232 | if (zone == lm85_zone_map[i]) |
| 233 | break; |
| 234 | if (i > 7) /* Not found. */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 235 | i = 3; /* Always 100% */ |
Jean Delvare | e89e22b | 2008-06-25 08:47:35 -0400 | [diff] [blame] | 236 | return i << 5; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 237 | } |
| 238 | |
Guenter Roeck | 2a844c1 | 2013-01-09 08:09:34 -0800 | [diff] [blame] | 239 | #define HYST_TO_REG(val) clamp_val(((val) + 500) / 1000, 0, 15) |
Jean Delvare | 1f44809 | 2008-04-29 14:03:37 +0200 | [diff] [blame] | 240 | #define HYST_FROM_REG(val) ((val) * 1000) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 241 | |
Guenter Roeck | 09770b2 | 2012-01-14 20:47:36 -0800 | [diff] [blame] | 242 | /* |
| 243 | * Chip sampling rates |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 244 | * |
| 245 | * Some sensors are not updated more frequently than once per second |
| 246 | * so it doesn't make sense to read them more often than that. |
| 247 | * We cache the results and return the saved data if the driver |
| 248 | * is called again before a second has elapsed. |
| 249 | * |
| 250 | * Also, there is significant configuration data for this chip |
| 251 | * given the automatic PWM fan control that is possible. There |
| 252 | * are about 47 bytes of config data to only 22 bytes of actual |
| 253 | * readings. So, we keep the config data up to date in the cache |
| 254 | * when it is written and only sample it once every 1 *minute* |
| 255 | */ |
| 256 | #define LM85_DATA_INTERVAL (HZ + HZ / 2) |
| 257 | #define LM85_CONFIG_INTERVAL (1 * 60 * HZ) |
| 258 | |
Guenter Roeck | 09770b2 | 2012-01-14 20:47:36 -0800 | [diff] [blame] | 259 | /* |
| 260 | * LM85 can automatically adjust fan speeds based on temperature |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 261 | * This structure encapsulates an entire Zone config. There are |
| 262 | * three zones (one for each temperature input) on the lm85 |
| 263 | */ |
| 264 | struct lm85_zone { |
| 265 | s8 limit; /* Low temp limit */ |
| 266 | u8 hyst; /* Low limit hysteresis. (0-15) */ |
| 267 | u8 range; /* Temp range, encoded */ |
| 268 | s8 critical; /* "All fans ON" temp limit */ |
Guenter Roeck | 09770b2 | 2012-01-14 20:47:36 -0800 | [diff] [blame] | 269 | u8 max_desired; /* |
| 270 | * Actual "max" temperature specified. Preserved |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 271 | * to prevent "drift" as other autofan control |
| 272 | * values change. |
| 273 | */ |
| 274 | }; |
| 275 | |
| 276 | struct lm85_autofan { |
| 277 | u8 config; /* Register value */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 278 | u8 min_pwm; /* Minimum PWM value, encoded */ |
| 279 | u8 min_off; /* Min PWM or OFF below "limit", flag */ |
| 280 | }; |
| 281 | |
Guenter Roeck | 09770b2 | 2012-01-14 20:47:36 -0800 | [diff] [blame] | 282 | /* |
| 283 | * For each registered chip, we need to keep some data in memory. |
| 284 | * The structure is dynamically allocated. |
| 285 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 286 | struct lm85_data { |
Axel Lin | 746f688 | 2014-07-23 12:29:11 +0800 | [diff] [blame] | 287 | struct i2c_client *client; |
| 288 | const struct attribute_group *groups[6]; |
Jean Delvare | 8a0795d | 2008-10-17 17:51:14 +0200 | [diff] [blame] | 289 | const int *freq_map; |
Jeremy Gebben | 57bc301 | 2019-02-04 13:19:03 -0700 | [diff] [blame] | 290 | unsigned int freq_map_size; |
| 291 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 292 | enum chips type; |
| 293 | |
Guenter Roeck | de24880 | 2011-02-25 08:19:42 -0800 | [diff] [blame] | 294 | bool has_vid5; /* true if VID5 is configured for ADT7463 or ADT7468 */ |
| 295 | |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 296 | struct mutex update_lock; |
Paul Fertser | 952a11c | 2021-09-24 22:52:02 +0300 | [diff] [blame] | 297 | bool valid; /* true if following fields are valid */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 298 | unsigned long last_reading; /* In jiffies */ |
| 299 | unsigned long last_config; /* In jiffies */ |
| 300 | |
| 301 | u8 in[8]; /* Register value */ |
| 302 | u8 in_max[8]; /* Register value */ |
| 303 | u8 in_min[8]; /* Register value */ |
| 304 | s8 temp[3]; /* Register value */ |
| 305 | s8 temp_min[3]; /* Register value */ |
| 306 | s8 temp_max[3]; /* Register value */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 307 | u16 fan[4]; /* Register value */ |
| 308 | u16 fan_min[4]; /* Register value */ |
| 309 | u8 pwm[3]; /* Register value */ |
Jean Delvare | 34e7dc6 | 2008-10-17 17:51:13 +0200 | [diff] [blame] | 310 | u8 pwm_freq[3]; /* Register encoding */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 311 | u8 temp_ext[3]; /* Decoded values */ |
| 312 | u8 in_ext[8]; /* Decoded values */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 313 | u8 vid; /* Register value */ |
| 314 | u8 vrm; /* VRM version */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 315 | u32 alarms; /* Register encoding, combined */ |
Darrick J. Wong | 79b92f2 | 2008-11-12 13:26:59 -0800 | [diff] [blame] | 316 | u8 cfg5; /* Config Register 5 on ADT7468 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 317 | struct lm85_autofan autofan[3]; |
| 318 | struct lm85_zone zone[3]; |
| 319 | }; |
| 320 | |
Axel Lin | 6fd5dd5 | 2014-07-23 12:27:39 +0800 | [diff] [blame] | 321 | static int lm85_read_value(struct i2c_client *client, u8 reg) |
| 322 | { |
| 323 | int res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 324 | |
Axel Lin | 6fd5dd5 | 2014-07-23 12:27:39 +0800 | [diff] [blame] | 325 | /* What size location is it? */ |
| 326 | switch (reg) { |
| 327 | case LM85_REG_FAN(0): /* Read WORD data */ |
| 328 | case LM85_REG_FAN(1): |
| 329 | case LM85_REG_FAN(2): |
| 330 | case LM85_REG_FAN(3): |
| 331 | case LM85_REG_FAN_MIN(0): |
| 332 | case LM85_REG_FAN_MIN(1): |
| 333 | case LM85_REG_FAN_MIN(2): |
| 334 | case LM85_REG_FAN_MIN(3): |
| 335 | case LM85_REG_ALARM1: /* Read both bytes at once */ |
| 336 | res = i2c_smbus_read_byte_data(client, reg) & 0xff; |
| 337 | res |= i2c_smbus_read_byte_data(client, reg + 1) << 8; |
| 338 | break; |
| 339 | default: /* Read BYTE data */ |
| 340 | res = i2c_smbus_read_byte_data(client, reg); |
| 341 | break; |
| 342 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 343 | |
Axel Lin | 6fd5dd5 | 2014-07-23 12:27:39 +0800 | [diff] [blame] | 344 | return res; |
| 345 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 346 | |
Axel Lin | 6fd5dd5 | 2014-07-23 12:27:39 +0800 | [diff] [blame] | 347 | static void lm85_write_value(struct i2c_client *client, u8 reg, int value) |
| 348 | { |
| 349 | switch (reg) { |
| 350 | case LM85_REG_FAN(0): /* Write WORD data */ |
| 351 | case LM85_REG_FAN(1): |
| 352 | case LM85_REG_FAN(2): |
| 353 | case LM85_REG_FAN(3): |
| 354 | case LM85_REG_FAN_MIN(0): |
| 355 | case LM85_REG_FAN_MIN(1): |
| 356 | case LM85_REG_FAN_MIN(2): |
| 357 | case LM85_REG_FAN_MIN(3): |
| 358 | /* NOTE: ALARM is read only, so not included here */ |
| 359 | i2c_smbus_write_byte_data(client, reg, value & 0xff); |
| 360 | i2c_smbus_write_byte_data(client, reg + 1, value >> 8); |
| 361 | break; |
| 362 | default: /* Write BYTE data */ |
| 363 | i2c_smbus_write_byte_data(client, reg, value); |
| 364 | break; |
| 365 | } |
| 366 | } |
Jean Delvare | 67712d0 | 2008-10-17 17:51:14 +0200 | [diff] [blame] | 367 | |
Axel Lin | 6fd5dd5 | 2014-07-23 12:27:39 +0800 | [diff] [blame] | 368 | static struct lm85_data *lm85_update_device(struct device *dev) |
| 369 | { |
Axel Lin | 746f688 | 2014-07-23 12:29:11 +0800 | [diff] [blame] | 370 | struct lm85_data *data = dev_get_drvdata(dev); |
| 371 | struct i2c_client *client = data->client; |
Axel Lin | 6fd5dd5 | 2014-07-23 12:27:39 +0800 | [diff] [blame] | 372 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 373 | |
Axel Lin | 6fd5dd5 | 2014-07-23 12:27:39 +0800 | [diff] [blame] | 374 | mutex_lock(&data->update_lock); |
| 375 | |
| 376 | if (!data->valid || |
| 377 | time_after(jiffies, data->last_reading + LM85_DATA_INTERVAL)) { |
| 378 | /* Things that change quickly */ |
| 379 | dev_dbg(&client->dev, "Reading sensor values\n"); |
| 380 | |
| 381 | /* |
| 382 | * Have to read extended bits first to "freeze" the |
| 383 | * more significant bits that are read later. |
| 384 | * There are 2 additional resolution bits per channel and we |
| 385 | * have room for 4, so we shift them to the left. |
| 386 | */ |
| 387 | if (data->type == adm1027 || data->type == adt7463 || |
| 388 | data->type == adt7468) { |
| 389 | int ext1 = lm85_read_value(client, |
| 390 | ADM1027_REG_EXTEND_ADC1); |
| 391 | int ext2 = lm85_read_value(client, |
| 392 | ADM1027_REG_EXTEND_ADC2); |
| 393 | int val = (ext1 << 8) + ext2; |
| 394 | |
| 395 | for (i = 0; i <= 4; i++) |
| 396 | data->in_ext[i] = |
| 397 | ((val >> (i * 2)) & 0x03) << 2; |
| 398 | |
| 399 | for (i = 0; i <= 2; i++) |
| 400 | data->temp_ext[i] = |
| 401 | (val >> ((i + 4) * 2)) & 0x0c; |
| 402 | } |
| 403 | |
| 404 | data->vid = lm85_read_value(client, LM85_REG_VID); |
| 405 | |
| 406 | for (i = 0; i <= 3; ++i) { |
| 407 | data->in[i] = |
| 408 | lm85_read_value(client, LM85_REG_IN(i)); |
| 409 | data->fan[i] = |
| 410 | lm85_read_value(client, LM85_REG_FAN(i)); |
| 411 | } |
| 412 | |
| 413 | if (!data->has_vid5) |
| 414 | data->in[4] = lm85_read_value(client, LM85_REG_IN(4)); |
| 415 | |
| 416 | if (data->type == adt7468) |
| 417 | data->cfg5 = lm85_read_value(client, ADT7468_REG_CFG5); |
| 418 | |
| 419 | for (i = 0; i <= 2; ++i) { |
| 420 | data->temp[i] = |
| 421 | lm85_read_value(client, LM85_REG_TEMP(i)); |
| 422 | data->pwm[i] = |
| 423 | lm85_read_value(client, LM85_REG_PWM(i)); |
| 424 | |
| 425 | if (IS_ADT7468_OFF64(data)) |
| 426 | data->temp[i] -= 64; |
| 427 | } |
| 428 | |
| 429 | data->alarms = lm85_read_value(client, LM85_REG_ALARM1); |
| 430 | |
| 431 | if (data->type == emc6d100) { |
| 432 | /* Three more voltage sensors */ |
| 433 | for (i = 5; i <= 7; ++i) { |
| 434 | data->in[i] = lm85_read_value(client, |
| 435 | EMC6D100_REG_IN(i)); |
| 436 | } |
| 437 | /* More alarm bits */ |
| 438 | data->alarms |= lm85_read_value(client, |
| 439 | EMC6D100_REG_ALARM3) << 16; |
| 440 | } else if (data->type == emc6d102 || data->type == emc6d103 || |
| 441 | data->type == emc6d103s) { |
| 442 | /* |
| 443 | * Have to read LSB bits after the MSB ones because |
| 444 | * the reading of the MSB bits has frozen the |
| 445 | * LSBs (backward from the ADM1027). |
| 446 | */ |
| 447 | int ext1 = lm85_read_value(client, |
| 448 | EMC6D102_REG_EXTEND_ADC1); |
| 449 | int ext2 = lm85_read_value(client, |
| 450 | EMC6D102_REG_EXTEND_ADC2); |
| 451 | int ext3 = lm85_read_value(client, |
| 452 | EMC6D102_REG_EXTEND_ADC3); |
| 453 | int ext4 = lm85_read_value(client, |
| 454 | EMC6D102_REG_EXTEND_ADC4); |
| 455 | data->in_ext[0] = ext3 & 0x0f; |
| 456 | data->in_ext[1] = ext4 & 0x0f; |
| 457 | data->in_ext[2] = ext4 >> 4; |
| 458 | data->in_ext[3] = ext3 >> 4; |
| 459 | data->in_ext[4] = ext2 >> 4; |
| 460 | |
| 461 | data->temp_ext[0] = ext1 & 0x0f; |
| 462 | data->temp_ext[1] = ext2 & 0x0f; |
| 463 | data->temp_ext[2] = ext1 >> 4; |
| 464 | } |
| 465 | |
| 466 | data->last_reading = jiffies; |
| 467 | } /* last_reading */ |
| 468 | |
| 469 | if (!data->valid || |
| 470 | time_after(jiffies, data->last_config + LM85_CONFIG_INTERVAL)) { |
| 471 | /* Things that don't change often */ |
| 472 | dev_dbg(&client->dev, "Reading config values\n"); |
| 473 | |
| 474 | for (i = 0; i <= 3; ++i) { |
| 475 | data->in_min[i] = |
| 476 | lm85_read_value(client, LM85_REG_IN_MIN(i)); |
| 477 | data->in_max[i] = |
| 478 | lm85_read_value(client, LM85_REG_IN_MAX(i)); |
| 479 | data->fan_min[i] = |
| 480 | lm85_read_value(client, LM85_REG_FAN_MIN(i)); |
| 481 | } |
| 482 | |
| 483 | if (!data->has_vid5) { |
| 484 | data->in_min[4] = lm85_read_value(client, |
| 485 | LM85_REG_IN_MIN(4)); |
| 486 | data->in_max[4] = lm85_read_value(client, |
| 487 | LM85_REG_IN_MAX(4)); |
| 488 | } |
| 489 | |
| 490 | if (data->type == emc6d100) { |
| 491 | for (i = 5; i <= 7; ++i) { |
| 492 | data->in_min[i] = lm85_read_value(client, |
| 493 | EMC6D100_REG_IN_MIN(i)); |
| 494 | data->in_max[i] = lm85_read_value(client, |
| 495 | EMC6D100_REG_IN_MAX(i)); |
| 496 | } |
| 497 | } |
| 498 | |
| 499 | for (i = 0; i <= 2; ++i) { |
| 500 | int val; |
| 501 | |
| 502 | data->temp_min[i] = |
| 503 | lm85_read_value(client, LM85_REG_TEMP_MIN(i)); |
| 504 | data->temp_max[i] = |
| 505 | lm85_read_value(client, LM85_REG_TEMP_MAX(i)); |
| 506 | |
| 507 | data->autofan[i].config = |
| 508 | lm85_read_value(client, LM85_REG_AFAN_CONFIG(i)); |
| 509 | val = lm85_read_value(client, LM85_REG_AFAN_RANGE(i)); |
Jeremy Gebben | 57bc301 | 2019-02-04 13:19:03 -0700 | [diff] [blame] | 510 | data->pwm_freq[i] = val % data->freq_map_size; |
Axel Lin | 6fd5dd5 | 2014-07-23 12:27:39 +0800 | [diff] [blame] | 511 | data->zone[i].range = val >> 4; |
| 512 | data->autofan[i].min_pwm = |
| 513 | lm85_read_value(client, LM85_REG_AFAN_MINPWM(i)); |
| 514 | data->zone[i].limit = |
| 515 | lm85_read_value(client, LM85_REG_AFAN_LIMIT(i)); |
| 516 | data->zone[i].critical = |
| 517 | lm85_read_value(client, LM85_REG_AFAN_CRITICAL(i)); |
| 518 | |
| 519 | if (IS_ADT7468_OFF64(data)) { |
| 520 | data->temp_min[i] -= 64; |
| 521 | data->temp_max[i] -= 64; |
| 522 | data->zone[i].limit -= 64; |
| 523 | data->zone[i].critical -= 64; |
| 524 | } |
| 525 | } |
| 526 | |
| 527 | if (data->type != emc6d103s) { |
| 528 | i = lm85_read_value(client, LM85_REG_AFAN_SPIKE1); |
| 529 | data->autofan[0].min_off = (i & 0x20) != 0; |
| 530 | data->autofan[1].min_off = (i & 0x40) != 0; |
| 531 | data->autofan[2].min_off = (i & 0x80) != 0; |
| 532 | |
| 533 | i = lm85_read_value(client, LM85_REG_AFAN_HYST1); |
| 534 | data->zone[0].hyst = i >> 4; |
| 535 | data->zone[1].hyst = i & 0x0f; |
| 536 | |
| 537 | i = lm85_read_value(client, LM85_REG_AFAN_HYST2); |
| 538 | data->zone[2].hyst = i >> 4; |
| 539 | } |
| 540 | |
| 541 | data->last_config = jiffies; |
| 542 | } /* last_config */ |
| 543 | |
Paul Fertser | 952a11c | 2021-09-24 22:52:02 +0300 | [diff] [blame] | 544 | data->valid = true; |
Axel Lin | 6fd5dd5 | 2014-07-23 12:27:39 +0800 | [diff] [blame] | 545 | |
| 546 | mutex_unlock(&data->update_lock); |
| 547 | |
| 548 | return data; |
| 549 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 550 | |
| 551 | /* 4 Fans */ |
Guenter Roeck | 7bc85e4 | 2019-01-22 10:40:33 -0800 | [diff] [blame] | 552 | static ssize_t fan_show(struct device *dev, struct device_attribute *attr, |
| 553 | char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 554 | { |
Jean Delvare | b353a48 | 2007-07-05 20:36:12 +0200 | [diff] [blame] | 555 | int nr = to_sensor_dev_attr(attr)->index; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 556 | struct lm85_data *data = lm85_update_device(dev); |
Jean Delvare | 1f44809 | 2008-04-29 14:03:37 +0200 | [diff] [blame] | 557 | return sprintf(buf, "%d\n", FAN_FROM_REG(data->fan[nr])); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 558 | } |
Jean Delvare | b353a48 | 2007-07-05 20:36:12 +0200 | [diff] [blame] | 559 | |
Guenter Roeck | 7bc85e4 | 2019-01-22 10:40:33 -0800 | [diff] [blame] | 560 | static ssize_t fan_min_show(struct device *dev, struct device_attribute *attr, |
| 561 | char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 562 | { |
Jean Delvare | b353a48 | 2007-07-05 20:36:12 +0200 | [diff] [blame] | 563 | int nr = to_sensor_dev_attr(attr)->index; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 564 | struct lm85_data *data = lm85_update_device(dev); |
Jean Delvare | 1f44809 | 2008-04-29 14:03:37 +0200 | [diff] [blame] | 565 | return sprintf(buf, "%d\n", FAN_FROM_REG(data->fan_min[nr])); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 566 | } |
Jean Delvare | b353a48 | 2007-07-05 20:36:12 +0200 | [diff] [blame] | 567 | |
Guenter Roeck | 7bc85e4 | 2019-01-22 10:40:33 -0800 | [diff] [blame] | 568 | static ssize_t fan_min_store(struct device *dev, |
| 569 | struct device_attribute *attr, const char *buf, |
| 570 | size_t count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 571 | { |
Jean Delvare | b353a48 | 2007-07-05 20:36:12 +0200 | [diff] [blame] | 572 | int nr = to_sensor_dev_attr(attr)->index; |
Axel Lin | 746f688 | 2014-07-23 12:29:11 +0800 | [diff] [blame] | 573 | struct lm85_data *data = dev_get_drvdata(dev); |
| 574 | struct i2c_client *client = data->client; |
Guenter Roeck | 09770b2 | 2012-01-14 20:47:36 -0800 | [diff] [blame] | 575 | unsigned long val; |
| 576 | int err; |
| 577 | |
| 578 | err = kstrtoul(buf, 10, &val); |
| 579 | if (err) |
| 580 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 581 | |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 582 | mutex_lock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 583 | data->fan_min[nr] = FAN_TO_REG(val); |
| 584 | lm85_write_value(client, LM85_REG_FAN_MIN(nr), data->fan_min[nr]); |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 585 | mutex_unlock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 586 | return count; |
| 587 | } |
| 588 | |
Guenter Roeck | 7bc85e4 | 2019-01-22 10:40:33 -0800 | [diff] [blame] | 589 | static SENSOR_DEVICE_ATTR_RO(fan1_input, fan, 0); |
| 590 | static SENSOR_DEVICE_ATTR_RW(fan1_min, fan_min, 0); |
| 591 | static SENSOR_DEVICE_ATTR_RO(fan2_input, fan, 1); |
| 592 | static SENSOR_DEVICE_ATTR_RW(fan2_min, fan_min, 1); |
| 593 | static SENSOR_DEVICE_ATTR_RO(fan3_input, fan, 2); |
| 594 | static SENSOR_DEVICE_ATTR_RW(fan3_min, fan_min, 2); |
| 595 | static SENSOR_DEVICE_ATTR_RO(fan4_input, fan, 3); |
| 596 | static SENSOR_DEVICE_ATTR_RW(fan4_min, fan_min, 3); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 597 | |
| 598 | /* vid, vrm, alarms */ |
| 599 | |
Julia Lawall | d0ed69d | 2016-12-22 13:04:52 +0100 | [diff] [blame] | 600 | static ssize_t cpu0_vid_show(struct device *dev, |
| 601 | struct device_attribute *attr, char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 602 | { |
| 603 | struct lm85_data *data = lm85_update_device(dev); |
Jean Delvare | 9c516ef | 2005-11-26 20:07:54 +0100 | [diff] [blame] | 604 | int vid; |
| 605 | |
Guenter Roeck | de24880 | 2011-02-25 08:19:42 -0800 | [diff] [blame] | 606 | if (data->has_vid5) { |
Jean Delvare | 9c516ef | 2005-11-26 20:07:54 +0100 | [diff] [blame] | 607 | /* 6-pin VID (VRM 10) */ |
| 608 | vid = vid_from_reg(data->vid & 0x3f, data->vrm); |
| 609 | } else { |
| 610 | /* 5-pin VID (VRM 9) */ |
| 611 | vid = vid_from_reg(data->vid & 0x1f, data->vrm); |
| 612 | } |
| 613 | |
| 614 | return sprintf(buf, "%d\n", vid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 615 | } |
| 616 | |
Julia Lawall | d0ed69d | 2016-12-22 13:04:52 +0100 | [diff] [blame] | 617 | static DEVICE_ATTR_RO(cpu0_vid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 618 | |
Julia Lawall | d0ed69d | 2016-12-22 13:04:52 +0100 | [diff] [blame] | 619 | static ssize_t vrm_show(struct device *dev, struct device_attribute *attr, |
| 620 | char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 621 | { |
Jean Delvare | 90d6619 | 2007-10-08 18:24:35 +0200 | [diff] [blame] | 622 | struct lm85_data *data = dev_get_drvdata(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 623 | return sprintf(buf, "%ld\n", (long) data->vrm); |
| 624 | } |
| 625 | |
Julia Lawall | d0ed69d | 2016-12-22 13:04:52 +0100 | [diff] [blame] | 626 | static ssize_t vrm_store(struct device *dev, struct device_attribute *attr, |
| 627 | const char *buf, size_t count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 628 | { |
Jean Delvare | 8f74efe | 2007-12-01 11:25:33 +0100 | [diff] [blame] | 629 | struct lm85_data *data = dev_get_drvdata(dev); |
Guenter Roeck | 09770b2 | 2012-01-14 20:47:36 -0800 | [diff] [blame] | 630 | unsigned long val; |
| 631 | int err; |
| 632 | |
| 633 | err = kstrtoul(buf, 10, &val); |
| 634 | if (err) |
| 635 | return err; |
| 636 | |
Guenter Roeck | 3248c3b | 2014-07-29 22:23:12 -0700 | [diff] [blame] | 637 | if (val > 255) |
| 638 | return -EINVAL; |
| 639 | |
Guenter Roeck | 09770b2 | 2012-01-14 20:47:36 -0800 | [diff] [blame] | 640 | data->vrm = val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 641 | return count; |
| 642 | } |
| 643 | |
Julia Lawall | d0ed69d | 2016-12-22 13:04:52 +0100 | [diff] [blame] | 644 | static DEVICE_ATTR_RW(vrm); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 645 | |
Julia Lawall | d0ed69d | 2016-12-22 13:04:52 +0100 | [diff] [blame] | 646 | static ssize_t alarms_show(struct device *dev, struct device_attribute *attr, |
| 647 | char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 648 | { |
| 649 | struct lm85_data *data = lm85_update_device(dev); |
Jean Delvare | 68188ba | 2005-05-16 18:52:38 +0200 | [diff] [blame] | 650 | return sprintf(buf, "%u\n", data->alarms); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 651 | } |
| 652 | |
Julia Lawall | d0ed69d | 2016-12-22 13:04:52 +0100 | [diff] [blame] | 653 | static DEVICE_ATTR_RO(alarms); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 654 | |
Guenter Roeck | 7bc85e4 | 2019-01-22 10:40:33 -0800 | [diff] [blame] | 655 | static ssize_t alarm_show(struct device *dev, struct device_attribute *attr, |
| 656 | char *buf) |
Jean Delvare | bf76e9d | 2007-07-05 20:37:58 +0200 | [diff] [blame] | 657 | { |
| 658 | int nr = to_sensor_dev_attr(attr)->index; |
| 659 | struct lm85_data *data = lm85_update_device(dev); |
| 660 | return sprintf(buf, "%u\n", (data->alarms >> nr) & 1); |
| 661 | } |
| 662 | |
Guenter Roeck | 7bc85e4 | 2019-01-22 10:40:33 -0800 | [diff] [blame] | 663 | static SENSOR_DEVICE_ATTR_RO(in0_alarm, alarm, 0); |
| 664 | static SENSOR_DEVICE_ATTR_RO(in1_alarm, alarm, 1); |
| 665 | static SENSOR_DEVICE_ATTR_RO(in2_alarm, alarm, 2); |
| 666 | static SENSOR_DEVICE_ATTR_RO(in3_alarm, alarm, 3); |
| 667 | static SENSOR_DEVICE_ATTR_RO(in4_alarm, alarm, 8); |
| 668 | static SENSOR_DEVICE_ATTR_RO(in5_alarm, alarm, 18); |
| 669 | static SENSOR_DEVICE_ATTR_RO(in6_alarm, alarm, 16); |
| 670 | static SENSOR_DEVICE_ATTR_RO(in7_alarm, alarm, 17); |
| 671 | static SENSOR_DEVICE_ATTR_RO(temp1_alarm, alarm, 4); |
| 672 | static SENSOR_DEVICE_ATTR_RO(temp1_fault, alarm, 14); |
| 673 | static SENSOR_DEVICE_ATTR_RO(temp2_alarm, alarm, 5); |
| 674 | static SENSOR_DEVICE_ATTR_RO(temp3_alarm, alarm, 6); |
| 675 | static SENSOR_DEVICE_ATTR_RO(temp3_fault, alarm, 15); |
| 676 | static SENSOR_DEVICE_ATTR_RO(fan1_alarm, alarm, 10); |
| 677 | static SENSOR_DEVICE_ATTR_RO(fan2_alarm, alarm, 11); |
| 678 | static SENSOR_DEVICE_ATTR_RO(fan3_alarm, alarm, 12); |
| 679 | static SENSOR_DEVICE_ATTR_RO(fan4_alarm, alarm, 13); |
Jean Delvare | bf76e9d | 2007-07-05 20:37:58 +0200 | [diff] [blame] | 680 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 681 | /* pwm */ |
| 682 | |
Guenter Roeck | 7bc85e4 | 2019-01-22 10:40:33 -0800 | [diff] [blame] | 683 | static ssize_t pwm_show(struct device *dev, struct device_attribute *attr, |
| 684 | char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 685 | { |
Jean Delvare | b353a48 | 2007-07-05 20:36:12 +0200 | [diff] [blame] | 686 | int nr = to_sensor_dev_attr(attr)->index; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 687 | struct lm85_data *data = lm85_update_device(dev); |
Jean Delvare | 1f44809 | 2008-04-29 14:03:37 +0200 | [diff] [blame] | 688 | return sprintf(buf, "%d\n", PWM_FROM_REG(data->pwm[nr])); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 689 | } |
Jean Delvare | b353a48 | 2007-07-05 20:36:12 +0200 | [diff] [blame] | 690 | |
Guenter Roeck | 7bc85e4 | 2019-01-22 10:40:33 -0800 | [diff] [blame] | 691 | static ssize_t pwm_store(struct device *dev, struct device_attribute *attr, |
| 692 | const char *buf, size_t count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 693 | { |
Jean Delvare | b353a48 | 2007-07-05 20:36:12 +0200 | [diff] [blame] | 694 | int nr = to_sensor_dev_attr(attr)->index; |
Axel Lin | 746f688 | 2014-07-23 12:29:11 +0800 | [diff] [blame] | 695 | struct lm85_data *data = dev_get_drvdata(dev); |
| 696 | struct i2c_client *client = data->client; |
Guenter Roeck | 09770b2 | 2012-01-14 20:47:36 -0800 | [diff] [blame] | 697 | unsigned long val; |
| 698 | int err; |
| 699 | |
| 700 | err = kstrtoul(buf, 10, &val); |
| 701 | if (err) |
| 702 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 703 | |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 704 | mutex_lock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 705 | data->pwm[nr] = PWM_TO_REG(val); |
| 706 | lm85_write_value(client, LM85_REG_PWM(nr), data->pwm[nr]); |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 707 | mutex_unlock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 708 | return count; |
| 709 | } |
Jean Delvare | b353a48 | 2007-07-05 20:36:12 +0200 | [diff] [blame] | 710 | |
Guenter Roeck | 7bc85e4 | 2019-01-22 10:40:33 -0800 | [diff] [blame] | 711 | static ssize_t pwm_enable_show(struct device *dev, |
| 712 | struct device_attribute *attr, char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 713 | { |
Jean Delvare | b353a48 | 2007-07-05 20:36:12 +0200 | [diff] [blame] | 714 | int nr = to_sensor_dev_attr(attr)->index; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 715 | struct lm85_data *data = lm85_update_device(dev); |
Jean Delvare | 4b4df95 | 2007-12-03 23:23:21 +0100 | [diff] [blame] | 716 | int pwm_zone, enable; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 717 | |
| 718 | pwm_zone = ZONE_FROM_REG(data->autofan[nr].config); |
Jean Delvare | 4b4df95 | 2007-12-03 23:23:21 +0100 | [diff] [blame] | 719 | switch (pwm_zone) { |
| 720 | case -1: /* PWM is always at 100% */ |
| 721 | enable = 0; |
| 722 | break; |
| 723 | case 0: /* PWM is always at 0% */ |
| 724 | case -2: /* PWM responds to manual control */ |
| 725 | enable = 1; |
| 726 | break; |
| 727 | default: /* PWM in automatic mode */ |
| 728 | enable = 2; |
| 729 | } |
| 730 | return sprintf(buf, "%d\n", enable); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 731 | } |
| 732 | |
Guenter Roeck | 7bc85e4 | 2019-01-22 10:40:33 -0800 | [diff] [blame] | 733 | static ssize_t pwm_enable_store(struct device *dev, |
| 734 | struct device_attribute *attr, |
| 735 | const char *buf, size_t count) |
Jean Delvare | 455f791 | 2007-12-03 23:28:42 +0100 | [diff] [blame] | 736 | { |
| 737 | int nr = to_sensor_dev_attr(attr)->index; |
Axel Lin | 746f688 | 2014-07-23 12:29:11 +0800 | [diff] [blame] | 738 | struct lm85_data *data = dev_get_drvdata(dev); |
| 739 | struct i2c_client *client = data->client; |
Jean Delvare | 455f791 | 2007-12-03 23:28:42 +0100 | [diff] [blame] | 740 | u8 config; |
Guenter Roeck | 09770b2 | 2012-01-14 20:47:36 -0800 | [diff] [blame] | 741 | unsigned long val; |
| 742 | int err; |
| 743 | |
| 744 | err = kstrtoul(buf, 10, &val); |
| 745 | if (err) |
| 746 | return err; |
Jean Delvare | 455f791 | 2007-12-03 23:28:42 +0100 | [diff] [blame] | 747 | |
| 748 | switch (val) { |
| 749 | case 0: |
| 750 | config = 3; |
| 751 | break; |
| 752 | case 1: |
| 753 | config = 7; |
| 754 | break; |
| 755 | case 2: |
Guenter Roeck | 09770b2 | 2012-01-14 20:47:36 -0800 | [diff] [blame] | 756 | /* |
| 757 | * Here we have to choose arbitrarily one of the 5 possible |
| 758 | * configurations; I go for the safest |
| 759 | */ |
Jean Delvare | 455f791 | 2007-12-03 23:28:42 +0100 | [diff] [blame] | 760 | config = 6; |
| 761 | break; |
| 762 | default: |
| 763 | return -EINVAL; |
| 764 | } |
| 765 | |
| 766 | mutex_lock(&data->update_lock); |
| 767 | data->autofan[nr].config = lm85_read_value(client, |
| 768 | LM85_REG_AFAN_CONFIG(nr)); |
| 769 | data->autofan[nr].config = (data->autofan[nr].config & ~0xe0) |
| 770 | | (config << 5); |
| 771 | lm85_write_value(client, LM85_REG_AFAN_CONFIG(nr), |
| 772 | data->autofan[nr].config); |
| 773 | mutex_unlock(&data->update_lock); |
| 774 | return count; |
| 775 | } |
| 776 | |
Guenter Roeck | 7bc85e4 | 2019-01-22 10:40:33 -0800 | [diff] [blame] | 777 | static ssize_t pwm_freq_show(struct device *dev, |
| 778 | struct device_attribute *attr, char *buf) |
Jean Delvare | 34e7dc6 | 2008-10-17 17:51:13 +0200 | [diff] [blame] | 779 | { |
| 780 | int nr = to_sensor_dev_attr(attr)->index; |
| 781 | struct lm85_data *data = lm85_update_device(dev); |
Jean Delvare | f6c61cf | 2010-10-28 20:31:50 +0200 | [diff] [blame] | 782 | int freq; |
| 783 | |
| 784 | if (IS_ADT7468_HFPWM(data)) |
| 785 | freq = 22500; |
| 786 | else |
Jeremy Gebben | 57bc301 | 2019-02-04 13:19:03 -0700 | [diff] [blame] | 787 | freq = FREQ_FROM_REG(data->freq_map, data->freq_map_size, |
| 788 | data->pwm_freq[nr]); |
Jean Delvare | f6c61cf | 2010-10-28 20:31:50 +0200 | [diff] [blame] | 789 | |
| 790 | return sprintf(buf, "%d\n", freq); |
Jean Delvare | 34e7dc6 | 2008-10-17 17:51:13 +0200 | [diff] [blame] | 791 | } |
| 792 | |
Guenter Roeck | 7bc85e4 | 2019-01-22 10:40:33 -0800 | [diff] [blame] | 793 | static ssize_t pwm_freq_store(struct device *dev, |
| 794 | struct device_attribute *attr, const char *buf, |
| 795 | size_t count) |
Jean Delvare | 34e7dc6 | 2008-10-17 17:51:13 +0200 | [diff] [blame] | 796 | { |
| 797 | int nr = to_sensor_dev_attr(attr)->index; |
Axel Lin | 746f688 | 2014-07-23 12:29:11 +0800 | [diff] [blame] | 798 | struct lm85_data *data = dev_get_drvdata(dev); |
| 799 | struct i2c_client *client = data->client; |
Guenter Roeck | 09770b2 | 2012-01-14 20:47:36 -0800 | [diff] [blame] | 800 | unsigned long val; |
| 801 | int err; |
| 802 | |
| 803 | err = kstrtoul(buf, 10, &val); |
| 804 | if (err) |
| 805 | return err; |
Jean Delvare | 34e7dc6 | 2008-10-17 17:51:13 +0200 | [diff] [blame] | 806 | |
| 807 | mutex_lock(&data->update_lock); |
Guenter Roeck | 09770b2 | 2012-01-14 20:47:36 -0800 | [diff] [blame] | 808 | /* |
| 809 | * The ADT7468 has a special high-frequency PWM output mode, |
Jean Delvare | f6c61cf | 2010-10-28 20:31:50 +0200 | [diff] [blame] | 810 | * where all PWM outputs are driven by a 22.5 kHz clock. |
Guenter Roeck | 09770b2 | 2012-01-14 20:47:36 -0800 | [diff] [blame] | 811 | * This might confuse the user, but there's not much we can do. |
| 812 | */ |
Jean Delvare | f6c61cf | 2010-10-28 20:31:50 +0200 | [diff] [blame] | 813 | if (data->type == adt7468 && val >= 11300) { /* High freq. mode */ |
| 814 | data->cfg5 &= ~ADT7468_HFPWM; |
| 815 | lm85_write_value(client, ADT7468_REG_CFG5, data->cfg5); |
| 816 | } else { /* Low freq. mode */ |
Bartosz Golaszewski | 0f3721c | 2015-04-16 12:43:36 -0700 | [diff] [blame] | 817 | data->pwm_freq[nr] = FREQ_TO_REG(data->freq_map, |
Jeremy Gebben | 57bc301 | 2019-02-04 13:19:03 -0700 | [diff] [blame] | 818 | data->freq_map_size, val); |
Jean Delvare | f6c61cf | 2010-10-28 20:31:50 +0200 | [diff] [blame] | 819 | lm85_write_value(client, LM85_REG_AFAN_RANGE(nr), |
| 820 | (data->zone[nr].range << 4) |
| 821 | | data->pwm_freq[nr]); |
| 822 | if (data->type == adt7468) { |
| 823 | data->cfg5 |= ADT7468_HFPWM; |
| 824 | lm85_write_value(client, ADT7468_REG_CFG5, data->cfg5); |
| 825 | } |
| 826 | } |
Jean Delvare | 34e7dc6 | 2008-10-17 17:51:13 +0200 | [diff] [blame] | 827 | mutex_unlock(&data->update_lock); |
| 828 | return count; |
| 829 | } |
| 830 | |
Guenter Roeck | 7bc85e4 | 2019-01-22 10:40:33 -0800 | [diff] [blame] | 831 | static SENSOR_DEVICE_ATTR_RW(pwm1, pwm, 0); |
| 832 | static SENSOR_DEVICE_ATTR_RW(pwm1_enable, pwm_enable, 0); |
| 833 | static SENSOR_DEVICE_ATTR_RW(pwm1_freq, pwm_freq, 0); |
| 834 | static SENSOR_DEVICE_ATTR_RW(pwm2, pwm, 1); |
| 835 | static SENSOR_DEVICE_ATTR_RW(pwm2_enable, pwm_enable, 1); |
| 836 | static SENSOR_DEVICE_ATTR_RW(pwm2_freq, pwm_freq, 1); |
| 837 | static SENSOR_DEVICE_ATTR_RW(pwm3, pwm, 2); |
| 838 | static SENSOR_DEVICE_ATTR_RW(pwm3_enable, pwm_enable, 2); |
| 839 | static SENSOR_DEVICE_ATTR_RW(pwm3_freq, pwm_freq, 2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 840 | |
| 841 | /* Voltages */ |
| 842 | |
Guenter Roeck | 7bc85e4 | 2019-01-22 10:40:33 -0800 | [diff] [blame] | 843 | static ssize_t in_show(struct device *dev, struct device_attribute *attr, |
| 844 | char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 845 | { |
Jean Delvare | b353a48 | 2007-07-05 20:36:12 +0200 | [diff] [blame] | 846 | int nr = to_sensor_dev_attr(attr)->index; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 847 | struct lm85_data *data = lm85_update_device(dev); |
Jean Delvare | 1f44809 | 2008-04-29 14:03:37 +0200 | [diff] [blame] | 848 | return sprintf(buf, "%d\n", INSEXT_FROM_REG(nr, data->in[nr], |
| 849 | data->in_ext[nr])); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 850 | } |
Jean Delvare | b353a48 | 2007-07-05 20:36:12 +0200 | [diff] [blame] | 851 | |
Guenter Roeck | 7bc85e4 | 2019-01-22 10:40:33 -0800 | [diff] [blame] | 852 | static ssize_t in_min_show(struct device *dev, struct device_attribute *attr, |
| 853 | char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 854 | { |
Jean Delvare | b353a48 | 2007-07-05 20:36:12 +0200 | [diff] [blame] | 855 | int nr = to_sensor_dev_attr(attr)->index; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 856 | struct lm85_data *data = lm85_update_device(dev); |
Jean Delvare | 1f44809 | 2008-04-29 14:03:37 +0200 | [diff] [blame] | 857 | return sprintf(buf, "%d\n", INS_FROM_REG(nr, data->in_min[nr])); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 858 | } |
Jean Delvare | b353a48 | 2007-07-05 20:36:12 +0200 | [diff] [blame] | 859 | |
Guenter Roeck | 7bc85e4 | 2019-01-22 10:40:33 -0800 | [diff] [blame] | 860 | static ssize_t in_min_store(struct device *dev, struct device_attribute *attr, |
| 861 | const char *buf, size_t count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 862 | { |
Jean Delvare | b353a48 | 2007-07-05 20:36:12 +0200 | [diff] [blame] | 863 | int nr = to_sensor_dev_attr(attr)->index; |
Axel Lin | 746f688 | 2014-07-23 12:29:11 +0800 | [diff] [blame] | 864 | struct lm85_data *data = dev_get_drvdata(dev); |
| 865 | struct i2c_client *client = data->client; |
Guenter Roeck | 09770b2 | 2012-01-14 20:47:36 -0800 | [diff] [blame] | 866 | long val; |
| 867 | int err; |
| 868 | |
| 869 | err = kstrtol(buf, 10, &val); |
| 870 | if (err) |
| 871 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 872 | |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 873 | mutex_lock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 874 | data->in_min[nr] = INS_TO_REG(nr, val); |
| 875 | lm85_write_value(client, LM85_REG_IN_MIN(nr), data->in_min[nr]); |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 876 | mutex_unlock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 877 | return count; |
| 878 | } |
Jean Delvare | b353a48 | 2007-07-05 20:36:12 +0200 | [diff] [blame] | 879 | |
Guenter Roeck | 7bc85e4 | 2019-01-22 10:40:33 -0800 | [diff] [blame] | 880 | static ssize_t in_max_show(struct device *dev, struct device_attribute *attr, |
| 881 | char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 882 | { |
Jean Delvare | b353a48 | 2007-07-05 20:36:12 +0200 | [diff] [blame] | 883 | int nr = to_sensor_dev_attr(attr)->index; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 884 | struct lm85_data *data = lm85_update_device(dev); |
Jean Delvare | 1f44809 | 2008-04-29 14:03:37 +0200 | [diff] [blame] | 885 | return sprintf(buf, "%d\n", INS_FROM_REG(nr, data->in_max[nr])); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 886 | } |
Jean Delvare | b353a48 | 2007-07-05 20:36:12 +0200 | [diff] [blame] | 887 | |
Guenter Roeck | 7bc85e4 | 2019-01-22 10:40:33 -0800 | [diff] [blame] | 888 | static ssize_t in_max_store(struct device *dev, struct device_attribute *attr, |
| 889 | const char *buf, size_t count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 890 | { |
Jean Delvare | b353a48 | 2007-07-05 20:36:12 +0200 | [diff] [blame] | 891 | int nr = to_sensor_dev_attr(attr)->index; |
Axel Lin | 746f688 | 2014-07-23 12:29:11 +0800 | [diff] [blame] | 892 | struct lm85_data *data = dev_get_drvdata(dev); |
| 893 | struct i2c_client *client = data->client; |
Guenter Roeck | 09770b2 | 2012-01-14 20:47:36 -0800 | [diff] [blame] | 894 | long val; |
| 895 | int err; |
| 896 | |
| 897 | err = kstrtol(buf, 10, &val); |
| 898 | if (err) |
| 899 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 900 | |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 901 | mutex_lock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 902 | data->in_max[nr] = INS_TO_REG(nr, val); |
| 903 | lm85_write_value(client, LM85_REG_IN_MAX(nr), data->in_max[nr]); |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 904 | mutex_unlock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 905 | return count; |
| 906 | } |
Jean Delvare | b353a48 | 2007-07-05 20:36:12 +0200 | [diff] [blame] | 907 | |
Guenter Roeck | 7bc85e4 | 2019-01-22 10:40:33 -0800 | [diff] [blame] | 908 | static SENSOR_DEVICE_ATTR_RO(in0_input, in, 0); |
| 909 | static SENSOR_DEVICE_ATTR_RW(in0_min, in_min, 0); |
| 910 | static SENSOR_DEVICE_ATTR_RW(in0_max, in_max, 0); |
| 911 | static SENSOR_DEVICE_ATTR_RO(in1_input, in, 1); |
| 912 | static SENSOR_DEVICE_ATTR_RW(in1_min, in_min, 1); |
| 913 | static SENSOR_DEVICE_ATTR_RW(in1_max, in_max, 1); |
| 914 | static SENSOR_DEVICE_ATTR_RO(in2_input, in, 2); |
| 915 | static SENSOR_DEVICE_ATTR_RW(in2_min, in_min, 2); |
| 916 | static SENSOR_DEVICE_ATTR_RW(in2_max, in_max, 2); |
| 917 | static SENSOR_DEVICE_ATTR_RO(in3_input, in, 3); |
| 918 | static SENSOR_DEVICE_ATTR_RW(in3_min, in_min, 3); |
| 919 | static SENSOR_DEVICE_ATTR_RW(in3_max, in_max, 3); |
| 920 | static SENSOR_DEVICE_ATTR_RO(in4_input, in, 4); |
| 921 | static SENSOR_DEVICE_ATTR_RW(in4_min, in_min, 4); |
| 922 | static SENSOR_DEVICE_ATTR_RW(in4_max, in_max, 4); |
| 923 | static SENSOR_DEVICE_ATTR_RO(in5_input, in, 5); |
| 924 | static SENSOR_DEVICE_ATTR_RW(in5_min, in_min, 5); |
| 925 | static SENSOR_DEVICE_ATTR_RW(in5_max, in_max, 5); |
| 926 | static SENSOR_DEVICE_ATTR_RO(in6_input, in, 6); |
| 927 | static SENSOR_DEVICE_ATTR_RW(in6_min, in_min, 6); |
| 928 | static SENSOR_DEVICE_ATTR_RW(in6_max, in_max, 6); |
| 929 | static SENSOR_DEVICE_ATTR_RO(in7_input, in, 7); |
| 930 | static SENSOR_DEVICE_ATTR_RW(in7_min, in_min, 7); |
| 931 | static SENSOR_DEVICE_ATTR_RW(in7_max, in_max, 7); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 932 | |
| 933 | /* Temps */ |
| 934 | |
Guenter Roeck | 7bc85e4 | 2019-01-22 10:40:33 -0800 | [diff] [blame] | 935 | static ssize_t temp_show(struct device *dev, struct device_attribute *attr, |
| 936 | char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 937 | { |
Jean Delvare | b353a48 | 2007-07-05 20:36:12 +0200 | [diff] [blame] | 938 | int nr = to_sensor_dev_attr(attr)->index; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 939 | struct lm85_data *data = lm85_update_device(dev); |
Jean Delvare | 1f44809 | 2008-04-29 14:03:37 +0200 | [diff] [blame] | 940 | return sprintf(buf, "%d\n", TEMPEXT_FROM_REG(data->temp[nr], |
| 941 | data->temp_ext[nr])); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 942 | } |
Jean Delvare | b353a48 | 2007-07-05 20:36:12 +0200 | [diff] [blame] | 943 | |
Guenter Roeck | 7bc85e4 | 2019-01-22 10:40:33 -0800 | [diff] [blame] | 944 | static ssize_t temp_min_show(struct device *dev, |
| 945 | struct device_attribute *attr, char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 946 | { |
Jean Delvare | b353a48 | 2007-07-05 20:36:12 +0200 | [diff] [blame] | 947 | int nr = to_sensor_dev_attr(attr)->index; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 948 | struct lm85_data *data = lm85_update_device(dev); |
Jean Delvare | 1f44809 | 2008-04-29 14:03:37 +0200 | [diff] [blame] | 949 | return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_min[nr])); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 950 | } |
Jean Delvare | b353a48 | 2007-07-05 20:36:12 +0200 | [diff] [blame] | 951 | |
Guenter Roeck | 7bc85e4 | 2019-01-22 10:40:33 -0800 | [diff] [blame] | 952 | static ssize_t temp_min_store(struct device *dev, |
| 953 | struct device_attribute *attr, const char *buf, |
| 954 | size_t count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 955 | { |
Jean Delvare | b353a48 | 2007-07-05 20:36:12 +0200 | [diff] [blame] | 956 | int nr = to_sensor_dev_attr(attr)->index; |
Axel Lin | 746f688 | 2014-07-23 12:29:11 +0800 | [diff] [blame] | 957 | struct lm85_data *data = dev_get_drvdata(dev); |
| 958 | struct i2c_client *client = data->client; |
Guenter Roeck | 09770b2 | 2012-01-14 20:47:36 -0800 | [diff] [blame] | 959 | long val; |
| 960 | int err; |
| 961 | |
| 962 | err = kstrtol(buf, 10, &val); |
| 963 | if (err) |
| 964 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 965 | |
Darrick J. Wong | 79b92f2 | 2008-11-12 13:26:59 -0800 | [diff] [blame] | 966 | if (IS_ADT7468_OFF64(data)) |
| 967 | val += 64; |
| 968 | |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 969 | mutex_lock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 970 | data->temp_min[nr] = TEMP_TO_REG(val); |
| 971 | lm85_write_value(client, LM85_REG_TEMP_MIN(nr), data->temp_min[nr]); |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 972 | mutex_unlock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 973 | return count; |
| 974 | } |
Jean Delvare | b353a48 | 2007-07-05 20:36:12 +0200 | [diff] [blame] | 975 | |
Guenter Roeck | 7bc85e4 | 2019-01-22 10:40:33 -0800 | [diff] [blame] | 976 | static ssize_t temp_max_show(struct device *dev, |
| 977 | struct device_attribute *attr, char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 978 | { |
Jean Delvare | b353a48 | 2007-07-05 20:36:12 +0200 | [diff] [blame] | 979 | int nr = to_sensor_dev_attr(attr)->index; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 980 | struct lm85_data *data = lm85_update_device(dev); |
Jean Delvare | 1f44809 | 2008-04-29 14:03:37 +0200 | [diff] [blame] | 981 | return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_max[nr])); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 982 | } |
Jean Delvare | b353a48 | 2007-07-05 20:36:12 +0200 | [diff] [blame] | 983 | |
Guenter Roeck | 7bc85e4 | 2019-01-22 10:40:33 -0800 | [diff] [blame] | 984 | static ssize_t temp_max_store(struct device *dev, |
| 985 | struct device_attribute *attr, const char *buf, |
| 986 | size_t count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 987 | { |
Jean Delvare | b353a48 | 2007-07-05 20:36:12 +0200 | [diff] [blame] | 988 | int nr = to_sensor_dev_attr(attr)->index; |
Axel Lin | 746f688 | 2014-07-23 12:29:11 +0800 | [diff] [blame] | 989 | struct lm85_data *data = dev_get_drvdata(dev); |
| 990 | struct i2c_client *client = data->client; |
Guenter Roeck | 09770b2 | 2012-01-14 20:47:36 -0800 | [diff] [blame] | 991 | long val; |
| 992 | int err; |
| 993 | |
| 994 | err = kstrtol(buf, 10, &val); |
| 995 | if (err) |
| 996 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 997 | |
Darrick J. Wong | 79b92f2 | 2008-11-12 13:26:59 -0800 | [diff] [blame] | 998 | if (IS_ADT7468_OFF64(data)) |
| 999 | val += 64; |
| 1000 | |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 1001 | mutex_lock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1002 | data->temp_max[nr] = TEMP_TO_REG(val); |
| 1003 | lm85_write_value(client, LM85_REG_TEMP_MAX(nr), data->temp_max[nr]); |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 1004 | mutex_unlock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1005 | return count; |
| 1006 | } |
Jean Delvare | b353a48 | 2007-07-05 20:36:12 +0200 | [diff] [blame] | 1007 | |
Guenter Roeck | 7bc85e4 | 2019-01-22 10:40:33 -0800 | [diff] [blame] | 1008 | static SENSOR_DEVICE_ATTR_RO(temp1_input, temp, 0); |
| 1009 | static SENSOR_DEVICE_ATTR_RW(temp1_min, temp_min, 0); |
| 1010 | static SENSOR_DEVICE_ATTR_RW(temp1_max, temp_max, 0); |
| 1011 | static SENSOR_DEVICE_ATTR_RO(temp2_input, temp, 1); |
| 1012 | static SENSOR_DEVICE_ATTR_RW(temp2_min, temp_min, 1); |
| 1013 | static SENSOR_DEVICE_ATTR_RW(temp2_max, temp_max, 1); |
| 1014 | static SENSOR_DEVICE_ATTR_RO(temp3_input, temp, 2); |
| 1015 | static SENSOR_DEVICE_ATTR_RW(temp3_min, temp_min, 2); |
| 1016 | static SENSOR_DEVICE_ATTR_RW(temp3_max, temp_max, 2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1017 | |
| 1018 | /* Automatic PWM control */ |
| 1019 | |
Guenter Roeck | 7bc85e4 | 2019-01-22 10:40:33 -0800 | [diff] [blame] | 1020 | static ssize_t pwm_auto_channels_show(struct device *dev, |
| 1021 | struct device_attribute *attr, |
| 1022 | char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1023 | { |
Jean Delvare | b353a48 | 2007-07-05 20:36:12 +0200 | [diff] [blame] | 1024 | int nr = to_sensor_dev_attr(attr)->index; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1025 | struct lm85_data *data = lm85_update_device(dev); |
Jean Delvare | 1f44809 | 2008-04-29 14:03:37 +0200 | [diff] [blame] | 1026 | return sprintf(buf, "%d\n", ZONE_FROM_REG(data->autofan[nr].config)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1027 | } |
Jean Delvare | b353a48 | 2007-07-05 20:36:12 +0200 | [diff] [blame] | 1028 | |
Guenter Roeck | 7bc85e4 | 2019-01-22 10:40:33 -0800 | [diff] [blame] | 1029 | static ssize_t pwm_auto_channels_store(struct device *dev, |
| 1030 | struct device_attribute *attr, |
| 1031 | const char *buf, size_t count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1032 | { |
Jean Delvare | b353a48 | 2007-07-05 20:36:12 +0200 | [diff] [blame] | 1033 | int nr = to_sensor_dev_attr(attr)->index; |
Axel Lin | 746f688 | 2014-07-23 12:29:11 +0800 | [diff] [blame] | 1034 | struct lm85_data *data = dev_get_drvdata(dev); |
| 1035 | struct i2c_client *client = data->client; |
Guenter Roeck | 09770b2 | 2012-01-14 20:47:36 -0800 | [diff] [blame] | 1036 | long val; |
| 1037 | int err; |
| 1038 | |
| 1039 | err = kstrtol(buf, 10, &val); |
| 1040 | if (err) |
| 1041 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1042 | |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 1043 | mutex_lock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1044 | data->autofan[nr].config = (data->autofan[nr].config & (~0xe0)) |
Jean Delvare | 1f44809 | 2008-04-29 14:03:37 +0200 | [diff] [blame] | 1045 | | ZONE_TO_REG(val); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1046 | lm85_write_value(client, LM85_REG_AFAN_CONFIG(nr), |
| 1047 | data->autofan[nr].config); |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 1048 | mutex_unlock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1049 | return count; |
| 1050 | } |
Jean Delvare | b353a48 | 2007-07-05 20:36:12 +0200 | [diff] [blame] | 1051 | |
Guenter Roeck | 7bc85e4 | 2019-01-22 10:40:33 -0800 | [diff] [blame] | 1052 | static ssize_t pwm_auto_pwm_min_show(struct device *dev, |
| 1053 | struct device_attribute *attr, char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1054 | { |
Jean Delvare | b353a48 | 2007-07-05 20:36:12 +0200 | [diff] [blame] | 1055 | int nr = to_sensor_dev_attr(attr)->index; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1056 | struct lm85_data *data = lm85_update_device(dev); |
Jean Delvare | 1f44809 | 2008-04-29 14:03:37 +0200 | [diff] [blame] | 1057 | return sprintf(buf, "%d\n", PWM_FROM_REG(data->autofan[nr].min_pwm)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1058 | } |
Jean Delvare | b353a48 | 2007-07-05 20:36:12 +0200 | [diff] [blame] | 1059 | |
Guenter Roeck | 7bc85e4 | 2019-01-22 10:40:33 -0800 | [diff] [blame] | 1060 | static ssize_t pwm_auto_pwm_min_store(struct device *dev, |
| 1061 | struct device_attribute *attr, |
| 1062 | const char *buf, size_t count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1063 | { |
Jean Delvare | b353a48 | 2007-07-05 20:36:12 +0200 | [diff] [blame] | 1064 | int nr = to_sensor_dev_attr(attr)->index; |
Axel Lin | 746f688 | 2014-07-23 12:29:11 +0800 | [diff] [blame] | 1065 | struct lm85_data *data = dev_get_drvdata(dev); |
| 1066 | struct i2c_client *client = data->client; |
Guenter Roeck | 09770b2 | 2012-01-14 20:47:36 -0800 | [diff] [blame] | 1067 | unsigned long val; |
| 1068 | int err; |
| 1069 | |
| 1070 | err = kstrtoul(buf, 10, &val); |
| 1071 | if (err) |
| 1072 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1073 | |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 1074 | mutex_lock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1075 | data->autofan[nr].min_pwm = PWM_TO_REG(val); |
| 1076 | lm85_write_value(client, LM85_REG_AFAN_MINPWM(nr), |
| 1077 | data->autofan[nr].min_pwm); |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 1078 | mutex_unlock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1079 | return count; |
| 1080 | } |
Jean Delvare | b353a48 | 2007-07-05 20:36:12 +0200 | [diff] [blame] | 1081 | |
Guenter Roeck | 7bc85e4 | 2019-01-22 10:40:33 -0800 | [diff] [blame] | 1082 | static ssize_t pwm_auto_pwm_minctl_show(struct device *dev, |
| 1083 | struct device_attribute *attr, |
| 1084 | char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1085 | { |
Jean Delvare | b353a48 | 2007-07-05 20:36:12 +0200 | [diff] [blame] | 1086 | int nr = to_sensor_dev_attr(attr)->index; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1087 | struct lm85_data *data = lm85_update_device(dev); |
Jean Delvare | 1f44809 | 2008-04-29 14:03:37 +0200 | [diff] [blame] | 1088 | return sprintf(buf, "%d\n", data->autofan[nr].min_off); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1089 | } |
Jean Delvare | b353a48 | 2007-07-05 20:36:12 +0200 | [diff] [blame] | 1090 | |
Guenter Roeck | 7bc85e4 | 2019-01-22 10:40:33 -0800 | [diff] [blame] | 1091 | static ssize_t pwm_auto_pwm_minctl_store(struct device *dev, |
| 1092 | struct device_attribute *attr, |
| 1093 | const char *buf, size_t count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1094 | { |
Jean Delvare | b353a48 | 2007-07-05 20:36:12 +0200 | [diff] [blame] | 1095 | int nr = to_sensor_dev_attr(attr)->index; |
Axel Lin | 746f688 | 2014-07-23 12:29:11 +0800 | [diff] [blame] | 1096 | struct lm85_data *data = dev_get_drvdata(dev); |
| 1097 | struct i2c_client *client = data->client; |
Jean Delvare | 7133e56 | 2008-04-12 19:56:35 +0200 | [diff] [blame] | 1098 | u8 tmp; |
Guenter Roeck | 09770b2 | 2012-01-14 20:47:36 -0800 | [diff] [blame] | 1099 | long val; |
| 1100 | int err; |
| 1101 | |
| 1102 | err = kstrtol(buf, 10, &val); |
| 1103 | if (err) |
| 1104 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1105 | |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 1106 | mutex_lock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1107 | data->autofan[nr].min_off = val; |
Jean Delvare | 7133e56 | 2008-04-12 19:56:35 +0200 | [diff] [blame] | 1108 | tmp = lm85_read_value(client, LM85_REG_AFAN_SPIKE1); |
| 1109 | tmp &= ~(0x20 << nr); |
| 1110 | if (data->autofan[nr].min_off) |
| 1111 | tmp |= 0x20 << nr; |
| 1112 | lm85_write_value(client, LM85_REG_AFAN_SPIKE1, tmp); |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 1113 | mutex_unlock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1114 | return count; |
| 1115 | } |
Jean Delvare | b353a48 | 2007-07-05 20:36:12 +0200 | [diff] [blame] | 1116 | |
Guenter Roeck | 7bc85e4 | 2019-01-22 10:40:33 -0800 | [diff] [blame] | 1117 | static SENSOR_DEVICE_ATTR_RW(pwm1_auto_channels, pwm_auto_channels, 0); |
| 1118 | static SENSOR_DEVICE_ATTR_RW(pwm1_auto_pwm_min, pwm_auto_pwm_min, 0); |
| 1119 | static SENSOR_DEVICE_ATTR_RW(pwm1_auto_pwm_minctl, pwm_auto_pwm_minctl, 0); |
| 1120 | static SENSOR_DEVICE_ATTR_RW(pwm2_auto_channels, pwm_auto_channels, 1); |
| 1121 | static SENSOR_DEVICE_ATTR_RW(pwm2_auto_pwm_min, pwm_auto_pwm_min, 1); |
| 1122 | static SENSOR_DEVICE_ATTR_RW(pwm2_auto_pwm_minctl, pwm_auto_pwm_minctl, 1); |
| 1123 | static SENSOR_DEVICE_ATTR_RW(pwm3_auto_channels, pwm_auto_channels, 2); |
| 1124 | static SENSOR_DEVICE_ATTR_RW(pwm3_auto_pwm_min, pwm_auto_pwm_min, 2); |
| 1125 | static SENSOR_DEVICE_ATTR_RW(pwm3_auto_pwm_minctl, pwm_auto_pwm_minctl, 2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1126 | |
| 1127 | /* Temperature settings for automatic PWM control */ |
| 1128 | |
Guenter Roeck | 7bc85e4 | 2019-01-22 10:40:33 -0800 | [diff] [blame] | 1129 | static ssize_t temp_auto_temp_off_show(struct device *dev, |
| 1130 | struct device_attribute *attr, |
| 1131 | char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1132 | { |
Jean Delvare | b353a48 | 2007-07-05 20:36:12 +0200 | [diff] [blame] | 1133 | int nr = to_sensor_dev_attr(attr)->index; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1134 | struct lm85_data *data = lm85_update_device(dev); |
Jean Delvare | 1f44809 | 2008-04-29 14:03:37 +0200 | [diff] [blame] | 1135 | return sprintf(buf, "%d\n", TEMP_FROM_REG(data->zone[nr].limit) - |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1136 | HYST_FROM_REG(data->zone[nr].hyst)); |
| 1137 | } |
Jean Delvare | b353a48 | 2007-07-05 20:36:12 +0200 | [diff] [blame] | 1138 | |
Guenter Roeck | 7bc85e4 | 2019-01-22 10:40:33 -0800 | [diff] [blame] | 1139 | static ssize_t temp_auto_temp_off_store(struct device *dev, |
| 1140 | struct device_attribute *attr, |
| 1141 | const char *buf, size_t count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1142 | { |
Jean Delvare | b353a48 | 2007-07-05 20:36:12 +0200 | [diff] [blame] | 1143 | int nr = to_sensor_dev_attr(attr)->index; |
Axel Lin | 746f688 | 2014-07-23 12:29:11 +0800 | [diff] [blame] | 1144 | struct lm85_data *data = dev_get_drvdata(dev); |
| 1145 | struct i2c_client *client = data->client; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1146 | int min; |
Guenter Roeck | 09770b2 | 2012-01-14 20:47:36 -0800 | [diff] [blame] | 1147 | long val; |
| 1148 | int err; |
| 1149 | |
| 1150 | err = kstrtol(buf, 10, &val); |
| 1151 | if (err) |
| 1152 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1153 | |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 1154 | mutex_lock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1155 | min = TEMP_FROM_REG(data->zone[nr].limit); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1156 | data->zone[nr].hyst = HYST_TO_REG(min - val); |
Jean Delvare | 1f44809 | 2008-04-29 14:03:37 +0200 | [diff] [blame] | 1157 | if (nr == 0 || nr == 1) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1158 | lm85_write_value(client, LM85_REG_AFAN_HYST1, |
| 1159 | (data->zone[0].hyst << 4) |
Jean Delvare | 1f44809 | 2008-04-29 14:03:37 +0200 | [diff] [blame] | 1160 | | data->zone[1].hyst); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1161 | } else { |
| 1162 | lm85_write_value(client, LM85_REG_AFAN_HYST2, |
Jean Delvare | 1f44809 | 2008-04-29 14:03:37 +0200 | [diff] [blame] | 1163 | (data->zone[2].hyst << 4)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1164 | } |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 1165 | mutex_unlock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1166 | return count; |
| 1167 | } |
Jean Delvare | b353a48 | 2007-07-05 20:36:12 +0200 | [diff] [blame] | 1168 | |
Guenter Roeck | 7bc85e4 | 2019-01-22 10:40:33 -0800 | [diff] [blame] | 1169 | static ssize_t temp_auto_temp_min_show(struct device *dev, |
| 1170 | struct device_attribute *attr, |
| 1171 | char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1172 | { |
Jean Delvare | b353a48 | 2007-07-05 20:36:12 +0200 | [diff] [blame] | 1173 | int nr = to_sensor_dev_attr(attr)->index; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1174 | struct lm85_data *data = lm85_update_device(dev); |
Jean Delvare | 1f44809 | 2008-04-29 14:03:37 +0200 | [diff] [blame] | 1175 | return sprintf(buf, "%d\n", TEMP_FROM_REG(data->zone[nr].limit)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1176 | } |
Jean Delvare | b353a48 | 2007-07-05 20:36:12 +0200 | [diff] [blame] | 1177 | |
Guenter Roeck | 7bc85e4 | 2019-01-22 10:40:33 -0800 | [diff] [blame] | 1178 | static ssize_t temp_auto_temp_min_store(struct device *dev, |
| 1179 | struct device_attribute *attr, |
| 1180 | const char *buf, size_t count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1181 | { |
Jean Delvare | b353a48 | 2007-07-05 20:36:12 +0200 | [diff] [blame] | 1182 | int nr = to_sensor_dev_attr(attr)->index; |
Axel Lin | 746f688 | 2014-07-23 12:29:11 +0800 | [diff] [blame] | 1183 | struct lm85_data *data = dev_get_drvdata(dev); |
| 1184 | struct i2c_client *client = data->client; |
Guenter Roeck | 09770b2 | 2012-01-14 20:47:36 -0800 | [diff] [blame] | 1185 | long val; |
| 1186 | int err; |
| 1187 | |
| 1188 | err = kstrtol(buf, 10, &val); |
| 1189 | if (err) |
| 1190 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1191 | |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 1192 | mutex_lock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1193 | data->zone[nr].limit = TEMP_TO_REG(val); |
| 1194 | lm85_write_value(client, LM85_REG_AFAN_LIMIT(nr), |
| 1195 | data->zone[nr].limit); |
| 1196 | |
| 1197 | /* Update temp_auto_max and temp_auto_range */ |
| 1198 | data->zone[nr].range = RANGE_TO_REG( |
| 1199 | TEMP_FROM_REG(data->zone[nr].max_desired) - |
| 1200 | TEMP_FROM_REG(data->zone[nr].limit)); |
| 1201 | lm85_write_value(client, LM85_REG_AFAN_RANGE(nr), |
| 1202 | ((data->zone[nr].range & 0x0f) << 4) |
Jeremy Gebben | 57bc301 | 2019-02-04 13:19:03 -0700 | [diff] [blame] | 1203 | | data->pwm_freq[nr]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1204 | |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 1205 | mutex_unlock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1206 | return count; |
| 1207 | } |
Jean Delvare | b353a48 | 2007-07-05 20:36:12 +0200 | [diff] [blame] | 1208 | |
Guenter Roeck | 7bc85e4 | 2019-01-22 10:40:33 -0800 | [diff] [blame] | 1209 | static ssize_t temp_auto_temp_max_show(struct device *dev, |
| 1210 | struct device_attribute *attr, |
| 1211 | char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1212 | { |
Jean Delvare | b353a48 | 2007-07-05 20:36:12 +0200 | [diff] [blame] | 1213 | int nr = to_sensor_dev_attr(attr)->index; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1214 | struct lm85_data *data = lm85_update_device(dev); |
Jean Delvare | 1f44809 | 2008-04-29 14:03:37 +0200 | [diff] [blame] | 1215 | return sprintf(buf, "%d\n", TEMP_FROM_REG(data->zone[nr].limit) + |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1216 | RANGE_FROM_REG(data->zone[nr].range)); |
| 1217 | } |
Jean Delvare | b353a48 | 2007-07-05 20:36:12 +0200 | [diff] [blame] | 1218 | |
Guenter Roeck | 7bc85e4 | 2019-01-22 10:40:33 -0800 | [diff] [blame] | 1219 | static ssize_t temp_auto_temp_max_store(struct device *dev, |
| 1220 | struct device_attribute *attr, |
| 1221 | const char *buf, size_t count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1222 | { |
Jean Delvare | b353a48 | 2007-07-05 20:36:12 +0200 | [diff] [blame] | 1223 | int nr = to_sensor_dev_attr(attr)->index; |
Axel Lin | 746f688 | 2014-07-23 12:29:11 +0800 | [diff] [blame] | 1224 | struct lm85_data *data = dev_get_drvdata(dev); |
| 1225 | struct i2c_client *client = data->client; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1226 | int min; |
Guenter Roeck | 09770b2 | 2012-01-14 20:47:36 -0800 | [diff] [blame] | 1227 | long val; |
| 1228 | int err; |
| 1229 | |
| 1230 | err = kstrtol(buf, 10, &val); |
| 1231 | if (err) |
| 1232 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1233 | |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 1234 | mutex_lock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1235 | min = TEMP_FROM_REG(data->zone[nr].limit); |
| 1236 | data->zone[nr].max_desired = TEMP_TO_REG(val); |
| 1237 | data->zone[nr].range = RANGE_TO_REG( |
| 1238 | val - min); |
| 1239 | lm85_write_value(client, LM85_REG_AFAN_RANGE(nr), |
| 1240 | ((data->zone[nr].range & 0x0f) << 4) |
Jeremy Gebben | 57bc301 | 2019-02-04 13:19:03 -0700 | [diff] [blame] | 1241 | | data->pwm_freq[nr]); |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 1242 | mutex_unlock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1243 | return count; |
| 1244 | } |
Jean Delvare | b353a48 | 2007-07-05 20:36:12 +0200 | [diff] [blame] | 1245 | |
Guenter Roeck | 7bc85e4 | 2019-01-22 10:40:33 -0800 | [diff] [blame] | 1246 | static ssize_t temp_auto_temp_crit_show(struct device *dev, |
| 1247 | struct device_attribute *attr, |
| 1248 | char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1249 | { |
Jean Delvare | b353a48 | 2007-07-05 20:36:12 +0200 | [diff] [blame] | 1250 | int nr = to_sensor_dev_attr(attr)->index; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1251 | struct lm85_data *data = lm85_update_device(dev); |
Jean Delvare | 1f44809 | 2008-04-29 14:03:37 +0200 | [diff] [blame] | 1252 | return sprintf(buf, "%d\n", TEMP_FROM_REG(data->zone[nr].critical)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1253 | } |
Jean Delvare | b353a48 | 2007-07-05 20:36:12 +0200 | [diff] [blame] | 1254 | |
Guenter Roeck | 7bc85e4 | 2019-01-22 10:40:33 -0800 | [diff] [blame] | 1255 | static ssize_t temp_auto_temp_crit_store(struct device *dev, |
| 1256 | struct device_attribute *attr, |
| 1257 | const char *buf, size_t count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1258 | { |
Jean Delvare | b353a48 | 2007-07-05 20:36:12 +0200 | [diff] [blame] | 1259 | int nr = to_sensor_dev_attr(attr)->index; |
Axel Lin | 746f688 | 2014-07-23 12:29:11 +0800 | [diff] [blame] | 1260 | struct lm85_data *data = dev_get_drvdata(dev); |
| 1261 | struct i2c_client *client = data->client; |
Guenter Roeck | 09770b2 | 2012-01-14 20:47:36 -0800 | [diff] [blame] | 1262 | long val; |
| 1263 | int err; |
| 1264 | |
| 1265 | err = kstrtol(buf, 10, &val); |
| 1266 | if (err) |
| 1267 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1268 | |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 1269 | mutex_lock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1270 | data->zone[nr].critical = TEMP_TO_REG(val); |
| 1271 | lm85_write_value(client, LM85_REG_AFAN_CRITICAL(nr), |
| 1272 | data->zone[nr].critical); |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 1273 | mutex_unlock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1274 | return count; |
| 1275 | } |
Jean Delvare | b353a48 | 2007-07-05 20:36:12 +0200 | [diff] [blame] | 1276 | |
Guenter Roeck | 7bc85e4 | 2019-01-22 10:40:33 -0800 | [diff] [blame] | 1277 | static SENSOR_DEVICE_ATTR_RW(temp1_auto_temp_off, temp_auto_temp_off, 0); |
| 1278 | static SENSOR_DEVICE_ATTR_RW(temp1_auto_temp_min, temp_auto_temp_min, 0); |
| 1279 | static SENSOR_DEVICE_ATTR_RW(temp1_auto_temp_max, temp_auto_temp_max, 0); |
| 1280 | static SENSOR_DEVICE_ATTR_RW(temp1_auto_temp_crit, temp_auto_temp_crit, 0); |
| 1281 | static SENSOR_DEVICE_ATTR_RW(temp2_auto_temp_off, temp_auto_temp_off, 1); |
| 1282 | static SENSOR_DEVICE_ATTR_RW(temp2_auto_temp_min, temp_auto_temp_min, 1); |
| 1283 | static SENSOR_DEVICE_ATTR_RW(temp2_auto_temp_max, temp_auto_temp_max, 1); |
| 1284 | static SENSOR_DEVICE_ATTR_RW(temp2_auto_temp_crit, temp_auto_temp_crit, 1); |
| 1285 | static SENSOR_DEVICE_ATTR_RW(temp3_auto_temp_off, temp_auto_temp_off, 2); |
| 1286 | static SENSOR_DEVICE_ATTR_RW(temp3_auto_temp_min, temp_auto_temp_min, 2); |
| 1287 | static SENSOR_DEVICE_ATTR_RW(temp3_auto_temp_max, temp_auto_temp_max, 2); |
| 1288 | static SENSOR_DEVICE_ATTR_RW(temp3_auto_temp_crit, temp_auto_temp_crit, 2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1289 | |
Mark M. Hoffman | 0501a38 | 2006-09-24 21:14:35 +0200 | [diff] [blame] | 1290 | static struct attribute *lm85_attributes[] = { |
Jean Delvare | b353a48 | 2007-07-05 20:36:12 +0200 | [diff] [blame] | 1291 | &sensor_dev_attr_fan1_input.dev_attr.attr, |
| 1292 | &sensor_dev_attr_fan2_input.dev_attr.attr, |
| 1293 | &sensor_dev_attr_fan3_input.dev_attr.attr, |
| 1294 | &sensor_dev_attr_fan4_input.dev_attr.attr, |
| 1295 | &sensor_dev_attr_fan1_min.dev_attr.attr, |
| 1296 | &sensor_dev_attr_fan2_min.dev_attr.attr, |
| 1297 | &sensor_dev_attr_fan3_min.dev_attr.attr, |
| 1298 | &sensor_dev_attr_fan4_min.dev_attr.attr, |
Jean Delvare | bf76e9d | 2007-07-05 20:37:58 +0200 | [diff] [blame] | 1299 | &sensor_dev_attr_fan1_alarm.dev_attr.attr, |
| 1300 | &sensor_dev_attr_fan2_alarm.dev_attr.attr, |
| 1301 | &sensor_dev_attr_fan3_alarm.dev_attr.attr, |
| 1302 | &sensor_dev_attr_fan4_alarm.dev_attr.attr, |
Jean Delvare | b353a48 | 2007-07-05 20:36:12 +0200 | [diff] [blame] | 1303 | |
| 1304 | &sensor_dev_attr_pwm1.dev_attr.attr, |
| 1305 | &sensor_dev_attr_pwm2.dev_attr.attr, |
| 1306 | &sensor_dev_attr_pwm3.dev_attr.attr, |
| 1307 | &sensor_dev_attr_pwm1_enable.dev_attr.attr, |
| 1308 | &sensor_dev_attr_pwm2_enable.dev_attr.attr, |
| 1309 | &sensor_dev_attr_pwm3_enable.dev_attr.attr, |
Jean Delvare | 34e7dc6 | 2008-10-17 17:51:13 +0200 | [diff] [blame] | 1310 | &sensor_dev_attr_pwm1_freq.dev_attr.attr, |
| 1311 | &sensor_dev_attr_pwm2_freq.dev_attr.attr, |
| 1312 | &sensor_dev_attr_pwm3_freq.dev_attr.attr, |
Jean Delvare | b353a48 | 2007-07-05 20:36:12 +0200 | [diff] [blame] | 1313 | |
| 1314 | &sensor_dev_attr_in0_input.dev_attr.attr, |
| 1315 | &sensor_dev_attr_in1_input.dev_attr.attr, |
| 1316 | &sensor_dev_attr_in2_input.dev_attr.attr, |
| 1317 | &sensor_dev_attr_in3_input.dev_attr.attr, |
| 1318 | &sensor_dev_attr_in0_min.dev_attr.attr, |
| 1319 | &sensor_dev_attr_in1_min.dev_attr.attr, |
| 1320 | &sensor_dev_attr_in2_min.dev_attr.attr, |
| 1321 | &sensor_dev_attr_in3_min.dev_attr.attr, |
| 1322 | &sensor_dev_attr_in0_max.dev_attr.attr, |
| 1323 | &sensor_dev_attr_in1_max.dev_attr.attr, |
| 1324 | &sensor_dev_attr_in2_max.dev_attr.attr, |
| 1325 | &sensor_dev_attr_in3_max.dev_attr.attr, |
Jean Delvare | bf76e9d | 2007-07-05 20:37:58 +0200 | [diff] [blame] | 1326 | &sensor_dev_attr_in0_alarm.dev_attr.attr, |
| 1327 | &sensor_dev_attr_in1_alarm.dev_attr.attr, |
| 1328 | &sensor_dev_attr_in2_alarm.dev_attr.attr, |
| 1329 | &sensor_dev_attr_in3_alarm.dev_attr.attr, |
Jean Delvare | b353a48 | 2007-07-05 20:36:12 +0200 | [diff] [blame] | 1330 | |
| 1331 | &sensor_dev_attr_temp1_input.dev_attr.attr, |
| 1332 | &sensor_dev_attr_temp2_input.dev_attr.attr, |
| 1333 | &sensor_dev_attr_temp3_input.dev_attr.attr, |
| 1334 | &sensor_dev_attr_temp1_min.dev_attr.attr, |
| 1335 | &sensor_dev_attr_temp2_min.dev_attr.attr, |
| 1336 | &sensor_dev_attr_temp3_min.dev_attr.attr, |
| 1337 | &sensor_dev_attr_temp1_max.dev_attr.attr, |
| 1338 | &sensor_dev_attr_temp2_max.dev_attr.attr, |
| 1339 | &sensor_dev_attr_temp3_max.dev_attr.attr, |
Jean Delvare | bf76e9d | 2007-07-05 20:37:58 +0200 | [diff] [blame] | 1340 | &sensor_dev_attr_temp1_alarm.dev_attr.attr, |
| 1341 | &sensor_dev_attr_temp2_alarm.dev_attr.attr, |
| 1342 | &sensor_dev_attr_temp3_alarm.dev_attr.attr, |
| 1343 | &sensor_dev_attr_temp1_fault.dev_attr.attr, |
| 1344 | &sensor_dev_attr_temp3_fault.dev_attr.attr, |
Jean Delvare | b353a48 | 2007-07-05 20:36:12 +0200 | [diff] [blame] | 1345 | |
| 1346 | &sensor_dev_attr_pwm1_auto_channels.dev_attr.attr, |
| 1347 | &sensor_dev_attr_pwm2_auto_channels.dev_attr.attr, |
| 1348 | &sensor_dev_attr_pwm3_auto_channels.dev_attr.attr, |
| 1349 | &sensor_dev_attr_pwm1_auto_pwm_min.dev_attr.attr, |
| 1350 | &sensor_dev_attr_pwm2_auto_pwm_min.dev_attr.attr, |
| 1351 | &sensor_dev_attr_pwm3_auto_pwm_min.dev_attr.attr, |
Jean Delvare | b353a48 | 2007-07-05 20:36:12 +0200 | [diff] [blame] | 1352 | |
Jean Delvare | b353a48 | 2007-07-05 20:36:12 +0200 | [diff] [blame] | 1353 | &sensor_dev_attr_temp1_auto_temp_min.dev_attr.attr, |
| 1354 | &sensor_dev_attr_temp2_auto_temp_min.dev_attr.attr, |
| 1355 | &sensor_dev_attr_temp3_auto_temp_min.dev_attr.attr, |
| 1356 | &sensor_dev_attr_temp1_auto_temp_max.dev_attr.attr, |
| 1357 | &sensor_dev_attr_temp2_auto_temp_max.dev_attr.attr, |
| 1358 | &sensor_dev_attr_temp3_auto_temp_max.dev_attr.attr, |
| 1359 | &sensor_dev_attr_temp1_auto_temp_crit.dev_attr.attr, |
| 1360 | &sensor_dev_attr_temp2_auto_temp_crit.dev_attr.attr, |
| 1361 | &sensor_dev_attr_temp3_auto_temp_crit.dev_attr.attr, |
| 1362 | |
Mark M. Hoffman | 0501a38 | 2006-09-24 21:14:35 +0200 | [diff] [blame] | 1363 | &dev_attr_vrm.attr, |
| 1364 | &dev_attr_cpu0_vid.attr, |
| 1365 | &dev_attr_alarms.attr, |
Mark M. Hoffman | 0501a38 | 2006-09-24 21:14:35 +0200 | [diff] [blame] | 1366 | NULL |
| 1367 | }; |
| 1368 | |
| 1369 | static const struct attribute_group lm85_group = { |
| 1370 | .attrs = lm85_attributes, |
| 1371 | }; |
| 1372 | |
Guenter Roeck | 06923f8 | 2011-02-19 08:27:47 -0800 | [diff] [blame] | 1373 | static struct attribute *lm85_attributes_minctl[] = { |
| 1374 | &sensor_dev_attr_pwm1_auto_pwm_minctl.dev_attr.attr, |
| 1375 | &sensor_dev_attr_pwm2_auto_pwm_minctl.dev_attr.attr, |
| 1376 | &sensor_dev_attr_pwm3_auto_pwm_minctl.dev_attr.attr, |
Jean Delvare | 5f441e2 | 2011-04-29 16:33:36 +0200 | [diff] [blame] | 1377 | NULL |
Guenter Roeck | 06923f8 | 2011-02-19 08:27:47 -0800 | [diff] [blame] | 1378 | }; |
| 1379 | |
| 1380 | static const struct attribute_group lm85_group_minctl = { |
| 1381 | .attrs = lm85_attributes_minctl, |
| 1382 | }; |
| 1383 | |
| 1384 | static struct attribute *lm85_attributes_temp_off[] = { |
| 1385 | &sensor_dev_attr_temp1_auto_temp_off.dev_attr.attr, |
| 1386 | &sensor_dev_attr_temp2_auto_temp_off.dev_attr.attr, |
| 1387 | &sensor_dev_attr_temp3_auto_temp_off.dev_attr.attr, |
Jean Delvare | 5f441e2 | 2011-04-29 16:33:36 +0200 | [diff] [blame] | 1388 | NULL |
Guenter Roeck | 06923f8 | 2011-02-19 08:27:47 -0800 | [diff] [blame] | 1389 | }; |
| 1390 | |
| 1391 | static const struct attribute_group lm85_group_temp_off = { |
| 1392 | .attrs = lm85_attributes_temp_off, |
| 1393 | }; |
| 1394 | |
Jean Delvare | 6b9aad2 | 2007-07-05 20:37:21 +0200 | [diff] [blame] | 1395 | static struct attribute *lm85_attributes_in4[] = { |
Jean Delvare | b353a48 | 2007-07-05 20:36:12 +0200 | [diff] [blame] | 1396 | &sensor_dev_attr_in4_input.dev_attr.attr, |
| 1397 | &sensor_dev_attr_in4_min.dev_attr.attr, |
| 1398 | &sensor_dev_attr_in4_max.dev_attr.attr, |
Jean Delvare | bf76e9d | 2007-07-05 20:37:58 +0200 | [diff] [blame] | 1399 | &sensor_dev_attr_in4_alarm.dev_attr.attr, |
Mark M. Hoffman | 0501a38 | 2006-09-24 21:14:35 +0200 | [diff] [blame] | 1400 | NULL |
| 1401 | }; |
| 1402 | |
Jean Delvare | 6b9aad2 | 2007-07-05 20:37:21 +0200 | [diff] [blame] | 1403 | static const struct attribute_group lm85_group_in4 = { |
| 1404 | .attrs = lm85_attributes_in4, |
| 1405 | }; |
| 1406 | |
| 1407 | static struct attribute *lm85_attributes_in567[] = { |
| 1408 | &sensor_dev_attr_in5_input.dev_attr.attr, |
| 1409 | &sensor_dev_attr_in6_input.dev_attr.attr, |
| 1410 | &sensor_dev_attr_in7_input.dev_attr.attr, |
| 1411 | &sensor_dev_attr_in5_min.dev_attr.attr, |
| 1412 | &sensor_dev_attr_in6_min.dev_attr.attr, |
| 1413 | &sensor_dev_attr_in7_min.dev_attr.attr, |
| 1414 | &sensor_dev_attr_in5_max.dev_attr.attr, |
| 1415 | &sensor_dev_attr_in6_max.dev_attr.attr, |
| 1416 | &sensor_dev_attr_in7_max.dev_attr.attr, |
Jean Delvare | bf76e9d | 2007-07-05 20:37:58 +0200 | [diff] [blame] | 1417 | &sensor_dev_attr_in5_alarm.dev_attr.attr, |
| 1418 | &sensor_dev_attr_in6_alarm.dev_attr.attr, |
| 1419 | &sensor_dev_attr_in7_alarm.dev_attr.attr, |
Jean Delvare | 6b9aad2 | 2007-07-05 20:37:21 +0200 | [diff] [blame] | 1420 | NULL |
| 1421 | }; |
| 1422 | |
| 1423 | static const struct attribute_group lm85_group_in567 = { |
| 1424 | .attrs = lm85_attributes_in567, |
Mark M. Hoffman | 0501a38 | 2006-09-24 21:14:35 +0200 | [diff] [blame] | 1425 | }; |
| 1426 | |
Jean Delvare | 5f4475947 | 2008-06-25 09:10:30 -0400 | [diff] [blame] | 1427 | static void lm85_init_client(struct i2c_client *client) |
| 1428 | { |
| 1429 | int value; |
| 1430 | |
| 1431 | /* Start monitoring if needed */ |
| 1432 | value = lm85_read_value(client, LM85_REG_CONFIG); |
| 1433 | if (!(value & 0x01)) { |
| 1434 | dev_info(&client->dev, "Starting monitoring\n"); |
| 1435 | lm85_write_value(client, LM85_REG_CONFIG, value | 0x01); |
| 1436 | } |
| 1437 | |
| 1438 | /* Warn about unusual configuration bits */ |
| 1439 | if (value & 0x02) |
| 1440 | dev_warn(&client->dev, "Device configuration is locked\n"); |
| 1441 | if (!(value & 0x04)) |
| 1442 | dev_warn(&client->dev, "Device is not ready\n"); |
| 1443 | } |
| 1444 | |
Jean Delvare | 5cfaf33 | 2009-09-15 17:18:14 +0200 | [diff] [blame] | 1445 | static int lm85_is_fake(struct i2c_client *client) |
| 1446 | { |
| 1447 | /* |
| 1448 | * Differenciate between real LM96000 and Winbond WPCD377I. The latter |
| 1449 | * emulate the former except that it has no hardware monitoring function |
| 1450 | * so the readings are always 0. |
| 1451 | */ |
| 1452 | int i; |
| 1453 | u8 in_temp, fan; |
| 1454 | |
| 1455 | for (i = 0; i < 8; i++) { |
| 1456 | in_temp = i2c_smbus_read_byte_data(client, 0x20 + i); |
| 1457 | fan = i2c_smbus_read_byte_data(client, 0x28 + i); |
| 1458 | if (in_temp != 0x00 || fan != 0xff) |
| 1459 | return 0; |
| 1460 | } |
| 1461 | |
| 1462 | return 1; |
| 1463 | } |
| 1464 | |
Jean Delvare | 67712d0 | 2008-10-17 17:51:14 +0200 | [diff] [blame] | 1465 | /* Return 0 if detection is successful, -ENODEV otherwise */ |
Jean Delvare | 310ec79 | 2009-12-14 21:17:23 +0100 | [diff] [blame] | 1466 | static int lm85_detect(struct i2c_client *client, struct i2c_board_info *info) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1467 | { |
Jean Delvare | 67712d0 | 2008-10-17 17:51:14 +0200 | [diff] [blame] | 1468 | struct i2c_adapter *adapter = client->adapter; |
| 1469 | int address = client->addr; |
Jean Delvare | 590e853 | 2014-06-11 18:35:56 +0200 | [diff] [blame] | 1470 | const char *type_name = NULL; |
Jean Delvare | d42a2eb | 2009-12-09 20:35:53 +0100 | [diff] [blame] | 1471 | int company, verstep; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1472 | |
Jean Delvare | e89e22b | 2008-06-25 08:47:35 -0400 | [diff] [blame] | 1473 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1474 | /* We need to be able to do byte I/O */ |
Jean Delvare | 67712d0 | 2008-10-17 17:51:14 +0200 | [diff] [blame] | 1475 | return -ENODEV; |
Jean Delvare | 1f44809 | 2008-04-29 14:03:37 +0200 | [diff] [blame] | 1476 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1477 | |
Jean Delvare | d42a2eb | 2009-12-09 20:35:53 +0100 | [diff] [blame] | 1478 | /* Determine the chip type */ |
| 1479 | company = lm85_read_value(client, LM85_REG_COMPANY); |
| 1480 | verstep = lm85_read_value(client, LM85_REG_VERSTEP); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1481 | |
Guenter Roeck | b55f375 | 2013-01-10 10:01:24 -0800 | [diff] [blame] | 1482 | dev_dbg(&adapter->dev, |
| 1483 | "Detecting device at 0x%02x with COMPANY: 0x%02x and VERSTEP: 0x%02x\n", |
Jean Delvare | d42a2eb | 2009-12-09 20:35:53 +0100 | [diff] [blame] | 1484 | address, company, verstep); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1485 | |
Jean Delvare | d42a2eb | 2009-12-09 20:35:53 +0100 | [diff] [blame] | 1486 | if (company == LM85_COMPANY_NATIONAL) { |
| 1487 | switch (verstep) { |
| 1488 | case LM85_VERSTEP_LM85C: |
| 1489 | type_name = "lm85c"; |
| 1490 | break; |
| 1491 | case LM85_VERSTEP_LM85B: |
| 1492 | type_name = "lm85b"; |
| 1493 | break; |
| 1494 | case LM85_VERSTEP_LM96000_1: |
| 1495 | case LM85_VERSTEP_LM96000_2: |
| 1496 | /* Check for Winbond WPCD377I */ |
| 1497 | if (lm85_is_fake(client)) { |
| 1498 | dev_dbg(&adapter->dev, |
| 1499 | "Found Winbond WPCD377I, ignoring\n"); |
| 1500 | return -ENODEV; |
| 1501 | } |
Jeremy Gebben | 11650cf | 2019-02-04 13:19:05 -0700 | [diff] [blame] | 1502 | type_name = "lm96000"; |
Jean Delvare | d42a2eb | 2009-12-09 20:35:53 +0100 | [diff] [blame] | 1503 | break; |
Jean Delvare | 69fc1fe | 2008-10-17 17:51:13 +0200 | [diff] [blame] | 1504 | } |
Jean Delvare | d42a2eb | 2009-12-09 20:35:53 +0100 | [diff] [blame] | 1505 | } else if (company == LM85_COMPANY_ANALOG_DEV) { |
| 1506 | switch (verstep) { |
| 1507 | case LM85_VERSTEP_ADM1027: |
| 1508 | type_name = "adm1027"; |
| 1509 | break; |
| 1510 | case LM85_VERSTEP_ADT7463: |
| 1511 | case LM85_VERSTEP_ADT7463C: |
| 1512 | type_name = "adt7463"; |
| 1513 | break; |
| 1514 | case LM85_VERSTEP_ADT7468_1: |
| 1515 | case LM85_VERSTEP_ADT7468_2: |
| 1516 | type_name = "adt7468"; |
| 1517 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1518 | } |
Jean Delvare | d42a2eb | 2009-12-09 20:35:53 +0100 | [diff] [blame] | 1519 | } else if (company == LM85_COMPANY_SMSC) { |
| 1520 | switch (verstep) { |
| 1521 | case LM85_VERSTEP_EMC6D100_A0: |
| 1522 | case LM85_VERSTEP_EMC6D100_A1: |
| 1523 | /* Note: we can't tell a '100 from a '101 */ |
| 1524 | type_name = "emc6d100"; |
| 1525 | break; |
| 1526 | case LM85_VERSTEP_EMC6D102: |
| 1527 | type_name = "emc6d102"; |
| 1528 | break; |
Jan Beulich | f065a93 | 2011-02-18 03:18:26 -0500 | [diff] [blame] | 1529 | case LM85_VERSTEP_EMC6D103_A0: |
| 1530 | case LM85_VERSTEP_EMC6D103_A1: |
| 1531 | type_name = "emc6d103"; |
| 1532 | break; |
Jan Beulich | f065a93 | 2011-02-18 03:18:26 -0500 | [diff] [blame] | 1533 | case LM85_VERSTEP_EMC6D103S: |
| 1534 | type_name = "emc6d103s"; |
| 1535 | break; |
Jean Delvare | d42a2eb | 2009-12-09 20:35:53 +0100 | [diff] [blame] | 1536 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1537 | } |
| 1538 | |
Jean Delvare | 590e853 | 2014-06-11 18:35:56 +0200 | [diff] [blame] | 1539 | if (!type_name) |
| 1540 | return -ENODEV; |
| 1541 | |
Jean Delvare | 67712d0 | 2008-10-17 17:51:14 +0200 | [diff] [blame] | 1542 | strlcpy(info->type, type_name, I2C_NAME_SIZE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1543 | |
Jean Delvare | 67712d0 | 2008-10-17 17:51:14 +0200 | [diff] [blame] | 1544 | return 0; |
| 1545 | } |
| 1546 | |
Stephen Kitt | 6748703 | 2020-08-13 18:02:22 +0200 | [diff] [blame] | 1547 | static const struct i2c_device_id lm85_id[]; |
| 1548 | |
| 1549 | static int lm85_probe(struct i2c_client *client) |
Guenter Roeck | bc6db2b | 2011-02-25 08:26:47 -0800 | [diff] [blame] | 1550 | { |
Axel Lin | 746f688 | 2014-07-23 12:29:11 +0800 | [diff] [blame] | 1551 | struct device *dev = &client->dev; |
| 1552 | struct device *hwmon_dev; |
Jean Delvare | 67712d0 | 2008-10-17 17:51:14 +0200 | [diff] [blame] | 1553 | struct lm85_data *data; |
Axel Lin | 746f688 | 2014-07-23 12:29:11 +0800 | [diff] [blame] | 1554 | int idx = 0; |
Jean Delvare | 67712d0 | 2008-10-17 17:51:14 +0200 | [diff] [blame] | 1555 | |
Axel Lin | 746f688 | 2014-07-23 12:29:11 +0800 | [diff] [blame] | 1556 | data = devm_kzalloc(dev, sizeof(struct lm85_data), GFP_KERNEL); |
Jean Delvare | 67712d0 | 2008-10-17 17:51:14 +0200 | [diff] [blame] | 1557 | if (!data) |
| 1558 | return -ENOMEM; |
| 1559 | |
Axel Lin | 746f688 | 2014-07-23 12:29:11 +0800 | [diff] [blame] | 1560 | data->client = client; |
Javier Martinez Canillas | 00c0f9d | 2017-02-24 10:13:03 -0300 | [diff] [blame] | 1561 | if (client->dev.of_node) |
| 1562 | data->type = (enum chips)of_device_get_match_data(&client->dev); |
| 1563 | else |
Stephen Kitt | 6748703 | 2020-08-13 18:02:22 +0200 | [diff] [blame] | 1564 | data->type = i2c_match_id(lm85_id, client)->driver_data; |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 1565 | mutex_init(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1566 | |
Jean Delvare | 67712d0 | 2008-10-17 17:51:14 +0200 | [diff] [blame] | 1567 | /* Fill in the chip specific driver values */ |
| 1568 | switch (data->type) { |
| 1569 | case adm1027: |
| 1570 | case adt7463: |
Jean Delvare | fa7a579 | 2010-10-28 20:31:50 +0200 | [diff] [blame] | 1571 | case adt7468: |
Jean Delvare | 67712d0 | 2008-10-17 17:51:14 +0200 | [diff] [blame] | 1572 | case emc6d100: |
| 1573 | case emc6d102: |
Jan Beulich | f065a93 | 2011-02-18 03:18:26 -0500 | [diff] [blame] | 1574 | case emc6d103: |
Guenter Roeck | 06923f8 | 2011-02-19 08:27:47 -0800 | [diff] [blame] | 1575 | case emc6d103s: |
Jean Delvare | 67712d0 | 2008-10-17 17:51:14 +0200 | [diff] [blame] | 1576 | data->freq_map = adm1027_freq_map; |
Jeremy Gebben | 57bc301 | 2019-02-04 13:19:03 -0700 | [diff] [blame] | 1577 | data->freq_map_size = ARRAY_SIZE(adm1027_freq_map); |
Jean Delvare | 67712d0 | 2008-10-17 17:51:14 +0200 | [diff] [blame] | 1578 | break; |
Jeremy Gebben | e9b9548 | 2019-02-04 13:19:06 -0700 | [diff] [blame] | 1579 | case lm96000: |
| 1580 | data->freq_map = lm96000_freq_map; |
| 1581 | data->freq_map_size = ARRAY_SIZE(lm96000_freq_map); |
| 1582 | break; |
Jean Delvare | 67712d0 | 2008-10-17 17:51:14 +0200 | [diff] [blame] | 1583 | default: |
| 1584 | data->freq_map = lm85_freq_map; |
Jeremy Gebben | 57bc301 | 2019-02-04 13:19:03 -0700 | [diff] [blame] | 1585 | data->freq_map_size = ARRAY_SIZE(lm85_freq_map); |
Jean Delvare | 67712d0 | 2008-10-17 17:51:14 +0200 | [diff] [blame] | 1586 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1587 | |
| 1588 | /* Set the VRM version */ |
Jean Delvare | 303760b | 2005-07-31 21:52:01 +0200 | [diff] [blame] | 1589 | data->vrm = vid_which_vrm(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1590 | |
| 1591 | /* Initialize the LM85 chip */ |
Jean Delvare | e89e22b | 2008-06-25 08:47:35 -0400 | [diff] [blame] | 1592 | lm85_init_client(client); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1593 | |
Axel Lin | 746f688 | 2014-07-23 12:29:11 +0800 | [diff] [blame] | 1594 | /* sysfs hooks */ |
| 1595 | data->groups[idx++] = &lm85_group; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1596 | |
Guenter Roeck | 06923f8 | 2011-02-19 08:27:47 -0800 | [diff] [blame] | 1597 | /* minctl and temp_off exist on all chips except emc6d103s */ |
| 1598 | if (data->type != emc6d103s) { |
Axel Lin | 746f688 | 2014-07-23 12:29:11 +0800 | [diff] [blame] | 1599 | data->groups[idx++] = &lm85_group_minctl; |
| 1600 | data->groups[idx++] = &lm85_group_temp_off; |
Guenter Roeck | 06923f8 | 2011-02-19 08:27:47 -0800 | [diff] [blame] | 1601 | } |
| 1602 | |
Guenter Roeck | 09770b2 | 2012-01-14 20:47:36 -0800 | [diff] [blame] | 1603 | /* |
| 1604 | * The ADT7463/68 have an optional VRM 10 mode where pin 21 is used |
| 1605 | * as a sixth digital VID input rather than an analog input. |
| 1606 | */ |
Guenter Roeck | de24880 | 2011-02-25 08:19:42 -0800 | [diff] [blame] | 1607 | if (data->type == adt7463 || data->type == adt7468) { |
| 1608 | u8 vid = lm85_read_value(client, LM85_REG_VID); |
| 1609 | if (vid & 0x80) |
| 1610 | data->has_vid5 = true; |
| 1611 | } |
| 1612 | |
Axel Lin | 746f688 | 2014-07-23 12:29:11 +0800 | [diff] [blame] | 1613 | if (!data->has_vid5) |
| 1614 | data->groups[idx++] = &lm85_group_in4; |
Jean Delvare | 6b9aad2 | 2007-07-05 20:37:21 +0200 | [diff] [blame] | 1615 | |
| 1616 | /* The EMC6D100 has 3 additional voltage inputs */ |
Axel Lin | 746f688 | 2014-07-23 12:29:11 +0800 | [diff] [blame] | 1617 | if (data->type == emc6d100) |
| 1618 | data->groups[idx++] = &lm85_group_in567; |
Mark M. Hoffman | 0501a38 | 2006-09-24 21:14:35 +0200 | [diff] [blame] | 1619 | |
Axel Lin | 746f688 | 2014-07-23 12:29:11 +0800 | [diff] [blame] | 1620 | hwmon_dev = devm_hwmon_device_register_with_groups(dev, client->name, |
| 1621 | data, data->groups); |
| 1622 | return PTR_ERR_OR_ZERO(hwmon_dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1623 | } |
| 1624 | |
Axel Lin | 6fd5dd5 | 2014-07-23 12:27:39 +0800 | [diff] [blame] | 1625 | static const struct i2c_device_id lm85_id[] = { |
| 1626 | { "adm1027", adm1027 }, |
| 1627 | { "adt7463", adt7463 }, |
| 1628 | { "adt7468", adt7468 }, |
| 1629 | { "lm85", lm85 }, |
| 1630 | { "lm85b", lm85 }, |
| 1631 | { "lm85c", lm85 }, |
Jeremy Gebben | 11650cf | 2019-02-04 13:19:05 -0700 | [diff] [blame] | 1632 | { "lm96000", lm96000 }, |
Axel Lin | 6fd5dd5 | 2014-07-23 12:27:39 +0800 | [diff] [blame] | 1633 | { "emc6d100", emc6d100 }, |
| 1634 | { "emc6d101", emc6d100 }, |
| 1635 | { "emc6d102", emc6d102 }, |
| 1636 | { "emc6d103", emc6d103 }, |
| 1637 | { "emc6d103s", emc6d103s }, |
| 1638 | { } |
| 1639 | }; |
| 1640 | MODULE_DEVICE_TABLE(i2c, lm85_id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1641 | |
Guenter Roeck | 20b497a | 2019-04-04 07:44:40 -0700 | [diff] [blame] | 1642 | static const struct of_device_id __maybe_unused lm85_of_match[] = { |
Javier Martinez Canillas | 00c0f9d | 2017-02-24 10:13:03 -0300 | [diff] [blame] | 1643 | { |
| 1644 | .compatible = "adi,adm1027", |
| 1645 | .data = (void *)adm1027 |
| 1646 | }, |
| 1647 | { |
| 1648 | .compatible = "adi,adt7463", |
| 1649 | .data = (void *)adt7463 |
| 1650 | }, |
| 1651 | { |
| 1652 | .compatible = "adi,adt7468", |
| 1653 | .data = (void *)adt7468 |
| 1654 | }, |
| 1655 | { |
| 1656 | .compatible = "national,lm85", |
| 1657 | .data = (void *)lm85 |
| 1658 | }, |
| 1659 | { |
| 1660 | .compatible = "national,lm85b", |
| 1661 | .data = (void *)lm85 |
| 1662 | }, |
| 1663 | { |
| 1664 | .compatible = "national,lm85c", |
| 1665 | .data = (void *)lm85 |
| 1666 | }, |
| 1667 | { |
Jeremy Gebben | 11650cf | 2019-02-04 13:19:05 -0700 | [diff] [blame] | 1668 | .compatible = "ti,lm96000", |
| 1669 | .data = (void *)lm96000 |
| 1670 | }, |
| 1671 | { |
Javier Martinez Canillas | 00c0f9d | 2017-02-24 10:13:03 -0300 | [diff] [blame] | 1672 | .compatible = "smsc,emc6d100", |
| 1673 | .data = (void *)emc6d100 |
| 1674 | }, |
| 1675 | { |
| 1676 | .compatible = "smsc,emc6d101", |
| 1677 | .data = (void *)emc6d100 |
| 1678 | }, |
| 1679 | { |
| 1680 | .compatible = "smsc,emc6d102", |
| 1681 | .data = (void *)emc6d102 |
| 1682 | }, |
| 1683 | { |
| 1684 | .compatible = "smsc,emc6d103", |
| 1685 | .data = (void *)emc6d103 |
| 1686 | }, |
| 1687 | { |
| 1688 | .compatible = "smsc,emc6d103s", |
| 1689 | .data = (void *)emc6d103s |
| 1690 | }, |
| 1691 | { }, |
| 1692 | }; |
| 1693 | MODULE_DEVICE_TABLE(of, lm85_of_match); |
| 1694 | |
Axel Lin | 6fd5dd5 | 2014-07-23 12:27:39 +0800 | [diff] [blame] | 1695 | static struct i2c_driver lm85_driver = { |
| 1696 | .class = I2C_CLASS_HWMON, |
| 1697 | .driver = { |
| 1698 | .name = "lm85", |
Javier Martinez Canillas | 00c0f9d | 2017-02-24 10:13:03 -0300 | [diff] [blame] | 1699 | .of_match_table = of_match_ptr(lm85_of_match), |
Axel Lin | 6fd5dd5 | 2014-07-23 12:27:39 +0800 | [diff] [blame] | 1700 | }, |
Stephen Kitt | 6748703 | 2020-08-13 18:02:22 +0200 | [diff] [blame] | 1701 | .probe_new = lm85_probe, |
Axel Lin | 6fd5dd5 | 2014-07-23 12:27:39 +0800 | [diff] [blame] | 1702 | .id_table = lm85_id, |
| 1703 | .detect = lm85_detect, |
| 1704 | .address_list = normal_i2c, |
| 1705 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1706 | |
Axel Lin | f0967ee | 2012-01-20 15:38:18 +0800 | [diff] [blame] | 1707 | module_i2c_driver(lm85_driver); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1708 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1709 | MODULE_LICENSE("GPL"); |
Jean Delvare | 1f44809 | 2008-04-29 14:03:37 +0200 | [diff] [blame] | 1710 | MODULE_AUTHOR("Philip Pokorny <ppokorny@penguincomputing.com>, " |
| 1711 | "Margit Schubert-While <margitsw@t-online.de>, " |
Jean Delvare | e89e22b | 2008-06-25 08:47:35 -0400 | [diff] [blame] | 1712 | "Justin Thiessen <jthiessen@penguincomputing.com>"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1713 | MODULE_DESCRIPTION("LM85-B, LM85-C driver"); |