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