2022-08-01 15:08:48

by Dmitry Rokosov

[permalink] [raw]
Subject: [PATCH v3 0/3] units: complement the set of Hz units

During msa311 accel IIO driver development

https://lore.kernel.org/linux-iio/[email protected]/

Andy requested to use proper units in the hz->ms calculation. Current
units.h header doesn't have milli, micro and nano HZ coefficients, so
some drivers (in the IIO subsystem) implement their own copies for that.

The current patchset resolves such a problem and intoduces general
MILLIHZ_PER_HZ, MICROHZ_PER_HZ and NANOHZ_PER_HZ definitions in the units.h,
and fixes all drivers which duplicate these units.

Changes:
* v2->v3:
- changed UHZ_PER_HZ to MICROHZ_PER_HZ and NHZ_PER_HZ to
NANOHZ_PER_HZ to save name consistency for all new HZ units

* v1->v2:
- changed MHZ_PER_HZ to a different name as Andy suggested
(suppose MILLIHZ_PER_HZ is good enough)

Dmitry Rokosov (3):
units: complement the set of Hz units
iio: accel: adxl345: use HZ macro from units.h
iio: common: scmi_sensors: use HZ macro from units.h

drivers/iio/accel/adxl345_core.c | 7 ++++---
drivers/iio/common/scmi_sensors/scmi_iio.c | 8 ++++----
include/linux/units.h | 3 +++
3 files changed, 11 insertions(+), 7 deletions(-)

--
2.36.0


2022-08-01 15:32:12

by Dmitry Rokosov

[permalink] [raw]
Subject: [PATCH v3 3/3] iio: common: scmi_sensors: use HZ macro from units.h

Remove duplicated definition of UHZ_PER_HZ, because it's available in
the units.h as MICROHZ_PER_HZ.

Signed-off-by: Dmitry Rokosov <[email protected]>
Reviewed-by: Andy Shevchenko <[email protected]>
---
drivers/iio/common/scmi_sensors/scmi_iio.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/iio/common/scmi_sensors/scmi_iio.c b/drivers/iio/common/scmi_sensors/scmi_iio.c
index 793d628db55f..54ccf19ab2bb 100644
--- a/drivers/iio/common/scmi_sensors/scmi_iio.c
+++ b/drivers/iio/common/scmi_sensors/scmi_iio.c
@@ -18,6 +18,7 @@
#include <linux/scmi_protocol.h>
#include <linux/time.h>
#include <linux/types.h>
+#include <linux/units.h>

#define SCMI_IIO_NUM_OF_AXIS 3

@@ -130,7 +131,6 @@ static const struct iio_buffer_setup_ops scmi_iio_buffer_ops = {
static int scmi_iio_set_odr_val(struct iio_dev *iio_dev, int val, int val2)
{
struct scmi_iio_priv *sensor = iio_priv(iio_dev);
- const unsigned long UHZ_PER_HZ = 1000000UL;
u64 sec, mult, uHz, sf;
u32 sensor_config;
char buf[32];
@@ -145,7 +145,7 @@ static int scmi_iio_set_odr_val(struct iio_dev *iio_dev, int val, int val2)
return err;
}

- uHz = val * UHZ_PER_HZ + val2;
+ uHz = val * MICROHZ_PER_HZ + val2;

/*
* The seconds field in the sensor interval in SCMI is 16 bits long
@@ -156,10 +156,10 @@ static int scmi_iio_set_odr_val(struct iio_dev *iio_dev, int val, int val2)
* count the number of characters
*/
sf = (u64)uHz * 0xFFFF;
- do_div(sf, UHZ_PER_HZ);
+ do_div(sf, MICROHZ_PER_HZ);
mult = scnprintf(buf, sizeof(buf), "%llu", sf) - 1;

- sec = int_pow(10, mult) * UHZ_PER_HZ;
+ sec = int_pow(10, mult) * MICROHZ_PER_HZ;
do_div(sec, uHz);
if (sec == 0) {
dev_err(&iio_dev->dev,
--
2.36.0

2022-08-28 16:55:19

by Jonathan Cameron

[permalink] [raw]
Subject: Re: [PATCH v3 0/3] units: complement the set of Hz units

On Mon, 1 Aug 2022 14:37:23 +0000
Dmitry Rokosov <[email protected]> wrote:

> During msa311 accel IIO driver development
>
> https://lore.kernel.org/linux-iio/[email protected]/
>
> Andy requested to use proper units in the hz->ms calculation. Current
> units.h header doesn't have milli, micro and nano HZ coefficients, so
> some drivers (in the IIO subsystem) implement their own copies for that.
>
> The current patchset resolves such a problem and intoduces general
> MILLIHZ_PER_HZ, MICROHZ_PER_HZ and NANOHZ_PER_HZ definitions in the units.h,
> and fixes all drivers which duplicate these units.

Ok, I'm just about convinced this is worth doing given the precedence
of similar cases. Applied to the togreg branch of iio.git and pushed
out as testing.

Thanks,

Jonathan
>
> Changes:
> * v2->v3:
> - changed UHZ_PER_HZ to MICROHZ_PER_HZ and NHZ_PER_HZ to
> NANOHZ_PER_HZ to save name consistency for all new HZ units
>
> * v1->v2:
> - changed MHZ_PER_HZ to a different name as Andy suggested
> (suppose MILLIHZ_PER_HZ is good enough)
>
> Dmitry Rokosov (3):
> units: complement the set of Hz units
> iio: accel: adxl345: use HZ macro from units.h
> iio: common: scmi_sensors: use HZ macro from units.h
>
> drivers/iio/accel/adxl345_core.c | 7 ++++---
> drivers/iio/common/scmi_sensors/scmi_iio.c | 8 ++++----
> include/linux/units.h | 3 +++
> 3 files changed, 11 insertions(+), 7 deletions(-)
>