diff options
Diffstat (limited to 'drivers/hwmon/lm85.c')
-rw-r--r-- | drivers/hwmon/lm85.c | 672 |
1 files changed, 277 insertions, 395 deletions
diff --git a/drivers/hwmon/lm85.c b/drivers/hwmon/lm85.c index ee5eca1c1921..12d446f54f97 100644 --- a/drivers/hwmon/lm85.c +++ b/drivers/hwmon/lm85.c | |||
@@ -1,7 +1,7 @@ | |||
1 | /* | 1 | /* |
2 | lm85.c - Part of lm_sensors, Linux kernel modules for hardware | 2 | lm85.c - Part of lm_sensors, Linux kernel modules for hardware |
3 | monitoring | 3 | monitoring |
4 | Copyright (c) 1998, 1999 Frodo Looijaard <frodol@dds.nl> | 4 | Copyright (c) 1998, 1999 Frodo Looijaard <frodol@dds.nl> |
5 | Copyright (c) 2002, 2003 Philip Pokorny <ppokorny@penguincomputing.com> | 5 | Copyright (c) 2002, 2003 Philip Pokorny <ppokorny@penguincomputing.com> |
6 | Copyright (c) 2003 Margit Schubert-While <margitsw@t-online.de> | 6 | Copyright (c) 2003 Margit Schubert-While <margitsw@t-online.de> |
7 | Copyright (c) 2004 Justin Thiessen <jthiessen@penguincomputing.com> | 7 | Copyright (c) 2004 Justin Thiessen <jthiessen@penguincomputing.com> |
@@ -51,24 +51,17 @@ I2C_CLIENT_INSMOD_6(lm85b, lm85c, adm1027, adt7463, emc6d100, emc6d102); | |||
51 | #define LM85_REG_TEMP_MAX(nr) (0x4f + (nr) * 2) | 51 | #define LM85_REG_TEMP_MAX(nr) (0x4f + (nr) * 2) |
52 | 52 | ||
53 | /* Fan speeds are LSB, MSB (2 bytes) */ | 53 | /* Fan speeds are LSB, MSB (2 bytes) */ |
54 | #define LM85_REG_FAN(nr) (0x28 + (nr) *2) | 54 | #define LM85_REG_FAN(nr) (0x28 + (nr) * 2) |
55 | #define LM85_REG_FAN_MIN(nr) (0x54 + (nr) *2) | 55 | #define LM85_REG_FAN_MIN(nr) (0x54 + (nr) * 2) |
56 | 56 | ||
57 | #define LM85_REG_PWM(nr) (0x30 + (nr)) | 57 | #define LM85_REG_PWM(nr) (0x30 + (nr)) |
58 | 58 | ||
59 | #define ADT7463_REG_OPPOINT(nr) (0x33 + (nr)) | ||
60 | |||
61 | #define ADT7463_REG_TMIN_CTL1 0x36 | ||
62 | #define ADT7463_REG_TMIN_CTL2 0x37 | ||
63 | |||
64 | #define LM85_REG_DEVICE 0x3d | ||
65 | #define LM85_REG_COMPANY 0x3e | 59 | #define LM85_REG_COMPANY 0x3e |
66 | #define LM85_REG_VERSTEP 0x3f | 60 | #define LM85_REG_VERSTEP 0x3f |
67 | /* These are the recognized values for the above regs */ | 61 | /* These are the recognized values for the above regs */ |
68 | #define LM85_DEVICE_ADX 0x27 | ||
69 | #define LM85_COMPANY_NATIONAL 0x01 | 62 | #define LM85_COMPANY_NATIONAL 0x01 |
70 | #define LM85_COMPANY_ANALOG_DEV 0x41 | 63 | #define LM85_COMPANY_ANALOG_DEV 0x41 |
71 | #define LM85_COMPANY_SMSC 0x5c | 64 | #define LM85_COMPANY_SMSC 0x5c |
72 | #define LM85_VERSTEP_VMASK 0xf0 | 65 | #define LM85_VERSTEP_VMASK 0xf0 |
73 | #define LM85_VERSTEP_GENERIC 0x60 | 66 | #define LM85_VERSTEP_GENERIC 0x60 |
74 | #define LM85_VERSTEP_LM85C 0x60 | 67 | #define LM85_VERSTEP_LM85C 0x60 |
@@ -91,58 +84,45 @@ I2C_CLIENT_INSMOD_6(lm85b, lm85c, adm1027, adt7463, emc6d100, emc6d102); | |||
91 | #define LM85_REG_AFAN_CONFIG(nr) (0x5c + (nr)) | 84 | #define LM85_REG_AFAN_CONFIG(nr) (0x5c + (nr)) |
92 | #define LM85_REG_AFAN_RANGE(nr) (0x5f + (nr)) | 85 | #define LM85_REG_AFAN_RANGE(nr) (0x5f + (nr)) |
93 | #define LM85_REG_AFAN_SPIKE1 0x62 | 86 | #define LM85_REG_AFAN_SPIKE1 0x62 |
94 | #define LM85_REG_AFAN_SPIKE2 0x63 | ||
95 | #define LM85_REG_AFAN_MINPWM(nr) (0x64 + (nr)) | 87 | #define LM85_REG_AFAN_MINPWM(nr) (0x64 + (nr)) |
96 | #define LM85_REG_AFAN_LIMIT(nr) (0x67 + (nr)) | 88 | #define LM85_REG_AFAN_LIMIT(nr) (0x67 + (nr)) |
97 | #define LM85_REG_AFAN_CRITICAL(nr) (0x6a + (nr)) | 89 | #define LM85_REG_AFAN_CRITICAL(nr) (0x6a + (nr)) |
98 | #define LM85_REG_AFAN_HYST1 0x6d | 90 | #define LM85_REG_AFAN_HYST1 0x6d |
99 | #define LM85_REG_AFAN_HYST2 0x6e | 91 | #define LM85_REG_AFAN_HYST2 0x6e |
100 | 92 | ||
101 | #define LM85_REG_TACH_MODE 0x74 | ||
102 | #define LM85_REG_SPINUP_CTL 0x75 | ||
103 | |||
104 | #define ADM1027_REG_TEMP_OFFSET(nr) (0x70 + (nr)) | ||
105 | #define ADM1027_REG_CONFIG2 0x73 | ||
106 | #define ADM1027_REG_INTMASK1 0x74 | ||
107 | #define ADM1027_REG_INTMASK2 0x75 | ||
108 | #define ADM1027_REG_EXTEND_ADC1 0x76 | 93 | #define ADM1027_REG_EXTEND_ADC1 0x76 |
109 | #define ADM1027_REG_EXTEND_ADC2 0x77 | 94 | #define ADM1027_REG_EXTEND_ADC2 0x77 |
110 | #define ADM1027_REG_CONFIG3 0x78 | ||
111 | #define ADM1027_REG_FAN_PPR 0x7b | ||
112 | |||
113 | #define ADT7463_REG_THERM 0x79 | ||
114 | #define ADT7463_REG_THERM_LIMIT 0x7A | ||
115 | 95 | ||
116 | #define EMC6D100_REG_ALARM3 0x7d | 96 | #define EMC6D100_REG_ALARM3 0x7d |
117 | /* IN5, IN6 and IN7 */ | 97 | /* IN5, IN6 and IN7 */ |
118 | #define EMC6D100_REG_IN(nr) (0x70 + ((nr)-5)) | 98 | #define EMC6D100_REG_IN(nr) (0x70 + ((nr) - 5)) |
119 | #define EMC6D100_REG_IN_MIN(nr) (0x73 + ((nr)-5) * 2) | 99 | #define EMC6D100_REG_IN_MIN(nr) (0x73 + ((nr) - 5) * 2) |
120 | #define EMC6D100_REG_IN_MAX(nr) (0x74 + ((nr)-5) * 2) | 100 | #define EMC6D100_REG_IN_MAX(nr) (0x74 + ((nr) - 5) * 2) |
121 | #define EMC6D102_REG_EXTEND_ADC1 0x85 | 101 | #define EMC6D102_REG_EXTEND_ADC1 0x85 |
122 | #define EMC6D102_REG_EXTEND_ADC2 0x86 | 102 | #define EMC6D102_REG_EXTEND_ADC2 0x86 |
123 | #define EMC6D102_REG_EXTEND_ADC3 0x87 | 103 | #define EMC6D102_REG_EXTEND_ADC3 0x87 |
124 | #define EMC6D102_REG_EXTEND_ADC4 0x88 | 104 | #define EMC6D102_REG_EXTEND_ADC4 0x88 |
125 | 105 | ||
126 | 106 | ||
127 | /* Conversions. Rounding and limit checking is only done on the TO_REG | 107 | /* Conversions. Rounding and limit checking is only done on the TO_REG |
128 | variants. Note that you should be a bit careful with which arguments | 108 | variants. Note that you should be a bit careful with which arguments |
129 | these macros are called: arguments may be evaluated more than once. | 109 | these macros are called: arguments may be evaluated more than once. |
130 | */ | 110 | */ |
131 | 111 | ||
132 | /* IN are scaled acording to built-in resistors */ | 112 | /* IN are scaled acording to built-in resistors */ |
133 | static int lm85_scaling[] = { /* .001 Volts */ | 113 | static const int lm85_scaling[] = { /* .001 Volts */ |
134 | 2500, 2250, 3300, 5000, 12000, | 114 | 2500, 2250, 3300, 5000, 12000, |
135 | 3300, 1500, 1800 /*EMC6D100*/ | 115 | 3300, 1500, 1800 /*EMC6D100*/ |
136 | }; | 116 | }; |
137 | #define SCALE(val,from,to) (((val)*(to) + ((from)/2))/(from)) | 117 | #define SCALE(val, from, to) (((val) * (to) + ((from) / 2)) / (from)) |
138 | 118 | ||
139 | #define INS_TO_REG(n,val) \ | 119 | #define INS_TO_REG(n, val) \ |
140 | SENSORS_LIMIT(SCALE(val,lm85_scaling[n],192),0,255) | 120 | SENSORS_LIMIT(SCALE(val, lm85_scaling[n], 192), 0, 255) |
141 | 121 | ||
142 | #define INSEXT_FROM_REG(n,val,ext) \ | 122 | #define INSEXT_FROM_REG(n, val, ext) \ |
143 | SCALE(((val) << 4) + (ext), 192 << 4, lm85_scaling[n]) | 123 | SCALE(((val) << 4) + (ext), 192 << 4, lm85_scaling[n]) |
144 | 124 | ||
145 | #define INS_FROM_REG(n,val) SCALE((val), 192, lm85_scaling[n]) | 125 | #define INS_FROM_REG(n, val) SCALE((val), 192, lm85_scaling[n]) |
146 | 126 | ||
147 | /* FAN speed is measured using 90kHz clock */ | 127 | /* FAN speed is measured using 90kHz clock */ |
148 | static inline u16 FAN_TO_REG(unsigned long val) | 128 | static inline u16 FAN_TO_REG(unsigned long val) |
@@ -151,16 +131,17 @@ static inline u16 FAN_TO_REG(unsigned long val) | |||
151 | return 0xffff; | 131 | return 0xffff; |
152 | return SENSORS_LIMIT(5400000 / val, 1, 0xfffe); | 132 | return SENSORS_LIMIT(5400000 / val, 1, 0xfffe); |
153 | } | 133 | } |
154 | #define FAN_FROM_REG(val) ((val)==0?-1:(val)==0xffff?0:5400000/(val)) | 134 | #define FAN_FROM_REG(val) ((val) == 0 ? -1 : (val) == 0xffff ? 0 : \ |
135 | 5400000 / (val)) | ||
155 | 136 | ||
156 | /* Temperature is reported in .001 degC increments */ | 137 | /* Temperature is reported in .001 degC increments */ |
157 | #define TEMP_TO_REG(val) \ | 138 | #define TEMP_TO_REG(val) \ |
158 | SENSORS_LIMIT(SCALE(val,1000,1),-127,127) | 139 | SENSORS_LIMIT(SCALE(val, 1000, 1), -127, 127) |
159 | #define TEMPEXT_FROM_REG(val,ext) \ | 140 | #define TEMPEXT_FROM_REG(val, ext) \ |
160 | SCALE(((val) << 4) + (ext), 16, 1000) | 141 | SCALE(((val) << 4) + (ext), 16, 1000) |
161 | #define TEMP_FROM_REG(val) ((val) * 1000) | 142 | #define TEMP_FROM_REG(val) ((val) * 1000) |
162 | 143 | ||
163 | #define PWM_TO_REG(val) (SENSORS_LIMIT(val,0,255)) | 144 | #define PWM_TO_REG(val) SENSORS_LIMIT(val, 0, 255) |
164 | #define PWM_FROM_REG(val) (val) | 145 | #define PWM_FROM_REG(val) (val) |
165 | 146 | ||
166 | 147 | ||
@@ -183,17 +164,17 @@ static inline u16 FAN_TO_REG(unsigned long val) | |||
183 | */ | 164 | */ |
184 | 165 | ||
185 | /* These are the zone temperature range encodings in .001 degree C */ | 166 | /* These are the zone temperature range encodings in .001 degree C */ |
186 | static int lm85_range_map[] = { | 167 | static const int lm85_range_map[] = { |
187 | 2000, 2500, 3300, 4000, 5000, 6600, | 168 | 2000, 2500, 3300, 4000, 5000, 6600, 8000, 10000, |
188 | 8000, 10000, 13300, 16000, 20000, 26600, | 169 | 13300, 16000, 20000, 26600, 32000, 40000, 53300, 80000 |
189 | 32000, 40000, 53300, 80000 | 170 | }; |
190 | }; | 171 | |
191 | static int RANGE_TO_REG( int range ) | 172 | static int RANGE_TO_REG(int range) |
192 | { | 173 | { |
193 | int i; | 174 | int i; |
194 | 175 | ||
195 | if (range >= lm85_range_map[15]) | 176 | if (range >= lm85_range_map[15]) |
196 | return 15 ; | 177 | return 15; |
197 | 178 | ||
198 | /* Find the closest match */ | 179 | /* Find the closest match */ |
199 | for (i = 14; i >= 0; --i) { | 180 | for (i = 14; i >= 0; --i) { |
@@ -207,28 +188,25 @@ static int RANGE_TO_REG( int range ) | |||
207 | 188 | ||
208 | return 0; | 189 | return 0; |
209 | } | 190 | } |
210 | #define RANGE_FROM_REG(val) (lm85_range_map[(val)&0x0f]) | 191 | #define RANGE_FROM_REG(val) lm85_range_map[(val) & 0x0f] |
211 | 192 | ||
212 | /* These are the Acoustic Enhancement, or Temperature smoothing encodings | ||
213 | * NOTE: The enable/disable bit is INCLUDED in these encodings as the | ||
214 | * MSB (bit 3, value 8). If the enable bit is 0, the encoded value | ||
215 | * is ignored, or set to 0. | ||
216 | */ | ||
217 | /* These are the PWM frequency encodings */ | 193 | /* These are the PWM frequency encodings */ |
218 | static int lm85_freq_map[] = { /* .1 Hz */ | 194 | static const int lm85_freq_map[] = { /* .1 Hz */ |
219 | 100, 150, 230, 300, 380, 470, 620, 940 | 195 | 100, 150, 230, 300, 380, 470, 620, 940 |
220 | }; | 196 | }; |
221 | static int FREQ_TO_REG( int freq ) | 197 | |
198 | static int FREQ_TO_REG(int freq) | ||
222 | { | 199 | { |
223 | int i; | 200 | int i; |
224 | 201 | ||
225 | if( freq >= lm85_freq_map[7] ) { return 7 ; } | 202 | if (freq >= lm85_freq_map[7]) |
226 | for( i = 0 ; i < 7 ; ++i ) | 203 | return 7; |
227 | if( freq <= lm85_freq_map[i] ) | 204 | for (i = 0; i < 7; ++i) |
228 | break ; | 205 | if (freq <= lm85_freq_map[i]) |
229 | return( i & 0x07 ); | 206 | break; |
207 | return i; | ||
230 | } | 208 | } |
231 | #define FREQ_FROM_REG(val) (lm85_freq_map[(val)&0x07]) | 209 | #define FREQ_FROM_REG(val) lm85_freq_map[(val) & 0x07] |
232 | 210 | ||
233 | /* Since we can't use strings, I'm abusing these numbers | 211 | /* Since we can't use strings, I'm abusing these numbers |
234 | * to stand in for the following meanings: | 212 | * to stand in for the following meanings: |
@@ -242,30 +220,23 @@ static int FREQ_TO_REG( int freq ) | |||
242 | * -2 -- PWM responds to manual control | 220 | * -2 -- PWM responds to manual control |
243 | */ | 221 | */ |
244 | 222 | ||
245 | static int lm85_zone_map[] = { 1, 2, 3, -1, 0, 23, 123, -2 }; | 223 | static const int lm85_zone_map[] = { 1, 2, 3, -1, 0, 23, 123, -2 }; |
246 | #define ZONE_FROM_REG(val) (lm85_zone_map[((val)>>5)&0x07]) | 224 | #define ZONE_FROM_REG(val) lm85_zone_map[(val) >> 5] |
247 | 225 | ||
248 | static int ZONE_TO_REG( int zone ) | 226 | static int ZONE_TO_REG(int zone) |
249 | { | 227 | { |
250 | int i; | 228 | int i; |
251 | 229 | ||
252 | for( i = 0 ; i <= 7 ; ++i ) | 230 | for (i = 0; i <= 7; ++i) |
253 | if( zone == lm85_zone_map[i] ) | 231 | if (zone == lm85_zone_map[i]) |
254 | break ; | 232 | break; |
255 | if( i > 7 ) /* Not found. */ | 233 | if (i > 7) /* Not found. */ |
256 | i = 3; /* Always 100% */ | 234 | i = 3; /* Always 100% */ |
257 | return( (i & 0x07)<<5 ); | 235 | return i << 5; |
258 | } | 236 | } |
259 | 237 | ||
260 | #define HYST_TO_REG(val) (SENSORS_LIMIT(((val)+500)/1000,0,15)) | 238 | #define HYST_TO_REG(val) SENSORS_LIMIT(((val) + 500) / 1000, 0, 15) |
261 | #define HYST_FROM_REG(val) ((val)*1000) | 239 | #define HYST_FROM_REG(val) ((val) * 1000) |
262 | |||
263 | #define OFFSET_TO_REG(val) (SENSORS_LIMIT((val)/25,-127,127)) | ||
264 | #define OFFSET_FROM_REG(val) ((val)*25) | ||
265 | |||
266 | #define PPR_MASK(fan) (0x03<<(fan *2)) | ||
267 | #define PPR_TO_REG(val,fan) (SENSORS_LIMIT((val)-1,0,3)<<(fan *2)) | ||
268 | #define PPR_FROM_REG(val,fan) ((((val)>>(fan * 2))&0x03)+1) | ||
269 | 240 | ||
270 | /* Chip sampling rates | 241 | /* Chip sampling rates |
271 | * | 242 | * |
@@ -292,11 +263,11 @@ struct lm85_zone { | |||
292 | u8 hyst; /* Low limit hysteresis. (0-15) */ | 263 | u8 hyst; /* Low limit hysteresis. (0-15) */ |
293 | u8 range; /* Temp range, encoded */ | 264 | u8 range; /* Temp range, encoded */ |
294 | s8 critical; /* "All fans ON" temp limit */ | 265 | s8 critical; /* "All fans ON" temp limit */ |
295 | u8 off_desired; /* Actual "off" temperature specified. Preserved | 266 | u8 off_desired; /* Actual "off" temperature specified. Preserved |
296 | * to prevent "drift" as other autofan control | 267 | * to prevent "drift" as other autofan control |
297 | * values change. | 268 | * values change. |
298 | */ | 269 | */ |
299 | u8 max_desired; /* Actual "max" temperature specified. Preserved | 270 | u8 max_desired; /* Actual "max" temperature specified. Preserved |
300 | * to prevent "drift" as other autofan control | 271 | * to prevent "drift" as other autofan control |
301 | * values change. | 272 | * values change. |
302 | */ | 273 | */ |
@@ -327,23 +298,13 @@ struct lm85_data { | |||
327 | s8 temp[3]; /* Register value */ | 298 | s8 temp[3]; /* Register value */ |
328 | s8 temp_min[3]; /* Register value */ | 299 | s8 temp_min[3]; /* Register value */ |
329 | s8 temp_max[3]; /* Register value */ | 300 | s8 temp_max[3]; /* Register value */ |
330 | s8 temp_offset[3]; /* Register value */ | ||
331 | u16 fan[4]; /* Register value */ | 301 | u16 fan[4]; /* Register value */ |
332 | u16 fan_min[4]; /* Register value */ | 302 | u16 fan_min[4]; /* Register value */ |
333 | u8 pwm[3]; /* Register value */ | 303 | u8 pwm[3]; /* Register value */ |
334 | u8 spinup_ctl; /* Register encoding, combined */ | ||
335 | u8 tach_mode; /* Register encoding, combined */ | ||
336 | u8 temp_ext[3]; /* Decoded values */ | 304 | u8 temp_ext[3]; /* Decoded values */ |
337 | u8 in_ext[8]; /* Decoded values */ | 305 | u8 in_ext[8]; /* Decoded values */ |
338 | u8 fan_ppr; /* Register value */ | ||
339 | u8 smooth[3]; /* Register encoding */ | ||
340 | u8 vid; /* Register value */ | 306 | u8 vid; /* Register value */ |
341 | u8 vrm; /* VRM version */ | 307 | u8 vrm; /* VRM version */ |
342 | u8 syncpwm3; /* Saved PWM3 for TACH 2,3,4 config */ | ||
343 | u8 oppoint[3]; /* Register value */ | ||
344 | u16 tmin_ctl; /* Register value */ | ||
345 | unsigned long therm_total; /* Cummulative therm count */ | ||
346 | u8 therm_limit; /* Register value */ | ||
347 | u32 alarms; /* Register encoding, combined */ | 308 | u32 alarms; /* Register encoding, combined */ |
348 | struct lm85_autofan autofan[3]; | 309 | struct lm85_autofan autofan[3]; |
349 | struct lm85_zone zone[3]; | 310 | struct lm85_zone zone[3]; |
@@ -355,9 +316,8 @@ static int lm85_detect(struct i2c_adapter *adapter, int address, | |||
355 | static int lm85_detach_client(struct i2c_client *client); | 316 | static int lm85_detach_client(struct i2c_client *client); |
356 | 317 | ||
357 | static int lm85_read_value(struct i2c_client *client, u8 reg); | 318 | static int lm85_read_value(struct i2c_client *client, u8 reg); |
358 | static int lm85_write_value(struct i2c_client *client, u8 reg, int value); | 319 | static void lm85_write_value(struct i2c_client *client, u8 reg, int value); |
359 | static struct lm85_data *lm85_update_device(struct device *dev); | 320 | static struct lm85_data *lm85_update_device(struct device *dev); |
360 | static void lm85_init_client(struct i2c_client *client); | ||
361 | 321 | ||
362 | 322 | ||
363 | static struct i2c_driver lm85_driver = { | 323 | static struct i2c_driver lm85_driver = { |
@@ -375,7 +335,7 @@ static ssize_t show_fan(struct device *dev, struct device_attribute *attr, | |||
375 | { | 335 | { |
376 | int nr = to_sensor_dev_attr(attr)->index; | 336 | int nr = to_sensor_dev_attr(attr)->index; |
377 | struct lm85_data *data = lm85_update_device(dev); | 337 | struct lm85_data *data = lm85_update_device(dev); |
378 | return sprintf(buf,"%d\n", FAN_FROM_REG(data->fan[nr]) ); | 338 | return sprintf(buf, "%d\n", FAN_FROM_REG(data->fan[nr])); |
379 | } | 339 | } |
380 | 340 | ||
381 | static ssize_t show_fan_min(struct device *dev, struct device_attribute *attr, | 341 | static ssize_t show_fan_min(struct device *dev, struct device_attribute *attr, |
@@ -383,7 +343,7 @@ static ssize_t show_fan_min(struct device *dev, struct device_attribute *attr, | |||
383 | { | 343 | { |
384 | int nr = to_sensor_dev_attr(attr)->index; | 344 | int nr = to_sensor_dev_attr(attr)->index; |
385 | struct lm85_data *data = lm85_update_device(dev); | 345 | struct lm85_data *data = lm85_update_device(dev); |
386 | return sprintf(buf,"%d\n", FAN_FROM_REG(data->fan_min[nr]) ); | 346 | return sprintf(buf, "%d\n", FAN_FROM_REG(data->fan_min[nr])); |
387 | } | 347 | } |
388 | 348 | ||
389 | static ssize_t set_fan_min(struct device *dev, struct device_attribute *attr, | 349 | static ssize_t set_fan_min(struct device *dev, struct device_attribute *attr, |
@@ -414,7 +374,8 @@ show_fan_offset(4); | |||
414 | 374 | ||
415 | /* vid, vrm, alarms */ | 375 | /* vid, vrm, alarms */ |
416 | 376 | ||
417 | static ssize_t show_vid_reg(struct device *dev, struct device_attribute *attr, char *buf) | 377 | static ssize_t show_vid_reg(struct device *dev, struct device_attribute *attr, |
378 | char *buf) | ||
418 | { | 379 | { |
419 | struct lm85_data *data = lm85_update_device(dev); | 380 | struct lm85_data *data = lm85_update_device(dev); |
420 | int vid; | 381 | int vid; |
@@ -432,13 +393,15 @@ static ssize_t show_vid_reg(struct device *dev, struct device_attribute *attr, c | |||
432 | 393 | ||
433 | static DEVICE_ATTR(cpu0_vid, S_IRUGO, show_vid_reg, NULL); | 394 | static DEVICE_ATTR(cpu0_vid, S_IRUGO, show_vid_reg, NULL); |
434 | 395 | ||
435 | static ssize_t show_vrm_reg(struct device *dev, struct device_attribute *attr, char *buf) | 396 | static ssize_t show_vrm_reg(struct device *dev, struct device_attribute *attr, |
397 | char *buf) | ||
436 | { | 398 | { |
437 | struct lm85_data *data = dev_get_drvdata(dev); | 399 | struct lm85_data *data = dev_get_drvdata(dev); |
438 | return sprintf(buf, "%ld\n", (long) data->vrm); | 400 | return sprintf(buf, "%ld\n", (long) data->vrm); |
439 | } | 401 | } |
440 | 402 | ||
441 | static ssize_t store_vrm_reg(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) | 403 | static ssize_t store_vrm_reg(struct device *dev, struct device_attribute *attr, |
404 | const char *buf, size_t count) | ||
442 | { | 405 | { |
443 | struct lm85_data *data = dev_get_drvdata(dev); | 406 | struct lm85_data *data = dev_get_drvdata(dev); |
444 | data->vrm = simple_strtoul(buf, NULL, 10); | 407 | data->vrm = simple_strtoul(buf, NULL, 10); |
@@ -447,7 +410,8 @@ static ssize_t store_vrm_reg(struct device *dev, struct device_attribute *attr, | |||
447 | 410 | ||
448 | static DEVICE_ATTR(vrm, S_IRUGO | S_IWUSR, show_vrm_reg, store_vrm_reg); | 411 | static DEVICE_ATTR(vrm, S_IRUGO | S_IWUSR, show_vrm_reg, store_vrm_reg); |
449 | 412 | ||
450 | static ssize_t show_alarms_reg(struct device *dev, struct device_attribute *attr, char *buf) | 413 | static ssize_t show_alarms_reg(struct device *dev, struct device_attribute |
414 | *attr, char *buf) | ||
451 | { | 415 | { |
452 | struct lm85_data *data = lm85_update_device(dev); | 416 | struct lm85_data *data = lm85_update_device(dev); |
453 | return sprintf(buf, "%u\n", data->alarms); | 417 | return sprintf(buf, "%u\n", data->alarms); |
@@ -488,7 +452,7 @@ static ssize_t show_pwm(struct device *dev, struct device_attribute *attr, | |||
488 | { | 452 | { |
489 | int nr = to_sensor_dev_attr(attr)->index; | 453 | int nr = to_sensor_dev_attr(attr)->index; |
490 | struct lm85_data *data = lm85_update_device(dev); | 454 | struct lm85_data *data = lm85_update_device(dev); |
491 | return sprintf(buf,"%d\n", PWM_FROM_REG(data->pwm[nr]) ); | 455 | return sprintf(buf, "%d\n", PWM_FROM_REG(data->pwm[nr])); |
492 | } | 456 | } |
493 | 457 | ||
494 | static ssize_t set_pwm(struct device *dev, struct device_attribute *attr, | 458 | static ssize_t set_pwm(struct device *dev, struct device_attribute *attr, |
@@ -581,17 +545,16 @@ static ssize_t show_in(struct device *dev, struct device_attribute *attr, | |||
581 | { | 545 | { |
582 | int nr = to_sensor_dev_attr(attr)->index; | 546 | int nr = to_sensor_dev_attr(attr)->index; |
583 | struct lm85_data *data = lm85_update_device(dev); | 547 | struct lm85_data *data = lm85_update_device(dev); |
584 | return sprintf( buf, "%d\n", INSEXT_FROM_REG(nr, | 548 | return sprintf(buf, "%d\n", INSEXT_FROM_REG(nr, data->in[nr], |
585 | data->in[nr], | 549 | data->in_ext[nr])); |
586 | data->in_ext[nr])); | ||
587 | } | 550 | } |
588 | 551 | ||
589 | static ssize_t show_in_min(struct device *dev, struct device_attribute *attr, | 552 | static ssize_t show_in_min(struct device *dev, struct device_attribute *attr, |
590 | char *buf) | 553 | char *buf) |
591 | { | 554 | { |
592 | int nr = to_sensor_dev_attr(attr)->index; | 555 | int nr = to_sensor_dev_attr(attr)->index; |
593 | struct lm85_data *data = lm85_update_device(dev); | 556 | struct lm85_data *data = lm85_update_device(dev); |
594 | return sprintf(buf,"%d\n", INS_FROM_REG(nr, data->in_min[nr]) ); | 557 | return sprintf(buf, "%d\n", INS_FROM_REG(nr, data->in_min[nr])); |
595 | } | 558 | } |
596 | 559 | ||
597 | static ssize_t set_in_min(struct device *dev, struct device_attribute *attr, | 560 | static ssize_t set_in_min(struct device *dev, struct device_attribute *attr, |
@@ -614,7 +577,7 @@ static ssize_t show_in_max(struct device *dev, struct device_attribute *attr, | |||
614 | { | 577 | { |
615 | int nr = to_sensor_dev_attr(attr)->index; | 578 | int nr = to_sensor_dev_attr(attr)->index; |
616 | struct lm85_data *data = lm85_update_device(dev); | 579 | struct lm85_data *data = lm85_update_device(dev); |
617 | return sprintf(buf,"%d\n", INS_FROM_REG(nr, data->in_max[nr]) ); | 580 | return sprintf(buf, "%d\n", INS_FROM_REG(nr, data->in_max[nr])); |
618 | } | 581 | } |
619 | 582 | ||
620 | static ssize_t set_in_max(struct device *dev, struct device_attribute *attr, | 583 | static ssize_t set_in_max(struct device *dev, struct device_attribute *attr, |
@@ -656,8 +619,8 @@ static ssize_t show_temp(struct device *dev, struct device_attribute *attr, | |||
656 | { | 619 | { |
657 | int nr = to_sensor_dev_attr(attr)->index; | 620 | int nr = to_sensor_dev_attr(attr)->index; |
658 | struct lm85_data *data = lm85_update_device(dev); | 621 | struct lm85_data *data = lm85_update_device(dev); |
659 | return sprintf(buf,"%d\n", TEMPEXT_FROM_REG(data->temp[nr], | 622 | return sprintf(buf, "%d\n", TEMPEXT_FROM_REG(data->temp[nr], |
660 | data->temp_ext[nr])); | 623 | data->temp_ext[nr])); |
661 | } | 624 | } |
662 | 625 | ||
663 | static ssize_t show_temp_min(struct device *dev, struct device_attribute *attr, | 626 | static ssize_t show_temp_min(struct device *dev, struct device_attribute *attr, |
@@ -665,7 +628,7 @@ static ssize_t show_temp_min(struct device *dev, struct device_attribute *attr, | |||
665 | { | 628 | { |
666 | int nr = to_sensor_dev_attr(attr)->index; | 629 | int nr = to_sensor_dev_attr(attr)->index; |
667 | struct lm85_data *data = lm85_update_device(dev); | 630 | struct lm85_data *data = lm85_update_device(dev); |
668 | return sprintf(buf,"%d\n", TEMP_FROM_REG(data->temp_min[nr]) ); | 631 | return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_min[nr])); |
669 | } | 632 | } |
670 | 633 | ||
671 | static ssize_t set_temp_min(struct device *dev, struct device_attribute *attr, | 634 | static ssize_t set_temp_min(struct device *dev, struct device_attribute *attr, |
@@ -688,7 +651,7 @@ static ssize_t show_temp_max(struct device *dev, struct device_attribute *attr, | |||
688 | { | 651 | { |
689 | int nr = to_sensor_dev_attr(attr)->index; | 652 | int nr = to_sensor_dev_attr(attr)->index; |
690 | struct lm85_data *data = lm85_update_device(dev); | 653 | struct lm85_data *data = lm85_update_device(dev); |
691 | return sprintf(buf,"%d\n", TEMP_FROM_REG(data->temp_max[nr]) ); | 654 | return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_max[nr])); |
692 | } | 655 | } |
693 | 656 | ||
694 | static ssize_t set_temp_max(struct device *dev, struct device_attribute *attr, | 657 | static ssize_t set_temp_max(struct device *dev, struct device_attribute *attr, |
@@ -697,7 +660,7 @@ static ssize_t set_temp_max(struct device *dev, struct device_attribute *attr, | |||
697 | int nr = to_sensor_dev_attr(attr)->index; | 660 | int nr = to_sensor_dev_attr(attr)->index; |
698 | struct i2c_client *client = to_i2c_client(dev); | 661 | struct i2c_client *client = to_i2c_client(dev); |
699 | struct lm85_data *data = i2c_get_clientdata(client); | 662 | struct lm85_data *data = i2c_get_clientdata(client); |
700 | long val = simple_strtol(buf, NULL, 10); | 663 | long val = simple_strtol(buf, NULL, 10); |
701 | 664 | ||
702 | mutex_lock(&data->update_lock); | 665 | mutex_lock(&data->update_lock); |
703 | data->temp_max[nr] = TEMP_TO_REG(val); | 666 | data->temp_max[nr] = TEMP_TO_REG(val); |
@@ -726,7 +689,7 @@ static ssize_t show_pwm_auto_channels(struct device *dev, | |||
726 | { | 689 | { |
727 | int nr = to_sensor_dev_attr(attr)->index; | 690 | int nr = to_sensor_dev_attr(attr)->index; |
728 | struct lm85_data *data = lm85_update_device(dev); | 691 | struct lm85_data *data = lm85_update_device(dev); |
729 | return sprintf(buf,"%d\n", ZONE_FROM_REG(data->autofan[nr].config)); | 692 | return sprintf(buf, "%d\n", ZONE_FROM_REG(data->autofan[nr].config)); |
730 | } | 693 | } |
731 | 694 | ||
732 | static ssize_t set_pwm_auto_channels(struct device *dev, | 695 | static ssize_t set_pwm_auto_channels(struct device *dev, |
@@ -735,11 +698,11 @@ static ssize_t set_pwm_auto_channels(struct device *dev, | |||
735 | int nr = to_sensor_dev_attr(attr)->index; | 698 | int nr = to_sensor_dev_attr(attr)->index; |
736 | struct i2c_client *client = to_i2c_client(dev); | 699 | struct i2c_client *client = to_i2c_client(dev); |
737 | struct lm85_data *data = i2c_get_clientdata(client); | 700 | struct lm85_data *data = i2c_get_clientdata(client); |
738 | long val = simple_strtol(buf, NULL, 10); | 701 | long val = simple_strtol(buf, NULL, 10); |
739 | 702 | ||
740 | mutex_lock(&data->update_lock); | 703 | mutex_lock(&data->update_lock); |
741 | data->autofan[nr].config = (data->autofan[nr].config & (~0xe0)) | 704 | data->autofan[nr].config = (data->autofan[nr].config & (~0xe0)) |
742 | | ZONE_TO_REG(val) ; | 705 | | ZONE_TO_REG(val); |
743 | lm85_write_value(client, LM85_REG_AFAN_CONFIG(nr), | 706 | lm85_write_value(client, LM85_REG_AFAN_CONFIG(nr), |
744 | data->autofan[nr].config); | 707 | data->autofan[nr].config); |
745 | mutex_unlock(&data->update_lock); | 708 | mutex_unlock(&data->update_lock); |
@@ -751,7 +714,7 @@ static ssize_t show_pwm_auto_pwm_min(struct device *dev, | |||
751 | { | 714 | { |
752 | int nr = to_sensor_dev_attr(attr)->index; | 715 | int nr = to_sensor_dev_attr(attr)->index; |
753 | struct lm85_data *data = lm85_update_device(dev); | 716 | struct lm85_data *data = lm85_update_device(dev); |
754 | return sprintf(buf,"%d\n", PWM_FROM_REG(data->autofan[nr].min_pwm)); | 717 | return sprintf(buf, "%d\n", PWM_FROM_REG(data->autofan[nr].min_pwm)); |
755 | } | 718 | } |
756 | 719 | ||
757 | static ssize_t set_pwm_auto_pwm_min(struct device *dev, | 720 | static ssize_t set_pwm_auto_pwm_min(struct device *dev, |
@@ -775,7 +738,7 @@ static ssize_t show_pwm_auto_pwm_minctl(struct device *dev, | |||
775 | { | 738 | { |
776 | int nr = to_sensor_dev_attr(attr)->index; | 739 | int nr = to_sensor_dev_attr(attr)->index; |
777 | struct lm85_data *data = lm85_update_device(dev); | 740 | struct lm85_data *data = lm85_update_device(dev); |
778 | return sprintf(buf,"%d\n", data->autofan[nr].min_off); | 741 | return sprintf(buf, "%d\n", data->autofan[nr].min_off); |
779 | } | 742 | } |
780 | 743 | ||
781 | static ssize_t set_pwm_auto_pwm_minctl(struct device *dev, | 744 | static ssize_t set_pwm_auto_pwm_minctl(struct device *dev, |
@@ -785,15 +748,15 @@ static ssize_t set_pwm_auto_pwm_minctl(struct device *dev, | |||
785 | struct i2c_client *client = to_i2c_client(dev); | 748 | struct i2c_client *client = to_i2c_client(dev); |
786 | struct lm85_data *data = i2c_get_clientdata(client); | 749 | struct lm85_data *data = i2c_get_clientdata(client); |
787 | long val = simple_strtol(buf, NULL, 10); | 750 | long val = simple_strtol(buf, NULL, 10); |
751 | u8 tmp; | ||
788 | 752 | ||
789 | mutex_lock(&data->update_lock); | 753 | mutex_lock(&data->update_lock); |
790 | data->autofan[nr].min_off = val; | 754 | data->autofan[nr].min_off = val; |
791 | lm85_write_value(client, LM85_REG_AFAN_SPIKE1, data->smooth[0] | 755 | tmp = lm85_read_value(client, LM85_REG_AFAN_SPIKE1); |
792 | | data->syncpwm3 | 756 | tmp &= ~(0x20 << nr); |
793 | | (data->autofan[0].min_off ? 0x20 : 0) | 757 | if (data->autofan[nr].min_off) |
794 | | (data->autofan[1].min_off ? 0x40 : 0) | 758 | tmp |= 0x20 << nr; |
795 | | (data->autofan[2].min_off ? 0x80 : 0) | 759 | lm85_write_value(client, LM85_REG_AFAN_SPIKE1, tmp); |
796 | ); | ||
797 | mutex_unlock(&data->update_lock); | 760 | mutex_unlock(&data->update_lock); |
798 | return count; | 761 | return count; |
799 | } | 762 | } |
@@ -803,7 +766,7 @@ static ssize_t show_pwm_auto_pwm_freq(struct device *dev, | |||
803 | { | 766 | { |
804 | int nr = to_sensor_dev_attr(attr)->index; | 767 | int nr = to_sensor_dev_attr(attr)->index; |
805 | struct lm85_data *data = lm85_update_device(dev); | 768 | struct lm85_data *data = lm85_update_device(dev); |
806 | return sprintf(buf,"%d\n", FREQ_FROM_REG(data->autofan[nr].freq)); | 769 | return sprintf(buf, "%d\n", FREQ_FROM_REG(data->autofan[nr].freq)); |
807 | } | 770 | } |
808 | 771 | ||
809 | static ssize_t set_pwm_auto_pwm_freq(struct device *dev, | 772 | static ssize_t set_pwm_auto_pwm_freq(struct device *dev, |
@@ -818,8 +781,7 @@ static ssize_t set_pwm_auto_pwm_freq(struct device *dev, | |||
818 | data->autofan[nr].freq = FREQ_TO_REG(val); | 781 | data->autofan[nr].freq = FREQ_TO_REG(val); |
819 | lm85_write_value(client, LM85_REG_AFAN_RANGE(nr), | 782 | lm85_write_value(client, LM85_REG_AFAN_RANGE(nr), |
820 | (data->zone[nr].range << 4) | 783 | (data->zone[nr].range << 4) |
821 | | data->autofan[nr].freq | 784 | | data->autofan[nr].freq); |
822 | ); | ||
823 | mutex_unlock(&data->update_lock); | 785 | mutex_unlock(&data->update_lock); |
824 | return count; | 786 | return count; |
825 | } | 787 | } |
@@ -849,7 +811,7 @@ static ssize_t show_temp_auto_temp_off(struct device *dev, | |||
849 | { | 811 | { |
850 | int nr = to_sensor_dev_attr(attr)->index; | 812 | int nr = to_sensor_dev_attr(attr)->index; |
851 | struct lm85_data *data = lm85_update_device(dev); | 813 | struct lm85_data *data = lm85_update_device(dev); |
852 | return sprintf(buf,"%d\n", TEMP_FROM_REG(data->zone[nr].limit) - | 814 | return sprintf(buf, "%d\n", TEMP_FROM_REG(data->zone[nr].limit) - |
853 | HYST_FROM_REG(data->zone[nr].hyst)); | 815 | HYST_FROM_REG(data->zone[nr].hyst)); |
854 | } | 816 | } |
855 | 817 | ||
@@ -866,15 +828,13 @@ static ssize_t set_temp_auto_temp_off(struct device *dev, | |||
866 | min = TEMP_FROM_REG(data->zone[nr].limit); | 828 | min = TEMP_FROM_REG(data->zone[nr].limit); |
867 | data->zone[nr].off_desired = TEMP_TO_REG(val); | 829 | data->zone[nr].off_desired = TEMP_TO_REG(val); |
868 | data->zone[nr].hyst = HYST_TO_REG(min - val); | 830 | data->zone[nr].hyst = HYST_TO_REG(min - val); |
869 | if ( nr == 0 || nr == 1 ) { | 831 | if (nr == 0 || nr == 1) { |
870 | lm85_write_value(client, LM85_REG_AFAN_HYST1, | 832 | lm85_write_value(client, LM85_REG_AFAN_HYST1, |
871 | (data->zone[0].hyst << 4) | 833 | (data->zone[0].hyst << 4) |
872 | | data->zone[1].hyst | 834 | | data->zone[1].hyst); |
873 | ); | ||
874 | } else { | 835 | } else { |
875 | lm85_write_value(client, LM85_REG_AFAN_HYST2, | 836 | lm85_write_value(client, LM85_REG_AFAN_HYST2, |
876 | (data->zone[2].hyst << 4) | 837 | (data->zone[2].hyst << 4)); |
877 | ); | ||
878 | } | 838 | } |
879 | mutex_unlock(&data->update_lock); | 839 | mutex_unlock(&data->update_lock); |
880 | return count; | 840 | return count; |
@@ -885,7 +845,7 @@ static ssize_t show_temp_auto_temp_min(struct device *dev, | |||
885 | { | 845 | { |
886 | int nr = to_sensor_dev_attr(attr)->index; | 846 | int nr = to_sensor_dev_attr(attr)->index; |
887 | struct lm85_data *data = lm85_update_device(dev); | 847 | struct lm85_data *data = lm85_update_device(dev); |
888 | return sprintf(buf,"%d\n", TEMP_FROM_REG(data->zone[nr].limit) ); | 848 | return sprintf(buf, "%d\n", TEMP_FROM_REG(data->zone[nr].limit)); |
889 | } | 849 | } |
890 | 850 | ||
891 | static ssize_t set_temp_auto_temp_min(struct device *dev, | 851 | static ssize_t set_temp_auto_temp_min(struct device *dev, |
@@ -913,15 +873,13 @@ static ssize_t set_temp_auto_temp_min(struct device *dev, | |||
913 | data->zone[nr].hyst = HYST_TO_REG(TEMP_FROM_REG( | 873 | data->zone[nr].hyst = HYST_TO_REG(TEMP_FROM_REG( |
914 | data->zone[nr].limit) - TEMP_FROM_REG( | 874 | data->zone[nr].limit) - TEMP_FROM_REG( |
915 | data->zone[nr].off_desired)); | 875 | data->zone[nr].off_desired)); |
916 | if ( nr == 0 || nr == 1 ) { | 876 | if (nr == 0 || nr == 1) { |
917 | lm85_write_value(client, LM85_REG_AFAN_HYST1, | 877 | lm85_write_value(client, LM85_REG_AFAN_HYST1, |
918 | (data->zone[0].hyst << 4) | 878 | (data->zone[0].hyst << 4) |
919 | | data->zone[1].hyst | 879 | | data->zone[1].hyst); |
920 | ); | ||
921 | } else { | 880 | } else { |
922 | lm85_write_value(client, LM85_REG_AFAN_HYST2, | 881 | lm85_write_value(client, LM85_REG_AFAN_HYST2, |
923 | (data->zone[2].hyst << 4) | 882 | (data->zone[2].hyst << 4)); |
924 | ); | ||
925 | } | 883 | } |
926 | mutex_unlock(&data->update_lock); | 884 | mutex_unlock(&data->update_lock); |
927 | return count; | 885 | return count; |
@@ -932,7 +890,7 @@ static ssize_t show_temp_auto_temp_max(struct device *dev, | |||
932 | { | 890 | { |
933 | int nr = to_sensor_dev_attr(attr)->index; | 891 | int nr = to_sensor_dev_attr(attr)->index; |
934 | struct lm85_data *data = lm85_update_device(dev); | 892 | struct lm85_data *data = lm85_update_device(dev); |
935 | return sprintf(buf,"%d\n", TEMP_FROM_REG(data->zone[nr].limit) + | 893 | return sprintf(buf, "%d\n", TEMP_FROM_REG(data->zone[nr].limit) + |
936 | RANGE_FROM_REG(data->zone[nr].range)); | 894 | RANGE_FROM_REG(data->zone[nr].range)); |
937 | } | 895 | } |
938 | 896 | ||
@@ -962,11 +920,11 @@ static ssize_t show_temp_auto_temp_crit(struct device *dev, | |||
962 | { | 920 | { |
963 | int nr = to_sensor_dev_attr(attr)->index; | 921 | int nr = to_sensor_dev_attr(attr)->index; |
964 | struct lm85_data *data = lm85_update_device(dev); | 922 | struct lm85_data *data = lm85_update_device(dev); |
965 | return sprintf(buf,"%d\n", TEMP_FROM_REG(data->zone[nr].critical)); | 923 | return sprintf(buf, "%d\n", TEMP_FROM_REG(data->zone[nr].critical)); |
966 | } | 924 | } |
967 | 925 | ||
968 | static ssize_t set_temp_auto_temp_crit(struct device *dev, | 926 | static ssize_t set_temp_auto_temp_crit(struct device *dev, |
969 | struct device_attribute *attr,const char *buf, size_t count) | 927 | struct device_attribute *attr, const char *buf, size_t count) |
970 | { | 928 | { |
971 | int nr = to_sensor_dev_attr(attr)->index; | 929 | int nr = to_sensor_dev_attr(attr)->index; |
972 | struct i2c_client *client = to_i2c_client(dev); | 930 | struct i2c_client *client = to_i2c_client(dev); |
@@ -1127,20 +1085,37 @@ static const struct attribute_group lm85_group_in567 = { | |||
1127 | .attrs = lm85_attributes_in567, | 1085 | .attrs = lm85_attributes_in567, |
1128 | }; | 1086 | }; |
1129 | 1087 | ||
1088 | static void lm85_init_client(struct i2c_client *client) | ||
1089 | { | ||
1090 | int value; | ||
1091 | |||
1092 | /* Start monitoring if needed */ | ||
1093 | value = lm85_read_value(client, LM85_REG_CONFIG); | ||
1094 | if (!(value & 0x01)) { | ||
1095 | dev_info(&client->dev, "Starting monitoring\n"); | ||
1096 | lm85_write_value(client, LM85_REG_CONFIG, value | 0x01); | ||
1097 | } | ||
1098 | |||
1099 | /* Warn about unusual configuration bits */ | ||
1100 | if (value & 0x02) | ||
1101 | dev_warn(&client->dev, "Device configuration is locked\n"); | ||
1102 | if (!(value & 0x04)) | ||
1103 | dev_warn(&client->dev, "Device is not ready\n"); | ||
1104 | } | ||
1105 | |||
1130 | static int lm85_detect(struct i2c_adapter *adapter, int address, | 1106 | static int lm85_detect(struct i2c_adapter *adapter, int address, |
1131 | int kind) | 1107 | int kind) |
1132 | { | 1108 | { |
1133 | int company, verstep ; | 1109 | int company, verstep; |
1134 | struct i2c_client *new_client = NULL; | 1110 | struct i2c_client *client; |
1135 | struct lm85_data *data; | 1111 | struct lm85_data *data; |
1136 | int err = 0; | 1112 | int err = 0; |
1137 | const char *type_name = ""; | 1113 | const char *type_name; |
1138 | 1114 | ||
1139 | if (!i2c_check_functionality(adapter, | 1115 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) { |
1140 | I2C_FUNC_SMBUS_BYTE_DATA)) { | ||
1141 | /* We need to be able to do byte I/O */ | 1116 | /* We need to be able to do byte I/O */ |
1142 | goto ERROR0 ; | 1117 | goto ERROR0; |
1143 | }; | 1118 | } |
1144 | 1119 | ||
1145 | /* OK. For now, we presume we have a valid client. We now create the | 1120 | /* OK. For now, we presume we have a valid client. We now create the |
1146 | client structure, even though we cannot fill it completely yet. | 1121 | client structure, even though we cannot fill it completely yet. |
@@ -1151,138 +1126,145 @@ static int lm85_detect(struct i2c_adapter *adapter, int address, | |||
1151 | goto ERROR0; | 1126 | goto ERROR0; |
1152 | } | 1127 | } |
1153 | 1128 | ||
1154 | new_client = &data->client; | 1129 | client = &data->client; |
1155 | i2c_set_clientdata(new_client, data); | 1130 | i2c_set_clientdata(client, data); |
1156 | new_client->addr = address; | 1131 | client->addr = address; |
1157 | new_client->adapter = adapter; | 1132 | client->adapter = adapter; |
1158 | new_client->driver = &lm85_driver; | 1133 | client->driver = &lm85_driver; |
1159 | new_client->flags = 0; | ||
1160 | 1134 | ||
1161 | /* Now, we do the remaining detection. */ | 1135 | /* Now, we do the remaining detection. */ |
1162 | 1136 | ||
1163 | company = lm85_read_value(new_client, LM85_REG_COMPANY); | 1137 | company = lm85_read_value(client, LM85_REG_COMPANY); |
1164 | verstep = lm85_read_value(new_client, LM85_REG_VERSTEP); | 1138 | verstep = lm85_read_value(client, LM85_REG_VERSTEP); |
1165 | 1139 | ||
1166 | dev_dbg(&adapter->dev, "Detecting device at %d,0x%02x with" | 1140 | dev_dbg(&adapter->dev, "Detecting device at %d,0x%02x with" |
1167 | " COMPANY: 0x%02x and VERSTEP: 0x%02x\n", | 1141 | " COMPANY: 0x%02x and VERSTEP: 0x%02x\n", |
1168 | i2c_adapter_id(new_client->adapter), new_client->addr, | 1142 | i2c_adapter_id(client->adapter), client->addr, |
1169 | company, verstep); | 1143 | company, verstep); |
1170 | 1144 | ||
1171 | /* If auto-detecting, Determine the chip type. */ | 1145 | /* If auto-detecting, Determine the chip type. */ |
1172 | if (kind <= 0) { | 1146 | if (kind <= 0) { |
1173 | dev_dbg(&adapter->dev, "Autodetecting device at %d,0x%02x ...\n", | 1147 | dev_dbg(&adapter->dev, "Autodetecting device at %d,0x%02x ...\n", |
1174 | i2c_adapter_id(adapter), address ); | 1148 | i2c_adapter_id(adapter), address); |
1175 | if( company == LM85_COMPANY_NATIONAL | 1149 | if (company == LM85_COMPANY_NATIONAL |
1176 | && verstep == LM85_VERSTEP_LM85C ) { | 1150 | && verstep == LM85_VERSTEP_LM85C) { |
1177 | kind = lm85c ; | 1151 | kind = lm85c; |
1178 | } else if( company == LM85_COMPANY_NATIONAL | 1152 | } else if (company == LM85_COMPANY_NATIONAL |
1179 | && verstep == LM85_VERSTEP_LM85B ) { | 1153 | && verstep == LM85_VERSTEP_LM85B) { |
1180 | kind = lm85b ; | 1154 | kind = lm85b; |
1181 | } else if( company == LM85_COMPANY_NATIONAL | 1155 | } else if (company == LM85_COMPANY_NATIONAL |
1182 | && (verstep & LM85_VERSTEP_VMASK) == LM85_VERSTEP_GENERIC ) { | 1156 | && (verstep & LM85_VERSTEP_VMASK) == LM85_VERSTEP_GENERIC) { |
1183 | dev_err(&adapter->dev, "Unrecognized version/stepping 0x%02x" | 1157 | dev_err(&adapter->dev, "Unrecognized version/stepping 0x%02x" |
1184 | " Defaulting to LM85.\n", verstep); | 1158 | " Defaulting to LM85.\n", verstep); |
1185 | kind = any_chip ; | 1159 | kind = any_chip; |
1186 | } else if( company == LM85_COMPANY_ANALOG_DEV | 1160 | } else if (company == LM85_COMPANY_ANALOG_DEV |
1187 | && verstep == LM85_VERSTEP_ADM1027 ) { | 1161 | && verstep == LM85_VERSTEP_ADM1027) { |
1188 | kind = adm1027 ; | 1162 | kind = adm1027; |
1189 | } else if( company == LM85_COMPANY_ANALOG_DEV | 1163 | } else if (company == LM85_COMPANY_ANALOG_DEV |
1190 | && (verstep == LM85_VERSTEP_ADT7463 | 1164 | && (verstep == LM85_VERSTEP_ADT7463 |
1191 | || verstep == LM85_VERSTEP_ADT7463C) ) { | 1165 | || verstep == LM85_VERSTEP_ADT7463C)) { |
1192 | kind = adt7463 ; | 1166 | kind = adt7463; |
1193 | } else if( company == LM85_COMPANY_ANALOG_DEV | 1167 | } else if (company == LM85_COMPANY_ANALOG_DEV |
1194 | && (verstep & LM85_VERSTEP_VMASK) == LM85_VERSTEP_GENERIC ) { | 1168 | && (verstep & LM85_VERSTEP_VMASK) == LM85_VERSTEP_GENERIC) { |
1195 | dev_err(&adapter->dev, "Unrecognized version/stepping 0x%02x" | 1169 | dev_err(&adapter->dev, "Unrecognized version/stepping 0x%02x" |
1196 | " Defaulting to Generic LM85.\n", verstep ); | 1170 | " Defaulting to Generic LM85.\n", verstep); |
1197 | kind = any_chip ; | 1171 | kind = any_chip; |
1198 | } else if( company == LM85_COMPANY_SMSC | 1172 | } else if (company == LM85_COMPANY_SMSC |
1199 | && (verstep == LM85_VERSTEP_EMC6D100_A0 | 1173 | && (verstep == LM85_VERSTEP_EMC6D100_A0 |
1200 | || verstep == LM85_VERSTEP_EMC6D100_A1) ) { | 1174 | || verstep == LM85_VERSTEP_EMC6D100_A1)) { |
1201 | /* Unfortunately, we can't tell a '100 from a '101 | 1175 | /* Unfortunately, we can't tell a '100 from a '101 |
1202 | * from the registers. Since a '101 is a '100 | 1176 | * from the registers. Since a '101 is a '100 |
1203 | * in a package with fewer pins and therefore no | 1177 | * in a package with fewer pins and therefore no |
1204 | * 3.3V, 1.5V or 1.8V inputs, perhaps if those | 1178 | * 3.3V, 1.5V or 1.8V inputs, perhaps if those |
1205 | * inputs read 0, then it's a '101. | 1179 | * inputs read 0, then it's a '101. |
1206 | */ | 1180 | */ |
1207 | kind = emc6d100 ; | 1181 | kind = emc6d100; |
1208 | } else if( company == LM85_COMPANY_SMSC | 1182 | } else if (company == LM85_COMPANY_SMSC |
1209 | && verstep == LM85_VERSTEP_EMC6D102) { | 1183 | && verstep == LM85_VERSTEP_EMC6D102) { |
1210 | kind = emc6d102 ; | 1184 | kind = emc6d102; |
1211 | } else if( company == LM85_COMPANY_SMSC | 1185 | } else if (company == LM85_COMPANY_SMSC |
1212 | && (verstep & LM85_VERSTEP_VMASK) == LM85_VERSTEP_GENERIC) { | 1186 | && (verstep & LM85_VERSTEP_VMASK) == LM85_VERSTEP_GENERIC) { |
1213 | dev_err(&adapter->dev, "lm85: Detected SMSC chip\n"); | 1187 | dev_err(&adapter->dev, "lm85: Detected SMSC chip\n"); |
1214 | dev_err(&adapter->dev, "lm85: Unrecognized version/stepping 0x%02x" | 1188 | dev_err(&adapter->dev, "lm85: Unrecognized version/stepping 0x%02x" |
1215 | " Defaulting to Generic LM85.\n", verstep ); | 1189 | " Defaulting to Generic LM85.\n", verstep); |
1216 | kind = any_chip ; | 1190 | kind = any_chip; |
1217 | } else if( kind == any_chip | 1191 | } else if (kind == any_chip |
1218 | && (verstep & LM85_VERSTEP_VMASK) == LM85_VERSTEP_GENERIC) { | 1192 | && (verstep & LM85_VERSTEP_VMASK) == LM85_VERSTEP_GENERIC) { |
1219 | dev_err(&adapter->dev, "Generic LM85 Version 6 detected\n"); | 1193 | dev_err(&adapter->dev, "Generic LM85 Version 6 detected\n"); |
1220 | /* Leave kind as "any_chip" */ | 1194 | /* Leave kind as "any_chip" */ |
1221 | } else { | 1195 | } else { |
1222 | dev_dbg(&adapter->dev, "Autodetection failed\n"); | 1196 | dev_dbg(&adapter->dev, "Autodetection failed\n"); |
1223 | /* Not an LM85 ... */ | 1197 | /* Not an LM85... */ |
1224 | if( kind == any_chip ) { /* User used force=x,y */ | 1198 | if (kind == any_chip) { /* User used force=x,y */ |
1225 | dev_err(&adapter->dev, "Generic LM85 Version 6 not" | 1199 | dev_err(&adapter->dev, "Generic LM85 Version 6 not" |
1226 | " found at %d,0x%02x. Try force_lm85c.\n", | 1200 | " found at %d,0x%02x. Try force_lm85c.\n", |
1227 | i2c_adapter_id(adapter), address ); | 1201 | i2c_adapter_id(adapter), address); |
1228 | } | 1202 | } |
1229 | err = 0 ; | 1203 | err = 0; |
1230 | goto ERROR1; | 1204 | goto ERROR1; |
1231 | } | 1205 | } |
1232 | } | 1206 | } |
1233 | 1207 | ||
1234 | /* Fill in the chip specific driver values */ | 1208 | /* Fill in the chip specific driver values */ |
1235 | if ( kind == any_chip ) { | 1209 | switch (kind) { |
1236 | type_name = "lm85"; | 1210 | case lm85b: |
1237 | } else if ( kind == lm85b ) { | ||
1238 | type_name = "lm85b"; | 1211 | type_name = "lm85b"; |
1239 | } else if ( kind == lm85c ) { | 1212 | break; |
1213 | case lm85c: | ||
1240 | type_name = "lm85c"; | 1214 | type_name = "lm85c"; |
1241 | } else if ( kind == adm1027 ) { | 1215 | break; |
1216 | case adm1027: | ||
1242 | type_name = "adm1027"; | 1217 | type_name = "adm1027"; |
1243 | } else if ( kind == adt7463 ) { | 1218 | break; |
1219 | case adt7463: | ||
1244 | type_name = "adt7463"; | 1220 | type_name = "adt7463"; |
1245 | } else if ( kind == emc6d100){ | 1221 | break; |
1222 | case emc6d100: | ||
1246 | type_name = "emc6d100"; | 1223 | type_name = "emc6d100"; |
1247 | } else if ( kind == emc6d102 ) { | 1224 | break; |
1225 | case emc6d102: | ||
1248 | type_name = "emc6d102"; | 1226 | type_name = "emc6d102"; |
1227 | break; | ||
1228 | default: | ||
1229 | type_name = "lm85"; | ||
1249 | } | 1230 | } |
1250 | strlcpy(new_client->name, type_name, I2C_NAME_SIZE); | 1231 | strlcpy(client->name, type_name, I2C_NAME_SIZE); |
1251 | 1232 | ||
1252 | /* Fill in the remaining client fields */ | 1233 | /* Fill in the remaining client fields */ |
1253 | data->type = kind; | 1234 | data->type = kind; |
1254 | data->valid = 0; | ||
1255 | mutex_init(&data->update_lock); | 1235 | mutex_init(&data->update_lock); |
1256 | 1236 | ||
1257 | /* Tell the I2C layer a new client has arrived */ | 1237 | /* Tell the I2C layer a new client has arrived */ |
1258 | if ((err = i2c_attach_client(new_client))) | 1238 | err = i2c_attach_client(client); |
1239 | if (err) | ||
1259 | goto ERROR1; | 1240 | goto ERROR1; |
1260 | 1241 | ||
1261 | /* Set the VRM version */ | 1242 | /* Set the VRM version */ |
1262 | data->vrm = vid_which_vrm(); | 1243 | data->vrm = vid_which_vrm(); |
1263 | 1244 | ||
1264 | /* Initialize the LM85 chip */ | 1245 | /* Initialize the LM85 chip */ |
1265 | lm85_init_client(new_client); | 1246 | lm85_init_client(client); |
1266 | 1247 | ||
1267 | /* Register sysfs hooks */ | 1248 | /* Register sysfs hooks */ |
1268 | if ((err = sysfs_create_group(&new_client->dev.kobj, &lm85_group))) | 1249 | err = sysfs_create_group(&client->dev.kobj, &lm85_group); |
1250 | if (err) | ||
1269 | goto ERROR2; | 1251 | goto ERROR2; |
1270 | 1252 | ||
1271 | /* The ADT7463 has an optional VRM 10 mode where pin 21 is used | 1253 | /* The ADT7463 has an optional VRM 10 mode where pin 21 is used |
1272 | as a sixth digital VID input rather than an analog input. */ | 1254 | as a sixth digital VID input rather than an analog input. */ |
1273 | data->vid = lm85_read_value(new_client, LM85_REG_VID); | 1255 | data->vid = lm85_read_value(client, LM85_REG_VID); |
1274 | if (!(kind == adt7463 && (data->vid & 0x80))) | 1256 | if (!(kind == adt7463 && (data->vid & 0x80))) |
1275 | if ((err = sysfs_create_group(&new_client->dev.kobj, | 1257 | if ((err = sysfs_create_group(&client->dev.kobj, |
1276 | &lm85_group_in4))) | 1258 | &lm85_group_in4))) |
1277 | goto ERROR3; | 1259 | goto ERROR3; |
1278 | 1260 | ||
1279 | /* The EMC6D100 has 3 additional voltage inputs */ | 1261 | /* The EMC6D100 has 3 additional voltage inputs */ |
1280 | if (kind == emc6d100) | 1262 | if (kind == emc6d100) |
1281 | if ((err = sysfs_create_group(&new_client->dev.kobj, | 1263 | if ((err = sysfs_create_group(&client->dev.kobj, |
1282 | &lm85_group_in567))) | 1264 | &lm85_group_in567))) |
1283 | goto ERROR3; | 1265 | goto ERROR3; |
1284 | 1266 | ||
1285 | data->hwmon_dev = hwmon_device_register(&new_client->dev); | 1267 | data->hwmon_dev = hwmon_device_register(&client->dev); |
1286 | if (IS_ERR(data->hwmon_dev)) { | 1268 | if (IS_ERR(data->hwmon_dev)) { |
1287 | err = PTR_ERR(data->hwmon_dev); | 1269 | err = PTR_ERR(data->hwmon_dev); |
1288 | goto ERROR3; | 1270 | goto ERROR3; |
@@ -1291,16 +1273,16 @@ static int lm85_detect(struct i2c_adapter *adapter, int address, | |||
1291 | return 0; | 1273 | return 0; |
1292 | 1274 | ||
1293 | /* Error out and cleanup code */ | 1275 | /* Error out and cleanup code */ |
1294 | ERROR3: | 1276 | ERROR3: |
1295 | sysfs_remove_group(&new_client->dev.kobj, &lm85_group); | 1277 | sysfs_remove_group(&client->dev.kobj, &lm85_group); |
1296 | sysfs_remove_group(&new_client->dev.kobj, &lm85_group_in4); | 1278 | sysfs_remove_group(&client->dev.kobj, &lm85_group_in4); |
1297 | if (kind == emc6d100) | 1279 | if (kind == emc6d100) |
1298 | sysfs_remove_group(&new_client->dev.kobj, &lm85_group_in567); | 1280 | sysfs_remove_group(&client->dev.kobj, &lm85_group_in567); |
1299 | ERROR2: | 1281 | ERROR2: |
1300 | i2c_detach_client(new_client); | 1282 | i2c_detach_client(client); |
1301 | ERROR1: | 1283 | ERROR1: |
1302 | kfree(data); | 1284 | kfree(data); |
1303 | ERROR0: | 1285 | ERROR0: |
1304 | return err; | 1286 | return err; |
1305 | } | 1287 | } |
1306 | 1288 | ||
@@ -1323,100 +1305,46 @@ static int lm85_read_value(struct i2c_client *client, u8 reg) | |||
1323 | int res; | 1305 | int res; |
1324 | 1306 | ||
1325 | /* What size location is it? */ | 1307 | /* What size location is it? */ |
1326 | switch( reg ) { | 1308 | switch (reg) { |
1327 | case LM85_REG_FAN(0) : /* Read WORD data */ | 1309 | case LM85_REG_FAN(0): /* Read WORD data */ |
1328 | case LM85_REG_FAN(1) : | 1310 | case LM85_REG_FAN(1): |
1329 | case LM85_REG_FAN(2) : | 1311 | case LM85_REG_FAN(2): |
1330 | case LM85_REG_FAN(3) : | 1312 | case LM85_REG_FAN(3): |
1331 | case LM85_REG_FAN_MIN(0) : | 1313 | case LM85_REG_FAN_MIN(0): |
1332 | case LM85_REG_FAN_MIN(1) : | 1314 | case LM85_REG_FAN_MIN(1): |
1333 | case LM85_REG_FAN_MIN(2) : | 1315 | case LM85_REG_FAN_MIN(2): |
1334 | case LM85_REG_FAN_MIN(3) : | 1316 | case LM85_REG_FAN_MIN(3): |
1335 | case LM85_REG_ALARM1 : /* Read both bytes at once */ | 1317 | case LM85_REG_ALARM1: /* Read both bytes at once */ |
1336 | res = i2c_smbus_read_byte_data(client, reg) & 0xff ; | 1318 | res = i2c_smbus_read_byte_data(client, reg) & 0xff; |
1337 | res |= i2c_smbus_read_byte_data(client, reg+1) << 8 ; | 1319 | res |= i2c_smbus_read_byte_data(client, reg + 1) << 8; |
1338 | break ; | 1320 | break; |
1339 | case ADT7463_REG_TMIN_CTL1 : /* Read WORD MSB, LSB */ | ||
1340 | res = i2c_smbus_read_byte_data(client, reg) << 8 ; | ||
1341 | res |= i2c_smbus_read_byte_data(client, reg+1) & 0xff ; | ||
1342 | break ; | ||
1343 | default: /* Read BYTE data */ | 1321 | default: /* Read BYTE data */ |
1344 | res = i2c_smbus_read_byte_data(client, reg); | 1322 | res = i2c_smbus_read_byte_data(client, reg); |
1345 | break ; | 1323 | break; |
1346 | } | 1324 | } |
1347 | 1325 | ||
1348 | return res ; | 1326 | return res; |
1349 | } | 1327 | } |
1350 | 1328 | ||
1351 | static int lm85_write_value(struct i2c_client *client, u8 reg, int value) | 1329 | static void lm85_write_value(struct i2c_client *client, u8 reg, int value) |
1352 | { | 1330 | { |
1353 | int res ; | 1331 | switch (reg) { |
1354 | 1332 | case LM85_REG_FAN(0): /* Write WORD data */ | |
1355 | switch( reg ) { | 1333 | case LM85_REG_FAN(1): |
1356 | case LM85_REG_FAN(0) : /* Write WORD data */ | 1334 | case LM85_REG_FAN(2): |
1357 | case LM85_REG_FAN(1) : | 1335 | case LM85_REG_FAN(3): |
1358 | case LM85_REG_FAN(2) : | 1336 | case LM85_REG_FAN_MIN(0): |
1359 | case LM85_REG_FAN(3) : | 1337 | case LM85_REG_FAN_MIN(1): |
1360 | case LM85_REG_FAN_MIN(0) : | 1338 | case LM85_REG_FAN_MIN(2): |
1361 | case LM85_REG_FAN_MIN(1) : | 1339 | case LM85_REG_FAN_MIN(3): |
1362 | case LM85_REG_FAN_MIN(2) : | ||
1363 | case LM85_REG_FAN_MIN(3) : | ||
1364 | /* NOTE: ALARM is read only, so not included here */ | 1340 | /* NOTE: ALARM is read only, so not included here */ |
1365 | res = i2c_smbus_write_byte_data(client, reg, value & 0xff) ; | 1341 | i2c_smbus_write_byte_data(client, reg, value & 0xff); |
1366 | res |= i2c_smbus_write_byte_data(client, reg+1, (value>>8) & 0xff) ; | 1342 | i2c_smbus_write_byte_data(client, reg + 1, value >> 8); |
1367 | break ; | 1343 | break; |
1368 | case ADT7463_REG_TMIN_CTL1 : /* Write WORD MSB, LSB */ | ||
1369 | res = i2c_smbus_write_byte_data(client, reg, (value>>8) & 0xff); | ||
1370 | res |= i2c_smbus_write_byte_data(client, reg+1, value & 0xff) ; | ||
1371 | break ; | ||
1372 | default: /* Write BYTE data */ | 1344 | default: /* Write BYTE data */ |
1373 | res = i2c_smbus_write_byte_data(client, reg, value); | 1345 | i2c_smbus_write_byte_data(client, reg, value); |
1374 | break ; | 1346 | break; |
1375 | } | 1347 | } |
1376 | |||
1377 | return res ; | ||
1378 | } | ||
1379 | |||
1380 | static void lm85_init_client(struct i2c_client *client) | ||
1381 | { | ||
1382 | int value; | ||
1383 | struct lm85_data *data = i2c_get_clientdata(client); | ||
1384 | |||
1385 | dev_dbg(&client->dev, "Initializing device\n"); | ||
1386 | |||
1387 | /* Warn if part was not "READY" */ | ||
1388 | value = lm85_read_value(client, LM85_REG_CONFIG); | ||
1389 | dev_dbg(&client->dev, "LM85_REG_CONFIG is: 0x%02x\n", value); | ||
1390 | if( value & 0x02 ) { | ||
1391 | dev_err(&client->dev, "Client (%d,0x%02x) config is locked.\n", | ||
1392 | i2c_adapter_id(client->adapter), client->addr ); | ||
1393 | }; | ||
1394 | if( ! (value & 0x04) ) { | ||
1395 | dev_err(&client->dev, "Client (%d,0x%02x) is not ready.\n", | ||
1396 | i2c_adapter_id(client->adapter), client->addr ); | ||
1397 | }; | ||
1398 | if( value & 0x10 | ||
1399 | && ( data->type == adm1027 | ||
1400 | || data->type == adt7463 ) ) { | ||
1401 | dev_err(&client->dev, "Client (%d,0x%02x) VxI mode is set. " | ||
1402 | "Please report this to the lm85 maintainer.\n", | ||
1403 | i2c_adapter_id(client->adapter), client->addr ); | ||
1404 | }; | ||
1405 | |||
1406 | /* WE INTENTIONALLY make no changes to the limits, | ||
1407 | * offsets, pwms, fans and zones. If they were | ||
1408 | * configured, we don't want to mess with them. | ||
1409 | * If they weren't, the default is 100% PWM, no | ||
1410 | * control and will suffice until 'sensors -s' | ||
1411 | * can be run by the user. | ||
1412 | */ | ||
1413 | |||
1414 | /* Start monitoring */ | ||
1415 | value = lm85_read_value(client, LM85_REG_CONFIG); | ||
1416 | /* Try to clear LOCK, Set START, save everything else */ | ||
1417 | value = (value & ~ 0x02) | 0x01 ; | ||
1418 | dev_dbg(&client->dev, "Setting CONFIG to: 0x%02x\n", value); | ||
1419 | lm85_write_value(client, LM85_REG_CONFIG, value); | ||
1420 | } | 1348 | } |
1421 | 1349 | ||
1422 | static struct lm85_data *lm85_update_device(struct device *dev) | 1350 | static struct lm85_data *lm85_update_device(struct device *dev) |
@@ -1427,28 +1355,30 @@ static struct lm85_data *lm85_update_device(struct device *dev) | |||
1427 | 1355 | ||
1428 | mutex_lock(&data->update_lock); | 1356 | mutex_lock(&data->update_lock); |
1429 | 1357 | ||
1430 | if ( !data->valid || | 1358 | if (!data->valid || |
1431 | time_after(jiffies, data->last_reading + LM85_DATA_INTERVAL) ) { | 1359 | time_after(jiffies, data->last_reading + LM85_DATA_INTERVAL)) { |
1432 | /* Things that change quickly */ | 1360 | /* Things that change quickly */ |
1433 | dev_dbg(&client->dev, "Reading sensor values\n"); | 1361 | dev_dbg(&client->dev, "Reading sensor values\n"); |
1434 | 1362 | ||
1435 | /* Have to read extended bits first to "freeze" the | 1363 | /* Have to read extended bits first to "freeze" the |
1436 | * more significant bits that are read later. | 1364 | * more significant bits that are read later. |
1437 | * There are 2 additional resolution bits per channel and we | 1365 | * There are 2 additional resolution bits per channel and we |
1438 | * have room for 4, so we shift them to the left. | 1366 | * have room for 4, so we shift them to the left. |
1439 | */ | 1367 | */ |
1440 | if ( (data->type == adm1027) || (data->type == adt7463) ) { | 1368 | if (data->type == adm1027 || data->type == adt7463) { |
1441 | int ext1 = lm85_read_value(client, | 1369 | int ext1 = lm85_read_value(client, |
1442 | ADM1027_REG_EXTEND_ADC1); | 1370 | ADM1027_REG_EXTEND_ADC1); |
1443 | int ext2 = lm85_read_value(client, | 1371 | int ext2 = lm85_read_value(client, |
1444 | ADM1027_REG_EXTEND_ADC2); | 1372 | ADM1027_REG_EXTEND_ADC2); |
1445 | int val = (ext1 << 8) + ext2; | 1373 | int val = (ext1 << 8) + ext2; |
1446 | 1374 | ||
1447 | for(i = 0; i <= 4; i++) | 1375 | for (i = 0; i <= 4; i++) |
1448 | data->in_ext[i] = ((val>>(i * 2))&0x03) << 2; | 1376 | data->in_ext[i] = |
1377 | ((val >> (i * 2)) & 0x03) << 2; | ||
1449 | 1378 | ||
1450 | for(i = 0; i <= 2; i++) | 1379 | for (i = 0; i <= 2; i++) |
1451 | data->temp_ext[i] = (val>>((i + 4) * 2))&0x0c; | 1380 | data->temp_ext[i] = |
1381 | (val >> ((i + 4) * 2)) & 0x0c; | ||
1452 | } | 1382 | } |
1453 | 1383 | ||
1454 | data->vid = lm85_read_value(client, LM85_REG_VID); | 1384 | data->vid = lm85_read_value(client, LM85_REG_VID); |
@@ -1456,6 +1386,8 @@ static struct lm85_data *lm85_update_device(struct device *dev) | |||
1456 | for (i = 0; i <= 3; ++i) { | 1386 | for (i = 0; i <= 3; ++i) { |
1457 | data->in[i] = | 1387 | data->in[i] = |
1458 | lm85_read_value(client, LM85_REG_IN(i)); | 1388 | lm85_read_value(client, LM85_REG_IN(i)); |
1389 | data->fan[i] = | ||
1390 | lm85_read_value(client, LM85_REG_FAN(i)); | ||
1459 | } | 1391 | } |
1460 | 1392 | ||
1461 | if (!(data->type == adt7463 && (data->vid & 0x80))) { | 1393 | if (!(data->type == adt7463 && (data->vid & 0x80))) { |
@@ -1463,38 +1395,25 @@ static struct lm85_data *lm85_update_device(struct device *dev) | |||
1463 | LM85_REG_IN(4)); | 1395 | LM85_REG_IN(4)); |
1464 | } | 1396 | } |
1465 | 1397 | ||
1466 | for (i = 0; i <= 3; ++i) { | ||
1467 | data->fan[i] = | ||
1468 | lm85_read_value(client, LM85_REG_FAN(i)); | ||
1469 | } | ||
1470 | |||
1471 | for (i = 0; i <= 2; ++i) { | 1398 | for (i = 0; i <= 2; ++i) { |
1472 | data->temp[i] = | 1399 | data->temp[i] = |
1473 | lm85_read_value(client, LM85_REG_TEMP(i)); | 1400 | lm85_read_value(client, LM85_REG_TEMP(i)); |
1474 | } | ||
1475 | |||
1476 | for (i = 0; i <= 2; ++i) { | ||
1477 | data->pwm[i] = | 1401 | data->pwm[i] = |
1478 | lm85_read_value(client, LM85_REG_PWM(i)); | 1402 | lm85_read_value(client, LM85_REG_PWM(i)); |
1479 | } | 1403 | } |
1480 | 1404 | ||
1481 | data->alarms = lm85_read_value(client, LM85_REG_ALARM1); | 1405 | data->alarms = lm85_read_value(client, LM85_REG_ALARM1); |
1482 | 1406 | ||
1483 | if ( data->type == adt7463 ) { | 1407 | if (data->type == emc6d100) { |
1484 | if( data->therm_total < ULONG_MAX - 256 ) { | ||
1485 | data->therm_total += | ||
1486 | lm85_read_value(client, ADT7463_REG_THERM ); | ||
1487 | } | ||
1488 | } else if ( data->type == emc6d100 ) { | ||
1489 | /* Three more voltage sensors */ | 1408 | /* Three more voltage sensors */ |
1490 | for (i = 5; i <= 7; ++i) { | 1409 | for (i = 5; i <= 7; ++i) { |
1491 | data->in[i] = | 1410 | data->in[i] = lm85_read_value(client, |
1492 | lm85_read_value(client, EMC6D100_REG_IN(i)); | 1411 | EMC6D100_REG_IN(i)); |
1493 | } | 1412 | } |
1494 | /* More alarm bits */ | 1413 | /* More alarm bits */ |
1495 | data->alarms |= | 1414 | data->alarms |= lm85_read_value(client, |
1496 | lm85_read_value(client, EMC6D100_REG_ALARM3) << 16; | 1415 | EMC6D100_REG_ALARM3) << 16; |
1497 | } else if (data->type == emc6d102 ) { | 1416 | } else if (data->type == emc6d102) { |
1498 | /* Have to read LSB bits after the MSB ones because | 1417 | /* Have to read LSB bits after the MSB ones because |
1499 | the reading of the MSB bits has frozen the | 1418 | the reading of the MSB bits has frozen the |
1500 | LSBs (backward from the ADM1027). | 1419 | LSBs (backward from the ADM1027). |
@@ -1509,20 +1428,20 @@ static struct lm85_data *lm85_update_device(struct device *dev) | |||
1509 | EMC6D102_REG_EXTEND_ADC4); | 1428 | EMC6D102_REG_EXTEND_ADC4); |
1510 | data->in_ext[0] = ext3 & 0x0f; | 1429 | data->in_ext[0] = ext3 & 0x0f; |
1511 | data->in_ext[1] = ext4 & 0x0f; | 1430 | data->in_ext[1] = ext4 & 0x0f; |
1512 | data->in_ext[2] = (ext4 >> 4) & 0x0f; | 1431 | data->in_ext[2] = ext4 >> 4; |
1513 | data->in_ext[3] = (ext3 >> 4) & 0x0f; | 1432 | data->in_ext[3] = ext3 >> 4; |
1514 | data->in_ext[4] = (ext2 >> 4) & 0x0f; | 1433 | data->in_ext[4] = ext2 >> 4; |
1515 | 1434 | ||
1516 | data->temp_ext[0] = ext1 & 0x0f; | 1435 | data->temp_ext[0] = ext1 & 0x0f; |
1517 | data->temp_ext[1] = ext2 & 0x0f; | 1436 | data->temp_ext[1] = ext2 & 0x0f; |
1518 | data->temp_ext[2] = (ext1 >> 4) & 0x0f; | 1437 | data->temp_ext[2] = ext1 >> 4; |
1519 | } | 1438 | } |
1520 | 1439 | ||
1521 | data->last_reading = jiffies ; | 1440 | data->last_reading = jiffies; |
1522 | }; /* last_reading */ | 1441 | } /* last_reading */ |
1523 | 1442 | ||
1524 | if ( !data->valid || | 1443 | if (!data->valid || |
1525 | time_after(jiffies, data->last_config + LM85_CONFIG_INTERVAL) ) { | 1444 | time_after(jiffies, data->last_config + LM85_CONFIG_INTERVAL)) { |
1526 | /* Things that don't change often */ | 1445 | /* Things that don't change often */ |
1527 | dev_dbg(&client->dev, "Reading config values\n"); | 1446 | dev_dbg(&client->dev, "Reading config values\n"); |
1528 | 1447 | ||
@@ -1531,6 +1450,8 @@ static struct lm85_data *lm85_update_device(struct device *dev) | |||
1531 | lm85_read_value(client, LM85_REG_IN_MIN(i)); | 1450 | lm85_read_value(client, LM85_REG_IN_MIN(i)); |
1532 | data->in_max[i] = | 1451 | data->in_max[i] = |
1533 | lm85_read_value(client, LM85_REG_IN_MAX(i)); | 1452 | lm85_read_value(client, LM85_REG_IN_MAX(i)); |
1453 | data->fan_min[i] = | ||
1454 | lm85_read_value(client, LM85_REG_FAN_MIN(i)); | ||
1534 | } | 1455 | } |
1535 | 1456 | ||
1536 | if (!(data->type == adt7463 && (data->vid & 0x80))) { | 1457 | if (!(data->type == adt7463 && (data->vid & 0x80))) { |
@@ -1540,34 +1461,28 @@ static struct lm85_data *lm85_update_device(struct device *dev) | |||
1540 | LM85_REG_IN_MAX(4)); | 1461 | LM85_REG_IN_MAX(4)); |
1541 | } | 1462 | } |
1542 | 1463 | ||
1543 | if ( data->type == emc6d100 ) { | 1464 | if (data->type == emc6d100) { |
1544 | for (i = 5; i <= 7; ++i) { | 1465 | for (i = 5; i <= 7; ++i) { |
1545 | data->in_min[i] = | 1466 | data->in_min[i] = lm85_read_value(client, |
1546 | lm85_read_value(client, EMC6D100_REG_IN_MIN(i)); | 1467 | EMC6D100_REG_IN_MIN(i)); |
1547 | data->in_max[i] = | 1468 | data->in_max[i] = lm85_read_value(client, |
1548 | lm85_read_value(client, EMC6D100_REG_IN_MAX(i)); | 1469 | EMC6D100_REG_IN_MAX(i)); |
1549 | } | 1470 | } |
1550 | } | 1471 | } |
1551 | 1472 | ||
1552 | for (i = 0; i <= 3; ++i) { | ||
1553 | data->fan_min[i] = | ||
1554 | lm85_read_value(client, LM85_REG_FAN_MIN(i)); | ||
1555 | } | ||
1556 | |||
1557 | for (i = 0; i <= 2; ++i) { | 1473 | for (i = 0; i <= 2; ++i) { |
1474 | int val; | ||
1475 | |||
1558 | data->temp_min[i] = | 1476 | data->temp_min[i] = |
1559 | lm85_read_value(client, LM85_REG_TEMP_MIN(i)); | 1477 | lm85_read_value(client, LM85_REG_TEMP_MIN(i)); |
1560 | data->temp_max[i] = | 1478 | data->temp_max[i] = |
1561 | lm85_read_value(client, LM85_REG_TEMP_MAX(i)); | 1479 | lm85_read_value(client, LM85_REG_TEMP_MAX(i)); |
1562 | } | ||
1563 | 1480 | ||
1564 | for (i = 0; i <= 2; ++i) { | ||
1565 | int val ; | ||
1566 | data->autofan[i].config = | 1481 | data->autofan[i].config = |
1567 | lm85_read_value(client, LM85_REG_AFAN_CONFIG(i)); | 1482 | lm85_read_value(client, LM85_REG_AFAN_CONFIG(i)); |
1568 | val = lm85_read_value(client, LM85_REG_AFAN_RANGE(i)); | 1483 | val = lm85_read_value(client, LM85_REG_AFAN_RANGE(i)); |
1569 | data->autofan[i].freq = val & 0x07 ; | 1484 | data->autofan[i].freq = val & 0x07; |
1570 | data->zone[i].range = (val >> 4) & 0x0f ; | 1485 | data->zone[i].range = val >> 4; |
1571 | data->autofan[i].min_pwm = | 1486 | data->autofan[i].min_pwm = |
1572 | lm85_read_value(client, LM85_REG_AFAN_MINPWM(i)); | 1487 | lm85_read_value(client, LM85_REG_AFAN_MINPWM(i)); |
1573 | data->zone[i].limit = | 1488 | data->zone[i].limit = |
@@ -1577,50 +1492,19 @@ static struct lm85_data *lm85_update_device(struct device *dev) | |||
1577 | } | 1492 | } |
1578 | 1493 | ||
1579 | i = lm85_read_value(client, LM85_REG_AFAN_SPIKE1); | 1494 | i = lm85_read_value(client, LM85_REG_AFAN_SPIKE1); |
1580 | data->smooth[0] = i & 0x0f ; | 1495 | data->autofan[0].min_off = (i & 0x20) != 0; |
1581 | data->syncpwm3 = i & 0x10 ; /* Save PWM3 config */ | 1496 | data->autofan[1].min_off = (i & 0x40) != 0; |
1582 | data->autofan[0].min_off = (i & 0x20) != 0 ; | 1497 | data->autofan[2].min_off = (i & 0x80) != 0; |
1583 | data->autofan[1].min_off = (i & 0x40) != 0 ; | ||
1584 | data->autofan[2].min_off = (i & 0x80) != 0 ; | ||
1585 | i = lm85_read_value(client, LM85_REG_AFAN_SPIKE2); | ||
1586 | data->smooth[1] = (i>>4) & 0x0f ; | ||
1587 | data->smooth[2] = i & 0x0f ; | ||
1588 | 1498 | ||
1589 | i = lm85_read_value(client, LM85_REG_AFAN_HYST1); | 1499 | i = lm85_read_value(client, LM85_REG_AFAN_HYST1); |
1590 | data->zone[0].hyst = (i>>4) & 0x0f ; | 1500 | data->zone[0].hyst = i >> 4; |
1591 | data->zone[1].hyst = i & 0x0f ; | 1501 | data->zone[1].hyst = i & 0x0f; |
1592 | 1502 | ||
1593 | i = lm85_read_value(client, LM85_REG_AFAN_HYST2); | 1503 | i = lm85_read_value(client, LM85_REG_AFAN_HYST2); |
1594 | data->zone[2].hyst = (i>>4) & 0x0f ; | 1504 | data->zone[2].hyst = i >> 4; |
1595 | 1505 | ||
1596 | if ( (data->type == lm85b) || (data->type == lm85c) ) { | ||
1597 | data->tach_mode = lm85_read_value(client, | ||
1598 | LM85_REG_TACH_MODE ); | ||
1599 | data->spinup_ctl = lm85_read_value(client, | ||
1600 | LM85_REG_SPINUP_CTL ); | ||
1601 | } else if ( (data->type == adt7463) || (data->type == adm1027) ) { | ||
1602 | if ( data->type == adt7463 ) { | ||
1603 | for (i = 0; i <= 2; ++i) { | ||
1604 | data->oppoint[i] = lm85_read_value(client, | ||
1605 | ADT7463_REG_OPPOINT(i) ); | ||
1606 | } | ||
1607 | data->tmin_ctl = lm85_read_value(client, | ||
1608 | ADT7463_REG_TMIN_CTL1 ); | ||
1609 | data->therm_limit = lm85_read_value(client, | ||
1610 | ADT7463_REG_THERM_LIMIT ); | ||
1611 | } | ||
1612 | for (i = 0; i <= 2; ++i) { | ||
1613 | data->temp_offset[i] = lm85_read_value(client, | ||
1614 | ADM1027_REG_TEMP_OFFSET(i) ); | ||
1615 | } | ||
1616 | data->tach_mode = lm85_read_value(client, | ||
1617 | ADM1027_REG_CONFIG3 ); | ||
1618 | data->fan_ppr = lm85_read_value(client, | ||
1619 | ADM1027_REG_FAN_PPR ); | ||
1620 | } | ||
1621 | |||
1622 | data->last_config = jiffies; | 1506 | data->last_config = jiffies; |
1623 | }; /* last_config */ | 1507 | } /* last_config */ |
1624 | 1508 | ||
1625 | data->valid = 1; | 1509 | data->valid = 1; |
1626 | 1510 | ||
@@ -1635,17 +1519,15 @@ static int __init sm_lm85_init(void) | |||
1635 | return i2c_add_driver(&lm85_driver); | 1519 | return i2c_add_driver(&lm85_driver); |
1636 | } | 1520 | } |
1637 | 1521 | ||
1638 | static void __exit sm_lm85_exit(void) | 1522 | static void __exit sm_lm85_exit(void) |
1639 | { | 1523 | { |
1640 | i2c_del_driver(&lm85_driver); | 1524 | i2c_del_driver(&lm85_driver); |
1641 | } | 1525 | } |
1642 | 1526 | ||
1643 | /* Thanks to Richard Barrington for adding the LM85 to sensors-detect. | ||
1644 | * Thanks to Margit Schubert-While <margitsw@t-online.de> for help with | ||
1645 | * post 2.7.0 CVS changes. | ||
1646 | */ | ||
1647 | MODULE_LICENSE("GPL"); | 1527 | MODULE_LICENSE("GPL"); |
1648 | MODULE_AUTHOR("Philip Pokorny <ppokorny@penguincomputing.com>, Margit Schubert-While <margitsw@t-online.de>, Justin Thiessen <jthiessen@penguincomputing.com"); | 1528 | MODULE_AUTHOR("Philip Pokorny <ppokorny@penguincomputing.com>, " |
1529 | "Margit Schubert-While <margitsw@t-online.de>, " | ||
1530 | "Justin Thiessen <jthiessen@penguincomputing.com>"); | ||
1649 | MODULE_DESCRIPTION("LM85-B, LM85-C driver"); | 1531 | MODULE_DESCRIPTION("LM85-B, LM85-C driver"); |
1650 | 1532 | ||
1651 | module_init(sm_lm85_init); | 1533 | module_init(sm_lm85_init); |