Merge branch 'hwmon-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/jdelvare/staging

* 'hwmon-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/jdelvare/staging: (23 commits)
hwmon: Remove the deprecated adt7473 driver
hwmon: Fix off-by-one kind values
hwmon: (tmp421) Fix temperature conversions
hwmon: (tmp421) Restore missing inputs
hwmon: Driver for Andigilog aSC7621 family monitoring chips
hwmon: (adt7411) Improve locking
hwmon: Add driver for ADT7411 voltage and temperature sensor
hwmon: (w83793) Add watchdog functionality
hwmon: (g760a) Make rpm_from_cnt static
hwmon: (it87) Validate auto pwm settings
hwmon: (it87) Add support for old automatic fan speed control
hwmon: (it87) Drop dead web links in documentation
hwmon: (it87) Add an entry in MAINTAINERS
hwmon: (it87) Use strict_strtol instead of simple_strtol
hwmon: (it87) Fix many checkpatch errors and warnings
hwmon: (it87) Add support for beep on alarm
hwmon: (it87) Create vid attributes by group
hwmon: (it87) Refactor attributes creation and removal
hwmon: (it87) Expose the PWM/temperature mappings
hwmon: (it87) Display fan outputs in automatic mode as such
...

+3336 -1580
-6
Documentation/feature-removal-schedule.txt
··· 449 450 ---------------------------- 451 452 - What: adt7473 hardware monitoring driver 453 - When: February 2010 454 - Why: Obsoleted by the adt7475 driver. 455 - Who: Jean Delvare <khali@linux-fr.org> 456 - 457 - --------------------------- 458 What: Support for lcd_switch and display_get in asus-laptop driver 459 When: March 2010 460 Why: These two features use non-standard interfaces. There are the
··· 449 450 ---------------------------- 451 452 What: Support for lcd_switch and display_get in asus-laptop driver 453 When: March 2010 454 Why: These two features use non-standard interfaces. There are the
+42
Documentation/hwmon/adt7411
···
··· 1 + Kernel driver adt7411 2 + ===================== 3 + 4 + Supported chips: 5 + * Analog Devices ADT7411 6 + Prefix: 'adt7411' 7 + Addresses scanned: 0x48, 0x4a, 0x4b 8 + Datasheet: Publicly available at the Analog Devices website 9 + 10 + Author: Wolfram Sang (based on adt7470 by Darrick J. Wong) 11 + 12 + Description 13 + ----------- 14 + 15 + This driver implements support for the Analog Devices ADT7411 chip. There may 16 + be other chips that implement this interface. 17 + 18 + The ADT7411 can use an I2C/SMBus compatible 2-wire interface or an 19 + SPI-compatible 4-wire interface. It provides a 10-bit analog to digital 20 + converter which measures 1 temperature, vdd and 8 input voltages. It has an 21 + internal temperature sensor, but an external one can also be connected (one 22 + loses 2 inputs then). There are high- and low-limit registers for all inputs. 23 + 24 + Check the datasheet for details. 25 + 26 + sysfs-Interface 27 + --------------- 28 + 29 + in0_input - vdd voltage input 30 + in[1-8]_input - analog 1-8 input 31 + temp1_input - temperature input 32 + 33 + Besides standard interfaces, this driver adds (0 = off, 1 = on): 34 + 35 + adc_ref_vdd - Use vdd as reference instead of 2.25 V 36 + fast_sampling - Sample at 22.5 kHz instead of 1.4 kHz, but drop filters 37 + no_average - Turn off averaging over 16 samples 38 + 39 + Notes 40 + ----- 41 + 42 + SPI, external temperature sensor and limit registers are not supported yet.
-74
Documentation/hwmon/adt7473
··· 1 - Kernel driver adt7473 2 - ====================== 3 - 4 - Supported chips: 5 - * Analog Devices ADT7473 6 - Prefix: 'adt7473' 7 - Addresses scanned: I2C 0x2C, 0x2D, 0x2E 8 - Datasheet: Publicly available at the Analog Devices website 9 - 10 - Author: Darrick J. Wong 11 - 12 - This driver is depreacted, please use the adt7475 driver instead. 13 - 14 - Description 15 - ----------- 16 - 17 - This driver implements support for the Analog Devices ADT7473 chip family. 18 - 19 - The ADT7473 uses the 2-wire interface compatible with the SMBUS 2.0 20 - specification. Using an analog to digital converter it measures three (3) 21 - temperatures and two (2) voltages. It has four (4) 16-bit counters for 22 - measuring fan speed. There are three (3) PWM outputs that can be used 23 - to control fan speed. 24 - 25 - A sophisticated control system for the PWM outputs is designed into the 26 - ADT7473 that allows fan speed to be adjusted automatically based on any of the 27 - three temperature sensors. Each PWM output is individually adjustable and 28 - programmable. Once configured, the ADT7473 will adjust the PWM outputs in 29 - response to the measured temperatures without further host intervention. 30 - This feature can also be disabled for manual control of the PWM's. 31 - 32 - Each of the measured inputs (voltage, temperature, fan speed) has 33 - corresponding high/low limit values. The ADT7473 will signal an ALARM if 34 - any measured value exceeds either limit. 35 - 36 - The ADT7473 samples all inputs continuously. The driver will not read 37 - the registers more often than once every other second. Further, 38 - configuration data is only read once per minute. 39 - 40 - Special Features 41 - ---------------- 42 - 43 - The ADT7473 have a 10-bit ADC and can therefore measure temperatures 44 - with 0.25 degC resolution. Temperature readings can be configured either 45 - for twos complement format or "Offset 64" format, wherein 63 is subtracted 46 - from the raw value to get the temperature value. 47 - 48 - The Analog Devices datasheet is very detailed and describes a procedure for 49 - determining an optimal configuration for the automatic PWM control. 50 - 51 - Configuration Notes 52 - ------------------- 53 - 54 - Besides standard interfaces driver adds the following: 55 - 56 - * PWM Control 57 - 58 - * pwm#_auto_point1_pwm and temp#_auto_point1_temp and 59 - * pwm#_auto_point2_pwm and temp#_auto_point2_temp - 60 - 61 - point1: Set the pwm speed at a lower temperature bound. 62 - point2: Set the pwm speed at a higher temperature bound. 63 - 64 - The ADT7473 will scale the pwm between the lower and higher pwm speed when 65 - the temperature is between the two temperature boundaries. PWM values range 66 - from 0 (off) to 255 (full speed). Fan speed will be set to maximum when the 67 - temperature sensor associated with the PWM control exceeds temp#_max. 68 - 69 - Notes 70 - ----- 71 - 72 - The NVIDIA binary driver presents an ADT7473 chip via an on-card i2c bus. 73 - Unfortunately, they fail to set the i2c adapter class, so this driver may 74 - fail to find the chip until the nvidia driver is patched.
···
+296
Documentation/hwmon/asc7621
···
··· 1 + Kernel driver asc7621 2 + ================== 3 + 4 + Supported chips: 5 + Andigilog aSC7621 and aSC7621a 6 + Prefix: 'asc7621' 7 + Addresses scanned: I2C 0x2c, 0x2d, 0x2e 8 + Datasheet: http://www.fairview5.com/linux/asc7621/asc7621.pdf 9 + 10 + Author: 11 + George Joseph 12 + 13 + Description provided by Dave Pivin @ Andigilog: 14 + 15 + Andigilog has both the PECI and pre-PECI versions of the Heceta-6, as 16 + Intel calls them. Heceta-6e has high frequency PWM and Heceta-6p has 17 + added PECI and a 4th thermal zone. The Andigilog aSC7611 is the 18 + Heceta-6e part and aSC7621 is the Heceta-6p part. They are both in 19 + volume production, shipping to Intel and their subs. 20 + 21 + We have enhanced both parts relative to the governing Intel 22 + specification. First enhancement is temperature reading resolution. We 23 + have used registers below 20h for vendor-specific functions in addition 24 + to those in the Intel-specified vendor range. 25 + 26 + Our conversion process produces a result that is reported as two bytes. 27 + The fan speed control uses this finer value to produce a "step-less" fan 28 + PWM output. These two bytes are "read-locked" to guarantee that once a 29 + high or low byte is read, the other byte is locked-in until after the 30 + next read of any register. So to get an atomic reading, read high or low 31 + byte, then the very next read should be the opposite byte. Our data 32 + sheet says 10-bits of resolution, although you may find the lower bits 33 + are active, they are not necessarily reliable or useful externally. We 34 + chose not to mask them. 35 + 36 + We employ significant filtering that is user tunable as described in the 37 + data sheet. Our temperature reports and fan PWM outputs are very smooth 38 + when compared to the competition, in addition to the higher resolution 39 + temperature reports. The smoother PWM output does not require user 40 + intervention. 41 + 42 + We offer GPIO features on the former VID pins. These are open-drain 43 + outputs or inputs and may be used as general purpose I/O or as alarm 44 + outputs that are based on temperature limits. These are in 19h and 1Ah. 45 + 46 + We offer flexible mapping of temperature readings to thermal zones. Any 47 + temperature may be mapped to any zone, which has a default assignment 48 + that follows Intel's specs. 49 + 50 + Since there is a fan to zone assignment that allows for the "hotter" of 51 + a set of zones to control the PWM of an individual fan, but there is no 52 + indication to the user, we have added an indicator that shows which zone 53 + is currently controlling the PWM for a given fan. This is in register 54 + 00h. 55 + 56 + Both remote diode temperature readings may be given an offset value such 57 + that the reported reading as well as the temperature used to determine 58 + PWM may be offset for system calibration purposes. 59 + 60 + PECI Extended configuration allows for having more than two domains per 61 + PECI address and also provides an enabling function for each PECI 62 + address. One could use our flexible zone assignment to have a zone 63 + assigned to up to 4 PECI addresses. This is not possible in the default 64 + Intel configuration. This would be useful in multi-CPU systems with 65 + individual fans on each that would benefit from individual fan control. 66 + This is in register 0Eh. 67 + 68 + The tachometer measurement system is flexible and able to adapt to many 69 + fan types. We can also support pulse-stretched PWM so that 3-wire fans 70 + may be used. These characteristics are in registers 04h to 07h. 71 + 72 + Finally, we have added a tach disable function that turns off the tach 73 + measurement system for individual tachs in order to save power. That is 74 + in register 75h. 75 + 76 + -- 77 + aSC7621 Product Description 78 + 79 + The aSC7621 has a two wire digital interface compatible with SMBus 2.0. 80 + Using a 10-bit ADC, the aSC7621 measures the temperature of two remote diode 81 + connected transistors as well as its own die. Support for Platform 82 + Environmental Control Interface (PECI) is included. 83 + 84 + Using temperature information from these four zones, an automatic fan speed 85 + control algorithm is employed to minimize acoustic impact while achieving 86 + recommended CPU temperature under varying operational loads. 87 + 88 + To set fan speed, the aSC7621 has three independent pulse width modulation 89 + (PWM) outputs that are controlled by one, or a combination of three, 90 + temperature zones. Both high- and low-frequency PWM ranges are supported. 91 + 92 + The aSC7621 also includes a digital filter that can be invoked to smooth 93 + temperature readings for better control of fan speed and minimum acoustic 94 + impact. 95 + 96 + The aSC7621 has tachometer inputs to measure fan speed on up to four fans. 97 + Limit and status registers for all measured values are included to alert 98 + the system host that any measurements are outside of programmed limits 99 + via status registers. 100 + 101 + System voltages of VCCP, 2.5V, 3.3V, 5.0V, and 12V motherboard power are 102 + monitored efficiently with internal scaling resistors. 103 + 104 + Features 105 + - Supports PECI interface and monitors internal and remote thermal diodes 106 + - 2-wire, SMBus 2.0 compliant, serial interface 107 + - 10-bit ADC 108 + - Monitors VCCP, 2.5V, 3.3V, 5.0V, and 12V motherboard/processor supplies 109 + - Programmable autonomous fan control based on temperature readings 110 + - Noise filtering of temperature reading for fan speed control 111 + - 0.25C digital temperature sensor resolution 112 + - 3 PWM fan speed control outputs for 2-, 3- or 4-wire fans and up to 4 fan 113 + tachometer inputs 114 + - Enhanced measured temperature to Temperature Zone assignment. 115 + - Provides high and low PWM frequency ranges 116 + - 3 GPIO pins for custom use 117 + - 24-Lead QSOP package 118 + 119 + Configuration Notes 120 + =================== 121 + 122 + Except where noted below, the sysfs entries created by this driver follow 123 + the standards defined in "sysfs-interface". 124 + 125 + temp1_source 126 + 0 (default) peci_legacy = 0, Remote 1 Temperature 127 + peci_legacy = 1, PECI Processor Temperature 0 128 + 1 Remote 1 Temperature 129 + 2 Remote 2 Temperature 130 + 3 Internal Temperature 131 + 4 PECI Processor Temperature 0 132 + 5 PECI Processor Temperature 1 133 + 6 PECI Processor Temperature 2 134 + 7 PECI Processor Temperature 3 135 + 136 + temp2_source 137 + 0 (default) Internal Temperature 138 + 1 Remote 1 Temperature 139 + 2 Remote 2 Temperature 140 + 3 Internal Temperature 141 + 4 PECI Processor Temperature 0 142 + 5 PECI Processor Temperature 1 143 + 6 PECI Processor Temperature 2 144 + 7 PECI Processor Temperature 3 145 + 146 + temp3_source 147 + 0 (default) Remote 2 Temperature 148 + 1 Remote 1 Temperature 149 + 2 Remote 2 Temperature 150 + 3 Internal Temperature 151 + 4 PECI Processor Temperature 0 152 + 5 PECI Processor Temperature 1 153 + 6 PECI Processor Temperature 2 154 + 7 PECI Processor Temperature 3 155 + 156 + temp4_source 157 + 0 (default) peci_legacy = 0, PECI Processor Temperature 0 158 + peci_legacy = 1, Remote 1 Temperature 159 + 1 Remote 1 Temperature 160 + 2 Remote 2 Temperature 161 + 3 Internal Temperature 162 + 4 PECI Processor Temperature 0 163 + 5 PECI Processor Temperature 1 164 + 6 PECI Processor Temperature 2 165 + 7 PECI Processor Temperature 3 166 + 167 + temp[1-4]_smoothing_enable 168 + temp[1-4]_smoothing_time 169 + Smooths spikes in temp readings caused by noise. 170 + Valid values in milliseconds are: 171 + 35000 172 + 17600 173 + 11800 174 + 7000 175 + 4400 176 + 3000 177 + 1600 178 + 800 179 + 180 + temp[1-4]_crit 181 + When the corresponding zone temperature reaches this value, 182 + ALL pwm outputs will got to 100%. 183 + 184 + temp[5-8]_input 185 + temp[5-8]_enable 186 + The aSC7621 can also read temperatures provided by the processor 187 + via the PECI bus. Usually these are "core" temps and are relative 188 + to the point where the automatic thermal control circuit starts 189 + throttling. This means that these are usually negative numbers. 190 + 191 + pwm[1-3]_enable 192 + 0 Fan off. 193 + 1 Fan on manual control. 194 + 2 Fan on automatic control and will run at the minimum pwm 195 + if the temperature for the zone is below the minimum. 196 + 3 Fan on automatic control but will be off if the temperature 197 + for the zone is below the minimum. 198 + 4-254 Ignored. 199 + 255 Fan on full. 200 + 201 + pwm[1-3]_auto_channels 202 + Bitmap as described in sysctl-interface with the following 203 + exceptions... 204 + Only the following combination of zones (and their corresponding masks) 205 + are valid: 206 + 1 207 + 2 208 + 3 209 + 2,3 210 + 1,2,3 211 + 4 212 + 1,2,3,4 213 + 214 + Special values: 215 + 0 Disabled. 216 + 16 Fan on manual control. 217 + 31 Fan on full. 218 + 219 + 220 + pwm[1-3]_invert 221 + When set, inverts the meaning of pwm[1-3]. 222 + i.e. when pwm = 0, the fan will be on full and 223 + when pwm = 255 the fan will be off. 224 + 225 + pwm[1-3]_freq 226 + PWM frequency in Hz 227 + Valid values in Hz are: 228 + 229 + 10 230 + 15 231 + 23 232 + 30 (default) 233 + 38 234 + 47 235 + 62 236 + 94 237 + 23000 238 + 24000 239 + 25000 240 + 26000 241 + 27000 242 + 28000 243 + 29000 244 + 30000 245 + 246 + Setting any other value will be ignored. 247 + 248 + peci_enable 249 + Enables or disables PECI 250 + 251 + peci_avg 252 + Input filter average time. 253 + 254 + 0 0 Sec. (no Smoothing) (default) 255 + 1 0.25 Sec. 256 + 2 0.5 Sec. 257 + 3 1.0 Sec. 258 + 4 2.0 Sec. 259 + 5 4.0 Sec. 260 + 6 8.0 Sec. 261 + 7 0.0 Sec. 262 + 263 + peci_legacy 264 + 265 + 0 Standard Mode (default) 266 + Remote Diode 1 reading is associated with 267 + Temperature Zone 1, PECI is associated with 268 + Zone 4 269 + 270 + 1 Legacy Mode 271 + PECI is associated with Temperature Zone 1, 272 + Remote Diode 1 is associated with Zone 4 273 + 274 + peci_diode 275 + Diode filter 276 + 277 + 0 0.25 Sec. 278 + 1 1.1 Sec. 279 + 2 2.4 Sec. (default) 280 + 3 3.4 Sec. 281 + 4 5.0 Sec. 282 + 5 6.8 Sec. 283 + 6 10.2 Sec. 284 + 7 16.4 Sec. 285 + 286 + peci_4domain 287 + Four domain enable 288 + 289 + 0 1 or 2 Domains for enabled processors (default) 290 + 1 3 or 4 Domains for enabled processors 291 + 292 + peci_domain 293 + Domain 294 + 295 + 0 Processor contains a single domain (0) (default) 296 + 1 Processor contains two domains (0,1)
+38 -15
Documentation/hwmon/it87
··· 5 * IT8705F 6 Prefix: 'it87' 7 Addresses scanned: from Super I/O config space (8 I/O ports) 8 - Datasheet: Publicly available at the ITE website 9 - http://www.ite.com.tw/product_info/file/pc/IT8705F_V.0.4.1.pdf 10 * IT8712F 11 Prefix: 'it8712' 12 Addresses scanned: from Super I/O config space (8 I/O ports) 13 - Datasheet: Publicly available at the ITE website 14 - http://www.ite.com.tw/product_info/file/pc/IT8712F_V0.9.1.pdf 15 - http://www.ite.com.tw/product_info/file/pc/Errata%20V0.1%20for%20IT8712F%20V0.9.1.pdf 16 - http://www.ite.com.tw/product_info/file/pc/IT8712F_V0.9.3.pdf 17 * IT8716F/IT8726F 18 Prefix: 'it8716' 19 Addresses scanned: from Super I/O config space (8 I/O ports) 20 - Datasheet: Publicly available at the ITE website 21 - http://www.ite.com.tw/product_info/file/pc/IT8716F_V0.3.ZIP 22 - http://www.ite.com.tw/product_info/file/pc/IT8726F_V0.3.pdf 23 * IT8718F 24 Prefix: 'it8718' 25 Addresses scanned: from Super I/O config space (8 I/O ports) 26 - Datasheet: Publicly available at the ITE website 27 - http://www.ite.com.tw/product_info/file/pc/IT8718F_V0.2.zip 28 - http://www.ite.com.tw/product_info/file/pc/IT8718F_V0%203_(for%20C%20version).zip 29 * IT8720F 30 Prefix: 'it8720' 31 Addresses scanned: from Super I/O config space (8 I/O ports) 32 - Datasheet: Not yet publicly available. 33 * SiS950 [clone of IT8705F] 34 Prefix: 'it87' 35 Addresses scanned: from Super I/O config space (8 I/O ports) ··· 128 seconds since the last update). This means that you can easily miss 129 once-only alarms. 130 131 The IT87xx only updates its values each 1.5 seconds; reading it more often 132 will do no harm, but will return 'old' values. 133 ··· 146 ----------------- 147 148 The fan speed control features are limited to manual PWM mode. Automatic 149 - "Smart Guardian" mode control handling is not implemented. However 150 - if you want to go for "manual mode" just write 1 to pwmN_enable. 151 152 If you are only able to control the fan speed with very small PWM values, 153 try lowering the PWM base frequency (pwm1_freq). Depending on the fan, 154 it may give you a somewhat greater control range. The same frequency is 155 used to drive all fan outputs, which is why pwm2_freq and pwm3_freq are 156 read-only.
··· 5 * IT8705F 6 Prefix: 'it87' 7 Addresses scanned: from Super I/O config space (8 I/O ports) 8 + Datasheet: Once publicly available at the ITE website, but no longer 9 * IT8712F 10 Prefix: 'it8712' 11 Addresses scanned: from Super I/O config space (8 I/O ports) 12 + Datasheet: Once publicly available at the ITE website, but no longer 13 * IT8716F/IT8726F 14 Prefix: 'it8716' 15 Addresses scanned: from Super I/O config space (8 I/O ports) 16 + Datasheet: Once publicly available at the ITE website, but no longer 17 * IT8718F 18 Prefix: 'it8718' 19 Addresses scanned: from Super I/O config space (8 I/O ports) 20 + Datasheet: Once publicly available at the ITE website, but no longer 21 * IT8720F 22 Prefix: 'it8720' 23 Addresses scanned: from Super I/O config space (8 I/O ports) 24 + Datasheet: Not publicly available 25 * SiS950 [clone of IT8705F] 26 Prefix: 'it87' 27 Addresses scanned: from Super I/O config space (8 I/O ports) ··· 136 seconds since the last update). This means that you can easily miss 137 once-only alarms. 138 139 + Out-of-limit readings can also result in beeping, if the chip is properly 140 + wired and configured. Beeping can be enabled or disabled per sensor type 141 + (temperatures, voltages and fans.) 142 + 143 The IT87xx only updates its values each 1.5 seconds; reading it more often 144 will do no harm, but will return 'old' values. 145 ··· 150 ----------------- 151 152 The fan speed control features are limited to manual PWM mode. Automatic 153 + "Smart Guardian" mode control handling is only implemented for older chips 154 + (see below.) However if you want to go for "manual mode" just write 1 to 155 + pwmN_enable. 156 157 If you are only able to control the fan speed with very small PWM values, 158 try lowering the PWM base frequency (pwm1_freq). Depending on the fan, 159 it may give you a somewhat greater control range. The same frequency is 160 used to drive all fan outputs, which is why pwm2_freq and pwm3_freq are 161 read-only. 162 + 163 + 164 + Automatic fan speed control (old interface) 165 + ------------------------------------------- 166 + 167 + The driver supports the old interface to automatic fan speed control 168 + which is implemented by IT8705F chips up to revision F and IT8712F 169 + chips up to revision G. 170 + 171 + This interface implements 4 temperature vs. PWM output trip points. 172 + The PWM output of trip point 4 is always the maximum value (fan running 173 + at full speed) while the PWM output of the other 3 trip points can be 174 + freely chosen. The temperature of all 4 trip points can be freely chosen. 175 + Additionally, trip point 1 has an hysteresis temperature attached, to 176 + prevent fast switching between fan on and off. 177 + 178 + The chip automatically computes the PWM output value based on the input 179 + temperature, based on this simple rule: if the temperature value is 180 + between trip point N and trip point N+1 then the PWM output value is 181 + the one of trip point N. The automatic control mode is less flexible 182 + than the manual control mode, but it reacts faster, is more robust and 183 + doesn't use CPU cycles. 184 + 185 + Trip points must be set properly before switching to automatic fan speed 186 + control mode. The driver will perform basic integrity checks before 187 + actually switching to automatic control mode.
+22
Documentation/hwmon/lm90
··· 84 Addresses scanned: I2C 0x4c 85 Datasheet: Publicly available at the Maxim website 86 http://www.maxim-ic.com/quick_view2.cfm/qv_pk/3500 87 88 89 Author: Jean Delvare <khali@linux-fr.org> ··· 151 * Selectable address 152 * Remote sensor type selection 153 154 All temperature values are given in degrees Celsius. Resolution 155 is 1.0 degree for the local temperature, 0.125 degree for the remote 156 temperature, except for the MAX6657, MAX6658 and MAX6659 which have a ··· 172 The lm90 driver will not update its values more frequently than every 173 other second; reading them more often will do no harm, but will return 174 'old' values. 175 176 PEC Support 177 -----------
··· 84 Addresses scanned: I2C 0x4c 85 Datasheet: Publicly available at the Maxim website 86 http://www.maxim-ic.com/quick_view2.cfm/qv_pk/3500 87 + * Winbond/Nuvoton W83L771AWG/ASG 88 + Prefix: 'w83l771' 89 + Addresses scanned: I2C 0x4c 90 + Datasheet: Not publicly available, can be requested from Nuvoton 91 92 93 Author: Jean Delvare <khali@linux-fr.org> ··· 147 * Selectable address 148 * Remote sensor type selection 149 150 + W83L771AWG/ASG 151 + * The AWG and ASG variants only differ in package format. 152 + * Filter and alert configuration register at 0xBF 153 + * Diode ideality factor configuration (remote sensor) at 0xE3 154 + * Moving average (depending on conversion rate) 155 + 156 All temperature values are given in degrees Celsius. Resolution 157 is 1.0 degree for the local temperature, 0.125 degree for the remote 158 temperature, except for the MAX6657, MAX6658 and MAX6659 which have a ··· 162 The lm90 driver will not update its values more frequently than every 163 other second; reading them more often will do no harm, but will return 164 'old' values. 165 + 166 + SMBus Alert Support 167 + ------------------- 168 + 169 + This driver has basic support for SMBus alert. When an alert is received, 170 + the status register is read and the faulty temperature channel is logged. 171 + 172 + The Analog Devices chips (ADM1032 and ADT7461) do not implement the SMBus 173 + alert protocol properly so additional care is needed: the ALERT output is 174 + disabled when an alert is received, and is re-enabled only when the alarm 175 + is gone. Otherwise the chip would block alerts from other chips in the bus 176 + as long as the alarm is active. 177 178 PEC Support 179 -----------
+14
MAINTAINERS
··· 968 S: Maintained 969 F: arch/arm/vfp/ 970 971 ASUS ACPI EXTRAS DRIVER 972 M: Corentin Chary <corentincj@iksaif.net> 973 M: Karol Kozimor <sziwan@users.sourceforge.net> ··· 3054 W: http://www.melware.de 3055 S: Maintained 3056 F: drivers/isdn/hardware/eicon/ 3057 3058 IVTV VIDEO4LINUX DRIVER 3059 M: Andy Walls <awalls@radix.net>
··· 968 S: Maintained 969 F: arch/arm/vfp/ 970 971 + ASC7621 HARDWARE MONITOR DRIVER 972 + M: George Joseph <george.joseph@fairview5.com> 973 + L: lm-sensors@lm-sensors.org 974 + S: Maintained 975 + F: Documentation/hwmon/asc7621 976 + F: drivers/hwmon/asc7621.c 977 + 978 ASUS ACPI EXTRAS DRIVER 979 M: Corentin Chary <corentincj@iksaif.net> 980 M: Karol Kozimor <sziwan@users.sourceforge.net> ··· 3047 W: http://www.melware.de 3048 S: Maintained 3049 F: drivers/isdn/hardware/eicon/ 3050 + 3051 + IT87 HARDWARE MONITORING DRIVER 3052 + M: Jean Delvare <khali@linux-fr.org> 3053 + L: lm-sensors@lm-sensors.org 3054 + S: Maintained 3055 + F: Documentation/hwmon/it87 3056 + F: drivers/hwmon/it87.c 3057 3058 IVTV VIDEO4LINUX DRIVER 3059 M: Andy Walls <awalls@radix.net>
+28 -17
drivers/hwmon/Kconfig
··· 170 This driver can also be built as a module. If so, the module 171 will be called adm9240. 172 173 config SENSORS_ADT7462 174 tristate "Analog Devices ADT7462" 175 depends on I2C && EXPERIMENTAL ··· 200 This driver can also be built as a module. If so, the module 201 will be called adt7470. 202 203 - config SENSORS_ADT7473 204 - tristate "Analog Devices ADT7473 (DEPRECATED)" 205 - depends on I2C && EXPERIMENTAL 206 - select SENSORS_ADT7475 207 - help 208 - If you say yes here you get support for the Analog Devices 209 - ADT7473 temperature monitoring chips. 210 - 211 - This driver is deprecated, you should use the adt7475 driver 212 - instead. 213 - 214 - This driver can also be built as a module. If so, the module 215 - will be called adt7473. 216 - 217 config SENSORS_ADT7475 218 tristate "Analog Devices ADT7473, ADT7475, ADT7476 and ADT7490" 219 depends on I2C && EXPERIMENTAL ··· 211 212 This driver can also be build as a module. If so, the module 213 will be called adt7475. 214 215 config SENSORS_K8TEMP 216 tristate "AMD Athlon64/FX or Opteron temperature sensor" ··· 572 depends on I2C 573 help 574 If you say yes here you get support for National Semiconductor LM90, 575 - LM86, LM89 and LM99, Analog Devices ADM1032 and ADT7461, and Maxim 576 MAX6646, MAX6647, MAX6648, MAX6649, MAX6657, MAX6658, MAX6659, 577 - MAX6680, MAX6681 and MAX6692 sensor chips. 578 579 This driver can also be built as a module. If so, the module 580 will be called lm90. ··· 919 select HWMON_VID 920 help 921 If you say yes here you get support for the Winbond W83793 922 - hardware monitoring chip. 923 924 This driver can also be built as a module. If so, the module 925 will be called w83793.
··· 170 This driver can also be built as a module. If so, the module 171 will be called adm9240. 172 173 + config SENSORS_ADT7411 174 + tristate "Analog Devices ADT7411" 175 + depends on I2C && EXPERIMENTAL 176 + help 177 + If you say yes here you get support for the Analog Devices 178 + ADT7411 voltage and temperature monitoring chip. 179 + 180 + This driver can also be built as a module. If so, the module 181 + will be called adt7411. 182 + 183 config SENSORS_ADT7462 184 tristate "Analog Devices ADT7462" 185 depends on I2C && EXPERIMENTAL ··· 190 This driver can also be built as a module. If so, the module 191 will be called adt7470. 192 193 config SENSORS_ADT7475 194 tristate "Analog Devices ADT7473, ADT7475, ADT7476 and ADT7490" 195 depends on I2C && EXPERIMENTAL ··· 215 216 This driver can also be build as a module. If so, the module 217 will be called adt7475. 218 + 219 + config SENSORS_ASC7621 220 + tristate "Andigilog aSC7621" 221 + depends on HWMON && I2C 222 + help 223 + If you say yes here you get support for the aSC7621 224 + family of SMBus sensors chip found on most Intel X48, X38, 975, 225 + 965 and 945 desktop boards. Currently supported chips: 226 + aSC7621 227 + aSC7621a 228 + 229 + This driver can also be built as a module. If so, the module 230 + will be called asc7621. 231 232 config SENSORS_K8TEMP 233 tristate "AMD Athlon64/FX or Opteron temperature sensor" ··· 563 depends on I2C 564 help 565 If you say yes here you get support for National Semiconductor LM90, 566 + LM86, LM89 and LM99, Analog Devices ADM1032 and ADT7461, Maxim 567 MAX6646, MAX6647, MAX6648, MAX6649, MAX6657, MAX6658, MAX6659, 568 + MAX6680, MAX6681 and MAX6692, and Winbond/Nuvoton W83L771AWG/ASG 569 + sensor chips. 570 571 This driver can also be built as a module. If so, the module 572 will be called lm90. ··· 909 select HWMON_VID 910 help 911 If you say yes here you get support for the Winbond W83793 912 + hardware monitoring chip, including support for the integrated 913 + watchdog. 914 915 This driver can also be built as a module. If so, the module 916 will be called w83793.
+2 -1
drivers/hwmon/Makefile
··· 29 obj-$(CONFIG_SENSORS_ADM1031) += adm1031.o 30 obj-$(CONFIG_SENSORS_ADM9240) += adm9240.o 31 obj-$(CONFIG_SENSORS_ADS7828) += ads7828.o 32 obj-$(CONFIG_SENSORS_ADT7462) += adt7462.o 33 obj-$(CONFIG_SENSORS_ADT7470) += adt7470.o 34 - obj-$(CONFIG_SENSORS_ADT7473) += adt7473.o 35 obj-$(CONFIG_SENSORS_ADT7475) += adt7475.o 36 obj-$(CONFIG_SENSORS_APPLESMC) += applesmc.o 37 obj-$(CONFIG_SENSORS_AMS) += ams/ 38 obj-$(CONFIG_SENSORS_ATXP1) += atxp1.o 39 obj-$(CONFIG_SENSORS_CORETEMP) += coretemp.o 40 obj-$(CONFIG_SENSORS_DME1737) += dme1737.o
··· 29 obj-$(CONFIG_SENSORS_ADM1031) += adm1031.o 30 obj-$(CONFIG_SENSORS_ADM9240) += adm9240.o 31 obj-$(CONFIG_SENSORS_ADS7828) += ads7828.o 32 + obj-$(CONFIG_SENSORS_ADT7411) += adt7411.o 33 obj-$(CONFIG_SENSORS_ADT7462) += adt7462.o 34 obj-$(CONFIG_SENSORS_ADT7470) += adt7470.o 35 obj-$(CONFIG_SENSORS_ADT7475) += adt7475.o 36 obj-$(CONFIG_SENSORS_APPLESMC) += applesmc.o 37 obj-$(CONFIG_SENSORS_AMS) += ams/ 38 + obj-$(CONFIG_SENSORS_ASC7621) += asc7621.o 39 obj-$(CONFIG_SENSORS_ATXP1) += atxp1.o 40 obj-$(CONFIG_SENSORS_CORETEMP) += coretemp.o 41 obj-$(CONFIG_SENSORS_DME1737) += dme1737.o
+366
drivers/hwmon/adt7411.c
···
··· 1 + /* 2 + * Driver for the ADT7411 (I2C/SPI 8 channel 10 bit ADC & temperature-sensor) 3 + * 4 + * Copyright (C) 2008, 2010 Pengutronix 5 + * 6 + * This program is free software; you can redistribute it and/or modify 7 + * it under the terms of the GNU General Public License version 2 as 8 + * published by the Free Software Foundation. 9 + * 10 + * TODO: SPI, support for external temperature sensor 11 + * use power-down mode for suspend?, interrupt handling? 12 + */ 13 + 14 + #include <linux/kernel.h> 15 + #include <linux/module.h> 16 + #include <linux/init.h> 17 + #include <linux/err.h> 18 + #include <linux/delay.h> 19 + #include <linux/mutex.h> 20 + #include <linux/jiffies.h> 21 + #include <linux/i2c.h> 22 + #include <linux/hwmon.h> 23 + #include <linux/hwmon-sysfs.h> 24 + 25 + #define ADT7411_REG_INT_TEMP_VDD_LSB 0x03 26 + #define ADT7411_REG_EXT_TEMP_AIN14_LSB 0x04 27 + #define ADT7411_REG_VDD_MSB 0x06 28 + #define ADT7411_REG_INT_TEMP_MSB 0x07 29 + #define ADT7411_REG_EXT_TEMP_AIN1_MSB 0x08 30 + 31 + #define ADT7411_REG_CFG1 0x18 32 + #define ADT7411_CFG1_START_MONITOR (1 << 0) 33 + 34 + #define ADT7411_REG_CFG2 0x19 35 + #define ADT7411_CFG2_DISABLE_AVG (1 << 5) 36 + 37 + #define ADT7411_REG_CFG3 0x1a 38 + #define ADT7411_CFG3_ADC_CLK_225 (1 << 0) 39 + #define ADT7411_CFG3_REF_VDD (1 << 4) 40 + 41 + #define ADT7411_REG_DEVICE_ID 0x4d 42 + #define ADT7411_REG_MANUFACTURER_ID 0x4e 43 + 44 + #define ADT7411_DEVICE_ID 0x2 45 + #define ADT7411_MANUFACTURER_ID 0x41 46 + 47 + static const unsigned short normal_i2c[] = { 0x48, 0x4a, 0x4b, I2C_CLIENT_END }; 48 + 49 + struct adt7411_data { 50 + struct mutex device_lock; /* for "atomic" device accesses */ 51 + struct mutex update_lock; 52 + unsigned long next_update; 53 + int vref_cached; 54 + struct device *hwmon_dev; 55 + }; 56 + 57 + /* 58 + * When reading a register containing (up to 4) lsb, all associated 59 + * msb-registers get locked by the hardware. After _one_ of those msb is read, 60 + * _all_ are unlocked. In order to use this locking correctly, reading lsb/msb 61 + * is protected here with a mutex, too. 62 + */ 63 + static int adt7411_read_10_bit(struct i2c_client *client, u8 lsb_reg, 64 + u8 msb_reg, u8 lsb_shift) 65 + { 66 + struct adt7411_data *data = i2c_get_clientdata(client); 67 + int val, tmp; 68 + 69 + mutex_lock(&data->device_lock); 70 + 71 + val = i2c_smbus_read_byte_data(client, lsb_reg); 72 + if (val < 0) 73 + goto exit_unlock; 74 + 75 + tmp = (val >> lsb_shift) & 3; 76 + val = i2c_smbus_read_byte_data(client, msb_reg); 77 + 78 + if (val >= 0) 79 + val = (val << 2) | tmp; 80 + 81 + exit_unlock: 82 + mutex_unlock(&data->device_lock); 83 + 84 + return val; 85 + } 86 + 87 + static int adt7411_modify_bit(struct i2c_client *client, u8 reg, u8 bit, 88 + bool flag) 89 + { 90 + struct adt7411_data *data = i2c_get_clientdata(client); 91 + int ret, val; 92 + 93 + mutex_lock(&data->device_lock); 94 + 95 + ret = i2c_smbus_read_byte_data(client, reg); 96 + if (ret < 0) 97 + goto exit_unlock; 98 + 99 + if (flag) 100 + val = ret | bit; 101 + else 102 + val = ret & ~bit; 103 + 104 + ret = i2c_smbus_write_byte_data(client, reg, val); 105 + 106 + exit_unlock: 107 + mutex_unlock(&data->device_lock); 108 + return ret; 109 + } 110 + 111 + static ssize_t adt7411_show_vdd(struct device *dev, 112 + struct device_attribute *attr, char *buf) 113 + { 114 + struct i2c_client *client = to_i2c_client(dev); 115 + int ret = adt7411_read_10_bit(client, ADT7411_REG_INT_TEMP_VDD_LSB, 116 + ADT7411_REG_VDD_MSB, 2); 117 + 118 + return ret < 0 ? ret : sprintf(buf, "%u\n", ret * 7000 / 1024); 119 + } 120 + 121 + static ssize_t adt7411_show_temp(struct device *dev, 122 + struct device_attribute *attr, char *buf) 123 + { 124 + struct i2c_client *client = to_i2c_client(dev); 125 + int val = adt7411_read_10_bit(client, ADT7411_REG_INT_TEMP_VDD_LSB, 126 + ADT7411_REG_INT_TEMP_MSB, 0); 127 + 128 + if (val < 0) 129 + return val; 130 + 131 + val = val & 0x200 ? val - 0x400 : val; /* 10 bit signed */ 132 + 133 + return sprintf(buf, "%d\n", val * 250); 134 + } 135 + 136 + static ssize_t adt7411_show_input(struct device *dev, 137 + struct device_attribute *attr, char *buf) 138 + { 139 + int nr = to_sensor_dev_attr(attr)->index; 140 + struct i2c_client *client = to_i2c_client(dev); 141 + struct adt7411_data *data = i2c_get_clientdata(client); 142 + int val; 143 + u8 lsb_reg, lsb_shift; 144 + 145 + mutex_lock(&data->update_lock); 146 + if (time_after_eq(jiffies, data->next_update)) { 147 + val = i2c_smbus_read_byte_data(client, ADT7411_REG_CFG3); 148 + if (val < 0) 149 + goto exit_unlock; 150 + 151 + if (val & ADT7411_CFG3_REF_VDD) { 152 + val = adt7411_read_10_bit(client, 153 + ADT7411_REG_INT_TEMP_VDD_LSB, 154 + ADT7411_REG_VDD_MSB, 2); 155 + if (val < 0) 156 + goto exit_unlock; 157 + 158 + data->vref_cached = val * 7000 / 1024; 159 + } else { 160 + data->vref_cached = 2250; 161 + } 162 + 163 + data->next_update = jiffies + HZ; 164 + } 165 + 166 + lsb_reg = ADT7411_REG_EXT_TEMP_AIN14_LSB + (nr >> 2); 167 + lsb_shift = 2 * (nr & 0x03); 168 + val = adt7411_read_10_bit(client, lsb_reg, 169 + ADT7411_REG_EXT_TEMP_AIN1_MSB + nr, lsb_shift); 170 + if (val < 0) 171 + goto exit_unlock; 172 + 173 + val = sprintf(buf, "%u\n", val * data->vref_cached / 1024); 174 + exit_unlock: 175 + mutex_unlock(&data->update_lock); 176 + return val; 177 + } 178 + 179 + static ssize_t adt7411_show_bit(struct device *dev, 180 + struct device_attribute *attr, char *buf) 181 + { 182 + struct sensor_device_attribute_2 *attr2 = to_sensor_dev_attr_2(attr); 183 + struct i2c_client *client = to_i2c_client(dev); 184 + int ret = i2c_smbus_read_byte_data(client, attr2->index); 185 + 186 + return ret < 0 ? ret : sprintf(buf, "%u\n", !!(ret & attr2->nr)); 187 + } 188 + 189 + static ssize_t adt7411_set_bit(struct device *dev, 190 + struct device_attribute *attr, const char *buf, 191 + size_t count) 192 + { 193 + struct sensor_device_attribute_2 *s_attr2 = to_sensor_dev_attr_2(attr); 194 + struct i2c_client *client = to_i2c_client(dev); 195 + struct adt7411_data *data = i2c_get_clientdata(client); 196 + int ret; 197 + unsigned long flag; 198 + 199 + ret = strict_strtoul(buf, 0, &flag); 200 + if (ret || flag > 1) 201 + return -EINVAL; 202 + 203 + ret = adt7411_modify_bit(client, s_attr2->index, s_attr2->nr, flag); 204 + 205 + /* force update */ 206 + mutex_lock(&data->update_lock); 207 + data->next_update = jiffies; 208 + mutex_unlock(&data->update_lock); 209 + 210 + return ret < 0 ? ret : count; 211 + } 212 + 213 + #define ADT7411_BIT_ATTR(__name, __reg, __bit) \ 214 + SENSOR_DEVICE_ATTR_2(__name, S_IRUGO | S_IWUSR, adt7411_show_bit, \ 215 + adt7411_set_bit, __bit, __reg) 216 + 217 + static DEVICE_ATTR(temp1_input, S_IRUGO, adt7411_show_temp, NULL); 218 + static DEVICE_ATTR(in0_input, S_IRUGO, adt7411_show_vdd, NULL); 219 + static SENSOR_DEVICE_ATTR(in1_input, S_IRUGO, adt7411_show_input, NULL, 0); 220 + static SENSOR_DEVICE_ATTR(in2_input, S_IRUGO, adt7411_show_input, NULL, 1); 221 + static SENSOR_DEVICE_ATTR(in3_input, S_IRUGO, adt7411_show_input, NULL, 2); 222 + static SENSOR_DEVICE_ATTR(in4_input, S_IRUGO, adt7411_show_input, NULL, 3); 223 + static SENSOR_DEVICE_ATTR(in5_input, S_IRUGO, adt7411_show_input, NULL, 4); 224 + static SENSOR_DEVICE_ATTR(in6_input, S_IRUGO, adt7411_show_input, NULL, 5); 225 + static SENSOR_DEVICE_ATTR(in7_input, S_IRUGO, adt7411_show_input, NULL, 6); 226 + static SENSOR_DEVICE_ATTR(in8_input, S_IRUGO, adt7411_show_input, NULL, 7); 227 + static ADT7411_BIT_ATTR(no_average, ADT7411_REG_CFG2, ADT7411_CFG2_DISABLE_AVG); 228 + static ADT7411_BIT_ATTR(fast_sampling, ADT7411_REG_CFG3, ADT7411_CFG3_ADC_CLK_225); 229 + static ADT7411_BIT_ATTR(adc_ref_vdd, ADT7411_REG_CFG3, ADT7411_CFG3_REF_VDD); 230 + 231 + static struct attribute *adt7411_attrs[] = { 232 + &dev_attr_temp1_input.attr, 233 + &dev_attr_in0_input.attr, 234 + &sensor_dev_attr_in1_input.dev_attr.attr, 235 + &sensor_dev_attr_in2_input.dev_attr.attr, 236 + &sensor_dev_attr_in3_input.dev_attr.attr, 237 + &sensor_dev_attr_in4_input.dev_attr.attr, 238 + &sensor_dev_attr_in5_input.dev_attr.attr, 239 + &sensor_dev_attr_in6_input.dev_attr.attr, 240 + &sensor_dev_attr_in7_input.dev_attr.attr, 241 + &sensor_dev_attr_in8_input.dev_attr.attr, 242 + &sensor_dev_attr_no_average.dev_attr.attr, 243 + &sensor_dev_attr_fast_sampling.dev_attr.attr, 244 + &sensor_dev_attr_adc_ref_vdd.dev_attr.attr, 245 + NULL 246 + }; 247 + 248 + static const struct attribute_group adt7411_attr_grp = { 249 + .attrs = adt7411_attrs, 250 + }; 251 + 252 + static int adt7411_detect(struct i2c_client *client, 253 + struct i2c_board_info *info) 254 + { 255 + int val; 256 + 257 + if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA)) 258 + return -ENODEV; 259 + 260 + val = i2c_smbus_read_byte_data(client, ADT7411_REG_MANUFACTURER_ID); 261 + if (val < 0 || val != ADT7411_MANUFACTURER_ID) { 262 + dev_dbg(&client->dev, "Wrong manufacturer ID. Got %d, " 263 + "expected %d\n", val, ADT7411_MANUFACTURER_ID); 264 + return -ENODEV; 265 + } 266 + 267 + val = i2c_smbus_read_byte_data(client, ADT7411_REG_DEVICE_ID); 268 + if (val < 0 || val != ADT7411_DEVICE_ID) { 269 + dev_dbg(&client->dev, "Wrong device ID. Got %d, " 270 + "expected %d\n", val, ADT7411_DEVICE_ID); 271 + return -ENODEV; 272 + } 273 + 274 + strlcpy(info->type, "adt7411", I2C_NAME_SIZE); 275 + 276 + return 0; 277 + } 278 + 279 + static int __devinit adt7411_probe(struct i2c_client *client, 280 + const struct i2c_device_id *id) 281 + { 282 + struct adt7411_data *data; 283 + int ret; 284 + 285 + data = kzalloc(sizeof(*data), GFP_KERNEL); 286 + if (!data) 287 + return -ENOMEM; 288 + 289 + i2c_set_clientdata(client, data); 290 + mutex_init(&data->device_lock); 291 + mutex_init(&data->update_lock); 292 + 293 + ret = adt7411_modify_bit(client, ADT7411_REG_CFG1, 294 + ADT7411_CFG1_START_MONITOR, 1); 295 + if (ret < 0) 296 + goto exit_free; 297 + 298 + /* force update on first occasion */ 299 + data->next_update = jiffies; 300 + 301 + ret = sysfs_create_group(&client->dev.kobj, &adt7411_attr_grp); 302 + if (ret) 303 + goto exit_free; 304 + 305 + data->hwmon_dev = hwmon_device_register(&client->dev); 306 + if (IS_ERR(data->hwmon_dev)) { 307 + ret = PTR_ERR(data->hwmon_dev); 308 + goto exit_remove; 309 + } 310 + 311 + dev_info(&client->dev, "successfully registered\n"); 312 + 313 + return 0; 314 + 315 + exit_remove: 316 + sysfs_remove_group(&client->dev.kobj, &adt7411_attr_grp); 317 + exit_free: 318 + i2c_set_clientdata(client, NULL); 319 + kfree(data); 320 + return ret; 321 + } 322 + 323 + static int __devexit adt7411_remove(struct i2c_client *client) 324 + { 325 + struct adt7411_data *data = i2c_get_clientdata(client); 326 + 327 + hwmon_device_unregister(data->hwmon_dev); 328 + sysfs_remove_group(&client->dev.kobj, &adt7411_attr_grp); 329 + i2c_set_clientdata(client, NULL); 330 + kfree(data); 331 + return 0; 332 + } 333 + 334 + static const struct i2c_device_id adt7411_id[] = { 335 + { "adt7411", 0 }, 336 + { } 337 + }; 338 + 339 + static struct i2c_driver adt7411_driver = { 340 + .driver = { 341 + .name = "adt7411", 342 + }, 343 + .probe = adt7411_probe, 344 + .remove = __devexit_p(adt7411_remove), 345 + .id_table = adt7411_id, 346 + .detect = adt7411_detect, 347 + .address_list = normal_i2c, 348 + .class = I2C_CLASS_HWMON, 349 + }; 350 + 351 + static int __init sensors_adt7411_init(void) 352 + { 353 + return i2c_add_driver(&adt7411_driver); 354 + } 355 + module_init(sensors_adt7411_init) 356 + 357 + static void __exit sensors_adt7411_exit(void) 358 + { 359 + i2c_del_driver(&adt7411_driver); 360 + } 361 + module_exit(sensors_adt7411_exit) 362 + 363 + MODULE_AUTHOR("Sascha Hauer <s.hauer@pengutronix.de> and " 364 + "Wolfram Sang <w.sang@pengutronix.de>"); 365 + MODULE_DESCRIPTION("ADT7411 driver"); 366 + MODULE_LICENSE("GPL v2");
-1180
drivers/hwmon/adt7473.c
··· 1 - /* 2 - * A hwmon driver for the Analog Devices ADT7473 3 - * Copyright (C) 2007 IBM 4 - * 5 - * Author: Darrick J. Wong <djwong@us.ibm.com> 6 - * 7 - * This program is free software; you can redistribute it and/or modify 8 - * it under the terms of the GNU General Public License as published by 9 - * the Free Software Foundation; either version 2 of the License, or 10 - * (at your option) any later version. 11 - * 12 - * This program is distributed in the hope that it will be useful, 13 - * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 - * GNU General Public License for more details. 16 - * 17 - * You should have received a copy of the GNU General Public License 18 - * along with this program; if not, write to the Free Software 19 - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 20 - */ 21 - 22 - #include <linux/module.h> 23 - #include <linux/jiffies.h> 24 - #include <linux/i2c.h> 25 - #include <linux/hwmon.h> 26 - #include <linux/hwmon-sysfs.h> 27 - #include <linux/err.h> 28 - #include <linux/mutex.h> 29 - #include <linux/delay.h> 30 - #include <linux/log2.h> 31 - 32 - /* Addresses to scan */ 33 - static const unsigned short normal_i2c[] = { 0x2C, 0x2D, 0x2E, I2C_CLIENT_END }; 34 - 35 - /* ADT7473 registers */ 36 - #define ADT7473_REG_BASE_ADDR 0x20 37 - 38 - #define ADT7473_REG_VOLT_BASE_ADDR 0x21 39 - #define ADT7473_REG_VOLT_MIN_BASE_ADDR 0x46 40 - 41 - #define ADT7473_REG_TEMP_BASE_ADDR 0x25 42 - #define ADT7473_REG_TEMP_LIMITS_BASE_ADDR 0x4E 43 - #define ADT7473_REG_TEMP_TMIN_BASE_ADDR 0x67 44 - #define ADT7473_REG_TEMP_TMAX_BASE_ADDR 0x6A 45 - 46 - #define ADT7473_REG_FAN_BASE_ADDR 0x28 47 - #define ADT7473_REG_FAN_MIN_BASE_ADDR 0x54 48 - 49 - #define ADT7473_REG_PWM_BASE_ADDR 0x30 50 - #define ADT7473_REG_PWM_MIN_BASE_ADDR 0x64 51 - #define ADT7473_REG_PWM_MAX_BASE_ADDR 0x38 52 - #define ADT7473_REG_PWM_BHVR_BASE_ADDR 0x5C 53 - #define ADT7473_PWM_BHVR_MASK 0xE0 54 - #define ADT7473_PWM_BHVR_SHIFT 5 55 - 56 - #define ADT7473_REG_CFG1 0x40 57 - #define ADT7473_CFG1_START 0x01 58 - #define ADT7473_CFG1_READY 0x04 59 - #define ADT7473_REG_CFG2 0x73 60 - #define ADT7473_REG_CFG3 0x78 61 - #define ADT7473_REG_CFG4 0x7D 62 - #define ADT7473_CFG4_MAX_DUTY_AT_OVT 0x08 63 - #define ADT7473_REG_CFG5 0x7C 64 - #define ADT7473_CFG5_TEMP_TWOS 0x01 65 - #define ADT7473_CFG5_TEMP_OFFSET 0x02 66 - 67 - #define ADT7473_REG_DEVICE 0x3D 68 - #define ADT7473_VENDOR 0x41 69 - #define ADT7473_REG_VENDOR 0x3E 70 - #define ADT7473_DEVICE 0x73 71 - #define ADT7473_REG_REVISION 0x3F 72 - #define ADT7473_REV_68 0x68 73 - #define ADT7473_REV_69 0x69 74 - 75 - #define ADT7473_REG_ALARM1 0x41 76 - #define ADT7473_VCCP_ALARM 0x02 77 - #define ADT7473_VCC_ALARM 0x04 78 - #define ADT7473_R1T_ALARM 0x10 79 - #define ADT7473_LT_ALARM 0x20 80 - #define ADT7473_R2T_ALARM 0x40 81 - #define ADT7473_OOL 0x80 82 - #define ADT7473_REG_ALARM2 0x42 83 - #define ADT7473_OVT_ALARM 0x02 84 - #define ADT7473_FAN1_ALARM 0x04 85 - #define ADT7473_FAN2_ALARM 0x08 86 - #define ADT7473_FAN3_ALARM 0x10 87 - #define ADT7473_FAN4_ALARM 0x20 88 - #define ADT7473_R1T_SHORT 0x40 89 - #define ADT7473_R2T_SHORT 0x80 90 - 91 - #define ALARM2(x) ((x) << 8) 92 - 93 - #define ADT7473_VOLT_COUNT 2 94 - #define ADT7473_REG_VOLT(x) (ADT7473_REG_VOLT_BASE_ADDR + (x)) 95 - #define ADT7473_REG_VOLT_MIN(x) (ADT7473_REG_VOLT_MIN_BASE_ADDR + ((x) * 2)) 96 - #define ADT7473_REG_VOLT_MAX(x) (ADT7473_REG_VOLT_MIN_BASE_ADDR + \ 97 - ((x) * 2) + 1) 98 - 99 - #define ADT7473_TEMP_COUNT 3 100 - #define ADT7473_REG_TEMP(x) (ADT7473_REG_TEMP_BASE_ADDR + (x)) 101 - #define ADT7473_REG_TEMP_MIN(x) (ADT7473_REG_TEMP_LIMITS_BASE_ADDR + ((x) * 2)) 102 - #define ADT7473_REG_TEMP_MAX(x) (ADT7473_REG_TEMP_LIMITS_BASE_ADDR + \ 103 - ((x) * 2) + 1) 104 - #define ADT7473_REG_TEMP_TMIN(x) (ADT7473_REG_TEMP_TMIN_BASE_ADDR + (x)) 105 - #define ADT7473_REG_TEMP_TMAX(x) (ADT7473_REG_TEMP_TMAX_BASE_ADDR + (x)) 106 - 107 - #define ADT7473_FAN_COUNT 4 108 - #define ADT7473_REG_FAN(x) (ADT7473_REG_FAN_BASE_ADDR + ((x) * 2)) 109 - #define ADT7473_REG_FAN_MIN(x) (ADT7473_REG_FAN_MIN_BASE_ADDR + ((x) * 2)) 110 - 111 - #define ADT7473_PWM_COUNT 3 112 - #define ADT7473_REG_PWM(x) (ADT7473_REG_PWM_BASE_ADDR + (x)) 113 - #define ADT7473_REG_PWM_MAX(x) (ADT7473_REG_PWM_MAX_BASE_ADDR + (x)) 114 - #define ADT7473_REG_PWM_MIN(x) (ADT7473_REG_PWM_MIN_BASE_ADDR + (x)) 115 - #define ADT7473_REG_PWM_BHVR(x) (ADT7473_REG_PWM_BHVR_BASE_ADDR + (x)) 116 - 117 - /* How often do we reread sensors values? (In jiffies) */ 118 - #define SENSOR_REFRESH_INTERVAL (2 * HZ) 119 - 120 - /* How often do we reread sensor limit values? (In jiffies) */ 121 - #define LIMIT_REFRESH_INTERVAL (60 * HZ) 122 - 123 - /* datasheet says to divide this number by the fan reading to get fan rpm */ 124 - #define FAN_PERIOD_TO_RPM(x) ((90000 * 60) / (x)) 125 - #define FAN_RPM_TO_PERIOD FAN_PERIOD_TO_RPM 126 - #define FAN_PERIOD_INVALID 65535 127 - #define FAN_DATA_VALID(x) ((x) && (x) != FAN_PERIOD_INVALID) 128 - 129 - struct adt7473_data { 130 - struct device *hwmon_dev; 131 - struct attribute_group attrs; 132 - struct mutex lock; 133 - char sensors_valid; 134 - char limits_valid; 135 - unsigned long sensors_last_updated; /* In jiffies */ 136 - unsigned long limits_last_updated; /* In jiffies */ 137 - 138 - u8 volt[ADT7473_VOLT_COUNT]; 139 - s8 volt_min[ADT7473_VOLT_COUNT]; 140 - s8 volt_max[ADT7473_VOLT_COUNT]; 141 - 142 - s8 temp[ADT7473_TEMP_COUNT]; 143 - s8 temp_min[ADT7473_TEMP_COUNT]; 144 - s8 temp_max[ADT7473_TEMP_COUNT]; 145 - s8 temp_tmin[ADT7473_TEMP_COUNT]; 146 - /* This is called the !THERM limit in the datasheet */ 147 - s8 temp_tmax[ADT7473_TEMP_COUNT]; 148 - 149 - u16 fan[ADT7473_FAN_COUNT]; 150 - u16 fan_min[ADT7473_FAN_COUNT]; 151 - 152 - u8 pwm[ADT7473_PWM_COUNT]; 153 - u8 pwm_max[ADT7473_PWM_COUNT]; 154 - u8 pwm_min[ADT7473_PWM_COUNT]; 155 - u8 pwm_behavior[ADT7473_PWM_COUNT]; 156 - 157 - u8 temp_twos_complement; 158 - u8 temp_offset; 159 - 160 - u16 alarm; 161 - u8 max_duty_at_overheat; 162 - }; 163 - 164 - static int adt7473_probe(struct i2c_client *client, 165 - const struct i2c_device_id *id); 166 - static int adt7473_detect(struct i2c_client *client, 167 - struct i2c_board_info *info); 168 - static int adt7473_remove(struct i2c_client *client); 169 - 170 - static const struct i2c_device_id adt7473_id[] = { 171 - { "adt7473", 0 }, 172 - { } 173 - }; 174 - 175 - static struct i2c_driver adt7473_driver = { 176 - .class = I2C_CLASS_HWMON, 177 - .driver = { 178 - .name = "adt7473", 179 - }, 180 - .probe = adt7473_probe, 181 - .remove = adt7473_remove, 182 - .id_table = adt7473_id, 183 - .detect = adt7473_detect, 184 - .address_list = normal_i2c, 185 - }; 186 - 187 - /* 188 - * 16-bit registers on the ADT7473 are low-byte first. The data sheet says 189 - * that the low byte must be read before the high byte. 190 - */ 191 - static inline int adt7473_read_word_data(struct i2c_client *client, u8 reg) 192 - { 193 - u16 foo; 194 - foo = i2c_smbus_read_byte_data(client, reg); 195 - foo |= ((u16)i2c_smbus_read_byte_data(client, reg + 1) << 8); 196 - return foo; 197 - } 198 - 199 - static inline int adt7473_write_word_data(struct i2c_client *client, u8 reg, 200 - u16 value) 201 - { 202 - return i2c_smbus_write_byte_data(client, reg, value & 0xFF) 203 - && i2c_smbus_write_byte_data(client, reg + 1, value >> 8); 204 - } 205 - 206 - static void adt7473_init_client(struct i2c_client *client) 207 - { 208 - int reg = i2c_smbus_read_byte_data(client, ADT7473_REG_CFG1); 209 - 210 - if (!(reg & ADT7473_CFG1_READY)) { 211 - dev_err(&client->dev, "Chip not ready.\n"); 212 - } else { 213 - /* start monitoring */ 214 - i2c_smbus_write_byte_data(client, ADT7473_REG_CFG1, 215 - reg | ADT7473_CFG1_START); 216 - } 217 - } 218 - 219 - static struct adt7473_data *adt7473_update_device(struct device *dev) 220 - { 221 - struct i2c_client *client = to_i2c_client(dev); 222 - struct adt7473_data *data = i2c_get_clientdata(client); 223 - unsigned long local_jiffies = jiffies; 224 - u8 cfg; 225 - int i; 226 - 227 - mutex_lock(&data->lock); 228 - if (time_before(local_jiffies, data->sensors_last_updated + 229 - SENSOR_REFRESH_INTERVAL) 230 - && data->sensors_valid) 231 - goto no_sensor_update; 232 - 233 - for (i = 0; i < ADT7473_VOLT_COUNT; i++) 234 - data->volt[i] = i2c_smbus_read_byte_data(client, 235 - ADT7473_REG_VOLT(i)); 236 - 237 - /* Determine temperature encoding */ 238 - cfg = i2c_smbus_read_byte_data(client, ADT7473_REG_CFG5); 239 - data->temp_twos_complement = (cfg & ADT7473_CFG5_TEMP_TWOS); 240 - 241 - /* 242 - * What does this do? it implies a variable temperature sensor 243 - * offset, but the datasheet doesn't say anything about this bit 244 - * and other parts of the datasheet imply that "offset64" mode 245 - * means that you shift temp values by -64 if the above bit was set. 246 - */ 247 - data->temp_offset = (cfg & ADT7473_CFG5_TEMP_OFFSET); 248 - 249 - for (i = 0; i < ADT7473_TEMP_COUNT; i++) 250 - data->temp[i] = i2c_smbus_read_byte_data(client, 251 - ADT7473_REG_TEMP(i)); 252 - 253 - for (i = 0; i < ADT7473_FAN_COUNT; i++) 254 - data->fan[i] = adt7473_read_word_data(client, 255 - ADT7473_REG_FAN(i)); 256 - 257 - for (i = 0; i < ADT7473_PWM_COUNT; i++) 258 - data->pwm[i] = i2c_smbus_read_byte_data(client, 259 - ADT7473_REG_PWM(i)); 260 - 261 - data->alarm = i2c_smbus_read_byte_data(client, ADT7473_REG_ALARM1); 262 - if (data->alarm & ADT7473_OOL) 263 - data->alarm |= ALARM2(i2c_smbus_read_byte_data(client, 264 - ADT7473_REG_ALARM2)); 265 - 266 - data->sensors_last_updated = local_jiffies; 267 - data->sensors_valid = 1; 268 - 269 - no_sensor_update: 270 - if (time_before(local_jiffies, data->limits_last_updated + 271 - LIMIT_REFRESH_INTERVAL) 272 - && data->limits_valid) 273 - goto out; 274 - 275 - for (i = 0; i < ADT7473_VOLT_COUNT; i++) { 276 - data->volt_min[i] = i2c_smbus_read_byte_data(client, 277 - ADT7473_REG_VOLT_MIN(i)); 278 - data->volt_max[i] = i2c_smbus_read_byte_data(client, 279 - ADT7473_REG_VOLT_MAX(i)); 280 - } 281 - 282 - for (i = 0; i < ADT7473_TEMP_COUNT; i++) { 283 - data->temp_min[i] = i2c_smbus_read_byte_data(client, 284 - ADT7473_REG_TEMP_MIN(i)); 285 - data->temp_max[i] = i2c_smbus_read_byte_data(client, 286 - ADT7473_REG_TEMP_MAX(i)); 287 - data->temp_tmin[i] = i2c_smbus_read_byte_data(client, 288 - ADT7473_REG_TEMP_TMIN(i)); 289 - data->temp_tmax[i] = i2c_smbus_read_byte_data(client, 290 - ADT7473_REG_TEMP_TMAX(i)); 291 - } 292 - 293 - for (i = 0; i < ADT7473_FAN_COUNT; i++) 294 - data->fan_min[i] = adt7473_read_word_data(client, 295 - ADT7473_REG_FAN_MIN(i)); 296 - 297 - for (i = 0; i < ADT7473_PWM_COUNT; i++) { 298 - data->pwm_max[i] = i2c_smbus_read_byte_data(client, 299 - ADT7473_REG_PWM_MAX(i)); 300 - data->pwm_min[i] = i2c_smbus_read_byte_data(client, 301 - ADT7473_REG_PWM_MIN(i)); 302 - data->pwm_behavior[i] = i2c_smbus_read_byte_data(client, 303 - ADT7473_REG_PWM_BHVR(i)); 304 - } 305 - 306 - i = i2c_smbus_read_byte_data(client, ADT7473_REG_CFG4); 307 - data->max_duty_at_overheat = !!(i & ADT7473_CFG4_MAX_DUTY_AT_OVT); 308 - 309 - data->limits_last_updated = local_jiffies; 310 - data->limits_valid = 1; 311 - 312 - out: 313 - mutex_unlock(&data->lock); 314 - return data; 315 - } 316 - 317 - /* 318 - * Conversions 319 - */ 320 - 321 - /* IN are scaled acording to built-in resistors */ 322 - static const int adt7473_scaling[] = { /* .001 Volts */ 323 - 2250, 3300 324 - }; 325 - #define SCALE(val, from, to) (((val) * (to) + ((from) / 2)) / (from)) 326 - 327 - static int decode_volt(int volt_index, u8 raw) 328 - { 329 - return SCALE(raw, 192, adt7473_scaling[volt_index]); 330 - } 331 - 332 - static u8 encode_volt(int volt_index, int cooked) 333 - { 334 - int raw = SCALE(cooked, adt7473_scaling[volt_index], 192); 335 - return SENSORS_LIMIT(raw, 0, 255); 336 - } 337 - 338 - static ssize_t show_volt_min(struct device *dev, 339 - struct device_attribute *devattr, 340 - char *buf) 341 - { 342 - struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); 343 - struct adt7473_data *data = adt7473_update_device(dev); 344 - return sprintf(buf, "%d\n", 345 - decode_volt(attr->index, data->volt_min[attr->index])); 346 - } 347 - 348 - static ssize_t set_volt_min(struct device *dev, 349 - struct device_attribute *devattr, 350 - const char *buf, 351 - size_t count) 352 - { 353 - struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); 354 - struct i2c_client *client = to_i2c_client(dev); 355 - struct adt7473_data *data = i2c_get_clientdata(client); 356 - long volt; 357 - 358 - if (strict_strtol(buf, 10, &volt)) 359 - return -EINVAL; 360 - 361 - volt = encode_volt(attr->index, volt); 362 - 363 - mutex_lock(&data->lock); 364 - data->volt_min[attr->index] = volt; 365 - i2c_smbus_write_byte_data(client, ADT7473_REG_VOLT_MIN(attr->index), 366 - volt); 367 - mutex_unlock(&data->lock); 368 - 369 - return count; 370 - } 371 - 372 - static ssize_t show_volt_max(struct device *dev, 373 - struct device_attribute *devattr, 374 - char *buf) 375 - { 376 - struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); 377 - struct adt7473_data *data = adt7473_update_device(dev); 378 - return sprintf(buf, "%d\n", 379 - decode_volt(attr->index, data->volt_max[attr->index])); 380 - } 381 - 382 - static ssize_t set_volt_max(struct device *dev, 383 - struct device_attribute *devattr, 384 - const char *buf, 385 - size_t count) 386 - { 387 - struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); 388 - struct i2c_client *client = to_i2c_client(dev); 389 - struct adt7473_data *data = i2c_get_clientdata(client); 390 - long volt; 391 - 392 - if (strict_strtol(buf, 10, &volt)) 393 - return -EINVAL; 394 - 395 - volt = encode_volt(attr->index, volt); 396 - 397 - mutex_lock(&data->lock); 398 - data->volt_max[attr->index] = volt; 399 - i2c_smbus_write_byte_data(client, ADT7473_REG_VOLT_MAX(attr->index), 400 - volt); 401 - mutex_unlock(&data->lock); 402 - 403 - return count; 404 - } 405 - 406 - static ssize_t show_volt(struct device *dev, struct device_attribute *devattr, 407 - char *buf) 408 - { 409 - struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); 410 - struct adt7473_data *data = adt7473_update_device(dev); 411 - 412 - return sprintf(buf, "%d\n", 413 - decode_volt(attr->index, data->volt[attr->index])); 414 - } 415 - 416 - /* 417 - * This chip can report temperature data either as a two's complement 418 - * number in the range -128 to 127, or as an unsigned number that must 419 - * be offset by 64. 420 - */ 421 - static int decode_temp(u8 twos_complement, u8 raw) 422 - { 423 - return twos_complement ? (s8)raw : raw - 64; 424 - } 425 - 426 - static u8 encode_temp(u8 twos_complement, int cooked) 427 - { 428 - u8 ret = twos_complement ? cooked & 0xFF : cooked + 64; 429 - return SENSORS_LIMIT(ret, 0, 255); 430 - } 431 - 432 - static ssize_t show_temp_min(struct device *dev, 433 - struct device_attribute *devattr, 434 - char *buf) 435 - { 436 - struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); 437 - struct adt7473_data *data = adt7473_update_device(dev); 438 - return sprintf(buf, "%d\n", 1000 * decode_temp( 439 - data->temp_twos_complement, 440 - data->temp_min[attr->index])); 441 - } 442 - 443 - static ssize_t set_temp_min(struct device *dev, 444 - struct device_attribute *devattr, 445 - const char *buf, 446 - size_t count) 447 - { 448 - struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); 449 - struct i2c_client *client = to_i2c_client(dev); 450 - struct adt7473_data *data = i2c_get_clientdata(client); 451 - long temp; 452 - 453 - if (strict_strtol(buf, 10, &temp)) 454 - return -EINVAL; 455 - 456 - temp = DIV_ROUND_CLOSEST(temp, 1000); 457 - temp = encode_temp(data->temp_twos_complement, temp); 458 - 459 - mutex_lock(&data->lock); 460 - data->temp_min[attr->index] = temp; 461 - i2c_smbus_write_byte_data(client, ADT7473_REG_TEMP_MIN(attr->index), 462 - temp); 463 - mutex_unlock(&data->lock); 464 - 465 - return count; 466 - } 467 - 468 - static ssize_t show_temp_max(struct device *dev, 469 - struct device_attribute *devattr, 470 - char *buf) 471 - { 472 - struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); 473 - struct adt7473_data *data = adt7473_update_device(dev); 474 - return sprintf(buf, "%d\n", 1000 * decode_temp( 475 - data->temp_twos_complement, 476 - data->temp_max[attr->index])); 477 - } 478 - 479 - static ssize_t set_temp_max(struct device *dev, 480 - struct device_attribute *devattr, 481 - const char *buf, 482 - size_t count) 483 - { 484 - struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); 485 - struct i2c_client *client = to_i2c_client(dev); 486 - struct adt7473_data *data = i2c_get_clientdata(client); 487 - long temp; 488 - 489 - if (strict_strtol(buf, 10, &temp)) 490 - return -EINVAL; 491 - 492 - temp = DIV_ROUND_CLOSEST(temp, 1000); 493 - temp = encode_temp(data->temp_twos_complement, temp); 494 - 495 - mutex_lock(&data->lock); 496 - data->temp_max[attr->index] = temp; 497 - i2c_smbus_write_byte_data(client, ADT7473_REG_TEMP_MAX(attr->index), 498 - temp); 499 - mutex_unlock(&data->lock); 500 - 501 - return count; 502 - } 503 - 504 - static ssize_t show_temp(struct device *dev, struct device_attribute *devattr, 505 - char *buf) 506 - { 507 - struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); 508 - struct adt7473_data *data = adt7473_update_device(dev); 509 - return sprintf(buf, "%d\n", 1000 * decode_temp( 510 - data->temp_twos_complement, 511 - data->temp[attr->index])); 512 - } 513 - 514 - static ssize_t show_fan_min(struct device *dev, 515 - struct device_attribute *devattr, 516 - char *buf) 517 - { 518 - struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); 519 - struct adt7473_data *data = adt7473_update_device(dev); 520 - 521 - if (FAN_DATA_VALID(data->fan_min[attr->index])) 522 - return sprintf(buf, "%d\n", 523 - FAN_PERIOD_TO_RPM(data->fan_min[attr->index])); 524 - else 525 - return sprintf(buf, "0\n"); 526 - } 527 - 528 - static ssize_t set_fan_min(struct device *dev, 529 - struct device_attribute *devattr, 530 - const char *buf, size_t count) 531 - { 532 - struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); 533 - struct i2c_client *client = to_i2c_client(dev); 534 - struct adt7473_data *data = i2c_get_clientdata(client); 535 - long temp; 536 - 537 - if (strict_strtol(buf, 10, &temp) || !temp) 538 - return -EINVAL; 539 - 540 - temp = FAN_RPM_TO_PERIOD(temp); 541 - temp = SENSORS_LIMIT(temp, 1, 65534); 542 - 543 - mutex_lock(&data->lock); 544 - data->fan_min[attr->index] = temp; 545 - adt7473_write_word_data(client, ADT7473_REG_FAN_MIN(attr->index), temp); 546 - mutex_unlock(&data->lock); 547 - 548 - return count; 549 - } 550 - 551 - static ssize_t show_fan(struct device *dev, struct device_attribute *devattr, 552 - char *buf) 553 - { 554 - struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); 555 - struct adt7473_data *data = adt7473_update_device(dev); 556 - 557 - if (FAN_DATA_VALID(data->fan[attr->index])) 558 - return sprintf(buf, "%d\n", 559 - FAN_PERIOD_TO_RPM(data->fan[attr->index])); 560 - else 561 - return sprintf(buf, "0\n"); 562 - } 563 - 564 - static ssize_t show_max_duty_at_crit(struct device *dev, 565 - struct device_attribute *devattr, 566 - char *buf) 567 - { 568 - struct adt7473_data *data = adt7473_update_device(dev); 569 - return sprintf(buf, "%d\n", data->max_duty_at_overheat); 570 - } 571 - 572 - static ssize_t set_max_duty_at_crit(struct device *dev, 573 - struct device_attribute *devattr, 574 - const char *buf, 575 - size_t count) 576 - { 577 - u8 reg; 578 - struct i2c_client *client = to_i2c_client(dev); 579 - struct adt7473_data *data = i2c_get_clientdata(client); 580 - long temp; 581 - 582 - if (strict_strtol(buf, 10, &temp)) 583 - return -EINVAL; 584 - 585 - mutex_lock(&data->lock); 586 - data->max_duty_at_overheat = !!temp; 587 - reg = i2c_smbus_read_byte_data(client, ADT7473_REG_CFG4); 588 - if (temp) 589 - reg |= ADT7473_CFG4_MAX_DUTY_AT_OVT; 590 - else 591 - reg &= ~ADT7473_CFG4_MAX_DUTY_AT_OVT; 592 - i2c_smbus_write_byte_data(client, ADT7473_REG_CFG4, reg); 593 - mutex_unlock(&data->lock); 594 - 595 - return count; 596 - } 597 - 598 - static ssize_t show_pwm(struct device *dev, struct device_attribute *devattr, 599 - char *buf) 600 - { 601 - struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); 602 - struct adt7473_data *data = adt7473_update_device(dev); 603 - return sprintf(buf, "%d\n", data->pwm[attr->index]); 604 - } 605 - 606 - static ssize_t set_pwm(struct device *dev, struct device_attribute *devattr, 607 - const char *buf, size_t count) 608 - { 609 - struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); 610 - struct i2c_client *client = to_i2c_client(dev); 611 - struct adt7473_data *data = i2c_get_clientdata(client); 612 - long temp; 613 - 614 - if (strict_strtol(buf, 10, &temp)) 615 - return -EINVAL; 616 - 617 - temp = SENSORS_LIMIT(temp, 0, 255); 618 - 619 - mutex_lock(&data->lock); 620 - data->pwm[attr->index] = temp; 621 - i2c_smbus_write_byte_data(client, ADT7473_REG_PWM(attr->index), temp); 622 - mutex_unlock(&data->lock); 623 - 624 - return count; 625 - } 626 - 627 - static ssize_t show_pwm_max(struct device *dev, 628 - struct device_attribute *devattr, 629 - char *buf) 630 - { 631 - struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); 632 - struct adt7473_data *data = adt7473_update_device(dev); 633 - return sprintf(buf, "%d\n", data->pwm_max[attr->index]); 634 - } 635 - 636 - static ssize_t set_pwm_max(struct device *dev, 637 - struct device_attribute *devattr, 638 - const char *buf, 639 - size_t count) 640 - { 641 - struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); 642 - struct i2c_client *client = to_i2c_client(dev); 643 - struct adt7473_data *data = i2c_get_clientdata(client); 644 - long temp; 645 - 646 - if (strict_strtol(buf, 10, &temp)) 647 - return -EINVAL; 648 - 649 - temp = SENSORS_LIMIT(temp, 0, 255); 650 - 651 - mutex_lock(&data->lock); 652 - data->pwm_max[attr->index] = temp; 653 - i2c_smbus_write_byte_data(client, ADT7473_REG_PWM_MAX(attr->index), 654 - temp); 655 - mutex_unlock(&data->lock); 656 - 657 - return count; 658 - } 659 - 660 - static ssize_t show_pwm_min(struct device *dev, 661 - struct device_attribute *devattr, 662 - char *buf) 663 - { 664 - struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); 665 - struct adt7473_data *data = adt7473_update_device(dev); 666 - return sprintf(buf, "%d\n", data->pwm_min[attr->index]); 667 - } 668 - 669 - static ssize_t set_pwm_min(struct device *dev, 670 - struct device_attribute *devattr, 671 - const char *buf, 672 - size_t count) 673 - { 674 - struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); 675 - struct i2c_client *client = to_i2c_client(dev); 676 - struct adt7473_data *data = i2c_get_clientdata(client); 677 - long temp; 678 - 679 - if (strict_strtol(buf, 10, &temp)) 680 - return -EINVAL; 681 - 682 - temp = SENSORS_LIMIT(temp, 0, 255); 683 - 684 - mutex_lock(&data->lock); 685 - data->pwm_min[attr->index] = temp; 686 - i2c_smbus_write_byte_data(client, ADT7473_REG_PWM_MIN(attr->index), 687 - temp); 688 - mutex_unlock(&data->lock); 689 - 690 - return count; 691 - } 692 - 693 - static ssize_t show_temp_tmax(struct device *dev, 694 - struct device_attribute *devattr, 695 - char *buf) 696 - { 697 - struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); 698 - struct adt7473_data *data = adt7473_update_device(dev); 699 - return sprintf(buf, "%d\n", 1000 * decode_temp( 700 - data->temp_twos_complement, 701 - data->temp_tmax[attr->index])); 702 - } 703 - 704 - static ssize_t set_temp_tmax(struct device *dev, 705 - struct device_attribute *devattr, 706 - const char *buf, 707 - size_t count) 708 - { 709 - struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); 710 - struct i2c_client *client = to_i2c_client(dev); 711 - struct adt7473_data *data = i2c_get_clientdata(client); 712 - long temp; 713 - 714 - if (strict_strtol(buf, 10, &temp)) 715 - return -EINVAL; 716 - 717 - temp = DIV_ROUND_CLOSEST(temp, 1000); 718 - temp = encode_temp(data->temp_twos_complement, temp); 719 - 720 - mutex_lock(&data->lock); 721 - data->temp_tmax[attr->index] = temp; 722 - i2c_smbus_write_byte_data(client, ADT7473_REG_TEMP_TMAX(attr->index), 723 - temp); 724 - mutex_unlock(&data->lock); 725 - 726 - return count; 727 - } 728 - 729 - static ssize_t show_temp_tmin(struct device *dev, 730 - struct device_attribute *devattr, 731 - char *buf) 732 - { 733 - struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); 734 - struct adt7473_data *data = adt7473_update_device(dev); 735 - return sprintf(buf, "%d\n", 1000 * decode_temp( 736 - data->temp_twos_complement, 737 - data->temp_tmin[attr->index])); 738 - } 739 - 740 - static ssize_t set_temp_tmin(struct device *dev, 741 - struct device_attribute *devattr, 742 - const char *buf, 743 - size_t count) 744 - { 745 - struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); 746 - struct i2c_client *client = to_i2c_client(dev); 747 - struct adt7473_data *data = i2c_get_clientdata(client); 748 - long temp; 749 - 750 - if (strict_strtol(buf, 10, &temp)) 751 - return -EINVAL; 752 - 753 - temp = DIV_ROUND_CLOSEST(temp, 1000); 754 - temp = encode_temp(data->temp_twos_complement, temp); 755 - 756 - mutex_lock(&data->lock); 757 - data->temp_tmin[attr->index] = temp; 758 - i2c_smbus_write_byte_data(client, ADT7473_REG_TEMP_TMIN(attr->index), 759 - temp); 760 - mutex_unlock(&data->lock); 761 - 762 - return count; 763 - } 764 - 765 - static ssize_t show_pwm_enable(struct device *dev, 766 - struct device_attribute *devattr, 767 - char *buf) 768 - { 769 - struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); 770 - struct adt7473_data *data = adt7473_update_device(dev); 771 - 772 - switch (data->pwm_behavior[attr->index] >> ADT7473_PWM_BHVR_SHIFT) { 773 - case 3: 774 - return sprintf(buf, "0\n"); 775 - case 7: 776 - return sprintf(buf, "1\n"); 777 - default: 778 - return sprintf(buf, "2\n"); 779 - } 780 - } 781 - 782 - static ssize_t set_pwm_enable(struct device *dev, 783 - struct device_attribute *devattr, 784 - const char *buf, 785 - size_t count) 786 - { 787 - u8 reg; 788 - struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); 789 - struct i2c_client *client = to_i2c_client(dev); 790 - struct adt7473_data *data = i2c_get_clientdata(client); 791 - long temp; 792 - 793 - if (strict_strtol(buf, 10, &temp)) 794 - return -EINVAL; 795 - 796 - switch (temp) { 797 - case 0: 798 - temp = 3; 799 - break; 800 - case 1: 801 - temp = 7; 802 - break; 803 - case 2: 804 - /* Enter automatic mode with fans off */ 805 - temp = 4; 806 - break; 807 - default: 808 - return -EINVAL; 809 - } 810 - 811 - mutex_lock(&data->lock); 812 - reg = i2c_smbus_read_byte_data(client, 813 - ADT7473_REG_PWM_BHVR(attr->index)); 814 - reg = (temp << ADT7473_PWM_BHVR_SHIFT) | 815 - (reg & ~ADT7473_PWM_BHVR_MASK); 816 - i2c_smbus_write_byte_data(client, ADT7473_REG_PWM_BHVR(attr->index), 817 - reg); 818 - data->pwm_behavior[attr->index] = reg; 819 - mutex_unlock(&data->lock); 820 - 821 - return count; 822 - } 823 - 824 - static ssize_t show_pwm_auto_temp(struct device *dev, 825 - struct device_attribute *devattr, 826 - char *buf) 827 - { 828 - struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); 829 - struct adt7473_data *data = adt7473_update_device(dev); 830 - int bhvr = data->pwm_behavior[attr->index] >> ADT7473_PWM_BHVR_SHIFT; 831 - 832 - switch (bhvr) { 833 - case 3: 834 - case 4: 835 - case 7: 836 - return sprintf(buf, "0\n"); 837 - case 0: 838 - case 1: 839 - case 5: 840 - case 6: 841 - return sprintf(buf, "%d\n", bhvr + 1); 842 - case 2: 843 - return sprintf(buf, "4\n"); 844 - } 845 - /* shouldn't ever get here */ 846 - BUG(); 847 - } 848 - 849 - static ssize_t set_pwm_auto_temp(struct device *dev, 850 - struct device_attribute *devattr, 851 - const char *buf, 852 - size_t count) 853 - { 854 - u8 reg; 855 - struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); 856 - struct i2c_client *client = to_i2c_client(dev); 857 - struct adt7473_data *data = i2c_get_clientdata(client); 858 - long temp; 859 - 860 - if (strict_strtol(buf, 10, &temp)) 861 - return -EINVAL; 862 - 863 - switch (temp) { 864 - case 1: 865 - case 2: 866 - case 6: 867 - case 7: 868 - temp--; 869 - break; 870 - case 0: 871 - temp = 4; 872 - break; 873 - default: 874 - return -EINVAL; 875 - } 876 - 877 - mutex_lock(&data->lock); 878 - reg = i2c_smbus_read_byte_data(client, 879 - ADT7473_REG_PWM_BHVR(attr->index)); 880 - reg = (temp << ADT7473_PWM_BHVR_SHIFT) | 881 - (reg & ~ADT7473_PWM_BHVR_MASK); 882 - i2c_smbus_write_byte_data(client, ADT7473_REG_PWM_BHVR(attr->index), 883 - reg); 884 - data->pwm_behavior[attr->index] = reg; 885 - mutex_unlock(&data->lock); 886 - 887 - return count; 888 - } 889 - 890 - static ssize_t show_alarm(struct device *dev, 891 - struct device_attribute *devattr, 892 - char *buf) 893 - { 894 - struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); 895 - struct adt7473_data *data = adt7473_update_device(dev); 896 - 897 - if (data->alarm & attr->index) 898 - return sprintf(buf, "1\n"); 899 - else 900 - return sprintf(buf, "0\n"); 901 - } 902 - 903 - 904 - static SENSOR_DEVICE_ATTR(in1_max, S_IWUSR | S_IRUGO, show_volt_max, 905 - set_volt_max, 0); 906 - static SENSOR_DEVICE_ATTR(in2_max, S_IWUSR | S_IRUGO, show_volt_max, 907 - set_volt_max, 1); 908 - 909 - static SENSOR_DEVICE_ATTR(in1_min, S_IWUSR | S_IRUGO, show_volt_min, 910 - set_volt_min, 0); 911 - static SENSOR_DEVICE_ATTR(in2_min, S_IWUSR | S_IRUGO, show_volt_min, 912 - set_volt_min, 1); 913 - 914 - static SENSOR_DEVICE_ATTR(in1_input, S_IRUGO, show_volt, NULL, 0); 915 - static SENSOR_DEVICE_ATTR(in2_input, S_IRUGO, show_volt, NULL, 1); 916 - 917 - static SENSOR_DEVICE_ATTR(in1_alarm, S_IRUGO, show_alarm, NULL, 918 - ADT7473_VCCP_ALARM); 919 - static SENSOR_DEVICE_ATTR(in2_alarm, S_IRUGO, show_alarm, NULL, 920 - ADT7473_VCC_ALARM); 921 - 922 - static SENSOR_DEVICE_ATTR(temp1_max, S_IWUSR | S_IRUGO, show_temp_max, 923 - set_temp_max, 0); 924 - static SENSOR_DEVICE_ATTR(temp2_max, S_IWUSR | S_IRUGO, show_temp_max, 925 - set_temp_max, 1); 926 - static SENSOR_DEVICE_ATTR(temp3_max, S_IWUSR | S_IRUGO, show_temp_max, 927 - set_temp_max, 2); 928 - 929 - static SENSOR_DEVICE_ATTR(temp1_min, S_IWUSR | S_IRUGO, show_temp_min, 930 - set_temp_min, 0); 931 - static SENSOR_DEVICE_ATTR(temp2_min, S_IWUSR | S_IRUGO, show_temp_min, 932 - set_temp_min, 1); 933 - static SENSOR_DEVICE_ATTR(temp3_min, S_IWUSR | S_IRUGO, show_temp_min, 934 - set_temp_min, 2); 935 - 936 - static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, show_temp, NULL, 0); 937 - static SENSOR_DEVICE_ATTR(temp2_input, S_IRUGO, show_temp, NULL, 1); 938 - static SENSOR_DEVICE_ATTR(temp3_input, S_IRUGO, show_temp, NULL, 2); 939 - 940 - static SENSOR_DEVICE_ATTR(temp1_alarm, S_IRUGO, show_alarm, NULL, 941 - ADT7473_R1T_ALARM | ALARM2(ADT7473_R1T_SHORT)); 942 - static SENSOR_DEVICE_ATTR(temp2_alarm, S_IRUGO, show_alarm, NULL, 943 - ADT7473_LT_ALARM); 944 - static SENSOR_DEVICE_ATTR(temp3_alarm, S_IRUGO, show_alarm, NULL, 945 - ADT7473_R2T_ALARM | ALARM2(ADT7473_R2T_SHORT)); 946 - 947 - static SENSOR_DEVICE_ATTR(fan1_min, S_IWUSR | S_IRUGO, show_fan_min, 948 - set_fan_min, 0); 949 - static SENSOR_DEVICE_ATTR(fan2_min, S_IWUSR | S_IRUGO, show_fan_min, 950 - set_fan_min, 1); 951 - static SENSOR_DEVICE_ATTR(fan3_min, S_IWUSR | S_IRUGO, show_fan_min, 952 - set_fan_min, 2); 953 - static SENSOR_DEVICE_ATTR(fan4_min, S_IWUSR | S_IRUGO, show_fan_min, 954 - set_fan_min, 3); 955 - 956 - static SENSOR_DEVICE_ATTR(fan1_input, S_IRUGO, show_fan, NULL, 0); 957 - static SENSOR_DEVICE_ATTR(fan2_input, S_IRUGO, show_fan, NULL, 1); 958 - static SENSOR_DEVICE_ATTR(fan3_input, S_IRUGO, show_fan, NULL, 2); 959 - static SENSOR_DEVICE_ATTR(fan4_input, S_IRUGO, show_fan, NULL, 3); 960 - 961 - static SENSOR_DEVICE_ATTR(fan1_alarm, S_IRUGO, show_alarm, NULL, 962 - ALARM2(ADT7473_FAN1_ALARM)); 963 - static SENSOR_DEVICE_ATTR(fan2_alarm, S_IRUGO, show_alarm, NULL, 964 - ALARM2(ADT7473_FAN2_ALARM)); 965 - static SENSOR_DEVICE_ATTR(fan3_alarm, S_IRUGO, show_alarm, NULL, 966 - ALARM2(ADT7473_FAN3_ALARM)); 967 - static SENSOR_DEVICE_ATTR(fan4_alarm, S_IRUGO, show_alarm, NULL, 968 - ALARM2(ADT7473_FAN4_ALARM)); 969 - 970 - static SENSOR_DEVICE_ATTR(pwm_use_point2_pwm_at_crit, S_IWUSR | S_IRUGO, 971 - show_max_duty_at_crit, set_max_duty_at_crit, 0); 972 - 973 - static SENSOR_DEVICE_ATTR(pwm1, S_IWUSR | S_IRUGO, show_pwm, set_pwm, 0); 974 - static SENSOR_DEVICE_ATTR(pwm2, S_IWUSR | S_IRUGO, show_pwm, set_pwm, 1); 975 - static SENSOR_DEVICE_ATTR(pwm3, S_IWUSR | S_IRUGO, show_pwm, set_pwm, 2); 976 - 977 - static SENSOR_DEVICE_ATTR(pwm1_auto_point1_pwm, S_IWUSR | S_IRUGO, 978 - show_pwm_min, set_pwm_min, 0); 979 - static SENSOR_DEVICE_ATTR(pwm2_auto_point1_pwm, S_IWUSR | S_IRUGO, 980 - show_pwm_min, set_pwm_min, 1); 981 - static SENSOR_DEVICE_ATTR(pwm3_auto_point1_pwm, S_IWUSR | S_IRUGO, 982 - show_pwm_min, set_pwm_min, 2); 983 - 984 - static SENSOR_DEVICE_ATTR(pwm1_auto_point2_pwm, S_IWUSR | S_IRUGO, 985 - show_pwm_max, set_pwm_max, 0); 986 - static SENSOR_DEVICE_ATTR(pwm2_auto_point2_pwm, S_IWUSR | S_IRUGO, 987 - show_pwm_max, set_pwm_max, 1); 988 - static SENSOR_DEVICE_ATTR(pwm3_auto_point2_pwm, S_IWUSR | S_IRUGO, 989 - show_pwm_max, set_pwm_max, 2); 990 - 991 - static SENSOR_DEVICE_ATTR(temp1_auto_point1_temp, S_IWUSR | S_IRUGO, 992 - show_temp_tmin, set_temp_tmin, 0); 993 - static SENSOR_DEVICE_ATTR(temp2_auto_point1_temp, S_IWUSR | S_IRUGO, 994 - show_temp_tmin, set_temp_tmin, 1); 995 - static SENSOR_DEVICE_ATTR(temp3_auto_point1_temp, S_IWUSR | S_IRUGO, 996 - show_temp_tmin, set_temp_tmin, 2); 997 - 998 - static SENSOR_DEVICE_ATTR(temp1_auto_point2_temp, S_IWUSR | S_IRUGO, 999 - show_temp_tmax, set_temp_tmax, 0); 1000 - static SENSOR_DEVICE_ATTR(temp2_auto_point2_temp, S_IWUSR | S_IRUGO, 1001 - show_temp_tmax, set_temp_tmax, 1); 1002 - static SENSOR_DEVICE_ATTR(temp3_auto_point2_temp, S_IWUSR | S_IRUGO, 1003 - show_temp_tmax, set_temp_tmax, 2); 1004 - 1005 - static SENSOR_DEVICE_ATTR(pwm1_enable, S_IWUSR | S_IRUGO, show_pwm_enable, 1006 - set_pwm_enable, 0); 1007 - static SENSOR_DEVICE_ATTR(pwm2_enable, S_IWUSR | S_IRUGO, show_pwm_enable, 1008 - set_pwm_enable, 1); 1009 - static SENSOR_DEVICE_ATTR(pwm3_enable, S_IWUSR | S_IRUGO, show_pwm_enable, 1010 - set_pwm_enable, 2); 1011 - 1012 - static SENSOR_DEVICE_ATTR(pwm1_auto_channels_temp, S_IWUSR | S_IRUGO, 1013 - show_pwm_auto_temp, set_pwm_auto_temp, 0); 1014 - static SENSOR_DEVICE_ATTR(pwm2_auto_channels_temp, S_IWUSR | S_IRUGO, 1015 - show_pwm_auto_temp, set_pwm_auto_temp, 1); 1016 - static SENSOR_DEVICE_ATTR(pwm3_auto_channels_temp, S_IWUSR | S_IRUGO, 1017 - show_pwm_auto_temp, set_pwm_auto_temp, 2); 1018 - 1019 - static struct attribute *adt7473_attr[] = 1020 - { 1021 - &sensor_dev_attr_in1_max.dev_attr.attr, 1022 - &sensor_dev_attr_in2_max.dev_attr.attr, 1023 - &sensor_dev_attr_in1_min.dev_attr.attr, 1024 - &sensor_dev_attr_in2_min.dev_attr.attr, 1025 - &sensor_dev_attr_in1_input.dev_attr.attr, 1026 - &sensor_dev_attr_in2_input.dev_attr.attr, 1027 - &sensor_dev_attr_in1_alarm.dev_attr.attr, 1028 - &sensor_dev_attr_in2_alarm.dev_attr.attr, 1029 - 1030 - &sensor_dev_attr_temp1_max.dev_attr.attr, 1031 - &sensor_dev_attr_temp2_max.dev_attr.attr, 1032 - &sensor_dev_attr_temp3_max.dev_attr.attr, 1033 - &sensor_dev_attr_temp1_min.dev_attr.attr, 1034 - &sensor_dev_attr_temp2_min.dev_attr.attr, 1035 - &sensor_dev_attr_temp3_min.dev_attr.attr, 1036 - &sensor_dev_attr_temp1_input.dev_attr.attr, 1037 - &sensor_dev_attr_temp2_input.dev_attr.attr, 1038 - &sensor_dev_attr_temp3_input.dev_attr.attr, 1039 - &sensor_dev_attr_temp1_alarm.dev_attr.attr, 1040 - &sensor_dev_attr_temp2_alarm.dev_attr.attr, 1041 - &sensor_dev_attr_temp3_alarm.dev_attr.attr, 1042 - &sensor_dev_attr_temp1_auto_point1_temp.dev_attr.attr, 1043 - &sensor_dev_attr_temp2_auto_point1_temp.dev_attr.attr, 1044 - &sensor_dev_attr_temp3_auto_point1_temp.dev_attr.attr, 1045 - &sensor_dev_attr_temp1_auto_point2_temp.dev_attr.attr, 1046 - &sensor_dev_attr_temp2_auto_point2_temp.dev_attr.attr, 1047 - &sensor_dev_attr_temp3_auto_point2_temp.dev_attr.attr, 1048 - 1049 - &sensor_dev_attr_fan1_min.dev_attr.attr, 1050 - &sensor_dev_attr_fan2_min.dev_attr.attr, 1051 - &sensor_dev_attr_fan3_min.dev_attr.attr, 1052 - &sensor_dev_attr_fan4_min.dev_attr.attr, 1053 - &sensor_dev_attr_fan1_input.dev_attr.attr, 1054 - &sensor_dev_attr_fan2_input.dev_attr.attr, 1055 - &sensor_dev_attr_fan3_input.dev_attr.attr, 1056 - &sensor_dev_attr_fan4_input.dev_attr.attr, 1057 - &sensor_dev_attr_fan1_alarm.dev_attr.attr, 1058 - &sensor_dev_attr_fan2_alarm.dev_attr.attr, 1059 - &sensor_dev_attr_fan3_alarm.dev_attr.attr, 1060 - &sensor_dev_attr_fan4_alarm.dev_attr.attr, 1061 - 1062 - &sensor_dev_attr_pwm_use_point2_pwm_at_crit.dev_attr.attr, 1063 - 1064 - &sensor_dev_attr_pwm1.dev_attr.attr, 1065 - &sensor_dev_attr_pwm2.dev_attr.attr, 1066 - &sensor_dev_attr_pwm3.dev_attr.attr, 1067 - &sensor_dev_attr_pwm1_auto_point1_pwm.dev_attr.attr, 1068 - &sensor_dev_attr_pwm2_auto_point1_pwm.dev_attr.attr, 1069 - &sensor_dev_attr_pwm3_auto_point1_pwm.dev_attr.attr, 1070 - &sensor_dev_attr_pwm1_auto_point2_pwm.dev_attr.attr, 1071 - &sensor_dev_attr_pwm2_auto_point2_pwm.dev_attr.attr, 1072 - &sensor_dev_attr_pwm3_auto_point2_pwm.dev_attr.attr, 1073 - 1074 - &sensor_dev_attr_pwm1_enable.dev_attr.attr, 1075 - &sensor_dev_attr_pwm2_enable.dev_attr.attr, 1076 - &sensor_dev_attr_pwm3_enable.dev_attr.attr, 1077 - &sensor_dev_attr_pwm1_auto_channels_temp.dev_attr.attr, 1078 - &sensor_dev_attr_pwm2_auto_channels_temp.dev_attr.attr, 1079 - &sensor_dev_attr_pwm3_auto_channels_temp.dev_attr.attr, 1080 - 1081 - NULL 1082 - }; 1083 - 1084 - /* Return 0 if detection is successful, -ENODEV otherwise */ 1085 - static int adt7473_detect(struct i2c_client *client, 1086 - struct i2c_board_info *info) 1087 - { 1088 - struct i2c_adapter *adapter = client->adapter; 1089 - int vendor, device, revision; 1090 - 1091 - if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) 1092 - return -ENODEV; 1093 - 1094 - vendor = i2c_smbus_read_byte_data(client, ADT7473_REG_VENDOR); 1095 - if (vendor != ADT7473_VENDOR) 1096 - return -ENODEV; 1097 - 1098 - device = i2c_smbus_read_byte_data(client, ADT7473_REG_DEVICE); 1099 - if (device != ADT7473_DEVICE) 1100 - return -ENODEV; 1101 - 1102 - revision = i2c_smbus_read_byte_data(client, ADT7473_REG_REVISION); 1103 - if (revision != ADT7473_REV_68 && revision != ADT7473_REV_69) 1104 - return -ENODEV; 1105 - 1106 - strlcpy(info->type, "adt7473", I2C_NAME_SIZE); 1107 - 1108 - return 0; 1109 - } 1110 - 1111 - static int adt7473_probe(struct i2c_client *client, 1112 - const struct i2c_device_id *id) 1113 - { 1114 - struct adt7473_data *data; 1115 - int err; 1116 - 1117 - data = kzalloc(sizeof(struct adt7473_data), GFP_KERNEL); 1118 - if (!data) { 1119 - err = -ENOMEM; 1120 - goto exit; 1121 - } 1122 - 1123 - i2c_set_clientdata(client, data); 1124 - mutex_init(&data->lock); 1125 - 1126 - dev_info(&client->dev, "%s chip found\n", client->name); 1127 - 1128 - /* Initialize the ADT7473 chip */ 1129 - adt7473_init_client(client); 1130 - 1131 - /* Register sysfs hooks */ 1132 - data->attrs.attrs = adt7473_attr; 1133 - err = sysfs_create_group(&client->dev.kobj, &data->attrs); 1134 - if (err) 1135 - goto exit_free; 1136 - 1137 - data->hwmon_dev = hwmon_device_register(&client->dev); 1138 - if (IS_ERR(data->hwmon_dev)) { 1139 - err = PTR_ERR(data->hwmon_dev); 1140 - goto exit_remove; 1141 - } 1142 - 1143 - return 0; 1144 - 1145 - exit_remove: 1146 - sysfs_remove_group(&client->dev.kobj, &data->attrs); 1147 - exit_free: 1148 - kfree(data); 1149 - exit: 1150 - return err; 1151 - } 1152 - 1153 - static int adt7473_remove(struct i2c_client *client) 1154 - { 1155 - struct adt7473_data *data = i2c_get_clientdata(client); 1156 - 1157 - hwmon_device_unregister(data->hwmon_dev); 1158 - sysfs_remove_group(&client->dev.kobj, &data->attrs); 1159 - kfree(data); 1160 - return 0; 1161 - } 1162 - 1163 - static int __init adt7473_init(void) 1164 - { 1165 - pr_notice("The adt7473 driver is deprecated, please use the adt7475 " 1166 - "driver instead\n"); 1167 - return i2c_add_driver(&adt7473_driver); 1168 - } 1169 - 1170 - static void __exit adt7473_exit(void) 1171 - { 1172 - i2c_del_driver(&adt7473_driver); 1173 - } 1174 - 1175 - MODULE_AUTHOR("Darrick J. Wong <djwong@us.ibm.com>"); 1176 - MODULE_DESCRIPTION("ADT7473 driver"); 1177 - MODULE_LICENSE("GPL"); 1178 - 1179 - module_init(adt7473_init); 1180 - module_exit(adt7473_exit);
···
+1255
drivers/hwmon/asc7621.c
···
··· 1 + /* 2 + * asc7621.c - Part of lm_sensors, Linux kernel modules for hardware monitoring 3 + * Copyright (c) 2007, 2010 George Joseph <george.joseph@fairview5.com> 4 + * 5 + * This program is free software; you can redistribute it and/or modify 6 + * it under the terms of the GNU General Public License as published by 7 + * the Free Software Foundation; either version 2 of the License, or 8 + * (at your option) any later version. 9 + * 10 + * This program is distributed in the hope that it will be useful, 11 + * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 + * GNU General Public License for more details. 14 + * 15 + * You should have received a copy of the GNU General Public License 16 + * along with this program; if not, write to the Free Software 17 + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 18 + */ 19 + 20 + #include <linux/module.h> 21 + #include <linux/init.h> 22 + #include <linux/slab.h> 23 + #include <linux/jiffies.h> 24 + #include <linux/i2c.h> 25 + #include <linux/hwmon.h> 26 + #include <linux/hwmon-sysfs.h> 27 + #include <linux/err.h> 28 + #include <linux/mutex.h> 29 + 30 + /* Addresses to scan */ 31 + static unsigned short normal_i2c[] = { 32 + 0x2c, 0x2d, 0x2e, I2C_CLIENT_END 33 + }; 34 + 35 + enum asc7621_type { 36 + asc7621, 37 + asc7621a 38 + }; 39 + 40 + #define INTERVAL_HIGH (HZ + HZ / 2) 41 + #define INTERVAL_LOW (1 * 60 * HZ) 42 + #define PRI_NONE 0 43 + #define PRI_LOW 1 44 + #define PRI_HIGH 2 45 + #define FIRST_CHIP asc7621 46 + #define LAST_CHIP asc7621a 47 + 48 + struct asc7621_chip { 49 + char *name; 50 + enum asc7621_type chip_type; 51 + u8 company_reg; 52 + u8 company_id; 53 + u8 verstep_reg; 54 + u8 verstep_id; 55 + unsigned short *addresses; 56 + }; 57 + 58 + static struct asc7621_chip asc7621_chips[] = { 59 + { 60 + .name = "asc7621", 61 + .chip_type = asc7621, 62 + .company_reg = 0x3e, 63 + .company_id = 0x61, 64 + .verstep_reg = 0x3f, 65 + .verstep_id = 0x6c, 66 + .addresses = normal_i2c, 67 + }, 68 + { 69 + .name = "asc7621a", 70 + .chip_type = asc7621a, 71 + .company_reg = 0x3e, 72 + .company_id = 0x61, 73 + .verstep_reg = 0x3f, 74 + .verstep_id = 0x6d, 75 + .addresses = normal_i2c, 76 + }, 77 + }; 78 + 79 + /* 80 + * Defines the highest register to be used, not the count. 81 + * The actual count will probably be smaller because of gaps 82 + * in the implementation (unused register locations). 83 + * This define will safely set the array size of both the parameter 84 + * and data arrays. 85 + * This comes from the data sheet register description table. 86 + */ 87 + #define LAST_REGISTER 0xff 88 + 89 + struct asc7621_data { 90 + struct i2c_client client; 91 + struct device *class_dev; 92 + struct mutex update_lock; 93 + int valid; /* !=0 if following fields are valid */ 94 + unsigned long last_high_reading; /* In jiffies */ 95 + unsigned long last_low_reading; /* In jiffies */ 96 + /* 97 + * Registers we care about occupy the corresponding index 98 + * in the array. Registers we don't care about are left 99 + * at 0. 100 + */ 101 + u8 reg[LAST_REGISTER + 1]; 102 + }; 103 + 104 + /* 105 + * Macro to get the parent asc7621_param structure 106 + * from a sensor_device_attribute passed into the 107 + * show/store functions. 108 + */ 109 + #define to_asc7621_param(_sda) \ 110 + container_of(_sda, struct asc7621_param, sda) 111 + 112 + /* 113 + * Each parameter to be retrieved needs an asc7621_param structure 114 + * allocated. It contains the sensor_device_attribute structure 115 + * and the control info needed to retrieve the value from the register map. 116 + */ 117 + struct asc7621_param { 118 + struct sensor_device_attribute sda; 119 + u8 priority; 120 + u8 msb[3]; 121 + u8 lsb[3]; 122 + u8 mask[3]; 123 + u8 shift[3]; 124 + }; 125 + 126 + /* 127 + * This is the map that ultimately indicates whether we'll be 128 + * retrieving a register value or not, and at what frequency. 129 + */ 130 + static u8 asc7621_register_priorities[255]; 131 + 132 + static struct asc7621_data *asc7621_update_device(struct device *dev); 133 + 134 + static inline u8 read_byte(struct i2c_client *client, u8 reg) 135 + { 136 + int res = i2c_smbus_read_byte_data(client, reg); 137 + if (res < 0) { 138 + dev_err(&client->dev, 139 + "Unable to read from register 0x%02x.\n", reg); 140 + return 0; 141 + }; 142 + return res & 0xff; 143 + } 144 + 145 + static inline int write_byte(struct i2c_client *client, u8 reg, u8 data) 146 + { 147 + int res = i2c_smbus_write_byte_data(client, reg, data); 148 + if (res < 0) { 149 + dev_err(&client->dev, 150 + "Unable to write value 0x%02x to register 0x%02x.\n", 151 + data, reg); 152 + }; 153 + return res; 154 + } 155 + 156 + /* 157 + * Data Handlers 158 + * Each function handles the formatting, storage 159 + * and retrieval of like parameters. 160 + */ 161 + 162 + #define SETUP_SHOW_data_param(d, a) \ 163 + struct sensor_device_attribute *sda = to_sensor_dev_attr(a); \ 164 + struct asc7621_data *data = asc7621_update_device(d); \ 165 + struct asc7621_param *param = to_asc7621_param(sda) 166 + 167 + #define SETUP_STORE_data_param(d, a) \ 168 + struct sensor_device_attribute *sda = to_sensor_dev_attr(a); \ 169 + struct i2c_client *client = to_i2c_client(d); \ 170 + struct asc7621_data *data = i2c_get_clientdata(client); \ 171 + struct asc7621_param *param = to_asc7621_param(sda) 172 + 173 + /* 174 + * u8 is just what it sounds like...an unsigned byte with no 175 + * special formatting. 176 + */ 177 + static ssize_t show_u8(struct device *dev, struct device_attribute *attr, 178 + char *buf) 179 + { 180 + SETUP_SHOW_data_param(dev, attr); 181 + 182 + return sprintf(buf, "%u\n", data->reg[param->msb[0]]); 183 + } 184 + 185 + static ssize_t store_u8(struct device *dev, struct device_attribute *attr, 186 + const char *buf, size_t count) 187 + { 188 + SETUP_STORE_data_param(dev, attr); 189 + long reqval; 190 + 191 + if (strict_strtol(buf, 10, &reqval)) 192 + return -EINVAL; 193 + 194 + reqval = SENSORS_LIMIT(reqval, 0, 255); 195 + 196 + mutex_lock(&data->update_lock); 197 + data->reg[param->msb[0]] = reqval; 198 + write_byte(client, param->msb[0], reqval); 199 + mutex_unlock(&data->update_lock); 200 + return count; 201 + } 202 + 203 + /* 204 + * Many of the config values occupy only a few bits of a register. 205 + */ 206 + static ssize_t show_bitmask(struct device *dev, 207 + struct device_attribute *attr, char *buf) 208 + { 209 + SETUP_SHOW_data_param(dev, attr); 210 + 211 + return sprintf(buf, "%u\n", 212 + (data->reg[param->msb[0]] >> param-> 213 + shift[0]) & param->mask[0]); 214 + } 215 + 216 + static ssize_t store_bitmask(struct device *dev, 217 + struct device_attribute *attr, 218 + const char *buf, size_t count) 219 + { 220 + SETUP_STORE_data_param(dev, attr); 221 + long reqval; 222 + u8 currval; 223 + 224 + if (strict_strtol(buf, 10, &reqval)) 225 + return -EINVAL; 226 + 227 + reqval = SENSORS_LIMIT(reqval, 0, param->mask[0]); 228 + 229 + reqval = (reqval & param->mask[0]) << param->shift[0]; 230 + 231 + mutex_lock(&data->update_lock); 232 + currval = read_byte(client, param->msb[0]); 233 + reqval |= (currval & ~(param->mask[0] << param->shift[0])); 234 + data->reg[param->msb[0]] = reqval; 235 + write_byte(client, param->msb[0], reqval); 236 + mutex_unlock(&data->update_lock); 237 + return count; 238 + } 239 + 240 + /* 241 + * 16 bit fan rpm values 242 + * reported by the device as the number of 11.111us periods (90khz) 243 + * between full fan rotations. Therefore... 244 + * RPM = (90000 * 60) / register value 245 + */ 246 + static ssize_t show_fan16(struct device *dev, 247 + struct device_attribute *attr, char *buf) 248 + { 249 + SETUP_SHOW_data_param(dev, attr); 250 + u16 regval; 251 + 252 + mutex_lock(&data->update_lock); 253 + regval = (data->reg[param->msb[0]] << 8) | data->reg[param->lsb[0]]; 254 + mutex_unlock(&data->update_lock); 255 + 256 + return sprintf(buf, "%u\n", 257 + (regval == 0 ? -1 : (regval) == 258 + 0xffff ? 0 : 5400000 / regval)); 259 + } 260 + 261 + static ssize_t store_fan16(struct device *dev, 262 + struct device_attribute *attr, const char *buf, 263 + size_t count) 264 + { 265 + SETUP_STORE_data_param(dev, attr); 266 + long reqval; 267 + 268 + if (strict_strtol(buf, 10, &reqval)) 269 + return -EINVAL; 270 + 271 + reqval = 272 + (SENSORS_LIMIT((reqval) <= 0 ? 0 : 5400000 / (reqval), 0, 65534)); 273 + 274 + mutex_lock(&data->update_lock); 275 + data->reg[param->msb[0]] = (reqval >> 8) & 0xff; 276 + data->reg[param->lsb[0]] = reqval & 0xff; 277 + write_byte(client, param->msb[0], data->reg[param->msb[0]]); 278 + write_byte(client, param->lsb[0], data->reg[param->lsb[0]]); 279 + mutex_unlock(&data->update_lock); 280 + 281 + return count; 282 + } 283 + 284 + /* 285 + * Voltages are scaled in the device so that the nominal voltage 286 + * is 3/4ths of the 0-255 range (i.e. 192). 287 + * If all voltages are 'normal' then all voltage registers will 288 + * read 0xC0. This doesn't help us if we don't have a point of refernce. 289 + * The data sheet however provides us with the full scale value for each 290 + * which is stored in in_scaling. The sda->index parameter value provides 291 + * the index into in_scaling. 292 + * 293 + * NOTE: The chip expects the first 2 inputs be 2.5 and 2.25 volts 294 + * respectively. That doesn't mean that's what the motherboard provides. :) 295 + */ 296 + 297 + static int asc7621_in_scaling[] = { 298 + 3320, 3000, 4380, 6640, 16000 299 + }; 300 + 301 + static ssize_t show_in10(struct device *dev, struct device_attribute *attr, 302 + char *buf) 303 + { 304 + SETUP_SHOW_data_param(dev, attr); 305 + u16 regval; 306 + u8 nr = sda->index; 307 + 308 + mutex_lock(&data->update_lock); 309 + regval = (data->reg[param->msb[0]] * asc7621_in_scaling[nr]) / 256; 310 + 311 + /* The LSB value is a 2-bit scaling of the MSB's LSbit value. 312 + * I.E. If the maximim voltage for this input is 6640 millivolts then 313 + * a MSB register value of 0 = 0mv and 255 = 6640mv. 314 + * A 1 step change therefore represents 25.9mv (6640 / 256). 315 + * The extra 2-bits therefore represent increments of 6.48mv. 316 + */ 317 + regval += ((asc7621_in_scaling[nr] / 256) / 4) * 318 + (data->reg[param->lsb[0]] >> 6); 319 + 320 + mutex_unlock(&data->update_lock); 321 + 322 + return sprintf(buf, "%u\n", regval); 323 + } 324 + 325 + /* 8 bit voltage values (the mins and maxs) */ 326 + static ssize_t show_in8(struct device *dev, struct device_attribute *attr, 327 + char *buf) 328 + { 329 + SETUP_SHOW_data_param(dev, attr); 330 + u8 nr = sda->index; 331 + 332 + return sprintf(buf, "%u\n", 333 + ((data->reg[param->msb[0]] * 334 + asc7621_in_scaling[nr]) / 256)); 335 + } 336 + 337 + static ssize_t store_in8(struct device *dev, struct device_attribute *attr, 338 + const char *buf, size_t count) 339 + { 340 + SETUP_STORE_data_param(dev, attr); 341 + long reqval; 342 + u8 nr = sda->index; 343 + 344 + if (strict_strtol(buf, 10, &reqval)) 345 + return -EINVAL; 346 + 347 + reqval = SENSORS_LIMIT(reqval, 0, asc7621_in_scaling[nr]); 348 + 349 + reqval = (reqval * 255 + 128) / asc7621_in_scaling[nr]; 350 + 351 + mutex_lock(&data->update_lock); 352 + data->reg[param->msb[0]] = reqval; 353 + write_byte(client, param->msb[0], reqval); 354 + mutex_unlock(&data->update_lock); 355 + 356 + return count; 357 + } 358 + 359 + static ssize_t show_temp8(struct device *dev, 360 + struct device_attribute *attr, char *buf) 361 + { 362 + SETUP_SHOW_data_param(dev, attr); 363 + 364 + return sprintf(buf, "%d\n", ((s8) data->reg[param->msb[0]]) * 1000); 365 + } 366 + 367 + static ssize_t store_temp8(struct device *dev, 368 + struct device_attribute *attr, const char *buf, 369 + size_t count) 370 + { 371 + SETUP_STORE_data_param(dev, attr); 372 + long reqval; 373 + s8 temp; 374 + 375 + if (strict_strtol(buf, 10, &reqval)) 376 + return -EINVAL; 377 + 378 + reqval = SENSORS_LIMIT(reqval, -127000, 127000); 379 + 380 + temp = reqval / 1000; 381 + 382 + mutex_lock(&data->update_lock); 383 + data->reg[param->msb[0]] = temp; 384 + write_byte(client, param->msb[0], temp); 385 + mutex_unlock(&data->update_lock); 386 + return count; 387 + } 388 + 389 + /* 390 + * Temperatures that occupy 2 bytes always have the whole 391 + * number of degrees in the MSB with some part of the LSB 392 + * indicating fractional degrees. 393 + */ 394 + 395 + /* mmmmmmmm.llxxxxxx */ 396 + static ssize_t show_temp10(struct device *dev, 397 + struct device_attribute *attr, char *buf) 398 + { 399 + SETUP_SHOW_data_param(dev, attr); 400 + u8 msb, lsb; 401 + int temp; 402 + 403 + mutex_lock(&data->update_lock); 404 + msb = data->reg[param->msb[0]]; 405 + lsb = (data->reg[param->lsb[0]] >> 6) & 0x03; 406 + temp = (((s8) msb) * 1000) + (lsb * 250); 407 + mutex_unlock(&data->update_lock); 408 + 409 + return sprintf(buf, "%d\n", temp); 410 + } 411 + 412 + /* mmmmmm.ll */ 413 + static ssize_t show_temp62(struct device *dev, 414 + struct device_attribute *attr, char *buf) 415 + { 416 + SETUP_SHOW_data_param(dev, attr); 417 + u8 regval = data->reg[param->msb[0]]; 418 + int temp = ((s8) (regval & 0xfc) * 1000) + ((regval & 0x03) * 250); 419 + 420 + return sprintf(buf, "%d\n", temp); 421 + } 422 + 423 + static ssize_t store_temp62(struct device *dev, 424 + struct device_attribute *attr, const char *buf, 425 + size_t count) 426 + { 427 + SETUP_STORE_data_param(dev, attr); 428 + long reqval, i, f; 429 + s8 temp; 430 + 431 + if (strict_strtol(buf, 10, &reqval)) 432 + return -EINVAL; 433 + 434 + reqval = SENSORS_LIMIT(reqval, -32000, 31750); 435 + i = reqval / 1000; 436 + f = reqval - (i * 1000); 437 + temp = i << 2; 438 + temp |= f / 250; 439 + 440 + mutex_lock(&data->update_lock); 441 + data->reg[param->msb[0]] = temp; 442 + write_byte(client, param->msb[0], temp); 443 + mutex_unlock(&data->update_lock); 444 + return count; 445 + } 446 + 447 + /* 448 + * The aSC7621 doesn't provide an "auto_point2". Instead, you 449 + * specify the auto_point1 and a range. To keep with the sysfs 450 + * hwmon specs, we synthesize the auto_point_2 from them. 451 + */ 452 + 453 + static u32 asc7621_range_map[] = { 454 + 2000, 2500, 3330, 4000, 5000, 6670, 8000, 10000, 455 + 13330, 16000, 20000, 26670, 32000, 40000, 53330, 80000, 456 + }; 457 + 458 + static ssize_t show_ap2_temp(struct device *dev, 459 + struct device_attribute *attr, char *buf) 460 + { 461 + SETUP_SHOW_data_param(dev, attr); 462 + long auto_point1; 463 + u8 regval; 464 + int temp; 465 + 466 + mutex_lock(&data->update_lock); 467 + auto_point1 = ((s8) data->reg[param->msb[1]]) * 1000; 468 + regval = 469 + ((data->reg[param->msb[0]] >> param->shift[0]) & param->mask[0]); 470 + temp = auto_point1 + asc7621_range_map[SENSORS_LIMIT(regval, 0, 15)]; 471 + mutex_unlock(&data->update_lock); 472 + 473 + return sprintf(buf, "%d\n", temp); 474 + 475 + } 476 + 477 + static ssize_t store_ap2_temp(struct device *dev, 478 + struct device_attribute *attr, 479 + const char *buf, size_t count) 480 + { 481 + SETUP_STORE_data_param(dev, attr); 482 + long reqval, auto_point1; 483 + int i; 484 + u8 currval, newval = 0; 485 + 486 + if (strict_strtol(buf, 10, &reqval)) 487 + return -EINVAL; 488 + 489 + mutex_lock(&data->update_lock); 490 + auto_point1 = data->reg[param->msb[1]] * 1000; 491 + reqval = SENSORS_LIMIT(reqval, auto_point1 + 2000, auto_point1 + 80000); 492 + 493 + for (i = ARRAY_SIZE(asc7621_range_map) - 1; i >= 0; i--) { 494 + if (reqval >= auto_point1 + asc7621_range_map[i]) { 495 + newval = i; 496 + break; 497 + } 498 + } 499 + 500 + newval = (newval & param->mask[0]) << param->shift[0]; 501 + currval = read_byte(client, param->msb[0]); 502 + newval |= (currval & ~(param->mask[0] << param->shift[0])); 503 + data->reg[param->msb[0]] = newval; 504 + write_byte(client, param->msb[0], newval); 505 + mutex_unlock(&data->update_lock); 506 + return count; 507 + } 508 + 509 + static ssize_t show_pwm_ac(struct device *dev, 510 + struct device_attribute *attr, char *buf) 511 + { 512 + SETUP_SHOW_data_param(dev, attr); 513 + u8 config, altbit, regval; 514 + u8 map[] = { 515 + 0x01, 0x02, 0x04, 0x1f, 0x00, 0x06, 0x07, 0x10, 516 + 0x08, 0x0f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f 517 + }; 518 + 519 + mutex_lock(&data->update_lock); 520 + config = (data->reg[param->msb[0]] >> param->shift[0]) & param->mask[0]; 521 + altbit = (data->reg[param->msb[1]] >> param->shift[1]) & param->mask[1]; 522 + regval = config | (altbit << 3); 523 + mutex_unlock(&data->update_lock); 524 + 525 + return sprintf(buf, "%u\n", map[SENSORS_LIMIT(regval, 0, 15)]); 526 + } 527 + 528 + static ssize_t store_pwm_ac(struct device *dev, 529 + struct device_attribute *attr, 530 + const char *buf, size_t count) 531 + { 532 + SETUP_STORE_data_param(dev, attr); 533 + unsigned long reqval; 534 + u8 currval, config, altbit, newval; 535 + u16 map[] = { 536 + 0x04, 0x00, 0x01, 0xff, 0x02, 0xff, 0x05, 0x06, 537 + 0x08, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x0f, 538 + 0x07, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 539 + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x03, 540 + }; 541 + 542 + if (strict_strtoul(buf, 10, &reqval)) 543 + return -EINVAL; 544 + 545 + if (reqval > 31) 546 + return -EINVAL; 547 + 548 + reqval = map[reqval]; 549 + if (reqval == 0xff) 550 + return -EINVAL; 551 + 552 + config = reqval & 0x07; 553 + altbit = (reqval >> 3) & 0x01; 554 + 555 + config = (config & param->mask[0]) << param->shift[0]; 556 + altbit = (altbit & param->mask[1]) << param->shift[1]; 557 + 558 + mutex_lock(&data->update_lock); 559 + currval = read_byte(client, param->msb[0]); 560 + newval = config | (currval & ~(param->mask[0] << param->shift[0])); 561 + newval = altbit | (newval & ~(param->mask[1] << param->shift[1])); 562 + data->reg[param->msb[0]] = newval; 563 + write_byte(client, param->msb[0], newval); 564 + mutex_unlock(&data->update_lock); 565 + return count; 566 + } 567 + 568 + static ssize_t show_pwm_enable(struct device *dev, 569 + struct device_attribute *attr, char *buf) 570 + { 571 + SETUP_SHOW_data_param(dev, attr); 572 + u8 config, altbit, minoff, val, newval; 573 + 574 + mutex_lock(&data->update_lock); 575 + config = (data->reg[param->msb[0]] >> param->shift[0]) & param->mask[0]; 576 + altbit = (data->reg[param->msb[1]] >> param->shift[1]) & param->mask[1]; 577 + minoff = (data->reg[param->msb[2]] >> param->shift[2]) & param->mask[2]; 578 + mutex_unlock(&data->update_lock); 579 + 580 + val = config | (altbit << 3); 581 + newval = 0; 582 + 583 + if (val == 3 || val >= 10) 584 + newval = 255; 585 + else if (val == 4) 586 + newval = 0; 587 + else if (val == 7) 588 + newval = 1; 589 + else if (minoff == 1) 590 + newval = 2; 591 + else 592 + newval = 3; 593 + 594 + return sprintf(buf, "%u\n", newval); 595 + } 596 + 597 + static ssize_t store_pwm_enable(struct device *dev, 598 + struct device_attribute *attr, 599 + const char *buf, size_t count) 600 + { 601 + SETUP_STORE_data_param(dev, attr); 602 + long reqval; 603 + u8 currval, config, altbit, newval, minoff = 255; 604 + 605 + if (strict_strtol(buf, 10, &reqval)) 606 + return -EINVAL; 607 + 608 + switch (reqval) { 609 + case 0: 610 + newval = 0x04; 611 + break; 612 + case 1: 613 + newval = 0x07; 614 + break; 615 + case 2: 616 + newval = 0x00; 617 + minoff = 1; 618 + break; 619 + case 3: 620 + newval = 0x00; 621 + minoff = 0; 622 + break; 623 + case 255: 624 + newval = 0x03; 625 + break; 626 + default: 627 + return -EINVAL; 628 + } 629 + 630 + config = newval & 0x07; 631 + altbit = (newval >> 3) & 0x01; 632 + 633 + mutex_lock(&data->update_lock); 634 + config = (config & param->mask[0]) << param->shift[0]; 635 + altbit = (altbit & param->mask[1]) << param->shift[1]; 636 + currval = read_byte(client, param->msb[0]); 637 + newval = config | (currval & ~(param->mask[0] << param->shift[0])); 638 + newval = altbit | (newval & ~(param->mask[1] << param->shift[1])); 639 + data->reg[param->msb[0]] = newval; 640 + write_byte(client, param->msb[0], newval); 641 + if (minoff < 255) { 642 + minoff = (minoff & param->mask[2]) << param->shift[2]; 643 + currval = read_byte(client, param->msb[2]); 644 + newval = 645 + minoff | (currval & ~(param->mask[2] << param->shift[2])); 646 + data->reg[param->msb[2]] = newval; 647 + write_byte(client, param->msb[2], newval); 648 + } 649 + mutex_unlock(&data->update_lock); 650 + return count; 651 + } 652 + 653 + static u32 asc7621_pwm_freq_map[] = { 654 + 10, 15, 23, 30, 38, 47, 62, 94, 655 + 23000, 24000, 25000, 26000, 27000, 28000, 29000, 30000 656 + }; 657 + 658 + static ssize_t show_pwm_freq(struct device *dev, 659 + struct device_attribute *attr, char *buf) 660 + { 661 + SETUP_SHOW_data_param(dev, attr); 662 + u8 regval = 663 + (data->reg[param->msb[0]] >> param->shift[0]) & param->mask[0]; 664 + 665 + regval = SENSORS_LIMIT(regval, 0, 15); 666 + 667 + return sprintf(buf, "%u\n", asc7621_pwm_freq_map[regval]); 668 + } 669 + 670 + static ssize_t store_pwm_freq(struct device *dev, 671 + struct device_attribute *attr, 672 + const char *buf, size_t count) 673 + { 674 + SETUP_STORE_data_param(dev, attr); 675 + unsigned long reqval; 676 + u8 currval, newval = 255; 677 + int i; 678 + 679 + if (strict_strtoul(buf, 10, &reqval)) 680 + return -EINVAL; 681 + 682 + for (i = 0; i < ARRAY_SIZE(asc7621_pwm_freq_map); i++) { 683 + if (reqval == asc7621_pwm_freq_map[i]) { 684 + newval = i; 685 + break; 686 + } 687 + } 688 + if (newval == 255) 689 + return -EINVAL; 690 + 691 + newval = (newval & param->mask[0]) << param->shift[0]; 692 + 693 + mutex_lock(&data->update_lock); 694 + currval = read_byte(client, param->msb[0]); 695 + newval |= (currval & ~(param->mask[0] << param->shift[0])); 696 + data->reg[param->msb[0]] = newval; 697 + write_byte(client, param->msb[0], newval); 698 + mutex_unlock(&data->update_lock); 699 + return count; 700 + } 701 + 702 + static u32 asc7621_pwm_auto_spinup_map[] = { 703 + 0, 100, 250, 400, 700, 1000, 2000, 4000 704 + }; 705 + 706 + static ssize_t show_pwm_ast(struct device *dev, 707 + struct device_attribute *attr, char *buf) 708 + { 709 + SETUP_SHOW_data_param(dev, attr); 710 + u8 regval = 711 + (data->reg[param->msb[0]] >> param->shift[0]) & param->mask[0]; 712 + 713 + regval = SENSORS_LIMIT(regval, 0, 7); 714 + 715 + return sprintf(buf, "%u\n", asc7621_pwm_auto_spinup_map[regval]); 716 + 717 + } 718 + 719 + static ssize_t store_pwm_ast(struct device *dev, 720 + struct device_attribute *attr, 721 + const char *buf, size_t count) 722 + { 723 + SETUP_STORE_data_param(dev, attr); 724 + long reqval; 725 + u8 currval, newval = 255; 726 + u32 i; 727 + 728 + if (strict_strtol(buf, 10, &reqval)) 729 + return -EINVAL; 730 + 731 + for (i = 0; i < ARRAY_SIZE(asc7621_pwm_auto_spinup_map); i++) { 732 + if (reqval == asc7621_pwm_auto_spinup_map[i]) { 733 + newval = i; 734 + break; 735 + } 736 + } 737 + if (newval == 255) 738 + return -EINVAL; 739 + 740 + newval = (newval & param->mask[0]) << param->shift[0]; 741 + 742 + mutex_lock(&data->update_lock); 743 + currval = read_byte(client, param->msb[0]); 744 + newval |= (currval & ~(param->mask[0] << param->shift[0])); 745 + data->reg[param->msb[0]] = newval; 746 + write_byte(client, param->msb[0], newval); 747 + mutex_unlock(&data->update_lock); 748 + return count; 749 + } 750 + 751 + static u32 asc7621_temp_smoothing_time_map[] = { 752 + 35000, 17600, 11800, 7000, 4400, 3000, 1600, 800 753 + }; 754 + 755 + static ssize_t show_temp_st(struct device *dev, 756 + struct device_attribute *attr, char *buf) 757 + { 758 + SETUP_SHOW_data_param(dev, attr); 759 + u8 regval = 760 + (data->reg[param->msb[0]] >> param->shift[0]) & param->mask[0]; 761 + regval = SENSORS_LIMIT(regval, 0, 7); 762 + 763 + return sprintf(buf, "%u\n", asc7621_temp_smoothing_time_map[regval]); 764 + } 765 + 766 + static ssize_t store_temp_st(struct device *dev, 767 + struct device_attribute *attr, 768 + const char *buf, size_t count) 769 + { 770 + SETUP_STORE_data_param(dev, attr); 771 + long reqval; 772 + u8 currval, newval = 255; 773 + u32 i; 774 + 775 + if (strict_strtol(buf, 10, &reqval)) 776 + return -EINVAL; 777 + 778 + for (i = 0; i < ARRAY_SIZE(asc7621_temp_smoothing_time_map); i++) { 779 + if (reqval == asc7621_temp_smoothing_time_map[i]) { 780 + newval = i; 781 + break; 782 + } 783 + } 784 + 785 + if (newval == 255) 786 + return -EINVAL; 787 + 788 + newval = (newval & param->mask[0]) << param->shift[0]; 789 + 790 + mutex_lock(&data->update_lock); 791 + currval = read_byte(client, param->msb[0]); 792 + newval |= (currval & ~(param->mask[0] << param->shift[0])); 793 + data->reg[param->msb[0]] = newval; 794 + write_byte(client, param->msb[0], newval); 795 + mutex_unlock(&data->update_lock); 796 + return count; 797 + } 798 + 799 + /* 800 + * End of data handlers 801 + * 802 + * These defines do nothing more than make the table easier 803 + * to read when wrapped at column 80. 804 + */ 805 + 806 + /* 807 + * Creates a variable length array inititalizer. 808 + * VAA(1,3,5,7) would produce {1,3,5,7} 809 + */ 810 + #define VAA(args...) {args} 811 + 812 + #define PREAD(name, n, pri, rm, rl, m, s, r) \ 813 + {.sda = SENSOR_ATTR(name, S_IRUGO, show_##r, NULL, n), \ 814 + .priority = pri, .msb[0] = rm, .lsb[0] = rl, .mask[0] = m, \ 815 + .shift[0] = s,} 816 + 817 + #define PWRITE(name, n, pri, rm, rl, m, s, r) \ 818 + {.sda = SENSOR_ATTR(name, S_IRUGO | S_IWUSR, show_##r, store_##r, n), \ 819 + .priority = pri, .msb[0] = rm, .lsb[0] = rl, .mask[0] = m, \ 820 + .shift[0] = s,} 821 + 822 + /* 823 + * PWRITEM assumes that the initializers for the .msb, .lsb, .mask and .shift 824 + * were created using the VAA macro. 825 + */ 826 + #define PWRITEM(name, n, pri, rm, rl, m, s, r) \ 827 + {.sda = SENSOR_ATTR(name, S_IRUGO | S_IWUSR, show_##r, store_##r, n), \ 828 + .priority = pri, .msb = rm, .lsb = rl, .mask = m, .shift = s,} 829 + 830 + static struct asc7621_param asc7621_params[] = { 831 + PREAD(in0_input, 0, PRI_HIGH, 0x20, 0x13, 0, 0, in10), 832 + PREAD(in1_input, 1, PRI_HIGH, 0x21, 0x18, 0, 0, in10), 833 + PREAD(in2_input, 2, PRI_HIGH, 0x22, 0x11, 0, 0, in10), 834 + PREAD(in3_input, 3, PRI_HIGH, 0x23, 0x12, 0, 0, in10), 835 + PREAD(in4_input, 4, PRI_HIGH, 0x24, 0x14, 0, 0, in10), 836 + 837 + PWRITE(in0_min, 0, PRI_LOW, 0x44, 0, 0, 0, in8), 838 + PWRITE(in1_min, 1, PRI_LOW, 0x46, 0, 0, 0, in8), 839 + PWRITE(in2_min, 2, PRI_LOW, 0x48, 0, 0, 0, in8), 840 + PWRITE(in3_min, 3, PRI_LOW, 0x4a, 0, 0, 0, in8), 841 + PWRITE(in4_min, 4, PRI_LOW, 0x4c, 0, 0, 0, in8), 842 + 843 + PWRITE(in0_max, 0, PRI_LOW, 0x45, 0, 0, 0, in8), 844 + PWRITE(in1_max, 1, PRI_LOW, 0x47, 0, 0, 0, in8), 845 + PWRITE(in2_max, 2, PRI_LOW, 0x49, 0, 0, 0, in8), 846 + PWRITE(in3_max, 3, PRI_LOW, 0x4b, 0, 0, 0, in8), 847 + PWRITE(in4_max, 4, PRI_LOW, 0x4d, 0, 0, 0, in8), 848 + 849 + PREAD(in0_alarm, 0, PRI_LOW, 0x41, 0, 0x01, 0, bitmask), 850 + PREAD(in1_alarm, 1, PRI_LOW, 0x41, 0, 0x01, 1, bitmask), 851 + PREAD(in2_alarm, 2, PRI_LOW, 0x41, 0, 0x01, 2, bitmask), 852 + PREAD(in3_alarm, 3, PRI_LOW, 0x41, 0, 0x01, 3, bitmask), 853 + PREAD(in4_alarm, 4, PRI_LOW, 0x42, 0, 0x01, 0, bitmask), 854 + 855 + PREAD(fan1_input, 0, PRI_HIGH, 0x29, 0x28, 0, 0, fan16), 856 + PREAD(fan2_input, 1, PRI_HIGH, 0x2b, 0x2a, 0, 0, fan16), 857 + PREAD(fan3_input, 2, PRI_HIGH, 0x2d, 0x2c, 0, 0, fan16), 858 + PREAD(fan4_input, 3, PRI_HIGH, 0x2f, 0x2e, 0, 0, fan16), 859 + 860 + PWRITE(fan1_min, 0, PRI_LOW, 0x55, 0x54, 0, 0, fan16), 861 + PWRITE(fan2_min, 1, PRI_LOW, 0x57, 0x56, 0, 0, fan16), 862 + PWRITE(fan3_min, 2, PRI_LOW, 0x59, 0x58, 0, 0, fan16), 863 + PWRITE(fan4_min, 3, PRI_LOW, 0x5b, 0x5a, 0, 0, fan16), 864 + 865 + PREAD(fan1_alarm, 0, PRI_LOW, 0x42, 0, 0x01, 0, bitmask), 866 + PREAD(fan2_alarm, 1, PRI_LOW, 0x42, 0, 0x01, 1, bitmask), 867 + PREAD(fan3_alarm, 2, PRI_LOW, 0x42, 0, 0x01, 2, bitmask), 868 + PREAD(fan4_alarm, 3, PRI_LOW, 0x42, 0, 0x01, 3, bitmask), 869 + 870 + PREAD(temp1_input, 0, PRI_HIGH, 0x25, 0x10, 0, 0, temp10), 871 + PREAD(temp2_input, 1, PRI_HIGH, 0x26, 0x15, 0, 0, temp10), 872 + PREAD(temp3_input, 2, PRI_HIGH, 0x27, 0x16, 0, 0, temp10), 873 + PREAD(temp4_input, 3, PRI_HIGH, 0x33, 0x17, 0, 0, temp10), 874 + PREAD(temp5_input, 4, PRI_HIGH, 0xf7, 0xf6, 0, 0, temp10), 875 + PREAD(temp6_input, 5, PRI_HIGH, 0xf9, 0xf8, 0, 0, temp10), 876 + PREAD(temp7_input, 6, PRI_HIGH, 0xfb, 0xfa, 0, 0, temp10), 877 + PREAD(temp8_input, 7, PRI_HIGH, 0xfd, 0xfc, 0, 0, temp10), 878 + 879 + PWRITE(temp1_min, 0, PRI_LOW, 0x4e, 0, 0, 0, temp8), 880 + PWRITE(temp2_min, 1, PRI_LOW, 0x50, 0, 0, 0, temp8), 881 + PWRITE(temp3_min, 2, PRI_LOW, 0x52, 0, 0, 0, temp8), 882 + PWRITE(temp4_min, 3, PRI_LOW, 0x34, 0, 0, 0, temp8), 883 + 884 + PWRITE(temp1_max, 0, PRI_LOW, 0x4f, 0, 0, 0, temp8), 885 + PWRITE(temp2_max, 1, PRI_LOW, 0x51, 0, 0, 0, temp8), 886 + PWRITE(temp3_max, 2, PRI_LOW, 0x53, 0, 0, 0, temp8), 887 + PWRITE(temp4_max, 3, PRI_LOW, 0x35, 0, 0, 0, temp8), 888 + 889 + PREAD(temp1_alarm, 0, PRI_LOW, 0x41, 0, 0x01, 4, bitmask), 890 + PREAD(temp2_alarm, 1, PRI_LOW, 0x41, 0, 0x01, 5, bitmask), 891 + PREAD(temp3_alarm, 2, PRI_LOW, 0x41, 0, 0x01, 6, bitmask), 892 + PREAD(temp4_alarm, 3, PRI_LOW, 0x43, 0, 0x01, 0, bitmask), 893 + 894 + PWRITE(temp1_source, 0, PRI_LOW, 0x02, 0, 0x07, 4, bitmask), 895 + PWRITE(temp2_source, 1, PRI_LOW, 0x02, 0, 0x07, 0, bitmask), 896 + PWRITE(temp3_source, 2, PRI_LOW, 0x03, 0, 0x07, 4, bitmask), 897 + PWRITE(temp4_source, 3, PRI_LOW, 0x03, 0, 0x07, 0, bitmask), 898 + 899 + PWRITE(temp1_smoothing_enable, 0, PRI_LOW, 0x62, 0, 0x01, 3, bitmask), 900 + PWRITE(temp2_smoothing_enable, 1, PRI_LOW, 0x63, 0, 0x01, 7, bitmask), 901 + PWRITE(temp3_smoothing_enable, 2, PRI_LOW, 0x64, 0, 0x01, 3, bitmask), 902 + PWRITE(temp4_smoothing_enable, 3, PRI_LOW, 0x3c, 0, 0x01, 3, bitmask), 903 + 904 + PWRITE(temp1_smoothing_time, 0, PRI_LOW, 0x62, 0, 0x07, 0, temp_st), 905 + PWRITE(temp2_smoothing_time, 1, PRI_LOW, 0x63, 0, 0x07, 4, temp_st), 906 + PWRITE(temp3_smoothing_time, 2, PRI_LOW, 0x63, 0, 0x07, 0, temp_st), 907 + PWRITE(temp4_smoothing_time, 3, PRI_LOW, 0x3c, 0, 0x07, 0, temp_st), 908 + 909 + PWRITE(temp1_auto_point1_temp_hyst, 0, PRI_LOW, 0x6d, 0, 0x0f, 4, 910 + bitmask), 911 + PWRITE(temp2_auto_point1_temp_hyst, 1, PRI_LOW, 0x6d, 0, 0x0f, 0, 912 + bitmask), 913 + PWRITE(temp3_auto_point1_temp_hyst, 2, PRI_LOW, 0x6e, 0, 0x0f, 4, 914 + bitmask), 915 + PWRITE(temp4_auto_point1_temp_hyst, 3, PRI_LOW, 0x6e, 0, 0x0f, 0, 916 + bitmask), 917 + 918 + PREAD(temp1_auto_point2_temp_hyst, 0, PRI_LOW, 0x6d, 0, 0x0f, 4, 919 + bitmask), 920 + PREAD(temp2_auto_point2_temp_hyst, 1, PRI_LOW, 0x6d, 0, 0x0f, 0, 921 + bitmask), 922 + PREAD(temp3_auto_point2_temp_hyst, 2, PRI_LOW, 0x6e, 0, 0x0f, 4, 923 + bitmask), 924 + PREAD(temp4_auto_point2_temp_hyst, 3, PRI_LOW, 0x6e, 0, 0x0f, 0, 925 + bitmask), 926 + 927 + PWRITE(temp1_auto_point1_temp, 0, PRI_LOW, 0x67, 0, 0, 0, temp8), 928 + PWRITE(temp2_auto_point1_temp, 1, PRI_LOW, 0x68, 0, 0, 0, temp8), 929 + PWRITE(temp3_auto_point1_temp, 2, PRI_LOW, 0x69, 0, 0, 0, temp8), 930 + PWRITE(temp4_auto_point1_temp, 3, PRI_LOW, 0x3b, 0, 0, 0, temp8), 931 + 932 + PWRITEM(temp1_auto_point2_temp, 0, PRI_LOW, VAA(0x5f, 0x67), VAA(0), 933 + VAA(0x0f), VAA(4), ap2_temp), 934 + PWRITEM(temp2_auto_point2_temp, 1, PRI_LOW, VAA(0x60, 0x68), VAA(0), 935 + VAA(0x0f), VAA(4), ap2_temp), 936 + PWRITEM(temp3_auto_point2_temp, 2, PRI_LOW, VAA(0x61, 0x69), VAA(0), 937 + VAA(0x0f), VAA(4), ap2_temp), 938 + PWRITEM(temp4_auto_point2_temp, 3, PRI_LOW, VAA(0x3c, 0x3b), VAA(0), 939 + VAA(0x0f), VAA(4), ap2_temp), 940 + 941 + PWRITE(temp1_crit, 0, PRI_LOW, 0x6a, 0, 0, 0, temp8), 942 + PWRITE(temp2_crit, 1, PRI_LOW, 0x6b, 0, 0, 0, temp8), 943 + PWRITE(temp3_crit, 2, PRI_LOW, 0x6c, 0, 0, 0, temp8), 944 + PWRITE(temp4_crit, 3, PRI_LOW, 0x3d, 0, 0, 0, temp8), 945 + 946 + PWRITE(temp5_enable, 4, PRI_LOW, 0x0e, 0, 0x01, 0, bitmask), 947 + PWRITE(temp6_enable, 5, PRI_LOW, 0x0e, 0, 0x01, 1, bitmask), 948 + PWRITE(temp7_enable, 6, PRI_LOW, 0x0e, 0, 0x01, 2, bitmask), 949 + PWRITE(temp8_enable, 7, PRI_LOW, 0x0e, 0, 0x01, 3, bitmask), 950 + 951 + PWRITE(remote1_offset, 0, PRI_LOW, 0x1c, 0, 0, 0, temp62), 952 + PWRITE(remote2_offset, 1, PRI_LOW, 0x1d, 0, 0, 0, temp62), 953 + 954 + PWRITE(pwm1, 0, PRI_HIGH, 0x30, 0, 0, 0, u8), 955 + PWRITE(pwm2, 1, PRI_HIGH, 0x31, 0, 0, 0, u8), 956 + PWRITE(pwm3, 2, PRI_HIGH, 0x32, 0, 0, 0, u8), 957 + 958 + PWRITE(pwm1_invert, 0, PRI_LOW, 0x5c, 0, 0x01, 4, bitmask), 959 + PWRITE(pwm2_invert, 1, PRI_LOW, 0x5d, 0, 0x01, 4, bitmask), 960 + PWRITE(pwm3_invert, 2, PRI_LOW, 0x5e, 0, 0x01, 4, bitmask), 961 + 962 + PWRITEM(pwm1_enable, 0, PRI_LOW, VAA(0x5c, 0x5c, 0x62), VAA(0, 0, 0), 963 + VAA(0x07, 0x01, 0x01), VAA(5, 3, 5), pwm_enable), 964 + PWRITEM(pwm2_enable, 1, PRI_LOW, VAA(0x5d, 0x5d, 0x62), VAA(0, 0, 0), 965 + VAA(0x07, 0x01, 0x01), VAA(5, 3, 6), pwm_enable), 966 + PWRITEM(pwm3_enable, 2, PRI_LOW, VAA(0x5e, 0x5e, 0x62), VAA(0, 0, 0), 967 + VAA(0x07, 0x01, 0x01), VAA(5, 3, 7), pwm_enable), 968 + 969 + PWRITEM(pwm1_auto_channels, 0, PRI_LOW, VAA(0x5c, 0x5c), VAA(0, 0), 970 + VAA(0x07, 0x01), VAA(5, 3), pwm_ac), 971 + PWRITEM(pwm2_auto_channels, 1, PRI_LOW, VAA(0x5d, 0x5d), VAA(0, 0), 972 + VAA(0x07, 0x01), VAA(5, 3), pwm_ac), 973 + PWRITEM(pwm3_auto_channels, 2, PRI_LOW, VAA(0x5e, 0x5e), VAA(0, 0), 974 + VAA(0x07, 0x01), VAA(5, 3), pwm_ac), 975 + 976 + PWRITE(pwm1_auto_point1_pwm, 0, PRI_LOW, 0x64, 0, 0, 0, u8), 977 + PWRITE(pwm2_auto_point1_pwm, 1, PRI_LOW, 0x65, 0, 0, 0, u8), 978 + PWRITE(pwm3_auto_point1_pwm, 2, PRI_LOW, 0x66, 0, 0, 0, u8), 979 + 980 + PWRITE(pwm1_auto_point2_pwm, 0, PRI_LOW, 0x38, 0, 0, 0, u8), 981 + PWRITE(pwm2_auto_point2_pwm, 1, PRI_LOW, 0x39, 0, 0, 0, u8), 982 + PWRITE(pwm3_auto_point2_pwm, 2, PRI_LOW, 0x3a, 0, 0, 0, u8), 983 + 984 + PWRITE(pwm1_freq, 0, PRI_LOW, 0x5f, 0, 0x0f, 0, pwm_freq), 985 + PWRITE(pwm2_freq, 1, PRI_LOW, 0x60, 0, 0x0f, 0, pwm_freq), 986 + PWRITE(pwm3_freq, 2, PRI_LOW, 0x61, 0, 0x0f, 0, pwm_freq), 987 + 988 + PREAD(pwm1_auto_zone_assigned, 0, PRI_LOW, 0, 0, 0x03, 2, bitmask), 989 + PREAD(pwm2_auto_zone_assigned, 1, PRI_LOW, 0, 0, 0x03, 4, bitmask), 990 + PREAD(pwm3_auto_zone_assigned, 2, PRI_LOW, 0, 0, 0x03, 6, bitmask), 991 + 992 + PWRITE(pwm1_auto_spinup_time, 0, PRI_LOW, 0x5c, 0, 0x07, 0, pwm_ast), 993 + PWRITE(pwm2_auto_spinup_time, 1, PRI_LOW, 0x5d, 0, 0x07, 0, pwm_ast), 994 + PWRITE(pwm3_auto_spinup_time, 2, PRI_LOW, 0x5e, 0, 0x07, 0, pwm_ast), 995 + 996 + PWRITE(peci_enable, 0, PRI_LOW, 0x40, 0, 0x01, 4, bitmask), 997 + PWRITE(peci_avg, 0, PRI_LOW, 0x36, 0, 0x07, 0, bitmask), 998 + PWRITE(peci_domain, 0, PRI_LOW, 0x36, 0, 0x01, 3, bitmask), 999 + PWRITE(peci_legacy, 0, PRI_LOW, 0x36, 0, 0x01, 4, bitmask), 1000 + PWRITE(peci_diode, 0, PRI_LOW, 0x0e, 0, 0x07, 4, bitmask), 1001 + PWRITE(peci_4domain, 0, PRI_LOW, 0x0e, 0, 0x01, 4, bitmask), 1002 + 1003 + }; 1004 + 1005 + static struct asc7621_data *asc7621_update_device(struct device *dev) 1006 + { 1007 + struct i2c_client *client = to_i2c_client(dev); 1008 + struct asc7621_data *data = i2c_get_clientdata(client); 1009 + int i; 1010 + 1011 + /* 1012 + * The asc7621 chips guarantee consistent reads of multi-byte values 1013 + * regardless of the order of the reads. No special logic is needed 1014 + * so we can just read the registers in whatever order they appear 1015 + * in the asc7621_params array. 1016 + */ 1017 + 1018 + mutex_lock(&data->update_lock); 1019 + 1020 + /* Read all the high priority registers */ 1021 + 1022 + if (!data->valid || 1023 + time_after(jiffies, data->last_high_reading + INTERVAL_HIGH)) { 1024 + 1025 + for (i = 0; i < ARRAY_SIZE(asc7621_register_priorities); i++) { 1026 + if (asc7621_register_priorities[i] == PRI_HIGH) { 1027 + data->reg[i] = 1028 + i2c_smbus_read_byte_data(client, i) & 0xff; 1029 + } 1030 + } 1031 + data->last_high_reading = jiffies; 1032 + }; /* last_reading */ 1033 + 1034 + /* Read all the low priority registers. */ 1035 + 1036 + if (!data->valid || 1037 + time_after(jiffies, data->last_low_reading + INTERVAL_LOW)) { 1038 + 1039 + for (i = 0; i < ARRAY_SIZE(asc7621_params); i++) { 1040 + if (asc7621_register_priorities[i] == PRI_LOW) { 1041 + data->reg[i] = 1042 + i2c_smbus_read_byte_data(client, i) & 0xff; 1043 + } 1044 + } 1045 + data->last_low_reading = jiffies; 1046 + }; /* last_reading */ 1047 + 1048 + data->valid = 1; 1049 + 1050 + mutex_unlock(&data->update_lock); 1051 + 1052 + return data; 1053 + } 1054 + 1055 + /* 1056 + * Standard detection and initialization below 1057 + * 1058 + * Helper function that checks if an address is valid 1059 + * for a particular chip. 1060 + */ 1061 + 1062 + static inline int valid_address_for_chip(int chip_type, int address) 1063 + { 1064 + int i; 1065 + 1066 + for (i = 0; asc7621_chips[chip_type].addresses[i] != I2C_CLIENT_END; 1067 + i++) { 1068 + if (asc7621_chips[chip_type].addresses[i] == address) 1069 + return 1; 1070 + } 1071 + return 0; 1072 + } 1073 + 1074 + static void asc7621_init_client(struct i2c_client *client) 1075 + { 1076 + int value; 1077 + 1078 + /* Warn if part was not "READY" */ 1079 + 1080 + value = read_byte(client, 0x40); 1081 + 1082 + if (value & 0x02) { 1083 + dev_err(&client->dev, 1084 + "Client (%d,0x%02x) config is locked.\n", 1085 + i2c_adapter_id(client->adapter), client->addr); 1086 + }; 1087 + if (!(value & 0x04)) { 1088 + dev_err(&client->dev, "Client (%d,0x%02x) is not ready.\n", 1089 + i2c_adapter_id(client->adapter), client->addr); 1090 + }; 1091 + 1092 + /* 1093 + * Start monitoring 1094 + * 1095 + * Try to clear LOCK, Set START, save everything else 1096 + */ 1097 + value = (value & ~0x02) | 0x01; 1098 + write_byte(client, 0x40, value & 0xff); 1099 + 1100 + } 1101 + 1102 + static int 1103 + asc7621_probe(struct i2c_client *client, const struct i2c_device_id *id) 1104 + { 1105 + struct asc7621_data *data; 1106 + int i, err; 1107 + 1108 + if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA)) 1109 + return -EIO; 1110 + 1111 + data = kzalloc(sizeof(struct asc7621_data), GFP_KERNEL); 1112 + if (data == NULL) 1113 + return -ENOMEM; 1114 + 1115 + i2c_set_clientdata(client, data); 1116 + data->valid = 0; 1117 + mutex_init(&data->update_lock); 1118 + 1119 + /* Initialize the asc7621 chip */ 1120 + asc7621_init_client(client); 1121 + 1122 + /* Create the sysfs entries */ 1123 + for (i = 0; i < ARRAY_SIZE(asc7621_params); i++) { 1124 + err = 1125 + device_create_file(&client->dev, 1126 + &(asc7621_params[i].sda.dev_attr)); 1127 + if (err) 1128 + goto exit_remove; 1129 + } 1130 + 1131 + data->class_dev = hwmon_device_register(&client->dev); 1132 + if (IS_ERR(data->class_dev)) { 1133 + err = PTR_ERR(data->class_dev); 1134 + goto exit_remove; 1135 + } 1136 + 1137 + return 0; 1138 + 1139 + exit_remove: 1140 + for (i = 0; i < ARRAY_SIZE(asc7621_params); i++) { 1141 + device_remove_file(&client->dev, 1142 + &(asc7621_params[i].sda.dev_attr)); 1143 + } 1144 + 1145 + i2c_set_clientdata(client, NULL); 1146 + kfree(data); 1147 + return err; 1148 + } 1149 + 1150 + static int asc7621_detect(struct i2c_client *client, 1151 + struct i2c_board_info *info) 1152 + { 1153 + struct i2c_adapter *adapter = client->adapter; 1154 + int company, verstep, chip_index; 1155 + struct device *dev; 1156 + 1157 + dev = &client->dev; 1158 + 1159 + if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) 1160 + return -ENODEV; 1161 + 1162 + for (chip_index = FIRST_CHIP; chip_index <= LAST_CHIP; chip_index++) { 1163 + 1164 + if (!valid_address_for_chip(chip_index, client->addr)) 1165 + continue; 1166 + 1167 + company = read_byte(client, 1168 + asc7621_chips[chip_index].company_reg); 1169 + verstep = read_byte(client, 1170 + asc7621_chips[chip_index].verstep_reg); 1171 + 1172 + if (company == asc7621_chips[chip_index].company_id && 1173 + verstep == asc7621_chips[chip_index].verstep_id) { 1174 + strlcpy(client->name, asc7621_chips[chip_index].name, 1175 + I2C_NAME_SIZE); 1176 + strlcpy(info->type, asc7621_chips[chip_index].name, 1177 + I2C_NAME_SIZE); 1178 + 1179 + dev_info(&adapter->dev, "Matched %s\n", 1180 + asc7621_chips[chip_index].name); 1181 + return 0; 1182 + } 1183 + } 1184 + 1185 + return -ENODEV; 1186 + } 1187 + 1188 + static int asc7621_remove(struct i2c_client *client) 1189 + { 1190 + struct asc7621_data *data = i2c_get_clientdata(client); 1191 + int i; 1192 + 1193 + hwmon_device_unregister(data->class_dev); 1194 + 1195 + for (i = 0; i < ARRAY_SIZE(asc7621_params); i++) { 1196 + device_remove_file(&client->dev, 1197 + &(asc7621_params[i].sda.dev_attr)); 1198 + } 1199 + 1200 + i2c_set_clientdata(client, NULL); 1201 + kfree(data); 1202 + return 0; 1203 + } 1204 + 1205 + static const struct i2c_device_id asc7621_id[] = { 1206 + {"asc7621", asc7621}, 1207 + {"asc7621a", asc7621a}, 1208 + {}, 1209 + }; 1210 + 1211 + MODULE_DEVICE_TABLE(i2c, asc7621_id); 1212 + 1213 + static struct i2c_driver asc7621_driver = { 1214 + .class = I2C_CLASS_HWMON, 1215 + .driver = { 1216 + .name = "asc7621", 1217 + }, 1218 + .probe = asc7621_probe, 1219 + .remove = asc7621_remove, 1220 + .id_table = asc7621_id, 1221 + .detect = asc7621_detect, 1222 + .address_list = normal_i2c, 1223 + }; 1224 + 1225 + static int __init sm_asc7621_init(void) 1226 + { 1227 + int i, j; 1228 + /* 1229 + * Collect all the registers needed into a single array. 1230 + * This way, if a register isn't actually used for anything, 1231 + * we don't retrieve it. 1232 + */ 1233 + 1234 + for (i = 0; i < ARRAY_SIZE(asc7621_params); i++) { 1235 + for (j = 0; j < ARRAY_SIZE(asc7621_params[i].msb); j++) 1236 + asc7621_register_priorities[asc7621_params[i].msb[j]] = 1237 + asc7621_params[i].priority; 1238 + for (j = 0; j < ARRAY_SIZE(asc7621_params[i].lsb); j++) 1239 + asc7621_register_priorities[asc7621_params[i].lsb[j]] = 1240 + asc7621_params[i].priority; 1241 + } 1242 + return i2c_add_driver(&asc7621_driver); 1243 + } 1244 + 1245 + static void __exit sm_asc7621_exit(void) 1246 + { 1247 + i2c_del_driver(&asc7621_driver); 1248 + } 1249 + 1250 + MODULE_LICENSE("GPL"); 1251 + MODULE_AUTHOR("George Joseph"); 1252 + MODULE_DESCRIPTION("Andigilog aSC7621 and aSC7621a driver"); 1253 + 1254 + module_init(sm_asc7621_init); 1255 + module_exit(sm_asc7621_exit);
+6 -9
drivers/hwmon/fschmd.c
··· 267 struct list_head list; /* member of the watchdog_data_list */ 268 struct kref kref; 269 struct miscdevice watchdog_miscdev; 270 - int kind; 271 unsigned long watchdog_is_open; 272 char watchdog_expect_close; 273 char watchdog_name[10]; /* must be unique to avoid sysfs conflict */ ··· 325 int index = to_sensor_dev_attr(devattr)->index; 326 struct fschmd_data *data = fschmd_update_device(dev); 327 328 - /* fscher / fschrc - 1 as data->kind is an array index, not a chips */ 329 - if (data->kind == (fscher - 1) || data->kind >= (fschrc - 1)) 330 return sprintf(buf, "%d\n", (data->volt[index] * dmi_vref * 331 dmi_mult[index]) / 255 + dmi_offset[index]); 332 else ··· 491 int val = data->fan_min[index]; 492 493 /* 0 = allow turning off (except on the syl), 1-255 = 50-100% */ 494 - if (val || data->kind == fscsyl - 1) 495 val = val / 2 + 128; 496 497 return sprintf(buf, "%d\n", val); ··· 505 unsigned long v = simple_strtoul(buf, NULL, 10); 506 507 /* reg: 0 = allow turning off (except on the syl), 1-255 = 50-100% */ 508 - if (v || data->kind == fscsyl - 1) { 509 v = SENSORS_LIMIT(v, 128, 255); 510 v = (v - 128) * 2 + 1; 511 } ··· 1036 else 1037 return -ENODEV; 1038 1039 - strlcpy(info->type, fschmd_id[kind - 1].name, I2C_NAME_SIZE); 1040 1041 return 0; 1042 } ··· 1064 (where the client is found through a data ptr instead of the 1065 otherway around) */ 1066 data->client = client; 1067 1068 if (kind == fscpos) { 1069 /* The Poseidon has hardwired temp limits, fill these ··· 1084 dmi_vref = 33; 1085 } 1086 } 1087 - 1088 - /* i2c kind goes from 1-6, we want from 0-5 to address arrays */ 1089 - data->kind = kind - 1; 1090 1091 /* Read in some never changing registers */ 1092 data->revision = i2c_smbus_read_byte_data(client, FSCHMD_REG_REVISION);
··· 267 struct list_head list; /* member of the watchdog_data_list */ 268 struct kref kref; 269 struct miscdevice watchdog_miscdev; 270 + enum chips kind; 271 unsigned long watchdog_is_open; 272 char watchdog_expect_close; 273 char watchdog_name[10]; /* must be unique to avoid sysfs conflict */ ··· 325 int index = to_sensor_dev_attr(devattr)->index; 326 struct fschmd_data *data = fschmd_update_device(dev); 327 328 + if (data->kind == fscher || data->kind >= fschrc) 329 return sprintf(buf, "%d\n", (data->volt[index] * dmi_vref * 330 dmi_mult[index]) / 255 + dmi_offset[index]); 331 else ··· 492 int val = data->fan_min[index]; 493 494 /* 0 = allow turning off (except on the syl), 1-255 = 50-100% */ 495 + if (val || data->kind == fscsyl) 496 val = val / 2 + 128; 497 498 return sprintf(buf, "%d\n", val); ··· 506 unsigned long v = simple_strtoul(buf, NULL, 10); 507 508 /* reg: 0 = allow turning off (except on the syl), 1-255 = 50-100% */ 509 + if (v || data->kind == fscsyl) { 510 v = SENSORS_LIMIT(v, 128, 255); 511 v = (v - 128) * 2 + 1; 512 } ··· 1037 else 1038 return -ENODEV; 1039 1040 + strlcpy(info->type, fschmd_id[kind].name, I2C_NAME_SIZE); 1041 1042 return 0; 1043 } ··· 1065 (where the client is found through a data ptr instead of the 1066 otherway around) */ 1067 data->client = client; 1068 + data->kind = kind; 1069 1070 if (kind == fscpos) { 1071 /* The Poseidon has hardwired temp limits, fill these ··· 1084 dmi_vref = 33; 1085 } 1086 } 1087 1088 /* Read in some never changing registers */ 1089 data->revision = i2c_smbus_read_byte_data(client, FSCHMD_REG_REVISION);
+1 -1
drivers/hwmon/g760a.c
··· 68 #define PWM_FROM_CNT(cnt) (0xff-(cnt)) 69 #define PWM_TO_CNT(pwm) (0xff-(pwm)) 70 71 - unsigned int rpm_from_cnt(u8 val, u32 clk, u16 div) 72 { 73 return ((val == 0x00) ? 0 : ((clk*30)/(val*div))); 74 }
··· 68 #define PWM_FROM_CNT(cnt) (0xff-(cnt)) 69 #define PWM_TO_CNT(pwm) (0xff-(pwm)) 70 71 + static inline unsigned int rpm_from_cnt(u8 val, u32 clk, u16 div) 72 { 73 return ((val == 0x00) ? 0 : ((clk*30)/(val*div))); 74 }
+686 -253
drivers/hwmon/it87.c
··· 1 /* 2 - it87.c - Part of lm_sensors, Linux kernel modules for hardware 3 - monitoring. 4 - 5 - The IT8705F is an LPC-based Super I/O part that contains UARTs, a 6 - parallel port, an IR port, a MIDI port, a floppy controller, etc., in 7 - addition to an Environment Controller (Enhanced Hardware Monitor and 8 - Fan Controller) 9 - 10 - This driver supports only the Environment Controller in the IT8705F and 11 - similar parts. The other devices are supported by different drivers. 12 - 13 - Supports: IT8705F Super I/O chip w/LPC interface 14 - IT8712F Super I/O chip w/LPC interface 15 - IT8716F Super I/O chip w/LPC interface 16 - IT8718F Super I/O chip w/LPC interface 17 - IT8720F Super I/O chip w/LPC interface 18 - IT8726F Super I/O chip w/LPC interface 19 - Sis950 A clone of the IT8705F 20 - 21 - Copyright (C) 2001 Chris Gauthron 22 - Copyright (C) 2005-2007 Jean Delvare <khali@linux-fr.org> 23 - 24 - This program is free software; you can redistribute it and/or modify 25 - it under the terms of the GNU General Public License as published by 26 - the Free Software Foundation; either version 2 of the License, or 27 - (at your option) any later version. 28 - 29 - This program is distributed in the hope that it will be useful, 30 - but WITHOUT ANY WARRANTY; without even the implied warranty of 31 - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 32 - GNU General Public License for more details. 33 - 34 - You should have received a copy of the GNU General Public License 35 - along with this program; if not, write to the Free Software 36 - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 37 - */ 38 39 #include <linux/module.h> 40 #include <linux/init.h> ··· 128 #define IT87_SIO_GPIO5_REG 0x29 129 #define IT87_SIO_PINX2_REG 0x2c /* Pin selection */ 130 #define IT87_SIO_VID_REG 0xfc /* VID value */ 131 132 /* Update battery voltage after every reading if true */ 133 static int update_vbat; ··· 188 189 #define IT87_REG_VIN_ENABLE 0x50 190 #define IT87_REG_TEMP_ENABLE 0x51 191 192 #define IT87_REG_CHIPID 0x58 193 194 #define IN_TO_REG(val) (SENSORS_LIMIT((((val) + 8)/16),0,255)) 195 #define IN_FROM_REG(val) ((val) * 16) ··· 251 /* Values read from Super-I/O config space */ 252 u8 revision; 253 u8 vid_value; 254 /* Features skipped based on config or DMI */ 255 u8 skip_vid; 256 u8 skip_fan; ··· 285 u8 vid; /* Register encoding, combined */ 286 u8 vrm; 287 u32 alarms; /* Register encoding, combined */ 288 u8 fan_main_ctrl; /* Register value */ 289 u8 fan_ctl; /* Register value */ 290 - u8 manual_pwm_ctl[3]; /* manual PWM value set by user */ 291 }; 292 293 static inline int has_16bit_fans(const struct it87_data *data) ··· 312 || data->type == it8716 313 || data->type == it8718 314 || data->type == it8720; 315 } 316 317 static int it87_probe(struct platform_device *pdev); ··· 379 int nr = sensor_attr->index; 380 381 struct it87_data *data = dev_get_drvdata(dev); 382 - unsigned long val = simple_strtoul(buf, NULL, 10); 383 384 mutex_lock(&data->update_lock); 385 data->in_min[nr] = IN_TO_REG(val); ··· 398 int nr = sensor_attr->index; 399 400 struct it87_data *data = dev_get_drvdata(dev); 401 - unsigned long val = simple_strtoul(buf, NULL, 10); 402 403 mutex_lock(&data->update_lock); 404 data->in_max[nr] = IN_TO_REG(val); ··· 474 int nr = sensor_attr->index; 475 476 struct it87_data *data = dev_get_drvdata(dev); 477 - int val = simple_strtol(buf, NULL, 10); 478 479 mutex_lock(&data->update_lock); 480 data->temp_high[nr] = TEMP_TO_REG(val); ··· 492 int nr = sensor_attr->index; 493 494 struct it87_data *data = dev_get_drvdata(dev); 495 - int val = simple_strtol(buf, NULL, 10); 496 497 mutex_lock(&data->update_lock); 498 data->temp_low[nr] = TEMP_TO_REG(val); ··· 522 int nr = sensor_attr->index; 523 524 struct it87_data *data = it87_update_device(dev); 525 - u8 reg = data->sensor; /* In case the value is updated while we use it */ 526 - 527 if (reg & (1 << nr)) 528 return sprintf(buf, "3\n"); /* thermal diode */ 529 if (reg & (8 << nr)) ··· 538 int nr = sensor_attr->index; 539 540 struct it87_data *data = dev_get_drvdata(dev); 541 - int val = simple_strtol(buf, NULL, 10); 542 543 mutex_lock(&data->update_lock); 544 ··· 554 } 555 /* 3 = thermal diode; 4 = thermistor; 0 = disabled */ 556 if (val == 3) 557 - data->sensor |= 1 << nr; 558 else if (val == 4) 559 - data->sensor |= 8 << nr; 560 else if (val != 0) { 561 mutex_unlock(&data->update_lock); 562 return -EINVAL; ··· 574 show_sensor_offset(3); 575 576 /* 3 Fans */ 577 static ssize_t show_fan(struct device *dev, struct device_attribute *attr, 578 char *buf) 579 { ··· 594 int nr = sensor_attr->index; 595 596 struct it87_data *data = it87_update_device(dev); 597 - return sprintf(buf,"%d\n", FAN_FROM_REG(data->fan[nr], 598 DIV_FROM_REG(data->fan_div[nr]))); 599 } 600 static ssize_t show_fan_min(struct device *dev, struct device_attribute *attr, ··· 604 int nr = sensor_attr->index; 605 606 struct it87_data *data = it87_update_device(dev); 607 - return sprintf(buf,"%d\n", 608 - FAN_FROM_REG(data->fan_min[nr], DIV_FROM_REG(data->fan_div[nr]))); 609 } 610 static ssize_t show_fan_div(struct device *dev, struct device_attribute *attr, 611 char *buf) ··· 616 struct it87_data *data = it87_update_device(dev); 617 return sprintf(buf, "%d\n", DIV_FROM_REG(data->fan_div[nr])); 618 } 619 - static ssize_t show_pwm_enable(struct device *dev, struct device_attribute *attr, 620 - char *buf) 621 { 622 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); 623 int nr = sensor_attr->index; 624 625 struct it87_data *data = it87_update_device(dev); 626 - return sprintf(buf,"%d\n", (data->fan_main_ctrl & (1 << nr)) ? 1 : 0); 627 } 628 static ssize_t show_pwm(struct device *dev, struct device_attribute *attr, 629 char *buf) ··· 632 int nr = sensor_attr->index; 633 634 struct it87_data *data = it87_update_device(dev); 635 - return sprintf(buf,"%d\n", data->manual_pwm_ctl[nr]); 636 } 637 static ssize_t show_pwm_freq(struct device *dev, struct device_attribute *attr, 638 char *buf) ··· 649 int nr = sensor_attr->index; 650 651 struct it87_data *data = dev_get_drvdata(dev); 652 - int val = simple_strtol(buf, NULL, 10); 653 u8 reg; 654 655 mutex_lock(&data->update_lock); 656 reg = it87_read_value(data, IT87_REG_FAN_DIV); 657 switch (nr) { 658 - case 0: data->fan_div[nr] = reg & 0x07; break; 659 - case 1: data->fan_div[nr] = (reg >> 3) & 0x07; break; 660 - case 2: data->fan_div[nr] = (reg & 0x40) ? 3 : 1; break; 661 } 662 663 data->fan_min[nr] = FAN_TO_REG(val, DIV_FROM_REG(data->fan_div[nr])); ··· 681 int nr = sensor_attr->index; 682 683 struct it87_data *data = dev_get_drvdata(dev); 684 - unsigned long val = simple_strtoul(buf, NULL, 10); 685 int min; 686 u8 old; 687 688 mutex_lock(&data->update_lock); 689 old = it87_read_value(data, IT87_REG_FAN_DIV); ··· 719 mutex_unlock(&data->update_lock); 720 return count; 721 } 722 static ssize_t set_pwm_enable(struct device *dev, 723 struct device_attribute *attr, const char *buf, size_t count) 724 { ··· 752 int nr = sensor_attr->index; 753 754 struct it87_data *data = dev_get_drvdata(dev); 755 - int val = simple_strtol(buf, NULL, 10); 756 757 mutex_lock(&data->update_lock); 758 ··· 772 it87_write_value(data, IT87_REG_FAN_CTL, tmp | (1 << nr)); 773 /* set on/off mode */ 774 data->fan_main_ctrl &= ~(1 << nr); 775 - it87_write_value(data, IT87_REG_FAN_MAIN_CTRL, data->fan_main_ctrl); 776 - } else if (val == 1) { 777 /* set SmartGuardian mode */ 778 data->fan_main_ctrl |= (1 << nr); 779 - it87_write_value(data, IT87_REG_FAN_MAIN_CTRL, data->fan_main_ctrl); 780 - /* set saved pwm value, clear FAN_CTLX PWM mode bit */ 781 - it87_write_value(data, IT87_REG_PWM(nr), PWM_TO_REG(data->manual_pwm_ctl[nr])); 782 - } else { 783 - mutex_unlock(&data->update_lock); 784 - return -EINVAL; 785 } 786 787 mutex_unlock(&data->update_lock); ··· 796 int nr = sensor_attr->index; 797 798 struct it87_data *data = dev_get_drvdata(dev); 799 - int val = simple_strtol(buf, NULL, 10); 800 801 - if (val < 0 || val > 255) 802 return -EINVAL; 803 804 mutex_lock(&data->update_lock); 805 - data->manual_pwm_ctl[nr] = val; 806 - if (data->fan_main_ctrl & (1 << nr)) 807 - it87_write_value(data, IT87_REG_PWM(nr), PWM_TO_REG(data->manual_pwm_ctl[nr])); 808 mutex_unlock(&data->update_lock); 809 return count; 810 } ··· 816 struct device_attribute *attr, const char *buf, size_t count) 817 { 818 struct it87_data *data = dev_get_drvdata(dev); 819 - unsigned long val = simple_strtoul(buf, NULL, 10); 820 int i; 821 822 /* Search for the nearest available frequency */ 823 for (i = 0; i < 7; i++) { ··· 834 it87_write_value(data, IT87_REG_FAN_CTL, data->fan_ctl); 835 mutex_unlock(&data->update_lock); 836 837 return count; 838 } 839 ··· 982 show_pwm, set_pwm, offset - 1); \ 983 static DEVICE_ATTR(pwm##offset##_freq, \ 984 (offset == 1 ? S_IRUGO | S_IWUSR : S_IRUGO), \ 985 - show_pwm_freq, (offset == 1 ? set_pwm_freq : NULL)); 986 987 show_pwm_offset(1); 988 show_pwm_offset(2); ··· 1042 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); 1043 int nr = sensor_attr->index; 1044 struct it87_data *data = dev_get_drvdata(dev); 1045 - int val = simple_strtol(buf, NULL, 10); 1046 1047 mutex_lock(&data->update_lock); 1048 data->fan_min[nr] = FAN16_TO_REG(val); ··· 1075 show_fan16_offset(5); 1076 1077 /* Alarms */ 1078 - static ssize_t show_alarms(struct device *dev, struct device_attribute *attr, char *buf) 1079 { 1080 struct it87_data *data = it87_update_device(dev); 1081 return sprintf(buf, "%u\n", data->alarms); ··· 1107 static SENSOR_DEVICE_ATTR(temp2_alarm, S_IRUGO, show_alarm, NULL, 17); 1108 static SENSOR_DEVICE_ATTR(temp3_alarm, S_IRUGO, show_alarm, NULL, 18); 1109 1110 - static ssize_t 1111 - show_vrm_reg(struct device *dev, struct device_attribute *attr, char *buf) 1112 { 1113 struct it87_data *data = dev_get_drvdata(dev); 1114 return sprintf(buf, "%u\n", data->vrm); 1115 } 1116 - static ssize_t 1117 - store_vrm_reg(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) 1118 { 1119 struct it87_data *data = dev_get_drvdata(dev); 1120 - u32 val; 1121 1122 - val = simple_strtoul(buf, NULL, 10); 1123 data->vrm = val; 1124 1125 return count; 1126 } 1127 static DEVICE_ATTR(vrm, S_IRUGO | S_IWUSR, show_vrm_reg, store_vrm_reg); 1128 1129 - static ssize_t 1130 - show_vid_reg(struct device *dev, struct device_attribute *attr, char *buf) 1131 { 1132 struct it87_data *data = it87_update_device(dev); 1133 return sprintf(buf, "%ld\n", (long) vid_from_reg(data->vid, data->vrm)); ··· 1253 .attrs = it87_attributes, 1254 }; 1255 1256 - static struct attribute *it87_attributes_opt[] = { 1257 &sensor_dev_attr_fan1_input16.dev_attr.attr, 1258 &sensor_dev_attr_fan1_min16.dev_attr.attr, 1259 &sensor_dev_attr_fan2_input16.dev_attr.attr, 1260 &sensor_dev_attr_fan2_min16.dev_attr.attr, 1261 &sensor_dev_attr_fan3_input16.dev_attr.attr, 1262 &sensor_dev_attr_fan3_min16.dev_attr.attr, 1263 &sensor_dev_attr_fan4_input16.dev_attr.attr, 1264 &sensor_dev_attr_fan4_min16.dev_attr.attr, 1265 &sensor_dev_attr_fan5_input16.dev_attr.attr, 1266 &sensor_dev_attr_fan5_min16.dev_attr.attr, 1267 1268 &sensor_dev_attr_fan1_input.dev_attr.attr, 1269 &sensor_dev_attr_fan1_min.dev_attr.attr, 1270 &sensor_dev_attr_fan1_div.dev_attr.attr, 1271 &sensor_dev_attr_fan2_input.dev_attr.attr, 1272 &sensor_dev_attr_fan2_min.dev_attr.attr, 1273 &sensor_dev_attr_fan2_div.dev_attr.attr, 1274 &sensor_dev_attr_fan3_input.dev_attr.attr, 1275 &sensor_dev_attr_fan3_min.dev_attr.attr, 1276 &sensor_dev_attr_fan3_div.dev_attr.attr, 1277 - 1278 - &sensor_dev_attr_fan1_alarm.dev_attr.attr, 1279 - &sensor_dev_attr_fan2_alarm.dev_attr.attr, 1280 &sensor_dev_attr_fan3_alarm.dev_attr.attr, 1281 - &sensor_dev_attr_fan4_alarm.dev_attr.attr, 1282 - &sensor_dev_attr_fan5_alarm.dev_attr.attr, 1283 1284 &sensor_dev_attr_pwm1_enable.dev_attr.attr, 1285 - &sensor_dev_attr_pwm2_enable.dev_attr.attr, 1286 - &sensor_dev_attr_pwm3_enable.dev_attr.attr, 1287 &sensor_dev_attr_pwm1.dev_attr.attr, 1288 - &sensor_dev_attr_pwm2.dev_attr.attr, 1289 - &sensor_dev_attr_pwm3.dev_attr.attr, 1290 &dev_attr_pwm1_freq.attr, 1291 &dev_attr_pwm2_freq.attr, 1292 &dev_attr_pwm3_freq.attr, 1293 1294 &dev_attr_vrm.attr, 1295 &dev_attr_cpu0_vid.attr, 1296 NULL 1297 }; 1298 1299 - static const struct attribute_group it87_group_opt = { 1300 - .attrs = it87_attributes_opt, 1301 }; 1302 1303 /* SuperIO detection - will change isa_address if a chip is found */ ··· 1482 if (sio_data->type == it87) { 1483 /* The IT8705F doesn't have VID pins at all */ 1484 sio_data->skip_vid = 1; 1485 } else { 1486 int reg; 1487 ··· 1519 pr_info("it87: in3 is VCC (+5V)\n"); 1520 if (reg & (1 << 1)) 1521 pr_info("it87: in7 is VCCH (+5V Stand-By)\n"); 1522 } 1523 1524 /* Disable specific features based on DMI strings */ 1525 board_vendor = dmi_get_system_info(DMI_BOARD_VENDOR); ··· 1548 return err; 1549 } 1550 1551 static int __devinit it87_probe(struct platform_device *pdev) 1552 { 1553 struct it87_data *data; 1554 struct resource *res; 1555 struct device *dev = &pdev->dev; 1556 struct it87_sio_data *sio_data = dev->platform_data; 1557 - int err = 0; 1558 int enable_pwm_interface; 1559 static const char *names[] = { 1560 "it87", 1561 "it8712", ··· 1605 goto ERROR0; 1606 } 1607 1608 - if (!(data = kzalloc(sizeof(struct it87_data), GFP_KERNEL))) { 1609 err = -ENOMEM; 1610 goto ERROR1; 1611 } ··· 1634 it87_init_device(pdev); 1635 1636 /* Register sysfs hooks */ 1637 - if ((err = sysfs_create_group(&dev->kobj, &it87_group))) 1638 goto ERROR2; 1639 1640 /* Do not create fan files for disabled fans */ 1641 - if (has_16bit_fans(data)) { 1642 - /* 16-bit tachometers */ 1643 - if (data->has_fan & (1 << 0)) { 1644 - if ((err = device_create_file(dev, 1645 - &sensor_dev_attr_fan1_input16.dev_attr)) 1646 - || (err = device_create_file(dev, 1647 - &sensor_dev_attr_fan1_min16.dev_attr)) 1648 - || (err = device_create_file(dev, 1649 - &sensor_dev_attr_fan1_alarm.dev_attr))) 1650 goto ERROR4; 1651 - } 1652 - if (data->has_fan & (1 << 1)) { 1653 - if ((err = device_create_file(dev, 1654 - &sensor_dev_attr_fan2_input16.dev_attr)) 1655 - || (err = device_create_file(dev, 1656 - &sensor_dev_attr_fan2_min16.dev_attr)) 1657 - || (err = device_create_file(dev, 1658 - &sensor_dev_attr_fan2_alarm.dev_attr))) 1659 - goto ERROR4; 1660 - } 1661 - if (data->has_fan & (1 << 2)) { 1662 - if ((err = device_create_file(dev, 1663 - &sensor_dev_attr_fan3_input16.dev_attr)) 1664 - || (err = device_create_file(dev, 1665 - &sensor_dev_attr_fan3_min16.dev_attr)) 1666 - || (err = device_create_file(dev, 1667 - &sensor_dev_attr_fan3_alarm.dev_attr))) 1668 - goto ERROR4; 1669 - } 1670 - if (data->has_fan & (1 << 3)) { 1671 - if ((err = device_create_file(dev, 1672 - &sensor_dev_attr_fan4_input16.dev_attr)) 1673 - || (err = device_create_file(dev, 1674 - &sensor_dev_attr_fan4_min16.dev_attr)) 1675 - || (err = device_create_file(dev, 1676 - &sensor_dev_attr_fan4_alarm.dev_attr))) 1677 - goto ERROR4; 1678 - } 1679 - if (data->has_fan & (1 << 4)) { 1680 - if ((err = device_create_file(dev, 1681 - &sensor_dev_attr_fan5_input16.dev_attr)) 1682 - || (err = device_create_file(dev, 1683 - &sensor_dev_attr_fan5_min16.dev_attr)) 1684 - || (err = device_create_file(dev, 1685 - &sensor_dev_attr_fan5_alarm.dev_attr))) 1686 - goto ERROR4; 1687 - } 1688 - } else { 1689 - /* 8-bit tachometers with clock divider */ 1690 - if (data->has_fan & (1 << 0)) { 1691 - if ((err = device_create_file(dev, 1692 - &sensor_dev_attr_fan1_input.dev_attr)) 1693 - || (err = device_create_file(dev, 1694 - &sensor_dev_attr_fan1_min.dev_attr)) 1695 - || (err = device_create_file(dev, 1696 - &sensor_dev_attr_fan1_div.dev_attr)) 1697 - || (err = device_create_file(dev, 1698 - &sensor_dev_attr_fan1_alarm.dev_attr))) 1699 - goto ERROR4; 1700 - } 1701 - if (data->has_fan & (1 << 1)) { 1702 - if ((err = device_create_file(dev, 1703 - &sensor_dev_attr_fan2_input.dev_attr)) 1704 - || (err = device_create_file(dev, 1705 - &sensor_dev_attr_fan2_min.dev_attr)) 1706 - || (err = device_create_file(dev, 1707 - &sensor_dev_attr_fan2_div.dev_attr)) 1708 - || (err = device_create_file(dev, 1709 - &sensor_dev_attr_fan2_alarm.dev_attr))) 1710 - goto ERROR4; 1711 - } 1712 - if (data->has_fan & (1 << 2)) { 1713 - if ((err = device_create_file(dev, 1714 - &sensor_dev_attr_fan3_input.dev_attr)) 1715 - || (err = device_create_file(dev, 1716 - &sensor_dev_attr_fan3_min.dev_attr)) 1717 - || (err = device_create_file(dev, 1718 - &sensor_dev_attr_fan3_div.dev_attr)) 1719 - || (err = device_create_file(dev, 1720 - &sensor_dev_attr_fan3_alarm.dev_attr))) 1721 - goto ERROR4; 1722 } 1723 } 1724 1725 if (enable_pwm_interface) { 1726 - if (!(sio_data->skip_pwm & (1 << 0))) { 1727 - if ((err = device_create_file(dev, 1728 - &sensor_dev_attr_pwm1_enable.dev_attr)) 1729 - || (err = device_create_file(dev, 1730 - &sensor_dev_attr_pwm1.dev_attr)) 1731 - || (err = device_create_file(dev, 1732 - &dev_attr_pwm1_freq))) 1733 goto ERROR4; 1734 - } 1735 - if (!(sio_data->skip_pwm & (1 << 1))) { 1736 - if ((err = device_create_file(dev, 1737 - &sensor_dev_attr_pwm2_enable.dev_attr)) 1738 - || (err = device_create_file(dev, 1739 - &sensor_dev_attr_pwm2.dev_attr)) 1740 - || (err = device_create_file(dev, 1741 - &dev_attr_pwm2_freq))) 1742 - goto ERROR4; 1743 - } 1744 - if (!(sio_data->skip_pwm & (1 << 2))) { 1745 - if ((err = device_create_file(dev, 1746 - &sensor_dev_attr_pwm3_enable.dev_attr)) 1747 - || (err = device_create_file(dev, 1748 - &sensor_dev_attr_pwm3.dev_attr)) 1749 - || (err = device_create_file(dev, 1750 - &dev_attr_pwm3_freq))) 1751 goto ERROR4; 1752 } 1753 } ··· 1696 data->vrm = vid_which_vrm(); 1697 /* VID reading from Super-I/O config space if available */ 1698 data->vid = sio_data->vid_value; 1699 - if ((err = device_create_file(dev, 1700 - &dev_attr_vrm)) 1701 - || (err = device_create_file(dev, 1702 - &dev_attr_cpu0_vid))) 1703 goto ERROR4; 1704 } 1705 ··· 1710 return 0; 1711 1712 ERROR4: 1713 - sysfs_remove_group(&dev->kobj, &it87_group); 1714 - sysfs_remove_group(&dev->kobj, &it87_group_opt); 1715 ERROR2: 1716 platform_set_drvdata(pdev, NULL); 1717 kfree(data); ··· 1725 struct it87_data *data = platform_get_drvdata(pdev); 1726 1727 hwmon_device_unregister(data->hwmon_dev); 1728 - sysfs_remove_group(&pdev->dev.kobj, &it87_group); 1729 - sysfs_remove_group(&pdev->dev.kobj, &it87_group_opt); 1730 1731 release_region(data->addr, IT87_EC_EXTENT); 1732 platform_set_drvdata(pdev, NULL); ··· 1811 int tmp, i; 1812 u8 mask; 1813 1814 - /* initialize to sane defaults: 1815 - * - if the chip is in manual pwm mode, this will be overwritten with 1816 - * the actual settings on the chip (so in this case, initialization 1817 - * is not needed) 1818 - * - if in automatic or on/off mode, we could switch to manual mode, 1819 - * read the registers and set manual_pwm_ctl accordingly, but currently 1820 - * this is not implemented, so we initialize to something sane */ 1821 for (i = 0; i < 3; i++) { 1822 - data->manual_pwm_ctl[i] = 0xff; 1823 } 1824 1825 /* Some chips seem to have default value 0xff for all limit ··· 1863 if ((data->fan_main_ctrl & mask) == 0) { 1864 /* Enable all fan tachometers */ 1865 data->fan_main_ctrl |= mask; 1866 - it87_write_value(data, IT87_REG_FAN_MAIN_CTRL, data->fan_main_ctrl); 1867 } 1868 data->has_fan = (data->fan_main_ctrl >> 4) & 0x07; 1869 ··· 1889 /* Fan input pins may be used for alternative functions */ 1890 data->has_fan &= ~sio_data->skip_fan; 1891 1892 - /* Set current fan mode registers and the default settings for the 1893 - * other mode registers */ 1894 - for (i = 0; i < 3; i++) { 1895 - if (data->fan_main_ctrl & (1 << i)) { 1896 - /* pwm mode */ 1897 - tmp = it87_read_value(data, IT87_REG_PWM(i)); 1898 - if (tmp & 0x80) { 1899 - /* automatic pwm - not yet implemented, but 1900 - * leave the settings made by the BIOS alone 1901 - * until a change is requested via the sysfs 1902 - * interface */ 1903 - } else { 1904 - /* manual pwm */ 1905 - data->manual_pwm_ctl[i] = PWM_FROM_REG(tmp); 1906 - } 1907 - } 1908 - } 1909 - 1910 /* Start monitoring */ 1911 it87_write_value(data, IT87_REG_CONFIG, 1912 (it87_read_value(data, IT87_REG_CONFIG) & 0x36) 1913 | (update_vbat ? 0x41 : 0x01)); 1914 } 1915 1916 static struct it87_data *it87_update_device(struct device *dev) ··· 1924 1925 if (time_after(jiffies, data->last_updated + HZ + HZ / 2) 1926 || !data->valid) { 1927 - 1928 if (update_vbat) { 1929 /* Cleared after each update, so reenable. Value 1930 - returned by this read will be previous value */ 1931 it87_write_value(data, IT87_REG_CONFIG, 1932 - it87_read_value(data, IT87_REG_CONFIG) | 0x40); 1933 } 1934 for (i = 0; i <= 7; i++) { 1935 data->in[i] = 1936 - it87_read_value(data, IT87_REG_VIN(i)); 1937 data->in_min[i] = 1938 - it87_read_value(data, IT87_REG_VIN_MIN(i)); 1939 data->in_max[i] = 1940 - it87_read_value(data, IT87_REG_VIN_MAX(i)); 1941 } 1942 /* in8 (battery) has no limit registers */ 1943 - data->in[8] = 1944 - it87_read_value(data, IT87_REG_VIN(8)); 1945 1946 for (i = 0; i < 5; i++) { 1947 /* Skip disabled fans */ ··· 1947 continue; 1948 1949 data->fan_min[i] = 1950 - it87_read_value(data, IT87_REG_FAN_MIN[i]); 1951 data->fan[i] = it87_read_value(data, 1952 IT87_REG_FAN[i]); 1953 /* Add high byte if in 16-bit mode */ ··· 1960 } 1961 for (i = 0; i < 3; i++) { 1962 data->temp[i] = 1963 - it87_read_value(data, IT87_REG_TEMP(i)); 1964 data->temp_high[i] = 1965 - it87_read_value(data, IT87_REG_TEMP_HIGH(i)); 1966 data->temp_low[i] = 1967 - it87_read_value(data, IT87_REG_TEMP_LOW(i)); 1968 } 1969 1970 /* Newer chips don't have clock dividers */ ··· 1979 it87_read_value(data, IT87_REG_ALARM1) | 1980 (it87_read_value(data, IT87_REG_ALARM2) << 8) | 1981 (it87_read_value(data, IT87_REG_ALARM3) << 16); 1982 data->fan_main_ctrl = it87_read_value(data, 1983 IT87_REG_FAN_MAIN_CTRL); 1984 data->fan_ctl = it87_read_value(data, IT87_REG_FAN_CTL); 1985 1986 data->sensor = it87_read_value(data, IT87_REG_TEMP_ENABLE); 1987 /* The 8705 does not have VID capability. ··· 2060 static int __init sm_it87_init(void) 2061 { 2062 int err; 2063 - unsigned short isa_address=0; 2064 struct it87_sio_data sio_data; 2065 2066 memset(&sio_data, 0, sizeof(struct it87_sio_data)); ··· 2072 return err; 2073 2074 err = it87_device_add(isa_address, &sio_data); 2075 - if (err){ 2076 platform_driver_unregister(&it87_driver); 2077 return err; 2078 } ··· 2093 module_param(update_vbat, bool, 0); 2094 MODULE_PARM_DESC(update_vbat, "Update vbat if set else return powerup value"); 2095 module_param(fix_pwm_polarity, bool, 0); 2096 - MODULE_PARM_DESC(fix_pwm_polarity, "Force PWM polarity to active high (DANGEROUS)"); 2097 MODULE_LICENSE("GPL"); 2098 2099 module_init(sm_it87_init);
··· 1 /* 2 + * it87.c - Part of lm_sensors, Linux kernel modules for hardware 3 + * monitoring. 4 + * 5 + * The IT8705F is an LPC-based Super I/O part that contains UARTs, a 6 + * parallel port, an IR port, a MIDI port, a floppy controller, etc., in 7 + * addition to an Environment Controller (Enhanced Hardware Monitor and 8 + * Fan Controller) 9 + * 10 + * This driver supports only the Environment Controller in the IT8705F and 11 + * similar parts. The other devices are supported by different drivers. 12 + * 13 + * Supports: IT8705F Super I/O chip w/LPC interface 14 + * IT8712F Super I/O chip w/LPC interface 15 + * IT8716F Super I/O chip w/LPC interface 16 + * IT8718F Super I/O chip w/LPC interface 17 + * IT8720F Super I/O chip w/LPC interface 18 + * IT8726F Super I/O chip w/LPC interface 19 + * Sis950 A clone of the IT8705F 20 + * 21 + * Copyright (C) 2001 Chris Gauthron 22 + * Copyright (C) 2005-2010 Jean Delvare <khali@linux-fr.org> 23 + * 24 + * This program is free software; you can redistribute it and/or modify 25 + * it under the terms of the GNU General Public License as published by 26 + * the Free Software Foundation; either version 2 of the License, or 27 + * (at your option) any later version. 28 + * 29 + * This program is distributed in the hope that it will be useful, 30 + * but WITHOUT ANY WARRANTY; without even the implied warranty of 31 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 32 + * GNU General Public License for more details. 33 + * 34 + * You should have received a copy of the GNU General Public License 35 + * along with this program; if not, write to the Free Software 36 + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 37 + */ 38 39 #include <linux/module.h> 40 #include <linux/init.h> ··· 128 #define IT87_SIO_GPIO5_REG 0x29 129 #define IT87_SIO_PINX2_REG 0x2c /* Pin selection */ 130 #define IT87_SIO_VID_REG 0xfc /* VID value */ 131 + #define IT87_SIO_BEEP_PIN_REG 0xf6 /* Beep pin mapping */ 132 133 /* Update battery voltage after every reading if true */ 134 static int update_vbat; ··· 187 188 #define IT87_REG_VIN_ENABLE 0x50 189 #define IT87_REG_TEMP_ENABLE 0x51 190 + #define IT87_REG_BEEP_ENABLE 0x5c 191 192 #define IT87_REG_CHIPID 0x58 193 + 194 + #define IT87_REG_AUTO_TEMP(nr, i) (0x60 + (nr) * 8 + (i)) 195 + #define IT87_REG_AUTO_PWM(nr, i) (0x65 + (nr) * 8 + (i)) 196 197 #define IN_TO_REG(val) (SENSORS_LIMIT((((val) + 8)/16),0,255)) 198 #define IN_FROM_REG(val) ((val) * 16) ··· 246 /* Values read from Super-I/O config space */ 247 u8 revision; 248 u8 vid_value; 249 + u8 beep_pin; 250 /* Features skipped based on config or DMI */ 251 u8 skip_vid; 252 u8 skip_fan; ··· 279 u8 vid; /* Register encoding, combined */ 280 u8 vrm; 281 u32 alarms; /* Register encoding, combined */ 282 + u8 beeps; /* Register encoding */ 283 u8 fan_main_ctrl; /* Register value */ 284 u8 fan_ctl; /* Register value */ 285 + 286 + /* The following 3 arrays correspond to the same registers. The 287 + * meaning of bits 6-0 depends on the value of bit 7, and we want 288 + * to preserve settings on mode changes, so we have to track all 289 + * values separately. */ 290 + u8 pwm_ctrl[3]; /* Register value */ 291 + u8 pwm_duty[3]; /* Manual PWM value set by user (bit 6-0) */ 292 + u8 pwm_temp_map[3]; /* PWM to temp. chan. mapping (bits 1-0) */ 293 + 294 + /* Automatic fan speed control registers */ 295 + u8 auto_pwm[3][4]; /* [nr][3] is hard-coded */ 296 + s8 auto_temp[3][5]; /* [nr][0] is point1_temp_hyst */ 297 }; 298 299 static inline int has_16bit_fans(const struct it87_data *data) ··· 294 || data->type == it8716 295 || data->type == it8718 296 || data->type == it8720; 297 + } 298 + 299 + static inline int has_old_autopwm(const struct it87_data *data) 300 + { 301 + /* The old automatic fan speed control interface is implemented 302 + by IT8705F chips up to revision F and IT8712F chips up to 303 + revision G. */ 304 + return (data->type == it87 && data->revision < 0x03) 305 + || (data->type == it8712 && data->revision < 0x08); 306 } 307 308 static int it87_probe(struct platform_device *pdev); ··· 352 int nr = sensor_attr->index; 353 354 struct it87_data *data = dev_get_drvdata(dev); 355 + unsigned long val; 356 + 357 + if (strict_strtoul(buf, 10, &val) < 0) 358 + return -EINVAL; 359 360 mutex_lock(&data->update_lock); 361 data->in_min[nr] = IN_TO_REG(val); ··· 368 int nr = sensor_attr->index; 369 370 struct it87_data *data = dev_get_drvdata(dev); 371 + unsigned long val; 372 + 373 + if (strict_strtoul(buf, 10, &val) < 0) 374 + return -EINVAL; 375 376 mutex_lock(&data->update_lock); 377 data->in_max[nr] = IN_TO_REG(val); ··· 441 int nr = sensor_attr->index; 442 443 struct it87_data *data = dev_get_drvdata(dev); 444 + long val; 445 + 446 + if (strict_strtol(buf, 10, &val) < 0) 447 + return -EINVAL; 448 449 mutex_lock(&data->update_lock); 450 data->temp_high[nr] = TEMP_TO_REG(val); ··· 456 int nr = sensor_attr->index; 457 458 struct it87_data *data = dev_get_drvdata(dev); 459 + long val; 460 + 461 + if (strict_strtol(buf, 10, &val) < 0) 462 + return -EINVAL; 463 464 mutex_lock(&data->update_lock); 465 data->temp_low[nr] = TEMP_TO_REG(val); ··· 483 int nr = sensor_attr->index; 484 485 struct it87_data *data = it87_update_device(dev); 486 + u8 reg = data->sensor; /* In case the value is updated while 487 + we use it */ 488 + 489 if (reg & (1 << nr)) 490 return sprintf(buf, "3\n"); /* thermal diode */ 491 if (reg & (8 << nr)) ··· 498 int nr = sensor_attr->index; 499 500 struct it87_data *data = dev_get_drvdata(dev); 501 + long val; 502 + 503 + if (strict_strtol(buf, 10, &val) < 0) 504 + return -EINVAL; 505 506 mutex_lock(&data->update_lock); 507 ··· 511 } 512 /* 3 = thermal diode; 4 = thermistor; 0 = disabled */ 513 if (val == 3) 514 + data->sensor |= 1 << nr; 515 else if (val == 4) 516 + data->sensor |= 8 << nr; 517 else if (val != 0) { 518 mutex_unlock(&data->update_lock); 519 return -EINVAL; ··· 531 show_sensor_offset(3); 532 533 /* 3 Fans */ 534 + 535 + static int pwm_mode(const struct it87_data *data, int nr) 536 + { 537 + int ctrl = data->fan_main_ctrl & (1 << nr); 538 + 539 + if (ctrl == 0) /* Full speed */ 540 + return 0; 541 + if (data->pwm_ctrl[nr] & 0x80) /* Automatic mode */ 542 + return 2; 543 + else /* Manual mode */ 544 + return 1; 545 + } 546 + 547 static ssize_t show_fan(struct device *dev, struct device_attribute *attr, 548 char *buf) 549 { ··· 538 int nr = sensor_attr->index; 539 540 struct it87_data *data = it87_update_device(dev); 541 + return sprintf(buf, "%d\n", FAN_FROM_REG(data->fan[nr], 542 DIV_FROM_REG(data->fan_div[nr]))); 543 } 544 static ssize_t show_fan_min(struct device *dev, struct device_attribute *attr, ··· 548 int nr = sensor_attr->index; 549 550 struct it87_data *data = it87_update_device(dev); 551 + return sprintf(buf, "%d\n", FAN_FROM_REG(data->fan_min[nr], 552 + DIV_FROM_REG(data->fan_div[nr]))); 553 } 554 static ssize_t show_fan_div(struct device *dev, struct device_attribute *attr, 555 char *buf) ··· 560 struct it87_data *data = it87_update_device(dev); 561 return sprintf(buf, "%d\n", DIV_FROM_REG(data->fan_div[nr])); 562 } 563 + static ssize_t show_pwm_enable(struct device *dev, 564 + struct device_attribute *attr, char *buf) 565 { 566 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); 567 int nr = sensor_attr->index; 568 569 struct it87_data *data = it87_update_device(dev); 570 + return sprintf(buf, "%d\n", pwm_mode(data, nr)); 571 } 572 static ssize_t show_pwm(struct device *dev, struct device_attribute *attr, 573 char *buf) ··· 576 int nr = sensor_attr->index; 577 578 struct it87_data *data = it87_update_device(dev); 579 + return sprintf(buf, "%d\n", PWM_FROM_REG(data->pwm_duty[nr])); 580 } 581 static ssize_t show_pwm_freq(struct device *dev, struct device_attribute *attr, 582 char *buf) ··· 593 int nr = sensor_attr->index; 594 595 struct it87_data *data = dev_get_drvdata(dev); 596 + long val; 597 u8 reg; 598 + 599 + if (strict_strtol(buf, 10, &val) < 0) 600 + return -EINVAL; 601 602 mutex_lock(&data->update_lock); 603 reg = it87_read_value(data, IT87_REG_FAN_DIV); 604 switch (nr) { 605 + case 0: 606 + data->fan_div[nr] = reg & 0x07; 607 + break; 608 + case 1: 609 + data->fan_div[nr] = (reg >> 3) & 0x07; 610 + break; 611 + case 2: 612 + data->fan_div[nr] = (reg & 0x40) ? 3 : 1; 613 + break; 614 } 615 616 data->fan_min[nr] = FAN_TO_REG(val, DIV_FROM_REG(data->fan_div[nr])); ··· 616 int nr = sensor_attr->index; 617 618 struct it87_data *data = dev_get_drvdata(dev); 619 + unsigned long val; 620 int min; 621 u8 old; 622 + 623 + if (strict_strtoul(buf, 10, &val) < 0) 624 + return -EINVAL; 625 626 mutex_lock(&data->update_lock); 627 old = it87_read_value(data, IT87_REG_FAN_DIV); ··· 651 mutex_unlock(&data->update_lock); 652 return count; 653 } 654 + 655 + /* Returns 0 if OK, -EINVAL otherwise */ 656 + static int check_trip_points(struct device *dev, int nr) 657 + { 658 + const struct it87_data *data = dev_get_drvdata(dev); 659 + int i, err = 0; 660 + 661 + if (has_old_autopwm(data)) { 662 + for (i = 0; i < 3; i++) { 663 + if (data->auto_temp[nr][i] > data->auto_temp[nr][i + 1]) 664 + err = -EINVAL; 665 + } 666 + for (i = 0; i < 2; i++) { 667 + if (data->auto_pwm[nr][i] > data->auto_pwm[nr][i + 1]) 668 + err = -EINVAL; 669 + } 670 + } 671 + 672 + if (err) { 673 + dev_err(dev, "Inconsistent trip points, not switching to " 674 + "automatic mode\n"); 675 + dev_err(dev, "Adjust the trip points and try again\n"); 676 + } 677 + return err; 678 + } 679 + 680 static ssize_t set_pwm_enable(struct device *dev, 681 struct device_attribute *attr, const char *buf, size_t count) 682 { ··· 658 int nr = sensor_attr->index; 659 660 struct it87_data *data = dev_get_drvdata(dev); 661 + long val; 662 + 663 + if (strict_strtol(buf, 10, &val) < 0 || val < 0 || val > 2) 664 + return -EINVAL; 665 + 666 + /* Check trip points before switching to automatic mode */ 667 + if (val == 2) { 668 + if (check_trip_points(dev, nr) < 0) 669 + return -EINVAL; 670 + } 671 672 mutex_lock(&data->update_lock); 673 ··· 669 it87_write_value(data, IT87_REG_FAN_CTL, tmp | (1 << nr)); 670 /* set on/off mode */ 671 data->fan_main_ctrl &= ~(1 << nr); 672 + it87_write_value(data, IT87_REG_FAN_MAIN_CTRL, 673 + data->fan_main_ctrl); 674 + } else { 675 + if (val == 1) /* Manual mode */ 676 + data->pwm_ctrl[nr] = data->pwm_duty[nr]; 677 + else /* Automatic mode */ 678 + data->pwm_ctrl[nr] = 0x80 | data->pwm_temp_map[nr]; 679 + it87_write_value(data, IT87_REG_PWM(nr), data->pwm_ctrl[nr]); 680 /* set SmartGuardian mode */ 681 data->fan_main_ctrl |= (1 << nr); 682 + it87_write_value(data, IT87_REG_FAN_MAIN_CTRL, 683 + data->fan_main_ctrl); 684 } 685 686 mutex_unlock(&data->update_lock); ··· 691 int nr = sensor_attr->index; 692 693 struct it87_data *data = dev_get_drvdata(dev); 694 + long val; 695 696 + if (strict_strtol(buf, 10, &val) < 0 || val < 0 || val > 255) 697 return -EINVAL; 698 699 mutex_lock(&data->update_lock); 700 + data->pwm_duty[nr] = PWM_TO_REG(val); 701 + /* If we are in manual mode, write the duty cycle immediately; 702 + * otherwise, just store it for later use. */ 703 + if (!(data->pwm_ctrl[nr] & 0x80)) { 704 + data->pwm_ctrl[nr] = data->pwm_duty[nr]; 705 + it87_write_value(data, IT87_REG_PWM(nr), data->pwm_ctrl[nr]); 706 + } 707 mutex_unlock(&data->update_lock); 708 return count; 709 } ··· 707 struct device_attribute *attr, const char *buf, size_t count) 708 { 709 struct it87_data *data = dev_get_drvdata(dev); 710 + unsigned long val; 711 int i; 712 + 713 + if (strict_strtoul(buf, 10, &val) < 0) 714 + return -EINVAL; 715 716 /* Search for the nearest available frequency */ 717 for (i = 0; i < 7; i++) { ··· 722 it87_write_value(data, IT87_REG_FAN_CTL, data->fan_ctl); 723 mutex_unlock(&data->update_lock); 724 725 + return count; 726 + } 727 + static ssize_t show_pwm_temp_map(struct device *dev, 728 + struct device_attribute *attr, char *buf) 729 + { 730 + struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); 731 + int nr = sensor_attr->index; 732 + 733 + struct it87_data *data = it87_update_device(dev); 734 + int map; 735 + 736 + if (data->pwm_temp_map[nr] < 3) 737 + map = 1 << data->pwm_temp_map[nr]; 738 + else 739 + map = 0; /* Should never happen */ 740 + return sprintf(buf, "%d\n", map); 741 + } 742 + static ssize_t set_pwm_temp_map(struct device *dev, 743 + struct device_attribute *attr, const char *buf, size_t count) 744 + { 745 + struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); 746 + int nr = sensor_attr->index; 747 + 748 + struct it87_data *data = dev_get_drvdata(dev); 749 + long val; 750 + u8 reg; 751 + 752 + /* This check can go away if we ever support automatic fan speed 753 + control on newer chips. */ 754 + if (!has_old_autopwm(data)) { 755 + dev_notice(dev, "Mapping change disabled for safety reasons\n"); 756 + return -EINVAL; 757 + } 758 + 759 + if (strict_strtol(buf, 10, &val) < 0) 760 + return -EINVAL; 761 + 762 + switch (val) { 763 + case (1 << 0): 764 + reg = 0x00; 765 + break; 766 + case (1 << 1): 767 + reg = 0x01; 768 + break; 769 + case (1 << 2): 770 + reg = 0x02; 771 + break; 772 + default: 773 + return -EINVAL; 774 + } 775 + 776 + mutex_lock(&data->update_lock); 777 + data->pwm_temp_map[nr] = reg; 778 + /* If we are in automatic mode, write the temp mapping immediately; 779 + * otherwise, just store it for later use. */ 780 + if (data->pwm_ctrl[nr] & 0x80) { 781 + data->pwm_ctrl[nr] = 0x80 | data->pwm_temp_map[nr]; 782 + it87_write_value(data, IT87_REG_PWM(nr), data->pwm_ctrl[nr]); 783 + } 784 + mutex_unlock(&data->update_lock); 785 + return count; 786 + } 787 + 788 + static ssize_t show_auto_pwm(struct device *dev, 789 + struct device_attribute *attr, char *buf) 790 + { 791 + struct it87_data *data = it87_update_device(dev); 792 + struct sensor_device_attribute_2 *sensor_attr = 793 + to_sensor_dev_attr_2(attr); 794 + int nr = sensor_attr->nr; 795 + int point = sensor_attr->index; 796 + 797 + return sprintf(buf, "%d\n", PWM_FROM_REG(data->auto_pwm[nr][point])); 798 + } 799 + 800 + static ssize_t set_auto_pwm(struct device *dev, 801 + struct device_attribute *attr, const char *buf, size_t count) 802 + { 803 + struct it87_data *data = dev_get_drvdata(dev); 804 + struct sensor_device_attribute_2 *sensor_attr = 805 + to_sensor_dev_attr_2(attr); 806 + int nr = sensor_attr->nr; 807 + int point = sensor_attr->index; 808 + long val; 809 + 810 + if (strict_strtol(buf, 10, &val) < 0 || val < 0 || val > 255) 811 + return -EINVAL; 812 + 813 + mutex_lock(&data->update_lock); 814 + data->auto_pwm[nr][point] = PWM_TO_REG(val); 815 + it87_write_value(data, IT87_REG_AUTO_PWM(nr, point), 816 + data->auto_pwm[nr][point]); 817 + mutex_unlock(&data->update_lock); 818 + return count; 819 + } 820 + 821 + static ssize_t show_auto_temp(struct device *dev, 822 + struct device_attribute *attr, char *buf) 823 + { 824 + struct it87_data *data = it87_update_device(dev); 825 + struct sensor_device_attribute_2 *sensor_attr = 826 + to_sensor_dev_attr_2(attr); 827 + int nr = sensor_attr->nr; 828 + int point = sensor_attr->index; 829 + 830 + return sprintf(buf, "%d\n", TEMP_FROM_REG(data->auto_temp[nr][point])); 831 + } 832 + 833 + static ssize_t set_auto_temp(struct device *dev, 834 + struct device_attribute *attr, const char *buf, size_t count) 835 + { 836 + struct it87_data *data = dev_get_drvdata(dev); 837 + struct sensor_device_attribute_2 *sensor_attr = 838 + to_sensor_dev_attr_2(attr); 839 + int nr = sensor_attr->nr; 840 + int point = sensor_attr->index; 841 + long val; 842 + 843 + if (strict_strtol(buf, 10, &val) < 0 || val < -128000 || val > 127000) 844 + return -EINVAL; 845 + 846 + mutex_lock(&data->update_lock); 847 + data->auto_temp[nr][point] = TEMP_TO_REG(val); 848 + it87_write_value(data, IT87_REG_AUTO_TEMP(nr, point), 849 + data->auto_temp[nr][point]); 850 + mutex_unlock(&data->update_lock); 851 return count; 852 } 853 ··· 744 show_pwm, set_pwm, offset - 1); \ 745 static DEVICE_ATTR(pwm##offset##_freq, \ 746 (offset == 1 ? S_IRUGO | S_IWUSR : S_IRUGO), \ 747 + show_pwm_freq, (offset == 1 ? set_pwm_freq : NULL)); \ 748 + static SENSOR_DEVICE_ATTR(pwm##offset##_auto_channels_temp, \ 749 + S_IRUGO | S_IWUSR, show_pwm_temp_map, set_pwm_temp_map, \ 750 + offset - 1); \ 751 + static SENSOR_DEVICE_ATTR_2(pwm##offset##_auto_point1_pwm, \ 752 + S_IRUGO | S_IWUSR, show_auto_pwm, set_auto_pwm, \ 753 + offset - 1, 0); \ 754 + static SENSOR_DEVICE_ATTR_2(pwm##offset##_auto_point2_pwm, \ 755 + S_IRUGO | S_IWUSR, show_auto_pwm, set_auto_pwm, \ 756 + offset - 1, 1); \ 757 + static SENSOR_DEVICE_ATTR_2(pwm##offset##_auto_point3_pwm, \ 758 + S_IRUGO | S_IWUSR, show_auto_pwm, set_auto_pwm, \ 759 + offset - 1, 2); \ 760 + static SENSOR_DEVICE_ATTR_2(pwm##offset##_auto_point4_pwm, \ 761 + S_IRUGO, show_auto_pwm, NULL, offset - 1, 3); \ 762 + static SENSOR_DEVICE_ATTR_2(pwm##offset##_auto_point1_temp, \ 763 + S_IRUGO | S_IWUSR, show_auto_temp, set_auto_temp, \ 764 + offset - 1, 1); \ 765 + static SENSOR_DEVICE_ATTR_2(pwm##offset##_auto_point1_temp_hyst, \ 766 + S_IRUGO | S_IWUSR, show_auto_temp, set_auto_temp, \ 767 + offset - 1, 0); \ 768 + static SENSOR_DEVICE_ATTR_2(pwm##offset##_auto_point2_temp, \ 769 + S_IRUGO | S_IWUSR, show_auto_temp, set_auto_temp, \ 770 + offset - 1, 2); \ 771 + static SENSOR_DEVICE_ATTR_2(pwm##offset##_auto_point3_temp, \ 772 + S_IRUGO | S_IWUSR, show_auto_temp, set_auto_temp, \ 773 + offset - 1, 3); \ 774 + static SENSOR_DEVICE_ATTR_2(pwm##offset##_auto_point4_temp, \ 775 + S_IRUGO | S_IWUSR, show_auto_temp, set_auto_temp, \ 776 + offset - 1, 4); 777 778 show_pwm_offset(1); 779 show_pwm_offset(2); ··· 775 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); 776 int nr = sensor_attr->index; 777 struct it87_data *data = dev_get_drvdata(dev); 778 + long val; 779 + 780 + if (strict_strtol(buf, 10, &val) < 0) 781 + return -EINVAL; 782 783 mutex_lock(&data->update_lock); 784 data->fan_min[nr] = FAN16_TO_REG(val); ··· 805 show_fan16_offset(5); 806 807 /* Alarms */ 808 + static ssize_t show_alarms(struct device *dev, struct device_attribute *attr, 809 + char *buf) 810 { 811 struct it87_data *data = it87_update_device(dev); 812 return sprintf(buf, "%u\n", data->alarms); ··· 836 static SENSOR_DEVICE_ATTR(temp2_alarm, S_IRUGO, show_alarm, NULL, 17); 837 static SENSOR_DEVICE_ATTR(temp3_alarm, S_IRUGO, show_alarm, NULL, 18); 838 839 + static ssize_t show_beep(struct device *dev, struct device_attribute *attr, 840 + char *buf) 841 + { 842 + int bitnr = to_sensor_dev_attr(attr)->index; 843 + struct it87_data *data = it87_update_device(dev); 844 + return sprintf(buf, "%u\n", (data->beeps >> bitnr) & 1); 845 + } 846 + static ssize_t set_beep(struct device *dev, struct device_attribute *attr, 847 + const char *buf, size_t count) 848 + { 849 + int bitnr = to_sensor_dev_attr(attr)->index; 850 + struct it87_data *data = dev_get_drvdata(dev); 851 + long val; 852 + 853 + if (strict_strtol(buf, 10, &val) < 0 854 + || (val != 0 && val != 1)) 855 + return -EINVAL; 856 + 857 + mutex_lock(&data->update_lock); 858 + data->beeps = it87_read_value(data, IT87_REG_BEEP_ENABLE); 859 + if (val) 860 + data->beeps |= (1 << bitnr); 861 + else 862 + data->beeps &= ~(1 << bitnr); 863 + it87_write_value(data, IT87_REG_BEEP_ENABLE, data->beeps); 864 + mutex_unlock(&data->update_lock); 865 + return count; 866 + } 867 + 868 + static SENSOR_DEVICE_ATTR(in0_beep, S_IRUGO | S_IWUSR, 869 + show_beep, set_beep, 1); 870 + static SENSOR_DEVICE_ATTR(in1_beep, S_IRUGO, show_beep, NULL, 1); 871 + static SENSOR_DEVICE_ATTR(in2_beep, S_IRUGO, show_beep, NULL, 1); 872 + static SENSOR_DEVICE_ATTR(in3_beep, S_IRUGO, show_beep, NULL, 1); 873 + static SENSOR_DEVICE_ATTR(in4_beep, S_IRUGO, show_beep, NULL, 1); 874 + static SENSOR_DEVICE_ATTR(in5_beep, S_IRUGO, show_beep, NULL, 1); 875 + static SENSOR_DEVICE_ATTR(in6_beep, S_IRUGO, show_beep, NULL, 1); 876 + static SENSOR_DEVICE_ATTR(in7_beep, S_IRUGO, show_beep, NULL, 1); 877 + /* fanX_beep writability is set later */ 878 + static SENSOR_DEVICE_ATTR(fan1_beep, S_IRUGO, show_beep, set_beep, 0); 879 + static SENSOR_DEVICE_ATTR(fan2_beep, S_IRUGO, show_beep, set_beep, 0); 880 + static SENSOR_DEVICE_ATTR(fan3_beep, S_IRUGO, show_beep, set_beep, 0); 881 + static SENSOR_DEVICE_ATTR(fan4_beep, S_IRUGO, show_beep, set_beep, 0); 882 + static SENSOR_DEVICE_ATTR(fan5_beep, S_IRUGO, show_beep, set_beep, 0); 883 + static SENSOR_DEVICE_ATTR(temp1_beep, S_IRUGO | S_IWUSR, 884 + show_beep, set_beep, 2); 885 + static SENSOR_DEVICE_ATTR(temp2_beep, S_IRUGO, show_beep, NULL, 2); 886 + static SENSOR_DEVICE_ATTR(temp3_beep, S_IRUGO, show_beep, NULL, 2); 887 + 888 + static ssize_t show_vrm_reg(struct device *dev, struct device_attribute *attr, 889 + char *buf) 890 { 891 struct it87_data *data = dev_get_drvdata(dev); 892 return sprintf(buf, "%u\n", data->vrm); 893 } 894 + static ssize_t store_vrm_reg(struct device *dev, struct device_attribute *attr, 895 + const char *buf, size_t count) 896 { 897 struct it87_data *data = dev_get_drvdata(dev); 898 + unsigned long val; 899 900 + if (strict_strtoul(buf, 10, &val) < 0) 901 + return -EINVAL; 902 + 903 data->vrm = val; 904 905 return count; 906 } 907 static DEVICE_ATTR(vrm, S_IRUGO | S_IWUSR, show_vrm_reg, store_vrm_reg); 908 909 + static ssize_t show_vid_reg(struct device *dev, struct device_attribute *attr, 910 + char *buf) 911 { 912 struct it87_data *data = it87_update_device(dev); 913 return sprintf(buf, "%ld\n", (long) vid_from_reg(data->vid, data->vrm)); ··· 931 .attrs = it87_attributes, 932 }; 933 934 + static struct attribute *it87_attributes_beep[] = { 935 + &sensor_dev_attr_in0_beep.dev_attr.attr, 936 + &sensor_dev_attr_in1_beep.dev_attr.attr, 937 + &sensor_dev_attr_in2_beep.dev_attr.attr, 938 + &sensor_dev_attr_in3_beep.dev_attr.attr, 939 + &sensor_dev_attr_in4_beep.dev_attr.attr, 940 + &sensor_dev_attr_in5_beep.dev_attr.attr, 941 + &sensor_dev_attr_in6_beep.dev_attr.attr, 942 + &sensor_dev_attr_in7_beep.dev_attr.attr, 943 + 944 + &sensor_dev_attr_temp1_beep.dev_attr.attr, 945 + &sensor_dev_attr_temp2_beep.dev_attr.attr, 946 + &sensor_dev_attr_temp3_beep.dev_attr.attr, 947 + NULL 948 + }; 949 + 950 + static const struct attribute_group it87_group_beep = { 951 + .attrs = it87_attributes_beep, 952 + }; 953 + 954 + static struct attribute *it87_attributes_fan16[5][3+1] = { { 955 &sensor_dev_attr_fan1_input16.dev_attr.attr, 956 &sensor_dev_attr_fan1_min16.dev_attr.attr, 957 + &sensor_dev_attr_fan1_alarm.dev_attr.attr, 958 + NULL 959 + }, { 960 &sensor_dev_attr_fan2_input16.dev_attr.attr, 961 &sensor_dev_attr_fan2_min16.dev_attr.attr, 962 + &sensor_dev_attr_fan2_alarm.dev_attr.attr, 963 + NULL 964 + }, { 965 &sensor_dev_attr_fan3_input16.dev_attr.attr, 966 &sensor_dev_attr_fan3_min16.dev_attr.attr, 967 + &sensor_dev_attr_fan3_alarm.dev_attr.attr, 968 + NULL 969 + }, { 970 &sensor_dev_attr_fan4_input16.dev_attr.attr, 971 &sensor_dev_attr_fan4_min16.dev_attr.attr, 972 + &sensor_dev_attr_fan4_alarm.dev_attr.attr, 973 + NULL 974 + }, { 975 &sensor_dev_attr_fan5_input16.dev_attr.attr, 976 &sensor_dev_attr_fan5_min16.dev_attr.attr, 977 + &sensor_dev_attr_fan5_alarm.dev_attr.attr, 978 + NULL 979 + } }; 980 981 + static const struct attribute_group it87_group_fan16[5] = { 982 + { .attrs = it87_attributes_fan16[0] }, 983 + { .attrs = it87_attributes_fan16[1] }, 984 + { .attrs = it87_attributes_fan16[2] }, 985 + { .attrs = it87_attributes_fan16[3] }, 986 + { .attrs = it87_attributes_fan16[4] }, 987 + }; 988 + 989 + static struct attribute *it87_attributes_fan[3][4+1] = { { 990 &sensor_dev_attr_fan1_input.dev_attr.attr, 991 &sensor_dev_attr_fan1_min.dev_attr.attr, 992 &sensor_dev_attr_fan1_div.dev_attr.attr, 993 + &sensor_dev_attr_fan1_alarm.dev_attr.attr, 994 + NULL 995 + }, { 996 &sensor_dev_attr_fan2_input.dev_attr.attr, 997 &sensor_dev_attr_fan2_min.dev_attr.attr, 998 &sensor_dev_attr_fan2_div.dev_attr.attr, 999 + &sensor_dev_attr_fan2_alarm.dev_attr.attr, 1000 + NULL 1001 + }, { 1002 &sensor_dev_attr_fan3_input.dev_attr.attr, 1003 &sensor_dev_attr_fan3_min.dev_attr.attr, 1004 &sensor_dev_attr_fan3_div.dev_attr.attr, 1005 &sensor_dev_attr_fan3_alarm.dev_attr.attr, 1006 + NULL 1007 + } }; 1008 1009 + static const struct attribute_group it87_group_fan[3] = { 1010 + { .attrs = it87_attributes_fan[0] }, 1011 + { .attrs = it87_attributes_fan[1] }, 1012 + { .attrs = it87_attributes_fan[2] }, 1013 + }; 1014 + 1015 + static const struct attribute_group * 1016 + it87_get_fan_group(const struct it87_data *data) 1017 + { 1018 + return has_16bit_fans(data) ? it87_group_fan16 : it87_group_fan; 1019 + } 1020 + 1021 + static struct attribute *it87_attributes_pwm[3][4+1] = { { 1022 &sensor_dev_attr_pwm1_enable.dev_attr.attr, 1023 &sensor_dev_attr_pwm1.dev_attr.attr, 1024 &dev_attr_pwm1_freq.attr, 1025 + &sensor_dev_attr_pwm1_auto_channels_temp.dev_attr.attr, 1026 + NULL 1027 + }, { 1028 + &sensor_dev_attr_pwm2_enable.dev_attr.attr, 1029 + &sensor_dev_attr_pwm2.dev_attr.attr, 1030 &dev_attr_pwm2_freq.attr, 1031 + &sensor_dev_attr_pwm2_auto_channels_temp.dev_attr.attr, 1032 + NULL 1033 + }, { 1034 + &sensor_dev_attr_pwm3_enable.dev_attr.attr, 1035 + &sensor_dev_attr_pwm3.dev_attr.attr, 1036 &dev_attr_pwm3_freq.attr, 1037 + &sensor_dev_attr_pwm3_auto_channels_temp.dev_attr.attr, 1038 + NULL 1039 + } }; 1040 1041 + static const struct attribute_group it87_group_pwm[3] = { 1042 + { .attrs = it87_attributes_pwm[0] }, 1043 + { .attrs = it87_attributes_pwm[1] }, 1044 + { .attrs = it87_attributes_pwm[2] }, 1045 + }; 1046 + 1047 + static struct attribute *it87_attributes_autopwm[3][9+1] = { { 1048 + &sensor_dev_attr_pwm1_auto_point1_pwm.dev_attr.attr, 1049 + &sensor_dev_attr_pwm1_auto_point2_pwm.dev_attr.attr, 1050 + &sensor_dev_attr_pwm1_auto_point3_pwm.dev_attr.attr, 1051 + &sensor_dev_attr_pwm1_auto_point4_pwm.dev_attr.attr, 1052 + &sensor_dev_attr_pwm1_auto_point1_temp.dev_attr.attr, 1053 + &sensor_dev_attr_pwm1_auto_point1_temp_hyst.dev_attr.attr, 1054 + &sensor_dev_attr_pwm1_auto_point2_temp.dev_attr.attr, 1055 + &sensor_dev_attr_pwm1_auto_point3_temp.dev_attr.attr, 1056 + &sensor_dev_attr_pwm1_auto_point4_temp.dev_attr.attr, 1057 + NULL 1058 + }, { 1059 + &sensor_dev_attr_pwm2_auto_point1_pwm.dev_attr.attr, 1060 + &sensor_dev_attr_pwm2_auto_point2_pwm.dev_attr.attr, 1061 + &sensor_dev_attr_pwm2_auto_point3_pwm.dev_attr.attr, 1062 + &sensor_dev_attr_pwm2_auto_point4_pwm.dev_attr.attr, 1063 + &sensor_dev_attr_pwm2_auto_point1_temp.dev_attr.attr, 1064 + &sensor_dev_attr_pwm2_auto_point1_temp_hyst.dev_attr.attr, 1065 + &sensor_dev_attr_pwm2_auto_point2_temp.dev_attr.attr, 1066 + &sensor_dev_attr_pwm2_auto_point3_temp.dev_attr.attr, 1067 + &sensor_dev_attr_pwm2_auto_point4_temp.dev_attr.attr, 1068 + NULL 1069 + }, { 1070 + &sensor_dev_attr_pwm3_auto_point1_pwm.dev_attr.attr, 1071 + &sensor_dev_attr_pwm3_auto_point2_pwm.dev_attr.attr, 1072 + &sensor_dev_attr_pwm3_auto_point3_pwm.dev_attr.attr, 1073 + &sensor_dev_attr_pwm3_auto_point4_pwm.dev_attr.attr, 1074 + &sensor_dev_attr_pwm3_auto_point1_temp.dev_attr.attr, 1075 + &sensor_dev_attr_pwm3_auto_point1_temp_hyst.dev_attr.attr, 1076 + &sensor_dev_attr_pwm3_auto_point2_temp.dev_attr.attr, 1077 + &sensor_dev_attr_pwm3_auto_point3_temp.dev_attr.attr, 1078 + &sensor_dev_attr_pwm3_auto_point4_temp.dev_attr.attr, 1079 + NULL 1080 + } }; 1081 + 1082 + static const struct attribute_group it87_group_autopwm[3] = { 1083 + { .attrs = it87_attributes_autopwm[0] }, 1084 + { .attrs = it87_attributes_autopwm[1] }, 1085 + { .attrs = it87_attributes_autopwm[2] }, 1086 + }; 1087 + 1088 + static struct attribute *it87_attributes_fan_beep[] = { 1089 + &sensor_dev_attr_fan1_beep.dev_attr.attr, 1090 + &sensor_dev_attr_fan2_beep.dev_attr.attr, 1091 + &sensor_dev_attr_fan3_beep.dev_attr.attr, 1092 + &sensor_dev_attr_fan4_beep.dev_attr.attr, 1093 + &sensor_dev_attr_fan5_beep.dev_attr.attr, 1094 + }; 1095 + 1096 + static struct attribute *it87_attributes_vid[] = { 1097 &dev_attr_vrm.attr, 1098 &dev_attr_cpu0_vid.attr, 1099 NULL 1100 }; 1101 1102 + static const struct attribute_group it87_group_vid = { 1103 + .attrs = it87_attributes_vid, 1104 }; 1105 1106 /* SuperIO detection - will change isa_address if a chip is found */ ··· 1035 if (sio_data->type == it87) { 1036 /* The IT8705F doesn't have VID pins at all */ 1037 sio_data->skip_vid = 1; 1038 + 1039 + /* The IT8705F has a different LD number for GPIO */ 1040 + superio_select(5); 1041 + sio_data->beep_pin = superio_inb(IT87_SIO_BEEP_PIN_REG) & 0x3f; 1042 } else { 1043 int reg; 1044 ··· 1068 pr_info("it87: in3 is VCC (+5V)\n"); 1069 if (reg & (1 << 1)) 1070 pr_info("it87: in7 is VCCH (+5V Stand-By)\n"); 1071 + 1072 + sio_data->beep_pin = superio_inb(IT87_SIO_BEEP_PIN_REG) & 0x3f; 1073 } 1074 + if (sio_data->beep_pin) 1075 + pr_info("it87: Beeping is supported\n"); 1076 1077 /* Disable specific features based on DMI strings */ 1078 board_vendor = dmi_get_system_info(DMI_BOARD_VENDOR); ··· 1093 return err; 1094 } 1095 1096 + static void it87_remove_files(struct device *dev) 1097 + { 1098 + struct it87_data *data = platform_get_drvdata(pdev); 1099 + struct it87_sio_data *sio_data = dev->platform_data; 1100 + const struct attribute_group *fan_group = it87_get_fan_group(data); 1101 + int i; 1102 + 1103 + sysfs_remove_group(&dev->kobj, &it87_group); 1104 + if (sio_data->beep_pin) 1105 + sysfs_remove_group(&dev->kobj, &it87_group_beep); 1106 + for (i = 0; i < 5; i++) { 1107 + if (!(data->has_fan & (1 << i))) 1108 + continue; 1109 + sysfs_remove_group(&dev->kobj, &fan_group[i]); 1110 + if (sio_data->beep_pin) 1111 + sysfs_remove_file(&dev->kobj, 1112 + it87_attributes_fan_beep[i]); 1113 + } 1114 + for (i = 0; i < 3; i++) { 1115 + if (sio_data->skip_pwm & (1 << 0)) 1116 + continue; 1117 + sysfs_remove_group(&dev->kobj, &it87_group_pwm[i]); 1118 + if (has_old_autopwm(data)) 1119 + sysfs_remove_group(&dev->kobj, 1120 + &it87_group_autopwm[i]); 1121 + } 1122 + if (!sio_data->skip_vid) 1123 + sysfs_remove_group(&dev->kobj, &it87_group_vid); 1124 + } 1125 + 1126 static int __devinit it87_probe(struct platform_device *pdev) 1127 { 1128 struct it87_data *data; 1129 struct resource *res; 1130 struct device *dev = &pdev->dev; 1131 struct it87_sio_data *sio_data = dev->platform_data; 1132 + const struct attribute_group *fan_group; 1133 + int err = 0, i; 1134 int enable_pwm_interface; 1135 + int fan_beep_need_rw; 1136 static const char *names[] = { 1137 "it87", 1138 "it8712", ··· 1118 goto ERROR0; 1119 } 1120 1121 + data = kzalloc(sizeof(struct it87_data), GFP_KERNEL); 1122 + if (!data) { 1123 err = -ENOMEM; 1124 goto ERROR1; 1125 } ··· 1146 it87_init_device(pdev); 1147 1148 /* Register sysfs hooks */ 1149 + err = sysfs_create_group(&dev->kobj, &it87_group); 1150 + if (err) 1151 goto ERROR2; 1152 1153 + if (sio_data->beep_pin) { 1154 + err = sysfs_create_group(&dev->kobj, &it87_group_beep); 1155 + if (err) 1156 + goto ERROR4; 1157 + } 1158 + 1159 /* Do not create fan files for disabled fans */ 1160 + fan_group = it87_get_fan_group(data); 1161 + fan_beep_need_rw = 1; 1162 + for (i = 0; i < 5; i++) { 1163 + if (!(data->has_fan & (1 << i))) 1164 + continue; 1165 + err = sysfs_create_group(&dev->kobj, &fan_group[i]); 1166 + if (err) 1167 + goto ERROR4; 1168 + 1169 + if (sio_data->beep_pin) { 1170 + err = sysfs_create_file(&dev->kobj, 1171 + it87_attributes_fan_beep[i]); 1172 + if (err) 1173 goto ERROR4; 1174 + if (!fan_beep_need_rw) 1175 + continue; 1176 + 1177 + /* As we have a single beep enable bit for all fans, 1178 + * only the first enabled fan has a writable attribute 1179 + * for it. */ 1180 + if (sysfs_chmod_file(&dev->kobj, 1181 + it87_attributes_fan_beep[i], 1182 + S_IRUGO | S_IWUSR)) 1183 + dev_dbg(dev, "chmod +w fan%d_beep failed\n", 1184 + i + 1); 1185 + fan_beep_need_rw = 0; 1186 } 1187 } 1188 1189 if (enable_pwm_interface) { 1190 + for (i = 0; i < 3; i++) { 1191 + if (sio_data->skip_pwm & (1 << i)) 1192 + continue; 1193 + err = sysfs_create_group(&dev->kobj, 1194 + &it87_group_pwm[i]); 1195 + if (err) 1196 goto ERROR4; 1197 + 1198 + if (!has_old_autopwm(data)) 1199 + continue; 1200 + err = sysfs_create_group(&dev->kobj, 1201 + &it87_group_autopwm[i]); 1202 + if (err) 1203 goto ERROR4; 1204 } 1205 } ··· 1268 data->vrm = vid_which_vrm(); 1269 /* VID reading from Super-I/O config space if available */ 1270 data->vid = sio_data->vid_value; 1271 + err = sysfs_create_group(&dev->kobj, &it87_group_vid); 1272 + if (err) 1273 goto ERROR4; 1274 } 1275 ··· 1284 return 0; 1285 1286 ERROR4: 1287 + it87_remove_files(dev); 1288 ERROR2: 1289 platform_set_drvdata(pdev, NULL); 1290 kfree(data); ··· 1300 struct it87_data *data = platform_get_drvdata(pdev); 1301 1302 hwmon_device_unregister(data->hwmon_dev); 1303 + it87_remove_files(&pdev->dev); 1304 1305 release_region(data->addr, IT87_EC_EXTENT); 1306 platform_set_drvdata(pdev, NULL); ··· 1387 int tmp, i; 1388 u8 mask; 1389 1390 + /* For each PWM channel: 1391 + * - If it is in automatic mode, setting to manual mode should set 1392 + * the fan to full speed by default. 1393 + * - If it is in manual mode, we need a mapping to temperature 1394 + * channels to use when later setting to automatic mode later. 1395 + * Use a 1:1 mapping by default (we are clueless.) 1396 + * In both cases, the value can (and should) be changed by the user 1397 + * prior to switching to a different mode. */ 1398 for (i = 0; i < 3; i++) { 1399 + data->pwm_temp_map[i] = i; 1400 + data->pwm_duty[i] = 0x7f; /* Full speed */ 1401 + data->auto_pwm[i][3] = 0x7f; /* Full speed, hard-coded */ 1402 } 1403 1404 /* Some chips seem to have default value 0xff for all limit ··· 1436 if ((data->fan_main_ctrl & mask) == 0) { 1437 /* Enable all fan tachometers */ 1438 data->fan_main_ctrl |= mask; 1439 + it87_write_value(data, IT87_REG_FAN_MAIN_CTRL, 1440 + data->fan_main_ctrl); 1441 } 1442 data->has_fan = (data->fan_main_ctrl >> 4) & 0x07; 1443 ··· 1461 /* Fan input pins may be used for alternative functions */ 1462 data->has_fan &= ~sio_data->skip_fan; 1463 1464 /* Start monitoring */ 1465 it87_write_value(data, IT87_REG_CONFIG, 1466 (it87_read_value(data, IT87_REG_CONFIG) & 0x36) 1467 | (update_vbat ? 0x41 : 0x01)); 1468 + } 1469 + 1470 + static void it87_update_pwm_ctrl(struct it87_data *data, int nr) 1471 + { 1472 + data->pwm_ctrl[nr] = it87_read_value(data, IT87_REG_PWM(nr)); 1473 + if (data->pwm_ctrl[nr] & 0x80) /* Automatic mode */ 1474 + data->pwm_temp_map[nr] = data->pwm_ctrl[nr] & 0x03; 1475 + else /* Manual mode */ 1476 + data->pwm_duty[nr] = data->pwm_ctrl[nr] & 0x7f; 1477 + 1478 + if (has_old_autopwm(data)) { 1479 + int i; 1480 + 1481 + for (i = 0; i < 5 ; i++) 1482 + data->auto_temp[nr][i] = it87_read_value(data, 1483 + IT87_REG_AUTO_TEMP(nr, i)); 1484 + for (i = 0; i < 3 ; i++) 1485 + data->auto_pwm[nr][i] = it87_read_value(data, 1486 + IT87_REG_AUTO_PWM(nr, i)); 1487 + } 1488 } 1489 1490 static struct it87_data *it87_update_device(struct device *dev) ··· 1494 1495 if (time_after(jiffies, data->last_updated + HZ + HZ / 2) 1496 || !data->valid) { 1497 if (update_vbat) { 1498 /* Cleared after each update, so reenable. Value 1499 + returned by this read will be previous value */ 1500 it87_write_value(data, IT87_REG_CONFIG, 1501 + it87_read_value(data, IT87_REG_CONFIG) | 0x40); 1502 } 1503 for (i = 0; i <= 7; i++) { 1504 data->in[i] = 1505 + it87_read_value(data, IT87_REG_VIN(i)); 1506 data->in_min[i] = 1507 + it87_read_value(data, IT87_REG_VIN_MIN(i)); 1508 data->in_max[i] = 1509 + it87_read_value(data, IT87_REG_VIN_MAX(i)); 1510 } 1511 /* in8 (battery) has no limit registers */ 1512 + data->in[8] = it87_read_value(data, IT87_REG_VIN(8)); 1513 1514 for (i = 0; i < 5; i++) { 1515 /* Skip disabled fans */ ··· 1519 continue; 1520 1521 data->fan_min[i] = 1522 + it87_read_value(data, IT87_REG_FAN_MIN[i]); 1523 data->fan[i] = it87_read_value(data, 1524 IT87_REG_FAN[i]); 1525 /* Add high byte if in 16-bit mode */ ··· 1532 } 1533 for (i = 0; i < 3; i++) { 1534 data->temp[i] = 1535 + it87_read_value(data, IT87_REG_TEMP(i)); 1536 data->temp_high[i] = 1537 + it87_read_value(data, IT87_REG_TEMP_HIGH(i)); 1538 data->temp_low[i] = 1539 + it87_read_value(data, IT87_REG_TEMP_LOW(i)); 1540 } 1541 1542 /* Newer chips don't have clock dividers */ ··· 1551 it87_read_value(data, IT87_REG_ALARM1) | 1552 (it87_read_value(data, IT87_REG_ALARM2) << 8) | 1553 (it87_read_value(data, IT87_REG_ALARM3) << 16); 1554 + data->beeps = it87_read_value(data, IT87_REG_BEEP_ENABLE); 1555 + 1556 data->fan_main_ctrl = it87_read_value(data, 1557 IT87_REG_FAN_MAIN_CTRL); 1558 data->fan_ctl = it87_read_value(data, IT87_REG_FAN_CTL); 1559 + for (i = 0; i < 3; i++) 1560 + it87_update_pwm_ctrl(data, i); 1561 1562 data->sensor = it87_read_value(data, IT87_REG_TEMP_ENABLE); 1563 /* The 8705 does not have VID capability. ··· 1628 static int __init sm_it87_init(void) 1629 { 1630 int err; 1631 + unsigned short isa_address = 0; 1632 struct it87_sio_data sio_data; 1633 1634 memset(&sio_data, 0, sizeof(struct it87_sio_data)); ··· 1640 return err; 1641 1642 err = it87_device_add(isa_address, &sio_data); 1643 + if (err) { 1644 platform_driver_unregister(&it87_driver); 1645 return err; 1646 } ··· 1661 module_param(update_vbat, bool, 0); 1662 MODULE_PARM_DESC(update_vbat, "Update vbat if set else return powerup value"); 1663 module_param(fix_pwm_polarity, bool, 0); 1664 + MODULE_PARM_DESC(fix_pwm_polarity, 1665 + "Force PWM polarity to active high (DANGEROUS)"); 1666 MODULE_LICENSE("GPL"); 1667 1668 module_init(sm_it87_init);
+84 -5
drivers/hwmon/lm90.c
··· 1 /* 2 * lm90.c - Part of lm_sensors, Linux kernel modules for hardware 3 * monitoring 4 - * Copyright (C) 2003-2009 Jean Delvare <khali@linux-fr.org> 5 * 6 * Based on the lm83 driver. The LM90 is a sensor chip made by National 7 * Semiconductor. It reports up to two temperatures (its own plus up to ··· 93 static const unsigned short normal_i2c[] = { 94 0x18, 0x19, 0x1a, 0x29, 0x2a, 0x2b, 0x4c, 0x4d, 0x4e, I2C_CLIENT_END }; 95 96 - enum chips { lm90, adm1032, lm99, lm86, max6657, adt7461, max6680, max6646 }; 97 98 /* 99 * The LM90 registers ··· 152 static int lm90_probe(struct i2c_client *client, 153 const struct i2c_device_id *id); 154 static void lm90_init_client(struct i2c_client *client); 155 static int lm90_remove(struct i2c_client *client); 156 static struct lm90_data *lm90_update_device(struct device *dev); 157 ··· 175 { "max6659", max6657 }, 176 { "max6680", max6680 }, 177 { "max6681", max6680 }, 178 { } 179 }; 180 MODULE_DEVICE_TABLE(i2c, lm90_id); ··· 187 }, 188 .probe = lm90_probe, 189 .remove = lm90_remove, 190 .id_table = lm90_id, 191 .detect = lm90_detect, 192 .address_list = normal_i2c, ··· 204 unsigned long last_updated; /* in jiffies */ 205 int kind; 206 int flags; 207 208 /* registers values */ 209 s8 temp8[4]; /* 0: local low limit ··· 765 && reg_convrate <= 0x07) { 766 name = "max6646"; 767 } 768 } 769 770 if (!name) { /* identification failed */ ··· 807 if (data->kind == adm1032) { 808 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE)) 809 new_client->flags &= ~I2C_CLIENT_PEC; 810 } 811 812 /* Initialize the LM90 chip */ ··· 858 859 static void lm90_init_client(struct i2c_client *client) 860 { 861 - u8 config, config_orig; 862 struct lm90_data *data = i2c_get_clientdata(client); 863 864 /* ··· 870 dev_warn(&client->dev, "Initialization failed!\n"); 871 return; 872 } 873 - config_orig = config; 874 875 /* Check Temperature Range Select */ 876 if (data->kind == adt7461) { ··· 888 } 889 890 config &= 0xBF; /* run */ 891 - if (config != config_orig) /* Only write if changed */ 892 i2c_smbus_write_byte_data(client, LM90_REG_W_CONFIG1, config); 893 } 894 ··· 903 device_remove_file(&client->dev, 904 &sensor_dev_attr_temp2_offset.dev_attr); 905 906 kfree(data); 907 return 0; 908 } 909 910 static int lm90_read16(struct i2c_client *client, u8 regh, u8 regl, u16 *value) ··· 1029 data->temp11[3] = (h << 8) | l; 1030 } 1031 lm90_read_reg(client, LM90_REG_R_STATUS, &data->alarms); 1032 1033 data->last_updated = jiffies; 1034 data->valid = 1;
··· 1 /* 2 * lm90.c - Part of lm_sensors, Linux kernel modules for hardware 3 * monitoring 4 + * Copyright (C) 2003-2010 Jean Delvare <khali@linux-fr.org> 5 * 6 * Based on the lm83 driver. The LM90 is a sensor chip made by National 7 * Semiconductor. It reports up to two temperatures (its own plus up to ··· 93 static const unsigned short normal_i2c[] = { 94 0x18, 0x19, 0x1a, 0x29, 0x2a, 0x2b, 0x4c, 0x4d, 0x4e, I2C_CLIENT_END }; 95 96 + enum chips { lm90, adm1032, lm99, lm86, max6657, adt7461, max6680, max6646, 97 + w83l771 }; 98 99 /* 100 * The LM90 registers ··· 151 static int lm90_probe(struct i2c_client *client, 152 const struct i2c_device_id *id); 153 static void lm90_init_client(struct i2c_client *client); 154 + static void lm90_alert(struct i2c_client *client, unsigned int flag); 155 static int lm90_remove(struct i2c_client *client); 156 static struct lm90_data *lm90_update_device(struct device *dev); 157 ··· 173 { "max6659", max6657 }, 174 { "max6680", max6680 }, 175 { "max6681", max6680 }, 176 + { "w83l771", w83l771 }, 177 { } 178 }; 179 MODULE_DEVICE_TABLE(i2c, lm90_id); ··· 184 }, 185 .probe = lm90_probe, 186 .remove = lm90_remove, 187 + .alert = lm90_alert, 188 .id_table = lm90_id, 189 .detect = lm90_detect, 190 .address_list = normal_i2c, ··· 200 unsigned long last_updated; /* in jiffies */ 201 int kind; 202 int flags; 203 + 204 + u8 config_orig; /* Original configuration register value */ 205 + u8 alert_alarms; /* Which alarm bits trigger ALERT# */ 206 207 /* registers values */ 208 s8 temp8[4]; /* 0: local low limit ··· 758 && reg_convrate <= 0x07) { 759 name = "max6646"; 760 } 761 + } else 762 + if (address == 0x4C 763 + && man_id == 0x5C) { /* Winbond/Nuvoton */ 764 + if ((chip_id & 0xFE) == 0x10 /* W83L771AWG/ASG */ 765 + && (reg_config1 & 0x2A) == 0x00 766 + && reg_convrate <= 0x08) { 767 + name = "w83l771"; 768 + } 769 } 770 771 if (!name) { /* identification failed */ ··· 792 if (data->kind == adm1032) { 793 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE)) 794 new_client->flags &= ~I2C_CLIENT_PEC; 795 + } 796 + 797 + /* Different devices have different alarm bits triggering the 798 + * ALERT# output */ 799 + switch (data->kind) { 800 + case lm90: 801 + case lm99: 802 + case lm86: 803 + data->alert_alarms = 0x7b; 804 + break; 805 + default: 806 + data->alert_alarms = 0x7c; 807 + break; 808 } 809 810 /* Initialize the LM90 chip */ ··· 830 831 static void lm90_init_client(struct i2c_client *client) 832 { 833 + u8 config; 834 struct lm90_data *data = i2c_get_clientdata(client); 835 836 /* ··· 842 dev_warn(&client->dev, "Initialization failed!\n"); 843 return; 844 } 845 + data->config_orig = config; 846 847 /* Check Temperature Range Select */ 848 if (data->kind == adt7461) { ··· 860 } 861 862 config &= 0xBF; /* run */ 863 + if (config != data->config_orig) /* Only write if changed */ 864 i2c_smbus_write_byte_data(client, LM90_REG_W_CONFIG1, config); 865 } 866 ··· 875 device_remove_file(&client->dev, 876 &sensor_dev_attr_temp2_offset.dev_attr); 877 878 + /* Restore initial configuration */ 879 + i2c_smbus_write_byte_data(client, LM90_REG_W_CONFIG1, 880 + data->config_orig); 881 + 882 kfree(data); 883 return 0; 884 + } 885 + 886 + static void lm90_alert(struct i2c_client *client, unsigned int flag) 887 + { 888 + struct lm90_data *data = i2c_get_clientdata(client); 889 + u8 config, alarms; 890 + 891 + lm90_read_reg(client, LM90_REG_R_STATUS, &alarms); 892 + if ((alarms & 0x7f) == 0) { 893 + dev_info(&client->dev, "Everything OK\n"); 894 + } else { 895 + if (alarms & 0x61) 896 + dev_warn(&client->dev, 897 + "temp%d out of range, please check!\n", 1); 898 + if (alarms & 0x1a) 899 + dev_warn(&client->dev, 900 + "temp%d out of range, please check!\n", 2); 901 + if (alarms & 0x04) 902 + dev_warn(&client->dev, 903 + "temp%d diode open, please check!\n", 2); 904 + 905 + /* Disable ALERT# output, because these chips don't implement 906 + SMBus alert correctly; they should only hold the alert line 907 + low briefly. */ 908 + if ((data->kind == adm1032 || data->kind == adt7461) 909 + && (alarms & data->alert_alarms)) { 910 + dev_dbg(&client->dev, "Disabling ALERT#\n"); 911 + lm90_read_reg(client, LM90_REG_R_CONFIG1, &config); 912 + i2c_smbus_write_byte_data(client, LM90_REG_W_CONFIG1, 913 + config | 0x80); 914 + } 915 + } 916 } 917 918 static int lm90_read16(struct i2c_client *client, u8 regh, u8 regl, u16 *value) ··· 965 data->temp11[3] = (h << 8) | l; 966 } 967 lm90_read_reg(client, LM90_REG_R_STATUS, &data->alarms); 968 + 969 + /* Re-enable ALERT# output if it was originally enabled and 970 + * relevant alarms are all clear */ 971 + if ((data->config_orig & 0x80) == 0 972 + && (data->alarms & data->alert_alarms) == 0) { 973 + u8 config; 974 + 975 + lm90_read_reg(client, LM90_REG_R_CONFIG1, &config); 976 + if (config & 0x80) { 977 + dev_dbg(&client->dev, "Re-enabling ALERT#\n"); 978 + i2c_smbus_write_byte_data(client, 979 + LM90_REG_W_CONFIG1, 980 + config & ~0x80); 981 + } 982 + } 983 984 data->last_updated = jiffies; 985 data->valid = 1;
+3 -4
drivers/hwmon/tmp401.c
··· 134 struct mutex update_lock; 135 char valid; /* zero until following fields are valid */ 136 unsigned long last_updated; /* in jiffies */ 137 - int kind; 138 139 /* register values */ 140 u8 status; ··· 524 if (reg > 15) 525 return -ENODEV; 526 527 - strlcpy(info->type, tmp401_id[kind - 1].name, I2C_NAME_SIZE); 528 529 return 0; 530 } ··· 572 goto exit_remove; 573 } 574 575 - dev_info(&client->dev, "Detected TI %s chip\n", 576 - names[data->kind - 1]); 577 578 return 0; 579
··· 134 struct mutex update_lock; 135 char valid; /* zero until following fields are valid */ 136 unsigned long last_updated; /* in jiffies */ 137 + enum chips kind; 138 139 /* register values */ 140 u8 status; ··· 524 if (reg > 15) 525 return -ENODEV; 526 527 + strlcpy(info->type, tmp401_id[kind].name, I2C_NAME_SIZE); 528 529 return 0; 530 } ··· 572 goto exit_remove; 573 } 574 575 + dev_info(&client->dev, "Detected TI %s chip\n", names[data->kind]); 576 577 return 0; 578
+13 -11
drivers/hwmon/tmp421.c
··· 61 #define TMP423_DEVICE_ID 0x23 62 63 static const struct i2c_device_id tmp421_id[] = { 64 - { "tmp421", tmp421 }, 65 - { "tmp422", tmp422 }, 66 - { "tmp423", tmp423 }, 67 { } 68 }; 69 MODULE_DEVICE_TABLE(i2c, tmp421_id); ··· 73 struct mutex update_lock; 74 char valid; 75 unsigned long last_updated; 76 - int kind; 77 u8 config; 78 s16 temp[4]; 79 }; 80 81 static int temp_from_s16(s16 reg) 82 { 83 - int temp = reg; 84 85 return (temp * 1000 + 128) / 256; 86 } 87 88 static int temp_from_u16(u16 reg) 89 { 90 - int temp = reg; 91 92 /* Add offset for extended temperature range. */ 93 temp -= 64 * 256; ··· 109 data->config = i2c_smbus_read_byte_data(client, 110 TMP421_CONFIG_REG_1); 111 112 - for (i = 0; i <= data->kind; i++) { 113 data->temp[i] = i2c_smbus_read_byte_data(client, 114 TMP421_TEMP_MSB[i]) << 8; 115 data->temp[i] |= i2c_smbus_read_byte_data(client, ··· 168 devattr = container_of(a, struct device_attribute, attr); 169 index = to_sensor_dev_attr(devattr)->index; 170 171 - if (data->kind > index) 172 return a->mode; 173 174 return 0; ··· 254 return -ENODEV; 255 } 256 257 - strlcpy(info->type, tmp421_id[kind - 1].name, I2C_NAME_SIZE); 258 dev_info(&adapter->dev, "Detected TI %s chip at 0x%02x\n", 259 - names[kind - 1], client->addr); 260 261 return 0; 262 } ··· 273 274 i2c_set_clientdata(client, data); 275 mutex_init(&data->update_lock); 276 - data->kind = id->driver_data; 277 278 err = tmp421_init_client(client); 279 if (err)
··· 61 #define TMP423_DEVICE_ID 0x23 62 63 static const struct i2c_device_id tmp421_id[] = { 64 + { "tmp421", 2 }, 65 + { "tmp422", 3 }, 66 + { "tmp423", 4 }, 67 { } 68 }; 69 MODULE_DEVICE_TABLE(i2c, tmp421_id); ··· 73 struct mutex update_lock; 74 char valid; 75 unsigned long last_updated; 76 + int channels; 77 u8 config; 78 s16 temp[4]; 79 }; 80 81 static int temp_from_s16(s16 reg) 82 { 83 + /* Mask out status bits */ 84 + int temp = reg & ~0xf; 85 86 return (temp * 1000 + 128) / 256; 87 } 88 89 static int temp_from_u16(u16 reg) 90 { 91 + /* Mask out status bits */ 92 + int temp = reg & ~0xf; 93 94 /* Add offset for extended temperature range. */ 95 temp -= 64 * 256; ··· 107 data->config = i2c_smbus_read_byte_data(client, 108 TMP421_CONFIG_REG_1); 109 110 + for (i = 0; i < data->channels; i++) { 111 data->temp[i] = i2c_smbus_read_byte_data(client, 112 TMP421_TEMP_MSB[i]) << 8; 113 data->temp[i] |= i2c_smbus_read_byte_data(client, ··· 166 devattr = container_of(a, struct device_attribute, attr); 167 index = to_sensor_dev_attr(devattr)->index; 168 169 + if (index < data->channels) 170 return a->mode; 171 172 return 0; ··· 252 return -ENODEV; 253 } 254 255 + strlcpy(info->type, tmp421_id[kind].name, I2C_NAME_SIZE); 256 dev_info(&adapter->dev, "Detected TI %s chip at 0x%02x\n", 257 + names[kind], client->addr); 258 259 return 0; 260 } ··· 271 272 i2c_set_clientdata(client, data); 273 mutex_init(&data->update_lock); 274 + data->channels = id->driver_data; 275 276 err = tmp421_init_client(client); 277 if (err)
+480 -4
drivers/hwmon/w83793.c
··· 3 Copyright (C) 2006 Winbond Electronics Corp. 4 Yuan Mu 5 Rudolf Marek <r.marek@assembler.cz> 6 7 This program is free software; you can redistribute it and/or modify 8 it under the terms of the GNU General Public License as published by ··· 39 #include <linux/hwmon-sysfs.h> 40 #include <linux/err.h> 41 #include <linux/mutex.h> 42 43 /* Addresses to scan */ 44 static const unsigned short normal_i2c[] = { 0x2c, 0x2d, 0x2e, 0x2f, ··· 64 static int reset; 65 module_param(reset, bool, 0); 66 MODULE_PARM_DESC(reset, "Set to 1 to reset chip, not recommended"); 67 68 /* 69 Address 0x00, 0x0d, 0x0e, 0x0f in all three banks are reserved ··· 97 #define W83793_REG_VID_LATCHA 0x07 98 #define W83793_REG_VID_LATCHB 0x08 99 #define W83793_REG_VID_CTRL 0x59 100 101 static u16 W83793_REG_TEMP_MODE[2] = { 0x5e, 0x5f }; 102 ··· 254 u8 tolerance[3]; /* Temp tolerance(Smart Fan I/II) */ 255 u8 sf2_pwm[6][7]; /* Smart FanII: Fan duty cycle */ 256 u8 sf2_temp[6][7]; /* Smart FanII: Temp level point */ 257 }; 258 259 static u8 w83793_read_value(struct i2c_client *client, u16 reg); 260 static int w83793_write_value(struct i2c_client *client, u16 reg, u8 value); ··· 1123 /* Start monitoring */ 1124 w83793_write_value(client, W83793_REG_CONFIG, 1125 w83793_read_value(client, W83793_REG_CONFIG) | 0x01); 1126 - 1127 } 1128 1129 static int w83793_remove(struct i2c_client *client) 1130 { 1131 struct w83793_data *data = i2c_get_clientdata(client); 1132 struct device *dev = &client->dev; 1133 - int i; 1134 1135 hwmon_device_unregister(data->hwmon_dev); 1136 ··· 1494 if (data->lm75[1] != NULL) 1495 i2c_unregister_device(data->lm75[1]); 1496 1497 - kfree(data); 1498 1499 return 0; 1500 } ··· 1601 const struct i2c_device_id *id) 1602 { 1603 struct device *dev = &client->dev; 1604 struct w83793_data *data; 1605 int i, tmp, val, err; 1606 int files_fan = ARRAY_SIZE(w83793_left_fan) / 7; ··· 1617 i2c_set_clientdata(client, data); 1618 data->bank = i2c_smbus_read_byte_data(client, W83793_REG_BANKSEL); 1619 mutex_init(&data->update_lock); 1620 1621 err = w83793_detect_subclients(client); 1622 if (err) ··· 1787 goto exit_remove; 1788 } 1789 1790 return 0; 1791 1792 /* Unregister sysfs hooks */ 1793 ··· 2104 i2c_del_driver(&w83793_driver); 2105 } 2106 2107 - MODULE_AUTHOR("Yuan Mu"); 2108 MODULE_DESCRIPTION("w83793 driver"); 2109 MODULE_LICENSE("GPL"); 2110
··· 3 Copyright (C) 2006 Winbond Electronics Corp. 4 Yuan Mu 5 Rudolf Marek <r.marek@assembler.cz> 6 + Copyright (C) 2009-2010 Sven Anders <anders@anduras.de>, ANDURAS AG. 7 + Watchdog driver part 8 + (Based partially on fschmd driver, 9 + Copyright 2007-2008 by Hans de Goede) 10 11 This program is free software; you can redistribute it and/or modify 12 it under the terms of the GNU General Public License as published by ··· 35 #include <linux/hwmon-sysfs.h> 36 #include <linux/err.h> 37 #include <linux/mutex.h> 38 + #include <linux/fs.h> 39 + #include <linux/watchdog.h> 40 + #include <linux/miscdevice.h> 41 + #include <linux/uaccess.h> 42 + #include <linux/kref.h> 43 + #include <linux/notifier.h> 44 + #include <linux/reboot.h> 45 + 46 + /* Default values */ 47 + #define WATCHDOG_TIMEOUT 2 /* 2 minute default timeout */ 48 49 /* Addresses to scan */ 50 static const unsigned short normal_i2c[] = { 0x2c, 0x2d, 0x2e, 0x2f, ··· 50 static int reset; 51 module_param(reset, bool, 0); 52 MODULE_PARM_DESC(reset, "Set to 1 to reset chip, not recommended"); 53 + 54 + static int timeout = WATCHDOG_TIMEOUT; /* default timeout in minutes */ 55 + module_param(timeout, int, 0); 56 + MODULE_PARM_DESC(timeout, 57 + "Watchdog timeout in minutes. 2<= timeout <=255 (default=" 58 + __MODULE_STRING(WATCHDOG_TIMEOUT) ")"); 59 + 60 + static int nowayout = WATCHDOG_NOWAYOUT; 61 + module_param(nowayout, int, 0); 62 + MODULE_PARM_DESC(nowayout, 63 + "Watchdog cannot be stopped once started (default=" 64 + __MODULE_STRING(WATCHDOG_NOWAYOUT) ")"); 65 66 /* 67 Address 0x00, 0x0d, 0x0e, 0x0f in all three banks are reserved ··· 71 #define W83793_REG_VID_LATCHA 0x07 72 #define W83793_REG_VID_LATCHB 0x08 73 #define W83793_REG_VID_CTRL 0x59 74 + 75 + #define W83793_REG_WDT_LOCK 0x01 76 + #define W83793_REG_WDT_ENABLE 0x02 77 + #define W83793_REG_WDT_STATUS 0x03 78 + #define W83793_REG_WDT_TIMEOUT 0x04 79 80 static u16 W83793_REG_TEMP_MODE[2] = { 0x5e, 0x5f }; 81 ··· 223 u8 tolerance[3]; /* Temp tolerance(Smart Fan I/II) */ 224 u8 sf2_pwm[6][7]; /* Smart FanII: Fan duty cycle */ 225 u8 sf2_temp[6][7]; /* Smart FanII: Temp level point */ 226 + 227 + /* watchdog */ 228 + struct i2c_client *client; 229 + struct mutex watchdog_lock; 230 + struct list_head list; /* member of the watchdog_data_list */ 231 + struct kref kref; 232 + struct miscdevice watchdog_miscdev; 233 + unsigned long watchdog_is_open; 234 + char watchdog_expect_close; 235 + char watchdog_name[10]; /* must be unique to avoid sysfs conflict */ 236 + unsigned int watchdog_caused_reboot; 237 + int watchdog_timeout; /* watchdog timeout in minutes */ 238 }; 239 + 240 + /* Somewhat ugly :( global data pointer list with all devices, so that 241 + we can find our device data as when using misc_register. There is no 242 + other method to get to one's device data from the open file-op and 243 + for usage in the reboot notifier callback. */ 244 + static LIST_HEAD(watchdog_data_list); 245 + 246 + /* Note this lock not only protect list access, but also data.kref access */ 247 + static DEFINE_MUTEX(watchdog_data_mutex); 248 + 249 + /* Release our data struct when we're detached from the i2c client *and* all 250 + references to our watchdog device are released */ 251 + static void w83793_release_resources(struct kref *ref) 252 + { 253 + struct w83793_data *data = container_of(ref, struct w83793_data, kref); 254 + kfree(data); 255 + } 256 257 static u8 w83793_read_value(struct i2c_client *client, u16 reg); 258 static int w83793_write_value(struct i2c_client *client, u16 reg, u8 value); ··· 1063 /* Start monitoring */ 1064 w83793_write_value(client, W83793_REG_CONFIG, 1065 w83793_read_value(client, W83793_REG_CONFIG) | 0x01); 1066 } 1067 + 1068 + /* 1069 + * Watchdog routines 1070 + */ 1071 + 1072 + static int watchdog_set_timeout(struct w83793_data *data, int timeout) 1073 + { 1074 + int ret, mtimeout; 1075 + 1076 + mtimeout = DIV_ROUND_UP(timeout, 60); 1077 + 1078 + if (mtimeout > 255) 1079 + return -EINVAL; 1080 + 1081 + mutex_lock(&data->watchdog_lock); 1082 + if (!data->client) { 1083 + ret = -ENODEV; 1084 + goto leave; 1085 + } 1086 + 1087 + data->watchdog_timeout = mtimeout; 1088 + 1089 + /* Set Timeout value (in Minutes) */ 1090 + w83793_write_value(data->client, W83793_REG_WDT_TIMEOUT, 1091 + data->watchdog_timeout); 1092 + 1093 + ret = mtimeout * 60; 1094 + 1095 + leave: 1096 + mutex_unlock(&data->watchdog_lock); 1097 + return ret; 1098 + } 1099 + 1100 + static int watchdog_get_timeout(struct w83793_data *data) 1101 + { 1102 + int timeout; 1103 + 1104 + mutex_lock(&data->watchdog_lock); 1105 + timeout = data->watchdog_timeout * 60; 1106 + mutex_unlock(&data->watchdog_lock); 1107 + 1108 + return timeout; 1109 + } 1110 + 1111 + static int watchdog_trigger(struct w83793_data *data) 1112 + { 1113 + int ret = 0; 1114 + 1115 + mutex_lock(&data->watchdog_lock); 1116 + if (!data->client) { 1117 + ret = -ENODEV; 1118 + goto leave; 1119 + } 1120 + 1121 + /* Set Timeout value (in Minutes) */ 1122 + w83793_write_value(data->client, W83793_REG_WDT_TIMEOUT, 1123 + data->watchdog_timeout); 1124 + 1125 + leave: 1126 + mutex_unlock(&data->watchdog_lock); 1127 + return ret; 1128 + } 1129 + 1130 + static int watchdog_enable(struct w83793_data *data) 1131 + { 1132 + int ret = 0; 1133 + 1134 + mutex_lock(&data->watchdog_lock); 1135 + if (!data->client) { 1136 + ret = -ENODEV; 1137 + goto leave; 1138 + } 1139 + 1140 + /* Set initial timeout */ 1141 + w83793_write_value(data->client, W83793_REG_WDT_TIMEOUT, 1142 + data->watchdog_timeout); 1143 + 1144 + /* Enable Soft Watchdog */ 1145 + w83793_write_value(data->client, W83793_REG_WDT_LOCK, 0x55); 1146 + 1147 + leave: 1148 + mutex_unlock(&data->watchdog_lock); 1149 + return ret; 1150 + } 1151 + 1152 + static int watchdog_disable(struct w83793_data *data) 1153 + { 1154 + int ret = 0; 1155 + 1156 + mutex_lock(&data->watchdog_lock); 1157 + if (!data->client) { 1158 + ret = -ENODEV; 1159 + goto leave; 1160 + } 1161 + 1162 + /* Disable Soft Watchdog */ 1163 + w83793_write_value(data->client, W83793_REG_WDT_LOCK, 0xAA); 1164 + 1165 + leave: 1166 + mutex_unlock(&data->watchdog_lock); 1167 + return ret; 1168 + } 1169 + 1170 + static int watchdog_open(struct inode *inode, struct file *filp) 1171 + { 1172 + struct w83793_data *pos, *data = NULL; 1173 + int watchdog_is_open; 1174 + 1175 + /* We get called from drivers/char/misc.c with misc_mtx hold, and we 1176 + call misc_register() from w83793_probe() with watchdog_data_mutex 1177 + hold, as misc_register() takes the misc_mtx lock, this is a possible 1178 + deadlock, so we use mutex_trylock here. */ 1179 + if (!mutex_trylock(&watchdog_data_mutex)) 1180 + return -ERESTARTSYS; 1181 + list_for_each_entry(pos, &watchdog_data_list, list) { 1182 + if (pos->watchdog_miscdev.minor == iminor(inode)) { 1183 + data = pos; 1184 + break; 1185 + } 1186 + } 1187 + 1188 + /* Check, if device is already open */ 1189 + watchdog_is_open = test_and_set_bit(0, &data->watchdog_is_open); 1190 + 1191 + /* Increase data reference counter (if not already done). 1192 + Note we can never not have found data, so we don't check for this */ 1193 + if (!watchdog_is_open) 1194 + kref_get(&data->kref); 1195 + 1196 + mutex_unlock(&watchdog_data_mutex); 1197 + 1198 + /* Check, if device is already open and possibly issue error */ 1199 + if (watchdog_is_open) 1200 + return -EBUSY; 1201 + 1202 + /* Enable Soft Watchdog */ 1203 + watchdog_enable(data); 1204 + 1205 + /* Store pointer to data into filp's private data */ 1206 + filp->private_data = data; 1207 + 1208 + return nonseekable_open(inode, filp); 1209 + } 1210 + 1211 + static int watchdog_close(struct inode *inode, struct file *filp) 1212 + { 1213 + struct w83793_data *data = filp->private_data; 1214 + 1215 + if (data->watchdog_expect_close) { 1216 + watchdog_disable(data); 1217 + data->watchdog_expect_close = 0; 1218 + } else { 1219 + watchdog_trigger(data); 1220 + dev_crit(&data->client->dev, 1221 + "unexpected close, not stopping watchdog!\n"); 1222 + } 1223 + 1224 + clear_bit(0, &data->watchdog_is_open); 1225 + 1226 + /* Decrease data reference counter */ 1227 + mutex_lock(&watchdog_data_mutex); 1228 + kref_put(&data->kref, w83793_release_resources); 1229 + mutex_unlock(&watchdog_data_mutex); 1230 + 1231 + return 0; 1232 + } 1233 + 1234 + static ssize_t watchdog_write(struct file *filp, const char __user *buf, 1235 + size_t count, loff_t *offset) 1236 + { 1237 + size_t ret; 1238 + struct w83793_data *data = filp->private_data; 1239 + 1240 + if (count) { 1241 + if (!nowayout) { 1242 + size_t i; 1243 + 1244 + /* Clear it in case it was set with a previous write */ 1245 + data->watchdog_expect_close = 0; 1246 + 1247 + for (i = 0; i != count; i++) { 1248 + char c; 1249 + if (get_user(c, buf + i)) 1250 + return -EFAULT; 1251 + if (c == 'V') 1252 + data->watchdog_expect_close = 1; 1253 + } 1254 + } 1255 + ret = watchdog_trigger(data); 1256 + if (ret < 0) 1257 + return ret; 1258 + } 1259 + return count; 1260 + } 1261 + 1262 + static int watchdog_ioctl(struct inode *inode, struct file *filp, 1263 + unsigned int cmd, unsigned long arg) 1264 + { 1265 + static struct watchdog_info ident = { 1266 + .options = WDIOF_KEEPALIVEPING | 1267 + WDIOF_SETTIMEOUT | 1268 + WDIOF_CARDRESET, 1269 + .identity = "w83793 watchdog" 1270 + }; 1271 + 1272 + int val, ret = 0; 1273 + struct w83793_data *data = filp->private_data; 1274 + 1275 + switch (cmd) { 1276 + case WDIOC_GETSUPPORT: 1277 + if (!nowayout) 1278 + ident.options |= WDIOF_MAGICCLOSE; 1279 + if (copy_to_user((void __user *)arg, &ident, sizeof(ident))) 1280 + ret = -EFAULT; 1281 + break; 1282 + 1283 + case WDIOC_GETSTATUS: 1284 + val = data->watchdog_caused_reboot ? WDIOF_CARDRESET : 0; 1285 + ret = put_user(val, (int __user *)arg); 1286 + break; 1287 + 1288 + case WDIOC_GETBOOTSTATUS: 1289 + ret = put_user(0, (int __user *)arg); 1290 + break; 1291 + 1292 + case WDIOC_KEEPALIVE: 1293 + ret = watchdog_trigger(data); 1294 + break; 1295 + 1296 + case WDIOC_GETTIMEOUT: 1297 + val = watchdog_get_timeout(data); 1298 + ret = put_user(val, (int __user *)arg); 1299 + break; 1300 + 1301 + case WDIOC_SETTIMEOUT: 1302 + if (get_user(val, (int __user *)arg)) { 1303 + ret = -EFAULT; 1304 + break; 1305 + } 1306 + ret = watchdog_set_timeout(data, val); 1307 + if (ret > 0) 1308 + ret = put_user(ret, (int __user *)arg); 1309 + break; 1310 + 1311 + case WDIOC_SETOPTIONS: 1312 + if (get_user(val, (int __user *)arg)) { 1313 + ret = -EFAULT; 1314 + break; 1315 + } 1316 + 1317 + if (val & WDIOS_DISABLECARD) 1318 + ret = watchdog_disable(data); 1319 + else if (val & WDIOS_ENABLECARD) 1320 + ret = watchdog_enable(data); 1321 + else 1322 + ret = -EINVAL; 1323 + 1324 + break; 1325 + default: 1326 + ret = -ENOTTY; 1327 + } 1328 + 1329 + return ret; 1330 + } 1331 + 1332 + static const struct file_operations watchdog_fops = { 1333 + .owner = THIS_MODULE, 1334 + .llseek = no_llseek, 1335 + .open = watchdog_open, 1336 + .release = watchdog_close, 1337 + .write = watchdog_write, 1338 + .ioctl = watchdog_ioctl, 1339 + }; 1340 + 1341 + /* 1342 + * Notifier for system down 1343 + */ 1344 + 1345 + static int watchdog_notify_sys(struct notifier_block *this, unsigned long code, 1346 + void *unused) 1347 + { 1348 + struct w83793_data *data = NULL; 1349 + 1350 + if (code == SYS_DOWN || code == SYS_HALT) { 1351 + 1352 + /* Disable each registered watchdog */ 1353 + mutex_lock(&watchdog_data_mutex); 1354 + list_for_each_entry(data, &watchdog_data_list, list) { 1355 + if (data->watchdog_miscdev.minor) 1356 + watchdog_disable(data); 1357 + } 1358 + mutex_unlock(&watchdog_data_mutex); 1359 + } 1360 + 1361 + return NOTIFY_DONE; 1362 + } 1363 + 1364 + /* 1365 + * The WDT needs to learn about soft shutdowns in order to 1366 + * turn the timebomb registers off. 1367 + */ 1368 + 1369 + static struct notifier_block watchdog_notifier = { 1370 + .notifier_call = watchdog_notify_sys, 1371 + }; 1372 + 1373 + /* 1374 + * Init / remove routines 1375 + */ 1376 1377 static int w83793_remove(struct i2c_client *client) 1378 { 1379 struct w83793_data *data = i2c_get_clientdata(client); 1380 struct device *dev = &client->dev; 1381 + int i, tmp; 1382 + 1383 + /* Unregister the watchdog (if registered) */ 1384 + if (data->watchdog_miscdev.minor) { 1385 + misc_deregister(&data->watchdog_miscdev); 1386 + 1387 + if (data->watchdog_is_open) { 1388 + dev_warn(&client->dev, 1389 + "i2c client detached with watchdog open! " 1390 + "Stopping watchdog.\n"); 1391 + watchdog_disable(data); 1392 + } 1393 + 1394 + mutex_lock(&watchdog_data_mutex); 1395 + list_del(&data->list); 1396 + mutex_unlock(&watchdog_data_mutex); 1397 + 1398 + /* Tell the watchdog code the client is gone */ 1399 + mutex_lock(&data->watchdog_lock); 1400 + data->client = NULL; 1401 + mutex_unlock(&data->watchdog_lock); 1402 + } 1403 + 1404 + /* Reset Configuration Register to Disable Watch Dog Registers */ 1405 + tmp = w83793_read_value(client, W83793_REG_CONFIG); 1406 + w83793_write_value(client, W83793_REG_CONFIG, tmp & ~0x04); 1407 + 1408 + unregister_reboot_notifier(&watchdog_notifier); 1409 1410 hwmon_device_unregister(data->hwmon_dev); 1411 ··· 1099 if (data->lm75[1] != NULL) 1100 i2c_unregister_device(data->lm75[1]); 1101 1102 + /* Decrease data reference counter */ 1103 + mutex_lock(&watchdog_data_mutex); 1104 + kref_put(&data->kref, w83793_release_resources); 1105 + mutex_unlock(&watchdog_data_mutex); 1106 1107 return 0; 1108 } ··· 1203 const struct i2c_device_id *id) 1204 { 1205 struct device *dev = &client->dev; 1206 + const int watchdog_minors[] = { WATCHDOG_MINOR, 212, 213, 214, 215 }; 1207 struct w83793_data *data; 1208 int i, tmp, val, err; 1209 int files_fan = ARRAY_SIZE(w83793_left_fan) / 7; ··· 1218 i2c_set_clientdata(client, data); 1219 data->bank = i2c_smbus_read_byte_data(client, W83793_REG_BANKSEL); 1220 mutex_init(&data->update_lock); 1221 + mutex_init(&data->watchdog_lock); 1222 + INIT_LIST_HEAD(&data->list); 1223 + kref_init(&data->kref); 1224 + 1225 + /* Store client pointer in our data struct for watchdog usage 1226 + (where the client is found through a data ptr instead of the 1227 + otherway around) */ 1228 + data->client = client; 1229 1230 err = w83793_detect_subclients(client); 1231 if (err) ··· 1380 goto exit_remove; 1381 } 1382 1383 + /* Watchdog initialization */ 1384 + 1385 + /* Register boot notifier */ 1386 + err = register_reboot_notifier(&watchdog_notifier); 1387 + if (err != 0) { 1388 + dev_err(&client->dev, 1389 + "cannot register reboot notifier (err=%d)\n", err); 1390 + goto exit_devunreg; 1391 + } 1392 + 1393 + /* Enable Watchdog registers. 1394 + Set Configuration Register to Enable Watch Dog Registers 1395 + (Bit 2) = XXXX, X1XX. */ 1396 + tmp = w83793_read_value(client, W83793_REG_CONFIG); 1397 + w83793_write_value(client, W83793_REG_CONFIG, tmp | 0x04); 1398 + 1399 + /* Set the default watchdog timeout */ 1400 + data->watchdog_timeout = timeout; 1401 + 1402 + /* Check, if last reboot was caused by watchdog */ 1403 + data->watchdog_caused_reboot = 1404 + w83793_read_value(data->client, W83793_REG_WDT_STATUS) & 0x01; 1405 + 1406 + /* Disable Soft Watchdog during initialiation */ 1407 + watchdog_disable(data); 1408 + 1409 + /* We take the data_mutex lock early so that watchdog_open() cannot 1410 + run when misc_register() has completed, but we've not yet added 1411 + our data to the watchdog_data_list (and set the default timeout) */ 1412 + mutex_lock(&watchdog_data_mutex); 1413 + for (i = 0; i < ARRAY_SIZE(watchdog_minors); i++) { 1414 + /* Register our watchdog part */ 1415 + snprintf(data->watchdog_name, sizeof(data->watchdog_name), 1416 + "watchdog%c", (i == 0) ? '\0' : ('0' + i)); 1417 + data->watchdog_miscdev.name = data->watchdog_name; 1418 + data->watchdog_miscdev.fops = &watchdog_fops; 1419 + data->watchdog_miscdev.minor = watchdog_minors[i]; 1420 + 1421 + err = misc_register(&data->watchdog_miscdev); 1422 + if (err == -EBUSY) 1423 + continue; 1424 + if (err) { 1425 + data->watchdog_miscdev.minor = 0; 1426 + dev_err(&client->dev, 1427 + "Registering watchdog chardev: %d\n", err); 1428 + break; 1429 + } 1430 + 1431 + list_add(&data->list, &watchdog_data_list); 1432 + 1433 + dev_info(&client->dev, 1434 + "Registered watchdog chardev major 10, minor: %d\n", 1435 + watchdog_minors[i]); 1436 + break; 1437 + } 1438 + if (i == ARRAY_SIZE(watchdog_minors)) { 1439 + data->watchdog_miscdev.minor = 0; 1440 + dev_warn(&client->dev, "Couldn't register watchdog chardev " 1441 + "(due to no free minor)\n"); 1442 + } 1443 + 1444 + mutex_unlock(&watchdog_data_mutex); 1445 + 1446 return 0; 1447 + 1448 + /* Unregister hwmon device */ 1449 + 1450 + exit_devunreg: 1451 + 1452 + hwmon_device_unregister(data->hwmon_dev); 1453 1454 /* Unregister sysfs hooks */ 1455 ··· 1628 i2c_del_driver(&w83793_driver); 1629 } 1630 1631 + MODULE_AUTHOR("Yuan Mu, Sven Anders"); 1632 MODULE_DESCRIPTION("w83793 driver"); 1633 MODULE_LICENSE("GPL"); 1634