Skip to contentSkip to conversation

iio: frequency: ad9832: cleanups

PATCH In review Joshua Crofts 3 participants 7 messages Apr 17 – Apr 19

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

v6 cover iio: frequency: ad9832: cleanups

This series cleans up issues in the AD9832 driver, including proxy header removal and bit math simplification.

v2:
- PATCH 1: removed redundant bits.h include as it is implied in bitops.h
- PATCH 2: changed ull to u64 type
v3:
- PATCH 2: remove rogue vim typo
v4:
- PATCH 1: removed slab.h based on IWYU recommendation, header reordering
v5:
- PATCH 1: commit message stylistic changes
v6:
- PATCH 1: add additional headers per kernel.h removal, commit message edit
- PATCH 2: commit message edit

Joshua Crofts (2):
iio: frequency: ad9832: remove kernel.h proxy header
iio: frequency: ad9832: simplify bitwise math

 drivers/staging/iio/frequency/ad9832.c | 20 ++++++++++++--------
 1 file changed, 12 insertions(+), 8 deletions(-)
Signature · 1 line
2.47.3
#1 lore raw

PATCH v6 1/2 iio: frequency: ad9832: remove kernel.h proxy header

Remove kernel.h proxy header and add replacement headers (array_size, dev_printk.h, kstrtox, mod_devicetable, mutex, types, asm/byteorder) to maintain atomicity. Moved asm/div64.h header below generic <linux/*> headers. Additionally, add bitops.h for BIT_ULL() macro.

Audited using the include-what-you-use tool.

---
 drivers/staging/iio/frequency/ad9832.c | 16 ++++++++++------
 1 file changed, 10 insertions(+), 6 deletions(-)
drivers/staging/iio/frequency/ad9832.c +10 -6
index b87ea1781b..c0b7852f1c 100644
@@ -5,21 +5,25 @@
  * Copyright 2011 Analog Devices Inc.
  */
 
-#include <asm/div64.h>
-
+#include <linux/array_size.h>
 #include <linux/bitfield.h>
-#include <linux/bits.h>
+#include <linux/bitops.h>
 #include <linux/clk.h>
-#include <linux/device.h>
+#include <linux/dev_printk.h>
 #include <linux/err.h>
-#include <linux/kernel.h>
+#include <linux/kstrtox.h>
+#include <linux/mod_devicetable.h>
 #include <linux/module.h>
+#include <linux/mutex.h>
 #include <linux/regulator/consumer.h>
-#include <linux/slab.h>
 #include <linux/spi/spi.h>
 #include <linux/sysfs.h>
+#include <linux/types.h>
 #include <linux/unaligned.h>
 
+#include <asm/byteorder.h>
+#include <asm/div64.h>
+
 #include <linux/iio/iio.h>
 #include <linux/iio/sysfs.h>
 
Signature · 1 line
2.47.3
#2 lore raw

Re: [PATCH v6 1/2] iio: frequency: ad9832: remove kernel.h proxy header

Quoted 2 lines · Joshua Crofts

Remove kernel.h proxy header and add replacement headers (array_size, dev_printk.h, kstrtox, mod_devicetable, mutex, types, asm/byteorder) to

I guess it's better to add .h to all of them. No need to resend for that. Perhaps Jonathan tweaks it.

Quoted 4 lines

maintain atomicity. Moved asm/div64.h header below generic <linux/*> headers. Additionally, add bitops.h for BIT_ULL() macro.

Audited using the include-what-you-use tool.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
maintainer
#3 lore raw

Re: [PATCH v6 1/2] iio: frequency: ad9832: remove kernel.h proxy header

Quoted 12 lines · On Fri, 17 Apr 2026 20:50:05 +0300 Andy Shevchenko…
Quoted 2 lines · Joshua Crofts

Remove kernel.h proxy header and add replacement headers (array_size, dev_printk.h, kstrtox, mod_devicetable, mutex, types, asm/byteorder) to

I guess it's better to add .h to all of them. No need to resend for that. Perhaps Jonathan tweaks it.

Quoted 4 lines

maintain atomicity. Moved asm/div64.h header below generic <linux/*> headers. Additionally, add bitops.h for BIT_ULL() macro.

Audited using the include-what-you-use tool.

Tidied up. The Sashiko stuff disagreed a bit with one or two choices, but nothing that I think warrants a change to this.

So applied this patch

Thanks,

Jonathan

#4 lore raw

PATCH v6 2/2 iio: frequency: ad9832: simplify bitwise math

In reply to Joshua Crofts

Refactor the ad9832_calc_freqreg by adding a BIT_ULL() macro instead of manual bit shifting for better readability.

---
 drivers/staging/iio/frequency/ad9832.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/staging/iio/frequency/ad9832.c +2 -2
index c0b7852f1c..6ce9651542 100644
@@ -117,8 +117,8 @@ struct ad9832_state {
 
 static unsigned long ad9832_calc_freqreg(unsigned long mclk, unsigned long fout)
 {
-	unsigned long long freqreg = (u64)fout *
-				     (u64)((u64)1L << AD9832_FREQ_BITS);
+	u64 freqreg = (u64)fout * BIT_ULL(AD9832_FREQ_BITS);
+
 	do_div(freqreg, mclk);
 	return freqreg;
 }
Signature · 1 line
2.47.3
maintainer
#5 lore raw

Re: [PATCH v6 2/2] iio: frequency: ad9832: simplify bitwise math

Quoted 15 lines · On Fri, 17 Apr 2026 10:16:23 +0000 Joshua Crofts <[email protected]>…

Refactor the ad9832_calc_freqreg by adding a BIT_ULL() macro instead of manual bit shifting for better readability.

---
 drivers/staging/iio/frequency/ad9832.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/staging/iio/frequency/ad9832.c +0 -0
index c0b7852f1c..6ce9651542 100644

drivers/staging/iio/frequency/ad9832.c struct ad9832_state { · line 120

Quoted 6 lines
drivers/staging/iio/frequency/ad9832.c +1 -2
@@ -117,8 +117,8 @@ struct ad9832_state {
 
 static unsigned long ad9832_calc_freqreg(unsigned long mclk, unsigned long fout)
 {
-	unsigned long long freqreg = (u64)fout *
-				     (u64)((u64)1L << AD9832_FREQ_BITS);
+	u64 freqreg = (u64)fout * BIT_ULL(AD9832_FREQ_BITS);

https://sashiko.dev/#/patchset/20260417101623.1281-1-joshua.crofts1%40gmail.com

So does this actually improve readability? Sashiko had fun with this one and I'm somewhat inclined to agree with it. The suggestion it made was that the following was more readable still and avoided oddity of using BIT_ULL as a multiplier.

	u64 freqreg = (u64)fout << AD9832_FREQ_BITS;
Quoted 4 lines
drivers/staging/iio/frequency/ad9832.c +1 -0
+
 	do_div(freqreg, mclk);
 	return freqreg;
 }
#6 lore raw

Re: [PATCH v6 2/2] iio: frequency: ad9832: simplify bitwise math

Quoted 11 lines · Jonathan Cameron

drivers/staging/iio/frequency/ad9832.c struct ad9832_state { · line 120

Quoted 3 lines
drivers/staging/iio/frequency/ad9832.c +1 -2
-     unsigned long long freqreg = (u64)fout *
-                                  (u64)((u64)1L << AD9832_FREQ_BITS);
+     u64 freqreg = (u64)fout * BIT_ULL(AD9832_FREQ_BITS);

https://sashiko.dev/#/patchset/20260417101623.1281-1-joshua.crofts1%40gmail.com

So does this actually improve readability? Sashiko had fun with this one and I'm somewhat inclined to agree with it. The suggestion it made was that the following was more readable still and avoided oddity of using BIT_ULL as a multiplier.

        u64 freqreg = (u64)fout << AD9832_FREQ_BITS;

Fair enough, the suggestion seems valid. IMO my initial patch did improve the readability as it removed two u64 casts in the expression, but sure, I'll send a follow up patch.

Thanks for the reviews on the other patches, these are my first ever ones that I've submitted.

Signature · 3 lines
Kind regards

CJD