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