Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge master.kernel.org:/pub/scm/linux/kernel/git/gregkh/i2c-2.6

* master.kernel.org:/pub/scm/linux/kernel/git/gregkh/i2c-2.6: (44 commits)
[PATCH] I2C: I2C controllers go into right place on sysfs
[PATCH] hwmon-vid: Add support for Intel Core and Conroe
[PATCH] lm70: New hardware monitoring driver
[PATCH] hwmon: Fix the Kconfig header
[PATCH] i2c-i801: Merge setup function
[PATCH] i2c-i801: Better pci subsystem integration
[PATCH] i2c-i801: Cleanups
[PATCH] i2c-i801: Remove PCI function check
[PATCH] i2c-i801: Remove force_addr parameter
[PATCH] i2c-i801: Fix block transaction poll loops
[PATCH] scx200_acb: Documentation update
[PATCH] scx200_acb: Mark scx200_acb_probe __init
[PATCH] scx200_acb: Use PCI I/O resource when appropriate
[PATCH] i2c: Mark block write buffers as const
[PATCH] i2c-ocores: Minor cleanups
[PATCH] abituguru: Fix fan detection
[PATCH] abituguru: Review fixes
[PATCH] abituguru: New hardware monitoring driver
[PATCH] w83792d: Add missing data access locks
[PATCH] w83792d: Fix setting the PWM value
...

+5745 -472
+59
Documentation/hwmon/abituguru
··· 1 + Kernel driver abituguru 2 + ======================= 3 + 4 + Supported chips: 5 + * Abit uGuru (Hardware Monitor part only) 6 + Prefix: 'abituguru' 7 + Addresses scanned: ISA 0x0E0 8 + Datasheet: Not available, this driver is based on reverse engineering. 9 + A "Datasheet" has been written based on the reverse engineering it 10 + should be available in the same dir as this file under the name 11 + abituguru-datasheet. 12 + 13 + Authors: 14 + Hans de Goede <j.w.r.degoede@hhs.nl>, 15 + (Initial reverse engineering done by Olle Sandberg 16 + <ollebull@gmail.com>) 17 + 18 + 19 + Module Parameters 20 + ----------------- 21 + 22 + * force: bool Force detection. Note this parameter only causes the 23 + detection to be skipped, if the uGuru can't be read 24 + the module initialization (insmod) will still fail. 25 + * fan_sensors: int Tell the driver how many fan speed sensors there are 26 + on your motherboard. Default: 0 (autodetect). 27 + * pwms: int Tell the driver how many fan speed controls (fan 28 + pwms) your motherboard has. Default: 0 (autodetect). 29 + * verbose: int How verbose should the driver be? (0-3): 30 + 0 normal output 31 + 1 + verbose error reporting 32 + 2 + sensors type probing info\n" 33 + 3 + retryable error reporting 34 + Default: 2 (the driver is still in the testing phase) 35 + 36 + Notice if you need any of the first three options above please insmod the 37 + driver with verbose set to 3 and mail me <j.w.r.degoede@hhs.nl> the output of: 38 + dmesg | grep abituguru 39 + 40 + 41 + Description 42 + ----------- 43 + 44 + This driver supports the hardware monitoring features of the Abit uGuru chip 45 + found on Abit uGuru featuring motherboards (most modern Abit motherboards). 46 + 47 + The uGuru chip in reality is a Winbond W83L950D in disguise (despite Abit 48 + claiming it is "a new microprocessor designed by the ABIT Engineers"). 49 + Unfortunatly this doesn't help since the W83L950D is a generic 50 + microcontroller with a custom Abit application running on it. 51 + 52 + Despite Abit not releasing any information regarding the uGuru, Olle 53 + Sandberg <ollebull@gmail.com> has managed to reverse engineer the sensor part 54 + of the uGuru. Without his work this driver would not have been possible. 55 + 56 + Known Issues 57 + ------------ 58 + 59 + The voltage and frequency control parts of the Abit uGuru are not supported.
+312
Documentation/hwmon/abituguru-datasheet
··· 1 + uGuru datasheet 2 + =============== 3 + 4 + First of all, what I know about uGuru is no fact based on any help, hints or 5 + datasheet from Abit. The data I have got on uGuru have I assembled through 6 + my weak knowledge in "backwards engineering". 7 + And just for the record, you may have noticed uGuru isn't a chip developed by 8 + Abit, as they claim it to be. It's realy just an microprocessor (uC) created by 9 + Winbond (W83L950D). And no, reading the manual for this specific uC or 10 + mailing Windbond for help won't give any usefull data about uGuru, as it is 11 + the program inside the uC that is responding to calls. 12 + 13 + Olle Sandberg <ollebull@gmail.com>, 2005-05-25 14 + 15 + 16 + Original version by Olle Sandberg who did the heavy lifting of the initial 17 + reverse engineering. This version has been almost fully rewritten for clarity 18 + and extended with write support and info on more databanks, the write support 19 + is once again reverse engineered by Olle the additional databanks have been 20 + reverse engineered by me. I would like to express my thanks to Olle, this 21 + document and the Linux driver could not have been written without his efforts. 22 + 23 + Note: because of the lack of specs only the sensors part of the uGuru is 24 + described here and not the CPU / RAM / etc voltage & frequency control. 25 + 26 + Hans de Goede <j.w.r.degoede@hhs.nl>, 28-01-2006 27 + 28 + 29 + Detection 30 + ========= 31 + 32 + As far as known the uGuru is always placed at and using the (ISA) I/O-ports 33 + 0xE0 and 0xE4, so we don't have to scan any port-range, just check what the two 34 + ports are holding for detection. We will refer to 0xE0 as CMD (command-port) 35 + and 0xE4 as DATA because Abit refers to them with these names. 36 + 37 + If DATA holds 0x00 or 0x08 and CMD holds 0x00 or 0xAC an uGuru could be 38 + present. We have to check for two different values at data-port, because 39 + after a reboot uGuru will hold 0x00 here, but if the driver is removed and 40 + later on attached again data-port will hold 0x08, more about this later. 41 + 42 + After wider testing of the Linux kernel driver some variants of the uGuru have 43 + turned up which will hold 0x00 instead of 0xAC at the CMD port, thus we also 44 + have to test CMD for two different values. On these uGuru's DATA will initally 45 + hold 0x09 and will only hold 0x08 after reading CMD first, so CMD must be read 46 + first! 47 + 48 + To be really sure an uGuru is present a test read of one or more register 49 + sets should be done. 50 + 51 + 52 + Reading / Writing 53 + ================= 54 + 55 + Addressing 56 + ---------- 57 + 58 + The uGuru has a number of different addressing levels. The first addressing 59 + level we will call banks. A bank holds data for one or more sensors. The data 60 + in a bank for a sensor is one or more bytes large. 61 + 62 + The number of bytes is fixed for a given bank, you should always read or write 63 + that many bytes, reading / writing more will fail, the results when writing 64 + less then the number of bytes for a given bank are undetermined. 65 + 66 + See below for all known bank addresses, numbers of sensors in that bank, 67 + number of bytes data per sensor and contents/meaning of those bytes. 68 + 69 + Although both this document and the kernel driver have kept the sensor 70 + terminoligy for the addressing within a bank this is not 100% correct, in 71 + bank 0x24 for example the addressing within the bank selects a PWM output not 72 + a sensor. 73 + 74 + Notice that some banks have both a read and a write address this is how the 75 + uGuru determines if a read from or a write to the bank is taking place, thus 76 + when reading you should always use the read address and when writing the 77 + write address. The write address is always one (1) more then the read address. 78 + 79 + 80 + uGuru ready 81 + ----------- 82 + 83 + Before you can read from or write to the uGuru you must first put the uGuru 84 + in "ready" mode. 85 + 86 + To put the uGuru in ready mode first write 0x00 to DATA and then wait for DATA 87 + to hold 0x09, DATA should read 0x09 within 250 read cycles. 88 + 89 + Next CMD _must_ be read and should hold 0xAC, usually CMD will hold 0xAC the 90 + first read but sometimes it takes a while before CMD holds 0xAC and thus it 91 + has to be read a number of times (max 50). 92 + 93 + After reading CMD, DATA should hold 0x08 which means that the uGuru is ready 94 + for input. As above DATA will usually hold 0x08 the first read but not always. 95 + This step can be skipped, but it is undetermined what happens if the uGuru has 96 + not yet reported 0x08 at DATA and you proceed with writing a bank address. 97 + 98 + 99 + Sending bank and sensor addresses to the uGuru 100 + ---------------------------------------------- 101 + 102 + First the uGuru must be in "ready" mode as described above, DATA should hold 103 + 0x08 indicating that the uGuru wants input, in this case the bank address. 104 + 105 + Next write the bank address to DATA. After the bank address has been written 106 + wait for to DATA to hold 0x08 again indicating that it wants / is ready for 107 + more input (max 250 reads). 108 + 109 + Once DATA holds 0x08 again write the sensor address to CMD. 110 + 111 + 112 + Reading 113 + ------- 114 + 115 + First send the bank and sensor addresses as described above. 116 + Then for each byte of data you want to read wait for DATA to hold 0x01 117 + which indicates that the uGuru is ready to be read (max 250 reads) and once 118 + DATA holds 0x01 read the byte from CMD. 119 + 120 + Once all bytes have been read data will hold 0x09, but there is no reason to 121 + test for this. Notice that the number of bytes is bank address dependent see 122 + above and below. 123 + 124 + After completing a successfull read it is advised to put the uGuru back in 125 + ready mode, so that it is ready for the next read / write cycle. This way 126 + if your program / driver is unloaded and later loaded again the detection 127 + algorithm described above will still work. 128 + 129 + 130 + 131 + Writing 132 + ------- 133 + 134 + First send the bank and sensor addresses as described above. 135 + Then for each byte of data you want to write wait for DATA to hold 0x00 136 + which indicates that the uGuru is ready to be written (max 250 reads) and 137 + once DATA holds 0x00 write the byte to CMD. 138 + 139 + Once all bytes have been written wait for DATA to hold 0x01 (max 250 reads) 140 + don't ask why this is the way it is. 141 + 142 + Once DATA holds 0x01 read CMD it should hold 0xAC now. 143 + 144 + After completing a successfull write it is advised to put the uGuru back in 145 + ready mode, so that it is ready for the next read / write cycle. This way 146 + if your program / driver is unloaded and later loaded again the detection 147 + algorithm described above will still work. 148 + 149 + 150 + Gotchas 151 + ------- 152 + 153 + After wider testing of the Linux kernel driver some variants of the uGuru have 154 + turned up which do not hold 0x08 at DATA within 250 reads after writing the 155 + bank address. With these versions this happens quite frequent, using larger 156 + timeouts doesn't help, they just go offline for a second or 2, doing some 157 + internal callibration or whatever. Your code should be prepared to handle 158 + this and in case of no response in this specific case just goto sleep for a 159 + while and then retry. 160 + 161 + 162 + Address Map 163 + =========== 164 + 165 + Bank 0x20 Alarms (R) 166 + -------------------- 167 + This bank contains 0 sensors, iow the sensor address is ignored (but must be 168 + written) just use 0. Bank 0x20 contains 3 bytes: 169 + 170 + Byte 0: 171 + This byte holds the alarm flags for sensor 0-7 of Sensor Bank1, with bit 0 172 + corresponding to sensor 0, 1 to 1, etc. 173 + 174 + Byte 1: 175 + This byte holds the alarm flags for sensor 8-15 of Sensor Bank1, with bit 0 176 + corresponding to sensor 8, 1 to 9, etc. 177 + 178 + Byte 2: 179 + This byte holds the alarm flags for sensor 0-5 of Sensor Bank2, with bit 0 180 + corresponding to sensor 0, 1 to 1, etc. 181 + 182 + 183 + Bank 0x21 Sensor Bank1 Values / Readings (R) 184 + -------------------------------------------- 185 + This bank contains 16 sensors, for each sensor it contains 1 byte. 186 + So far the following sensors are known to be available on all motherboards: 187 + Sensor 0 CPU temp 188 + Sensor 1 SYS temp 189 + Sensor 3 CPU core volt 190 + Sensor 4 DDR volt 191 + Sensor 10 DDR Vtt volt 192 + Sensor 15 PWM temp 193 + 194 + Byte 0: 195 + This byte holds the reading from the sensor. Sensors in Bank1 can be both 196 + volt and temp sensors, this is motherboard specific. The uGuru however does 197 + seem to know (be programmed with) what kindoff sensor is attached see Sensor 198 + Bank1 Settings description. 199 + 200 + Volt sensors use a linear scale, a reading 0 corresponds with 0 volt and a 201 + reading of 255 with 3494 mV. The sensors for higher voltages however are 202 + connected through a division circuit. The currently known division circuits 203 + in use result in ranges of: 0-4361mV, 0-6248mV or 0-14510mV. 3.3 volt sources 204 + use the 0-4361mV range, 5 volt the 0-6248mV and 12 volt the 0-14510mV . 205 + 206 + Temp sensors also use a linear scale, a reading of 0 corresponds with 0 degree 207 + Celsius and a reading of 255 with a reading of 255 degrees Celsius. 208 + 209 + 210 + Bank 0x22 Sensor Bank1 Settings (R) 211 + Bank 0x23 Sensor Bank1 Settings (W) 212 + ----------------------------------- 213 + 214 + This bank contains 16 sensors, for each sensor it contains 3 bytes. Each 215 + set of 3 bytes contains the settings for the sensor with the same sensor 216 + address in Bank 0x21 . 217 + 218 + Byte 0: 219 + Alarm behaviour for the selected sensor. A 1 enables the described behaviour. 220 + Bit 0: Give an alarm if measured temp is over the warning threshold (RW) * 221 + Bit 1: Give an alarm if measured volt is over the max threshold (RW) ** 222 + Bit 2: Give an alarm if measured volt is under the min threshold (RW) ** 223 + Bit 3: Beep if alarm (RW) 224 + Bit 4: 1 if alarm cause measured temp is over the warning threshold (R) 225 + Bit 5: 1 if alarm cause measured volt is over the max threshold (R) 226 + Bit 6: 1 if alarm cause measured volt is under the min threshold (R) 227 + Bit 7: Volt sensor: Shutdown if alarm persist for more then 4 seconds (RW) 228 + Temp sensor: Shutdown if temp is over the shutdown threshold (RW) 229 + 230 + * This bit is only honored/used by the uGuru if a temp sensor is connected 231 + ** This bit is only honored/used by the uGuru if a volt sensor is connected 232 + Note with some trickery this can be used to find out what kinda sensor is 233 + detected see the Linux kernel driver for an example with many comments on 234 + how todo this. 235 + 236 + Byte 1: 237 + Temp sensor: warning threshold (scale as bank 0x21) 238 + Volt sensor: min threshold (scale as bank 0x21) 239 + 240 + Byte 2: 241 + Temp sensor: shutdown threshold (scale as bank 0x21) 242 + Volt sensor: max threshold (scale as bank 0x21) 243 + 244 + 245 + Bank 0x24 PWM outputs for FAN's (R) 246 + Bank 0x25 PWM outputs for FAN's (W) 247 + ----------------------------------- 248 + 249 + This bank contains 3 "sensors", for each sensor it contains 5 bytes. 250 + Sensor 0 usually controls the CPU fan 251 + Sensor 1 usually controls the NB (or chipset for single chip) fan 252 + Sensor 2 usually controls the System fan 253 + 254 + Byte 0: 255 + Flag 0x80 to enable control, Fan runs at 100% when disabled. 256 + low nibble (temp)sensor address at bank 0x21 used for control. 257 + 258 + Byte 1: 259 + 0-255 = 0-12v (linear), specify voltage at which fan will rotate when under 260 + low threshold temp (specified in byte 3) 261 + 262 + Byte 2: 263 + 0-255 = 0-12v (linear), specify voltage at which fan will rotate when above 264 + high threshold temp (specified in byte 4) 265 + 266 + Byte 3: 267 + Low threshold temp (scale as bank 0x21) 268 + 269 + byte 4: 270 + High threshold temp (scale as bank 0x21) 271 + 272 + 273 + Bank 0x26 Sensors Bank2 Values / Readings (R) 274 + --------------------------------------------- 275 + 276 + This bank contains 6 sensors (AFAIK), for each sensor it contains 1 byte. 277 + So far the following sensors are known to be available on all motherboards: 278 + Sensor 0: CPU fan speed 279 + Sensor 1: NB (or chipset for single chip) fan speed 280 + Sensor 2: SYS fan speed 281 + 282 + Byte 0: 283 + This byte holds the reading from the sensor. 0-255 = 0-15300 (linear) 284 + 285 + 286 + Bank 0x27 Sensors Bank2 Settings (R) 287 + Bank 0x28 Sensors Bank2 Settings (W) 288 + ------------------------------------ 289 + 290 + This bank contains 6 sensors (AFAIK), for each sensor it contains 2 bytes. 291 + 292 + Byte 0: 293 + Alarm behaviour for the selected sensor. A 1 enables the described behaviour. 294 + Bit 0: Give an alarm if measured rpm is under the min threshold (RW) 295 + Bit 3: Beep if alarm (RW) 296 + Bit 7: Shutdown if alarm persist for more then 4 seconds (RW) 297 + 298 + Byte 1: 299 + min threshold (scale as bank 0x26) 300 + 301 + 302 + Warning for the adventerous 303 + =========================== 304 + 305 + A word of caution to those who want to experiment and see if they can figure 306 + the voltage / clock programming out, I tried reading and only reading banks 307 + 0-0x30 with the reading code used for the sensor banks (0x20-0x28) and this 308 + resulted in a _permanent_ reprogramming of the voltages, luckily I had the 309 + sensors part configured so that it would shutdown my system on any out of spec 310 + voltages which proprably safed my computer (after a reboot I managed to 311 + immediatly enter the bios and reload the defaults). This probably means that 312 + the read/write cycle for the non sensor part is different from the sensor part.
+31
Documentation/hwmon/lm70
··· 1 + Kernel driver lm70 2 + ================== 3 + 4 + Supported chip: 5 + * National Semiconductor LM70 6 + Datasheet: http://www.national.com/pf/LM/LM70.html 7 + 8 + Author: 9 + Kaiwan N Billimoria <kaiwan@designergraphix.com> 10 + 11 + Description 12 + ----------- 13 + 14 + This driver implements support for the National Semiconductor LM70 15 + temperature sensor. 16 + 17 + The LM70 temperature sensor chip supports a single temperature sensor. 18 + It communicates with a host processor (or microcontroller) via an 19 + SPI/Microwire Bus interface. 20 + 21 + Communication with the LM70 is simple: when the temperature is to be sensed, 22 + the driver accesses the LM70 using SPI communication: 16 SCLK cycles 23 + comprise the MOSI/MISO loop. At the end of the transfer, the 11-bit 2's 24 + complement digital temperature (sent via the SIO line), is available in the 25 + driver for interpretation. This driver makes use of the kernel's in-core 26 + SPI support. 27 + 28 + Thanks to 29 + --------- 30 + Jean Delvare <khali@linux-fr.org> for mentoring the hwmon-side driver 31 + development.
+13 -4
Documentation/hwmon/lm83
··· 7 7 Addresses scanned: I2C 0x18 - 0x1a, 0x29 - 0x2b, 0x4c - 0x4e 8 8 Datasheet: Publicly available at the National Semiconductor website 9 9 http://www.national.com/pf/LM/LM83.html 10 + * National Semiconductor LM82 11 + Addresses scanned: I2C 0x18 - 0x1a, 0x29 - 0x2b, 0x4c - 0x4e 12 + Datasheet: Publicly available at the National Semiconductor website 13 + http://www.national.com/pf/LM/LM82.html 10 14 11 15 12 16 Author: Jean Delvare <khali@linux-fr.org> ··· 19 15 ----------- 20 16 21 17 The LM83 is a digital temperature sensor. It senses its own temperature as 22 - well as the temperature of up to three external diodes. It is compatible 23 - with many other devices such as the LM84 and all other ADM1021 clones. 24 - The main difference between the LM83 and the LM84 in that the later can 25 - only sense the temperature of one external diode. 18 + well as the temperature of up to three external diodes. The LM82 is 19 + a stripped down version of the LM83 that only supports one external diode. 20 + Both are compatible with many other devices such as the LM84 and all 21 + other ADM1021 clones. The main difference between the LM83 and the LM84 22 + in that the later can only sense the temperature of one external diode. 26 23 27 24 Using the adm1021 driver for a LM83 should work, but only two temperatures 28 25 will be reported instead of four. ··· 35 30 36 31 Confirmed motherboards: 37 32 SBS P014 33 + SBS PSL09 38 34 39 35 Unconfirmed motherboards: 40 36 Gigabyte GA-8IK1100 41 37 Iwill MPX2 42 38 Soltek SL-75DRV5 39 + 40 + The LM82 is confirmed to have been found on most AMD Geode reference 41 + designs and test platforms. 43 42 44 43 The driver has been successfully tested by Magnus Forsstr�m, who I'd 45 44 like to thank here. More testers will be of course welcome.
+102
Documentation/hwmon/smsc47m192
··· 1 + Kernel driver smsc47m192 2 + ======================== 3 + 4 + Supported chips: 5 + * SMSC LPC47M192 and LPC47M997 6 + Prefix: 'smsc47m192' 7 + Addresses scanned: I2C 0x2c - 0x2d 8 + Datasheet: The datasheet for LPC47M192 is publicly available from 9 + http://www.smsc.com/ 10 + The LPC47M997 is compatible for hardware monitoring. 11 + 12 + Author: Hartmut Rick <linux@rick.claranet.de> 13 + Special thanks to Jean Delvare for careful checking 14 + of the code and many helpful comments and suggestions. 15 + 16 + 17 + Description 18 + ----------- 19 + 20 + This driver implements support for the hardware sensor capabilities 21 + of the SMSC LPC47M192 and LPC47M997 Super-I/O chips. 22 + 23 + These chips support 3 temperature channels and 8 voltage inputs 24 + as well as CPU voltage VID input. 25 + 26 + They do also have fan monitoring and control capabilities, but the 27 + these features are accessed via ISA bus and are not supported by this 28 + driver. Use the 'smsc47m1' driver for fan monitoring and control. 29 + 30 + Voltages and temperatures are measured by an 8-bit ADC, the resolution 31 + of the temperatures is 1 bit per degree C. 32 + Voltages are scaled such that the nominal voltage corresponds to 33 + 192 counts, i.e. 3/4 of the full range. Thus the available range for 34 + each voltage channel is 0V ... 255/192*(nominal voltage), the resolution 35 + is 1 bit per (nominal voltage)/192. 36 + Both voltage and temperature values are scaled by 1000, the sys files 37 + show voltages in mV and temperatures in units of 0.001 degC. 38 + 39 + The +12V analog voltage input channel (in4_input) is multiplexed with 40 + bit 4 of the encoded CPU voltage. This means that you either get 41 + a +12V voltage measurement or a 5 bit CPU VID, but not both. 42 + The default setting is to use the pin as 12V input, and use only 4 bit VID. 43 + This driver assumes that the information in the configuration register 44 + is correct, i.e. that the BIOS has updated the configuration if 45 + the motherboard has this input wired to VID4. 46 + 47 + The temperature and voltage readings are updated once every 1.5 seconds. 48 + Reading them more often repeats the same values. 49 + 50 + 51 + sysfs interface 52 + --------------- 53 + 54 + in0_input - +2.5V voltage input 55 + in1_input - CPU voltage input (nominal 2.25V) 56 + in2_input - +3.3V voltage input 57 + in3_input - +5V voltage input 58 + in4_input - +12V voltage input (may be missing if used as VID4) 59 + in5_input - Vcc voltage input (nominal 3.3V) 60 + This is the supply voltage of the sensor chip itself. 61 + in6_input - +1.5V voltage input 62 + in7_input - +1.8V voltage input 63 + 64 + in[0-7]_min, 65 + in[0-7]_max - lower and upper alarm thresholds for in[0-7]_input reading 66 + 67 + All voltages are read and written in mV. 68 + 69 + in[0-7]_alarm - alarm flags for voltage inputs 70 + These files read '1' in case of alarm, '0' otherwise. 71 + 72 + temp1_input - chip temperature measured by on-chip diode 73 + temp[2-3]_input - temperature measured by external diodes (one of these would 74 + typically be wired to the diode inside the CPU) 75 + 76 + temp[1-3]_min, 77 + temp[1-3]_max - lower and upper alarm thresholds for temperatures 78 + 79 + temp[1-3]_offset - temperature offset registers 80 + The chip adds the offsets stored in these registers to 81 + the corresponding temperature readings. 82 + Note that temp1 and temp2 offsets share the same register, 83 + they cannot both be different from zero at the same time. 84 + Writing a non-zero number to one of them will reset the other 85 + offset to zero. 86 + 87 + All temperatures and offsets are read and written in 88 + units of 0.001 degC. 89 + 90 + temp[1-3]_alarm - alarm flags for temperature inputs, '1' in case of alarm, 91 + '0' otherwise. 92 + temp[2-3]_input_fault - diode fault flags for temperature inputs 2 and 3. 93 + A fault is detected if the two pins for the corresponding 94 + sensor are open or shorted, or any of the two is shorted 95 + to ground or Vcc. '1' indicates a diode fault. 96 + 97 + cpu0_vid - CPU voltage as received from the CPU 98 + 99 + vrm - CPU VID standard used for decoding CPU voltage 100 + 101 + The *_min, *_max, *_offset and vrm files can be read and 102 + written, all others are read-only.
+188 -88
Documentation/hwmon/sysfs-interface
··· 3 3 4 4 The libsensors library offers an interface to the raw sensors data 5 5 through the sysfs interface. See libsensors documentation and source for 6 - more further information. As of writing this document, libsensors 7 - (from lm_sensors 2.8.3) is heavily chip-dependant. Adding or updating 6 + further information. As of writing this document, libsensors 7 + (from lm_sensors 2.8.3) is heavily chip-dependent. Adding or updating 8 8 support for any given chip requires modifying the library's code. 9 9 This is because libsensors was written for the procfs interface 10 10 older kernel modules were using, which wasn't standardized enough. 11 11 Recent versions of libsensors (from lm_sensors 2.8.2 and later) have 12 12 support for the sysfs interface, though. 13 13 14 - The new sysfs interface was designed to be as chip-independant as 14 + The new sysfs interface was designed to be as chip-independent as 15 15 possible. 16 16 17 17 Note that motherboards vary widely in the connections to sensor chips. ··· 24 24 can change from motherboard to motherboard, the conversions cannot be 25 25 hard coded into the driver and have to be done in user space. 26 26 27 - For this reason, even if we aim at a chip-independant libsensors, it will 27 + For this reason, even if we aim at a chip-independent libsensors, it will 28 28 still require a configuration file (e.g. /etc/sensors.conf) for proper 29 29 values conversion, labeling of inputs and hiding of unused inputs. 30 30 ··· 39 39 this standard. 40 40 41 41 Note that this standard isn't completely established yet, so it is subject 42 - to changes, even important ones. One more reason to use the library instead 43 - of accessing sysfs files directly. 42 + to changes. If you are writing a new hardware monitoring driver those 43 + features can't seem to fit in this interface, please contact us with your 44 + extension proposal. Keep in mind that backward compatibility must be 45 + preserved. 44 46 45 47 Each chip gets its own directory in the sysfs /sys/devices tree. To 46 - find all sensor chips, it is easier to follow the symlinks from 47 - /sys/i2c/devices/ 48 + find all sensor chips, it is easier to follow the device symlinks from 49 + /sys/class/hwmon/hwmon*. 48 50 49 - All sysfs values are fixed point numbers. To get the true value of some 50 - of the values, you should divide by the specified value. 51 + All sysfs values are fixed point numbers. 51 52 52 53 There is only one value per file, unlike the older /proc specification. 53 54 The common scheme for files naming is: <type><number>_<item>. Usual ··· 70 69 71 70 ------------------------------------------------------------------------- 72 71 72 + [0-*] denotes any positive number starting from 0 73 + [1-*] denotes any positive number starting from 1 74 + RO read only value 75 + RW read/write value 76 + 77 + Read/write values may be read-only for some chips, depending on the 78 + hardware implementation. 79 + 80 + All entries are optional, and should only be created in a given driver 81 + if the chip has the feature. 82 + 73 83 ************ 74 84 * Voltages * 75 85 ************ 76 86 77 - in[0-8]_min Voltage min value. 87 + in[0-*]_min Voltage min value. 78 88 Unit: millivolt 79 - Read/Write 89 + RW 80 90 81 - in[0-8]_max Voltage max value. 91 + in[0-*]_max Voltage max value. 82 92 Unit: millivolt 83 - Read/Write 93 + RW 84 94 85 - in[0-8]_input Voltage input value. 95 + in[0-*]_input Voltage input value. 86 96 Unit: millivolt 87 - Read only 97 + RO 98 + Voltage measured on the chip pin. 88 99 Actual voltage depends on the scaling resistors on the 89 100 motherboard, as recommended in the chip datasheet. 90 101 This varies by chip and by motherboard. 91 102 Because of this variation, values are generally NOT scaled 92 103 by the chip driver, and must be done by the application. 93 104 However, some drivers (notably lm87 and via686a) 94 - do scale, with various degrees of success. 105 + do scale, because of internal resistors built into a chip. 95 106 These drivers will output the actual voltage. 96 107 97 108 Typical usage: ··· 117 104 in7_* varies 118 105 in8_* varies 119 106 120 - cpu[0-1]_vid CPU core reference voltage. 107 + cpu[0-*]_vid CPU core reference voltage. 121 108 Unit: millivolt 122 - Read only. 109 + RO 123 110 Not always correct. 124 111 125 112 vrm Voltage Regulator Module version number. 126 - Read only. 127 - Two digit number, first is major version, second is 128 - minor version. 113 + RW (but changing it should no more be necessary) 114 + Originally the VRM standard version multiplied by 10, but now 115 + an arbitrary number, as not all standards have a version 116 + number. 129 117 Affects the way the driver calculates the CPU core reference 130 118 voltage from the vid pins. 119 + 120 + Also see the Alarms section for status flags associated with voltages. 131 121 132 122 133 123 ******** 134 124 * Fans * 135 125 ******** 136 126 137 - fan[1-3]_min Fan minimum value 127 + fan[1-*]_min Fan minimum value 138 128 Unit: revolution/min (RPM) 139 - Read/Write. 129 + RW 140 130 141 - fan[1-3]_input Fan input value. 131 + fan[1-*]_input Fan input value. 142 132 Unit: revolution/min (RPM) 143 - Read only. 133 + RO 144 134 145 - fan[1-3]_div Fan divisor. 135 + fan[1-*]_div Fan divisor. 146 136 Integer value in powers of two (1, 2, 4, 8, 16, 32, 64, 128). 137 + RW 147 138 Some chips only support values 1, 2, 4 and 8. 148 139 Note that this is actually an internal clock divisor, which 149 140 affects the measurable speed range, not the read value. 141 + 142 + Also see the Alarms section for status flags associated with fans. 143 + 150 144 151 145 ******* 152 146 * PWM * 153 147 ******* 154 148 155 - pwm[1-3] Pulse width modulation fan control. 149 + pwm[1-*] Pulse width modulation fan control. 156 150 Integer value in the range 0 to 255 157 - Read/Write 151 + RW 158 152 255 is max or 100%. 159 153 160 - pwm[1-3]_enable 154 + pwm[1-*]_enable 161 155 Switch PWM on and off. 162 156 Not always present even if fan*_pwm is. 163 - 0 to turn off 164 - 1 to turn on in manual mode 165 - 2 to turn on in automatic mode 166 - Read/Write 157 + 0: turn off 158 + 1: turn on in manual mode 159 + 2+: turn on in automatic mode 160 + Check individual chip documentation files for automatic mode details. 161 + RW 162 + 163 + pwm[1-*]_mode 164 + 0: DC mode 165 + 1: PWM mode 166 + RW 167 167 168 168 pwm[1-*]_auto_channels_temp 169 169 Select which temperature channels affect this PWM output in 170 170 auto mode. Bitfield, 1 is temp1, 2 is temp2, 4 is temp3 etc... 171 171 Which values are possible depend on the chip used. 172 + RW 172 173 173 174 pwm[1-*]_auto_point[1-*]_pwm 174 175 pwm[1-*]_auto_point[1-*]_temp ··· 190 163 Define the PWM vs temperature curve. Number of trip points is 191 164 chip-dependent. Use this for chips which associate trip points 192 165 to PWM output channels. 166 + RW 193 167 194 168 OR 195 169 ··· 200 172 Define the PWM vs temperature curve. Number of trip points is 201 173 chip-dependent. Use this for chips which associate trip points 202 174 to temperature channels. 175 + RW 203 176 204 177 205 178 **************** 206 179 * Temperatures * 207 180 **************** 208 181 209 - temp[1-3]_type Sensor type selection. 182 + temp[1-*]_type Sensor type selection. 210 183 Integers 1 to 4 or thermistor Beta value (typically 3435) 211 - Read/Write. 184 + RW 212 185 1: PII/Celeron Diode 213 186 2: 3904 transistor 214 187 3: thermal diode 215 188 4: thermistor (default/unknown Beta) 216 189 Not all types are supported by all chips 217 190 218 - temp[1-4]_max Temperature max value. 219 - Unit: millidegree Celcius 220 - Read/Write value. 191 + temp[1-*]_max Temperature max value. 192 + Unit: millidegree Celsius (or millivolt, see below) 193 + RW 221 194 222 - temp[1-3]_min Temperature min value. 223 - Unit: millidegree Celcius 224 - Read/Write value. 195 + temp[1-*]_min Temperature min value. 196 + Unit: millidegree Celsius 197 + RW 225 198 226 - temp[1-3]_max_hyst 199 + temp[1-*]_max_hyst 227 200 Temperature hysteresis value for max limit. 228 - Unit: millidegree Celcius 201 + Unit: millidegree Celsius 229 202 Must be reported as an absolute temperature, NOT a delta 230 203 from the max value. 231 - Read/Write value. 204 + RW 232 205 233 - temp[1-4]_input Temperature input value. 234 - Unit: millidegree Celcius 235 - Read only value. 206 + temp[1-*]_input Temperature input value. 207 + Unit: millidegree Celsius 208 + RO 236 209 237 - temp[1-4]_crit Temperature critical value, typically greater than 210 + temp[1-*]_crit Temperature critical value, typically greater than 238 211 corresponding temp_max values. 239 - Unit: millidegree Celcius 240 - Read/Write value. 212 + Unit: millidegree Celsius 213 + RW 241 214 242 - temp[1-2]_crit_hyst 215 + temp[1-*]_crit_hyst 243 216 Temperature hysteresis value for critical limit. 244 - Unit: millidegree Celcius 217 + Unit: millidegree Celsius 245 218 Must be reported as an absolute temperature, NOT a delta 246 219 from the critical value. 220 + RW 221 + 222 + temp[1-4]_offset 223 + Temperature offset which is added to the temperature reading 224 + by the chip. 225 + Unit: millidegree Celsius 247 226 Read/Write value. 248 227 249 228 If there are multiple temperature sensors, temp1_* is ··· 260 225 itself, for example the thermal diode inside the CPU or 261 226 a thermistor nearby. 262 227 228 + Some chips measure temperature using external thermistors and an ADC, and 229 + report the temperature measurement as a voltage. Converting this voltage 230 + back to a temperature (or the other way around for limits) requires 231 + mathematical functions not available in the kernel, so the conversion 232 + must occur in user space. For these chips, all temp* files described 233 + above should contain values expressed in millivolt instead of millidegree 234 + Celsius. In other words, such temperature channels are handled as voltage 235 + channels by the driver. 236 + 237 + Also see the Alarms section for status flags associated with temperatures. 238 + 263 239 264 240 ************ 265 241 * Currents * ··· 279 233 Note that no known chip provides current measurements as of writing, 280 234 so this part is theoretical, so to say. 281 235 282 - curr[1-n]_max Current max value 236 + curr[1-*]_max Current max value 283 237 Unit: milliampere 284 - Read/Write. 238 + RW 285 239 286 - curr[1-n]_min Current min value. 240 + curr[1-*]_min Current min value. 287 241 Unit: milliampere 288 - Read/Write. 242 + RW 289 243 290 - curr[1-n]_input Current input value 244 + curr[1-*]_input Current input value 291 245 Unit: milliampere 292 - Read only. 246 + RO 293 247 294 248 295 - ********* 296 - * Other * 297 - ********* 249 + ********** 250 + * Alarms * 251 + ********** 252 + 253 + Each channel or limit may have an associated alarm file, containing a 254 + boolean value. 1 means than an alarm condition exists, 0 means no alarm. 255 + 256 + Usually a given chip will either use channel-related alarms, or 257 + limit-related alarms, not both. The driver should just reflect the hardware 258 + implementation. 259 + 260 + in[0-*]_alarm 261 + fan[1-*]_alarm 262 + temp[1-*]_alarm 263 + Channel alarm 264 + 0: no alarm 265 + 1: alarm 266 + RO 267 + 268 + OR 269 + 270 + in[0-*]_min_alarm 271 + in[0-*]_max_alarm 272 + fan[1-*]_min_alarm 273 + temp[1-*]_min_alarm 274 + temp[1-*]_max_alarm 275 + temp[1-*]_crit_alarm 276 + Limit alarm 277 + 0: no alarm 278 + 1: alarm 279 + RO 280 + 281 + Each input channel may have an associated fault file. This can be used 282 + to notify open diodes, unconnected fans etc. where the hardware 283 + supports it. When this boolean has value 1, the measurement for that 284 + channel should not be trusted. 285 + 286 + in[0-*]_input_fault 287 + fan[1-*]_input_fault 288 + temp[1-*]_input_fault 289 + Input fault condition 290 + 0: no fault occured 291 + 1: fault condition 292 + RO 293 + 294 + Some chips also offer the possibility to get beeped when an alarm occurs: 295 + 296 + beep_enable Master beep enable 297 + 0: no beeps 298 + 1: beeps 299 + RW 300 + 301 + in[0-*]_beep 302 + fan[1-*]_beep 303 + temp[1-*]_beep 304 + Channel beep 305 + 0: disable 306 + 1: enable 307 + RW 308 + 309 + In theory, a chip could provide per-limit beep masking, but no such chip 310 + was seen so far. 311 + 312 + Old drivers provided a different, non-standard interface to alarms and 313 + beeps. These interface files are deprecated, but will be kept around 314 + for compatibility reasons: 298 315 299 316 alarms Alarm bitmask. 300 - Read only. 317 + RO 301 318 Integer representation of one to four bytes. 302 319 A '1' bit means an alarm. 303 320 Chips should be programmed for 'comparator' mode so that ··· 368 259 if it is still valid. 369 260 Generally a direct representation of a chip's internal 370 261 alarm registers; there is no standard for the position 371 - of individual bits. 262 + of individual bits. For this reason, the use of this 263 + interface file for new drivers is discouraged. Use 264 + individual *_alarm and *_fault files instead. 372 265 Bits are defined in kernel/include/sensors.h. 373 266 374 - alarms_in Alarm bitmask relative to in (voltage) channels 375 - Read only 376 - A '1' bit means an alarm, LSB corresponds to in0 and so on 377 - Prefered to 'alarms' for newer chips 378 - 379 - alarms_fan Alarm bitmask relative to fan channels 380 - Read only 381 - A '1' bit means an alarm, LSB corresponds to fan1 and so on 382 - Prefered to 'alarms' for newer chips 383 - 384 - alarms_temp Alarm bitmask relative to temp (temperature) channels 385 - Read only 386 - A '1' bit means an alarm, LSB corresponds to temp1 and so on 387 - Prefered to 'alarms' for newer chips 388 - 389 - beep_enable Beep/interrupt enable 390 - 0 to disable. 391 - 1 to enable. 392 - Read/Write 393 - 394 267 beep_mask Bitmask for beep. 395 - Same format as 'alarms' with the same bit locations. 396 - Read/Write 268 + Same format as 'alarms' with the same bit locations, 269 + use discouraged for the same reason. Use individual 270 + *_beep files instead. 271 + RW 272 + 273 + 274 + ********* 275 + * Other * 276 + ********* 397 277 398 278 eeprom Raw EEPROM data in binary form. 399 - Read only. 279 + RO 400 280 401 281 pec Enable or disable PEC (SMBus only) 402 - Read/Write 282 + 0: disable 283 + 1: enable 284 + RW
+9 -8
Documentation/hwmon/userspace-tools
··· 6 6 are also connected directly through the ISA bus. 7 7 8 8 The kernel drivers make the data from the sensor chips available in the /sys 9 - virtual filesystem. Userspace tools are then used to display or set or the 10 - data in a more friendly manner. 9 + virtual filesystem. Userspace tools are then used to display the measured 10 + values or configure the chips in a more friendly manner. 11 11 12 12 Lm-sensors 13 13 ---------- 14 14 15 - Core set of utilites that will allow you to obtain health information, 15 + Core set of utilities that will allow you to obtain health information, 16 16 setup monitoring limits etc. You can get them on their homepage 17 17 http://www.lm-sensors.nu/ or as a package from your Linux distribution. 18 18 19 19 If from website: 20 - Get lmsensors from project web site. Please note, you need only userspace 21 - part, so compile with "make user_install" target. 20 + Get lm-sensors from project web site. Please note, you need only userspace 21 + part, so compile with "make user" and install with "make user_install". 22 22 23 23 General hints to get things working: 24 24 25 25 0) get lm-sensors userspace utils 26 - 1) compile all drivers in I2C section as modules in your kernel 26 + 1) compile all drivers in I2C and Hardware Monitoring sections as modules 27 + in your kernel 27 28 2) run sensors-detect script, it will tell you what modules you need to load. 28 29 3) load them and run "sensors" command, you should see some results. 29 30 4) fix sensors.conf, labels, limits, fan divisors 30 31 5) if any more problems consult FAQ, or documentation 31 32 32 - Other utilites 33 - -------------- 33 + Other utilities 34 + --------------- 34 35 35 36 If you want some graphical indicators of system health look for applications 36 37 like: gkrellm, ksensors, xsensors, wmtemp, wmsensors, wmgtemp, ksysguardd,
+113
Documentation/hwmon/w83791d
··· 1 + Kernel driver w83791d 2 + ===================== 3 + 4 + Supported chips: 5 + * Winbond W83791D 6 + Prefix: 'w83791d' 7 + Addresses scanned: I2C 0x2c - 0x2f 8 + Datasheet: http://www.winbond-usa.com/products/winbond_products/pdfs/PCIC/W83791Da.pdf 9 + 10 + Author: Charles Spirakis <bezaur@gmail.com> 11 + 12 + This driver was derived from the w83781d.c and w83792d.c source files. 13 + 14 + Credits: 15 + w83781d.c: 16 + Frodo Looijaard <frodol@dds.nl>, 17 + Philip Edelbrock <phil@netroedge.com>, 18 + and Mark Studebaker <mdsxyz123@yahoo.com> 19 + w83792d.c: 20 + Chunhao Huang <DZShen@Winbond.com.tw>, 21 + Rudolf Marek <r.marek@sh.cvut.cz> 22 + 23 + Module Parameters 24 + ----------------- 25 + 26 + * init boolean 27 + (default 0) 28 + Use 'init=1' to have the driver do extra software initializations. 29 + The default behavior is to do the minimum initialization possible 30 + and depend on the BIOS to properly setup the chip. If you know you 31 + have a w83791d and you're having problems, try init=1 before trying 32 + reset=1. 33 + 34 + * reset boolean 35 + (default 0) 36 + Use 'reset=1' to reset the chip (via index 0x40, bit 7). The default 37 + behavior is no chip reset to preserve BIOS settings. 38 + 39 + * force_subclients=bus,caddr,saddr,saddr 40 + This is used to force the i2c addresses for subclients of 41 + a certain chip. Example usage is `force_subclients=0,0x2f,0x4a,0x4b' 42 + to force the subclients of chip 0x2f on bus 0 to i2c addresses 43 + 0x4a and 0x4b. 44 + 45 + 46 + Description 47 + ----------- 48 + 49 + This driver implements support for the Winbond W83791D chip. 50 + 51 + Detection of the chip can sometimes be foiled because it can be in an 52 + internal state that allows no clean access (Bank with ID register is not 53 + currently selected). If you know the address of the chip, use a 'force' 54 + parameter; this will put it into a more well-behaved state first. 55 + 56 + The driver implements three temperature sensors, five fan rotation speed 57 + sensors, and ten voltage sensors. 58 + 59 + Temperatures are measured in degrees Celsius and measurement resolution is 1 60 + degC for temp1 and 0.5 degC for temp2 and temp3. An alarm is triggered when 61 + the temperature gets higher than the Overtemperature Shutdown value; it stays 62 + on until the temperature falls below the Hysteresis value. 63 + 64 + Fan rotation speeds are reported in RPM (rotations per minute). An alarm is 65 + triggered if the rotation speed has dropped below a programmable limit. Fan 66 + readings can be divided by a programmable divider (1, 2, 4, 8 for fan 1/2/3 67 + and 1, 2, 4, 8, 16, 32, 64 or 128 for fan 4/5) to give the readings more 68 + range or accuracy. 69 + 70 + Voltage sensors (also known as IN sensors) report their values in millivolts. 71 + An alarm is triggered if the voltage has crossed a programmable minimum 72 + or maximum limit. 73 + 74 + Alarms are provided as output from a "realtime status register". The 75 + following bits are defined: 76 + 77 + bit - alarm on: 78 + 0 - Vcore 79 + 1 - VINR0 80 + 2 - +3.3VIN 81 + 3 - 5VDD 82 + 4 - temp1 83 + 5 - temp2 84 + 6 - fan1 85 + 7 - fan2 86 + 8 - +12VIN 87 + 9 - -12VIN 88 + 10 - -5VIN 89 + 11 - fan3 90 + 12 - chassis 91 + 13 - temp3 92 + 14 - VINR1 93 + 15 - reserved 94 + 16 - tart1 95 + 17 - tart2 96 + 18 - tart3 97 + 19 - VSB 98 + 20 - VBAT 99 + 21 - fan4 100 + 22 - fan5 101 + 23 - reserved 102 + 103 + When an alarm goes off, you can be warned by a beeping signal through your 104 + computer speaker. It is possible to enable all beeping globally, or only 105 + the beeping for some alarms. 106 + 107 + The driver only reads the chip values each 3 seconds; reading them more 108 + often will do no harm, but will return 'old' values. 109 + 110 + W83791D TODO: 111 + --------------- 112 + Provide a patch for per-file alarms as discussed on the mailing list 113 + Provide a patch for smart-fan control (still need appropriate motherboard/fans)
+1 -2
Documentation/i2c/busses/i2c-i801
··· 21 21 Module Parameters 22 22 ----------------- 23 23 24 - * force_addr: int 25 - Forcibly enable the ICH at the given address. EXTREMELY DANGEROUS! 24 + None. 26 25 27 26 28 27 Description
+2
Documentation/i2c/busses/i2c-nforce2
··· 7 7 * nForce3 250Gb MCP 10de:00E4 8 8 * nForce4 MCP 10de:0052 9 9 * nForce4 MCP-04 10de:0034 10 + * nForce4 MCP51 10de:0264 11 + * nForce4 MCP55 10de:0368 10 12 11 13 Datasheet: not publically available, but seems to be similar to the 12 14 AMD-8111 SMBus 2.0 adapter.
+51
Documentation/i2c/busses/i2c-ocores
··· 1 + Kernel driver i2c-ocores 2 + 3 + Supported adapters: 4 + * OpenCores.org I2C controller by Richard Herveille (see datasheet link) 5 + Datasheet: http://www.opencores.org/projects.cgi/web/i2c/overview 6 + 7 + Author: Peter Korsgaard <jacmet@sunsite.dk> 8 + 9 + Description 10 + ----------- 11 + 12 + i2c-ocores is an i2c bus driver for the OpenCores.org I2C controller 13 + IP core by Richard Herveille. 14 + 15 + Usage 16 + ----- 17 + 18 + i2c-ocores uses the platform bus, so you need to provide a struct 19 + platform_device with the base address and interrupt number. The 20 + dev.platform_data of the device should also point to a struct 21 + ocores_i2c_platform_data (see linux/i2c-ocores.h) describing the 22 + distance between registers and the input clock speed. 23 + 24 + E.G. something like: 25 + 26 + static struct resource ocores_resources[] = { 27 + [0] = { 28 + .start = MYI2C_BASEADDR, 29 + .end = MYI2C_BASEADDR + 8, 30 + .flags = IORESOURCE_MEM, 31 + }, 32 + [1] = { 33 + .start = MYI2C_IRQ, 34 + .end = MYI2C_IRQ, 35 + .flags = IORESOURCE_IRQ, 36 + }, 37 + }; 38 + 39 + static struct ocores_i2c_platform_data myi2c_data = { 40 + .regstep = 2, /* two bytes between registers */ 41 + .clock_khz = 50000, /* input clock of 50MHz */ 42 + }; 43 + 44 + static struct platform_device myi2c = { 45 + .name = "ocores-i2c", 46 + .dev = { 47 + .platform_data = &myi2c_data, 48 + }, 49 + .num_resources = ARRAY_SIZE(ocores_resources), 50 + .resource = ocores_resources, 51 + };
+33 -7
Documentation/i2c/busses/i2c-piix4
··· 6 6 Datasheet: Publicly available at the Intel website 7 7 * ServerWorks OSB4, CSB5, CSB6 and HT-1000 southbridges 8 8 Datasheet: Only available via NDA from ServerWorks 9 + * ATI IXP southbridges IXP200, IXP300, IXP400 10 + Datasheet: Not publicly available 9 11 * Standard Microsystems (SMSC) SLC90E66 (Victory66) southbridge 10 12 Datasheet: Publicly available at the SMSC website http://www.smsc.com 11 13 ··· 23 21 Forcibly enable the PIIX4. DANGEROUS! 24 22 * force_addr: int 25 23 Forcibly enable the PIIX4 at the given address. EXTREMELY DANGEROUS! 26 - * fix_hstcfg: int 27 - Fix config register. Needed on some boards (Force CPCI735). 28 24 29 25 30 26 Description ··· 63 63 The PIIX/PIIX3 does not implement an SMBus or I2C bus, so you can't use 64 64 this driver on those mainboards. 65 65 66 - The ServerWorks Southbridges, the Intel 440MX, and the Victory766 are 66 + The ServerWorks Southbridges, the Intel 440MX, and the Victory66 are 67 67 identical to the PIIX4 in I2C/SMBus support. 68 68 69 - A few OSB4 southbridges are known to be misconfigured by the BIOS. In this 70 - case, you have you use the fix_hstcfg module parameter. Do not use it 71 - unless you know you have to, because in some cases it also breaks 72 - configuration on southbridges that don't need it. 69 + If you own Force CPCI735 motherboard or other OSB4 based systems you may need 70 + to change the SMBus Interrupt Select register so the SMBus controller uses 71 + the SMI mode. 72 + 73 + 1) Use lspci command and locate the PCI device with the SMBus controller: 74 + 00:0f.0 ISA bridge: ServerWorks OSB4 South Bridge (rev 4f) 75 + The line may vary for different chipsets. Please consult the driver source 76 + for all possible PCI ids (and lspci -n to match them). Lets assume the 77 + device is located at 00:0f.0. 78 + 2) Now you just need to change the value in 0xD2 register. Get it first with 79 + command: lspci -xxx -s 00:0f.0 80 + If the value is 0x3 then you need to change it to 0x1 81 + setpci -s 00:0f.0 d2.b=1 82 + 83 + Please note that you don't need to do that in all cases, just when the SMBus is 84 + not working properly. 85 + 86 + 87 + Hardware-specific issues 88 + ------------------------ 89 + 90 + This driver will refuse to load on IBM systems with an Intel PIIX4 SMBus. 91 + Some of these machines have an RFID EEPROM (24RF08) connected to the SMBus, 92 + which can easily get corrupted due to a state machine bug. These are mostly 93 + Thinkpad laptops, but desktop systems may also be affected. We have no list 94 + of all affected systems, so the only safe solution was to prevent access to 95 + the SMBus on all IBM systems (detected using DMI data.) 96 + 97 + For additional information, read: 98 + http://www2.lm-sensors.nu/~lm78/cvs/lm_sensors2/README.thinkpad
+18 -1
Documentation/i2c/busses/scx200_acb
··· 2 2 3 3 Author: Christer Weinigel <wingel@nano-system.com> 4 4 5 + The driver supersedes the older, never merged driver named i2c-nscacb. 6 + 5 7 Module Parameters 6 8 ----------------- 7 9 8 - * base: int 10 + * base: up to 4 ints 9 11 Base addresses for the ACCESS.bus controllers on SCx200 and SC1100 devices 12 + 13 + By default the driver uses two base addresses 0x820 and 0x840. 14 + If you want only one base address, specify the second as 0 so as to 15 + override this default. 10 16 11 17 Description 12 18 ----------- 13 19 14 20 Enable the use of the ACCESS.bus controller on the Geode SCx200 and 15 21 SC1100 processors and the CS5535 and CS5536 Geode companion devices. 22 + 23 + Device-specific notes 24 + --------------------- 25 + 26 + The SC1100 WRAP boards are known to use base addresses 0x810 and 0x820. 27 + If the scx200_acb driver is built into the kernel, add the following 28 + parameter to your boot command line: 29 + scx200_acb.base=0x810,0x820 30 + If the scx200_acb driver is built as a module, add the following line to 31 + the file /etc/modprobe.conf instead: 32 + options scx200_acb base=0x810,0x820
+12 -12
MAINTAINERS
··· 181 181 L: linux-aio@kvack.org 182 182 S: Supported 183 183 184 + ABIT UGURU HARDWARE MONITOR DRIVER 185 + P: Hans de Goede 186 + M: j.w.r.degoede@hhs.nl 187 + L: lm-sensors@lm-sensors.org 188 + S: Maintained 189 + 184 190 ACENIC DRIVER 185 191 P: Jes Sorensen 186 192 M: jes@trained-monkey.org ··· 2063 2057 L: linux-fbdev-devel@lists.sourceforge.net 2064 2058 S: Maintained 2065 2059 2060 + OPENCORES I2C BUS DRIVER 2061 + P: Peter Korsgaard 2062 + M: jacmet@sunsite.dk 2063 + L: lm-sensors@lm-sensors.org 2064 + S: Maintained 2065 + 2066 2066 ORACLE CLUSTER FILESYSTEM 2 (OCFS2) 2067 2067 P: Mark Fasheh 2068 2068 M: mark.fasheh@oracle.com ··· 2539 2527 M: thomas@winischhofer.net 2540 2528 W: http://www.winischhofer.at/linuxsisusbvga.shtml 2541 2529 S: Maintained 2542 - 2543 - SMSC47M1 HARDWARE MONITOR DRIVER 2544 - P: Jean Delvare 2545 - M: khali@linux-fr.org 2546 - L: lm-sensors@lm-sensors.org 2547 - S: Odd Fixes 2548 2530 2549 2531 SMB FILESYSTEM 2550 2532 P: Urban Widmark ··· 3151 3145 L: wbsd-devel@list.drzeus.cx 3152 3146 W: http://projects.drzeus.cx/wbsd 3153 3147 S: Maintained 3154 - 3155 - W83L785TS HARDWARE MONITOR DRIVER 3156 - P: Jean Delvare 3157 - M: khali@linux-fr.org 3158 - L: lm-sensors@lm-sensors.org 3159 - S: Odd Fixes 3160 3148 3161 3149 WATCHDOG DEVICE DRIVERS 3162 3150 P: Wim Van Sebroeck
+61 -4
drivers/hwmon/Kconfig
··· 1 1 # 2 - # I2C Sensor chip drivers configuration 2 + # Hardware monitoring chip drivers configuration 3 3 # 4 4 5 5 menu "Hardware Monitoring support" ··· 16 16 should say Y here and also to the specific driver(s) for your 17 17 sensors chip(s) below. 18 18 19 + To find out which specific driver(s) you need, use the 20 + sensors-detect script from the lm_sensors package. Read 21 + <file:Documentation/hwmon/userspace-tools> for details. 22 + 19 23 This support can also be built as a module. If so, the module 20 24 will be called hwmon. 21 25 22 26 config HWMON_VID 23 27 tristate 24 28 default n 29 + 30 + config SENSORS_ABITUGURU 31 + tristate "Abit uGuru" 32 + depends on HWMON && EXPERIMENTAL 33 + help 34 + If you say yes here you get support for the Abit uGuru chips 35 + sensor part. The voltage and frequency control parts of the Abit 36 + uGuru are not supported. The Abit uGuru chip can be found on Abit 37 + uGuru featuring motherboards (most modern Abit motherboards). 38 + 39 + This driver can also be built as a module. If so, the module 40 + will be called abituguru. 25 41 26 42 config SENSORS_ADM1021 27 43 tristate "Analog Devices ADM1021 and compatibles" ··· 204 188 This driver can also be built as a module. If so, the module 205 189 will be called lm63. 206 190 191 + config SENSORS_LM70 192 + tristate "National Semiconductor LM70" 193 + depends on HWMON && SPI_MASTER && EXPERIMENTAL 194 + help 195 + If you say yes here you get support for the National Semiconductor 196 + LM70 digital temperature sensor chip. 197 + 198 + This driver can also be built as a module. If so, the module 199 + will be called lm70. 200 + 207 201 config SENSORS_LM75 208 202 tristate "National Semiconductor LM75 and compatibles" 209 203 depends on HWMON && I2C ··· 262 236 will be called lm80. 263 237 264 238 config SENSORS_LM83 265 - tristate "National Semiconductor LM83" 239 + tristate "National Semiconductor LM83 and compatibles" 266 240 depends on HWMON && I2C 267 241 help 268 242 If you say yes here you get support for National Semiconductor 269 - LM83 sensor chips. 243 + LM82 and LM83 sensor chips. 270 244 271 245 This driver can also be built as a module. If so, the module 272 246 will be called lm83. ··· 359 333 help 360 334 If you say yes here you get support for the integrated fan 361 335 monitoring and control capabilities of the SMSC LPC47B27x, 362 - LPC47M10x, LPC47M13x, LPC47M14x, LPC47M15x and LPC47M192 chips. 336 + LPC47M10x, LPC47M13x, LPC47M14x, LPC47M15x, LPC47M192 and 337 + LPC47M997 chips. 338 + 339 + The temperature and voltage sensor features of the LPC47M192 340 + and LPC47M997 are supported by another driver, select also 341 + "SMSC LPC47M192 and compatibles" below for those. 363 342 364 343 This driver can also be built as a module. If so, the module 365 344 will be called smsc47m1. 345 + 346 + config SENSORS_SMSC47M192 347 + tristate "SMSC LPC47M192 and compatibles" 348 + depends on HWMON && I2C && EXPERIMENTAL 349 + select HWMON_VID 350 + help 351 + If you say yes here you get support for the temperature and 352 + voltage sensors of the SMSC LPC47M192 and LPC47M997 chips. 353 + 354 + The fan monitoring and control capabilities of these chips 355 + are supported by another driver, select 356 + "SMSC LPC47M10x and compatibles" above. You need both drivers 357 + if you want fan control and voltage/temperature sensor support. 358 + 359 + This driver can also be built as a module. If so, the module 360 + will be called smsc47m192. 366 361 367 362 config SENSORS_SMSC47B397 368 363 tristate "SMSC LPC47B397-NC" ··· 431 384 432 385 This driver can also be built as a module. If so, the module 433 386 will be called w83781d. 387 + 388 + config SENSORS_W83791D 389 + tristate "Winbond W83791D" 390 + depends on HWMON && I2C && EXPERIMENTAL 391 + select HWMON_VID 392 + help 393 + If you say yes here you get support for the Winbond W83791D chip. 394 + 395 + This driver can also be built as a module. If so, the module 396 + will be called w83791d. 434 397 435 398 config SENSORS_W83792D 436 399 tristate "Winbond W83792D"
+4
drivers/hwmon/Makefile
··· 10 10 obj-$(CONFIG_SENSORS_W83627HF) += w83627hf.o 11 11 obj-$(CONFIG_SENSORS_W83792D) += w83792d.o 12 12 obj-$(CONFIG_SENSORS_W83781D) += w83781d.o 13 + obj-$(CONFIG_SENSORS_W83791D) += w83791d.o 13 14 15 + obj-$(CONFIG_SENSORS_ABITUGURU) += abituguru.o 14 16 obj-$(CONFIG_SENSORS_ADM1021) += adm1021.o 15 17 obj-$(CONFIG_SENSORS_ADM1025) += adm1025.o 16 18 obj-$(CONFIG_SENSORS_ADM1026) += adm1026.o ··· 28 26 obj-$(CONFIG_SENSORS_HDAPS) += hdaps.o 29 27 obj-$(CONFIG_SENSORS_IT87) += it87.o 30 28 obj-$(CONFIG_SENSORS_LM63) += lm63.o 29 + obj-$(CONFIG_SENSORS_LM70) += lm70.o 31 30 obj-$(CONFIG_SENSORS_LM75) += lm75.o 32 31 obj-$(CONFIG_SENSORS_LM77) += lm77.o 33 32 obj-$(CONFIG_SENSORS_LM78) += lm78.o ··· 43 40 obj-$(CONFIG_SENSORS_SIS5595) += sis5595.o 44 41 obj-$(CONFIG_SENSORS_SMSC47B397)+= smsc47b397.o 45 42 obj-$(CONFIG_SENSORS_SMSC47M1) += smsc47m1.o 43 + obj-$(CONFIG_SENSORS_SMSC47M192)+= smsc47m192.o 46 44 obj-$(CONFIG_SENSORS_VIA686A) += via686a.o 47 45 obj-$(CONFIG_SENSORS_VT8231) += vt8231.o 48 46 obj-$(CONFIG_SENSORS_W83627EHF) += w83627ehf.o
+1415
drivers/hwmon/abituguru.c
··· 1 + /* 2 + abituguru.c Copyright (c) 2005-2006 Hans de Goede <j.w.r.degoede@hhs.nl> 3 + 4 + This program is free software; you can redistribute it and/or modify 5 + it under the terms of the GNU General Public License as published by 6 + the Free Software Foundation; either version 2 of the License, or 7 + (at your option) any later version. 8 + 9 + This program is distributed in the hope that it will be useful, 10 + but WITHOUT ANY WARRANTY; without even the implied warranty of 11 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 + GNU General Public License for more details. 13 + 14 + You should have received a copy of the GNU General Public License 15 + along with this program; if not, write to the Free Software 16 + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 17 + */ 18 + /* 19 + This driver supports the sensor part of the custom Abit uGuru chip found 20 + on Abit uGuru motherboards. Note: because of lack of specs the CPU / RAM / 21 + etc voltage & frequency control is not supported! 22 + */ 23 + #include <linux/module.h> 24 + #include <linux/init.h> 25 + #include <linux/slab.h> 26 + #include <linux/jiffies.h> 27 + #include <linux/mutex.h> 28 + #include <linux/err.h> 29 + #include <linux/platform_device.h> 30 + #include <linux/hwmon.h> 31 + #include <linux/hwmon-sysfs.h> 32 + #include <asm/io.h> 33 + 34 + /* Banks */ 35 + #define ABIT_UGURU_ALARM_BANK 0x20 /* 1x 3 bytes */ 36 + #define ABIT_UGURU_SENSOR_BANK1 0x21 /* 16x volt and temp */ 37 + #define ABIT_UGURU_FAN_PWM 0x24 /* 3x 5 bytes */ 38 + #define ABIT_UGURU_SENSOR_BANK2 0x26 /* fans */ 39 + /* max nr of sensors in bank1, a bank1 sensor can be in, temp or nc */ 40 + #define ABIT_UGURU_MAX_BANK1_SENSORS 16 41 + /* Warning if you increase one of the 2 MAX defines below to 10 or higher you 42 + should adjust the belonging _NAMES_LENGTH macro for the 2 digit number! */ 43 + /* max nr of sensors in bank2, currently mb's with max 6 fans are known */ 44 + #define ABIT_UGURU_MAX_BANK2_SENSORS 6 45 + /* max nr of pwm outputs, currently mb's with max 5 pwm outputs are known */ 46 + #define ABIT_UGURU_MAX_PWMS 5 47 + /* uGuru sensor bank 1 flags */ /* Alarm if: */ 48 + #define ABIT_UGURU_TEMP_HIGH_ALARM_ENABLE 0x01 /* temp over warn */ 49 + #define ABIT_UGURU_VOLT_HIGH_ALARM_ENABLE 0x02 /* volt over max */ 50 + #define ABIT_UGURU_VOLT_LOW_ALARM_ENABLE 0x04 /* volt under min */ 51 + #define ABIT_UGURU_TEMP_HIGH_ALARM_FLAG 0x10 /* temp is over warn */ 52 + #define ABIT_UGURU_VOLT_HIGH_ALARM_FLAG 0x20 /* volt is over max */ 53 + #define ABIT_UGURU_VOLT_LOW_ALARM_FLAG 0x40 /* volt is under min */ 54 + /* uGuru sensor bank 2 flags */ /* Alarm if: */ 55 + #define ABIT_UGURU_FAN_LOW_ALARM_ENABLE 0x01 /* fan under min */ 56 + /* uGuru sensor bank common flags */ 57 + #define ABIT_UGURU_BEEP_ENABLE 0x08 /* beep if alarm */ 58 + #define ABIT_UGURU_SHUTDOWN_ENABLE 0x80 /* shutdown if alarm */ 59 + /* uGuru fan PWM (speed control) flags */ 60 + #define ABIT_UGURU_FAN_PWM_ENABLE 0x80 /* enable speed control */ 61 + /* Values used for conversion */ 62 + #define ABIT_UGURU_FAN_MAX 15300 /* RPM */ 63 + /* Bank1 sensor types */ 64 + #define ABIT_UGURU_IN_SENSOR 0 65 + #define ABIT_UGURU_TEMP_SENSOR 1 66 + #define ABIT_UGURU_NC 2 67 + /* Timeouts / Retries, if these turn out to need a lot of fiddling we could 68 + convert them to params. */ 69 + /* 250 was determined by trial and error, 200 works most of the time, but not 70 + always. I assume this is cpu-speed independent, since the ISA-bus and not 71 + the CPU should be the bottleneck. Note that 250 sometimes is still not 72 + enough (only reported on AN7 mb) this is handled by a higher layer. */ 73 + #define ABIT_UGURU_WAIT_TIMEOUT 250 74 + /* Normally all expected status in abituguru_ready, are reported after the 75 + first read, but sometimes not and we need to poll, 5 polls was not enough 76 + 50 sofar is. */ 77 + #define ABIT_UGURU_READY_TIMEOUT 50 78 + /* Maximum 3 retries on timedout reads/writes, delay 200 ms before retrying */ 79 + #define ABIT_UGURU_MAX_RETRIES 3 80 + #define ABIT_UGURU_RETRY_DELAY (HZ/5) 81 + /* Maximum 2 timeouts in abituguru_update_device, iow 3 in a row is an error */ 82 + #define ABIT_UGURU_MAX_TIMEOUTS 2 83 + /* utility macros */ 84 + #define ABIT_UGURU_NAME "abituguru" 85 + #define ABIT_UGURU_DEBUG(level, format, arg...) \ 86 + if (level <= verbose) \ 87 + printk(KERN_DEBUG ABIT_UGURU_NAME ": " format , ## arg) 88 + /* Macros to help calculate the sysfs_names array length */ 89 + /* sum of strlen of: in??_input\0, in??_{min,max}\0, in??_{min,max}_alarm\0, 90 + in??_{min,max}_alarm_enable\0, in??_beep\0, in??_shutdown\0 */ 91 + #define ABITUGURU_IN_NAMES_LENGTH (11 + 2 * 9 + 2 * 15 + 2 * 22 + 10 + 14) 92 + /* sum of strlen of: temp??_input\0, temp??_max\0, temp??_crit\0, 93 + temp??_alarm\0, temp??_alarm_enable\0, temp??_beep\0, temp??_shutdown\0 */ 94 + #define ABITUGURU_TEMP_NAMES_LENGTH (13 + 11 + 12 + 13 + 20 + 12 + 16) 95 + /* sum of strlen of: fan?_input\0, fan?_min\0, fan?_alarm\0, 96 + fan?_alarm_enable\0, fan?_beep\0, fan?_shutdown\0 */ 97 + #define ABITUGURU_FAN_NAMES_LENGTH (11 + 9 + 11 + 18 + 10 + 14) 98 + /* sum of strlen of: pwm?_enable\0, pwm?_auto_channels_temp\0, 99 + pwm?_auto_point{1,2}_pwm\0, pwm?_auto_point{1,2}_temp\0 */ 100 + #define ABITUGURU_PWM_NAMES_LENGTH (12 + 24 + 2 * 21 + 2 * 22) 101 + /* IN_NAMES_LENGTH > TEMP_NAMES_LENGTH so assume all bank1 sensors are in */ 102 + #define ABITUGURU_SYSFS_NAMES_LENGTH ( \ 103 + ABIT_UGURU_MAX_BANK1_SENSORS * ABITUGURU_IN_NAMES_LENGTH + \ 104 + ABIT_UGURU_MAX_BANK2_SENSORS * ABITUGURU_FAN_NAMES_LENGTH + \ 105 + ABIT_UGURU_MAX_PWMS * ABITUGURU_PWM_NAMES_LENGTH) 106 + 107 + /* All the macros below are named identical to the oguru and oguru2 programs 108 + reverse engineered by Olle Sandberg, hence the names might not be 100% 109 + logical. I could come up with better names, but I prefer keeping the names 110 + identical so that this driver can be compared with his work more easily. */ 111 + /* Two i/o-ports are used by uGuru */ 112 + #define ABIT_UGURU_BASE 0x00E0 113 + /* Used to tell uGuru what to read and to read the actual data */ 114 + #define ABIT_UGURU_CMD 0x00 115 + /* Mostly used to check if uGuru is busy */ 116 + #define ABIT_UGURU_DATA 0x04 117 + #define ABIT_UGURU_REGION_LENGTH 5 118 + /* uGuru status' */ 119 + #define ABIT_UGURU_STATUS_WRITE 0x00 /* Ready to be written */ 120 + #define ABIT_UGURU_STATUS_READ 0x01 /* Ready to be read */ 121 + #define ABIT_UGURU_STATUS_INPUT 0x08 /* More input */ 122 + #define ABIT_UGURU_STATUS_READY 0x09 /* Ready to be written */ 123 + 124 + /* Constants */ 125 + /* in (Volt) sensors go up to 3494 mV, temp to 255000 millidegrees Celsius */ 126 + static const int abituguru_bank1_max_value[2] = { 3494, 255000 }; 127 + /* Min / Max allowed values for sensor2 (fan) alarm threshold, these values 128 + correspond to 300-3000 RPM */ 129 + static const u8 abituguru_bank2_min_threshold = 5; 130 + static const u8 abituguru_bank2_max_threshold = 50; 131 + /* Register 0 is a bitfield, 1 and 2 are pwm settings (255 = 100%), 3 and 4 132 + are temperature trip points. */ 133 + static const int abituguru_pwm_settings_multiplier[5] = { 0, 1, 1, 1000, 1000 }; 134 + /* Min / Max allowed values for pwm_settings. Note: pwm1 (CPU fan) is a 135 + special case the minium allowed pwm% setting for this is 30% (77) on 136 + some MB's this special case is handled in the code! */ 137 + static const u8 abituguru_pwm_min[5] = { 0, 170, 170, 25, 25 }; 138 + static const u8 abituguru_pwm_max[5] = { 0, 255, 255, 75, 75 }; 139 + 140 + 141 + /* Insmod parameters */ 142 + static int force; 143 + module_param(force, bool, 0); 144 + MODULE_PARM_DESC(force, "Set to one to force detection."); 145 + static int fan_sensors; 146 + module_param(fan_sensors, int, 0); 147 + MODULE_PARM_DESC(fan_sensors, "Number of fan sensors on the uGuru " 148 + "(0 = autodetect)"); 149 + static int pwms; 150 + module_param(pwms, int, 0); 151 + MODULE_PARM_DESC(pwms, "Number of PWMs on the uGuru " 152 + "(0 = autodetect)"); 153 + 154 + /* Default verbose is 2, since this driver is still in the testing phase */ 155 + static int verbose = 2; 156 + module_param(verbose, int, 0644); 157 + MODULE_PARM_DESC(verbose, "How verbose should the driver be? (0-3):\n" 158 + " 0 normal output\n" 159 + " 1 + verbose error reporting\n" 160 + " 2 + sensors type probing info\n" 161 + " 3 + retryable error reporting"); 162 + 163 + 164 + /* For the Abit uGuru, we need to keep some data in memory. 165 + The structure is dynamically allocated, at the same time when a new 166 + abituguru device is allocated. */ 167 + struct abituguru_data { 168 + struct class_device *class_dev; /* hwmon registered device */ 169 + struct mutex update_lock; /* protect access to data and uGuru */ 170 + unsigned long last_updated; /* In jiffies */ 171 + unsigned short addr; /* uguru base address */ 172 + char uguru_ready; /* is the uguru in ready state? */ 173 + unsigned char update_timeouts; /* number of update timeouts since last 174 + successful update */ 175 + 176 + /* The sysfs attr and their names are generated automatically, for bank1 177 + we cannot use a predefined array because we don't know beforehand 178 + of a sensor is a volt or a temp sensor, for bank2 and the pwms its 179 + easier todo things the same way. For in sensors we have 9 (temp 7) 180 + sysfs entries per sensor, for bank2 and pwms 6. */ 181 + struct sensor_device_attribute_2 sysfs_attr[ 182 + ABIT_UGURU_MAX_BANK1_SENSORS * 9 + 183 + ABIT_UGURU_MAX_BANK2_SENSORS * 6 + ABIT_UGURU_MAX_PWMS * 6]; 184 + /* Buffer to store the dynamically generated sysfs names */ 185 + char sysfs_names[ABITUGURU_SYSFS_NAMES_LENGTH]; 186 + 187 + /* Bank 1 data */ 188 + /* number of and addresses of [0] in, [1] temp sensors */ 189 + u8 bank1_sensors[2]; 190 + u8 bank1_address[2][ABIT_UGURU_MAX_BANK1_SENSORS]; 191 + u8 bank1_value[ABIT_UGURU_MAX_BANK1_SENSORS]; 192 + /* This array holds 3 entries per sensor for the bank 1 sensor settings 193 + (flags, min, max for voltage / flags, warn, shutdown for temp). */ 194 + u8 bank1_settings[ABIT_UGURU_MAX_BANK1_SENSORS][3]; 195 + /* Maximum value for each sensor used for scaling in mV/millidegrees 196 + Celsius. */ 197 + int bank1_max_value[ABIT_UGURU_MAX_BANK1_SENSORS]; 198 + 199 + /* Bank 2 data, ABIT_UGURU_MAX_BANK2_SENSORS entries for bank2 */ 200 + u8 bank2_sensors; /* actual number of bank2 sensors found */ 201 + u8 bank2_value[ABIT_UGURU_MAX_BANK2_SENSORS]; 202 + u8 bank2_settings[ABIT_UGURU_MAX_BANK2_SENSORS][2]; /* flags, min */ 203 + 204 + /* Alarms 2 bytes for bank1, 1 byte for bank2 */ 205 + u8 alarms[3]; 206 + 207 + /* Fan PWM (speed control) 5 bytes per PWM */ 208 + u8 pwms; /* actual number of pwms found */ 209 + u8 pwm_settings[ABIT_UGURU_MAX_PWMS][5]; 210 + }; 211 + 212 + /* wait till the uguru is in the specified state */ 213 + static int abituguru_wait(struct abituguru_data *data, u8 state) 214 + { 215 + int timeout = ABIT_UGURU_WAIT_TIMEOUT; 216 + 217 + while (inb_p(data->addr + ABIT_UGURU_DATA) != state) { 218 + timeout--; 219 + if (timeout == 0) 220 + return -EBUSY; 221 + } 222 + return 0; 223 + } 224 + 225 + /* Put the uguru in ready for input state */ 226 + static int abituguru_ready(struct abituguru_data *data) 227 + { 228 + int timeout = ABIT_UGURU_READY_TIMEOUT; 229 + 230 + if (data->uguru_ready) 231 + return 0; 232 + 233 + /* Reset? / Prepare for next read/write cycle */ 234 + outb(0x00, data->addr + ABIT_UGURU_DATA); 235 + 236 + /* Wait till the uguru is ready */ 237 + if (abituguru_wait(data, ABIT_UGURU_STATUS_READY)) { 238 + ABIT_UGURU_DEBUG(1, 239 + "timeout exceeded waiting for ready state\n"); 240 + return -EIO; 241 + } 242 + 243 + /* Cmd port MUST be read now and should contain 0xAC */ 244 + while (inb_p(data->addr + ABIT_UGURU_CMD) != 0xAC) { 245 + timeout--; 246 + if (timeout == 0) { 247 + ABIT_UGURU_DEBUG(1, 248 + "CMD reg does not hold 0xAC after ready command\n"); 249 + return -EIO; 250 + } 251 + } 252 + 253 + /* After this the ABIT_UGURU_DATA port should contain 254 + ABIT_UGURU_STATUS_INPUT */ 255 + timeout = ABIT_UGURU_READY_TIMEOUT; 256 + while (inb_p(data->addr + ABIT_UGURU_DATA) != ABIT_UGURU_STATUS_INPUT) { 257 + timeout--; 258 + if (timeout == 0) { 259 + ABIT_UGURU_DEBUG(1, 260 + "state != more input after ready command\n"); 261 + return -EIO; 262 + } 263 + } 264 + 265 + data->uguru_ready = 1; 266 + return 0; 267 + } 268 + 269 + /* Send the bank and then sensor address to the uGuru for the next read/write 270 + cycle. This function gets called as the first part of a read/write by 271 + abituguru_read and abituguru_write. This function should never be 272 + called by any other function. */ 273 + static int abituguru_send_address(struct abituguru_data *data, 274 + u8 bank_addr, u8 sensor_addr, int retries) 275 + { 276 + /* assume the caller does error handling itself if it has not requested 277 + any retries, and thus be quiet. */ 278 + int report_errors = retries; 279 + 280 + for (;;) { 281 + /* Make sure the uguru is ready and then send the bank address, 282 + after this the uguru is no longer "ready". */ 283 + if (abituguru_ready(data) != 0) 284 + return -EIO; 285 + outb(bank_addr, data->addr + ABIT_UGURU_DATA); 286 + data->uguru_ready = 0; 287 + 288 + /* Wait till the uguru is ABIT_UGURU_STATUS_INPUT state again 289 + and send the sensor addr */ 290 + if (abituguru_wait(data, ABIT_UGURU_STATUS_INPUT)) { 291 + if (retries) { 292 + ABIT_UGURU_DEBUG(3, "timeout exceeded " 293 + "waiting for more input state, %d " 294 + "tries remaining\n", retries); 295 + set_current_state(TASK_UNINTERRUPTIBLE); 296 + schedule_timeout(ABIT_UGURU_RETRY_DELAY); 297 + retries--; 298 + continue; 299 + } 300 + if (report_errors) 301 + ABIT_UGURU_DEBUG(1, "timeout exceeded " 302 + "waiting for more input state " 303 + "(bank: %d)\n", (int)bank_addr); 304 + return -EBUSY; 305 + } 306 + outb(sensor_addr, data->addr + ABIT_UGURU_CMD); 307 + return 0; 308 + } 309 + } 310 + 311 + /* Read count bytes from sensor sensor_addr in bank bank_addr and store the 312 + result in buf, retry the send address part of the read retries times. */ 313 + static int abituguru_read(struct abituguru_data *data, 314 + u8 bank_addr, u8 sensor_addr, u8 *buf, int count, int retries) 315 + { 316 + int i; 317 + 318 + /* Send the address */ 319 + i = abituguru_send_address(data, bank_addr, sensor_addr, retries); 320 + if (i) 321 + return i; 322 + 323 + /* And read the data */ 324 + for (i = 0; i < count; i++) { 325 + if (abituguru_wait(data, ABIT_UGURU_STATUS_READ)) { 326 + ABIT_UGURU_DEBUG(1, "timeout exceeded waiting for " 327 + "read state (bank: %d, sensor: %d)\n", 328 + (int)bank_addr, (int)sensor_addr); 329 + break; 330 + } 331 + buf[i] = inb(data->addr + ABIT_UGURU_CMD); 332 + } 333 + 334 + /* Last put the chip back in ready state */ 335 + abituguru_ready(data); 336 + 337 + return i; 338 + } 339 + 340 + /* Write count bytes from buf to sensor sensor_addr in bank bank_addr, the send 341 + address part of the write is always retried ABIT_UGURU_MAX_RETRIES times. */ 342 + static int abituguru_write(struct abituguru_data *data, 343 + u8 bank_addr, u8 sensor_addr, u8 *buf, int count) 344 + { 345 + int i; 346 + 347 + /* Send the address */ 348 + i = abituguru_send_address(data, bank_addr, sensor_addr, 349 + ABIT_UGURU_MAX_RETRIES); 350 + if (i) 351 + return i; 352 + 353 + /* And write the data */ 354 + for (i = 0; i < count; i++) { 355 + if (abituguru_wait(data, ABIT_UGURU_STATUS_WRITE)) { 356 + ABIT_UGURU_DEBUG(1, "timeout exceeded waiting for " 357 + "write state (bank: %d, sensor: %d)\n", 358 + (int)bank_addr, (int)sensor_addr); 359 + break; 360 + } 361 + outb(buf[i], data->addr + ABIT_UGURU_CMD); 362 + } 363 + 364 + /* Now we need to wait till the chip is ready to be read again, 365 + don't ask why */ 366 + if (abituguru_wait(data, ABIT_UGURU_STATUS_READ)) { 367 + ABIT_UGURU_DEBUG(1, "timeout exceeded waiting for read state " 368 + "after write (bank: %d, sensor: %d)\n", (int)bank_addr, 369 + (int)sensor_addr); 370 + return -EIO; 371 + } 372 + 373 + /* Cmd port MUST be read now and should contain 0xAC */ 374 + if (inb_p(data->addr + ABIT_UGURU_CMD) != 0xAC) { 375 + ABIT_UGURU_DEBUG(1, "CMD reg does not hold 0xAC after write " 376 + "(bank: %d, sensor: %d)\n", (int)bank_addr, 377 + (int)sensor_addr); 378 + return -EIO; 379 + } 380 + 381 + /* Last put the chip back in ready state */ 382 + abituguru_ready(data); 383 + 384 + return i; 385 + } 386 + 387 + /* Detect sensor type. Temp and Volt sensors are enabled with 388 + different masks and will ignore enable masks not meant for them. 389 + This enables us to test what kind of sensor we're dealing with. 390 + By setting the alarm thresholds so that we will always get an 391 + alarm for sensor type X and then enabling the sensor as sensor type 392 + X, if we then get an alarm it is a sensor of type X. */ 393 + static int __devinit 394 + abituguru_detect_bank1_sensor_type(struct abituguru_data *data, 395 + u8 sensor_addr) 396 + { 397 + u8 val, buf[3]; 398 + int ret = ABIT_UGURU_NC; 399 + 400 + /* First read the sensor and the current settings */ 401 + if (abituguru_read(data, ABIT_UGURU_SENSOR_BANK1, sensor_addr, &val, 402 + 1, ABIT_UGURU_MAX_RETRIES) != 1) 403 + return -ENODEV; 404 + 405 + /* Test val is sane / usable for sensor type detection. */ 406 + if ((val < 10u) || (val > 240u)) { 407 + printk(KERN_WARNING ABIT_UGURU_NAME 408 + ": bank1-sensor: %d reading (%d) too close to limits, " 409 + "unable to determine sensor type, skipping sensor\n", 410 + (int)sensor_addr, (int)val); 411 + /* assume no sensor is there for sensors for which we can't 412 + determine the sensor type because their reading is too close 413 + to their limits, this usually means no sensor is there. */ 414 + return ABIT_UGURU_NC; 415 + } 416 + 417 + ABIT_UGURU_DEBUG(2, "testing bank1 sensor %d\n", (int)sensor_addr); 418 + /* Volt sensor test, enable volt low alarm, set min value ridicously 419 + high. If its a volt sensor this should always give us an alarm. */ 420 + buf[0] = ABIT_UGURU_VOLT_LOW_ALARM_ENABLE; 421 + buf[1] = 245; 422 + buf[2] = 250; 423 + if (abituguru_write(data, ABIT_UGURU_SENSOR_BANK1 + 2, sensor_addr, 424 + buf, 3) != 3) 425 + return -ENODEV; 426 + /* Now we need 20 ms to give the uguru time to read the sensors 427 + and raise a voltage alarm */ 428 + set_current_state(TASK_UNINTERRUPTIBLE); 429 + schedule_timeout(HZ/50); 430 + /* Check for alarm and check the alarm is a volt low alarm. */ 431 + if (abituguru_read(data, ABIT_UGURU_ALARM_BANK, 0, buf, 3, 432 + ABIT_UGURU_MAX_RETRIES) != 3) 433 + return -ENODEV; 434 + if (buf[sensor_addr/8] & (0x01 << (sensor_addr % 8))) { 435 + if (abituguru_read(data, ABIT_UGURU_SENSOR_BANK1 + 1, 436 + sensor_addr, buf, 3, 437 + ABIT_UGURU_MAX_RETRIES) != 3) 438 + return -ENODEV; 439 + if (buf[0] & ABIT_UGURU_VOLT_LOW_ALARM_FLAG) { 440 + /* Restore original settings */ 441 + if (abituguru_write(data, ABIT_UGURU_SENSOR_BANK1 + 2, 442 + sensor_addr, 443 + data->bank1_settings[sensor_addr], 444 + 3) != 3) 445 + return -ENODEV; 446 + ABIT_UGURU_DEBUG(2, " found volt sensor\n"); 447 + return ABIT_UGURU_IN_SENSOR; 448 + } else 449 + ABIT_UGURU_DEBUG(2, " alarm raised during volt " 450 + "sensor test, but volt low flag not set\n"); 451 + } else 452 + ABIT_UGURU_DEBUG(2, " alarm not raised during volt sensor " 453 + "test\n"); 454 + 455 + /* Temp sensor test, enable sensor as a temp sensor, set beep value 456 + ridicously low (but not too low, otherwise uguru ignores it). 457 + If its a temp sensor this should always give us an alarm. */ 458 + buf[0] = ABIT_UGURU_TEMP_HIGH_ALARM_ENABLE; 459 + buf[1] = 5; 460 + buf[2] = 10; 461 + if (abituguru_write(data, ABIT_UGURU_SENSOR_BANK1 + 2, sensor_addr, 462 + buf, 3) != 3) 463 + return -ENODEV; 464 + /* Now we need 50 ms to give the uguru time to read the sensors 465 + and raise a temp alarm */ 466 + set_current_state(TASK_UNINTERRUPTIBLE); 467 + schedule_timeout(HZ/20); 468 + /* Check for alarm and check the alarm is a temp high alarm. */ 469 + if (abituguru_read(data, ABIT_UGURU_ALARM_BANK, 0, buf, 3, 470 + ABIT_UGURU_MAX_RETRIES) != 3) 471 + return -ENODEV; 472 + if (buf[sensor_addr/8] & (0x01 << (sensor_addr % 8))) { 473 + if (abituguru_read(data, ABIT_UGURU_SENSOR_BANK1 + 1, 474 + sensor_addr, buf, 3, 475 + ABIT_UGURU_MAX_RETRIES) != 3) 476 + return -ENODEV; 477 + if (buf[0] & ABIT_UGURU_TEMP_HIGH_ALARM_FLAG) { 478 + ret = ABIT_UGURU_TEMP_SENSOR; 479 + ABIT_UGURU_DEBUG(2, " found temp sensor\n"); 480 + } else 481 + ABIT_UGURU_DEBUG(2, " alarm raised during temp " 482 + "sensor test, but temp high flag not set\n"); 483 + } else 484 + ABIT_UGURU_DEBUG(2, " alarm not raised during temp sensor " 485 + "test\n"); 486 + 487 + /* Restore original settings */ 488 + if (abituguru_write(data, ABIT_UGURU_SENSOR_BANK1 + 2, sensor_addr, 489 + data->bank1_settings[sensor_addr], 3) != 3) 490 + return -ENODEV; 491 + 492 + return ret; 493 + } 494 + 495 + /* These functions try to find out how many sensors there are in bank2 and how 496 + many pwms there are. The purpose of this is to make sure that we don't give 497 + the user the possibility to change settings for non-existent sensors / pwm. 498 + The uGuru will happily read / write whatever memory happens to be after the 499 + memory storing the PWM settings when reading/writing to a PWM which is not 500 + there. Notice even if we detect a PWM which doesn't exist we normally won't 501 + write to it, unless the user tries to change the settings. 502 + 503 + Although the uGuru allows reading (settings) from non existing bank2 504 + sensors, my version of the uGuru does seem to stop writing to them, the 505 + write function above aborts in this case with: 506 + "CMD reg does not hold 0xAC after write" 507 + 508 + Notice these 2 tests are non destructive iow read-only tests, otherwise 509 + they would defeat their purpose. Although for the bank2_sensors detection a 510 + read/write test would be feasible because of the reaction above, I've 511 + however opted to stay on the safe side. */ 512 + static void __devinit 513 + abituguru_detect_no_bank2_sensors(struct abituguru_data *data) 514 + { 515 + int i; 516 + 517 + if (fan_sensors) { 518 + data->bank2_sensors = fan_sensors; 519 + ABIT_UGURU_DEBUG(2, "assuming %d fan sensors because of " 520 + "\"fan_sensors\" module param\n", 521 + (int)data->bank2_sensors); 522 + return; 523 + } 524 + 525 + ABIT_UGURU_DEBUG(2, "detecting number of fan sensors\n"); 526 + for (i = 0; i < ABIT_UGURU_MAX_BANK2_SENSORS; i++) { 527 + /* 0x89 are the known used bits: 528 + -0x80 enable shutdown 529 + -0x08 enable beep 530 + -0x01 enable alarm 531 + All other bits should be 0, but on some motherboards 532 + 0x40 (bit 6) is also high for some of the fans?? */ 533 + if (data->bank2_settings[i][0] & ~0xC9) { 534 + ABIT_UGURU_DEBUG(2, " bank2 sensor %d does not seem " 535 + "to be a fan sensor: settings[0] = %02X\n", 536 + i, (unsigned int)data->bank2_settings[i][0]); 537 + break; 538 + } 539 + 540 + /* check if the threshold is within the allowed range */ 541 + if (data->bank2_settings[i][1] < 542 + abituguru_bank2_min_threshold) { 543 + ABIT_UGURU_DEBUG(2, " bank2 sensor %d does not seem " 544 + "to be a fan sensor: the threshold (%d) is " 545 + "below the minimum (%d)\n", i, 546 + (int)data->bank2_settings[i][1], 547 + (int)abituguru_bank2_min_threshold); 548 + break; 549 + } 550 + if (data->bank2_settings[i][1] > 551 + abituguru_bank2_max_threshold) { 552 + ABIT_UGURU_DEBUG(2, " bank2 sensor %d does not seem " 553 + "to be a fan sensor: the threshold (%d) is " 554 + "above the maximum (%d)\n", i, 555 + (int)data->bank2_settings[i][1], 556 + (int)abituguru_bank2_max_threshold); 557 + break; 558 + } 559 + } 560 + 561 + data->bank2_sensors = i; 562 + ABIT_UGURU_DEBUG(2, " found: %d fan sensors\n", 563 + (int)data->bank2_sensors); 564 + } 565 + 566 + static void __devinit 567 + abituguru_detect_no_pwms(struct abituguru_data *data) 568 + { 569 + int i, j; 570 + 571 + if (pwms) { 572 + data->pwms = pwms; 573 + ABIT_UGURU_DEBUG(2, "assuming %d PWM outputs because of " 574 + "\"pwms\" module param\n", (int)data->pwms); 575 + return; 576 + } 577 + 578 + ABIT_UGURU_DEBUG(2, "detecting number of PWM outputs\n"); 579 + for (i = 0; i < ABIT_UGURU_MAX_PWMS; i++) { 580 + /* 0x80 is the enable bit and the low 581 + nibble is which temp sensor to use, 582 + the other bits should be 0 */ 583 + if (data->pwm_settings[i][0] & ~0x8F) { 584 + ABIT_UGURU_DEBUG(2, " pwm channel %d does not seem " 585 + "to be a pwm channel: settings[0] = %02X\n", 586 + i, (unsigned int)data->pwm_settings[i][0]); 587 + break; 588 + } 589 + 590 + /* the low nibble must correspond to one of the temp sensors 591 + we've found */ 592 + for (j = 0; j < data->bank1_sensors[ABIT_UGURU_TEMP_SENSOR]; 593 + j++) { 594 + if (data->bank1_address[ABIT_UGURU_TEMP_SENSOR][j] == 595 + (data->pwm_settings[i][0] & 0x0F)) 596 + break; 597 + } 598 + if (j == data->bank1_sensors[ABIT_UGURU_TEMP_SENSOR]) { 599 + ABIT_UGURU_DEBUG(2, " pwm channel %d does not seem " 600 + "to be a pwm channel: %d is not a valid temp " 601 + "sensor address\n", i, 602 + data->pwm_settings[i][0] & 0x0F); 603 + break; 604 + } 605 + 606 + /* check if all other settings are within the allowed range */ 607 + for (j = 1; j < 5; j++) { 608 + u8 min; 609 + /* special case pwm1 min pwm% */ 610 + if ((i == 0) && ((j == 1) || (j == 2))) 611 + min = 77; 612 + else 613 + min = abituguru_pwm_min[j]; 614 + if (data->pwm_settings[i][j] < min) { 615 + ABIT_UGURU_DEBUG(2, " pwm channel %d does " 616 + "not seem to be a pwm channel: " 617 + "setting %d (%d) is below the minimum " 618 + "value (%d)\n", i, j, 619 + (int)data->pwm_settings[i][j], 620 + (int)min); 621 + goto abituguru_detect_no_pwms_exit; 622 + } 623 + if (data->pwm_settings[i][j] > abituguru_pwm_max[j]) { 624 + ABIT_UGURU_DEBUG(2, " pwm channel %d does " 625 + "not seem to be a pwm channel: " 626 + "setting %d (%d) is above the maximum " 627 + "value (%d)\n", i, j, 628 + (int)data->pwm_settings[i][j], 629 + (int)abituguru_pwm_max[j]); 630 + goto abituguru_detect_no_pwms_exit; 631 + } 632 + } 633 + 634 + /* check that min temp < max temp and min pwm < max pwm */ 635 + if (data->pwm_settings[i][1] >= data->pwm_settings[i][2]) { 636 + ABIT_UGURU_DEBUG(2, " pwm channel %d does not seem " 637 + "to be a pwm channel: min pwm (%d) >= " 638 + "max pwm (%d)\n", i, 639 + (int)data->pwm_settings[i][1], 640 + (int)data->pwm_settings[i][2]); 641 + break; 642 + } 643 + if (data->pwm_settings[i][3] >= data->pwm_settings[i][4]) { 644 + ABIT_UGURU_DEBUG(2, " pwm channel %d does not seem " 645 + "to be a pwm channel: min temp (%d) >= " 646 + "max temp (%d)\n", i, 647 + (int)data->pwm_settings[i][3], 648 + (int)data->pwm_settings[i][4]); 649 + break; 650 + } 651 + } 652 + 653 + abituguru_detect_no_pwms_exit: 654 + data->pwms = i; 655 + ABIT_UGURU_DEBUG(2, " found: %d PWM outputs\n", (int)data->pwms); 656 + } 657 + 658 + /* Following are the sysfs callback functions. These functions expect: 659 + sensor_device_attribute_2->index: sensor address/offset in the bank 660 + sensor_device_attribute_2->nr: register offset, bitmask or NA. */ 661 + static struct abituguru_data *abituguru_update_device(struct device *dev); 662 + 663 + static ssize_t show_bank1_value(struct device *dev, 664 + struct device_attribute *devattr, char *buf) 665 + { 666 + struct sensor_device_attribute_2 *attr = to_sensor_dev_attr_2(devattr); 667 + struct abituguru_data *data = abituguru_update_device(dev); 668 + if (!data) 669 + return -EIO; 670 + return sprintf(buf, "%d\n", (data->bank1_value[attr->index] * 671 + data->bank1_max_value[attr->index] + 128) / 255); 672 + } 673 + 674 + static ssize_t show_bank1_setting(struct device *dev, 675 + struct device_attribute *devattr, char *buf) 676 + { 677 + struct sensor_device_attribute_2 *attr = to_sensor_dev_attr_2(devattr); 678 + struct abituguru_data *data = dev_get_drvdata(dev); 679 + return sprintf(buf, "%d\n", 680 + (data->bank1_settings[attr->index][attr->nr] * 681 + data->bank1_max_value[attr->index] + 128) / 255); 682 + } 683 + 684 + static ssize_t show_bank2_value(struct device *dev, 685 + struct device_attribute *devattr, char *buf) 686 + { 687 + struct sensor_device_attribute_2 *attr = to_sensor_dev_attr_2(devattr); 688 + struct abituguru_data *data = abituguru_update_device(dev); 689 + if (!data) 690 + return -EIO; 691 + return sprintf(buf, "%d\n", (data->bank2_value[attr->index] * 692 + ABIT_UGURU_FAN_MAX + 128) / 255); 693 + } 694 + 695 + static ssize_t show_bank2_setting(struct device *dev, 696 + struct device_attribute *devattr, char *buf) 697 + { 698 + struct sensor_device_attribute_2 *attr = to_sensor_dev_attr_2(devattr); 699 + struct abituguru_data *data = dev_get_drvdata(dev); 700 + return sprintf(buf, "%d\n", 701 + (data->bank2_settings[attr->index][attr->nr] * 702 + ABIT_UGURU_FAN_MAX + 128) / 255); 703 + } 704 + 705 + static ssize_t store_bank1_setting(struct device *dev, struct device_attribute 706 + *devattr, const char *buf, size_t count) 707 + { 708 + struct sensor_device_attribute_2 *attr = to_sensor_dev_attr_2(devattr); 709 + struct abituguru_data *data = dev_get_drvdata(dev); 710 + u8 val = (simple_strtoul(buf, NULL, 10) * 255 + 711 + data->bank1_max_value[attr->index]/2) / 712 + data->bank1_max_value[attr->index]; 713 + ssize_t ret = count; 714 + 715 + mutex_lock(&data->update_lock); 716 + if (data->bank1_settings[attr->index][attr->nr] != val) { 717 + u8 orig_val = data->bank1_settings[attr->index][attr->nr]; 718 + data->bank1_settings[attr->index][attr->nr] = val; 719 + if (abituguru_write(data, ABIT_UGURU_SENSOR_BANK1 + 2, 720 + attr->index, data->bank1_settings[attr->index], 721 + 3) <= attr->nr) { 722 + data->bank1_settings[attr->index][attr->nr] = orig_val; 723 + ret = -EIO; 724 + } 725 + } 726 + mutex_unlock(&data->update_lock); 727 + return ret; 728 + } 729 + 730 + static ssize_t store_bank2_setting(struct device *dev, struct device_attribute 731 + *devattr, const char *buf, size_t count) 732 + { 733 + struct sensor_device_attribute_2 *attr = to_sensor_dev_attr_2(devattr); 734 + struct abituguru_data *data = dev_get_drvdata(dev); 735 + u8 val = (simple_strtoul(buf, NULL, 10)*255 + ABIT_UGURU_FAN_MAX/2) / 736 + ABIT_UGURU_FAN_MAX; 737 + ssize_t ret = count; 738 + 739 + /* this check can be done before taking the lock */ 740 + if ((val < abituguru_bank2_min_threshold) || 741 + (val > abituguru_bank2_max_threshold)) 742 + return -EINVAL; 743 + 744 + mutex_lock(&data->update_lock); 745 + if (data->bank2_settings[attr->index][attr->nr] != val) { 746 + u8 orig_val = data->bank2_settings[attr->index][attr->nr]; 747 + data->bank2_settings[attr->index][attr->nr] = val; 748 + if (abituguru_write(data, ABIT_UGURU_SENSOR_BANK2 + 2, 749 + attr->index, data->bank2_settings[attr->index], 750 + 2) <= attr->nr) { 751 + data->bank2_settings[attr->index][attr->nr] = orig_val; 752 + ret = -EIO; 753 + } 754 + } 755 + mutex_unlock(&data->update_lock); 756 + return ret; 757 + } 758 + 759 + static ssize_t show_bank1_alarm(struct device *dev, 760 + struct device_attribute *devattr, char *buf) 761 + { 762 + struct sensor_device_attribute_2 *attr = to_sensor_dev_attr_2(devattr); 763 + struct abituguru_data *data = abituguru_update_device(dev); 764 + if (!data) 765 + return -EIO; 766 + /* See if the alarm bit for this sensor is set, and if the 767 + alarm matches the type of alarm we're looking for (for volt 768 + it can be either low or high). The type is stored in a few 769 + readonly bits in the settings part of the relevant sensor. 770 + The bitmask of the type is passed to us in attr->nr. */ 771 + if ((data->alarms[attr->index / 8] & (0x01 << (attr->index % 8))) && 772 + (data->bank1_settings[attr->index][0] & attr->nr)) 773 + return sprintf(buf, "1\n"); 774 + else 775 + return sprintf(buf, "0\n"); 776 + } 777 + 778 + static ssize_t show_bank2_alarm(struct device *dev, 779 + struct device_attribute *devattr, char *buf) 780 + { 781 + struct sensor_device_attribute_2 *attr = to_sensor_dev_attr_2(devattr); 782 + struct abituguru_data *data = abituguru_update_device(dev); 783 + if (!data) 784 + return -EIO; 785 + if (data->alarms[2] & (0x01 << attr->index)) 786 + return sprintf(buf, "1\n"); 787 + else 788 + return sprintf(buf, "0\n"); 789 + } 790 + 791 + static ssize_t show_bank1_mask(struct device *dev, 792 + struct device_attribute *devattr, char *buf) 793 + { 794 + struct sensor_device_attribute_2 *attr = to_sensor_dev_attr_2(devattr); 795 + struct abituguru_data *data = dev_get_drvdata(dev); 796 + if (data->bank1_settings[attr->index][0] & attr->nr) 797 + return sprintf(buf, "1\n"); 798 + else 799 + return sprintf(buf, "0\n"); 800 + } 801 + 802 + static ssize_t show_bank2_mask(struct device *dev, 803 + struct device_attribute *devattr, char *buf) 804 + { 805 + struct sensor_device_attribute_2 *attr = to_sensor_dev_attr_2(devattr); 806 + struct abituguru_data *data = dev_get_drvdata(dev); 807 + if (data->bank2_settings[attr->index][0] & attr->nr) 808 + return sprintf(buf, "1\n"); 809 + else 810 + return sprintf(buf, "0\n"); 811 + } 812 + 813 + static ssize_t store_bank1_mask(struct device *dev, 814 + struct device_attribute *devattr, const char *buf, size_t count) 815 + { 816 + struct sensor_device_attribute_2 *attr = to_sensor_dev_attr_2(devattr); 817 + struct abituguru_data *data = dev_get_drvdata(dev); 818 + int mask = simple_strtoul(buf, NULL, 10); 819 + ssize_t ret = count; 820 + u8 orig_val; 821 + 822 + mutex_lock(&data->update_lock); 823 + orig_val = data->bank1_settings[attr->index][0]; 824 + 825 + if (mask) 826 + data->bank1_settings[attr->index][0] |= attr->nr; 827 + else 828 + data->bank1_settings[attr->index][0] &= ~attr->nr; 829 + 830 + if ((data->bank1_settings[attr->index][0] != orig_val) && 831 + (abituguru_write(data, 832 + ABIT_UGURU_SENSOR_BANK1 + 2, attr->index, 833 + data->bank1_settings[attr->index], 3) < 1)) { 834 + data->bank1_settings[attr->index][0] = orig_val; 835 + ret = -EIO; 836 + } 837 + mutex_unlock(&data->update_lock); 838 + return ret; 839 + } 840 + 841 + static ssize_t store_bank2_mask(struct device *dev, 842 + struct device_attribute *devattr, const char *buf, size_t count) 843 + { 844 + struct sensor_device_attribute_2 *attr = to_sensor_dev_attr_2(devattr); 845 + struct abituguru_data *data = dev_get_drvdata(dev); 846 + int mask = simple_strtoul(buf, NULL, 10); 847 + ssize_t ret = count; 848 + u8 orig_val; 849 + 850 + mutex_lock(&data->update_lock); 851 + orig_val = data->bank2_settings[attr->index][0]; 852 + 853 + if (mask) 854 + data->bank2_settings[attr->index][0] |= attr->nr; 855 + else 856 + data->bank2_settings[attr->index][0] &= ~attr->nr; 857 + 858 + if ((data->bank2_settings[attr->index][0] != orig_val) && 859 + (abituguru_write(data, 860 + ABIT_UGURU_SENSOR_BANK2 + 2, attr->index, 861 + data->bank2_settings[attr->index], 2) < 1)) { 862 + data->bank2_settings[attr->index][0] = orig_val; 863 + ret = -EIO; 864 + } 865 + mutex_unlock(&data->update_lock); 866 + return ret; 867 + } 868 + 869 + /* Fan PWM (speed control) */ 870 + static ssize_t show_pwm_setting(struct device *dev, 871 + struct device_attribute *devattr, char *buf) 872 + { 873 + struct sensor_device_attribute_2 *attr = to_sensor_dev_attr_2(devattr); 874 + struct abituguru_data *data = dev_get_drvdata(dev); 875 + return sprintf(buf, "%d\n", data->pwm_settings[attr->index][attr->nr] * 876 + abituguru_pwm_settings_multiplier[attr->nr]); 877 + } 878 + 879 + static ssize_t store_pwm_setting(struct device *dev, struct device_attribute 880 + *devattr, const char *buf, size_t count) 881 + { 882 + struct sensor_device_attribute_2 *attr = to_sensor_dev_attr_2(devattr); 883 + struct abituguru_data *data = dev_get_drvdata(dev); 884 + u8 min, val = (simple_strtoul(buf, NULL, 10) + 885 + abituguru_pwm_settings_multiplier[attr->nr]/2) / 886 + abituguru_pwm_settings_multiplier[attr->nr]; 887 + ssize_t ret = count; 888 + 889 + /* special case pwm1 min pwm% */ 890 + if ((attr->index == 0) && ((attr->nr == 1) || (attr->nr == 2))) 891 + min = 77; 892 + else 893 + min = abituguru_pwm_min[attr->nr]; 894 + 895 + /* this check can be done before taking the lock */ 896 + if ((val < min) || (val > abituguru_pwm_max[attr->nr])) 897 + return -EINVAL; 898 + 899 + mutex_lock(&data->update_lock); 900 + /* this check needs to be done after taking the lock */ 901 + if ((attr->nr & 1) && 902 + (val >= data->pwm_settings[attr->index][attr->nr + 1])) 903 + ret = -EINVAL; 904 + else if (!(attr->nr & 1) && 905 + (val <= data->pwm_settings[attr->index][attr->nr - 1])) 906 + ret = -EINVAL; 907 + else if (data->pwm_settings[attr->index][attr->nr] != val) { 908 + u8 orig_val = data->pwm_settings[attr->index][attr->nr]; 909 + data->pwm_settings[attr->index][attr->nr] = val; 910 + if (abituguru_write(data, ABIT_UGURU_FAN_PWM + 1, 911 + attr->index, data->pwm_settings[attr->index], 912 + 5) <= attr->nr) { 913 + data->pwm_settings[attr->index][attr->nr] = 914 + orig_val; 915 + ret = -EIO; 916 + } 917 + } 918 + mutex_unlock(&data->update_lock); 919 + return ret; 920 + } 921 + 922 + static ssize_t show_pwm_sensor(struct device *dev, 923 + struct device_attribute *devattr, char *buf) 924 + { 925 + struct sensor_device_attribute_2 *attr = to_sensor_dev_attr_2(devattr); 926 + struct abituguru_data *data = dev_get_drvdata(dev); 927 + int i; 928 + /* We need to walk to the temp sensor addresses to find what 929 + the userspace id of the configured temp sensor is. */ 930 + for (i = 0; i < data->bank1_sensors[ABIT_UGURU_TEMP_SENSOR]; i++) 931 + if (data->bank1_address[ABIT_UGURU_TEMP_SENSOR][i] == 932 + (data->pwm_settings[attr->index][0] & 0x0F)) 933 + return sprintf(buf, "%d\n", i+1); 934 + 935 + return -ENXIO; 936 + } 937 + 938 + static ssize_t store_pwm_sensor(struct device *dev, struct device_attribute 939 + *devattr, const char *buf, size_t count) 940 + { 941 + struct sensor_device_attribute_2 *attr = to_sensor_dev_attr_2(devattr); 942 + struct abituguru_data *data = dev_get_drvdata(dev); 943 + unsigned long val = simple_strtoul(buf, NULL, 10) - 1; 944 + ssize_t ret = count; 945 + 946 + mutex_lock(&data->update_lock); 947 + if (val < data->bank1_sensors[ABIT_UGURU_TEMP_SENSOR]) { 948 + u8 orig_val = data->pwm_settings[attr->index][0]; 949 + u8 address = data->bank1_address[ABIT_UGURU_TEMP_SENSOR][val]; 950 + data->pwm_settings[attr->index][0] &= 0xF0; 951 + data->pwm_settings[attr->index][0] |= address; 952 + if (data->pwm_settings[attr->index][0] != orig_val) { 953 + if (abituguru_write(data, ABIT_UGURU_FAN_PWM + 1, 954 + attr->index, 955 + data->pwm_settings[attr->index], 956 + 5) < 1) { 957 + data->pwm_settings[attr->index][0] = orig_val; 958 + ret = -EIO; 959 + } 960 + } 961 + } 962 + else 963 + ret = -EINVAL; 964 + mutex_unlock(&data->update_lock); 965 + return ret; 966 + } 967 + 968 + static ssize_t show_pwm_enable(struct device *dev, 969 + struct device_attribute *devattr, char *buf) 970 + { 971 + struct sensor_device_attribute_2 *attr = to_sensor_dev_attr_2(devattr); 972 + struct abituguru_data *data = dev_get_drvdata(dev); 973 + int res = 0; 974 + if (data->pwm_settings[attr->index][0] & ABIT_UGURU_FAN_PWM_ENABLE) 975 + res = 2; 976 + return sprintf(buf, "%d\n", res); 977 + } 978 + 979 + static ssize_t store_pwm_enable(struct device *dev, struct device_attribute 980 + *devattr, const char *buf, size_t count) 981 + { 982 + struct sensor_device_attribute_2 *attr = to_sensor_dev_attr_2(devattr); 983 + struct abituguru_data *data = dev_get_drvdata(dev); 984 + u8 orig_val, user_val = simple_strtoul(buf, NULL, 10); 985 + ssize_t ret = count; 986 + 987 + mutex_lock(&data->update_lock); 988 + orig_val = data->pwm_settings[attr->index][0]; 989 + switch (user_val) { 990 + case 0: 991 + data->pwm_settings[attr->index][0] &= 992 + ~ABIT_UGURU_FAN_PWM_ENABLE; 993 + break; 994 + case 2: 995 + data->pwm_settings[attr->index][0] |= 996 + ABIT_UGURU_FAN_PWM_ENABLE; 997 + break; 998 + default: 999 + ret = -EINVAL; 1000 + } 1001 + if ((data->pwm_settings[attr->index][0] != orig_val) && 1002 + (abituguru_write(data, ABIT_UGURU_FAN_PWM + 1, 1003 + attr->index, data->pwm_settings[attr->index], 1004 + 5) < 1)) { 1005 + data->pwm_settings[attr->index][0] = orig_val; 1006 + ret = -EIO; 1007 + } 1008 + mutex_unlock(&data->update_lock); 1009 + return ret; 1010 + } 1011 + 1012 + static ssize_t show_name(struct device *dev, 1013 + struct device_attribute *devattr, char *buf) 1014 + { 1015 + return sprintf(buf, "%s\n", ABIT_UGURU_NAME); 1016 + } 1017 + 1018 + /* Sysfs attr templates, the real entries are generated automatically. */ 1019 + static const 1020 + struct sensor_device_attribute_2 abituguru_sysfs_bank1_templ[2][9] = { 1021 + { 1022 + SENSOR_ATTR_2(in%d_input, 0444, show_bank1_value, NULL, 0, 0), 1023 + SENSOR_ATTR_2(in%d_min, 0644, show_bank1_setting, 1024 + store_bank1_setting, 1, 0), 1025 + SENSOR_ATTR_2(in%d_min_alarm, 0444, show_bank1_alarm, NULL, 1026 + ABIT_UGURU_VOLT_LOW_ALARM_FLAG, 0), 1027 + SENSOR_ATTR_2(in%d_max, 0644, show_bank1_setting, 1028 + store_bank1_setting, 2, 0), 1029 + SENSOR_ATTR_2(in%d_max_alarm, 0444, show_bank1_alarm, NULL, 1030 + ABIT_UGURU_VOLT_HIGH_ALARM_FLAG, 0), 1031 + SENSOR_ATTR_2(in%d_beep, 0644, show_bank1_mask, 1032 + store_bank1_mask, ABIT_UGURU_BEEP_ENABLE, 0), 1033 + SENSOR_ATTR_2(in%d_shutdown, 0644, show_bank1_mask, 1034 + store_bank1_mask, ABIT_UGURU_SHUTDOWN_ENABLE, 0), 1035 + SENSOR_ATTR_2(in%d_min_alarm_enable, 0644, show_bank1_mask, 1036 + store_bank1_mask, ABIT_UGURU_VOLT_LOW_ALARM_ENABLE, 0), 1037 + SENSOR_ATTR_2(in%d_max_alarm_enable, 0644, show_bank1_mask, 1038 + store_bank1_mask, ABIT_UGURU_VOLT_HIGH_ALARM_ENABLE, 0), 1039 + }, { 1040 + SENSOR_ATTR_2(temp%d_input, 0444, show_bank1_value, NULL, 0, 0), 1041 + SENSOR_ATTR_2(temp%d_alarm, 0444, show_bank1_alarm, NULL, 1042 + ABIT_UGURU_TEMP_HIGH_ALARM_FLAG, 0), 1043 + SENSOR_ATTR_2(temp%d_max, 0644, show_bank1_setting, 1044 + store_bank1_setting, 1, 0), 1045 + SENSOR_ATTR_2(temp%d_crit, 0644, show_bank1_setting, 1046 + store_bank1_setting, 2, 0), 1047 + SENSOR_ATTR_2(temp%d_beep, 0644, show_bank1_mask, 1048 + store_bank1_mask, ABIT_UGURU_BEEP_ENABLE, 0), 1049 + SENSOR_ATTR_2(temp%d_shutdown, 0644, show_bank1_mask, 1050 + store_bank1_mask, ABIT_UGURU_SHUTDOWN_ENABLE, 0), 1051 + SENSOR_ATTR_2(temp%d_alarm_enable, 0644, show_bank1_mask, 1052 + store_bank1_mask, ABIT_UGURU_TEMP_HIGH_ALARM_ENABLE, 0), 1053 + } 1054 + }; 1055 + 1056 + static const struct sensor_device_attribute_2 abituguru_sysfs_fan_templ[6] = { 1057 + SENSOR_ATTR_2(fan%d_input, 0444, show_bank2_value, NULL, 0, 0), 1058 + SENSOR_ATTR_2(fan%d_alarm, 0444, show_bank2_alarm, NULL, 0, 0), 1059 + SENSOR_ATTR_2(fan%d_min, 0644, show_bank2_setting, 1060 + store_bank2_setting, 1, 0), 1061 + SENSOR_ATTR_2(fan%d_beep, 0644, show_bank2_mask, 1062 + store_bank2_mask, ABIT_UGURU_BEEP_ENABLE, 0), 1063 + SENSOR_ATTR_2(fan%d_shutdown, 0644, show_bank2_mask, 1064 + store_bank2_mask, ABIT_UGURU_SHUTDOWN_ENABLE, 0), 1065 + SENSOR_ATTR_2(fan%d_alarm_enable, 0644, show_bank2_mask, 1066 + store_bank2_mask, ABIT_UGURU_FAN_LOW_ALARM_ENABLE, 0), 1067 + }; 1068 + 1069 + static const struct sensor_device_attribute_2 abituguru_sysfs_pwm_templ[6] = { 1070 + SENSOR_ATTR_2(pwm%d_enable, 0644, show_pwm_enable, 1071 + store_pwm_enable, 0, 0), 1072 + SENSOR_ATTR_2(pwm%d_auto_channels_temp, 0644, show_pwm_sensor, 1073 + store_pwm_sensor, 0, 0), 1074 + SENSOR_ATTR_2(pwm%d_auto_point1_pwm, 0644, show_pwm_setting, 1075 + store_pwm_setting, 1, 0), 1076 + SENSOR_ATTR_2(pwm%d_auto_point2_pwm, 0644, show_pwm_setting, 1077 + store_pwm_setting, 2, 0), 1078 + SENSOR_ATTR_2(pwm%d_auto_point1_temp, 0644, show_pwm_setting, 1079 + store_pwm_setting, 3, 0), 1080 + SENSOR_ATTR_2(pwm%d_auto_point2_temp, 0644, show_pwm_setting, 1081 + store_pwm_setting, 4, 0), 1082 + }; 1083 + 1084 + static struct sensor_device_attribute_2 abituguru_sysfs_attr[] = { 1085 + SENSOR_ATTR_2(name, 0444, show_name, NULL, 0, 0), 1086 + }; 1087 + 1088 + static int __devinit abituguru_probe(struct platform_device *pdev) 1089 + { 1090 + struct abituguru_data *data; 1091 + int i, j, used, sysfs_names_free, sysfs_attr_i, res = -ENODEV; 1092 + char *sysfs_filename; 1093 + 1094 + /* El weirdo probe order, to keep the sysfs order identical to the 1095 + BIOS and window-appliction listing order. */ 1096 + const u8 probe_order[ABIT_UGURU_MAX_BANK1_SENSORS] = { 1097 + 0x00, 0x01, 0x03, 0x04, 0x0A, 0x08, 0x0E, 0x02, 1098 + 0x09, 0x06, 0x05, 0x0B, 0x0F, 0x0D, 0x07, 0x0C }; 1099 + 1100 + if (!(data = kzalloc(sizeof(struct abituguru_data), GFP_KERNEL))) 1101 + return -ENOMEM; 1102 + 1103 + data->addr = platform_get_resource(pdev, IORESOURCE_IO, 0)->start; 1104 + mutex_init(&data->update_lock); 1105 + platform_set_drvdata(pdev, data); 1106 + 1107 + /* See if the uGuru is ready */ 1108 + if (inb_p(data->addr + ABIT_UGURU_DATA) == ABIT_UGURU_STATUS_INPUT) 1109 + data->uguru_ready = 1; 1110 + 1111 + /* Completely read the uGuru this has 2 purposes: 1112 + - testread / see if one really is there. 1113 + - make an in memory copy of all the uguru settings for future use. */ 1114 + if (abituguru_read(data, ABIT_UGURU_ALARM_BANK, 0, 1115 + data->alarms, 3, ABIT_UGURU_MAX_RETRIES) != 3) 1116 + goto abituguru_probe_error; 1117 + 1118 + for (i = 0; i < ABIT_UGURU_MAX_BANK1_SENSORS; i++) { 1119 + if (abituguru_read(data, ABIT_UGURU_SENSOR_BANK1, i, 1120 + &data->bank1_value[i], 1, 1121 + ABIT_UGURU_MAX_RETRIES) != 1) 1122 + goto abituguru_probe_error; 1123 + if (abituguru_read(data, ABIT_UGURU_SENSOR_BANK1+1, i, 1124 + data->bank1_settings[i], 3, 1125 + ABIT_UGURU_MAX_RETRIES) != 3) 1126 + goto abituguru_probe_error; 1127 + } 1128 + /* Note: We don't know how many bank2 sensors / pwms there really are, 1129 + but in order to "detect" this we need to read the maximum amount 1130 + anyways. If we read sensors/pwms not there we'll just read crap 1131 + this can't hurt. We need the detection because we don't want 1132 + unwanted writes, which will hurt! */ 1133 + for (i = 0; i < ABIT_UGURU_MAX_BANK2_SENSORS; i++) { 1134 + if (abituguru_read(data, ABIT_UGURU_SENSOR_BANK2, i, 1135 + &data->bank2_value[i], 1, 1136 + ABIT_UGURU_MAX_RETRIES) != 1) 1137 + goto abituguru_probe_error; 1138 + if (abituguru_read(data, ABIT_UGURU_SENSOR_BANK2+1, i, 1139 + data->bank2_settings[i], 2, 1140 + ABIT_UGURU_MAX_RETRIES) != 2) 1141 + goto abituguru_probe_error; 1142 + } 1143 + for (i = 0; i < ABIT_UGURU_MAX_PWMS; i++) { 1144 + if (abituguru_read(data, ABIT_UGURU_FAN_PWM, i, 1145 + data->pwm_settings[i], 5, 1146 + ABIT_UGURU_MAX_RETRIES) != 5) 1147 + goto abituguru_probe_error; 1148 + } 1149 + data->last_updated = jiffies; 1150 + 1151 + /* Detect sensor types and fill the sysfs attr for bank1 */ 1152 + sysfs_attr_i = 0; 1153 + sysfs_filename = data->sysfs_names; 1154 + sysfs_names_free = ABITUGURU_SYSFS_NAMES_LENGTH; 1155 + for (i = 0; i < ABIT_UGURU_MAX_BANK1_SENSORS; i++) { 1156 + res = abituguru_detect_bank1_sensor_type(data, probe_order[i]); 1157 + if (res < 0) 1158 + goto abituguru_probe_error; 1159 + if (res == ABIT_UGURU_NC) 1160 + continue; 1161 + 1162 + /* res 1 (temp) sensors have 7 sysfs entries, 0 (in) 9 */ 1163 + for (j = 0; j < (res ? 7 : 9); j++) { 1164 + used = snprintf(sysfs_filename, sysfs_names_free, 1165 + abituguru_sysfs_bank1_templ[res][j].dev_attr. 1166 + attr.name, data->bank1_sensors[res] + res) 1167 + + 1; 1168 + data->sysfs_attr[sysfs_attr_i] = 1169 + abituguru_sysfs_bank1_templ[res][j]; 1170 + data->sysfs_attr[sysfs_attr_i].dev_attr.attr.name = 1171 + sysfs_filename; 1172 + data->sysfs_attr[sysfs_attr_i].index = probe_order[i]; 1173 + sysfs_filename += used; 1174 + sysfs_names_free -= used; 1175 + sysfs_attr_i++; 1176 + } 1177 + data->bank1_max_value[probe_order[i]] = 1178 + abituguru_bank1_max_value[res]; 1179 + data->bank1_address[res][data->bank1_sensors[res]] = 1180 + probe_order[i]; 1181 + data->bank1_sensors[res]++; 1182 + } 1183 + /* Detect number of sensors and fill the sysfs attr for bank2 (fans) */ 1184 + abituguru_detect_no_bank2_sensors(data); 1185 + for (i = 0; i < data->bank2_sensors; i++) { 1186 + for (j = 0; j < ARRAY_SIZE(abituguru_sysfs_fan_templ); j++) { 1187 + used = snprintf(sysfs_filename, sysfs_names_free, 1188 + abituguru_sysfs_fan_templ[j].dev_attr.attr.name, 1189 + i + 1) + 1; 1190 + data->sysfs_attr[sysfs_attr_i] = 1191 + abituguru_sysfs_fan_templ[j]; 1192 + data->sysfs_attr[sysfs_attr_i].dev_attr.attr.name = 1193 + sysfs_filename; 1194 + data->sysfs_attr[sysfs_attr_i].index = i; 1195 + sysfs_filename += used; 1196 + sysfs_names_free -= used; 1197 + sysfs_attr_i++; 1198 + } 1199 + } 1200 + /* Detect number of sensors and fill the sysfs attr for pwms */ 1201 + abituguru_detect_no_pwms(data); 1202 + for (i = 0; i < data->pwms; i++) { 1203 + for (j = 0; j < ARRAY_SIZE(abituguru_sysfs_pwm_templ); j++) { 1204 + used = snprintf(sysfs_filename, sysfs_names_free, 1205 + abituguru_sysfs_pwm_templ[j].dev_attr.attr.name, 1206 + i + 1) + 1; 1207 + data->sysfs_attr[sysfs_attr_i] = 1208 + abituguru_sysfs_pwm_templ[j]; 1209 + data->sysfs_attr[sysfs_attr_i].dev_attr.attr.name = 1210 + sysfs_filename; 1211 + data->sysfs_attr[sysfs_attr_i].index = i; 1212 + sysfs_filename += used; 1213 + sysfs_names_free -= used; 1214 + sysfs_attr_i++; 1215 + } 1216 + } 1217 + /* Fail safe check, this should never happen! */ 1218 + if (sysfs_names_free < 0) { 1219 + printk(KERN_ERR ABIT_UGURU_NAME ": Fatal error ran out of " 1220 + "space for sysfs attr names. This should never " 1221 + "happen please report to the abituguru maintainer " 1222 + "(see MAINTAINERS)\n"); 1223 + res = -ENAMETOOLONG; 1224 + goto abituguru_probe_error; 1225 + } 1226 + printk(KERN_INFO ABIT_UGURU_NAME ": found Abit uGuru\n"); 1227 + 1228 + /* Register sysfs hooks */ 1229 + data->class_dev = hwmon_device_register(&pdev->dev); 1230 + if (IS_ERR(data->class_dev)) { 1231 + res = PTR_ERR(data->class_dev); 1232 + goto abituguru_probe_error; 1233 + } 1234 + for (i = 0; i < sysfs_attr_i; i++) 1235 + device_create_file(&pdev->dev, &data->sysfs_attr[i].dev_attr); 1236 + for (i = 0; i < ARRAY_SIZE(abituguru_sysfs_attr); i++) 1237 + device_create_file(&pdev->dev, 1238 + &abituguru_sysfs_attr[i].dev_attr); 1239 + 1240 + return 0; 1241 + 1242 + abituguru_probe_error: 1243 + kfree(data); 1244 + return res; 1245 + } 1246 + 1247 + static int __devexit abituguru_remove(struct platform_device *pdev) 1248 + { 1249 + struct abituguru_data *data = platform_get_drvdata(pdev); 1250 + 1251 + platform_set_drvdata(pdev, NULL); 1252 + hwmon_device_unregister(data->class_dev); 1253 + kfree(data); 1254 + 1255 + return 0; 1256 + } 1257 + 1258 + static struct abituguru_data *abituguru_update_device(struct device *dev) 1259 + { 1260 + int i, err; 1261 + struct abituguru_data *data = dev_get_drvdata(dev); 1262 + /* fake a complete successful read if no update necessary. */ 1263 + char success = 1; 1264 + 1265 + mutex_lock(&data->update_lock); 1266 + if (time_after(jiffies, data->last_updated + HZ)) { 1267 + success = 0; 1268 + if ((err = abituguru_read(data, ABIT_UGURU_ALARM_BANK, 0, 1269 + data->alarms, 3, 0)) != 3) 1270 + goto LEAVE_UPDATE; 1271 + for (i = 0; i < ABIT_UGURU_MAX_BANK1_SENSORS; i++) { 1272 + if ((err = abituguru_read(data, 1273 + ABIT_UGURU_SENSOR_BANK1, i, 1274 + &data->bank1_value[i], 1, 0)) != 1) 1275 + goto LEAVE_UPDATE; 1276 + if ((err = abituguru_read(data, 1277 + ABIT_UGURU_SENSOR_BANK1 + 1, i, 1278 + data->bank1_settings[i], 3, 0)) != 3) 1279 + goto LEAVE_UPDATE; 1280 + } 1281 + for (i = 0; i < data->bank2_sensors; i++) 1282 + if ((err = abituguru_read(data, 1283 + ABIT_UGURU_SENSOR_BANK2, i, 1284 + &data->bank2_value[i], 1, 0)) != 1) 1285 + goto LEAVE_UPDATE; 1286 + /* success! */ 1287 + success = 1; 1288 + data->update_timeouts = 0; 1289 + LEAVE_UPDATE: 1290 + /* handle timeout condition */ 1291 + if (err == -EBUSY) { 1292 + /* No overflow please */ 1293 + if (data->update_timeouts < 255u) 1294 + data->update_timeouts++; 1295 + if (data->update_timeouts <= ABIT_UGURU_MAX_TIMEOUTS) { 1296 + ABIT_UGURU_DEBUG(3, "timeout exceeded, will " 1297 + "try again next update\n"); 1298 + /* Just a timeout, fake a successful read */ 1299 + success = 1; 1300 + } else 1301 + ABIT_UGURU_DEBUG(1, "timeout exceeded %d " 1302 + "times waiting for more input state\n", 1303 + (int)data->update_timeouts); 1304 + } 1305 + /* On success set last_updated */ 1306 + if (success) 1307 + data->last_updated = jiffies; 1308 + } 1309 + mutex_unlock(&data->update_lock); 1310 + 1311 + if (success) 1312 + return data; 1313 + else 1314 + return NULL; 1315 + } 1316 + 1317 + static struct platform_driver abituguru_driver = { 1318 + .driver = { 1319 + .owner = THIS_MODULE, 1320 + .name = ABIT_UGURU_NAME, 1321 + }, 1322 + .probe = abituguru_probe, 1323 + .remove = __devexit_p(abituguru_remove), 1324 + }; 1325 + 1326 + static int __init abituguru_detect(void) 1327 + { 1328 + /* See if there is an uguru there. After a reboot uGuru will hold 0x00 1329 + at DATA and 0xAC, when this driver has already been loaded once 1330 + DATA will hold 0x08. For most uGuru's CMD will hold 0xAC in either 1331 + scenario but some will hold 0x00. 1332 + Some uGuru's initally hold 0x09 at DATA and will only hold 0x08 1333 + after reading CMD first, so CMD must be read first! */ 1334 + u8 cmd_val = inb_p(ABIT_UGURU_BASE + ABIT_UGURU_CMD); 1335 + u8 data_val = inb_p(ABIT_UGURU_BASE + ABIT_UGURU_DATA); 1336 + if (((data_val == 0x00) || (data_val == 0x08)) && 1337 + ((cmd_val == 0x00) || (cmd_val == 0xAC))) 1338 + return ABIT_UGURU_BASE; 1339 + 1340 + ABIT_UGURU_DEBUG(2, "no Abit uGuru found, data = 0x%02X, cmd = " 1341 + "0x%02X\n", (unsigned int)data_val, (unsigned int)cmd_val); 1342 + 1343 + if (force) { 1344 + printk(KERN_INFO ABIT_UGURU_NAME ": Assuming Abit uGuru is " 1345 + "present because of \"force\" parameter\n"); 1346 + return ABIT_UGURU_BASE; 1347 + } 1348 + 1349 + /* No uGuru found */ 1350 + return -ENODEV; 1351 + } 1352 + 1353 + static struct platform_device *abituguru_pdev; 1354 + 1355 + static int __init abituguru_init(void) 1356 + { 1357 + int address, err; 1358 + struct resource res = { .flags = IORESOURCE_IO }; 1359 + 1360 + address = abituguru_detect(); 1361 + if (address < 0) 1362 + return address; 1363 + 1364 + err = platform_driver_register(&abituguru_driver); 1365 + if (err) 1366 + goto exit; 1367 + 1368 + abituguru_pdev = platform_device_alloc(ABIT_UGURU_NAME, address); 1369 + if (!abituguru_pdev) { 1370 + printk(KERN_ERR ABIT_UGURU_NAME 1371 + ": Device allocation failed\n"); 1372 + err = -ENOMEM; 1373 + goto exit_driver_unregister; 1374 + } 1375 + 1376 + res.start = address; 1377 + res.end = address + ABIT_UGURU_REGION_LENGTH - 1; 1378 + res.name = ABIT_UGURU_NAME; 1379 + 1380 + err = platform_device_add_resources(abituguru_pdev, &res, 1); 1381 + if (err) { 1382 + printk(KERN_ERR ABIT_UGURU_NAME 1383 + ": Device resource addition failed (%d)\n", err); 1384 + goto exit_device_put; 1385 + } 1386 + 1387 + err = platform_device_add(abituguru_pdev); 1388 + if (err) { 1389 + printk(KERN_ERR ABIT_UGURU_NAME 1390 + ": Device addition failed (%d)\n", err); 1391 + goto exit_device_put; 1392 + } 1393 + 1394 + return 0; 1395 + 1396 + exit_device_put: 1397 + platform_device_put(abituguru_pdev); 1398 + exit_driver_unregister: 1399 + platform_driver_unregister(&abituguru_driver); 1400 + exit: 1401 + return err; 1402 + } 1403 + 1404 + static void __exit abituguru_exit(void) 1405 + { 1406 + platform_device_unregister(abituguru_pdev); 1407 + platform_driver_unregister(&abituguru_driver); 1408 + } 1409 + 1410 + MODULE_AUTHOR("Hans de Goede <j.w.r.degoede@hhs.nl>"); 1411 + MODULE_DESCRIPTION("Abit uGuru Sensor device"); 1412 + MODULE_LICENSE("GPL"); 1413 + 1414 + module_init(abituguru_init); 1415 + module_exit(abituguru_exit);
+7 -8
drivers/hwmon/f71805f.c
··· 99 99 #define ADDR_REG_OFFSET 0 100 100 #define DATA_REG_OFFSET 1 101 101 102 - static struct resource f71805f_resource __initdata = { 103 - .flags = IORESOURCE_IO, 104 - }; 105 - 106 102 /* 107 103 * Registers 108 104 */ ··· 778 782 779 783 static int __init f71805f_device_add(unsigned short address) 780 784 { 785 + struct resource res = { 786 + .start = address, 787 + .end = address + REGION_LENGTH - 1, 788 + .flags = IORESOURCE_IO, 789 + }; 781 790 int err; 782 791 783 792 pdev = platform_device_alloc(DRVNAME, address); ··· 792 791 goto exit; 793 792 } 794 793 795 - f71805f_resource.start = address; 796 - f71805f_resource.end = address + REGION_LENGTH - 1; 797 - f71805f_resource.name = pdev->name; 798 - err = platform_device_add_resources(pdev, &f71805f_resource, 1); 794 + res.name = pdev->name; 795 + err = platform_device_add_resources(pdev, &res, 1); 799 796 if (err) { 800 797 printk(KERN_ERR DRVNAME ": Device resource addition failed " 801 798 "(%d)\n", err);
+5 -3
drivers/hwmon/hdaps.c
··· 41 41 #define HDAPS_PORT_STATE 0x1611 /* device state */ 42 42 #define HDAPS_PORT_YPOS 0x1612 /* y-axis position */ 43 43 #define HDAPS_PORT_XPOS 0x1614 /* x-axis position */ 44 - #define HDAPS_PORT_TEMP1 0x1616 /* device temperature, in celcius */ 44 + #define HDAPS_PORT_TEMP1 0x1616 /* device temperature, in Celsius */ 45 45 #define HDAPS_PORT_YVAR 0x1617 /* y-axis variance (what is this?) */ 46 46 #define HDAPS_PORT_XVAR 0x1619 /* x-axis variance (what is this?) */ 47 47 #define HDAPS_PORT_TEMP2 0x161b /* device temperature (again?) */ ··· 522 522 { 523 523 int ret; 524 524 525 - /* Note that DMI_MATCH(...,"ThinkPad T42") will match "ThinkPad T42p" */ 525 + /* Note that HDAPS_DMI_MATCH_NORMAL("ThinkPad T42") would match 526 + "ThinkPad T42p", so the order of the entries matters */ 526 527 struct dmi_system_id hdaps_whitelist[] = { 527 528 HDAPS_DMI_MATCH_NORMAL("ThinkPad H"), 528 529 HDAPS_DMI_MATCH_INVERT("ThinkPad R50p"), 529 530 HDAPS_DMI_MATCH_NORMAL("ThinkPad R50"), 530 531 HDAPS_DMI_MATCH_NORMAL("ThinkPad R51"), 531 532 HDAPS_DMI_MATCH_NORMAL("ThinkPad R52"), 533 + HDAPS_DMI_MATCH_NORMAL("ThinkPad H"), /* R52 (1846AQG) */ 532 534 HDAPS_DMI_MATCH_INVERT("ThinkPad T41p"), 533 535 HDAPS_DMI_MATCH_NORMAL("ThinkPad T41"), 534 536 HDAPS_DMI_MATCH_INVERT("ThinkPad T42p"), ··· 538 536 HDAPS_DMI_MATCH_NORMAL("ThinkPad T43"), 539 537 HDAPS_DMI_MATCH_LENOVO("ThinkPad T60p"), 540 538 HDAPS_DMI_MATCH_NORMAL("ThinkPad X40"), 541 - HDAPS_DMI_MATCH_NORMAL("ThinkPad X41 Tablet"), 542 539 HDAPS_DMI_MATCH_NORMAL("ThinkPad X41"), 543 540 HDAPS_DMI_MATCH_LENOVO("ThinkPad X60"), 541 + HDAPS_DMI_MATCH_NORMAL("ThinkPad Z60m"), 544 542 { .ident = NULL } 545 543 }; 546 544
+36 -8
drivers/hwmon/hwmon-vid.c
··· 58 58 doesn't seem to be any named specification for these. The conversion 59 59 tables are detailed directly in the various Pentium M datasheets: 60 60 http://www.intel.com/design/intarch/pentiumm/docs_pentiumm.htm 61 + 62 + The 14 specification corresponds to Intel Core series. There 63 + doesn't seem to be any named specification for these. The conversion 64 + tables are detailed directly in the various Pentium Core datasheets: 65 + http://www.intel.com/design/mobile/datashts/309221.htm 66 + 67 + The 110 (VRM 11) specification corresponds to Intel Conroe based series. 68 + http://www.intel.com/design/processor/applnots/313214.htm 61 69 */ 62 70 63 71 /* vrm is the VRM/VRD document version multiplied by 10. 64 - val is the 4-, 5- or 6-bit VID code. 65 - Returned value is in mV to avoid floating point in the kernel. */ 72 + val is the 4-bit or more VID code. 73 + Returned value is in mV to avoid floating point in the kernel. 74 + Some VID have some bits in uV scale, this is rounded to mV */ 66 75 int vid_from_reg(int val, u8 vrm) 67 76 { 68 77 int vid; ··· 79 70 switch(vrm) { 80 71 81 72 case 100: /* VRD 10.0 */ 73 + /* compute in uV, round to mV */ 74 + val &= 0x3f; 82 75 if((val & 0x1f) == 0x1f) 83 76 return 0; 84 77 if((val & 0x1f) <= 0x09 || val == 0x0a) 85 - vid = 10875 - (val & 0x1f) * 250; 78 + vid = 1087500 - (val & 0x1f) * 25000; 86 79 else 87 - vid = 18625 - (val & 0x1f) * 250; 80 + vid = 1862500 - (val & 0x1f) * 25000; 88 81 if(val & 0x20) 89 - vid -= 125; 90 - vid /= 10; /* only return 3 dec. places for now */ 91 - return vid; 82 + vid -= 12500; 83 + return((vid + 500) / 1000); 92 84 85 + case 110: /* Intel Conroe */ 86 + /* compute in uV, round to mV */ 87 + val &= 0xff; 88 + if(((val & 0x7e) == 0xfe) || (!(val & 0x7e))) 89 + return 0; 90 + return((1600000 - (val - 2) * 6250 + 500) / 1000); 93 91 case 24: /* Opteron processor */ 92 + val &= 0x1f; 94 93 return(val == 0x1f ? 0 : 1550 - val * 25); 95 94 96 95 case 91: /* VRM 9.1 */ 97 96 case 90: /* VRM 9.0 */ 97 + val &= 0x1f; 98 98 return(val == 0x1f ? 0 : 99 99 1850 - val * 25); 100 100 101 101 case 85: /* VRM 8.5 */ 102 + val &= 0x1f; 102 103 return((val & 0x10 ? 25 : 0) + 103 104 ((val & 0x0f) > 0x04 ? 2050 : 1250) - 104 105 ((val & 0x0f) * 50)); ··· 117 98 val &= 0x0f; 118 99 /* fall through */ 119 100 case 82: /* VRM 8.2 */ 101 + val &= 0x1f; 120 102 return(val == 0x1f ? 0 : 121 103 val & 0x10 ? 5100 - (val) * 100 : 122 104 2050 - (val) * 50); 123 105 case 17: /* Intel IMVP-II */ 106 + val &= 0x1f; 124 107 return(val & 0x10 ? 975 - (val & 0xF) * 25 : 125 108 1750 - val * 50); 126 109 case 13: 127 - return(1708 - (val & 0x3f) * 16); 110 + val &= 0x3f; 111 + return(1708 - val * 16); 112 + case 14: /* Intel Core */ 113 + /* compute in uV, round to mV */ 114 + val &= 0x7f; 115 + return(val > 0x77 ? 0 : (1500000 - (val * 12500) + 500) / 1000); 128 116 default: /* report 0 for unknown */ 129 117 printk(KERN_INFO "hwmon-vid: requested unknown VRM version\n"); 130 118 return 0; ··· 164 138 {X86_VENDOR_INTEL, 0x6, 0x9, ANY, 13}, /* Pentium M (130 nm) */ 165 139 {X86_VENDOR_INTEL, 0x6, 0xB, ANY, 85}, /* Tualatin */ 166 140 {X86_VENDOR_INTEL, 0x6, 0xD, ANY, 13}, /* Pentium M (90 nm) */ 141 + {X86_VENDOR_INTEL, 0x6, 0xE, ANY, 14}, /* Intel Core (65 nm) */ 142 + {X86_VENDOR_INTEL, 0x6, 0xF, ANY, 110}, /* Intel Conroe */ 167 143 {X86_VENDOR_INTEL, 0x6, ANY, ANY, 82}, /* any P6 */ 168 144 {X86_VENDOR_INTEL, 0x7, ANY, ANY, 0}, /* Itanium */ 169 145 {X86_VENDOR_INTEL, 0xF, 0x0, ANY, 90}, /* P4 */
+165
drivers/hwmon/lm70.c
··· 1 + /* 2 + * lm70.c 3 + * 4 + * The LM70 is a temperature sensor chip from National Semiconductor (NS). 5 + * Copyright (C) 2006 Kaiwan N Billimoria <kaiwan@designergraphix.com> 6 + * 7 + * The LM70 communicates with a host processor via an SPI/Microwire Bus 8 + * interface. The complete datasheet is available at National's website 9 + * here: 10 + * http://www.national.com/pf/LM/LM70.html 11 + * 12 + * This program is free software; you can redistribute it and/or modify 13 + * it under the terms of the GNU General Public License as published by 14 + * the Free Software Foundation; either version 2 of the License, or 15 + * (at your option) any later version. 16 + * 17 + * This program is distributed in the hope that it will be useful, 18 + * but WITHOUT ANY WARRANTY; without even the implied warranty of 19 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 20 + * GNU General Public License for more details. 21 + * 22 + * You should have received a copy of the GNU General Public License 23 + * along with this program; if not, write to the Free Software 24 + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 25 + */ 26 + 27 + #include <linux/init.h> 28 + #include <linux/module.h> 29 + #include <linux/kernel.h> 30 + #include <linux/device.h> 31 + #include <linux/err.h> 32 + #include <linux/sysfs.h> 33 + #include <linux/hwmon.h> 34 + #include <linux/spi/spi.h> 35 + #include <asm/semaphore.h> 36 + 37 + #define DRVNAME "lm70" 38 + 39 + struct lm70 { 40 + struct class_device *cdev; 41 + struct semaphore sem; 42 + }; 43 + 44 + /* sysfs hook function */ 45 + static ssize_t lm70_sense_temp(struct device *dev, 46 + struct device_attribute *attr, char *buf) 47 + { 48 + struct spi_device *spi = to_spi_device(dev); 49 + int status, val; 50 + u8 rxbuf[2]; 51 + s16 raw=0; 52 + struct lm70 *p_lm70 = dev_get_drvdata(&spi->dev); 53 + 54 + if (down_interruptible(&p_lm70->sem)) 55 + return -ERESTARTSYS; 56 + 57 + /* 58 + * spi_read() requires a DMA-safe buffer; so we use 59 + * spi_write_then_read(), transmitting 0 bytes. 60 + */ 61 + status = spi_write_then_read(spi, NULL, 0, &rxbuf[0], 2); 62 + if (status < 0) { 63 + printk(KERN_WARNING 64 + "spi_write_then_read failed with status %d\n", status); 65 + goto out; 66 + } 67 + dev_dbg(dev, "rxbuf[1] : 0x%x rxbuf[0] : 0x%x\n", rxbuf[1], rxbuf[0]); 68 + 69 + raw = (rxbuf[1] << 8) + rxbuf[0]; 70 + dev_dbg(dev, "raw=0x%x\n", raw); 71 + 72 + /* 73 + * The "raw" temperature read into rxbuf[] is a 16-bit signed 2's 74 + * complement value. Only the MSB 11 bits (1 sign + 10 temperature 75 + * bits) are meaningful; the LSB 5 bits are to be discarded. 76 + * See the datasheet. 77 + * 78 + * Further, each bit represents 0.25 degrees Celsius; so, multiply 79 + * by 0.25. Also multiply by 1000 to represent in millidegrees 80 + * Celsius. 81 + * So it's equivalent to multiplying by 0.25 * 1000 = 250. 82 + */ 83 + val = ((int)raw/32) * 250; 84 + status = sprintf(buf, "%+d\n", val); /* millidegrees Celsius */ 85 + out: 86 + up(&p_lm70->sem); 87 + return status; 88 + } 89 + 90 + static DEVICE_ATTR(temp1_input, S_IRUGO, lm70_sense_temp, NULL); 91 + 92 + /*----------------------------------------------------------------------*/ 93 + 94 + static int __devinit lm70_probe(struct spi_device *spi) 95 + { 96 + struct lm70 *p_lm70; 97 + int status; 98 + 99 + p_lm70 = kzalloc(sizeof *p_lm70, GFP_KERNEL); 100 + if (!p_lm70) 101 + return -ENOMEM; 102 + 103 + init_MUTEX(&p_lm70->sem); 104 + 105 + /* sysfs hook */ 106 + p_lm70->cdev = hwmon_device_register(&spi->dev); 107 + if (IS_ERR(p_lm70->cdev)) { 108 + dev_dbg(&spi->dev, "hwmon_device_register failed.\n"); 109 + status = PTR_ERR(p_lm70->cdev); 110 + goto out_dev_reg_failed; 111 + } 112 + dev_set_drvdata(&spi->dev, p_lm70); 113 + 114 + if ((status = device_create_file(&spi->dev, &dev_attr_temp1_input))) { 115 + dev_dbg(&spi->dev, "device_create_file failure.\n"); 116 + goto out_dev_create_file_failed; 117 + } 118 + 119 + return 0; 120 + 121 + out_dev_create_file_failed: 122 + hwmon_device_unregister(p_lm70->cdev); 123 + out_dev_reg_failed: 124 + dev_set_drvdata(&spi->dev, NULL); 125 + kfree(p_lm70); 126 + return status; 127 + } 128 + 129 + static int __exit lm70_remove(struct spi_device *spi) 130 + { 131 + struct lm70 *p_lm70 = dev_get_drvdata(&spi->dev); 132 + 133 + device_remove_file(&spi->dev, &dev_attr_temp1_input); 134 + hwmon_device_unregister(p_lm70->cdev); 135 + dev_set_drvdata(&spi->dev, NULL); 136 + kfree(p_lm70); 137 + 138 + return 0; 139 + } 140 + 141 + static struct spi_driver lm70_driver = { 142 + .driver = { 143 + .name = "lm70", 144 + .owner = THIS_MODULE, 145 + }, 146 + .probe = lm70_probe, 147 + .remove = __devexit_p(lm70_remove), 148 + }; 149 + 150 + static int __init init_lm70(void) 151 + { 152 + return spi_register_driver(&lm70_driver); 153 + } 154 + 155 + static void __exit cleanup_lm70(void) 156 + { 157 + spi_unregister_driver(&lm70_driver); 158 + } 159 + 160 + module_init(init_lm70); 161 + module_exit(cleanup_lm70); 162 + 163 + MODULE_AUTHOR("Kaiwan N Billimoria"); 164 + MODULE_DESCRIPTION("National Semiconductor LM70 Linux driver"); 165 + MODULE_LICENSE("GPL");
+37 -13
drivers/hwmon/lm83.c
··· 12 12 * Since the datasheet omits to give the chip stepping code, I give it 13 13 * here: 0x03 (at register 0xff). 14 14 * 15 + * Also supports the LM82 temp sensor, which is basically a stripped down 16 + * model of the LM83. Datasheet is here: 17 + * http://www.national.com/pf/LM/LM82.html 18 + * 15 19 * This program is free software; you can redistribute it and/or modify 16 20 * it under the terms of the GNU General Public License as published by 17 21 * the Free Software Foundation; either version 2 of the License, or ··· 56 52 * Insmod parameters 57 53 */ 58 54 59 - I2C_CLIENT_INSMOD_1(lm83); 55 + I2C_CLIENT_INSMOD_2(lm83, lm82); 60 56 61 57 /* 62 58 * The LM83 registers ··· 287 283 if (man_id == 0x01) { /* National Semiconductor */ 288 284 if (chip_id == 0x03) { 289 285 kind = lm83; 286 + } else 287 + if (chip_id == 0x01) { 288 + kind = lm82; 290 289 } 291 290 } 292 291 ··· 303 296 304 297 if (kind == lm83) { 305 298 name = "lm83"; 299 + } else 300 + if (kind == lm82) { 301 + name = "lm82"; 306 302 } 307 303 308 304 /* We can fill in the remaining client fields */ ··· 329 319 goto exit_detach; 330 320 } 331 321 322 + /* 323 + * The LM82 can only monitor one external diode which is 324 + * at the same register as the LM83 temp3 entry - so we 325 + * declare 1 and 3 common, and then 2 and 4 only for the LM83. 326 + */ 327 + 332 328 device_create_file(&new_client->dev, 333 329 &sensor_dev_attr_temp1_input.dev_attr); 334 330 device_create_file(&new_client->dev, 335 - &sensor_dev_attr_temp2_input.dev_attr); 336 - device_create_file(&new_client->dev, 337 331 &sensor_dev_attr_temp3_input.dev_attr); 338 - device_create_file(&new_client->dev, 339 - &sensor_dev_attr_temp4_input.dev_attr); 332 + 340 333 device_create_file(&new_client->dev, 341 334 &sensor_dev_attr_temp1_max.dev_attr); 342 335 device_create_file(&new_client->dev, 343 - &sensor_dev_attr_temp2_max.dev_attr); 344 - device_create_file(&new_client->dev, 345 336 &sensor_dev_attr_temp3_max.dev_attr); 346 - device_create_file(&new_client->dev, 347 - &sensor_dev_attr_temp4_max.dev_attr); 337 + 348 338 device_create_file(&new_client->dev, 349 339 &sensor_dev_attr_temp1_crit.dev_attr); 350 340 device_create_file(&new_client->dev, 351 - &sensor_dev_attr_temp2_crit.dev_attr); 352 - device_create_file(&new_client->dev, 353 341 &sensor_dev_attr_temp3_crit.dev_attr); 354 - device_create_file(&new_client->dev, 355 - &sensor_dev_attr_temp4_crit.dev_attr); 342 + 356 343 device_create_file(&new_client->dev, &dev_attr_alarms); 344 + 345 + if (kind == lm83) { 346 + device_create_file(&new_client->dev, 347 + &sensor_dev_attr_temp2_input.dev_attr); 348 + device_create_file(&new_client->dev, 349 + &sensor_dev_attr_temp4_input.dev_attr); 350 + 351 + device_create_file(&new_client->dev, 352 + &sensor_dev_attr_temp2_max.dev_attr); 353 + device_create_file(&new_client->dev, 354 + &sensor_dev_attr_temp4_max.dev_attr); 355 + 356 + device_create_file(&new_client->dev, 357 + &sensor_dev_attr_temp2_crit.dev_attr); 358 + device_create_file(&new_client->dev, 359 + &sensor_dev_attr_temp4_crit.dev_attr); 360 + } 357 361 358 362 return 0; 359 363
+648
drivers/hwmon/smsc47m192.c
··· 1 + /* 2 + smsc47m192.c - Support for hardware monitoring block of 3 + SMSC LPC47M192 and LPC47M997 Super I/O chips 4 + 5 + Copyright (C) 2006 Hartmut Rick <linux@rick.claranet.de> 6 + 7 + Derived from lm78.c and other chip drivers. 8 + 9 + This program is free software; you can redistribute it and/or modify 10 + it under the terms of the GNU General Public License as published by 11 + the Free Software Foundation; either version 2 of the License, or 12 + (at your option) any later version. 13 + 14 + This program is distributed in the hope that it will be useful, 15 + but WITHOUT ANY WARRANTY; without even the implied warranty of 16 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 + GNU General Public License for more details. 18 + 19 + You should have received a copy of the GNU General Public License 20 + along with this program; if not, write to the Free Software 21 + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 22 + */ 23 + 24 + #include <linux/module.h> 25 + #include <linux/init.h> 26 + #include <linux/slab.h> 27 + #include <linux/jiffies.h> 28 + #include <linux/i2c.h> 29 + #include <linux/hwmon.h> 30 + #include <linux/hwmon-sysfs.h> 31 + #include <linux/hwmon-vid.h> 32 + #include <linux/err.h> 33 + 34 + /* Addresses to scan */ 35 + static unsigned short normal_i2c[] = { 0x2c, 0x2d, I2C_CLIENT_END }; 36 + 37 + /* Insmod parameters */ 38 + I2C_CLIENT_INSMOD_1(smsc47m192); 39 + 40 + /* SMSC47M192 registers */ 41 + #define SMSC47M192_REG_IN(nr) ((nr)<6 ? (0x20 + (nr)) : \ 42 + (0x50 + (nr) - 6)) 43 + #define SMSC47M192_REG_IN_MAX(nr) ((nr)<6 ? (0x2b + (nr) * 2) : \ 44 + (0x54 + (((nr) - 6) * 2))) 45 + #define SMSC47M192_REG_IN_MIN(nr) ((nr)<6 ? (0x2c + (nr) * 2) : \ 46 + (0x55 + (((nr) - 6) * 2))) 47 + static u8 SMSC47M192_REG_TEMP[3] = { 0x27, 0x26, 0x52 }; 48 + static u8 SMSC47M192_REG_TEMP_MAX[3] = { 0x39, 0x37, 0x58 }; 49 + static u8 SMSC47M192_REG_TEMP_MIN[3] = { 0x3A, 0x38, 0x59 }; 50 + #define SMSC47M192_REG_TEMP_OFFSET(nr) ((nr)==2 ? 0x1e : 0x1f) 51 + #define SMSC47M192_REG_ALARM1 0x41 52 + #define SMSC47M192_REG_ALARM2 0x42 53 + #define SMSC47M192_REG_VID 0x47 54 + #define SMSC47M192_REG_VID4 0x49 55 + #define SMSC47M192_REG_CONFIG 0x40 56 + #define SMSC47M192_REG_SFR 0x4f 57 + #define SMSC47M192_REG_COMPANY_ID 0x3e 58 + #define SMSC47M192_REG_VERSION 0x3f 59 + 60 + /* generalised scaling with integer rounding */ 61 + static inline int SCALE(long val, int mul, int div) 62 + { 63 + if (val < 0) 64 + return (val * mul - div / 2) / div; 65 + else 66 + return (val * mul + div / 2) / div; 67 + } 68 + 69 + /* Conversions */ 70 + 71 + /* smsc47m192 internally scales voltage measurements */ 72 + static const u16 nom_mv[] = { 2500, 2250, 3300, 5000, 12000, 3300, 1500, 1800 }; 73 + 74 + static inline unsigned int IN_FROM_REG(u8 reg, int n) 75 + { 76 + return SCALE(reg, nom_mv[n], 192); 77 + } 78 + 79 + static inline u8 IN_TO_REG(unsigned long val, int n) 80 + { 81 + return SENSORS_LIMIT(SCALE(val, 192, nom_mv[n]), 0, 255); 82 + } 83 + 84 + /* TEMP: 0.001 degC units (-128C to +127C) 85 + REG: 1C/bit, two's complement */ 86 + static inline s8 TEMP_TO_REG(int val) 87 + { 88 + return SENSORS_LIMIT(SCALE(val, 1, 1000), -128000, 127000); 89 + } 90 + 91 + static inline int TEMP_FROM_REG(s8 val) 92 + { 93 + return val * 1000; 94 + } 95 + 96 + struct smsc47m192_data { 97 + struct i2c_client client; 98 + struct class_device *class_dev; 99 + struct semaphore update_lock; 100 + char valid; /* !=0 if following fields are valid */ 101 + unsigned long last_updated; /* In jiffies */ 102 + 103 + u8 in[8]; /* Register value */ 104 + u8 in_max[8]; /* Register value */ 105 + u8 in_min[8]; /* Register value */ 106 + s8 temp[3]; /* Register value */ 107 + s8 temp_max[3]; /* Register value */ 108 + s8 temp_min[3]; /* Register value */ 109 + s8 temp_offset[3]; /* Register value */ 110 + u16 alarms; /* Register encoding, combined */ 111 + u8 vid; /* Register encoding, combined */ 112 + u8 vrm; 113 + }; 114 + 115 + static int smsc47m192_attach_adapter(struct i2c_adapter *adapter); 116 + static int smsc47m192_detect(struct i2c_adapter *adapter, int address, 117 + int kind); 118 + static int smsc47m192_detach_client(struct i2c_client *client); 119 + static struct smsc47m192_data *smsc47m192_update_device(struct device *dev); 120 + 121 + static struct i2c_driver smsc47m192_driver = { 122 + .driver = { 123 + .name = "smsc47m192", 124 + }, 125 + .attach_adapter = smsc47m192_attach_adapter, 126 + .detach_client = smsc47m192_detach_client, 127 + }; 128 + 129 + /* Voltages */ 130 + static ssize_t show_in(struct device *dev, struct device_attribute *attr, 131 + char *buf) 132 + { 133 + struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); 134 + int nr = sensor_attr->index; 135 + struct smsc47m192_data *data = smsc47m192_update_device(dev); 136 + return sprintf(buf, "%d\n", IN_FROM_REG(data->in[nr], nr)); 137 + } 138 + 139 + static ssize_t show_in_min(struct device *dev, struct device_attribute *attr, 140 + char *buf) 141 + { 142 + struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); 143 + int nr = sensor_attr->index; 144 + struct smsc47m192_data *data = smsc47m192_update_device(dev); 145 + return sprintf(buf, "%d\n", IN_FROM_REG(data->in_min[nr], nr)); 146 + } 147 + 148 + static ssize_t show_in_max(struct device *dev, struct device_attribute *attr, 149 + char *buf) 150 + { 151 + struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); 152 + int nr = sensor_attr->index; 153 + struct smsc47m192_data *data = smsc47m192_update_device(dev); 154 + return sprintf(buf, "%d\n", IN_FROM_REG(data->in_max[nr], nr)); 155 + } 156 + 157 + static ssize_t set_in_min(struct device *dev, struct device_attribute *attr, 158 + const char *buf, size_t count) 159 + { 160 + struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); 161 + int nr = sensor_attr->index; 162 + struct i2c_client *client = to_i2c_client(dev); 163 + struct smsc47m192_data *data = i2c_get_clientdata(client); 164 + unsigned long val = simple_strtoul(buf, NULL, 10); 165 + 166 + down(&data->update_lock); 167 + data->in_min[nr] = IN_TO_REG(val, nr); 168 + i2c_smbus_write_byte_data(client, SMSC47M192_REG_IN_MIN(nr), 169 + data->in_min[nr]); 170 + up(&data->update_lock); 171 + return count; 172 + } 173 + 174 + static ssize_t set_in_max(struct device *dev, struct device_attribute *attr, 175 + const char *buf, size_t count) 176 + { 177 + struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); 178 + int nr = sensor_attr->index; 179 + struct i2c_client *client = to_i2c_client(dev); 180 + struct smsc47m192_data *data = i2c_get_clientdata(client); 181 + unsigned long val = simple_strtoul(buf, NULL, 10); 182 + 183 + down(&data->update_lock); 184 + data->in_max[nr] = IN_TO_REG(val, nr); 185 + i2c_smbus_write_byte_data(client, SMSC47M192_REG_IN_MAX(nr), 186 + data->in_max[nr]); 187 + up(&data->update_lock); 188 + return count; 189 + } 190 + 191 + #define show_in_offset(offset) \ 192 + static SENSOR_DEVICE_ATTR(in##offset##_input, S_IRUGO, \ 193 + show_in, NULL, offset); \ 194 + static SENSOR_DEVICE_ATTR(in##offset##_min, S_IRUGO | S_IWUSR, \ 195 + show_in_min, set_in_min, offset); \ 196 + static SENSOR_DEVICE_ATTR(in##offset##_max, S_IRUGO | S_IWUSR, \ 197 + show_in_max, set_in_max, offset); 198 + 199 + show_in_offset(0) 200 + show_in_offset(1) 201 + show_in_offset(2) 202 + show_in_offset(3) 203 + show_in_offset(4) 204 + show_in_offset(5) 205 + show_in_offset(6) 206 + show_in_offset(7) 207 + 208 + /* Temperatures */ 209 + static ssize_t show_temp(struct device *dev, struct device_attribute *attr, 210 + char *buf) 211 + { 212 + struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); 213 + int nr = sensor_attr->index; 214 + struct smsc47m192_data *data = smsc47m192_update_device(dev); 215 + return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp[nr])); 216 + } 217 + 218 + static ssize_t show_temp_min(struct device *dev, struct device_attribute *attr, 219 + char *buf) 220 + { 221 + struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); 222 + int nr = sensor_attr->index; 223 + struct smsc47m192_data *data = smsc47m192_update_device(dev); 224 + return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_min[nr])); 225 + } 226 + 227 + static ssize_t show_temp_max(struct device *dev, struct device_attribute *attr, 228 + char *buf) 229 + { 230 + struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); 231 + int nr = sensor_attr->index; 232 + struct smsc47m192_data *data = smsc47m192_update_device(dev); 233 + return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_max[nr])); 234 + } 235 + 236 + static ssize_t set_temp_min(struct device *dev, struct device_attribute *attr, 237 + const char *buf, size_t count) 238 + { 239 + struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); 240 + int nr = sensor_attr->index; 241 + struct i2c_client *client = to_i2c_client(dev); 242 + struct smsc47m192_data *data = i2c_get_clientdata(client); 243 + long val = simple_strtol(buf, NULL, 10); 244 + 245 + down(&data->update_lock); 246 + data->temp_min[nr] = TEMP_TO_REG(val); 247 + i2c_smbus_write_byte_data(client, SMSC47M192_REG_TEMP_MIN[nr], 248 + data->temp_min[nr]); 249 + up(&data->update_lock); 250 + return count; 251 + } 252 + 253 + static ssize_t set_temp_max(struct device *dev, struct device_attribute *attr, 254 + const char *buf, size_t count) 255 + { 256 + struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); 257 + int nr = sensor_attr->index; 258 + struct i2c_client *client = to_i2c_client(dev); 259 + struct smsc47m192_data *data = i2c_get_clientdata(client); 260 + long val = simple_strtol(buf, NULL, 10); 261 + 262 + down(&data->update_lock); 263 + data->temp_max[nr] = TEMP_TO_REG(val); 264 + i2c_smbus_write_byte_data(client, SMSC47M192_REG_TEMP_MAX[nr], 265 + data->temp_max[nr]); 266 + up(&data->update_lock); 267 + return count; 268 + } 269 + 270 + static ssize_t show_temp_offset(struct device *dev, struct device_attribute 271 + *attr, char *buf) 272 + { 273 + struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); 274 + int nr = sensor_attr->index; 275 + struct smsc47m192_data *data = smsc47m192_update_device(dev); 276 + return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_offset[nr])); 277 + } 278 + 279 + static ssize_t set_temp_offset(struct device *dev, struct device_attribute 280 + *attr, const char *buf, size_t count) 281 + { 282 + struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); 283 + int nr = sensor_attr->index; 284 + struct i2c_client *client = to_i2c_client(dev); 285 + struct smsc47m192_data *data = i2c_get_clientdata(client); 286 + u8 sfr = i2c_smbus_read_byte_data(client, SMSC47M192_REG_SFR); 287 + long val = simple_strtol(buf, NULL, 10); 288 + 289 + down(&data->update_lock); 290 + data->temp_offset[nr] = TEMP_TO_REG(val); 291 + if (nr>1) 292 + i2c_smbus_write_byte_data(client, 293 + SMSC47M192_REG_TEMP_OFFSET(nr), data->temp_offset[nr]); 294 + else if (data->temp_offset[nr] != 0) { 295 + /* offset[0] and offset[1] share the same register, 296 + SFR bit 4 activates offset[0] */ 297 + i2c_smbus_write_byte_data(client, SMSC47M192_REG_SFR, 298 + (sfr & 0xef) | (nr==0 ? 0x10 : 0)); 299 + data->temp_offset[1-nr] = 0; 300 + i2c_smbus_write_byte_data(client, 301 + SMSC47M192_REG_TEMP_OFFSET(nr), data->temp_offset[nr]); 302 + } else if ((sfr & 0x10) == (nr==0 ? 0x10 : 0)) 303 + i2c_smbus_write_byte_data(client, 304 + SMSC47M192_REG_TEMP_OFFSET(nr), 0); 305 + up(&data->update_lock); 306 + return count; 307 + } 308 + 309 + #define show_temp_index(index) \ 310 + static SENSOR_DEVICE_ATTR(temp##index##_input, S_IRUGO, \ 311 + show_temp, NULL, index-1); \ 312 + static SENSOR_DEVICE_ATTR(temp##index##_min, S_IRUGO | S_IWUSR, \ 313 + show_temp_min, set_temp_min, index-1); \ 314 + static SENSOR_DEVICE_ATTR(temp##index##_max, S_IRUGO | S_IWUSR, \ 315 + show_temp_max, set_temp_max, index-1); \ 316 + static SENSOR_DEVICE_ATTR(temp##index##_offset, S_IRUGO | S_IWUSR, \ 317 + show_temp_offset, set_temp_offset, index-1); 318 + 319 + show_temp_index(1) 320 + show_temp_index(2) 321 + show_temp_index(3) 322 + 323 + /* VID */ 324 + static ssize_t show_vid(struct device *dev, struct device_attribute *attr, 325 + char *buf) 326 + { 327 + struct smsc47m192_data *data = smsc47m192_update_device(dev); 328 + return sprintf(buf, "%d\n", vid_from_reg(data->vid, data->vrm)); 329 + } 330 + static DEVICE_ATTR(cpu0_vid, S_IRUGO, show_vid, NULL); 331 + 332 + static ssize_t show_vrm(struct device *dev, struct device_attribute *attr, 333 + char *buf) 334 + { 335 + struct smsc47m192_data *data = smsc47m192_update_device(dev); 336 + return sprintf(buf, "%d\n", data->vrm); 337 + } 338 + 339 + static ssize_t set_vrm(struct device *dev, struct device_attribute *attr, 340 + const char *buf, size_t count) 341 + { 342 + struct i2c_client *client = to_i2c_client(dev); 343 + struct smsc47m192_data *data = i2c_get_clientdata(client); 344 + data->vrm = simple_strtoul(buf, NULL, 10); 345 + return count; 346 + } 347 + static DEVICE_ATTR(vrm, S_IRUGO | S_IWUSR, show_vrm, set_vrm); 348 + 349 + /* Alarms */ 350 + static ssize_t show_alarm(struct device *dev, struct device_attribute *attr, 351 + char *buf) 352 + { 353 + struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); 354 + int nr = sensor_attr->index; 355 + struct smsc47m192_data *data = smsc47m192_update_device(dev); 356 + return sprintf(buf, "%u\n", (data->alarms & nr) ? 1 : 0); 357 + } 358 + 359 + static SENSOR_DEVICE_ATTR(temp1_alarm, S_IRUGO, show_alarm, NULL, 0x0010); 360 + static SENSOR_DEVICE_ATTR(temp2_alarm, S_IRUGO, show_alarm, NULL, 0x0020); 361 + static SENSOR_DEVICE_ATTR(temp3_alarm, S_IRUGO, show_alarm, NULL, 0x0040); 362 + static SENSOR_DEVICE_ATTR(temp2_input_fault, S_IRUGO, show_alarm, NULL, 0x4000); 363 + static SENSOR_DEVICE_ATTR(temp3_input_fault, S_IRUGO, show_alarm, NULL, 0x8000); 364 + static SENSOR_DEVICE_ATTR(in0_alarm, S_IRUGO, show_alarm, NULL, 0x0001); 365 + static SENSOR_DEVICE_ATTR(in1_alarm, S_IRUGO, show_alarm, NULL, 0x0002); 366 + static SENSOR_DEVICE_ATTR(in2_alarm, S_IRUGO, show_alarm, NULL, 0x0004); 367 + static SENSOR_DEVICE_ATTR(in3_alarm, S_IRUGO, show_alarm, NULL, 0x0008); 368 + static SENSOR_DEVICE_ATTR(in4_alarm, S_IRUGO, show_alarm, NULL, 0x0100); 369 + static SENSOR_DEVICE_ATTR(in5_alarm, S_IRUGO, show_alarm, NULL, 0x0200); 370 + static SENSOR_DEVICE_ATTR(in6_alarm, S_IRUGO, show_alarm, NULL, 0x0400); 371 + static SENSOR_DEVICE_ATTR(in7_alarm, S_IRUGO, show_alarm, NULL, 0x0800); 372 + 373 + /* This function is called when: 374 + * smsc47m192_driver is inserted (when this module is loaded), for each 375 + available adapter 376 + * when a new adapter is inserted (and smsc47m192_driver is still present) */ 377 + static int smsc47m192_attach_adapter(struct i2c_adapter *adapter) 378 + { 379 + if (!(adapter->class & I2C_CLASS_HWMON)) 380 + return 0; 381 + return i2c_probe(adapter, &addr_data, smsc47m192_detect); 382 + } 383 + 384 + static void smsc47m192_init_client(struct i2c_client *client) 385 + { 386 + int i; 387 + u8 config = i2c_smbus_read_byte_data(client, SMSC47M192_REG_CONFIG); 388 + u8 sfr = i2c_smbus_read_byte_data(client, SMSC47M192_REG_SFR); 389 + 390 + /* select cycle mode (pause 1 sec between updates) */ 391 + i2c_smbus_write_byte_data(client, SMSC47M192_REG_SFR, 392 + (sfr & 0xfd) | 0x02); 393 + if (!(config & 0x01)) { 394 + /* initialize alarm limits */ 395 + for (i=0; i<8; i++) { 396 + i2c_smbus_write_byte_data(client, 397 + SMSC47M192_REG_IN_MIN(i), 0); 398 + i2c_smbus_write_byte_data(client, 399 + SMSC47M192_REG_IN_MAX(i), 0xff); 400 + } 401 + for (i=0; i<3; i++) { 402 + i2c_smbus_write_byte_data(client, 403 + SMSC47M192_REG_TEMP_MIN[i], 0x80); 404 + i2c_smbus_write_byte_data(client, 405 + SMSC47M192_REG_TEMP_MAX[i], 0x7f); 406 + } 407 + 408 + /* start monitoring */ 409 + i2c_smbus_write_byte_data(client, SMSC47M192_REG_CONFIG, 410 + (config & 0xf7) | 0x01); 411 + } 412 + } 413 + 414 + /* This function is called by i2c_probe */ 415 + static int smsc47m192_detect(struct i2c_adapter *adapter, int address, 416 + int kind) 417 + { 418 + struct i2c_client *client; 419 + struct smsc47m192_data *data; 420 + int err = 0; 421 + int version, config; 422 + 423 + if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) 424 + goto exit; 425 + 426 + if (!(data = kzalloc(sizeof(struct smsc47m192_data), GFP_KERNEL))) { 427 + err = -ENOMEM; 428 + goto exit; 429 + } 430 + 431 + client = &data->client; 432 + i2c_set_clientdata(client, data); 433 + client->addr = address; 434 + client->adapter = adapter; 435 + client->driver = &smsc47m192_driver; 436 + 437 + if (kind == 0) 438 + kind = smsc47m192; 439 + 440 + /* Detection criteria from sensors_detect script */ 441 + if (kind < 0) { 442 + if (i2c_smbus_read_byte_data(client, 443 + SMSC47M192_REG_COMPANY_ID) == 0x55 444 + && ((version = i2c_smbus_read_byte_data(client, 445 + SMSC47M192_REG_VERSION)) & 0xf0) == 0x20 446 + && (i2c_smbus_read_byte_data(client, 447 + SMSC47M192_REG_VID) & 0x70) == 0x00 448 + && (i2c_smbus_read_byte_data(client, 449 + SMSC47M192_REG_VID4) & 0xfe) == 0x80) { 450 + dev_info(&adapter->dev, 451 + "found SMSC47M192 or SMSC47M997, " 452 + "version 2, stepping A%d\n", version & 0x0f); 453 + } else { 454 + dev_dbg(&adapter->dev, 455 + "SMSC47M192 detection failed at 0x%02x\n", 456 + address); 457 + goto exit_free; 458 + } 459 + } 460 + 461 + /* Fill in the remaining client fields and put into the global list */ 462 + strlcpy(client->name, "smsc47m192", I2C_NAME_SIZE); 463 + data->vrm = vid_which_vrm(); 464 + init_MUTEX(&data->update_lock); 465 + 466 + /* Tell the I2C layer a new client has arrived */ 467 + if ((err = i2c_attach_client(client))) 468 + goto exit_free; 469 + 470 + /* Initialize the SMSC47M192 chip */ 471 + smsc47m192_init_client(client); 472 + 473 + /* Register sysfs hooks */ 474 + data->class_dev = hwmon_device_register(&client->dev); 475 + if (IS_ERR(data->class_dev)) { 476 + err = PTR_ERR(data->class_dev); 477 + goto exit_detach; 478 + } 479 + 480 + device_create_file(&client->dev, &sensor_dev_attr_in0_input.dev_attr); 481 + device_create_file(&client->dev, &sensor_dev_attr_in0_min.dev_attr); 482 + device_create_file(&client->dev, &sensor_dev_attr_in0_max.dev_attr); 483 + device_create_file(&client->dev, &sensor_dev_attr_in0_alarm.dev_attr); 484 + device_create_file(&client->dev, &sensor_dev_attr_in1_input.dev_attr); 485 + device_create_file(&client->dev, &sensor_dev_attr_in1_min.dev_attr); 486 + device_create_file(&client->dev, &sensor_dev_attr_in1_max.dev_attr); 487 + device_create_file(&client->dev, &sensor_dev_attr_in1_alarm.dev_attr); 488 + device_create_file(&client->dev, &sensor_dev_attr_in2_input.dev_attr); 489 + device_create_file(&client->dev, &sensor_dev_attr_in2_min.dev_attr); 490 + device_create_file(&client->dev, &sensor_dev_attr_in2_max.dev_attr); 491 + device_create_file(&client->dev, &sensor_dev_attr_in2_alarm.dev_attr); 492 + device_create_file(&client->dev, &sensor_dev_attr_in3_input.dev_attr); 493 + device_create_file(&client->dev, &sensor_dev_attr_in3_min.dev_attr); 494 + device_create_file(&client->dev, &sensor_dev_attr_in3_max.dev_attr); 495 + device_create_file(&client->dev, &sensor_dev_attr_in3_alarm.dev_attr); 496 + 497 + /* Pin 110 is either in4 (+12V) or VID4 */ 498 + config = i2c_smbus_read_byte_data(client, SMSC47M192_REG_CONFIG); 499 + if (!(config & 0x20)) { 500 + device_create_file(&client->dev, 501 + &sensor_dev_attr_in4_input.dev_attr); 502 + device_create_file(&client->dev, 503 + &sensor_dev_attr_in4_min.dev_attr); 504 + device_create_file(&client->dev, 505 + &sensor_dev_attr_in4_max.dev_attr); 506 + device_create_file(&client->dev, 507 + &sensor_dev_attr_in4_alarm.dev_attr); 508 + } 509 + device_create_file(&client->dev, &sensor_dev_attr_in5_input.dev_attr); 510 + device_create_file(&client->dev, &sensor_dev_attr_in5_min.dev_attr); 511 + device_create_file(&client->dev, &sensor_dev_attr_in5_max.dev_attr); 512 + device_create_file(&client->dev, &sensor_dev_attr_in5_alarm.dev_attr); 513 + device_create_file(&client->dev, &sensor_dev_attr_in6_input.dev_attr); 514 + device_create_file(&client->dev, &sensor_dev_attr_in6_min.dev_attr); 515 + device_create_file(&client->dev, &sensor_dev_attr_in6_max.dev_attr); 516 + device_create_file(&client->dev, &sensor_dev_attr_in6_alarm.dev_attr); 517 + device_create_file(&client->dev, &sensor_dev_attr_in7_input.dev_attr); 518 + device_create_file(&client->dev, &sensor_dev_attr_in7_min.dev_attr); 519 + device_create_file(&client->dev, &sensor_dev_attr_in7_max.dev_attr); 520 + device_create_file(&client->dev, &sensor_dev_attr_in7_alarm.dev_attr); 521 + device_create_file(&client->dev, &sensor_dev_attr_temp1_input.dev_attr); 522 + device_create_file(&client->dev, &sensor_dev_attr_temp1_max.dev_attr); 523 + device_create_file(&client->dev, &sensor_dev_attr_temp1_min.dev_attr); 524 + device_create_file(&client->dev, 525 + &sensor_dev_attr_temp1_offset.dev_attr); 526 + device_create_file(&client->dev, &sensor_dev_attr_temp1_alarm.dev_attr); 527 + device_create_file(&client->dev, &sensor_dev_attr_temp2_input.dev_attr); 528 + device_create_file(&client->dev, &sensor_dev_attr_temp2_max.dev_attr); 529 + device_create_file(&client->dev, &sensor_dev_attr_temp2_min.dev_attr); 530 + device_create_file(&client->dev, 531 + &sensor_dev_attr_temp2_offset.dev_attr); 532 + device_create_file(&client->dev, &sensor_dev_attr_temp2_alarm.dev_attr); 533 + device_create_file(&client->dev, 534 + &sensor_dev_attr_temp2_input_fault.dev_attr); 535 + device_create_file(&client->dev, &sensor_dev_attr_temp3_input.dev_attr); 536 + device_create_file(&client->dev, &sensor_dev_attr_temp3_max.dev_attr); 537 + device_create_file(&client->dev, &sensor_dev_attr_temp3_min.dev_attr); 538 + device_create_file(&client->dev, 539 + &sensor_dev_attr_temp3_offset.dev_attr); 540 + device_create_file(&client->dev, &sensor_dev_attr_temp3_alarm.dev_attr); 541 + device_create_file(&client->dev, 542 + &sensor_dev_attr_temp3_input_fault.dev_attr); 543 + device_create_file(&client->dev, &dev_attr_cpu0_vid); 544 + device_create_file(&client->dev, &dev_attr_vrm); 545 + 546 + return 0; 547 + 548 + exit_detach: 549 + i2c_detach_client(client); 550 + exit_free: 551 + kfree(data); 552 + exit: 553 + return err; 554 + } 555 + 556 + static int smsc47m192_detach_client(struct i2c_client *client) 557 + { 558 + struct smsc47m192_data *data = i2c_get_clientdata(client); 559 + int err; 560 + 561 + hwmon_device_unregister(data->class_dev); 562 + 563 + if ((err = i2c_detach_client(client))) 564 + return err; 565 + 566 + kfree(data); 567 + 568 + return 0; 569 + } 570 + 571 + static struct smsc47m192_data *smsc47m192_update_device(struct device *dev) 572 + { 573 + struct i2c_client *client = to_i2c_client(dev); 574 + struct smsc47m192_data *data = i2c_get_clientdata(client); 575 + int i, config; 576 + 577 + down(&data->update_lock); 578 + 579 + if (time_after(jiffies, data->last_updated + HZ + HZ / 2) 580 + || !data->valid) { 581 + u8 sfr = i2c_smbus_read_byte_data(client, SMSC47M192_REG_SFR); 582 + 583 + dev_dbg(&client->dev, "Starting smsc47m192 update\n"); 584 + 585 + for (i = 0; i <= 7; i++) { 586 + data->in[i] = i2c_smbus_read_byte_data(client, 587 + SMSC47M192_REG_IN(i)); 588 + data->in_min[i] = i2c_smbus_read_byte_data(client, 589 + SMSC47M192_REG_IN_MIN(i)); 590 + data->in_max[i] = i2c_smbus_read_byte_data(client, 591 + SMSC47M192_REG_IN_MAX(i)); 592 + } 593 + for (i = 0; i < 3; i++) { 594 + data->temp[i] = i2c_smbus_read_byte_data(client, 595 + SMSC47M192_REG_TEMP[i]); 596 + data->temp_max[i] = i2c_smbus_read_byte_data(client, 597 + SMSC47M192_REG_TEMP_MAX[i]); 598 + data->temp_min[i] = i2c_smbus_read_byte_data(client, 599 + SMSC47M192_REG_TEMP_MIN[i]); 600 + } 601 + for (i = 1; i < 3; i++) 602 + data->temp_offset[i] = i2c_smbus_read_byte_data(client, 603 + SMSC47M192_REG_TEMP_OFFSET(i)); 604 + /* first offset is temp_offset[0] if SFR bit 4 is set, 605 + temp_offset[1] otherwise */ 606 + if (sfr & 0x10) { 607 + data->temp_offset[0] = data->temp_offset[1]; 608 + data->temp_offset[1] = 0; 609 + } else 610 + data->temp_offset[0] = 0; 611 + 612 + data->vid = i2c_smbus_read_byte_data(client, SMSC47M192_REG_VID) 613 + & 0x0f; 614 + config = i2c_smbus_read_byte_data(client, 615 + SMSC47M192_REG_CONFIG); 616 + if (config & 0x20) 617 + data->vid |= (i2c_smbus_read_byte_data(client, 618 + SMSC47M192_REG_VID4) & 0x01) << 4; 619 + data->alarms = i2c_smbus_read_byte_data(client, 620 + SMSC47M192_REG_ALARM1) | 621 + (i2c_smbus_read_byte_data(client, 622 + SMSC47M192_REG_ALARM2) << 8); 623 + 624 + data->last_updated = jiffies; 625 + data->valid = 1; 626 + } 627 + 628 + up(&data->update_lock); 629 + 630 + return data; 631 + } 632 + 633 + static int __init smsc47m192_init(void) 634 + { 635 + return i2c_add_driver(&smsc47m192_driver); 636 + } 637 + 638 + static void __exit smsc47m192_exit(void) 639 + { 640 + i2c_del_driver(&smsc47m192_driver); 641 + } 642 + 643 + MODULE_AUTHOR("Hartmut Rick <linux@rick.claranet.de>"); 644 + MODULE_DESCRIPTION("SMSC47M192 driver"); 645 + MODULE_LICENSE("GPL"); 646 + 647 + module_init(smsc47m192_init); 648 + module_exit(smsc47m192_exit);
+166 -4
drivers/hwmon/w83627ehf.c
··· 30 30 Supports the following chips: 31 31 32 32 Chip #vin #fan #pwm #temp chip_id man_id 33 - w83627ehf - 5 - 3 0x88 0x5ca3 34 - 35 - This is a preliminary version of the driver, only supporting the 36 - fan and temperature inputs. The chip does much more than that. 33 + w83627ehf 10 5 - 3 0x88 0x5ca3 37 34 */ 38 35 39 36 #include <linux/module.h> ··· 118 121 static const u16 W83627EHF_REG_FAN[] = { 0x28, 0x29, 0x2a, 0x3f, 0x553 }; 119 122 static const u16 W83627EHF_REG_FAN_MIN[] = { 0x3b, 0x3c, 0x3d, 0x3e, 0x55c }; 120 123 124 + /* The W83627EHF registers for nr=7,8,9 are in bank 5 */ 125 + #define W83627EHF_REG_IN_MAX(nr) ((nr < 7) ? (0x2b + (nr) * 2) : \ 126 + (0x554 + (((nr) - 7) * 2))) 127 + #define W83627EHF_REG_IN_MIN(nr) ((nr < 7) ? (0x2c + (nr) * 2) : \ 128 + (0x555 + (((nr) - 7) * 2))) 129 + #define W83627EHF_REG_IN(nr) ((nr < 7) ? (0x20 + (nr)) : \ 130 + (0x550 + (nr) - 7)) 131 + 121 132 #define W83627EHF_REG_TEMP1 0x27 122 133 #define W83627EHF_REG_TEMP1_HYST 0x3a 123 134 #define W83627EHF_REG_TEMP1_OVER 0x39 ··· 140 135 #define W83627EHF_REG_VBAT 0x5D 141 136 #define W83627EHF_REG_DIODE 0x59 142 137 #define W83627EHF_REG_SMI_OVT 0x4C 138 + 139 + #define W83627EHF_REG_ALARM1 0x459 140 + #define W83627EHF_REG_ALARM2 0x45A 141 + #define W83627EHF_REG_ALARM3 0x45B 143 142 144 143 /* 145 144 * Conversions ··· 181 172 return (temp + 500) / 1000; 182 173 } 183 174 175 + /* Some of analog inputs have internal scaling (2x), 8mV is ADC LSB */ 176 + 177 + static u8 scale_in[10] = { 8, 8, 16, 16, 8, 8, 8, 16, 16, 8 }; 178 + 179 + static inline long in_from_reg(u8 reg, u8 nr) 180 + { 181 + return reg * scale_in[nr]; 182 + } 183 + 184 + static inline u8 in_to_reg(u32 val, u8 nr) 185 + { 186 + return SENSORS_LIMIT(((val + (scale_in[nr] / 2)) / scale_in[nr]), 0, 255); 187 + } 188 + 184 189 /* 185 190 * Data structures and manipulation thereof 186 191 */ ··· 209 186 unsigned long last_updated; /* In jiffies */ 210 187 211 188 /* Register values */ 189 + u8 in[10]; /* Register value */ 190 + u8 in_max[10]; /* Register value */ 191 + u8 in_min[10]; /* Register value */ 212 192 u8 fan[5]; 213 193 u8 fan_min[5]; 214 194 u8 fan_div[5]; ··· 222 196 s16 temp[2]; 223 197 s16 temp_max[2]; 224 198 s16 temp_max_hyst[2]; 199 + u32 alarms; 225 200 }; 226 201 227 202 static inline int is_word_sized(u16 reg) ··· 376 349 data->fan_div[3] |= (i >> 5) & 0x04; 377 350 } 378 351 352 + /* Measured voltages and limits */ 353 + for (i = 0; i < 10; i++) { 354 + data->in[i] = w83627ehf_read_value(client, 355 + W83627EHF_REG_IN(i)); 356 + data->in_min[i] = w83627ehf_read_value(client, 357 + W83627EHF_REG_IN_MIN(i)); 358 + data->in_max[i] = w83627ehf_read_value(client, 359 + W83627EHF_REG_IN_MAX(i)); 360 + } 361 + 379 362 /* Measured fan speeds and limits */ 380 363 for (i = 0; i < 5; i++) { 381 364 if (!(data->has_fan & (1 << i))) ··· 432 395 W83627EHF_REG_TEMP_HYST[i]); 433 396 } 434 397 398 + data->alarms = w83627ehf_read_value(client, 399 + W83627EHF_REG_ALARM1) | 400 + (w83627ehf_read_value(client, 401 + W83627EHF_REG_ALARM2) << 8) | 402 + (w83627ehf_read_value(client, 403 + W83627EHF_REG_ALARM3) << 16); 404 + 435 405 data->last_updated = jiffies; 436 406 data->valid = 1; 437 407 } ··· 450 406 /* 451 407 * Sysfs callback functions 452 408 */ 409 + #define show_in_reg(reg) \ 410 + static ssize_t \ 411 + show_##reg(struct device *dev, struct device_attribute *attr, \ 412 + char *buf) \ 413 + { \ 414 + struct w83627ehf_data *data = w83627ehf_update_device(dev); \ 415 + struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); \ 416 + int nr = sensor_attr->index; \ 417 + return sprintf(buf, "%ld\n", in_from_reg(data->reg[nr], nr)); \ 418 + } 419 + show_in_reg(in) 420 + show_in_reg(in_min) 421 + show_in_reg(in_max) 422 + 423 + #define store_in_reg(REG, reg) \ 424 + static ssize_t \ 425 + store_in_##reg (struct device *dev, struct device_attribute *attr, \ 426 + const char *buf, size_t count) \ 427 + { \ 428 + struct i2c_client *client = to_i2c_client(dev); \ 429 + struct w83627ehf_data *data = i2c_get_clientdata(client); \ 430 + struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); \ 431 + int nr = sensor_attr->index; \ 432 + u32 val = simple_strtoul(buf, NULL, 10); \ 433 + \ 434 + mutex_lock(&data->update_lock); \ 435 + data->in_##reg[nr] = in_to_reg(val, nr); \ 436 + w83627ehf_write_value(client, W83627EHF_REG_IN_##REG(nr), \ 437 + data->in_##reg[nr]); \ 438 + mutex_unlock(&data->update_lock); \ 439 + return count; \ 440 + } 441 + 442 + store_in_reg(MIN, min) 443 + store_in_reg(MAX, max) 444 + 445 + static ssize_t show_alarm(struct device *dev, struct device_attribute *attr, char *buf) 446 + { 447 + struct w83627ehf_data *data = w83627ehf_update_device(dev); 448 + struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); 449 + int nr = sensor_attr->index; 450 + return sprintf(buf, "%u\n", (data->alarms >> nr) & 0x01); 451 + } 452 + 453 + static struct sensor_device_attribute sda_in_input[] = { 454 + SENSOR_ATTR(in0_input, S_IRUGO, show_in, NULL, 0), 455 + SENSOR_ATTR(in1_input, S_IRUGO, show_in, NULL, 1), 456 + SENSOR_ATTR(in2_input, S_IRUGO, show_in, NULL, 2), 457 + SENSOR_ATTR(in3_input, S_IRUGO, show_in, NULL, 3), 458 + SENSOR_ATTR(in4_input, S_IRUGO, show_in, NULL, 4), 459 + SENSOR_ATTR(in5_input, S_IRUGO, show_in, NULL, 5), 460 + SENSOR_ATTR(in6_input, S_IRUGO, show_in, NULL, 6), 461 + SENSOR_ATTR(in7_input, S_IRUGO, show_in, NULL, 7), 462 + SENSOR_ATTR(in8_input, S_IRUGO, show_in, NULL, 8), 463 + SENSOR_ATTR(in9_input, S_IRUGO, show_in, NULL, 9), 464 + }; 465 + 466 + static struct sensor_device_attribute sda_in_alarm[] = { 467 + SENSOR_ATTR(in0_alarm, S_IRUGO, show_alarm, NULL, 0), 468 + SENSOR_ATTR(in1_alarm, S_IRUGO, show_alarm, NULL, 1), 469 + SENSOR_ATTR(in2_alarm, S_IRUGO, show_alarm, NULL, 2), 470 + SENSOR_ATTR(in3_alarm, S_IRUGO, show_alarm, NULL, 3), 471 + SENSOR_ATTR(in4_alarm, S_IRUGO, show_alarm, NULL, 8), 472 + SENSOR_ATTR(in5_alarm, S_IRUGO, show_alarm, NULL, 21), 473 + SENSOR_ATTR(in6_alarm, S_IRUGO, show_alarm, NULL, 20), 474 + SENSOR_ATTR(in7_alarm, S_IRUGO, show_alarm, NULL, 16), 475 + SENSOR_ATTR(in8_alarm, S_IRUGO, show_alarm, NULL, 17), 476 + SENSOR_ATTR(in9_alarm, S_IRUGO, show_alarm, NULL, 19), 477 + }; 478 + 479 + static struct sensor_device_attribute sda_in_min[] = { 480 + SENSOR_ATTR(in0_min, S_IWUSR | S_IRUGO, show_in_min, store_in_min, 0), 481 + SENSOR_ATTR(in1_min, S_IWUSR | S_IRUGO, show_in_min, store_in_min, 1), 482 + SENSOR_ATTR(in2_min, S_IWUSR | S_IRUGO, show_in_min, store_in_min, 2), 483 + SENSOR_ATTR(in3_min, S_IWUSR | S_IRUGO, show_in_min, store_in_min, 3), 484 + SENSOR_ATTR(in4_min, S_IWUSR | S_IRUGO, show_in_min, store_in_min, 4), 485 + SENSOR_ATTR(in5_min, S_IWUSR | S_IRUGO, show_in_min, store_in_min, 5), 486 + SENSOR_ATTR(in6_min, S_IWUSR | S_IRUGO, show_in_min, store_in_min, 6), 487 + SENSOR_ATTR(in7_min, S_IWUSR | S_IRUGO, show_in_min, store_in_min, 7), 488 + SENSOR_ATTR(in8_min, S_IWUSR | S_IRUGO, show_in_min, store_in_min, 8), 489 + SENSOR_ATTR(in9_min, S_IWUSR | S_IRUGO, show_in_min, store_in_min, 9), 490 + }; 491 + 492 + static struct sensor_device_attribute sda_in_max[] = { 493 + SENSOR_ATTR(in0_max, S_IWUSR | S_IRUGO, show_in_max, store_in_max, 0), 494 + SENSOR_ATTR(in1_max, S_IWUSR | S_IRUGO, show_in_max, store_in_max, 1), 495 + SENSOR_ATTR(in2_max, S_IWUSR | S_IRUGO, show_in_max, store_in_max, 2), 496 + SENSOR_ATTR(in3_max, S_IWUSR | S_IRUGO, show_in_max, store_in_max, 3), 497 + SENSOR_ATTR(in4_max, S_IWUSR | S_IRUGO, show_in_max, store_in_max, 4), 498 + SENSOR_ATTR(in5_max, S_IWUSR | S_IRUGO, show_in_max, store_in_max, 5), 499 + SENSOR_ATTR(in6_max, S_IWUSR | S_IRUGO, show_in_max, store_in_max, 6), 500 + SENSOR_ATTR(in7_max, S_IWUSR | S_IRUGO, show_in_max, store_in_max, 7), 501 + SENSOR_ATTR(in8_max, S_IWUSR | S_IRUGO, show_in_max, store_in_max, 8), 502 + SENSOR_ATTR(in9_max, S_IWUSR | S_IRUGO, show_in_max, store_in_max, 9), 503 + }; 504 + 505 + static void device_create_file_in(struct device *dev, int i) 506 + { 507 + device_create_file(dev, &sda_in_input[i].dev_attr); 508 + device_create_file(dev, &sda_in_alarm[i].dev_attr); 509 + device_create_file(dev, &sda_in_min[i].dev_attr); 510 + device_create_file(dev, &sda_in_max[i].dev_attr); 511 + } 453 512 454 513 #define show_fan_reg(reg) \ 455 514 static ssize_t \ ··· 652 505 SENSOR_ATTR(fan5_input, S_IRUGO, show_fan, NULL, 4), 653 506 }; 654 507 508 + static struct sensor_device_attribute sda_fan_alarm[] = { 509 + SENSOR_ATTR(fan1_alarm, S_IRUGO, show_alarm, NULL, 6), 510 + SENSOR_ATTR(fan2_alarm, S_IRUGO, show_alarm, NULL, 7), 511 + SENSOR_ATTR(fan3_alarm, S_IRUGO, show_alarm, NULL, 11), 512 + SENSOR_ATTR(fan4_alarm, S_IRUGO, show_alarm, NULL, 10), 513 + SENSOR_ATTR(fan5_alarm, S_IRUGO, show_alarm, NULL, 23), 514 + }; 515 + 655 516 static struct sensor_device_attribute sda_fan_min[] = { 656 517 SENSOR_ATTR(fan1_min, S_IWUSR | S_IRUGO, show_fan_min, 657 518 store_fan_min, 0), ··· 684 529 static void device_create_file_fan(struct device *dev, int i) 685 530 { 686 531 device_create_file(dev, &sda_fan_input[i].dev_attr); 532 + device_create_file(dev, &sda_fan_alarm[i].dev_attr); 687 533 device_create_file(dev, &sda_fan_div[i].dev_attr); 688 534 device_create_file(dev, &sda_fan_min[i].dev_attr); 689 535 } ··· 772 616 store_temp_max_hyst, 0), 773 617 SENSOR_ATTR(temp3_max_hyst, S_IRUGO | S_IWUSR, show_temp_max_hyst, 774 618 store_temp_max_hyst, 1), 619 + SENSOR_ATTR(temp1_alarm, S_IRUGO, show_alarm, NULL, 4), 620 + SENSOR_ATTR(temp2_alarm, S_IRUGO, show_alarm, NULL, 5), 621 + SENSOR_ATTR(temp3_alarm, S_IRUGO, show_alarm, NULL, 13), 775 622 }; 776 623 777 624 /* ··· 863 704 err = PTR_ERR(data->class_dev); 864 705 goto exit_detach; 865 706 } 707 + 708 + for (i = 0; i < 10; i++) 709 + device_create_file_in(dev, i); 866 710 867 711 for (i = 0; i < 5; i++) { 868 712 if (data->has_fan & (1 << i))
+1255
drivers/hwmon/w83791d.c
··· 1 + /* 2 + w83791d.c - Part of lm_sensors, Linux kernel modules for hardware 3 + monitoring 4 + 5 + Copyright (C) 2006 Charles Spirakis <bezaur@gmail.com> 6 + 7 + This program is free software; you can redistribute it and/or modify 8 + it under the terms of the GNU General Public License as published by 9 + the Free Software Foundation; either version 2 of the License, or 10 + (at your option) any later version. 11 + 12 + This program is distributed in the hope that it will be useful, 13 + but WITHOUT ANY WARRANTY; without even the implied warranty of 14 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 + GNU General Public License for more details. 16 + 17 + You should have received a copy of the GNU General Public License 18 + along with this program; if not, write to the Free Software 19 + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 20 + */ 21 + 22 + /* 23 + Supports following chips: 24 + 25 + Chip #vin #fanin #pwm #temp wchipid vendid i2c ISA 26 + w83791d 10 5 3 3 0x71 0x5ca3 yes no 27 + 28 + The w83791d chip appears to be part way between the 83781d and the 29 + 83792d. Thus, this file is derived from both the w83792d.c and 30 + w83781d.c files, but its output is more along the lines of the 31 + 83781d (which means there are no changes to the user-mode sensors 32 + program which treats the 83791d as an 83781d). 33 + */ 34 + 35 + #include <linux/config.h> 36 + #include <linux/module.h> 37 + #include <linux/init.h> 38 + #include <linux/slab.h> 39 + #include <linux/i2c.h> 40 + #include <linux/hwmon.h> 41 + #include <linux/hwmon-vid.h> 42 + #include <linux/hwmon-sysfs.h> 43 + #include <linux/err.h> 44 + #include <linux/mutex.h> 45 + 46 + #define NUMBER_OF_VIN 10 47 + #define NUMBER_OF_FANIN 5 48 + #define NUMBER_OF_TEMPIN 3 49 + 50 + /* Addresses to scan */ 51 + static unsigned short normal_i2c[] = { 0x2c, 0x2d, 0x2e, 0x2f, I2C_CLIENT_END }; 52 + 53 + /* Insmod parameters */ 54 + I2C_CLIENT_INSMOD_1(w83791d); 55 + I2C_CLIENT_MODULE_PARM(force_subclients, "List of subclient addresses: " 56 + "{bus, clientaddr, subclientaddr1, subclientaddr2}"); 57 + 58 + static int reset; 59 + module_param(reset, bool, 0); 60 + MODULE_PARM_DESC(reset, "Set to one to force a hardware chip reset"); 61 + 62 + static int init; 63 + module_param(init, bool, 0); 64 + MODULE_PARM_DESC(init, "Set to one to force extra software initialization"); 65 + 66 + /* The W83791D registers */ 67 + static const u8 W83791D_REG_IN[NUMBER_OF_VIN] = { 68 + 0x20, /* VCOREA in DataSheet */ 69 + 0x21, /* VINR0 in DataSheet */ 70 + 0x22, /* +3.3VIN in DataSheet */ 71 + 0x23, /* VDD5V in DataSheet */ 72 + 0x24, /* +12VIN in DataSheet */ 73 + 0x25, /* -12VIN in DataSheet */ 74 + 0x26, /* -5VIN in DataSheet */ 75 + 0xB0, /* 5VSB in DataSheet */ 76 + 0xB1, /* VBAT in DataSheet */ 77 + 0xB2 /* VINR1 in DataSheet */ 78 + }; 79 + 80 + static const u8 W83791D_REG_IN_MAX[NUMBER_OF_VIN] = { 81 + 0x2B, /* VCOREA High Limit in DataSheet */ 82 + 0x2D, /* VINR0 High Limit in DataSheet */ 83 + 0x2F, /* +3.3VIN High Limit in DataSheet */ 84 + 0x31, /* VDD5V High Limit in DataSheet */ 85 + 0x33, /* +12VIN High Limit in DataSheet */ 86 + 0x35, /* -12VIN High Limit in DataSheet */ 87 + 0x37, /* -5VIN High Limit in DataSheet */ 88 + 0xB4, /* 5VSB High Limit in DataSheet */ 89 + 0xB6, /* VBAT High Limit in DataSheet */ 90 + 0xB8 /* VINR1 High Limit in DataSheet */ 91 + }; 92 + static const u8 W83791D_REG_IN_MIN[NUMBER_OF_VIN] = { 93 + 0x2C, /* VCOREA Low Limit in DataSheet */ 94 + 0x2E, /* VINR0 Low Limit in DataSheet */ 95 + 0x30, /* +3.3VIN Low Limit in DataSheet */ 96 + 0x32, /* VDD5V Low Limit in DataSheet */ 97 + 0x34, /* +12VIN Low Limit in DataSheet */ 98 + 0x36, /* -12VIN Low Limit in DataSheet */ 99 + 0x38, /* -5VIN Low Limit in DataSheet */ 100 + 0xB5, /* 5VSB Low Limit in DataSheet */ 101 + 0xB7, /* VBAT Low Limit in DataSheet */ 102 + 0xB9 /* VINR1 Low Limit in DataSheet */ 103 + }; 104 + static const u8 W83791D_REG_FAN[NUMBER_OF_FANIN] = { 105 + 0x28, /* FAN 1 Count in DataSheet */ 106 + 0x29, /* FAN 2 Count in DataSheet */ 107 + 0x2A, /* FAN 3 Count in DataSheet */ 108 + 0xBA, /* FAN 4 Count in DataSheet */ 109 + 0xBB, /* FAN 5 Count in DataSheet */ 110 + }; 111 + static const u8 W83791D_REG_FAN_MIN[NUMBER_OF_FANIN] = { 112 + 0x3B, /* FAN 1 Count Low Limit in DataSheet */ 113 + 0x3C, /* FAN 2 Count Low Limit in DataSheet */ 114 + 0x3D, /* FAN 3 Count Low Limit in DataSheet */ 115 + 0xBC, /* FAN 4 Count Low Limit in DataSheet */ 116 + 0xBD, /* FAN 5 Count Low Limit in DataSheet */ 117 + }; 118 + 119 + static const u8 W83791D_REG_FAN_CFG[2] = { 120 + 0x84, /* FAN 1/2 configuration */ 121 + 0x95, /* FAN 3 configuration */ 122 + }; 123 + 124 + static const u8 W83791D_REG_FAN_DIV[3] = { 125 + 0x47, /* contains FAN1 and FAN2 Divisor */ 126 + 0x4b, /* contains FAN3 Divisor */ 127 + 0x5C, /* contains FAN4 and FAN5 Divisor */ 128 + }; 129 + 130 + #define W83791D_REG_BANK 0x4E 131 + #define W83791D_REG_TEMP2_CONFIG 0xC2 132 + #define W83791D_REG_TEMP3_CONFIG 0xCA 133 + 134 + static const u8 W83791D_REG_TEMP1[3] = { 135 + 0x27, /* TEMP 1 in DataSheet */ 136 + 0x39, /* TEMP 1 Over in DataSheet */ 137 + 0x3A, /* TEMP 1 Hyst in DataSheet */ 138 + }; 139 + 140 + static const u8 W83791D_REG_TEMP_ADD[2][6] = { 141 + {0xC0, /* TEMP 2 in DataSheet */ 142 + 0xC1, /* TEMP 2(0.5 deg) in DataSheet */ 143 + 0xC5, /* TEMP 2 Over High part in DataSheet */ 144 + 0xC6, /* TEMP 2 Over Low part in DataSheet */ 145 + 0xC3, /* TEMP 2 Thyst High part in DataSheet */ 146 + 0xC4}, /* TEMP 2 Thyst Low part in DataSheet */ 147 + {0xC8, /* TEMP 3 in DataSheet */ 148 + 0xC9, /* TEMP 3(0.5 deg) in DataSheet */ 149 + 0xCD, /* TEMP 3 Over High part in DataSheet */ 150 + 0xCE, /* TEMP 3 Over Low part in DataSheet */ 151 + 0xCB, /* TEMP 3 Thyst High part in DataSheet */ 152 + 0xCC} /* TEMP 3 Thyst Low part in DataSheet */ 153 + }; 154 + 155 + #define W83791D_REG_BEEP_CONFIG 0x4D 156 + 157 + static const u8 W83791D_REG_BEEP_CTRL[3] = { 158 + 0x56, /* BEEP Control Register 1 */ 159 + 0x57, /* BEEP Control Register 2 */ 160 + 0xA3, /* BEEP Control Register 3 */ 161 + }; 162 + 163 + #define W83791D_REG_CONFIG 0x40 164 + #define W83791D_REG_VID_FANDIV 0x47 165 + #define W83791D_REG_DID_VID4 0x49 166 + #define W83791D_REG_WCHIPID 0x58 167 + #define W83791D_REG_CHIPMAN 0x4F 168 + #define W83791D_REG_PIN 0x4B 169 + #define W83791D_REG_I2C_SUBADDR 0x4A 170 + 171 + #define W83791D_REG_ALARM1 0xA9 /* realtime status register1 */ 172 + #define W83791D_REG_ALARM2 0xAA /* realtime status register2 */ 173 + #define W83791D_REG_ALARM3 0xAB /* realtime status register3 */ 174 + 175 + #define W83791D_REG_VBAT 0x5D 176 + #define W83791D_REG_I2C_ADDR 0x48 177 + 178 + /* The SMBus locks itself. The Winbond W83791D has a bank select register 179 + (index 0x4e), but the driver only accesses registers in bank 0. Since 180 + we don't switch banks, we don't need any special code to handle 181 + locking access between bank switches */ 182 + static inline int w83791d_read(struct i2c_client *client, u8 reg) 183 + { 184 + return i2c_smbus_read_byte_data(client, reg); 185 + } 186 + 187 + static inline int w83791d_write(struct i2c_client *client, u8 reg, u8 value) 188 + { 189 + return i2c_smbus_write_byte_data(client, reg, value); 190 + } 191 + 192 + /* The analog voltage inputs have 16mV LSB. Since the sysfs output is 193 + in mV as would be measured on the chip input pin, need to just 194 + multiply/divide by 16 to translate from/to register values. */ 195 + #define IN_TO_REG(val) (SENSORS_LIMIT((((val) + 8) / 16), 0, 255)) 196 + #define IN_FROM_REG(val) ((val) * 16) 197 + 198 + static u8 fan_to_reg(long rpm, int div) 199 + { 200 + if (rpm == 0) 201 + return 255; 202 + rpm = SENSORS_LIMIT(rpm, 1, 1000000); 203 + return SENSORS_LIMIT((1350000 + rpm * div / 2) / (rpm * div), 1, 254); 204 + } 205 + 206 + #define FAN_FROM_REG(val,div) ((val) == 0 ? -1 : \ 207 + ((val) == 255 ? 0 : \ 208 + 1350000 / ((val) * (div)))) 209 + 210 + /* for temp1 which is 8-bit resolution, LSB = 1 degree Celsius */ 211 + #define TEMP1_FROM_REG(val) ((val) * 1000) 212 + #define TEMP1_TO_REG(val) ((val) <= -128000 ? -128 : \ 213 + (val) >= 127000 ? 127 : \ 214 + (val) < 0 ? ((val) - 500) / 1000 : \ 215 + ((val) + 500) / 1000) 216 + 217 + /* for temp2 and temp3 which are 9-bit resolution, LSB = 0.5 degree Celsius 218 + Assumes the top 8 bits are the integral amount and the bottom 8 bits 219 + are the fractional amount. Since we only have 0.5 degree resolution, 220 + the bottom 7 bits will always be zero */ 221 + #define TEMP23_FROM_REG(val) ((val) / 128 * 500) 222 + #define TEMP23_TO_REG(val) ((val) <= -128000 ? 0x8000 : \ 223 + (val) >= 127500 ? 0x7F80 : \ 224 + (val) < 0 ? ((val) - 250) / 500 * 128 : \ 225 + ((val) + 250) / 500 * 128) 226 + 227 + 228 + #define BEEP_MASK_TO_REG(val) ((val) & 0xffffff) 229 + #define BEEP_MASK_FROM_REG(val) ((val) & 0xffffff) 230 + 231 + #define DIV_FROM_REG(val) (1 << (val)) 232 + 233 + static u8 div_to_reg(int nr, long val) 234 + { 235 + int i; 236 + int max; 237 + 238 + /* first three fan's divisor max out at 8, rest max out at 128 */ 239 + max = (nr < 3) ? 8 : 128; 240 + val = SENSORS_LIMIT(val, 1, max) >> 1; 241 + for (i = 0; i < 7; i++) { 242 + if (val == 0) 243 + break; 244 + val >>= 1; 245 + } 246 + return (u8) i; 247 + } 248 + 249 + struct w83791d_data { 250 + struct i2c_client client; 251 + struct class_device *class_dev; 252 + struct mutex update_lock; 253 + 254 + char valid; /* !=0 if following fields are valid */ 255 + unsigned long last_updated; /* In jiffies */ 256 + 257 + /* array of 2 pointers to subclients */ 258 + struct i2c_client *lm75[2]; 259 + 260 + /* volts */ 261 + u8 in[NUMBER_OF_VIN]; /* Register value */ 262 + u8 in_max[NUMBER_OF_VIN]; /* Register value */ 263 + u8 in_min[NUMBER_OF_VIN]; /* Register value */ 264 + 265 + /* fans */ 266 + u8 fan[NUMBER_OF_FANIN]; /* Register value */ 267 + u8 fan_min[NUMBER_OF_FANIN]; /* Register value */ 268 + u8 fan_div[NUMBER_OF_FANIN]; /* Register encoding, shifted right */ 269 + 270 + /* Temperature sensors */ 271 + 272 + s8 temp1[3]; /* current, over, thyst */ 273 + s16 temp_add[2][3]; /* fixed point value. Top 8 bits are the 274 + integral part, bottom 8 bits are the 275 + fractional part. We only use the top 276 + 9 bits as the resolution is only 277 + to the 0.5 degree C... 278 + two sensors with three values 279 + (cur, over, hyst) */ 280 + 281 + /* Misc */ 282 + u32 alarms; /* realtime status register encoding,combined */ 283 + u8 beep_enable; /* Global beep enable */ 284 + u32 beep_mask; /* Mask off specific beeps */ 285 + u8 vid; /* Register encoding, combined */ 286 + u8 vrm; /* hwmon-vid */ 287 + }; 288 + 289 + static int w83791d_attach_adapter(struct i2c_adapter *adapter); 290 + static int w83791d_detect(struct i2c_adapter *adapter, int address, int kind); 291 + static int w83791d_detach_client(struct i2c_client *client); 292 + 293 + static int w83791d_read(struct i2c_client *client, u8 register); 294 + static int w83791d_write(struct i2c_client *client, u8 register, u8 value); 295 + static struct w83791d_data *w83791d_update_device(struct device *dev); 296 + 297 + #ifdef DEBUG 298 + static void w83791d_print_debug(struct w83791d_data *data, struct device *dev); 299 + #endif 300 + 301 + static void w83791d_init_client(struct i2c_client *client); 302 + 303 + static struct i2c_driver w83791d_driver = { 304 + .driver = { 305 + .name = "w83791d", 306 + }, 307 + .attach_adapter = w83791d_attach_adapter, 308 + .detach_client = w83791d_detach_client, 309 + }; 310 + 311 + /* following are the sysfs callback functions */ 312 + #define show_in_reg(reg) \ 313 + static ssize_t show_##reg(struct device *dev, struct device_attribute *attr, \ 314 + char *buf) \ 315 + { \ 316 + struct sensor_device_attribute *sensor_attr = \ 317 + to_sensor_dev_attr(attr); \ 318 + struct w83791d_data *data = w83791d_update_device(dev); \ 319 + int nr = sensor_attr->index; \ 320 + return sprintf(buf,"%d\n", IN_FROM_REG(data->reg[nr])); \ 321 + } 322 + 323 + show_in_reg(in); 324 + show_in_reg(in_min); 325 + show_in_reg(in_max); 326 + 327 + #define store_in_reg(REG, reg) \ 328 + static ssize_t store_in_##reg(struct device *dev, \ 329 + struct device_attribute *attr, \ 330 + const char *buf, size_t count) \ 331 + { \ 332 + struct sensor_device_attribute *sensor_attr = \ 333 + to_sensor_dev_attr(attr); \ 334 + struct i2c_client *client = to_i2c_client(dev); \ 335 + struct w83791d_data *data = i2c_get_clientdata(client); \ 336 + unsigned long val = simple_strtoul(buf, NULL, 10); \ 337 + int nr = sensor_attr->index; \ 338 + \ 339 + mutex_lock(&data->update_lock); \ 340 + data->in_##reg[nr] = IN_TO_REG(val); \ 341 + w83791d_write(client, W83791D_REG_IN_##REG[nr], data->in_##reg[nr]); \ 342 + mutex_unlock(&data->update_lock); \ 343 + \ 344 + return count; \ 345 + } 346 + store_in_reg(MIN, min); 347 + store_in_reg(MAX, max); 348 + 349 + static struct sensor_device_attribute sda_in_input[] = { 350 + SENSOR_ATTR(in0_input, S_IRUGO, show_in, NULL, 0), 351 + SENSOR_ATTR(in1_input, S_IRUGO, show_in, NULL, 1), 352 + SENSOR_ATTR(in2_input, S_IRUGO, show_in, NULL, 2), 353 + SENSOR_ATTR(in3_input, S_IRUGO, show_in, NULL, 3), 354 + SENSOR_ATTR(in4_input, S_IRUGO, show_in, NULL, 4), 355 + SENSOR_ATTR(in5_input, S_IRUGO, show_in, NULL, 5), 356 + SENSOR_ATTR(in6_input, S_IRUGO, show_in, NULL, 6), 357 + SENSOR_ATTR(in7_input, S_IRUGO, show_in, NULL, 7), 358 + SENSOR_ATTR(in8_input, S_IRUGO, show_in, NULL, 8), 359 + SENSOR_ATTR(in9_input, S_IRUGO, show_in, NULL, 9), 360 + }; 361 + 362 + static struct sensor_device_attribute sda_in_min[] = { 363 + SENSOR_ATTR(in0_min, S_IWUSR | S_IRUGO, show_in_min, store_in_min, 0), 364 + SENSOR_ATTR(in1_min, S_IWUSR | S_IRUGO, show_in_min, store_in_min, 1), 365 + SENSOR_ATTR(in2_min, S_IWUSR | S_IRUGO, show_in_min, store_in_min, 2), 366 + SENSOR_ATTR(in3_min, S_IWUSR | S_IRUGO, show_in_min, store_in_min, 3), 367 + SENSOR_ATTR(in4_min, S_IWUSR | S_IRUGO, show_in_min, store_in_min, 4), 368 + SENSOR_ATTR(in5_min, S_IWUSR | S_IRUGO, show_in_min, store_in_min, 5), 369 + SENSOR_ATTR(in6_min, S_IWUSR | S_IRUGO, show_in_min, store_in_min, 6), 370 + SENSOR_ATTR(in7_min, S_IWUSR | S_IRUGO, show_in_min, store_in_min, 7), 371 + SENSOR_ATTR(in8_min, S_IWUSR | S_IRUGO, show_in_min, store_in_min, 8), 372 + SENSOR_ATTR(in9_min, S_IWUSR | S_IRUGO, show_in_min, store_in_min, 9), 373 + }; 374 + 375 + static struct sensor_device_attribute sda_in_max[] = { 376 + SENSOR_ATTR(in0_max, S_IWUSR | S_IRUGO, show_in_max, store_in_max, 0), 377 + SENSOR_ATTR(in1_max, S_IWUSR | S_IRUGO, show_in_max, store_in_max, 1), 378 + SENSOR_ATTR(in2_max, S_IWUSR | S_IRUGO, show_in_max, store_in_max, 2), 379 + SENSOR_ATTR(in3_max, S_IWUSR | S_IRUGO, show_in_max, store_in_max, 3), 380 + SENSOR_ATTR(in4_max, S_IWUSR | S_IRUGO, show_in_max, store_in_max, 4), 381 + SENSOR_ATTR(in5_max, S_IWUSR | S_IRUGO, show_in_max, store_in_max, 5), 382 + SENSOR_ATTR(in6_max, S_IWUSR | S_IRUGO, show_in_max, store_in_max, 6), 383 + SENSOR_ATTR(in7_max, S_IWUSR | S_IRUGO, show_in_max, store_in_max, 7), 384 + SENSOR_ATTR(in8_max, S_IWUSR | S_IRUGO, show_in_max, store_in_max, 8), 385 + SENSOR_ATTR(in9_max, S_IWUSR | S_IRUGO, show_in_max, store_in_max, 9), 386 + }; 387 + 388 + #define show_fan_reg(reg) \ 389 + static ssize_t show_##reg(struct device *dev, struct device_attribute *attr, \ 390 + char *buf) \ 391 + { \ 392 + struct sensor_device_attribute *sensor_attr = \ 393 + to_sensor_dev_attr(attr); \ 394 + struct w83791d_data *data = w83791d_update_device(dev); \ 395 + int nr = sensor_attr->index; \ 396 + return sprintf(buf,"%d\n", \ 397 + FAN_FROM_REG(data->reg[nr], DIV_FROM_REG(data->fan_div[nr]))); \ 398 + } 399 + 400 + show_fan_reg(fan); 401 + show_fan_reg(fan_min); 402 + 403 + static ssize_t store_fan_min(struct device *dev, struct device_attribute *attr, 404 + const char *buf, size_t count) 405 + { 406 + struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); 407 + struct i2c_client *client = to_i2c_client(dev); 408 + struct w83791d_data *data = i2c_get_clientdata(client); 409 + unsigned long val = simple_strtoul(buf, NULL, 10); 410 + int nr = sensor_attr->index; 411 + 412 + mutex_lock(&data->update_lock); 413 + data->fan_min[nr] = fan_to_reg(val, DIV_FROM_REG(data->fan_div[nr])); 414 + w83791d_write(client, W83791D_REG_FAN_MIN[nr], data->fan_min[nr]); 415 + mutex_unlock(&data->update_lock); 416 + 417 + return count; 418 + } 419 + 420 + static ssize_t show_fan_div(struct device *dev, struct device_attribute *attr, 421 + char *buf) 422 + { 423 + struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); 424 + int nr = sensor_attr->index; 425 + struct w83791d_data *data = w83791d_update_device(dev); 426 + return sprintf(buf, "%u\n", DIV_FROM_REG(data->fan_div[nr])); 427 + } 428 + 429 + /* Note: we save and restore the fan minimum here, because its value is 430 + determined in part by the fan divisor. This follows the principle of 431 + least suprise; the user doesn't expect the fan minimum to change just 432 + because the divisor changed. */ 433 + static ssize_t store_fan_div(struct device *dev, struct device_attribute *attr, 434 + const char *buf, size_t count) 435 + { 436 + struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); 437 + struct i2c_client *client = to_i2c_client(dev); 438 + struct w83791d_data *data = i2c_get_clientdata(client); 439 + int nr = sensor_attr->index; 440 + unsigned long min; 441 + u8 tmp_fan_div; 442 + u8 fan_div_reg; 443 + int indx = 0; 444 + u8 keep_mask = 0; 445 + u8 new_shift = 0; 446 + 447 + /* Save fan_min */ 448 + min = FAN_FROM_REG(data->fan_min[nr], DIV_FROM_REG(data->fan_div[nr])); 449 + 450 + mutex_lock(&data->update_lock); 451 + data->fan_div[nr] = div_to_reg(nr, simple_strtoul(buf, NULL, 10)); 452 + 453 + switch (nr) { 454 + case 0: 455 + indx = 0; 456 + keep_mask = 0xcf; 457 + new_shift = 4; 458 + break; 459 + case 1: 460 + indx = 0; 461 + keep_mask = 0x3f; 462 + new_shift = 6; 463 + break; 464 + case 2: 465 + indx = 1; 466 + keep_mask = 0x3f; 467 + new_shift = 6; 468 + break; 469 + case 3: 470 + indx = 2; 471 + keep_mask = 0xf8; 472 + new_shift = 0; 473 + break; 474 + case 4: 475 + indx = 2; 476 + keep_mask = 0x8f; 477 + new_shift = 4; 478 + break; 479 + #ifdef DEBUG 480 + default: 481 + dev_warn(dev, "store_fan_div: Unexpected nr seen: %d\n", nr); 482 + count = -EINVAL; 483 + goto err_exit; 484 + #endif 485 + } 486 + 487 + fan_div_reg = w83791d_read(client, W83791D_REG_FAN_DIV[indx]) 488 + & keep_mask; 489 + tmp_fan_div = (data->fan_div[nr] << new_shift) & ~keep_mask; 490 + 491 + w83791d_write(client, W83791D_REG_FAN_DIV[indx], 492 + fan_div_reg | tmp_fan_div); 493 + 494 + /* Restore fan_min */ 495 + data->fan_min[nr] = fan_to_reg(min, DIV_FROM_REG(data->fan_div[nr])); 496 + w83791d_write(client, W83791D_REG_FAN_MIN[nr], data->fan_min[nr]); 497 + 498 + #ifdef DEBUG 499 + err_exit: 500 + #endif 501 + mutex_unlock(&data->update_lock); 502 + 503 + return count; 504 + } 505 + 506 + static struct sensor_device_attribute sda_fan_input[] = { 507 + SENSOR_ATTR(fan1_input, S_IRUGO, show_fan, NULL, 0), 508 + SENSOR_ATTR(fan2_input, S_IRUGO, show_fan, NULL, 1), 509 + SENSOR_ATTR(fan3_input, S_IRUGO, show_fan, NULL, 2), 510 + SENSOR_ATTR(fan4_input, S_IRUGO, show_fan, NULL, 3), 511 + SENSOR_ATTR(fan5_input, S_IRUGO, show_fan, NULL, 4), 512 + }; 513 + 514 + static struct sensor_device_attribute sda_fan_min[] = { 515 + SENSOR_ATTR(fan1_min, S_IWUSR | S_IRUGO, 516 + show_fan_min, store_fan_min, 0), 517 + SENSOR_ATTR(fan2_min, S_IWUSR | S_IRUGO, 518 + show_fan_min, store_fan_min, 1), 519 + SENSOR_ATTR(fan3_min, S_IWUSR | S_IRUGO, 520 + show_fan_min, store_fan_min, 2), 521 + SENSOR_ATTR(fan4_min, S_IWUSR | S_IRUGO, 522 + show_fan_min, store_fan_min, 3), 523 + SENSOR_ATTR(fan5_min, S_IWUSR | S_IRUGO, 524 + show_fan_min, store_fan_min, 4), 525 + }; 526 + 527 + static struct sensor_device_attribute sda_fan_div[] = { 528 + SENSOR_ATTR(fan1_div, S_IWUSR | S_IRUGO, 529 + show_fan_div, store_fan_div, 0), 530 + SENSOR_ATTR(fan2_div, S_IWUSR | S_IRUGO, 531 + show_fan_div, store_fan_div, 1), 532 + SENSOR_ATTR(fan3_div, S_IWUSR | S_IRUGO, 533 + show_fan_div, store_fan_div, 2), 534 + SENSOR_ATTR(fan4_div, S_IWUSR | S_IRUGO, 535 + show_fan_div, store_fan_div, 3), 536 + SENSOR_ATTR(fan5_div, S_IWUSR | S_IRUGO, 537 + show_fan_div, store_fan_div, 4), 538 + }; 539 + 540 + /* read/write the temperature1, includes measured value and limits */ 541 + static ssize_t show_temp1(struct device *dev, struct device_attribute *devattr, 542 + char *buf) 543 + { 544 + struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); 545 + struct w83791d_data *data = w83791d_update_device(dev); 546 + return sprintf(buf, "%d\n", TEMP1_FROM_REG(data->temp1[attr->index])); 547 + } 548 + 549 + static ssize_t store_temp1(struct device *dev, struct device_attribute *devattr, 550 + const char *buf, size_t count) 551 + { 552 + struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); 553 + struct i2c_client *client = to_i2c_client(dev); 554 + struct w83791d_data *data = i2c_get_clientdata(client); 555 + long val = simple_strtol(buf, NULL, 10); 556 + int nr = attr->index; 557 + 558 + mutex_lock(&data->update_lock); 559 + data->temp1[nr] = TEMP1_TO_REG(val); 560 + w83791d_write(client, W83791D_REG_TEMP1[nr], data->temp1[nr]); 561 + mutex_unlock(&data->update_lock); 562 + return count; 563 + } 564 + 565 + /* read/write temperature2-3, includes measured value and limits */ 566 + static ssize_t show_temp23(struct device *dev, struct device_attribute *devattr, 567 + char *buf) 568 + { 569 + struct sensor_device_attribute_2 *attr = to_sensor_dev_attr_2(devattr); 570 + struct w83791d_data *data = w83791d_update_device(dev); 571 + int nr = attr->nr; 572 + int index = attr->index; 573 + return sprintf(buf, "%d\n", TEMP23_FROM_REG(data->temp_add[nr][index])); 574 + } 575 + 576 + static ssize_t store_temp23(struct device *dev, 577 + struct device_attribute *devattr, 578 + const char *buf, size_t count) 579 + { 580 + struct sensor_device_attribute_2 *attr = to_sensor_dev_attr_2(devattr); 581 + struct i2c_client *client = to_i2c_client(dev); 582 + struct w83791d_data *data = i2c_get_clientdata(client); 583 + long val = simple_strtol(buf, NULL, 10); 584 + int nr = attr->nr; 585 + int index = attr->index; 586 + 587 + mutex_lock(&data->update_lock); 588 + data->temp_add[nr][index] = TEMP23_TO_REG(val); 589 + w83791d_write(client, W83791D_REG_TEMP_ADD[nr][index * 2], 590 + data->temp_add[nr][index] >> 8); 591 + w83791d_write(client, W83791D_REG_TEMP_ADD[nr][index * 2 + 1], 592 + data->temp_add[nr][index] & 0x80); 593 + mutex_unlock(&data->update_lock); 594 + 595 + return count; 596 + } 597 + 598 + static struct sensor_device_attribute_2 sda_temp_input[] = { 599 + SENSOR_ATTR_2(temp1_input, S_IRUGO, show_temp1, NULL, 0, 0), 600 + SENSOR_ATTR_2(temp2_input, S_IRUGO, show_temp23, NULL, 0, 0), 601 + SENSOR_ATTR_2(temp3_input, S_IRUGO, show_temp23, NULL, 1, 0), 602 + }; 603 + 604 + static struct sensor_device_attribute_2 sda_temp_max[] = { 605 + SENSOR_ATTR_2(temp1_max, S_IRUGO | S_IWUSR, 606 + show_temp1, store_temp1, 0, 1), 607 + SENSOR_ATTR_2(temp2_max, S_IRUGO | S_IWUSR, 608 + show_temp23, store_temp23, 0, 1), 609 + SENSOR_ATTR_2(temp3_max, S_IRUGO | S_IWUSR, 610 + show_temp23, store_temp23, 1, 1), 611 + }; 612 + 613 + static struct sensor_device_attribute_2 sda_temp_max_hyst[] = { 614 + SENSOR_ATTR_2(temp1_max_hyst, S_IRUGO | S_IWUSR, 615 + show_temp1, store_temp1, 0, 2), 616 + SENSOR_ATTR_2(temp2_max_hyst, S_IRUGO | S_IWUSR, 617 + show_temp23, store_temp23, 0, 2), 618 + SENSOR_ATTR_2(temp3_max_hyst, S_IRUGO | S_IWUSR, 619 + show_temp23, store_temp23, 1, 2), 620 + }; 621 + 622 + 623 + /* get reatime status of all sensors items: voltage, temp, fan */ 624 + static ssize_t show_alarms_reg(struct device *dev, 625 + struct device_attribute *attr, char *buf) 626 + { 627 + struct w83791d_data *data = w83791d_update_device(dev); 628 + return sprintf(buf, "%u\n", data->alarms); 629 + } 630 + 631 + static DEVICE_ATTR(alarms, S_IRUGO, show_alarms_reg, NULL); 632 + 633 + /* Beep control */ 634 + 635 + #define GLOBAL_BEEP_ENABLE_SHIFT 15 636 + #define GLOBAL_BEEP_ENABLE_MASK (1 << GLOBAL_BEEP_ENABLE_SHIFT) 637 + 638 + static ssize_t show_beep_enable(struct device *dev, 639 + struct device_attribute *attr, char *buf) 640 + { 641 + struct w83791d_data *data = w83791d_update_device(dev); 642 + return sprintf(buf, "%d\n", data->beep_enable); 643 + } 644 + 645 + static ssize_t show_beep_mask(struct device *dev, 646 + struct device_attribute *attr, char *buf) 647 + { 648 + struct w83791d_data *data = w83791d_update_device(dev); 649 + return sprintf(buf, "%d\n", BEEP_MASK_FROM_REG(data->beep_mask)); 650 + } 651 + 652 + 653 + static ssize_t store_beep_mask(struct device *dev, 654 + struct device_attribute *attr, 655 + const char *buf, size_t count) 656 + { 657 + struct i2c_client *client = to_i2c_client(dev); 658 + struct w83791d_data *data = i2c_get_clientdata(client); 659 + long val = simple_strtol(buf, NULL, 10); 660 + int i; 661 + 662 + mutex_lock(&data->update_lock); 663 + 664 + /* The beep_enable state overrides any enabling request from 665 + the masks */ 666 + data->beep_mask = BEEP_MASK_TO_REG(val) & ~GLOBAL_BEEP_ENABLE_MASK; 667 + data->beep_mask |= (data->beep_enable << GLOBAL_BEEP_ENABLE_SHIFT); 668 + 669 + val = data->beep_mask; 670 + 671 + for (i = 0; i < 3; i++) { 672 + w83791d_write(client, W83791D_REG_BEEP_CTRL[i], (val & 0xff)); 673 + val >>= 8; 674 + } 675 + 676 + mutex_unlock(&data->update_lock); 677 + 678 + return count; 679 + } 680 + 681 + static ssize_t store_beep_enable(struct device *dev, 682 + struct device_attribute *attr, 683 + const char *buf, size_t count) 684 + { 685 + struct i2c_client *client = to_i2c_client(dev); 686 + struct w83791d_data *data = i2c_get_clientdata(client); 687 + long val = simple_strtol(buf, NULL, 10); 688 + 689 + mutex_lock(&data->update_lock); 690 + 691 + data->beep_enable = val ? 1 : 0; 692 + 693 + /* Keep the full mask value in sync with the current enable */ 694 + data->beep_mask &= ~GLOBAL_BEEP_ENABLE_MASK; 695 + data->beep_mask |= (data->beep_enable << GLOBAL_BEEP_ENABLE_SHIFT); 696 + 697 + /* The global control is in the second beep control register 698 + so only need to update that register */ 699 + val = (data->beep_mask >> 8) & 0xff; 700 + 701 + w83791d_write(client, W83791D_REG_BEEP_CTRL[1], val); 702 + 703 + mutex_unlock(&data->update_lock); 704 + 705 + return count; 706 + } 707 + 708 + static struct sensor_device_attribute sda_beep_ctrl[] = { 709 + SENSOR_ATTR(beep_enable, S_IRUGO | S_IWUSR, 710 + show_beep_enable, store_beep_enable, 0), 711 + SENSOR_ATTR(beep_mask, S_IRUGO | S_IWUSR, 712 + show_beep_mask, store_beep_mask, 1) 713 + }; 714 + 715 + /* cpu voltage regulation information */ 716 + static ssize_t show_vid_reg(struct device *dev, 717 + struct device_attribute *attr, char *buf) 718 + { 719 + struct w83791d_data *data = w83791d_update_device(dev); 720 + return sprintf(buf, "%d\n", vid_from_reg(data->vid, data->vrm)); 721 + } 722 + 723 + static DEVICE_ATTR(cpu0_vid, S_IRUGO, show_vid_reg, NULL); 724 + 725 + static ssize_t show_vrm_reg(struct device *dev, 726 + struct device_attribute *attr, char *buf) 727 + { 728 + struct w83791d_data *data = w83791d_update_device(dev); 729 + return sprintf(buf, "%d\n", data->vrm); 730 + } 731 + 732 + static ssize_t store_vrm_reg(struct device *dev, 733 + struct device_attribute *attr, 734 + const char *buf, size_t count) 735 + { 736 + struct i2c_client *client = to_i2c_client(dev); 737 + struct w83791d_data *data = i2c_get_clientdata(client); 738 + unsigned long val = simple_strtoul(buf, NULL, 10); 739 + 740 + /* No lock needed as vrm is internal to the driver 741 + (not read from a chip register) and so is not 742 + updated in w83791d_update_device() */ 743 + data->vrm = val; 744 + 745 + return count; 746 + } 747 + 748 + static DEVICE_ATTR(vrm, S_IRUGO | S_IWUSR, show_vrm_reg, store_vrm_reg); 749 + 750 + /* This function is called when: 751 + * w83791d_driver is inserted (when this module is loaded), for each 752 + available adapter 753 + * when a new adapter is inserted (and w83791d_driver is still present) */ 754 + static int w83791d_attach_adapter(struct i2c_adapter *adapter) 755 + { 756 + if (!(adapter->class & I2C_CLASS_HWMON)) 757 + return 0; 758 + return i2c_probe(adapter, &addr_data, w83791d_detect); 759 + } 760 + 761 + 762 + static int w83791d_create_subclient(struct i2c_adapter *adapter, 763 + struct i2c_client *client, int addr, 764 + struct i2c_client **sub_cli) 765 + { 766 + int err; 767 + struct i2c_client *sub_client; 768 + 769 + (*sub_cli) = sub_client = 770 + kzalloc(sizeof(struct i2c_client), GFP_KERNEL); 771 + if (!(sub_client)) { 772 + return -ENOMEM; 773 + } 774 + sub_client->addr = 0x48 + addr; 775 + i2c_set_clientdata(sub_client, NULL); 776 + sub_client->adapter = adapter; 777 + sub_client->driver = &w83791d_driver; 778 + strlcpy(sub_client->name, "w83791d subclient", I2C_NAME_SIZE); 779 + if ((err = i2c_attach_client(sub_client))) { 780 + dev_err(&client->dev, "subclient registration " 781 + "at address 0x%x failed\n", sub_client->addr); 782 + kfree(sub_client); 783 + return err; 784 + } 785 + return 0; 786 + } 787 + 788 + 789 + static int w83791d_detect_subclients(struct i2c_adapter *adapter, int address, 790 + int kind, struct i2c_client *client) 791 + { 792 + struct w83791d_data *data = i2c_get_clientdata(client); 793 + int i, id, err; 794 + u8 val; 795 + 796 + id = i2c_adapter_id(adapter); 797 + if (force_subclients[0] == id && force_subclients[1] == address) { 798 + for (i = 2; i <= 3; i++) { 799 + if (force_subclients[i] < 0x48 || 800 + force_subclients[i] > 0x4f) { 801 + dev_err(&client->dev, 802 + "invalid subclient " 803 + "address %d; must be 0x48-0x4f\n", 804 + force_subclients[i]); 805 + err = -ENODEV; 806 + goto error_sc_0; 807 + } 808 + } 809 + w83791d_write(client, W83791D_REG_I2C_SUBADDR, 810 + (force_subclients[2] & 0x07) | 811 + ((force_subclients[3] & 0x07) << 4)); 812 + } 813 + 814 + val = w83791d_read(client, W83791D_REG_I2C_SUBADDR); 815 + if (!(val & 0x08)) { 816 + err = w83791d_create_subclient(adapter, client, 817 + val & 0x7, &data->lm75[0]); 818 + if (err < 0) 819 + goto error_sc_0; 820 + } 821 + if (!(val & 0x80)) { 822 + if ((data->lm75[0] != NULL) && 823 + ((val & 0x7) == ((val >> 4) & 0x7))) { 824 + dev_err(&client->dev, 825 + "duplicate addresses 0x%x, " 826 + "use force_subclient\n", 827 + data->lm75[0]->addr); 828 + err = -ENODEV; 829 + goto error_sc_1; 830 + } 831 + err = w83791d_create_subclient(adapter, client, 832 + (val >> 4) & 0x7, &data->lm75[1]); 833 + if (err < 0) 834 + goto error_sc_1; 835 + } 836 + 837 + return 0; 838 + 839 + /* Undo inits in case of errors */ 840 + 841 + error_sc_1: 842 + if (data->lm75[0] != NULL) { 843 + i2c_detach_client(data->lm75[0]); 844 + kfree(data->lm75[0]); 845 + } 846 + error_sc_0: 847 + return err; 848 + } 849 + 850 + 851 + static int w83791d_detect(struct i2c_adapter *adapter, int address, int kind) 852 + { 853 + struct i2c_client *client; 854 + struct device *dev; 855 + struct w83791d_data *data; 856 + int i, val1, val2; 857 + int err = 0; 858 + const char *client_name = ""; 859 + 860 + if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) { 861 + goto error0; 862 + } 863 + 864 + /* OK. For now, we presume we have a valid client. We now create the 865 + client structure, even though we cannot fill it completely yet. 866 + But it allows us to access w83791d_{read,write}_value. */ 867 + if (!(data = kzalloc(sizeof(struct w83791d_data), GFP_KERNEL))) { 868 + err = -ENOMEM; 869 + goto error0; 870 + } 871 + 872 + client = &data->client; 873 + dev = &client->dev; 874 + i2c_set_clientdata(client, data); 875 + client->addr = address; 876 + client->adapter = adapter; 877 + client->driver = &w83791d_driver; 878 + mutex_init(&data->update_lock); 879 + 880 + /* Now, we do the remaining detection. */ 881 + 882 + /* The w83791d may be stuck in some other bank than bank 0. This may 883 + make reading other information impossible. Specify a force=... 884 + parameter, and the Winbond will be reset to the right bank. */ 885 + if (kind < 0) { 886 + if (w83791d_read(client, W83791D_REG_CONFIG) & 0x80) { 887 + dev_dbg(dev, "Detection failed at step 1\n"); 888 + goto error1; 889 + } 890 + val1 = w83791d_read(client, W83791D_REG_BANK); 891 + val2 = w83791d_read(client, W83791D_REG_CHIPMAN); 892 + /* Check for Winbond ID if in bank 0 */ 893 + if (!(val1 & 0x07)) { 894 + /* yes it is Bank0 */ 895 + if (((!(val1 & 0x80)) && (val2 != 0xa3)) || 896 + ((val1 & 0x80) && (val2 != 0x5c))) { 897 + dev_dbg(dev, "Detection failed at step 2\n"); 898 + goto error1; 899 + } 900 + } 901 + /* If Winbond chip, address of chip and W83791D_REG_I2C_ADDR 902 + should match */ 903 + if (w83791d_read(client, W83791D_REG_I2C_ADDR) != address) { 904 + dev_dbg(dev, "Detection failed at step 3\n"); 905 + goto error1; 906 + } 907 + } 908 + 909 + /* We either have a force parameter or we have reason to 910 + believe it is a Winbond chip. Either way, we want bank 0 and 911 + Vendor ID high byte */ 912 + val1 = w83791d_read(client, W83791D_REG_BANK) & 0x78; 913 + w83791d_write(client, W83791D_REG_BANK, val1 | 0x80); 914 + 915 + /* Verify it is a Winbond w83791d */ 916 + if (kind <= 0) { 917 + /* get vendor ID */ 918 + val2 = w83791d_read(client, W83791D_REG_CHIPMAN); 919 + if (val2 != 0x5c) { /* the vendor is NOT Winbond */ 920 + dev_dbg(dev, "Detection failed at step 4\n"); 921 + goto error1; 922 + } 923 + val1 = w83791d_read(client, W83791D_REG_WCHIPID); 924 + if (val1 == 0x71) { 925 + kind = w83791d; 926 + } else { 927 + if (kind == 0) 928 + dev_warn(dev, 929 + "w83791d: Ignoring 'force' parameter " 930 + "for unknown chip at adapter %d, " 931 + "address 0x%02x\n", 932 + i2c_adapter_id(adapter), address); 933 + goto error1; 934 + } 935 + } 936 + 937 + if (kind == w83791d) { 938 + client_name = "w83791d"; 939 + } else { 940 + dev_err(dev, "w83791d: Internal error: unknown kind (%d)?!?", 941 + kind); 942 + goto error1; 943 + } 944 + 945 + #ifdef DEBUG 946 + val1 = w83791d_read(client, W83791D_REG_DID_VID4); 947 + dev_dbg(dev, "Device ID version: %d.%d (0x%02x)\n", 948 + (val1 >> 5) & 0x07, (val1 >> 1) & 0x0f, val1); 949 + #endif 950 + 951 + /* Fill in the remaining client fields and put into the global list */ 952 + strlcpy(client->name, client_name, I2C_NAME_SIZE); 953 + 954 + /* Tell the I2C layer a new client has arrived */ 955 + if ((err = i2c_attach_client(client))) 956 + goto error1; 957 + 958 + if ((err = w83791d_detect_subclients(adapter, address, kind, client))) 959 + goto error2; 960 + 961 + /* Initialize the chip */ 962 + w83791d_init_client(client); 963 + 964 + /* If the fan_div is changed, make sure there is a rational 965 + fan_min in place */ 966 + for (i = 0; i < NUMBER_OF_FANIN; i++) { 967 + data->fan_min[i] = w83791d_read(client, W83791D_REG_FAN_MIN[i]); 968 + } 969 + 970 + /* Register sysfs hooks */ 971 + data->class_dev = hwmon_device_register(dev); 972 + if (IS_ERR(data->class_dev)) { 973 + err = PTR_ERR(data->class_dev); 974 + goto error3; 975 + } 976 + 977 + for (i = 0; i < NUMBER_OF_VIN; i++) { 978 + device_create_file(dev, &sda_in_input[i].dev_attr); 979 + device_create_file(dev, &sda_in_min[i].dev_attr); 980 + device_create_file(dev, &sda_in_max[i].dev_attr); 981 + } 982 + 983 + for (i = 0; i < NUMBER_OF_FANIN; i++) { 984 + device_create_file(dev, &sda_fan_input[i].dev_attr); 985 + device_create_file(dev, &sda_fan_div[i].dev_attr); 986 + device_create_file(dev, &sda_fan_min[i].dev_attr); 987 + } 988 + 989 + for (i = 0; i < NUMBER_OF_TEMPIN; i++) { 990 + device_create_file(dev, &sda_temp_input[i].dev_attr); 991 + device_create_file(dev, &sda_temp_max[i].dev_attr); 992 + device_create_file(dev, &sda_temp_max_hyst[i].dev_attr); 993 + } 994 + 995 + device_create_file(dev, &dev_attr_alarms); 996 + 997 + for (i = 0; i < ARRAY_SIZE(sda_beep_ctrl); i++) { 998 + device_create_file(dev, &sda_beep_ctrl[i].dev_attr); 999 + } 1000 + 1001 + device_create_file(dev, &dev_attr_cpu0_vid); 1002 + device_create_file(dev, &dev_attr_vrm); 1003 + 1004 + return 0; 1005 + 1006 + error3: 1007 + if (data->lm75[0] != NULL) { 1008 + i2c_detach_client(data->lm75[0]); 1009 + kfree(data->lm75[0]); 1010 + } 1011 + if (data->lm75[1] != NULL) { 1012 + i2c_detach_client(data->lm75[1]); 1013 + kfree(data->lm75[1]); 1014 + } 1015 + error2: 1016 + i2c_detach_client(client); 1017 + error1: 1018 + kfree(data); 1019 + error0: 1020 + return err; 1021 + } 1022 + 1023 + static int w83791d_detach_client(struct i2c_client *client) 1024 + { 1025 + struct w83791d_data *data = i2c_get_clientdata(client); 1026 + int err; 1027 + 1028 + /* main client */ 1029 + if (data) 1030 + hwmon_device_unregister(data->class_dev); 1031 + 1032 + if ((err = i2c_detach_client(client))) 1033 + return err; 1034 + 1035 + /* main client */ 1036 + if (data) 1037 + kfree(data); 1038 + /* subclient */ 1039 + else 1040 + kfree(client); 1041 + 1042 + return 0; 1043 + } 1044 + 1045 + static void w83791d_init_client(struct i2c_client *client) 1046 + { 1047 + struct w83791d_data *data = i2c_get_clientdata(client); 1048 + u8 tmp; 1049 + u8 old_beep; 1050 + 1051 + /* The difference between reset and init is that reset 1052 + does a hard reset of the chip via index 0x40, bit 7, 1053 + but init simply forces certain registers to have "sane" 1054 + values. The hope is that the BIOS has done the right 1055 + thing (which is why the default is reset=0, init=0), 1056 + but if not, reset is the hard hammer and init 1057 + is the soft mallet both of which are trying to whack 1058 + things into place... 1059 + NOTE: The data sheet makes a distinction between 1060 + "power on defaults" and "reset by MR". As far as I can tell, 1061 + the hard reset puts everything into a power-on state so I'm 1062 + not sure what "reset by MR" means or how it can happen. 1063 + */ 1064 + if (reset || init) { 1065 + /* keep some BIOS settings when we... */ 1066 + old_beep = w83791d_read(client, W83791D_REG_BEEP_CONFIG); 1067 + 1068 + if (reset) { 1069 + /* ... reset the chip and ... */ 1070 + w83791d_write(client, W83791D_REG_CONFIG, 0x80); 1071 + } 1072 + 1073 + /* ... disable power-on abnormal beep */ 1074 + w83791d_write(client, W83791D_REG_BEEP_CONFIG, old_beep | 0x80); 1075 + 1076 + /* disable the global beep (not done by hard reset) */ 1077 + tmp = w83791d_read(client, W83791D_REG_BEEP_CTRL[1]); 1078 + w83791d_write(client, W83791D_REG_BEEP_CTRL[1], tmp & 0xef); 1079 + 1080 + if (init) { 1081 + /* Make sure monitoring is turned on for add-ons */ 1082 + tmp = w83791d_read(client, W83791D_REG_TEMP2_CONFIG); 1083 + if (tmp & 1) { 1084 + w83791d_write(client, W83791D_REG_TEMP2_CONFIG, 1085 + tmp & 0xfe); 1086 + } 1087 + 1088 + tmp = w83791d_read(client, W83791D_REG_TEMP3_CONFIG); 1089 + if (tmp & 1) { 1090 + w83791d_write(client, W83791D_REG_TEMP3_CONFIG, 1091 + tmp & 0xfe); 1092 + } 1093 + 1094 + /* Start monitoring */ 1095 + tmp = w83791d_read(client, W83791D_REG_CONFIG) & 0xf7; 1096 + w83791d_write(client, W83791D_REG_CONFIG, tmp | 0x01); 1097 + } 1098 + } 1099 + 1100 + data->vrm = vid_which_vrm(); 1101 + } 1102 + 1103 + static struct w83791d_data *w83791d_update_device(struct device *dev) 1104 + { 1105 + struct i2c_client *client = to_i2c_client(dev); 1106 + struct w83791d_data *data = i2c_get_clientdata(client); 1107 + int i, j; 1108 + u8 reg_array_tmp[3]; 1109 + 1110 + mutex_lock(&data->update_lock); 1111 + 1112 + if (time_after(jiffies, data->last_updated + (HZ * 3)) 1113 + || !data->valid) { 1114 + dev_dbg(dev, "Starting w83791d device update\n"); 1115 + 1116 + /* Update the voltages measured value and limits */ 1117 + for (i = 0; i < NUMBER_OF_VIN; i++) { 1118 + data->in[i] = w83791d_read(client, 1119 + W83791D_REG_IN[i]); 1120 + data->in_max[i] = w83791d_read(client, 1121 + W83791D_REG_IN_MAX[i]); 1122 + data->in_min[i] = w83791d_read(client, 1123 + W83791D_REG_IN_MIN[i]); 1124 + } 1125 + 1126 + /* Update the fan counts and limits */ 1127 + for (i = 0; i < NUMBER_OF_FANIN; i++) { 1128 + /* Update the Fan measured value and limits */ 1129 + data->fan[i] = w83791d_read(client, 1130 + W83791D_REG_FAN[i]); 1131 + data->fan_min[i] = w83791d_read(client, 1132 + W83791D_REG_FAN_MIN[i]); 1133 + } 1134 + 1135 + /* Update the fan divisor */ 1136 + for (i = 0; i < 3; i++) { 1137 + reg_array_tmp[i] = w83791d_read(client, 1138 + W83791D_REG_FAN_DIV[i]); 1139 + } 1140 + data->fan_div[0] = (reg_array_tmp[0] >> 4) & 0x03; 1141 + data->fan_div[1] = (reg_array_tmp[0] >> 6) & 0x03; 1142 + data->fan_div[2] = (reg_array_tmp[1] >> 6) & 0x03; 1143 + data->fan_div[3] = reg_array_tmp[2] & 0x07; 1144 + data->fan_div[4] = (reg_array_tmp[2] >> 4) & 0x07; 1145 + 1146 + /* Update the first temperature sensor */ 1147 + for (i = 0; i < 3; i++) { 1148 + data->temp1[i] = w83791d_read(client, 1149 + W83791D_REG_TEMP1[i]); 1150 + } 1151 + 1152 + /* Update the rest of the temperature sensors */ 1153 + for (i = 0; i < 2; i++) { 1154 + for (j = 0; j < 3; j++) { 1155 + data->temp_add[i][j] = 1156 + (w83791d_read(client, 1157 + W83791D_REG_TEMP_ADD[i][j * 2]) << 8) | 1158 + w83791d_read(client, 1159 + W83791D_REG_TEMP_ADD[i][j * 2 + 1]); 1160 + } 1161 + } 1162 + 1163 + /* Update the realtime status */ 1164 + data->alarms = 1165 + w83791d_read(client, W83791D_REG_ALARM1) + 1166 + (w83791d_read(client, W83791D_REG_ALARM2) << 8) + 1167 + (w83791d_read(client, W83791D_REG_ALARM3) << 16); 1168 + 1169 + /* Update the beep configuration information */ 1170 + data->beep_mask = 1171 + w83791d_read(client, W83791D_REG_BEEP_CTRL[0]) + 1172 + (w83791d_read(client, W83791D_REG_BEEP_CTRL[1]) << 8) + 1173 + (w83791d_read(client, W83791D_REG_BEEP_CTRL[2]) << 16); 1174 + 1175 + data->beep_enable = 1176 + (data->beep_mask >> GLOBAL_BEEP_ENABLE_SHIFT) & 0x01; 1177 + 1178 + /* Update the cpu voltage information */ 1179 + i = w83791d_read(client, W83791D_REG_VID_FANDIV); 1180 + data->vid = i & 0x0f; 1181 + data->vid |= (w83791d_read(client, W83791D_REG_DID_VID4) & 0x01) 1182 + << 4; 1183 + 1184 + data->last_updated = jiffies; 1185 + data->valid = 1; 1186 + } 1187 + 1188 + mutex_unlock(&data->update_lock); 1189 + 1190 + #ifdef DEBUG 1191 + w83791d_print_debug(data, dev); 1192 + #endif 1193 + 1194 + return data; 1195 + } 1196 + 1197 + #ifdef DEBUG 1198 + static void w83791d_print_debug(struct w83791d_data *data, struct device *dev) 1199 + { 1200 + int i = 0, j = 0; 1201 + 1202 + dev_dbg(dev, "======Start of w83791d debug values======\n"); 1203 + dev_dbg(dev, "%d set of Voltages: ===>\n", NUMBER_OF_VIN); 1204 + for (i = 0; i < NUMBER_OF_VIN; i++) { 1205 + dev_dbg(dev, "vin[%d] is: 0x%02x\n", i, data->in[i]); 1206 + dev_dbg(dev, "vin[%d] min is: 0x%02x\n", i, data->in_min[i]); 1207 + dev_dbg(dev, "vin[%d] max is: 0x%02x\n", i, data->in_max[i]); 1208 + } 1209 + dev_dbg(dev, "%d set of Fan Counts/Divisors: ===>\n", NUMBER_OF_FANIN); 1210 + for (i = 0; i < NUMBER_OF_FANIN; i++) { 1211 + dev_dbg(dev, "fan[%d] is: 0x%02x\n", i, data->fan[i]); 1212 + dev_dbg(dev, "fan[%d] min is: 0x%02x\n", i, data->fan_min[i]); 1213 + dev_dbg(dev, "fan_div[%d] is: 0x%02x\n", i, data->fan_div[i]); 1214 + } 1215 + 1216 + /* temperature math is signed, but only print out the 1217 + bits that matter */ 1218 + dev_dbg(dev, "%d set of Temperatures: ===>\n", NUMBER_OF_TEMPIN); 1219 + for (i = 0; i < 3; i++) { 1220 + dev_dbg(dev, "temp1[%d] is: 0x%02x\n", i, (u8) data->temp1[i]); 1221 + } 1222 + for (i = 0; i < 2; i++) { 1223 + for (j = 0; j < 3; j++) { 1224 + dev_dbg(dev, "temp_add[%d][%d] is: 0x%04x\n", i, j, 1225 + (u16) data->temp_add[i][j]); 1226 + } 1227 + } 1228 + 1229 + dev_dbg(dev, "Misc Information: ===>\n"); 1230 + dev_dbg(dev, "alarm is: 0x%08x\n", data->alarms); 1231 + dev_dbg(dev, "beep_mask is: 0x%08x\n", data->beep_mask); 1232 + dev_dbg(dev, "beep_enable is: %d\n", data->beep_enable); 1233 + dev_dbg(dev, "vid is: 0x%02x\n", data->vid); 1234 + dev_dbg(dev, "vrm is: 0x%02x\n", data->vrm); 1235 + dev_dbg(dev, "=======End of w83791d debug values========\n"); 1236 + dev_dbg(dev, "\n"); 1237 + } 1238 + #endif 1239 + 1240 + static int __init sensors_w83791d_init(void) 1241 + { 1242 + return i2c_add_driver(&w83791d_driver); 1243 + } 1244 + 1245 + static void __exit sensors_w83791d_exit(void) 1246 + { 1247 + i2c_del_driver(&w83791d_driver); 1248 + } 1249 + 1250 + MODULE_AUTHOR("Charles Spirakis <bezaur@gmail.com>"); 1251 + MODULE_DESCRIPTION("W83791D driver"); 1252 + MODULE_LICENSE("GPL"); 1253 + 1254 + module_init(sensors_w83791d_init); 1255 + module_exit(sensors_w83791d_exit);
+54 -32
drivers/hwmon/w83792d.c
··· 250 250 : (val)) / 1000, 0, 0xff)) 251 251 #define TEMP_ADD_TO_REG_LOW(val) ((val%1000) ? 0x80 : 0x00) 252 252 253 - #define PWM_FROM_REG(val) (val) 254 - #define PWM_TO_REG(val) (SENSORS_LIMIT((val),0,255)) 255 253 #define DIV_FROM_REG(val) (1 << (val)) 256 254 257 255 static inline u8 ··· 289 291 u8 pwm[7]; /* We only consider the first 3 set of pwm, 290 292 although 792 chip has 7 set of pwm. */ 291 293 u8 pwmenable[3]; 292 - u8 pwm_mode[7]; /* indicates PWM or DC mode: 1->PWM; 0->DC */ 293 294 u32 alarms; /* realtime status register encoding,combined */ 294 295 u8 chassis; /* Chassis status */ 295 296 u8 chassis_clear; /* CLR_CHS, clear chassis intrusion detection */ ··· 372 375 u32 val; \ 373 376 \ 374 377 val = simple_strtoul(buf, NULL, 10); \ 378 + mutex_lock(&data->update_lock); \ 375 379 data->in_##reg[nr] = SENSORS_LIMIT(IN_TO_REG(nr, val)/4, 0, 255); \ 376 380 w83792d_write_value(client, W83792D_REG_IN_##REG[nr], data->in_##reg[nr]); \ 381 + mutex_unlock(&data->update_lock); \ 377 382 \ 378 383 return count; \ 379 384 } ··· 442 443 u32 val; 443 444 444 445 val = simple_strtoul(buf, NULL, 10); 446 + mutex_lock(&data->update_lock); 445 447 data->fan_min[nr] = FAN_TO_REG(val, DIV_FROM_REG(data->fan_div[nr])); 446 448 w83792d_write_value(client, W83792D_REG_FAN_MIN[nr], 447 449 data->fan_min[nr]); 450 + mutex_unlock(&data->update_lock); 448 451 449 452 return count; 450 453 } ··· 479 478 u8 tmp_fan_div; 480 479 481 480 /* Save fan_min */ 481 + mutex_lock(&data->update_lock); 482 482 min = FAN_FROM_REG(data->fan_min[nr], 483 483 DIV_FROM_REG(data->fan_div[nr])); 484 484 ··· 495 493 /* Restore fan_min */ 496 494 data->fan_min[nr] = FAN_TO_REG(min, DIV_FROM_REG(data->fan_div[nr])); 497 495 w83792d_write_value(client, W83792D_REG_FAN_MIN[nr], data->fan_min[nr]); 496 + mutex_unlock(&data->update_lock); 498 497 499 498 return count; 500 499 } ··· 550 547 s32 val; 551 548 552 549 val = simple_strtol(buf, NULL, 10); 553 - 550 + mutex_lock(&data->update_lock); 554 551 data->temp1[nr] = TEMP1_TO_REG(val); 555 552 w83792d_write_value(client, W83792D_REG_TEMP1[nr], 556 553 data->temp1[nr]); 554 + mutex_unlock(&data->update_lock); 557 555 558 556 return count; 559 557 } ··· 584 580 s32 val; 585 581 586 582 val = simple_strtol(buf, NULL, 10); 587 - 583 + mutex_lock(&data->update_lock); 588 584 data->temp_add[nr][index] = TEMP_ADD_TO_REG_HIGH(val); 589 585 data->temp_add[nr][index+1] = TEMP_ADD_TO_REG_LOW(val); 590 586 w83792d_write_value(client, W83792D_REG_TEMP_ADD[nr][index], 591 587 data->temp_add[nr][index]); 592 588 w83792d_write_value(client, W83792D_REG_TEMP_ADD[nr][index+1], 593 589 data->temp_add[nr][index+1]); 590 + mutex_unlock(&data->update_lock); 594 591 595 592 return count; 596 593 } ··· 632 627 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); 633 628 int nr = sensor_attr->index; 634 629 struct w83792d_data *data = w83792d_update_device(dev); 635 - return sprintf(buf, "%ld\n", (long) PWM_FROM_REG(data->pwm[nr-1])); 630 + return sprintf(buf, "%d\n", (data->pwm[nr] & 0x0f) << 4); 636 631 } 637 632 638 633 static ssize_t ··· 664 659 const char *buf, size_t count) 665 660 { 666 661 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); 667 - int nr = sensor_attr->index - 1; 662 + int nr = sensor_attr->index; 668 663 struct i2c_client *client = to_i2c_client(dev); 669 664 struct w83792d_data *data = i2c_get_clientdata(client); 670 - u32 val; 665 + u8 val = SENSORS_LIMIT(simple_strtoul(buf, NULL, 10), 0, 255) >> 4; 671 666 672 - val = simple_strtoul(buf, NULL, 10); 673 - data->pwm[nr] = PWM_TO_REG(val); 667 + mutex_lock(&data->update_lock); 668 + val |= w83792d_read_value(client, W83792D_REG_PWM[nr]) & 0xf0; 669 + data->pwm[nr] = val; 674 670 w83792d_write_value(client, W83792D_REG_PWM[nr], data->pwm[nr]); 671 + mutex_unlock(&data->update_lock); 675 672 676 673 return count; 677 674 } ··· 690 683 u8 fan_cfg_tmp, cfg1_tmp, cfg2_tmp, cfg3_tmp, cfg4_tmp; 691 684 692 685 val = simple_strtoul(buf, NULL, 10); 686 + if (val < 1 || val > 3) 687 + return -EINVAL; 688 + 689 + mutex_lock(&data->update_lock); 693 690 switch (val) { 694 691 case 1: 695 692 data->pwmenable[nr] = 0; /* manual mode */ ··· 704 693 case 3: 705 694 data->pwmenable[nr] = 1; /* thermal cruise/Smart Fan I */ 706 695 break; 707 - default: 708 - return -EINVAL; 709 696 } 710 697 cfg1_tmp = data->pwmenable[0]; 711 698 cfg2_tmp = (data->pwmenable[1]) << 2; ··· 711 702 cfg4_tmp = w83792d_read_value(client,W83792D_REG_FAN_CFG) & 0xc0; 712 703 fan_cfg_tmp = ((cfg4_tmp | cfg3_tmp) | cfg2_tmp) | cfg1_tmp; 713 704 w83792d_write_value(client, W83792D_REG_FAN_CFG, fan_cfg_tmp); 705 + mutex_unlock(&data->update_lock); 714 706 715 707 return count; 716 708 } 717 709 718 710 static struct sensor_device_attribute sda_pwm[] = { 719 - SENSOR_ATTR(pwm1, S_IWUSR | S_IRUGO, show_pwm, store_pwm, 1), 720 - SENSOR_ATTR(pwm2, S_IWUSR | S_IRUGO, show_pwm, store_pwm, 2), 721 - SENSOR_ATTR(pwm3, S_IWUSR | S_IRUGO, show_pwm, store_pwm, 3), 711 + SENSOR_ATTR(pwm1, S_IWUSR | S_IRUGO, show_pwm, store_pwm, 0), 712 + SENSOR_ATTR(pwm2, S_IWUSR | S_IRUGO, show_pwm, store_pwm, 1), 713 + SENSOR_ATTR(pwm3, S_IWUSR | S_IRUGO, show_pwm, store_pwm, 2), 722 714 }; 723 715 static struct sensor_device_attribute sda_pwm_enable[] = { 724 716 SENSOR_ATTR(pwm1_enable, S_IWUSR | S_IRUGO, ··· 738 728 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); 739 729 int nr = sensor_attr->index; 740 730 struct w83792d_data *data = w83792d_update_device(dev); 741 - return sprintf(buf, "%d\n", data->pwm_mode[nr-1]); 731 + return sprintf(buf, "%d\n", data->pwm[nr] >> 7); 742 732 } 743 733 744 734 static ssize_t ··· 746 736 const char *buf, size_t count) 747 737 { 748 738 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); 749 - int nr = sensor_attr->index - 1; 739 + int nr = sensor_attr->index; 750 740 struct i2c_client *client = to_i2c_client(dev); 751 741 struct w83792d_data *data = i2c_get_clientdata(client); 752 742 u32 val; 753 - u8 pwm_mode_mask = 0; 754 743 755 744 val = simple_strtoul(buf, NULL, 10); 756 - data->pwm_mode[nr] = SENSORS_LIMIT(val, 0, 1); 757 - pwm_mode_mask = w83792d_read_value(client, 758 - W83792D_REG_PWM[nr]) & 0x7f; 759 - w83792d_write_value(client, W83792D_REG_PWM[nr], 760 - ((data->pwm_mode[nr]) << 7) | pwm_mode_mask); 745 + if (val != 0 && val != 1) 746 + return -EINVAL; 747 + 748 + mutex_lock(&data->update_lock); 749 + data->pwm[nr] = w83792d_read_value(client, W83792D_REG_PWM[nr]); 750 + if (val) { /* PWM mode */ 751 + data->pwm[nr] |= 0x80; 752 + } else { /* DC mode */ 753 + data->pwm[nr] &= 0x7f; 754 + } 755 + w83792d_write_value(client, W83792D_REG_PWM[nr], data->pwm[nr]); 756 + mutex_unlock(&data->update_lock); 761 757 762 758 return count; 763 759 } 764 760 765 761 static struct sensor_device_attribute sda_pwm_mode[] = { 766 762 SENSOR_ATTR(pwm1_mode, S_IWUSR | S_IRUGO, 767 - show_pwm_mode, store_pwm_mode, 1), 763 + show_pwm_mode, store_pwm_mode, 0), 768 764 SENSOR_ATTR(pwm2_mode, S_IWUSR | S_IRUGO, 769 - show_pwm_mode, store_pwm_mode, 2), 765 + show_pwm_mode, store_pwm_mode, 1), 770 766 SENSOR_ATTR(pwm3_mode, S_IWUSR | S_IRUGO, 771 - show_pwm_mode, store_pwm_mode, 3), 767 + show_pwm_mode, store_pwm_mode, 2), 772 768 }; 773 769 774 770 ··· 805 789 u8 temp1 = 0, temp2 = 0; 806 790 807 791 val = simple_strtoul(buf, NULL, 10); 808 - 792 + mutex_lock(&data->update_lock); 809 793 data->chassis_clear = SENSORS_LIMIT(val, 0 ,1); 810 794 temp1 = ((data->chassis_clear) << 7) & 0x80; 811 795 temp2 = w83792d_read_value(client, 812 796 W83792D_REG_CHASSIS_CLR) & 0x7f; 813 797 w83792d_write_value(client, W83792D_REG_CHASSIS_CLR, temp1 | temp2); 798 + mutex_unlock(&data->update_lock); 814 799 815 800 return count; 816 801 } ··· 844 827 val = simple_strtoul(buf, NULL, 10); 845 828 target_tmp = val; 846 829 target_tmp = target_tmp & 0x7f; 830 + mutex_lock(&data->update_lock); 847 831 target_mask = w83792d_read_value(client, W83792D_REG_THERMAL[nr]) & 0x80; 848 832 data->thermal_cruise[nr] = SENSORS_LIMIT(target_tmp, 0, 255); 849 833 w83792d_write_value(client, W83792D_REG_THERMAL[nr], 850 834 (data->thermal_cruise[nr]) | target_mask); 835 + mutex_unlock(&data->update_lock); 851 836 852 837 return count; 853 838 } ··· 886 867 u8 tol_tmp, tol_mask; 887 868 888 869 val = simple_strtoul(buf, NULL, 10); 870 + mutex_lock(&data->update_lock); 889 871 tol_mask = w83792d_read_value(client, 890 872 W83792D_REG_TOLERANCE[nr]) & ((nr == 1) ? 0x0f : 0xf0); 891 873 tol_tmp = SENSORS_LIMIT(val, 0, 15); ··· 897 877 } 898 878 w83792d_write_value(client, W83792D_REG_TOLERANCE[nr], 899 879 tol_mask | tol_tmp); 880 + mutex_unlock(&data->update_lock); 900 881 901 882 return count; 902 883 } ··· 936 915 u8 mask_tmp = 0; 937 916 938 917 val = simple_strtoul(buf, NULL, 10); 918 + mutex_lock(&data->update_lock); 939 919 data->sf2_points[index][nr] = SENSORS_LIMIT(val, 0, 127); 940 920 mask_tmp = w83792d_read_value(client, 941 921 W83792D_REG_POINTS[index][nr]) & 0x80; 942 922 w83792d_write_value(client, W83792D_REG_POINTS[index][nr], 943 923 mask_tmp|data->sf2_points[index][nr]); 924 + mutex_unlock(&data->update_lock); 944 925 945 926 return count; 946 927 } ··· 1002 979 u8 mask_tmp=0, level_tmp=0; 1003 980 1004 981 val = simple_strtoul(buf, NULL, 10); 982 + mutex_lock(&data->update_lock); 1005 983 data->sf2_levels[index][nr] = SENSORS_LIMIT((val * 15) / 100, 0, 15); 1006 984 mask_tmp = w83792d_read_value(client, W83792D_REG_LEVELS[index][nr]) 1007 985 & ((nr==3) ? 0xf0 : 0x0f); ··· 1012 988 level_tmp = data->sf2_levels[index][nr] << 4; 1013 989 } 1014 990 w83792d_write_value(client, W83792D_REG_LEVELS[index][nr], level_tmp | mask_tmp); 991 + mutex_unlock(&data->update_lock); 1015 992 1016 993 return count; 1017 994 } ··· 1398 1373 struct i2c_client *client = to_i2c_client(dev); 1399 1374 struct w83792d_data *data = i2c_get_clientdata(client); 1400 1375 int i, j; 1401 - u8 reg_array_tmp[4], pwm_array_tmp[7], reg_tmp; 1376 + u8 reg_array_tmp[4], reg_tmp; 1402 1377 1403 1378 mutex_lock(&data->update_lock); 1404 1379 ··· 1427 1402 data->fan_min[i] = w83792d_read_value(client, 1428 1403 W83792D_REG_FAN_MIN[i]); 1429 1404 /* Update the PWM/DC Value and PWM/DC flag */ 1430 - pwm_array_tmp[i] = w83792d_read_value(client, 1405 + data->pwm[i] = w83792d_read_value(client, 1431 1406 W83792D_REG_PWM[i]); 1432 - data->pwm[i] = pwm_array_tmp[i] & 0x0f; 1433 - data->pwm_mode[i] = pwm_array_tmp[i] >> 7; 1434 1407 } 1435 1408 1436 1409 reg_tmp = w83792d_read_value(client, W83792D_REG_FAN_CFG); ··· 1536 1513 dev_dbg(dev, "fan[%d] is: 0x%x\n", i, data->fan[i]); 1537 1514 dev_dbg(dev, "fan[%d] min is: 0x%x\n", i, data->fan_min[i]); 1538 1515 dev_dbg(dev, "pwm[%d] is: 0x%x\n", i, data->pwm[i]); 1539 - dev_dbg(dev, "pwm_mode[%d] is: 0x%x\n", i, data->pwm_mode[i]); 1540 1516 } 1541 1517 dev_dbg(dev, "3 set of Temperatures: =====>\n"); 1542 1518 for (i=0; i<3; i++) {
+21 -1
drivers/i2c/busses/Kconfig
··· 163 163 I2C bus. 164 164 165 165 config I2C_PIIX4 166 - tristate "Intel PIIX4" 166 + tristate "Intel PIIX4 and compatible (ATI/Serverworks/Broadcom/SMSC)" 167 167 depends on I2C && PCI 168 168 help 169 169 If you say yes to this option, support will be included for the Intel ··· 172 172 of Broadcom): 173 173 Intel PIIX4 174 174 Intel 440MX 175 + ATI IXP200 176 + ATI IXP300 177 + ATI IXP400 175 178 Serverworks OSB4 176 179 Serverworks CSB5 177 180 Serverworks CSB6 ··· 275 272 276 273 This driver can also be built as a module. If so, the module 277 274 will be called i2c-nforce2. 275 + 276 + config I2C_OCORES 277 + tristate "OpenCores I2C Controller" 278 + depends on I2C && EXPERIMENTAL 279 + help 280 + If you say yes to this option, support will be included for the 281 + OpenCores I2C controller. For details see 282 + http://www.opencores.org/projects.cgi/web/i2c/overview 283 + 284 + This driver can also be built as a module. If so, the module 285 + will be called i2c-ocores. 278 286 279 287 config I2C_PARPORT 280 288 tristate "Parallel port adapter" ··· 514 500 tristate "PCA9564 on an ISA bus" 515 501 depends on I2C 516 502 select I2C_ALGOPCA 503 + default n 517 504 help 518 505 This driver supports ISA boards using the Philips PCA 9564 519 506 Parallel bus to I2C bus controller 520 507 521 508 This driver can also be built as a module. If so, the module 522 509 will be called i2c-pca-isa. 510 + 511 + This device is almost undetectable and using this driver on a 512 + system which doesn't have this device will result in long 513 + delays when I2C/SMBus chip drivers are loaded (e.g. at boot 514 + time). If unsure, say N. 523 515 524 516 config I2C_MV64XXX 525 517 tristate "Marvell mv64xxx I2C Controller"
+1
drivers/i2c/busses/Makefile
··· 23 23 obj-$(CONFIG_I2C_MPC) += i2c-mpc.o 24 24 obj-$(CONFIG_I2C_MV64XXX) += i2c-mv64xxx.o 25 25 obj-$(CONFIG_I2C_NFORCE2) += i2c-nforce2.o 26 + obj-$(CONFIG_I2C_OCORES) += i2c-ocores.o 26 27 obj-$(CONFIG_I2C_PARPORT) += i2c-parport.o 27 28 obj-$(CONFIG_I2C_PARPORT_LIGHT) += i2c-parport-light.o 28 29 obj-$(CONFIG_I2C_PCA_ISA) += i2c-pca-isa.o
+64 -90
drivers/i2c/busses/i2c-i801.c
··· 1 1 /* 2 - i801.c - Part of lm_sensors, Linux kernel modules for hardware 2 + i2c-i801.c - Part of lm_sensors, Linux kernel modules for hardware 3 3 monitoring 4 4 Copyright (c) 1998 - 2002 Frodo Looijaard <frodol@dds.nl>, 5 5 Philip Edelbrock <phil@netroedge.com>, and Mark D. Studebaker ··· 36 36 This driver supports several versions of Intel's I/O Controller Hubs (ICH). 37 37 For SMBus support, they are similar to the PIIX4 and are part 38 38 of Intel's '810' and other chipsets. 39 - See the doc/busses/i2c-i801 file for details. 39 + See the file Documentation/i2c/busses/i2c-i801 for details. 40 40 I2C Block Read and Process Call are not supported. 41 41 */ 42 42 ··· 66 66 #define SMBAUXCTL (13 + i801_smba) /* ICH4 only */ 67 67 68 68 /* PCI Address Constants */ 69 - #define SMBBA 0x020 69 + #define SMBBAR 4 70 70 #define SMBHSTCFG 0x040 71 - #define SMBREV 0x008 72 71 73 72 /* Host configuration bits for SMBHSTCFG */ 74 73 #define SMBHSTCFG_HST_EN 1 ··· 91 92 #define I801_START 0x40 92 93 #define I801_PEC_EN 0x80 /* ICH4 only */ 93 94 94 - /* insmod parameters */ 95 - 96 - /* If force_addr is set to anything different from 0, we forcibly enable 97 - the I801 at the given address. VERY DANGEROUS! */ 98 - static u16 force_addr; 99 - module_param(force_addr, ushort, 0); 100 - MODULE_PARM_DESC(force_addr, 101 - "Forcibly enable the I801 at the given address. " 102 - "EXTREMELY DANGEROUS!"); 103 95 104 96 static int i801_transaction(void); 105 97 static int i801_block_transaction(union i2c_smbus_data *data, char read_write, 106 98 int command, int hwpec); 107 99 108 - static unsigned short i801_smba; 100 + static unsigned long i801_smba; 109 101 static struct pci_driver i801_driver; 110 102 static struct pci_dev *I801_dev; 111 103 static int isich4; 112 - 113 - static int i801_setup(struct pci_dev *dev) 114 - { 115 - int error_return = 0; 116 - unsigned char temp; 117 - 118 - /* Note: we keep on searching until we have found 'function 3' */ 119 - if(PCI_FUNC(dev->devfn) != 3) 120 - return -ENODEV; 121 - 122 - I801_dev = dev; 123 - if ((dev->device == PCI_DEVICE_ID_INTEL_82801DB_3) || 124 - (dev->device == PCI_DEVICE_ID_INTEL_82801EB_3) || 125 - (dev->device == PCI_DEVICE_ID_INTEL_ESB_4)) 126 - isich4 = 1; 127 - else 128 - isich4 = 0; 129 - 130 - /* Determine the address of the SMBus areas */ 131 - if (force_addr) { 132 - i801_smba = force_addr & 0xfff0; 133 - } else { 134 - pci_read_config_word(I801_dev, SMBBA, &i801_smba); 135 - i801_smba &= 0xfff0; 136 - if(i801_smba == 0) { 137 - dev_err(&dev->dev, "SMB base address uninitialized " 138 - "- upgrade BIOS or use force_addr=0xaddr\n"); 139 - return -ENODEV; 140 - } 141 - } 142 - 143 - if (!request_region(i801_smba, (isich4 ? 16 : 8), i801_driver.name)) { 144 - dev_err(&dev->dev, "I801_smb region 0x%x already in use!\n", 145 - i801_smba); 146 - error_return = -EBUSY; 147 - goto END; 148 - } 149 - 150 - pci_read_config_byte(I801_dev, SMBHSTCFG, &temp); 151 - temp &= ~SMBHSTCFG_I2C_EN; /* SMBus timing */ 152 - pci_write_config_byte(I801_dev, SMBHSTCFG, temp); 153 - 154 - /* If force_addr is set, we program the new address here. Just to make 155 - sure, we disable the device first. */ 156 - if (force_addr) { 157 - pci_write_config_byte(I801_dev, SMBHSTCFG, temp & 0xfe); 158 - pci_write_config_word(I801_dev, SMBBA, i801_smba); 159 - pci_write_config_byte(I801_dev, SMBHSTCFG, temp | 0x01); 160 - dev_warn(&dev->dev, "WARNING: I801 SMBus interface set to " 161 - "new address %04x!\n", i801_smba); 162 - } else if ((temp & 1) == 0) { 163 - pci_write_config_byte(I801_dev, SMBHSTCFG, temp | 1); 164 - dev_warn(&dev->dev, "enabling SMBus device\n"); 165 - } 166 - 167 - if (temp & 0x02) 168 - dev_dbg(&dev->dev, "I801 using Interrupt SMI# for SMBus.\n"); 169 - else 170 - dev_dbg(&dev->dev, "I801 using PCI Interrupt for SMBus.\n"); 171 - 172 - pci_read_config_byte(I801_dev, SMBREV, &temp); 173 - dev_dbg(&dev->dev, "SMBREV = 0x%X\n", temp); 174 - dev_dbg(&dev->dev, "I801_smba = 0x%X\n", i801_smba); 175 - 176 - END: 177 - return error_return; 178 - } 179 104 180 105 static int i801_transaction(void) 181 106 { ··· 257 334 /* We will always wait for a fraction of a second! */ 258 335 timeout = 0; 259 336 do { 260 - temp = inb_p(SMBHSTSTS); 261 337 msleep(1); 338 + temp = inb_p(SMBHSTSTS); 262 339 } 263 340 while ((!(temp & 0x80)) 264 341 && (timeout++ < MAX_TIMEOUT)); ··· 316 393 /* wait for INTR bit as advised by Intel */ 317 394 timeout = 0; 318 395 do { 319 - temp = inb_p(SMBHSTSTS); 320 396 msleep(1); 397 + temp = inb_p(SMBHSTSTS); 321 398 } while ((!(temp & 0x02)) 322 399 && (timeout++ < MAX_TIMEOUT)); 323 400 ··· 464 541 465 542 static int __devinit i801_probe(struct pci_dev *dev, const struct pci_device_id *id) 466 543 { 544 + unsigned char temp; 545 + int err; 467 546 468 - if (i801_setup(dev)) { 469 - dev_warn(&dev->dev, 470 - "I801 not detected, module not inserted.\n"); 471 - return -ENODEV; 547 + I801_dev = dev; 548 + if ((dev->device == PCI_DEVICE_ID_INTEL_82801DB_3) || 549 + (dev->device == PCI_DEVICE_ID_INTEL_82801EB_3) || 550 + (dev->device == PCI_DEVICE_ID_INTEL_ESB_4)) 551 + isich4 = 1; 552 + else 553 + isich4 = 0; 554 + 555 + err = pci_enable_device(dev); 556 + if (err) { 557 + dev_err(&dev->dev, "Failed to enable SMBus PCI device (%d)\n", 558 + err); 559 + goto exit; 472 560 } 561 + 562 + /* Determine the address of the SMBus area */ 563 + i801_smba = pci_resource_start(dev, SMBBAR); 564 + if (!i801_smba) { 565 + dev_err(&dev->dev, "SMBus base address uninitialized, " 566 + "upgrade BIOS\n"); 567 + err = -ENODEV; 568 + goto exit_disable; 569 + } 570 + 571 + err = pci_request_region(dev, SMBBAR, i801_driver.name); 572 + if (err) { 573 + dev_err(&dev->dev, "Failed to request SMBus region " 574 + "0x%lx-0x%lx\n", i801_smba, 575 + pci_resource_end(dev, SMBBAR)); 576 + goto exit_disable; 577 + } 578 + 579 + pci_read_config_byte(I801_dev, SMBHSTCFG, &temp); 580 + temp &= ~SMBHSTCFG_I2C_EN; /* SMBus timing */ 581 + if (!(temp & SMBHSTCFG_HST_EN)) { 582 + dev_info(&dev->dev, "Enabling SMBus device\n"); 583 + temp |= SMBHSTCFG_HST_EN; 584 + } 585 + pci_write_config_byte(I801_dev, SMBHSTCFG, temp); 586 + 587 + if (temp & SMBHSTCFG_SMB_SMI_EN) 588 + dev_dbg(&dev->dev, "SMBus using interrupt SMI#\n"); 589 + else 590 + dev_dbg(&dev->dev, "SMBus using PCI Interrupt\n"); 473 591 474 592 /* set up the driverfs linkage to our parent device */ 475 593 i801_adapter.dev.parent = &dev->dev; 476 594 477 595 snprintf(i801_adapter.name, I2C_NAME_SIZE, 478 - "SMBus I801 adapter at %04x", i801_smba); 479 - return i2c_add_adapter(&i801_adapter); 596 + "SMBus I801 adapter at %04lx", i801_smba); 597 + err = i2c_add_adapter(&i801_adapter); 598 + if (err) { 599 + dev_err(&dev->dev, "Failed to add SMBus adapter\n"); 600 + goto exit_disable; 601 + } 602 + 603 + exit_disable: 604 + pci_disable_device(dev); 605 + exit: 606 + return err; 480 607 } 481 608 482 609 static void __devexit i801_remove(struct pci_dev *dev) 483 610 { 484 611 i2c_del_adapter(&i801_adapter); 485 - release_region(i801_smba, (isich4 ? 16 : 8)); 612 + pci_release_region(dev, SMBBAR); 613 + pci_disable_device(dev); 486 614 } 487 615 488 616 static struct pci_driver i801_driver = {
+27 -11
drivers/i2c/busses/i2c-nforce2.c
··· 31 31 nForce3 250Gb MCP 00E4 32 32 nForce4 MCP 0052 33 33 nForce4 MCP-04 0034 34 + nForce4 MCP51 0264 35 + nForce4 MCP55 0368 34 36 35 37 This driver supports the 2 SMBuses that are included in the MCP of the 36 38 nForce2/3/4 chipsets. ··· 66 64 67 65 /* 68 66 * nVidia nForce2 SMBus control register definitions 67 + * (Newer incarnations use standard BARs 4 and 5 instead) 69 68 */ 70 69 #define NFORCE_PCI_SMB1 0x50 71 70 #define NFORCE_PCI_SMB2 0x54 ··· 262 259 { PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE3S_SMBUS) }, 263 260 { PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE4_SMBUS) }, 264 261 { PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE_MCP04_SMBUS) }, 262 + { PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE_MCP51_SMBUS) }, 263 + { PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE_MCP55_SMBUS) }, 265 264 { 0 } 266 265 }; 267 266 ··· 271 266 MODULE_DEVICE_TABLE (pci, nforce2_ids); 272 267 273 268 274 - static int __devinit nforce2_probe_smb (struct pci_dev *dev, int reg, 275 - struct nforce2_smbus *smbus, char *name) 269 + static int __devinit nforce2_probe_smb (struct pci_dev *dev, int bar, 270 + int alt_reg, struct nforce2_smbus *smbus, const char *name) 276 271 { 277 - u16 iobase; 278 272 int error; 279 273 280 - if (pci_read_config_word(dev, reg, &iobase) != PCIBIOS_SUCCESSFUL) { 281 - dev_err(&smbus->adapter.dev, "Error reading PCI config for %s\n", name); 282 - return -1; 274 + smbus->base = pci_resource_start(dev, bar); 275 + if (smbus->base) { 276 + smbus->size = pci_resource_len(dev, bar); 277 + } else { 278 + /* Older incarnations of the device used non-standard BARs */ 279 + u16 iobase; 280 + 281 + if (pci_read_config_word(dev, alt_reg, &iobase) 282 + != PCIBIOS_SUCCESSFUL) { 283 + dev_err(&dev->dev, "Error reading PCI config for %s\n", 284 + name); 285 + return -1; 286 + } 287 + 288 + smbus->base = iobase & PCI_BASE_ADDRESS_IO_MASK; 289 + smbus->size = 8; 283 290 } 284 - smbus->dev = dev; 285 - smbus->base = iobase & 0xfffc; 286 - smbus->size = 8; 291 + smbus->dev = dev; 287 292 288 293 if (!request_region(smbus->base, smbus->size, nforce2_driver.name)) { 289 294 dev_err(&smbus->adapter.dev, "Error requesting region %02x .. %02X for %s\n", ··· 328 313 pci_set_drvdata(dev, smbuses); 329 314 330 315 /* SMBus adapter 1 */ 331 - res1 = nforce2_probe_smb (dev, NFORCE_PCI_SMB1, &smbuses[0], "SMB1"); 316 + res1 = nforce2_probe_smb(dev, 4, NFORCE_PCI_SMB1, &smbuses[0], "SMB1"); 332 317 if (res1 < 0) { 333 318 dev_err(&dev->dev, "Error probing SMB1.\n"); 334 319 smbuses[0].base = 0; /* to have a check value */ 335 320 } 336 - res2 = nforce2_probe_smb (dev, NFORCE_PCI_SMB2, &smbuses[1], "SMB2"); 321 + /* SMBus adapter 2 */ 322 + res2 = nforce2_probe_smb(dev, 5, NFORCE_PCI_SMB2, &smbuses[1], "SMB2"); 337 323 if (res2 < 0) { 338 324 dev_err(&dev->dev, "Error probing SMB2.\n"); 339 325 smbuses[1].base = 0; /* to have a check value */
+341
drivers/i2c/busses/i2c-ocores.c
··· 1 + /* 2 + * i2c-ocores.c: I2C bus driver for OpenCores I2C controller 3 + * (http://www.opencores.org/projects.cgi/web/i2c/overview). 4 + * 5 + * Peter Korsgaard <jacmet@sunsite.dk> 6 + * 7 + * This file is licensed under the terms of the GNU General Public License 8 + * version 2. This program is licensed "as is" without any warranty of any 9 + * kind, whether express or implied. 10 + */ 11 + 12 + #include <linux/config.h> 13 + #include <linux/kernel.h> 14 + #include <linux/module.h> 15 + #include <linux/sched.h> 16 + #include <linux/init.h> 17 + #include <linux/errno.h> 18 + #include <linux/platform_device.h> 19 + #include <linux/i2c.h> 20 + #include <linux/interrupt.h> 21 + #include <linux/wait.h> 22 + #include <linux/i2c-ocores.h> 23 + #include <asm/io.h> 24 + 25 + struct ocores_i2c { 26 + void __iomem *base; 27 + int regstep; 28 + wait_queue_head_t wait; 29 + struct i2c_adapter adap; 30 + struct i2c_msg *msg; 31 + int pos; 32 + int nmsgs; 33 + int state; /* see STATE_ */ 34 + }; 35 + 36 + /* registers */ 37 + #define OCI2C_PRELOW 0 38 + #define OCI2C_PREHIGH 1 39 + #define OCI2C_CONTROL 2 40 + #define OCI2C_DATA 3 41 + #define OCI2C_CMD 4 /* write only */ 42 + #define OCI2C_STATUS 4 /* read only, same address as OCI2C_CMD */ 43 + 44 + #define OCI2C_CTRL_IEN 0x40 45 + #define OCI2C_CTRL_EN 0x80 46 + 47 + #define OCI2C_CMD_START 0x91 48 + #define OCI2C_CMD_STOP 0x41 49 + #define OCI2C_CMD_READ 0x21 50 + #define OCI2C_CMD_WRITE 0x11 51 + #define OCI2C_CMD_READ_ACK 0x21 52 + #define OCI2C_CMD_READ_NACK 0x29 53 + #define OCI2C_CMD_IACK 0x01 54 + 55 + #define OCI2C_STAT_IF 0x01 56 + #define OCI2C_STAT_TIP 0x02 57 + #define OCI2C_STAT_ARBLOST 0x20 58 + #define OCI2C_STAT_BUSY 0x40 59 + #define OCI2C_STAT_NACK 0x80 60 + 61 + #define STATE_DONE 0 62 + #define STATE_START 1 63 + #define STATE_WRITE 2 64 + #define STATE_READ 3 65 + #define STATE_ERROR 4 66 + 67 + static inline void oc_setreg(struct ocores_i2c *i2c, int reg, u8 value) 68 + { 69 + iowrite8(value, i2c->base + reg * i2c->regstep); 70 + } 71 + 72 + static inline u8 oc_getreg(struct ocores_i2c *i2c, int reg) 73 + { 74 + return ioread8(i2c->base + reg * i2c->regstep); 75 + } 76 + 77 + static void ocores_process(struct ocores_i2c *i2c) 78 + { 79 + struct i2c_msg *msg = i2c->msg; 80 + u8 stat = oc_getreg(i2c, OCI2C_STATUS); 81 + 82 + if ((i2c->state == STATE_DONE) || (i2c->state == STATE_ERROR)) { 83 + /* stop has been sent */ 84 + oc_setreg(i2c, OCI2C_CMD, OCI2C_CMD_IACK); 85 + wake_up(&i2c->wait); 86 + return; 87 + } 88 + 89 + /* error? */ 90 + if (stat & OCI2C_STAT_ARBLOST) { 91 + i2c->state = STATE_ERROR; 92 + oc_setreg(i2c, OCI2C_CMD, OCI2C_CMD_STOP); 93 + return; 94 + } 95 + 96 + if ((i2c->state == STATE_START) || (i2c->state == STATE_WRITE)) { 97 + i2c->state = 98 + (msg->flags & I2C_M_RD) ? STATE_READ : STATE_WRITE; 99 + 100 + if (stat & OCI2C_STAT_NACK) { 101 + i2c->state = STATE_ERROR; 102 + oc_setreg(i2c, OCI2C_CMD, OCI2C_CMD_STOP); 103 + return; 104 + } 105 + } else 106 + msg->buf[i2c->pos++] = oc_getreg(i2c, OCI2C_DATA); 107 + 108 + /* end of msg? */ 109 + if (i2c->pos == msg->len) { 110 + i2c->nmsgs--; 111 + i2c->msg++; 112 + i2c->pos = 0; 113 + msg = i2c->msg; 114 + 115 + if (i2c->nmsgs) { /* end? */ 116 + /* send start? */ 117 + if (!(msg->flags & I2C_M_NOSTART)) { 118 + u8 addr = (msg->addr << 1); 119 + 120 + if (msg->flags & I2C_M_RD) 121 + addr |= 1; 122 + 123 + i2c->state = STATE_START; 124 + 125 + oc_setreg(i2c, OCI2C_DATA, addr); 126 + oc_setreg(i2c, OCI2C_CMD, OCI2C_CMD_START); 127 + return; 128 + } else 129 + i2c->state = (msg->flags & I2C_M_RD) 130 + ? STATE_READ : STATE_WRITE; 131 + } else { 132 + i2c->state = STATE_DONE; 133 + oc_setreg(i2c, OCI2C_CMD, OCI2C_CMD_STOP); 134 + return; 135 + } 136 + } 137 + 138 + if (i2c->state == STATE_READ) { 139 + oc_setreg(i2c, OCI2C_CMD, i2c->pos == (msg->len-1) ? 140 + OCI2C_CMD_READ_NACK : OCI2C_CMD_READ_ACK); 141 + } else { 142 + oc_setreg(i2c, OCI2C_DATA, msg->buf[i2c->pos++]); 143 + oc_setreg(i2c, OCI2C_CMD, OCI2C_CMD_WRITE); 144 + } 145 + } 146 + 147 + static irqreturn_t ocores_isr(int irq, void *dev_id, struct pt_regs *regs) 148 + { 149 + struct ocores_i2c *i2c = dev_id; 150 + 151 + ocores_process(i2c); 152 + 153 + return IRQ_HANDLED; 154 + } 155 + 156 + static int ocores_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs, int num) 157 + { 158 + struct ocores_i2c *i2c = i2c_get_adapdata(adap); 159 + 160 + i2c->msg = msgs; 161 + i2c->pos = 0; 162 + i2c->nmsgs = num; 163 + i2c->state = STATE_START; 164 + 165 + oc_setreg(i2c, OCI2C_DATA, 166 + (i2c->msg->addr << 1) | 167 + ((i2c->msg->flags & I2C_M_RD) ? 1:0)); 168 + 169 + oc_setreg(i2c, OCI2C_CMD, OCI2C_CMD_START); 170 + 171 + if (wait_event_timeout(i2c->wait, (i2c->state == STATE_ERROR) || 172 + (i2c->state == STATE_DONE), HZ)) 173 + return (i2c->state == STATE_DONE) ? num : -EIO; 174 + else 175 + return -ETIMEDOUT; 176 + } 177 + 178 + static void ocores_init(struct ocores_i2c *i2c, 179 + struct ocores_i2c_platform_data *pdata) 180 + { 181 + int prescale; 182 + u8 ctrl = oc_getreg(i2c, OCI2C_CONTROL); 183 + 184 + /* make sure the device is disabled */ 185 + oc_setreg(i2c, OCI2C_CONTROL, ctrl & ~(OCI2C_CTRL_EN|OCI2C_CTRL_IEN)); 186 + 187 + prescale = (pdata->clock_khz / (5*100)) - 1; 188 + oc_setreg(i2c, OCI2C_PRELOW, prescale & 0xff); 189 + oc_setreg(i2c, OCI2C_PREHIGH, prescale >> 8); 190 + 191 + /* Init the device */ 192 + oc_setreg(i2c, OCI2C_CMD, OCI2C_CMD_IACK); 193 + oc_setreg(i2c, OCI2C_CONTROL, ctrl | OCI2C_CTRL_IEN | OCI2C_CTRL_EN); 194 + } 195 + 196 + 197 + static u32 ocores_func(struct i2c_adapter *adap) 198 + { 199 + return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL; 200 + } 201 + 202 + static struct i2c_algorithm ocores_algorithm = { 203 + .master_xfer = ocores_xfer, 204 + .functionality = ocores_func, 205 + }; 206 + 207 + static struct i2c_adapter ocores_adapter = { 208 + .owner = THIS_MODULE, 209 + .name = "i2c-ocores", 210 + .class = I2C_CLASS_HWMON, 211 + .algo = &ocores_algorithm, 212 + }; 213 + 214 + 215 + static int __devinit ocores_i2c_probe(struct platform_device *pdev) 216 + { 217 + struct ocores_i2c *i2c; 218 + struct ocores_i2c_platform_data *pdata; 219 + struct resource *res, *res2; 220 + int ret; 221 + 222 + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 223 + if (!res) 224 + return -ENODEV; 225 + 226 + res2 = platform_get_resource(pdev, IORESOURCE_IRQ, 0); 227 + if (!res2) 228 + return -ENODEV; 229 + 230 + pdata = (struct ocores_i2c_platform_data*) pdev->dev.platform_data; 231 + if (!pdata) 232 + return -ENODEV; 233 + 234 + i2c = kzalloc(sizeof(*i2c), GFP_KERNEL); 235 + if (!i2c) 236 + return -ENOMEM; 237 + 238 + if (!request_mem_region(res->start, res->end - res->start + 1, 239 + pdev->name)) { 240 + dev_err(&pdev->dev, "Memory region busy\n"); 241 + ret = -EBUSY; 242 + goto request_mem_failed; 243 + } 244 + 245 + i2c->base = ioremap(res->start, res->end - res->start + 1); 246 + if (!i2c->base) { 247 + dev_err(&pdev->dev, "Unable to map registers\n"); 248 + ret = -EIO; 249 + goto map_failed; 250 + } 251 + 252 + i2c->regstep = pdata->regstep; 253 + ocores_init(i2c, pdata); 254 + 255 + init_waitqueue_head(&i2c->wait); 256 + ret = request_irq(res2->start, ocores_isr, 0, pdev->name, i2c); 257 + if (ret) { 258 + dev_err(&pdev->dev, "Cannot claim IRQ\n"); 259 + goto request_irq_failed; 260 + } 261 + 262 + /* hook up driver to tree */ 263 + platform_set_drvdata(pdev, i2c); 264 + i2c->adap = ocores_adapter; 265 + i2c_set_adapdata(&i2c->adap, i2c); 266 + i2c->adap.dev.parent = &pdev->dev; 267 + 268 + /* add i2c adapter to i2c tree */ 269 + ret = i2c_add_adapter(&i2c->adap); 270 + if (ret) { 271 + dev_err(&pdev->dev, "Failed to add adapter\n"); 272 + goto add_adapter_failed; 273 + } 274 + 275 + return 0; 276 + 277 + add_adapter_failed: 278 + free_irq(res2->start, i2c); 279 + request_irq_failed: 280 + iounmap(i2c->base); 281 + map_failed: 282 + release_mem_region(res->start, res->end - res->start + 1); 283 + request_mem_failed: 284 + kfree(i2c); 285 + 286 + return ret; 287 + } 288 + 289 + static int __devexit ocores_i2c_remove(struct platform_device* pdev) 290 + { 291 + struct ocores_i2c *i2c = platform_get_drvdata(pdev); 292 + struct resource *res; 293 + 294 + /* disable i2c logic */ 295 + oc_setreg(i2c, OCI2C_CONTROL, oc_getreg(i2c, OCI2C_CONTROL) 296 + & ~(OCI2C_CTRL_EN|OCI2C_CTRL_IEN)); 297 + 298 + /* remove adapter & data */ 299 + i2c_del_adapter(&i2c->adap); 300 + platform_set_drvdata(pdev, NULL); 301 + 302 + res = platform_get_resource(pdev, IORESOURCE_IRQ, 0); 303 + if (res) 304 + free_irq(res->start, i2c); 305 + 306 + iounmap(i2c->base); 307 + 308 + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 309 + if (res) 310 + release_mem_region(res->start, res->end - res->start + 1); 311 + 312 + kfree(i2c); 313 + 314 + return 0; 315 + } 316 + 317 + static struct platform_driver ocores_i2c_driver = { 318 + .probe = ocores_i2c_probe, 319 + .remove = __devexit_p(ocores_i2c_remove), 320 + .driver = { 321 + .owner = THIS_MODULE, 322 + .name = "ocores-i2c", 323 + }, 324 + }; 325 + 326 + static int __init ocores_i2c_init(void) 327 + { 328 + return platform_driver_register(&ocores_i2c_driver); 329 + } 330 + 331 + static void __exit ocores_i2c_exit(void) 332 + { 333 + platform_driver_unregister(&ocores_i2c_driver); 334 + } 335 + 336 + module_init(ocores_i2c_init); 337 + module_exit(ocores_i2c_exit); 338 + 339 + MODULE_AUTHOR("Peter Korsgaard <jacmet@sunsite.dk>"); 340 + MODULE_DESCRIPTION("OpenCores I2C bus driver"); 341 + MODULE_LICENSE("GPL");
+8 -25
drivers/i2c/busses/i2c-piix4.c
··· 102 102 "Forcibly enable the PIIX4 at the given address. " 103 103 "EXTREMELY DANGEROUS!"); 104 104 105 - /* If fix_hstcfg is set to anything different from 0, we reset one of the 106 - registers to be a valid value. */ 107 - static int fix_hstcfg; 108 - module_param (fix_hstcfg, int, 0); 109 - MODULE_PARM_DESC(fix_hstcfg, 110 - "Fix config register. Needed on some boards (Force CPCI735)."); 111 - 112 105 static int piix4_transaction(void); 113 106 114 107 static unsigned short piix4_smba; ··· 130 137 /* Don't access SMBus on IBM systems which get corrupted eeproms */ 131 138 if (dmi_check_system(piix4_dmi_table) && 132 139 PIIX4_dev->vendor == PCI_VENDOR_ID_INTEL) { 133 - dev_err(&PIIX4_dev->dev, "IBM Laptop detected; this module " 140 + dev_err(&PIIX4_dev->dev, "IBM system detected; this module " 134 141 "may corrupt your serial eeprom! Refusing to load " 135 142 "module!\n"); 136 143 return -EPERM; ··· 159 166 160 167 pci_read_config_byte(PIIX4_dev, SMBHSTCFG, &temp); 161 168 162 - /* Some BIOS will set up the chipset incorrectly and leave a register 163 - in an undefined state (causing I2C to act very strangely). */ 164 - if (temp & 0x02) { 165 - if (fix_hstcfg) { 166 - dev_info(&PIIX4_dev->dev, "Working around buggy BIOS " 167 - "(I2C)\n"); 168 - temp &= 0xfd; 169 - pci_write_config_byte(PIIX4_dev, SMBHSTCFG, temp); 170 - } else { 171 - dev_info(&PIIX4_dev->dev, "Unusual config register " 172 - "value\n"); 173 - dev_info(&PIIX4_dev->dev, "Try using fix_hstcfg=1 if " 174 - "you experience problems\n"); 175 - } 176 - } 177 - 178 169 /* If force_addr is set, we program the new address here. Just to make 179 170 sure, we disable the PIIX4 first. */ 180 171 if (force_addr) { ··· 191 214 } 192 215 } 193 216 194 - if ((temp & 0x0E) == 8) 217 + if (((temp & 0x0E) == 8) || ((temp & 0x0E) == 2)) 195 218 dev_dbg(&PIIX4_dev->dev, "Using Interrupt 9 for SMBus.\n"); 196 219 else if ((temp & 0x0E) == 0) 197 220 dev_dbg(&PIIX4_dev->dev, "Using Interrupt SMI# for SMBus.\n"); ··· 390 413 static struct pci_device_id piix4_ids[] = { 391 414 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82371AB_3), 392 415 .driver_data = 3 }, 416 + { PCI_DEVICE(PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_IXP200_SMBUS), 417 + .driver_data = 0 }, 418 + { PCI_DEVICE(PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_IXP300_SMBUS), 419 + .driver_data = 0 }, 420 + { PCI_DEVICE(PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_IXP400_SMBUS), 421 + .driver_data = 0 }, 393 422 { PCI_DEVICE(PCI_VENDOR_ID_SERVERWORKS, PCI_DEVICE_ID_SERVERWORKS_OSB4), 394 423 .driver_data = 0 }, 395 424 { PCI_DEVICE(PCI_VENDOR_ID_SERVERWORKS, PCI_DEVICE_ID_SERVERWORKS_CSB5),
+150 -56
drivers/i2c/busses/scx200_acb.c
··· 33 33 #include <linux/delay.h> 34 34 #include <linux/mutex.h> 35 35 #include <asm/io.h> 36 - #include <asm/msr.h> 37 36 38 37 #include <linux/scx200.h> 39 38 ··· 84 85 u8 *ptr; 85 86 char needs_reset; 86 87 unsigned len; 88 + 89 + /* PCI device info */ 90 + struct pci_dev *pdev; 91 + int bar; 87 92 }; 88 93 89 94 /* Register Definitions */ ··· 384 381 static struct scx200_acb_iface *scx200_acb_list; 385 382 static DECLARE_MUTEX(scx200_acb_list_mutex); 386 383 387 - static int scx200_acb_probe(struct scx200_acb_iface *iface) 384 + static __init int scx200_acb_probe(struct scx200_acb_iface *iface) 388 385 { 389 386 u8 val; 390 387 ··· 420 417 return 0; 421 418 } 422 419 423 - static int __init scx200_acb_create(const char *text, int base, int index) 420 + static __init struct scx200_acb_iface *scx200_create_iface(const char *text, 421 + int index) 424 422 { 425 423 struct scx200_acb_iface *iface; 426 424 struct i2c_adapter *adapter; 427 - int rc; 428 425 429 426 iface = kzalloc(sizeof(*iface), GFP_KERNEL); 430 427 if (!iface) { 431 428 printk(KERN_ERR NAME ": can't allocate memory\n"); 432 - rc = -ENOMEM; 433 - goto errout; 429 + return NULL; 434 430 } 435 431 436 432 adapter = &iface->adapter; ··· 442 440 443 441 mutex_init(&iface->mutex); 444 442 445 - if (!request_region(base, 8, adapter->name)) { 446 - printk(KERN_ERR NAME ": can't allocate io 0x%x-0x%x\n", 447 - base, base + 8-1); 448 - rc = -EBUSY; 449 - goto errout_free; 450 - } 451 - iface->base = base; 443 + return iface; 444 + } 445 + 446 + static int __init scx200_acb_create(struct scx200_acb_iface *iface) 447 + { 448 + struct i2c_adapter *adapter; 449 + int rc; 450 + 451 + adapter = &iface->adapter; 452 452 453 453 rc = scx200_acb_probe(iface); 454 454 if (rc) { 455 455 printk(KERN_WARNING NAME ": probe failed\n"); 456 - goto errout_release; 456 + return rc; 457 457 } 458 458 459 459 scx200_acb_reset(iface); 460 460 461 461 if (i2c_add_adapter(adapter) < 0) { 462 462 printk(KERN_ERR NAME ": failed to register\n"); 463 - rc = -ENODEV; 464 - goto errout_release; 463 + return -ENODEV; 465 464 } 466 465 467 466 down(&scx200_acb_list_mutex); ··· 471 468 up(&scx200_acb_list_mutex); 472 469 473 470 return 0; 471 + } 474 472 475 - errout_release: 476 - release_region(iface->base, 8); 473 + static __init int scx200_create_pci(const char *text, struct pci_dev *pdev, 474 + int bar) 475 + { 476 + struct scx200_acb_iface *iface; 477 + int rc; 478 + 479 + iface = scx200_create_iface(text, 0); 480 + 481 + if (iface == NULL) 482 + return -ENOMEM; 483 + 484 + iface->pdev = pdev; 485 + iface->bar = bar; 486 + 487 + pci_enable_device_bars(iface->pdev, 1 << iface->bar); 488 + 489 + rc = pci_request_region(iface->pdev, iface->bar, iface->adapter.name); 490 + 491 + if (rc != 0) { 492 + printk(KERN_ERR NAME ": can't allocate PCI BAR %d\n", 493 + iface->bar); 494 + goto errout_free; 495 + } 496 + 497 + iface->base = pci_resource_start(iface->pdev, iface->bar); 498 + rc = scx200_acb_create(iface); 499 + 500 + if (rc == 0) 501 + return 0; 502 + 503 + pci_release_region(iface->pdev, iface->bar); 504 + pci_dev_put(iface->pdev); 477 505 errout_free: 478 506 kfree(iface); 479 - errout: 480 507 return rc; 481 508 } 482 509 483 - static struct pci_device_id scx200[] = { 484 - { PCI_DEVICE(PCI_VENDOR_ID_NS, PCI_DEVICE_ID_NS_SCx200_BRIDGE) }, 485 - { PCI_DEVICE(PCI_VENDOR_ID_NS, PCI_DEVICE_ID_NS_SC1100_BRIDGE) }, 486 - { }, 487 - }; 488 - 489 - static struct pci_device_id divil_pci[] = { 490 - { PCI_DEVICE(PCI_VENDOR_ID_NS, PCI_DEVICE_ID_NS_CS5535_ISA) }, 491 - { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_CS5536_ISA) }, 492 - { } /* NULL entry */ 493 - }; 494 - 495 - #define MSR_LBAR_SMB 0x5140000B 496 - 497 - static __init int scx200_add_cs553x(void) 510 + static int __init scx200_create_isa(const char *text, unsigned long base, 511 + int index) 498 512 { 499 - u32 low, hi; 500 - u32 smb_base; 513 + struct scx200_acb_iface *iface; 514 + int rc; 501 515 502 - /* Grab & reserve the SMB I/O range */ 503 - rdmsr(MSR_LBAR_SMB, low, hi); 516 + iface = scx200_create_iface(text, index); 504 517 505 - /* Check the IO mask and whether SMB is enabled */ 506 - if (hi != 0x0000F001) { 507 - printk(KERN_WARNING NAME ": SMBus not enabled\n"); 508 - return -ENODEV; 518 + if (iface == NULL) 519 + return -ENOMEM; 520 + 521 + if (request_region(base, 8, iface->adapter.name) == 0) { 522 + printk(KERN_ERR NAME ": can't allocate io 0x%lx-0x%lx\n", 523 + base, base + 8 - 1); 524 + rc = -EBUSY; 525 + goto errout_free; 509 526 } 510 527 511 - /* SMBus IO size is 8 bytes */ 512 - smb_base = low & 0x0000FFF8; 528 + iface->base = base; 529 + rc = scx200_acb_create(iface); 513 530 514 - return scx200_acb_create("CS5535", smb_base, 0); 531 + if (rc == 0) 532 + return 0; 533 + 534 + release_region(base, 8); 535 + errout_free: 536 + kfree(iface); 537 + return rc; 538 + } 539 + 540 + /* Driver data is an index into the scx200_data array that indicates 541 + * the name and the BAR where the I/O address resource is located. ISA 542 + * devices are flagged with a bar value of -1 */ 543 + 544 + static struct pci_device_id scx200_pci[] = { 545 + { PCI_DEVICE(PCI_VENDOR_ID_NS, PCI_DEVICE_ID_NS_SCx200_BRIDGE), 546 + .driver_data = 0 }, 547 + { PCI_DEVICE(PCI_VENDOR_ID_NS, PCI_DEVICE_ID_NS_SC1100_BRIDGE), 548 + .driver_data = 0 }, 549 + { PCI_DEVICE(PCI_VENDOR_ID_NS, PCI_DEVICE_ID_NS_CS5535_ISA), 550 + .driver_data = 1 }, 551 + { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_CS5536_ISA), 552 + .driver_data = 2 } 553 + }; 554 + 555 + static struct { 556 + const char *name; 557 + int bar; 558 + } scx200_data[] = { 559 + { "SCx200", -1 }, 560 + { "CS5535", 0 }, 561 + { "CS5536", 0 } 562 + }; 563 + 564 + static __init int scx200_scan_pci(void) 565 + { 566 + int data, dev; 567 + int rc = -ENODEV; 568 + struct pci_dev *pdev; 569 + 570 + for(dev = 0; dev < ARRAY_SIZE(scx200_pci); dev++) { 571 + pdev = pci_get_device(scx200_pci[dev].vendor, 572 + scx200_pci[dev].device, NULL); 573 + 574 + if (pdev == NULL) 575 + continue; 576 + 577 + data = scx200_pci[dev].driver_data; 578 + 579 + /* if .bar is greater or equal to zero, this is a 580 + * PCI device - otherwise, we assume 581 + that the ports are ISA based 582 + */ 583 + 584 + if (scx200_data[data].bar >= 0) 585 + rc = scx200_create_pci(scx200_data[data].name, pdev, 586 + scx200_data[data].bar); 587 + else { 588 + int i; 589 + 590 + for (i = 0; i < MAX_DEVICES; ++i) { 591 + if (base[i] == 0) 592 + continue; 593 + 594 + rc = scx200_create_isa(scx200_data[data].name, 595 + base[i], 596 + i); 597 + } 598 + } 599 + 600 + break; 601 + } 602 + 603 + return rc; 515 604 } 516 605 517 606 static int __init scx200_acb_init(void) 518 607 { 519 - int i; 520 - int rc = -ENODEV; 608 + int rc; 521 609 522 610 pr_debug(NAME ": NatSemi SCx200 ACCESS.bus Driver\n"); 523 611 524 - /* Verify that this really is a SCx200 processor */ 525 - if (pci_dev_present(scx200)) { 526 - for (i = 0; i < MAX_DEVICES; ++i) { 527 - if (base[i] > 0) 528 - rc = scx200_acb_create("SCx200", base[i], i); 529 - } 530 - } else if (pci_dev_present(divil_pci)) 531 - rc = scx200_add_cs553x(); 612 + rc = scx200_scan_pci(); 532 613 533 614 /* If at least one bus was created, init must succeed */ 534 615 if (scx200_acb_list) ··· 630 543 up(&scx200_acb_list_mutex); 631 544 632 545 i2c_del_adapter(&iface->adapter); 633 - release_region(iface->base, 8); 546 + 547 + if (iface->pdev) { 548 + pci_release_region(iface->pdev, iface->bar); 549 + pci_dev_put(iface->pdev); 550 + } 551 + else 552 + release_region(iface->base, 8); 553 + 634 554 kfree(iface); 635 555 down(&scx200_acb_list_mutex); 636 556 }
+8
drivers/i2c/chips/Kconfig
··· 39 39 config SENSORS_PCF8574 40 40 tristate "Philips PCF8574 and PCF8574A" 41 41 depends on I2C && EXPERIMENTAL 42 + default n 42 43 help 43 44 If you say yes here you get support for Philips PCF8574 and 44 45 PCF8574A chips. 45 46 46 47 This driver can also be built as a module. If so, the module 47 48 will be called pcf8574. 49 + 50 + These devices are hard to detect and rarely found on mainstream 51 + hardware. If unsure, say N. 48 52 49 53 config SENSORS_PCA9539 50 54 tristate "Philips PCA9539 16-bit I/O port" ··· 63 59 config SENSORS_PCF8591 64 60 tristate "Philips PCF8591" 65 61 depends on I2C && EXPERIMENTAL 62 + default n 66 63 help 67 64 If you say yes here you get support for Philips PCF8591 chips. 68 65 69 66 This driver can also be built as a module. If so, the module 70 67 will be called pcf8591. 68 + 69 + These devices are hard to detect and rarely found on mainstream 70 + hardware. If unsure, say N. 71 71 72 72 config ISP1301_OMAP 73 73 tristate "Philips ISP1301 with OMAP OTG"
+249 -87
drivers/i2c/chips/m41t00.c
··· 1 1 /* 2 - * drivers/i2c/chips/m41t00.c 3 - * 4 - * I2C client/driver for the ST M41T00 Real-Time Clock chip. 2 + * I2C client/driver for the ST M41T00 family of i2c rtc chips. 5 3 * 6 4 * Author: Mark A. Greer <mgreer@mvista.com> 7 5 * 8 - * 2005 (c) MontaVista Software, Inc. This file is licensed under 6 + * 2005, 2006 (c) MontaVista Software, Inc. This file is licensed under 9 7 * the terms of the GNU General Public License version 2. This program 10 8 * is licensed "as is" without any warranty of any kind, whether express 11 9 * or implied. ··· 11 13 /* 12 14 * This i2c client/driver wedges between the drivers/char/genrtc.c RTC 13 15 * interface and the SMBus interface of the i2c subsystem. 14 - * It would be more efficient to use i2c msgs/i2c_transfer directly but, as 15 - * recommened in .../Documentation/i2c/writing-clients section 16 - * "Sending and receiving", using SMBus level communication is preferred. 17 16 */ 18 17 19 18 #include <linux/kernel.h> ··· 19 24 #include <linux/i2c.h> 20 25 #include <linux/rtc.h> 21 26 #include <linux/bcd.h> 22 - #include <linux/mutex.h> 23 27 #include <linux/workqueue.h> 24 - 28 + #include <linux/platform_device.h> 29 + #include <linux/m41t00.h> 25 30 #include <asm/time.h> 26 31 #include <asm/rtc.h> 27 - 28 - #define M41T00_DRV_NAME "m41t00" 29 - 30 - static DEFINE_MUTEX(m41t00_mutex); 31 32 32 33 static struct i2c_driver m41t00_driver; 33 34 static struct i2c_client *save_client; 34 35 35 36 static unsigned short ignore[] = { I2C_CLIENT_END }; 36 - static unsigned short normal_addr[] = { 0x68, I2C_CLIENT_END }; 37 + static unsigned short normal_addr[] = { I2C_CLIENT_END, I2C_CLIENT_END }; 37 38 38 39 static struct i2c_client_address_data addr_data = { 39 - .normal_i2c = normal_addr, 40 - .probe = ignore, 41 - .ignore = ignore, 40 + .normal_i2c = normal_addr, 41 + .probe = ignore, 42 + .ignore = ignore, 42 43 }; 44 + 45 + struct m41t00_chip_info { 46 + u8 type; 47 + char *name; 48 + u8 read_limit; 49 + u8 sec; /* Offsets for chip regs */ 50 + u8 min; 51 + u8 hour; 52 + u8 day; 53 + u8 mon; 54 + u8 year; 55 + u8 alarm_mon; 56 + u8 alarm_hour; 57 + u8 sqw; 58 + u8 sqw_freq; 59 + }; 60 + 61 + static struct m41t00_chip_info m41t00_chip_info_tbl[] = { 62 + { 63 + .type = M41T00_TYPE_M41T00, 64 + .name = "m41t00", 65 + .read_limit = 5, 66 + .sec = 0, 67 + .min = 1, 68 + .hour = 2, 69 + .day = 4, 70 + .mon = 5, 71 + .year = 6, 72 + }, 73 + { 74 + .type = M41T00_TYPE_M41T81, 75 + .name = "m41t81", 76 + .read_limit = 1, 77 + .sec = 1, 78 + .min = 2, 79 + .hour = 3, 80 + .day = 5, 81 + .mon = 6, 82 + .year = 7, 83 + .alarm_mon = 0xa, 84 + .alarm_hour = 0xc, 85 + .sqw = 0x13, 86 + }, 87 + { 88 + .type = M41T00_TYPE_M41T85, 89 + .name = "m41t85", 90 + .read_limit = 1, 91 + .sec = 1, 92 + .min = 2, 93 + .hour = 3, 94 + .day = 5, 95 + .mon = 6, 96 + .year = 7, 97 + .alarm_mon = 0xa, 98 + .alarm_hour = 0xc, 99 + .sqw = 0x13, 100 + }, 101 + }; 102 + static struct m41t00_chip_info *m41t00_chip; 43 103 44 104 ulong 45 105 m41t00_get_rtc_time(void) 46 106 { 47 - s32 sec, min, hour, day, mon, year; 48 - s32 sec1, min1, hour1, day1, mon1, year1; 49 - ulong limit = 10; 107 + s32 sec, min, hour, day, mon, year; 108 + s32 sec1, min1, hour1, day1, mon1, year1; 109 + u8 reads = 0; 110 + u8 buf[8], msgbuf[1] = { 0 }; /* offset into rtc's regs */ 111 + struct i2c_msg msgs[] = { 112 + { 113 + .addr = save_client->addr, 114 + .flags = 0, 115 + .len = 1, 116 + .buf = msgbuf, 117 + }, 118 + { 119 + .addr = save_client->addr, 120 + .flags = I2C_M_RD, 121 + .len = 8, 122 + .buf = buf, 123 + }, 124 + }; 50 125 51 126 sec = min = hour = day = mon = year = 0; 52 - sec1 = min1 = hour1 = day1 = mon1 = year1 = 0; 53 127 54 - mutex_lock(&m41t00_mutex); 55 128 do { 56 - if (((sec = i2c_smbus_read_byte_data(save_client, 0)) >= 0) 57 - && ((min = i2c_smbus_read_byte_data(save_client, 1)) 58 - >= 0) 59 - && ((hour = i2c_smbus_read_byte_data(save_client, 2)) 60 - >= 0) 61 - && ((day = i2c_smbus_read_byte_data(save_client, 4)) 62 - >= 0) 63 - && ((mon = i2c_smbus_read_byte_data(save_client, 5)) 64 - >= 0) 65 - && ((year = i2c_smbus_read_byte_data(save_client, 6)) 66 - >= 0) 67 - && ((sec == sec1) && (min == min1) && (hour == hour1) 68 - && (day == day1) && (mon == mon1) 69 - && (year == year1))) 70 - 71 - break; 129 + if (i2c_transfer(save_client->adapter, msgs, 2) < 0) 130 + goto read_err; 72 131 73 132 sec1 = sec; 74 133 min1 = min; ··· 130 81 day1 = day; 131 82 mon1 = mon; 132 83 year1 = year; 133 - } while (--limit > 0); 134 - mutex_unlock(&m41t00_mutex); 135 84 136 - if (limit == 0) { 137 - dev_warn(&save_client->dev, 138 - "m41t00: can't read rtc chip\n"); 139 - sec = min = hour = day = mon = year = 0; 140 - } 85 + sec = buf[m41t00_chip->sec] & 0x7f; 86 + min = buf[m41t00_chip->min] & 0x7f; 87 + hour = buf[m41t00_chip->hour] & 0x3f; 88 + day = buf[m41t00_chip->day] & 0x3f; 89 + mon = buf[m41t00_chip->mon] & 0x1f; 90 + year = buf[m41t00_chip->year]; 91 + } while ((++reads < m41t00_chip->read_limit) && ((sec != sec1) 92 + || (min != min1) || (hour != hour1) || (day != day1) 93 + || (mon != mon1) || (year != year1))); 141 94 142 - sec &= 0x7f; 143 - min &= 0x7f; 144 - hour &= 0x3f; 145 - day &= 0x3f; 146 - mon &= 0x1f; 147 - year &= 0xff; 95 + if ((m41t00_chip->read_limit > 1) && ((sec != sec1) || (min != min1) 96 + || (hour != hour1) || (day != day1) || (mon != mon1) 97 + || (year != year1))) 98 + goto read_err; 148 99 149 - BCD_TO_BIN(sec); 150 - BCD_TO_BIN(min); 151 - BCD_TO_BIN(hour); 152 - BCD_TO_BIN(day); 153 - BCD_TO_BIN(mon); 154 - BCD_TO_BIN(year); 100 + sec = BCD2BIN(sec); 101 + min = BCD2BIN(min); 102 + hour = BCD2BIN(hour); 103 + day = BCD2BIN(day); 104 + mon = BCD2BIN(mon); 105 + year = BCD2BIN(year); 155 106 156 107 year += 1900; 157 108 if (year < 1970) 158 109 year += 100; 159 110 160 111 return mktime(year, mon, day, hour, min, sec); 112 + 113 + read_err: 114 + dev_err(&save_client->dev, "m41t00_get_rtc_time: Read error\n"); 115 + return 0; 161 116 } 117 + EXPORT_SYMBOL_GPL(m41t00_get_rtc_time); 162 118 163 119 static void 164 120 m41t00_set(void *arg) 165 121 { 166 122 struct rtc_time tm; 167 - ulong nowtime = *(ulong *)arg; 123 + int nowtime = *(int *)arg; 124 + s32 sec, min, hour, day, mon, year; 125 + u8 wbuf[9], *buf = &wbuf[1], msgbuf[1] = { 0 }; 126 + struct i2c_msg msgs[] = { 127 + { 128 + .addr = save_client->addr, 129 + .flags = 0, 130 + .len = 1, 131 + .buf = msgbuf, 132 + }, 133 + { 134 + .addr = save_client->addr, 135 + .flags = I2C_M_RD, 136 + .len = 8, 137 + .buf = buf, 138 + }, 139 + }; 168 140 169 141 to_tm(nowtime, &tm); 170 142 tm.tm_year = (tm.tm_year - 1900) % 100; 171 143 172 - BIN_TO_BCD(tm.tm_sec); 173 - BIN_TO_BCD(tm.tm_min); 174 - BIN_TO_BCD(tm.tm_hour); 175 - BIN_TO_BCD(tm.tm_mon); 176 - BIN_TO_BCD(tm.tm_mday); 177 - BIN_TO_BCD(tm.tm_year); 144 + sec = BIN2BCD(tm.tm_sec); 145 + min = BIN2BCD(tm.tm_min); 146 + hour = BIN2BCD(tm.tm_hour); 147 + day = BIN2BCD(tm.tm_mday); 148 + mon = BIN2BCD(tm.tm_mon); 149 + year = BIN2BCD(tm.tm_year); 178 150 179 - mutex_lock(&m41t00_mutex); 180 - if ((i2c_smbus_write_byte_data(save_client, 0, tm.tm_sec & 0x7f) < 0) 181 - || (i2c_smbus_write_byte_data(save_client, 1, tm.tm_min & 0x7f) 182 - < 0) 183 - || (i2c_smbus_write_byte_data(save_client, 2, tm.tm_hour & 0x3f) 184 - < 0) 185 - || (i2c_smbus_write_byte_data(save_client, 4, tm.tm_mday & 0x3f) 186 - < 0) 187 - || (i2c_smbus_write_byte_data(save_client, 5, tm.tm_mon & 0x1f) 188 - < 0) 189 - || (i2c_smbus_write_byte_data(save_client, 6, tm.tm_year & 0xff) 190 - < 0)) 151 + /* Read reg values into buf[0..7]/wbuf[1..8] */ 152 + if (i2c_transfer(save_client->adapter, msgs, 2) < 0) { 153 + dev_err(&save_client->dev, "m41t00_set: Read error\n"); 154 + return; 155 + } 191 156 192 - dev_warn(&save_client->dev,"m41t00: can't write to rtc chip\n"); 157 + wbuf[0] = 0; /* offset into rtc's regs */ 158 + buf[m41t00_chip->sec] = (buf[m41t00_chip->sec] & ~0x7f) | (sec & 0x7f); 159 + buf[m41t00_chip->min] = (buf[m41t00_chip->min] & ~0x7f) | (min & 0x7f); 160 + buf[m41t00_chip->hour] = (buf[m41t00_chip->hour] & ~0x3f) | (hour& 0x3f); 161 + buf[m41t00_chip->day] = (buf[m41t00_chip->day] & ~0x3f) | (day & 0x3f); 162 + buf[m41t00_chip->mon] = (buf[m41t00_chip->mon] & ~0x1f) | (mon & 0x1f); 193 163 194 - mutex_unlock(&m41t00_mutex); 195 - return; 164 + if (i2c_master_send(save_client, wbuf, 9) < 0) 165 + dev_err(&save_client->dev, "m41t00_set: Write error\n"); 196 166 } 197 167 198 168 static ulong new_time; ··· 230 162 231 163 return 0; 232 164 } 165 + EXPORT_SYMBOL_GPL(m41t00_set_rtc_time); 166 + 167 + /* 168 + ***************************************************************************** 169 + * 170 + * platform_data Driver Interface 171 + * 172 + ***************************************************************************** 173 + */ 174 + static int __init 175 + m41t00_platform_probe(struct platform_device *pdev) 176 + { 177 + struct m41t00_platform_data *pdata; 178 + int i; 179 + 180 + if (pdev && (pdata = pdev->dev.platform_data)) { 181 + normal_addr[0] = pdata->i2c_addr; 182 + 183 + for (i=0; i<ARRAY_SIZE(m41t00_chip_info_tbl); i++) 184 + if (m41t00_chip_info_tbl[i].type == pdata->type) { 185 + m41t00_chip = &m41t00_chip_info_tbl[i]; 186 + m41t00_chip->sqw_freq = pdata->sqw_freq; 187 + return 0; 188 + } 189 + } 190 + return -ENODEV; 191 + } 192 + 193 + static int __exit 194 + m41t00_platform_remove(struct platform_device *pdev) 195 + { 196 + return 0; 197 + } 198 + 199 + static struct platform_driver m41t00_platform_driver = { 200 + .probe = m41t00_platform_probe, 201 + .remove = m41t00_platform_remove, 202 + .driver = { 203 + .owner = THIS_MODULE, 204 + .name = M41T00_DRV_NAME, 205 + }, 206 + }; 233 207 234 208 /* 235 209 ***************************************************************************** ··· 286 176 struct i2c_client *client; 287 177 int rc; 288 178 179 + if (!i2c_check_functionality(adap, I2C_FUNC_I2C 180 + | I2C_FUNC_SMBUS_BYTE_DATA)) 181 + return 0; 182 + 289 183 client = kzalloc(sizeof(struct i2c_client), GFP_KERNEL); 290 184 if (!client) 291 185 return -ENOMEM; 292 186 293 - strncpy(client->name, M41T00_DRV_NAME, I2C_NAME_SIZE); 187 + strlcpy(client->name, m41t00_chip->name, I2C_NAME_SIZE); 294 188 client->addr = addr; 295 189 client->adapter = adap; 296 190 client->driver = &m41t00_driver; 297 191 298 - if ((rc = i2c_attach_client(client)) != 0) { 299 - kfree(client); 300 - return rc; 192 + if ((rc = i2c_attach_client(client))) 193 + goto attach_err; 194 + 195 + if (m41t00_chip->type != M41T00_TYPE_M41T00) { 196 + /* If asked, disable SQW, set SQW frequency & re-enable */ 197 + if (m41t00_chip->sqw_freq) 198 + if (((rc = i2c_smbus_read_byte_data(client, 199 + m41t00_chip->alarm_mon)) < 0) 200 + || ((rc = i2c_smbus_write_byte_data(client, 201 + m41t00_chip->alarm_mon, rc & ~0x40)) <0) 202 + || ((rc = i2c_smbus_write_byte_data(client, 203 + m41t00_chip->sqw, 204 + m41t00_chip->sqw_freq)) < 0) 205 + || ((rc = i2c_smbus_write_byte_data(client, 206 + m41t00_chip->alarm_mon, rc | 0x40)) <0)) 207 + goto sqw_err; 208 + 209 + /* Make sure HT (Halt Update) bit is cleared */ 210 + if ((rc = i2c_smbus_read_byte_data(client, 211 + m41t00_chip->alarm_hour)) < 0) 212 + goto ht_err; 213 + 214 + if (rc & 0x40) 215 + if ((rc = i2c_smbus_write_byte_data(client, 216 + m41t00_chip->alarm_hour, rc & ~0x40))<0) 217 + goto ht_err; 301 218 } 302 219 303 - m41t00_wq = create_singlethread_workqueue("m41t00"); 220 + /* Make sure ST (stop) bit is cleared */ 221 + if ((rc = i2c_smbus_read_byte_data(client, m41t00_chip->sec)) < 0) 222 + goto st_err; 223 + 224 + if (rc & 0x80) 225 + if ((rc = i2c_smbus_write_byte_data(client, m41t00_chip->sec, 226 + rc & ~0x80)) < 0) 227 + goto st_err; 228 + 229 + m41t00_wq = create_singlethread_workqueue(m41t00_chip->name); 304 230 save_client = client; 305 231 return 0; 232 + 233 + st_err: 234 + dev_err(&client->dev, "m41t00_probe: Can't clear ST bit\n"); 235 + goto attach_err; 236 + ht_err: 237 + dev_err(&client->dev, "m41t00_probe: Can't clear HT bit\n"); 238 + goto attach_err; 239 + sqw_err: 240 + dev_err(&client->dev, "m41t00_probe: Can't set SQW Frequency\n"); 241 + attach_err: 242 + kfree(client); 243 + return rc; 306 244 } 307 245 308 246 static int ··· 362 204 static int 363 205 m41t00_detach(struct i2c_client *client) 364 206 { 365 - int rc; 207 + int rc; 366 208 367 209 if ((rc = i2c_detach_client(client)) == 0) { 368 210 kfree(client); ··· 383 225 static int __init 384 226 m41t00_init(void) 385 227 { 386 - return i2c_add_driver(&m41t00_driver); 228 + int rc; 229 + 230 + if (!(rc = platform_driver_register(&m41t00_platform_driver))) 231 + rc = i2c_add_driver(&m41t00_driver); 232 + return rc; 387 233 } 388 234 389 235 static void __exit 390 236 m41t00_exit(void) 391 237 { 392 238 i2c_del_driver(&m41t00_driver); 393 - return; 239 + platform_driver_unregister(&m41t00_platform_driver); 394 240 } 395 241 396 242 module_init(m41t00_init);
+2 -2
drivers/i2c/i2c-core.c
··· 916 916 } 917 917 918 918 s32 i2c_smbus_write_block_data(struct i2c_client *client, u8 command, 919 - u8 length, u8 *values) 919 + u8 length, const u8 *values) 920 920 { 921 921 union i2c_smbus_data data; 922 922 ··· 944 944 } 945 945 946 946 s32 i2c_smbus_write_i2c_block_data(struct i2c_client *client, u8 command, 947 - u8 length, u8 *values) 947 + u8 length, const u8 *values) 948 948 { 949 949 union i2c_smbus_data data; 950 950
+1 -4
drivers/i2c/i2c-dev.c
··· 426 426 427 427 /* register this i2c device with the driver core */ 428 428 i2c_dev->adap = adap; 429 - if (adap->dev.parent == &platform_bus) 430 - dev = &adap->dev; 431 - else 432 - dev = adap->dev.parent; 429 + dev = &adap->dev; 433 430 i2c_dev->class_dev = class_device_create(i2c_dev_class, NULL, 434 431 MKDEV(I2C_MAJOR, i2c_dev->minor), 435 432 dev, "i2c-%d", i2c_dev->minor);
+19
include/linux/i2c-ocores.h
··· 1 + /* 2 + * i2c-ocores.h - definitions for the i2c-ocores interface 3 + * 4 + * Peter Korsgaard <jacmet@sunsite.dk> 5 + * 6 + * This file is licensed under the terms of the GNU General Public License 7 + * version 2. This program is licensed "as is" without any warranty of any 8 + * kind, whether express or implied. 9 + */ 10 + 11 + #ifndef _LINUX_I2C_OCORES_H 12 + #define _LINUX_I2C_OCORES_H 13 + 14 + struct ocores_i2c_platform_data { 15 + u32 regstep; /* distance between registers */ 16 + u32 clock_khz; /* input clock in kHz */ 17 + }; 18 + 19 + #endif /* _LINUX_I2C_OCORES_H */
+2 -2
include/linux/i2c.h
··· 97 97 u8 command, u16 value); 98 98 extern s32 i2c_smbus_write_block_data(struct i2c_client * client, 99 99 u8 command, u8 length, 100 - u8 *values); 100 + const u8 *values); 101 101 /* Returns the number of read bytes */ 102 102 extern s32 i2c_smbus_read_i2c_block_data(struct i2c_client * client, 103 103 u8 command, u8 *values); 104 104 extern s32 i2c_smbus_write_i2c_block_data(struct i2c_client * client, 105 105 u8 command, u8 length, 106 - u8 *values); 106 + const u8 *values); 107 107 108 108 /* 109 109 * A driver is capable of handling one or more physical devices present on
+50
include/linux/m41t00.h
··· 1 + /* 2 + * Definitions for the ST M41T00 family of i2c rtc chips. 3 + * 4 + * Author: Mark A. Greer <mgreer@mvista.com> 5 + * 6 + * 2005, 2006 (c) MontaVista Software, Inc. This file is licensed under 7 + * the terms of the GNU General Public License version 2. This program 8 + * is licensed "as is" without any warranty of any kind, whether express 9 + * or implied. 10 + */ 11 + 12 + #ifndef _M41T00_H 13 + #define _M41T00_H 14 + 15 + #define M41T00_DRV_NAME "m41t00" 16 + #define M41T00_I2C_ADDR 0x68 17 + 18 + #define M41T00_TYPE_M41T00 0 19 + #define M41T00_TYPE_M41T81 81 20 + #define M41T00_TYPE_M41T85 85 21 + 22 + struct m41t00_platform_data { 23 + u8 type; 24 + u8 i2c_addr; 25 + u8 sqw_freq; 26 + }; 27 + 28 + /* SQW output disabled, this is default value by power on */ 29 + #define M41T00_SQW_DISABLE (0) 30 + 31 + #define M41T00_SQW_32KHZ (1<<4) /* 32.768 KHz */ 32 + #define M41T00_SQW_8KHZ (2<<4) /* 8.192 KHz */ 33 + #define M41T00_SQW_4KHZ (3<<4) /* 4.096 KHz */ 34 + #define M41T00_SQW_2KHZ (4<<4) /* 2.048 KHz */ 35 + #define M41T00_SQW_1KHZ (5<<4) /* 1.024 KHz */ 36 + #define M41T00_SQW_512HZ (6<<4) /* 512 Hz */ 37 + #define M41T00_SQW_256HZ (7<<4) /* 256 Hz */ 38 + #define M41T00_SQW_128HZ (8<<4) /* 128 Hz */ 39 + #define M41T00_SQW_64HZ (9<<4) /* 64 Hz */ 40 + #define M41T00_SQW_32HZ (10<<4) /* 32 Hz */ 41 + #define M41T00_SQW_16HZ (11<<4) /* 16 Hz */ 42 + #define M41T00_SQW_8HZ (12<<4) /* 8 Hz */ 43 + #define M41T00_SQW_4HZ (13<<4) /* 4 Hz */ 44 + #define M41T00_SQW_2HZ (14<<4) /* 2 Hz */ 45 + #define M41T00_SQW_1HZ (15<<4) /* 1 Hz */ 46 + 47 + extern ulong m41t00_get_rtc_time(void); 48 + extern int m41t00_set_rtc_time(ulong nowtime); 49 + 50 + #endif /* _M41T00_H */
+5
include/linux/pci_ids.h
··· 352 352 #define PCI_DEVICE_ID_ATI_RS480 0x5950 353 353 /* ATI IXP Chipset */ 354 354 #define PCI_DEVICE_ID_ATI_IXP200_IDE 0x4349 355 + #define PCI_DEVICE_ID_ATI_IXP200_SMBUS 0x4353 356 + #define PCI_DEVICE_ID_ATI_IXP300_SMBUS 0x4363 355 357 #define PCI_DEVICE_ID_ATI_IXP300_IDE 0x4369 356 358 #define PCI_DEVICE_ID_ATI_IXP300_SATA 0x436e 359 + #define PCI_DEVICE_ID_ATI_IXP400_SMBUS 0x4372 357 360 #define PCI_DEVICE_ID_ATI_IXP400_IDE 0x4376 358 361 #define PCI_DEVICE_ID_ATI_IXP400_SATA 0x4379 359 362 #define PCI_DEVICE_ID_ATI_IXP400_SATA2 0x437a ··· 1136 1133 #define PCI_DEVICE_ID_NVIDIA_QUADRO4_900XGL 0x0258 1137 1134 #define PCI_DEVICE_ID_NVIDIA_QUADRO4_750XGL 0x0259 1138 1135 #define PCI_DEVICE_ID_NVIDIA_QUADRO4_700XGL 0x025B 1136 + #define PCI_DEVICE_ID_NVIDIA_NFORCE_MCP51_SMBUS 0x0264 1139 1137 #define PCI_DEVICE_ID_NVIDIA_NFORCE_MCP51_IDE 0x0265 1140 1138 #define PCI_DEVICE_ID_NVIDIA_NFORCE_MCP51_SATA 0x0266 1141 1139 #define PCI_DEVICE_ID_NVIDIA_NFORCE_MCP51_SATA2 0x0267 1140 + #define PCI_DEVICE_ID_NVIDIA_NFORCE_MCP55_SMBUS 0x0368 1142 1141 #define PCI_DEVICE_ID_NVIDIA_NFORCE_MCP55_IDE 0x036E 1143 1142 #define PCI_DEVICE_ID_NVIDIA_NFORCE_MCP55_SATA 0x037E 1144 1143 #define PCI_DEVICE_ID_NVIDIA_NFORCE_MCP55_SATA2 0x037F