aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
authorGuenter Roeck <linux@roeck-us.net>2012-01-15 09:38:23 -0500
committerGuenter Roeck <guenter.roeck@ericsson.com>2012-03-18 21:27:28 -0400
commit9004ac8134de260b2eb9a6d8fb2dd4a37321e49b (patch)
treef1b2470f90597f248203ffd2397cebb4a8563e06 /drivers
parentbce2778df9ea32146d59344c027001e270911f4b (diff)
hwmon: (via686a) Fix checkpatch issues
Fixed: ERROR: do not use assignment in if condition ERROR: open brace '{' following function declarations go on the next line ERROR: space prohibited before that close parenthesis ')' ERROR: space required after that ',' (ctx:VxV) ERROR: spaces required around that '==' (ctx:VxV) ERROR: spaces required around that ':' (ctx:VxV) ERROR: spaces required around that '?' (ctx:VxV) ERROR: that open brace { should be on the previous line WARNING: line over 80 characters WARNING: simple_strtol is obsolete, use kstrtol instead WARNING: simple_strtoul is obsolete, use kstrtoul instead Modify multi-line comments to follow Documentation/CodingStyle. Not fixed (false positive): ERROR: Macros with multiple statements should be enclosed in a do - while loop Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Diffstat (limited to 'drivers')
-rw-r--r--drivers/hwmon/via686a.c355
1 files changed, 207 insertions, 148 deletions
diff --git a/drivers/hwmon/via686a.c b/drivers/hwmon/via686a.c
index 1424f0a1e498..288135d85e11 100644
--- a/drivers/hwmon/via686a.c
+++ b/drivers/hwmon/via686a.c
@@ -1,34 +1,35 @@
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 *
10 <j.teh@iname.com> and Alex van Kaam <darkside@chello.nl>.) 10 * (Some conversion-factor data were contributed by Jonathan Teh Soon Yew
11 11 * <j.teh@iname.com> and Alex van Kaam <darkside@chello.nl>.)
12 This program is free software; you can redistribute it and/or modify 12 *
13 it under the terms of the GNU General Public License as published by 13 * This program is free software; you can redistribute it and/or modify
14 the Free Software Foundation; either version 2 of the License, or 14 * it under the terms of the GNU General Public License as published by
15 (at your option) any later version. 15 * the Free Software Foundation; either version 2 of the License, or
16 16 * (at your option) any later version.
17 This program is distributed in the hope that it will be useful, 17 *
18 but WITHOUT ANY WARRANTY; without even the implied warranty of 18 * This program is distributed in the hope that it will be useful,
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 GNU General Public License for more details. 20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 21 * GNU General Public License for more details.
22 You should have received a copy of the GNU General Public License 22 *
23 along with this program; if not, write to the Free Software 23 * You should have received a copy of the GNU General Public License
24 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 24 * along with this program; if not, write to the Free Software
25*/ 25 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26 */
26 27
27/* 28/*
28 Supports the Via VT82C686A, VT82C686B south bridges. 29 * Supports the Via VT82C686A, VT82C686B south bridges.
29 Reports all as a 686A. 30 * Reports all as a 686A.
30 Warning - only supports a single device. 31 * Warning - only supports a single device.
31*/ 32 */
32 33
33#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 34#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
34 35
@@ -47,8 +48,10 @@
47#include <linux/io.h> 48#include <linux/io.h>
48 49
49 50
50/* If force_addr is set to anything different from 0, we forcibly enable 51/*
51 the device at the given address. */ 52 * If force_addr is set to anything different from 0, we forcibly enable
53 * the device at the given address.
54 */
52static unsigned short force_addr; 55static unsigned short force_addr;
53module_param(force_addr, ushort, 0); 56module_param(force_addr, ushort, 0);
54MODULE_PARM_DESC(force_addr, 57MODULE_PARM_DESC(force_addr,
@@ -57,9 +60,9 @@ MODULE_PARM_DESC(force_addr,
57static struct platform_device *pdev; 60static struct platform_device *pdev;
58 61
59/* 62/*
60 The Via 686a southbridge has a LM78-like chip integrated on the same IC. 63 * The Via 686a southbridge has a LM78-like chip integrated on the same IC.
61 This driver is a customized copy of lm78.c 64 * This driver is a customized copy of lm78.c
62*/ 65 */
63 66
64/* Many VIA686A constants specified below */ 67/* Many VIA686A constants specified below */
65 68
@@ -91,40 +94,46 @@ static const u8 VIA686A_REG_TEMP_HYST[] = { 0x3a, 0x3e, 0x1e };
91#define VIA686A_REG_ALARM2 0x42 94#define VIA686A_REG_ALARM2 0x42
92#define VIA686A_REG_FANDIV 0x47 95#define VIA686A_REG_FANDIV 0x47
93#define VIA686A_REG_CONFIG 0x40 96#define VIA686A_REG_CONFIG 0x40
94/* The following register sets temp interrupt mode (bits 1-0 for temp1, 97/*
95 3-2 for temp2, 5-4 for temp3). Modes are: 98 * The following register sets temp interrupt mode (bits 1-0 for temp1,
96 00 interrupt stays as long as value is out-of-range 99 * 3-2 for temp2, 5-4 for temp3). Modes are:
97 01 interrupt is cleared once register is read (default) 100 * 00 interrupt stays as long as value is out-of-range
98 10 comparator mode- like 00, but ignores hysteresis 101 * 01 interrupt is cleared once register is read (default)
99 11 same as 00 */ 102 * 10 comparator mode- like 00, but ignores hysteresis
103 * 11 same as 00
104 */
100#define VIA686A_REG_TEMP_MODE 0x4b 105#define VIA686A_REG_TEMP_MODE 0x4b
101/* 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: */
102#define VIA686A_TEMP_MODE_MASK 0x3F 107#define VIA686A_TEMP_MODE_MASK 0x3F
103#define VIA686A_TEMP_MODE_CONTINUOUS 0x00 108#define VIA686A_TEMP_MODE_CONTINUOUS 0x00
104 109
105/* Conversions. Limit checking is only done on the TO_REG 110/*
106 variants. 111 * Conversions. Limit checking is only done on the TO_REG
107 112 * variants.
108********* VOLTAGE CONVERSIONS (Bob Dougherty) ******** 113 *
109 From HWMon.cpp (Copyright 1998-2000 Jonathan Teh Soon Yew): 114 ******** VOLTAGE CONVERSIONS (Bob Dougherty) ********
110 voltagefactor[0]=1.25/2628; (2628/1.25=2102.4) // Vccp 115 * From HWMon.cpp (Copyright 1998-2000 Jonathan Teh Soon Yew):
111 voltagefactor[1]=1.25/2628; (2628/1.25=2102.4) // +2.5V 116 * voltagefactor[0]=1.25/2628; (2628/1.25=2102.4) // Vccp
112 voltagefactor[2]=1.67/2628; (2628/1.67=1573.7) // +3.3V 117 * voltagefactor[1]=1.25/2628; (2628/1.25=2102.4) // +2.5V
113 voltagefactor[3]=2.6/2628; (2628/2.60=1010.8) // +5V 118 * voltagefactor[2]=1.67/2628; (2628/1.67=1573.7) // +3.3V
114 voltagefactor[4]=6.3/2628; (2628/6.30=417.14) // +12V 119 * voltagefactor[3]=2.6/2628; (2628/2.60=1010.8) // +5V
115 in[i]=(data[i+2]*25.0+133)*voltagefactor[i]; 120 * voltagefactor[4]=6.3/2628; (2628/6.30=417.14) // +12V
116 That is: 121 * in[i]=(data[i+2]*25.0+133)*voltagefactor[i];
117 volts = (25*regVal+133)*factor 122 * That is:
118 regVal = (volts/factor-133)/25 123 * volts = (25*regVal+133)*factor
119 (These conversions were contributed by Jonathan Teh Soon Yew 124 * regVal = (volts/factor-133)/25
120 <j.teh@iname.com>) */ 125 * (These conversions were contributed by Jonathan Teh Soon Yew
126 * <j.teh@iname.com>)
127 */
121static inline u8 IN_TO_REG(long val, int inNum) 128static inline u8 IN_TO_REG(long val, int inNum)
122{ 129{
123 /* To avoid floating point, we multiply constants by 10 (100 for +12V). 130 /*
124 Rounding is done (120500 is actually 133000 - 12500). 131 * To avoid floating point, we multiply constants by 10 (100 for +12V).
125 Remember that val is expressed in 0.001V/bit, which is why we divide 132 * Rounding is done (120500 is actually 133000 - 12500).
126 by an additional 10000 (100000 for +12V): 1000 for val and 10 (100) 133 * Remember that val is expressed in 0.001V/bit, which is why we divide
127 for the constants. */ 134 * by an additional 10000 (100000 for +12V): 1000 for val and 10 (100)
135 * for the constants.
136 */
128 if (inNum <= 1) 137 if (inNum <= 1)
129 return (u8) 138 return (u8)
130 SENSORS_LIMIT((val * 21024 - 1205000) / 250000, 0, 255); 139 SENSORS_LIMIT((val * 21024 - 1205000) / 250000, 0, 255);
@@ -141,9 +150,11 @@ static inline u8 IN_TO_REG(long val, int inNum)
141 150
142static inline long IN_FROM_REG(u8 val, int inNum) 151static inline long IN_FROM_REG(u8 val, int inNum)
143{ 152{
144 /* To avoid floating point, we multiply constants by 10 (100 for +12V). 153 /*
145 We also multiply them by 1000 because we want 0.001V/bit for the 154 * To avoid floating point, we multiply constants by 10 (100 for +12V).
146 output value. Rounding is done. */ 155 * We also multiply them by 1000 because we want 0.001V/bit for the
156 * output value. Rounding is done.
157 */
147 if (inNum <= 1) 158 if (inNum <= 1)
148 return (long) ((250000 * val + 1330000 + 21024 / 2) / 21024); 159 return (long) ((250000 * val + 1330000 + 21024 / 2) / 21024);
149 else if (inNum == 2) 160 else if (inNum == 2)
@@ -155,9 +166,11 @@ static inline long IN_FROM_REG(u8 val, int inNum)
155} 166}
156 167
157/********* FAN RPM CONVERSIONS ********/ 168/********* FAN RPM CONVERSIONS ********/
158/* Higher register values = slower fans (the fan's strobe gates a counter). 169/*
159 But this chip saturates back at 0, not at 255 like all the other chips. 170 * Higher register values = slower fans (the fan's strobe gates a counter).
160 So, 0 means 0 RPM */ 171 * But this chip saturates back at 0, not at 255 like all the other chips.
172 * So, 0 means 0 RPM
173 */
161static inline u8 FAN_TO_REG(long rpm, int div) 174static inline u8 FAN_TO_REG(long rpm, int div)
162{ 175{
163 if (rpm == 0) 176 if (rpm == 0)
@@ -166,42 +179,45 @@ static inline u8 FAN_TO_REG(long rpm, int div)
166 return SENSORS_LIMIT((1350000 + rpm * div / 2) / (rpm * div), 1, 255); 179 return SENSORS_LIMIT((1350000 + rpm * div / 2) / (rpm * div), 1, 255);
167} 180}
168 181
169#define FAN_FROM_REG(val,div) ((val)==0?0:(val)==255?0:1350000/((val)*(div))) 182#define FAN_FROM_REG(val, div) ((val) == 0 ? 0 : (val) == 255 ? 0 : 1350000 / \
183 ((val) * (div)))
170 184
171/******** TEMP CONVERSIONS (Bob Dougherty) *********/ 185/******** TEMP CONVERSIONS (Bob Dougherty) *********/
172/* linear fits from HWMon.cpp (Copyright 1998-2000 Jonathan Teh Soon Yew) 186/*
173 if(temp<169) 187 * linear fits from HWMon.cpp (Copyright 1998-2000 Jonathan Teh Soon Yew)
174 return double(temp)*0.427-32.08; 188 * if(temp<169)
175 else if(temp>=169 && temp<=202) 189 * return double(temp)*0.427-32.08;
176 return double(temp)*0.582-58.16; 190 * else if(temp>=169 && temp<=202)
177 else 191 * return double(temp)*0.582-58.16;
178 return double(temp)*0.924-127.33; 192 * else
179 193 * return double(temp)*0.924-127.33;
180 A fifth-order polynomial fits the unofficial data (provided by Alex van 194 *
181 Kaam <darkside@chello.nl>) a bit better. It also give more reasonable 195 * A fifth-order polynomial fits the unofficial data (provided by Alex van
182 numbers on my machine (ie. they agree with what my BIOS tells me). 196 * Kaam <darkside@chello.nl>) a bit better. It also give more reasonable
183 Here's the fifth-order fit to the 8-bit data: 197 * numbers on my machine (ie. they agree with what my BIOS tells me).
184 temp = 1.625093e-10*val^5 - 1.001632e-07*val^4 + 2.457653e-05*val^3 - 198 * Here's the fifth-order fit to the 8-bit data:
185 2.967619e-03*val^2 + 2.175144e-01*val - 7.090067e+0. 199 * temp = 1.625093e-10*val^5 - 1.001632e-07*val^4 + 2.457653e-05*val^3 -
186 200 * 2.967619e-03*val^2 + 2.175144e-01*val - 7.090067e+0.
187 (2000-10-25- RFD: thanks to Uwe Andersen <uandersen@mayah.com> for 201 *
188 finding my typos in this formula!) 202 * (2000-10-25- RFD: thanks to Uwe Andersen <uandersen@mayah.com> for
189 203 * finding my typos in this formula!)
190 Alas, none of the elegant function-fit solutions will work because we 204 *
191 aren't allowed to use floating point in the kernel and doing it with 205 * Alas, none of the elegant function-fit solutions will work because we
192 integers doesn't provide enough precision. So we'll do boring old 206 * aren't allowed to use floating point in the kernel and doing it with
193 look-up table stuff. The unofficial data (see below) have effectively 207 * integers doesn't provide enough precision. So we'll do boring old
194 7-bit resolution (they are rounded to the nearest degree). I'm assuming 208 * look-up table stuff. The unofficial data (see below) have effectively
195 that the transfer function of the device is monotonic and smooth, so a 209 * 7-bit resolution (they are rounded to the nearest degree). I'm assuming
196 smooth function fit to the data will allow us to get better precision. 210 * that the transfer function of the device is monotonic and smooth, so a
197 I used the 5th-order poly fit described above and solved for 211 * smooth function fit to the data will allow us to get better precision.
198 VIA register values 0-255. I *10 before rounding, so we get tenth-degree 212 * I used the 5th-order poly fit described above and solved for
199 precision. (I could have done all 1024 values for our 10-bit readings, 213 * VIA register values 0-255. I *10 before rounding, so we get tenth-degree
200 but the function is very linear in the useful range (0-80 deg C), so 214 * precision. (I could have done all 1024 values for our 10-bit readings,
201 we'll just use linear interpolation for 10-bit readings.) So, tempLUT 215 * but the function is very linear in the useful range (0-80 deg C), so
202 is the temp at via register values 0-255: */ 216 * we'll just use linear interpolation for 10-bit readings.) So, tempLUT
203static const s16 tempLUT[] = 217 * is the temp at via register values 0-255:
204{ -709, -688, -667, -646, -627, -607, -589, -570, -553, -536, -519, 218 */
219static const s16 tempLUT[] = {
220 -709, -688, -667, -646, -627, -607, -589, -570, -553, -536, -519,
205 -503, -487, -471, -456, -442, -428, -414, -400, -387, -375, 221 -503, -487, -471, -456, -442, -428, -414, -400, -387, -375,
206 -362, -350, -339, -327, -316, -305, -295, -285, -275, -265, 222 -362, -350, -339, -327, -316, -305, -295, -285, -275, -265,
207 -255, -246, -237, -229, -220, -212, -204, -196, -188, -180, 223 -255, -246, -237, -229, -220, -212, -204, -196, -188, -180,
@@ -225,29 +241,31 @@ static const s16 tempLUT[] =
225 1276, 1301, 1326, 1352, 1378, 1406, 1434, 1462 241 1276, 1301, 1326, 1352, 1378, 1406, 1434, 1462
226}; 242};
227 243
228/* the original LUT values from Alex van Kaam <darkside@chello.nl> 244/*
229 (for via register values 12-240): 245 * the original LUT values from Alex van Kaam <darkside@chello.nl>
230{-50,-49,-47,-45,-43,-41,-39,-38,-37,-35,-34,-33,-32,-31, 246 * (for via register values 12-240):
231-30,-29,-28,-27,-26,-25,-24,-24,-23,-22,-21,-20,-20,-19,-18,-17,-17,-16,-15, 247 * {-50,-49,-47,-45,-43,-41,-39,-38,-37,-35,-34,-33,-32,-31,
232-15,-14,-14,-13,-12,-12,-11,-11,-10,-9,-9,-8,-8,-7,-7,-6,-6,-5,-5,-4,-4,-3, 248 * -30,-29,-28,-27,-26,-25,-24,-24,-23,-22,-21,-20,-20,-19,-18,-17,-17,-16,-15,
233-3,-2,-2,-1,-1,0,0,1,1,1,3,3,3,4,4,4,5,5,5,6,6,7,7,8,8,9,9,9,10,10,11,11,12, 249 * -15,-14,-14,-13,-12,-12,-11,-11,-10,-9,-9,-8,-8,-7,-7,-6,-6,-5,-5,-4,-4,-3,
23412,12,13,13,13,14,14,15,15,16,16,16,17,17,18,18,19,19,20,20,21,21,21,22,22, 250 * -3,-2,-2,-1,-1,0,0,1,1,1,3,3,3,4,4,4,5,5,5,6,6,7,7,8,8,9,9,9,10,10,11,11,12,
23522,23,23,24,24,25,25,26,26,26,27,27,27,28,28,29,29,30,30,30,31,31,32,32,33, 251 * 12,12,13,13,13,14,14,15,15,16,16,16,17,17,18,18,19,19,20,20,21,21,21,22,22,
23633,34,34,35,35,35,36,36,37,37,38,38,39,39,40,40,41,41,42,42,43,43,44,44,45, 252 * 22,23,23,24,24,25,25,26,26,26,27,27,27,28,28,29,29,30,30,30,31,31,32,32,33,
23745,46,46,47,48,48,49,49,50,51,51,52,52,53,53,54,55,55,56,57,57,58,59,59,60, 253 * 33,34,34,35,35,35,36,36,37,37,38,38,39,39,40,40,41,41,42,42,43,43,44,44,45,
23861,62,62,63,64,65,66,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,83,84, 254 * 45,46,46,47,48,48,49,49,50,51,51,52,52,53,53,54,55,55,56,57,57,58,59,59,60,
23985,86,88,89,91,92,94,96,97,99,101,103,105,107,109,110}; 255 * 61,62,62,63,64,65,66,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,83,84,
240 256 * 85,86,88,89,91,92,94,96,97,99,101,103,105,107,109,110};
241 257 *
242 Here's the reverse LUT. I got it by doing a 6-th order poly fit (needed 258 *
243 an extra term for a good fit to these inverse data!) and then 259 * Here's the reverse LUT. I got it by doing a 6-th order poly fit (needed
244 solving for each temp value from -50 to 110 (the useable range for 260 * an extra term for a good fit to these inverse data!) and then
245 this chip). Here's the fit: 261 * solving for each temp value from -50 to 110 (the useable range for
246 viaRegVal = -1.160370e-10*val^6 +3.193693e-08*val^5 - 1.464447e-06*val^4 262 * this chip). Here's the fit:
247 - 2.525453e-04*val^3 + 1.424593e-02*val^2 + 2.148941e+00*val +7.275808e+01) 263 * viaRegVal = -1.160370e-10*val^6 +3.193693e-08*val^5 - 1.464447e-06*val^4
248 Note that n=161: */ 264 * - 2.525453e-04*val^3 + 1.424593e-02*val^2 + 2.148941e+00*val +7.275808e+01)
249static const u8 viaLUT[] = 265 * Note that n=161:
250{ 12, 12, 13, 14, 14, 15, 16, 16, 17, 18, 18, 19, 20, 20, 21, 22, 23, 266 */
267static const u8 viaLUT[] = {
268 12, 12, 13, 14, 14, 15, 16, 16, 17, 18, 18, 19, 20, 20, 21, 22, 23,
251 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 35, 36, 37, 39, 40, 269 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 35, 36, 37, 39, 40,
252 41, 43, 45, 46, 48, 49, 51, 53, 55, 57, 59, 60, 62, 64, 66, 270 41, 43, 45, 46, 48, 49, 51, 53, 55, 57, 59, 60, 62, 64, 66,
253 69, 71, 73, 75, 77, 79, 82, 84, 86, 88, 91, 93, 95, 98, 100, 271 69, 71, 73, 75, 77, 79, 82, 84, 86, 88, 91, 93, 95, 98, 100,
@@ -262,9 +280,11 @@ static const u8 viaLUT[] =
262 239, 240 280 239, 240
263}; 281};
264 282
265/* Converting temps to (8-bit) hyst and over registers 283/*
266 No interpolation here. 284 * Converting temps to (8-bit) hyst and over registers
267 The +50 is because the temps start at -50 */ 285 * No interpolation here.
286 * The +50 is because the temps start at -50
287 */
268static inline u8 TEMP_TO_REG(long val) 288static inline u8 TEMP_TO_REG(long val)
269{ 289{
270 return viaLUT[val <= -50000 ? 0 : val >= 110000 ? 160 : 290 return viaLUT[val <= -50000 ? 0 : val >= 110000 ? 160 :
@@ -290,10 +310,12 @@ static inline long TEMP_FROM_REG10(u16 val)
290} 310}
291 311
292#define DIV_FROM_REG(val) (1 << (val)) 312#define DIV_FROM_REG(val) (1 << (val))
293#define DIV_TO_REG(val) ((val)==8?3:(val)==4?2:(val)==1?0:1) 313#define DIV_TO_REG(val) ((val) == 8 ? 3 : (val) == 4 ? 2 : (val) == 1 ? 0 : 1)
294 314
295/* For each registered chip, we need to keep some data in memory. 315/*
296 The structure is dynamically allocated. */ 316 * For each registered chip, we need to keep some data in memory.
317 * The structure is dynamically allocated.
318 */
297struct via686a_data { 319struct via686a_data {
298 unsigned short addr; 320 unsigned short addr;
299 const char *name; 321 const char *name;
@@ -365,7 +387,12 @@ static ssize_t set_in_min(struct device *dev, struct device_attribute *da,
365 struct via686a_data *data = dev_get_drvdata(dev); 387 struct via686a_data *data = dev_get_drvdata(dev);
366 struct sensor_device_attribute *attr = to_sensor_dev_attr(da); 388 struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
367 int nr = attr->index; 389 int nr = attr->index;
368 unsigned long val = simple_strtoul(buf, NULL, 10); 390 unsigned long val;
391 int err;
392
393 err = kstrtoul(buf, 10, &val);
394 if (err)
395 return err;
369 396
370 mutex_lock(&data->update_lock); 397 mutex_lock(&data->update_lock);
371 data->in_min[nr] = IN_TO_REG(val, nr); 398 data->in_min[nr] = IN_TO_REG(val, nr);
@@ -379,7 +406,12 @@ static ssize_t set_in_max(struct device *dev, struct device_attribute *da,
379 struct via686a_data *data = dev_get_drvdata(dev); 406 struct via686a_data *data = dev_get_drvdata(dev);
380 struct sensor_device_attribute *attr = to_sensor_dev_attr(da); 407 struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
381 int nr = attr->index; 408 int nr = attr->index;
382 unsigned long val = simple_strtoul(buf, NULL, 10); 409 unsigned long val;
410 int err;
411
412 err = kstrtoul(buf, 10, &val);
413 if (err)
414 return err;
383 415
384 mutex_lock(&data->update_lock); 416 mutex_lock(&data->update_lock);
385 data->in_max[nr] = IN_TO_REG(val, nr); 417 data->in_max[nr] = IN_TO_REG(val, nr);
@@ -429,7 +461,12 @@ static ssize_t set_temp_over(struct device *dev, struct device_attribute *da,
429 struct via686a_data *data = dev_get_drvdata(dev); 461 struct via686a_data *data = dev_get_drvdata(dev);
430 struct sensor_device_attribute *attr = to_sensor_dev_attr(da); 462 struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
431 int nr = attr->index; 463 int nr = attr->index;
432 int val = simple_strtol(buf, NULL, 10); 464 long val;
465 int err;
466
467 err = kstrtol(buf, 10, &val);
468 if (err)
469 return err;
433 470
434 mutex_lock(&data->update_lock); 471 mutex_lock(&data->update_lock);
435 data->temp_over[nr] = TEMP_TO_REG(val); 472 data->temp_over[nr] = TEMP_TO_REG(val);
@@ -443,7 +480,12 @@ static ssize_t set_temp_hyst(struct device *dev, struct device_attribute *da,
443 struct via686a_data *data = dev_get_drvdata(dev); 480 struct via686a_data *data = dev_get_drvdata(dev);
444 struct sensor_device_attribute *attr = to_sensor_dev_attr(da); 481 struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
445 int nr = attr->index; 482 int nr = attr->index;
446 int val = simple_strtol(buf, NULL, 10); 483 long val;
484 int err;
485
486 err = kstrtol(buf, 10, &val);
487 if (err)
488 return err;
447 489
448 mutex_lock(&data->update_lock); 490 mutex_lock(&data->update_lock);
449 data->temp_hyst[nr] = TEMP_TO_REG(val); 491 data->temp_hyst[nr] = TEMP_TO_REG(val);
@@ -471,7 +513,7 @@ static ssize_t show_fan(struct device *dev, struct device_attribute *da,
471 struct sensor_device_attribute *attr = to_sensor_dev_attr(da); 513 struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
472 int nr = attr->index; 514 int nr = attr->index;
473 return sprintf(buf, "%d\n", FAN_FROM_REG(data->fan[nr], 515 return sprintf(buf, "%d\n", FAN_FROM_REG(data->fan[nr],
474 DIV_FROM_REG(data->fan_div[nr])) ); 516 DIV_FROM_REG(data->fan_div[nr])));
475} 517}
476static ssize_t show_fan_min(struct device *dev, struct device_attribute *da, 518static ssize_t show_fan_min(struct device *dev, struct device_attribute *da,
477 char *buf) { 519 char *buf) {
@@ -479,21 +521,27 @@ static ssize_t show_fan_min(struct device *dev, struct device_attribute *da,
479 struct sensor_device_attribute *attr = to_sensor_dev_attr(da); 521 struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
480 int nr = attr->index; 522 int nr = attr->index;
481 return sprintf(buf, "%d\n", 523 return sprintf(buf, "%d\n",
482 FAN_FROM_REG(data->fan_min[nr], DIV_FROM_REG(data->fan_div[nr])) ); 524 FAN_FROM_REG(data->fan_min[nr],
525 DIV_FROM_REG(data->fan_div[nr])));
483} 526}
484static ssize_t show_fan_div(struct device *dev, struct device_attribute *da, 527static ssize_t show_fan_div(struct device *dev, struct device_attribute *da,
485 char *buf) { 528 char *buf) {
486 struct via686a_data *data = via686a_update_device(dev); 529 struct via686a_data *data = via686a_update_device(dev);
487 struct sensor_device_attribute *attr = to_sensor_dev_attr(da); 530 struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
488 int nr = attr->index; 531 int nr = attr->index;
489 return sprintf(buf, "%d\n", DIV_FROM_REG(data->fan_div[nr]) ); 532 return sprintf(buf, "%d\n", DIV_FROM_REG(data->fan_div[nr]));
490} 533}
491static ssize_t set_fan_min(struct device *dev, struct device_attribute *da, 534static ssize_t set_fan_min(struct device *dev, struct device_attribute *da,
492 const char *buf, size_t count) { 535 const char *buf, size_t count) {
493 struct via686a_data *data = dev_get_drvdata(dev); 536 struct via686a_data *data = dev_get_drvdata(dev);
494 struct sensor_device_attribute *attr = to_sensor_dev_attr(da); 537 struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
495 int nr = attr->index; 538 int nr = attr->index;
496 int val = simple_strtol(buf, NULL, 10); 539 unsigned long val;
540 int err;
541
542 err = kstrtoul(buf, 10, &val);
543 if (err)
544 return err;
497 545
498 mutex_lock(&data->update_lock); 546 mutex_lock(&data->update_lock);
499 data->fan_min[nr] = FAN_TO_REG(val, DIV_FROM_REG(data->fan_div[nr])); 547 data->fan_min[nr] = FAN_TO_REG(val, DIV_FROM_REG(data->fan_div[nr]));
@@ -506,8 +554,13 @@ static ssize_t set_fan_div(struct device *dev, struct device_attribute *da,
506 struct via686a_data *data = dev_get_drvdata(dev); 554 struct via686a_data *data = dev_get_drvdata(dev);
507 struct sensor_device_attribute *attr = to_sensor_dev_attr(da); 555 struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
508 int nr = attr->index; 556 int nr = attr->index;
509 int val = simple_strtol(buf, NULL, 10);
510 int old; 557 int old;
558 unsigned long val;
559 int err;
560
561 err = kstrtoul(buf, 10, &val);
562 if (err)
563 return err;
511 564
512 mutex_lock(&data->update_lock); 565 mutex_lock(&data->update_lock);
513 old = via686a_read_value(data, VIA686A_REG_FANDIV); 566 old = via686a_read_value(data, VIA686A_REG_FANDIV);
@@ -530,10 +583,13 @@ show_fan_offset(1);
530show_fan_offset(2); 583show_fan_offset(2);
531 584
532/* Alarms */ 585/* Alarms */
533static ssize_t show_alarms(struct device *dev, struct device_attribute *attr, char *buf) { 586static ssize_t show_alarms(struct device *dev, struct device_attribute *attr,
587 char *buf)
588{
534 struct via686a_data *data = via686a_update_device(dev); 589 struct via686a_data *data = via686a_update_device(dev);
535 return sprintf(buf, "%u\n", data->alarms); 590 return sprintf(buf, "%u\n", data->alarms);
536} 591}
592
537static DEVICE_ATTR(alarms, S_IRUGO, show_alarms, NULL); 593static DEVICE_ATTR(alarms, S_IRUGO, show_alarms, NULL);
538 594
539static ssize_t show_alarm(struct device *dev, struct device_attribute *attr, 595static ssize_t show_alarm(struct device *dev, struct device_attribute *attr,
@@ -641,7 +697,8 @@ static int __devinit via686a_probe(struct platform_device *pdev)
641 return -ENODEV; 697 return -ENODEV;
642 } 698 }
643 699
644 if (!(data = kzalloc(sizeof(struct via686a_data), GFP_KERNEL))) { 700 data = kzalloc(sizeof(struct via686a_data), GFP_KERNEL);
701 if (!data) {
645 err = -ENOMEM; 702 err = -ENOMEM;
646 goto exit_release; 703 goto exit_release;
647 } 704 }
@@ -655,7 +712,8 @@ static int __devinit via686a_probe(struct platform_device *pdev)
655 via686a_init_device(data); 712 via686a_init_device(data);
656 713
657 /* Register sysfs hooks */ 714 /* Register sysfs hooks */
658 if ((err = sysfs_create_group(&pdev->dev.kobj, &via686a_group))) 715 err = sysfs_create_group(&pdev->dev.kobj, &via686a_group);
716 if (err)
659 goto exit_free; 717 goto exit_free;
660 718
661 data->hwmon_dev = hwmon_device_register(&pdev->dev); 719 data->hwmon_dev = hwmon_device_register(&pdev->dev);
@@ -748,10 +806,11 @@ static struct via686a_data *via686a_update_device(struct device *dev)
748 via686a_read_value(data, 806 via686a_read_value(data,
749 VIA686A_REG_TEMP_HYST[i]); 807 VIA686A_REG_TEMP_HYST[i]);
750 } 808 }
751 /* add in lower 2 bits 809 /*
752 temp1 uses bits 7-6 of VIA686A_REG_TEMP_LOW1 810 * add in lower 2 bits
753 temp2 uses bits 5-4 of VIA686A_REG_TEMP_LOW23 811 * temp1 uses bits 7-6 of VIA686A_REG_TEMP_LOW1
754 temp3 uses bits 7-6 of VIA686A_REG_TEMP_LOW23 812 * temp2 uses bits 5-4 of VIA686A_REG_TEMP_LOW23
813 * temp3 uses bits 7-6 of VIA686A_REG_TEMP_LOW23
755 */ 814 */
756 data->temp[0] |= (via686a_read_value(data, 815 data->temp[0] |= (via686a_read_value(data,
757 VIA686A_REG_TEMP_LOW1) 816 VIA686A_REG_TEMP_LOW1)
@@ -779,9 +838,8 @@ static struct via686a_data *via686a_update_device(struct device *dev)
779 838
780static DEFINE_PCI_DEVICE_TABLE(via686a_pci_ids) = { 839static DEFINE_PCI_DEVICE_TABLE(via686a_pci_ids) = {
781 { PCI_DEVICE(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_82C686_4) }, 840 { PCI_DEVICE(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_82C686_4) },
782 { 0, } 841 { }
783}; 842};
784
785MODULE_DEVICE_TABLE(pci, via686a_pci_ids); 843MODULE_DEVICE_TABLE(pci, via686a_pci_ids);
786 844
787static int __devinit via686a_device_add(unsigned short address) 845static int __devinit via686a_device_add(unsigned short address)
@@ -872,7 +930,8 @@ static int __devinit via686a_pci_probe(struct pci_dev *dev,
872 if (via686a_device_add(address)) 930 if (via686a_device_add(address))
873 goto exit_unregister; 931 goto exit_unregister;
874 932
875 /* Always return failure here. This is to allow other drivers to bind 933 /*
934 * Always return failure here. This is to allow other drivers to bind
876 * to this pci device. We don't really want to have control over the 935 * to this pci device. We don't really want to have control over the
877 * pci device, we only wanted to read as few register values from it. 936 * pci device, we only wanted to read as few register values from it.
878 */ 937 */