diff options
Diffstat (limited to 'drivers/i2c')
-rw-r--r-- | drivers/i2c/chips/via686a.c | 276 |
1 files changed, 140 insertions, 136 deletions
diff --git a/drivers/i2c/chips/via686a.c b/drivers/i2c/chips/via686a.c index 3140ae8882a9..9370aaf29c3b 100644 --- a/drivers/i2c/chips/via686a.c +++ b/drivers/i2c/chips/via686a.c | |||
@@ -1,12 +1,12 @@ | |||
1 | /* | 1 | /* |
2 | via686a.c - Part of lm_sensors, Linux kernel modules | 2 | via686a.c - Part of lm_sensors, Linux kernel modules |
3 | for hardware monitoring | 3 | for hardware monitoring |
4 | 4 | ||
5 | Copyright (c) 1998 - 2002 Frodo Looijaard <frodol@dds.nl>, | 5 | Copyright (c) 1998 - 2002 Frodo Looijaard <frodol@dds.nl>, |
6 | Kyösti Mälkki <kmalkki@cc.hut.fi>, | 6 | Kyösti Mälkki <kmalkki@cc.hut.fi>, |
7 | Mark Studebaker <mdsxyz123@yahoo.com>, | 7 | Mark Studebaker <mdsxyz123@yahoo.com>, |
8 | and Bob Dougherty <bobd@stanford.edu> | 8 | and Bob Dougherty <bobd@stanford.edu> |
9 | (Some conversion-factor data were contributed by Jonathan Teh Soon Yew | 9 | (Some conversion-factor data were contributed by Jonathan Teh Soon Yew |
10 | <j.teh@iname.com> and Alex van Kaam <darkside@chello.nl>.) | 10 | <j.teh@iname.com> and Alex van Kaam <darkside@chello.nl>.) |
11 | 11 | ||
12 | This program is free software; you can redistribute it and/or modify | 12 | This program is free software; you can redistribute it and/or modify |
@@ -64,19 +64,19 @@ SENSORS_INSMOD_1(via686a); | |||
64 | /* Many VIA686A constants specified below */ | 64 | /* Many VIA686A constants specified below */ |
65 | 65 | ||
66 | /* Length of ISA address segment */ | 66 | /* Length of ISA address segment */ |
67 | #define VIA686A_EXTENT 0x80 | 67 | #define VIA686A_EXTENT 0x80 |
68 | #define VIA686A_BASE_REG 0x70 | 68 | #define VIA686A_BASE_REG 0x70 |
69 | #define VIA686A_ENABLE_REG 0x74 | 69 | #define VIA686A_ENABLE_REG 0x74 |
70 | 70 | ||
71 | /* The VIA686A registers */ | 71 | /* The VIA686A registers */ |
72 | /* ins numbered 0-4 */ | 72 | /* ins numbered 0-4 */ |
73 | #define VIA686A_REG_IN_MAX(nr) (0x2b + ((nr) * 2)) | 73 | #define VIA686A_REG_IN_MAX(nr) (0x2b + ((nr) * 2)) |
74 | #define VIA686A_REG_IN_MIN(nr) (0x2c + ((nr) * 2)) | 74 | #define VIA686A_REG_IN_MIN(nr) (0x2c + ((nr) * 2)) |
75 | #define VIA686A_REG_IN(nr) (0x22 + (nr)) | 75 | #define VIA686A_REG_IN(nr) (0x22 + (nr)) |
76 | 76 | ||
77 | /* fans numbered 1-2 */ | 77 | /* fans numbered 1-2 */ |
78 | #define VIA686A_REG_FAN_MIN(nr) (0x3a + (nr)) | 78 | #define VIA686A_REG_FAN_MIN(nr) (0x3a + (nr)) |
79 | #define VIA686A_REG_FAN(nr) (0x28 + (nr)) | 79 | #define VIA686A_REG_FAN(nr) (0x28 + (nr)) |
80 | 80 | ||
81 | /* the following values are as speced by VIA: */ | 81 | /* the following values are as speced by VIA: */ |
82 | static const u8 regtemp[] = { 0x20, 0x21, 0x1f }; | 82 | static const u8 regtemp[] = { 0x20, 0x21, 0x1f }; |
@@ -87,26 +87,28 @@ static const u8 reghyst[] = { 0x3a, 0x3e, 0x1e }; | |||
87 | #define VIA686A_REG_TEMP(nr) (regtemp[nr]) | 87 | #define VIA686A_REG_TEMP(nr) (regtemp[nr]) |
88 | #define VIA686A_REG_TEMP_OVER(nr) (regover[nr]) | 88 | #define VIA686A_REG_TEMP_OVER(nr) (regover[nr]) |
89 | #define VIA686A_REG_TEMP_HYST(nr) (reghyst[nr]) | 89 | #define VIA686A_REG_TEMP_HYST(nr) (reghyst[nr]) |
90 | #define VIA686A_REG_TEMP_LOW1 0x4b // bits 7-6 | 90 | /* bits 7-6 */ |
91 | #define VIA686A_REG_TEMP_LOW23 0x49 // 2 = bits 5-4, 3 = bits 7-6 | 91 | #define VIA686A_REG_TEMP_LOW1 0x4b |
92 | 92 | /* 2 = bits 5-4, 3 = bits 7-6 */ | |
93 | #define VIA686A_REG_ALARM1 0x41 | 93 | #define VIA686A_REG_TEMP_LOW23 0x49 |
94 | #define VIA686A_REG_ALARM2 0x42 | 94 | |
95 | #define VIA686A_REG_FANDIV 0x47 | 95 | #define VIA686A_REG_ALARM1 0x41 |
96 | #define VIA686A_REG_CONFIG 0x40 | 96 | #define VIA686A_REG_ALARM2 0x42 |
97 | /* The following register sets temp interrupt mode (bits 1-0 for temp1, | 97 | #define VIA686A_REG_FANDIV 0x47 |
98 | #define VIA686A_REG_CONFIG 0x40 | ||
99 | /* The following register sets temp interrupt mode (bits 1-0 for temp1, | ||
98 | 3-2 for temp2, 5-4 for temp3). Modes are: | 100 | 3-2 for temp2, 5-4 for temp3). Modes are: |
99 | 00 interrupt stays as long as value is out-of-range | 101 | 00 interrupt stays as long as value is out-of-range |
100 | 01 interrupt is cleared once register is read (default) | 102 | 01 interrupt is cleared once register is read (default) |
101 | 10 comparator mode- like 00, but ignores hysteresis | 103 | 10 comparator mode- like 00, but ignores hysteresis |
102 | 11 same as 00 */ | 104 | 11 same as 00 */ |
103 | #define VIA686A_REG_TEMP_MODE 0x4b | 105 | #define VIA686A_REG_TEMP_MODE 0x4b |
104 | /* We'll just assume that you want to set all 3 simultaneously: */ | 106 | /* We'll just assume that you want to set all 3 simultaneously: */ |
105 | #define VIA686A_TEMP_MODE_MASK 0x3F | 107 | #define VIA686A_TEMP_MODE_MASK 0x3F |
106 | #define VIA686A_TEMP_MODE_CONTINUOUS (0x00) | 108 | #define VIA686A_TEMP_MODE_CONTINUOUS 0x00 |
107 | 109 | ||
108 | /* Conversions. Limit checking is only done on the TO_REG | 110 | /* Conversions. Limit checking is only done on the TO_REG |
109 | variants. | 111 | variants. |
110 | 112 | ||
111 | ********* VOLTAGE CONVERSIONS (Bob Dougherty) ******** | 113 | ********* VOLTAGE CONVERSIONS (Bob Dougherty) ******** |
112 | From HWMon.cpp (Copyright 1998-2000 Jonathan Teh Soon Yew): | 114 | From HWMon.cpp (Copyright 1998-2000 Jonathan Teh Soon Yew): |
@@ -119,7 +121,7 @@ static const u8 reghyst[] = { 0x3a, 0x3e, 0x1e }; | |||
119 | That is: | 121 | That is: |
120 | volts = (25*regVal+133)*factor | 122 | volts = (25*regVal+133)*factor |
121 | regVal = (volts/factor-133)/25 | 123 | regVal = (volts/factor-133)/25 |
122 | (These conversions were contributed by Jonathan Teh Soon Yew | 124 | (These conversions were contributed by Jonathan Teh Soon Yew |
123 | <j.teh@iname.com>) */ | 125 | <j.teh@iname.com>) */ |
124 | static inline u8 IN_TO_REG(long val, int inNum) | 126 | static inline u8 IN_TO_REG(long val, int inNum) |
125 | { | 127 | { |
@@ -180,55 +182,55 @@ static inline u8 FAN_TO_REG(long rpm, int div) | |||
180 | else | 182 | else |
181 | return double(temp)*0.924-127.33; | 183 | return double(temp)*0.924-127.33; |
182 | 184 | ||
183 | A fifth-order polynomial fits the unofficial data (provided by Alex van | 185 | A fifth-order polynomial fits the unofficial data (provided by Alex van |
184 | Kaam <darkside@chello.nl>) a bit better. It also give more reasonable | 186 | Kaam <darkside@chello.nl>) a bit better. It also give more reasonable |
185 | numbers on my machine (ie. they agree with what my BIOS tells me). | 187 | numbers on my machine (ie. they agree with what my BIOS tells me). |
186 | Here's the fifth-order fit to the 8-bit data: | 188 | Here's the fifth-order fit to the 8-bit data: |
187 | temp = 1.625093e-10*val^5 - 1.001632e-07*val^4 + 2.457653e-05*val^3 - | 189 | temp = 1.625093e-10*val^5 - 1.001632e-07*val^4 + 2.457653e-05*val^3 - |
188 | 2.967619e-03*val^2 + 2.175144e-01*val - 7.090067e+0. | 190 | 2.967619e-03*val^2 + 2.175144e-01*val - 7.090067e+0. |
189 | 191 | ||
190 | (2000-10-25- RFD: thanks to Uwe Andersen <uandersen@mayah.com> for | 192 | (2000-10-25- RFD: thanks to Uwe Andersen <uandersen@mayah.com> for |
191 | finding my typos in this formula!) | 193 | finding my typos in this formula!) |
192 | 194 | ||
193 | Alas, none of the elegant function-fit solutions will work because we | 195 | Alas, none of the elegant function-fit solutions will work because we |
194 | aren't allowed to use floating point in the kernel and doing it with | 196 | aren't allowed to use floating point in the kernel and doing it with |
195 | integers doesn't rpovide enough precision. So we'll do boring old | 197 | integers doesn't provide enough precision. So we'll do boring old |
196 | look-up table stuff. The unofficial data (see below) have effectively | 198 | look-up table stuff. The unofficial data (see below) have effectively |
197 | 7-bit resolution (they are rounded to the nearest degree). I'm assuming | 199 | 7-bit resolution (they are rounded to the nearest degree). I'm assuming |
198 | that the transfer function of the device is monotonic and smooth, so a | 200 | that the transfer function of the device is monotonic and smooth, so a |
199 | smooth function fit to the data will allow us to get better precision. | 201 | smooth function fit to the data will allow us to get better precision. |
200 | I used the 5th-order poly fit described above and solved for | 202 | I used the 5th-order poly fit described above and solved for |
201 | VIA register values 0-255. I *10 before rounding, so we get tenth-degree | 203 | VIA register values 0-255. I *10 before rounding, so we get tenth-degree |
202 | precision. (I could have done all 1024 values for our 10-bit readings, | 204 | precision. (I could have done all 1024 values for our 10-bit readings, |
203 | but the function is very linear in the useful range (0-80 deg C), so | 205 | but the function is very linear in the useful range (0-80 deg C), so |
204 | we'll just use linear interpolation for 10-bit readings.) So, tempLUT | 206 | we'll just use linear interpolation for 10-bit readings.) So, tempLUT |
205 | is the temp at via register values 0-255: */ | 207 | is the temp at via register values 0-255: */ |
206 | static const long tempLUT[] = | 208 | static const long tempLUT[] = |
207 | { -709, -688, -667, -646, -627, -607, -589, -570, -553, -536, -519, | 209 | { -709, -688, -667, -646, -627, -607, -589, -570, -553, -536, -519, |
208 | -503, -487, -471, -456, -442, -428, -414, -400, -387, -375, | 210 | -503, -487, -471, -456, -442, -428, -414, -400, -387, -375, |
209 | -362, -350, -339, -327, -316, -305, -295, -285, -275, -265, | 211 | -362, -350, -339, -327, -316, -305, -295, -285, -275, -265, |
210 | -255, -246, -237, -229, -220, -212, -204, -196, -188, -180, | 212 | -255, -246, -237, -229, -220, -212, -204, -196, -188, -180, |
211 | -173, -166, -159, -152, -145, -139, -132, -126, -120, -114, | 213 | -173, -166, -159, -152, -145, -139, -132, -126, -120, -114, |
212 | -108, -102, -96, -91, -85, -80, -74, -69, -64, -59, -54, -49, | 214 | -108, -102, -96, -91, -85, -80, -74, -69, -64, -59, -54, -49, |
213 | -44, -39, -34, -29, -25, -20, -15, -11, -6, -2, 3, 7, 12, 16, | 215 | -44, -39, -34, -29, -25, -20, -15, -11, -6, -2, 3, 7, 12, 16, |
214 | 20, 25, 29, 33, 37, 42, 46, 50, 54, 59, 63, 67, 71, 75, 79, 84, | 216 | 20, 25, 29, 33, 37, 42, 46, 50, 54, 59, 63, 67, 71, 75, 79, 84, |
215 | 88, 92, 96, 100, 104, 109, 113, 117, 121, 125, 130, 134, 138, | 217 | 88, 92, 96, 100, 104, 109, 113, 117, 121, 125, 130, 134, 138, |
216 | 142, 146, 151, 155, 159, 163, 168, 172, 176, 181, 185, 189, | 218 | 142, 146, 151, 155, 159, 163, 168, 172, 176, 181, 185, 189, |
217 | 193, 198, 202, 206, 211, 215, 219, 224, 228, 232, 237, 241, | 219 | 193, 198, 202, 206, 211, 215, 219, 224, 228, 232, 237, 241, |
218 | 245, 250, 254, 259, 263, 267, 272, 276, 281, 285, 290, 294, | 220 | 245, 250, 254, 259, 263, 267, 272, 276, 281, 285, 290, 294, |
219 | 299, 303, 307, 312, 316, 321, 325, 330, 334, 339, 344, 348, | 221 | 299, 303, 307, 312, 316, 321, 325, 330, 334, 339, 344, 348, |
220 | 353, 357, 362, 366, 371, 376, 380, 385, 390, 395, 399, 404, | 222 | 353, 357, 362, 366, 371, 376, 380, 385, 390, 395, 399, 404, |
221 | 409, 414, 419, 423, 428, 433, 438, 443, 449, 454, 459, 464, | 223 | 409, 414, 419, 423, 428, 433, 438, 443, 449, 454, 459, 464, |
222 | 469, 475, 480, 486, 491, 497, 502, 508, 514, 520, 526, 532, | 224 | 469, 475, 480, 486, 491, 497, 502, 508, 514, 520, 526, 532, |
223 | 538, 544, 551, 557, 564, 571, 578, 584, 592, 599, 606, 614, | 225 | 538, 544, 551, 557, 564, 571, 578, 584, 592, 599, 606, 614, |
224 | 621, 629, 637, 645, 654, 662, 671, 680, 689, 698, 708, 718, | 226 | 621, 629, 637, 645, 654, 662, 671, 680, 689, 698, 708, 718, |
225 | 728, 738, 749, 759, 770, 782, 793, 805, 818, 830, 843, 856, | 227 | 728, 738, 749, 759, 770, 782, 793, 805, 818, 830, 843, 856, |
226 | 870, 883, 898, 912, 927, 943, 958, 975, 991, 1008, 1026, 1044, | 228 | 870, 883, 898, 912, 927, 943, 958, 975, 991, 1008, 1026, 1044, |
227 | 1062, 1081, 1101, 1121, 1141, 1162, 1184, 1206, 1229, 1252, | 229 | 1062, 1081, 1101, 1121, 1141, 1162, 1184, 1206, 1229, 1252, |
228 | 1276, 1301, 1326, 1352, 1378, 1406, 1434, 1462 | 230 | 1276, 1301, 1326, 1352, 1378, 1406, 1434, 1462 |
229 | }; | 231 | }; |
230 | 232 | ||
231 | /* the original LUT values from Alex van Kaam <darkside@chello.nl> | 233 | /* the original LUT values from Alex van Kaam <darkside@chello.nl> |
232 | (for via register values 12-240): | 234 | (for via register values 12-240): |
233 | {-50,-49,-47,-45,-43,-41,-39,-38,-37,-35,-34,-33,-32,-31, | 235 | {-50,-49,-47,-45,-43,-41,-39,-38,-37,-35,-34,-33,-32,-31, |
234 | -30,-29,-28,-27,-26,-25,-24,-24,-23,-22,-21,-20,-20,-19,-18,-17,-17,-16,-15, | 236 | -30,-29,-28,-27,-26,-25,-24,-24,-23,-22,-21,-20,-20,-19,-18,-17,-17,-16,-15, |
@@ -243,26 +245,26 @@ static const long tempLUT[] = | |||
243 | 245 | ||
244 | 246 | ||
245 | Here's the reverse LUT. I got it by doing a 6-th order poly fit (needed | 247 | Here's the reverse LUT. I got it by doing a 6-th order poly fit (needed |
246 | an extra term for a good fit to these inverse data!) and then | 248 | an extra term for a good fit to these inverse data!) and then |
247 | solving for each temp value from -50 to 110 (the useable range for | 249 | solving for each temp value from -50 to 110 (the useable range for |
248 | this chip). Here's the fit: | 250 | this chip). Here's the fit: |
249 | viaRegVal = -1.160370e-10*val^6 +3.193693e-08*val^5 - 1.464447e-06*val^4 | 251 | viaRegVal = -1.160370e-10*val^6 +3.193693e-08*val^5 - 1.464447e-06*val^4 |
250 | - 2.525453e-04*val^3 + 1.424593e-02*val^2 + 2.148941e+00*val +7.275808e+01) | 252 | - 2.525453e-04*val^3 + 1.424593e-02*val^2 + 2.148941e+00*val +7.275808e+01) |
251 | Note that n=161: */ | 253 | Note that n=161: */ |
252 | static const u8 viaLUT[] = | 254 | static const u8 viaLUT[] = |
253 | { 12, 12, 13, 14, 14, 15, 16, 16, 17, 18, 18, 19, 20, 20, 21, 22, 23, | 255 | { 12, 12, 13, 14, 14, 15, 16, 16, 17, 18, 18, 19, 20, 20, 21, 22, 23, |
254 | 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 35, 36, 37, 39, 40, | 256 | 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 35, 36, 37, 39, 40, |
255 | 41, 43, 45, 46, 48, 49, 51, 53, 55, 57, 59, 60, 62, 64, 66, | 257 | 41, 43, 45, 46, 48, 49, 51, 53, 55, 57, 59, 60, 62, 64, 66, |
256 | 69, 71, 73, 75, 77, 79, 82, 84, 86, 88, 91, 93, 95, 98, 100, | 258 | 69, 71, 73, 75, 77, 79, 82, 84, 86, 88, 91, 93, 95, 98, 100, |
257 | 103, 105, 107, 110, 112, 115, 117, 119, 122, 124, 126, 129, | 259 | 103, 105, 107, 110, 112, 115, 117, 119, 122, 124, 126, 129, |
258 | 131, 134, 136, 138, 140, 143, 145, 147, 150, 152, 154, 156, | 260 | 131, 134, 136, 138, 140, 143, 145, 147, 150, 152, 154, 156, |
259 | 158, 160, 162, 164, 166, 168, 170, 172, 174, 176, 178, 180, | 261 | 158, 160, 162, 164, 166, 168, 170, 172, 174, 176, 178, 180, |
260 | 182, 183, 185, 187, 188, 190, 192, 193, 195, 196, 198, 199, | 262 | 182, 183, 185, 187, 188, 190, 192, 193, 195, 196, 198, 199, |
261 | 200, 202, 203, 205, 206, 207, 208, 209, 210, 211, 212, 213, | 263 | 200, 202, 203, 205, 206, 207, 208, 209, 210, 211, 212, 213, |
262 | 214, 215, 216, 217, 218, 219, 220, 221, 222, 222, 223, 224, | 264 | 214, 215, 216, 217, 218, 219, 220, 221, 222, 222, 223, 224, |
263 | 225, 226, 226, 227, 228, 228, 229, 230, 230, 231, 232, 232, | 265 | 225, 226, 226, 227, 228, 228, 229, 230, 230, 231, 232, 232, |
264 | 233, 233, 234, 235, 235, 236, 236, 237, 237, 238, 238, 239, | 266 | 233, 233, 234, 235, 235, 236, 236, 237, 237, 238, 238, 239, |
265 | 239, 240 | 267 | 239, 240 |
266 | }; | 268 | }; |
267 | 269 | ||
268 | /* Converting temps to (8-bit) hyst and over registers | 270 | /* Converting temps to (8-bit) hyst and over registers |
@@ -270,7 +272,7 @@ static const u8 viaLUT[] = | |||
270 | The +50 is because the temps start at -50 */ | 272 | The +50 is because the temps start at -50 */ |
271 | static inline u8 TEMP_TO_REG(long val) | 273 | static inline u8 TEMP_TO_REG(long val) |
272 | { | 274 | { |
273 | return viaLUT[val <= -50000 ? 0 : val >= 110000 ? 160 : | 275 | return viaLUT[val <= -50000 ? 0 : val >= 110000 ? 160 : |
274 | (val < 0 ? val - 500 : val + 500) / 1000 + 50]; | 276 | (val < 0 ? val - 500 : val + 500) / 1000 + 50]; |
275 | } | 277 | } |
276 | 278 | ||
@@ -289,7 +291,7 @@ static inline long TEMP_FROM_REG10(u16 val) | |||
289 | 291 | ||
290 | /* do some linear interpolation */ | 292 | /* do some linear interpolation */ |
291 | return (tempLUT[eightBits] * (4 - twoBits) + | 293 | return (tempLUT[eightBits] * (4 - twoBits) + |
292 | tempLUT[eightBits + 1] * twoBits) * 25; | 294 | tempLUT[eightBits + 1] * twoBits) * 25; |
293 | } | 295 | } |
294 | 296 | ||
295 | #define DIV_FROM_REG(val) (1 << (val)) | 297 | #define DIV_FROM_REG(val) (1 << (val)) |
@@ -354,28 +356,28 @@ static ssize_t show_in_max(struct device *dev, char *buf, int nr) { | |||
354 | return sprintf(buf, "%ld\n", IN_FROM_REG(data->in_max[nr], nr)); | 356 | return sprintf(buf, "%ld\n", IN_FROM_REG(data->in_max[nr], nr)); |
355 | } | 357 | } |
356 | 358 | ||
357 | static ssize_t set_in_min(struct device *dev, const char *buf, | 359 | static ssize_t set_in_min(struct device *dev, const char *buf, |
358 | size_t count, int nr) { | 360 | size_t count, int nr) { |
359 | struct i2c_client *client = to_i2c_client(dev); | 361 | struct i2c_client *client = to_i2c_client(dev); |
360 | struct via686a_data *data = i2c_get_clientdata(client); | 362 | struct via686a_data *data = i2c_get_clientdata(client); |
361 | unsigned long val = simple_strtoul(buf, NULL, 10); | 363 | unsigned long val = simple_strtoul(buf, NULL, 10); |
362 | 364 | ||
363 | down(&data->update_lock); | 365 | down(&data->update_lock); |
364 | data->in_min[nr] = IN_TO_REG(val,nr); | 366 | data->in_min[nr] = IN_TO_REG(val, nr); |
365 | via686a_write_value(client, VIA686A_REG_IN_MIN(nr), | 367 | via686a_write_value(client, VIA686A_REG_IN_MIN(nr), |
366 | data->in_min[nr]); | 368 | data->in_min[nr]); |
367 | up(&data->update_lock); | 369 | up(&data->update_lock); |
368 | return count; | 370 | return count; |
369 | } | 371 | } |
370 | static ssize_t set_in_max(struct device *dev, const char *buf, | 372 | static ssize_t set_in_max(struct device *dev, const char *buf, |
371 | size_t count, int nr) { | 373 | size_t count, int nr) { |
372 | struct i2c_client *client = to_i2c_client(dev); | 374 | struct i2c_client *client = to_i2c_client(dev); |
373 | struct via686a_data *data = i2c_get_clientdata(client); | 375 | struct via686a_data *data = i2c_get_clientdata(client); |
374 | unsigned long val = simple_strtoul(buf, NULL, 10); | 376 | unsigned long val = simple_strtoul(buf, NULL, 10); |
375 | 377 | ||
376 | down(&data->update_lock); | 378 | down(&data->update_lock); |
377 | data->in_max[nr] = IN_TO_REG(val,nr); | 379 | data->in_max[nr] = IN_TO_REG(val, nr); |
378 | via686a_write_value(client, VIA686A_REG_IN_MAX(nr), | 380 | via686a_write_value(client, VIA686A_REG_IN_MAX(nr), |
379 | data->in_max[nr]); | 381 | data->in_max[nr]); |
380 | up(&data->update_lock); | 382 | up(&data->update_lock); |
381 | return count; | 383 | return count; |
@@ -431,7 +433,7 @@ static ssize_t show_temp_hyst(struct device *dev, char *buf, int nr) { | |||
431 | struct via686a_data *data = via686a_update_device(dev); | 433 | struct via686a_data *data = via686a_update_device(dev); |
432 | return sprintf(buf, "%ld\n", TEMP_FROM_REG(data->temp_hyst[nr])); | 434 | return sprintf(buf, "%ld\n", TEMP_FROM_REG(data->temp_hyst[nr])); |
433 | } | 435 | } |
434 | static ssize_t set_temp_over(struct device *dev, const char *buf, | 436 | static ssize_t set_temp_over(struct device *dev, const char *buf, |
435 | size_t count, int nr) { | 437 | size_t count, int nr) { |
436 | struct i2c_client *client = to_i2c_client(dev); | 438 | struct i2c_client *client = to_i2c_client(dev); |
437 | struct via686a_data *data = i2c_get_clientdata(client); | 439 | struct via686a_data *data = i2c_get_clientdata(client); |
@@ -443,7 +445,7 @@ static ssize_t set_temp_over(struct device *dev, const char *buf, | |||
443 | up(&data->update_lock); | 445 | up(&data->update_lock); |
444 | return count; | 446 | return count; |
445 | } | 447 | } |
446 | static ssize_t set_temp_hyst(struct device *dev, const char *buf, | 448 | static ssize_t set_temp_hyst(struct device *dev, const char *buf, |
447 | size_t count, int nr) { | 449 | size_t count, int nr) { |
448 | struct i2c_client *client = to_i2c_client(dev); | 450 | struct i2c_client *client = to_i2c_client(dev); |
449 | struct via686a_data *data = i2c_get_clientdata(client); | 451 | struct via686a_data *data = i2c_get_clientdata(client); |
@@ -484,7 +486,7 @@ static DEVICE_ATTR(temp##offset##_input, S_IRUGO, show_temp_##offset, NULL);\ | |||
484 | static DEVICE_ATTR(temp##offset##_max, S_IRUGO | S_IWUSR, \ | 486 | static DEVICE_ATTR(temp##offset##_max, S_IRUGO | S_IWUSR, \ |
485 | show_temp_##offset##_over, set_temp_##offset##_over); \ | 487 | show_temp_##offset##_over, set_temp_##offset##_over); \ |
486 | static DEVICE_ATTR(temp##offset##_max_hyst, S_IRUGO | S_IWUSR, \ | 488 | static DEVICE_ATTR(temp##offset##_max_hyst, S_IRUGO | S_IWUSR, \ |
487 | show_temp_##offset##_hyst, set_temp_##offset##_hyst); | 489 | show_temp_##offset##_hyst, set_temp_##offset##_hyst); |
488 | 490 | ||
489 | show_temp_offset(1); | 491 | show_temp_offset(1); |
490 | show_temp_offset(2); | 492 | show_temp_offset(2); |
@@ -493,19 +495,19 @@ show_temp_offset(3); | |||
493 | /* 2 Fans */ | 495 | /* 2 Fans */ |
494 | static ssize_t show_fan(struct device *dev, char *buf, int nr) { | 496 | static ssize_t show_fan(struct device *dev, char *buf, int nr) { |
495 | struct via686a_data *data = via686a_update_device(dev); | 497 | struct via686a_data *data = via686a_update_device(dev); |
496 | return sprintf(buf,"%d\n", FAN_FROM_REG(data->fan[nr], | 498 | return sprintf(buf, "%d\n", FAN_FROM_REG(data->fan[nr], |
497 | DIV_FROM_REG(data->fan_div[nr])) ); | 499 | DIV_FROM_REG(data->fan_div[nr])) ); |
498 | } | 500 | } |
499 | static ssize_t show_fan_min(struct device *dev, char *buf, int nr) { | 501 | static ssize_t show_fan_min(struct device *dev, char *buf, int nr) { |
500 | struct via686a_data *data = via686a_update_device(dev); | 502 | struct via686a_data *data = via686a_update_device(dev); |
501 | return sprintf(buf,"%d\n", | 503 | return sprintf(buf, "%d\n", |
502 | FAN_FROM_REG(data->fan_min[nr], DIV_FROM_REG(data->fan_div[nr])) ); | 504 | FAN_FROM_REG(data->fan_min[nr], DIV_FROM_REG(data->fan_div[nr])) ); |
503 | } | 505 | } |
504 | static ssize_t show_fan_div(struct device *dev, char *buf, int nr) { | 506 | static ssize_t show_fan_div(struct device *dev, char *buf, int nr) { |
505 | struct via686a_data *data = via686a_update_device(dev); | 507 | struct via686a_data *data = via686a_update_device(dev); |
506 | return sprintf(buf,"%d\n", DIV_FROM_REG(data->fan_div[nr]) ); | 508 | return sprintf(buf, "%d\n", DIV_FROM_REG(data->fan_div[nr]) ); |
507 | } | 509 | } |
508 | static ssize_t set_fan_min(struct device *dev, const char *buf, | 510 | static ssize_t set_fan_min(struct device *dev, const char *buf, |
509 | size_t count, int nr) { | 511 | size_t count, int nr) { |
510 | struct i2c_client *client = to_i2c_client(dev); | 512 | struct i2c_client *client = to_i2c_client(dev); |
511 | struct via686a_data *data = i2c_get_clientdata(client); | 513 | struct via686a_data *data = i2c_get_clientdata(client); |
@@ -517,7 +519,7 @@ static ssize_t set_fan_min(struct device *dev, const char *buf, | |||
517 | up(&data->update_lock); | 519 | up(&data->update_lock); |
518 | return count; | 520 | return count; |
519 | } | 521 | } |
520 | static ssize_t set_fan_div(struct device *dev, const char *buf, | 522 | static ssize_t set_fan_div(struct device *dev, const char *buf, |
521 | size_t count, int nr) { | 523 | size_t count, int nr) { |
522 | struct i2c_client *client = to_i2c_client(dev); | 524 | struct i2c_client *client = to_i2c_client(dev); |
523 | struct via686a_data *data = i2c_get_clientdata(client); | 525 | struct via686a_data *data = i2c_get_clientdata(client); |
@@ -608,11 +610,12 @@ static int via686a_detect(struct i2c_adapter *adapter, int address, int kind) | |||
608 | } | 610 | } |
609 | 611 | ||
610 | /* 8231 requires multiple of 256, we enforce that on 686 as well */ | 612 | /* 8231 requires multiple of 256, we enforce that on 686 as well */ |
611 | if(force_addr) | 613 | if (force_addr) |
612 | address = force_addr & 0xFF00; | 614 | address = force_addr & 0xFF00; |
613 | 615 | ||
614 | if(force_addr) { | 616 | if (force_addr) { |
615 | dev_warn(&adapter->dev,"forcing ISA address 0x%04X\n", address); | 617 | dev_warn(&adapter->dev, "forcing ISA address 0x%04X\n", |
618 | address); | ||
616 | if (PCIBIOS_SUCCESSFUL != | 619 | if (PCIBIOS_SUCCESSFUL != |
617 | pci_write_config_word(s_bridge, VIA686A_BASE_REG, address)) | 620 | pci_write_config_word(s_bridge, VIA686A_BASE_REG, address)) |
618 | return -ENODEV; | 621 | return -ENODEV; |
@@ -621,17 +624,17 @@ static int via686a_detect(struct i2c_adapter *adapter, int address, int kind) | |||
621 | pci_read_config_word(s_bridge, VIA686A_ENABLE_REG, &val)) | 624 | pci_read_config_word(s_bridge, VIA686A_ENABLE_REG, &val)) |
622 | return -ENODEV; | 625 | return -ENODEV; |
623 | if (!(val & 0x0001)) { | 626 | if (!(val & 0x0001)) { |
624 | dev_warn(&adapter->dev,"enabling sensors\n"); | 627 | dev_warn(&adapter->dev, "enabling sensors\n"); |
625 | if (PCIBIOS_SUCCESSFUL != | 628 | if (PCIBIOS_SUCCESSFUL != |
626 | pci_write_config_word(s_bridge, VIA686A_ENABLE_REG, | 629 | pci_write_config_word(s_bridge, VIA686A_ENABLE_REG, |
627 | val | 0x0001)) | 630 | val | 0x0001)) |
628 | return -ENODEV; | 631 | return -ENODEV; |
629 | } | 632 | } |
630 | 633 | ||
631 | /* Reserve the ISA region */ | 634 | /* Reserve the ISA region */ |
632 | if (!request_region(address, VIA686A_EXTENT, via686a_driver.name)) { | 635 | if (!request_region(address, VIA686A_EXTENT, via686a_driver.name)) { |
633 | dev_err(&adapter->dev,"region 0x%x already in use!\n", | 636 | dev_err(&adapter->dev, "region 0x%x already in use!\n", |
634 | address); | 637 | address); |
635 | return -ENODEV; | 638 | return -ENODEV; |
636 | } | 639 | } |
637 | 640 | ||
@@ -656,7 +659,7 @@ static int via686a_detect(struct i2c_adapter *adapter, int address, int kind) | |||
656 | /* Tell the I2C layer a new client has arrived */ | 659 | /* Tell the I2C layer a new client has arrived */ |
657 | if ((err = i2c_attach_client(new_client))) | 660 | if ((err = i2c_attach_client(new_client))) |
658 | goto ERROR3; | 661 | goto ERROR3; |
659 | 662 | ||
660 | /* Initialize the VIA686A chip */ | 663 | /* Initialize the VIA686A chip */ |
661 | via686a_init_client(new_client); | 664 | via686a_init_client(new_client); |
662 | 665 | ||
@@ -695,9 +698,9 @@ static int via686a_detect(struct i2c_adapter *adapter, int address, int kind) | |||
695 | 698 | ||
696 | return 0; | 699 | return 0; |
697 | 700 | ||
698 | ERROR3: | 701 | ERROR3: |
699 | kfree(data); | 702 | kfree(data); |
700 | ERROR0: | 703 | ERROR0: |
701 | release_region(address, VIA686A_EXTENT); | 704 | release_region(address, VIA686A_EXTENT); |
702 | return err; | 705 | return err; |
703 | } | 706 | } |
@@ -728,7 +731,7 @@ static void via686a_init_client(struct i2c_client *client) | |||
728 | via686a_write_value(client, VIA686A_REG_CONFIG, (reg|0x01)&0x7F); | 731 | via686a_write_value(client, VIA686A_REG_CONFIG, (reg|0x01)&0x7F); |
729 | 732 | ||
730 | /* Configure temp interrupt mode for continuous-interrupt operation */ | 733 | /* Configure temp interrupt mode for continuous-interrupt operation */ |
731 | via686a_write_value(client, VIA686A_REG_TEMP_MODE, | 734 | via686a_write_value(client, VIA686A_REG_TEMP_MODE, |
732 | via686a_read_value(client, VIA686A_REG_TEMP_MODE) & | 735 | via686a_read_value(client, VIA686A_REG_TEMP_MODE) & |
733 | !(VIA686A_TEMP_MODE_MASK | VIA686A_TEMP_MODE_CONTINUOUS)); | 736 | !(VIA686A_TEMP_MODE_MASK | VIA686A_TEMP_MODE_CONTINUOUS)); |
734 | } | 737 | } |
@@ -768,7 +771,7 @@ static struct via686a_data *via686a_update_device(struct device *dev) | |||
768 | via686a_read_value(client, | 771 | via686a_read_value(client, |
769 | VIA686A_REG_TEMP_HYST(i)); | 772 | VIA686A_REG_TEMP_HYST(i)); |
770 | } | 773 | } |
771 | /* add in lower 2 bits | 774 | /* add in lower 2 bits |
772 | temp1 uses bits 7-6 of VIA686A_REG_TEMP_LOW1 | 775 | temp1 uses bits 7-6 of VIA686A_REG_TEMP_LOW1 |
773 | temp2 uses bits 5-4 of VIA686A_REG_TEMP_LOW23 | 776 | temp2 uses bits 5-4 of VIA686A_REG_TEMP_LOW23 |
774 | temp3 uses bits 7-6 of VIA686A_REG_TEMP_LOW23 | 777 | temp3 uses bits 7-6 of VIA686A_REG_TEMP_LOW23 |
@@ -800,35 +803,36 @@ static struct via686a_data *via686a_update_device(struct device *dev) | |||
800 | } | 803 | } |
801 | 804 | ||
802 | static struct pci_device_id via686a_pci_ids[] = { | 805 | static struct pci_device_id via686a_pci_ids[] = { |
803 | { PCI_DEVICE(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_82C686_4) }, | 806 | { PCI_DEVICE(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_82C686_4) }, |
804 | { 0, } | 807 | { 0, } |
805 | }; | 808 | }; |
806 | 809 | ||
807 | MODULE_DEVICE_TABLE(pci, via686a_pci_ids); | 810 | MODULE_DEVICE_TABLE(pci, via686a_pci_ids); |
808 | 811 | ||
809 | static int __devinit via686a_pci_probe(struct pci_dev *dev, | 812 | static int __devinit via686a_pci_probe(struct pci_dev *dev, |
810 | const struct pci_device_id *id) | 813 | const struct pci_device_id *id) |
811 | { | 814 | { |
812 | u16 val; | 815 | u16 val; |
813 | int addr = 0; | 816 | int addr = 0; |
814 | 817 | ||
815 | if (PCIBIOS_SUCCESSFUL != | 818 | if (PCIBIOS_SUCCESSFUL != |
816 | pci_read_config_word(dev, VIA686A_BASE_REG, &val)) | 819 | pci_read_config_word(dev, VIA686A_BASE_REG, &val)) |
817 | return -ENODEV; | 820 | return -ENODEV; |
818 | 821 | ||
819 | addr = val & ~(VIA686A_EXTENT - 1); | 822 | addr = val & ~(VIA686A_EXTENT - 1); |
820 | if (addr == 0 && force_addr == 0) { | 823 | if (addr == 0 && force_addr == 0) { |
821 | dev_err(&dev->dev,"base address not set - upgrade BIOS or use force_addr=0xaddr\n"); | 824 | dev_err(&dev->dev, "base address not set - upgrade BIOS " |
822 | return -ENODEV; | 825 | "or use force_addr=0xaddr\n"); |
823 | } | 826 | return -ENODEV; |
824 | if (force_addr) | 827 | } |
825 | addr = force_addr; /* so detect will get called */ | 828 | if (force_addr) |
826 | 829 | addr = force_addr; /* so detect will get called */ | |
827 | if (!addr) { | 830 | |
828 | dev_err(&dev->dev,"No Via 686A sensors found.\n"); | 831 | if (!addr) { |
829 | return -ENODEV; | 832 | dev_err(&dev->dev, "No Via 686A sensors found.\n"); |
830 | } | 833 | return -ENODEV; |
831 | normal_isa[0] = addr; | 834 | } |
835 | normal_isa[0] = addr; | ||
832 | 836 | ||
833 | s_bridge = pci_dev_get(dev); | 837 | s_bridge = pci_dev_get(dev); |
834 | if (i2c_add_driver(&via686a_driver)) { | 838 | if (i2c_add_driver(&via686a_driver)) { |
@@ -844,14 +848,14 @@ static int __devinit via686a_pci_probe(struct pci_dev *dev, | |||
844 | } | 848 | } |
845 | 849 | ||
846 | static struct pci_driver via686a_pci_driver = { | 850 | static struct pci_driver via686a_pci_driver = { |
847 | .name = "via686a", | 851 | .name = "via686a", |
848 | .id_table = via686a_pci_ids, | 852 | .id_table = via686a_pci_ids, |
849 | .probe = via686a_pci_probe, | 853 | .probe = via686a_pci_probe, |
850 | }; | 854 | }; |
851 | 855 | ||
852 | static int __init sm_via686a_init(void) | 856 | static int __init sm_via686a_init(void) |
853 | { | 857 | { |
854 | return pci_register_driver(&via686a_pci_driver); | 858 | return pci_register_driver(&via686a_pci_driver); |
855 | } | 859 | } |
856 | 860 | ||
857 | static void __exit sm_via686a_exit(void) | 861 | static void __exit sm_via686a_exit(void) |
@@ -865,8 +869,8 @@ static void __exit sm_via686a_exit(void) | |||
865 | } | 869 | } |
866 | 870 | ||
867 | MODULE_AUTHOR("Kyösti Mälkki <kmalkki@cc.hut.fi>, " | 871 | MODULE_AUTHOR("Kyösti Mälkki <kmalkki@cc.hut.fi>, " |
868 | "Mark Studebaker <mdsxyz123@yahoo.com> " | 872 | "Mark Studebaker <mdsxyz123@yahoo.com> " |
869 | "and Bob Dougherty <bobd@stanford.edu>"); | 873 | "and Bob Dougherty <bobd@stanford.edu>"); |
870 | MODULE_DESCRIPTION("VIA 686A Sensor device"); | 874 | MODULE_DESCRIPTION("VIA 686A Sensor device"); |
871 | MODULE_LICENSE("GPL"); | 875 | MODULE_LICENSE("GPL"); |
872 | 876 | ||