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