Linux-Hwmon Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH 01/13] hwmon: (nct6775) Rename configuration register variables
@ 2018-09-20 13:45 Guenter Roeck
  2018-09-20 13:45 ` [PATCH 02/13] hwmon: (nct6775) Replace 'regval' with variables named after config registers Guenter Roeck
                   ` (11 more replies)
  0 siblings, 12 replies; 13+ messages in thread
From: Guenter Roeck @ 2018-09-20 13:45 UTC (permalink / raw)
  To: Hardware Monitoring; +Cc: Jean Delvare, Guenter Roeck

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>
---
 drivers/hwmon/nct6775.c | 42 +++++++++++++++++++++---------------------
 1 file changed, 21 insertions(+), 21 deletions(-)

diff --git a/drivers/hwmon/nct6775.c b/drivers/hwmon/nct6775.c
index 2a9fc8c9fb9e..7a3a1d59553e 100644
--- a/drivers/hwmon/nct6775.c
+++ b/drivers/hwmon/nct6775.c
@@ -3497,7 +3497,7 @@ nct6775_check_fan_inputs(struct nct6775_data *data)
 		pwm3pin = regval & 0x08;
 	} else {
 		/* NCT6779D, NCT6791D, NCT6792D, NCT6793D, NCT6795D, NCT6796D */
-		int regval_1b, regval_2a, regval_2f;
+		int cr1b, cr2a, cr2f;
 		bool dsw_en;
 
 		regval = superio_inb(sioreg, 0x1c);
@@ -3520,20 +3520,20 @@ nct6775_check_fan_inputs(struct nct6775_data *data)
 		case nct6793:
 		case nct6795:
 		case nct6796:
-			regval_1b = superio_inb(sioreg, 0x1b);
-			regval_2a = superio_inb(sioreg, 0x2a);
-			regval_2f = superio_inb(sioreg, 0x2f);
-			dsw_en = regval_2f & BIT(3);
+			cr1b = superio_inb(sioreg, 0x1b);
+			cr2a = superio_inb(sioreg, 0x2a);
+			cr2f = superio_inb(sioreg, 0x2f);
+			dsw_en = cr2f & BIT(3);
 
 			if (!pwm5pin)
 				pwm5pin = regval & BIT(7);
 
 			if (!fan5pin)
-				fan5pin = regval_1b & BIT(5);
+				fan5pin = cr1b & BIT(5);
 
 			superio_select(sioreg, NCT6775_LD_12);
 			if (data->kind != nct6796) {
-				int regval_eb = superio_inb(sioreg, 0xeb);
+				int creb = superio_inb(sioreg, 0xeb);
 
 				if (!dsw_en) {
 					fan6pin = regval & BIT(1);
@@ -3541,33 +3541,33 @@ nct6775_check_fan_inputs(struct nct6775_data *data)
 				}
 
 				if (!fan5pin)
-					fan5pin = regval_eb & BIT(5);
+					fan5pin = creb & BIT(5);
 				if (!pwm5pin)
-					pwm5pin = (regval_eb & BIT(4)) &&
-						!(regval_2a & BIT(0));
+					pwm5pin = (creb & BIT(4)) &&
+						!(cr2a & BIT(0));
 				if (!fan6pin)
-					fan6pin = regval_eb & BIT(3);
+					fan6pin = creb & BIT(3);
 				if (!pwm6pin)
-					pwm6pin = regval_eb & BIT(2);
+					pwm6pin = creb & BIT(2);
 			}
 
 			if (data->kind == nct6795 || data->kind == nct6796) {
-				int regval_ed = superio_inb(sioreg, 0xed);
+				int cred = superio_inb(sioreg, 0xed);
 
 				if (!fan6pin)
-					fan6pin = (regval_2a & BIT(4)) &&
-					  (!dsw_en || (regval_ed & BIT(4)));
+					fan6pin = (cr2a & BIT(4)) &&
+					  (!dsw_en || (cred & BIT(4)));
 				if (!pwm6pin)
-					pwm6pin = (regval_2a & BIT(3)) &&
-					  (regval_ed & BIT(2));
+					pwm6pin = (cr2a & BIT(3)) &&
+					  (cred & BIT(2));
 			}
 
 			if (data->kind == nct6796) {
-				int regval_1d = superio_inb(sioreg, 0x1d);
-				int regval_2b = superio_inb(sioreg, 0x2b);
+				int cr1d = superio_inb(sioreg, 0x1d);
+				int cr2b = superio_inb(sioreg, 0x2b);
 
-				fan7pin = !(regval_2b & BIT(2));
-				pwm7pin = !(regval_1d & (BIT(2) | BIT(3)));
+				fan7pin = !(cr2b & BIT(2));
+				pwm7pin = !(cr1d & (BIT(2) | BIT(3)));
 			}
 
 			break;
-- 
2.7.4

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [PATCH 02/13] hwmon: (nct6775) Replace 'regval' with variables named after config registers
  2018-09-20 13:45 [PATCH 01/13] hwmon: (nct6775) Rename configuration register variables Guenter Roeck
@ 2018-09-20 13:45 ` Guenter Roeck
  2018-09-20 13:45 ` [PATCH 03/13] hwmon: (nct6775) Move config variable declarations and initializations Guenter Roeck
                   ` (10 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: Guenter Roeck @ 2018-09-20 13:45 UTC (permalink / raw)
  To: Hardware Monitoring; +Cc: Jean Delvare, Guenter Roeck

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>
---
 drivers/hwmon/nct6775.c | 43 +++++++++++++++++++++++--------------------
 1 file changed, 23 insertions(+), 20 deletions(-)

diff --git a/drivers/hwmon/nct6775.c b/drivers/hwmon/nct6775.c
index 7a3a1d59553e..bd1c4772994a 100644
--- a/drivers/hwmon/nct6775.c
+++ b/drivers/hwmon/nct6775.c
@@ -3436,7 +3436,8 @@ nct6775_check_fan_inputs(struct nct6775_data *data)
 	bool pwm3pin = false, pwm4pin = false, pwm5pin = false;
 	bool pwm6pin = false, pwm7pin = false;
 	int sioreg = data->sioreg;
-	int regval;
+	int cr24;
+	int cr2c;
 
 	/* Store SIO_REG_ENABLE for use during resume */
 	superio_select(sioreg, NCT6775_LD_HWM);
@@ -3444,10 +3445,10 @@ nct6775_check_fan_inputs(struct nct6775_data *data)
 
 	/* fan4 and fan5 share some pins with the GPIO and serial flash */
 	if (data->kind == nct6775) {
-		regval = superio_inb(sioreg, 0x2c);
+		cr2c = superio_inb(sioreg, 0x2c);
 
-		fan3pin = regval & BIT(6);
-		pwm3pin = regval & BIT(7);
+		fan3pin = cr2c & BIT(6);
+		pwm3pin = cr2c & BIT(7);
 
 		/* On NCT6775, fan4 shares pins with the fdc interface */
 		fan4pin = !(superio_inb(sioreg, 0x2A) & 0x80);
@@ -3492,30 +3493,32 @@ nct6775_check_fan_inputs(struct nct6775_data *data)
 		fan4min = fan4pin;
 		pwm3pin = fan3pin;
 	} else if (data->kind == nct6106) {
-		regval = superio_inb(sioreg, 0x24);
-		fan3pin = !(regval & 0x80);
-		pwm3pin = regval & 0x08;
+		cr24 = superio_inb(sioreg, 0x24);
+		fan3pin = !(cr24 & 0x80);
+		pwm3pin = cr24 & 0x08;
 	} else {
 		/* NCT6779D, NCT6791D, NCT6792D, NCT6793D, NCT6795D, NCT6796D */
 		int cr1b, cr2a, cr2f;
+		int cr1c;
+		int cr2d;
 		bool dsw_en;
 
-		regval = superio_inb(sioreg, 0x1c);
+		cr1c = superio_inb(sioreg, 0x1c);
 
-		fan3pin = !(regval & BIT(5));
-		fan4pin = !(regval & BIT(6));
-		fan5pin = !(regval & BIT(7));
+		fan3pin = !(cr1c & BIT(5));
+		fan4pin = !(cr1c & BIT(6));
+		fan5pin = !(cr1c & BIT(7));
 
-		pwm3pin = !(regval & BIT(0));
-		pwm4pin = !(regval & BIT(1));
-		pwm5pin = !(regval & BIT(2));
+		pwm3pin = !(cr1c & BIT(0));
+		pwm4pin = !(cr1c & BIT(1));
+		pwm5pin = !(cr1c & BIT(2));
 
-		regval = superio_inb(sioreg, 0x2d);
+		cr2d = superio_inb(sioreg, 0x2d);
 		switch (data->kind) {
 		case nct6791:
 		case nct6792:
-			fan6pin = regval & BIT(1);
-			pwm6pin = regval & BIT(0);
+			fan6pin = cr2d & BIT(1);
+			pwm6pin = cr2d & BIT(0);
 			break;
 		case nct6793:
 		case nct6795:
@@ -3526,7 +3529,7 @@ nct6775_check_fan_inputs(struct nct6775_data *data)
 			dsw_en = cr2f & BIT(3);
 
 			if (!pwm5pin)
-				pwm5pin = regval & BIT(7);
+				pwm5pin = cr2d & BIT(7);
 
 			if (!fan5pin)
 				fan5pin = cr1b & BIT(5);
@@ -3536,8 +3539,8 @@ nct6775_check_fan_inputs(struct nct6775_data *data)
 				int creb = superio_inb(sioreg, 0xeb);
 
 				if (!dsw_en) {
-					fan6pin = regval & BIT(1);
-					pwm6pin = regval & BIT(0);
+					fan6pin = cr2d & BIT(1);
+					pwm6pin = cr2d & BIT(0);
 				}
 
 				if (!fan5pin)
-- 
2.7.4

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [PATCH 03/13] hwmon: (nct6775) Move config variable declarations and initializations
  2018-09-20 13:45 [PATCH 01/13] hwmon: (nct6775) Rename configuration register variables Guenter Roeck
  2018-09-20 13:45 ` [PATCH 02/13] hwmon: (nct6775) Replace 'regval' with variables named after config registers Guenter Roeck
@ 2018-09-20 13:45 ` Guenter Roeck
  2018-09-20 13:45 ` [PATCH 04/13] hwmon: (nct6775) Declare and initialize LDN specific config variables earlier Guenter Roeck
                   ` (9 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: Guenter Roeck @ 2018-09-20 13:45 UTC (permalink / raw)
  To: Hardware Monitoring; +Cc: Jean Delvare, Guenter Roeck

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>
---
 drivers/hwmon/nct6775.c | 30 +++++++++++-------------------
 1 file changed, 11 insertions(+), 19 deletions(-)

diff --git a/drivers/hwmon/nct6775.c b/drivers/hwmon/nct6775.c
index bd1c4772994a..aa8a44608ca3 100644
--- a/drivers/hwmon/nct6775.c
+++ b/drivers/hwmon/nct6775.c
@@ -3436,8 +3436,6 @@ nct6775_check_fan_inputs(struct nct6775_data *data)
 	bool pwm3pin = false, pwm4pin = false, pwm5pin = false;
 	bool pwm6pin = false, pwm7pin = false;
 	int sioreg = data->sioreg;
-	int cr24;
-	int cr2c;
 
 	/* Store SIO_REG_ENABLE for use during resume */
 	superio_select(sioreg, NCT6775_LD_HWM);
@@ -3445,7 +3443,7 @@ nct6775_check_fan_inputs(struct nct6775_data *data)
 
 	/* fan4 and fan5 share some pins with the GPIO and serial flash */
 	if (data->kind == nct6775) {
-		cr2c = superio_inb(sioreg, 0x2c);
+		int cr2c = superio_inb(sioreg, 0x2c);
 
 		fan3pin = cr2c & BIT(6);
 		pwm3pin = cr2c & BIT(7);
@@ -3493,17 +3491,20 @@ nct6775_check_fan_inputs(struct nct6775_data *data)
 		fan4min = fan4pin;
 		pwm3pin = fan3pin;
 	} else if (data->kind == nct6106) {
-		cr24 = superio_inb(sioreg, 0x24);
+		int cr24 = superio_inb(sioreg, 0x24);
+
 		fan3pin = !(cr24 & 0x80);
 		pwm3pin = cr24 & 0x08;
 	} else {
 		/* NCT6779D, NCT6791D, NCT6792D, NCT6793D, NCT6795D, NCT6796D */
-		int cr1b, cr2a, cr2f;
-		int cr1c;
-		int cr2d;
-		bool dsw_en;
-
-		cr1c = superio_inb(sioreg, 0x1c);
+		int cr1b = superio_inb(sioreg, 0x1b);
+		int cr1c = superio_inb(sioreg, 0x1c);
+		int cr1d = superio_inb(sioreg, 0x1d);
+		int cr2a = superio_inb(sioreg, 0x2a);
+		int cr2b = superio_inb(sioreg, 0x2b);
+		int cr2d = superio_inb(sioreg, 0x2d);
+		int cr2f = superio_inb(sioreg, 0x2f);
+		bool dsw_en = cr2f & BIT(3);
 
 		fan3pin = !(cr1c & BIT(5));
 		fan4pin = !(cr1c & BIT(6));
@@ -3513,7 +3514,6 @@ nct6775_check_fan_inputs(struct nct6775_data *data)
 		pwm4pin = !(cr1c & BIT(1));
 		pwm5pin = !(cr1c & BIT(2));
 
-		cr2d = superio_inb(sioreg, 0x2d);
 		switch (data->kind) {
 		case nct6791:
 		case nct6792:
@@ -3523,11 +3523,6 @@ nct6775_check_fan_inputs(struct nct6775_data *data)
 		case nct6793:
 		case nct6795:
 		case nct6796:
-			cr1b = superio_inb(sioreg, 0x1b);
-			cr2a = superio_inb(sioreg, 0x2a);
-			cr2f = superio_inb(sioreg, 0x2f);
-			dsw_en = cr2f & BIT(3);
-
 			if (!pwm5pin)
 				pwm5pin = cr2d & BIT(7);
 
@@ -3566,9 +3561,6 @@ nct6775_check_fan_inputs(struct nct6775_data *data)
 			}
 
 			if (data->kind == nct6796) {
-				int cr1d = superio_inb(sioreg, 0x1d);
-				int cr2b = superio_inb(sioreg, 0x2b);
-
 				fan7pin = !(cr2b & BIT(2));
 				pwm7pin = !(cr1d & (BIT(2) | BIT(3)));
 			}
-- 
2.7.4

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [PATCH 04/13] hwmon: (nct6775) Declare and initialize LDN specific config variables earlier
  2018-09-20 13:45 [PATCH 01/13] hwmon: (nct6775) Rename configuration register variables Guenter Roeck
  2018-09-20 13:45 ` [PATCH 02/13] hwmon: (nct6775) Replace 'regval' with variables named after config registers Guenter Roeck
  2018-09-20 13:45 ` [PATCH 03/13] hwmon: (nct6775) Move config variable declarations and initializations Guenter Roeck
@ 2018-09-20 13:45 ` Guenter Roeck
  2018-09-20 13:45 ` [PATCH 05/13] hwmon: (nct6775) Use logical or instead of if statements where possible Guenter Roeck
                   ` (8 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: Guenter Roeck @ 2018-09-20 13:45 UTC (permalink / raw)
  To: Hardware Monitoring; +Cc: Jean Delvare, Guenter Roeck

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>
---
 drivers/hwmon/nct6775.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/drivers/hwmon/nct6775.c b/drivers/hwmon/nct6775.c
index aa8a44608ca3..984b22d4999a 100644
--- a/drivers/hwmon/nct6775.c
+++ b/drivers/hwmon/nct6775.c
@@ -3505,6 +3505,12 @@ nct6775_check_fan_inputs(struct nct6775_data *data)
 		int cr2d = superio_inb(sioreg, 0x2d);
 		int cr2f = superio_inb(sioreg, 0x2f);
 		bool dsw_en = cr2f & BIT(3);
+		int creb;
+		int cred;
+
+		superio_select(sioreg, NCT6775_LD_12);
+		creb = superio_inb(sioreg, 0xeb);
+		cred = superio_inb(sioreg, 0xed);
 
 		fan3pin = !(cr1c & BIT(5));
 		fan4pin = !(cr1c & BIT(6));
@@ -3529,10 +3535,7 @@ nct6775_check_fan_inputs(struct nct6775_data *data)
 			if (!fan5pin)
 				fan5pin = cr1b & BIT(5);
 
-			superio_select(sioreg, NCT6775_LD_12);
 			if (data->kind != nct6796) {
-				int creb = superio_inb(sioreg, 0xeb);
-
 				if (!dsw_en) {
 					fan6pin = cr2d & BIT(1);
 					pwm6pin = cr2d & BIT(0);
@@ -3550,8 +3553,6 @@ nct6775_check_fan_inputs(struct nct6775_data *data)
 			}
 
 			if (data->kind == nct6795 || data->kind == nct6796) {
-				int cred = superio_inb(sioreg, 0xed);
-
 				if (!fan6pin)
 					fan6pin = (cr2a & BIT(4)) &&
 					  (!dsw_en || (cred & BIT(4)));
-- 
2.7.4

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [PATCH 05/13] hwmon: (nct6775) Use logical or instead of if statements where possible
  2018-09-20 13:45 [PATCH 01/13] hwmon: (nct6775) Rename configuration register variables Guenter Roeck
                   ` (2 preceding siblings ...)
  2018-09-20 13:45 ` [PATCH 04/13] hwmon: (nct6775) Declare and initialize LDN specific config variables earlier Guenter Roeck
@ 2018-09-20 13:45 ` Guenter Roeck
  2018-09-20 13:45 ` [PATCH 06/13] hwmon: (nct6775) Improve instruction grouping Guenter Roeck
                   ` (7 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: Guenter Roeck @ 2018-09-20 13:45 UTC (permalink / raw)
  To: Hardware Monitoring; +Cc: Jean Delvare, Guenter Roeck

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>
---
 drivers/hwmon/nct6775.c | 34 +++++++++++-----------------------
 1 file changed, 11 insertions(+), 23 deletions(-)

diff --git a/drivers/hwmon/nct6775.c b/drivers/hwmon/nct6775.c
index 984b22d4999a..0f20f7c2a96b 100644
--- a/drivers/hwmon/nct6775.c
+++ b/drivers/hwmon/nct6775.c
@@ -3529,36 +3529,24 @@ nct6775_check_fan_inputs(struct nct6775_data *data)
 		case nct6793:
 		case nct6795:
 		case nct6796:
-			if (!pwm5pin)
-				pwm5pin = cr2d & BIT(7);
+			pwm5pin |= cr2d & BIT(7);
 
-			if (!fan5pin)
-				fan5pin = cr1b & BIT(5);
+			fan5pin |= cr1b & BIT(5);
 
 			if (data->kind != nct6796) {
-				if (!dsw_en) {
-					fan6pin = cr2d & BIT(1);
-					pwm6pin = cr2d & BIT(0);
-				}
+				fan6pin = !dsw_en && (cr2d & BIT(1));
+				pwm6pin = !dsw_en && (cr2d & BIT(0));
 
-				if (!fan5pin)
-					fan5pin = creb & BIT(5);
-				if (!pwm5pin)
-					pwm5pin = (creb & BIT(4)) &&
-						!(cr2a & BIT(0));
-				if (!fan6pin)
-					fan6pin = creb & BIT(3);
-				if (!pwm6pin)
-					pwm6pin = creb & BIT(2);
+				fan5pin |= creb & BIT(5);
+				pwm5pin |= (creb & BIT(4)) && !(cr2a & BIT(0));
+				fan6pin |= creb & BIT(3);
+				pwm6pin |= creb & BIT(2);
 			}
 
 			if (data->kind == nct6795 || data->kind == nct6796) {
-				if (!fan6pin)
-					fan6pin = (cr2a & BIT(4)) &&
-					  (!dsw_en || (cred & BIT(4)));
-				if (!pwm6pin)
-					pwm6pin = (cr2a & BIT(3)) &&
-					  (cred & BIT(2));
+				fan6pin |= (cr2a & BIT(4)) &&
+						(!dsw_en || (cred & BIT(4)));
+				pwm6pin |= (cr2a & BIT(3)) && (cred & BIT(2));
 			}
 
 			if (data->kind == nct6796) {
-- 
2.7.4

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [PATCH 06/13] hwmon: (nct6775) Improve instruction grouping
  2018-09-20 13:45 [PATCH 01/13] hwmon: (nct6775) Rename configuration register variables Guenter Roeck
                   ` (3 preceding siblings ...)
  2018-09-20 13:45 ` [PATCH 05/13] hwmon: (nct6775) Use logical or instead of if statements where possible Guenter Roeck
@ 2018-09-20 13:45 ` Guenter Roeck
  2018-09-20 13:45 ` [PATCH 07/13] hwmon: (nct6775) Fix fan6/pwm6 detection for NCT6792D Guenter Roeck
                   ` (6 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: Guenter Roeck @ 2018-09-20 13:45 UTC (permalink / raw)
  To: Hardware Monitoring; +Cc: Jean Delvare, Guenter Roeck

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>
---
 drivers/hwmon/nct6775.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/hwmon/nct6775.c b/drivers/hwmon/nct6775.c
index 0f20f7c2a96b..0ad4bf0ab8be 100644
--- a/drivers/hwmon/nct6775.c
+++ b/drivers/hwmon/nct6775.c
@@ -3530,16 +3530,16 @@ nct6775_check_fan_inputs(struct nct6775_data *data)
 		case nct6795:
 		case nct6796:
 			pwm5pin |= cr2d & BIT(7);
-
 			fan5pin |= cr1b & BIT(5);
 
 			if (data->kind != nct6796) {
-				fan6pin = !dsw_en && (cr2d & BIT(1));
-				pwm6pin = !dsw_en && (cr2d & BIT(0));
-
 				fan5pin |= creb & BIT(5);
 				pwm5pin |= (creb & BIT(4)) && !(cr2a & BIT(0));
+
+				fan6pin = !dsw_en && (cr2d & BIT(1));
 				fan6pin |= creb & BIT(3);
+
+				pwm6pin = !dsw_en && (cr2d & BIT(0));
 				pwm6pin |= creb & BIT(2);
 			}
 
-- 
2.7.4

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [PATCH 07/13] hwmon: (nct6775) Fix fan6/pwm6 detection for NCT6792D
  2018-09-20 13:45 [PATCH 01/13] hwmon: (nct6775) Rename configuration register variables Guenter Roeck
                   ` (4 preceding siblings ...)
  2018-09-20 13:45 ` [PATCH 06/13] hwmon: (nct6775) Improve instruction grouping Guenter Roeck
@ 2018-09-20 13:45 ` Guenter Roeck
  2018-09-20 13:45 ` [PATCH 08/13] hwmon: (nct6775) Separate fan/pwm configuration detection for NCT6793D Guenter Roeck
                   ` (5 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: Guenter Roeck @ 2018-09-20 13:45 UTC (permalink / raw)
  To: Hardware Monitoring; +Cc: Jean Delvare, Guenter Roeck

Per datasheet, AUXFANIN3 (fan6) and AUXFANOUT3 (pwm6) are only connected
if DSW_EN is false.

Signed-off-by: Guenter Roeck <linux@roeck-us.net>
---
 drivers/hwmon/nct6775.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/hwmon/nct6775.c b/drivers/hwmon/nct6775.c
index 0ad4bf0ab8be..6e11df697e6e 100644
--- a/drivers/hwmon/nct6775.c
+++ b/drivers/hwmon/nct6775.c
@@ -3522,10 +3522,13 @@ nct6775_check_fan_inputs(struct nct6775_data *data)
 
 		switch (data->kind) {
 		case nct6791:
-		case nct6792:
 			fan6pin = cr2d & BIT(1);
 			pwm6pin = cr2d & BIT(0);
 			break;
+		case nct6792:
+			fan6pin = !dsw_en && (cr2d & BIT(1));
+			pwm6pin = !dsw_en && (cr2d & BIT(0));
+			break;
 		case nct6793:
 		case nct6795:
 		case nct6796:
-- 
2.7.4

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [PATCH 08/13] hwmon: (nct6775) Separate fan/pwm configuration detection for NCT6793D
  2018-09-20 13:45 [PATCH 01/13] hwmon: (nct6775) Rename configuration register variables Guenter Roeck
                   ` (5 preceding siblings ...)
  2018-09-20 13:45 ` [PATCH 07/13] hwmon: (nct6775) Fix fan6/pwm6 detection for NCT6792D Guenter Roeck
@ 2018-09-20 13:45 ` Guenter Roeck
  2018-09-20 13:45 ` [PATCH 09/13] hwmon: (nct6775) Separate fan/pwm configuration detection for NCT6795D Guenter Roeck
                   ` (4 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: Guenter Roeck @ 2018-09-20 13:45 UTC (permalink / raw)
  To: Hardware Monitoring; +Cc: Jean Delvare, Guenter Roeck

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>
---
 drivers/hwmon/nct6775.c | 19 ++++++++++++++-----
 1 file changed, 14 insertions(+), 5 deletions(-)

diff --git a/drivers/hwmon/nct6775.c b/drivers/hwmon/nct6775.c
index 6e11df697e6e..556b4cfacbd1 100644
--- a/drivers/hwmon/nct6775.c
+++ b/drivers/hwmon/nct6775.c
@@ -3530,6 +3530,17 @@ nct6775_check_fan_inputs(struct nct6775_data *data)
 			pwm6pin = !dsw_en && (cr2d & BIT(0));
 			break;
 		case nct6793:
+			fan5pin |= cr1b & BIT(5);
+			fan5pin |= creb & BIT(5);
+
+			fan6pin = creb & BIT(3);
+
+			pwm5pin |= cr2d & BIT(7);
+			pwm5pin |= (creb & BIT(4)) && !(cr2a & BIT(0));
+
+			pwm6pin = !dsw_en && (cr2d & BIT(0));
+			pwm6pin |= creb & BIT(2);
+			break;
 		case nct6795:
 		case nct6796:
 			pwm5pin |= cr2d & BIT(7);
@@ -3546,11 +3557,9 @@ nct6775_check_fan_inputs(struct nct6775_data *data)
 				pwm6pin |= creb & BIT(2);
 			}
 
-			if (data->kind == nct6795 || data->kind == nct6796) {
-				fan6pin |= (cr2a & BIT(4)) &&
-						(!dsw_en || (cred & BIT(4)));
-				pwm6pin |= (cr2a & BIT(3)) && (cred & BIT(2));
-			}
+			fan6pin |= (cr2a & BIT(4)) &&
+					(!dsw_en || (cred & BIT(4)));
+			pwm6pin |= (cr2a & BIT(3)) && (cred & BIT(2));
 
 			if (data->kind == nct6796) {
 				fan7pin = !(cr2b & BIT(2));
-- 
2.7.4

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [PATCH 09/13] hwmon: (nct6775) Separate fan/pwm configuration detection for NCT6795D
  2018-09-20 13:45 [PATCH 01/13] hwmon: (nct6775) Rename configuration register variables Guenter Roeck
                   ` (6 preceding siblings ...)
  2018-09-20 13:45 ` [PATCH 08/13] hwmon: (nct6775) Separate fan/pwm configuration detection for NCT6793D Guenter Roeck
@ 2018-09-20 13:45 ` Guenter Roeck
  2018-09-20 13:45 ` [PATCH 10/13] hwmon: (nct6796) Clean up and amend fan/pwm configuration for NCT6796D Guenter Roeck
                   ` (3 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: Guenter Roeck @ 2018-09-20 13:45 UTC (permalink / raw)
  To: Hardware Monitoring; +Cc: Jean Delvare, Guenter Roeck

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>
---
 drivers/hwmon/nct6775.c | 19 +++++++++++++++----
 1 file changed, 15 insertions(+), 4 deletions(-)

diff --git a/drivers/hwmon/nct6775.c b/drivers/hwmon/nct6775.c
index 556b4cfacbd1..d9c2b934321d 100644
--- a/drivers/hwmon/nct6775.c
+++ b/drivers/hwmon/nct6775.c
@@ -3542,6 +3542,19 @@ nct6775_check_fan_inputs(struct nct6775_data *data)
 			pwm6pin |= creb & BIT(2);
 			break;
 		case nct6795:
+			fan5pin |= cr1b & BIT(5);
+			fan5pin |= creb & BIT(5);
+
+			fan6pin = (cr2a & BIT(4)) &&
+					(!dsw_en || (cred & BIT(4)));
+			fan6pin |= creb & BIT(3);
+
+			pwm5pin |= cr2d & BIT(7);
+			pwm5pin |= (creb & BIT(4)) && !(cr2a & BIT(0));
+
+			pwm6pin = (cr2a & BIT(3)) && (cred & BIT(2));
+			pwm6pin |= creb & BIT(2);
+			break;
 		case nct6796:
 			pwm5pin |= cr2d & BIT(7);
 			fan5pin |= cr1b & BIT(5);
@@ -3561,10 +3574,8 @@ nct6775_check_fan_inputs(struct nct6775_data *data)
 					(!dsw_en || (cred & BIT(4)));
 			pwm6pin |= (cr2a & BIT(3)) && (cred & BIT(2));
 
-			if (data->kind == nct6796) {
-				fan7pin = !(cr2b & BIT(2));
-				pwm7pin = !(cr1d & (BIT(2) | BIT(3)));
-			}
+			fan7pin = !(cr2b & BIT(2));
+			pwm7pin = !(cr1d & (BIT(2) | BIT(3)));
 
 			break;
 		default:	/* NCT6779D */
-- 
2.7.4

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [PATCH 10/13] hwmon: (nct6796) Clean up and amend fan/pwm configuration for NCT6796D
  2018-09-20 13:45 [PATCH 01/13] hwmon: (nct6775) Rename configuration register variables Guenter Roeck
                   ` (7 preceding siblings ...)
  2018-09-20 13:45 ` [PATCH 09/13] hwmon: (nct6775) Separate fan/pwm configuration detection for NCT6795D Guenter Roeck
@ 2018-09-20 13:45 ` Guenter Roeck
  2018-09-20 13:45 ` [PATCH 11/13] hwmon: (nct6775) Fix names of DIMM temperature sources Guenter Roeck
                   ` (2 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: Guenter Roeck @ 2018-09-20 13:45 UTC (permalink / raw)
  To: Hardware Monitoring; +Cc: Jean Delvare, Guenter Roeck

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>
---
 drivers/hwmon/nct6775.c | 27 +++++++++++++--------------
 1 file changed, 13 insertions(+), 14 deletions(-)

diff --git a/drivers/hwmon/nct6775.c b/drivers/hwmon/nct6775.c
index d9c2b934321d..c07414dd38dd 100644
--- a/drivers/hwmon/nct6775.c
+++ b/drivers/hwmon/nct6775.c
@@ -3505,10 +3505,12 @@ nct6775_check_fan_inputs(struct nct6775_data *data)
 		int cr2d = superio_inb(sioreg, 0x2d);
 		int cr2f = superio_inb(sioreg, 0x2f);
 		bool dsw_en = cr2f & BIT(3);
+		int cre0;
 		int creb;
 		int cred;
 
 		superio_select(sioreg, NCT6775_LD_12);
+		cre0 = superio_inb(sioreg, 0xe0);
 		creb = superio_inb(sioreg, 0xeb);
 		cred = superio_inb(sioreg, 0xed);
 
@@ -3556,27 +3558,24 @@ nct6775_check_fan_inputs(struct nct6775_data *data)
 			pwm6pin |= creb & BIT(2);
 			break;
 		case nct6796:
-			pwm5pin |= cr2d & BIT(7);
 			fan5pin |= cr1b & BIT(5);
+			fan5pin |= (cre0 & BIT(3)) && !(cr1b & BIT(0));
+			fan5pin |= creb & BIT(5);
 
-			if (data->kind != nct6796) {
-				fan5pin |= creb & BIT(5);
-				pwm5pin |= (creb & BIT(4)) && !(cr2a & BIT(0));
+			fan6pin = (cr2a & BIT(4)) &&
+					(!dsw_en || (cred & BIT(4)));
+			fan6pin |= creb & BIT(3);
 
-				fan6pin = !dsw_en && (cr2d & BIT(1));
-				fan6pin |= creb & BIT(3);
+			fan7pin = !(cr2b & BIT(2));
 
-				pwm6pin = !dsw_en && (cr2d & BIT(0));
-				pwm6pin |= creb & BIT(2);
-			}
+			pwm5pin |= cr2d & BIT(7);
+			pwm5pin |= (cre0 & BIT(4)) && !(cr1b & BIT(0));
+			pwm5pin |= (creb & BIT(4)) && !(cr2a & BIT(0));
 
-			fan6pin |= (cr2a & BIT(4)) &&
-					(!dsw_en || (cred & BIT(4)));
-			pwm6pin |= (cr2a & BIT(3)) && (cred & BIT(2));
+			pwm6pin = (cr2a & BIT(3)) && (cred & BIT(2));
+			pwm6pin |= creb & BIT(2);
 
-			fan7pin = !(cr2b & BIT(2));
 			pwm7pin = !(cr1d & (BIT(2) | BIT(3)));
-
 			break;
 		default:	/* NCT6779D */
 			break;
-- 
2.7.4

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [PATCH 11/13] hwmon: (nct6775) Fix names of DIMM temperature sources
  2018-09-20 13:45 [PATCH 01/13] hwmon: (nct6775) Rename configuration register variables Guenter Roeck
                   ` (8 preceding siblings ...)
  2018-09-20 13:45 ` [PATCH 10/13] hwmon: (nct6796) Clean up and amend fan/pwm configuration for NCT6796D Guenter Roeck
@ 2018-09-20 13:45 ` Guenter Roeck
  2018-09-20 13:45 ` [PATCH 12/13] hwmon: (nct6775) Add support for NCT6797D Guenter Roeck
  2018-09-20 13:45 ` [PATCH 13/13] hwmon: (nct6775) Add support for NCT6798D Guenter Roeck
  11 siblings, 0 replies; 13+ messages in thread
From: Guenter Roeck @ 2018-09-20 13:45 UTC (permalink / raw)
  To: Hardware Monitoring; +Cc: Jean Delvare, Guenter Roeck

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>
---
 drivers/hwmon/nct6775.c | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/drivers/hwmon/nct6775.c b/drivers/hwmon/nct6775.c
index c07414dd38dd..77255f7da974 100644
--- a/drivers/hwmon/nct6775.c
+++ b/drivers/hwmon/nct6775.c
@@ -704,10 +704,10 @@ static const char *const nct6795_temp_label[] = {
 	"PCH_CHIP_TEMP",
 	"PCH_CPU_TEMP",
 	"PCH_MCH_TEMP",
-	"PCH_DIM0_TEMP",
-	"PCH_DIM1_TEMP",
-	"PCH_DIM2_TEMP",
-	"PCH_DIM3_TEMP",
+	"Agent0 Dimm0",
+	"Agent0 Dimm1",
+	"Agent1 Dimm0",
+	"Agent1 Dimm1",
 	"BYTE_TEMP0",
 	"BYTE_TEMP1",
 	"PECI Agent 0 Calibration",
@@ -742,10 +742,10 @@ static const char *const nct6796_temp_label[] = {
 	"PCH_CHIP_TEMP",
 	"PCH_CPU_TEMP",
 	"PCH_MCH_TEMP",
-	"PCH_DIM0_TEMP",
-	"PCH_DIM1_TEMP",
-	"PCH_DIM2_TEMP",
-	"PCH_DIM3_TEMP",
+	"Agent0 Dimm0",
+	"Agent0 Dimm1",
+	"Agent1 Dimm0",
+	"Agent1 Dimm1",
 	"BYTE_TEMP0",
 	"BYTE_TEMP1",
 	"PECI Agent 0 Calibration",
-- 
2.7.4

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [PATCH 12/13] hwmon: (nct6775) Add support for NCT6797D
  2018-09-20 13:45 [PATCH 01/13] hwmon: (nct6775) Rename configuration register variables Guenter Roeck
                   ` (9 preceding siblings ...)
  2018-09-20 13:45 ` [PATCH 11/13] hwmon: (nct6775) Fix names of DIMM temperature sources Guenter Roeck
@ 2018-09-20 13:45 ` Guenter Roeck
  2018-09-20 13:45 ` [PATCH 13/13] hwmon: (nct6775) Add support for NCT6798D Guenter Roeck
  11 siblings, 0 replies; 13+ messages in thread
From: Guenter Roeck @ 2018-09-20 13:45 UTC (permalink / raw)
  To: Hardware Monitoring; +Cc: Jean Delvare, Guenter Roeck

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>
---
 drivers/hwmon/nct6775.c | 45 +++++++++++++++++++++++++++++++++++++++++----
 1 file changed, 41 insertions(+), 4 deletions(-)

diff --git a/drivers/hwmon/nct6775.c b/drivers/hwmon/nct6775.c
index 77255f7da974..9569acf80e18 100644
--- a/drivers/hwmon/nct6775.c
+++ b/drivers/hwmon/nct6775.c
@@ -42,6 +42,7 @@
  * nct6793d    15      6       6       2+6    0xd120 0xc1    0x5ca3
  * nct6795d    14      6       6       2+6    0xd350 0xc1    0x5ca3
  * nct6796d    14      7       7       2+6    0xd420 0xc1    0x5ca3
+ * nct6797d    14      7       7       2+6    0xd450 0xc1    0x5ca3
  *
  * #temp lists the number of monitored temperature sources (first value) plus
  * the number of directly connectable temperature sensors (second value).
@@ -69,7 +70,7 @@
 #define USE_ALTERNATE
 
 enum kinds { nct6106, nct6775, nct6776, nct6779, nct6791, nct6792, nct6793,
-	     nct6795, nct6796 };
+	     nct6795, nct6796, nct6797 };
 
 /* used to set data->name = nct6775_device_names[data->sio_kind] */
 static const char * const nct6775_device_names[] = {
@@ -82,6 +83,7 @@ static const char * const nct6775_device_names[] = {
 	"nct6793",
 	"nct6795",
 	"nct6796",
+	"nct6797",
 };
 
 static const char * const nct6775_sio_names[] __initconst = {
@@ -94,6 +96,7 @@ static const char * const nct6775_sio_names[] __initconst = {
 	"NCT6793D",
 	"NCT6795D",
 	"NCT6796D",
+	"NCT6797D",
 };
 
 static unsigned short force_id;
@@ -129,6 +132,7 @@ MODULE_PARM_DESC(fan_debounce, "Enable debouncing for fan RPM signal");
 #define SIO_NCT6793_ID		0xd120
 #define SIO_NCT6795_ID		0xd350
 #define SIO_NCT6796_ID		0xd420
+#define SIO_NCT6797_ID		0xd450
 #define SIO_ID_MASK		0xFFF0
 
 enum pwm_enable { off, manual, thermal_cruise, speed_cruise, sf3, sf4 };
@@ -504,7 +508,7 @@ static const s8 NCT6779_BEEP_BITS[] = {
 static const u16 NCT6779_REG_FAN[] = {
 	0x4c0, 0x4c2, 0x4c4, 0x4c6, 0x4c8, 0x4ca, 0x4ce };
 static const u16 NCT6779_REG_FAN_PULSES[NUM_FAN] = {
-	0x644, 0x645, 0x646, 0x647, 0x648, 0x649 };
+	0x644, 0x645, 0x646, 0x647, 0x648, 0x649, 0x64f };
 
 static const u16 NCT6779_REG_CRITICAL_PWM_ENABLE[] = {
 	0x136, 0x236, 0x336, 0x836, 0x936, 0xa36, 0xb36 };
@@ -1288,6 +1292,7 @@ static bool is_word_sized(struct nct6775_data *data, u16 reg)
 	case nct6793:
 	case nct6795:
 	case nct6796:
+	case nct6797:
 		return reg == 0x150 || reg == 0x153 || reg == 0x155 ||
 		  (reg & 0xfff0) == 0x4c0 ||
 		  reg == 0x402 ||
@@ -1643,6 +1648,7 @@ static void nct6775_update_pwm_limits(struct device *dev)
 		case nct6793:
 		case nct6795:
 		case nct6796:
+		case nct6797:
 			reg = nct6775_read_value(data,
 					data->REG_CRITICAL_PWM_ENABLE[i]);
 			if (reg & data->CRITICAL_PWM_ENABLE_MASK)
@@ -3077,6 +3083,7 @@ store_auto_pwm(struct device *dev, struct device_attribute *attr,
 		case nct6793:
 		case nct6795:
 		case nct6796:
+		case nct6797:
 			nct6775_write_value(data, data->REG_CRITICAL_PWM[nr],
 					    val);
 			reg = nct6775_read_value(data,
@@ -3496,7 +3503,11 @@ nct6775_check_fan_inputs(struct nct6775_data *data)
 		fan3pin = !(cr24 & 0x80);
 		pwm3pin = cr24 & 0x08;
 	} else {
-		/* NCT6779D, NCT6791D, NCT6792D, NCT6793D, NCT6795D, NCT6796D */
+		/*
+		 * NCT6779D, NCT6791D, NCT6792D, NCT6793D, NCT6795D, NCT6796D,
+		 * NCT6797D
+		 */
+		int cr1a = superio_inb(sioreg, 0x1a);
 		int cr1b = superio_inb(sioreg, 0x1b);
 		int cr1c = superio_inb(sioreg, 0x1c);
 		int cr1d = superio_inb(sioreg, 0x1d);
@@ -3505,6 +3516,7 @@ nct6775_check_fan_inputs(struct nct6775_data *data)
 		int cr2d = superio_inb(sioreg, 0x2d);
 		int cr2f = superio_inb(sioreg, 0x2f);
 		bool dsw_en = cr2f & BIT(3);
+		bool ddr4_en = cr2f & BIT(4);
 		int cre0;
 		int creb;
 		int cred;
@@ -3577,6 +3589,23 @@ nct6775_check_fan_inputs(struct nct6775_data *data)
 
 			pwm7pin = !(cr1d & (BIT(2) | BIT(3)));
 			break;
+		case nct6797:
+			fan5pin |= !ddr4_en && (cr1b & BIT(5));
+			fan5pin |= creb & BIT(5);
+
+			fan6pin = cr2a & BIT(4);
+			fan6pin |= creb & BIT(3);
+
+			fan7pin = cr1a & BIT(1);
+
+			pwm5pin |= (creb & BIT(4)) && !(cr2a & BIT(0));
+			pwm5pin |= !ddr4_en && (cr2d & BIT(7));
+
+			pwm6pin = creb & BIT(2);
+			pwm6pin |= cred & BIT(2);
+
+			pwm7pin = cr1d & BIT(4);
+			break;
 		default:	/* NCT6779D */
 			break;
 		}
@@ -3954,8 +3983,10 @@ static int nct6775_probe(struct platform_device *pdev)
 	case nct6793:
 	case nct6795:
 	case nct6796:
+	case nct6797:
 		data->in_num = 15;
-		data->pwm_num = (data->kind == nct6796) ? 7 : 6;
+		data->pwm_num = (data->kind == nct6796 ||
+				 data->kind == nct6797) ? 7 : 6;
 		data->auto_pwm_num = 4;
 		data->has_fan_div = false;
 		data->temp_fixed_num = 6;
@@ -3989,6 +4020,7 @@ static int nct6775_probe(struct platform_device *pdev)
 			data->virt_temp_mask = NCT6793_VIRT_TEMP_MASK;
 			break;
 		case nct6795:
+		case nct6797:
 			data->temp_label = nct6795_temp_label;
 			data->temp_mask = NCT6795_TEMP_MASK;
 			data->virt_temp_mask = NCT6795_VIRT_TEMP_MASK;
@@ -4267,6 +4299,7 @@ static int nct6775_probe(struct platform_device *pdev)
 	case nct6793:
 	case nct6795:
 	case nct6796:
+	case nct6797:
 		break;
 	}
 
@@ -4302,6 +4335,7 @@ static int nct6775_probe(struct platform_device *pdev)
 		case nct6793:
 		case nct6795:
 		case nct6796:
+		case nct6797:
 			tmp |= 0x7e;
 			break;
 		}
@@ -4504,6 +4538,9 @@ static int __init nct6775_find(int sioaddr, struct nct6775_sio_data *sio_data)
 	case SIO_NCT6796_ID:
 		sio_data->kind = nct6796;
 		break;
+	case SIO_NCT6797_ID:
+		sio_data->kind = nct6797;
+		break;
 	default:
 		if (val != 0xffff)
 			pr_debug("unsupported chip ID: 0x%04x\n", val);
-- 
2.7.4

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [PATCH 13/13] hwmon: (nct6775) Add support for NCT6798D
  2018-09-20 13:45 [PATCH 01/13] hwmon: (nct6775) Rename configuration register variables Guenter Roeck
                   ` (10 preceding siblings ...)
  2018-09-20 13:45 ` [PATCH 12/13] hwmon: (nct6775) Add support for NCT6797D Guenter Roeck
@ 2018-09-20 13:45 ` Guenter Roeck
  11 siblings, 0 replies; 13+ messages in thread
From: Guenter Roeck @ 2018-09-20 13:45 UTC (permalink / raw)
  To: Hardware Monitoring; +Cc: Jean Delvare, Guenter Roeck

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>
---
 drivers/hwmon/nct6775.c | 84 ++++++++++++++++++++++++++++++++++++++++++++++---
 1 file changed, 80 insertions(+), 4 deletions(-)

diff --git a/drivers/hwmon/nct6775.c b/drivers/hwmon/nct6775.c
index 9569acf80e18..c3040079b1cb 100644
--- a/drivers/hwmon/nct6775.c
+++ b/drivers/hwmon/nct6775.c
@@ -43,6 +43,9 @@
  * nct6795d    14      6       6       2+6    0xd350 0xc1    0x5ca3
  * nct6796d    14      7       7       2+6    0xd420 0xc1    0x5ca3
  * nct6797d    14      7       7       2+6    0xd450 0xc1    0x5ca3
+ *                                           (0xd451)
+ * nct6798d    14      7       7       2+6    0xd458 0xc1    0x5ca3
+ *                                           (0xd459)
  *
  * #temp lists the number of monitored temperature sources (first value) plus
  * the number of directly connectable temperature sensors (second value).
@@ -70,7 +73,7 @@
 #define USE_ALTERNATE
 
 enum kinds { nct6106, nct6775, nct6776, nct6779, nct6791, nct6792, nct6793,
-	     nct6795, nct6796, nct6797 };
+	     nct6795, nct6796, nct6797, nct6798 };
 
 /* used to set data->name = nct6775_device_names[data->sio_kind] */
 static const char * const nct6775_device_names[] = {
@@ -84,6 +87,7 @@ static const char * const nct6775_device_names[] = {
 	"nct6795",
 	"nct6796",
 	"nct6797",
+	"nct6798",
 };
 
 static const char * const nct6775_sio_names[] __initconst = {
@@ -97,6 +101,7 @@ static const char * const nct6775_sio_names[] __initconst = {
 	"NCT6795D",
 	"NCT6796D",
 	"NCT6797D",
+	"NCT6798D",
 };
 
 static unsigned short force_id;
@@ -133,7 +138,8 @@ MODULE_PARM_DESC(fan_debounce, "Enable debouncing for fan RPM signal");
 #define SIO_NCT6795_ID		0xd350
 #define SIO_NCT6796_ID		0xd420
 #define SIO_NCT6797_ID		0xd450
-#define SIO_ID_MASK		0xFFF0
+#define SIO_NCT6798_ID		0xd458
+#define SIO_ID_MASK		0xFFF8
 
 enum pwm_enable { off, manual, thermal_cruise, speed_cruise, sf3, sf4 };
 
@@ -761,6 +767,44 @@ static const char *const nct6796_temp_label[] = {
 #define NCT6796_TEMP_MASK	0xbfff0ffe
 #define NCT6796_VIRT_TEMP_MASK	0x80000c00
 
+static const char *const nct6798_temp_label[] = {
+	"",
+	"SYSTIN",
+	"CPUTIN",
+	"AUXTIN0",
+	"AUXTIN1",
+	"AUXTIN2",
+	"AUXTIN3",
+	"AUXTIN4",
+	"SMBUSMASTER 0",
+	"SMBUSMASTER 1",
+	"Virtual_TEMP",
+	"Virtual_TEMP",
+	"",
+	"",
+	"",
+	"",
+	"PECI Agent 0",
+	"PECI Agent 1",
+	"PCH_CHIP_CPU_MAX_TEMP",
+	"PCH_CHIP_TEMP",
+	"PCH_CPU_TEMP",
+	"PCH_MCH_TEMP",
+	"Agent0 Dimm0",
+	"Agent0 Dimm1",
+	"Agent1 Dimm0",
+	"Agent1 Dimm1",
+	"BYTE_TEMP0",
+	"BYTE_TEMP1",
+	"",
+	"",
+	"",
+	"Virtual_TEMP"
+};
+
+#define NCT6798_TEMP_MASK	0x8fff0ffe
+#define NCT6798_VIRT_TEMP_MASK	0x80000c00
+
 /* NCT6102D/NCT6106D specific data */
 
 #define NCT6106_REG_VBAT	0x318
@@ -1293,6 +1337,7 @@ static bool is_word_sized(struct nct6775_data *data, u16 reg)
 	case nct6795:
 	case nct6796:
 	case nct6797:
+	case nct6798:
 		return reg == 0x150 || reg == 0x153 || reg == 0x155 ||
 		  (reg & 0xfff0) == 0x4c0 ||
 		  reg == 0x402 ||
@@ -1649,6 +1694,7 @@ static void nct6775_update_pwm_limits(struct device *dev)
 		case nct6795:
 		case nct6796:
 		case nct6797:
+		case nct6798:
 			reg = nct6775_read_value(data,
 					data->REG_CRITICAL_PWM_ENABLE[i]);
 			if (reg & data->CRITICAL_PWM_ENABLE_MASK)
@@ -3084,6 +3130,7 @@ store_auto_pwm(struct device *dev, struct device_attribute *attr,
 		case nct6795:
 		case nct6796:
 		case nct6797:
+		case nct6798:
 			nct6775_write_value(data, data->REG_CRITICAL_PWM[nr],
 					    val);
 			reg = nct6775_read_value(data,
@@ -3505,7 +3552,7 @@ nct6775_check_fan_inputs(struct nct6775_data *data)
 	} else {
 		/*
 		 * NCT6779D, NCT6791D, NCT6792D, NCT6793D, NCT6795D, NCT6796D,
-		 * NCT6797D
+		 * NCT6797D, NCT6798D
 		 */
 		int cr1a = superio_inb(sioreg, 0x1a);
 		int cr1b = superio_inb(sioreg, 0x1b);
@@ -3606,6 +3653,23 @@ nct6775_check_fan_inputs(struct nct6775_data *data)
 
 			pwm7pin = cr1d & BIT(4);
 			break;
+		case nct6798:
+			fan6pin = !(cr1b & BIT(0)) && (cre0 & BIT(3));
+			fan6pin |= cr2a & BIT(4);
+			fan6pin |= creb & BIT(5);
+
+			fan7pin = cr1b & BIT(5);
+			fan7pin |= !(cr2b & BIT(2));
+			fan7pin |= creb & BIT(3);
+
+			pwm6pin = !(cr1b & BIT(0)) && (cre0 & BIT(4));
+			pwm6pin |= !(cred & BIT(2)) && (cr2a & BIT(3));
+			pwm6pin |= (creb & BIT(4)) && !(cr2a & BIT(0));
+
+			pwm7pin = !(cr1d & (BIT(2) | BIT(3)));
+			pwm7pin |= cr2d & BIT(7);
+			pwm7pin |= creb & BIT(2);
+			break;
 		default:	/* NCT6779D */
 			break;
 		}
@@ -3984,9 +4048,11 @@ static int nct6775_probe(struct platform_device *pdev)
 	case nct6795:
 	case nct6796:
 	case nct6797:
+	case nct6798:
 		data->in_num = 15;
 		data->pwm_num = (data->kind == nct6796 ||
-				 data->kind == nct6797) ? 7 : 6;
+				 data->kind == nct6797 ||
+				 data->kind == nct6798) ? 7 : 6;
 		data->auto_pwm_num = 4;
 		data->has_fan_div = false;
 		data->temp_fixed_num = 6;
@@ -4030,6 +4096,11 @@ static int nct6775_probe(struct platform_device *pdev)
 			data->temp_mask = NCT6796_TEMP_MASK;
 			data->virt_temp_mask = NCT6796_VIRT_TEMP_MASK;
 			break;
+		case nct6798:
+			data->temp_label = nct6798_temp_label;
+			data->temp_mask = NCT6798_TEMP_MASK;
+			data->virt_temp_mask = NCT6798_VIRT_TEMP_MASK;
+			break;
 		}
 
 		data->REG_CONFIG = NCT6775_REG_CONFIG;
@@ -4300,6 +4371,7 @@ static int nct6775_probe(struct platform_device *pdev)
 	case nct6795:
 	case nct6796:
 	case nct6797:
+	case nct6798:
 		break;
 	}
 
@@ -4336,6 +4408,7 @@ static int nct6775_probe(struct platform_device *pdev)
 		case nct6795:
 		case nct6796:
 		case nct6797:
+		case nct6798:
 			tmp |= 0x7e;
 			break;
 		}
@@ -4541,6 +4614,9 @@ static int __init nct6775_find(int sioaddr, struct nct6775_sio_data *sio_data)
 	case SIO_NCT6797_ID:
 		sio_data->kind = nct6797;
 		break;
+	case SIO_NCT6798_ID:
+		sio_data->kind = nct6798;
+		break;
 	default:
 		if (val != 0xffff)
 			pr_debug("unsupported chip ID: 0x%04x\n", val);
-- 
2.7.4

^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, back to index

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-09-20 13:45 [PATCH 01/13] hwmon: (nct6775) Rename configuration register variables Guenter Roeck
2018-09-20 13:45 ` [PATCH 02/13] hwmon: (nct6775) Replace 'regval' with variables named after config registers Guenter Roeck
2018-09-20 13:45 ` [PATCH 03/13] hwmon: (nct6775) Move config variable declarations and initializations Guenter Roeck
2018-09-20 13:45 ` [PATCH 04/13] hwmon: (nct6775) Declare and initialize LDN specific config variables earlier Guenter Roeck
2018-09-20 13:45 ` [PATCH 05/13] hwmon: (nct6775) Use logical or instead of if statements where possible Guenter Roeck
2018-09-20 13:45 ` [PATCH 06/13] hwmon: (nct6775) Improve instruction grouping Guenter Roeck
2018-09-20 13:45 ` [PATCH 07/13] hwmon: (nct6775) Fix fan6/pwm6 detection for NCT6792D Guenter Roeck
2018-09-20 13:45 ` [PATCH 08/13] hwmon: (nct6775) Separate fan/pwm configuration detection for NCT6793D Guenter Roeck
2018-09-20 13:45 ` [PATCH 09/13] hwmon: (nct6775) Separate fan/pwm configuration detection for NCT6795D Guenter Roeck
2018-09-20 13:45 ` [PATCH 10/13] hwmon: (nct6796) Clean up and amend fan/pwm configuration for NCT6796D Guenter Roeck
2018-09-20 13:45 ` [PATCH 11/13] hwmon: (nct6775) Fix names of DIMM temperature sources Guenter Roeck
2018-09-20 13:45 ` [PATCH 12/13] hwmon: (nct6775) Add support for NCT6797D Guenter Roeck
2018-09-20 13:45 ` [PATCH 13/13] hwmon: (nct6775) Add support for NCT6798D Guenter Roeck

Linux-Hwmon Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-hwmon/0 linux-hwmon/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-hwmon linux-hwmon/ https://lore.kernel.org/linux-hwmon \
		linux-hwmon@vger.kernel.org
	public-inbox-index linux-hwmon

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-hwmon


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git