diff mbox series

[v2,2/2] hwmon: (pmbus/bpa-rs600) Add workaround for incorrect Pin max

Message ID 20210812014000.26293-3-chris.packham@alliedtelesis.co.nz (mailing list archive)
State Accepted
Headers show
Series hwmon: (pmbus/bpa-rs600) cleanup and workaround | expand

Commit Message

Chris Packham Aug. 12, 2021, 1:40 a.m. UTC
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(+)

Comments

Guenter Roeck Aug. 12, 2021, 4:41 a.m. UTC | #1
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;
diff mbox series

Patch

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;