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