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