Linux-Hwmon Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH v5 0/2] hwmon: scmi: Scale values to target desired HWMON units
@ 2019-05-08 18:46 Florian Fainelli
  2019-05-08 18:46 ` [PATCH v5 1/2] firmware: arm_scmi: Fetch and store sensor scale Florian Fainelli
  2019-05-08 18:46 ` [PATCH v5 2/2] hwmon: scmi: Scale values to target desired HWMON units Florian Fainelli
  0 siblings, 2 replies; 10+ messages in thread
From: Florian Fainelli @ 2019-05-08 18:46 UTC (permalink / raw)
  To: linux-kernel
  Cc: bcm-kernel-feedback-list, Florian Fainelli, Sudeep Holla,
	Jean Delvare, Guenter Roeck, linux-arm-kernel, linux-hwmon

Hi Sudeep, Guenter,

This patch series adds support for scaling SCMI sensor values read from
firmware. Sudeep, let me know if you think we should be treating scale
== 0 as a special value to preserve some firmware compatibility (not
that this would be desired).

Changes in v5:
- overflow check would not work, so check specifically for an absolute
  scale being greater than 19 to avoid returning an incorrect power of
  10 factor
- fixed incorrect value argument passed to scmi_hwmon_scale().
- Added Guenter's Reviewed-by tag on the first patch

Changes in v4:
- deal with overflow in the caller of __pow10() as suggested by Guenter
  which makes us rework a bit how the value argument/return value are
  passed
- don't harcode the latest power of 10 factor to be 18, just rely on
  overflowing the u64 value instead

Changes in v3:

- add a local __pow10 function to scmi-hwmon.c while a plan to provide
  a generic function is figured out.
- add check on power > 18 which would overflow a 64-bit unsigned integer
- use div64_u64() to properly divide a 64-bit quantity with an unsigned
  64-bit quantity

Changes in v2:

- added a helper function in kernel.h: __pow10()
- made the scale in scmi_sensor_info an s8 type, added defines for
  checking the sign bit and sign extending with a mask
- simplify computations in hwmon driver

Florian Fainelli (2):
  firmware: arm_scmi: Fetch and store sensor scale
  hwmon: scmi: Scale values to target desired HWMON units

 drivers/firmware/arm_scmi/sensors.c |  6 ++++
 drivers/hwmon/scmi-hwmon.c          | 45 +++++++++++++++++++++++++++++
 include/linux/scmi_protocol.h       |  1 +
 3 files changed, 52 insertions(+)

-- 
2.17.1


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

* [PATCH v5 1/2] firmware: arm_scmi: Fetch and store sensor scale
  2019-05-08 18:46 [PATCH v5 0/2] hwmon: scmi: Scale values to target desired HWMON units Florian Fainelli
@ 2019-05-08 18:46 ` Florian Fainelli
  2019-05-08 18:46 ` [PATCH v5 2/2] hwmon: scmi: Scale values to target desired HWMON units Florian Fainelli
  1 sibling, 0 replies; 10+ messages in thread
From: Florian Fainelli @ 2019-05-08 18:46 UTC (permalink / raw)
  To: linux-kernel
  Cc: bcm-kernel-feedback-list, Florian Fainelli, Sudeep Holla,
	Jean Delvare, Guenter Roeck, linux-arm-kernel, linux-hwmon

In preparation for dealing with scales within the SCMI HWMON driver,
fetch and store the sensor unit scale into the scmi_sensor_info
structure. In order to simplify computations for upper layer, take care
of sign extending the scale to a full 8-bit signed value.

Reviewed-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Florian Fainelli <f.fainelli@gmail.com>
---
 drivers/firmware/arm_scmi/sensors.c | 6 ++++++
 include/linux/scmi_protocol.h       | 1 +
 2 files changed, 7 insertions(+)

diff --git a/drivers/firmware/arm_scmi/sensors.c b/drivers/firmware/arm_scmi/sensors.c
index b53d5cc9c9f6..21353470a740 100644
--- a/drivers/firmware/arm_scmi/sensors.c
+++ b/drivers/firmware/arm_scmi/sensors.c
@@ -34,6 +34,8 @@ struct scmi_msg_resp_sensor_description {
 		__le32 attributes_high;
 #define SENSOR_TYPE(x)		((x) & 0xff)
 #define SENSOR_SCALE(x)		(((x) >> 11) & 0x3f)
+#define SENSOR_SCALE_SIGN	BIT(5)
+#define SENSOR_SCALE_EXTEND	GENMASK(7, 6)
 #define SENSOR_UPDATE_SCALE(x)	(((x) >> 22) & 0x1f)
 #define SENSOR_UPDATE_BASE(x)	(((x) >> 27) & 0x1f)
 		    u8 name[SCMI_MAX_STR_SIZE];
@@ -140,6 +142,10 @@ static int scmi_sensor_description_get(const struct scmi_handle *handle,
 			s = &si->sensors[desc_index + cnt];
 			s->id = le32_to_cpu(buf->desc[cnt].id);
 			s->type = SENSOR_TYPE(attrh);
+			s->scale = SENSOR_SCALE(attrh);
+			/* Sign extend to a full s8 */
+			if (s->scale & SENSOR_SCALE_SIGN)
+				s->scale |= SENSOR_SCALE_EXTEND;
 			strlcpy(s->name, buf->desc[cnt].name, SCMI_MAX_STR_SIZE);
 		}
 
diff --git a/include/linux/scmi_protocol.h b/include/linux/scmi_protocol.h
index 3105055c00a7..9ff2e9357e9a 100644
--- a/include/linux/scmi_protocol.h
+++ b/include/linux/scmi_protocol.h
@@ -144,6 +144,7 @@ struct scmi_power_ops {
 struct scmi_sensor_info {
 	u32 id;
 	u8 type;
+	s8 scale;
 	char name[SCMI_MAX_STR_SIZE];
 };
 
-- 
2.17.1


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

* [PATCH v5 2/2] hwmon: scmi: Scale values to target desired HWMON units
  2019-05-08 18:46 [PATCH v5 0/2] hwmon: scmi: Scale values to target desired HWMON units Florian Fainelli
  2019-05-08 18:46 ` [PATCH v5 1/2] firmware: arm_scmi: Fetch and store sensor scale Florian Fainelli
@ 2019-05-08 18:46 ` Florian Fainelli
  2019-05-08 21:10   ` Guenter Roeck
  2019-05-14 16:37   ` Sudeep Holla
  1 sibling, 2 replies; 10+ messages in thread
From: Florian Fainelli @ 2019-05-08 18:46 UTC (permalink / raw)
  To: linux-kernel
  Cc: bcm-kernel-feedback-list, Florian Fainelli, Sudeep Holla,
	Jean Delvare, Guenter Roeck, linux-arm-kernel, linux-hwmon

If the SCMI firmware implementation is reporting values in a scale that
is different from the HWMON units, we need to scale up or down the value
according to how far appart they are.

Signed-off-by: Florian Fainelli <f.fainelli@gmail.com>
---
 drivers/hwmon/scmi-hwmon.c | 45 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 45 insertions(+)

diff --git a/drivers/hwmon/scmi-hwmon.c b/drivers/hwmon/scmi-hwmon.c
index a80183a488c5..2c7b87edf5aa 100644
--- a/drivers/hwmon/scmi-hwmon.c
+++ b/drivers/hwmon/scmi-hwmon.c
@@ -18,6 +18,47 @@ struct scmi_sensors {
 	const struct scmi_sensor_info **info[hwmon_max];
 };
 
+static inline u64 __pow10(u8 x)
+{
+	u64 r = 1;
+
+	while (x--)
+		r *= 10;
+
+	return r;
+}
+
+static int scmi_hwmon_scale(const struct scmi_sensor_info *sensor, u64 *value)
+{
+	s8 scale = sensor->scale;
+	u64 f;
+
+	switch (sensor->type) {
+	case TEMPERATURE_C:
+	case VOLTAGE:
+	case CURRENT:
+		scale += 3;
+		break;
+	case POWER:
+	case ENERGY:
+		scale += 6;
+		break;
+	default:
+		break;
+	}
+
+	if (abs(scale) > 19)
+		return -E2BIG;
+
+	f = __pow10(abs(scale));
+	if (scale > 0)
+		*value *= f;
+	else
+		*value = div64_u64(*value, f);
+
+        return 0;
+}
+
 static int scmi_hwmon_read(struct device *dev, enum hwmon_sensor_types type,
 			   u32 attr, int channel, long *val)
 {
@@ -29,6 +70,10 @@ static int scmi_hwmon_read(struct device *dev, enum hwmon_sensor_types type,
 
 	sensor = *(scmi_sensors->info[type] + channel);
 	ret = h->sensor_ops->reading_get(h, sensor->id, false, &value);
+	if (ret)
+		return ret;
+
+	ret = scmi_hwmon_scale(sensor, &value);
 	if (!ret)
 		*val = value;
 
-- 
2.17.1


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

* Re: [PATCH v5 2/2] hwmon: scmi: Scale values to target desired HWMON units
  2019-05-08 18:46 ` [PATCH v5 2/2] hwmon: scmi: Scale values to target desired HWMON units Florian Fainelli
@ 2019-05-08 21:10   ` Guenter Roeck
  2019-05-13 18:10     ` Florian Fainelli
  2019-05-14 16:37   ` Sudeep Holla
  1 sibling, 1 reply; 10+ messages in thread
From: Guenter Roeck @ 2019-05-08 21:10 UTC (permalink / raw)
  To: Florian Fainelli
  Cc: linux-kernel, bcm-kernel-feedback-list, Sudeep Holla,
	Jean Delvare, linux-arm-kernel, open list:HARDWARE MONITORING

On Wed, May 08, 2019 at 11:46:35AM -0700, Florian Fainelli wrote:
> If the SCMI firmware implementation is reporting values in a scale that
> is different from the HWMON units, we need to scale up or down the value
> according to how far appart they are.
> 
> Signed-off-by: Florian Fainelli <f.fainelli@gmail.com>

Reviewed-by: Guenter Roeck <linux@roeck-us.net>

Question is which tree this series should go through. I am fine with arm.

Thanks,
Guenter

> ---
>  drivers/hwmon/scmi-hwmon.c | 45 ++++++++++++++++++++++++++++++++++++++
>  1 file changed, 45 insertions(+)
> 
> diff --git a/drivers/hwmon/scmi-hwmon.c b/drivers/hwmon/scmi-hwmon.c
> index a80183a488c5..2c7b87edf5aa 100644
> --- a/drivers/hwmon/scmi-hwmon.c
> +++ b/drivers/hwmon/scmi-hwmon.c
> @@ -18,6 +18,47 @@ struct scmi_sensors {
>  	const struct scmi_sensor_info **info[hwmon_max];
>  };
>  
> +static inline u64 __pow10(u8 x)
> +{
> +	u64 r = 1;
> +
> +	while (x--)
> +		r *= 10;
> +
> +	return r;
> +}
> +
> +static int scmi_hwmon_scale(const struct scmi_sensor_info *sensor, u64 *value)
> +{
> +	s8 scale = sensor->scale;
> +	u64 f;
> +
> +	switch (sensor->type) {
> +	case TEMPERATURE_C:
> +	case VOLTAGE:
> +	case CURRENT:
> +		scale += 3;
> +		break;
> +	case POWER:
> +	case ENERGY:
> +		scale += 6;
> +		break;
> +	default:
> +		break;
> +	}
> +
> +	if (abs(scale) > 19)
> +		return -E2BIG;
> +
> +	f = __pow10(abs(scale));
> +	if (scale > 0)
> +		*value *= f;
> +	else
> +		*value = div64_u64(*value, f);
> +
> +        return 0;
> +}
> +
>  static int scmi_hwmon_read(struct device *dev, enum hwmon_sensor_types type,
>  			   u32 attr, int channel, long *val)
>  {
> @@ -29,6 +70,10 @@ static int scmi_hwmon_read(struct device *dev, enum hwmon_sensor_types type,
>  
>  	sensor = *(scmi_sensors->info[type] + channel);
>  	ret = h->sensor_ops->reading_get(h, sensor->id, false, &value);
> +	if (ret)
> +		return ret;
> +
> +	ret = scmi_hwmon_scale(sensor, &value);
>  	if (!ret)
>  		*val = value;
>  
> -- 
> 2.17.1
> 

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

* Re: [PATCH v5 2/2] hwmon: scmi: Scale values to target desired HWMON units
  2019-05-08 21:10   ` Guenter Roeck
@ 2019-05-13 18:10     ` Florian Fainelli
  2019-05-14 10:38       ` Sudeep Holla
  0 siblings, 1 reply; 10+ messages in thread
From: Florian Fainelli @ 2019-05-13 18:10 UTC (permalink / raw)
  To: Guenter Roeck, Florian Fainelli
  Cc: linux-kernel, bcm-kernel-feedback-list, Sudeep Holla,
	Jean Delvare, linux-arm-kernel, open list:HARDWARE MONITORING

On 5/8/19 2:10 PM, Guenter Roeck wrote:
> On Wed, May 08, 2019 at 11:46:35AM -0700, Florian Fainelli wrote:
>> If the SCMI firmware implementation is reporting values in a scale that
>> is different from the HWMON units, we need to scale up or down the value
>> according to how far appart they are.
>>
>> Signed-off-by: Florian Fainelli <f.fainelli@gmail.com>
> 
> Reviewed-by: Guenter Roeck <linux@roeck-us.net>
> 
> Question is which tree this series should go through. I am fine with arm.

Fine with me as well, Sudeep are you picking up these patches or should
they go through HWMON and Guenter?
-- 
Florian

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

* Re: [PATCH v5 2/2] hwmon: scmi: Scale values to target desired HWMON units
  2019-05-13 18:10     ` Florian Fainelli
@ 2019-05-14 10:38       ` Sudeep Holla
  0 siblings, 0 replies; 10+ messages in thread
From: Sudeep Holla @ 2019-05-14 10:38 UTC (permalink / raw)
  To: Florian Fainelli
  Cc: Guenter Roeck, linux-kernel, bcm-kernel-feedback-list,
	Jean Delvare, linux-arm-kernel, open list:HARDWARE MONITORING

On Mon, May 13, 2019 at 11:10:28AM -0700, Florian Fainelli wrote:
> On 5/8/19 2:10 PM, Guenter Roeck wrote:
> > On Wed, May 08, 2019 at 11:46:35AM -0700, Florian Fainelli wrote:
> >> If the SCMI firmware implementation is reporting values in a scale that
> >> is different from the HWMON units, we need to scale up or down the value
> >> according to how far appart they are.
> >>
> >> Signed-off-by: Florian Fainelli <f.fainelli@gmail.com>
> > 
> > Reviewed-by: Guenter Roeck <linux@roeck-us.net>
> > 
> > Question is which tree this series should go through. I am fine with arm.
> 
> Fine with me as well, Sudeep are you picking up these patches or should
> they go through HWMON and Guenter?

Sure I can pick and send it to arm-soc for v5.3

--
Regards,
Sudeep

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

* Re: [PATCH v5 2/2] hwmon: scmi: Scale values to target desired HWMON units
  2019-05-08 18:46 ` [PATCH v5 2/2] hwmon: scmi: Scale values to target desired HWMON units Florian Fainelli
  2019-05-08 21:10   ` Guenter Roeck
@ 2019-05-14 16:37   ` Sudeep Holla
  2019-05-14 16:44     ` Florian Fainelli
  1 sibling, 1 reply; 10+ messages in thread
From: Sudeep Holla @ 2019-05-14 16:37 UTC (permalink / raw)
  To: Florian Fainelli
  Cc: linux-kernel, bcm-kernel-feedback-list, Jean Delvare,
	Guenter Roeck, linux-arm-kernel, open list:HARDWARE MONITORING,
	Sudeep Holla

On Wed, May 08, 2019 at 11:46:35AM -0700, Florian Fainelli wrote:
> If the SCMI firmware implementation is reporting values in a scale that
> is different from the HWMON units, we need to scale up or down the value
> according to how far appart they are.
> 
> Signed-off-by: Florian Fainelli <f.fainelli@gmail.com>
> ---
>  drivers/hwmon/scmi-hwmon.c | 45 ++++++++++++++++++++++++++++++++++++++
>  1 file changed, 45 insertions(+)
> 
> diff --git a/drivers/hwmon/scmi-hwmon.c b/drivers/hwmon/scmi-hwmon.c
> index a80183a488c5..2c7b87edf5aa 100644
> --- a/drivers/hwmon/scmi-hwmon.c
> +++ b/drivers/hwmon/scmi-hwmon.c
> @@ -18,6 +18,47 @@ struct scmi_sensors {
>  	const struct scmi_sensor_info **info[hwmon_max];
>  };
>  
> +static inline u64 __pow10(u8 x)
> +{
> +	u64 r = 1;
> +
> +	while (x--)
> +		r *= 10;
> +
> +	return r;
> +}
> +
> +static int scmi_hwmon_scale(const struct scmi_sensor_info *sensor, u64 *value)
> +{
> +	s8 scale = sensor->scale;
> +	u64 f;
> +
> +	switch (sensor->type) {
> +	case TEMPERATURE_C:
> +	case VOLTAGE:
> +	case CURRENT:
> +		scale += 3;
> +		break;
> +	case POWER:
> +	case ENERGY:
> +		scale += 6;
> +		break;
> +	default:
> +		break;
> +	}
> +

I was applying this and wanted to check if we can add a check for scale=0
here and return early here to above the below check and __pow10(0) ?

Let me know if you agree. I can fix up. Also I will try to test it on
Juno if firmware behaves correctly :)

--
Regards,
Sudeep

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

* Re: [PATCH v5 2/2] hwmon: scmi: Scale values to target desired HWMON units
  2019-05-14 16:37   ` Sudeep Holla
@ 2019-05-14 16:44     ` Florian Fainelli
  2019-05-14 16:58       ` Guenter Roeck
  0 siblings, 1 reply; 10+ messages in thread
From: Florian Fainelli @ 2019-05-14 16:44 UTC (permalink / raw)
  To: Sudeep Holla, Florian Fainelli
  Cc: linux-kernel, bcm-kernel-feedback-list, Jean Delvare,
	Guenter Roeck, linux-arm-kernel, open list:HARDWARE MONITORING

On 5/14/19 9:37 AM, Sudeep Holla wrote:
> On Wed, May 08, 2019 at 11:46:35AM -0700, Florian Fainelli wrote:
>> If the SCMI firmware implementation is reporting values in a scale that
>> is different from the HWMON units, we need to scale up or down the value
>> according to how far appart they are.
>>
>> Signed-off-by: Florian Fainelli <f.fainelli@gmail.com>
>> ---
>>  drivers/hwmon/scmi-hwmon.c | 45 ++++++++++++++++++++++++++++++++++++++
>>  1 file changed, 45 insertions(+)
>>
>> diff --git a/drivers/hwmon/scmi-hwmon.c b/drivers/hwmon/scmi-hwmon.c
>> index a80183a488c5..2c7b87edf5aa 100644
>> --- a/drivers/hwmon/scmi-hwmon.c
>> +++ b/drivers/hwmon/scmi-hwmon.c
>> @@ -18,6 +18,47 @@ struct scmi_sensors {
>>  	const struct scmi_sensor_info **info[hwmon_max];
>>  };
>>  
>> +static inline u64 __pow10(u8 x)
>> +{
>> +	u64 r = 1;
>> +
>> +	while (x--)
>> +		r *= 10;
>> +
>> +	return r;
>> +}
>> +
>> +static int scmi_hwmon_scale(const struct scmi_sensor_info *sensor, u64 *value)
>> +{
>> +	s8 scale = sensor->scale;
>> +	u64 f;
>> +
>> +	switch (sensor->type) {
>> +	case TEMPERATURE_C:
>> +	case VOLTAGE:
>> +	case CURRENT:
>> +		scale += 3;
>> +		break;
>> +	case POWER:
>> +	case ENERGY:
>> +		scale += 6;
>> +		break;
>> +	default:
>> +		break;
>> +	}
>> +
> 
> I was applying this and wanted to check if we can add a check for scale=0
> here and return early here to above the below check and __pow10(0) ?

Doing an early check for scale == 0 sounds like a good idea,good catch!
Feel free to amend the patch directly when you apply it.

> 
> Let me know if you agree. I can fix up. Also I will try to test it on
> Juno if firmware behaves correctly :)

Great, thanks.
-- 
Florian

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

* Re: [PATCH v5 2/2] hwmon: scmi: Scale values to target desired HWMON units
  2019-05-14 16:44     ` Florian Fainelli
@ 2019-05-14 16:58       ` Guenter Roeck
  2019-05-14 17:00         ` Sudeep Holla
  0 siblings, 1 reply; 10+ messages in thread
From: Guenter Roeck @ 2019-05-14 16:58 UTC (permalink / raw)
  To: Florian Fainelli
  Cc: Sudeep Holla, linux-kernel, bcm-kernel-feedback-list,
	Jean Delvare, linux-arm-kernel, open list:HARDWARE MONITORING

On Tue, May 14, 2019 at 09:44:02AM -0700, Florian Fainelli wrote:
> On 5/14/19 9:37 AM, Sudeep Holla wrote:
> > On Wed, May 08, 2019 at 11:46:35AM -0700, Florian Fainelli wrote:
> >> If the SCMI firmware implementation is reporting values in a scale that
> >> is different from the HWMON units, we need to scale up or down the value
> >> according to how far appart they are.
> >>
> >> Signed-off-by: Florian Fainelli <f.fainelli@gmail.com>
> >> ---
> >>  drivers/hwmon/scmi-hwmon.c | 45 ++++++++++++++++++++++++++++++++++++++
> >>  1 file changed, 45 insertions(+)
> >>
> >> diff --git a/drivers/hwmon/scmi-hwmon.c b/drivers/hwmon/scmi-hwmon.c
> >> index a80183a488c5..2c7b87edf5aa 100644
> >> --- a/drivers/hwmon/scmi-hwmon.c
> >> +++ b/drivers/hwmon/scmi-hwmon.c
> >> @@ -18,6 +18,47 @@ struct scmi_sensors {
> >>  	const struct scmi_sensor_info **info[hwmon_max];
> >>  };
> >>  
> >> +static inline u64 __pow10(u8 x)
> >> +{
> >> +	u64 r = 1;
> >> +
> >> +	while (x--)
> >> +		r *= 10;
> >> +
> >> +	return r;
> >> +}
> >> +
> >> +static int scmi_hwmon_scale(const struct scmi_sensor_info *sensor, u64 *value)
> >> +{
> >> +	s8 scale = sensor->scale;
> >> +	u64 f;
> >> +
> >> +	switch (sensor->type) {
> >> +	case TEMPERATURE_C:
> >> +	case VOLTAGE:
> >> +	case CURRENT:
> >> +		scale += 3;
> >> +		break;
> >> +	case POWER:
> >> +	case ENERGY:
> >> +		scale += 6;
> >> +		break;
> >> +	default:
> >> +		break;
> >> +	}
> >> +
> > 
> > I was applying this and wanted to check if we can add a check for scale=0
> > here and return early here to above the below check and __pow10(0) ?
> 
> Doing an early check for scale == 0 sounds like a good idea,good catch!
> Feel free to amend the patch directly when you apply it.
> 

Ok with me. Just make it == 0 :-).

Guenter

> > 
> > Let me know if you agree. I can fix up. Also I will try to test it on
> > Juno if firmware behaves correctly :)
> 
> Great, thanks.
> -- 
> Florian

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

* Re: [PATCH v5 2/2] hwmon: scmi: Scale values to target desired HWMON units
  2019-05-14 16:58       ` Guenter Roeck
@ 2019-05-14 17:00         ` Sudeep Holla
  0 siblings, 0 replies; 10+ messages in thread
From: Sudeep Holla @ 2019-05-14 17:00 UTC (permalink / raw)
  To: Guenter Roeck
  Cc: Florian Fainelli, linux-kernel, bcm-kernel-feedback-list,
	Jean Delvare, linux-arm-kernel, open list:HARDWARE MONITORING,
	Sudeep Holla

On Tue, May 14, 2019 at 09:58:06AM -0700, Guenter Roeck wrote:
> On Tue, May 14, 2019 at 09:44:02AM -0700, Florian Fainelli wrote:
> > On 5/14/19 9:37 AM, Sudeep Holla wrote:
> > > On Wed, May 08, 2019 at 11:46:35AM -0700, Florian Fainelli wrote:
> > >> If the SCMI firmware implementation is reporting values in a scale that
> > >> is different from the HWMON units, we need to scale up or down the value
> > >> according to how far appart they are.
> > >>
> > >> Signed-off-by: Florian Fainelli <f.fainelli@gmail.com>
> > >> ---
> > >>  drivers/hwmon/scmi-hwmon.c | 45 ++++++++++++++++++++++++++++++++++++++
> > >>  1 file changed, 45 insertions(+)
> > >>
> > >> diff --git a/drivers/hwmon/scmi-hwmon.c b/drivers/hwmon/scmi-hwmon.c
> > >> index a80183a488c5..2c7b87edf5aa 100644
> > >> --- a/drivers/hwmon/scmi-hwmon.c
> > >> +++ b/drivers/hwmon/scmi-hwmon.c
> > >> @@ -18,6 +18,47 @@ struct scmi_sensors {
> > >>  	const struct scmi_sensor_info **info[hwmon_max];
> > >>  };
> > >>
> > >> +static inline u64 __pow10(u8 x)
> > >> +{
> > >> +	u64 r = 1;
> > >> +
> > >> +	while (x--)
> > >> +		r *= 10;
> > >> +
> > >> +	return r;
> > >> +}
> > >> +
> > >> +static int scmi_hwmon_scale(const struct scmi_sensor_info *sensor, u64 *value)
> > >> +{
> > >> +	s8 scale = sensor->scale;
> > >> +	u64 f;
> > >> +
> > >> +	switch (sensor->type) {
> > >> +	case TEMPERATURE_C:
> > >> +	case VOLTAGE:
> > >> +	case CURRENT:
> > >> +		scale += 3;
> > >> +		break;
> > >> +	case POWER:
> > >> +	case ENERGY:
> > >> +		scale += 6;
> > >> +		break;
> > >> +	default:
> > >> +		break;
> > >> +	}
> > >> +
> > >
> > > I was applying this and wanted to check if we can add a check for scale=0
> > > here and return early here to above the below check and __pow10(0) ?
> >
> > Doing an early check for scale == 0 sounds like a good idea,good catch!
> > Feel free to amend the patch directly when you apply it.
> >
>
> Ok with me. Just make it == 0 :-).
>

Thanks Guenter and Florian for quick response, done now.

--
Regards,
Sudeep

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

end of thread, back to index

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-05-08 18:46 [PATCH v5 0/2] hwmon: scmi: Scale values to target desired HWMON units Florian Fainelli
2019-05-08 18:46 ` [PATCH v5 1/2] firmware: arm_scmi: Fetch and store sensor scale Florian Fainelli
2019-05-08 18:46 ` [PATCH v5 2/2] hwmon: scmi: Scale values to target desired HWMON units Florian Fainelli
2019-05-08 21:10   ` Guenter Roeck
2019-05-13 18:10     ` Florian Fainelli
2019-05-14 10:38       ` Sudeep Holla
2019-05-14 16:37   ` Sudeep Holla
2019-05-14 16:44     ` Florian Fainelli
2019-05-14 16:58       ` Guenter Roeck
2019-05-14 17:00         ` Sudeep Holla

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 linux-hwmon@archiver.kernel.org
	public-inbox-index linux-hwmon


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