summaryrefslogtreecommitdiffstats
path: root/Documentation/hwmon/lm85
blob: 7c49feaa79d236824c109a865835a6618eb49523 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
Kernel driver lm85
==================

Supported chips:
  * National Semiconductor LM85 (B and C versions)
    Prefix: 'lm85'
    Addresses scanned: I2C 0x2c, 0x2d, 0x2e
    Datasheet: http://www.national.com/pf/LM/LM85.html
  * Analog Devices ADM1027
    Prefix: 'adm1027'
    Addresses scanned: I2C 0x2c, 0x2d, 0x2e
    Datasheet: http://www.onsemi.com/PowerSolutions/product.do?id=ADM1027
  * Analog Devices ADT7463
    Prefix: 'adt7463'
    Addresses scanned: I2C 0x2c, 0x2d, 0x2e
    Datasheet: http://www.onsemi.com/PowerSolutions/product.do?id=ADT7463
  * Analog Devices ADT7468
    Prefix: 'adt7468'
    Addresses scanned: I2C 0x2c, 0x2d, 0x2e
    Datasheet: http://www.onsemi.com/PowerSolutions/product.do?id=ADT7468
  * SMSC EMC6D100, SMSC EMC6D101
    Prefix: 'emc6d100'
    Addresses scanned: I2C 0x2c, 0x2d, 0x2e
    Datasheet: http://www.smsc.com/media/Downloads_Public/discontinued/6d100.pdf 
  * SMSC EMC6D102
    Prefix: 'emc6d102'
    Addresses scanned: I2C 0x2c, 0x2d, 0x2e
    Datasheet: http://www.smsc.com/main/catalog/emc6d102.html
  * SMSC EMC6D103
    Prefix: 'emc6d103'
    Addresses scanned: I2C 0x2c, 0x2d, 0x2e
    Datasheet: http://www.smsc.com/main/catalog/emc6d103.html
  * SMSC EMC6D103S
    Prefix: 'emc6d103s'
    Addresses scanned: I2C 0x2c, 0x2d, 0x2e
    Datasheet: http://www.smsc.com/main/catalog/emc6d103s.html

Authors:
        Philip Pokorny <ppokorny@penguincomputing.com>,
        Frodo Looijaard <frodol@dds.nl>,
        Richard Barrington <rich_b_nz@clear.net.nz>,
        Margit Schubert-While <margitsw@t-online.de>,
        Justin Thiessen <jthiessen@penguincomputing.com>

Description
-----------

This driver implements support for the National Semiconductor LM85 and
compatible chips including the Analog Devices ADM1027, ADT7463, ADT7468 and
SMSC EMC6D10x chips family.

The LM85 uses the 2-wire interface compatible with the SMBUS 2.0
specification. Using an analog to digital converter it measures three (3)
temperatures and five (5) voltages. It has four (4) 16-bit counters for
measuring fan speed. Five (5) digital inputs are provided for sampling the
VID signals from the processor to the VRM. Lastly, there are three (3) PWM
outputs that can be used to control fan speed.

The voltage inputs have internal scaling resistors so that the following
voltage can be measured without external resistors:

  2.5V, 3.3V, 5V, 12V, and CPU core voltage (2.25V)

The temperatures measured are one internal diode, and two remote diodes.
Remote 1 is generally the CPU temperature. These inputs are designed to
measure a thermal diode like the one in a Pentium 4 processor in a socket
423 or socket 478 package. They can also measure temperature using a
transistor like the 2N3904.

A sophisticated control system for the PWM outputs is designed into the
LM85 that allows fan speed to be adjusted automatically based on any of the
three temperature sensors. Each PWM output is individually adjustable and
programmable. Once configured, the LM85 will adjust the PWM outputs in
response to the measured temperatures without further host intervention.
This feature can also be disabled for manual control of the PWM's.

Each of the measured inputs (voltage, temperature, fan speed) has
corresponding high/low limit values. The LM85 will signal an ALARM if any
measured value exceeds either limit.

The LM85 samples all inputs continuously. The lm85 driver will not read
the registers more often than once a second. Further, configuration data is
only read once each 5 minutes. There is twice as much config data as
measurements, so this would seem to be a worthwhile optimization.

Special Features
----------------

The LM85 has four fan speed monitoring modes. The ADM1027 has only two.
Both have special circuitry to compensate for PWM interactions with the
TACH signal from the fans. The ADM1027 can be configured to measure the
speed of a two wire fan, but the input conditioning circuitry is different
for 3-wire and 2-wire mode. For this reason, the 2-wire fan modes are not
exposed to user control. The BIOS should initialize them to the correct
mode. If you've designed your own ADM1027, you'll have to modify the
init_client function and add an insmod parameter to set this up.

To smooth the response of fans to changes in temperature, the LM85 has an
optional filter for smoothing temperatures. The ADM1027 has the same
config option but uses it to rate limit the changes to fan speed instead.

The ADM1027, ADT7463 and ADT7468 have a 10-bit ADC and can therefore
measure temperatures with 0.25 degC resolution. They also provide an offset
to the temperature readings that is automatically applied during
measurement. This offset can be used to zero out any errors due to traces
and placement. The documentation says that the offset is in 0.25 degC
steps, but in initial testing of the ADM1027 it was 1.00 degC steps. Analog
Devices has confirmed this "bug". The ADT7463 is reported to work as
described in the documentation. The current lm85 driver does not show the
offset register.

The ADT7468 has a high-frequency PWM mode, where all PWM outputs are
driven by a 22.5 kHz clock. This is a global mode, not per-PWM output,
which means that setting any PWM frequency above 11.3 kHz will switch
all 3 PWM outputs to a 22.5 kHz frequency. Conversely, setting any PWM
frequency below 11.3 kHz will switch all 3 PWM outputs to a frequency
between 10 and 100 Hz, which can then be tuned separately.

See the vendor datasheets for more information. There is application note
from National (AN-1260) with some additional information about the LM85.
The Analog Devices datasheet is very detailed and describes a procedure for
determining an optimal configuration for the automatic PWM control.

The SMSC EMC6D100 & EMC6D101 monitor external voltages, temperatures, and
fan speeds. They use this monitoring capability to alert the system to out
of limit conditions and can automatically control the speeds of multiple
fans in a PC or embedded system. The EMC6D101, available in a 24-pin SSOP
package, and the EMC6D100, available in a 28-pin SSOP package, are designed
to be register compatible. The EMC6D100 offers all the features of the
EMC6D101 plus additional voltage monitoring and system control features.
Unfortunately it is not possible to distinguish between the package
versions on register level so these additional voltage inputs may read
zero. EMC6D102 and EMC6D103 feature additional ADC bits thus extending precision
of voltage and temperature channels.

SMSC EMC6D103S is similar to EMC6D103, but does not support pwm#_auto_pwm_minctl
and temp#_auto_temp_off.

Hardware Configurations
-----------------------

The LM85 can be jumpered for 3 different SMBus addresses. There are
no other hardware configuration options for the LM85.

The lm85 driver detects both LM85B and LM85C revisions of the chip. See the
datasheet for a complete description of the differences. Other than
identifying the chip, the driver behaves no differently with regard to
these two chips. The LM85B is recommended for new designs.

The ADM1027, ADT7463 and ADT7468 chips have an optional SMBALERT output
that can be used to signal the chipset in case a limit is exceeded or the
temperature sensors fail. Individual sensor interrupts can be masked so
they won't trigger SMBALERT. The SMBALERT output if configured replaces one
of the other functions (PWM2 or IN0). This functionality is not implemented
in current driver.

The ADT7463 and ADT7468 also have an optional THERM output/input which can
be connected to the processor PROC_HOT output. If available, the autofan
control dynamic Tmin feature can be enabled to keep the system temperature
within spec (just?!) with the least possible fan noise.

Configuration Notes
-------------------

Besides standard interfaces driver adds following:

* Temperatures and Zones

Each temperature sensor is associated with a Zone. There are three
sensors and therefore three zones (# 1, 2 and 3). Each zone has the following
temperature configuration points:

* temp#_auto_temp_off - temperature below which fans should be off or spinning very low.
* temp#_auto_temp_min - temperature over which fans start to spin.
* temp#_auto_temp_max - temperature when fans spin at full speed.
* temp#_auto_temp_crit - temperature when all fans will run full speed.

* PWM Control

There are three PWM outputs. The LM85 datasheet suggests that the
pwm3 output control both fan3 and fan4. Each PWM can be individually
configured and assigned to a zone for its control value. Each PWM can be
configured individually according to the following options.

* pwm#_auto_pwm_min - this specifies the PWM value for temp#_auto_temp_off
                      temperature. (PWM value from 0 to 255)

* pwm#_auto_pwm_minctl - this flags selects for temp#_auto_temp_off temperature
                         the behaviour of fans. Write 1 to let fans spinning at
			 pwm#_auto_pwm_min or write 0 to let them off.

NOTE: It has been reported that there is a bug in the LM85 that causes the flag
to be associated with the zones not the PWMs. This contradicts all the
published documentation. Setting pwm#_min_ctl in this case actually affects all
PWMs controlled by zone '#'.

* PWM Controlling Zone selection

* pwm#_auto_channels - controls zone that is associated with PWM

Configuration choices:

   Value     Meaning
  ------  ------------------------------------------------
      1    Controlled by Zone 1
      2    Controlled by Zone 2
      3    Controlled by Zone 3
     23    Controlled by higher temp of Zone 2 or 3
    123    Controlled by highest temp of Zone 1, 2 or 3
      0    PWM always 0%  (off)
     -1    PWM always 100%  (full on)
     -2    Manual control (write to 'pwm#' to set)

The National LM85's have two vendor specific configuration
features. Tach. mode and Spinup Control. For more details on these,
see the LM85 datasheet or Application Note AN-1260. These features
are not currently supported by the lm85 driver.

The Analog Devices ADM1027 has several vendor specific enhancements.
The number of pulses-per-rev of the fans can be set, Tach monitoring
can be optimized for PWM operation, and an offset can be applied to
the temperatures to compensate for systemic errors in the
measurements. These features are not currently supported by the lm85
driver.

In addition to the ADM1027 features, the ADT7463 and ADT7468 also have
Tmin control and THERM asserted counts. Automatic Tmin control acts to
adjust the Tmin value to maintain the measured temperature sensor at a
specified temperature. There isn't much documentation on this feature in
the ADT7463 data sheet. This is not supported by current driver.
'n722' href='#n722'>722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853
// SPDX-License-Identifier: GPL-2.0-only
/*
 * jump label support
 *
 * Copyright (C) 2009 Jason Baron <jbaron@redhat.com>
 * Copyright (C) 2011 Peter Zijlstra
 *
 */
#include <linux/memory.h>
#include <linux/uaccess.h>
#include <linux/module.h>
#include <linux/list.h>
#include <linux/slab.h>
#include <linux/sort.h>
#include <linux/err.h>
#include <linux/static_key.h>
#include <linux/jump_label_ratelimit.h>
#include <linux/bug.h>
#include <linux/cpu.h>
#include <asm/sections.h>

/* mutex to protect coming/going of the jump_label table */
static DEFINE_MUTEX(jump_label_mutex);

void jump_label_lock(void)
{
	mutex_lock(&jump_label_mutex);
}

void jump_label_unlock(void)
{
	mutex_unlock(&jump_label_mutex);
}

static int jump_label_cmp(const void *a, const void *b)
{
	const struct jump_entry *jea = a;
	const struct jump_entry *jeb = b;

	/*
	 * Entrires are sorted by key.
	 */
	if (jump_entry_key(jea) < jump_entry_key(jeb))
		return -1;

	if (jump_entry_key(jea) > jump_entry_key(jeb))
		return 1;

	/*
	 * In the batching mode, entries should also be sorted by the code
	 * inside the already sorted list of entries, enabling a bsearch in
	 * the vector.
	 */
	if (jump_entry_code(jea) < jump_entry_code(jeb))
		return -1;

	if (jump_entry_code(jea) > jump_entry_code(jeb))
		return 1;

	return 0;
}

static void jump_label_swap(void *a, void *b, int size)
{
	long delta = (unsigned long)a - (unsigned long)b;
	struct jump_entry *jea = a;
	struct jump_entry *jeb = b;
	struct jump_entry tmp = *jea;

	jea->code	= jeb->code - delta;
	jea->target	= jeb->target - delta;
	jea->key	= jeb->key - delta;

	jeb->code	= tmp.code + delta;
	jeb->target	= tmp.target + delta;
	jeb->key	= tmp.key + delta;
}

static void
jump_label_sort_entries(struct jump_entry *start, struct jump_entry *stop)
{
	unsigned long size;
	void *swapfn = NULL;

	if (IS_ENABLED(CONFIG_HAVE_ARCH_JUMP_LABEL_RELATIVE))
		swapfn = jump_label_swap;

	size = (((unsigned long)stop - (unsigned long)start)
					/ sizeof(struct jump_entry));
	sort(start, size, sizeof(struct jump_entry), jump_label_cmp, swapfn);
}

static void jump_label_update(struct static_key *key);

/*
 * There are similar definitions for the !CONFIG_JUMP_LABEL case in jump_label.h.
 * The use of 'atomic_read()' requires atomic.h and its problematic for some
 * kernel headers such as kernel.h and others. Since static_key_count() is not
 * used in the branch statements as it is for the !CONFIG_JUMP_LABEL case its ok
 * to have it be a function here. Similarly, for 'static_key_enable()' and
 * 'static_key_disable()', which require bug.h. This should allow jump_label.h
 * to be included from most/all places for CONFIG_JUMP_LABEL.
 */
int static_key_count(struct static_key *key)
{
	/*
	 * -1 means the first static_key_slow_inc() is in progress.
	 *  static_key_enabled() must return true, so return 1 here.
	 */
	int n = atomic_read(&key->enabled);

	return n >= 0 ? n : 1;
}
EXPORT_SYMBOL_GPL(static_key_count);

void static_key_slow_inc_cpuslocked(struct static_key *key)
{
	int v, v1;

	STATIC_KEY_CHECK_USE(key);
	lockdep_assert_cpus_held();

	/*
	 * Careful if we get concurrent static_key_slow_inc() calls;
	 * later calls must wait for the first one to _finish_ the
	 * jump_label_update() process.  At the same time, however,
	 * the jump_label_update() call below wants to see
	 * static_key_enabled(&key) for jumps to be updated properly.
	 *
	 * So give a special meaning to negative key->enabled: it sends
	 * static_key_slow_inc() down the slow path, and it is non-zero
	 * so it counts as "enabled" in jump_label_update().  Note that
	 * atomic_inc_unless_negative() checks >= 0, so roll our own.
	 */
	for (v = atomic_read(&key->enabled); v > 0; v = v1) {
		v1 = atomic_cmpxchg(&key->enabled, v, v + 1);
		if (likely(v1 == v))
			return;
	}

	jump_label_lock();
	if (atomic_read(&key->enabled) == 0) {
		atomic_set(&key->enabled, -1);
		jump_label_update(key);
		/*
		 * Ensure that if the above cmpxchg loop observes our positive
		 * value, it must also observe all the text changes.
		 */
		atomic_set_release(&key->enabled, 1);
	} else {
		atomic_inc(&key->enabled);
	}
	jump_label_unlock();
}

void static_key_slow_inc(struct static_key *key)
{
	cpus_read_lock();
	static_key_slow_inc_cpuslocked(key);
	cpus_read_unlock();
}
EXPORT_SYMBOL_GPL(static_key_slow_inc);

void static_key_enable_cpuslocked(struct static_key *key)
{
	STATIC_KEY_CHECK_USE(key);
	lockdep_assert_cpus_held();

	if (atomic_read(&key->enabled) > 0) {
		WARN_ON_ONCE(atomic_read(&key->enabled) != 1);
		return;
	}

	jump_label_lock();
	if (atomic_read(&key->enabled) == 0) {
		atomic_set(&key->enabled, -1);
		jump_label_update(key);
		/*
		 * See static_key_slow_inc().
		 */
		atomic_set_release(&key->enabled, 1);
	}
	jump_label_unlock();
}
EXPORT_SYMBOL_GPL(static_key_enable_cpuslocked);

void static_key_enable(struct static_key *key)
{
	cpus_read_lock();
	static_key_enable_cpuslocked(key);
	cpus_read_unlock();
}
EXPORT_SYMBOL_GPL(static_key_enable);

void static_key_disable_cpuslocked(struct static_key *key)
{
	STATIC_KEY_CHECK_USE(key);
	lockdep_assert_cpus_held();

	if (atomic_read(&key->enabled) != 1) {
		WARN_ON_ONCE(atomic_read(&am