1
0
Fork 0
Commit Graph

95 Commits (310ca162d779efee8a2dc3731439680f3e9c1e86)

Author SHA1 Message Date
Guenter Roeck 0599682b82 hwmon: (nct6775) Add support for NCT6798D
NCT6798D is, with the exception of fan and pwm channel configuration
registers, similar to other chips of the series. One interesting
difference is the chip ID, which is now extended to 13 bit (the 12-bit
chip ID value overlaps with the chip ID of NCT6797D).

Signed-off-by: Guenter Roeck <linux@roeck-us.net>
2018-10-10 20:37:13 -07:00
Guenter Roeck e41da286a2 hwmon: (nct6775) Add support for NCT6797D
Add support for NCT6797D. With the exception of fan/pwm configuration
registers, it is mostly compatible with NCT6795D.

Signed-off-by: Guenter Roeck <linux@roeck-us.net>
2018-10-10 20:37:13 -07:00
Guenter Roeck 3be8c9d103 hwmon: (nct6775) Fix names of DIMM temperature sources
For NCT6795D and NCT6796D, the DIMM temperature sources are named
"Agent[01] Dimm [01]" per datasheet. Match names in datasheets to
avoid confusion.

Signed-off-by: Guenter Roeck <linux@roeck-us.net>
2018-10-10 20:37:13 -07:00
Guenter Roeck 3fdb06aff5 hwmon: (nct6796) Clean up and amend fan/pwm configuration for NCT6796D
Now that everything is separated, clean up fan and pwm configuration
for NCT6796D. While doing that, take the forgotten configuration register
cre0 into account to determine if AUXFANIN2 (fan5) and AUXFANOUT2 (pwm5)
are connected.

Signed-off-by: Guenter Roeck <linux@roeck-us.net>
2018-10-10 20:37:13 -07:00
Guenter Roeck b75a806389 hwmon: (nct6775) Separate fan/pwm configuration detection for NCT6795D
Separate fan/pwm configuration detection for NCT6795D into separate
case statement to make the code easier to read.

No functional change.

Signed-off-by: Guenter Roeck <linux@roeck-us.net>
2018-10-10 20:37:13 -07:00
Guenter Roeck 2d99925a15 hwmon: (nct6775) Separate fan/pwm configuration detection for NCT6793D
While detecting the configuration for multiple chips in one go reduces
code size, it also increases code complexity. Separate chip detection
to improve code readability. As first step, separate detection for
NCT6793D.

No functional change.

Signed-off-by: Guenter Roeck <linux@roeck-us.net>
2018-10-10 20:37:13 -07:00
Guenter Roeck 7dcdbdeb1b hwmon: (nct6775) Fix fan6/pwm6 detection for NCT6792D
Per datasheet, AUXFANIN3 (fan6) and AUXFANOUT3 (pwm6) are only connected
if DSW_EN is false.

Signed-off-by: Guenter Roeck <linux@roeck-us.net>
2018-10-10 20:37:13 -07:00
Guenter Roeck b2833f397d hwmon: (nct6775) Improve instruction grouping
When determining support for a given fan or pwm control, the code is
easier to read if the necessary instructions are grouped together.

No functional change.

Signed-off-by: Guenter Roeck <linux@roeck-us.net>
2018-10-10 20:37:13 -07:00
Guenter Roeck a4e0a080ca hwmon: (nct6775) Use logical or instead of if statements where possible
Use
	boolean |= <expression>;
instead of
	if (!boolean)
		boolean = <expression>;
to assign values to boolean variables.

No functional change.

Signed-off-by: Guenter Roeck <linux@roeck-us.net>
2018-10-10 20:37:13 -07:00
Guenter Roeck 2d888c5f22 hwmon: (nct6775) Declare and initialize LDN specific config variables earlier
Declare and initialize LDN / chip specific configuration variables
earlier. This simplifies re-using the configuration variables for
multiple chips and makes the code easier to read.

Signed-off-by: Guenter Roeck <linux@roeck-us.net>
2018-10-10 20:37:13 -07:00
Guenter Roeck 97ce6df468 hwmon: (nct6775) Move config variable declarations and initializations
Group configuration variable declarations and initialization together.
While this results in reading more registers than necessary for a given
chip, it improves code readability and simplifies extending the code.

Signed-off-by: Guenter Roeck <linux@roeck-us.net>
2018-10-10 20:37:13 -07:00
Guenter Roeck a6c54f2cde hwmon: (nct6775) Replace 'regval' with variables named after config registers
Using variables named after configuration registers makes it more obvious
which configuration register value is used, especially if more than one
configuration register value is used to determine a configuration detail.

No functional change.

Signed-off-by: Guenter Roeck <linux@roeck-us.net>
2018-10-10 20:37:13 -07:00
Guenter Roeck 0085a5108d hwmon: (nct6775) Rename configuration register variables
Use variable names from chip datasheets (crXX) instead of regval_XX
for configuration register variables. This is shorter and, together
with subsequent changes, makes the code easier to read.

No functional change.

Signed-off-by: Guenter Roeck <linux@roeck-us.net>
2018-10-10 20:37:13 -07:00
Guenter Roeck 61b6c66a8f hwmon: (nct6775) Only display fan speed tolerance conditionally
A fan speed tolerance only makes sense if a fan target speed has been
configured in the first place. Otherwise we get odd output such as

fan1_target:0
fan1_tolerance:337500

Only display values other than 0 if a fan target speed has been configured.

Signed-off-by: Guenter Roeck <linux@roeck-us.net>
2018-10-10 20:37:13 -07:00
Dan Carpenter c3bf6076cc hwmon: (nct6775) Clean up a condition
I removed the "dsw_en &&" chunk of the condition because we know that
"dsw_en" is set.

Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
2018-10-10 20:37:13 -07:00
Guenter Roeck 5506635428 hwmon: (nct6775) Use different register to get fan RPM for fan7
The documented register to retrieve the fan RPM for fan7 is found
to be unreliable at least with NCT6796D revision 3. Let's use
register 0x4ce instead. This is undocumented for NCT6796D, but
documented for NCT6797D and NCT6798D and known to be working.

Reported-by: Robert Kern <ulteq@web.de>
Cc: Robert Kern <ulteq@web.de>
Fixes: 81820059a4 ("hwmon: (nct6775) Add support for NCT6796D")
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
2018-09-17 05:38:50 -07:00
Guenter Roeck f6de298806 hwmon: (nct6775) Fix RPM output for fan7 on NCT6796D
fan7 on NCT6796D does not have a fan count register; it only has an RPM
register. Switch to using RPM registers to read the fan speed for all
chips supporting it to solve the problem for good.

Reported-by: Robert Kern <ulteq@web.de>
Cc: Robert Kern <ulteq@web.de>
Fixes: 81820059a4 ("hwmon: (nct6775) Add support for NCT6796D")
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
2018-09-15 16:18:44 -07:00
Guenter Roeck 37196ba4ae hwmon: (nct6775) Fix virtual temperature sources for NCT6796D
The following kernel log message is reported for the nct6775 driver
on ASUS WS X299 SAGE.

nct6775: Found NCT6796D or compatible chip at 0x2e:0x290
nct6775 nct6775.656: Invalid temperature source 11 at index 0,
			source register 0x100, temp register 0x73
nct6775 nct6775.656: Invalid temperature source 11 at index 2,
			source register 0x300, temp register 0x77
nct6775 nct6775.656: Invalid temperature source 11 at index 3,
			source register 0x800, temp register 0x79
nct6775 nct6775.656: Invalid temperature source 11 at index 4,
			source register 0x900, temp register 0x7b

A recent version of the datasheet lists temperature source 11 as reserved.
However, an older version of the datasheet lists temperature sources 10
and 11 as supported virtual temperature sources. Apparently the older
version of the datasheet is correct, so list those temperature sources
as supported.

Virtual temperature sources are different than other temperature sources:
Values are not read from a temperature sensor, but written either from
BIOS or an embedded controller. As such, each virtual temperature has to
be reported. Since there is now more than one temperature source, we have
to keep virtual temperature sources in a chip-specific mask and can no
longer rely on the assumption that there is only one virtual temperature
source with a fixed index. This accounts for most of the complexity of this
patch.

Reported-by: Robert Kern <ulteq@web.de>
Cc: Robert Kern <ulteq@web.de>
Fixes: 81820059a4 ("hwmon: (nct6775) Add support for NCT6796D")
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
2018-09-15 07:42:07 -07:00
Guenter Roeck c793279c77 hwmon: (nct6775) Fix access to fan pulse registers
Not all fans have a fan pulse register. This can result in reading
beyond the end of REG_FAN_PULSES and FAN_PULSE_SHIFT arrays,
and was reported by smatch as possible error.

1672          for (i = 0; i < ARRAY_SIZE(data->rpm); i++) {
                              ^^^^^^^^^^^^^^^^^^^^^^^^
			      This is a 7 element array.
...
1685                  data->fan_pulses[i] =
1686                    (nct6775_read_value(data, data->REG_FAN_PULSES[i])
1687                          >> data->FAN_PULSE_SHIFT[i]) & 0x03;
                                 ^^^^^^^^^^^^^^^^^^^^^^^^
				 FAN_PULSE_SHIFT is either 5 or 6
				 elements.

To fix the problem, we have to ensure that all REG_FAN_PULSES and
FAN_PULSE_SHIFT have the appropriate length, and that REG_FAN_PULSES
is only read if the register actually exists.

Fixes: 6c009501ff ("hwmon: (nct6775) Add support for NCT6102D/6106D")
Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
2018-09-07 09:33:36 -07:00
Dan Carpenter e3f3d7ab00 hwmon: (nct6775) Set weight source to zero correctly
This is dead code because j can never be 1 at this point.  We had
intended to just test if the bit was clear.

Fixes: bbd8decd41 ("hwmon: (nct6775) Add support for weighted fan control")
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
2018-09-05 14:47:50 -07:00
Gustavo A. R. Silva d49dbfade9 hwmon: (nct6775) Fix potential Spectre v1
val can be indirectly controlled by user-space, hence leading to
a potential exploitation of the Spectre variant 1 vulnerability.

This issue was detected with the help of Smatch:

vers/hwmon/nct6775.c:2698 store_pwm_weight_temp_sel() warn: potential
spectre issue 'data->temp_src' [r]

Fix this by sanitizing val before using it to index data->temp_src

Notice that given that speculation windows are large, the policy is
to kill the speculation on the first load and not worry if it can be
completed with a dependent load/store [1].

[1] https://marc.info/?l=linux-kernel&m=152449131114778&w=2

Cc: stable@vger.kernel.org
Signed-off-by: Gustavo A. R. Silva <gustavo@embeddedor.com>
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
2018-08-26 17:45:25 -07:00
Gustavo A. R. Silva ffb3243245 hwmon: Mark expected switch fall-throughs
In preparation to enabling -Wimplicit-fallthrough, mark switch cases
where we are expecting to fall through.

Signed-off-by: Gustavo A. R. Silva <gustavo@embeddedor.com>
Reviewed-by: Jean Delvare <jdelvare@suse.de>
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
2018-07-08 20:08:13 -07:00
Guenter Roeck 57fec3acb4 hwmon: (nct6775) Fix comment in the description of pwm_mode
Commit 415eb2a1aa ("hwmon: (nct6775) Fix writing pwmX_mode") changed
the definition of the pwm_mode variable, but did not update the comment
describing it.

Reported-by: Ben Hutchings <ben.hutchings@codethink.co.uk>
Cc: Ben Hutchings <ben.hutchings@codethink.co.uk>
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
2018-07-08 20:08:13 -07:00
Guenter Roeck 91bb8f45f7 hwmon: (nct6775) Fix loop limit
Commit cc66b30382 ("hwmon: (nct6775) Rework temperature source and label
handling") changed a loop limit from "data->temp_label_num - 1" to "32",
as part of moving from a string array to a bit mask. This results in the
following error, reported by UBSAN.

UBSAN: Undefined behaviour in drivers/hwmon/nct6775.c:4179:27
shift exponent 32 is too large for 32-bit type 'long unsigned int'

Similar to the original loop, the limit has to be one less than the
number of bits.

Fixes: cc66b30382 ("hwmon: (nct6775) Rework temperature source and label handling")
Reported-by: Paul Menzel <pmenzel+linux-hwmon@molgen.mpg.de>
Cc: Paul Menzel <pmenzel+linux-hwmon@molgen.mpg.de>
Tested-by: Paul Menzel <pmenzel+linux-hwmon@molgen.mpg.de>
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
2018-06-16 16:40:36 -07:00
Kees Cook a86854d0c5 treewide: devm_kzalloc() -> devm_kcalloc()
The devm_kzalloc() function has a 2-factor argument form, devm_kcalloc().
This patch replaces cases of:

        devm_kzalloc(handle, a * b, gfp)

with:
        devm_kcalloc(handle, a * b, gfp)

as well as handling cases of:

        devm_kzalloc(handle, a * b * c, gfp)

with:

        devm_kzalloc(handle, array3_size(a, b, c), gfp)

as it's slightly less ugly than:

        devm_kcalloc(handle, array_size(a, b), c, gfp)

This does, however, attempt to ignore constant size factors like:

        devm_kzalloc(handle, 4 * 1024, gfp)

though any constants defined via macros get caught up in the conversion.

Any factors with a sizeof() of "unsigned char", "char", and "u8" were
dropped, since they're redundant.

Some manual whitespace fixes were needed in this patch, as Coccinelle
really liked to write "=devm_kcalloc..." instead of "= devm_kcalloc...".

The Coccinelle script used for this was:

// Fix redundant parens around sizeof().
@@
expression HANDLE;
type TYPE;
expression THING, E;
@@

(
  devm_kzalloc(HANDLE,
-	(sizeof(TYPE)) * E
+	sizeof(TYPE) * E
  , ...)
|
  devm_kzalloc(HANDLE,
-	(sizeof(THING)) * E
+	sizeof(THING) * E
  , ...)
)

// Drop single-byte sizes and redundant parens.
@@
expression HANDLE;
expression COUNT;
typedef u8;
typedef __u8;
@@

(
  devm_kzalloc(HANDLE,
-	sizeof(u8) * (COUNT)
+	COUNT
  , ...)
|
  devm_kzalloc(HANDLE,
-	sizeof(__u8) * (COUNT)
+	COUNT
  , ...)
|
  devm_kzalloc(HANDLE,
-	sizeof(char) * (COUNT)
+	COUNT
  , ...)
|
  devm_kzalloc(HANDLE,
-	sizeof(unsigned char) * (COUNT)
+	COUNT
  , ...)
|
  devm_kzalloc(HANDLE,
-	sizeof(u8) * COUNT
+	COUNT
  , ...)
|
  devm_kzalloc(HANDLE,
-	sizeof(__u8) * COUNT
+	COUNT
  , ...)
|
  devm_kzalloc(HANDLE,
-	sizeof(char) * COUNT
+	COUNT
  , ...)
|
  devm_kzalloc(HANDLE,
-	sizeof(unsigned char) * COUNT
+	COUNT
  , ...)
)

// 2-factor product with sizeof(type/expression) and identifier or constant.
@@
expression HANDLE;
type TYPE;
expression THING;
identifier COUNT_ID;
constant COUNT_CONST;
@@

(
- devm_kzalloc
+ devm_kcalloc
  (HANDLE,
-	sizeof(TYPE) * (COUNT_ID)
+	COUNT_ID, sizeof(TYPE)
  , ...)
|
- devm_kzalloc
+ devm_kcalloc
  (HANDLE,
-	sizeof(TYPE) * COUNT_ID
+	COUNT_ID, sizeof(TYPE)
  , ...)
|
- devm_kzalloc
+ devm_kcalloc
  (HANDLE,
-	sizeof(TYPE) * (COUNT_CONST)
+	COUNT_CONST, sizeof(TYPE)
  , ...)
|
- devm_kzalloc
+ devm_kcalloc
  (HANDLE,
-	sizeof(TYPE) * COUNT_CONST
+	COUNT_CONST, sizeof(TYPE)
  , ...)
|
- devm_kzalloc
+ devm_kcalloc
  (HANDLE,
-	sizeof(THING) * (COUNT_ID)
+	COUNT_ID, sizeof(THING)
  , ...)
|
- devm_kzalloc
+ devm_kcalloc
  (HANDLE,
-	sizeof(THING) * COUNT_ID
+	COUNT_ID, sizeof(THING)
  , ...)
|
- devm_kzalloc
+ devm_kcalloc
  (HANDLE,
-	sizeof(THING) * (COUNT_CONST)
+	COUNT_CONST, sizeof(THING)
  , ...)
|
- devm_kzalloc
+ devm_kcalloc
  (HANDLE,
-	sizeof(THING) * COUNT_CONST
+	COUNT_CONST, sizeof(THING)
  , ...)
)

// 2-factor product, only identifiers.
@@
expression HANDLE;
identifier SIZE, COUNT;
@@

- devm_kzalloc
+ devm_kcalloc
  (HANDLE,
-	SIZE * COUNT
+	COUNT, SIZE
  , ...)

// 3-factor product with 1 sizeof(type) or sizeof(expression), with
// redundant parens removed.
@@
expression HANDLE;
expression THING;
identifier STRIDE, COUNT;
type TYPE;
@@

(
  devm_kzalloc(HANDLE,
-	sizeof(TYPE) * (COUNT) * (STRIDE)
+	array3_size(COUNT, STRIDE, sizeof(TYPE))
  , ...)
|
  devm_kzalloc(HANDLE,
-	sizeof(TYPE) * (COUNT) * STRIDE
+	array3_size(COUNT, STRIDE, sizeof(TYPE))
  , ...)
|
  devm_kzalloc(HANDLE,
-	sizeof(TYPE) * COUNT * (STRIDE)
+	array3_size(COUNT, STRIDE, sizeof(TYPE))
  , ...)
|
  devm_kzalloc(HANDLE,
-	sizeof(TYPE) * COUNT * STRIDE
+	array3_size(COUNT, STRIDE, sizeof(TYPE))
  , ...)
|
  devm_kzalloc(HANDLE,
-	sizeof(THING) * (COUNT) * (STRIDE)
+	array3_size(COUNT, STRIDE, sizeof(THING))
  , ...)
|
  devm_kzalloc(HANDLE,
-	sizeof(THING) * (COUNT) * STRIDE
+	array3_size(COUNT, STRIDE, sizeof(THING))
  , ...)
|
  devm_kzalloc(HANDLE,
-	sizeof(THING) * COUNT * (STRIDE)
+	array3_size(COUNT, STRIDE, sizeof(THING))
  , ...)
|
  devm_kzalloc(HANDLE,
-	sizeof(THING) * COUNT * STRIDE
+	array3_size(COUNT, STRIDE, sizeof(THING))
  , ...)
)

// 3-factor product with 2 sizeof(variable), with redundant parens removed.
@@
expression HANDLE;
expression THING1, THING2;
identifier COUNT;
type TYPE1, TYPE2;
@@

(
  devm_kzalloc(HANDLE,
-	sizeof(TYPE1) * sizeof(TYPE2) * COUNT
+	array3_size(COUNT, sizeof(TYPE1), sizeof(TYPE2))
  , ...)
|
  devm_kzalloc(HANDLE,
-	sizeof(TYPE1) * sizeof(THING2) * (COUNT)
+	array3_size(COUNT, sizeof(TYPE1), sizeof(TYPE2))
  , ...)
|
  devm_kzalloc(HANDLE,
-	sizeof(THING1) * sizeof(THING2) * COUNT
+	array3_size(COUNT, sizeof(THING1), sizeof(THING2))
  , ...)
|
  devm_kzalloc(HANDLE,
-	sizeof(THING1) * sizeof(THING2) * (COUNT)
+	array3_size(COUNT, sizeof(THING1), sizeof(THING2))
  , ...)
|
  devm_kzalloc(HANDLE,
-	sizeof(TYPE1) * sizeof(THING2) * COUNT
+	array3_size(COUNT, sizeof(TYPE1), sizeof(THING2))
  , ...)
|
  devm_kzalloc(HANDLE,
-	sizeof(TYPE1) * sizeof(THING2) * (COUNT)
+	array3_size(COUNT, sizeof(TYPE1), sizeof(THING2))
  , ...)
)

// 3-factor product, only identifiers, with redundant parens removed.
@@
expression HANDLE;
identifier STRIDE, SIZE, COUNT;
@@

(
  devm_kzalloc(HANDLE,
-	(COUNT) * STRIDE * SIZE
+	array3_size(COUNT, STRIDE, SIZE)
  , ...)
|
  devm_kzalloc(HANDLE,
-	COUNT * (STRIDE) * SIZE
+	array3_size(COUNT, STRIDE, SIZE)
  , ...)
|
  devm_kzalloc(HANDLE,
-	COUNT * STRIDE * (SIZE)
+	array3_size(COUNT, STRIDE, SIZE)
  , ...)
|
  devm_kzalloc(HANDLE,
-	(COUNT) * (STRIDE) * SIZE
+	array3_size(COUNT, STRIDE, SIZE)
  , ...)
|
  devm_kzalloc(HANDLE,
-	COUNT * (STRIDE) * (SIZE)
+	array3_size(COUNT, STRIDE, SIZE)
  , ...)
|
  devm_kzalloc(HANDLE,
-	(COUNT) * STRIDE * (SIZE)
+	array3_size(COUNT, STRIDE, SIZE)
  , ...)
|
  devm_kzalloc(HANDLE,
-	(COUNT) * (STRIDE) * (SIZE)
+	array3_size(COUNT, STRIDE, SIZE)
  , ...)
|
  devm_kzalloc(HANDLE,
-	COUNT * STRIDE * SIZE
+	array3_size(COUNT, STRIDE, SIZE)
  , ...)
)

// Any remaining multi-factor products, first at least 3-factor products,
// when they're not all constants...
@@
expression HANDLE;
expression E1, E2, E3;
constant C1, C2, C3;
@@

(
  devm_kzalloc(HANDLE, C1 * C2 * C3, ...)
|
  devm_kzalloc(HANDLE,
-	(E1) * E2 * E3
+	array3_size(E1, E2, E3)
  , ...)
|
  devm_kzalloc(HANDLE,
-	(E1) * (E2) * E3
+	array3_size(E1, E2, E3)
  , ...)
|
  devm_kzalloc(HANDLE,
-	(E1) * (E2) * (E3)
+	array3_size(E1, E2, E3)
  , ...)
|
  devm_kzalloc(HANDLE,
-	E1 * E2 * E3
+	array3_size(E1, E2, E3)
  , ...)
)

// And then all remaining 2 factors products when they're not all constants,
// keeping sizeof() as the second factor argument.
@@
expression HANDLE;
expression THING, E1, E2;
type TYPE;
constant C1, C2, C3;
@@

(
  devm_kzalloc(HANDLE, sizeof(THING) * C2, ...)
|
  devm_kzalloc(HANDLE, sizeof(TYPE) * C2, ...)
|
  devm_kzalloc(HANDLE, C1 * C2 * C3, ...)
|
  devm_kzalloc(HANDLE, C1 * C2, ...)
|
- devm_kzalloc
+ devm_kcalloc
  (HANDLE,
-	sizeof(TYPE) * (E2)
+	E2, sizeof(TYPE)
  , ...)
|
- devm_kzalloc
+ devm_kcalloc
  (HANDLE,
-	sizeof(TYPE) * E2
+	E2, sizeof(TYPE)
  , ...)
|
- devm_kzalloc
+ devm_kcalloc
  (HANDLE,
-	sizeof(THING) * (E2)
+	E2, sizeof(THING)
  , ...)
|
- devm_kzalloc
+ devm_kcalloc
  (HANDLE,
-	sizeof(THING) * E2
+	E2, sizeof(THING)
  , ...)
|
- devm_kzalloc
+ devm_kcalloc
  (HANDLE,
-	(E1) * E2
+	E1, E2
  , ...)
|
- devm_kzalloc
+ devm_kcalloc
  (HANDLE,
-	(E1) * (E2)
+	E1, E2
  , ...)
|
- devm_kzalloc
+ devm_kcalloc
  (HANDLE,
-	E1 * E2
+	E1, E2
  , ...)
)

Signed-off-by: Kees Cook <keescook@chromium.org>
2018-06-12 16:19:22 -07:00
Guenter Roeck 415eb2a1aa hwmon: (nct6775) Fix writing pwmX_mode
pwmX_mode is defined in the ABI as 0=DC mode, 1=pwm mode. The chip
register bit is set to 1 for DC mode. This got mixed up, and writing
1 into pwmX_mode resulted in DC mode enabled. Fix it up by using
the ABI definition throughout the driver for consistency.

Fixes: 77eb5b3703 ("hwmon: (nct6775) Add support for pwm, pwm_mode, ... ")
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
2018-03-27 08:49:24 -07:00
Guenter Roeck 81820059a4 hwmon: (nct6775) Add support for NCT6796D
NCT6796D is mostly compatible to NCT6795D. It supports an additional
pwm control and fan speed channel.

While we are at it, update documentation for NCT6795D.

Signed-off-by: Guenter Roeck <linux@roeck-us.net>
2018-03-10 19:00:14 -08:00
Guenter Roeck 1b20624090 hwmon: (nct6775) Initialize boolean variables with declaration
Initialize boolean flags in nct6775_check_fan_inputs() while
declaring them instead of several times throughout the code.

Signed-off-by: Guenter Roeck <linux@roeck-us.net>
2018-03-10 19:00:14 -08:00
Guenter Roeck 00fd4cfe5b hwmon: (nct6775) Improve fan6/pwm6 support
Improve fan6/pwm6 detection on NCT6795D. Add support for fan pulses
for fans 4..6 and fan min limits for fan6.

Signed-off-by: Guenter Roeck <linux@roeck-us.net>
2018-03-10 19:00:14 -08:00
Guenter Roeck e2617262f1 hwmon: (nct6775) Use NUM_FAN consistently
The size of some of the arrays using the number of fans is hardcoded.
Use NUM_FAN consistently throughout the driver.

Signed-off-by: Guenter Roeck <linux@roeck-us.net>
2018-03-10 19:00:14 -08:00
Guenter Roeck 419220dc48 hwmon: (nct6775) Add support for NCT6795D
NCT6795D is mostly compatible to NCT6793D with a few minor differences.

Signed-off-by: Guenter Roeck <linux@roeck-us.net>
2017-06-11 17:08:19 -07:00
Guenter Roeck e5c8522110 hwmon: (nct6775) Improve fan detection
Recent chips support multiple pins for fan speed inputs and fan control
outputs. Examine all of them to determine supported fan controls.

Signed-off-by: Guenter Roeck <linux@roeck-us.net>
2017-06-11 17:08:19 -07:00
Guenter Roeck cc66b30382 hwmon: (nct6775) Rework temperature source and label handling
Instead of checking if a temperature source has a label, use a bit mask
to determine if a temperature source is valid for a given chip.
This simplifies the code and, if necessary, lets us support chips with
unknown or incomplete labels.

Signed-off-by: Guenter Roeck <linux@roeck-us.net>
2017-06-11 17:08:19 -07:00
Guenter Roeck d1bb218687 hwmon: (nct6775) Use bitops
Using bitops instead of shift operations makes the code easier to read.

Signed-off-by: Guenter Roeck <linux@roeck-us.net>
2017-06-11 17:08:19 -07:00
Julia Lawall 93d72ac3b6 hwmon: (nct6775) use permission-specific DEVICE_ATTR variants
Use DEVICE_ATTR_RW for read/write attributes. This simplifies the source
code, improves readbility, and reduces the chance of inconsistencies.

The conversion was done automatically using coccinelle. It was validated
by compiling both the old and the new source code and comparing its text,
data, and bss size.

Signed-off-by: Julia Lawall <Julia.Lawall@lip6.fr>
[groeck: Updated description]
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
2017-01-02 10:19:45 -08:00
Guenter Roeck 7ce4190c4c hwmon: (nct6775) Add support for multiple virtual temperature sources
For virtual temperatures, the actual temperature values are written
by software, presumably by the BIOS. This functionality is (as of
right now) supported on NCT6791D, NCT6792D, and NCT6793D. On those chips,
the temperatures are written into registers 0xea..0xef on page 0.
This is known to be used on some Asus motherboards, where the actual
temperature source can be configured in the BIOS.

Report the 'virtual' temperatures for all monotoring sources to address
this situation.

Example for the resulting output (as seen with the 'sensors' command):

nct6791-isa-0290
Adapter: ISA adapter
...
Virtual_TEMP:           +31.0°C
PECI Agent 0:           +38.5°C
Virtual_TEMP:           +32.0°C
...

Signed-off-by: Guenter Roeck <linux@roeck-us.net>
2016-09-18 15:32:35 -07:00
Guenter Roeck fc72af3ad4 hwmon: (nct6775) Do not accept force_id unless chip is found
Since commit 698a7c24a5 ("hwmon: (nct6775) Support two SuperIO chips
in the same system"), the driver supports two Super-IO chips. This has
the undesirable side effect that force_id always detects a second chip
at address 0xfff8, even if no chip exists at that address.

nct6775: Found NCT6793D or compatible chip at 0x4e:0xfff8

If no chip at all is found at a given SIO address, it does not make sense
to instantiate it. Limit force_id to only work if some chip is found,
that is if the chip ID returns a value other than 0xffff.

Reviewed-by: Jean Delvare <jdelvare@suse.de>
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
2016-09-08 21:34:16 -07:00
Julia Lawall c60fdf8587 hwmon: (nct6683,nct6775) constify sensor_template_group structures
The sensor_template_group structures are never modified, so declare them as
const.

Done with the help of Coccinelle.

Signed-off-by: Julia Lawall <Julia.Lawall@lip6.fr>
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
2015-12-18 08:20:59 -08:00
Guenter Roeck 50224f4d09 hwmon: (nct6775) Introduce separate temperature labels for NCT6792 and NCT6793
NCT6792 and NCT6793 are mostly register compatible to NCT6791, but
temperature sources are different and difficult to manage with a single
temperature label array. Introduce separate temperature label arrays
for those chips to reflect the differences.

Signed-off-by: Guenter Roeck <linux@roeck-us.net>
2015-10-30 07:58:58 -07:00
Guenter Roeck 9a38371a8c hwmon: (nct6775) NCT6791D and NCT6792D have an additional temperature source
Both NCT6791D and NCT6792D permit selection of a 'virtual' temperature
register as temperature source. The virtual temperature registers are
registers 0xea to 0xef in bank 0 and can be written by software.

Signed-off-by: Guenter Roeck <linux@roeck-us.net>
2015-10-30 07:35:14 -07:00
Guenter Roeck cd1faefa66 hwmon: (nct6775) Add support for NCT6793D
NCT6793D is register compatible with NCT6792D.

Also move nct6775_sio_names[] closer to enum kinds to simplify
adding new chips.

Tested-by: Grazvydas Ignotas <notasas@gmail.com>
Reviewed-by: Jean Delvare <jdelvare@suse.de>
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
2015-09-12 19:43:02 -07:00
Guenter Roeck 728d294004 hwmon: (nct6775) Swap STEP_UP_TIME and STEP_DOWN_TIME registers for most chips
The STEP_UP_TIME and STEP_DOWN_TIME registers are swapped for all chips but
NCT6775.

Reported-by: Grazvydas Ignotas <notasas@gmail.com>
Reviewed-by: Jean Delvare <jdelvare@suse.de>
Cc: stable@vger.kernel.org # v3.10+
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
2015-09-12 19:43:02 -07:00
Guenter Roeck 1b63bf6172 hwmon: (nct6775) Add missing sysfs attribute initialization
The following error message is seen when loading the nct6775 driver
with DEBUG_LOCK_ALLOC enabled.

BUG: key ffff88040b2f0030 not in .data!
------------[ cut here ]------------
WARNING: CPU: 0 PID: 186 at kernel/locking/lockdep.c:2988
				lockdep_init_map+0x469/0x630()
DEBUG_LOCKS_WARN_ON(1)

Caused by a missing call to sysfs_attr_init() when initializing
sysfs attributes.

Reported-by: Alexey Orishko <alexey.orishko@gmail.com>
Reviewed-by: Jean Delvare <jdelvare@suse.de>
Cc: stable@vger.kernel.org # v3.12+
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
2015-05-29 17:47:33 -07:00
Guenter Roeck 25cdd99deb hwmon: (nct6775) Enable auxiliary fan monitoring on ASRock Z77 Pro4-M
Auxiliary fan monitoring is not enabled on ASRock Z77 Pro4-M
with BIOS version 2.00 if booted in UEFI Ultra-FastBoot mode.

Signed-off-by: Guenter Roeck <linux@roeck-us.net>
2015-03-15 08:54:18 -07:00
Guenter Roeck d2a14ea51a hwmon: (nct6775) Restore hardware monitoring logical device status on resume
After a suspend/resume cycle it is not guaranteed that the hardware monitoring
device is still enabled. Ensure that this is the case after resume.

Signed-off-by: Guenter Roeck <linux@roeck-us.net>
2015-03-15 08:54:12 -07:00
Guenter Roeck 48e9318256 hwmon: (nct6775) Convert to use SIMPLE_DEV_PM_OPS
Get rid of #ifdef CONFIG_PM by using SIMPLE_DEV_PM_OPS and declaring suspend
and resume functions with __maybe_unused.

Signed-off-by: Guenter Roeck <linux@roeck-us.net>
2015-03-15 08:54:05 -07:00
Linus Torvalds e6b5be2be4 Driver core patches for 3.19-rc1
Here's the set of driver core patches for 3.19-rc1.
 
 They are dominated by the removal of the .owner field in platform
 drivers.  They touch a lot of files, but they are "simple" changes, just
 removing a line in a structure.
 
 Other than that, a few minor driver core and debugfs changes.  There are
 some ath9k patches coming in through this tree that have been acked by
 the wireless maintainers as they relied on the debugfs changes.
 
 Everything has been in linux-next for a while.
 
 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
 -----BEGIN PGP SIGNATURE-----
 Version: GnuPG v2
 
 iEYEABECAAYFAlSOD20ACgkQMUfUDdst+ylLPACg2QrW1oHhdTMT9WI8jihlHVRM
 53kAoLeteByQ3iVwWurwwseRPiWa8+MI
 =OVRS
 -----END PGP SIGNATURE-----

Merge tag 'driver-core-3.19-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/driver-core

Pull driver core update from Greg KH:
 "Here's the set of driver core patches for 3.19-rc1.

  They are dominated by the removal of the .owner field in platform
  drivers.  They touch a lot of files, but they are "simple" changes,
  just removing a line in a structure.

  Other than that, a few minor driver core and debugfs changes.  There
  are some ath9k patches coming in through this tree that have been
  acked by the wireless maintainers as they relied on the debugfs
  changes.

  Everything has been in linux-next for a while"

* tag 'driver-core-3.19-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/driver-core: (324 commits)
  Revert "ath: ath9k: use debugfs_create_devm_seqfile() helper for seq_file entries"
  fs: debugfs: add forward declaration for struct device type
  firmware class: Deletion of an unnecessary check before the function call "vunmap"
  firmware loader: fix hung task warning dump
  devcoredump: provide a one-way disable function
  device: Add dev_<level>_once variants
  ath: ath9k: use debugfs_create_devm_seqfile() helper for seq_file entries
  ath: use seq_file api for ath9k debugfs files
  debugfs: add helper function to create device related seq_file
  drivers/base: cacheinfo: remove noisy error boot message
  Revert "core: platform: add warning if driver has no owner"
  drivers: base: support cpu cache information interface to userspace via sysfs
  drivers: base: add cpu_device_create to support per-cpu devices
  topology: replace custom attribute macros with standard DEVICE_ATTR*
  cpumask: factor out show_cpumap into separate helper function
  driver core: Fix unbalanced device reference in drivers_probe
  driver core: fix race with userland in device_add()
  sysfs/kernfs: make read requests on pre-alloc files use the buffer.
  sysfs/kernfs: allow attributes to request write buffer be pre-allocated.
  fs: sysfs: return EGBIG on write if offset is larger than file size
  ...
2014-12-14 16:10:09 -08:00
Guenter Roeck 9cd892bcbe hwmon: (nct6775) Add blank lines after declarations
checkpatch complains about
	WARNING: Missing a blank line after declarations

Add missing blank lines. Also reorder variables length-wise where appropriate
if a function header is touched anyway.

Reviewed-by: Jean Delvare <jdelvare@suse.de>
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
2014-11-30 20:13:14 -08:00
Guenter Roeck 8aefb93f09 hwmon: (nct6775) Add support for NCT6792D
NCT6792D is similar to NCT6791D. Only beep control and temperature
monitoring registers are different.

Reviewed-by: Jean Delvare <jdelvare@suse.de>
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
2014-11-30 20:13:13 -08:00
Wolfram Sang 2a1ed07718 hwmon: drop owner assignment from platform_drivers
A platform_driver does not need to set an owner, it will be populated by the
driver core.

Signed-off-by: Wolfram Sang <wsa@the-dreams.de>
2014-10-20 16:20:36 +02:00