linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 0/2] hwmon: (pmbus/bpa-rs600) cleanup and workaround
@ 2021-08-12  1:39 Chris Packham
  2021-08-12  1:39 ` [PATCH v2 1/2] hwmon: (pmbus/bpa-rs600) Don't use rated limits as warn limits Chris Packham
  2021-08-12  1:40 ` [PATCH v2 2/2] hwmon: (pmbus/bpa-rs600) Add workaround for incorrect Pin max Chris Packham
  0 siblings, 2 replies; 5+ messages in thread
From: Chris Packham @ 2021-08-12  1:39 UTC (permalink / raw)
  To: linux, jdelvare; +Cc: linux-hwmon, linux-kernel, Chris Packham

This series should apply cleanly without the BPD-RS600 support[1] which is in
Guenter's tree by hasn't made it to Linus' yet. Patch 2/2 technically fixes a
problem that is only present on the BPD-RS600. Patch 1/2 might need to head to
stable but it's probably not the end of the world if it doesn't.

[1] - https://lore.kernel.org/linux-hwmon/20210708220618.23576-1-chris.packham@alliedtelesis.co.nz/

Chris Packham (2):
  hwmon: (pmbus/bpa-rs600) Don't use rated limits as warn limits
  hwmon: (pmbus/bpa-rs600) Add workaround for incorrect Pin max

 drivers/hwmon/pmbus/bpa-rs600.c | 48 ++++++++++++++++-----------------
 1 file changed, 23 insertions(+), 25 deletions(-)

-- 
2.32.0


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

* [PATCH v2 1/2] hwmon: (pmbus/bpa-rs600) Don't use rated limits as warn limits
  2021-08-12  1:39 [PATCH v2 0/2] hwmon: (pmbus/bpa-rs600) cleanup and workaround Chris Packham
@ 2021-08-12  1:39 ` Chris Packham
  2021-08-12  4:40   ` Guenter Roeck
  2021-08-12  1:40 ` [PATCH v2 2/2] hwmon: (pmbus/bpa-rs600) Add workaround for incorrect Pin max Chris Packham
  1 sibling, 1 reply; 5+ messages in thread
From: Chris Packham @ 2021-08-12  1:39 UTC (permalink / raw)
  To: linux, jdelvare; +Cc: linux-hwmon, linux-kernel, Chris Packham

In the initial implementation a number of PMBUS_x_WARN_LIMITs were
mapped to MFR fields. This was incorrect as these MFR limits reflect the
rated limit as opposed to a limit which will generate warning. Instead
return -ENXIO like we were already doing for other WARN_LIMITs.

Subsequently these rated limits have been exposed generically as new
fields in the sysfs ABI so the values are still available.

Fixes: 15b2703e5e02 ("hwmon: (pmbus) Add driver for BluTek BPA-RS600")
Signed-off-by: Chris Packham <chris.packham@alliedtelesis.co.nz>
---

Notes:
    Changes in v2:
    - Reworked to remove the mapping of warning limits to rated limits.

 drivers/hwmon/pmbus/bpa-rs600.c | 25 -------------------------
 1 file changed, 25 deletions(-)

diff --git a/drivers/hwmon/pmbus/bpa-rs600.c b/drivers/hwmon/pmbus/bpa-rs600.c
index d205b41540ce..84dee86399cb 100644
--- a/drivers/hwmon/pmbus/bpa-rs600.c
+++ b/drivers/hwmon/pmbus/bpa-rs600.c
@@ -12,15 +12,6 @@
 #include <linux/pmbus.h>
 #include "pmbus.h"
 
-#define BPARS600_MFR_VIN_MIN	0xa0
-#define BPARS600_MFR_VIN_MAX	0xa1
-#define BPARS600_MFR_IIN_MAX	0xa2
-#define BPARS600_MFR_PIN_MAX	0xa3
-#define BPARS600_MFR_VOUT_MIN	0xa4
-#define BPARS600_MFR_VOUT_MAX	0xa5
-#define BPARS600_MFR_IOUT_MAX	0xa6
-#define BPARS600_MFR_POUT_MAX	0xa7
-
 enum chips { bpa_rs600, bpd_rs600 };
 
 static int bpa_rs600_read_byte_data(struct i2c_client *client, int page, int reg)
@@ -83,29 +74,13 @@ static int bpa_rs600_read_word_data(struct i2c_client *client, int page, int pha
 
 	switch (reg) {
 	case PMBUS_VIN_UV_WARN_LIMIT:
-		ret = pmbus_read_word_data(client, 0, 0xff, BPARS600_MFR_VIN_MIN);
-		break;
 	case PMBUS_VIN_OV_WARN_LIMIT:
-		ret = pmbus_read_word_data(client, 0, 0xff, BPARS600_MFR_VIN_MAX);
-		break;
 	case PMBUS_VOUT_UV_WARN_LIMIT:
-		ret = pmbus_read_word_data(client, 0, 0xff, BPARS600_MFR_VOUT_MIN);
-		break;
 	case PMBUS_VOUT_OV_WARN_LIMIT:
-		ret = pmbus_read_word_data(client, 0, 0xff, BPARS600_MFR_VOUT_MAX);
-		break;
 	case PMBUS_IIN_OC_WARN_LIMIT:
-		ret = pmbus_read_word_data(client, 0, 0xff, BPARS600_MFR_IIN_MAX);
-		break;
 	case PMBUS_IOUT_OC_WARN_LIMIT:
-		ret = pmbus_read_word_data(client, 0, 0xff, BPARS600_MFR_IOUT_MAX);
-		break;
 	case PMBUS_PIN_OP_WARN_LIMIT:
-		ret = pmbus_read_word_data(client, 0, 0xff, BPARS600_MFR_PIN_MAX);
-		break;
 	case PMBUS_POUT_OP_WARN_LIMIT:
-		ret = pmbus_read_word_data(client, 0, 0xff, BPARS600_MFR_POUT_MAX);
-		break;
 	case PMBUS_VIN_UV_FAULT_LIMIT:
 	case PMBUS_VIN_OV_FAULT_LIMIT:
 	case PMBUS_VOUT_UV_FAULT_LIMIT:
-- 
2.32.0


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

* [PATCH v2 2/2] hwmon: (pmbus/bpa-rs600) Add workaround for incorrect Pin max
  2021-08-12  1:39 [PATCH v2 0/2] hwmon: (pmbus/bpa-rs600) cleanup and workaround Chris Packham
  2021-08-12  1:39 ` [PATCH v2 1/2] hwmon: (pmbus/bpa-rs600) Don't use rated limits as warn limits Chris Packham
@ 2021-08-12  1:40 ` Chris Packham
  2021-08-12  4:41   ` Guenter Roeck
  1 sibling, 1 reply; 5+ messages in thread
From: Chris Packham @ 2021-08-12  1:40 UTC (permalink / raw)
  To: linux, jdelvare; +Cc: linux-hwmon, linux-kernel, Chris Packham

BPD-RS600 modules running firmware v5.70 misreport the MFR_PIN_MAX.
The indicate a maximum of 1640W instead of 700W. Detect the invalid
reading and return a sensible value instead.

Signed-off-by: Chris Packham <chris.packham@alliedtelesis.co.nz>
---

Notes:
    Changes in v2:
    - Add comments for magic values

 drivers/hwmon/pmbus/bpa-rs600.c | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)

diff --git a/drivers/hwmon/pmbus/bpa-rs600.c b/drivers/hwmon/pmbus/bpa-rs600.c
index 84dee86399cb..f2d4e378a775 100644
--- a/drivers/hwmon/pmbus/bpa-rs600.c
+++ b/drivers/hwmon/pmbus/bpa-rs600.c
@@ -65,6 +65,26 @@ static int bpa_rs600_read_vin(struct i2c_client *client)
 	return ret;
 }
 
+/*
+ * Firmware V5.70 incorrectly reports 1640W for MFR_PIN_MAX.
+ * Deal with this by returning a sensible value.
+ */
+static int bpa_rs600_read_pin_max(struct i2c_client *client)
+{
+	int ret;
+
+	ret = pmbus_read_word_data(client, 0, 0xff, PMBUS_MFR_PIN_MAX);
+	if (ret < 0)
+		return ret;
+
+	/* Detect invalid 1640W (linear encoding) */
+	if (ret == 0x0b34)
+		/* Report 700W (linear encoding) */
+		return 0x095e;
+
+	return ret;
+}
+
 static int bpa_rs600_read_word_data(struct i2c_client *client, int page, int phase, int reg)
 {
 	int ret;
@@ -91,6 +111,9 @@ static int bpa_rs600_read_word_data(struct i2c_client *client, int page, int pha
 	case PMBUS_READ_VIN:
 		ret = bpa_rs600_read_vin(client);
 		break;
+	case PMBUS_MFR_PIN_MAX:
+		ret = bpa_rs600_read_pin_max(client);
+		break;
 	default:
 		if (reg >= PMBUS_VIRT_BASE)
 			ret = -ENXIO;
-- 
2.32.0


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

* Re: [PATCH v2 1/2] hwmon: (pmbus/bpa-rs600) Don't use rated limits as warn limits
  2021-08-12  1:39 ` [PATCH v2 1/2] hwmon: (pmbus/bpa-rs600) Don't use rated limits as warn limits Chris Packham
@ 2021-08-12  4:40   ` Guenter Roeck
  0 siblings, 0 replies; 5+ messages in thread
From: Guenter Roeck @ 2021-08-12  4:40 UTC (permalink / raw)
  To: Chris Packham; +Cc: jdelvare, linux-hwmon, linux-kernel

On Thu, Aug 12, 2021 at 01:39:59PM +1200, Chris Packham wrote:
> In the initial implementation a number of PMBUS_x_WARN_LIMITs were
> mapped to MFR fields. This was incorrect as these MFR limits reflect the
> rated limit as opposed to a limit which will generate warning. Instead
> return -ENXIO like we were already doing for other WARN_LIMITs.
> 
> Subsequently these rated limits have been exposed generically as new
> fields in the sysfs ABI so the values are still available.
> 
> Fixes: 15b2703e5e02 ("hwmon: (pmbus) Add driver for BluTek BPA-RS600")
> Signed-off-by: Chris Packham <chris.packham@alliedtelesis.co.nz>

Applied.

Thanks,
Guenter

> ---
> 
> Notes:
>     Changes in v2:
>     - Reworked to remove the mapping of warning limits to rated limits.
> 
>  drivers/hwmon/pmbus/bpa-rs600.c | 25 -------------------------
>  1 file changed, 25 deletions(-)
> 
> diff --git a/drivers/hwmon/pmbus/bpa-rs600.c b/drivers/hwmon/pmbus/bpa-rs600.c
> index d205b41540ce..84dee86399cb 100644
> --- a/drivers/hwmon/pmbus/bpa-rs600.c
> +++ b/drivers/hwmon/pmbus/bpa-rs600.c
> @@ -12,15 +12,6 @@
>  #include <linux/pmbus.h>
>  #include "pmbus.h"
>  
> -#define BPARS600_MFR_VIN_MIN	0xa0
> -#define BPARS600_MFR_VIN_MAX	0xa1
> -#define BPARS600_MFR_IIN_MAX	0xa2
> -#define BPARS600_MFR_PIN_MAX	0xa3
> -#define BPARS600_MFR_VOUT_MIN	0xa4
> -#define BPARS600_MFR_VOUT_MAX	0xa5
> -#define BPARS600_MFR_IOUT_MAX	0xa6
> -#define BPARS600_MFR_POUT_MAX	0xa7
> -
>  enum chips { bpa_rs600, bpd_rs600 };
>  
>  static int bpa_rs600_read_byte_data(struct i2c_client *client, int page, int reg)
> @@ -83,29 +74,13 @@ static int bpa_rs600_read_word_data(struct i2c_client *client, int page, int pha
>  
>  	switch (reg) {
>  	case PMBUS_VIN_UV_WARN_LIMIT:
> -		ret = pmbus_read_word_data(client, 0, 0xff, BPARS600_MFR_VIN_MIN);
> -		break;
>  	case PMBUS_VIN_OV_WARN_LIMIT:
> -		ret = pmbus_read_word_data(client, 0, 0xff, BPARS600_MFR_VIN_MAX);
> -		break;
>  	case PMBUS_VOUT_UV_WARN_LIMIT:
> -		ret = pmbus_read_word_data(client, 0, 0xff, BPARS600_MFR_VOUT_MIN);
> -		break;
>  	case PMBUS_VOUT_OV_WARN_LIMIT:
> -		ret = pmbus_read_word_data(client, 0, 0xff, BPARS600_MFR_VOUT_MAX);
> -		break;
>  	case PMBUS_IIN_OC_WARN_LIMIT:
> -		ret = pmbus_read_word_data(client, 0, 0xff, BPARS600_MFR_IIN_MAX);
> -		break;
>  	case PMBUS_IOUT_OC_WARN_LIMIT:
> -		ret = pmbus_read_word_data(client, 0, 0xff, BPARS600_MFR_IOUT_MAX);
> -		break;
>  	case PMBUS_PIN_OP_WARN_LIMIT:
> -		ret = pmbus_read_word_data(client, 0, 0xff, BPARS600_MFR_PIN_MAX);
> -		break;
>  	case PMBUS_POUT_OP_WARN_LIMIT:
> -		ret = pmbus_read_word_data(client, 0, 0xff, BPARS600_MFR_POUT_MAX);
> -		break;
>  	case PMBUS_VIN_UV_FAULT_LIMIT:
>  	case PMBUS_VIN_OV_FAULT_LIMIT:
>  	case PMBUS_VOUT_UV_FAULT_LIMIT:

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

* Re: [PATCH v2 2/2] hwmon: (pmbus/bpa-rs600) Add workaround for incorrect Pin max
  2021-08-12  1:40 ` [PATCH v2 2/2] hwmon: (pmbus/bpa-rs600) Add workaround for incorrect Pin max Chris Packham
@ 2021-08-12  4:41   ` Guenter Roeck
  0 siblings, 0 replies; 5+ messages in thread
From: Guenter Roeck @ 2021-08-12  4:41 UTC (permalink / raw)
  To: Chris Packham; +Cc: jdelvare, linux-hwmon, linux-kernel

On Thu, Aug 12, 2021 at 01:40:00PM +1200, Chris Packham wrote:
> BPD-RS600 modules running firmware v5.70 misreport the MFR_PIN_MAX.
> The indicate a maximum of 1640W instead of 700W. Detect the invalid
> reading and return a sensible value instead.
> 
> Signed-off-by: Chris Packham <chris.packham@alliedtelesis.co.nz>

Applied.

Thanks,
Guenter

> ---
> 
> Notes:
>     Changes in v2:
>     - Add comments for magic values
> 
>  drivers/hwmon/pmbus/bpa-rs600.c | 23 +++++++++++++++++++++++
>  1 file changed, 23 insertions(+)
> 
> diff --git a/drivers/hwmon/pmbus/bpa-rs600.c b/drivers/hwmon/pmbus/bpa-rs600.c
> index 84dee86399cb..f2d4e378a775 100644
> --- a/drivers/hwmon/pmbus/bpa-rs600.c
> +++ b/drivers/hwmon/pmbus/bpa-rs600.c
> @@ -65,6 +65,26 @@ static int bpa_rs600_read_vin(struct i2c_client *client)
>  	return ret;
>  }
>  
> +/*
> + * Firmware V5.70 incorrectly reports 1640W for MFR_PIN_MAX.
> + * Deal with this by returning a sensible value.
> + */
> +static int bpa_rs600_read_pin_max(struct i2c_client *client)
> +{
> +	int ret;
> +
> +	ret = pmbus_read_word_data(client, 0, 0xff, PMBUS_MFR_PIN_MAX);
> +	if (ret < 0)
> +		return ret;
> +
> +	/* Detect invalid 1640W (linear encoding) */
> +	if (ret == 0x0b34)
> +		/* Report 700W (linear encoding) */
> +		return 0x095e;
> +
> +	return ret;
> +}
> +
>  static int bpa_rs600_read_word_data(struct i2c_client *client, int page, int phase, int reg)
>  {
>  	int ret;
> @@ -91,6 +111,9 @@ static int bpa_rs600_read_word_data(struct i2c_client *client, int page, int pha
>  	case PMBUS_READ_VIN:
>  		ret = bpa_rs600_read_vin(client);
>  		break;
> +	case PMBUS_MFR_PIN_MAX:
> +		ret = bpa_rs600_read_pin_max(client);
> +		break;
>  	default:
>  		if (reg >= PMBUS_VIRT_BASE)
>  			ret = -ENXIO;

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

end of thread, other threads:[~2021-08-12  4:41 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-12  1:39 [PATCH v2 0/2] hwmon: (pmbus/bpa-rs600) cleanup and workaround Chris Packham
2021-08-12  1:39 ` [PATCH v2 1/2] hwmon: (pmbus/bpa-rs600) Don't use rated limits as warn limits Chris Packham
2021-08-12  4:40   ` Guenter Roeck
2021-08-12  1:40 ` [PATCH v2 2/2] hwmon: (pmbus/bpa-rs600) Add workaround for incorrect Pin max Chris Packham
2021-08-12  4:41   ` Guenter Roeck

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).