Merge branch 'release' of git://lm-sensors.org/kernel/mhoffman/hwmon-2.6

* 'release' of git://lm-sensors.org/kernel/mhoffman/hwmon-2.6: (44 commits)
i2c: Delete the i2c-isa pseudo bus driver
hwmon: refuse to load abituguru driver on non-Abit boards
hwmon: fix Abit Uguru3 driver detection on some motherboards
hwmon/w83627ehf: Be quiet when no chip is found
hwmon/w83627ehf: No need to initialize fan_min
hwmon/w83627ehf: Export the thermal sensor types
hwmon/w83627ehf: Enable VBAT monitoring
hwmon/w83627ehf: Add support for the VID inputs
hwmon/w83627ehf: Fix timing issues
hwmon/w83627ehf: Add error messages for two error cases
hwmon/w83627ehf: Convert to a platform driver
hwmon/w83627ehf: Update the Kconfig entry
make coretemp_device_remove() static
hwmon: Add LM93 support
hwmon: Improve the pwmN_enable documentation
hwmon/smsc47b397: Don't report missing fans as spinning at 82 RPM
hwmon: Add support for newer uGuru's
hwmon/f71805f: Add temperature-tracking fan control mode
hwmon/w83627ehf: Preserve speed reading when changing fan min
hwmon: fix detection of abituguru volt inputs
...

Manual fixup of trivial conflict in MAINTAINERS file

+8803 -1715
-9
Documentation/feature-removal-schedule.txt
··· 164 165 --------------------------- 166 167 - What: i2c-isa 168 - When: December 2006 169 - Why: i2c-isa is a non-sense and doesn't fit in the device driver 170 - model. Drivers relying on it are better implemented as platform 171 - drivers. 172 - Who: Jean Delvare <khali@linux-fr.org> 173 - 174 - --------------------------- 175 - 176 What: i2c_adapter.list 177 When: July 2007 178 Why: Superfluous, this list duplicates the one maintained by the driver
··· 164 165 --------------------------- 166 167 What: i2c_adapter.list 168 When: July 2007 169 Why: Superfluous, this list duplicates the one maintained by the driver
+18 -13
Documentation/hwmon/abituguru
··· 2 ======================= 3 4 Supported chips: 5 - * Abit uGuru revision 1-3 (Hardware Monitor part only) 6 Prefix: 'abituguru' 7 Addresses scanned: ISA 0x0E0 8 Datasheet: Not available, this driver is based on reverse engineering. ··· 20 uGuru 2.1.0.0 ~ 2.1.2.8 (AS8, AV8, AA8, AG8, AA8XE, AX8) 21 uGuru 2.2.0.0 ~ 2.2.0.6 (AA8 Fatal1ty) 22 uGuru 2.3.0.0 ~ 2.3.0.9 (AN8) 23 - uGuru 3.0.0.0 ~ 3.0.1.2 (AW8, AL8, NI8) 24 - uGuru 4.xxxxx? (AT8 32X) (2) 25 1) For revisions 2 and 3 uGuru's the driver can autodetect the 26 sensortype (Volt or Temp) for bank1 sensors, for revision 1 uGuru's 27 this doesnot always work. For these uGuru's the autodection can ··· 30 bank1_types=1,1,0,0,0,0,0,2,0,0,0,0,2,0,0,1 31 You may also need to specify the fan_sensors option for these boards 32 fan_sensors=5 33 - 2) The current version of the abituguru driver is known to NOT work 34 - on these Motherboards 35 36 Authors: 37 Hans de Goede <j.w.r.degoede@hhs.nl>, ··· 44 ----------------- 45 46 * force: bool Force detection. Note this parameter only causes the 47 - detection to be skipped, if the uGuru can't be read 48 - the module initialization (insmod) will still fail. 49 * bank1_types: int[] Bank1 sensortype autodetection override: 50 -1 autodetect (default) 51 0 volt sensor ··· 72 Description 73 ----------- 74 75 - This driver supports the hardware monitoring features of the Abit uGuru chip 76 - found on Abit uGuru featuring motherboards (most modern Abit motherboards). 77 78 - The uGuru chip in reality is a Winbond W83L950D in disguise (despite Abit 79 - claiming it is "a new microprocessor designed by the ABIT Engineers"). 80 - Unfortunatly this doesn't help since the W83L950D is a generic 81 - microcontroller with a custom Abit application running on it. 82 83 Despite Abit not releasing any information regarding the uGuru, Olle 84 Sandberg <ollebull@gmail.com> has managed to reverse engineer the sensor part
··· 2 ======================= 3 4 Supported chips: 5 + * Abit uGuru revision 1 & 2 (Hardware Monitor part only) 6 Prefix: 'abituguru' 7 Addresses scanned: ISA 0x0E0 8 Datasheet: Not available, this driver is based on reverse engineering. ··· 20 uGuru 2.1.0.0 ~ 2.1.2.8 (AS8, AV8, AA8, AG8, AA8XE, AX8) 21 uGuru 2.2.0.0 ~ 2.2.0.6 (AA8 Fatal1ty) 22 uGuru 2.3.0.0 ~ 2.3.0.9 (AN8) 23 + uGuru 3.0.0.0 ~ 3.0.x.x (AW8, AL8, AT8, NI8 SLI, AT8 32X, AN8 32X, 24 + AW9D-MAX) (2) 25 1) For revisions 2 and 3 uGuru's the driver can autodetect the 26 sensortype (Volt or Temp) for bank1 sensors, for revision 1 uGuru's 27 this doesnot always work. For these uGuru's the autodection can ··· 30 bank1_types=1,1,0,0,0,0,0,2,0,0,0,0,2,0,0,1 31 You may also need to specify the fan_sensors option for these boards 32 fan_sensors=5 33 + 2) There is a seperate abituguru3 driver for these motherboards, 34 + the abituguru (without the 3 !) driver will not work on these 35 + motherboards (and visa versa)! 36 37 Authors: 38 Hans de Goede <j.w.r.degoede@hhs.nl>, ··· 43 ----------------- 44 45 * force: bool Force detection. Note this parameter only causes the 46 + detection to be skipped, and thus the insmod to 47 + succeed. If the uGuru can't be read the actual hwmon 48 + driver will not load and thus no hwmon device will get 49 + registered. 50 * bank1_types: int[] Bank1 sensortype autodetection override: 51 -1 autodetect (default) 52 0 volt sensor ··· 69 Description 70 ----------- 71 72 + This driver supports the hardware monitoring features of the first and 73 + second revision of the Abit uGuru chip found on Abit uGuru featuring 74 + motherboards (most modern Abit motherboards). 75 76 + The first and second revision of the uGuru chip in reality is a Winbond 77 + W83L950D in disguise (despite Abit claiming it is "a new microprocessor 78 + designed by the ABIT Engineers"). Unfortunatly this doesn't help since the 79 + W83L950D is a generic microcontroller with a custom Abit application running 80 + on it. 81 82 Despite Abit not releasing any information regarding the uGuru, Olle 83 Sandberg <ollebull@gmail.com> has managed to reverse engineer the sensor part
+65
Documentation/hwmon/abituguru3
···
··· 1 + Kernel driver abituguru3 2 + ======================== 3 + 4 + Supported chips: 5 + * Abit uGuru revision 3 (Hardware Monitor part, reading only) 6 + Prefix: 'abituguru3' 7 + Addresses scanned: ISA 0x0E0 8 + Datasheet: Not available, this driver is based on reverse engineering. 9 + Note: 10 + The uGuru is a microcontroller with onboard firmware which programs 11 + it to behave as a hwmon IC. There are many different revisions of the 12 + firmware and thus effectivly many different revisions of the uGuru. 13 + Below is an incomplete list with which revisions are used for which 14 + Motherboards: 15 + uGuru 1.00 ~ 1.24 (AI7, KV8-MAX3, AN7) 16 + uGuru 2.0.0.0 ~ 2.0.4.2 (KV8-PRO) 17 + uGuru 2.1.0.0 ~ 2.1.2.8 (AS8, AV8, AA8, AG8, AA8XE, AX8) 18 + uGuru 2.3.0.0 ~ 2.3.0.9 (AN8) 19 + uGuru 3.0.0.0 ~ 3.0.x.x (AW8, AL8, AT8, NI8 SLI, AT8 32X, AN8 32X, 20 + AW9D-MAX) 21 + The abituguru3 driver is only for revison 3.0.x.x motherboards, 22 + this driver will not work on older motherboards. For older 23 + motherboards use the abituguru (without the 3 !) driver. 24 + 25 + Authors: 26 + Hans de Goede <j.w.r.degoede@hhs.nl>, 27 + (Initial reverse engineering done by Louis Kruger) 28 + 29 + 30 + Module Parameters 31 + ----------------- 32 + 33 + * force: bool Force detection. Note this parameter only causes the 34 + detection to be skipped, and thus the insmod to 35 + succeed. If the uGuru can't be read the actual hwmon 36 + driver will not load and thus no hwmon device will get 37 + registered. 38 + * verbose: bool Should the driver be verbose? 39 + 0/off/false normal output 40 + 1/on/true + verbose error reporting (default) 41 + Default: 1 (the driver is still in the testing phase) 42 + 43 + Description 44 + ----------- 45 + 46 + This driver supports the hardware monitoring features of the third revision of 47 + the Abit uGuru chip, found on recent Abit uGuru featuring motherboards. 48 + 49 + The 3rd revision of the uGuru chip in reality is a Winbond W83L951G. 50 + Unfortunatly this doesn't help since the W83L951G is a generic microcontroller 51 + with a custom Abit application running on it. 52 + 53 + Despite Abit not releasing any information regarding the uGuru revision 3, 54 + Louis Kruger has managed to reverse engineer the sensor part of the uGuru. 55 + Without his work this driver would not have been possible. 56 + 57 + Known Issues 58 + ------------ 59 + 60 + The voltage and frequency control parts of the Abit uGuru are not supported, 61 + neither is writing any of the sensor settings and writing / reading the 62 + fanspeed control registers (FanEQ) 63 + 64 + If you encounter any problems please mail me <j.w.r.degoede@hhs.nl> and 65 + include the output of: "dmesg | grep abituguru"
+257
Documentation/hwmon/dme1737
···
··· 1 + Kernel driver dme1737 2 + ===================== 3 + 4 + Supported chips: 5 + * SMSC DME1737 and compatibles (like Asus A8000) 6 + Prefix: 'dme1737' 7 + Addresses scanned: I2C 0x2c, 0x2d, 0x2e 8 + Datasheet: Provided by SMSC upon request and under NDA 9 + 10 + Authors: 11 + Juerg Haefliger <juergh@gmail.com> 12 + 13 + 14 + Module Parameters 15 + ----------------- 16 + 17 + * force_start: bool Enables the monitoring of voltage, fan and temp inputs 18 + and PWM output control functions. Using this parameter 19 + shouldn't be required since the BIOS usually takes care 20 + of this. 21 + 22 + Note that there is no need to use this parameter if the driver loads without 23 + complaining. The driver will say so if it is necessary. 24 + 25 + 26 + Description 27 + ----------- 28 + 29 + This driver implements support for the hardware monitoring capabilities of the 30 + SMSC DME1737 and Asus A8000 (which are the same) Super-I/O chips. This chip 31 + features monitoring of 3 temp sensors temp[1-3] (2 remote diodes and 1 32 + internal), 7 voltages in[0-6] (6 external and 1 internal) and 6 fan speeds 33 + fan[1-6]. Additionally, the chip implements 5 PWM outputs pwm[1-3,5-6] for 34 + controlling fan speeds both manually and automatically. 35 + 36 + Fan[3-6] and pwm[3,5-6] are optional features and their availability is 37 + dependent on the configuration of the chip. The driver will detect which 38 + features are present during initialization and create the sysfs attributes 39 + accordingly. 40 + 41 + 42 + Voltage Monitoring 43 + ------------------ 44 + 45 + The voltage inputs are sampled with 12-bit resolution and have internal 46 + scaling resistors. The values returned by the driver therefore reflect true 47 + millivolts and don't need scaling. The voltage inputs are mapped as follows 48 + (the last column indicates the input ranges): 49 + 50 + in0: +5VTR (+5V standby) 0V - 6.64V 51 + in1: Vccp (processor core) 0V - 3V 52 + in2: VCC (internal +3.3V) 0V - 4.38V 53 + in3: +5V 0V - 6.64V 54 + in4: +12V 0V - 16V 55 + in5: VTR (+3.3V standby) 0V - 4.38V 56 + in6: Vbat (+3.0V) 0V - 4.38V 57 + 58 + Each voltage input has associated min and max limits which trigger an alarm 59 + when crossed. 60 + 61 + 62 + Temperature Monitoring 63 + ---------------------- 64 + 65 + Temperatures are measured with 12-bit resolution and reported in millidegree 66 + Celsius. The chip also features offsets for all 3 temperature inputs which - 67 + when programmed - get added to the input readings. The chip does all the 68 + scaling by itself and the driver therefore reports true temperatures that don't 69 + need any user-space adjustments. The temperature inputs are mapped as follows 70 + (the last column indicates the input ranges): 71 + 72 + temp1: Remote diode 1 (3904 type) temperature -127C - +127C 73 + temp2: DME1737 internal temperature -127C - +127C 74 + temp3: Remote diode 2 (3904 type) temperature -127C - +127C 75 + 76 + Each temperature input has associated min and max limits which trigger an alarm 77 + when crossed. Additionally, each temperature input has a fault attribute that 78 + returns 1 when a faulty diode or an unconnected input is detected and 0 79 + otherwise. 80 + 81 + 82 + Fan Monitoring 83 + -------------- 84 + 85 + Fan RPMs are measured with 16-bit resolution. The chip provides inputs for 6 86 + fan tachometers. All 6 inputs have an associated min limit which triggers an 87 + alarm when crossed. Fan inputs 1-4 provide type attributes that need to be set 88 + to the number of pulses per fan revolution that the connected tachometer 89 + generates. Supported values are 1, 2, and 4. Fan inputs 5-6 only support fans 90 + that generate 2 pulses per revolution. Fan inputs 5-6 also provide a max 91 + attribute that needs to be set to the maximum attainable RPM (fan at 100% duty- 92 + cycle) of the input. The chip adjusts the sampling rate based on this value. 93 + 94 + 95 + PWM Output Control 96 + ------------------ 97 + 98 + This chip features 5 PWM outputs. PWM outputs 1-3 are associated with fan 99 + inputs 1-3 and PWM outputs 5-6 are associated with fan inputs 5-6. PWM outputs 100 + 1-3 can be configured to operate either in manual or automatic mode by setting 101 + the appropriate enable attribute accordingly. PWM outputs 5-6 can only operate 102 + in manual mode, their enable attributes are therefore read-only. When set to 103 + manual mode, the fan speed is set by writing the duty-cycle value to the 104 + appropriate PWM attribute. In automatic mode, the PWM attribute returns the 105 + current duty-cycle as set by the fan controller in the chip. All PWM outputs 106 + support the setting of the output frequency via the freq attribute. 107 + 108 + In automatic mode, the chip supports the setting of the PWM ramp rate which 109 + defines how fast the PWM output is adjusting to changes of the associated 110 + temperature input. Associating PWM outputs to temperature inputs is done via 111 + temperature zones. The chip features 3 zones whose assignments to temperature 112 + inputs is static and determined during initialization. These assignments can 113 + be retrieved via the zone[1-3]_auto_channels_temp attributes. Each PWM output 114 + is assigned to one (or hottest of multiple) temperature zone(s) through the 115 + pwm[1-3]_auto_channels_zone attributes. Each PWM output has 3 distinct output 116 + duty-cycles: full, low, and min. Full is internally hard-wired to 255 (100%) 117 + and low and min can be programmed via pwm[1-3]_auto_point1_pwm and 118 + pwm[1-3]_auto_pwm_min, respectively. The thermal thresholds of the zones are 119 + programmed via zone[1-3]_auto_point[1-3]_temp and 120 + zone[1-3]_auto_point1_temp_hyst: 121 + 122 + pwm[1-3]_auto_point2_pwm full-speed duty-cycle (255, i.e., 100%) 123 + pwm[1-3]_auto_point1_pwm low-speed duty-cycle 124 + pwm[1-3]_auto_pwm_min min-speed duty-cycle 125 + 126 + zone[1-3]_auto_point3_temp full-speed temp (all outputs) 127 + zone[1-3]_auto_point2_temp full-speed temp 128 + zone[1-3]_auto_point1_temp low-speed temp 129 + zone[1-3]_auto_point1_temp_hyst min-speed temp 130 + 131 + The chip adjusts the output duty-cycle linearly in the range of auto_point1_pwm 132 + to auto_point2_pwm if the temperature of the associated zone is between 133 + auto_point1_temp and auto_point2_temp. If the temperature drops below the 134 + auto_point1_temp_hyst value, the output duty-cycle is set to the auto_pwm_min 135 + value which only supports two values: 0 or auto_point1_pwm. That means that the 136 + fan either turns completely off or keeps spinning with the low-speed 137 + duty-cycle. If any of the temperatures rise above the auto_point3_temp value, 138 + all PWM outputs are set to 100% duty-cycle. 139 + 140 + Following is another representation of how the chip sets the output duty-cycle 141 + based on the temperature of the associated thermal zone: 142 + 143 + Duty-Cycle Duty-Cycle 144 + Temperature Rising Temp Falling Temp 145 + ----------- ----------- ------------ 146 + full-speed full-speed full-speed 147 + 148 + < linearly adjusted duty-cycle > 149 + 150 + low-speed low-speed low-speed 151 + min-speed low-speed 152 + min-speed min-speed min-speed 153 + min-speed min-speed 154 + 155 + 156 + Sysfs Attributes 157 + ---------------- 158 + 159 + Following is a list of all sysfs attributes that the driver provides, their 160 + permissions and a short description: 161 + 162 + Name Perm Description 163 + ---- ---- ----------- 164 + cpu0_vid RO CPU core reference voltage in 165 + millivolts. 166 + vrm RW Voltage regulator module version 167 + number. 168 + 169 + in[0-6]_input RO Measured voltage in millivolts. 170 + in[0-6]_min RW Low limit for voltage input. 171 + in[0-6]_max RW High limit for voltage input. 172 + in[0-6]_alarm RO Voltage input alarm. Returns 1 if 173 + voltage input is or went outside the 174 + associated min-max range, 0 otherwise. 175 + 176 + temp[1-3]_input RO Measured temperature in millidegree 177 + Celsius. 178 + temp[1-3]_min RW Low limit for temp input. 179 + temp[1-3]_max RW High limit for temp input. 180 + temp[1-3]_offset RW Offset for temp input. This value will 181 + be added by the chip to the measured 182 + temperature. 183 + temp[1-3]_alarm RO Alarm for temp input. Returns 1 if temp 184 + input is or went outside the associated 185 + min-max range, 0 otherwise. 186 + temp[1-3]_fault RO Temp input fault. Returns 1 if the chip 187 + detects a faulty thermal diode or an 188 + unconnected temp input, 0 otherwise. 189 + 190 + zone[1-3]_auto_channels_temp RO Temperature zone to temperature input 191 + mapping. This attribute is a bitfield 192 + and supports the following values: 193 + 1: temp1 194 + 2: temp2 195 + 4: temp3 196 + zone[1-3]_auto_point1_temp_hyst RW Auto PWM temp point1 hysteresis. The 197 + output of the corresponding PWM is set 198 + to the pwm_auto_min value if the temp 199 + falls below the auto_point1_temp_hyst 200 + value. 201 + zone[1-3]_auto_point[1-3]_temp RW Auto PWM temp points. Auto_point1 is 202 + the low-speed temp, auto_point2 is the 203 + full-speed temp, and auto_point3 is the 204 + temp at which all PWM outputs are set 205 + to full-speed (100% duty-cycle). 206 + 207 + fan[1-6]_input RO Measured fan speed in RPM. 208 + fan[1-6]_min RW Low limit for fan input. 209 + fan[1-6]_alarm RO Alarm for fan input. Returns 1 if fan 210 + input is or went below the associated 211 + min value, 0 otherwise. 212 + fan[1-4]_type RW Type of attached fan. Expressed in 213 + number of pulses per revolution that 214 + the fan generates. Supported values are 215 + 1, 2, and 4. 216 + fan[5-6]_max RW Max attainable RPM at 100% duty-cycle. 217 + Required for chip to adjust the 218 + sampling rate accordingly. 219 + 220 + pmw[1-3,5-6] RO/RW Duty-cycle of PWM output. Supported 221 + values are 0-255 (0%-100%). Only 222 + writeable if the associated PWM is in 223 + manual mode. 224 + pwm[1-3]_enable RW Enable of PWM outputs 1-3. Supported 225 + values are: 226 + 0: turned off (output @ 100%) 227 + 1: manual mode 228 + 2: automatic mode 229 + pwm[5-6]_enable RO Enable of PWM outputs 5-6. Always 230 + returns 1 since these 2 outputs are 231 + hard-wired to manual mode. 232 + pmw[1-3,5-6]_freq RW Frequency of PWM output. Supported 233 + values are in the range 11Hz-30000Hz 234 + (default is 25000Hz). 235 + pmw[1-3]_ramp_rate RW Ramp rate of PWM output. Determines how 236 + fast the PWM duty-cycle will change 237 + when the PWM is in automatic mode. 238 + Expressed in ms per PWM step. Supported 239 + values are in the range 0ms-206ms 240 + (default is 0, which means the duty- 241 + cycle changes instantly). 242 + pwm[1-3]_auto_channels_zone RW PWM output to temperature zone mapping. 243 + This attribute is a bitfield and 244 + supports the following values: 245 + 1: zone1 246 + 2: zone2 247 + 4: zone3 248 + 6: highest of zone[2-3] 249 + 7: highest of zone[1-3] 250 + pwm[1-3]_auto_pwm_min RW Auto PWM min pwm. Minimum PWM duty- 251 + cycle. Supported values are 0 or 252 + auto_point1_pwm. 253 + pwm[1-3]_auto_point1_pwm RW Auto PWM pwm point. Auto_point1 is the 254 + low-speed duty-cycle. 255 + pwm[1-3]_auto_point2_pwm RO Auto PWM pwm point. Auto_point2 is the 256 + full-speed duty-cycle which is hard- 257 + wired to 255 (100% duty-cycle).
+22 -13
Documentation/hwmon/f71805f
··· 5 * Fintek F71805F/FG 6 Prefix: 'f71805f' 7 Addresses scanned: none, address read from Super I/O config space 8 - Datasheet: Provided by Fintek on request 9 * Fintek F71872F/FG 10 Prefix: 'f71872f' 11 Addresses scanned: none, address read from Super I/O config space 12 - Datasheet: Provided by Fintek on request 13 14 Author: Jean Delvare <khali@linux-fr.org> 15 ··· 128 When the PWM method is used, you can select the operating frequency, 129 from 187.5 kHz (default) to 31 Hz. The best frequency depends on the 130 fan model. As a rule of thumb, lower frequencies seem to give better 131 - control, but may generate annoying high-pitch noise. Fintek recommends 132 not going below 1 kHz, as the fan tachometers get confused by lower 133 frequencies as well. 134 ··· 138 corresponds to a pwm value of 106 for the driver. The driver doesn't 139 enforce this limit though. 140 141 - Three different fan control modes are supported: 142 143 - * Manual mode 144 - You ask for a specific PWM duty cycle or DC voltage. 145 146 - * Fan speed mode 147 - You ask for a specific fan speed. This mode assumes that pwm1 148 - corresponds to fan1, pwm2 to fan2 and pwm3 to fan3. 149 150 - * Temperature mode 151 - You define 3 temperature/fan speed trip points, and the fan speed is 152 - adjusted depending on the measured temperature, using interpolation. 153 - This mode is not yet supported by the driver.
··· 5 * Fintek F71805F/FG 6 Prefix: 'f71805f' 7 Addresses scanned: none, address read from Super I/O config space 8 + Datasheet: Available from the Fintek website 9 * Fintek F71872F/FG 10 Prefix: 'f71872f' 11 Addresses scanned: none, address read from Super I/O config space 12 + Datasheet: Available from the Fintek website 13 14 Author: Jean Delvare <khali@linux-fr.org> 15 ··· 128 When the PWM method is used, you can select the operating frequency, 129 from 187.5 kHz (default) to 31 Hz. The best frequency depends on the 130 fan model. As a rule of thumb, lower frequencies seem to give better 131 + control, but may generate annoying high-pitch noise. So a frequency just 132 + above the audible range, such as 25 kHz, may be a good choice; if this 133 + doesn't give you good linear control, try reducing it. Fintek recommends 134 not going below 1 kHz, as the fan tachometers get confused by lower 135 frequencies as well. 136 ··· 136 corresponds to a pwm value of 106 for the driver. The driver doesn't 137 enforce this limit though. 138 139 + Three different fan control modes are supported; the mode number is written 140 + to the pwm<n>_enable file. 141 142 + * 1: Manual mode 143 + You ask for a specific PWM duty cycle or DC voltage by writing to the 144 + pwm<n> file. 145 146 + * 2: Temperature mode 147 + You define 3 temperature/fan speed trip points using the 148 + pwm<n>_auto_point<m>_temp and _fan files. These define a staircase 149 + relationship between temperature and fan speed with two additional points 150 + interpolated between the values that you define. When the temperature 151 + is below auto_point1_temp the fan is switched off. 152 153 + * 3: Fan speed mode 154 + You ask for a specific fan speed by writing to the fan<n>_target file. 155 + 156 + Both of the automatic modes require that pwm1 corresponds to fan1, pwm2 to 157 + fan2 and pwm3 to fan3. Temperature mode also requires that temp1 corresponds 158 + to pwm1 and fan1, etc.
+7 -2
Documentation/hwmon/it87
··· 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/ 15 - * IT8716F 16 Prefix: 'it8716' 17 Addresses scanned: from Super I/O config space (8 I/O ports) 18 Datasheet: Publicly available at the ITE website 19 http://www.ite.com.tw/product_info/file/pc/IT8716F_V0.3.ZIP 20 * IT8718F 21 Prefix: 'it8718' 22 Addresses scanned: from Super I/O config space (8 I/O ports) ··· 69 ----------- 70 71 This driver implements support for the IT8705F, IT8712F, IT8716F, 72 - IT8718F and SiS950 chips. 73 74 These chips are 'Super I/O chips', supporting floppy disks, infrared ports, 75 joysticks and other miscellaneous stuff. For hardware monitoring, they ··· 97 clock divider mess) but not compatible with the older chips and 98 revisions. For now, the driver only uses the 16-bit mode on the 99 IT8716F and IT8718F. 100 101 Temperatures are measured in degrees Celsius. An alarm is triggered once 102 when the Overtemperature Shutdown limit is crossed.
··· 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/ 15 + * IT8716F/IT8726F 16 Prefix: 'it8716' 17 Addresses scanned: from Super I/O config space (8 I/O ports) 18 Datasheet: Publicly available at the ITE website 19 http://www.ite.com.tw/product_info/file/pc/IT8716F_V0.3.ZIP 20 + http://www.ite.com.tw/product_info/file/pc/IT8726F_V0.3.pdf 21 * IT8718F 22 Prefix: 'it8718' 23 Addresses scanned: from Super I/O config space (8 I/O ports) ··· 68 ----------- 69 70 This driver implements support for the IT8705F, IT8712F, IT8716F, 71 + IT8718F, IT8726F and SiS950 chips. 72 73 These chips are 'Super I/O chips', supporting floppy disks, infrared ports, 74 joysticks and other miscellaneous stuff. For hardware monitoring, they ··· 96 clock divider mess) but not compatible with the older chips and 97 revisions. For now, the driver only uses the 16-bit mode on the 98 IT8716F and IT8718F. 99 + 100 + The IT8726F is just bit enhanced IT8716F with additional hardware 101 + for AMD power sequencing. Therefore the chip will appear as IT8716F 102 + to userspace applications. 103 104 Temperatures are measured in degrees Celsius. An alarm is triggered once 105 when the Overtemperature Shutdown limit is crossed.
+28 -8
Documentation/hwmon/lm90
··· 48 Addresses scanned: I2C 0x4c, 0x4d (unsupported 0x4e) 49 Datasheet: Publicly available at the Maxim website 50 http://www.maxim-ic.com/quick_view2.cfm/qv_pk/2578 51 52 53 Author: Jean Delvare <khali@linux-fr.org> ··· 71 The LM90 is a digital temperature sensor. It senses its own temperature as 72 well as the temperature of up to one external diode. It is compatible 73 with many other devices such as the LM86, the LM89, the LM99, the ADM1032, 74 - the MAX6657, MAX6658 and the MAX6659 all of which are supported by this driver. 75 - Note that there is no easy way to differentiate between the last three 76 - variants. The extra address and features of the MAX6659 are not supported by 77 - this driver. Additionally, the ADT7461 is supported if found in ADM1032 78 - compatibility mode. 79 80 The specificity of this family of chipsets over the ADM1021/LM84 81 family is that it features critical limits with hysteresis, and an ··· 109 * ALERT is triggered by open remote sensor. 110 * SMBus PEC support for Write Byte and Receive Byte transactions. 111 112 - ADT7461 113 * Extended temperature range (breaks compatibility) 114 * Lower resolution for remote temperature 115 116 MAX6657 and MAX6658: 117 * Remote sensor type selection 118 119 - MAX6659 120 * Selectable address 121 * Second critical temperature limit 122 * Remote sensor type selection 123 124 All temperature values are given in degrees Celsius. Resolution ··· 161 Additionally, the ADM1032 doesn't support SMBus Send Byte with PEC. 162 Instead, it will try to write the PEC value to the register (because the 163 SMBus Send Byte transaction with PEC is similar to a Write Byte transaction 164 - without PEC), which is not what we want. Thus, PEC is explicitely disabled 165 on SMBus Send Byte transactions in the lm90 driver. 166 167 PEC on byte data transactions represents a significant increase in bandwidth
··· 48 Addresses scanned: I2C 0x4c, 0x4d (unsupported 0x4e) 49 Datasheet: Publicly available at the Maxim website 50 http://www.maxim-ic.com/quick_view2.cfm/qv_pk/2578 51 + * Maxim MAX6680 52 + Prefix: 'max6680' 53 + Addresses scanned: I2C 0x18, 0x19, 0x1a, 0x29, 0x2a, 0x2b, 54 + 0x4c, 0x4d and 0x4e 55 + Datasheet: Publicly available at the Maxim website 56 + http://www.maxim-ic.com/quick_view2.cfm/qv_pk/3370 57 + * Maxim MAX6681 58 + Prefix: 'max6680' 59 + Addresses scanned: I2C 0x18, 0x19, 0x1a, 0x29, 0x2a, 0x2b, 60 + 0x4c, 0x4d and 0x4e 61 + Datasheet: Publicly available at the Maxim website 62 + http://www.maxim-ic.com/quick_view2.cfm/qv_pk/3370 63 64 65 Author: Jean Delvare <khali@linux-fr.org> ··· 59 The LM90 is a digital temperature sensor. It senses its own temperature as 60 well as the temperature of up to one external diode. It is compatible 61 with many other devices such as the LM86, the LM89, the LM99, the ADM1032, 62 + the MAX6657, MAX6658, MAX6659, MAX6680 and the MAX6681 all of which are 63 + supported by this driver. 64 + 65 + Note that there is no easy way to differentiate between the MAX6657, 66 + MAX6658 and MAX6659 variants. The extra address and features of the 67 + MAX6659 are not supported by this driver. The MAX6680 and MAX6681 only 68 + differ in their pinout, therefore they obviously can't (and don't need to) 69 + be distinguished. Additionally, the ADT7461 is supported if found in 70 + ADM1032 compatibility mode. 71 72 The specificity of this family of chipsets over the ADM1021/LM84 73 family is that it features critical limits with hysteresis, and an ··· 93 * ALERT is triggered by open remote sensor. 94 * SMBus PEC support for Write Byte and Receive Byte transactions. 95 96 + ADT7461: 97 * Extended temperature range (breaks compatibility) 98 * Lower resolution for remote temperature 99 100 MAX6657 and MAX6658: 101 * Remote sensor type selection 102 103 + MAX6659: 104 * Selectable address 105 * Second critical temperature limit 106 + * Remote sensor type selection 107 + 108 + MAX6680 and MAX6681: 109 + * Selectable address 110 * Remote sensor type selection 111 112 All temperature values are given in degrees Celsius. Resolution ··· 141 Additionally, the ADM1032 doesn't support SMBus Send Byte with PEC. 142 Instead, it will try to write the PEC value to the register (because the 143 SMBus Send Byte transaction with PEC is similar to a Write Byte transaction 144 + without PEC), which is not what we want. Thus, PEC is explicitly disabled 145 on SMBus Send Byte transactions in the lm90 driver. 146 147 PEC on byte data transactions represents a significant increase in bandwidth
+412
Documentation/hwmon/lm93
···
··· 1 + Kernel driver lm93 2 + ================== 3 + 4 + Supported chips: 5 + * National Semiconductor LM93 6 + Prefix 'lm93' 7 + Addresses scanned: I2C 0x2c-0x2e 8 + Datasheet: http://www.national.com/ds.cgi/LM/LM93.pdf 9 + 10 + Author: 11 + Mark M. Hoffman <mhoffman@lightlink.com> 12 + Ported to 2.6 by Eric J. Bowersox <ericb@aspsys.com> 13 + Adapted to 2.6.20 by Carsten Emde <ce@osadl.org> 14 + Modified for mainline integration by Hans J. Koch <hjk@linutronix.de> 15 + 16 + Module Parameters 17 + ----------------- 18 + 19 + (specific to LM93) 20 + * init: integer 21 + Set to non-zero to force some initializations (default is 0). 22 + * disable_block: integer 23 + A "0" allows SMBus block data transactions if the host supports them. A "1" 24 + disables SMBus block data transactions. The default is 0. 25 + * vccp_limit_type: integer array (2) 26 + Configures in7 and in8 limit type, where 0 means absolute and non-zero 27 + means relative. "Relative" here refers to "Dynamic Vccp Monitoring using 28 + VID" from the datasheet. It greatly simplifies the interface to allow 29 + only one set of limits (absolute or relative) to be in operation at a 30 + time (even though the hardware is capable of enabling both). There's 31 + not a compelling use case for enabling both at once, anyway. The default 32 + is "0,0". 33 + * vid_agtl: integer 34 + A "0" configures the VID pins for V(ih) = 2.1V min, V(il) = 0.8V max. 35 + A "1" configures the VID pins for V(ih) = 0.8V min, V(il) = 0.4V max. 36 + (The latter setting is referred to as AGTL+ Compatible in the datasheet.) 37 + I.e. this parameter controls the VID pin input thresholds; if your VID 38 + inputs are not working, try changing this. The default value is "0". 39 + 40 + (common among sensor drivers) 41 + * force: short array (min = 1, max = 48) 42 + List of adapter,address pairs to assume to be present. Autodetection 43 + of the target device will still be attempted. Use one of the more 44 + specific force directives below if this doesn't detect the device. 45 + * force_lm93: short array (min = 1, max = 48) 46 + List of adapter,address pairs which are unquestionably assumed to contain 47 + a 'lm93' chip 48 + * ignore: short array (min = 1, max = 48) 49 + List of adapter,address pairs not to scan 50 + * ignore_range: short array (min = 1, max = 48) 51 + List of adapter,start-addr,end-addr triples not to scan 52 + * probe: short array (min = 1, max = 48) 53 + List of adapter,address pairs to scan additionally 54 + * probe_range: short array (min = 1, max = 48) 55 + List of adapter,start-addr,end-addr triples to scan additionally 56 + 57 + 58 + Hardware Description 59 + -------------------- 60 + 61 + (from the datasheet) 62 + 63 + The LM93, hardware monitor, has a two wire digital interface compatible with 64 + SMBus 2.0. Using an 8-bit ADC, the LM93 measures the temperature of two remote 65 + diode connected transistors as well as its own die and 16 power supply 66 + voltages. To set fan speed, the LM93 has two PWM outputs that are each 67 + controlled by up to four temperature zones. The fancontrol algorithm is lookup 68 + table based. The LM93 includes a digital filter that can be invoked to smooth 69 + temperature readings for better control of fan speed. The LM93 has four 70 + tachometer inputs to measure fan speed. Limit and status registers for all 71 + measured values are included. The LM93 builds upon the functionality of 72 + previous motherboard management ASICs and uses some of the LM85 s features 73 + (i.e. smart tachometer mode). It also adds measurement and control support 74 + for dynamic Vccp monitoring and PROCHOT. It is designed to monitor a dual 75 + processor Xeon class motherboard with a minimum of external components. 76 + 77 + 78 + Driver Description 79 + ------------------ 80 + 81 + This driver implements support for the National Semiconductor LM93. 82 + 83 + 84 + User Interface 85 + -------------- 86 + 87 + #PROCHOT: 88 + 89 + The LM93 can monitor two #PROCHOT signals. The results are found in the 90 + sysfs files prochot1, prochot2, prochot1_avg, prochot2_avg, prochot1_max, 91 + and prochot2_max. prochot1_max and prochot2_max contain the user limits 92 + for #PROCHOT1 and #PROCHOT2, respectively. prochot1 and prochot2 contain 93 + the current readings for the most recent complete time interval. The 94 + value of prochot1_avg and prochot2_avg is something like a 2 period 95 + exponential moving average (but not quite - check the datasheet). Note 96 + that this third value is calculated by the chip itself. All values range 97 + from 0-255 where 0 indicates no throttling, and 255 indicates > 99.6%. 98 + 99 + The monitoring intervals for the two #PROCHOT signals is also configurable. 100 + These intervals can be found in the sysfs files prochot1_interval and 101 + prochot2_interval. The values in these files specify the intervals for 102 + #P1_PROCHOT and #P2_PROCHOT, respectively. Selecting a value not in this 103 + list will cause the driver to use the next largest interval. The available 104 + intervals are: 105 + 106 + #PROCHOT intervals: 0.73, 1.46, 2.9, 5.8, 11.7, 23.3, 46.6, 93.2, 186, 372 107 + 108 + It is possible to configure the LM93 to logically short the two #PROCHOT 109 + signals. I.e. when #P1_PROCHOT is asserted, the LM93 will automatically 110 + assert #P2_PROCHOT, and vice-versa. This mode is enabled by writing a 111 + non-zero integer to the sysfs file prochot_short. 112 + 113 + The LM93 can also override the #PROCHOT pins by driving a PWM signal onto 114 + one or both of them. When overridden, the signal has a period of 3.56 mS, 115 + a minimum pulse width of 5 clocks (at 22.5kHz => 6.25% duty cycle), and 116 + a maximum pulse width of 80 clocks (at 22.5kHz => 99.88% duty cycle). 117 + 118 + The sysfs files prochot1_override and prochot2_override contain boolean 119 + intgers which enable or disable the override function for #P1_PROCHOT and 120 + #P2_PROCHOT, respectively. The sysfs file prochot_override_duty_cycle 121 + contains a value controlling the duty cycle for the PWM signal used when 122 + the override function is enabled. This value ranges from 0 to 15, with 0 123 + indicating minimum duty cycle and 15 indicating maximum. 124 + 125 + #VRD_HOT: 126 + 127 + The LM93 can monitor two #VRD_HOT signals. The results are found in the 128 + sysfs files vrdhot1 and vrdhot2. There is one value per file: a boolean for 129 + which 1 indicates #VRD_HOT is asserted and 0 indicates it is negated. These 130 + files are read-only. 131 + 132 + Smart Tach Mode: 133 + 134 + (from the datasheet) 135 + 136 + If a fan is driven using a low-side drive PWM, the tachometer 137 + output of the fan is corrupted. The LM93 includes smart tachometer 138 + circuitry that allows an accurate tachometer reading to be 139 + achieved despite the signal corruption. In smart tach mode all 140 + four signals are measured within 4 seconds. 141 + 142 + Smart tach mode is enabled by the driver by writing 1 or 2 (associating the 143 + the fan tachometer with a pwm) to the sysfs file fan<n>_smart_tach. A zero 144 + will disable the function for that fan. Note that Smart tach mode cannot be 145 + enabled if the PWM output frequency is 22500 Hz (see below). 146 + 147 + Manual PWM: 148 + 149 + The LM93 has a fixed or override mode for the two PWM outputs (although, there 150 + are still some conditions that will override even this mode - see section 151 + 15.10.6 of the datasheet for details.) The sysfs files pwm1_override 152 + and pwm2_override are used to enable this mode; each is a boolean integer 153 + where 0 disables and 1 enables the manual control mode. The sysfs files pwm1 154 + and pwm2 are used to set the manual duty cycle; each is an integer (0-255) 155 + where 0 is 0% duty cycle, and 255 is 100%. Note that the duty cycle values 156 + are constrained by the hardware. Selecting a value which is not available 157 + will cause the driver to use the next largest value. Also note: when manual 158 + PWM mode is disabled, the value of pwm1 and pwm2 indicates the current duty 159 + cycle chosen by the h/w. 160 + 161 + PWM Output Frequency: 162 + 163 + The LM93 supports several different frequencies for the PWM output channels. 164 + The sysfs files pwm1_freq and pwm2_freq are used to select the frequency. The 165 + frequency values are constrained by the hardware. Selecting a value which is 166 + not available will cause the driver to use the next largest value. Also note 167 + that this parameter has implications for the Smart Tach Mode (see above). 168 + 169 + PWM Output Frequencies: 12, 36, 48, 60, 72, 84, 96, 22500 (h/w default) 170 + 171 + Automatic PWM: 172 + 173 + The LM93 is capable of complex automatic fan control, with many different 174 + points of configuration. To start, each PWM output can be bound to any 175 + combination of eight control sources. The final PWM is the largest of all 176 + individual control sources to which the PWM output is bound. 177 + 178 + The eight control sources are: temp1-temp4 (aka "zones" in the datasheet), 179 + #PROCHOT 1 & 2, and #VRDHOT 1 & 2. The bindings are expressed as a bitmask 180 + in the sysfs files pwm<n>_auto_channels, where a "1" enables the binding, and 181 + a "0" disables it. The h/w default is 0x0f (all temperatures bound). 182 + 183 + 0x01 - Temp 1 184 + 0x02 - Temp 2 185 + 0x04 - Temp 3 186 + 0x08 - Temp 4 187 + 0x10 - #PROCHOT 1 188 + 0x20 - #PROCHOT 2 189 + 0x40 - #VRDHOT 1 190 + 0x80 - #VRDHOT 2 191 + 192 + The function y = f(x) takes a source temperature x to a PWM output y. This 193 + function of the LM93 is derived from a base temperature and a table of 12 194 + temperature offsets. The base temperature is expressed in degrees C in the 195 + sysfs files temp<n>_auto_base. The offsets are expressed in cumulative 196 + degrees C, with the value of offset <i> for temperature value <n> being 197 + contained in the file temp<n>_auto_offset<i>. E.g. if the base temperature 198 + is 40C: 199 + 200 + offset # temp<n>_auto_offset<i> range pwm 201 + 1 0 - 25.00% 202 + 2 0 - 28.57% 203 + 3 1 40C - 41C 32.14% 204 + 4 1 41C - 42C 35.71% 205 + 5 2 42C - 44C 39.29% 206 + 6 2 44C - 46C 42.86% 207 + 7 2 48C - 50C 46.43% 208 + 8 2 50C - 52C 50.00% 209 + 9 2 52C - 54C 53.57% 210 + 10 2 54C - 56C 57.14% 211 + 11 2 56C - 58C 71.43% 212 + 12 2 58C - 60C 85.71% 213 + > 60C 100.00% 214 + 215 + Valid offsets are in the range 0C <= x <= 7.5C in 0.5C increments. 216 + 217 + There is an independent base temperature for each temperature channel. Note, 218 + however, there are only two tables of offsets: one each for temp[12] and 219 + temp[34]. Therefore, any change to e.g. temp1_auto_offset<i> will also 220 + affect temp2_auto_offset<i>. 221 + 222 + The LM93 can also apply hysteresis to the offset table, to prevent unwanted 223 + oscillation between two steps in the offsets table. These values are found in 224 + the sysfs files temp<n>_auto_offset_hyst. The value in this file has the 225 + same representation as in temp<n>_auto_offset<i>. 226 + 227 + If a temperature reading falls below the base value for that channel, the LM93 228 + will use the minimum PWM value. These values are found in the sysfs files 229 + temp<n>_auto_pwm_min. Note, there are only two minimums: one each for temp[12] 230 + and temp[34]. Therefore, any change to e.g. temp1_auto_pwm_min will also 231 + affect temp2_auto_pwm_min. 232 + 233 + PWM Spin-Up Cycle: 234 + 235 + A spin-up cycle occurs when a PWM output is commanded from 0% duty cycle to 236 + some value > 0%. The LM93 supports a minimum duty cycle during spin-up. These 237 + values are found in the sysfs files pwm<n>_auto_spinup_min. The value in this 238 + file has the same representation as other PWM duty cycle values. The 239 + duration of the spin-up cycle is also configurable. These values are found in 240 + the sysfs files pwm<n>_auto_spinup_time. The value in this file is 241 + the spin-up time in seconds. The available spin-up times are constrained by 242 + the hardware. Selecting a value which is not available will cause the driver 243 + to use the next largest value. 244 + 245 + Spin-up Durations: 0 (disabled, h/w default), 0.1, 0.25, 0.4, 0.7, 1.0, 246 + 2.0, 4.0 247 + 248 + #PROCHOT and #VRDHOT PWM Ramping: 249 + 250 + If the #PROCHOT or #VRDHOT signals are asserted while bound to a PWM output 251 + channel, the LM93 will ramp the PWM output up to 100% duty cycle in discrete 252 + steps. The duration of each step is configurable. There are two files, with 253 + one value each in seconds: pwm_auto_prochot_ramp and pwm_auto_vrdhot_ramp. 254 + The available ramp times are constrained by the hardware. Selecting a value 255 + which is not available will cause the driver to use the next largest value. 256 + 257 + Ramp Times: 0 (disabled, h/w default) to 0.75 in 0.05 second intervals 258 + 259 + Fan Boost: 260 + 261 + For each temperature channel, there is a boost temperature: if the channel 262 + exceeds this limit, the LM93 will immediately drive both PWM outputs to 100%. 263 + This limit is expressed in degrees C in the sysfs files temp<n>_auto_boost. 264 + There is also a hysteresis temperature for this function: after the boost 265 + limit is reached, the temperature channel must drop below this value before 266 + the boost function is disabled. This temperature is also expressed in degrees 267 + C in the sysfs files temp<n>_auto_boost_hyst. 268 + 269 + GPIO Pins: 270 + 271 + The LM93 can monitor the logic level of four dedicated GPIO pins as well as the 272 + four tach input pins. GPIO0-GPIO3 correspond to (fan) tach 1-4, respectively. 273 + All eight GPIOs are read by reading the bitmask in the sysfs file gpio. The 274 + LSB is GPIO0, and the MSB is GPIO7. 275 + 276 + 277 + LM93 Unique sysfs Files 278 + ----------------------- 279 + 280 + file description 281 + ------------------------------------------------------------- 282 + 283 + prochot<n> current #PROCHOT % 284 + 285 + prochot<n>_avg moving average #PROCHOT % 286 + 287 + prochot<n>_max limit #PROCHOT % 288 + 289 + prochot_short enable or disable logical #PROCHOT pin short 290 + 291 + prochot<n>_override force #PROCHOT assertion as PWM 292 + 293 + prochot_override_duty_cycle 294 + duty cycle for the PWM signal used when 295 + #PROCHOT is overridden 296 + 297 + prochot<n>_interval #PROCHOT PWM sampling interval 298 + 299 + vrdhot<n> 0 means negated, 1 means asserted 300 + 301 + fan<n>_smart_tach enable or disable smart tach mode 302 + 303 + pwm<n>_auto_channels select control sources for PWM outputs 304 + 305 + pwm<n>_auto_spinup_min minimum duty cycle during spin-up 306 + 307 + pwm<n>_auto_spinup_time duration of spin-up 308 + 309 + pwm_auto_prochot_ramp ramp time per step when #PROCHOT asserted 310 + 311 + pwm_auto_vrdhot_ramp ramp time per step when #VRDHOT asserted 312 + 313 + temp<n>_auto_base temperature channel base 314 + 315 + temp<n>_auto_offset[1-12] 316 + temperature channel offsets 317 + 318 + temp<n>_auto_offset_hyst 319 + temperature channel offset hysteresis 320 + 321 + temp<n>_auto_boost temperature channel boost (PWMs to 100%) limit 322 + 323 + temp<n>_auto_boost_hyst temperature channel boost hysteresis 324 + 325 + gpio input state of 8 GPIO pins; read-only 326 + 327 + 328 + Sample Configuration File 329 + ------------------------- 330 + 331 + Here is a sample LM93 chip config for sensors.conf: 332 + 333 + ---------- cut here ---------- 334 + chip "lm93-*" 335 + 336 + # VOLTAGE INPUTS 337 + 338 + # labels and scaling based on datasheet recommendations 339 + label in1 "+12V1" 340 + compute in1 @ * 12.945, @ / 12.945 341 + set in1_min 12 * 0.90 342 + set in1_max 12 * 1.10 343 + 344 + label in2 "+12V2" 345 + compute in2 @ * 12.945, @ / 12.945 346 + set in2_min 12 * 0.90 347 + set in2_max 12 * 1.10 348 + 349 + label in3 "+12V3" 350 + compute in3 @ * 12.945, @ / 12.945 351 + set in3_min 12 * 0.90 352 + set in3_max 12 * 1.10 353 + 354 + label in4 "FSB_Vtt" 355 + 356 + label in5 "3GIO" 357 + 358 + label in6 "ICH_Core" 359 + 360 + label in7 "Vccp1" 361 + 362 + label in8 "Vccp2" 363 + 364 + label in9 "+3.3V" 365 + set in9_min 3.3 * 0.90 366 + set in9_max 3.3 * 1.10 367 + 368 + label in10 "+5V" 369 + set in10_min 5.0 * 0.90 370 + set in10_max 5.0 * 1.10 371 + 372 + label in11 "SCSI_Core" 373 + 374 + label in12 "Mem_Core" 375 + 376 + label in13 "Mem_Vtt" 377 + 378 + label in14 "Gbit_Core" 379 + 380 + # Assuming R1/R2 = 4.1143, and 3.3V reference 381 + # -12V = (4.1143 + 1) * (@ - 3.3) + 3.3 382 + label in15 "-12V" 383 + compute in15 @ * 5.1143 - 13.57719, (@ + 13.57719) / 5.1143 384 + set in15_min -12 * 0.90 385 + set in15_max -12 * 1.10 386 + 387 + label in16 "+3.3VSB" 388 + set in16_min 3.3 * 0.90 389 + set in16_max 3.3 * 1.10 390 + 391 + # TEMPERATURE INPUTS 392 + 393 + label temp1 "CPU1" 394 + label temp2 "CPU2" 395 + label temp3 "LM93" 396 + 397 + # TACHOMETER INPUTS 398 + 399 + label fan1 "Fan1" 400 + set fan1_min 3000 401 + label fan2 "Fan2" 402 + set fan2_min 3000 403 + label fan3 "Fan3" 404 + set fan3_min 3000 405 + label fan4 "Fan4" 406 + set fan4_min 3000 407 + 408 + # PWM OUTPUTS 409 + 410 + label pwm1 "CPU1" 411 + label pwm2 "CPU2" 412 +
+4 -3
Documentation/hwmon/smsc47b397
··· 4 Supported chips: 5 * SMSC LPC47B397-NC 6 * SMSC SCH5307-NS 7 Prefix: 'smsc47b397' 8 Addresses scanned: none, address read from Super I/O config space 9 Datasheet: In this file ··· 19 provided by Craig Kelly (In-Store Broadcast Network) and edited/corrected 20 by Mark M. Hoffman <mhoffman@lightlink.com>. 21 22 - [1] And SMSC SCH5307-NS, which has a different device ID but is otherwise 23 - compatible. 24 25 * * * * * 26 ··· 132 The registers of interest for identifying the SIO on the dc7100 are Device ID 133 (0x20) and Device Rev (0x21). 134 135 - The Device ID will read 0x6F (for SCH5307-NS, 0x81) 136 The Device Rev currently reads 0x01 137 138 Obtaining the HWM Base Address.
··· 4 Supported chips: 5 * SMSC LPC47B397-NC 6 * SMSC SCH5307-NS 7 + * SMSC SCH5317 8 Prefix: 'smsc47b397' 9 Addresses scanned: none, address read from Super I/O config space 10 Datasheet: In this file ··· 18 provided by Craig Kelly (In-Store Broadcast Network) and edited/corrected 19 by Mark M. Hoffman <mhoffman@lightlink.com>. 20 21 + [1] And SMSC SCH5307-NS and SCH5317, which have different device IDs but are 22 + otherwise compatible. 23 24 * * * * * 25 ··· 131 The registers of interest for identifying the SIO on the dc7100 are Device ID 132 (0x20) and Device Rev (0x21). 133 134 + The Device ID will read 0x6F (0x81 for SCH5307-NS, and 0x85 for SCH5317) 135 The Device Rev currently reads 0x01 136 137 Obtaining the HWM Base Address.
+7 -8
Documentation/hwmon/sysfs-interface
··· 172 255 is max or 100%. 173 174 pwm[1-*]_enable 175 - Switch PWM on and off. 176 - Not always present even if pwmN is. 177 - 0: turn off 178 - 1: turn on in manual mode 179 - 2+: turn on in automatic mode 180 Check individual chip documentation files for automatic mode 181 details. 182 RW ··· 342 supports it. When this boolean has value 1, the measurement for that 343 channel should not be trusted. 344 345 - in[0-*]_input_fault 346 - fan[1-*]_input_fault 347 - temp[1-*]_input_fault 348 Input fault condition 349 0: no fault occured 350 1: fault condition
··· 172 255 is max or 100%. 173 174 pwm[1-*]_enable 175 + Fan speed control method: 176 + 0: no fan speed control (i.e. fan at full speed) 177 + 1: manual fan speed control enabled (using pwm[1-*]) 178 + 2+: automatic fan speed control enabled 179 Check individual chip documentation files for automatic mode 180 details. 181 RW ··· 343 supports it. When this boolean has value 1, the measurement for that 344 channel should not be trusted. 345 346 + in[0-*]_fault 347 + fan[1-*]_fault 348 + temp[1-*]_fault 349 Input fault condition 350 0: no fault occured 351 1: fault condition
+3 -3
Documentation/hwmon/w83627ehf
··· 22 W83627DHG super I/O chips. We will refer to them collectively as Winbond chips. 23 24 The chips implement three temperature sensors, five fan rotation 25 - speed sensors, ten analog voltage sensors (only nine for the 627DHG), alarms 26 - with beep warnings (control unimplemented), and some automatic fan regulation 27 - strategies (plus manual fan control mode). 28 29 Temperatures are measured in degrees Celsius and measurement resolution is 1 30 degC for temp1 and 0.5 degC for temp2 and temp3. An alarm is triggered when
··· 22 W83627DHG super I/O chips. We will refer to them collectively as Winbond chips. 23 24 The chips implement three temperature sensors, five fan rotation 25 + speed sensors, ten analog voltage sensors (only nine for the 627DHG), one 26 + VID (6 pins), alarms with beep warnings (control unimplemented), and 27 + some automatic fan regulation strategies (plus manual fan control mode). 28 29 Temperatures are measured in degrees Celsius and measurement resolution is 1 30 degC for temp1 and 0.5 degC for temp2 and temp3. An alarm is triggered when
+33 -3
MAINTAINERS
··· 607 W: http://xf.iksaif.net/acpi4asus 608 S: Maintained 609 610 ASUS LAPTOP EXTRAS DRIVER 611 P: Corentin Chary 612 M: corentincj@iksaif.net ··· 1279 L: linux-kernel@vger.kernel.org 1280 S: Maintained 1281 1282 DOCBOOK FOR DOCUMENTATION 1283 P: Randy Dunlap 1284 M: rdunlap@xenotime.net ··· 1635 S: Maintained 1636 1637 HARDWARE MONITORING 1638 - P: Jean Delvare 1639 - M: khali@linux-fr.org 1640 L: lm-sensors@lm-sensors.org 1641 W: http://www.lm-sensors.org/ 1642 - T: quilt http://khali.linux-fr.org/devel/linux-2.6/jdelvare-hwmon/ 1643 S: Maintained 1644 1645 HARDWARE RANDOM NUMBER GENERATOR CORE ··· 1773 HUGETLB FILESYSTEM 1774 P: William Irwin 1775 M: wli@holomorphy.com 1776 S: Maintained 1777 1778 I2C SUBSYSTEM ··· 3310 L: netdev@vger.kernel.org 3311 S: Maintained 3312 3313 SIS FRAMEBUFFER DRIVER 3314 P: Thomas Winischhofer 3315 M: thomas@winischhofer.net ··· 3331 SMC91x ETHERNET DRIVER 3332 P: Nicolas Pitre 3333 M: nico@cam.org 3334 S: Maintained 3335 3336 SOFTMAC LAYER (IEEE 802.11)
··· 607 W: http://xf.iksaif.net/acpi4asus 608 S: Maintained 609 610 + ASUS ASB100 HARDWARE MONITOR DRIVER 611 + P: Mark M. Hoffman 612 + M: mhoffman@lightlink.com 613 + L: lm-sensors@lm-sensors.org 614 + S: Maintained 615 + 616 ASUS LAPTOP EXTRAS DRIVER 617 P: Corentin Chary 618 M: corentincj@iksaif.net ··· 1273 L: linux-kernel@vger.kernel.org 1274 S: Maintained 1275 1276 + DME1737 HARDWARE MONITOR DRIVER 1277 + P: Juerg Haefliger 1278 + M: juergh@gmail.com 1279 + L: lm-sensors@lm-sensors.org 1280 + S: Maintained 1281 + 1282 DOCBOOK FOR DOCUMENTATION 1283 P: Randy Dunlap 1284 M: rdunlap@xenotime.net ··· 1623 S: Maintained 1624 1625 HARDWARE MONITORING 1626 + P: Mark M. Hoffman 1627 + M: mhoffman@lightlink.com 1628 L: lm-sensors@lm-sensors.org 1629 W: http://www.lm-sensors.org/ 1630 + T: git lm-sensors.org:/kernel/mhoffman/hwmon-2.6.git 1631 S: Maintained 1632 1633 HARDWARE RANDOM NUMBER GENERATOR CORE ··· 1761 HUGETLB FILESYSTEM 1762 P: William Irwin 1763 M: wli@holomorphy.com 1764 + S: Maintained 1765 + 1766 + I2C/SMBUS STUB DRIVER 1767 + P: Mark M. Hoffman 1768 + M: mhoffman@lightlink.com 1769 + L: lm-sensors@lm-sensors.org 1770 S: Maintained 1771 1772 I2C SUBSYSTEM ··· 3292 L: netdev@vger.kernel.org 3293 S: Maintained 3294 3295 + SIS 96X I2C/SMBUS DRIVER 3296 + P: Mark M. Hoffman 3297 + M: mhoffman@lightlink.com 3298 + L: lm-sensors@lm-sensors.org 3299 + S: Maintained 3300 + 3301 SIS FRAMEBUFFER DRIVER 3302 P: Thomas Winischhofer 3303 M: thomas@winischhofer.net ··· 3307 SMC91x ETHERNET DRIVER 3308 P: Nicolas Pitre 3309 M: nico@cam.org 3310 + S: Maintained 3311 + 3312 + SMSC47B397 HARDWARE MONITOR DRIVER 3313 + P: Mark M. Hoffman 3314 + M: mhoffman@lightlink.com 3315 + L: lm-sensors@lm-sensors.org 3316 S: Maintained 3317 3318 SOFTMAC LAYER (IEEE 802.11)
-1
arch/arm/configs/badge4_defconfig
··· 708 # I2C Hardware Bus support 709 # 710 CONFIG_I2C_ELEKTOR=m 711 - # CONFIG_I2C_ISA is not set 712 # CONFIG_I2C_PARPORT is not set 713 # CONFIG_I2C_PARPORT_LIGHT is not set 714 # CONFIG_I2C_STUB is not set
··· 708 # I2C Hardware Bus support 709 # 710 CONFIG_I2C_ELEKTOR=m 711 # CONFIG_I2C_PARPORT is not set 712 # CONFIG_I2C_PARPORT_LIGHT is not set 713 # CONFIG_I2C_STUB is not set
-1
arch/arm/configs/clps7500_defconfig
··· 536 # I2C Hardware Bus support 537 # 538 # CONFIG_I2C_ELEKTOR is not set 539 - # CONFIG_I2C_ISA is not set 540 # CONFIG_I2C_PARPORT is not set 541 # CONFIG_I2C_PARPORT_LIGHT is not set 542 # CONFIG_I2C_PCA_ISA is not set
··· 536 # I2C Hardware Bus support 537 # 538 # CONFIG_I2C_ELEKTOR is not set 539 # CONFIG_I2C_PARPORT is not set 540 # CONFIG_I2C_PARPORT_LIGHT is not set 541 # CONFIG_I2C_PCA_ISA is not set
-1
arch/arm/configs/footbridge_defconfig
··· 748 # CONFIG_I2C_ELEKTOR is not set 749 # CONFIG_I2C_I801 is not set 750 # CONFIG_I2C_I810 is not set 751 - # CONFIG_I2C_ISA is not set 752 # CONFIG_I2C_NFORCE2 is not set 753 # CONFIG_I2C_PARPORT is not set 754 # CONFIG_I2C_PARPORT_LIGHT is not set
··· 748 # CONFIG_I2C_ELEKTOR is not set 749 # CONFIG_I2C_I801 is not set 750 # CONFIG_I2C_I810 is not set 751 # CONFIG_I2C_NFORCE2 is not set 752 # CONFIG_I2C_PARPORT is not set 753 # CONFIG_I2C_PARPORT_LIGHT is not set
-1
arch/arm/configs/neponset_defconfig
··· 698 # I2C Hardware Bus support 699 # 700 # CONFIG_I2C_ELEKTOR is not set 701 - # CONFIG_I2C_ISA is not set 702 # CONFIG_I2C_PARPORT_LIGHT is not set 703 # CONFIG_I2C_STUB is not set 704 # CONFIG_I2C_PCA_ISA is not set
··· 698 # I2C Hardware Bus support 699 # 700 # CONFIG_I2C_ELEKTOR is not set 701 # CONFIG_I2C_PARPORT_LIGHT is not set 702 # CONFIG_I2C_STUB is not set 703 # CONFIG_I2C_PCA_ISA is not set
-1
arch/arm/configs/picotux200_defconfig
··· 735 # I2C Hardware Bus support 736 # 737 CONFIG_I2C_AT91=m 738 - CONFIG_I2C_ISA=m 739 # CONFIG_I2C_OCORES is not set 740 # CONFIG_I2C_PARPORT_LIGHT is not set 741 # CONFIG_I2C_STUB is not set
··· 735 # I2C Hardware Bus support 736 # 737 CONFIG_I2C_AT91=m 738 # CONFIG_I2C_OCORES is not set 739 # CONFIG_I2C_PARPORT_LIGHT is not set 740 # CONFIG_I2C_STUB is not set
-1
arch/arm/configs/rpc_defconfig
··· 558 # 559 # I2C Hardware Bus support 560 # 561 - # CONFIG_I2C_ISA is not set 562 # CONFIG_I2C_PARPORT is not set 563 # CONFIG_I2C_PARPORT_LIGHT is not set 564 # CONFIG_I2C_STUB is not set
··· 558 # 559 # I2C Hardware Bus support 560 # 561 # CONFIG_I2C_PARPORT is not set 562 # CONFIG_I2C_PARPORT_LIGHT is not set 563 # CONFIG_I2C_STUB is not set
-1
arch/arm/configs/s3c2410_defconfig
··· 826 # I2C Hardware Bus support 827 # 828 # CONFIG_I2C_ELEKTOR is not set 829 - CONFIG_I2C_ISA=m 830 # CONFIG_I2C_OCORES is not set 831 # CONFIG_I2C_PARPORT is not set 832 # CONFIG_I2C_PARPORT_LIGHT is not set
··· 826 # I2C Hardware Bus support 827 # 828 # CONFIG_I2C_ELEKTOR is not set 829 # CONFIG_I2C_OCORES is not set 830 # CONFIG_I2C_PARPORT is not set 831 # CONFIG_I2C_PARPORT_LIGHT is not set
-1
arch/m32r/m32104ut/defconfig.m32104ut
··· 699 # I2C Hardware Bus support 700 # 701 CONFIG_I2C_ELEKTOR=m 702 - CONFIG_I2C_ISA=m 703 # CONFIG_I2C_OCORES is not set 704 # CONFIG_I2C_PARPORT is not set 705 # CONFIG_I2C_PARPORT_LIGHT is not set
··· 699 # I2C Hardware Bus support 700 # 701 CONFIG_I2C_ELEKTOR=m 702 # CONFIG_I2C_OCORES is not set 703 # CONFIG_I2C_PARPORT is not set 704 # CONFIG_I2C_PARPORT_LIGHT is not set
-1
arch/ppc/configs/ev64260_defconfig
··· 531 # CONFIG_I2C_AMD8111 is not set 532 # CONFIG_I2C_I801 is not set 533 # CONFIG_I2C_I810 is not set 534 - # CONFIG_I2C_ISA is not set 535 # CONFIG_I2C_NFORCE2 is not set 536 # CONFIG_I2C_PARPORT_LIGHT is not set 537 # CONFIG_I2C_PIIX4 is not set
··· 531 # CONFIG_I2C_AMD8111 is not set 532 # CONFIG_I2C_I801 is not set 533 # CONFIG_I2C_I810 is not set 534 # CONFIG_I2C_NFORCE2 is not set 535 # CONFIG_I2C_PARPORT_LIGHT is not set 536 # CONFIG_I2C_PIIX4 is not set
-1
arch/ppc/configs/mpc8540_ads_defconfig
··· 452 # CONFIG_I2C_AMD8111 is not set 453 # CONFIG_I2C_I801 is not set 454 # CONFIG_I2C_I810 is not set 455 - # CONFIG_I2C_ISA is not set 456 CONFIG_I2C_MPC=y 457 # CONFIG_I2C_NFORCE2 is not set 458 # CONFIG_I2C_PARPORT_LIGHT is not set
··· 452 # CONFIG_I2C_AMD8111 is not set 453 # CONFIG_I2C_I801 is not set 454 # CONFIG_I2C_I810 is not set 455 CONFIG_I2C_MPC=y 456 # CONFIG_I2C_NFORCE2 is not set 457 # CONFIG_I2C_PARPORT_LIGHT is not set
-1
arch/ppc/configs/mpc8548_cds_defconfig
··· 413 # 414 # I2C Hardware Bus support 415 # 416 - # CONFIG_I2C_ISA is not set 417 CONFIG_I2C_MPC=y 418 # CONFIG_I2C_PARPORT_LIGHT is not set 419 # CONFIG_I2C_PCA_ISA is not set
··· 413 # 414 # I2C Hardware Bus support 415 # 416 CONFIG_I2C_MPC=y 417 # CONFIG_I2C_PARPORT_LIGHT is not set 418 # CONFIG_I2C_PCA_ISA is not set
-1
arch/ppc/configs/mpc8555_cds_defconfig
··· 518 # CONFIG_I2C_I801 is not set 519 # CONFIG_I2C_I810 is not set 520 # CONFIG_I2C_PIIX4 is not set 521 - # CONFIG_I2C_ISA is not set 522 CONFIG_I2C_MPC=y 523 # CONFIG_I2C_NFORCE2 is not set 524 # CONFIG_I2C_PARPORT_LIGHT is not set
··· 518 # CONFIG_I2C_I801 is not set 519 # CONFIG_I2C_I810 is not set 520 # CONFIG_I2C_PIIX4 is not set 521 CONFIG_I2C_MPC=y 522 # CONFIG_I2C_NFORCE2 is not set 523 # CONFIG_I2C_PARPORT_LIGHT is not set
-1
arch/ppc/configs/mpc8560_ads_defconfig
··· 489 # CONFIG_I2C_I801 is not set 490 # CONFIG_I2C_I810 is not set 491 # CONFIG_I2C_PIIX4 is not set 492 - # CONFIG_I2C_ISA is not set 493 CONFIG_I2C_MPC=y 494 # CONFIG_I2C_NFORCE2 is not set 495 # CONFIG_I2C_PARPORT_LIGHT is not set
··· 489 # CONFIG_I2C_I801 is not set 490 # CONFIG_I2C_I810 is not set 491 # CONFIG_I2C_PIIX4 is not set 492 CONFIG_I2C_MPC=y 493 # CONFIG_I2C_NFORCE2 is not set 494 # CONFIG_I2C_PARPORT_LIGHT is not set
-1
arch/ppc/configs/radstone_ppc7d_defconfig
··· 710 # CONFIG_I2C_I801 is not set 711 # CONFIG_I2C_I810 is not set 712 # CONFIG_I2C_PIIX4 is not set 713 - # CONFIG_I2C_ISA is not set 714 # CONFIG_I2C_MPC is not set 715 # CONFIG_I2C_NFORCE2 is not set 716 # CONFIG_I2C_PARPORT_LIGHT is not set
··· 710 # CONFIG_I2C_I801 is not set 711 # CONFIG_I2C_I810 is not set 712 # CONFIG_I2C_PIIX4 is not set 713 # CONFIG_I2C_MPC is not set 714 # CONFIG_I2C_NFORCE2 is not set 715 # CONFIG_I2C_PARPORT_LIGHT is not set
-1
arch/ppc/configs/stx_gp3_defconfig
··· 661 # CONFIG_I2C_I801 is not set 662 # CONFIG_I2C_I810 is not set 663 # CONFIG_I2C_PIIX4 is not set 664 - # CONFIG_I2C_ISA is not set 665 # CONFIG_I2C_MPC is not set 666 # CONFIG_I2C_NFORCE2 is not set 667 # CONFIG_I2C_PARPORT is not set
··· 661 # CONFIG_I2C_I801 is not set 662 # CONFIG_I2C_I810 is not set 663 # CONFIG_I2C_PIIX4 is not set 664 # CONFIG_I2C_MPC is not set 665 # CONFIG_I2C_NFORCE2 is not set 666 # CONFIG_I2C_PARPORT is not set
-1
arch/ppc/configs/sycamore_defconfig
··· 461 # CONFIG_I2C_I801 is not set 462 # CONFIG_I2C_I810 is not set 463 # CONFIG_I2C_IBM_IIC is not set 464 - # CONFIG_I2C_ISA is not set 465 # CONFIG_I2C_NFORCE2 is not set 466 # CONFIG_I2C_PARPORT_LIGHT is not set 467 # CONFIG_I2C_PIIX4 is not set
··· 461 # CONFIG_I2C_I801 is not set 462 # CONFIG_I2C_I810 is not set 463 # CONFIG_I2C_IBM_IIC is not set 464 # CONFIG_I2C_NFORCE2 is not set 465 # CONFIG_I2C_PARPORT_LIGHT is not set 466 # CONFIG_I2C_PIIX4 is not set
+57 -25
drivers/hwmon/Kconfig
··· 29 default n 30 31 config SENSORS_ABITUGURU 32 - tristate "Abit uGuru" 33 depends on EXPERIMENTAL 34 help 35 - If you say yes here you get support for the Abit uGuru chips 36 - sensor part. The voltage and frequency control parts of the Abit 37 - uGuru are not supported. The Abit uGuru chip can be found on Abit 38 - uGuru featuring motherboards (most modern Abit motherboards). 39 40 This driver can also be built as a module. If so, the module 41 will be called abituguru. 42 43 config SENSORS_AD7418 44 tristate "Analog Devices AD7416, AD7417 and AD7418" ··· 267 268 config SENSORS_IT87 269 tristate "ITE IT87xx and compatibles" 270 - depends on I2C 271 - select I2C_ISA 272 select HWMON_VID 273 help 274 If you say yes here you get support for ITE IT8705F, IT8712F, 275 - IT8716F and IT8718F sensor chips, and the SiS960 clone. 276 277 This driver can also be built as a module. If so, the module 278 will be called it87. ··· 380 depends on I2C 381 help 382 If you say yes here you get support for National Semiconductor LM90, 383 - LM86, LM89 and LM99, Analog Devices ADM1032 and Maxim MAX6657 and 384 - MAX6658 sensor chips. 385 386 The Analog Devices ADT7461 sensor chip is also supported, but only 387 if found in ADM1032 compatibility mode. ··· 398 399 This driver can also be built as a module. If so, the module 400 will be called lm92. 401 402 config SENSORS_MAX1619 403 tristate "Maxim MAX1619 sensor chip" ··· 431 432 config SENSORS_PC87360 433 tristate "National Semiconductor PC87360 family" 434 - depends on I2C && EXPERIMENTAL 435 - select I2C_ISA 436 select HWMON_VID 437 help 438 If you say yes here you get access to the hardware monitoring ··· 457 458 config SENSORS_SIS5595 459 tristate "Silicon Integrated Systems Corp. SiS5595" 460 - depends on I2C && PCI && EXPERIMENTAL 461 - select I2C_ISA 462 help 463 If you say yes here you get support for the integrated sensors in 464 SiS5595 South Bridges. 465 466 This driver can also be built as a module. If so, the module 467 will be called sis5595. 468 469 config SENSORS_SMSC47M1 470 tristate "SMSC LPC47M10x and compatibles" ··· 522 523 config SENSORS_VIA686A 524 tristate "VIA686A" 525 - depends on I2C && PCI 526 - select I2C_ISA 527 help 528 If you say yes here you get support for the integrated sensors in 529 Via 686A/B South Bridges. ··· 543 544 config SENSORS_VT8231 545 tristate "VIA VT8231" 546 - depends on I2C && PCI && EXPERIMENTAL 547 select HWMON_VID 548 - select I2C_ISA 549 help 550 If you say yes here then you get support for the integrated sensors 551 in the VIA VT8231 device. ··· 617 will be called w83627hf. 618 619 config SENSORS_W83627EHF 620 - tristate "Winbond W83627EHF" 621 - depends on I2C && EXPERIMENTAL 622 - select I2C_ISA 623 help 624 - If you say yes here you get preliminary support for the hardware 625 monitoring functionality of the Winbond W83627EHF Super-I/O chip. 626 - Only fan and temperature inputs are supported at the moment, while 627 - the chip does much more than that. 628 629 This driver also supports the W83627EHG, which is the lead-free 630 - version of the W83627EHF. 631 632 This driver can also be built as a module. If so, the module 633 will be called w83627ehf.
··· 29 default n 30 31 config SENSORS_ABITUGURU 32 + tristate "Abit uGuru (rev 1 & 2)" 33 depends on EXPERIMENTAL 34 help 35 + If you say yes here you get support for the sensor part of the first 36 + and second revision of the Abit uGuru chip. The voltage and frequency 37 + control parts of the Abit uGuru are not supported. The Abit uGuru 38 + chip can be found on Abit uGuru featuring motherboards (most modern 39 + Abit motherboards from before end 2005). For more info and a list 40 + of which motherboards have which revision see 41 + Documentation/hwmon/abituguru 42 43 This driver can also be built as a module. If so, the module 44 will be called abituguru. 45 + 46 + config SENSORS_ABITUGURU3 47 + tristate "Abit uGuru (rev 3)" 48 + depends on HWMON && EXPERIMENTAL 49 + help 50 + If you say yes here you get support for the sensor part of the 51 + third revision of the Abit uGuru chip. Only reading the sensors 52 + and their settings is supported. The third revision of the Abit 53 + uGuru chip can be found on recent Abit motherboards (since end 54 + 2005). For more info and a list of which motherboards have which 55 + revision see Documentation/hwmon/abituguru3 56 + 57 + This driver can also be built as a module. If so, the module 58 + will be called abituguru3. 59 60 config SENSORS_AD7418 61 tristate "Analog Devices AD7416, AD7417 and AD7418" ··· 250 251 config SENSORS_IT87 252 tristate "ITE IT87xx and compatibles" 253 select HWMON_VID 254 help 255 If you say yes here you get support for ITE IT8705F, IT8712F, 256 + IT8716F, IT8718F and IT8726F sensor chips, and the SiS960 clone. 257 258 This driver can also be built as a module. If so, the module 259 will be called it87. ··· 365 depends on I2C 366 help 367 If you say yes here you get support for National Semiconductor LM90, 368 + LM86, LM89 and LM99, Analog Devices ADM1032 and Maxim MAX6657, 369 + MAX6658, MAX6659, MAX6680 and MAX6681 sensor chips. 370 371 The Analog Devices ADT7461 sensor chip is also supported, but only 372 if found in ADM1032 compatibility mode. ··· 383 384 This driver can also be built as a module. If so, the module 385 will be called lm92. 386 + 387 + config SENSORS_LM93 388 + tristate "National Semiconductor LM93 and compatibles" 389 + depends on HWMON && I2C 390 + select HWMON_VID 391 + help 392 + If you say yes here you get support for National Semiconductor LM93 393 + sensor chips. 394 + 395 + This driver can also be built as a module. If so, the module 396 + will be called lm93. 397 398 config SENSORS_MAX1619 399 tristate "Maxim MAX1619 sensor chip" ··· 405 406 config SENSORS_PC87360 407 tristate "National Semiconductor PC87360 family" 408 select HWMON_VID 409 help 410 If you say yes here you get access to the hardware monitoring ··· 433 434 config SENSORS_SIS5595 435 tristate "Silicon Integrated Systems Corp. SiS5595" 436 + depends on PCI 437 help 438 If you say yes here you get support for the integrated sensors in 439 SiS5595 South Bridges. 440 441 This driver can also be built as a module. If so, the module 442 will be called sis5595. 443 + 444 + config SENSORS_DME1737 445 + tristate "SMSC DME1737 and compatibles" 446 + depends on I2C && EXPERIMENTAL 447 + select HWMON_VID 448 + help 449 + If you say yes here you get support for the hardware monitoring 450 + and fan control features of the SMSC DME1737 (and compatibles 451 + like the Asus A8000) Super-I/O chip. 452 + 453 + This driver can also be built as a module. If so, the module 454 + will be called dme1737. 455 456 config SENSORS_SMSC47M1 457 tristate "SMSC LPC47M10x and compatibles" ··· 487 488 config SENSORS_VIA686A 489 tristate "VIA686A" 490 + depends on PCI 491 help 492 If you say yes here you get support for the integrated sensors in 493 Via 686A/B South Bridges. ··· 509 510 config SENSORS_VT8231 511 tristate "VIA VT8231" 512 + depends on PCI 513 select HWMON_VID 514 help 515 If you say yes here then you get support for the integrated sensors 516 in the VIA VT8231 device. ··· 584 will be called w83627hf. 585 586 config SENSORS_W83627EHF 587 + tristate "Winbond W83627EHF/DHG" 588 + select HWMON_VID 589 help 590 + If you say yes here you get support for the hardware 591 monitoring functionality of the Winbond W83627EHF Super-I/O chip. 592 593 This driver also supports the W83627EHG, which is the lead-free 594 + version of the W83627EHF, and the W83627DHG, which is a similar 595 + chip suited for specific Intel processors that use PECI such as 596 + the Core 2 Duo. 597 598 This driver can also be built as a module. If so, the module 599 will be called w83627ehf.
+3
drivers/hwmon/Makefile
··· 14 obj-$(CONFIG_SENSORS_W83791D) += w83791d.o 15 16 obj-$(CONFIG_SENSORS_ABITUGURU) += abituguru.o 17 obj-$(CONFIG_SENSORS_AD7418) += ad7418.o 18 obj-$(CONFIG_SENSORS_ADM1021) += adm1021.o 19 obj-$(CONFIG_SENSORS_ADM1025) += adm1025.o ··· 26 obj-$(CONFIG_SENSORS_AMS) += ams/ 27 obj-$(CONFIG_SENSORS_ATXP1) += atxp1.o 28 obj-$(CONFIG_SENSORS_CORETEMP) += coretemp.o 29 obj-$(CONFIG_SENSORS_DS1621) += ds1621.o 30 obj-$(CONFIG_SENSORS_F71805F) += f71805f.o 31 obj-$(CONFIG_SENSORS_FSCHER) += fscher.o ··· 47 obj-$(CONFIG_SENSORS_LM87) += lm87.o 48 obj-$(CONFIG_SENSORS_LM90) += lm90.o 49 obj-$(CONFIG_SENSORS_LM92) += lm92.o 50 obj-$(CONFIG_SENSORS_MAX1619) += max1619.o 51 obj-$(CONFIG_SENSORS_MAX6650) += max6650.o 52 obj-$(CONFIG_SENSORS_PC87360) += pc87360.o
··· 14 obj-$(CONFIG_SENSORS_W83791D) += w83791d.o 15 16 obj-$(CONFIG_SENSORS_ABITUGURU) += abituguru.o 17 + obj-$(CONFIG_SENSORS_ABITUGURU3)+= abituguru3.o 18 obj-$(CONFIG_SENSORS_AD7418) += ad7418.o 19 obj-$(CONFIG_SENSORS_ADM1021) += adm1021.o 20 obj-$(CONFIG_SENSORS_ADM1025) += adm1025.o ··· 25 obj-$(CONFIG_SENSORS_AMS) += ams/ 26 obj-$(CONFIG_SENSORS_ATXP1) += atxp1.o 27 obj-$(CONFIG_SENSORS_CORETEMP) += coretemp.o 28 + obj-$(CONFIG_SENSORS_DME1737) += dme1737.o 29 obj-$(CONFIG_SENSORS_DS1621) += ds1621.o 30 obj-$(CONFIG_SENSORS_F71805F) += f71805f.o 31 obj-$(CONFIG_SENSORS_FSCHER) += fscher.o ··· 45 obj-$(CONFIG_SENSORS_LM87) += lm87.o 46 obj-$(CONFIG_SENSORS_LM90) += lm90.o 47 obj-$(CONFIG_SENSORS_LM92) += lm92.o 48 + obj-$(CONFIG_SENSORS_LM93) += lm93.o 49 obj-$(CONFIG_SENSORS_MAX1619) += max1619.o 50 obj-$(CONFIG_SENSORS_MAX6650) += max6650.o 51 obj-$(CONFIG_SENSORS_PC87360) += pc87360.o
+33 -12
drivers/hwmon/abituguru.c
··· 16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 17 */ 18 /* 19 - This driver supports the sensor part of the custom Abit uGuru chip found 20 - on Abit uGuru motherboards. Note: because of lack of specs the CPU / RAM / 21 - etc voltage & frequency control is not supported! 22 */ 23 #include <linux/module.h> 24 #include <linux/sched.h> ··· 31 #include <linux/platform_device.h> 32 #include <linux/hwmon.h> 33 #include <linux/hwmon-sysfs.h> 34 #include <asm/io.h> 35 36 /* Banks */ ··· 419 abituguru_detect_bank1_sensor_type(struct abituguru_data *data, 420 u8 sensor_addr) 421 { 422 - u8 val, buf[3]; 423 int i, ret = -ENODEV; /* error is the most common used retval :| */ 424 425 /* If overriden by the user return the user selected type */ ··· 437 return -ENODEV; 438 439 /* Test val is sane / usable for sensor type detection. */ 440 - if ((val < 10u) || (val > 240u)) { 441 printk(KERN_WARNING ABIT_UGURU_NAME 442 ": bank1-sensor: %d reading (%d) too close to limits, " 443 "unable to determine sensor type, skipping sensor\n", ··· 450 451 ABIT_UGURU_DEBUG(2, "testing bank1 sensor %d\n", (int)sensor_addr); 452 /* Volt sensor test, enable volt low alarm, set min value ridicously 453 - high. If its a volt sensor this should always give us an alarm. */ 454 - buf[0] = ABIT_UGURU_VOLT_LOW_ALARM_ENABLE; 455 - buf[1] = 245; 456 - buf[2] = 250; 457 if (abituguru_write(data, ABIT_UGURU_SENSOR_BANK1 + 2, sensor_addr, 458 buf, 3) != 3) 459 goto abituguru_detect_bank1_sensor_type_exit; ··· 480 sensor_addr, buf, 3, 481 ABIT_UGURU_MAX_RETRIES) != 3) 482 goto abituguru_detect_bank1_sensor_type_exit; 483 - if (buf[0] & ABIT_UGURU_VOLT_LOW_ALARM_FLAG) { 484 ABIT_UGURU_DEBUG(2, " found volt sensor\n"); 485 ret = ABIT_UGURU_IN_SENSOR; 486 goto abituguru_detect_bank1_sensor_type_exit; 487 } else 488 ABIT_UGURU_DEBUG(2, " alarm raised during volt " 489 - "sensor test, but volt low flag not set\n"); 490 } else 491 ABIT_UGURU_DEBUG(2, " alarm not raised during volt sensor " 492 "test\n"); ··· 1298 for (i = 0; i < ARRAY_SIZE(abituguru_sysfs_attr); i++) 1299 device_remove_file(&pdev->dev, 1300 &abituguru_sysfs_attr[i].dev_attr); 1301 kfree(data); 1302 return res; 1303 } ··· 1308 int i; 1309 struct abituguru_data *data = platform_get_drvdata(pdev); 1310 1311 - platform_set_drvdata(pdev, NULL); 1312 hwmon_device_unregister(data->class_dev); 1313 for (i = 0; data->sysfs_attr[i].dev_attr.attr.name; i++) 1314 device_remove_file(&pdev->dev, &data->sysfs_attr[i].dev_attr); 1315 for (i = 0; i < ARRAY_SIZE(abituguru_sysfs_attr); i++) 1316 device_remove_file(&pdev->dev, 1317 &abituguru_sysfs_attr[i].dev_attr); 1318 kfree(data); 1319 1320 return 0; ··· 1447 { 1448 int address, err; 1449 struct resource res = { .flags = IORESOURCE_IO }; 1450 1451 address = abituguru_detect(); 1452 if (address < 0)
··· 16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 17 */ 18 /* 19 + This driver supports the sensor part of the first and second revision of 20 + the custom Abit uGuru chip found on Abit uGuru motherboards. Note: because 21 + of lack of specs the CPU/RAM voltage & frequency control is not supported! 22 */ 23 #include <linux/module.h> 24 #include <linux/sched.h> ··· 31 #include <linux/platform_device.h> 32 #include <linux/hwmon.h> 33 #include <linux/hwmon-sysfs.h> 34 + #include <linux/dmi.h> 35 #include <asm/io.h> 36 37 /* Banks */ ··· 418 abituguru_detect_bank1_sensor_type(struct abituguru_data *data, 419 u8 sensor_addr) 420 { 421 + u8 val, test_flag, buf[3]; 422 int i, ret = -ENODEV; /* error is the most common used retval :| */ 423 424 /* If overriden by the user return the user selected type */ ··· 436 return -ENODEV; 437 438 /* Test val is sane / usable for sensor type detection. */ 439 + if ((val < 10u) || (val > 250u)) { 440 printk(KERN_WARNING ABIT_UGURU_NAME 441 ": bank1-sensor: %d reading (%d) too close to limits, " 442 "unable to determine sensor type, skipping sensor\n", ··· 449 450 ABIT_UGURU_DEBUG(2, "testing bank1 sensor %d\n", (int)sensor_addr); 451 /* Volt sensor test, enable volt low alarm, set min value ridicously 452 + high, or vica versa if the reading is very high. If its a volt 453 + sensor this should always give us an alarm. */ 454 + if (val <= 240u) { 455 + buf[0] = ABIT_UGURU_VOLT_LOW_ALARM_ENABLE; 456 + buf[1] = 245; 457 + buf[2] = 250; 458 + test_flag = ABIT_UGURU_VOLT_LOW_ALARM_FLAG; 459 + } else { 460 + buf[0] = ABIT_UGURU_VOLT_HIGH_ALARM_ENABLE; 461 + buf[1] = 5; 462 + buf[2] = 10; 463 + test_flag = ABIT_UGURU_VOLT_HIGH_ALARM_FLAG; 464 + } 465 + 466 if (abituguru_write(data, ABIT_UGURU_SENSOR_BANK1 + 2, sensor_addr, 467 buf, 3) != 3) 468 goto abituguru_detect_bank1_sensor_type_exit; ··· 469 sensor_addr, buf, 3, 470 ABIT_UGURU_MAX_RETRIES) != 3) 471 goto abituguru_detect_bank1_sensor_type_exit; 472 + if (buf[0] & test_flag) { 473 ABIT_UGURU_DEBUG(2, " found volt sensor\n"); 474 ret = ABIT_UGURU_IN_SENSOR; 475 goto abituguru_detect_bank1_sensor_type_exit; 476 } else 477 ABIT_UGURU_DEBUG(2, " alarm raised during volt " 478 + "sensor test, but volt range flag not set\n"); 479 } else 480 ABIT_UGURU_DEBUG(2, " alarm not raised during volt sensor " 481 "test\n"); ··· 1287 for (i = 0; i < ARRAY_SIZE(abituguru_sysfs_attr); i++) 1288 device_remove_file(&pdev->dev, 1289 &abituguru_sysfs_attr[i].dev_attr); 1290 + platform_set_drvdata(pdev, NULL); 1291 kfree(data); 1292 return res; 1293 } ··· 1296 int i; 1297 struct abituguru_data *data = platform_get_drvdata(pdev); 1298 1299 hwmon_device_unregister(data->class_dev); 1300 for (i = 0; data->sysfs_attr[i].dev_attr.attr.name; i++) 1301 device_remove_file(&pdev->dev, &data->sysfs_attr[i].dev_attr); 1302 for (i = 0; i < ARRAY_SIZE(abituguru_sysfs_attr); i++) 1303 device_remove_file(&pdev->dev, 1304 &abituguru_sysfs_attr[i].dev_attr); 1305 + platform_set_drvdata(pdev, NULL); 1306 kfree(data); 1307 1308 return 0; ··· 1435 { 1436 int address, err; 1437 struct resource res = { .flags = IORESOURCE_IO }; 1438 + 1439 + #ifdef CONFIG_DMI 1440 + char *board_vendor = dmi_get_system_info(DMI_BOARD_VENDOR); 1441 + 1442 + /* safety check, refuse to load on non Abit motherboards */ 1443 + if (!force && (!board_vendor || 1444 + strcmp(board_vendor, "http://www.abit.com.tw/"))) 1445 + return -ENODEV; 1446 + #endif 1447 1448 address = abituguru_detect(); 1449 if (address < 0)
+1140
drivers/hwmon/abituguru3.c
···
··· 1 + /* 2 + abituguru3.c Copyright (c) 2006 Hans de Goede <j.w.r.degoede@hhs.nl> 3 + 4 + This program is free software; you can redistribute it and/or modify 5 + it under the terms of the GNU General Public License as published by 6 + the Free Software Foundation; either version 2 of the License, or 7 + (at your option) any later version. 8 + 9 + This program is distributed in the hope that it will be useful, 10 + but WITHOUT ANY WARRANTY; without even the implied warranty of 11 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 + GNU General Public License for more details. 13 + 14 + You should have received a copy of the GNU General Public License 15 + along with this program; if not, write to the Free Software 16 + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 17 + */ 18 + /* 19 + This driver supports the sensor part of revision 3 of the custom Abit uGuru 20 + chip found on newer Abit uGuru motherboards. Note: because of lack of specs 21 + only reading the sensors and their settings is supported. 22 + */ 23 + #include <linux/module.h> 24 + #include <linux/init.h> 25 + #include <linux/slab.h> 26 + #include <linux/jiffies.h> 27 + #include <linux/mutex.h> 28 + #include <linux/err.h> 29 + #include <linux/delay.h> 30 + #include <linux/platform_device.h> 31 + #include <linux/hwmon.h> 32 + #include <linux/hwmon-sysfs.h> 33 + #include <asm/io.h> 34 + 35 + /* uGuru3 bank addresses */ 36 + #define ABIT_UGURU3_SETTINGS_BANK 0x01 37 + #define ABIT_UGURU3_SENSORS_BANK 0x08 38 + #define ABIT_UGURU3_MISC_BANK 0x09 39 + #define ABIT_UGURU3_ALARMS_START 0x1E 40 + #define ABIT_UGURU3_SETTINGS_START 0x24 41 + #define ABIT_UGURU3_VALUES_START 0x80 42 + #define ABIT_UGURU3_BOARD_ID 0x0A 43 + /* uGuru3 sensor bank flags */ /* Alarm if: */ 44 + #define ABIT_UGURU3_TEMP_HIGH_ALARM_ENABLE 0x01 /* temp over warn */ 45 + #define ABIT_UGURU3_VOLT_HIGH_ALARM_ENABLE 0x02 /* volt over max */ 46 + #define ABIT_UGURU3_VOLT_LOW_ALARM_ENABLE 0x04 /* volt under min */ 47 + #define ABIT_UGURU3_TEMP_HIGH_ALARM_FLAG 0x10 /* temp is over warn */ 48 + #define ABIT_UGURU3_VOLT_HIGH_ALARM_FLAG 0x20 /* volt is over max */ 49 + #define ABIT_UGURU3_VOLT_LOW_ALARM_FLAG 0x40 /* volt is under min */ 50 + #define ABIT_UGURU3_FAN_LOW_ALARM_ENABLE 0x01 /* fan under min */ 51 + #define ABIT_UGURU3_BEEP_ENABLE 0x08 /* beep if alarm */ 52 + #define ABIT_UGURU3_SHUTDOWN_ENABLE 0x80 /* shutdown if alarm */ 53 + /* sensor types */ 54 + #define ABIT_UGURU3_IN_SENSOR 0 55 + #define ABIT_UGURU3_TEMP_SENSOR 1 56 + #define ABIT_UGURU3_FAN_SENSOR 2 57 + 58 + /* Timeouts / Retries, if these turn out to need a lot of fiddling we could 59 + convert them to params. Determined by trial and error. I assume this is 60 + cpu-speed independent, since the ISA-bus and not the CPU should be the 61 + bottleneck. */ 62 + #define ABIT_UGURU3_WAIT_TIMEOUT 250 63 + /* Normally the 0xAC at the end of synchronize() is reported after the 64 + first read, but sometimes not and we need to poll */ 65 + #define ABIT_UGURU3_SYNCHRONIZE_TIMEOUT 5 66 + /* utility macros */ 67 + #define ABIT_UGURU3_NAME "abituguru3" 68 + #define ABIT_UGURU3_DEBUG(format, arg...) \ 69 + if (verbose) \ 70 + printk(KERN_DEBUG ABIT_UGURU3_NAME ": " format , ## arg) 71 + 72 + /* Macros to help calculate the sysfs_names array length */ 73 + #define ABIT_UGURU3_MAX_NO_SENSORS 26 74 + /* sum of strlen +1 of: in??_input\0, in??_{min,max}\0, in??_{min,max}_alarm\0, 75 + in??_{min,max}_alarm_enable\0, in??_beep\0, in??_shutdown\0, in??_label\0 */ 76 + #define ABIT_UGURU3_IN_NAMES_LENGTH (11 + 2 * 9 + 2 * 15 + 2 * 22 + 10 + 14 + 11) 77 + /* sum of strlen +1 of: temp??_input\0, temp??_max\0, temp??_crit\0, 78 + temp??_alarm\0, temp??_alarm_enable\0, temp??_beep\0, temp??_shutdown\0, 79 + temp??_label\0 */ 80 + #define ABIT_UGURU3_TEMP_NAMES_LENGTH (13 + 11 + 12 + 13 + 20 + 12 + 16 + 13) 81 + /* sum of strlen +1 of: fan??_input\0, fan??_min\0, fan??_alarm\0, 82 + fan??_alarm_enable\0, fan??_beep\0, fan??_shutdown\0, fan??_label\0 */ 83 + #define ABIT_UGURU3_FAN_NAMES_LENGTH (12 + 10 + 12 + 19 + 11 + 15 + 12) 84 + /* Worst case scenario 16 in sensors (longest names_length) and the rest 85 + temp sensors (second longest names_length). */ 86 + #define ABIT_UGURU3_SYSFS_NAMES_LENGTH (16 * ABIT_UGURU3_IN_NAMES_LENGTH + \ 87 + (ABIT_UGURU3_MAX_NO_SENSORS - 16) * ABIT_UGURU3_TEMP_NAMES_LENGTH) 88 + 89 + /* All the macros below are named identical to the openguru2 program 90 + reverse engineered by Louis Kruger, hence the names might not be 100% 91 + logical. I could come up with better names, but I prefer keeping the names 92 + identical so that this driver can be compared with his work more easily. */ 93 + /* Two i/o-ports are used by uGuru */ 94 + #define ABIT_UGURU3_BASE 0x00E0 95 + #define ABIT_UGURU3_CMD 0x00 96 + #define ABIT_UGURU3_DATA 0x04 97 + #define ABIT_UGURU3_REGION_LENGTH 5 98 + /* The wait_xxx functions return this on success and the last contents 99 + of the DATA register (0-255) on failure. */ 100 + #define ABIT_UGURU3_SUCCESS -1 101 + /* uGuru status flags */ 102 + #define ABIT_UGURU3_STATUS_READY_FOR_READ 0x01 103 + #define ABIT_UGURU3_STATUS_BUSY 0x02 104 + 105 + 106 + /* Structures */ 107 + struct abituguru3_sensor_info { 108 + const char* name; 109 + int port; 110 + int type; 111 + int multiplier; 112 + int divisor; 113 + int offset; 114 + }; 115 + 116 + struct abituguru3_motherboard_info { 117 + u16 id; 118 + const char *name; 119 + /* + 1 -> end of sensors indicated by a sensor with name == NULL */ 120 + struct abituguru3_sensor_info sensors[ABIT_UGURU3_MAX_NO_SENSORS + 1]; 121 + }; 122 + 123 + /* For the Abit uGuru, we need to keep some data in memory. 124 + The structure is dynamically allocated, at the same time when a new 125 + abituguru3 device is allocated. */ 126 + struct abituguru3_data { 127 + struct class_device *class_dev; /* hwmon registered device */ 128 + struct mutex update_lock; /* protect access to data and uGuru */ 129 + unsigned short addr; /* uguru base address */ 130 + char valid; /* !=0 if following fields are valid */ 131 + unsigned long last_updated; /* In jiffies */ 132 + 133 + /* For convenience the sysfs attr and their names are generated 134 + automatically. We have max 10 entries per sensor (for in sensors) */ 135 + struct sensor_device_attribute_2 sysfs_attr[ABIT_UGURU3_MAX_NO_SENSORS 136 + * 10]; 137 + 138 + /* Buffer to store the dynamically generated sysfs names */ 139 + char sysfs_names[ABIT_UGURU3_SYSFS_NAMES_LENGTH]; 140 + 141 + /* Pointer to the sensors info for the detected motherboard */ 142 + const struct abituguru3_sensor_info *sensors; 143 + 144 + /* The abituguru3 supports upto 48 sensors, and thus has registers 145 + sets for 48 sensors, for convienence reasons / simplicity of the 146 + code we always read and store all registers for all 48 sensors */ 147 + 148 + /* Alarms for all 48 sensors (1 bit per sensor) */ 149 + u8 alarms[48/8]; 150 + 151 + /* Value of all 48 sensors */ 152 + u8 value[48]; 153 + 154 + /* Settings of all 48 sensors, note in and temp sensors (the first 32 155 + sensors) have 3 bytes of settings, while fans only have 2 bytes, 156 + for convenience we use 3 bytes for all sensors */ 157 + u8 settings[48][3]; 158 + }; 159 + 160 + 161 + /* Constants */ 162 + static const struct abituguru3_motherboard_info abituguru3_motherboards[] = { 163 + { 0x000C, "unknown", { 164 + { "CPU Core", 0, 0, 10, 1, 0 }, 165 + { "DDR", 1, 0, 10, 1, 0 }, 166 + { "DDR VTT", 2, 0, 10, 1, 0 }, 167 + { "CPU VTT 1.2V", 3, 0, 10, 1, 0 }, 168 + { "MCH & PCIE 1.5V", 4, 0, 10, 1, 0 }, 169 + { "MCH 2.5V", 5, 0, 20, 1, 0 }, 170 + { "ICH 1.05V", 6, 0, 10, 1, 0 }, 171 + { "ATX +12V (24-Pin)", 7, 0, 60, 1, 0 }, 172 + { "ATX +12V (4-pin)", 8, 0, 60, 1, 0 }, 173 + { "ATX +5V", 9, 0, 30, 1, 0 }, 174 + { "+3.3V", 10, 0, 20, 1, 0 }, 175 + { "5VSB", 11, 0, 30, 1, 0 }, 176 + { "CPU", 24, 1, 1, 1, 0 }, 177 + { "System ", 25, 1, 1, 1, 0 }, 178 + { "PWM", 26, 1, 1, 1, 0 }, 179 + { "CPU Fan", 32, 2, 60, 1, 0 }, 180 + { "NB Fan", 33, 2, 60, 1, 0 }, 181 + { "SYS FAN", 34, 2, 60, 1, 0 }, 182 + { "AUX1 Fan", 35, 2, 60, 1, 0 }, 183 + { NULL, 0, 0, 0, 0, 0 } } 184 + }, 185 + { 0x000D, "Abit AW8", { 186 + { "CPU Core", 0, 0, 10, 1, 0 }, 187 + { "DDR", 1, 0, 10, 1, 0 }, 188 + { "DDR VTT", 2, 0, 10, 1, 0 }, 189 + { "CPU VTT 1.2V", 3, 0, 10, 1, 0 }, 190 + { "MCH & PCIE 1.5V", 4, 0, 10, 1, 0 }, 191 + { "MCH 2.5V", 5, 0, 20, 1, 0 }, 192 + { "ICH 1.05V", 6, 0, 10, 1, 0 }, 193 + { "ATX +12V (24-Pin)", 7, 0, 60, 1, 0 }, 194 + { "ATX +12V (4-pin)", 8, 0, 60, 1, 0 }, 195 + { "ATX +5V", 9, 0, 30, 1, 0 }, 196 + { "+3.3V", 10, 0, 20, 1, 0 }, 197 + { "5VSB", 11, 0, 30, 1, 0 }, 198 + { "CPU", 24, 1, 1, 1, 0 }, 199 + { "System ", 25, 1, 1, 1, 0 }, 200 + { "PWM1", 26, 1, 1, 1, 0 }, 201 + { "PWM2", 27, 1, 1, 1, 0 }, 202 + { "PWM3", 28, 1, 1, 1, 0 }, 203 + { "PWM4", 29, 1, 1, 1, 0 }, 204 + { "CPU Fan", 32, 2, 60, 1, 0 }, 205 + { "NB Fan", 33, 2, 60, 1, 0 }, 206 + { "SYS Fan", 34, 2, 60, 1, 0 }, 207 + { "AUX1 Fan", 35, 2, 60, 1, 0 }, 208 + { "AUX2 Fan", 36, 2, 60, 1, 0 }, 209 + { "AUX3 Fan", 37, 2, 60, 1, 0 }, 210 + { "AUX4 Fan", 38, 2, 60, 1, 0 }, 211 + { "AUX5 Fan", 39, 2, 60, 1, 0 }, 212 + { NULL, 0, 0, 0, 0, 0 } } 213 + }, 214 + { 0x000E, "AL-8", { 215 + { "CPU Core", 0, 0, 10, 1, 0 }, 216 + { "DDR", 1, 0, 10, 1, 0 }, 217 + { "DDR VTT", 2, 0, 10, 1, 0 }, 218 + { "CPU VTT 1.2V", 3, 0, 10, 1, 0 }, 219 + { "MCH & PCIE 1.5V", 4, 0, 10, 1, 0 }, 220 + { "MCH 2.5V", 5, 0, 20, 1, 0 }, 221 + { "ICH 1.05V", 6, 0, 10, 1, 0 }, 222 + { "ATX +12V (24-Pin)", 7, 0, 60, 1, 0 }, 223 + { "ATX +12V (4-pin)", 8, 0, 60, 1, 0 }, 224 + { "ATX +5V", 9, 0, 30, 1, 0 }, 225 + { "+3.3V", 10, 0, 20, 1, 0 }, 226 + { "5VSB", 11, 0, 30, 1, 0 }, 227 + { "CPU", 24, 1, 1, 1, 0 }, 228 + { "System ", 25, 1, 1, 1, 0 }, 229 + { "PWM", 26, 1, 1, 1, 0 }, 230 + { "CPU Fan", 32, 2, 60, 1, 0 }, 231 + { "NB Fan", 33, 2, 60, 1, 0 }, 232 + { "SYS Fan", 34, 2, 60, 1, 0 }, 233 + { NULL, 0, 0, 0, 0, 0 } } 234 + }, 235 + { 0x000F, "unknown", { 236 + { "CPU Core", 0, 0, 10, 1, 0 }, 237 + { "DDR", 1, 0, 10, 1, 0 }, 238 + { "DDR VTT", 2, 0, 10, 1, 0 }, 239 + { "CPU VTT 1.2V", 3, 0, 10, 1, 0 }, 240 + { "MCH & PCIE 1.5V", 4, 0, 10, 1, 0 }, 241 + { "MCH 2.5V", 5, 0, 20, 1, 0 }, 242 + { "ICH 1.05V", 6, 0, 10, 1, 0 }, 243 + { "ATX +12V (24-Pin)", 7, 0, 60, 1, 0 }, 244 + { "ATX +12V (4-pin)", 8, 0, 60, 1, 0 }, 245 + { "ATX +5V", 9, 0, 30, 1, 0 }, 246 + { "+3.3V", 10, 0, 20, 1, 0 }, 247 + { "5VSB", 11, 0, 30, 1, 0 }, 248 + { "CPU", 24, 1, 1, 1, 0 }, 249 + { "System ", 25, 1, 1, 1, 0 }, 250 + { "PWM", 26, 1, 1, 1, 0 }, 251 + { "CPU Fan", 32, 2, 60, 1, 0 }, 252 + { "NB Fan", 33, 2, 60, 1, 0 }, 253 + { "SYS Fan", 34, 2, 60, 1, 0 }, 254 + { NULL, 0, 0, 0, 0, 0 } } 255 + }, 256 + { 0x0010, "Abit NI8 SLI GR", { 257 + { "CPU Core", 0, 0, 10, 1, 0 }, 258 + { "DDR", 1, 0, 10, 1, 0 }, 259 + { "DDR VTT", 2, 0, 10, 1, 0 }, 260 + { "CPU VTT 1.2V", 3, 0, 10, 1, 0 }, 261 + { "NB 1.4V", 4, 0, 10, 1, 0 }, 262 + { "SB 1.5V", 6, 0, 10, 1, 0 }, 263 + { "ATX +12V (24-Pin)", 7, 0, 60, 1, 0 }, 264 + { "ATX +12V (4-pin)", 8, 0, 60, 1, 0 }, 265 + { "ATX +5V", 9, 0, 30, 1, 0 }, 266 + { "+3.3V", 10, 0, 20, 1, 0 }, 267 + { "5VSB", 11, 0, 30, 1, 0 }, 268 + { "CPU", 24, 1, 1, 1, 0 }, 269 + { "SYS", 25, 1, 1, 1, 0 }, 270 + { "PWM", 26, 1, 1, 1, 0 }, 271 + { "CPU Fan", 32, 2, 60, 1, 0 }, 272 + { "NB Fan", 33, 2, 60, 1, 0 }, 273 + { "SYS Fan", 34, 2, 60, 1, 0 }, 274 + { "AUX1 Fan", 35, 2, 60, 1, 0 }, 275 + { "OTES1 Fan", 36, 2, 60, 1, 0 }, 276 + { NULL, 0, 0, 0, 0, 0 } } 277 + }, 278 + { 0x0011, "Abit AT8 32X", { 279 + { "CPU Core", 0, 0, 10, 1, 0 }, 280 + { "DDR", 1, 0, 20, 1, 0 }, 281 + { "DDR VTT", 2, 0, 10, 1, 0 }, 282 + { "CPU VDDA 2.5V", 6, 0, 20, 1, 0 }, 283 + { "NB 1.8V", 4, 0, 10, 1, 0 }, 284 + { "NB 1.8V Dual", 5, 0, 10, 1, 0 }, 285 + { "HTV 1.2", 3, 0, 10, 1, 0 }, 286 + { "PCIE 1.2V", 12, 0, 10, 1, 0 }, 287 + { "NB 1.2V", 13, 0, 10, 1, 0 }, 288 + { "ATX +12V (24-Pin)", 7, 0, 60, 1, 0 }, 289 + { "ATX +12V (4-pin)", 8, 0, 60, 1, 0 }, 290 + { "ATX +5V", 9, 0, 30, 1, 0 }, 291 + { "+3.3V", 10, 0, 20, 1, 0 }, 292 + { "5VSB", 11, 0, 30, 1, 0 }, 293 + { "CPU", 24, 1, 1, 1, 0 }, 294 + { "NB", 25, 1, 1, 1, 0 }, 295 + { "System", 26, 1, 1, 1, 0 }, 296 + { "PWM", 27, 1, 1, 1, 0 }, 297 + { "CPU Fan", 32, 2, 60, 1, 0 }, 298 + { "NB Fan", 33, 2, 60, 1, 0 }, 299 + { "SYS Fan", 34, 2, 60, 1, 0 }, 300 + { "AUX1 Fan", 35, 2, 60, 1, 0 }, 301 + { "AUX2 Fan", 36, 2, 60, 1, 0 }, 302 + { NULL, 0, 0, 0, 0, 0 } } 303 + }, 304 + { 0x0012, "Abit AN8 32X", { 305 + { "CPU Core", 0, 0, 10, 1, 0 }, 306 + { "DDR", 1, 0, 20, 1, 0 }, 307 + { "DDR VTT", 2, 0, 10, 1, 0 }, 308 + { "HyperTransport", 3, 0, 10, 1, 0 }, 309 + { "CPU VDDA 2.5V", 5, 0, 20, 1, 0 }, 310 + { "NB", 4, 0, 10, 1, 0 }, 311 + { "SB", 6, 0, 10, 1, 0 }, 312 + { "ATX +12V (24-Pin)", 7, 0, 60, 1, 0 }, 313 + { "ATX +12V (4-pin)", 8, 0, 60, 1, 0 }, 314 + { "ATX +5V", 9, 0, 30, 1, 0 }, 315 + { "+3.3V", 10, 0, 20, 1, 0 }, 316 + { "5VSB", 11, 0, 30, 1, 0 }, 317 + { "CPU", 24, 1, 1, 1, 0 }, 318 + { "SYS", 25, 1, 1, 1, 0 }, 319 + { "PWM", 26, 1, 1, 1, 0 }, 320 + { "CPU Fan", 32, 2, 60, 1, 0 }, 321 + { "NB Fan", 33, 2, 60, 1, 0 }, 322 + { "SYS Fan", 34, 2, 60, 1, 0 }, 323 + { "AUX1 Fan", 36, 2, 60, 1, 0 }, 324 + { NULL, 0, 0, 0, 0, 0 } } 325 + }, 326 + { 0x0013, "unknown", { 327 + { "CPU Core", 0, 0, 10, 1, 0 }, 328 + { "DDR", 1, 0, 10, 1, 0 }, 329 + { "DDR VTT", 2, 0, 10, 1, 0 }, 330 + { "CPU VTT 1.2V", 3, 0, 10, 1, 0 }, 331 + { "MCH & PCIE 1.5V", 4, 0, 10, 1, 0 }, 332 + { "MCH 2.5V", 5, 0, 20, 1, 0 }, 333 + { "ICH 1.05V", 6, 0, 10, 1, 0 }, 334 + { "ATX +12V (24-Pin)", 7, 0, 60, 1, 0 }, 335 + { "ATX +12V (4-pin)", 8, 0, 60, 1, 0 }, 336 + { "ATX +5V", 9, 0, 30, 1, 0 }, 337 + { "+3.3V", 10, 0, 20, 1, 0 }, 338 + { "5VSB", 11, 0, 30, 1, 0 }, 339 + { "CPU", 24, 1, 1, 1, 0 }, 340 + { "System ", 25, 1, 1, 1, 0 }, 341 + { "PWM1", 26, 1, 1, 1, 0 }, 342 + { "PWM2", 27, 1, 1, 1, 0 }, 343 + { "PWM3", 28, 1, 1, 1, 0 }, 344 + { "PWM4", 29, 1, 1, 1, 0 }, 345 + { "CPU Fan", 32, 2, 60, 1, 0 }, 346 + { "NB Fan", 33, 2, 60, 1, 0 }, 347 + { "SYS Fan", 34, 2, 60, 1, 0 }, 348 + { "AUX1 Fan", 35, 2, 60, 1, 0 }, 349 + { "AUX2 Fan", 36, 2, 60, 1, 0 }, 350 + { "AUX3 Fan", 37, 2, 60, 1, 0 }, 351 + { "AUX4 Fan", 38, 2, 60, 1, 0 }, 352 + { NULL, 0, 0, 0, 0, 0 } } 353 + }, 354 + { 0x0014, "Abit AB9 Pro", { 355 + { "CPU Core", 0, 0, 10, 1, 0 }, 356 + { "DDR", 1, 0, 10, 1, 0 }, 357 + { "DDR VTT", 2, 0, 10, 1, 0 }, 358 + { "CPU VTT 1.2V", 3, 0, 10, 1, 0 }, 359 + { "MCH & PCIE 1.5V", 4, 0, 10, 1, 0 }, 360 + { "MCH 2.5V", 5, 0, 20, 1, 0 }, 361 + { "ICH 1.05V", 6, 0, 10, 1, 0 }, 362 + { "ATX +12V (24-Pin)", 7, 0, 60, 1, 0 }, 363 + { "ATX +12V (4-pin)", 8, 0, 60, 1, 0 }, 364 + { "ATX +5V", 9, 0, 30, 1, 0 }, 365 + { "+3.3V", 10, 0, 20, 1, 0 }, 366 + { "5VSB", 11, 0, 30, 1, 0 }, 367 + { "CPU", 24, 1, 1, 1, 0 }, 368 + { "System ", 25, 1, 1, 1, 0 }, 369 + { "PWM", 26, 1, 1, 1, 0 }, 370 + { "CPU Fan", 32, 2, 60, 1, 0 }, 371 + { "NB Fan", 33, 2, 60, 1, 0 }, 372 + { "SYS Fan", 34, 2, 60, 1, 0 }, 373 + { NULL, 0, 0, 0, 0, 0 } } 374 + }, 375 + { 0x0015, "unknown", { 376 + { "CPU Core", 0, 0, 10, 1, 0 }, 377 + { "DDR", 1, 0, 20, 1, 0 }, 378 + { "DDR VTT", 2, 0, 10, 1, 0 }, 379 + { "HyperTransport", 3, 0, 10, 1, 0 }, 380 + { "CPU VDDA 2.5V", 5, 0, 20, 1, 0 }, 381 + { "NB", 4, 0, 10, 1, 0 }, 382 + { "SB", 6, 0, 10, 1, 0 }, 383 + { "ATX +12V (24-Pin)", 7, 0, 60, 1, 0 }, 384 + { "ATX +12V (4-pin)", 8, 0, 60, 1, 0 }, 385 + { "ATX +5V", 9, 0, 30, 1, 0 }, 386 + { "+3.3V", 10, 0, 20, 1, 0 }, 387 + { "5VSB", 11, 0, 30, 1, 0 }, 388 + { "CPU", 24, 1, 1, 1, 0 }, 389 + { "SYS", 25, 1, 1, 1, 0 }, 390 + { "PWM", 26, 1, 1, 1, 0 }, 391 + { "CPU Fan", 32, 2, 60, 1, 0 }, 392 + { "NB Fan", 33, 2, 60, 1, 0 }, 393 + { "SYS Fan", 34, 2, 60, 1, 0 }, 394 + { "AUX1 Fan", 33, 2, 60, 1, 0 }, 395 + { "AUX2 Fan", 35, 2, 60, 1, 0 }, 396 + { "AUX3 Fan", 36, 2, 60, 1, 0 }, 397 + { NULL, 0, 0, 0, 0, 0 } } 398 + }, 399 + { 0x0016, "AW9D-MAX", { 400 + { "CPU Core", 0, 0, 10, 1, 0 }, 401 + { "DDR2", 1, 0, 20, 1, 0 }, 402 + { "DDR2 VTT", 2, 0, 10, 1, 0 }, 403 + { "CPU VTT 1.2V", 3, 0, 10, 1, 0 }, 404 + { "MCH & PCIE 1.5V", 4, 0, 10, 1, 0 }, 405 + { "MCH 2.5V", 5, 0, 20, 1, 0 }, 406 + { "ICH 1.05V", 6, 0, 10, 1, 0 }, 407 + { "ATX +12V (24-Pin)", 7, 0, 60, 1, 0 }, 408 + { "ATX +12V (4-pin)", 8, 0, 60, 1, 0 }, 409 + { "ATX +5V", 9, 0, 30, 1, 0 }, 410 + { "+3.3V", 10, 0, 20, 1, 0 }, 411 + { "5VSB", 11, 0, 30, 1, 0 }, 412 + { "CPU", 24, 1, 1, 1, 0 }, 413 + { "System ", 25, 1, 1, 1, 0 }, 414 + { "PWM1", 26, 1, 1, 1, 0 }, 415 + { "PWM2", 27, 1, 1, 1, 0 }, 416 + { "PWM3", 28, 1, 1, 1, 0 }, 417 + { "PWM4", 29, 1, 1, 1, 0 }, 418 + { "CPU Fan", 32, 2, 60, 1, 0 }, 419 + { "NB Fan", 33, 2, 60, 1, 0 }, 420 + { "SYS Fan", 34, 2, 60, 1, 0 }, 421 + { "AUX1 Fan", 35, 2, 60, 1, 0 }, 422 + { "AUX2 Fan", 36, 2, 60, 1, 0 }, 423 + { "AUX3 Fan", 37, 2, 60, 1, 0 }, 424 + { "OTES1 Fan", 38, 2, 60, 1, 0 }, 425 + { NULL, 0, 0, 0, 0, 0 } } 426 + }, 427 + { 0x0017, "unknown", { 428 + { "CPU Core", 0, 0, 10, 1, 0 }, 429 + { "DDR2", 1, 0, 20, 1, 0 }, 430 + { "DDR2 VTT", 2, 0, 10, 1, 0 }, 431 + { "HyperTransport", 3, 0, 10, 1, 0 }, 432 + { "CPU VDDA 2.5V", 6, 0, 20, 1, 0 }, 433 + { "NB 1.8V", 4, 0, 10, 1, 0 }, 434 + { "NB 1.2V ", 13, 0, 10, 1, 0 }, 435 + { "SB 1.2V", 5, 0, 10, 1, 0 }, 436 + { "PCIE 1.2V", 12, 0, 10, 1, 0 }, 437 + { "ATX +12V (24-Pin)", 7, 0, 60, 1, 0 }, 438 + { "ATX +12V (4-pin)", 8, 0, 60, 1, 0 }, 439 + { "ATX +5V", 9, 0, 30, 1, 0 }, 440 + { "ATX +3.3V", 10, 0, 20, 1, 0 }, 441 + { "ATX 5VSB", 11, 0, 30, 1, 0 }, 442 + { "CPU", 24, 1, 1, 1, 0 }, 443 + { "System ", 26, 1, 1, 1, 0 }, 444 + { "PWM", 27, 1, 1, 1, 0 }, 445 + { "CPU FAN", 32, 2, 60, 1, 0 }, 446 + { "SYS FAN", 34, 2, 60, 1, 0 }, 447 + { "AUX1 FAN", 35, 2, 60, 1, 0 }, 448 + { "AUX2 FAN", 36, 2, 60, 1, 0 }, 449 + { "AUX3 FAN", 37, 2, 60, 1, 0 }, 450 + { NULL, 0, 0, 0, 0, 0 } } 451 + }, 452 + { 0x0018, "unknown", { 453 + { "CPU Core", 0, 0, 10, 1, 0 }, 454 + { "DDR2", 1, 0, 20, 1, 0 }, 455 + { "DDR2 VTT", 2, 0, 10, 1, 0 }, 456 + { "CPU VTT", 3, 0, 10, 1, 0 }, 457 + { "MCH 1.25V", 4, 0, 10, 1, 0 }, 458 + { "ICHIO 1.5V", 5, 0, 10, 1, 0 }, 459 + { "ICH 1.05V", 6, 0, 10, 1, 0 }, 460 + { "ATX +12V (24-Pin)", 7, 0, 60, 1, 0 }, 461 + { "ATX +12V (4-pin)", 8, 0, 60, 1, 0 }, 462 + { "ATX +5V", 9, 0, 30, 1, 0 }, 463 + { "+3.3V", 10, 0, 20, 1, 0 }, 464 + { "5VSB", 11, 0, 30, 1, 0 }, 465 + { "CPU", 24, 1, 1, 1, 0 }, 466 + { "System ", 25, 1, 1, 1, 0 }, 467 + { "PWM Phase1", 26, 1, 1, 1, 0 }, 468 + { "PWM Phase2", 27, 1, 1, 1, 0 }, 469 + { "PWM Phase3", 28, 1, 1, 1, 0 }, 470 + { "PWM Phase4", 29, 1, 1, 1, 0 }, 471 + { "PWM Phase5", 30, 1, 1, 1, 0 }, 472 + { "CPU Fan", 32, 2, 60, 1, 0 }, 473 + { "SYS Fan", 34, 2, 60, 1, 0 }, 474 + { "AUX1 Fan", 33, 2, 60, 1, 0 }, 475 + { "AUX2 Fan", 35, 2, 60, 1, 0 }, 476 + { "AUX3 Fan", 36, 2, 60, 1, 0 }, 477 + { NULL, 0, 0, 0, 0, 0 } } 478 + }, 479 + { 0x0019, "unknown", { 480 + { "CPU Core", 7, 0, 10, 1, 0 }, 481 + { "DDR2", 13, 0, 20, 1, 0 }, 482 + { "DDR2 VTT", 14, 0, 10, 1, 0 }, 483 + { "CPU VTT", 3, 0, 20, 1, 0 }, 484 + { "NB 1.2V ", 4, 0, 10, 1, 0 }, 485 + { "SB 1.5V", 6, 0, 10, 1, 0 }, 486 + { "HyperTransport", 5, 0, 10, 1, 0 }, 487 + { "ATX +12V (24-Pin)", 12, 0, 60, 1, 0 }, 488 + { "ATX +12V (4-pin)", 8, 0, 60, 1, 0 }, 489 + { "ATX +5V", 9, 0, 30, 1, 0 }, 490 + { "ATX +3.3V", 10, 0, 20, 1, 0 }, 491 + { "ATX 5VSB", 11, 0, 30, 1, 0 }, 492 + { "CPU", 24, 1, 1, 1, 0 }, 493 + { "System ", 25, 1, 1, 1, 0 }, 494 + { "PWM Phase1", 26, 1, 1, 1, 0 }, 495 + { "PWM Phase2", 27, 1, 1, 1, 0 }, 496 + { "PWM Phase3", 28, 1, 1, 1, 0 }, 497 + { "PWM Phase4", 29, 1, 1, 1, 0 }, 498 + { "PWM Phase5", 30, 1, 1, 1, 0 }, 499 + { "CPU FAN", 32, 2, 60, 1, 0 }, 500 + { "SYS FAN", 34, 2, 60, 1, 0 }, 501 + { "AUX1 FAN", 33, 2, 60, 1, 0 }, 502 + { "AUX2 FAN", 35, 2, 60, 1, 0 }, 503 + { "AUX3 FAN", 36, 2, 60, 1, 0 }, 504 + { NULL, 0, 0, 0, 0, 0 } } 505 + }, 506 + { 0x001A, "unknown", { 507 + { "CPU Core", 0, 0, 10, 1, 0 }, 508 + { "DDR2", 1, 0, 20, 1, 0 }, 509 + { "DDR2 VTT", 2, 0, 10, 1, 0 }, 510 + { "CPU VTT 1.2V", 3, 0, 10, 1, 0 }, 511 + { "MCH 1.25V", 4, 0, 10, 1, 0 }, 512 + { "ICHIO 1.5V", 5, 0, 10, 1, 0 }, 513 + { "ICH 1.05V", 6, 0, 10, 1, 0 }, 514 + { "ATX +12V (24-Pin)", 7, 0, 60, 1, 0 }, 515 + { "ATX +12V (8-pin)", 8, 0, 60, 1, 0 }, 516 + { "ATX +5V", 9, 0, 30, 1, 0 }, 517 + { "+3.3V", 10, 0, 20, 1, 0 }, 518 + { "5VSB", 11, 0, 30, 1, 0 }, 519 + { "CPU", 24, 1, 1, 1, 0 }, 520 + { "System ", 25, 1, 1, 1, 0 }, 521 + { "PWM ", 26, 1, 1, 1, 0 }, 522 + { "PWM Phase2", 27, 1, 1, 1, 0 }, 523 + { "PWM Phase3", 28, 1, 1, 1, 0 }, 524 + { "PWM Phase4", 29, 1, 1, 1, 0 }, 525 + { "PWM Phase5", 30, 1, 1, 1, 0 }, 526 + { "CPU Fan", 32, 2, 60, 1, 0 }, 527 + { "SYS Fan", 34, 2, 60, 1, 0 }, 528 + { "AUX1 Fan", 33, 2, 60, 1, 0 }, 529 + { "AUX2 Fan", 35, 2, 60, 1, 0 }, 530 + { "AUX3 Fan", 36, 2, 60, 1, 0 }, 531 + { NULL, 0, 0, 0, 0, 0 } } 532 + }, 533 + { 0x0000, NULL, { { NULL, 0, 0, 0, 0, 0 } } } 534 + }; 535 + 536 + 537 + /* Insmod parameters */ 538 + static int force; 539 + module_param(force, bool, 0); 540 + MODULE_PARM_DESC(force, "Set to one to force detection."); 541 + /* Default verbose is 1, since this driver is still in the testing phase */ 542 + static int verbose = 1; 543 + module_param(verbose, bool, 0644); 544 + MODULE_PARM_DESC(verbose, "Enable/disable verbose error reporting"); 545 + 546 + 547 + /* wait while the uguru is busy (usually after a write) */ 548 + static int abituguru3_wait_while_busy(struct abituguru3_data *data) 549 + { 550 + u8 x; 551 + int timeout = ABIT_UGURU3_WAIT_TIMEOUT; 552 + 553 + while ((x = inb_p(data->addr + ABIT_UGURU3_DATA)) & 554 + ABIT_UGURU3_STATUS_BUSY) { 555 + timeout--; 556 + if (timeout == 0) 557 + return x; 558 + /* sleep a bit before our last try, to give the uGuru3 one 559 + last chance to respond. */ 560 + if (timeout == 1) 561 + msleep(1); 562 + } 563 + return ABIT_UGURU3_SUCCESS; 564 + } 565 + 566 + /* wait till uguru is ready to be read */ 567 + static int abituguru3_wait_for_read(struct abituguru3_data *data) 568 + { 569 + u8 x; 570 + int timeout = ABIT_UGURU3_WAIT_TIMEOUT; 571 + 572 + while (!((x = inb_p(data->addr + ABIT_UGURU3_DATA)) & 573 + ABIT_UGURU3_STATUS_READY_FOR_READ)) { 574 + timeout--; 575 + if (timeout == 0) 576 + return x; 577 + /* sleep a bit before our last try, to give the uGuru3 one 578 + last chance to respond. */ 579 + if (timeout == 1) 580 + msleep(1); 581 + } 582 + return ABIT_UGURU3_SUCCESS; 583 + } 584 + 585 + /* This synchronizes us with the uGuru3's protocol state machine, this 586 + must be done before each command. */ 587 + static int abituguru3_synchronize(struct abituguru3_data *data) 588 + { 589 + int x, timeout = ABIT_UGURU3_SYNCHRONIZE_TIMEOUT; 590 + 591 + if ((x = abituguru3_wait_while_busy(data)) != ABIT_UGURU3_SUCCESS) { 592 + ABIT_UGURU3_DEBUG("synchronize timeout during initial busy " 593 + "wait, status: 0x%02x\n", x); 594 + return -EIO; 595 + } 596 + 597 + outb(0x20, data->addr + ABIT_UGURU3_DATA); 598 + if ((x = abituguru3_wait_while_busy(data)) != ABIT_UGURU3_SUCCESS) { 599 + ABIT_UGURU3_DEBUG("synchronize timeout after sending 0x20, " 600 + "status: 0x%02x\n", x); 601 + return -EIO; 602 + } 603 + 604 + outb(0x10, data->addr + ABIT_UGURU3_CMD); 605 + if ((x = abituguru3_wait_while_busy(data)) != ABIT_UGURU3_SUCCESS) { 606 + ABIT_UGURU3_DEBUG("synchronize timeout after sending 0x10, " 607 + "status: 0x%02x\n", x); 608 + return -EIO; 609 + } 610 + 611 + outb(0x00, data->addr + ABIT_UGURU3_CMD); 612 + if ((x = abituguru3_wait_while_busy(data)) != ABIT_UGURU3_SUCCESS) { 613 + ABIT_UGURU3_DEBUG("synchronize timeout after sending 0x00, " 614 + "status: 0x%02x\n", x); 615 + return -EIO; 616 + } 617 + 618 + if ((x = abituguru3_wait_for_read(data)) != ABIT_UGURU3_SUCCESS) { 619 + ABIT_UGURU3_DEBUG("synchronize timeout waiting for read, " 620 + "status: 0x%02x\n", x); 621 + return -EIO; 622 + } 623 + 624 + while ((x = inb(data->addr + ABIT_UGURU3_CMD)) != 0xAC) { 625 + timeout--; 626 + if (timeout == 0) { 627 + ABIT_UGURU3_DEBUG("synchronize timeout cmd does not " 628 + "hold 0xAC after synchronize, cmd: 0x%02x\n", 629 + x); 630 + return -EIO; 631 + } 632 + msleep(1); 633 + } 634 + return 0; 635 + } 636 + 637 + /* Read count bytes from sensor sensor_addr in bank bank_addr and store the 638 + result in buf */ 639 + static int abituguru3_read(struct abituguru3_data *data, u8 bank, u8 offset, 640 + u8 count, u8 *buf) 641 + { 642 + int i, x; 643 + 644 + if ((x = abituguru3_synchronize(data))) 645 + return x; 646 + 647 + outb(0x1A, data->addr + ABIT_UGURU3_DATA); 648 + if ((x = abituguru3_wait_while_busy(data)) != ABIT_UGURU3_SUCCESS) { 649 + ABIT_UGURU3_DEBUG("read from 0x%02x:0x%02x timed out after " 650 + "sending 0x1A, status: 0x%02x\n", (unsigned int)bank, 651 + (unsigned int)offset, x); 652 + return -EIO; 653 + } 654 + 655 + outb(bank, data->addr + ABIT_UGURU3_CMD); 656 + if ((x = abituguru3_wait_while_busy(data)) != ABIT_UGURU3_SUCCESS) { 657 + ABIT_UGURU3_DEBUG("read from 0x%02x:0x%02x timed out after " 658 + "sending the bank, status: 0x%02x\n", 659 + (unsigned int)bank, (unsigned int)offset, x); 660 + return -EIO; 661 + } 662 + 663 + outb(offset, data->addr + ABIT_UGURU3_CMD); 664 + if ((x = abituguru3_wait_while_busy(data)) != ABIT_UGURU3_SUCCESS) { 665 + ABIT_UGURU3_DEBUG("read from 0x%02x:0x%02x timed out after " 666 + "sending the offset, status: 0x%02x\n", 667 + (unsigned int)bank, (unsigned int)offset, x); 668 + return -EIO; 669 + } 670 + 671 + outb(count, data->addr + ABIT_UGURU3_CMD); 672 + if ((x = abituguru3_wait_while_busy(data)) != ABIT_UGURU3_SUCCESS) { 673 + ABIT_UGURU3_DEBUG("read from 0x%02x:0x%02x timed out after " 674 + "sending the count, status: 0x%02x\n", 675 + (unsigned int)bank, (unsigned int)offset, x); 676 + return -EIO; 677 + } 678 + 679 + for (i = 0; i < count; i++) { 680 + if ((x = abituguru3_wait_for_read(data)) != 681 + ABIT_UGURU3_SUCCESS) { 682 + ABIT_UGURU3_DEBUG("timeout reading byte %d from " 683 + "0x%02x:0x%02x, status: 0x%02x\n", i, 684 + (unsigned int)bank, (unsigned int)offset, x); 685 + break; 686 + } 687 + buf[i] = inb(data->addr + ABIT_UGURU3_CMD); 688 + } 689 + return i; 690 + } 691 + 692 + /* Sensor settings are stored 1 byte per offset with the bytes 693 + placed add consecutive offsets. */ 694 + int abituguru3_read_increment_offset(struct abituguru3_data *data, u8 bank, 695 + u8 offset, u8 count, u8 *buf, int offset_count) 696 + { 697 + int i, x; 698 + 699 + for (i = 0; i < offset_count; i++) 700 + if ((x = abituguru3_read(data, bank, offset + i, count, 701 + buf + i * count)) != count) 702 + return i * count + (i && (x < 0)) ? 0 : x; 703 + 704 + return i * count; 705 + } 706 + 707 + /* Following are the sysfs callback functions. These functions expect: 708 + sensor_device_attribute_2->index: index into the data->sensors array 709 + sensor_device_attribute_2->nr: register offset, bitmask or NA. */ 710 + static struct abituguru3_data *abituguru3_update_device(struct device *dev); 711 + 712 + static ssize_t show_value(struct device *dev, 713 + struct device_attribute *devattr, char *buf) 714 + { 715 + int value; 716 + struct sensor_device_attribute_2 *attr = to_sensor_dev_attr_2(devattr); 717 + struct abituguru3_data *data = abituguru3_update_device(dev); 718 + const struct abituguru3_sensor_info *sensor; 719 + 720 + if (!data) 721 + return -EIO; 722 + 723 + sensor = &data->sensors[attr->index]; 724 + 725 + /* are we reading a setting, or is this a normal read? */ 726 + if (attr->nr) 727 + value = data->settings[sensor->port][attr->nr]; 728 + else 729 + value = data->value[sensor->port]; 730 + 731 + /* convert the value */ 732 + value = (value * sensor->multiplier) / sensor->divisor + 733 + sensor->offset; 734 + 735 + /* alternatively we could update the sensors settings struct for this, 736 + but then its contents would differ from the windows sw ini files */ 737 + if (sensor->type == ABIT_UGURU3_TEMP_SENSOR) 738 + value *= 1000; 739 + 740 + return sprintf(buf, "%d\n", value); 741 + } 742 + 743 + static ssize_t show_alarm(struct device *dev, 744 + struct device_attribute *devattr, char *buf) 745 + { 746 + int port; 747 + struct sensor_device_attribute_2 *attr = to_sensor_dev_attr_2(devattr); 748 + struct abituguru3_data *data = abituguru3_update_device(dev); 749 + 750 + if (!data) 751 + return -EIO; 752 + 753 + port = data->sensors[attr->index].port; 754 + 755 + /* See if the alarm bit for this sensor is set and if a bitmask is 756 + given in attr->nr also check if the alarm matches the type of alarm 757 + we're looking for (for volt it can be either low or high). The type 758 + is stored in a few readonly bits in the settings of the sensor. */ 759 + if ((data->alarms[port / 8] & (0x01 << (port % 8))) && 760 + (!attr->nr || (data->settings[port][0] & attr->nr))) 761 + return sprintf(buf, "1\n"); 762 + else 763 + return sprintf(buf, "0\n"); 764 + } 765 + 766 + static ssize_t show_mask(struct device *dev, 767 + struct device_attribute *devattr, char *buf) 768 + { 769 + struct sensor_device_attribute_2 *attr = to_sensor_dev_attr_2(devattr); 770 + struct abituguru3_data *data = dev_get_drvdata(dev); 771 + 772 + if (data->settings[data->sensors[attr->index].port][0] & attr->nr) 773 + return sprintf(buf, "1\n"); 774 + else 775 + return sprintf(buf, "0\n"); 776 + } 777 + 778 + static ssize_t show_label(struct device *dev, 779 + struct device_attribute *devattr, char *buf) 780 + { 781 + struct sensor_device_attribute_2 *attr = to_sensor_dev_attr_2(devattr); 782 + struct abituguru3_data *data = dev_get_drvdata(dev); 783 + 784 + return sprintf(buf, "%s\n", data->sensors[attr->index].name); 785 + } 786 + 787 + static ssize_t show_name(struct device *dev, 788 + struct device_attribute *devattr, char *buf) 789 + { 790 + return sprintf(buf, "%s\n", ABIT_UGURU3_NAME); 791 + } 792 + 793 + /* Sysfs attr templates, the real entries are generated automatically. */ 794 + static const 795 + struct sensor_device_attribute_2 abituguru3_sysfs_templ[3][10] = { { 796 + SENSOR_ATTR_2(in%d_input, 0444, show_value, NULL, 0, 0), 797 + SENSOR_ATTR_2(in%d_min, 0444, show_value, NULL, 1, 0), 798 + SENSOR_ATTR_2(in%d_max, 0444, show_value, NULL, 2, 0), 799 + SENSOR_ATTR_2(in%d_min_alarm, 0444, show_alarm, NULL, 800 + ABIT_UGURU3_VOLT_LOW_ALARM_FLAG, 0), 801 + SENSOR_ATTR_2(in%d_max_alarm, 0444, show_alarm, NULL, 802 + ABIT_UGURU3_VOLT_HIGH_ALARM_FLAG, 0), 803 + SENSOR_ATTR_2(in%d_beep, 0444, show_mask, NULL, 804 + ABIT_UGURU3_BEEP_ENABLE, 0), 805 + SENSOR_ATTR_2(in%d_shutdown, 0444, show_mask, NULL, 806 + ABIT_UGURU3_SHUTDOWN_ENABLE, 0), 807 + SENSOR_ATTR_2(in%d_min_alarm_enable, 0444, show_mask, NULL, 808 + ABIT_UGURU3_VOLT_LOW_ALARM_ENABLE, 0), 809 + SENSOR_ATTR_2(in%d_max_alarm_enable, 0444, show_mask, NULL, 810 + ABIT_UGURU3_VOLT_HIGH_ALARM_ENABLE, 0), 811 + SENSOR_ATTR_2(in%d_label, 0444, show_label, NULL, 0, 0) 812 + }, { 813 + SENSOR_ATTR_2(temp%d_input, 0444, show_value, NULL, 0, 0), 814 + SENSOR_ATTR_2(temp%d_max, 0444, show_value, NULL, 1, 0), 815 + SENSOR_ATTR_2(temp%d_crit, 0444, show_value, NULL, 2, 0), 816 + SENSOR_ATTR_2(temp%d_alarm, 0444, show_alarm, NULL, 0, 0), 817 + SENSOR_ATTR_2(temp%d_beep, 0444, show_mask, NULL, 818 + ABIT_UGURU3_BEEP_ENABLE, 0), 819 + SENSOR_ATTR_2(temp%d_shutdown, 0444, show_mask, NULL, 820 + ABIT_UGURU3_SHUTDOWN_ENABLE, 0), 821 + SENSOR_ATTR_2(temp%d_alarm_enable, 0444, show_mask, NULL, 822 + ABIT_UGURU3_TEMP_HIGH_ALARM_ENABLE, 0), 823 + SENSOR_ATTR_2(temp%d_label, 0444, show_label, NULL, 0, 0) 824 + }, { 825 + SENSOR_ATTR_2(fan%d_input, 0444, show_value, NULL, 0, 0), 826 + SENSOR_ATTR_2(fan%d_min, 0444, show_value, NULL, 1, 0), 827 + SENSOR_ATTR_2(fan%d_alarm, 0444, show_alarm, NULL, 0, 0), 828 + SENSOR_ATTR_2(fan%d_beep, 0444, show_mask, NULL, 829 + ABIT_UGURU3_BEEP_ENABLE, 0), 830 + SENSOR_ATTR_2(fan%d_shutdown, 0444, show_mask, NULL, 831 + ABIT_UGURU3_SHUTDOWN_ENABLE, 0), 832 + SENSOR_ATTR_2(fan%d_alarm_enable, 0444, show_mask, NULL, 833 + ABIT_UGURU3_FAN_LOW_ALARM_ENABLE, 0), 834 + SENSOR_ATTR_2(fan%d_label, 0444, show_label, NULL, 0, 0) 835 + } }; 836 + 837 + static struct sensor_device_attribute_2 abituguru3_sysfs_attr[] = { 838 + SENSOR_ATTR_2(name, 0444, show_name, NULL, 0, 0), 839 + }; 840 + 841 + static int __devinit abituguru3_probe(struct platform_device *pdev) 842 + { 843 + const int no_sysfs_attr[3] = { 10, 8, 7 }; 844 + int sensor_index[3] = { 0, 1, 1 }; 845 + struct abituguru3_data *data; 846 + int i, j, type, used, sysfs_names_free, sysfs_attr_i, res = -ENODEV; 847 + char *sysfs_filename; 848 + u8 buf[2]; 849 + u16 id; 850 + 851 + if (!(data = kzalloc(sizeof(struct abituguru3_data), GFP_KERNEL))) 852 + return -ENOMEM; 853 + 854 + data->addr = platform_get_resource(pdev, IORESOURCE_IO, 0)->start; 855 + mutex_init(&data->update_lock); 856 + platform_set_drvdata(pdev, data); 857 + 858 + /* Read the motherboard ID */ 859 + if ((i = abituguru3_read(data, ABIT_UGURU3_MISC_BANK, 860 + ABIT_UGURU3_BOARD_ID, 2, buf)) != 2) { 861 + goto abituguru3_probe_error; 862 + } 863 + 864 + /* Completely read the uGuru to see if one really is there */ 865 + if (!abituguru3_update_device(&pdev->dev)) 866 + goto abituguru3_probe_error; 867 + 868 + /* lookup the ID in our motherboard table */ 869 + id = ((u16)buf[0] << 8) | (u16)buf[1]; 870 + for (i = 0; abituguru3_motherboards[i].id; i++) 871 + if (abituguru3_motherboards[i].id == id) 872 + break; 873 + if (!abituguru3_motherboards[i].id) { 874 + printk(KERN_ERR ABIT_UGURU3_NAME ": error unknown motherboard " 875 + "ID: %04X. Please report this to the abituguru3 " 876 + "maintainer (see MAINTAINERS)\n", (unsigned int)id); 877 + goto abituguru3_probe_error; 878 + } 879 + data->sensors = abituguru3_motherboards[i].sensors; 880 + printk(KERN_INFO ABIT_UGURU3_NAME ": found Abit uGuru3, motherboard " 881 + "ID: %04X (%s)\n", (unsigned int)id, 882 + abituguru3_motherboards[i].name); 883 + 884 + /* Fill the sysfs attr array */ 885 + sysfs_attr_i = 0; 886 + sysfs_filename = data->sysfs_names; 887 + sysfs_names_free = ABIT_UGURU3_SYSFS_NAMES_LENGTH; 888 + for (i = 0; data->sensors[i].name; i++) { 889 + /* Fail safe check, this should never happen! */ 890 + if (i >= ABIT_UGURU3_MAX_NO_SENSORS) { 891 + printk(KERN_ERR ABIT_UGURU3_NAME 892 + ": Fatal error motherboard has more sensors " 893 + "then ABIT_UGURU3_MAX_NO_SENSORS. This should " 894 + "never happen please report to the abituguru3 " 895 + "maintainer (see MAINTAINERS)\n"); 896 + res = -ENAMETOOLONG; 897 + goto abituguru3_probe_error; 898 + } 899 + type = data->sensors[i].type; 900 + for (j = 0; j < no_sysfs_attr[type]; j++) { 901 + used = snprintf(sysfs_filename, sysfs_names_free, 902 + abituguru3_sysfs_templ[type][j].dev_attr.attr. 903 + name, sensor_index[type]) + 1; 904 + data->sysfs_attr[sysfs_attr_i] = 905 + abituguru3_sysfs_templ[type][j]; 906 + data->sysfs_attr[sysfs_attr_i].dev_attr.attr.name = 907 + sysfs_filename; 908 + data->sysfs_attr[sysfs_attr_i].index = i; 909 + sysfs_filename += used; 910 + sysfs_names_free -= used; 911 + sysfs_attr_i++; 912 + } 913 + sensor_index[type]++; 914 + } 915 + /* Fail safe check, this should never happen! */ 916 + if (sysfs_names_free < 0) { 917 + printk(KERN_ERR ABIT_UGURU3_NAME 918 + ": Fatal error ran out of space for sysfs attr names. " 919 + "This should never happen please report to the " 920 + "abituguru3 maintainer (see MAINTAINERS)\n"); 921 + res = -ENAMETOOLONG; 922 + goto abituguru3_probe_error; 923 + } 924 + 925 + /* Register sysfs hooks */ 926 + for (i = 0; i < sysfs_attr_i; i++) 927 + if (device_create_file(&pdev->dev, 928 + &data->sysfs_attr[i].dev_attr)) 929 + goto abituguru3_probe_error; 930 + for (i = 0; i < ARRAY_SIZE(abituguru3_sysfs_attr); i++) 931 + if (device_create_file(&pdev->dev, 932 + &abituguru3_sysfs_attr[i].dev_attr)) 933 + goto abituguru3_probe_error; 934 + 935 + data->class_dev = hwmon_device_register(&pdev->dev); 936 + if (IS_ERR(data->class_dev)) { 937 + res = PTR_ERR(data->class_dev); 938 + goto abituguru3_probe_error; 939 + } 940 + 941 + return 0; /* success */ 942 + 943 + abituguru3_probe_error: 944 + for (i = 0; data->sysfs_attr[i].dev_attr.attr.name; i++) 945 + device_remove_file(&pdev->dev, &data->sysfs_attr[i].dev_attr); 946 + for (i = 0; i < ARRAY_SIZE(abituguru3_sysfs_attr); i++) 947 + device_remove_file(&pdev->dev, 948 + &abituguru3_sysfs_attr[i].dev_attr); 949 + kfree(data); 950 + return res; 951 + } 952 + 953 + static int __devexit abituguru3_remove(struct platform_device *pdev) 954 + { 955 + int i; 956 + struct abituguru3_data *data = platform_get_drvdata(pdev); 957 + 958 + platform_set_drvdata(pdev, NULL); 959 + hwmon_device_unregister(data->class_dev); 960 + for (i = 0; data->sysfs_attr[i].dev_attr.attr.name; i++) 961 + device_remove_file(&pdev->dev, &data->sysfs_attr[i].dev_attr); 962 + for (i = 0; i < ARRAY_SIZE(abituguru3_sysfs_attr); i++) 963 + device_remove_file(&pdev->dev, 964 + &abituguru3_sysfs_attr[i].dev_attr); 965 + kfree(data); 966 + 967 + return 0; 968 + } 969 + 970 + static struct abituguru3_data *abituguru3_update_device(struct device *dev) 971 + { 972 + int i; 973 + struct abituguru3_data *data = dev_get_drvdata(dev); 974 + 975 + mutex_lock(&data->update_lock); 976 + if (!data->valid || time_after(jiffies, data->last_updated + HZ)) { 977 + /* Clear data->valid while updating */ 978 + data->valid = 0; 979 + /* Read alarms */ 980 + if (abituguru3_read_increment_offset(data, 981 + ABIT_UGURU3_SETTINGS_BANK, 982 + ABIT_UGURU3_ALARMS_START, 983 + 1, data->alarms, 48/8) != (48/8)) 984 + goto LEAVE_UPDATE; 985 + /* Read in and temp sensors (3 byte settings / sensor) */ 986 + for (i = 0; i < 32; i++) { 987 + if (abituguru3_read(data, ABIT_UGURU3_SENSORS_BANK, 988 + ABIT_UGURU3_VALUES_START + i, 989 + 1, &data->value[i]) != 1) 990 + goto LEAVE_UPDATE; 991 + if (abituguru3_read_increment_offset(data, 992 + ABIT_UGURU3_SETTINGS_BANK, 993 + ABIT_UGURU3_SETTINGS_START + i * 3, 994 + 1, 995 + data->settings[i], 3) != 3) 996 + goto LEAVE_UPDATE; 997 + } 998 + /* Read temp sensors (2 byte settings / sensor) */ 999 + for (i = 0; i < 16; i++) { 1000 + if (abituguru3_read(data, ABIT_UGURU3_SENSORS_BANK, 1001 + ABIT_UGURU3_VALUES_START + 32 + i, 1002 + 1, &data->value[32 + i]) != 1) 1003 + goto LEAVE_UPDATE; 1004 + if (abituguru3_read_increment_offset(data, 1005 + ABIT_UGURU3_SETTINGS_BANK, 1006 + ABIT_UGURU3_SETTINGS_START + 32 * 3 + 1007 + i * 2, 1, 1008 + data->settings[32 + i], 2) != 2) 1009 + goto LEAVE_UPDATE; 1010 + } 1011 + data->last_updated = jiffies; 1012 + data->valid = 1; 1013 + } 1014 + LEAVE_UPDATE: 1015 + mutex_unlock(&data->update_lock); 1016 + if (data->valid) 1017 + return data; 1018 + else 1019 + return NULL; 1020 + } 1021 + 1022 + #ifdef CONFIG_PM 1023 + static int abituguru3_suspend(struct platform_device *pdev, pm_message_t state) 1024 + { 1025 + struct abituguru3_data *data = platform_get_drvdata(pdev); 1026 + /* make sure all communications with the uguru3 are done and no new 1027 + ones are started */ 1028 + mutex_lock(&data->update_lock); 1029 + return 0; 1030 + } 1031 + 1032 + static int abituguru3_resume(struct platform_device *pdev) 1033 + { 1034 + struct abituguru3_data *data = platform_get_drvdata(pdev); 1035 + mutex_unlock(&data->update_lock); 1036 + return 0; 1037 + } 1038 + #else 1039 + #define abituguru3_suspend NULL 1040 + #define abituguru3_resume NULL 1041 + #endif /* CONFIG_PM */ 1042 + 1043 + static struct platform_driver abituguru3_driver = { 1044 + .driver = { 1045 + .owner = THIS_MODULE, 1046 + .name = ABIT_UGURU3_NAME, 1047 + }, 1048 + .probe = abituguru3_probe, 1049 + .remove = __devexit_p(abituguru3_remove), 1050 + .suspend = abituguru3_suspend, 1051 + .resume = abituguru3_resume 1052 + }; 1053 + 1054 + static int __init abituguru3_detect(void) 1055 + { 1056 + /* See if there is an uguru3 there. An idle uGuru3 will hold 0x00 or 1057 + 0x08 at DATA and 0xAC at CMD. Sometimes the uGuru3 will hold 0x05 1058 + at CMD instead, why is unknown. So we test for 0x05 too. */ 1059 + u8 data_val = inb_p(ABIT_UGURU3_BASE + ABIT_UGURU3_DATA); 1060 + u8 cmd_val = inb_p(ABIT_UGURU3_BASE + ABIT_UGURU3_CMD); 1061 + if (((data_val == 0x00) || (data_val == 0x08)) && 1062 + ((cmd_val == 0xAC) || (cmd_val == 0x05))) 1063 + return ABIT_UGURU3_BASE; 1064 + 1065 + ABIT_UGURU3_DEBUG("no Abit uGuru3 found, data = 0x%02X, cmd = " 1066 + "0x%02X\n", (unsigned int)data_val, (unsigned int)cmd_val); 1067 + 1068 + if (force) { 1069 + printk(KERN_INFO ABIT_UGURU3_NAME ": Assuming Abit uGuru3 is " 1070 + "present because of \"force\" parameter\n"); 1071 + return ABIT_UGURU3_BASE; 1072 + } 1073 + 1074 + /* No uGuru3 found */ 1075 + return -ENODEV; 1076 + } 1077 + 1078 + static struct platform_device *abituguru3_pdev; 1079 + 1080 + static int __init abituguru3_init(void) 1081 + { 1082 + int address, err; 1083 + struct resource res = { .flags = IORESOURCE_IO }; 1084 + 1085 + address = abituguru3_detect(); 1086 + if (address < 0) 1087 + return address; 1088 + 1089 + err = platform_driver_register(&abituguru3_driver); 1090 + if (err) 1091 + goto exit; 1092 + 1093 + abituguru3_pdev = platform_device_alloc(ABIT_UGURU3_NAME, address); 1094 + if (!abituguru3_pdev) { 1095 + printk(KERN_ERR ABIT_UGURU3_NAME 1096 + ": Device allocation failed\n"); 1097 + err = -ENOMEM; 1098 + goto exit_driver_unregister; 1099 + } 1100 + 1101 + res.start = address; 1102 + res.end = address + ABIT_UGURU3_REGION_LENGTH - 1; 1103 + res.name = ABIT_UGURU3_NAME; 1104 + 1105 + err = platform_device_add_resources(abituguru3_pdev, &res, 1); 1106 + if (err) { 1107 + printk(KERN_ERR ABIT_UGURU3_NAME 1108 + ": Device resource addition failed (%d)\n", err); 1109 + goto exit_device_put; 1110 + } 1111 + 1112 + err = platform_device_add(abituguru3_pdev); 1113 + if (err) { 1114 + printk(KERN_ERR ABIT_UGURU3_NAME 1115 + ": Device addition failed (%d)\n", err); 1116 + goto exit_device_put; 1117 + } 1118 + 1119 + return 0; 1120 + 1121 + exit_device_put: 1122 + platform_device_put(abituguru3_pdev); 1123 + exit_driver_unregister: 1124 + platform_driver_unregister(&abituguru3_driver); 1125 + exit: 1126 + return err; 1127 + } 1128 + 1129 + static void __exit abituguru3_exit(void) 1130 + { 1131 + platform_device_unregister(abituguru3_pdev); 1132 + platform_driver_unregister(&abituguru3_driver); 1133 + } 1134 + 1135 + MODULE_AUTHOR("Hans de Goede <j.w.r.degoede@hhs.nl>"); 1136 + MODULE_DESCRIPTION("Abit uGuru3 Sensor device"); 1137 + MODULE_LICENSE("GPL"); 1138 + 1139 + module_init(abituguru3_init); 1140 + module_exit(abituguru3_exit);
+1 -1
drivers/hwmon/coretemp.c
··· 318 } 319 320 #ifdef CONFIG_HOTPLUG_CPU 321 - void coretemp_device_remove(unsigned int cpu) 322 { 323 struct pdev_entry *p, *n; 324 mutex_lock(&pdev_list_mutex);
··· 318 } 319 320 #ifdef CONFIG_HOTPLUG_CPU 321 + static void coretemp_device_remove(unsigned int cpu) 322 { 323 struct pdev_entry *p, *n; 324 mutex_lock(&pdev_list_mutex);
+2080
drivers/hwmon/dme1737.c
···
··· 1 + /* 2 + * dme1737.c - driver for the SMSC DME1737 and Asus A8000 Super-I/O chips 3 + * integrated hardware monitoring features. 4 + * Copyright (c) 2007 Juerg Haefliger <juergh@gmail.com> 5 + * 6 + * This driver is based on the LM85 driver. The hardware monitoring 7 + * capabilities of the DME1737 are very similar to the LM85 with some 8 + * additional features. Even though the DME1737 is a Super-I/O chip, the 9 + * hardware monitoring registers are only accessible via SMBus. 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 13 + * the Free Software Foundation; either version 2 of the License, or 14 + * (at your option) any later version. 15 + * 16 + * This program is distributed in the hope that it will be useful, 17 + * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 + * GNU General Public License for more details. 20 + * 21 + * You should have received a copy of the GNU General Public License 22 + * along with this program; if not, write to the Free Software 23 + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 24 + */ 25 + 26 + #include <linux/module.h> 27 + #include <linux/init.h> 28 + #include <linux/slab.h> 29 + #include <linux/jiffies.h> 30 + #include <linux/i2c.h> 31 + #include <linux/hwmon.h> 32 + #include <linux/hwmon-sysfs.h> 33 + #include <linux/hwmon-vid.h> 34 + #include <linux/err.h> 35 + #include <linux/mutex.h> 36 + #include <asm/io.h> 37 + 38 + /* Module load parameters */ 39 + static int force_start; 40 + module_param(force_start, bool, 0); 41 + MODULE_PARM_DESC(force_start, "Force the chip to start monitoring inputs"); 42 + 43 + /* Addresses to scan */ 44 + static unsigned short normal_i2c[] = {0x2c, 0x2d, 0x2e, I2C_CLIENT_END}; 45 + 46 + /* Insmod parameters */ 47 + I2C_CLIENT_INSMOD_1(dme1737); 48 + 49 + /* --------------------------------------------------------------------- 50 + * Registers 51 + * 52 + * The sensors are defined as follows: 53 + * 54 + * Voltages Temperatures 55 + * -------- ------------ 56 + * in0 +5VTR (+5V stdby) temp1 Remote diode 1 57 + * in1 Vccp (proc core) temp2 Internal temp 58 + * in2 VCC (internal +3.3V) temp3 Remote diode 2 59 + * in3 +5V 60 + * in4 +12V 61 + * in5 VTR (+3.3V stby) 62 + * in6 Vbat 63 + * 64 + * --------------------------------------------------------------------- */ 65 + 66 + /* Voltages (in) numbered 0-6 (ix) */ 67 + #define DME1737_REG_IN(ix) ((ix) < 5 ? 0x20 + (ix) \ 68 + : 0x94 + (ix)) 69 + #define DME1737_REG_IN_MIN(ix) ((ix) < 5 ? 0x44 + (ix) * 2 \ 70 + : 0x91 + (ix) * 2) 71 + #define DME1737_REG_IN_MAX(ix) ((ix) < 5 ? 0x45 + (ix) * 2 \ 72 + : 0x92 + (ix) * 2) 73 + 74 + /* Temperatures (temp) numbered 0-2 (ix) */ 75 + #define DME1737_REG_TEMP(ix) (0x25 + (ix)) 76 + #define DME1737_REG_TEMP_MIN(ix) (0x4e + (ix) * 2) 77 + #define DME1737_REG_TEMP_MAX(ix) (0x4f + (ix) * 2) 78 + #define DME1737_REG_TEMP_OFFSET(ix) ((ix) == 0 ? 0x1f \ 79 + : 0x1c + (ix)) 80 + 81 + /* Voltage and temperature LSBs 82 + * The LSBs (4 bits each) are stored in 5 registers with the following layouts: 83 + * IN_TEMP_LSB(0) = [in5, in6] 84 + * IN_TEMP_LSB(1) = [temp3, temp1] 85 + * IN_TEMP_LSB(2) = [in4, temp2] 86 + * IN_TEMP_LSB(3) = [in3, in0] 87 + * IN_TEMP_LSB(4) = [in2, in1] */ 88 + #define DME1737_REG_IN_TEMP_LSB(ix) (0x84 + (ix)) 89 + static const u8 DME1737_REG_IN_LSB[] = {3, 4, 4, 3, 2, 0, 0}; 90 + static const u8 DME1737_REG_IN_LSB_SHL[] = {4, 4, 0, 0, 0, 0, 4}; 91 + static const u8 DME1737_REG_TEMP_LSB[] = {1, 2, 1}; 92 + static const u8 DME1737_REG_TEMP_LSB_SHL[] = {4, 4, 0}; 93 + 94 + /* Fans numbered 0-5 (ix) */ 95 + #define DME1737_REG_FAN(ix) ((ix) < 4 ? 0x28 + (ix) * 2 \ 96 + : 0xa1 + (ix) * 2) 97 + #define DME1737_REG_FAN_MIN(ix) ((ix) < 4 ? 0x54 + (ix) * 2 \ 98 + : 0xa5 + (ix) * 2) 99 + #define DME1737_REG_FAN_OPT(ix) ((ix) < 4 ? 0x90 + (ix) \ 100 + : 0xb2 + (ix)) 101 + #define DME1737_REG_FAN_MAX(ix) (0xb4 + (ix)) /* only for fan[4-5] */ 102 + 103 + /* PWMs numbered 0-2, 4-5 (ix) */ 104 + #define DME1737_REG_PWM(ix) ((ix) < 3 ? 0x30 + (ix) \ 105 + : 0xa1 + (ix)) 106 + #define DME1737_REG_PWM_CONFIG(ix) (0x5c + (ix)) /* only for pwm[0-2] */ 107 + #define DME1737_REG_PWM_MIN(ix) (0x64 + (ix)) /* only for pwm[0-2] */ 108 + #define DME1737_REG_PWM_FREQ(ix) ((ix) < 3 ? 0x5f + (ix) \ 109 + : 0xa3 + (ix)) 110 + /* The layout of the ramp rate registers is different from the other pwm 111 + * registers. The bits for the 3 PWMs are stored in 2 registers: 112 + * PWM_RR(0) = [OFF3, OFF2, OFF1, RES, RR1E, RR1-2, RR1-1, RR1-0] 113 + * PWM_RR(1) = [RR2E, RR2-2, RR2-1, RR2-0, RR3E, RR3-2, RR3-1, RR3-0] */ 114 + #define DME1737_REG_PWM_RR(ix) (0x62 + (ix)) /* only for pwm[0-2] */ 115 + 116 + /* Thermal zones 0-2 */ 117 + #define DME1737_REG_ZONE_LOW(ix) (0x67 + (ix)) 118 + #define DME1737_REG_ZONE_ABS(ix) (0x6a + (ix)) 119 + /* The layout of the hysteresis registers is different from the other zone 120 + * registers. The bits for the 3 zones are stored in 2 registers: 121 + * ZONE_HYST(0) = [H1-3, H1-2, H1-1, H1-0, H2-3, H2-2, H2-1, H2-0] 122 + * ZONE_HYST(1) = [H3-3, H3-2, H3-1, H3-0, RES, RES, RES, RES] */ 123 + #define DME1737_REG_ZONE_HYST(ix) (0x6d + (ix)) 124 + 125 + /* Alarm registers and bit mapping 126 + * The 3 8-bit alarm registers will be concatenated to a single 32-bit 127 + * alarm value [0, ALARM3, ALARM2, ALARM1]. */ 128 + #define DME1737_REG_ALARM1 0x41 129 + #define DME1737_REG_ALARM2 0x42 130 + #define DME1737_REG_ALARM3 0x83 131 + static const u8 DME1737_BIT_ALARM_IN[] = {0, 1, 2, 3, 8, 16, 17}; 132 + static const u8 DME1737_BIT_ALARM_TEMP[] = {4, 5, 6}; 133 + static const u8 DME1737_BIT_ALARM_FAN[] = {10, 11, 12, 13, 22, 23}; 134 + 135 + /* Miscellaneous registers */ 136 + #define DME1737_REG_COMPANY 0x3e 137 + #define DME1737_REG_VERSTEP 0x3f 138 + #define DME1737_REG_CONFIG 0x40 139 + #define DME1737_REG_CONFIG2 0x7f 140 + #define DME1737_REG_VID 0x43 141 + #define DME1737_REG_TACH_PWM 0x81 142 + 143 + /* --------------------------------------------------------------------- 144 + * Misc defines 145 + * --------------------------------------------------------------------- */ 146 + 147 + /* Chip identification */ 148 + #define DME1737_COMPANY_SMSC 0x5c 149 + #define DME1737_VERSTEP 0x88 150 + #define DME1737_VERSTEP_MASK 0xf8 151 + 152 + /* --------------------------------------------------------------------- 153 + * Data structures and manipulation thereof 154 + * --------------------------------------------------------------------- */ 155 + 156 + struct dme1737_data { 157 + struct i2c_client client; 158 + struct class_device *class_dev; 159 + 160 + struct mutex update_lock; 161 + int valid; /* !=0 if following fields are valid */ 162 + unsigned long last_update; /* in jiffies */ 163 + unsigned long last_vbat; /* in jiffies */ 164 + 165 + u8 vid; 166 + u8 pwm_rr_en; 167 + u8 has_pwm; 168 + u8 has_fan; 169 + 170 + /* Register values */ 171 + u16 in[7]; 172 + u8 in_min[7]; 173 + u8 in_max[7]; 174 + s16 temp[3]; 175 + s8 temp_min[3]; 176 + s8 temp_max[3]; 177 + s8 temp_offset[3]; 178 + u8 config; 179 + u8 config2; 180 + u8 vrm; 181 + u16 fan[6]; 182 + u16 fan_min[6]; 183 + u8 fan_max[2]; 184 + u8 fan_opt[6]; 185 + u8 pwm[6]; 186 + u8 pwm_min[3]; 187 + u8 pwm_config[3]; 188 + u8 pwm_acz[3]; 189 + u8 pwm_freq[6]; 190 + u8 pwm_rr[2]; 191 + u8 zone_low[3]; 192 + u8 zone_abs[3]; 193 + u8 zone_hyst[2]; 194 + u32 alarms; 195 + }; 196 + 197 + /* Nominal voltage values */ 198 + static const int IN_NOMINAL[] = {5000, 2250, 3300, 5000, 12000, 3300, 3300}; 199 + 200 + /* Voltage input 201 + * Voltage inputs have 16 bits resolution, limit values have 8 bits 202 + * resolution. */ 203 + static inline int IN_FROM_REG(int reg, int ix, int res) 204 + { 205 + return (reg * IN_NOMINAL[ix] + (3 << (res - 3))) / (3 << (res - 2)); 206 + } 207 + 208 + static inline int IN_TO_REG(int val, int ix) 209 + { 210 + return SENSORS_LIMIT((val * 192 + IN_NOMINAL[ix] / 2) / 211 + IN_NOMINAL[ix], 0, 255); 212 + } 213 + 214 + /* Temperature input 215 + * The register values represent temperatures in 2's complement notation from 216 + * -127 degrees C to +127 degrees C. Temp inputs have 16 bits resolution, limit 217 + * values have 8 bits resolution. */ 218 + static inline int TEMP_FROM_REG(int reg, int res) 219 + { 220 + return (reg * 1000) >> (res - 8); 221 + } 222 + 223 + static inline int TEMP_TO_REG(int val) 224 + { 225 + return SENSORS_LIMIT((val < 0 ? val - 500 : val + 500) / 1000, 226 + -128, 127); 227 + } 228 + 229 + /* Temperature range */ 230 + static const int TEMP_RANGE[] = {2000, 2500, 3333, 4000, 5000, 6666, 8000, 231 + 10000, 13333, 16000, 20000, 26666, 32000, 232 + 40000, 53333, 80000}; 233 + 234 + static inline int TEMP_RANGE_FROM_REG(int reg) 235 + { 236 + return TEMP_RANGE[(reg >> 4) & 0x0f]; 237 + } 238 + 239 + static int TEMP_RANGE_TO_REG(int val, int reg) 240 + { 241 + int i; 242 + 243 + for (i = 15; i > 0; i--) { 244 + if (val > (TEMP_RANGE[i] + TEMP_RANGE[i - 1] + 1) / 2) { 245 + break; 246 + } 247 + } 248 + 249 + return (reg & 0x0f) | (i << 4); 250 + } 251 + 252 + /* Temperature hysteresis 253 + * Register layout: 254 + * reg[0] = [H1-3, H1-2, H1-1, H1-0, H2-3, H2-2, H2-1, H2-0] 255 + * reg[1] = [H3-3, H3-2, H3-1, H3-0, xxxx, xxxx, xxxx, xxxx] */ 256 + static inline int TEMP_HYST_FROM_REG(int reg, int ix) 257 + { 258 + return (((ix == 1) ? reg : reg >> 4) & 0x0f) * 1000; 259 + } 260 + 261 + static inline int TEMP_HYST_TO_REG(int val, int ix, int reg) 262 + { 263 + int hyst = SENSORS_LIMIT((val + 500) / 1000, 0, 15); 264 + 265 + return (ix == 1) ? (reg & 0xf0) | hyst : (reg & 0x0f) | (hyst << 4); 266 + } 267 + 268 + /* Fan input RPM */ 269 + static inline int FAN_FROM_REG(int reg, int tpc) 270 + { 271 + return (reg == 0 || reg == 0xffff) ? 0 : 272 + (tpc == 0) ? 90000 * 60 / reg : tpc * reg; 273 + } 274 + 275 + static inline int FAN_TO_REG(int val, int tpc) 276 + { 277 + return SENSORS_LIMIT((tpc == 0) ? 90000 * 60 / val : val / tpc, 278 + 0, 0xffff); 279 + } 280 + 281 + /* Fan TPC (tach pulse count) 282 + * Converts a register value to a TPC multiplier or returns 0 if the tachometer 283 + * is configured in legacy (non-tpc) mode */ 284 + static inline int FAN_TPC_FROM_REG(int reg) 285 + { 286 + return (reg & 0x20) ? 0 : 60 >> (reg & 0x03); 287 + } 288 + 289 + /* Fan type 290 + * The type of a fan is expressed in number of pulses-per-revolution that it 291 + * emits */ 292 + static inline int FAN_TYPE_FROM_REG(int reg) 293 + { 294 + int edge = (reg >> 1) & 0x03; 295 + 296 + return (edge > 0) ? 1 << (edge - 1) : 0; 297 + } 298 + 299 + static inline int FAN_TYPE_TO_REG(int val, int reg) 300 + { 301 + int edge = (val == 4) ? 3 : val; 302 + 303 + return (reg & 0xf9) | (edge << 1); 304 + } 305 + 306 + /* Fan max RPM */ 307 + static const int FAN_MAX[] = {0x54, 0x38, 0x2a, 0x21, 0x1c, 0x18, 0x15, 0x12, 308 + 0x11, 0x0f, 0x0e}; 309 + 310 + static int FAN_MAX_FROM_REG(int reg) 311 + { 312 + int i; 313 + 314 + for (i = 10; i > 0; i--) { 315 + if (reg == FAN_MAX[i]) { 316 + break; 317 + } 318 + } 319 + 320 + return 1000 + i * 500; 321 + } 322 + 323 + static int FAN_MAX_TO_REG(int val) 324 + { 325 + int i; 326 + 327 + for (i = 10; i > 0; i--) { 328 + if (val > (1000 + (i - 1) * 500)) { 329 + break; 330 + } 331 + } 332 + 333 + return FAN_MAX[i]; 334 + } 335 + 336 + /* PWM enable 337 + * Register to enable mapping: 338 + * 000: 2 fan on zone 1 auto 339 + * 001: 2 fan on zone 2 auto 340 + * 010: 2 fan on zone 3 auto 341 + * 011: 0 fan full on 342 + * 100: -1 fan disabled 343 + * 101: 2 fan on hottest of zones 2,3 auto 344 + * 110: 2 fan on hottest of zones 1,2,3 auto 345 + * 111: 1 fan in manual mode */ 346 + static inline int PWM_EN_FROM_REG(int reg) 347 + { 348 + static const int en[] = {2, 2, 2, 0, -1, 2, 2, 1}; 349 + 350 + return en[(reg >> 5) & 0x07]; 351 + } 352 + 353 + static inline int PWM_EN_TO_REG(int val, int reg) 354 + { 355 + int en = (val == 1) ? 7 : 3; 356 + 357 + return (reg & 0x1f) | ((en & 0x07) << 5); 358 + } 359 + 360 + /* PWM auto channels zone 361 + * Register to auto channels zone mapping (ACZ is a bitfield with bit x 362 + * corresponding to zone x+1): 363 + * 000: 001 fan on zone 1 auto 364 + * 001: 010 fan on zone 2 auto 365 + * 010: 100 fan on zone 3 auto 366 + * 011: 000 fan full on 367 + * 100: 000 fan disabled 368 + * 101: 110 fan on hottest of zones 2,3 auto 369 + * 110: 111 fan on hottest of zones 1,2,3 auto 370 + * 111: 000 fan in manual mode */ 371 + static inline int PWM_ACZ_FROM_REG(int reg) 372 + { 373 + static const int acz[] = {1, 2, 4, 0, 0, 6, 7, 0}; 374 + 375 + return acz[(reg >> 5) & 0x07]; 376 + } 377 + 378 + static inline int PWM_ACZ_TO_REG(int val, int reg) 379 + { 380 + int acz = (val == 4) ? 2 : val - 1; 381 + 382 + return (reg & 0x1f) | ((acz & 0x07) << 5); 383 + } 384 + 385 + /* PWM frequency */ 386 + static const int PWM_FREQ[] = {11, 15, 22, 29, 35, 44, 59, 88, 387 + 15000, 20000, 30000, 25000, 0, 0, 0, 0}; 388 + 389 + static inline int PWM_FREQ_FROM_REG(int reg) 390 + { 391 + return PWM_FREQ[reg & 0x0f]; 392 + } 393 + 394 + static int PWM_FREQ_TO_REG(int val, int reg) 395 + { 396 + int i; 397 + 398 + /* the first two cases are special - stupid chip design! */ 399 + if (val > 27500) { 400 + i = 10; 401 + } else if (val > 22500) { 402 + i = 11; 403 + } else { 404 + for (i = 9; i > 0; i--) { 405 + if (val > (PWM_FREQ[i] + PWM_FREQ[i - 1] + 1) / 2) { 406 + break; 407 + } 408 + } 409 + } 410 + 411 + return (reg & 0xf0) | i; 412 + } 413 + 414 + /* PWM ramp rate 415 + * Register layout: 416 + * reg[0] = [OFF3, OFF2, OFF1, RES, RR1-E, RR1-2, RR1-1, RR1-0] 417 + * reg[1] = [RR2-E, RR2-2, RR2-1, RR2-0, RR3-E, RR3-2, RR3-1, RR3-0] */ 418 + static const u8 PWM_RR[] = {206, 104, 69, 41, 26, 18, 10, 5}; 419 + 420 + static inline int PWM_RR_FROM_REG(int reg, int ix) 421 + { 422 + int rr = (ix == 1) ? reg >> 4 : reg; 423 + 424 + return (rr & 0x08) ? PWM_RR[rr & 0x07] : 0; 425 + } 426 + 427 + static int PWM_RR_TO_REG(int val, int ix, int reg) 428 + { 429 + int i; 430 + 431 + for (i = 0; i < 7; i++) { 432 + if (val > (PWM_RR[i] + PWM_RR[i + 1] + 1) / 2) { 433 + break; 434 + } 435 + } 436 + 437 + return (ix == 1) ? (reg & 0x8f) | (i << 4) : (reg & 0xf8) | i; 438 + } 439 + 440 + /* PWM ramp rate enable */ 441 + static inline int PWM_RR_EN_FROM_REG(int reg, int ix) 442 + { 443 + return PWM_RR_FROM_REG(reg, ix) ? 1 : 0; 444 + } 445 + 446 + static inline int PWM_RR_EN_TO_REG(int val, int ix, int reg) 447 + { 448 + int en = (ix == 1) ? 0x80 : 0x08; 449 + 450 + return val ? reg | en : reg & ~en; 451 + } 452 + 453 + /* PWM min/off 454 + * The PWM min/off bits are part of the PMW ramp rate register 0 (see above for 455 + * the register layout). */ 456 + static inline int PWM_OFF_FROM_REG(int reg, int ix) 457 + { 458 + return (reg >> (ix + 5)) & 0x01; 459 + } 460 + 461 + static inline int PWM_OFF_TO_REG(int val, int ix, int reg) 462 + { 463 + return (reg & ~(1 << (ix + 5))) | ((val & 0x01) << (ix + 5)); 464 + } 465 + 466 + /* --------------------------------------------------------------------- 467 + * Device I/O access 468 + * --------------------------------------------------------------------- */ 469 + 470 + static u8 dme1737_read(struct i2c_client *client, u8 reg) 471 + { 472 + s32 val = i2c_smbus_read_byte_data(client, reg); 473 + 474 + if (val < 0) { 475 + dev_warn(&client->dev, "Read from register 0x%02x failed! " 476 + "Please report to the driver maintainer.\n", reg); 477 + } 478 + 479 + return val; 480 + } 481 + 482 + static s32 dme1737_write(struct i2c_client *client, u8 reg, u8 value) 483 + { 484 + s32 res = i2c_smbus_write_byte_data(client, reg, value); 485 + 486 + if (res < 0) { 487 + dev_warn(&client->dev, "Write to register 0x%02x failed! " 488 + "Please report to the driver maintainer.\n", reg); 489 + } 490 + 491 + return res; 492 + } 493 + 494 + static struct dme1737_data *dme1737_update_device(struct device *dev) 495 + { 496 + struct i2c_client *client = to_i2c_client(dev); 497 + struct dme1737_data *data = i2c_get_clientdata(client); 498 + int ix; 499 + u8 lsb[5]; 500 + 501 + mutex_lock(&data->update_lock); 502 + 503 + /* Enable a Vbat monitoring cycle every 10 mins */ 504 + if (time_after(jiffies, data->last_vbat + 600 * HZ) || !data->valid) { 505 + dme1737_write(client, DME1737_REG_CONFIG, dme1737_read(client, 506 + DME1737_REG_CONFIG) | 0x10); 507 + data->last_vbat = jiffies; 508 + } 509 + 510 + /* Sample register contents every 1 sec */ 511 + if (time_after(jiffies, data->last_update + HZ) || !data->valid) { 512 + data->vid = dme1737_read(client, DME1737_REG_VID) & 0x3f; 513 + 514 + /* In (voltage) registers */ 515 + for (ix = 0; ix < ARRAY_SIZE(data->in); ix++) { 516 + /* Voltage inputs are stored as 16 bit values even 517 + * though they have only 12 bits resolution. This is 518 + * to make it consistent with the temp inputs. */ 519 + data->in[ix] = dme1737_read(client, 520 + DME1737_REG_IN(ix)) << 8; 521 + data->in_min[ix] = dme1737_read(client, 522 + DME1737_REG_IN_MIN(ix)); 523 + data->in_max[ix] = dme1737_read(client, 524 + DME1737_REG_IN_MAX(ix)); 525 + } 526 + 527 + /* Temp registers */ 528 + for (ix = 0; ix < ARRAY_SIZE(data->temp); ix++) { 529 + /* Temp inputs are stored as 16 bit values even 530 + * though they have only 12 bits resolution. This is 531 + * to take advantage of implicit conversions between 532 + * register values (2's complement) and temp values 533 + * (signed decimal). */ 534 + data->temp[ix] = dme1737_read(client, 535 + DME1737_REG_TEMP(ix)) << 8; 536 + data->temp_min[ix] = dme1737_read(client, 537 + DME1737_REG_TEMP_MIN(ix)); 538 + data->temp_max[ix] = dme1737_read(client, 539 + DME1737_REG_TEMP_MAX(ix)); 540 + data->temp_offset[ix] = dme1737_read(client, 541 + DME1737_REG_TEMP_OFFSET(ix)); 542 + } 543 + 544 + /* In and temp LSB registers 545 + * The LSBs are latched when the MSBs are read, so the order in 546 + * which the registers are read (MSB first, then LSB) is 547 + * important! */ 548 + for (ix = 0; ix < ARRAY_SIZE(lsb); ix++) { 549 + lsb[ix] = dme1737_read(client, 550 + DME1737_REG_IN_TEMP_LSB(ix)); 551 + } 552 + for (ix = 0; ix < ARRAY_SIZE(data->in); ix++) { 553 + data->in[ix] |= (lsb[DME1737_REG_IN_LSB[ix]] << 554 + DME1737_REG_IN_LSB_SHL[ix]) & 0xf0; 555 + } 556 + for (ix = 0; ix < ARRAY_SIZE(data->temp); ix++) { 557 + data->temp[ix] |= (lsb[DME1737_REG_TEMP_LSB[ix]] << 558 + DME1737_REG_TEMP_LSB_SHL[ix]) & 0xf0; 559 + } 560 + 561 + /* Fan registers */ 562 + for (ix = 0; ix < ARRAY_SIZE(data->fan); ix++) { 563 + /* Skip reading registers if optional fans are not 564 + * present */ 565 + if (!(data->has_fan & (1 << ix))) { 566 + continue; 567 + } 568 + data->fan[ix] = dme1737_read(client, 569 + DME1737_REG_FAN(ix)); 570 + data->fan[ix] |= dme1737_read(client, 571 + DME1737_REG_FAN(ix) + 1) << 8; 572 + data->fan_min[ix] = dme1737_read(client, 573 + DME1737_REG_FAN_MIN(ix)); 574 + data->fan_min[ix] |= dme1737_read(client, 575 + DME1737_REG_FAN_MIN(ix) + 1) << 8; 576 + data->fan_opt[ix] = dme1737_read(client, 577 + DME1737_REG_FAN_OPT(ix)); 578 + /* fan_max exists only for fan[5-6] */ 579 + if (ix > 3) { 580 + data->fan_max[ix - 4] = dme1737_read(client, 581 + DME1737_REG_FAN_MAX(ix)); 582 + } 583 + } 584 + 585 + /* PWM registers */ 586 + for (ix = 0; ix < ARRAY_SIZE(data->pwm); ix++) { 587 + /* Skip reading registers if optional PWMs are not 588 + * present */ 589 + if (!(data->has_pwm & (1 << ix))) { 590 + continue; 591 + } 592 + data->pwm[ix] = dme1737_read(client, 593 + DME1737_REG_PWM(ix)); 594 + data->pwm_freq[ix] = dme1737_read(client, 595 + DME1737_REG_PWM_FREQ(ix)); 596 + /* pwm_config and pwm_min exist only for pwm[1-3] */ 597 + if (ix < 3) { 598 + data->pwm_config[ix] = dme1737_read(client, 599 + DME1737_REG_PWM_CONFIG(ix)); 600 + data->pwm_min[ix] = dme1737_read(client, 601 + DME1737_REG_PWM_MIN(ix)); 602 + } 603 + } 604 + for (ix = 0; ix < ARRAY_SIZE(data->pwm_rr); ix++) { 605 + data->pwm_rr[ix] = dme1737_read(client, 606 + DME1737_REG_PWM_RR(ix)); 607 + } 608 + 609 + /* Thermal zone registers */ 610 + for (ix = 0; ix < ARRAY_SIZE(data->zone_low); ix++) { 611 + data->zone_low[ix] = dme1737_read(client, 612 + DME1737_REG_ZONE_LOW(ix)); 613 + data->zone_abs[ix] = dme1737_read(client, 614 + DME1737_REG_ZONE_ABS(ix)); 615 + } 616 + for (ix = 0; ix < ARRAY_SIZE(data->zone_hyst); ix++) { 617 + data->zone_hyst[ix] = dme1737_read(client, 618 + DME1737_REG_ZONE_HYST(ix)); 619 + } 620 + 621 + /* Alarm registers */ 622 + data->alarms = dme1737_read(client, 623 + DME1737_REG_ALARM1); 624 + /* Bit 7 tells us if the other alarm registers are non-zero and 625 + * therefore also need to be read */ 626 + if (data->alarms & 0x80) { 627 + data->alarms |= dme1737_read(client, 628 + DME1737_REG_ALARM2) << 8; 629 + data->alarms |= dme1737_read(client, 630 + DME1737_REG_ALARM3) << 16; 631 + } 632 + 633 + data->last_update = jiffies; 634 + data->valid = 1; 635 + } 636 + 637 + mutex_unlock(&data->update_lock); 638 + 639 + return data; 640 + } 641 + 642 + /* --------------------------------------------------------------------- 643 + * Voltage sysfs attributes 644 + * ix = [0-5] 645 + * --------------------------------------------------------------------- */ 646 + 647 + #define SYS_IN_INPUT 0 648 + #define SYS_IN_MIN 1 649 + #define SYS_IN_MAX 2 650 + #define SYS_IN_ALARM 3 651 + 652 + static ssize_t show_in(struct device *dev, struct device_attribute *attr, 653 + char *buf) 654 + { 655 + struct dme1737_data *data = dme1737_update_device(dev); 656 + struct sensor_device_attribute_2 657 + *sensor_attr_2 = to_sensor_dev_attr_2(attr); 658 + int ix = sensor_attr_2->index; 659 + int fn = sensor_attr_2->nr; 660 + int res; 661 + 662 + switch (fn) { 663 + case SYS_IN_INPUT: 664 + res = IN_FROM_REG(data->in[ix], ix, 16); 665 + break; 666 + case SYS_IN_MIN: 667 + res = IN_FROM_REG(data->in_min[ix], ix, 8); 668 + break; 669 + case SYS_IN_MAX: 670 + res = IN_FROM_REG(data->in_max[ix], ix, 8); 671 + break; 672 + case SYS_IN_ALARM: 673 + res = (data->alarms >> DME1737_BIT_ALARM_IN[ix]) & 0x01; 674 + break; 675 + default: 676 + res = 0; 677 + dev_dbg(dev, "Unknown attr fetch (%d)\n", fn); 678 + } 679 + 680 + return sprintf(buf, "%d\n", res); 681 + } 682 + 683 + static ssize_t set_in(struct device *dev, struct device_attribute *attr, 684 + const char *buf, size_t count) 685 + { 686 + struct i2c_client *client = to_i2c_client(dev); 687 + struct dme1737_data *data = i2c_get_clientdata(client); 688 + struct sensor_device_attribute_2 689 + *sensor_attr_2 = to_sensor_dev_attr_2(attr); 690 + int ix = sensor_attr_2->index; 691 + int fn = sensor_attr_2->nr; 692 + long val = simple_strtol(buf, NULL, 10); 693 + 694 + mutex_lock(&data->update_lock); 695 + switch (fn) { 696 + case SYS_IN_MIN: 697 + data->in_min[ix] = IN_TO_REG(val, ix); 698 + dme1737_write(client, DME1737_REG_IN_MIN(ix), 699 + data->in_min[ix]); 700 + break; 701 + case SYS_IN_MAX: 702 + data->in_max[ix] = IN_TO_REG(val, ix); 703 + dme1737_write(client, DME1737_REG_IN_MAX(ix), 704 + data->in_max[ix]); 705 + break; 706 + default: 707 + dev_dbg(dev, "Unknown attr fetch (%d)\n", fn); 708 + } 709 + mutex_unlock(&data->update_lock); 710 + 711 + return count; 712 + } 713 + 714 + /* --------------------------------------------------------------------- 715 + * Temperature sysfs attributes 716 + * ix = [0-2] 717 + * --------------------------------------------------------------------- */ 718 + 719 + #define SYS_TEMP_INPUT 0 720 + #define SYS_TEMP_MIN 1 721 + #define SYS_TEMP_MAX 2 722 + #define SYS_TEMP_OFFSET 3 723 + #define SYS_TEMP_ALARM 4 724 + #define SYS_TEMP_FAULT 5 725 + 726 + static ssize_t show_temp(struct device *dev, struct device_attribute *attr, 727 + char *buf) 728 + { 729 + struct dme1737_data *data = dme1737_update_device(dev); 730 + struct sensor_device_attribute_2 731 + *sensor_attr_2 = to_sensor_dev_attr_2(attr); 732 + int ix = sensor_attr_2->index; 733 + int fn = sensor_attr_2->nr; 734 + int res; 735 + 736 + switch (fn) { 737 + case SYS_TEMP_INPUT: 738 + res = TEMP_FROM_REG(data->temp[ix], 16); 739 + break; 740 + case SYS_TEMP_MIN: 741 + res = TEMP_FROM_REG(data->temp_min[ix], 8); 742 + break; 743 + case SYS_TEMP_MAX: 744 + res = TEMP_FROM_REG(data->temp_max[ix], 8); 745 + break; 746 + case SYS_TEMP_OFFSET: 747 + res = TEMP_FROM_REG(data->temp_offset[ix], 8); 748 + break; 749 + case SYS_TEMP_ALARM: 750 + res = (data->alarms >> DME1737_BIT_ALARM_TEMP[ix]) & 0x01; 751 + break; 752 + case SYS_TEMP_FAULT: 753 + res = (data->temp[ix] == 0x0800); 754 + break; 755 + default: 756 + res = 0; 757 + dev_dbg(dev, "Unknown attr fetch (%d)\n", fn); 758 + } 759 + 760 + return sprintf(buf, "%d\n", res); 761 + } 762 + 763 + static ssize_t set_temp(struct device *dev, struct device_attribute *attr, 764 + const char *buf, size_t count) 765 + { 766 + struct i2c_client *client = to_i2c_client(dev); 767 + struct dme1737_data *data = i2c_get_clientdata(client); 768 + struct sensor_device_attribute_2 769 + *sensor_attr_2 = to_sensor_dev_attr_2(attr); 770 + int ix = sensor_attr_2->index; 771 + int fn = sensor_attr_2->nr; 772 + long val = simple_strtol(buf, NULL, 10); 773 + 774 + mutex_lock(&data->update_lock); 775 + switch (fn) { 776 + case SYS_TEMP_MIN: 777 + data->temp_min[ix] = TEMP_TO_REG(val); 778 + dme1737_write(client, DME1737_REG_TEMP_MIN(ix), 779 + data->temp_min[ix]); 780 + break; 781 + case SYS_TEMP_MAX: 782 + data->temp_max[ix] = TEMP_TO_REG(val); 783 + dme1737_write(client, DME1737_REG_TEMP_MAX(ix), 784 + data->temp_max[ix]); 785 + break; 786 + case SYS_TEMP_OFFSET: 787 + data->temp_offset[ix] = TEMP_TO_REG(val); 788 + dme1737_write(client, DME1737_REG_TEMP_OFFSET(ix), 789 + data->temp_offset[ix]); 790 + break; 791 + default: 792 + dev_dbg(dev, "Unknown attr fetch (%d)\n", fn); 793 + } 794 + mutex_unlock(&data->update_lock); 795 + 796 + return count; 797 + } 798 + 799 + /* --------------------------------------------------------------------- 800 + * Zone sysfs attributes 801 + * ix = [0-2] 802 + * --------------------------------------------------------------------- */ 803 + 804 + #define SYS_ZONE_AUTO_CHANNELS_TEMP 0 805 + #define SYS_ZONE_AUTO_POINT1_TEMP_HYST 1 806 + #define SYS_ZONE_AUTO_POINT1_TEMP 2 807 + #define SYS_ZONE_AUTO_POINT2_TEMP 3 808 + #define SYS_ZONE_AUTO_POINT3_TEMP 4 809 + 810 + static ssize_t show_zone(struct device *dev, struct device_attribute *attr, 811 + char *buf) 812 + { 813 + struct dme1737_data *data = dme1737_update_device(dev); 814 + struct sensor_device_attribute_2 815 + *sensor_attr_2 = to_sensor_dev_attr_2(attr); 816 + int ix = sensor_attr_2->index; 817 + int fn = sensor_attr_2->nr; 818 + int res; 819 + 820 + switch (fn) { 821 + case SYS_ZONE_AUTO_CHANNELS_TEMP: 822 + /* check config2 for non-standard temp-to-zone mapping */ 823 + if ((ix == 1) && (data->config2 & 0x02)) { 824 + res = 4; 825 + } else { 826 + res = 1 << ix; 827 + } 828 + break; 829 + case SYS_ZONE_AUTO_POINT1_TEMP_HYST: 830 + res = TEMP_FROM_REG(data->zone_low[ix], 8) - 831 + TEMP_HYST_FROM_REG(data->zone_hyst[ix == 2], ix); 832 + break; 833 + case SYS_ZONE_AUTO_POINT1_TEMP: 834 + res = TEMP_FROM_REG(data->zone_low[ix], 8); 835 + break; 836 + case SYS_ZONE_AUTO_POINT2_TEMP: 837 + /* pwm_freq holds the temp range bits in the upper nibble */ 838 + res = TEMP_FROM_REG(data->zone_low[ix], 8) + 839 + TEMP_RANGE_FROM_REG(data->pwm_freq[ix]); 840 + break; 841 + case SYS_ZONE_AUTO_POINT3_TEMP: 842 + res = TEMP_FROM_REG(data->zone_abs[ix], 8); 843 + break; 844 + default: 845 + res = 0; 846 + dev_dbg(dev, "Unknown attr fetch (%d)\n", fn); 847 + } 848 + 849 + return sprintf(buf, "%d\n", res); 850 + } 851 + 852 + static ssize_t set_zone(struct device *dev, struct device_attribute *attr, 853 + const char *buf, size_t count) 854 + { 855 + struct i2c_client *client = to_i2c_client(dev); 856 + struct dme1737_data *data = i2c_get_clientdata(client); 857 + struct sensor_device_attribute_2 858 + *sensor_attr_2 = to_sensor_dev_attr_2(attr); 859 + int ix = sensor_attr_2->index; 860 + int fn = sensor_attr_2->nr; 861 + long val = simple_strtol(buf, NULL, 10); 862 + 863 + mutex_lock(&data->update_lock); 864 + switch (fn) { 865 + case SYS_ZONE_AUTO_POINT1_TEMP_HYST: 866 + /* Refresh the cache */ 867 + data->zone_low[ix] = dme1737_read(client, 868 + DME1737_REG_ZONE_LOW(ix)); 869 + /* Modify the temp hyst value */ 870 + data->zone_hyst[ix == 2] = TEMP_HYST_TO_REG( 871 + TEMP_FROM_REG(data->zone_low[ix], 8) - 872 + val, ix, dme1737_read(client, 873 + DME1737_REG_ZONE_HYST(ix == 2))); 874 + dme1737_write(client, DME1737_REG_ZONE_HYST(ix == 2), 875 + data->zone_hyst[ix == 2]); 876 + break; 877 + case SYS_ZONE_AUTO_POINT1_TEMP: 878 + data->zone_low[ix] = TEMP_TO_REG(val); 879 + dme1737_write(client, DME1737_REG_ZONE_LOW(ix), 880 + data->zone_low[ix]); 881 + break; 882 + case SYS_ZONE_AUTO_POINT2_TEMP: 883 + /* Refresh the cache */ 884 + data->zone_low[ix] = dme1737_read(client, 885 + DME1737_REG_ZONE_LOW(ix)); 886 + /* Modify the temp range value (which is stored in the upper 887 + * nibble of the pwm_freq register) */ 888 + data->pwm_freq[ix] = TEMP_RANGE_TO_REG(val - 889 + TEMP_FROM_REG(data->zone_low[ix], 8), 890 + dme1737_read(client, 891 + DME1737_REG_PWM_FREQ(ix))); 892 + dme1737_write(client, DME1737_REG_PWM_FREQ(ix), 893 + data->pwm_freq[ix]); 894 + break; 895 + case SYS_ZONE_AUTO_POINT3_TEMP: 896 + data->zone_abs[ix] = TEMP_TO_REG(val); 897 + dme1737_write(client, DME1737_REG_ZONE_ABS(ix), 898 + data->zone_abs[ix]); 899 + break; 900 + default: 901 + dev_dbg(dev, "Unknown attr fetch (%d)\n", fn); 902 + } 903 + mutex_unlock(&data->update_lock); 904 + 905 + return count; 906 + } 907 + 908 + /* --------------------------------------------------------------------- 909 + * Fan sysfs attributes 910 + * ix = [0-5] 911 + * --------------------------------------------------------------------- */ 912 + 913 + #define SYS_FAN_INPUT 0 914 + #define SYS_FAN_MIN 1 915 + #define SYS_FAN_MAX 2 916 + #define SYS_FAN_ALARM 3 917 + #define SYS_FAN_TYPE 4 918 + 919 + static ssize_t show_fan(struct device *dev, struct device_attribute *attr, 920 + char *buf) 921 + { 922 + struct dme1737_data *data = dme1737_update_device(dev); 923 + struct sensor_device_attribute_2 924 + *sensor_attr_2 = to_sensor_dev_attr_2(attr); 925 + int ix = sensor_attr_2->index; 926 + int fn = sensor_attr_2->nr; 927 + int res; 928 + 929 + switch (fn) { 930 + case SYS_FAN_INPUT: 931 + res = FAN_FROM_REG(data->fan[ix], 932 + ix < 4 ? 0 : 933 + FAN_TPC_FROM_REG(data->fan_opt[ix])); 934 + break; 935 + case SYS_FAN_MIN: 936 + res = FAN_FROM_REG(data->fan_min[ix], 937 + ix < 4 ? 0 : 938 + FAN_TPC_FROM_REG(data->fan_opt[ix])); 939 + break; 940 + case SYS_FAN_MAX: 941 + /* only valid for fan[5-6] */ 942 + res = FAN_MAX_FROM_REG(data->fan_max[ix - 4]); 943 + break; 944 + case SYS_FAN_ALARM: 945 + res = (data->alarms >> DME1737_BIT_ALARM_FAN[ix]) & 0x01; 946 + break; 947 + case SYS_FAN_TYPE: 948 + /* only valid for fan[1-4] */ 949 + res = FAN_TYPE_FROM_REG(data->fan_opt[ix]); 950 + break; 951 + default: 952 + res = 0; 953 + dev_dbg(dev, "Unknown attr fetch (%d)\n", fn); 954 + } 955 + 956 + return sprintf(buf, "%d\n", res); 957 + } 958 + 959 + static ssize_t set_fan(struct device *dev, struct device_attribute *attr, 960 + const char *buf, size_t count) 961 + { 962 + struct i2c_client *client = to_i2c_client(dev); 963 + struct dme1737_data *data = i2c_get_clientdata(client); 964 + struct sensor_device_attribute_2 965 + *sensor_attr_2 = to_sensor_dev_attr_2(attr); 966 + int ix = sensor_attr_2->index; 967 + int fn = sensor_attr_2->nr; 968 + long val = simple_strtol(buf, NULL, 10); 969 + 970 + mutex_lock(&data->update_lock); 971 + switch (fn) { 972 + case SYS_FAN_MIN: 973 + if (ix < 4) { 974 + data->fan_min[ix] = FAN_TO_REG(val, 0); 975 + } else { 976 + /* Refresh the cache */ 977 + data->fan_opt[ix] = dme1737_read(client, 978 + DME1737_REG_FAN_OPT(ix)); 979 + /* Modify the fan min value */ 980 + data->fan_min[ix] = FAN_TO_REG(val, 981 + FAN_TPC_FROM_REG(data->fan_opt[ix])); 982 + } 983 + dme1737_write(client, DME1737_REG_FAN_MIN(ix), 984 + data->fan_min[ix] & 0xff); 985 + dme1737_write(client, DME1737_REG_FAN_MIN(ix) + 1, 986 + data->fan_min[ix] >> 8); 987 + break; 988 + case SYS_FAN_MAX: 989 + /* Only valid for fan[5-6] */ 990 + data->fan_max[ix - 4] = FAN_MAX_TO_REG(val); 991 + dme1737_write(client, DME1737_REG_FAN_MAX(ix), 992 + data->fan_max[ix - 4]); 993 + break; 994 + case SYS_FAN_TYPE: 995 + /* Only valid for fan[1-4] */ 996 + if (!(val == 1 || val == 2 || val == 4)) { 997 + count = -EINVAL; 998 + dev_warn(&client->dev, "Fan type value %ld not " 999 + "supported. Choose one of 1, 2, or 4.\n", 1000 + val); 1001 + goto exit; 1002 + } 1003 + data->fan_opt[ix] = FAN_TYPE_TO_REG(val, dme1737_read(client, 1004 + DME1737_REG_FAN_OPT(ix))); 1005 + dme1737_write(client, DME1737_REG_FAN_OPT(ix), 1006 + data->fan_opt[ix]); 1007 + break; 1008 + default: 1009 + dev_dbg(dev, "Unknown attr fetch (%d)\n", fn); 1010 + } 1011 + exit: 1012 + mutex_unlock(&data->update_lock); 1013 + 1014 + return count; 1015 + } 1016 + 1017 + /* --------------------------------------------------------------------- 1018 + * PWM sysfs attributes 1019 + * ix = [0-4] 1020 + * --------------------------------------------------------------------- */ 1021 + 1022 + #define SYS_PWM 0 1023 + #define SYS_PWM_FREQ 1 1024 + #define SYS_PWM_ENABLE 2 1025 + #define SYS_PWM_RAMP_RATE 3 1026 + #define SYS_PWM_AUTO_CHANNELS_ZONE 4 1027 + #define SYS_PWM_AUTO_PWM_MIN 5 1028 + #define SYS_PWM_AUTO_POINT1_PWM 6 1029 + #define SYS_PWM_AUTO_POINT2_PWM 7 1030 + 1031 + static ssize_t show_pwm(struct device *dev, struct device_attribute *attr, 1032 + char *buf) 1033 + { 1034 + struct dme1737_data *data = dme1737_update_device(dev); 1035 + struct sensor_device_attribute_2 1036 + *sensor_attr_2 = to_sensor_dev_attr_2(attr); 1037 + int ix = sensor_attr_2->index; 1038 + int fn = sensor_attr_2->nr; 1039 + int res; 1040 + 1041 + switch (fn) { 1042 + case SYS_PWM: 1043 + if (PWM_EN_FROM_REG(data->pwm_config[ix]) == 0) { 1044 + res = 255; 1045 + } else { 1046 + res = data->pwm[ix]; 1047 + } 1048 + break; 1049 + case SYS_PWM_FREQ: 1050 + res = PWM_FREQ_FROM_REG(data->pwm_freq[ix]); 1051 + break; 1052 + case SYS_PWM_ENABLE: 1053 + if (ix > 3) { 1054 + res = 1; /* pwm[5-6] hard-wired to manual mode */ 1055 + } else { 1056 + res = PWM_EN_FROM_REG(data->pwm_config[ix]); 1057 + } 1058 + break; 1059 + case SYS_PWM_RAMP_RATE: 1060 + /* Only valid for pwm[1-3] */ 1061 + res = PWM_RR_FROM_REG(data->pwm_rr[ix > 0], ix); 1062 + break; 1063 + case SYS_PWM_AUTO_CHANNELS_ZONE: 1064 + /* Only valid for pwm[1-3] */ 1065 + if (PWM_EN_FROM_REG(data->pwm_config[ix]) == 2) { 1066 + res = PWM_ACZ_FROM_REG(data->pwm_config[ix]); 1067 + } else { 1068 + res = data->pwm_acz[ix]; 1069 + } 1070 + break; 1071 + case SYS_PWM_AUTO_PWM_MIN: 1072 + /* Only valid for pwm[1-3] */ 1073 + if (PWM_OFF_FROM_REG(data->pwm_rr[0], ix)) { 1074 + res = data->pwm_min[ix]; 1075 + } else { 1076 + res = 0; 1077 + } 1078 + break; 1079 + case SYS_PWM_AUTO_POINT1_PWM: 1080 + /* Only valid for pwm[1-3] */ 1081 + res = data->pwm_min[ix]; 1082 + break; 1083 + case SYS_PWM_AUTO_POINT2_PWM: 1084 + /* Only valid for pwm[1-3] */ 1085 + res = 255; /* hard-wired */ 1086 + break; 1087 + default: 1088 + res = 0; 1089 + dev_dbg(dev, "Unknown attr fetch (%d)\n", fn); 1090 + } 1091 + 1092 + return sprintf(buf, "%d\n", res); 1093 + } 1094 + 1095 + static struct attribute *dme1737_attr_pwm[]; 1096 + static void dme1737_chmod_file(struct i2c_client*, struct attribute*, mode_t); 1097 + 1098 + static ssize_t set_pwm(struct device *dev, struct device_attribute *attr, 1099 + const char *buf, size_t count) 1100 + { 1101 + struct i2c_client *client = to_i2c_client(dev); 1102 + struct dme1737_data *data = i2c_get_clientdata(client); 1103 + struct sensor_device_attribute_2 1104 + *sensor_attr_2 = to_sensor_dev_attr_2(attr); 1105 + int ix = sensor_attr_2->index; 1106 + int fn = sensor_attr_2->nr; 1107 + long val = simple_strtol(buf, NULL, 10); 1108 + 1109 + mutex_lock(&data->update_lock); 1110 + switch (fn) { 1111 + case SYS_PWM: 1112 + data->pwm[ix] = SENSORS_LIMIT(val, 0, 255); 1113 + dme1737_write(client, DME1737_REG_PWM(ix), data->pwm[ix]); 1114 + break; 1115 + case SYS_PWM_FREQ: 1116 + data->pwm_freq[ix] = PWM_FREQ_TO_REG(val, dme1737_read(client, 1117 + DME1737_REG_PWM_FREQ(ix))); 1118 + dme1737_write(client, DME1737_REG_PWM_FREQ(ix), 1119 + data->pwm_freq[ix]); 1120 + break; 1121 + case SYS_PWM_ENABLE: 1122 + /* Only valid for pwm[1-3] */ 1123 + if (val < 0 || val > 2) { 1124 + count = -EINVAL; 1125 + dev_warn(&client->dev, "PWM enable %ld not " 1126 + "supported. Choose one of 0, 1, or 2.\n", 1127 + val); 1128 + goto exit; 1129 + } 1130 + /* Refresh the cache */ 1131 + data->pwm_config[ix] = dme1737_read(client, 1132 + DME1737_REG_PWM_CONFIG(ix)); 1133 + if (val == PWM_EN_FROM_REG(data->pwm_config[ix])) { 1134 + /* Bail out if no change */ 1135 + goto exit; 1136 + } 1137 + /* Do some housekeeping if we are currently in auto mode */ 1138 + if (PWM_EN_FROM_REG(data->pwm_config[ix]) == 2) { 1139 + /* Save the current zone channel assignment */ 1140 + data->pwm_acz[ix] = PWM_ACZ_FROM_REG( 1141 + data->pwm_config[ix]); 1142 + /* Save the current ramp rate state and disable it */ 1143 + data->pwm_rr[ix > 0] = dme1737_read(client, 1144 + DME1737_REG_PWM_RR(ix > 0)); 1145 + data->pwm_rr_en &= ~(1 << ix); 1146 + if (PWM_RR_EN_FROM_REG(data->pwm_rr[ix > 0], ix)) { 1147 + data->pwm_rr_en |= (1 << ix); 1148 + data->pwm_rr[ix > 0] = PWM_RR_EN_TO_REG(0, ix, 1149 + data->pwm_rr[ix > 0]); 1150 + dme1737_write(client, 1151 + DME1737_REG_PWM_RR(ix > 0), 1152 + data->pwm_rr[ix > 0]); 1153 + } 1154 + } 1155 + /* Set the new PWM mode */ 1156 + switch (val) { 1157 + case 0: 1158 + /* Change permissions of pwm[ix] to read-only */ 1159 + dme1737_chmod_file(client, dme1737_attr_pwm[ix], 1160 + S_IRUGO); 1161 + /* Turn fan fully on */ 1162 + data->pwm_config[ix] = PWM_EN_TO_REG(0, 1163 + data->pwm_config[ix]); 1164 + dme1737_write(client, DME1737_REG_PWM_CONFIG(ix), 1165 + data->pwm_config[ix]); 1166 + break; 1167 + case 1: 1168 + /* Turn on manual mode */ 1169 + data->pwm_config[ix] = PWM_EN_TO_REG(1, 1170 + data->pwm_config[ix]); 1171 + dme1737_write(client, DME1737_REG_PWM_CONFIG(ix), 1172 + data->pwm_config[ix]); 1173 + /* Change permissions of pwm[ix] to read-writeable */ 1174 + dme1737_chmod_file(client, dme1737_attr_pwm[ix], 1175 + S_IRUGO | S_IWUSR); 1176 + break; 1177 + case 2: 1178 + /* Change permissions of pwm[ix] to read-only */ 1179 + dme1737_chmod_file(client, dme1737_attr_pwm[ix], 1180 + S_IRUGO); 1181 + /* Turn on auto mode using the saved zone channel 1182 + * assignment */ 1183 + data->pwm_config[ix] = PWM_ACZ_TO_REG( 1184 + data->pwm_acz[ix], 1185 + data->pwm_config[ix]); 1186 + dme1737_write(client, DME1737_REG_PWM_CONFIG(ix), 1187 + data->pwm_config[ix]); 1188 + /* Enable PWM ramp rate if previously enabled */ 1189 + if (data->pwm_rr_en & (1 << ix)) { 1190 + data->pwm_rr[ix > 0] = PWM_RR_EN_TO_REG(1, ix, 1191 + dme1737_read(client, 1192 + DME1737_REG_PWM_RR(ix > 0))); 1193 + dme1737_write(client, 1194 + DME1737_REG_PWM_RR(ix > 0), 1195 + data->pwm_rr[ix > 0]); 1196 + } 1197 + break; 1198 + } 1199 + break; 1200 + case SYS_PWM_RAMP_RATE: 1201 + /* Only valid for pwm[1-3] */ 1202 + /* Refresh the cache */ 1203 + data->pwm_config[ix] = dme1737_read(client, 1204 + DME1737_REG_PWM_CONFIG(ix)); 1205 + data->pwm_rr[ix > 0] = dme1737_read(client, 1206 + DME1737_REG_PWM_RR(ix > 0)); 1207 + /* Set the ramp rate value */ 1208 + if (val > 0) { 1209 + data->pwm_rr[ix > 0] = PWM_RR_TO_REG(val, ix, 1210 + data->pwm_rr[ix > 0]); 1211 + } 1212 + /* Enable/disable the feature only if the associated PWM 1213 + * output is in automatic mode. */ 1214 + if (PWM_EN_FROM_REG(data->pwm_config[ix]) == 2) { 1215 + data->pwm_rr[ix > 0] = PWM_RR_EN_TO_REG(val > 0, ix, 1216 + data->pwm_rr[ix > 0]); 1217 + } 1218 + dme1737_write(client, DME1737_REG_PWM_RR(ix > 0), 1219 + data->pwm_rr[ix > 0]); 1220 + break; 1221 + case SYS_PWM_AUTO_CHANNELS_ZONE: 1222 + /* Only valid for pwm[1-3] */ 1223 + if (!(val == 1 || val == 2 || val == 4 || 1224 + val == 6 || val == 7)) { 1225 + count = -EINVAL; 1226 + dev_warn(&client->dev, "PWM auto channels zone %ld " 1227 + "not supported. Choose one of 1, 2, 4, 6, " 1228 + "or 7.\n", val); 1229 + goto exit; 1230 + } 1231 + /* Refresh the cache */ 1232 + data->pwm_config[ix] = dme1737_read(client, 1233 + DME1737_REG_PWM_CONFIG(ix)); 1234 + if (PWM_EN_FROM_REG(data->pwm_config[ix]) == 2) { 1235 + /* PWM is already in auto mode so update the temp 1236 + * channel assignment */ 1237 + data->pwm_config[ix] = PWM_ACZ_TO_REG(val, 1238 + data->pwm_config[ix]); 1239 + dme1737_write(client, DME1737_REG_PWM_CONFIG(ix), 1240 + data->pwm_config[ix]); 1241 + } else { 1242 + /* PWM is not in auto mode so we save the temp 1243 + * channel assignment for later use */ 1244 + data->pwm_acz[ix] = val; 1245 + } 1246 + break; 1247 + case SYS_PWM_AUTO_PWM_MIN: 1248 + /* Only valid for pwm[1-3] */ 1249 + /* Refresh the cache */ 1250 + data->pwm_min[ix] = dme1737_read(client, 1251 + DME1737_REG_PWM_MIN(ix)); 1252 + /* There are only 2 values supported for the auto_pwm_min 1253 + * value: 0 or auto_point1_pwm. So if the temperature drops 1254 + * below the auto_point1_temp_hyst value, the fan either turns 1255 + * off or runs at auto_point1_pwm duty-cycle. */ 1256 + if (val > ((data->pwm_min[ix] + 1) / 2)) { 1257 + data->pwm_rr[0] = PWM_OFF_TO_REG(1, ix, 1258 + dme1737_read(client, 1259 + DME1737_REG_PWM_RR(0))); 1260 + 1261 + } else { 1262 + data->pwm_rr[0] = PWM_OFF_TO_REG(0, ix, 1263 + dme1737_read(client, 1264 + DME1737_REG_PWM_RR(0))); 1265 + 1266 + } 1267 + dme1737_write(client, DME1737_REG_PWM_RR(0), 1268 + data->pwm_rr[0]); 1269 + break; 1270 + case SYS_PWM_AUTO_POINT1_PWM: 1271 + /* Only valid for pwm[1-3] */ 1272 + data->pwm_min[ix] = SENSORS_LIMIT(val, 0, 255); 1273 + dme1737_write(client, DME1737_REG_PWM_MIN(ix), 1274 + data->pwm_min[ix]); 1275 + break; 1276 + default: 1277 + dev_dbg(dev, "Unknown attr fetch (%d)\n", fn); 1278 + } 1279 + exit: 1280 + mutex_unlock(&data->update_lock); 1281 + 1282 + return count; 1283 + } 1284 + 1285 + /* --------------------------------------------------------------------- 1286 + * Miscellaneous sysfs attributes 1287 + * --------------------------------------------------------------------- */ 1288 + 1289 + static ssize_t show_vrm(struct device *dev, struct device_attribute *attr, 1290 + char *buf) 1291 + { 1292 + struct i2c_client *client = to_i2c_client(dev); 1293 + struct dme1737_data *data = i2c_get_clientdata(client); 1294 + 1295 + return sprintf(buf, "%d\n", data->vrm); 1296 + } 1297 + 1298 + static ssize_t set_vrm(struct device *dev, struct device_attribute *attr, 1299 + const char *buf, size_t count) 1300 + { 1301 + struct i2c_client *client = to_i2c_client(dev); 1302 + struct dme1737_data *data = i2c_get_clientdata(client); 1303 + long val = simple_strtol(buf, NULL, 10); 1304 + 1305 + data->vrm = val; 1306 + return count; 1307 + } 1308 + 1309 + static ssize_t show_vid(struct device *dev, struct device_attribute *attr, 1310 + char *buf) 1311 + { 1312 + struct dme1737_data *data = dme1737_update_device(dev); 1313 + 1314 + return sprintf(buf, "%d\n", vid_from_reg(data->vid, data->vrm)); 1315 + } 1316 + 1317 + /* --------------------------------------------------------------------- 1318 + * Sysfs device attribute defines and structs 1319 + * --------------------------------------------------------------------- */ 1320 + 1321 + /* Voltages 0-6 */ 1322 + 1323 + #define SENSOR_DEVICE_ATTR_IN(ix) \ 1324 + static SENSOR_DEVICE_ATTR_2(in##ix##_input, S_IRUGO, \ 1325 + show_in, NULL, SYS_IN_INPUT, ix); \ 1326 + static SENSOR_DEVICE_ATTR_2(in##ix##_min, S_IRUGO | S_IWUSR, \ 1327 + show_in, set_in, SYS_IN_MIN, ix); \ 1328 + static SENSOR_DEVICE_ATTR_2(in##ix##_max, S_IRUGO | S_IWUSR, \ 1329 + show_in, set_in, SYS_IN_MAX, ix); \ 1330 + static SENSOR_DEVICE_ATTR_2(in##ix##_alarm, S_IRUGO, \ 1331 + show_in, NULL, SYS_IN_ALARM, ix) 1332 + 1333 + SENSOR_DEVICE_ATTR_IN(0); 1334 + SENSOR_DEVICE_ATTR_IN(1); 1335 + SENSOR_DEVICE_ATTR_IN(2); 1336 + SENSOR_DEVICE_ATTR_IN(3); 1337 + SENSOR_DEVICE_ATTR_IN(4); 1338 + SENSOR_DEVICE_ATTR_IN(5); 1339 + SENSOR_DEVICE_ATTR_IN(6); 1340 + 1341 + /* Temperatures 1-3 */ 1342 + 1343 + #define SENSOR_DEVICE_ATTR_TEMP(ix) \ 1344 + static SENSOR_DEVICE_ATTR_2(temp##ix##_input, S_IRUGO, \ 1345 + show_temp, NULL, SYS_TEMP_INPUT, ix-1); \ 1346 + static SENSOR_DEVICE_ATTR_2(temp##ix##_min, S_IRUGO | S_IWUSR, \ 1347 + show_temp, set_temp, SYS_TEMP_MIN, ix-1); \ 1348 + static SENSOR_DEVICE_ATTR_2(temp##ix##_max, S_IRUGO | S_IWUSR, \ 1349 + show_temp, set_temp, SYS_TEMP_MAX, ix-1); \ 1350 + static SENSOR_DEVICE_ATTR_2(temp##ix##_offset, S_IRUGO, \ 1351 + show_temp, set_temp, SYS_TEMP_OFFSET, ix-1); \ 1352 + static SENSOR_DEVICE_ATTR_2(temp##ix##_alarm, S_IRUGO, \ 1353 + show_temp, NULL, SYS_TEMP_ALARM, ix-1); \ 1354 + static SENSOR_DEVICE_ATTR_2(temp##ix##_fault, S_IRUGO, \ 1355 + show_temp, NULL, SYS_TEMP_FAULT, ix-1) 1356 + 1357 + SENSOR_DEVICE_ATTR_TEMP(1); 1358 + SENSOR_DEVICE_ATTR_TEMP(2); 1359 + SENSOR_DEVICE_ATTR_TEMP(3); 1360 + 1361 + /* Zones 1-3 */ 1362 + 1363 + #define SENSOR_DEVICE_ATTR_ZONE(ix) \ 1364 + static SENSOR_DEVICE_ATTR_2(zone##ix##_auto_channels_temp, S_IRUGO, \ 1365 + show_zone, NULL, SYS_ZONE_AUTO_CHANNELS_TEMP, ix-1); \ 1366 + static SENSOR_DEVICE_ATTR_2(zone##ix##_auto_point1_temp_hyst, S_IRUGO, \ 1367 + show_zone, set_zone, SYS_ZONE_AUTO_POINT1_TEMP_HYST, ix-1); \ 1368 + static SENSOR_DEVICE_ATTR_2(zone##ix##_auto_point1_temp, S_IRUGO, \ 1369 + show_zone, set_zone, SYS_ZONE_AUTO_POINT1_TEMP, ix-1); \ 1370 + static SENSOR_DEVICE_ATTR_2(zone##ix##_auto_point2_temp, S_IRUGO, \ 1371 + show_zone, set_zone, SYS_ZONE_AUTO_POINT2_TEMP, ix-1); \ 1372 + static SENSOR_DEVICE_ATTR_2(zone##ix##_auto_point3_temp, S_IRUGO, \ 1373 + show_zone, set_zone, SYS_ZONE_AUTO_POINT3_TEMP, ix-1) 1374 + 1375 + SENSOR_DEVICE_ATTR_ZONE(1); 1376 + SENSOR_DEVICE_ATTR_ZONE(2); 1377 + SENSOR_DEVICE_ATTR_ZONE(3); 1378 + 1379 + /* Fans 1-4 */ 1380 + 1381 + #define SENSOR_DEVICE_ATTR_FAN_1TO4(ix) \ 1382 + static SENSOR_DEVICE_ATTR_2(fan##ix##_input, S_IRUGO, \ 1383 + show_fan, NULL, SYS_FAN_INPUT, ix-1); \ 1384 + static SENSOR_DEVICE_ATTR_2(fan##ix##_min, S_IRUGO | S_IWUSR, \ 1385 + show_fan, set_fan, SYS_FAN_MIN, ix-1); \ 1386 + static SENSOR_DEVICE_ATTR_2(fan##ix##_alarm, S_IRUGO, \ 1387 + show_fan, NULL, SYS_FAN_ALARM, ix-1); \ 1388 + static SENSOR_DEVICE_ATTR_2(fan##ix##_type, S_IRUGO | S_IWUSR, \ 1389 + show_fan, set_fan, SYS_FAN_TYPE, ix-1) 1390 + 1391 + SENSOR_DEVICE_ATTR_FAN_1TO4(1); 1392 + SENSOR_DEVICE_ATTR_FAN_1TO4(2); 1393 + SENSOR_DEVICE_ATTR_FAN_1TO4(3); 1394 + SENSOR_DEVICE_ATTR_FAN_1TO4(4); 1395 + 1396 + /* Fans 5-6 */ 1397 + 1398 + #define SENSOR_DEVICE_ATTR_FAN_5TO6(ix) \ 1399 + static SENSOR_DEVICE_ATTR_2(fan##ix##_input, S_IRUGO, \ 1400 + show_fan, NULL, SYS_FAN_INPUT, ix-1); \ 1401 + static SENSOR_DEVICE_ATTR_2(fan##ix##_min, S_IRUGO | S_IWUSR, \ 1402 + show_fan, set_fan, SYS_FAN_MIN, ix-1); \ 1403 + static SENSOR_DEVICE_ATTR_2(fan##ix##_alarm, S_IRUGO, \ 1404 + show_fan, NULL, SYS_FAN_ALARM, ix-1); \ 1405 + static SENSOR_DEVICE_ATTR_2(fan##ix##_max, S_IRUGO | S_IWUSR, \ 1406 + show_fan, set_fan, SYS_FAN_MAX, ix-1) 1407 + 1408 + SENSOR_DEVICE_ATTR_FAN_5TO6(5); 1409 + SENSOR_DEVICE_ATTR_FAN_5TO6(6); 1410 + 1411 + /* PWMs 1-3 */ 1412 + 1413 + #define SENSOR_DEVICE_ATTR_PWM_1TO3(ix) \ 1414 + static SENSOR_DEVICE_ATTR_2(pwm##ix, S_IRUGO, \ 1415 + show_pwm, set_pwm, SYS_PWM, ix-1); \ 1416 + static SENSOR_DEVICE_ATTR_2(pwm##ix##_freq, S_IRUGO, \ 1417 + show_pwm, set_pwm, SYS_PWM_FREQ, ix-1); \ 1418 + static SENSOR_DEVICE_ATTR_2(pwm##ix##_enable, S_IRUGO, \ 1419 + show_pwm, set_pwm, SYS_PWM_ENABLE, ix-1); \ 1420 + static SENSOR_DEVICE_ATTR_2(pwm##ix##_ramp_rate, S_IRUGO, \ 1421 + show_pwm, set_pwm, SYS_PWM_RAMP_RATE, ix-1); \ 1422 + static SENSOR_DEVICE_ATTR_2(pwm##ix##_auto_channels_zone, S_IRUGO, \ 1423 + show_pwm, set_pwm, SYS_PWM_AUTO_CHANNELS_ZONE, ix-1); \ 1424 + static SENSOR_DEVICE_ATTR_2(pwm##ix##_auto_pwm_min, S_IRUGO, \ 1425 + show_pwm, set_pwm, SYS_PWM_AUTO_PWM_MIN, ix-1); \ 1426 + static SENSOR_DEVICE_ATTR_2(pwm##ix##_auto_point1_pwm, S_IRUGO, \ 1427 + show_pwm, set_pwm, SYS_PWM_AUTO_POINT1_PWM, ix-1); \ 1428 + static SENSOR_DEVICE_ATTR_2(pwm##ix##_auto_point2_pwm, S_IRUGO, \ 1429 + show_pwm, NULL, SYS_PWM_AUTO_POINT2_PWM, ix-1) 1430 + 1431 + SENSOR_DEVICE_ATTR_PWM_1TO3(1); 1432 + SENSOR_DEVICE_ATTR_PWM_1TO3(2); 1433 + SENSOR_DEVICE_ATTR_PWM_1TO3(3); 1434 + 1435 + /* PWMs 5-6 */ 1436 + 1437 + #define SENSOR_DEVICE_ATTR_PWM_5TO6(ix) \ 1438 + static SENSOR_DEVICE_ATTR_2(pwm##ix, S_IRUGO | S_IWUSR, \ 1439 + show_pwm, set_pwm, SYS_PWM, ix-1); \ 1440 + static SENSOR_DEVICE_ATTR_2(pwm##ix##_freq, S_IRUGO | S_IWUSR, \ 1441 + show_pwm, set_pwm, SYS_PWM_FREQ, ix-1); \ 1442 + static SENSOR_DEVICE_ATTR_2(pwm##ix##_enable, S_IRUGO, \ 1443 + show_pwm, NULL, SYS_PWM_ENABLE, ix-1) 1444 + 1445 + SENSOR_DEVICE_ATTR_PWM_5TO6(5); 1446 + SENSOR_DEVICE_ATTR_PWM_5TO6(6); 1447 + 1448 + /* Misc */ 1449 + 1450 + static DEVICE_ATTR(vrm, S_IRUGO | S_IWUSR, show_vrm, set_vrm); 1451 + static DEVICE_ATTR(cpu0_vid, S_IRUGO, show_vid, NULL); 1452 + 1453 + #define SENSOR_DEV_ATTR_IN(ix) \ 1454 + &sensor_dev_attr_in##ix##_input.dev_attr.attr, \ 1455 + &sensor_dev_attr_in##ix##_min.dev_attr.attr, \ 1456 + &sensor_dev_attr_in##ix##_max.dev_attr.attr, \ 1457 + &sensor_dev_attr_in##ix##_alarm.dev_attr.attr 1458 + 1459 + /* These attributes are read-writeable only if the chip is *not* locked */ 1460 + #define SENSOR_DEV_ATTR_TEMP_LOCK(ix) \ 1461 + &sensor_dev_attr_temp##ix##_offset.dev_attr.attr 1462 + 1463 + #define SENSOR_DEV_ATTR_TEMP(ix) \ 1464 + SENSOR_DEV_ATTR_TEMP_LOCK(ix), \ 1465 + &sensor_dev_attr_temp##ix##_input.dev_attr.attr, \ 1466 + &sensor_dev_attr_temp##ix##_min.dev_attr.attr, \ 1467 + &sensor_dev_attr_temp##ix##_max.dev_attr.attr, \ 1468 + &sensor_dev_attr_temp##ix##_alarm.dev_attr.attr, \ 1469 + &sensor_dev_attr_temp##ix##_fault.dev_attr.attr 1470 + 1471 + /* These attributes are read-writeable only if the chip is *not* locked */ 1472 + #define SENSOR_DEV_ATTR_ZONE_LOCK(ix) \ 1473 + &sensor_dev_attr_zone##ix##_auto_point1_temp_hyst.dev_attr.attr, \ 1474 + &sensor_dev_attr_zone##ix##_auto_point1_temp.dev_attr.attr, \ 1475 + &sensor_dev_attr_zone##ix##_auto_point2_temp.dev_attr.attr, \ 1476 + &sensor_dev_attr_zone##ix##_auto_point3_temp.dev_attr.attr 1477 + 1478 + #define SENSOR_DEV_ATTR_ZONE(ix) \ 1479 + SENSOR_DEV_ATTR_ZONE_LOCK(ix), \ 1480 + &sensor_dev_attr_zone##ix##_auto_channels_temp.dev_attr.attr 1481 + 1482 + #define SENSOR_DEV_ATTR_FAN_1TO4(ix) \ 1483 + &sensor_dev_attr_fan##ix##_input.dev_attr.attr, \ 1484 + &sensor_dev_attr_fan##ix##_min.dev_attr.attr, \ 1485 + &sensor_dev_attr_fan##ix##_alarm.dev_attr.attr, \ 1486 + &sensor_dev_attr_fan##ix##_type.dev_attr.attr 1487 + 1488 + #define SENSOR_DEV_ATTR_FAN_5TO6(ix) \ 1489 + &sensor_dev_attr_fan##ix##_input.dev_attr.attr, \ 1490 + &sensor_dev_attr_fan##ix##_min.dev_attr.attr, \ 1491 + &sensor_dev_attr_fan##ix##_alarm.dev_attr.attr, \ 1492 + &sensor_dev_attr_fan##ix##_max.dev_attr.attr 1493 + 1494 + /* These attributes are read-writeable only if the chip is *not* locked */ 1495 + #define SENSOR_DEV_ATTR_PWM_1TO3_LOCK(ix) \ 1496 + &sensor_dev_attr_pwm##ix##_freq.dev_attr.attr, \ 1497 + &sensor_dev_attr_pwm##ix##_enable.dev_attr.attr, \ 1498 + &sensor_dev_attr_pwm##ix##_ramp_rate.dev_attr.attr, \ 1499 + &sensor_dev_attr_pwm##ix##_auto_channels_zone.dev_attr.attr, \ 1500 + &sensor_dev_attr_pwm##ix##_auto_pwm_min.dev_attr.attr, \ 1501 + &sensor_dev_attr_pwm##ix##_auto_point1_pwm.dev_attr.attr 1502 + 1503 + #define SENSOR_DEV_ATTR_PWM_1TO3(ix) \ 1504 + SENSOR_DEV_ATTR_PWM_1TO3_LOCK(ix), \ 1505 + &sensor_dev_attr_pwm##ix.dev_attr.attr, \ 1506 + &sensor_dev_attr_pwm##ix##_auto_point2_pwm.dev_attr.attr 1507 + 1508 + /* These attributes are read-writeable only if the chip is *not* locked */ 1509 + #define SENSOR_DEV_ATTR_PWM_5TO6_LOCK(ix) \ 1510 + &sensor_dev_attr_pwm##ix.dev_attr.attr, \ 1511 + &sensor_dev_attr_pwm##ix##_freq.dev_attr.attr 1512 + 1513 + #define SENSOR_DEV_ATTR_PWM_5TO6(ix) \ 1514 + SENSOR_DEV_ATTR_PWM_5TO6_LOCK(ix), \ 1515 + &sensor_dev_attr_pwm##ix##_enable.dev_attr.attr 1516 + 1517 + /* This struct holds all the attributes that are always present and need to be 1518 + * created unconditionally. The attributes that need modification of their 1519 + * permissions are created read-only and write permissions are added or removed 1520 + * on the fly when required */ 1521 + static struct attribute *dme1737_attr[] ={ 1522 + /* Voltages */ 1523 + SENSOR_DEV_ATTR_IN(0), 1524 + SENSOR_DEV_ATTR_IN(1), 1525 + SENSOR_DEV_ATTR_IN(2), 1526 + SENSOR_DEV_ATTR_IN(3), 1527 + SENSOR_DEV_ATTR_IN(4), 1528 + SENSOR_DEV_ATTR_IN(5), 1529 + SENSOR_DEV_ATTR_IN(6), 1530 + /* Temperatures */ 1531 + SENSOR_DEV_ATTR_TEMP(1), 1532 + SENSOR_DEV_ATTR_TEMP(2), 1533 + SENSOR_DEV_ATTR_TEMP(3), 1534 + /* Zones */ 1535 + SENSOR_DEV_ATTR_ZONE(1), 1536 + SENSOR_DEV_ATTR_ZONE(2), 1537 + SENSOR_DEV_ATTR_ZONE(3), 1538 + /* Misc */ 1539 + &dev_attr_vrm.attr, 1540 + &dev_attr_cpu0_vid.attr, 1541 + NULL 1542 + }; 1543 + 1544 + static const struct attribute_group dme1737_group = { 1545 + .attrs = dme1737_attr, 1546 + }; 1547 + 1548 + /* The following structs hold the PWM attributes, some of which are optional. 1549 + * Their creation depends on the chip configuration which is determined during 1550 + * module load. */ 1551 + static struct attribute *dme1737_attr_pwm1[] = { 1552 + SENSOR_DEV_ATTR_PWM_1TO3(1), 1553 + NULL 1554 + }; 1555 + static struct attribute *dme1737_attr_pwm2[] = { 1556 + SENSOR_DEV_ATTR_PWM_1TO3(2), 1557 + NULL 1558 + }; 1559 + static struct attribute *dme1737_attr_pwm3[] = { 1560 + SENSOR_DEV_ATTR_PWM_1TO3(3), 1561 + NULL 1562 + }; 1563 + static struct attribute *dme1737_attr_pwm5[] = { 1564 + SENSOR_DEV_ATTR_PWM_5TO6(5), 1565 + NULL 1566 + }; 1567 + static struct attribute *dme1737_attr_pwm6[] = { 1568 + SENSOR_DEV_ATTR_PWM_5TO6(6), 1569 + NULL 1570 + }; 1571 + 1572 + static const struct attribute_group dme1737_pwm_group[] = { 1573 + { .attrs = dme1737_attr_pwm1 }, 1574 + { .attrs = dme1737_attr_pwm2 }, 1575 + { .attrs = dme1737_attr_pwm3 }, 1576 + { .attrs = NULL }, 1577 + { .attrs = dme1737_attr_pwm5 }, 1578 + { .attrs = dme1737_attr_pwm6 }, 1579 + }; 1580 + 1581 + /* The following structs hold the fan attributes, some of which are optional. 1582 + * Their creation depends on the chip configuration which is determined during 1583 + * module load. */ 1584 + static struct attribute *dme1737_attr_fan1[] = { 1585 + SENSOR_DEV_ATTR_FAN_1TO4(1), 1586 + NULL 1587 + }; 1588 + static struct attribute *dme1737_attr_fan2[] = { 1589 + SENSOR_DEV_ATTR_FAN_1TO4(2), 1590 + NULL 1591 + }; 1592 + static struct attribute *dme1737_attr_fan3[] = { 1593 + SENSOR_DEV_ATTR_FAN_1TO4(3), 1594 + NULL 1595 + }; 1596 + static struct attribute *dme1737_attr_fan4[] = { 1597 + SENSOR_DEV_ATTR_FAN_1TO4(4), 1598 + NULL 1599 + }; 1600 + static struct attribute *dme1737_attr_fan5[] = { 1601 + SENSOR_DEV_ATTR_FAN_5TO6(5), 1602 + NULL 1603 + }; 1604 + static struct attribute *dme1737_attr_fan6[] = { 1605 + SENSOR_DEV_ATTR_FAN_5TO6(6), 1606 + NULL 1607 + }; 1608 + 1609 + static const struct attribute_group dme1737_fan_group[] = { 1610 + { .attrs = dme1737_attr_fan1 }, 1611 + { .attrs = dme1737_attr_fan2 }, 1612 + { .attrs = dme1737_attr_fan3 }, 1613 + { .attrs = dme1737_attr_fan4 }, 1614 + { .attrs = dme1737_attr_fan5 }, 1615 + { .attrs = dme1737_attr_fan6 }, 1616 + }; 1617 + 1618 + /* The permissions of all of the following attributes are changed to read- 1619 + * writeable if the chip is *not* locked. Otherwise they stay read-only. */ 1620 + static struct attribute *dme1737_attr_lock[] = { 1621 + /* Temperatures */ 1622 + SENSOR_DEV_ATTR_TEMP_LOCK(1), 1623 + SENSOR_DEV_ATTR_TEMP_LOCK(2), 1624 + SENSOR_DEV_ATTR_TEMP_LOCK(3), 1625 + /* Zones */ 1626 + SENSOR_DEV_ATTR_ZONE_LOCK(1), 1627 + SENSOR_DEV_ATTR_ZONE_LOCK(2), 1628 + SENSOR_DEV_ATTR_ZONE_LOCK(3), 1629 + NULL 1630 + }; 1631 + 1632 + static const struct attribute_group dme1737_lock_group = { 1633 + .attrs = dme1737_attr_lock, 1634 + }; 1635 + 1636 + /* The permissions of the following PWM attributes are changed to read- 1637 + * writeable if the chip is *not* locked and the respective PWM is available. 1638 + * Otherwise they stay read-only. */ 1639 + static struct attribute *dme1737_attr_pwm1_lock[] = { 1640 + SENSOR_DEV_ATTR_PWM_1TO3_LOCK(1), 1641 + NULL 1642 + }; 1643 + static struct attribute *dme1737_attr_pwm2_lock[] = { 1644 + SENSOR_DEV_ATTR_PWM_1TO3_LOCK(2), 1645 + NULL 1646 + }; 1647 + static struct attribute *dme1737_attr_pwm3_lock[] = { 1648 + SENSOR_DEV_ATTR_PWM_1TO3_LOCK(3), 1649 + NULL 1650 + }; 1651 + static struct attribute *dme1737_attr_pwm5_lock[] = { 1652 + SENSOR_DEV_ATTR_PWM_5TO6_LOCK(5), 1653 + NULL 1654 + }; 1655 + static struct attribute *dme1737_attr_pwm6_lock[] = { 1656 + SENSOR_DEV_ATTR_PWM_5TO6_LOCK(6), 1657 + NULL 1658 + }; 1659 + 1660 + static const struct attribute_group dme1737_pwm_lock_group[] = { 1661 + { .attrs = dme1737_attr_pwm1_lock }, 1662 + { .attrs = dme1737_attr_pwm2_lock }, 1663 + { .attrs = dme1737_attr_pwm3_lock }, 1664 + { .attrs = NULL }, 1665 + { .attrs = dme1737_attr_pwm5_lock }, 1666 + { .attrs = dme1737_attr_pwm6_lock }, 1667 + }; 1668 + 1669 + /* Pwm[1-3] are read-writeable if the associated pwm is in manual mode and the 1670 + * chip is not locked. Otherwise they are read-only. */ 1671 + static struct attribute *dme1737_attr_pwm[] = { 1672 + &sensor_dev_attr_pwm1.dev_attr.attr, 1673 + &sensor_dev_attr_pwm2.dev_attr.attr, 1674 + &sensor_dev_attr_pwm3.dev_attr.attr, 1675 + }; 1676 + 1677 + /* --------------------------------------------------------------------- 1678 + * Super-IO functions 1679 + * --------------------------------------------------------------------- */ 1680 + 1681 + static inline int dme1737_sio_inb(int sio_cip, int reg) 1682 + { 1683 + outb(reg, sio_cip); 1684 + return inb(sio_cip + 1); 1685 + } 1686 + 1687 + static inline void dme1737_sio_outb(int sio_cip, int reg, int val) 1688 + { 1689 + outb(reg, sio_cip); 1690 + outb(val, sio_cip + 1); 1691 + } 1692 + 1693 + static int dme1737_sio_get_features(int sio_cip, struct i2c_client *client) 1694 + { 1695 + struct dme1737_data *data = i2c_get_clientdata(client); 1696 + int err = 0, reg; 1697 + u16 addr; 1698 + 1699 + /* Enter configuration mode */ 1700 + outb(0x55, sio_cip); 1701 + 1702 + /* Check device ID 1703 + * The DME1737 can return either 0x78 or 0x77 as its device ID. */ 1704 + reg = dme1737_sio_inb(sio_cip, 0x20); 1705 + if (!(reg == 0x77 || reg == 0x78)) { 1706 + err = -ENODEV; 1707 + goto exit; 1708 + } 1709 + 1710 + /* Select logical device A (runtime registers) */ 1711 + dme1737_sio_outb(sio_cip, 0x07, 0x0a); 1712 + 1713 + /* Get the base address of the runtime registers */ 1714 + if (!(addr = (dme1737_sio_inb(sio_cip, 0x60) << 8) | 1715 + dme1737_sio_inb(sio_cip, 0x61))) { 1716 + err = -ENODEV; 1717 + goto exit; 1718 + } 1719 + 1720 + /* Read the runtime registers to determine which optional features 1721 + * are enabled and available. Bits [3:2] of registers 0x43-0x46 are set 1722 + * to '10' if the respective feature is enabled. */ 1723 + if ((inb(addr + 0x43) & 0x0c) == 0x08) { /* fan6 */ 1724 + data->has_fan |= (1 << 5); 1725 + } 1726 + if ((inb(addr + 0x44) & 0x0c) == 0x08) { /* pwm6 */ 1727 + data->has_pwm |= (1 << 5); 1728 + } 1729 + if ((inb(addr + 0x45) & 0x0c) == 0x08) { /* fan5 */ 1730 + data->has_fan |= (1 << 4); 1731 + } 1732 + if ((inb(addr + 0x46) & 0x0c) == 0x08) { /* pwm5 */ 1733 + data->has_pwm |= (1 << 4); 1734 + } 1735 + 1736 + exit: 1737 + /* Exit configuration mode */ 1738 + outb(0xaa, sio_cip); 1739 + 1740 + return err; 1741 + } 1742 + 1743 + /* --------------------------------------------------------------------- 1744 + * Device detection, registration and initialization 1745 + * --------------------------------------------------------------------- */ 1746 + 1747 + static struct i2c_driver dme1737_driver; 1748 + 1749 + static void dme1737_chmod_file(struct i2c_client *client, 1750 + struct attribute *attr, mode_t mode) 1751 + { 1752 + if (sysfs_chmod_file(&client->dev.kobj, attr, mode)) { 1753 + dev_warn(&client->dev, "Failed to change permissions of %s.\n", 1754 + attr->name); 1755 + } 1756 + } 1757 + 1758 + static void dme1737_chmod_group(struct i2c_client *client, 1759 + const struct attribute_group *group, 1760 + mode_t mode) 1761 + { 1762 + struct attribute **attr; 1763 + 1764 + for (attr = group->attrs; *attr; attr++) { 1765 + dme1737_chmod_file(client, *attr, mode); 1766 + } 1767 + } 1768 + 1769 + static int dme1737_init_client(struct i2c_client *client) 1770 + { 1771 + struct dme1737_data *data = i2c_get_clientdata(client); 1772 + int ix; 1773 + u8 reg; 1774 + 1775 + data->config = dme1737_read(client, DME1737_REG_CONFIG); 1776 + /* Inform if part is not monitoring/started */ 1777 + if (!(data->config & 0x01)) { 1778 + if (!force_start) { 1779 + dev_err(&client->dev, "Device is not monitoring. " 1780 + "Use the force_start load parameter to " 1781 + "override.\n"); 1782 + return -EFAULT; 1783 + } 1784 + 1785 + /* Force monitoring */ 1786 + data->config |= 0x01; 1787 + dme1737_write(client, DME1737_REG_CONFIG, data->config); 1788 + } 1789 + /* Inform if part is not ready */ 1790 + if (!(data->config & 0x04)) { 1791 + dev_err(&client->dev, "Device is not ready.\n"); 1792 + return -EFAULT; 1793 + } 1794 + 1795 + data->config2 = dme1737_read(client, DME1737_REG_CONFIG2); 1796 + /* Check if optional fan3 input is enabled */ 1797 + if (data->config2 & 0x04) { 1798 + data->has_fan |= (1 << 2); 1799 + } 1800 + 1801 + /* Fan4 and pwm3 are only available if the client's I2C address 1802 + * is the default 0x2e. Otherwise the I/Os associated with these 1803 + * functions are used for addr enable/select. */ 1804 + if (client->addr == 0x2e) { 1805 + data->has_fan |= (1 << 3); 1806 + data->has_pwm |= (1 << 2); 1807 + } 1808 + 1809 + /* Determine if the optional fan[5-6] and/or pwm[5-6] are enabled. 1810 + * For this, we need to query the runtime registers through the 1811 + * Super-IO LPC interface. Try both config ports 0x2e and 0x4e. */ 1812 + if (dme1737_sio_get_features(0x2e, client) && 1813 + dme1737_sio_get_features(0x4e, client)) { 1814 + dev_warn(&client->dev, "Failed to query Super-IO for optional " 1815 + "features.\n"); 1816 + } 1817 + 1818 + /* Fan1, fan2, pwm1, and pwm2 are always present */ 1819 + data->has_fan |= 0x03; 1820 + data->has_pwm |= 0x03; 1821 + 1822 + dev_info(&client->dev, "Optional features: pwm3=%s, pwm5=%s, pwm6=%s, " 1823 + "fan3=%s, fan4=%s, fan5=%s, fan6=%s.\n", 1824 + (data->has_pwm & (1 << 2)) ? "yes" : "no", 1825 + (data->has_pwm & (1 << 4)) ? "yes" : "no", 1826 + (data->has_pwm & (1 << 5)) ? "yes" : "no", 1827 + (data->has_fan & (1 << 2)) ? "yes" : "no", 1828 + (data->has_fan & (1 << 3)) ? "yes" : "no", 1829 + (data->has_fan & (1 << 4)) ? "yes" : "no", 1830 + (data->has_fan & (1 << 5)) ? "yes" : "no"); 1831 + 1832 + reg = dme1737_read(client, DME1737_REG_TACH_PWM); 1833 + /* Inform if fan-to-pwm mapping differs from the default */ 1834 + if (reg != 0xa4) { 1835 + dev_warn(&client->dev, "Non-standard fan to pwm mapping: " 1836 + "fan1->pwm%d, fan2->pwm%d, fan3->pwm%d, " 1837 + "fan4->pwm%d. Please report to the driver " 1838 + "maintainer.\n", 1839 + (reg & 0x03) + 1, ((reg >> 2) & 0x03) + 1, 1840 + ((reg >> 4) & 0x03) + 1, ((reg >> 6) & 0x03) + 1); 1841 + } 1842 + 1843 + /* Switch pwm[1-3] to manual mode if they are currently disabled and 1844 + * set the duty-cycles to 0% (which is identical to the PWMs being 1845 + * disabled). */ 1846 + if (!(data->config & 0x02)) { 1847 + for (ix = 0; ix < 3; ix++) { 1848 + data->pwm_config[ix] = dme1737_read(client, 1849 + DME1737_REG_PWM_CONFIG(ix)); 1850 + if ((data->has_pwm & (1 << ix)) && 1851 + (PWM_EN_FROM_REG(data->pwm_config[ix]) == -1)) { 1852 + dev_info(&client->dev, "Switching pwm%d to " 1853 + "manual mode.\n", ix + 1); 1854 + data->pwm_config[ix] = PWM_EN_TO_REG(1, 1855 + data->pwm_config[ix]); 1856 + dme1737_write(client, DME1737_REG_PWM(ix), 0); 1857 + dme1737_write(client, 1858 + DME1737_REG_PWM_CONFIG(ix), 1859 + data->pwm_config[ix]); 1860 + } 1861 + } 1862 + } 1863 + 1864 + /* Initialize the default PWM auto channels zone (acz) assignments */ 1865 + data->pwm_acz[0] = 1; /* pwm1 -> zone1 */ 1866 + data->pwm_acz[1] = 2; /* pwm2 -> zone2 */ 1867 + data->pwm_acz[2] = 4; /* pwm3 -> zone3 */ 1868 + 1869 + /* Set VRM */ 1870 + data->vrm = vid_which_vrm(); 1871 + 1872 + return 0; 1873 + } 1874 + 1875 + static int dme1737_detect(struct i2c_adapter *adapter, int address, 1876 + int kind) 1877 + { 1878 + u8 company, verstep = 0; 1879 + struct i2c_client *client; 1880 + struct dme1737_data *data; 1881 + int ix, err = 0; 1882 + const char *name; 1883 + 1884 + if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) { 1885 + goto exit; 1886 + } 1887 + 1888 + if (!(data = kzalloc(sizeof(struct dme1737_data), GFP_KERNEL))) { 1889 + err = -ENOMEM; 1890 + goto exit; 1891 + } 1892 + 1893 + client = &data->client; 1894 + i2c_set_clientdata(client, data); 1895 + client->addr = address; 1896 + client->adapter = adapter; 1897 + client->driver = &dme1737_driver; 1898 + 1899 + /* A negative kind means that the driver was loaded with no force 1900 + * parameter (default), so we must identify the chip. */ 1901 + if (kind < 0) { 1902 + company = dme1737_read(client, DME1737_REG_COMPANY); 1903 + verstep = dme1737_read(client, DME1737_REG_VERSTEP); 1904 + 1905 + if (!((company == DME1737_COMPANY_SMSC) && 1906 + ((verstep & DME1737_VERSTEP_MASK) == DME1737_VERSTEP))) { 1907 + err = -ENODEV; 1908 + goto exit_kfree; 1909 + } 1910 + } 1911 + 1912 + kind = dme1737; 1913 + name = "dme1737"; 1914 + 1915 + /* Fill in the remaining client fields and put it into the global 1916 + * list */ 1917 + strlcpy(client->name, name, I2C_NAME_SIZE); 1918 + mutex_init(&data->update_lock); 1919 + 1920 + /* Tell the I2C layer a new client has arrived */ 1921 + if ((err = i2c_attach_client(client))) { 1922 + goto exit_kfree; 1923 + } 1924 + 1925 + /* Initialize the DME1737 chip */ 1926 + if ((err = dme1737_init_client(client))) { 1927 + goto exit_detach; 1928 + } 1929 + 1930 + /* Create standard sysfs attributes */ 1931 + if ((err = sysfs_create_group(&client->dev.kobj, &dme1737_group))) { 1932 + goto exit_detach; 1933 + } 1934 + 1935 + /* Create fan sysfs attributes */ 1936 + for (ix = 0; ix < ARRAY_SIZE(dme1737_fan_group); ix++) { 1937 + if (data->has_fan & (1 << ix)) { 1938 + if ((err = sysfs_create_group(&client->dev.kobj, 1939 + &dme1737_fan_group[ix]))) { 1940 + goto exit_remove; 1941 + } 1942 + } 1943 + } 1944 + 1945 + /* Create PWM sysfs attributes */ 1946 + for (ix = 0; ix < ARRAY_SIZE(dme1737_pwm_group); ix++) { 1947 + if (data->has_pwm & (1 << ix)) { 1948 + if ((err = sysfs_create_group(&client->dev.kobj, 1949 + &dme1737_pwm_group[ix]))) { 1950 + goto exit_remove; 1951 + } 1952 + } 1953 + } 1954 + 1955 + /* Inform if the device is locked. Otherwise change the permissions of 1956 + * selected attributes from read-only to read-writeable. */ 1957 + if (data->config & 0x02) { 1958 + dev_info(&client->dev, "Device is locked. Some attributes " 1959 + "will be read-only.\n"); 1960 + } else { 1961 + /* Change permissions of standard attributes */ 1962 + dme1737_chmod_group(client, &dme1737_lock_group, 1963 + S_IRUGO | S_IWUSR); 1964 + 1965 + /* Change permissions of PWM attributes */ 1966 + for (ix = 0; ix < ARRAY_SIZE(dme1737_pwm_lock_group); ix++) { 1967 + if (data->has_pwm & (1 << ix)) { 1968 + dme1737_chmod_group(client, 1969 + &dme1737_pwm_lock_group[ix], 1970 + S_IRUGO | S_IWUSR); 1971 + } 1972 + } 1973 + 1974 + /* Change permissions of pwm[1-3] if in manual mode */ 1975 + for (ix = 0; ix < 3; ix++) { 1976 + if ((data->has_pwm & (1 << ix)) && 1977 + (PWM_EN_FROM_REG(data->pwm_config[ix]) == 1)) { 1978 + dme1737_chmod_file(client, 1979 + dme1737_attr_pwm[ix], 1980 + S_IRUGO | S_IWUSR); 1981 + } 1982 + } 1983 + } 1984 + 1985 + /* Register device */ 1986 + data->class_dev = hwmon_device_register(&client->dev); 1987 + if (IS_ERR(data->class_dev)) { 1988 + err = PTR_ERR(data->class_dev); 1989 + goto exit_remove; 1990 + } 1991 + 1992 + dev_info(&adapter->dev, "Found a DME1737 chip at 0x%02x " 1993 + "(rev 0x%02x)\n", client->addr, verstep); 1994 + 1995 + return 0; 1996 + 1997 + exit_remove: 1998 + for (ix = 0; ix < ARRAY_SIZE(dme1737_fan_group); ix++) { 1999 + if (data->has_fan & (1 << ix)) { 2000 + sysfs_remove_group(&client->dev.kobj, 2001 + &dme1737_fan_group[ix]); 2002 + } 2003 + } 2004 + for (ix = 0; ix < ARRAY_SIZE(dme1737_pwm_group); ix++) { 2005 + if (data->has_pwm & (1 << ix)) { 2006 + sysfs_remove_group(&client->dev.kobj, 2007 + &dme1737_pwm_group[ix]); 2008 + } 2009 + } 2010 + sysfs_remove_group(&client->dev.kobj, &dme1737_group); 2011 + exit_detach: 2012 + i2c_detach_client(client); 2013 + exit_kfree: 2014 + kfree(data); 2015 + exit: 2016 + return err; 2017 + } 2018 + 2019 + static int dme1737_attach_adapter(struct i2c_adapter *adapter) 2020 + { 2021 + if (!(adapter->class & I2C_CLASS_HWMON)) { 2022 + return 0; 2023 + } 2024 + 2025 + return i2c_probe(adapter, &addr_data, dme1737_detect); 2026 + } 2027 + 2028 + static int dme1737_detach_client(struct i2c_client *client) 2029 + { 2030 + struct dme1737_data *data = i2c_get_clientdata(client); 2031 + int ix, err; 2032 + 2033 + hwmon_device_unregister(data->class_dev); 2034 + 2035 + for (ix = 0; ix < ARRAY_SIZE(dme1737_fan_group); ix++) { 2036 + if (data->has_fan & (1 << ix)) { 2037 + sysfs_remove_group(&client->dev.kobj, 2038 + &dme1737_fan_group[ix]); 2039 + } 2040 + } 2041 + for (ix = 0; ix < ARRAY_SIZE(dme1737_pwm_group); ix++) { 2042 + if (data->has_pwm & (1 << ix)) { 2043 + sysfs_remove_group(&client->dev.kobj, 2044 + &dme1737_pwm_group[ix]); 2045 + } 2046 + } 2047 + sysfs_remove_group(&client->dev.kobj, &dme1737_group); 2048 + 2049 + if ((err = i2c_detach_client(client))) { 2050 + return err; 2051 + } 2052 + 2053 + kfree(data); 2054 + return 0; 2055 + } 2056 + 2057 + static struct i2c_driver dme1737_driver = { 2058 + .driver = { 2059 + .name = "dme1737", 2060 + }, 2061 + .attach_adapter = dme1737_attach_adapter, 2062 + .detach_client = dme1737_detach_client, 2063 + }; 2064 + 2065 + static int __init dme1737_init(void) 2066 + { 2067 + return i2c_add_driver(&dme1737_driver); 2068 + } 2069 + 2070 + static void __exit dme1737_exit(void) 2071 + { 2072 + i2c_del_driver(&dme1737_driver); 2073 + } 2074 + 2075 + MODULE_AUTHOR("Juerg Haefliger <juergh@gmail.com>"); 2076 + MODULE_DESCRIPTION("DME1737 sensors"); 2077 + MODULE_LICENSE("GPL"); 2078 + 2079 + module_init(dme1737_init); 2080 + module_exit(dme1737_exit);
+77 -82
drivers/hwmon/ds1621.c
··· 27 #include <linux/jiffies.h> 28 #include <linux/i2c.h> 29 #include <linux/hwmon.h> 30 #include <linux/err.h> 31 #include <linux/mutex.h> 32 #include <linux/sysfs.h> ··· 53 #define DS1621_REG_CONFIG_DONE 0x80 54 55 /* The DS1621 registers */ 56 - #define DS1621_REG_TEMP 0xAA /* word, RO */ 57 - #define DS1621_REG_TEMP_MIN 0xA2 /* word, RW */ 58 - #define DS1621_REG_TEMP_MAX 0xA1 /* word, RW */ 59 #define DS1621_REG_CONF 0xAC /* byte, RW */ 60 #define DS1621_COM_START 0xEE /* no data */ 61 #define DS1621_COM_STOP 0x22 /* no data */ ··· 66 #define DS1621_ALARM_TEMP_HIGH 0x40 67 #define DS1621_ALARM_TEMP_LOW 0x20 68 69 - /* Conversions. Rounding and limit checking is only done on the TO_REG 70 - variants. Note that you should be a bit careful with which arguments 71 - these macros are called: arguments may be evaluated more than once. 72 - Fixing this is just not worth it. */ 73 #define ALARMS_FROM_REG(val) ((val) & \ 74 (DS1621_ALARM_TEMP_HIGH | DS1621_ALARM_TEMP_LOW)) 75 ··· 78 char valid; /* !=0 if following fields are valid */ 79 unsigned long last_updated; /* In jiffies */ 80 81 - u16 temp, temp_min, temp_max; /* Register values, word */ 82 u8 conf; /* Register encoding, combined */ 83 }; 84 ··· 101 102 /* All registers are word-sized, except for the configuration register. 103 DS1621 uses a high-byte first convention, which is exactly opposite to 104 - the usual practice. */ 105 static int ds1621_read_value(struct i2c_client *client, u8 reg) 106 { 107 if (reg == DS1621_REG_CONF) ··· 110 return swab16(i2c_smbus_read_word_data(client, reg)); 111 } 112 113 - /* All registers are word-sized, except for the configuration register. 114 - DS1621 uses a high-byte first convention, which is exactly opposite to 115 - the usual practice. */ 116 static int ds1621_write_value(struct i2c_client *client, u8 reg, u16 value) 117 { 118 if (reg == DS1621_REG_CONF) ··· 136 i2c_smbus_write_byte(client, DS1621_COM_START); 137 } 138 139 - #define show(value) \ 140 - static ssize_t show_##value(struct device *dev, struct device_attribute *attr, char *buf) \ 141 - { \ 142 - struct ds1621_data *data = ds1621_update_client(dev); \ 143 - return sprintf(buf, "%d\n", LM75_TEMP_FROM_REG(data->value)); \ 144 } 145 146 - show(temp); 147 - show(temp_min); 148 - show(temp_max); 149 150 - #define set_temp(suffix, value, reg) \ 151 - static ssize_t set_temp_##suffix(struct device *dev, struct device_attribute *attr, const char *buf, \ 152 - size_t count) \ 153 - { \ 154 - struct i2c_client *client = to_i2c_client(dev); \ 155 - struct ds1621_data *data = ds1621_update_client(dev); \ 156 - u16 val = LM75_TEMP_TO_REG(simple_strtoul(buf, NULL, 10)); \ 157 - \ 158 - mutex_lock(&data->update_lock); \ 159 - data->value = val; \ 160 - ds1621_write_value(client, reg, data->value); \ 161 - mutex_unlock(&data->update_lock); \ 162 - return count; \ 163 } 164 165 - set_temp(min, temp_min, DS1621_REG_TEMP_MIN); 166 - set_temp(max, temp_max, DS1621_REG_TEMP_MAX); 167 - 168 - static ssize_t show_alarms(struct device *dev, struct device_attribute *attr, char *buf) 169 { 170 struct ds1621_data *data = ds1621_update_client(dev); 171 return sprintf(buf, "%d\n", ALARMS_FROM_REG(data->conf)); 172 } 173 174 static DEVICE_ATTR(alarms, S_IRUGO, show_alarms, NULL); 175 - static DEVICE_ATTR(temp1_input, S_IRUGO , show_temp, NULL); 176 - static DEVICE_ATTR(temp1_min, S_IWUSR | S_IRUGO , show_temp_min, set_temp_min); 177 - static DEVICE_ATTR(temp1_max, S_IWUSR | S_IRUGO, show_temp_max, set_temp_max); 178 179 static struct attribute *ds1621_attributes[] = { 180 - &dev_attr_temp1_input.attr, 181 - &dev_attr_temp1_min.attr, 182 - &dev_attr_temp1_max.attr, 183 &dev_attr_alarms.attr, 184 NULL 185 }; ··· 212 int kind) 213 { 214 int conf, temp; 215 - struct i2c_client *new_client; 216 struct ds1621_data *data; 217 - int err = 0; 218 219 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA 220 | I2C_FUNC_SMBUS_WORD_DATA ··· 229 goto exit; 230 } 231 232 - new_client = &data->client; 233 - i2c_set_clientdata(new_client, data); 234 - new_client->addr = address; 235 - new_client->adapter = adapter; 236 - new_client->driver = &ds1621_driver; 237 - new_client->flags = 0; 238 - 239 240 /* Now, we do the remaining detection. It is lousy. */ 241 if (kind < 0) { 242 /* The NVB bit should be low if no EEPROM write has been 243 requested during the latest 10ms, which is highly 244 improbable in our case. */ 245 - conf = ds1621_read_value(new_client, DS1621_REG_CONF); 246 if (conf & DS1621_REG_CONFIG_NVB) 247 goto exit_free; 248 /* The 7 lowest bits of a temperature should always be 0. */ 249 - temp = ds1621_read_value(new_client, DS1621_REG_TEMP); 250 - if (temp & 0x007f) 251 - goto exit_free; 252 - temp = ds1621_read_value(new_client, DS1621_REG_TEMP_MIN); 253 - if (temp & 0x007f) 254 - goto exit_free; 255 - temp = ds1621_read_value(new_client, DS1621_REG_TEMP_MAX); 256 - if (temp & 0x007f) 257 - goto exit_free; 258 } 259 260 - /* Determine the chip type - only one kind supported! */ 261 - if (kind <= 0) 262 - kind = ds1621; 263 - 264 /* Fill in remaining client fields and put it into the global list */ 265 - strlcpy(new_client->name, "ds1621", I2C_NAME_SIZE); 266 - data->valid = 0; 267 mutex_init(&data->update_lock); 268 269 /* Tell the I2C layer a new client has arrived */ 270 - if ((err = i2c_attach_client(new_client))) 271 goto exit_free; 272 273 /* Initialize the DS1621 chip */ 274 - ds1621_init_client(new_client); 275 276 /* Register sysfs hooks */ 277 - if ((err = sysfs_create_group(&new_client->dev.kobj, &ds1621_group))) 278 goto exit_detach; 279 280 - data->class_dev = hwmon_device_register(&new_client->dev); 281 if (IS_ERR(data->class_dev)) { 282 err = PTR_ERR(data->class_dev); 283 goto exit_remove_files; ··· 275 return 0; 276 277 exit_remove_files: 278 - sysfs_remove_group(&new_client->dev.kobj, &ds1621_group); 279 exit_detach: 280 - i2c_detach_client(new_client); 281 exit_free: 282 kfree(data); 283 exit: ··· 311 312 if (time_after(jiffies, data->last_updated + HZ + HZ / 2) 313 || !data->valid) { 314 315 dev_dbg(&client->dev, "Starting ds1621 update\n"); 316 317 data->conf = ds1621_read_value(client, DS1621_REG_CONF); 318 319 - data->temp = ds1621_read_value(client, DS1621_REG_TEMP); 320 - 321 - data->temp_min = ds1621_read_value(client, 322 - DS1621_REG_TEMP_MIN); 323 - data->temp_max = ds1621_read_value(client, 324 - DS1621_REG_TEMP_MAX); 325 326 /* reset alarms if necessary */ 327 new_conf = data->conf; 328 - if (data->temp > data->temp_min) 329 new_conf &= ~DS1621_ALARM_TEMP_LOW; 330 - if (data->temp < data->temp_max) 331 new_conf &= ~DS1621_ALARM_TEMP_HIGH; 332 if (data->conf != new_conf) 333 ds1621_write_value(client, DS1621_REG_CONF,
··· 27 #include <linux/jiffies.h> 28 #include <linux/i2c.h> 29 #include <linux/hwmon.h> 30 + #include <linux/hwmon-sysfs.h> 31 #include <linux/err.h> 32 #include <linux/mutex.h> 33 #include <linux/sysfs.h> ··· 52 #define DS1621_REG_CONFIG_DONE 0x80 53 54 /* The DS1621 registers */ 55 + static const u8 DS1621_REG_TEMP[3] = { 56 + 0xAA, /* input, word, RO */ 57 + 0xA2, /* min, word, RW */ 58 + 0xA1, /* max, word, RW */ 59 + }; 60 #define DS1621_REG_CONF 0xAC /* byte, RW */ 61 #define DS1621_COM_START 0xEE /* no data */ 62 #define DS1621_COM_STOP 0x22 /* no data */ ··· 63 #define DS1621_ALARM_TEMP_HIGH 0x40 64 #define DS1621_ALARM_TEMP_LOW 0x20 65 66 + /* Conversions */ 67 #define ALARMS_FROM_REG(val) ((val) & \ 68 (DS1621_ALARM_TEMP_HIGH | DS1621_ALARM_TEMP_LOW)) 69 ··· 78 char valid; /* !=0 if following fields are valid */ 79 unsigned long last_updated; /* In jiffies */ 80 81 + u16 temp[3]; /* Register values, word */ 82 u8 conf; /* Register encoding, combined */ 83 }; 84 ··· 101 102 /* All registers are word-sized, except for the configuration register. 103 DS1621 uses a high-byte first convention, which is exactly opposite to 104 + the SMBus standard. */ 105 static int ds1621_read_value(struct i2c_client *client, u8 reg) 106 { 107 if (reg == DS1621_REG_CONF) ··· 110 return swab16(i2c_smbus_read_word_data(client, reg)); 111 } 112 113 static int ds1621_write_value(struct i2c_client *client, u8 reg, u16 value) 114 { 115 if (reg == DS1621_REG_CONF) ··· 139 i2c_smbus_write_byte(client, DS1621_COM_START); 140 } 141 142 + static ssize_t show_temp(struct device *dev, struct device_attribute *da, 143 + char *buf) 144 + { 145 + struct sensor_device_attribute *attr = to_sensor_dev_attr(da); 146 + struct ds1621_data *data = ds1621_update_client(dev); 147 + return sprintf(buf, "%d\n", 148 + LM75_TEMP_FROM_REG(data->temp[attr->index])); 149 } 150 151 + static ssize_t set_temp(struct device *dev, struct device_attribute *da, 152 + const char *buf, size_t count) 153 + { 154 + struct sensor_device_attribute *attr = to_sensor_dev_attr(da); 155 + struct i2c_client *client = to_i2c_client(dev); 156 + struct ds1621_data *data = ds1621_update_client(dev); 157 + u16 val = LM75_TEMP_TO_REG(simple_strtoul(buf, NULL, 10)); 158 159 + mutex_lock(&data->update_lock); 160 + data->temp[attr->index] = val; 161 + ds1621_write_value(client, DS1621_REG_TEMP[attr->index], 162 + data->temp[attr->index]); 163 + mutex_unlock(&data->update_lock); 164 + return count; 165 } 166 167 + static ssize_t show_alarms(struct device *dev, struct device_attribute *da, 168 + char *buf) 169 { 170 struct ds1621_data *data = ds1621_update_client(dev); 171 return sprintf(buf, "%d\n", ALARMS_FROM_REG(data->conf)); 172 } 173 174 + static ssize_t show_alarm(struct device *dev, struct device_attribute *da, 175 + char *buf) 176 + { 177 + struct sensor_device_attribute *attr = to_sensor_dev_attr(da); 178 + struct ds1621_data *data = ds1621_update_client(dev); 179 + return sprintf(buf, "%d\n", !!(data->conf & attr->index)); 180 + } 181 + 182 static DEVICE_ATTR(alarms, S_IRUGO, show_alarms, NULL); 183 + static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, show_temp, NULL, 0); 184 + static SENSOR_DEVICE_ATTR(temp1_min, S_IWUSR | S_IRUGO, show_temp, set_temp, 1); 185 + static SENSOR_DEVICE_ATTR(temp1_max, S_IWUSR | S_IRUGO, show_temp, set_temp, 2); 186 + static SENSOR_DEVICE_ATTR(temp1_min_alarm, S_IRUGO, show_alarm, NULL, 187 + DS1621_ALARM_TEMP_LOW); 188 + static SENSOR_DEVICE_ATTR(temp1_max_alarm, S_IRUGO, show_alarm, NULL, 189 + DS1621_ALARM_TEMP_HIGH); 190 191 static struct attribute *ds1621_attributes[] = { 192 + &sensor_dev_attr_temp1_input.dev_attr.attr, 193 + &sensor_dev_attr_temp1_min.dev_attr.attr, 194 + &sensor_dev_attr_temp1_max.dev_attr.attr, 195 + &sensor_dev_attr_temp1_min_alarm.dev_attr.attr, 196 + &sensor_dev_attr_temp1_max_alarm.dev_attr.attr, 197 &dev_attr_alarms.attr, 198 NULL 199 }; ··· 204 int kind) 205 { 206 int conf, temp; 207 + struct i2c_client *client; 208 struct ds1621_data *data; 209 + int i, err = 0; 210 211 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA 212 | I2C_FUNC_SMBUS_WORD_DATA ··· 221 goto exit; 222 } 223 224 + client = &data->client; 225 + i2c_set_clientdata(client, data); 226 + client->addr = address; 227 + client->adapter = adapter; 228 + client->driver = &ds1621_driver; 229 230 /* Now, we do the remaining detection. It is lousy. */ 231 if (kind < 0) { 232 /* The NVB bit should be low if no EEPROM write has been 233 requested during the latest 10ms, which is highly 234 improbable in our case. */ 235 + conf = ds1621_read_value(client, DS1621_REG_CONF); 236 if (conf & DS1621_REG_CONFIG_NVB) 237 goto exit_free; 238 /* The 7 lowest bits of a temperature should always be 0. */ 239 + for (i = 0; i < ARRAY_SIZE(data->temp); i++) { 240 + temp = ds1621_read_value(client, DS1621_REG_TEMP[i]); 241 + if (temp & 0x007f) 242 + goto exit_free; 243 + } 244 } 245 246 /* Fill in remaining client fields and put it into the global list */ 247 + strlcpy(client->name, "ds1621", I2C_NAME_SIZE); 248 mutex_init(&data->update_lock); 249 250 /* Tell the I2C layer a new client has arrived */ 251 + if ((err = i2c_attach_client(client))) 252 goto exit_free; 253 254 /* Initialize the DS1621 chip */ 255 + ds1621_init_client(client); 256 257 /* Register sysfs hooks */ 258 + if ((err = sysfs_create_group(&client->dev.kobj, &ds1621_group))) 259 goto exit_detach; 260 261 + data->class_dev = hwmon_device_register(&client->dev); 262 if (IS_ERR(data->class_dev)) { 263 err = PTR_ERR(data->class_dev); 264 goto exit_remove_files; ··· 278 return 0; 279 280 exit_remove_files: 281 + sysfs_remove_group(&client->dev.kobj, &ds1621_group); 282 exit_detach: 283 + i2c_detach_client(client); 284 exit_free: 285 kfree(data); 286 exit: ··· 314 315 if (time_after(jiffies, data->last_updated + HZ + HZ / 2) 316 || !data->valid) { 317 + int i; 318 319 dev_dbg(&client->dev, "Starting ds1621 update\n"); 320 321 data->conf = ds1621_read_value(client, DS1621_REG_CONF); 322 323 + for (i = 0; i < ARRAY_SIZE(data->temp); i++) 324 + data->temp[i] = ds1621_read_value(client, 325 + DS1621_REG_TEMP[i]); 326 327 /* reset alarms if necessary */ 328 new_conf = data->conf; 329 + if (data->temp[0] > data->temp[1]) /* input > min */ 330 new_conf &= ~DS1621_ALARM_TEMP_LOW; 331 + if (data->temp[0] < data->temp[2]) /* input < max */ 332 new_conf &= ~DS1621_ALARM_TEMP_HIGH; 333 if (data->conf != new_conf) 334 ds1621_write_value(client, DS1621_REG_CONF,
+170 -8
drivers/hwmon/f71805f.c
··· 127 #define F71805F_REG_TEMP_HIGH(nr) (0x54 + 2 * (nr)) 128 #define F71805F_REG_TEMP_HYST(nr) (0x55 + 2 * (nr)) 129 #define F71805F_REG_TEMP_MODE 0x01 130 131 #define F71805F_REG_START 0x00 132 /* status nr from 0 to 2 */ ··· 150 /* 151 * Data structures and manipulation thereof 152 */ 153 154 struct f71805f_data { 155 unsigned short addr; ··· 182 u8 temp_hyst[3]; 183 u8 temp_mode; 184 unsigned long alarms; 185 }; 186 187 struct f71805f_sio_data { ··· 325 static struct f71805f_data *f71805f_update_device(struct device *dev) 326 { 327 struct f71805f_data *data = dev_get_drvdata(dev); 328 - int nr; 329 330 mutex_lock(&data->update_lock); 331 ··· 355 F71805F_REG_TEMP_HYST(nr)); 356 } 357 data->temp_mode = f71805f_read8(data, F71805F_REG_TEMP_MODE); 358 359 data->last_limits = jiffies; 360 } ··· 730 return count; 731 } 732 733 static ssize_t show_temp(struct device *dev, struct device_attribute *devattr, 734 char *buf) 735 { ··· 1021 show_pwm_freq, set_pwm_freq, 2); 1022 static SENSOR_DEVICE_ATTR(pwm3_mode, S_IRUGO, show_pwm_mode, NULL, 2); 1023 1024 static SENSOR_DEVICE_ATTR(in0_alarm, S_IRUGO, show_alarm, NULL, 0); 1025 static SENSOR_DEVICE_ATTR(in1_alarm, S_IRUGO, show_alarm, NULL, 1); 1026 static SENSOR_DEVICE_ATTR(in2_alarm, S_IRUGO, show_alarm, NULL, 2); ··· 1159 &sensor_dev_attr_temp3_max.dev_attr.attr, 1160 &sensor_dev_attr_temp3_max_hyst.dev_attr.attr, 1161 &sensor_dev_attr_temp3_type.dev_attr.attr, 1162 1163 &sensor_dev_attr_in0_alarm.dev_attr.attr, 1164 &sensor_dev_attr_in1_alarm.dev_attr.attr, ··· 1407 struct resource *res; 1408 int i; 1409 1410 - platform_set_drvdata(pdev, NULL); 1411 hwmon_device_unregister(data->class_dev); 1412 sysfs_remove_group(&pdev->dev.kobj, &f71805f_group); 1413 for (i = 0; i < 4; i++) 1414 sysfs_remove_group(&pdev->dev.kobj, &f71805f_group_optin[i]); 1415 sysfs_remove_group(&pdev->dev.kobj, &f71805f_group_pwm_freq); 1416 kfree(data); 1417 1418 res = platform_get_resource(pdev, IORESOURCE_IO, 0); ··· 1455 goto exit_device_put; 1456 } 1457 1458 - pdev->dev.platform_data = kmalloc(sizeof(struct f71805f_sio_data), 1459 - GFP_KERNEL); 1460 - if (!pdev->dev.platform_data) { 1461 - err = -ENOMEM; 1462 printk(KERN_ERR DRVNAME ": Platform data allocation failed\n"); 1463 goto exit_device_put; 1464 } 1465 - memcpy(pdev->dev.platform_data, sio_data, 1466 - sizeof(struct f71805f_sio_data)); 1467 1468 err = platform_device_add(pdev); 1469 if (err) {
··· 127 #define F71805F_REG_TEMP_HIGH(nr) (0x54 + 2 * (nr)) 128 #define F71805F_REG_TEMP_HYST(nr) (0x55 + 2 * (nr)) 129 #define F71805F_REG_TEMP_MODE 0x01 130 + /* pwm/fan pwmnr from 0 to 2, auto point apnr from 0 to 2 */ 131 + /* map Fintek numbers to our numbers as follows: 9->0, 5->1, 1->2 */ 132 + #define F71805F_REG_PWM_AUTO_POINT_TEMP(pwmnr, apnr) \ 133 + (0xA0 + 0x10 * (pwmnr) + (2 - (apnr))) 134 + #define F71805F_REG_PWM_AUTO_POINT_FAN(pwmnr, apnr) \ 135 + (0xA4 + 0x10 * (pwmnr) + \ 136 + 2 * (2 - (apnr))) 137 138 #define F71805F_REG_START 0x00 139 /* status nr from 0 to 2 */ ··· 143 /* 144 * Data structures and manipulation thereof 145 */ 146 + 147 + struct f71805f_auto_point { 148 + u8 temp[3]; 149 + u16 fan[3]; 150 + }; 151 152 struct f71805f_data { 153 unsigned short addr; ··· 170 u8 temp_hyst[3]; 171 u8 temp_mode; 172 unsigned long alarms; 173 + struct f71805f_auto_point auto_points[3]; 174 }; 175 176 struct f71805f_sio_data { ··· 312 static struct f71805f_data *f71805f_update_device(struct device *dev) 313 { 314 struct f71805f_data *data = dev_get_drvdata(dev); 315 + int nr, apnr; 316 317 mutex_lock(&data->update_lock); 318 ··· 342 F71805F_REG_TEMP_HYST(nr)); 343 } 344 data->temp_mode = f71805f_read8(data, F71805F_REG_TEMP_MODE); 345 + for (nr = 0; nr < 3; nr++) { 346 + for (apnr = 0; apnr < 3; apnr++) { 347 + data->auto_points[nr].temp[apnr] = 348 + f71805f_read8(data, 349 + F71805F_REG_PWM_AUTO_POINT_TEMP(nr, 350 + apnr)); 351 + data->auto_points[nr].fan[apnr] = 352 + f71805f_read16(data, 353 + F71805F_REG_PWM_AUTO_POINT_FAN(nr, 354 + apnr)); 355 + } 356 + } 357 358 data->last_limits = jiffies; 359 } ··· 705 return count; 706 } 707 708 + static ssize_t show_pwm_auto_point_temp(struct device *dev, 709 + struct device_attribute *devattr, 710 + char* buf) 711 + { 712 + struct f71805f_data *data = dev_get_drvdata(dev); 713 + struct sensor_device_attribute_2 *attr = to_sensor_dev_attr_2(devattr); 714 + int pwmnr = attr->nr; 715 + int apnr = attr->index; 716 + 717 + return sprintf(buf, "%ld\n", 718 + temp_from_reg(data->auto_points[pwmnr].temp[apnr])); 719 + } 720 + 721 + static ssize_t set_pwm_auto_point_temp(struct device *dev, 722 + struct device_attribute *devattr, 723 + const char* buf, size_t count) 724 + { 725 + struct f71805f_data *data = dev_get_drvdata(dev); 726 + struct sensor_device_attribute_2 *attr = to_sensor_dev_attr_2(devattr); 727 + int pwmnr = attr->nr; 728 + int apnr = attr->index; 729 + unsigned long val = simple_strtol(buf, NULL, 10); 730 + 731 + mutex_lock(&data->update_lock); 732 + data->auto_points[pwmnr].temp[apnr] = temp_to_reg(val); 733 + f71805f_write8(data, F71805F_REG_PWM_AUTO_POINT_TEMP(pwmnr, apnr), 734 + data->auto_points[pwmnr].temp[apnr]); 735 + mutex_unlock(&data->update_lock); 736 + 737 + return count; 738 + } 739 + 740 + static ssize_t show_pwm_auto_point_fan(struct device *dev, 741 + struct device_attribute *devattr, 742 + char* buf) 743 + { 744 + struct f71805f_data *data = dev_get_drvdata(dev); 745 + struct sensor_device_attribute_2 *attr = to_sensor_dev_attr_2(devattr); 746 + int pwmnr = attr->nr; 747 + int apnr = attr->index; 748 + 749 + return sprintf(buf, "%ld\n", 750 + fan_from_reg(data->auto_points[pwmnr].fan[apnr])); 751 + } 752 + 753 + static ssize_t set_pwm_auto_point_fan(struct device *dev, 754 + struct device_attribute *devattr, 755 + const char* buf, size_t count) 756 + { 757 + struct f71805f_data *data = dev_get_drvdata(dev); 758 + struct sensor_device_attribute_2 *attr = to_sensor_dev_attr_2(devattr); 759 + int pwmnr = attr->nr; 760 + int apnr = attr->index; 761 + unsigned long val = simple_strtoul(buf, NULL, 10); 762 + 763 + mutex_lock(&data->update_lock); 764 + data->auto_points[pwmnr].fan[apnr] = fan_to_reg(val); 765 + f71805f_write16(data, F71805F_REG_PWM_AUTO_POINT_FAN(pwmnr, apnr), 766 + data->auto_points[pwmnr].fan[apnr]); 767 + mutex_unlock(&data->update_lock); 768 + 769 + return count; 770 + } 771 + 772 static ssize_t show_temp(struct device *dev, struct device_attribute *devattr, 773 char *buf) 774 { ··· 932 show_pwm_freq, set_pwm_freq, 2); 933 static SENSOR_DEVICE_ATTR(pwm3_mode, S_IRUGO, show_pwm_mode, NULL, 2); 934 935 + static SENSOR_DEVICE_ATTR_2(pwm1_auto_point1_temp, S_IRUGO | S_IWUSR, 936 + show_pwm_auto_point_temp, set_pwm_auto_point_temp, 937 + 0, 0); 938 + static SENSOR_DEVICE_ATTR_2(pwm1_auto_point1_fan, S_IRUGO | S_IWUSR, 939 + show_pwm_auto_point_fan, set_pwm_auto_point_fan, 940 + 0, 0); 941 + static SENSOR_DEVICE_ATTR_2(pwm1_auto_point2_temp, S_IRUGO | S_IWUSR, 942 + show_pwm_auto_point_temp, set_pwm_auto_point_temp, 943 + 0, 1); 944 + static SENSOR_DEVICE_ATTR_2(pwm1_auto_point2_fan, S_IRUGO | S_IWUSR, 945 + show_pwm_auto_point_fan, set_pwm_auto_point_fan, 946 + 0, 1); 947 + static SENSOR_DEVICE_ATTR_2(pwm1_auto_point3_temp, S_IRUGO | S_IWUSR, 948 + show_pwm_auto_point_temp, set_pwm_auto_point_temp, 949 + 0, 2); 950 + static SENSOR_DEVICE_ATTR_2(pwm1_auto_point3_fan, S_IRUGO | S_IWUSR, 951 + show_pwm_auto_point_fan, set_pwm_auto_point_fan, 952 + 0, 2); 953 + 954 + static SENSOR_DEVICE_ATTR_2(pwm2_auto_point1_temp, S_IRUGO | S_IWUSR, 955 + show_pwm_auto_point_temp, set_pwm_auto_point_temp, 956 + 1, 0); 957 + static SENSOR_DEVICE_ATTR_2(pwm2_auto_point1_fan, S_IRUGO | S_IWUSR, 958 + show_pwm_auto_point_fan, set_pwm_auto_point_fan, 959 + 1, 0); 960 + static SENSOR_DEVICE_ATTR_2(pwm2_auto_point2_temp, S_IRUGO | S_IWUSR, 961 + show_pwm_auto_point_temp, set_pwm_auto_point_temp, 962 + 1, 1); 963 + static SENSOR_DEVICE_ATTR_2(pwm2_auto_point2_fan, S_IRUGO | S_IWUSR, 964 + show_pwm_auto_point_fan, set_pwm_auto_point_fan, 965 + 1, 1); 966 + static SENSOR_DEVICE_ATTR_2(pwm2_auto_point3_temp, S_IRUGO | S_IWUSR, 967 + show_pwm_auto_point_temp, set_pwm_auto_point_temp, 968 + 1, 2); 969 + static SENSOR_DEVICE_ATTR_2(pwm2_auto_point3_fan, S_IRUGO | S_IWUSR, 970 + show_pwm_auto_point_fan, set_pwm_auto_point_fan, 971 + 1, 2); 972 + 973 + static SENSOR_DEVICE_ATTR_2(pwm3_auto_point1_temp, S_IRUGO | S_IWUSR, 974 + show_pwm_auto_point_temp, set_pwm_auto_point_temp, 975 + 2, 0); 976 + static SENSOR_DEVICE_ATTR_2(pwm3_auto_point1_fan, S_IRUGO | S_IWUSR, 977 + show_pwm_auto_point_fan, set_pwm_auto_point_fan, 978 + 2, 0); 979 + static SENSOR_DEVICE_ATTR_2(pwm3_auto_point2_temp, S_IRUGO | S_IWUSR, 980 + show_pwm_auto_point_temp, set_pwm_auto_point_temp, 981 + 2, 1); 982 + static SENSOR_DEVICE_ATTR_2(pwm3_auto_point2_fan, S_IRUGO | S_IWUSR, 983 + show_pwm_auto_point_fan, set_pwm_auto_point_fan, 984 + 2, 1); 985 + static SENSOR_DEVICE_ATTR_2(pwm3_auto_point3_temp, S_IRUGO | S_IWUSR, 986 + show_pwm_auto_point_temp, set_pwm_auto_point_temp, 987 + 2, 2); 988 + static SENSOR_DEVICE_ATTR_2(pwm3_auto_point3_fan, S_IRUGO | S_IWUSR, 989 + show_pwm_auto_point_fan, set_pwm_auto_point_fan, 990 + 2, 2); 991 + 992 static SENSOR_DEVICE_ATTR(in0_alarm, S_IRUGO, show_alarm, NULL, 0); 993 static SENSOR_DEVICE_ATTR(in1_alarm, S_IRUGO, show_alarm, NULL, 1); 994 static SENSOR_DEVICE_ATTR(in2_alarm, S_IRUGO, show_alarm, NULL, 2); ··· 1013 &sensor_dev_attr_temp3_max.dev_attr.attr, 1014 &sensor_dev_attr_temp3_max_hyst.dev_attr.attr, 1015 &sensor_dev_attr_temp3_type.dev_attr.attr, 1016 + 1017 + &sensor_dev_attr_pwm1_auto_point1_temp.dev_attr.attr, 1018 + &sensor_dev_attr_pwm1_auto_point1_fan.dev_attr.attr, 1019 + &sensor_dev_attr_pwm1_auto_point2_temp.dev_attr.attr, 1020 + &sensor_dev_attr_pwm1_auto_point2_fan.dev_attr.attr, 1021 + &sensor_dev_attr_pwm1_auto_point3_temp.dev_attr.attr, 1022 + &sensor_dev_attr_pwm1_auto_point3_fan.dev_attr.attr, 1023 + &sensor_dev_attr_pwm2_auto_point1_temp.dev_attr.attr, 1024 + &sensor_dev_attr_pwm2_auto_point1_fan.dev_attr.attr, 1025 + &sensor_dev_attr_pwm2_auto_point2_temp.dev_attr.attr, 1026 + &sensor_dev_attr_pwm2_auto_point2_fan.dev_attr.attr, 1027 + &sensor_dev_attr_pwm2_auto_point3_temp.dev_attr.attr, 1028 + &sensor_dev_attr_pwm2_auto_point3_fan.dev_attr.attr, 1029 + &sensor_dev_attr_pwm3_auto_point1_temp.dev_attr.attr, 1030 + &sensor_dev_attr_pwm3_auto_point1_fan.dev_attr.attr, 1031 + &sensor_dev_attr_pwm3_auto_point2_temp.dev_attr.attr, 1032 + &sensor_dev_attr_pwm3_auto_point2_fan.dev_attr.attr, 1033 + &sensor_dev_attr_pwm3_auto_point3_temp.dev_attr.attr, 1034 + &sensor_dev_attr_pwm3_auto_point3_fan.dev_attr.attr, 1035 1036 &sensor_dev_attr_in0_alarm.dev_attr.attr, 1037 &sensor_dev_attr_in1_alarm.dev_attr.attr, ··· 1242 struct resource *res; 1243 int i; 1244 1245 hwmon_device_unregister(data->class_dev); 1246 sysfs_remove_group(&pdev->dev.kobj, &f71805f_group); 1247 for (i = 0; i < 4; i++) 1248 sysfs_remove_group(&pdev->dev.kobj, &f71805f_group_optin[i]); 1249 sysfs_remove_group(&pdev->dev.kobj, &f71805f_group_pwm_freq); 1250 + platform_set_drvdata(pdev, NULL); 1251 kfree(data); 1252 1253 res = platform_get_resource(pdev, IORESOURCE_IO, 0); ··· 1290 goto exit_device_put; 1291 } 1292 1293 + err = platform_device_add_data(pdev, sio_data, 1294 + sizeof(struct f71805f_sio_data)); 1295 + if (err) { 1296 printk(KERN_ERR DRVNAME ": Platform data allocation failed\n"); 1297 goto exit_device_put; 1298 } 1299 1300 err = platform_device_add(pdev); 1301 if (err) {
+278 -215
drivers/hwmon/it87.c
··· 6 IT8712F Super I/O chip w/LPC interface 7 IT8716F Super I/O chip w/LPC interface 8 IT8718F Super I/O chip w/LPC interface 9 Sis950 A clone of the IT8705F 10 11 Copyright (C) 2001 Chris Gauthron <chrisg@0-in.com> ··· 31 #include <linux/init.h> 32 #include <linux/slab.h> 33 #include <linux/jiffies.h> 34 - #include <linux/i2c.h> 35 - #include <linux/i2c-isa.h> 36 #include <linux/hwmon.h> 37 #include <linux/hwmon-sysfs.h> 38 #include <linux/hwmon-vid.h> ··· 40 #include <linux/sysfs.h> 41 #include <asm/io.h> 42 43 44 - static unsigned short isa_address; 45 enum chips { it87, it8712, it8716, it8718 }; 46 47 #define REG 0x2e /* The register to read/write */ 48 #define DEV 0x07 /* Register: Logical device select */ ··· 99 #define IT8705F_DEVID 0x8705 100 #define IT8716F_DEVID 0x8716 101 #define IT8718F_DEVID 0x8718 102 #define IT87_ACT_REG 0x30 103 #define IT87_BASE_REG 0x60 104 ··· 112 113 /* Not all BIOSes properly configure the PWM registers */ 114 static int fix_pwm_polarity; 115 - 116 - /* Values read from Super-I/O config space */ 117 - static u16 chip_type; 118 - static u8 vid_value; 119 120 /* Many IT87 constants specified below */ 121 ··· 213 }; 214 215 216 /* For each registered chip, we need to keep some data in memory. 217 The structure is dynamically allocated. */ 218 struct it87_data { 219 - struct i2c_client client; 220 struct class_device *class_dev; 221 enum chips type; 222 223 struct mutex update_lock; 224 char valid; /* !=0 if following fields are valid */ 225 unsigned long last_updated; /* In jiffies */ ··· 251 }; 252 253 254 - static int it87_detect(struct i2c_adapter *adapter); 255 - static int it87_detach_client(struct i2c_client *client); 256 257 - static int it87_read_value(struct i2c_client *client, u8 reg); 258 - static void it87_write_value(struct i2c_client *client, u8 reg, u8 value); 259 static struct it87_data *it87_update_device(struct device *dev); 260 - static int it87_check_pwm(struct i2c_client *client); 261 - static void it87_init_client(struct i2c_client *client, struct it87_data *data); 262 263 264 - static struct i2c_driver it87_isa_driver = { 265 .driver = { 266 .owner = THIS_MODULE, 267 - .name = "it87-isa", 268 }, 269 - .attach_adapter = it87_detect, 270 - .detach_client = it87_detach_client, 271 }; 272 - 273 274 static ssize_t show_in(struct device *dev, struct device_attribute *attr, 275 char *buf) ··· 306 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); 307 int nr = sensor_attr->index; 308 309 - struct i2c_client *client = to_i2c_client(dev); 310 - struct it87_data *data = i2c_get_clientdata(client); 311 unsigned long val = simple_strtoul(buf, NULL, 10); 312 313 mutex_lock(&data->update_lock); 314 data->in_min[nr] = IN_TO_REG(val); 315 - it87_write_value(client, IT87_REG_VIN_MIN(nr), 316 data->in_min[nr]); 317 mutex_unlock(&data->update_lock); 318 return count; ··· 322 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); 323 int nr = sensor_attr->index; 324 325 - struct i2c_client *client = to_i2c_client(dev); 326 - struct it87_data *data = i2c_get_clientdata(client); 327 unsigned long val = simple_strtoul(buf, NULL, 10); 328 329 mutex_lock(&data->update_lock); 330 data->in_max[nr] = IN_TO_REG(val); 331 - it87_write_value(client, IT87_REG_VIN_MAX(nr), 332 data->in_max[nr]); 333 mutex_unlock(&data->update_lock); 334 return count; ··· 395 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); 396 int nr = sensor_attr->index; 397 398 - struct i2c_client *client = to_i2c_client(dev); 399 - struct it87_data *data = i2c_get_clientdata(client); 400 int val = simple_strtol(buf, NULL, 10); 401 402 mutex_lock(&data->update_lock); 403 data->temp_high[nr] = TEMP_TO_REG(val); 404 - it87_write_value(client, IT87_REG_TEMP_HIGH(nr), data->temp_high[nr]); 405 mutex_unlock(&data->update_lock); 406 return count; 407 } ··· 410 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); 411 int nr = sensor_attr->index; 412 413 - struct i2c_client *client = to_i2c_client(dev); 414 - struct it87_data *data = i2c_get_clientdata(client); 415 int val = simple_strtol(buf, NULL, 10); 416 417 mutex_lock(&data->update_lock); 418 data->temp_low[nr] = TEMP_TO_REG(val); 419 - it87_write_value(client, IT87_REG_TEMP_LOW(nr), data->temp_low[nr]); 420 mutex_unlock(&data->update_lock); 421 return count; 422 } ··· 452 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); 453 int nr = sensor_attr->index; 454 455 - struct i2c_client *client = to_i2c_client(dev); 456 - struct it87_data *data = i2c_get_clientdata(client); 457 int val = simple_strtol(buf, NULL, 10); 458 459 mutex_lock(&data->update_lock); ··· 468 mutex_unlock(&data->update_lock); 469 return -EINVAL; 470 } 471 - it87_write_value(client, IT87_REG_TEMP_ENABLE, data->sensor); 472 mutex_unlock(&data->update_lock); 473 return count; 474 } ··· 542 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); 543 int nr = sensor_attr->index; 544 545 - struct i2c_client *client = to_i2c_client(dev); 546 - struct it87_data *data = i2c_get_clientdata(client); 547 int val = simple_strtol(buf, NULL, 10); 548 u8 reg; 549 550 mutex_lock(&data->update_lock); 551 - reg = it87_read_value(client, IT87_REG_FAN_DIV); 552 switch (nr) { 553 case 0: data->fan_div[nr] = reg & 0x07; break; 554 case 1: data->fan_div[nr] = (reg >> 3) & 0x07; break; ··· 555 } 556 557 data->fan_min[nr] = FAN_TO_REG(val, DIV_FROM_REG(data->fan_div[nr])); 558 - it87_write_value(client, IT87_REG_FAN_MIN(nr), data->fan_min[nr]); 559 mutex_unlock(&data->update_lock); 560 return count; 561 } ··· 565 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); 566 int nr = sensor_attr->index; 567 568 - struct i2c_client *client = to_i2c_client(dev); 569 - struct it87_data *data = i2c_get_clientdata(client); 570 unsigned long val = simple_strtoul(buf, NULL, 10); 571 int min; 572 u8 old; 573 574 mutex_lock(&data->update_lock); 575 - old = it87_read_value(client, IT87_REG_FAN_DIV); 576 577 /* Save fan min limit */ 578 min = FAN_FROM_REG(data->fan_min[nr], DIV_FROM_REG(data->fan_div[nr])); ··· 592 val |= (data->fan_div[1] & 0x07) << 3; 593 if (data->fan_div[2] == 3) 594 val |= 0x1 << 6; 595 - it87_write_value(client, IT87_REG_FAN_DIV, val); 596 597 /* Restore fan min limit */ 598 data->fan_min[nr] = FAN_TO_REG(min, DIV_FROM_REG(data->fan_div[nr])); 599 - it87_write_value(client, IT87_REG_FAN_MIN(nr), data->fan_min[nr]); 600 601 mutex_unlock(&data->update_lock); 602 return count; ··· 607 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); 608 int nr = sensor_attr->index; 609 610 - struct i2c_client *client = to_i2c_client(dev); 611 - struct it87_data *data = i2c_get_clientdata(client); 612 int val = simple_strtol(buf, NULL, 10); 613 614 mutex_lock(&data->update_lock); ··· 615 if (val == 0) { 616 int tmp; 617 /* make sure the fan is on when in on/off mode */ 618 - tmp = it87_read_value(client, IT87_REG_FAN_CTL); 619 - it87_write_value(client, IT87_REG_FAN_CTL, tmp | (1 << nr)); 620 /* set on/off mode */ 621 data->fan_main_ctrl &= ~(1 << nr); 622 - it87_write_value(client, IT87_REG_FAN_MAIN_CTRL, data->fan_main_ctrl); 623 } else if (val == 1) { 624 /* set SmartGuardian mode */ 625 data->fan_main_ctrl |= (1 << nr); 626 - it87_write_value(client, IT87_REG_FAN_MAIN_CTRL, data->fan_main_ctrl); 627 /* set saved pwm value, clear FAN_CTLX PWM mode bit */ 628 - it87_write_value(client, IT87_REG_PWM(nr), PWM_TO_REG(data->manual_pwm_ctl[nr])); 629 } else { 630 mutex_unlock(&data->update_lock); 631 return -EINVAL; ··· 640 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); 641 int nr = sensor_attr->index; 642 643 - struct i2c_client *client = to_i2c_client(dev); 644 - struct it87_data *data = i2c_get_clientdata(client); 645 int val = simple_strtol(buf, NULL, 10); 646 647 if (val < 0 || val > 255) ··· 649 mutex_lock(&data->update_lock); 650 data->manual_pwm_ctl[nr] = val; 651 if (data->fan_main_ctrl & (1 << nr)) 652 - it87_write_value(client, IT87_REG_PWM(nr), PWM_TO_REG(data->manual_pwm_ctl[nr])); 653 mutex_unlock(&data->update_lock); 654 return count; 655 } 656 static ssize_t set_pwm_freq(struct device *dev, 657 struct device_attribute *attr, const char *buf, size_t count) 658 { 659 - struct i2c_client *client = to_i2c_client(dev); 660 - struct it87_data *data = i2c_get_clientdata(client); 661 unsigned long val = simple_strtoul(buf, NULL, 10); 662 int i; 663 ··· 667 } 668 669 mutex_lock(&data->update_lock); 670 - data->fan_ctl = it87_read_value(client, IT87_REG_FAN_CTL) & 0x8f; 671 data->fan_ctl |= i << 4; 672 - it87_write_value(client, IT87_REG_FAN_CTL, data->fan_ctl); 673 mutex_unlock(&data->update_lock); 674 675 return count; ··· 724 { 725 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); 726 int nr = sensor_attr->index; 727 - struct i2c_client *client = to_i2c_client(dev); 728 - struct it87_data *data = i2c_get_clientdata(client); 729 int val = simple_strtol(buf, NULL, 10); 730 731 mutex_lock(&data->update_lock); 732 data->fan_min[nr] = FAN16_TO_REG(val); 733 - it87_write_value(client, IT87_REG_FAN_MIN(nr), 734 data->fan_min[nr] & 0xff); 735 - it87_write_value(client, IT87_REG_FANX_MIN(nr), 736 data->fan_min[nr] >> 8); 737 mutex_unlock(&data->update_lock); 738 return count; ··· 769 static ssize_t 770 store_vrm_reg(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) 771 { 772 - struct i2c_client *client = to_i2c_client(dev); 773 - struct it87_data *data = i2c_get_clientdata(client); 774 u32 val; 775 776 val = simple_strtoul(buf, NULL, 10); ··· 786 return sprintf(buf, "%ld\n", (long) vid_from_reg(data->vid, data->vrm)); 787 } 788 static DEVICE_ATTR(cpu0_vid, S_IRUGO, show_vid_reg, NULL); 789 790 static struct attribute *it87_attributes[] = { 791 &sensor_dev_attr_in0_input.dev_attr.attr, ··· 836 &sensor_dev_attr_temp3_type.dev_attr.attr, 837 838 &dev_attr_alarms.attr, 839 NULL 840 }; 841 ··· 879 }; 880 881 /* SuperIO detection - will change isa_address if a chip is found */ 882 - static int __init it87_find(unsigned short *address) 883 { 884 int err = -ENODEV; 885 886 superio_enter(); 887 chip_type = superio_inw(DEVID); 888 - if (chip_type != IT8712F_DEVID 889 - && chip_type != IT8716F_DEVID 890 - && chip_type != IT8718F_DEVID 891 - && chip_type != IT8705F_DEVID) 892 - goto exit; 893 894 superio_select(PME); 895 if (!(superio_inb(IT87_ACT_REG) & 0x01)) { ··· 932 933 superio_select(GPIO); 934 if (chip_type == it8718) 935 - vid_value = superio_inb(IT87_SIO_VID_REG); 936 937 reg = superio_inb(IT87_SIO_PINX2_REG); 938 if (reg & (1 << 0)) ··· 946 return err; 947 } 948 949 - /* This function is called by i2c_probe */ 950 - static int it87_detect(struct i2c_adapter *adapter) 951 { 952 - struct i2c_client *new_client; 953 struct it87_data *data; 954 int err = 0; 955 - const char *name; 956 int enable_pwm_interface; 957 958 - /* Reserve the ISA region */ 959 - if (!request_region(isa_address, IT87_EXTENT, 960 - it87_isa_driver.driver.name)){ 961 err = -EBUSY; 962 goto ERROR0; 963 } ··· 975 goto ERROR1; 976 } 977 978 - new_client = &data->client; 979 - i2c_set_clientdata(new_client, data); 980 - new_client->addr = isa_address; 981 - new_client->adapter = adapter; 982 - new_client->driver = &it87_isa_driver; 983 984 /* Now, we do the remaining detection. */ 985 - if ((it87_read_value(new_client, IT87_REG_CONFIG) & 0x80) 986 - || it87_read_value(new_client, IT87_REG_CHIPID) != 0x90) { 987 err = -ENODEV; 988 goto ERROR2; 989 } 990 991 - /* Determine the chip type. */ 992 - switch (chip_type) { 993 - case IT8712F_DEVID: 994 - data->type = it8712; 995 - name = "it8712"; 996 - break; 997 - case IT8716F_DEVID: 998 - data->type = it8716; 999 - name = "it8716"; 1000 - break; 1001 - case IT8718F_DEVID: 1002 - data->type = it8718; 1003 - name = "it8718"; 1004 - break; 1005 - default: 1006 - data->type = it87; 1007 - name = "it87"; 1008 - } 1009 1010 - /* Fill in the remaining client fields and put it into the global list */ 1011 - strlcpy(new_client->name, name, I2C_NAME_SIZE); 1012 mutex_init(&data->update_lock); 1013 1014 - /* Tell the I2C layer a new client has arrived */ 1015 - if ((err = i2c_attach_client(new_client))) 1016 - goto ERROR2; 1017 - 1018 /* Check PWM configuration */ 1019 - enable_pwm_interface = it87_check_pwm(new_client); 1020 1021 /* Initialize the IT87 chip */ 1022 - it87_init_client(new_client, data); 1023 1024 /* Register sysfs hooks */ 1025 - if ((err = sysfs_create_group(&new_client->dev.kobj, &it87_group))) 1026 - goto ERROR3; 1027 1028 /* Do not create fan files for disabled fans */ 1029 if (data->type == it8716 || data->type == it8718) { 1030 /* 16-bit tachometers */ 1031 if (data->has_fan & (1 << 0)) { 1032 - if ((err = device_create_file(&new_client->dev, 1033 &sensor_dev_attr_fan1_input16.dev_attr)) 1034 - || (err = device_create_file(&new_client->dev, 1035 &sensor_dev_attr_fan1_min16.dev_attr))) 1036 goto ERROR4; 1037 } 1038 if (data->has_fan & (1 << 1)) { 1039 - if ((err = device_create_file(&new_client->dev, 1040 &sensor_dev_attr_fan2_input16.dev_attr)) 1041 - || (err = device_create_file(&new_client->dev, 1042 &sensor_dev_attr_fan2_min16.dev_attr))) 1043 goto ERROR4; 1044 } 1045 if (data->has_fan & (1 << 2)) { 1046 - if ((err = device_create_file(&new_client->dev, 1047 &sensor_dev_attr_fan3_input16.dev_attr)) 1048 - || (err = device_create_file(&new_client->dev, 1049 &sensor_dev_attr_fan3_min16.dev_attr))) 1050 goto ERROR4; 1051 } 1052 } else { 1053 /* 8-bit tachometers with clock divider */ 1054 if (data->has_fan & (1 << 0)) { 1055 - if ((err = device_create_file(&new_client->dev, 1056 &sensor_dev_attr_fan1_input.dev_attr)) 1057 - || (err = device_create_file(&new_client->dev, 1058 &sensor_dev_attr_fan1_min.dev_attr)) 1059 - || (err = device_create_file(&new_client->dev, 1060 &sensor_dev_attr_fan1_div.dev_attr))) 1061 goto ERROR4; 1062 } 1063 if (data->has_fan & (1 << 1)) { 1064 - if ((err = device_create_file(&new_client->dev, 1065 &sensor_dev_attr_fan2_input.dev_attr)) 1066 - || (err = device_create_file(&new_client->dev, 1067 &sensor_dev_attr_fan2_min.dev_attr)) 1068 - || (err = device_create_file(&new_client->dev, 1069 &sensor_dev_attr_fan2_div.dev_attr))) 1070 goto ERROR4; 1071 } 1072 if (data->has_fan & (1 << 2)) { 1073 - if ((err = device_create_file(&new_client->dev, 1074 &sensor_dev_attr_fan3_input.dev_attr)) 1075 - || (err = device_create_file(&new_client->dev, 1076 &sensor_dev_attr_fan3_min.dev_attr)) 1077 - || (err = device_create_file(&new_client->dev, 1078 &sensor_dev_attr_fan3_div.dev_attr))) 1079 goto ERROR4; 1080 } 1081 } 1082 1083 if (enable_pwm_interface) { 1084 - if ((err = device_create_file(&new_client->dev, 1085 &sensor_dev_attr_pwm1_enable.dev_attr)) 1086 - || (err = device_create_file(&new_client->dev, 1087 &sensor_dev_attr_pwm2_enable.dev_attr)) 1088 - || (err = device_create_file(&new_client->dev, 1089 &sensor_dev_attr_pwm3_enable.dev_attr)) 1090 - || (err = device_create_file(&new_client->dev, 1091 &sensor_dev_attr_pwm1.dev_attr)) 1092 - || (err = device_create_file(&new_client->dev, 1093 &sensor_dev_attr_pwm2.dev_attr)) 1094 - || (err = device_create_file(&new_client->dev, 1095 &sensor_dev_attr_pwm3.dev_attr)) 1096 - || (err = device_create_file(&new_client->dev, 1097 &dev_attr_pwm1_freq)) 1098 - || (err = device_create_file(&new_client->dev, 1099 &dev_attr_pwm2_freq)) 1100 - || (err = device_create_file(&new_client->dev, 1101 &dev_attr_pwm3_freq))) 1102 goto ERROR4; 1103 } ··· 1081 || data->type == it8718) { 1082 data->vrm = vid_which_vrm(); 1083 /* VID reading from Super-I/O config space if available */ 1084 - data->vid = vid_value; 1085 - if ((err = device_create_file(&new_client->dev, 1086 &dev_attr_vrm)) 1087 - || (err = device_create_file(&new_client->dev, 1088 &dev_attr_cpu0_vid))) 1089 goto ERROR4; 1090 } 1091 1092 - data->class_dev = hwmon_device_register(&new_client->dev); 1093 if (IS_ERR(data->class_dev)) { 1094 err = PTR_ERR(data->class_dev); 1095 goto ERROR4; ··· 1098 return 0; 1099 1100 ERROR4: 1101 - sysfs_remove_group(&new_client->dev.kobj, &it87_group); 1102 - sysfs_remove_group(&new_client->dev.kobj, &it87_group_opt); 1103 - ERROR3: 1104 - i2c_detach_client(new_client); 1105 ERROR2: 1106 kfree(data); 1107 ERROR1: 1108 - release_region(isa_address, IT87_EXTENT); 1109 ERROR0: 1110 return err; 1111 } 1112 1113 - static int it87_detach_client(struct i2c_client *client) 1114 { 1115 - struct it87_data *data = i2c_get_clientdata(client); 1116 - int err; 1117 1118 hwmon_device_unregister(data->class_dev); 1119 - sysfs_remove_group(&client->dev.kobj, &it87_group); 1120 - sysfs_remove_group(&client->dev.kobj, &it87_group_opt); 1121 1122 - if ((err = i2c_detach_client(client))) 1123 - return err; 1124 - 1125 - release_region(client->addr, IT87_EXTENT); 1126 kfree(data); 1127 1128 return 0; ··· 1127 /* Must be called with data->update_lock held, except during initialization. 1128 We ignore the IT87 BUSY flag at this moment - it could lead to deadlocks, 1129 would slow down the IT87 access and should not be necessary. */ 1130 - static int it87_read_value(struct i2c_client *client, u8 reg) 1131 { 1132 - outb_p(reg, client->addr + IT87_ADDR_REG_OFFSET); 1133 - return inb_p(client->addr + IT87_DATA_REG_OFFSET); 1134 } 1135 1136 /* Must be called with data->update_lock held, except during initialization. 1137 We ignore the IT87 BUSY flag at this moment - it could lead to deadlocks, 1138 would slow down the IT87 access and should not be necessary. */ 1139 - static void it87_write_value(struct i2c_client *client, u8 reg, u8 value) 1140 { 1141 - outb_p(reg, client->addr + IT87_ADDR_REG_OFFSET); 1142 - outb_p(value, client->addr + IT87_DATA_REG_OFFSET); 1143 } 1144 1145 /* Return 1 if and only if the PWM interface is safe to use */ 1146 - static int it87_check_pwm(struct i2c_client *client) 1147 { 1148 /* Some BIOSes fail to correctly configure the IT87 fans. All fans off 1149 * and polarity set to active low is sign that this is the case so we 1150 * disable pwm control to protect the user. */ 1151 - int tmp = it87_read_value(client, IT87_REG_FAN_CTL); 1152 if ((tmp & 0x87) == 0) { 1153 if (fix_pwm_polarity) { 1154 /* The user asks us to attempt a chip reconfiguration. ··· 1159 u8 pwm[3]; 1160 1161 for (i = 0; i < 3; i++) 1162 - pwm[i] = it87_read_value(client, 1163 IT87_REG_PWM(i)); 1164 1165 /* If any fan is in automatic pwm mode, the polarity ··· 1167 * better don't change anything (but still disable the 1168 * PWM interface). */ 1169 if (!((pwm[0] | pwm[1] | pwm[2]) & 0x80)) { 1170 - dev_info(&client->dev, "Reconfiguring PWM to " 1171 "active high polarity\n"); 1172 - it87_write_value(client, IT87_REG_FAN_CTL, 1173 tmp | 0x87); 1174 for (i = 0; i < 3; i++) 1175 - it87_write_value(client, 1176 IT87_REG_PWM(i), 1177 0x7f & ~pwm[i]); 1178 return 1; 1179 } 1180 1181 - dev_info(&client->dev, "PWM configuration is " 1182 "too broken to be fixed\n"); 1183 } 1184 1185 - dev_info(&client->dev, "Detected broken BIOS " 1186 "defaults, disabling PWM interface\n"); 1187 return 0; 1188 } else if (fix_pwm_polarity) { 1189 - dev_info(&client->dev, "PWM configuration looks " 1190 "sane, won't touch\n"); 1191 } 1192 ··· 1194 } 1195 1196 /* Called when we have found a new IT87. */ 1197 - static void it87_init_client(struct i2c_client *client, struct it87_data *data) 1198 { 1199 int tmp, i; 1200 1201 /* initialize to sane defaults: ··· 1216 * means -1 degree C, which surprisingly doesn't trigger an alarm, 1217 * but is still confusing, so change to 127 degrees C. */ 1218 for (i = 0; i < 8; i++) { 1219 - tmp = it87_read_value(client, IT87_REG_VIN_MIN(i)); 1220 if (tmp == 0xff) 1221 - it87_write_value(client, IT87_REG_VIN_MIN(i), 0); 1222 } 1223 for (i = 0; i < 3; i++) { 1224 - tmp = it87_read_value(client, IT87_REG_TEMP_HIGH(i)); 1225 if (tmp == 0xff) 1226 - it87_write_value(client, IT87_REG_TEMP_HIGH(i), 127); 1227 } 1228 1229 /* Check if temperature channnels are reset manually or by some reason */ 1230 - tmp = it87_read_value(client, IT87_REG_TEMP_ENABLE); 1231 if ((tmp & 0x3f) == 0) { 1232 /* Temp1,Temp3=thermistor; Temp2=thermal diode */ 1233 tmp = (tmp & 0xc0) | 0x2a; 1234 - it87_write_value(client, IT87_REG_TEMP_ENABLE, tmp); 1235 } 1236 data->sensor = tmp; 1237 1238 /* Check if voltage monitors are reset manually or by some reason */ 1239 - tmp = it87_read_value(client, IT87_REG_VIN_ENABLE); 1240 if ((tmp & 0xff) == 0) { 1241 /* Enable all voltage monitors */ 1242 - it87_write_value(client, IT87_REG_VIN_ENABLE, 0xff); 1243 } 1244 1245 /* Check if tachometers are reset manually or by some reason */ 1246 - data->fan_main_ctrl = it87_read_value(client, IT87_REG_FAN_MAIN_CTRL); 1247 if ((data->fan_main_ctrl & 0x70) == 0) { 1248 /* Enable all fan tachometers */ 1249 data->fan_main_ctrl |= 0x70; 1250 - it87_write_value(client, IT87_REG_FAN_MAIN_CTRL, data->fan_main_ctrl); 1251 } 1252 data->has_fan = (data->fan_main_ctrl >> 4) & 0x07; 1253 1254 /* Set tachometers to 16-bit mode if needed */ 1255 if (data->type == it8716 || data->type == it8718) { 1256 - tmp = it87_read_value(client, IT87_REG_FAN_16BIT); 1257 if (~tmp & 0x07 & data->has_fan) { 1258 - dev_dbg(&client->dev, 1259 "Setting fan1-3 to 16-bit mode\n"); 1260 - it87_write_value(client, IT87_REG_FAN_16BIT, 1261 tmp | 0x07); 1262 } 1263 } ··· 1267 for (i = 0; i < 3; i++) { 1268 if (data->fan_main_ctrl & (1 << i)) { 1269 /* pwm mode */ 1270 - tmp = it87_read_value(client, IT87_REG_PWM(i)); 1271 if (tmp & 0x80) { 1272 /* automatic pwm - not yet implemented, but 1273 * leave the settings made by the BIOS alone ··· 1281 } 1282 1283 /* Start monitoring */ 1284 - it87_write_value(client, IT87_REG_CONFIG, 1285 - (it87_read_value(client, IT87_REG_CONFIG) & 0x36) 1286 | (update_vbat ? 0x41 : 0x01)); 1287 } 1288 1289 static struct it87_data *it87_update_device(struct device *dev) 1290 { 1291 - struct i2c_client *client = to_i2c_client(dev); 1292 - struct it87_data *data = i2c_get_clientdata(client); 1293 int i; 1294 1295 mutex_lock(&data->update_lock); ··· 1299 if (update_vbat) { 1300 /* Cleared after each update, so reenable. Value 1301 returned by this read will be previous value */ 1302 - it87_write_value(client, IT87_REG_CONFIG, 1303 - it87_read_value(client, IT87_REG_CONFIG) | 0x40); 1304 } 1305 for (i = 0; i <= 7; i++) { 1306 data->in[i] = 1307 - it87_read_value(client, IT87_REG_VIN(i)); 1308 data->in_min[i] = 1309 - it87_read_value(client, IT87_REG_VIN_MIN(i)); 1310 data->in_max[i] = 1311 - it87_read_value(client, IT87_REG_VIN_MAX(i)); 1312 } 1313 /* in8 (battery) has no limit registers */ 1314 data->in[8] = 1315 - it87_read_value(client, IT87_REG_VIN(8)); 1316 1317 for (i = 0; i < 3; i++) { 1318 /* Skip disabled fans */ ··· 1320 continue; 1321 1322 data->fan_min[i] = 1323 - it87_read_value(client, IT87_REG_FAN_MIN(i)); 1324 - data->fan[i] = it87_read_value(client, 1325 IT87_REG_FAN(i)); 1326 /* Add high byte if in 16-bit mode */ 1327 if (data->type == it8716 || data->type == it8718) { 1328 - data->fan[i] |= it87_read_value(client, 1329 IT87_REG_FANX(i)) << 8; 1330 - data->fan_min[i] |= it87_read_value(client, 1331 IT87_REG_FANX_MIN(i)) << 8; 1332 } 1333 } 1334 for (i = 0; i < 3; i++) { 1335 data->temp[i] = 1336 - it87_read_value(client, IT87_REG_TEMP(i)); 1337 data->temp_high[i] = 1338 - it87_read_value(client, IT87_REG_TEMP_HIGH(i)); 1339 data->temp_low[i] = 1340 - it87_read_value(client, IT87_REG_TEMP_LOW(i)); 1341 } 1342 1343 /* Newer chips don't have clock dividers */ 1344 if ((data->has_fan & 0x07) && data->type != it8716 1345 && data->type != it8718) { 1346 - i = it87_read_value(client, IT87_REG_FAN_DIV); 1347 data->fan_div[0] = i & 0x07; 1348 data->fan_div[1] = (i >> 3) & 0x07; 1349 data->fan_div[2] = (i & 0x40) ? 3 : 1; 1350 } 1351 1352 data->alarms = 1353 - it87_read_value(client, IT87_REG_ALARM1) | 1354 - (it87_read_value(client, IT87_REG_ALARM2) << 8) | 1355 - (it87_read_value(client, IT87_REG_ALARM3) << 16); 1356 - data->fan_main_ctrl = it87_read_value(client, IT87_REG_FAN_MAIN_CTRL); 1357 - data->fan_ctl = it87_read_value(client, IT87_REG_FAN_CTL); 1358 1359 - data->sensor = it87_read_value(client, IT87_REG_TEMP_ENABLE); 1360 /* The 8705 does not have VID capability */ 1361 if (data->type == it8712 || data->type == it8716) { 1362 - data->vid = it87_read_value(client, IT87_REG_VID); 1363 /* The older IT8712F revisions had only 5 VID pins, 1364 but we assume it is always safe to read 6 bits. */ 1365 data->vid &= 0x3f; ··· 1374 return data; 1375 } 1376 1377 static int __init sm_it87_init(void) 1378 { 1379 - int res; 1380 1381 - if ((res = it87_find(&isa_address))) 1382 - return res; 1383 - return i2c_isa_add_driver(&it87_isa_driver); 1384 } 1385 1386 static void __exit sm_it87_exit(void) 1387 { 1388 - i2c_isa_del_driver(&it87_isa_driver); 1389 } 1390 1391 1392 MODULE_AUTHOR("Chris Gauthron <chrisg@0-in.com>, " 1393 "Jean Delvare <khali@linux-fr.org>"); 1394 - MODULE_DESCRIPTION("IT8705F/8712F/8716F/8718F, SiS950 driver"); 1395 module_param(update_vbat, bool, 0); 1396 MODULE_PARM_DESC(update_vbat, "Update vbat if set else return powerup value"); 1397 module_param(fix_pwm_polarity, bool, 0);
··· 6 IT8712F Super I/O chip w/LPC interface 7 IT8716F Super I/O chip w/LPC interface 8 IT8718F Super I/O chip w/LPC interface 9 + IT8726F Super I/O chip w/LPC interface 10 Sis950 A clone of the IT8705F 11 12 Copyright (C) 2001 Chris Gauthron <chrisg@0-in.com> ··· 30 #include <linux/init.h> 31 #include <linux/slab.h> 32 #include <linux/jiffies.h> 33 + #include <linux/platform_device.h> 34 #include <linux/hwmon.h> 35 #include <linux/hwmon-sysfs.h> 36 #include <linux/hwmon-vid.h> ··· 40 #include <linux/sysfs.h> 41 #include <asm/io.h> 42 43 + #define DRVNAME "it87" 44 45 enum chips { it87, it8712, it8716, it8718 }; 46 + 47 + static struct platform_device *pdev; 48 49 #define REG 0x2e /* The register to read/write */ 50 #define DEV 0x07 /* Register: Logical device select */ ··· 97 #define IT8705F_DEVID 0x8705 98 #define IT8716F_DEVID 0x8716 99 #define IT8718F_DEVID 0x8718 100 + #define IT8726F_DEVID 0x8726 101 #define IT87_ACT_REG 0x30 102 #define IT87_BASE_REG 0x60 103 ··· 109 110 /* Not all BIOSes properly configure the PWM registers */ 111 static int fix_pwm_polarity; 112 113 /* Many IT87 constants specified below */ 114 ··· 214 }; 215 216 217 + struct it87_sio_data { 218 + enum chips type; 219 + /* Values read from Super-I/O config space */ 220 + u8 vid_value; 221 + }; 222 + 223 /* For each registered chip, we need to keep some data in memory. 224 The structure is dynamically allocated. */ 225 struct it87_data { 226 struct class_device *class_dev; 227 enum chips type; 228 229 + unsigned short addr; 230 + const char *name; 231 struct mutex update_lock; 232 char valid; /* !=0 if following fields are valid */ 233 unsigned long last_updated; /* In jiffies */ ··· 245 }; 246 247 248 + static int it87_probe(struct platform_device *pdev); 249 + static int it87_remove(struct platform_device *pdev); 250 251 + static int it87_read_value(struct it87_data *data, u8 reg); 252 + static void it87_write_value(struct it87_data *data, u8 reg, u8 value); 253 static struct it87_data *it87_update_device(struct device *dev); 254 + static int it87_check_pwm(struct device *dev); 255 + static void it87_init_device(struct platform_device *pdev); 256 257 258 + static struct platform_driver it87_driver = { 259 .driver = { 260 .owner = THIS_MODULE, 261 + .name = DRVNAME, 262 }, 263 + .probe = it87_probe, 264 + .remove = __devexit_p(it87_remove), 265 }; 266 267 static ssize_t show_in(struct device *dev, struct device_attribute *attr, 268 char *buf) ··· 301 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); 302 int nr = sensor_attr->index; 303 304 + struct it87_data *data = dev_get_drvdata(dev); 305 unsigned long val = simple_strtoul(buf, NULL, 10); 306 307 mutex_lock(&data->update_lock); 308 data->in_min[nr] = IN_TO_REG(val); 309 + it87_write_value(data, IT87_REG_VIN_MIN(nr), 310 data->in_min[nr]); 311 mutex_unlock(&data->update_lock); 312 return count; ··· 318 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); 319 int nr = sensor_attr->index; 320 321 + struct it87_data *data = dev_get_drvdata(dev); 322 unsigned long val = simple_strtoul(buf, NULL, 10); 323 324 mutex_lock(&data->update_lock); 325 data->in_max[nr] = IN_TO_REG(val); 326 + it87_write_value(data, IT87_REG_VIN_MAX(nr), 327 data->in_max[nr]); 328 mutex_unlock(&data->update_lock); 329 return count; ··· 392 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); 393 int nr = sensor_attr->index; 394 395 + struct it87_data *data = dev_get_drvdata(dev); 396 int val = simple_strtol(buf, NULL, 10); 397 398 mutex_lock(&data->update_lock); 399 data->temp_high[nr] = TEMP_TO_REG(val); 400 + it87_write_value(data, IT87_REG_TEMP_HIGH(nr), data->temp_high[nr]); 401 mutex_unlock(&data->update_lock); 402 return count; 403 } ··· 408 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); 409 int nr = sensor_attr->index; 410 411 + struct it87_data *data = dev_get_drvdata(dev); 412 int val = simple_strtol(buf, NULL, 10); 413 414 mutex_lock(&data->update_lock); 415 data->temp_low[nr] = TEMP_TO_REG(val); 416 + it87_write_value(data, IT87_REG_TEMP_LOW(nr), data->temp_low[nr]); 417 mutex_unlock(&data->update_lock); 418 return count; 419 } ··· 451 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); 452 int nr = sensor_attr->index; 453 454 + struct it87_data *data = dev_get_drvdata(dev); 455 int val = simple_strtol(buf, NULL, 10); 456 457 mutex_lock(&data->update_lock); ··· 468 mutex_unlock(&data->update_lock); 469 return -EINVAL; 470 } 471 + it87_write_value(data, IT87_REG_TEMP_ENABLE, data->sensor); 472 mutex_unlock(&data->update_lock); 473 return count; 474 } ··· 542 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); 543 int nr = sensor_attr->index; 544 545 + struct it87_data *data = dev_get_drvdata(dev); 546 int val = simple_strtol(buf, NULL, 10); 547 u8 reg; 548 549 mutex_lock(&data->update_lock); 550 + reg = it87_read_value(data, IT87_REG_FAN_DIV); 551 switch (nr) { 552 case 0: data->fan_div[nr] = reg & 0x07; break; 553 case 1: data->fan_div[nr] = (reg >> 3) & 0x07; break; ··· 556 } 557 558 data->fan_min[nr] = FAN_TO_REG(val, DIV_FROM_REG(data->fan_div[nr])); 559 + it87_write_value(data, IT87_REG_FAN_MIN(nr), data->fan_min[nr]); 560 mutex_unlock(&data->update_lock); 561 return count; 562 } ··· 566 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); 567 int nr = sensor_attr->index; 568 569 + struct it87_data *data = dev_get_drvdata(dev); 570 unsigned long val = simple_strtoul(buf, NULL, 10); 571 int min; 572 u8 old; 573 574 mutex_lock(&data->update_lock); 575 + old = it87_read_value(data, IT87_REG_FAN_DIV); 576 577 /* Save fan min limit */ 578 min = FAN_FROM_REG(data->fan_min[nr], DIV_FROM_REG(data->fan_div[nr])); ··· 594 val |= (data->fan_div[1] & 0x07) << 3; 595 if (data->fan_div[2] == 3) 596 val |= 0x1 << 6; 597 + it87_write_value(data, IT87_REG_FAN_DIV, val); 598 599 /* Restore fan min limit */ 600 data->fan_min[nr] = FAN_TO_REG(min, DIV_FROM_REG(data->fan_div[nr])); 601 + it87_write_value(data, IT87_REG_FAN_MIN(nr), data->fan_min[nr]); 602 603 mutex_unlock(&data->update_lock); 604 return count; ··· 609 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); 610 int nr = sensor_attr->index; 611 612 + struct it87_data *data = dev_get_drvdata(dev); 613 int val = simple_strtol(buf, NULL, 10); 614 615 mutex_lock(&data->update_lock); ··· 618 if (val == 0) { 619 int tmp; 620 /* make sure the fan is on when in on/off mode */ 621 + tmp = it87_read_value(data, IT87_REG_FAN_CTL); 622 + it87_write_value(data, IT87_REG_FAN_CTL, tmp | (1 << nr)); 623 /* set on/off mode */ 624 data->fan_main_ctrl &= ~(1 << nr); 625 + it87_write_value(data, IT87_REG_FAN_MAIN_CTRL, data->fan_main_ctrl); 626 } else if (val == 1) { 627 /* set SmartGuardian mode */ 628 data->fan_main_ctrl |= (1 << nr); 629 + it87_write_value(data, IT87_REG_FAN_MAIN_CTRL, data->fan_main_ctrl); 630 /* set saved pwm value, clear FAN_CTLX PWM mode bit */ 631 + it87_write_value(data, IT87_REG_PWM(nr), PWM_TO_REG(data->manual_pwm_ctl[nr])); 632 } else { 633 mutex_unlock(&data->update_lock); 634 return -EINVAL; ··· 643 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); 644 int nr = sensor_attr->index; 645 646 + struct it87_data *data = dev_get_drvdata(dev); 647 int val = simple_strtol(buf, NULL, 10); 648 649 if (val < 0 || val > 255) ··· 653 mutex_lock(&data->update_lock); 654 data->manual_pwm_ctl[nr] = val; 655 if (data->fan_main_ctrl & (1 << nr)) 656 + it87_write_value(data, IT87_REG_PWM(nr), PWM_TO_REG(data->manual_pwm_ctl[nr])); 657 mutex_unlock(&data->update_lock); 658 return count; 659 } 660 static ssize_t set_pwm_freq(struct device *dev, 661 struct device_attribute *attr, const char *buf, size_t count) 662 { 663 + struct it87_data *data = dev_get_drvdata(dev); 664 unsigned long val = simple_strtoul(buf, NULL, 10); 665 int i; 666 ··· 672 } 673 674 mutex_lock(&data->update_lock); 675 + data->fan_ctl = it87_read_value(data, IT87_REG_FAN_CTL) & 0x8f; 676 data->fan_ctl |= i << 4; 677 + it87_write_value(data, IT87_REG_FAN_CTL, data->fan_ctl); 678 mutex_unlock(&data->update_lock); 679 680 return count; ··· 729 { 730 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); 731 int nr = sensor_attr->index; 732 + struct it87_data *data = dev_get_drvdata(dev); 733 int val = simple_strtol(buf, NULL, 10); 734 735 mutex_lock(&data->update_lock); 736 data->fan_min[nr] = FAN16_TO_REG(val); 737 + it87_write_value(data, IT87_REG_FAN_MIN(nr), 738 data->fan_min[nr] & 0xff); 739 + it87_write_value(data, IT87_REG_FANX_MIN(nr), 740 data->fan_min[nr] >> 8); 741 mutex_unlock(&data->update_lock); 742 return count; ··· 775 static ssize_t 776 store_vrm_reg(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) 777 { 778 + struct it87_data *data = dev_get_drvdata(dev); 779 u32 val; 780 781 val = simple_strtoul(buf, NULL, 10); ··· 793 return sprintf(buf, "%ld\n", (long) vid_from_reg(data->vid, data->vrm)); 794 } 795 static DEVICE_ATTR(cpu0_vid, S_IRUGO, show_vid_reg, NULL); 796 + 797 + static ssize_t show_name(struct device *dev, struct device_attribute 798 + *devattr, char *buf) 799 + { 800 + struct it87_data *data = dev_get_drvdata(dev); 801 + return sprintf(buf, "%s\n", data->name); 802 + } 803 + static DEVICE_ATTR(name, S_IRUGO, show_name, NULL); 804 805 static struct attribute *it87_attributes[] = { 806 &sensor_dev_attr_in0_input.dev_attr.attr, ··· 835 &sensor_dev_attr_temp3_type.dev_attr.attr, 836 837 &dev_attr_alarms.attr, 838 + &dev_attr_name.attr, 839 NULL 840 }; 841 ··· 877 }; 878 879 /* SuperIO detection - will change isa_address if a chip is found */ 880 + static int __init it87_find(unsigned short *address, 881 + struct it87_sio_data *sio_data) 882 { 883 int err = -ENODEV; 884 + u16 chip_type; 885 886 superio_enter(); 887 chip_type = superio_inw(DEVID); 888 + 889 + switch (chip_type) { 890 + case IT8705F_DEVID: 891 + sio_data->type = it87; 892 + break; 893 + case IT8712F_DEVID: 894 + sio_data->type = it8712; 895 + break; 896 + case IT8716F_DEVID: 897 + case IT8726F_DEVID: 898 + sio_data->type = it8716; 899 + break; 900 + case IT8718F_DEVID: 901 + sio_data->type = it8718; 902 + break; 903 + case 0xffff: /* No device at all */ 904 + goto exit; 905 + default: 906 + pr_debug(DRVNAME ": Unsupported chip (DEVID=0x%x)\n", 907 + chip_type); 908 + goto exit; 909 + } 910 911 superio_select(PME); 912 if (!(superio_inb(IT87_ACT_REG) & 0x01)) { ··· 911 912 superio_select(GPIO); 913 if (chip_type == it8718) 914 + sio_data->vid_value = superio_inb(IT87_SIO_VID_REG); 915 916 reg = superio_inb(IT87_SIO_PINX2_REG); 917 if (reg & (1 << 0)) ··· 925 return err; 926 } 927 928 + static int __devinit it87_probe(struct platform_device *pdev) 929 { 930 struct it87_data *data; 931 + struct resource *res; 932 + struct device *dev = &pdev->dev; 933 + struct it87_sio_data *sio_data = dev->platform_data; 934 int err = 0; 935 int enable_pwm_interface; 936 + static const char *names[] = { 937 + "it87", 938 + "it8712", 939 + "it8716", 940 + "it8718", 941 + }; 942 943 + res = platform_get_resource(pdev, IORESOURCE_IO, 0); 944 + if (!request_region(res->start, IT87_EXTENT, DRVNAME)) { 945 + dev_err(dev, "Failed to request region 0x%lx-0x%lx\n", 946 + (unsigned long)res->start, 947 + (unsigned long)(res->start + IT87_EXTENT - 1)); 948 err = -EBUSY; 949 goto ERROR0; 950 } ··· 946 goto ERROR1; 947 } 948 949 + data->addr = res->start; 950 + data->type = sio_data->type; 951 + data->name = names[sio_data->type]; 952 953 /* Now, we do the remaining detection. */ 954 + if ((it87_read_value(data, IT87_REG_CONFIG) & 0x80) 955 + || it87_read_value(data, IT87_REG_CHIPID) != 0x90) { 956 err = -ENODEV; 957 goto ERROR2; 958 } 959 960 + platform_set_drvdata(pdev, data); 961 962 mutex_init(&data->update_lock); 963 964 /* Check PWM configuration */ 965 + enable_pwm_interface = it87_check_pwm(dev); 966 967 /* Initialize the IT87 chip */ 968 + it87_init_device(pdev); 969 970 /* Register sysfs hooks */ 971 + if ((err = sysfs_create_group(&dev->kobj, &it87_group))) 972 + goto ERROR2; 973 974 /* Do not create fan files for disabled fans */ 975 if (data->type == it8716 || data->type == it8718) { 976 /* 16-bit tachometers */ 977 if (data->has_fan & (1 << 0)) { 978 + if ((err = device_create_file(dev, 979 &sensor_dev_attr_fan1_input16.dev_attr)) 980 + || (err = device_create_file(dev, 981 &sensor_dev_attr_fan1_min16.dev_attr))) 982 goto ERROR4; 983 } 984 if (data->has_fan & (1 << 1)) { 985 + if ((err = device_create_file(dev, 986 &sensor_dev_attr_fan2_input16.dev_attr)) 987 + || (err = device_create_file(dev, 988 &sensor_dev_attr_fan2_min16.dev_attr))) 989 goto ERROR4; 990 } 991 if (data->has_fan & (1 << 2)) { 992 + if ((err = device_create_file(dev, 993 &sensor_dev_attr_fan3_input16.dev_attr)) 994 + || (err = device_create_file(dev, 995 &sensor_dev_attr_fan3_min16.dev_attr))) 996 goto ERROR4; 997 } 998 } else { 999 /* 8-bit tachometers with clock divider */ 1000 if (data->has_fan & (1 << 0)) { 1001 + if ((err = device_create_file(dev, 1002 &sensor_dev_attr_fan1_input.dev_attr)) 1003 + || (err = device_create_file(dev, 1004 &sensor_dev_attr_fan1_min.dev_attr)) 1005 + || (err = device_create_file(dev, 1006 &sensor_dev_attr_fan1_div.dev_attr))) 1007 goto ERROR4; 1008 } 1009 if (data->has_fan & (1 << 1)) { 1010 + if ((err = device_create_file(dev, 1011 &sensor_dev_attr_fan2_input.dev_attr)) 1012 + || (err = device_create_file(dev, 1013 &sensor_dev_attr_fan2_min.dev_attr)) 1014 + || (err = device_create_file(dev, 1015 &sensor_dev_attr_fan2_div.dev_attr))) 1016 goto ERROR4; 1017 } 1018 if (data->has_fan & (1 << 2)) { 1019 + if ((err = device_create_file(dev, 1020 &sensor_dev_attr_fan3_input.dev_attr)) 1021 + || (err = device_create_file(dev, 1022 &sensor_dev_attr_fan3_min.dev_attr)) 1023 + || (err = device_create_file(dev, 1024 &sensor_dev_attr_fan3_div.dev_attr))) 1025 goto ERROR4; 1026 } 1027 } 1028 1029 if (enable_pwm_interface) { 1030 + if ((err = device_create_file(dev, 1031 &sensor_dev_attr_pwm1_enable.dev_attr)) 1032 + || (err = device_create_file(dev, 1033 &sensor_dev_attr_pwm2_enable.dev_attr)) 1034 + || (err = device_create_file(dev, 1035 &sensor_dev_attr_pwm3_enable.dev_attr)) 1036 + || (err = device_create_file(dev, 1037 &sensor_dev_attr_pwm1.dev_attr)) 1038 + || (err = device_create_file(dev, 1039 &sensor_dev_attr_pwm2.dev_attr)) 1040 + || (err = device_create_file(dev, 1041 &sensor_dev_attr_pwm3.dev_attr)) 1042 + || (err = device_create_file(dev, 1043 &dev_attr_pwm1_freq)) 1044 + || (err = device_create_file(dev, 1045 &dev_attr_pwm2_freq)) 1046 + || (err = device_create_file(dev, 1047 &dev_attr_pwm3_freq))) 1048 goto ERROR4; 1049 } ··· 1077 || data->type == it8718) { 1078 data->vrm = vid_which_vrm(); 1079 /* VID reading from Super-I/O config space if available */ 1080 + data->vid = sio_data->vid_value; 1081 + if ((err = device_create_file(dev, 1082 &dev_attr_vrm)) 1083 + || (err = device_create_file(dev, 1084 &dev_attr_cpu0_vid))) 1085 goto ERROR4; 1086 } 1087 1088 + data->class_dev = hwmon_device_register(dev); 1089 if (IS_ERR(data->class_dev)) { 1090 err = PTR_ERR(data->class_dev); 1091 goto ERROR4; ··· 1094 return 0; 1095 1096 ERROR4: 1097 + sysfs_remove_group(&dev->kobj, &it87_group); 1098 + sysfs_remove_group(&dev->kobj, &it87_group_opt); 1099 ERROR2: 1100 + platform_set_drvdata(pdev, NULL); 1101 kfree(data); 1102 ERROR1: 1103 + release_region(res->start, IT87_EXTENT); 1104 ERROR0: 1105 return err; 1106 } 1107 1108 + static int __devexit it87_remove(struct platform_device *pdev) 1109 { 1110 + struct it87_data *data = platform_get_drvdata(pdev); 1111 1112 hwmon_device_unregister(data->class_dev); 1113 + sysfs_remove_group(&pdev->dev.kobj, &it87_group); 1114 + sysfs_remove_group(&pdev->dev.kobj, &it87_group_opt); 1115 1116 + release_region(data->addr, IT87_EXTENT); 1117 + platform_set_drvdata(pdev, NULL); 1118 kfree(data); 1119 1120 return 0; ··· 1127 /* Must be called with data->update_lock held, except during initialization. 1128 We ignore the IT87 BUSY flag at this moment - it could lead to deadlocks, 1129 would slow down the IT87 access and should not be necessary. */ 1130 + static int it87_read_value(struct it87_data *data, u8 reg) 1131 { 1132 + outb_p(reg, data->addr + IT87_ADDR_REG_OFFSET); 1133 + return inb_p(data->addr + IT87_DATA_REG_OFFSET); 1134 } 1135 1136 /* Must be called with data->update_lock held, except during initialization. 1137 We ignore the IT87 BUSY flag at this moment - it could lead to deadlocks, 1138 would slow down the IT87 access and should not be necessary. */ 1139 + static void it87_write_value(struct it87_data *data, u8 reg, u8 value) 1140 { 1141 + outb_p(reg, data->addr + IT87_ADDR_REG_OFFSET); 1142 + outb_p(value, data->addr + IT87_DATA_REG_OFFSET); 1143 } 1144 1145 /* Return 1 if and only if the PWM interface is safe to use */ 1146 + static int __devinit it87_check_pwm(struct device *dev) 1147 { 1148 + struct it87_data *data = dev_get_drvdata(dev); 1149 /* Some BIOSes fail to correctly configure the IT87 fans. All fans off 1150 * and polarity set to active low is sign that this is the case so we 1151 * disable pwm control to protect the user. */ 1152 + int tmp = it87_read_value(data, IT87_REG_FAN_CTL); 1153 if ((tmp & 0x87) == 0) { 1154 if (fix_pwm_polarity) { 1155 /* The user asks us to attempt a chip reconfiguration. ··· 1158 u8 pwm[3]; 1159 1160 for (i = 0; i < 3; i++) 1161 + pwm[i] = it87_read_value(data, 1162 IT87_REG_PWM(i)); 1163 1164 /* If any fan is in automatic pwm mode, the polarity ··· 1166 * better don't change anything (but still disable the 1167 * PWM interface). */ 1168 if (!((pwm[0] | pwm[1] | pwm[2]) & 0x80)) { 1169 + dev_info(dev, "Reconfiguring PWM to " 1170 "active high polarity\n"); 1171 + it87_write_value(data, IT87_REG_FAN_CTL, 1172 tmp | 0x87); 1173 for (i = 0; i < 3; i++) 1174 + it87_write_value(data, 1175 IT87_REG_PWM(i), 1176 0x7f & ~pwm[i]); 1177 return 1; 1178 } 1179 1180 + dev_info(dev, "PWM configuration is " 1181 "too broken to be fixed\n"); 1182 } 1183 1184 + dev_info(dev, "Detected broken BIOS " 1185 "defaults, disabling PWM interface\n"); 1186 return 0; 1187 } else if (fix_pwm_polarity) { 1188 + dev_info(dev, "PWM configuration looks " 1189 "sane, won't touch\n"); 1190 } 1191 ··· 1193 } 1194 1195 /* Called when we have found a new IT87. */ 1196 + static void __devinit it87_init_device(struct platform_device *pdev) 1197 { 1198 + struct it87_data *data = platform_get_drvdata(pdev); 1199 int tmp, i; 1200 1201 /* initialize to sane defaults: ··· 1214 * means -1 degree C, which surprisingly doesn't trigger an alarm, 1215 * but is still confusing, so change to 127 degrees C. */ 1216 for (i = 0; i < 8; i++) { 1217 + tmp = it87_read_value(data, IT87_REG_VIN_MIN(i)); 1218 if (tmp == 0xff) 1219 + it87_write_value(data, IT87_REG_VIN_MIN(i), 0); 1220 } 1221 for (i = 0; i < 3; i++) { 1222 + tmp = it87_read_value(data, IT87_REG_TEMP_HIGH(i)); 1223 if (tmp == 0xff) 1224 + it87_write_value(data, IT87_REG_TEMP_HIGH(i), 127); 1225 } 1226 1227 /* Check if temperature channnels are reset manually or by some reason */ 1228 + tmp = it87_read_value(data, IT87_REG_TEMP_ENABLE); 1229 if ((tmp & 0x3f) == 0) { 1230 /* Temp1,Temp3=thermistor; Temp2=thermal diode */ 1231 tmp = (tmp & 0xc0) | 0x2a; 1232 + it87_write_value(data, IT87_REG_TEMP_ENABLE, tmp); 1233 } 1234 data->sensor = tmp; 1235 1236 /* Check if voltage monitors are reset manually or by some reason */ 1237 + tmp = it87_read_value(data, IT87_REG_VIN_ENABLE); 1238 if ((tmp & 0xff) == 0) { 1239 /* Enable all voltage monitors */ 1240 + it87_write_value(data, IT87_REG_VIN_ENABLE, 0xff); 1241 } 1242 1243 /* Check if tachometers are reset manually or by some reason */ 1244 + data->fan_main_ctrl = it87_read_value(data, IT87_REG_FAN_MAIN_CTRL); 1245 if ((data->fan_main_ctrl & 0x70) == 0) { 1246 /* Enable all fan tachometers */ 1247 data->fan_main_ctrl |= 0x70; 1248 + it87_write_value(data, IT87_REG_FAN_MAIN_CTRL, data->fan_main_ctrl); 1249 } 1250 data->has_fan = (data->fan_main_ctrl >> 4) & 0x07; 1251 1252 /* Set tachometers to 16-bit mode if needed */ 1253 if (data->type == it8716 || data->type == it8718) { 1254 + tmp = it87_read_value(data, IT87_REG_FAN_16BIT); 1255 if (~tmp & 0x07 & data->has_fan) { 1256 + dev_dbg(&pdev->dev, 1257 "Setting fan1-3 to 16-bit mode\n"); 1258 + it87_write_value(data, IT87_REG_FAN_16BIT, 1259 tmp | 0x07); 1260 } 1261 } ··· 1265 for (i = 0; i < 3; i++) { 1266 if (data->fan_main_ctrl & (1 << i)) { 1267 /* pwm mode */ 1268 + tmp = it87_read_value(data, IT87_REG_PWM(i)); 1269 if (tmp & 0x80) { 1270 /* automatic pwm - not yet implemented, but 1271 * leave the settings made by the BIOS alone ··· 1279 } 1280 1281 /* Start monitoring */ 1282 + it87_write_value(data, IT87_REG_CONFIG, 1283 + (it87_read_value(data, IT87_REG_CONFIG) & 0x36) 1284 | (update_vbat ? 0x41 : 0x01)); 1285 } 1286 1287 static struct it87_data *it87_update_device(struct device *dev) 1288 { 1289 + struct it87_data *data = dev_get_drvdata(dev); 1290 int i; 1291 1292 mutex_lock(&data->update_lock); ··· 1298 if (update_vbat) { 1299 /* Cleared after each update, so reenable. Value 1300 returned by this read will be previous value */ 1301 + it87_write_value(data, IT87_REG_CONFIG, 1302 + it87_read_value(data, IT87_REG_CONFIG) | 0x40); 1303 } 1304 for (i = 0; i <= 7; i++) { 1305 data->in[i] = 1306 + it87_read_value(data, IT87_REG_VIN(i)); 1307 data->in_min[i] = 1308 + it87_read_value(data, IT87_REG_VIN_MIN(i)); 1309 data->in_max[i] = 1310 + it87_read_value(data, IT87_REG_VIN_MAX(i)); 1311 } 1312 /* in8 (battery) has no limit registers */ 1313 data->in[8] = 1314 + it87_read_value(data, IT87_REG_VIN(8)); 1315 1316 for (i = 0; i < 3; i++) { 1317 /* Skip disabled fans */ ··· 1319 continue; 1320 1321 data->fan_min[i] = 1322 + it87_read_value(data, IT87_REG_FAN_MIN(i)); 1323 + data->fan[i] = it87_read_value(data, 1324 IT87_REG_FAN(i)); 1325 /* Add high byte if in 16-bit mode */ 1326 if (data->type == it8716 || data->type == it8718) { 1327 + data->fan[i] |= it87_read_value(data, 1328 IT87_REG_FANX(i)) << 8; 1329 + data->fan_min[i] |= it87_read_value(data, 1330 IT87_REG_FANX_MIN(i)) << 8; 1331 } 1332 } 1333 for (i = 0; i < 3; i++) { 1334 data->temp[i] = 1335 + it87_read_value(data, IT87_REG_TEMP(i)); 1336 data->temp_high[i] = 1337 + it87_read_value(data, IT87_REG_TEMP_HIGH(i)); 1338 data->temp_low[i] = 1339 + it87_read_value(data, IT87_REG_TEMP_LOW(i)); 1340 } 1341 1342 /* Newer chips don't have clock dividers */ 1343 if ((data->has_fan & 0x07) && data->type != it8716 1344 && data->type != it8718) { 1345 + i = it87_read_value(data, IT87_REG_FAN_DIV); 1346 data->fan_div[0] = i & 0x07; 1347 data->fan_div[1] = (i >> 3) & 0x07; 1348 data->fan_div[2] = (i & 0x40) ? 3 : 1; 1349 } 1350 1351 data->alarms = 1352 + it87_read_value(data, IT87_REG_ALARM1) | 1353 + (it87_read_value(data, IT87_REG_ALARM2) << 8) | 1354 + (it87_read_value(data, IT87_REG_ALARM3) << 16); 1355 + data->fan_main_ctrl = it87_read_value(data, 1356 + IT87_REG_FAN_MAIN_CTRL); 1357 + data->fan_ctl = it87_read_value(data, IT87_REG_FAN_CTL); 1358 1359 + data->sensor = it87_read_value(data, IT87_REG_TEMP_ENABLE); 1360 /* The 8705 does not have VID capability */ 1361 if (data->type == it8712 || data->type == it8716) { 1362 + data->vid = it87_read_value(data, IT87_REG_VID); 1363 /* The older IT8712F revisions had only 5 VID pins, 1364 but we assume it is always safe to read 6 bits. */ 1365 data->vid &= 0x3f; ··· 1372 return data; 1373 } 1374 1375 + static int __init it87_device_add(unsigned short address, 1376 + const struct it87_sio_data *sio_data) 1377 + { 1378 + struct resource res = { 1379 + .start = address , 1380 + .end = address + IT87_EXTENT - 1, 1381 + .name = DRVNAME, 1382 + .flags = IORESOURCE_IO, 1383 + }; 1384 + int err; 1385 + 1386 + pdev = platform_device_alloc(DRVNAME, address); 1387 + if (!pdev) { 1388 + err = -ENOMEM; 1389 + printk(KERN_ERR DRVNAME ": Device allocation failed\n"); 1390 + goto exit; 1391 + } 1392 + 1393 + err = platform_device_add_resources(pdev, &res, 1); 1394 + if (err) { 1395 + printk(KERN_ERR DRVNAME ": Device resource addition failed " 1396 + "(%d)\n", err); 1397 + goto exit_device_put; 1398 + } 1399 + 1400 + err = platform_device_add_data(pdev, sio_data, 1401 + sizeof(struct it87_sio_data)); 1402 + if (err) { 1403 + printk(KERN_ERR DRVNAME ": Platform data allocation failed\n"); 1404 + goto exit_device_put; 1405 + } 1406 + 1407 + err = platform_device_add(pdev); 1408 + if (err) { 1409 + printk(KERN_ERR DRVNAME ": Device addition failed (%d)\n", 1410 + err); 1411 + goto exit_device_put; 1412 + } 1413 + 1414 + return 0; 1415 + 1416 + exit_device_put: 1417 + platform_device_put(pdev); 1418 + exit: 1419 + return err; 1420 + } 1421 + 1422 static int __init sm_it87_init(void) 1423 { 1424 + int err; 1425 + unsigned short isa_address=0; 1426 + struct it87_sio_data sio_data; 1427 1428 + err = it87_find(&isa_address, &sio_data); 1429 + if (err) 1430 + return err; 1431 + err = platform_driver_register(&it87_driver); 1432 + if (err) 1433 + return err; 1434 + 1435 + err = it87_device_add(isa_address, &sio_data); 1436 + if (err){ 1437 + platform_driver_unregister(&it87_driver); 1438 + return err; 1439 + } 1440 + 1441 + return 0; 1442 } 1443 1444 static void __exit sm_it87_exit(void) 1445 { 1446 + platform_device_unregister(pdev); 1447 + platform_driver_unregister(&it87_driver); 1448 } 1449 1450 1451 MODULE_AUTHOR("Chris Gauthron <chrisg@0-in.com>, " 1452 "Jean Delvare <khali@linux-fr.org>"); 1453 + MODULE_DESCRIPTION("IT8705F/8712F/8716F/8718F/8726F, SiS950 driver"); 1454 module_param(update_vbat, bool, 0); 1455 MODULE_PARM_DESC(update_vbat, "Update vbat if set else return powerup value"); 1456 module_param(fix_pwm_polarity, bool, 0);
+2 -2
drivers/hwmon/lm63.c
··· 364 /* Individual alarm files */ 365 static SENSOR_DEVICE_ATTR(fan1_min_alarm, S_IRUGO, show_alarm, NULL, 0); 366 static SENSOR_DEVICE_ATTR(temp2_crit_alarm, S_IRUGO, show_alarm, NULL, 1); 367 - static SENSOR_DEVICE_ATTR(temp2_input_fault, S_IRUGO, show_alarm, NULL, 2); 368 static SENSOR_DEVICE_ATTR(temp2_min_alarm, S_IRUGO, show_alarm, NULL, 3); 369 static SENSOR_DEVICE_ATTR(temp2_max_alarm, S_IRUGO, show_alarm, NULL, 4); 370 static SENSOR_DEVICE_ATTR(temp1_max_alarm, S_IRUGO, show_alarm, NULL, 6); ··· 383 &dev_attr_temp2_crit_hyst.attr, 384 385 &sensor_dev_attr_temp2_crit_alarm.dev_attr.attr, 386 - &sensor_dev_attr_temp2_input_fault.dev_attr.attr, 387 &sensor_dev_attr_temp2_min_alarm.dev_attr.attr, 388 &sensor_dev_attr_temp2_max_alarm.dev_attr.attr, 389 &sensor_dev_attr_temp1_max_alarm.dev_attr.attr,
··· 364 /* Individual alarm files */ 365 static SENSOR_DEVICE_ATTR(fan1_min_alarm, S_IRUGO, show_alarm, NULL, 0); 366 static SENSOR_DEVICE_ATTR(temp2_crit_alarm, S_IRUGO, show_alarm, NULL, 1); 367 + static SENSOR_DEVICE_ATTR(temp2_fault, S_IRUGO, show_alarm, NULL, 2); 368 static SENSOR_DEVICE_ATTR(temp2_min_alarm, S_IRUGO, show_alarm, NULL, 3); 369 static SENSOR_DEVICE_ATTR(temp2_max_alarm, S_IRUGO, show_alarm, NULL, 4); 370 static SENSOR_DEVICE_ATTR(temp1_max_alarm, S_IRUGO, show_alarm, NULL, 6); ··· 383 &dev_attr_temp2_crit_hyst.attr, 384 385 &sensor_dev_attr_temp2_crit_alarm.dev_attr.attr, 386 + &sensor_dev_attr_temp2_fault.dev_attr.attr, 387 &sensor_dev_attr_temp2_min_alarm.dev_attr.attr, 388 &sensor_dev_attr_temp2_max_alarm.dev_attr.attr, 389 &sensor_dev_attr_temp1_max_alarm.dev_attr.attr,
+6 -6
drivers/hwmon/lm83.c
··· 223 /* Individual alarm files */ 224 static SENSOR_DEVICE_ATTR(temp1_crit_alarm, S_IRUGO, show_alarm, NULL, 0); 225 static SENSOR_DEVICE_ATTR(temp3_crit_alarm, S_IRUGO, show_alarm, NULL, 1); 226 - static SENSOR_DEVICE_ATTR(temp3_input_fault, S_IRUGO, show_alarm, NULL, 2); 227 static SENSOR_DEVICE_ATTR(temp3_max_alarm, S_IRUGO, show_alarm, NULL, 4); 228 static SENSOR_DEVICE_ATTR(temp1_max_alarm, S_IRUGO, show_alarm, NULL, 6); 229 static SENSOR_DEVICE_ATTR(temp2_crit_alarm, S_IRUGO, show_alarm, NULL, 8); 230 static SENSOR_DEVICE_ATTR(temp4_crit_alarm, S_IRUGO, show_alarm, NULL, 9); 231 - static SENSOR_DEVICE_ATTR(temp4_input_fault, S_IRUGO, show_alarm, NULL, 10); 232 static SENSOR_DEVICE_ATTR(temp4_max_alarm, S_IRUGO, show_alarm, NULL, 12); 233 - static SENSOR_DEVICE_ATTR(temp2_input_fault, S_IRUGO, show_alarm, NULL, 13); 234 static SENSOR_DEVICE_ATTR(temp2_max_alarm, S_IRUGO, show_alarm, NULL, 15); 235 /* Raw alarm file for compatibility */ 236 static DEVICE_ATTR(alarms, S_IRUGO, show_alarms, NULL); ··· 245 246 &sensor_dev_attr_temp1_crit_alarm.dev_attr.attr, 247 &sensor_dev_attr_temp3_crit_alarm.dev_attr.attr, 248 - &sensor_dev_attr_temp3_input_fault.dev_attr.attr, 249 &sensor_dev_attr_temp3_max_alarm.dev_attr.attr, 250 &sensor_dev_attr_temp1_max_alarm.dev_attr.attr, 251 &dev_attr_alarms.attr, ··· 266 267 &sensor_dev_attr_temp2_crit_alarm.dev_attr.attr, 268 &sensor_dev_attr_temp4_crit_alarm.dev_attr.attr, 269 - &sensor_dev_attr_temp4_input_fault.dev_attr.attr, 270 &sensor_dev_attr_temp4_max_alarm.dev_attr.attr, 271 - &sensor_dev_attr_temp2_input_fault.dev_attr.attr, 272 &sensor_dev_attr_temp2_max_alarm.dev_attr.attr, 273 NULL 274 };
··· 223 /* Individual alarm files */ 224 static SENSOR_DEVICE_ATTR(temp1_crit_alarm, S_IRUGO, show_alarm, NULL, 0); 225 static SENSOR_DEVICE_ATTR(temp3_crit_alarm, S_IRUGO, show_alarm, NULL, 1); 226 + static SENSOR_DEVICE_ATTR(temp3_fault, S_IRUGO, show_alarm, NULL, 2); 227 static SENSOR_DEVICE_ATTR(temp3_max_alarm, S_IRUGO, show_alarm, NULL, 4); 228 static SENSOR_DEVICE_ATTR(temp1_max_alarm, S_IRUGO, show_alarm, NULL, 6); 229 static SENSOR_DEVICE_ATTR(temp2_crit_alarm, S_IRUGO, show_alarm, NULL, 8); 230 static SENSOR_DEVICE_ATTR(temp4_crit_alarm, S_IRUGO, show_alarm, NULL, 9); 231 + static SENSOR_DEVICE_ATTR(temp4_fault, S_IRUGO, show_alarm, NULL, 10); 232 static SENSOR_DEVICE_ATTR(temp4_max_alarm, S_IRUGO, show_alarm, NULL, 12); 233 + static SENSOR_DEVICE_ATTR(temp2_fault, S_IRUGO, show_alarm, NULL, 13); 234 static SENSOR_DEVICE_ATTR(temp2_max_alarm, S_IRUGO, show_alarm, NULL, 15); 235 /* Raw alarm file for compatibility */ 236 static DEVICE_ATTR(alarms, S_IRUGO, show_alarms, NULL); ··· 245 246 &sensor_dev_attr_temp1_crit_alarm.dev_attr.attr, 247 &sensor_dev_attr_temp3_crit_alarm.dev_attr.attr, 248 + &sensor_dev_attr_temp3_fault.dev_attr.attr, 249 &sensor_dev_attr_temp3_max_alarm.dev_attr.attr, 250 &sensor_dev_attr_temp1_max_alarm.dev_attr.attr, 251 &dev_attr_alarms.attr, ··· 266 267 &sensor_dev_attr_temp2_crit_alarm.dev_attr.attr, 268 &sensor_dev_attr_temp4_crit_alarm.dev_attr.attr, 269 + &sensor_dev_attr_temp4_fault.dev_attr.attr, 270 &sensor_dev_attr_temp4_max_alarm.dev_attr.attr, 271 + &sensor_dev_attr_temp2_fault.dev_attr.attr, 272 &sensor_dev_attr_temp2_max_alarm.dev_attr.attr, 273 NULL 274 };
+59 -19
drivers/hwmon/lm90.c
··· 43 * variants. The extra address and features of the MAX6659 are not 44 * supported by this driver. 45 * 46 * This driver also supports the ADT7461 chip from Analog Devices but 47 * only in its "compatability mode". If an ADT7461 chip is found but 48 * is configured in non-compatible mode (where its temperature ··· 91 /* 92 * Addresses to scan 93 * Address is fully defined internally and cannot be changed except for 94 - * MAX6659. 95 * LM86, LM89, LM90, LM99, ADM1032, ADM1032-1, ADT7461, MAX6657 and MAX6658 96 * have address 0x4c. 97 * ADM1032-2, ADT7461-2, LM89-1, and LM99-1 have address 0x4d. 98 * MAX6659 can have address 0x4c, 0x4d or 0x4e (unsupported). 99 */ 100 101 - static unsigned short normal_i2c[] = { 0x4c, 0x4d, I2C_CLIENT_END }; 102 103 /* 104 * Insmod parameters 105 */ 106 107 - I2C_CLIENT_INSMOD_6(lm90, adm1032, lm99, lm86, max6657, adt7461); 108 109 /* 110 * The LM90 registers ··· 371 /* Individual alarm files */ 372 static SENSOR_DEVICE_ATTR(temp1_crit_alarm, S_IRUGO, show_alarm, NULL, 0); 373 static SENSOR_DEVICE_ATTR(temp2_crit_alarm, S_IRUGO, show_alarm, NULL, 1); 374 - static SENSOR_DEVICE_ATTR(temp2_input_fault, S_IRUGO, show_alarm, NULL, 2); 375 static SENSOR_DEVICE_ATTR(temp2_min_alarm, S_IRUGO, show_alarm, NULL, 3); 376 static SENSOR_DEVICE_ATTR(temp2_max_alarm, S_IRUGO, show_alarm, NULL, 4); 377 static SENSOR_DEVICE_ATTR(temp1_min_alarm, S_IRUGO, show_alarm, NULL, 5); ··· 393 394 &sensor_dev_attr_temp1_crit_alarm.dev_attr.attr, 395 &sensor_dev_attr_temp2_crit_alarm.dev_attr.attr, 396 - &sensor_dev_attr_temp2_input_fault.dev_attr.attr, 397 &sensor_dev_attr_temp2_min_alarm.dev_attr.attr, 398 &sensor_dev_attr_temp2_max_alarm.dev_attr.attr, 399 &sensor_dev_attr_temp1_min_alarm.dev_attr.attr, ··· 441 */ 442 443 /* The ADM1032 supports PEC but not on write byte transactions, so we need 444 - to explicitely ask for a transaction without PEC. */ 445 static inline s32 adm1032_write_byte(struct i2c_client *client, u8 value) 446 { 447 return i2c_smbus_xfer(client->adapter, client->addr, ··· 537 &reg_convrate) < 0) 538 goto exit_free; 539 540 - if (man_id == 0x01) { /* National Semiconductor */ 541 u8 reg_config2; 542 543 if (lm90_read_reg(new_client, LM90_REG_R_CONFIG2, ··· 561 } 562 } 563 } else 564 - if (man_id == 0x41) { /* Analog Devices */ 565 if ((chip_id & 0xF0) == 0x40 /* ADM1032 */ 566 && (reg_config1 & 0x3F) == 0x00 567 && reg_convrate <= 0x0A) { ··· 576 } else 577 if (man_id == 0x4D) { /* Maxim */ 578 /* 579 - * The Maxim variants do NOT have a chip_id register. 580 - * Reading from that address will return the last read 581 - * value, which in our case is those of the man_id 582 - * register. Likewise, the config1 register seems to 583 - * lack a low nibble, so the value will be those of the 584 - * previous read, so in our case those of the man_id 585 - * register. 586 */ 587 if (chip_id == man_id 588 && (reg_config1 & 0x1F) == (man_id & 0x0F) 589 && reg_convrate <= 0x09) { 590 kind = max6657; 591 } 592 } 593 ··· 625 name = "lm86"; 626 } else if (kind == max6657) { 627 name = "max6657"; 628 } else if (kind == adt7461) { 629 name = "adt7461"; 630 } ··· 674 675 static void lm90_init_client(struct i2c_client *client) 676 { 677 - u8 config; 678 679 /* 680 * Start the conversions. ··· 686 dev_warn(&client->dev, "Initialization failed!\n"); 687 return; 688 } 689 - if (config & 0x40) 690 - i2c_smbus_write_byte_data(client, LM90_REG_W_CONFIG1, 691 - config & 0xBF); /* run */ 692 } 693 694 static int lm90_detach_client(struct i2c_client *client)
··· 43 * variants. The extra address and features of the MAX6659 are not 44 * supported by this driver. 45 * 46 + * This driver also supports the MAX6680 and MAX6681, two other sensor 47 + * chips made by Maxim. These are quite similar to the other Maxim 48 + * chips. Complete datasheet can be obtained at: 49 + * http://www.maxim-ic.com/quick_view2.cfm/qv_pk/3370 50 + * The MAX6680 and MAX6681 only differ in the pinout so they can be 51 + * treated identically. 52 + * 53 * This driver also supports the ADT7461 chip from Analog Devices but 54 * only in its "compatability mode". If an ADT7461 chip is found but 55 * is configured in non-compatible mode (where its temperature ··· 84 /* 85 * Addresses to scan 86 * Address is fully defined internally and cannot be changed except for 87 + * MAX6659, MAX6680 and MAX6681. 88 * LM86, LM89, LM90, LM99, ADM1032, ADM1032-1, ADT7461, MAX6657 and MAX6658 89 * have address 0x4c. 90 * ADM1032-2, ADT7461-2, LM89-1, and LM99-1 have address 0x4d. 91 * MAX6659 can have address 0x4c, 0x4d or 0x4e (unsupported). 92 + * MAX6680 and MAX6681 can have address 0x18, 0x19, 0x1a, 0x29, 0x2a, 0x2b, 93 + * 0x4c, 0x4d or 0x4e. 94 */ 95 96 + static unsigned short normal_i2c[] = { 0x18, 0x19, 0x1a, 97 + 0x29, 0x2a, 0x2b, 98 + 0x4c, 0x4d, 0x4e, 99 + I2C_CLIENT_END }; 100 101 /* 102 * Insmod parameters 103 */ 104 105 + I2C_CLIENT_INSMOD_7(lm90, adm1032, lm99, lm86, max6657, adt7461, max6680); 106 107 /* 108 * The LM90 registers ··· 359 /* Individual alarm files */ 360 static SENSOR_DEVICE_ATTR(temp1_crit_alarm, S_IRUGO, show_alarm, NULL, 0); 361 static SENSOR_DEVICE_ATTR(temp2_crit_alarm, S_IRUGO, show_alarm, NULL, 1); 362 + static SENSOR_DEVICE_ATTR(temp2_fault, S_IRUGO, show_alarm, NULL, 2); 363 static SENSOR_DEVICE_ATTR(temp2_min_alarm, S_IRUGO, show_alarm, NULL, 3); 364 static SENSOR_DEVICE_ATTR(temp2_max_alarm, S_IRUGO, show_alarm, NULL, 4); 365 static SENSOR_DEVICE_ATTR(temp1_min_alarm, S_IRUGO, show_alarm, NULL, 5); ··· 381 382 &sensor_dev_attr_temp1_crit_alarm.dev_attr.attr, 383 &sensor_dev_attr_temp2_crit_alarm.dev_attr.attr, 384 + &sensor_dev_attr_temp2_fault.dev_attr.attr, 385 &sensor_dev_attr_temp2_min_alarm.dev_attr.attr, 386 &sensor_dev_attr_temp2_max_alarm.dev_attr.attr, 387 &sensor_dev_attr_temp1_min_alarm.dev_attr.attr, ··· 429 */ 430 431 /* The ADM1032 supports PEC but not on write byte transactions, so we need 432 + to explicitly ask for a transaction without PEC. */ 433 static inline s32 adm1032_write_byte(struct i2c_client *client, u8 value) 434 { 435 return i2c_smbus_xfer(client->adapter, client->addr, ··· 525 &reg_convrate) < 0) 526 goto exit_free; 527 528 + if ((address == 0x4C || address == 0x4D) 529 + && man_id == 0x01) { /* National Semiconductor */ 530 u8 reg_config2; 531 532 if (lm90_read_reg(new_client, LM90_REG_R_CONFIG2, ··· 548 } 549 } 550 } else 551 + if ((address == 0x4C || address == 0x4D) 552 + && man_id == 0x41) { /* Analog Devices */ 553 if ((chip_id & 0xF0) == 0x40 /* ADM1032 */ 554 && (reg_config1 & 0x3F) == 0x00 555 && reg_convrate <= 0x0A) { ··· 562 } else 563 if (man_id == 0x4D) { /* Maxim */ 564 /* 565 + * The MAX6657, MAX6658 and MAX6659 do NOT have a 566 + * chip_id register. Reading from that address will 567 + * return the last read value, which in our case is 568 + * those of the man_id register. Likewise, the config1 569 + * register seems to lack a low nibble, so the value 570 + * will be those of the previous read, so in our case 571 + * those of the man_id register. 572 */ 573 if (chip_id == man_id 574 + && (address == 0x4F || address == 0x4D) 575 && (reg_config1 & 0x1F) == (man_id & 0x0F) 576 && reg_convrate <= 0x09) { 577 kind = max6657; 578 + } else 579 + /* The chip_id register of the MAX6680 and MAX6681 580 + * holds the revision of the chip. 581 + * the lowest bit of the config1 register is unused 582 + * and should return zero when read, so should the 583 + * second to last bit of config1 (software reset) 584 + */ 585 + if (chip_id == 0x01 586 + && (reg_config1 & 0x03) == 0x00 587 + && reg_convrate <= 0x07) { 588 + kind = max6680; 589 } 590 } 591 ··· 599 name = "lm86"; 600 } else if (kind == max6657) { 601 name = "max6657"; 602 + } else if (kind == max6680) { 603 + name = "max6680"; 604 } else if (kind == adt7461) { 605 name = "adt7461"; 606 } ··· 646 647 static void lm90_init_client(struct i2c_client *client) 648 { 649 + u8 config, config_orig; 650 + struct lm90_data *data = i2c_get_clientdata(client); 651 652 /* 653 * Start the conversions. ··· 657 dev_warn(&client->dev, "Initialization failed!\n"); 658 return; 659 } 660 + config_orig = config; 661 + 662 + /* 663 + * Put MAX6680/MAX8881 into extended resolution (bit 0x10, 664 + * 0.125 degree resolution) and range (0x08, extend range 665 + * to -64 degree) mode for the remote temperature sensor. 666 + */ 667 + if (data->kind == max6680) { 668 + config |= 0x18; 669 + } 670 + 671 + config &= 0xBF; /* run */ 672 + if (config != config_orig) /* Only write if changed */ 673 + i2c_smbus_write_byte_data(client, LM90_REG_W_CONFIG1, config); 674 } 675 676 static int lm90_detach_client(struct i2c_client *client)
+2655
drivers/hwmon/lm93.c
···
··· 1 + /* 2 + lm93.c - Part of lm_sensors, Linux kernel modules for hardware monitoring 3 + 4 + Author/Maintainer: Mark M. Hoffman <mhoffman@lightlink.com> 5 + Copyright (c) 2004 Utilitek Systems, Inc. 6 + 7 + derived in part from lm78.c: 8 + Copyright (c) 1998, 1999 Frodo Looijaard <frodol@dds.nl> 9 + 10 + derived in part from lm85.c: 11 + Copyright (c) 2002, 2003 Philip Pokorny <ppokorny@penguincomputing.com> 12 + Copyright (c) 2003 Margit Schubert-While <margitsw@t-online.de> 13 + 14 + derived in part from w83l785ts.c: 15 + Copyright (c) 2003-2004 Jean Delvare <khali@linux-fr.org> 16 + 17 + Ported to Linux 2.6 by Eric J. Bowersox <ericb@aspsys.com> 18 + Copyright (c) 2005 Aspen Systems, Inc. 19 + 20 + Adapted to 2.6.20 by Carsten Emde <cbe@osadl.org> 21 + Copyright (c) 2006 Carsten Emde, Open Source Automation Development Lab 22 + 23 + Modified for mainline integration by Hans J. Koch <hjk@linutronix.de> 24 + Copyright (c) 2007 Hans J. Koch, Linutronix GmbH 25 + 26 + This program is free software; you can redistribute it and/or modify 27 + it under the terms of the GNU General Public License as published by 28 + the Free Software Foundation; either version 2 of the License, or 29 + (at your option) any later version. 30 + 31 + This program is distributed in the hope that it will be useful, 32 + but WITHOUT ANY WARRANTY; without even the implied warranty of 33 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 34 + GNU General Public License for more details. 35 + 36 + You should have received a copy of the GNU General Public License 37 + along with this program; if not, write to the Free Software 38 + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 39 + */ 40 + 41 + #include <linux/module.h> 42 + #include <linux/init.h> 43 + #include <linux/slab.h> 44 + #include <linux/i2c.h> 45 + #include <linux/hwmon.h> 46 + #include <linux/hwmon-sysfs.h> 47 + #include <linux/hwmon-vid.h> 48 + #include <linux/err.h> 49 + #include <linux/delay.h> 50 + 51 + /* LM93 REGISTER ADDRESSES */ 52 + 53 + /* miscellaneous */ 54 + #define LM93_REG_MFR_ID 0x3e 55 + #define LM93_REG_VER 0x3f 56 + #define LM93_REG_STATUS_CONTROL 0xe2 57 + #define LM93_REG_CONFIG 0xe3 58 + #define LM93_REG_SLEEP_CONTROL 0xe4 59 + 60 + /* alarm values start here */ 61 + #define LM93_REG_HOST_ERROR_1 0x48 62 + 63 + /* voltage inputs: in1-in16 (nr => 0-15) */ 64 + #define LM93_REG_IN(nr) (0x56 + (nr)) 65 + #define LM93_REG_IN_MIN(nr) (0x90 + (nr) * 2) 66 + #define LM93_REG_IN_MAX(nr) (0x91 + (nr) * 2) 67 + 68 + /* temperature inputs: temp1-temp4 (nr => 0-3) */ 69 + #define LM93_REG_TEMP(nr) (0x50 + (nr)) 70 + #define LM93_REG_TEMP_MIN(nr) (0x78 + (nr) * 2) 71 + #define LM93_REG_TEMP_MAX(nr) (0x79 + (nr) * 2) 72 + 73 + /* temp[1-4]_auto_boost (nr => 0-3) */ 74 + #define LM93_REG_BOOST(nr) (0x80 + (nr)) 75 + 76 + /* #PROCHOT inputs: prochot1-prochot2 (nr => 0-1) */ 77 + #define LM93_REG_PROCHOT_CUR(nr) (0x67 + (nr) * 2) 78 + #define LM93_REG_PROCHOT_AVG(nr) (0x68 + (nr) * 2) 79 + #define LM93_REG_PROCHOT_MAX(nr) (0xb0 + (nr)) 80 + 81 + /* fan tach inputs: fan1-fan4 (nr => 0-3) */ 82 + #define LM93_REG_FAN(nr) (0x6e + (nr) * 2) 83 + #define LM93_REG_FAN_MIN(nr) (0xb4 + (nr) * 2) 84 + 85 + /* pwm outputs: pwm1-pwm2 (nr => 0-1, reg => 0-3) */ 86 + #define LM93_REG_PWM_CTL(nr,reg) (0xc8 + (reg) + (nr) * 4) 87 + #define LM93_PWM_CTL1 0x0 88 + #define LM93_PWM_CTL2 0x1 89 + #define LM93_PWM_CTL3 0x2 90 + #define LM93_PWM_CTL4 0x3 91 + 92 + /* GPIO input state */ 93 + #define LM93_REG_GPI 0x6b 94 + 95 + /* vid inputs: vid1-vid2 (nr => 0-1) */ 96 + #define LM93_REG_VID(nr) (0x6c + (nr)) 97 + 98 + /* vccp1 & vccp2: VID relative inputs (nr => 0-1) */ 99 + #define LM93_REG_VCCP_LIMIT_OFF(nr) (0xb2 + (nr)) 100 + 101 + /* temp[1-4]_auto_boost_hyst */ 102 + #define LM93_REG_BOOST_HYST_12 0xc0 103 + #define LM93_REG_BOOST_HYST_34 0xc1 104 + #define LM93_REG_BOOST_HYST(nr) (0xc0 + (nr)/2) 105 + 106 + /* temp[1-4]_auto_pwm_[min|hyst] */ 107 + #define LM93_REG_PWM_MIN_HYST_12 0xc3 108 + #define LM93_REG_PWM_MIN_HYST_34 0xc4 109 + #define LM93_REG_PWM_MIN_HYST(nr) (0xc3 + (nr)/2) 110 + 111 + /* prochot_override & prochot_interval */ 112 + #define LM93_REG_PROCHOT_OVERRIDE 0xc6 113 + #define LM93_REG_PROCHOT_INTERVAL 0xc7 114 + 115 + /* temp[1-4]_auto_base (nr => 0-3) */ 116 + #define LM93_REG_TEMP_BASE(nr) (0xd0 + (nr)) 117 + 118 + /* temp[1-4]_auto_offsets (step => 0-11) */ 119 + #define LM93_REG_TEMP_OFFSET(step) (0xd4 + (step)) 120 + 121 + /* #PROCHOT & #VRDHOT PWM ramp control */ 122 + #define LM93_REG_PWM_RAMP_CTL 0xbf 123 + 124 + /* miscellaneous */ 125 + #define LM93_REG_SFC1 0xbc 126 + #define LM93_REG_SFC2 0xbd 127 + #define LM93_REG_GPI_VID_CTL 0xbe 128 + #define LM93_REG_SF_TACH_TO_PWM 0xe0 129 + 130 + /* error masks */ 131 + #define LM93_REG_GPI_ERR_MASK 0xec 132 + #define LM93_REG_MISC_ERR_MASK 0xed 133 + 134 + /* LM93 REGISTER VALUES */ 135 + #define LM93_MFR_ID 0x73 136 + #define LM93_MFR_ID_PROTOTYPE 0x72 137 + 138 + /* SMBus capabilities */ 139 + #define LM93_SMBUS_FUNC_FULL (I2C_FUNC_SMBUS_BYTE_DATA | \ 140 + I2C_FUNC_SMBUS_WORD_DATA | I2C_FUNC_SMBUS_BLOCK_DATA) 141 + #define LM93_SMBUS_FUNC_MIN (I2C_FUNC_SMBUS_BYTE_DATA | \ 142 + I2C_FUNC_SMBUS_WORD_DATA) 143 + 144 + /* Addresses to scan */ 145 + static unsigned short normal_i2c[] = { 0x2c, 0x2d, 0x2e, I2C_CLIENT_END }; 146 + 147 + /* Insmod parameters */ 148 + I2C_CLIENT_INSMOD_1(lm93); 149 + 150 + static int disable_block; 151 + module_param(disable_block, bool, 0); 152 + MODULE_PARM_DESC(disable_block, 153 + "Set to non-zero to disable SMBus block data transactions."); 154 + 155 + static int init; 156 + module_param(init, bool, 0); 157 + MODULE_PARM_DESC(init, "Set to non-zero to force chip initialization."); 158 + 159 + static int vccp_limit_type[2] = {0,0}; 160 + module_param_array(vccp_limit_type, int, NULL, 0); 161 + MODULE_PARM_DESC(vccp_limit_type, "Configures in7 and in8 limit modes."); 162 + 163 + static int vid_agtl; 164 + module_param(vid_agtl, int, 0); 165 + MODULE_PARM_DESC(vid_agtl, "Configures VID pin input thresholds."); 166 + 167 + /* Driver data */ 168 + static struct i2c_driver lm93_driver; 169 + 170 + /* LM93 BLOCK READ COMMANDS */ 171 + static const struct { u8 cmd; u8 len; } lm93_block_read_cmds[12] = { 172 + { 0xf2, 8 }, 173 + { 0xf3, 8 }, 174 + { 0xf4, 6 }, 175 + { 0xf5, 16 }, 176 + { 0xf6, 4 }, 177 + { 0xf7, 8 }, 178 + { 0xf8, 12 }, 179 + { 0xf9, 32 }, 180 + { 0xfa, 8 }, 181 + { 0xfb, 8 }, 182 + { 0xfc, 16 }, 183 + { 0xfd, 9 }, 184 + }; 185 + 186 + /* ALARMS: SYSCTL format described further below 187 + REG: 64 bits in 8 registers, as immediately below */ 188 + struct block1_t { 189 + u8 host_status_1; 190 + u8 host_status_2; 191 + u8 host_status_3; 192 + u8 host_status_4; 193 + u8 p1_prochot_status; 194 + u8 p2_prochot_status; 195 + u8 gpi_status; 196 + u8 fan_status; 197 + }; 198 + 199 + /* 200 + * Client-specific data 201 + */ 202 + struct lm93_data { 203 + struct i2c_client client; 204 + struct class_device *class_dev; 205 + 206 + struct mutex update_lock; 207 + unsigned long last_updated; /* In jiffies */ 208 + 209 + /* client update function */ 210 + void (*update)(struct lm93_data *, struct i2c_client *); 211 + 212 + char valid; /* !=0 if following fields are valid */ 213 + 214 + /* register values, arranged by block read groups */ 215 + struct block1_t block1; 216 + 217 + /* temp1 - temp4: unfiltered readings 218 + temp1 - temp2: filtered readings */ 219 + u8 block2[6]; 220 + 221 + /* vin1 - vin16: readings */ 222 + u8 block3[16]; 223 + 224 + /* prochot1 - prochot2: readings */ 225 + struct { 226 + u8 cur; 227 + u8 avg; 228 + } block4[2]; 229 + 230 + /* fan counts 1-4 => 14-bits, LE, *left* justified */ 231 + u16 block5[4]; 232 + 233 + /* block6 has a lot of data we don't need */ 234 + struct { 235 + u8 min; 236 + u8 max; 237 + } temp_lim[3]; 238 + 239 + /* vin1 - vin16: low and high limits */ 240 + struct { 241 + u8 min; 242 + u8 max; 243 + } block7[16]; 244 + 245 + /* fan count limits 1-4 => same format as block5 */ 246 + u16 block8[4]; 247 + 248 + /* pwm control registers (2 pwms, 4 regs) */ 249 + u8 block9[2][4]; 250 + 251 + /* auto/pwm base temp and offset temp registers */ 252 + struct { 253 + u8 base[4]; 254 + u8 offset[12]; 255 + } block10; 256 + 257 + /* master config register */ 258 + u8 config; 259 + 260 + /* VID1 & VID2 => register format, 6-bits, right justified */ 261 + u8 vid[2]; 262 + 263 + /* prochot1 - prochot2: limits */ 264 + u8 prochot_max[2]; 265 + 266 + /* vccp1 & vccp2 (in7 & in8): VID relative limits (register format) */ 267 + u8 vccp_limits[2]; 268 + 269 + /* GPIO input state (register format, i.e. inverted) */ 270 + u8 gpi; 271 + 272 + /* #PROCHOT override (register format) */ 273 + u8 prochot_override; 274 + 275 + /* #PROCHOT intervals (register format) */ 276 + u8 prochot_interval; 277 + 278 + /* Fan Boost Temperatures (register format) */ 279 + u8 boost[4]; 280 + 281 + /* Fan Boost Hysteresis (register format) */ 282 + u8 boost_hyst[2]; 283 + 284 + /* Temperature Zone Min. PWM & Hysteresis (register format) */ 285 + u8 auto_pwm_min_hyst[2]; 286 + 287 + /* #PROCHOT & #VRDHOT PWM Ramp Control */ 288 + u8 pwm_ramp_ctl; 289 + 290 + /* miscellaneous setup regs */ 291 + u8 sfc1; 292 + u8 sfc2; 293 + u8 sf_tach_to_pwm; 294 + 295 + /* The two PWM CTL2 registers can read something other than what was 296 + last written for the OVR_DC field (duty cycle override). So, we 297 + save the user-commanded value here. */ 298 + u8 pwm_override[2]; 299 + }; 300 + 301 + /* VID: mV 302 + REG: 6-bits, right justified, *always* using Intel VRM/VRD 10 */ 303 + static int LM93_VID_FROM_REG(u8 reg) 304 + { 305 + return vid_from_reg((reg & 0x3f), 100); 306 + } 307 + 308 + /* min, max, and nominal register values, per channel (u8) */ 309 + static const u8 lm93_vin_reg_min[16] = { 310 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 311 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xae, 312 + }; 313 + static const u8 lm93_vin_reg_max[16] = { 314 + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 315 + 0xff, 0xfa, 0xff, 0xff, 0xff, 0xff, 0xff, 0xd1, 316 + }; 317 + /* Values from the datasheet. They're here for documentation only. 318 + static const u8 lm93_vin_reg_nom[16] = { 319 + 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 320 + 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0x40, 0xc0, 321 + }; 322 + */ 323 + 324 + /* min, max, and nominal voltage readings, per channel (mV)*/ 325 + static const unsigned long lm93_vin_val_min[16] = { 326 + 0, 0, 0, 0, 0, 0, 0, 0, 327 + 0, 0, 0, 0, 0, 0, 0, 3000, 328 + }; 329 + 330 + static const unsigned long lm93_vin_val_max[16] = { 331 + 1236, 1236, 1236, 1600, 2000, 2000, 1600, 1600, 332 + 4400, 6500, 3333, 2625, 1312, 1312, 1236, 3600, 333 + }; 334 + /* Values from the datasheet. They're here for documentation only. 335 + static const unsigned long lm93_vin_val_nom[16] = { 336 + 927, 927, 927, 1200, 1500, 1500, 1200, 1200, 337 + 3300, 5000, 2500, 1969, 984, 984, 309, 3300, 338 + }; 339 + */ 340 + 341 + static unsigned LM93_IN_FROM_REG(int nr, u8 reg) 342 + { 343 + const long uV_max = lm93_vin_val_max[nr] * 1000; 344 + const long uV_min = lm93_vin_val_min[nr] * 1000; 345 + 346 + const long slope = (uV_max - uV_min) / 347 + (lm93_vin_reg_max[nr] - lm93_vin_reg_min[nr]); 348 + const long intercept = uV_min - slope * lm93_vin_reg_min[nr]; 349 + 350 + return (slope * reg + intercept + 500) / 1000; 351 + } 352 + 353 + /* IN: mV, limits determined by channel nr 354 + REG: scaling determined by channel nr */ 355 + static u8 LM93_IN_TO_REG(int nr, unsigned val) 356 + { 357 + /* range limit */ 358 + const long mV = SENSORS_LIMIT(val, 359 + lm93_vin_val_min[nr], lm93_vin_val_max[nr]); 360 + 361 + /* try not to lose too much precision here */ 362 + const long uV = mV * 1000; 363 + const long uV_max = lm93_vin_val_max[nr] * 1000; 364 + const long uV_min = lm93_vin_val_min[nr] * 1000; 365 + 366 + /* convert */ 367 + const long slope = (uV_max - uV_min) / 368 + (lm93_vin_reg_max[nr] - lm93_vin_reg_min[nr]); 369 + const long intercept = uV_min - slope * lm93_vin_reg_min[nr]; 370 + 371 + u8 result = ((uV - intercept + (slope/2)) / slope); 372 + result = SENSORS_LIMIT(result, 373 + lm93_vin_reg_min[nr], lm93_vin_reg_max[nr]); 374 + return result; 375 + } 376 + 377 + /* vid in mV, upper == 0 indicates low limit, otherwise upper limit */ 378 + static unsigned LM93_IN_REL_FROM_REG(u8 reg, int upper, int vid) 379 + { 380 + const long uV_offset = upper ? (((reg >> 4 & 0x0f) + 1) * 12500) : 381 + (((reg >> 0 & 0x0f) + 1) * -25000); 382 + const long uV_vid = vid * 1000; 383 + return (uV_vid + uV_offset + 5000) / 10000; 384 + } 385 + 386 + #define LM93_IN_MIN_FROM_REG(reg,vid) LM93_IN_REL_FROM_REG(reg,0,vid) 387 + #define LM93_IN_MAX_FROM_REG(reg,vid) LM93_IN_REL_FROM_REG(reg,1,vid) 388 + 389 + /* vid in mV , upper == 0 indicates low limit, otherwise upper limit 390 + upper also determines which nibble of the register is returned 391 + (the other nibble will be 0x0) */ 392 + static u8 LM93_IN_REL_TO_REG(unsigned val, int upper, int vid) 393 + { 394 + long uV_offset = vid * 1000 - val * 10000; 395 + if (upper) { 396 + uV_offset = SENSORS_LIMIT(uV_offset, 12500, 200000); 397 + return (u8)((uV_offset / 12500 - 1) << 4); 398 + } else { 399 + uV_offset = SENSORS_LIMIT(uV_offset, -400000, -25000); 400 + return (u8)((uV_offset / -25000 - 1) << 0); 401 + } 402 + } 403 + 404 + /* TEMP: 1/1000 degrees C (-128C to +127C) 405 + REG: 1C/bit, two's complement */ 406 + static int LM93_TEMP_FROM_REG(u8 reg) 407 + { 408 + return (s8)reg * 1000; 409 + } 410 + 411 + #define LM93_TEMP_MIN (-128000) 412 + #define LM93_TEMP_MAX ( 127000) 413 + 414 + /* TEMP: 1/1000 degrees C (-128C to +127C) 415 + REG: 1C/bit, two's complement */ 416 + static u8 LM93_TEMP_TO_REG(int temp) 417 + { 418 + int ntemp = SENSORS_LIMIT(temp, LM93_TEMP_MIN, LM93_TEMP_MAX); 419 + ntemp += (ntemp<0 ? -500 : 500); 420 + return (u8)(ntemp / 1000); 421 + } 422 + 423 + /* Determine 4-bit temperature offset resolution */ 424 + static int LM93_TEMP_OFFSET_MODE_FROM_REG(u8 sfc2, int nr) 425 + { 426 + /* mode: 0 => 1C/bit, nonzero => 0.5C/bit */ 427 + return sfc2 & (nr < 2 ? 0x10 : 0x20); 428 + } 429 + 430 + /* This function is common to all 4-bit temperature offsets 431 + reg is 4 bits right justified 432 + mode 0 => 1C/bit, mode !0 => 0.5C/bit */ 433 + static int LM93_TEMP_OFFSET_FROM_REG(u8 reg, int mode) 434 + { 435 + return (reg & 0x0f) * (mode ? 5 : 10); 436 + } 437 + 438 + #define LM93_TEMP_OFFSET_MIN ( 0) 439 + #define LM93_TEMP_OFFSET_MAX0 (150) 440 + #define LM93_TEMP_OFFSET_MAX1 ( 75) 441 + 442 + /* This function is common to all 4-bit temperature offsets 443 + returns 4 bits right justified 444 + mode 0 => 1C/bit, mode !0 => 0.5C/bit */ 445 + static u8 LM93_TEMP_OFFSET_TO_REG(int off, int mode) 446 + { 447 + int factor = mode ? 5 : 10; 448 + 449 + off = SENSORS_LIMIT(off, LM93_TEMP_OFFSET_MIN, 450 + mode ? LM93_TEMP_OFFSET_MAX1 : LM93_TEMP_OFFSET_MAX0); 451 + return (u8)((off + factor/2) / factor); 452 + } 453 + 454 + /* 0 <= nr <= 3 */ 455 + static int LM93_TEMP_AUTO_OFFSET_FROM_REG(u8 reg, int nr, int mode) 456 + { 457 + /* temp1-temp2 (nr=0,1) use lower nibble */ 458 + if (nr < 2) 459 + return LM93_TEMP_OFFSET_FROM_REG(reg & 0x0f, mode); 460 + 461 + /* temp3-temp4 (nr=2,3) use upper nibble */ 462 + else 463 + return LM93_TEMP_OFFSET_FROM_REG(reg >> 4 & 0x0f, mode); 464 + } 465 + 466 + /* TEMP: 1/10 degrees C (0C to +15C (mode 0) or +7.5C (mode non-zero)) 467 + REG: 1.0C/bit (mode 0) or 0.5C/bit (mode non-zero) 468 + 0 <= nr <= 3 */ 469 + static u8 LM93_TEMP_AUTO_OFFSET_TO_REG(u8 old, int off, int nr, int mode) 470 + { 471 + u8 new = LM93_TEMP_OFFSET_TO_REG(off, mode); 472 + 473 + /* temp1-temp2 (nr=0,1) use lower nibble */ 474 + if (nr < 2) 475 + return (old & 0xf0) | (new & 0x0f); 476 + 477 + /* temp3-temp4 (nr=2,3) use upper nibble */ 478 + else 479 + return (new << 4 & 0xf0) | (old & 0x0f); 480 + } 481 + 482 + static int LM93_AUTO_BOOST_HYST_FROM_REGS(struct lm93_data *data, int nr, 483 + int mode) 484 + { 485 + u8 reg; 486 + 487 + switch (nr) { 488 + case 0: 489 + reg = data->boost_hyst[0] & 0x0f; 490 + break; 491 + case 1: 492 + reg = data->boost_hyst[0] >> 4 & 0x0f; 493 + break; 494 + case 2: 495 + reg = data->boost_hyst[1] & 0x0f; 496 + break; 497 + case 3: 498 + default: 499 + reg = data->boost_hyst[1] >> 4 & 0x0f; 500 + break; 501 + } 502 + 503 + return LM93_TEMP_FROM_REG(data->boost[nr]) - 504 + LM93_TEMP_OFFSET_FROM_REG(reg, mode); 505 + } 506 + 507 + static u8 LM93_AUTO_BOOST_HYST_TO_REG(struct lm93_data *data, long hyst, 508 + int nr, int mode) 509 + { 510 + u8 reg = LM93_TEMP_OFFSET_TO_REG( 511 + (LM93_TEMP_FROM_REG(data->boost[nr]) - hyst), mode); 512 + 513 + switch (nr) { 514 + case 0: 515 + reg = (data->boost_hyst[0] & 0xf0) | (reg & 0x0f); 516 + break; 517 + case 1: 518 + reg = (reg << 4 & 0xf0) | (data->boost_hyst[0] & 0x0f); 519 + break; 520 + case 2: 521 + reg = (data->boost_hyst[1] & 0xf0) | (reg & 0x0f); 522 + break; 523 + case 3: 524 + default: 525 + reg = (reg << 4 & 0xf0) | (data->boost_hyst[1] & 0x0f); 526 + break; 527 + } 528 + 529 + return reg; 530 + } 531 + 532 + /* PWM: 0-255 per sensors documentation 533 + REG: 0-13 as mapped below... right justified */ 534 + typedef enum { LM93_PWM_MAP_HI_FREQ, LM93_PWM_MAP_LO_FREQ } pwm_freq_t; 535 + static int lm93_pwm_map[2][16] = { 536 + { 537 + 0x00, /* 0.00% */ 0x40, /* 25.00% */ 538 + 0x50, /* 31.25% */ 0x60, /* 37.50% */ 539 + 0x70, /* 43.75% */ 0x80, /* 50.00% */ 540 + 0x90, /* 56.25% */ 0xa0, /* 62.50% */ 541 + 0xb0, /* 68.75% */ 0xc0, /* 75.00% */ 542 + 0xd0, /* 81.25% */ 0xe0, /* 87.50% */ 543 + 0xf0, /* 93.75% */ 0xff, /* 100.00% */ 544 + 0xff, 0xff, /* 14, 15 are reserved and should never occur */ 545 + }, 546 + { 547 + 0x00, /* 0.00% */ 0x40, /* 25.00% */ 548 + 0x49, /* 28.57% */ 0x52, /* 32.14% */ 549 + 0x5b, /* 35.71% */ 0x64, /* 39.29% */ 550 + 0x6d, /* 42.86% */ 0x76, /* 46.43% */ 551 + 0x80, /* 50.00% */ 0x89, /* 53.57% */ 552 + 0x92, /* 57.14% */ 0xb6, /* 71.43% */ 553 + 0xdb, /* 85.71% */ 0xff, /* 100.00% */ 554 + 0xff, 0xff, /* 14, 15 are reserved and should never occur */ 555 + }, 556 + }; 557 + 558 + static int LM93_PWM_FROM_REG(u8 reg, pwm_freq_t freq) 559 + { 560 + return lm93_pwm_map[freq][reg & 0x0f]; 561 + } 562 + 563 + /* round up to nearest match */ 564 + static u8 LM93_PWM_TO_REG(int pwm, pwm_freq_t freq) 565 + { 566 + int i; 567 + for (i = 0; i < 13; i++) 568 + if (pwm <= lm93_pwm_map[freq][i]) 569 + break; 570 + 571 + /* can fall through with i==13 */ 572 + return (u8)i; 573 + } 574 + 575 + static int LM93_FAN_FROM_REG(u16 regs) 576 + { 577 + const u16 count = le16_to_cpu(regs) >> 2; 578 + return count==0 ? -1 : count==0x3fff ? 0: 1350000 / count; 579 + } 580 + 581 + /* 582 + * RPM: (82.5 to 1350000) 583 + * REG: 14-bits, LE, *left* justified 584 + */ 585 + static u16 LM93_FAN_TO_REG(long rpm) 586 + { 587 + u16 count, regs; 588 + 589 + if (rpm == 0) { 590 + count = 0x3fff; 591 + } else { 592 + rpm = SENSORS_LIMIT(rpm, 1, 1000000); 593 + count = SENSORS_LIMIT((1350000 + rpm) / rpm, 1, 0x3ffe); 594 + } 595 + 596 + regs = count << 2; 597 + return cpu_to_le16(regs); 598 + } 599 + 600 + /* PWM FREQ: HZ 601 + REG: 0-7 as mapped below */ 602 + static int lm93_pwm_freq_map[8] = { 603 + 22500, 96, 84, 72, 60, 48, 36, 12 604 + }; 605 + 606 + static int LM93_PWM_FREQ_FROM_REG(u8 reg) 607 + { 608 + return lm93_pwm_freq_map[reg & 0x07]; 609 + } 610 + 611 + /* round up to nearest match */ 612 + static u8 LM93_PWM_FREQ_TO_REG(int freq) 613 + { 614 + int i; 615 + for (i = 7; i > 0; i--) 616 + if (freq <= lm93_pwm_freq_map[i]) 617 + break; 618 + 619 + /* can fall through with i==0 */ 620 + return (u8)i; 621 + } 622 + 623 + /* TIME: 1/100 seconds 624 + * REG: 0-7 as mapped below */ 625 + static int lm93_spinup_time_map[8] = { 626 + 0, 10, 25, 40, 70, 100, 200, 400, 627 + }; 628 + 629 + static int LM93_SPINUP_TIME_FROM_REG(u8 reg) 630 + { 631 + return lm93_spinup_time_map[reg >> 5 & 0x07]; 632 + } 633 + 634 + /* round up to nearest match */ 635 + static u8 LM93_SPINUP_TIME_TO_REG(int time) 636 + { 637 + int i; 638 + for (i = 0; i < 7; i++) 639 + if (time <= lm93_spinup_time_map[i]) 640 + break; 641 + 642 + /* can fall through with i==8 */ 643 + return (u8)i; 644 + } 645 + 646 + #define LM93_RAMP_MIN 0 647 + #define LM93_RAMP_MAX 75 648 + 649 + static int LM93_RAMP_FROM_REG(u8 reg) 650 + { 651 + return (reg & 0x0f) * 5; 652 + } 653 + 654 + /* RAMP: 1/100 seconds 655 + REG: 50mS/bit 4-bits right justified */ 656 + static u8 LM93_RAMP_TO_REG(int ramp) 657 + { 658 + ramp = SENSORS_LIMIT(ramp, LM93_RAMP_MIN, LM93_RAMP_MAX); 659 + return (u8)((ramp + 2) / 5); 660 + } 661 + 662 + /* PROCHOT: 0-255, 0 => 0%, 255 => > 96.6% 663 + * REG: (same) */ 664 + static u8 LM93_PROCHOT_TO_REG(long prochot) 665 + { 666 + prochot = SENSORS_LIMIT(prochot, 0, 255); 667 + return (u8)prochot; 668 + } 669 + 670 + /* PROCHOT-INTERVAL: 73 - 37200 (1/100 seconds) 671 + * REG: 0-9 as mapped below */ 672 + static int lm93_interval_map[10] = { 673 + 73, 146, 290, 580, 1170, 2330, 4660, 9320, 18600, 37200, 674 + }; 675 + 676 + static int LM93_INTERVAL_FROM_REG(u8 reg) 677 + { 678 + return lm93_interval_map[reg & 0x0f]; 679 + } 680 + 681 + /* round up to nearest match */ 682 + static u8 LM93_INTERVAL_TO_REG(long interval) 683 + { 684 + int i; 685 + for (i = 0; i < 9; i++) 686 + if (interval <= lm93_interval_map[i]) 687 + break; 688 + 689 + /* can fall through with i==9 */ 690 + return (u8)i; 691 + } 692 + 693 + /* GPIO: 0-255, GPIO0 is LSB 694 + * REG: inverted */ 695 + static unsigned LM93_GPI_FROM_REG(u8 reg) 696 + { 697 + return ~reg & 0xff; 698 + } 699 + 700 + /* alarm bitmask definitions 701 + The LM93 has nearly 64 bits of error status... I've pared that down to 702 + what I think is a useful subset in order to fit it into 32 bits. 703 + 704 + Especially note that the #VRD_HOT alarms are missing because we provide 705 + that information as values in another sysfs file. 706 + 707 + If libsensors is extended to support 64 bit values, this could be revisited. 708 + */ 709 + #define LM93_ALARM_IN1 0x00000001 710 + #define LM93_ALARM_IN2 0x00000002 711 + #define LM93_ALARM_IN3 0x00000004 712 + #define LM93_ALARM_IN4 0x00000008 713 + #define LM93_ALARM_IN5 0x00000010 714 + #define LM93_ALARM_IN6 0x00000020 715 + #define LM93_ALARM_IN7 0x00000040 716 + #define LM93_ALARM_IN8 0x00000080 717 + #define LM93_ALARM_IN9 0x00000100 718 + #define LM93_ALARM_IN10 0x00000200 719 + #define LM93_ALARM_IN11 0x00000400 720 + #define LM93_ALARM_IN12 0x00000800 721 + #define LM93_ALARM_IN13 0x00001000 722 + #define LM93_ALARM_IN14 0x00002000 723 + #define LM93_ALARM_IN15 0x00004000 724 + #define LM93_ALARM_IN16 0x00008000 725 + #define LM93_ALARM_FAN1 0x00010000 726 + #define LM93_ALARM_FAN2 0x00020000 727 + #define LM93_ALARM_FAN3 0x00040000 728 + #define LM93_ALARM_FAN4 0x00080000 729 + #define LM93_ALARM_PH1_ERR 0x00100000 730 + #define LM93_ALARM_PH2_ERR 0x00200000 731 + #define LM93_ALARM_SCSI1_ERR 0x00400000 732 + #define LM93_ALARM_SCSI2_ERR 0x00800000 733 + #define LM93_ALARM_DVDDP1_ERR 0x01000000 734 + #define LM93_ALARM_DVDDP2_ERR 0x02000000 735 + #define LM93_ALARM_D1_ERR 0x04000000 736 + #define LM93_ALARM_D2_ERR 0x08000000 737 + #define LM93_ALARM_TEMP1 0x10000000 738 + #define LM93_ALARM_TEMP2 0x20000000 739 + #define LM93_ALARM_TEMP3 0x40000000 740 + 741 + static unsigned LM93_ALARMS_FROM_REG(struct block1_t b1) 742 + { 743 + unsigned result; 744 + result = b1.host_status_2 & 0x3f; 745 + 746 + if (vccp_limit_type[0]) 747 + result |= (b1.host_status_4 & 0x10) << 2; 748 + else 749 + result |= b1.host_status_2 & 0x40; 750 + 751 + if (vccp_limit_type[1]) 752 + result |= (b1.host_status_4 & 0x20) << 2; 753 + else 754 + result |= b1.host_status_2 & 0x80; 755 + 756 + result |= b1.host_status_3 << 8; 757 + result |= (b1.fan_status & 0x0f) << 16; 758 + result |= (b1.p1_prochot_status & 0x80) << 13; 759 + result |= (b1.p2_prochot_status & 0x80) << 14; 760 + result |= (b1.host_status_4 & 0xfc) << 20; 761 + result |= (b1.host_status_1 & 0x07) << 28; 762 + return result; 763 + } 764 + 765 + #define MAX_RETRIES 5 766 + 767 + static u8 lm93_read_byte(struct i2c_client *client, u8 reg) 768 + { 769 + int value, i; 770 + 771 + /* retry in case of read errors */ 772 + for (i=1; i<=MAX_RETRIES; i++) { 773 + if ((value = i2c_smbus_read_byte_data(client, reg)) >= 0) { 774 + return value; 775 + } else { 776 + dev_warn(&client->dev,"lm93: read byte data failed, " 777 + "address 0x%02x.\n", reg); 778 + mdelay(i + 3); 779 + } 780 + 781 + } 782 + 783 + /* <TODO> what to return in case of error? */ 784 + dev_err(&client->dev,"lm93: All read byte retries failed!!\n"); 785 + return 0; 786 + } 787 + 788 + static int lm93_write_byte(struct i2c_client *client, u8 reg, u8 value) 789 + { 790 + int result; 791 + 792 + /* <TODO> how to handle write errors? */ 793 + result = i2c_smbus_write_byte_data(client, reg, value); 794 + 795 + if (result < 0) 796 + dev_warn(&client->dev,"lm93: write byte data failed, " 797 + "0x%02x at address 0x%02x.\n", value, reg); 798 + 799 + return result; 800 + } 801 + 802 + static u16 lm93_read_word(struct i2c_client *client, u8 reg) 803 + { 804 + int value, i; 805 + 806 + /* retry in case of read errors */ 807 + for (i=1; i<=MAX_RETRIES; i++) { 808 + if ((value = i2c_smbus_read_word_data(client, reg)) >= 0) { 809 + return value; 810 + } else { 811 + dev_warn(&client->dev,"lm93: read word data failed, " 812 + "address 0x%02x.\n", reg); 813 + mdelay(i + 3); 814 + } 815 + 816 + } 817 + 818 + /* <TODO> what to return in case of error? */ 819 + dev_err(&client->dev,"lm93: All read word retries failed!!\n"); 820 + return 0; 821 + } 822 + 823 + static int lm93_write_word(struct i2c_client *client, u8 reg, u16 value) 824 + { 825 + int result; 826 + 827 + /* <TODO> how to handle write errors? */ 828 + result = i2c_smbus_write_word_data(client, reg, value); 829 + 830 + if (result < 0) 831 + dev_warn(&client->dev,"lm93: write word data failed, " 832 + "0x%04x at address 0x%02x.\n", value, reg); 833 + 834 + return result; 835 + } 836 + 837 + static u8 lm93_block_buffer[I2C_SMBUS_BLOCK_MAX]; 838 + 839 + /* 840 + read block data into values, retry if not expected length 841 + fbn => index to lm93_block_read_cmds table 842 + (Fixed Block Number - section 14.5.2 of LM93 datasheet) 843 + */ 844 + static void lm93_read_block(struct i2c_client *client, u8 fbn, u8 *values) 845 + { 846 + int i, result=0; 847 + 848 + for (i = 1; i <= MAX_RETRIES; i++) { 849 + result = i2c_smbus_read_block_data(client, 850 + lm93_block_read_cmds[fbn].cmd, lm93_block_buffer); 851 + 852 + if (result == lm93_block_read_cmds[fbn].len) { 853 + break; 854 + } else { 855 + dev_warn(&client->dev,"lm93: block read data failed, " 856 + "command 0x%02x.\n", 857 + lm93_block_read_cmds[fbn].cmd); 858 + mdelay(i + 3); 859 + } 860 + } 861 + 862 + if (result == lm93_block_read_cmds[fbn].len) { 863 + memcpy(values,lm93_block_buffer,lm93_block_read_cmds[fbn].len); 864 + } else { 865 + /* <TODO> what to do in case of error? */ 866 + } 867 + } 868 + 869 + static struct lm93_data *lm93_update_device(struct device *dev) 870 + { 871 + struct i2c_client *client = to_i2c_client(dev); 872 + struct lm93_data *data = i2c_get_clientdata(client); 873 + const unsigned long interval = HZ + (HZ / 2); 874 + 875 + mutex_lock(&data->update_lock); 876 + 877 + if (time_after(jiffies, data->last_updated + interval) || 878 + !data->valid) { 879 + 880 + data->update(data, client); 881 + data->last_updated = jiffies; 882 + data->valid = 1; 883 + } 884 + 885 + mutex_unlock(&data->update_lock); 886 + return data; 887 + } 888 + 889 + /* update routine for data that has no corresponding SMBus block command */ 890 + static void lm93_update_client_common(struct lm93_data *data, 891 + struct i2c_client *client) 892 + { 893 + int i; 894 + u8 *ptr; 895 + 896 + /* temp1 - temp4: limits */ 897 + for (i = 0; i < 4; i++) { 898 + data->temp_lim[i].min = 899 + lm93_read_byte(client, LM93_REG_TEMP_MIN(i)); 900 + data->temp_lim[i].max = 901 + lm93_read_byte(client, LM93_REG_TEMP_MAX(i)); 902 + } 903 + 904 + /* config register */ 905 + data->config = lm93_read_byte(client, LM93_REG_CONFIG); 906 + 907 + /* vid1 - vid2: values */ 908 + for (i = 0; i < 2; i++) 909 + data->vid[i] = lm93_read_byte(client, LM93_REG_VID(i)); 910 + 911 + /* prochot1 - prochot2: limits */ 912 + for (i = 0; i < 2; i++) 913 + data->prochot_max[i] = lm93_read_byte(client, 914 + LM93_REG_PROCHOT_MAX(i)); 915 + 916 + /* vccp1 - vccp2: VID relative limits */ 917 + for (i = 0; i < 2; i++) 918 + data->vccp_limits[i] = lm93_read_byte(client, 919 + LM93_REG_VCCP_LIMIT_OFF(i)); 920 + 921 + /* GPIO input state */ 922 + data->gpi = lm93_read_byte(client, LM93_REG_GPI); 923 + 924 + /* #PROCHOT override state */ 925 + data->prochot_override = lm93_read_byte(client, 926 + LM93_REG_PROCHOT_OVERRIDE); 927 + 928 + /* #PROCHOT intervals */ 929 + data->prochot_interval = lm93_read_byte(client, 930 + LM93_REG_PROCHOT_INTERVAL); 931 + 932 + /* Fan Boost Termperature registers */ 933 + for (i = 0; i < 4; i++) 934 + data->boost[i] = lm93_read_byte(client, LM93_REG_BOOST(i)); 935 + 936 + /* Fan Boost Temperature Hyst. registers */ 937 + data->boost_hyst[0] = lm93_read_byte(client, LM93_REG_BOOST_HYST_12); 938 + data->boost_hyst[1] = lm93_read_byte(client, LM93_REG_BOOST_HYST_34); 939 + 940 + /* Temperature Zone Min. PWM & Hysteresis registers */ 941 + data->auto_pwm_min_hyst[0] = 942 + lm93_read_byte(client, LM93_REG_PWM_MIN_HYST_12); 943 + data->auto_pwm_min_hyst[1] = 944 + lm93_read_byte(client, LM93_REG_PWM_MIN_HYST_34); 945 + 946 + /* #PROCHOT & #VRDHOT PWM Ramp Control register */ 947 + data->pwm_ramp_ctl = lm93_read_byte(client, LM93_REG_PWM_RAMP_CTL); 948 + 949 + /* misc setup registers */ 950 + data->sfc1 = lm93_read_byte(client, LM93_REG_SFC1); 951 + data->sfc2 = lm93_read_byte(client, LM93_REG_SFC2); 952 + data->sf_tach_to_pwm = lm93_read_byte(client, 953 + LM93_REG_SF_TACH_TO_PWM); 954 + 955 + /* write back alarm values to clear */ 956 + for (i = 0, ptr = (u8 *)(&data->block1); i < 8; i++) 957 + lm93_write_byte(client, LM93_REG_HOST_ERROR_1 + i, *(ptr + i)); 958 + } 959 + 960 + /* update routine which uses SMBus block data commands */ 961 + static void lm93_update_client_full(struct lm93_data *data, 962 + struct i2c_client *client) 963 + { 964 + dev_dbg(&client->dev,"starting device update (block data enabled)\n"); 965 + 966 + /* in1 - in16: values & limits */ 967 + lm93_read_block(client, 3, (u8 *)(data->block3)); 968 + lm93_read_block(client, 7, (u8 *)(data->block7)); 969 + 970 + /* temp1 - temp4: values */ 971 + lm93_read_block(client, 2, (u8 *)(data->block2)); 972 + 973 + /* prochot1 - prochot2: values */ 974 + lm93_read_block(client, 4, (u8 *)(data->block4)); 975 + 976 + /* fan1 - fan4: values & limits */ 977 + lm93_read_block(client, 5, (u8 *)(data->block5)); 978 + lm93_read_block(client, 8, (u8 *)(data->block8)); 979 + 980 + /* pmw control registers */ 981 + lm93_read_block(client, 9, (u8 *)(data->block9)); 982 + 983 + /* alarm values */ 984 + lm93_read_block(client, 1, (u8 *)(&data->block1)); 985 + 986 + /* auto/pwm registers */ 987 + lm93_read_block(client, 10, (u8 *)(&data->block10)); 988 + 989 + lm93_update_client_common(data, client); 990 + } 991 + 992 + /* update routine which uses SMBus byte/word data commands only */ 993 + static void lm93_update_client_min(struct lm93_data *data, 994 + struct i2c_client *client) 995 + { 996 + int i,j; 997 + u8 *ptr; 998 + 999 + dev_dbg(&client->dev,"starting device update (block data disabled)\n"); 1000 + 1001 + /* in1 - in16: values & limits */ 1002 + for (i = 0; i < 16; i++) { 1003 + data->block3[i] = 1004 + lm93_read_byte(client, LM93_REG_IN(i)); 1005 + data->block7[i].min = 1006 + lm93_read_byte(client, LM93_REG_IN_MIN(i)); 1007 + data->block7[i].max = 1008 + lm93_read_byte(client, LM93_REG_IN_MAX(i)); 1009 + } 1010 + 1011 + /* temp1 - temp4: values */ 1012 + for (i = 0; i < 4; i++) { 1013 + data->block2[i] = 1014 + lm93_read_byte(client, LM93_REG_TEMP(i)); 1015 + } 1016 + 1017 + /* prochot1 - prochot2: values */ 1018 + for (i = 0; i < 2; i++) { 1019 + data->block4[i].cur = 1020 + lm93_read_byte(client, LM93_REG_PROCHOT_CUR(i)); 1021 + data->block4[i].avg = 1022 + lm93_read_byte(client, LM93_REG_PROCHOT_AVG(i)); 1023 + } 1024 + 1025 + /* fan1 - fan4: values & limits */ 1026 + for (i = 0; i < 4; i++) { 1027 + data->block5[i] = 1028 + lm93_read_word(client, LM93_REG_FAN(i)); 1029 + data->block8[i] = 1030 + lm93_read_word(client, LM93_REG_FAN_MIN(i)); 1031 + } 1032 + 1033 + /* pwm control registers */ 1034 + for (i = 0; i < 2; i++) { 1035 + for (j = 0; j < 4; j++) { 1036 + data->block9[i][j] = 1037 + lm93_read_byte(client, LM93_REG_PWM_CTL(i,j)); 1038 + } 1039 + } 1040 + 1041 + /* alarm values */ 1042 + for (i = 0, ptr = (u8 *)(&data->block1); i < 8; i++) { 1043 + *(ptr + i) = 1044 + lm93_read_byte(client, LM93_REG_HOST_ERROR_1 + i); 1045 + } 1046 + 1047 + /* auto/pwm (base temp) registers */ 1048 + for (i = 0; i < 4; i++) { 1049 + data->block10.base[i] = 1050 + lm93_read_byte(client, LM93_REG_TEMP_BASE(i)); 1051 + } 1052 + 1053 + /* auto/pwm (offset temp) registers */ 1054 + for (i = 0; i < 12; i++) { 1055 + data->block10.offset[i] = 1056 + lm93_read_byte(client, LM93_REG_TEMP_OFFSET(i)); 1057 + } 1058 + 1059 + lm93_update_client_common(data, client); 1060 + } 1061 + 1062 + /* following are the sysfs callback functions */ 1063 + static ssize_t show_in(struct device *dev, struct device_attribute *attr, 1064 + char *buf) 1065 + { 1066 + int nr = (to_sensor_dev_attr(attr))->index; 1067 + 1068 + struct lm93_data *data = lm93_update_device(dev); 1069 + return sprintf(buf, "%d\n", LM93_IN_FROM_REG(nr, data->block3[nr])); 1070 + } 1071 + 1072 + static SENSOR_DEVICE_ATTR(in1_input, S_IRUGO, show_in, NULL, 0); 1073 + static SENSOR_DEVICE_ATTR(in2_input, S_IRUGO, show_in, NULL, 1); 1074 + static SENSOR_DEVICE_ATTR(in3_input, S_IRUGO, show_in, NULL, 2); 1075 + static SENSOR_DEVICE_ATTR(in4_input, S_IRUGO, show_in, NULL, 3); 1076 + static SENSOR_DEVICE_ATTR(in5_input, S_IRUGO, show_in, NULL, 4); 1077 + static SENSOR_DEVICE_ATTR(in6_input, S_IRUGO, show_in, NULL, 5); 1078 + static SENSOR_DEVICE_ATTR(in7_input, S_IRUGO, show_in, NULL, 6); 1079 + static SENSOR_DEVICE_ATTR(in8_input, S_IRUGO, show_in, NULL, 7); 1080 + static SENSOR_DEVICE_ATTR(in9_input, S_IRUGO, show_in, NULL, 8); 1081 + static SENSOR_DEVICE_ATTR(in10_input, S_IRUGO, show_in, NULL, 9); 1082 + static SENSOR_DEVICE_ATTR(in11_input, S_IRUGO, show_in, NULL, 10); 1083 + static SENSOR_DEVICE_ATTR(in12_input, S_IRUGO, show_in, NULL, 11); 1084 + static SENSOR_DEVICE_ATTR(in13_input, S_IRUGO, show_in, NULL, 12); 1085 + static SENSOR_DEVICE_ATTR(in14_input, S_IRUGO, show_in, NULL, 13); 1086 + static SENSOR_DEVICE_ATTR(in15_input, S_IRUGO, show_in, NULL, 14); 1087 + static SENSOR_DEVICE_ATTR(in16_input, S_IRUGO, show_in, NULL, 15); 1088 + 1089 + static ssize_t show_in_min(struct device *dev, 1090 + struct device_attribute *attr, char *buf) 1091 + { 1092 + int nr = (to_sensor_dev_attr(attr))->index; 1093 + struct lm93_data *data = lm93_update_device(dev); 1094 + int vccp = nr - 6; 1095 + long rc, vid; 1096 + 1097 + if ((nr==6 || nr==7) && (vccp_limit_type[vccp])) { 1098 + vid = LM93_VID_FROM_REG(data->vid[vccp]); 1099 + rc = LM93_IN_MIN_FROM_REG(data->vccp_limits[vccp], vid); 1100 + } 1101 + else { 1102 + rc = LM93_IN_FROM_REG(nr, data->block7[nr].min); \ 1103 + } 1104 + return sprintf(buf, "%ld\n", rc); \ 1105 + } 1106 + 1107 + static ssize_t store_in_min(struct device *dev, struct device_attribute *attr, 1108 + const char *buf, size_t count) 1109 + { 1110 + int nr = (to_sensor_dev_attr(attr))->index; 1111 + struct i2c_client *client = to_i2c_client(dev); 1112 + struct lm93_data *data = i2c_get_clientdata(client); 1113 + u32 val = simple_strtoul(buf, NULL, 10); 1114 + int vccp = nr - 6; 1115 + long vid; 1116 + 1117 + mutex_lock(&data->update_lock); 1118 + if ((nr==6 || nr==7) && (vccp_limit_type[vccp])) { 1119 + vid = LM93_VID_FROM_REG(data->vid[vccp]); 1120 + data->vccp_limits[vccp] = (data->vccp_limits[vccp] & 0xf0) | 1121 + LM93_IN_REL_TO_REG(val, 0, vid); 1122 + lm93_write_byte(client, LM93_REG_VCCP_LIMIT_OFF(vccp), 1123 + data->vccp_limits[vccp]); 1124 + } 1125 + else { 1126 + data->block7[nr].min = LM93_IN_TO_REG(nr,val); 1127 + lm93_write_byte(client, LM93_REG_IN_MIN(nr), 1128 + data->block7[nr].min); 1129 + } 1130 + mutex_unlock(&data->update_lock); 1131 + return count; 1132 + } 1133 + 1134 + static SENSOR_DEVICE_ATTR(in1_min, S_IWUSR | S_IRUGO, 1135 + show_in_min, store_in_min, 0); 1136 + static SENSOR_DEVICE_ATTR(in2_min, S_IWUSR | S_IRUGO, 1137 + show_in_min, store_in_min, 1); 1138 + static SENSOR_DEVICE_ATTR(in3_min, S_IWUSR | S_IRUGO, 1139 + show_in_min, store_in_min, 2); 1140 + static SENSOR_DEVICE_ATTR(in4_min, S_IWUSR | S_IRUGO, 1141 + show_in_min, store_in_min, 3); 1142 + static SENSOR_DEVICE_ATTR(in5_min, S_IWUSR | S_IRUGO, 1143 + show_in_min, store_in_min, 4); 1144 + static SENSOR_DEVICE_ATTR(in6_min, S_IWUSR | S_IRUGO, 1145 + show_in_min, store_in_min, 5); 1146 + static SENSOR_DEVICE_ATTR(in7_min, S_IWUSR | S_IRUGO, 1147 + show_in_min, store_in_min, 6); 1148 + static SENSOR_DEVICE_ATTR(in8_min, S_IWUSR | S_IRUGO, 1149 + show_in_min, store_in_min, 7); 1150 + static SENSOR_DEVICE_ATTR(in9_min, S_IWUSR | S_IRUGO, 1151 + show_in_min, store_in_min, 8); 1152 + static SENSOR_DEVICE_ATTR(in10_min, S_IWUSR | S_IRUGO, 1153 + show_in_min, store_in_min, 9); 1154 + static SENSOR_DEVICE_ATTR(in11_min, S_IWUSR | S_IRUGO, 1155 + show_in_min, store_in_min, 10); 1156 + static SENSOR_DEVICE_ATTR(in12_min, S_IWUSR | S_IRUGO, 1157 + show_in_min, store_in_min, 11); 1158 + static SENSOR_DEVICE_ATTR(in13_min, S_IWUSR | S_IRUGO, 1159 + show_in_min, store_in_min, 12); 1160 + static SENSOR_DEVICE_ATTR(in14_min, S_IWUSR | S_IRUGO, 1161 + show_in_min, store_in_min, 13); 1162 + static SENSOR_DEVICE_ATTR(in15_min, S_IWUSR | S_IRUGO, 1163 + show_in_min, store_in_min, 14); 1164 + static SENSOR_DEVICE_ATTR(in16_min, S_IWUSR | S_IRUGO, 1165 + show_in_min, store_in_min, 15); 1166 + 1167 + static ssize_t show_in_max(struct device *dev, 1168 + struct device_attribute *attr, char *buf) 1169 + { 1170 + int nr = (to_sensor_dev_attr(attr))->index; 1171 + struct lm93_data *data = lm93_update_device(dev); 1172 + int vccp = nr - 6; 1173 + long rc, vid; 1174 + 1175 + if ((nr==6 || nr==7) && (vccp_limit_type[vccp])) { 1176 + vid = LM93_VID_FROM_REG(data->vid[vccp]); 1177 + rc = LM93_IN_MAX_FROM_REG(data->vccp_limits[vccp],vid); 1178 + } 1179 + else { 1180 + rc = LM93_IN_FROM_REG(nr,data->block7[nr].max); \ 1181 + } 1182 + return sprintf(buf,"%ld\n",rc); \ 1183 + } 1184 + 1185 + static ssize_t store_in_max(struct device *dev, struct device_attribute *attr, 1186 + const char *buf, size_t count) 1187 + { 1188 + int nr = (to_sensor_dev_attr(attr))->index; 1189 + struct i2c_client *client = to_i2c_client(dev); 1190 + struct lm93_data *data = i2c_get_clientdata(client); 1191 + u32 val = simple_strtoul(buf, NULL, 10); 1192 + int vccp = nr - 6; 1193 + long vid; 1194 + 1195 + mutex_lock(&data->update_lock); 1196 + if ((nr==6 || nr==7) && (vccp_limit_type[vccp])) { 1197 + vid = LM93_VID_FROM_REG(data->vid[vccp]); 1198 + data->vccp_limits[vccp] = (data->vccp_limits[vccp] & 0x0f) | 1199 + LM93_IN_REL_TO_REG(val, 1, vid); 1200 + lm93_write_byte(client, LM93_REG_VCCP_LIMIT_OFF(vccp), 1201 + data->vccp_limits[vccp]); 1202 + } 1203 + else { 1204 + data->block7[nr].max = LM93_IN_TO_REG(nr,val); 1205 + lm93_write_byte(client, LM93_REG_IN_MAX(nr), 1206 + data->block7[nr].max); 1207 + } 1208 + mutex_unlock(&data->update_lock); 1209 + return count; 1210 + } 1211 + 1212 + static SENSOR_DEVICE_ATTR(in1_max, S_IWUSR | S_IRUGO, 1213 + show_in_max, store_in_max, 0); 1214 + static SENSOR_DEVICE_ATTR(in2_max, S_IWUSR | S_IRUGO, 1215 + show_in_max, store_in_max, 1); 1216 + static SENSOR_DEVICE_ATTR(in3_max, S_IWUSR | S_IRUGO, 1217 + show_in_max, store_in_max, 2); 1218 + static SENSOR_DEVICE_ATTR(in4_max, S_IWUSR | S_IRUGO, 1219 + show_in_max, store_in_max, 3); 1220 + static SENSOR_DEVICE_ATTR(in5_max, S_IWUSR | S_IRUGO, 1221 + show_in_max, store_in_max, 4); 1222 + static SENSOR_DEVICE_ATTR(in6_max, S_IWUSR | S_IRUGO, 1223 + show_in_max, store_in_max, 5); 1224 + static SENSOR_DEVICE_ATTR(in7_max, S_IWUSR | S_IRUGO, 1225 + show_in_max, store_in_max, 6); 1226 + static SENSOR_DEVICE_ATTR(in8_max, S_IWUSR | S_IRUGO, 1227 + show_in_max, store_in_max, 7); 1228 + static SENSOR_DEVICE_ATTR(in9_max, S_IWUSR | S_IRUGO, 1229 + show_in_max, store_in_max, 8); 1230 + static SENSOR_DEVICE_ATTR(in10_max, S_IWUSR | S_IRUGO, 1231 + show_in_max, store_in_max, 9); 1232 + static SENSOR_DEVICE_ATTR(in11_max, S_IWUSR | S_IRUGO, 1233 + show_in_max, store_in_max, 10); 1234 + static SENSOR_DEVICE_ATTR(in12_max, S_IWUSR | S_IRUGO, 1235 + show_in_max, store_in_max, 11); 1236 + static SENSOR_DEVICE_ATTR(in13_max, S_IWUSR | S_IRUGO, 1237 + show_in_max, store_in_max, 12); 1238 + static SENSOR_DEVICE_ATTR(in14_max, S_IWUSR | S_IRUGO, 1239 + show_in_max, store_in_max, 13); 1240 + static SENSOR_DEVICE_ATTR(in15_max, S_IWUSR | S_IRUGO, 1241 + show_in_max, store_in_max, 14); 1242 + static SENSOR_DEVICE_ATTR(in16_max, S_IWUSR | S_IRUGO, 1243 + show_in_max, store_in_max, 15); 1244 + 1245 + static ssize_t show_temp(struct device *dev, 1246 + struct device_attribute *attr, char *buf) 1247 + { 1248 + int nr = (to_sensor_dev_attr(attr))->index; 1249 + struct lm93_data *data = lm93_update_device(dev); 1250 + return sprintf(buf,"%d\n",LM93_TEMP_FROM_REG(data->block2[nr])); 1251 + } 1252 + 1253 + static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, show_temp, NULL, 0); 1254 + static SENSOR_DEVICE_ATTR(temp2_input, S_IRUGO, show_temp, NULL, 1); 1255 + static SENSOR_DEVICE_ATTR(temp3_input, S_IRUGO, show_temp, NULL, 2); 1256 + 1257 + static ssize_t show_temp_min(struct device *dev, 1258 + struct device_attribute *attr, char *buf) 1259 + { 1260 + int nr = (to_sensor_dev_attr(attr))->index; 1261 + struct lm93_data *data = lm93_update_device(dev); 1262 + return sprintf(buf,"%d\n",LM93_TEMP_FROM_REG(data->temp_lim[nr].min)); 1263 + } 1264 + 1265 + static ssize_t store_temp_min(struct device *dev, struct device_attribute *attr, 1266 + const char *buf, size_t count) 1267 + { 1268 + int nr = (to_sensor_dev_attr(attr))->index; 1269 + struct i2c_client *client = to_i2c_client(dev); 1270 + struct lm93_data *data = i2c_get_clientdata(client); 1271 + u32 val = simple_strtoul(buf, NULL, 10); 1272 + 1273 + mutex_lock(&data->update_lock); 1274 + data->temp_lim[nr].min = LM93_TEMP_TO_REG(val); 1275 + lm93_write_byte(client, LM93_REG_TEMP_MIN(nr), data->temp_lim[nr].min); 1276 + mutex_unlock(&data->update_lock); 1277 + return count; 1278 + } 1279 + 1280 + static SENSOR_DEVICE_ATTR(temp1_min, S_IWUSR | S_IRUGO, 1281 + show_temp_min, store_temp_min, 0); 1282 + static SENSOR_DEVICE_ATTR(temp2_min, S_IWUSR | S_IRUGO, 1283 + show_temp_min, store_temp_min, 1); 1284 + static SENSOR_DEVICE_ATTR(temp3_min, S_IWUSR | S_IRUGO, 1285 + show_temp_min, store_temp_min, 2); 1286 + 1287 + static ssize_t show_temp_max(struct device *dev, 1288 + struct device_attribute *attr, char *buf) 1289 + { 1290 + int nr = (to_sensor_dev_attr(attr))->index; 1291 + struct lm93_data *data = lm93_update_device(dev); 1292 + return sprintf(buf,"%d\n",LM93_TEMP_FROM_REG(data->temp_lim[nr].max)); 1293 + } 1294 + 1295 + static ssize_t store_temp_max(struct device *dev, struct device_attribute *attr, 1296 + const char *buf, size_t count) 1297 + { 1298 + int nr = (to_sensor_dev_attr(attr))->index; 1299 + struct i2c_client *client = to_i2c_client(dev); 1300 + struct lm93_data *data = i2c_get_clientdata(client); 1301 + u32 val = simple_strtoul(buf, NULL, 10); 1302 + 1303 + mutex_lock(&data->update_lock); 1304 + data->temp_lim[nr].max = LM93_TEMP_TO_REG(val); 1305 + lm93_write_byte(client, LM93_REG_TEMP_MAX(nr), data->temp_lim[nr].max); 1306 + mutex_unlock(&data->update_lock); 1307 + return count; 1308 + } 1309 + 1310 + static SENSOR_DEVICE_ATTR(temp1_max, S_IWUSR | S_IRUGO, 1311 + show_temp_max, store_temp_max, 0); 1312 + static SENSOR_DEVICE_ATTR(temp2_max, S_IWUSR | S_IRUGO, 1313 + show_temp_max, store_temp_max, 1); 1314 + static SENSOR_DEVICE_ATTR(temp3_max, S_IWUSR | S_IRUGO, 1315 + show_temp_max, store_temp_max, 2); 1316 + 1317 + static ssize_t show_temp_auto_base(struct device *dev, 1318 + struct device_attribute *attr, char *buf) 1319 + { 1320 + int nr = (to_sensor_dev_attr(attr))->index; 1321 + struct lm93_data *data = lm93_update_device(dev); 1322 + return sprintf(buf,"%d\n",LM93_TEMP_FROM_REG(data->block10.base[nr])); 1323 + } 1324 + 1325 + static ssize_t store_temp_auto_base(struct device *dev, 1326 + struct device_attribute *attr, 1327 + const char *buf, size_t count) 1328 + { 1329 + int nr = (to_sensor_dev_attr(attr))->index; 1330 + struct i2c_client *client = to_i2c_client(dev); 1331 + struct lm93_data *data = i2c_get_clientdata(client); 1332 + u32 val = simple_strtoul(buf, NULL, 10); 1333 + 1334 + mutex_lock(&data->update_lock); 1335 + data->block10.base[nr] = LM93_TEMP_TO_REG(val); 1336 + lm93_write_byte(client, LM93_REG_TEMP_BASE(nr), data->block10.base[nr]); 1337 + mutex_unlock(&data->update_lock); 1338 + return count; 1339 + } 1340 + 1341 + static SENSOR_DEVICE_ATTR(temp1_auto_base, S_IWUSR | S_IRUGO, 1342 + show_temp_auto_base, store_temp_auto_base, 0); 1343 + static SENSOR_DEVICE_ATTR(temp2_auto_base, S_IWUSR | S_IRUGO, 1344 + show_temp_auto_base, store_temp_auto_base, 1); 1345 + static SENSOR_DEVICE_ATTR(temp3_auto_base, S_IWUSR | S_IRUGO, 1346 + show_temp_auto_base, store_temp_auto_base, 2); 1347 + 1348 + static ssize_t show_temp_auto_boost(struct device *dev, 1349 + struct device_attribute *attr,char *buf) 1350 + { 1351 + int nr = (to_sensor_dev_attr(attr))->index; 1352 + struct lm93_data *data = lm93_update_device(dev); 1353 + return sprintf(buf,"%d\n",LM93_TEMP_FROM_REG(data->boost[nr])); 1354 + } 1355 + 1356 + static ssize_t store_temp_auto_boost(struct device *dev, 1357 + struct device_attribute *attr, 1358 + const char *buf, size_t count) 1359 + { 1360 + int nr = (to_sensor_dev_attr(attr))->index; 1361 + struct i2c_client *client = to_i2c_client(dev); 1362 + struct lm93_data *data = i2c_get_clientdata(client); 1363 + u32 val = simple_strtoul(buf, NULL, 10); 1364 + 1365 + mutex_lock(&data->update_lock); 1366 + data->boost[nr] = LM93_TEMP_TO_REG(val); 1367 + lm93_write_byte(client, LM93_REG_BOOST(nr), data->boost[nr]); 1368 + mutex_unlock(&data->update_lock); 1369 + return count; 1370 + } 1371 + 1372 + static SENSOR_DEVICE_ATTR(temp1_auto_boost, S_IWUSR | S_IRUGO, 1373 + show_temp_auto_boost, store_temp_auto_boost, 0); 1374 + static SENSOR_DEVICE_ATTR(temp2_auto_boost, S_IWUSR | S_IRUGO, 1375 + show_temp_auto_boost, store_temp_auto_boost, 1); 1376 + static SENSOR_DEVICE_ATTR(temp3_auto_boost, S_IWUSR | S_IRUGO, 1377 + show_temp_auto_boost, store_temp_auto_boost, 2); 1378 + 1379 + static ssize_t show_temp_auto_boost_hyst(struct device *dev, 1380 + struct device_attribute *attr, 1381 + char *buf) 1382 + { 1383 + int nr = (to_sensor_dev_attr(attr))->index; 1384 + struct lm93_data *data = lm93_update_device(dev); 1385 + int mode = LM93_TEMP_OFFSET_MODE_FROM_REG(data->sfc2, nr); 1386 + return sprintf(buf,"%d\n", 1387 + LM93_AUTO_BOOST_HYST_FROM_REGS(data, nr, mode)); 1388 + } 1389 + 1390 + static ssize_t store_temp_auto_boost_hyst(struct device *dev, 1391 + struct device_attribute *attr, 1392 + const char *buf, size_t count) 1393 + { 1394 + int nr = (to_sensor_dev_attr(attr))->index; 1395 + struct i2c_client *client = to_i2c_client(dev); 1396 + struct lm93_data *data = i2c_get_clientdata(client); 1397 + u32 val = simple_strtoul(buf, NULL, 10); 1398 + 1399 + mutex_lock(&data->update_lock); 1400 + /* force 0.5C/bit mode */ 1401 + data->sfc2 = lm93_read_byte(client, LM93_REG_SFC2); 1402 + data->sfc2 |= ((nr < 2) ? 0x10 : 0x20); 1403 + lm93_write_byte(client, LM93_REG_SFC2, data->sfc2); 1404 + data->boost_hyst[nr/2] = LM93_AUTO_BOOST_HYST_TO_REG(data, val, nr, 1); 1405 + lm93_write_byte(client, LM93_REG_BOOST_HYST(nr), 1406 + data->boost_hyst[nr/2]); 1407 + mutex_unlock(&data->update_lock); 1408 + return count; 1409 + } 1410 + 1411 + static SENSOR_DEVICE_ATTR(temp1_auto_boost_hyst, S_IWUSR | S_IRUGO, 1412 + show_temp_auto_boost_hyst, 1413 + store_temp_auto_boost_hyst, 0); 1414 + static SENSOR_DEVICE_ATTR(temp2_auto_boost_hyst, S_IWUSR | S_IRUGO, 1415 + show_temp_auto_boost_hyst, 1416 + store_temp_auto_boost_hyst, 1); 1417 + static SENSOR_DEVICE_ATTR(temp3_auto_boost_hyst, S_IWUSR | S_IRUGO, 1418 + show_temp_auto_boost_hyst, 1419 + store_temp_auto_boost_hyst, 2); 1420 + 1421 + static ssize_t show_temp_auto_offset(struct device *dev, 1422 + struct device_attribute *attr, char *buf) 1423 + { 1424 + struct sensor_device_attribute_2 *s_attr = to_sensor_dev_attr_2(attr); 1425 + int nr = s_attr->index; 1426 + int ofs = s_attr->nr; 1427 + struct lm93_data *data = lm93_update_device(dev); 1428 + int mode = LM93_TEMP_OFFSET_MODE_FROM_REG(data->sfc2, nr); 1429 + return sprintf(buf,"%d\n", 1430 + LM93_TEMP_AUTO_OFFSET_FROM_REG(data->block10.offset[ofs], 1431 + nr,mode)); 1432 + } 1433 + 1434 + static ssize_t store_temp_auto_offset(struct device *dev, 1435 + struct device_attribute *attr, 1436 + const char *buf, size_t count) 1437 + { 1438 + struct sensor_device_attribute_2 *s_attr = to_sensor_dev_attr_2(attr); 1439 + int nr = s_attr->index; 1440 + int ofs = s_attr->nr; 1441 + struct i2c_client *client = to_i2c_client(dev); 1442 + struct lm93_data *data = i2c_get_clientdata(client); 1443 + u32 val = simple_strtoul(buf, NULL, 10); 1444 + 1445 + mutex_lock(&data->update_lock); 1446 + /* force 0.5C/bit mode */ 1447 + data->sfc2 = lm93_read_byte(client, LM93_REG_SFC2); 1448 + data->sfc2 |= ((nr < 2) ? 0x10 : 0x20); 1449 + lm93_write_byte(client, LM93_REG_SFC2, data->sfc2); 1450 + data->block10.offset[ofs] = LM93_TEMP_AUTO_OFFSET_TO_REG( 1451 + data->block10.offset[ofs], val, nr, 1); 1452 + lm93_write_byte(client, LM93_REG_TEMP_OFFSET(ofs), 1453 + data->block10.offset[ofs]); 1454 + mutex_unlock(&data->update_lock); 1455 + return count; 1456 + } 1457 + 1458 + static SENSOR_DEVICE_ATTR_2(temp1_auto_offset1, S_IWUSR | S_IRUGO, 1459 + show_temp_auto_offset, store_temp_auto_offset, 0, 0); 1460 + static SENSOR_DEVICE_ATTR_2(temp1_auto_offset2, S_IWUSR | S_IRUGO, 1461 + show_temp_auto_offset, store_temp_auto_offset, 1, 0); 1462 + static SENSOR_DEVICE_ATTR_2(temp1_auto_offset3, S_IWUSR | S_IRUGO, 1463 + show_temp_auto_offset, store_temp_auto_offset, 2, 0); 1464 + static SENSOR_DEVICE_ATTR_2(temp1_auto_offset4, S_IWUSR | S_IRUGO, 1465 + show_temp_auto_offset, store_temp_auto_offset, 3, 0); 1466 + static SENSOR_DEVICE_ATTR_2(temp1_auto_offset5, S_IWUSR | S_IRUGO, 1467 + show_temp_auto_offset, store_temp_auto_offset, 4, 0); 1468 + static SENSOR_DEVICE_ATTR_2(temp1_auto_offset6, S_IWUSR | S_IRUGO, 1469 + show_temp_auto_offset, store_temp_auto_offset, 5, 0); 1470 + static SENSOR_DEVICE_ATTR_2(temp1_auto_offset7, S_IWUSR | S_IRUGO, 1471 + show_temp_auto_offset, store_temp_auto_offset, 6, 0); 1472 + static SENSOR_DEVICE_ATTR_2(temp1_auto_offset8, S_IWUSR | S_IRUGO, 1473 + show_temp_auto_offset, store_temp_auto_offset, 7, 0); 1474 + static SENSOR_DEVICE_ATTR_2(temp1_auto_offset9, S_IWUSR | S_IRUGO, 1475 + show_temp_auto_offset, store_temp_auto_offset, 8, 0); 1476 + static SENSOR_DEVICE_ATTR_2(temp1_auto_offset10, S_IWUSR | S_IRUGO, 1477 + show_temp_auto_offset, store_temp_auto_offset, 9, 0); 1478 + static SENSOR_DEVICE_ATTR_2(temp1_auto_offset11, S_IWUSR | S_IRUGO, 1479 + show_temp_auto_offset, store_temp_auto_offset, 10, 0); 1480 + static SENSOR_DEVICE_ATTR_2(temp1_auto_offset12, S_IWUSR | S_IRUGO, 1481 + show_temp_auto_offset, store_temp_auto_offset, 11, 0); 1482 + static SENSOR_DEVICE_ATTR_2(temp2_auto_offset1, S_IWUSR | S_IRUGO, 1483 + show_temp_auto_offset, store_temp_auto_offset, 0, 1); 1484 + static SENSOR_DEVICE_ATTR_2(temp2_auto_offset2, S_IWUSR | S_IRUGO, 1485 + show_temp_auto_offset, store_temp_auto_offset, 1, 1); 1486 + static SENSOR_DEVICE_ATTR_2(temp2_auto_offset3, S_IWUSR | S_IRUGO, 1487 + show_temp_auto_offset, store_temp_auto_offset, 2, 1); 1488 + static SENSOR_DEVICE_ATTR_2(temp2_auto_offset4, S_IWUSR | S_IRUGO, 1489 + show_temp_auto_offset, store_temp_auto_offset, 3, 1); 1490 + static SENSOR_DEVICE_ATTR_2(temp2_auto_offset5, S_IWUSR | S_IRUGO, 1491 + show_temp_auto_offset, store_temp_auto_offset, 4, 1); 1492 + static SENSOR_DEVICE_ATTR_2(temp2_auto_offset6, S_IWUSR | S_IRUGO, 1493 + show_temp_auto_offset, store_temp_auto_offset, 5, 1); 1494 + static SENSOR_DEVICE_ATTR_2(temp2_auto_offset7, S_IWUSR | S_IRUGO, 1495 + show_temp_auto_offset, store_temp_auto_offset, 6, 1); 1496 + static SENSOR_DEVICE_ATTR_2(temp2_auto_offset8, S_IWUSR | S_IRUGO, 1497 + show_temp_auto_offset, store_temp_auto_offset, 7, 1); 1498 + static SENSOR_DEVICE_ATTR_2(temp2_auto_offset9, S_IWUSR | S_IRUGO, 1499 + show_temp_auto_offset, store_temp_auto_offset, 8, 1); 1500 + static SENSOR_DEVICE_ATTR_2(temp2_auto_offset10, S_IWUSR | S_IRUGO, 1501 + show_temp_auto_offset, store_temp_auto_offset, 9, 1); 1502 + static SENSOR_DEVICE_ATTR_2(temp2_auto_offset11, S_IWUSR | S_IRUGO, 1503 + show_temp_auto_offset, store_temp_auto_offset, 10, 1); 1504 + static SENSOR_DEVICE_ATTR_2(temp2_auto_offset12, S_IWUSR | S_IRUGO, 1505 + show_temp_auto_offset, store_temp_auto_offset, 11, 1); 1506 + static SENSOR_DEVICE_ATTR_2(temp3_auto_offset1, S_IWUSR | S_IRUGO, 1507 + show_temp_auto_offset, store_temp_auto_offset, 0, 2); 1508 + static SENSOR_DEVICE_ATTR_2(temp3_auto_offset2, S_IWUSR | S_IRUGO, 1509 + show_temp_auto_offset, store_temp_auto_offset, 1, 2); 1510 + static SENSOR_DEVICE_ATTR_2(temp3_auto_offset3, S_IWUSR | S_IRUGO, 1511 + show_temp_auto_offset, store_temp_auto_offset, 2, 2); 1512 + static SENSOR_DEVICE_ATTR_2(temp3_auto_offset4, S_IWUSR | S_IRUGO, 1513 + show_temp_auto_offset, store_temp_auto_offset, 3, 2); 1514 + static SENSOR_DEVICE_ATTR_2(temp3_auto_offset5, S_IWUSR | S_IRUGO, 1515 + show_temp_auto_offset, store_temp_auto_offset, 4, 2); 1516 + static SENSOR_DEVICE_ATTR_2(temp3_auto_offset6, S_IWUSR | S_IRUGO, 1517 + show_temp_auto_offset, store_temp_auto_offset, 5, 2); 1518 + static SENSOR_DEVICE_ATTR_2(temp3_auto_offset7, S_IWUSR | S_IRUGO, 1519 + show_temp_auto_offset, store_temp_auto_offset, 6, 2); 1520 + static SENSOR_DEVICE_ATTR_2(temp3_auto_offset8, S_IWUSR | S_IRUGO, 1521 + show_temp_auto_offset, store_temp_auto_offset, 7, 2); 1522 + static SENSOR_DEVICE_ATTR_2(temp3_auto_offset9, S_IWUSR | S_IRUGO, 1523 + show_temp_auto_offset, store_temp_auto_offset, 8, 2); 1524 + static SENSOR_DEVICE_ATTR_2(temp3_auto_offset10, S_IWUSR | S_IRUGO, 1525 + show_temp_auto_offset, store_temp_auto_offset, 9, 2); 1526 + static SENSOR_DEVICE_ATTR_2(temp3_auto_offset11, S_IWUSR | S_IRUGO, 1527 + show_temp_auto_offset, store_temp_auto_offset, 10, 2); 1528 + static SENSOR_DEVICE_ATTR_2(temp3_auto_offset12, S_IWUSR | S_IRUGO, 1529 + show_temp_auto_offset, store_temp_auto_offset, 11, 2); 1530 + 1531 + static ssize_t show_temp_auto_pwm_min(struct device *dev, 1532 + struct device_attribute *attr, char *buf) 1533 + { 1534 + int nr = (to_sensor_dev_attr(attr))->index; 1535 + u8 reg, ctl4; 1536 + struct lm93_data *data = lm93_update_device(dev); 1537 + reg = data->auto_pwm_min_hyst[nr/2] >> 4 & 0x0f; 1538 + ctl4 = data->block9[nr][LM93_PWM_CTL4]; 1539 + return sprintf(buf,"%d\n",LM93_PWM_FROM_REG(reg, (ctl4 & 0x07) ? 1540 + LM93_PWM_MAP_LO_FREQ : LM93_PWM_MAP_HI_FREQ)); 1541 + } 1542 + 1543 + static ssize_t store_temp_auto_pwm_min(struct device *dev, 1544 + struct device_attribute *attr, 1545 + const char *buf, size_t count) 1546 + { 1547 + int nr = (to_sensor_dev_attr(attr))->index; 1548 + struct i2c_client *client = to_i2c_client(dev); 1549 + struct lm93_data *data = i2c_get_clientdata(client); 1550 + u32 val = simple_strtoul(buf, NULL, 10); 1551 + u8 reg, ctl4; 1552 + 1553 + mutex_lock(&data->update_lock); 1554 + reg = lm93_read_byte(client, LM93_REG_PWM_MIN_HYST(nr)); 1555 + ctl4 = lm93_read_byte(client, LM93_REG_PWM_CTL(nr,LM93_PWM_CTL4)); 1556 + reg = (reg & 0x0f) | 1557 + LM93_PWM_TO_REG(val, (ctl4 & 0x07) ? 1558 + LM93_PWM_MAP_LO_FREQ : 1559 + LM93_PWM_MAP_HI_FREQ) << 4; 1560 + data->auto_pwm_min_hyst[nr/2] = reg; 1561 + lm93_write_byte(client, LM93_REG_PWM_MIN_HYST(nr), reg); 1562 + mutex_unlock(&data->update_lock); 1563 + return count; 1564 + } 1565 + 1566 + static SENSOR_DEVICE_ATTR(temp1_auto_pwm_min, S_IWUSR | S_IRUGO, 1567 + show_temp_auto_pwm_min, 1568 + store_temp_auto_pwm_min, 0); 1569 + static SENSOR_DEVICE_ATTR(temp2_auto_pwm_min, S_IWUSR | S_IRUGO, 1570 + show_temp_auto_pwm_min, 1571 + store_temp_auto_pwm_min, 1); 1572 + static SENSOR_DEVICE_ATTR(temp3_auto_pwm_min, S_IWUSR | S_IRUGO, 1573 + show_temp_auto_pwm_min, 1574 + store_temp_auto_pwm_min, 2); 1575 + 1576 + static ssize_t show_temp_auto_offset_hyst(struct device *dev, 1577 + struct device_attribute *attr, char *buf) 1578 + { 1579 + int nr = (to_sensor_dev_attr(attr))->index; 1580 + struct lm93_data *data = lm93_update_device(dev); 1581 + int mode = LM93_TEMP_OFFSET_MODE_FROM_REG(data->sfc2, nr); 1582 + return sprintf(buf,"%d\n",LM93_TEMP_OFFSET_FROM_REG( 1583 + data->auto_pwm_min_hyst[nr/2], mode)); 1584 + } 1585 + 1586 + static ssize_t store_temp_auto_offset_hyst(struct device *dev, 1587 + struct device_attribute *attr, 1588 + const char *buf, size_t count) 1589 + { 1590 + int nr = (to_sensor_dev_attr(attr))->index; 1591 + struct i2c_client *client = to_i2c_client(dev); 1592 + struct lm93_data *data = i2c_get_clientdata(client); 1593 + u32 val = simple_strtoul(buf, NULL, 10); 1594 + u8 reg; 1595 + 1596 + mutex_lock(&data->update_lock); 1597 + /* force 0.5C/bit mode */ 1598 + data->sfc2 = lm93_read_byte(client, LM93_REG_SFC2); 1599 + data->sfc2 |= ((nr < 2) ? 0x10 : 0x20); 1600 + lm93_write_byte(client, LM93_REG_SFC2, data->sfc2); 1601 + reg = data->auto_pwm_min_hyst[nr/2]; 1602 + reg = (reg & 0xf0) | (LM93_TEMP_OFFSET_TO_REG(val, 1) & 0x0f); 1603 + data->auto_pwm_min_hyst[nr/2] = reg; 1604 + lm93_write_byte(client, LM93_REG_PWM_MIN_HYST(nr), reg); 1605 + mutex_unlock(&data->update_lock); 1606 + return count; 1607 + } 1608 + 1609 + static SENSOR_DEVICE_ATTR(temp1_auto_offset_hyst, S_IWUSR | S_IRUGO, 1610 + show_temp_auto_offset_hyst, 1611 + store_temp_auto_offset_hyst, 0); 1612 + static SENSOR_DEVICE_ATTR(temp2_auto_offset_hyst, S_IWUSR | S_IRUGO, 1613 + show_temp_auto_offset_hyst, 1614 + store_temp_auto_offset_hyst, 1); 1615 + static SENSOR_DEVICE_ATTR(temp3_auto_offset_hyst, S_IWUSR | S_IRUGO, 1616 + show_temp_auto_offset_hyst, 1617 + store_temp_auto_offset_hyst, 2); 1618 + 1619 + static ssize_t show_fan_input(struct device *dev, 1620 + struct device_attribute *attr, char *buf) 1621 + { 1622 + struct sensor_device_attribute *s_attr = to_sensor_dev_attr(attr); 1623 + int nr = s_attr->index; 1624 + struct lm93_data *data = lm93_update_device(dev); 1625 + 1626 + return sprintf(buf,"%d\n",LM93_FAN_FROM_REG(data->block5[nr])); 1627 + } 1628 + 1629 + static SENSOR_DEVICE_ATTR(fan1_input, S_IRUGO, show_fan_input, NULL, 0); 1630 + static SENSOR_DEVICE_ATTR(fan2_input, S_IRUGO, show_fan_input, NULL, 1); 1631 + static SENSOR_DEVICE_ATTR(fan3_input, S_IRUGO, show_fan_input, NULL, 2); 1632 + static SENSOR_DEVICE_ATTR(fan4_input, S_IRUGO, show_fan_input, NULL, 3); 1633 + 1634 + static ssize_t show_fan_min(struct device *dev, 1635 + struct device_attribute *attr, char *buf) 1636 + { 1637 + int nr = (to_sensor_dev_attr(attr))->index; 1638 + struct lm93_data *data = lm93_update_device(dev); 1639 + 1640 + return sprintf(buf,"%d\n",LM93_FAN_FROM_REG(data->block8[nr])); 1641 + } 1642 + 1643 + static ssize_t store_fan_min(struct device *dev, struct device_attribute *attr, 1644 + const char *buf, size_t count) 1645 + { 1646 + int nr = (to_sensor_dev_attr(attr))->index; 1647 + struct i2c_client *client = to_i2c_client(dev); 1648 + struct lm93_data *data = i2c_get_clientdata(client); 1649 + u32 val = simple_strtoul(buf, NULL, 10); 1650 + 1651 + mutex_lock(&data->update_lock); 1652 + data->block8[nr] = LM93_FAN_TO_REG(val); 1653 + lm93_write_word(client,LM93_REG_FAN_MIN(nr),data->block8[nr]); 1654 + mutex_unlock(&data->update_lock); 1655 + return count; 1656 + } 1657 + 1658 + static SENSOR_DEVICE_ATTR(fan1_min, S_IWUSR | S_IRUGO, 1659 + show_fan_min, store_fan_min, 0); 1660 + static SENSOR_DEVICE_ATTR(fan2_min, S_IWUSR | S_IRUGO, 1661 + show_fan_min, store_fan_min, 1); 1662 + static SENSOR_DEVICE_ATTR(fan3_min, S_IWUSR | S_IRUGO, 1663 + show_fan_min, store_fan_min, 2); 1664 + static SENSOR_DEVICE_ATTR(fan4_min, S_IWUSR | S_IRUGO, 1665 + show_fan_min, store_fan_min, 3); 1666 + 1667 + /* some tedious bit-twiddling here to deal with the register format: 1668 + 1669 + data->sf_tach_to_pwm: (tach to pwm mapping bits) 1670 + 1671 + bit | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 1672 + T4:P2 T4:P1 T3:P2 T3:P1 T2:P2 T2:P1 T1:P2 T1:P1 1673 + 1674 + data->sfc2: (enable bits) 1675 + 1676 + bit | 3 | 2 | 1 | 0 1677 + T4 T3 T2 T1 1678 + */ 1679 + 1680 + static ssize_t show_fan_smart_tach(struct device *dev, 1681 + struct device_attribute *attr, char *buf) 1682 + { 1683 + int nr = (to_sensor_dev_attr(attr))->index; 1684 + struct lm93_data *data = lm93_update_device(dev); 1685 + long rc = 0; 1686 + int mapping; 1687 + 1688 + /* extract the relevant mapping */ 1689 + mapping = (data->sf_tach_to_pwm >> (nr * 2)) & 0x03; 1690 + 1691 + /* if there's a mapping and it's enabled */ 1692 + if (mapping && ((data->sfc2 >> nr) & 0x01)) 1693 + rc = mapping; 1694 + return sprintf(buf,"%ld\n",rc); 1695 + } 1696 + 1697 + /* helper function - must grab data->update_lock before calling 1698 + fan is 0-3, indicating fan1-fan4 */ 1699 + static void lm93_write_fan_smart_tach(struct i2c_client *client, 1700 + struct lm93_data *data, int fan, long value) 1701 + { 1702 + /* insert the new mapping and write it out */ 1703 + data->sf_tach_to_pwm = lm93_read_byte(client, LM93_REG_SF_TACH_TO_PWM); 1704 + data->sf_tach_to_pwm &= ~(0x3 << fan * 2); 1705 + data->sf_tach_to_pwm |= value << fan * 2; 1706 + lm93_write_byte(client, LM93_REG_SF_TACH_TO_PWM, data->sf_tach_to_pwm); 1707 + 1708 + /* insert the enable bit and write it out */ 1709 + data->sfc2 = lm93_read_byte(client, LM93_REG_SFC2); 1710 + if (value) 1711 + data->sfc2 |= 1 << fan; 1712 + else 1713 + data->sfc2 &= ~(1 << fan); 1714 + lm93_write_byte(client, LM93_REG_SFC2, data->sfc2); 1715 + } 1716 + 1717 + static ssize_t store_fan_smart_tach(struct device *dev, 1718 + struct device_attribute *attr, 1719 + const char *buf, size_t count) 1720 + { 1721 + int nr = (to_sensor_dev_attr(attr))->index; 1722 + struct i2c_client *client = to_i2c_client(dev); 1723 + struct lm93_data *data = i2c_get_clientdata(client); 1724 + u32 val = simple_strtoul(buf, NULL, 10); 1725 + 1726 + mutex_lock(&data->update_lock); 1727 + /* sanity test, ignore the write otherwise */ 1728 + if (0 <= val && val <= 2) { 1729 + /* can't enable if pwm freq is 22.5KHz */ 1730 + if (val) { 1731 + u8 ctl4 = lm93_read_byte(client, 1732 + LM93_REG_PWM_CTL(val-1,LM93_PWM_CTL4)); 1733 + if ((ctl4 & 0x07) == 0) 1734 + val = 0; 1735 + } 1736 + lm93_write_fan_smart_tach(client, data, nr, val); 1737 + } 1738 + mutex_unlock(&data->update_lock); 1739 + return count; 1740 + } 1741 + 1742 + static SENSOR_DEVICE_ATTR(fan1_smart_tach, S_IWUSR | S_IRUGO, 1743 + show_fan_smart_tach, store_fan_smart_tach, 0); 1744 + static SENSOR_DEVICE_ATTR(fan2_smart_tach, S_IWUSR | S_IRUGO, 1745 + show_fan_smart_tach, store_fan_smart_tach, 1); 1746 + static SENSOR_DEVICE_ATTR(fan3_smart_tach, S_IWUSR | S_IRUGO, 1747 + show_fan_smart_tach, store_fan_smart_tach, 2); 1748 + static SENSOR_DEVICE_ATTR(fan4_smart_tach, S_IWUSR | S_IRUGO, 1749 + show_fan_smart_tach, store_fan_smart_tach, 3); 1750 + 1751 + static ssize_t show_pwm(struct device *dev, struct device_attribute *attr, 1752 + char *buf) 1753 + { 1754 + int nr = (to_sensor_dev_attr(attr))->index; 1755 + struct lm93_data *data = lm93_update_device(dev); 1756 + u8 ctl2, ctl4; 1757 + long rc; 1758 + 1759 + ctl2 = data->block9[nr][LM93_PWM_CTL2]; 1760 + ctl4 = data->block9[nr][LM93_PWM_CTL4]; 1761 + if (ctl2 & 0x01) /* show user commanded value if enabled */ 1762 + rc = data->pwm_override[nr]; 1763 + else /* show present h/w value if manual pwm disabled */ 1764 + rc = LM93_PWM_FROM_REG(ctl2 >> 4, (ctl4 & 0x07) ? 1765 + LM93_PWM_MAP_LO_FREQ : LM93_PWM_MAP_HI_FREQ); 1766 + return sprintf(buf,"%ld\n",rc); 1767 + } 1768 + 1769 + static ssize_t store_pwm(struct device *dev, struct device_attribute *attr, 1770 + const char *buf, size_t count) 1771 + { 1772 + int nr = (to_sensor_dev_attr(attr))->index; 1773 + struct i2c_client *client = to_i2c_client(dev); 1774 + struct lm93_data *data = i2c_get_clientdata(client); 1775 + u32 val = simple_strtoul(buf, NULL, 10); 1776 + u8 ctl2, ctl4; 1777 + 1778 + mutex_lock(&data->update_lock); 1779 + ctl2 = lm93_read_byte(client,LM93_REG_PWM_CTL(nr,LM93_PWM_CTL2)); 1780 + ctl4 = lm93_read_byte(client, LM93_REG_PWM_CTL(nr,LM93_PWM_CTL4)); 1781 + ctl2 = (ctl2 & 0x0f) | LM93_PWM_TO_REG(val,(ctl4 & 0x07) ? 1782 + LM93_PWM_MAP_LO_FREQ : LM93_PWM_MAP_HI_FREQ) << 4; 1783 + /* save user commanded value */ 1784 + data->pwm_override[nr] = LM93_PWM_FROM_REG(ctl2 >> 4, 1785 + (ctl4 & 0x07) ? LM93_PWM_MAP_LO_FREQ : 1786 + LM93_PWM_MAP_HI_FREQ); 1787 + lm93_write_byte(client,LM93_REG_PWM_CTL(nr,LM93_PWM_CTL2),ctl2); 1788 + mutex_unlock(&data->update_lock); 1789 + return count; 1790 + } 1791 + 1792 + static SENSOR_DEVICE_ATTR(pwm1, S_IWUSR | S_IRUGO, show_pwm, store_pwm, 0); 1793 + static SENSOR_DEVICE_ATTR(pwm2, S_IWUSR | S_IRUGO, show_pwm, store_pwm, 1); 1794 + 1795 + static ssize_t show_pwm_enable(struct device *dev, 1796 + struct device_attribute *attr, char *buf) 1797 + { 1798 + int nr = (to_sensor_dev_attr(attr))->index; 1799 + struct lm93_data *data = lm93_update_device(dev); 1800 + u8 ctl2; 1801 + long rc; 1802 + 1803 + ctl2 = data->block9[nr][LM93_PWM_CTL2]; 1804 + if (ctl2 & 0x01) /* manual override enabled ? */ 1805 + rc = ((ctl2 & 0xF0) == 0xF0) ? 0 : 1; 1806 + else 1807 + rc = 2; 1808 + return sprintf(buf,"%ld\n",rc); 1809 + } 1810 + 1811 + static ssize_t store_pwm_enable(struct device *dev, 1812 + struct device_attribute *attr, 1813 + const char *buf, size_t count) 1814 + { 1815 + int nr = (to_sensor_dev_attr(attr))->index; 1816 + struct i2c_client *client = to_i2c_client(dev); 1817 + struct lm93_data *data = i2c_get_clientdata(client); 1818 + u32 val = simple_strtoul(buf, NULL, 10); 1819 + u8 ctl2; 1820 + 1821 + mutex_lock(&data->update_lock); 1822 + ctl2 = lm93_read_byte(client,LM93_REG_PWM_CTL(nr,LM93_PWM_CTL2)); 1823 + 1824 + switch (val) { 1825 + case 0: 1826 + ctl2 |= 0xF1; /* enable manual override, set PWM to max */ 1827 + break; 1828 + case 1: ctl2 |= 0x01; /* enable manual override */ 1829 + break; 1830 + case 2: ctl2 &= ~0x01; /* disable manual override */ 1831 + break; 1832 + default: 1833 + mutex_unlock(&data->update_lock); 1834 + return -EINVAL; 1835 + } 1836 + 1837 + lm93_write_byte(client,LM93_REG_PWM_CTL(nr,LM93_PWM_CTL2),ctl2); 1838 + mutex_unlock(&data->update_lock); 1839 + return count; 1840 + } 1841 + 1842 + static SENSOR_DEVICE_ATTR(pwm1_enable, S_IWUSR | S_IRUGO, 1843 + show_pwm_enable, store_pwm_enable, 0); 1844 + static SENSOR_DEVICE_ATTR(pwm2_enable, S_IWUSR | S_IRUGO, 1845 + show_pwm_enable, store_pwm_enable, 1); 1846 + 1847 + static ssize_t show_pwm_freq(struct device *dev, struct device_attribute *attr, 1848 + char *buf) 1849 + { 1850 + int nr = (to_sensor_dev_attr(attr))->index; 1851 + struct lm93_data *data = lm93_update_device(dev); 1852 + u8 ctl4; 1853 + 1854 + ctl4 = data->block9[nr][LM93_PWM_CTL4]; 1855 + return sprintf(buf,"%d\n",LM93_PWM_FREQ_FROM_REG(ctl4)); 1856 + } 1857 + 1858 + /* helper function - must grab data->update_lock before calling 1859 + pwm is 0-1, indicating pwm1-pwm2 1860 + this disables smart tach for all tach channels bound to the given pwm */ 1861 + static void lm93_disable_fan_smart_tach(struct i2c_client *client, 1862 + struct lm93_data *data, int pwm) 1863 + { 1864 + int mapping = lm93_read_byte(client, LM93_REG_SF_TACH_TO_PWM); 1865 + int mask; 1866 + 1867 + /* collapse the mapping into a mask of enable bits */ 1868 + mapping = (mapping >> pwm) & 0x55; 1869 + mask = mapping & 0x01; 1870 + mask |= (mapping & 0x04) >> 1; 1871 + mask |= (mapping & 0x10) >> 2; 1872 + mask |= (mapping & 0x40) >> 3; 1873 + 1874 + /* disable smart tach according to the mask */ 1875 + data->sfc2 = lm93_read_byte(client, LM93_REG_SFC2); 1876 + data->sfc2 &= ~mask; 1877 + lm93_write_byte(client, LM93_REG_SFC2, data->sfc2); 1878 + } 1879 + 1880 + static ssize_t store_pwm_freq(struct device *dev, 1881 + struct device_attribute *attr, 1882 + const char *buf, size_t count) 1883 + { 1884 + int nr = (to_sensor_dev_attr(attr))->index; 1885 + struct i2c_client *client = to_i2c_client(dev); 1886 + struct lm93_data *data = i2c_get_clientdata(client); 1887 + u32 val = simple_strtoul(buf, NULL, 10); 1888 + u8 ctl4; 1889 + 1890 + mutex_lock(&data->update_lock); 1891 + ctl4 = lm93_read_byte(client,LM93_REG_PWM_CTL(nr,LM93_PWM_CTL4)); 1892 + ctl4 = (ctl4 & 0xf8) | LM93_PWM_FREQ_TO_REG(val); 1893 + data->block9[nr][LM93_PWM_CTL4] = ctl4; 1894 + /* ctl4 == 0 -> 22.5KHz -> disable smart tach */ 1895 + if (!ctl4) 1896 + lm93_disable_fan_smart_tach(client, data, nr); 1897 + lm93_write_byte(client, LM93_REG_PWM_CTL(nr,LM93_PWM_CTL4), ctl4); 1898 + mutex_unlock(&data->update_lock); 1899 + return count; 1900 + } 1901 + 1902 + static SENSOR_DEVICE_ATTR(pwm1_freq, S_IWUSR | S_IRUGO, 1903 + show_pwm_freq, store_pwm_freq, 0); 1904 + static SENSOR_DEVICE_ATTR(pwm2_freq, S_IWUSR | S_IRUGO, 1905 + show_pwm_freq, store_pwm_freq, 1); 1906 + 1907 + static ssize_t show_pwm_auto_channels(struct device *dev, 1908 + struct device_attribute *attr, char *buf) 1909 + { 1910 + int nr = (to_sensor_dev_attr(attr))->index; 1911 + struct lm93_data *data = lm93_update_device(dev); 1912 + return sprintf(buf,"%d\n",data->block9[nr][LM93_PWM_CTL1]); 1913 + } 1914 + 1915 + static ssize_t store_pwm_auto_channels(struct device *dev, 1916 + struct device_attribute *attr, 1917 + const char *buf, size_t count) 1918 + { 1919 + int nr = (to_sensor_dev_attr(attr))->index; 1920 + struct i2c_client *client = to_i2c_client(dev); 1921 + struct lm93_data *data = i2c_get_clientdata(client); 1922 + u32 val = simple_strtoul(buf, NULL, 10); 1923 + 1924 + mutex_lock(&data->update_lock); 1925 + data->block9[nr][LM93_PWM_CTL1] = SENSORS_LIMIT(val, 0, 255); 1926 + lm93_write_byte(client, LM93_REG_PWM_CTL(nr,LM93_PWM_CTL1), 1927 + data->block9[nr][LM93_PWM_CTL1]); 1928 + mutex_unlock(&data->update_lock); 1929 + return count; 1930 + } 1931 + 1932 + static SENSOR_DEVICE_ATTR(pwm1_auto_channels, S_IWUSR | S_IRUGO, 1933 + show_pwm_auto_channels, store_pwm_auto_channels, 0); 1934 + static SENSOR_DEVICE_ATTR(pwm2_auto_channels, S_IWUSR | S_IRUGO, 1935 + show_pwm_auto_channels, store_pwm_auto_channels, 1); 1936 + 1937 + static ssize_t show_pwm_auto_spinup_min(struct device *dev, 1938 + struct device_attribute *attr,char *buf) 1939 + { 1940 + int nr = (to_sensor_dev_attr(attr))->index; 1941 + struct lm93_data *data = lm93_update_device(dev); 1942 + u8 ctl3, ctl4; 1943 + 1944 + ctl3 = data->block9[nr][LM93_PWM_CTL3]; 1945 + ctl4 = data->block9[nr][LM93_PWM_CTL4]; 1946 + return sprintf(buf,"%d\n", 1947 + LM93_PWM_FROM_REG(ctl3 & 0x0f, (ctl4 & 0x07) ? 1948 + LM93_PWM_MAP_LO_FREQ : LM93_PWM_MAP_HI_FREQ)); 1949 + } 1950 + 1951 + static ssize_t store_pwm_auto_spinup_min(struct device *dev, 1952 + struct device_attribute *attr, 1953 + const char *buf, size_t count) 1954 + { 1955 + int nr = (to_sensor_dev_attr(attr))->index; 1956 + struct i2c_client *client = to_i2c_client(dev); 1957 + struct lm93_data *data = i2c_get_clientdata(client); 1958 + u32 val = simple_strtoul(buf, NULL, 10); 1959 + u8 ctl3, ctl4; 1960 + 1961 + mutex_lock(&data->update_lock); 1962 + ctl3 = lm93_read_byte(client,LM93_REG_PWM_CTL(nr, LM93_PWM_CTL3)); 1963 + ctl4 = lm93_read_byte(client,LM93_REG_PWM_CTL(nr, LM93_PWM_CTL4)); 1964 + ctl3 = (ctl3 & 0xf0) | LM93_PWM_TO_REG(val, (ctl4 & 0x07) ? 1965 + LM93_PWM_MAP_LO_FREQ : 1966 + LM93_PWM_MAP_HI_FREQ); 1967 + data->block9[nr][LM93_PWM_CTL3] = ctl3; 1968 + lm93_write_byte(client,LM93_REG_PWM_CTL(nr, LM93_PWM_CTL3), ctl3); 1969 + mutex_unlock(&data->update_lock); 1970 + return count; 1971 + } 1972 + 1973 + static SENSOR_DEVICE_ATTR(pwm1_auto_spinup_min, S_IWUSR | S_IRUGO, 1974 + show_pwm_auto_spinup_min, 1975 + store_pwm_auto_spinup_min, 0); 1976 + static SENSOR_DEVICE_ATTR(pwm2_auto_spinup_min, S_IWUSR | S_IRUGO, 1977 + show_pwm_auto_spinup_min, 1978 + store_pwm_auto_spinup_min, 1); 1979 + 1980 + static ssize_t show_pwm_auto_spinup_time(struct device *dev, 1981 + struct device_attribute *attr, char *buf) 1982 + { 1983 + int nr = (to_sensor_dev_attr(attr))->index; 1984 + struct lm93_data *data = lm93_update_device(dev); 1985 + return sprintf(buf,"%d\n",LM93_SPINUP_TIME_FROM_REG( 1986 + data->block9[nr][LM93_PWM_CTL3])); 1987 + } 1988 + 1989 + static ssize_t store_pwm_auto_spinup_time(struct device *dev, 1990 + struct device_attribute *attr, 1991 + const char *buf, size_t count) 1992 + { 1993 + int nr = (to_sensor_dev_attr(attr))->index; 1994 + struct i2c_client *client = to_i2c_client(dev); 1995 + struct lm93_data *data = i2c_get_clientdata(client); 1996 + u32 val = simple_strtoul(buf, NULL, 10); 1997 + u8 ctl3; 1998 + 1999 + mutex_lock(&data->update_lock); 2000 + ctl3 = lm93_read_byte(client,LM93_REG_PWM_CTL(nr, LM93_PWM_CTL3)); 2001 + ctl3 = (ctl3 & 0x1f) | (LM93_SPINUP_TIME_TO_REG(val) << 5 & 0xe0); 2002 + data->block9[nr][LM93_PWM_CTL3] = ctl3; 2003 + lm93_write_byte(client,LM93_REG_PWM_CTL(nr, LM93_PWM_CTL3), ctl3); 2004 + mutex_unlock(&data->update_lock); 2005 + return count; 2006 + } 2007 + 2008 + static SENSOR_DEVICE_ATTR(pwm1_auto_spinup_time, S_IWUSR | S_IRUGO, 2009 + show_pwm_auto_spinup_time, 2010 + store_pwm_auto_spinup_time, 0); 2011 + static SENSOR_DEVICE_ATTR(pwm2_auto_spinup_time, S_IWUSR | S_IRUGO, 2012 + show_pwm_auto_spinup_time, 2013 + store_pwm_auto_spinup_time, 1); 2014 + 2015 + static ssize_t show_pwm_auto_prochot_ramp(struct device *dev, 2016 + struct device_attribute *attr, char *buf) 2017 + { 2018 + struct lm93_data *data = lm93_update_device(dev); 2019 + return sprintf(buf,"%d\n", 2020 + LM93_RAMP_FROM_REG(data->pwm_ramp_ctl >> 4 & 0x0f)); 2021 + } 2022 + 2023 + static ssize_t store_pwm_auto_prochot_ramp(struct device *dev, 2024 + struct device_attribute *attr, 2025 + const char *buf, size_t count) 2026 + { 2027 + struct i2c_client *client = to_i2c_client(dev); 2028 + struct lm93_data *data = i2c_get_clientdata(client); 2029 + u32 val = simple_strtoul(buf, NULL, 10); 2030 + u8 ramp; 2031 + 2032 + mutex_lock(&data->update_lock); 2033 + ramp = lm93_read_byte(client, LM93_REG_PWM_RAMP_CTL); 2034 + ramp = (ramp & 0x0f) | (LM93_RAMP_TO_REG(val) << 4 & 0xf0); 2035 + lm93_write_byte(client, LM93_REG_PWM_RAMP_CTL, ramp); 2036 + mutex_unlock(&data->update_lock); 2037 + return count; 2038 + } 2039 + 2040 + static DEVICE_ATTR(pwm_auto_prochot_ramp, S_IRUGO | S_IWUSR, 2041 + show_pwm_auto_prochot_ramp, 2042 + store_pwm_auto_prochot_ramp); 2043 + 2044 + static ssize_t show_pwm_auto_vrdhot_ramp(struct device *dev, 2045 + struct device_attribute *attr, char *buf) 2046 + { 2047 + struct lm93_data *data = lm93_update_device(dev); 2048 + return sprintf(buf,"%d\n", 2049 + LM93_RAMP_FROM_REG(data->pwm_ramp_ctl & 0x0f)); 2050 + } 2051 + 2052 + static ssize_t store_pwm_auto_vrdhot_ramp(struct device *dev, 2053 + struct device_attribute *attr, 2054 + const char *buf, size_t count) 2055 + { 2056 + struct i2c_client *client = to_i2c_client(dev); 2057 + struct lm93_data *data = i2c_get_clientdata(client); 2058 + u32 val = simple_strtoul(buf, NULL, 10); 2059 + u8 ramp; 2060 + 2061 + mutex_lock(&data->update_lock); 2062 + ramp = lm93_read_byte(client, LM93_REG_PWM_RAMP_CTL); 2063 + ramp = (ramp & 0xf0) | (LM93_RAMP_TO_REG(val) & 0x0f); 2064 + lm93_write_byte(client, LM93_REG_PWM_RAMP_CTL, ramp); 2065 + mutex_unlock(&data->update_lock); 2066 + return 0; 2067 + } 2068 + 2069 + static DEVICE_ATTR(pwm_auto_vrdhot_ramp, S_IRUGO | S_IWUSR, 2070 + show_pwm_auto_vrdhot_ramp, 2071 + store_pwm_auto_vrdhot_ramp); 2072 + 2073 + static ssize_t show_vid(struct device *dev, struct device_attribute *attr, 2074 + char *buf) 2075 + { 2076 + int nr = (to_sensor_dev_attr(attr))->index; 2077 + struct lm93_data *data = lm93_update_device(dev); 2078 + return sprintf(buf,"%d\n",LM93_VID_FROM_REG(data->vid[nr])); 2079 + } 2080 + 2081 + static SENSOR_DEVICE_ATTR(vid1, S_IRUGO, show_vid, NULL, 0); 2082 + static SENSOR_DEVICE_ATTR(vid2, S_IRUGO, show_vid, NULL, 1); 2083 + 2084 + static ssize_t show_prochot(struct device *dev, struct device_attribute *attr, 2085 + char *buf) 2086 + { 2087 + int nr = (to_sensor_dev_attr(attr))->index; 2088 + struct lm93_data *data = lm93_update_device(dev); 2089 + return sprintf(buf,"%d\n",data->block4[nr].cur); 2090 + } 2091 + 2092 + static SENSOR_DEVICE_ATTR(prochot1, S_IRUGO, show_prochot, NULL, 0); 2093 + static SENSOR_DEVICE_ATTR(prochot2, S_IRUGO, show_prochot, NULL, 1); 2094 + 2095 + static ssize_t show_prochot_avg(struct device *dev, 2096 + struct device_attribute *attr, char *buf) 2097 + { 2098 + int nr = (to_sensor_dev_attr(attr))->index; 2099 + struct lm93_data *data = lm93_update_device(dev); 2100 + return sprintf(buf,"%d\n",data->block4[nr].avg); 2101 + } 2102 + 2103 + static SENSOR_DEVICE_ATTR(prochot1_avg, S_IRUGO, show_prochot_avg, NULL, 0); 2104 + static SENSOR_DEVICE_ATTR(prochot2_avg, S_IRUGO, show_prochot_avg, NULL, 1); 2105 + 2106 + static ssize_t show_prochot_max(struct device *dev, 2107 + struct device_attribute *attr, char *buf) 2108 + { 2109 + int nr = (to_sensor_dev_attr(attr))->index; 2110 + struct lm93_data *data = lm93_update_device(dev); 2111 + return sprintf(buf,"%d\n",data->prochot_max[nr]); 2112 + } 2113 + 2114 + static ssize_t store_prochot_max(struct device *dev, 2115 + struct device_attribute *attr, 2116 + const char *buf, size_t count) 2117 + { 2118 + int nr = (to_sensor_dev_attr(attr))->index; 2119 + struct i2c_client *client = to_i2c_client(dev); 2120 + struct lm93_data *data = i2c_get_clientdata(client); 2121 + u32 val = simple_strtoul(buf, NULL, 10); 2122 + 2123 + mutex_lock(&data->update_lock); 2124 + data->prochot_max[nr] = LM93_PROCHOT_TO_REG(val); 2125 + lm93_write_byte(client, LM93_REG_PROCHOT_MAX(nr), 2126 + data->prochot_max[nr]); 2127 + mutex_unlock(&data->update_lock); 2128 + return count; 2129 + } 2130 + 2131 + static SENSOR_DEVICE_ATTR(prochot1_max, S_IWUSR | S_IRUGO, 2132 + show_prochot_max, store_prochot_max, 0); 2133 + static SENSOR_DEVICE_ATTR(prochot2_max, S_IWUSR | S_IRUGO, 2134 + show_prochot_max, store_prochot_max, 1); 2135 + 2136 + static const u8 prochot_override_mask[] = { 0x80, 0x40 }; 2137 + 2138 + static ssize_t show_prochot_override(struct device *dev, 2139 + struct device_attribute *attr, char *buf) 2140 + { 2141 + int nr = (to_sensor_dev_attr(attr))->index; 2142 + struct lm93_data *data = lm93_update_device(dev); 2143 + return sprintf(buf,"%d\n", 2144 + (data->prochot_override & prochot_override_mask[nr]) ? 1 : 0); 2145 + } 2146 + 2147 + static ssize_t store_prochot_override(struct device *dev, 2148 + struct device_attribute *attr, 2149 + const char *buf, size_t count) 2150 + { 2151 + int nr = (to_sensor_dev_attr(attr))->index; 2152 + struct i2c_client *client = to_i2c_client(dev); 2153 + struct lm93_data *data = i2c_get_clientdata(client); 2154 + u32 val = simple_strtoul(buf, NULL, 10); 2155 + 2156 + mutex_lock(&data->update_lock); 2157 + if (val) 2158 + data->prochot_override |= prochot_override_mask[nr]; 2159 + else 2160 + data->prochot_override &= (~prochot_override_mask[nr]); 2161 + lm93_write_byte(client, LM93_REG_PROCHOT_OVERRIDE, 2162 + data->prochot_override); 2163 + mutex_unlock(&data->update_lock); 2164 + return count; 2165 + } 2166 + 2167 + static SENSOR_DEVICE_ATTR(prochot1_override, S_IWUSR | S_IRUGO, 2168 + show_prochot_override, store_prochot_override, 0); 2169 + static SENSOR_DEVICE_ATTR(prochot2_override, S_IWUSR | S_IRUGO, 2170 + show_prochot_override, store_prochot_override, 1); 2171 + 2172 + static ssize_t show_prochot_interval(struct device *dev, 2173 + struct device_attribute *attr, char *buf) 2174 + { 2175 + int nr = (to_sensor_dev_attr(attr))->index; 2176 + struct lm93_data *data = lm93_update_device(dev); 2177 + u8 tmp; 2178 + if (nr==1) 2179 + tmp = (data->prochot_interval & 0xf0) >> 4; 2180 + else 2181 + tmp = data->prochot_interval & 0x0f; 2182 + return sprintf(buf,"%d\n",LM93_INTERVAL_FROM_REG(tmp)); 2183 + } 2184 + 2185 + static ssize_t store_prochot_interval(struct device *dev, 2186 + struct device_attribute *attr, 2187 + const char *buf, size_t count) 2188 + { 2189 + int nr = (to_sensor_dev_attr(attr))->index; 2190 + struct i2c_client *client = to_i2c_client(dev); 2191 + struct lm93_data *data = i2c_get_clientdata(client); 2192 + u32 val = simple_strtoul(buf, NULL, 10); 2193 + u8 tmp; 2194 + 2195 + mutex_lock(&data->update_lock); 2196 + tmp = lm93_read_byte(client, LM93_REG_PROCHOT_INTERVAL); 2197 + if (nr==1) 2198 + tmp = (tmp & 0x0f) | (LM93_INTERVAL_TO_REG(val) << 4); 2199 + else 2200 + tmp = (tmp & 0xf0) | LM93_INTERVAL_TO_REG(val); 2201 + data->prochot_interval = tmp; 2202 + lm93_write_byte(client, LM93_REG_PROCHOT_INTERVAL, tmp); 2203 + mutex_unlock(&data->update_lock); 2204 + return count; 2205 + } 2206 + 2207 + static SENSOR_DEVICE_ATTR(prochot1_interval, S_IWUSR | S_IRUGO, 2208 + show_prochot_interval, store_prochot_interval, 0); 2209 + static SENSOR_DEVICE_ATTR(prochot2_interval, S_IWUSR | S_IRUGO, 2210 + show_prochot_interval, store_prochot_interval, 1); 2211 + 2212 + static ssize_t show_prochot_override_duty_cycle(struct device *dev, 2213 + struct device_attribute *attr, 2214 + char *buf) 2215 + { 2216 + struct lm93_data *data = lm93_update_device(dev); 2217 + return sprintf(buf,"%d\n",data->prochot_override & 0x0f); 2218 + } 2219 + 2220 + static ssize_t store_prochot_override_duty_cycle(struct device *dev, 2221 + struct device_attribute *attr, 2222 + const char *buf, size_t count) 2223 + { 2224 + struct i2c_client *client = to_i2c_client(dev); 2225 + struct lm93_data *data = i2c_get_clientdata(client); 2226 + u32 val = simple_strtoul(buf, NULL, 10); 2227 + 2228 + mutex_lock(&data->update_lock); 2229 + data->prochot_override = (data->prochot_override & 0xf0) | 2230 + SENSORS_LIMIT(val, 0, 15); 2231 + lm93_write_byte(client, LM93_REG_PROCHOT_OVERRIDE, 2232 + data->prochot_override); 2233 + mutex_unlock(&data->update_lock); 2234 + return count; 2235 + } 2236 + 2237 + static DEVICE_ATTR(prochot_override_duty_cycle, S_IRUGO | S_IWUSR, 2238 + show_prochot_override_duty_cycle, 2239 + store_prochot_override_duty_cycle); 2240 + 2241 + static ssize_t show_prochot_short(struct device *dev, 2242 + struct device_attribute *attr, char *buf) 2243 + { 2244 + struct lm93_data *data = lm93_update_device(dev); 2245 + return sprintf(buf,"%d\n",(data->config & 0x10) ? 1 : 0); 2246 + } 2247 + 2248 + static ssize_t store_prochot_short(struct device *dev, 2249 + struct device_attribute *attr, 2250 + const char *buf, size_t count) 2251 + { 2252 + struct i2c_client *client = to_i2c_client(dev); 2253 + struct lm93_data *data = i2c_get_clientdata(client); 2254 + u32 val = simple_strtoul(buf, NULL, 10); 2255 + 2256 + mutex_lock(&data->update_lock); 2257 + if (val) 2258 + data->config |= 0x10; 2259 + else 2260 + data->config &= ~0x10; 2261 + lm93_write_byte(client, LM93_REG_CONFIG, data->config); 2262 + mutex_unlock(&data->update_lock); 2263 + return count; 2264 + } 2265 + 2266 + static DEVICE_ATTR(prochot_short, S_IRUGO | S_IWUSR, 2267 + show_prochot_short, store_prochot_short); 2268 + 2269 + static ssize_t show_vrdhot(struct device *dev, struct device_attribute *attr, 2270 + char *buf) 2271 + { 2272 + int nr = (to_sensor_dev_attr(attr))->index; 2273 + struct lm93_data *data = lm93_update_device(dev); 2274 + return sprintf(buf,"%d\n", 2275 + data->block1.host_status_1 & (1 << (nr+4)) ? 1 : 0); 2276 + } 2277 + 2278 + static SENSOR_DEVICE_ATTR(vrdhot1, S_IRUGO, show_vrdhot, NULL, 0); 2279 + static SENSOR_DEVICE_ATTR(vrdhot2, S_IRUGO, show_vrdhot, NULL, 1); 2280 + 2281 + static ssize_t show_gpio(struct device *dev, struct device_attribute *attr, 2282 + char *buf) 2283 + { 2284 + struct lm93_data *data = lm93_update_device(dev); 2285 + return sprintf(buf,"%d\n",LM93_GPI_FROM_REG(data->gpi)); 2286 + } 2287 + 2288 + static DEVICE_ATTR(gpio, S_IRUGO, show_gpio, NULL); 2289 + 2290 + static ssize_t show_alarms(struct device *dev, struct device_attribute *attr, 2291 + char *buf) 2292 + { 2293 + struct lm93_data *data = lm93_update_device(dev); 2294 + return sprintf(buf,"%d\n",LM93_ALARMS_FROM_REG(data->block1)); 2295 + } 2296 + 2297 + static DEVICE_ATTR(alarms, S_IRUGO, show_alarms, NULL); 2298 + 2299 + static struct attribute *lm93_attrs[] = { 2300 + &sensor_dev_attr_in1_input.dev_attr.attr, 2301 + &sensor_dev_attr_in2_input.dev_attr.attr, 2302 + &sensor_dev_attr_in3_input.dev_attr.attr, 2303 + &sensor_dev_attr_in4_input.dev_attr.attr, 2304 + &sensor_dev_attr_in5_input.dev_attr.attr, 2305 + &sensor_dev_attr_in6_input.dev_attr.attr, 2306 + &sensor_dev_attr_in7_input.dev_attr.attr, 2307 + &sensor_dev_attr_in8_input.dev_attr.attr, 2308 + &sensor_dev_attr_in9_input.dev_attr.attr, 2309 + &sensor_dev_attr_in10_input.dev_attr.attr, 2310 + &sensor_dev_attr_in11_input.dev_attr.attr, 2311 + &sensor_dev_attr_in12_input.dev_attr.attr, 2312 + &sensor_dev_attr_in13_input.dev_attr.attr, 2313 + &sensor_dev_attr_in14_input.dev_attr.attr, 2314 + &sensor_dev_attr_in15_input.dev_attr.attr, 2315 + &sensor_dev_attr_in16_input.dev_attr.attr, 2316 + &sensor_dev_attr_in1_min.dev_attr.attr, 2317 + &sensor_dev_attr_in2_min.dev_attr.attr, 2318 + &sensor_dev_attr_in3_min.dev_attr.attr, 2319 + &sensor_dev_attr_in4_min.dev_attr.attr, 2320 + &sensor_dev_attr_in5_min.dev_attr.attr, 2321 + &sensor_dev_attr_in6_min.dev_attr.attr, 2322 + &sensor_dev_attr_in7_min.dev_attr.attr, 2323 + &sensor_dev_attr_in8_min.dev_attr.attr, 2324 + &sensor_dev_attr_in9_min.dev_attr.attr, 2325 + &sensor_dev_attr_in10_min.dev_attr.attr, 2326 + &sensor_dev_attr_in11_min.dev_attr.attr, 2327 + &sensor_dev_attr_in12_min.dev_attr.attr, 2328 + &sensor_dev_attr_in13_min.dev_attr.attr, 2329 + &sensor_dev_attr_in14_min.dev_attr.attr, 2330 + &sensor_dev_attr_in15_min.dev_attr.attr, 2331 + &sensor_dev_attr_in16_min.dev_attr.attr, 2332 + &sensor_dev_attr_in1_max.dev_attr.attr, 2333 + &sensor_dev_attr_in2_max.dev_attr.attr, 2334 + &sensor_dev_attr_in3_max.dev_attr.attr, 2335 + &sensor_dev_attr_in4_max.dev_attr.attr, 2336 + &sensor_dev_attr_in5_max.dev_attr.attr, 2337 + &sensor_dev_attr_in6_max.dev_attr.attr, 2338 + &sensor_dev_attr_in7_max.dev_attr.attr, 2339 + &sensor_dev_attr_in8_max.dev_attr.attr, 2340 + &sensor_dev_attr_in9_max.dev_attr.attr, 2341 + &sensor_dev_attr_in10_max.dev_attr.attr, 2342 + &sensor_dev_attr_in11_max.dev_attr.attr, 2343 + &sensor_dev_attr_in12_max.dev_attr.attr, 2344 + &sensor_dev_attr_in13_max.dev_attr.attr, 2345 + &sensor_dev_attr_in14_max.dev_attr.attr, 2346 + &sensor_dev_attr_in15_max.dev_attr.attr, 2347 + &sensor_dev_attr_in16_max.dev_attr.attr, 2348 + &sensor_dev_attr_temp1_input.dev_attr.attr, 2349 + &sensor_dev_attr_temp2_input.dev_attr.attr, 2350 + &sensor_dev_attr_temp3_input.dev_attr.attr, 2351 + &sensor_dev_attr_temp1_min.dev_attr.attr, 2352 + &sensor_dev_attr_temp2_min.dev_attr.attr, 2353 + &sensor_dev_attr_temp3_min.dev_attr.attr, 2354 + &sensor_dev_attr_temp1_max.dev_attr.attr, 2355 + &sensor_dev_attr_temp2_max.dev_attr.attr, 2356 + &sensor_dev_attr_temp3_max.dev_attr.attr, 2357 + &sensor_dev_attr_temp1_auto_base.dev_attr.attr, 2358 + &sensor_dev_attr_temp2_auto_base.dev_attr.attr, 2359 + &sensor_dev_attr_temp3_auto_base.dev_attr.attr, 2360 + &sensor_dev_attr_temp1_auto_boost.dev_attr.attr, 2361 + &sensor_dev_attr_temp2_auto_boost.dev_attr.attr, 2362 + &sensor_dev_attr_temp3_auto_boost.dev_attr.attr, 2363 + &sensor_dev_attr_temp1_auto_boost_hyst.dev_attr.attr, 2364 + &sensor_dev_attr_temp2_auto_boost_hyst.dev_attr.attr, 2365 + &sensor_dev_attr_temp3_auto_boost_hyst.dev_attr.attr, 2366 + &sensor_dev_attr_temp1_auto_offset1.dev_attr.attr, 2367 + &sensor_dev_attr_temp1_auto_offset2.dev_attr.attr, 2368 + &sensor_dev_attr_temp1_auto_offset3.dev_attr.attr, 2369 + &sensor_dev_attr_temp1_auto_offset4.dev_attr.attr, 2370 + &sensor_dev_attr_temp1_auto_offset5.dev_attr.attr, 2371 + &sensor_dev_attr_temp1_auto_offset6.dev_attr.attr, 2372 + &sensor_dev_attr_temp1_auto_offset7.dev_attr.attr, 2373 + &sensor_dev_attr_temp1_auto_offset8.dev_attr.attr, 2374 + &sensor_dev_attr_temp1_auto_offset9.dev_attr.attr, 2375 + &sensor_dev_attr_temp1_auto_offset10.dev_attr.attr, 2376 + &sensor_dev_attr_temp1_auto_offset11.dev_attr.attr, 2377 + &sensor_dev_attr_temp1_auto_offset12.dev_attr.attr, 2378 + &sensor_dev_attr_temp2_auto_offset1.dev_attr.attr, 2379 + &sensor_dev_attr_temp2_auto_offset2.dev_attr.attr, 2380 + &sensor_dev_attr_temp2_auto_offset3.dev_attr.attr, 2381 + &sensor_dev_attr_temp2_auto_offset4.dev_attr.attr, 2382 + &sensor_dev_attr_temp2_auto_offset5.dev_attr.attr, 2383 + &sensor_dev_attr_temp2_auto_offset6.dev_attr.attr, 2384 + &sensor_dev_attr_temp2_auto_offset7.dev_attr.attr, 2385 + &sensor_dev_attr_temp2_auto_offset8.dev_attr.attr, 2386 + &sensor_dev_attr_temp2_auto_offset9.dev_attr.attr, 2387 + &sensor_dev_attr_temp2_auto_offset10.dev_attr.attr, 2388 + &sensor_dev_attr_temp2_auto_offset11.dev_attr.attr, 2389 + &sensor_dev_attr_temp2_auto_offset12.dev_attr.attr, 2390 + &sensor_dev_attr_temp3_auto_offset1.dev_attr.attr, 2391 + &sensor_dev_attr_temp3_auto_offset2.dev_attr.attr, 2392 + &sensor_dev_attr_temp3_auto_offset3.dev_attr.attr, 2393 + &sensor_dev_attr_temp3_auto_offset4.dev_attr.attr, 2394 + &sensor_dev_attr_temp3_auto_offset5.dev_attr.attr, 2395 + &sensor_dev_attr_temp3_auto_offset6.dev_attr.attr, 2396 + &sensor_dev_attr_temp3_auto_offset7.dev_attr.attr, 2397 + &sensor_dev_attr_temp3_auto_offset8.dev_attr.attr, 2398 + &sensor_dev_attr_temp3_auto_offset9.dev_attr.attr, 2399 + &sensor_dev_attr_temp3_auto_offset10.dev_attr.attr, 2400 + &sensor_dev_attr_temp3_auto_offset11.dev_attr.attr, 2401 + &sensor_dev_attr_temp3_auto_offset12.dev_attr.attr, 2402 + &sensor_dev_attr_temp1_auto_pwm_min.dev_attr.attr, 2403 + &sensor_dev_attr_temp2_auto_pwm_min.dev_attr.attr, 2404 + &sensor_dev_attr_temp3_auto_pwm_min.dev_attr.attr, 2405 + &sensor_dev_attr_temp1_auto_offset_hyst.dev_attr.attr, 2406 + &sensor_dev_attr_temp2_auto_offset_hyst.dev_attr.attr, 2407 + &sensor_dev_attr_temp3_auto_offset_hyst.dev_attr.attr, 2408 + &sensor_dev_attr_fan1_input.dev_attr.attr, 2409 + &sensor_dev_attr_fan2_input.dev_attr.attr, 2410 + &sensor_dev_attr_fan3_input.dev_attr.attr, 2411 + &sensor_dev_attr_fan4_input.dev_attr.attr, 2412 + &sensor_dev_attr_fan1_min.dev_attr.attr, 2413 + &sensor_dev_attr_fan2_min.dev_attr.attr, 2414 + &sensor_dev_attr_fan3_min.dev_attr.attr, 2415 + &sensor_dev_attr_fan4_min.dev_attr.attr, 2416 + &sensor_dev_attr_fan1_smart_tach.dev_attr.attr, 2417 + &sensor_dev_attr_fan2_smart_tach.dev_attr.attr, 2418 + &sensor_dev_attr_fan3_smart_tach.dev_attr.attr, 2419 + &sensor_dev_attr_fan4_smart_tach.dev_attr.attr, 2420 + &sensor_dev_attr_pwm1.dev_attr.attr, 2421 + &sensor_dev_attr_pwm2.dev_attr.attr, 2422 + &sensor_dev_attr_pwm1_enable.dev_attr.attr, 2423 + &sensor_dev_attr_pwm2_enable.dev_attr.attr, 2424 + &sensor_dev_attr_pwm1_freq.dev_attr.attr, 2425 + &sensor_dev_attr_pwm2_freq.dev_attr.attr, 2426 + &sensor_dev_attr_pwm1_auto_channels.dev_attr.attr, 2427 + &sensor_dev_attr_pwm2_auto_channels.dev_attr.attr, 2428 + &sensor_dev_attr_pwm1_auto_spinup_min.dev_attr.attr, 2429 + &sensor_dev_attr_pwm2_auto_spinup_min.dev_attr.attr, 2430 + &sensor_dev_attr_pwm1_auto_spinup_time.dev_attr.attr, 2431 + &sensor_dev_attr_pwm2_auto_spinup_time.dev_attr.attr, 2432 + &dev_attr_pwm_auto_prochot_ramp.attr, 2433 + &dev_attr_pwm_auto_vrdhot_ramp.attr, 2434 + &sensor_dev_attr_vid1.dev_attr.attr, 2435 + &sensor_dev_attr_vid2.dev_attr.attr, 2436 + &sensor_dev_attr_prochot1.dev_attr.attr, 2437 + &sensor_dev_attr_prochot2.dev_attr.attr, 2438 + &sensor_dev_attr_prochot1_avg.dev_attr.attr, 2439 + &sensor_dev_attr_prochot2_avg.dev_attr.attr, 2440 + &sensor_dev_attr_prochot1_max.dev_attr.attr, 2441 + &sensor_dev_attr_prochot2_max.dev_attr.attr, 2442 + &sensor_dev_attr_prochot1_override.dev_attr.attr, 2443 + &sensor_dev_attr_prochot2_override.dev_attr.attr, 2444 + &sensor_dev_attr_prochot1_interval.dev_attr.attr, 2445 + &sensor_dev_attr_prochot2_interval.dev_attr.attr, 2446 + &dev_attr_prochot_override_duty_cycle.attr, 2447 + &dev_attr_prochot_short.attr, 2448 + &sensor_dev_attr_vrdhot1.dev_attr.attr, 2449 + &sensor_dev_attr_vrdhot2.dev_attr.attr, 2450 + &dev_attr_gpio.attr, 2451 + &dev_attr_alarms.attr, 2452 + NULL 2453 + }; 2454 + 2455 + static struct attribute_group lm93_attr_grp = { 2456 + .attrs = lm93_attrs, 2457 + }; 2458 + 2459 + static void lm93_init_client(struct i2c_client *client) 2460 + { 2461 + int i; 2462 + u8 reg; 2463 + 2464 + /* configure VID pin input thresholds */ 2465 + reg = lm93_read_byte(client, LM93_REG_GPI_VID_CTL); 2466 + lm93_write_byte(client, LM93_REG_GPI_VID_CTL, 2467 + reg | (vid_agtl ? 0x03 : 0x00)); 2468 + 2469 + if (init) { 2470 + /* enable #ALERT pin */ 2471 + reg = lm93_read_byte(client, LM93_REG_CONFIG); 2472 + lm93_write_byte(client, LM93_REG_CONFIG, reg | 0x08); 2473 + 2474 + /* enable ASF mode for BMC status registers */ 2475 + reg = lm93_read_byte(client, LM93_REG_STATUS_CONTROL); 2476 + lm93_write_byte(client, LM93_REG_STATUS_CONTROL, reg | 0x02); 2477 + 2478 + /* set sleep state to S0 */ 2479 + lm93_write_byte(client, LM93_REG_SLEEP_CONTROL, 0); 2480 + 2481 + /* unmask #VRDHOT and dynamic VCCP (if nec) error events */ 2482 + reg = lm93_read_byte(client, LM93_REG_MISC_ERR_MASK); 2483 + reg &= ~0x03; 2484 + reg &= ~(vccp_limit_type[0] ? 0x10 : 0); 2485 + reg &= ~(vccp_limit_type[1] ? 0x20 : 0); 2486 + lm93_write_byte(client, LM93_REG_MISC_ERR_MASK, reg); 2487 + } 2488 + 2489 + /* start monitoring */ 2490 + reg = lm93_read_byte(client, LM93_REG_CONFIG); 2491 + lm93_write_byte(client, LM93_REG_CONFIG, reg | 0x01); 2492 + 2493 + /* spin until ready */ 2494 + for (i=0; i<20; i++) { 2495 + msleep(10); 2496 + if ((lm93_read_byte(client, LM93_REG_CONFIG) & 0x80) == 0x80) 2497 + return; 2498 + } 2499 + 2500 + dev_warn(&client->dev,"timed out waiting for sensor " 2501 + "chip to signal ready!\n"); 2502 + } 2503 + 2504 + static int lm93_detect(struct i2c_adapter *adapter, int address, int kind) 2505 + { 2506 + struct lm93_data *data; 2507 + struct i2c_client *client; 2508 + 2509 + int err = -ENODEV, func; 2510 + void (*update)(struct lm93_data *, struct i2c_client *); 2511 + 2512 + /* choose update routine based on bus capabilities */ 2513 + func = i2c_get_functionality(adapter); 2514 + if ( ((LM93_SMBUS_FUNC_FULL & func) == LM93_SMBUS_FUNC_FULL) && 2515 + (!disable_block) ) { 2516 + dev_dbg(&adapter->dev,"using SMBus block data transactions\n"); 2517 + update = lm93_update_client_full; 2518 + } else if ((LM93_SMBUS_FUNC_MIN & func) == LM93_SMBUS_FUNC_MIN) { 2519 + dev_dbg(&adapter->dev,"disabled SMBus block data " 2520 + "transactions\n"); 2521 + update = lm93_update_client_min; 2522 + } else { 2523 + dev_dbg(&adapter->dev,"detect failed, " 2524 + "smbus byte and/or word data not supported!\n"); 2525 + goto err_out; 2526 + } 2527 + 2528 + /* OK. For now, we presume we have a valid client. We now create the 2529 + client structure, even though we cannot fill it completely yet. 2530 + But it allows us to access lm78_{read,write}_value. */ 2531 + 2532 + if ( !(data = kzalloc(sizeof(struct lm93_data), GFP_KERNEL))) { 2533 + dev_dbg(&adapter->dev,"out of memory!\n"); 2534 + err = -ENOMEM; 2535 + goto err_out; 2536 + } 2537 + 2538 + client = &data->client; 2539 + i2c_set_clientdata(client, data); 2540 + client->addr = address; 2541 + client->adapter = adapter; 2542 + client->driver = &lm93_driver; 2543 + 2544 + /* detection */ 2545 + if (kind < 0) { 2546 + int mfr = lm93_read_byte(client, LM93_REG_MFR_ID); 2547 + 2548 + if (mfr != 0x01) { 2549 + dev_dbg(&adapter->dev,"detect failed, " 2550 + "bad manufacturer id 0x%02x!\n", mfr); 2551 + goto err_free; 2552 + } 2553 + } 2554 + 2555 + if (kind <= 0) { 2556 + int ver = lm93_read_byte(client, LM93_REG_VER); 2557 + 2558 + if ((ver == LM93_MFR_ID) || (ver == LM93_MFR_ID_PROTOTYPE)) { 2559 + kind = lm93; 2560 + } else { 2561 + dev_dbg(&adapter->dev,"detect failed, " 2562 + "bad version id 0x%02x!\n", ver); 2563 + if (kind == 0) 2564 + dev_dbg(&adapter->dev, 2565 + "(ignored 'force' parameter)\n"); 2566 + goto err_free; 2567 + } 2568 + } 2569 + 2570 + /* fill in remaining client fields */ 2571 + strlcpy(client->name, "lm93", I2C_NAME_SIZE); 2572 + dev_dbg(&adapter->dev,"loading %s at %d,0x%02x\n", 2573 + client->name, i2c_adapter_id(client->adapter), 2574 + client->addr); 2575 + 2576 + /* housekeeping */ 2577 + data->valid = 0; 2578 + data->update = update; 2579 + mutex_init(&data->update_lock); 2580 + 2581 + /* tell the I2C layer a new client has arrived */ 2582 + if ((err = i2c_attach_client(client))) 2583 + goto err_free; 2584 + 2585 + /* initialize the chip */ 2586 + lm93_init_client(client); 2587 + 2588 + err = sysfs_create_group(&client->dev.kobj, &lm93_attr_grp); 2589 + if (err) 2590 + goto err_detach; 2591 + 2592 + /* Register hwmon driver class */ 2593 + data->class_dev = hwmon_device_register(&client->dev); 2594 + if ( !IS_ERR(data->class_dev)) 2595 + return 0; 2596 + 2597 + err = PTR_ERR(data->class_dev); 2598 + dev_err(&client->dev, "error registering hwmon device.\n"); 2599 + sysfs_remove_group(&client->dev.kobj, &lm93_attr_grp); 2600 + err_detach: 2601 + i2c_detach_client(client); 2602 + err_free: 2603 + kfree(data); 2604 + err_out: 2605 + return err; 2606 + } 2607 + 2608 + /* This function is called when: 2609 + * lm93_driver is inserted (when this module is loaded), for each 2610 + available adapter 2611 + * when a new adapter is inserted (and lm93_driver is still present) */ 2612 + static int lm93_attach_adapter(struct i2c_adapter *adapter) 2613 + { 2614 + return i2c_probe(adapter, &addr_data, lm93_detect); 2615 + } 2616 + 2617 + static int lm93_detach_client(struct i2c_client *client) 2618 + { 2619 + struct lm93_data *data = i2c_get_clientdata(client); 2620 + int err = 0; 2621 + 2622 + hwmon_device_unregister(data->class_dev); 2623 + sysfs_remove_group(&client->dev.kobj, &lm93_attr_grp); 2624 + 2625 + err = i2c_detach_client(client); 2626 + if (!err) 2627 + kfree(data); 2628 + return err; 2629 + } 2630 + 2631 + static struct i2c_driver lm93_driver = { 2632 + .driver = { 2633 + .name = "lm93", 2634 + }, 2635 + .attach_adapter = lm93_attach_adapter, 2636 + .detach_client = lm93_detach_client, 2637 + }; 2638 + 2639 + static int __init lm93_init(void) 2640 + { 2641 + return i2c_add_driver(&lm93_driver); 2642 + } 2643 + 2644 + static void __exit lm93_exit(void) 2645 + { 2646 + i2c_del_driver(&lm93_driver); 2647 + } 2648 + 2649 + MODULE_AUTHOR("Mark M. Hoffman <mhoffman@lightlink.com>, " 2650 + "Hans J. Koch <hjk@linutronix.de"); 2651 + MODULE_DESCRIPTION("LM93 driver"); 2652 + MODULE_LICENSE("GPL"); 2653 + 2654 + module_init(lm93_init); 2655 + module_exit(lm93_exit);
+137 -95
drivers/hwmon/pc87360.c
··· 1 /* 2 * pc87360.c - Part of lm_sensors, Linux kernel modules 3 * for hardware monitoring 4 - * Copyright (C) 2004 Jean Delvare <khali@linux-fr.org> 5 * 6 * Copied from smsc47m1.c: 7 * Copyright (C) 2002 Mark D. Studebaker <mdsxyz123@yahoo.com> ··· 37 #include <linux/init.h> 38 #include <linux/slab.h> 39 #include <linux/jiffies.h> 40 - #include <linux/i2c.h> 41 - #include <linux/i2c-isa.h> 42 #include <linux/hwmon.h> 43 #include <linux/hwmon-sysfs.h> 44 #include <linux/hwmon-vid.h> ··· 46 #include <asm/io.h> 47 48 static u8 devid; 49 - static unsigned short address; 50 static unsigned short extra_isa[3]; 51 static u8 confreg[4]; 52 - 53 - enum chips { any_chip, pc87360, pc87363, pc87364, pc87365, pc87366 }; 54 55 static int init = 1; 56 module_param(init, int, 0); ··· 175 ((val) + 500) / 1000) 176 177 /* 178 - * Client data (each client gets its own) 179 */ 180 181 struct pc87360_data { 182 - struct i2c_client client; 183 struct class_device *class_dev; 184 struct mutex lock; 185 struct mutex update_lock; ··· 219 * Functions declaration 220 */ 221 222 - static int pc87360_detect(struct i2c_adapter *adapter); 223 - static int pc87360_detach_client(struct i2c_client *client); 224 225 static int pc87360_read_value(struct pc87360_data *data, u8 ldi, u8 bank, 226 u8 reg); 227 static void pc87360_write_value(struct pc87360_data *data, u8 ldi, u8 bank, 228 u8 reg, u8 value); 229 - static void pc87360_init_client(struct i2c_client *client, int use_thermistors); 230 static struct pc87360_data *pc87360_update_device(struct device *dev); 231 232 /* 233 - * Driver data (common to all clients) 234 */ 235 236 - static struct i2c_driver pc87360_driver = { 237 .driver = { 238 .owner = THIS_MODULE, 239 .name = "pc87360", 240 }, 241 - .attach_adapter = pc87360_detect, 242 - .detach_client = pc87360_detach_client, 243 }; 244 245 /* ··· 279 size_t count) 280 { 281 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); 282 - struct i2c_client *client = to_i2c_client(dev); 283 - struct pc87360_data *data = i2c_get_clientdata(client); 284 long fan_min = simple_strtol(buf, NULL, 10); 285 286 mutex_lock(&data->update_lock); ··· 344 size_t count) 345 { 346 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); 347 - struct i2c_client *client = to_i2c_client(dev); 348 - struct pc87360_data *data = i2c_get_clientdata(client); 349 long val = simple_strtol(buf, NULL, 10); 350 351 mutex_lock(&data->update_lock); ··· 406 size_t count) 407 { 408 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); 409 - struct i2c_client *client = to_i2c_client(dev); 410 - struct pc87360_data *data = i2c_get_clientdata(client); 411 long val = simple_strtol(buf, NULL, 10); 412 413 mutex_lock(&data->update_lock); ··· 420 size_t count) 421 { 422 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); 423 - struct i2c_client *client = to_i2c_client(dev); 424 - struct pc87360_data *data = i2c_get_clientdata(client); 425 long val = simple_strtol(buf, NULL, 10); 426 427 mutex_lock(&data->update_lock); ··· 505 } 506 static ssize_t set_vrm(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) 507 { 508 - struct i2c_client *client = to_i2c_client(dev); 509 - struct pc87360_data *data = i2c_get_clientdata(client); 510 data->vrm = simple_strtoul(buf, NULL, 10); 511 return count; 512 } ··· 577 size_t count) 578 { 579 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); 580 - struct i2c_client *client = to_i2c_client(dev); 581 - struct pc87360_data *data = i2c_get_clientdata(client); 582 long val = simple_strtol(buf, NULL, 10); 583 584 mutex_lock(&data->update_lock); ··· 591 size_t count) 592 { 593 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); 594 - struct i2c_client *client = to_i2c_client(dev); 595 - struct pc87360_data *data = i2c_get_clientdata(client); 596 long val = simple_strtol(buf, NULL, 10); 597 598 mutex_lock(&data->update_lock); ··· 605 size_t count) 606 { 607 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); 608 - struct i2c_client *client = to_i2c_client(dev); 609 - struct pc87360_data *data = i2c_get_clientdata(client); 610 long val = simple_strtol(buf, NULL, 10); 611 612 mutex_lock(&data->update_lock); ··· 705 size_t count) 706 { 707 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); 708 - struct i2c_client *client = to_i2c_client(dev); 709 - struct pc87360_data *data = i2c_get_clientdata(client); 710 long val = simple_strtol(buf, NULL, 10); 711 712 mutex_lock(&data->update_lock); ··· 719 size_t count) 720 { 721 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); 722 - struct i2c_client *client = to_i2c_client(dev); 723 - struct pc87360_data *data = i2c_get_clientdata(client); 724 long val = simple_strtol(buf, NULL, 10); 725 726 mutex_lock(&data->update_lock); ··· 733 size_t count) 734 { 735 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); 736 - struct i2c_client *client = to_i2c_client(dev); 737 - struct pc87360_data *data = i2c_get_clientdata(client); 738 long val = simple_strtol(buf, NULL, 10); 739 740 mutex_lock(&data->update_lock); ··· 804 static const struct attribute_group pc8736x_temp_group = { 805 .attrs = pc8736x_temp_attr_array, 806 }; 807 808 /* 809 * Device detection, registration and update ··· 907 return 0; 908 } 909 910 - static int pc87360_detect(struct i2c_adapter *adapter) 911 { 912 int i; 913 - struct i2c_client *client; 914 struct pc87360_data *data; 915 int err = 0; 916 const char *name = "pc87360"; 917 int use_thermistors = 0; 918 - struct device *dev; 919 920 if (!(data = kzalloc(sizeof(struct pc87360_data), GFP_KERNEL))) 921 return -ENOMEM; 922 - 923 - client = &data->client; 924 - dev = &client->dev; 925 - i2c_set_clientdata(client, data); 926 - client->addr = address; 927 - mutex_init(&data->lock); 928 - client->adapter = adapter; 929 - client->driver = &pc87360_driver; 930 - client->flags = 0; 931 932 data->fannr = 2; 933 data->innr = 0; ··· 945 break; 946 } 947 948 - strlcpy(client->name, name, sizeof(client->name)); 949 data->valid = 0; 950 mutex_init(&data->update_lock); 951 952 for (i = 0; i < 3; i++) { 953 if (((data->address[i] = extra_isa[i])) 954 && !request_region(extra_isa[i], PC87360_EXTENT, 955 pc87360_driver.driver.name)) { 956 - dev_err(&client->dev, "Region 0x%x-0x%x already " 957 "in use!\n", extra_isa[i], 958 extra_isa[i]+PC87360_EXTENT-1); 959 for (i--; i >= 0; i--) ··· 969 if (data->fannr) 970 data->fan_conf = confreg[0] | (confreg[1] << 8); 971 972 - if ((err = i2c_attach_client(client))) 973 - goto ERROR2; 974 - 975 /* Use the correct reference voltage 976 Unless both the VLM and the TMS logical devices agree to 977 use an external Vref, the internal one is used. */ ··· 980 PC87365_REG_TEMP_CONFIG); 981 } 982 data->in_vref = (i&0x02) ? 3025 : 2966; 983 - dev_dbg(&client->dev, "Using %s reference voltage\n", 984 (i&0x02) ? "external" : "internal"); 985 986 data->vid_conf = confreg[3]; ··· 999 if (devid == 0xe9 && data->address[1]) /* PC87366 */ 1000 use_thermistors = confreg[2] & 0x40; 1001 1002 - pc87360_init_client(client, use_thermistors); 1003 } 1004 1005 /* Register all-or-nothing sysfs groups */ 1006 1007 if (data->innr && 1008 - (err = sysfs_create_group(&client->dev.kobj, 1009 &pc8736x_vin_group))) 1010 goto ERROR3; 1011 1012 if (data->innr == 14 && 1013 - (err = sysfs_create_group(&client->dev.kobj, 1014 &pc8736x_therm_group))) 1015 goto ERROR3; 1016 ··· 1051 goto ERROR3; 1052 } 1053 1054 - data->class_dev = hwmon_device_register(&client->dev); 1055 if (IS_ERR(data->class_dev)) { 1056 err = PTR_ERR(data->class_dev); 1057 goto ERROR3; ··· 1062 return 0; 1063 1064 ERROR3: 1065 /* can still remove groups whose members were added individually */ 1066 - sysfs_remove_group(&client->dev.kobj, &pc8736x_temp_group); 1067 - sysfs_remove_group(&client->dev.kobj, &pc8736x_fan_group); 1068 - sysfs_remove_group(&client->dev.kobj, &pc8736x_therm_group); 1069 - sysfs_remove_group(&client->dev.kobj, &pc8736x_vin_group); 1070 - 1071 - i2c_detach_client(client); 1072 - ERROR2: 1073 for (i = 0; i < 3; i++) { 1074 if (data->address[i]) { 1075 release_region(data->address[i], PC87360_EXTENT); ··· 1078 return err; 1079 } 1080 1081 - static int pc87360_detach_client(struct i2c_client *client) 1082 { 1083 - struct pc87360_data *data = i2c_get_clientdata(client); 1084 int i; 1085 1086 hwmon_device_unregister(data->class_dev); 1087 1088 - sysfs_remove_group(&client->dev.kobj, &pc8736x_temp_group); 1089 - sysfs_remove_group(&client->dev.kobj, &pc8736x_fan_group); 1090 - sysfs_remove_group(&client->dev.kobj, &pc8736x_therm_group); 1091 - sysfs_remove_group(&client->dev.kobj, &pc8736x_vin_group); 1092 - 1093 - if ((i = i2c_detach_client(client))) 1094 - return i; 1095 1096 for (i = 0; i < 3; i++) { 1097 if (data->address[i]) { ··· 1127 mutex_unlock(&(data->lock)); 1128 } 1129 1130 - static void pc87360_init_client(struct i2c_client *client, int use_thermistors) 1131 { 1132 - struct pc87360_data *data = i2c_get_clientdata(client); 1133 int i, nr; 1134 const u8 init_in[14] = { 2, 2, 2, 2, 2, 2, 2, 1, 1, 3, 1, 2, 2, 2 }; 1135 const u8 init_temp[3] = { 2, 2, 1 }; ··· 1139 if (init >= 2 && data->innr) { 1140 reg = pc87360_read_value(data, LD_IN, NO_BANK, 1141 PC87365_REG_IN_CONVRATE); 1142 - dev_info(&client->dev, "VLM conversion set to " 1143 "1s period, 160us delay\n"); 1144 pc87360_write_value(data, LD_IN, NO_BANK, 1145 PC87365_REG_IN_CONVRATE, ··· 1153 reg = pc87360_read_value(data, LD_IN, i, 1154 PC87365_REG_IN_STATUS); 1155 if (!(reg & 0x01)) { 1156 - dev_dbg(&client->dev, "Forcibly " 1157 "enabling in%d\n", i); 1158 pc87360_write_value(data, LD_IN, i, 1159 PC87365_REG_IN_STATUS, ··· 1177 reg = pc87360_read_value(data, LD_TEMP, i, 1178 PC87365_REG_TEMP_STATUS); 1179 if (!(reg & 0x01)) { 1180 - dev_dbg(&client->dev, "Forcibly " 1181 "enabling temp%d\n", i+1); 1182 pc87360_write_value(data, LD_TEMP, i, 1183 PC87365_REG_TEMP_STATUS, ··· 1194 reg = pc87360_read_value(data, LD_TEMP, 1195 (i-11)/2, PC87365_REG_TEMP_STATUS); 1196 if (reg & 0x01) { 1197 - dev_dbg(&client->dev, "Skipping " 1198 "temp%d, pin already in use " 1199 "by temp%d\n", i-7, (i-11)/2); 1200 continue; ··· 1204 reg = pc87360_read_value(data, LD_IN, i, 1205 PC87365_REG_IN_STATUS); 1206 if (!(reg & 0x01)) { 1207 - dev_dbg(&client->dev, "Forcibly " 1208 "enabling temp%d\n", i-7); 1209 pc87360_write_value(data, LD_IN, i, 1210 PC87365_REG_TEMP_STATUS, ··· 1218 reg = pc87360_read_value(data, LD_IN, NO_BANK, 1219 PC87365_REG_IN_CONFIG); 1220 if (reg & 0x01) { 1221 - dev_dbg(&client->dev, "Forcibly " 1222 "enabling monitoring (VLM)\n"); 1223 pc87360_write_value(data, LD_IN, NO_BANK, 1224 PC87365_REG_IN_CONFIG, ··· 1230 reg = pc87360_read_value(data, LD_TEMP, NO_BANK, 1231 PC87365_REG_TEMP_CONFIG); 1232 if (reg & 0x01) { 1233 - dev_dbg(&client->dev, "Forcibly enabling " 1234 "monitoring (TMS)\n"); 1235 pc87360_write_value(data, LD_TEMP, NO_BANK, 1236 PC87365_REG_TEMP_CONFIG, ··· 1252 } 1253 } 1254 1255 - static void pc87360_autodiv(struct i2c_client *client, int nr) 1256 { 1257 - struct pc87360_data *data = i2c_get_clientdata(client); 1258 u8 old_min = data->fan_min[nr]; 1259 1260 /* Increase clock divider if needed and possible */ ··· 1264 data->fan_status[nr] += 0x20; 1265 data->fan_min[nr] >>= 1; 1266 data->fan[nr] >>= 1; 1267 - dev_dbg(&client->dev, "Increasing " 1268 "clock divider to %d for fan %d\n", 1269 FAN_DIV_FROM_REG(data->fan_status[nr]), nr+1); 1270 } ··· 1276 data->fan_status[nr] -= 0x20; 1277 data->fan_min[nr] <<= 1; 1278 data->fan[nr] <<= 1; 1279 - dev_dbg(&client->dev, "Decreasing " 1280 "clock divider to %d for fan %d\n", 1281 FAN_DIV_FROM_REG(data->fan_status[nr]), 1282 nr+1); ··· 1293 1294 static struct pc87360_data *pc87360_update_device(struct device *dev) 1295 { 1296 - struct i2c_client *client = to_i2c_client(dev); 1297 - struct pc87360_data *data = i2c_get_clientdata(client); 1298 u8 i; 1299 1300 mutex_lock(&data->update_lock); 1301 1302 if (time_after(jiffies, data->last_updated + HZ * 2) || !data->valid) { 1303 - dev_dbg(&client->dev, "Data update\n"); 1304 1305 /* Fans */ 1306 for (i = 0; i < data->fannr; i++) { ··· 1313 LD_FAN, NO_BANK, 1314 PC87360_REG_FAN_MIN(i)); 1315 /* Change clock divider if needed */ 1316 - pc87360_autodiv(client, i); 1317 /* Clear bits and write new divider */ 1318 pc87360_write_value(data, LD_FAN, NO_BANK, 1319 PC87360_REG_FAN_STATUS(i), ··· 1401 return data; 1402 } 1403 1404 static int __init pc87360_init(void) 1405 { 1406 - int i; 1407 1408 if (pc87360_find(0x2e, &devid, extra_isa) 1409 && pc87360_find(0x4e, &devid, extra_isa)) { ··· 1470 return -ENODEV; 1471 } 1472 1473 - return i2c_isa_add_driver(&pc87360_driver); 1474 } 1475 1476 static void __exit pc87360_exit(void) 1477 { 1478 - i2c_isa_del_driver(&pc87360_driver); 1479 } 1480 1481
··· 1 /* 2 * pc87360.c - Part of lm_sensors, Linux kernel modules 3 * for hardware monitoring 4 + * Copyright (C) 2004, 2007 Jean Delvare <khali@linux-fr.org> 5 * 6 * Copied from smsc47m1.c: 7 * Copyright (C) 2002 Mark D. Studebaker <mdsxyz123@yahoo.com> ··· 37 #include <linux/init.h> 38 #include <linux/slab.h> 39 #include <linux/jiffies.h> 40 + #include <linux/platform_device.h> 41 #include <linux/hwmon.h> 42 #include <linux/hwmon-sysfs.h> 43 #include <linux/hwmon-vid.h> ··· 47 #include <asm/io.h> 48 49 static u8 devid; 50 + static struct platform_device *pdev; 51 static unsigned short extra_isa[3]; 52 static u8 confreg[4]; 53 54 static int init = 1; 55 module_param(init, int, 0); ··· 178 ((val) + 500) / 1000) 179 180 /* 181 + * Device data 182 */ 183 184 struct pc87360_data { 185 + const char *name; 186 struct class_device *class_dev; 187 struct mutex lock; 188 struct mutex update_lock; ··· 222 * Functions declaration 223 */ 224 225 + static int pc87360_probe(struct platform_device *pdev); 226 + static int pc87360_remove(struct platform_device *pdev); 227 228 static int pc87360_read_value(struct pc87360_data *data, u8 ldi, u8 bank, 229 u8 reg); 230 static void pc87360_write_value(struct pc87360_data *data, u8 ldi, u8 bank, 231 u8 reg, u8 value); 232 + static void pc87360_init_device(struct platform_device *pdev, 233 + int use_thermistors); 234 static struct pc87360_data *pc87360_update_device(struct device *dev); 235 236 /* 237 + * Driver data 238 */ 239 240 + static struct platform_driver pc87360_driver = { 241 .driver = { 242 .owner = THIS_MODULE, 243 .name = "pc87360", 244 }, 245 + .probe = pc87360_probe, 246 + .remove = __devexit_p(pc87360_remove), 247 }; 248 249 /* ··· 281 size_t count) 282 { 283 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); 284 + struct pc87360_data *data = dev_get_drvdata(dev); 285 long fan_min = simple_strtol(buf, NULL, 10); 286 287 mutex_lock(&data->update_lock); ··· 347 size_t count) 348 { 349 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); 350 + struct pc87360_data *data = dev_get_drvdata(dev); 351 long val = simple_strtol(buf, NULL, 10); 352 353 mutex_lock(&data->update_lock); ··· 410 size_t count) 411 { 412 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); 413 + struct pc87360_data *data = dev_get_drvdata(dev); 414 long val = simple_strtol(buf, NULL, 10); 415 416 mutex_lock(&data->update_lock); ··· 425 size_t count) 426 { 427 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); 428 + struct pc87360_data *data = dev_get_drvdata(dev); 429 long val = simple_strtol(buf, NULL, 10); 430 431 mutex_lock(&data->update_lock); ··· 511 } 512 static ssize_t set_vrm(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) 513 { 514 + struct pc87360_data *data = dev_get_drvdata(dev); 515 data->vrm = simple_strtoul(buf, NULL, 10); 516 return count; 517 } ··· 584 size_t count) 585 { 586 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); 587 + struct pc87360_data *data = dev_get_drvdata(dev); 588 long val = simple_strtol(buf, NULL, 10); 589 590 mutex_lock(&data->update_lock); ··· 599 size_t count) 600 { 601 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); 602 + struct pc87360_data *data = dev_get_drvdata(dev); 603 long val = simple_strtol(buf, NULL, 10); 604 605 mutex_lock(&data->update_lock); ··· 614 size_t count) 615 { 616 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); 617 + struct pc87360_data *data = dev_get_drvdata(dev); 618 long val = simple_strtol(buf, NULL, 10); 619 620 mutex_lock(&data->update_lock); ··· 715 size_t count) 716 { 717 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); 718 + struct pc87360_data *data = dev_get_drvdata(dev); 719 long val = simple_strtol(buf, NULL, 10); 720 721 mutex_lock(&data->update_lock); ··· 730 size_t count) 731 { 732 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); 733 + struct pc87360_data *data = dev_get_drvdata(dev); 734 long val = simple_strtol(buf, NULL, 10); 735 736 mutex_lock(&data->update_lock); ··· 745 size_t count) 746 { 747 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); 748 + struct pc87360_data *data = dev_get_drvdata(dev); 749 long val = simple_strtol(buf, NULL, 10); 750 751 mutex_lock(&data->update_lock); ··· 817 static const struct attribute_group pc8736x_temp_group = { 818 .attrs = pc8736x_temp_attr_array, 819 }; 820 + 821 + static ssize_t show_name(struct device *dev, struct device_attribute 822 + *devattr, char *buf) 823 + { 824 + struct pc87360_data *data = dev_get_drvdata(dev); 825 + return sprintf(buf, "%s\n", data->name); 826 + } 827 + static DEVICE_ATTR(name, S_IRUGO, show_name, NULL); 828 829 /* 830 * Device detection, registration and update ··· 912 return 0; 913 } 914 915 + static int __devinit pc87360_probe(struct platform_device *pdev) 916 { 917 int i; 918 struct pc87360_data *data; 919 int err = 0; 920 const char *name = "pc87360"; 921 int use_thermistors = 0; 922 + struct device *dev = &pdev->dev; 923 924 if (!(data = kzalloc(sizeof(struct pc87360_data), GFP_KERNEL))) 925 return -ENOMEM; 926 927 data->fannr = 2; 928 data->innr = 0; ··· 960 break; 961 } 962 963 + data->name = name; 964 data->valid = 0; 965 + mutex_init(&data->lock); 966 mutex_init(&data->update_lock); 967 + platform_set_drvdata(pdev, data); 968 969 for (i = 0; i < 3; i++) { 970 if (((data->address[i] = extra_isa[i])) 971 && !request_region(extra_isa[i], PC87360_EXTENT, 972 pc87360_driver.driver.name)) { 973 + dev_err(dev, "Region 0x%x-0x%x already " 974 "in use!\n", extra_isa[i], 975 extra_isa[i]+PC87360_EXTENT-1); 976 for (i--; i >= 0; i--) ··· 982 if (data->fannr) 983 data->fan_conf = confreg[0] | (confreg[1] << 8); 984 985 /* Use the correct reference voltage 986 Unless both the VLM and the TMS logical devices agree to 987 use an external Vref, the internal one is used. */ ··· 996 PC87365_REG_TEMP_CONFIG); 997 } 998 data->in_vref = (i&0x02) ? 3025 : 2966; 999 + dev_dbg(dev, "Using %s reference voltage\n", 1000 (i&0x02) ? "external" : "internal"); 1001 1002 data->vid_conf = confreg[3]; ··· 1015 if (devid == 0xe9 && data->address[1]) /* PC87366 */ 1016 use_thermistors = confreg[2] & 0x40; 1017 1018 + pc87360_init_device(pdev, use_thermistors); 1019 } 1020 1021 /* Register all-or-nothing sysfs groups */ 1022 1023 if (data->innr && 1024 + (err = sysfs_create_group(&dev->kobj, 1025 &pc8736x_vin_group))) 1026 goto ERROR3; 1027 1028 if (data->innr == 14 && 1029 + (err = sysfs_create_group(&dev->kobj, 1030 &pc8736x_therm_group))) 1031 goto ERROR3; 1032 ··· 1067 goto ERROR3; 1068 } 1069 1070 + if ((err = device_create_file(dev, &dev_attr_name))) 1071 + goto ERROR3; 1072 + 1073 + data->class_dev = hwmon_device_register(dev); 1074 if (IS_ERR(data->class_dev)) { 1075 err = PTR_ERR(data->class_dev); 1076 goto ERROR3; ··· 1075 return 0; 1076 1077 ERROR3: 1078 + device_remove_file(dev, &dev_attr_name); 1079 /* can still remove groups whose members were added individually */ 1080 + sysfs_remove_group(&dev->kobj, &pc8736x_temp_group); 1081 + sysfs_remove_group(&dev->kobj, &pc8736x_fan_group); 1082 + sysfs_remove_group(&dev->kobj, &pc8736x_therm_group); 1083 + sysfs_remove_group(&dev->kobj, &pc8736x_vin_group); 1084 for (i = 0; i < 3; i++) { 1085 if (data->address[i]) { 1086 release_region(data->address[i], PC87360_EXTENT); ··· 1093 return err; 1094 } 1095 1096 + static int __devexit pc87360_remove(struct platform_device *pdev) 1097 { 1098 + struct pc87360_data *data = platform_get_drvdata(pdev); 1099 int i; 1100 1101 hwmon_device_unregister(data->class_dev); 1102 1103 + device_remove_file(&pdev->dev, &dev_attr_name); 1104 + sysfs_remove_group(&pdev->dev.kobj, &pc8736x_temp_group); 1105 + sysfs_remove_group(&pdev->dev.kobj, &pc8736x_fan_group); 1106 + sysfs_remove_group(&pdev->dev.kobj, &pc8736x_therm_group); 1107 + sysfs_remove_group(&pdev->dev.kobj, &pc8736x_vin_group); 1108 1109 for (i = 0; i < 3; i++) { 1110 if (data->address[i]) { ··· 1144 mutex_unlock(&(data->lock)); 1145 } 1146 1147 + static void pc87360_init_device(struct platform_device *pdev, 1148 + int use_thermistors) 1149 { 1150 + struct pc87360_data *data = platform_get_drvdata(pdev); 1151 int i, nr; 1152 const u8 init_in[14] = { 2, 2, 2, 2, 2, 2, 2, 1, 1, 3, 1, 2, 2, 2 }; 1153 const u8 init_temp[3] = { 2, 2, 1 }; ··· 1155 if (init >= 2 && data->innr) { 1156 reg = pc87360_read_value(data, LD_IN, NO_BANK, 1157 PC87365_REG_IN_CONVRATE); 1158 + dev_info(&pdev->dev, "VLM conversion set to " 1159 "1s period, 160us delay\n"); 1160 pc87360_write_value(data, LD_IN, NO_BANK, 1161 PC87365_REG_IN_CONVRATE, ··· 1169 reg = pc87360_read_value(data, LD_IN, i, 1170 PC87365_REG_IN_STATUS); 1171 if (!(reg & 0x01)) { 1172 + dev_dbg(&pdev->dev, "Forcibly " 1173 "enabling in%d\n", i); 1174 pc87360_write_value(data, LD_IN, i, 1175 PC87365_REG_IN_STATUS, ··· 1193 reg = pc87360_read_value(data, LD_TEMP, i, 1194 PC87365_REG_TEMP_STATUS); 1195 if (!(reg & 0x01)) { 1196 + dev_dbg(&pdev->dev, "Forcibly " 1197 "enabling temp%d\n", i+1); 1198 pc87360_write_value(data, LD_TEMP, i, 1199 PC87365_REG_TEMP_STATUS, ··· 1210 reg = pc87360_read_value(data, LD_TEMP, 1211 (i-11)/2, PC87365_REG_TEMP_STATUS); 1212 if (reg & 0x01) { 1213 + dev_dbg(&pdev->dev, "Skipping " 1214 "temp%d, pin already in use " 1215 "by temp%d\n", i-7, (i-11)/2); 1216 continue; ··· 1220 reg = pc87360_read_value(data, LD_IN, i, 1221 PC87365_REG_IN_STATUS); 1222 if (!(reg & 0x01)) { 1223 + dev_dbg(&pdev->dev, "Forcibly " 1224 "enabling temp%d\n", i-7); 1225 pc87360_write_value(data, LD_IN, i, 1226 PC87365_REG_TEMP_STATUS, ··· 1234 reg = pc87360_read_value(data, LD_IN, NO_BANK, 1235 PC87365_REG_IN_CONFIG); 1236 if (reg & 0x01) { 1237 + dev_dbg(&pdev->dev, "Forcibly " 1238 "enabling monitoring (VLM)\n"); 1239 pc87360_write_value(data, LD_IN, NO_BANK, 1240 PC87365_REG_IN_CONFIG, ··· 1246 reg = pc87360_read_value(data, LD_TEMP, NO_BANK, 1247 PC87365_REG_TEMP_CONFIG); 1248 if (reg & 0x01) { 1249 + dev_dbg(&pdev->dev, "Forcibly enabling " 1250 "monitoring (TMS)\n"); 1251 pc87360_write_value(data, LD_TEMP, NO_BANK, 1252 PC87365_REG_TEMP_CONFIG, ··· 1268 } 1269 } 1270 1271 + static void pc87360_autodiv(struct device *dev, int nr) 1272 { 1273 + struct pc87360_data *data = dev_get_drvdata(dev); 1274 u8 old_min = data->fan_min[nr]; 1275 1276 /* Increase clock divider if needed and possible */ ··· 1280 data->fan_status[nr] += 0x20; 1281 data->fan_min[nr] >>= 1; 1282 data->fan[nr] >>= 1; 1283 + dev_dbg(dev, "Increasing " 1284 "clock divider to %d for fan %d\n", 1285 FAN_DIV_FROM_REG(data->fan_status[nr]), nr+1); 1286 } ··· 1292 data->fan_status[nr] -= 0x20; 1293 data->fan_min[nr] <<= 1; 1294 data->fan[nr] <<= 1; 1295 + dev_dbg(dev, "Decreasing " 1296 "clock divider to %d for fan %d\n", 1297 FAN_DIV_FROM_REG(data->fan_status[nr]), 1298 nr+1); ··· 1309 1310 static struct pc87360_data *pc87360_update_device(struct device *dev) 1311 { 1312 + struct pc87360_data *data = dev_get_drvdata(dev); 1313 u8 i; 1314 1315 mutex_lock(&data->update_lock); 1316 1317 if (time_after(jiffies, data->last_updated + HZ * 2) || !data->valid) { 1318 + dev_dbg(dev, "Data update\n"); 1319 1320 /* Fans */ 1321 for (i = 0; i < data->fannr; i++) { ··· 1330 LD_FAN, NO_BANK, 1331 PC87360_REG_FAN_MIN(i)); 1332 /* Change clock divider if needed */ 1333 + pc87360_autodiv(dev, i); 1334 /* Clear bits and write new divider */ 1335 pc87360_write_value(data, LD_FAN, NO_BANK, 1336 PC87360_REG_FAN_STATUS(i), ··· 1418 return data; 1419 } 1420 1421 + static int __init pc87360_device_add(unsigned short address) 1422 + { 1423 + struct resource res = { 1424 + .name = "pc87360", 1425 + .flags = IORESOURCE_IO, 1426 + }; 1427 + int err, i; 1428 + 1429 + pdev = platform_device_alloc("pc87360", address); 1430 + if (!pdev) { 1431 + err = -ENOMEM; 1432 + printk(KERN_ERR "pc87360: Device allocation failed\n"); 1433 + goto exit; 1434 + } 1435 + 1436 + for (i = 0; i < 3; i++) { 1437 + if (!extra_isa[i]) 1438 + continue; 1439 + res.start = extra_isa[i]; 1440 + res.end = extra_isa[i] + PC87360_EXTENT - 1; 1441 + err = platform_device_add_resources(pdev, &res, 1); 1442 + if (err) { 1443 + printk(KERN_ERR "pc87360: Device resource[%d] " 1444 + "addition failed (%d)\n", i, err); 1445 + goto exit_device_put; 1446 + } 1447 + } 1448 + 1449 + err = platform_device_add(pdev); 1450 + if (err) { 1451 + printk(KERN_ERR "pc87360: Device addition failed (%d)\n", 1452 + err); 1453 + goto exit_device_put; 1454 + } 1455 + 1456 + return 0; 1457 + 1458 + exit_device_put: 1459 + platform_device_put(pdev); 1460 + exit: 1461 + return err; 1462 + } 1463 + 1464 static int __init pc87360_init(void) 1465 { 1466 + int err, i; 1467 + unsigned short address = 0; 1468 1469 if (pc87360_find(0x2e, &devid, extra_isa) 1470 && pc87360_find(0x4e, &devid, extra_isa)) { ··· 1443 return -ENODEV; 1444 } 1445 1446 + err = platform_driver_register(&pc87360_driver); 1447 + if (err) 1448 + goto exit; 1449 + 1450 + /* Sets global pdev as a side effect */ 1451 + err = pc87360_device_add(address); 1452 + if (err) 1453 + goto exit_driver; 1454 + 1455 + return 0; 1456 + 1457 + exit_driver: 1458 + platform_driver_unregister(&pc87360_driver); 1459 + exit: 1460 + return err; 1461 } 1462 1463 static void __exit pc87360_exit(void) 1464 { 1465 + platform_device_unregister(pdev); 1466 + platform_driver_unregister(&pc87360_driver); 1467 } 1468 1469
+1 -1
drivers/hwmon/pc87427.c
··· 484 struct resource *res; 485 int i; 486 487 - platform_set_drvdata(pdev, NULL); 488 hwmon_device_unregister(data->class_dev); 489 device_remove_file(&pdev->dev, &dev_attr_name); 490 for (i = 0; i < 8; i++) { ··· 491 continue; 492 sysfs_remove_group(&pdev->dev.kobj, &pc87427_group_fan[i]); 493 } 494 kfree(data); 495 496 res = platform_get_resource(pdev, IORESOURCE_IO, 0);
··· 484 struct resource *res; 485 int i; 486 487 hwmon_device_unregister(data->class_dev); 488 device_remove_file(&pdev->dev, &dev_attr_name); 489 for (i = 0; i < 8; i++) { ··· 492 continue; 493 sysfs_remove_group(&pdev->dev.kobj, &pc87427_group_fan[i]); 494 } 495 + platform_set_drvdata(pdev, NULL); 496 kfree(data); 497 498 res = platform_get_resource(pdev, IORESOURCE_IO, 0);
+255 -255
drivers/hwmon/sis5595.c
··· 54 #include <linux/slab.h> 55 #include <linux/ioport.h> 56 #include <linux/pci.h> 57 - #include <linux/i2c.h> 58 - #include <linux/i2c-isa.h> 59 #include <linux/hwmon.h> 60 #include <linux/err.h> 61 #include <linux/init.h> 62 #include <linux/jiffies.h> ··· 72 MODULE_PARM_DESC(force_addr, 73 "Initialize the base address of the sensors"); 74 75 - /* Device address 76 - Note that we can't determine the ISA address until we have initialized 77 - our module */ 78 - static unsigned short address; 79 80 /* Many SIS5595 constants specified below */ 81 82 /* Length of ISA address segment */ 83 #define SIS5595_EXTENT 8 84 /* PCI Config Registers */ 85 - #define SIS5595_REVISION_REG 0x08 86 #define SIS5595_BASE_REG 0x68 87 #define SIS5595_PIN_REG 0x7A 88 #define SIS5595_ENABLE_REG 0x7B ··· 161 /* For each registered chip, we need to keep some data in memory. 162 The structure is dynamically allocated. */ 163 struct sis5595_data { 164 - struct i2c_client client; 165 struct class_device *class_dev; 166 struct mutex lock; 167 ··· 186 187 static struct pci_dev *s_bridge; /* pointer to the (only) sis5595 */ 188 189 - static int sis5595_detect(struct i2c_adapter *adapter); 190 - static int sis5595_detach_client(struct i2c_client *client); 191 192 - static int sis5595_read_value(struct i2c_client *client, u8 reg); 193 - static int sis5595_write_value(struct i2c_client *client, u8 reg, u8 value); 194 static struct sis5595_data *sis5595_update_device(struct device *dev); 195 - static void sis5595_init_client(struct i2c_client *client); 196 197 - static struct i2c_driver sis5595_driver = { 198 .driver = { 199 .owner = THIS_MODULE, 200 .name = "sis5595", 201 }, 202 - .attach_adapter = sis5595_detect, 203 - .detach_client = sis5595_detach_client, 204 }; 205 206 /* 4 Voltages */ 207 - static ssize_t show_in(struct device *dev, char *buf, int nr) 208 { 209 struct sis5595_data *data = sis5595_update_device(dev); 210 return sprintf(buf, "%d\n", IN_FROM_REG(data->in[nr])); 211 } 212 213 - static ssize_t show_in_min(struct device *dev, char *buf, int nr) 214 { 215 struct sis5595_data *data = sis5595_update_device(dev); 216 return sprintf(buf, "%d\n", IN_FROM_REG(data->in_min[nr])); 217 } 218 219 - static ssize_t show_in_max(struct device *dev, char *buf, int nr) 220 { 221 struct sis5595_data *data = sis5595_update_device(dev); 222 return sprintf(buf, "%d\n", IN_FROM_REG(data->in_max[nr])); 223 } 224 225 - static ssize_t set_in_min(struct device *dev, const char *buf, 226 - size_t count, int nr) 227 { 228 - struct i2c_client *client = to_i2c_client(dev); 229 - struct sis5595_data *data = i2c_get_clientdata(client); 230 unsigned long val = simple_strtoul(buf, NULL, 10); 231 232 mutex_lock(&data->update_lock); 233 data->in_min[nr] = IN_TO_REG(val); 234 - sis5595_write_value(client, SIS5595_REG_IN_MIN(nr), data->in_min[nr]); 235 mutex_unlock(&data->update_lock); 236 return count; 237 } 238 239 - static ssize_t set_in_max(struct device *dev, const char *buf, 240 - size_t count, int nr) 241 { 242 - struct i2c_client *client = to_i2c_client(dev); 243 - struct sis5595_data *data = i2c_get_clientdata(client); 244 unsigned long val = simple_strtoul(buf, NULL, 10); 245 246 mutex_lock(&data->update_lock); 247 data->in_max[nr] = IN_TO_REG(val); 248 - sis5595_write_value(client, SIS5595_REG_IN_MAX(nr), data->in_max[nr]); 249 mutex_unlock(&data->update_lock); 250 return count; 251 } 252 253 #define show_in_offset(offset) \ 254 - static ssize_t \ 255 - show_in##offset (struct device *dev, struct device_attribute *attr, char *buf) \ 256 - { \ 257 - return show_in(dev, buf, offset); \ 258 - } \ 259 - static DEVICE_ATTR(in##offset##_input, S_IRUGO, \ 260 - show_in##offset, NULL); \ 261 - static ssize_t \ 262 - show_in##offset##_min (struct device *dev, struct device_attribute *attr, char *buf) \ 263 - { \ 264 - return show_in_min(dev, buf, offset); \ 265 - } \ 266 - static ssize_t \ 267 - show_in##offset##_max (struct device *dev, struct device_attribute *attr, char *buf) \ 268 - { \ 269 - return show_in_max(dev, buf, offset); \ 270 - } \ 271 - static ssize_t set_in##offset##_min (struct device *dev, struct device_attribute *attr, \ 272 - const char *buf, size_t count) \ 273 - { \ 274 - return set_in_min(dev, buf, count, offset); \ 275 - } \ 276 - static ssize_t set_in##offset##_max (struct device *dev, struct device_attribute *attr, \ 277 - const char *buf, size_t count) \ 278 - { \ 279 - return set_in_max(dev, buf, count, offset); \ 280 - } \ 281 - static DEVICE_ATTR(in##offset##_min, S_IRUGO | S_IWUSR, \ 282 - show_in##offset##_min, set_in##offset##_min); \ 283 - static DEVICE_ATTR(in##offset##_max, S_IRUGO | S_IWUSR, \ 284 - show_in##offset##_max, set_in##offset##_max); 285 286 show_in_offset(0); 287 show_in_offset(1); ··· 290 291 static ssize_t set_temp_over(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) 292 { 293 - struct i2c_client *client = to_i2c_client(dev); 294 - struct sis5595_data *data = i2c_get_clientdata(client); 295 long val = simple_strtol(buf, NULL, 10); 296 297 mutex_lock(&data->update_lock); 298 data->temp_over = TEMP_TO_REG(val); 299 - sis5595_write_value(client, SIS5595_REG_TEMP_OVER, data->temp_over); 300 mutex_unlock(&data->update_lock); 301 return count; 302 } ··· 308 309 static ssize_t set_temp_hyst(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) 310 { 311 - struct i2c_client *client = to_i2c_client(dev); 312 - struct sis5595_data *data = i2c_get_clientdata(client); 313 long val = simple_strtol(buf, NULL, 10); 314 315 mutex_lock(&data->update_lock); 316 data->temp_hyst = TEMP_TO_REG(val); 317 - sis5595_write_value(client, SIS5595_REG_TEMP_HYST, data->temp_hyst); 318 mutex_unlock(&data->update_lock); 319 return count; 320 } ··· 325 show_temp_hyst, set_temp_hyst); 326 327 /* 2 Fans */ 328 - static ssize_t show_fan(struct device *dev, char *buf, int nr) 329 { 330 struct sis5595_data *data = sis5595_update_device(dev); 331 return sprintf(buf, "%d\n", FAN_FROM_REG(data->fan[nr], 332 DIV_FROM_REG(data->fan_div[nr])) ); 333 } 334 335 - static ssize_t show_fan_min(struct device *dev, char *buf, int nr) 336 { 337 struct sis5595_data *data = sis5595_update_device(dev); 338 return sprintf(buf,"%d\n", FAN_FROM_REG(data->fan_min[nr], 339 DIV_FROM_REG(data->fan_div[nr])) ); 340 } 341 342 - static ssize_t set_fan_min(struct device *dev, const char *buf, 343 - size_t count, int nr) 344 { 345 - struct i2c_client *client = to_i2c_client(dev); 346 - struct sis5595_data *data = i2c_get_clientdata(client); 347 unsigned long val = simple_strtoul(buf, NULL, 10); 348 349 mutex_lock(&data->update_lock); 350 data->fan_min[nr] = FAN_TO_REG(val, DIV_FROM_REG(data->fan_div[nr])); 351 - sis5595_write_value(client, SIS5595_REG_FAN_MIN(nr), data->fan_min[nr]); 352 mutex_unlock(&data->update_lock); 353 return count; 354 } 355 356 - static ssize_t show_fan_div(struct device *dev, char *buf, int nr) 357 { 358 struct sis5595_data *data = sis5595_update_device(dev); 359 return sprintf(buf, "%d\n", DIV_FROM_REG(data->fan_div[nr]) ); 360 } 361 ··· 373 determined in part by the fan divisor. This follows the principle of 374 least surprise; the user doesn't expect the fan minimum to change just 375 because the divisor changed. */ 376 - static ssize_t set_fan_div(struct device *dev, const char *buf, 377 - size_t count, int nr) 378 { 379 - struct i2c_client *client = to_i2c_client(dev); 380 - struct sis5595_data *data = i2c_get_clientdata(client); 381 unsigned long min; 382 unsigned long val = simple_strtoul(buf, NULL, 10); 383 int reg; ··· 386 mutex_lock(&data->update_lock); 387 min = FAN_FROM_REG(data->fan_min[nr], 388 DIV_FROM_REG(data->fan_div[nr])); 389 - reg = sis5595_read_value(client, SIS5595_REG_FANDIV); 390 391 switch (val) { 392 case 1: data->fan_div[nr] = 0; break; ··· 394 case 4: data->fan_div[nr] = 2; break; 395 case 8: data->fan_div[nr] = 3; break; 396 default: 397 - dev_err(&client->dev, "fan_div value %ld not " 398 "supported. Choose one of 1, 2, 4 or 8!\n", val); 399 mutex_unlock(&data->update_lock); 400 return -EINVAL; ··· 408 reg = (reg & 0x3f) | (data->fan_div[nr] << 6); 409 break; 410 } 411 - sis5595_write_value(client, SIS5595_REG_FANDIV, reg); 412 data->fan_min[nr] = 413 FAN_TO_REG(min, DIV_FROM_REG(data->fan_div[nr])); 414 - sis5595_write_value(client, SIS5595_REG_FAN_MIN(nr), data->fan_min[nr]); 415 mutex_unlock(&data->update_lock); 416 return count; 417 } 418 419 #define show_fan_offset(offset) \ 420 - static ssize_t show_fan_##offset (struct device *dev, struct device_attribute *attr, char *buf) \ 421 - { \ 422 - return show_fan(dev, buf, offset - 1); \ 423 - } \ 424 - static ssize_t show_fan_##offset##_min (struct device *dev, struct device_attribute *attr, char *buf) \ 425 - { \ 426 - return show_fan_min(dev, buf, offset - 1); \ 427 - } \ 428 - static ssize_t show_fan_##offset##_div (struct device *dev, struct device_attribute *attr, char *buf) \ 429 - { \ 430 - return show_fan_div(dev, buf, offset - 1); \ 431 - } \ 432 - static ssize_t set_fan_##offset##_min (struct device *dev, struct device_attribute *attr, \ 433 - const char *buf, size_t count) \ 434 - { \ 435 - return set_fan_min(dev, buf, count, offset - 1); \ 436 - } \ 437 - static DEVICE_ATTR(fan##offset##_input, S_IRUGO, show_fan_##offset, NULL);\ 438 - static DEVICE_ATTR(fan##offset##_min, S_IRUGO | S_IWUSR, \ 439 - show_fan_##offset##_min, set_fan_##offset##_min); 440 441 show_fan_offset(1); 442 show_fan_offset(2); 443 - 444 - static ssize_t set_fan_1_div(struct device *dev, struct device_attribute *attr, const char *buf, 445 - size_t count) 446 - { 447 - return set_fan_div(dev, buf, count, 0) ; 448 - } 449 - 450 - static ssize_t set_fan_2_div(struct device *dev, struct device_attribute *attr, const char *buf, 451 - size_t count) 452 - { 453 - return set_fan_div(dev, buf, count, 1) ; 454 - } 455 - static DEVICE_ATTR(fan1_div, S_IRUGO | S_IWUSR, 456 - show_fan_1_div, set_fan_1_div); 457 - static DEVICE_ATTR(fan2_div, S_IRUGO | S_IWUSR, 458 - show_fan_2_div, set_fan_2_div); 459 460 /* Alarms */ 461 static ssize_t show_alarms(struct device *dev, struct device_attribute *attr, char *buf) ··· 435 } 436 static DEVICE_ATTR(alarms, S_IRUGO, show_alarms, NULL); 437 438 - static struct attribute *sis5595_attributes[] = { 439 - &dev_attr_in0_input.attr, 440 - &dev_attr_in0_min.attr, 441 - &dev_attr_in0_max.attr, 442 - &dev_attr_in1_input.attr, 443 - &dev_attr_in1_min.attr, 444 - &dev_attr_in1_max.attr, 445 - &dev_attr_in2_input.attr, 446 - &dev_attr_in2_min.attr, 447 - &dev_attr_in2_max.attr, 448 - &dev_attr_in3_input.attr, 449 - &dev_attr_in3_min.attr, 450 - &dev_attr_in3_max.attr, 451 452 - &dev_attr_fan1_input.attr, 453 - &dev_attr_fan1_min.attr, 454 - &dev_attr_fan1_div.attr, 455 - &dev_attr_fan2_input.attr, 456 - &dev_attr_fan2_min.attr, 457 - &dev_attr_fan2_div.attr, 458 459 &dev_attr_alarms.attr, 460 NULL 461 }; 462 ··· 474 }; 475 476 static struct attribute *sis5595_attributes_opt[] = { 477 - &dev_attr_in4_input.attr, 478 - &dev_attr_in4_min.attr, 479 - &dev_attr_in4_max.attr, 480 481 &dev_attr_temp1_input.attr, 482 &dev_attr_temp1_max.attr, ··· 489 }; 490 491 /* This is called when the module is loaded */ 492 - static int sis5595_detect(struct i2c_adapter *adapter) 493 { 494 int err = 0; 495 int i; 496 - struct i2c_client *new_client; 497 struct sis5595_data *data; 498 char val; 499 - u16 a; 500 501 - if (force_addr) 502 - address = force_addr & ~(SIS5595_EXTENT - 1); 503 /* Reserve the ISA region */ 504 - if (!request_region(address, SIS5595_EXTENT, 505 sis5595_driver.driver.name)) { 506 err = -EBUSY; 507 goto exit; 508 - } 509 - if (force_addr) { 510 - dev_warn(&adapter->dev, "forcing ISA address 0x%04X\n", address); 511 - if (PCIBIOS_SUCCESSFUL != 512 - pci_write_config_word(s_bridge, SIS5595_BASE_REG, address)) 513 - goto exit_release; 514 - if (PCIBIOS_SUCCESSFUL != 515 - pci_read_config_word(s_bridge, SIS5595_BASE_REG, &a)) 516 - goto exit_release; 517 - if ((a & ~(SIS5595_EXTENT - 1)) != address) 518 - /* doesn't work for some chips? */ 519 - goto exit_release; 520 - } 521 - 522 - if (PCIBIOS_SUCCESSFUL != 523 - pci_read_config_byte(s_bridge, SIS5595_ENABLE_REG, &val)) { 524 - goto exit_release; 525 - } 526 - if ((val & 0x80) == 0) { 527 - if (PCIBIOS_SUCCESSFUL != 528 - pci_write_config_byte(s_bridge, SIS5595_ENABLE_REG, 529 - val | 0x80)) 530 - goto exit_release; 531 - if (PCIBIOS_SUCCESSFUL != 532 - pci_read_config_byte(s_bridge, SIS5595_ENABLE_REG, &val)) 533 - goto exit_release; 534 - if ((val & 0x80) == 0) 535 - /* doesn't work for some chips! */ 536 - goto exit_release; 537 } 538 539 if (!(data = kzalloc(sizeof(struct sis5595_data), GFP_KERNEL))) { ··· 510 goto exit_release; 511 } 512 513 - new_client = &data->client; 514 - new_client->addr = address; 515 mutex_init(&data->lock); 516 - i2c_set_clientdata(new_client, data); 517 - new_client->adapter = adapter; 518 - new_client->driver = &sis5595_driver; 519 - new_client->flags = 0; 520 521 /* Check revision and pin registers to determine whether 4 or 5 voltages */ 522 - pci_read_config_byte(s_bridge, SIS5595_REVISION_REG, &(data->revision)); 523 /* 4 voltages, 1 temp */ 524 data->maxins = 3; 525 if (data->revision >= REV2MIN) { ··· 527 data->maxins = 4; 528 } 529 530 - /* Fill in the remaining client fields and put it into the global list */ 531 - strlcpy(new_client->name, "sis5595", I2C_NAME_SIZE); 532 - 533 - data->valid = 0; 534 - mutex_init(&data->update_lock); 535 - 536 - /* Tell the I2C layer a new client has arrived */ 537 - if ((err = i2c_attach_client(new_client))) 538 - goto exit_free; 539 - 540 /* Initialize the SIS5595 chip */ 541 - sis5595_init_client(new_client); 542 543 /* A few vars need to be filled upon startup */ 544 for (i = 0; i < 2; i++) { 545 - data->fan_min[i] = sis5595_read_value(new_client, 546 SIS5595_REG_FAN_MIN(i)); 547 } 548 549 /* Register sysfs hooks */ 550 - if ((err = sysfs_create_group(&new_client->dev.kobj, &sis5595_group))) 551 - goto exit_detach; 552 if (data->maxins == 4) { 553 - if ((err = device_create_file(&new_client->dev, 554 - &dev_attr_in4_input)) 555 - || (err = device_create_file(&new_client->dev, 556 - &dev_attr_in4_min)) 557 - || (err = device_create_file(&new_client->dev, 558 - &dev_attr_in4_max))) 559 goto exit_remove_files; 560 } else { 561 - if ((err = device_create_file(&new_client->dev, 562 &dev_attr_temp1_input)) 563 - || (err = device_create_file(&new_client->dev, 564 &dev_attr_temp1_max)) 565 - || (err = device_create_file(&new_client->dev, 566 &dev_attr_temp1_max_hyst))) 567 goto exit_remove_files; 568 } 569 570 - data->class_dev = hwmon_device_register(&new_client->dev); 571 if (IS_ERR(data->class_dev)) { 572 err = PTR_ERR(data->class_dev); 573 goto exit_remove_files; ··· 566 return 0; 567 568 exit_remove_files: 569 - sysfs_remove_group(&new_client->dev.kobj, &sis5595_group); 570 - sysfs_remove_group(&new_client->dev.kobj, &sis5595_group_opt); 571 - exit_detach: 572 - i2c_detach_client(new_client); 573 exit_free: 574 kfree(data); 575 exit_release: 576 - release_region(address, SIS5595_EXTENT); 577 exit: 578 return err; 579 } 580 581 - static int sis5595_detach_client(struct i2c_client *client) 582 { 583 - struct sis5595_data *data = i2c_get_clientdata(client); 584 - int err; 585 586 hwmon_device_unregister(data->class_dev); 587 - sysfs_remove_group(&client->dev.kobj, &sis5595_group); 588 - sysfs_remove_group(&client->dev.kobj, &sis5595_group_opt); 589 590 - if ((err = i2c_detach_client(client))) 591 - return err; 592 - 593 - release_region(client->addr, SIS5595_EXTENT); 594 - 595 kfree(data); 596 597 return 0; ··· 593 594 595 /* ISA access must be locked explicitly. */ 596 - static int sis5595_read_value(struct i2c_client *client, u8 reg) 597 { 598 int res; 599 600 - struct sis5595_data *data = i2c_get_clientdata(client); 601 mutex_lock(&data->lock); 602 - outb_p(reg, client->addr + SIS5595_ADDR_REG_OFFSET); 603 - res = inb_p(client->addr + SIS5595_DATA_REG_OFFSET); 604 mutex_unlock(&data->lock); 605 return res; 606 } 607 608 - static int sis5595_write_value(struct i2c_client *client, u8 reg, u8 value) 609 { 610 - struct sis5595_data *data = i2c_get_clientdata(client); 611 mutex_lock(&data->lock); 612 - outb_p(reg, client->addr + SIS5595_ADDR_REG_OFFSET); 613 - outb_p(value, client->addr + SIS5595_DATA_REG_OFFSET); 614 mutex_unlock(&data->lock); 615 - return 0; 616 } 617 618 /* Called when we have found a new SIS5595. */ 619 - static void sis5595_init_client(struct i2c_client *client) 620 { 621 - u8 config = sis5595_read_value(client, SIS5595_REG_CONFIG); 622 if (!(config & 0x01)) 623 - sis5595_write_value(client, SIS5595_REG_CONFIG, 624 (config & 0xf7) | 0x01); 625 } 626 627 static struct sis5595_data *sis5595_update_device(struct device *dev) 628 { 629 - struct i2c_client *client = to_i2c_client(dev); 630 - struct sis5595_data *data = i2c_get_clientdata(client); 631 int i; 632 633 mutex_lock(&data->update_lock); ··· 633 634 for (i = 0; i <= data->maxins; i++) { 635 data->in[i] = 636 - sis5595_read_value(client, SIS5595_REG_IN(i)); 637 data->in_min[i] = 638 - sis5595_read_value(client, 639 SIS5595_REG_IN_MIN(i)); 640 data->in_max[i] = 641 - sis5595_read_value(client, 642 SIS5595_REG_IN_MAX(i)); 643 } 644 for (i = 0; i < 2; i++) { 645 data->fan[i] = 646 - sis5595_read_value(client, SIS5595_REG_FAN(i)); 647 data->fan_min[i] = 648 - sis5595_read_value(client, 649 SIS5595_REG_FAN_MIN(i)); 650 } 651 if (data->maxins == 3) { 652 data->temp = 653 - sis5595_read_value(client, SIS5595_REG_TEMP); 654 data->temp_over = 655 - sis5595_read_value(client, SIS5595_REG_TEMP_OVER); 656 data->temp_hyst = 657 - sis5595_read_value(client, SIS5595_REG_TEMP_HYST); 658 } 659 - i = sis5595_read_value(client, SIS5595_REG_FANDIV); 660 data->fan_div[0] = (i >> 4) & 0x03; 661 data->fan_div[1] = i >> 6; 662 data->alarms = 663 - sis5595_read_value(client, SIS5595_REG_ALARM1) | 664 - (sis5595_read_value(client, SIS5595_REG_ALARM2) << 8); 665 data->last_updated = jiffies; 666 data->valid = 1; 667 } ··· 692 PCI_DEVICE_ID_SI_5598, 693 0 }; 694 695 static int __devinit sis5595_pci_probe(struct pci_dev *dev, 696 const struct pci_device_id *id) 697 { 698 - u16 val; 699 int *i; 700 701 for (i = blacklist; *i != 0; i++) { ··· 748 } 749 } 750 751 if (PCIBIOS_SUCCESSFUL != 752 - pci_read_config_word(dev, SIS5595_BASE_REG, &val)) 753 return -ENODEV; 754 755 - address = val & ~(SIS5595_EXTENT - 1); 756 - if (address == 0 && force_addr == 0) { 757 dev_err(&dev->dev, "Base address not set - upgrade BIOS or use force_addr=0xaddr\n"); 758 return -ENODEV; 759 } 760 761 s_bridge = pci_dev_get(dev); 762 - if (i2c_isa_add_driver(&sis5595_driver)) { 763 - pci_dev_put(s_bridge); 764 - s_bridge = NULL; 765 - } 766 767 /* Always return failure here. This is to allow other drivers to bind 768 * to this pci device. We don't really want to have control over the 769 * pci device, we only wanted to read as few register values from it. 770 */ 771 return -ENODEV; 772 } 773 ··· 827 { 828 pci_unregister_driver(&sis5595_pci_driver); 829 if (s_bridge != NULL) { 830 - i2c_isa_del_driver(&sis5595_driver); 831 pci_dev_put(s_bridge); 832 s_bridge = NULL; 833 }
··· 54 #include <linux/slab.h> 55 #include <linux/ioport.h> 56 #include <linux/pci.h> 57 + #include <linux/platform_device.h> 58 #include <linux/hwmon.h> 59 + #include <linux/hwmon-sysfs.h> 60 #include <linux/err.h> 61 #include <linux/init.h> 62 #include <linux/jiffies.h> ··· 72 MODULE_PARM_DESC(force_addr, 73 "Initialize the base address of the sensors"); 74 75 + static struct platform_device *pdev; 76 77 /* Many SIS5595 constants specified below */ 78 79 /* Length of ISA address segment */ 80 #define SIS5595_EXTENT 8 81 /* PCI Config Registers */ 82 #define SIS5595_BASE_REG 0x68 83 #define SIS5595_PIN_REG 0x7A 84 #define SIS5595_ENABLE_REG 0x7B ··· 165 /* For each registered chip, we need to keep some data in memory. 166 The structure is dynamically allocated. */ 167 struct sis5595_data { 168 + unsigned short addr; 169 + const char *name; 170 struct class_device *class_dev; 171 struct mutex lock; 172 ··· 189 190 static struct pci_dev *s_bridge; /* pointer to the (only) sis5595 */ 191 192 + static int sis5595_probe(struct platform_device *pdev); 193 + static int sis5595_remove(struct platform_device *pdev); 194 195 + static int sis5595_read_value(struct sis5595_data *data, u8 reg); 196 + static void sis5595_write_value(struct sis5595_data *data, u8 reg, u8 value); 197 static struct sis5595_data *sis5595_update_device(struct device *dev); 198 + static void sis5595_init_device(struct sis5595_data *data); 199 200 + static struct platform_driver sis5595_driver = { 201 .driver = { 202 .owner = THIS_MODULE, 203 .name = "sis5595", 204 }, 205 + .probe = sis5595_probe, 206 + .remove = __devexit_p(sis5595_remove), 207 }; 208 209 /* 4 Voltages */ 210 + static ssize_t show_in(struct device *dev, struct device_attribute *da, 211 + char *buf) 212 { 213 struct sis5595_data *data = sis5595_update_device(dev); 214 + struct sensor_device_attribute *attr = to_sensor_dev_attr(da); 215 + int nr = attr->index; 216 return sprintf(buf, "%d\n", IN_FROM_REG(data->in[nr])); 217 } 218 219 + static ssize_t show_in_min(struct device *dev, struct device_attribute *da, 220 + char *buf) 221 { 222 struct sis5595_data *data = sis5595_update_device(dev); 223 + struct sensor_device_attribute *attr = to_sensor_dev_attr(da); 224 + int nr = attr->index; 225 return sprintf(buf, "%d\n", IN_FROM_REG(data->in_min[nr])); 226 } 227 228 + static ssize_t show_in_max(struct device *dev, struct device_attribute *da, 229 + char *buf) 230 { 231 struct sis5595_data *data = sis5595_update_device(dev); 232 + struct sensor_device_attribute *attr = to_sensor_dev_attr(da); 233 + int nr = attr->index; 234 return sprintf(buf, "%d\n", IN_FROM_REG(data->in_max[nr])); 235 } 236 237 + static ssize_t set_in_min(struct device *dev, struct device_attribute *da, 238 + const char *buf, size_t count) 239 { 240 + struct sis5595_data *data = dev_get_drvdata(dev); 241 + struct sensor_device_attribute *attr = to_sensor_dev_attr(da); 242 + int nr = attr->index; 243 unsigned long val = simple_strtoul(buf, NULL, 10); 244 245 mutex_lock(&data->update_lock); 246 data->in_min[nr] = IN_TO_REG(val); 247 + sis5595_write_value(data, SIS5595_REG_IN_MIN(nr), data->in_min[nr]); 248 mutex_unlock(&data->update_lock); 249 return count; 250 } 251 252 + static ssize_t set_in_max(struct device *dev, struct device_attribute *da, 253 + const char *buf, size_t count) 254 { 255 + struct sis5595_data *data = dev_get_drvdata(dev); 256 + struct sensor_device_attribute *attr = to_sensor_dev_attr(da); 257 + int nr = attr->index; 258 unsigned long val = simple_strtoul(buf, NULL, 10); 259 260 mutex_lock(&data->update_lock); 261 data->in_max[nr] = IN_TO_REG(val); 262 + sis5595_write_value(data, SIS5595_REG_IN_MAX(nr), data->in_max[nr]); 263 mutex_unlock(&data->update_lock); 264 return count; 265 } 266 267 #define show_in_offset(offset) \ 268 + static SENSOR_DEVICE_ATTR(in##offset##_input, S_IRUGO, \ 269 + show_in, NULL, offset); \ 270 + static SENSOR_DEVICE_ATTR(in##offset##_min, S_IRUGO | S_IWUSR, \ 271 + show_in_min, set_in_min, offset); \ 272 + static SENSOR_DEVICE_ATTR(in##offset##_max, S_IRUGO | S_IWUSR, \ 273 + show_in_max, set_in_max, offset); 274 275 show_in_offset(0); 276 show_in_offset(1); ··· 307 308 static ssize_t set_temp_over(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) 309 { 310 + struct sis5595_data *data = dev_get_drvdata(dev); 311 long val = simple_strtol(buf, NULL, 10); 312 313 mutex_lock(&data->update_lock); 314 data->temp_over = TEMP_TO_REG(val); 315 + sis5595_write_value(data, SIS5595_REG_TEMP_OVER, data->temp_over); 316 mutex_unlock(&data->update_lock); 317 return count; 318 } ··· 326 327 static ssize_t set_temp_hyst(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) 328 { 329 + struct sis5595_data *data = dev_get_drvdata(dev); 330 long val = simple_strtol(buf, NULL, 10); 331 332 mutex_lock(&data->update_lock); 333 data->temp_hyst = TEMP_TO_REG(val); 334 + sis5595_write_value(data, SIS5595_REG_TEMP_HYST, data->temp_hyst); 335 mutex_unlock(&data->update_lock); 336 return count; 337 } ··· 344 show_temp_hyst, set_temp_hyst); 345 346 /* 2 Fans */ 347 + static ssize_t show_fan(struct device *dev, struct device_attribute *da, 348 + char *buf) 349 { 350 struct sis5595_data *data = sis5595_update_device(dev); 351 + struct sensor_device_attribute *attr = to_sensor_dev_attr(da); 352 + int nr = attr->index; 353 return sprintf(buf, "%d\n", FAN_FROM_REG(data->fan[nr], 354 DIV_FROM_REG(data->fan_div[nr])) ); 355 } 356 357 + static ssize_t show_fan_min(struct device *dev, struct device_attribute *da, 358 + char *buf) 359 { 360 struct sis5595_data *data = sis5595_update_device(dev); 361 + struct sensor_device_attribute *attr = to_sensor_dev_attr(da); 362 + int nr = attr->index; 363 return sprintf(buf,"%d\n", FAN_FROM_REG(data->fan_min[nr], 364 DIV_FROM_REG(data->fan_div[nr])) ); 365 } 366 367 + static ssize_t set_fan_min(struct device *dev, struct device_attribute *da, 368 + const char *buf, size_t count) 369 { 370 + struct sis5595_data *data = dev_get_drvdata(dev); 371 + struct sensor_device_attribute *attr = to_sensor_dev_attr(da); 372 + int nr = attr->index; 373 unsigned long val = simple_strtoul(buf, NULL, 10); 374 375 mutex_lock(&data->update_lock); 376 data->fan_min[nr] = FAN_TO_REG(val, DIV_FROM_REG(data->fan_div[nr])); 377 + sis5595_write_value(data, SIS5595_REG_FAN_MIN(nr), data->fan_min[nr]); 378 mutex_unlock(&data->update_lock); 379 return count; 380 } 381 382 + static ssize_t show_fan_div(struct device *dev, struct device_attribute *da, 383 + char *buf) 384 { 385 struct sis5595_data *data = sis5595_update_device(dev); 386 + struct sensor_device_attribute *attr = to_sensor_dev_attr(da); 387 + int nr = attr->index; 388 return sprintf(buf, "%d\n", DIV_FROM_REG(data->fan_div[nr]) ); 389 } 390 ··· 382 determined in part by the fan divisor. This follows the principle of 383 least surprise; the user doesn't expect the fan minimum to change just 384 because the divisor changed. */ 385 + static ssize_t set_fan_div(struct device *dev, struct device_attribute *da, 386 + const char *buf, size_t count) 387 { 388 + struct sis5595_data *data = dev_get_drvdata(dev); 389 + struct sensor_device_attribute *attr = to_sensor_dev_attr(da); 390 + int nr = attr->index; 391 unsigned long min; 392 unsigned long val = simple_strtoul(buf, NULL, 10); 393 int reg; ··· 394 mutex_lock(&data->update_lock); 395 min = FAN_FROM_REG(data->fan_min[nr], 396 DIV_FROM_REG(data->fan_div[nr])); 397 + reg = sis5595_read_value(data, SIS5595_REG_FANDIV); 398 399 switch (val) { 400 case 1: data->fan_div[nr] = 0; break; ··· 402 case 4: data->fan_div[nr] = 2; break; 403 case 8: data->fan_div[nr] = 3; break; 404 default: 405 + dev_err(dev, "fan_div value %ld not " 406 "supported. Choose one of 1, 2, 4 or 8!\n", val); 407 mutex_unlock(&data->update_lock); 408 return -EINVAL; ··· 416 reg = (reg & 0x3f) | (data->fan_div[nr] << 6); 417 break; 418 } 419 + sis5595_write_value(data, SIS5595_REG_FANDIV, reg); 420 data->fan_min[nr] = 421 FAN_TO_REG(min, DIV_FROM_REG(data->fan_div[nr])); 422 + sis5595_write_value(data, SIS5595_REG_FAN_MIN(nr), data->fan_min[nr]); 423 mutex_unlock(&data->update_lock); 424 return count; 425 } 426 427 #define show_fan_offset(offset) \ 428 + static SENSOR_DEVICE_ATTR(fan##offset##_input, S_IRUGO, \ 429 + show_fan, NULL, offset - 1); \ 430 + static SENSOR_DEVICE_ATTR(fan##offset##_min, S_IRUGO | S_IWUSR, \ 431 + show_fan_min, set_fan_min, offset - 1); \ 432 + static SENSOR_DEVICE_ATTR(fan##offset##_div, S_IRUGO | S_IWUSR, \ 433 + show_fan_div, set_fan_div, offset - 1); 434 435 show_fan_offset(1); 436 show_fan_offset(2); 437 438 /* Alarms */ 439 static ssize_t show_alarms(struct device *dev, struct device_attribute *attr, char *buf) ··· 473 } 474 static DEVICE_ATTR(alarms, S_IRUGO, show_alarms, NULL); 475 476 + static ssize_t show_name(struct device *dev, struct device_attribute *attr, 477 + char *buf) 478 + { 479 + struct sis5595_data *data = dev_get_drvdata(dev); 480 + return sprintf(buf, "%s\n", data->name); 481 + } 482 + static DEVICE_ATTR(name, S_IRUGO, show_name, NULL); 483 484 + static struct attribute *sis5595_attributes[] = { 485 + &sensor_dev_attr_in0_input.dev_attr.attr, 486 + &sensor_dev_attr_in0_min.dev_attr.attr, 487 + &sensor_dev_attr_in0_max.dev_attr.attr, 488 + &sensor_dev_attr_in1_input.dev_attr.attr, 489 + &sensor_dev_attr_in1_min.dev_attr.attr, 490 + &sensor_dev_attr_in1_max.dev_attr.attr, 491 + &sensor_dev_attr_in2_input.dev_attr.attr, 492 + &sensor_dev_attr_in2_min.dev_attr.attr, 493 + &sensor_dev_attr_in2_max.dev_attr.attr, 494 + &sensor_dev_attr_in3_input.dev_attr.attr, 495 + &sensor_dev_attr_in3_min.dev_attr.attr, 496 + &sensor_dev_attr_in3_max.dev_attr.attr, 497 + 498 + &sensor_dev_attr_fan1_input.dev_attr.attr, 499 + &sensor_dev_attr_fan1_min.dev_attr.attr, 500 + &sensor_dev_attr_fan1_div.dev_attr.attr, 501 + &sensor_dev_attr_fan2_input.dev_attr.attr, 502 + &sensor_dev_attr_fan2_min.dev_attr.attr, 503 + &sensor_dev_attr_fan2_div.dev_attr.attr, 504 505 &dev_attr_alarms.attr, 506 + &dev_attr_name.attr, 507 NULL 508 }; 509 ··· 503 }; 504 505 static struct attribute *sis5595_attributes_opt[] = { 506 + &sensor_dev_attr_in4_input.dev_attr.attr, 507 + &sensor_dev_attr_in4_min.dev_attr.attr, 508 + &sensor_dev_attr_in4_max.dev_attr.attr, 509 510 &dev_attr_temp1_input.attr, 511 &dev_attr_temp1_max.attr, ··· 518 }; 519 520 /* This is called when the module is loaded */ 521 + static int __devinit sis5595_probe(struct platform_device *pdev) 522 { 523 int err = 0; 524 int i; 525 struct sis5595_data *data; 526 + struct resource *res; 527 char val; 528 529 /* Reserve the ISA region */ 530 + res = platform_get_resource(pdev, IORESOURCE_IO, 0); 531 + if (!request_region(res->start, SIS5595_EXTENT, 532 sis5595_driver.driver.name)) { 533 err = -EBUSY; 534 goto exit; 535 } 536 537 if (!(data = kzalloc(sizeof(struct sis5595_data), GFP_KERNEL))) { ··· 570 goto exit_release; 571 } 572 573 mutex_init(&data->lock); 574 + mutex_init(&data->update_lock); 575 + data->addr = res->start; 576 + data->name = "sis5595"; 577 + platform_set_drvdata(pdev, data); 578 579 /* Check revision and pin registers to determine whether 4 or 5 voltages */ 580 + pci_read_config_byte(s_bridge, PCI_REVISION_ID, &data->revision); 581 /* 4 voltages, 1 temp */ 582 data->maxins = 3; 583 if (data->revision >= REV2MIN) { ··· 589 data->maxins = 4; 590 } 591 592 /* Initialize the SIS5595 chip */ 593 + sis5595_init_device(data); 594 595 /* A few vars need to be filled upon startup */ 596 for (i = 0; i < 2; i++) { 597 + data->fan_min[i] = sis5595_read_value(data, 598 SIS5595_REG_FAN_MIN(i)); 599 } 600 601 /* Register sysfs hooks */ 602 + if ((err = sysfs_create_group(&pdev->dev.kobj, &sis5595_group))) 603 + goto exit_free; 604 if (data->maxins == 4) { 605 + if ((err = device_create_file(&pdev->dev, 606 + &sensor_dev_attr_in4_input.dev_attr)) 607 + || (err = device_create_file(&pdev->dev, 608 + &sensor_dev_attr_in4_min.dev_attr)) 609 + || (err = device_create_file(&pdev->dev, 610 + &sensor_dev_attr_in4_max.dev_attr))) 611 goto exit_remove_files; 612 } else { 613 + if ((err = device_create_file(&pdev->dev, 614 &dev_attr_temp1_input)) 615 + || (err = device_create_file(&pdev->dev, 616 &dev_attr_temp1_max)) 617 + || (err = device_create_file(&pdev->dev, 618 &dev_attr_temp1_max_hyst))) 619 goto exit_remove_files; 620 } 621 622 + data->class_dev = hwmon_device_register(&pdev->dev); 623 if (IS_ERR(data->class_dev)) { 624 err = PTR_ERR(data->class_dev); 625 goto exit_remove_files; ··· 638 return 0; 639 640 exit_remove_files: 641 + sysfs_remove_group(&pdev->dev.kobj, &sis5595_group); 642 + sysfs_remove_group(&pdev->dev.kobj, &sis5595_group_opt); 643 exit_free: 644 kfree(data); 645 exit_release: 646 + release_region(res->start, SIS5595_EXTENT); 647 exit: 648 return err; 649 } 650 651 + static int __devexit sis5595_remove(struct platform_device *pdev) 652 { 653 + struct sis5595_data *data = platform_get_drvdata(pdev); 654 655 hwmon_device_unregister(data->class_dev); 656 + sysfs_remove_group(&pdev->dev.kobj, &sis5595_group); 657 + sysfs_remove_group(&pdev->dev.kobj, &sis5595_group_opt); 658 659 + release_region(data->addr, SIS5595_EXTENT); 660 + platform_set_drvdata(pdev, NULL); 661 kfree(data); 662 663 return 0; ··· 671 672 673 /* ISA access must be locked explicitly. */ 674 + static int sis5595_read_value(struct sis5595_data *data, u8 reg) 675 { 676 int res; 677 678 mutex_lock(&data->lock); 679 + outb_p(reg, data->addr + SIS5595_ADDR_REG_OFFSET); 680 + res = inb_p(data->addr + SIS5595_DATA_REG_OFFSET); 681 mutex_unlock(&data->lock); 682 return res; 683 } 684 685 + static void sis5595_write_value(struct sis5595_data *data, u8 reg, u8 value) 686 { 687 mutex_lock(&data->lock); 688 + outb_p(reg, data->addr + SIS5595_ADDR_REG_OFFSET); 689 + outb_p(value, data->addr + SIS5595_DATA_REG_OFFSET); 690 mutex_unlock(&data->lock); 691 } 692 693 /* Called when we have found a new SIS5595. */ 694 + static void __devinit sis5595_init_device(struct sis5595_data *data) 695 { 696 + u8 config = sis5595_read_value(data, SIS5595_REG_CONFIG); 697 if (!(config & 0x01)) 698 + sis5595_write_value(data, SIS5595_REG_CONFIG, 699 (config & 0xf7) | 0x01); 700 } 701 702 static struct sis5595_data *sis5595_update_device(struct device *dev) 703 { 704 + struct sis5595_data *data = dev_get_drvdata(dev); 705 int i; 706 707 mutex_lock(&data->update_lock); ··· 715 716 for (i = 0; i <= data->maxins; i++) { 717 data->in[i] = 718 + sis5595_read_value(data, SIS5595_REG_IN(i)); 719 data->in_min[i] = 720 + sis5595_read_value(data, 721 SIS5595_REG_IN_MIN(i)); 722 data->in_max[i] = 723 + sis5595_read_value(data, 724 SIS5595_REG_IN_MAX(i)); 725 } 726 for (i = 0; i < 2; i++) { 727 data->fan[i] = 728 + sis5595_read_value(data, SIS5595_REG_FAN(i)); 729 data->fan_min[i] = 730 + sis5595_read_value(data, 731 SIS5595_REG_FAN_MIN(i)); 732 } 733 if (data->maxins == 3) { 734 data->temp = 735 + sis5595_read_value(data, SIS5595_REG_TEMP); 736 data->temp_over = 737 + sis5595_read_value(data, SIS5595_REG_TEMP_OVER); 738 data->temp_hyst = 739 + sis5595_read_value(data, SIS5595_REG_TEMP_HYST); 740 } 741 + i = sis5595_read_value(data, SIS5595_REG_FANDIV); 742 data->fan_div[0] = (i >> 4) & 0x03; 743 data->fan_div[1] = i >> 6; 744 data->alarms = 745 + sis5595_read_value(data, SIS5595_REG_ALARM1) | 746 + (sis5595_read_value(data, SIS5595_REG_ALARM2) << 8); 747 data->last_updated = jiffies; 748 data->valid = 1; 749 } ··· 774 PCI_DEVICE_ID_SI_5598, 775 0 }; 776 777 + static int __devinit sis5595_device_add(unsigned short address) 778 + { 779 + struct resource res = { 780 + .start = address, 781 + .end = address + SIS5595_EXTENT - 1, 782 + .name = "sis5595", 783 + .flags = IORESOURCE_IO, 784 + }; 785 + int err; 786 + 787 + pdev = platform_device_alloc("sis5595", address); 788 + if (!pdev) { 789 + err = -ENOMEM; 790 + printk(KERN_ERR "sis5595: Device allocation failed\n"); 791 + goto exit; 792 + } 793 + 794 + err = platform_device_add_resources(pdev, &res, 1); 795 + if (err) { 796 + printk(KERN_ERR "sis5595: Device resource addition failed " 797 + "(%d)\n", err); 798 + goto exit_device_put; 799 + } 800 + 801 + err = platform_device_add(pdev); 802 + if (err) { 803 + printk(KERN_ERR "sis5595: Device addition failed (%d)\n", 804 + err); 805 + goto exit_device_put; 806 + } 807 + 808 + return 0; 809 + 810 + exit_device_put: 811 + platform_device_put(pdev); 812 + exit: 813 + return err; 814 + } 815 + 816 static int __devinit sis5595_pci_probe(struct pci_dev *dev, 817 const struct pci_device_id *id) 818 { 819 + u16 address; 820 + u8 enable; 821 int *i; 822 823 for (i = blacklist; *i != 0; i++) { ··· 790 } 791 } 792 793 + force_addr &= ~(SIS5595_EXTENT - 1); 794 + if (force_addr) { 795 + dev_warn(&dev->dev, "Forcing ISA address 0x%x\n", force_addr); 796 + pci_write_config_word(dev, SIS5595_BASE_REG, force_addr); 797 + } 798 + 799 if (PCIBIOS_SUCCESSFUL != 800 + pci_read_config_word(dev, SIS5595_BASE_REG, &address)) { 801 + dev_err(&dev->dev, "Failed to read ISA address\n"); 802 return -ENODEV; 803 + } 804 805 + address &= ~(SIS5595_EXTENT - 1); 806 + if (!address) { 807 dev_err(&dev->dev, "Base address not set - upgrade BIOS or use force_addr=0xaddr\n"); 808 return -ENODEV; 809 } 810 + if (force_addr && address != force_addr) { 811 + /* doesn't work for some chips? */ 812 + dev_err(&dev->dev, "Failed to force ISA address\n"); 813 + return -ENODEV; 814 + } 815 + 816 + if (PCIBIOS_SUCCESSFUL != 817 + pci_read_config_byte(dev, SIS5595_ENABLE_REG, &enable)) { 818 + dev_err(&dev->dev, "Failed to read enable register\n"); 819 + return -ENODEV; 820 + } 821 + if (!(enable & 0x80)) { 822 + if ((PCIBIOS_SUCCESSFUL != 823 + pci_write_config_byte(dev, SIS5595_ENABLE_REG, 824 + enable | 0x80)) 825 + || (PCIBIOS_SUCCESSFUL != 826 + pci_read_config_byte(dev, SIS5595_ENABLE_REG, &enable)) 827 + || (!(enable & 0x80))) { 828 + /* doesn't work for some chips! */ 829 + dev_err(&dev->dev, "Failed to enable HWM device\n"); 830 + return -ENODEV; 831 + } 832 + } 833 + 834 + if (platform_driver_register(&sis5595_driver)) { 835 + dev_dbg(&dev->dev, "Failed to register sis5595 driver\n"); 836 + goto exit; 837 + } 838 839 s_bridge = pci_dev_get(dev); 840 + /* Sets global pdev as a side effect */ 841 + if (sis5595_device_add(address)) 842 + goto exit_unregister; 843 844 /* Always return failure here. This is to allow other drivers to bind 845 * to this pci device. We don't really want to have control over the 846 * pci device, we only wanted to read as few register values from it. 847 */ 848 + return -ENODEV; 849 + 850 + exit_unregister: 851 + pci_dev_put(dev); 852 + platform_driver_unregister(&sis5595_driver); 853 + exit: 854 return -ENODEV; 855 } 856 ··· 828 { 829 pci_unregister_driver(&sis5595_pci_driver); 830 if (s_bridge != NULL) { 831 + platform_device_unregister(pdev); 832 + platform_driver_unregister(&sis5595_driver); 833 pci_dev_put(s_bridge); 834 s_bridge = NULL; 835 }
+5 -2
drivers/hwmon/smsc47b397.c
··· 174 REG: count of 90kHz pulses / revolution */ 175 static int fan_from_reg(u16 reg) 176 { 177 return 90000 * 60 / reg; 178 } 179 ··· 335 superio_enter(); 336 id = superio_inb(SUPERIO_REG_DEVID); 337 338 - if ((id != 0x6f) && (id != 0x81)) { 339 superio_exit(); 340 return -ENODEV; 341 } ··· 348 349 printk(KERN_INFO DRVNAME ": found SMSC %s " 350 "(base address 0x%04x, revision %u)\n", 351 - id == 0x81 ? "SCH5307-NS" : "LPC47B397-NC", *addr, rev); 352 353 superio_exit(); 354 return 0;
··· 174 REG: count of 90kHz pulses / revolution */ 175 static int fan_from_reg(u16 reg) 176 { 177 + if (reg == 0 || reg == 0xffff) 178 + return 0; 179 return 90000 * 60 / reg; 180 } 181 ··· 333 superio_enter(); 334 id = superio_inb(SUPERIO_REG_DEVID); 335 336 + if ((id != 0x6f) && (id != 0x81) && (id != 0x85)) { 337 superio_exit(); 338 return -ENODEV; 339 } ··· 346 347 printk(KERN_INFO DRVNAME ": found SMSC %s " 348 "(base address 0x%04x, revision %u)\n", 349 + id == 0x81 ? "SCH5307-NS" : id == 0x85 ? "SCH5317" : 350 + "LPC47B397-NC", *addr, rev); 351 352 superio_exit(); 353 return 0;
+5 -7
drivers/hwmon/smsc47m1.c
··· 597 error_remove_files: 598 sysfs_remove_group(&dev->kobj, &smsc47m1_group); 599 error_free: 600 kfree(data); 601 error_release: 602 release_region(res->start, SMSC_EXTENT); ··· 609 struct smsc47m1_data *data = platform_get_drvdata(pdev); 610 struct resource *res; 611 612 - platform_set_drvdata(pdev, NULL); 613 hwmon_device_unregister(data->class_dev); 614 sysfs_remove_group(&pdev->dev.kobj, &smsc47m1_group); 615 616 res = platform_get_resource(pdev, IORESOURCE_IO, 0); 617 release_region(res->start, SMSC_EXTENT); 618 kfree(data); 619 620 return 0; ··· 694 goto exit_device_put; 695 } 696 697 - pdev->dev.platform_data = kmalloc(sizeof(struct smsc47m1_sio_data), 698 - GFP_KERNEL); 699 - if (!pdev->dev.platform_data) { 700 - err = -ENOMEM; 701 printk(KERN_ERR DRVNAME ": Platform data allocation failed\n"); 702 goto exit_device_put; 703 } 704 - memcpy(pdev->dev.platform_data, sio_data, 705 - sizeof(struct smsc47m1_sio_data)); 706 707 err = platform_device_add(pdev); 708 if (err) {
··· 597 error_remove_files: 598 sysfs_remove_group(&dev->kobj, &smsc47m1_group); 599 error_free: 600 + platform_set_drvdata(pdev, NULL); 601 kfree(data); 602 error_release: 603 release_region(res->start, SMSC_EXTENT); ··· 608 struct smsc47m1_data *data = platform_get_drvdata(pdev); 609 struct resource *res; 610 611 hwmon_device_unregister(data->class_dev); 612 sysfs_remove_group(&pdev->dev.kobj, &smsc47m1_group); 613 614 res = platform_get_resource(pdev, IORESOURCE_IO, 0); 615 release_region(res->start, SMSC_EXTENT); 616 + platform_set_drvdata(pdev, NULL); 617 kfree(data); 618 619 return 0; ··· 693 goto exit_device_put; 694 } 695 696 + err = platform_device_add_data(pdev, sio_data, 697 + sizeof(struct smsc47m1_sio_data)); 698 + if (err) { 699 printk(KERN_ERR DRVNAME ": Platform data allocation failed\n"); 700 goto exit_device_put; 701 } 702 703 err = platform_device_add(pdev); 704 if (err) {
+19 -18
drivers/hwmon/smsc47m192.c
··· 31 #include <linux/hwmon-vid.h> 32 #include <linux/err.h> 33 #include <linux/sysfs.h> 34 35 /* Addresses to scan */ 36 static unsigned short normal_i2c[] = { 0x2c, 0x2d, I2C_CLIENT_END }; ··· 98 struct smsc47m192_data { 99 struct i2c_client client; 100 struct class_device *class_dev; 101 - struct semaphore update_lock; 102 char valid; /* !=0 if following fields are valid */ 103 unsigned long last_updated; /* In jiffies */ 104 ··· 165 struct smsc47m192_data *data = i2c_get_clientdata(client); 166 unsigned long val = simple_strtoul(buf, NULL, 10); 167 168 - down(&data->update_lock); 169 data->in_min[nr] = IN_TO_REG(val, nr); 170 i2c_smbus_write_byte_data(client, SMSC47M192_REG_IN_MIN(nr), 171 data->in_min[nr]); 172 - up(&data->update_lock); 173 return count; 174 } 175 ··· 182 struct smsc47m192_data *data = i2c_get_clientdata(client); 183 unsigned long val = simple_strtoul(buf, NULL, 10); 184 185 - down(&data->update_lock); 186 data->in_max[nr] = IN_TO_REG(val, nr); 187 i2c_smbus_write_byte_data(client, SMSC47M192_REG_IN_MAX(nr), 188 data->in_max[nr]); 189 - up(&data->update_lock); 190 return count; 191 } 192 ··· 244 struct smsc47m192_data *data = i2c_get_clientdata(client); 245 long val = simple_strtol(buf, NULL, 10); 246 247 - down(&data->update_lock); 248 data->temp_min[nr] = TEMP_TO_REG(val); 249 i2c_smbus_write_byte_data(client, SMSC47M192_REG_TEMP_MIN[nr], 250 data->temp_min[nr]); 251 - up(&data->update_lock); 252 return count; 253 } 254 ··· 261 struct smsc47m192_data *data = i2c_get_clientdata(client); 262 long val = simple_strtol(buf, NULL, 10); 263 264 - down(&data->update_lock); 265 data->temp_max[nr] = TEMP_TO_REG(val); 266 i2c_smbus_write_byte_data(client, SMSC47M192_REG_TEMP_MAX[nr], 267 data->temp_max[nr]); 268 - up(&data->update_lock); 269 return count; 270 } 271 ··· 288 u8 sfr = i2c_smbus_read_byte_data(client, SMSC47M192_REG_SFR); 289 long val = simple_strtol(buf, NULL, 10); 290 291 - down(&data->update_lock); 292 data->temp_offset[nr] = TEMP_TO_REG(val); 293 if (nr>1) 294 i2c_smbus_write_byte_data(client, ··· 304 } else if ((sfr & 0x10) == (nr==0 ? 0x10 : 0)) 305 i2c_smbus_write_byte_data(client, 306 SMSC47M192_REG_TEMP_OFFSET(nr), 0); 307 - up(&data->update_lock); 308 return count; 309 } 310 ··· 361 static SENSOR_DEVICE_ATTR(temp1_alarm, S_IRUGO, show_alarm, NULL, 0x0010); 362 static SENSOR_DEVICE_ATTR(temp2_alarm, S_IRUGO, show_alarm, NULL, 0x0020); 363 static SENSOR_DEVICE_ATTR(temp3_alarm, S_IRUGO, show_alarm, NULL, 0x0040); 364 - static SENSOR_DEVICE_ATTR(temp2_input_fault, S_IRUGO, show_alarm, NULL, 0x4000); 365 - static SENSOR_DEVICE_ATTR(temp3_input_fault, S_IRUGO, show_alarm, NULL, 0x8000); 366 static SENSOR_DEVICE_ATTR(in0_alarm, S_IRUGO, show_alarm, NULL, 0x0001); 367 static SENSOR_DEVICE_ATTR(in1_alarm, S_IRUGO, show_alarm, NULL, 0x0002); 368 static SENSOR_DEVICE_ATTR(in2_alarm, S_IRUGO, show_alarm, NULL, 0x0004); ··· 412 &sensor_dev_attr_temp2_min.dev_attr.attr, 413 &sensor_dev_attr_temp2_offset.dev_attr.attr, 414 &sensor_dev_attr_temp2_alarm.dev_attr.attr, 415 - &sensor_dev_attr_temp2_input_fault.dev_attr.attr, 416 &sensor_dev_attr_temp3_input.dev_attr.attr, 417 &sensor_dev_attr_temp3_max.dev_attr.attr, 418 &sensor_dev_attr_temp3_min.dev_attr.attr, 419 &sensor_dev_attr_temp3_offset.dev_attr.attr, 420 &sensor_dev_attr_temp3_alarm.dev_attr.attr, 421 - &sensor_dev_attr_temp3_input_fault.dev_attr.attr, 422 423 &dev_attr_cpu0_vid.attr, 424 &dev_attr_vrm.attr, ··· 532 /* Fill in the remaining client fields and put into the global list */ 533 strlcpy(client->name, "smsc47m192", I2C_NAME_SIZE); 534 data->vrm = vid_which_vrm(); 535 - init_MUTEX(&data->update_lock); 536 537 /* Tell the I2C layer a new client has arrived */ 538 if ((err = i2c_attach_client(client))) ··· 595 struct smsc47m192_data *data = i2c_get_clientdata(client); 596 int i, config; 597 598 - down(&data->update_lock); 599 600 if (time_after(jiffies, data->last_updated + HZ + HZ / 2) 601 || !data->valid) { ··· 646 data->valid = 1; 647 } 648 649 - up(&data->update_lock); 650 651 return data; 652 }
··· 31 #include <linux/hwmon-vid.h> 32 #include <linux/err.h> 33 #include <linux/sysfs.h> 34 + #include <linux/mutex.h> 35 36 /* Addresses to scan */ 37 static unsigned short normal_i2c[] = { 0x2c, 0x2d, I2C_CLIENT_END }; ··· 97 struct smsc47m192_data { 98 struct i2c_client client; 99 struct class_device *class_dev; 100 + struct mutex update_lock; 101 char valid; /* !=0 if following fields are valid */ 102 unsigned long last_updated; /* In jiffies */ 103 ··· 164 struct smsc47m192_data *data = i2c_get_clientdata(client); 165 unsigned long val = simple_strtoul(buf, NULL, 10); 166 167 + mutex_lock(&data->update_lock); 168 data->in_min[nr] = IN_TO_REG(val, nr); 169 i2c_smbus_write_byte_data(client, SMSC47M192_REG_IN_MIN(nr), 170 data->in_min[nr]); 171 + mutex_unlock(&data->update_lock); 172 return count; 173 } 174 ··· 181 struct smsc47m192_data *data = i2c_get_clientdata(client); 182 unsigned long val = simple_strtoul(buf, NULL, 10); 183 184 + mutex_lock(&data->update_lock); 185 data->in_max[nr] = IN_TO_REG(val, nr); 186 i2c_smbus_write_byte_data(client, SMSC47M192_REG_IN_MAX(nr), 187 data->in_max[nr]); 188 + mutex_unlock(&data->update_lock); 189 return count; 190 } 191 ··· 243 struct smsc47m192_data *data = i2c_get_clientdata(client); 244 long val = simple_strtol(buf, NULL, 10); 245 246 + mutex_lock(&data->update_lock); 247 data->temp_min[nr] = TEMP_TO_REG(val); 248 i2c_smbus_write_byte_data(client, SMSC47M192_REG_TEMP_MIN[nr], 249 data->temp_min[nr]); 250 + mutex_unlock(&data->update_lock); 251 return count; 252 } 253 ··· 260 struct smsc47m192_data *data = i2c_get_clientdata(client); 261 long val = simple_strtol(buf, NULL, 10); 262 263 + mutex_lock(&data->update_lock); 264 data->temp_max[nr] = TEMP_TO_REG(val); 265 i2c_smbus_write_byte_data(client, SMSC47M192_REG_TEMP_MAX[nr], 266 data->temp_max[nr]); 267 + mutex_unlock(&data->update_lock); 268 return count; 269 } 270 ··· 287 u8 sfr = i2c_smbus_read_byte_data(client, SMSC47M192_REG_SFR); 288 long val = simple_strtol(buf, NULL, 10); 289 290 + mutex_lock(&data->update_lock); 291 data->temp_offset[nr] = TEMP_TO_REG(val); 292 if (nr>1) 293 i2c_smbus_write_byte_data(client, ··· 303 } else if ((sfr & 0x10) == (nr==0 ? 0x10 : 0)) 304 i2c_smbus_write_byte_data(client, 305 SMSC47M192_REG_TEMP_OFFSET(nr), 0); 306 + mutex_unlock(&data->update_lock); 307 return count; 308 } 309 ··· 360 static SENSOR_DEVICE_ATTR(temp1_alarm, S_IRUGO, show_alarm, NULL, 0x0010); 361 static SENSOR_DEVICE_ATTR(temp2_alarm, S_IRUGO, show_alarm, NULL, 0x0020); 362 static SENSOR_DEVICE_ATTR(temp3_alarm, S_IRUGO, show_alarm, NULL, 0x0040); 363 + static SENSOR_DEVICE_ATTR(temp2_fault, S_IRUGO, show_alarm, NULL, 0x4000); 364 + static SENSOR_DEVICE_ATTR(temp3_fault, S_IRUGO, show_alarm, NULL, 0x8000); 365 static SENSOR_DEVICE_ATTR(in0_alarm, S_IRUGO, show_alarm, NULL, 0x0001); 366 static SENSOR_DEVICE_ATTR(in1_alarm, S_IRUGO, show_alarm, NULL, 0x0002); 367 static SENSOR_DEVICE_ATTR(in2_alarm, S_IRUGO, show_alarm, NULL, 0x0004); ··· 411 &sensor_dev_attr_temp2_min.dev_attr.attr, 412 &sensor_dev_attr_temp2_offset.dev_attr.attr, 413 &sensor_dev_attr_temp2_alarm.dev_attr.attr, 414 + &sensor_dev_attr_temp2_fault.dev_attr.attr, 415 &sensor_dev_attr_temp3_input.dev_attr.attr, 416 &sensor_dev_attr_temp3_max.dev_attr.attr, 417 &sensor_dev_attr_temp3_min.dev_attr.attr, 418 &sensor_dev_attr_temp3_offset.dev_attr.attr, 419 &sensor_dev_attr_temp3_alarm.dev_attr.attr, 420 + &sensor_dev_attr_temp3_fault.dev_attr.attr, 421 422 &dev_attr_cpu0_vid.attr, 423 &dev_attr_vrm.attr, ··· 531 /* Fill in the remaining client fields and put into the global list */ 532 strlcpy(client->name, "smsc47m192", I2C_NAME_SIZE); 533 data->vrm = vid_which_vrm(); 534 + mutex_init(&data->update_lock); 535 536 /* Tell the I2C layer a new client has arrived */ 537 if ((err = i2c_attach_client(client))) ··· 594 struct smsc47m192_data *data = i2c_get_clientdata(client); 595 int i, config; 596 597 + mutex_lock(&data->update_lock); 598 599 if (time_after(jiffies, data->last_updated + HZ + HZ / 2) 600 || !data->valid) { ··· 645 data->valid = 1; 646 } 647 648 + mutex_unlock(&data->update_lock); 649 650 return data; 651 }
+266 -268
drivers/hwmon/via686a.c
··· 34 #include <linux/slab.h> 35 #include <linux/pci.h> 36 #include <linux/jiffies.h> 37 - #include <linux/i2c.h> 38 - #include <linux/i2c-isa.h> 39 #include <linux/hwmon.h> 40 #include <linux/err.h> 41 #include <linux/init.h> 42 #include <linux/mutex.h> ··· 51 MODULE_PARM_DESC(force_addr, 52 "Initialize the base address of the sensors"); 53 54 - /* Device address 55 - Note that we can't determine the ISA address until we have initialized 56 - our module */ 57 - static unsigned short address; 58 59 /* 60 The Via 686a southbridge has a LM78-like chip integrated on the same IC. ··· 292 /* For each registered chip, we need to keep some data in memory. 293 The structure is dynamically allocated. */ 294 struct via686a_data { 295 - struct i2c_client client; 296 struct class_device *class_dev; 297 struct mutex update_lock; 298 char valid; /* !=0 if following fields are valid */ ··· 313 314 static struct pci_dev *s_bridge; /* pointer to the (only) via686a */ 315 316 - static int via686a_detect(struct i2c_adapter *adapter); 317 - static int via686a_detach_client(struct i2c_client *client); 318 319 - static inline int via686a_read_value(struct i2c_client *client, u8 reg) 320 { 321 - return (inb_p(client->addr + reg)); 322 } 323 324 - static inline void via686a_write_value(struct i2c_client *client, u8 reg, 325 u8 value) 326 { 327 - outb_p(value, client->addr + reg); 328 } 329 330 static struct via686a_data *via686a_update_device(struct device *dev); 331 - static void via686a_init_client(struct i2c_client *client); 332 333 /* following are the sysfs callback functions */ 334 335 /* 7 voltage sensors */ 336 - static ssize_t show_in(struct device *dev, char *buf, int nr) { 337 struct via686a_data *data = via686a_update_device(dev); 338 return sprintf(buf, "%ld\n", IN_FROM_REG(data->in[nr], nr)); 339 } 340 341 - static ssize_t show_in_min(struct device *dev, char *buf, int nr) { 342 struct via686a_data *data = via686a_update_device(dev); 343 return sprintf(buf, "%ld\n", IN_FROM_REG(data->in_min[nr], nr)); 344 } 345 346 - static ssize_t show_in_max(struct device *dev, char *buf, int nr) { 347 struct via686a_data *data = via686a_update_device(dev); 348 return sprintf(buf, "%ld\n", IN_FROM_REG(data->in_max[nr], nr)); 349 } 350 351 - static ssize_t set_in_min(struct device *dev, const char *buf, 352 - size_t count, int nr) { 353 - struct i2c_client *client = to_i2c_client(dev); 354 - struct via686a_data *data = i2c_get_clientdata(client); 355 unsigned long val = simple_strtoul(buf, NULL, 10); 356 357 mutex_lock(&data->update_lock); 358 data->in_min[nr] = IN_TO_REG(val, nr); 359 - via686a_write_value(client, VIA686A_REG_IN_MIN(nr), 360 data->in_min[nr]); 361 mutex_unlock(&data->update_lock); 362 return count; 363 } 364 - static ssize_t set_in_max(struct device *dev, const char *buf, 365 - size_t count, int nr) { 366 - struct i2c_client *client = to_i2c_client(dev); 367 - struct via686a_data *data = i2c_get_clientdata(client); 368 unsigned long val = simple_strtoul(buf, NULL, 10); 369 370 mutex_lock(&data->update_lock); 371 data->in_max[nr] = IN_TO_REG(val, nr); 372 - via686a_write_value(client, VIA686A_REG_IN_MAX(nr), 373 data->in_max[nr]); 374 mutex_unlock(&data->update_lock); 375 return count; 376 } 377 #define show_in_offset(offset) \ 378 - static ssize_t \ 379 - show_in##offset (struct device *dev, struct device_attribute *attr, char *buf) \ 380 - { \ 381 - return show_in(dev, buf, offset); \ 382 - } \ 383 - static ssize_t \ 384 - show_in##offset##_min (struct device *dev, struct device_attribute *attr, char *buf) \ 385 - { \ 386 - return show_in_min(dev, buf, offset); \ 387 - } \ 388 - static ssize_t \ 389 - show_in##offset##_max (struct device *dev, struct device_attribute *attr, char *buf) \ 390 - { \ 391 - return show_in_max(dev, buf, offset); \ 392 - } \ 393 - static ssize_t set_in##offset##_min (struct device *dev, struct device_attribute *attr, \ 394 - const char *buf, size_t count) \ 395 - { \ 396 - return set_in_min(dev, buf, count, offset); \ 397 - } \ 398 - static ssize_t set_in##offset##_max (struct device *dev, struct device_attribute *attr, \ 399 - const char *buf, size_t count) \ 400 - { \ 401 - return set_in_max(dev, buf, count, offset); \ 402 - } \ 403 - static DEVICE_ATTR(in##offset##_input, S_IRUGO, show_in##offset, NULL);\ 404 - static DEVICE_ATTR(in##offset##_min, S_IRUGO | S_IWUSR, \ 405 - show_in##offset##_min, set_in##offset##_min); \ 406 - static DEVICE_ATTR(in##offset##_max, S_IRUGO | S_IWUSR, \ 407 - show_in##offset##_max, set_in##offset##_max); 408 409 show_in_offset(0); 410 show_in_offset(1); ··· 400 show_in_offset(4); 401 402 /* 3 temperatures */ 403 - static ssize_t show_temp(struct device *dev, char *buf, int nr) { 404 struct via686a_data *data = via686a_update_device(dev); 405 return sprintf(buf, "%ld\n", TEMP_FROM_REG10(data->temp[nr])); 406 } 407 - static ssize_t show_temp_over(struct device *dev, char *buf, int nr) { 408 struct via686a_data *data = via686a_update_device(dev); 409 return sprintf(buf, "%ld\n", TEMP_FROM_REG(data->temp_over[nr])); 410 } 411 - static ssize_t show_temp_hyst(struct device *dev, char *buf, int nr) { 412 struct via686a_data *data = via686a_update_device(dev); 413 return sprintf(buf, "%ld\n", TEMP_FROM_REG(data->temp_hyst[nr])); 414 } 415 - static ssize_t set_temp_over(struct device *dev, const char *buf, 416 - size_t count, int nr) { 417 - struct i2c_client *client = to_i2c_client(dev); 418 - struct via686a_data *data = i2c_get_clientdata(client); 419 int val = simple_strtol(buf, NULL, 10); 420 421 mutex_lock(&data->update_lock); 422 data->temp_over[nr] = TEMP_TO_REG(val); 423 - via686a_write_value(client, VIA686A_REG_TEMP_OVER[nr], 424 data->temp_over[nr]); 425 mutex_unlock(&data->update_lock); 426 return count; 427 } 428 - static ssize_t set_temp_hyst(struct device *dev, const char *buf, 429 - size_t count, int nr) { 430 - struct i2c_client *client = to_i2c_client(dev); 431 - struct via686a_data *data = i2c_get_clientdata(client); 432 int val = simple_strtol(buf, NULL, 10); 433 434 mutex_lock(&data->update_lock); 435 data->temp_hyst[nr] = TEMP_TO_REG(val); 436 - via686a_write_value(client, VIA686A_REG_TEMP_HYST[nr], 437 data->temp_hyst[nr]); 438 mutex_unlock(&data->update_lock); 439 return count; 440 } 441 #define show_temp_offset(offset) \ 442 - static ssize_t show_temp_##offset (struct device *dev, struct device_attribute *attr, char *buf) \ 443 - { \ 444 - return show_temp(dev, buf, offset - 1); \ 445 - } \ 446 - static ssize_t \ 447 - show_temp_##offset##_over (struct device *dev, struct device_attribute *attr, char *buf) \ 448 - { \ 449 - return show_temp_over(dev, buf, offset - 1); \ 450 - } \ 451 - static ssize_t \ 452 - show_temp_##offset##_hyst (struct device *dev, struct device_attribute *attr, char *buf) \ 453 - { \ 454 - return show_temp_hyst(dev, buf, offset - 1); \ 455 - } \ 456 - static ssize_t set_temp_##offset##_over (struct device *dev, struct device_attribute *attr, \ 457 - const char *buf, size_t count) \ 458 - { \ 459 - return set_temp_over(dev, buf, count, offset - 1); \ 460 - } \ 461 - static ssize_t set_temp_##offset##_hyst (struct device *dev, struct device_attribute *attr, \ 462 - const char *buf, size_t count) \ 463 - { \ 464 - return set_temp_hyst(dev, buf, count, offset - 1); \ 465 - } \ 466 - static DEVICE_ATTR(temp##offset##_input, S_IRUGO, show_temp_##offset, NULL);\ 467 - static DEVICE_ATTR(temp##offset##_max, S_IRUGO | S_IWUSR, \ 468 - show_temp_##offset##_over, set_temp_##offset##_over); \ 469 - static DEVICE_ATTR(temp##offset##_max_hyst, S_IRUGO | S_IWUSR, \ 470 - show_temp_##offset##_hyst, set_temp_##offset##_hyst); 471 472 show_temp_offset(1); 473 show_temp_offset(2); 474 show_temp_offset(3); 475 476 /* 2 Fans */ 477 - static ssize_t show_fan(struct device *dev, char *buf, int nr) { 478 struct via686a_data *data = via686a_update_device(dev); 479 return sprintf(buf, "%d\n", FAN_FROM_REG(data->fan[nr], 480 DIV_FROM_REG(data->fan_div[nr])) ); 481 } 482 - static ssize_t show_fan_min(struct device *dev, char *buf, int nr) { 483 struct via686a_data *data = via686a_update_device(dev); 484 return sprintf(buf, "%d\n", 485 FAN_FROM_REG(data->fan_min[nr], DIV_FROM_REG(data->fan_div[nr])) ); 486 } 487 - static ssize_t show_fan_div(struct device *dev, char *buf, int nr) { 488 struct via686a_data *data = via686a_update_device(dev); 489 return sprintf(buf, "%d\n", DIV_FROM_REG(data->fan_div[nr]) ); 490 } 491 - static ssize_t set_fan_min(struct device *dev, const char *buf, 492 - size_t count, int nr) { 493 - struct i2c_client *client = to_i2c_client(dev); 494 - struct via686a_data *data = i2c_get_clientdata(client); 495 int val = simple_strtol(buf, NULL, 10); 496 497 mutex_lock(&data->update_lock); 498 data->fan_min[nr] = FAN_TO_REG(val, DIV_FROM_REG(data->fan_div[nr])); 499 - via686a_write_value(client, VIA686A_REG_FAN_MIN(nr+1), data->fan_min[nr]); 500 mutex_unlock(&data->update_lock); 501 return count; 502 } 503 - static ssize_t set_fan_div(struct device *dev, const char *buf, 504 - size_t count, int nr) { 505 - struct i2c_client *client = to_i2c_client(dev); 506 - struct via686a_data *data = i2c_get_clientdata(client); 507 int val = simple_strtol(buf, NULL, 10); 508 int old; 509 510 mutex_lock(&data->update_lock); 511 - old = via686a_read_value(client, VIA686A_REG_FANDIV); 512 data->fan_div[nr] = DIV_TO_REG(val); 513 old = (old & 0x0f) | (data->fan_div[1] << 6) | (data->fan_div[0] << 4); 514 - via686a_write_value(client, VIA686A_REG_FANDIV, old); 515 mutex_unlock(&data->update_lock); 516 return count; 517 } 518 519 #define show_fan_offset(offset) \ 520 - static ssize_t show_fan_##offset (struct device *dev, struct device_attribute *attr, char *buf) \ 521 - { \ 522 - return show_fan(dev, buf, offset - 1); \ 523 - } \ 524 - static ssize_t show_fan_##offset##_min (struct device *dev, struct device_attribute *attr, char *buf) \ 525 - { \ 526 - return show_fan_min(dev, buf, offset - 1); \ 527 - } \ 528 - static ssize_t show_fan_##offset##_div (struct device *dev, struct device_attribute *attr, char *buf) \ 529 - { \ 530 - return show_fan_div(dev, buf, offset - 1); \ 531 - } \ 532 - static ssize_t set_fan_##offset##_min (struct device *dev, struct device_attribute *attr, \ 533 - const char *buf, size_t count) \ 534 - { \ 535 - return set_fan_min(dev, buf, count, offset - 1); \ 536 - } \ 537 - static ssize_t set_fan_##offset##_div (struct device *dev, struct device_attribute *attr, \ 538 - const char *buf, size_t count) \ 539 - { \ 540 - return set_fan_div(dev, buf, count, offset - 1); \ 541 - } \ 542 - static DEVICE_ATTR(fan##offset##_input, S_IRUGO, show_fan_##offset, NULL);\ 543 - static DEVICE_ATTR(fan##offset##_min, S_IRUGO | S_IWUSR, \ 544 - show_fan_##offset##_min, set_fan_##offset##_min); \ 545 - static DEVICE_ATTR(fan##offset##_div, S_IRUGO | S_IWUSR, \ 546 - show_fan_##offset##_div, set_fan_##offset##_div); 547 548 show_fan_offset(1); 549 show_fan_offset(2); ··· 533 } 534 static DEVICE_ATTR(alarms, S_IRUGO, show_alarms, NULL); 535 536 static struct attribute *via686a_attributes[] = { 537 - &dev_attr_in0_input.attr, 538 - &dev_attr_in1_input.attr, 539 - &dev_attr_in2_input.attr, 540 - &dev_attr_in3_input.attr, 541 - &dev_attr_in4_input.attr, 542 - &dev_attr_in0_min.attr, 543 - &dev_attr_in1_min.attr, 544 - &dev_attr_in2_min.attr, 545 - &dev_attr_in3_min.attr, 546 - &dev_attr_in4_min.attr, 547 - &dev_attr_in0_max.attr, 548 - &dev_attr_in1_max.attr, 549 - &dev_attr_in2_max.attr, 550 - &dev_attr_in3_max.attr, 551 - &dev_attr_in4_max.attr, 552 553 - &dev_attr_temp1_input.attr, 554 - &dev_attr_temp2_input.attr, 555 - &dev_attr_temp3_input.attr, 556 - &dev_attr_temp1_max.attr, 557 - &dev_attr_temp2_max.attr, 558 - &dev_attr_temp3_max.attr, 559 - &dev_attr_temp1_max_hyst.attr, 560 - &dev_attr_temp2_max_hyst.attr, 561 - &dev_attr_temp3_max_hyst.attr, 562 563 - &dev_attr_fan1_input.attr, 564 - &dev_attr_fan2_input.attr, 565 - &dev_attr_fan1_min.attr, 566 - &dev_attr_fan2_min.attr, 567 - &dev_attr_fan1_div.attr, 568 - &dev_attr_fan2_div.attr, 569 570 &dev_attr_alarms.attr, 571 NULL 572 }; 573 ··· 584 .attrs = via686a_attributes, 585 }; 586 587 - /* The driver. I choose to use type i2c_driver, as at is identical to both 588 - smbus_driver and isa_driver, and clients could be of either kind */ 589 - static struct i2c_driver via686a_driver = { 590 .driver = { 591 .owner = THIS_MODULE, 592 .name = "via686a", 593 }, 594 - .attach_adapter = via686a_detect, 595 - .detach_client = via686a_detach_client, 596 }; 597 598 599 /* This is called when the module is loaded */ 600 - static int via686a_detect(struct i2c_adapter *adapter) 601 { 602 - struct i2c_client *new_client; 603 struct via686a_data *data; 604 - int err = 0; 605 - const char client_name[] = "via686a"; 606 - u16 val; 607 - 608 - /* 8231 requires multiple of 256, we enforce that on 686 as well */ 609 - if (force_addr) { 610 - address = force_addr & 0xFF00; 611 - dev_warn(&adapter->dev, "forcing ISA address 0x%04X\n", 612 - address); 613 - if (PCIBIOS_SUCCESSFUL != 614 - pci_write_config_word(s_bridge, VIA686A_BASE_REG, address)) 615 - return -ENODEV; 616 - } 617 - if (PCIBIOS_SUCCESSFUL != 618 - pci_read_config_word(s_bridge, VIA686A_ENABLE_REG, &val)) 619 - return -ENODEV; 620 - if (!(val & 0x0001)) { 621 - if (force_addr) { 622 - dev_info(&adapter->dev, "enabling sensors\n"); 623 - if (PCIBIOS_SUCCESSFUL != 624 - pci_write_config_word(s_bridge, VIA686A_ENABLE_REG, 625 - val | 0x0001)) 626 - return -ENODEV; 627 - } else { 628 - dev_warn(&adapter->dev, "sensors disabled - enable " 629 - "with force_addr=0x%x\n", address); 630 - return -ENODEV; 631 - } 632 - } 633 634 /* Reserve the ISA region */ 635 - if (!request_region(address, VIA686A_EXTENT, 636 via686a_driver.driver.name)) { 637 - dev_err(&adapter->dev, "region 0x%x already in use!\n", 638 - address); 639 return -ENODEV; 640 } 641 ··· 615 goto exit_release; 616 } 617 618 - new_client = &data->client; 619 - i2c_set_clientdata(new_client, data); 620 - new_client->addr = address; 621 - new_client->adapter = adapter; 622 - new_client->driver = &via686a_driver; 623 - new_client->flags = 0; 624 - 625 - /* Fill in the remaining client fields and put into the global list */ 626 - strlcpy(new_client->name, client_name, I2C_NAME_SIZE); 627 - 628 - data->valid = 0; 629 mutex_init(&data->update_lock); 630 - /* Tell the I2C layer a new client has arrived */ 631 - if ((err = i2c_attach_client(new_client))) 632 - goto exit_free; 633 634 /* Initialize the VIA686A chip */ 635 - via686a_init_client(new_client); 636 637 /* Register sysfs hooks */ 638 - if ((err = sysfs_create_group(&new_client->dev.kobj, &via686a_group))) 639 - goto exit_detach; 640 641 - data->class_dev = hwmon_device_register(&new_client->dev); 642 if (IS_ERR(data->class_dev)) { 643 err = PTR_ERR(data->class_dev); 644 goto exit_remove_files; ··· 636 return 0; 637 638 exit_remove_files: 639 - sysfs_remove_group(&new_client->dev.kobj, &via686a_group); 640 - exit_detach: 641 - i2c_detach_client(new_client); 642 exit_free: 643 kfree(data); 644 exit_release: 645 - release_region(address, VIA686A_EXTENT); 646 return err; 647 } 648 649 - static int via686a_detach_client(struct i2c_client *client) 650 { 651 - struct via686a_data *data = i2c_get_clientdata(client); 652 - int err; 653 654 hwmon_device_unregister(data->class_dev); 655 - sysfs_remove_group(&client->dev.kobj, &via686a_group); 656 657 - if ((err = i2c_detach_client(client))) 658 - return err; 659 - 660 - release_region(client->addr, VIA686A_EXTENT); 661 kfree(data); 662 663 return 0; 664 } 665 666 - static void via686a_init_client(struct i2c_client *client) 667 { 668 u8 reg; 669 670 /* Start monitoring */ 671 - reg = via686a_read_value(client, VIA686A_REG_CONFIG); 672 - via686a_write_value(client, VIA686A_REG_CONFIG, (reg|0x01)&0x7F); 673 674 /* Configure temp interrupt mode for continuous-interrupt operation */ 675 - via686a_write_value(client, VIA686A_REG_TEMP_MODE, 676 - via686a_read_value(client, VIA686A_REG_TEMP_MODE) & 677 - !(VIA686A_TEMP_MODE_MASK | VIA686A_TEMP_MODE_CONTINUOUS)); 678 } 679 680 static struct via686a_data *via686a_update_device(struct device *dev) 681 { 682 - struct i2c_client *client = to_i2c_client(dev); 683 - struct via686a_data *data = i2c_get_clientdata(client); 684 int i; 685 686 mutex_lock(&data->update_lock); ··· 684 || !data->valid) { 685 for (i = 0; i <= 4; i++) { 686 data->in[i] = 687 - via686a_read_value(client, VIA686A_REG_IN(i)); 688 - data->in_min[i] = via686a_read_value(client, 689 VIA686A_REG_IN_MIN 690 (i)); 691 data->in_max[i] = 692 - via686a_read_value(client, VIA686A_REG_IN_MAX(i)); 693 } 694 for (i = 1; i <= 2; i++) { 695 data->fan[i - 1] = 696 - via686a_read_value(client, VIA686A_REG_FAN(i)); 697 - data->fan_min[i - 1] = via686a_read_value(client, 698 VIA686A_REG_FAN_MIN(i)); 699 } 700 for (i = 0; i <= 2; i++) { 701 - data->temp[i] = via686a_read_value(client, 702 VIA686A_REG_TEMP[i]) << 2; 703 data->temp_over[i] = 704 - via686a_read_value(client, 705 VIA686A_REG_TEMP_OVER[i]); 706 data->temp_hyst[i] = 707 - via686a_read_value(client, 708 VIA686A_REG_TEMP_HYST[i]); 709 } 710 /* add in lower 2 bits ··· 712 temp2 uses bits 5-4 of VIA686A_REG_TEMP_LOW23 713 temp3 uses bits 7-6 of VIA686A_REG_TEMP_LOW23 714 */ 715 - data->temp[0] |= (via686a_read_value(client, 716 VIA686A_REG_TEMP_LOW1) 717 & 0xc0) >> 6; 718 data->temp[1] |= 719 - (via686a_read_value(client, VIA686A_REG_TEMP_LOW23) & 720 0x30) >> 4; 721 data->temp[2] |= 722 - (via686a_read_value(client, VIA686A_REG_TEMP_LOW23) & 723 0xc0) >> 6; 724 725 - i = via686a_read_value(client, VIA686A_REG_FANDIV); 726 data->fan_div[0] = (i >> 4) & 0x03; 727 data->fan_div[1] = i >> 6; 728 data->alarms = 729 - via686a_read_value(client, 730 VIA686A_REG_ALARM1) | 731 - (via686a_read_value(client, VIA686A_REG_ALARM2) << 8); 732 data->last_updated = jiffies; 733 data->valid = 1; 734 } ··· 745 746 MODULE_DEVICE_TABLE(pci, via686a_pci_ids); 747 748 static int __devinit via686a_pci_probe(struct pci_dev *dev, 749 const struct pci_device_id *id) 750 { 751 - u16 val; 752 753 if (PCIBIOS_SUCCESSFUL != 754 pci_read_config_word(dev, VIA686A_BASE_REG, &val)) 755 return -ENODEV; 756 757 address = val & ~(VIA686A_EXTENT - 1); 758 - if (address == 0 && force_addr == 0) { 759 dev_err(&dev->dev, "base address not set - upgrade BIOS " 760 "or use force_addr=0xaddr\n"); 761 return -ENODEV; 762 } 763 764 - s_bridge = pci_dev_get(dev); 765 - if (i2c_isa_add_driver(&via686a_driver)) { 766 - pci_dev_put(s_bridge); 767 - s_bridge = NULL; 768 } 769 770 /* Always return failure here. This is to allow other drivers to bind 771 * to this pci device. We don't really want to have control over the 772 * pci device, we only wanted to read as few register values from it. 773 */ 774 return -ENODEV; 775 } 776 ··· 859 { 860 pci_unregister_driver(&via686a_pci_driver); 861 if (s_bridge != NULL) { 862 - i2c_isa_del_driver(&via686a_driver); 863 pci_dev_put(s_bridge); 864 s_bridge = NULL; 865 }
··· 34 #include <linux/slab.h> 35 #include <linux/pci.h> 36 #include <linux/jiffies.h> 37 + #include <linux/platform_device.h> 38 #include <linux/hwmon.h> 39 + #include <linux/hwmon-sysfs.h> 40 #include <linux/err.h> 41 #include <linux/init.h> 42 #include <linux/mutex.h> ··· 51 MODULE_PARM_DESC(force_addr, 52 "Initialize the base address of the sensors"); 53 54 + static struct platform_device *pdev; 55 56 /* 57 The Via 686a southbridge has a LM78-like chip integrated on the same IC. ··· 295 /* For each registered chip, we need to keep some data in memory. 296 The structure is dynamically allocated. */ 297 struct via686a_data { 298 + unsigned short addr; 299 + const char *name; 300 struct class_device *class_dev; 301 struct mutex update_lock; 302 char valid; /* !=0 if following fields are valid */ ··· 315 316 static struct pci_dev *s_bridge; /* pointer to the (only) via686a */ 317 318 + static int via686a_probe(struct platform_device *pdev); 319 + static int via686a_remove(struct platform_device *pdev); 320 321 + static inline int via686a_read_value(struct via686a_data *data, u8 reg) 322 { 323 + return inb_p(data->addr + reg); 324 } 325 326 + static inline void via686a_write_value(struct via686a_data *data, u8 reg, 327 u8 value) 328 { 329 + outb_p(value, data->addr + reg); 330 } 331 332 static struct via686a_data *via686a_update_device(struct device *dev); 333 + static void via686a_init_device(struct via686a_data *data); 334 335 /* following are the sysfs callback functions */ 336 337 /* 7 voltage sensors */ 338 + static ssize_t show_in(struct device *dev, struct device_attribute *da, 339 + char *buf) { 340 struct via686a_data *data = via686a_update_device(dev); 341 + struct sensor_device_attribute *attr = to_sensor_dev_attr(da); 342 + int nr = attr->index; 343 return sprintf(buf, "%ld\n", IN_FROM_REG(data->in[nr], nr)); 344 } 345 346 + static ssize_t show_in_min(struct device *dev, struct device_attribute *da, 347 + char *buf) { 348 struct via686a_data *data = via686a_update_device(dev); 349 + struct sensor_device_attribute *attr = to_sensor_dev_attr(da); 350 + int nr = attr->index; 351 return sprintf(buf, "%ld\n", IN_FROM_REG(data->in_min[nr], nr)); 352 } 353 354 + static ssize_t show_in_max(struct device *dev, struct device_attribute *da, 355 + char *buf) { 356 struct via686a_data *data = via686a_update_device(dev); 357 + struct sensor_device_attribute *attr = to_sensor_dev_attr(da); 358 + int nr = attr->index; 359 return sprintf(buf, "%ld\n", IN_FROM_REG(data->in_max[nr], nr)); 360 } 361 362 + static ssize_t set_in_min(struct device *dev, struct device_attribute *da, 363 + const char *buf, size_t count) { 364 + struct via686a_data *data = dev_get_drvdata(dev); 365 + struct sensor_device_attribute *attr = to_sensor_dev_attr(da); 366 + int nr = attr->index; 367 unsigned long val = simple_strtoul(buf, NULL, 10); 368 369 mutex_lock(&data->update_lock); 370 data->in_min[nr] = IN_TO_REG(val, nr); 371 + via686a_write_value(data, VIA686A_REG_IN_MIN(nr), 372 data->in_min[nr]); 373 mutex_unlock(&data->update_lock); 374 return count; 375 } 376 + static ssize_t set_in_max(struct device *dev, struct device_attribute *da, 377 + const char *buf, size_t count) { 378 + struct via686a_data *data = dev_get_drvdata(dev); 379 + struct sensor_device_attribute *attr = to_sensor_dev_attr(da); 380 + int nr = attr->index; 381 unsigned long val = simple_strtoul(buf, NULL, 10); 382 383 mutex_lock(&data->update_lock); 384 data->in_max[nr] = IN_TO_REG(val, nr); 385 + via686a_write_value(data, VIA686A_REG_IN_MAX(nr), 386 data->in_max[nr]); 387 mutex_unlock(&data->update_lock); 388 return count; 389 } 390 #define show_in_offset(offset) \ 391 + static SENSOR_DEVICE_ATTR(in##offset##_input, S_IRUGO, \ 392 + show_in, NULL, offset); \ 393 + static SENSOR_DEVICE_ATTR(in##offset##_min, S_IRUGO | S_IWUSR, \ 394 + show_in_min, set_in_min, offset); \ 395 + static SENSOR_DEVICE_ATTR(in##offset##_max, S_IRUGO | S_IWUSR, \ 396 + show_in_max, set_in_max, offset); 397 398 show_in_offset(0); 399 show_in_offset(1); ··· 415 show_in_offset(4); 416 417 /* 3 temperatures */ 418 + static ssize_t show_temp(struct device *dev, struct device_attribute *da, 419 + char *buf) { 420 struct via686a_data *data = via686a_update_device(dev); 421 + struct sensor_device_attribute *attr = to_sensor_dev_attr(da); 422 + int nr = attr->index; 423 return sprintf(buf, "%ld\n", TEMP_FROM_REG10(data->temp[nr])); 424 } 425 + static ssize_t show_temp_over(struct device *dev, struct device_attribute *da, 426 + char *buf) { 427 struct via686a_data *data = via686a_update_device(dev); 428 + struct sensor_device_attribute *attr = to_sensor_dev_attr(da); 429 + int nr = attr->index; 430 return sprintf(buf, "%ld\n", TEMP_FROM_REG(data->temp_over[nr])); 431 } 432 + static ssize_t show_temp_hyst(struct device *dev, struct device_attribute *da, 433 + char *buf) { 434 struct via686a_data *data = via686a_update_device(dev); 435 + struct sensor_device_attribute *attr = to_sensor_dev_attr(da); 436 + int nr = attr->index; 437 return sprintf(buf, "%ld\n", TEMP_FROM_REG(data->temp_hyst[nr])); 438 } 439 + static ssize_t set_temp_over(struct device *dev, struct device_attribute *da, 440 + const char *buf, size_t count) { 441 + struct via686a_data *data = dev_get_drvdata(dev); 442 + struct sensor_device_attribute *attr = to_sensor_dev_attr(da); 443 + int nr = attr->index; 444 int val = simple_strtol(buf, NULL, 10); 445 446 mutex_lock(&data->update_lock); 447 data->temp_over[nr] = TEMP_TO_REG(val); 448 + via686a_write_value(data, VIA686A_REG_TEMP_OVER[nr], 449 data->temp_over[nr]); 450 mutex_unlock(&data->update_lock); 451 return count; 452 } 453 + static ssize_t set_temp_hyst(struct device *dev, struct device_attribute *da, 454 + const char *buf, size_t count) { 455 + struct via686a_data *data = dev_get_drvdata(dev); 456 + struct sensor_device_attribute *attr = to_sensor_dev_attr(da); 457 + int nr = attr->index; 458 int val = simple_strtol(buf, NULL, 10); 459 460 mutex_lock(&data->update_lock); 461 data->temp_hyst[nr] = TEMP_TO_REG(val); 462 + via686a_write_value(data, VIA686A_REG_TEMP_HYST[nr], 463 data->temp_hyst[nr]); 464 mutex_unlock(&data->update_lock); 465 return count; 466 } 467 #define show_temp_offset(offset) \ 468 + static SENSOR_DEVICE_ATTR(temp##offset##_input, S_IRUGO, \ 469 + show_temp, NULL, offset - 1); \ 470 + static SENSOR_DEVICE_ATTR(temp##offset##_max, S_IRUGO | S_IWUSR, \ 471 + show_temp_over, set_temp_over, offset - 1); \ 472 + static SENSOR_DEVICE_ATTR(temp##offset##_max_hyst, S_IRUGO | S_IWUSR, \ 473 + show_temp_hyst, set_temp_hyst, offset - 1); 474 475 show_temp_offset(1); 476 show_temp_offset(2); 477 show_temp_offset(3); 478 479 /* 2 Fans */ 480 + static ssize_t show_fan(struct device *dev, struct device_attribute *da, 481 + char *buf) { 482 struct via686a_data *data = via686a_update_device(dev); 483 + struct sensor_device_attribute *attr = to_sensor_dev_attr(da); 484 + int nr = attr->index; 485 return sprintf(buf, "%d\n", FAN_FROM_REG(data->fan[nr], 486 DIV_FROM_REG(data->fan_div[nr])) ); 487 } 488 + static ssize_t show_fan_min(struct device *dev, struct device_attribute *da, 489 + char *buf) { 490 struct via686a_data *data = via686a_update_device(dev); 491 + struct sensor_device_attribute *attr = to_sensor_dev_attr(da); 492 + int nr = attr->index; 493 return sprintf(buf, "%d\n", 494 FAN_FROM_REG(data->fan_min[nr], DIV_FROM_REG(data->fan_div[nr])) ); 495 } 496 + static ssize_t show_fan_div(struct device *dev, struct device_attribute *da, 497 + char *buf) { 498 struct via686a_data *data = via686a_update_device(dev); 499 + struct sensor_device_attribute *attr = to_sensor_dev_attr(da); 500 + int nr = attr->index; 501 return sprintf(buf, "%d\n", DIV_FROM_REG(data->fan_div[nr]) ); 502 } 503 + static ssize_t set_fan_min(struct device *dev, struct device_attribute *da, 504 + const char *buf, size_t count) { 505 + struct via686a_data *data = dev_get_drvdata(dev); 506 + struct sensor_device_attribute *attr = to_sensor_dev_attr(da); 507 + int nr = attr->index; 508 int val = simple_strtol(buf, NULL, 10); 509 510 mutex_lock(&data->update_lock); 511 data->fan_min[nr] = FAN_TO_REG(val, DIV_FROM_REG(data->fan_div[nr])); 512 + via686a_write_value(data, VIA686A_REG_FAN_MIN(nr+1), data->fan_min[nr]); 513 mutex_unlock(&data->update_lock); 514 return count; 515 } 516 + static ssize_t set_fan_div(struct device *dev, struct device_attribute *da, 517 + const char *buf, size_t count) { 518 + struct via686a_data *data = dev_get_drvdata(dev); 519 + struct sensor_device_attribute *attr = to_sensor_dev_attr(da); 520 + int nr = attr->index; 521 int val = simple_strtol(buf, NULL, 10); 522 int old; 523 524 mutex_lock(&data->update_lock); 525 + old = via686a_read_value(data, VIA686A_REG_FANDIV); 526 data->fan_div[nr] = DIV_TO_REG(val); 527 old = (old & 0x0f) | (data->fan_div[1] << 6) | (data->fan_div[0] << 4); 528 + via686a_write_value(data, VIA686A_REG_FANDIV, old); 529 mutex_unlock(&data->update_lock); 530 return count; 531 } 532 533 #define show_fan_offset(offset) \ 534 + static SENSOR_DEVICE_ATTR(fan##offset##_input, S_IRUGO, \ 535 + show_fan, NULL, offset - 1); \ 536 + static SENSOR_DEVICE_ATTR(fan##offset##_min, S_IRUGO | S_IWUSR, \ 537 + show_fan_min, set_fan_min, offset - 1); \ 538 + static SENSOR_DEVICE_ATTR(fan##offset##_div, S_IRUGO | S_IWUSR, \ 539 + show_fan_div, set_fan_div, offset - 1); 540 541 show_fan_offset(1); 542 show_fan_offset(2); ··· 570 } 571 static DEVICE_ATTR(alarms, S_IRUGO, show_alarms, NULL); 572 573 + static ssize_t show_name(struct device *dev, struct device_attribute 574 + *devattr, char *buf) 575 + { 576 + struct via686a_data *data = dev_get_drvdata(dev); 577 + return sprintf(buf, "%s\n", data->name); 578 + } 579 + static DEVICE_ATTR(name, S_IRUGO, show_name, NULL); 580 + 581 static struct attribute *via686a_attributes[] = { 582 + &sensor_dev_attr_in0_input.dev_attr.attr, 583 + &sensor_dev_attr_in1_input.dev_attr.attr, 584 + &sensor_dev_attr_in2_input.dev_attr.attr, 585 + &sensor_dev_attr_in3_input.dev_attr.attr, 586 + &sensor_dev_attr_in4_input.dev_attr.attr, 587 + &sensor_dev_attr_in0_min.dev_attr.attr, 588 + &sensor_dev_attr_in1_min.dev_attr.attr, 589 + &sensor_dev_attr_in2_min.dev_attr.attr, 590 + &sensor_dev_attr_in3_min.dev_attr.attr, 591 + &sensor_dev_attr_in4_min.dev_attr.attr, 592 + &sensor_dev_attr_in0_max.dev_attr.attr, 593 + &sensor_dev_attr_in1_max.dev_attr.attr, 594 + &sensor_dev_attr_in2_max.dev_attr.attr, 595 + &sensor_dev_attr_in3_max.dev_attr.attr, 596 + &sensor_dev_attr_in4_max.dev_attr.attr, 597 598 + &sensor_dev_attr_temp1_input.dev_attr.attr, 599 + &sensor_dev_attr_temp2_input.dev_attr.attr, 600 + &sensor_dev_attr_temp3_input.dev_attr.attr, 601 + &sensor_dev_attr_temp1_max.dev_attr.attr, 602 + &sensor_dev_attr_temp2_max.dev_attr.attr, 603 + &sensor_dev_attr_temp3_max.dev_attr.attr, 604 + &sensor_dev_attr_temp1_max_hyst.dev_attr.attr, 605 + &sensor_dev_attr_temp2_max_hyst.dev_attr.attr, 606 + &sensor_dev_attr_temp3_max_hyst.dev_attr.attr, 607 608 + &sensor_dev_attr_fan1_input.dev_attr.attr, 609 + &sensor_dev_attr_fan2_input.dev_attr.attr, 610 + &sensor_dev_attr_fan1_min.dev_attr.attr, 611 + &sensor_dev_attr_fan2_min.dev_attr.attr, 612 + &sensor_dev_attr_fan1_div.dev_attr.attr, 613 + &sensor_dev_attr_fan2_div.dev_attr.attr, 614 615 &dev_attr_alarms.attr, 616 + &dev_attr_name.attr, 617 NULL 618 }; 619 ··· 612 .attrs = via686a_attributes, 613 }; 614 615 + static struct platform_driver via686a_driver = { 616 .driver = { 617 .owner = THIS_MODULE, 618 .name = "via686a", 619 }, 620 + .probe = via686a_probe, 621 + .remove = __devexit_p(via686a_remove), 622 }; 623 624 625 /* This is called when the module is loaded */ 626 + static int __devinit via686a_probe(struct platform_device *pdev) 627 { 628 struct via686a_data *data; 629 + struct resource *res; 630 + int err; 631 632 /* Reserve the ISA region */ 633 + res = platform_get_resource(pdev, IORESOURCE_IO, 0); 634 + if (!request_region(res->start, VIA686A_EXTENT, 635 via686a_driver.driver.name)) { 636 + dev_err(&pdev->dev, "Region 0x%lx-0x%lx already in use!\n", 637 + (unsigned long)res->start, (unsigned long)res->end); 638 return -ENODEV; 639 } 640 ··· 672 goto exit_release; 673 } 674 675 + platform_set_drvdata(pdev, data); 676 + data->addr = res->start; 677 + data->name = "via686a"; 678 mutex_init(&data->update_lock); 679 680 /* Initialize the VIA686A chip */ 681 + via686a_init_device(data); 682 683 /* Register sysfs hooks */ 684 + if ((err = sysfs_create_group(&pdev->dev.kobj, &via686a_group))) 685 + goto exit_free; 686 687 + data->class_dev = hwmon_device_register(&pdev->dev); 688 if (IS_ERR(data->class_dev)) { 689 err = PTR_ERR(data->class_dev); 690 goto exit_remove_files; ··· 704 return 0; 705 706 exit_remove_files: 707 + sysfs_remove_group(&pdev->dev.kobj, &via686a_group); 708 exit_free: 709 kfree(data); 710 exit_release: 711 + release_region(res->start, VIA686A_EXTENT); 712 return err; 713 } 714 715 + static int __devexit via686a_remove(struct platform_device *pdev) 716 { 717 + struct via686a_data *data = platform_get_drvdata(pdev); 718 719 hwmon_device_unregister(data->class_dev); 720 + sysfs_remove_group(&pdev->dev.kobj, &via686a_group); 721 722 + release_region(data->addr, VIA686A_EXTENT); 723 + platform_set_drvdata(pdev, NULL); 724 kfree(data); 725 726 return 0; 727 } 728 729 + static void __devinit via686a_init_device(struct via686a_data *data) 730 { 731 u8 reg; 732 733 /* Start monitoring */ 734 + reg = via686a_read_value(data, VIA686A_REG_CONFIG); 735 + via686a_write_value(data, VIA686A_REG_CONFIG, (reg | 0x01) & 0x7F); 736 737 /* Configure temp interrupt mode for continuous-interrupt operation */ 738 + reg = via686a_read_value(data, VIA686A_REG_TEMP_MODE); 739 + via686a_write_value(data, VIA686A_REG_TEMP_MODE, 740 + (reg & ~VIA686A_TEMP_MODE_MASK) 741 + | VIA686A_TEMP_MODE_CONTINUOUS); 742 } 743 744 static struct via686a_data *via686a_update_device(struct device *dev) 745 { 746 + struct via686a_data *data = dev_get_drvdata(dev); 747 int i; 748 749 mutex_lock(&data->update_lock); ··· 757 || !data->valid) { 758 for (i = 0; i <= 4; i++) { 759 data->in[i] = 760 + via686a_read_value(data, VIA686A_REG_IN(i)); 761 + data->in_min[i] = via686a_read_value(data, 762 VIA686A_REG_IN_MIN 763 (i)); 764 data->in_max[i] = 765 + via686a_read_value(data, VIA686A_REG_IN_MAX(i)); 766 } 767 for (i = 1; i <= 2; i++) { 768 data->fan[i - 1] = 769 + via686a_read_value(data, VIA686A_REG_FAN(i)); 770 + data->fan_min[i - 1] = via686a_read_value(data, 771 VIA686A_REG_FAN_MIN(i)); 772 } 773 for (i = 0; i <= 2; i++) { 774 + data->temp[i] = via686a_read_value(data, 775 VIA686A_REG_TEMP[i]) << 2; 776 data->temp_over[i] = 777 + via686a_read_value(data, 778 VIA686A_REG_TEMP_OVER[i]); 779 data->temp_hyst[i] = 780 + via686a_read_value(data, 781 VIA686A_REG_TEMP_HYST[i]); 782 } 783 /* add in lower 2 bits ··· 785 temp2 uses bits 5-4 of VIA686A_REG_TEMP_LOW23 786 temp3 uses bits 7-6 of VIA686A_REG_TEMP_LOW23 787 */ 788 + data->temp[0] |= (via686a_read_value(data, 789 VIA686A_REG_TEMP_LOW1) 790 & 0xc0) >> 6; 791 data->temp[1] |= 792 + (via686a_read_value(data, VIA686A_REG_TEMP_LOW23) & 793 0x30) >> 4; 794 data->temp[2] |= 795 + (via686a_read_value(data, VIA686A_REG_TEMP_LOW23) & 796 0xc0) >> 6; 797 798 + i = via686a_read_value(data, VIA686A_REG_FANDIV); 799 data->fan_div[0] = (i >> 4) & 0x03; 800 data->fan_div[1] = i >> 6; 801 data->alarms = 802 + via686a_read_value(data, 803 VIA686A_REG_ALARM1) | 804 + (via686a_read_value(data, VIA686A_REG_ALARM2) << 8); 805 data->last_updated = jiffies; 806 data->valid = 1; 807 } ··· 818 819 MODULE_DEVICE_TABLE(pci, via686a_pci_ids); 820 821 + static int __devinit via686a_device_add(unsigned short address) 822 + { 823 + struct resource res = { 824 + .start = address, 825 + .end = address + VIA686A_EXTENT - 1, 826 + .name = "via686a", 827 + .flags = IORESOURCE_IO, 828 + }; 829 + int err; 830 + 831 + pdev = platform_device_alloc("via686a", address); 832 + if (!pdev) { 833 + err = -ENOMEM; 834 + printk(KERN_ERR "via686a: Device allocation failed\n"); 835 + goto exit; 836 + } 837 + 838 + err = platform_device_add_resources(pdev, &res, 1); 839 + if (err) { 840 + printk(KERN_ERR "via686a: Device resource addition failed " 841 + "(%d)\n", err); 842 + goto exit_device_put; 843 + } 844 + 845 + err = platform_device_add(pdev); 846 + if (err) { 847 + printk(KERN_ERR "via686a: Device addition failed (%d)\n", 848 + err); 849 + goto exit_device_put; 850 + } 851 + 852 + return 0; 853 + 854 + exit_device_put: 855 + platform_device_put(pdev); 856 + exit: 857 + return err; 858 + } 859 + 860 static int __devinit via686a_pci_probe(struct pci_dev *dev, 861 const struct pci_device_id *id) 862 { 863 + u16 address, val; 864 865 + if (force_addr) { 866 + address = force_addr & ~(VIA686A_EXTENT - 1); 867 + dev_warn(&dev->dev, "Forcing ISA address 0x%x\n", address); 868 + if (PCIBIOS_SUCCESSFUL != 869 + pci_write_config_word(dev, VIA686A_BASE_REG, address | 1)) 870 + return -ENODEV; 871 + } 872 if (PCIBIOS_SUCCESSFUL != 873 pci_read_config_word(dev, VIA686A_BASE_REG, &val)) 874 return -ENODEV; 875 876 address = val & ~(VIA686A_EXTENT - 1); 877 + if (address == 0) { 878 dev_err(&dev->dev, "base address not set - upgrade BIOS " 879 "or use force_addr=0xaddr\n"); 880 return -ENODEV; 881 } 882 883 + if (PCIBIOS_SUCCESSFUL != 884 + pci_read_config_word(dev, VIA686A_ENABLE_REG, &val)) 885 + return -ENODEV; 886 + if (!(val & 0x0001)) { 887 + if (!force_addr) { 888 + dev_warn(&dev->dev, "Sensors disabled, enable " 889 + "with force_addr=0x%x\n", address); 890 + return -ENODEV; 891 + } 892 + 893 + dev_warn(&dev->dev, "Enabling sensors\n"); 894 + if (PCIBIOS_SUCCESSFUL != 895 + pci_write_config_word(dev, VIA686A_ENABLE_REG, 896 + val | 0x0001)) 897 + return -ENODEV; 898 } 899 + 900 + if (platform_driver_register(&via686a_driver)) 901 + goto exit; 902 + 903 + /* Sets global pdev as a side effect */ 904 + if (via686a_device_add(address)) 905 + goto exit_unregister; 906 907 /* Always return failure here. This is to allow other drivers to bind 908 * to this pci device. We don't really want to have control over the 909 * pci device, we only wanted to read as few register values from it. 910 */ 911 + s_bridge = pci_dev_get(dev); 912 + return -ENODEV; 913 + 914 + exit_unregister: 915 + platform_driver_unregister(&via686a_driver); 916 + exit: 917 return -ENODEV; 918 } 919 ··· 862 { 863 pci_unregister_driver(&via686a_pci_driver); 864 if (s_bridge != NULL) { 865 + platform_device_unregister(pdev); 866 + platform_driver_unregister(&via686a_driver); 867 pci_dev_put(s_bridge); 868 s_bridge = NULL; 869 }
+174 -144
drivers/hwmon/vt8231.c
··· 29 #include <linux/slab.h> 30 #include <linux/pci.h> 31 #include <linux/jiffies.h> 32 - #include <linux/i2c.h> 33 - #include <linux/i2c-isa.h> 34 #include <linux/hwmon.h> 35 #include <linux/hwmon-sysfs.h> 36 #include <linux/hwmon-vid.h> ··· 41 module_param(force_addr, int, 0); 42 MODULE_PARM_DESC(force_addr, "Initialize the base address of the sensors"); 43 44 - /* Device address 45 - Note that we can't determine the ISA address until we have initialized 46 - our module */ 47 - static unsigned short isa_address; 48 49 #define VT8231_EXTENT 0x80 50 #define VT8231_BASE_REG 0x70 ··· 144 #define FAN_FROM_REG(val, div) ((val) == 0 ? 0 : 1310720 / ((val) * (div))) 145 146 struct vt8231_data { 147 - struct i2c_client client; 148 struct mutex update_lock; 149 struct class_device *class_dev; 150 char valid; /* !=0 if following fields are valid */ ··· 166 }; 167 168 static struct pci_dev *s_bridge; 169 - static int vt8231_detect(struct i2c_adapter *adapter); 170 - static int vt8231_detach_client(struct i2c_client *client); 171 static struct vt8231_data *vt8231_update_device(struct device *dev); 172 - static void vt8231_init_client(struct i2c_client *client); 173 174 - static inline int vt8231_read_value(struct i2c_client *client, u8 reg) 175 { 176 - return inb_p(client->addr + reg); 177 } 178 179 - static inline void vt8231_write_value(struct i2c_client *client, u8 reg, 180 u8 value) 181 { 182 - outb_p(value, client->addr + reg); 183 } 184 185 /* following are the sysfs callback functions */ ··· 218 { 219 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); 220 int nr = sensor_attr->index; 221 - struct i2c_client *client = to_i2c_client(dev); 222 - struct vt8231_data *data = i2c_get_clientdata(client); 223 unsigned long val = simple_strtoul(buf, NULL, 10); 224 225 mutex_lock(&data->update_lock); 226 data->in_min[nr] = SENSORS_LIMIT(((val * 958) / 10000) + 3, 0, 255); 227 - vt8231_write_value(client, regvoltmin[nr], data->in_min[nr]); 228 mutex_unlock(&data->update_lock); 229 return count; 230 } ··· 233 { 234 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); 235 int nr = sensor_attr->index; 236 - struct i2c_client *client = to_i2c_client(dev); 237 - struct vt8231_data *data = i2c_get_clientdata(client); 238 unsigned long val = simple_strtoul(buf, NULL, 10); 239 240 mutex_lock(&data->update_lock); 241 data->in_max[nr] = SENSORS_LIMIT(((val * 958) / 10000) + 3, 0, 255); 242 - vt8231_write_value(client, regvoltmax[nr], data->in_max[nr]); 243 mutex_unlock(&data->update_lock); 244 return count; 245 } ··· 274 static ssize_t set_in5_min(struct device *dev, struct device_attribute *attr, 275 const char *buf, size_t count) 276 { 277 - struct i2c_client *client = to_i2c_client(dev); 278 - struct vt8231_data *data = i2c_get_clientdata(client); 279 unsigned long val = simple_strtoul(buf, NULL, 10); 280 281 mutex_lock(&data->update_lock); 282 data->in_min[5] = SENSORS_LIMIT(((val * 958 * 34) / (10000 * 54)) + 3, 283 0, 255); 284 - vt8231_write_value(client, regvoltmin[5], data->in_min[5]); 285 mutex_unlock(&data->update_lock); 286 return count; 287 } ··· 288 static ssize_t set_in5_max(struct device *dev, struct device_attribute *attr, 289 const char *buf, size_t count) 290 { 291 - struct i2c_client *client = to_i2c_client(dev); 292 - struct vt8231_data *data = i2c_get_clientdata(client); 293 unsigned long val = simple_strtoul(buf, NULL, 10); 294 295 mutex_lock(&data->update_lock); 296 data->in_max[5] = SENSORS_LIMIT(((val * 958 * 34) / (10000 * 54)) + 3, 297 0, 255); 298 - vt8231_write_value(client, regvoltmax[5], data->in_max[5]); 299 mutex_unlock(&data->update_lock); 300 return count; 301 } ··· 342 static ssize_t set_temp0_max(struct device *dev, struct device_attribute *attr, 343 const char *buf, size_t count) 344 { 345 - struct i2c_client *client = to_i2c_client(dev); 346 - struct vt8231_data *data = i2c_get_clientdata(client); 347 int val = simple_strtol(buf, NULL, 10); 348 349 mutex_lock(&data->update_lock); 350 data->temp_max[0] = SENSORS_LIMIT((val + 500) / 1000, 0, 255); 351 - vt8231_write_value(client, regtempmax[0], data->temp_max[0]); 352 mutex_unlock(&data->update_lock); 353 return count; 354 } 355 static ssize_t set_temp0_min(struct device *dev, struct device_attribute *attr, 356 const char *buf, size_t count) 357 { 358 - struct i2c_client *client = to_i2c_client(dev); 359 - struct vt8231_data *data = i2c_get_clientdata(client); 360 int val = simple_strtol(buf, NULL, 10); 361 362 mutex_lock(&data->update_lock); 363 data->temp_min[0] = SENSORS_LIMIT((val + 500) / 1000, 0, 255); 364 - vt8231_write_value(client, regtempmin[0], data->temp_min[0]); 365 mutex_unlock(&data->update_lock); 366 return count; 367 } ··· 396 { 397 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); 398 int nr = sensor_attr->index; 399 - struct i2c_client *client = to_i2c_client(dev); 400 - struct vt8231_data *data = i2c_get_clientdata(client); 401 int val = simple_strtol(buf, NULL, 10); 402 403 mutex_lock(&data->update_lock); 404 data->temp_max[nr] = SENSORS_LIMIT(TEMP_MAXMIN_TO_REG(val), 0, 255); 405 - vt8231_write_value(client, regtempmax[nr], data->temp_max[nr]); 406 mutex_unlock(&data->update_lock); 407 return count; 408 } ··· 410 { 411 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); 412 int nr = sensor_attr->index; 413 - struct i2c_client *client = to_i2c_client(dev); 414 - struct vt8231_data *data = i2c_get_clientdata(client); 415 int val = simple_strtol(buf, NULL, 10); 416 417 mutex_lock(&data->update_lock); 418 data->temp_min[nr] = SENSORS_LIMIT(TEMP_MAXMIN_TO_REG(val), 0, 255); 419 - vt8231_write_value(client, regtempmin[nr], data->temp_min[nr]); 420 mutex_unlock(&data->update_lock); 421 return count; 422 } ··· 476 { 477 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); 478 int nr = sensor_attr->index; 479 - struct i2c_client *client = to_i2c_client(dev); 480 - struct vt8231_data *data = i2c_get_clientdata(client); 481 int val = simple_strtoul(buf, NULL, 10); 482 483 mutex_lock(&data->update_lock); 484 data->fan_min[nr] = FAN_TO_REG(val, DIV_FROM_REG(data->fan_div[nr])); 485 - vt8231_write_value(client, VT8231_REG_FAN_MIN(nr), data->fan_min[nr]); 486 mutex_unlock(&data->update_lock); 487 return count; 488 } ··· 489 static ssize_t set_fan_div(struct device *dev, struct device_attribute *attr, 490 const char *buf, size_t count) 491 { 492 - struct i2c_client *client = to_i2c_client(dev); 493 - struct vt8231_data *data = i2c_get_clientdata(client); 494 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); 495 unsigned long val = simple_strtoul(buf, NULL, 10); 496 int nr = sensor_attr->index; 497 - int old = vt8231_read_value(client, VT8231_REG_FANDIV); 498 long min = FAN_FROM_REG(data->fan_min[nr], 499 DIV_FROM_REG(data->fan_div[nr])); 500 ··· 504 case 4: data->fan_div[nr] = 2; break; 505 case 8: data->fan_div[nr] = 3; break; 506 default: 507 - dev_err(&client->dev, "fan_div value %ld not supported." 508 "Choose one of 1, 2, 4 or 8!\n", val); 509 mutex_unlock(&data->update_lock); 510 return -EINVAL; ··· 512 513 /* Correct the fan minimum speed */ 514 data->fan_min[nr] = FAN_TO_REG(min, DIV_FROM_REG(data->fan_div[nr])); 515 - vt8231_write_value(client, VT8231_REG_FAN_MIN(nr), data->fan_min[nr]); 516 517 old = (old & 0x0f) | (data->fan_div[1] << 6) | (data->fan_div[0] << 4); 518 - vt8231_write_value(client, VT8231_REG_FANDIV, old); 519 mutex_unlock(&data->update_lock); 520 return count; 521 } ··· 539 struct vt8231_data *data = vt8231_update_device(dev); 540 return sprintf(buf, "%d\n", data->alarms); 541 } 542 - 543 static DEVICE_ATTR(alarms, S_IRUGO, show_alarms, NULL); 544 545 static struct attribute *vt8231_attributes_temps[6][4] = { 546 { ··· 643 &sensor_dev_attr_fan1_div.dev_attr.attr, 644 &sensor_dev_attr_fan2_div.dev_attr.attr, 645 &dev_attr_alarms.attr, 646 NULL 647 }; 648 ··· 651 .attrs = vt8231_attributes, 652 }; 653 654 - static struct i2c_driver vt8231_driver = { 655 .driver = { 656 .owner = THIS_MODULE, 657 .name = "vt8231", 658 }, 659 - .attach_adapter = vt8231_detect, 660 - .detach_client = vt8231_detach_client, 661 }; 662 663 static struct pci_device_id vt8231_pci_ids[] = { ··· 676 .probe = vt8231_pci_probe, 677 }; 678 679 - int vt8231_detect(struct i2c_adapter *adapter) 680 { 681 - struct i2c_client *client; 682 struct vt8231_data *data; 683 int err = 0, i; 684 - u16 val; 685 - 686 - /* 8231 requires multiple of 256 */ 687 - if (force_addr) { 688 - isa_address = force_addr & 0xFF00; 689 - dev_warn(&adapter->dev, "forcing ISA address 0x%04X\n", 690 - isa_address); 691 - if (PCIBIOS_SUCCESSFUL != pci_write_config_word(s_bridge, 692 - VT8231_BASE_REG, isa_address)) 693 - return -ENODEV; 694 - } 695 - 696 - if (PCIBIOS_SUCCESSFUL != 697 - pci_read_config_word(s_bridge, VT8231_ENABLE_REG, &val)) 698 - return -ENODEV; 699 - 700 - if (!(val & 0x0001)) { 701 - dev_warn(&adapter->dev, "enabling sensors\n"); 702 - if (PCIBIOS_SUCCESSFUL != 703 - pci_write_config_word(s_bridge, VT8231_ENABLE_REG, 704 - val | 0x0001)) 705 - return -ENODEV; 706 - } 707 708 /* Reserve the ISA region */ 709 - if (!request_region(isa_address, VT8231_EXTENT, 710 - vt8231_pci_driver.name)) { 711 - dev_err(&adapter->dev, "region 0x%x already in use!\n", 712 - isa_address); 713 return -ENODEV; 714 } 715 ··· 696 goto exit_release; 697 } 698 699 - client = &data->client; 700 - i2c_set_clientdata(client, data); 701 - client->addr = isa_address; 702 - client->adapter = adapter; 703 - client->driver = &vt8231_driver; 704 - 705 - /* Fill in the remaining client fields and put into the global list */ 706 - strlcpy(client->name, "vt8231", I2C_NAME_SIZE); 707 708 mutex_init(&data->update_lock); 709 - 710 - /* Tell the I2C layer a new client has arrived */ 711 - if ((err = i2c_attach_client(client))) 712 - goto exit_free; 713 - 714 - vt8231_init_client(client); 715 716 /* Register sysfs hooks */ 717 - if ((err = sysfs_create_group(&client->dev.kobj, &vt8231_group))) 718 - goto exit_detach; 719 720 /* Must update device information to find out the config field */ 721 - data->uch_config = vt8231_read_value(client, VT8231_REG_UCH_CONFIG); 722 723 for (i = 0; i < ARRAY_SIZE(vt8231_group_temps); i++) { 724 if (ISTEMP(i, data->uch_config)) { 725 - if ((err = sysfs_create_group(&client->dev.kobj, 726 &vt8231_group_temps[i]))) 727 goto exit_remove_files; 728 } ··· 720 721 for (i = 0; i < ARRAY_SIZE(vt8231_group_volts); i++) { 722 if (ISVOLT(i, data->uch_config)) { 723 - if ((err = sysfs_create_group(&client->dev.kobj, 724 &vt8231_group_volts[i]))) 725 goto exit_remove_files; 726 } 727 } 728 729 - data->class_dev = hwmon_device_register(&client->dev); 730 if (IS_ERR(data->class_dev)) { 731 err = PTR_ERR(data->class_dev); 732 goto exit_remove_files; ··· 735 736 exit_remove_files: 737 for (i = 0; i < ARRAY_SIZE(vt8231_group_volts); i++) 738 - sysfs_remove_group(&client->dev.kobj, &vt8231_group_volts[i]); 739 740 for (i = 0; i < ARRAY_SIZE(vt8231_group_temps); i++) 741 - sysfs_remove_group(&client->dev.kobj, &vt8231_group_temps[i]); 742 743 - sysfs_remove_group(&client->dev.kobj, &vt8231_group); 744 - exit_detach: 745 - i2c_detach_client(client); 746 exit_free: 747 kfree(data); 748 exit_release: 749 - release_region(isa_address, VT8231_EXTENT); 750 return err; 751 } 752 753 - static int vt8231_detach_client(struct i2c_client *client) 754 { 755 - struct vt8231_data *data = i2c_get_clientdata(client); 756 - int err, i; 757 758 hwmon_device_unregister(data->class_dev); 759 760 for (i = 0; i < ARRAY_SIZE(vt8231_group_volts); i++) 761 - sysfs_remove_group(&client->dev.kobj, &vt8231_group_volts[i]); 762 763 for (i = 0; i < ARRAY_SIZE(vt8231_group_temps); i++) 764 - sysfs_remove_group(&client->dev.kobj, &vt8231_group_temps[i]); 765 766 - sysfs_remove_group(&client->dev.kobj, &vt8231_group); 767 768 - if ((err = i2c_detach_client(client))) { 769 - return err; 770 - } 771 - 772 - release_region(client->addr, VT8231_EXTENT); 773 kfree(data); 774 - 775 return 0; 776 } 777 778 - static void vt8231_init_client(struct i2c_client *client) 779 { 780 - vt8231_write_value(client, VT8231_REG_TEMP1_CONFIG, 0); 781 - vt8231_write_value(client, VT8231_REG_TEMP2_CONFIG, 0); 782 } 783 784 static struct vt8231_data *vt8231_update_device(struct device *dev) 785 { 786 - struct i2c_client *client = to_i2c_client(dev); 787 - struct vt8231_data *data = i2c_get_clientdata(client); 788 int i; 789 u16 low; 790 ··· 790 || !data->valid) { 791 for (i = 0; i < 6; i++) { 792 if (ISVOLT(i, data->uch_config)) { 793 - data->in[i] = vt8231_read_value(client, 794 regvolt[i]); 795 - data->in_min[i] = vt8231_read_value(client, 796 regvoltmin[i]); 797 - data->in_max[i] = vt8231_read_value(client, 798 regvoltmax[i]); 799 } 800 } 801 for (i = 0; i < 2; i++) { 802 - data->fan[i] = vt8231_read_value(client, 803 VT8231_REG_FAN(i)); 804 - data->fan_min[i] = vt8231_read_value(client, 805 VT8231_REG_FAN_MIN(i)); 806 } 807 808 - low = vt8231_read_value(client, VT8231_REG_TEMP_LOW01); 809 low = (low >> 6) | ((low & 0x30) >> 2) 810 - | (vt8231_read_value(client, VT8231_REG_TEMP_LOW25) << 4); 811 for (i = 0; i < 6; i++) { 812 if (ISTEMP(i, data->uch_config)) { 813 - data->temp[i] = (vt8231_read_value(client, 814 regtemp[i]) << 2) 815 | ((low >> (2 * i)) & 0x03); 816 - data->temp_max[i] = vt8231_read_value(client, 817 regtempmax[i]); 818 - data->temp_min[i] = vt8231_read_value(client, 819 regtempmin[i]); 820 } 821 } 822 823 - i = vt8231_read_value(client, VT8231_REG_FANDIV); 824 data->fan_div[0] = (i >> 4) & 0x03; 825 data->fan_div[1] = i >> 6; 826 - data->alarms = vt8231_read_value(client, VT8231_REG_ALARM1) | 827 - (vt8231_read_value(client, VT8231_REG_ALARM2) << 8); 828 829 /* Set alarm flags correctly */ 830 if (!data->fan[0] && data->fan_min[0]) { ··· 848 return data; 849 } 850 851 static int __devinit vt8231_pci_probe(struct pci_dev *dev, 852 const struct pci_device_id *id) 853 { 854 - u16 val; 855 856 if (PCIBIOS_SUCCESSFUL != pci_read_config_word(dev, VT8231_BASE_REG, 857 &val)) 858 return -ENODEV; 859 860 - isa_address = val & ~(VT8231_EXTENT - 1); 861 - if (isa_address == 0 && force_addr == 0) { 862 dev_err(&dev->dev, "base address not set -\ 863 upgrade BIOS or use force_addr=0xaddr\n"); 864 return -ENODEV; 865 } 866 867 - s_bridge = pci_dev_get(dev); 868 869 - if (i2c_isa_add_driver(&vt8231_driver)) { 870 - pci_dev_put(s_bridge); 871 - s_bridge = NULL; 872 } 873 874 /* Always return failure here. This is to allow other drivers to bind 875 * to this pci device. We don't really want to have control over the 876 * pci device, we only wanted to read as few register values from it. 877 */ 878 return -ENODEV; 879 } 880 ··· 956 { 957 pci_unregister_driver(&vt8231_pci_driver); 958 if (s_bridge != NULL) { 959 - i2c_isa_del_driver(&vt8231_driver); 960 pci_dev_put(s_bridge); 961 s_bridge = NULL; 962 }
··· 29 #include <linux/slab.h> 30 #include <linux/pci.h> 31 #include <linux/jiffies.h> 32 + #include <linux/platform_device.h> 33 #include <linux/hwmon.h> 34 #include <linux/hwmon-sysfs.h> 35 #include <linux/hwmon-vid.h> ··· 42 module_param(force_addr, int, 0); 43 MODULE_PARM_DESC(force_addr, "Initialize the base address of the sensors"); 44 45 + static struct platform_device *pdev; 46 47 #define VT8231_EXTENT 0x80 48 #define VT8231_BASE_REG 0x70 ··· 148 #define FAN_FROM_REG(val, div) ((val) == 0 ? 0 : 1310720 / ((val) * (div))) 149 150 struct vt8231_data { 151 + unsigned short addr; 152 + const char *name; 153 + 154 struct mutex update_lock; 155 struct class_device *class_dev; 156 char valid; /* !=0 if following fields are valid */ ··· 168 }; 169 170 static struct pci_dev *s_bridge; 171 + static int vt8231_probe(struct platform_device *pdev); 172 + static int vt8231_remove(struct platform_device *pdev); 173 static struct vt8231_data *vt8231_update_device(struct device *dev); 174 + static void vt8231_init_device(struct vt8231_data *data); 175 176 + static inline int vt8231_read_value(struct vt8231_data *data, u8 reg) 177 { 178 + return inb_p(data->addr + reg); 179 } 180 181 + static inline void vt8231_write_value(struct vt8231_data *data, u8 reg, 182 u8 value) 183 { 184 + outb_p(value, data->addr + reg); 185 } 186 187 /* following are the sysfs callback functions */ ··· 220 { 221 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); 222 int nr = sensor_attr->index; 223 + struct vt8231_data *data = dev_get_drvdata(dev); 224 unsigned long val = simple_strtoul(buf, NULL, 10); 225 226 mutex_lock(&data->update_lock); 227 data->in_min[nr] = SENSORS_LIMIT(((val * 958) / 10000) + 3, 0, 255); 228 + vt8231_write_value(data, regvoltmin[nr], data->in_min[nr]); 229 mutex_unlock(&data->update_lock); 230 return count; 231 } ··· 236 { 237 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); 238 int nr = sensor_attr->index; 239 + struct vt8231_data *data = dev_get_drvdata(dev); 240 unsigned long val = simple_strtoul(buf, NULL, 10); 241 242 mutex_lock(&data->update_lock); 243 data->in_max[nr] = SENSORS_LIMIT(((val * 958) / 10000) + 3, 0, 255); 244 + vt8231_write_value(data, regvoltmax[nr], data->in_max[nr]); 245 mutex_unlock(&data->update_lock); 246 return count; 247 } ··· 278 static ssize_t set_in5_min(struct device *dev, struct device_attribute *attr, 279 const char *buf, size_t count) 280 { 281 + struct vt8231_data *data = dev_get_drvdata(dev); 282 unsigned long val = simple_strtoul(buf, NULL, 10); 283 284 mutex_lock(&data->update_lock); 285 data->in_min[5] = SENSORS_LIMIT(((val * 958 * 34) / (10000 * 54)) + 3, 286 0, 255); 287 + vt8231_write_value(data, regvoltmin[5], data->in_min[5]); 288 mutex_unlock(&data->update_lock); 289 return count; 290 } ··· 293 static ssize_t set_in5_max(struct device *dev, struct device_attribute *attr, 294 const char *buf, size_t count) 295 { 296 + struct vt8231_data *data = dev_get_drvdata(dev); 297 unsigned long val = simple_strtoul(buf, NULL, 10); 298 299 mutex_lock(&data->update_lock); 300 data->in_max[5] = SENSORS_LIMIT(((val * 958 * 34) / (10000 * 54)) + 3, 301 0, 255); 302 + vt8231_write_value(data, regvoltmax[5], data->in_max[5]); 303 mutex_unlock(&data->update_lock); 304 return count; 305 } ··· 348 static ssize_t set_temp0_max(struct device *dev, struct device_attribute *attr, 349 const char *buf, size_t count) 350 { 351 + struct vt8231_data *data = dev_get_drvdata(dev); 352 int val = simple_strtol(buf, NULL, 10); 353 354 mutex_lock(&data->update_lock); 355 data->temp_max[0] = SENSORS_LIMIT((val + 500) / 1000, 0, 255); 356 + vt8231_write_value(data, regtempmax[0], data->temp_max[0]); 357 mutex_unlock(&data->update_lock); 358 return count; 359 } 360 static ssize_t set_temp0_min(struct device *dev, struct device_attribute *attr, 361 const char *buf, size_t count) 362 { 363 + struct vt8231_data *data = dev_get_drvdata(dev); 364 int val = simple_strtol(buf, NULL, 10); 365 366 mutex_lock(&data->update_lock); 367 data->temp_min[0] = SENSORS_LIMIT((val + 500) / 1000, 0, 255); 368 + vt8231_write_value(data, regtempmin[0], data->temp_min[0]); 369 mutex_unlock(&data->update_lock); 370 return count; 371 } ··· 404 { 405 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); 406 int nr = sensor_attr->index; 407 + struct vt8231_data *data = dev_get_drvdata(dev); 408 int val = simple_strtol(buf, NULL, 10); 409 410 mutex_lock(&data->update_lock); 411 data->temp_max[nr] = SENSORS_LIMIT(TEMP_MAXMIN_TO_REG(val), 0, 255); 412 + vt8231_write_value(data, regtempmax[nr], data->temp_max[nr]); 413 mutex_unlock(&data->update_lock); 414 return count; 415 } ··· 419 { 420 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); 421 int nr = sensor_attr->index; 422 + struct vt8231_data *data = dev_get_drvdata(dev); 423 int val = simple_strtol(buf, NULL, 10); 424 425 mutex_lock(&data->update_lock); 426 data->temp_min[nr] = SENSORS_LIMIT(TEMP_MAXMIN_TO_REG(val), 0, 255); 427 + vt8231_write_value(data, regtempmin[nr], data->temp_min[nr]); 428 mutex_unlock(&data->update_lock); 429 return count; 430 } ··· 486 { 487 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); 488 int nr = sensor_attr->index; 489 + struct vt8231_data *data = dev_get_drvdata(dev); 490 int val = simple_strtoul(buf, NULL, 10); 491 492 mutex_lock(&data->update_lock); 493 data->fan_min[nr] = FAN_TO_REG(val, DIV_FROM_REG(data->fan_div[nr])); 494 + vt8231_write_value(data, VT8231_REG_FAN_MIN(nr), data->fan_min[nr]); 495 mutex_unlock(&data->update_lock); 496 return count; 497 } ··· 500 static ssize_t set_fan_div(struct device *dev, struct device_attribute *attr, 501 const char *buf, size_t count) 502 { 503 + struct vt8231_data *data = dev_get_drvdata(dev); 504 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); 505 unsigned long val = simple_strtoul(buf, NULL, 10); 506 int nr = sensor_attr->index; 507 + int old = vt8231_read_value(data, VT8231_REG_FANDIV); 508 long min = FAN_FROM_REG(data->fan_min[nr], 509 DIV_FROM_REG(data->fan_div[nr])); 510 ··· 516 case 4: data->fan_div[nr] = 2; break; 517 case 8: data->fan_div[nr] = 3; break; 518 default: 519 + dev_err(dev, "fan_div value %ld not supported." 520 "Choose one of 1, 2, 4 or 8!\n", val); 521 mutex_unlock(&data->update_lock); 522 return -EINVAL; ··· 524 525 /* Correct the fan minimum speed */ 526 data->fan_min[nr] = FAN_TO_REG(min, DIV_FROM_REG(data->fan_div[nr])); 527 + vt8231_write_value(data, VT8231_REG_FAN_MIN(nr), data->fan_min[nr]); 528 529 old = (old & 0x0f) | (data->fan_div[1] << 6) | (data->fan_div[0] << 4); 530 + vt8231_write_value(data, VT8231_REG_FANDIV, old); 531 mutex_unlock(&data->update_lock); 532 return count; 533 } ··· 551 struct vt8231_data *data = vt8231_update_device(dev); 552 return sprintf(buf, "%d\n", data->alarms); 553 } 554 static DEVICE_ATTR(alarms, S_IRUGO, show_alarms, NULL); 555 + 556 + static ssize_t show_name(struct device *dev, struct device_attribute 557 + *devattr, char *buf) 558 + { 559 + struct vt8231_data *data = dev_get_drvdata(dev); 560 + return sprintf(buf, "%s\n", data->name); 561 + } 562 + static DEVICE_ATTR(name, S_IRUGO, show_name, NULL); 563 564 static struct attribute *vt8231_attributes_temps[6][4] = { 565 { ··· 648 &sensor_dev_attr_fan1_div.dev_attr.attr, 649 &sensor_dev_attr_fan2_div.dev_attr.attr, 650 &dev_attr_alarms.attr, 651 + &dev_attr_name.attr, 652 NULL 653 }; 654 ··· 655 .attrs = vt8231_attributes, 656 }; 657 658 + static struct platform_driver vt8231_driver = { 659 .driver = { 660 .owner = THIS_MODULE, 661 .name = "vt8231", 662 }, 663 + .probe = vt8231_probe, 664 + .remove = __devexit_p(vt8231_remove), 665 }; 666 667 static struct pci_device_id vt8231_pci_ids[] = { ··· 680 .probe = vt8231_pci_probe, 681 }; 682 683 + int vt8231_probe(struct platform_device *pdev) 684 { 685 + struct resource *res; 686 struct vt8231_data *data; 687 int err = 0, i; 688 689 /* Reserve the ISA region */ 690 + res = platform_get_resource(pdev, IORESOURCE_IO, 0); 691 + if (!request_region(res->start, VT8231_EXTENT, 692 + vt8231_driver.driver.name)) { 693 + dev_err(&pdev->dev, "Region 0x%lx-0x%lx already in use!\n", 694 + (unsigned long)res->start, (unsigned long)res->end); 695 return -ENODEV; 696 } 697 ··· 722 goto exit_release; 723 } 724 725 + platform_set_drvdata(pdev, data); 726 + data->addr = res->start; 727 + data->name = "vt8231"; 728 729 mutex_init(&data->update_lock); 730 + vt8231_init_device(data); 731 732 /* Register sysfs hooks */ 733 + if ((err = sysfs_create_group(&pdev->dev.kobj, &vt8231_group))) 734 + goto exit_free; 735 736 /* Must update device information to find out the config field */ 737 + data->uch_config = vt8231_read_value(data, VT8231_REG_UCH_CONFIG); 738 739 for (i = 0; i < ARRAY_SIZE(vt8231_group_temps); i++) { 740 if (ISTEMP(i, data->uch_config)) { 741 + if ((err = sysfs_create_group(&pdev->dev.kobj, 742 &vt8231_group_temps[i]))) 743 goto exit_remove_files; 744 } ··· 756 757 for (i = 0; i < ARRAY_SIZE(vt8231_group_volts); i++) { 758 if (ISVOLT(i, data->uch_config)) { 759 + if ((err = sysfs_create_group(&pdev->dev.kobj, 760 &vt8231_group_volts[i]))) 761 goto exit_remove_files; 762 } 763 } 764 765 + data->class_dev = hwmon_device_register(&pdev->dev); 766 if (IS_ERR(data->class_dev)) { 767 err = PTR_ERR(data->class_dev); 768 goto exit_remove_files; ··· 771 772 exit_remove_files: 773 for (i = 0; i < ARRAY_SIZE(vt8231_group_volts); i++) 774 + sysfs_remove_group(&pdev->dev.kobj, &vt8231_group_volts[i]); 775 776 for (i = 0; i < ARRAY_SIZE(vt8231_group_temps); i++) 777 + sysfs_remove_group(&pdev->dev.kobj, &vt8231_group_temps[i]); 778 779 + sysfs_remove_group(&pdev->dev.kobj, &vt8231_group); 780 + 781 exit_free: 782 + platform_set_drvdata(pdev, NULL); 783 kfree(data); 784 + 785 exit_release: 786 + release_region(res->start, VT8231_EXTENT); 787 return err; 788 } 789 790 + static int vt8231_remove(struct platform_device *pdev) 791 { 792 + struct vt8231_data *data = platform_get_drvdata(pdev); 793 + int i; 794 795 hwmon_device_unregister(data->class_dev); 796 797 for (i = 0; i < ARRAY_SIZE(vt8231_group_volts); i++) 798 + sysfs_remove_group(&pdev->dev.kobj, &vt8231_group_volts[i]); 799 800 for (i = 0; i < ARRAY_SIZE(vt8231_group_temps); i++) 801 + sysfs_remove_group(&pdev->dev.kobj, &vt8231_group_temps[i]); 802 803 + sysfs_remove_group(&pdev->dev.kobj, &vt8231_group); 804 805 + release_region(data->addr, VT8231_EXTENT); 806 + platform_set_drvdata(pdev, NULL); 807 kfree(data); 808 return 0; 809 } 810 811 + static void vt8231_init_device(struct vt8231_data *data) 812 { 813 + vt8231_write_value(data, VT8231_REG_TEMP1_CONFIG, 0); 814 + vt8231_write_value(data, VT8231_REG_TEMP2_CONFIG, 0); 815 } 816 817 static struct vt8231_data *vt8231_update_device(struct device *dev) 818 { 819 + struct vt8231_data *data = dev_get_drvdata(dev); 820 int i; 821 u16 low; 822 ··· 830 || !data->valid) { 831 for (i = 0; i < 6; i++) { 832 if (ISVOLT(i, data->uch_config)) { 833 + data->in[i] = vt8231_read_value(data, 834 regvolt[i]); 835 + data->in_min[i] = vt8231_read_value(data, 836 regvoltmin[i]); 837 + data->in_max[i] = vt8231_read_value(data, 838 regvoltmax[i]); 839 } 840 } 841 for (i = 0; i < 2; i++) { 842 + data->fan[i] = vt8231_read_value(data, 843 VT8231_REG_FAN(i)); 844 + data->fan_min[i] = vt8231_read_value(data, 845 VT8231_REG_FAN_MIN(i)); 846 } 847 848 + low = vt8231_read_value(data, VT8231_REG_TEMP_LOW01); 849 low = (low >> 6) | ((low & 0x30) >> 2) 850 + | (vt8231_read_value(data, VT8231_REG_TEMP_LOW25) << 4); 851 for (i = 0; i < 6; i++) { 852 if (ISTEMP(i, data->uch_config)) { 853 + data->temp[i] = (vt8231_read_value(data, 854 regtemp[i]) << 2) 855 | ((low >> (2 * i)) & 0x03); 856 + data->temp_max[i] = vt8231_read_value(data, 857 regtempmax[i]); 858 + data->temp_min[i] = vt8231_read_value(data, 859 regtempmin[i]); 860 } 861 } 862 863 + i = vt8231_read_value(data, VT8231_REG_FANDIV); 864 data->fan_div[0] = (i >> 4) & 0x03; 865 data->fan_div[1] = i >> 6; 866 + data->alarms = vt8231_read_value(data, VT8231_REG_ALARM1) | 867 + (vt8231_read_value(data, VT8231_REG_ALARM2) << 8); 868 869 /* Set alarm flags correctly */ 870 if (!data->fan[0] && data->fan_min[0]) { ··· 888 return data; 889 } 890 891 + static int __devinit vt8231_device_add(unsigned short address) 892 + { 893 + struct resource res = { 894 + .start = address, 895 + .end = address + VT8231_EXTENT - 1, 896 + .name = "vt8231", 897 + .flags = IORESOURCE_IO, 898 + }; 899 + int err; 900 + 901 + pdev = platform_device_alloc("vt8231", address); 902 + if (!pdev) { 903 + err = -ENOMEM; 904 + printk(KERN_ERR "vt8231: Device allocation failed\n"); 905 + goto exit; 906 + } 907 + 908 + err = platform_device_add_resources(pdev, &res, 1); 909 + if (err) { 910 + printk(KERN_ERR "vt8231: Device resource addition failed " 911 + "(%d)\n", err); 912 + goto exit_device_put; 913 + } 914 + 915 + err = platform_device_add(pdev); 916 + if (err) { 917 + printk(KERN_ERR "vt8231: Device addition failed (%d)\n", 918 + err); 919 + goto exit_device_put; 920 + } 921 + 922 + return 0; 923 + 924 + exit_device_put: 925 + platform_device_put(pdev); 926 + exit: 927 + return err; 928 + } 929 + 930 static int __devinit vt8231_pci_probe(struct pci_dev *dev, 931 const struct pci_device_id *id) 932 { 933 + u16 address, val; 934 + if (force_addr) { 935 + address = force_addr & 0xff00; 936 + dev_warn(&dev->dev, "Forcing ISA address 0x%x\n", 937 + address); 938 + 939 + if (PCIBIOS_SUCCESSFUL != 940 + pci_write_config_word(dev, VT8231_BASE_REG, address | 1)) 941 + return -ENODEV; 942 + } 943 944 if (PCIBIOS_SUCCESSFUL != pci_read_config_word(dev, VT8231_BASE_REG, 945 &val)) 946 return -ENODEV; 947 948 + address = val & ~(VT8231_EXTENT - 1); 949 + if (address == 0) { 950 dev_err(&dev->dev, "base address not set -\ 951 upgrade BIOS or use force_addr=0xaddr\n"); 952 return -ENODEV; 953 } 954 955 + if (PCIBIOS_SUCCESSFUL != pci_read_config_word(dev, VT8231_ENABLE_REG, 956 + &val)) 957 + return -ENODEV; 958 959 + if (!(val & 0x0001)) { 960 + dev_warn(&dev->dev, "enabling sensors\n"); 961 + if (PCIBIOS_SUCCESSFUL != 962 + pci_write_config_word(dev, VT8231_ENABLE_REG, 963 + val | 0x0001)) 964 + return -ENODEV; 965 } 966 + 967 + if (platform_driver_register(&vt8231_driver)) 968 + goto exit; 969 + 970 + /* Sets global pdev as a side effect */ 971 + if (vt8231_device_add(address)) 972 + goto exit_unregister; 973 974 /* Always return failure here. This is to allow other drivers to bind 975 * to this pci device. We don't really want to have control over the 976 * pci device, we only wanted to read as few register values from it. 977 */ 978 + 979 + /* We do, however, mark ourselves as using the PCI device to stop it 980 + getting unloaded. */ 981 + s_bridge = pci_dev_get(dev); 982 + return -ENODEV; 983 + 984 + exit_unregister: 985 + platform_driver_unregister(&vt8231_driver); 986 + exit: 987 return -ENODEV; 988 } 989 ··· 927 { 928 pci_unregister_driver(&vt8231_pci_driver); 929 if (s_bridge != NULL) { 930 + platform_device_unregister(pdev); 931 + platform_driver_unregister(&vt8231_driver); 932 pci_dev_put(s_bridge); 933 s_bridge = NULL; 934 }
+379 -234
drivers/hwmon/w83627ehf.c
··· 41 #include <linux/module.h> 42 #include <linux/init.h> 43 #include <linux/slab.h> 44 - #include <linux/i2c.h> 45 - #include <linux/i2c-isa.h> 46 #include <linux/hwmon.h> 47 #include <linux/hwmon-sysfs.h> 48 #include <linux/err.h> 49 #include <linux/mutex.h> 50 #include <asm/io.h> 51 #include "lm75.h" 52 53 - /* The actual ISA address is read from Super-I/O configuration space */ 54 - static unsigned short address; 55 56 /* 57 * Super-I/O constants and functions 58 */ 59 60 - /* 61 - * The three following globals are initialized in w83627ehf_find(), before 62 - * the i2c-isa device is created. Otherwise, they could be stored in 63 - * w83627ehf_data. This is ugly, but necessary, and when the driver is next 64 - * updated to become a platform driver, the globals will disappear. 65 - */ 66 - static int REG; /* The register to read/write */ 67 - static int VAL; /* The value to read/write */ 68 - /* The w83627ehf/ehg have 10 voltage inputs, but the w83627dhg has 9. This 69 - * value is also used in w83627ehf_detect() to export a device name in sysfs 70 - * (e.g. w83627ehf or w83627dhg) */ 71 - static int w83627ehf_num_in; 72 - 73 #define W83627EHF_LD_HWM 0x0b 74 75 #define SIO_REG_LDSEL 0x07 /* Logical device select */ 76 #define SIO_REG_DEVID 0x20 /* Device ID (2 bytes) */ 77 #define SIO_REG_ENABLE 0x30 /* Logical device enable */ 78 #define SIO_REG_ADDR 0x60 /* Logical device address (2 bytes) */ 79 80 #define SIO_W83627EHF_ID 0x8850 81 #define SIO_W83627EHG_ID 0x8860 ··· 81 #define SIO_ID_MASK 0xFFF0 82 83 static inline void 84 - superio_outb(int reg, int val) 85 { 86 - outb(reg, REG); 87 - outb(val, VAL); 88 } 89 90 static inline int 91 - superio_inb(int reg) 92 { 93 - outb(reg, REG); 94 - return inb(VAL); 95 } 96 97 static inline void 98 - superio_select(int ld) 99 { 100 - outb(SIO_REG_LDSEL, REG); 101 - outb(ld, VAL); 102 } 103 104 static inline void 105 - superio_enter(void) 106 { 107 - outb(0x87, REG); 108 - outb(0x87, REG); 109 } 110 111 static inline void 112 - superio_exit(void) 113 { 114 - outb(0x02, REG); 115 - outb(0x02, VAL); 116 } 117 118 /* ··· 122 #define IOREGION_ALIGNMENT ~7 123 #define IOREGION_OFFSET 5 124 #define IOREGION_LENGTH 2 125 - #define ADDR_REG_OFFSET 5 126 - #define DATA_REG_OFFSET 6 127 128 #define W83627EHF_REG_BANK 0x4E 129 #define W83627EHF_REG_CONFIG 0x40 ··· 253 */ 254 255 struct w83627ehf_data { 256 - struct i2c_client client; 257 struct class_device *class_dev; 258 struct mutex lock; 259 ··· 264 unsigned long last_updated; /* In jiffies */ 265 266 /* Register values */ 267 u8 in[10]; /* Register value */ 268 u8 in_max[10]; /* Register value */ 269 u8 in_min[10]; /* Register value */ ··· 272 u8 fan_min[5]; 273 u8 fan_div[5]; 274 u8 has_fan; /* some fan inputs can be disabled */ 275 s8 temp1; 276 s8 temp1_max; 277 s8 temp1_max_hyst; ··· 290 291 u8 fan_min_output[4]; /* minimum fan speed */ 292 u8 fan_stop_time[4]; 293 }; 294 295 static inline int is_word_sized(u16 reg) ··· 313 nothing for registers which live in bank 0. For others, they respectively 314 set the bank register to the correct value (before the register is 315 accessed), and back to 0 (afterwards). */ 316 - static inline void w83627ehf_set_bank(struct i2c_client *client, u16 reg) 317 { 318 if (reg & 0xff00) { 319 - outb_p(W83627EHF_REG_BANK, client->addr + ADDR_REG_OFFSET); 320 - outb_p(reg >> 8, client->addr + DATA_REG_OFFSET); 321 } 322 } 323 324 - static inline void w83627ehf_reset_bank(struct i2c_client *client, u16 reg) 325 { 326 if (reg & 0xff00) { 327 - outb_p(W83627EHF_REG_BANK, client->addr + ADDR_REG_OFFSET); 328 - outb_p(0, client->addr + DATA_REG_OFFSET); 329 } 330 } 331 332 - static u16 w83627ehf_read_value(struct i2c_client *client, u16 reg) 333 { 334 - struct w83627ehf_data *data = i2c_get_clientdata(client); 335 int res, word_sized = is_word_sized(reg); 336 337 mutex_lock(&data->lock); 338 339 - w83627ehf_set_bank(client, reg); 340 - outb_p(reg & 0xff, client->addr + ADDR_REG_OFFSET); 341 - res = inb_p(client->addr + DATA_REG_OFFSET); 342 if (word_sized) { 343 outb_p((reg & 0xff) + 1, 344 - client->addr + ADDR_REG_OFFSET); 345 - res = (res << 8) + inb_p(client->addr + DATA_REG_OFFSET); 346 } 347 - w83627ehf_reset_bank(client, reg); 348 349 mutex_unlock(&data->lock); 350 351 return res; 352 } 353 354 - static int w83627ehf_write_value(struct i2c_client *client, u16 reg, u16 value) 355 { 356 - struct w83627ehf_data *data = i2c_get_clientdata(client); 357 int word_sized = is_word_sized(reg); 358 359 mutex_lock(&data->lock); 360 361 - w83627ehf_set_bank(client, reg); 362 - outb_p(reg & 0xff, client->addr + ADDR_REG_OFFSET); 363 if (word_sized) { 364 - outb_p(value >> 8, client->addr + DATA_REG_OFFSET); 365 outb_p((reg & 0xff) + 1, 366 - client->addr + ADDR_REG_OFFSET); 367 } 368 - outb_p(value & 0xff, client->addr + DATA_REG_OFFSET); 369 - w83627ehf_reset_bank(client, reg); 370 371 mutex_unlock(&data->lock); 372 return 0; 373 } 374 375 /* This function assumes that the caller holds data->update_lock */ 376 - static void w83627ehf_write_fan_div(struct i2c_client *client, int nr) 377 { 378 - struct w83627ehf_data *data = i2c_get_clientdata(client); 379 u8 reg; 380 381 switch (nr) { 382 case 0: 383 - reg = (w83627ehf_read_value(client, W83627EHF_REG_FANDIV1) & 0xcf) 384 | ((data->fan_div[0] & 0x03) << 4); 385 /* fan5 input control bit is write only, compute the value */ 386 reg |= (data->has_fan & (1 << 4)) ? 1 : 0; 387 - w83627ehf_write_value(client, W83627EHF_REG_FANDIV1, reg); 388 - reg = (w83627ehf_read_value(client, W83627EHF_REG_VBAT) & 0xdf) 389 | ((data->fan_div[0] & 0x04) << 3); 390 - w83627ehf_write_value(client, W83627EHF_REG_VBAT, reg); 391 break; 392 case 1: 393 - reg = (w83627ehf_read_value(client, W83627EHF_REG_FANDIV1) & 0x3f) 394 | ((data->fan_div[1] & 0x03) << 6); 395 /* fan5 input control bit is write only, compute the value */ 396 reg |= (data->has_fan & (1 << 4)) ? 1 : 0; 397 - w83627ehf_write_value(client, W83627EHF_REG_FANDIV1, reg); 398 - reg = (w83627ehf_read_value(client, W83627EHF_REG_VBAT) & 0xbf) 399 | ((data->fan_div[1] & 0x04) << 4); 400 - w83627ehf_write_value(client, W83627EHF_REG_VBAT, reg); 401 break; 402 case 2: 403 - reg = (w83627ehf_read_value(client, W83627EHF_REG_FANDIV2) & 0x3f) 404 | ((data->fan_div[2] & 0x03) << 6); 405 - w83627ehf_write_value(client, W83627EHF_REG_FANDIV2, reg); 406 - reg = (w83627ehf_read_value(client, W83627EHF_REG_VBAT) & 0x7f) 407 | ((data->fan_div[2] & 0x04) << 5); 408 - w83627ehf_write_value(client, W83627EHF_REG_VBAT, reg); 409 break; 410 case 3: 411 - reg = (w83627ehf_read_value(client, W83627EHF_REG_DIODE) & 0xfc) 412 | (data->fan_div[3] & 0x03); 413 - w83627ehf_write_value(client, W83627EHF_REG_DIODE, reg); 414 - reg = (w83627ehf_read_value(client, W83627EHF_REG_SMI_OVT) & 0x7f) 415 | ((data->fan_div[3] & 0x04) << 5); 416 - w83627ehf_write_value(client, W83627EHF_REG_SMI_OVT, reg); 417 break; 418 case 4: 419 - reg = (w83627ehf_read_value(client, W83627EHF_REG_DIODE) & 0x73) 420 | ((data->fan_div[4] & 0x03) << 2) 421 | ((data->fan_div[4] & 0x04) << 5); 422 - w83627ehf_write_value(client, W83627EHF_REG_DIODE, reg); 423 break; 424 } 425 } 426 427 static struct w83627ehf_data *w83627ehf_update_device(struct device *dev) 428 { 429 - struct i2c_client *client = to_i2c_client(dev); 430 - struct w83627ehf_data *data = i2c_get_clientdata(client); 431 int pwmcfg = 0, tolerance = 0; /* shut up the compiler */ 432 int i; 433 434 mutex_lock(&data->update_lock); 435 436 - if (time_after(jiffies, data->last_updated + HZ) 437 || !data->valid) { 438 /* Fan clock dividers */ 439 - i = w83627ehf_read_value(client, W83627EHF_REG_FANDIV1); 440 data->fan_div[0] = (i >> 4) & 0x03; 441 data->fan_div[1] = (i >> 6) & 0x03; 442 - i = w83627ehf_read_value(client, W83627EHF_REG_FANDIV2); 443 data->fan_div[2] = (i >> 6) & 0x03; 444 - i = w83627ehf_read_value(client, W83627EHF_REG_VBAT); 445 data->fan_div[0] |= (i >> 3) & 0x04; 446 data->fan_div[1] |= (i >> 4) & 0x04; 447 data->fan_div[2] |= (i >> 5) & 0x04; 448 if (data->has_fan & ((1 << 3) | (1 << 4))) { 449 - i = w83627ehf_read_value(client, W83627EHF_REG_DIODE); 450 data->fan_div[3] = i & 0x03; 451 data->fan_div[4] = ((i >> 2) & 0x03) 452 | ((i >> 5) & 0x04); 453 } 454 if (data->has_fan & (1 << 3)) { 455 - i = w83627ehf_read_value(client, W83627EHF_REG_SMI_OVT); 456 data->fan_div[3] |= (i >> 5) & 0x04; 457 } 458 459 /* Measured voltages and limits */ 460 - for (i = 0; i < w83627ehf_num_in; i++) { 461 - data->in[i] = w83627ehf_read_value(client, 462 W83627EHF_REG_IN(i)); 463 - data->in_min[i] = w83627ehf_read_value(client, 464 W83627EHF_REG_IN_MIN(i)); 465 - data->in_max[i] = w83627ehf_read_value(client, 466 W83627EHF_REG_IN_MAX(i)); 467 } 468 ··· 467 if (!(data->has_fan & (1 << i))) 468 continue; 469 470 - data->fan[i] = w83627ehf_read_value(client, 471 W83627EHF_REG_FAN[i]); 472 - data->fan_min[i] = w83627ehf_read_value(client, 473 W83627EHF_REG_FAN_MIN[i]); 474 475 /* If we failed to measure the fan speed and clock ··· 477 time */ 478 if (data->fan[i] == 0xff 479 && data->fan_div[i] < 0x07) { 480 - dev_dbg(&client->dev, "Increasing fan%d " 481 "clock divider from %u to %u\n", 482 i + 1, div_from_reg(data->fan_div[i]), 483 div_from_reg(data->fan_div[i] + 1)); 484 data->fan_div[i]++; 485 - w83627ehf_write_fan_div(client, i); 486 /* Preserve min limit if possible */ 487 if (data->fan_min[i] >= 2 488 && data->fan_min[i] != 255) 489 - w83627ehf_write_value(client, 490 W83627EHF_REG_FAN_MIN[i], 491 (data->fan_min[i] /= 2)); 492 } ··· 495 for (i = 0; i < 4; i++) { 496 /* pwmcfg, tolarance mapped for i=0, i=1 to same reg */ 497 if (i != 1) { 498 - pwmcfg = w83627ehf_read_value(client, 499 W83627EHF_REG_PWM_ENABLE[i]); 500 - tolerance = w83627ehf_read_value(client, 501 W83627EHF_REG_TOLERANCE[i]); 502 } 503 data->pwm_mode[i] = ··· 506 data->pwm_enable[i] = 507 ((pwmcfg >> W83627EHF_PWM_ENABLE_SHIFT[i]) 508 & 3) + 1; 509 - data->pwm[i] = w83627ehf_read_value(client, 510 W83627EHF_REG_PWM[i]); 511 - data->fan_min_output[i] = w83627ehf_read_value(client, 512 W83627EHF_REG_FAN_MIN_OUTPUT[i]); 513 - data->fan_stop_time[i] = w83627ehf_read_value(client, 514 W83627EHF_REG_FAN_STOP_TIME[i]); 515 data->target_temp[i] = 516 - w83627ehf_read_value(client, 517 W83627EHF_REG_TARGET[i]) & 518 (data->pwm_mode[i] == 1 ? 0x7f : 0xff); 519 data->tolerance[i] = (tolerance >> (i == 1 ? 4 : 0)) ··· 521 } 522 523 /* Measured temperatures and limits */ 524 - data->temp1 = w83627ehf_read_value(client, 525 W83627EHF_REG_TEMP1); 526 - data->temp1_max = w83627ehf_read_value(client, 527 W83627EHF_REG_TEMP1_OVER); 528 - data->temp1_max_hyst = w83627ehf_read_value(client, 529 W83627EHF_REG_TEMP1_HYST); 530 for (i = 0; i < 2; i++) { 531 - data->temp[i] = w83627ehf_read_value(client, 532 W83627EHF_REG_TEMP[i]); 533 - data->temp_max[i] = w83627ehf_read_value(client, 534 W83627EHF_REG_TEMP_OVER[i]); 535 - data->temp_max_hyst[i] = w83627ehf_read_value(client, 536 W83627EHF_REG_TEMP_HYST[i]); 537 } 538 539 - data->alarms = w83627ehf_read_value(client, 540 W83627EHF_REG_ALARM1) | 541 - (w83627ehf_read_value(client, 542 W83627EHF_REG_ALARM2) << 8) | 543 - (w83627ehf_read_value(client, 544 W83627EHF_REG_ALARM3) << 16); 545 546 data->last_updated = jiffies; ··· 573 store_in_##reg (struct device *dev, struct device_attribute *attr, \ 574 const char *buf, size_t count) \ 575 { \ 576 - struct i2c_client *client = to_i2c_client(dev); \ 577 - struct w83627ehf_data *data = i2c_get_clientdata(client); \ 578 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); \ 579 int nr = sensor_attr->index; \ 580 u32 val = simple_strtoul(buf, NULL, 10); \ 581 \ 582 mutex_lock(&data->update_lock); \ 583 data->in_##reg[nr] = in_to_reg(val, nr); \ 584 - w83627ehf_write_value(client, W83627EHF_REG_IN_##REG(nr), \ 585 data->in_##reg[nr]); \ 586 mutex_unlock(&data->update_lock); \ 587 return count; \ ··· 678 store_fan_min(struct device *dev, struct device_attribute *attr, 679 const char *buf, size_t count) 680 { 681 - struct i2c_client *client = to_i2c_client(dev); 682 - struct w83627ehf_data *data = i2c_get_clientdata(client); 683 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); 684 int nr = sensor_attr->index; 685 unsigned int val = simple_strtoul(buf, NULL, 10); ··· 720 /* Write both the fan clock divider (if it changed) and the new 721 fan min (unconditionally) */ 722 if (new_div != data->fan_div[nr]) { 723 - if (new_div > data->fan_div[nr]) 724 - data->fan[nr] >>= (data->fan_div[nr] - new_div); 725 - else 726 - data->fan[nr] <<= (new_div - data->fan_div[nr]); 727 728 dev_dbg(dev, "fan%u clock divider changed from %u to %u\n", 729 nr + 1, div_from_reg(data->fan_div[nr]), 730 div_from_reg(new_div)); 731 data->fan_div[nr] = new_div; 732 - w83627ehf_write_fan_div(client, nr); 733 } 734 - w83627ehf_write_value(client, W83627EHF_REG_FAN_MIN[nr], 735 data->fan_min[nr]); 736 mutex_unlock(&data->update_lock); 737 ··· 799 store_temp1_##reg(struct device *dev, struct device_attribute *attr, \ 800 const char *buf, size_t count) \ 801 { \ 802 - struct i2c_client *client = to_i2c_client(dev); \ 803 - struct w83627ehf_data *data = i2c_get_clientdata(client); \ 804 u32 val = simple_strtoul(buf, NULL, 10); \ 805 \ 806 mutex_lock(&data->update_lock); \ 807 data->temp1_##reg = temp1_to_reg(val, -128000, 127000); \ 808 - w83627ehf_write_value(client, W83627EHF_REG_TEMP1_##REG, \ 809 data->temp1_##reg); \ 810 mutex_unlock(&data->update_lock); \ 811 return count; \ ··· 832 store_##reg(struct device *dev, struct device_attribute *attr, \ 833 const char *buf, size_t count) \ 834 { \ 835 - struct i2c_client *client = to_i2c_client(dev); \ 836 - struct w83627ehf_data *data = i2c_get_clientdata(client); \ 837 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); \ 838 int nr = sensor_attr->index; \ 839 u32 val = simple_strtoul(buf, NULL, 10); \ 840 \ 841 mutex_lock(&data->update_lock); \ 842 data->reg[nr] = LM75_TEMP_TO_REG(val); \ 843 - w83627ehf_write_value(client, W83627EHF_REG_TEMP_##REG[nr], \ 844 data->reg[nr]); \ 845 mutex_unlock(&data->update_lock); \ 846 return count; \ 847 } 848 store_temp_reg(OVER, temp_max); 849 store_temp_reg(HYST, temp_max_hyst); 850 851 static struct sensor_device_attribute sda_temp[] = { 852 SENSOR_ATTR(temp1_input, S_IRUGO, show_temp1, NULL, 0), ··· 875 SENSOR_ATTR(temp1_alarm, S_IRUGO, show_alarm, NULL, 4), 876 SENSOR_ATTR(temp2_alarm, S_IRUGO, show_alarm, NULL, 5), 877 SENSOR_ATTR(temp3_alarm, S_IRUGO, show_alarm, NULL, 13), 878 }; 879 880 #define show_pwm_reg(reg) \ ··· 898 store_pwm_mode(struct device *dev, struct device_attribute *attr, 899 const char *buf, size_t count) 900 { 901 - struct i2c_client *client = to_i2c_client(dev); 902 - struct w83627ehf_data *data = i2c_get_clientdata(client); 903 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); 904 int nr = sensor_attr->index; 905 u32 val = simple_strtoul(buf, NULL, 10); ··· 907 if (val > 1) 908 return -EINVAL; 909 mutex_lock(&data->update_lock); 910 - reg = w83627ehf_read_value(client, W83627EHF_REG_PWM_ENABLE[nr]); 911 data->pwm_mode[nr] = val; 912 reg &= ~(1 << W83627EHF_PWM_MODE_SHIFT[nr]); 913 if (!val) 914 reg |= 1 << W83627EHF_PWM_MODE_SHIFT[nr]; 915 - w83627ehf_write_value(client, W83627EHF_REG_PWM_ENABLE[nr], reg); 916 mutex_unlock(&data->update_lock); 917 return count; 918 } ··· 921 store_pwm(struct device *dev, struct device_attribute *attr, 922 const char *buf, size_t count) 923 { 924 - struct i2c_client *client = to_i2c_client(dev); 925 - struct w83627ehf_data *data = i2c_get_clientdata(client); 926 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); 927 int nr = sensor_attr->index; 928 u32 val = SENSORS_LIMIT(simple_strtoul(buf, NULL, 10), 0, 255); 929 930 mutex_lock(&data->update_lock); 931 data->pwm[nr] = val; 932 - w83627ehf_write_value(client, W83627EHF_REG_PWM[nr], val); 933 mutex_unlock(&data->update_lock); 934 return count; 935 } ··· 937 store_pwm_enable(struct device *dev, struct device_attribute *attr, 938 const char *buf, size_t count) 939 { 940 - struct i2c_client *client = to_i2c_client(dev); 941 - struct w83627ehf_data *data = i2c_get_clientdata(client); 942 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); 943 int nr = sensor_attr->index; 944 u32 val = simple_strtoul(buf, NULL, 10); ··· 946 if (!val || (val > 2)) /* only modes 1 and 2 are supported */ 947 return -EINVAL; 948 mutex_lock(&data->update_lock); 949 - reg = w83627ehf_read_value(client, W83627EHF_REG_PWM_ENABLE[nr]); 950 data->pwm_enable[nr] = val; 951 reg &= ~(0x03 << W83627EHF_PWM_ENABLE_SHIFT[nr]); 952 reg |= (val - 1) << W83627EHF_PWM_ENABLE_SHIFT[nr]; 953 - w83627ehf_write_value(client, W83627EHF_REG_PWM_ENABLE[nr], reg); 954 mutex_unlock(&data->update_lock); 955 return count; 956 } ··· 973 store_target_temp(struct device *dev, struct device_attribute *attr, 974 const char *buf, size_t count) 975 { 976 - struct i2c_client *client = to_i2c_client(dev); 977 - struct w83627ehf_data *data = i2c_get_clientdata(client); 978 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); 979 int nr = sensor_attr->index; 980 u8 val = temp1_to_reg(simple_strtoul(buf, NULL, 10), 0, 127000); 981 982 mutex_lock(&data->update_lock); 983 data->target_temp[nr] = val; 984 - w83627ehf_write_value(client, W83627EHF_REG_TARGET[nr], val); 985 mutex_unlock(&data->update_lock); 986 return count; 987 } ··· 989 store_tolerance(struct device *dev, struct device_attribute *attr, 990 const char *buf, size_t count) 991 { 992 - struct i2c_client *client = to_i2c_client(dev); 993 - struct w83627ehf_data *data = i2c_get_clientdata(client); 994 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); 995 int nr = sensor_attr->index; 996 u16 reg; ··· 997 u8 val = temp1_to_reg(simple_strtoul(buf, NULL, 10), 0, 15000); 998 999 mutex_lock(&data->update_lock); 1000 - reg = w83627ehf_read_value(client, W83627EHF_REG_TOLERANCE[nr]); 1001 data->tolerance[nr] = val; 1002 if (nr == 1) 1003 reg = (reg & 0x0f) | (val << 4); 1004 else 1005 reg = (reg & 0xf0) | val; 1006 - w83627ehf_write_value(client, W83627EHF_REG_TOLERANCE[nr], reg); 1007 mutex_unlock(&data->update_lock); 1008 return count; 1009 } ··· 1074 store_##reg(struct device *dev, struct device_attribute *attr, \ 1075 const char *buf, size_t count) \ 1076 {\ 1077 - struct i2c_client *client = to_i2c_client(dev); \ 1078 - struct w83627ehf_data *data = i2c_get_clientdata(client); \ 1079 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); \ 1080 int nr = sensor_attr->index; \ 1081 u32 val = SENSORS_LIMIT(simple_strtoul(buf, NULL, 10), 1, 255); \ 1082 mutex_lock(&data->update_lock); \ 1083 data->reg[nr] = val; \ 1084 - w83627ehf_write_value(client, W83627EHF_REG_##REG[nr], val); \ 1085 mutex_unlock(&data->update_lock); \ 1086 return count; \ 1087 } ··· 1102 store_##reg(struct device *dev, struct device_attribute *attr, \ 1103 const char *buf, size_t count) \ 1104 { \ 1105 - struct i2c_client *client = to_i2c_client(dev); \ 1106 - struct w83627ehf_data *data = i2c_get_clientdata(client); \ 1107 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); \ 1108 int nr = sensor_attr->index; \ 1109 u8 val = step_time_to_reg(simple_strtoul(buf, NULL, 10), \ 1110 data->pwm_mode[nr]); \ 1111 mutex_lock(&data->update_lock); \ 1112 data->reg[nr] = val; \ 1113 - w83627ehf_write_value(client, W83627EHF_REG_##REG[nr], val); \ 1114 mutex_unlock(&data->update_lock); \ 1115 return count; \ 1116 } \ 1117 1118 fan_time_functions(fan_stop_time, FAN_STOP_TIME) 1119 1120 1121 static struct sensor_device_attribute sda_sf3_arrays_fan4[] = { 1122 SENSOR_ATTR(pwm4_stop_time, S_IWUSR | S_IRUGO, show_fan_stop_time, ··· 1147 store_fan_min_output, 2), 1148 }; 1149 1150 /* 1151 - * Driver and client management 1152 */ 1153 1154 static void w83627ehf_device_remove_files(struct device *dev) ··· 1164 /* some entries in the following arrays may not have been used in 1165 * device_create_file(), but device_remove_file() will ignore them */ 1166 int i; 1167 1168 for (i = 0; i < ARRAY_SIZE(sda_sf3_arrays); i++) 1169 device_remove_file(dev, &sda_sf3_arrays[i].dev_attr); 1170 for (i = 0; i < ARRAY_SIZE(sda_sf3_arrays_fan4); i++) 1171 device_remove_file(dev, &sda_sf3_arrays_fan4[i].dev_attr); 1172 - for (i = 0; i < w83627ehf_num_in; i++) { 1173 device_remove_file(dev, &sda_in_input[i].dev_attr); 1174 device_remove_file(dev, &sda_in_alarm[i].dev_attr); 1175 device_remove_file(dev, &sda_in_min[i].dev_attr); ··· 1191 } 1192 for (i = 0; i < ARRAY_SIZE(sda_temp); i++) 1193 device_remove_file(dev, &sda_temp[i].dev_attr); 1194 } 1195 1196 - static struct i2c_driver w83627ehf_driver; 1197 - 1198 - static void w83627ehf_init_client(struct i2c_client *client) 1199 { 1200 int i; 1201 - u8 tmp; 1202 1203 /* Start monitoring is needed */ 1204 - tmp = w83627ehf_read_value(client, W83627EHF_REG_CONFIG); 1205 if (!(tmp & 0x01)) 1206 - w83627ehf_write_value(client, W83627EHF_REG_CONFIG, 1207 tmp | 0x01); 1208 1209 /* Enable temp2 and temp3 if needed */ 1210 for (i = 0; i < 2; i++) { 1211 - tmp = w83627ehf_read_value(client, 1212 W83627EHF_REG_TEMP_CONFIG[i]); 1213 if (tmp & 0x01) 1214 - w83627ehf_write_value(client, 1215 W83627EHF_REG_TEMP_CONFIG[i], 1216 tmp & 0xfe); 1217 } 1218 } 1219 1220 - static int w83627ehf_detect(struct i2c_adapter *adapter) 1221 { 1222 - struct i2c_client *client; 1223 struct w83627ehf_data *data; 1224 - struct device *dev; 1225 - u8 fan4pin, fan5pin; 1226 int i, err = 0; 1227 1228 - if (!request_region(address + IOREGION_OFFSET, IOREGION_LENGTH, 1229 - w83627ehf_driver.driver.name)) { 1230 err = -EBUSY; 1231 goto exit; 1232 } 1233 ··· 1257 goto exit_release; 1258 } 1259 1260 - client = &data->client; 1261 - i2c_set_clientdata(client, data); 1262 - client->addr = address; 1263 mutex_init(&data->lock); 1264 - client->adapter = adapter; 1265 - client->driver = &w83627ehf_driver; 1266 - client->flags = 0; 1267 - dev = &client->dev; 1268 - 1269 - if (w83627ehf_num_in == 9) 1270 - strlcpy(client->name, "w83627dhg", I2C_NAME_SIZE); 1271 - else /* just say ehf. 627EHG is 627EHF in lead-free packaging. */ 1272 - strlcpy(client->name, "w83627ehf", I2C_NAME_SIZE); 1273 - 1274 - data->valid = 0; 1275 mutex_init(&data->update_lock); 1276 1277 - /* Tell the i2c layer a new client has arrived */ 1278 - if ((err = i2c_attach_client(client))) 1279 - goto exit_free; 1280 1281 /* Initialize the chip */ 1282 - w83627ehf_init_client(client); 1283 1284 - /* A few vars need to be filled upon startup */ 1285 - for (i = 0; i < 5; i++) 1286 - data->fan_min[i] = w83627ehf_read_value(client, 1287 - W83627EHF_REG_FAN_MIN[i]); 1288 1289 /* fan4 and fan5 share some pins with the GPIO and serial flash */ 1290 1291 - superio_enter(); 1292 - fan5pin = superio_inb(0x24) & 0x2; 1293 - fan4pin = superio_inb(0x29) & 0x6; 1294 - superio_exit(); 1295 1296 /* It looks like fan4 and fan5 pins can be alternatively used 1297 as fan on/off switches, but fan5 control is write only :/ ··· 1306 is not the default. */ 1307 1308 data->has_fan = 0x07; /* fan1, fan2 and fan3 */ 1309 - i = w83627ehf_read_value(client, W83627EHF_REG_FANDIV1); 1310 if ((i & (1 << 2)) && (!fan4pin)) 1311 data->has_fan |= (1 << 3); 1312 if (!(i & (1 << 1)) && (!fan5pin)) ··· 1326 goto exit_remove; 1327 } 1328 1329 - for (i = 0; i < w83627ehf_num_in; i++) 1330 if ((err = device_create_file(dev, &sda_in_input[i].dev_attr)) 1331 || (err = device_create_file(dev, 1332 &sda_in_alarm[i].dev_attr)) ··· 1366 if ((err = device_create_file(dev, &sda_temp[i].dev_attr))) 1367 goto exit_remove; 1368 1369 data->class_dev = hwmon_device_register(dev); 1370 if (IS_ERR(data->class_dev)) { 1371 err = PTR_ERR(data->class_dev); ··· 1386 1387 exit_remove: 1388 w83627ehf_device_remove_files(dev); 1389 - i2c_detach_client(client); 1390 - exit_free: 1391 kfree(data); 1392 exit_release: 1393 - release_region(address + IOREGION_OFFSET, IOREGION_LENGTH); 1394 exit: 1395 return err; 1396 } 1397 1398 - static int w83627ehf_detach_client(struct i2c_client *client) 1399 { 1400 - struct w83627ehf_data *data = i2c_get_clientdata(client); 1401 - int err; 1402 1403 hwmon_device_unregister(data->class_dev); 1404 - w83627ehf_device_remove_files(&client->dev); 1405 - 1406 - if ((err = i2c_detach_client(client))) 1407 - return err; 1408 - release_region(client->addr + IOREGION_OFFSET, IOREGION_LENGTH); 1409 kfree(data); 1410 1411 return 0; 1412 } 1413 1414 - static struct i2c_driver w83627ehf_driver = { 1415 .driver = { 1416 .owner = THIS_MODULE, 1417 - .name = "w83627ehf", 1418 }, 1419 - .attach_adapter = w83627ehf_detect, 1420 - .detach_client = w83627ehf_detach_client, 1421 }; 1422 1423 - static int __init w83627ehf_find(int sioaddr, unsigned short *addr) 1424 { 1425 u16 val; 1426 1427 - REG = sioaddr; 1428 - VAL = sioaddr + 1; 1429 - superio_enter(); 1430 1431 - val = (superio_inb(SIO_REG_DEVID) << 8) 1432 - | superio_inb(SIO_REG_DEVID + 1); 1433 switch (val & SIO_ID_MASK) { 1434 - case SIO_W83627DHG_ID: 1435 - w83627ehf_num_in = 9; 1436 - break; 1437 case SIO_W83627EHF_ID: 1438 case SIO_W83627EHG_ID: 1439 - w83627ehf_num_in = 10; 1440 break; 1441 default: 1442 - printk(KERN_WARNING "w83627ehf: unsupported chip ID: 0x%04x\n", 1443 - val); 1444 - superio_exit(); 1445 return -ENODEV; 1446 } 1447 1448 - superio_select(W83627EHF_LD_HWM); 1449 - val = (superio_inb(SIO_REG_ADDR) << 8) 1450 - | superio_inb(SIO_REG_ADDR + 1); 1451 *addr = val & IOREGION_ALIGNMENT; 1452 if (*addr == 0) { 1453 - superio_exit(); 1454 return -ENODEV; 1455 } 1456 1457 /* Activate logical device if needed */ 1458 - val = superio_inb(SIO_REG_ENABLE); 1459 - if (!(val & 0x01)) 1460 - superio_outb(SIO_REG_ENABLE, val | 0x01); 1461 1462 - superio_exit(); 1463 return 0; 1464 } 1465 1466 static int __init sensors_w83627ehf_init(void) 1467 { 1468 - if (w83627ehf_find(0x2e, &address) 1469 - && w83627ehf_find(0x4e, &address)) 1470 return -ENODEV; 1471 1472 - return i2c_isa_add_driver(&w83627ehf_driver); 1473 } 1474 1475 static void __exit sensors_w83627ehf_exit(void) 1476 { 1477 - i2c_isa_del_driver(&w83627ehf_driver); 1478 } 1479 1480 MODULE_AUTHOR("Jean Delvare <khali@linux-fr.org>");
··· 41 #include <linux/module.h> 42 #include <linux/init.h> 43 #include <linux/slab.h> 44 + #include <linux/jiffies.h> 45 + #include <linux/platform_device.h> 46 #include <linux/hwmon.h> 47 #include <linux/hwmon-sysfs.h> 48 + #include <linux/hwmon-vid.h> 49 #include <linux/err.h> 50 #include <linux/mutex.h> 51 #include <asm/io.h> 52 #include "lm75.h" 53 54 + enum kinds { w83627ehf, w83627dhg }; 55 + 56 + /* used to set data->name = w83627ehf_device_names[data->sio_kind] */ 57 + static const char * w83627ehf_device_names[] = { 58 + "w83627ehf", 59 + "w83627dhg", 60 + }; 61 + 62 + #define DRVNAME "w83627ehf" 63 64 /* 65 * Super-I/O constants and functions 66 */ 67 68 #define W83627EHF_LD_HWM 0x0b 69 70 #define SIO_REG_LDSEL 0x07 /* Logical device select */ 71 #define SIO_REG_DEVID 0x20 /* Device ID (2 bytes) */ 72 + #define SIO_REG_EN_VRM10 0x2C /* GPIO3, GPIO4 selection */ 73 #define SIO_REG_ENABLE 0x30 /* Logical device enable */ 74 #define SIO_REG_ADDR 0x60 /* Logical device address (2 bytes) */ 75 + #define SIO_REG_VID_CTRL 0xF0 /* VID control */ 76 + #define SIO_REG_VID_DATA 0xF1 /* VID data */ 77 78 #define SIO_W83627EHF_ID 0x8850 79 #define SIO_W83627EHG_ID 0x8860 ··· 83 #define SIO_ID_MASK 0xFFF0 84 85 static inline void 86 + superio_outb(int ioreg, int reg, int val) 87 { 88 + outb(reg, ioreg); 89 + outb(val, ioreg + 1); 90 } 91 92 static inline int 93 + superio_inb(int ioreg, int reg) 94 { 95 + outb(reg, ioreg); 96 + return inb(ioreg + 1); 97 } 98 99 static inline void 100 + superio_select(int ioreg, int ld) 101 { 102 + outb(SIO_REG_LDSEL, ioreg); 103 + outb(ld, ioreg + 1); 104 } 105 106 static inline void 107 + superio_enter(int ioreg) 108 { 109 + outb(0x87, ioreg); 110 + outb(0x87, ioreg); 111 } 112 113 static inline void 114 + superio_exit(int ioreg) 115 { 116 + outb(0x02, ioreg); 117 + outb(0x02, ioreg + 1); 118 } 119 120 /* ··· 124 #define IOREGION_ALIGNMENT ~7 125 #define IOREGION_OFFSET 5 126 #define IOREGION_LENGTH 2 127 + #define ADDR_REG_OFFSET 0 128 + #define DATA_REG_OFFSET 1 129 130 #define W83627EHF_REG_BANK 0x4E 131 #define W83627EHF_REG_CONFIG 0x40 ··· 255 */ 256 257 struct w83627ehf_data { 258 + int addr; /* IO base of hw monitor block */ 259 + const char *name; 260 + 261 struct class_device *class_dev; 262 struct mutex lock; 263 ··· 264 unsigned long last_updated; /* In jiffies */ 265 266 /* Register values */ 267 + u8 in_num; /* number of in inputs we have */ 268 u8 in[10]; /* Register value */ 269 u8 in_max[10]; /* Register value */ 270 u8 in_min[10]; /* Register value */ ··· 271 u8 fan_min[5]; 272 u8 fan_div[5]; 273 u8 has_fan; /* some fan inputs can be disabled */ 274 + u8 temp_type[3]; 275 s8 temp1; 276 s8 temp1_max; 277 s8 temp1_max_hyst; ··· 288 289 u8 fan_min_output[4]; /* minimum fan speed */ 290 u8 fan_stop_time[4]; 291 + 292 + u8 vid; 293 + u8 vrm; 294 + }; 295 + 296 + struct w83627ehf_sio_data { 297 + int sioreg; 298 + enum kinds kind; 299 }; 300 301 static inline int is_word_sized(u16 reg) ··· 303 nothing for registers which live in bank 0. For others, they respectively 304 set the bank register to the correct value (before the register is 305 accessed), and back to 0 (afterwards). */ 306 + static inline void w83627ehf_set_bank(struct w83627ehf_data *data, u16 reg) 307 { 308 if (reg & 0xff00) { 309 + outb_p(W83627EHF_REG_BANK, data->addr + ADDR_REG_OFFSET); 310 + outb_p(reg >> 8, data->addr + DATA_REG_OFFSET); 311 } 312 } 313 314 + static inline void w83627ehf_reset_bank(struct w83627ehf_data *data, u16 reg) 315 { 316 if (reg & 0xff00) { 317 + outb_p(W83627EHF_REG_BANK, data->addr + ADDR_REG_OFFSET); 318 + outb_p(0, data->addr + DATA_REG_OFFSET); 319 } 320 } 321 322 + static u16 w83627ehf_read_value(struct w83627ehf_data *data, u16 reg) 323 { 324 int res, word_sized = is_word_sized(reg); 325 326 mutex_lock(&data->lock); 327 328 + w83627ehf_set_bank(data, reg); 329 + outb_p(reg & 0xff, data->addr + ADDR_REG_OFFSET); 330 + res = inb_p(data->addr + DATA_REG_OFFSET); 331 if (word_sized) { 332 outb_p((reg & 0xff) + 1, 333 + data->addr + ADDR_REG_OFFSET); 334 + res = (res << 8) + inb_p(data->addr + DATA_REG_OFFSET); 335 } 336 + w83627ehf_reset_bank(data, reg); 337 338 mutex_unlock(&data->lock); 339 340 return res; 341 } 342 343 + static int w83627ehf_write_value(struct w83627ehf_data *data, u16 reg, u16 value) 344 { 345 int word_sized = is_word_sized(reg); 346 347 mutex_lock(&data->lock); 348 349 + w83627ehf_set_bank(data, reg); 350 + outb_p(reg & 0xff, data->addr + ADDR_REG_OFFSET); 351 if (word_sized) { 352 + outb_p(value >> 8, data->addr + DATA_REG_OFFSET); 353 outb_p((reg & 0xff) + 1, 354 + data->addr + ADDR_REG_OFFSET); 355 } 356 + outb_p(value & 0xff, data->addr + DATA_REG_OFFSET); 357 + w83627ehf_reset_bank(data, reg); 358 359 mutex_unlock(&data->lock); 360 return 0; 361 } 362 363 /* This function assumes that the caller holds data->update_lock */ 364 + static void w83627ehf_write_fan_div(struct w83627ehf_data *data, int nr) 365 { 366 u8 reg; 367 368 switch (nr) { 369 case 0: 370 + reg = (w83627ehf_read_value(data, W83627EHF_REG_FANDIV1) & 0xcf) 371 | ((data->fan_div[0] & 0x03) << 4); 372 /* fan5 input control bit is write only, compute the value */ 373 reg |= (data->has_fan & (1 << 4)) ? 1 : 0; 374 + w83627ehf_write_value(data, W83627EHF_REG_FANDIV1, reg); 375 + reg = (w83627ehf_read_value(data, W83627EHF_REG_VBAT) & 0xdf) 376 | ((data->fan_div[0] & 0x04) << 3); 377 + w83627ehf_write_value(data, W83627EHF_REG_VBAT, reg); 378 break; 379 case 1: 380 + reg = (w83627ehf_read_value(data, W83627EHF_REG_FANDIV1) & 0x3f) 381 | ((data->fan_div[1] & 0x03) << 6); 382 /* fan5 input control bit is write only, compute the value */ 383 reg |= (data->has_fan & (1 << 4)) ? 1 : 0; 384 + w83627ehf_write_value(data, W83627EHF_REG_FANDIV1, reg); 385 + reg = (w83627ehf_read_value(data, W83627EHF_REG_VBAT) & 0xbf) 386 | ((data->fan_div[1] & 0x04) << 4); 387 + w83627ehf_write_value(data, W83627EHF_REG_VBAT, reg); 388 break; 389 case 2: 390 + reg = (w83627ehf_read_value(data, W83627EHF_REG_FANDIV2) & 0x3f) 391 | ((data->fan_div[2] & 0x03) << 6); 392 + w83627ehf_write_value(data, W83627EHF_REG_FANDIV2, reg); 393 + reg = (w83627ehf_read_value(data, W83627EHF_REG_VBAT) & 0x7f) 394 | ((data->fan_div[2] & 0x04) << 5); 395 + w83627ehf_write_value(data, W83627EHF_REG_VBAT, reg); 396 break; 397 case 3: 398 + reg = (w83627ehf_read_value(data, W83627EHF_REG_DIODE) & 0xfc) 399 | (data->fan_div[3] & 0x03); 400 + w83627ehf_write_value(data, W83627EHF_REG_DIODE, reg); 401 + reg = (w83627ehf_read_value(data, W83627EHF_REG_SMI_OVT) & 0x7f) 402 | ((data->fan_div[3] & 0x04) << 5); 403 + w83627ehf_write_value(data, W83627EHF_REG_SMI_OVT, reg); 404 break; 405 case 4: 406 + reg = (w83627ehf_read_value(data, W83627EHF_REG_DIODE) & 0x73) 407 | ((data->fan_div[4] & 0x03) << 2) 408 | ((data->fan_div[4] & 0x04) << 5); 409 + w83627ehf_write_value(data, W83627EHF_REG_DIODE, reg); 410 break; 411 } 412 } 413 414 static struct w83627ehf_data *w83627ehf_update_device(struct device *dev) 415 { 416 + struct w83627ehf_data *data = dev_get_drvdata(dev); 417 int pwmcfg = 0, tolerance = 0; /* shut up the compiler */ 418 int i; 419 420 mutex_lock(&data->update_lock); 421 422 + if (time_after(jiffies, data->last_updated + HZ + HZ/2) 423 || !data->valid) { 424 /* Fan clock dividers */ 425 + i = w83627ehf_read_value(data, W83627EHF_REG_FANDIV1); 426 data->fan_div[0] = (i >> 4) & 0x03; 427 data->fan_div[1] = (i >> 6) & 0x03; 428 + i = w83627ehf_read_value(data, W83627EHF_REG_FANDIV2); 429 data->fan_div[2] = (i >> 6) & 0x03; 430 + i = w83627ehf_read_value(data, W83627EHF_REG_VBAT); 431 data->fan_div[0] |= (i >> 3) & 0x04; 432 data->fan_div[1] |= (i >> 4) & 0x04; 433 data->fan_div[2] |= (i >> 5) & 0x04; 434 if (data->has_fan & ((1 << 3) | (1 << 4))) { 435 + i = w83627ehf_read_value(data, W83627EHF_REG_DIODE); 436 data->fan_div[3] = i & 0x03; 437 data->fan_div[4] = ((i >> 2) & 0x03) 438 | ((i >> 5) & 0x04); 439 } 440 if (data->has_fan & (1 << 3)) { 441 + i = w83627ehf_read_value(data, W83627EHF_REG_SMI_OVT); 442 data->fan_div[3] |= (i >> 5) & 0x04; 443 } 444 445 /* Measured voltages and limits */ 446 + for (i = 0; i < data->in_num; i++) { 447 + data->in[i] = w83627ehf_read_value(data, 448 W83627EHF_REG_IN(i)); 449 + data->in_min[i] = w83627ehf_read_value(data, 450 W83627EHF_REG_IN_MIN(i)); 451 + data->in_max[i] = w83627ehf_read_value(data, 452 W83627EHF_REG_IN_MAX(i)); 453 } 454 ··· 461 if (!(data->has_fan & (1 << i))) 462 continue; 463 464 + data->fan[i] = w83627ehf_read_value(data, 465 W83627EHF_REG_FAN[i]); 466 + data->fan_min[i] = w83627ehf_read_value(data, 467 W83627EHF_REG_FAN_MIN[i]); 468 469 /* If we failed to measure the fan speed and clock ··· 471 time */ 472 if (data->fan[i] == 0xff 473 && data->fan_div[i] < 0x07) { 474 + dev_dbg(dev, "Increasing fan%d " 475 "clock divider from %u to %u\n", 476 i + 1, div_from_reg(data->fan_div[i]), 477 div_from_reg(data->fan_div[i] + 1)); 478 data->fan_div[i]++; 479 + w83627ehf_write_fan_div(data, i); 480 /* Preserve min limit if possible */ 481 if (data->fan_min[i] >= 2 482 && data->fan_min[i] != 255) 483 + w83627ehf_write_value(data, 484 W83627EHF_REG_FAN_MIN[i], 485 (data->fan_min[i] /= 2)); 486 } ··· 489 for (i = 0; i < 4; i++) { 490 /* pwmcfg, tolarance mapped for i=0, i=1 to same reg */ 491 if (i != 1) { 492 + pwmcfg = w83627ehf_read_value(data, 493 W83627EHF_REG_PWM_ENABLE[i]); 494 + tolerance = w83627ehf_read_value(data, 495 W83627EHF_REG_TOLERANCE[i]); 496 } 497 data->pwm_mode[i] = ··· 500 data->pwm_enable[i] = 501 ((pwmcfg >> W83627EHF_PWM_ENABLE_SHIFT[i]) 502 & 3) + 1; 503 + data->pwm[i] = w83627ehf_read_value(data, 504 W83627EHF_REG_PWM[i]); 505 + data->fan_min_output[i] = w83627ehf_read_value(data, 506 W83627EHF_REG_FAN_MIN_OUTPUT[i]); 507 + data->fan_stop_time[i] = w83627ehf_read_value(data, 508 W83627EHF_REG_FAN_STOP_TIME[i]); 509 data->target_temp[i] = 510 + w83627ehf_read_value(data, 511 W83627EHF_REG_TARGET[i]) & 512 (data->pwm_mode[i] == 1 ? 0x7f : 0xff); 513 data->tolerance[i] = (tolerance >> (i == 1 ? 4 : 0)) ··· 515 } 516 517 /* Measured temperatures and limits */ 518 + data->temp1 = w83627ehf_read_value(data, 519 W83627EHF_REG_TEMP1); 520 + data->temp1_max = w83627ehf_read_value(data, 521 W83627EHF_REG_TEMP1_OVER); 522 + data->temp1_max_hyst = w83627ehf_read_value(data, 523 W83627EHF_REG_TEMP1_HYST); 524 for (i = 0; i < 2; i++) { 525 + data->temp[i] = w83627ehf_read_value(data, 526 W83627EHF_REG_TEMP[i]); 527 + data->temp_max[i] = w83627ehf_read_value(data, 528 W83627EHF_REG_TEMP_OVER[i]); 529 + data->temp_max_hyst[i] = w83627ehf_read_value(data, 530 W83627EHF_REG_TEMP_HYST[i]); 531 } 532 533 + data->alarms = w83627ehf_read_value(data, 534 W83627EHF_REG_ALARM1) | 535 + (w83627ehf_read_value(data, 536 W83627EHF_REG_ALARM2) << 8) | 537 + (w83627ehf_read_value(data, 538 W83627EHF_REG_ALARM3) << 16); 539 540 data->last_updated = jiffies; ··· 567 store_in_##reg (struct device *dev, struct device_attribute *attr, \ 568 const char *buf, size_t count) \ 569 { \ 570 + struct w83627ehf_data *data = dev_get_drvdata(dev); \ 571 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); \ 572 int nr = sensor_attr->index; \ 573 u32 val = simple_strtoul(buf, NULL, 10); \ 574 \ 575 mutex_lock(&data->update_lock); \ 576 data->in_##reg[nr] = in_to_reg(val, nr); \ 577 + w83627ehf_write_value(data, W83627EHF_REG_IN_##REG(nr), \ 578 data->in_##reg[nr]); \ 579 mutex_unlock(&data->update_lock); \ 580 return count; \ ··· 673 store_fan_min(struct device *dev, struct device_attribute *attr, 674 const char *buf, size_t count) 675 { 676 + struct w83627ehf_data *data = dev_get_drvdata(dev); 677 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); 678 int nr = sensor_attr->index; 679 unsigned int val = simple_strtoul(buf, NULL, 10); ··· 716 /* Write both the fan clock divider (if it changed) and the new 717 fan min (unconditionally) */ 718 if (new_div != data->fan_div[nr]) { 719 + /* Preserve the fan speed reading */ 720 + if (data->fan[nr] != 0xff) { 721 + if (new_div > data->fan_div[nr]) 722 + data->fan[nr] >>= new_div - data->fan_div[nr]; 723 + else if (data->fan[nr] & 0x80) 724 + data->fan[nr] = 0xff; 725 + else 726 + data->fan[nr] <<= data->fan_div[nr] - new_div; 727 + } 728 729 dev_dbg(dev, "fan%u clock divider changed from %u to %u\n", 730 nr + 1, div_from_reg(data->fan_div[nr]), 731 div_from_reg(new_div)); 732 data->fan_div[nr] = new_div; 733 + w83627ehf_write_fan_div(data, nr); 734 + /* Give the chip time to sample a new speed value */ 735 + data->last_updated = jiffies; 736 } 737 + w83627ehf_write_value(data, W83627EHF_REG_FAN_MIN[nr], 738 data->fan_min[nr]); 739 mutex_unlock(&data->update_lock); 740 ··· 788 store_temp1_##reg(struct device *dev, struct device_attribute *attr, \ 789 const char *buf, size_t count) \ 790 { \ 791 + struct w83627ehf_data *data = dev_get_drvdata(dev); \ 792 u32 val = simple_strtoul(buf, NULL, 10); \ 793 \ 794 mutex_lock(&data->update_lock); \ 795 data->temp1_##reg = temp1_to_reg(val, -128000, 127000); \ 796 + w83627ehf_write_value(data, W83627EHF_REG_TEMP1_##REG, \ 797 data->temp1_##reg); \ 798 mutex_unlock(&data->update_lock); \ 799 return count; \ ··· 822 store_##reg(struct device *dev, struct device_attribute *attr, \ 823 const char *buf, size_t count) \ 824 { \ 825 + struct w83627ehf_data *data = dev_get_drvdata(dev); \ 826 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); \ 827 int nr = sensor_attr->index; \ 828 u32 val = simple_strtoul(buf, NULL, 10); \ 829 \ 830 mutex_lock(&data->update_lock); \ 831 data->reg[nr] = LM75_TEMP_TO_REG(val); \ 832 + w83627ehf_write_value(data, W83627EHF_REG_TEMP_##REG[nr], \ 833 data->reg[nr]); \ 834 mutex_unlock(&data->update_lock); \ 835 return count; \ 836 } 837 store_temp_reg(OVER, temp_max); 838 store_temp_reg(HYST, temp_max_hyst); 839 + 840 + static ssize_t 841 + show_temp_type(struct device *dev, struct device_attribute *attr, char *buf) 842 + { 843 + struct w83627ehf_data *data = w83627ehf_update_device(dev); 844 + struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); 845 + int nr = sensor_attr->index; 846 + return sprintf(buf, "%d\n", (int)data->temp_type[nr]); 847 + } 848 849 static struct sensor_device_attribute sda_temp[] = { 850 SENSOR_ATTR(temp1_input, S_IRUGO, show_temp1, NULL, 0), ··· 857 SENSOR_ATTR(temp1_alarm, S_IRUGO, show_alarm, NULL, 4), 858 SENSOR_ATTR(temp2_alarm, S_IRUGO, show_alarm, NULL, 5), 859 SENSOR_ATTR(temp3_alarm, S_IRUGO, show_alarm, NULL, 13), 860 + SENSOR_ATTR(temp1_type, S_IRUGO, show_temp_type, NULL, 0), 861 + SENSOR_ATTR(temp2_type, S_IRUGO, show_temp_type, NULL, 1), 862 + SENSOR_ATTR(temp3_type, S_IRUGO, show_temp_type, NULL, 2), 863 }; 864 865 #define show_pwm_reg(reg) \ ··· 877 store_pwm_mode(struct device *dev, struct device_attribute *attr, 878 const char *buf, size_t count) 879 { 880 + struct w83627ehf_data *data = dev_get_drvdata(dev); 881 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); 882 int nr = sensor_attr->index; 883 u32 val = simple_strtoul(buf, NULL, 10); ··· 887 if (val > 1) 888 return -EINVAL; 889 mutex_lock(&data->update_lock); 890 + reg = w83627ehf_read_value(data, W83627EHF_REG_PWM_ENABLE[nr]); 891 data->pwm_mode[nr] = val; 892 reg &= ~(1 << W83627EHF_PWM_MODE_SHIFT[nr]); 893 if (!val) 894 reg |= 1 << W83627EHF_PWM_MODE_SHIFT[nr]; 895 + w83627ehf_write_value(data, W83627EHF_REG_PWM_ENABLE[nr], reg); 896 mutex_unlock(&data->update_lock); 897 return count; 898 } ··· 901 store_pwm(struct device *dev, struct device_attribute *attr, 902 const char *buf, size_t count) 903 { 904 + struct w83627ehf_data *data = dev_get_drvdata(dev); 905 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); 906 int nr = sensor_attr->index; 907 u32 val = SENSORS_LIMIT(simple_strtoul(buf, NULL, 10), 0, 255); 908 909 mutex_lock(&data->update_lock); 910 data->pwm[nr] = val; 911 + w83627ehf_write_value(data, W83627EHF_REG_PWM[nr], val); 912 mutex_unlock(&data->update_lock); 913 return count; 914 } ··· 918 store_pwm_enable(struct device *dev, struct device_attribute *attr, 919 const char *buf, size_t count) 920 { 921 + struct w83627ehf_data *data = dev_get_drvdata(dev); 922 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); 923 int nr = sensor_attr->index; 924 u32 val = simple_strtoul(buf, NULL, 10); ··· 928 if (!val || (val > 2)) /* only modes 1 and 2 are supported */ 929 return -EINVAL; 930 mutex_lock(&data->update_lock); 931 + reg = w83627ehf_read_value(data, W83627EHF_REG_PWM_ENABLE[nr]); 932 data->pwm_enable[nr] = val; 933 reg &= ~(0x03 << W83627EHF_PWM_ENABLE_SHIFT[nr]); 934 reg |= (val - 1) << W83627EHF_PWM_ENABLE_SHIFT[nr]; 935 + w83627ehf_write_value(data, W83627EHF_REG_PWM_ENABLE[nr], reg); 936 mutex_unlock(&data->update_lock); 937 return count; 938 } ··· 955 store_target_temp(struct device *dev, struct device_attribute *attr, 956 const char *buf, size_t count) 957 { 958 + struct w83627ehf_data *data = dev_get_drvdata(dev); 959 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); 960 int nr = sensor_attr->index; 961 u8 val = temp1_to_reg(simple_strtoul(buf, NULL, 10), 0, 127000); 962 963 mutex_lock(&data->update_lock); 964 data->target_temp[nr] = val; 965 + w83627ehf_write_value(data, W83627EHF_REG_TARGET[nr], val); 966 mutex_unlock(&data->update_lock); 967 return count; 968 } ··· 972 store_tolerance(struct device *dev, struct device_attribute *attr, 973 const char *buf, size_t count) 974 { 975 + struct w83627ehf_data *data = dev_get_drvdata(dev); 976 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); 977 int nr = sensor_attr->index; 978 u16 reg; ··· 981 u8 val = temp1_to_reg(simple_strtoul(buf, NULL, 10), 0, 15000); 982 983 mutex_lock(&data->update_lock); 984 + reg = w83627ehf_read_value(data, W83627EHF_REG_TOLERANCE[nr]); 985 data->tolerance[nr] = val; 986 if (nr == 1) 987 reg = (reg & 0x0f) | (val << 4); 988 else 989 reg = (reg & 0xf0) | val; 990 + w83627ehf_write_value(data, W83627EHF_REG_TOLERANCE[nr], reg); 991 mutex_unlock(&data->update_lock); 992 return count; 993 } ··· 1058 store_##reg(struct device *dev, struct device_attribute *attr, \ 1059 const char *buf, size_t count) \ 1060 {\ 1061 + struct w83627ehf_data *data = dev_get_drvdata(dev); \ 1062 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); \ 1063 int nr = sensor_attr->index; \ 1064 u32 val = SENSORS_LIMIT(simple_strtoul(buf, NULL, 10), 1, 255); \ 1065 mutex_lock(&data->update_lock); \ 1066 data->reg[nr] = val; \ 1067 + w83627ehf_write_value(data, W83627EHF_REG_##REG[nr], val); \ 1068 mutex_unlock(&data->update_lock); \ 1069 return count; \ 1070 } ··· 1087 store_##reg(struct device *dev, struct device_attribute *attr, \ 1088 const char *buf, size_t count) \ 1089 { \ 1090 + struct w83627ehf_data *data = dev_get_drvdata(dev); \ 1091 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); \ 1092 int nr = sensor_attr->index; \ 1093 u8 val = step_time_to_reg(simple_strtoul(buf, NULL, 10), \ 1094 data->pwm_mode[nr]); \ 1095 mutex_lock(&data->update_lock); \ 1096 data->reg[nr] = val; \ 1097 + w83627ehf_write_value(data, W83627EHF_REG_##REG[nr], val); \ 1098 mutex_unlock(&data->update_lock); \ 1099 return count; \ 1100 } \ 1101 1102 fan_time_functions(fan_stop_time, FAN_STOP_TIME) 1103 1104 + static ssize_t show_name(struct device *dev, struct device_attribute *attr, 1105 + char *buf) 1106 + { 1107 + struct w83627ehf_data *data = dev_get_drvdata(dev); 1108 + 1109 + return sprintf(buf, "%s\n", data->name); 1110 + } 1111 + static DEVICE_ATTR(name, S_IRUGO, show_name, NULL); 1112 1113 static struct sensor_device_attribute sda_sf3_arrays_fan4[] = { 1114 SENSOR_ATTR(pwm4_stop_time, S_IWUSR | S_IRUGO, show_fan_stop_time, ··· 1125 store_fan_min_output, 2), 1126 }; 1127 1128 + static ssize_t 1129 + show_vid(struct device *dev, struct device_attribute *attr, char *buf) 1130 + { 1131 + struct w83627ehf_data *data = dev_get_drvdata(dev); 1132 + return sprintf(buf, "%d\n", vid_from_reg(data->vid, data->vrm)); 1133 + } 1134 + static DEVICE_ATTR(cpu0_vid, S_IRUGO, show_vid, NULL); 1135 + 1136 /* 1137 + * Driver and device management 1138 */ 1139 1140 static void w83627ehf_device_remove_files(struct device *dev) ··· 1134 /* some entries in the following arrays may not have been used in 1135 * device_create_file(), but device_remove_file() will ignore them */ 1136 int i; 1137 + struct w83627ehf_data *data = dev_get_drvdata(dev); 1138 1139 for (i = 0; i < ARRAY_SIZE(sda_sf3_arrays); i++) 1140 device_remove_file(dev, &sda_sf3_arrays[i].dev_attr); 1141 for (i = 0; i < ARRAY_SIZE(sda_sf3_arrays_fan4); i++) 1142 device_remove_file(dev, &sda_sf3_arrays_fan4[i].dev_attr); 1143 + for (i = 0; i < data->in_num; i++) { 1144 device_remove_file(dev, &sda_in_input[i].dev_attr); 1145 device_remove_file(dev, &sda_in_alarm[i].dev_attr); 1146 device_remove_file(dev, &sda_in_min[i].dev_attr); ··· 1160 } 1161 for (i = 0; i < ARRAY_SIZE(sda_temp); i++) 1162 device_remove_file(dev, &sda_temp[i].dev_attr); 1163 + 1164 + device_remove_file(dev, &dev_attr_name); 1165 + if (data->vid != 0x3f) 1166 + device_remove_file(dev, &dev_attr_cpu0_vid); 1167 } 1168 1169 + /* Get the monitoring functions started */ 1170 + static inline void __devinit w83627ehf_init_device(struct w83627ehf_data *data) 1171 { 1172 int i; 1173 + u8 tmp, diode; 1174 1175 /* Start monitoring is needed */ 1176 + tmp = w83627ehf_read_value(data, W83627EHF_REG_CONFIG); 1177 if (!(tmp & 0x01)) 1178 + w83627ehf_write_value(data, W83627EHF_REG_CONFIG, 1179 tmp | 0x01); 1180 1181 /* Enable temp2 and temp3 if needed */ 1182 for (i = 0; i < 2; i++) { 1183 + tmp = w83627ehf_read_value(data, 1184 W83627EHF_REG_TEMP_CONFIG[i]); 1185 if (tmp & 0x01) 1186 + w83627ehf_write_value(data, 1187 W83627EHF_REG_TEMP_CONFIG[i], 1188 tmp & 0xfe); 1189 } 1190 + 1191 + /* Enable VBAT monitoring if needed */ 1192 + tmp = w83627ehf_read_value(data, W83627EHF_REG_VBAT); 1193 + if (!(tmp & 0x01)) 1194 + w83627ehf_write_value(data, W83627EHF_REG_VBAT, tmp | 0x01); 1195 + 1196 + /* Get thermal sensor types */ 1197 + diode = w83627ehf_read_value(data, W83627EHF_REG_DIODE); 1198 + for (i = 0; i < 3; i++) { 1199 + if ((tmp & (0x02 << i))) 1200 + data->temp_type[i] = (diode & (0x10 << i)) ? 1 : 2; 1201 + else 1202 + data->temp_type[i] = 4; /* thermistor */ 1203 + } 1204 } 1205 1206 + static int __devinit w83627ehf_probe(struct platform_device *pdev) 1207 { 1208 + struct device *dev = &pdev->dev; 1209 + struct w83627ehf_sio_data *sio_data = dev->platform_data; 1210 struct w83627ehf_data *data; 1211 + struct resource *res; 1212 + u8 fan4pin, fan5pin, en_vrm10; 1213 int i, err = 0; 1214 1215 + res = platform_get_resource(pdev, IORESOURCE_IO, 0); 1216 + if (!request_region(res->start, IOREGION_LENGTH, DRVNAME)) { 1217 err = -EBUSY; 1218 + dev_err(dev, "Failed to request region 0x%lx-0x%lx\n", 1219 + (unsigned long)res->start, 1220 + (unsigned long)res->start + IOREGION_LENGTH - 1); 1221 goto exit; 1222 } 1223 ··· 1205 goto exit_release; 1206 } 1207 1208 + data->addr = res->start; 1209 mutex_init(&data->lock); 1210 mutex_init(&data->update_lock); 1211 + data->name = w83627ehf_device_names[sio_data->kind]; 1212 + platform_set_drvdata(pdev, data); 1213 1214 + /* 627EHG and 627EHF have 10 voltage inputs; DHG has 9 */ 1215 + data->in_num = (sio_data->kind == w83627dhg) ? 9 : 10; 1216 1217 /* Initialize the chip */ 1218 + w83627ehf_init_device(data); 1219 1220 + data->vrm = vid_which_vrm(); 1221 + superio_enter(sio_data->sioreg); 1222 + /* Set VID input sensibility if needed. In theory the BIOS should 1223 + have set it, but in practice it's not always the case. */ 1224 + en_vrm10 = superio_inb(sio_data->sioreg, SIO_REG_EN_VRM10); 1225 + if ((en_vrm10 & 0x08) && data->vrm != 100) { 1226 + dev_warn(dev, "Setting VID input voltage to TTL\n"); 1227 + superio_outb(sio_data->sioreg, SIO_REG_EN_VRM10, 1228 + en_vrm10 & ~0x08); 1229 + } else if (!(en_vrm10 & 0x08) && data->vrm == 100) { 1230 + dev_warn(dev, "Setting VID input voltage to VRM10\n"); 1231 + superio_outb(sio_data->sioreg, SIO_REG_EN_VRM10, 1232 + en_vrm10 | 0x08); 1233 + } 1234 + /* Read VID value */ 1235 + superio_select(sio_data->sioreg, W83627EHF_LD_HWM); 1236 + if (superio_inb(sio_data->sioreg, SIO_REG_VID_CTRL) & 0x80) 1237 + data->vid = superio_inb(sio_data->sioreg, SIO_REG_VID_DATA) & 0x3f; 1238 + else { 1239 + dev_info(dev, "VID pins in output mode, CPU VID not " 1240 + "available\n"); 1241 + data->vid = 0x3f; 1242 + } 1243 1244 /* fan4 and fan5 share some pins with the GPIO and serial flash */ 1245 1246 + fan5pin = superio_inb(sio_data->sioreg, 0x24) & 0x2; 1247 + fan4pin = superio_inb(sio_data->sioreg, 0x29) & 0x6; 1248 + superio_exit(sio_data->sioreg); 1249 1250 /* It looks like fan4 and fan5 pins can be alternatively used 1251 as fan on/off switches, but fan5 control is write only :/ ··· 1248 is not the default. */ 1249 1250 data->has_fan = 0x07; /* fan1, fan2 and fan3 */ 1251 + i = w83627ehf_read_value(data, W83627EHF_REG_FANDIV1); 1252 if ((i & (1 << 2)) && (!fan4pin)) 1253 data->has_fan |= (1 << 3); 1254 if (!(i & (1 << 1)) && (!fan5pin)) ··· 1268 goto exit_remove; 1269 } 1270 1271 + for (i = 0; i < data->in_num; i++) 1272 if ((err = device_create_file(dev, &sda_in_input[i].dev_attr)) 1273 || (err = device_create_file(dev, 1274 &sda_in_alarm[i].dev_attr)) ··· 1308 if ((err = device_create_file(dev, &sda_temp[i].dev_attr))) 1309 goto exit_remove; 1310 1311 + err = device_create_file(dev, &dev_attr_name); 1312 + if (err) 1313 + goto exit_remove; 1314 + 1315 + if (data->vid != 0x3f) { 1316 + err = device_create_file(dev, &dev_attr_cpu0_vid); 1317 + if (err) 1318 + goto exit_remove; 1319 + } 1320 + 1321 data->class_dev = hwmon_device_register(dev); 1322 if (IS_ERR(data->class_dev)) { 1323 err = PTR_ERR(data->class_dev); ··· 1318 1319 exit_remove: 1320 w83627ehf_device_remove_files(dev); 1321 kfree(data); 1322 + platform_set_drvdata(pdev, NULL); 1323 exit_release: 1324 + release_region(res->start, IOREGION_LENGTH); 1325 exit: 1326 return err; 1327 } 1328 1329 + static int __devexit w83627ehf_remove(struct platform_device *pdev) 1330 { 1331 + struct w83627ehf_data *data = platform_get_drvdata(pdev); 1332 1333 hwmon_device_unregister(data->class_dev); 1334 + w83627ehf_device_remove_files(&pdev->dev); 1335 + release_region(data->addr, IOREGION_LENGTH); 1336 + platform_set_drvdata(pdev, NULL); 1337 kfree(data); 1338 1339 return 0; 1340 } 1341 1342 + static struct platform_driver w83627ehf_driver = { 1343 .driver = { 1344 .owner = THIS_MODULE, 1345 + .name = DRVNAME, 1346 }, 1347 + .probe = w83627ehf_probe, 1348 + .remove = __devexit_p(w83627ehf_remove), 1349 }; 1350 1351 + /* w83627ehf_find() looks for a '627 in the Super-I/O config space */ 1352 + static int __init w83627ehf_find(int sioaddr, unsigned short *addr, 1353 + struct w83627ehf_sio_data *sio_data) 1354 { 1355 + static const char __initdata sio_name_W83627EHF[] = "W83627EHF"; 1356 + static const char __initdata sio_name_W83627EHG[] = "W83627EHG"; 1357 + static const char __initdata sio_name_W83627DHG[] = "W83627DHG"; 1358 + 1359 u16 val; 1360 + const char *sio_name; 1361 1362 + superio_enter(sioaddr); 1363 1364 + val = (superio_inb(sioaddr, SIO_REG_DEVID) << 8) 1365 + | superio_inb(sioaddr, SIO_REG_DEVID + 1); 1366 switch (val & SIO_ID_MASK) { 1367 case SIO_W83627EHF_ID: 1368 + sio_data->kind = w83627ehf; 1369 + sio_name = sio_name_W83627EHF; 1370 + break; 1371 case SIO_W83627EHG_ID: 1372 + sio_data->kind = w83627ehf; 1373 + sio_name = sio_name_W83627EHG; 1374 + break; 1375 + case SIO_W83627DHG_ID: 1376 + sio_data->kind = w83627dhg; 1377 + sio_name = sio_name_W83627DHG; 1378 break; 1379 default: 1380 + if (val != 0xffff) 1381 + pr_debug(DRVNAME ": unsupported chip ID: 0x%04x\n", 1382 + val); 1383 + superio_exit(sioaddr); 1384 return -ENODEV; 1385 } 1386 1387 + /* We have a known chip, find the HWM I/O address */ 1388 + superio_select(sioaddr, W83627EHF_LD_HWM); 1389 + val = (superio_inb(sioaddr, SIO_REG_ADDR) << 8) 1390 + | superio_inb(sioaddr, SIO_REG_ADDR + 1); 1391 *addr = val & IOREGION_ALIGNMENT; 1392 if (*addr == 0) { 1393 + printk(KERN_ERR DRVNAME ": Refusing to enable a Super-I/O " 1394 + "device with a base I/O port 0.\n"); 1395 + superio_exit(sioaddr); 1396 return -ENODEV; 1397 } 1398 1399 /* Activate logical device if needed */ 1400 + val = superio_inb(sioaddr, SIO_REG_ENABLE); 1401 + if (!(val & 0x01)) { 1402 + printk(KERN_WARNING DRVNAME ": Forcibly enabling Super-I/O. " 1403 + "Sensor is probably unusable.\n"); 1404 + superio_outb(sioaddr, SIO_REG_ENABLE, val | 0x01); 1405 + } 1406 1407 + superio_exit(sioaddr); 1408 + pr_info(DRVNAME ": Found %s chip at %#x\n", sio_name, *addr); 1409 + sio_data->sioreg = sioaddr; 1410 + 1411 return 0; 1412 } 1413 1414 + /* when Super-I/O functions move to a separate file, the Super-I/O 1415 + * bus will manage the lifetime of the device and this module will only keep 1416 + * track of the w83627ehf driver. But since we platform_device_alloc(), we 1417 + * must keep track of the device */ 1418 + static struct platform_device *pdev; 1419 + 1420 static int __init sensors_w83627ehf_init(void) 1421 { 1422 + int err; 1423 + unsigned short address; 1424 + struct resource res; 1425 + struct w83627ehf_sio_data sio_data; 1426 + 1427 + /* initialize sio_data->kind and sio_data->sioreg. 1428 + * 1429 + * when Super-I/O functions move to a separate file, the Super-I/O 1430 + * driver will probe 0x2e and 0x4e and auto-detect the presence of a 1431 + * w83627ehf hardware monitor, and call probe() */ 1432 + if (w83627ehf_find(0x2e, &address, &sio_data) && 1433 + w83627ehf_find(0x4e, &address, &sio_data)) 1434 return -ENODEV; 1435 1436 + err = platform_driver_register(&w83627ehf_driver); 1437 + if (err) 1438 + goto exit; 1439 + 1440 + if (!(pdev = platform_device_alloc(DRVNAME, address))) { 1441 + err = -ENOMEM; 1442 + printk(KERN_ERR DRVNAME ": Device allocation failed\n"); 1443 + goto exit_unregister; 1444 + } 1445 + 1446 + err = platform_device_add_data(pdev, &sio_data, 1447 + sizeof(struct w83627ehf_sio_data)); 1448 + if (err) { 1449 + printk(KERN_ERR DRVNAME ": Platform data allocation failed\n"); 1450 + goto exit_device_put; 1451 + } 1452 + 1453 + memset(&res, 0, sizeof(res)); 1454 + res.name = DRVNAME; 1455 + res.start = address + IOREGION_OFFSET; 1456 + res.end = address + IOREGION_OFFSET + IOREGION_LENGTH - 1; 1457 + res.flags = IORESOURCE_IO; 1458 + err = platform_device_add_resources(pdev, &res, 1); 1459 + if (err) { 1460 + printk(KERN_ERR DRVNAME ": Device resource addition failed " 1461 + "(%d)\n", err); 1462 + goto exit_device_put; 1463 + } 1464 + 1465 + /* platform_device_add calls probe() */ 1466 + err = platform_device_add(pdev); 1467 + if (err) { 1468 + printk(KERN_ERR DRVNAME ": Device addition failed (%d)\n", 1469 + err); 1470 + goto exit_device_put; 1471 + } 1472 + 1473 + return 0; 1474 + 1475 + exit_device_put: 1476 + platform_device_put(pdev); 1477 + exit_unregister: 1478 + platform_driver_unregister(&w83627ehf_driver); 1479 + exit: 1480 + return err; 1481 } 1482 1483 static void __exit sensors_w83627ehf_exit(void) 1484 { 1485 + platform_device_unregister(pdev); 1486 + platform_driver_unregister(&w83627ehf_driver); 1487 } 1488 1489 MODULE_AUTHOR("Jean Delvare <khali@linux-fr.org>");
+145 -8
drivers/hwmon/w83627hf.c
··· 220 #define W836X7HF_REG_PWM(type, nr) (((type) == w83627hf) ? \ 221 regpwm_627hf[(nr) - 1] : regpwm[(nr) - 1]) 222 223 #define W83781D_REG_I2C_ADDR 0x48 224 #define W83781D_REG_I2C_SUBADDR 0x4A 225 ··· 278 #define FAN_FROM_REG(val,div) ((val)==0?-1:(val)==255?0:1350000/((val)*(div))) 279 280 #define PWM_TO_REG(val) (SENSORS_LIMIT((val),0,255)) 281 282 #define BEEP_MASK_FROM_REG(val) (val) 283 #define BEEP_MASK_TO_REG(val) ((val) & 0xffffff) ··· 371 u32 beep_mask; /* Register encoding, combined */ 372 u8 beep_enable; /* Boolean */ 373 u8 pwm[3]; /* Register value */ 374 u16 sens[3]; /* 782D/783S only. 375 1 = pentium diode; 2 = 3904 diode; 376 3000-5000 = thermistor beta. ··· 908 sysfs_pwm(3); 909 910 static ssize_t 911 show_sensor_reg(struct device *dev, char *buf, int nr) 912 { 913 struct w83627hf_data *data = w83627hf_update_device(dev); ··· 1191 1192 &dev_attr_pwm3.attr, 1193 1194 NULL 1195 }; 1196 ··· 1256 || (err = device_create_file(dev, &dev_attr_in5_max)) 1257 || (err = device_create_file(dev, &dev_attr_in6_input)) 1258 || (err = device_create_file(dev, &dev_attr_in6_min)) 1259 - || (err = device_create_file(dev, &dev_attr_in6_max))) 1260 goto ERROR4; 1261 1262 if (data->type != w83697hf) ··· 1288 if ((err = device_create_file(dev, &dev_attr_pwm3))) 1289 goto ERROR4; 1290 1291 data->class_dev = hwmon_device_register(dev); 1292 if (IS_ERR(data->class_dev)) { 1293 err = PTR_ERR(data->class_dev); ··· 1306 sysfs_remove_group(&dev->kobj, &w83627hf_group); 1307 sysfs_remove_group(&dev->kobj, &w83627hf_group_opt); 1308 ERROR3: 1309 kfree(data); 1310 ERROR1: 1311 release_region(res->start, WINB_REGION_SIZE); ··· 1319 struct w83627hf_data *data = platform_get_drvdata(pdev); 1320 struct resource *res; 1321 1322 - platform_set_drvdata(pdev, NULL); 1323 hwmon_device_unregister(data->class_dev); 1324 1325 sysfs_remove_group(&pdev->dev.kobj, &w83627hf_group); 1326 sysfs_remove_group(&pdev->dev.kobj, &w83627hf_group_opt); 1327 kfree(data); 1328 1329 res = platform_get_resource(pdev, IORESOURCE_IO, 0); ··· 1598 (data->type == w83627hf || data->type == w83697hf)) 1599 break; 1600 } 1601 1602 data->temp = w83627hf_read_value(data, W83781D_REG_TEMP(1)); 1603 data->temp_max = ··· 1688 goto exit_device_put; 1689 } 1690 1691 - pdev->dev.platform_data = kmalloc(sizeof(struct w83627hf_sio_data), 1692 - GFP_KERNEL); 1693 - if (!pdev->dev.platform_data) { 1694 - err = -ENOMEM; 1695 printk(KERN_ERR DRVNAME ": Platform data allocation failed\n"); 1696 goto exit_device_put; 1697 } 1698 - memcpy(pdev->dev.platform_data, sio_data, 1699 - sizeof(struct w83627hf_sio_data)); 1700 1701 err = platform_device_add(pdev); 1702 if (err) {
··· 220 #define W836X7HF_REG_PWM(type, nr) (((type) == w83627hf) ? \ 221 regpwm_627hf[(nr) - 1] : regpwm[(nr) - 1]) 222 223 + #define W83627HF_REG_PWM_FREQ 0x5C /* Only for the 627HF */ 224 + 225 + #define W83637HF_REG_PWM_FREQ1 0x00 /* 697HF/687THF too */ 226 + #define W83637HF_REG_PWM_FREQ2 0x02 /* 697HF/687THF too */ 227 + #define W83637HF_REG_PWM_FREQ3 0x10 /* 687THF too */ 228 + 229 + static const u8 W83637HF_REG_PWM_FREQ[] = { W83637HF_REG_PWM_FREQ1, 230 + W83637HF_REG_PWM_FREQ2, 231 + W83637HF_REG_PWM_FREQ3 }; 232 + 233 + #define W83627HF_BASE_PWM_FREQ 46870 234 + 235 #define W83781D_REG_I2C_ADDR 0x48 236 #define W83781D_REG_I2C_SUBADDR 0x4A 237 ··· 266 #define FAN_FROM_REG(val,div) ((val)==0?-1:(val)==255?0:1350000/((val)*(div))) 267 268 #define PWM_TO_REG(val) (SENSORS_LIMIT((val),0,255)) 269 + 270 + static inline unsigned long pwm_freq_from_reg_627hf(u8 reg) 271 + { 272 + unsigned long freq; 273 + freq = W83627HF_BASE_PWM_FREQ >> reg; 274 + return freq; 275 + } 276 + static inline u8 pwm_freq_to_reg_627hf(unsigned long val) 277 + { 278 + u8 i; 279 + /* Only 5 dividers (1 2 4 8 16) 280 + Search for the nearest available frequency */ 281 + for (i = 0; i < 4; i++) { 282 + if (val > (((W83627HF_BASE_PWM_FREQ >> i) + 283 + (W83627HF_BASE_PWM_FREQ >> (i+1))) / 2)) 284 + break; 285 + } 286 + return i; 287 + } 288 + 289 + static inline unsigned long pwm_freq_from_reg(u8 reg) 290 + { 291 + /* Clock bit 8 -> 180 kHz or 24 MHz */ 292 + unsigned long clock = (reg & 0x80) ? 180000UL : 24000000UL; 293 + 294 + reg &= 0x7f; 295 + /* This should not happen but anyway... */ 296 + if (reg == 0) 297 + reg++; 298 + return (clock / (reg << 8)); 299 + } 300 + static inline u8 pwm_freq_to_reg(unsigned long val) 301 + { 302 + /* Minimum divider value is 0x01 and maximum is 0x7F */ 303 + if (val >= 93750) /* The highest we can do */ 304 + return 0x01; 305 + if (val >= 720) /* Use 24 MHz clock */ 306 + return (24000000UL / (val << 8)); 307 + if (val < 6) /* The lowest we can do */ 308 + return 0xFF; 309 + else /* Use 180 kHz clock */ 310 + return (0x80 | (180000UL / (val << 8))); 311 + } 312 313 #define BEEP_MASK_FROM_REG(val) (val) 314 #define BEEP_MASK_TO_REG(val) ((val) & 0xffffff) ··· 316 u32 beep_mask; /* Register encoding, combined */ 317 u8 beep_enable; /* Boolean */ 318 u8 pwm[3]; /* Register value */ 319 + u8 pwm_freq[3]; /* Register value */ 320 u16 sens[3]; /* 782D/783S only. 321 1 = pentium diode; 2 = 3904 diode; 322 3000-5000 = thermistor beta. ··· 852 sysfs_pwm(3); 853 854 static ssize_t 855 + show_pwm_freq_reg(struct device *dev, char *buf, int nr) 856 + { 857 + struct w83627hf_data *data = w83627hf_update_device(dev); 858 + if (data->type == w83627hf) 859 + return sprintf(buf, "%ld\n", 860 + pwm_freq_from_reg_627hf(data->pwm_freq[nr - 1])); 861 + else 862 + return sprintf(buf, "%ld\n", 863 + pwm_freq_from_reg(data->pwm_freq[nr - 1])); 864 + } 865 + 866 + static ssize_t 867 + store_pwm_freq_reg(struct device *dev, const char *buf, size_t count, int nr) 868 + { 869 + struct w83627hf_data *data = dev_get_drvdata(dev); 870 + static const u8 mask[]={0xF8, 0x8F}; 871 + u32 val; 872 + 873 + val = simple_strtoul(buf, NULL, 10); 874 + 875 + mutex_lock(&data->update_lock); 876 + 877 + if (data->type == w83627hf) { 878 + data->pwm_freq[nr - 1] = pwm_freq_to_reg_627hf(val); 879 + w83627hf_write_value(data, W83627HF_REG_PWM_FREQ, 880 + (data->pwm_freq[nr - 1] << ((nr - 1)*4)) | 881 + (w83627hf_read_value(data, 882 + W83627HF_REG_PWM_FREQ) & mask[nr - 1])); 883 + } else { 884 + data->pwm_freq[nr - 1] = pwm_freq_to_reg(val); 885 + w83627hf_write_value(data, W83637HF_REG_PWM_FREQ[nr - 1], 886 + data->pwm_freq[nr - 1]); 887 + } 888 + 889 + mutex_unlock(&data->update_lock); 890 + return count; 891 + } 892 + 893 + #define sysfs_pwm_freq(offset) \ 894 + static ssize_t show_regs_pwm_freq_##offset(struct device *dev, \ 895 + struct device_attribute *attr, char *buf) \ 896 + { \ 897 + return show_pwm_freq_reg(dev, buf, offset); \ 898 + } \ 899 + static ssize_t \ 900 + store_regs_pwm_freq_##offset(struct device *dev, \ 901 + struct device_attribute *attr, const char *buf, size_t count) \ 902 + { \ 903 + return store_pwm_freq_reg(dev, buf, count, offset); \ 904 + } \ 905 + static DEVICE_ATTR(pwm##offset##_freq, S_IRUGO | S_IWUSR, \ 906 + show_regs_pwm_freq_##offset, store_regs_pwm_freq_##offset); 907 + 908 + sysfs_pwm_freq(1); 909 + sysfs_pwm_freq(2); 910 + sysfs_pwm_freq(3); 911 + 912 + static ssize_t 913 show_sensor_reg(struct device *dev, char *buf, int nr) 914 { 915 struct w83627hf_data *data = w83627hf_update_device(dev); ··· 1077 1078 &dev_attr_pwm3.attr, 1079 1080 + &dev_attr_pwm1_freq.attr, 1081 + &dev_attr_pwm2_freq.attr, 1082 + &dev_attr_pwm3_freq.attr, 1083 NULL 1084 }; 1085 ··· 1139 || (err = device_create_file(dev, &dev_attr_in5_max)) 1140 || (err = device_create_file(dev, &dev_attr_in6_input)) 1141 || (err = device_create_file(dev, &dev_attr_in6_min)) 1142 + || (err = device_create_file(dev, &dev_attr_in6_max)) 1143 + || (err = device_create_file(dev, &dev_attr_pwm1_freq)) 1144 + || (err = device_create_file(dev, &dev_attr_pwm2_freq))) 1145 goto ERROR4; 1146 1147 if (data->type != w83697hf) ··· 1169 if ((err = device_create_file(dev, &dev_attr_pwm3))) 1170 goto ERROR4; 1171 1172 + if (data->type == w83637hf || data->type == w83687thf) 1173 + if ((err = device_create_file(dev, &dev_attr_pwm1_freq)) 1174 + || (err = device_create_file(dev, &dev_attr_pwm2_freq)) 1175 + || (err = device_create_file(dev, &dev_attr_pwm3_freq))) 1176 + goto ERROR4; 1177 + 1178 data->class_dev = hwmon_device_register(dev); 1179 if (IS_ERR(data->class_dev)) { 1180 err = PTR_ERR(data->class_dev); ··· 1181 sysfs_remove_group(&dev->kobj, &w83627hf_group); 1182 sysfs_remove_group(&dev->kobj, &w83627hf_group_opt); 1183 ERROR3: 1184 + platform_set_drvdata(pdev, NULL); 1185 kfree(data); 1186 ERROR1: 1187 release_region(res->start, WINB_REGION_SIZE); ··· 1193 struct w83627hf_data *data = platform_get_drvdata(pdev); 1194 struct resource *res; 1195 1196 hwmon_device_unregister(data->class_dev); 1197 1198 sysfs_remove_group(&pdev->dev.kobj, &w83627hf_group); 1199 sysfs_remove_group(&pdev->dev.kobj, &w83627hf_group_opt); 1200 + platform_set_drvdata(pdev, NULL); 1201 kfree(data); 1202 1203 res = platform_get_resource(pdev, IORESOURCE_IO, 0); ··· 1472 (data->type == w83627hf || data->type == w83697hf)) 1473 break; 1474 } 1475 + if (data->type == w83627hf) { 1476 + u8 tmp = w83627hf_read_value(data, 1477 + W83627HF_REG_PWM_FREQ); 1478 + data->pwm_freq[0] = tmp & 0x07; 1479 + data->pwm_freq[1] = (tmp >> 4) & 0x07; 1480 + } else if (data->type != w83627thf) { 1481 + for (i = 1; i <= 3; i++) { 1482 + data->pwm_freq[i - 1] = 1483 + w83627hf_read_value(data, 1484 + W83637HF_REG_PWM_FREQ[i - 1]); 1485 + if (i == 2 && (data->type == w83697hf)) 1486 + break; 1487 + } 1488 + } 1489 1490 data->temp = w83627hf_read_value(data, W83781D_REG_TEMP(1)); 1491 data->temp_max = ··· 1548 goto exit_device_put; 1549 } 1550 1551 + err = platform_device_add_data(pdev, sio_data, 1552 + sizeof(struct w83627hf_sio_data)); 1553 + if (err) { 1554 printk(KERN_ERR DRVNAME ": Platform data allocation failed\n"); 1555 goto exit_device_put; 1556 } 1557 1558 err = platform_device_add(pdev); 1559 if (err) {
-3
drivers/i2c/busses/Kconfig
··· 237 This driver can also be built as a module. If so, the module 238 will be called i2c-iop3xx. 239 240 - config I2C_ISA 241 - tristate 242 - 243 config I2C_IXP4XX 244 tristate "IXP4xx GPIO-Based I2C Interface (DEPRECATED)" 245 depends on ARCH_IXP4XX
··· 237 This driver can also be built as a module. If so, the module 238 will be called i2c-iop3xx. 239 240 config I2C_IXP4XX 241 tristate "IXP4xx GPIO-Based I2C Interface (DEPRECATED)" 242 depends on ARCH_IXP4XX
-1
drivers/i2c/busses/Makefile
··· 18 obj-$(CONFIG_I2C_I810) += i2c-i810.o 19 obj-$(CONFIG_I2C_IBM_IIC) += i2c-ibm_iic.o 20 obj-$(CONFIG_I2C_IOP3XX) += i2c-iop3xx.o 21 - obj-$(CONFIG_I2C_ISA) += i2c-isa.o 22 obj-$(CONFIG_I2C_IXP2000) += i2c-ixp2000.o 23 obj-$(CONFIG_I2C_IXP4XX) += i2c-ixp4xx.o 24 obj-$(CONFIG_I2C_POWERMAC) += i2c-powermac.o
··· 18 obj-$(CONFIG_I2C_I810) += i2c-i810.o 19 obj-$(CONFIG_I2C_IBM_IIC) += i2c-ibm_iic.o 20 obj-$(CONFIG_I2C_IOP3XX) += i2c-iop3xx.o 21 obj-$(CONFIG_I2C_IXP2000) += i2c-ixp2000.o 22 obj-$(CONFIG_I2C_IXP4XX) += i2c-ixp4xx.o 23 obj-$(CONFIG_I2C_POWERMAC) += i2c-powermac.o
-192
drivers/i2c/busses/i2c-isa.c
··· 1 - /* 2 - i2c-isa.c - an i2c-core-like thing for ISA hardware monitoring chips 3 - Copyright (C) 2005 Jean Delvare <khali@linux-fr.org> 4 - 5 - Based on the i2c-isa pseudo-adapter from the lm_sensors project 6 - Copyright (c) 1998, 1999 Frodo Looijaard <frodol@dds.nl> 7 - 8 - This program is free software; you can redistribute it and/or modify 9 - it under the terms of the GNU General Public License as published by 10 - the Free Software Foundation; either version 2 of the License, or 11 - (at your option) any later version. 12 - 13 - This program is distributed in the hope that it will be useful, 14 - but WITHOUT ANY WARRANTY; without even the implied warranty of 15 - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 - GNU General Public License for more details. 17 - 18 - You should have received a copy of the GNU General Public License 19 - along with this program; if not, write to the Free Software 20 - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 21 - */ 22 - 23 - /* This implements an i2c-core-like thing for ISA hardware monitoring 24 - chips. Such chips are linked to the i2c subsystem for historical 25 - reasons (because the early ISA hardware monitoring chips such as the 26 - LM78 had both an I2C and an ISA interface). They used to be 27 - registered with the main i2c-core, but as a first step in the 28 - direction of a clean separation between I2C and ISA chip drivers, 29 - we now have this separate core for ISA ones. It is significantly 30 - more simple than the real one, of course, because we don't have to 31 - handle multiple busses: there is only one (fake) ISA adapter. 32 - It is worth noting that we still rely on i2c-core for some things 33 - at the moment - but hopefully this won't last. */ 34 - 35 - #include <linux/init.h> 36 - #include <linux/module.h> 37 - #include <linux/kernel.h> 38 - #include <linux/errno.h> 39 - #include <linux/i2c.h> 40 - #include <linux/i2c-isa.h> 41 - #include <linux/platform_device.h> 42 - #include <linux/completion.h> 43 - 44 - /* Exported by i2c-core for i2c-isa only */ 45 - extern void i2c_adapter_dev_release(struct device *dev); 46 - extern struct class i2c_adapter_class; 47 - 48 - static u32 isa_func(struct i2c_adapter *adapter); 49 - 50 - /* This is the actual algorithm we define */ 51 - static const struct i2c_algorithm isa_algorithm = { 52 - .functionality = isa_func, 53 - }; 54 - 55 - /* There can only be one... */ 56 - static struct i2c_adapter isa_adapter = { 57 - .owner = THIS_MODULE, 58 - .id = I2C_HW_ISA, 59 - .class = I2C_CLASS_HWMON, 60 - .algo = &isa_algorithm, 61 - .name = "ISA main adapter", 62 - }; 63 - 64 - /* We can't do a thing... */ 65 - static u32 isa_func(struct i2c_adapter *adapter) 66 - { 67 - return 0; 68 - } 69 - 70 - 71 - /* We implement an interface which resembles i2c_{add,del}_driver, 72 - but for i2c-isa drivers. We don't have to remember and handle lists 73 - of drivers and adapters so this is much more simple, of course. */ 74 - 75 - int i2c_isa_add_driver(struct i2c_driver *driver) 76 - { 77 - int res; 78 - 79 - /* Add the driver to the list of i2c drivers in the driver core */ 80 - driver->driver.bus = &i2c_bus_type; 81 - res = driver_register(&driver->driver); 82 - if (res) 83 - return res; 84 - dev_dbg(&isa_adapter.dev, "Driver %s registered\n", driver->driver.name); 85 - 86 - /* Now look for clients */ 87 - res = driver->attach_adapter(&isa_adapter); 88 - if (res) { 89 - dev_dbg(&isa_adapter.dev, 90 - "Driver %s failed to attach adapter, unregistering\n", 91 - driver->driver.name); 92 - driver_unregister(&driver->driver); 93 - } 94 - return res; 95 - } 96 - 97 - int i2c_isa_del_driver(struct i2c_driver *driver) 98 - { 99 - struct list_head *item, *_n; 100 - struct i2c_client *client; 101 - int res; 102 - 103 - /* Detach all clients belonging to this one driver */ 104 - list_for_each_safe(item, _n, &isa_adapter.clients) { 105 - client = list_entry(item, struct i2c_client, list); 106 - if (client->driver != driver) 107 - continue; 108 - dev_dbg(&isa_adapter.dev, "Detaching client %s at 0x%x\n", 109 - client->name, client->addr); 110 - if ((res = driver->detach_client(client))) { 111 - dev_err(&isa_adapter.dev, "Failed, driver " 112 - "%s not unregistered!\n", 113 - driver->driver.name); 114 - return res; 115 - } 116 - } 117 - 118 - /* Get the driver off the core list */ 119 - driver_unregister(&driver->driver); 120 - dev_dbg(&isa_adapter.dev, "Driver %s unregistered\n", driver->driver.name); 121 - 122 - return 0; 123 - } 124 - 125 - 126 - static int __init i2c_isa_init(void) 127 - { 128 - int err; 129 - 130 - mutex_init(&isa_adapter.clist_lock); 131 - INIT_LIST_HEAD(&isa_adapter.clients); 132 - 133 - isa_adapter.nr = ANY_I2C_ISA_BUS; 134 - isa_adapter.dev.parent = &platform_bus; 135 - sprintf(isa_adapter.dev.bus_id, "i2c-%d", isa_adapter.nr); 136 - isa_adapter.dev.release = &i2c_adapter_dev_release; 137 - isa_adapter.dev.class = &i2c_adapter_class; 138 - err = device_register(&isa_adapter.dev); 139 - if (err) { 140 - printk(KERN_ERR "i2c-isa: Failed to register device\n"); 141 - goto exit; 142 - } 143 - 144 - dev_dbg(&isa_adapter.dev, "%s registered\n", isa_adapter.name); 145 - 146 - return 0; 147 - 148 - exit: 149 - return err; 150 - } 151 - 152 - static void __exit i2c_isa_exit(void) 153 - { 154 - #ifdef DEBUG 155 - struct list_head *item, *_n; 156 - struct i2c_client *client = NULL; 157 - #endif 158 - 159 - /* There should be no more active client */ 160 - #ifdef DEBUG 161 - dev_dbg(&isa_adapter.dev, "Looking for clients\n"); 162 - list_for_each_safe(item, _n, &isa_adapter.clients) { 163 - client = list_entry(item, struct i2c_client, list); 164 - dev_err(&isa_adapter.dev, "Driver %s still has an active " 165 - "ISA client at 0x%x\n", client->driver->driver.name, 166 - client->addr); 167 - } 168 - if (client != NULL) 169 - return; 170 - #endif 171 - 172 - /* Clean up the sysfs representation */ 173 - dev_dbg(&isa_adapter.dev, "Unregistering from sysfs\n"); 174 - init_completion(&isa_adapter.dev_released); 175 - device_unregister(&isa_adapter.dev); 176 - 177 - /* Wait for sysfs to drop all references */ 178 - dev_dbg(&isa_adapter.dev, "Waiting for sysfs completion\n"); 179 - wait_for_completion(&isa_adapter.dev_released); 180 - 181 - dev_dbg(&isa_adapter.dev, "%s unregistered\n", isa_adapter.name); 182 - } 183 - 184 - EXPORT_SYMBOL(i2c_isa_add_driver); 185 - EXPORT_SYMBOL(i2c_isa_del_driver); 186 - 187 - MODULE_AUTHOR("Jean Delvare <khali@linux-fr.org>"); 188 - MODULE_DESCRIPTION("ISA bus access through i2c"); 189 - MODULE_LICENSE("GPL"); 190 - 191 - module_init(i2c_isa_init); 192 - module_exit(i2c_isa_exit);
···
-2
drivers/i2c/i2c-core.c
··· 288 struct i2c_adapter *adap = to_i2c_adapter(dev); 289 complete(&adap->dev_released); 290 } 291 - EXPORT_SYMBOL_GPL(i2c_adapter_dev_release); /* exported to i2c-isa */ 292 293 static ssize_t 294 show_adapter_name(struct device *dev, struct device_attribute *attr, char *buf) ··· 306 .name = "i2c-adapter", 307 .dev_attrs = i2c_adapter_attrs, 308 }; 309 - EXPORT_SYMBOL_GPL(i2c_adapter_class); /* exported to i2c-isa */ 310 311 static void i2c_scan_static_board_info(struct i2c_adapter *adapter) 312 {
··· 288 struct i2c_adapter *adap = to_i2c_adapter(dev); 289 complete(&adap->dev_released); 290 } 291 292 static ssize_t 293 show_adapter_name(struct device *dev, struct device_attribute *attr, char *buf) ··· 307 .name = "i2c-adapter", 308 .dev_attrs = i2c_adapter_attrs, 309 }; 310 311 static void i2c_scan_static_board_info(struct i2c_adapter *adapter) 312 {
-36
include/linux/i2c-isa.h
··· 1 - /* 2 - * i2c-isa.h - definitions for the i2c-isa pseudo-i2c-adapter interface 3 - * 4 - * Copyright (C) 2005 Jean Delvare <khali@linux-fr.org> 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 as published by 8 - * the Free Software Foundation; either version 2 of the License, or 9 - * (at your option) any later version. 10 - * 11 - * This program is distributed in the hope that it will be useful, 12 - * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 - * GNU General Public License for more details. 15 - * 16 - * You should have received a copy of the GNU General Public License 17 - * along with this program; if not, write to the Free Software 18 - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 19 - */ 20 - 21 - #ifndef _LINUX_I2C_ISA_H 22 - #define _LINUX_I2C_ISA_H 23 - 24 - #include <linux/i2c.h> 25 - 26 - extern int i2c_isa_add_driver(struct i2c_driver *driver); 27 - extern int i2c_isa_del_driver(struct i2c_driver *driver); 28 - 29 - /* Detect whether we are on the isa bus. This is only useful to hybrid 30 - (i2c+isa) drivers. */ 31 - #define i2c_is_isa_adapter(adapptr) \ 32 - ((adapptr)->id == I2C_HW_ISA) 33 - #define i2c_is_isa_client(clientptr) \ 34 - i2c_is_isa_adapter((clientptr)->adapter) 35 - 36 - #endif /* _LINUX_I2C_ISA_H */
···
-1
include/linux/i2c.h
··· 368 369 /* The numbers to use to set I2C bus address */ 370 #define ANY_I2C_BUS 0xffff 371 - #define ANY_I2C_ISA_BUS 9191 372 373 374 /* ----- functions exported by i2c.o */
··· 368 369 /* The numbers to use to set I2C bus address */ 370 #define ANY_I2C_BUS 0xffff 371 372 373 /* ----- functions exported by i2c.o */