2022-07-25 18:54:37

by Dmitry Rokosov

[permalink] [raw]
Subject: [PATCH v1 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
MHZ_PER_HZ, UHZ_PER_HZ and NHZ_PER_HZ definitions in the units.h, and
fixes all drivers which duplicate these units.

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 | 2 +-
drivers/iio/common/scmi_sensors/scmi_iio.c | 2 +-
include/linux/units.h | 3 +++
3 files changed, 5 insertions(+), 2 deletions(-)

--
2.36.0


2022-07-25 18:54:47

by Dmitry Rokosov

[permalink] [raw]
Subject: [PATCH v1 2/3] iio: accel: adxl345: use HZ macro from units.h

Remove duplicate definition of NHZ_PER_HZ, because it's available in
the units.h.

Signed-off-by: Dmitry Rokosov <[email protected]>
---
drivers/iio/accel/adxl345_core.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/iio/accel/adxl345_core.c b/drivers/iio/accel/adxl345_core.c
index 370bfec1275a..94189133fe8f 100644
--- a/drivers/iio/accel/adxl345_core.c
+++ b/drivers/iio/accel/adxl345_core.c
@@ -10,6 +10,7 @@
#include <linux/module.h>
#include <linux/property.h>
#include <linux/regmap.h>
+#include <linux/units.h>

#include <linux/iio/iio.h>
#include <linux/iio/sysfs.h>
@@ -32,7 +33,6 @@

#define ADXL345_BW_RATE GENMASK(3, 0)
#define ADXL345_BASE_RATE_NANO_HZ 97656250LL
-#define NHZ_PER_HZ 1000000000LL

#define ADXL345_POWER_CTL_MEASURE BIT(3)
#define ADXL345_POWER_CTL_STANDBY 0x00
--
2.36.0

2022-07-25 19:11:31

by Dmitry Rokosov

[permalink] [raw]
Subject: [PATCH v1 1/3] units: complement the set of Hz units

Currently, Hz units do not have milli, micro and nano Hz coefficients.
Some drivers (IIO especially) use their analogues to calculate
appropriate Hz values. This patch includes them to units.h definitions,
so they can be used from different kernel places.

Signed-off-by: Dmitry Rokosov <[email protected]>
---
include/linux/units.h | 3 +++
1 file changed, 3 insertions(+)

diff --git a/include/linux/units.h b/include/linux/units.h
index 681fc652e3d7..900a642f0ff8 100644
--- a/include/linux/units.h
+++ b/include/linux/units.h
@@ -20,6 +20,9 @@
#define PICO 1000000000000ULL
#define FEMTO 1000000000000000ULL

+#define NHZ_PER_HZ 1000000000UL
+#define UHZ_PER_HZ 1000000UL
+#define MHZ_PER_HZ 1000UL
#define HZ_PER_KHZ 1000UL
#define KHZ_PER_MHZ 1000UL
#define HZ_PER_MHZ 1000000UL
--
2.36.0

2022-07-25 21:35:32

by Andy Shevchenko

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

On Mon, Jul 25, 2022 at 8:44 PM Dmitry Rokosov <[email protected]> wrote:
>
> Currently, Hz units do not have milli, micro and nano Hz coefficients.
> Some drivers (IIO especially) use their analogues to calculate
> appropriate Hz values. This patch includes them to units.h definitions,
> so they can be used from different kernel places.

...

> +#define NHZ_PER_HZ 1000000000UL
> +#define UHZ_PER_HZ 1000000UL
> +#define MHZ_PER_HZ 1000UL

mHZ perhaps?

> #define HZ_PER_KHZ 1000UL
> #define KHZ_PER_MHZ 1000UL
> #define HZ_PER_MHZ 1000000UL


--
With Best Regards,
Andy Shevchenko

2022-07-26 10:01:25

by Dmitry Rokosov

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

Hello Andy,

Thank you for quick review.

On Mon, Jul 25, 2022 at 11:29:31PM +0200, Andy Shevchenko wrote:
> On Mon, Jul 25, 2022 at 8:44 PM Dmitry Rokosov <[email protected]> wrote:
> >
> > Currently, Hz units do not have milli, micro and nano Hz coefficients.
> > Some drivers (IIO especially) use their analogues to calculate
> > appropriate Hz values. This patch includes them to units.h definitions,
> > so they can be used from different kernel places.
>
> ...
>
> > +#define NHZ_PER_HZ 1000000000UL
> > +#define UHZ_PER_HZ 1000000UL
> > +#define MHZ_PER_HZ 1000UL
>
> mHZ perhaps?
>

I'm afraid it will not have the same view as other HZ units.
Maybe it's better to call mHZ as MILLIHZ? What do you think?

--
Thank you,
Dmitry