diff options
author | Guenter Roeck <linux@roeck-us.net> | 2012-01-14 15:30:52 -0500 |
---|---|---|
committer | Guenter Roeck <guenter.roeck@ericsson.com> | 2012-03-18 21:27:18 -0400 |
commit | 1bd385d67946391dd3ed80654e36adbb634f0be6 (patch) | |
tree | 970dd74684f559053bf7555f97c11d9b24b4c15d /drivers/hwmon/abituguru.c | |
parent | 8969e84d954af3f7142cb5e6fd870466aaf59932 (diff) |
hwmon: (abituguru) Fix checkpatch issues
Fixed:
ERROR: do not use assignment in if condition
ERROR: else should follow close brace '}'
ERROR: switch and case should be at the same indent
WARNING: simple_strtoul is obsolete, use kstrtoul instead
Modify multi-line comments to follow Documentation/CodingStyle.
Not fixed:
WARNING: msleep < 20ms can sleep for up to 20ms
Cc: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Diffstat (limited to 'drivers/hwmon/abituguru.c')
-rw-r--r-- | drivers/hwmon/abituguru.c | 584 |
1 files changed, 360 insertions, 224 deletions
diff --git a/drivers/hwmon/abituguru.c b/drivers/hwmon/abituguru.c index 3b728e8f169b..a72bf25601a4 100644 --- a/drivers/hwmon/abituguru.c +++ b/drivers/hwmon/abituguru.c | |||
@@ -1,25 +1,25 @@ | |||
1 | /* | 1 | /* |
2 | abituguru.c Copyright (c) 2005-2006 Hans de Goede <hdegoede@redhat.com> | 2 | * abituguru.c Copyright (c) 2005-2006 Hans de Goede <hdegoede@redhat.com> |
3 | 3 | * | |
4 | This program is free software; you can redistribute it and/or modify | 4 | * This program is free software; you can redistribute it and/or modify |
5 | it under the terms of the GNU General Public License as published by | 5 | * it under the terms of the GNU General Public License as published by |
6 | the Free Software Foundation; either version 2 of the License, or | 6 | * the Free Software Foundation; either version 2 of the License, or |
7 | (at your option) any later version. | 7 | * (at your option) any later version. |
8 | 8 | * | |
9 | This program is distributed in the hope that it will be useful, | 9 | * This program is distributed in the hope that it will be useful, |
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 | GNU General Public License for more details. | 12 | * GNU General Public License for more details. |
13 | 13 | * | |
14 | You should have received a copy of the GNU General Public License | 14 | * You should have received a copy of the GNU General Public License |
15 | along with this program; if not, write to the Free Software | 15 | * along with this program; if not, write to the Free Software |
16 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | 16 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
17 | */ | 17 | */ |
18 | /* | 18 | /* |
19 | This driver supports the sensor part of the first and second revision of | 19 | * This driver supports the sensor part of the first and second revision of |
20 | the custom Abit uGuru chip found on Abit uGuru motherboards. Note: because | 20 | * the custom Abit uGuru chip found on Abit uGuru motherboards. Note: because |
21 | of lack of specs the CPU/RAM voltage & frequency control is not supported! | 21 | * of lack of specs the CPU/RAM voltage & frequency control is not supported! |
22 | */ | 22 | */ |
23 | 23 | ||
24 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt | 24 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
25 | 25 | ||
@@ -44,8 +44,10 @@ | |||
44 | #define ABIT_UGURU_SENSOR_BANK2 0x26 /* fans */ | 44 | #define ABIT_UGURU_SENSOR_BANK2 0x26 /* fans */ |
45 | /* max nr of sensors in bank1, a bank1 sensor can be in, temp or nc */ | 45 | /* max nr of sensors in bank1, a bank1 sensor can be in, temp or nc */ |
46 | #define ABIT_UGURU_MAX_BANK1_SENSORS 16 | 46 | #define ABIT_UGURU_MAX_BANK1_SENSORS 16 |
47 | /* Warning if you increase one of the 2 MAX defines below to 10 or higher you | 47 | /* |
48 | should adjust the belonging _NAMES_LENGTH macro for the 2 digit number! */ | 48 | * Warning if you increase one of the 2 MAX defines below to 10 or higher you |
49 | * should adjust the belonging _NAMES_LENGTH macro for the 2 digit number! | ||
50 | */ | ||
49 | /* max nr of sensors in bank2, currently mb's with max 6 fans are known */ | 51 | /* max nr of sensors in bank2, currently mb's with max 6 fans are known */ |
50 | #define ABIT_UGURU_MAX_BANK2_SENSORS 6 | 52 | #define ABIT_UGURU_MAX_BANK2_SENSORS 6 |
51 | /* max nr of pwm outputs, currently mb's with max 5 pwm outputs are known */ | 53 | /* max nr of pwm outputs, currently mb's with max 5 pwm outputs are known */ |
@@ -70,16 +72,22 @@ | |||
70 | #define ABIT_UGURU_IN_SENSOR 0 | 72 | #define ABIT_UGURU_IN_SENSOR 0 |
71 | #define ABIT_UGURU_TEMP_SENSOR 1 | 73 | #define ABIT_UGURU_TEMP_SENSOR 1 |
72 | #define ABIT_UGURU_NC 2 | 74 | #define ABIT_UGURU_NC 2 |
73 | /* In many cases we need to wait for the uGuru to reach a certain status, most | 75 | /* |
74 | of the time it will reach this status within 30 - 90 ISA reads, and thus we | 76 | * In many cases we need to wait for the uGuru to reach a certain status, most |
75 | can best busy wait. This define gives the total amount of reads to try. */ | 77 | * of the time it will reach this status within 30 - 90 ISA reads, and thus we |
78 | * can best busy wait. This define gives the total amount of reads to try. | ||
79 | */ | ||
76 | #define ABIT_UGURU_WAIT_TIMEOUT 125 | 80 | #define ABIT_UGURU_WAIT_TIMEOUT 125 |
77 | /* However sometimes older versions of the uGuru seem to be distracted and they | 81 | /* |
78 | do not respond for a long time. To handle this we sleep before each of the | 82 | * However sometimes older versions of the uGuru seem to be distracted and they |
79 | last ABIT_UGURU_WAIT_TIMEOUT_SLEEP tries. */ | 83 | * do not respond for a long time. To handle this we sleep before each of the |
84 | * last ABIT_UGURU_WAIT_TIMEOUT_SLEEP tries. | ||
85 | */ | ||
80 | #define ABIT_UGURU_WAIT_TIMEOUT_SLEEP 5 | 86 | #define ABIT_UGURU_WAIT_TIMEOUT_SLEEP 5 |
81 | /* Normally all expected status in abituguru_ready, are reported after the | 87 | /* |
82 | first read, but sometimes not and we need to poll. */ | 88 | * Normally all expected status in abituguru_ready, are reported after the |
89 | * first read, but sometimes not and we need to poll. | ||
90 | */ | ||
83 | #define ABIT_UGURU_READY_TIMEOUT 5 | 91 | #define ABIT_UGURU_READY_TIMEOUT 5 |
84 | /* Maximum 3 retries on timedout reads/writes, delay 200 ms before retrying */ | 92 | /* Maximum 3 retries on timedout reads/writes, delay 200 ms before retrying */ |
85 | #define ABIT_UGURU_MAX_RETRIES 3 | 93 | #define ABIT_UGURU_MAX_RETRIES 3 |
@@ -92,17 +100,25 @@ | |||
92 | if (level <= verbose) \ | 100 | if (level <= verbose) \ |
93 | printk(KERN_DEBUG ABIT_UGURU_NAME ": " format , ## arg) | 101 | printk(KERN_DEBUG ABIT_UGURU_NAME ": " format , ## arg) |
94 | /* Macros to help calculate the sysfs_names array length */ | 102 | /* Macros to help calculate the sysfs_names array length */ |
95 | /* sum of strlen of: in??_input\0, in??_{min,max}\0, in??_{min,max}_alarm\0, | 103 | /* |
96 | in??_{min,max}_alarm_enable\0, in??_beep\0, in??_shutdown\0 */ | 104 | * sum of strlen of: in??_input\0, in??_{min,max}\0, in??_{min,max}_alarm\0, |
105 | * in??_{min,max}_alarm_enable\0, in??_beep\0, in??_shutdown\0 | ||
106 | */ | ||
97 | #define ABITUGURU_IN_NAMES_LENGTH (11 + 2 * 9 + 2 * 15 + 2 * 22 + 10 + 14) | 107 | #define ABITUGURU_IN_NAMES_LENGTH (11 + 2 * 9 + 2 * 15 + 2 * 22 + 10 + 14) |
98 | /* sum of strlen of: temp??_input\0, temp??_max\0, temp??_crit\0, | 108 | /* |
99 | temp??_alarm\0, temp??_alarm_enable\0, temp??_beep\0, temp??_shutdown\0 */ | 109 | * sum of strlen of: temp??_input\0, temp??_max\0, temp??_crit\0, |
110 | * temp??_alarm\0, temp??_alarm_enable\0, temp??_beep\0, temp??_shutdown\0 | ||
111 | */ | ||
100 | #define ABITUGURU_TEMP_NAMES_LENGTH (13 + 11 + 12 + 13 + 20 + 12 + 16) | 112 | #define ABITUGURU_TEMP_NAMES_LENGTH (13 + 11 + 12 + 13 + 20 + 12 + 16) |
101 | /* sum of strlen of: fan?_input\0, fan?_min\0, fan?_alarm\0, | 113 | /* |
102 | fan?_alarm_enable\0, fan?_beep\0, fan?_shutdown\0 */ | 114 | * sum of strlen of: fan?_input\0, fan?_min\0, fan?_alarm\0, |
115 | * fan?_alarm_enable\0, fan?_beep\0, fan?_shutdown\0 | ||
116 | */ | ||
103 | #define ABITUGURU_FAN_NAMES_LENGTH (11 + 9 + 11 + 18 + 10 + 14) | 117 | #define ABITUGURU_FAN_NAMES_LENGTH (11 + 9 + 11 + 18 + 10 + 14) |
104 | /* sum of strlen of: pwm?_enable\0, pwm?_auto_channels_temp\0, | 118 | /* |
105 | pwm?_auto_point{1,2}_pwm\0, pwm?_auto_point{1,2}_temp\0 */ | 119 | * sum of strlen of: pwm?_enable\0, pwm?_auto_channels_temp\0, |
120 | * pwm?_auto_point{1,2}_pwm\0, pwm?_auto_point{1,2}_temp\0 | ||
121 | */ | ||
106 | #define ABITUGURU_PWM_NAMES_LENGTH (12 + 24 + 2 * 21 + 2 * 22) | 122 | #define ABITUGURU_PWM_NAMES_LENGTH (12 + 24 + 2 * 21 + 2 * 22) |
107 | /* IN_NAMES_LENGTH > TEMP_NAMES_LENGTH so assume all bank1 sensors are in */ | 123 | /* IN_NAMES_LENGTH > TEMP_NAMES_LENGTH so assume all bank1 sensors are in */ |
108 | #define ABITUGURU_SYSFS_NAMES_LENGTH ( \ | 124 | #define ABITUGURU_SYSFS_NAMES_LENGTH ( \ |
@@ -110,10 +126,12 @@ | |||
110 | ABIT_UGURU_MAX_BANK2_SENSORS * ABITUGURU_FAN_NAMES_LENGTH + \ | 126 | ABIT_UGURU_MAX_BANK2_SENSORS * ABITUGURU_FAN_NAMES_LENGTH + \ |
111 | ABIT_UGURU_MAX_PWMS * ABITUGURU_PWM_NAMES_LENGTH) | 127 | ABIT_UGURU_MAX_PWMS * ABITUGURU_PWM_NAMES_LENGTH) |
112 | 128 | ||
113 | /* All the macros below are named identical to the oguru and oguru2 programs | 129 | /* |
114 | reverse engineered by Olle Sandberg, hence the names might not be 100% | 130 | * All the macros below are named identical to the oguru and oguru2 programs |
115 | logical. I could come up with better names, but I prefer keeping the names | 131 | * reverse engineered by Olle Sandberg, hence the names might not be 100% |
116 | identical so that this driver can be compared with his work more easily. */ | 132 | * logical. I could come up with better names, but I prefer keeping the names |
133 | * identical so that this driver can be compared with his work more easily. | ||
134 | */ | ||
117 | /* Two i/o-ports are used by uGuru */ | 135 | /* Two i/o-ports are used by uGuru */ |
118 | #define ABIT_UGURU_BASE 0x00E0 | 136 | #define ABIT_UGURU_BASE 0x00E0 |
119 | /* Used to tell uGuru what to read and to read the actual data */ | 137 | /* Used to tell uGuru what to read and to read the actual data */ |
@@ -130,16 +148,22 @@ | |||
130 | /* Constants */ | 148 | /* Constants */ |
131 | /* in (Volt) sensors go up to 3494 mV, temp to 255000 millidegrees Celsius */ | 149 | /* in (Volt) sensors go up to 3494 mV, temp to 255000 millidegrees Celsius */ |
132 | static const int abituguru_bank1_max_value[2] = { 3494, 255000 }; | 150 | static const int abituguru_bank1_max_value[2] = { 3494, 255000 }; |
133 | /* Min / Max allowed values for sensor2 (fan) alarm threshold, these values | 151 | /* |
134 | correspond to 300-3000 RPM */ | 152 | * Min / Max allowed values for sensor2 (fan) alarm threshold, these values |
153 | * correspond to 300-3000 RPM | ||
154 | */ | ||
135 | static const u8 abituguru_bank2_min_threshold = 5; | 155 | static const u8 abituguru_bank2_min_threshold = 5; |
136 | static const u8 abituguru_bank2_max_threshold = 50; | 156 | static const u8 abituguru_bank2_max_threshold = 50; |
137 | /* Register 0 is a bitfield, 1 and 2 are pwm settings (255 = 100%), 3 and 4 | 157 | /* |
138 | are temperature trip points. */ | 158 | * Register 0 is a bitfield, 1 and 2 are pwm settings (255 = 100%), 3 and 4 |
159 | * are temperature trip points. | ||
160 | */ | ||
139 | static const int abituguru_pwm_settings_multiplier[5] = { 0, 1, 1, 1000, 1000 }; | 161 | static const int abituguru_pwm_settings_multiplier[5] = { 0, 1, 1, 1000, 1000 }; |
140 | /* Min / Max allowed values for pwm_settings. Note: pwm1 (CPU fan) is a | 162 | /* |
141 | special case the minium allowed pwm% setting for this is 30% (77) on | 163 | * Min / Max allowed values for pwm_settings. Note: pwm1 (CPU fan) is a |
142 | some MB's this special case is handled in the code! */ | 164 | * special case the minium allowed pwm% setting for this is 30% (77) on |
165 | * some MB's this special case is handled in the code! | ||
166 | */ | ||
143 | static const u8 abituguru_pwm_min[5] = { 0, 170, 170, 25, 25 }; | 167 | static const u8 abituguru_pwm_min[5] = { 0, 170, 170, 25, 25 }; |
144 | static const u8 abituguru_pwm_max[5] = { 0, 255, 255, 75, 75 }; | 168 | static const u8 abituguru_pwm_max[5] = { 0, 255, 255, 75, 75 }; |
145 | 169 | ||
@@ -175,23 +199,29 @@ MODULE_PARM_DESC(verbose, "How verbose should the driver be? (0-3):\n" | |||
175 | " 3 + retryable error reporting"); | 199 | " 3 + retryable error reporting"); |
176 | 200 | ||
177 | 201 | ||
178 | /* For the Abit uGuru, we need to keep some data in memory. | 202 | /* |
179 | The structure is dynamically allocated, at the same time when a new | 203 | * For the Abit uGuru, we need to keep some data in memory. |
180 | abituguru device is allocated. */ | 204 | * The structure is dynamically allocated, at the same time when a new |
205 | * abituguru device is allocated. | ||
206 | */ | ||
181 | struct abituguru_data { | 207 | struct abituguru_data { |
182 | struct device *hwmon_dev; /* hwmon registered device */ | 208 | struct device *hwmon_dev; /* hwmon registered device */ |
183 | struct mutex update_lock; /* protect access to data and uGuru */ | 209 | struct mutex update_lock; /* protect access to data and uGuru */ |
184 | unsigned long last_updated; /* In jiffies */ | 210 | unsigned long last_updated; /* In jiffies */ |
185 | unsigned short addr; /* uguru base address */ | 211 | unsigned short addr; /* uguru base address */ |
186 | char uguru_ready; /* is the uguru in ready state? */ | 212 | char uguru_ready; /* is the uguru in ready state? */ |
187 | unsigned char update_timeouts; /* number of update timeouts since last | 213 | unsigned char update_timeouts; /* |
188 | successful update */ | 214 | * number of update timeouts since last |
189 | 215 | * successful update | |
190 | /* The sysfs attr and their names are generated automatically, for bank1 | 216 | */ |
191 | we cannot use a predefined array because we don't know beforehand | 217 | |
192 | of a sensor is a volt or a temp sensor, for bank2 and the pwms its | 218 | /* |
193 | easier todo things the same way. For in sensors we have 9 (temp 7) | 219 | * The sysfs attr and their names are generated automatically, for bank1 |
194 | sysfs entries per sensor, for bank2 and pwms 6. */ | 220 | * we cannot use a predefined array because we don't know beforehand |
221 | * of a sensor is a volt or a temp sensor, for bank2 and the pwms its | ||
222 | * easier todo things the same way. For in sensors we have 9 (temp 7) | ||
223 | * sysfs entries per sensor, for bank2 and pwms 6. | ||
224 | */ | ||
195 | struct sensor_device_attribute_2 sysfs_attr[ | 225 | struct sensor_device_attribute_2 sysfs_attr[ |
196 | ABIT_UGURU_MAX_BANK1_SENSORS * 9 + | 226 | ABIT_UGURU_MAX_BANK1_SENSORS * 9 + |
197 | ABIT_UGURU_MAX_BANK2_SENSORS * 6 + ABIT_UGURU_MAX_PWMS * 6]; | 227 | ABIT_UGURU_MAX_BANK2_SENSORS * 6 + ABIT_UGURU_MAX_PWMS * 6]; |
@@ -203,11 +233,15 @@ struct abituguru_data { | |||
203 | u8 bank1_sensors[2]; | 233 | u8 bank1_sensors[2]; |
204 | u8 bank1_address[2][ABIT_UGURU_MAX_BANK1_SENSORS]; | 234 | u8 bank1_address[2][ABIT_UGURU_MAX_BANK1_SENSORS]; |
205 | u8 bank1_value[ABIT_UGURU_MAX_BANK1_SENSORS]; | 235 | u8 bank1_value[ABIT_UGURU_MAX_BANK1_SENSORS]; |
206 | /* This array holds 3 entries per sensor for the bank 1 sensor settings | 236 | /* |
207 | (flags, min, max for voltage / flags, warn, shutdown for temp). */ | 237 | * This array holds 3 entries per sensor for the bank 1 sensor settings |
238 | * (flags, min, max for voltage / flags, warn, shutdown for temp). | ||
239 | */ | ||
208 | u8 bank1_settings[ABIT_UGURU_MAX_BANK1_SENSORS][3]; | 240 | u8 bank1_settings[ABIT_UGURU_MAX_BANK1_SENSORS][3]; |
209 | /* Maximum value for each sensor used for scaling in mV/millidegrees | 241 | /* |
210 | Celsius. */ | 242 | * Maximum value for each sensor used for scaling in mV/millidegrees |
243 | * Celsius. | ||
244 | */ | ||
211 | int bank1_max_value[ABIT_UGURU_MAX_BANK1_SENSORS]; | 245 | int bank1_max_value[ABIT_UGURU_MAX_BANK1_SENSORS]; |
212 | 246 | ||
213 | /* Bank 2 data, ABIT_UGURU_MAX_BANK2_SENSORS entries for bank2 */ | 247 | /* Bank 2 data, ABIT_UGURU_MAX_BANK2_SENSORS entries for bank2 */ |
@@ -236,8 +270,10 @@ static int abituguru_wait(struct abituguru_data *data, u8 state) | |||
236 | timeout--; | 270 | timeout--; |
237 | if (timeout == 0) | 271 | if (timeout == 0) |
238 | return -EBUSY; | 272 | return -EBUSY; |
239 | /* sleep a bit before our last few tries, see the comment on | 273 | /* |
240 | this where ABIT_UGURU_WAIT_TIMEOUT_SLEEP is defined. */ | 274 | * sleep a bit before our last few tries, see the comment on |
275 | * this where ABIT_UGURU_WAIT_TIMEOUT_SLEEP is defined. | ||
276 | */ | ||
241 | if (timeout <= ABIT_UGURU_WAIT_TIMEOUT_SLEEP) | 277 | if (timeout <= ABIT_UGURU_WAIT_TIMEOUT_SLEEP) |
242 | msleep(0); | 278 | msleep(0); |
243 | } | 279 | } |
@@ -273,8 +309,10 @@ static int abituguru_ready(struct abituguru_data *data) | |||
273 | msleep(0); | 309 | msleep(0); |
274 | } | 310 | } |
275 | 311 | ||
276 | /* After this the ABIT_UGURU_DATA port should contain | 312 | /* |
277 | ABIT_UGURU_STATUS_INPUT */ | 313 | * After this the ABIT_UGURU_DATA port should contain |
314 | * ABIT_UGURU_STATUS_INPUT | ||
315 | */ | ||
278 | timeout = ABIT_UGURU_READY_TIMEOUT; | 316 | timeout = ABIT_UGURU_READY_TIMEOUT; |
279 | while (inb_p(data->addr + ABIT_UGURU_DATA) != ABIT_UGURU_STATUS_INPUT) { | 317 | while (inb_p(data->addr + ABIT_UGURU_DATA) != ABIT_UGURU_STATUS_INPUT) { |
280 | timeout--; | 318 | timeout--; |
@@ -290,27 +328,35 @@ static int abituguru_ready(struct abituguru_data *data) | |||
290 | return 0; | 328 | return 0; |
291 | } | 329 | } |
292 | 330 | ||
293 | /* Send the bank and then sensor address to the uGuru for the next read/write | 331 | /* |
294 | cycle. This function gets called as the first part of a read/write by | 332 | * Send the bank and then sensor address to the uGuru for the next read/write |
295 | abituguru_read and abituguru_write. This function should never be | 333 | * cycle. This function gets called as the first part of a read/write by |
296 | called by any other function. */ | 334 | * abituguru_read and abituguru_write. This function should never be |
335 | * called by any other function. | ||
336 | */ | ||
297 | static int abituguru_send_address(struct abituguru_data *data, | 337 | static int abituguru_send_address(struct abituguru_data *data, |
298 | u8 bank_addr, u8 sensor_addr, int retries) | 338 | u8 bank_addr, u8 sensor_addr, int retries) |
299 | { | 339 | { |
300 | /* assume the caller does error handling itself if it has not requested | 340 | /* |
301 | any retries, and thus be quiet. */ | 341 | * assume the caller does error handling itself if it has not requested |
342 | * any retries, and thus be quiet. | ||
343 | */ | ||
302 | int report_errors = retries; | 344 | int report_errors = retries; |
303 | 345 | ||
304 | for (;;) { | 346 | for (;;) { |
305 | /* Make sure the uguru is ready and then send the bank address, | 347 | /* |
306 | after this the uguru is no longer "ready". */ | 348 | * Make sure the uguru is ready and then send the bank address, |
349 | * after this the uguru is no longer "ready". | ||
350 | */ | ||
307 | if (abituguru_ready(data) != 0) | 351 | if (abituguru_ready(data) != 0) |
308 | return -EIO; | 352 | return -EIO; |
309 | outb(bank_addr, data->addr + ABIT_UGURU_DATA); | 353 | outb(bank_addr, data->addr + ABIT_UGURU_DATA); |
310 | data->uguru_ready = 0; | 354 | data->uguru_ready = 0; |
311 | 355 | ||
312 | /* Wait till the uguru is ABIT_UGURU_STATUS_INPUT state again | 356 | /* |
313 | and send the sensor addr */ | 357 | * Wait till the uguru is ABIT_UGURU_STATUS_INPUT state again |
358 | * and send the sensor addr | ||
359 | */ | ||
314 | if (abituguru_wait(data, ABIT_UGURU_STATUS_INPUT)) { | 360 | if (abituguru_wait(data, ABIT_UGURU_STATUS_INPUT)) { |
315 | if (retries) { | 361 | if (retries) { |
316 | ABIT_UGURU_DEBUG(3, "timeout exceeded " | 362 | ABIT_UGURU_DEBUG(3, "timeout exceeded " |
@@ -332,8 +378,10 @@ static int abituguru_send_address(struct abituguru_data *data, | |||
332 | } | 378 | } |
333 | } | 379 | } |
334 | 380 | ||
335 | /* Read count bytes from sensor sensor_addr in bank bank_addr and store the | 381 | /* |
336 | result in buf, retry the send address part of the read retries times. */ | 382 | * Read count bytes from sensor sensor_addr in bank bank_addr and store the |
383 | * result in buf, retry the send address part of the read retries times. | ||
384 | */ | ||
337 | static int abituguru_read(struct abituguru_data *data, | 385 | static int abituguru_read(struct abituguru_data *data, |
338 | u8 bank_addr, u8 sensor_addr, u8 *buf, int count, int retries) | 386 | u8 bank_addr, u8 sensor_addr, u8 *buf, int count, int retries) |
339 | { | 387 | { |
@@ -362,13 +410,17 @@ static int abituguru_read(struct abituguru_data *data, | |||
362 | return i; | 410 | return i; |
363 | } | 411 | } |
364 | 412 | ||
365 | /* Write count bytes from buf to sensor sensor_addr in bank bank_addr, the send | 413 | /* |
366 | address part of the write is always retried ABIT_UGURU_MAX_RETRIES times. */ | 414 | * Write count bytes from buf to sensor sensor_addr in bank bank_addr, the send |
415 | * address part of the write is always retried ABIT_UGURU_MAX_RETRIES times. | ||
416 | */ | ||
367 | static int abituguru_write(struct abituguru_data *data, | 417 | static int abituguru_write(struct abituguru_data *data, |
368 | u8 bank_addr, u8 sensor_addr, u8 *buf, int count) | 418 | u8 bank_addr, u8 sensor_addr, u8 *buf, int count) |
369 | { | 419 | { |
370 | /* We use the ready timeout as we have to wait for 0xAC just like the | 420 | /* |
371 | ready function */ | 421 | * We use the ready timeout as we have to wait for 0xAC just like the |
422 | * ready function | ||
423 | */ | ||
372 | int i, timeout = ABIT_UGURU_READY_TIMEOUT; | 424 | int i, timeout = ABIT_UGURU_READY_TIMEOUT; |
373 | 425 | ||
374 | /* Send the address */ | 426 | /* Send the address */ |
@@ -388,9 +440,11 @@ static int abituguru_write(struct abituguru_data *data, | |||
388 | outb(buf[i], data->addr + ABIT_UGURU_CMD); | 440 | outb(buf[i], data->addr + ABIT_UGURU_CMD); |
389 | } | 441 | } |
390 | 442 | ||
391 | /* Now we need to wait till the chip is ready to be read again, | 443 | /* |
392 | so that we can read 0xAC as confirmation that our write has | 444 | * Now we need to wait till the chip is ready to be read again, |
393 | succeeded. */ | 445 | * so that we can read 0xAC as confirmation that our write has |
446 | * succeeded. | ||
447 | */ | ||
394 | if (abituguru_wait(data, ABIT_UGURU_STATUS_READ)) { | 448 | if (abituguru_wait(data, ABIT_UGURU_STATUS_READ)) { |
395 | ABIT_UGURU_DEBUG(1, "timeout exceeded waiting for read state " | 449 | ABIT_UGURU_DEBUG(1, "timeout exceeded waiting for read state " |
396 | "after write (bank: %d, sensor: %d)\n", (int)bank_addr, | 450 | "after write (bank: %d, sensor: %d)\n", (int)bank_addr, |
@@ -416,12 +470,14 @@ static int abituguru_write(struct abituguru_data *data, | |||
416 | return i; | 470 | return i; |
417 | } | 471 | } |
418 | 472 | ||
419 | /* Detect sensor type. Temp and Volt sensors are enabled with | 473 | /* |
420 | different masks and will ignore enable masks not meant for them. | 474 | * Detect sensor type. Temp and Volt sensors are enabled with |
421 | This enables us to test what kind of sensor we're dealing with. | 475 | * different masks and will ignore enable masks not meant for them. |
422 | By setting the alarm thresholds so that we will always get an | 476 | * This enables us to test what kind of sensor we're dealing with. |
423 | alarm for sensor type X and then enabling the sensor as sensor type | 477 | * By setting the alarm thresholds so that we will always get an |
424 | X, if we then get an alarm it is a sensor of type X. */ | 478 | * alarm for sensor type X and then enabling the sensor as sensor type |
479 | * X, if we then get an alarm it is a sensor of type X. | ||
480 | */ | ||
425 | static int __devinit | 481 | static int __devinit |
426 | abituguru_detect_bank1_sensor_type(struct abituguru_data *data, | 482 | abituguru_detect_bank1_sensor_type(struct abituguru_data *data, |
427 | u8 sensor_addr) | 483 | u8 sensor_addr) |
@@ -448,16 +504,20 @@ abituguru_detect_bank1_sensor_type(struct abituguru_data *data, | |||
448 | pr_warn("bank1-sensor: %d reading (%d) too close to limits, " | 504 | pr_warn("bank1-sensor: %d reading (%d) too close to limits, " |
449 | "unable to determine sensor type, skipping sensor\n", | 505 | "unable to determine sensor type, skipping sensor\n", |
450 | (int)sensor_addr, (int)val); | 506 | (int)sensor_addr, (int)val); |
451 | /* assume no sensor is there for sensors for which we can't | 507 | /* |
452 | determine the sensor type because their reading is too close | 508 | * assume no sensor is there for sensors for which we can't |
453 | to their limits, this usually means no sensor is there. */ | 509 | * determine the sensor type because their reading is too close |
510 | * to their limits, this usually means no sensor is there. | ||
511 | */ | ||
454 | return ABIT_UGURU_NC; | 512 | return ABIT_UGURU_NC; |
455 | } | 513 | } |
456 | 514 | ||
457 | ABIT_UGURU_DEBUG(2, "testing bank1 sensor %d\n", (int)sensor_addr); | 515 | ABIT_UGURU_DEBUG(2, "testing bank1 sensor %d\n", (int)sensor_addr); |
458 | /* Volt sensor test, enable volt low alarm, set min value ridicously | 516 | /* |
459 | high, or vica versa if the reading is very high. If its a volt | 517 | * Volt sensor test, enable volt low alarm, set min value ridicously |
460 | sensor this should always give us an alarm. */ | 518 | * high, or vica versa if the reading is very high. If its a volt |
519 | * sensor this should always give us an alarm. | ||
520 | */ | ||
461 | if (val <= 240u) { | 521 | if (val <= 240u) { |
462 | buf[0] = ABIT_UGURU_VOLT_LOW_ALARM_ENABLE; | 522 | buf[0] = ABIT_UGURU_VOLT_LOW_ALARM_ENABLE; |
463 | buf[1] = 245; | 523 | buf[1] = 245; |
@@ -473,8 +533,10 @@ abituguru_detect_bank1_sensor_type(struct abituguru_data *data, | |||
473 | if (abituguru_write(data, ABIT_UGURU_SENSOR_BANK1 + 2, sensor_addr, | 533 | if (abituguru_write(data, ABIT_UGURU_SENSOR_BANK1 + 2, sensor_addr, |
474 | buf, 3) != 3) | 534 | buf, 3) != 3) |
475 | goto abituguru_detect_bank1_sensor_type_exit; | 535 | goto abituguru_detect_bank1_sensor_type_exit; |
476 | /* Now we need 20 ms to give the uguru time to read the sensors | 536 | /* |
477 | and raise a voltage alarm */ | 537 | * Now we need 20 ms to give the uguru time to read the sensors |
538 | * and raise a voltage alarm | ||
539 | */ | ||
478 | set_current_state(TASK_UNINTERRUPTIBLE); | 540 | set_current_state(TASK_UNINTERRUPTIBLE); |
479 | schedule_timeout(HZ/50); | 541 | schedule_timeout(HZ/50); |
480 | /* Check for alarm and check the alarm is a volt low alarm. */ | 542 | /* Check for alarm and check the alarm is a volt low alarm. */ |
@@ -497,17 +559,21 @@ abituguru_detect_bank1_sensor_type(struct abituguru_data *data, | |||
497 | ABIT_UGURU_DEBUG(2, " alarm not raised during volt sensor " | 559 | ABIT_UGURU_DEBUG(2, " alarm not raised during volt sensor " |
498 | "test\n"); | 560 | "test\n"); |
499 | 561 | ||
500 | /* Temp sensor test, enable sensor as a temp sensor, set beep value | 562 | /* |
501 | ridicously low (but not too low, otherwise uguru ignores it). | 563 | * Temp sensor test, enable sensor as a temp sensor, set beep value |
502 | If its a temp sensor this should always give us an alarm. */ | 564 | * ridicously low (but not too low, otherwise uguru ignores it). |
565 | * If its a temp sensor this should always give us an alarm. | ||
566 | */ | ||
503 | buf[0] = ABIT_UGURU_TEMP_HIGH_ALARM_ENABLE; | 567 | buf[0] = ABIT_UGURU_TEMP_HIGH_ALARM_ENABLE; |
504 | buf[1] = 5; | 568 | buf[1] = 5; |
505 | buf[2] = 10; | 569 | buf[2] = 10; |
506 | if (abituguru_write(data, ABIT_UGURU_SENSOR_BANK1 + 2, sensor_addr, | 570 | if (abituguru_write(data, ABIT_UGURU_SENSOR_BANK1 + 2, sensor_addr, |
507 | buf, 3) != 3) | 571 | buf, 3) != 3) |
508 | goto abituguru_detect_bank1_sensor_type_exit; | 572 | goto abituguru_detect_bank1_sensor_type_exit; |
509 | /* Now we need 50 ms to give the uguru time to read the sensors | 573 | /* |
510 | and raise a temp alarm */ | 574 | * Now we need 50 ms to give the uguru time to read the sensors |
575 | * and raise a temp alarm | ||
576 | */ | ||
511 | set_current_state(TASK_UNINTERRUPTIBLE); | 577 | set_current_state(TASK_UNINTERRUPTIBLE); |
512 | schedule_timeout(HZ/20); | 578 | schedule_timeout(HZ/20); |
513 | /* Check for alarm and check the alarm is a temp high alarm. */ | 579 | /* Check for alarm and check the alarm is a temp high alarm. */ |
@@ -532,9 +598,11 @@ abituguru_detect_bank1_sensor_type(struct abituguru_data *data, | |||
532 | 598 | ||
533 | ret = ABIT_UGURU_NC; | 599 | ret = ABIT_UGURU_NC; |
534 | abituguru_detect_bank1_sensor_type_exit: | 600 | abituguru_detect_bank1_sensor_type_exit: |
535 | /* Restore original settings, failing here is really BAD, it has been | 601 | /* |
536 | reported that some BIOS-es hang when entering the uGuru menu with | 602 | * Restore original settings, failing here is really BAD, it has been |
537 | invalid settings present in the uGuru, so we try this 3 times. */ | 603 | * reported that some BIOS-es hang when entering the uGuru menu with |
604 | * invalid settings present in the uGuru, so we try this 3 times. | ||
605 | */ | ||
538 | for (i = 0; i < 3; i++) | 606 | for (i = 0; i < 3; i++) |
539 | if (abituguru_write(data, ABIT_UGURU_SENSOR_BANK1 + 2, | 607 | if (abituguru_write(data, ABIT_UGURU_SENSOR_BANK1 + 2, |
540 | sensor_addr, data->bank1_settings[sensor_addr], | 608 | sensor_addr, data->bank1_settings[sensor_addr], |
@@ -548,23 +616,25 @@ abituguru_detect_bank1_sensor_type_exit: | |||
548 | return ret; | 616 | return ret; |
549 | } | 617 | } |
550 | 618 | ||
551 | /* These functions try to find out how many sensors there are in bank2 and how | 619 | /* |
552 | many pwms there are. The purpose of this is to make sure that we don't give | 620 | * These functions try to find out how many sensors there are in bank2 and how |
553 | the user the possibility to change settings for non-existent sensors / pwm. | 621 | * many pwms there are. The purpose of this is to make sure that we don't give |
554 | The uGuru will happily read / write whatever memory happens to be after the | 622 | * the user the possibility to change settings for non-existent sensors / pwm. |
555 | memory storing the PWM settings when reading/writing to a PWM which is not | 623 | * The uGuru will happily read / write whatever memory happens to be after the |
556 | there. Notice even if we detect a PWM which doesn't exist we normally won't | 624 | * memory storing the PWM settings when reading/writing to a PWM which is not |
557 | write to it, unless the user tries to change the settings. | 625 | * there. Notice even if we detect a PWM which doesn't exist we normally won't |
558 | 626 | * write to it, unless the user tries to change the settings. | |
559 | Although the uGuru allows reading (settings) from non existing bank2 | 627 | * |
560 | sensors, my version of the uGuru does seem to stop writing to them, the | 628 | * Although the uGuru allows reading (settings) from non existing bank2 |
561 | write function above aborts in this case with: | 629 | * sensors, my version of the uGuru does seem to stop writing to them, the |
562 | "CMD reg does not hold 0xAC after write" | 630 | * write function above aborts in this case with: |
563 | 631 | * "CMD reg does not hold 0xAC after write" | |
564 | Notice these 2 tests are non destructive iow read-only tests, otherwise | 632 | * |
565 | they would defeat their purpose. Although for the bank2_sensors detection a | 633 | * Notice these 2 tests are non destructive iow read-only tests, otherwise |
566 | read/write test would be feasible because of the reaction above, I've | 634 | * they would defeat their purpose. Although for the bank2_sensors detection a |
567 | however opted to stay on the safe side. */ | 635 | * read/write test would be feasible because of the reaction above, I've |
636 | * however opted to stay on the safe side. | ||
637 | */ | ||
568 | static void __devinit | 638 | static void __devinit |
569 | abituguru_detect_no_bank2_sensors(struct abituguru_data *data) | 639 | abituguru_detect_no_bank2_sensors(struct abituguru_data *data) |
570 | { | 640 | { |
@@ -580,12 +650,14 @@ abituguru_detect_no_bank2_sensors(struct abituguru_data *data) | |||
580 | 650 | ||
581 | ABIT_UGURU_DEBUG(2, "detecting number of fan sensors\n"); | 651 | ABIT_UGURU_DEBUG(2, "detecting number of fan sensors\n"); |
582 | for (i = 0; i < ABIT_UGURU_MAX_BANK2_SENSORS; i++) { | 652 | for (i = 0; i < ABIT_UGURU_MAX_BANK2_SENSORS; i++) { |
583 | /* 0x89 are the known used bits: | 653 | /* |
584 | -0x80 enable shutdown | 654 | * 0x89 are the known used bits: |
585 | -0x08 enable beep | 655 | * -0x80 enable shutdown |
586 | -0x01 enable alarm | 656 | * -0x08 enable beep |
587 | All other bits should be 0, but on some motherboards | 657 | * -0x01 enable alarm |
588 | 0x40 (bit 6) is also high for some of the fans?? */ | 658 | * All other bits should be 0, but on some motherboards |
659 | * 0x40 (bit 6) is also high for some of the fans?? | ||
660 | */ | ||
589 | if (data->bank2_settings[i][0] & ~0xC9) { | 661 | if (data->bank2_settings[i][0] & ~0xC9) { |
590 | ABIT_UGURU_DEBUG(2, " bank2 sensor %d does not seem " | 662 | ABIT_UGURU_DEBUG(2, " bank2 sensor %d does not seem " |
591 | "to be a fan sensor: settings[0] = %02X\n", | 663 | "to be a fan sensor: settings[0] = %02X\n", |
@@ -633,9 +705,11 @@ abituguru_detect_no_pwms(struct abituguru_data *data) | |||
633 | 705 | ||
634 | ABIT_UGURU_DEBUG(2, "detecting number of PWM outputs\n"); | 706 | ABIT_UGURU_DEBUG(2, "detecting number of PWM outputs\n"); |
635 | for (i = 0; i < ABIT_UGURU_MAX_PWMS; i++) { | 707 | for (i = 0; i < ABIT_UGURU_MAX_PWMS; i++) { |
636 | /* 0x80 is the enable bit and the low | 708 | /* |
637 | nibble is which temp sensor to use, | 709 | * 0x80 is the enable bit and the low |
638 | the other bits should be 0 */ | 710 | * nibble is which temp sensor to use, |
711 | * the other bits should be 0 | ||
712 | */ | ||
639 | if (data->pwm_settings[i][0] & ~0x8F) { | 713 | if (data->pwm_settings[i][0] & ~0x8F) { |
640 | ABIT_UGURU_DEBUG(2, " pwm channel %d does not seem " | 714 | ABIT_UGURU_DEBUG(2, " pwm channel %d does not seem " |
641 | "to be a pwm channel: settings[0] = %02X\n", | 715 | "to be a pwm channel: settings[0] = %02X\n", |
@@ -643,8 +717,10 @@ abituguru_detect_no_pwms(struct abituguru_data *data) | |||
643 | break; | 717 | break; |
644 | } | 718 | } |
645 | 719 | ||
646 | /* the low nibble must correspond to one of the temp sensors | 720 | /* |
647 | we've found */ | 721 | * the low nibble must correspond to one of the temp sensors |
722 | * we've found | ||
723 | */ | ||
648 | for (j = 0; j < data->bank1_sensors[ABIT_UGURU_TEMP_SENSOR]; | 724 | for (j = 0; j < data->bank1_sensors[ABIT_UGURU_TEMP_SENSOR]; |
649 | j++) { | 725 | j++) { |
650 | if (data->bank1_address[ABIT_UGURU_TEMP_SENSOR][j] == | 726 | if (data->bank1_address[ABIT_UGURU_TEMP_SENSOR][j] == |
@@ -711,9 +787,11 @@ abituguru_detect_no_pwms_exit: | |||
711 | ABIT_UGURU_DEBUG(2, " found: %d PWM outputs\n", (int)data->pwms); | 787 | ABIT_UGURU_DEBUG(2, " found: %d PWM outputs\n", (int)data->pwms); |
712 | } | 788 | } |
713 | 789 | ||
714 | /* Following are the sysfs callback functions. These functions expect: | 790 | /* |
715 | sensor_device_attribute_2->index: sensor address/offset in the bank | 791 | * Following are the sysfs callback functions. These functions expect: |
716 | sensor_device_attribute_2->nr: register offset, bitmask or NA. */ | 792 | * sensor_device_attribute_2->index: sensor address/offset in the bank |
793 | * sensor_device_attribute_2->nr: register offset, bitmask or NA. | ||
794 | */ | ||
717 | static struct abituguru_data *abituguru_update_device(struct device *dev); | 795 | static struct abituguru_data *abituguru_update_device(struct device *dev); |
718 | 796 | ||
719 | static ssize_t show_bank1_value(struct device *dev, | 797 | static ssize_t show_bank1_value(struct device *dev, |
@@ -763,10 +841,18 @@ static ssize_t store_bank1_setting(struct device *dev, struct device_attribute | |||
763 | { | 841 | { |
764 | struct sensor_device_attribute_2 *attr = to_sensor_dev_attr_2(devattr); | 842 | struct sensor_device_attribute_2 *attr = to_sensor_dev_attr_2(devattr); |
765 | struct abituguru_data *data = dev_get_drvdata(dev); | 843 | struct abituguru_data *data = dev_get_drvdata(dev); |
766 | u8 val = (simple_strtoul(buf, NULL, 10) * 255 + | 844 | unsigned long val; |
767 | data->bank1_max_value[attr->index]/2) / | 845 | ssize_t ret; |
846 | |||
847 | ret = kstrtoul(buf, 10, &val); | ||
848 | if (ret) | ||
849 | return ret; | ||
850 | |||
851 | ret = count; | ||
852 | val = (val * 255 + data->bank1_max_value[attr->index] / 2) / | ||
768 | data->bank1_max_value[attr->index]; | 853 | data->bank1_max_value[attr->index]; |
769 | ssize_t ret = count; | 854 | if (val > 255) |
855 | return -EINVAL; | ||
770 | 856 | ||
771 | mutex_lock(&data->update_lock); | 857 | mutex_lock(&data->update_lock); |
772 | if (data->bank1_settings[attr->index][attr->nr] != val) { | 858 | if (data->bank1_settings[attr->index][attr->nr] != val) { |
@@ -788,13 +874,19 @@ static ssize_t store_bank2_setting(struct device *dev, struct device_attribute | |||
788 | { | 874 | { |
789 | struct sensor_device_attribute_2 *attr = to_sensor_dev_attr_2(devattr); | 875 | struct sensor_device_attribute_2 *attr = to_sensor_dev_attr_2(devattr); |
790 | struct abituguru_data *data = dev_get_drvdata(dev); | 876 | struct abituguru_data *data = dev_get_drvdata(dev); |
791 | u8 val = (simple_strtoul(buf, NULL, 10)*255 + ABIT_UGURU_FAN_MAX/2) / | 877 | unsigned long val; |
792 | ABIT_UGURU_FAN_MAX; | 878 | ssize_t ret; |
793 | ssize_t ret = count; | 879 | |
880 | ret = kstrtoul(buf, 10, &val); | ||
881 | if (ret) | ||
882 | return ret; | ||
883 | |||
884 | ret = count; | ||
885 | val = (val * 255 + ABIT_UGURU_FAN_MAX / 2) / ABIT_UGURU_FAN_MAX; | ||
794 | 886 | ||
795 | /* this check can be done before taking the lock */ | 887 | /* this check can be done before taking the lock */ |
796 | if ((val < abituguru_bank2_min_threshold) || | 888 | if (val < abituguru_bank2_min_threshold || |
797 | (val > abituguru_bank2_max_threshold)) | 889 | val > abituguru_bank2_max_threshold) |
798 | return -EINVAL; | 890 | return -EINVAL; |
799 | 891 | ||
800 | mutex_lock(&data->update_lock); | 892 | mutex_lock(&data->update_lock); |
@@ -819,11 +911,13 @@ static ssize_t show_bank1_alarm(struct device *dev, | |||
819 | struct abituguru_data *data = abituguru_update_device(dev); | 911 | struct abituguru_data *data = abituguru_update_device(dev); |
820 | if (!data) | 912 | if (!data) |
821 | return -EIO; | 913 | return -EIO; |
822 | /* See if the alarm bit for this sensor is set, and if the | 914 | /* |
823 | alarm matches the type of alarm we're looking for (for volt | 915 | * See if the alarm bit for this sensor is set, and if the |
824 | it can be either low or high). The type is stored in a few | 916 | * alarm matches the type of alarm we're looking for (for volt |
825 | readonly bits in the settings part of the relevant sensor. | 917 | * it can be either low or high). The type is stored in a few |
826 | The bitmask of the type is passed to us in attr->nr. */ | 918 | * readonly bits in the settings part of the relevant sensor. |
919 | * The bitmask of the type is passed to us in attr->nr. | ||
920 | */ | ||
827 | if ((data->alarms[attr->index / 8] & (0x01 << (attr->index % 8))) && | 921 | if ((data->alarms[attr->index / 8] & (0x01 << (attr->index % 8))) && |
828 | (data->bank1_settings[attr->index][0] & attr->nr)) | 922 | (data->bank1_settings[attr->index][0] & attr->nr)) |
829 | return sprintf(buf, "1\n"); | 923 | return sprintf(buf, "1\n"); |
@@ -871,10 +965,15 @@ static ssize_t store_bank1_mask(struct device *dev, | |||
871 | { | 965 | { |
872 | struct sensor_device_attribute_2 *attr = to_sensor_dev_attr_2(devattr); | 966 | struct sensor_device_attribute_2 *attr = to_sensor_dev_attr_2(devattr); |
873 | struct abituguru_data *data = dev_get_drvdata(dev); | 967 | struct abituguru_data *data = dev_get_drvdata(dev); |
874 | int mask = simple_strtoul(buf, NULL, 10); | 968 | ssize_t ret; |
875 | ssize_t ret = count; | ||
876 | u8 orig_val; | 969 | u8 orig_val; |
970 | unsigned long mask; | ||
971 | |||
972 | ret = kstrtoul(buf, 10, &mask); | ||
973 | if (ret) | ||
974 | return ret; | ||
877 | 975 | ||
976 | ret = count; | ||
878 | mutex_lock(&data->update_lock); | 977 | mutex_lock(&data->update_lock); |
879 | orig_val = data->bank1_settings[attr->index][0]; | 978 | orig_val = data->bank1_settings[attr->index][0]; |
880 | 979 | ||
@@ -899,10 +998,15 @@ static ssize_t store_bank2_mask(struct device *dev, | |||
899 | { | 998 | { |
900 | struct sensor_device_attribute_2 *attr = to_sensor_dev_attr_2(devattr); | 999 | struct sensor_device_attribute_2 *attr = to_sensor_dev_attr_2(devattr); |
901 | struct abituguru_data *data = dev_get_drvdata(dev); | 1000 | struct abituguru_data *data = dev_get_drvdata(dev); |
902 | int mask = simple_strtoul(buf, NULL, 10); | 1001 | ssize_t ret; |
903 | ssize_t ret = count; | ||
904 | u8 orig_val; | 1002 | u8 orig_val; |
1003 | unsigned long mask; | ||
905 | 1004 | ||
1005 | ret = kstrtoul(buf, 10, &mask); | ||
1006 | if (ret) | ||
1007 | return ret; | ||
1008 | |||
1009 | ret = count; | ||
906 | mutex_lock(&data->update_lock); | 1010 | mutex_lock(&data->update_lock); |
907 | orig_val = data->bank2_settings[attr->index][0]; | 1011 | orig_val = data->bank2_settings[attr->index][0]; |
908 | 1012 | ||
@@ -937,10 +1041,17 @@ static ssize_t store_pwm_setting(struct device *dev, struct device_attribute | |||
937 | { | 1041 | { |
938 | struct sensor_device_attribute_2 *attr = to_sensor_dev_attr_2(devattr); | 1042 | struct sensor_device_attribute_2 *attr = to_sensor_dev_attr_2(devattr); |
939 | struct abituguru_data *data = dev_get_drvdata(dev); | 1043 | struct abituguru_data *data = dev_get_drvdata(dev); |
940 | u8 min, val = (simple_strtoul(buf, NULL, 10) + | 1044 | u8 min; |
941 | abituguru_pwm_settings_multiplier[attr->nr]/2) / | 1045 | unsigned long val; |
942 | abituguru_pwm_settings_multiplier[attr->nr]; | 1046 | ssize_t ret; |
943 | ssize_t ret = count; | 1047 | |
1048 | ret = kstrtoul(buf, 10, &val); | ||
1049 | if (ret) | ||
1050 | return ret; | ||
1051 | |||
1052 | ret = count; | ||
1053 | val = (val + abituguru_pwm_settings_multiplier[attr->nr] / 2) / | ||
1054 | abituguru_pwm_settings_multiplier[attr->nr]; | ||
944 | 1055 | ||
945 | /* special case pwm1 min pwm% */ | 1056 | /* special case pwm1 min pwm% */ |
946 | if ((attr->index == 0) && ((attr->nr == 1) || (attr->nr == 2))) | 1057 | if ((attr->index == 0) && ((attr->nr == 1) || (attr->nr == 2))) |
@@ -949,7 +1060,7 @@ static ssize_t store_pwm_setting(struct device *dev, struct device_attribute | |||
949 | min = abituguru_pwm_min[attr->nr]; | 1060 | min = abituguru_pwm_min[attr->nr]; |
950 | 1061 | ||
951 | /* this check can be done before taking the lock */ | 1062 | /* this check can be done before taking the lock */ |
952 | if ((val < min) || (val > abituguru_pwm_max[attr->nr])) | 1063 | if (val < min || val > abituguru_pwm_max[attr->nr]) |
953 | return -EINVAL; | 1064 | return -EINVAL; |
954 | 1065 | ||
955 | mutex_lock(&data->update_lock); | 1066 | mutex_lock(&data->update_lock); |
@@ -981,8 +1092,10 @@ static ssize_t show_pwm_sensor(struct device *dev, | |||
981 | struct sensor_device_attribute_2 *attr = to_sensor_dev_attr_2(devattr); | 1092 | struct sensor_device_attribute_2 *attr = to_sensor_dev_attr_2(devattr); |
982 | struct abituguru_data *data = dev_get_drvdata(dev); | 1093 | struct abituguru_data *data = dev_get_drvdata(dev); |
983 | int i; | 1094 | int i; |
984 | /* We need to walk to the temp sensor addresses to find what | 1095 | /* |
985 | the userspace id of the configured temp sensor is. */ | 1096 | * We need to walk to the temp sensor addresses to find what |
1097 | * the userspace id of the configured temp sensor is. | ||
1098 | */ | ||
986 | for (i = 0; i < data->bank1_sensors[ABIT_UGURU_TEMP_SENSOR]; i++) | 1099 | for (i = 0; i < data->bank1_sensors[ABIT_UGURU_TEMP_SENSOR]; i++) |
987 | if (data->bank1_address[ABIT_UGURU_TEMP_SENSOR][i] == | 1100 | if (data->bank1_address[ABIT_UGURU_TEMP_SENSOR][i] == |
988 | (data->pwm_settings[attr->index][0] & 0x0F)) | 1101 | (data->pwm_settings[attr->index][0] & 0x0F)) |
@@ -996,27 +1109,32 @@ static ssize_t store_pwm_sensor(struct device *dev, struct device_attribute | |||
996 | { | 1109 | { |
997 | struct sensor_device_attribute_2 *attr = to_sensor_dev_attr_2(devattr); | 1110 | struct sensor_device_attribute_2 *attr = to_sensor_dev_attr_2(devattr); |
998 | struct abituguru_data *data = dev_get_drvdata(dev); | 1111 | struct abituguru_data *data = dev_get_drvdata(dev); |
999 | unsigned long val = simple_strtoul(buf, NULL, 10) - 1; | 1112 | ssize_t ret; |
1000 | ssize_t ret = count; | 1113 | unsigned long val; |
1114 | u8 orig_val; | ||
1115 | u8 address; | ||
1116 | |||
1117 | ret = kstrtoul(buf, 10, &val); | ||
1118 | if (ret) | ||
1119 | return ret; | ||
1001 | 1120 | ||
1121 | if (val == 0 || val > data->bank1_sensors[ABIT_UGURU_TEMP_SENSOR]) | ||
1122 | return -EINVAL; | ||
1123 | |||
1124 | val -= 1; | ||
1125 | ret = count; | ||
1002 | mutex_lock(&data->update_lock); | 1126 | mutex_lock(&data->update_lock); |
1003 | if (val < data->bank1_sensors[ABIT_UGURU_TEMP_SENSOR]) { | 1127 | orig_val = data->pwm_settings[attr->index][0]; |
1004 | u8 orig_val = data->pwm_settings[attr->index][0]; | 1128 | address = data->bank1_address[ABIT_UGURU_TEMP_SENSOR][val]; |
1005 | u8 address = data->bank1_address[ABIT_UGURU_TEMP_SENSOR][val]; | 1129 | data->pwm_settings[attr->index][0] &= 0xF0; |
1006 | data->pwm_settings[attr->index][0] &= 0xF0; | 1130 | data->pwm_settings[attr->index][0] |= address; |
1007 | data->pwm_settings[attr->index][0] |= address; | 1131 | if (data->pwm_settings[attr->index][0] != orig_val) { |
1008 | if (data->pwm_settings[attr->index][0] != orig_val) { | 1132 | if (abituguru_write(data, ABIT_UGURU_FAN_PWM + 1, attr->index, |
1009 | if (abituguru_write(data, ABIT_UGURU_FAN_PWM + 1, | 1133 | data->pwm_settings[attr->index], 5) < 1) { |
1010 | attr->index, | 1134 | data->pwm_settings[attr->index][0] = orig_val; |
1011 | data->pwm_settings[attr->index], | 1135 | ret = -EIO; |
1012 | 5) < 1) { | ||
1013 | data->pwm_settings[attr->index][0] = orig_val; | ||
1014 | ret = -EIO; | ||
1015 | } | ||
1016 | } | 1136 | } |
1017 | } | 1137 | } |
1018 | else | ||
1019 | ret = -EINVAL; | ||
1020 | mutex_unlock(&data->update_lock); | 1138 | mutex_unlock(&data->update_lock); |
1021 | return ret; | 1139 | return ret; |
1022 | } | 1140 | } |
@@ -1037,22 +1155,27 @@ static ssize_t store_pwm_enable(struct device *dev, struct device_attribute | |||
1037 | { | 1155 | { |
1038 | struct sensor_device_attribute_2 *attr = to_sensor_dev_attr_2(devattr); | 1156 | struct sensor_device_attribute_2 *attr = to_sensor_dev_attr_2(devattr); |
1039 | struct abituguru_data *data = dev_get_drvdata(dev); | 1157 | struct abituguru_data *data = dev_get_drvdata(dev); |
1040 | u8 orig_val, user_val = simple_strtoul(buf, NULL, 10); | 1158 | u8 orig_val; |
1041 | ssize_t ret = count; | 1159 | ssize_t ret; |
1160 | unsigned long user_val; | ||
1161 | |||
1162 | ret = kstrtoul(buf, 10, &user_val); | ||
1163 | if (ret) | ||
1164 | return ret; | ||
1042 | 1165 | ||
1166 | ret = count; | ||
1043 | mutex_lock(&data->update_lock); | 1167 | mutex_lock(&data->update_lock); |
1044 | orig_val = data->pwm_settings[attr->index][0]; | 1168 | orig_val = data->pwm_settings[attr->index][0]; |
1045 | switch (user_val) { | 1169 | switch (user_val) { |
1046 | case 0: | 1170 | case 0: |
1047 | data->pwm_settings[attr->index][0] &= | 1171 | data->pwm_settings[attr->index][0] &= |
1048 | ~ABIT_UGURU_FAN_PWM_ENABLE; | 1172 | ~ABIT_UGURU_FAN_PWM_ENABLE; |
1049 | break; | 1173 | break; |
1050 | case 2: | 1174 | case 2: |
1051 | data->pwm_settings[attr->index][0] |= | 1175 | data->pwm_settings[attr->index][0] |= ABIT_UGURU_FAN_PWM_ENABLE; |
1052 | ABIT_UGURU_FAN_PWM_ENABLE; | 1176 | break; |
1053 | break; | 1177 | default: |
1054 | default: | 1178 | ret = -EINVAL; |
1055 | ret = -EINVAL; | ||
1056 | } | 1179 | } |
1057 | if ((data->pwm_settings[attr->index][0] != orig_val) && | 1180 | if ((data->pwm_settings[attr->index][0] != orig_val) && |
1058 | (abituguru_write(data, ABIT_UGURU_FAN_PWM + 1, | 1181 | (abituguru_write(data, ABIT_UGURU_FAN_PWM + 1, |
@@ -1147,13 +1270,16 @@ static int __devinit abituguru_probe(struct platform_device *pdev) | |||
1147 | int i, j, used, sysfs_names_free, sysfs_attr_i, res = -ENODEV; | 1270 | int i, j, used, sysfs_names_free, sysfs_attr_i, res = -ENODEV; |
1148 | char *sysfs_filename; | 1271 | char *sysfs_filename; |
1149 | 1272 | ||
1150 | /* El weirdo probe order, to keep the sysfs order identical to the | 1273 | /* |
1151 | BIOS and window-appliction listing order. */ | 1274 | * El weirdo probe order, to keep the sysfs order identical to the |
1275 | * BIOS and window-appliction listing order. | ||
1276 | */ | ||
1152 | const u8 probe_order[ABIT_UGURU_MAX_BANK1_SENSORS] = { | 1277 | const u8 probe_order[ABIT_UGURU_MAX_BANK1_SENSORS] = { |
1153 | 0x00, 0x01, 0x03, 0x04, 0x0A, 0x08, 0x0E, 0x02, | 1278 | 0x00, 0x01, 0x03, 0x04, 0x0A, 0x08, 0x0E, 0x02, |
1154 | 0x09, 0x06, 0x05, 0x0B, 0x0F, 0x0D, 0x07, 0x0C }; | 1279 | 0x09, 0x06, 0x05, 0x0B, 0x0F, 0x0D, 0x07, 0x0C }; |
1155 | 1280 | ||
1156 | if (!(data = kzalloc(sizeof(struct abituguru_data), GFP_KERNEL))) | 1281 | data = kzalloc(sizeof(struct abituguru_data), GFP_KERNEL); |
1282 | if (!data) | ||
1157 | return -ENOMEM; | 1283 | return -ENOMEM; |
1158 | 1284 | ||
1159 | data->addr = platform_get_resource(pdev, IORESOURCE_IO, 0)->start; | 1285 | data->addr = platform_get_resource(pdev, IORESOURCE_IO, 0)->start; |
@@ -1164,9 +1290,11 @@ static int __devinit abituguru_probe(struct platform_device *pdev) | |||
1164 | if (inb_p(data->addr + ABIT_UGURU_DATA) == ABIT_UGURU_STATUS_INPUT) | 1290 | if (inb_p(data->addr + ABIT_UGURU_DATA) == ABIT_UGURU_STATUS_INPUT) |
1165 | data->uguru_ready = 1; | 1291 | data->uguru_ready = 1; |
1166 | 1292 | ||
1167 | /* Completely read the uGuru this has 2 purposes: | 1293 | /* |
1168 | - testread / see if one really is there. | 1294 | * Completely read the uGuru this has 2 purposes: |
1169 | - make an in memory copy of all the uguru settings for future use. */ | 1295 | * - testread / see if one really is there. |
1296 | * - make an in memory copy of all the uguru settings for future use. | ||
1297 | */ | ||
1170 | if (abituguru_read(data, ABIT_UGURU_ALARM_BANK, 0, | 1298 | if (abituguru_read(data, ABIT_UGURU_ALARM_BANK, 0, |
1171 | data->alarms, 3, ABIT_UGURU_MAX_RETRIES) != 3) | 1299 | data->alarms, 3, ABIT_UGURU_MAX_RETRIES) != 3) |
1172 | goto abituguru_probe_error; | 1300 | goto abituguru_probe_error; |
@@ -1181,11 +1309,13 @@ static int __devinit abituguru_probe(struct platform_device *pdev) | |||
1181 | ABIT_UGURU_MAX_RETRIES) != 3) | 1309 | ABIT_UGURU_MAX_RETRIES) != 3) |
1182 | goto abituguru_probe_error; | 1310 | goto abituguru_probe_error; |
1183 | } | 1311 | } |
1184 | /* Note: We don't know how many bank2 sensors / pwms there really are, | 1312 | /* |
1185 | but in order to "detect" this we need to read the maximum amount | 1313 | * Note: We don't know how many bank2 sensors / pwms there really are, |
1186 | anyways. If we read sensors/pwms not there we'll just read crap | 1314 | * but in order to "detect" this we need to read the maximum amount |
1187 | this can't hurt. We need the detection because we don't want | 1315 | * anyways. If we read sensors/pwms not there we'll just read crap |
1188 | unwanted writes, which will hurt! */ | 1316 | * this can't hurt. We need the detection because we don't want |
1317 | * unwanted writes, which will hurt! | ||
1318 | */ | ||
1189 | for (i = 0; i < ABIT_UGURU_MAX_BANK2_SENSORS; i++) { | 1319 | for (i = 0; i < ABIT_UGURU_MAX_BANK2_SENSORS; i++) { |
1190 | if (abituguru_read(data, ABIT_UGURU_SENSOR_BANK2, i, | 1320 | if (abituguru_read(data, ABIT_UGURU_SENSOR_BANK2, i, |
1191 | &data->bank2_value[i], 1, | 1321 | &data->bank2_value[i], 1, |
@@ -1332,24 +1462,26 @@ static struct abituguru_data *abituguru_update_device(struct device *dev) | |||
1332 | mutex_lock(&data->update_lock); | 1462 | mutex_lock(&data->update_lock); |
1333 | if (time_after(jiffies, data->last_updated + HZ)) { | 1463 | if (time_after(jiffies, data->last_updated + HZ)) { |
1334 | success = 0; | 1464 | success = 0; |
1335 | if ((err = abituguru_read(data, ABIT_UGURU_ALARM_BANK, 0, | 1465 | err = abituguru_read(data, ABIT_UGURU_ALARM_BANK, 0, |
1336 | data->alarms, 3, 0)) != 3) | 1466 | data->alarms, 3, 0); |
1467 | if (err != 3) | ||
1337 | goto LEAVE_UPDATE; | 1468 | goto LEAVE_UPDATE; |
1338 | for (i = 0; i < ABIT_UGURU_MAX_BANK1_SENSORS; i++) { | 1469 | for (i = 0; i < ABIT_UGURU_MAX_BANK1_SENSORS; i++) { |
1339 | if ((err = abituguru_read(data, | 1470 | err = abituguru_read(data, ABIT_UGURU_SENSOR_BANK1, |
1340 | ABIT_UGURU_SENSOR_BANK1, i, | 1471 | i, &data->bank1_value[i], 1, 0); |
1341 | &data->bank1_value[i], 1, 0)) != 1) | 1472 | if (err != 1) |
1342 | goto LEAVE_UPDATE; | 1473 | goto LEAVE_UPDATE; |
1343 | if ((err = abituguru_read(data, | 1474 | err = abituguru_read(data, ABIT_UGURU_SENSOR_BANK1 + 1, |
1344 | ABIT_UGURU_SENSOR_BANK1 + 1, i, | 1475 | i, data->bank1_settings[i], 3, 0); |
1345 | data->bank1_settings[i], 3, 0)) != 3) | 1476 | if (err != 3) |
1346 | goto LEAVE_UPDATE; | 1477 | goto LEAVE_UPDATE; |
1347 | } | 1478 | } |
1348 | for (i = 0; i < data->bank2_sensors; i++) | 1479 | for (i = 0; i < data->bank2_sensors; i++) { |
1349 | if ((err = abituguru_read(data, | 1480 | err = abituguru_read(data, ABIT_UGURU_SENSOR_BANK2, i, |
1350 | ABIT_UGURU_SENSOR_BANK2, i, | 1481 | &data->bank2_value[i], 1, 0); |
1351 | &data->bank2_value[i], 1, 0)) != 1) | 1482 | if (err != 1) |
1352 | goto LEAVE_UPDATE; | 1483 | goto LEAVE_UPDATE; |
1484 | } | ||
1353 | /* success! */ | 1485 | /* success! */ |
1354 | success = 1; | 1486 | success = 1; |
1355 | data->update_timeouts = 0; | 1487 | data->update_timeouts = 0; |
@@ -1385,8 +1517,10 @@ LEAVE_UPDATE: | |||
1385 | static int abituguru_suspend(struct platform_device *pdev, pm_message_t state) | 1517 | static int abituguru_suspend(struct platform_device *pdev, pm_message_t state) |
1386 | { | 1518 | { |
1387 | struct abituguru_data *data = platform_get_drvdata(pdev); | 1519 | struct abituguru_data *data = platform_get_drvdata(pdev); |
1388 | /* make sure all communications with the uguru are done and no new | 1520 | /* |
1389 | ones are started */ | 1521 | * make sure all communications with the uguru are done and no new |
1522 | * ones are started | ||
1523 | */ | ||
1390 | mutex_lock(&data->update_lock); | 1524 | mutex_lock(&data->update_lock); |
1391 | return 0; | 1525 | return 0; |
1392 | } | 1526 | } |
@@ -1418,12 +1552,14 @@ static struct platform_driver abituguru_driver = { | |||
1418 | 1552 | ||
1419 | static int __init abituguru_detect(void) | 1553 | static int __init abituguru_detect(void) |
1420 | { | 1554 | { |
1421 | /* See if there is an uguru there. After a reboot uGuru will hold 0x00 | 1555 | /* |
1422 | at DATA and 0xAC, when this driver has already been loaded once | 1556 | * See if there is an uguru there. After a reboot uGuru will hold 0x00 |
1423 | DATA will hold 0x08. For most uGuru's CMD will hold 0xAC in either | 1557 | * at DATA and 0xAC, when this driver has already been loaded once |
1424 | scenario but some will hold 0x00. | 1558 | * DATA will hold 0x08. For most uGuru's CMD will hold 0xAC in either |
1425 | Some uGuru's initially hold 0x09 at DATA and will only hold 0x08 | 1559 | * scenario but some will hold 0x00. |
1426 | after reading CMD first, so CMD must be read first! */ | 1560 | * Some uGuru's initially hold 0x09 at DATA and will only hold 0x08 |
1561 | * after reading CMD first, so CMD must be read first! | ||
1562 | */ | ||
1427 | u8 cmd_val = inb_p(ABIT_UGURU_BASE + ABIT_UGURU_CMD); | 1563 | u8 cmd_val = inb_p(ABIT_UGURU_BASE + ABIT_UGURU_CMD); |
1428 | u8 data_val = inb_p(ABIT_UGURU_BASE + ABIT_UGURU_DATA); | 1564 | u8 data_val = inb_p(ABIT_UGURU_BASE + ABIT_UGURU_DATA); |
1429 | if (((data_val == 0x00) || (data_val == 0x08)) && | 1565 | if (((data_val == 0x00) || (data_val == 0x08)) && |