Skip to contentSkip to conversation

hw/i2c/imx_i2c: Always set interrupt status bit if interrupt condition occurs

PATCH In review Bernhard Beschow 4 participants 5 messages May 7, 2025 – May 8, 2025 Arm i.MX and Layerscape

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 hw/i2c/imx_i2c: Always set interrupt status bit if interrupt condition occurs

According to the i.MX 8M Plus reference manual, the status flag I2C_I2SR[IIF] continues to be set when an interrupt condition occurs even when I2C interrupts are disabled (I2C_I2CR[IIEN] is clear). However, the device model only sets the flag when I2C interrupts are enabled which causes U-Boot to loop forever. Fix the device model by always setting the flag and let I2C_I2CR[IIEN] guard I2C interrupts only.

Also remove the comment in the code since it merely stated the obvious and would be outdated now.

Fixes 20d0f9cf6a41 ("i.MX: Add I2C controller emulator")
cc qemu-stable
---
 hw/i2c/imx_i2c.c | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)
hw/i2c/imx_i2c.c +5 -6
index 91f84c2ad7..d26177c85d 100644
@@ -79,13 +79,12 @@ static void imx_i2c_reset(DeviceState *dev)
 
 static inline void imx_i2c_raise_interrupt(IMXI2CState *s)
 {
-    /*
-     * raise an interrupt if the device is enabled and it is configured
-     * to generate some interrupts.
-     */
-    if (imx_i2c_is_enabled(s) && imx_i2c_interrupt_is_enabled(s)) {
+    if (imx_i2c_is_enabled(s)) {
         s->i2sr |= I2SR_IIF;
-        qemu_irq_raise(s->irq);
+
+        if (imx_i2c_interrupt_is_enabled(s)) {
+            qemu_irq_raise(s->irq);
+        }
     }
 }
 
Signature · 1 line
2.49.0
Acked-by on v1 1/1
#1 lore raw
Quoted 9 lines · Bernhard Beschow

According to the i.MX 8M Plus reference manual, the status flag I2C_I2SR[IIF] continues to be set when an interrupt condition occurs even when I2C interrupts are disabled (I2C_I2CR[IIEN] is clear). However, the device model only sets the flag when I2C interrupts are enabled which causes U-Boot to loop forever. Fix the device model by always setting the flag and let I2C_I2CR[IIEN] guard I2C interrupts only.

Also remove the comment in the code since it merely stated the obvious and would be outdated now.

This looks good to me. I can give you an:

or I can take it into my tree.

-corey

Quoted 35 lines
Fixes 20d0f9cf6a41 ("i.MX: Add I2C controller emulator")
cc qemu-stable
---
 hw/i2c/imx_i2c.c | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)
hw/i2c/imx_i2c.c +5 -6
index 91f84c2ad7..d26177c85d 100644
@@ -79,13 +79,12 @@ static void imx_i2c_reset(DeviceState *dev)
 
 static inline void imx_i2c_raise_interrupt(IMXI2CState *s)
 {
-    /*
-     * raise an interrupt if the device is enabled and it is configured
-     * to generate some interrupts.
-     */
-    if (imx_i2c_is_enabled(s) && imx_i2c_interrupt_is_enabled(s)) {
+    if (imx_i2c_is_enabled(s)) {
         s->i2sr |= I2SR_IIF;
-        qemu_irq_raise(s->irq);
+
+        if (imx_i2c_interrupt_is_enabled(s)) {
+            qemu_irq_raise(s->irq);
+        }
     }
 }
 
Signature · 1 line
2.49.0
#2 lore raw
Quoted 8 lines · Corey Minyard
Quoted 7 lines · Bernhard Beschow

According to the i.MX 8M Plus reference manual, the status flag I2C_I2SR[IIF] continues to be set when an interrupt condition occurs even when I2C interrupts are disabled (I2C_I2CR[IIEN] is clear). However, the device model only sets the flag when I2C interrupts are enabled which causes U-Boot to loop forever. Fix the device model by always setting the flag and let I2C_I2CR[IIEN] guard I2C interrupts only.

Quoted 8 lines
Quoted 2 lines

Also remove the comment in the code since it merely stated the obvious and would be outdated now.

This looks good to me. I can give you an:

or I can take it into my tree.

I have to respin my hw-misc PR so I'll squeeze this.

Thanks!

Phil.

#3 lore raw
Quoted 16 lines · Philippe Mathieu-Daudé
Quoted 15 lines · Corey Minyard
Quoted 9 lines · Bernhard Beschow

According to the i.MX 8M Plus reference manual, the status flag I2C_I2SR[IIF] continues to be set when an interrupt condition occurs even when I2C interrupts are disabled (I2C_I2CR[IIEN] is clear). However, the device model only sets the flag when I2C interrupts are enabled which causes U-Boot to loop forever. Fix the device model by always setting the flag and let I2C_I2CR[IIEN] guard I2C interrupts only.

Also remove the comment in the code since it merely stated the obvious and would be outdated now.

This looks good to me.  I can give you an:

Quoted 7 lines
Quoted 1 line

or I can take it into my tree.

I have to respin my hw-misc PR so I'll squeeze this.

Thanks!

Phil.

FWIW I noticed the patch subject is truncated to my default git-view because it is over 72 chars. Since there is no enforcement on patch subject / description lines length in checkpatch.pl I suppose nobody really cares about that so I'll merge as is.

#4 lore raw
Quoted 4 lines · Philippe Mathieu-Daudé

FWIW I noticed the patch subject is truncated to my default git-view because it is over 72 chars. Since there is no enforcement on patch subject / description lines length in checkpatch.pl I suppose nobody really cares about that so I'll merge as is.

I treat subject length stuff as an "it would be nice to be below this" thing -- I try to keep them from being overlong lines. But sometimes you really can't express what the patch is doing in that length limit, and in those cases I favour having a slightly long subject line over having one that doesn't say what the patch is doing.

In the description part, we should be keeping away from overlength lines by having them wrap at 75 chars or less, unless there's a strong reason to not wrap (usually it's a URL or we're quoting an error message).

thanks
-- PMM