[PATCH v4 1/2] iio: adc: mcp3422: rewrite mask macros with help of bits.h APIs
Marcelo Machado Lage
marcelomlage em usp.br
Sex Abr 24 20:20:08 -03 2026
Rewrite MCP3422_CHANNEL_MASK, MCP3422_PGA_MASK, MCP3422_SRATE_MASK
and MCP3422_CONT_SAMPLING using GENMASK() and BIT() macros from
bits.h.
The other macros MCP3422_SRATE_{240, 60, 15, 3} were not changed
because they are also used as array indices.
Signed-off-by: Marcelo Machado Lage <marcelomlage em usp.br>
Co-developed-by: Vinicius Lira <vinilira em usp.br>
Signed-off-by: Vinicius Lira <vinilira em usp.br>
---
v1 -> v2:
- Split this change from the rest of the patch, following a request by Andy Shevchenko
v2 -> v3:
- Sort marks in logical order, following a request by David Lechner
- Delete the "/* Masks */" comment to avoid confusion, following a request by Jonathan Cameron
v3 -> v4:
- Correct a typo in the commit message, following a request by Jonathan Cameron
- Rephrase the Subject, following a request by Andy Shevchenko
v1: https://lore.kernel.org/linux-iio/20260417005041.484742-1-marcelomlage@usp.br/
v2: https://lore.kernel.org/linux-iio/20260417165747.507487-1-marcelomlage@usp.br/
v3: https://lore.kernel.org/linux-iio/20260420191455.529923-1-marcelomlage@usp.br/
drivers/iio/adc/mcp3422.c | 11 ++++++-----
1 file changed, 6 insertions(+), 5 deletions(-)
diff --git a/drivers/iio/adc/mcp3422.c b/drivers/iio/adc/mcp3422.c
index 50834fdcf738..0cd0e7d39e39 100644
--- a/drivers/iio/adc/mcp3422.c
+++ b/drivers/iio/adc/mcp3422.c
@@ -13,6 +13,7 @@
* voltage unit is nV.
*/
+#include <linux/bits.h>
#include <linux/err.h>
#include <linux/i2c.h>
#include <linux/module.h>
@@ -24,10 +25,10 @@
#include <linux/iio/iio.h>
#include <linux/iio/sysfs.h>
-/* Masks */
-#define MCP3422_CHANNEL_MASK 0x60
-#define MCP3422_PGA_MASK 0x03
-#define MCP3422_SRATE_MASK 0x0C
+#define MCP3422_CHANNEL_MASK GENMASK(6, 5)
+#define MCP3422_SRATE_MASK GENMASK(3, 2)
+#define MCP3422_PGA_MASK GENMASK(1, 0)
+
#define MCP3422_SRATE_240 0x0
#define MCP3422_SRATE_60 0x1
#define MCP3422_SRATE_15 0x2
@@ -36,7 +37,7 @@
#define MCP3422_PGA_2 1
#define MCP3422_PGA_4 2
#define MCP3422_PGA_8 3
-#define MCP3422_CONT_SAMPLING 0x10
+#define MCP3422_CONT_SAMPLING BIT(4)
#define MCP3422_CHANNEL(config) (((config) & MCP3422_CHANNEL_MASK) >> 5)
#define MCP3422_PGA(config) ((config) & MCP3422_PGA_MASK)
--
2.34.1
Mais detalhes sobre a lista de discussão kernel