| 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 | |
|---|
| 8 | This program is free software; you can redistribute it and/or modify |
|---|
| 9 | it under the terms of the GNU General Public License as published by |
|---|
| 10 | the Free Software Foundation; either version 2 of the License, or |
|---|
| 11 | (at your option) any later version. |
|---|
| 12 | |
|---|
| 13 | This program is distributed in the hope that it will be useful, |
|---|
| 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 16 | GNU General Public License for more details. |
|---|
| 17 | |
|---|
| 18 | You should have received a copy of the GNU General Public License |
|---|
| 19 | along with this program; if not, write to the Free Software |
|---|
| 20 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
|---|
| 21 | |
|---|
| 22 | CHANGELOG |
|---|
| 23 | |
|---|
| 24 | 2002-11-13 First patch for LM85 functionality |
|---|
| 25 | 2002-11-18 LM85 functionality mostly done |
|---|
| 26 | 2002-12-02 Adding ADM1027 functionality |
|---|
| 27 | 2002-12-06 Adding ADT7463 functionality |
|---|
| 28 | 2003-01-09 Code cleanup. |
|---|
| 29 | Save reserved bits in case they are implemented |
|---|
| 30 | in a future chip. (Solve problem with lockups |
|---|
| 31 | on ADM1027 due to chip initialization) |
|---|
| 32 | Added chip initialization bypass option |
|---|
| 33 | 2003-02-12 Add THERM asserted counts for ADT7463 |
|---|
| 34 | Added #ifdef so we can compile against 2.6.5 |
|---|
| 35 | without updating i2c-ids.h |
|---|
| 36 | 2003-02-17 Prepare for switch to 2.7.0 development |
|---|
| 37 | Implement tmin_control for ADT7463 |
|---|
| 38 | Expose THERM asserted counts to /proc |
|---|
| 39 | Code cleanup |
|---|
| 40 | 2003-02-19 Working with Margit and LM_SENSORS developers |
|---|
| 41 | 2003-02-23 Removed chip initialization entirely |
|---|
| 42 | Scale voltages in driver at Margit's request |
|---|
| 43 | Change PWM from 0-100% to 0-255 per LM sensors standard |
|---|
| 44 | 2003-02-27 Documentation and code cleanups |
|---|
| 45 | Added this CHANGELOG |
|---|
| 46 | Print additional precision for temperatures and voltages |
|---|
| 47 | Many thanks to Margit Schubert-While and Brandt xxxxxx |
|---|
| 48 | for help testing this version |
|---|
| 49 | 2003-02-28 More diagnostic messages regarding BIOS setup |
|---|
| 50 | 2003-03-01 Added Interrupt mask register support. |
|---|
| 51 | 2003-03-08 Fixed problem with pseudo 16-bit registers |
|---|
| 52 | Cleaned up some compiler warnings. |
|---|
| 53 | Fixed problem with Operating Point and THERM counting |
|---|
| 54 | 2003-03-21 Initial support for EMC6D100 and EMC6D101 chips |
|---|
| 55 | 2003-06-30 Add support for EMC6D100 extra voltage inputs. |
|---|
| 56 | */ |
|---|
| 57 | |
|---|
| 58 | #include <linux/module.h> |
|---|
| 59 | #include <linux/slab.h> |
|---|
| 60 | #include <linux/i2c.h> |
|---|
| 61 | #include <linux/i2c-proc.h> |
|---|
| 62 | #include <linux/init.h> |
|---|
| 63 | #include "version.h" |
|---|
| 64 | #include "sensors_vid.h" |
|---|
| 65 | |
|---|
| 66 | #ifndef I2C_DRIVERID_LM85 |
|---|
| 67 | #define I2C_DRIVERID_LM85 1039 |
|---|
| 68 | #endif |
|---|
| 69 | |
|---|
| 70 | /* Addresses to scan */ |
|---|
| 71 | static unsigned short normal_i2c[] = { 0x2c, 0x2d, 0x2e, SENSORS_I2C_END }; |
|---|
| 72 | static unsigned short normal_i2c_range[] = { SENSORS_I2C_END }; |
|---|
| 73 | static unsigned int normal_isa[] = { SENSORS_ISA_END }; |
|---|
| 74 | static unsigned int normal_isa_range[] = { SENSORS_ISA_END }; |
|---|
| 75 | |
|---|
| 76 | /* Insmod parameters */ |
|---|
| 77 | SENSORS_INSMOD_6(lm85b, lm85c, adm1027, adt7463, emc6d100, emc6d102); |
|---|
| 78 | |
|---|
| 79 | /* Many LM85 constants specified below */ |
|---|
| 80 | |
|---|
| 81 | /* The LM85 registers */ |
|---|
| 82 | #define LM85_REG_IN(nr) (0x20 + (nr)) |
|---|
| 83 | #define LM85_REG_IN_MIN(nr) (0x44 + (nr) * 2) |
|---|
| 84 | #define LM85_REG_IN_MAX(nr) (0x45 + (nr) * 2) |
|---|
| 85 | |
|---|
| 86 | #define LM85_REG_TEMP(nr) (0x25 + (nr)) |
|---|
| 87 | #define LM85_REG_TEMP_MIN(nr) (0x4e + (nr) * 2) |
|---|
| 88 | #define LM85_REG_TEMP_MAX(nr) (0x4f + (nr) * 2) |
|---|
| 89 | |
|---|
| 90 | /* Fan speeds are LSB, MSB (2 bytes) */ |
|---|
| 91 | #define LM85_REG_FAN(nr) (0x28 + (nr) *2) |
|---|
| 92 | #define LM85_REG_FAN_MIN(nr) (0x54 + (nr) *2) |
|---|
| 93 | |
|---|
| 94 | #define LM85_REG_PWM(nr) (0x30 + (nr)) |
|---|
| 95 | |
|---|
| 96 | #define ADT7463_REG_OPPOINT(nr) (0x33 + (nr)) |
|---|
| 97 | |
|---|
| 98 | #define ADT7463_REG_TMIN_CTL1 0x36 |
|---|
| 99 | #define ADT7463_REG_TMIN_CTL2 0x37 |
|---|
| 100 | #define ADT7463_REG_TMIN_CTL 0x0136 |
|---|
| 101 | |
|---|
| 102 | #define LM85_REG_DEVICE 0x3d |
|---|
| 103 | #define LM85_REG_COMPANY 0x3e |
|---|
| 104 | #define LM85_REG_VERSTEP 0x3f |
|---|
| 105 | /* These are the recognized values for the above regs */ |
|---|
| 106 | #define LM85_DEVICE_ADX 0x27 |
|---|
| 107 | #define LM85_COMPANY_NATIONAL 0x01 |
|---|
| 108 | #define LM85_COMPANY_ANALOG_DEV 0x41 |
|---|
| 109 | #define LM85_COMPANY_SMSC 0x5c |
|---|
| 110 | #define LM85_VERSTEP_VMASK 0xf0 |
|---|
| 111 | #define LM85_VERSTEP_SMASK 0x0f |
|---|
| 112 | #define LM85_VERSTEP_GENERIC 0x60 |
|---|
| 113 | #define LM85_VERSTEP_LM85C 0x60 |
|---|
| 114 | #define LM85_VERSTEP_LM85B 0x62 |
|---|
| 115 | #define LM85_VERSTEP_ADM1027 0x60 |
|---|
| 116 | #define LM85_VERSTEP_ADT7463 0x62 |
|---|
| 117 | #define LM85_VERSTEP_ADT7463C 0x6A |
|---|
| 118 | #define LM85_VERSTEP_EMC6D100_A0 0x60 |
|---|
| 119 | #define LM85_VERSTEP_EMC6D100_A1 0x61 |
|---|
| 120 | #define LM85_VERSTEP_EMC6D102 0x65 |
|---|
| 121 | |
|---|
| 122 | #define LM85_REG_CONFIG 0x40 |
|---|
| 123 | |
|---|
| 124 | #define LM85_REG_ALARM1 0x41 |
|---|
| 125 | #define LM85_REG_ALARM2 0x42 |
|---|
| 126 | #define LM85_REG_ALARM 0x0141 |
|---|
| 127 | |
|---|
| 128 | #define LM85_REG_VID 0x43 |
|---|
| 129 | |
|---|
| 130 | /* Automated FAN control */ |
|---|
| 131 | #define LM85_REG_AFAN_CONFIG(nr) (0x5c + (nr)) |
|---|
| 132 | #define LM85_REG_AFAN_RANGE(nr) (0x5f + (nr)) |
|---|
| 133 | #define LM85_REG_AFAN_SPIKE1 0x62 |
|---|
| 134 | #define LM85_REG_AFAN_SPIKE2 0x63 |
|---|
| 135 | #define LM85_REG_AFAN_MINPWM(nr) (0x64 + (nr)) |
|---|
| 136 | #define LM85_REG_AFAN_LIMIT(nr) (0x67 + (nr)) |
|---|
| 137 | #define LM85_REG_AFAN_CRITICAL(nr) (0x6a + (nr)) |
|---|
| 138 | #define LM85_REG_AFAN_HYST1 0x6d |
|---|
| 139 | #define LM85_REG_AFAN_HYST2 0x6e |
|---|
| 140 | |
|---|
| 141 | #define LM85_REG_TACH_MODE 0x74 |
|---|
| 142 | #define LM85_REG_SPINUP_CTL 0x75 |
|---|
| 143 | |
|---|
| 144 | #define ADM1027_REG_TEMP_OFFSET(nr) (0x70 + (nr)) |
|---|
| 145 | #define ADM1027_REG_CONFIG2 0x73 |
|---|
| 146 | #define ADM1027_REG_INTMASK1 0x74 |
|---|
| 147 | #define ADM1027_REG_INTMASK2 0x75 |
|---|
| 148 | #define ADM1027_REG_INTMASK 0x0174 |
|---|
| 149 | #define ADM1027_REG_EXTEND_ADC1 0x76 |
|---|
| 150 | #define ADM1027_REG_EXTEND_ADC2 0x77 |
|---|
| 151 | #define ADM1027_REG_EXTEND_ADC 0x0176 |
|---|
| 152 | #define ADM1027_REG_CONFIG3 0x78 |
|---|
| 153 | #define ADM1027_REG_FAN_PPR 0x7b |
|---|
| 154 | |
|---|
| 155 | #define ADT7463_REG_THERM 0x79 |
|---|
| 156 | #define ADT7463_REG_THERM_LIMIT 0x7A |
|---|
| 157 | #define ADT7463_REG_CONFIG4 0x7D |
|---|
| 158 | |
|---|
| 159 | #define EMC6D100_REG_SFR 0x7c |
|---|
| 160 | #define EMC6D100_REG_ALARM3 0x7d |
|---|
| 161 | #define EMC6D100_REG_CONF 0x7f |
|---|
| 162 | #define EMC6D100_REG_INT_EN 0x80 |
|---|
| 163 | /* IN5, IN6 and IN7 */ |
|---|
| 164 | #define EMC6D100_REG_IN(nr) (0x70 + ((nr)-5)) |
|---|
| 165 | #define EMC6D100_REG_IN_MIN(nr) (0x73 + ((nr)-5) * 2) |
|---|
| 166 | #define EMC6D100_REG_IN_MAX(nr) (0x74 + ((nr)-5) * 2) |
|---|
| 167 | |
|---|
| 168 | #define EMC6D102_REG_EXTEND_ADC1 0x85 |
|---|
| 169 | #define EMC6D102_REG_EXTEND_ADC2 0x86 |
|---|
| 170 | #define EMC6D102_REG_EXTEND_ADC3 0x87 |
|---|
| 171 | #define EMC6D102_REG_EXTEND_ADC4 0x88 |
|---|
| 172 | |
|---|
| 173 | /* Conversions. Rounding and limit checking is only done on the TO_REG |
|---|
| 174 | variants. Note that you should be a bit careful with which arguments |
|---|
| 175 | these macros are called: arguments may be evaluated more than once. |
|---|
| 176 | */ |
|---|
| 177 | |
|---|
| 178 | /* IN are scaled 1.000 == 0xc0, mag = 3 */ |
|---|
| 179 | #define IN_TO_REG(val) (SENSORS_LIMIT((((val)*0xc0+500)/1000),0,255)) |
|---|
| 180 | #define INEXT_FROM_REG(val,ext) (((val)*1000 + (ext)*250 + 96)/0xc0) |
|---|
| 181 | #define IN_FROM_REG(val) (INEXT_FROM_REG(val,0)) |
|---|
| 182 | |
|---|
| 183 | /* IN are scaled acording to built-in resistors */ |
|---|
| 184 | static int lm85_scaling[] = { /* .001 Volts */ |
|---|
| 185 | 2500, 2250, 3300, 5000, 12000, |
|---|
| 186 | 3300, 1500, 1800, /* EMC6D100 */ |
|---|
| 187 | }; |
|---|
| 188 | #define SCALE(val,from,to) (((val)*(to) + ((from)/2))/(from)) |
|---|
| 189 | #define INS_TO_REG(n,val) (SENSORS_LIMIT(SCALE(val,lm85_scaling[n],192),0,255)) |
|---|
| 190 | #define INSEXT_FROM_REG(n,val,ext) (SCALE((val)*4 + (ext),192*4,lm85_scaling[n])) |
|---|
| 191 | #define INS_FROM_REG(n,val) (INSEXT_FROM_REG(n,val,0)) |
|---|
| 192 | |
|---|
| 193 | /* FAN speed is measured using 90kHz clock */ |
|---|
| 194 | #define FAN_TO_REG(val) ((val)<=0?0xffff:SENSORS_LIMIT(5400000/(val),1,65534)) |
|---|
| 195 | #define FAN_FROM_REG(val) ((val)==0?-1:(val)==0xffff?0:5400000/(val)) |
|---|
| 196 | |
|---|
| 197 | /* Temperature is reported in .01 degC increments */ |
|---|
| 198 | #define TEMP_TO_REG(val) (SENSORS_LIMIT(((val)+50)/100,-127,127)) |
|---|
| 199 | #define TEMPEXT_FROM_REG(val,ext) ((val)*100 + (ext)*25) |
|---|
| 200 | #define TEMP_FROM_REG(val) (TEMPEXT_FROM_REG(val,0)) |
|---|
| 201 | #define EXTTEMP_TO_REG(val) (SENSORS_LIMIT((val)/25,-127,127)) |
|---|
| 202 | #define OPPOINT_TO_REG(val) (SENSORS_LIMIT(val,-127,127)) |
|---|
| 203 | #define OPPOINT_FROM_REG(val) (val) |
|---|
| 204 | |
|---|
| 205 | #define PWM_TO_REG(val) (SENSORS_LIMIT(val,0,255)) |
|---|
| 206 | #define PWM_FROM_REG(val) (val) |
|---|
| 207 | |
|---|
| 208 | #define EXT_FROM_REG(val,sensor) (((val)>>(sensor * 2))&0x03) |
|---|
| 209 | |
|---|
| 210 | /* ZONEs have the following parameters: |
|---|
| 211 | * Limit (low) temp, 1. degC |
|---|
| 212 | * Hysteresis (below limit), 1. degC (0-15) |
|---|
| 213 | * Range of speed control, .1 degC (2-80) |
|---|
| 214 | * Critical (high) temp, 1. degC |
|---|
| 215 | * |
|---|
| 216 | * FAN PWMs have the following parameters: |
|---|
| 217 | * Reference Zone, 1, 2, 3, etc. |
|---|
| 218 | * Spinup time, .05 sec |
|---|
| 219 | * PWM value at limit/low temp, 1 count |
|---|
| 220 | * PWM Frequency, 1. Hz |
|---|
| 221 | * PWM is Min or OFF below limit, flag |
|---|
| 222 | * Invert PWM output, flag |
|---|
| 223 | * |
|---|
| 224 | * Some chips filter the temp, others the fan. |
|---|
| 225 | * Filter constant (or disabled) .1 seconds |
|---|
| 226 | */ |
|---|
| 227 | |
|---|
| 228 | /* These are the zone temperature range encodings */ |
|---|
| 229 | static int lm85_range_map[] = { /* .1 degC */ |
|---|
| 230 | 20, 25, 33, 40, 50, 66, |
|---|
| 231 | 80, 100, 133, 160, 200, 266, |
|---|
| 232 | 320, 400, 533, 800 |
|---|
| 233 | }; |
|---|
| 234 | static int RANGE_TO_REG( int range ) |
|---|
| 235 | { |
|---|
| 236 | int i; |
|---|
| 237 | |
|---|
| 238 | if( range >= lm85_range_map[15] ) { return 15 ; } |
|---|
| 239 | for( i = 0 ; i < 15 ; ++i ) |
|---|
| 240 | if( range <= lm85_range_map[i] ) |
|---|
| 241 | break ; |
|---|
| 242 | return( i & 0x0f ); |
|---|
| 243 | } |
|---|
| 244 | #define RANGE_FROM_REG(val) (lm85_range_map[(val)&0x0f]) |
|---|
| 245 | |
|---|
| 246 | /* These are the Acoustic Enhancement, or Temperature smoothing encodings |
|---|
| 247 | * NOTE: The enable/disable bit is INCLUDED in these encodings as the |
|---|
| 248 | * MSB (bit 3, value 8). If the enable bit is 0, the encoded value |
|---|
| 249 | * is ignored, or set to 0. |
|---|
| 250 | */ |
|---|
| 251 | static int lm85_smooth_map[] = { /* .1 sec */ |
|---|
| 252 | 350, 176, 118, 70, 44, 30, 16, 8 |
|---|
| 253 | /* 35.4 * 1/1, 1/2, 1/3, 1/5, 1/8, 1/12, 1/24, 1/48 */ |
|---|
| 254 | }; |
|---|
| 255 | static int SMOOTH_TO_REG( int smooth ) |
|---|
| 256 | { |
|---|
| 257 | int i; |
|---|
| 258 | |
|---|
| 259 | if( smooth <= 0 ) { return 0 ; } /* Disabled */ |
|---|
| 260 | for( i = 0 ; i < 7 ; ++i ) |
|---|
| 261 | if( smooth >= lm85_smooth_map[i] ) |
|---|
| 262 | break ; |
|---|
| 263 | return( (i & 0x07) | 0x08 ); |
|---|
| 264 | } |
|---|
| 265 | #define SMOOTH_FROM_REG(val) ((val)&0x08?lm85_smooth_map[(val)&0x07]:0) |
|---|
| 266 | |
|---|
| 267 | /* These are the fan spinup delay time encodings */ |
|---|
| 268 | static int lm85_spinup_map[] = { /* .1 sec */ |
|---|
| 269 | 0, 1, 2, 4, 7, 10, 20, 40 |
|---|
| 270 | }; |
|---|
| 271 | static int SPINUP_TO_REG( int spinup ) |
|---|
| 272 | { |
|---|
| 273 | int i; |
|---|
| 274 | |
|---|
| 275 | if( spinup >= lm85_spinup_map[7] ) { return 7 ; } |
|---|
| 276 | for( i = 0 ; i < 7 ; ++i ) |
|---|
| 277 | if( spinup <= lm85_spinup_map[i] ) |
|---|
| 278 | break ; |
|---|
| 279 | return( i & 0x07 ); |
|---|
| 280 | } |
|---|
| 281 | #define SPINUP_FROM_REG(val) (lm85_spinup_map[(val)&0x07]) |
|---|
| 282 | |
|---|
| 283 | /* These are the PWM frequency encodings */ |
|---|
| 284 | static int lm85_freq_map[] = { /* .1 Hz */ |
|---|
| 285 | 100, 150, 230, 300, 380, 470, 620, 980 |
|---|
| 286 | }; |
|---|
| 287 | static int FREQ_TO_REG( int freq ) |
|---|
| 288 | { |
|---|
| 289 | int i; |
|---|
| 290 | |
|---|
| 291 | if( freq >= lm85_freq_map[7] ) { return 7 ; } |
|---|
| 292 | for( i = 0 ; i < 7 ; ++i ) |
|---|
| 293 | if( freq <= lm85_freq_map[i] ) |
|---|
| 294 | break ; |
|---|
| 295 | return( i & 0x07 ); |
|---|
| 296 | } |
|---|
| 297 | #define FREQ_FROM_REG(val) (lm85_freq_map[(val)&0x07]) |
|---|
| 298 | |
|---|
| 299 | /* Since we can't use strings, I'm abusing these numbers |
|---|
| 300 | * to stand in for the following meanings: |
|---|
| 301 | * 1 -- PWM responds to Zone 1 |
|---|
| 302 | * 2 -- PWM responds to Zone 2 |
|---|
| 303 | * 3 -- PWM responds to Zone 3 |
|---|
| 304 | * 23 -- PWM responds to the higher temp of Zone 2 or 3 |
|---|
| 305 | * 123 -- PWM responds to highest of Zone 1, 2, or 3 |
|---|
| 306 | * 0 -- PWM is always at 0% (ie, off) |
|---|
| 307 | * -1 -- PWM is always at 100% |
|---|
| 308 | * -2 -- PWM responds to manual control |
|---|
| 309 | */ |
|---|
| 310 | static int lm85_zone_map[] = { 1, 2, 3, -1, 0, 23, 123, -2 }; |
|---|
| 311 | static int ZONE_TO_REG( int zone ) |
|---|
| 312 | { |
|---|
| 313 | int i; |
|---|
| 314 | |
|---|
| 315 | for( i = 0 ; i <= 7 ; ++i ) |
|---|
| 316 | if( zone == lm85_zone_map[i] ) |
|---|
| 317 | break ; |
|---|
| 318 | if( i > 7 ) /* Not found. */ |
|---|
| 319 | i = 3; /* Always 100% */ |
|---|
| 320 | return( (i & 0x07)<<5 ); |
|---|
| 321 | } |
|---|
| 322 | #define ZONE_FROM_REG(val) (lm85_zone_map[((val)>>5)&0x07]) |
|---|
| 323 | |
|---|
| 324 | #define HYST_TO_REG(val) (SENSORS_LIMIT((-(val)+5)/10,0,15)) |
|---|
| 325 | #define HYST_FROM_REG(val) (-(val)*10) |
|---|
| 326 | |
|---|
| 327 | #define OFFSET_TO_REG(val) (SENSORS_LIMIT((val)/25,-127,127)) |
|---|
| 328 | #define OFFSET_FROM_REG(val) ((val)*25) |
|---|
| 329 | |
|---|
| 330 | #define PPR_MASK(fan) (0x03<<(fan *2)) |
|---|
| 331 | #define PPR_TO_REG(val,fan) (SENSORS_LIMIT((val)-1,0,3)<<(fan *2)) |
|---|
| 332 | #define PPR_FROM_REG(val,fan) ((((val)>>(fan * 2))&0x03)+1) |
|---|
| 333 | |
|---|
| 334 | /* When converting to REG, we need to fixup the carry-over bit */ |
|---|
| 335 | #define INTMASK_FROM_REG(val) (val) |
|---|
| 336 | #define INTMASK_TO_REG(val) (SENSORS_LIMIT((val)|((val)&0xff00?0x80:0),0,65535)) |
|---|
| 337 | |
|---|
| 338 | /* Typically used with Pentium 4 systems v9.1 VRM spec */ |
|---|
| 339 | #define LM85_INIT_VRM 91 |
|---|
| 340 | |
|---|
| 341 | /* Chip sampling rates |
|---|
| 342 | * |
|---|
| 343 | * Some sensors are not updated more frequently than once per second |
|---|
| 344 | * so it doesn't make sense to read them more often than that. |
|---|
| 345 | * We cache the results and return the saved data if the driver |
|---|
| 346 | * is called again before a second has elapsed. |
|---|
| 347 | * |
|---|
| 348 | * Also, there is significant configuration data for this chip |
|---|
| 349 | * given the automatic PWM fan control that is possible. There |
|---|
| 350 | * are about 47 bytes of config data to only 22 bytes of actual |
|---|
| 351 | * readings. So, we keep the config data up to date in the cache |
|---|
| 352 | * when it is written and only sample it once every 5 *minutes* |
|---|
| 353 | */ |
|---|
| 354 | #define LM85_DATA_INTERVAL (1 * HZ) |
|---|
| 355 | #define LM85_CONFIG_INTERVAL (5 * 60 * HZ) |
|---|
| 356 | |
|---|
| 357 | /* For each registered LM85, we need to keep some data in memory. That |
|---|
| 358 | data is pointed to by client->data. The structure itself is |
|---|
| 359 | dynamically allocated, when a new lm85 client is allocated. */ |
|---|
| 360 | |
|---|
| 361 | /* LM85 can automatically adjust fan speeds based on temperature |
|---|
| 362 | * This structure encapsulates an entire Zone config. There are |
|---|
| 363 | * three zones (one for each temperature input) on the lm85 |
|---|
| 364 | */ |
|---|
| 365 | struct lm85_zone { |
|---|
| 366 | s8 limit; /* Low temp limit */ |
|---|
| 367 | u8 hyst; /* Low limit hysteresis. (0-15) */ |
|---|
| 368 | u8 range; /* Temp range, encoded */ |
|---|
| 369 | s8 critical; /* "All fans ON" temp limit */ |
|---|
| 370 | }; |
|---|
| 371 | |
|---|
| 372 | struct lm85_autofan { |
|---|
| 373 | u8 config; /* Register value */ |
|---|
| 374 | u8 freq; /* PWM frequency, encoded */ |
|---|
| 375 | u8 min_pwm; /* Minimum PWM value, encoded */ |
|---|
| 376 | u8 min_off; /* Min PWM or OFF below "limit", flag */ |
|---|
| 377 | }; |
|---|
| 378 | |
|---|
| 379 | struct lm85_data { |
|---|
| 380 | struct i2c_client client; |
|---|
| 381 | int sysctl_id; |
|---|
| 382 | enum chips type; |
|---|
| 383 | |
|---|
| 384 | struct semaphore update_lock; |
|---|
| 385 | int valid; /* !=0 if following fields are valid */ |
|---|
| 386 | unsigned long last_reading; /* In jiffies */ |
|---|
| 387 | unsigned long last_config; /* In jiffies */ |
|---|
| 388 | |
|---|
| 389 | u8 in[8]; /* Register value */ |
|---|
| 390 | u8 in_max[8]; /* Register value */ |
|---|
| 391 | u8 in_min[8]; /* Register value */ |
|---|
| 392 | s8 temp[3]; /* Register value */ |
|---|
| 393 | s8 temp_min[3]; /* Register value */ |
|---|
| 394 | s8 temp_max[3]; /* Register value */ |
|---|
| 395 | s8 temp_offset[3]; /* Register value */ |
|---|
| 396 | u16 fan[4]; /* Register value */ |
|---|
| 397 | u16 fan_min[4]; /* Register value */ |
|---|
| 398 | u8 pwm[3]; /* Register value */ |
|---|
| 399 | u8 spinup_ctl; /* Register encoding, combined */ |
|---|
| 400 | u8 tach_mode; /* Register encoding, combined */ |
|---|
| 401 | u16 extend_adc; /* Register value */ |
|---|
| 402 | u8 fan_ppr; /* Register value */ |
|---|
| 403 | u8 smooth[3]; /* Register encoding */ |
|---|
| 404 | u8 vid; /* Register value */ |
|---|
| 405 | u8 vrm; /* VRM version */ |
|---|
| 406 | u8 syncpwm3; /* Saved PWM3 for TACH 2,3,4 config */ |
|---|
| 407 | s8 oppoint[3]; /* Register value */ |
|---|
| 408 | u16 tmin_ctl; /* Register value */ |
|---|
| 409 | long therm_total; /* Cummulative therm count */ |
|---|
| 410 | long therm_ovfl; /* Count of therm overflows */ |
|---|
| 411 | u8 therm_limit; /* Register value */ |
|---|
| 412 | u32 alarms; /* Register encoding, combined */ |
|---|
| 413 | u32 alarm_mask; /* Register encoding, combined */ |
|---|
| 414 | struct lm85_autofan autofan[3]; |
|---|
| 415 | struct lm85_zone zone[3]; |
|---|
| 416 | }; |
|---|
| 417 | |
|---|
| 418 | static int lm85_attach_adapter(struct i2c_adapter *adapter); |
|---|
| 419 | static int lm85_detect(struct i2c_adapter *adapter, int address, |
|---|
| 420 | unsigned short flags, int kind); |
|---|
| 421 | static int lm85_detach_client(struct i2c_client *client); |
|---|
| 422 | static int lm85_read_value(struct i2c_client *client, u16 register); |
|---|
| 423 | static int lm85_write_value(struct i2c_client *client, u16 register, int value); |
|---|
| 424 | static void lm85_update_client(struct i2c_client *client); |
|---|
| 425 | static void lm85_init_client(struct i2c_client *client); |
|---|
| 426 | |
|---|
| 427 | |
|---|
| 428 | static void lm85_in(struct i2c_client *client, int operation, int ctl_name, |
|---|
| 429 | int *nrels_mag, long *results); |
|---|
| 430 | static void lm85_fan(struct i2c_client *client, int operation, |
|---|
| 431 | int ctl_name, int *nrels_mag, long *results); |
|---|
| 432 | static void lm85_temp(struct i2c_client *client, int operation, |
|---|
| 433 | int ctl_name, int *nrels_mag, long *results); |
|---|
| 434 | static void lm85_vid(struct i2c_client *client, int operation, |
|---|
| 435 | int ctl_name, int *nrels_mag, long *results); |
|---|
| 436 | static void lm85_vrm(struct i2c_client *client, int operation, |
|---|
| 437 | int ctl_name, int *nrels_mag, long *results); |
|---|
| 438 | static void lm85_alarms(struct i2c_client *client, int operation, |
|---|
| 439 | int ctl_name, int *nrels_mag, long *results); |
|---|
| 440 | static void lm85_pwm(struct i2c_client *client, int operation, |
|---|
| 441 | int ctl_name, int *nrels_mag, long *results); |
|---|
| 442 | static void lm85_zone(struct i2c_client *client, int operation, |
|---|
| 443 | int ctl_name, int *nrels_mag, long *results); |
|---|
| 444 | static void lm85_pwm_config(struct i2c_client *client, int operation, |
|---|
| 445 | int ctl_name, int *nrels_mag, long *results); |
|---|
| 446 | static void lm85_pwm_zone(struct i2c_client *client, int operation, |
|---|
| 447 | int ctl_name, int *nrels_mag, long *results); |
|---|
| 448 | static void lm85_smooth(struct i2c_client *client, int operation, |
|---|
| 449 | int ctl_name, int *nrels_mag, long *results); |
|---|
| 450 | |
|---|
| 451 | static void lm85_spinup_ctl(struct i2c_client *client, int operation, |
|---|
| 452 | int ctl_name, int *nrels_mag, long *results); |
|---|
| 453 | static void lm85_tach_mode(struct i2c_client *client, int operation, |
|---|
| 454 | int ctl_name, int *nrels_mag, long *results); |
|---|
| 455 | |
|---|
| 456 | static void adm1027_tach_mode(struct i2c_client *client, int operation, |
|---|
| 457 | int ctl_name, int *nrels_mag, long *results); |
|---|
| 458 | static void adm1027_temp_offset(struct i2c_client *client, int operation, |
|---|
| 459 | int ctl_name, int *nrels_mag, long *results); |
|---|
| 460 | static void adm1027_fan_ppr(struct i2c_client *client, int operation, |
|---|
| 461 | int ctl_name, int *nrels_mag, long *results); |
|---|
| 462 | static void adm1027_alarm_mask(struct i2c_client *client, int operation, |
|---|
| 463 | int ctl_name, int *nrels_mag, long *results); |
|---|
| 464 | |
|---|
| 465 | static void adt7463_tmin_ctl(struct i2c_client *client, int operation, |
|---|
| 466 | int ctl_name, int *nrels_mag, long *results); |
|---|
| 467 | static void adt7463_therm_signal(struct i2c_client *client, int operation, |
|---|
| 468 | int ctl_name, int *nrels_mag, long *results); |
|---|
| 469 | |
|---|
| 470 | static void emc6d100_in(struct i2c_client *client, int operation, |
|---|
| 471 | int ctl_name, int *nrels_mag, long *results); |
|---|
| 472 | |
|---|
| 473 | static struct i2c_driver lm85_driver = { |
|---|
| 474 | .name = "LM85 compatible sensor driver", |
|---|
| 475 | .id = I2C_DRIVERID_LM85, |
|---|
| 476 | .flags = I2C_DF_NOTIFY, |
|---|
| 477 | .attach_adapter = &lm85_attach_adapter, |
|---|
| 478 | .detach_client = &lm85_detach_client, |
|---|
| 479 | }; |
|---|
| 480 | |
|---|
| 481 | /* Unique ID assigned to each LM85 detected */ |
|---|
| 482 | static int lm85_id = 0; |
|---|
| 483 | |
|---|
| 484 | /* -- SENSORS SYSCTL START -- */ |
|---|
| 485 | /* Common parameters */ |
|---|
| 486 | #define LM85_SYSCTL_IN0 1000 |
|---|
| 487 | #define LM85_SYSCTL_IN1 1001 |
|---|
| 488 | #define LM85_SYSCTL_IN2 1002 |
|---|
| 489 | #define LM85_SYSCTL_IN3 1003 |
|---|
| 490 | #define LM85_SYSCTL_IN4 1004 |
|---|
| 491 | #define LM85_SYSCTL_FAN1 1005 |
|---|
| 492 | #define LM85_SYSCTL_FAN2 1006 |
|---|
| 493 | #define LM85_SYSCTL_FAN3 1007 |
|---|
| 494 | #define LM85_SYSCTL_FAN4 1008 |
|---|
| 495 | #define LM85_SYSCTL_TEMP1 1009 |
|---|
| 496 | #define LM85_SYSCTL_TEMP2 1010 |
|---|
| 497 | #define LM85_SYSCTL_TEMP3 1011 |
|---|
| 498 | #define LM85_SYSCTL_VID 1012 |
|---|
| 499 | #define LM85_SYSCTL_ALARMS 1013 |
|---|
| 500 | #define LM85_SYSCTL_PWM1 1014 |
|---|
| 501 | #define LM85_SYSCTL_PWM2 1015 |
|---|
| 502 | #define LM85_SYSCTL_PWM3 1016 |
|---|
| 503 | #define LM85_SYSCTL_VRM 1017 |
|---|
| 504 | #define LM85_SYSCTL_PWM_CFG1 1019 |
|---|
| 505 | #define LM85_SYSCTL_PWM_CFG2 1020 |
|---|
| 506 | #define LM85_SYSCTL_PWM_CFG3 1021 |
|---|
| 507 | #define LM85_SYSCTL_PWM_ZONE1 1022 |
|---|
| 508 | #define LM85_SYSCTL_PWM_ZONE2 1023 |
|---|
| 509 | #define LM85_SYSCTL_PWM_ZONE3 1024 |
|---|
| 510 | #define LM85_SYSCTL_ZONE1 1025 |
|---|
| 511 | #define LM85_SYSCTL_ZONE2 1026 |
|---|
| 512 | #define LM85_SYSCTL_ZONE3 1027 |
|---|
| 513 | #define LM85_SYSCTL_SMOOTH1 1028 |
|---|
| 514 | #define LM85_SYSCTL_SMOOTH2 1029 |
|---|
| 515 | #define LM85_SYSCTL_SMOOTH3 1030 |
|---|
| 516 | |
|---|
| 517 | /* Vendor specific values */ |
|---|
| 518 | #define LM85_SYSCTL_SPINUP_CTL 1100 |
|---|
| 519 | #define LM85_SYSCTL_TACH_MODE 1101 |
|---|
| 520 | |
|---|
| 521 | /* Analog Devices variant of the LM85 */ |
|---|
| 522 | #define ADM1027_SYSCTL_TACH_MODE 1200 |
|---|
| 523 | #define ADM1027_SYSCTL_TEMP_OFFSET1 1201 |
|---|
| 524 | #define ADM1027_SYSCTL_TEMP_OFFSET2 1202 |
|---|
| 525 | #define ADM1027_SYSCTL_TEMP_OFFSET3 1203 |
|---|
| 526 | #define ADM1027_SYSCTL_FAN_PPR 1204 |
|---|
| 527 | #define ADM1027_SYSCTL_ALARM_MASK 1205 |
|---|
| 528 | |
|---|
| 529 | /* Analog Devices variant of the LM85/ADM1027 */ |
|---|
| 530 | #define ADT7463_SYSCTL_TMIN_CTL1 1300 |
|---|
| 531 | #define ADT7463_SYSCTL_TMIN_CTL2 1301 |
|---|
| 532 | #define ADT7463_SYSCTL_TMIN_CTL3 1302 |
|---|
| 533 | #define ADT7463_SYSCTL_THERM_SIGNAL 1303 |
|---|
| 534 | |
|---|
| 535 | /* SMSC variant of the LM85 */ |
|---|
| 536 | #define EMC6D100_SYSCTL_IN5 1400 |
|---|
| 537 | #define EMC6D100_SYSCTL_IN6 1401 |
|---|
| 538 | #define EMC6D100_SYSCTL_IN7 1402 |
|---|
| 539 | |
|---|
| 540 | #define LM85_ALARM_IN0 0x0001 |
|---|
| 541 | #define LM85_ALARM_IN1 0x0002 |
|---|
| 542 | #define LM85_ALARM_IN2 0x0004 |
|---|
| 543 | #define LM85_ALARM_IN3 0x0008 |
|---|
| 544 | #define LM85_ALARM_TEMP1 0x0010 |
|---|
| 545 | #define LM85_ALARM_TEMP2 0x0020 |
|---|
| 546 | #define LM85_ALARM_TEMP3 0x0040 |
|---|
| 547 | #define LM85_ALARM_ALARM2 0x0080 |
|---|
| 548 | #define LM85_ALARM_IN4 0x0100 |
|---|
| 549 | #define LM85_ALARM_RESERVED 0x0200 |
|---|
| 550 | #define LM85_ALARM_FAN1 0x0400 |
|---|
| 551 | #define LM85_ALARM_FAN2 0x0800 |
|---|
| 552 | #define LM85_ALARM_FAN3 0x1000 |
|---|
| 553 | #define LM85_ALARM_FAN4 0x2000 |
|---|
| 554 | #define LM85_ALARM_TEMP1_FAULT 0x4000 |
|---|
| 555 | #define LM85_ALARM_TEMP3_FAULT 0x08000 |
|---|
| 556 | #define LM85_ALARM_IN6 0x10000 |
|---|
| 557 | #define LM85_ALARM_IN7 0x20000 |
|---|
| 558 | #define LM85_ALARM_IN5 0x40000 |
|---|
| 559 | /* -- SENSORS SYSCTL END -- */ |
|---|
| 560 | |
|---|
| 561 | /* The /proc/sys entries */ |
|---|
| 562 | /* These files are created for each detected LM85. This is just a template; |
|---|
| 563 | * The actual list is built from this and additional per-chip |
|---|
| 564 | * custom lists below. Note the XXX_LEN macros. These must be |
|---|
| 565 | * compile time constants because they will be used to allocate |
|---|
| 566 | * space for the final template passed to i2c_register_entry. |
|---|
| 567 | * We depend on the ability of GCC to evaluate expressions at |
|---|
| 568 | * compile time to turn these expressions into compile time |
|---|
| 569 | * constants, but this can generate a warning. |
|---|
| 570 | */ |
|---|
| 571 | static ctl_table lm85_common[] = { |
|---|
| 572 | {LM85_SYSCTL_IN0, "in0", NULL, 0, 0644, NULL, &i2c_proc_real, |
|---|
| 573 | &i2c_sysctl_real, NULL, &lm85_in}, |
|---|
| 574 | {LM85_SYSCTL_IN1, "in1", NULL, 0, 0644, NULL, &i2c_proc_real, |
|---|
| 575 | &i2c_sysctl_real, NULL, &lm85_in}, |
|---|
| 576 | {LM85_SYSCTL_IN2, "in2", NULL, 0, 0644, NULL, &i2c_proc_real, |
|---|
| 577 | &i2c_sysctl_real, NULL, &lm85_in}, |
|---|
| 578 | {LM85_SYSCTL_IN3, "in3", NULL, 0, 0644, NULL, &i2c_proc_real, |
|---|
| 579 | &i2c_sysctl_real, NULL, &lm85_in}, |
|---|
| 580 | {LM85_SYSCTL_IN4, "in4", NULL, 0, 0644, NULL, &i2c_proc_real, |
|---|
| 581 | &i2c_sysctl_real, NULL, &lm85_in}, |
|---|
| 582 | {LM85_SYSCTL_FAN1, "fan1", NULL, 0, 0644, NULL, &i2c_proc_real, |
|---|
| 583 | &i2c_sysctl_real, NULL, &lm85_fan}, |
|---|
| 584 | {LM85_SYSCTL_FAN2, "fan2", NULL, 0, 0644, NULL, &i2c_proc_real, |
|---|
| 585 | &i2c_sysctl_real, NULL, &lm85_fan}, |
|---|
| 586 | {LM85_SYSCTL_FAN3, "fan3", NULL, 0, 0644, NULL, &i2c_proc_real, |
|---|
| 587 | &i2c_sysctl_real, NULL, &lm85_fan}, |
|---|
| 588 | {LM85_SYSCTL_FAN4, "fan4", NULL, 0, 0644, NULL, &i2c_proc_real, |
|---|
| 589 | &i2c_sysctl_real, NULL, &lm85_fan}, |
|---|
| 590 | {LM85_SYSCTL_TEMP1, "temp1", NULL, 0, 0644, NULL, &i2c_proc_real, |
|---|
| 591 | &i2c_sysctl_real, NULL, &lm85_temp}, |
|---|
| 592 | {LM85_SYSCTL_TEMP2, "temp2", NULL, 0, 0644, NULL, &i2c_proc_real, |
|---|
| 593 | &i2c_sysctl_real, NULL, &lm85_temp}, |
|---|
| 594 | {LM85_SYSCTL_TEMP3, "temp3", NULL, 0, 0644, NULL, &i2c_proc_real, |
|---|
| 595 | &i2c_sysctl_real, NULL, &lm85_temp}, |
|---|
| 596 | {LM85_SYSCTL_VID, "vid", NULL, 0, 0444, NULL, &i2c_proc_real, |
|---|
| 597 | &i2c_sysctl_real, NULL, &lm85_vid}, |
|---|
| 598 | {LM85_SYSCTL_VRM, "vrm", NULL, 0, 0644, NULL, &i2c_proc_real, |
|---|
| 599 | &i2c_sysctl_real, NULL, &lm85_vrm}, |
|---|
| 600 | {LM85_SYSCTL_ALARMS, "alarms", NULL, 0, 0444, NULL, &i2c_proc_real, |
|---|
| 601 | &i2c_sysctl_real, NULL, &lm85_alarms}, |
|---|
| 602 | {LM85_SYSCTL_PWM1, "pwm1", NULL, 0, 0644, NULL, &i2c_proc_real, |
|---|
| 603 | &i2c_sysctl_real, NULL, &lm85_pwm}, |
|---|
| 604 | {LM85_SYSCTL_PWM2, "pwm2", NULL, 0, 0644, NULL, &i2c_proc_real, |
|---|
| 605 | &i2c_sysctl_real, NULL, &lm85_pwm}, |
|---|
| 606 | {LM85_SYSCTL_PWM3, "pwm3", NULL, 0, 0644, NULL, &i2c_proc_real, |
|---|
| 607 | &i2c_sysctl_real, NULL, &lm85_pwm}, |
|---|
| 608 | {LM85_SYSCTL_PWM_CFG1, "pwm1_cfg", NULL, 0, 0644, NULL, &i2c_proc_real, |
|---|
| 609 | &i2c_sysctl_real, NULL, &lm85_pwm_config}, |
|---|
| 610 | {LM85_SYSCTL_PWM_CFG2, "pwm2_cfg", NULL, 0, 0644, NULL, &i2c_proc_real, |
|---|
| 611 | &i2c_sysctl_real, NULL, &lm85_pwm_config}, |
|---|
| 612 | {LM85_SYSCTL_PWM_CFG3, "pwm3_cfg", NULL, 0, 0644, NULL, &i2c_proc_real, |
|---|
| 613 | &i2c_sysctl_real, NULL, &lm85_pwm_config}, |
|---|
| 614 | {LM85_SYSCTL_PWM_ZONE1, "pwm1_zone", NULL, 0, 0644, NULL, |
|---|
| 615 | &i2c_proc_real, &i2c_sysctl_real, NULL, &lm85_pwm_zone}, |
|---|
| 616 | {LM85_SYSCTL_PWM_ZONE2, "pwm2_zone", NULL, 0, 0644, NULL, |
|---|
| 617 | &i2c_proc_real, &i2c_sysctl_real, NULL, &lm85_pwm_zone}, |
|---|
| 618 | {LM85_SYSCTL_PWM_ZONE3, "pwm3_zone", NULL, 0, 0644, NULL, |
|---|
| 619 | &i2c_proc_real, &i2c_sysctl_real, NULL, &lm85_pwm_zone}, |
|---|
| 620 | {LM85_SYSCTL_ZONE1, "zone1", NULL, 0, 0644, NULL, &i2c_proc_real, |
|---|
| 621 | &i2c_sysctl_real, NULL, &lm85_zone}, |
|---|
| 622 | {LM85_SYSCTL_ZONE2, "zone2", NULL, 0, 0644, NULL, &i2c_proc_real, |
|---|
| 623 | &i2c_sysctl_real, NULL, &lm85_zone}, |
|---|
| 624 | {LM85_SYSCTL_ZONE3, "zone3", NULL, 0, 0644, NULL, &i2c_proc_real, |
|---|
| 625 | &i2c_sysctl_real, NULL, &lm85_zone}, |
|---|
| 626 | {LM85_SYSCTL_SMOOTH1, "smooth1", NULL, 0, 0644, NULL, &i2c_proc_real, |
|---|
| 627 | &i2c_sysctl_real, NULL, &lm85_smooth}, |
|---|
| 628 | {LM85_SYSCTL_SMOOTH2, "smooth2", NULL, 0, 0644, NULL, &i2c_proc_real, |
|---|
| 629 | &i2c_sysctl_real, NULL, &lm85_smooth}, |
|---|
| 630 | {LM85_SYSCTL_SMOOTH3, "smooth3", NULL, 0, 0644, NULL, &i2c_proc_real, |
|---|
| 631 | &i2c_sysctl_real, NULL, &lm85_smooth}, |
|---|
| 632 | {0} |
|---|
| 633 | }; |
|---|
| 634 | #define CTLTBL_COMMON (sizeof(lm85_common)/sizeof(lm85_common[0])) |
|---|
| 635 | |
|---|
| 636 | /* NOTE: tach_mode is a shared name, but implemented with |
|---|
| 637 | * different functions |
|---|
| 638 | */ |
|---|
| 639 | static ctl_table lm85_specific[] = { |
|---|
| 640 | {LM85_SYSCTL_SPINUP_CTL, "spinup_ctl", NULL, 0, 0644, NULL, |
|---|
| 641 | &i2c_proc_real, &i2c_sysctl_real, NULL, &lm85_spinup_ctl}, |
|---|
| 642 | {LM85_SYSCTL_TACH_MODE, "tach_mode", NULL, 0, 0644, NULL, |
|---|
| 643 | &i2c_proc_real, &i2c_sysctl_real, NULL, &lm85_tach_mode}, |
|---|
| 644 | /* {0} The doc generator needs this. */ |
|---|
| 645 | }; |
|---|
| 646 | #define CTLTBL_LM85 (sizeof(lm85_specific)/sizeof(lm85_specific[0])) |
|---|
| 647 | |
|---|
| 648 | static ctl_table adm1027_specific[] = { |
|---|
| 649 | {ADM1027_SYSCTL_TACH_MODE, "tach_mode", NULL, 0, 0644, NULL, |
|---|
| 650 | &i2c_proc_real, &i2c_sysctl_real, NULL, &adm1027_tach_mode}, |
|---|
| 651 | {ADM1027_SYSCTL_TEMP_OFFSET1, "temp1_offset", NULL, 0, 0644, NULL, |
|---|
| 652 | &i2c_proc_real, &i2c_sysctl_real, NULL, &adm1027_temp_offset}, |
|---|
| 653 | {ADM1027_SYSCTL_TEMP_OFFSET2, "temp2_offset", NULL, 0, 0644, NULL, |
|---|
| 654 | &i2c_proc_real, &i2c_sysctl_real, NULL, &adm1027_temp_offset}, |
|---|
| 655 | {ADM1027_SYSCTL_TEMP_OFFSET3, "temp3_offset", NULL, 0, 0644, NULL, |
|---|
| 656 | &i2c_proc_real, &i2c_sysctl_real, NULL, &adm1027_temp_offset}, |
|---|
| 657 | {ADM1027_SYSCTL_FAN_PPR, "fan_ppr", NULL, 0, 0644, NULL, |
|---|
| 658 | &i2c_proc_real, &i2c_sysctl_real, NULL, &adm1027_fan_ppr}, |
|---|
| 659 | {ADM1027_SYSCTL_ALARM_MASK, "alarm_mask", NULL, 0, 0644, NULL, |
|---|
| 660 | &i2c_proc_real, &i2c_sysctl_real, NULL, &adm1027_alarm_mask}, |
|---|
| 661 | /* {0} The doc generator needs this. */ |
|---|
| 662 | }; |
|---|
| 663 | #define CTLTBL_ADM1027 (sizeof(adm1027_specific)/sizeof(adm1027_specific[0])) |
|---|
| 664 | |
|---|
| 665 | static ctl_table adt7463_specific[] = { |
|---|
| 666 | {ADT7463_SYSCTL_TMIN_CTL1, "tmin_ctl1", NULL, 0, 0644, NULL, |
|---|
| 667 | &i2c_proc_real, &i2c_sysctl_real, NULL, &adt7463_tmin_ctl}, |
|---|
| 668 | {ADT7463_SYSCTL_TMIN_CTL2, "tmin_ctl2", NULL, 0, 0644, NULL, |
|---|
| 669 | &i2c_proc_real, &i2c_sysctl_real, NULL, &adt7463_tmin_ctl}, |
|---|
| 670 | {ADT7463_SYSCTL_TMIN_CTL3, "tmin_ctl3", NULL, 0, 0644, NULL, |
|---|
| 671 | &i2c_proc_real, &i2c_sysctl_real, NULL, &adt7463_tmin_ctl}, |
|---|
| 672 | {ADT7463_SYSCTL_THERM_SIGNAL, "therm_signal", NULL, 0, 0644, NULL, |
|---|
| 673 | &i2c_proc_real, &i2c_sysctl_real, NULL, &adt7463_therm_signal}, |
|---|
| 674 | /* {0} The doc generator needs this. */ |
|---|
| 675 | }; |
|---|
| 676 | #define CTLTBL_ADT7463 (sizeof(adt7463_specific)/sizeof(adt7463_specific[0])) |
|---|
| 677 | |
|---|
| 678 | static ctl_table emc6d100_specific[] = { |
|---|
| 679 | {EMC6D100_SYSCTL_IN5, "in5", NULL, 0, 0644, NULL, &i2c_proc_real, |
|---|
| 680 | &i2c_sysctl_real, NULL, &emc6d100_in}, |
|---|
| 681 | {EMC6D100_SYSCTL_IN6, "in6", NULL, 0, 0644, NULL, &i2c_proc_real, |
|---|
| 682 | &i2c_sysctl_real, NULL, &emc6d100_in}, |
|---|
| 683 | {EMC6D100_SYSCTL_IN7, "in7", NULL, 0, 0644, NULL, &i2c_proc_real, |
|---|
| 684 | &i2c_sysctl_real, NULL, &emc6d100_in}, |
|---|
| 685 | /* {0} The doc generator needs this. */ |
|---|
| 686 | }; |
|---|
| 687 | #define CTLTBL_EMC6D100 (sizeof(emc6d100_specific)/sizeof(emc6d100_specific[0])) |
|---|
| 688 | |
|---|
| 689 | |
|---|
| 690 | #define MAX2(a,b) ((a)>(b)?(a):(b)) |
|---|
| 691 | #define MAX3(a,b,c) ((a)>(b)?MAX2((a),(c)):MAX2((b),(c))) |
|---|
| 692 | #define MAX4(a,b,c,d) ((a)>(b)?MAX3((a),(c),(d)):MAX3((b),(c),(d))) |
|---|
| 693 | |
|---|
| 694 | #define CTLTBL_MAX (CTLTBL_COMMON + MAX3(CTLTBL_LM85, CTLTBL_ADM1027+CTLTBL_ADT7463, CTLTBL_EMC6D100)) |
|---|
| 695 | |
|---|
| 696 | /* This function is called when: |
|---|
| 697 | * lm85_driver is inserted (when this module is loaded), for each |
|---|
| 698 | available adapter |
|---|
| 699 | * when a new adapter is inserted (and lm85_driver is still present) */ |
|---|
| 700 | static int lm85_attach_adapter(struct i2c_adapter *adapter) |
|---|
| 701 | { |
|---|
| 702 | return i2c_detect(adapter, &addr_data, lm85_detect); |
|---|
| 703 | } |
|---|
| 704 | |
|---|
| 705 | /* This function is called by i2c_detect */ |
|---|
| 706 | static int lm85_detect(struct i2c_adapter *adapter, int address, |
|---|
| 707 | unsigned short flags, int kind) |
|---|
| 708 | { |
|---|
| 709 | int i; |
|---|
| 710 | int company, verstep ; |
|---|
| 711 | struct i2c_client *new_client; |
|---|
| 712 | struct lm85_data *data; |
|---|
| 713 | int err = 0; |
|---|
| 714 | const char *type_name = ""; |
|---|
| 715 | struct ctl_table template[CTLTBL_MAX] ; |
|---|
| 716 | int template_used ; |
|---|
| 717 | |
|---|
| 718 | if (i2c_is_isa_adapter(adapter)) { |
|---|
| 719 | /* This chip has no ISA interface */ |
|---|
| 720 | goto ERROR0 ; |
|---|
| 721 | }; |
|---|
| 722 | |
|---|
| 723 | if (!i2c_check_functionality(adapter, |
|---|
| 724 | I2C_FUNC_SMBUS_BYTE_DATA)) { |
|---|
| 725 | /* We need to be able to do byte I/O */ |
|---|
| 726 | goto ERROR0 ; |
|---|
| 727 | }; |
|---|
| 728 | |
|---|
| 729 | /* OK. For now, we presume we have a valid client. We now create the |
|---|
| 730 | client structure, even though we cannot fill it completely yet. |
|---|
| 731 | But it allows us to access lm85_{read,write}_value. */ |
|---|
| 732 | |
|---|
| 733 | if (!(data = kmalloc(sizeof(struct lm85_data), GFP_KERNEL))) { |
|---|
| 734 | err = -ENOMEM; |
|---|
| 735 | goto ERROR0; |
|---|
| 736 | } |
|---|
| 737 | |
|---|
| 738 | new_client = &data->client; |
|---|
| 739 | new_client->addr = address; |
|---|
| 740 | new_client->data = data; |
|---|
| 741 | new_client->adapter = adapter; |
|---|
| 742 | new_client->driver = &lm85_driver; |
|---|
| 743 | new_client->flags = 0; |
|---|
| 744 | |
|---|
| 745 | /* Now, we do the remaining detection. */ |
|---|
| 746 | |
|---|
| 747 | company = lm85_read_value(new_client, LM85_REG_COMPANY); |
|---|
| 748 | verstep = lm85_read_value(new_client, LM85_REG_VERSTEP); |
|---|
| 749 | |
|---|
| 750 | #ifdef DEBUG |
|---|
| 751 | printk("lm85: Detecting device at %d,0x%02x with" |
|---|
| 752 | " COMPANY: 0x%02x and VERSTEP: 0x%02x\n", |
|---|
| 753 | i2c_adapter_id(new_client->adapter), new_client->addr, |
|---|
| 754 | company, verstep |
|---|
| 755 | ); |
|---|
| 756 | #endif |
|---|
| 757 | |
|---|
| 758 | /* If auto-detecting, Determine the chip type. */ |
|---|
| 759 | if (kind <= 0) { |
|---|
| 760 | #ifdef DEBUG |
|---|
| 761 | printk("lm85: Autodetecting device at %d,0x%02x ...\n", |
|---|
| 762 | i2c_adapter_id(adapter), address ); |
|---|
| 763 | #endif |
|---|
| 764 | if( company == LM85_COMPANY_NATIONAL |
|---|
| 765 | && verstep == LM85_VERSTEP_LM85C ) { |
|---|
| 766 | kind = lm85c ; |
|---|
| 767 | } else if( company == LM85_COMPANY_NATIONAL |
|---|
| 768 | && verstep == LM85_VERSTEP_LM85B ) { |
|---|
| 769 | kind = lm85b ; |
|---|
| 770 | } else if( company == LM85_COMPANY_NATIONAL |
|---|
| 771 | && (verstep & LM85_VERSTEP_VMASK) == LM85_VERSTEP_GENERIC) { |
|---|
| 772 | printk("lm85: Detected National Semiconductor chip\n"); |
|---|
| 773 | printk("lm85: Unrecognized version/stepping 0x%02x" |
|---|
| 774 | " Defaulting to Generic LM85.\n", verstep ); |
|---|
| 775 | kind = any_chip ; |
|---|
| 776 | } else if( company == LM85_COMPANY_ANALOG_DEV |
|---|
| 777 | && verstep == LM85_VERSTEP_ADM1027 ) { |
|---|
| 778 | kind = adm1027 ; |
|---|
| 779 | } else if( company == LM85_COMPANY_ANALOG_DEV |
|---|
| 780 | && (verstep == LM85_VERSTEP_ADT7463 |
|---|
| 781 | || verstep == LM85_VERSTEP_ADT7463C) ) { |
|---|
| 782 | kind = adt7463 ; |
|---|
| 783 | } else if( company == LM85_COMPANY_ANALOG_DEV |
|---|
| 784 | && (verstep & LM85_VERSTEP_VMASK) == LM85_VERSTEP_GENERIC) { |
|---|
| 785 | printk("lm85: Detected Analog Devices chip\n"); |
|---|
| 786 | printk("lm85: Unrecognized version/stepping 0x%02x" |
|---|
| 787 | " Defaulting to Generic LM85.\n", verstep ); |
|---|
| 788 | kind = any_chip ; |
|---|
| 789 | } else if( company == LM85_COMPANY_SMSC |
|---|
| 790 | && verstep == LM85_VERSTEP_EMC6D102) { |
|---|
| 791 | kind = emc6d102; |
|---|
| 792 | } else if( company == LM85_COMPANY_SMSC |
|---|
| 793 | && (verstep == LM85_VERSTEP_EMC6D100_A0 |
|---|
| 794 | || verstep == LM85_VERSTEP_EMC6D100_A1) ) { |
|---|
| 795 | /* Unfortunately, we can't tell a '100 from a '101 |
|---|
| 796 | * from the registers. Since a '101 is a '100 |
|---|
| 797 | * in a package with fewer pins and therefore no |
|---|
| 798 | * 3.3V, 1.5V or 1.8V inputs, perhaps if those |
|---|
| 799 | * inputs read 0, then it's a '101. |
|---|
| 800 | */ |
|---|
| 801 | kind = emc6d100 ; |
|---|
| 802 | } else if( company == LM85_COMPANY_SMSC |
|---|
| 803 | && (verstep & LM85_VERSTEP_VMASK) == LM85_VERSTEP_GENERIC) { |
|---|
| 804 | printk("lm85: Detected SMSC chip\n"); |
|---|
| 805 | printk("lm85: Unrecognized version/stepping 0x%02x" |
|---|
| 806 | " Defaulting to Generic LM85.\n", verstep ); |
|---|
| 807 | kind = any_chip ; |
|---|
| 808 | } else if( kind == any_chip |
|---|
| 809 | && (verstep & LM85_VERSTEP_VMASK) == LM85_VERSTEP_GENERIC) { |
|---|
| 810 | printk("lm85: Generic LM85 Version 6 detected\n"); |
|---|
| 811 | /* Leave kind as "any_chip" */ |
|---|
| 812 | } else { |
|---|
| 813 | #ifdef DEBUG |
|---|
| 814 | printk("lm85: Autodetection failed\n"); |
|---|
| 815 | #endif |
|---|
| 816 | /* Not an LM85 ... */ |
|---|
| 817 | if( kind == any_chip ) { /* User used force=x,y */ |
|---|
| 818 | printk("lm85: Generic LM85 Version 6 not" |
|---|
| 819 | " found at %d,0x%02x. Try force_lm85c.\n", |
|---|
| 820 | i2c_adapter_id(adapter), address ); |
|---|
| 821 | } |
|---|
| 822 | goto ERROR1; |
|---|
| 823 | } |
|---|
| 824 | } |
|---|
| 825 | |
|---|
| 826 | /* Fill in the chip specific driver values */ |
|---|
| 827 | switch (kind) { |
|---|
| 828 | case any_chip : |
|---|
| 829 | type_name = "lm85"; |
|---|
| 830 | strcpy(new_client->name, "Generic LM85"); |
|---|
| 831 | template_used = 0 ; |
|---|
| 832 | break ; |
|---|
| 833 | case lm85b : |
|---|
| 834 | type_name = "lm85b"; |
|---|
| 835 | strcpy(new_client->name, "National LM85-B"); |
|---|
| 836 | memcpy( template, lm85_specific, sizeof(lm85_specific) ); |
|---|
| 837 | template_used = CTLTBL_LM85 ; |
|---|
| 838 | break ; |
|---|
| 839 | case lm85c : |
|---|
| 840 | type_name = "lm85c"; |
|---|
| 841 | strcpy(new_client->name, "National LM85-C"); |
|---|
| 842 | memcpy( template, lm85_specific, sizeof(lm85_specific) ); |
|---|
| 843 | template_used = CTLTBL_LM85 ; |
|---|
| 844 | break ; |
|---|
| 845 | case adm1027 : |
|---|
| 846 | type_name = "adm1027"; |
|---|
| 847 | strcpy(new_client->name, "Analog Devices ADM1027"); |
|---|
| 848 | memcpy( template, adm1027_specific, sizeof(adm1027_specific) ); |
|---|
| 849 | template_used = CTLTBL_ADM1027 ; |
|---|
| 850 | break ; |
|---|
| 851 | case adt7463 : |
|---|
| 852 | type_name = "adt7463"; |
|---|
| 853 | strcpy(new_client->name, "Analog Devices ADT7463"); |
|---|
| 854 | memcpy( template, adt7463_specific, sizeof(adt7463_specific) ); |
|---|
| 855 | template_used = CTLTBL_ADT7463 ; |
|---|
| 856 | memcpy( template+template_used, adm1027_specific, sizeof(adm1027_specific) ); |
|---|
| 857 | template_used += CTLTBL_ADM1027 ; |
|---|
| 858 | break ; |
|---|
| 859 | case emc6d100 : |
|---|
| 860 | type_name = "emc6d100"; |
|---|
| 861 | strcpy(new_client->name, "SMSC EMC6D100"); |
|---|
| 862 | memcpy(template, emc6d100_specific, sizeof(emc6d100_specific)); |
|---|
| 863 | template_used = CTLTBL_EMC6D100 ; |
|---|
| 864 | break ; |
|---|
| 865 | case emc6d102 : |
|---|
| 866 | type_name = "emc6d102"; |
|---|
| 867 | strcpy(new_client->name, "SMSC EMC6D102"); |
|---|
| 868 | template_used = 0; |
|---|
| 869 | break; |
|---|
| 870 | default : |
|---|
| 871 | printk("lm85: Internal error, invalid kind (%d)!\n", kind); |
|---|
| 872 | err = -EFAULT ; |
|---|
| 873 | goto ERROR1; |
|---|
| 874 | } |
|---|
| 875 | |
|---|
| 876 | /* Fill in the remaining client fields */ |
|---|
| 877 | new_client->id = lm85_id++; |
|---|
| 878 | printk("lm85: Assigning ID %d to %s at %d,0x%02x\n", |
|---|
| 879 | new_client->id, new_client->name, |
|---|
| 880 | i2c_adapter_id(new_client->adapter), |
|---|
| 881 | new_client->addr |
|---|
| 882 | ); |
|---|
| 883 | |
|---|
| 884 | /* Housekeeping values */ |
|---|
| 885 | data->type = kind; |
|---|
| 886 | data->valid = 0; |
|---|
| 887 | |
|---|
| 888 | /* Set the VRM version */ |
|---|
| 889 | data->vrm = LM85_INIT_VRM ; |
|---|
| 890 | |
|---|
| 891 | /* Zero the accumulators */ |
|---|
| 892 | data->therm_total = 0; |
|---|
| 893 | data->therm_ovfl = 0; |
|---|
| 894 | |
|---|
| 895 | init_MUTEX(&data->update_lock); |
|---|
| 896 | data->extend_adc = 0; |
|---|
| 897 | |
|---|
| 898 | /* Initialize the LM85 chip */ |
|---|
| 899 | lm85_init_client(new_client); |
|---|
| 900 | |
|---|
| 901 | /* Tell the I2C layer a new client has arrived */ |
|---|
| 902 | if ((err = i2c_attach_client(new_client))) |
|---|
| 903 | goto ERROR1; |
|---|
| 904 | |
|---|
| 905 | /* Finish out the template */ |
|---|
| 906 | memcpy( template + template_used, lm85_common, sizeof(lm85_common) ); |
|---|
| 907 | |
|---|
| 908 | /* Register a new directory entry with module sensors */ |
|---|
| 909 | if ((i = i2c_register_entry(new_client, |
|---|
| 910 | type_name, |
|---|
| 911 | template, |
|---|
| 912 | THIS_MODULE)) < 0) { |
|---|
| 913 | err = i; |
|---|
| 914 | goto ERROR2; |
|---|
| 915 | } |
|---|
| 916 | data->sysctl_id = i; |
|---|
| 917 | |
|---|
| 918 | return 0; |
|---|
| 919 | |
|---|
| 920 | /* Error out and cleanup code */ |
|---|
| 921 | ERROR2: |
|---|
| 922 | i2c_detach_client(new_client); |
|---|
| 923 | ERROR1: |
|---|
| 924 | kfree(data); |
|---|
| 925 | ERROR0: |
|---|
| 926 | return err; |
|---|
| 927 | } |
|---|
| 928 | |
|---|
| 929 | static int lm85_detach_client(struct i2c_client *client) |
|---|
| 930 | { |
|---|
| 931 | int err; |
|---|
| 932 | int id ; |
|---|
| 933 | |
|---|
| 934 | id = client->id; |
|---|
| 935 | i2c_deregister_entry(((struct lm85_data *)(client->data))->sysctl_id); |
|---|
| 936 | |
|---|
| 937 | if ((err = i2c_detach_client(client))) { |
|---|
| 938 | printk("lm85(%d): Client deregistration failed," |
|---|
| 939 | " client not detached.\n", id ); |
|---|
| 940 | return err; |
|---|
| 941 | } |
|---|
| 942 | |
|---|
| 943 | kfree(client->data); |
|---|
| 944 | |
|---|
| 945 | return 0; |
|---|
| 946 | } |
|---|
| 947 | |
|---|
| 948 | static int lm85_read_value(struct i2c_client *client, u16 reg) |
|---|
| 949 | { |
|---|
| 950 | int res; |
|---|
| 951 | |
|---|
| 952 | /* What size location is it? */ |
|---|
| 953 | switch( reg ) { |
|---|
| 954 | case LM85_REG_FAN(0) : /* Read WORD data */ |
|---|
| 955 | case LM85_REG_FAN(1) : |
|---|
| 956 | case LM85_REG_FAN(2) : |
|---|
| 957 | case LM85_REG_FAN(3) : |
|---|
| 958 | case LM85_REG_FAN_MIN(0) : |
|---|
| 959 | case LM85_REG_FAN_MIN(1) : |
|---|
| 960 | case LM85_REG_FAN_MIN(2) : |
|---|
| 961 | case LM85_REG_FAN_MIN(3) : |
|---|
| 962 | case LM85_REG_ALARM : /* Read ALARM1 and ALARM2 */ |
|---|
| 963 | case ADM1027_REG_INTMASK : /* Read MASK1 and MASK2 */ |
|---|
| 964 | case ADM1027_REG_EXTEND_ADC : /* Read ADC1 and ADC2 */ |
|---|
| 965 | reg &= 0xff ; /* Pseudo words have address + 0x0100 */ |
|---|
| 966 | res = i2c_smbus_read_byte_data(client, reg) & 0xff ; |
|---|
| 967 | res |= (i2c_smbus_read_byte_data(client, reg+1) & 0xff) << 8 ; |
|---|
| 968 | break ; |
|---|
| 969 | case ADT7463_REG_TMIN_CTL : /* Read WORD MSB, LSB */ |
|---|
| 970 | reg &= 0xff ; /* Pseudo words have address + 0x0100 */ |
|---|
| 971 | res = (i2c_smbus_read_byte_data(client, reg) & 0xff) << 8 ; |
|---|
| 972 | res |= i2c_smbus_read_byte_data(client, reg+1) & 0xff ; |
|---|
| 973 | break ; |
|---|
| 974 | default: /* Read BYTE data */ |
|---|
| 975 | res = i2c_smbus_read_byte_data(client, reg & 0xff) & 0xff ; |
|---|
| 976 | break ; |
|---|
| 977 | } |
|---|
| 978 | |
|---|
| 979 | return res ; |
|---|
| 980 | } |
|---|
| 981 | |
|---|
| 982 | static int lm85_write_value(struct i2c_client *client, u16 reg, int value) |
|---|
| 983 | { |
|---|
| 984 | int res ; |
|---|
| 985 | |
|---|
| 986 | switch( reg ) { |
|---|
| 987 | case LM85_REG_FAN(0) : /* Write WORD data */ |
|---|
| 988 | case LM85_REG_FAN(1) : |
|---|
| 989 | case LM85_REG_FAN(2) : |
|---|
| 990 | case LM85_REG_FAN(3) : |
|---|
| 991 | case LM85_REG_FAN_MIN(0) : |
|---|
| 992 | case LM85_REG_FAN_MIN(1) : |
|---|
| 993 | case LM85_REG_FAN_MIN(2) : |
|---|
| 994 | case LM85_REG_FAN_MIN(3) : |
|---|
| 995 | case ADM1027_REG_INTMASK : |
|---|
| 996 | /* NOTE: ALARM and ADC are read only, so not included here */ |
|---|
| 997 | reg &= 0xff ; /* Pseudo words have address + 0x0100 */ |
|---|
| 998 | res = i2c_smbus_write_byte_data(client, reg, value & 0xff) ; |
|---|
| 999 | res |= i2c_smbus_write_byte_data(client, reg+1, (value>>8) & 0xff) ; |
|---|
| 1000 | break ; |
|---|
| 1001 | case ADT7463_REG_TMIN_CTL : /* Write WORD MSB, LSB */ |
|---|
| 1002 | reg &= 0xff ; /* Pseudo words have address + 0x0100 */ |
|---|
| 1003 | res = i2c_smbus_write_byte_data(client, reg, (value>>8) & 0xff); |
|---|
| 1004 | res |= i2c_smbus_write_byte_data(client, reg+1, value & 0xff) ; |
|---|
| 1005 | break ; |
|---|
| 1006 | default: /* Write BYTE data */ |
|---|
| 1007 | res = i2c_smbus_write_byte_data(client, reg & 0xff, value); |
|---|
| 1008 | break ; |
|---|
| 1009 | } |
|---|
| 1010 | |
|---|
| 1011 | return res ; |
|---|
| 1012 | } |
|---|
| 1013 | |
|---|
| 1014 | /* Called when we have found a new LM85. */ |
|---|
| 1015 | static void lm85_init_client(struct i2c_client *client) |
|---|
| 1016 | { |
|---|
| 1017 | int value; |
|---|
| 1018 | struct lm85_data *data = client->data; |
|---|
| 1019 | |
|---|
| 1020 | #ifdef DEBUG |
|---|
| 1021 | printk("lm85(%d): Initializing device\n", client->id); |
|---|
| 1022 | #endif |
|---|
| 1023 | |
|---|
| 1024 | /* Warn if part was not "READY" */ |
|---|
| 1025 | value = lm85_read_value(client, LM85_REG_CONFIG); |
|---|
| 1026 | #ifdef DEBUG |
|---|
| 1027 | printk("lm85(%d): LM85_REG_CONFIG is: 0x%02x\n", client->id, value ); |
|---|
| 1028 | #endif |
|---|
| 1029 | if( value & 0x02 ) { |
|---|
| 1030 | printk("lm85(%d): Client (%d,0x%02x) config is locked.\n", |
|---|
| 1031 | client->id, |
|---|
| 1032 | i2c_adapter_id(client->adapter), client->addr ); |
|---|
| 1033 | }; |
|---|
| 1034 | if( ! (value & 0x04) ) { |
|---|
| 1035 | printk("lm85(%d): Client (%d,0x%02x) is not ready.\n", |
|---|
| 1036 | client->id, |
|---|
| 1037 | i2c_adapter_id(client->adapter), client->addr ); |
|---|
| 1038 | }; |
|---|
| 1039 | if( (data->type == adm1027 || data->type == adt7463) |
|---|
| 1040 | && (value & 0x10) |
|---|
| 1041 | ) { |
|---|
| 1042 | printk("lm85(%d): Client (%d,0x%02x) VxI mode is set. " |
|---|
| 1043 | "Please report this to the lm85 maintainer.\n", |
|---|
| 1044 | client->id, |
|---|
| 1045 | i2c_adapter_id(client->adapter), client->addr ); |
|---|
| 1046 | }; |
|---|
| 1047 | |
|---|
| 1048 | /* See if SYNC to PWM3 is set */ |
|---|
| 1049 | if( data->type == adt7463 |
|---|
| 1050 | && (lm85_read_value(client, LM85_REG_AFAN_SPIKE1) & 0x10) |
|---|
| 1051 | ) { |
|---|
| 1052 | printk("lm85(%d): Sync to PWM3 is set. Expect PWM3 " |
|---|
| 1053 | "to control fans 2, 3, and 4\n", |
|---|
| 1054 | client->id ); |
|---|
| 1055 | }; |
|---|
| 1056 | |
|---|
| 1057 | /* See if PWM2 is #SMBALERT */ |
|---|
| 1058 | if( (data->type == adm1027 || data->type == adt7463) |
|---|
| 1059 | && (lm85_read_value(client, ADM1027_REG_CONFIG3) & 0x01) |
|---|
| 1060 | ) { |
|---|
| 1061 | printk("lm85(%d): PWM2 is SMBALERT. PWM2 not available.\n", |
|---|
| 1062 | client->id ); |
|---|
| 1063 | }; |
|---|
| 1064 | |
|---|
| 1065 | /* Check if 2.5V and 5V inputs are reconfigured */ |
|---|
| 1066 | if( data->type == adt7463 ) { |
|---|
| 1067 | value = lm85_read_value(client, ADT7463_REG_CONFIG4); |
|---|
| 1068 | if( value & 0x01 ) { |
|---|
| 1069 | printk("lm85(%d): 2.5V input (in0) is SMBALERT. " |
|---|
| 1070 | "in0 not available.\n", client->id ); |
|---|
| 1071 | }; |
|---|
| 1072 | if( value & 0x02 ) { |
|---|
| 1073 | printk("lm85(%d): 5V input (in3) is THERM. " |
|---|
| 1074 | "in3 not available.\n", client->id ); |
|---|
| 1075 | } |
|---|
| 1076 | }; |
|---|
| 1077 | |
|---|
| 1078 | /* FIXME? Display EMC6D100 config info? */ |
|---|
| 1079 | |
|---|
| 1080 | /* WE INTENTIONALLY make no changes to the limits, |
|---|
| 1081 | * offsets, pwms, fans and zones. If they were |
|---|
| 1082 | * configured, we don't want to mess with them. |
|---|
| 1083 | * If they weren't, the default is 100% PWM, no |
|---|
| 1084 | * control and will suffice until 'sensors -s' |
|---|
| 1085 | * can be run by the user. |
|---|
| 1086 | */ |
|---|
| 1087 | |
|---|
| 1088 | /* Start monitoring */ |
|---|
| 1089 | value = lm85_read_value(client, LM85_REG_CONFIG); |
|---|
| 1090 | /* Try to clear LOCK, Set START, save everything else */ |
|---|
| 1091 | value = ((value & ~ 0x02) | 0x01) & 0xff ; |
|---|
| 1092 | #ifdef DEBUG |
|---|
| 1093 | printk("lm85(%d): Setting CONFIG to: 0x%02x\n", client->id, value ); |
|---|
| 1094 | #endif |
|---|
| 1095 | lm85_write_value(client, LM85_REG_CONFIG, value); |
|---|
| 1096 | |
|---|
| 1097 | } |
|---|
| 1098 | |
|---|
| 1099 | static void lm85_update_client(struct i2c_client *client) |
|---|
| 1100 | { |
|---|
| 1101 | struct lm85_data *data = client->data; |
|---|
| 1102 | int i; |
|---|
| 1103 | |
|---|
| 1104 | down(&data->update_lock); |
|---|
| 1105 | |
|---|
| 1106 | if (!data->valid |
|---|
| 1107 | || (jiffies - data->last_reading > LM85_DATA_INTERVAL )) { |
|---|
| 1108 | /* Things that change quickly */ |
|---|
| 1109 | |
|---|
| 1110 | #ifdef DEBUG |
|---|
| 1111 | printk("lm85(%d): Reading sensor values\n", client->id); |
|---|
| 1112 | #endif |
|---|
| 1113 | /* Have to read extended bits first to "freeze" the |
|---|
| 1114 | * more significant bits that are read later. |
|---|
| 1115 | */ |
|---|
| 1116 | switch( data->type ) { |
|---|
| 1117 | case adm1027 : |
|---|
| 1118 | case adt7463 : |
|---|
| 1119 | data->extend_adc = |
|---|
| 1120 | lm85_read_value(client, ADM1027_REG_EXTEND_ADC); |
|---|
| 1121 | break ; |
|---|
| 1122 | default : |
|---|
| 1123 | break ; |
|---|
| 1124 | } |
|---|
| 1125 | |
|---|
| 1126 | for (i = 0; i <= 4; ++i) { |
|---|
| 1127 | data->in[i] = |
|---|
| 1128 | lm85_read_value(client, LM85_REG_IN(i)); |
|---|
| 1129 | } |
|---|
| 1130 | |
|---|
| 1131 | for (i = 0; i <= 3; ++i) { |
|---|
| 1132 | data->fan[i] = |
|---|
| 1133 | lm85_read_value(client, LM85_REG_FAN(i)); |
|---|
| 1134 | } |
|---|
| 1135 | |
|---|
| 1136 | for (i = 0; i <= 2; ++i) { |
|---|
| 1137 | data->temp[i] = |
|---|
| 1138 | lm85_read_value(client, LM85_REG_TEMP(i)); |
|---|
| 1139 | } |
|---|
| 1140 | |
|---|
| 1141 | for (i = 0; i <= 2; ++i) { |
|---|
| 1142 | data->pwm[i] = |
|---|
| 1143 | lm85_read_value(client, LM85_REG_PWM(i)); |
|---|
| 1144 | } |
|---|
| 1145 | |
|---|
| 1146 | data->alarms = lm85_read_value(client, LM85_REG_ALARM); |
|---|
| 1147 | |
|---|
| 1148 | switch( data->type ) { |
|---|
| 1149 | case adt7463 : |
|---|
| 1150 | /* REG_THERM code duplicated in therm_signal() */ |
|---|
| 1151 | i = lm85_read_value(client, ADT7463_REG_THERM); |
|---|
| 1152 | if( data->therm_total < LONG_MAX - 256 ) { |
|---|
| 1153 | data->therm_total += i ; |
|---|
| 1154 | } |
|---|
| 1155 | if( i >= 255 ) { |
|---|
| 1156 | ++data->therm_ovfl ; |
|---|
| 1157 | } |
|---|
| 1158 | break ; |
|---|
| 1159 | case emc6d100 : |
|---|
| 1160 | /* Three more voltage sensors */ |
|---|
| 1161 | for (i = 5; i <= 7; ++i) { |
|---|
| 1162 | data->in[i] = |
|---|
| 1163 | lm85_read_value(client, EMC6D100_REG_IN(i)); |
|---|
| 1164 | } |
|---|
| 1165 | /* More alarm bits */ |
|---|
| 1166 | data->alarms |= |
|---|
| 1167 | lm85_read_value(client, EMC6D100_REG_ALARM3) << 16; |
|---|
| 1168 | |
|---|
| 1169 | break ; |
|---|
| 1170 | case emc6d102 : |
|---|
| 1171 | /* Have to read LSB bits after the MSB ones because |
|---|
| 1172 | the reading of the MSB bits has frozen the |
|---|
| 1173 | LSBs (backward from the ADM1027). |
|---|
| 1174 | We use only two extra bits per channel, and encode |
|---|
| 1175 | them in the same format the ADM1027 uses, to keep the |
|---|
| 1176 | rest of the code unchanged. |
|---|
| 1177 | */ |
|---|
| 1178 | i = lm85_read_value(client, EMC6D102_REG_EXTEND_ADC1); |
|---|
| 1179 | data->extend_adc = (i & 0xcc) << 8; /* temp3, temp1 */ |
|---|
| 1180 | i = lm85_read_value(client, EMC6D102_REG_EXTEND_ADC2); |
|---|
| 1181 | data->extend_adc |= (i & 0x0c) << 10; /* temp2 */ |
|---|
| 1182 | data->extend_adc |= (i & 0xc0) << 2; /* in4 */ |
|---|
| 1183 | i = lm85_read_value(client, EMC6D102_REG_EXTEND_ADC3); |
|---|
| 1184 | data->extend_adc |= (i & 0x0c) >> 2; /* in0 */ |
|---|
| 1185 | data->extend_adc |= i & 0xc0; /* in3 */ |
|---|
| 1186 | i = lm85_read_value(client, EMC6D102_REG_EXTEND_ADC4); |
|---|
| 1187 | data->extend_adc |= i & 0x0c; /* in1 */ |
|---|
| 1188 | data->extend_adc |= (i & 0xc0) >> 2; /* in2 */ |
|---|
| 1189 | break; |
|---|
| 1190 | default : break ; /* no warnings */ |
|---|
| 1191 | } |
|---|
| 1192 | |
|---|
| 1193 | data->last_reading = jiffies ; |
|---|
| 1194 | }; /* last_reading */ |
|---|
| 1195 | |
|---|
| 1196 | if (!data->valid |
|---|
| 1197 | || (jiffies - data->last_config > LM85_CONFIG_INTERVAL) ) { |
|---|
| 1198 | /* Things that don't change often */ |
|---|
| 1199 | |
|---|
| 1200 | #ifdef DEBUG |
|---|
| 1201 | printk("lm85(%d): Reading config values\n", client->id); |
|---|
| 1202 | #endif |
|---|
| 1203 | for (i = 0; i <= 4; ++i) { |
|---|
| 1204 | data->in_min[i] = |
|---|
| 1205 | lm85_read_value(client, LM85_REG_IN_MIN(i)); |
|---|
| 1206 | data->in_max[i] = |
|---|
| 1207 | lm85_read_value(client, LM85_REG_IN_MAX(i)); |
|---|
| 1208 | } |
|---|
| 1209 | |
|---|
| 1210 | for (i = 0; i <= 3; ++i) { |
|---|
| 1211 | data->fan_min[i] = |
|---|
| 1212 | lm85_read_value(client, LM85_REG_FAN_MIN(i)); |
|---|
| 1213 | } |
|---|
| 1214 | |
|---|
| 1215 | for (i = 0; i <= 2; ++i) { |
|---|
| 1216 | data->temp_min[i] = |
|---|
| 1217 | lm85_read_value(client, LM85_REG_TEMP_MIN(i)); |
|---|
| 1218 | data->temp_max[i] = |
|---|
| 1219 | lm85_read_value(client, LM85_REG_TEMP_MAX(i)); |
|---|
| 1220 | } |
|---|
| 1221 | |
|---|
| 1222 | data->vid = lm85_read_value(client, LM85_REG_VID); |
|---|
| 1223 | |
|---|
| 1224 | for (i = 0; i <= 2; ++i) { |
|---|
| 1225 | int val ; |
|---|
| 1226 | data->autofan[i].config = |
|---|
| 1227 | lm85_read_value(client, LM85_REG_AFAN_CONFIG(i)); |
|---|
| 1228 | val = lm85_read_value(client, LM85_REG_AFAN_RANGE(i)); |
|---|
| 1229 | data->autofan[i].freq = val & 0x07 ; |
|---|
| 1230 | data->zone[i].range = (val >> 4) & 0x0f ; |
|---|
| 1231 | data->autofan[i].min_pwm = |
|---|
| 1232 | lm85_read_value(client, LM85_REG_AFAN_MINPWM(i)); |
|---|
| 1233 | data->zone[i].limit = |
|---|
| 1234 | lm85_read_value(client, LM85_REG_AFAN_LIMIT(i)); |
|---|
| 1235 | data->zone[i].critical = |
|---|
| 1236 | lm85_read_value(client, LM85_REG_AFAN_CRITICAL(i)); |
|---|
| 1237 | } |
|---|
| 1238 | |
|---|
| 1239 | i = lm85_read_value(client, LM85_REG_AFAN_SPIKE1); |
|---|
| 1240 | data->smooth[0] = i & 0x0f ; |
|---|
| 1241 | data->syncpwm3 = i & 0x10 ; /* Save PWM3 config */ |
|---|
| 1242 | data->autofan[0].min_off = i & 0x20 ; |
|---|
| 1243 | data->autofan[1].min_off = i & 0x40 ; |
|---|
| 1244 | data->autofan[2].min_off = i & 0x80 ; |
|---|
| 1245 | i = lm85_read_value(client, LM85_REG_AFAN_SPIKE2); |
|---|
| 1246 | data->smooth[1] = (i>>4) & 0x0f ; |
|---|
| 1247 | data->smooth[2] = i & 0x0f ; |
|---|
| 1248 | |
|---|
| 1249 | i = lm85_read_value(client, LM85_REG_AFAN_HYST1); |
|---|
| 1250 | data->zone[0].hyst = (i>>4) & 0x0f ; |
|---|
| 1251 | data->zone[1].hyst = i & 0x0f ; |
|---|
| 1252 | |
|---|
| 1253 | i = lm85_read_value(client, LM85_REG_AFAN_HYST2); |
|---|
| 1254 | data->zone[2].hyst = (i>>4) & 0x0f ; |
|---|
| 1255 | |
|---|
| 1256 | switch( data->type ) { |
|---|
| 1257 | case lm85b : |
|---|
| 1258 | case lm85c : |
|---|
| 1259 | data->tach_mode = lm85_read_value(client, |
|---|
| 1260 | LM85_REG_TACH_MODE ); |
|---|
| 1261 | data->spinup_ctl = lm85_read_value(client, |
|---|
| 1262 | LM85_REG_SPINUP_CTL ); |
|---|
| 1263 | break ; |
|---|
| 1264 | case adt7463 : |
|---|
| 1265 | for (i = 0; i <= 2; ++i) { |
|---|
| 1266 | data->oppoint[i] = lm85_read_value(client, |
|---|
| 1267 | ADT7463_REG_OPPOINT(i) ); |
|---|
| 1268 | } |
|---|
| 1269 | data->tmin_ctl = lm85_read_value(client, |
|---|
| 1270 | ADT7463_REG_TMIN_CTL ); |
|---|
| 1271 | data->therm_limit = lm85_read_value(client, |
|---|
| 1272 | ADT7463_REG_THERM_LIMIT ); |
|---|
| 1273 | /* FALL THROUGH */ |
|---|
| 1274 | case adm1027 : |
|---|
| 1275 | for (i = 0; i <= 2; ++i) { |
|---|
| 1276 | data->temp_offset[i] = lm85_read_value(client, |
|---|
| 1277 | ADM1027_REG_TEMP_OFFSET(i) ); |
|---|
| 1278 | } |
|---|
| 1279 | data->tach_mode = lm85_read_value(client, |
|---|
| 1280 | ADM1027_REG_CONFIG3 ); |
|---|
| 1281 | data->fan_ppr = lm85_read_value(client, |
|---|
| 1282 | ADM1027_REG_FAN_PPR ); |
|---|
| 1283 | data->alarm_mask = lm85_read_value(client, |
|---|
| 1284 | ADM1027_REG_INTMASK ); |
|---|
| 1285 | break ; |
|---|
| 1286 | case emc6d100 : |
|---|
| 1287 | for (i = 5; i <= 7; ++i) { |
|---|
| 1288 | data->in_min[i] = |
|---|
| 1289 | lm85_read_value(client, EMC6D100_REG_IN_MIN(i)); |
|---|
| 1290 | data->in_max[i] = |
|---|
| 1291 | lm85_read_value(client, EMC6D100_REG_IN_MAX(i)); |
|---|
| 1292 | } |
|---|
| 1293 | break ; |
|---|
| 1294 | default : break ; /* no warnings */ |
|---|
| 1295 | } |
|---|
| 1296 | |
|---|
| 1297 | data->last_config = jiffies; |
|---|
| 1298 | }; /* last_config */ |
|---|
| 1299 | |
|---|
| 1300 | data->valid = 1; |
|---|
| 1301 | |
|---|
| 1302 | up(&data->update_lock); |
|---|
| 1303 | } |
|---|
| 1304 | |
|---|
| 1305 | |
|---|
| 1306 | /* The next functions are the call-back functions of the /proc/sys and |
|---|
| 1307 | sysctl files. Which function is used is defined in the ctl_table in |
|---|
| 1308 | the extra1 field. |
|---|
| 1309 | Each function must return the magnitude (power of 10 to divide the data |
|---|
| 1310 | with) if it is called with operation==SENSORS_PROC_REAL_INFO. It must |
|---|
| 1311 | put a maximum of *nrels elements in results reflecting the data of this |
|---|
| 1312 | file, and set *nrels to the number it actually put in it, if operation== |
|---|
| 1313 | SENSORS_PROC_REAL_READ. Finally, it must get upto *nrels elements from |
|---|
| 1314 | results and write them to the chip, if operations==SENSORS_PROC_REAL_WRITE. |
|---|
| 1315 | */ |
|---|
| 1316 | void lm85_in(struct i2c_client *client, int operation, int ctl_name, |
|---|
| 1317 | int *nrels_mag, long *results) |
|---|
| 1318 | { |
|---|
| 1319 | struct lm85_data *data = client->data; |
|---|
| 1320 | int nr = ctl_name - LM85_SYSCTL_IN0; |
|---|
| 1321 | |
|---|
| 1322 | if (nr < 0 || nr > 4) |
|---|
| 1323 | return ; /* ERROR */ |
|---|
| 1324 | |
|---|
| 1325 | if (operation == SENSORS_PROC_REAL_INFO) |
|---|
| 1326 | *nrels_mag = 3; /* 1.000 */ |
|---|
| 1327 | else if (operation == SENSORS_PROC_REAL_READ) { |
|---|
| 1328 | int ext; |
|---|
| 1329 | lm85_update_client(client); |
|---|
| 1330 | ext = EXT_FROM_REG(data->extend_adc, nr); |
|---|
| 1331 | results[0] = INS_FROM_REG(nr,data->in_min[nr]); |
|---|
| 1332 | results[1] = INS_FROM_REG(nr,data->in_max[nr]); |
|---|
| 1333 | results[2] = INSEXT_FROM_REG(nr,data->in[nr],ext); |
|---|
| 1334 | *nrels_mag = 3; |
|---|
| 1335 | } else if (operation == SENSORS_PROC_REAL_WRITE) { |
|---|
| 1336 | down(&data->update_lock); |
|---|
| 1337 | if (*nrels_mag > 1) { |
|---|
| 1338 | data->in_max[nr] = INS_TO_REG(nr,results[1]); |
|---|
| 1339 | lm85_write_value(client, LM85_REG_IN_MAX(nr), |
|---|
| 1340 | data->in_max[nr]); |
|---|
| 1341 | } |
|---|
| 1342 | if (*nrels_mag > 0) { |
|---|
| 1343 | data->in_min[nr] = INS_TO_REG(nr,results[0]); |
|---|
| 1344 | lm85_write_value(client, LM85_REG_IN_MIN(nr), |
|---|
| 1345 | data->in_min[nr]); |
|---|
| 1346 | } |
|---|
| 1347 | up(&data->update_lock); |
|---|
| 1348 | } |
|---|
| 1349 | } |
|---|
| 1350 | |
|---|
| 1351 | void lm85_fan(struct i2c_client *client, int operation, int ctl_name, |
|---|
| 1352 | int *nrels_mag, long *results) |
|---|
| 1353 | { |
|---|
| 1354 | struct lm85_data *data = client->data; |
|---|
| 1355 | int nr = ctl_name - LM85_SYSCTL_FAN1 ; |
|---|
| 1356 | |
|---|
| 1357 | if (nr < 0 || nr > 3) |
|---|
| 1358 | return ; /* ERROR */ |
|---|
| 1359 | |
|---|
| 1360 | if (operation == SENSORS_PROC_REAL_INFO) |
|---|
| 1361 | *nrels_mag = 0; |
|---|
| 1362 | else if (operation == SENSORS_PROC_REAL_READ) { |
|---|
| 1363 | lm85_update_client(client); |
|---|
| 1364 | results[0] = FAN_FROM_REG(data->fan_min[nr]); |
|---|
| 1365 | results[1] = FAN_FROM_REG(data->fan[nr]); |
|---|
| 1366 | *nrels_mag = 2; |
|---|
| 1367 | } else if (operation == SENSORS_PROC_REAL_WRITE) { |
|---|
| 1368 | down(&data->update_lock); |
|---|
| 1369 | if (*nrels_mag > 0) { |
|---|
| 1370 | data->fan_min[nr] = FAN_TO_REG(results[0]); |
|---|
| 1371 | lm85_write_value(client, LM85_REG_FAN_MIN(nr), |
|---|
| 1372 | data->fan_min[nr]); |
|---|
| 1373 | } |
|---|
| 1374 | up(&data->update_lock); |
|---|
| 1375 | } |
|---|
| 1376 | } |
|---|
| 1377 | |
|---|
| 1378 | |
|---|
| 1379 | void lm85_temp(struct i2c_client *client, int operation, int ctl_name, |
|---|
| 1380 | int *nrels_mag, long *results) |
|---|
| 1381 | { |
|---|
| 1382 | struct lm85_data *data = client->data; |
|---|
| 1383 | int nr = ctl_name - LM85_SYSCTL_TEMP1 ; |
|---|
| 1384 | |
|---|
| 1385 | if (nr < 0 || nr > 2) |
|---|
| 1386 | return ; /* ERROR */ |
|---|
| 1387 | |
|---|
| 1388 | if (operation == SENSORS_PROC_REAL_INFO) |
|---|
| 1389 | *nrels_mag = 2; |
|---|
| 1390 | else if (operation == SENSORS_PROC_REAL_READ) { |
|---|
| 1391 | int ext; |
|---|
| 1392 | lm85_update_client(client); |
|---|
| 1393 | |
|---|
| 1394 | /* +5 for offset of temp data in ext reg */ |
|---|
| 1395 | ext = EXT_FROM_REG(data->extend_adc, nr+5); |
|---|
| 1396 | |
|---|
| 1397 | results[0] = TEMP_FROM_REG(data->temp_min[nr]); |
|---|
| 1398 | results[1] = TEMP_FROM_REG(data->temp_max[nr]); |
|---|
| 1399 | results[2] = TEMPEXT_FROM_REG(data->temp[nr],ext); |
|---|
| 1400 | *nrels_mag = 3; |
|---|
| 1401 | } else if (operation == SENSORS_PROC_REAL_WRITE) { |
|---|
| 1402 | down(&data->update_lock); |
|---|
| 1403 | if (*nrels_mag > 1) { |
|---|
| 1404 | data->temp_max[nr] = TEMP_TO_REG(results[1]); |
|---|
| 1405 | lm85_write_value(client, LM85_REG_TEMP_MAX(nr), |
|---|
| 1406 | data->temp_max[nr]); |
|---|
| 1407 | } |
|---|
| 1408 | if (*nrels_mag > 0) { |
|---|
| 1409 | data->temp_min[nr] = TEMP_TO_REG(results[0]); |
|---|
| 1410 | lm85_write_value(client, LM85_REG_TEMP_MIN(nr), |
|---|
| 1411 | data->temp_min[nr]); |
|---|
| 1412 | } |
|---|
| 1413 | up(&data->update_lock); |
|---|
| 1414 | } |
|---|
| 1415 | } |
|---|
| 1416 | |
|---|
| 1417 | void lm85_pwm(struct i2c_client *client, int operation, int ctl_name, |
|---|
| 1418 | int *nrels_mag, long *results) |
|---|
| 1419 | { |
|---|
| 1420 | struct lm85_data *data = client->data; |
|---|
| 1421 | int nr = ctl_name - LM85_SYSCTL_PWM1 ; |
|---|
| 1422 | int pwm_zone ; |
|---|
| 1423 | |
|---|
| 1424 | if (nr < 0 || nr > 2) |
|---|
| 1425 | return ; /* ERROR */ |
|---|
| 1426 | |
|---|
| 1427 | if (operation == SENSORS_PROC_REAL_INFO) |
|---|
| 1428 | *nrels_mag = 0; |
|---|
| 1429 | else if (operation == SENSORS_PROC_REAL_READ) { |
|---|
| 1430 | lm85_update_client(client); |
|---|
| 1431 | results[0] = PWM_FROM_REG(data->pwm[nr]); |
|---|
| 1432 | pwm_zone = ZONE_FROM_REG(data->autofan[nr].config); |
|---|
| 1433 | /* PWM "enabled" if not off (0) nor on (-1) */ |
|---|
| 1434 | results[1] = pwm_zone != 0 && pwm_zone != -1 ; |
|---|
| 1435 | *nrels_mag = 2; |
|---|
| 1436 | } else if (operation == SENSORS_PROC_REAL_WRITE) { |
|---|
| 1437 | down(&data->update_lock); |
|---|
| 1438 | /* PWM enable is read-only */ |
|---|
| 1439 | if (*nrels_mag > 0) { |
|---|
| 1440 | data->pwm[nr] = PWM_TO_REG(results[0]); |
|---|
| 1441 | lm85_write_value(client, LM85_REG_PWM(nr), |
|---|
| 1442 | data->pwm[nr]); |
|---|
| 1443 | } |
|---|
| 1444 | up(&data->update_lock); |
|---|
| 1445 | } |
|---|
| 1446 | } |
|---|
| 1447 | |
|---|
| 1448 | void lm85_vid(struct i2c_client *client, int operation, int ctl_name, |
|---|
| 1449 | int *nrels_mag, long *results) |
|---|
| 1450 | { |
|---|
| 1451 | struct lm85_data *data = client->data; |
|---|
| 1452 | |
|---|
| 1453 | if( ctl_name != LM85_SYSCTL_VID ) |
|---|
| 1454 | return ; /* ERROR */ |
|---|
| 1455 | |
|---|
| 1456 | if (operation == SENSORS_PROC_REAL_INFO) |
|---|
| 1457 | *nrels_mag = 3; |
|---|
| 1458 | else if (operation == SENSORS_PROC_REAL_READ) { |
|---|
| 1459 | lm85_update_client(client); |
|---|
| 1460 | results[0] = vid_from_reg((data->vid)&0x3f, data->vrm); |
|---|
| 1461 | *nrels_mag = 1; |
|---|
| 1462 | } |
|---|
| 1463 | } |
|---|
| 1464 | |
|---|
| 1465 | void lm85_vrm(struct i2c_client *client, int operation, int ctl_name, |
|---|
| 1466 | int *nrels_mag, long *results) |
|---|
| 1467 | { |
|---|
| 1468 | struct lm85_data *data = client->data; |
|---|
| 1469 | |
|---|
| 1470 | if( ctl_name != LM85_SYSCTL_VRM ) |
|---|
| 1471 | return ; /* ERROR */ |
|---|
| 1472 | |
|---|
| 1473 | if (operation == SENSORS_PROC_REAL_INFO) |
|---|
| 1474 | *nrels_mag = 1; |
|---|
| 1475 | else if (operation == SENSORS_PROC_REAL_READ) { |
|---|
| 1476 | results[0] = data->vrm ; |
|---|
| 1477 | *nrels_mag = 1; |
|---|
| 1478 | } else if (operation == SENSORS_PROC_REAL_WRITE) { |
|---|
| 1479 | down(&data->update_lock); |
|---|
| 1480 | if (*nrels_mag > 0) { |
|---|
| 1481 | data->vrm = results[0] ; |
|---|
| 1482 | } |
|---|
| 1483 | up(&data->update_lock); |
|---|
| 1484 | } |
|---|
| 1485 | } |
|---|
| 1486 | |
|---|
| 1487 | void lm85_alarms(struct i2c_client *client, int operation, int ctl_name, |
|---|
| 1488 | int *nrels_mag, long *results) |
|---|
| 1489 | { |
|---|
| 1490 | struct lm85_data *data = client->data; |
|---|
| 1491 | |
|---|
| 1492 | if( ctl_name != LM85_SYSCTL_ALARMS ) |
|---|
| 1493 | return ; /* ERROR */ |
|---|
| 1494 | |
|---|
| 1495 | if (operation == SENSORS_PROC_REAL_INFO) |
|---|
| 1496 | *nrels_mag = 0; |
|---|
| 1497 | else if (operation == SENSORS_PROC_REAL_READ) { |
|---|
| 1498 | lm85_update_client(client); |
|---|
| 1499 | results[0] = data->alarms; |
|---|
| 1500 | *nrels_mag = 1; |
|---|
| 1501 | } |
|---|
| 1502 | } |
|---|
| 1503 | |
|---|
| 1504 | void lm85_spinup_ctl(struct i2c_client *client, int operation, int ctl_name, |
|---|
| 1505 | int *nrels_mag, long *results) |
|---|
| 1506 | { |
|---|
| 1507 | struct lm85_data *data = client->data; |
|---|
| 1508 | int old; |
|---|
| 1509 | |
|---|
| 1510 | if( ctl_name != LM85_SYSCTL_SPINUP_CTL ) |
|---|
| 1511 | return ; /* ERROR */ |
|---|
| 1512 | |
|---|
| 1513 | if (operation == SENSORS_PROC_REAL_INFO) |
|---|
| 1514 | *nrels_mag = 0; |
|---|
| 1515 | else if (operation == SENSORS_PROC_REAL_READ) { |
|---|
| 1516 | lm85_update_client(client); |
|---|
| 1517 | results[0] = (data->spinup_ctl & 1) != 0 ; |
|---|
| 1518 | results[1] = (data->spinup_ctl & 2) != 0 ; |
|---|
| 1519 | results[2] = (data->spinup_ctl & 4) != 0 ; |
|---|
| 1520 | *nrels_mag = 3; |
|---|
| 1521 | } else if (operation == SENSORS_PROC_REAL_WRITE) { |
|---|
| 1522 | down(&data->update_lock); |
|---|
| 1523 | old = data->spinup_ctl ; |
|---|
| 1524 | if (*nrels_mag > 2) { |
|---|
| 1525 | old = (old & (~4)) | (results[2]?4:0) ; |
|---|
| 1526 | } |
|---|
| 1527 | if (*nrels_mag > 1) { |
|---|
| 1528 | old = (old & (~2)) | (results[1]?2:0) ; |
|---|
| 1529 | } |
|---|
| 1530 | if (*nrels_mag > 0) { |
|---|
| 1531 | old = (old & (~1)) | (results[0]?1:0) ; |
|---|
| 1532 | lm85_write_value(client, LM85_REG_SPINUP_CTL, old); |
|---|
| 1533 | data->spinup_ctl = old ; |
|---|
| 1534 | } |
|---|
| 1535 | up(&data->update_lock); |
|---|
| 1536 | } |
|---|
| 1537 | } |
|---|
| 1538 | |
|---|
| 1539 | void lm85_tach_mode(struct i2c_client *client, int operation, int ctl_name, |
|---|
| 1540 | int *nrels_mag, long *results) |
|---|
| 1541 | { |
|---|
| 1542 | struct lm85_data *data = client->data; |
|---|
| 1543 | int old; |
|---|
| 1544 | |
|---|
| 1545 | /* Tach Mode 1, Tach Mode 2, Tach Mode 3 & 4 */ |
|---|
| 1546 | |
|---|
| 1547 | if( ctl_name != LM85_SYSCTL_TACH_MODE ) |
|---|
| 1548 | return ; /* ERROR */ |
|---|
| 1549 | |
|---|
| 1550 | if (operation == SENSORS_PROC_REAL_INFO) |
|---|
| 1551 | *nrels_mag = 0; |
|---|
| 1552 | else if (operation == SENSORS_PROC_REAL_READ) { |
|---|
| 1553 | lm85_update_client(client); |
|---|
| 1554 | results[0] = (data->tach_mode & 0x03) ; |
|---|
| 1555 | results[1] = (data->tach_mode & 0x0c) >> 2 ; |
|---|
| 1556 | results[2] = (data->tach_mode & 0x30) >> 4 ; |
|---|
| 1557 | *nrels_mag = 3; |
|---|
| 1558 | } else if (operation == SENSORS_PROC_REAL_WRITE) { |
|---|
| 1559 | down(&data->update_lock); |
|---|
| 1560 | old = data->tach_mode ; |
|---|
| 1561 | if (*nrels_mag > 2) { |
|---|
| 1562 | old = (old & (~0x30)) | ((results[2]&3) << 4) ; |
|---|
| 1563 | } |
|---|
| 1564 | if (*nrels_mag > 1) { |
|---|
| 1565 | old = (old & (~0x0c)) | ((results[1]&3) << 2) ; |
|---|
| 1566 | } |
|---|
| 1567 | if (*nrels_mag > 0) { |
|---|
| 1568 | old = (old & (~0x03)) | (results[0]&3) ; |
|---|
| 1569 | lm85_write_value(client, LM85_REG_TACH_MODE, old); |
|---|
| 1570 | data->tach_mode = old ; |
|---|
| 1571 | } |
|---|
| 1572 | up(&data->update_lock); |
|---|
| 1573 | } |
|---|
| 1574 | } |
|---|
| 1575 | |
|---|
| 1576 | void adm1027_tach_mode(struct i2c_client *client, int operation, int ctl_name, |
|---|
| 1577 | int *nrels_mag, long *results) |
|---|
| 1578 | { |
|---|
| 1579 | struct lm85_data *data = client->data; |
|---|
| 1580 | int old; |
|---|
| 1581 | |
|---|
| 1582 | /* Tach/DC 1, Tach/DC 2, Tach/DC 3, Tach/DC 4 */ |
|---|
| 1583 | |
|---|
| 1584 | if( ctl_name != ADM1027_SYSCTL_TACH_MODE ) |
|---|
| 1585 | return ; /* ERROR */ |
|---|
| 1586 | |
|---|
| 1587 | if (operation == SENSORS_PROC_REAL_INFO) |
|---|
| 1588 | *nrels_mag = 0; |
|---|
| 1589 | else if (operation == SENSORS_PROC_REAL_READ) { |
|---|
| 1590 | lm85_update_client(client); |
|---|
| 1591 | results[0] = (data->tach_mode & 0x10) != 0 ; |
|---|
| 1592 | results[1] = (data->tach_mode & 0x20) != 0 ; |
|---|
| 1593 | results[2] = (data->tach_mode & 0x40) != 0 ; |
|---|
| 1594 | results[3] = (data->tach_mode & 0x80) != 0 ; |
|---|
| 1595 | *nrels_mag = 4; |
|---|
| 1596 | } else if (operation == SENSORS_PROC_REAL_WRITE) { |
|---|
| 1597 | down(&data->update_lock); |
|---|
| 1598 | old = data->tach_mode ; |
|---|
| 1599 | if (*nrels_mag > 3) { |
|---|
| 1600 | old = (old & (~0x80)) | (results[3] ? 0x80 : 0) ; |
|---|
| 1601 | } |
|---|
| 1602 | if (*nrels_mag > 2) { |
|---|
| 1603 | old = (old & (~0x40)) | (results[2] ? 0x40 : 0) ; |
|---|
| 1604 | } |
|---|
| 1605 | if (*nrels_mag > 1) { |
|---|
| 1606 | old = (old & (~0x20)) | (results[1] ? 0x20 : 0) ; |
|---|
| 1607 | } |
|---|
| 1608 | if (*nrels_mag > 0) { |
|---|
| 1609 | old = (old & (~0x10)) | (results[0] ? 0x10 : 0) ; |
|---|
| 1610 | |
|---|
| 1611 | /* Enable fast measurements if any TACH's are DC */ |
|---|
| 1612 | old = (old & (~0x08)) | ((old&0xf0) ? 0x08 : 0) ; |
|---|
| 1613 | |
|---|
| 1614 | lm85_write_value(client, ADM1027_REG_CONFIG3, old); |
|---|
| 1615 | data->tach_mode = old ; |
|---|
| 1616 | } |
|---|
| 1617 | up(&data->update_lock); |
|---|
| 1618 | } |
|---|
| 1619 | } |
|---|
| 1620 | |
|---|
| 1621 | void lm85_pwm_config(struct i2c_client *client, int operation, int ctl_name, |
|---|
| 1622 | int *nrels_mag, long *results) |
|---|
| 1623 | { |
|---|
| 1624 | struct lm85_data *data = client->data; |
|---|
| 1625 | int nr = ctl_name - LM85_SYSCTL_PWM_CFG1 ; |
|---|
| 1626 | |
|---|
| 1627 | /* Spinup, min PWM, PWM Frequency, min below limit, Invert */ |
|---|
| 1628 | |
|---|
| 1629 | if (nr < 0 || nr > 2) |
|---|
| 1630 | return ; /* ERROR */ |
|---|
| 1631 | |
|---|
| 1632 | if (operation == SENSORS_PROC_REAL_INFO) |
|---|
| 1633 | *nrels_mag = 1; |
|---|
| 1634 | else if (operation == SENSORS_PROC_REAL_READ) { |
|---|
| 1635 | lm85_update_client(client); |
|---|
| 1636 | |
|---|
| 1637 | results[0] = SPINUP_FROM_REG(data->autofan[nr].config); |
|---|
| 1638 | results[1] = PWM_FROM_REG(data->autofan[nr].min_pwm)*10; |
|---|
| 1639 | results[2] = FREQ_FROM_REG(data->autofan[nr].freq); |
|---|
| 1640 | results[3] = data->autofan[nr].min_off ? 10 : 0 ; |
|---|
| 1641 | results[4] = (data->autofan[nr].config & 0x10) ? 10 : 0 ; |
|---|
| 1642 | *nrels_mag = 5; |
|---|
| 1643 | } else if (operation == SENSORS_PROC_REAL_WRITE) { |
|---|
| 1644 | int old_config ; |
|---|
| 1645 | |
|---|
| 1646 | down(&data->update_lock); |
|---|
| 1647 | old_config = data->autofan[nr].config ; |
|---|
| 1648 | if (*nrels_mag > 4) { |
|---|
| 1649 | old_config = (old_config & (~0x10)) | (results[4]?0x10:0) ; |
|---|
| 1650 | } |
|---|
| 1651 | if (*nrels_mag > 3) { |
|---|
| 1652 | data->autofan[nr].min_off = results[3] != 0 ; |
|---|
| 1653 | lm85_write_value(client, LM85_REG_AFAN_SPIKE1, |
|---|
| 1654 | data->smooth[0] |
|---|
| 1655 | | data->syncpwm3 |
|---|
| 1656 | | (data->autofan[0].min_off ? 0x20 : 0) |
|---|
| 1657 | | (data->autofan[1].min_off ? 0x40 : 0) |
|---|
| 1658 | | (data->autofan[2].min_off ? 0x80 : 0) |
|---|
| 1659 | ); |
|---|
| 1660 | } |
|---|
| 1661 | if (*nrels_mag > 2) { |
|---|
| 1662 | data->autofan[nr].freq = FREQ_TO_REG(results[2]) ; |
|---|
| 1663 | lm85_write_value(client, LM85_REG_AFAN_RANGE(nr), |
|---|
| 1664 | (data->zone[nr].range << 4) |
|---|
| 1665 | | data->autofan[nr].freq |
|---|
| 1666 | ); |
|---|
| 1667 | } |
|---|
| 1668 | if (*nrels_mag > 1) { |
|---|
| 1669 | data->autofan[nr].min_pwm = PWM_TO_REG((results[1]+5)/10); |
|---|
| 1670 | lm85_write_value(client, LM85_REG_AFAN_MINPWM(nr), |
|---|
| 1671 | data->autofan[nr].min_pwm |
|---|
| 1672 | ); |
|---|
| 1673 | } |
|---|
| 1674 | if (*nrels_mag > 0) { |
|---|
| 1675 | old_config = (old_config & (~0x07)) | SPINUP_TO_REG(results[0]) ; |
|---|
| 1676 | lm85_write_value(client, LM85_REG_AFAN_CONFIG(nr), old_config); |
|---|
| 1677 | data->autofan[nr].config = old_config ; |
|---|
| 1678 | } |
|---|
| 1679 | up(&data->update_lock); |
|---|
| 1680 | } |
|---|
| 1681 | } |
|---|
| 1682 | |
|---|
| 1683 | void lm85_smooth(struct i2c_client *client, int operation, int ctl_name, |
|---|
| 1684 | int *nrels_mag, long *results) |
|---|
| 1685 | { |
|---|
| 1686 | struct lm85_data *data = client->data; |
|---|
| 1687 | int nr = ctl_name - LM85_SYSCTL_SMOOTH1 ; |
|---|
| 1688 | |
|---|
| 1689 | if (nr < 0 || nr > 2) |
|---|
| 1690 | return ; /* ERROR */ |
|---|
| 1691 | |
|---|
| 1692 | if (operation == SENSORS_PROC_REAL_INFO) |
|---|
| 1693 | *nrels_mag = 1; |
|---|
| 1694 | else if (operation == SENSORS_PROC_REAL_READ) { |
|---|
| 1695 | lm85_update_client(client); |
|---|
| 1696 | results[0] = SMOOTH_FROM_REG(data->smooth[nr]); |
|---|
| 1697 | *nrels_mag = 1; |
|---|
| 1698 | |
|---|
| 1699 | } else if (operation == SENSORS_PROC_REAL_WRITE) { |
|---|
| 1700 | down(&data->update_lock); |
|---|
| 1701 | if( *nrels_mag > 0 ) { |
|---|
| 1702 | data->smooth[nr] = SMOOTH_TO_REG(results[0]); |
|---|
| 1703 | } |
|---|
| 1704 | if( nr == 0 ) { |
|---|
| 1705 | lm85_write_value(client, LM85_REG_AFAN_SPIKE1, |
|---|
| 1706 | data->smooth[0] |
|---|
| 1707 | | data->syncpwm3 |
|---|
| 1708 | | (data->autofan[0].min_off ? 0x20 : 0) |
|---|
| 1709 | | (data->autofan[1].min_off ? 0x40 : 0) |
|---|
| 1710 | | (data->autofan[2].min_off ? 0x80 : 0) |
|---|
| 1711 | ); |
|---|
| 1712 | } else { |
|---|
| 1713 | lm85_write_value(client, LM85_REG_AFAN_SPIKE2, |
|---|
| 1714 | (data->smooth[1] << 4) | data->smooth[2]); |
|---|
| 1715 | } |
|---|
| 1716 | up(&data->update_lock); |
|---|
| 1717 | } |
|---|
| 1718 | } |
|---|
| 1719 | |
|---|
| 1720 | void lm85_zone(struct i2c_client *client, int operation, int ctl_name, |
|---|
| 1721 | int *nrels_mag, long *results) |
|---|
| 1722 | { |
|---|
| 1723 | struct lm85_data *data = client->data; |
|---|
| 1724 | int nr = ctl_name - LM85_SYSCTL_ZONE1 ; |
|---|
| 1725 | |
|---|
| 1726 | /* Limit, Hysteresis (neg), Range, Critical */ |
|---|
| 1727 | |
|---|
| 1728 | if (nr < 0 || nr > 2) |
|---|
| 1729 | return ; /* ERROR */ |
|---|
| 1730 | |
|---|
| 1731 | if (operation == SENSORS_PROC_REAL_INFO) |
|---|
| 1732 | *nrels_mag = 1; |
|---|
| 1733 | else if (operation == SENSORS_PROC_REAL_READ) { |
|---|
| 1734 | lm85_update_client(client); |
|---|
| 1735 | |
|---|
| 1736 | results[0] = TEMP_FROM_REG(data->zone[nr].limit) / 10; |
|---|
| 1737 | results[1] = HYST_FROM_REG(data->zone[nr].hyst); |
|---|
| 1738 | results[2] = RANGE_FROM_REG(data->zone[nr].range); |
|---|
| 1739 | results[3] = TEMP_FROM_REG(data->zone[nr].critical) / 10; |
|---|
| 1740 | *nrels_mag = 4; |
|---|
| 1741 | |
|---|
| 1742 | } else if (operation == SENSORS_PROC_REAL_WRITE) { |
|---|
| 1743 | down(&data->update_lock); |
|---|
| 1744 | if (*nrels_mag > 3) { |
|---|
| 1745 | data->zone[nr].critical = TEMP_TO_REG(results[3]*10); |
|---|
| 1746 | lm85_write_value(client, LM85_REG_AFAN_CRITICAL(nr), |
|---|
| 1747 | data->zone[nr].critical ); |
|---|
| 1748 | } |
|---|
| 1749 | if (*nrels_mag > 2) { |
|---|
| 1750 | data->zone[nr].range = RANGE_TO_REG(results[2]); |
|---|
| 1751 | lm85_write_value(client, LM85_REG_AFAN_RANGE(nr), |
|---|
| 1752 | (data->zone[nr].range << 4) |
|---|
| 1753 | | data->autofan[nr].freq |
|---|
| 1754 | ); |
|---|
| 1755 | } |
|---|
| 1756 | if (*nrels_mag > 1) { |
|---|
| 1757 | data->zone[nr].hyst = HYST_TO_REG(results[1]); |
|---|
| 1758 | if( nr == 0 || nr == 1 ) { |
|---|
| 1759 | lm85_write_value(client, LM85_REG_AFAN_HYST1, |
|---|
| 1760 | (data->zone[0].hyst << 4) |
|---|
| 1761 | | data->zone[1].hyst |
|---|
| 1762 | ); |
|---|
| 1763 | } else { |
|---|
| 1764 | lm85_write_value(client, LM85_REG_AFAN_HYST2, |
|---|
| 1765 | (data->zone[2].hyst << 4) |
|---|
| 1766 | ); |
|---|
| 1767 | } |
|---|
| 1768 | } |
|---|
| 1769 | if (*nrels_mag > 0) { |
|---|
| 1770 | data->zone[nr].limit = TEMP_TO_REG(results[0]*10); |
|---|
| 1771 | lm85_write_value(client, LM85_REG_AFAN_LIMIT(nr), |
|---|
| 1772 | data->zone[nr].limit |
|---|
| 1773 | ); |
|---|
| 1774 | } |
|---|
| 1775 | up(&data->update_lock); |
|---|
| 1776 | } |
|---|
| 1777 | } |
|---|
| 1778 | |
|---|
| 1779 | void lm85_pwm_zone(struct i2c_client *client, int operation, int ctl_name, |
|---|
| 1780 | int *nrels_mag, long *results) |
|---|
| 1781 | { |
|---|
| 1782 | struct lm85_data *data = client->data; |
|---|
| 1783 | int nr = ctl_name - LM85_SYSCTL_PWM_ZONE1 ; |
|---|
| 1784 | |
|---|
| 1785 | if (nr < 0 || nr > 2) |
|---|
| 1786 | return ; /* ERROR */ |
|---|
| 1787 | |
|---|
| 1788 | if (operation == SENSORS_PROC_REAL_INFO) |
|---|
| 1789 | *nrels_mag = 0; |
|---|
| 1790 | else if (operation == SENSORS_PROC_REAL_READ) { |
|---|
| 1791 | lm85_update_client(client); |
|---|
| 1792 | results[0] = ZONE_FROM_REG(data->autofan[nr].config); |
|---|
| 1793 | *nrels_mag = 1; |
|---|
| 1794 | } else if (operation == SENSORS_PROC_REAL_WRITE) { |
|---|
| 1795 | down(&data->update_lock); |
|---|
| 1796 | if (*nrels_mag > 0) { |
|---|
| 1797 | data->autofan[nr].config = |
|---|
| 1798 | (data->autofan[nr].config & (~0xe0)) |
|---|
| 1799 | | ZONE_TO_REG(results[0]) ; |
|---|
| 1800 | lm85_write_value(client, LM85_REG_AFAN_CONFIG(nr), |
|---|
| 1801 | data->autofan[nr].config); |
|---|
| 1802 | } |
|---|
| 1803 | up(&data->update_lock); |
|---|
| 1804 | } |
|---|
| 1805 | } |
|---|
| 1806 | |
|---|
| 1807 | void adm1027_temp_offset(struct i2c_client *client, int operation, int ctl_name, |
|---|
| 1808 | int *nrels_mag, long *results) |
|---|
| 1809 | { |
|---|
| 1810 | struct lm85_data *data = client->data; |
|---|
| 1811 | int nr = ctl_name - ADM1027_SYSCTL_TEMP_OFFSET1 ; |
|---|
| 1812 | |
|---|
| 1813 | if (nr < 0 || nr > 2) |
|---|
| 1814 | return ; /* ERROR */ |
|---|
| 1815 | |
|---|
| 1816 | if (operation == SENSORS_PROC_REAL_INFO) |
|---|
| 1817 | *nrels_mag = 2; |
|---|
| 1818 | else if (operation == SENSORS_PROC_REAL_READ) { |
|---|
| 1819 | lm85_update_client(client); |
|---|
| 1820 | switch( data->type ) { |
|---|
| 1821 | case adm1027 : |
|---|
| 1822 | default : |
|---|
| 1823 | results[0] = TEMP_FROM_REG(data->temp_offset[nr]); |
|---|
| 1824 | break ; |
|---|
| 1825 | case adt7463 : |
|---|
| 1826 | results[0] = TEMPEXT_FROM_REG(0,data->temp_offset[nr]); |
|---|
| 1827 | break ; |
|---|
| 1828 | } |
|---|
| 1829 | *nrels_mag = 1; |
|---|
| 1830 | } else if (operation == SENSORS_PROC_REAL_WRITE) { |
|---|
| 1831 | down(&data->update_lock); |
|---|
| 1832 | if (*nrels_mag > 0) { |
|---|
| 1833 | switch( data->type ) { |
|---|
| 1834 | case adm1027 : |
|---|
| 1835 | default : |
|---|
| 1836 | data->temp_offset[nr] = TEMP_TO_REG(results[0]); |
|---|
| 1837 | break ; |
|---|
| 1838 | case adt7463 : |
|---|
| 1839 | data->temp_offset[nr] = EXTTEMP_TO_REG(results[0]); |
|---|
| 1840 | break ; |
|---|
| 1841 | }; |
|---|
| 1842 | lm85_write_value(client, ADM1027_REG_TEMP_OFFSET(nr), |
|---|
| 1843 | data->temp_offset[nr]); |
|---|
| 1844 | } |
|---|
| 1845 | up(&data->update_lock); |
|---|
| 1846 | } |
|---|
| 1847 | } |
|---|
| 1848 | |
|---|
| 1849 | void adm1027_fan_ppr(struct i2c_client *client, int operation, int ctl_name, |
|---|
| 1850 | int *nrels_mag, long *results) |
|---|
| 1851 | { |
|---|
| 1852 | struct lm85_data *data = client->data; |
|---|
| 1853 | int old ; |
|---|
| 1854 | |
|---|
| 1855 | if (ctl_name != ADM1027_SYSCTL_FAN_PPR) |
|---|
| 1856 | return ; /* ERROR */ |
|---|
| 1857 | |
|---|
| 1858 | if (operation == SENSORS_PROC_REAL_INFO) |
|---|
| 1859 | *nrels_mag = 0; |
|---|
| 1860 | else if (operation == SENSORS_PROC_REAL_READ) { |
|---|
| 1861 | lm85_update_client(client); |
|---|
| 1862 | results[0] = PPR_FROM_REG(data->fan_ppr,0); |
|---|
| 1863 | results[1] = PPR_FROM_REG(data->fan_ppr,1); |
|---|
| 1864 | results[2] = PPR_FROM_REG(data->fan_ppr,2); |
|---|
| 1865 | results[3] = PPR_FROM_REG(data->fan_ppr,3); |
|---|
| 1866 | *nrels_mag = 4; |
|---|
| 1867 | } else if (operation == SENSORS_PROC_REAL_WRITE) { |
|---|
| 1868 | down(&data->update_lock); |
|---|
| 1869 | old = data->fan_ppr ; |
|---|
| 1870 | if (*nrels_mag > 3) { |
|---|
| 1871 | old = (old & ~PPR_MASK(3)) | PPR_TO_REG(results[3],3); |
|---|
| 1872 | }; |
|---|
| 1873 | if (*nrels_mag > 2) { |
|---|
| 1874 | old = (old & ~PPR_MASK(2)) | PPR_TO_REG(results[2],2); |
|---|
| 1875 | }; |
|---|
| 1876 | if (*nrels_mag > 1) { |
|---|
| 1877 | old = (old & ~PPR_MASK(1)) | PPR_TO_REG(results[1],1); |
|---|
| 1878 | }; |
|---|
| 1879 | if (*nrels_mag > 0) { |
|---|
| 1880 | old = (old & ~PPR_MASK(0)) | PPR_TO_REG(results[0],0); |
|---|
| 1881 | lm85_write_value(client, ADM1027_REG_FAN_PPR, old); |
|---|
| 1882 | data->fan_ppr = old ; |
|---|
| 1883 | } |
|---|
| 1884 | up(&data->update_lock); |
|---|
| 1885 | } |
|---|
| 1886 | } |
|---|
| 1887 | |
|---|
| 1888 | void adm1027_alarm_mask(struct i2c_client *client, int operation, |
|---|
| 1889 | int ctl_name, int *nrels_mag, long *results) |
|---|
| 1890 | { |
|---|
| 1891 | struct lm85_data *data = client->data; |
|---|
| 1892 | |
|---|
| 1893 | if( ctl_name != ADM1027_SYSCTL_ALARM_MASK ) |
|---|
| 1894 | return ; /* ERROR */ |
|---|
| 1895 | |
|---|
| 1896 | if (operation == SENSORS_PROC_REAL_INFO) |
|---|
| 1897 | *nrels_mag = 0; |
|---|
| 1898 | else if (operation == SENSORS_PROC_REAL_READ) { |
|---|
| 1899 | lm85_update_client(client); |
|---|
| 1900 | results[0] = INTMASK_FROM_REG(data->alarm_mask); |
|---|
| 1901 | *nrels_mag = 1; |
|---|
| 1902 | } else if (operation == SENSORS_PROC_REAL_WRITE) { |
|---|
| 1903 | down(&data->update_lock); |
|---|
| 1904 | if (*nrels_mag > 0) { |
|---|
| 1905 | data->alarm_mask = INTMASK_TO_REG(results[0]); |
|---|
| 1906 | lm85_write_value(client, ADM1027_REG_INTMASK, |
|---|
| 1907 | data->alarm_mask); |
|---|
| 1908 | } |
|---|
| 1909 | up(&data->update_lock); |
|---|
| 1910 | } |
|---|
| 1911 | } |
|---|
| 1912 | |
|---|
| 1913 | void adt7463_tmin_ctl(struct i2c_client *client, int operation, int ctl_name, |
|---|
| 1914 | int *nrels_mag, long *results) |
|---|
| 1915 | { |
|---|
| 1916 | struct lm85_data *data = client->data; |
|---|
| 1917 | int nr = ctl_name - ADT7463_SYSCTL_TMIN_CTL1 ; |
|---|
| 1918 | u16 old ; |
|---|
| 1919 | |
|---|
| 1920 | if (nr < 0 || nr > 2) |
|---|
| 1921 | return ; /* ERROR */ |
|---|
| 1922 | |
|---|
| 1923 | if (operation == SENSORS_PROC_REAL_INFO) |
|---|
| 1924 | *nrels_mag = 0; |
|---|
| 1925 | else if (operation == SENSORS_PROC_REAL_READ) { |
|---|
| 1926 | old = data->tmin_ctl ; |
|---|
| 1927 | results[0] = (old & ( 0x2000 << nr )) != 0 ; |
|---|
| 1928 | results[1] = (old >> (nr*3)) & 0x07 ; |
|---|
| 1929 | results[2] = (old & ( 0x0400 << nr )) != 0 ; |
|---|
| 1930 | results[3] = OPPOINT_FROM_REG(data->oppoint[nr]); |
|---|
| 1931 | *nrels_mag = 4; |
|---|
| 1932 | } else if (operation == SENSORS_PROC_REAL_WRITE) { |
|---|
| 1933 | down(&data->update_lock); |
|---|
| 1934 | old = data->tmin_ctl ; |
|---|
| 1935 | if (*nrels_mag > 3) { |
|---|
| 1936 | data->oppoint[nr] = OPPOINT_TO_REG(results[3]); |
|---|
| 1937 | lm85_write_value(client, ADT7463_REG_OPPOINT(nr), |
|---|
| 1938 | data->oppoint[nr]); |
|---|
| 1939 | }; |
|---|
| 1940 | if (*nrels_mag > 2) { |
|---|
| 1941 | if( results[2] ) { |
|---|
| 1942 | old |= (0x0400 << nr) ; |
|---|
| 1943 | } else { |
|---|
| 1944 | old &= ~(0x0400 << nr) ; |
|---|
| 1945 | } |
|---|
| 1946 | }; |
|---|
| 1947 | if (*nrels_mag > 1) { |
|---|
| 1948 | old &= ~(0x07 << (nr*3)) ; |
|---|
| 1949 | old |= (results[1] & 0x07) << (nr*3) ; |
|---|
| 1950 | }; |
|---|
| 1951 | if (*nrels_mag > 0) { |
|---|
| 1952 | if( results[0] ) { |
|---|
| 1953 | old |= 0x2000 << nr ; |
|---|
| 1954 | } else { |
|---|
| 1955 | old &= ~(0x2000 << nr) ; |
|---|
| 1956 | } |
|---|
| 1957 | lm85_write_value(client, ADT7463_REG_TMIN_CTL, old); |
|---|
| 1958 | data->tmin_ctl = old ; |
|---|
| 1959 | } |
|---|
| 1960 | up(&data->update_lock); |
|---|
| 1961 | } |
|---|
| 1962 | } |
|---|
| 1963 | |
|---|
| 1964 | void adt7463_therm_signal(struct i2c_client *client, int operation, |
|---|
| 1965 | int ctl_name, int *nrels_mag, long *results) |
|---|
| 1966 | { |
|---|
| 1967 | struct lm85_data *data = client->data; |
|---|
| 1968 | int counts ; |
|---|
| 1969 | |
|---|
| 1970 | if (ctl_name != ADT7463_SYSCTL_THERM_SIGNAL) |
|---|
| 1971 | return ; /* ERROR */ |
|---|
| 1972 | |
|---|
| 1973 | if (operation == SENSORS_PROC_REAL_INFO) |
|---|
| 1974 | *nrels_mag = 0; |
|---|
| 1975 | else if (operation == SENSORS_PROC_REAL_READ) { |
|---|
| 1976 | /* Don't call update_client here because |
|---|
| 1977 | * ADT7463_REG_THERM has to be read every |
|---|
| 1978 | * 5 seconds to prevent lost counts |
|---|
| 1979 | */ |
|---|
| 1980 | down(&data->update_lock); |
|---|
| 1981 | counts = lm85_read_value(client, ADT7463_REG_THERM) & 0xff; |
|---|
| 1982 | if( data->therm_total < LONG_MAX - 256 ) { |
|---|
| 1983 | data->therm_total += counts ; |
|---|
| 1984 | } |
|---|
| 1985 | if( counts >= 255 ) { |
|---|
| 1986 | ++data->therm_ovfl ; |
|---|
| 1987 | } |
|---|
| 1988 | up(&data->update_lock); |
|---|
| 1989 | |
|---|
| 1990 | results[0] = data->therm_limit ; |
|---|
| 1991 | results[1] = data->therm_total ; |
|---|
| 1992 | results[2] = data->therm_ovfl ; |
|---|
| 1993 | *nrels_mag = 3; |
|---|
| 1994 | } else if (operation == SENSORS_PROC_REAL_WRITE) { |
|---|
| 1995 | down(&data->update_lock); |
|---|
| 1996 | /* therm_total and therm_ovfl are read only */ |
|---|
| 1997 | if (*nrels_mag > 0) { |
|---|
| 1998 | data->therm_limit = SENSORS_LIMIT(results[0],0,255); |
|---|
| 1999 | lm85_write_value(client, ADT7463_REG_THERM_LIMIT, |
|---|
| 2000 | data->therm_limit); |
|---|
| 2001 | }; |
|---|
| 2002 | up(&data->update_lock); |
|---|
| 2003 | } |
|---|
| 2004 | } |
|---|
| 2005 | |
|---|
| 2006 | |
|---|
| 2007 | void emc6d100_in(struct i2c_client *client, int operation, int ctl_name, |
|---|
| 2008 | int *nrels_mag, long *results) |
|---|
| 2009 | { |
|---|
| 2010 | struct lm85_data *data = client->data; |
|---|
| 2011 | int nr = ctl_name - EMC6D100_SYSCTL_IN5 +5; |
|---|
| 2012 | |
|---|
| 2013 | if (nr < 5 || nr > 7) |
|---|
| 2014 | return ; /* ERROR */ |
|---|
| 2015 | |
|---|
| 2016 | if (operation == SENSORS_PROC_REAL_INFO) |
|---|
| 2017 | *nrels_mag = 3; /* 1.000 */ |
|---|
| 2018 | else if (operation == SENSORS_PROC_REAL_READ) { |
|---|
| 2019 | lm85_update_client(client); |
|---|
| 2020 | results[0] = INS_FROM_REG(nr,data->in_min[nr]); |
|---|
| 2021 | results[1] = INS_FROM_REG(nr,data->in_max[nr]); |
|---|
| 2022 | results[2] = INS_FROM_REG(nr,data->in[nr]); |
|---|
| 2023 | *nrels_mag = 3; |
|---|
| 2024 | } else if (operation == SENSORS_PROC_REAL_WRITE) { |
|---|
| 2025 | down(&data->update_lock); |
|---|
| 2026 | if (*nrels_mag > 1) { |
|---|
| 2027 | data->in_max[nr] = INS_TO_REG(nr,results[1]); |
|---|
| 2028 | lm85_write_value(client, EMC6D100_REG_IN_MAX(nr), |
|---|
| 2029 | data->in_max[nr]); |
|---|
| 2030 | } |
|---|
| 2031 | if (*nrels_mag > 0) { |
|---|
| 2032 | data->in_min[nr] = INS_TO_REG(nr,results[0]); |
|---|
| 2033 | lm85_write_value(client, EMC6D100_REG_IN_MIN(nr), |
|---|
| 2034 | data->in_min[nr]); |
|---|
| 2035 | } |
|---|
| 2036 | up(&data->update_lock); |
|---|
| 2037 | } |
|---|
| 2038 | } |
|---|
| 2039 | |
|---|
| 2040 | |
|---|
| 2041 | static int __init sm_lm85_init(void) |
|---|
| 2042 | { |
|---|
| 2043 | printk("lm85: Version %s (%s)\n", LM_VERSION, LM_DATE); |
|---|
| 2044 | return i2c_add_driver(&lm85_driver); |
|---|
| 2045 | } |
|---|
| 2046 | |
|---|
| 2047 | static void __exit sm_lm85_exit(void) |
|---|
| 2048 | { |
|---|
| 2049 | i2c_del_driver(&lm85_driver); |
|---|
| 2050 | } |
|---|
| 2051 | |
|---|
| 2052 | /* Thanks to Richard Barrington for adding the LM85 to sensors-detect. |
|---|
| 2053 | * Thanks to Margit Schubert-While <margitsw@t-online.de> for help with |
|---|
| 2054 | * post 2.7.0 CVS changes |
|---|
| 2055 | */ |
|---|
| 2056 | MODULE_LICENSE("GPL"); |
|---|
| 2057 | MODULE_AUTHOR("Philip Pokorny <ppokorny@penguincomputing.com"); |
|---|
| 2058 | MODULE_DESCRIPTION("LM85-B, LM85-C driver"); |
|---|
| 2059 | |
|---|
| 2060 | module_init(sm_lm85_init); |
|---|
| 2061 | module_exit(sm_lm85_exit); |
|---|