Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | lm85.c - Part of lm_sensors, Linux kernel modules for hardware |
| 3 | monitoring |
Jean Delvare | 1f44809 | 2008-04-29 14:03:37 +0200 | [diff] [blame] | 4 | Copyright (c) 1998, 1999 Frodo Looijaard <frodol@dds.nl> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5 | Copyright (c) 2002, 2003 Philip Pokorny <ppokorny@penguincomputing.com> |
| 6 | Copyright (c) 2003 Margit Schubert-While <margitsw@t-online.de> |
| 7 | Copyright (c) 2004 Justin Thiessen <jthiessen@penguincomputing.com> |
| 8 | |
| 9 | Chip details at <http://www.national.com/ds/LM/LM85.pdf> |
| 10 | |
| 11 | This program is free software; you can redistribute it and/or modify |
| 12 | it under the terms of the GNU General Public License as published by |
| 13 | the Free Software Foundation; either version 2 of the License, or |
| 14 | (at your option) any later version. |
| 15 | |
| 16 | This program is distributed in the hope that it will be useful, |
| 17 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 18 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 19 | GNU General Public License for more details. |
| 20 | |
| 21 | You should have received a copy of the GNU General Public License |
| 22 | along with this program; if not, write to the Free Software |
| 23 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 24 | */ |
| 25 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 | #include <linux/module.h> |
| 27 | #include <linux/init.h> |
| 28 | #include <linux/slab.h> |
| 29 | #include <linux/jiffies.h> |
| 30 | #include <linux/i2c.h> |
Mark M. Hoffman | 943b083 | 2005-07-15 21:39:18 -0400 | [diff] [blame] | 31 | #include <linux/hwmon.h> |
Jean Delvare | 303760b | 2005-07-31 21:52:01 +0200 | [diff] [blame] | 32 | #include <linux/hwmon-vid.h> |
Jean Delvare | b353a48 | 2007-07-05 20:36:12 +0200 | [diff] [blame] | 33 | #include <linux/hwmon-sysfs.h> |
Mark M. Hoffman | 943b083 | 2005-07-15 21:39:18 -0400 | [diff] [blame] | 34 | #include <linux/err.h> |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 35 | #include <linux/mutex.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | |
| 37 | /* Addresses to scan */ |
Mark M. Hoffman | 25e9c86 | 2008-02-17 22:28:03 -0500 | [diff] [blame] | 38 | static const unsigned short normal_i2c[] = { 0x2c, 0x2d, 0x2e, I2C_CLIENT_END }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | |
| 40 | /* Insmod parameters */ |
Jean Delvare | f4b5026 | 2005-07-31 21:49:03 +0200 | [diff] [blame] | 41 | I2C_CLIENT_INSMOD_6(lm85b, lm85c, adm1027, adt7463, emc6d100, emc6d102); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 42 | |
| 43 | /* The LM85 registers */ |
| 44 | |
| 45 | #define LM85_REG_IN(nr) (0x20 + (nr)) |
| 46 | #define LM85_REG_IN_MIN(nr) (0x44 + (nr) * 2) |
| 47 | #define LM85_REG_IN_MAX(nr) (0x45 + (nr) * 2) |
| 48 | |
| 49 | #define LM85_REG_TEMP(nr) (0x25 + (nr)) |
| 50 | #define LM85_REG_TEMP_MIN(nr) (0x4e + (nr) * 2) |
| 51 | #define LM85_REG_TEMP_MAX(nr) (0x4f + (nr) * 2) |
| 52 | |
| 53 | /* Fan speeds are LSB, MSB (2 bytes) */ |
Jean Delvare | 1f44809 | 2008-04-29 14:03:37 +0200 | [diff] [blame] | 54 | #define LM85_REG_FAN(nr) (0x28 + (nr) * 2) |
| 55 | #define LM85_REG_FAN_MIN(nr) (0x54 + (nr) * 2) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 56 | |
| 57 | #define LM85_REG_PWM(nr) (0x30 + (nr)) |
| 58 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 59 | #define LM85_REG_COMPANY 0x3e |
| 60 | #define LM85_REG_VERSTEP 0x3f |
| 61 | /* These are the recognized values for the above regs */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 62 | #define LM85_COMPANY_NATIONAL 0x01 |
| 63 | #define LM85_COMPANY_ANALOG_DEV 0x41 |
Jean Delvare | 1f44809 | 2008-04-29 14:03:37 +0200 | [diff] [blame] | 64 | #define LM85_COMPANY_SMSC 0x5c |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 65 | #define LM85_VERSTEP_VMASK 0xf0 |
| 66 | #define LM85_VERSTEP_GENERIC 0x60 |
| 67 | #define LM85_VERSTEP_LM85C 0x60 |
| 68 | #define LM85_VERSTEP_LM85B 0x62 |
| 69 | #define LM85_VERSTEP_ADM1027 0x60 |
| 70 | #define LM85_VERSTEP_ADT7463 0x62 |
| 71 | #define LM85_VERSTEP_ADT7463C 0x6A |
| 72 | #define LM85_VERSTEP_EMC6D100_A0 0x60 |
| 73 | #define LM85_VERSTEP_EMC6D100_A1 0x61 |
| 74 | #define LM85_VERSTEP_EMC6D102 0x65 |
| 75 | |
| 76 | #define LM85_REG_CONFIG 0x40 |
| 77 | |
| 78 | #define LM85_REG_ALARM1 0x41 |
| 79 | #define LM85_REG_ALARM2 0x42 |
| 80 | |
| 81 | #define LM85_REG_VID 0x43 |
| 82 | |
| 83 | /* Automated FAN control */ |
| 84 | #define LM85_REG_AFAN_CONFIG(nr) (0x5c + (nr)) |
| 85 | #define LM85_REG_AFAN_RANGE(nr) (0x5f + (nr)) |
| 86 | #define LM85_REG_AFAN_SPIKE1 0x62 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 87 | #define LM85_REG_AFAN_MINPWM(nr) (0x64 + (nr)) |
| 88 | #define LM85_REG_AFAN_LIMIT(nr) (0x67 + (nr)) |
| 89 | #define LM85_REG_AFAN_CRITICAL(nr) (0x6a + (nr)) |
| 90 | #define LM85_REG_AFAN_HYST1 0x6d |
| 91 | #define LM85_REG_AFAN_HYST2 0x6e |
| 92 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 93 | #define ADM1027_REG_EXTEND_ADC1 0x76 |
| 94 | #define ADM1027_REG_EXTEND_ADC2 0x77 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 95 | |
| 96 | #define EMC6D100_REG_ALARM3 0x7d |
| 97 | /* IN5, IN6 and IN7 */ |
Jean Delvare | 1f44809 | 2008-04-29 14:03:37 +0200 | [diff] [blame] | 98 | #define EMC6D100_REG_IN(nr) (0x70 + ((nr) - 5)) |
| 99 | #define EMC6D100_REG_IN_MIN(nr) (0x73 + ((nr) - 5) * 2) |
| 100 | #define EMC6D100_REG_IN_MAX(nr) (0x74 + ((nr) - 5) * 2) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 101 | #define EMC6D102_REG_EXTEND_ADC1 0x85 |
| 102 | #define EMC6D102_REG_EXTEND_ADC2 0x86 |
| 103 | #define EMC6D102_REG_EXTEND_ADC3 0x87 |
| 104 | #define EMC6D102_REG_EXTEND_ADC4 0x88 |
| 105 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 106 | |
Jean Delvare | 1f44809 | 2008-04-29 14:03:37 +0200 | [diff] [blame] | 107 | /* Conversions. Rounding and limit checking is only done on the TO_REG |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 108 | variants. Note that you should be a bit careful with which arguments |
| 109 | these macros are called: arguments may be evaluated more than once. |
| 110 | */ |
| 111 | |
| 112 | /* IN are scaled acording to built-in resistors */ |
Jean Delvare | e89e22b | 2008-06-25 08:47:35 -0400 | [diff] [blame] | 113 | static const int lm85_scaling[] = { /* .001 Volts */ |
Jean Delvare | 1f44809 | 2008-04-29 14:03:37 +0200 | [diff] [blame] | 114 | 2500, 2250, 3300, 5000, 12000, |
| 115 | 3300, 1500, 1800 /*EMC6D100*/ |
| 116 | }; |
| 117 | #define SCALE(val, from, to) (((val) * (to) + ((from) / 2)) / (from)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 118 | |
Jean Delvare | 1f44809 | 2008-04-29 14:03:37 +0200 | [diff] [blame] | 119 | #define INS_TO_REG(n, val) \ |
| 120 | SENSORS_LIMIT(SCALE(val, lm85_scaling[n], 192), 0, 255) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 121 | |
Jean Delvare | 1f44809 | 2008-04-29 14:03:37 +0200 | [diff] [blame] | 122 | #define INSEXT_FROM_REG(n, val, ext) \ |
Jean Delvare | 5a4d3ef | 2007-07-05 20:38:32 +0200 | [diff] [blame] | 123 | SCALE(((val) << 4) + (ext), 192 << 4, lm85_scaling[n]) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 124 | |
Jean Delvare | 1f44809 | 2008-04-29 14:03:37 +0200 | [diff] [blame] | 125 | #define INS_FROM_REG(n, val) SCALE((val), 192, lm85_scaling[n]) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 126 | |
| 127 | /* FAN speed is measured using 90kHz clock */ |
Jean Delvare | 63f281a | 2007-07-05 20:39:40 +0200 | [diff] [blame] | 128 | static inline u16 FAN_TO_REG(unsigned long val) |
| 129 | { |
| 130 | if (!val) |
| 131 | return 0xffff; |
| 132 | return SENSORS_LIMIT(5400000 / val, 1, 0xfffe); |
| 133 | } |
Jean Delvare | 1f44809 | 2008-04-29 14:03:37 +0200 | [diff] [blame] | 134 | #define FAN_FROM_REG(val) ((val) == 0 ? -1 : (val) == 0xffff ? 0 : \ |
| 135 | 5400000 / (val)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 136 | |
| 137 | /* Temperature is reported in .001 degC increments */ |
| 138 | #define TEMP_TO_REG(val) \ |
Jean Delvare | 1f44809 | 2008-04-29 14:03:37 +0200 | [diff] [blame] | 139 | SENSORS_LIMIT(SCALE(val, 1000, 1), -127, 127) |
| 140 | #define TEMPEXT_FROM_REG(val, ext) \ |
Jean Delvare | 5a4d3ef | 2007-07-05 20:38:32 +0200 | [diff] [blame] | 141 | SCALE(((val) << 4) + (ext), 16, 1000) |
| 142 | #define TEMP_FROM_REG(val) ((val) * 1000) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 143 | |
Jean Delvare | 1f44809 | 2008-04-29 14:03:37 +0200 | [diff] [blame] | 144 | #define PWM_TO_REG(val) SENSORS_LIMIT(val, 0, 255) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 145 | #define PWM_FROM_REG(val) (val) |
| 146 | |
| 147 | |
| 148 | /* ZONEs have the following parameters: |
| 149 | * Limit (low) temp, 1. degC |
| 150 | * Hysteresis (below limit), 1. degC (0-15) |
| 151 | * Range of speed control, .1 degC (2-80) |
| 152 | * Critical (high) temp, 1. degC |
| 153 | * |
| 154 | * FAN PWMs have the following parameters: |
| 155 | * Reference Zone, 1, 2, 3, etc. |
| 156 | * Spinup time, .05 sec |
| 157 | * PWM value at limit/low temp, 1 count |
| 158 | * PWM Frequency, 1. Hz |
| 159 | * PWM is Min or OFF below limit, flag |
| 160 | * Invert PWM output, flag |
| 161 | * |
| 162 | * Some chips filter the temp, others the fan. |
| 163 | * Filter constant (or disabled) .1 seconds |
| 164 | */ |
| 165 | |
| 166 | /* These are the zone temperature range encodings in .001 degree C */ |
Jean Delvare | e89e22b | 2008-06-25 08:47:35 -0400 | [diff] [blame] | 167 | static const int lm85_range_map[] = { |
Jean Delvare | 1f44809 | 2008-04-29 14:03:37 +0200 | [diff] [blame] | 168 | 2000, 2500, 3300, 4000, 5000, 6600, 8000, 10000, |
| 169 | 13300, 16000, 20000, 26600, 32000, 40000, 53300, 80000 |
| 170 | }; |
| 171 | |
| 172 | static int RANGE_TO_REG(int range) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 173 | { |
| 174 | int i; |
| 175 | |
Jean Delvare | d38b149 | 2008-04-03 10:40:39 +0200 | [diff] [blame] | 176 | if (range >= lm85_range_map[15]) |
Jean Delvare | 1f44809 | 2008-04-29 14:03:37 +0200 | [diff] [blame] | 177 | return 15; |
Jean Delvare | d38b149 | 2008-04-03 10:40:39 +0200 | [diff] [blame] | 178 | |
| 179 | /* Find the closest match */ |
| 180 | for (i = 14; i >= 0; --i) { |
| 181 | if (range >= lm85_range_map[i]) { |
| 182 | if ((lm85_range_map[i + 1] - range) < |
| 183 | (range - lm85_range_map[i])) |
| 184 | return i + 1; |
| 185 | return i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 186 | } |
| 187 | } |
Jean Delvare | d38b149 | 2008-04-03 10:40:39 +0200 | [diff] [blame] | 188 | |
| 189 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 190 | } |
Jean Delvare | 1f44809 | 2008-04-29 14:03:37 +0200 | [diff] [blame] | 191 | #define RANGE_FROM_REG(val) lm85_range_map[(val) & 0x0f] |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 192 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 193 | /* These are the PWM frequency encodings */ |
Jean Delvare | e89e22b | 2008-06-25 08:47:35 -0400 | [diff] [blame] | 194 | static const int lm85_freq_map[] = { /* .1 Hz */ |
Jean Delvare | 1f44809 | 2008-04-29 14:03:37 +0200 | [diff] [blame] | 195 | 100, 150, 230, 300, 380, 470, 620, 940 |
| 196 | }; |
| 197 | |
| 198 | static int FREQ_TO_REG(int freq) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 199 | { |
| 200 | int i; |
| 201 | |
Jean Delvare | 1f44809 | 2008-04-29 14:03:37 +0200 | [diff] [blame] | 202 | if (freq >= lm85_freq_map[7]) |
| 203 | return 7; |
| 204 | for (i = 0; i < 7; ++i) |
| 205 | if (freq <= lm85_freq_map[i]) |
| 206 | break; |
Jean Delvare | e89e22b | 2008-06-25 08:47:35 -0400 | [diff] [blame] | 207 | return i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 208 | } |
Jean Delvare | 1f44809 | 2008-04-29 14:03:37 +0200 | [diff] [blame] | 209 | #define FREQ_FROM_REG(val) lm85_freq_map[(val) & 0x07] |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 210 | |
| 211 | /* Since we can't use strings, I'm abusing these numbers |
| 212 | * to stand in for the following meanings: |
| 213 | * 1 -- PWM responds to Zone 1 |
| 214 | * 2 -- PWM responds to Zone 2 |
| 215 | * 3 -- PWM responds to Zone 3 |
| 216 | * 23 -- PWM responds to the higher temp of Zone 2 or 3 |
| 217 | * 123 -- PWM responds to highest of Zone 1, 2, or 3 |
| 218 | * 0 -- PWM is always at 0% (ie, off) |
| 219 | * -1 -- PWM is always at 100% |
| 220 | * -2 -- PWM responds to manual control |
| 221 | */ |
| 222 | |
Jean Delvare | e89e22b | 2008-06-25 08:47:35 -0400 | [diff] [blame] | 223 | static const int lm85_zone_map[] = { 1, 2, 3, -1, 0, 23, 123, -2 }; |
| 224 | #define ZONE_FROM_REG(val) lm85_zone_map[(val) >> 5] |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 225 | |
Jean Delvare | 1f44809 | 2008-04-29 14:03:37 +0200 | [diff] [blame] | 226 | static int ZONE_TO_REG(int zone) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 227 | { |
| 228 | int i; |
| 229 | |
Jean Delvare | 1f44809 | 2008-04-29 14:03:37 +0200 | [diff] [blame] | 230 | for (i = 0; i <= 7; ++i) |
| 231 | if (zone == lm85_zone_map[i]) |
| 232 | break; |
| 233 | if (i > 7) /* Not found. */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 234 | i = 3; /* Always 100% */ |
Jean Delvare | e89e22b | 2008-06-25 08:47:35 -0400 | [diff] [blame] | 235 | return i << 5; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 236 | } |
| 237 | |
Jean Delvare | 1f44809 | 2008-04-29 14:03:37 +0200 | [diff] [blame] | 238 | #define HYST_TO_REG(val) SENSORS_LIMIT(((val) + 500) / 1000, 0, 15) |
| 239 | #define HYST_FROM_REG(val) ((val) * 1000) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 240 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 241 | /* Chip sampling rates |
| 242 | * |
| 243 | * Some sensors are not updated more frequently than once per second |
| 244 | * so it doesn't make sense to read them more often than that. |
| 245 | * We cache the results and return the saved data if the driver |
| 246 | * is called again before a second has elapsed. |
| 247 | * |
| 248 | * Also, there is significant configuration data for this chip |
| 249 | * given the automatic PWM fan control that is possible. There |
| 250 | * are about 47 bytes of config data to only 22 bytes of actual |
| 251 | * readings. So, we keep the config data up to date in the cache |
| 252 | * when it is written and only sample it once every 1 *minute* |
| 253 | */ |
| 254 | #define LM85_DATA_INTERVAL (HZ + HZ / 2) |
| 255 | #define LM85_CONFIG_INTERVAL (1 * 60 * HZ) |
| 256 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 257 | /* LM85 can automatically adjust fan speeds based on temperature |
| 258 | * This structure encapsulates an entire Zone config. There are |
| 259 | * three zones (one for each temperature input) on the lm85 |
| 260 | */ |
| 261 | struct lm85_zone { |
| 262 | s8 limit; /* Low temp limit */ |
| 263 | u8 hyst; /* Low limit hysteresis. (0-15) */ |
| 264 | u8 range; /* Temp range, encoded */ |
| 265 | s8 critical; /* "All fans ON" temp limit */ |
Jean Delvare | 1f44809 | 2008-04-29 14:03:37 +0200 | [diff] [blame] | 266 | u8 off_desired; /* Actual "off" temperature specified. Preserved |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 267 | * to prevent "drift" as other autofan control |
| 268 | * values change. |
| 269 | */ |
Jean Delvare | 1f44809 | 2008-04-29 14:03:37 +0200 | [diff] [blame] | 270 | u8 max_desired; /* 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 */ |
| 278 | u8 freq; /* PWM frequency, encoded */ |
| 279 | u8 min_pwm; /* Minimum PWM value, encoded */ |
| 280 | u8 min_off; /* Min PWM or OFF below "limit", flag */ |
| 281 | }; |
| 282 | |
Jean Delvare | ed6bafb | 2007-02-14 21:15:03 +0100 | [diff] [blame] | 283 | /* For each registered chip, we need to keep some data in memory. |
| 284 | The structure is dynamically allocated. */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 285 | struct lm85_data { |
| 286 | struct i2c_client client; |
Tony Jones | 1beeffe | 2007-08-20 13:46:20 -0700 | [diff] [blame] | 287 | struct device *hwmon_dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 288 | enum chips type; |
| 289 | |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 290 | struct mutex update_lock; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 291 | int valid; /* !=0 if following fields are valid */ |
| 292 | unsigned long last_reading; /* In jiffies */ |
| 293 | unsigned long last_config; /* In jiffies */ |
| 294 | |
| 295 | u8 in[8]; /* Register value */ |
| 296 | u8 in_max[8]; /* Register value */ |
| 297 | u8 in_min[8]; /* Register value */ |
| 298 | s8 temp[3]; /* Register value */ |
| 299 | s8 temp_min[3]; /* Register value */ |
| 300 | s8 temp_max[3]; /* Register value */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 301 | u16 fan[4]; /* Register value */ |
| 302 | u16 fan_min[4]; /* Register value */ |
| 303 | u8 pwm[3]; /* Register value */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 304 | u8 temp_ext[3]; /* Decoded values */ |
| 305 | u8 in_ext[8]; /* Decoded values */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 306 | u8 vid; /* Register value */ |
| 307 | u8 vrm; /* VRM version */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 308 | u32 alarms; /* Register encoding, combined */ |
| 309 | struct lm85_autofan autofan[3]; |
| 310 | struct lm85_zone zone[3]; |
| 311 | }; |
| 312 | |
| 313 | static int lm85_attach_adapter(struct i2c_adapter *adapter); |
| 314 | static int lm85_detect(struct i2c_adapter *adapter, int address, |
| 315 | int kind); |
| 316 | static int lm85_detach_client(struct i2c_client *client); |
| 317 | |
Darren Jenkins | f6c27fc | 2006-02-27 23:14:58 +0100 | [diff] [blame] | 318 | static int lm85_read_value(struct i2c_client *client, u8 reg); |
Jean Delvare | e89e22b | 2008-06-25 08:47:35 -0400 | [diff] [blame] | 319 | static void lm85_write_value(struct i2c_client *client, u8 reg, int value); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 320 | static struct lm85_data *lm85_update_device(struct device *dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 321 | |
| 322 | |
| 323 | static struct i2c_driver lm85_driver = { |
Laurent Riffard | cdaf793 | 2005-11-26 20:37:41 +0100 | [diff] [blame] | 324 | .driver = { |
Laurent Riffard | cdaf793 | 2005-11-26 20:37:41 +0100 | [diff] [blame] | 325 | .name = "lm85", |
| 326 | }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 327 | .attach_adapter = lm85_attach_adapter, |
| 328 | .detach_client = lm85_detach_client, |
| 329 | }; |
| 330 | |
| 331 | |
| 332 | /* 4 Fans */ |
Jean Delvare | b353a48 | 2007-07-05 20:36:12 +0200 | [diff] [blame] | 333 | static ssize_t show_fan(struct device *dev, struct device_attribute *attr, |
| 334 | char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 335 | { |
Jean Delvare | b353a48 | 2007-07-05 20:36:12 +0200 | [diff] [blame] | 336 | int nr = to_sensor_dev_attr(attr)->index; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 337 | struct lm85_data *data = lm85_update_device(dev); |
Jean Delvare | 1f44809 | 2008-04-29 14:03:37 +0200 | [diff] [blame] | 338 | return sprintf(buf, "%d\n", FAN_FROM_REG(data->fan[nr])); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 339 | } |
Jean Delvare | b353a48 | 2007-07-05 20:36:12 +0200 | [diff] [blame] | 340 | |
| 341 | static ssize_t show_fan_min(struct device *dev, struct device_attribute *attr, |
| 342 | char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 343 | { |
Jean Delvare | b353a48 | 2007-07-05 20:36:12 +0200 | [diff] [blame] | 344 | int nr = to_sensor_dev_attr(attr)->index; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 345 | struct lm85_data *data = lm85_update_device(dev); |
Jean Delvare | 1f44809 | 2008-04-29 14:03:37 +0200 | [diff] [blame] | 346 | return sprintf(buf, "%d\n", FAN_FROM_REG(data->fan_min[nr])); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 347 | } |
Jean Delvare | b353a48 | 2007-07-05 20:36:12 +0200 | [diff] [blame] | 348 | |
| 349 | static ssize_t set_fan_min(struct device *dev, struct device_attribute *attr, |
| 350 | const char *buf, size_t count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 351 | { |
Jean Delvare | b353a48 | 2007-07-05 20:36:12 +0200 | [diff] [blame] | 352 | int nr = to_sensor_dev_attr(attr)->index; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 353 | struct i2c_client *client = to_i2c_client(dev); |
| 354 | struct lm85_data *data = i2c_get_clientdata(client); |
Jean Delvare | 63f281a | 2007-07-05 20:39:40 +0200 | [diff] [blame] | 355 | unsigned long val = simple_strtoul(buf, NULL, 10); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 356 | |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 357 | mutex_lock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 358 | data->fan_min[nr] = FAN_TO_REG(val); |
| 359 | 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] | 360 | mutex_unlock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 361 | return count; |
| 362 | } |
| 363 | |
| 364 | #define show_fan_offset(offset) \ |
Jean Delvare | b353a48 | 2007-07-05 20:36:12 +0200 | [diff] [blame] | 365 | static SENSOR_DEVICE_ATTR(fan##offset##_input, S_IRUGO, \ |
| 366 | show_fan, NULL, offset - 1); \ |
| 367 | static SENSOR_DEVICE_ATTR(fan##offset##_min, S_IRUGO | S_IWUSR, \ |
| 368 | show_fan_min, set_fan_min, offset - 1) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 369 | |
| 370 | show_fan_offset(1); |
| 371 | show_fan_offset(2); |
| 372 | show_fan_offset(3); |
| 373 | show_fan_offset(4); |
| 374 | |
| 375 | /* vid, vrm, alarms */ |
| 376 | |
Jean Delvare | 1f44809 | 2008-04-29 14:03:37 +0200 | [diff] [blame] | 377 | static ssize_t show_vid_reg(struct device *dev, struct device_attribute *attr, |
| 378 | char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 379 | { |
| 380 | struct lm85_data *data = lm85_update_device(dev); |
Jean Delvare | 9c516ef | 2005-11-26 20:07:54 +0100 | [diff] [blame] | 381 | int vid; |
| 382 | |
| 383 | if (data->type == adt7463 && (data->vid & 0x80)) { |
| 384 | /* 6-pin VID (VRM 10) */ |
| 385 | vid = vid_from_reg(data->vid & 0x3f, data->vrm); |
| 386 | } else { |
| 387 | /* 5-pin VID (VRM 9) */ |
| 388 | vid = vid_from_reg(data->vid & 0x1f, data->vrm); |
| 389 | } |
| 390 | |
| 391 | return sprintf(buf, "%d\n", vid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 392 | } |
| 393 | |
| 394 | static DEVICE_ATTR(cpu0_vid, S_IRUGO, show_vid_reg, NULL); |
| 395 | |
Jean Delvare | 1f44809 | 2008-04-29 14:03:37 +0200 | [diff] [blame] | 396 | static ssize_t show_vrm_reg(struct device *dev, struct device_attribute *attr, |
| 397 | char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 398 | { |
Jean Delvare | 90d6619 | 2007-10-08 18:24:35 +0200 | [diff] [blame] | 399 | struct lm85_data *data = dev_get_drvdata(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 400 | return sprintf(buf, "%ld\n", (long) data->vrm); |
| 401 | } |
| 402 | |
Jean Delvare | 1f44809 | 2008-04-29 14:03:37 +0200 | [diff] [blame] | 403 | static ssize_t store_vrm_reg(struct device *dev, struct device_attribute *attr, |
| 404 | const char *buf, size_t count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 405 | { |
Jean Delvare | 8f74efe | 2007-12-01 11:25:33 +0100 | [diff] [blame] | 406 | struct lm85_data *data = dev_get_drvdata(dev); |
| 407 | data->vrm = simple_strtoul(buf, NULL, 10); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 408 | return count; |
| 409 | } |
| 410 | |
| 411 | static DEVICE_ATTR(vrm, S_IRUGO | S_IWUSR, show_vrm_reg, store_vrm_reg); |
| 412 | |
Jean Delvare | 1f44809 | 2008-04-29 14:03:37 +0200 | [diff] [blame] | 413 | static ssize_t show_alarms_reg(struct device *dev, struct device_attribute |
| 414 | *attr, char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 415 | { |
| 416 | struct lm85_data *data = lm85_update_device(dev); |
Jean Delvare | 68188ba | 2005-05-16 18:52:38 +0200 | [diff] [blame] | 417 | return sprintf(buf, "%u\n", data->alarms); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 418 | } |
| 419 | |
| 420 | static DEVICE_ATTR(alarms, S_IRUGO, show_alarms_reg, NULL); |
| 421 | |
Jean Delvare | bf76e9d | 2007-07-05 20:37:58 +0200 | [diff] [blame] | 422 | static ssize_t show_alarm(struct device *dev, struct device_attribute *attr, |
| 423 | char *buf) |
| 424 | { |
| 425 | int nr = to_sensor_dev_attr(attr)->index; |
| 426 | struct lm85_data *data = lm85_update_device(dev); |
| 427 | return sprintf(buf, "%u\n", (data->alarms >> nr) & 1); |
| 428 | } |
| 429 | |
| 430 | static SENSOR_DEVICE_ATTR(in0_alarm, S_IRUGO, show_alarm, NULL, 0); |
| 431 | static SENSOR_DEVICE_ATTR(in1_alarm, S_IRUGO, show_alarm, NULL, 1); |
| 432 | static SENSOR_DEVICE_ATTR(in2_alarm, S_IRUGO, show_alarm, NULL, 2); |
| 433 | static SENSOR_DEVICE_ATTR(in3_alarm, S_IRUGO, show_alarm, NULL, 3); |
| 434 | static SENSOR_DEVICE_ATTR(in4_alarm, S_IRUGO, show_alarm, NULL, 8); |
| 435 | static SENSOR_DEVICE_ATTR(in5_alarm, S_IRUGO, show_alarm, NULL, 18); |
| 436 | static SENSOR_DEVICE_ATTR(in6_alarm, S_IRUGO, show_alarm, NULL, 16); |
| 437 | static SENSOR_DEVICE_ATTR(in7_alarm, S_IRUGO, show_alarm, NULL, 17); |
| 438 | static SENSOR_DEVICE_ATTR(temp1_alarm, S_IRUGO, show_alarm, NULL, 4); |
| 439 | static SENSOR_DEVICE_ATTR(temp1_fault, S_IRUGO, show_alarm, NULL, 14); |
| 440 | static SENSOR_DEVICE_ATTR(temp2_alarm, S_IRUGO, show_alarm, NULL, 5); |
| 441 | static SENSOR_DEVICE_ATTR(temp3_alarm, S_IRUGO, show_alarm, NULL, 6); |
| 442 | static SENSOR_DEVICE_ATTR(temp3_fault, S_IRUGO, show_alarm, NULL, 15); |
| 443 | static SENSOR_DEVICE_ATTR(fan1_alarm, S_IRUGO, show_alarm, NULL, 10); |
| 444 | static SENSOR_DEVICE_ATTR(fan2_alarm, S_IRUGO, show_alarm, NULL, 11); |
| 445 | static SENSOR_DEVICE_ATTR(fan3_alarm, S_IRUGO, show_alarm, NULL, 12); |
| 446 | static SENSOR_DEVICE_ATTR(fan4_alarm, S_IRUGO, show_alarm, NULL, 13); |
| 447 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 448 | /* pwm */ |
| 449 | |
Jean Delvare | b353a48 | 2007-07-05 20:36:12 +0200 | [diff] [blame] | 450 | static ssize_t show_pwm(struct device *dev, struct device_attribute *attr, |
| 451 | char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 452 | { |
Jean Delvare | b353a48 | 2007-07-05 20:36:12 +0200 | [diff] [blame] | 453 | int nr = to_sensor_dev_attr(attr)->index; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 454 | struct lm85_data *data = lm85_update_device(dev); |
Jean Delvare | 1f44809 | 2008-04-29 14:03:37 +0200 | [diff] [blame] | 455 | return sprintf(buf, "%d\n", PWM_FROM_REG(data->pwm[nr])); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 456 | } |
Jean Delvare | b353a48 | 2007-07-05 20:36:12 +0200 | [diff] [blame] | 457 | |
| 458 | static ssize_t set_pwm(struct device *dev, struct device_attribute *attr, |
| 459 | const char *buf, size_t count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 460 | { |
Jean Delvare | b353a48 | 2007-07-05 20:36:12 +0200 | [diff] [blame] | 461 | int nr = to_sensor_dev_attr(attr)->index; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 462 | struct i2c_client *client = to_i2c_client(dev); |
| 463 | struct lm85_data *data = i2c_get_clientdata(client); |
| 464 | long val = simple_strtol(buf, NULL, 10); |
| 465 | |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 466 | mutex_lock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 467 | data->pwm[nr] = PWM_TO_REG(val); |
| 468 | lm85_write_value(client, LM85_REG_PWM(nr), data->pwm[nr]); |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 469 | mutex_unlock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 470 | return count; |
| 471 | } |
Jean Delvare | b353a48 | 2007-07-05 20:36:12 +0200 | [diff] [blame] | 472 | |
| 473 | static ssize_t show_pwm_enable(struct device *dev, struct device_attribute |
| 474 | *attr, char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 475 | { |
Jean Delvare | b353a48 | 2007-07-05 20:36:12 +0200 | [diff] [blame] | 476 | int nr = to_sensor_dev_attr(attr)->index; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 477 | struct lm85_data *data = lm85_update_device(dev); |
Jean Delvare | 4b4df95 | 2007-12-03 23:23:21 +0100 | [diff] [blame] | 478 | int pwm_zone, enable; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 479 | |
| 480 | pwm_zone = ZONE_FROM_REG(data->autofan[nr].config); |
Jean Delvare | 4b4df95 | 2007-12-03 23:23:21 +0100 | [diff] [blame] | 481 | switch (pwm_zone) { |
| 482 | case -1: /* PWM is always at 100% */ |
| 483 | enable = 0; |
| 484 | break; |
| 485 | case 0: /* PWM is always at 0% */ |
| 486 | case -2: /* PWM responds to manual control */ |
| 487 | enable = 1; |
| 488 | break; |
| 489 | default: /* PWM in automatic mode */ |
| 490 | enable = 2; |
| 491 | } |
| 492 | return sprintf(buf, "%d\n", enable); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 493 | } |
| 494 | |
Jean Delvare | 455f791 | 2007-12-03 23:28:42 +0100 | [diff] [blame] | 495 | static ssize_t set_pwm_enable(struct device *dev, struct device_attribute |
| 496 | *attr, const char *buf, size_t count) |
| 497 | { |
| 498 | int nr = to_sensor_dev_attr(attr)->index; |
| 499 | struct i2c_client *client = to_i2c_client(dev); |
| 500 | struct lm85_data *data = i2c_get_clientdata(client); |
| 501 | long val = simple_strtol(buf, NULL, 10); |
| 502 | u8 config; |
| 503 | |
| 504 | switch (val) { |
| 505 | case 0: |
| 506 | config = 3; |
| 507 | break; |
| 508 | case 1: |
| 509 | config = 7; |
| 510 | break; |
| 511 | case 2: |
| 512 | /* Here we have to choose arbitrarily one of the 5 possible |
| 513 | configurations; I go for the safest */ |
| 514 | config = 6; |
| 515 | break; |
| 516 | default: |
| 517 | return -EINVAL; |
| 518 | } |
| 519 | |
| 520 | mutex_lock(&data->update_lock); |
| 521 | data->autofan[nr].config = lm85_read_value(client, |
| 522 | LM85_REG_AFAN_CONFIG(nr)); |
| 523 | data->autofan[nr].config = (data->autofan[nr].config & ~0xe0) |
| 524 | | (config << 5); |
| 525 | lm85_write_value(client, LM85_REG_AFAN_CONFIG(nr), |
| 526 | data->autofan[nr].config); |
| 527 | mutex_unlock(&data->update_lock); |
| 528 | return count; |
| 529 | } |
| 530 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 531 | #define show_pwm_reg(offset) \ |
Jean Delvare | b353a48 | 2007-07-05 20:36:12 +0200 | [diff] [blame] | 532 | static SENSOR_DEVICE_ATTR(pwm##offset, S_IRUGO | S_IWUSR, \ |
| 533 | show_pwm, set_pwm, offset - 1); \ |
Jean Delvare | 455f791 | 2007-12-03 23:28:42 +0100 | [diff] [blame] | 534 | static SENSOR_DEVICE_ATTR(pwm##offset##_enable, S_IRUGO | S_IWUSR, \ |
| 535 | show_pwm_enable, set_pwm_enable, offset - 1) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 536 | |
| 537 | show_pwm_reg(1); |
| 538 | show_pwm_reg(2); |
| 539 | show_pwm_reg(3); |
| 540 | |
| 541 | /* Voltages */ |
| 542 | |
Jean Delvare | b353a48 | 2007-07-05 20:36:12 +0200 | [diff] [blame] | 543 | static ssize_t show_in(struct device *dev, struct device_attribute *attr, |
| 544 | char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 545 | { |
Jean Delvare | b353a48 | 2007-07-05 20:36:12 +0200 | [diff] [blame] | 546 | int nr = to_sensor_dev_attr(attr)->index; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 547 | struct lm85_data *data = lm85_update_device(dev); |
Jean Delvare | 1f44809 | 2008-04-29 14:03:37 +0200 | [diff] [blame] | 548 | return sprintf(buf, "%d\n", INSEXT_FROM_REG(nr, data->in[nr], |
| 549 | data->in_ext[nr])); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 550 | } |
Jean Delvare | b353a48 | 2007-07-05 20:36:12 +0200 | [diff] [blame] | 551 | |
Jean Delvare | 1f44809 | 2008-04-29 14:03:37 +0200 | [diff] [blame] | 552 | static ssize_t show_in_min(struct device *dev, struct device_attribute *attr, |
Jean Delvare | b353a48 | 2007-07-05 20:36:12 +0200 | [diff] [blame] | 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", INS_FROM_REG(nr, data->in_min[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 | |
| 560 | static ssize_t set_in_min(struct device *dev, struct device_attribute *attr, |
| 561 | const char *buf, size_t count) |
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 i2c_client *client = to_i2c_client(dev); |
| 565 | struct lm85_data *data = i2c_get_clientdata(client); |
| 566 | long val = simple_strtol(buf, NULL, 10); |
| 567 | |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 568 | mutex_lock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 569 | data->in_min[nr] = INS_TO_REG(nr, val); |
| 570 | 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] | 571 | mutex_unlock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 572 | return count; |
| 573 | } |
Jean Delvare | b353a48 | 2007-07-05 20:36:12 +0200 | [diff] [blame] | 574 | |
| 575 | static ssize_t show_in_max(struct device *dev, struct device_attribute *attr, |
| 576 | char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 577 | { |
Jean Delvare | b353a48 | 2007-07-05 20:36:12 +0200 | [diff] [blame] | 578 | int nr = to_sensor_dev_attr(attr)->index; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 579 | struct lm85_data *data = lm85_update_device(dev); |
Jean Delvare | 1f44809 | 2008-04-29 14:03:37 +0200 | [diff] [blame] | 580 | 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] | 581 | } |
Jean Delvare | b353a48 | 2007-07-05 20:36:12 +0200 | [diff] [blame] | 582 | |
| 583 | static ssize_t set_in_max(struct device *dev, struct device_attribute *attr, |
| 584 | const char *buf, size_t count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 585 | { |
Jean Delvare | b353a48 | 2007-07-05 20:36:12 +0200 | [diff] [blame] | 586 | int nr = to_sensor_dev_attr(attr)->index; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 587 | struct i2c_client *client = to_i2c_client(dev); |
| 588 | struct lm85_data *data = i2c_get_clientdata(client); |
| 589 | long val = simple_strtol(buf, NULL, 10); |
| 590 | |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 591 | mutex_lock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 592 | data->in_max[nr] = INS_TO_REG(nr, val); |
| 593 | 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] | 594 | mutex_unlock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 595 | return count; |
| 596 | } |
Jean Delvare | b353a48 | 2007-07-05 20:36:12 +0200 | [diff] [blame] | 597 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 598 | #define show_in_reg(offset) \ |
Jean Delvare | b353a48 | 2007-07-05 20:36:12 +0200 | [diff] [blame] | 599 | static SENSOR_DEVICE_ATTR(in##offset##_input, S_IRUGO, \ |
| 600 | show_in, NULL, offset); \ |
| 601 | static SENSOR_DEVICE_ATTR(in##offset##_min, S_IRUGO | S_IWUSR, \ |
| 602 | show_in_min, set_in_min, offset); \ |
| 603 | static SENSOR_DEVICE_ATTR(in##offset##_max, S_IRUGO | S_IWUSR, \ |
| 604 | show_in_max, set_in_max, offset) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 605 | |
| 606 | show_in_reg(0); |
| 607 | show_in_reg(1); |
| 608 | show_in_reg(2); |
| 609 | show_in_reg(3); |
| 610 | show_in_reg(4); |
Jean Delvare | 6b9aad2 | 2007-07-05 20:37:21 +0200 | [diff] [blame] | 611 | show_in_reg(5); |
| 612 | show_in_reg(6); |
| 613 | show_in_reg(7); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 614 | |
| 615 | /* Temps */ |
| 616 | |
Jean Delvare | b353a48 | 2007-07-05 20:36:12 +0200 | [diff] [blame] | 617 | static ssize_t show_temp(struct device *dev, struct device_attribute *attr, |
| 618 | char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 619 | { |
Jean Delvare | b353a48 | 2007-07-05 20:36:12 +0200 | [diff] [blame] | 620 | int nr = to_sensor_dev_attr(attr)->index; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 621 | struct lm85_data *data = lm85_update_device(dev); |
Jean Delvare | 1f44809 | 2008-04-29 14:03:37 +0200 | [diff] [blame] | 622 | return sprintf(buf, "%d\n", TEMPEXT_FROM_REG(data->temp[nr], |
| 623 | data->temp_ext[nr])); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 624 | } |
Jean Delvare | b353a48 | 2007-07-05 20:36:12 +0200 | [diff] [blame] | 625 | |
| 626 | static ssize_t show_temp_min(struct device *dev, struct device_attribute *attr, |
| 627 | char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 628 | { |
Jean Delvare | b353a48 | 2007-07-05 20:36:12 +0200 | [diff] [blame] | 629 | int nr = to_sensor_dev_attr(attr)->index; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 630 | struct lm85_data *data = lm85_update_device(dev); |
Jean Delvare | 1f44809 | 2008-04-29 14:03:37 +0200 | [diff] [blame] | 631 | return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_min[nr])); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 632 | } |
Jean Delvare | b353a48 | 2007-07-05 20:36:12 +0200 | [diff] [blame] | 633 | |
| 634 | static ssize_t set_temp_min(struct device *dev, struct device_attribute *attr, |
| 635 | const char *buf, size_t count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 636 | { |
Jean Delvare | b353a48 | 2007-07-05 20:36:12 +0200 | [diff] [blame] | 637 | int nr = to_sensor_dev_attr(attr)->index; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 638 | struct i2c_client *client = to_i2c_client(dev); |
| 639 | struct lm85_data *data = i2c_get_clientdata(client); |
| 640 | long val = simple_strtol(buf, NULL, 10); |
| 641 | |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 642 | mutex_lock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 643 | data->temp_min[nr] = TEMP_TO_REG(val); |
| 644 | 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] | 645 | mutex_unlock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 646 | return count; |
| 647 | } |
Jean Delvare | b353a48 | 2007-07-05 20:36:12 +0200 | [diff] [blame] | 648 | |
| 649 | static ssize_t show_temp_max(struct device *dev, struct device_attribute *attr, |
| 650 | char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 651 | { |
Jean Delvare | b353a48 | 2007-07-05 20:36:12 +0200 | [diff] [blame] | 652 | int nr = to_sensor_dev_attr(attr)->index; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 653 | struct lm85_data *data = lm85_update_device(dev); |
Jean Delvare | 1f44809 | 2008-04-29 14:03:37 +0200 | [diff] [blame] | 654 | return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_max[nr])); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 655 | } |
Jean Delvare | b353a48 | 2007-07-05 20:36:12 +0200 | [diff] [blame] | 656 | |
| 657 | static ssize_t set_temp_max(struct device *dev, struct device_attribute *attr, |
| 658 | const char *buf, size_t count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 659 | { |
Jean Delvare | b353a48 | 2007-07-05 20:36:12 +0200 | [diff] [blame] | 660 | int nr = to_sensor_dev_attr(attr)->index; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 661 | struct i2c_client *client = to_i2c_client(dev); |
| 662 | struct lm85_data *data = i2c_get_clientdata(client); |
Jean Delvare | 1f44809 | 2008-04-29 14:03:37 +0200 | [diff] [blame] | 663 | long val = simple_strtol(buf, NULL, 10); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 664 | |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 665 | mutex_lock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 666 | data->temp_max[nr] = TEMP_TO_REG(val); |
| 667 | 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] | 668 | mutex_unlock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 669 | return count; |
| 670 | } |
Jean Delvare | b353a48 | 2007-07-05 20:36:12 +0200 | [diff] [blame] | 671 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 672 | #define show_temp_reg(offset) \ |
Jean Delvare | b353a48 | 2007-07-05 20:36:12 +0200 | [diff] [blame] | 673 | static SENSOR_DEVICE_ATTR(temp##offset##_input, S_IRUGO, \ |
| 674 | show_temp, NULL, offset - 1); \ |
| 675 | static SENSOR_DEVICE_ATTR(temp##offset##_min, S_IRUGO | S_IWUSR, \ |
| 676 | show_temp_min, set_temp_min, offset - 1); \ |
| 677 | static SENSOR_DEVICE_ATTR(temp##offset##_max, S_IRUGO | S_IWUSR, \ |
| 678 | show_temp_max, set_temp_max, offset - 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 679 | |
| 680 | show_temp_reg(1); |
| 681 | show_temp_reg(2); |
| 682 | show_temp_reg(3); |
| 683 | |
| 684 | |
| 685 | /* Automatic PWM control */ |
| 686 | |
Jean Delvare | b353a48 | 2007-07-05 20:36:12 +0200 | [diff] [blame] | 687 | static ssize_t show_pwm_auto_channels(struct device *dev, |
| 688 | struct device_attribute *attr, char *buf) |
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 | int nr = to_sensor_dev_attr(attr)->index; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 691 | struct lm85_data *data = lm85_update_device(dev); |
Jean Delvare | 1f44809 | 2008-04-29 14:03:37 +0200 | [diff] [blame] | 692 | return sprintf(buf, "%d\n", ZONE_FROM_REG(data->autofan[nr].config)); |
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 | |
| 695 | static ssize_t set_pwm_auto_channels(struct device *dev, |
| 696 | struct device_attribute *attr, const char *buf, size_t count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 697 | { |
Jean Delvare | b353a48 | 2007-07-05 20:36:12 +0200 | [diff] [blame] | 698 | int nr = to_sensor_dev_attr(attr)->index; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 699 | struct i2c_client *client = to_i2c_client(dev); |
| 700 | struct lm85_data *data = i2c_get_clientdata(client); |
Jean Delvare | 1f44809 | 2008-04-29 14:03:37 +0200 | [diff] [blame] | 701 | long val = simple_strtol(buf, NULL, 10); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 702 | |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 703 | mutex_lock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 704 | data->autofan[nr].config = (data->autofan[nr].config & (~0xe0)) |
Jean Delvare | 1f44809 | 2008-04-29 14:03:37 +0200 | [diff] [blame] | 705 | | ZONE_TO_REG(val); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 706 | lm85_write_value(client, LM85_REG_AFAN_CONFIG(nr), |
| 707 | data->autofan[nr].config); |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 708 | mutex_unlock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 709 | return count; |
| 710 | } |
Jean Delvare | b353a48 | 2007-07-05 20:36:12 +0200 | [diff] [blame] | 711 | |
| 712 | static ssize_t show_pwm_auto_pwm_min(struct device *dev, |
| 713 | struct device_attribute *attr, char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 714 | { |
Jean Delvare | b353a48 | 2007-07-05 20:36:12 +0200 | [diff] [blame] | 715 | int nr = to_sensor_dev_attr(attr)->index; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 716 | struct lm85_data *data = lm85_update_device(dev); |
Jean Delvare | 1f44809 | 2008-04-29 14:03:37 +0200 | [diff] [blame] | 717 | 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] | 718 | } |
Jean Delvare | b353a48 | 2007-07-05 20:36:12 +0200 | [diff] [blame] | 719 | |
| 720 | static ssize_t set_pwm_auto_pwm_min(struct device *dev, |
| 721 | struct device_attribute *attr, const char *buf, size_t count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 722 | { |
Jean Delvare | b353a48 | 2007-07-05 20:36:12 +0200 | [diff] [blame] | 723 | int nr = to_sensor_dev_attr(attr)->index; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 724 | struct i2c_client *client = to_i2c_client(dev); |
| 725 | struct lm85_data *data = i2c_get_clientdata(client); |
| 726 | long val = simple_strtol(buf, NULL, 10); |
| 727 | |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 728 | mutex_lock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 729 | data->autofan[nr].min_pwm = PWM_TO_REG(val); |
| 730 | lm85_write_value(client, LM85_REG_AFAN_MINPWM(nr), |
| 731 | data->autofan[nr].min_pwm); |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 732 | mutex_unlock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 733 | return count; |
| 734 | } |
Jean Delvare | b353a48 | 2007-07-05 20:36:12 +0200 | [diff] [blame] | 735 | |
| 736 | static ssize_t show_pwm_auto_pwm_minctl(struct device *dev, |
| 737 | struct device_attribute *attr, char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 738 | { |
Jean Delvare | b353a48 | 2007-07-05 20:36:12 +0200 | [diff] [blame] | 739 | int nr = to_sensor_dev_attr(attr)->index; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 740 | struct lm85_data *data = lm85_update_device(dev); |
Jean Delvare | 1f44809 | 2008-04-29 14:03:37 +0200 | [diff] [blame] | 741 | return sprintf(buf, "%d\n", data->autofan[nr].min_off); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 742 | } |
Jean Delvare | b353a48 | 2007-07-05 20:36:12 +0200 | [diff] [blame] | 743 | |
| 744 | static ssize_t set_pwm_auto_pwm_minctl(struct device *dev, |
| 745 | struct device_attribute *attr, const char *buf, size_t count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 746 | { |
Jean Delvare | b353a48 | 2007-07-05 20:36:12 +0200 | [diff] [blame] | 747 | int nr = to_sensor_dev_attr(attr)->index; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 748 | struct i2c_client *client = to_i2c_client(dev); |
| 749 | struct lm85_data *data = i2c_get_clientdata(client); |
| 750 | long val = simple_strtol(buf, NULL, 10); |
Jean Delvare | 7133e56 | 2008-04-12 19:56:35 +0200 | [diff] [blame] | 751 | u8 tmp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 752 | |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 753 | mutex_lock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 754 | data->autofan[nr].min_off = val; |
Jean Delvare | 7133e56 | 2008-04-12 19:56:35 +0200 | [diff] [blame] | 755 | tmp = lm85_read_value(client, LM85_REG_AFAN_SPIKE1); |
| 756 | tmp &= ~(0x20 << nr); |
| 757 | if (data->autofan[nr].min_off) |
| 758 | tmp |= 0x20 << nr; |
| 759 | lm85_write_value(client, LM85_REG_AFAN_SPIKE1, tmp); |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 760 | mutex_unlock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 761 | return count; |
| 762 | } |
Jean Delvare | b353a48 | 2007-07-05 20:36:12 +0200 | [diff] [blame] | 763 | |
| 764 | static ssize_t show_pwm_auto_pwm_freq(struct device *dev, |
| 765 | struct device_attribute *attr, char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 766 | { |
Jean Delvare | b353a48 | 2007-07-05 20:36:12 +0200 | [diff] [blame] | 767 | int nr = to_sensor_dev_attr(attr)->index; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 768 | struct lm85_data *data = lm85_update_device(dev); |
Jean Delvare | 1f44809 | 2008-04-29 14:03:37 +0200 | [diff] [blame] | 769 | return sprintf(buf, "%d\n", FREQ_FROM_REG(data->autofan[nr].freq)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 770 | } |
Jean Delvare | b353a48 | 2007-07-05 20:36:12 +0200 | [diff] [blame] | 771 | |
| 772 | static ssize_t set_pwm_auto_pwm_freq(struct device *dev, |
| 773 | struct device_attribute *attr, const char *buf, size_t count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 774 | { |
Jean Delvare | b353a48 | 2007-07-05 20:36:12 +0200 | [diff] [blame] | 775 | int nr = to_sensor_dev_attr(attr)->index; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 776 | struct i2c_client *client = to_i2c_client(dev); |
| 777 | struct lm85_data *data = i2c_get_clientdata(client); |
| 778 | long val = simple_strtol(buf, NULL, 10); |
| 779 | |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 780 | mutex_lock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 781 | data->autofan[nr].freq = FREQ_TO_REG(val); |
| 782 | lm85_write_value(client, LM85_REG_AFAN_RANGE(nr), |
| 783 | (data->zone[nr].range << 4) |
Jean Delvare | 1f44809 | 2008-04-29 14:03:37 +0200 | [diff] [blame] | 784 | | data->autofan[nr].freq); |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 785 | mutex_unlock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 786 | return count; |
| 787 | } |
Jean Delvare | b353a48 | 2007-07-05 20:36:12 +0200 | [diff] [blame] | 788 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 789 | #define pwm_auto(offset) \ |
Jean Delvare | b353a48 | 2007-07-05 20:36:12 +0200 | [diff] [blame] | 790 | static SENSOR_DEVICE_ATTR(pwm##offset##_auto_channels, \ |
| 791 | S_IRUGO | S_IWUSR, show_pwm_auto_channels, \ |
| 792 | set_pwm_auto_channels, offset - 1); \ |
| 793 | static SENSOR_DEVICE_ATTR(pwm##offset##_auto_pwm_min, \ |
| 794 | S_IRUGO | S_IWUSR, show_pwm_auto_pwm_min, \ |
| 795 | set_pwm_auto_pwm_min, offset - 1); \ |
| 796 | static SENSOR_DEVICE_ATTR(pwm##offset##_auto_pwm_minctl, \ |
| 797 | S_IRUGO | S_IWUSR, show_pwm_auto_pwm_minctl, \ |
| 798 | set_pwm_auto_pwm_minctl, offset - 1); \ |
| 799 | static SENSOR_DEVICE_ATTR(pwm##offset##_auto_pwm_freq, \ |
| 800 | S_IRUGO | S_IWUSR, show_pwm_auto_pwm_freq, \ |
| 801 | set_pwm_auto_pwm_freq, offset - 1); |
| 802 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 803 | pwm_auto(1); |
| 804 | pwm_auto(2); |
| 805 | pwm_auto(3); |
| 806 | |
| 807 | /* Temperature settings for automatic PWM control */ |
| 808 | |
Jean Delvare | b353a48 | 2007-07-05 20:36:12 +0200 | [diff] [blame] | 809 | static ssize_t show_temp_auto_temp_off(struct device *dev, |
| 810 | struct device_attribute *attr, char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 811 | { |
Jean Delvare | b353a48 | 2007-07-05 20:36:12 +0200 | [diff] [blame] | 812 | int nr = to_sensor_dev_attr(attr)->index; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 813 | struct lm85_data *data = lm85_update_device(dev); |
Jean Delvare | 1f44809 | 2008-04-29 14:03:37 +0200 | [diff] [blame] | 814 | return sprintf(buf, "%d\n", TEMP_FROM_REG(data->zone[nr].limit) - |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 815 | HYST_FROM_REG(data->zone[nr].hyst)); |
| 816 | } |
Jean Delvare | b353a48 | 2007-07-05 20:36:12 +0200 | [diff] [blame] | 817 | |
| 818 | static ssize_t set_temp_auto_temp_off(struct device *dev, |
| 819 | struct device_attribute *attr, const char *buf, size_t count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 820 | { |
Jean Delvare | b353a48 | 2007-07-05 20:36:12 +0200 | [diff] [blame] | 821 | int nr = to_sensor_dev_attr(attr)->index; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 822 | struct i2c_client *client = to_i2c_client(dev); |
| 823 | struct lm85_data *data = i2c_get_clientdata(client); |
| 824 | int min; |
| 825 | long val = simple_strtol(buf, NULL, 10); |
| 826 | |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 827 | mutex_lock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 828 | min = TEMP_FROM_REG(data->zone[nr].limit); |
| 829 | data->zone[nr].off_desired = TEMP_TO_REG(val); |
| 830 | data->zone[nr].hyst = HYST_TO_REG(min - val); |
Jean Delvare | 1f44809 | 2008-04-29 14:03:37 +0200 | [diff] [blame] | 831 | if (nr == 0 || nr == 1) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 832 | lm85_write_value(client, LM85_REG_AFAN_HYST1, |
| 833 | (data->zone[0].hyst << 4) |
Jean Delvare | 1f44809 | 2008-04-29 14:03:37 +0200 | [diff] [blame] | 834 | | data->zone[1].hyst); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 835 | } else { |
| 836 | lm85_write_value(client, LM85_REG_AFAN_HYST2, |
Jean Delvare | 1f44809 | 2008-04-29 14:03:37 +0200 | [diff] [blame] | 837 | (data->zone[2].hyst << 4)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 838 | } |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 839 | mutex_unlock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 840 | return count; |
| 841 | } |
Jean Delvare | b353a48 | 2007-07-05 20:36:12 +0200 | [diff] [blame] | 842 | |
| 843 | static ssize_t show_temp_auto_temp_min(struct device *dev, |
| 844 | struct device_attribute *attr, 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", TEMP_FROM_REG(data->zone[nr].limit)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 849 | } |
Jean Delvare | b353a48 | 2007-07-05 20:36:12 +0200 | [diff] [blame] | 850 | |
| 851 | static ssize_t set_temp_auto_temp_min(struct device *dev, |
| 852 | struct device_attribute *attr, const char *buf, size_t count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 853 | { |
Jean Delvare | b353a48 | 2007-07-05 20:36:12 +0200 | [diff] [blame] | 854 | int nr = to_sensor_dev_attr(attr)->index; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 855 | struct i2c_client *client = to_i2c_client(dev); |
| 856 | struct lm85_data *data = i2c_get_clientdata(client); |
| 857 | long val = simple_strtol(buf, NULL, 10); |
| 858 | |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 859 | mutex_lock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 860 | data->zone[nr].limit = TEMP_TO_REG(val); |
| 861 | lm85_write_value(client, LM85_REG_AFAN_LIMIT(nr), |
| 862 | data->zone[nr].limit); |
| 863 | |
| 864 | /* Update temp_auto_max and temp_auto_range */ |
| 865 | data->zone[nr].range = RANGE_TO_REG( |
| 866 | TEMP_FROM_REG(data->zone[nr].max_desired) - |
| 867 | TEMP_FROM_REG(data->zone[nr].limit)); |
| 868 | lm85_write_value(client, LM85_REG_AFAN_RANGE(nr), |
| 869 | ((data->zone[nr].range & 0x0f) << 4) |
| 870 | | (data->autofan[nr].freq & 0x07)); |
| 871 | |
| 872 | /* Update temp_auto_hyst and temp_auto_off */ |
| 873 | data->zone[nr].hyst = HYST_TO_REG(TEMP_FROM_REG( |
| 874 | data->zone[nr].limit) - TEMP_FROM_REG( |
| 875 | data->zone[nr].off_desired)); |
Jean Delvare | 1f44809 | 2008-04-29 14:03:37 +0200 | [diff] [blame] | 876 | if (nr == 0 || nr == 1) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 877 | lm85_write_value(client, LM85_REG_AFAN_HYST1, |
| 878 | (data->zone[0].hyst << 4) |
Jean Delvare | 1f44809 | 2008-04-29 14:03:37 +0200 | [diff] [blame] | 879 | | data->zone[1].hyst); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 880 | } else { |
| 881 | lm85_write_value(client, LM85_REG_AFAN_HYST2, |
Jean Delvare | 1f44809 | 2008-04-29 14:03:37 +0200 | [diff] [blame] | 882 | (data->zone[2].hyst << 4)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 883 | } |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 884 | mutex_unlock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 885 | return count; |
| 886 | } |
Jean Delvare | b353a48 | 2007-07-05 20:36:12 +0200 | [diff] [blame] | 887 | |
| 888 | static ssize_t show_temp_auto_temp_max(struct device *dev, |
| 889 | struct device_attribute *attr, char *buf) |
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; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 892 | struct lm85_data *data = lm85_update_device(dev); |
Jean Delvare | 1f44809 | 2008-04-29 14:03:37 +0200 | [diff] [blame] | 893 | return sprintf(buf, "%d\n", TEMP_FROM_REG(data->zone[nr].limit) + |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 894 | RANGE_FROM_REG(data->zone[nr].range)); |
| 895 | } |
Jean Delvare | b353a48 | 2007-07-05 20:36:12 +0200 | [diff] [blame] | 896 | |
| 897 | static ssize_t set_temp_auto_temp_max(struct device *dev, |
| 898 | struct device_attribute *attr, const char *buf, size_t count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 899 | { |
Jean Delvare | b353a48 | 2007-07-05 20:36:12 +0200 | [diff] [blame] | 900 | int nr = to_sensor_dev_attr(attr)->index; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 901 | struct i2c_client *client = to_i2c_client(dev); |
| 902 | struct lm85_data *data = i2c_get_clientdata(client); |
| 903 | int min; |
| 904 | long val = simple_strtol(buf, NULL, 10); |
| 905 | |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 906 | mutex_lock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 907 | min = TEMP_FROM_REG(data->zone[nr].limit); |
| 908 | data->zone[nr].max_desired = TEMP_TO_REG(val); |
| 909 | data->zone[nr].range = RANGE_TO_REG( |
| 910 | val - min); |
| 911 | lm85_write_value(client, LM85_REG_AFAN_RANGE(nr), |
| 912 | ((data->zone[nr].range & 0x0f) << 4) |
| 913 | | (data->autofan[nr].freq & 0x07)); |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 914 | mutex_unlock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 915 | return count; |
| 916 | } |
Jean Delvare | b353a48 | 2007-07-05 20:36:12 +0200 | [diff] [blame] | 917 | |
| 918 | static ssize_t show_temp_auto_temp_crit(struct device *dev, |
| 919 | struct device_attribute *attr, char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 920 | { |
Jean Delvare | b353a48 | 2007-07-05 20:36:12 +0200 | [diff] [blame] | 921 | int nr = to_sensor_dev_attr(attr)->index; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 922 | struct lm85_data *data = lm85_update_device(dev); |
Jean Delvare | 1f44809 | 2008-04-29 14:03:37 +0200 | [diff] [blame] | 923 | return sprintf(buf, "%d\n", TEMP_FROM_REG(data->zone[nr].critical)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 924 | } |
Jean Delvare | b353a48 | 2007-07-05 20:36:12 +0200 | [diff] [blame] | 925 | |
| 926 | static ssize_t set_temp_auto_temp_crit(struct device *dev, |
Jean Delvare | 1f44809 | 2008-04-29 14:03:37 +0200 | [diff] [blame] | 927 | struct device_attribute *attr, const char *buf, size_t count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 928 | { |
Jean Delvare | b353a48 | 2007-07-05 20:36:12 +0200 | [diff] [blame] | 929 | int nr = to_sensor_dev_attr(attr)->index; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 930 | struct i2c_client *client = to_i2c_client(dev); |
| 931 | struct lm85_data *data = i2c_get_clientdata(client); |
| 932 | long val = simple_strtol(buf, NULL, 10); |
| 933 | |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 934 | mutex_lock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 935 | data->zone[nr].critical = TEMP_TO_REG(val); |
| 936 | lm85_write_value(client, LM85_REG_AFAN_CRITICAL(nr), |
| 937 | data->zone[nr].critical); |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 938 | mutex_unlock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 939 | return count; |
| 940 | } |
Jean Delvare | b353a48 | 2007-07-05 20:36:12 +0200 | [diff] [blame] | 941 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 942 | #define temp_auto(offset) \ |
Jean Delvare | b353a48 | 2007-07-05 20:36:12 +0200 | [diff] [blame] | 943 | static SENSOR_DEVICE_ATTR(temp##offset##_auto_temp_off, \ |
| 944 | S_IRUGO | S_IWUSR, show_temp_auto_temp_off, \ |
| 945 | set_temp_auto_temp_off, offset - 1); \ |
| 946 | static SENSOR_DEVICE_ATTR(temp##offset##_auto_temp_min, \ |
| 947 | S_IRUGO | S_IWUSR, show_temp_auto_temp_min, \ |
| 948 | set_temp_auto_temp_min, offset - 1); \ |
| 949 | static SENSOR_DEVICE_ATTR(temp##offset##_auto_temp_max, \ |
| 950 | S_IRUGO | S_IWUSR, show_temp_auto_temp_max, \ |
| 951 | set_temp_auto_temp_max, offset - 1); \ |
| 952 | static SENSOR_DEVICE_ATTR(temp##offset##_auto_temp_crit, \ |
| 953 | S_IRUGO | S_IWUSR, show_temp_auto_temp_crit, \ |
| 954 | set_temp_auto_temp_crit, offset - 1); |
| 955 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 956 | temp_auto(1); |
| 957 | temp_auto(2); |
| 958 | temp_auto(3); |
| 959 | |
Ben Dooks | d8d2061 | 2005-10-26 21:05:46 +0200 | [diff] [blame] | 960 | static int lm85_attach_adapter(struct i2c_adapter *adapter) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 961 | { |
| 962 | if (!(adapter->class & I2C_CLASS_HWMON)) |
| 963 | return 0; |
Jean Delvare | 2ed2dc3 | 2005-07-31 21:42:02 +0200 | [diff] [blame] | 964 | return i2c_probe(adapter, &addr_data, lm85_detect); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 965 | } |
| 966 | |
Mark M. Hoffman | 0501a38 | 2006-09-24 21:14:35 +0200 | [diff] [blame] | 967 | static struct attribute *lm85_attributes[] = { |
Jean Delvare | b353a48 | 2007-07-05 20:36:12 +0200 | [diff] [blame] | 968 | &sensor_dev_attr_fan1_input.dev_attr.attr, |
| 969 | &sensor_dev_attr_fan2_input.dev_attr.attr, |
| 970 | &sensor_dev_attr_fan3_input.dev_attr.attr, |
| 971 | &sensor_dev_attr_fan4_input.dev_attr.attr, |
| 972 | &sensor_dev_attr_fan1_min.dev_attr.attr, |
| 973 | &sensor_dev_attr_fan2_min.dev_attr.attr, |
| 974 | &sensor_dev_attr_fan3_min.dev_attr.attr, |
| 975 | &sensor_dev_attr_fan4_min.dev_attr.attr, |
Jean Delvare | bf76e9d | 2007-07-05 20:37:58 +0200 | [diff] [blame] | 976 | &sensor_dev_attr_fan1_alarm.dev_attr.attr, |
| 977 | &sensor_dev_attr_fan2_alarm.dev_attr.attr, |
| 978 | &sensor_dev_attr_fan3_alarm.dev_attr.attr, |
| 979 | &sensor_dev_attr_fan4_alarm.dev_attr.attr, |
Jean Delvare | b353a48 | 2007-07-05 20:36:12 +0200 | [diff] [blame] | 980 | |
| 981 | &sensor_dev_attr_pwm1.dev_attr.attr, |
| 982 | &sensor_dev_attr_pwm2.dev_attr.attr, |
| 983 | &sensor_dev_attr_pwm3.dev_attr.attr, |
| 984 | &sensor_dev_attr_pwm1_enable.dev_attr.attr, |
| 985 | &sensor_dev_attr_pwm2_enable.dev_attr.attr, |
| 986 | &sensor_dev_attr_pwm3_enable.dev_attr.attr, |
| 987 | |
| 988 | &sensor_dev_attr_in0_input.dev_attr.attr, |
| 989 | &sensor_dev_attr_in1_input.dev_attr.attr, |
| 990 | &sensor_dev_attr_in2_input.dev_attr.attr, |
| 991 | &sensor_dev_attr_in3_input.dev_attr.attr, |
| 992 | &sensor_dev_attr_in0_min.dev_attr.attr, |
| 993 | &sensor_dev_attr_in1_min.dev_attr.attr, |
| 994 | &sensor_dev_attr_in2_min.dev_attr.attr, |
| 995 | &sensor_dev_attr_in3_min.dev_attr.attr, |
| 996 | &sensor_dev_attr_in0_max.dev_attr.attr, |
| 997 | &sensor_dev_attr_in1_max.dev_attr.attr, |
| 998 | &sensor_dev_attr_in2_max.dev_attr.attr, |
| 999 | &sensor_dev_attr_in3_max.dev_attr.attr, |
Jean Delvare | bf76e9d | 2007-07-05 20:37:58 +0200 | [diff] [blame] | 1000 | &sensor_dev_attr_in0_alarm.dev_attr.attr, |
| 1001 | &sensor_dev_attr_in1_alarm.dev_attr.attr, |
| 1002 | &sensor_dev_attr_in2_alarm.dev_attr.attr, |
| 1003 | &sensor_dev_attr_in3_alarm.dev_attr.attr, |
Jean Delvare | b353a48 | 2007-07-05 20:36:12 +0200 | [diff] [blame] | 1004 | |
| 1005 | &sensor_dev_attr_temp1_input.dev_attr.attr, |
| 1006 | &sensor_dev_attr_temp2_input.dev_attr.attr, |
| 1007 | &sensor_dev_attr_temp3_input.dev_attr.attr, |
| 1008 | &sensor_dev_attr_temp1_min.dev_attr.attr, |
| 1009 | &sensor_dev_attr_temp2_min.dev_attr.attr, |
| 1010 | &sensor_dev_attr_temp3_min.dev_attr.attr, |
| 1011 | &sensor_dev_attr_temp1_max.dev_attr.attr, |
| 1012 | &sensor_dev_attr_temp2_max.dev_attr.attr, |
| 1013 | &sensor_dev_attr_temp3_max.dev_attr.attr, |
Jean Delvare | bf76e9d | 2007-07-05 20:37:58 +0200 | [diff] [blame] | 1014 | &sensor_dev_attr_temp1_alarm.dev_attr.attr, |
| 1015 | &sensor_dev_attr_temp2_alarm.dev_attr.attr, |
| 1016 | &sensor_dev_attr_temp3_alarm.dev_attr.attr, |
| 1017 | &sensor_dev_attr_temp1_fault.dev_attr.attr, |
| 1018 | &sensor_dev_attr_temp3_fault.dev_attr.attr, |
Jean Delvare | b353a48 | 2007-07-05 20:36:12 +0200 | [diff] [blame] | 1019 | |
| 1020 | &sensor_dev_attr_pwm1_auto_channels.dev_attr.attr, |
| 1021 | &sensor_dev_attr_pwm2_auto_channels.dev_attr.attr, |
| 1022 | &sensor_dev_attr_pwm3_auto_channels.dev_attr.attr, |
| 1023 | &sensor_dev_attr_pwm1_auto_pwm_min.dev_attr.attr, |
| 1024 | &sensor_dev_attr_pwm2_auto_pwm_min.dev_attr.attr, |
| 1025 | &sensor_dev_attr_pwm3_auto_pwm_min.dev_attr.attr, |
| 1026 | &sensor_dev_attr_pwm1_auto_pwm_minctl.dev_attr.attr, |
| 1027 | &sensor_dev_attr_pwm2_auto_pwm_minctl.dev_attr.attr, |
| 1028 | &sensor_dev_attr_pwm3_auto_pwm_minctl.dev_attr.attr, |
| 1029 | &sensor_dev_attr_pwm1_auto_pwm_freq.dev_attr.attr, |
| 1030 | &sensor_dev_attr_pwm2_auto_pwm_freq.dev_attr.attr, |
| 1031 | &sensor_dev_attr_pwm3_auto_pwm_freq.dev_attr.attr, |
| 1032 | |
| 1033 | &sensor_dev_attr_temp1_auto_temp_off.dev_attr.attr, |
| 1034 | &sensor_dev_attr_temp2_auto_temp_off.dev_attr.attr, |
| 1035 | &sensor_dev_attr_temp3_auto_temp_off.dev_attr.attr, |
| 1036 | &sensor_dev_attr_temp1_auto_temp_min.dev_attr.attr, |
| 1037 | &sensor_dev_attr_temp2_auto_temp_min.dev_attr.attr, |
| 1038 | &sensor_dev_attr_temp3_auto_temp_min.dev_attr.attr, |
| 1039 | &sensor_dev_attr_temp1_auto_temp_max.dev_attr.attr, |
| 1040 | &sensor_dev_attr_temp2_auto_temp_max.dev_attr.attr, |
| 1041 | &sensor_dev_attr_temp3_auto_temp_max.dev_attr.attr, |
| 1042 | &sensor_dev_attr_temp1_auto_temp_crit.dev_attr.attr, |
| 1043 | &sensor_dev_attr_temp2_auto_temp_crit.dev_attr.attr, |
| 1044 | &sensor_dev_attr_temp3_auto_temp_crit.dev_attr.attr, |
| 1045 | |
Mark M. Hoffman | 0501a38 | 2006-09-24 21:14:35 +0200 | [diff] [blame] | 1046 | &dev_attr_vrm.attr, |
| 1047 | &dev_attr_cpu0_vid.attr, |
| 1048 | &dev_attr_alarms.attr, |
Mark M. Hoffman | 0501a38 | 2006-09-24 21:14:35 +0200 | [diff] [blame] | 1049 | NULL |
| 1050 | }; |
| 1051 | |
| 1052 | static const struct attribute_group lm85_group = { |
| 1053 | .attrs = lm85_attributes, |
| 1054 | }; |
| 1055 | |
Jean Delvare | 6b9aad2 | 2007-07-05 20:37:21 +0200 | [diff] [blame] | 1056 | static struct attribute *lm85_attributes_in4[] = { |
Jean Delvare | b353a48 | 2007-07-05 20:36:12 +0200 | [diff] [blame] | 1057 | &sensor_dev_attr_in4_input.dev_attr.attr, |
| 1058 | &sensor_dev_attr_in4_min.dev_attr.attr, |
| 1059 | &sensor_dev_attr_in4_max.dev_attr.attr, |
Jean Delvare | bf76e9d | 2007-07-05 20:37:58 +0200 | [diff] [blame] | 1060 | &sensor_dev_attr_in4_alarm.dev_attr.attr, |
Mark M. Hoffman | 0501a38 | 2006-09-24 21:14:35 +0200 | [diff] [blame] | 1061 | NULL |
| 1062 | }; |
| 1063 | |
Jean Delvare | 6b9aad2 | 2007-07-05 20:37:21 +0200 | [diff] [blame] | 1064 | static const struct attribute_group lm85_group_in4 = { |
| 1065 | .attrs = lm85_attributes_in4, |
| 1066 | }; |
| 1067 | |
| 1068 | static struct attribute *lm85_attributes_in567[] = { |
| 1069 | &sensor_dev_attr_in5_input.dev_attr.attr, |
| 1070 | &sensor_dev_attr_in6_input.dev_attr.attr, |
| 1071 | &sensor_dev_attr_in7_input.dev_attr.attr, |
| 1072 | &sensor_dev_attr_in5_min.dev_attr.attr, |
| 1073 | &sensor_dev_attr_in6_min.dev_attr.attr, |
| 1074 | &sensor_dev_attr_in7_min.dev_attr.attr, |
| 1075 | &sensor_dev_attr_in5_max.dev_attr.attr, |
| 1076 | &sensor_dev_attr_in6_max.dev_attr.attr, |
| 1077 | &sensor_dev_attr_in7_max.dev_attr.attr, |
Jean Delvare | bf76e9d | 2007-07-05 20:37:58 +0200 | [diff] [blame] | 1078 | &sensor_dev_attr_in5_alarm.dev_attr.attr, |
| 1079 | &sensor_dev_attr_in6_alarm.dev_attr.attr, |
| 1080 | &sensor_dev_attr_in7_alarm.dev_attr.attr, |
Jean Delvare | 6b9aad2 | 2007-07-05 20:37:21 +0200 | [diff] [blame] | 1081 | NULL |
| 1082 | }; |
| 1083 | |
| 1084 | static const struct attribute_group lm85_group_in567 = { |
| 1085 | .attrs = lm85_attributes_in567, |
Mark M. Hoffman | 0501a38 | 2006-09-24 21:14:35 +0200 | [diff] [blame] | 1086 | }; |
| 1087 | |
Jean Delvare | 5f4475947 | 2008-06-25 09:10:30 -0400 | [diff] [blame^] | 1088 | static void lm85_init_client(struct i2c_client *client) |
| 1089 | { |
| 1090 | int value; |
| 1091 | |
| 1092 | /* Start monitoring if needed */ |
| 1093 | value = lm85_read_value(client, LM85_REG_CONFIG); |
| 1094 | if (!(value & 0x01)) { |
| 1095 | dev_info(&client->dev, "Starting monitoring\n"); |
| 1096 | lm85_write_value(client, LM85_REG_CONFIG, value | 0x01); |
| 1097 | } |
| 1098 | |
| 1099 | /* Warn about unusual configuration bits */ |
| 1100 | if (value & 0x02) |
| 1101 | dev_warn(&client->dev, "Device configuration is locked\n"); |
| 1102 | if (!(value & 0x04)) |
| 1103 | dev_warn(&client->dev, "Device is not ready\n"); |
| 1104 | } |
| 1105 | |
Ben Dooks | d8d2061 | 2005-10-26 21:05:46 +0200 | [diff] [blame] | 1106 | static int lm85_detect(struct i2c_adapter *adapter, int address, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1107 | int kind) |
| 1108 | { |
Jean Delvare | 1f44809 | 2008-04-29 14:03:37 +0200 | [diff] [blame] | 1109 | int company, verstep; |
Jean Delvare | e89e22b | 2008-06-25 08:47:35 -0400 | [diff] [blame] | 1110 | struct i2c_client *client; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1111 | struct lm85_data *data; |
| 1112 | int err = 0; |
Jean Delvare | e89e22b | 2008-06-25 08:47:35 -0400 | [diff] [blame] | 1113 | const char *type_name; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1114 | |
Jean Delvare | e89e22b | 2008-06-25 08:47:35 -0400 | [diff] [blame] | 1115 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1116 | /* We need to be able to do byte I/O */ |
Jean Delvare | 1f44809 | 2008-04-29 14:03:37 +0200 | [diff] [blame] | 1117 | goto ERROR0; |
| 1118 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1119 | |
| 1120 | /* OK. For now, we presume we have a valid client. We now create the |
| 1121 | client structure, even though we cannot fill it completely yet. |
| 1122 | But it allows us to access lm85_{read,write}_value. */ |
| 1123 | |
Deepak Saxena | ba9c2e8 | 2005-10-17 23:08:32 +0200 | [diff] [blame] | 1124 | if (!(data = kzalloc(sizeof(struct lm85_data), GFP_KERNEL))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1125 | err = -ENOMEM; |
| 1126 | goto ERROR0; |
| 1127 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1128 | |
Jean Delvare | e89e22b | 2008-06-25 08:47:35 -0400 | [diff] [blame] | 1129 | client = &data->client; |
| 1130 | i2c_set_clientdata(client, data); |
| 1131 | client->addr = address; |
| 1132 | client->adapter = adapter; |
| 1133 | client->driver = &lm85_driver; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1134 | |
| 1135 | /* Now, we do the remaining detection. */ |
| 1136 | |
Jean Delvare | e89e22b | 2008-06-25 08:47:35 -0400 | [diff] [blame] | 1137 | company = lm85_read_value(client, LM85_REG_COMPANY); |
| 1138 | verstep = lm85_read_value(client, LM85_REG_VERSTEP); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1139 | |
| 1140 | dev_dbg(&adapter->dev, "Detecting device at %d,0x%02x with" |
| 1141 | " COMPANY: 0x%02x and VERSTEP: 0x%02x\n", |
Jean Delvare | e89e22b | 2008-06-25 08:47:35 -0400 | [diff] [blame] | 1142 | i2c_adapter_id(client->adapter), client->addr, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1143 | company, verstep); |
| 1144 | |
| 1145 | /* If auto-detecting, Determine the chip type. */ |
| 1146 | if (kind <= 0) { |
| 1147 | dev_dbg(&adapter->dev, "Autodetecting device at %d,0x%02x ...\n", |
Jean Delvare | 1f44809 | 2008-04-29 14:03:37 +0200 | [diff] [blame] | 1148 | i2c_adapter_id(adapter), address); |
| 1149 | if (company == LM85_COMPANY_NATIONAL |
| 1150 | && verstep == LM85_VERSTEP_LM85C) { |
| 1151 | kind = lm85c; |
| 1152 | } else if (company == LM85_COMPANY_NATIONAL |
| 1153 | && verstep == LM85_VERSTEP_LM85B) { |
| 1154 | kind = lm85b; |
| 1155 | } else if (company == LM85_COMPANY_NATIONAL |
| 1156 | && (verstep & LM85_VERSTEP_VMASK) == LM85_VERSTEP_GENERIC) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1157 | dev_err(&adapter->dev, "Unrecognized version/stepping 0x%02x" |
| 1158 | " Defaulting to LM85.\n", verstep); |
Jean Delvare | 1f44809 | 2008-04-29 14:03:37 +0200 | [diff] [blame] | 1159 | kind = any_chip; |
| 1160 | } else if (company == LM85_COMPANY_ANALOG_DEV |
| 1161 | && verstep == LM85_VERSTEP_ADM1027) { |
| 1162 | kind = adm1027; |
| 1163 | } else if (company == LM85_COMPANY_ANALOG_DEV |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1164 | && (verstep == LM85_VERSTEP_ADT7463 |
Jean Delvare | 1f44809 | 2008-04-29 14:03:37 +0200 | [diff] [blame] | 1165 | || verstep == LM85_VERSTEP_ADT7463C)) { |
| 1166 | kind = adt7463; |
| 1167 | } else if (company == LM85_COMPANY_ANALOG_DEV |
| 1168 | && (verstep & LM85_VERSTEP_VMASK) == LM85_VERSTEP_GENERIC) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1169 | dev_err(&adapter->dev, "Unrecognized version/stepping 0x%02x" |
Jean Delvare | 1f44809 | 2008-04-29 14:03:37 +0200 | [diff] [blame] | 1170 | " Defaulting to Generic LM85.\n", verstep); |
| 1171 | kind = any_chip; |
| 1172 | } else if (company == LM85_COMPANY_SMSC |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1173 | && (verstep == LM85_VERSTEP_EMC6D100_A0 |
Jean Delvare | 1f44809 | 2008-04-29 14:03:37 +0200 | [diff] [blame] | 1174 | || verstep == LM85_VERSTEP_EMC6D100_A1)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1175 | /* Unfortunately, we can't tell a '100 from a '101 |
| 1176 | * from the registers. Since a '101 is a '100 |
| 1177 | * in a package with fewer pins and therefore no |
| 1178 | * 3.3V, 1.5V or 1.8V inputs, perhaps if those |
| 1179 | * inputs read 0, then it's a '101. |
| 1180 | */ |
Jean Delvare | 1f44809 | 2008-04-29 14:03:37 +0200 | [diff] [blame] | 1181 | kind = emc6d100; |
| 1182 | } else if (company == LM85_COMPANY_SMSC |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1183 | && verstep == LM85_VERSTEP_EMC6D102) { |
Jean Delvare | 1f44809 | 2008-04-29 14:03:37 +0200 | [diff] [blame] | 1184 | kind = emc6d102; |
| 1185 | } else if (company == LM85_COMPANY_SMSC |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1186 | && (verstep & LM85_VERSTEP_VMASK) == LM85_VERSTEP_GENERIC) { |
| 1187 | dev_err(&adapter->dev, "lm85: Detected SMSC chip\n"); |
| 1188 | dev_err(&adapter->dev, "lm85: Unrecognized version/stepping 0x%02x" |
Jean Delvare | 1f44809 | 2008-04-29 14:03:37 +0200 | [diff] [blame] | 1189 | " Defaulting to Generic LM85.\n", verstep); |
| 1190 | kind = any_chip; |
| 1191 | } else if (kind == any_chip |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1192 | && (verstep & LM85_VERSTEP_VMASK) == LM85_VERSTEP_GENERIC) { |
| 1193 | dev_err(&adapter->dev, "Generic LM85 Version 6 detected\n"); |
| 1194 | /* Leave kind as "any_chip" */ |
| 1195 | } else { |
| 1196 | dev_dbg(&adapter->dev, "Autodetection failed\n"); |
Jean Delvare | 1f44809 | 2008-04-29 14:03:37 +0200 | [diff] [blame] | 1197 | /* Not an LM85... */ |
| 1198 | if (kind == any_chip) { /* User used force=x,y */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1199 | dev_err(&adapter->dev, "Generic LM85 Version 6 not" |
| 1200 | " found at %d,0x%02x. Try force_lm85c.\n", |
Jean Delvare | 1f44809 | 2008-04-29 14:03:37 +0200 | [diff] [blame] | 1201 | i2c_adapter_id(adapter), address); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1202 | } |
Jean Delvare | 1f44809 | 2008-04-29 14:03:37 +0200 | [diff] [blame] | 1203 | err = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1204 | goto ERROR1; |
| 1205 | } |
| 1206 | } |
| 1207 | |
| 1208 | /* Fill in the chip specific driver values */ |
Jean Delvare | e89e22b | 2008-06-25 08:47:35 -0400 | [diff] [blame] | 1209 | switch (kind) { |
| 1210 | case lm85b: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1211 | type_name = "lm85b"; |
Jean Delvare | e89e22b | 2008-06-25 08:47:35 -0400 | [diff] [blame] | 1212 | break; |
| 1213 | case lm85c: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1214 | type_name = "lm85c"; |
Jean Delvare | e89e22b | 2008-06-25 08:47:35 -0400 | [diff] [blame] | 1215 | break; |
| 1216 | case adm1027: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1217 | type_name = "adm1027"; |
Jean Delvare | e89e22b | 2008-06-25 08:47:35 -0400 | [diff] [blame] | 1218 | break; |
| 1219 | case adt7463: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1220 | type_name = "adt7463"; |
Jean Delvare | e89e22b | 2008-06-25 08:47:35 -0400 | [diff] [blame] | 1221 | break; |
| 1222 | case emc6d100: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1223 | type_name = "emc6d100"; |
Jean Delvare | e89e22b | 2008-06-25 08:47:35 -0400 | [diff] [blame] | 1224 | break; |
| 1225 | case emc6d102: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1226 | type_name = "emc6d102"; |
Jean Delvare | e89e22b | 2008-06-25 08:47:35 -0400 | [diff] [blame] | 1227 | break; |
| 1228 | default: |
| 1229 | type_name = "lm85"; |
| 1230 | } |
| 1231 | strlcpy(client->name, type_name, I2C_NAME_SIZE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1232 | |
| 1233 | /* Fill in the remaining client fields */ |
| 1234 | data->type = kind; |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 1235 | mutex_init(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1236 | |
| 1237 | /* Tell the I2C layer a new client has arrived */ |
Jean Delvare | e89e22b | 2008-06-25 08:47:35 -0400 | [diff] [blame] | 1238 | err = i2c_attach_client(client); |
| 1239 | if (err) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1240 | goto ERROR1; |
| 1241 | |
| 1242 | /* Set the VRM version */ |
Jean Delvare | 303760b | 2005-07-31 21:52:01 +0200 | [diff] [blame] | 1243 | data->vrm = vid_which_vrm(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1244 | |
| 1245 | /* Initialize the LM85 chip */ |
Jean Delvare | e89e22b | 2008-06-25 08:47:35 -0400 | [diff] [blame] | 1246 | lm85_init_client(client); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1247 | |
| 1248 | /* Register sysfs hooks */ |
Jean Delvare | e89e22b | 2008-06-25 08:47:35 -0400 | [diff] [blame] | 1249 | err = sysfs_create_group(&client->dev.kobj, &lm85_group); |
| 1250 | if (err) |
Mark M. Hoffman | 943b083 | 2005-07-15 21:39:18 -0400 | [diff] [blame] | 1251 | goto ERROR2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1252 | |
Jean Delvare | 9c516ef | 2005-11-26 20:07:54 +0100 | [diff] [blame] | 1253 | /* The ADT7463 has an optional VRM 10 mode where pin 21 is used |
| 1254 | as a sixth digital VID input rather than an analog input. */ |
Jean Delvare | e89e22b | 2008-06-25 08:47:35 -0400 | [diff] [blame] | 1255 | data->vid = lm85_read_value(client, LM85_REG_VID); |
Mark M. Hoffman | 0501a38 | 2006-09-24 21:14:35 +0200 | [diff] [blame] | 1256 | if (!(kind == adt7463 && (data->vid & 0x80))) |
Jean Delvare | e89e22b | 2008-06-25 08:47:35 -0400 | [diff] [blame] | 1257 | if ((err = sysfs_create_group(&client->dev.kobj, |
Jean Delvare | 6b9aad2 | 2007-07-05 20:37:21 +0200 | [diff] [blame] | 1258 | &lm85_group_in4))) |
| 1259 | goto ERROR3; |
| 1260 | |
| 1261 | /* The EMC6D100 has 3 additional voltage inputs */ |
| 1262 | if (kind == emc6d100) |
Jean Delvare | e89e22b | 2008-06-25 08:47:35 -0400 | [diff] [blame] | 1263 | if ((err = sysfs_create_group(&client->dev.kobj, |
Jean Delvare | 6b9aad2 | 2007-07-05 20:37:21 +0200 | [diff] [blame] | 1264 | &lm85_group_in567))) |
Mark M. Hoffman | 0501a38 | 2006-09-24 21:14:35 +0200 | [diff] [blame] | 1265 | goto ERROR3; |
| 1266 | |
Jean Delvare | e89e22b | 2008-06-25 08:47:35 -0400 | [diff] [blame] | 1267 | data->hwmon_dev = hwmon_device_register(&client->dev); |
Tony Jones | 1beeffe | 2007-08-20 13:46:20 -0700 | [diff] [blame] | 1268 | if (IS_ERR(data->hwmon_dev)) { |
| 1269 | err = PTR_ERR(data->hwmon_dev); |
Mark M. Hoffman | 0501a38 | 2006-09-24 21:14:35 +0200 | [diff] [blame] | 1270 | goto ERROR3; |
Jean Delvare | 9c516ef | 2005-11-26 20:07:54 +0100 | [diff] [blame] | 1271 | } |
| 1272 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1273 | return 0; |
| 1274 | |
| 1275 | /* Error out and cleanup code */ |
Jean Delvare | 1f44809 | 2008-04-29 14:03:37 +0200 | [diff] [blame] | 1276 | ERROR3: |
Jean Delvare | e89e22b | 2008-06-25 08:47:35 -0400 | [diff] [blame] | 1277 | sysfs_remove_group(&client->dev.kobj, &lm85_group); |
| 1278 | sysfs_remove_group(&client->dev.kobj, &lm85_group_in4); |
Jean Delvare | 6b9aad2 | 2007-07-05 20:37:21 +0200 | [diff] [blame] | 1279 | if (kind == emc6d100) |
Jean Delvare | e89e22b | 2008-06-25 08:47:35 -0400 | [diff] [blame] | 1280 | sysfs_remove_group(&client->dev.kobj, &lm85_group_in567); |
Jean Delvare | 1f44809 | 2008-04-29 14:03:37 +0200 | [diff] [blame] | 1281 | ERROR2: |
Jean Delvare | e89e22b | 2008-06-25 08:47:35 -0400 | [diff] [blame] | 1282 | i2c_detach_client(client); |
Jean Delvare | 1f44809 | 2008-04-29 14:03:37 +0200 | [diff] [blame] | 1283 | ERROR1: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1284 | kfree(data); |
Jean Delvare | 1f44809 | 2008-04-29 14:03:37 +0200 | [diff] [blame] | 1285 | ERROR0: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1286 | return err; |
| 1287 | } |
| 1288 | |
Ben Dooks | d8d2061 | 2005-10-26 21:05:46 +0200 | [diff] [blame] | 1289 | static int lm85_detach_client(struct i2c_client *client) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1290 | { |
Mark M. Hoffman | 943b083 | 2005-07-15 21:39:18 -0400 | [diff] [blame] | 1291 | struct lm85_data *data = i2c_get_clientdata(client); |
Tony Jones | 1beeffe | 2007-08-20 13:46:20 -0700 | [diff] [blame] | 1292 | hwmon_device_unregister(data->hwmon_dev); |
Mark M. Hoffman | 0501a38 | 2006-09-24 21:14:35 +0200 | [diff] [blame] | 1293 | sysfs_remove_group(&client->dev.kobj, &lm85_group); |
Jean Delvare | 6b9aad2 | 2007-07-05 20:37:21 +0200 | [diff] [blame] | 1294 | sysfs_remove_group(&client->dev.kobj, &lm85_group_in4); |
| 1295 | if (data->type == emc6d100) |
| 1296 | sysfs_remove_group(&client->dev.kobj, &lm85_group_in567); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1297 | i2c_detach_client(client); |
Mark M. Hoffman | 943b083 | 2005-07-15 21:39:18 -0400 | [diff] [blame] | 1298 | kfree(data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1299 | return 0; |
| 1300 | } |
| 1301 | |
| 1302 | |
Ben Dooks | d8d2061 | 2005-10-26 21:05:46 +0200 | [diff] [blame] | 1303 | static int lm85_read_value(struct i2c_client *client, u8 reg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1304 | { |
| 1305 | int res; |
| 1306 | |
| 1307 | /* What size location is it? */ |
Jean Delvare | 1f44809 | 2008-04-29 14:03:37 +0200 | [diff] [blame] | 1308 | switch (reg) { |
| 1309 | case LM85_REG_FAN(0): /* Read WORD data */ |
| 1310 | case LM85_REG_FAN(1): |
| 1311 | case LM85_REG_FAN(2): |
| 1312 | case LM85_REG_FAN(3): |
| 1313 | case LM85_REG_FAN_MIN(0): |
| 1314 | case LM85_REG_FAN_MIN(1): |
| 1315 | case LM85_REG_FAN_MIN(2): |
| 1316 | case LM85_REG_FAN_MIN(3): |
| 1317 | case LM85_REG_ALARM1: /* Read both bytes at once */ |
| 1318 | res = i2c_smbus_read_byte_data(client, reg) & 0xff; |
| 1319 | res |= i2c_smbus_read_byte_data(client, reg + 1) << 8; |
| 1320 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1321 | default: /* Read BYTE data */ |
| 1322 | res = i2c_smbus_read_byte_data(client, reg); |
Jean Delvare | 1f44809 | 2008-04-29 14:03:37 +0200 | [diff] [blame] | 1323 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1324 | } |
| 1325 | |
Jean Delvare | 1f44809 | 2008-04-29 14:03:37 +0200 | [diff] [blame] | 1326 | return res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1327 | } |
| 1328 | |
Jean Delvare | e89e22b | 2008-06-25 08:47:35 -0400 | [diff] [blame] | 1329 | static void lm85_write_value(struct i2c_client *client, u8 reg, int value) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1330 | { |
Jean Delvare | 1f44809 | 2008-04-29 14:03:37 +0200 | [diff] [blame] | 1331 | switch (reg) { |
| 1332 | case LM85_REG_FAN(0): /* Write WORD data */ |
| 1333 | case LM85_REG_FAN(1): |
| 1334 | case LM85_REG_FAN(2): |
| 1335 | case LM85_REG_FAN(3): |
| 1336 | case LM85_REG_FAN_MIN(0): |
| 1337 | case LM85_REG_FAN_MIN(1): |
| 1338 | case LM85_REG_FAN_MIN(2): |
| 1339 | case LM85_REG_FAN_MIN(3): |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1340 | /* NOTE: ALARM is read only, so not included here */ |
Jean Delvare | e89e22b | 2008-06-25 08:47:35 -0400 | [diff] [blame] | 1341 | i2c_smbus_write_byte_data(client, reg, value & 0xff); |
| 1342 | i2c_smbus_write_byte_data(client, reg + 1, value >> 8); |
Jean Delvare | 1f44809 | 2008-04-29 14:03:37 +0200 | [diff] [blame] | 1343 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1344 | default: /* Write BYTE data */ |
Jean Delvare | e89e22b | 2008-06-25 08:47:35 -0400 | [diff] [blame] | 1345 | i2c_smbus_write_byte_data(client, reg, value); |
Jean Delvare | 1f44809 | 2008-04-29 14:03:37 +0200 | [diff] [blame] | 1346 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1347 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1348 | } |
| 1349 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1350 | static struct lm85_data *lm85_update_device(struct device *dev) |
| 1351 | { |
| 1352 | struct i2c_client *client = to_i2c_client(dev); |
| 1353 | struct lm85_data *data = i2c_get_clientdata(client); |
| 1354 | int i; |
| 1355 | |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 1356 | mutex_lock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1357 | |
Jean Delvare | 1f44809 | 2008-04-29 14:03:37 +0200 | [diff] [blame] | 1358 | if (!data->valid || |
| 1359 | time_after(jiffies, data->last_reading + LM85_DATA_INTERVAL)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1360 | /* Things that change quickly */ |
| 1361 | dev_dbg(&client->dev, "Reading sensor values\n"); |
Jean Delvare | 1f44809 | 2008-04-29 14:03:37 +0200 | [diff] [blame] | 1362 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1363 | /* Have to read extended bits first to "freeze" the |
| 1364 | * more significant bits that are read later. |
Jean Delvare | 5a4d3ef | 2007-07-05 20:38:32 +0200 | [diff] [blame] | 1365 | * There are 2 additional resolution bits per channel and we |
| 1366 | * have room for 4, so we shift them to the left. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1367 | */ |
Jean Delvare | 1f44809 | 2008-04-29 14:03:37 +0200 | [diff] [blame] | 1368 | if (data->type == adm1027 || data->type == adt7463) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1369 | int ext1 = lm85_read_value(client, |
| 1370 | ADM1027_REG_EXTEND_ADC1); |
| 1371 | int ext2 = lm85_read_value(client, |
| 1372 | ADM1027_REG_EXTEND_ADC2); |
| 1373 | int val = (ext1 << 8) + ext2; |
| 1374 | |
Jean Delvare | 1f44809 | 2008-04-29 14:03:37 +0200 | [diff] [blame] | 1375 | for (i = 0; i <= 4; i++) |
| 1376 | data->in_ext[i] = |
| 1377 | ((val >> (i * 2)) & 0x03) << 2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1378 | |
Jean Delvare | 1f44809 | 2008-04-29 14:03:37 +0200 | [diff] [blame] | 1379 | for (i = 0; i <= 2; i++) |
| 1380 | data->temp_ext[i] = |
| 1381 | (val >> ((i + 4) * 2)) & 0x0c; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1382 | } |
| 1383 | |
Jean Delvare | 9c516ef | 2005-11-26 20:07:54 +0100 | [diff] [blame] | 1384 | data->vid = lm85_read_value(client, LM85_REG_VID); |
| 1385 | |
| 1386 | for (i = 0; i <= 3; ++i) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1387 | data->in[i] = |
| 1388 | lm85_read_value(client, LM85_REG_IN(i)); |
Jean Delvare | e89e22b | 2008-06-25 08:47:35 -0400 | [diff] [blame] | 1389 | data->fan[i] = |
| 1390 | lm85_read_value(client, LM85_REG_FAN(i)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1391 | } |
| 1392 | |
Jean Delvare | 9c516ef | 2005-11-26 20:07:54 +0100 | [diff] [blame] | 1393 | if (!(data->type == adt7463 && (data->vid & 0x80))) { |
| 1394 | data->in[4] = lm85_read_value(client, |
| 1395 | LM85_REG_IN(4)); |
| 1396 | } |
| 1397 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1398 | for (i = 0; i <= 2; ++i) { |
| 1399 | data->temp[i] = |
| 1400 | lm85_read_value(client, LM85_REG_TEMP(i)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1401 | data->pwm[i] = |
| 1402 | lm85_read_value(client, LM85_REG_PWM(i)); |
| 1403 | } |
| 1404 | |
| 1405 | data->alarms = lm85_read_value(client, LM85_REG_ALARM1); |
| 1406 | |
Jean Delvare | dd1ac53 | 2008-05-01 08:47:33 +0200 | [diff] [blame] | 1407 | if (data->type == emc6d100) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1408 | /* Three more voltage sensors */ |
| 1409 | for (i = 5; i <= 7; ++i) { |
Jean Delvare | 1f44809 | 2008-04-29 14:03:37 +0200 | [diff] [blame] | 1410 | data->in[i] = lm85_read_value(client, |
| 1411 | EMC6D100_REG_IN(i)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1412 | } |
| 1413 | /* More alarm bits */ |
Jean Delvare | 1f44809 | 2008-04-29 14:03:37 +0200 | [diff] [blame] | 1414 | data->alarms |= lm85_read_value(client, |
| 1415 | EMC6D100_REG_ALARM3) << 16; |
| 1416 | } else if (data->type == emc6d102) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1417 | /* Have to read LSB bits after the MSB ones because |
| 1418 | the reading of the MSB bits has frozen the |
| 1419 | LSBs (backward from the ADM1027). |
| 1420 | */ |
| 1421 | int ext1 = lm85_read_value(client, |
| 1422 | EMC6D102_REG_EXTEND_ADC1); |
| 1423 | int ext2 = lm85_read_value(client, |
| 1424 | EMC6D102_REG_EXTEND_ADC2); |
| 1425 | int ext3 = lm85_read_value(client, |
| 1426 | EMC6D102_REG_EXTEND_ADC3); |
| 1427 | int ext4 = lm85_read_value(client, |
| 1428 | EMC6D102_REG_EXTEND_ADC4); |
| 1429 | data->in_ext[0] = ext3 & 0x0f; |
| 1430 | data->in_ext[1] = ext4 & 0x0f; |
Jean Delvare | e89e22b | 2008-06-25 08:47:35 -0400 | [diff] [blame] | 1431 | data->in_ext[2] = ext4 >> 4; |
| 1432 | data->in_ext[3] = ext3 >> 4; |
| 1433 | data->in_ext[4] = ext2 >> 4; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1434 | |
| 1435 | data->temp_ext[0] = ext1 & 0x0f; |
| 1436 | data->temp_ext[1] = ext2 & 0x0f; |
Jean Delvare | e89e22b | 2008-06-25 08:47:35 -0400 | [diff] [blame] | 1437 | data->temp_ext[2] = ext1 >> 4; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1438 | } |
| 1439 | |
Jean Delvare | 1f44809 | 2008-04-29 14:03:37 +0200 | [diff] [blame] | 1440 | data->last_reading = jiffies; |
| 1441 | } /* last_reading */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1442 | |
Jean Delvare | 1f44809 | 2008-04-29 14:03:37 +0200 | [diff] [blame] | 1443 | if (!data->valid || |
| 1444 | time_after(jiffies, data->last_config + LM85_CONFIG_INTERVAL)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1445 | /* Things that don't change often */ |
| 1446 | dev_dbg(&client->dev, "Reading config values\n"); |
| 1447 | |
Jean Delvare | 9c516ef | 2005-11-26 20:07:54 +0100 | [diff] [blame] | 1448 | for (i = 0; i <= 3; ++i) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1449 | data->in_min[i] = |
| 1450 | lm85_read_value(client, LM85_REG_IN_MIN(i)); |
| 1451 | data->in_max[i] = |
| 1452 | lm85_read_value(client, LM85_REG_IN_MAX(i)); |
Jean Delvare | e89e22b | 2008-06-25 08:47:35 -0400 | [diff] [blame] | 1453 | data->fan_min[i] = |
| 1454 | lm85_read_value(client, LM85_REG_FAN_MIN(i)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1455 | } |
| 1456 | |
Jean Delvare | 9c516ef | 2005-11-26 20:07:54 +0100 | [diff] [blame] | 1457 | if (!(data->type == adt7463 && (data->vid & 0x80))) { |
| 1458 | data->in_min[4] = lm85_read_value(client, |
| 1459 | LM85_REG_IN_MIN(4)); |
| 1460 | data->in_max[4] = lm85_read_value(client, |
| 1461 | LM85_REG_IN_MAX(4)); |
| 1462 | } |
| 1463 | |
Jean Delvare | 1f44809 | 2008-04-29 14:03:37 +0200 | [diff] [blame] | 1464 | if (data->type == emc6d100) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1465 | for (i = 5; i <= 7; ++i) { |
Jean Delvare | 1f44809 | 2008-04-29 14:03:37 +0200 | [diff] [blame] | 1466 | data->in_min[i] = lm85_read_value(client, |
| 1467 | EMC6D100_REG_IN_MIN(i)); |
| 1468 | data->in_max[i] = lm85_read_value(client, |
| 1469 | EMC6D100_REG_IN_MAX(i)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1470 | } |
| 1471 | } |
| 1472 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1473 | for (i = 0; i <= 2; ++i) { |
Jean Delvare | e89e22b | 2008-06-25 08:47:35 -0400 | [diff] [blame] | 1474 | int val; |
| 1475 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1476 | data->temp_min[i] = |
| 1477 | lm85_read_value(client, LM85_REG_TEMP_MIN(i)); |
| 1478 | data->temp_max[i] = |
| 1479 | lm85_read_value(client, LM85_REG_TEMP_MAX(i)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1480 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1481 | data->autofan[i].config = |
| 1482 | lm85_read_value(client, LM85_REG_AFAN_CONFIG(i)); |
| 1483 | val = lm85_read_value(client, LM85_REG_AFAN_RANGE(i)); |
Jean Delvare | 1f44809 | 2008-04-29 14:03:37 +0200 | [diff] [blame] | 1484 | data->autofan[i].freq = val & 0x07; |
Jean Delvare | e89e22b | 2008-06-25 08:47:35 -0400 | [diff] [blame] | 1485 | data->zone[i].range = val >> 4; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1486 | data->autofan[i].min_pwm = |
| 1487 | lm85_read_value(client, LM85_REG_AFAN_MINPWM(i)); |
| 1488 | data->zone[i].limit = |
| 1489 | lm85_read_value(client, LM85_REG_AFAN_LIMIT(i)); |
| 1490 | data->zone[i].critical = |
| 1491 | lm85_read_value(client, LM85_REG_AFAN_CRITICAL(i)); |
| 1492 | } |
| 1493 | |
| 1494 | i = lm85_read_value(client, LM85_REG_AFAN_SPIKE1); |
Jean Delvare | 1f44809 | 2008-04-29 14:03:37 +0200 | [diff] [blame] | 1495 | data->autofan[0].min_off = (i & 0x20) != 0; |
| 1496 | data->autofan[1].min_off = (i & 0x40) != 0; |
| 1497 | data->autofan[2].min_off = (i & 0x80) != 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1498 | |
| 1499 | i = lm85_read_value(client, LM85_REG_AFAN_HYST1); |
Jean Delvare | e89e22b | 2008-06-25 08:47:35 -0400 | [diff] [blame] | 1500 | data->zone[0].hyst = i >> 4; |
Jean Delvare | 1f44809 | 2008-04-29 14:03:37 +0200 | [diff] [blame] | 1501 | data->zone[1].hyst = i & 0x0f; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1502 | |
| 1503 | i = lm85_read_value(client, LM85_REG_AFAN_HYST2); |
Jean Delvare | e89e22b | 2008-06-25 08:47:35 -0400 | [diff] [blame] | 1504 | data->zone[2].hyst = i >> 4; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1505 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1506 | data->last_config = jiffies; |
Jean Delvare | 1f44809 | 2008-04-29 14:03:37 +0200 | [diff] [blame] | 1507 | } /* last_config */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1508 | |
| 1509 | data->valid = 1; |
| 1510 | |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 1511 | mutex_unlock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1512 | |
| 1513 | return data; |
| 1514 | } |
| 1515 | |
| 1516 | |
| 1517 | static int __init sm_lm85_init(void) |
| 1518 | { |
| 1519 | return i2c_add_driver(&lm85_driver); |
| 1520 | } |
| 1521 | |
Jean Delvare | 1f44809 | 2008-04-29 14:03:37 +0200 | [diff] [blame] | 1522 | static void __exit sm_lm85_exit(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1523 | { |
| 1524 | i2c_del_driver(&lm85_driver); |
| 1525 | } |
| 1526 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1527 | MODULE_LICENSE("GPL"); |
Jean Delvare | 1f44809 | 2008-04-29 14:03:37 +0200 | [diff] [blame] | 1528 | MODULE_AUTHOR("Philip Pokorny <ppokorny@penguincomputing.com>, " |
| 1529 | "Margit Schubert-While <margitsw@t-online.de>, " |
Jean Delvare | e89e22b | 2008-06-25 08:47:35 -0400 | [diff] [blame] | 1530 | "Justin Thiessen <jthiessen@penguincomputing.com>"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1531 | MODULE_DESCRIPTION("LM85-B, LM85-C driver"); |
| 1532 | |
| 1533 | module_init(sm_lm85_init); |
| 1534 | module_exit(sm_lm85_exit); |