diff options
| author | Linus Torvalds <torvalds@linux-foundation.org> | 2010-10-28 15:17:00 -0400 |
|---|---|---|
| committer | Linus Torvalds <torvalds@linux-foundation.org> | 2010-10-28 15:17:00 -0400 |
| commit | 150cd843fac0160fce616fb3e5cbe64e9db7481e (patch) | |
| tree | eca7ed23a2238665462ff92fe6e9b591da3e092a | |
| parent | f063a0c0c995d010960efcc1b2ed14b99674f25c (diff) | |
| parent | 44c1bcd4bcde32b2a31a6775a277706ab489c0dc (diff) | |
Merge branch 'hwmon-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/jdelvare/staging
* 'hwmon-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/jdelvare/staging: (68 commits)
hwmon: (it87) Add support for the IT8721F/IT8758E
hwmon: (it87) Move conversion functions
hwmon: Remove many EXPERIMENTAL flags
hwmon: (lm85) Add support for ADT7468 high-frequency PWM mode
hwmon: (lm85) Document the ADT7468 as supported
hwmon: (lm85) Fix ADT7468 frequency table
hwmon: I2C addresses are constant
Move ams driver to macintosh
hwmon: (pcf8591) Don't attempt to detect devices
hwmon: (pcf8591) Register as a hwmon device
hwmon: (w83795) Use standard attributes for chassis intrusion
hwmon: (w83795) Exclude fan control feature by default
hwmon: (w83795) Add myself as co-author and maintainer
hwmon: (w83795) More style cleanups
hwmon: (w83795) Fix LSB reading of voltage limits
hwmon: (w83795) Use dev_get_drvdata() where possible
hwmon: (w83795) Delay reading pwm config registers
hwmon: (w83795) Delay reading limit registers
hwmon: (w83795) Move register reads to dedicated functions
hwmon: (w83795) Pack similar register reads
...
27 files changed, 3284 insertions, 556 deletions
diff --git a/Documentation/hwmon/it87 b/Documentation/hwmon/it87 index 8d08bf0d38ed..38425f0f2645 100644 --- a/Documentation/hwmon/it87 +++ b/Documentation/hwmon/it87 | |||
| @@ -22,6 +22,10 @@ Supported chips: | |||
| 22 | Prefix: 'it8720' | 22 | Prefix: 'it8720' |
| 23 | Addresses scanned: from Super I/O config space (8 I/O ports) | 23 | Addresses scanned: from Super I/O config space (8 I/O ports) |
| 24 | Datasheet: Not publicly available | 24 | Datasheet: Not publicly available |
| 25 | * IT8721F/IT8758E | ||
| 26 | Prefix: 'it8721' | ||
| 27 | Addresses scanned: from Super I/O config space (8 I/O ports) | ||
| 28 | Datasheet: Not publicly available | ||
| 25 | * SiS950 [clone of IT8705F] | 29 | * SiS950 [clone of IT8705F] |
| 26 | Prefix: 'it87' | 30 | Prefix: 'it87' |
| 27 | Addresses scanned: from Super I/O config space (8 I/O ports) | 31 | Addresses scanned: from Super I/O config space (8 I/O ports) |
| @@ -67,7 +71,7 @@ Description | |||
| 67 | ----------- | 71 | ----------- |
| 68 | 72 | ||
| 69 | This driver implements support for the IT8705F, IT8712F, IT8716F, | 73 | This driver implements support for the IT8705F, IT8712F, IT8716F, |
| 70 | IT8718F, IT8720F, IT8726F and SiS950 chips. | 74 | IT8718F, IT8720F, IT8721F, IT8726F, IT8758E and SiS950 chips. |
| 71 | 75 | ||
| 72 | These chips are 'Super I/O chips', supporting floppy disks, infrared ports, | 76 | These chips are 'Super I/O chips', supporting floppy disks, infrared ports, |
| 73 | joysticks and other miscellaneous stuff. For hardware monitoring, they | 77 | joysticks and other miscellaneous stuff. For hardware monitoring, they |
| @@ -86,14 +90,15 @@ the driver won't notice and report changes in the VID value. The two | |||
| 86 | upper VID bits share their pins with voltage inputs (in5 and in6) so you | 90 | upper VID bits share their pins with voltage inputs (in5 and in6) so you |
| 87 | can't have both on a given board. | 91 | can't have both on a given board. |
| 88 | 92 | ||
| 89 | The IT8716F, IT8718F, IT8720F and later IT8712F revisions have support for | 93 | The IT8716F, IT8718F, IT8720F, IT8721F/IT8758E and later IT8712F revisions |
| 90 | 2 additional fans. The additional fans are supported by the driver. | 94 | have support for 2 additional fans. The additional fans are supported by the |
| 95 | driver. | ||
| 91 | 96 | ||
| 92 | The IT8716F, IT8718F and IT8720F, and late IT8712F and IT8705F also have | 97 | The IT8716F, IT8718F, IT8720F and IT8721F/IT8758E, and late IT8712F and |
| 93 | optional 16-bit tachometer counters for fans 1 to 3. This is better (no more | 98 | IT8705F also have optional 16-bit tachometer counters for fans 1 to 3. This |
| 94 | fan clock divider mess) but not compatible with the older chips and | 99 | is better (no more fan clock divider mess) but not compatible with the older |
| 95 | revisions. The 16-bit tachometer mode is enabled by the driver when one | 100 | chips and revisions. The 16-bit tachometer mode is enabled by the driver when |
| 96 | of the above chips is detected. | 101 | one of the above chips is detected. |
| 97 | 102 | ||
| 98 | The IT8726F is just bit enhanced IT8716F with additional hardware | 103 | The IT8726F is just bit enhanced IT8716F with additional hardware |
| 99 | for AMD power sequencing. Therefore the chip will appear as IT8716F | 104 | for AMD power sequencing. Therefore the chip will appear as IT8716F |
| @@ -115,7 +120,12 @@ alarm is triggered if the voltage has crossed a programmable minimum or | |||
| 115 | maximum limit. Note that minimum in this case always means 'closest to | 120 | maximum limit. Note that minimum in this case always means 'closest to |
| 116 | zero'; this is important for negative voltage measurements. All voltage | 121 | zero'; this is important for negative voltage measurements. All voltage |
| 117 | inputs can measure voltages between 0 and 4.08 volts, with a resolution of | 122 | inputs can measure voltages between 0 and 4.08 volts, with a resolution of |
| 118 | 0.016 volt. The battery voltage in8 does not have limit registers. | 123 | 0.016 volt (except IT8721F/IT8758E: 0.012 volt.) The battery voltage in8 does |
| 124 | not have limit registers. | ||
| 125 | |||
| 126 | On the IT8721F/IT8758E, some voltage inputs are internal and scaled inside | ||
| 127 | the chip (in7, in8 and optionally in3). The driver handles this transparently | ||
| 128 | so user-space doesn't have to care. | ||
| 119 | 129 | ||
| 120 | The VID lines (IT8712F/IT8716F/IT8718F/IT8720F) encode the core voltage value: | 130 | The VID lines (IT8712F/IT8716F/IT8718F/IT8720F) encode the core voltage value: |
| 121 | the voltage level your processor should work with. This is hardcoded by | 131 | the voltage level your processor should work with. This is hardcoded by |
diff --git a/Documentation/hwmon/lm85 b/Documentation/hwmon/lm85 index b98e0e0d1910..239258a63c81 100644 --- a/Documentation/hwmon/lm85 +++ b/Documentation/hwmon/lm85 | |||
| @@ -14,6 +14,10 @@ Supported chips: | |||
| 14 | Prefix: 'adt7463' | 14 | Prefix: 'adt7463' |
| 15 | Addresses scanned: I2C 0x2c, 0x2d, 0x2e | 15 | Addresses scanned: I2C 0x2c, 0x2d, 0x2e |
| 16 | Datasheet: http://www.onsemi.com/PowerSolutions/product.do?id=ADT7463 | 16 | Datasheet: http://www.onsemi.com/PowerSolutions/product.do?id=ADT7463 |
| 17 | * Analog Devices ADT7468 | ||
| 18 | Prefix: 'adt7468' | ||
| 19 | Addresses scanned: I2C 0x2c, 0x2d, 0x2e | ||
| 20 | Datasheet: http://www.onsemi.com/PowerSolutions/product.do?id=ADT7468 | ||
| 17 | * SMSC EMC6D100, SMSC EMC6D101 | 21 | * SMSC EMC6D100, SMSC EMC6D101 |
| 18 | Prefix: 'emc6d100' | 22 | Prefix: 'emc6d100' |
| 19 | Addresses scanned: I2C 0x2c, 0x2d, 0x2e | 23 | Addresses scanned: I2C 0x2c, 0x2d, 0x2e |
| @@ -34,7 +38,7 @@ Description | |||
| 34 | ----------- | 38 | ----------- |
| 35 | 39 | ||
| 36 | This driver implements support for the National Semiconductor LM85 and | 40 | This driver implements support for the National Semiconductor LM85 and |
| 37 | compatible chips including the Analog Devices ADM1027, ADT7463 and | 41 | compatible chips including the Analog Devices ADM1027, ADT7463, ADT7468 and |
| 38 | SMSC EMC6D10x chips family. | 42 | SMSC EMC6D10x chips family. |
| 39 | 43 | ||
| 40 | The LM85 uses the 2-wire interface compatible with the SMBUS 2.0 | 44 | The LM85 uses the 2-wire interface compatible with the SMBUS 2.0 |
| @@ -87,14 +91,22 @@ To smooth the response of fans to changes in temperature, the LM85 has an | |||
| 87 | optional filter for smoothing temperatures. The ADM1027 has the same | 91 | optional filter for smoothing temperatures. The ADM1027 has the same |
| 88 | config option but uses it to rate limit the changes to fan speed instead. | 92 | config option but uses it to rate limit the changes to fan speed instead. |
| 89 | 93 | ||
| 90 | The ADM1027 and ADT7463 have a 10-bit ADC and can therefore measure | 94 | The ADM1027, ADT7463 and ADT7468 have a 10-bit ADC and can therefore |
| 91 | temperatures with 0.25 degC resolution. They also provide an offset to the | 95 | measure temperatures with 0.25 degC resolution. They also provide an offset |
| 92 | temperature readings that is automatically applied during measurement. | 96 | to the temperature readings that is automatically applied during |
| 93 | This offset can be used to zero out any errors due to traces and placement. | 97 | measurement. This offset can be used to zero out any errors due to traces |
| 94 | The documentation says that the offset is in 0.25 degC steps, but in | 98 | and placement. The documentation says that the offset is in 0.25 degC |
| 95 | initial testing of the ADM1027 it was 1.00 degC steps. Analog Devices has | 99 | steps, but in initial testing of the ADM1027 it was 1.00 degC steps. Analog |
| 96 | confirmed this "bug". The ADT7463 is reported to work as described in the | 100 | Devices has confirmed this "bug". The ADT7463 is reported to work as |
| 97 | documentation. The current lm85 driver does not show the offset register. | 101 | described in the documentation. The current lm85 driver does not show the |
| 102 | offset register. | ||
| 103 | |||
| 104 | The ADT7468 has a high-frequency PWM mode, where all PWM outputs are | ||
| 105 | driven by a 22.5 kHz clock. This is a global mode, not per-PWM output, | ||
| 106 | which means that setting any PWM frequency above 11.3 kHz will switch | ||
| 107 | all 3 PWM outputs to a 22.5 kHz frequency. Conversely, setting any PWM | ||
| 108 | frequency below 11.3 kHz will switch all 3 PWM outputs to a frequency | ||
| 109 | between 10 and 100 Hz, which can then be tuned separately. | ||
| 98 | 110 | ||
| 99 | See the vendor datasheets for more information. There is application note | 111 | See the vendor datasheets for more information. There is application note |
| 100 | from National (AN-1260) with some additional information about the LM85. | 112 | from National (AN-1260) with some additional information about the LM85. |
| @@ -125,17 +137,17 @@ datasheet for a complete description of the differences. Other than | |||
| 125 | identifying the chip, the driver behaves no differently with regard to | 137 | identifying the chip, the driver behaves no differently with regard to |
| 126 | these two chips. The LM85B is recommended for new designs. | 138 | these two chips. The LM85B is recommended for new designs. |
| 127 | 139 | ||
| 128 | The ADM1027 and ADT7463 chips have an optional SMBALERT output that can be | 140 | The ADM1027, ADT7463 and ADT7468 chips have an optional SMBALERT output |
| 129 | used to signal the chipset in case a limit is exceeded or the temperature | 141 | that can be used to signal the chipset in case a limit is exceeded or the |
| 130 | sensors fail. Individual sensor interrupts can be masked so they won't | 142 | temperature sensors fail. Individual sensor interrupts can be masked so |
| 131 | trigger SMBALERT. The SMBALERT output if configured replaces one of the other | 143 | they won't trigger SMBALERT. The SMBALERT output if configured replaces one |
| 132 | functions (PWM2 or IN0). This functionality is not implemented in current | 144 | of the other functions (PWM2 or IN0). This functionality is not implemented |
| 133 | driver. | 145 | in current driver. |
| 134 | 146 | ||
| 135 | The ADT7463 also has an optional THERM output/input which can be connected | 147 | The ADT7463 and ADT7468 also have an optional THERM output/input which can |
| 136 | to the processor PROC_HOT output. If available, the autofan control | 148 | be connected to the processor PROC_HOT output. If available, the autofan |
| 137 | dynamic Tmin feature can be enabled to keep the system temperature within | 149 | control dynamic Tmin feature can be enabled to keep the system temperature |
| 138 | spec (just?!) with the least possible fan noise. | 150 | within spec (just?!) with the least possible fan noise. |
| 139 | 151 | ||
| 140 | Configuration Notes | 152 | Configuration Notes |
| 141 | ------------------- | 153 | ------------------- |
| @@ -201,8 +213,8 @@ the temperatures to compensate for systemic errors in the | |||
| 201 | measurements. These features are not currently supported by the lm85 | 213 | measurements. These features are not currently supported by the lm85 |
| 202 | driver. | 214 | driver. |
| 203 | 215 | ||
| 204 | In addition to the ADM1027 features, the ADT7463 also has Tmin control | 216 | In addition to the ADM1027 features, the ADT7463 and ADT7468 also have |
| 205 | and THERM asserted counts. Automatic Tmin control acts to adjust the | 217 | Tmin control and THERM asserted counts. Automatic Tmin control acts to |
| 206 | Tmin value to maintain the measured temperature sensor at a specified | 218 | adjust the Tmin value to maintain the measured temperature sensor at a |
| 207 | temperature. There isn't much documentation on this feature in the | 219 | specified temperature. There isn't much documentation on this feature in |
| 208 | ADT7463 data sheet. This is not supported by current driver. | 220 | the ADT7463 data sheet. This is not supported by current driver. |
diff --git a/Documentation/hwmon/lm90 b/Documentation/hwmon/lm90 index 6a03dd4bcc94..fa475c0a48a3 100644 --- a/Documentation/hwmon/lm90 +++ b/Documentation/hwmon/lm90 | |||
| @@ -63,8 +63,8 @@ Supported chips: | |||
| 63 | Datasheet: Publicly available at the Maxim website | 63 | Datasheet: Publicly available at the Maxim website |
| 64 | http://www.maxim-ic.com/quick_view2.cfm/qv_pk/2578 | 64 | http://www.maxim-ic.com/quick_view2.cfm/qv_pk/2578 |
| 65 | * Maxim MAX6659 | 65 | * Maxim MAX6659 |
| 66 | Prefix: 'max6657' | 66 | Prefix: 'max6659' |
| 67 | Addresses scanned: I2C 0x4c, 0x4d (unsupported 0x4e) | 67 | Addresses scanned: I2C 0x4c, 0x4d, 0x4e |
| 68 | Datasheet: Publicly available at the Maxim website | 68 | Datasheet: Publicly available at the Maxim website |
| 69 | http://www.maxim-ic.com/quick_view2.cfm/qv_pk/2578 | 69 | http://www.maxim-ic.com/quick_view2.cfm/qv_pk/2578 |
| 70 | * Maxim MAX6680 | 70 | * Maxim MAX6680 |
| @@ -84,6 +84,21 @@ Supported chips: | |||
| 84 | Addresses scanned: I2C 0x4c | 84 | Addresses scanned: I2C 0x4c |
| 85 | Datasheet: Publicly available at the Maxim website | 85 | Datasheet: Publicly available at the Maxim website |
| 86 | http://www.maxim-ic.com/quick_view2.cfm/qv_pk/3500 | 86 | http://www.maxim-ic.com/quick_view2.cfm/qv_pk/3500 |
| 87 | * Maxim MAX6695 | ||
| 88 | Prefix: 'max6695' | ||
| 89 | Addresses scanned: I2C 0x18 | ||
| 90 | Datasheet: Publicly available at the Maxim website | ||
| 91 | http://www.maxim-ic.com/datasheet/index.mvp/id/4199 | ||
| 92 | * Maxim MAX6696 | ||
| 93 | Prefix: 'max6695' | ||
| 94 | Addresses scanned: I2C 0x18, 0x19, 0x1a, 0x29, 0x2a, 0x2b, | ||
| 95 | 0x4c, 0x4d and 0x4e | ||
| 96 | Datasheet: Publicly available at the Maxim website | ||
| 97 | http://www.maxim-ic.com/datasheet/index.mvp/id/4199 | ||
| 98 | * Winbond/Nuvoton W83L771W/G | ||
| 99 | Prefix: 'w83l771' | ||
| 100 | Addresses scanned: I2C 0x4c | ||
| 101 | Datasheet: No longer available | ||
| 87 | * Winbond/Nuvoton W83L771AWG/ASG | 102 | * Winbond/Nuvoton W83L771AWG/ASG |
| 88 | Prefix: 'w83l771' | 103 | Prefix: 'w83l771' |
| 89 | Addresses scanned: I2C 0x4c | 104 | Addresses scanned: I2C 0x4c |
| @@ -101,10 +116,11 @@ well as the temperature of up to one external diode. It is compatible | |||
| 101 | with many other devices, many of which are supported by this driver. | 116 | with many other devices, many of which are supported by this driver. |
| 102 | 117 | ||
| 103 | Note that there is no easy way to differentiate between the MAX6657, | 118 | Note that there is no easy way to differentiate between the MAX6657, |
| 104 | MAX6658 and MAX6659 variants. The extra address and features of the | 119 | MAX6658 and MAX6659 variants. The extra features of the MAX6659 are only |
| 105 | MAX6659 are not supported by this driver. The MAX6680 and MAX6681 only | 120 | supported by this driver if the chip is located at address 0x4d or 0x4e, |
| 106 | differ in their pinout, therefore they obviously can't (and don't need to) | 121 | or if the chip type is explicitly selected as max6659. |
| 107 | be distinguished. | 122 | The MAX6680 and MAX6681 only differ in their pinout, therefore they obviously |
| 123 | can't (and don't need to) be distinguished. | ||
| 108 | 124 | ||
| 109 | The specificity of this family of chipsets over the ADM1021/LM84 | 125 | The specificity of this family of chipsets over the ADM1021/LM84 |
| 110 | family is that it features critical limits with hysteresis, and an | 126 | family is that it features critical limits with hysteresis, and an |
| @@ -151,11 +167,21 @@ MAX6680 and MAX6681: | |||
| 151 | * Selectable address | 167 | * Selectable address |
| 152 | * Remote sensor type selection | 168 | * Remote sensor type selection |
| 153 | 169 | ||
| 170 | MAX6695 and MAX6696: | ||
| 171 | * Better local resolution | ||
| 172 | * Selectable address (max6696) | ||
| 173 | * Second critical temperature limit | ||
| 174 | * Two remote sensors | ||
| 175 | |||
| 176 | W83L771W/G | ||
| 177 | * The G variant is lead-free, otherwise similar to the W. | ||
| 178 | * Filter and alert configuration register at 0xBF | ||
| 179 | * Moving average (depending on conversion rate) | ||
| 180 | |||
| 154 | W83L771AWG/ASG | 181 | W83L771AWG/ASG |
| 182 | * Successor of the W83L771W/G, same features. | ||
| 155 | * The AWG and ASG variants only differ in package format. | 183 | * The AWG and ASG variants only differ in package format. |
| 156 | * Filter and alert configuration register at 0xBF | ||
| 157 | * Diode ideality factor configuration (remote sensor) at 0xE3 | 184 | * Diode ideality factor configuration (remote sensor) at 0xE3 |
| 158 | * Moving average (depending on conversion rate) | ||
| 159 | 185 | ||
| 160 | All temperature values are given in degrees Celsius. Resolution | 186 | All temperature values are given in degrees Celsius. Resolution |
| 161 | is 1.0 degree for the local temperature, 0.125 degree for the remote | 187 | is 1.0 degree for the local temperature, 0.125 degree for the remote |
diff --git a/Documentation/hwmon/pcf8591 b/Documentation/hwmon/pcf8591 index e76a7892f68e..ac020b3bb7b3 100644 --- a/Documentation/hwmon/pcf8591 +++ b/Documentation/hwmon/pcf8591 | |||
| @@ -4,7 +4,7 @@ Kernel driver pcf8591 | |||
| 4 | Supported chips: | 4 | Supported chips: |
| 5 | * Philips/NXP PCF8591 | 5 | * Philips/NXP PCF8591 |
| 6 | Prefix: 'pcf8591' | 6 | Prefix: 'pcf8591' |
| 7 | Addresses scanned: I2C 0x48 - 0x4f | 7 | Addresses scanned: none |
| 8 | Datasheet: Publicly available at the NXP website | 8 | Datasheet: Publicly available at the NXP website |
| 9 | http://www.nxp.com/pip/PCF8591_6.html | 9 | http://www.nxp.com/pip/PCF8591_6.html |
| 10 | 10 | ||
| @@ -58,18 +58,16 @@ Module parameters | |||
| 58 | Accessing PCF8591 via /sys interface | 58 | Accessing PCF8591 via /sys interface |
| 59 | ------------------------------------- | 59 | ------------------------------------- |
| 60 | 60 | ||
| 61 | ! Be careful ! | 61 | The PCF8591 is plainly impossible to detect! Thus the driver won't even |
| 62 | The PCF8591 is plainly impossible to detect! Stupid chip. | 62 | try. You have to explicitly instantiate the device at the relevant |
| 63 | So every chip with address in the interval [0x48..0x4f] is | 63 | address (in the interval [0x48..0x4f]) either through platform data, or |
| 64 | detected as PCF8591. If you have other chips in this address | 64 | using the sysfs interface. See Documentation/i2c/instantiating-devices |
| 65 | range, the workaround is to load this module after the one | 65 | for details. |
| 66 | for your others chips. | ||
| 67 | 66 | ||
| 68 | On detection (i.e. insmod, modprobe et al.), directories are being | 67 | Directories are being created for each instantiated PCF8591: |
| 69 | created for each detected PCF8591: | ||
| 70 | 68 | ||
| 71 | /sys/bus/i2c/devices/<0>-<1>/ | 69 | /sys/bus/i2c/devices/<0>-<1>/ |
| 72 | where <0> is the bus the chip was detected on (e. g. i2c-0) | 70 | where <0> is the bus the chip is connected to (e. g. i2c-0) |
| 73 | and <1> the chip address ([48..4f]) | 71 | and <1> the chip address ([48..4f]) |
| 74 | 72 | ||
| 75 | Inside these directories, there are such files: | 73 | Inside these directories, there are such files: |
diff --git a/Documentation/hwmon/sysfs-interface b/Documentation/hwmon/sysfs-interface index 48ceabedf55d..645699010551 100644 --- a/Documentation/hwmon/sysfs-interface +++ b/Documentation/hwmon/sysfs-interface | |||
| @@ -309,6 +309,20 @@ temp[1-*]_crit_hyst | |||
| 309 | from the critical value. | 309 | from the critical value. |
| 310 | RW | 310 | RW |
| 311 | 311 | ||
| 312 | temp[1-*]_emergency | ||
| 313 | Temperature emergency max value, for chips supporting more than | ||
| 314 | two upper temperature limits. Must be equal or greater than | ||
| 315 | corresponding temp_crit values. | ||
| 316 | Unit: millidegree Celsius | ||
| 317 | RW | ||
| 318 | |||
| 319 | temp[1-*]_emergency_hyst | ||
| 320 | Temperature hysteresis value for emergency limit. | ||
| 321 | Unit: millidegree Celsius | ||
| 322 | Must be reported as an absolute temperature, NOT a delta | ||
| 323 | from the emergency value. | ||
| 324 | RW | ||
| 325 | |||
| 312 | temp[1-*]_lcrit Temperature critical min value, typically lower than | 326 | temp[1-*]_lcrit Temperature critical min value, typically lower than |
| 313 | corresponding temp_min values. | 327 | corresponding temp_min values. |
| 314 | Unit: millidegree Celsius | 328 | Unit: millidegree Celsius |
| @@ -505,6 +519,7 @@ fan[1-*]_max_alarm | |||
| 505 | temp[1-*]_min_alarm | 519 | temp[1-*]_min_alarm |
| 506 | temp[1-*]_max_alarm | 520 | temp[1-*]_max_alarm |
| 507 | temp[1-*]_crit_alarm | 521 | temp[1-*]_crit_alarm |
| 522 | temp[1-*]_emergency_alarm | ||
| 508 | Limit alarm | 523 | Limit alarm |
| 509 | 0: no alarm | 524 | 0: no alarm |
| 510 | 1: alarm | 525 | 1: alarm |
diff --git a/MAINTAINERS b/MAINTAINERS index ba9480edf8fd..d0c2206fd632 100644 --- a/MAINTAINERS +++ b/MAINTAINERS | |||
| @@ -432,7 +432,7 @@ AMS (Apple Motion Sensor) DRIVER | |||
| 432 | M: Stelian Pop <stelian@popies.net> | 432 | M: Stelian Pop <stelian@popies.net> |
| 433 | M: Michael Hanselmann <linux-kernel@hansmi.ch> | 433 | M: Michael Hanselmann <linux-kernel@hansmi.ch> |
| 434 | S: Supported | 434 | S: Supported |
| 435 | F: drivers/hwmon/ams/ | 435 | F: drivers/macintosh/ams/ |
| 436 | 436 | ||
| 437 | AMSO1100 RNIC DRIVER | 437 | AMSO1100 RNIC DRIVER |
| 438 | M: Tom Tucker <tom@opengridcomputing.com> | 438 | M: Tom Tucker <tom@opengridcomputing.com> |
| @@ -6465,6 +6465,12 @@ S: Maintained | |||
| 6465 | F: Documentation/hwmon/w83793 | 6465 | F: Documentation/hwmon/w83793 |
| 6466 | F: drivers/hwmon/w83793.c | 6466 | F: drivers/hwmon/w83793.c |
| 6467 | 6467 | ||
| 6468 | W83795 HARDWARE MONITORING DRIVER | ||
| 6469 | M: Jean Delvare <khali@linux-fr.org> | ||
| 6470 | L: lm-sensors@lm-sensors.org | ||
| 6471 | S: Maintained | ||
| 6472 | F: drivers/hwmon/w83795.c | ||
| 6473 | |||
| 6468 | W83L51xD SD/MMC CARD INTERFACE DRIVER | 6474 | W83L51xD SD/MMC CARD INTERFACE DRIVER |
| 6469 | M: Pierre Ossman <pierre@ossman.eu> | 6475 | M: Pierre Ossman <pierre@ossman.eu> |
| 6470 | S: Maintained | 6476 | S: Maintained |
diff --git a/drivers/hwmon/Kconfig b/drivers/hwmon/Kconfig index c357c835eb1e..a56f6adf3b76 100644 --- a/drivers/hwmon/Kconfig +++ b/drivers/hwmon/Kconfig | |||
| @@ -129,7 +129,7 @@ config SENSORS_ADM1025 | |||
| 129 | 129 | ||
| 130 | config SENSORS_ADM1026 | 130 | config SENSORS_ADM1026 |
| 131 | tristate "Analog Devices ADM1026 and compatibles" | 131 | tristate "Analog Devices ADM1026 and compatibles" |
| 132 | depends on I2C && EXPERIMENTAL | 132 | depends on I2C |
| 133 | select HWMON_VID | 133 | select HWMON_VID |
| 134 | help | 134 | help |
| 135 | If you say yes here you get support for Analog Devices ADM1026 | 135 | If you say yes here you get support for Analog Devices ADM1026 |
| @@ -140,7 +140,7 @@ config SENSORS_ADM1026 | |||
| 140 | 140 | ||
| 141 | config SENSORS_ADM1029 | 141 | config SENSORS_ADM1029 |
| 142 | tristate "Analog Devices ADM1029" | 142 | tristate "Analog Devices ADM1029" |
| 143 | depends on I2C && EXPERIMENTAL | 143 | depends on I2C |
| 144 | help | 144 | help |
| 145 | If you say yes here you get support for Analog Devices ADM1029 | 145 | If you say yes here you get support for Analog Devices ADM1029 |
| 146 | sensor chip. | 146 | sensor chip. |
| @@ -151,7 +151,7 @@ config SENSORS_ADM1029 | |||
| 151 | 151 | ||
| 152 | config SENSORS_ADM1031 | 152 | config SENSORS_ADM1031 |
| 153 | tristate "Analog Devices ADM1031 and compatibles" | 153 | tristate "Analog Devices ADM1031 and compatibles" |
| 154 | depends on I2C && EXPERIMENTAL | 154 | depends on I2C |
| 155 | help | 155 | help |
| 156 | If you say yes here you get support for Analog Devices ADM1031 | 156 | If you say yes here you get support for Analog Devices ADM1031 |
| 157 | and ADM1030 sensor chips. | 157 | and ADM1030 sensor chips. |
| @@ -202,7 +202,7 @@ config SENSORS_ADT7470 | |||
| 202 | 202 | ||
| 203 | config SENSORS_ADT7475 | 203 | config SENSORS_ADT7475 |
| 204 | tristate "Analog Devices ADT7473, ADT7475, ADT7476 and ADT7490" | 204 | tristate "Analog Devices ADT7473, ADT7475, ADT7476 and ADT7490" |
| 205 | depends on I2C && EXPERIMENTAL | 205 | depends on I2C |
| 206 | select HWMON_VID | 206 | select HWMON_VID |
| 207 | help | 207 | help |
| 208 | If you say yes here you get support for the Analog Devices | 208 | If you say yes here you get support for the Analog Devices |
| @@ -249,32 +249,6 @@ config SENSORS_K10TEMP | |||
| 249 | This driver can also be built as a module. If so, the module | 249 | This driver can also be built as a module. If so, the module |
| 250 | will be called k10temp. | 250 | will be called k10temp. |
| 251 | 251 | ||
| 252 | config SENSORS_AMS | ||
| 253 | tristate "Apple Motion Sensor driver" | ||
| 254 | depends on PPC_PMAC && !PPC64 && INPUT && ((ADB_PMU && I2C = y) || (ADB_PMU && !I2C) || I2C) && EXPERIMENTAL | ||
| 255 | select INPUT_POLLDEV | ||
| 256 | help | ||
| 257 | Support for the motion sensor included in PowerBooks. Includes | ||
| 258 | implementations for PMU and I2C. | ||
| 259 | |||
| 260 | This driver can also be built as a module. If so, the module | ||
| 261 | will be called ams. | ||
| 262 | |||
| 263 | config SENSORS_AMS_PMU | ||
| 264 | bool "PMU variant" | ||
| 265 | depends on SENSORS_AMS && ADB_PMU | ||
| 266 | default y | ||
| 267 | help | ||
| 268 | PMU variant of motion sensor, found in late 2005 PowerBooks. | ||
| 269 | |||
| 270 | config SENSORS_AMS_I2C | ||
| 271 | bool "I2C variant" | ||
| 272 | depends on SENSORS_AMS && I2C | ||
| 273 | default y | ||
| 274 | help | ||
| 275 | I2C variant of motion sensor, found in early 2005 PowerBooks and | ||
| 276 | iBooks. | ||
| 277 | |||
| 278 | config SENSORS_ASB100 | 252 | config SENSORS_ASB100 |
| 279 | tristate "Asus ASB100 Bach" | 253 | tristate "Asus ASB100 Bach" |
| 280 | depends on X86 && I2C && EXPERIMENTAL | 254 | depends on X86 && I2C && EXPERIMENTAL |
| @@ -322,7 +296,6 @@ config SENSORS_I5K_AMB | |||
| 322 | 296 | ||
| 323 | config SENSORS_F71805F | 297 | config SENSORS_F71805F |
| 324 | tristate "Fintek F71805F/FG, F71806F/FG and F71872F/FG" | 298 | tristate "Fintek F71805F/FG, F71806F/FG and F71872F/FG" |
| 325 | depends on EXPERIMENTAL | ||
| 326 | help | 299 | help |
| 327 | If you say yes here you get support for hardware monitoring | 300 | If you say yes here you get support for hardware monitoring |
| 328 | features of the Fintek F71805F/FG, F71806F/FG and F71872F/FG | 301 | features of the Fintek F71805F/FG, F71806F/FG and F71872F/FG |
| @@ -333,7 +306,6 @@ config SENSORS_F71805F | |||
| 333 | 306 | ||
| 334 | config SENSORS_F71882FG | 307 | config SENSORS_F71882FG |
| 335 | tristate "Fintek F71858FG, F71862FG, F71882FG, F71889FG and F8000" | 308 | tristate "Fintek F71858FG, F71862FG, F71882FG, F71889FG and F8000" |
| 336 | depends on EXPERIMENTAL | ||
| 337 | help | 309 | help |
| 338 | If you say yes here you get support for hardware monitoring | 310 | If you say yes here you get support for hardware monitoring |
| 339 | features of the Fintek F71858FG, F71862FG/71863FG, F71882FG/F71883FG, | 311 | features of the Fintek F71858FG, F71862FG/71863FG, F71882FG/F71883FG, |
| @@ -343,8 +315,8 @@ config SENSORS_F71882FG | |||
| 343 | will be called f71882fg. | 315 | will be called f71882fg. |
| 344 | 316 | ||
| 345 | config SENSORS_F75375S | 317 | config SENSORS_F75375S |
| 346 | tristate "Fintek F75375S/SP and F75373"; | 318 | tristate "Fintek F75375S/SP and F75373" |
| 347 | depends on I2C && EXPERIMENTAL | 319 | depends on I2C |
| 348 | help | 320 | help |
| 349 | If you say yes here you get support for hardware monitoring | 321 | If you say yes here you get support for hardware monitoring |
| 350 | features of the Fintek F75375S/SP and F75373 | 322 | features of the Fintek F75375S/SP and F75373 |
| @@ -456,8 +428,8 @@ config SENSORS_IT87 | |||
| 456 | select HWMON_VID | 428 | select HWMON_VID |
| 457 | help | 429 | help |
| 458 | If you say yes here you get support for ITE IT8705F, IT8712F, | 430 | If you say yes here you get support for ITE IT8705F, IT8712F, |
| 459 | IT8716F, IT8718F, IT8720F and IT8726F sensor chips, and the | 431 | IT8716F, IT8718F, IT8720F, IT8721F, IT8726F and IT8758E sensor |
| 460 | SiS960 clone. | 432 | chips, and the SiS960 clone. |
| 461 | 433 | ||
| 462 | This driver can also be built as a module. If so, the module | 434 | This driver can also be built as a module. If so, the module |
| 463 | will be called it87. | 435 | will be called it87. |
| @@ -499,7 +471,7 @@ config SENSORS_LM63 | |||
| 499 | 471 | ||
| 500 | config SENSORS_LM70 | 472 | config SENSORS_LM70 |
| 501 | tristate "National Semiconductor LM70 / Texas Instruments TMP121" | 473 | tristate "National Semiconductor LM70 / Texas Instruments TMP121" |
| 502 | depends on SPI_MASTER && EXPERIMENTAL | 474 | depends on SPI_MASTER |
| 503 | help | 475 | help |
| 504 | If you say yes here you get support for the National Semiconductor | 476 | If you say yes here you get support for the National Semiconductor |
| 505 | LM70 and Texas Instruments TMP121/TMP123 digital temperature | 477 | LM70 and Texas Instruments TMP121/TMP123 digital temperature |
| @@ -567,7 +539,7 @@ config SENSORS_LM78 | |||
| 567 | 539 | ||
| 568 | config SENSORS_LM80 | 540 | config SENSORS_LM80 |
| 569 | tristate "National Semiconductor LM80" | 541 | tristate "National Semiconductor LM80" |
| 570 | depends on I2C && EXPERIMENTAL | 542 | depends on I2C |
| 571 | help | 543 | help |
| 572 | If you say yes here you get support for National Semiconductor | 544 | If you say yes here you get support for National Semiconductor |
| 573 | LM80 sensor chips. | 545 | LM80 sensor chips. |
| @@ -587,11 +559,12 @@ config SENSORS_LM83 | |||
| 587 | 559 | ||
| 588 | config SENSORS_LM85 | 560 | config SENSORS_LM85 |
| 589 | tristate "National Semiconductor LM85 and compatibles" | 561 | tristate "National Semiconductor LM85 and compatibles" |
| 590 | depends on I2C && EXPERIMENTAL | 562 | depends on I2C |
| 591 | select HWMON_VID | 563 | select HWMON_VID |
| 592 | help | 564 | help |
| 593 | If you say yes here you get support for National Semiconductor LM85 | 565 | If you say yes here you get support for National Semiconductor LM85 |
| 594 | sensor chips and clones: ADT7463, EMC6D100, EMC6D102 and ADM1027. | 566 | sensor chips and clones: ADM1027, ADT7463, ADT7468, EMC6D100, |
| 567 | EMC6D101 and EMC6D102. | ||
| 595 | 568 | ||
| 596 | This driver can also be built as a module. If so, the module | 569 | This driver can also be built as a module. If so, the module |
| 597 | will be called lm85. | 570 | will be called lm85. |
| @@ -614,8 +587,8 @@ config SENSORS_LM90 | |||
| 614 | If you say yes here you get support for National Semiconductor LM90, | 587 | If you say yes here you get support for National Semiconductor LM90, |
| 615 | LM86, LM89 and LM99, Analog Devices ADM1032 and ADT7461, Maxim | 588 | LM86, LM89 and LM99, Analog Devices ADM1032 and ADT7461, Maxim |
| 616 | MAX6646, MAX6647, MAX6648, MAX6649, MAX6657, MAX6658, MAX6659, | 589 | MAX6646, MAX6647, MAX6648, MAX6649, MAX6657, MAX6658, MAX6659, |
| 617 | MAX6680, MAX6681 and MAX6692, and Winbond/Nuvoton W83L771AWG/ASG | 590 | MAX6680, MAX6681, MAX6692, MAX6695, MAX6696, and Winbond/Nuvoton |
| 618 | sensor chips. | 591 | W83L771W/G/AWG/ASG sensor chips. |
| 619 | 592 | ||
| 620 | This driver can also be built as a module. If so, the module | 593 | This driver can also be built as a module. If so, the module |
| 621 | will be called lm90. | 594 | will be called lm90. |
| @@ -726,7 +699,6 @@ config SENSORS_PC87360 | |||
| 726 | 699 | ||
| 727 | config SENSORS_PC87427 | 700 | config SENSORS_PC87427 |
| 728 | tristate "National Semiconductor PC87427" | 701 | tristate "National Semiconductor PC87427" |
| 729 | depends on EXPERIMENTAL | ||
| 730 | help | 702 | help |
| 731 | If you say yes here you get access to the hardware monitoring | 703 | If you say yes here you get access to the hardware monitoring |
| 732 | functions of the National Semiconductor PC87427 Super-I/O chip. | 704 | functions of the National Semiconductor PC87427 Super-I/O chip. |
| @@ -763,14 +735,14 @@ config SENSORS_SHT15 | |||
| 763 | will be called sht15. | 735 | will be called sht15. |
| 764 | 736 | ||
| 765 | config SENSORS_S3C | 737 | config SENSORS_S3C |
| 766 | tristate "S3C24XX/S3C64XX Inbuilt ADC" | 738 | tristate "Samsung built-in ADC" |
| 767 | depends on ARCH_S3C2410 | 739 | depends on S3C_ADC |
| 768 | help | 740 | help |
| 769 | If you say yes here you get support for the on-board ADCs of | 741 | If you say yes here you get support for the on-board ADCs of |
| 770 | the Samsung S3C24XX or S3C64XX series of SoC | 742 | the Samsung S3C24XX, S3C64XX and other series of SoC |
| 771 | 743 | ||
| 772 | This driver can also be built as a module. If so, the module | 744 | This driver can also be built as a module. If so, the module |
| 773 | will be called s3c-hwmo. | 745 | will be called s3c-hwmon. |
| 774 | 746 | ||
| 775 | config SENSORS_S3C_RAW | 747 | config SENSORS_S3C_RAW |
| 776 | bool "Include raw channel attributes in sysfs" | 748 | bool "Include raw channel attributes in sysfs" |
| @@ -854,7 +826,7 @@ config SENSORS_SMSC47M1 | |||
| 854 | 826 | ||
| 855 | config SENSORS_SMSC47M192 | 827 | config SENSORS_SMSC47M192 |
| 856 | tristate "SMSC LPC47M192 and compatibles" | 828 | tristate "SMSC LPC47M192 and compatibles" |
| 857 | depends on I2C && EXPERIMENTAL | 829 | depends on I2C |
| 858 | select HWMON_VID | 830 | select HWMON_VID |
| 859 | help | 831 | help |
| 860 | If you say yes here you get support for the temperature and | 832 | If you say yes here you get support for the temperature and |
| @@ -910,7 +882,7 @@ config SENSORS_AMC6821 | |||
| 910 | 882 | ||
| 911 | config SENSORS_THMC50 | 883 | config SENSORS_THMC50 |
| 912 | tristate "Texas Instruments THMC50 / Analog Devices ADM1022" | 884 | tristate "Texas Instruments THMC50 / Analog Devices ADM1022" |
| 913 | depends on I2C && EXPERIMENTAL | 885 | depends on I2C |
| 914 | help | 886 | help |
| 915 | If you say yes here you get support for Texas Instruments THMC50 | 887 | If you say yes here you get support for Texas Instruments THMC50 |
| 916 | sensor chips and clones: the Analog Devices ADM1022. | 888 | sensor chips and clones: the Analog Devices ADM1022. |
| @@ -968,7 +940,6 @@ config SENSORS_VIA686A | |||
| 968 | 940 | ||
| 969 | config SENSORS_VT1211 | 941 | config SENSORS_VT1211 |
| 970 | tristate "VIA VT1211" | 942 | tristate "VIA VT1211" |
| 971 | depends on EXPERIMENTAL | ||
| 972 | select HWMON_VID | 943 | select HWMON_VID |
| 973 | help | 944 | help |
| 974 | If you say yes here then you get support for hardware monitoring | 945 | If you say yes here then you get support for hardware monitoring |
| @@ -1012,7 +983,7 @@ config SENSORS_W83791D | |||
| 1012 | 983 | ||
| 1013 | config SENSORS_W83792D | 984 | config SENSORS_W83792D |
| 1014 | tristate "Winbond W83792D" | 985 | tristate "Winbond W83792D" |
| 1015 | depends on I2C && EXPERIMENTAL | 986 | depends on I2C |
| 1016 | help | 987 | help |
| 1017 | If you say yes here you get support for the Winbond W83792D chip. | 988 | If you say yes here you get support for the Winbond W83792D chip. |
| 1018 | 989 | ||
| @@ -1031,6 +1002,33 @@ config SENSORS_W83793 | |||
| 1031 | This driver can also be built as a module. If so, the module | 1002 | This driver can also be built as a module. If so, the module |
| 1032 | will be called w83793. | 1003 | will be called w83793. |
| 1033 | 1004 | ||
| 1005 | config SENSORS_W83795 | ||
| 1006 | tristate "Winbond/Nuvoton W83795G/ADG" | ||
| 1007 | depends on I2C && EXPERIMENTAL | ||
| 1008 | help | ||
| 1009 | If you say yes here you get support for the Winbond W83795G and | ||
| 1010 | W83795ADG hardware monitoring chip. | ||
| 1011 | |||
| 1012 | This driver can also be built as a module. If so, the module | ||
| 1013 | will be called w83795. | ||
| 1014 | |||
| 1015 | config SENSORS_W83795_FANCTRL | ||
| 1016 | boolean "Include fan control support (DANGEROUS)" | ||
| 1017 | depends on SENSORS_W83795 && EXPERIMENTAL | ||
| 1018 | default n | ||
| 1019 | help | ||
| 1020 | If you say yes here, support for the both manual and automatic | ||
| 1021 | fan control features will be included in the driver. | ||
| 1022 | |||
| 1023 | This part of the code wasn't carefully reviewed and tested yet, | ||
| 1024 | so enabling this option is strongly discouraged on production | ||
| 1025 | servers. Only developers and testers should enable it for the | ||
| 1026 | time being. | ||
| 1027 | |||
| 1028 | Please also note that this option will create sysfs attribute | ||
| 1029 | files which may change in the future, so you shouldn't rely | ||
| 1030 | on them being stable. | ||
| 1031 | |||
| 1034 | config SENSORS_W83L785TS | 1032 | config SENSORS_W83L785TS |
| 1035 | tristate "Winbond W83L785TS-S" | 1033 | tristate "Winbond W83L785TS-S" |
| 1036 | depends on I2C && EXPERIMENTAL | 1034 | depends on I2C && EXPERIMENTAL |
diff --git a/drivers/hwmon/Makefile b/drivers/hwmon/Makefile index d30f0f6870e0..2479b3da272c 100644 --- a/drivers/hwmon/Makefile +++ b/drivers/hwmon/Makefile | |||
| @@ -14,6 +14,7 @@ obj-$(CONFIG_SENSORS_ASB100) += asb100.o | |||
| 14 | obj-$(CONFIG_SENSORS_W83627HF) += w83627hf.o | 14 | obj-$(CONFIG_SENSORS_W83627HF) += w83627hf.o |
| 15 | obj-$(CONFIG_SENSORS_W83792D) += w83792d.o | 15 | obj-$(CONFIG_SENSORS_W83792D) += w83792d.o |
| 16 | obj-$(CONFIG_SENSORS_W83793) += w83793.o | 16 | obj-$(CONFIG_SENSORS_W83793) += w83793.o |
| 17 | obj-$(CONFIG_SENSORS_W83795) += w83795.o | ||
| 17 | obj-$(CONFIG_SENSORS_W83781D) += w83781d.o | 18 | obj-$(CONFIG_SENSORS_W83781D) += w83781d.o |
| 18 | obj-$(CONFIG_SENSORS_W83791D) += w83791d.o | 19 | obj-$(CONFIG_SENSORS_W83791D) += w83791d.o |
| 19 | 20 | ||
| @@ -35,7 +36,6 @@ obj-$(CONFIG_SENSORS_ADT7462) += adt7462.o | |||
| 35 | obj-$(CONFIG_SENSORS_ADT7470) += adt7470.o | 36 | obj-$(CONFIG_SENSORS_ADT7470) += adt7470.o |
| 36 | obj-$(CONFIG_SENSORS_ADT7475) += adt7475.o | 37 | obj-$(CONFIG_SENSORS_ADT7475) += adt7475.o |
| 37 | obj-$(CONFIG_SENSORS_APPLESMC) += applesmc.o | 38 | obj-$(CONFIG_SENSORS_APPLESMC) += applesmc.o |
| 38 | obj-$(CONFIG_SENSORS_AMS) += ams/ | ||
| 39 | obj-$(CONFIG_SENSORS_ASC7621) += asc7621.o | 39 | obj-$(CONFIG_SENSORS_ASC7621) += asc7621.o |
| 40 | obj-$(CONFIG_SENSORS_ATXP1) += atxp1.o | 40 | obj-$(CONFIG_SENSORS_ATXP1) += atxp1.o |
| 41 | obj-$(CONFIG_SENSORS_CORETEMP) += coretemp.o | 41 | obj-$(CONFIG_SENSORS_CORETEMP) += coretemp.o |
diff --git a/drivers/hwmon/adt7475.c b/drivers/hwmon/adt7475.c index a0c385145686..b5fcd87931cb 100644 --- a/drivers/hwmon/adt7475.c +++ b/drivers/hwmon/adt7475.c | |||
| @@ -146,7 +146,7 @@ | |||
| 146 | #define TEMP_OFFSET_REG(idx) (REG_TEMP_OFFSET_BASE + (idx)) | 146 | #define TEMP_OFFSET_REG(idx) (REG_TEMP_OFFSET_BASE + (idx)) |
| 147 | #define TEMP_TRANGE_REG(idx) (REG_TEMP_TRANGE_BASE + (idx)) | 147 | #define TEMP_TRANGE_REG(idx) (REG_TEMP_TRANGE_BASE + (idx)) |
| 148 | 148 | ||
| 149 | static unsigned short normal_i2c[] = { 0x2c, 0x2d, 0x2e, I2C_CLIENT_END }; | 149 | static const unsigned short normal_i2c[] = { 0x2c, 0x2d, 0x2e, I2C_CLIENT_END }; |
| 150 | 150 | ||
| 151 | enum chips { adt7473, adt7475, adt7476, adt7490 }; | 151 | enum chips { adt7473, adt7475, adt7476, adt7490 }; |
| 152 | 152 | ||
diff --git a/drivers/hwmon/asc7621.c b/drivers/hwmon/asc7621.c index 89b4f3babe87..d2596cec18b5 100644 --- a/drivers/hwmon/asc7621.c +++ b/drivers/hwmon/asc7621.c | |||
| @@ -28,7 +28,7 @@ | |||
| 28 | #include <linux/mutex.h> | 28 | #include <linux/mutex.h> |
| 29 | 29 | ||
| 30 | /* Addresses to scan */ | 30 | /* Addresses to scan */ |
| 31 | static unsigned short normal_i2c[] = { | 31 | static const unsigned short normal_i2c[] = { |
| 32 | 0x2c, 0x2d, 0x2e, I2C_CLIENT_END | 32 | 0x2c, 0x2d, 0x2e, I2C_CLIENT_END |
| 33 | }; | 33 | }; |
| 34 | 34 | ||
| @@ -52,7 +52,7 @@ struct asc7621_chip { | |||
| 52 | u8 company_id; | 52 | u8 company_id; |
| 53 | u8 verstep_reg; | 53 | u8 verstep_reg; |
| 54 | u8 verstep_id; | 54 | u8 verstep_id; |
| 55 | unsigned short *addresses; | 55 | const unsigned short *addresses; |
| 56 | }; | 56 | }; |
| 57 | 57 | ||
| 58 | static struct asc7621_chip asc7621_chips[] = { | 58 | static struct asc7621_chip asc7621_chips[] = { |
diff --git a/drivers/hwmon/it87.c b/drivers/hwmon/it87.c index f7701295937d..14a5d981be7d 100644 --- a/drivers/hwmon/it87.c +++ b/drivers/hwmon/it87.c | |||
| @@ -15,7 +15,9 @@ | |||
| 15 | * IT8716F Super I/O chip w/LPC interface | 15 | * IT8716F Super I/O chip w/LPC interface |
| 16 | * IT8718F Super I/O chip w/LPC interface | 16 | * IT8718F Super I/O chip w/LPC interface |
| 17 | * IT8720F Super I/O chip w/LPC interface | 17 | * IT8720F Super I/O chip w/LPC interface |
| 18 | * IT8721F Super I/O chip w/LPC interface | ||
| 18 | * IT8726F Super I/O chip w/LPC interface | 19 | * IT8726F Super I/O chip w/LPC interface |
| 20 | * IT8758E Super I/O chip w/LPC interface | ||
| 19 | * Sis950 A clone of the IT8705F | 21 | * Sis950 A clone of the IT8705F |
| 20 | * | 22 | * |
| 21 | * Copyright (C) 2001 Chris Gauthron | 23 | * Copyright (C) 2001 Chris Gauthron |
| @@ -54,7 +56,7 @@ | |||
| 54 | 56 | ||
| 55 | #define DRVNAME "it87" | 57 | #define DRVNAME "it87" |
| 56 | 58 | ||
| 57 | enum chips { it87, it8712, it8716, it8718, it8720 }; | 59 | enum chips { it87, it8712, it8716, it8718, it8720, it8721 }; |
| 58 | 60 | ||
| 59 | static unsigned short force_id; | 61 | static unsigned short force_id; |
| 60 | module_param(force_id, ushort, 0); | 62 | module_param(force_id, ushort, 0); |
| @@ -126,6 +128,7 @@ superio_exit(void) | |||
| 126 | #define IT8716F_DEVID 0x8716 | 128 | #define IT8716F_DEVID 0x8716 |
| 127 | #define IT8718F_DEVID 0x8718 | 129 | #define IT8718F_DEVID 0x8718 |
| 128 | #define IT8720F_DEVID 0x8720 | 130 | #define IT8720F_DEVID 0x8720 |
| 131 | #define IT8721F_DEVID 0x8721 | ||
| 129 | #define IT8726F_DEVID 0x8726 | 132 | #define IT8726F_DEVID 0x8726 |
| 130 | #define IT87_ACT_REG 0x30 | 133 | #define IT87_ACT_REG 0x30 |
| 131 | #define IT87_BASE_REG 0x60 | 134 | #define IT87_BASE_REG 0x60 |
| @@ -202,56 +205,6 @@ static const u8 IT87_REG_FANX_MIN[] = { 0x1b, 0x1c, 0x1d, 0x85, 0x87 }; | |||
| 202 | #define IT87_REG_AUTO_TEMP(nr, i) (0x60 + (nr) * 8 + (i)) | 205 | #define IT87_REG_AUTO_TEMP(nr, i) (0x60 + (nr) * 8 + (i)) |
| 203 | #define IT87_REG_AUTO_PWM(nr, i) (0x65 + (nr) * 8 + (i)) | 206 | #define IT87_REG_AUTO_PWM(nr, i) (0x65 + (nr) * 8 + (i)) |
| 204 | 207 | ||
| 205 | #define IN_TO_REG(val) (SENSORS_LIMIT((((val) + 8)/16),0,255)) | ||
| 206 | #define IN_FROM_REG(val) ((val) * 16) | ||
| 207 | |||
| 208 | static inline u8 FAN_TO_REG(long rpm, int div) | ||
| 209 | { | ||
| 210 | if (rpm == 0) | ||
| 211 | return 255; | ||
| 212 | rpm = SENSORS_LIMIT(rpm, 1, 1000000); | ||
| 213 | return SENSORS_LIMIT((1350000 + rpm * div / 2) / (rpm * div), 1, | ||
| 214 | 254); | ||
| 215 | } | ||
| 216 | |||
| 217 | static inline u16 FAN16_TO_REG(long rpm) | ||
| 218 | { | ||
| 219 | if (rpm == 0) | ||
| 220 | return 0xffff; | ||
| 221 | return SENSORS_LIMIT((1350000 + rpm) / (rpm * 2), 1, 0xfffe); | ||
| 222 | } | ||
| 223 | |||
| 224 | #define FAN_FROM_REG(val,div) ((val)==0?-1:(val)==255?0:1350000/((val)*(div))) | ||
| 225 | /* The divider is fixed to 2 in 16-bit mode */ | ||
| 226 | #define FAN16_FROM_REG(val) ((val)==0?-1:(val)==0xffff?0:1350000/((val)*2)) | ||
| 227 | |||
| 228 | #define TEMP_TO_REG(val) (SENSORS_LIMIT(((val)<0?(((val)-500)/1000):\ | ||
| 229 | ((val)+500)/1000),-128,127)) | ||
| 230 | #define TEMP_FROM_REG(val) ((val) * 1000) | ||
| 231 | |||
| 232 | #define PWM_TO_REG(val) ((val) >> 1) | ||
| 233 | #define PWM_FROM_REG(val) (((val)&0x7f) << 1) | ||
| 234 | |||
| 235 | static int DIV_TO_REG(int val) | ||
| 236 | { | ||
| 237 | int answer = 0; | ||
| 238 | while (answer < 7 && (val >>= 1)) | ||
| 239 | answer++; | ||
| 240 | return answer; | ||
| 241 | } | ||
| 242 | #define DIV_FROM_REG(val) (1 << (val)) | ||
| 243 | |||
| 244 | static const unsigned int pwm_freq[8] = { | ||
| 245 | 48000000 / 128, | ||
| 246 | 24000000 / 128, | ||
| 247 | 12000000 / 128, | ||
| 248 | 8000000 / 128, | ||
| 249 | 6000000 / 128, | ||
| 250 | 3000000 / 128, | ||
| 251 | 1500000 / 128, | ||
| 252 | 750000 / 128, | ||
| 253 | }; | ||
| 254 | |||
| 255 | 208 | ||
| 256 | struct it87_sio_data { | 209 | struct it87_sio_data { |
| 257 | enum chips type; | 210 | enum chips type; |
| @@ -279,6 +232,7 @@ struct it87_data { | |||
| 279 | char valid; /* !=0 if following fields are valid */ | 232 | char valid; /* !=0 if following fields are valid */ |
| 280 | unsigned long last_updated; /* In jiffies */ | 233 | unsigned long last_updated; /* In jiffies */ |
| 281 | 234 | ||
| 235 | u16 in_scaled; /* Internal voltage sensors are scaled */ | ||
| 282 | u8 in[9]; /* Register value */ | 236 | u8 in[9]; /* Register value */ |
| 283 | u8 in_max[8]; /* Register value */ | 237 | u8 in_max[8]; /* Register value */ |
| 284 | u8 in_min[8]; /* Register value */ | 238 | u8 in_min[8]; /* Register value */ |
| @@ -310,6 +264,96 @@ struct it87_data { | |||
| 310 | s8 auto_temp[3][5]; /* [nr][0] is point1_temp_hyst */ | 264 | s8 auto_temp[3][5]; /* [nr][0] is point1_temp_hyst */ |
| 311 | }; | 265 | }; |
| 312 | 266 | ||
| 267 | static u8 in_to_reg(const struct it87_data *data, int nr, long val) | ||
| 268 | { | ||
| 269 | long lsb; | ||
| 270 | |||
| 271 | if (data->type == it8721) { | ||
| 272 | if (data->in_scaled & (1 << nr)) | ||
| 273 | lsb = 24; | ||
| 274 | else | ||
| 275 | lsb = 12; | ||
| 276 | } else | ||
| 277 | lsb = 16; | ||
| 278 | |||
| 279 | val = DIV_ROUND_CLOSEST(val, lsb); | ||
| 280 | return SENSORS_LIMIT(val, 0, 255); | ||
| 281 | } | ||
| 282 | |||
| 283 | static int in_from_reg(const struct it87_data *data, int nr, int val) | ||
| 284 | { | ||
| 285 | if (data->type == it8721) { | ||
| 286 | if (data->in_scaled & (1 << nr)) | ||
| 287 | return val * 24; | ||
| 288 | else | ||
| 289 | return val * 12; | ||
| 290 | } else | ||
| 291 | return val * 16; | ||
| 292 | } | ||
| 293 | |||
| 294 | static inline u8 FAN_TO_REG(long rpm, int div) | ||
| 295 | { | ||
| 296 | if (rpm == 0) | ||
| 297 | return 255; | ||
| 298 | rpm = SENSORS_LIMIT(rpm, 1, 1000000); | ||
| 299 | return SENSORS_LIMIT((1350000 + rpm * div / 2) / (rpm * div), 1, | ||
| 300 | 254); | ||
| 301 | } | ||
| 302 | |||
| 303 | static inline u16 FAN16_TO_REG(long rpm) | ||
| 304 | { | ||
| 305 | if (rpm == 0) | ||
| 306 | return 0xffff; | ||
| 307 | return SENSORS_LIMIT((1350000 + rpm) / (rpm * 2), 1, 0xfffe); | ||
| 308 | } | ||
| 309 | |||
| 310 | #define FAN_FROM_REG(val, div) ((val) == 0 ? -1 : (val) == 255 ? 0 : \ | ||
| 311 | 1350000 / ((val) * (div))) | ||
| 312 | /* The divider is fixed to 2 in 16-bit mode */ | ||
| 313 | #define FAN16_FROM_REG(val) ((val) == 0 ? -1 : (val) == 0xffff ? 0 : \ | ||
| 314 | 1350000 / ((val) * 2)) | ||
| 315 | |||
| 316 | #define TEMP_TO_REG(val) (SENSORS_LIMIT(((val) < 0 ? (((val) - 500) / 1000) : \ | ||
| 317 | ((val) + 500) / 1000), -128, 127)) | ||
| 318 | #define TEMP_FROM_REG(val) ((val) * 1000) | ||
| 319 | |||
| 320 | static u8 pwm_to_reg(const struct it87_data *data, long val) | ||
| 321 | { | ||
| 322 | if (data->type == it8721) | ||
| 323 | return val; | ||
| 324 | else | ||
| 325 | return val >> 1; | ||
| 326 | } | ||
| 327 | |||
| 328 | static int pwm_from_reg(const struct it87_data *data, u8 reg) | ||
| 329 | { | ||
| 330 | if (data->type == it8721) | ||
| 331 | return reg; | ||
| 332 | else | ||
| 333 | return (reg & 0x7f) << 1; | ||
| 334 | } | ||
| 335 | |||
| 336 | |||
| 337 | static int DIV_TO_REG(int val) | ||
| 338 | { | ||
| 339 | int answer = 0; | ||
| 340 | while (answer < 7 && (val >>= 1)) | ||
| 341 | answer++; | ||
| 342 | return answer; | ||
| 343 | } | ||
| 344 | #define DIV_FROM_REG(val) (1 << (val)) | ||
| 345 | |||
| 346 | static const unsigned int pwm_freq[8] = { | ||
| 347 | 48000000 / 128, | ||
| 348 | 24000000 / 128, | ||
| 349 | 12000000 / 128, | ||
| 350 | 8000000 / 128, | ||
| 351 | 6000000 / 128, | ||
| 352 | 3000000 / 128, | ||
| 353 | 1500000 / 128, | ||
| 354 | 750000 / 128, | ||
| 355 | }; | ||
| 356 | |||
| 313 | static inline int has_16bit_fans(const struct it87_data *data) | 357 | static inline int has_16bit_fans(const struct it87_data *data) |
| 314 | { | 358 | { |
| 315 | /* IT8705F Datasheet 0.4.1, 3h == Version G. | 359 | /* IT8705F Datasheet 0.4.1, 3h == Version G. |
| @@ -319,7 +363,8 @@ static inline int has_16bit_fans(const struct it87_data *data) | |||
| 319 | || (data->type == it8712 && data->revision >= 0x08) | 363 | || (data->type == it8712 && data->revision >= 0x08) |
| 320 | || data->type == it8716 | 364 | || data->type == it8716 |
| 321 | || data->type == it8718 | 365 | || data->type == it8718 |
| 322 | || data->type == it8720; | 366 | || data->type == it8720 |
| 367 | || data->type == it8721; | ||
| 323 | } | 368 | } |
| 324 | 369 | ||
| 325 | static inline int has_old_autopwm(const struct it87_data *data) | 370 | static inline int has_old_autopwm(const struct it87_data *data) |
| @@ -357,7 +402,7 @@ static ssize_t show_in(struct device *dev, struct device_attribute *attr, | |||
| 357 | int nr = sensor_attr->index; | 402 | int nr = sensor_attr->index; |
| 358 | 403 | ||
| 359 | struct it87_data *data = it87_update_device(dev); | 404 | struct it87_data *data = it87_update_device(dev); |
| 360 | return sprintf(buf, "%d\n", IN_FROM_REG(data->in[nr])); | 405 | return sprintf(buf, "%d\n", in_from_reg(data, nr, data->in[nr])); |
| 361 | } | 406 | } |
| 362 | 407 | ||
| 363 | static ssize_t show_in_min(struct device *dev, struct device_attribute *attr, | 408 | static ssize_t show_in_min(struct device *dev, struct device_attribute *attr, |
| @@ -367,7 +412,7 @@ static ssize_t show_in_min(struct device *dev, struct device_attribute *attr, | |||
| 367 | int nr = sensor_attr->index; | 412 | int nr = sensor_attr->index; |
| 368 | 413 | ||
| 369 | struct it87_data *data = it87_update_device(dev); | 414 | struct it87_data *data = it87_update_device(dev); |
| 370 | return sprintf(buf, "%d\n", IN_FROM_REG(data->in_min[nr])); | 415 | return sprintf(buf, "%d\n", in_from_reg(data, nr, data->in_min[nr])); |
| 371 | } | 416 | } |
| 372 | 417 | ||
| 373 | static ssize_t show_in_max(struct device *dev, struct device_attribute *attr, | 418 | static ssize_t show_in_max(struct device *dev, struct device_attribute *attr, |
| @@ -377,7 +422,7 @@ static ssize_t show_in_max(struct device *dev, struct device_attribute *attr, | |||
| 377 | int nr = sensor_attr->index; | 422 | int nr = sensor_attr->index; |
| 378 | 423 | ||
| 379 | struct it87_data *data = it87_update_device(dev); | 424 | struct it87_data *data = it87_update_device(dev); |
| 380 | return sprintf(buf, "%d\n", IN_FROM_REG(data->in_max[nr])); | 425 | return sprintf(buf, "%d\n", in_from_reg(data, nr, data->in_max[nr])); |
| 381 | } | 426 | } |
| 382 | 427 | ||
| 383 | static ssize_t set_in_min(struct device *dev, struct device_attribute *attr, | 428 | static ssize_t set_in_min(struct device *dev, struct device_attribute *attr, |
| @@ -393,7 +438,7 @@ static ssize_t set_in_min(struct device *dev, struct device_attribute *attr, | |||
| 393 | return -EINVAL; | 438 | return -EINVAL; |
| 394 | 439 | ||
| 395 | mutex_lock(&data->update_lock); | 440 | mutex_lock(&data->update_lock); |
| 396 | data->in_min[nr] = IN_TO_REG(val); | 441 | data->in_min[nr] = in_to_reg(data, nr, val); |
| 397 | it87_write_value(data, IT87_REG_VIN_MIN(nr), | 442 | it87_write_value(data, IT87_REG_VIN_MIN(nr), |
| 398 | data->in_min[nr]); | 443 | data->in_min[nr]); |
| 399 | mutex_unlock(&data->update_lock); | 444 | mutex_unlock(&data->update_lock); |
| @@ -412,7 +457,7 @@ static ssize_t set_in_max(struct device *dev, struct device_attribute *attr, | |||
| 412 | return -EINVAL; | 457 | return -EINVAL; |
| 413 | 458 | ||
| 414 | mutex_lock(&data->update_lock); | 459 | mutex_lock(&data->update_lock); |
| 415 | data->in_max[nr] = IN_TO_REG(val); | 460 | data->in_max[nr] = in_to_reg(data, nr, val); |
| 416 | it87_write_value(data, IT87_REG_VIN_MAX(nr), | 461 | it87_write_value(data, IT87_REG_VIN_MAX(nr), |
| 417 | data->in_max[nr]); | 462 | data->in_max[nr]); |
| 418 | mutex_unlock(&data->update_lock); | 463 | mutex_unlock(&data->update_lock); |
| @@ -642,7 +687,8 @@ static ssize_t show_pwm(struct device *dev, struct device_attribute *attr, | |||
| 642 | int nr = sensor_attr->index; | 687 | int nr = sensor_attr->index; |
| 643 | 688 | ||
| 644 | struct it87_data *data = it87_update_device(dev); | 689 | struct it87_data *data = it87_update_device(dev); |
| 645 | return sprintf(buf, "%d\n", PWM_FROM_REG(data->pwm_duty[nr])); | 690 | return sprintf(buf, "%d\n", |
| 691 | pwm_from_reg(data, data->pwm_duty[nr])); | ||
| 646 | } | 692 | } |
| 647 | static ssize_t show_pwm_freq(struct device *dev, struct device_attribute *attr, | 693 | static ssize_t show_pwm_freq(struct device *dev, struct device_attribute *attr, |
| 648 | char *buf) | 694 | char *buf) |
| @@ -812,7 +858,7 @@ static ssize_t set_pwm(struct device *dev, struct device_attribute *attr, | |||
| 812 | return -EINVAL; | 858 | return -EINVAL; |
| 813 | 859 | ||
| 814 | mutex_lock(&data->update_lock); | 860 | mutex_lock(&data->update_lock); |
| 815 | data->pwm_duty[nr] = PWM_TO_REG(val); | 861 | data->pwm_duty[nr] = pwm_to_reg(data, val); |
| 816 | /* If we are in manual mode, write the duty cycle immediately; | 862 | /* If we are in manual mode, write the duty cycle immediately; |
| 817 | * otherwise, just store it for later use. */ | 863 | * otherwise, just store it for later use. */ |
| 818 | if (!(data->pwm_ctrl[nr] & 0x80)) { | 864 | if (!(data->pwm_ctrl[nr] & 0x80)) { |
| @@ -916,7 +962,8 @@ static ssize_t show_auto_pwm(struct device *dev, | |||
| 916 | int nr = sensor_attr->nr; | 962 | int nr = sensor_attr->nr; |
| 917 | int point = sensor_attr->index; | 963 | int point = sensor_attr->index; |
| 918 | 964 | ||
| 919 | return sprintf(buf, "%d\n", PWM_FROM_REG(data->auto_pwm[nr][point])); | 965 | return sprintf(buf, "%d\n", |
| 966 | pwm_from_reg(data, data->auto_pwm[nr][point])); | ||
| 920 | } | 967 | } |
| 921 | 968 | ||
| 922 | static ssize_t set_auto_pwm(struct device *dev, | 969 | static ssize_t set_auto_pwm(struct device *dev, |
| @@ -933,7 +980,7 @@ static ssize_t set_auto_pwm(struct device *dev, | |||
| 933 | return -EINVAL; | 980 | return -EINVAL; |
| 934 | 981 | ||
| 935 | mutex_lock(&data->update_lock); | 982 | mutex_lock(&data->update_lock); |
| 936 | data->auto_pwm[nr][point] = PWM_TO_REG(val); | 983 | data->auto_pwm[nr][point] = pwm_to_reg(data, val); |
| 937 | it87_write_value(data, IT87_REG_AUTO_PWM(nr, point), | 984 | it87_write_value(data, IT87_REG_AUTO_PWM(nr, point), |
| 938 | data->auto_pwm[nr][point]); | 985 | data->auto_pwm[nr][point]); |
| 939 | mutex_unlock(&data->update_lock); | 986 | mutex_unlock(&data->update_lock); |
| @@ -1203,9 +1250,16 @@ static ssize_t show_label(struct device *dev, struct device_attribute *attr, | |||
| 1203 | "5VSB", | 1250 | "5VSB", |
| 1204 | "Vbat", | 1251 | "Vbat", |
| 1205 | }; | 1252 | }; |
| 1253 | static const char *labels_it8721[] = { | ||
| 1254 | "+3.3V", | ||
| 1255 | "3VSB", | ||
| 1256 | "Vbat", | ||
| 1257 | }; | ||
| 1258 | struct it87_data *data = dev_get_drvdata(dev); | ||
| 1206 | int nr = to_sensor_dev_attr(attr)->index; | 1259 | int nr = to_sensor_dev_attr(attr)->index; |
| 1207 | 1260 | ||
| 1208 | return sprintf(buf, "%s\n", labels[nr]); | 1261 | return sprintf(buf, "%s\n", data->type == it8721 ? labels_it8721[nr] |
| 1262 | : labels[nr]); | ||
| 1209 | } | 1263 | } |
| 1210 | static SENSOR_DEVICE_ATTR(in3_label, S_IRUGO, show_label, NULL, 0); | 1264 | static SENSOR_DEVICE_ATTR(in3_label, S_IRUGO, show_label, NULL, 0); |
| 1211 | static SENSOR_DEVICE_ATTR(in7_label, S_IRUGO, show_label, NULL, 1); | 1265 | static SENSOR_DEVICE_ATTR(in7_label, S_IRUGO, show_label, NULL, 1); |
| @@ -1490,6 +1544,9 @@ static int __init it87_find(unsigned short *address, | |||
| 1490 | case IT8720F_DEVID: | 1544 | case IT8720F_DEVID: |
| 1491 | sio_data->type = it8720; | 1545 | sio_data->type = it8720; |
| 1492 | break; | 1546 | break; |
| 1547 | case IT8721F_DEVID: | ||
| 1548 | sio_data->type = it8721; | ||
| 1549 | break; | ||
| 1493 | case 0xffff: /* No device at all */ | 1550 | case 0xffff: /* No device at all */ |
| 1494 | goto exit; | 1551 | goto exit; |
| 1495 | default: | 1552 | default: |
| @@ -1530,11 +1587,17 @@ static int __init it87_find(unsigned short *address, | |||
| 1530 | int reg; | 1587 | int reg; |
| 1531 | 1588 | ||
| 1532 | superio_select(GPIO); | 1589 | superio_select(GPIO); |
| 1533 | /* We need at least 4 VID pins */ | 1590 | |
| 1534 | reg = superio_inb(IT87_SIO_GPIO3_REG); | 1591 | reg = superio_inb(IT87_SIO_GPIO3_REG); |
| 1535 | if (reg & 0x0f) { | 1592 | if (sio_data->type == it8721) { |
| 1536 | pr_info("it87: VID is disabled (pins used for GPIO)\n"); | 1593 | /* The IT8721F/IT8758E doesn't have VID pins at all */ |
| 1537 | sio_data->skip_vid = 1; | 1594 | sio_data->skip_vid = 1; |
| 1595 | } else { | ||
| 1596 | /* We need at least 4 VID pins */ | ||
| 1597 | if (reg & 0x0f) { | ||
| 1598 | pr_info("it87: VID is disabled (pins used for GPIO)\n"); | ||
| 1599 | sio_data->skip_vid = 1; | ||
| 1600 | } | ||
| 1538 | } | 1601 | } |
| 1539 | 1602 | ||
| 1540 | /* Check if fan3 is there or not */ | 1603 | /* Check if fan3 is there or not */ |
| @@ -1572,7 +1635,7 @@ static int __init it87_find(unsigned short *address, | |||
| 1572 | } | 1635 | } |
| 1573 | if (reg & (1 << 0)) | 1636 | if (reg & (1 << 0)) |
| 1574 | sio_data->internal |= (1 << 0); | 1637 | sio_data->internal |= (1 << 0); |
| 1575 | if (reg & (1 << 1)) | 1638 | if ((reg & (1 << 1)) || sio_data->type == it8721) |
| 1576 | sio_data->internal |= (1 << 1); | 1639 | sio_data->internal |= (1 << 1); |
| 1577 | 1640 | ||
| 1578 | sio_data->beep_pin = superio_inb(IT87_SIO_BEEP_PIN_REG) & 0x3f; | 1641 | sio_data->beep_pin = superio_inb(IT87_SIO_BEEP_PIN_REG) & 0x3f; |
| @@ -1650,6 +1713,7 @@ static int __devinit it87_probe(struct platform_device *pdev) | |||
| 1650 | "it8716", | 1713 | "it8716", |
| 1651 | "it8718", | 1714 | "it8718", |
| 1652 | "it8720", | 1715 | "it8720", |
| 1716 | "it8721", | ||
| 1653 | }; | 1717 | }; |
| 1654 | 1718 | ||
| 1655 | res = platform_get_resource(pdev, IORESOURCE_IO, 0); | 1719 | res = platform_get_resource(pdev, IORESOURCE_IO, 0); |
| @@ -1686,6 +1750,16 @@ static int __devinit it87_probe(struct platform_device *pdev) | |||
| 1686 | /* Check PWM configuration */ | 1750 | /* Check PWM configuration */ |
| 1687 | enable_pwm_interface = it87_check_pwm(dev); | 1751 | enable_pwm_interface = it87_check_pwm(dev); |
| 1688 | 1752 | ||
| 1753 | /* Starting with IT8721F, we handle scaling of internal voltages */ | ||
| 1754 | if (data->type == it8721) { | ||
| 1755 | if (sio_data->internal & (1 << 0)) | ||
| 1756 | data->in_scaled |= (1 << 3); /* in3 is AVCC */ | ||
| 1757 | if (sio_data->internal & (1 << 1)) | ||
| 1758 | data->in_scaled |= (1 << 7); /* in7 is VSB */ | ||
| 1759 | if (sio_data->internal & (1 << 2)) | ||
| 1760 | data->in_scaled |= (1 << 8); /* in8 is Vbat */ | ||
| 1761 | } | ||
| 1762 | |||
| 1689 | /* Initialize the IT87 chip */ | 1763 | /* Initialize the IT87 chip */ |
| 1690 | it87_init_device(pdev); | 1764 | it87_init_device(pdev); |
| 1691 | 1765 | ||
| @@ -2051,7 +2125,7 @@ static struct it87_data *it87_update_device(struct device *dev) | |||
| 2051 | 2125 | ||
| 2052 | data->sensor = it87_read_value(data, IT87_REG_TEMP_ENABLE); | 2126 | data->sensor = it87_read_value(data, IT87_REG_TEMP_ENABLE); |
| 2053 | /* The 8705 does not have VID capability. | 2127 | /* The 8705 does not have VID capability. |
| 2054 | The 8718 and the 8720 don't use IT87_REG_VID for the | 2128 | The 8718 and later don't use IT87_REG_VID for the |
| 2055 | same purpose. */ | 2129 | same purpose. */ |
| 2056 | if (data->type == it8712 || data->type == it8716) { | 2130 | if (data->type == it8712 || data->type == it8716) { |
| 2057 | data->vid = it87_read_value(data, IT87_REG_VID); | 2131 | data->vid = it87_read_value(data, IT87_REG_VID); |
| @@ -2151,7 +2225,7 @@ static void __exit sm_it87_exit(void) | |||
| 2151 | 2225 | ||
| 2152 | MODULE_AUTHOR("Chris Gauthron, " | 2226 | MODULE_AUTHOR("Chris Gauthron, " |
| 2153 | "Jean Delvare <khali@linux-fr.org>"); | 2227 | "Jean Delvare <khali@linux-fr.org>"); |
| 2154 | MODULE_DESCRIPTION("IT8705F/8712F/8716F/8718F/8720F/8726F, SiS950 driver"); | 2228 | MODULE_DESCRIPTION("IT8705F/IT871xF/IT872xF hardware monitoring driver"); |
| 2155 | module_param(update_vbat, bool, 0); | 2229 | module_param(update_vbat, bool, 0); |
| 2156 | MODULE_PARM_DESC(update_vbat, "Update vbat if set else return powerup value"); | 2230 | MODULE_PARM_DESC(update_vbat, "Update vbat if set else return powerup value"); |
| 2157 | module_param(fix_pwm_polarity, bool, 0); | 2231 | module_param(fix_pwm_polarity, bool, 0); |
diff --git a/drivers/hwmon/k8temp.c b/drivers/hwmon/k8temp.c index 39ead2a4d3c5..418496f13020 100644 --- a/drivers/hwmon/k8temp.c +++ b/drivers/hwmon/k8temp.c | |||
| @@ -191,38 +191,31 @@ static int __devinit k8temp_probe(struct pci_dev *pdev, | |||
| 191 | model = boot_cpu_data.x86_model; | 191 | model = boot_cpu_data.x86_model; |
| 192 | stepping = boot_cpu_data.x86_mask; | 192 | stepping = boot_cpu_data.x86_mask; |
| 193 | 193 | ||
| 194 | switch (boot_cpu_data.x86) { | 194 | /* feature available since SH-C0, exclude older revisions */ |
| 195 | case 0xf: | 195 | if (((model == 4) && (stepping == 0)) || |
| 196 | /* feature available since SH-C0, exclude older revisions */ | 196 | ((model == 5) && (stepping <= 1))) { |
| 197 | if (((model == 4) && (stepping == 0)) || | 197 | err = -ENODEV; |
| 198 | ((model == 5) && (stepping <= 1))) { | 198 | goto exit_free; |
| 199 | err = -ENODEV; | 199 | } |
| 200 | goto exit_free; | ||
| 201 | } | ||
| 202 | |||
| 203 | /* | ||
| 204 | * AMD NPT family 0fh, i.e. RevF and RevG: | ||
| 205 | * meaning of SEL_CORE bit is inverted | ||
| 206 | */ | ||
| 207 | if (model >= 0x40) { | ||
| 208 | data->swap_core_select = 1; | ||
| 209 | dev_warn(&pdev->dev, "Temperature readouts might be " | ||
| 210 | "wrong - check erratum #141\n"); | ||
| 211 | } | ||
| 212 | |||
| 213 | if (is_rev_g_desktop(model)) { | ||
| 214 | /* | ||
| 215 | * RevG desktop CPUs (i.e. no socket S1G1 or | ||
| 216 | * ASB1 parts) need additional offset, | ||
| 217 | * otherwise reported temperature is below | ||
| 218 | * ambient temperature | ||
| 219 | */ | ||
| 220 | data->temp_offset = 21000; | ||
| 221 | } | ||
| 222 | 200 | ||
| 223 | break; | 201 | /* |
| 202 | * AMD NPT family 0fh, i.e. RevF and RevG: | ||
| 203 | * meaning of SEL_CORE bit is inverted | ||
| 204 | */ | ||
| 205 | if (model >= 0x40) { | ||
| 206 | data->swap_core_select = 1; | ||
| 207 | dev_warn(&pdev->dev, "Temperature readouts might be wrong - " | ||
| 208 | "check erratum #141\n"); | ||
| 224 | } | 209 | } |
| 225 | 210 | ||
| 211 | /* | ||
| 212 | * RevG desktop CPUs (i.e. no socket S1G1 or ASB1 parts) need | ||
| 213 | * additional offset, otherwise reported temperature is below | ||
| 214 | * ambient temperature | ||
| 215 | */ | ||
| 216 | if (is_rev_g_desktop(model)) | ||
| 217 | data->temp_offset = 21000; | ||
| 218 | |||
| 226 | pci_read_config_byte(pdev, REG_TEMP, &scfg); | 219 | pci_read_config_byte(pdev, REG_TEMP, &scfg); |
| 227 | scfg &= ~(SEL_PLACE | SEL_CORE); /* Select sensor 0, core0 */ | 220 | scfg &= ~(SEL_PLACE | SEL_CORE); /* Select sensor 0, core0 */ |
| 228 | pci_write_config_byte(pdev, REG_TEMP, scfg); | 221 | pci_write_config_byte(pdev, REG_TEMP, scfg); |
diff --git a/drivers/hwmon/lm75.c b/drivers/hwmon/lm75.c index ab5b87a81677..f36eb80d227f 100644 --- a/drivers/hwmon/lm75.c +++ b/drivers/hwmon/lm75.c | |||
| @@ -1,22 +1,22 @@ | |||
| 1 | /* | 1 | /* |
| 2 | lm75.c - Part of lm_sensors, Linux kernel modules for hardware | 2 | * lm75.c - Part of lm_sensors, Linux kernel modules for hardware |
| 3 | monitoring | 3 | * monitoring |
| 4 | Copyright (c) 1998, 1999 Frodo Looijaard <frodol@dds.nl> | 4 | * Copyright (c) 1998, 1999 Frodo Looijaard <frodol@dds.nl> |
| 5 | 5 | * | |
| 6 | This program is free software; you can redistribute it and/or modify | 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 | 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 | 8 | * the Free Software Foundation; either version 2 of the License, or |
| 9 | (at your option) any later version. | 9 | * (at your option) any later version. |
| 10 | 10 | * | |
| 11 | This program is distributed in the hope that it will be useful, | 11 | * This program is distributed in the hope that it will be useful, |
| 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | GNU General Public License for more details. | 14 | * GNU General Public License for more details. |
| 15 | 15 | * | |
| 16 | You should have received a copy of the GNU General Public License | 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 | 17 | * along with this program; if not, write to the Free Software |
| 18 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | 18 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 19 | */ | 19 | */ |
| 20 | 20 | ||
| 21 | #include <linux/module.h> | 21 | #include <linux/module.h> |
| 22 | #include <linux/init.h> | 22 | #include <linux/init.h> |
| @@ -103,7 +103,12 @@ static ssize_t set_temp(struct device *dev, struct device_attribute *da, | |||
| 103 | struct i2c_client *client = to_i2c_client(dev); | 103 | struct i2c_client *client = to_i2c_client(dev); |
| 104 | struct lm75_data *data = i2c_get_clientdata(client); | 104 | struct lm75_data *data = i2c_get_clientdata(client); |
| 105 | int nr = attr->index; | 105 | int nr = attr->index; |
| 106 | long temp = simple_strtol(buf, NULL, 10); | 106 | long temp; |
| 107 | int error; | ||
| 108 | |||
| 109 | error = strict_strtol(buf, 10, &temp); | ||
| 110 | if (error) | ||
| 111 | return error; | ||
| 107 | 112 | ||
| 108 | mutex_lock(&data->update_lock); | 113 | mutex_lock(&data->update_lock); |
| 109 | data->temp[nr] = LM75_TEMP_TO_REG(temp); | 114 | data->temp[nr] = LM75_TEMP_TO_REG(temp); |
| @@ -335,9 +340,11 @@ static struct i2c_driver lm75_driver = { | |||
| 335 | 340 | ||
| 336 | /* register access */ | 341 | /* register access */ |
| 337 | 342 | ||
| 338 | /* All registers are word-sized, except for the configuration register. | 343 | /* |
| 339 | LM75 uses a high-byte first convention, which is exactly opposite to | 344 | * All registers are word-sized, except for the configuration register. |
| 340 | the SMBus standard. */ | 345 | * LM75 uses a high-byte first convention, which is exactly opposite to |
| 346 | * the SMBus standard. | ||
| 347 | */ | ||
| 341 | static int lm75_read_value(struct i2c_client *client, u8 reg) | 348 | static int lm75_read_value(struct i2c_client *client, u8 reg) |
| 342 | { | 349 | { |
| 343 | int value; | 350 | int value; |
diff --git a/drivers/hwmon/lm85.c b/drivers/hwmon/lm85.c index b3841a615595..1e229847f37a 100644 --- a/drivers/hwmon/lm85.c +++ b/drivers/hwmon/lm85.c | |||
| @@ -64,9 +64,12 @@ enum chips { | |||
| 64 | #define LM85_REG_VERSTEP 0x3f | 64 | #define LM85_REG_VERSTEP 0x3f |
| 65 | 65 | ||
| 66 | #define ADT7468_REG_CFG5 0x7c | 66 | #define ADT7468_REG_CFG5 0x7c |
| 67 | #define ADT7468_OFF64 0x01 | 67 | #define ADT7468_OFF64 (1 << 0) |
| 68 | #define ADT7468_HFPWM (1 << 1) | ||
| 68 | #define IS_ADT7468_OFF64(data) \ | 69 | #define IS_ADT7468_OFF64(data) \ |
| 69 | ((data)->type == adt7468 && !((data)->cfg5 & ADT7468_OFF64)) | 70 | ((data)->type == adt7468 && !((data)->cfg5 & ADT7468_OFF64)) |
| 71 | #define IS_ADT7468_HFPWM(data) \ | ||
| 72 | ((data)->type == adt7468 && !((data)->cfg5 & ADT7468_HFPWM)) | ||
| 70 | 73 | ||
| 71 | /* These are the recognized values for the above regs */ | 74 | /* These are the recognized values for the above regs */ |
| 72 | #define LM85_COMPANY_NATIONAL 0x01 | 75 | #define LM85_COMPANY_NATIONAL 0x01 |
| @@ -567,8 +570,14 @@ static ssize_t show_pwm_freq(struct device *dev, | |||
| 567 | { | 570 | { |
| 568 | int nr = to_sensor_dev_attr(attr)->index; | 571 | int nr = to_sensor_dev_attr(attr)->index; |
| 569 | struct lm85_data *data = lm85_update_device(dev); | 572 | struct lm85_data *data = lm85_update_device(dev); |
| 570 | return sprintf(buf, "%d\n", FREQ_FROM_REG(data->freq_map, | 573 | int freq; |
| 571 | data->pwm_freq[nr])); | 574 | |
| 575 | if (IS_ADT7468_HFPWM(data)) | ||
| 576 | freq = 22500; | ||
| 577 | else | ||
| 578 | freq = FREQ_FROM_REG(data->freq_map, data->pwm_freq[nr]); | ||
| 579 | |||
| 580 | return sprintf(buf, "%d\n", freq); | ||
| 572 | } | 581 | } |
| 573 | 582 | ||
| 574 | static ssize_t set_pwm_freq(struct device *dev, | 583 | static ssize_t set_pwm_freq(struct device *dev, |
| @@ -580,10 +589,22 @@ static ssize_t set_pwm_freq(struct device *dev, | |||
| 580 | long val = simple_strtol(buf, NULL, 10); | 589 | long val = simple_strtol(buf, NULL, 10); |
| 581 | 590 | ||
| 582 | mutex_lock(&data->update_lock); | 591 | mutex_lock(&data->update_lock); |
| 583 | data->pwm_freq[nr] = FREQ_TO_REG(data->freq_map, val); | 592 | /* The ADT7468 has a special high-frequency PWM output mode, |
| 584 | lm85_write_value(client, LM85_REG_AFAN_RANGE(nr), | 593 | * where all PWM outputs are driven by a 22.5 kHz clock. |
| 585 | (data->zone[nr].range << 4) | 594 | * This might confuse the user, but there's not much we can do. */ |
| 586 | | data->pwm_freq[nr]); | 595 | if (data->type == adt7468 && val >= 11300) { /* High freq. mode */ |
| 596 | data->cfg5 &= ~ADT7468_HFPWM; | ||
| 597 | lm85_write_value(client, ADT7468_REG_CFG5, data->cfg5); | ||
| 598 | } else { /* Low freq. mode */ | ||
| 599 | data->pwm_freq[nr] = FREQ_TO_REG(data->freq_map, val); | ||
| 600 | lm85_write_value(client, LM85_REG_AFAN_RANGE(nr), | ||
| 601 | (data->zone[nr].range << 4) | ||
| 602 | | data->pwm_freq[nr]); | ||
| 603 | if (data->type == adt7468) { | ||
| 604 | data->cfg5 |= ADT7468_HFPWM; | ||
| 605 | lm85_write_value(client, ADT7468_REG_CFG5, data->cfg5); | ||
| 606 | } | ||
| 607 | } | ||
| 587 | mutex_unlock(&data->update_lock); | 608 | mutex_unlock(&data->update_lock); |
| 588 | return count; | 609 | return count; |
| 589 | } | 610 | } |
| @@ -1259,6 +1280,7 @@ static int lm85_probe(struct i2c_client *client, | |||
| 1259 | switch (data->type) { | 1280 | switch (data->type) { |
| 1260 | case adm1027: | 1281 | case adm1027: |
| 1261 | case adt7463: | 1282 | case adt7463: |
| 1283 | case adt7468: | ||
| 1262 | case emc6d100: | 1284 | case emc6d100: |
| 1263 | case emc6d102: | 1285 | case emc6d102: |
| 1264 | data->freq_map = adm1027_freq_map; | 1286 | data->freq_map = adm1027_freq_map; |
diff --git a/drivers/hwmon/lm90.c b/drivers/hwmon/lm90.c index 760ef72eea56..812781c655a7 100644 --- a/drivers/hwmon/lm90.c +++ b/drivers/hwmon/lm90.c | |||
| @@ -28,9 +28,11 @@ | |||
| 28 | * This driver also supports the MAX6657, MAX6658 and MAX6659 sensor | 28 | * This driver also supports the MAX6657, MAX6658 and MAX6659 sensor |
| 29 | * chips made by Maxim. These chips are similar to the LM86. | 29 | * chips made by Maxim. These chips are similar to the LM86. |
| 30 | * Note that there is no easy way to differentiate between the three | 30 | * Note that there is no easy way to differentiate between the three |
| 31 | * variants. The extra address and features of the MAX6659 are not | 31 | * variants. We use the device address to detect MAX6659, which will result |
| 32 | * supported by this driver. These chips lack the remote temperature | 32 | * in a detection as max6657 if it is on address 0x4c. The extra address |
| 33 | * offset feature. | 33 | * and features of the MAX6659 are only supported if the chip is configured |
| 34 | * explicitly as max6659, or if its address is not 0x4c. | ||
| 35 | * These chips lack the remote temperature offset feature. | ||
| 34 | * | 36 | * |
| 35 | * This driver also supports the MAX6646, MAX6647, MAX6648, MAX6649 and | 37 | * This driver also supports the MAX6646, MAX6647, MAX6648, MAX6649 and |
| 36 | * MAX6692 chips made by Maxim. These are again similar to the LM86, | 38 | * MAX6692 chips made by Maxim. These are again similar to the LM86, |
| @@ -42,6 +44,11 @@ | |||
| 42 | * chips. The MAX6680 and MAX6681 only differ in the pinout so they can | 44 | * chips. The MAX6680 and MAX6681 only differ in the pinout so they can |
| 43 | * be treated identically. | 45 | * be treated identically. |
| 44 | * | 46 | * |
| 47 | * This driver also supports the MAX6695 and MAX6696, two other sensor | ||
| 48 | * chips made by Maxim. These are also quite similar to other Maxim | ||
| 49 | * chips, but support three temperature sensors instead of two. MAX6695 | ||
| 50 | * and MAX6696 only differ in the pinout so they can be treated identically. | ||
| 51 | * | ||
| 45 | * This driver also supports the ADT7461 chip from Analog Devices. | 52 | * This driver also supports the ADT7461 chip from Analog Devices. |
| 46 | * It's supported in both compatibility and extended mode. It is mostly | 53 | * It's supported in both compatibility and extended mode. It is mostly |
| 47 | * compatible with LM90 except for a data format difference for the | 54 | * compatible with LM90 except for a data format difference for the |
| @@ -81,11 +88,11 @@ | |||
| 81 | * Addresses to scan | 88 | * Addresses to scan |
| 82 | * Address is fully defined internally and cannot be changed except for | 89 | * Address is fully defined internally and cannot be changed except for |
| 83 | * MAX6659, MAX6680 and MAX6681. | 90 | * MAX6659, MAX6680 and MAX6681. |
| 84 | * LM86, LM89, LM90, LM99, ADM1032, ADM1032-1, ADT7461, MAX6649, MAX6657 | 91 | * LM86, LM89, LM90, LM99, ADM1032, ADM1032-1, ADT7461, MAX6649, MAX6657, |
| 85 | * and MAX6658 have address 0x4c. | 92 | * MAX6658 and W83L771 have address 0x4c. |
| 86 | * ADM1032-2, ADT7461-2, LM89-1, LM99-1 and MAX6646 have address 0x4d. | 93 | * ADM1032-2, ADT7461-2, LM89-1, LM99-1 and MAX6646 have address 0x4d. |
| 87 | * MAX6647 has address 0x4e. | 94 | * MAX6647 has address 0x4e. |
| 88 | * MAX6659 can have address 0x4c, 0x4d or 0x4e (unsupported). | 95 | * MAX6659 can have address 0x4c, 0x4d or 0x4e. |
| 89 | * MAX6680 and MAX6681 can have address 0x18, 0x19, 0x1a, 0x29, 0x2a, 0x2b, | 96 | * MAX6680 and MAX6681 can have address 0x18, 0x19, 0x1a, 0x29, 0x2a, 0x2b, |
| 90 | * 0x4c, 0x4d or 0x4e. | 97 | * 0x4c, 0x4d or 0x4e. |
| 91 | */ | 98 | */ |
| @@ -93,8 +100,8 @@ | |||
| 93 | static const unsigned short normal_i2c[] = { | 100 | static const unsigned short normal_i2c[] = { |
| 94 | 0x18, 0x19, 0x1a, 0x29, 0x2a, 0x2b, 0x4c, 0x4d, 0x4e, I2C_CLIENT_END }; | 101 | 0x18, 0x19, 0x1a, 0x29, 0x2a, 0x2b, 0x4c, 0x4d, 0x4e, I2C_CLIENT_END }; |
| 95 | 102 | ||
| 96 | enum chips { lm90, adm1032, lm99, lm86, max6657, adt7461, max6680, max6646, | 103 | enum chips { lm90, adm1032, lm99, lm86, max6657, max6659, adt7461, max6680, |
| 97 | w83l771 }; | 104 | max6646, w83l771, max6696 }; |
| 98 | 105 | ||
| 99 | /* | 106 | /* |
| 100 | * The LM90 registers | 107 | * The LM90 registers |
| @@ -135,26 +142,30 @@ enum chips { lm90, adm1032, lm99, lm86, max6657, adt7461, max6680, max6646, | |||
| 135 | #define LM90_REG_R_TCRIT_HYST 0x21 | 142 | #define LM90_REG_R_TCRIT_HYST 0x21 |
| 136 | #define LM90_REG_W_TCRIT_HYST 0x21 | 143 | #define LM90_REG_W_TCRIT_HYST 0x21 |
| 137 | 144 | ||
| 138 | /* MAX6646/6647/6649/6657/6658/6659 registers */ | 145 | /* MAX6646/6647/6649/6657/6658/6659/6695/6696 registers */ |
| 139 | 146 | ||
| 140 | #define MAX6657_REG_R_LOCAL_TEMPL 0x11 | 147 | #define MAX6657_REG_R_LOCAL_TEMPL 0x11 |
| 148 | #define MAX6696_REG_R_STATUS2 0x12 | ||
| 149 | #define MAX6659_REG_R_REMOTE_EMERG 0x16 | ||
| 150 | #define MAX6659_REG_W_REMOTE_EMERG 0x16 | ||
| 151 | #define MAX6659_REG_R_LOCAL_EMERG 0x17 | ||
| 152 | #define MAX6659_REG_W_LOCAL_EMERG 0x17 | ||
| 141 | 153 | ||
| 142 | /* | 154 | #define LM90_DEF_CONVRATE_RVAL 6 /* Def conversion rate register value */ |
| 143 | * Device flags | 155 | #define LM90_MAX_CONVRATE_MS 16000 /* Maximum conversion rate in ms */ |
| 144 | */ | ||
| 145 | #define LM90_FLAG_ADT7461_EXT 0x01 /* ADT7461 extended mode */ | ||
| 146 | 156 | ||
| 147 | /* | 157 | /* |
| 148 | * Functions declaration | 158 | * Device flags |
| 149 | */ | 159 | */ |
| 150 | 160 | #define LM90_FLAG_ADT7461_EXT (1 << 0) /* ADT7461 extended mode */ | |
| 151 | static int lm90_detect(struct i2c_client *client, struct i2c_board_info *info); | 161 | /* Device features */ |
| 152 | static int lm90_probe(struct i2c_client *client, | 162 | #define LM90_HAVE_OFFSET (1 << 1) /* temperature offset register */ |
| 153 | const struct i2c_device_id *id); | 163 | #define LM90_HAVE_LOCAL_EXT (1 << 2) /* extended local temperature */ |
| 154 | static void lm90_init_client(struct i2c_client *client); | 164 | #define LM90_HAVE_REM_LIMIT_EXT (1 << 3) /* extended remote limit */ |
| 155 | static void lm90_alert(struct i2c_client *client, unsigned int flag); | 165 | #define LM90_HAVE_EMERGENCY (1 << 4) /* 3rd upper (emergency) limit */ |
| 156 | static int lm90_remove(struct i2c_client *client); | 166 | #define LM90_HAVE_EMERGENCY_ALARM (1 << 5)/* emergency alarm */ |
| 157 | static struct lm90_data *lm90_update_device(struct device *dev); | 167 | #define LM90_HAVE_TEMP3 (1 << 6) /* 3rd temperature sensor */ |
| 168 | #define LM90_HAVE_BROKEN_ALERT (1 << 7) /* Broken alert */ | ||
| 158 | 169 | ||
| 159 | /* | 170 | /* |
| 160 | * Driver data (common to all clients) | 171 | * Driver data (common to all clients) |
| @@ -172,25 +183,85 @@ static const struct i2c_device_id lm90_id[] = { | |||
| 172 | { "max6649", max6646 }, | 183 | { "max6649", max6646 }, |
| 173 | { "max6657", max6657 }, | 184 | { "max6657", max6657 }, |
| 174 | { "max6658", max6657 }, | 185 | { "max6658", max6657 }, |
| 175 | { "max6659", max6657 }, | 186 | { "max6659", max6659 }, |
| 176 | { "max6680", max6680 }, | 187 | { "max6680", max6680 }, |
| 177 | { "max6681", max6680 }, | 188 | { "max6681", max6680 }, |
| 189 | { "max6695", max6696 }, | ||
| 190 | { "max6696", max6696 }, | ||
| 178 | { "w83l771", w83l771 }, | 191 | { "w83l771", w83l771 }, |
| 179 | { } | 192 | { } |
| 180 | }; | 193 | }; |
| 181 | MODULE_DEVICE_TABLE(i2c, lm90_id); | 194 | MODULE_DEVICE_TABLE(i2c, lm90_id); |
| 182 | 195 | ||
| 183 | static struct i2c_driver lm90_driver = { | 196 | /* |
| 184 | .class = I2C_CLASS_HWMON, | 197 | * chip type specific parameters |
| 185 | .driver = { | 198 | */ |
| 186 | .name = "lm90", | 199 | struct lm90_params { |
| 200 | u32 flags; /* Capabilities */ | ||
| 201 | u16 alert_alarms; /* Which alarm bits trigger ALERT# */ | ||
| 202 | /* Upper 8 bits for max6695/96 */ | ||
| 203 | u8 max_convrate; /* Maximum conversion rate register value */ | ||
| 204 | }; | ||
| 205 | |||
| 206 | static const struct lm90_params lm90_params[] = { | ||
| 207 | [adm1032] = { | ||
| 208 | .flags = LM90_HAVE_OFFSET | LM90_HAVE_REM_LIMIT_EXT | ||
| 209 | | LM90_HAVE_BROKEN_ALERT, | ||
| 210 | .alert_alarms = 0x7c, | ||
| 211 | .max_convrate = 10, | ||
| 212 | }, | ||
| 213 | [adt7461] = { | ||
| 214 | .flags = LM90_HAVE_OFFSET | LM90_HAVE_REM_LIMIT_EXT | ||
| 215 | | LM90_HAVE_BROKEN_ALERT, | ||
| 216 | .alert_alarms = 0x7c, | ||
| 217 | .max_convrate = 10, | ||
| 218 | }, | ||
| 219 | [lm86] = { | ||
| 220 | .flags = LM90_HAVE_OFFSET | LM90_HAVE_REM_LIMIT_EXT, | ||
| 221 | .alert_alarms = 0x7b, | ||
| 222 | .max_convrate = 9, | ||
| 223 | }, | ||
| 224 | [lm90] = { | ||
| 225 | .flags = LM90_HAVE_OFFSET | LM90_HAVE_REM_LIMIT_EXT, | ||
| 226 | .alert_alarms = 0x7b, | ||
| 227 | .max_convrate = 9, | ||
| 228 | }, | ||
| 229 | [lm99] = { | ||
| 230 | .flags = LM90_HAVE_OFFSET | LM90_HAVE_REM_LIMIT_EXT, | ||
| 231 | .alert_alarms = 0x7b, | ||
| 232 | .max_convrate = 9, | ||
| 233 | }, | ||
| 234 | [max6646] = { | ||
| 235 | .flags = LM90_HAVE_LOCAL_EXT, | ||
| 236 | .alert_alarms = 0x7c, | ||
| 237 | .max_convrate = 6, | ||
| 238 | }, | ||
| 239 | [max6657] = { | ||
| 240 | .flags = LM90_HAVE_LOCAL_EXT, | ||
| 241 | .alert_alarms = 0x7c, | ||
| 242 | .max_convrate = 8, | ||
| 243 | }, | ||
| 244 | [max6659] = { | ||
| 245 | .flags = LM90_HAVE_LOCAL_EXT | LM90_HAVE_EMERGENCY, | ||
| 246 | .alert_alarms = 0x7c, | ||
| 247 | .max_convrate = 8, | ||
| 248 | }, | ||
| 249 | [max6680] = { | ||
| 250 | .flags = LM90_HAVE_OFFSET, | ||
| 251 | .alert_alarms = 0x7c, | ||
| 252 | .max_convrate = 7, | ||
| 253 | }, | ||
| 254 | [max6696] = { | ||
| 255 | .flags = LM90_HAVE_LOCAL_EXT | LM90_HAVE_EMERGENCY | ||
| 256 | | LM90_HAVE_EMERGENCY_ALARM | LM90_HAVE_TEMP3, | ||
| 257 | .alert_alarms = 0x187c, | ||
| 258 | .max_convrate = 6, | ||
| 259 | }, | ||
| 260 | [w83l771] = { | ||
| 261 | .flags = LM90_HAVE_OFFSET | LM90_HAVE_REM_LIMIT_EXT, | ||
| 262 | .alert_alarms = 0x7c, | ||
| 263 | .max_convrate = 8, | ||
| 187 | }, | 264 | }, |
| 188 | .probe = lm90_probe, | ||
| 189 | .remove = lm90_remove, | ||
| 190 | .alert = lm90_alert, | ||
| 191 | .id_table = lm90_id, | ||
| 192 | .detect = lm90_detect, | ||
| 193 | .address_list = normal_i2c, | ||
| 194 | }; | 265 | }; |
| 195 | 266 | ||
| 196 | /* | 267 | /* |
| @@ -203,26 +274,268 @@ struct lm90_data { | |||
| 203 | char valid; /* zero until following fields are valid */ | 274 | char valid; /* zero until following fields are valid */ |
| 204 | unsigned long last_updated; /* in jiffies */ | 275 | unsigned long last_updated; /* in jiffies */ |
| 205 | int kind; | 276 | int kind; |
| 206 | int flags; | 277 | u32 flags; |
| 278 | |||
| 279 | int update_interval; /* in milliseconds */ | ||
| 207 | 280 | ||
| 208 | u8 config_orig; /* Original configuration register value */ | 281 | u8 config_orig; /* Original configuration register value */ |
| 209 | u8 alert_alarms; /* Which alarm bits trigger ALERT# */ | 282 | u8 convrate_orig; /* Original conversion rate register value */ |
| 283 | u16 alert_alarms; /* Which alarm bits trigger ALERT# */ | ||
| 284 | /* Upper 8 bits for max6695/96 */ | ||
| 285 | u8 max_convrate; /* Maximum conversion rate */ | ||
| 210 | 286 | ||
| 211 | /* registers values */ | 287 | /* registers values */ |
| 212 | s8 temp8[4]; /* 0: local low limit | 288 | s8 temp8[8]; /* 0: local low limit |
| 213 | 1: local high limit | 289 | 1: local high limit |
| 214 | 2: local critical limit | 290 | 2: local critical limit |
| 215 | 3: remote critical limit */ | 291 | 3: remote critical limit |
| 216 | s16 temp11[5]; /* 0: remote input | 292 | 4: local emergency limit (max6659 and max6695/96) |
| 293 | 5: remote emergency limit (max6659 and max6695/96) | ||
| 294 | 6: remote 2 critical limit (max6695/96 only) | ||
| 295 | 7: remote 2 emergency limit (max6695/96 only) */ | ||
| 296 | s16 temp11[8]; /* 0: remote input | ||
| 217 | 1: remote low limit | 297 | 1: remote low limit |
| 218 | 2: remote high limit | 298 | 2: remote high limit |
| 219 | 3: remote offset (except max6646 and max6657) | 299 | 3: remote offset (except max6646, max6657/58/59, |
| 220 | 4: local input */ | 300 | and max6695/96) |
| 301 | 4: local input | ||
| 302 | 5: remote 2 input (max6695/96 only) | ||
| 303 | 6: remote 2 low limit (max6695/96 only) | ||
| 304 | 7: remote 2 high limit (ma6695/96 only) */ | ||
| 221 | u8 temp_hyst; | 305 | u8 temp_hyst; |
| 222 | u8 alarms; /* bitvector */ | 306 | u16 alarms; /* bitvector (upper 8 bits for max6695/96) */ |
| 223 | }; | 307 | }; |
| 224 | 308 | ||
| 225 | /* | 309 | /* |
| 310 | * Support functions | ||
| 311 | */ | ||
| 312 | |||
| 313 | /* | ||
| 314 | * The ADM1032 supports PEC but not on write byte transactions, so we need | ||
| 315 | * to explicitly ask for a transaction without PEC. | ||
| 316 | */ | ||
| 317 | static inline s32 adm1032_write_byte(struct i2c_client *client, u8 value) | ||
| 318 | { | ||
| 319 | return i2c_smbus_xfer(client->adapter, client->addr, | ||
| 320 | client->flags & ~I2C_CLIENT_PEC, | ||
| 321 | I2C_SMBUS_WRITE, value, I2C_SMBUS_BYTE, NULL); | ||
| 322 | } | ||
| 323 | |||
| 324 | /* | ||
| 325 | * It is assumed that client->update_lock is held (unless we are in | ||
| 326 | * detection or initialization steps). This matters when PEC is enabled, | ||
| 327 | * because we don't want the address pointer to change between the write | ||
| 328 | * byte and the read byte transactions. | ||
| 329 | */ | ||
| 330 | static int lm90_read_reg(struct i2c_client *client, u8 reg, u8 *value) | ||
| 331 | { | ||
| 332 | int err; | ||
| 333 | |||
| 334 | if (client->flags & I2C_CLIENT_PEC) { | ||
| 335 | err = adm1032_write_byte(client, reg); | ||
| 336 | if (err >= 0) | ||
| 337 | err = i2c_smbus_read_byte(client); | ||
| 338 | } else | ||
| 339 | err = i2c_smbus_read_byte_data(client, reg); | ||
| 340 | |||
| 341 | if (err < 0) { | ||
| 342 | dev_warn(&client->dev, "Register %#02x read failed (%d)\n", | ||
| 343 | reg, err); | ||
| 344 | return err; | ||
| 345 | } | ||
| 346 | *value = err; | ||
| 347 | |||
| 348 | return 0; | ||
| 349 | } | ||
| 350 | |||
| 351 | static int lm90_read16(struct i2c_client *client, u8 regh, u8 regl, u16 *value) | ||
| 352 | { | ||
| 353 | int err; | ||
| 354 | u8 oldh, newh, l; | ||
| 355 | |||
| 356 | /* | ||
| 357 | * There is a trick here. We have to read two registers to have the | ||
| 358 | * sensor temperature, but we have to beware a conversion could occur | ||
| 359 | * inbetween the readings. The datasheet says we should either use | ||
| 360 | * the one-shot conversion register, which we don't want to do | ||
| 361 | * (disables hardware monitoring) or monitor the busy bit, which is | ||
| 362 | * impossible (we can't read the values and monitor that bit at the | ||
| 363 | * exact same time). So the solution used here is to read the high | ||
| 364 | * byte once, then the low byte, then the high byte again. If the new | ||
| 365 | * high byte matches the old one, then we have a valid reading. Else | ||
| 366 | * we have to read the low byte again, and now we believe we have a | ||
| 367 | * correct reading. | ||
| 368 | */ | ||
| 369 | if ((err = lm90_read_reg(client, regh, &oldh)) | ||
| 370 | || (err = lm90_read_reg(client, regl, &l)) | ||
| 371 | || (err = lm90_read_reg(client, regh, &newh))) | ||
| 372 | return err; | ||
| 373 | if (oldh != newh) { | ||
| 374 | err = lm90_read_reg(client, regl, &l); | ||
| 375 | if (err) | ||
| 376 | return err; | ||
| 377 | } | ||
| 378 | *value = (newh << 8) | l; | ||
| 379 | |||
| 380 | return 0; | ||
| 381 | } | ||
| 382 | |||
| 383 | /* | ||
| 384 | * client->update_lock must be held when calling this function (unless we are | ||
| 385 | * in detection or initialization steps), and while a remote channel other | ||
| 386 | * than channel 0 is selected. Also, calling code must make sure to re-select | ||
| 387 | * external channel 0 before releasing the lock. This is necessary because | ||
| 388 | * various registers have different meanings as a result of selecting a | ||
| 389 | * non-default remote channel. | ||
| 390 | */ | ||
| 391 | static inline void lm90_select_remote_channel(struct i2c_client *client, | ||
| 392 | struct lm90_data *data, | ||
| 393 | int channel) | ||
| 394 | { | ||
| 395 | u8 config; | ||
| 396 | |||
| 397 | if (data->kind == max6696) { | ||
| 398 | lm90_read_reg(client, LM90_REG_R_CONFIG1, &config); | ||
| 399 | config &= ~0x08; | ||
| 400 | if (channel) | ||
| 401 | config |= 0x08; | ||
| 402 | i2c_smbus_write_byte_data(client, LM90_REG_W_CONFIG1, | ||
| 403 | config); | ||
| 404 | } | ||
| 405 | } | ||
| 406 | |||
| 407 | /* | ||
| 408 | * Set conversion rate. | ||
| 409 | * client->update_lock must be held when calling this function (unless we are | ||
| 410 | * in detection or initialization steps). | ||
| 411 | */ | ||
| 412 | static void lm90_set_convrate(struct i2c_client *client, struct lm90_data *data, | ||
| 413 | unsigned int interval) | ||
| 414 | { | ||
| 415 | int i; | ||
| 416 | unsigned int update_interval; | ||
| 417 | |||
| 418 | /* Shift calculations to avoid rounding errors */ | ||
| 419 | interval <<= 6; | ||
| 420 | |||
| 421 | /* find the nearest update rate */ | ||
| 422 | for (i = 0, update_interval = LM90_MAX_CONVRATE_MS << 6; | ||
| 423 | i < data->max_convrate; i++, update_interval >>= 1) | ||
| 424 | if (interval >= update_interval * 3 / 4) | ||
| 425 | break; | ||
| 426 | |||
| 427 | i2c_smbus_write_byte_data(client, LM90_REG_W_CONVRATE, i); | ||
| 428 | data->update_interval = DIV_ROUND_CLOSEST(update_interval, 64); | ||
| 429 | } | ||
| 430 | |||
| 431 | static struct lm90_data *lm90_update_device(struct device *dev) | ||
| 432 | { | ||
| 433 | struct i2c_client *client = to_i2c_client(dev); | ||
| 434 | struct lm90_data *data = i2c_get_clientdata(client); | ||
| 435 | unsigned long next_update; | ||
| 436 | |||
| 437 | mutex_lock(&data->update_lock); | ||
| 438 | |||
| 439 | next_update = data->last_updated | ||
| 440 | + msecs_to_jiffies(data->update_interval) + 1; | ||
| 441 | if (time_after(jiffies, next_update) || !data->valid) { | ||
| 442 | u8 h, l; | ||
| 443 | u8 alarms; | ||
| 444 | |||
| 445 | dev_dbg(&client->dev, "Updating lm90 data.\n"); | ||
| 446 | lm90_read_reg(client, LM90_REG_R_LOCAL_LOW, &data->temp8[0]); | ||
| 447 | lm90_read_reg(client, LM90_REG_R_LOCAL_HIGH, &data->temp8[1]); | ||
| 448 | lm90_read_reg(client, LM90_REG_R_LOCAL_CRIT, &data->temp8[2]); | ||
| 449 | lm90_read_reg(client, LM90_REG_R_REMOTE_CRIT, &data->temp8[3]); | ||
| 450 | lm90_read_reg(client, LM90_REG_R_TCRIT_HYST, &data->temp_hyst); | ||
| 451 | |||
| 452 | if (data->flags & LM90_HAVE_LOCAL_EXT) { | ||
| 453 | lm90_read16(client, LM90_REG_R_LOCAL_TEMP, | ||
| 454 | MAX6657_REG_R_LOCAL_TEMPL, | ||
| 455 | &data->temp11[4]); | ||
| 456 | } else { | ||
| 457 | if (lm90_read_reg(client, LM90_REG_R_LOCAL_TEMP, | ||
| 458 | &h) == 0) | ||
| 459 | data->temp11[4] = h << 8; | ||
| 460 | } | ||
| 461 | lm90_read16(client, LM90_REG_R_REMOTE_TEMPH, | ||
| 462 | LM90_REG_R_REMOTE_TEMPL, &data->temp11[0]); | ||
| 463 | |||
| 464 | if (lm90_read_reg(client, LM90_REG_R_REMOTE_LOWH, &h) == 0) { | ||
| 465 | data->temp11[1] = h << 8; | ||
| 466 | if ((data->flags & LM90_HAVE_REM_LIMIT_EXT) | ||
| 467 | && lm90_read_reg(client, LM90_REG_R_REMOTE_LOWL, | ||
| 468 | &l) == 0) | ||
| 469 | data->temp11[1] |= l; | ||
| 470 | } | ||
| 471 | if (lm90_read_reg(client, LM90_REG_R_REMOTE_HIGHH, &h) == 0) { | ||
| 472 | data->temp11[2] = h << 8; | ||
| 473 | if ((data->flags & LM90_HAVE_REM_LIMIT_EXT) | ||
| 474 | && lm90_read_reg(client, LM90_REG_R_REMOTE_HIGHL, | ||
| 475 | &l) == 0) | ||
| 476 | data->temp11[2] |= l; | ||
| 477 | } | ||
| 478 | |||
| 479 | if (data->flags & LM90_HAVE_OFFSET) { | ||
| 480 | if (lm90_read_reg(client, LM90_REG_R_REMOTE_OFFSH, | ||
| 481 | &h) == 0 | ||
| 482 | && lm90_read_reg(client, LM90_REG_R_REMOTE_OFFSL, | ||
| 483 | &l) == 0) | ||
| 484 | data->temp11[3] = (h << 8) | l; | ||
| 485 | } | ||
| 486 | if (data->flags & LM90_HAVE_EMERGENCY) { | ||
| 487 | lm90_read_reg(client, MAX6659_REG_R_LOCAL_EMERG, | ||
| 488 | &data->temp8[4]); | ||
| 489 | lm90_read_reg(client, MAX6659_REG_R_REMOTE_EMERG, | ||
| 490 | &data->temp8[5]); | ||
| 491 | } | ||
| 492 | lm90_read_reg(client, LM90_REG_R_STATUS, &alarms); | ||
| 493 | data->alarms = alarms; /* save as 16 bit value */ | ||
| 494 | |||
| 495 | if (data->kind == max6696) { | ||
| 496 | lm90_select_remote_channel(client, data, 1); | ||
| 497 | lm90_read_reg(client, LM90_REG_R_REMOTE_CRIT, | ||
| 498 | &data->temp8[6]); | ||
| 499 | lm90_read_reg(client, MAX6659_REG_R_REMOTE_EMERG, | ||
| 500 | &data->temp8[7]); | ||
| 501 | lm90_read16(client, LM90_REG_R_REMOTE_TEMPH, | ||
| 502 | LM90_REG_R_REMOTE_TEMPL, &data->temp11[5]); | ||
| 503 | if (!lm90_read_reg(client, LM90_REG_R_REMOTE_LOWH, &h)) | ||
| 504 | data->temp11[6] = h << 8; | ||
| 505 | if (!lm90_read_reg(client, LM90_REG_R_REMOTE_HIGHH, &h)) | ||
| 506 | data->temp11[7] = h << 8; | ||
| 507 | lm90_select_remote_channel(client, data, 0); | ||
| 508 | |||
| 509 | if (!lm90_read_reg(client, MAX6696_REG_R_STATUS2, | ||
| 510 | &alarms)) | ||
| 511 | data->alarms |= alarms << 8; | ||
| 512 | } | ||
| 513 | |||
| 514 | /* Re-enable ALERT# output if it was originally enabled and | ||
| 515 | * relevant alarms are all clear */ | ||
| 516 | if ((data->config_orig & 0x80) == 0 | ||
| 517 | && (data->alarms & data->alert_alarms) == 0) { | ||
| 518 | u8 config; | ||
| 519 | |||
| 520 | lm90_read_reg(client, LM90_REG_R_CONFIG1, &config); | ||
| 521 | if (config & 0x80) { | ||
| 522 | dev_dbg(&client->dev, "Re-enabling ALERT#\n"); | ||
| 523 | i2c_smbus_write_byte_data(client, | ||
| 524 | LM90_REG_W_CONFIG1, | ||
| 525 | config & ~0x80); | ||
| 526 | } | ||
| 527 | } | ||
| 528 | |||
| 529 | data->last_updated = jiffies; | ||
| 530 | data->valid = 1; | ||
| 531 | } | ||
| 532 | |||
| 533 | mutex_unlock(&data->update_lock); | ||
| 534 | |||
| 535 | return data; | ||
| 536 | } | ||
| 537 | |||
| 538 | /* | ||
| 226 | * Conversions | 539 | * Conversions |
| 227 | * For local temperatures and limits, critical limits and the hysteresis | 540 | * For local temperatures and limits, critical limits and the hysteresis |
| 228 | * value, the LM90 uses signed 8-bit values with LSB = 1 degree Celsius. | 541 | * value, the LM90 uses signed 8-bit values with LSB = 1 degree Celsius. |
| @@ -377,18 +690,27 @@ static ssize_t show_temp8(struct device *dev, struct device_attribute *devattr, | |||
| 377 | static ssize_t set_temp8(struct device *dev, struct device_attribute *devattr, | 690 | static ssize_t set_temp8(struct device *dev, struct device_attribute *devattr, |
| 378 | const char *buf, size_t count) | 691 | const char *buf, size_t count) |
| 379 | { | 692 | { |
| 380 | static const u8 reg[4] = { | 693 | static const u8 reg[8] = { |
| 381 | LM90_REG_W_LOCAL_LOW, | 694 | LM90_REG_W_LOCAL_LOW, |
| 382 | LM90_REG_W_LOCAL_HIGH, | 695 | LM90_REG_W_LOCAL_HIGH, |
| 383 | LM90_REG_W_LOCAL_CRIT, | 696 | LM90_REG_W_LOCAL_CRIT, |
| 384 | LM90_REG_W_REMOTE_CRIT, | 697 | LM90_REG_W_REMOTE_CRIT, |
| 698 | MAX6659_REG_W_LOCAL_EMERG, | ||
| 699 | MAX6659_REG_W_REMOTE_EMERG, | ||
| 700 | LM90_REG_W_REMOTE_CRIT, | ||
| 701 | MAX6659_REG_W_REMOTE_EMERG, | ||
| 385 | }; | 702 | }; |
| 386 | 703 | ||
| 387 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); | 704 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); |
| 388 | struct i2c_client *client = to_i2c_client(dev); | 705 | struct i2c_client *client = to_i2c_client(dev); |
| 389 | struct lm90_data *data = i2c_get_clientdata(client); | 706 | struct lm90_data *data = i2c_get_clientdata(client); |
| 390 | long val = simple_strtol(buf, NULL, 10); | ||
| 391 | int nr = attr->index; | 707 | int nr = attr->index; |
| 708 | long val; | ||
| 709 | int err; | ||
| 710 | |||
| 711 | err = strict_strtol(buf, 10, &val); | ||
| 712 | if (err < 0) | ||
| 713 | return err; | ||
| 392 | 714 | ||
| 393 | /* +16 degrees offset for temp2 for the LM99 */ | 715 | /* +16 degrees offset for temp2 for the LM99 */ |
| 394 | if (data->kind == lm99 && attr->index == 3) | 716 | if (data->kind == lm99 && attr->index == 3) |
| @@ -401,7 +723,11 @@ static ssize_t set_temp8(struct device *dev, struct device_attribute *devattr, | |||
| 401 | data->temp8[nr] = temp_to_u8(val); | 723 | data->temp8[nr] = temp_to_u8(val); |
| 402 | else | 724 | else |
| 403 | data->temp8[nr] = temp_to_s8(val); | 725 | data->temp8[nr] = temp_to_s8(val); |
| 726 | |||
| 727 | lm90_select_remote_channel(client, data, nr >= 6); | ||
| 404 | i2c_smbus_write_byte_data(client, reg[nr], data->temp8[nr]); | 728 | i2c_smbus_write_byte_data(client, reg[nr], data->temp8[nr]); |
| 729 | lm90_select_remote_channel(client, data, 0); | ||
| 730 | |||
| 405 | mutex_unlock(&data->update_lock); | 731 | mutex_unlock(&data->update_lock); |
| 406 | return count; | 732 | return count; |
| 407 | } | 733 | } |
| @@ -409,7 +735,7 @@ static ssize_t set_temp8(struct device *dev, struct device_attribute *devattr, | |||
| 409 | static ssize_t show_temp11(struct device *dev, struct device_attribute *devattr, | 735 | static ssize_t show_temp11(struct device *dev, struct device_attribute *devattr, |
| 410 | char *buf) | 736 | char *buf) |
| 411 | { | 737 | { |
| 412 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); | 738 | struct sensor_device_attribute_2 *attr = to_sensor_dev_attr_2(devattr); |
| 413 | struct lm90_data *data = lm90_update_device(dev); | 739 | struct lm90_data *data = lm90_update_device(dev); |
| 414 | int temp; | 740 | int temp; |
| 415 | 741 | ||
| @@ -430,46 +756,58 @@ static ssize_t show_temp11(struct device *dev, struct device_attribute *devattr, | |||
| 430 | static ssize_t set_temp11(struct device *dev, struct device_attribute *devattr, | 756 | static ssize_t set_temp11(struct device *dev, struct device_attribute *devattr, |
| 431 | const char *buf, size_t count) | 757 | const char *buf, size_t count) |
| 432 | { | 758 | { |
| 433 | static const u8 reg[6] = { | 759 | struct { |
| 434 | LM90_REG_W_REMOTE_LOWH, | 760 | u8 high; |
| 435 | LM90_REG_W_REMOTE_LOWL, | 761 | u8 low; |
| 436 | LM90_REG_W_REMOTE_HIGHH, | 762 | int channel; |
| 437 | LM90_REG_W_REMOTE_HIGHL, | 763 | } reg[5] = { |
| 438 | LM90_REG_W_REMOTE_OFFSH, | 764 | { LM90_REG_W_REMOTE_LOWH, LM90_REG_W_REMOTE_LOWL, 0 }, |
| 439 | LM90_REG_W_REMOTE_OFFSL, | 765 | { LM90_REG_W_REMOTE_HIGHH, LM90_REG_W_REMOTE_HIGHL, 0 }, |
| 766 | { LM90_REG_W_REMOTE_OFFSH, LM90_REG_W_REMOTE_OFFSL, 0 }, | ||
| 767 | { LM90_REG_W_REMOTE_LOWH, LM90_REG_W_REMOTE_LOWL, 1 }, | ||
| 768 | { LM90_REG_W_REMOTE_HIGHH, LM90_REG_W_REMOTE_HIGHL, 1 } | ||
| 440 | }; | 769 | }; |
| 441 | 770 | ||
| 442 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); | 771 | struct sensor_device_attribute_2 *attr = to_sensor_dev_attr_2(devattr); |
| 443 | struct i2c_client *client = to_i2c_client(dev); | 772 | struct i2c_client *client = to_i2c_client(dev); |
| 444 | struct lm90_data *data = i2c_get_clientdata(client); | 773 | struct lm90_data *data = i2c_get_clientdata(client); |
| 445 | long val = simple_strtol(buf, NULL, 10); | 774 | int nr = attr->nr; |
| 446 | int nr = attr->index; | 775 | int index = attr->index; |
| 776 | long val; | ||
| 777 | int err; | ||
| 778 | |||
| 779 | err = strict_strtol(buf, 10, &val); | ||
| 780 | if (err < 0) | ||
| 781 | return err; | ||
| 447 | 782 | ||
| 448 | /* +16 degrees offset for temp2 for the LM99 */ | 783 | /* +16 degrees offset for temp2 for the LM99 */ |
| 449 | if (data->kind == lm99 && attr->index <= 2) | 784 | if (data->kind == lm99 && index <= 2) |
| 450 | val -= 16000; | 785 | val -= 16000; |
| 451 | 786 | ||
| 452 | mutex_lock(&data->update_lock); | 787 | mutex_lock(&data->update_lock); |
| 453 | if (data->kind == adt7461) | 788 | if (data->kind == adt7461) |
| 454 | data->temp11[nr] = temp_to_u16_adt7461(data, val); | 789 | data->temp11[index] = temp_to_u16_adt7461(data, val); |
| 455 | else if (data->kind == max6657 || data->kind == max6680) | ||
| 456 | data->temp11[nr] = temp_to_s8(val) << 8; | ||
| 457 | else if (data->kind == max6646) | 790 | else if (data->kind == max6646) |
| 458 | data->temp11[nr] = temp_to_u8(val) << 8; | 791 | data->temp11[index] = temp_to_u8(val) << 8; |
| 792 | else if (data->flags & LM90_HAVE_REM_LIMIT_EXT) | ||
| 793 | data->temp11[index] = temp_to_s16(val); | ||
| 459 | else | 794 | else |
| 460 | data->temp11[nr] = temp_to_s16(val); | 795 | data->temp11[index] = temp_to_s8(val) << 8; |
| 461 | 796 | ||
| 462 | i2c_smbus_write_byte_data(client, reg[(nr - 1) * 2], | 797 | lm90_select_remote_channel(client, data, reg[nr].channel); |
| 463 | data->temp11[nr] >> 8); | 798 | i2c_smbus_write_byte_data(client, reg[nr].high, |
| 464 | if (data->kind != max6657 && data->kind != max6680 | 799 | data->temp11[index] >> 8); |
| 465 | && data->kind != max6646) | 800 | if (data->flags & LM90_HAVE_REM_LIMIT_EXT) |
| 466 | i2c_smbus_write_byte_data(client, reg[(nr - 1) * 2 + 1], | 801 | i2c_smbus_write_byte_data(client, reg[nr].low, |
| 467 | data->temp11[nr] & 0xff); | 802 | data->temp11[index] & 0xff); |
| 803 | lm90_select_remote_channel(client, data, 0); | ||
| 804 | |||
| 468 | mutex_unlock(&data->update_lock); | 805 | mutex_unlock(&data->update_lock); |
| 469 | return count; | 806 | return count; |
| 470 | } | 807 | } |
| 471 | 808 | ||
| 472 | static ssize_t show_temphyst(struct device *dev, struct device_attribute *devattr, | 809 | static ssize_t show_temphyst(struct device *dev, |
| 810 | struct device_attribute *devattr, | ||
| 473 | char *buf) | 811 | char *buf) |
| 474 | { | 812 | { |
| 475 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); | 813 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); |
| @@ -495,9 +833,14 @@ static ssize_t set_temphyst(struct device *dev, struct device_attribute *dummy, | |||
| 495 | { | 833 | { |
| 496 | struct i2c_client *client = to_i2c_client(dev); | 834 | struct i2c_client *client = to_i2c_client(dev); |
| 497 | struct lm90_data *data = i2c_get_clientdata(client); | 835 | struct lm90_data *data = i2c_get_clientdata(client); |
| 498 | long val = simple_strtol(buf, NULL, 10); | 836 | long val; |
| 837 | int err; | ||
| 499 | int temp; | 838 | int temp; |
| 500 | 839 | ||
| 840 | err = strict_strtol(buf, 10, &val); | ||
| 841 | if (err < 0) | ||
| 842 | return err; | ||
| 843 | |||
| 501 | mutex_lock(&data->update_lock); | 844 | mutex_lock(&data->update_lock); |
| 502 | if (data->kind == adt7461) | 845 | if (data->kind == adt7461) |
| 503 | temp = temp_from_u8_adt7461(data, data->temp8[2]); | 846 | temp = temp_from_u8_adt7461(data, data->temp8[2]); |
| @@ -530,16 +873,44 @@ static ssize_t show_alarm(struct device *dev, struct device_attribute | |||
| 530 | return sprintf(buf, "%d\n", (data->alarms >> bitnr) & 1); | 873 | return sprintf(buf, "%d\n", (data->alarms >> bitnr) & 1); |
| 531 | } | 874 | } |
| 532 | 875 | ||
| 533 | static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, show_temp11, NULL, 4); | 876 | static ssize_t show_update_interval(struct device *dev, |
| 534 | static SENSOR_DEVICE_ATTR(temp2_input, S_IRUGO, show_temp11, NULL, 0); | 877 | struct device_attribute *attr, char *buf) |
| 878 | { | ||
| 879 | struct lm90_data *data = dev_get_drvdata(dev); | ||
| 880 | |||
| 881 | return sprintf(buf, "%u\n", data->update_interval); | ||
| 882 | } | ||
| 883 | |||
| 884 | static ssize_t set_update_interval(struct device *dev, | ||
| 885 | struct device_attribute *attr, | ||
| 886 | const char *buf, size_t count) | ||
| 887 | { | ||
| 888 | struct i2c_client *client = to_i2c_client(dev); | ||
| 889 | struct lm90_data *data = i2c_get_clientdata(client); | ||
| 890 | unsigned long val; | ||
| 891 | int err; | ||
| 892 | |||
| 893 | err = strict_strtoul(buf, 10, &val); | ||
| 894 | if (err) | ||
| 895 | return err; | ||
| 896 | |||
| 897 | mutex_lock(&data->update_lock); | ||
| 898 | lm90_set_convrate(client, data, val); | ||
| 899 | mutex_unlock(&data->update_lock); | ||
| 900 | |||
| 901 | return count; | ||
| 902 | } | ||
| 903 | |||
| 904 | static SENSOR_DEVICE_ATTR_2(temp1_input, S_IRUGO, show_temp11, NULL, 0, 4); | ||
| 905 | static SENSOR_DEVICE_ATTR_2(temp2_input, S_IRUGO, show_temp11, NULL, 0, 0); | ||
| 535 | static SENSOR_DEVICE_ATTR(temp1_min, S_IWUSR | S_IRUGO, show_temp8, | 906 | static SENSOR_DEVICE_ATTR(temp1_min, S_IWUSR | S_IRUGO, show_temp8, |
| 536 | set_temp8, 0); | 907 | set_temp8, 0); |
| 537 | static SENSOR_DEVICE_ATTR(temp2_min, S_IWUSR | S_IRUGO, show_temp11, | 908 | static SENSOR_DEVICE_ATTR_2(temp2_min, S_IWUSR | S_IRUGO, show_temp11, |
| 538 | set_temp11, 1); | 909 | set_temp11, 0, 1); |
| 539 | static SENSOR_DEVICE_ATTR(temp1_max, S_IWUSR | S_IRUGO, show_temp8, | 910 | static SENSOR_DEVICE_ATTR(temp1_max, S_IWUSR | S_IRUGO, show_temp8, |
| 540 | set_temp8, 1); | 911 | set_temp8, 1); |
| 541 | static SENSOR_DEVICE_ATTR(temp2_max, S_IWUSR | S_IRUGO, show_temp11, | 912 | static SENSOR_DEVICE_ATTR_2(temp2_max, S_IWUSR | S_IRUGO, show_temp11, |
| 542 | set_temp11, 2); | 913 | set_temp11, 1, 2); |
| 543 | static SENSOR_DEVICE_ATTR(temp1_crit, S_IWUSR | S_IRUGO, show_temp8, | 914 | static SENSOR_DEVICE_ATTR(temp1_crit, S_IWUSR | S_IRUGO, show_temp8, |
| 544 | set_temp8, 2); | 915 | set_temp8, 2); |
| 545 | static SENSOR_DEVICE_ATTR(temp2_crit, S_IWUSR | S_IRUGO, show_temp8, | 916 | static SENSOR_DEVICE_ATTR(temp2_crit, S_IWUSR | S_IRUGO, show_temp8, |
| @@ -547,8 +918,8 @@ static SENSOR_DEVICE_ATTR(temp2_crit, S_IWUSR | S_IRUGO, show_temp8, | |||
| 547 | static SENSOR_DEVICE_ATTR(temp1_crit_hyst, S_IWUSR | S_IRUGO, show_temphyst, | 918 | static SENSOR_DEVICE_ATTR(temp1_crit_hyst, S_IWUSR | S_IRUGO, show_temphyst, |
| 548 | set_temphyst, 2); | 919 | set_temphyst, 2); |
| 549 | static SENSOR_DEVICE_ATTR(temp2_crit_hyst, S_IRUGO, show_temphyst, NULL, 3); | 920 | static SENSOR_DEVICE_ATTR(temp2_crit_hyst, S_IRUGO, show_temphyst, NULL, 3); |
| 550 | static SENSOR_DEVICE_ATTR(temp2_offset, S_IWUSR | S_IRUGO, show_temp11, | 921 | static SENSOR_DEVICE_ATTR_2(temp2_offset, S_IWUSR | S_IRUGO, show_temp11, |
| 551 | set_temp11, 3); | 922 | set_temp11, 2, 3); |
| 552 | 923 | ||
| 553 | /* Individual alarm files */ | 924 | /* Individual alarm files */ |
| 554 | static SENSOR_DEVICE_ATTR(temp1_crit_alarm, S_IRUGO, show_alarm, NULL, 0); | 925 | static SENSOR_DEVICE_ATTR(temp1_crit_alarm, S_IRUGO, show_alarm, NULL, 0); |
| @@ -561,6 +932,9 @@ static SENSOR_DEVICE_ATTR(temp1_max_alarm, S_IRUGO, show_alarm, NULL, 6); | |||
| 561 | /* Raw alarm file for compatibility */ | 932 | /* Raw alarm file for compatibility */ |
| 562 | static DEVICE_ATTR(alarms, S_IRUGO, show_alarms, NULL); | 933 | static DEVICE_ATTR(alarms, S_IRUGO, show_alarms, NULL); |
| 563 | 934 | ||
| 935 | static DEVICE_ATTR(update_interval, S_IRUGO | S_IWUSR, show_update_interval, | ||
| 936 | set_update_interval); | ||
| 937 | |||
| 564 | static struct attribute *lm90_attributes[] = { | 938 | static struct attribute *lm90_attributes[] = { |
| 565 | &sensor_dev_attr_temp1_input.dev_attr.attr, | 939 | &sensor_dev_attr_temp1_input.dev_attr.attr, |
| 566 | &sensor_dev_attr_temp2_input.dev_attr.attr, | 940 | &sensor_dev_attr_temp2_input.dev_attr.attr, |
| @@ -581,6 +955,7 @@ static struct attribute *lm90_attributes[] = { | |||
| 581 | &sensor_dev_attr_temp1_min_alarm.dev_attr.attr, | 955 | &sensor_dev_attr_temp1_min_alarm.dev_attr.attr, |
| 582 | &sensor_dev_attr_temp1_max_alarm.dev_attr.attr, | 956 | &sensor_dev_attr_temp1_max_alarm.dev_attr.attr, |
| 583 | &dev_attr_alarms.attr, | 957 | &dev_attr_alarms.attr, |
| 958 | &dev_attr_update_interval.attr, | ||
| 584 | NULL | 959 | NULL |
| 585 | }; | 960 | }; |
| 586 | 961 | ||
| @@ -588,6 +963,86 @@ static const struct attribute_group lm90_group = { | |||
| 588 | .attrs = lm90_attributes, | 963 | .attrs = lm90_attributes, |
| 589 | }; | 964 | }; |
| 590 | 965 | ||
| 966 | /* | ||
| 967 | * Additional attributes for devices with emergency sensors | ||
| 968 | */ | ||
| 969 | static SENSOR_DEVICE_ATTR(temp1_emergency, S_IWUSR | S_IRUGO, show_temp8, | ||
| 970 | set_temp8, 4); | ||
| 971 | static SENSOR_DEVICE_ATTR(temp2_emergency, S_IWUSR | S_IRUGO, show_temp8, | ||
| 972 | set_temp8, 5); | ||
| 973 | static SENSOR_DEVICE_ATTR(temp1_emergency_hyst, S_IRUGO, show_temphyst, | ||
| 974 | NULL, 4); | ||
| 975 | static SENSOR_DEVICE_ATTR(temp2_emergency_hyst, S_IRUGO, show_temphyst, | ||
| 976 | NULL, 5); | ||
| 977 | |||
| 978 | static struct attribute *lm90_emergency_attributes[] = { | ||
| 979 | &sensor_dev_attr_temp1_emergency.dev_attr.attr, | ||
| 980 | &sensor_dev_attr_temp2_emergency.dev_attr.attr, | ||
| 981 | &sensor_dev_attr_temp1_emergency_hyst.dev_attr.attr, | ||
| 982 | &sensor_dev_attr_temp2_emergency_hyst.dev_attr.attr, | ||
| 983 | NULL | ||
| 984 | }; | ||
| 985 | |||
| 986 | static const struct attribute_group lm90_emergency_group = { | ||
| 987 | .attrs = lm90_emergency_attributes, | ||
| 988 | }; | ||
| 989 | |||
| 990 | static SENSOR_DEVICE_ATTR(temp1_emergency_alarm, S_IRUGO, show_alarm, NULL, 15); | ||
| 991 | static SENSOR_DEVICE_ATTR(temp2_emergency_alarm, S_IRUGO, show_alarm, NULL, 13); | ||
| 992 | |||
| 993 | static struct attribute *lm90_emergency_alarm_attributes[] = { | ||
| 994 | &sensor_dev_attr_temp1_emergency_alarm.dev_attr.attr, | ||
| 995 | &sensor_dev_attr_temp2_emergency_alarm.dev_attr.attr, | ||
| 996 | NULL | ||
| 997 | }; | ||
| 998 | |||
| 999 | static const struct attribute_group lm90_emergency_alarm_group = { | ||
| 1000 | .attrs = lm90_emergency_alarm_attributes, | ||
| 1001 | }; | ||
| 1002 | |||
| 1003 | /* | ||
| 1004 | * Additional attributes for devices with 3 temperature sensors | ||
| 1005 | */ | ||
| 1006 | static SENSOR_DEVICE_ATTR_2(temp3_input, S_IRUGO, show_temp11, NULL, 0, 5); | ||
| 1007 | static SENSOR_DEVICE_ATTR_2(temp3_min, S_IWUSR | S_IRUGO, show_temp11, | ||
| 1008 | set_temp11, 3, 6); | ||
| 1009 | static SENSOR_DEVICE_ATTR_2(temp3_max, S_IWUSR | S_IRUGO, show_temp11, | ||
| 1010 | set_temp11, 4, 7); | ||
| 1011 | static SENSOR_DEVICE_ATTR(temp3_crit, S_IWUSR | S_IRUGO, show_temp8, | ||
| 1012 | set_temp8, 6); | ||
| 1013 | static SENSOR_DEVICE_ATTR(temp3_crit_hyst, S_IRUGO, show_temphyst, NULL, 6); | ||
| 1014 | static SENSOR_DEVICE_ATTR(temp3_emergency, S_IWUSR | S_IRUGO, show_temp8, | ||
| 1015 | set_temp8, 7); | ||
| 1016 | static SENSOR_DEVICE_ATTR(temp3_emergency_hyst, S_IRUGO, show_temphyst, | ||
| 1017 | NULL, 7); | ||
| 1018 | |||
| 1019 | static SENSOR_DEVICE_ATTR(temp3_crit_alarm, S_IRUGO, show_alarm, NULL, 9); | ||
| 1020 | static SENSOR_DEVICE_ATTR(temp3_fault, S_IRUGO, show_alarm, NULL, 10); | ||
| 1021 | static SENSOR_DEVICE_ATTR(temp3_min_alarm, S_IRUGO, show_alarm, NULL, 11); | ||
| 1022 | static SENSOR_DEVICE_ATTR(temp3_max_alarm, S_IRUGO, show_alarm, NULL, 12); | ||
| 1023 | static SENSOR_DEVICE_ATTR(temp3_emergency_alarm, S_IRUGO, show_alarm, NULL, 14); | ||
| 1024 | |||
| 1025 | static struct attribute *lm90_temp3_attributes[] = { | ||
| 1026 | &sensor_dev_attr_temp3_input.dev_attr.attr, | ||
| 1027 | &sensor_dev_attr_temp3_min.dev_attr.attr, | ||
| 1028 | &sensor_dev_attr_temp3_max.dev_attr.attr, | ||
| 1029 | &sensor_dev_attr_temp3_crit.dev_attr.attr, | ||
| 1030 | &sensor_dev_attr_temp3_crit_hyst.dev_attr.attr, | ||
| 1031 | &sensor_dev_attr_temp3_emergency.dev_attr.attr, | ||
| 1032 | &sensor_dev_attr_temp3_emergency_hyst.dev_attr.attr, | ||
| 1033 | |||
| 1034 | &sensor_dev_attr_temp3_fault.dev_attr.attr, | ||
| 1035 | &sensor_dev_attr_temp3_min_alarm.dev_attr.attr, | ||
| 1036 | &sensor_dev_attr_temp3_max_alarm.dev_attr.attr, | ||
| 1037 | &sensor_dev_attr_temp3_crit_alarm.dev_attr.attr, | ||
| 1038 | &sensor_dev_attr_temp3_emergency_alarm.dev_attr.attr, | ||
| 1039 | NULL | ||
| 1040 | }; | ||
| 1041 | |||
| 1042 | static const struct attribute_group lm90_temp3_group = { | ||
| 1043 | .attrs = lm90_temp3_attributes, | ||
| 1044 | }; | ||
| 1045 | |||
| 591 | /* pec used for ADM1032 only */ | 1046 | /* pec used for ADM1032 only */ |
| 592 | static ssize_t show_pec(struct device *dev, struct device_attribute *dummy, | 1047 | static ssize_t show_pec(struct device *dev, struct device_attribute *dummy, |
| 593 | char *buf) | 1048 | char *buf) |
| @@ -600,7 +1055,12 @@ static ssize_t set_pec(struct device *dev, struct device_attribute *dummy, | |||
| 600 | const char *buf, size_t count) | 1055 | const char *buf, size_t count) |
| 601 | { | 1056 | { |
| 602 | struct i2c_client *client = to_i2c_client(dev); | 1057 | struct i2c_client *client = to_i2c_client(dev); |
| 603 | long val = simple_strtol(buf, NULL, 10); | 1058 | long val; |
| 1059 | int err; | ||
| 1060 | |||
| 1061 | err = strict_strtol(buf, 10, &val); | ||
| 1062 | if (err < 0) | ||
| 1063 | return err; | ||
| 604 | 1064 | ||
| 605 | switch (val) { | 1065 | switch (val) { |
| 606 | case 0: | 1066 | case 0: |
| @@ -622,40 +1082,6 @@ static DEVICE_ATTR(pec, S_IWUSR | S_IRUGO, show_pec, set_pec); | |||
| 622 | * Real code | 1082 | * Real code |
| 623 | */ | 1083 | */ |
| 624 | 1084 | ||
| 625 | /* The ADM1032 supports PEC but not on write byte transactions, so we need | ||
| 626 | to explicitly ask for a transaction without PEC. */ | ||
| 627 | static inline s32 adm1032_write_byte(struct i2c_client *client, u8 value) | ||
| 628 | { | ||
| 629 | return i2c_smbus_xfer(client->adapter, client->addr, | ||
| 630 | client->flags & ~I2C_CLIENT_PEC, | ||
| 631 | I2C_SMBUS_WRITE, value, I2C_SMBUS_BYTE, NULL); | ||
| 632 | } | ||
| 633 | |||
| 634 | /* It is assumed that client->update_lock is held (unless we are in | ||
| 635 | detection or initialization steps). This matters when PEC is enabled, | ||
| 636 | because we don't want the address pointer to change between the write | ||
| 637 | byte and the read byte transactions. */ | ||
| 638 | static int lm90_read_reg(struct i2c_client* client, u8 reg, u8 *value) | ||
| 639 | { | ||
| 640 | int err; | ||
| 641 | |||
| 642 | if (client->flags & I2C_CLIENT_PEC) { | ||
| 643 | err = adm1032_write_byte(client, reg); | ||
| 644 | if (err >= 0) | ||
| 645 | err = i2c_smbus_read_byte(client); | ||
| 646 | } else | ||
| 647 | err = i2c_smbus_read_byte_data(client, reg); | ||
| 648 | |||
| 649 | if (err < 0) { | ||
| 650 | dev_warn(&client->dev, "Register %#02x read failed (%d)\n", | ||
| 651 | reg, err); | ||
| 652 | return err; | ||
| 653 | } | ||
| 654 | *value = err; | ||
| 655 | |||
| 656 | return 0; | ||
| 657 | } | ||
| 658 | |||
| 659 | /* Return 0 if detection is successful, -ENODEV otherwise */ | 1085 | /* Return 0 if detection is successful, -ENODEV otherwise */ |
| 660 | static int lm90_detect(struct i2c_client *new_client, | 1086 | static int lm90_detect(struct i2c_client *new_client, |
| 661 | struct i2c_board_info *info) | 1087 | struct i2c_board_info *info) |
| @@ -730,6 +1156,23 @@ static int lm90_detect(struct i2c_client *new_client, | |||
| 730 | } | 1156 | } |
| 731 | } else | 1157 | } else |
| 732 | if (man_id == 0x4D) { /* Maxim */ | 1158 | if (man_id == 0x4D) { /* Maxim */ |
| 1159 | int reg_emerg, reg_emerg2, reg_status2; | ||
| 1160 | |||
| 1161 | /* | ||
| 1162 | * We read MAX6659_REG_R_REMOTE_EMERG twice, and re-read | ||
| 1163 | * LM90_REG_R_MAN_ID in between. If MAX6659_REG_R_REMOTE_EMERG | ||
| 1164 | * exists, both readings will reflect the same value. Otherwise, | ||
| 1165 | * the readings will be different. | ||
| 1166 | */ | ||
| 1167 | if ((reg_emerg = i2c_smbus_read_byte_data(new_client, | ||
| 1168 | MAX6659_REG_R_REMOTE_EMERG)) < 0 | ||
| 1169 | || i2c_smbus_read_byte_data(new_client, LM90_REG_R_MAN_ID) < 0 | ||
| 1170 | || (reg_emerg2 = i2c_smbus_read_byte_data(new_client, | ||
| 1171 | MAX6659_REG_R_REMOTE_EMERG)) < 0 | ||
| 1172 | || (reg_status2 = i2c_smbus_read_byte_data(new_client, | ||
| 1173 | MAX6696_REG_R_STATUS2)) < 0) | ||
| 1174 | return -ENODEV; | ||
| 1175 | |||
| 733 | /* | 1176 | /* |
| 734 | * The MAX6657, MAX6658 and MAX6659 do NOT have a chip_id | 1177 | * The MAX6657, MAX6658 and MAX6659 do NOT have a chip_id |
| 735 | * register. Reading from that address will return the last | 1178 | * register. Reading from that address will return the last |
| @@ -737,12 +1180,38 @@ static int lm90_detect(struct i2c_client *new_client, | |||
| 737 | * register. Likewise, the config1 register seems to lack a | 1180 | * register. Likewise, the config1 register seems to lack a |
| 738 | * low nibble, so the value will be those of the previous | 1181 | * low nibble, so the value will be those of the previous |
| 739 | * read, so in our case those of the man_id register. | 1182 | * read, so in our case those of the man_id register. |
| 1183 | * MAX6659 has a third set of upper temperature limit registers. | ||
| 1184 | * Those registers also return values on MAX6657 and MAX6658, | ||
| 1185 | * thus the only way to detect MAX6659 is by its address. | ||
| 1186 | * For this reason it will be mis-detected as MAX6657 if its | ||
| 1187 | * address is 0x4C. | ||
| 740 | */ | 1188 | */ |
| 741 | if (chip_id == man_id | 1189 | if (chip_id == man_id |
| 742 | && (address == 0x4C || address == 0x4D) | 1190 | && (address == 0x4C || address == 0x4D || address == 0x4E) |
| 743 | && (reg_config1 & 0x1F) == (man_id & 0x0F) | 1191 | && (reg_config1 & 0x1F) == (man_id & 0x0F) |
| 744 | && reg_convrate <= 0x09) { | 1192 | && reg_convrate <= 0x09) { |
| 745 | name = "max6657"; | 1193 | if (address == 0x4C) |
| 1194 | name = "max6657"; | ||
| 1195 | else | ||
| 1196 | name = "max6659"; | ||
| 1197 | } else | ||
| 1198 | /* | ||
| 1199 | * Even though MAX6695 and MAX6696 do not have a chip ID | ||
| 1200 | * register, reading it returns 0x01. Bit 4 of the config1 | ||
| 1201 | * register is unused and should return zero when read. Bit 0 of | ||
| 1202 | * the status2 register is unused and should return zero when | ||
| 1203 | * read. | ||
| 1204 | * | ||
| 1205 | * MAX6695 and MAX6696 have an additional set of temperature | ||
| 1206 | * limit registers. We can detect those chips by checking if | ||
| 1207 | * one of those registers exists. | ||
| 1208 | */ | ||
| 1209 | if (chip_id == 0x01 | ||
| 1210 | && (reg_config1 & 0x10) == 0x00 | ||
| 1211 | && (reg_status2 & 0x01) == 0x00 | ||
| 1212 | && reg_emerg == reg_emerg2 | ||
| 1213 | && reg_convrate <= 0x07) { | ||
| 1214 | name = "max6696"; | ||
| 746 | } else | 1215 | } else |
| 747 | /* | 1216 | /* |
| 748 | * The chip_id register of the MAX6680 and MAX6681 holds the | 1217 | * The chip_id register of the MAX6680 and MAX6681 holds the |
| @@ -768,10 +1237,23 @@ static int lm90_detect(struct i2c_client *new_client, | |||
| 768 | } else | 1237 | } else |
| 769 | if (address == 0x4C | 1238 | if (address == 0x4C |
| 770 | && man_id == 0x5C) { /* Winbond/Nuvoton */ | 1239 | && man_id == 0x5C) { /* Winbond/Nuvoton */ |
| 771 | if ((chip_id & 0xFE) == 0x10 /* W83L771AWG/ASG */ | 1240 | int reg_config2; |
| 772 | && (reg_config1 & 0x2A) == 0x00 | 1241 | |
| 773 | && reg_convrate <= 0x08) { | 1242 | reg_config2 = i2c_smbus_read_byte_data(new_client, |
| 774 | name = "w83l771"; | 1243 | LM90_REG_R_CONFIG2); |
| 1244 | if (reg_config2 < 0) | ||
| 1245 | return -ENODEV; | ||
| 1246 | |||
| 1247 | if ((reg_config1 & 0x2A) == 0x00 | ||
| 1248 | && (reg_config2 & 0xF8) == 0x00) { | ||
| 1249 | if (chip_id == 0x01 /* W83L771W/G */ | ||
| 1250 | && reg_convrate <= 0x09) { | ||
| 1251 | name = "w83l771"; | ||
| 1252 | } else | ||
| 1253 | if ((chip_id & 0xFE) == 0x10 /* W83L771AWG/ASG */ | ||
| 1254 | && reg_convrate <= 0x08) { | ||
| 1255 | name = "w83l771"; | ||
| 1256 | } | ||
| 775 | } | 1257 | } |
| 776 | } | 1258 | } |
| 777 | 1259 | ||
| @@ -787,6 +1269,69 @@ static int lm90_detect(struct i2c_client *new_client, | |||
| 787 | return 0; | 1269 | return 0; |
| 788 | } | 1270 | } |
| 789 | 1271 | ||
| 1272 | static void lm90_remove_files(struct i2c_client *client, struct lm90_data *data) | ||
| 1273 | { | ||
| 1274 | if (data->flags & LM90_HAVE_TEMP3) | ||
| 1275 | sysfs_remove_group(&client->dev.kobj, &lm90_temp3_group); | ||
| 1276 | if (data->flags & LM90_HAVE_EMERGENCY_ALARM) | ||
| 1277 | sysfs_remove_group(&client->dev.kobj, | ||
| 1278 | &lm90_emergency_alarm_group); | ||
| 1279 | if (data->flags & LM90_HAVE_EMERGENCY) | ||
| 1280 | sysfs_remove_group(&client->dev.kobj, | ||
| 1281 | &lm90_emergency_group); | ||
| 1282 | if (data->flags & LM90_HAVE_OFFSET) | ||
| 1283 | device_remove_file(&client->dev, | ||
| 1284 | &sensor_dev_attr_temp2_offset.dev_attr); | ||
| 1285 | device_remove_file(&client->dev, &dev_attr_pec); | ||
| 1286 | sysfs_remove_group(&client->dev.kobj, &lm90_group); | ||
| 1287 | } | ||
| 1288 | |||
| 1289 | static void lm90_init_client(struct i2c_client *client) | ||
| 1290 | { | ||
| 1291 | u8 config, convrate; | ||
| 1292 | struct lm90_data *data = i2c_get_clientdata(client); | ||
| 1293 | |||
| 1294 | if (lm90_read_reg(client, LM90_REG_R_CONVRATE, &convrate) < 0) { | ||
| 1295 | dev_warn(&client->dev, "Failed to read convrate register!\n"); | ||
| 1296 | convrate = LM90_DEF_CONVRATE_RVAL; | ||
| 1297 | } | ||
| 1298 | data->convrate_orig = convrate; | ||
| 1299 | |||
| 1300 | /* | ||
| 1301 | * Start the conversions. | ||
| 1302 | */ | ||
| 1303 | lm90_set_convrate(client, data, 500); /* 500ms; 2Hz conversion rate */ | ||
| 1304 | if (lm90_read_reg(client, LM90_REG_R_CONFIG1, &config) < 0) { | ||
| 1305 | dev_warn(&client->dev, "Initialization failed!\n"); | ||
| 1306 | return; | ||
| 1307 | } | ||
| 1308 | data->config_orig = config; | ||
| 1309 | |||
| 1310 | /* Check Temperature Range Select */ | ||
| 1311 | if (data->kind == adt7461) { | ||
| 1312 | if (config & 0x04) | ||
| 1313 | data->flags |= LM90_FLAG_ADT7461_EXT; | ||
| 1314 | } | ||
| 1315 | |||
| 1316 | /* | ||
| 1317 | * Put MAX6680/MAX8881 into extended resolution (bit 0x10, | ||
| 1318 | * 0.125 degree resolution) and range (0x08, extend range | ||
| 1319 | * to -64 degree) mode for the remote temperature sensor. | ||
| 1320 | */ | ||
| 1321 | if (data->kind == max6680) | ||
| 1322 | config |= 0x18; | ||
| 1323 | |||
| 1324 | /* | ||
| 1325 | * Select external channel 0 for max6695/96 | ||
| 1326 | */ | ||
| 1327 | if (data->kind == max6696) | ||
| 1328 | config &= ~0x08; | ||
| 1329 | |||
| 1330 | config &= 0xBF; /* run */ | ||
| 1331 | if (config != data->config_orig) /* Only write if changed */ | ||
| 1332 | i2c_smbus_write_byte_data(client, LM90_REG_W_CONFIG1, config); | ||
| 1333 | } | ||
| 1334 | |||
| 790 | static int lm90_probe(struct i2c_client *new_client, | 1335 | static int lm90_probe(struct i2c_client *new_client, |
| 791 | const struct i2c_device_id *id) | 1336 | const struct i2c_device_id *id) |
| 792 | { | 1337 | { |
| @@ -811,31 +1356,48 @@ static int lm90_probe(struct i2c_client *new_client, | |||
| 811 | 1356 | ||
| 812 | /* Different devices have different alarm bits triggering the | 1357 | /* Different devices have different alarm bits triggering the |
| 813 | * ALERT# output */ | 1358 | * ALERT# output */ |
| 814 | switch (data->kind) { | 1359 | data->alert_alarms = lm90_params[data->kind].alert_alarms; |
| 815 | case lm90: | 1360 | |
| 816 | case lm99: | 1361 | /* Set chip capabilities */ |
| 817 | case lm86: | 1362 | data->flags = lm90_params[data->kind].flags; |
| 818 | data->alert_alarms = 0x7b; | 1363 | |
| 819 | break; | 1364 | /* Set maximum conversion rate */ |
| 820 | default: | 1365 | data->max_convrate = lm90_params[data->kind].max_convrate; |
| 821 | data->alert_alarms = 0x7c; | ||
| 822 | break; | ||
| 823 | } | ||
| 824 | 1366 | ||
| 825 | /* Initialize the LM90 chip */ | 1367 | /* Initialize the LM90 chip */ |
| 826 | lm90_init_client(new_client); | 1368 | lm90_init_client(new_client); |
| 827 | 1369 | ||
| 828 | /* Register sysfs hooks */ | 1370 | /* Register sysfs hooks */ |
| 829 | if ((err = sysfs_create_group(&new_client->dev.kobj, &lm90_group))) | 1371 | err = sysfs_create_group(&new_client->dev.kobj, &lm90_group); |
| 1372 | if (err) | ||
| 830 | goto exit_free; | 1373 | goto exit_free; |
| 831 | if (new_client->flags & I2C_CLIENT_PEC) { | 1374 | if (new_client->flags & I2C_CLIENT_PEC) { |
| 832 | if ((err = device_create_file(&new_client->dev, | 1375 | err = device_create_file(&new_client->dev, &dev_attr_pec); |
| 833 | &dev_attr_pec))) | 1376 | if (err) |
| 1377 | goto exit_remove_files; | ||
| 1378 | } | ||
| 1379 | if (data->flags & LM90_HAVE_OFFSET) { | ||
| 1380 | err = device_create_file(&new_client->dev, | ||
| 1381 | &sensor_dev_attr_temp2_offset.dev_attr); | ||
| 1382 | if (err) | ||
| 834 | goto exit_remove_files; | 1383 | goto exit_remove_files; |
| 835 | } | 1384 | } |
| 836 | if (data->kind != max6657 && data->kind != max6646) { | 1385 | if (data->flags & LM90_HAVE_EMERGENCY) { |
| 837 | if ((err = device_create_file(&new_client->dev, | 1386 | err = sysfs_create_group(&new_client->dev.kobj, |
| 838 | &sensor_dev_attr_temp2_offset.dev_attr))) | 1387 | &lm90_emergency_group); |
| 1388 | if (err) | ||
| 1389 | goto exit_remove_files; | ||
| 1390 | } | ||
| 1391 | if (data->flags & LM90_HAVE_EMERGENCY_ALARM) { | ||
| 1392 | err = sysfs_create_group(&new_client->dev.kobj, | ||
| 1393 | &lm90_emergency_alarm_group); | ||
| 1394 | if (err) | ||
| 1395 | goto exit_remove_files; | ||
| 1396 | } | ||
| 1397 | if (data->flags & LM90_HAVE_TEMP3) { | ||
| 1398 | err = sysfs_create_group(&new_client->dev.kobj, | ||
| 1399 | &lm90_temp3_group); | ||
| 1400 | if (err) | ||
| 839 | goto exit_remove_files; | 1401 | goto exit_remove_files; |
| 840 | } | 1402 | } |
| 841 | 1403 | ||
| @@ -848,62 +1410,23 @@ static int lm90_probe(struct i2c_client *new_client, | |||
| 848 | return 0; | 1410 | return 0; |
| 849 | 1411 | ||
| 850 | exit_remove_files: | 1412 | exit_remove_files: |
| 851 | sysfs_remove_group(&new_client->dev.kobj, &lm90_group); | 1413 | lm90_remove_files(new_client, data); |
| 852 | device_remove_file(&new_client->dev, &dev_attr_pec); | ||
| 853 | exit_free: | 1414 | exit_free: |
| 854 | kfree(data); | 1415 | kfree(data); |
| 855 | exit: | 1416 | exit: |
| 856 | return err; | 1417 | return err; |
| 857 | } | 1418 | } |
| 858 | 1419 | ||
| 859 | static void lm90_init_client(struct i2c_client *client) | ||
| 860 | { | ||
| 861 | u8 config; | ||
| 862 | struct lm90_data *data = i2c_get_clientdata(client); | ||
| 863 | |||
| 864 | /* | ||
| 865 | * Start the conversions. | ||
| 866 | */ | ||
| 867 | i2c_smbus_write_byte_data(client, LM90_REG_W_CONVRATE, | ||
| 868 | 5); /* 2 Hz */ | ||
| 869 | if (lm90_read_reg(client, LM90_REG_R_CONFIG1, &config) < 0) { | ||
| 870 | dev_warn(&client->dev, "Initialization failed!\n"); | ||
| 871 | return; | ||
| 872 | } | ||
| 873 | data->config_orig = config; | ||
| 874 | |||
| 875 | /* Check Temperature Range Select */ | ||
| 876 | if (data->kind == adt7461) { | ||
| 877 | if (config & 0x04) | ||
| 878 | data->flags |= LM90_FLAG_ADT7461_EXT; | ||
| 879 | } | ||
| 880 | |||
| 881 | /* | ||
| 882 | * Put MAX6680/MAX8881 into extended resolution (bit 0x10, | ||
| 883 | * 0.125 degree resolution) and range (0x08, extend range | ||
| 884 | * to -64 degree) mode for the remote temperature sensor. | ||
| 885 | */ | ||
| 886 | if (data->kind == max6680) { | ||
| 887 | config |= 0x18; | ||
| 888 | } | ||
| 889 | |||
| 890 | config &= 0xBF; /* run */ | ||
| 891 | if (config != data->config_orig) /* Only write if changed */ | ||
| 892 | i2c_smbus_write_byte_data(client, LM90_REG_W_CONFIG1, config); | ||
| 893 | } | ||
| 894 | |||
| 895 | static int lm90_remove(struct i2c_client *client) | 1420 | static int lm90_remove(struct i2c_client *client) |
| 896 | { | 1421 | { |
| 897 | struct lm90_data *data = i2c_get_clientdata(client); | 1422 | struct lm90_data *data = i2c_get_clientdata(client); |
| 898 | 1423 | ||
| 899 | hwmon_device_unregister(data->hwmon_dev); | 1424 | hwmon_device_unregister(data->hwmon_dev); |
| 900 | sysfs_remove_group(&client->dev.kobj, &lm90_group); | 1425 | lm90_remove_files(client, data); |
| 901 | device_remove_file(&client->dev, &dev_attr_pec); | ||
| 902 | if (data->kind != max6657 && data->kind != max6646) | ||
| 903 | device_remove_file(&client->dev, | ||
| 904 | &sensor_dev_attr_temp2_offset.dev_attr); | ||
| 905 | 1426 | ||
| 906 | /* Restore initial configuration */ | 1427 | /* Restore initial configuration */ |
| 1428 | i2c_smbus_write_byte_data(client, LM90_REG_W_CONVRATE, | ||
| 1429 | data->convrate_orig); | ||
| 907 | i2c_smbus_write_byte_data(client, LM90_REG_W_CONFIG1, | 1430 | i2c_smbus_write_byte_data(client, LM90_REG_W_CONFIG1, |
| 908 | data->config_orig); | 1431 | data->config_orig); |
| 909 | 1432 | ||
| @@ -914,10 +1437,14 @@ static int lm90_remove(struct i2c_client *client) | |||
| 914 | static void lm90_alert(struct i2c_client *client, unsigned int flag) | 1437 | static void lm90_alert(struct i2c_client *client, unsigned int flag) |
| 915 | { | 1438 | { |
| 916 | struct lm90_data *data = i2c_get_clientdata(client); | 1439 | struct lm90_data *data = i2c_get_clientdata(client); |
| 917 | u8 config, alarms; | 1440 | u8 config, alarms, alarms2 = 0; |
| 918 | 1441 | ||
| 919 | lm90_read_reg(client, LM90_REG_R_STATUS, &alarms); | 1442 | lm90_read_reg(client, LM90_REG_R_STATUS, &alarms); |
| 920 | if ((alarms & 0x7f) == 0) { | 1443 | |
| 1444 | if (data->kind == max6696) | ||
| 1445 | lm90_read_reg(client, MAX6696_REG_R_STATUS2, &alarms2); | ||
| 1446 | |||
| 1447 | if ((alarms & 0x7f) == 0 && (alarms2 & 0xfe) == 0) { | ||
| 921 | dev_info(&client->dev, "Everything OK\n"); | 1448 | dev_info(&client->dev, "Everything OK\n"); |
| 922 | } else { | 1449 | } else { |
| 923 | if (alarms & 0x61) | 1450 | if (alarms & 0x61) |
| @@ -930,10 +1457,14 @@ static void lm90_alert(struct i2c_client *client, unsigned int flag) | |||
| 930 | dev_warn(&client->dev, | 1457 | dev_warn(&client->dev, |
| 931 | "temp%d diode open, please check!\n", 2); | 1458 | "temp%d diode open, please check!\n", 2); |
| 932 | 1459 | ||
| 1460 | if (alarms2 & 0x18) | ||
| 1461 | dev_warn(&client->dev, | ||
| 1462 | "temp%d out of range, please check!\n", 3); | ||
| 1463 | |||
| 933 | /* Disable ALERT# output, because these chips don't implement | 1464 | /* Disable ALERT# output, because these chips don't implement |
| 934 | SMBus alert correctly; they should only hold the alert line | 1465 | SMBus alert correctly; they should only hold the alert line |
| 935 | low briefly. */ | 1466 | low briefly. */ |
| 936 | if ((data->kind == adm1032 || data->kind == adt7461) | 1467 | if ((data->flags & LM90_HAVE_BROKEN_ALERT) |
| 937 | && (alarms & data->alert_alarms)) { | 1468 | && (alarms & data->alert_alarms)) { |
| 938 | dev_dbg(&client->dev, "Disabling ALERT#\n"); | 1469 | dev_dbg(&client->dev, "Disabling ALERT#\n"); |
| 939 | lm90_read_reg(client, LM90_REG_R_CONFIG1, &config); | 1470 | lm90_read_reg(client, LM90_REG_R_CONFIG1, &config); |
| @@ -943,117 +1474,18 @@ static void lm90_alert(struct i2c_client *client, unsigned int flag) | |||
| 943 | } | 1474 | } |
| 944 | } | 1475 | } |
| 945 | 1476 | ||
| 946 | static int lm90_read16(struct i2c_client *client, u8 regh, u8 regl, u16 *value) | 1477 | static struct i2c_driver lm90_driver = { |
| 947 | { | 1478 | .class = I2C_CLASS_HWMON, |
| 948 | int err; | 1479 | .driver = { |
| 949 | u8 oldh, newh, l; | 1480 | .name = "lm90", |
| 950 | 1481 | }, | |
| 951 | /* | 1482 | .probe = lm90_probe, |
| 952 | * There is a trick here. We have to read two registers to have the | 1483 | .remove = lm90_remove, |
| 953 | * sensor temperature, but we have to beware a conversion could occur | 1484 | .alert = lm90_alert, |
| 954 | * inbetween the readings. The datasheet says we should either use | 1485 | .id_table = lm90_id, |
| 955 | * the one-shot conversion register, which we don't want to do | 1486 | .detect = lm90_detect, |
| 956 | * (disables hardware monitoring) or monitor the busy bit, which is | 1487 | .address_list = normal_i2c, |
| 957 | * impossible (we can't read the values and monitor that bit at the | 1488 | }; |
| 958 | * exact same time). So the solution used here is to read the high | ||
| 959 | * byte once, then the low byte, then the high byte again. If the new | ||
| 960 | * high byte matches the old one, then we have a valid reading. Else | ||
| 961 | * we have to read the low byte again, and now we believe we have a | ||
| 962 | * correct reading. | ||
| 963 | */ | ||
| 964 | if ((err = lm90_read_reg(client, regh, &oldh)) | ||
| 965 | || (err = lm90_read_reg(client, regl, &l)) | ||
| 966 | || (err = lm90_read_reg(client, regh, &newh))) | ||
| 967 | return err; | ||
| 968 | if (oldh != newh) { | ||
| 969 | err = lm90_read_reg(client, regl, &l); | ||
| 970 | if (err) | ||
| 971 | return err; | ||
| 972 | } | ||
| 973 | *value = (newh << 8) | l; | ||
| 974 | |||
| 975 | return 0; | ||
| 976 | } | ||
| 977 | |||
| 978 | static struct lm90_data *lm90_update_device(struct device *dev) | ||
| 979 | { | ||
| 980 | struct i2c_client *client = to_i2c_client(dev); | ||
| 981 | struct lm90_data *data = i2c_get_clientdata(client); | ||
| 982 | |||
| 983 | mutex_lock(&data->update_lock); | ||
| 984 | |||
| 985 | if (time_after(jiffies, data->last_updated + HZ / 2 + HZ / 10) | ||
| 986 | || !data->valid) { | ||
| 987 | u8 h, l; | ||
| 988 | |||
| 989 | dev_dbg(&client->dev, "Updating lm90 data.\n"); | ||
| 990 | lm90_read_reg(client, LM90_REG_R_LOCAL_LOW, &data->temp8[0]); | ||
| 991 | lm90_read_reg(client, LM90_REG_R_LOCAL_HIGH, &data->temp8[1]); | ||
| 992 | lm90_read_reg(client, LM90_REG_R_LOCAL_CRIT, &data->temp8[2]); | ||
| 993 | lm90_read_reg(client, LM90_REG_R_REMOTE_CRIT, &data->temp8[3]); | ||
| 994 | lm90_read_reg(client, LM90_REG_R_TCRIT_HYST, &data->temp_hyst); | ||
| 995 | |||
| 996 | if (data->kind == max6657 || data->kind == max6646) { | ||
| 997 | lm90_read16(client, LM90_REG_R_LOCAL_TEMP, | ||
| 998 | MAX6657_REG_R_LOCAL_TEMPL, | ||
| 999 | &data->temp11[4]); | ||
| 1000 | } else { | ||
| 1001 | if (lm90_read_reg(client, LM90_REG_R_LOCAL_TEMP, | ||
| 1002 | &h) == 0) | ||
| 1003 | data->temp11[4] = h << 8; | ||
| 1004 | } | ||
| 1005 | lm90_read16(client, LM90_REG_R_REMOTE_TEMPH, | ||
| 1006 | LM90_REG_R_REMOTE_TEMPL, &data->temp11[0]); | ||
| 1007 | |||
| 1008 | if (lm90_read_reg(client, LM90_REG_R_REMOTE_LOWH, &h) == 0) { | ||
| 1009 | data->temp11[1] = h << 8; | ||
| 1010 | if (data->kind != max6657 && data->kind != max6680 | ||
| 1011 | && data->kind != max6646 | ||
| 1012 | && lm90_read_reg(client, LM90_REG_R_REMOTE_LOWL, | ||
| 1013 | &l) == 0) | ||
| 1014 | data->temp11[1] |= l; | ||
| 1015 | } | ||
| 1016 | if (lm90_read_reg(client, LM90_REG_R_REMOTE_HIGHH, &h) == 0) { | ||
| 1017 | data->temp11[2] = h << 8; | ||
| 1018 | if (data->kind != max6657 && data->kind != max6680 | ||
| 1019 | && data->kind != max6646 | ||
| 1020 | && lm90_read_reg(client, LM90_REG_R_REMOTE_HIGHL, | ||
| 1021 | &l) == 0) | ||
| 1022 | data->temp11[2] |= l; | ||
| 1023 | } | ||
| 1024 | |||
| 1025 | if (data->kind != max6657 && data->kind != max6646) { | ||
| 1026 | if (lm90_read_reg(client, LM90_REG_R_REMOTE_OFFSH, | ||
| 1027 | &h) == 0 | ||
| 1028 | && lm90_read_reg(client, LM90_REG_R_REMOTE_OFFSL, | ||
| 1029 | &l) == 0) | ||
| 1030 | data->temp11[3] = (h << 8) | l; | ||
| 1031 | } | ||
| 1032 | lm90_read_reg(client, LM90_REG_R_STATUS, &data->alarms); | ||
| 1033 | |||
| 1034 | /* Re-enable ALERT# output if it was originally enabled and | ||
| 1035 | * relevant alarms are all clear */ | ||
| 1036 | if ((data->config_orig & 0x80) == 0 | ||
| 1037 | && (data->alarms & data->alert_alarms) == 0) { | ||
| 1038 | u8 config; | ||
| 1039 | |||
| 1040 | lm90_read_reg(client, LM90_REG_R_CONFIG1, &config); | ||
| 1041 | if (config & 0x80) { | ||
| 1042 | dev_dbg(&client->dev, "Re-enabling ALERT#\n"); | ||
| 1043 | i2c_smbus_write_byte_data(client, | ||
| 1044 | LM90_REG_W_CONFIG1, | ||
| 1045 | config & ~0x80); | ||
| 1046 | } | ||
| 1047 | } | ||
| 1048 | |||
| 1049 | data->last_updated = jiffies; | ||
| 1050 | data->valid = 1; | ||
| 1051 | } | ||
| 1052 | |||
| 1053 | mutex_unlock(&data->update_lock); | ||
| 1054 | |||
| 1055 | return data; | ||
| 1056 | } | ||
| 1057 | 1489 | ||
| 1058 | static int __init sensors_lm90_init(void) | 1490 | static int __init sensors_lm90_init(void) |
| 1059 | { | 1491 | { |
diff --git a/drivers/hwmon/pcf8591.c b/drivers/hwmon/pcf8591.c index d44787949851..dc7259d69812 100644 --- a/drivers/hwmon/pcf8591.c +++ b/drivers/hwmon/pcf8591.c | |||
| @@ -23,10 +23,8 @@ | |||
| 23 | #include <linux/slab.h> | 23 | #include <linux/slab.h> |
| 24 | #include <linux/i2c.h> | 24 | #include <linux/i2c.h> |
| 25 | #include <linux/mutex.h> | 25 | #include <linux/mutex.h> |
| 26 | 26 | #include <linux/err.h> | |
| 27 | /* Addresses to scan */ | 27 | #include <linux/hwmon.h> |
| 28 | static const unsigned short normal_i2c[] = { 0x48, 0x49, 0x4a, 0x4b, 0x4c, | ||
| 29 | 0x4d, 0x4e, 0x4f, I2C_CLIENT_END }; | ||
| 30 | 28 | ||
| 31 | /* Insmod parameters */ | 29 | /* Insmod parameters */ |
| 32 | 30 | ||
| @@ -71,6 +69,7 @@ MODULE_PARM_DESC(input_mode, | |||
| 71 | #define REG_TO_SIGNED(reg) (((reg) & 0x80)?((reg) - 256):(reg)) | 69 | #define REG_TO_SIGNED(reg) (((reg) & 0x80)?((reg) - 256):(reg)) |
| 72 | 70 | ||
| 73 | struct pcf8591_data { | 71 | struct pcf8591_data { |
| 72 | struct device *hwmon_dev; | ||
| 74 | struct mutex update_lock; | 73 | struct mutex update_lock; |
| 75 | 74 | ||
| 76 | u8 control; | 75 | u8 control; |
| @@ -167,24 +166,6 @@ static const struct attribute_group pcf8591_attr_group_opt = { | |||
| 167 | * Real code | 166 | * Real code |
| 168 | */ | 167 | */ |
| 169 | 168 | ||
| 170 | /* Return 0 if detection is successful, -ENODEV otherwise */ | ||
| 171 | static int pcf8591_detect(struct i2c_client *client, | ||
| 172 | struct i2c_board_info *info) | ||
| 173 | { | ||
| 174 | struct i2c_adapter *adapter = client->adapter; | ||
| 175 | |||
| 176 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE | ||
| 177 | | I2C_FUNC_SMBUS_WRITE_BYTE_DATA)) | ||
| 178 | return -ENODEV; | ||
| 179 | |||
| 180 | /* Now, we would do the remaining detection. But the PCF8591 is plainly | ||
| 181 | impossible to detect! Stupid chip. */ | ||
| 182 | |||
| 183 | strlcpy(info->type, "pcf8591", I2C_NAME_SIZE); | ||
| 184 | |||
| 185 | return 0; | ||
| 186 | } | ||
| 187 | |||
| 188 | static int pcf8591_probe(struct i2c_client *client, | 169 | static int pcf8591_probe(struct i2c_client *client, |
| 189 | const struct i2c_device_id *id) | 170 | const struct i2c_device_id *id) |
| 190 | { | 171 | { |
| @@ -221,6 +202,12 @@ static int pcf8591_probe(struct i2c_client *client, | |||
| 221 | goto exit_sysfs_remove; | 202 | goto exit_sysfs_remove; |
| 222 | } | 203 | } |
| 223 | 204 | ||
| 205 | data->hwmon_dev = hwmon_device_register(&client->dev); | ||
| 206 | if (IS_ERR(data->hwmon_dev)) { | ||
| 207 | err = PTR_ERR(data->hwmon_dev); | ||
| 208 | goto exit_sysfs_remove; | ||
| 209 | } | ||
| 210 | |||
| 224 | return 0; | 211 | return 0; |
| 225 | 212 | ||
| 226 | exit_sysfs_remove: | 213 | exit_sysfs_remove: |
| @@ -234,6 +221,9 @@ exit: | |||
| 234 | 221 | ||
| 235 | static int pcf8591_remove(struct i2c_client *client) | 222 | static int pcf8591_remove(struct i2c_client *client) |
| 236 | { | 223 | { |
| 224 | struct pcf8591_data *data = i2c_get_clientdata(client); | ||
| 225 | |||
| 226 | hwmon_device_unregister(data->hwmon_dev); | ||
| 237 | sysfs_remove_group(&client->dev.kobj, &pcf8591_attr_group_opt); | 227 | sysfs_remove_group(&client->dev.kobj, &pcf8591_attr_group_opt); |
| 238 | sysfs_remove_group(&client->dev.kobj, &pcf8591_attr_group); | 228 | sysfs_remove_group(&client->dev.kobj, &pcf8591_attr_group); |
| 239 | kfree(i2c_get_clientdata(client)); | 229 | kfree(i2c_get_clientdata(client)); |
| @@ -295,10 +285,6 @@ static struct i2c_driver pcf8591_driver = { | |||
| 295 | .probe = pcf8591_probe, | 285 | .probe = pcf8591_probe, |
| 296 | .remove = pcf8591_remove, | 286 | .remove = pcf8591_remove, |
| 297 | .id_table = pcf8591_id, | 287 | .id_table = pcf8591_id, |
| 298 | |||
| 299 | .class = I2C_CLASS_HWMON, /* Nearest choice */ | ||
| 300 | .detect = pcf8591_detect, | ||
| 301 | .address_list = normal_i2c, | ||
| 302 | }; | 288 | }; |
| 303 | 289 | ||
| 304 | static int __init pcf8591_init(void) | 290 | static int __init pcf8591_init(void) |
diff --git a/drivers/hwmon/s3c-hwmon.c b/drivers/hwmon/s3c-hwmon.c index 3f3f9a47acfd..05248f2d7581 100644 --- a/drivers/hwmon/s3c-hwmon.c +++ b/drivers/hwmon/s3c-hwmon.c | |||
| @@ -51,7 +51,7 @@ struct s3c_hwmon_attr { | |||
| 51 | * @attr: The holders for the channel attributes. | 51 | * @attr: The holders for the channel attributes. |
| 52 | */ | 52 | */ |
| 53 | struct s3c_hwmon { | 53 | struct s3c_hwmon { |
| 54 | struct semaphore lock; | 54 | struct mutex lock; |
| 55 | struct s3c_adc_client *client; | 55 | struct s3c_adc_client *client; |
| 56 | struct device *hwmon_dev; | 56 | struct device *hwmon_dev; |
| 57 | 57 | ||
| @@ -73,14 +73,14 @@ static int s3c_hwmon_read_ch(struct device *dev, | |||
| 73 | { | 73 | { |
| 74 | int ret; | 74 | int ret; |
| 75 | 75 | ||
| 76 | ret = down_interruptible(&hwmon->lock); | 76 | ret = mutex_lock_interruptible(&hwmon->lock); |
| 77 | if (ret < 0) | 77 | if (ret < 0) |
| 78 | return ret; | 78 | return ret; |
| 79 | 79 | ||
| 80 | dev_dbg(dev, "reading channel %d\n", channel); | 80 | dev_dbg(dev, "reading channel %d\n", channel); |
| 81 | 81 | ||
| 82 | ret = s3c_adc_read(hwmon->client, channel); | 82 | ret = s3c_adc_read(hwmon->client, channel); |
| 83 | up(&hwmon->lock); | 83 | mutex_unlock(&hwmon->lock); |
| 84 | 84 | ||
| 85 | return ret; | 85 | return ret; |
| 86 | } | 86 | } |
| @@ -296,7 +296,7 @@ static int __devinit s3c_hwmon_probe(struct platform_device *dev) | |||
| 296 | 296 | ||
| 297 | platform_set_drvdata(dev, hwmon); | 297 | platform_set_drvdata(dev, hwmon); |
| 298 | 298 | ||
| 299 | init_MUTEX(&hwmon->lock); | 299 | mutex_init(&hwmon->lock); |
| 300 | 300 | ||
| 301 | /* Register with the core ADC driver. */ | 301 | /* Register with the core ADC driver. */ |
| 302 | 302 | ||
diff --git a/drivers/hwmon/tmp421.c b/drivers/hwmon/tmp421.c index 6b4165c12092..0517a8f09d35 100644 --- a/drivers/hwmon/tmp421.c +++ b/drivers/hwmon/tmp421.c | |||
| @@ -36,8 +36,8 @@ | |||
| 36 | #include <linux/sysfs.h> | 36 | #include <linux/sysfs.h> |
| 37 | 37 | ||
| 38 | /* Addresses to scan */ | 38 | /* Addresses to scan */ |
| 39 | static unsigned short normal_i2c[] = { 0x2a, 0x4c, 0x4d, 0x4e, 0x4f, | 39 | static const unsigned short normal_i2c[] = { 0x2a, 0x4c, 0x4d, 0x4e, 0x4f, |
| 40 | I2C_CLIENT_END }; | 40 | I2C_CLIENT_END }; |
| 41 | 41 | ||
| 42 | enum chips { tmp421, tmp422, tmp423 }; | 42 | enum chips { tmp421, tmp422, tmp423 }; |
| 43 | 43 | ||
diff --git a/drivers/hwmon/w83795.c b/drivers/hwmon/w83795.c new file mode 100644 index 000000000000..1d840aa83782 --- /dev/null +++ b/drivers/hwmon/w83795.c | |||
| @@ -0,0 +1,2121 @@ | |||
| 1 | /* | ||
| 2 | * w83795.c - Linux kernel driver for hardware monitoring | ||
| 3 | * Copyright (C) 2008 Nuvoton Technology Corp. | ||
| 4 | * Wei Song | ||
| 5 | * Copyright (C) 2010 Jean Delvare <khali@linux-fr.org> | ||
| 6 | * | ||
| 7 | * This program is free software; you can redistribute it and/or modify | ||
| 8 | * it under the terms of the GNU General Public License as published by | ||
| 9 | * the Free Software Foundation - version 2. | ||
| 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., 51 Franklin Street, Fifth Floor, Boston, MA | ||
| 19 | * 02110-1301 USA. | ||
| 20 | * | ||
| 21 | * Supports following chips: | ||
| 22 | * | ||
| 23 | * Chip #vin #fanin #pwm #temp #dts wchipid vendid i2c ISA | ||
| 24 | * w83795g 21 14 8 6 8 0x79 0x5ca3 yes no | ||
| 25 | * w83795adg 18 14 2 6 8 0x79 0x5ca3 yes no | ||
| 26 | */ | ||
| 27 | |||
| 28 | #include <linux/kernel.h> | ||
| 29 | #include <linux/module.h> | ||
| 30 | #include <linux/init.h> | ||
| 31 | #include <linux/slab.h> | ||
| 32 | #include <linux/i2c.h> | ||
| 33 | #include <linux/hwmon.h> | ||
| 34 | #include <linux/hwmon-sysfs.h> | ||
| 35 | #include <linux/err.h> | ||
| 36 | #include <linux/mutex.h> | ||
| 37 | #include <linux/delay.h> | ||
| 38 | |||
| 39 | /* Addresses to scan */ | ||
| 40 | static const unsigned short normal_i2c[] = { | ||
| 41 | 0x2c, 0x2d, 0x2e, 0x2f, I2C_CLIENT_END | ||
| 42 | }; | ||
| 43 | |||
| 44 | |||
| 45 | static int reset; | ||
| 46 | module_param(reset, bool, 0); | ||
| 47 | MODULE_PARM_DESC(reset, "Set to 1 to reset chip, not recommended"); | ||
| 48 | |||
| 49 | |||
| 50 | #define W83795_REG_BANKSEL 0x00 | ||
| 51 | #define W83795_REG_VENDORID 0xfd | ||
| 52 | #define W83795_REG_CHIPID 0xfe | ||
| 53 | #define W83795_REG_DEVICEID 0xfb | ||
| 54 | #define W83795_REG_DEVICEID_A 0xff | ||
| 55 | |||
| 56 | #define W83795_REG_I2C_ADDR 0xfc | ||
| 57 | #define W83795_REG_CONFIG 0x01 | ||
| 58 | #define W83795_REG_CONFIG_CONFIG48 0x04 | ||
| 59 | #define W83795_REG_CONFIG_START 0x01 | ||
| 60 | |||
| 61 | /* Multi-Function Pin Ctrl Registers */ | ||
| 62 | #define W83795_REG_VOLT_CTRL1 0x02 | ||
| 63 | #define W83795_REG_VOLT_CTRL2 0x03 | ||
| 64 | #define W83795_REG_TEMP_CTRL1 0x04 | ||
| 65 | #define W83795_REG_TEMP_CTRL2 0x05 | ||
| 66 | #define W83795_REG_FANIN_CTRL1 0x06 | ||
| 67 | #define W83795_REG_FANIN_CTRL2 0x07 | ||
| 68 | #define W83795_REG_VMIGB_CTRL 0x08 | ||
| 69 | |||
| 70 | #define TEMP_READ 0 | ||
| 71 | #define TEMP_CRIT 1 | ||
| 72 | #define TEMP_CRIT_HYST 2 | ||
| 73 | #define TEMP_WARN 3 | ||
| 74 | #define TEMP_WARN_HYST 4 | ||
| 75 | /* only crit and crit_hyst affect real-time alarm status | ||
| 76 | * current crit crit_hyst warn warn_hyst */ | ||
| 77 | static const u16 W83795_REG_TEMP[][5] = { | ||
| 78 | {0x21, 0x96, 0x97, 0x98, 0x99}, /* TD1/TR1 */ | ||
| 79 | {0x22, 0x9a, 0x9b, 0x9c, 0x9d}, /* TD2/TR2 */ | ||
| 80 | {0x23, 0x9e, 0x9f, 0xa0, 0xa1}, /* TD3/TR3 */ | ||
| 81 | {0x24, 0xa2, 0xa3, 0xa4, 0xa5}, /* TD4/TR4 */ | ||
| 82 | {0x1f, 0xa6, 0xa7, 0xa8, 0xa9}, /* TR5 */ | ||
| 83 | {0x20, 0xaa, 0xab, 0xac, 0xad}, /* TR6 */ | ||
| 84 | }; | ||
| 85 | |||
| 86 | #define IN_READ 0 | ||
| 87 | #define IN_MAX 1 | ||
| 88 | #define IN_LOW 2 | ||
| 89 | static const u16 W83795_REG_IN[][3] = { | ||
| 90 | /* Current, HL, LL */ | ||
| 91 | {0x10, 0x70, 0x71}, /* VSEN1 */ | ||
| 92 | {0x11, 0x72, 0x73}, /* VSEN2 */ | ||
| 93 | {0x12, 0x74, 0x75}, /* VSEN3 */ | ||
| 94 | {0x13, 0x76, 0x77}, /* VSEN4 */ | ||
| 95 | {0x14, 0x78, 0x79}, /* VSEN5 */ | ||
| 96 | {0x15, 0x7a, 0x7b}, /* VSEN6 */ | ||
| 97 | {0x16, 0x7c, 0x7d}, /* VSEN7 */ | ||
| 98 | {0x17, 0x7e, 0x7f}, /* VSEN8 */ | ||
| 99 | {0x18, 0x80, 0x81}, /* VSEN9 */ | ||
| 100 | {0x19, 0x82, 0x83}, /* VSEN10 */ | ||
| 101 | {0x1A, 0x84, 0x85}, /* VSEN11 */ | ||
| 102 | {0x1B, 0x86, 0x87}, /* VTT */ | ||
| 103 | {0x1C, 0x88, 0x89}, /* 3VDD */ | ||
| 104 | {0x1D, 0x8a, 0x8b}, /* 3VSB */ | ||
| 105 | {0x1E, 0x8c, 0x8d}, /* VBAT */ | ||
| 106 | {0x1F, 0xa6, 0xa7}, /* VSEN12 */ | ||
| 107 | {0x20, 0xaa, 0xab}, /* VSEN13 */ | ||
| 108 | {0x21, 0x96, 0x97}, /* VSEN14 */ | ||
| 109 | {0x22, 0x9a, 0x9b}, /* VSEN15 */ | ||
| 110 | {0x23, 0x9e, 0x9f}, /* VSEN16 */ | ||
| 111 | {0x24, 0xa2, 0xa3}, /* VSEN17 */ | ||
| 112 | }; | ||
| 113 | #define W83795_REG_VRLSB 0x3C | ||
| 114 | |||
| 115 | static const u8 W83795_REG_IN_HL_LSB[] = { | ||
| 116 | 0x8e, /* VSEN1-4 */ | ||
| 117 | 0x90, /* VSEN5-8 */ | ||
| 118 | 0x92, /* VSEN9-11 */ | ||
| 119 | 0x94, /* VTT, 3VDD, 3VSB, 3VBAT */ | ||
| 120 | 0xa8, /* VSEN12 */ | ||
| 121 | 0xac, /* VSEN13 */ | ||
| 122 | 0x98, /* VSEN14 */ | ||
| 123 | 0x9c, /* VSEN15 */ | ||
| 124 | 0xa0, /* VSEN16 */ | ||
| 125 | 0xa4, /* VSEN17 */ | ||
| 126 | }; | ||
| 127 | |||
| 128 | #define IN_LSB_REG(index, type) \ | ||
| 129 | (((type) == 1) ? W83795_REG_IN_HL_LSB[(index)] \ | ||
| 130 | : (W83795_REG_IN_HL_LSB[(index)] + 1)) | ||
| 131 | |||
| 132 | #define IN_LSB_SHIFT 0 | ||
| 133 | #define IN_LSB_IDX 1 | ||
| 134 | static const u8 IN_LSB_SHIFT_IDX[][2] = { | ||
| 135 | /* High/Low LSB shift, LSB No. */ | ||
| 136 | {0x00, 0x00}, /* VSEN1 */ | ||
| 137 | {0x02, 0x00}, /* VSEN2 */ | ||
| 138 | {0x04, 0x00}, /* VSEN3 */ | ||
| 139 | {0x06, 0x00}, /* VSEN4 */ | ||
| 140 | {0x00, 0x01}, /* VSEN5 */ | ||
| 141 | {0x02, 0x01}, /* VSEN6 */ | ||
| 142 | {0x04, 0x01}, /* VSEN7 */ | ||
| 143 | {0x06, 0x01}, /* VSEN8 */ | ||
| 144 | {0x00, 0x02}, /* VSEN9 */ | ||
| 145 | {0x02, 0x02}, /* VSEN10 */ | ||
| 146 | {0x04, 0x02}, /* VSEN11 */ | ||
| 147 | {0x00, 0x03}, /* VTT */ | ||
| 148 | {0x02, 0x03}, /* 3VDD */ | ||
| 149 | {0x04, 0x03}, /* 3VSB */ | ||
| 150 | {0x06, 0x03}, /* VBAT */ | ||
| 151 | {0x06, 0x04}, /* VSEN12 */ | ||
| 152 | {0x06, 0x05}, /* VSEN13 */ | ||
| 153 | {0x06, 0x06}, /* VSEN14 */ | ||
| 154 | {0x06, 0x07}, /* VSEN15 */ | ||
| 155 | {0x06, 0x08}, /* VSEN16 */ | ||
| 156 | {0x06, 0x09}, /* VSEN17 */ | ||
| 157 | }; | ||
| 158 | |||
| 159 | |||
| 160 | #define W83795_REG_FAN(index) (0x2E + (index)) | ||
| 161 | #define W83795_REG_FAN_MIN_HL(index) (0xB6 + (index)) | ||
| 162 | #define W83795_REG_FAN_MIN_LSB(index) (0xC4 + (index) / 2) | ||
| 163 | #define W83795_REG_FAN_MIN_LSB_SHIFT(index) \ | ||
| 164 | (((index) & 1) ? 4 : 0) | ||
| 165 | |||
| 166 | #define W83795_REG_VID_CTRL 0x6A | ||
| 167 | |||
| 168 | #define W83795_REG_ALARM(index) (0x41 + (index)) | ||
| 169 | #define W83795_REG_BEEP(index) (0x50 + (index)) | ||
| 170 | |||
| 171 | #define W83795_REG_CLR_CHASSIS 0x4D | ||
| 172 | |||
| 173 | |||
| 174 | #define W83795_REG_FCMS1 0x201 | ||
| 175 | #define W83795_REG_FCMS2 0x208 | ||
| 176 | #define W83795_REG_TFMR(index) (0x202 + (index)) | ||
| 177 | #define W83795_REG_FOMC 0x20F | ||
| 178 | |||
| 179 | #define W83795_REG_TSS(index) (0x209 + (index)) | ||
| 180 | |||
| 181 | #define PWM_OUTPUT 0 | ||
| 182 | #define PWM_FREQ 1 | ||
| 183 | #define PWM_START 2 | ||
| 184 | #define PWM_NONSTOP 3 | ||
| 185 | #define PWM_STOP_TIME 4 | ||
| 186 | #define W83795_REG_PWM(index, nr) (0x210 + (nr) * 8 + (index)) | ||
| 187 | |||
| 188 | #define W83795_REG_FTSH(index) (0x240 + (index) * 2) | ||
| 189 | #define W83795_REG_FTSL(index) (0x241 + (index) * 2) | ||
| 190 | #define W83795_REG_TFTS 0x250 | ||
| 191 | |||
| 192 | #define TEMP_PWM_TTTI 0 | ||
| 193 | #define TEMP_PWM_CTFS 1 | ||
| 194 | #define TEMP_PWM_HCT 2 | ||
| 195 | #define TEMP_PWM_HOT 3 | ||
| 196 | #define W83795_REG_TTTI(index) (0x260 + (index)) | ||
| 197 | #define W83795_REG_CTFS(index) (0x268 + (index)) | ||
| 198 | #define W83795_REG_HT(index) (0x270 + (index)) | ||
| 199 | |||
| 200 | #define SF4_TEMP 0 | ||
| 201 | #define SF4_PWM 1 | ||
| 202 | #define W83795_REG_SF4_TEMP(temp_num, index) \ | ||
| 203 | (0x280 + 0x10 * (temp_num) + (index)) | ||
| 204 | #define W83795_REG_SF4_PWM(temp_num, index) \ | ||
| 205 | (0x288 + 0x10 * (temp_num) + (index)) | ||
| 206 | |||
| 207 | #define W83795_REG_DTSC 0x301 | ||
| 208 | #define W83795_REG_DTSE 0x302 | ||
| 209 | #define W83795_REG_DTS(index) (0x26 + (index)) | ||
| 210 | #define W83795_REG_PECI_TBASE(index) (0x320 + (index)) | ||
| 211 | |||
| 212 | #define DTS_CRIT 0 | ||
| 213 | #define DTS_CRIT_HYST 1 | ||
| 214 | #define DTS_WARN 2 | ||
| 215 | #define DTS_WARN_HYST 3 | ||
| 216 | #define W83795_REG_DTS_EXT(index) (0xB2 + (index)) | ||
| 217 | |||
| 218 | #define SETUP_PWM_DEFAULT 0 | ||
| 219 | #define SETUP_PWM_UPTIME 1 | ||
| 220 | #define SETUP_PWM_DOWNTIME 2 | ||
| 221 | #define W83795_REG_SETUP_PWM(index) (0x20C + (index)) | ||
| 222 | |||
| 223 | static inline u16 in_from_reg(u8 index, u16 val) | ||
| 224 | { | ||
| 225 | /* 3VDD, 3VSB and VBAT: 6 mV/bit; other inputs: 2 mV/bit */ | ||
| 226 | if (index >= 12 && index <= 14) | ||
| 227 | return val * 6; | ||
| 228 | else | ||
| 229 | return val * 2; | ||
| 230 | } | ||
| 231 | |||
| 232 | static inline u16 in_to_reg(u8 index, u16 val) | ||
| 233 | { | ||
| 234 | if (index >= 12 && index <= 14) | ||
| 235 | return val / 6; | ||
| 236 | else | ||
| 237 | return val / 2; | ||
| 238 | } | ||
| 239 | |||
| 240 | static inline unsigned long fan_from_reg(u16 val) | ||
| 241 | { | ||
| 242 | if ((val == 0xfff) || (val == 0)) | ||
| 243 | return 0; | ||
| 244 | return 1350000UL / val; | ||
| 245 | } | ||
| 246 | |||
| 247 | static inline u16 fan_to_reg(long rpm) | ||
| 248 | { | ||
| 249 | if (rpm <= 0) | ||
| 250 | return 0x0fff; | ||
| 251 | return SENSORS_LIMIT((1350000 + (rpm >> 1)) / rpm, 1, 0xffe); | ||
| 252 | } | ||
| 253 | |||
| 254 | static inline unsigned long time_from_reg(u8 reg) | ||
| 255 | { | ||
| 256 | return reg * 100; | ||
| 257 | } | ||
| 258 | |||
| 259 | static inline u8 time_to_reg(unsigned long val) | ||
| 260 | { | ||
| 261 | return SENSORS_LIMIT((val + 50) / 100, 0, 0xff); | ||
| 262 | } | ||
| 263 | |||
| 264 | static inline long temp_from_reg(s8 reg) | ||
| 265 | { | ||
| 266 | return reg * 1000; | ||
| 267 | } | ||
| 268 | |||
| 269 | static inline s8 temp_to_reg(long val, s8 min, s8 max) | ||
| 270 | { | ||
| 271 | return SENSORS_LIMIT(val / 1000, min, max); | ||
| 272 | } | ||
| 273 | |||
| 274 | static const u16 pwm_freq_cksel0[16] = { | ||
| 275 | 1024, 512, 341, 256, 205, 171, 146, 128, | ||
| 276 | 85, 64, 32, 16, 8, 4, 2, 1 | ||
| 277 | }; | ||
| 278 | |||
| 279 | static unsigned int pwm_freq_from_reg(u8 reg, u16 clkin) | ||
| 280 | { | ||
| 281 | unsigned long base_clock; | ||
| 282 | |||
| 283 | if (reg & 0x80) { | ||
| 284 | base_clock = clkin * 1000 / ((clkin == 48000) ? 384 : 256); | ||
| 285 | return base_clock / ((reg & 0x7f) + 1); | ||
| 286 | } else | ||
| 287 | return pwm_freq_cksel0[reg & 0x0f]; | ||
| 288 | } | ||
| 289 | |||
| 290 | static u8 pwm_freq_to_reg(unsigned long val, u16 clkin) | ||
| 291 | { | ||
| 292 | unsigned long base_clock; | ||
| 293 | u8 reg0, reg1; | ||
| 294 | unsigned long best0, best1; | ||
| 295 | |||
| 296 | /* Best fit for cksel = 0 */ | ||
| 297 | for (reg0 = 0; reg0 < ARRAY_SIZE(pwm_freq_cksel0) - 1; reg0++) { | ||
| 298 | if (val > (pwm_freq_cksel0[reg0] + | ||
| 299 | pwm_freq_cksel0[reg0 + 1]) / 2) | ||
| 300 | break; | ||
| 301 | } | ||
| 302 | if (val < 375) /* cksel = 1 can't beat this */ | ||
| 303 | return reg0; | ||
| 304 | best0 = pwm_freq_cksel0[reg0]; | ||
| 305 | |||
| 306 | /* Best fit for cksel = 1 */ | ||
| 307 | base_clock = clkin * 1000 / ((clkin == 48000) ? 384 : 256); | ||
| 308 | reg1 = SENSORS_LIMIT(DIV_ROUND_CLOSEST(base_clock, val), 1, 128); | ||
| 309 | best1 = base_clock / reg1; | ||
| 310 | reg1 = 0x80 | (reg1 - 1); | ||
| 311 | |||
| 312 | /* Choose the closest one */ | ||
| 313 | if (abs(val - best0) > abs(val - best1)) | ||
| 314 | return reg1; | ||
| 315 | else | ||
| 316 | return reg0; | ||
| 317 | } | ||
| 318 | |||
| 319 | enum chip_types {w83795g, w83795adg}; | ||
| 320 | |||
| 321 | struct w83795_data { | ||
| 322 | struct device *hwmon_dev; | ||
| 323 | struct mutex update_lock; | ||
| 324 | unsigned long last_updated; /* In jiffies */ | ||
| 325 | enum chip_types chip_type; | ||
| 326 | |||
| 327 | u8 bank; | ||
| 328 | |||
| 329 | u32 has_in; /* Enable monitor VIN or not */ | ||
| 330 | u8 has_dyn_in; /* Only in2-0 can have this */ | ||
| 331 | u16 in[21][3]; /* Register value, read/high/low */ | ||
| 332 | u8 in_lsb[10][3]; /* LSB Register value, high/low */ | ||
| 333 | u8 has_gain; /* has gain: in17-20 * 8 */ | ||
| 334 | |||
| 335 | u16 has_fan; /* Enable fan14-1 or not */ | ||
| 336 | u16 fan[14]; /* Register value combine */ | ||
| 337 | u16 fan_min[14]; /* Register value combine */ | ||
| 338 | |||
| 339 | u8 has_temp; /* Enable monitor temp6-1 or not */ | ||
| 340 | s8 temp[6][5]; /* current, crit, crit_hyst, warn, warn_hyst */ | ||
| 341 | u8 temp_read_vrlsb[6]; | ||
| 342 | u8 temp_mode; /* Bit vector, 0 = TR, 1 = TD */ | ||
| 343 | u8 temp_src[3]; /* Register value */ | ||
| 344 | |||
| 345 | u8 enable_dts; /* Enable PECI and SB-TSI, | ||
| 346 | * bit 0: =1 enable, =0 disable, | ||
| 347 | * bit 1: =1 AMD SB-TSI, =0 Intel PECI */ | ||
| 348 | u8 has_dts; /* Enable monitor DTS temp */ | ||
| 349 | s8 dts[8]; /* Register value */ | ||
| 350 | u8 dts_read_vrlsb[8]; /* Register value */ | ||
| 351 | s8 dts_ext[4]; /* Register value */ | ||
| 352 | |||
| 353 | u8 has_pwm; /* 795g supports 8 pwm, 795adg only supports 2, | ||
| 354 | * no config register, only affected by chip | ||
| 355 | * type */ | ||
| 356 | u8 pwm[8][5]; /* Register value, output, freq, start, | ||
| 357 | * non stop, stop time */ | ||
| 358 | u16 clkin; /* CLKIN frequency in kHz */ | ||
| 359 | u8 pwm_fcms[2]; /* Register value */ | ||
| 360 | u8 pwm_tfmr[6]; /* Register value */ | ||
| 361 | u8 pwm_fomc; /* Register value */ | ||
| 362 | |||
| 363 | u16 target_speed[8]; /* Register value, target speed for speed | ||
| 364 | * cruise */ | ||
| 365 | u8 tol_speed; /* tolerance of target speed */ | ||
| 366 | u8 pwm_temp[6][4]; /* TTTI, CTFS, HCT, HOT */ | ||
| 367 | u8 sf4_reg[6][2][7]; /* 6 temp, temp/dcpwm, 7 registers */ | ||
| 368 | |||
| 369 | u8 setup_pwm[3]; /* Register value */ | ||
| 370 | |||
| 371 | u8 alarms[6]; /* Register value */ | ||
| 372 | u8 beeps[6]; /* Register value */ | ||
| 373 | |||
| 374 | char valid; | ||
| 375 | char valid_limits; | ||
| 376 | char valid_pwm_config; | ||
| 377 | }; | ||
| 378 | |||
| 379 | /* | ||
| 380 | * Hardware access | ||
| 381 | * We assume that nobdody can change the bank outside the driver. | ||
| 382 | */ | ||
| 383 | |||
| 384 | /* Must be called with data->update_lock held, except during initialization */ | ||
| 385 | static int w83795_set_bank(struct i2c_client *client, u8 bank) | ||
| 386 | { | ||
| 387 | struct w83795_data *data = i2c_get_clientdata(client); | ||
| 388 | int err; | ||
| 389 | |||
| 390 | /* If the same bank is already set, nothing to do */ | ||
| 391 | if ((data->bank & 0x07) == bank) | ||
| 392 | return 0; | ||
| 393 | |||
| 394 | /* Change to new bank, preserve all other bits */ | ||
| 395 | bank |= data->bank & ~0x07; | ||
| 396 | err = i2c_smbus_write_byte_data(client, W83795_REG_BANKSEL, bank); | ||
| 397 | if (err < 0) { | ||
| 398 | dev_err(&client->dev, | ||
| 399 | "Failed to set bank to %d, err %d\n", | ||
| 400 | (int)bank, err); | ||
| 401 | return err; | ||
| 402 | } | ||
| 403 | data->bank = bank; | ||
| 404 | |||
| 405 | return 0; | ||
| 406 | } | ||
| 407 | |||
| 408 | /* Must be called with data->update_lock held, except during initialization */ | ||
| 409 | static u8 w83795_read(struct i2c_client *client, u16 reg) | ||
| 410 | { | ||
| 411 | int err; | ||
| 412 | |||
| 413 | err = w83795_set_bank(client, reg >> 8); | ||
| 414 | if (err < 0) | ||
| 415 | return 0x00; /* Arbitrary */ | ||
| 416 | |||
| 417 | err = i2c_smbus_read_byte_data(client, reg & 0xff); | ||
| 418 | if (err < 0) { | ||
| 419 | dev_err(&client->dev, | ||
| 420 | "Failed to read from register 0x%03x, err %d\n", | ||
| 421 | (int)reg, err); | ||
| 422 | return 0x00; /* Arbitrary */ | ||
| 423 | } | ||
| 424 | return err; | ||
| 425 | } | ||
| 426 | |||
| 427 | /* Must be called with data->update_lock held, except during initialization */ | ||
| 428 | static int w83795_write(struct i2c_client *client, u16 reg, u8 value) | ||
| 429 | { | ||
| 430 | int err; | ||
| 431 | |||
| 432 | err = w83795_set_bank(client, reg >> 8); | ||
| 433 | if (err < 0) | ||
| 434 | return err; | ||
| 435 | |||
| 436 | err = i2c_smbus_write_byte_data(client, reg & 0xff, value); | ||
| 437 | if (err < 0) | ||
| 438 | dev_err(&client->dev, | ||
| 439 | "Failed to write to register 0x%03x, err %d\n", | ||
| 440 | (int)reg, err); | ||
| 441 | return err; | ||
| 442 | } | ||
| 443 | |||
| 444 | static void w83795_update_limits(struct i2c_client *client) | ||
| 445 | { | ||
| 446 | struct w83795_data *data = i2c_get_clientdata(client); | ||
| 447 | int i, limit; | ||
| 448 | |||
| 449 | /* Read the voltage limits */ | ||
| 450 | for (i = 0; i < ARRAY_SIZE(data->in); i++) { | ||
| 451 | if (!(data->has_in & (1 << i))) | ||
| 452 | continue; | ||
| 453 | data->in[i][IN_MAX] = | ||
| 454 | w83795_read(client, W83795_REG_IN[i][IN_MAX]); | ||
| 455 | data->in[i][IN_LOW] = | ||
| 456 | w83795_read(client, W83795_REG_IN[i][IN_LOW]); | ||
| 457 | } | ||
| 458 | for (i = 0; i < ARRAY_SIZE(data->in_lsb); i++) { | ||
| 459 | if ((i == 2 && data->chip_type == w83795adg) || | ||
| 460 | (i >= 4 && !(data->has_in & (1 << (i + 11))))) | ||
| 461 | continue; | ||
| 462 | data->in_lsb[i][IN_MAX] = | ||
| 463 | w83795_read(client, IN_LSB_REG(i, IN_MAX)); | ||
| 464 | data->in_lsb[i][IN_LOW] = | ||
| 465 | w83795_read(client, IN_LSB_REG(i, IN_LOW)); | ||
| 466 | } | ||
| 467 | |||
| 468 | /* Read the fan limits */ | ||
| 469 | for (i = 0; i < ARRAY_SIZE(data->fan); i++) { | ||
| 470 | u8 lsb; | ||
| 471 | |||
| 472 | /* Each register contains LSB for 2 fans, but we want to | ||
| 473 | * read it only once to save time */ | ||
| 474 | if ((i & 1) == 0 && (data->has_fan & (3 << i))) | ||
| 475 | lsb = w83795_read(client, W83795_REG_FAN_MIN_LSB(i)); | ||
| 476 | |||
| 477 | if (!(data->has_fan & (1 << i))) | ||
| 478 | continue; | ||
| 479 | data->fan_min[i] = | ||
| 480 | w83795_read(client, W83795_REG_FAN_MIN_HL(i)) << 4; | ||
| 481 | data->fan_min[i] |= | ||
| 482 | (lsb >> W83795_REG_FAN_MIN_LSB_SHIFT(i)) & 0x0F; | ||
| 483 | } | ||
| 484 | |||
| 485 | /* Read the temperature limits */ | ||
| 486 | for (i = 0; i < ARRAY_SIZE(data->temp); i++) { | ||
| 487 | if (!(data->has_temp & (1 << i))) | ||
| 488 | continue; | ||
| 489 | for (limit = TEMP_CRIT; limit <= TEMP_WARN_HYST; limit++) | ||
| 490 | data->temp[i][limit] = | ||
| 491 | w83795_read(client, W83795_REG_TEMP[i][limit]); | ||
| 492 | } | ||
| 493 | |||
| 494 | /* Read the DTS limits */ | ||
| 495 | if (data->enable_dts) { | ||
| 496 | for (limit = DTS_CRIT; limit <= DTS_WARN_HYST; limit++) | ||
| 497 | data->dts_ext[limit] = | ||
| 498 | w83795_read(client, W83795_REG_DTS_EXT(limit)); | ||
| 499 | } | ||
| 500 | |||
| 501 | /* Read beep settings */ | ||
| 502 | for (i = 0; i < ARRAY_SIZE(data->beeps); i++) | ||
| 503 | data->beeps[i] = w83795_read(client, W83795_REG_BEEP(i)); | ||
| 504 | |||
| 505 | data->valid_limits = 1; | ||
| 506 | } | ||
| 507 | |||
| 508 | static struct w83795_data *w83795_update_pwm_config(struct device *dev) | ||
| 509 | { | ||
| 510 | struct i2c_client *client = to_i2c_client(dev); | ||
| 511 | struct w83795_data *data = i2c_get_clientdata(client); | ||
| 512 | int i, tmp; | ||
| 513 | |||
| 514 | mutex_lock(&data->update_lock); | ||
| 515 | |||
| 516 | if (data->valid_pwm_config) | ||
| 517 | goto END; | ||
| 518 | |||
| 519 | /* Read temperature source selection */ | ||
| 520 | for (i = 0; i < ARRAY_SIZE(data->temp_src); i++) | ||
| 521 | data->temp_src[i] = w83795_read(client, W83795_REG_TSS(i)); | ||
| 522 | |||
| 523 | /* Read automatic fan speed control settings */ | ||
| 524 | data->pwm_fcms[0] = w83795_read(client, W83795_REG_FCMS1); | ||
| 525 | data->pwm_fcms[1] = w83795_read(client, W83795_REG_FCMS2); | ||
| 526 | for (i = 0; i < ARRAY_SIZE(data->pwm_tfmr); i++) | ||
| 527 | data->pwm_tfmr[i] = w83795_read(client, W83795_REG_TFMR(i)); | ||
| 528 | data->pwm_fomc = w83795_read(client, W83795_REG_FOMC); | ||
| 529 | for (i = 0; i < data->has_pwm; i++) { | ||
| 530 | for (tmp = PWM_FREQ; tmp <= PWM_STOP_TIME; tmp++) | ||
| 531 | data->pwm[i][tmp] = | ||
| 532 | w83795_read(client, W83795_REG_PWM(i, tmp)); | ||
| 533 | } | ||
| 534 | for (i = 0; i < ARRAY_SIZE(data->target_speed); i++) { | ||
| 535 | data->target_speed[i] = | ||
| 536 | w83795_read(client, W83795_REG_FTSH(i)) << 4; | ||
| 537 | data->target_speed[i] |= | ||
| 538 | w83795_read(client, W83795_REG_FTSL(i)) >> 4; | ||
| 539 | } | ||
| 540 | data->tol_speed = w83795_read(client, W83795_REG_TFTS) & 0x3f; | ||
| 541 | |||
| 542 | for (i = 0; i < ARRAY_SIZE(data->pwm_temp); i++) { | ||
| 543 | data->pwm_temp[i][TEMP_PWM_TTTI] = | ||
| 544 | w83795_read(client, W83795_REG_TTTI(i)) & 0x7f; | ||
| 545 | data->pwm_temp[i][TEMP_PWM_CTFS] = | ||
| 546 | w83795_read(client, W83795_REG_CTFS(i)); | ||
| 547 | tmp = w83795_read(client, W83795_REG_HT(i)); | ||
| 548 | data->pwm_temp[i][TEMP_PWM_HCT] = tmp >> 4; | ||
| 549 | data->pwm_temp[i][TEMP_PWM_HOT] = tmp & 0x0f; | ||
| 550 | } | ||
| 551 | |||
| 552 | /* Read SmartFanIV trip points */ | ||
| 553 | for (i = 0; i < ARRAY_SIZE(data->sf4_reg); i++) { | ||
| 554 | for (tmp = 0; tmp < 7; tmp++) { | ||
| 555 | data->sf4_reg[i][SF4_TEMP][tmp] = | ||
| 556 | w83795_read(client, | ||
| 557 | W83795_REG_SF4_TEMP(i, tmp)); | ||
| 558 | data->sf4_reg[i][SF4_PWM][tmp] = | ||
| 559 | w83795_read(client, W83795_REG_SF4_PWM(i, tmp)); | ||
| 560 | } | ||
| 561 | } | ||
| 562 | |||
| 563 | /* Read setup PWM */ | ||
| 564 | for (i = 0; i < ARRAY_SIZE(data->setup_pwm); i++) | ||
| 565 | data->setup_pwm[i] = | ||
| 566 | w83795_read(client, W83795_REG_SETUP_PWM(i)); | ||
| 567 | |||
| 568 | data->valid_pwm_config = 1; | ||
| 569 | |||
| 570 | END: | ||
| 571 | mutex_unlock(&data->update_lock); | ||
| 572 | return data; | ||
| 573 | } | ||
| 574 | |||
| 575 | static struct w83795_data *w83795_update_device(struct device *dev) | ||
| 576 | { | ||
| 577 | struct i2c_client *client = to_i2c_client(dev); | ||
| 578 | struct w83795_data *data = i2c_get_clientdata(client); | ||
| 579 | u16 tmp; | ||
| 580 | int i; | ||
| 581 | |||
| 582 | mutex_lock(&data->update_lock); | ||
| 583 | |||
| 584 | if (!data->valid_limits) | ||
| 585 | w83795_update_limits(client); | ||
| 586 | |||
| 587 | if (!(time_after(jiffies, data->last_updated + HZ * 2) | ||
| 588 | || !data->valid)) | ||
| 589 | goto END; | ||
| 590 | |||
| 591 | /* Update the voltages value */ | ||
| 592 | for (i = 0; i < ARRAY_SIZE(data->in); i++) { | ||
| 593 | if (!(data->has_in & (1 << i))) | ||
| 594 | continue; | ||
| 595 | tmp = w83795_read(client, W83795_REG_IN[i][IN_READ]) << 2; | ||
| 596 | tmp |= w83795_read(client, W83795_REG_VRLSB) >> 6; | ||
| 597 | data->in[i][IN_READ] = tmp; | ||
| 598 | } | ||
| 599 | |||
| 600 | /* in0-2 can have dynamic limits (W83795G only) */ | ||
| 601 | if (data->has_dyn_in) { | ||
| 602 | u8 lsb_max = w83795_read(client, IN_LSB_REG(0, IN_MAX)); | ||
| 603 | u8 lsb_low = w83795_read(client, IN_LSB_REG(0, IN_LOW)); | ||
| 604 | |||
| 605 | for (i = 0; i < 3; i++) { | ||
| 606 | if (!(data->has_dyn_in & (1 << i))) | ||
| 607 | continue; | ||
| 608 | data->in[i][IN_MAX] = | ||
| 609 | w83795_read(client, W83795_REG_IN[i][IN_MAX]); | ||
| 610 | data->in[i][IN_LOW] = | ||
| 611 | w83795_read(client, W83795_REG_IN[i][IN_LOW]); | ||
| 612 | data->in_lsb[i][IN_MAX] = (lsb_max >> (2 * i)) & 0x03; | ||
| 613 | data->in_lsb[i][IN_LOW] = (lsb_low >> (2 * i)) & 0x03; | ||
| 614 | } | ||
| 615 | } | ||
| 616 | |||
| 617 | /* Update fan */ | ||
| 618 | for (i = 0; i < ARRAY_SIZE(data->fan); i++) { | ||
| 619 | if (!(data->has_fan & (1 << i))) | ||
| 620 | continue; | ||
| 621 | data->fan[i] = w83795_read(client, W83795_REG_FAN(i)) << 4; | ||
| 622 | data->fan[i] |= w83795_read(client, W83795_REG_VRLSB) >> 4; | ||
| 623 | } | ||
| 624 | |||
| 625 | /* Update temperature */ | ||
| 626 | for (i = 0; i < ARRAY_SIZE(data->temp); i++) { | ||
| 627 | data->temp[i][TEMP_READ] = | ||
| 628 | w83795_read(client, W83795_REG_TEMP[i][TEMP_READ]); | ||
| 629 | data->temp_read_vrlsb[i] = | ||
| 630 | w83795_read(client, W83795_REG_VRLSB); | ||
| 631 | } | ||
| 632 | |||
| 633 | /* Update dts temperature */ | ||
| 634 | if (data->enable_dts) { | ||
| 635 | for (i = 0; i < ARRAY_SIZE(data->dts); i++) { | ||
| 636 | if (!(data->has_dts & (1 << i))) | ||
| 637 | continue; | ||
| 638 | data->dts[i] = | ||
| 639 | w83795_read(client, W83795_REG_DTS(i)); | ||
| 640 | data->dts_read_vrlsb[i] = | ||
| 641 | w83795_read(client, W83795_REG_VRLSB); | ||
| 642 | } | ||
| 643 | } | ||
| 644 | |||
| 645 | /* Update pwm output */ | ||
| 646 | for (i = 0; i < data->has_pwm; i++) { | ||
| 647 | data->pwm[i][PWM_OUTPUT] = | ||
| 648 | w83795_read(client, W83795_REG_PWM(i, PWM_OUTPUT)); | ||
| 649 | } | ||
| 650 | |||
| 651 | /* update alarm */ | ||
| 652 | for (i = 0; i < ARRAY_SIZE(data->alarms); i++) | ||
| 653 | data->alarms[i] = w83795_read(client, W83795_REG_ALARM(i)); | ||
| 654 | |||
| 655 | data->last_updated = jiffies; | ||
| 656 | data->valid = 1; | ||
| 657 | |||
| 658 | END: | ||
| 659 | mutex_unlock(&data->update_lock); | ||
| 660 | return data; | ||
| 661 | } | ||
| 662 | |||
| 663 | /* | ||
| 664 | * Sysfs attributes | ||
| 665 | */ | ||
| 666 | |||
| 667 | #define ALARM_STATUS 0 | ||
| 668 | #define BEEP_ENABLE 1 | ||
| 669 | static ssize_t | ||
| 670 | show_alarm_beep(struct device *dev, struct device_attribute *attr, char *buf) | ||
| 671 | { | ||
| 672 | struct w83795_data *data = w83795_update_device(dev); | ||
| 673 | struct sensor_device_attribute_2 *sensor_attr = | ||
| 674 | to_sensor_dev_attr_2(attr); | ||
| 675 | int nr = sensor_attr->nr; | ||
| 676 | int index = sensor_attr->index >> 3; | ||
| 677 | int bit = sensor_attr->index & 0x07; | ||
| 678 | u8 val; | ||
| 679 | |||
| 680 | if (nr == ALARM_STATUS) | ||
| 681 | val = (data->alarms[index] >> bit) & 1; | ||
| 682 | else /* BEEP_ENABLE */ | ||
| 683 | val = (data->beeps[index] >> bit) & 1; | ||
| 684 | |||
| 685 | return sprintf(buf, "%u\n", val); | ||
| 686 | } | ||
| 687 | |||
| 688 | static ssize_t | ||
| 689 | store_beep(struct device *dev, struct device_attribute *attr, | ||
| 690 | const char *buf, size_t count) | ||
| 691 | { | ||
| 692 | struct i2c_client *client = to_i2c_client(dev); | ||
| 693 | struct w83795_data *data = i2c_get_clientdata(client); | ||
| 694 | struct sensor_device_attribute_2 *sensor_attr = | ||
| 695 | to_sensor_dev_attr_2(attr); | ||
| 696 | int index = sensor_attr->index >> 3; | ||
| 697 | int shift = sensor_attr->index & 0x07; | ||
| 698 | u8 beep_bit = 1 << shift; | ||
| 699 | unsigned long val; | ||
| 700 | |||
| 701 | if (strict_strtoul(buf, 10, &val) < 0) | ||
| 702 | return -EINVAL; | ||
| 703 | if (val != 0 && val != 1) | ||
| 704 | return -EINVAL; | ||
| 705 | |||
| 706 | mutex_lock(&data->update_lock); | ||
| 707 | data->beeps[index] = w83795_read(client, W83795_REG_BEEP(index)); | ||
| 708 | data->beeps[index] &= ~beep_bit; | ||
| 709 | data->beeps[index] |= val << shift; | ||
| 710 | w83795_write(client, W83795_REG_BEEP(index), data->beeps[index]); | ||
| 711 | mutex_unlock(&data->update_lock); | ||
| 712 | |||
| 713 | return count; | ||
| 714 | } | ||
| 715 | |||
| 716 | /* Write 0 to clear chassis alarm */ | ||
| 717 | static ssize_t | ||
| 718 | store_chassis_clear(struct device *dev, | ||
| 719 | struct device_attribute *attr, const char *buf, | ||
| 720 | size_t count) | ||
| 721 | { | ||
| 722 | struct i2c_client *client = to_i2c_client(dev); | ||
| 723 | struct w83795_data *data = i2c_get_clientdata(client); | ||
| 724 | unsigned long val; | ||
| 725 | |||
| 726 | if (strict_strtoul(buf, 10, &val) < 0 || val != 0) | ||
| 727 | return -EINVAL; | ||
| 728 | |||
| 729 | mutex_lock(&data->update_lock); | ||
| 730 | val = w83795_read(client, W83795_REG_CLR_CHASSIS); | ||
| 731 | val |= 0x80; | ||
| 732 | w83795_write(client, W83795_REG_CLR_CHASSIS, val); | ||
| 733 | mutex_unlock(&data->update_lock); | ||
| 734 | return count; | ||
| 735 | } | ||
| 736 | |||
| 737 | #define FAN_INPUT 0 | ||
| 738 | #define FAN_MIN 1 | ||
| 739 | static ssize_t | ||
| 740 | show_fan(struct device *dev, struct device_attribute *attr, char *buf) | ||
| 741 | { | ||
| 742 | struct sensor_device_attribute_2 *sensor_attr = | ||
| 743 | to_sensor_dev_attr_2(attr); | ||
| 744 | int nr = sensor_attr->nr; | ||
| 745 | int index = sensor_attr->index; | ||
| 746 | struct w83795_data *data = w83795_update_device(dev); | ||
| 747 | u16 val; | ||
| 748 | |||
| 749 | if (nr == FAN_INPUT) | ||
| 750 | val = data->fan[index] & 0x0fff; | ||
| 751 | else | ||
| 752 | val = data->fan_min[index] & 0x0fff; | ||
| 753 | |||
| 754 | return sprintf(buf, "%lu\n", fan_from_reg(val)); | ||
| 755 | } | ||
| 756 | |||
| 757 | static ssize_t | ||
| 758 | store_fan_min(struct device *dev, struct device_attribute *attr, | ||
| 759 | const char *buf, size_t count) | ||
| 760 | { | ||
| 761 | struct sensor_device_attribute_2 *sensor_attr = | ||
| 762 | to_sensor_dev_attr_2(attr); | ||
| 763 | int index = sensor_attr->index; | ||
| 764 | struct i2c_client *client = to_i2c_client(dev); | ||
| 765 | struct w83795_data *data = i2c_get_clientdata(client); | ||
| 766 | unsigned long val; | ||
| 767 | |||
| 768 | if (strict_strtoul(buf, 10, &val)) | ||
| 769 | return -EINVAL; | ||
| 770 | val = fan_to_reg(val); | ||
| 771 | |||
| 772 | mutex_lock(&data->update_lock); | ||
| 773 | data->fan_min[index] = val; | ||
| 774 | w83795_write(client, W83795_REG_FAN_MIN_HL(index), (val >> 4) & 0xff); | ||
| 775 | val &= 0x0f; | ||
| 776 | if (index & 1) { | ||
| 777 | val <<= 4; | ||
| 778 | val |= w83795_read(client, W83795_REG_FAN_MIN_LSB(index)) | ||
| 779 | & 0x0f; | ||
| 780 | } else { | ||
| 781 | val |= w83795_read(client, W83795_REG_FAN_MIN_LSB(index)) | ||
| 782 | & 0xf0; | ||
| 783 | } | ||
| 784 | w83795_write(client, W83795_REG_FAN_MIN_LSB(index), val & 0xff); | ||
| 785 | mutex_unlock(&data->update_lock); | ||
| 786 | |||
| 787 | return count; | ||
| 788 | } | ||
| 789 | |||
| 790 | static ssize_t | ||
| 791 | show_pwm(struct device *dev, struct device_attribute *attr, char *buf) | ||
| 792 | { | ||
| 793 | struct w83795_data *data; | ||
| 794 | struct sensor_device_attribute_2 *sensor_attr = | ||
| 795 | to_sensor_dev_attr_2(attr); | ||
| 796 | int nr = sensor_attr->nr; | ||
| 797 | int index = sensor_attr->index; | ||
| 798 | unsigned int val; | ||
| 799 | |||
| 800 | data = nr == PWM_OUTPUT ? w83795_update_device(dev) | ||
| 801 | : w83795_update_pwm_config(dev); | ||
| 802 | |||
| 803 | switch (nr) { | ||
| 804 | case PWM_STOP_TIME: | ||
| 805 | val = time_from_reg(data->pwm[index][nr]); | ||
| 806 | break; | ||
| 807 | case PWM_FREQ: | ||
| 808 | val = pwm_freq_from_reg(data->pwm[index][nr], data->clkin); | ||
| 809 | break; | ||
| 810 | default: | ||
| 811 | val = data->pwm[index][nr]; | ||
| 812 | break; | ||
| 813 | } | ||
| 814 | |||
| 815 | return sprintf(buf, "%u\n", val); | ||
| 816 | } | ||
| 817 | |||
| 818 | static ssize_t | ||
| 819 | store_pwm(struct device *dev, struct device_attribute *attr, | ||
| 820 | const char *buf, size_t count) | ||
| 821 | { | ||
| 822 | struct i2c_client *client = to_i2c_client(dev); | ||
| 823 | struct w83795_data *data = i2c_get_clientdata(client); | ||
| 824 | struct sensor_device_attribute_2 *sensor_attr = | ||
| 825 | to_sensor_dev_attr_2(attr); | ||
| 826 | int nr = sensor_attr->nr; | ||
| 827 | int index = sensor_attr->index; | ||
| 828 | unsigned long val; | ||
| 829 | |||
| 830 | if (strict_strtoul(buf, 10, &val) < 0) | ||
| 831 | return -EINVAL; | ||
| 832 | |||
| 833 | mutex_lock(&data->update_lock); | ||
| 834 | switch (nr) { | ||
| 835 | case PWM_STOP_TIME: | ||
| 836 | val = time_to_reg(val); | ||
| 837 | break; | ||
| 838 | case PWM_FREQ: | ||
| 839 | val = pwm_freq_to_reg(val, data->clkin); | ||
| 840 | break; | ||
| 841 | default: | ||
| 842 | val = SENSORS_LIMIT(val, 0, 0xff); | ||
| 843 | break; | ||
| 844 | } | ||
| 845 | w83795_write(client, W83795_REG_PWM(index, nr), val); | ||
| 846 | data->pwm[index][nr] = val; | ||
| 847 | mutex_unlock(&data->update_lock); | ||
| 848 | return count; | ||
| 849 | } | ||
| 850 | |||
| 851 | static ssize_t | ||
| 852 | show_pwm_enable(struct device *dev, struct device_attribute *attr, char *buf) | ||
| 853 | { | ||
| 854 | struct sensor_device_attribute_2 *sensor_attr = | ||
| 855 | to_sensor_dev_attr_2(attr); | ||
| 856 | struct w83795_data *data = w83795_update_pwm_config(dev); | ||
| 857 | int index = sensor_attr->index; | ||
| 858 | u8 tmp; | ||
| 859 | |||
| 860 | if (1 == (data->pwm_fcms[0] & (1 << index))) { | ||
| 861 | tmp = 2; | ||
| 862 | goto out; | ||
| 863 | } | ||
| 864 | for (tmp = 0; tmp < 6; tmp++) { | ||
| 865 | if (data->pwm_tfmr[tmp] & (1 << index)) { | ||
| 866 | tmp = 3; | ||
| 867 | goto out; | ||
| 868 | } | ||
| 869 | } | ||
| 870 | if (data->pwm_fomc & (1 << index)) | ||
| 871 | tmp = 0; | ||
| 872 | else | ||
| 873 | tmp = 1; | ||
| 874 | |||
| 875 | out: | ||
| 876 | return sprintf(buf, "%u\n", tmp); | ||
| 877 | } | ||
| 878 | |||
| 879 | static ssize_t | ||
| 880 | store_pwm_enable(struct device *dev, struct device_attribute *attr, | ||
| 881 | const char *buf, size_t count) | ||
| 882 | { | ||
| 883 | struct i2c_client *client = to_i2c_client(dev); | ||
| 884 | struct w83795_data *data = w83795_update_pwm_config(dev); | ||
| 885 | struct sensor_device_attribute_2 *sensor_attr = | ||
| 886 | to_sensor_dev_attr_2(attr); | ||
| 887 | int index = sensor_attr->index; | ||
| 888 | unsigned long val; | ||
| 889 | int i; | ||
| 890 | |||
| 891 | if (strict_strtoul(buf, 10, &val) < 0) | ||
| 892 | return -EINVAL; | ||
| 893 | if (val > 2) | ||
| 894 | return -EINVAL; | ||
| 895 | |||
| 896 | mutex_lock(&data->update_lock); | ||
| 897 | switch (val) { | ||
| 898 | case 0: | ||
| 899 | case 1: | ||
| 900 | data->pwm_fcms[0] &= ~(1 << index); | ||
| 901 | w83795_write(client, W83795_REG_FCMS1, data->pwm_fcms[0]); | ||
| 902 | for (i = 0; i < 6; i++) { | ||
| 903 | data->pwm_tfmr[i] &= ~(1 << index); | ||
| 904 | w83795_write(client, W83795_REG_TFMR(i), | ||
| 905 | data->pwm_tfmr[i]); | ||
| 906 | } | ||
| 907 | data->pwm_fomc |= 1 << index; | ||
| 908 | data->pwm_fomc ^= val << index; | ||
| 909 | w83795_write(client, W83795_REG_FOMC, data->pwm_fomc); | ||
| 910 | break; | ||
| 911 | case 2: | ||
| 912 | data->pwm_fcms[0] |= (1 << index); | ||
| 913 | w83795_write(client, W83795_REG_FCMS1, data->pwm_fcms[0]); | ||
| 914 | break; | ||
| 915 | } | ||
| 916 | mutex_unlock(&data->update_lock); | ||
| 917 | return count; | ||
| 918 | } | ||
| 919 | |||
| 920 | static ssize_t | ||
| 921 | show_temp_src(struct device *dev, struct device_attribute *attr, char *buf) | ||
| 922 | { | ||
| 923 | struct sensor_device_attribute_2 *sensor_attr = | ||
| 924 | to_sensor_dev_attr_2(attr); | ||
| 925 | struct w83795_data *data = w83795_update_pwm_config(dev); | ||
| 926 | int index = sensor_attr->index; | ||
| 927 | u8 val = index / 2; | ||
| 928 | u8 tmp = data->temp_src[val]; | ||
| 929 | |||
| 930 | if (index & 1) | ||
| 931 | val = 4; | ||
| 932 | else | ||
| 933 | val = 0; | ||
| 934 | tmp >>= val; | ||
| 935 | tmp &= 0x0f; | ||
| 936 | |||
| 937 | return sprintf(buf, "%u\n", tmp); | ||
| 938 | } | ||
| 939 | |||
| 940 | static ssize_t | ||
| 941 | store_temp_src(struct device *dev, struct device_attribute *attr, | ||
| 942 | const char *buf, size_t count) | ||
| 943 | { | ||
| 944 | struct i2c_client *client = to_i2c_client(dev); | ||
| 945 | struct w83795_data *data = w83795_update_pwm_config(dev); | ||
| 946 | struct sensor_device_attribute_2 *sensor_attr = | ||
| 947 | to_sensor_dev_attr_2(attr); | ||
| 948 | int index = sensor_attr->index; | ||
| 949 | unsigned long tmp; | ||
| 950 | u8 val = index / 2; | ||
| 951 | |||
| 952 | if (strict_strtoul(buf, 10, &tmp) < 0) | ||
| 953 | return -EINVAL; | ||
| 954 | tmp = SENSORS_LIMIT(tmp, 0, 15); | ||
| 955 | |||
| 956 | mutex_lock(&data->update_lock); | ||
| 957 | if (index & 1) { | ||
| 958 | tmp <<= 4; | ||
| 959 | data->temp_src[val] &= 0x0f; | ||
| 960 | } else { | ||
| 961 | data->temp_src[val] &= 0xf0; | ||
| 962 | } | ||
| 963 | data->temp_src[val] |= tmp; | ||
| 964 | w83795_write(client, W83795_REG_TSS(val), data->temp_src[val]); | ||
| 965 | mutex_unlock(&data->update_lock); | ||
| 966 | |||
| 967 | return count; | ||
| 968 | } | ||
| 969 | |||
| 970 | #define TEMP_PWM_ENABLE 0 | ||
| 971 | #define TEMP_PWM_FAN_MAP 1 | ||
| 972 | static ssize_t | ||
| 973 | show_temp_pwm_enable(struct device *dev, struct device_attribute *attr, | ||
| 974 | char *buf) | ||
| 975 | { | ||
| 976 | struct w83795_data *data = w83795_update_pwm_config(dev); | ||
| 977 | struct sensor_device_attribute_2 *sensor_attr = | ||
| 978 | to_sensor_dev_attr_2(attr); | ||
| 979 | int nr = sensor_attr->nr; | ||
| 980 | int index = sensor_attr->index; | ||
| 981 | u8 tmp = 0xff; | ||
| 982 | |||
| 983 | switch (nr) { | ||
| 984 | case TEMP_PWM_ENABLE: | ||
| 985 | tmp = (data->pwm_fcms[1] >> index) & 1; | ||
| 986 | if (tmp) | ||
| 987 | tmp = 4; | ||
| 988 | else | ||
| 989 | tmp = 3; | ||
| 990 | break; | ||
| 991 | case TEMP_PWM_FAN_MAP: | ||
| 992 | tmp = data->pwm_tfmr[index]; | ||
| 993 | break; | ||
| 994 | } | ||
| 995 | |||
| 996 | return sprintf(buf, "%u\n", tmp); | ||
| 997 | } | ||
| 998 | |||
| 999 | static ssize_t | ||
| 1000 | store_temp_pwm_enable(struct device *dev, struct device_attribute *attr, | ||
| 1001 | const char *buf, size_t count) | ||
| 1002 | { | ||
| 1003 | struct i2c_client *client = to_i2c_client(dev); | ||
| 1004 | struct w83795_data *data = w83795_update_pwm_config(dev); | ||
| 1005 | struct sensor_device_attribute_2 *sensor_attr = | ||
| 1006 | to_sensor_dev_attr_2(attr); | ||
| 1007 | int nr = sensor_attr->nr; | ||
| 1008 | int index = sensor_attr->index; | ||
| 1009 | unsigned long tmp; | ||
| 1010 | |||
| 1011 | if (strict_strtoul(buf, 10, &tmp) < 0) | ||
| 1012 | return -EINVAL; | ||
| 1013 | |||
| 1014 | switch (nr) { | ||
| 1015 | case TEMP_PWM_ENABLE: | ||
| 1016 | if (tmp != 3 && tmp != 4) | ||
| 1017 | return -EINVAL; | ||
| 1018 | tmp -= 3; | ||
| 1019 | mutex_lock(&data->update_lock); | ||
| 1020 | data->pwm_fcms[1] &= ~(1 << index); | ||
| 1021 | data->pwm_fcms[1] |= tmp << index; | ||
| 1022 | w83795_write(client, W83795_REG_FCMS2, data->pwm_fcms[1]); | ||
| 1023 | mutex_unlock(&data->update_lock); | ||
| 1024 | break; | ||
| 1025 | case TEMP_PWM_FAN_MAP: | ||
| 1026 | mutex_lock(&data->update_lock); | ||
| 1027 | tmp = SENSORS_LIMIT(tmp, 0, 0xff); | ||
| 1028 | w83795_write(client, W83795_REG_TFMR(index), tmp); | ||
| 1029 | data->pwm_tfmr[index] = tmp; | ||
| 1030 | mutex_unlock(&data->update_lock); | ||
| 1031 | break; | ||
| 1032 | } | ||
| 1033 | return count; | ||
| 1034 | } | ||
| 1035 | |||
| 1036 | #define FANIN_TARGET 0 | ||
| 1037 | #define FANIN_TOL 1 | ||
| 1038 | static ssize_t | ||
| 1039 | show_fanin(struct device *dev, struct device_attribute *attr, char *buf) | ||
| 1040 | { | ||
| 1041 | struct w83795_data *data = w83795_update_pwm_config(dev); | ||
| 1042 | struct sensor_device_attribute_2 *sensor_attr = | ||
| 1043 | to_sensor_dev_attr_2(attr); | ||
| 1044 | int nr = sensor_attr->nr; | ||
| 1045 | int index = sensor_attr->index; | ||
| 1046 | u16 tmp = 0; | ||
| 1047 | |||
| 1048 | switch (nr) { | ||
| 1049 | case FANIN_TARGET: | ||
| 1050 | tmp = fan_from_reg(data->target_speed[index]); | ||
| 1051 | break; | ||
| 1052 | case FANIN_TOL: | ||
| 1053 | tmp = data->tol_speed; | ||
| 1054 | break; | ||
| 1055 | } | ||
| 1056 | |||
| 1057 | return sprintf(buf, "%u\n", tmp); | ||
| 1058 | } | ||
| 1059 | |||
| 1060 | static ssize_t | ||
| 1061 | store_fanin(struct device *dev, struct device_attribute *attr, | ||
| 1062 | const char *buf, size_t count) | ||
| 1063 | { | ||
| 1064 | struct i2c_client *client = to_i2c_client(dev); | ||
| 1065 | struct w83795_data *data = i2c_get_clientdata(client); | ||
| 1066 | struct sensor_device_attribute_2 *sensor_attr = | ||
| 1067 | to_sensor_dev_attr_2(attr); | ||
| 1068 | int nr = sensor_attr->nr; | ||
| 1069 | int index = sensor_attr->index; | ||
| 1070 | unsigned long val; | ||
| 1071 | |||
| 1072 | if (strict_strtoul(buf, 10, &val) < 0) | ||
| 1073 | return -EINVAL; | ||
| 1074 | |||
| 1075 | mutex_lock(&data->update_lock); | ||
| 1076 | switch (nr) { | ||
| 1077 | case FANIN_TARGET: | ||
| 1078 | val = fan_to_reg(SENSORS_LIMIT(val, 0, 0xfff)); | ||
| 1079 | w83795_write(client, W83795_REG_FTSH(index), val >> 4); | ||
| 1080 | w83795_write(client, W83795_REG_FTSL(index), (val << 4) & 0xf0); | ||
| 1081 | data->target_speed[index] = val; | ||
| 1082 | break; | ||
| 1083 | case FANIN_TOL: | ||
| 1084 | val = SENSORS_LIMIT(val, 0, 0x3f); | ||
| 1085 | w83795_write(client, W83795_REG_TFTS, val); | ||
| 1086 | data->tol_speed = val; | ||
| 1087 | break; | ||
| 1088 | } | ||
| 1089 | mutex_unlock(&data->update_lock); | ||
| 1090 | |||
| 1091 | return count; | ||
| 1092 | } | ||
| 1093 | |||
| 1094 | |||
| 1095 | static ssize_t | ||
| 1096 | show_temp_pwm(struct device *dev, struct device_attribute *attr, char *buf) | ||
| 1097 | { | ||
| 1098 | struct w83795_data *data = w83795_update_pwm_config(dev); | ||
| 1099 | struct sensor_device_attribute_2 *sensor_attr = | ||
| 1100 | to_sensor_dev_attr_2(attr); | ||
| 1101 | int nr = sensor_attr->nr; | ||
| 1102 | int index = sensor_attr->index; | ||
| 1103 | long tmp = temp_from_reg(data->pwm_temp[index][nr]); | ||
| 1104 | |||
| 1105 | return sprintf(buf, "%ld\n", tmp); | ||
| 1106 | } | ||
| 1107 | |||
| 1108 | static ssize_t | ||
| 1109 | store_temp_pwm(struct device *dev, struct device_attribute *attr, | ||
| 1110 | const char *buf, size_t count) | ||
| 1111 | { | ||
| 1112 | struct i2c_client *client = to_i2c_client(dev); | ||
| 1113 | struct w83795_data *data = i2c_get_clientdata(client); | ||
| 1114 | struct sensor_device_attribute_2 *sensor_attr = | ||
| 1115 | to_sensor_dev_attr_2(attr); | ||
| 1116 | int nr = sensor_attr->nr; | ||
| 1117 | int index = sensor_attr->index; | ||
| 1118 | unsigned long val; | ||
| 1119 | u8 tmp; | ||
| 1120 | |||
| 1121 | if (strict_strtoul(buf, 10, &val) < 0) | ||
| 1122 | return -EINVAL; | ||
| 1123 | val /= 1000; | ||
| 1124 | |||
| 1125 | mutex_lock(&data->update_lock); | ||
| 1126 | switch (nr) { | ||
| 1127 | case TEMP_PWM_TTTI: | ||
| 1128 | val = SENSORS_LIMIT(val, 0, 0x7f); | ||
| 1129 | w83795_write(client, W83795_REG_TTTI(index), val); | ||
| 1130 | break; | ||
| 1131 | case TEMP_PWM_CTFS: | ||
| 1132 | val = SENSORS_LIMIT(val, 0, 0x7f); | ||
| 1133 | w83795_write(client, W83795_REG_CTFS(index), val); | ||
| 1134 | break; | ||
| 1135 | case TEMP_PWM_HCT: | ||
| 1136 | val = SENSORS_LIMIT(val, 0, 0x0f); | ||
| 1137 | tmp = w83795_read(client, W83795_REG_HT(index)); | ||
| 1138 | tmp &= 0x0f; | ||
| 1139 | tmp |= (val << 4) & 0xf0; | ||
| 1140 | w83795_write(client, W83795_REG_HT(index), tmp); | ||
| 1141 | break; | ||
| 1142 | case TEMP_PWM_HOT: | ||
| 1143 | val = SENSORS_LIMIT(val, 0, 0x0f); | ||
| 1144 | tmp = w83795_read(client, W83795_REG_HT(index)); | ||
| 1145 | tmp &= 0xf0; | ||
| 1146 | tmp |= val & 0x0f; | ||
| 1147 | w83795_write(client, W83795_REG_HT(index), tmp); | ||
| 1148 | break; | ||
| 1149 | } | ||
| 1150 | data->pwm_temp[index][nr] = val; | ||
| 1151 | mutex_unlock(&data->update_lock); | ||
| 1152 | |||
| 1153 | return count; | ||
| 1154 | } | ||
| 1155 | |||
| 1156 | static ssize_t | ||
| 1157 | show_sf4_pwm(struct device *dev, struct device_attribute *attr, char *buf) | ||
| 1158 | { | ||
| 1159 | struct w83795_data *data = w83795_update_pwm_config(dev); | ||
| 1160 | struct sensor_device_attribute_2 *sensor_attr = | ||
| 1161 | to_sensor_dev_attr_2(attr); | ||
| 1162 | int nr = sensor_attr->nr; | ||
| 1163 | int index = sensor_attr->index; | ||
| 1164 | |||
| 1165 | return sprintf(buf, "%u\n", data->sf4_reg[index][SF4_PWM][nr]); | ||
| 1166 | } | ||
| 1167 | |||
| 1168 | static ssize_t | ||
| 1169 | store_sf4_pwm(struct device *dev, struct device_attribute *attr, | ||
| 1170 | const char *buf, size_t count) | ||
| 1171 | { | ||
| 1172 | struct i2c_client *client = to_i2c_client(dev); | ||
| 1173 | struct w83795_data *data = i2c_get_clientdata(client); | ||
| 1174 | struct sensor_device_attribute_2 *sensor_attr = | ||
| 1175 | to_sensor_dev_attr_2(attr); | ||
| 1176 | int nr = sensor_attr->nr; | ||
| 1177 | int index = sensor_attr->index; | ||
| 1178 | unsigned long val; | ||
| 1179 | |||
| 1180 | if (strict_strtoul(buf, 10, &val) < 0) | ||
| 1181 | return -EINVAL; | ||
| 1182 | |||
| 1183 | mutex_lock(&data->update_lock); | ||
| 1184 | w83795_write(client, W83795_REG_SF4_PWM(index, nr), val); | ||
| 1185 | data->sf4_reg[index][SF4_PWM][nr] = val; | ||
| 1186 | mutex_unlock(&data->update_lock); | ||
| 1187 | |||
| 1188 | return count; | ||
| 1189 | } | ||
| 1190 | |||
| 1191 | static ssize_t | ||
| 1192 | show_sf4_temp(struct device *dev, struct device_attribute *attr, char *buf) | ||
| 1193 | { | ||
| 1194 | struct w83795_data *data = w83795_update_pwm_config(dev); | ||
| 1195 | struct sensor_device_attribute_2 *sensor_attr = | ||
| 1196 | to_sensor_dev_attr_2(attr); | ||
| 1197 | int nr = sensor_attr->nr; | ||
| 1198 | int index = sensor_attr->index; | ||
| 1199 | |||
| 1200 | return sprintf(buf, "%u\n", | ||
| 1201 | (data->sf4_reg[index][SF4_TEMP][nr]) * 1000); | ||
| 1202 | } | ||
| 1203 | |||
| 1204 | static ssize_t | ||
| 1205 | store_sf4_temp(struct device *dev, struct device_attribute *attr, | ||
| 1206 | const char *buf, size_t count) | ||
| 1207 | { | ||
| 1208 | struct i2c_client *client = to_i2c_client(dev); | ||
| 1209 | struct w83795_data *data = i2c_get_clientdata(client); | ||
| 1210 | struct sensor_device_attribute_2 *sensor_attr = | ||
| 1211 | to_sensor_dev_attr_2(attr); | ||
| 1212 | int nr = sensor_attr->nr; | ||
| 1213 | int index = sensor_attr->index; | ||
| 1214 | unsigned long val; | ||
| 1215 | |||
| 1216 | if (strict_strtoul(buf, 10, &val) < 0) | ||
| 1217 | return -EINVAL; | ||
| 1218 | val /= 1000; | ||
| 1219 | |||
| 1220 | mutex_lock(&data->update_lock); | ||
| 1221 | w83795_write(client, W83795_REG_SF4_TEMP(index, nr), val); | ||
| 1222 | data->sf4_reg[index][SF4_TEMP][nr] = val; | ||
| 1223 | mutex_unlock(&data->update_lock); | ||
| 1224 | |||
| 1225 | return count; | ||
| 1226 | } | ||
| 1227 | |||
| 1228 | |||
| 1229 | static ssize_t | ||
| 1230 | show_temp(struct device *dev, struct device_attribute *attr, char *buf) | ||
| 1231 | { | ||
| 1232 | struct sensor_device_attribute_2 *sensor_attr = | ||
| 1233 | to_sensor_dev_attr_2(attr); | ||
| 1234 | int nr = sensor_attr->nr; | ||
| 1235 | int index = sensor_attr->index; | ||
| 1236 | struct w83795_data *data = w83795_update_device(dev); | ||
| 1237 | long temp = temp_from_reg(data->temp[index][nr]); | ||
| 1238 | |||
| 1239 | if (nr == TEMP_READ) | ||
| 1240 | temp += (data->temp_read_vrlsb[index] >> 6) * 250; | ||
| 1241 | return sprintf(buf, "%ld\n", temp); | ||
| 1242 | } | ||
| 1243 | |||
| 1244 | static ssize_t | ||
| 1245 | store_temp(struct device *dev, struct device_attribute *attr, | ||
| 1246 | const char *buf, size_t count) | ||
| 1247 | { | ||
| 1248 | struct sensor_device_attribute_2 *sensor_attr = | ||
| 1249 | to_sensor_dev_attr_2(attr); | ||
| 1250 | int nr = sensor_attr->nr; | ||
| 1251 | int index = sensor_attr->index; | ||
| 1252 | struct i2c_client *client = to_i2c_client(dev); | ||
| 1253 | struct w83795_data *data = i2c_get_clientdata(client); | ||
| 1254 | long tmp; | ||
| 1255 | |||
| 1256 | if (strict_strtol(buf, 10, &tmp) < 0) | ||
| 1257 | return -EINVAL; | ||
| 1258 | |||
| 1259 | mutex_lock(&data->update_lock); | ||
| 1260 | data->temp[index][nr] = temp_to_reg(tmp, -128, 127); | ||
| 1261 | w83795_write(client, W83795_REG_TEMP[index][nr], data->temp[index][nr]); | ||
| 1262 | mutex_unlock(&data->update_lock); | ||
| 1263 | return count; | ||
| 1264 | } | ||
| 1265 | |||
| 1266 | |||
| 1267 | static ssize_t | ||
| 1268 | show_dts_mode(struct device *dev, struct device_attribute *attr, char *buf) | ||
| 1269 | { | ||
| 1270 | struct w83795_data *data = dev_get_drvdata(dev); | ||
| 1271 | int tmp; | ||
| 1272 | |||
| 1273 | if (data->enable_dts & 2) | ||
| 1274 | tmp = 5; | ||
| 1275 | else | ||
| 1276 | tmp = 6; | ||
| 1277 | |||
| 1278 | return sprintf(buf, "%d\n", tmp); | ||
| 1279 | } | ||
| 1280 | |||
| 1281 | static ssize_t | ||
| 1282 | show_dts(struct device *dev, struct device_attribute *attr, char *buf) | ||
| 1283 | { | ||
| 1284 | struct sensor_device_attribute_2 *sensor_attr = | ||
| 1285 | to_sensor_dev_attr_2(attr); | ||
| 1286 | int index = sensor_attr->index; | ||
| 1287 | struct w83795_data *data = w83795_update_device(dev); | ||
| 1288 | long temp = temp_from_reg(data->dts[index]); | ||
| 1289 | |||
| 1290 | temp += (data->dts_read_vrlsb[index] >> 6) * 250; | ||
| 1291 | return sprintf(buf, "%ld\n", temp); | ||
| 1292 | } | ||
| 1293 | |||
| 1294 | static ssize_t | ||
| 1295 | show_dts_ext(struct device *dev, struct device_attribute *attr, char *buf) | ||
| 1296 | { | ||
| 1297 | struct sensor_device_attribute_2 *sensor_attr = | ||
| 1298 | to_sensor_dev_attr_2(attr); | ||
| 1299 | int nr = sensor_attr->nr; | ||
| 1300 | struct w83795_data *data = dev_get_drvdata(dev); | ||
| 1301 | long temp = temp_from_reg(data->dts_ext[nr]); | ||
| 1302 | |||
| 1303 | return sprintf(buf, "%ld\n", temp); | ||
| 1304 | } | ||
| 1305 | |||
| 1306 | static ssize_t | ||
| 1307 | store_dts_ext(struct device *dev, struct device_attribute *attr, | ||
| 1308 | const char *buf, size_t count) | ||
| 1309 | { | ||
| 1310 | struct sensor_device_attribute_2 *sensor_attr = | ||
| 1311 | to_sensor_dev_attr_2(attr); | ||
| 1312 | int nr = sensor_attr->nr; | ||
| 1313 | struct i2c_client *client = to_i2c_client(dev); | ||
| 1314 | struct w83795_data *data = i2c_get_clientdata(client); | ||
| 1315 | long tmp; | ||
| 1316 | |||
| 1317 | if (strict_strtol(buf, 10, &tmp) < 0) | ||
| 1318 | return -EINVAL; | ||
| 1319 | |||
| 1320 | mutex_lock(&data->update_lock); | ||
| 1321 | data->dts_ext[nr] = temp_to_reg(tmp, -128, 127); | ||
| 1322 | w83795_write(client, W83795_REG_DTS_EXT(nr), data->dts_ext[nr]); | ||
| 1323 | mutex_unlock(&data->update_lock); | ||
| 1324 | return count; | ||
| 1325 | } | ||
| 1326 | |||
| 1327 | |||
| 1328 | static ssize_t | ||
| 1329 | show_temp_mode(struct device *dev, struct device_attribute *attr, char *buf) | ||
| 1330 | { | ||
| 1331 | struct w83795_data *data = dev_get_drvdata(dev); | ||
| 1332 | struct sensor_device_attribute_2 *sensor_attr = | ||
| 1333 | to_sensor_dev_attr_2(attr); | ||
| 1334 | int index = sensor_attr->index; | ||
| 1335 | int tmp; | ||
| 1336 | |||
| 1337 | if (data->temp_mode & (1 << index)) | ||
| 1338 | tmp = 3; /* Thermal diode */ | ||
| 1339 | else | ||
| 1340 | tmp = 4; /* Thermistor */ | ||
| 1341 | |||
| 1342 | return sprintf(buf, "%d\n", tmp); | ||
| 1343 | } | ||
| 1344 | |||
| 1345 | /* Only for temp1-4 (temp5-6 can only be thermistor) */ | ||
| 1346 | static ssize_t | ||
| 1347 | store_temp_mode(struct device *dev, struct device_attribute *attr, | ||
| 1348 | const char *buf, size_t count) | ||
| 1349 | { | ||
| 1350 | struct i2c_client *client = to_i2c_client(dev); | ||
| 1351 | struct w83795_data *data = i2c_get_clientdata(client); | ||
| 1352 | struct sensor_device_attribute_2 *sensor_attr = | ||
| 1353 | to_sensor_dev_attr_2(attr); | ||
| 1354 | int index = sensor_attr->index; | ||
| 1355 | int reg_shift; | ||
| 1356 | unsigned long val; | ||
| 1357 | u8 tmp; | ||
| 1358 | |||
| 1359 | if (strict_strtoul(buf, 10, &val) < 0) | ||
| 1360 | return -EINVAL; | ||
| 1361 | if ((val != 4) && (val != 3)) | ||
| 1362 | return -EINVAL; | ||
| 1363 | |||
| 1364 | mutex_lock(&data->update_lock); | ||
| 1365 | if (val == 3) { | ||
| 1366 | /* Thermal diode */ | ||
| 1367 | val = 0x01; | ||
| 1368 | data->temp_mode |= 1 << index; | ||
| 1369 | } else if (val == 4) { | ||
| 1370 | /* Thermistor */ | ||
| 1371 | val = 0x03; | ||
| 1372 | data->temp_mode &= ~(1 << index); | ||
| 1373 | } | ||
| 1374 | |||
| 1375 | reg_shift = 2 * index; | ||
| 1376 | tmp = w83795_read(client, W83795_REG_TEMP_CTRL2); | ||
| 1377 | tmp &= ~(0x03 << reg_shift); | ||
| 1378 | tmp |= val << reg_shift; | ||
| 1379 | w83795_write(client, W83795_REG_TEMP_CTRL2, tmp); | ||
| 1380 | |||
| 1381 | mutex_unlock(&data->update_lock); | ||
| 1382 | return count; | ||
| 1383 | } | ||
| 1384 | |||
| 1385 | |||
| 1386 | /* show/store VIN */ | ||
| 1387 | static ssize_t | ||
| 1388 | show_in(struct device *dev, struct device_attribute *attr, char *buf) | ||
| 1389 | { | ||
| 1390 | struct sensor_device_attribute_2 *sensor_attr = | ||
| 1391 | to_sensor_dev_attr_2(attr); | ||
| 1392 | int nr = sensor_attr->nr; | ||
| 1393 | int index = sensor_attr->index; | ||
| 1394 | struct w83795_data *data = w83795_update_device(dev); | ||
| 1395 | u16 val = data->in[index][nr]; | ||
| 1396 | u8 lsb_idx; | ||
| 1397 | |||
| 1398 | switch (nr) { | ||
| 1399 | case IN_READ: | ||
| 1400 | /* calculate this value again by sensors as sensors3.conf */ | ||
| 1401 | if ((index >= 17) && | ||
| 1402 | !((data->has_gain >> (index - 17)) & 1)) | ||
| 1403 | val *= 8; | ||
| 1404 | break; | ||
| 1405 | case IN_MAX: | ||
| 1406 | case IN_LOW: | ||
| 1407 | lsb_idx = IN_LSB_SHIFT_IDX[index][IN_LSB_IDX]; | ||
| 1408 | val <<= 2; | ||
| 1409 | val |= (data->in_lsb[lsb_idx][nr] >> | ||
| 1410 | IN_LSB_SHIFT_IDX[index][IN_LSB_SHIFT]) & 0x03; | ||
| 1411 | if ((index >= 17) && | ||
| 1412 | !((data->has_gain >> (index - 17)) & 1)) | ||
| 1413 | val *= 8; | ||
| 1414 | break; | ||
| 1415 | } | ||
| 1416 | val = in_from_reg(index, val); | ||
| 1417 | |||
| 1418 | return sprintf(buf, "%d\n", val); | ||
| 1419 | } | ||
| 1420 | |||
| 1421 | static ssize_t | ||
| 1422 | store_in(struct device *dev, struct device_attribute *attr, | ||
| 1423 | const char *buf, size_t count) | ||
| 1424 | { | ||
| 1425 | struct sensor_device_attribute_2 *sensor_attr = | ||
| 1426 | to_sensor_dev_attr_2(attr); | ||
| 1427 | int nr = sensor_attr->nr; | ||
| 1428 | int index = sensor_attr->index; | ||
| 1429 | struct i2c_client *client = to_i2c_client(dev); | ||
| 1430 | struct w83795_data *data = i2c_get_clientdata(client); | ||
| 1431 | unsigned long val; | ||
| 1432 | u8 tmp; | ||
| 1433 | u8 lsb_idx; | ||
| 1434 | |||
| 1435 | if (strict_strtoul(buf, 10, &val) < 0) | ||
| 1436 | return -EINVAL; | ||
| 1437 | val = in_to_reg(index, val); | ||
| 1438 | |||
| 1439 | if ((index >= 17) && | ||
| 1440 | !((data->has_gain >> (index - 17)) & 1)) | ||
| 1441 | val /= 8; | ||
| 1442 | val = SENSORS_LIMIT(val, 0, 0x3FF); | ||
| 1443 | mutex_lock(&data->update_lock); | ||
| 1444 | |||
| 1445 | lsb_idx = IN_LSB_SHIFT_IDX[index][IN_LSB_IDX]; | ||
| 1446 | tmp = w83795_read(client, IN_LSB_REG(lsb_idx, nr)); | ||
| 1447 | tmp &= ~(0x03 << IN_LSB_SHIFT_IDX[index][IN_LSB_SHIFT]); | ||
| 1448 | tmp |= (val & 0x03) << IN_LSB_SHIFT_IDX[index][IN_LSB_SHIFT]; | ||
| 1449 | w83795_write(client, IN_LSB_REG(lsb_idx, nr), tmp); | ||
| 1450 | data->in_lsb[lsb_idx][nr] = tmp; | ||
| 1451 | |||
| 1452 | tmp = (val >> 2) & 0xff; | ||
| 1453 | w83795_write(client, W83795_REG_IN[index][nr], tmp); | ||
| 1454 | data->in[index][nr] = tmp; | ||
| 1455 | |||
| 1456 | mutex_unlock(&data->update_lock); | ||
| 1457 | return count; | ||
| 1458 | } | ||
| 1459 | |||
| 1460 | |||
| 1461 | #ifdef CONFIG_SENSORS_W83795_FANCTRL | ||
| 1462 | static ssize_t | ||
| 1463 | show_sf_setup(struct device *dev, struct device_attribute *attr, char *buf) | ||
| 1464 | { | ||
| 1465 | struct sensor_device_attribute_2 *sensor_attr = | ||
| 1466 | to_sensor_dev_attr_2(attr); | ||
| 1467 | int nr = sensor_attr->nr; | ||
| 1468 | struct w83795_data *data = w83795_update_pwm_config(dev); | ||
| 1469 | u16 val = data->setup_pwm[nr]; | ||
| 1470 | |||
| 1471 | switch (nr) { | ||
| 1472 | case SETUP_PWM_UPTIME: | ||
| 1473 | case SETUP_PWM_DOWNTIME: | ||
| 1474 | val = time_from_reg(val); | ||
| 1475 | break; | ||
| 1476 | } | ||
| 1477 | |||
| 1478 | return sprintf(buf, "%d\n", val); | ||
| 1479 | } | ||
| 1480 | |||
| 1481 | static ssize_t | ||
| 1482 | store_sf_setup(struct device *dev, struct device_attribute *attr, | ||
| 1483 | const char *buf, size_t count) | ||
| 1484 | { | ||
| 1485 | struct sensor_device_attribute_2 *sensor_attr = | ||
| 1486 | to_sensor_dev_attr_2(attr); | ||
| 1487 | int nr = sensor_attr->nr; | ||
| 1488 | struct i2c_client *client = to_i2c_client(dev); | ||
| 1489 | struct w83795_data *data = i2c_get_clientdata(client); | ||
| 1490 | unsigned long val; | ||
| 1491 | |||
| 1492 | if (strict_strtoul(buf, 10, &val) < 0) | ||
| 1493 | return -EINVAL; | ||
| 1494 | |||
| 1495 | switch (nr) { | ||
| 1496 | case SETUP_PWM_DEFAULT: | ||
| 1497 | val = SENSORS_LIMIT(val, 0, 0xff); | ||
| 1498 | break; | ||
| 1499 | case SETUP_PWM_UPTIME: | ||
| 1500 | case SETUP_PWM_DOWNTIME: | ||
| 1501 | val = time_to_reg(val); | ||
| 1502 | if (val == 0) | ||
| 1503 | return -EINVAL; | ||
| 1504 | break; | ||
| 1505 | } | ||
| 1506 | |||
| 1507 | mutex_lock(&data->update_lock); | ||
| 1508 | data->setup_pwm[nr] = val; | ||
| 1509 | w83795_write(client, W83795_REG_SETUP_PWM(nr), val); | ||
| 1510 | mutex_unlock(&data->update_lock); | ||
| 1511 | return count; | ||
| 1512 | } | ||
| 1513 | #endif | ||
| 1514 | |||
| 1515 | |||
| 1516 | #define NOT_USED -1 | ||
| 1517 | |||
| 1518 | /* Don't change the attribute order, _max and _min are accessed by index | ||
| 1519 | * somewhere else in the code */ | ||
| 1520 | #define SENSOR_ATTR_IN(index) { \ | ||
| 1521 | SENSOR_ATTR_2(in##index##_input, S_IRUGO, show_in, NULL, \ | ||
| 1522 | IN_READ, index), \ | ||
| 1523 | SENSOR_ATTR_2(in##index##_max, S_IRUGO | S_IWUSR, show_in, \ | ||
| 1524 | store_in, IN_MAX, index), \ | ||
| 1525 | SENSOR_ATTR_2(in##index##_min, S_IRUGO | S_IWUSR, show_in, \ | ||
| 1526 | store_in, IN_LOW, index), \ | ||
| 1527 | SENSOR_ATTR_2(in##index##_alarm, S_IRUGO, show_alarm_beep, \ | ||
| 1528 | NULL, ALARM_STATUS, index + ((index > 14) ? 1 : 0)), \ | ||
| 1529 | SENSOR_ATTR_2(in##index##_beep, S_IWUSR | S_IRUGO, \ | ||
| 1530 | show_alarm_beep, store_beep, BEEP_ENABLE, \ | ||
| 1531 | index + ((index > 14) ? 1 : 0)) } | ||
| 1532 | |||
| 1533 | #define SENSOR_ATTR_FAN(index) { \ | ||
| 1534 | SENSOR_ATTR_2(fan##index##_input, S_IRUGO, show_fan, \ | ||
| 1535 | NULL, FAN_INPUT, index - 1), \ | ||
| 1536 | SENSOR_ATTR_2(fan##index##_min, S_IWUSR | S_IRUGO, \ | ||
| 1537 | show_fan, store_fan_min, FAN_MIN, index - 1), \ | ||
| 1538 | SENSOR_ATTR_2(fan##index##_alarm, S_IRUGO, show_alarm_beep, \ | ||
| 1539 | NULL, ALARM_STATUS, index + 31), \ | ||
| 1540 | SENSOR_ATTR_2(fan##index##_beep, S_IWUSR | S_IRUGO, \ | ||
| 1541 | show_alarm_beep, store_beep, BEEP_ENABLE, index + 31) } | ||
| 1542 | |||
| 1543 | #define SENSOR_ATTR_PWM(index) { \ | ||
| 1544 | SENSOR_ATTR_2(pwm##index, S_IWUSR | S_IRUGO, show_pwm, \ | ||
| 1545 | store_pwm, PWM_OUTPUT, index - 1), \ | ||
| 1546 | SENSOR_ATTR_2(pwm##index##_nonstop, S_IWUSR | S_IRUGO, \ | ||
| 1547 | show_pwm, store_pwm, PWM_NONSTOP, index - 1), \ | ||
| 1548 | SENSOR_ATTR_2(pwm##index##_start, S_IWUSR | S_IRUGO, \ | ||
| 1549 | show_pwm, store_pwm, PWM_START, index - 1), \ | ||
| 1550 | SENSOR_ATTR_2(pwm##index##_stop_time, S_IWUSR | S_IRUGO, \ | ||
| 1551 | show_pwm, store_pwm, PWM_STOP_TIME, index - 1), \ | ||
| 1552 | SENSOR_ATTR_2(pwm##index##_freq, S_IWUSR | S_IRUGO, \ | ||
| 1553 | show_pwm, store_pwm, PWM_FREQ, index - 1), \ | ||
| 1554 | SENSOR_ATTR_2(pwm##index##_enable, S_IWUSR | S_IRUGO, \ | ||
| 1555 | show_pwm_enable, store_pwm_enable, NOT_USED, index - 1), \ | ||
| 1556 | SENSOR_ATTR_2(fan##index##_target, S_IWUSR | S_IRUGO, \ | ||
| 1557 | show_fanin, store_fanin, FANIN_TARGET, index - 1) } | ||
| 1558 | |||
| 1559 | #define SENSOR_ATTR_DTS(index) { \ | ||
| 1560 | SENSOR_ATTR_2(temp##index##_type, S_IRUGO , \ | ||
| 1561 | show_dts_mode, NULL, NOT_USED, index - 7), \ | ||
| 1562 | SENSOR_ATTR_2(temp##index##_input, S_IRUGO, show_dts, \ | ||
| 1563 | NULL, NOT_USED, index - 7), \ | ||
| 1564 | SENSOR_ATTR_2(temp##index##_crit, S_IRUGO | S_IWUSR, show_dts_ext, \ | ||
| 1565 | store_dts_ext, DTS_CRIT, NOT_USED), \ | ||
| 1566 | SENSOR_ATTR_2(temp##index##_crit_hyst, S_IRUGO | S_IWUSR, \ | ||
| 1567 | show_dts_ext, store_dts_ext, DTS_CRIT_HYST, NOT_USED), \ | ||
| 1568 | SENSOR_ATTR_2(temp##index##_max, S_IRUGO | S_IWUSR, show_dts_ext, \ | ||
| 1569 | store_dts_ext, DTS_WARN, NOT_USED), \ | ||
| 1570 | SENSOR_ATTR_2(temp##index##_max_hyst, S_IRUGO | S_IWUSR, \ | ||
| 1571 | show_dts_ext, store_dts_ext, DTS_WARN_HYST, NOT_USED), \ | ||
| 1572 | SENSOR_ATTR_2(temp##index##_alarm, S_IRUGO, \ | ||
| 1573 | show_alarm_beep, NULL, ALARM_STATUS, index + 17), \ | ||
| 1574 | SENSOR_ATTR_2(temp##index##_beep, S_IWUSR | S_IRUGO, \ | ||
| 1575 | show_alarm_beep, store_beep, BEEP_ENABLE, index + 17) } | ||
| 1576 | |||
| 1577 | #define SENSOR_ATTR_TEMP(index) { \ | ||
| 1578 | SENSOR_ATTR_2(temp##index##_type, S_IRUGO | (index < 4 ? S_IWUSR : 0), \ | ||
| 1579 | show_temp_mode, store_temp_mode, NOT_USED, index - 1), \ | ||
| 1580 | SENSOR_ATTR_2(temp##index##_input, S_IRUGO, show_temp, \ | ||
| 1581 | NULL, TEMP_READ, index - 1), \ | ||
| 1582 | SENSOR_ATTR_2(temp##index##_crit, S_IRUGO | S_IWUSR, show_temp, \ | ||
| 1583 | store_temp, TEMP_CRIT, index - 1), \ | ||
| 1584 | SENSOR_ATTR_2(temp##index##_crit_hyst, S_IRUGO | S_IWUSR, \ | ||
| 1585 | show_temp, store_temp, TEMP_CRIT_HYST, index - 1), \ | ||
| 1586 | SENSOR_ATTR_2(temp##index##_max, S_IRUGO | S_IWUSR, show_temp, \ | ||
| 1587 | store_temp, TEMP_WARN, index - 1), \ | ||
| 1588 | SENSOR_ATTR_2(temp##index##_max_hyst, S_IRUGO | S_IWUSR, \ | ||
| 1589 | show_temp, store_temp, TEMP_WARN_HYST, index - 1), \ | ||
| 1590 | SENSOR_ATTR_2(temp##index##_alarm, S_IRUGO, \ | ||
| 1591 | show_alarm_beep, NULL, ALARM_STATUS, \ | ||
| 1592 | index + (index > 4 ? 11 : 17)), \ | ||
| 1593 | SENSOR_ATTR_2(temp##index##_beep, S_IWUSR | S_IRUGO, \ | ||
| 1594 | show_alarm_beep, store_beep, BEEP_ENABLE, \ | ||
| 1595 | index + (index > 4 ? 11 : 17)), \ | ||
| 1596 | SENSOR_ATTR_2(temp##index##_source_sel, S_IWUSR | S_IRUGO, \ | ||
| 1597 | show_temp_src, store_temp_src, NOT_USED, index - 1), \ | ||
| 1598 | SENSOR_ATTR_2(temp##index##_pwm_enable, S_IWUSR | S_IRUGO, \ | ||
| 1599 | show_temp_pwm_enable, store_temp_pwm_enable, \ | ||
| 1600 | TEMP_PWM_ENABLE, index - 1), \ | ||
| 1601 | SENSOR_ATTR_2(temp##index##_auto_channels_pwm, S_IWUSR | S_IRUGO, \ | ||
| 1602 | show_temp_pwm_enable, store_temp_pwm_enable, \ | ||
| 1603 | TEMP_PWM_FAN_MAP, index - 1), \ | ||
| 1604 | SENSOR_ATTR_2(thermal_cruise##index, S_IWUSR | S_IRUGO, \ | ||
| 1605 | show_temp_pwm, store_temp_pwm, TEMP_PWM_TTTI, index - 1), \ | ||
| 1606 | SENSOR_ATTR_2(temp##index##_warn, S_IWUSR | S_IRUGO, \ | ||
| 1607 | show_temp_pwm, store_temp_pwm, TEMP_PWM_CTFS, index - 1), \ | ||
| 1608 | SENSOR_ATTR_2(temp##index##_warn_hyst, S_IWUSR | S_IRUGO, \ | ||
| 1609 | show_temp_pwm, store_temp_pwm, TEMP_PWM_HCT, index - 1), \ | ||
| 1610 | SENSOR_ATTR_2(temp##index##_operation_hyst, S_IWUSR | S_IRUGO, \ | ||
| 1611 | show_temp_pwm, store_temp_pwm, TEMP_PWM_HOT, index - 1), \ | ||
| 1612 | SENSOR_ATTR_2(temp##index##_auto_point1_pwm, S_IRUGO | S_IWUSR, \ | ||
| 1613 | show_sf4_pwm, store_sf4_pwm, 0, index - 1), \ | ||
| 1614 | SENSOR_ATTR_2(temp##index##_auto_point2_pwm, S_IRUGO | S_IWUSR, \ | ||
| 1615 | show_sf4_pwm, store_sf4_pwm, 1, index - 1), \ | ||
| 1616 | SENSOR_ATTR_2(temp##index##_auto_point3_pwm, S_IRUGO | S_IWUSR, \ | ||
| 1617 | show_sf4_pwm, store_sf4_pwm, 2, index - 1), \ | ||
| 1618 | SENSOR_ATTR_2(temp##index##_auto_point4_pwm, S_IRUGO | S_IWUSR, \ | ||
| 1619 | show_sf4_pwm, store_sf4_pwm, 3, index - 1), \ | ||
| 1620 | SENSOR_ATTR_2(temp##index##_auto_point5_pwm, S_IRUGO | S_IWUSR, \ | ||
| 1621 | show_sf4_pwm, store_sf4_pwm, 4, index - 1), \ | ||
| 1622 | SENSOR_ATTR_2(temp##index##_auto_point6_pwm, S_IRUGO | S_IWUSR, \ | ||
| 1623 | show_sf4_pwm, store_sf4_pwm, 5, index - 1), \ | ||
| 1624 | SENSOR_ATTR_2(temp##index##_auto_point7_pwm, S_IRUGO | S_IWUSR, \ | ||
| 1625 | show_sf4_pwm, store_sf4_pwm, 6, index - 1), \ | ||
| 1626 | SENSOR_ATTR_2(temp##index##_auto_point1_temp, S_IRUGO | S_IWUSR,\ | ||
| 1627 | show_sf4_temp, store_sf4_temp, 0, index - 1), \ | ||
| 1628 | SENSOR_ATTR_2(temp##index##_auto_point2_temp, S_IRUGO | S_IWUSR,\ | ||
| 1629 | show_sf4_temp, store_sf4_temp, 1, index - 1), \ | ||
| 1630 | SENSOR_ATTR_2(temp##index##_auto_point3_temp, S_IRUGO | S_IWUSR,\ | ||
| 1631 | show_sf4_temp, store_sf4_temp, 2, index - 1), \ | ||
| 1632 | SENSOR_ATTR_2(temp##index##_auto_point4_temp, S_IRUGO | S_IWUSR,\ | ||
| 1633 | show_sf4_temp, store_sf4_temp, 3, index - 1), \ | ||
| 1634 | SENSOR_ATTR_2(temp##index##_auto_point5_temp, S_IRUGO | S_IWUSR,\ | ||
| 1635 | show_sf4_temp, store_sf4_temp, 4, index - 1), \ | ||
| 1636 | SENSOR_ATTR_2(temp##index##_auto_point6_temp, S_IRUGO | S_IWUSR,\ | ||
| 1637 | show_sf4_temp, store_sf4_temp, 5, index - 1), \ | ||
| 1638 | SENSOR_ATTR_2(temp##index##_auto_point7_temp, S_IRUGO | S_IWUSR,\ | ||
| 1639 | show_sf4_temp, store_sf4_temp, 6, index - 1) } | ||
| 1640 | |||
| 1641 | |||
| 1642 | static struct sensor_device_attribute_2 w83795_in[][5] = { | ||
| 1643 | SENSOR_ATTR_IN(0), | ||
| 1644 | SENSOR_ATTR_IN(1), | ||
| 1645 | SENSOR_ATTR_IN(2), | ||
| 1646 | SENSOR_ATTR_IN(3), | ||
| 1647 | SENSOR_ATTR_IN(4), | ||
| 1648 | SENSOR_ATTR_IN(5), | ||
| 1649 | SENSOR_ATTR_IN(6), | ||
| 1650 | SENSOR_ATTR_IN(7), | ||
| 1651 | SENSOR_ATTR_IN(8), | ||
| 1652 | SENSOR_ATTR_IN(9), | ||
| 1653 | SENSOR_ATTR_IN(10), | ||
| 1654 | SENSOR_ATTR_IN(11), | ||
| 1655 | SENSOR_ATTR_IN(12), | ||
| 1656 | SENSOR_ATTR_IN(13), | ||
| 1657 | SENSOR_ATTR_IN(14), | ||
| 1658 | SENSOR_ATTR_IN(15), | ||
| 1659 | SENSOR_ATTR_IN(16), | ||
| 1660 | SENSOR_ATTR_IN(17), | ||
| 1661 | SENSOR_ATTR_IN(18), | ||
| 1662 | SENSOR_ATTR_IN(19), | ||
| 1663 | SENSOR_ATTR_IN(20), | ||
| 1664 | }; | ||
| 1665 | |||
| 1666 | static const struct sensor_device_attribute_2 w83795_fan[][4] = { | ||
| 1667 | SENSOR_ATTR_FAN(1), | ||
| 1668 | SENSOR_ATTR_FAN(2), | ||
| 1669 | SENSOR_ATTR_FAN(3), | ||
| 1670 | SENSOR_ATTR_FAN(4), | ||
| 1671 | SENSOR_ATTR_FAN(5), | ||
| 1672 | SENSOR_ATTR_FAN(6), | ||
| 1673 | SENSOR_ATTR_FAN(7), | ||
| 1674 | SENSOR_ATTR_FAN(8), | ||
| 1675 | SENSOR_ATTR_FAN(9), | ||
| 1676 | SENSOR_ATTR_FAN(10), | ||
| 1677 | SENSOR_ATTR_FAN(11), | ||
| 1678 | SENSOR_ATTR_FAN(12), | ||
| 1679 | SENSOR_ATTR_FAN(13), | ||
| 1680 | SENSOR_ATTR_FAN(14), | ||
| 1681 | }; | ||
| 1682 | |||
| 1683 | static const struct sensor_device_attribute_2 w83795_temp[][29] = { | ||
| 1684 | SENSOR_ATTR_TEMP(1), | ||
| 1685 | SENSOR_ATTR_TEMP(2), | ||
| 1686 | SENSOR_ATTR_TEMP(3), | ||
| 1687 | SENSOR_ATTR_TEMP(4), | ||
| 1688 | SENSOR_ATTR_TEMP(5), | ||
| 1689 | SENSOR_ATTR_TEMP(6), | ||
| 1690 | }; | ||
| 1691 | |||
| 1692 | static const struct sensor_device_attribute_2 w83795_dts[][8] = { | ||
| 1693 | SENSOR_ATTR_DTS(7), | ||
| 1694 | SENSOR_ATTR_DTS(8), | ||
| 1695 | SENSOR_ATTR_DTS(9), | ||
| 1696 | SENSOR_ATTR_DTS(10), | ||
| 1697 | SENSOR_ATTR_DTS(11), | ||
| 1698 | SENSOR_ATTR_DTS(12), | ||
| 1699 | SENSOR_ATTR_DTS(13), | ||
| 1700 | SENSOR_ATTR_DTS(14), | ||
| 1701 | }; | ||
| 1702 | |||
| 1703 | static const struct sensor_device_attribute_2 w83795_pwm[][7] = { | ||
| 1704 | SENSOR_ATTR_PWM(1), | ||
| 1705 | SENSOR_ATTR_PWM(2), | ||
| 1706 | SENSOR_ATTR_PWM(3), | ||
| 1707 | SENSOR_ATTR_PWM(4), | ||
| 1708 | SENSOR_ATTR_PWM(5), | ||
| 1709 | SENSOR_ATTR_PWM(6), | ||
| 1710 | SENSOR_ATTR_PWM(7), | ||
| 1711 | SENSOR_ATTR_PWM(8), | ||
| 1712 | }; | ||
| 1713 | |||
| 1714 | static const struct sensor_device_attribute_2 sda_single_files[] = { | ||
| 1715 | SENSOR_ATTR_2(intrusion0_alarm, S_IWUSR | S_IRUGO, show_alarm_beep, | ||
| 1716 | store_chassis_clear, ALARM_STATUS, 46), | ||
| 1717 | SENSOR_ATTR_2(intrusion0_beep, S_IWUSR | S_IRUGO, show_alarm_beep, | ||
| 1718 | store_beep, BEEP_ENABLE, 46), | ||
| 1719 | SENSOR_ATTR_2(beep_enable, S_IWUSR | S_IRUGO, show_alarm_beep, | ||
| 1720 | store_beep, BEEP_ENABLE, 47), | ||
| 1721 | #ifdef CONFIG_SENSORS_W83795_FANCTRL | ||
| 1722 | SENSOR_ATTR_2(speed_cruise_tolerance, S_IWUSR | S_IRUGO, show_fanin, | ||
| 1723 | store_fanin, FANIN_TOL, NOT_USED), | ||
| 1724 | SENSOR_ATTR_2(pwm_default, S_IWUSR | S_IRUGO, show_sf_setup, | ||
| 1725 | store_sf_setup, SETUP_PWM_DEFAULT, NOT_USED), | ||
| 1726 | SENSOR_ATTR_2(pwm_uptime, S_IWUSR | S_IRUGO, show_sf_setup, | ||
| 1727 | store_sf_setup, SETUP_PWM_UPTIME, NOT_USED), | ||
| 1728 | SENSOR_ATTR_2(pwm_downtime, S_IWUSR | S_IRUGO, show_sf_setup, | ||
| 1729 | store_sf_setup, SETUP_PWM_DOWNTIME, NOT_USED), | ||
| 1730 | #endif | ||
| 1731 | }; | ||
| 1732 | |||
| 1733 | /* | ||
| 1734 | * Driver interface | ||
| 1735 | */ | ||
| 1736 | |||
| 1737 | static void w83795_init_client(struct i2c_client *client) | ||
| 1738 | { | ||
| 1739 | struct w83795_data *data = i2c_get_clientdata(client); | ||
| 1740 | static const u16 clkin[4] = { /* in kHz */ | ||
| 1741 | 14318, 24000, 33333, 48000 | ||
| 1742 | }; | ||
| 1743 | u8 config; | ||
| 1744 | |||
| 1745 | if (reset) | ||
| 1746 | w83795_write(client, W83795_REG_CONFIG, 0x80); | ||
| 1747 | |||
| 1748 | /* Start monitoring if needed */ | ||
| 1749 | config = w83795_read(client, W83795_REG_CONFIG); | ||
| 1750 | if (!(config & W83795_REG_CONFIG_START)) { | ||
| 1751 | dev_info(&client->dev, "Enabling monitoring operations\n"); | ||
| 1752 | w83795_write(client, W83795_REG_CONFIG, | ||
| 1753 | config | W83795_REG_CONFIG_START); | ||
| 1754 | } | ||
| 1755 | |||
| 1756 | data->clkin = clkin[(config >> 3) & 0x3]; | ||
| 1757 | dev_dbg(&client->dev, "clkin = %u kHz\n", data->clkin); | ||
| 1758 | } | ||
| 1759 | |||
| 1760 | static int w83795_get_device_id(struct i2c_client *client) | ||
| 1761 | { | ||
| 1762 | int device_id; | ||
| 1763 | |||
| 1764 | device_id = i2c_smbus_read_byte_data(client, W83795_REG_DEVICEID); | ||
| 1765 | |||
| 1766 | /* Special case for rev. A chips; can't be checked first because later | ||
| 1767 | revisions emulate this for compatibility */ | ||
| 1768 | if (device_id < 0 || (device_id & 0xf0) != 0x50) { | ||
| 1769 | int alt_id; | ||
| 1770 | |||
| 1771 | alt_id = i2c_smbus_read_byte_data(client, | ||
| 1772 | W83795_REG_DEVICEID_A); | ||
| 1773 | if (alt_id == 0x50) | ||
| 1774 | device_id = alt_id; | ||
| 1775 | } | ||
| 1776 | |||
| 1777 | return device_id; | ||
| 1778 | } | ||
| 1779 | |||
| 1780 | /* Return 0 if detection is successful, -ENODEV otherwise */ | ||
| 1781 | static int w83795_detect(struct i2c_client *client, | ||
| 1782 | struct i2c_board_info *info) | ||
| 1783 | { | ||
| 1784 | int bank, vendor_id, device_id, expected, i2c_addr, config; | ||
| 1785 | struct i2c_adapter *adapter = client->adapter; | ||
| 1786 | unsigned short address = client->addr; | ||
| 1787 | const char *chip_name; | ||
| 1788 | |||
| 1789 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) | ||
| 1790 | return -ENODEV; | ||
| 1791 | bank = i2c_smbus_read_byte_data(client, W83795_REG_BANKSEL); | ||
| 1792 | if (bank < 0 || (bank & 0x7c)) { | ||
| 1793 | dev_dbg(&adapter->dev, | ||
| 1794 | "w83795: Detection failed at addr 0x%02hx, check %s\n", | ||
| 1795 | address, "bank"); | ||
| 1796 | return -ENODEV; | ||
| 1797 | } | ||
| 1798 | |||
| 1799 | /* Check Nuvoton vendor ID */ | ||
| 1800 | vendor_id = i2c_smbus_read_byte_data(client, W83795_REG_VENDORID); | ||
| 1801 | expected = bank & 0x80 ? 0x5c : 0xa3; | ||
| 1802 | if (vendor_id != expected) { | ||
| 1803 | dev_dbg(&adapter->dev, | ||
| 1804 | "w83795: Detection failed at addr 0x%02hx, check %s\n", | ||
| 1805 | address, "vendor id"); | ||
| 1806 | return -ENODEV; | ||
| 1807 | } | ||
| 1808 | |||
| 1809 | /* Check device ID */ | ||
| 1810 | device_id = w83795_get_device_id(client) | | ||
| 1811 | (i2c_smbus_read_byte_data(client, W83795_REG_CHIPID) << 8); | ||
| 1812 | if ((device_id >> 4) != 0x795) { | ||
| 1813 | dev_dbg(&adapter->dev, | ||
| 1814 | "w83795: Detection failed at addr 0x%02hx, check %s\n", | ||
| 1815 | address, "device id\n"); | ||
| 1816 | return -ENODEV; | ||
| 1817 | } | ||
| 1818 | |||
| 1819 | /* If Nuvoton chip, address of chip and W83795_REG_I2C_ADDR | ||
| 1820 | should match */ | ||
| 1821 | if ((bank & 0x07) == 0) { | ||
| 1822 | i2c_addr = i2c_smbus_read_byte_data(client, | ||
| 1823 | W83795_REG_I2C_ADDR); | ||
| 1824 | if ((i2c_addr & 0x7f) != address) { | ||
| 1825 | dev_dbg(&adapter->dev, | ||
| 1826 | "w83795: Detection failed at addr 0x%02hx, " | ||
| 1827 | "check %s\n", address, "i2c addr"); | ||
| 1828 | return -ENODEV; | ||
| 1829 | } | ||
| 1830 | } | ||
| 1831 | |||
| 1832 | /* Check 795 chip type: 795G or 795ADG | ||
| 1833 | Usually we don't write to chips during detection, but here we don't | ||
| 1834 | quite have the choice; hopefully it's OK, we are about to return | ||
| 1835 | success anyway */ | ||
| 1836 | if ((bank & 0x07) != 0) | ||
| 1837 | i2c_smbus_write_byte_data(client, W83795_REG_BANKSEL, | ||
| 1838 | bank & ~0x07); | ||
| 1839 | config = i2c_smbus_read_byte_data(client, W83795_REG_CONFIG); | ||
| 1840 | if (config & W83795_REG_CONFIG_CONFIG48) | ||
| 1841 | chip_name = "w83795adg"; | ||
| 1842 | else | ||
| 1843 | chip_name = "w83795g"; | ||
| 1844 | |||
| 1845 | strlcpy(info->type, chip_name, I2C_NAME_SIZE); | ||
| 1846 | dev_info(&adapter->dev, "Found %s rev. %c at 0x%02hx\n", chip_name, | ||
| 1847 | 'A' + (device_id & 0xf), address); | ||
| 1848 | |||
| 1849 | return 0; | ||
| 1850 | } | ||
| 1851 | |||
| 1852 | static int w83795_handle_files(struct device *dev, int (*fn)(struct device *, | ||
| 1853 | const struct device_attribute *)) | ||
| 1854 | { | ||
| 1855 | struct w83795_data *data = dev_get_drvdata(dev); | ||
| 1856 | int err, i, j; | ||
| 1857 | |||
| 1858 | for (i = 0; i < ARRAY_SIZE(w83795_in); i++) { | ||
| 1859 | if (!(data->has_in & (1 << i))) | ||
| 1860 | continue; | ||
| 1861 | for (j = 0; j < ARRAY_SIZE(w83795_in[0]); j++) { | ||
| 1862 | err = fn(dev, &w83795_in[i][j].dev_attr); | ||
| 1863 | if (err) | ||
| 1864 | return err; | ||
| 1865 | } | ||
| 1866 | } | ||
| 1867 | |||
| 1868 | for (i = 0; i < ARRAY_SIZE(w83795_fan); i++) { | ||
| 1869 | if (!(data->has_fan & (1 << i))) | ||
| 1870 | continue; | ||
| 1871 | for (j = 0; j < ARRAY_SIZE(w83795_fan[0]); j++) { | ||
| 1872 | err = fn(dev, &w83795_fan[i][j].dev_attr); | ||
| 1873 | if (err) | ||
| 1874 | return err; | ||
| 1875 | } | ||
| 1876 | } | ||
| 1877 | |||
| 1878 | for (i = 0; i < ARRAY_SIZE(sda_single_files); i++) { | ||
| 1879 | err = fn(dev, &sda_single_files[i].dev_attr); | ||
| 1880 | if (err) | ||
| 1881 | return err; | ||
| 1882 | } | ||
| 1883 | |||
| 1884 | #ifdef CONFIG_SENSORS_W83795_FANCTRL | ||
| 1885 | for (i = 0; i < data->has_pwm; i++) { | ||
| 1886 | for (j = 0; j < ARRAY_SIZE(w83795_pwm[0]); j++) { | ||
| 1887 | err = fn(dev, &w83795_pwm[i][j].dev_attr); | ||
| 1888 | if (err) | ||
| 1889 | return err; | ||
| 1890 | } | ||
| 1891 | } | ||
| 1892 | #endif | ||
| 1893 | |||
| 1894 | for (i = 0; i < ARRAY_SIZE(w83795_temp); i++) { | ||
| 1895 | if (!(data->has_temp & (1 << i))) | ||
| 1896 | continue; | ||
| 1897 | #ifdef CONFIG_SENSORS_W83795_FANCTRL | ||
| 1898 | for (j = 0; j < ARRAY_SIZE(w83795_temp[0]); j++) { | ||
| 1899 | #else | ||
| 1900 | for (j = 0; j < 8; j++) { | ||
| 1901 | #endif | ||
| 1902 | err = fn(dev, &w83795_temp[i][j].dev_attr); | ||
| 1903 | if (err) | ||
| 1904 | return err; | ||
| 1905 | } | ||
| 1906 | } | ||
| 1907 | |||
| 1908 | if (data->enable_dts) { | ||
| 1909 | for (i = 0; i < ARRAY_SIZE(w83795_dts); i++) { | ||
| 1910 | if (!(data->has_dts & (1 << i))) | ||
| 1911 | continue; | ||
| 1912 | for (j = 0; j < ARRAY_SIZE(w83795_dts[0]); j++) { | ||
| 1913 | err = fn(dev, &w83795_dts[i][j].dev_attr); | ||
| 1914 | if (err) | ||
| 1915 | return err; | ||
| 1916 | } | ||
| 1917 | } | ||
| 1918 | } | ||
| 1919 | |||
| 1920 | return 0; | ||
| 1921 | } | ||
| 1922 | |||
| 1923 | /* We need a wrapper that fits in w83795_handle_files */ | ||
| 1924 | static int device_remove_file_wrapper(struct device *dev, | ||
| 1925 | const struct device_attribute *attr) | ||
| 1926 | { | ||
| 1927 | device_remove_file(dev, attr); | ||
| 1928 | return 0; | ||
| 1929 | } | ||
| 1930 | |||
| 1931 | static void w83795_check_dynamic_in_limits(struct i2c_client *client) | ||
| 1932 | { | ||
| 1933 | struct w83795_data *data = i2c_get_clientdata(client); | ||
| 1934 | u8 vid_ctl; | ||
| 1935 | int i, err_max, err_min; | ||
| 1936 | |||
| 1937 | vid_ctl = w83795_read(client, W83795_REG_VID_CTRL); | ||
| 1938 | |||
| 1939 | /* Return immediately if VRM isn't configured */ | ||
| 1940 | if ((vid_ctl & 0x07) == 0x00 || (vid_ctl & 0x07) == 0x07) | ||
| 1941 | return; | ||
| 1942 | |||
| 1943 | data->has_dyn_in = (vid_ctl >> 3) & 0x07; | ||
| 1944 | for (i = 0; i < 2; i++) { | ||
| 1945 | if (!(data->has_dyn_in & (1 << i))) | ||
| 1946 | continue; | ||
| 1947 | |||
| 1948 | /* Voltage limits in dynamic mode, switch to read-only */ | ||
| 1949 | err_max = sysfs_chmod_file(&client->dev.kobj, | ||
| 1950 | &w83795_in[i][2].dev_attr.attr, | ||
| 1951 | S_IRUGO); | ||
| 1952 | err_min = sysfs_chmod_file(&client->dev.kobj, | ||
| 1953 | &w83795_in[i][3].dev_attr.attr, | ||
| 1954 | S_IRUGO); | ||
| 1955 | if (err_max || err_min) | ||
| 1956 | dev_warn(&client->dev, "Failed to set in%d limits " | ||
| 1957 | "read-only (%d, %d)\n", i, err_max, err_min); | ||
| 1958 | else | ||
| 1959 | dev_info(&client->dev, "in%d limits set dynamically " | ||
| 1960 | "from VID\n", i); | ||
| 1961 | } | ||
| 1962 | } | ||
| 1963 | |||
| 1964 | /* Check pins that can be used for either temperature or voltage monitoring */ | ||
| 1965 | static void w83795_apply_temp_config(struct w83795_data *data, u8 config, | ||
| 1966 | int temp_chan, int in_chan) | ||
| 1967 | { | ||
| 1968 | /* config is a 2-bit value */ | ||
| 1969 | switch (config) { | ||
| 1970 | case 0x2: /* Voltage monitoring */ | ||
| 1971 | data->has_in |= 1 << in_chan; | ||
| 1972 | break; | ||
| 1973 | case 0x1: /* Thermal diode */ | ||
| 1974 | if (temp_chan >= 4) | ||
| 1975 | break; | ||
| 1976 | data->temp_mode |= 1 << temp_chan; | ||
| 1977 | /* fall through */ | ||
| 1978 | case 0x3: /* Thermistor */ | ||
| 1979 | data->has_temp |= 1 << temp_chan; | ||
| 1980 | break; | ||
| 1981 | } | ||
| 1982 | } | ||
| 1983 | |||
| 1984 | static int w83795_probe(struct i2c_client *client, | ||
| 1985 | const struct i2c_device_id *id) | ||
| 1986 | { | ||
| 1987 | int i; | ||
| 1988 | u8 tmp; | ||
| 1989 | struct device *dev = &client->dev; | ||
| 1990 | struct w83795_data *data; | ||
| 1991 | int err; | ||
| 1992 | |||
| 1993 | data = kzalloc(sizeof(struct w83795_data), GFP_KERNEL); | ||
| 1994 | if (!data) { | ||
| 1995 | err = -ENOMEM; | ||
| 1996 | goto exit; | ||
| 1997 | } | ||
| 1998 | |||
| 1999 | i2c_set_clientdata(client, data); | ||
| 2000 | data->chip_type = id->driver_data; | ||
| 2001 | data->bank = i2c_smbus_read_byte_data(client, W83795_REG_BANKSEL); | ||
| 2002 | mutex_init(&data->update_lock); | ||
| 2003 | |||
| 2004 | /* Initialize the chip */ | ||
| 2005 | w83795_init_client(client); | ||
| 2006 | |||
| 2007 | /* Check which voltages and fans are present */ | ||
| 2008 | data->has_in = w83795_read(client, W83795_REG_VOLT_CTRL1) | ||
| 2009 | | (w83795_read(client, W83795_REG_VOLT_CTRL2) << 8); | ||
| 2010 | data->has_fan = w83795_read(client, W83795_REG_FANIN_CTRL1) | ||
| 2011 | | (w83795_read(client, W83795_REG_FANIN_CTRL2) << 8); | ||
| 2012 | |||
| 2013 | /* Check which analog temperatures and extra voltages are present */ | ||
| 2014 | tmp = w83795_read(client, W83795_REG_TEMP_CTRL1); | ||
| 2015 | if (tmp & 0x20) | ||
| 2016 | data->enable_dts = 1; | ||
| 2017 | w83795_apply_temp_config(data, (tmp >> 2) & 0x3, 5, 16); | ||
| 2018 | w83795_apply_temp_config(data, tmp & 0x3, 4, 15); | ||
| 2019 | tmp = w83795_read(client, W83795_REG_TEMP_CTRL2); | ||
| 2020 | w83795_apply_temp_config(data, tmp >> 6, 3, 20); | ||
| 2021 | w83795_apply_temp_config(data, (tmp >> 4) & 0x3, 2, 19); | ||
| 2022 | w83795_apply_temp_config(data, (tmp >> 2) & 0x3, 1, 18); | ||
| 2023 | w83795_apply_temp_config(data, tmp & 0x3, 0, 17); | ||
| 2024 | |||
| 2025 | /* Check DTS enable status */ | ||
| 2026 | if (data->enable_dts) { | ||
| 2027 | if (1 & w83795_read(client, W83795_REG_DTSC)) | ||
| 2028 | data->enable_dts |= 2; | ||
| 2029 | data->has_dts = w83795_read(client, W83795_REG_DTSE); | ||
| 2030 | } | ||
| 2031 | |||
| 2032 | /* Report PECI Tbase values */ | ||
| 2033 | if (data->enable_dts == 1) { | ||
| 2034 | for (i = 0; i < 8; i++) { | ||
| 2035 | if (!(data->has_dts & (1 << i))) | ||
| 2036 | continue; | ||
| 2037 | tmp = w83795_read(client, W83795_REG_PECI_TBASE(i)); | ||
| 2038 | dev_info(&client->dev, | ||
| 2039 | "PECI agent %d Tbase temperature: %u\n", | ||
| 2040 | i + 1, (unsigned int)tmp & 0x7f); | ||
| 2041 | } | ||
| 2042 | } | ||
| 2043 | |||
| 2044 | data->has_gain = w83795_read(client, W83795_REG_VMIGB_CTRL) & 0x0f; | ||
| 2045 | |||
| 2046 | /* pwm and smart fan */ | ||
| 2047 | if (data->chip_type == w83795g) | ||
| 2048 | data->has_pwm = 8; | ||
| 2049 | else | ||
| 2050 | data->has_pwm = 2; | ||
| 2051 | |||
| 2052 | err = w83795_handle_files(dev, device_create_file); | ||
| 2053 | if (err) | ||
| 2054 | goto exit_remove; | ||
| 2055 | |||
| 2056 | if (data->chip_type == w83795g) | ||
| 2057 | w83795_check_dynamic_in_limits(client); | ||
| 2058 | |||
| 2059 | data->hwmon_dev = hwmon_device_register(dev); | ||
| 2060 | if (IS_ERR(data->hwmon_dev)) { | ||
| 2061 | err = PTR_ERR(data->hwmon_dev); | ||
| 2062 | goto exit_remove; | ||
| 2063 | } | ||
| 2064 | |||
| 2065 | return 0; | ||
| 2066 | |||
| 2067 | exit_remove: | ||
| 2068 | w83795_handle_files(dev, device_remove_file_wrapper); | ||
| 2069 | kfree(data); | ||
| 2070 | exit: | ||
| 2071 | return err; | ||
| 2072 | } | ||
| 2073 | |||
| 2074 | static int w83795_remove(struct i2c_client *client) | ||
| 2075 | { | ||
| 2076 | struct w83795_data *data = i2c_get_clientdata(client); | ||
| 2077 | |||
| 2078 | hwmon_device_unregister(data->hwmon_dev); | ||
| 2079 | w83795_handle_files(&client->dev, device_remove_file_wrapper); | ||
| 2080 | kfree(data); | ||
| 2081 | |||
| 2082 | return 0; | ||
| 2083 | } | ||
| 2084 | |||
| 2085 | |||
| 2086 | static const struct i2c_device_id w83795_id[] = { | ||
| 2087 | { "w83795g", w83795g }, | ||
| 2088 | { "w83795adg", w83795adg }, | ||
| 2089 | { } | ||
| 2090 | }; | ||
| 2091 | MODULE_DEVICE_TABLE(i2c, w83795_id); | ||
| 2092 | |||
| 2093 | static struct i2c_driver w83795_driver = { | ||
| 2094 | .driver = { | ||
| 2095 | .name = "w83795", | ||
| 2096 | }, | ||
| 2097 | .probe = w83795_probe, | ||
| 2098 | .remove = w83795_remove, | ||
| 2099 | .id_table = w83795_id, | ||
| 2100 | |||
| 2101 | .class = I2C_CLASS_HWMON, | ||
| 2102 | .detect = w83795_detect, | ||
| 2103 | .address_list = normal_i2c, | ||
| 2104 | }; | ||
| 2105 | |||
| 2106 | static int __init sensors_w83795_init(void) | ||
| 2107 | { | ||
| 2108 | return i2c_add_driver(&w83795_driver); | ||
| 2109 | } | ||
| 2110 | |||
| 2111 | static void __exit sensors_w83795_exit(void) | ||
| 2112 | { | ||
| 2113 | i2c_del_driver(&w83795_driver); | ||
| 2114 | } | ||
| 2115 | |||
| 2116 | MODULE_AUTHOR("Wei Song, Jean Delvare <khali@linux-fr.org>"); | ||
| 2117 | MODULE_DESCRIPTION("W83795G/ADG hardware monitoring driver"); | ||
| 2118 | MODULE_LICENSE("GPL"); | ||
| 2119 | |||
| 2120 | module_init(sensors_w83795_init); | ||
| 2121 | module_exit(sensors_w83795_exit); | ||
diff --git a/drivers/macintosh/Kconfig b/drivers/macintosh/Kconfig index fd85bde283a0..3d7355ff7308 100644 --- a/drivers/macintosh/Kconfig +++ b/drivers/macintosh/Kconfig | |||
| @@ -256,4 +256,30 @@ config PMAC_RACKMETER | |||
| 256 | This driver provides some support to control the front panel | 256 | This driver provides some support to control the front panel |
| 257 | blue LEDs "vu-meter" of the XServer macs. | 257 | blue LEDs "vu-meter" of the XServer macs. |
| 258 | 258 | ||
| 259 | config SENSORS_AMS | ||
| 260 | tristate "Apple Motion Sensor driver" | ||
| 261 | depends on PPC_PMAC && !PPC64 && INPUT && ((ADB_PMU && I2C = y) || (ADB_PMU && !I2C) || I2C) && EXPERIMENTAL | ||
| 262 | select INPUT_POLLDEV | ||
| 263 | help | ||
| 264 | Support for the motion sensor included in PowerBooks. Includes | ||
| 265 | implementations for PMU and I2C. | ||
| 266 | |||
| 267 | This driver can also be built as a module. If so, the module | ||
| 268 | will be called ams. | ||
| 269 | |||
| 270 | config SENSORS_AMS_PMU | ||
| 271 | bool "PMU variant" | ||
| 272 | depends on SENSORS_AMS && ADB_PMU | ||
| 273 | default y | ||
| 274 | help | ||
| 275 | PMU variant of motion sensor, found in late 2005 PowerBooks. | ||
| 276 | |||
| 277 | config SENSORS_AMS_I2C | ||
| 278 | bool "I2C variant" | ||
| 279 | depends on SENSORS_AMS && I2C | ||
| 280 | default y | ||
| 281 | help | ||
| 282 | I2C variant of motion sensor, found in early 2005 PowerBooks and | ||
| 283 | iBooks. | ||
| 284 | |||
| 259 | endif # MACINTOSH_DRIVERS | 285 | endif # MACINTOSH_DRIVERS |
diff --git a/drivers/macintosh/Makefile b/drivers/macintosh/Makefile index e3132efa17c0..6652a6ebb6fa 100644 --- a/drivers/macintosh/Makefile +++ b/drivers/macintosh/Makefile | |||
| @@ -48,3 +48,5 @@ obj-$(CONFIG_WINDFARM_PM121) += windfarm_pm121.o windfarm_smu_sat.o \ | |||
| 48 | windfarm_max6690_sensor.o \ | 48 | windfarm_max6690_sensor.o \ |
| 49 | windfarm_lm75_sensor.o windfarm_pid.o | 49 | windfarm_lm75_sensor.o windfarm_pid.o |
| 50 | obj-$(CONFIG_PMAC_RACKMETER) += rack-meter.o | 50 | obj-$(CONFIG_PMAC_RACKMETER) += rack-meter.o |
| 51 | |||
| 52 | obj-$(CONFIG_SENSORS_AMS) += ams/ | ||
diff --git a/drivers/hwmon/ams/Makefile b/drivers/macintosh/ams/Makefile index 41c95b2089dc..41c95b2089dc 100644 --- a/drivers/hwmon/ams/Makefile +++ b/drivers/macintosh/ams/Makefile | |||
diff --git a/drivers/hwmon/ams/ams-core.c b/drivers/macintosh/ams/ams-core.c index 2ad62c339cd2..2ad62c339cd2 100644 --- a/drivers/hwmon/ams/ams-core.c +++ b/drivers/macintosh/ams/ams-core.c | |||
diff --git a/drivers/hwmon/ams/ams-i2c.c b/drivers/macintosh/ams/ams-i2c.c index abeecd27b484..abeecd27b484 100644 --- a/drivers/hwmon/ams/ams-i2c.c +++ b/drivers/macintosh/ams/ams-i2c.c | |||
diff --git a/drivers/hwmon/ams/ams-input.c b/drivers/macintosh/ams/ams-input.c index 8a712392cd38..8a712392cd38 100644 --- a/drivers/hwmon/ams/ams-input.c +++ b/drivers/macintosh/ams/ams-input.c | |||
diff --git a/drivers/hwmon/ams/ams-pmu.c b/drivers/macintosh/ams/ams-pmu.c index 4f61b3ee1b08..4f61b3ee1b08 100644 --- a/drivers/hwmon/ams/ams-pmu.c +++ b/drivers/macintosh/ams/ams-pmu.c | |||
diff --git a/drivers/hwmon/ams/ams.h b/drivers/macintosh/ams/ams.h index 90f094d45450..90f094d45450 100644 --- a/drivers/hwmon/ams/ams.h +++ b/drivers/macintosh/ams/ams.h | |||
