* [PATCH v2 1/4] iio: magnetometer: ak8975: header cleanup
2026-04-21 10:07 [PATCH v2 0/4] iio: magnetometer: ak8975: modernize and cleanup driver Joshua Crofts
@ 2026-04-21 10:07 ` Joshua Crofts
2026-04-21 10:35 ` Jonathan Cameron
2026-04-21 10:07 ` [PATCH v2 2/4] iio: magnetometer: ak8975: replace usleep_range() with fsleep() Joshua Crofts
` (2 subsequent siblings)
3 siblings, 1 reply; 8+ messages in thread
From: Joshua Crofts @ 2026-04-21 10:07 UTC (permalink / raw)
To: jic23; +Cc: dlechner, nuno.sa, andy, linux-iio, linux-kernel, Joshua Crofts
Clean up headers by removing proxy kernel.h header and adding new
headers to ensure atomicity (array_size.h, dev_printk.h, types.h,
asm/byteorder.h). Removed unused headers (slab.h, iio/sysfs.h,
iio/trigger.h) and added minmax.h, property.h, wait.h, irqreturn.h to
mitigate transient dependencies during compilation.
Audited using the include-what-you-use tool.
Signed-off-by: Joshua Crofts <joshua.crofts1@gmail.com>
---
drivers/iio/magnetometer/ak8975.c | 14 ++++++++++----
1 file changed, 10 insertions(+), 4 deletions(-)
diff --git a/drivers/iio/magnetometer/ak8975.c b/drivers/iio/magnetometer/ak8975.c
index 44782c26698..a829bee4cf8 100644
--- a/drivers/iio/magnetometer/ak8975.c
+++ b/drivers/iio/magnetometer/ak8975.c
@@ -9,8 +9,6 @@
#include <linux/module.h>
#include <linux/mod_devicetable.h>
-#include <linux/kernel.h>
-#include <linux/slab.h>
#include <linux/i2c.h>
#include <linux/interrupt.h>
#include <linux/err.h>
@@ -20,11 +18,19 @@
#include <linux/gpio/consumer.h>
#include <linux/regulator/consumer.h>
#include <linux/pm_runtime.h>
+#include <linux/array_size.h>
+#include <linux/delay.h>
+#include <linux/dev_printk.h>
+#include <linux/irqreturn.h>
+#include <linux/minmax.h>
+#include <linux/property.h>
+#include <linux/types.h>
+#include <linux/wait.h>
+
+#include <asm/byteorder.h>
#include <linux/iio/iio.h>
-#include <linux/iio/sysfs.h>
#include <linux/iio/buffer.h>
-#include <linux/iio/trigger.h>
#include <linux/iio/trigger_consumer.h>
#include <linux/iio/triggered_buffer.h>
--
2.47.3
^ permalink raw reply related [flat|nested] 8+ messages in thread* Re: [PATCH v2 1/4] iio: magnetometer: ak8975: header cleanup
2026-04-21 10:07 ` [PATCH v2 1/4] iio: magnetometer: ak8975: header cleanup Joshua Crofts
@ 2026-04-21 10:35 ` Jonathan Cameron
2026-04-21 10:52 ` Joshua Crofts
0 siblings, 1 reply; 8+ messages in thread
From: Jonathan Cameron @ 2026-04-21 10:35 UTC (permalink / raw)
To: Joshua Crofts; +Cc: dlechner, nuno.sa, andy, linux-iio, linux-kernel
On Tue, 21 Apr 2026 10:07:19 +0000
Joshua Crofts <joshua.crofts1@gmail.com> wrote:
> Clean up headers by removing proxy kernel.h header and adding new
> headers to ensure atomicity (array_size.h, dev_printk.h, types.h,
> asm/byteorder.h). Removed unused headers (slab.h, iio/sysfs.h,
> iio/trigger.h) and added minmax.h, property.h, wait.h, irqreturn.h to
> mitigate transient dependencies during compilation.
>
> Audited using the include-what-you-use tool.
>
> Signed-off-by: Joshua Crofts <joshua.crofts1@gmail.com>
I just saw your reply to v1 thread. General advice would be slow down a bit.
Even if you have reviews, a new patch set should sit for at least a few days
to gather multiple reviews before a revision.
For this sort of change I'd expect two patches.
1. Sort headers as is, not changes.
2. Add and remove headers.
Both are good to do, but if you do them together as you had in v1
it is annoyingly hard to review.
> ---
> drivers/iio/magnetometer/ak8975.c | 14 ++++++++++----
> 1 file changed, 10 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/iio/magnetometer/ak8975.c b/drivers/iio/magnetometer/ak8975.c
> index 44782c26698..a829bee4cf8 100644
> --- a/drivers/iio/magnetometer/ak8975.c
> +++ b/drivers/iio/magnetometer/ak8975.c
> @@ -9,8 +9,6 @@
>
> #include <linux/module.h>
> #include <linux/mod_devicetable.h>
> -#include <linux/kernel.h>
> -#include <linux/slab.h>
> #include <linux/i2c.h>
> #include <linux/interrupt.h>
> #include <linux/err.h>
> @@ -20,11 +18,19 @@
> #include <linux/gpio/consumer.h>
> #include <linux/regulator/consumer.h>
> #include <linux/pm_runtime.h>
> +#include <linux/array_size.h>
> +#include <linux/delay.h>
> +#include <linux/dev_printk.h>
> +#include <linux/irqreturn.h>
> +#include <linux/minmax.h>
> +#include <linux/property.h>
> +#include <linux/types.h>
> +#include <linux/wait.h>
Even if you don't sort, these should be inserted as near
as possible to where they'd end up in a sorted list.
> +
> +#include <asm/byteorder.h>
>
> #include <linux/iio/iio.h>
> -#include <linux/iio/sysfs.h>
> #include <linux/iio/buffer.h>
> -#include <linux/iio/trigger.h>
> #include <linux/iio/trigger_consumer.h>
> #include <linux/iio/triggered_buffer.h>
>
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH v2 1/4] iio: magnetometer: ak8975: header cleanup
2026-04-21 10:35 ` Jonathan Cameron
@ 2026-04-21 10:52 ` Joshua Crofts
0 siblings, 0 replies; 8+ messages in thread
From: Joshua Crofts @ 2026-04-21 10:52 UTC (permalink / raw)
To: Jonathan Cameron; +Cc: dlechner, nuno.sa, andy, linux-iio, linux-kernel
On Tue, 21 Apr 2026 at 12:36, Jonathan Cameron <jic23@kernel.org> wrote:
> I just saw your reply to v1 thread. General advice would be slow down a bit.
> Even if you have reviews, a new patch set should sit for at least a few days
> to gather multiple reviews before a revision.
Yeah, I might've sent a v2 a bit earlier, next time I'll let it sit
longer before
sending a new version.
> For this sort of change I'd expect two patches.
> 1. Sort headers as is, not changes.
> 2. Add and remove headers.
>
> Both are good to do, but if you do them together as you had in v1
> it is annoyingly hard to review.
Fair, I can see why that would be annoying. I'll split it into two patches
in the v3 version.
--
Kind regards
CJD
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH v2 2/4] iio: magnetometer: ak8975: replace usleep_range() with fsleep()
2026-04-21 10:07 [PATCH v2 0/4] iio: magnetometer: ak8975: modernize and cleanup driver Joshua Crofts
2026-04-21 10:07 ` [PATCH v2 1/4] iio: magnetometer: ak8975: header cleanup Joshua Crofts
@ 2026-04-21 10:07 ` Joshua Crofts
2026-04-21 10:07 ` [PATCH v2 3/4] iio: magnetometer: ak8975: change 'u8*' to 'u8 *' in cast Joshua Crofts
2026-04-21 10:07 ` [PATCH v2 4/4] iio: magnetometer: ak8975: modernize polling loops with iopoll() macros Joshua Crofts
3 siblings, 0 replies; 8+ messages in thread
From: Joshua Crofts @ 2026-04-21 10:07 UTC (permalink / raw)
To: jic23; +Cc: dlechner, nuno.sa, andy, linux-iio, linux-kernel, Joshua Crofts
Replace usleep_range() calls with fsleep(), passing the minimum value
required by the sensor for hardware delays.
fsleep() automatically selects the optimal sleep mechanism, simplifying
driver code and time management.
Signed-off-by: Joshua Crofts <joshua.crofts1@gmail.com>
---
drivers/iio/magnetometer/ak8975.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/drivers/iio/magnetometer/ak8975.c b/drivers/iio/magnetometer/ak8975.c
index a829bee4cf8..7c37faaa4d9 100644
--- a/drivers/iio/magnetometer/ak8975.c
+++ b/drivers/iio/magnetometer/ak8975.c
@@ -462,7 +462,8 @@ static int ak8975_power_on(const struct ak8975_data *data)
* and the minimum wait time before mode setting is 100us, in
* total 300us. Add some margin and say minimum 500us here.
*/
- usleep_range(500, 1000);
+ fsleep(500);
+
return 0;
}
@@ -552,7 +553,7 @@ static int ak8975_set_mode(struct ak8975_data *data, enum ak_ctrl_mode mode)
data->cntl_cache = regval;
/* After mode change wait at least 100us */
- usleep_range(100, 500);
+ fsleep(100);
return 0;
}
--
2.47.3
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH v2 3/4] iio: magnetometer: ak8975: change 'u8*' to 'u8 *' in cast
2026-04-21 10:07 [PATCH v2 0/4] iio: magnetometer: ak8975: modernize and cleanup driver Joshua Crofts
2026-04-21 10:07 ` [PATCH v2 1/4] iio: magnetometer: ak8975: header cleanup Joshua Crofts
2026-04-21 10:07 ` [PATCH v2 2/4] iio: magnetometer: ak8975: replace usleep_range() with fsleep() Joshua Crofts
@ 2026-04-21 10:07 ` Joshua Crofts
2026-04-21 10:07 ` [PATCH v2 4/4] iio: magnetometer: ak8975: modernize polling loops with iopoll() macros Joshua Crofts
3 siblings, 0 replies; 8+ messages in thread
From: Joshua Crofts @ 2026-04-21 10:07 UTC (permalink / raw)
To: jic23; +Cc: dlechner, nuno.sa, andy, linux-iio, linux-kernel, Joshua Crofts
Change 'u8*' cast to 'u8 *' as the former triggers a checkpatch error.
Signed-off-by: Joshua Crofts <joshua.crofts1@gmail.com>
---
drivers/iio/magnetometer/ak8975.c | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/drivers/iio/magnetometer/ak8975.c b/drivers/iio/magnetometer/ak8975.c
index 7c37faaa4d9..d0d95d3914a 100644
--- a/drivers/iio/magnetometer/ak8975.c
+++ b/drivers/iio/magnetometer/ak8975.c
@@ -760,9 +760,10 @@ static int ak8975_read_axis(struct iio_dev *indio_dev, int index, int *val)
if (ret)
goto exit;
- ret = i2c_smbus_read_i2c_block_data_or_emulated(
- client, def->data_regs[index],
- sizeof(rval), (u8*)&rval);
+ ret = i2c_smbus_read_i2c_block_data_or_emulated(client,
+ def->data_regs[index],
+ sizeof(rval),
+ (u8 *)&rval);
if (ret < 0)
goto exit;
--
2.47.3
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH v2 4/4] iio: magnetometer: ak8975: modernize polling loops with iopoll() macros
2026-04-21 10:07 [PATCH v2 0/4] iio: magnetometer: ak8975: modernize and cleanup driver Joshua Crofts
` (2 preceding siblings ...)
2026-04-21 10:07 ` [PATCH v2 3/4] iio: magnetometer: ak8975: change 'u8*' to 'u8 *' in cast Joshua Crofts
@ 2026-04-21 10:07 ` Joshua Crofts
2026-04-21 10:38 ` Jonathan Cameron
3 siblings, 1 reply; 8+ messages in thread
From: Joshua Crofts @ 2026-04-21 10:07 UTC (permalink / raw)
To: jic23; +Cc: dlechner, nuno.sa, andy, linux-iio, linux-kernel, Joshua Crofts
The driver currently uses while loops and msleep() for polling during
conversion waits.
Replace the custom polling loops with readx_poll_timeout() and
read_poll_timeout() macros from <linux/iopoll.h>. This reduces
boilerplate, standardizes timeout handling and improves overall code
readability, keeping the original timing and error behaviour.
Assisted-by: Gemini:3.1-Pro
Signed-off-by: Joshua Crofts <joshua.crofts1@gmail.com>
---
drivers/iio/magnetometer/ak8975.c | 44 ++++++++++++++-----------------
1 file changed, 20 insertions(+), 24 deletions(-)
diff --git a/drivers/iio/magnetometer/ak8975.c b/drivers/iio/magnetometer/ak8975.c
index d0d95d3914a..1b9386b7521 100644
--- a/drivers/iio/magnetometer/ak8975.c
+++ b/drivers/iio/magnetometer/ak8975.c
@@ -21,9 +21,11 @@
#include <linux/array_size.h>
#include <linux/delay.h>
#include <linux/dev_printk.h>
+#include <linux/iopoll.h>
#include <linux/irqreturn.h>
#include <linux/minmax.h>
#include <linux/property.h>
+#include <linux/time.h>
#include <linux/types.h>
#include <linux/wait.h>
@@ -653,17 +655,15 @@ static int ak8975_setup(struct i2c_client *client)
static int wait_conversion_complete_gpio(struct ak8975_data *data)
{
struct i2c_client *client = data->client;
- u32 timeout_ms = AK8975_MAX_CONVERSION_TIMEOUT;
int ret;
+ int val;
/* Wait for the conversion to complete. */
- while (timeout_ms) {
- msleep(AK8975_CONVERSION_DONE_POLL_TIME);
- if (gpiod_get_value(data->eoc_gpiod))
- break;
- timeout_ms -= AK8975_CONVERSION_DONE_POLL_TIME;
- }
- if (!timeout_ms) {
+ ret = readx_poll_timeout(gpiod_get_value, data->eoc_gpiod, val,
+ val != 0,
+ AK8975_CONVERSION_DONE_POLL_TIME * USEC_PER_MSEC,
+ AK8975_MAX_CONVERSION_TIMEOUT * USEC_PER_MSEC);
+ if (ret) {
dev_err(&client->dev, "Conversion timeout happened\n");
return -EINVAL;
}
@@ -678,30 +678,26 @@ static int wait_conversion_complete_gpio(struct ak8975_data *data)
static int wait_conversion_complete_polled(struct ak8975_data *data)
{
struct i2c_client *client = data->client;
- u8 read_status;
- u32 timeout_ms = AK8975_MAX_CONVERSION_TIMEOUT;
int ret;
+ int val;
/* Wait for the conversion to complete. */
- while (timeout_ms) {
- msleep(AK8975_CONVERSION_DONE_POLL_TIME);
- ret = i2c_smbus_read_byte_data(client,
- data->def->ctrl_regs[ST1]);
- if (ret < 0) {
- dev_err(&client->dev, "Error in reading ST1\n");
- return ret;
- }
- read_status = ret;
- if (read_status)
- break;
- timeout_ms -= AK8975_CONVERSION_DONE_POLL_TIME;
+ ret = read_poll_timeout(i2c_smbus_read_byte_data, val, val != 0,
+ AK8975_CONVERSION_DONE_POLL_TIME * USEC_PER_MSEC,
+ AK8975_MAX_CONVERSION_TIMEOUT * USEC_PER_MSEC,
+ true,
+ client, data->def->ctrl_regs[ST1]);
+ if (val < 0) {
+ dev_err(&client->dev, "Error in reading ST1\n");
+ return val;
}
- if (!timeout_ms) {
+
+ if (ret == -ETIMEDOUT) {
dev_err(&client->dev, "Conversion timeout happened\n");
return -EINVAL;
}
- return read_status;
+ return val;
}
/* Returns 0 if the end of conversion interrupt occurred or -ETIME otherwise */
--
2.47.3
^ permalink raw reply related [flat|nested] 8+ messages in thread* Re: [PATCH v2 4/4] iio: magnetometer: ak8975: modernize polling loops with iopoll() macros
2026-04-21 10:07 ` [PATCH v2 4/4] iio: magnetometer: ak8975: modernize polling loops with iopoll() macros Joshua Crofts
@ 2026-04-21 10:38 ` Jonathan Cameron
0 siblings, 0 replies; 8+ messages in thread
From: Jonathan Cameron @ 2026-04-21 10:38 UTC (permalink / raw)
To: Joshua Crofts; +Cc: dlechner, nuno.sa, andy, linux-iio, linux-kernel
On Tue, 21 Apr 2026 10:07:22 +0000
Joshua Crofts <joshua.crofts1@gmail.com> wrote:
> The driver currently uses while loops and msleep() for polling during
> conversion waits.
>
> Replace the custom polling loops with readx_poll_timeout() and
> read_poll_timeout() macros from <linux/iopoll.h>. This reduces
> boilerplate, standardizes timeout handling and improves overall code
> readability, keeping the original timing and error behaviour.
>
> Assisted-by: Gemini:3.1-Pro
> Signed-off-by: Joshua Crofts <joshua.crofts1@gmail.com>
The rest of this series looks fine to me.
Jonathan
^ permalink raw reply [flat|nested] 8+ messages in thread