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

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

* 'hwmon-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/groeck/staging:
hwmon: (coretemp) Fix checkpatch errors
hwmon: Remove pkgtemp driver
hwmon: (coretemp) Merge pkgtemp with coretemp
hwmon: (pmbus) Add support for Analog Devices ADM1275
hwmon: (pmbus) Support for TI UCD90xxx series Sequencer and System Health Controllers
hwmon: (pmbus) Add support for TI UCD9200 series of PWM System Controllers
hwmon: (pmbus) Use device specific function to read fan configuration
hwmon: (pmbus) Expand scope of device specific get_status function
hwmon: (pmbus) Introduce infrastructure to detect sensors and limit registers
hwmon: Driver for MAX16065 System Manager and compatibles
hwmon: (sht15) add support for CRC validation
hwmon: (sht15) add support for the status register
hwmon: (sht15) clean-up the probe function
hwmon: (sht15) general code clean-up
hwmon: Add support for MAX6642

+3795 -1472
+60
Documentation/hwmon/adm1275
··· 1 + Kernel driver adm1275 2 + ===================== 3 + 4 + Supported chips: 5 + * Analog Devices ADM1275 6 + Prefix: 'adm1275' 7 + Addresses scanned: - 8 + Datasheet: www.analog.com/static/imported-files/data_sheets/ADM1275.pdf 9 + 10 + Author: Guenter Roeck <guenter.roeck@ericsson.com> 11 + 12 + 13 + Description 14 + ----------- 15 + 16 + This driver supports hardware montoring for Analog Devices ADM1275 Hot-Swap 17 + Controller and Digital Power Monitor. 18 + 19 + The ADM1275 is a hot-swap controller that allows a circuit board to be removed 20 + from or inserted into a live backplane. It also features current and voltage 21 + readback via an integrated 12-bit analog-to-digital converter (ADC), accessed 22 + using a PMBus. interface. 23 + 24 + The driver is a client driver to the core PMBus driver. Please see 25 + Documentation/hwmon/pmbus for details on PMBus client drivers. 26 + 27 + 28 + Usage Notes 29 + ----------- 30 + 31 + This driver does not auto-detect devices. You will have to instantiate the 32 + devices explicitly. Please see Documentation/i2c/instantiating-devices for 33 + details. 34 + 35 + 36 + Platform data support 37 + --------------------- 38 + 39 + The driver supports standard PMBus driver platform data. Please see 40 + Documentation/hwmon/pmbus for details. 41 + 42 + 43 + Sysfs entries 44 + ------------- 45 + 46 + The following attributes are supported. Limits are read-write; all other 47 + attributes are read-only. 48 + 49 + in1_label "vin1" or "vout1" depending on chip variant and 50 + configuration. 51 + in1_input Measured voltage. From READ_VOUT register. 52 + in1_min Minumum Voltage. From VOUT_UV_WARN_LIMIT register. 53 + in1_max Maximum voltage. From VOUT_OV_WARN_LIMIT register. 54 + in1_min_alarm Voltage low alarm. From VOLTAGE_UV_WARNING status. 55 + in1_max_alarm Voltage high alarm. From VOLTAGE_OV_WARNING status. 56 + 57 + curr1_label "iout1" 58 + curr1_input Measured current. From READ_IOUT register. 59 + curr1_max Maximum current. From IOUT_OC_WARN_LIMIT register. 60 + curr1_max_alarm Current high alarm. From IOUT_OC_WARN_LIMIT register.
+14 -7
Documentation/hwmon/coretemp
··· 15 15 16 16 Description 17 17 ----------- 18 + This driver permits reading the DTS (Digital Temperature Sensor) embedded 19 + inside Intel CPUs. This driver can read both the per-core and per-package 20 + temperature using the appropriate sensors. The per-package sensor is new; 21 + as of now, it is present only in the SandyBridge platform. The driver will 22 + show the temperature of all cores inside a package under a single device 23 + directory inside hwmon. 18 24 19 - This driver permits reading temperature sensor embedded inside Intel Core CPU. 20 25 Temperature is measured in degrees Celsius and measurement resolution is 21 26 1 degree C. Valid temperatures are from 0 to TjMax degrees C, because 22 27 the actual value of temperature register is in fact a delta from TjMax. ··· 32 27 may be raised, if the temperature grows enough (more than TjMax) to trigger 33 28 the Out-Of-Spec bit. Following table summarizes the exported sysfs files: 34 29 35 - temp1_input - Core temperature (in millidegrees Celsius). 36 - temp1_max - All cooling devices should be turned on (on Core2). 37 - temp1_crit - Maximum junction temperature (in millidegrees Celsius). 38 - temp1_crit_alarm - Set when Out-of-spec bit is set, never clears. 30 + All Sysfs entries are named with their core_id (represented here by 'X'). 31 + tempX_input - Core temperature (in millidegrees Celsius). 32 + tempX_max - All cooling devices should be turned on (on Core2). 33 + tempX_crit - Maximum junction temperature (in millidegrees Celsius). 34 + tempX_crit_alarm - Set when Out-of-spec bit is set, never clears. 39 35 Correct CPU operation is no longer guaranteed. 40 - temp1_label - Contains string "Core X", where X is processor 41 - number. 36 + tempX_label - Contains string "Core X", where X is processor 37 + number. For Package temp, this will be "Physical id Y", 38 + where Y is the package number. 42 39 43 40 The TjMax temperature is set to 85 degrees C if undocumented model specific 44 41 register (UMSR) 0xee has bit 30 set. If not the TjMax is 100 degrees C as
+98
Documentation/hwmon/max16065
··· 1 + Kernel driver max16065 2 + ====================== 3 + 4 + Supported chips: 5 + * Maxim MAX16065, MAX16066 6 + Prefixes: 'max16065', 'max16066' 7 + Addresses scanned: - 8 + Datasheet: 9 + http://datasheets.maxim-ic.com/en/ds/MAX16065-MAX16066.pdf 10 + * Maxim MAX16067 11 + Prefix: 'max16067' 12 + Addresses scanned: - 13 + Datasheet: 14 + http://datasheets.maxim-ic.com/en/ds/MAX16067.pdf 15 + * Maxim MAX16068 16 + Prefix: 'max16068' 17 + Addresses scanned: - 18 + Datasheet: 19 + http://datasheets.maxim-ic.com/en/ds/MAX16068.pdf 20 + * Maxim MAX16070/MAX16071 21 + Prefixes: 'max16070', 'max16071' 22 + Addresses scanned: - 23 + Datasheet: 24 + http://datasheets.maxim-ic.com/en/ds/MAX16070-MAX16071.pdf 25 + 26 + 27 + Author: Guenter Roeck <guenter.roeck@ericsson.com> 28 + 29 + 30 + Description 31 + ----------- 32 + 33 + [From datasheets] The MAX16065/MAX16066 flash-configurable system managers 34 + monitor and sequence multiple system voltages. The MAX16065/MAX16066 can also 35 + accurately monitor (+/-2.5%) one current channel using a dedicated high-side 36 + current-sense amplifier. The MAX16065 manages up to twelve system voltages 37 + simultaneously, and the MAX16066 manages up to eight supply voltages. 38 + 39 + The MAX16067 flash-configurable system manager monitors and sequences multiple 40 + system voltages. The MAX16067 manages up to six system voltages simultaneously. 41 + 42 + The MAX16068 flash-configurable system manager monitors and manages up to six 43 + system voltages simultaneously. 44 + 45 + The MAX16070/MAX16071 flash-configurable system monitors supervise multiple 46 + system voltages. The MAX16070/MAX16071 can also accurately monitor (+/-2.5%) 47 + one current channel using a dedicated high-side current-sense amplifier. The 48 + MAX16070 monitors up to twelve system voltages simultaneously, and the MAX16071 49 + monitors up to eight supply voltages. 50 + 51 + Each monitored channel has its own low and high critical limits. MAX16065, 52 + MAX16066, MAX16070, and MAX16071 support an additional limit which is 53 + configurable as either low or high secondary limit. MAX16065, MAX16066, 54 + MAX16070, and MAX16071 also support supply current monitoring. 55 + 56 + 57 + Usage Notes 58 + ----------- 59 + 60 + This driver does not probe for devices, since there is no register which 61 + can be safely used to identify the chip. You will have to instantiate 62 + the devices explicitly. Please see Documentation/i2c/instantiating-devices for 63 + details. 64 + 65 + 66 + Sysfs entries 67 + ------------- 68 + 69 + in[0-11]_input Input voltage measurements. 70 + 71 + in12_input Voltage on CSP (Current Sense Positive) pin. 72 + Only if the chip supports current sensing and if 73 + current sensing is enabled. 74 + 75 + in[0-11]_min Low warning limit. 76 + Supported on MAX16065, MAX16066, MAX16070, and MAX16071 77 + only. 78 + 79 + in[0-11]_max High warning limit. 80 + Supported on MAX16065, MAX16066, MAX16070, and MAX16071 81 + only. 82 + 83 + Either low or high warning limits are supported 84 + (depending on chip configuration), but not both. 85 + 86 + in[0-11]_lcrit Low critical limit. 87 + 88 + in[0-11]_crit High critical limit. 89 + 90 + in[0-11]_alarm Input voltage alarm. 91 + 92 + curr1_input Current sense input; only if the chip supports current 93 + sensing and if current sensing is enabled. 94 + Displayed current assumes 0.001 Ohm current sense 95 + resistor. 96 + 97 + curr1_alarm Overcurrent alarm; only if the chip supports current 98 + sensing and if current sensing is enabled.
+21
Documentation/hwmon/max6642
··· 1 + Kernel driver max6642 2 + ===================== 3 + 4 + Supported chips: 5 + * Maxim MAX6642 6 + Prefix: 'max6642' 7 + Addresses scanned: I2C 0x48-0x4f 8 + Datasheet: Publicly available at the Maxim website 9 + http://datasheets.maxim-ic.com/en/ds/MAX6642.pdf 10 + 11 + Authors: 12 + Per Dalen <per.dalen@appeartv.com> 13 + 14 + Description 15 + ----------- 16 + 17 + The MAX6642 is a digital temperature sensor. It senses its own temperature as 18 + well as the temperature on one external diode. 19 + 20 + All temperature values are given in degrees Celsius. Resolution 21 + is 0.25 degree for the local temperature and for the remote temperature.
-36
Documentation/hwmon/pkgtemp
··· 1 - Kernel driver pkgtemp 2 - ====================== 3 - 4 - Supported chips: 5 - * Intel family 6 - Prefix: 'pkgtemp' 7 - CPUID: 8 - Datasheet: Intel 64 and IA-32 Architectures Software Developer's Manual 9 - Volume 3A: System Programming Guide 10 - 11 - Author: Fenghua Yu 12 - 13 - Description 14 - ----------- 15 - 16 - This driver permits reading package level temperature sensor embedded inside 17 - Intel CPU package. The sensors can be in core, uncore, memory controller, or 18 - other components in a package. The feature is first implemented in Intel Sandy 19 - Bridge platform. 20 - 21 - Temperature is measured in degrees Celsius and measurement resolution is 22 - 1 degree C. Valid temperatures are from 0 to TjMax degrees C, because the actual 23 - value of temperature register is in fact a delta from TjMax. 24 - 25 - Temperature known as TjMax is the maximum junction temperature of package. 26 - We get this from MSR_IA32_TEMPERATURE_TARGET. If the MSR is not accessible, 27 - we define TjMax as 100 degrees Celsius. At this temperature, protection 28 - mechanism will perform actions to forcibly cool down the package. Alarm 29 - may be raised, if the temperature grows enough (more than TjMax) to trigger 30 - the Out-Of-Spec bit. Following table summarizes the exported sysfs files: 31 - 32 - temp1_input - Package temperature (in millidegrees Celsius). 33 - temp1_max - All cooling devices should be turned on. 34 - temp1_crit - Maximum junction temperature (in millidegrees Celsius). 35 - temp1_crit_alarm - Set when Out-of-spec bit is set, never clears. 36 - Correct CPU operation is no longer guaranteed.
+74
Documentation/hwmon/sht15
··· 1 + Kernel driver sht15 2 + =================== 3 + 4 + Authors: 5 + * Wouter Horre 6 + * Jonathan Cameron 7 + * Vivien Didelot <vivien.didelot@savoirfairelinux.com> 8 + * Jerome Oufella <jerome.oufella@savoirfairelinux.com> 9 + 10 + Supported chips: 11 + * Sensirion SHT10 12 + Prefix: 'sht10' 13 + 14 + * Sensirion SHT11 15 + Prefix: 'sht11' 16 + 17 + * Sensirion SHT15 18 + Prefix: 'sht15' 19 + 20 + * Sensirion SHT71 21 + Prefix: 'sht71' 22 + 23 + * Sensirion SHT75 24 + Prefix: 'sht75' 25 + 26 + Datasheet: Publicly available at the Sensirion website 27 + http://www.sensirion.ch/en/pdf/product_information/Datasheet-humidity-sensor-SHT1x.pdf 28 + 29 + Description 30 + ----------- 31 + 32 + The SHT10, SHT11, SHT15, SHT71, and SHT75 are humidity and temperature 33 + sensors. 34 + 35 + The devices communicate using two GPIO lines. 36 + 37 + Supported resolutions for the measurements are 14 bits for temperature and 12 38 + bits for humidity, or 12 bits for temperature and 8 bits for humidity. 39 + 40 + The humidity calibration coefficients are programmed into an OTP memory on the 41 + chip. These coefficients are used to internally calibrate the signals from the 42 + sensors. Disabling the reload of those coefficients allows saving 10ms for each 43 + measurement and decrease power consumption, while loosing on precision. 44 + 45 + Some options may be set directly in the sht15_platform_data structure 46 + or via sysfs attributes. 47 + 48 + Notes: 49 + * The regulator supply name is set to "vcc". 50 + * If a CRC validation fails, a soft reset command is sent, which resets 51 + status register to its hardware default value, but the driver will try to 52 + restore the previous device configuration. 53 + 54 + Platform data 55 + ------------- 56 + 57 + * checksum: 58 + set it to true to enable CRC validation of the readings (default to false). 59 + * no_otp_reload: 60 + flag to indicate not to reload from OTP (default to false). 61 + * low_resolution: 62 + flag to indicate the temp/humidity resolution to use (default to false). 63 + 64 + Sysfs interface 65 + --------------- 66 + 67 + * temp1_input: temperature input 68 + * humidity1_input: humidity input 69 + * heater_enable: write 1 in this attribute to enable the on-chip heater, 70 + 0 to disable it. Be careful not to enable the heater 71 + for too long. 72 + * temp1_fault: if 1, this means that the voltage is low (below 2.47V) and 73 + measurement may be invalid. 74 + * humidity1_fault: same as temp1_fault.
+110
Documentation/hwmon/ucd9000
··· 1 + Kernel driver ucd9000 2 + ===================== 3 + 4 + Supported chips: 5 + * TI UCD90120, UCD90124, UCD9090, and UCD90910 6 + Prefixes: 'ucd90120', 'ucd90124', 'ucd9090', 'ucd90910' 7 + Addresses scanned: - 8 + Datasheets: 9 + http://focus.ti.com/lit/ds/symlink/ucd90120.pdf 10 + http://focus.ti.com/lit/ds/symlink/ucd90124.pdf 11 + http://focus.ti.com/lit/ds/symlink/ucd9090.pdf 12 + http://focus.ti.com/lit/ds/symlink/ucd90910.pdf 13 + 14 + Author: Guenter Roeck <guenter.roeck@ericsson.com> 15 + 16 + 17 + Description 18 + ----------- 19 + 20 + From datasheets: 21 + 22 + The UCD90120 Power Supply Sequencer and System Health Monitor monitors and 23 + sequences up to 12 independent voltage rails. The device integrates a 12-bit 24 + ADC with a 2.5V internal reference for monitoring up to 13 power supply voltage, 25 + current, or temperature inputs. 26 + 27 + The UCD90124 is a 12-rail PMBus/I2C addressable power-supply sequencer and 28 + system-health monitor. The device integrates a 12-bit ADC for monitoring up to 29 + 13 power-supply voltage, current, or temperature inputs. Twenty-six GPIO pins 30 + can be used for power supply enables, power-on reset signals, external 31 + interrupts, cascading, or other system functions. Twelve of these pins offer PWM 32 + functionality. Using these pins, the UCD90124 offers support for fan control, 33 + margining, and general-purpose PWM functions. 34 + 35 + The UCD9090 is a 10-rail PMBus/I2C addressable power-supply sequencer and 36 + monitor. The device integrates a 12-bit ADC for monitoring up to 10 power-supply 37 + voltage inputs. Twenty-three GPIO pins can be used for power supply enables, 38 + power-on reset signals, external interrupts, cascading, or other system 39 + functions. Ten of these pins offer PWM functionality. Using these pins, the 40 + UCD9090 offers support for margining, and general-purpose PWM functions. 41 + 42 + The UCD90910 is a ten-rail I2C / PMBus addressable power-supply sequencer and 43 + system-health monitor. The device integrates a 12-bit ADC for monitoring up to 44 + 13 power-supply voltage, current, or temperature inputs. 45 + 46 + This driver is a client driver to the core PMBus driver. Please see 47 + Documentation/hwmon/pmbus for details on PMBus client drivers. 48 + 49 + 50 + Usage Notes 51 + ----------- 52 + 53 + This driver does not auto-detect devices. You will have to instantiate the 54 + devices explicitly. Please see Documentation/i2c/instantiating-devices for 55 + details. 56 + 57 + 58 + Platform data support 59 + --------------------- 60 + 61 + The driver supports standard PMBus driver platform data. Please see 62 + Documentation/hwmon/pmbus for details. 63 + 64 + 65 + Sysfs entries 66 + ------------- 67 + 68 + The following attributes are supported. Limits are read-write; all other 69 + attributes are read-only. 70 + 71 + in[1-12]_label "vout[1-12]". 72 + in[1-12]_input Measured voltage. From READ_VOUT register. 73 + in[1-12]_min Minumum Voltage. From VOUT_UV_WARN_LIMIT register. 74 + in[1-12]_max Maximum voltage. From VOUT_OV_WARN_LIMIT register. 75 + in[1-12]_lcrit Critical minumum Voltage. VOUT_UV_FAULT_LIMIT register. 76 + in[1-12]_crit Critical maximum voltage. From VOUT_OV_FAULT_LIMIT register. 77 + in[1-12]_min_alarm Voltage low alarm. From VOLTAGE_UV_WARNING status. 78 + in[1-12]_max_alarm Voltage high alarm. From VOLTAGE_OV_WARNING status. 79 + in[1-12]_lcrit_alarm Voltage critical low alarm. From VOLTAGE_UV_FAULT status. 80 + in[1-12]_crit_alarm Voltage critical high alarm. From VOLTAGE_OV_FAULT status. 81 + 82 + curr[1-12]_label "iout[1-12]". 83 + curr[1-12]_input Measured current. From READ_IOUT register. 84 + curr[1-12]_max Maximum current. From IOUT_OC_WARN_LIMIT register. 85 + curr[1-12]_lcrit Critical minumum output current. From IOUT_UC_FAULT_LIMIT 86 + register. 87 + curr[1-12]_crit Critical maximum current. From IOUT_OC_FAULT_LIMIT register. 88 + curr[1-12]_max_alarm Current high alarm. From IOUT_OC_WARNING status. 89 + curr[1-12]_crit_alarm Current critical high alarm. From IOUT_OC_FAULT status. 90 + 91 + For each attribute index, either voltage or current is 92 + reported, but not both. If voltage or current is 93 + reported depends on the chip configuration. 94 + 95 + temp[1-2]_input Measured temperatures. From READ_TEMPERATURE_1 and 96 + READ_TEMPERATURE_2 registers. 97 + temp[1-2]_max Maximum temperature. From OT_WARN_LIMIT register. 98 + temp[1-2]_crit Critical high temperature. From OT_FAULT_LIMIT register. 99 + temp[1-2]_max_alarm Temperature high alarm. 100 + temp[1-2]_crit_alarm Temperature critical high alarm. 101 + 102 + fan[1-4]_input Fan RPM. 103 + fan[1-4]_alarm Fan alarm. 104 + fan[1-4]_fault Fan fault. 105 + 106 + Fan attributes are only available on chips supporting 107 + fan control (UCD90124, UCD90910). Attribute files are 108 + created only for enabled fans. 109 + Note that even though UCD90910 supports up to 10 fans, 110 + only up to four fans are currently supported.
+112
Documentation/hwmon/ucd9200
··· 1 + Kernel driver ucd9200 2 + ===================== 3 + 4 + Supported chips: 5 + * TI UCD9220, UCD9222, UCD9224, UCD9240, UCD9244, UCD9246, and UCD9248 6 + Prefixes: 'ucd9220', 'ucd9222', 'ucd9224', 'ucd9240', 'ucd9244', 'ucd9246', 7 + 'ucd9248' 8 + Addresses scanned: - 9 + Datasheets: 10 + http://focus.ti.com/lit/ds/symlink/ucd9220.pdf 11 + http://focus.ti.com/lit/ds/symlink/ucd9222.pdf 12 + http://focus.ti.com/lit/ds/symlink/ucd9224.pdf 13 + http://focus.ti.com/lit/ds/symlink/ucd9240.pdf 14 + http://focus.ti.com/lit/ds/symlink/ucd9244.pdf 15 + http://focus.ti.com/lit/ds/symlink/ucd9246.pdf 16 + http://focus.ti.com/lit/ds/symlink/ucd9248.pdf 17 + 18 + Author: Guenter Roeck <guenter.roeck@ericsson.com> 19 + 20 + 21 + Description 22 + ----------- 23 + 24 + [From datasheets] UCD9220, UCD9222, UCD9224, UCD9240, UCD9244, UCD9246, and 25 + UCD9248 are multi-rail, multi-phase synchronous buck digital PWM controllers 26 + designed for non-isolated DC/DC power applications. The devices integrate 27 + dedicated circuitry for DC/DC loop management with flash memory and a serial 28 + interface to support configuration, monitoring and management. 29 + 30 + This driver is a client driver to the core PMBus driver. Please see 31 + Documentation/hwmon/pmbus for details on PMBus client drivers. 32 + 33 + 34 + Usage Notes 35 + ----------- 36 + 37 + This driver does not auto-detect devices. You will have to instantiate the 38 + devices explicitly. Please see Documentation/i2c/instantiating-devices for 39 + details. 40 + 41 + 42 + Platform data support 43 + --------------------- 44 + 45 + The driver supports standard PMBus driver platform data. Please see 46 + Documentation/hwmon/pmbus for details. 47 + 48 + 49 + Sysfs entries 50 + ------------- 51 + 52 + The following attributes are supported. Limits are read-write; all other 53 + attributes are read-only. 54 + 55 + in1_label "vin". 56 + in1_input Measured voltage. From READ_VIN register. 57 + in1_min Minumum Voltage. From VIN_UV_WARN_LIMIT register. 58 + in1_max Maximum voltage. From VIN_OV_WARN_LIMIT register. 59 + in1_lcrit Critical minumum Voltage. VIN_UV_FAULT_LIMIT register. 60 + in1_crit Critical maximum voltage. From VIN_OV_FAULT_LIMIT register. 61 + in1_min_alarm Voltage low alarm. From VIN_UV_WARNING status. 62 + in1_max_alarm Voltage high alarm. From VIN_OV_WARNING status. 63 + in1_lcrit_alarm Voltage critical low alarm. From VIN_UV_FAULT status. 64 + in1_crit_alarm Voltage critical high alarm. From VIN_OV_FAULT status. 65 + 66 + in[2-5]_label "vout[1-4]". 67 + in[2-5]_input Measured voltage. From READ_VOUT register. 68 + in[2-5]_min Minumum Voltage. From VOUT_UV_WARN_LIMIT register. 69 + in[2-5]_max Maximum voltage. From VOUT_OV_WARN_LIMIT register. 70 + in[2-5]_lcrit Critical minumum Voltage. VOUT_UV_FAULT_LIMIT register. 71 + in[2-5]_crit Critical maximum voltage. From VOUT_OV_FAULT_LIMIT register. 72 + in[2-5]_min_alarm Voltage low alarm. From VOLTAGE_UV_WARNING status. 73 + in[2-5]_max_alarm Voltage high alarm. From VOLTAGE_OV_WARNING status. 74 + in[2-5]_lcrit_alarm Voltage critical low alarm. From VOLTAGE_UV_FAULT status. 75 + in[2-5]_crit_alarm Voltage critical high alarm. From VOLTAGE_OV_FAULT status. 76 + 77 + curr1_label "iin". 78 + curr1_input Measured current. From READ_IIN register. 79 + 80 + curr[2-5]_label "iout[1-4]". 81 + curr[2-5]_input Measured current. From READ_IOUT register. 82 + curr[2-5]_max Maximum current. From IOUT_OC_WARN_LIMIT register. 83 + curr[2-5]_lcrit Critical minumum output current. From IOUT_UC_FAULT_LIMIT 84 + register. 85 + curr[2-5]_crit Critical maximum current. From IOUT_OC_FAULT_LIMIT register. 86 + curr[2-5]_max_alarm Current high alarm. From IOUT_OC_WARNING status. 87 + curr[2-5]_crit_alarm Current critical high alarm. From IOUT_OC_FAULT status. 88 + 89 + power1_input Measured input power. From READ_PIN register. 90 + power1_label "pin" 91 + 92 + power[2-5]_input Measured output power. From READ_POUT register. 93 + power[2-5]_label "pout[1-4]" 94 + 95 + The number of output voltage, current, and power 96 + attribute sets is determined by the number of enabled 97 + rails. See chip datasheets for details. 98 + 99 + temp[1-5]_input Measured temperatures. From READ_TEMPERATURE_1 and 100 + READ_TEMPERATURE_2 registers. 101 + temp1 is the chip internal temperature. temp[2-5] are 102 + rail temperatures. temp[2-5] attributes are only 103 + created for enabled rails. See chip datasheets for 104 + details. 105 + temp[1-5]_max Maximum temperature. From OT_WARN_LIMIT register. 106 + temp[1-5]_crit Critical high temperature. From OT_FAULT_LIMIT register. 107 + temp[1-5]_max_alarm Temperature high alarm. 108 + temp[1-5]_crit_alarm Temperature critical high alarm. 109 + 110 + fan1_input Fan RPM. ucd9240 only. 111 + fan1_alarm Fan alarm. ucd9240 only. 112 + fan1_fault Fan fault. ucd9240 only.
+59 -7
drivers/hwmon/Kconfig
··· 408 408 sensor inside your CPU. Most of the family 6 CPUs 409 409 are supported. Check Documentation/hwmon/coretemp for details. 410 410 411 - config SENSORS_PKGTEMP 412 - tristate "Intel processor package temperature sensor" 413 - depends on X86 && EXPERIMENTAL 414 - help 415 - If you say yes here you get support for the package level temperature 416 - sensor inside your CPU. Check documentation/driver for details. 417 - 418 411 config SENSORS_IBMAEM 419 412 tristate "IBM Active Energy Manager temperature/power sensors and control" 420 413 select IPMI_SI ··· 701 708 This driver can also be built as a module. If so, the module 702 709 will be called max1111. 703 710 711 + config SENSORS_MAX16065 712 + tristate "Maxim MAX16065 System Manager and compatibles" 713 + depends on I2C 714 + help 715 + If you say yes here you get support for hardware monitoring 716 + capabilities of the following Maxim System Manager chips. 717 + MAX16065 718 + MAX16066 719 + MAX16067 720 + MAX16068 721 + MAX16070 722 + MAX16071 723 + 724 + This driver can also be built as a module. If so, the module 725 + will be called max16065. 726 + 704 727 config SENSORS_MAX1619 705 728 tristate "Maxim MAX1619 sensor chip" 706 729 depends on I2C ··· 735 726 736 727 This driver can also be built as a module. If so, the module 737 728 will be called max6639. 729 + 730 + config SENSORS_MAX6642 731 + tristate "Maxim MAX6642 sensor chip" 732 + depends on I2C && EXPERIMENTAL 733 + help 734 + If you say yes here you get support for MAX6642 sensor chip. 735 + MAX6642 is a SMBus-Compatible Remote/Local Temperature Sensor 736 + with Overtemperature Alarm from Maxim. 737 + 738 + This driver can also be built as a module. If so, the module 739 + will be called max6642. 738 740 739 741 config SENSORS_MAX6650 740 742 tristate "Maxim MAX6650 sensor chip" ··· 820 800 This driver can also be built as a module. If so, the module will 821 801 be called pmbus. 822 802 803 + config SENSORS_ADM1275 804 + tristate "Analog Devices ADM1275" 805 + default n 806 + help 807 + If you say yes here you get hardware monitoring support for Analog 808 + Devices ADM1275 Hot-Swap Controller and Digital Power Monitor. 809 + 810 + This driver can also be built as a module. If so, the module will 811 + be called adm1275. 812 + 823 813 config SENSORS_MAX16064 824 814 tristate "Maxim MAX16064" 825 815 default n ··· 859 829 860 830 This driver can also be built as a module. If so, the module will 861 831 be called max8688. 832 + 833 + config SENSORS_UCD9000 834 + tristate "TI UCD90120, UCD90124, UCD9090, UCD90910" 835 + default n 836 + help 837 + If you say yes here you get hardware monitoring support for TI 838 + UCD90120, UCD90124, UCD9090, UCD90910 Sequencer and System Health 839 + Controllers. 840 + 841 + This driver can also be built as a module. If so, the module will 842 + be called ucd9000. 843 + 844 + config SENSORS_UCD9200 845 + tristate "TI UCD9220, UCD9222, UCD9224, UCD9240, UCD9244, UCD9246, UCD9248" 846 + default n 847 + help 848 + If you say yes here you get hardware monitoring support for TI 849 + UCD9220, UCD9222, UCD9224, UCD9240, UCD9244, UCD9246, and UCD9248 850 + Digital PWM System Controllers. 851 + 852 + This driver can also be built as a module. If so, the module will 853 + be called ucd9200. 862 854 863 855 endif # PMBUS 864 856
+5 -1
drivers/hwmon/Makefile
··· 40 40 obj-$(CONFIG_SENSORS_ASC7621) += asc7621.o 41 41 obj-$(CONFIG_SENSORS_ATXP1) += atxp1.o 42 42 obj-$(CONFIG_SENSORS_CORETEMP) += coretemp.o 43 - obj-$(CONFIG_SENSORS_PKGTEMP) += pkgtemp.o 44 43 obj-$(CONFIG_SENSORS_DME1737) += dme1737.o 45 44 obj-$(CONFIG_SENSORS_DS620) += ds620.o 46 45 obj-$(CONFIG_SENSORS_DS1621) += ds1621.o ··· 82 83 obj-$(CONFIG_SENSORS_LTC4245) += ltc4245.o 83 84 obj-$(CONFIG_SENSORS_LTC4261) += ltc4261.o 84 85 obj-$(CONFIG_SENSORS_MAX1111) += max1111.o 86 + obj-$(CONFIG_SENSORS_MAX16065) += max16065.o 85 87 obj-$(CONFIG_SENSORS_MAX1619) += max1619.o 86 88 obj-$(CONFIG_SENSORS_MAX6639) += max6639.o 89 + obj-$(CONFIG_SENSORS_MAX6642) += max6642.o 87 90 obj-$(CONFIG_SENSORS_MAX6650) += max6650.o 88 91 obj-$(CONFIG_SENSORS_MC13783_ADC)+= mc13783-adc.o 89 92 obj-$(CONFIG_SENSORS_PC87360) += pc87360.o ··· 119 118 # PMBus drivers 120 119 obj-$(CONFIG_PMBUS) += pmbus_core.o 121 120 obj-$(CONFIG_SENSORS_PMBUS) += pmbus.o 121 + obj-$(CONFIG_SENSORS_ADM1275) += adm1275.o 122 122 obj-$(CONFIG_SENSORS_MAX16064) += max16064.o 123 123 obj-$(CONFIG_SENSORS_MAX34440) += max34440.o 124 124 obj-$(CONFIG_SENSORS_MAX8688) += max8688.o 125 + obj-$(CONFIG_SENSORS_UCD9000) += ucd9000.o 126 + obj-$(CONFIG_SENSORS_UCD9200) += ucd9200.o 125 127 126 128 ccflags-$(CONFIG_HWMON_DEBUG_CHIP) := -DDEBUG 127 129
+121
drivers/hwmon/adm1275.c
··· 1 + /* 2 + * Hardware monitoring driver for Analog Devices ADM1275 Hot-Swap Controller 3 + * and Digital Power Monitor 4 + * 5 + * Copyright (c) 2011 Ericsson AB. 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 + 18 + #include <linux/kernel.h> 19 + #include <linux/module.h> 20 + #include <linux/init.h> 21 + #include <linux/err.h> 22 + #include <linux/slab.h> 23 + #include <linux/i2c.h> 24 + #include "pmbus.h" 25 + 26 + #define ADM1275_PMON_CONFIG 0xd4 27 + 28 + #define ADM1275_VIN_VOUT_SELECT (1 << 6) 29 + #define ADM1275_VRANGE (1 << 5) 30 + 31 + static int adm1275_probe(struct i2c_client *client, 32 + const struct i2c_device_id *id) 33 + { 34 + int config; 35 + struct pmbus_driver_info *info; 36 + 37 + if (!i2c_check_functionality(client->adapter, 38 + I2C_FUNC_SMBUS_READ_BYTE_DATA)) 39 + return -ENODEV; 40 + 41 + info = kzalloc(sizeof(struct pmbus_driver_info), GFP_KERNEL); 42 + if (!info) 43 + return -ENOMEM; 44 + 45 + config = i2c_smbus_read_byte_data(client, ADM1275_PMON_CONFIG); 46 + if (config < 0) 47 + return config; 48 + 49 + info->pages = 1; 50 + info->direct[PSC_VOLTAGE_IN] = true; 51 + info->direct[PSC_VOLTAGE_OUT] = true; 52 + info->direct[PSC_CURRENT_OUT] = true; 53 + info->m[PSC_CURRENT_OUT] = 800; 54 + info->b[PSC_CURRENT_OUT] = 20475; 55 + info->R[PSC_CURRENT_OUT] = -1; 56 + info->func[0] = PMBUS_HAVE_IOUT | PMBUS_HAVE_STATUS_IOUT; 57 + 58 + if (config & ADM1275_VRANGE) { 59 + info->m[PSC_VOLTAGE_IN] = 19045; 60 + info->b[PSC_VOLTAGE_IN] = 0; 61 + info->R[PSC_VOLTAGE_IN] = -2; 62 + info->m[PSC_VOLTAGE_OUT] = 19045; 63 + info->b[PSC_VOLTAGE_OUT] = 0; 64 + info->R[PSC_VOLTAGE_OUT] = -2; 65 + } else { 66 + info->m[PSC_VOLTAGE_IN] = 6666; 67 + info->b[PSC_VOLTAGE_IN] = 0; 68 + info->R[PSC_VOLTAGE_IN] = -1; 69 + info->m[PSC_VOLTAGE_OUT] = 6666; 70 + info->b[PSC_VOLTAGE_OUT] = 0; 71 + info->R[PSC_VOLTAGE_OUT] = -1; 72 + } 73 + 74 + if (config & ADM1275_VIN_VOUT_SELECT) 75 + info->func[0] |= PMBUS_HAVE_VOUT | PMBUS_HAVE_STATUS_VOUT; 76 + else 77 + info->func[0] |= PMBUS_HAVE_VIN | PMBUS_HAVE_STATUS_INPUT; 78 + 79 + return pmbus_do_probe(client, id, info); 80 + } 81 + 82 + static int adm1275_remove(struct i2c_client *client) 83 + { 84 + const struct pmbus_driver_info *info = pmbus_get_driver_info(client); 85 + int ret; 86 + 87 + ret = pmbus_do_remove(client); 88 + kfree(info); 89 + return ret; 90 + } 91 + 92 + static const struct i2c_device_id adm1275_id[] = { 93 + {"adm1275", 0}, 94 + { } 95 + }; 96 + MODULE_DEVICE_TABLE(i2c, adm1275_id); 97 + 98 + static struct i2c_driver adm1275_driver = { 99 + .driver = { 100 + .name = "adm1275", 101 + }, 102 + .probe = adm1275_probe, 103 + .remove = adm1275_remove, 104 + .id_table = adm1275_id, 105 + }; 106 + 107 + static int __init adm1275_init(void) 108 + { 109 + return i2c_add_driver(&adm1275_driver); 110 + } 111 + 112 + static void __exit adm1275_exit(void) 113 + { 114 + i2c_del_driver(&adm1275_driver); 115 + } 116 + 117 + MODULE_AUTHOR("Guenter Roeck"); 118 + MODULE_DESCRIPTION("PMBus driver for Analog Devices ADM1275"); 119 + MODULE_LICENSE("GPL"); 120 + module_init(adm1275_init); 121 + module_exit(adm1275_exit);
+497 -245
drivers/hwmon/coretemp.c
··· 35 35 #include <linux/platform_device.h> 36 36 #include <linux/cpu.h> 37 37 #include <linux/pci.h> 38 + #include <linux/smp.h> 38 39 #include <asm/msr.h> 39 40 #include <asm/processor.h> 40 - #include <asm/smp.h> 41 41 42 42 #define DRVNAME "coretemp" 43 43 44 - typedef enum { SHOW_TEMP, SHOW_TJMAX, SHOW_TTARGET, SHOW_LABEL, 45 - SHOW_NAME } SHOW; 44 + #define BASE_SYSFS_ATTR_NO 2 /* Sysfs Base attr no for coretemp */ 45 + #define NUM_REAL_CORES 16 /* Number of Real cores per cpu */ 46 + #define CORETEMP_NAME_LENGTH 17 /* String Length of attrs */ 47 + #define MAX_ATTRS 5 /* Maximum no of per-core attrs */ 48 + #define MAX_CORE_DATA (NUM_REAL_CORES + BASE_SYSFS_ATTR_NO) 49 + 50 + #ifdef CONFIG_SMP 51 + #define TO_PHYS_ID(cpu) cpu_data(cpu).phys_proc_id 52 + #define TO_CORE_ID(cpu) cpu_data(cpu).cpu_core_id 53 + #define TO_ATTR_NO(cpu) (TO_CORE_ID(cpu) + BASE_SYSFS_ATTR_NO) 54 + #else 55 + #define TO_PHYS_ID(cpu) (cpu) 56 + #define TO_CORE_ID(cpu) (cpu) 57 + #define TO_ATTR_NO(cpu) (cpu) 58 + #endif 46 59 47 60 /* 48 - * Functions declaration 61 + * Per-Core Temperature Data 62 + * @last_updated: The time when the current temperature value was updated 63 + * earlier (in jiffies). 64 + * @cpu_core_id: The CPU Core from which temperature values should be read 65 + * This value is passed as "id" field to rdmsr/wrmsr functions. 66 + * @status_reg: One of IA32_THERM_STATUS or IA32_PACKAGE_THERM_STATUS, 67 + * from where the temperature values should be read. 68 + * @is_pkg_data: If this is 1, the temp_data holds pkgtemp data. 69 + * Otherwise, temp_data holds coretemp data. 70 + * @valid: If this is 1, the current temperature is valid. 49 71 */ 50 - 51 - static struct coretemp_data *coretemp_update_device(struct device *dev); 52 - 53 - struct coretemp_data { 54 - struct device *hwmon_dev; 55 - struct mutex update_lock; 56 - const char *name; 57 - u32 id; 58 - u16 core_id; 59 - char valid; /* zero until following fields are valid */ 60 - unsigned long last_updated; /* in jiffies */ 72 + struct temp_data { 61 73 int temp; 62 - int tjmax; 63 74 int ttarget; 64 - u8 alarm; 75 + int tjmax; 76 + unsigned long last_updated; 77 + unsigned int cpu; 78 + u32 cpu_core_id; 79 + u32 status_reg; 80 + bool is_pkg_data; 81 + bool valid; 82 + struct sensor_device_attribute sd_attrs[MAX_ATTRS]; 83 + char attr_name[MAX_ATTRS][CORETEMP_NAME_LENGTH]; 84 + struct mutex update_lock; 65 85 }; 66 86 67 - /* 68 - * Sysfs stuff 69 - */ 87 + /* Platform Data per Physical CPU */ 88 + struct platform_data { 89 + struct device *hwmon_dev; 90 + u16 phys_proc_id; 91 + struct temp_data *core_data[MAX_CORE_DATA]; 92 + struct device_attribute name_attr; 93 + }; 70 94 71 - static ssize_t show_name(struct device *dev, struct device_attribute 72 - *devattr, char *buf) 95 + struct pdev_entry { 96 + struct list_head list; 97 + struct platform_device *pdev; 98 + unsigned int cpu; 99 + u16 phys_proc_id; 100 + u16 cpu_core_id; 101 + }; 102 + 103 + static LIST_HEAD(pdev_list); 104 + static DEFINE_MUTEX(pdev_list_mutex); 105 + 106 + static ssize_t show_name(struct device *dev, 107 + struct device_attribute *devattr, char *buf) 73 108 { 74 - int ret; 75 - struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); 76 - struct coretemp_data *data = dev_get_drvdata(dev); 77 - 78 - if (attr->index == SHOW_NAME) 79 - ret = sprintf(buf, "%s\n", data->name); 80 - else /* show label */ 81 - ret = sprintf(buf, "Core %d\n", data->core_id); 82 - return ret; 109 + return sprintf(buf, "%s\n", DRVNAME); 83 110 } 84 111 85 - static ssize_t show_alarm(struct device *dev, struct device_attribute 86 - *devattr, char *buf) 112 + static ssize_t show_label(struct device *dev, 113 + struct device_attribute *devattr, char *buf) 87 114 { 88 - struct coretemp_data *data = coretemp_update_device(dev); 89 - /* read the Out-of-spec log, never clear */ 90 - return sprintf(buf, "%d\n", data->alarm); 115 + struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); 116 + struct platform_data *pdata = dev_get_drvdata(dev); 117 + struct temp_data *tdata = pdata->core_data[attr->index]; 118 + 119 + if (tdata->is_pkg_data) 120 + return sprintf(buf, "Physical id %u\n", pdata->phys_proc_id); 121 + 122 + return sprintf(buf, "Core %u\n", tdata->cpu_core_id); 123 + } 124 + 125 + static ssize_t show_crit_alarm(struct device *dev, 126 + struct device_attribute *devattr, char *buf) 127 + { 128 + u32 eax, edx; 129 + struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); 130 + struct platform_data *pdata = dev_get_drvdata(dev); 131 + struct temp_data *tdata = pdata->core_data[attr->index]; 132 + 133 + rdmsr_on_cpu(tdata->cpu, tdata->status_reg, &eax, &edx); 134 + 135 + return sprintf(buf, "%d\n", (eax >> 5) & 1); 136 + } 137 + 138 + static ssize_t show_tjmax(struct device *dev, 139 + struct device_attribute *devattr, char *buf) 140 + { 141 + struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); 142 + struct platform_data *pdata = dev_get_drvdata(dev); 143 + 144 + return sprintf(buf, "%d\n", pdata->core_data[attr->index]->tjmax); 145 + } 146 + 147 + static ssize_t show_ttarget(struct device *dev, 148 + struct device_attribute *devattr, char *buf) 149 + { 150 + struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); 151 + struct platform_data *pdata = dev_get_drvdata(dev); 152 + 153 + return sprintf(buf, "%d\n", pdata->core_data[attr->index]->ttarget); 91 154 } 92 155 93 156 static ssize_t show_temp(struct device *dev, 94 - struct device_attribute *devattr, char *buf) 157 + struct device_attribute *devattr, char *buf) 95 158 { 159 + u32 eax, edx; 96 160 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); 97 - struct coretemp_data *data = coretemp_update_device(dev); 98 - int err; 161 + struct platform_data *pdata = dev_get_drvdata(dev); 162 + struct temp_data *tdata = pdata->core_data[attr->index]; 99 163 100 - if (attr->index == SHOW_TEMP) 101 - err = data->valid ? sprintf(buf, "%d\n", data->temp) : -EAGAIN; 102 - else if (attr->index == SHOW_TJMAX) 103 - err = sprintf(buf, "%d\n", data->tjmax); 104 - else 105 - err = sprintf(buf, "%d\n", data->ttarget); 106 - return err; 107 - } 164 + mutex_lock(&tdata->update_lock); 108 165 109 - static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, show_temp, NULL, 110 - SHOW_TEMP); 111 - static SENSOR_DEVICE_ATTR(temp1_crit, S_IRUGO, show_temp, NULL, 112 - SHOW_TJMAX); 113 - static SENSOR_DEVICE_ATTR(temp1_max, S_IRUGO, show_temp, NULL, 114 - SHOW_TTARGET); 115 - static DEVICE_ATTR(temp1_crit_alarm, S_IRUGO, show_alarm, NULL); 116 - static SENSOR_DEVICE_ATTR(temp1_label, S_IRUGO, show_name, NULL, SHOW_LABEL); 117 - static SENSOR_DEVICE_ATTR(name, S_IRUGO, show_name, NULL, SHOW_NAME); 118 - 119 - static struct attribute *coretemp_attributes[] = { 120 - &sensor_dev_attr_name.dev_attr.attr, 121 - &sensor_dev_attr_temp1_label.dev_attr.attr, 122 - &dev_attr_temp1_crit_alarm.attr, 123 - &sensor_dev_attr_temp1_input.dev_attr.attr, 124 - &sensor_dev_attr_temp1_crit.dev_attr.attr, 125 - NULL 126 - }; 127 - 128 - static const struct attribute_group coretemp_group = { 129 - .attrs = coretemp_attributes, 130 - }; 131 - 132 - static struct coretemp_data *coretemp_update_device(struct device *dev) 133 - { 134 - struct coretemp_data *data = dev_get_drvdata(dev); 135 - 136 - mutex_lock(&data->update_lock); 137 - 138 - if (!data->valid || time_after(jiffies, data->last_updated + HZ)) { 139 - u32 eax, edx; 140 - 141 - data->valid = 0; 142 - rdmsr_on_cpu(data->id, MSR_IA32_THERM_STATUS, &eax, &edx); 143 - data->alarm = (eax >> 5) & 1; 144 - /* update only if data has been valid */ 166 + /* Check whether the time interval has elapsed */ 167 + if (!tdata->valid || time_after(jiffies, tdata->last_updated + HZ)) { 168 + rdmsr_on_cpu(tdata->cpu, tdata->status_reg, &eax, &edx); 169 + tdata->valid = 0; 170 + /* Check whether the data is valid */ 145 171 if (eax & 0x80000000) { 146 - data->temp = data->tjmax - (((eax >> 16) 147 - & 0x7f) * 1000); 148 - data->valid = 1; 149 - } else { 150 - dev_dbg(dev, "Temperature data invalid (0x%x)\n", eax); 172 + tdata->temp = tdata->tjmax - 173 + ((eax >> 16) & 0x7f) * 1000; 174 + tdata->valid = 1; 151 175 } 152 - data->last_updated = jiffies; 176 + tdata->last_updated = jiffies; 153 177 } 154 178 155 - mutex_unlock(&data->update_lock); 156 - return data; 179 + mutex_unlock(&tdata->update_lock); 180 + return tdata->valid ? sprintf(buf, "%d\n", tdata->temp) : -EAGAIN; 157 181 } 158 182 159 - static int __devinit adjust_tjmax(struct cpuinfo_x86 *c, u32 id, struct device *dev) 183 + static int adjust_tjmax(struct cpuinfo_x86 *c, u32 id, struct device *dev) 160 184 { 161 185 /* The 100C is default for both mobile and non mobile CPUs */ 162 186 ··· 193 169 194 170 /* Early chips have no MSR for TjMax */ 195 171 196 - if ((c->x86_model == 0xf) && (c->x86_mask < 4)) { 172 + if (c->x86_model == 0xf && c->x86_mask < 4) 197 173 usemsr_ee = 0; 198 - } 199 174 200 175 /* Atom CPUs */ 201 176 ··· 213 190 pci_dev_put(host_bridge); 214 191 } 215 192 216 - if ((c->x86_model > 0xe) && (usemsr_ee)) { 193 + if (c->x86_model > 0xe && usemsr_ee) { 217 194 u8 platform_id; 218 195 219 - /* Now we can detect the mobile CPU using Intel provided table 220 - http://softwarecommunity.intel.com/Wiki/Mobility/720.htm 221 - For Core2 cores, check MSR 0x17, bit 28 1 = Mobile CPU 222 - */ 223 - 196 + /* 197 + * Now we can detect the mobile CPU using Intel provided table 198 + * http://softwarecommunity.intel.com/Wiki/Mobility/720.htm 199 + * For Core2 cores, check MSR 0x17, bit 28 1 = Mobile CPU 200 + */ 224 201 err = rdmsr_safe_on_cpu(id, 0x17, &eax, &edx); 225 202 if (err) { 226 203 dev_warn(dev, ··· 228 205 " CPU\n"); 229 206 usemsr_ee = 0; 230 207 } else if (c->x86_model < 0x17 && !(eax & 0x10000000)) { 231 - /* Trust bit 28 up to Penryn, I could not find any 232 - documentation on that; if you happen to know 233 - someone at Intel please ask */ 208 + /* 209 + * Trust bit 28 up to Penryn, I could not find any 210 + * documentation on that; if you happen to know 211 + * someone at Intel please ask 212 + */ 234 213 usemsr_ee = 0; 235 214 } else { 236 215 /* Platform ID bits 52:50 (EDX starts at bit 32) */ 237 216 platform_id = (edx >> 18) & 0x7; 238 217 239 - /* Mobile Penryn CPU seems to be platform ID 7 or 5 240 - (guesswork) */ 241 - if ((c->x86_model == 0x17) && 242 - ((platform_id == 5) || (platform_id == 7))) { 243 - /* If MSR EE bit is set, set it to 90 degrees C, 244 - otherwise 105 degrees C */ 218 + /* 219 + * Mobile Penryn CPU seems to be platform ID 7 or 5 220 + * (guesswork) 221 + */ 222 + if (c->x86_model == 0x17 && 223 + (platform_id == 5 || platform_id == 7)) { 224 + /* 225 + * If MSR EE bit is set, set it to 90 degrees C, 226 + * otherwise 105 degrees C 227 + */ 245 228 tjmax_ee = 90000; 246 229 tjmax = 105000; 247 230 } ··· 255 226 } 256 227 257 228 if (usemsr_ee) { 258 - 259 229 err = rdmsr_safe_on_cpu(id, 0xee, &eax, &edx); 260 230 if (err) { 261 231 dev_warn(dev, ··· 263 235 } else if (eax & 0x40000000) { 264 236 tjmax = tjmax_ee; 265 237 } 266 - /* if we dont use msr EE it means we are desktop CPU (with exeception 267 - of Atom) */ 268 238 } else if (tjmax == 100000) { 239 + /* 240 + * If we don't use msr EE it means we are desktop CPU 241 + * (with exeception of Atom) 242 + */ 269 243 dev_warn(dev, "Using relative temperature scale!\n"); 270 244 } 271 245 272 246 return tjmax; 273 247 } 274 248 275 - static int __devinit get_tjmax(struct cpuinfo_x86 *c, u32 id, 276 - struct device *dev) 249 + static int get_tjmax(struct cpuinfo_x86 *c, u32 id, struct device *dev) 277 250 { 278 251 /* The 100C is default for both mobile and non mobile CPUs */ 279 252 int err; 280 253 u32 eax, edx; 281 254 u32 val; 282 255 283 - /* A new feature of current Intel(R) processors, the 284 - IA32_TEMPERATURE_TARGET contains the TjMax value */ 256 + /* 257 + * A new feature of current Intel(R) processors, the 258 + * IA32_TEMPERATURE_TARGET contains the TjMax value 259 + */ 285 260 err = rdmsr_safe_on_cpu(id, MSR_IA32_TEMPERATURE_TARGET, &eax, &edx); 286 261 if (err) { 287 262 dev_warn(dev, "Unable to read TjMax from CPU.\n"); ··· 294 263 * If the TjMax is not plausible, an assumption 295 264 * will be used 296 265 */ 297 - if ((val > 80) && (val < 120)) { 266 + if (val > 80 && val < 120) { 298 267 dev_info(dev, "TjMax is %d C.\n", val); 299 268 return val * 1000; 300 269 } ··· 331 300 rdmsr(MSR_IA32_UCODE_REV, eax, *(u32 *)edx); 332 301 } 333 302 334 - static int __devinit coretemp_probe(struct platform_device *pdev) 303 + static int get_pkg_tjmax(unsigned int cpu, struct device *dev) 335 304 { 336 - struct coretemp_data *data; 337 - struct cpuinfo_x86 *c = &cpu_data(pdev->id); 305 + int err; 306 + u32 eax, edx, val; 307 + 308 + err = rdmsr_safe_on_cpu(cpu, MSR_IA32_TEMPERATURE_TARGET, &eax, &edx); 309 + if (!err) { 310 + val = (eax >> 16) & 0xff; 311 + if (val > 80 && val < 120) 312 + return val * 1000; 313 + } 314 + dev_warn(dev, "Unable to read Pkg-TjMax from CPU:%u\n", cpu); 315 + return 100000; /* Default TjMax: 100 degree celsius */ 316 + } 317 + 318 + static int create_name_attr(struct platform_data *pdata, struct device *dev) 319 + { 320 + pdata->name_attr.attr.name = "name"; 321 + pdata->name_attr.attr.mode = S_IRUGO; 322 + pdata->name_attr.show = show_name; 323 + return device_create_file(dev, &pdata->name_attr); 324 + } 325 + 326 + static int create_core_attrs(struct temp_data *tdata, struct device *dev, 327 + int attr_no) 328 + { 329 + int err, i; 330 + static ssize_t (*rd_ptr[MAX_ATTRS]) (struct device *dev, 331 + struct device_attribute *devattr, char *buf) = { 332 + show_label, show_crit_alarm, show_ttarget, 333 + show_temp, show_tjmax }; 334 + static const char *names[MAX_ATTRS] = { 335 + "temp%d_label", "temp%d_crit_alarm", 336 + "temp%d_max", "temp%d_input", 337 + "temp%d_crit" }; 338 + 339 + for (i = 0; i < MAX_ATTRS; i++) { 340 + snprintf(tdata->attr_name[i], CORETEMP_NAME_LENGTH, names[i], 341 + attr_no); 342 + tdata->sd_attrs[i].dev_attr.attr.name = tdata->attr_name[i]; 343 + tdata->sd_attrs[i].dev_attr.attr.mode = S_IRUGO; 344 + tdata->sd_attrs[i].dev_attr.show = rd_ptr[i]; 345 + tdata->sd_attrs[i].dev_attr.store = NULL; 346 + tdata->sd_attrs[i].index = attr_no; 347 + err = device_create_file(dev, &tdata->sd_attrs[i].dev_attr); 348 + if (err) 349 + goto exit_free; 350 + } 351 + return 0; 352 + 353 + exit_free: 354 + while (--i >= 0) 355 + device_remove_file(dev, &tdata->sd_attrs[i].dev_attr); 356 + return err; 357 + } 358 + 359 + static void update_ttarget(__u8 cpu_model, struct temp_data *tdata, 360 + struct device *dev) 361 + { 338 362 int err; 339 363 u32 eax, edx; 340 364 341 - if (!(data = kzalloc(sizeof(struct coretemp_data), GFP_KERNEL))) { 342 - err = -ENOMEM; 343 - dev_err(&pdev->dev, "Out of memory\n"); 344 - goto exit; 365 + /* 366 + * Initialize ttarget value. Eventually this will be 367 + * initialized with the value from MSR_IA32_THERM_INTERRUPT 368 + * register. If IA32_TEMPERATURE_TARGET is supported, this 369 + * value will be over written below. 370 + * To Do: Patch to initialize ttarget from MSR_IA32_THERM_INTERRUPT 371 + */ 372 + tdata->ttarget = tdata->tjmax - 20000; 373 + 374 + /* 375 + * Read the still undocumented IA32_TEMPERATURE_TARGET. It exists 376 + * on older CPUs but not in this register, 377 + * Atoms don't have it either. 378 + */ 379 + if (cpu_model > 0xe && cpu_model != 0x1c) { 380 + err = rdmsr_safe_on_cpu(tdata->cpu, 381 + MSR_IA32_TEMPERATURE_TARGET, &eax, &edx); 382 + if (err) { 383 + dev_warn(dev, 384 + "Unable to read IA32_TEMPERATURE_TARGET MSR\n"); 385 + } else { 386 + tdata->ttarget = tdata->tjmax - 387 + ((eax >> 8) & 0xff) * 1000; 388 + } 345 389 } 390 + } 346 391 347 - data->id = pdev->id; 348 - #ifdef CONFIG_SMP 349 - data->core_id = c->cpu_core_id; 350 - #endif 351 - data->name = "coretemp"; 352 - mutex_init(&data->update_lock); 392 + static int chk_ucode_version(struct platform_device *pdev) 393 + { 394 + struct cpuinfo_x86 *c = &cpu_data(pdev->id); 395 + int err; 396 + u32 edx; 353 397 354 - /* test if we can access the THERM_STATUS MSR */ 355 - err = rdmsr_safe_on_cpu(data->id, MSR_IA32_THERM_STATUS, &eax, &edx); 356 - if (err) { 357 - dev_err(&pdev->dev, 358 - "Unable to access THERM_STATUS MSR, giving up\n"); 359 - goto exit_free; 360 - } 361 - 362 - /* Check if we have problem with errata AE18 of Core processors: 363 - Readings might stop update when processor visited too deep sleep, 364 - fixed for stepping D0 (6EC). 365 - */ 366 - 367 - if ((c->x86_model == 0xe) && (c->x86_mask < 0xc)) { 398 + /* 399 + * Check if we have problem with errata AE18 of Core processors: 400 + * Readings might stop update when processor visited too deep sleep, 401 + * fixed for stepping D0 (6EC). 402 + */ 403 + if (c->x86_model == 0xe && c->x86_mask < 0xc) { 368 404 /* check for microcode update */ 369 - err = smp_call_function_single(data->id, get_ucode_rev_on_cpu, 405 + err = smp_call_function_single(pdev->id, get_ucode_rev_on_cpu, 370 406 &edx, 1); 371 407 if (err) { 372 408 dev_err(&pdev->dev, 373 409 "Cannot determine microcode revision of " 374 - "CPU#%u (%d)!\n", data->id, err); 375 - err = -ENODEV; 376 - goto exit_free; 410 + "CPU#%u (%d)!\n", pdev->id, err); 411 + return -ENODEV; 377 412 } else if (edx < 0x39) { 378 - err = -ENODEV; 379 413 dev_err(&pdev->dev, 380 414 "Errata AE18 not fixed, update BIOS or " 381 415 "microcode of the CPU!\n"); 382 - goto exit_free; 416 + return -ENODEV; 383 417 } 384 418 } 419 + return 0; 420 + } 385 421 386 - data->tjmax = get_tjmax(c, data->id, &pdev->dev); 387 - platform_set_drvdata(pdev, data); 422 + static struct platform_device *coretemp_get_pdev(unsigned int cpu) 423 + { 424 + u16 phys_proc_id = TO_PHYS_ID(cpu); 425 + struct pdev_entry *p; 426 + 427 + mutex_lock(&pdev_list_mutex); 428 + 429 + list_for_each_entry(p, &pdev_list, list) 430 + if (p->phys_proc_id == phys_proc_id) { 431 + mutex_unlock(&pdev_list_mutex); 432 + return p->pdev; 433 + } 434 + 435 + mutex_unlock(&pdev_list_mutex); 436 + return NULL; 437 + } 438 + 439 + static struct temp_data *init_temp_data(unsigned int cpu, int pkg_flag) 440 + { 441 + struct temp_data *tdata; 442 + 443 + tdata = kzalloc(sizeof(struct temp_data), GFP_KERNEL); 444 + if (!tdata) 445 + return NULL; 446 + 447 + tdata->status_reg = pkg_flag ? MSR_IA32_PACKAGE_THERM_STATUS : 448 + MSR_IA32_THERM_STATUS; 449 + tdata->is_pkg_data = pkg_flag; 450 + tdata->cpu = cpu; 451 + tdata->cpu_core_id = TO_CORE_ID(cpu); 452 + mutex_init(&tdata->update_lock); 453 + return tdata; 454 + } 455 + 456 + static int create_core_data(struct platform_data *pdata, 457 + struct platform_device *pdev, 458 + unsigned int cpu, int pkg_flag) 459 + { 460 + struct temp_data *tdata; 461 + struct cpuinfo_x86 *c = &cpu_data(cpu); 462 + u32 eax, edx; 463 + int err, attr_no; 388 464 389 465 /* 390 - * read the still undocumented IA32_TEMPERATURE_TARGET. It exists 391 - * on older CPUs but not in this register, 392 - * Atoms don't have it either. 466 + * Find attr number for sysfs: 467 + * We map the attr number to core id of the CPU 468 + * The attr number is always core id + 2 469 + * The Pkgtemp will always show up as temp1_*, if available 393 470 */ 471 + attr_no = pkg_flag ? 1 : TO_ATTR_NO(cpu); 394 472 395 - if ((c->x86_model > 0xe) && (c->x86_model != 0x1c)) { 396 - err = rdmsr_safe_on_cpu(data->id, MSR_IA32_TEMPERATURE_TARGET, 397 - &eax, &edx); 398 - if (err) { 399 - dev_warn(&pdev->dev, "Unable to read" 400 - " IA32_TEMPERATURE_TARGET MSR\n"); 401 - } else { 402 - data->ttarget = data->tjmax - 403 - (((eax >> 8) & 0xff) * 1000); 404 - err = device_create_file(&pdev->dev, 405 - &sensor_dev_attr_temp1_max.dev_attr); 406 - if (err) 407 - goto exit_free; 408 - } 409 - } 473 + if (attr_no > MAX_CORE_DATA - 1) 474 + return -ERANGE; 410 475 411 - if ((err = sysfs_create_group(&pdev->dev.kobj, &coretemp_group))) 412 - goto exit_dev; 476 + /* Skip if it is a HT core, Not an error */ 477 + if (pdata->core_data[attr_no] != NULL) 478 + return 0; 413 479 414 - data->hwmon_dev = hwmon_device_register(&pdev->dev); 415 - if (IS_ERR(data->hwmon_dev)) { 416 - err = PTR_ERR(data->hwmon_dev); 417 - dev_err(&pdev->dev, "Class registration failed (%d)\n", 418 - err); 419 - goto exit_class; 420 - } 480 + tdata = init_temp_data(cpu, pkg_flag); 481 + if (!tdata) 482 + return -ENOMEM; 483 + 484 + /* Test if we can access the status register */ 485 + err = rdmsr_safe_on_cpu(cpu, tdata->status_reg, &eax, &edx); 486 + if (err) 487 + goto exit_free; 488 + 489 + /* We can access status register. Get Critical Temperature */ 490 + if (pkg_flag) 491 + tdata->tjmax = get_pkg_tjmax(pdev->id, &pdev->dev); 492 + else 493 + tdata->tjmax = get_tjmax(c, cpu, &pdev->dev); 494 + 495 + update_ttarget(c->x86_model, tdata, &pdev->dev); 496 + pdata->core_data[attr_no] = tdata; 497 + 498 + /* Create sysfs interfaces */ 499 + err = create_core_attrs(tdata, &pdev->dev, attr_no); 500 + if (err) 501 + goto exit_free; 421 502 422 503 return 0; 423 - 424 - exit_class: 425 - sysfs_remove_group(&pdev->dev.kobj, &coretemp_group); 426 - exit_dev: 427 - device_remove_file(&pdev->dev, &sensor_dev_attr_temp1_max.dev_attr); 428 504 exit_free: 429 - kfree(data); 430 - exit: 505 + kfree(tdata); 506 + return err; 507 + } 508 + 509 + static void coretemp_add_core(unsigned int cpu, int pkg_flag) 510 + { 511 + struct platform_data *pdata; 512 + struct platform_device *pdev = coretemp_get_pdev(cpu); 513 + int err; 514 + 515 + if (!pdev) 516 + return; 517 + 518 + pdata = platform_get_drvdata(pdev); 519 + 520 + err = create_core_data(pdata, pdev, cpu, pkg_flag); 521 + if (err) 522 + dev_err(&pdev->dev, "Adding Core %u failed\n", cpu); 523 + } 524 + 525 + static void coretemp_remove_core(struct platform_data *pdata, 526 + struct device *dev, int indx) 527 + { 528 + int i; 529 + struct temp_data *tdata = pdata->core_data[indx]; 530 + 531 + /* Remove the sysfs attributes */ 532 + for (i = 0; i < MAX_ATTRS; i++) 533 + device_remove_file(dev, &tdata->sd_attrs[i].dev_attr); 534 + 535 + kfree(pdata->core_data[indx]); 536 + pdata->core_data[indx] = NULL; 537 + } 538 + 539 + static int __devinit coretemp_probe(struct platform_device *pdev) 540 + { 541 + struct platform_data *pdata; 542 + int err; 543 + 544 + /* Check the microcode version of the CPU */ 545 + err = chk_ucode_version(pdev); 546 + if (err) 547 + return err; 548 + 549 + /* Initialize the per-package data structures */ 550 + pdata = kzalloc(sizeof(struct platform_data), GFP_KERNEL); 551 + if (!pdata) 552 + return -ENOMEM; 553 + 554 + err = create_name_attr(pdata, &pdev->dev); 555 + if (err) 556 + goto exit_free; 557 + 558 + pdata->phys_proc_id = TO_PHYS_ID(pdev->id); 559 + platform_set_drvdata(pdev, pdata); 560 + 561 + pdata->hwmon_dev = hwmon_device_register(&pdev->dev); 562 + if (IS_ERR(pdata->hwmon_dev)) { 563 + err = PTR_ERR(pdata->hwmon_dev); 564 + dev_err(&pdev->dev, "Class registration failed (%d)\n", err); 565 + goto exit_name; 566 + } 567 + return 0; 568 + 569 + exit_name: 570 + device_remove_file(&pdev->dev, &pdata->name_attr); 571 + platform_set_drvdata(pdev, NULL); 572 + exit_free: 573 + kfree(pdata); 431 574 return err; 432 575 } 433 576 434 577 static int __devexit coretemp_remove(struct platform_device *pdev) 435 578 { 436 - struct coretemp_data *data = platform_get_drvdata(pdev); 579 + struct platform_data *pdata = platform_get_drvdata(pdev); 580 + int i; 437 581 438 - hwmon_device_unregister(data->hwmon_dev); 439 - sysfs_remove_group(&pdev->dev.kobj, &coretemp_group); 440 - device_remove_file(&pdev->dev, &sensor_dev_attr_temp1_max.dev_attr); 582 + for (i = MAX_CORE_DATA - 1; i >= 0; --i) 583 + if (pdata->core_data[i]) 584 + coretemp_remove_core(pdata, &pdev->dev, i); 585 + 586 + device_remove_file(&pdev->dev, &pdata->name_attr); 587 + hwmon_device_unregister(pdata->hwmon_dev); 441 588 platform_set_drvdata(pdev, NULL); 442 - kfree(data); 589 + kfree(pdata); 443 590 return 0; 444 591 } 445 592 ··· 630 421 .remove = __devexit_p(coretemp_remove), 631 422 }; 632 423 633 - struct pdev_entry { 634 - struct list_head list; 635 - struct platform_device *pdev; 636 - unsigned int cpu; 637 - #ifdef CONFIG_SMP 638 - u16 phys_proc_id; 639 - u16 cpu_core_id; 640 - #endif 641 - }; 642 - 643 - static LIST_HEAD(pdev_list); 644 - static DEFINE_MUTEX(pdev_list_mutex); 645 - 646 424 static int __cpuinit coretemp_device_add(unsigned int cpu) 647 425 { 648 426 int err; 649 427 struct platform_device *pdev; 650 428 struct pdev_entry *pdev_entry; 651 - struct cpuinfo_x86 *c = &cpu_data(cpu); 652 - 653 - /* 654 - * CPUID.06H.EAX[0] indicates whether the CPU has thermal 655 - * sensors. We check this bit only, all the early CPUs 656 - * without thermal sensors will be filtered out. 657 - */ 658 - if (!cpu_has(c, X86_FEATURE_DTS)) { 659 - pr_info("CPU (model=0x%x) has no thermal sensor\n", 660 - c->x86_model); 661 - return 0; 662 - } 663 429 664 430 mutex_lock(&pdev_list_mutex); 665 - 666 - #ifdef CONFIG_SMP 667 - /* Skip second HT entry of each core */ 668 - list_for_each_entry(pdev_entry, &pdev_list, list) { 669 - if (c->phys_proc_id == pdev_entry->phys_proc_id && 670 - c->cpu_core_id == pdev_entry->cpu_core_id) { 671 - err = 0; /* Not an error */ 672 - goto exit; 673 - } 674 - } 675 - #endif 676 431 677 432 pdev = platform_device_alloc(DRVNAME, cpu); 678 433 if (!pdev) { ··· 659 486 660 487 pdev_entry->pdev = pdev; 661 488 pdev_entry->cpu = cpu; 662 - #ifdef CONFIG_SMP 663 - pdev_entry->phys_proc_id = c->phys_proc_id; 664 - pdev_entry->cpu_core_id = c->cpu_core_id; 665 - #endif 489 + pdev_entry->phys_proc_id = TO_PHYS_ID(cpu); 490 + pdev_entry->cpu_core_id = TO_CORE_ID(cpu); 491 + 666 492 list_add_tail(&pdev_entry->list, &pdev_list); 667 493 mutex_unlock(&pdev_list_mutex); 668 494 ··· 676 504 return err; 677 505 } 678 506 679 - static void __cpuinit coretemp_device_remove(unsigned int cpu) 507 + static void coretemp_device_remove(unsigned int cpu) 680 508 { 681 - struct pdev_entry *p; 682 - unsigned int i; 509 + struct pdev_entry *p, *n; 510 + u16 phys_proc_id = TO_PHYS_ID(cpu); 683 511 684 512 mutex_lock(&pdev_list_mutex); 685 - list_for_each_entry(p, &pdev_list, list) { 686 - if (p->cpu != cpu) 513 + list_for_each_entry_safe(p, n, &pdev_list, list) { 514 + if (p->phys_proc_id != phys_proc_id) 687 515 continue; 688 - 689 516 platform_device_unregister(p->pdev); 690 517 list_del(&p->list); 691 - mutex_unlock(&pdev_list_mutex); 692 518 kfree(p); 693 - for_each_cpu(i, cpu_sibling_mask(cpu)) 694 - if (i != cpu && !coretemp_device_add(i)) 695 - break; 696 - return; 697 519 } 698 520 mutex_unlock(&pdev_list_mutex); 521 + } 522 + 523 + static bool is_any_core_online(struct platform_data *pdata) 524 + { 525 + int i; 526 + 527 + /* Find online cores, except pkgtemp data */ 528 + for (i = MAX_CORE_DATA - 1; i >= 0; --i) { 529 + if (pdata->core_data[i] && 530 + !pdata->core_data[i]->is_pkg_data) { 531 + return true; 532 + } 533 + } 534 + return false; 535 + } 536 + 537 + static void __cpuinit get_core_online(unsigned int cpu) 538 + { 539 + struct cpuinfo_x86 *c = &cpu_data(cpu); 540 + struct platform_device *pdev = coretemp_get_pdev(cpu); 541 + int err; 542 + 543 + /* 544 + * CPUID.06H.EAX[0] indicates whether the CPU has thermal 545 + * sensors. We check this bit only, all the early CPUs 546 + * without thermal sensors will be filtered out. 547 + */ 548 + if (!cpu_has(c, X86_FEATURE_DTS)) 549 + return; 550 + 551 + if (!pdev) { 552 + /* 553 + * Alright, we have DTS support. 554 + * We are bringing the _first_ core in this pkg 555 + * online. So, initialize per-pkg data structures and 556 + * then bring this core online. 557 + */ 558 + err = coretemp_device_add(cpu); 559 + if (err) 560 + return; 561 + /* 562 + * Check whether pkgtemp support is available. 563 + * If so, add interfaces for pkgtemp. 564 + */ 565 + if (cpu_has(c, X86_FEATURE_PTS)) 566 + coretemp_add_core(cpu, 1); 567 + } 568 + /* 569 + * Physical CPU device already exists. 570 + * So, just add interfaces for this core. 571 + */ 572 + coretemp_add_core(cpu, 0); 573 + } 574 + 575 + static void __cpuinit put_core_offline(unsigned int cpu) 576 + { 577 + int i, indx; 578 + struct platform_data *pdata; 579 + struct platform_device *pdev = coretemp_get_pdev(cpu); 580 + 581 + /* If the physical CPU device does not exist, just return */ 582 + if (!pdev) 583 + return; 584 + 585 + pdata = platform_get_drvdata(pdev); 586 + 587 + indx = TO_ATTR_NO(cpu); 588 + 589 + if (pdata->core_data[indx] && pdata->core_data[indx]->cpu == cpu) 590 + coretemp_remove_core(pdata, &pdev->dev, indx); 591 + 592 + /* Online the HT version of this core, if any */ 593 + for_each_cpu(i, cpu_sibling_mask(cpu)) { 594 + if (i != cpu) { 595 + get_core_online(i); 596 + break; 597 + } 598 + } 599 + /* 600 + * If all cores in this pkg are offline, remove the device. 601 + * coretemp_device_remove calls unregister_platform_device, 602 + * which in turn calls coretemp_remove. This removes the 603 + * pkgtemp entry and does other clean ups. 604 + */ 605 + if (!is_any_core_online(pdata)) 606 + coretemp_device_remove(cpu); 699 607 } 700 608 701 609 static int __cpuinit coretemp_cpu_callback(struct notifier_block *nfb, ··· 786 534 switch (action) { 787 535 case CPU_ONLINE: 788 536 case CPU_DOWN_FAILED: 789 - coretemp_device_add(cpu); 537 + get_core_online(cpu); 790 538 break; 791 539 case CPU_DOWN_PREPARE: 792 - coretemp_device_remove(cpu); 540 + put_core_offline(cpu); 793 541 break; 794 542 } 795 543 return NOTIFY_OK; ··· 812 560 goto exit; 813 561 814 562 for_each_online_cpu(i) 815 - coretemp_device_add(i); 563 + get_core_online(i); 816 564 817 565 #ifndef CONFIG_HOTPLUG_CPU 818 566 if (list_empty(&pdev_list)) {
+717
drivers/hwmon/max16065.c
··· 1 + /* 2 + * Driver for 3 + * Maxim MAX16065/MAX16066 12-Channel/8-Channel, Flash-Configurable 4 + * System Managers with Nonvolatile Fault Registers 5 + * Maxim MAX16067/MAX16068 6-Channel, Flash-Configurable System Managers 6 + * with Nonvolatile Fault Registers 7 + * Maxim MAX16070/MAX16071 12-Channel/8-Channel, Flash-Configurable System 8 + * Monitors with Nonvolatile Fault Registers 9 + * 10 + * Copyright (C) 2011 Ericsson AB. 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; version 2 of the License. 15 + */ 16 + 17 + #include <linux/kernel.h> 18 + #include <linux/module.h> 19 + #include <linux/init.h> 20 + #include <linux/err.h> 21 + #include <linux/slab.h> 22 + #include <linux/i2c.h> 23 + #include <linux/hwmon.h> 24 + #include <linux/hwmon-sysfs.h> 25 + #include <linux/delay.h> 26 + #include <linux/jiffies.h> 27 + 28 + enum chips { max16065, max16066, max16067, max16068, max16070, max16071 }; 29 + 30 + /* 31 + * Registers 32 + */ 33 + #define MAX16065_ADC(x) ((x) * 2) 34 + 35 + #define MAX16065_CURR_SENSE 0x18 36 + #define MAX16065_CSP_ADC 0x19 37 + #define MAX16065_FAULT(x) (0x1b + (x)) 38 + #define MAX16065_SCALE(x) (0x43 + (x)) 39 + #define MAX16065_CURR_CONTROL 0x47 40 + #define MAX16065_LIMIT(l, x) (0x48 + (l) + (x) * 3) /* 41 + * l: limit 42 + * 0: min/max 43 + * 1: crit 44 + * 2: lcrit 45 + * x: ADC index 46 + */ 47 + 48 + #define MAX16065_SW_ENABLE 0x73 49 + 50 + #define MAX16065_WARNING_OV (1 << 3) /* Set if secondary threshold is OV 51 + warning */ 52 + 53 + #define MAX16065_CURR_ENABLE (1 << 0) 54 + 55 + #define MAX16065_NUM_LIMIT 3 56 + #define MAX16065_NUM_ADC 12 /* maximum number of ADC channels */ 57 + 58 + static const int max16065_num_adc[] = { 59 + [max16065] = 12, 60 + [max16066] = 8, 61 + [max16067] = 6, 62 + [max16068] = 6, 63 + [max16070] = 12, 64 + [max16071] = 8, 65 + }; 66 + 67 + static const bool max16065_have_secondary[] = { 68 + [max16065] = true, 69 + [max16066] = true, 70 + [max16067] = false, 71 + [max16068] = false, 72 + [max16070] = true, 73 + [max16071] = true, 74 + }; 75 + 76 + static const bool max16065_have_current[] = { 77 + [max16065] = true, 78 + [max16066] = true, 79 + [max16067] = false, 80 + [max16068] = false, 81 + [max16070] = true, 82 + [max16071] = true, 83 + }; 84 + 85 + struct max16065_data { 86 + enum chips type; 87 + struct device *hwmon_dev; 88 + struct mutex update_lock; 89 + bool valid; 90 + unsigned long last_updated; /* in jiffies */ 91 + int num_adc; 92 + bool have_current; 93 + int curr_gain; 94 + /* limits are in mV */ 95 + int limit[MAX16065_NUM_LIMIT][MAX16065_NUM_ADC]; 96 + int range[MAX16065_NUM_ADC + 1];/* voltage range */ 97 + int adc[MAX16065_NUM_ADC + 1]; /* adc values (raw) including csp_adc */ 98 + int curr_sense; 99 + int fault[2]; 100 + }; 101 + 102 + static const int max16065_adc_range[] = { 5560, 2780, 1390, 0 }; 103 + static const int max16065_csp_adc_range[] = { 7000, 14000 }; 104 + 105 + /* ADC registers have 10 bit resolution. */ 106 + static inline int ADC_TO_MV(int adc, int range) 107 + { 108 + return (adc * range) / 1024; 109 + } 110 + 111 + /* 112 + * Limit registers have 8 bit resolution and match upper 8 bits of ADC 113 + * registers. 114 + */ 115 + static inline int LIMIT_TO_MV(int limit, int range) 116 + { 117 + return limit * range / 256; 118 + } 119 + 120 + static inline int MV_TO_LIMIT(int mv, int range) 121 + { 122 + return SENSORS_LIMIT(DIV_ROUND_CLOSEST(mv * 256, range), 0, 255); 123 + } 124 + 125 + static inline int ADC_TO_CURR(int adc, int gain) 126 + { 127 + return adc * 1400000 / gain * 255; 128 + } 129 + 130 + /* 131 + * max16065_read_adc() 132 + * 133 + * Read 16 bit value from <reg>, <reg+1>. 134 + * Upper 8 bits are in <reg>, lower 2 bits are in bits 7:6 of <reg+1>. 135 + */ 136 + static int max16065_read_adc(struct i2c_client *client, int reg) 137 + { 138 + int rv; 139 + 140 + rv = i2c_smbus_read_word_data(client, reg); 141 + if (unlikely(rv < 0)) 142 + return rv; 143 + return ((rv & 0xff) << 2) | ((rv >> 14) & 0x03); 144 + } 145 + 146 + static struct max16065_data *max16065_update_device(struct device *dev) 147 + { 148 + struct i2c_client *client = to_i2c_client(dev); 149 + struct max16065_data *data = i2c_get_clientdata(client); 150 + 151 + mutex_lock(&data->update_lock); 152 + if (time_after(jiffies, data->last_updated + HZ) || !data->valid) { 153 + int i; 154 + 155 + for (i = 0; i < data->num_adc; i++) 156 + data->adc[i] 157 + = max16065_read_adc(client, MAX16065_ADC(i)); 158 + 159 + if (data->have_current) { 160 + data->adc[MAX16065_NUM_ADC] 161 + = max16065_read_adc(client, MAX16065_CSP_ADC); 162 + data->curr_sense 163 + = i2c_smbus_read_byte_data(client, 164 + MAX16065_CURR_SENSE); 165 + } 166 + 167 + for (i = 0; i < DIV_ROUND_UP(data->num_adc, 8); i++) 168 + data->fault[i] 169 + = i2c_smbus_read_byte_data(client, MAX16065_FAULT(i)); 170 + 171 + data->last_updated = jiffies; 172 + data->valid = 1; 173 + } 174 + mutex_unlock(&data->update_lock); 175 + return data; 176 + } 177 + 178 + static ssize_t max16065_show_alarm(struct device *dev, 179 + struct device_attribute *da, char *buf) 180 + { 181 + struct sensor_device_attribute_2 *attr2 = to_sensor_dev_attr_2(da); 182 + struct max16065_data *data = max16065_update_device(dev); 183 + int val = data->fault[attr2->nr]; 184 + 185 + if (val < 0) 186 + return val; 187 + 188 + val &= (1 << attr2->index); 189 + if (val) 190 + i2c_smbus_write_byte_data(to_i2c_client(dev), 191 + MAX16065_FAULT(attr2->nr), val); 192 + 193 + return snprintf(buf, PAGE_SIZE, "%d\n", !!val); 194 + } 195 + 196 + static ssize_t max16065_show_input(struct device *dev, 197 + struct device_attribute *da, char *buf) 198 + { 199 + struct sensor_device_attribute *attr = to_sensor_dev_attr(da); 200 + struct max16065_data *data = max16065_update_device(dev); 201 + int adc = data->adc[attr->index]; 202 + 203 + if (unlikely(adc < 0)) 204 + return adc; 205 + 206 + return snprintf(buf, PAGE_SIZE, "%d\n", 207 + ADC_TO_MV(adc, data->range[attr->index])); 208 + } 209 + 210 + static ssize_t max16065_show_current(struct device *dev, 211 + struct device_attribute *da, char *buf) 212 + { 213 + struct max16065_data *data = max16065_update_device(dev); 214 + 215 + if (unlikely(data->curr_sense < 0)) 216 + return data->curr_sense; 217 + 218 + return snprintf(buf, PAGE_SIZE, "%d\n", 219 + ADC_TO_CURR(data->curr_sense, data->curr_gain)); 220 + } 221 + 222 + static ssize_t max16065_set_limit(struct device *dev, 223 + struct device_attribute *da, 224 + const char *buf, size_t count) 225 + { 226 + struct sensor_device_attribute_2 *attr2 = to_sensor_dev_attr_2(da); 227 + struct i2c_client *client = to_i2c_client(dev); 228 + struct max16065_data *data = i2c_get_clientdata(client); 229 + unsigned long val; 230 + int err; 231 + int limit; 232 + 233 + err = strict_strtoul(buf, 10, &val); 234 + if (unlikely(err < 0)) 235 + return err; 236 + 237 + limit = MV_TO_LIMIT(val, data->range[attr2->index]); 238 + 239 + mutex_lock(&data->update_lock); 240 + data->limit[attr2->nr][attr2->index] 241 + = LIMIT_TO_MV(limit, data->range[attr2->index]); 242 + i2c_smbus_write_byte_data(client, 243 + MAX16065_LIMIT(attr2->nr, attr2->index), 244 + limit); 245 + mutex_unlock(&data->update_lock); 246 + 247 + return count; 248 + } 249 + 250 + static ssize_t max16065_show_limit(struct device *dev, 251 + struct device_attribute *da, char *buf) 252 + { 253 + struct sensor_device_attribute_2 *attr2 = to_sensor_dev_attr_2(da); 254 + struct i2c_client *client = to_i2c_client(dev); 255 + struct max16065_data *data = i2c_get_clientdata(client); 256 + 257 + return snprintf(buf, PAGE_SIZE, "%d\n", 258 + data->limit[attr2->nr][attr2->index]); 259 + } 260 + 261 + /* Construct a sensor_device_attribute structure for each register */ 262 + 263 + /* Input voltages */ 264 + static SENSOR_DEVICE_ATTR(in0_input, S_IRUGO, max16065_show_input, NULL, 0); 265 + static SENSOR_DEVICE_ATTR(in1_input, S_IRUGO, max16065_show_input, NULL, 1); 266 + static SENSOR_DEVICE_ATTR(in2_input, S_IRUGO, max16065_show_input, NULL, 2); 267 + static SENSOR_DEVICE_ATTR(in3_input, S_IRUGO, max16065_show_input, NULL, 3); 268 + static SENSOR_DEVICE_ATTR(in4_input, S_IRUGO, max16065_show_input, NULL, 4); 269 + static SENSOR_DEVICE_ATTR(in5_input, S_IRUGO, max16065_show_input, NULL, 5); 270 + static SENSOR_DEVICE_ATTR(in6_input, S_IRUGO, max16065_show_input, NULL, 6); 271 + static SENSOR_DEVICE_ATTR(in7_input, S_IRUGO, max16065_show_input, NULL, 7); 272 + static SENSOR_DEVICE_ATTR(in8_input, S_IRUGO, max16065_show_input, NULL, 8); 273 + static SENSOR_DEVICE_ATTR(in9_input, S_IRUGO, max16065_show_input, NULL, 9); 274 + static SENSOR_DEVICE_ATTR(in10_input, S_IRUGO, max16065_show_input, NULL, 10); 275 + static SENSOR_DEVICE_ATTR(in11_input, S_IRUGO, max16065_show_input, NULL, 11); 276 + static SENSOR_DEVICE_ATTR(in12_input, S_IRUGO, max16065_show_input, NULL, 12); 277 + 278 + /* Input voltages lcrit */ 279 + static SENSOR_DEVICE_ATTR_2(in0_lcrit, S_IWUSR | S_IRUGO, max16065_show_limit, 280 + max16065_set_limit, 2, 0); 281 + static SENSOR_DEVICE_ATTR_2(in1_lcrit, S_IWUSR | S_IRUGO, max16065_show_limit, 282 + max16065_set_limit, 2, 1); 283 + static SENSOR_DEVICE_ATTR_2(in2_lcrit, S_IWUSR | S_IRUGO, max16065_show_limit, 284 + max16065_set_limit, 2, 2); 285 + static SENSOR_DEVICE_ATTR_2(in3_lcrit, S_IWUSR | S_IRUGO, max16065_show_limit, 286 + max16065_set_limit, 2, 3); 287 + static SENSOR_DEVICE_ATTR_2(in4_lcrit, S_IWUSR | S_IRUGO, max16065_show_limit, 288 + max16065_set_limit, 2, 4); 289 + static SENSOR_DEVICE_ATTR_2(in5_lcrit, S_IWUSR | S_IRUGO, max16065_show_limit, 290 + max16065_set_limit, 2, 5); 291 + static SENSOR_DEVICE_ATTR_2(in6_lcrit, S_IWUSR | S_IRUGO, max16065_show_limit, 292 + max16065_set_limit, 2, 6); 293 + static SENSOR_DEVICE_ATTR_2(in7_lcrit, S_IWUSR | S_IRUGO, max16065_show_limit, 294 + max16065_set_limit, 2, 7); 295 + static SENSOR_DEVICE_ATTR_2(in8_lcrit, S_IWUSR | S_IRUGO, max16065_show_limit, 296 + max16065_set_limit, 2, 8); 297 + static SENSOR_DEVICE_ATTR_2(in9_lcrit, S_IWUSR | S_IRUGO, max16065_show_limit, 298 + max16065_set_limit, 2, 9); 299 + static SENSOR_DEVICE_ATTR_2(in10_lcrit, S_IWUSR | S_IRUGO, max16065_show_limit, 300 + max16065_set_limit, 2, 10); 301 + static SENSOR_DEVICE_ATTR_2(in11_lcrit, S_IWUSR | S_IRUGO, max16065_show_limit, 302 + max16065_set_limit, 2, 11); 303 + 304 + /* Input voltages crit */ 305 + static SENSOR_DEVICE_ATTR_2(in0_crit, S_IWUSR | S_IRUGO, max16065_show_limit, 306 + max16065_set_limit, 1, 0); 307 + static SENSOR_DEVICE_ATTR_2(in1_crit, S_IWUSR | S_IRUGO, max16065_show_limit, 308 + max16065_set_limit, 1, 1); 309 + static SENSOR_DEVICE_ATTR_2(in2_crit, S_IWUSR | S_IRUGO, max16065_show_limit, 310 + max16065_set_limit, 1, 2); 311 + static SENSOR_DEVICE_ATTR_2(in3_crit, S_IWUSR | S_IRUGO, max16065_show_limit, 312 + max16065_set_limit, 1, 3); 313 + static SENSOR_DEVICE_ATTR_2(in4_crit, S_IWUSR | S_IRUGO, max16065_show_limit, 314 + max16065_set_limit, 1, 4); 315 + static SENSOR_DEVICE_ATTR_2(in5_crit, S_IWUSR | S_IRUGO, max16065_show_limit, 316 + max16065_set_limit, 1, 5); 317 + static SENSOR_DEVICE_ATTR_2(in6_crit, S_IWUSR | S_IRUGO, max16065_show_limit, 318 + max16065_set_limit, 1, 6); 319 + static SENSOR_DEVICE_ATTR_2(in7_crit, S_IWUSR | S_IRUGO, max16065_show_limit, 320 + max16065_set_limit, 1, 7); 321 + static SENSOR_DEVICE_ATTR_2(in8_crit, S_IWUSR | S_IRUGO, max16065_show_limit, 322 + max16065_set_limit, 1, 8); 323 + static SENSOR_DEVICE_ATTR_2(in9_crit, S_IWUSR | S_IRUGO, max16065_show_limit, 324 + max16065_set_limit, 1, 9); 325 + static SENSOR_DEVICE_ATTR_2(in10_crit, S_IWUSR | S_IRUGO, max16065_show_limit, 326 + max16065_set_limit, 1, 10); 327 + static SENSOR_DEVICE_ATTR_2(in11_crit, S_IWUSR | S_IRUGO, max16065_show_limit, 328 + max16065_set_limit, 1, 11); 329 + 330 + /* Input voltages min */ 331 + static SENSOR_DEVICE_ATTR_2(in0_min, S_IWUSR | S_IRUGO, max16065_show_limit, 332 + max16065_set_limit, 0, 0); 333 + static SENSOR_DEVICE_ATTR_2(in1_min, S_IWUSR | S_IRUGO, max16065_show_limit, 334 + max16065_set_limit, 0, 1); 335 + static SENSOR_DEVICE_ATTR_2(in2_min, S_IWUSR | S_IRUGO, max16065_show_limit, 336 + max16065_set_limit, 0, 2); 337 + static SENSOR_DEVICE_ATTR_2(in3_min, S_IWUSR | S_IRUGO, max16065_show_limit, 338 + max16065_set_limit, 0, 3); 339 + static SENSOR_DEVICE_ATTR_2(in4_min, S_IWUSR | S_IRUGO, max16065_show_limit, 340 + max16065_set_limit, 0, 4); 341 + static SENSOR_DEVICE_ATTR_2(in5_min, S_IWUSR | S_IRUGO, max16065_show_limit, 342 + max16065_set_limit, 0, 5); 343 + static SENSOR_DEVICE_ATTR_2(in6_min, S_IWUSR | S_IRUGO, max16065_show_limit, 344 + max16065_set_limit, 0, 6); 345 + static SENSOR_DEVICE_ATTR_2(in7_min, S_IWUSR | S_IRUGO, max16065_show_limit, 346 + max16065_set_limit, 0, 7); 347 + static SENSOR_DEVICE_ATTR_2(in8_min, S_IWUSR | S_IRUGO, max16065_show_limit, 348 + max16065_set_limit, 0, 8); 349 + static SENSOR_DEVICE_ATTR_2(in9_min, S_IWUSR | S_IRUGO, max16065_show_limit, 350 + max16065_set_limit, 0, 9); 351 + static SENSOR_DEVICE_ATTR_2(in10_min, S_IWUSR | S_IRUGO, max16065_show_limit, 352 + max16065_set_limit, 0, 10); 353 + static SENSOR_DEVICE_ATTR_2(in11_min, S_IWUSR | S_IRUGO, max16065_show_limit, 354 + max16065_set_limit, 0, 11); 355 + 356 + /* Input voltages max */ 357 + static SENSOR_DEVICE_ATTR_2(in0_max, S_IWUSR | S_IRUGO, max16065_show_limit, 358 + max16065_set_limit, 0, 0); 359 + static SENSOR_DEVICE_ATTR_2(in1_max, S_IWUSR | S_IRUGO, max16065_show_limit, 360 + max16065_set_limit, 0, 1); 361 + static SENSOR_DEVICE_ATTR_2(in2_max, S_IWUSR | S_IRUGO, max16065_show_limit, 362 + max16065_set_limit, 0, 2); 363 + static SENSOR_DEVICE_ATTR_2(in3_max, S_IWUSR | S_IRUGO, max16065_show_limit, 364 + max16065_set_limit, 0, 3); 365 + static SENSOR_DEVICE_ATTR_2(in4_max, S_IWUSR | S_IRUGO, max16065_show_limit, 366 + max16065_set_limit, 0, 4); 367 + static SENSOR_DEVICE_ATTR_2(in5_max, S_IWUSR | S_IRUGO, max16065_show_limit, 368 + max16065_set_limit, 0, 5); 369 + static SENSOR_DEVICE_ATTR_2(in6_max, S_IWUSR | S_IRUGO, max16065_show_limit, 370 + max16065_set_limit, 0, 6); 371 + static SENSOR_DEVICE_ATTR_2(in7_max, S_IWUSR | S_IRUGO, max16065_show_limit, 372 + max16065_set_limit, 0, 7); 373 + static SENSOR_DEVICE_ATTR_2(in8_max, S_IWUSR | S_IRUGO, max16065_show_limit, 374 + max16065_set_limit, 0, 8); 375 + static SENSOR_DEVICE_ATTR_2(in9_max, S_IWUSR | S_IRUGO, max16065_show_limit, 376 + max16065_set_limit, 0, 9); 377 + static SENSOR_DEVICE_ATTR_2(in10_max, S_IWUSR | S_IRUGO, max16065_show_limit, 378 + max16065_set_limit, 0, 10); 379 + static SENSOR_DEVICE_ATTR_2(in11_max, S_IWUSR | S_IRUGO, max16065_show_limit, 380 + max16065_set_limit, 0, 11); 381 + 382 + /* alarms */ 383 + static SENSOR_DEVICE_ATTR_2(in0_alarm, S_IRUGO, max16065_show_alarm, NULL, 384 + 0, 0); 385 + static SENSOR_DEVICE_ATTR_2(in1_alarm, S_IRUGO, max16065_show_alarm, NULL, 386 + 0, 1); 387 + static SENSOR_DEVICE_ATTR_2(in2_alarm, S_IRUGO, max16065_show_alarm, NULL, 388 + 0, 2); 389 + static SENSOR_DEVICE_ATTR_2(in3_alarm, S_IRUGO, max16065_show_alarm, NULL, 390 + 0, 3); 391 + static SENSOR_DEVICE_ATTR_2(in4_alarm, S_IRUGO, max16065_show_alarm, NULL, 392 + 0, 4); 393 + static SENSOR_DEVICE_ATTR_2(in5_alarm, S_IRUGO, max16065_show_alarm, NULL, 394 + 0, 5); 395 + static SENSOR_DEVICE_ATTR_2(in6_alarm, S_IRUGO, max16065_show_alarm, NULL, 396 + 0, 6); 397 + static SENSOR_DEVICE_ATTR_2(in7_alarm, S_IRUGO, max16065_show_alarm, NULL, 398 + 0, 7); 399 + static SENSOR_DEVICE_ATTR_2(in8_alarm, S_IRUGO, max16065_show_alarm, NULL, 400 + 1, 0); 401 + static SENSOR_DEVICE_ATTR_2(in9_alarm, S_IRUGO, max16065_show_alarm, NULL, 402 + 1, 1); 403 + static SENSOR_DEVICE_ATTR_2(in10_alarm, S_IRUGO, max16065_show_alarm, NULL, 404 + 1, 2); 405 + static SENSOR_DEVICE_ATTR_2(in11_alarm, S_IRUGO, max16065_show_alarm, NULL, 406 + 1, 3); 407 + 408 + /* Current and alarm */ 409 + static SENSOR_DEVICE_ATTR(curr1_input, S_IRUGO, max16065_show_current, NULL, 0); 410 + static SENSOR_DEVICE_ATTR_2(curr1_alarm, S_IRUGO, max16065_show_alarm, NULL, 411 + 1, 4); 412 + 413 + /* 414 + * Finally, construct an array of pointers to members of the above objects, 415 + * as required for sysfs_create_group() 416 + */ 417 + static struct attribute *max16065_basic_attributes[] = { 418 + &sensor_dev_attr_in0_input.dev_attr.attr, 419 + &sensor_dev_attr_in0_lcrit.dev_attr.attr, 420 + &sensor_dev_attr_in0_crit.dev_attr.attr, 421 + &sensor_dev_attr_in0_alarm.dev_attr.attr, 422 + 423 + &sensor_dev_attr_in1_input.dev_attr.attr, 424 + &sensor_dev_attr_in1_lcrit.dev_attr.attr, 425 + &sensor_dev_attr_in1_crit.dev_attr.attr, 426 + &sensor_dev_attr_in1_alarm.dev_attr.attr, 427 + 428 + &sensor_dev_attr_in2_input.dev_attr.attr, 429 + &sensor_dev_attr_in2_lcrit.dev_attr.attr, 430 + &sensor_dev_attr_in2_crit.dev_attr.attr, 431 + &sensor_dev_attr_in2_alarm.dev_attr.attr, 432 + 433 + &sensor_dev_attr_in3_input.dev_attr.attr, 434 + &sensor_dev_attr_in3_lcrit.dev_attr.attr, 435 + &sensor_dev_attr_in3_crit.dev_attr.attr, 436 + &sensor_dev_attr_in3_alarm.dev_attr.attr, 437 + 438 + &sensor_dev_attr_in4_input.dev_attr.attr, 439 + &sensor_dev_attr_in4_lcrit.dev_attr.attr, 440 + &sensor_dev_attr_in4_crit.dev_attr.attr, 441 + &sensor_dev_attr_in4_alarm.dev_attr.attr, 442 + 443 + &sensor_dev_attr_in5_input.dev_attr.attr, 444 + &sensor_dev_attr_in5_lcrit.dev_attr.attr, 445 + &sensor_dev_attr_in5_crit.dev_attr.attr, 446 + &sensor_dev_attr_in5_alarm.dev_attr.attr, 447 + 448 + &sensor_dev_attr_in6_input.dev_attr.attr, 449 + &sensor_dev_attr_in6_lcrit.dev_attr.attr, 450 + &sensor_dev_attr_in6_crit.dev_attr.attr, 451 + &sensor_dev_attr_in6_alarm.dev_attr.attr, 452 + 453 + &sensor_dev_attr_in7_input.dev_attr.attr, 454 + &sensor_dev_attr_in7_lcrit.dev_attr.attr, 455 + &sensor_dev_attr_in7_crit.dev_attr.attr, 456 + &sensor_dev_attr_in7_alarm.dev_attr.attr, 457 + 458 + &sensor_dev_attr_in8_input.dev_attr.attr, 459 + &sensor_dev_attr_in8_lcrit.dev_attr.attr, 460 + &sensor_dev_attr_in8_crit.dev_attr.attr, 461 + &sensor_dev_attr_in8_alarm.dev_attr.attr, 462 + 463 + &sensor_dev_attr_in9_input.dev_attr.attr, 464 + &sensor_dev_attr_in9_lcrit.dev_attr.attr, 465 + &sensor_dev_attr_in9_crit.dev_attr.attr, 466 + &sensor_dev_attr_in9_alarm.dev_attr.attr, 467 + 468 + &sensor_dev_attr_in10_input.dev_attr.attr, 469 + &sensor_dev_attr_in10_lcrit.dev_attr.attr, 470 + &sensor_dev_attr_in10_crit.dev_attr.attr, 471 + &sensor_dev_attr_in10_alarm.dev_attr.attr, 472 + 473 + &sensor_dev_attr_in11_input.dev_attr.attr, 474 + &sensor_dev_attr_in11_lcrit.dev_attr.attr, 475 + &sensor_dev_attr_in11_crit.dev_attr.attr, 476 + &sensor_dev_attr_in11_alarm.dev_attr.attr, 477 + 478 + NULL 479 + }; 480 + 481 + static struct attribute *max16065_current_attributes[] = { 482 + &sensor_dev_attr_in12_input.dev_attr.attr, 483 + &sensor_dev_attr_curr1_input.dev_attr.attr, 484 + &sensor_dev_attr_curr1_alarm.dev_attr.attr, 485 + NULL 486 + }; 487 + 488 + static struct attribute *max16065_min_attributes[] = { 489 + &sensor_dev_attr_in0_min.dev_attr.attr, 490 + &sensor_dev_attr_in1_min.dev_attr.attr, 491 + &sensor_dev_attr_in2_min.dev_attr.attr, 492 + &sensor_dev_attr_in3_min.dev_attr.attr, 493 + &sensor_dev_attr_in4_min.dev_attr.attr, 494 + &sensor_dev_attr_in5_min.dev_attr.attr, 495 + &sensor_dev_attr_in6_min.dev_attr.attr, 496 + &sensor_dev_attr_in7_min.dev_attr.attr, 497 + &sensor_dev_attr_in8_min.dev_attr.attr, 498 + &sensor_dev_attr_in9_min.dev_attr.attr, 499 + &sensor_dev_attr_in10_min.dev_attr.attr, 500 + &sensor_dev_attr_in11_min.dev_attr.attr, 501 + NULL 502 + }; 503 + 504 + static struct attribute *max16065_max_attributes[] = { 505 + &sensor_dev_attr_in0_max.dev_attr.attr, 506 + &sensor_dev_attr_in1_max.dev_attr.attr, 507 + &sensor_dev_attr_in2_max.dev_attr.attr, 508 + &sensor_dev_attr_in3_max.dev_attr.attr, 509 + &sensor_dev_attr_in4_max.dev_attr.attr, 510 + &sensor_dev_attr_in5_max.dev_attr.attr, 511 + &sensor_dev_attr_in6_max.dev_attr.attr, 512 + &sensor_dev_attr_in7_max.dev_attr.attr, 513 + &sensor_dev_attr_in8_max.dev_attr.attr, 514 + &sensor_dev_attr_in9_max.dev_attr.attr, 515 + &sensor_dev_attr_in10_max.dev_attr.attr, 516 + &sensor_dev_attr_in11_max.dev_attr.attr, 517 + NULL 518 + }; 519 + 520 + static const struct attribute_group max16065_basic_group = { 521 + .attrs = max16065_basic_attributes, 522 + }; 523 + 524 + static const struct attribute_group max16065_current_group = { 525 + .attrs = max16065_current_attributes, 526 + }; 527 + 528 + static const struct attribute_group max16065_min_group = { 529 + .attrs = max16065_min_attributes, 530 + }; 531 + 532 + static const struct attribute_group max16065_max_group = { 533 + .attrs = max16065_max_attributes, 534 + }; 535 + 536 + static void max16065_cleanup(struct i2c_client *client) 537 + { 538 + sysfs_remove_group(&client->dev.kobj, &max16065_max_group); 539 + sysfs_remove_group(&client->dev.kobj, &max16065_min_group); 540 + sysfs_remove_group(&client->dev.kobj, &max16065_current_group); 541 + sysfs_remove_group(&client->dev.kobj, &max16065_basic_group); 542 + } 543 + 544 + static int max16065_probe(struct i2c_client *client, 545 + const struct i2c_device_id *id) 546 + { 547 + struct i2c_adapter *adapter = client->adapter; 548 + struct max16065_data *data; 549 + int i, j, val, ret; 550 + bool have_secondary; /* true if chip has secondary limits */ 551 + bool secondary_is_max = false; /* secondary limits reflect max */ 552 + 553 + if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA 554 + | I2C_FUNC_SMBUS_READ_WORD_DATA)) 555 + return -ENODEV; 556 + 557 + data = kzalloc(sizeof(*data), GFP_KERNEL); 558 + if (unlikely(!data)) 559 + return -ENOMEM; 560 + 561 + i2c_set_clientdata(client, data); 562 + mutex_init(&data->update_lock); 563 + 564 + data->num_adc = max16065_num_adc[id->driver_data]; 565 + data->have_current = max16065_have_current[id->driver_data]; 566 + have_secondary = max16065_have_secondary[id->driver_data]; 567 + 568 + if (have_secondary) { 569 + val = i2c_smbus_read_byte_data(client, MAX16065_SW_ENABLE); 570 + if (unlikely(val < 0)) { 571 + ret = val; 572 + goto out_free; 573 + } 574 + secondary_is_max = val & MAX16065_WARNING_OV; 575 + } 576 + 577 + /* Read scale registers, convert to range */ 578 + for (i = 0; i < DIV_ROUND_UP(data->num_adc, 4); i++) { 579 + val = i2c_smbus_read_byte_data(client, MAX16065_SCALE(i)); 580 + if (unlikely(val < 0)) { 581 + ret = val; 582 + goto out_free; 583 + } 584 + for (j = 0; j < 4 && i * 4 + j < data->num_adc; j++) { 585 + data->range[i * 4 + j] = 586 + max16065_adc_range[(val >> (j * 2)) & 0x3]; 587 + } 588 + } 589 + 590 + /* Read limits */ 591 + for (i = 0; i < MAX16065_NUM_LIMIT; i++) { 592 + if (i == 0 && !have_secondary) 593 + continue; 594 + 595 + for (j = 0; j < data->num_adc; j++) { 596 + val = i2c_smbus_read_byte_data(client, 597 + MAX16065_LIMIT(i, j)); 598 + if (unlikely(val < 0)) { 599 + ret = val; 600 + goto out_free; 601 + } 602 + data->limit[i][j] = LIMIT_TO_MV(val, data->range[j]); 603 + } 604 + } 605 + 606 + /* Register sysfs hooks */ 607 + for (i = 0; i < data->num_adc * 4; i++) { 608 + /* Do not create sysfs entry if channel is disabled */ 609 + if (!data->range[i / 4]) 610 + continue; 611 + 612 + ret = sysfs_create_file(&client->dev.kobj, 613 + max16065_basic_attributes[i]); 614 + if (unlikely(ret)) 615 + goto out; 616 + } 617 + 618 + if (have_secondary) { 619 + struct attribute **attr = secondary_is_max ? 620 + max16065_max_attributes : max16065_min_attributes; 621 + 622 + for (i = 0; i < data->num_adc; i++) { 623 + if (!data->range[i]) 624 + continue; 625 + 626 + ret = sysfs_create_file(&client->dev.kobj, attr[i]); 627 + if (unlikely(ret)) 628 + goto out; 629 + } 630 + } 631 + 632 + if (data->have_current) { 633 + val = i2c_smbus_read_byte_data(client, MAX16065_CURR_CONTROL); 634 + if (unlikely(val < 0)) { 635 + ret = val; 636 + goto out; 637 + } 638 + if (val & MAX16065_CURR_ENABLE) { 639 + /* 640 + * Current gain is 6, 12, 24, 48 based on values in 641 + * bit 2,3. 642 + */ 643 + data->curr_gain = 6 << ((val >> 2) & 0x03); 644 + data->range[MAX16065_NUM_ADC] 645 + = max16065_csp_adc_range[(val >> 1) & 0x01]; 646 + ret = sysfs_create_group(&client->dev.kobj, 647 + &max16065_current_group); 648 + if (unlikely(ret)) 649 + goto out; 650 + } else { 651 + data->have_current = false; 652 + } 653 + } 654 + 655 + data->hwmon_dev = hwmon_device_register(&client->dev); 656 + if (unlikely(IS_ERR(data->hwmon_dev))) { 657 + ret = PTR_ERR(data->hwmon_dev); 658 + goto out; 659 + } 660 + return 0; 661 + 662 + out: 663 + max16065_cleanup(client); 664 + out_free: 665 + kfree(data); 666 + return ret; 667 + } 668 + 669 + static int max16065_remove(struct i2c_client *client) 670 + { 671 + struct max16065_data *data = i2c_get_clientdata(client); 672 + 673 + hwmon_device_unregister(data->hwmon_dev); 674 + max16065_cleanup(client); 675 + kfree(data); 676 + 677 + return 0; 678 + } 679 + 680 + static const struct i2c_device_id max16065_id[] = { 681 + { "max16065", max16065 }, 682 + { "max16066", max16066 }, 683 + { "max16067", max16067 }, 684 + { "max16068", max16068 }, 685 + { "max16070", max16070 }, 686 + { "max16071", max16071 }, 687 + { } 688 + }; 689 + 690 + MODULE_DEVICE_TABLE(i2c, max16065_id); 691 + 692 + /* This is the driver that will be inserted */ 693 + static struct i2c_driver max16065_driver = { 694 + .driver = { 695 + .name = "max16065", 696 + }, 697 + .probe = max16065_probe, 698 + .remove = max16065_remove, 699 + .id_table = max16065_id, 700 + }; 701 + 702 + static int __init max16065_init(void) 703 + { 704 + return i2c_add_driver(&max16065_driver); 705 + } 706 + 707 + static void __exit max16065_exit(void) 708 + { 709 + i2c_del_driver(&max16065_driver); 710 + } 711 + 712 + MODULE_AUTHOR("Guenter Roeck <guenter.roeck@ericsson.com>"); 713 + MODULE_DESCRIPTION("MAX16065 driver"); 714 + MODULE_LICENSE("GPL"); 715 + 716 + module_init(max16065_init); 717 + module_exit(max16065_exit);
+3 -3
drivers/hwmon/max34440.c
··· 32 32 #define MAX34440_STATUS_OT_FAULT (1 << 5) 33 33 #define MAX34440_STATUS_OT_WARN (1 << 6) 34 34 35 - static int max34440_get_status(struct i2c_client *client, int page, int reg) 35 + static int max34440_read_byte_data(struct i2c_client *client, int page, int reg) 36 36 { 37 37 int ret; 38 38 int mfg_status; ··· 108 108 .func[11] = PMBUS_HAVE_TEMP | PMBUS_HAVE_STATUS_TEMP, 109 109 .func[12] = PMBUS_HAVE_TEMP | PMBUS_HAVE_STATUS_TEMP, 110 110 .func[13] = PMBUS_HAVE_TEMP | PMBUS_HAVE_STATUS_TEMP, 111 - .get_status = max34440_get_status, 111 + .read_byte_data = max34440_read_byte_data, 112 112 }, 113 113 [max34441] = { 114 114 .pages = 12, ··· 149 149 .func[9] = PMBUS_HAVE_TEMP | PMBUS_HAVE_STATUS_TEMP, 150 150 .func[10] = PMBUS_HAVE_TEMP | PMBUS_HAVE_STATUS_TEMP, 151 151 .func[11] = PMBUS_HAVE_TEMP | PMBUS_HAVE_STATUS_TEMP, 152 - .get_status = max34440_get_status, 152 + .read_byte_data = max34440_read_byte_data, 153 153 }, 154 154 }; 155 155
+356
drivers/hwmon/max6642.c
··· 1 + /* 2 + * Driver for +/-1 degree C, SMBus-Compatible Remote/Local Temperature Sensor 3 + * with Overtemperature Alarm 4 + * 5 + * Copyright (C) 2011 AppearTV AS 6 + * 7 + * Derived from: 8 + * 9 + * Based on the max1619 driver. 10 + * Copyright (C) 2003-2004 Alexey Fisher <fishor@mail.ru> 11 + * Jean Delvare <khali@linux-fr.org> 12 + * 13 + * The MAX6642 is a sensor chip made by Maxim. 14 + * It reports up to two temperatures (its own plus up to 15 + * one external one). Complete datasheet can be 16 + * obtained from Maxim's website at: 17 + * http://datasheets.maxim-ic.com/en/ds/MAX6642.pdf 18 + * 19 + * This program is free software; you can redistribute it and/or modify 20 + * it under the terms of the GNU General Public License as published by 21 + * the Free Software Foundation; either version 2 of the License, or 22 + * (at your option) any later version. 23 + * 24 + * This program is distributed in the hope that it will be useful, 25 + * but WITHOUT ANY WARRANTY; without even the implied warranty of 26 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 27 + * GNU General Public License for more details. 28 + * 29 + * You should have received a copy of the GNU General Public License 30 + * along with this program; if not, write to the Free Software 31 + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 32 + */ 33 + 34 + 35 + #include <linux/module.h> 36 + #include <linux/init.h> 37 + #include <linux/slab.h> 38 + #include <linux/jiffies.h> 39 + #include <linux/i2c.h> 40 + #include <linux/hwmon.h> 41 + #include <linux/hwmon-sysfs.h> 42 + #include <linux/err.h> 43 + #include <linux/mutex.h> 44 + #include <linux/sysfs.h> 45 + 46 + static const unsigned short normal_i2c[] = { 47 + 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f, I2C_CLIENT_END }; 48 + 49 + /* 50 + * The MAX6642 registers 51 + */ 52 + 53 + #define MAX6642_REG_R_MAN_ID 0xFE 54 + #define MAX6642_REG_R_CONFIG 0x03 55 + #define MAX6642_REG_W_CONFIG 0x09 56 + #define MAX6642_REG_R_STATUS 0x02 57 + #define MAX6642_REG_R_LOCAL_TEMP 0x00 58 + #define MAX6642_REG_R_LOCAL_TEMPL 0x11 59 + #define MAX6642_REG_R_LOCAL_HIGH 0x05 60 + #define MAX6642_REG_W_LOCAL_HIGH 0x0B 61 + #define MAX6642_REG_R_REMOTE_TEMP 0x01 62 + #define MAX6642_REG_R_REMOTE_TEMPL 0x10 63 + #define MAX6642_REG_R_REMOTE_HIGH 0x07 64 + #define MAX6642_REG_W_REMOTE_HIGH 0x0D 65 + 66 + /* 67 + * Conversions 68 + */ 69 + 70 + static int temp_from_reg10(int val) 71 + { 72 + return val * 250; 73 + } 74 + 75 + static int temp_from_reg(int val) 76 + { 77 + return val * 1000; 78 + } 79 + 80 + static int temp_to_reg(int val) 81 + { 82 + return val / 1000; 83 + } 84 + 85 + /* 86 + * Client data (each client gets its own) 87 + */ 88 + 89 + struct max6642_data { 90 + struct device *hwmon_dev; 91 + struct mutex update_lock; 92 + bool valid; /* zero until following fields are valid */ 93 + unsigned long last_updated; /* in jiffies */ 94 + 95 + /* registers values */ 96 + u16 temp_input[2]; /* local/remote */ 97 + u16 temp_high[2]; /* local/remote */ 98 + u8 alarms; 99 + }; 100 + 101 + /* 102 + * Real code 103 + */ 104 + 105 + static void max6642_init_client(struct i2c_client *client) 106 + { 107 + u8 config; 108 + struct max6642_data *data = i2c_get_clientdata(client); 109 + 110 + /* 111 + * Start the conversions. 112 + */ 113 + config = i2c_smbus_read_byte_data(client, MAX6642_REG_R_CONFIG); 114 + if (config & 0x40) 115 + i2c_smbus_write_byte_data(client, MAX6642_REG_W_CONFIG, 116 + config & 0xBF); /* run */ 117 + 118 + data->temp_high[0] = i2c_smbus_read_byte_data(client, 119 + MAX6642_REG_R_LOCAL_HIGH); 120 + data->temp_high[1] = i2c_smbus_read_byte_data(client, 121 + MAX6642_REG_R_REMOTE_HIGH); 122 + } 123 + 124 + /* Return 0 if detection is successful, -ENODEV otherwise */ 125 + static int max6642_detect(struct i2c_client *client, 126 + struct i2c_board_info *info) 127 + { 128 + struct i2c_adapter *adapter = client->adapter; 129 + u8 reg_config, reg_status, man_id; 130 + 131 + if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) 132 + return -ENODEV; 133 + 134 + /* identification */ 135 + man_id = i2c_smbus_read_byte_data(client, MAX6642_REG_R_MAN_ID); 136 + if (man_id != 0x4D) 137 + return -ENODEV; 138 + 139 + /* 140 + * We read the config and status register, the 4 lower bits in the 141 + * config register should be zero and bit 5, 3, 1 and 0 should be 142 + * zero in the status register. 143 + */ 144 + reg_config = i2c_smbus_read_byte_data(client, MAX6642_REG_R_CONFIG); 145 + reg_status = i2c_smbus_read_byte_data(client, MAX6642_REG_R_STATUS); 146 + if (((reg_config & 0x0f) != 0x00) || 147 + ((reg_status & 0x2b) != 0x00)) 148 + return -ENODEV; 149 + 150 + strlcpy(info->type, "max6642", I2C_NAME_SIZE); 151 + 152 + return 0; 153 + } 154 + 155 + static struct max6642_data *max6642_update_device(struct device *dev) 156 + { 157 + struct i2c_client *client = to_i2c_client(dev); 158 + struct max6642_data *data = i2c_get_clientdata(client); 159 + u16 val, tmp; 160 + 161 + mutex_lock(&data->update_lock); 162 + 163 + if (time_after(jiffies, data->last_updated + HZ) || !data->valid) { 164 + dev_dbg(&client->dev, "Updating max6642 data.\n"); 165 + val = i2c_smbus_read_byte_data(client, 166 + MAX6642_REG_R_LOCAL_TEMPL); 167 + tmp = (val >> 6) & 3; 168 + val = i2c_smbus_read_byte_data(client, 169 + MAX6642_REG_R_LOCAL_TEMP); 170 + val = (val << 2) | tmp; 171 + data->temp_input[0] = val; 172 + val = i2c_smbus_read_byte_data(client, 173 + MAX6642_REG_R_REMOTE_TEMPL); 174 + tmp = (val >> 6) & 3; 175 + val = i2c_smbus_read_byte_data(client, 176 + MAX6642_REG_R_REMOTE_TEMP); 177 + val = (val << 2) | tmp; 178 + data->temp_input[1] = val; 179 + data->alarms = i2c_smbus_read_byte_data(client, 180 + MAX6642_REG_R_STATUS); 181 + 182 + data->last_updated = jiffies; 183 + data->valid = 1; 184 + } 185 + 186 + mutex_unlock(&data->update_lock); 187 + 188 + return data; 189 + } 190 + 191 + /* 192 + * Sysfs stuff 193 + */ 194 + 195 + static ssize_t show_temp_max10(struct device *dev, 196 + struct device_attribute *dev_attr, char *buf) 197 + { 198 + struct max6642_data *data = max6642_update_device(dev); 199 + struct sensor_device_attribute *attr = to_sensor_dev_attr(dev_attr); 200 + 201 + return sprintf(buf, "%d\n", 202 + temp_from_reg10(data->temp_input[attr->index])); 203 + } 204 + 205 + static ssize_t show_temp_max(struct device *dev, struct device_attribute *attr, 206 + char *buf) 207 + { 208 + struct max6642_data *data = max6642_update_device(dev); 209 + struct sensor_device_attribute_2 *attr2 = to_sensor_dev_attr_2(attr); 210 + 211 + return sprintf(buf, "%d\n", temp_from_reg(data->temp_high[attr2->nr])); 212 + } 213 + 214 + static ssize_t set_temp_max(struct device *dev, struct device_attribute *attr, 215 + const char *buf, size_t count) 216 + { 217 + unsigned long val; 218 + int err; 219 + struct i2c_client *client = to_i2c_client(dev); 220 + struct max6642_data *data = i2c_get_clientdata(client); 221 + struct sensor_device_attribute_2 *attr2 = to_sensor_dev_attr_2(attr); 222 + 223 + err = strict_strtoul(buf, 10, &val); 224 + if (err < 0) 225 + return err; 226 + 227 + mutex_lock(&data->update_lock); 228 + data->temp_high[attr2->nr] = SENSORS_LIMIT(temp_to_reg(val), 0, 255); 229 + i2c_smbus_write_byte_data(client, attr2->index, 230 + data->temp_high[attr2->nr]); 231 + mutex_unlock(&data->update_lock); 232 + return count; 233 + } 234 + 235 + static ssize_t show_alarm(struct device *dev, struct device_attribute *attr, 236 + char *buf) 237 + { 238 + int bitnr = to_sensor_dev_attr(attr)->index; 239 + struct max6642_data *data = max6642_update_device(dev); 240 + return sprintf(buf, "%d\n", (data->alarms >> bitnr) & 1); 241 + } 242 + 243 + static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, show_temp_max10, NULL, 0); 244 + static SENSOR_DEVICE_ATTR(temp2_input, S_IRUGO, show_temp_max10, NULL, 1); 245 + static SENSOR_DEVICE_ATTR_2(temp1_max, S_IWUSR | S_IRUGO, show_temp_max, 246 + set_temp_max, 0, MAX6642_REG_W_LOCAL_HIGH); 247 + static SENSOR_DEVICE_ATTR_2(temp2_max, S_IWUSR | S_IRUGO, show_temp_max, 248 + set_temp_max, 1, MAX6642_REG_W_REMOTE_HIGH); 249 + static SENSOR_DEVICE_ATTR(temp_fault, S_IRUGO, show_alarm, NULL, 2); 250 + static SENSOR_DEVICE_ATTR(temp1_max_alarm, S_IRUGO, show_alarm, NULL, 6); 251 + static SENSOR_DEVICE_ATTR(temp2_max_alarm, S_IRUGO, show_alarm, NULL, 4); 252 + 253 + static struct attribute *max6642_attributes[] = { 254 + &sensor_dev_attr_temp1_input.dev_attr.attr, 255 + &sensor_dev_attr_temp2_input.dev_attr.attr, 256 + &sensor_dev_attr_temp1_max.dev_attr.attr, 257 + &sensor_dev_attr_temp2_max.dev_attr.attr, 258 + 259 + &sensor_dev_attr_temp_fault.dev_attr.attr, 260 + &sensor_dev_attr_temp1_max_alarm.dev_attr.attr, 261 + &sensor_dev_attr_temp2_max_alarm.dev_attr.attr, 262 + NULL 263 + }; 264 + 265 + static const struct attribute_group max6642_group = { 266 + .attrs = max6642_attributes, 267 + }; 268 + 269 + static int max6642_probe(struct i2c_client *new_client, 270 + const struct i2c_device_id *id) 271 + { 272 + struct max6642_data *data; 273 + int err; 274 + 275 + data = kzalloc(sizeof(struct max6642_data), GFP_KERNEL); 276 + if (!data) { 277 + err = -ENOMEM; 278 + goto exit; 279 + } 280 + 281 + i2c_set_clientdata(new_client, data); 282 + mutex_init(&data->update_lock); 283 + 284 + /* Initialize the MAX6642 chip */ 285 + max6642_init_client(new_client); 286 + 287 + /* Register sysfs hooks */ 288 + err = sysfs_create_group(&new_client->dev.kobj, &max6642_group); 289 + if (err) 290 + goto exit_free; 291 + 292 + data->hwmon_dev = hwmon_device_register(&new_client->dev); 293 + if (IS_ERR(data->hwmon_dev)) { 294 + err = PTR_ERR(data->hwmon_dev); 295 + goto exit_remove_files; 296 + } 297 + 298 + return 0; 299 + 300 + exit_remove_files: 301 + sysfs_remove_group(&new_client->dev.kobj, &max6642_group); 302 + exit_free: 303 + kfree(data); 304 + exit: 305 + return err; 306 + } 307 + 308 + static int max6642_remove(struct i2c_client *client) 309 + { 310 + struct max6642_data *data = i2c_get_clientdata(client); 311 + 312 + hwmon_device_unregister(data->hwmon_dev); 313 + sysfs_remove_group(&client->dev.kobj, &max6642_group); 314 + 315 + kfree(data); 316 + return 0; 317 + } 318 + 319 + /* 320 + * Driver data (common to all clients) 321 + */ 322 + 323 + static const struct i2c_device_id max6642_id[] = { 324 + { "max6642", 0 }, 325 + { } 326 + }; 327 + MODULE_DEVICE_TABLE(i2c, max6642_id); 328 + 329 + static struct i2c_driver max6642_driver = { 330 + .class = I2C_CLASS_HWMON, 331 + .driver = { 332 + .name = "max6642", 333 + }, 334 + .probe = max6642_probe, 335 + .remove = max6642_remove, 336 + .id_table = max6642_id, 337 + .detect = max6642_detect, 338 + .address_list = normal_i2c, 339 + }; 340 + 341 + static int __init max6642_init(void) 342 + { 343 + return i2c_add_driver(&max6642_driver); 344 + } 345 + 346 + static void __exit max6642_exit(void) 347 + { 348 + i2c_del_driver(&max6642_driver); 349 + } 350 + 351 + MODULE_AUTHOR("Per Dalen <per.dalen@appeartv.com>"); 352 + MODULE_DESCRIPTION("MAX6642 sensor driver"); 353 + MODULE_LICENSE("GPL"); 354 + 355 + module_init(max6642_init); 356 + module_exit(max6642_exit);
+2 -2
drivers/hwmon/max8688.c
··· 37 37 #define MAX8688_STATUS_OT_FAULT (1 << 13) 38 38 #define MAX8688_STATUS_OT_WARNING (1 << 14) 39 39 40 - static int max8688_get_status(struct i2c_client *client, int page, int reg) 40 + static int max8688_read_byte_data(struct i2c_client *client, int page, int reg) 41 41 { 42 42 int ret = 0; 43 43 int mfg_status; ··· 110 110 .func[0] = PMBUS_HAVE_VOUT | PMBUS_HAVE_IOUT | PMBUS_HAVE_TEMP 111 111 | PMBUS_HAVE_STATUS_VOUT | PMBUS_HAVE_STATUS_IOUT 112 112 | PMBUS_HAVE_STATUS_TEMP, 113 - .get_status = max8688_get_status, 113 + .read_byte_data = max8688_read_byte_data, 114 114 }; 115 115 116 116 static int max8688_probe(struct i2c_client *client,
-444
drivers/hwmon/pkgtemp.c
··· 1 - /* 2 - * pkgtemp.c - Linux kernel module for processor package hardware monitoring 3 - * 4 - * Copyright (C) 2010 Fenghua Yu <fenghua.yu@intel.com> 5 - * 6 - * Inspired from many hwmon drivers especially coretemp. 7 - * 8 - * This program is free software; you can redistribute it and/or modify 9 - * it under the terms of the GNU General Public License as published by 10 - * the Free Software Foundation; version 2 of the License. 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., 51 Franklin Street, Fifth Floor, Boston, MA 20 - * 02110-1301 USA. 21 - */ 22 - 23 - #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 24 - 25 - #include <linux/module.h> 26 - #include <linux/init.h> 27 - #include <linux/slab.h> 28 - #include <linux/jiffies.h> 29 - #include <linux/hwmon.h> 30 - #include <linux/sysfs.h> 31 - #include <linux/hwmon-sysfs.h> 32 - #include <linux/err.h> 33 - #include <linux/mutex.h> 34 - #include <linux/list.h> 35 - #include <linux/platform_device.h> 36 - #include <linux/cpu.h> 37 - #include <asm/msr.h> 38 - #include <asm/processor.h> 39 - #include <asm/smp.h> 40 - 41 - #define DRVNAME "pkgtemp" 42 - 43 - enum { SHOW_TEMP, SHOW_TJMAX, SHOW_TTARGET, SHOW_LABEL, SHOW_NAME }; 44 - 45 - /* 46 - * Functions declaration 47 - */ 48 - 49 - static struct pkgtemp_data *pkgtemp_update_device(struct device *dev); 50 - 51 - struct pkgtemp_data { 52 - struct device *hwmon_dev; 53 - struct mutex update_lock; 54 - const char *name; 55 - u32 id; 56 - u16 phys_proc_id; 57 - char valid; /* zero until following fields are valid */ 58 - unsigned long last_updated; /* in jiffies */ 59 - int temp; 60 - int tjmax; 61 - int ttarget; 62 - u8 alarm; 63 - }; 64 - 65 - /* 66 - * Sysfs stuff 67 - */ 68 - 69 - static ssize_t show_name(struct device *dev, struct device_attribute 70 - *devattr, char *buf) 71 - { 72 - int ret; 73 - struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); 74 - struct pkgtemp_data *data = dev_get_drvdata(dev); 75 - 76 - if (attr->index == SHOW_NAME) 77 - ret = sprintf(buf, "%s\n", data->name); 78 - else /* show label */ 79 - ret = sprintf(buf, "physical id %d\n", 80 - data->phys_proc_id); 81 - return ret; 82 - } 83 - 84 - static ssize_t show_alarm(struct device *dev, struct device_attribute 85 - *devattr, char *buf) 86 - { 87 - struct pkgtemp_data *data = pkgtemp_update_device(dev); 88 - /* read the Out-of-spec log, never clear */ 89 - return sprintf(buf, "%d\n", data->alarm); 90 - } 91 - 92 - static ssize_t show_temp(struct device *dev, 93 - struct device_attribute *devattr, char *buf) 94 - { 95 - struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); 96 - struct pkgtemp_data *data = pkgtemp_update_device(dev); 97 - int err = 0; 98 - 99 - if (attr->index == SHOW_TEMP) 100 - err = data->valid ? sprintf(buf, "%d\n", data->temp) : -EAGAIN; 101 - else if (attr->index == SHOW_TJMAX) 102 - err = sprintf(buf, "%d\n", data->tjmax); 103 - else 104 - err = sprintf(buf, "%d\n", data->ttarget); 105 - return err; 106 - } 107 - 108 - static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, show_temp, NULL, SHOW_TEMP); 109 - static SENSOR_DEVICE_ATTR(temp1_crit, S_IRUGO, show_temp, NULL, SHOW_TJMAX); 110 - static SENSOR_DEVICE_ATTR(temp1_max, S_IRUGO, show_temp, NULL, SHOW_TTARGET); 111 - static DEVICE_ATTR(temp1_crit_alarm, S_IRUGO, show_alarm, NULL); 112 - static SENSOR_DEVICE_ATTR(temp1_label, S_IRUGO, show_name, NULL, SHOW_LABEL); 113 - static SENSOR_DEVICE_ATTR(name, S_IRUGO, show_name, NULL, SHOW_NAME); 114 - 115 - static struct attribute *pkgtemp_attributes[] = { 116 - &sensor_dev_attr_name.dev_attr.attr, 117 - &sensor_dev_attr_temp1_label.dev_attr.attr, 118 - &dev_attr_temp1_crit_alarm.attr, 119 - &sensor_dev_attr_temp1_input.dev_attr.attr, 120 - &sensor_dev_attr_temp1_crit.dev_attr.attr, 121 - NULL 122 - }; 123 - 124 - static const struct attribute_group pkgtemp_group = { 125 - .attrs = pkgtemp_attributes, 126 - }; 127 - 128 - static struct pkgtemp_data *pkgtemp_update_device(struct device *dev) 129 - { 130 - struct pkgtemp_data *data = dev_get_drvdata(dev); 131 - unsigned int cpu; 132 - int err; 133 - 134 - mutex_lock(&data->update_lock); 135 - 136 - if (!data->valid || time_after(jiffies, data->last_updated + HZ)) { 137 - u32 eax, edx; 138 - 139 - data->valid = 0; 140 - cpu = data->id; 141 - err = rdmsr_on_cpu(cpu, MSR_IA32_PACKAGE_THERM_STATUS, 142 - &eax, &edx); 143 - if (!err) { 144 - data->alarm = (eax >> 5) & 1; 145 - data->temp = data->tjmax - (((eax >> 16) 146 - & 0x7f) * 1000); 147 - data->valid = 1; 148 - } else 149 - dev_dbg(dev, "Temperature data invalid (0x%x)\n", eax); 150 - 151 - data->last_updated = jiffies; 152 - } 153 - 154 - mutex_unlock(&data->update_lock); 155 - return data; 156 - } 157 - 158 - static int get_tjmax(int cpu, struct device *dev) 159 - { 160 - int default_tjmax = 100000; 161 - int err; 162 - u32 eax, edx; 163 - u32 val; 164 - 165 - /* IA32_TEMPERATURE_TARGET contains the TjMax value */ 166 - err = rdmsr_safe_on_cpu(cpu, MSR_IA32_TEMPERATURE_TARGET, &eax, &edx); 167 - if (!err) { 168 - val = (eax >> 16) & 0xff; 169 - if ((val > 80) && (val < 120)) { 170 - dev_info(dev, "TjMax is %d C.\n", val); 171 - return val * 1000; 172 - } 173 - } 174 - dev_warn(dev, "Unable to read TjMax from CPU.\n"); 175 - return default_tjmax; 176 - } 177 - 178 - static int __devinit pkgtemp_probe(struct platform_device *pdev) 179 - { 180 - struct pkgtemp_data *data; 181 - int err; 182 - u32 eax, edx; 183 - #ifdef CONFIG_SMP 184 - struct cpuinfo_x86 *c = &cpu_data(pdev->id); 185 - #endif 186 - 187 - data = kzalloc(sizeof(struct pkgtemp_data), GFP_KERNEL); 188 - if (!data) { 189 - err = -ENOMEM; 190 - dev_err(&pdev->dev, "Out of memory\n"); 191 - goto exit; 192 - } 193 - 194 - data->id = pdev->id; 195 - #ifdef CONFIG_SMP 196 - data->phys_proc_id = c->phys_proc_id; 197 - #endif 198 - data->name = "pkgtemp"; 199 - mutex_init(&data->update_lock); 200 - 201 - /* test if we can access the THERM_STATUS MSR */ 202 - err = rdmsr_safe_on_cpu(data->id, MSR_IA32_PACKAGE_THERM_STATUS, 203 - &eax, &edx); 204 - if (err) { 205 - dev_err(&pdev->dev, 206 - "Unable to access THERM_STATUS MSR, giving up\n"); 207 - goto exit_free; 208 - } 209 - 210 - data->tjmax = get_tjmax(data->id, &pdev->dev); 211 - platform_set_drvdata(pdev, data); 212 - 213 - err = rdmsr_safe_on_cpu(data->id, MSR_IA32_TEMPERATURE_TARGET, 214 - &eax, &edx); 215 - if (err) { 216 - dev_warn(&pdev->dev, "Unable to read" 217 - " IA32_TEMPERATURE_TARGET MSR\n"); 218 - } else { 219 - data->ttarget = data->tjmax - (((eax >> 8) & 0xff) * 1000); 220 - err = device_create_file(&pdev->dev, 221 - &sensor_dev_attr_temp1_max.dev_attr); 222 - if (err) 223 - goto exit_free; 224 - } 225 - 226 - err = sysfs_create_group(&pdev->dev.kobj, &pkgtemp_group); 227 - if (err) 228 - goto exit_dev; 229 - 230 - data->hwmon_dev = hwmon_device_register(&pdev->dev); 231 - if (IS_ERR(data->hwmon_dev)) { 232 - err = PTR_ERR(data->hwmon_dev); 233 - dev_err(&pdev->dev, "Class registration failed (%d)\n", 234 - err); 235 - goto exit_class; 236 - } 237 - 238 - return 0; 239 - 240 - exit_class: 241 - sysfs_remove_group(&pdev->dev.kobj, &pkgtemp_group); 242 - exit_dev: 243 - device_remove_file(&pdev->dev, &sensor_dev_attr_temp1_max.dev_attr); 244 - exit_free: 245 - kfree(data); 246 - exit: 247 - return err; 248 - } 249 - 250 - static int __devexit pkgtemp_remove(struct platform_device *pdev) 251 - { 252 - struct pkgtemp_data *data = platform_get_drvdata(pdev); 253 - 254 - hwmon_device_unregister(data->hwmon_dev); 255 - sysfs_remove_group(&pdev->dev.kobj, &pkgtemp_group); 256 - device_remove_file(&pdev->dev, &sensor_dev_attr_temp1_max.dev_attr); 257 - platform_set_drvdata(pdev, NULL); 258 - kfree(data); 259 - return 0; 260 - } 261 - 262 - static struct platform_driver pkgtemp_driver = { 263 - .driver = { 264 - .owner = THIS_MODULE, 265 - .name = DRVNAME, 266 - }, 267 - .probe = pkgtemp_probe, 268 - .remove = __devexit_p(pkgtemp_remove), 269 - }; 270 - 271 - struct pdev_entry { 272 - struct list_head list; 273 - struct platform_device *pdev; 274 - unsigned int cpu; 275 - #ifdef CONFIG_SMP 276 - u16 phys_proc_id; 277 - #endif 278 - }; 279 - 280 - static LIST_HEAD(pdev_list); 281 - static DEFINE_MUTEX(pdev_list_mutex); 282 - 283 - static int __cpuinit pkgtemp_device_add(unsigned int cpu) 284 - { 285 - int err; 286 - struct platform_device *pdev; 287 - struct pdev_entry *pdev_entry; 288 - struct cpuinfo_x86 *c = &cpu_data(cpu); 289 - 290 - if (!cpu_has(c, X86_FEATURE_PTS)) 291 - return 0; 292 - 293 - mutex_lock(&pdev_list_mutex); 294 - 295 - #ifdef CONFIG_SMP 296 - /* Only keep the first entry in each package */ 297 - list_for_each_entry(pdev_entry, &pdev_list, list) { 298 - if (c->phys_proc_id == pdev_entry->phys_proc_id) { 299 - err = 0; /* Not an error */ 300 - goto exit; 301 - } 302 - } 303 - #endif 304 - 305 - pdev = platform_device_alloc(DRVNAME, cpu); 306 - if (!pdev) { 307 - err = -ENOMEM; 308 - pr_err("Device allocation failed\n"); 309 - goto exit; 310 - } 311 - 312 - pdev_entry = kzalloc(sizeof(struct pdev_entry), GFP_KERNEL); 313 - if (!pdev_entry) { 314 - err = -ENOMEM; 315 - goto exit_device_put; 316 - } 317 - 318 - err = platform_device_add(pdev); 319 - if (err) { 320 - pr_err("Device addition failed (%d)\n", err); 321 - goto exit_device_free; 322 - } 323 - 324 - #ifdef CONFIG_SMP 325 - pdev_entry->phys_proc_id = c->phys_proc_id; 326 - #endif 327 - pdev_entry->pdev = pdev; 328 - pdev_entry->cpu = cpu; 329 - list_add_tail(&pdev_entry->list, &pdev_list); 330 - mutex_unlock(&pdev_list_mutex); 331 - 332 - return 0; 333 - 334 - exit_device_free: 335 - kfree(pdev_entry); 336 - exit_device_put: 337 - platform_device_put(pdev); 338 - exit: 339 - mutex_unlock(&pdev_list_mutex); 340 - return err; 341 - } 342 - 343 - static void __cpuinit pkgtemp_device_remove(unsigned int cpu) 344 - { 345 - struct pdev_entry *p; 346 - unsigned int i; 347 - int err; 348 - 349 - mutex_lock(&pdev_list_mutex); 350 - list_for_each_entry(p, &pdev_list, list) { 351 - if (p->cpu != cpu) 352 - continue; 353 - 354 - platform_device_unregister(p->pdev); 355 - list_del(&p->list); 356 - mutex_unlock(&pdev_list_mutex); 357 - kfree(p); 358 - for_each_cpu(i, cpu_core_mask(cpu)) { 359 - if (i != cpu) { 360 - err = pkgtemp_device_add(i); 361 - if (!err) 362 - break; 363 - } 364 - } 365 - return; 366 - } 367 - mutex_unlock(&pdev_list_mutex); 368 - } 369 - 370 - static int __cpuinit pkgtemp_cpu_callback(struct notifier_block *nfb, 371 - unsigned long action, void *hcpu) 372 - { 373 - unsigned int cpu = (unsigned long) hcpu; 374 - 375 - switch (action) { 376 - case CPU_ONLINE: 377 - case CPU_DOWN_FAILED: 378 - pkgtemp_device_add(cpu); 379 - break; 380 - case CPU_DOWN_PREPARE: 381 - pkgtemp_device_remove(cpu); 382 - break; 383 - } 384 - return NOTIFY_OK; 385 - } 386 - 387 - static struct notifier_block pkgtemp_cpu_notifier __refdata = { 388 - .notifier_call = pkgtemp_cpu_callback, 389 - }; 390 - 391 - static int __init pkgtemp_init(void) 392 - { 393 - int i, err = -ENODEV; 394 - 395 - /* quick check if we run Intel */ 396 - if (cpu_data(0).x86_vendor != X86_VENDOR_INTEL) 397 - goto exit; 398 - 399 - err = platform_driver_register(&pkgtemp_driver); 400 - if (err) 401 - goto exit; 402 - 403 - for_each_online_cpu(i) 404 - pkgtemp_device_add(i); 405 - 406 - #ifndef CONFIG_HOTPLUG_CPU 407 - if (list_empty(&pdev_list)) { 408 - err = -ENODEV; 409 - goto exit_driver_unreg; 410 - } 411 - #endif 412 - 413 - register_hotcpu_notifier(&pkgtemp_cpu_notifier); 414 - return 0; 415 - 416 - #ifndef CONFIG_HOTPLUG_CPU 417 - exit_driver_unreg: 418 - platform_driver_unregister(&pkgtemp_driver); 419 - #endif 420 - exit: 421 - return err; 422 - } 423 - 424 - static void __exit pkgtemp_exit(void) 425 - { 426 - struct pdev_entry *p, *n; 427 - 428 - unregister_hotcpu_notifier(&pkgtemp_cpu_notifier); 429 - mutex_lock(&pdev_list_mutex); 430 - list_for_each_entry_safe(p, n, &pdev_list, list) { 431 - platform_device_unregister(p->pdev); 432 - list_del(&p->list); 433 - kfree(p); 434 - } 435 - mutex_unlock(&pdev_list_mutex); 436 - platform_driver_unregister(&pkgtemp_driver); 437 - } 438 - 439 - MODULE_AUTHOR("Fenghua Yu <fenghua.yu@intel.com>"); 440 - MODULE_DESCRIPTION("Intel processor package temperature monitor"); 441 - MODULE_LICENSE("GPL"); 442 - 443 - module_init(pkgtemp_init) 444 - module_exit(pkgtemp_exit)
+4 -6
drivers/hwmon/pmbus.h
··· 281 281 282 282 u32 func[PMBUS_PAGES]; /* Functionality, per page */ 283 283 /* 284 - * The get_status function maps manufacturing specific status values 285 - * into PMBus standard status values. 286 - * This function is optional and only necessary if chip specific status 287 - * register values have to be mapped into standard PMBus status register 288 - * values. 284 + * The following functions map manufacturing specific register values 285 + * to PMBus standard register values. Specify only if mapping is 286 + * necessary. 289 287 */ 290 - int (*get_status)(struct i2c_client *client, int page, int reg); 288 + int (*read_byte_data)(struct i2c_client *client, int page, int reg); 291 289 /* 292 290 * The identify function determines supported PMBus functionality. 293 291 * This function is only necessary if a chip driver supports multiple
+464 -552
drivers/hwmon/pmbus_core.c
··· 270 270 } 271 271 EXPORT_SYMBOL_GPL(pmbus_get_driver_info); 272 272 273 - static int pmbus_get_status(struct i2c_client *client, int page, int reg) 273 + /* 274 + * _pmbus_read_byte_data() is similar to pmbus_read_byte_data(), but checks if 275 + * a device specific mapping funcion exists and calls it if necessary. 276 + */ 277 + static int _pmbus_read_byte_data(struct i2c_client *client, int page, int reg) 274 278 { 275 279 struct pmbus_data *data = i2c_get_clientdata(client); 276 280 const struct pmbus_driver_info *info = data->info; 277 281 int status; 278 282 279 - if (info->get_status) { 280 - status = info->get_status(client, page, reg); 283 + if (info->read_byte_data) { 284 + status = info->read_byte_data(client, page, reg); 281 285 if (status != -ENODATA) 282 286 return status; 283 287 } 284 - return pmbus_read_byte_data(client, page, reg); 288 + return pmbus_read_byte_data(client, page, reg); 285 289 } 286 290 287 291 static struct pmbus_data *pmbus_update_device(struct device *dev) ··· 306 302 if (!(info->func[i] & PMBUS_HAVE_STATUS_VOUT)) 307 303 continue; 308 304 data->status[PB_STATUS_VOUT_BASE + i] 309 - = pmbus_get_status(client, i, PMBUS_STATUS_VOUT); 305 + = _pmbus_read_byte_data(client, i, PMBUS_STATUS_VOUT); 310 306 } 311 307 for (i = 0; i < info->pages; i++) { 312 308 if (!(info->func[i] & PMBUS_HAVE_STATUS_IOUT)) 313 309 continue; 314 310 data->status[PB_STATUS_IOUT_BASE + i] 315 - = pmbus_get_status(client, i, PMBUS_STATUS_IOUT); 311 + = _pmbus_read_byte_data(client, i, PMBUS_STATUS_IOUT); 316 312 } 317 313 for (i = 0; i < info->pages; i++) { 318 314 if (!(info->func[i] & PMBUS_HAVE_STATUS_TEMP)) 319 315 continue; 320 316 data->status[PB_STATUS_TEMP_BASE + i] 321 - = pmbus_get_status(client, i, 322 - PMBUS_STATUS_TEMPERATURE); 317 + = _pmbus_read_byte_data(client, i, 318 + PMBUS_STATUS_TEMPERATURE); 323 319 } 324 320 for (i = 0; i < info->pages; i++) { 325 321 if (!(info->func[i] & PMBUS_HAVE_STATUS_FAN12)) 326 322 continue; 327 323 data->status[PB_STATUS_FAN_BASE + i] 328 - = pmbus_get_status(client, i, PMBUS_STATUS_FAN_12); 324 + = _pmbus_read_byte_data(client, i, 325 + PMBUS_STATUS_FAN_12); 329 326 } 330 327 331 328 for (i = 0; i < info->pages; i++) { 332 329 if (!(info->func[i] & PMBUS_HAVE_STATUS_FAN34)) 333 330 continue; 334 331 data->status[PB_STATUS_FAN34_BASE + i] 335 - = pmbus_get_status(client, i, PMBUS_STATUS_FAN_34); 332 + = _pmbus_read_byte_data(client, i, 333 + PMBUS_STATUS_FAN_34); 336 334 } 337 335 338 336 if (info->func[0] & PMBUS_HAVE_STATUS_INPUT) 339 337 data->status[PB_STATUS_INPUT_BASE] 340 - = pmbus_get_status(client, 0, PMBUS_STATUS_INPUT); 338 + = _pmbus_read_byte_data(client, 0, 339 + PMBUS_STATUS_INPUT); 341 340 342 341 for (i = 0; i < data->num_sensors; i++) { 343 342 struct pmbus_sensor *sensor = &data->sensors[i]; ··· 800 793 data->num_labels++; 801 794 } 802 795 803 - static const int pmbus_temp_registers[] = { 804 - PMBUS_READ_TEMPERATURE_1, 805 - PMBUS_READ_TEMPERATURE_2, 806 - PMBUS_READ_TEMPERATURE_3 807 - }; 808 - 809 - static const int pmbus_temp_flags[] = { 810 - PMBUS_HAVE_TEMP, 811 - PMBUS_HAVE_TEMP2, 812 - PMBUS_HAVE_TEMP3 813 - }; 814 - 815 - static const int pmbus_fan_registers[] = { 816 - PMBUS_READ_FAN_SPEED_1, 817 - PMBUS_READ_FAN_SPEED_2, 818 - PMBUS_READ_FAN_SPEED_3, 819 - PMBUS_READ_FAN_SPEED_4 820 - }; 821 - 822 - static const int pmbus_fan_config_registers[] = { 823 - PMBUS_FAN_CONFIG_12, 824 - PMBUS_FAN_CONFIG_12, 825 - PMBUS_FAN_CONFIG_34, 826 - PMBUS_FAN_CONFIG_34 827 - }; 828 - 829 - static const int pmbus_fan_status_registers[] = { 830 - PMBUS_STATUS_FAN_12, 831 - PMBUS_STATUS_FAN_12, 832 - PMBUS_STATUS_FAN_34, 833 - PMBUS_STATUS_FAN_34 834 - }; 835 - 836 - static const u32 pmbus_fan_flags[] = { 837 - PMBUS_HAVE_FAN12, 838 - PMBUS_HAVE_FAN12, 839 - PMBUS_HAVE_FAN34, 840 - PMBUS_HAVE_FAN34 841 - }; 842 - 843 - static const u32 pmbus_fan_status_flags[] = { 844 - PMBUS_HAVE_STATUS_FAN12, 845 - PMBUS_HAVE_STATUS_FAN12, 846 - PMBUS_HAVE_STATUS_FAN34, 847 - PMBUS_HAVE_STATUS_FAN34 848 - }; 849 - 850 796 /* 851 797 * Determine maximum number of sensors, booleans, and labels. 852 798 * To keep things simple, only make a rough high estimate. ··· 860 900 /* 861 901 * Search for attributes. Allocate sensors, booleans, and labels as needed. 862 902 */ 863 - static void pmbus_find_attributes(struct i2c_client *client, 864 - struct pmbus_data *data) 903 + 904 + /* 905 + * The pmbus_limit_attr structure describes a single limit attribute 906 + * and its associated alarm attribute. 907 + */ 908 + struct pmbus_limit_attr { 909 + u8 reg; /* Limit register */ 910 + const char *attr; /* Attribute name */ 911 + const char *alarm; /* Alarm attribute name */ 912 + u32 sbit; /* Alarm attribute status bit */ 913 + }; 914 + 915 + /* 916 + * The pmbus_sensor_attr structure describes one sensor attribute. This 917 + * description includes a reference to the associated limit attributes. 918 + */ 919 + struct pmbus_sensor_attr { 920 + u8 reg; /* sensor register */ 921 + enum pmbus_sensor_classes class;/* sensor class */ 922 + const char *label; /* sensor label */ 923 + bool paged; /* true if paged sensor */ 924 + bool update; /* true if update needed */ 925 + bool compare; /* true if compare function needed */ 926 + u32 func; /* sensor mask */ 927 + u32 sfunc; /* sensor status mask */ 928 + int sbase; /* status base register */ 929 + u32 gbit; /* generic status bit */ 930 + const struct pmbus_limit_attr *limit;/* limit registers */ 931 + int nlimit; /* # of limit registers */ 932 + }; 933 + 934 + /* 935 + * Add a set of limit attributes and, if supported, the associated 936 + * alarm attributes. 937 + */ 938 + static bool pmbus_add_limit_attrs(struct i2c_client *client, 939 + struct pmbus_data *data, 940 + const struct pmbus_driver_info *info, 941 + const char *name, int index, int page, 942 + int cbase, 943 + const struct pmbus_sensor_attr *attr) 944 + { 945 + const struct pmbus_limit_attr *l = attr->limit; 946 + int nlimit = attr->nlimit; 947 + bool have_alarm = false; 948 + int i, cindex; 949 + 950 + for (i = 0; i < nlimit; i++) { 951 + if (pmbus_check_word_register(client, page, l->reg)) { 952 + cindex = data->num_sensors; 953 + pmbus_add_sensor(data, name, l->attr, index, page, 954 + l->reg, attr->class, attr->update, 955 + false); 956 + if (info->func[page] & attr->sfunc) { 957 + if (attr->compare) { 958 + pmbus_add_boolean_cmp(data, name, 959 + l->alarm, index, 960 + cbase, cindex, 961 + attr->sbase + page, l->sbit); 962 + } else { 963 + pmbus_add_boolean_reg(data, name, 964 + l->alarm, index, 965 + attr->sbase + page, l->sbit); 966 + } 967 + have_alarm = true; 968 + } 969 + } 970 + l++; 971 + } 972 + return have_alarm; 973 + } 974 + 975 + static void pmbus_add_sensor_attrs_one(struct i2c_client *client, 976 + struct pmbus_data *data, 977 + const struct pmbus_driver_info *info, 978 + const char *name, 979 + int index, int page, 980 + const struct pmbus_sensor_attr *attr) 981 + { 982 + bool have_alarm; 983 + int cbase = data->num_sensors; 984 + 985 + if (attr->label) 986 + pmbus_add_label(data, name, index, attr->label, 987 + attr->paged ? page + 1 : 0); 988 + pmbus_add_sensor(data, name, "input", index, page, attr->reg, 989 + attr->class, true, true); 990 + if (attr->sfunc) { 991 + have_alarm = pmbus_add_limit_attrs(client, data, info, name, 992 + index, page, cbase, attr); 993 + /* 994 + * Add generic alarm attribute only if there are no individual 995 + * alarm attributes, and if there is a global alarm bit. 996 + */ 997 + if (!have_alarm && attr->gbit) 998 + pmbus_add_boolean_reg(data, name, "alarm", index, 999 + PB_STATUS_BASE + page, 1000 + attr->gbit); 1001 + } 1002 + } 1003 + 1004 + static void pmbus_add_sensor_attrs(struct i2c_client *client, 1005 + struct pmbus_data *data, 1006 + const char *name, 1007 + const struct pmbus_sensor_attr *attrs, 1008 + int nattrs) 865 1009 { 866 1010 const struct pmbus_driver_info *info = data->info; 867 - int page, i0, i1, in_index; 1011 + int index, i; 868 1012 869 - /* 870 - * Input voltage sensors 871 - */ 872 - in_index = 1; 873 - if (info->func[0] & PMBUS_HAVE_VIN) { 874 - bool have_alarm = false; 1013 + index = 1; 1014 + for (i = 0; i < nattrs; i++) { 1015 + int page, pages; 875 1016 876 - i0 = data->num_sensors; 877 - pmbus_add_label(data, "in", in_index, "vin", 0); 878 - pmbus_add_sensor(data, "in", "input", in_index, 0, 879 - PMBUS_READ_VIN, PSC_VOLTAGE_IN, true, true); 880 - if (pmbus_check_word_register(client, 0, 881 - PMBUS_VIN_UV_WARN_LIMIT)) { 882 - i1 = data->num_sensors; 883 - pmbus_add_sensor(data, "in", "min", in_index, 884 - 0, PMBUS_VIN_UV_WARN_LIMIT, 885 - PSC_VOLTAGE_IN, false, false); 886 - if (info->func[0] & PMBUS_HAVE_STATUS_INPUT) { 887 - pmbus_add_boolean_reg(data, "in", "min_alarm", 888 - in_index, 889 - PB_STATUS_INPUT_BASE, 890 - PB_VOLTAGE_UV_WARNING); 891 - have_alarm = true; 892 - } 893 - } 894 - if (pmbus_check_word_register(client, 0, 895 - PMBUS_VIN_UV_FAULT_LIMIT)) { 896 - i1 = data->num_sensors; 897 - pmbus_add_sensor(data, "in", "lcrit", in_index, 898 - 0, PMBUS_VIN_UV_FAULT_LIMIT, 899 - PSC_VOLTAGE_IN, false, false); 900 - if (info->func[0] & PMBUS_HAVE_STATUS_INPUT) { 901 - pmbus_add_boolean_reg(data, "in", "lcrit_alarm", 902 - in_index, 903 - PB_STATUS_INPUT_BASE, 904 - PB_VOLTAGE_UV_FAULT); 905 - have_alarm = true; 906 - } 907 - } 908 - if (pmbus_check_word_register(client, 0, 909 - PMBUS_VIN_OV_WARN_LIMIT)) { 910 - i1 = data->num_sensors; 911 - pmbus_add_sensor(data, "in", "max", in_index, 912 - 0, PMBUS_VIN_OV_WARN_LIMIT, 913 - PSC_VOLTAGE_IN, false, false); 914 - if (info->func[0] & PMBUS_HAVE_STATUS_INPUT) { 915 - pmbus_add_boolean_reg(data, "in", "max_alarm", 916 - in_index, 917 - PB_STATUS_INPUT_BASE, 918 - PB_VOLTAGE_OV_WARNING); 919 - have_alarm = true; 920 - } 921 - } 922 - if (pmbus_check_word_register(client, 0, 923 - PMBUS_VIN_OV_FAULT_LIMIT)) { 924 - i1 = data->num_sensors; 925 - pmbus_add_sensor(data, "in", "crit", in_index, 926 - 0, PMBUS_VIN_OV_FAULT_LIMIT, 927 - PSC_VOLTAGE_IN, false, false); 928 - if (info->func[0] & PMBUS_HAVE_STATUS_INPUT) { 929 - pmbus_add_boolean_reg(data, "in", "crit_alarm", 930 - in_index, 931 - PB_STATUS_INPUT_BASE, 932 - PB_VOLTAGE_OV_FAULT); 933 - have_alarm = true; 934 - } 935 - } 936 - /* 937 - * Add generic alarm attribute only if there are no individual 938 - * attributes. 939 - */ 940 - if (!have_alarm) 941 - pmbus_add_boolean_reg(data, "in", "alarm", 942 - in_index, 943 - PB_STATUS_BASE, 944 - PB_STATUS_VIN_UV); 945 - in_index++; 946 - } 947 - if (info->func[0] & PMBUS_HAVE_VCAP) { 948 - pmbus_add_label(data, "in", in_index, "vcap", 0); 949 - pmbus_add_sensor(data, "in", "input", in_index, 0, 950 - PMBUS_READ_VCAP, PSC_VOLTAGE_IN, true, true); 951 - in_index++; 952 - } 953 - 954 - /* 955 - * Output voltage sensors 956 - */ 957 - for (page = 0; page < info->pages; page++) { 958 - bool have_alarm = false; 959 - 960 - if (!(info->func[page] & PMBUS_HAVE_VOUT)) 961 - continue; 962 - 963 - i0 = data->num_sensors; 964 - pmbus_add_label(data, "in", in_index, "vout", page + 1); 965 - pmbus_add_sensor(data, "in", "input", in_index, page, 966 - PMBUS_READ_VOUT, PSC_VOLTAGE_OUT, true, true); 967 - if (pmbus_check_word_register(client, page, 968 - PMBUS_VOUT_UV_WARN_LIMIT)) { 969 - i1 = data->num_sensors; 970 - pmbus_add_sensor(data, "in", "min", in_index, page, 971 - PMBUS_VOUT_UV_WARN_LIMIT, 972 - PSC_VOLTAGE_OUT, false, false); 973 - if (info->func[page] & PMBUS_HAVE_STATUS_VOUT) { 974 - pmbus_add_boolean_reg(data, "in", "min_alarm", 975 - in_index, 976 - PB_STATUS_VOUT_BASE + 977 - page, 978 - PB_VOLTAGE_UV_WARNING); 979 - have_alarm = true; 980 - } 981 - } 982 - if (pmbus_check_word_register(client, page, 983 - PMBUS_VOUT_UV_FAULT_LIMIT)) { 984 - i1 = data->num_sensors; 985 - pmbus_add_sensor(data, "in", "lcrit", in_index, page, 986 - PMBUS_VOUT_UV_FAULT_LIMIT, 987 - PSC_VOLTAGE_OUT, false, false); 988 - if (info->func[page] & PMBUS_HAVE_STATUS_VOUT) { 989 - pmbus_add_boolean_reg(data, "in", "lcrit_alarm", 990 - in_index, 991 - PB_STATUS_VOUT_BASE + 992 - page, 993 - PB_VOLTAGE_UV_FAULT); 994 - have_alarm = true; 995 - } 996 - } 997 - if (pmbus_check_word_register(client, page, 998 - PMBUS_VOUT_OV_WARN_LIMIT)) { 999 - i1 = data->num_sensors; 1000 - pmbus_add_sensor(data, "in", "max", in_index, page, 1001 - PMBUS_VOUT_OV_WARN_LIMIT, 1002 - PSC_VOLTAGE_OUT, false, false); 1003 - if (info->func[page] & PMBUS_HAVE_STATUS_VOUT) { 1004 - pmbus_add_boolean_reg(data, "in", "max_alarm", 1005 - in_index, 1006 - PB_STATUS_VOUT_BASE + 1007 - page, 1008 - PB_VOLTAGE_OV_WARNING); 1009 - have_alarm = true; 1010 - } 1011 - } 1012 - if (pmbus_check_word_register(client, page, 1013 - PMBUS_VOUT_OV_FAULT_LIMIT)) { 1014 - i1 = data->num_sensors; 1015 - pmbus_add_sensor(data, "in", "crit", in_index, page, 1016 - PMBUS_VOUT_OV_FAULT_LIMIT, 1017 - PSC_VOLTAGE_OUT, false, false); 1018 - if (info->func[page] & PMBUS_HAVE_STATUS_VOUT) { 1019 - pmbus_add_boolean_reg(data, "in", "crit_alarm", 1020 - in_index, 1021 - PB_STATUS_VOUT_BASE + 1022 - page, 1023 - PB_VOLTAGE_OV_FAULT); 1024 - have_alarm = true; 1025 - } 1026 - } 1027 - /* 1028 - * Add generic alarm attribute only if there are no individual 1029 - * attributes. 1030 - */ 1031 - if (!have_alarm) 1032 - pmbus_add_boolean_reg(data, "in", "alarm", 1033 - in_index, 1034 - PB_STATUS_BASE + page, 1035 - PB_STATUS_VOUT_OV); 1036 - in_index++; 1037 - } 1038 - 1039 - /* 1040 - * Current sensors 1041 - */ 1042 - 1043 - /* 1044 - * Input current sensors 1045 - */ 1046 - in_index = 1; 1047 - if (info->func[0] & PMBUS_HAVE_IIN) { 1048 - i0 = data->num_sensors; 1049 - pmbus_add_label(data, "curr", in_index, "iin", 0); 1050 - pmbus_add_sensor(data, "curr", "input", in_index, 0, 1051 - PMBUS_READ_IIN, PSC_CURRENT_IN, true, true); 1052 - if (pmbus_check_word_register(client, 0, 1053 - PMBUS_IIN_OC_WARN_LIMIT)) { 1054 - i1 = data->num_sensors; 1055 - pmbus_add_sensor(data, "curr", "max", in_index, 1056 - 0, PMBUS_IIN_OC_WARN_LIMIT, 1057 - PSC_CURRENT_IN, false, false); 1058 - if (info->func[0] & PMBUS_HAVE_STATUS_INPUT) { 1059 - pmbus_add_boolean_reg(data, "curr", "max_alarm", 1060 - in_index, 1061 - PB_STATUS_INPUT_BASE, 1062 - PB_IIN_OC_WARNING); 1063 - } 1064 - } 1065 - if (pmbus_check_word_register(client, 0, 1066 - PMBUS_IIN_OC_FAULT_LIMIT)) { 1067 - i1 = data->num_sensors; 1068 - pmbus_add_sensor(data, "curr", "crit", in_index, 1069 - 0, PMBUS_IIN_OC_FAULT_LIMIT, 1070 - PSC_CURRENT_IN, false, false); 1071 - if (info->func[0] & PMBUS_HAVE_STATUS_INPUT) 1072 - pmbus_add_boolean_reg(data, "curr", 1073 - "crit_alarm", 1074 - in_index, 1075 - PB_STATUS_INPUT_BASE, 1076 - PB_IIN_OC_FAULT); 1077 - } 1078 - in_index++; 1079 - } 1080 - 1081 - /* 1082 - * Output current sensors 1083 - */ 1084 - for (page = 0; page < info->pages; page++) { 1085 - bool have_alarm = false; 1086 - 1087 - if (!(info->func[page] & PMBUS_HAVE_IOUT)) 1088 - continue; 1089 - 1090 - i0 = data->num_sensors; 1091 - pmbus_add_label(data, "curr", in_index, "iout", page + 1); 1092 - pmbus_add_sensor(data, "curr", "input", in_index, page, 1093 - PMBUS_READ_IOUT, PSC_CURRENT_OUT, true, true); 1094 - if (pmbus_check_word_register(client, page, 1095 - PMBUS_IOUT_OC_WARN_LIMIT)) { 1096 - i1 = data->num_sensors; 1097 - pmbus_add_sensor(data, "curr", "max", in_index, page, 1098 - PMBUS_IOUT_OC_WARN_LIMIT, 1099 - PSC_CURRENT_OUT, false, false); 1100 - if (info->func[page] & PMBUS_HAVE_STATUS_IOUT) { 1101 - pmbus_add_boolean_reg(data, "curr", "max_alarm", 1102 - in_index, 1103 - PB_STATUS_IOUT_BASE + 1104 - page, PB_IOUT_OC_WARNING); 1105 - have_alarm = true; 1106 - } 1107 - } 1108 - if (pmbus_check_word_register(client, page, 1109 - PMBUS_IOUT_UC_FAULT_LIMIT)) { 1110 - i1 = data->num_sensors; 1111 - pmbus_add_sensor(data, "curr", "lcrit", in_index, page, 1112 - PMBUS_IOUT_UC_FAULT_LIMIT, 1113 - PSC_CURRENT_OUT, false, false); 1114 - if (info->func[page] & PMBUS_HAVE_STATUS_IOUT) { 1115 - pmbus_add_boolean_reg(data, "curr", 1116 - "lcrit_alarm", 1117 - in_index, 1118 - PB_STATUS_IOUT_BASE + 1119 - page, PB_IOUT_UC_FAULT); 1120 - have_alarm = true; 1121 - } 1122 - } 1123 - if (pmbus_check_word_register(client, page, 1124 - PMBUS_IOUT_OC_FAULT_LIMIT)) { 1125 - i1 = data->num_sensors; 1126 - pmbus_add_sensor(data, "curr", "crit", in_index, page, 1127 - PMBUS_IOUT_OC_FAULT_LIMIT, 1128 - PSC_CURRENT_OUT, false, false); 1129 - if (info->func[page] & PMBUS_HAVE_STATUS_IOUT) { 1130 - pmbus_add_boolean_reg(data, "curr", 1131 - "crit_alarm", 1132 - in_index, 1133 - PB_STATUS_IOUT_BASE + 1134 - page, PB_IOUT_OC_FAULT); 1135 - have_alarm = true; 1136 - } 1137 - } 1138 - /* 1139 - * Add generic alarm attribute only if there are no individual 1140 - * attributes. 1141 - */ 1142 - if (!have_alarm) 1143 - pmbus_add_boolean_reg(data, "curr", "alarm", 1144 - in_index, 1145 - PB_STATUS_BASE + page, 1146 - PB_STATUS_IOUT_OC); 1147 - in_index++; 1148 - } 1149 - 1150 - /* 1151 - * Power sensors 1152 - */ 1153 - /* 1154 - * Input Power sensors 1155 - */ 1156 - in_index = 1; 1157 - if (info->func[0] & PMBUS_HAVE_PIN) { 1158 - i0 = data->num_sensors; 1159 - pmbus_add_label(data, "power", in_index, "pin", 0); 1160 - pmbus_add_sensor(data, "power", "input", in_index, 1161 - 0, PMBUS_READ_PIN, PSC_POWER, true, true); 1162 - if (pmbus_check_word_register(client, 0, 1163 - PMBUS_PIN_OP_WARN_LIMIT)) { 1164 - i1 = data->num_sensors; 1165 - pmbus_add_sensor(data, "power", "max", in_index, 1166 - 0, PMBUS_PIN_OP_WARN_LIMIT, PSC_POWER, 1167 - false, false); 1168 - if (info->func[0] & PMBUS_HAVE_STATUS_INPUT) 1169 - pmbus_add_boolean_reg(data, "power", 1170 - "alarm", 1171 - in_index, 1172 - PB_STATUS_INPUT_BASE, 1173 - PB_PIN_OP_WARNING); 1174 - } 1175 - in_index++; 1176 - } 1177 - 1178 - /* 1179 - * Output Power sensors 1180 - */ 1181 - for (page = 0; page < info->pages; page++) { 1182 - bool need_alarm = false; 1183 - 1184 - if (!(info->func[page] & PMBUS_HAVE_POUT)) 1185 - continue; 1186 - 1187 - i0 = data->num_sensors; 1188 - pmbus_add_label(data, "power", in_index, "pout", page + 1); 1189 - pmbus_add_sensor(data, "power", "input", in_index, page, 1190 - PMBUS_READ_POUT, PSC_POWER, true, true); 1191 - /* 1192 - * Per hwmon sysfs API, power_cap is to be used to limit output 1193 - * power. 1194 - * We have two registers related to maximum output power, 1195 - * PMBUS_POUT_MAX and PMBUS_POUT_OP_WARN_LIMIT. 1196 - * PMBUS_POUT_MAX matches the powerX_cap attribute definition. 1197 - * There is no attribute in the API to match 1198 - * PMBUS_POUT_OP_WARN_LIMIT. We use powerX_max for now. 1199 - */ 1200 - if (pmbus_check_word_register(client, page, PMBUS_POUT_MAX)) { 1201 - i1 = data->num_sensors; 1202 - pmbus_add_sensor(data, "power", "cap", in_index, page, 1203 - PMBUS_POUT_MAX, PSC_POWER, 1204 - false, false); 1205 - need_alarm = true; 1206 - } 1207 - if (pmbus_check_word_register(client, page, 1208 - PMBUS_POUT_OP_WARN_LIMIT)) { 1209 - i1 = data->num_sensors; 1210 - pmbus_add_sensor(data, "power", "max", in_index, page, 1211 - PMBUS_POUT_OP_WARN_LIMIT, PSC_POWER, 1212 - false, false); 1213 - need_alarm = true; 1214 - } 1215 - if (need_alarm && (info->func[page] & PMBUS_HAVE_STATUS_IOUT)) 1216 - pmbus_add_boolean_reg(data, "power", "alarm", 1217 - in_index, 1218 - PB_STATUS_IOUT_BASE + page, 1219 - PB_POUT_OP_WARNING 1220 - | PB_POWER_LIMITING); 1221 - 1222 - if (pmbus_check_word_register(client, page, 1223 - PMBUS_POUT_OP_FAULT_LIMIT)) { 1224 - i1 = data->num_sensors; 1225 - pmbus_add_sensor(data, "power", "crit", in_index, page, 1226 - PMBUS_POUT_OP_FAULT_LIMIT, PSC_POWER, 1227 - false, false); 1228 - if (info->func[page] & PMBUS_HAVE_STATUS_IOUT) 1229 - pmbus_add_boolean_reg(data, "power", 1230 - "crit_alarm", 1231 - in_index, 1232 - PB_STATUS_IOUT_BASE 1233 - + page, 1234 - PB_POUT_OP_FAULT); 1235 - } 1236 - in_index++; 1237 - } 1238 - 1239 - /* 1240 - * Temperature sensors 1241 - */ 1242 - in_index = 1; 1243 - for (page = 0; page < info->pages; page++) { 1244 - int t; 1245 - 1246 - for (t = 0; t < ARRAY_SIZE(pmbus_temp_registers); t++) { 1247 - bool have_alarm = false; 1248 - 1249 - /* 1250 - * A PMBus chip may support any combination of 1251 - * temperature registers on any page. So we can not 1252 - * abort after a failure to detect a register, but have 1253 - * to continue checking for all registers on all pages. 1254 - */ 1255 - if (!(info->func[page] & pmbus_temp_flags[t])) 1017 + pages = attrs->paged ? info->pages : 1; 1018 + for (page = 0; page < pages; page++) { 1019 + if (!(info->func[page] & attrs->func)) 1256 1020 continue; 1257 - 1258 - if (!pmbus_check_word_register 1259 - (client, page, pmbus_temp_registers[t])) 1260 - continue; 1261 - 1262 - i0 = data->num_sensors; 1263 - pmbus_add_sensor(data, "temp", "input", in_index, page, 1264 - pmbus_temp_registers[t], 1265 - PSC_TEMPERATURE, true, true); 1266 - 1267 - /* 1268 - * PMBus provides only one status register for TEMP1-3. 1269 - * Thus, we can not use the status register to determine 1270 - * which of the three sensors actually caused an alarm. 1271 - * Always compare current temperature against the limit 1272 - * registers to determine alarm conditions for a 1273 - * specific sensor. 1274 - * 1275 - * Since there is only one set of limit registers for 1276 - * up to three temperature sensors, we need to update 1277 - * all limit registers after the limit was changed for 1278 - * one of the sensors. This ensures that correct limits 1279 - * are reported for all temperature sensors. 1280 - */ 1281 - if (pmbus_check_word_register 1282 - (client, page, PMBUS_UT_WARN_LIMIT)) { 1283 - i1 = data->num_sensors; 1284 - pmbus_add_sensor(data, "temp", "min", in_index, 1285 - page, PMBUS_UT_WARN_LIMIT, 1286 - PSC_TEMPERATURE, true, false); 1287 - if (info->func[page] & PMBUS_HAVE_STATUS_TEMP) { 1288 - pmbus_add_boolean_cmp(data, "temp", 1289 - "min_alarm", in_index, i1, i0, 1290 - PB_STATUS_TEMP_BASE + page, 1291 - PB_TEMP_UT_WARNING); 1292 - have_alarm = true; 1293 - } 1294 - } 1295 - if (pmbus_check_word_register(client, page, 1296 - PMBUS_UT_FAULT_LIMIT)) { 1297 - i1 = data->num_sensors; 1298 - pmbus_add_sensor(data, "temp", "lcrit", 1299 - in_index, page, 1300 - PMBUS_UT_FAULT_LIMIT, 1301 - PSC_TEMPERATURE, true, false); 1302 - if (info->func[page] & PMBUS_HAVE_STATUS_TEMP) { 1303 - pmbus_add_boolean_cmp(data, "temp", 1304 - "lcrit_alarm", in_index, i1, i0, 1305 - PB_STATUS_TEMP_BASE + page, 1306 - PB_TEMP_UT_FAULT); 1307 - have_alarm = true; 1308 - } 1309 - } 1310 - if (pmbus_check_word_register 1311 - (client, page, PMBUS_OT_WARN_LIMIT)) { 1312 - i1 = data->num_sensors; 1313 - pmbus_add_sensor(data, "temp", "max", in_index, 1314 - page, PMBUS_OT_WARN_LIMIT, 1315 - PSC_TEMPERATURE, true, false); 1316 - if (info->func[page] & PMBUS_HAVE_STATUS_TEMP) { 1317 - pmbus_add_boolean_cmp(data, "temp", 1318 - "max_alarm", in_index, i0, i1, 1319 - PB_STATUS_TEMP_BASE + page, 1320 - PB_TEMP_OT_WARNING); 1321 - have_alarm = true; 1322 - } 1323 - } 1324 - if (pmbus_check_word_register(client, page, 1325 - PMBUS_OT_FAULT_LIMIT)) { 1326 - i1 = data->num_sensors; 1327 - pmbus_add_sensor(data, "temp", "crit", in_index, 1328 - page, PMBUS_OT_FAULT_LIMIT, 1329 - PSC_TEMPERATURE, true, false); 1330 - if (info->func[page] & PMBUS_HAVE_STATUS_TEMP) { 1331 - pmbus_add_boolean_cmp(data, "temp", 1332 - "crit_alarm", in_index, i0, i1, 1333 - PB_STATUS_TEMP_BASE + page, 1334 - PB_TEMP_OT_FAULT); 1335 - have_alarm = true; 1336 - } 1337 - } 1338 - /* 1339 - * Last resort - we were not able to create any alarm 1340 - * registers. Report alarm for all sensors using the 1341 - * status register temperature alarm bit. 1342 - */ 1343 - if (!have_alarm) 1344 - pmbus_add_boolean_reg(data, "temp", "alarm", 1345 - in_index, 1346 - PB_STATUS_BASE + page, 1347 - PB_STATUS_TEMPERATURE); 1348 - in_index++; 1021 + pmbus_add_sensor_attrs_one(client, data, info, name, 1022 + index, page, attrs); 1023 + index++; 1349 1024 } 1025 + attrs++; 1350 1026 } 1027 + } 1351 1028 1352 - /* 1353 - * Fans 1354 - */ 1355 - in_index = 1; 1029 + static const struct pmbus_limit_attr vin_limit_attrs[] = { 1030 + { 1031 + .reg = PMBUS_VIN_UV_WARN_LIMIT, 1032 + .attr = "min", 1033 + .alarm = "min_alarm", 1034 + .sbit = PB_VOLTAGE_UV_WARNING, 1035 + }, { 1036 + .reg = PMBUS_VIN_UV_FAULT_LIMIT, 1037 + .attr = "lcrit", 1038 + .alarm = "lcrit_alarm", 1039 + .sbit = PB_VOLTAGE_UV_FAULT, 1040 + }, { 1041 + .reg = PMBUS_VIN_OV_WARN_LIMIT, 1042 + .attr = "max", 1043 + .alarm = "max_alarm", 1044 + .sbit = PB_VOLTAGE_OV_WARNING, 1045 + }, { 1046 + .reg = PMBUS_VIN_OV_FAULT_LIMIT, 1047 + .attr = "crit", 1048 + .alarm = "crit_alarm", 1049 + .sbit = PB_VOLTAGE_OV_FAULT, 1050 + }, 1051 + }; 1052 + 1053 + static const struct pmbus_limit_attr vout_limit_attrs[] = { 1054 + { 1055 + .reg = PMBUS_VOUT_UV_WARN_LIMIT, 1056 + .attr = "min", 1057 + .alarm = "min_alarm", 1058 + .sbit = PB_VOLTAGE_UV_WARNING, 1059 + }, { 1060 + .reg = PMBUS_VOUT_UV_FAULT_LIMIT, 1061 + .attr = "lcrit", 1062 + .alarm = "lcrit_alarm", 1063 + .sbit = PB_VOLTAGE_UV_FAULT, 1064 + }, { 1065 + .reg = PMBUS_VOUT_OV_WARN_LIMIT, 1066 + .attr = "max", 1067 + .alarm = "max_alarm", 1068 + .sbit = PB_VOLTAGE_OV_WARNING, 1069 + }, { 1070 + .reg = PMBUS_VOUT_OV_FAULT_LIMIT, 1071 + .attr = "crit", 1072 + .alarm = "crit_alarm", 1073 + .sbit = PB_VOLTAGE_OV_FAULT, 1074 + } 1075 + }; 1076 + 1077 + static const struct pmbus_sensor_attr voltage_attributes[] = { 1078 + { 1079 + .reg = PMBUS_READ_VIN, 1080 + .class = PSC_VOLTAGE_IN, 1081 + .label = "vin", 1082 + .func = PMBUS_HAVE_VIN, 1083 + .sfunc = PMBUS_HAVE_STATUS_INPUT, 1084 + .sbase = PB_STATUS_INPUT_BASE, 1085 + .gbit = PB_STATUS_VIN_UV, 1086 + .limit = vin_limit_attrs, 1087 + .nlimit = ARRAY_SIZE(vin_limit_attrs), 1088 + }, { 1089 + .reg = PMBUS_READ_VCAP, 1090 + .class = PSC_VOLTAGE_IN, 1091 + .label = "vcap", 1092 + .func = PMBUS_HAVE_VCAP, 1093 + }, { 1094 + .reg = PMBUS_READ_VOUT, 1095 + .class = PSC_VOLTAGE_OUT, 1096 + .label = "vout", 1097 + .paged = true, 1098 + .func = PMBUS_HAVE_VOUT, 1099 + .sfunc = PMBUS_HAVE_STATUS_VOUT, 1100 + .sbase = PB_STATUS_VOUT_BASE, 1101 + .gbit = PB_STATUS_VOUT_OV, 1102 + .limit = vout_limit_attrs, 1103 + .nlimit = ARRAY_SIZE(vout_limit_attrs), 1104 + } 1105 + }; 1106 + 1107 + /* Current attributes */ 1108 + 1109 + static const struct pmbus_limit_attr iin_limit_attrs[] = { 1110 + { 1111 + .reg = PMBUS_IIN_OC_WARN_LIMIT, 1112 + .attr = "max", 1113 + .alarm = "max_alarm", 1114 + .sbit = PB_IIN_OC_WARNING, 1115 + }, { 1116 + .reg = PMBUS_IIN_OC_FAULT_LIMIT, 1117 + .attr = "crit", 1118 + .alarm = "crit_alarm", 1119 + .sbit = PB_IIN_OC_FAULT, 1120 + } 1121 + }; 1122 + 1123 + static const struct pmbus_limit_attr iout_limit_attrs[] = { 1124 + { 1125 + .reg = PMBUS_IOUT_OC_WARN_LIMIT, 1126 + .attr = "max", 1127 + .alarm = "max_alarm", 1128 + .sbit = PB_IOUT_OC_WARNING, 1129 + }, { 1130 + .reg = PMBUS_IOUT_UC_FAULT_LIMIT, 1131 + .attr = "lcrit", 1132 + .alarm = "lcrit_alarm", 1133 + .sbit = PB_IOUT_UC_FAULT, 1134 + }, { 1135 + .reg = PMBUS_IOUT_OC_FAULT_LIMIT, 1136 + .attr = "crit", 1137 + .alarm = "crit_alarm", 1138 + .sbit = PB_IOUT_OC_FAULT, 1139 + } 1140 + }; 1141 + 1142 + static const struct pmbus_sensor_attr current_attributes[] = { 1143 + { 1144 + .reg = PMBUS_READ_IIN, 1145 + .class = PSC_CURRENT_IN, 1146 + .label = "iin", 1147 + .func = PMBUS_HAVE_IIN, 1148 + .sfunc = PMBUS_HAVE_STATUS_INPUT, 1149 + .sbase = PB_STATUS_INPUT_BASE, 1150 + .limit = iin_limit_attrs, 1151 + .nlimit = ARRAY_SIZE(iin_limit_attrs), 1152 + }, { 1153 + .reg = PMBUS_READ_IOUT, 1154 + .class = PSC_CURRENT_OUT, 1155 + .label = "iout", 1156 + .paged = true, 1157 + .func = PMBUS_HAVE_IOUT, 1158 + .sfunc = PMBUS_HAVE_STATUS_IOUT, 1159 + .sbase = PB_STATUS_IOUT_BASE, 1160 + .gbit = PB_STATUS_IOUT_OC, 1161 + .limit = iout_limit_attrs, 1162 + .nlimit = ARRAY_SIZE(iout_limit_attrs), 1163 + } 1164 + }; 1165 + 1166 + /* Power attributes */ 1167 + 1168 + static const struct pmbus_limit_attr pin_limit_attrs[] = { 1169 + { 1170 + .reg = PMBUS_PIN_OP_WARN_LIMIT, 1171 + .attr = "max", 1172 + .alarm = "alarm", 1173 + .sbit = PB_PIN_OP_WARNING, 1174 + } 1175 + }; 1176 + 1177 + static const struct pmbus_limit_attr pout_limit_attrs[] = { 1178 + { 1179 + .reg = PMBUS_POUT_MAX, 1180 + .attr = "cap", 1181 + .alarm = "cap_alarm", 1182 + .sbit = PB_POWER_LIMITING, 1183 + }, { 1184 + .reg = PMBUS_POUT_OP_WARN_LIMIT, 1185 + .attr = "max", 1186 + .alarm = "max_alarm", 1187 + .sbit = PB_POUT_OP_WARNING, 1188 + }, { 1189 + .reg = PMBUS_POUT_OP_FAULT_LIMIT, 1190 + .attr = "crit", 1191 + .alarm = "crit_alarm", 1192 + .sbit = PB_POUT_OP_FAULT, 1193 + } 1194 + }; 1195 + 1196 + static const struct pmbus_sensor_attr power_attributes[] = { 1197 + { 1198 + .reg = PMBUS_READ_PIN, 1199 + .class = PSC_POWER, 1200 + .label = "pin", 1201 + .func = PMBUS_HAVE_PIN, 1202 + .sfunc = PMBUS_HAVE_STATUS_INPUT, 1203 + .sbase = PB_STATUS_INPUT_BASE, 1204 + .limit = pin_limit_attrs, 1205 + .nlimit = ARRAY_SIZE(pin_limit_attrs), 1206 + }, { 1207 + .reg = PMBUS_READ_POUT, 1208 + .class = PSC_POWER, 1209 + .label = "pout", 1210 + .paged = true, 1211 + .func = PMBUS_HAVE_POUT, 1212 + .sfunc = PMBUS_HAVE_STATUS_IOUT, 1213 + .sbase = PB_STATUS_IOUT_BASE, 1214 + .limit = pout_limit_attrs, 1215 + .nlimit = ARRAY_SIZE(pout_limit_attrs), 1216 + } 1217 + }; 1218 + 1219 + /* Temperature atributes */ 1220 + 1221 + static const struct pmbus_limit_attr temp_limit_attrs[] = { 1222 + { 1223 + .reg = PMBUS_UT_WARN_LIMIT, 1224 + .attr = "min", 1225 + .alarm = "min_alarm", 1226 + .sbit = PB_TEMP_UT_WARNING, 1227 + }, { 1228 + .reg = PMBUS_UT_FAULT_LIMIT, 1229 + .attr = "lcrit", 1230 + .alarm = "lcrit_alarm", 1231 + .sbit = PB_TEMP_UT_FAULT, 1232 + }, { 1233 + .reg = PMBUS_OT_WARN_LIMIT, 1234 + .attr = "max", 1235 + .alarm = "max_alarm", 1236 + .sbit = PB_TEMP_OT_WARNING, 1237 + }, { 1238 + .reg = PMBUS_OT_FAULT_LIMIT, 1239 + .attr = "crit", 1240 + .alarm = "crit_alarm", 1241 + .sbit = PB_TEMP_OT_FAULT, 1242 + } 1243 + }; 1244 + 1245 + static const struct pmbus_sensor_attr temp_attributes[] = { 1246 + { 1247 + .reg = PMBUS_READ_TEMPERATURE_1, 1248 + .class = PSC_TEMPERATURE, 1249 + .paged = true, 1250 + .update = true, 1251 + .compare = true, 1252 + .func = PMBUS_HAVE_TEMP, 1253 + .sfunc = PMBUS_HAVE_STATUS_TEMP, 1254 + .sbase = PB_STATUS_TEMP_BASE, 1255 + .gbit = PB_STATUS_TEMPERATURE, 1256 + .limit = temp_limit_attrs, 1257 + .nlimit = ARRAY_SIZE(temp_limit_attrs), 1258 + }, { 1259 + .reg = PMBUS_READ_TEMPERATURE_2, 1260 + .class = PSC_TEMPERATURE, 1261 + .paged = true, 1262 + .update = true, 1263 + .compare = true, 1264 + .func = PMBUS_HAVE_TEMP2, 1265 + .sfunc = PMBUS_HAVE_STATUS_TEMP, 1266 + .sbase = PB_STATUS_TEMP_BASE, 1267 + .gbit = PB_STATUS_TEMPERATURE, 1268 + .limit = temp_limit_attrs, 1269 + .nlimit = ARRAY_SIZE(temp_limit_attrs), 1270 + }, { 1271 + .reg = PMBUS_READ_TEMPERATURE_3, 1272 + .class = PSC_TEMPERATURE, 1273 + .paged = true, 1274 + .update = true, 1275 + .compare = true, 1276 + .func = PMBUS_HAVE_TEMP3, 1277 + .sfunc = PMBUS_HAVE_STATUS_TEMP, 1278 + .sbase = PB_STATUS_TEMP_BASE, 1279 + .gbit = PB_STATUS_TEMPERATURE, 1280 + .limit = temp_limit_attrs, 1281 + .nlimit = ARRAY_SIZE(temp_limit_attrs), 1282 + } 1283 + }; 1284 + 1285 + static const int pmbus_fan_registers[] = { 1286 + PMBUS_READ_FAN_SPEED_1, 1287 + PMBUS_READ_FAN_SPEED_2, 1288 + PMBUS_READ_FAN_SPEED_3, 1289 + PMBUS_READ_FAN_SPEED_4 1290 + }; 1291 + 1292 + static const int pmbus_fan_config_registers[] = { 1293 + PMBUS_FAN_CONFIG_12, 1294 + PMBUS_FAN_CONFIG_12, 1295 + PMBUS_FAN_CONFIG_34, 1296 + PMBUS_FAN_CONFIG_34 1297 + }; 1298 + 1299 + static const int pmbus_fan_status_registers[] = { 1300 + PMBUS_STATUS_FAN_12, 1301 + PMBUS_STATUS_FAN_12, 1302 + PMBUS_STATUS_FAN_34, 1303 + PMBUS_STATUS_FAN_34 1304 + }; 1305 + 1306 + static const u32 pmbus_fan_flags[] = { 1307 + PMBUS_HAVE_FAN12, 1308 + PMBUS_HAVE_FAN12, 1309 + PMBUS_HAVE_FAN34, 1310 + PMBUS_HAVE_FAN34 1311 + }; 1312 + 1313 + static const u32 pmbus_fan_status_flags[] = { 1314 + PMBUS_HAVE_STATUS_FAN12, 1315 + PMBUS_HAVE_STATUS_FAN12, 1316 + PMBUS_HAVE_STATUS_FAN34, 1317 + PMBUS_HAVE_STATUS_FAN34 1318 + }; 1319 + 1320 + /* Fans */ 1321 + static void pmbus_add_fan_attributes(struct i2c_client *client, 1322 + struct pmbus_data *data) 1323 + { 1324 + const struct pmbus_driver_info *info = data->info; 1325 + int index = 1; 1326 + int page; 1327 + 1356 1328 for (page = 0; page < info->pages; page++) { 1357 1329 int f; 1358 1330 ··· 1295 1403 break; 1296 1404 1297 1405 if (!pmbus_check_word_register(client, page, 1298 - pmbus_fan_registers[f]) 1299 - || !pmbus_check_byte_register(client, page, 1300 - pmbus_fan_config_registers[f])) 1406 + pmbus_fan_registers[f])) 1301 1407 break; 1302 1408 1303 1409 /* ··· 1303 1413 * Each fan configuration register covers multiple fans, 1304 1414 * so we have to do some magic. 1305 1415 */ 1306 - regval = pmbus_read_byte_data(client, page, 1416 + regval = _pmbus_read_byte_data(client, page, 1307 1417 pmbus_fan_config_registers[f]); 1308 1418 if (regval < 0 || 1309 1419 (!(regval & (PB_FAN_1_INSTALLED >> ((f & 1) * 4))))) 1310 1420 continue; 1311 1421 1312 - i0 = data->num_sensors; 1313 - pmbus_add_sensor(data, "fan", "input", in_index, page, 1422 + pmbus_add_sensor(data, "fan", "input", index, page, 1314 1423 pmbus_fan_registers[f], PSC_FAN, true, 1315 1424 true); 1316 1425 ··· 1327 1438 else 1328 1439 base = PB_STATUS_FAN_BASE + page; 1329 1440 pmbus_add_boolean_reg(data, "fan", "alarm", 1330 - in_index, base, 1441 + index, base, 1331 1442 PB_FAN_FAN1_WARNING >> (f & 1)); 1332 1443 pmbus_add_boolean_reg(data, "fan", "fault", 1333 - in_index, base, 1444 + index, base, 1334 1445 PB_FAN_FAN1_FAULT >> (f & 1)); 1335 1446 } 1336 - in_index++; 1447 + index++; 1337 1448 } 1338 1449 } 1450 + } 1451 + 1452 + static void pmbus_find_attributes(struct i2c_client *client, 1453 + struct pmbus_data *data) 1454 + { 1455 + /* Voltage sensors */ 1456 + pmbus_add_sensor_attrs(client, data, "in", voltage_attributes, 1457 + ARRAY_SIZE(voltage_attributes)); 1458 + 1459 + /* Current sensors */ 1460 + pmbus_add_sensor_attrs(client, data, "curr", current_attributes, 1461 + ARRAY_SIZE(current_attributes)); 1462 + 1463 + /* Power sensors */ 1464 + pmbus_add_sensor_attrs(client, data, "power", power_attributes, 1465 + ARRAY_SIZE(power_attributes)); 1466 + 1467 + /* Temperature sensors */ 1468 + pmbus_add_sensor_attrs(client, data, "temp", temp_attributes, 1469 + ARRAY_SIZE(temp_attributes)); 1470 + 1471 + /* Fans */ 1472 + pmbus_add_fan_attributes(client, data); 1339 1473 } 1340 1474 1341 1475 /*
+576 -165
drivers/hwmon/sht15.c
··· 1 1 /* 2 2 * sht15.c - support for the SHT15 Temperature and Humidity Sensor 3 3 * 4 + * Portions Copyright (c) 2010-2011 Savoir-faire Linux Inc. 5 + * Jerome Oufella <jerome.oufella@savoirfairelinux.com> 6 + * Vivien Didelot <vivien.didelot@savoirfairelinux.com> 7 + * 4 8 * Copyright (c) 2009 Jonathan Cameron 5 9 * 6 10 * Copyright (c) 2007 Wouter Horre ··· 13 9 * it under the terms of the GNU General Public License version 2 as 14 10 * published by the Free Software Foundation. 15 11 * 16 - * Currently ignoring checksum on readings. 17 - * Default resolution only (14bit temp, 12bit humidity) 18 - * Ignoring battery status. 19 - * Heater not enabled. 20 - * Timings are all conservative. 21 - * 22 - * Data sheet available (1/2009) at 23 - * http://www.sensirion.ch/en/pdf/product_information/Datasheet-humidity-sensor-SHT1x.pdf 24 - * 25 - * Regulator supply name = vcc 12 + * For further information, see the Documentation/hwmon/sht15 file. 26 13 */ 27 14 28 15 #include <linux/interrupt.h> ··· 34 39 #include <linux/slab.h> 35 40 #include <asm/atomic.h> 36 41 37 - #define SHT15_MEASURE_TEMP 3 38 - #define SHT15_MEASURE_RH 5 42 + /* Commands */ 43 + #define SHT15_MEASURE_TEMP 0x03 44 + #define SHT15_MEASURE_RH 0x05 45 + #define SHT15_WRITE_STATUS 0x06 46 + #define SHT15_READ_STATUS 0x07 47 + #define SHT15_SOFT_RESET 0x1E 39 48 40 - #define SHT15_READING_NOTHING 0 41 - #define SHT15_READING_TEMP 1 42 - #define SHT15_READING_HUMID 2 49 + /* Min timings */ 50 + #define SHT15_TSCKL 100 /* (nsecs) clock low */ 51 + #define SHT15_TSCKH 100 /* (nsecs) clock high */ 52 + #define SHT15_TSU 150 /* (nsecs) data setup time */ 53 + #define SHT15_TSRST 11 /* (msecs) soft reset time */ 43 54 44 - /* Min timings in nsecs */ 45 - #define SHT15_TSCKL 100 /* clock low */ 46 - #define SHT15_TSCKH 100 /* clock high */ 47 - #define SHT15_TSU 150 /* data setup time */ 55 + /* Status Register Bits */ 56 + #define SHT15_STATUS_LOW_RESOLUTION 0x01 57 + #define SHT15_STATUS_NO_OTP_RELOAD 0x02 58 + #define SHT15_STATUS_HEATER 0x04 59 + #define SHT15_STATUS_LOW_BATTERY 0x40 60 + 61 + /* Actions the driver may be doing */ 62 + enum sht15_state { 63 + SHT15_READING_NOTHING, 64 + SHT15_READING_TEMP, 65 + SHT15_READING_HUMID 66 + }; 48 67 49 68 /** 50 69 * struct sht15_temppair - elements of voltage dependent temp calc ··· 70 61 int d1; 71 62 }; 72 63 73 - /* Table 9 from data sheet - relates temperature calculation 74 - * to supply voltage. 75 - */ 64 + /* Table 9 from datasheet - relates temperature calculation to supply voltage */ 76 65 static const struct sht15_temppair temppoints[] = { 77 66 { 2500000, -39400 }, 78 67 { 3000000, -39600 }, ··· 79 72 { 5000000, -40100 }, 80 73 }; 81 74 75 + /* Table from CRC datasheet, section 2.4 */ 76 + static const u8 sht15_crc8_table[] = { 77 + 0, 49, 98, 83, 196, 245, 166, 151, 78 + 185, 136, 219, 234, 125, 76, 31, 46, 79 + 67, 114, 33, 16, 135, 182, 229, 212, 80 + 250, 203, 152, 169, 62, 15, 92, 109, 81 + 134, 183, 228, 213, 66, 115, 32, 17, 82 + 63, 14, 93, 108, 251, 202, 153, 168, 83 + 197, 244, 167, 150, 1, 48, 99, 82, 84 + 124, 77, 30, 47, 184, 137, 218, 235, 85 + 61, 12, 95, 110, 249, 200, 155, 170, 86 + 132, 181, 230, 215, 64, 113, 34, 19, 87 + 126, 79, 28, 45, 186, 139, 216, 233, 88 + 199, 246, 165, 148, 3, 50, 97, 80, 89 + 187, 138, 217, 232, 127, 78, 29, 44, 90 + 2, 51, 96, 81, 198, 247, 164, 149, 91 + 248, 201, 154, 171, 60, 13, 94, 111, 92 + 65, 112, 35, 18, 133, 180, 231, 214, 93 + 122, 75, 24, 41, 190, 143, 220, 237, 94 + 195, 242, 161, 144, 7, 54, 101, 84, 95 + 57, 8, 91, 106, 253, 204, 159, 174, 96 + 128, 177, 226, 211, 68, 117, 38, 23, 97 + 252, 205, 158, 175, 56, 9, 90, 107, 98 + 69, 116, 39, 22, 129, 176, 227, 210, 99 + 191, 142, 221, 236, 123, 74, 25, 40, 100 + 6, 55, 100, 85, 194, 243, 160, 145, 101 + 71, 118, 37, 20, 131, 178, 225, 208, 102 + 254, 207, 156, 173, 58, 11, 88, 105, 103 + 4, 53, 102, 87, 192, 241, 162, 147, 104 + 189, 140, 223, 238, 121, 72, 27, 42, 105 + 193, 240, 163, 146, 5, 52, 103, 86, 106 + 120, 73, 26, 43, 188, 141, 222, 239, 107 + 130, 179, 224, 209, 70, 119, 36, 21, 108 + 59, 10, 89, 104, 255, 206, 157, 172 109 + }; 110 + 82 111 /** 83 112 * struct sht15_data - device instance specific data 84 - * @pdata: platform data (gpio's etc) 85 - * @read_work: bh of interrupt handler 86 - * @wait_queue: wait queue for getting values from device 87 - * @val_temp: last temperature value read from device 88 - * @val_humid: last humidity value read from device 89 - * @flag: status flag used to identify what the last request was 90 - * @valid: are the current stored values valid (start condition) 91 - * @last_updat: time of last update 92 - * @read_lock: mutex to ensure only one read in progress 93 - * at a time. 94 - * @dev: associate device structure 95 - * @hwmon_dev: device associated with hwmon subsystem 96 - * @reg: associated regulator (if specified) 97 - * @nb: notifier block to handle notifications of voltage changes 98 - * @supply_uV: local copy of supply voltage used to allow 99 - * use of regulator consumer if available 100 - * @supply_uV_valid: indicates that an updated value has not yet 101 - * been obtained from the regulator and so any calculations 102 - * based upon it will be invalid. 103 - * @update_supply_work: work struct that is used to update the supply_uV 104 - * @interrupt_handled: flag used to indicate a hander has been scheduled 113 + * @pdata: platform data (gpio's etc). 114 + * @read_work: bh of interrupt handler. 115 + * @wait_queue: wait queue for getting values from device. 116 + * @val_temp: last temperature value read from device. 117 + * @val_humid: last humidity value read from device. 118 + * @val_status: last status register value read from device. 119 + * @checksum_ok: last value read from the device passed CRC validation. 120 + * @checksumming: flag used to enable the data validation with CRC. 121 + * @state: state identifying the action the driver is doing. 122 + * @measurements_valid: are the current stored measures valid (start condition). 123 + * @status_valid: is the current stored status valid (start condition). 124 + * @last_measurement: time of last measure. 125 + * @last_status: time of last status reading. 126 + * @read_lock: mutex to ensure only one read in progress at a time. 127 + * @dev: associate device structure. 128 + * @hwmon_dev: device associated with hwmon subsystem. 129 + * @reg: associated regulator (if specified). 130 + * @nb: notifier block to handle notifications of voltage 131 + * changes. 132 + * @supply_uV: local copy of supply voltage used to allow use of 133 + * regulator consumer if available. 134 + * @supply_uV_valid: indicates that an updated value has not yet been 135 + * obtained from the regulator and so any calculations 136 + * based upon it will be invalid. 137 + * @update_supply_work: work struct that is used to update the supply_uV. 138 + * @interrupt_handled: flag used to indicate a handler has been scheduled. 105 139 */ 106 140 struct sht15_data { 107 141 struct sht15_platform_data *pdata; ··· 150 102 wait_queue_head_t wait_queue; 151 103 uint16_t val_temp; 152 104 uint16_t val_humid; 153 - u8 flag; 154 - u8 valid; 155 - unsigned long last_updat; 105 + u8 val_status; 106 + bool checksum_ok; 107 + bool checksumming; 108 + enum sht15_state state; 109 + bool measurements_valid; 110 + bool status_valid; 111 + unsigned long last_measurement; 112 + unsigned long last_status; 156 113 struct mutex read_lock; 157 114 struct device *dev; 158 115 struct device *hwmon_dev; 159 116 struct regulator *reg; 160 117 struct notifier_block nb; 161 118 int supply_uV; 162 - int supply_uV_valid; 119 + bool supply_uV_valid; 163 120 struct work_struct update_supply_work; 164 121 atomic_t interrupt_handled; 165 122 }; 123 + 124 + /** 125 + * sht15_reverse() - reverse a byte 126 + * @byte: byte to reverse. 127 + */ 128 + static u8 sht15_reverse(u8 byte) 129 + { 130 + u8 i, c; 131 + 132 + for (c = 0, i = 0; i < 8; i++) 133 + c |= (!!(byte & (1 << i))) << (7 - i); 134 + return c; 135 + } 136 + 137 + /** 138 + * sht15_crc8() - compute crc8 139 + * @data: sht15 specific data. 140 + * @value: sht15 retrieved data. 141 + * 142 + * This implements section 2 of the CRC datasheet. 143 + */ 144 + static u8 sht15_crc8(struct sht15_data *data, 145 + const u8 *value, 146 + int len) 147 + { 148 + u8 crc = sht15_reverse(data->val_status & 0x0F); 149 + 150 + while (len--) { 151 + crc = sht15_crc8_table[*value ^ crc]; 152 + value++; 153 + } 154 + 155 + return crc; 156 + } 166 157 167 158 /** 168 159 * sht15_connection_reset() - reset the comms interface ··· 212 125 static void sht15_connection_reset(struct sht15_data *data) 213 126 { 214 127 int i; 128 + 215 129 gpio_direction_output(data->pdata->gpio_data, 1); 216 130 ndelay(SHT15_TSCKL); 217 131 gpio_set_value(data->pdata->gpio_sck, 0); ··· 224 136 ndelay(SHT15_TSCKL); 225 137 } 226 138 } 139 + 227 140 /** 228 141 * sht15_send_bit() - send an individual bit to the device 229 142 * @data: device state data 230 143 * @val: value of bit to be sent 231 - **/ 144 + */ 232 145 static inline void sht15_send_bit(struct sht15_data *data, int val) 233 146 { 234 - 235 147 gpio_set_value(data->pdata->gpio_data, val); 236 148 ndelay(SHT15_TSU); 237 149 gpio_set_value(data->pdata->gpio_sck, 1); ··· 242 154 243 155 /** 244 156 * sht15_transmission_start() - specific sequence for new transmission 245 - * 246 157 * @data: device state data 158 + * 247 159 * Timings for this are not documented on the data sheet, so very 248 160 * conservative ones used in implementation. This implements 249 161 * figure 12 on the data sheet. 250 - **/ 162 + */ 251 163 static void sht15_transmission_start(struct sht15_data *data) 252 164 { 253 165 /* ensure data is high and output */ ··· 268 180 gpio_set_value(data->pdata->gpio_sck, 0); 269 181 ndelay(SHT15_TSCKL); 270 182 } 183 + 271 184 /** 272 185 * sht15_send_byte() - send a single byte to the device 273 186 * @data: device state 274 187 * @byte: value to be sent 275 - **/ 188 + */ 276 189 static void sht15_send_byte(struct sht15_data *data, u8 byte) 277 190 { 278 191 int i; 192 + 279 193 for (i = 0; i < 8; i++) { 280 194 sht15_send_bit(data, !!(byte & 0x80)); 281 195 byte <<= 1; 282 196 } 283 197 } 198 + 284 199 /** 285 200 * sht15_wait_for_response() - checks for ack from device 286 201 * @data: device state 287 - **/ 202 + */ 288 203 static int sht15_wait_for_response(struct sht15_data *data) 289 204 { 290 205 gpio_direction_input(data->pdata->gpio_data); ··· 311 220 * 312 221 * On entry, sck is output low, data is output pull high 313 222 * and the interrupt disabled. 314 - **/ 223 + */ 315 224 static int sht15_send_cmd(struct sht15_data *data, u8 cmd) 316 225 { 317 226 int ret = 0; 227 + 318 228 sht15_transmission_start(data); 319 229 sht15_send_byte(data, cmd); 320 230 ret = sht15_wait_for_response(data); 321 231 return ret; 322 232 } 233 + 323 234 /** 324 - * sht15_update_single_val() - get a new value from device 235 + * sht15_soft_reset() - send a soft reset command 236 + * @data: sht15 specific data. 237 + * 238 + * As described in section 3.2 of the datasheet. 239 + */ 240 + static int sht15_soft_reset(struct sht15_data *data) 241 + { 242 + int ret; 243 + 244 + ret = sht15_send_cmd(data, SHT15_SOFT_RESET); 245 + if (ret) 246 + return ret; 247 + msleep(SHT15_TSRST); 248 + /* device resets default hardware status register value */ 249 + data->val_status = 0; 250 + 251 + return ret; 252 + } 253 + 254 + /** 255 + * sht15_ack() - send a ack 256 + * @data: sht15 specific data. 257 + * 258 + * Each byte of data is acknowledged by pulling the data line 259 + * low for one clock pulse. 260 + */ 261 + static void sht15_ack(struct sht15_data *data) 262 + { 263 + gpio_direction_output(data->pdata->gpio_data, 0); 264 + ndelay(SHT15_TSU); 265 + gpio_set_value(data->pdata->gpio_sck, 1); 266 + ndelay(SHT15_TSU); 267 + gpio_set_value(data->pdata->gpio_sck, 0); 268 + ndelay(SHT15_TSU); 269 + gpio_set_value(data->pdata->gpio_data, 1); 270 + 271 + gpio_direction_input(data->pdata->gpio_data); 272 + } 273 + 274 + /** 275 + * sht15_end_transmission() - notify device of end of transmission 276 + * @data: device state. 277 + * 278 + * This is basically a NAK (single clock pulse, data high). 279 + */ 280 + static void sht15_end_transmission(struct sht15_data *data) 281 + { 282 + gpio_direction_output(data->pdata->gpio_data, 1); 283 + ndelay(SHT15_TSU); 284 + gpio_set_value(data->pdata->gpio_sck, 1); 285 + ndelay(SHT15_TSCKH); 286 + gpio_set_value(data->pdata->gpio_sck, 0); 287 + ndelay(SHT15_TSCKL); 288 + } 289 + 290 + /** 291 + * sht15_read_byte() - Read a byte back from the device 292 + * @data: device state. 293 + */ 294 + static u8 sht15_read_byte(struct sht15_data *data) 295 + { 296 + int i; 297 + u8 byte = 0; 298 + 299 + for (i = 0; i < 8; ++i) { 300 + byte <<= 1; 301 + gpio_set_value(data->pdata->gpio_sck, 1); 302 + ndelay(SHT15_TSCKH); 303 + byte |= !!gpio_get_value(data->pdata->gpio_data); 304 + gpio_set_value(data->pdata->gpio_sck, 0); 305 + ndelay(SHT15_TSCKL); 306 + } 307 + return byte; 308 + } 309 + 310 + /** 311 + * sht15_send_status() - write the status register byte 312 + * @data: sht15 specific data. 313 + * @status: the byte to set the status register with. 314 + * 315 + * As described in figure 14 and table 5 of the datasheet. 316 + */ 317 + static int sht15_send_status(struct sht15_data *data, u8 status) 318 + { 319 + int ret; 320 + 321 + ret = sht15_send_cmd(data, SHT15_WRITE_STATUS); 322 + if (ret) 323 + return ret; 324 + gpio_direction_output(data->pdata->gpio_data, 1); 325 + ndelay(SHT15_TSU); 326 + sht15_send_byte(data, status); 327 + ret = sht15_wait_for_response(data); 328 + if (ret) 329 + return ret; 330 + 331 + data->val_status = status; 332 + return 0; 333 + } 334 + 335 + /** 336 + * sht15_update_status() - get updated status register from device if too old 337 + * @data: device instance specific data. 338 + * 339 + * As described in figure 15 and table 5 of the datasheet. 340 + */ 341 + static int sht15_update_status(struct sht15_data *data) 342 + { 343 + int ret = 0; 344 + u8 status; 345 + u8 previous_config; 346 + u8 dev_checksum = 0; 347 + u8 checksum_vals[2]; 348 + int timeout = HZ; 349 + 350 + mutex_lock(&data->read_lock); 351 + if (time_after(jiffies, data->last_status + timeout) 352 + || !data->status_valid) { 353 + ret = sht15_send_cmd(data, SHT15_READ_STATUS); 354 + if (ret) 355 + goto error_ret; 356 + status = sht15_read_byte(data); 357 + 358 + if (data->checksumming) { 359 + sht15_ack(data); 360 + dev_checksum = sht15_reverse(sht15_read_byte(data)); 361 + checksum_vals[0] = SHT15_READ_STATUS; 362 + checksum_vals[1] = status; 363 + data->checksum_ok = (sht15_crc8(data, checksum_vals, 2) 364 + == dev_checksum); 365 + } 366 + 367 + sht15_end_transmission(data); 368 + 369 + /* 370 + * Perform checksum validation on the received data. 371 + * Specification mentions that in case a checksum verification 372 + * fails, a soft reset command must be sent to the device. 373 + */ 374 + if (data->checksumming && !data->checksum_ok) { 375 + previous_config = data->val_status & 0x07; 376 + ret = sht15_soft_reset(data); 377 + if (ret) 378 + goto error_ret; 379 + if (previous_config) { 380 + ret = sht15_send_status(data, previous_config); 381 + if (ret) { 382 + dev_err(data->dev, 383 + "CRC validation failed, unable " 384 + "to restore device settings\n"); 385 + goto error_ret; 386 + } 387 + } 388 + ret = -EAGAIN; 389 + goto error_ret; 390 + } 391 + 392 + data->val_status = status; 393 + data->status_valid = true; 394 + data->last_status = jiffies; 395 + } 396 + error_ret: 397 + mutex_unlock(&data->read_lock); 398 + 399 + return ret; 400 + } 401 + 402 + /** 403 + * sht15_measurement() - get a new value from device 325 404 * @data: device instance specific data 326 405 * @command: command sent to request value 327 406 * @timeout_msecs: timeout after which comms are assumed 328 407 * to have failed are reset. 329 - **/ 330 - static inline int sht15_update_single_val(struct sht15_data *data, 331 - int command, 332 - int timeout_msecs) 408 + */ 409 + static int sht15_measurement(struct sht15_data *data, 410 + int command, 411 + int timeout_msecs) 333 412 { 334 413 int ret; 414 + u8 previous_config; 415 + 335 416 ret = sht15_send_cmd(data, command); 336 417 if (ret) 337 418 return ret; ··· 519 256 schedule_work(&data->read_work); 520 257 } 521 258 ret = wait_event_timeout(data->wait_queue, 522 - (data->flag == SHT15_READING_NOTHING), 259 + (data->state == SHT15_READING_NOTHING), 523 260 msecs_to_jiffies(timeout_msecs)); 524 261 if (ret == 0) {/* timeout occurred */ 525 262 disable_irq_nosync(gpio_to_irq(data->pdata->gpio_data)); 526 263 sht15_connection_reset(data); 527 264 return -ETIME; 528 265 } 266 + 267 + /* 268 + * Perform checksum validation on the received data. 269 + * Specification mentions that in case a checksum verification fails, 270 + * a soft reset command must be sent to the device. 271 + */ 272 + if (data->checksumming && !data->checksum_ok) { 273 + previous_config = data->val_status & 0x07; 274 + ret = sht15_soft_reset(data); 275 + if (ret) 276 + return ret; 277 + if (previous_config) { 278 + ret = sht15_send_status(data, previous_config); 279 + if (ret) { 280 + dev_err(data->dev, 281 + "CRC validation failed, unable " 282 + "to restore device settings\n"); 283 + return ret; 284 + } 285 + } 286 + return -EAGAIN; 287 + } 288 + 529 289 return 0; 530 290 } 531 291 532 292 /** 533 - * sht15_update_vals() - get updated readings from device if too old 293 + * sht15_update_measurements() - get updated measures from device if too old 534 294 * @data: device state 535 - **/ 536 - static int sht15_update_vals(struct sht15_data *data) 295 + */ 296 + static int sht15_update_measurements(struct sht15_data *data) 537 297 { 538 298 int ret = 0; 539 299 int timeout = HZ; 540 300 541 301 mutex_lock(&data->read_lock); 542 - if (time_after(jiffies, data->last_updat + timeout) 543 - || !data->valid) { 544 - data->flag = SHT15_READING_HUMID; 545 - ret = sht15_update_single_val(data, SHT15_MEASURE_RH, 160); 302 + if (time_after(jiffies, data->last_measurement + timeout) 303 + || !data->measurements_valid) { 304 + data->state = SHT15_READING_HUMID; 305 + ret = sht15_measurement(data, SHT15_MEASURE_RH, 160); 546 306 if (ret) 547 307 goto error_ret; 548 - data->flag = SHT15_READING_TEMP; 549 - ret = sht15_update_single_val(data, SHT15_MEASURE_TEMP, 400); 308 + data->state = SHT15_READING_TEMP; 309 + ret = sht15_measurement(data, SHT15_MEASURE_TEMP, 400); 550 310 if (ret) 551 311 goto error_ret; 552 - data->valid = 1; 553 - data->last_updat = jiffies; 312 + data->measurements_valid = true; 313 + data->last_measurement = jiffies; 554 314 } 555 315 error_ret: 556 316 mutex_unlock(&data->read_lock); ··· 586 300 * @data: device state 587 301 * 588 302 * As per section 4.3 of the data sheet. 589 - **/ 303 + */ 590 304 static inline int sht15_calc_temp(struct sht15_data *data) 591 305 { 592 306 int d1 = temppoints[0].d1; 307 + int d2 = (data->val_status & SHT15_STATUS_LOW_RESOLUTION) ? 40 : 10; 593 308 int i; 594 309 595 310 for (i = ARRAY_SIZE(temppoints) - 1; i > 0; i--) ··· 603 316 break; 604 317 } 605 318 606 - return data->val_temp*10 + d1; 319 + return data->val_temp * d2 + d1; 607 320 } 608 321 609 322 /** ··· 612 325 * 613 326 * This is the temperature compensated version as per section 4.2 of 614 327 * the data sheet. 615 - **/ 328 + * 329 + * The sensor is assumed to be V3, which is compatible with V4. 330 + * Humidity conversion coefficients are shown in table 7 of the datasheet. 331 + */ 616 332 static inline int sht15_calc_humid(struct sht15_data *data) 617 333 { 618 - int RHlinear; /* milli percent */ 334 + int rh_linear; /* milli percent */ 619 335 int temp = sht15_calc_temp(data); 620 - 336 + int c2, c3; 337 + int t2; 621 338 const int c1 = -4; 622 - const int c2 = 40500; /* x 10 ^ -6 */ 623 - const int c3 = -28; /* x 10 ^ -7 */ 624 339 625 - RHlinear = c1*1000 626 - + c2 * data->val_humid/1000 340 + if (data->val_status & SHT15_STATUS_LOW_RESOLUTION) { 341 + c2 = 648000; /* x 10 ^ -6 */ 342 + c3 = -7200; /* x 10 ^ -7 */ 343 + t2 = 1280; 344 + } else { 345 + c2 = 40500; /* x 10 ^ -6 */ 346 + c3 = -28; /* x 10 ^ -7 */ 347 + t2 = 80; 348 + } 349 + 350 + rh_linear = c1 * 1000 351 + + c2 * data->val_humid / 1000 627 352 + (data->val_humid * data->val_humid * c3) / 10000; 628 - return (temp - 25000) * (10000 + 80 * data->val_humid) 629 - / 1000000 + RHlinear; 353 + return (temp - 25000) * (10000 + t2 * data->val_humid) 354 + / 1000000 + rh_linear; 630 355 } 631 356 357 + /** 358 + * sht15_show_status() - show status information in sysfs 359 + * @dev: device. 360 + * @attr: device attribute. 361 + * @buf: sysfs buffer where information is written to. 362 + * 363 + * Will be called on read access to temp1_fault, humidity1_fault 364 + * and heater_enable sysfs attributes. 365 + * Returns number of bytes written into buffer, negative errno on error. 366 + */ 367 + static ssize_t sht15_show_status(struct device *dev, 368 + struct device_attribute *attr, 369 + char *buf) 370 + { 371 + int ret; 372 + struct sht15_data *data = dev_get_drvdata(dev); 373 + u8 bit = to_sensor_dev_attr(attr)->index; 374 + 375 + ret = sht15_update_status(data); 376 + 377 + return ret ? ret : sprintf(buf, "%d\n", !!(data->val_status & bit)); 378 + } 379 + 380 + /** 381 + * sht15_store_heater() - change heater state via sysfs 382 + * @dev: device. 383 + * @attr: device attribute. 384 + * @buf: sysfs buffer to read the new heater state from. 385 + * @count: length of the data. 386 + * 387 + * Will be called on read access to heater_enable sysfs attribute. 388 + * Returns number of bytes actually decoded, negative errno on error. 389 + */ 390 + static ssize_t sht15_store_heater(struct device *dev, 391 + struct device_attribute *attr, 392 + const char *buf, size_t count) 393 + { 394 + int ret; 395 + struct sht15_data *data = dev_get_drvdata(dev); 396 + long value; 397 + u8 status; 398 + 399 + if (strict_strtol(buf, 10, &value)) 400 + return -EINVAL; 401 + 402 + mutex_lock(&data->read_lock); 403 + status = data->val_status & 0x07; 404 + if (!!value) 405 + status |= SHT15_STATUS_HEATER; 406 + else 407 + status &= ~SHT15_STATUS_HEATER; 408 + 409 + ret = sht15_send_status(data, status); 410 + mutex_unlock(&data->read_lock); 411 + 412 + return ret ? ret : count; 413 + } 414 + 415 + /** 416 + * sht15_show_temp() - show temperature measurement value in sysfs 417 + * @dev: device. 418 + * @attr: device attribute. 419 + * @buf: sysfs buffer where measurement values are written to. 420 + * 421 + * Will be called on read access to temp1_input sysfs attribute. 422 + * Returns number of bytes written into buffer, negative errno on error. 423 + */ 632 424 static ssize_t sht15_show_temp(struct device *dev, 633 425 struct device_attribute *attr, 634 426 char *buf) ··· 716 350 struct sht15_data *data = dev_get_drvdata(dev); 717 351 718 352 /* Technically no need to read humidity as well */ 719 - ret = sht15_update_vals(data); 353 + ret = sht15_update_measurements(data); 720 354 721 355 return ret ? ret : sprintf(buf, "%d\n", 722 356 sht15_calc_temp(data)); 723 357 } 724 358 359 + /** 360 + * sht15_show_humidity() - show humidity measurement value in sysfs 361 + * @dev: device. 362 + * @attr: device attribute. 363 + * @buf: sysfs buffer where measurement values are written to. 364 + * 365 + * Will be called on read access to humidity1_input sysfs attribute. 366 + * Returns number of bytes written into buffer, negative errno on error. 367 + */ 725 368 static ssize_t sht15_show_humidity(struct device *dev, 726 369 struct device_attribute *attr, 727 370 char *buf) ··· 738 363 int ret; 739 364 struct sht15_data *data = dev_get_drvdata(dev); 740 365 741 - ret = sht15_update_vals(data); 366 + ret = sht15_update_measurements(data); 742 367 743 368 return ret ? ret : sprintf(buf, "%d\n", sht15_calc_humid(data)); 369 + } 744 370 745 - }; 746 371 static ssize_t show_name(struct device *dev, 747 372 struct device_attribute *attr, 748 373 char *buf) ··· 751 376 return sprintf(buf, "%s\n", pdev->name); 752 377 } 753 378 754 - static SENSOR_DEVICE_ATTR(temp1_input, 755 - S_IRUGO, sht15_show_temp, 756 - NULL, 0); 757 - static SENSOR_DEVICE_ATTR(humidity1_input, 758 - S_IRUGO, sht15_show_humidity, 759 - NULL, 0); 379 + static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, 380 + sht15_show_temp, NULL, 0); 381 + static SENSOR_DEVICE_ATTR(humidity1_input, S_IRUGO, 382 + sht15_show_humidity, NULL, 0); 383 + static SENSOR_DEVICE_ATTR(temp1_fault, S_IRUGO, sht15_show_status, NULL, 384 + SHT15_STATUS_LOW_BATTERY); 385 + static SENSOR_DEVICE_ATTR(humidity1_fault, S_IRUGO, sht15_show_status, NULL, 386 + SHT15_STATUS_LOW_BATTERY); 387 + static SENSOR_DEVICE_ATTR(heater_enable, S_IRUGO | S_IWUSR, sht15_show_status, 388 + sht15_store_heater, SHT15_STATUS_HEATER); 760 389 static DEVICE_ATTR(name, S_IRUGO, show_name, NULL); 761 390 static struct attribute *sht15_attrs[] = { 762 391 &sensor_dev_attr_temp1_input.dev_attr.attr, 763 392 &sensor_dev_attr_humidity1_input.dev_attr.attr, 393 + &sensor_dev_attr_temp1_fault.dev_attr.attr, 394 + &sensor_dev_attr_humidity1_fault.dev_attr.attr, 395 + &sensor_dev_attr_heater_enable.dev_attr.attr, 764 396 &dev_attr_name.attr, 765 397 NULL, 766 398 }; ··· 779 397 static irqreturn_t sht15_interrupt_fired(int irq, void *d) 780 398 { 781 399 struct sht15_data *data = d; 400 + 782 401 /* First disable the interrupt */ 783 402 disable_irq_nosync(irq); 784 403 atomic_inc(&data->interrupt_handled); 785 404 /* Then schedule a reading work struct */ 786 - if (data->flag != SHT15_READING_NOTHING) 405 + if (data->state != SHT15_READING_NOTHING) 787 406 schedule_work(&data->read_work); 788 407 return IRQ_HANDLED; 789 408 } 790 409 791 - /* Each byte of data is acknowledged by pulling the data line 792 - * low for one clock pulse. 793 - */ 794 - static void sht15_ack(struct sht15_data *data) 795 - { 796 - gpio_direction_output(data->pdata->gpio_data, 0); 797 - ndelay(SHT15_TSU); 798 - gpio_set_value(data->pdata->gpio_sck, 1); 799 - ndelay(SHT15_TSU); 800 - gpio_set_value(data->pdata->gpio_sck, 0); 801 - ndelay(SHT15_TSU); 802 - gpio_set_value(data->pdata->gpio_data, 1); 803 - 804 - gpio_direction_input(data->pdata->gpio_data); 805 - } 806 - /** 807 - * sht15_end_transmission() - notify device of end of transmission 808 - * @data: device state 809 - * 810 - * This is basically a NAK. (single clock pulse, data high) 811 - **/ 812 - static void sht15_end_transmission(struct sht15_data *data) 813 - { 814 - gpio_direction_output(data->pdata->gpio_data, 1); 815 - ndelay(SHT15_TSU); 816 - gpio_set_value(data->pdata->gpio_sck, 1); 817 - ndelay(SHT15_TSCKH); 818 - gpio_set_value(data->pdata->gpio_sck, 0); 819 - ndelay(SHT15_TSCKL); 820 - } 821 - 822 410 static void sht15_bh_read_data(struct work_struct *work_s) 823 411 { 824 - int i; 825 412 uint16_t val = 0; 413 + u8 dev_checksum = 0; 414 + u8 checksum_vals[3]; 826 415 struct sht15_data *data 827 416 = container_of(work_s, struct sht15_data, 828 417 read_work); 418 + 829 419 /* Firstly, verify the line is low */ 830 420 if (gpio_get_value(data->pdata->gpio_data)) { 831 - /* If not, then start the interrupt again - care 832 - here as could have gone low in meantime so verify 833 - it hasn't! 834 - */ 421 + /* 422 + * If not, then start the interrupt again - care here as could 423 + * have gone low in meantime so verify it hasn't! 424 + */ 835 425 atomic_set(&data->interrupt_handled, 0); 836 426 enable_irq(gpio_to_irq(data->pdata->gpio_data)); 837 427 /* If still not occurred or another handler has been scheduled */ ··· 811 457 || atomic_read(&data->interrupt_handled)) 812 458 return; 813 459 } 460 + 814 461 /* Read the data back from the device */ 815 - for (i = 0; i < 16; ++i) { 816 - val <<= 1; 817 - gpio_set_value(data->pdata->gpio_sck, 1); 818 - ndelay(SHT15_TSCKH); 819 - val |= !!gpio_get_value(data->pdata->gpio_data); 820 - gpio_set_value(data->pdata->gpio_sck, 0); 821 - ndelay(SHT15_TSCKL); 822 - if (i == 7) 823 - sht15_ack(data); 462 + val = sht15_read_byte(data); 463 + val <<= 8; 464 + sht15_ack(data); 465 + val |= sht15_read_byte(data); 466 + 467 + if (data->checksumming) { 468 + /* 469 + * Ask the device for a checksum and read it back. 470 + * Note: the device sends the checksum byte reversed. 471 + */ 472 + sht15_ack(data); 473 + dev_checksum = sht15_reverse(sht15_read_byte(data)); 474 + checksum_vals[0] = (data->state == SHT15_READING_TEMP) ? 475 + SHT15_MEASURE_TEMP : SHT15_MEASURE_RH; 476 + checksum_vals[1] = (u8) (val >> 8); 477 + checksum_vals[2] = (u8) val; 478 + data->checksum_ok 479 + = (sht15_crc8(data, checksum_vals, 3) == dev_checksum); 824 480 } 481 + 825 482 /* Tell the device we are done */ 826 483 sht15_end_transmission(data); 827 484 828 - switch (data->flag) { 485 + switch (data->state) { 829 486 case SHT15_READING_TEMP: 830 487 data->val_temp = val; 831 488 break; 832 489 case SHT15_READING_HUMID: 833 490 data->val_humid = val; 834 491 break; 492 + default: 493 + break; 835 494 } 836 495 837 - data->flag = SHT15_READING_NOTHING; 496 + data->state = SHT15_READING_NOTHING; 838 497 wake_up(&data->wait_queue); 839 498 } 840 499 ··· 867 500 * 868 501 * Note that as the notification code holds the regulator lock, we have 869 502 * to schedule an update of the supply voltage rather than getting it directly. 870 - **/ 503 + */ 871 504 static int sht15_invalidate_voltage(struct notifier_block *nb, 872 - unsigned long event, 873 - void *ignored) 505 + unsigned long event, 506 + void *ignored) 874 507 { 875 508 struct sht15_data *data = container_of(nb, struct sht15_data, nb); 876 509 ··· 885 518 { 886 519 int ret = 0; 887 520 struct sht15_data *data = kzalloc(sizeof(*data), GFP_KERNEL); 521 + u8 status = 0; 888 522 889 523 if (!data) { 890 524 ret = -ENOMEM; 891 - dev_err(&pdev->dev, "kzalloc failed"); 525 + dev_err(&pdev->dev, "kzalloc failed\n"); 892 526 goto error_ret; 893 527 } 894 528 ··· 901 533 init_waitqueue_head(&data->wait_queue); 902 534 903 535 if (pdev->dev.platform_data == NULL) { 904 - dev_err(&pdev->dev, "no platform data supplied"); 536 + dev_err(&pdev->dev, "no platform data supplied\n"); 905 537 goto err_free_data; 906 538 } 907 539 data->pdata = pdev->dev.platform_data; 908 - data->supply_uV = data->pdata->supply_mv*1000; 540 + data->supply_uV = data->pdata->supply_mv * 1000; 541 + if (data->pdata->checksum) 542 + data->checksumming = true; 543 + if (data->pdata->no_otp_reload) 544 + status |= SHT15_STATUS_NO_OTP_RELOAD; 545 + if (data->pdata->low_resolution) 546 + status |= SHT15_STATUS_LOW_RESOLUTION; 909 547 910 - /* If a regulator is available, query what the supply voltage actually is!*/ 548 + /* 549 + * If a regulator is available, 550 + * query what the supply voltage actually is! 551 + */ 911 552 data->reg = regulator_get(data->dev, "vcc"); 912 553 if (!IS_ERR(data->reg)) { 913 554 int voltage; ··· 926 549 data->supply_uV = voltage; 927 550 928 551 regulator_enable(data->reg); 929 - /* setup a notifier block to update this if another device 930 - * causes the voltage to change */ 552 + /* 553 + * Setup a notifier block to update this if another device 554 + * causes the voltage to change 555 + */ 931 556 data->nb.notifier_call = &sht15_invalidate_voltage; 932 557 ret = regulator_register_notifier(data->reg, &data->nb); 558 + if (ret) { 559 + dev_err(&pdev->dev, 560 + "regulator notifier request failed\n"); 561 + regulator_disable(data->reg); 562 + regulator_put(data->reg); 563 + goto err_free_data; 564 + } 933 565 } 934 - /* Try requesting the GPIOs */ 566 + 567 + /* Try requesting the GPIOs */ 935 568 ret = gpio_request(data->pdata->gpio_sck, "SHT15 sck"); 936 569 if (ret) { 937 - dev_err(&pdev->dev, "gpio request failed"); 938 - goto err_free_data; 570 + dev_err(&pdev->dev, "gpio request failed\n"); 571 + goto err_release_reg; 939 572 } 940 573 gpio_direction_output(data->pdata->gpio_sck, 0); 574 + 941 575 ret = gpio_request(data->pdata->gpio_data, "SHT15 data"); 942 576 if (ret) { 943 - dev_err(&pdev->dev, "gpio request failed"); 577 + dev_err(&pdev->dev, "gpio request failed\n"); 944 578 goto err_release_gpio_sck; 945 - } 946 - ret = sysfs_create_group(&pdev->dev.kobj, &sht15_attr_group); 947 - if (ret) { 948 - dev_err(&pdev->dev, "sysfs create failed"); 949 - goto err_release_gpio_data; 950 579 } 951 580 952 581 ret = request_irq(gpio_to_irq(data->pdata->gpio_data), ··· 961 578 "sht15 data", 962 579 data); 963 580 if (ret) { 964 - dev_err(&pdev->dev, "failed to get irq for data line"); 581 + dev_err(&pdev->dev, "failed to get irq for data line\n"); 965 582 goto err_release_gpio_data; 966 583 } 967 584 disable_irq_nosync(gpio_to_irq(data->pdata->gpio_data)); 968 585 sht15_connection_reset(data); 969 - sht15_send_cmd(data, 0x1E); 586 + ret = sht15_soft_reset(data); 587 + if (ret) 588 + goto err_release_irq; 589 + 590 + /* write status with platform data options */ 591 + if (status) { 592 + ret = sht15_send_status(data, status); 593 + if (ret) 594 + goto err_release_irq; 595 + } 596 + 597 + ret = sysfs_create_group(&pdev->dev.kobj, &sht15_attr_group); 598 + if (ret) { 599 + dev_err(&pdev->dev, "sysfs create failed\n"); 600 + goto err_release_irq; 601 + } 970 602 971 603 data->hwmon_dev = hwmon_device_register(data->dev); 972 604 if (IS_ERR(data->hwmon_dev)) { 973 605 ret = PTR_ERR(data->hwmon_dev); 974 - goto err_release_irq; 606 + goto err_release_sysfs_group; 975 607 } 608 + 976 609 return 0; 977 610 611 + err_release_sysfs_group: 612 + sysfs_remove_group(&pdev->dev.kobj, &sht15_attr_group); 978 613 err_release_irq: 979 614 free_irq(gpio_to_irq(data->pdata->gpio_data), data); 980 615 err_release_gpio_data: 981 616 gpio_free(data->pdata->gpio_data); 982 617 err_release_gpio_sck: 983 618 gpio_free(data->pdata->gpio_sck); 619 + err_release_reg: 620 + if (!IS_ERR(data->reg)) { 621 + regulator_unregister_notifier(data->reg, &data->nb); 622 + regulator_disable(data->reg); 623 + regulator_put(data->reg); 624 + } 984 625 err_free_data: 985 626 kfree(data); 986 627 error_ret: 987 - 988 628 return ret; 989 629 } 990 630 ··· 1015 609 { 1016 610 struct sht15_data *data = platform_get_drvdata(pdev); 1017 611 1018 - /* Make sure any reads from the device are done and 1019 - * prevent new ones from beginning */ 612 + /* 613 + * Make sure any reads from the device are done and 614 + * prevent new ones beginning 615 + */ 1020 616 mutex_lock(&data->read_lock); 617 + if (sht15_soft_reset(data)) { 618 + mutex_unlock(&data->read_lock); 619 + return -EFAULT; 620 + } 1021 621 hwmon_device_unregister(data->hwmon_dev); 1022 622 sysfs_remove_group(&pdev->dev.kobj, &sht15_attr_group); 1023 623 if (!IS_ERR(data->reg)) { ··· 1037 625 gpio_free(data->pdata->gpio_sck); 1038 626 mutex_unlock(&data->read_lock); 1039 627 kfree(data); 628 + 1040 629 return 0; 1041 630 } 1042 - 1043 631 1044 632 /* 1045 633 * sht_drivers simultaneously refers to __devinit and __devexit function ··· 1084 672 .remove = __devexit_p(sht15_remove), 1085 673 }, 1086 674 }; 1087 - 1088 675 1089 676 static int __init sht15_init(void) 1090 677 {
+278
drivers/hwmon/ucd9000.c
··· 1 + /* 2 + * Hardware monitoring driver for UCD90xxx Sequencer and System Health 3 + * Controller series 4 + * 5 + * Copyright (C) 2011 Ericsson AB. 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 + #include <linux/kernel.h> 23 + #include <linux/module.h> 24 + #include <linux/init.h> 25 + #include <linux/err.h> 26 + #include <linux/slab.h> 27 + #include <linux/i2c.h> 28 + #include <linux/i2c/pmbus.h> 29 + #include "pmbus.h" 30 + 31 + enum chips { ucd9000, ucd90120, ucd90124, ucd9090, ucd90910 }; 32 + 33 + #define UCD9000_MONITOR_CONFIG 0xd5 34 + #define UCD9000_NUM_PAGES 0xd6 35 + #define UCD9000_FAN_CONFIG_INDEX 0xe7 36 + #define UCD9000_FAN_CONFIG 0xe8 37 + #define UCD9000_DEVICE_ID 0xfd 38 + 39 + #define UCD9000_MON_TYPE(x) (((x) >> 5) & 0x07) 40 + #define UCD9000_MON_PAGE(x) ((x) & 0x0f) 41 + 42 + #define UCD9000_MON_VOLTAGE 1 43 + #define UCD9000_MON_TEMPERATURE 2 44 + #define UCD9000_MON_CURRENT 3 45 + #define UCD9000_MON_VOLTAGE_HW 4 46 + 47 + #define UCD9000_NUM_FAN 4 48 + 49 + struct ucd9000_data { 50 + u8 fan_data[UCD9000_NUM_FAN][I2C_SMBUS_BLOCK_MAX]; 51 + struct pmbus_driver_info info; 52 + }; 53 + #define to_ucd9000_data(_info) container_of(_info, struct ucd9000_data, info) 54 + 55 + static int ucd9000_get_fan_config(struct i2c_client *client, int fan) 56 + { 57 + int fan_config = 0; 58 + struct ucd9000_data *data 59 + = to_ucd9000_data(pmbus_get_driver_info(client)); 60 + 61 + if (data->fan_data[fan][3] & 1) 62 + fan_config |= PB_FAN_2_INSTALLED; /* Use lower bit position */ 63 + 64 + /* Pulses/revolution */ 65 + fan_config |= (data->fan_data[fan][3] & 0x06) >> 1; 66 + 67 + return fan_config; 68 + } 69 + 70 + static int ucd9000_read_byte_data(struct i2c_client *client, int page, int reg) 71 + { 72 + int ret = 0; 73 + int fan_config; 74 + 75 + switch (reg) { 76 + case PMBUS_FAN_CONFIG_12: 77 + if (page) 78 + return -EINVAL; 79 + 80 + ret = ucd9000_get_fan_config(client, 0); 81 + if (ret < 0) 82 + return ret; 83 + fan_config = ret << 4; 84 + ret = ucd9000_get_fan_config(client, 1); 85 + if (ret < 0) 86 + return ret; 87 + fan_config |= ret; 88 + ret = fan_config; 89 + break; 90 + case PMBUS_FAN_CONFIG_34: 91 + if (page) 92 + return -EINVAL; 93 + 94 + ret = ucd9000_get_fan_config(client, 2); 95 + if (ret < 0) 96 + return ret; 97 + fan_config = ret << 4; 98 + ret = ucd9000_get_fan_config(client, 3); 99 + if (ret < 0) 100 + return ret; 101 + fan_config |= ret; 102 + ret = fan_config; 103 + break; 104 + default: 105 + ret = -ENODATA; 106 + break; 107 + } 108 + return ret; 109 + } 110 + 111 + static const struct i2c_device_id ucd9000_id[] = { 112 + {"ucd9000", ucd9000}, 113 + {"ucd90120", ucd90120}, 114 + {"ucd90124", ucd90124}, 115 + {"ucd9090", ucd9090}, 116 + {"ucd90910", ucd90910}, 117 + {} 118 + }; 119 + MODULE_DEVICE_TABLE(i2c, ucd9000_id); 120 + 121 + static int ucd9000_probe(struct i2c_client *client, 122 + const struct i2c_device_id *id) 123 + { 124 + u8 block_buffer[I2C_SMBUS_BLOCK_MAX + 1]; 125 + struct ucd9000_data *data; 126 + struct pmbus_driver_info *info; 127 + const struct i2c_device_id *mid; 128 + int i, ret; 129 + 130 + if (!i2c_check_functionality(client->adapter, 131 + I2C_FUNC_SMBUS_BYTE_DATA | 132 + I2C_FUNC_SMBUS_BLOCK_DATA)) 133 + return -ENODEV; 134 + 135 + ret = i2c_smbus_read_block_data(client, UCD9000_DEVICE_ID, 136 + block_buffer); 137 + if (ret < 0) { 138 + dev_err(&client->dev, "Failed to read device ID\n"); 139 + return ret; 140 + } 141 + block_buffer[ret] = '\0'; 142 + dev_info(&client->dev, "Device ID %s\n", block_buffer); 143 + 144 + mid = NULL; 145 + for (i = 0; i < ARRAY_SIZE(ucd9000_id); i++) { 146 + mid = &ucd9000_id[i]; 147 + if (!strncasecmp(mid->name, block_buffer, strlen(mid->name))) 148 + break; 149 + } 150 + if (!mid || !strlen(mid->name)) { 151 + dev_err(&client->dev, "Unsupported device\n"); 152 + return -ENODEV; 153 + } 154 + 155 + if (id->driver_data != ucd9000 && id->driver_data != mid->driver_data) 156 + dev_notice(&client->dev, 157 + "Device mismatch: Configured %s, detected %s\n", 158 + id->name, mid->name); 159 + 160 + data = kzalloc(sizeof(struct ucd9000_data), GFP_KERNEL); 161 + if (!data) 162 + return -ENOMEM; 163 + info = &data->info; 164 + 165 + ret = i2c_smbus_read_byte_data(client, UCD9000_NUM_PAGES); 166 + if (ret < 0) { 167 + dev_err(&client->dev, 168 + "Failed to read number of active pages\n"); 169 + goto out; 170 + } 171 + info->pages = ret; 172 + if (!info->pages) { 173 + dev_err(&client->dev, "No pages configured\n"); 174 + ret = -ENODEV; 175 + goto out; 176 + } 177 + 178 + /* The internal temperature sensor is always active */ 179 + info->func[0] = PMBUS_HAVE_TEMP; 180 + 181 + /* Everything else is configurable */ 182 + ret = i2c_smbus_read_block_data(client, UCD9000_MONITOR_CONFIG, 183 + block_buffer); 184 + if (ret <= 0) { 185 + dev_err(&client->dev, "Failed to read configuration data\n"); 186 + ret = -ENODEV; 187 + goto out; 188 + } 189 + for (i = 0; i < ret; i++) { 190 + int page = UCD9000_MON_PAGE(block_buffer[i]); 191 + 192 + if (page >= info->pages) 193 + continue; 194 + 195 + switch (UCD9000_MON_TYPE(block_buffer[i])) { 196 + case UCD9000_MON_VOLTAGE: 197 + case UCD9000_MON_VOLTAGE_HW: 198 + info->func[page] |= PMBUS_HAVE_VOUT 199 + | PMBUS_HAVE_STATUS_VOUT; 200 + break; 201 + case UCD9000_MON_TEMPERATURE: 202 + info->func[page] |= PMBUS_HAVE_TEMP2 203 + | PMBUS_HAVE_STATUS_TEMP; 204 + break; 205 + case UCD9000_MON_CURRENT: 206 + info->func[page] |= PMBUS_HAVE_IOUT 207 + | PMBUS_HAVE_STATUS_IOUT; 208 + break; 209 + default: 210 + break; 211 + } 212 + } 213 + 214 + /* Fan configuration */ 215 + if (mid->driver_data == ucd90124) { 216 + for (i = 0; i < UCD9000_NUM_FAN; i++) { 217 + i2c_smbus_write_byte_data(client, 218 + UCD9000_FAN_CONFIG_INDEX, i); 219 + ret = i2c_smbus_read_block_data(client, 220 + UCD9000_FAN_CONFIG, 221 + data->fan_data[i]); 222 + if (ret < 0) 223 + goto out; 224 + } 225 + i2c_smbus_write_byte_data(client, UCD9000_FAN_CONFIG_INDEX, 0); 226 + 227 + info->read_byte_data = ucd9000_read_byte_data; 228 + info->func[0] |= PMBUS_HAVE_FAN12 | PMBUS_HAVE_STATUS_FAN12 229 + | PMBUS_HAVE_FAN34 | PMBUS_HAVE_STATUS_FAN34; 230 + } 231 + 232 + ret = pmbus_do_probe(client, mid, info); 233 + if (ret < 0) 234 + goto out; 235 + return 0; 236 + 237 + out: 238 + kfree(data); 239 + return ret; 240 + } 241 + 242 + static int ucd9000_remove(struct i2c_client *client) 243 + { 244 + int ret; 245 + struct ucd9000_data *data; 246 + 247 + data = to_ucd9000_data(pmbus_get_driver_info(client)); 248 + ret = pmbus_do_remove(client); 249 + kfree(data); 250 + return ret; 251 + } 252 + 253 + 254 + /* This is the driver that will be inserted */ 255 + static struct i2c_driver ucd9000_driver = { 256 + .driver = { 257 + .name = "ucd9000", 258 + }, 259 + .probe = ucd9000_probe, 260 + .remove = ucd9000_remove, 261 + .id_table = ucd9000_id, 262 + }; 263 + 264 + static int __init ucd9000_init(void) 265 + { 266 + return i2c_add_driver(&ucd9000_driver); 267 + } 268 + 269 + static void __exit ucd9000_exit(void) 270 + { 271 + i2c_del_driver(&ucd9000_driver); 272 + } 273 + 274 + MODULE_AUTHOR("Guenter Roeck"); 275 + MODULE_DESCRIPTION("PMBus driver for TI UCD90xxx"); 276 + MODULE_LICENSE("GPL"); 277 + module_init(ucd9000_init); 278 + module_exit(ucd9000_exit);
+210
drivers/hwmon/ucd9200.c
··· 1 + /* 2 + * Hardware monitoring driver for ucd9200 series Digital PWM System Controllers 3 + * 4 + * Copyright (C) 2011 Ericsson AB. 5 + * 6 + * This program is free software; you can redistribute it and/or modify 7 + * it under the terms of the GNU General Public License as published by 8 + * the Free Software Foundation; either version 2 of the License, or 9 + * (at your option) any later version. 10 + * 11 + * This program is distributed in the hope that it will be useful, 12 + * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 + * GNU General Public License for more details. 15 + * 16 + * You should have received a copy of the GNU General Public License 17 + * along with this program; if not, write to the Free Software 18 + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 19 + */ 20 + 21 + #include <linux/kernel.h> 22 + #include <linux/module.h> 23 + #include <linux/init.h> 24 + #include <linux/err.h> 25 + #include <linux/slab.h> 26 + #include <linux/i2c.h> 27 + #include <linux/i2c/pmbus.h> 28 + #include "pmbus.h" 29 + 30 + #define UCD9200_PHASE_INFO 0xd2 31 + #define UCD9200_DEVICE_ID 0xfd 32 + 33 + enum chips { ucd9200, ucd9220, ucd9222, ucd9224, ucd9240, ucd9244, ucd9246, 34 + ucd9248 }; 35 + 36 + static const struct i2c_device_id ucd9200_id[] = { 37 + {"ucd9200", ucd9200}, 38 + {"ucd9220", ucd9220}, 39 + {"ucd9222", ucd9222}, 40 + {"ucd9224", ucd9224}, 41 + {"ucd9240", ucd9240}, 42 + {"ucd9244", ucd9244}, 43 + {"ucd9246", ucd9246}, 44 + {"ucd9248", ucd9248}, 45 + {} 46 + }; 47 + MODULE_DEVICE_TABLE(i2c, ucd9200_id); 48 + 49 + static int ucd9200_probe(struct i2c_client *client, 50 + const struct i2c_device_id *id) 51 + { 52 + u8 block_buffer[I2C_SMBUS_BLOCK_MAX + 1]; 53 + struct pmbus_driver_info *info; 54 + const struct i2c_device_id *mid; 55 + int i, j, ret; 56 + 57 + if (!i2c_check_functionality(client->adapter, 58 + I2C_FUNC_SMBUS_BYTE_DATA | 59 + I2C_FUNC_SMBUS_BLOCK_DATA)) 60 + return -ENODEV; 61 + 62 + ret = i2c_smbus_read_block_data(client, UCD9200_DEVICE_ID, 63 + block_buffer); 64 + if (ret < 0) { 65 + dev_err(&client->dev, "Failed to read device ID\n"); 66 + return ret; 67 + } 68 + block_buffer[ret] = '\0'; 69 + dev_info(&client->dev, "Device ID %s\n", block_buffer); 70 + 71 + mid = NULL; 72 + for (i = 0; i < ARRAY_SIZE(ucd9200_id); i++) { 73 + mid = &ucd9200_id[i]; 74 + if (!strncasecmp(mid->name, block_buffer, strlen(mid->name))) 75 + break; 76 + } 77 + if (!mid || !strlen(mid->name)) { 78 + dev_err(&client->dev, "Unsupported device\n"); 79 + return -ENODEV; 80 + } 81 + if (id->driver_data != ucd9200 && id->driver_data != mid->driver_data) 82 + dev_notice(&client->dev, 83 + "Device mismatch: Configured %s, detected %s\n", 84 + id->name, mid->name); 85 + 86 + info = kzalloc(sizeof(struct pmbus_driver_info), GFP_KERNEL); 87 + if (!info) 88 + return -ENOMEM; 89 + 90 + ret = i2c_smbus_read_block_data(client, UCD9200_PHASE_INFO, 91 + block_buffer); 92 + if (ret < 0) { 93 + dev_err(&client->dev, "Failed to read phase information\n"); 94 + goto out; 95 + } 96 + 97 + /* 98 + * Calculate number of configured pages (rails) from PHASE_INFO 99 + * register. 100 + * Rails have to be sequential, so we can abort after finding 101 + * the first unconfigured rail. 102 + */ 103 + info->pages = 0; 104 + for (i = 0; i < ret; i++) { 105 + if (!block_buffer[i]) 106 + break; 107 + info->pages++; 108 + } 109 + if (!info->pages) { 110 + dev_err(&client->dev, "No rails configured\n"); 111 + ret = -ENODEV; 112 + goto out; 113 + } 114 + dev_info(&client->dev, "%d rails configured\n", info->pages); 115 + 116 + /* 117 + * Set PHASE registers on all pages to 0xff to ensure that phase 118 + * specific commands will apply to all phases of a given page (rail). 119 + * This only affects the READ_IOUT and READ_TEMPERATURE2 registers. 120 + * READ_IOUT will return the sum of currents of all phases of a rail, 121 + * and READ_TEMPERATURE2 will return the maximum temperature detected 122 + * for the the phases of the rail. 123 + */ 124 + for (i = 0; i < info->pages; i++) { 125 + /* 126 + * Setting PAGE & PHASE fails once in a while for no obvious 127 + * reason, so we need to retry a couple of times. 128 + */ 129 + for (j = 0; j < 3; j++) { 130 + ret = i2c_smbus_write_byte_data(client, PMBUS_PAGE, i); 131 + if (ret < 0) 132 + continue; 133 + ret = i2c_smbus_write_byte_data(client, PMBUS_PHASE, 134 + 0xff); 135 + if (ret < 0) 136 + continue; 137 + break; 138 + } 139 + if (ret < 0) { 140 + dev_err(&client->dev, 141 + "Failed to initialize PHASE registers\n"); 142 + goto out; 143 + } 144 + } 145 + if (info->pages > 1) 146 + i2c_smbus_write_byte_data(client, PMBUS_PAGE, 0); 147 + 148 + info->func[0] = PMBUS_HAVE_VIN | PMBUS_HAVE_STATUS_INPUT | 149 + PMBUS_HAVE_IIN | PMBUS_HAVE_PIN | 150 + PMBUS_HAVE_VOUT | PMBUS_HAVE_STATUS_VOUT | 151 + PMBUS_HAVE_IOUT | PMBUS_HAVE_STATUS_IOUT | 152 + PMBUS_HAVE_POUT | PMBUS_HAVE_TEMP | 153 + PMBUS_HAVE_TEMP2 | PMBUS_HAVE_STATUS_TEMP; 154 + 155 + for (i = 1; i < info->pages; i++) 156 + info->func[i] = PMBUS_HAVE_VOUT | PMBUS_HAVE_STATUS_VOUT | 157 + PMBUS_HAVE_IOUT | PMBUS_HAVE_STATUS_IOUT | 158 + PMBUS_HAVE_POUT | 159 + PMBUS_HAVE_TEMP2 | PMBUS_HAVE_STATUS_TEMP; 160 + 161 + /* ucd9240 supports a single fan */ 162 + if (mid->driver_data == ucd9240) 163 + info->func[0] |= PMBUS_HAVE_FAN12 | PMBUS_HAVE_STATUS_FAN12; 164 + 165 + ret = pmbus_do_probe(client, mid, info); 166 + if (ret < 0) 167 + goto out; 168 + return 0; 169 + out: 170 + kfree(info); 171 + return ret; 172 + } 173 + 174 + static int ucd9200_remove(struct i2c_client *client) 175 + { 176 + int ret; 177 + const struct pmbus_driver_info *info; 178 + 179 + info = pmbus_get_driver_info(client); 180 + ret = pmbus_do_remove(client); 181 + kfree(info); 182 + return ret; 183 + } 184 + 185 + 186 + /* This is the driver that will be inserted */ 187 + static struct i2c_driver ucd9200_driver = { 188 + .driver = { 189 + .name = "ucd9200", 190 + }, 191 + .probe = ucd9200_probe, 192 + .remove = ucd9200_remove, 193 + .id_table = ucd9200_id, 194 + }; 195 + 196 + static int __init ucd9200_init(void) 197 + { 198 + return i2c_add_driver(&ucd9200_driver); 199 + } 200 + 201 + static void __exit ucd9200_exit(void) 202 + { 203 + i2c_del_driver(&ucd9200_driver); 204 + } 205 + 206 + MODULE_AUTHOR("Guenter Roeck"); 207 + MODULE_DESCRIPTION("PMBus driver for TI UCD922x, UCD924x"); 208 + MODULE_LICENSE("GPL"); 209 + module_init(ucd9200_init); 210 + module_exit(ucd9200_exit);
+14 -4
include/linux/sht15.h
··· 8 8 * This program is free software; you can redistribute it and/or modify 9 9 * it under the terms of the GNU General Public License version 2 as 10 10 * published by the Free Software Foundation. 11 + * 12 + * For further information, see the Documentation/hwmon/sht15 file. 11 13 */ 12 14 13 15 /** 14 16 * struct sht15_platform_data - sht15 connectivity info 15 - * @gpio_data: no. of gpio to which bidirectional data line is connected 16 - * @gpio_sck: no. of gpio to which the data clock is connected. 17 - * @supply_mv: supply voltage in mv. Overridden by regulator if available. 18 - **/ 17 + * @gpio_data: no. of gpio to which bidirectional data line is 18 + * connected. 19 + * @gpio_sck: no. of gpio to which the data clock is connected. 20 + * @supply_mv: supply voltage in mv. Overridden by regulator if 21 + * available. 22 + * @checksum: flag to indicate the checksum should be validated. 23 + * @no_otp_reload: flag to indicate no reload from OTP. 24 + * @low_resolution: flag to indicate the temp/humidity resolution to use. 25 + */ 19 26 struct sht15_platform_data { 20 27 int gpio_data; 21 28 int gpio_sck; 22 29 int supply_mv; 30 + bool checksum; 31 + bool no_otp_reload; 32 + bool low_resolution; 23 33 }; 24 34