* [PATCH v3 0/3] units: complement the set of Hz units
@ 2022-08-01 14:37 Dmitry Rokosov
2022-08-01 14:37 ` [PATCH v3 1/3] " Dmitry Rokosov
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: Dmitry Rokosov @ 2022-08-01 14:37 UTC (permalink / raw)
To: akpm@linux-foundation.org, andriy.shevchenko@linux.intel.com,
daniel.lezcano@linaro.org, jic23@kernel.org, wsa@kernel.org,
andy.shevchenko@gmail.com, lars@metafoo.de,
Michael.Hennerich@analog.com, jbhayana@google.com
Cc: linux-iio@vger.kernel.org, kernel, linux-kernel@vger.kernel.org,
Dmitry Rokosov
During msa311 accel IIO driver development
https://lore.kernel.org/linux-iio/20220616104211.9257-1-ddrokosov@sberdevices.ru/
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
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH v3 1/3] units: complement the set of Hz units
2022-08-01 14:37 [PATCH v3 0/3] units: complement the set of Hz units Dmitry Rokosov
@ 2022-08-01 14:37 ` Dmitry Rokosov
2022-08-01 14:37 ` [PATCH v3 2/3] iio: accel: adxl345: use HZ macro from units.h Dmitry Rokosov
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: Dmitry Rokosov @ 2022-08-01 14:37 UTC (permalink / raw)
To: akpm@linux-foundation.org, andriy.shevchenko@linux.intel.com,
daniel.lezcano@linaro.org, jic23@kernel.org, wsa@kernel.org,
andy.shevchenko@gmail.com, lars@metafoo.de,
Michael.Hennerich@analog.com, jbhayana@google.com
Cc: linux-iio@vger.kernel.org, kernel, linux-kernel@vger.kernel.org,
Dmitry Rokosov
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 <ddrokosov@sberdevices.ru>
---
include/linux/units.h | 3 +++
1 file changed, 3 insertions(+)
diff --git a/include/linux/units.h b/include/linux/units.h
index 681fc652e3d7..2793a41e73a2 100644
--- a/include/linux/units.h
+++ b/include/linux/units.h
@@ -20,6 +20,9 @@
#define PICO 1000000000000ULL
#define FEMTO 1000000000000000ULL
+#define NANOHZ_PER_HZ 1000000000UL
+#define MICROHZ_PER_HZ 1000000UL
+#define MILLIHZ_PER_HZ 1000UL
#define HZ_PER_KHZ 1000UL
#define KHZ_PER_MHZ 1000UL
#define HZ_PER_MHZ 1000000UL
--
2.36.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH v3 2/3] iio: accel: adxl345: use HZ macro from units.h
2022-08-01 14:37 [PATCH v3 0/3] units: complement the set of Hz units Dmitry Rokosov
2022-08-01 14:37 ` [PATCH v3 1/3] " Dmitry Rokosov
@ 2022-08-01 14:37 ` Dmitry Rokosov
2022-08-01 14:37 ` [PATCH v3 3/3] iio: common: scmi_sensors: " Dmitry Rokosov
2022-08-28 15:47 ` [PATCH v3 0/3] units: complement the set of Hz units Jonathan Cameron
3 siblings, 0 replies; 5+ messages in thread
From: Dmitry Rokosov @ 2022-08-01 14:37 UTC (permalink / raw)
To: akpm@linux-foundation.org, andriy.shevchenko@linux.intel.com,
daniel.lezcano@linaro.org, jic23@kernel.org, wsa@kernel.org,
andy.shevchenko@gmail.com, lars@metafoo.de,
Michael.Hennerich@analog.com, jbhayana@google.com
Cc: linux-iio@vger.kernel.org, kernel, linux-kernel@vger.kernel.org,
Dmitry Rokosov
Remove duplicated definition of NHZ_PER_HZ, because it's available in
the units.h as NANOHZ_PER_HZ.
Signed-off-by: Dmitry Rokosov <ddrokosov@sberdevices.ru>
Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>
---
drivers/iio/accel/adxl345_core.c | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/drivers/iio/accel/adxl345_core.c b/drivers/iio/accel/adxl345_core.c
index 370bfec1275a..1919e0089c11 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
@@ -139,7 +139,7 @@ static int adxl345_read_raw(struct iio_dev *indio_dev,
samp_freq_nhz = ADXL345_BASE_RATE_NANO_HZ <<
(regval & ADXL345_BW_RATE);
- *val = div_s64_rem(samp_freq_nhz, NHZ_PER_HZ, val2);
+ *val = div_s64_rem(samp_freq_nhz, NANOHZ_PER_HZ, val2);
return IIO_VAL_INT_PLUS_NANO;
}
@@ -164,7 +164,8 @@ static int adxl345_write_raw(struct iio_dev *indio_dev,
ADXL345_REG_OFS_AXIS(chan->address),
val / 4);
case IIO_CHAN_INFO_SAMP_FREQ:
- n = div_s64(val * NHZ_PER_HZ + val2, ADXL345_BASE_RATE_NANO_HZ);
+ n = div_s64(val * NANOHZ_PER_HZ + val2,
+ ADXL345_BASE_RATE_NANO_HZ);
return regmap_update_bits(data->regmap, ADXL345_REG_BW_RATE,
ADXL345_BW_RATE,
--
2.36.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH v3 3/3] iio: common: scmi_sensors: use HZ macro from units.h
2022-08-01 14:37 [PATCH v3 0/3] units: complement the set of Hz units Dmitry Rokosov
2022-08-01 14:37 ` [PATCH v3 1/3] " Dmitry Rokosov
2022-08-01 14:37 ` [PATCH v3 2/3] iio: accel: adxl345: use HZ macro from units.h Dmitry Rokosov
@ 2022-08-01 14:37 ` Dmitry Rokosov
2022-08-28 15:47 ` [PATCH v3 0/3] units: complement the set of Hz units Jonathan Cameron
3 siblings, 0 replies; 5+ messages in thread
From: Dmitry Rokosov @ 2022-08-01 14:37 UTC (permalink / raw)
To: akpm@linux-foundation.org, andriy.shevchenko@linux.intel.com,
daniel.lezcano@linaro.org, jic23@kernel.org, wsa@kernel.org,
andy.shevchenko@gmail.com, lars@metafoo.de,
Michael.Hennerich@analog.com, jbhayana@google.com
Cc: linux-iio@vger.kernel.org, kernel, linux-kernel@vger.kernel.org,
Dmitry Rokosov
Remove duplicated definition of UHZ_PER_HZ, because it's available in
the units.h as MICROHZ_PER_HZ.
Signed-off-by: Dmitry Rokosov <ddrokosov@sberdevices.ru>
Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>
---
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
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH v3 0/3] units: complement the set of Hz units
2022-08-01 14:37 [PATCH v3 0/3] units: complement the set of Hz units Dmitry Rokosov
` (2 preceding siblings ...)
2022-08-01 14:37 ` [PATCH v3 3/3] iio: common: scmi_sensors: " Dmitry Rokosov
@ 2022-08-28 15:47 ` Jonathan Cameron
3 siblings, 0 replies; 5+ messages in thread
From: Jonathan Cameron @ 2022-08-28 15:47 UTC (permalink / raw)
To: Dmitry Rokosov
Cc: akpm@linux-foundation.org, andriy.shevchenko@linux.intel.com,
daniel.lezcano@linaro.org, wsa@kernel.org,
andy.shevchenko@gmail.com, lars@metafoo.de,
Michael.Hennerich@analog.com, jbhayana@google.com,
linux-iio@vger.kernel.org, kernel, linux-kernel@vger.kernel.org
On Mon, 1 Aug 2022 14:37:23 +0000
Dmitry Rokosov <DDRokosov@sberdevices.ru> wrote:
> During msa311 accel IIO driver development
>
> https://lore.kernel.org/linux-iio/20220616104211.9257-1-ddrokosov@sberdevices.ru/
>
> 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(-)
>
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2022-08-28 16:21 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-08-01 14:37 [PATCH v3 0/3] units: complement the set of Hz units Dmitry Rokosov
2022-08-01 14:37 ` [PATCH v3 1/3] " Dmitry Rokosov
2022-08-01 14:37 ` [PATCH v3 2/3] iio: accel: adxl345: use HZ macro from units.h Dmitry Rokosov
2022-08-01 14:37 ` [PATCH v3 3/3] iio: common: scmi_sensors: " Dmitry Rokosov
2022-08-28 15:47 ` [PATCH v3 0/3] units: complement the set of Hz units Jonathan Cameron
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).