* [PATCH v4 0/2] i2c: imx: guard and drop prefix
@ 2025-05-31 6:57 Troy Mitchell
2025-05-31 6:57 ` [PATCH v4 1/2] i2c: imx: use guard to take spinlock Troy Mitchell
` (2 more replies)
0 siblings, 3 replies; 5+ messages in thread
From: Troy Mitchell @ 2025-05-31 6:57 UTC (permalink / raw)
To: Oleksij Rempel, Pengutronix Kernel Team, Andi Shyti, Shawn Guo,
Sascha Hauer, Fabio Estevam
Cc: linux-i2c, imx, linux-arm-kernel, linux-kernel, Troy Mitchell,
Yongchao Jia, Frank Li, Ahmad Fatoum, Carlos Song
Since this patch[1], we have new callback function names.
Since this patch[2], we can use `guard` to call `spin_lock_irqsave`
and release this lock when it goes out of scope.
Link:
https://lore.kernel.org/all/20240706112116.24543-2-wsa+renesas@sang-engineering.com/ [1]
https://lore.kernel.org/all/20250227221924.265259-10-lyude@redhat.com/ [2]
Signed-off-by: Troy Mitchell <troymitchell988@gmail.com>
---
Changes in v4:
- Add Reviewed-by: Carlos Song and Acked-by: Oleksij Rempel
- No code changes
- Link to v3: https://lore.kernel.org/r/20250513-i2c-imx-update-v3-0-817b7426a67e@gmail.com
Changes in v3:
- use scoped_guard
- Link to v2: https://lore.kernel.org/r/20250427-i2c-imx-update-v2-0-d312e394b573@gmail.com
Changes in v2:
- Add more details in the commit message
- Drop a useless variable
- Refactor the logic of i2c_imx_isr function
- Link to v1: https://lore.kernel.org/r/20250421-i2c-imx-update-v1-0-1137f1f353d5@gmail.com
---
Troy Mitchell (2):
i2c: imx: use guard to take spinlock
i2c: imx: drop master prefix
drivers/i2c/busses/i2c-imx.c | 41 ++++++++++++++++++-----------------------
1 file changed, 18 insertions(+), 23 deletions(-)
---
base-commit: 9d7a0577c9db35c4cc52db90bc415ea248446472
change-id: 20250421-i2c-imx-update-d11d66dd87e8
Best regards,
--
Troy Mitchell <troymitchell988@gmail.com>
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH v4 1/2] i2c: imx: use guard to take spinlock
2025-05-31 6:57 [PATCH v4 0/2] i2c: imx: guard and drop prefix Troy Mitchell
@ 2025-05-31 6:57 ` Troy Mitchell
2025-05-31 6:57 ` [PATCH v4 2/2] i2c: imx: drop master prefix Troy Mitchell
2025-06-26 21:10 ` [PATCH v4 0/2] i2c: imx: guard and drop prefix Andi Shyti
2 siblings, 0 replies; 5+ messages in thread
From: Troy Mitchell @ 2025-05-31 6:57 UTC (permalink / raw)
To: Oleksij Rempel, Pengutronix Kernel Team, Andi Shyti, Shawn Guo,
Sascha Hauer, Fabio Estevam
Cc: linux-i2c, imx, linux-arm-kernel, linux-kernel, Troy Mitchell,
Yongchao Jia, Frank Li
Use guard to automatically release the lock after going out of scope
instead of calling it manually.
i2c_imx_slave_handle() can safely be entered with the lock held.
Refactored the i2c_imx_isr function so that i2c_imx_master_isr
does not participate in the guard scope
So Using scoped_guard simplifies the control flow
by ensuring consistent and automatic unlock,
which improves readability without affecting correctness.
Co-developed-by: Yongchao Jia <jyc0019@gmail.com>
Signed-off-by: Yongchao Jia <jyc0019@gmail.com>
Reviewed-by: Frank Li <Frank.Li@nxp.com>
Acked-by: Oleksij Rempel <o.rempel@pengutronix.de>
Signed-off-by: Troy Mitchell <troymitchell988@gmail.com>
---
drivers/i2c/busses/i2c-imx.c | 37 ++++++++++++++++---------------------
1 file changed, 16 insertions(+), 21 deletions(-)
diff --git a/drivers/i2c/busses/i2c-imx.c b/drivers/i2c/busses/i2c-imx.c
index 9e5d454d8318..5b276e007292 100644
--- a/drivers/i2c/busses/i2c-imx.c
+++ b/drivers/i2c/busses/i2c-imx.c
@@ -23,6 +23,7 @@
#include <linux/acpi.h>
#include <linux/clk.h>
+#include <linux/cleanup.h>
#include <linux/completion.h>
#include <linux/delay.h>
#include <linux/dma-mapping.h>
@@ -891,13 +892,13 @@ static enum hrtimer_restart i2c_imx_slave_timeout(struct hrtimer *t)
struct imx_i2c_struct *i2c_imx = container_of(t, struct imx_i2c_struct,
slave_timer);
unsigned int ctl, status;
- unsigned long flags;
- spin_lock_irqsave(&i2c_imx->slave_lock, flags);
+ guard(spinlock_irqsave)(&i2c_imx->slave_lock);
+
status = imx_i2c_read_reg(i2c_imx, IMX_I2C_I2SR);
ctl = imx_i2c_read_reg(i2c_imx, IMX_I2C_I2CR);
i2c_imx_slave_handle(i2c_imx, status, ctl);
- spin_unlock_irqrestore(&i2c_imx->slave_lock, flags);
+
return HRTIMER_NORESTART;
}
@@ -1125,32 +1126,26 @@ static irqreturn_t i2c_imx_isr(int irq, void *dev_id)
{
struct imx_i2c_struct *i2c_imx = dev_id;
unsigned int ctl, status;
- unsigned long flags;
- spin_lock_irqsave(&i2c_imx->slave_lock, flags);
- status = imx_i2c_read_reg(i2c_imx, IMX_I2C_I2SR);
- ctl = imx_i2c_read_reg(i2c_imx, IMX_I2C_I2CR);
+ scoped_guard(spinlock_irqsave, &i2c_imx->slave_lock) {
+ status = imx_i2c_read_reg(i2c_imx, IMX_I2C_I2SR);
+ ctl = imx_i2c_read_reg(i2c_imx, IMX_I2C_I2CR);
+
+ if (!(status & I2SR_IIF))
+ return IRQ_NONE;
- if (status & I2SR_IIF) {
i2c_imx_clear_irq(i2c_imx, I2SR_IIF);
+
if (i2c_imx->slave) {
- if (!(ctl & I2CR_MSTA)) {
- irqreturn_t ret;
-
- ret = i2c_imx_slave_handle(i2c_imx,
- status, ctl);
- spin_unlock_irqrestore(&i2c_imx->slave_lock,
- flags);
- return ret;
- }
+ if (!(ctl & I2CR_MSTA))
+ return i2c_imx_slave_handle(i2c_imx,
+ status, ctl);
+
i2c_imx_slave_finish_op(i2c_imx);
}
- spin_unlock_irqrestore(&i2c_imx->slave_lock, flags);
- return i2c_imx_master_isr(i2c_imx, status);
}
- spin_unlock_irqrestore(&i2c_imx->slave_lock, flags);
- return IRQ_NONE;
+ return i2c_imx_master_isr(i2c_imx, status);
}
static int i2c_imx_dma_write(struct imx_i2c_struct *i2c_imx,
--
2.34.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH v4 2/2] i2c: imx: drop master prefix
2025-05-31 6:57 [PATCH v4 0/2] i2c: imx: guard and drop prefix Troy Mitchell
2025-05-31 6:57 ` [PATCH v4 1/2] i2c: imx: use guard to take spinlock Troy Mitchell
@ 2025-05-31 6:57 ` Troy Mitchell
2025-06-02 13:55 ` Frank Li
2025-06-26 21:10 ` [PATCH v4 0/2] i2c: imx: guard and drop prefix Andi Shyti
2 siblings, 1 reply; 5+ messages in thread
From: Troy Mitchell @ 2025-05-31 6:57 UTC (permalink / raw)
To: Oleksij Rempel, Pengutronix Kernel Team, Andi Shyti, Shawn Guo,
Sascha Hauer, Fabio Estevam
Cc: linux-i2c, imx, linux-arm-kernel, linux-kernel, Troy Mitchell,
Yongchao Jia, Ahmad Fatoum, Carlos Song
In light of the recent updates to the i2c subsystem,
drop master prefix.
Reviewed-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
Reviewed-by: Carlos Song <carlos.song@nxp.com>
Acked-by: Oleksij Rempel <o.rempel@pengutronix.de>
Signed-off-by: Troy Mitchell <troymitchell988@gmail.com>
---
drivers/i2c/busses/i2c-imx.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/i2c/busses/i2c-imx.c b/drivers/i2c/busses/i2c-imx.c
index 5b276e007292..d85adfb73bac 100644
--- a/drivers/i2c/busses/i2c-imx.c
+++ b/drivers/i2c/busses/i2c-imx.c
@@ -1687,8 +1687,8 @@ static u32 i2c_imx_func(struct i2c_adapter *adapter)
}
static const struct i2c_algorithm i2c_imx_algo = {
- .master_xfer = i2c_imx_xfer,
- .master_xfer_atomic = i2c_imx_xfer_atomic,
+ .xfer = i2c_imx_xfer,
+ .xfer_atomic = i2c_imx_xfer_atomic,
.functionality = i2c_imx_func,
.reg_slave = i2c_imx_reg_slave,
.unreg_slave = i2c_imx_unreg_slave,
--
2.34.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH v4 2/2] i2c: imx: drop master prefix
2025-05-31 6:57 ` [PATCH v4 2/2] i2c: imx: drop master prefix Troy Mitchell
@ 2025-06-02 13:55 ` Frank Li
0 siblings, 0 replies; 5+ messages in thread
From: Frank Li @ 2025-06-02 13:55 UTC (permalink / raw)
To: Troy Mitchell
Cc: Oleksij Rempel, Pengutronix Kernel Team, Andi Shyti, Shawn Guo,
Sascha Hauer, Fabio Estevam, linux-i2c, imx, linux-arm-kernel,
linux-kernel, Yongchao Jia, Ahmad Fatoum, Carlos Song
On Sat, May 31, 2025 at 02:57:27PM +0800, Troy Mitchell wrote:
> In light of the recent updates to the i2c subsystem,
> drop master prefix.
>
> Reviewed-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
> Reviewed-by: Carlos Song <carlos.song@nxp.com>
> Acked-by: Oleksij Rempel <o.rempel@pengutronix.de>
> Signed-off-by: Troy Mitchell <troymitchell988@gmail.com>
Reviewed-by: Frank Li <Frank.Li@nxp.com>
> ---
> drivers/i2c/busses/i2c-imx.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/i2c/busses/i2c-imx.c b/drivers/i2c/busses/i2c-imx.c
> index 5b276e007292..d85adfb73bac 100644
> --- a/drivers/i2c/busses/i2c-imx.c
> +++ b/drivers/i2c/busses/i2c-imx.c
> @@ -1687,8 +1687,8 @@ static u32 i2c_imx_func(struct i2c_adapter *adapter)
> }
>
> static const struct i2c_algorithm i2c_imx_algo = {
> - .master_xfer = i2c_imx_xfer,
> - .master_xfer_atomic = i2c_imx_xfer_atomic,
> + .xfer = i2c_imx_xfer,
> + .xfer_atomic = i2c_imx_xfer_atomic,
> .functionality = i2c_imx_func,
> .reg_slave = i2c_imx_reg_slave,
> .unreg_slave = i2c_imx_unreg_slave,
>
> --
> 2.34.1
>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v4 0/2] i2c: imx: guard and drop prefix
2025-05-31 6:57 [PATCH v4 0/2] i2c: imx: guard and drop prefix Troy Mitchell
2025-05-31 6:57 ` [PATCH v4 1/2] i2c: imx: use guard to take spinlock Troy Mitchell
2025-05-31 6:57 ` [PATCH v4 2/2] i2c: imx: drop master prefix Troy Mitchell
@ 2025-06-26 21:10 ` Andi Shyti
2 siblings, 0 replies; 5+ messages in thread
From: Andi Shyti @ 2025-06-26 21:10 UTC (permalink / raw)
To: Troy Mitchell
Cc: Oleksij Rempel, Pengutronix Kernel Team, Shawn Guo, Sascha Hauer,
Fabio Estevam, linux-i2c, imx, linux-arm-kernel, linux-kernel,
Yongchao Jia, Frank Li, Ahmad Fatoum, Carlos Song
Hi Troy,
> Troy Mitchell (2):
> i2c: imx: use guard to take spinlock
I merged this patch to i2c/i2c-host.
> i2c: imx: drop master prefix
This patch has been already applied here:
614b1c3cbfb0 ("i2c: use inclusive callbacks in struct i2c_algorithm")
Thanks,
Andi
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2025-06-26 21:10 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-05-31 6:57 [PATCH v4 0/2] i2c: imx: guard and drop prefix Troy Mitchell
2025-05-31 6:57 ` [PATCH v4 1/2] i2c: imx: use guard to take spinlock Troy Mitchell
2025-05-31 6:57 ` [PATCH v4 2/2] i2c: imx: drop master prefix Troy Mitchell
2025-06-02 13:55 ` Frank Li
2025-06-26 21:10 ` [PATCH v4 0/2] i2c: imx: guard and drop prefix Andi Shyti
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).