diff mbox series

[v3,03/11] i2c: nomadik: simplify IRQ masking logic

Message ID 20240306-mbly-i2c-v3-3-605f866aa4ec@bootlin.com
State Accepted
Delegated to: Andi Shyti
Headers show
Series Add Mobileye EyeQ5 support to the Nomadik I2C controller & use hrtimers for timeouts | expand

Commit Message

Théo Lebrun March 6, 2024, 5:59 p.m. UTC
IRQ_MASK and I2C_CLEAR_ALL_INTS both mask available interrupts. IRQ_MASK
removes top options (bits 29-31). I2C_CLEAR_ALL_INTS removes reserved
options including top bits. Keep the latter.

31  29  27  25  23  21  19  17  15  13  11  09  07  05  03  01
  30  28  26  24  22  20  18  16  14  12  10  08  06  04  02  00
--- IRQ_MASK: --------------------------------------------------
      1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
0 0 0
--- I2C_CLEAR_ALL_INTS: ----------------------------------------
      1     1 1       1 1 1 1 1                   1 1 1 1 1 1 1
0 0 0   0 0     0 0 0           0 0 0 0 0 0 0 0 0

Notice I2C_CLEAR_ALL_INTS is more restrictive than IRQ_MASK.

Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Théo Lebrun <theo.lebrun@bootlin.com>
---
 drivers/i2c/busses/i2c-nomadik.c | 18 ++++++------------
 1 file changed, 6 insertions(+), 12 deletions(-)

Comments

Andi Shyti March 7, 2024, 11:01 p.m. UTC | #1
Hi Theo,

On Wed, Mar 06, 2024 at 06:59:23PM +0100, Théo Lebrun wrote:
> IRQ_MASK and I2C_CLEAR_ALL_INTS both mask available interrupts. IRQ_MASK
> removes top options (bits 29-31). I2C_CLEAR_ALL_INTS removes reserved
> options including top bits. Keep the latter.
> 
> 31  29  27  25  23  21  19  17  15  13  11  09  07  05  03  01
>   30  28  26  24  22  20  18  16  14  12  10  08  06  04  02  00
> --- IRQ_MASK: --------------------------------------------------
>       1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
> 0 0 0
> --- I2C_CLEAR_ALL_INTS: ----------------------------------------
>       1     1 1       1 1 1 1 1                   1 1 1 1 1 1 1
> 0 0 0   0 0     0 0 0           0 0 0 0 0 0 0 0 0
> 
> Notice I2C_CLEAR_ALL_INTS is more restrictive than IRQ_MASK.
> 
> Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
> Signed-off-by: Théo Lebrun <theo.lebrun@bootlin.com>

You did answer my question in v2, thanks, Theo!

Reviewed-by: Andi Shyti <andi.shyti@kernel.org>

Andi
Théo Lebrun March 8, 2024, 8:57 a.m. UTC | #2
Hello,

On Fri Mar 8, 2024 at 12:01 AM CET, Andi Shyti wrote:
> Hi Theo,
>
> On Wed, Mar 06, 2024 at 06:59:23PM +0100, Théo Lebrun wrote:
> > IRQ_MASK and I2C_CLEAR_ALL_INTS both mask available interrupts. IRQ_MASK
> > removes top options (bits 29-31). I2C_CLEAR_ALL_INTS removes reserved
> > options including top bits. Keep the latter.
> > 
> > 31  29  27  25  23  21  19  17  15  13  11  09  07  05  03  01
> >   30  28  26  24  22  20  18  16  14  12  10  08  06  04  02  00
> > --- IRQ_MASK: --------------------------------------------------
> >       1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
> > 0 0 0
> > --- I2C_CLEAR_ALL_INTS: ----------------------------------------
> >       1     1 1       1 1 1 1 1                   1 1 1 1 1 1 1
> > 0 0 0   0 0     0 0 0           0 0 0 0 0 0 0 0 0
> > 
> > Notice I2C_CLEAR_ALL_INTS is more restrictive than IRQ_MASK.
> > 
> > Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
> > Signed-off-by: Théo Lebrun <theo.lebrun@bootlin.com>
>
> You did answer my question in v2, thanks, Theo!

Oops my mailer syntax is telling me that the lines starting with '---'
might cause issue as it might mark the end of commit messages. I'll fix
that in next revision. If it gets applied before that it should be
checked that part of the message doesn't get lost.

Thanks Andi,

--
Théo Lebrun, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
Andi Shyti March 8, 2024, 12:27 p.m. UTC | #3
Hi Theo,

On Fri, Mar 08, 2024 at 09:57:39AM +0100, Théo Lebrun wrote:
> Hello,
> 
> On Fri Mar 8, 2024 at 12:01 AM CET, Andi Shyti wrote:
> > Hi Theo,
> >
> > On Wed, Mar 06, 2024 at 06:59:23PM +0100, Théo Lebrun wrote:
> > > IRQ_MASK and I2C_CLEAR_ALL_INTS both mask available interrupts. IRQ_MASK
> > > removes top options (bits 29-31). I2C_CLEAR_ALL_INTS removes reserved
> > > options including top bits. Keep the latter.
> > > 
> > > 31  29  27  25  23  21  19  17  15  13  11  09  07  05  03  01
> > >   30  28  26  24  22  20  18  16  14  12  10  08  06  04  02  00
> > > --- IRQ_MASK: --------------------------------------------------
> > >       1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
> > > 0 0 0
> > > --- I2C_CLEAR_ALL_INTS: ----------------------------------------
> > >       1     1 1       1 1 1 1 1                   1 1 1 1 1 1 1
> > > 0 0 0   0 0     0 0 0           0 0 0 0 0 0 0 0 0
> > > 
> > > Notice I2C_CLEAR_ALL_INTS is more restrictive than IRQ_MASK.
> > > 
> > > Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
> > > Signed-off-by: Théo Lebrun <theo.lebrun@bootlin.com>
> >
> > You did answer my question in v2, thanks, Theo!
> 
> Oops my mailer syntax is telling me that the lines starting with '---'
> might cause issue as it might mark the end of commit messages. I'll fix
> that in next revision. If it gets applied before that it should be
> checked that part of the message doesn't get lost.

mmhhh... right! No need to resend, if nothing else is needed from
the series, please paste the commit message here and I will fix
it.

Andi
Théo Lebrun March 8, 2024, 1:33 p.m. UTC | #4
Hello,

On Fri Mar 8, 2024 at 1:27 PM CET, Andi Shyti wrote:
> Hi Theo,
>
> On Fri, Mar 08, 2024 at 09:57:39AM +0100, Théo Lebrun wrote:
> > Hello,
> > 
> > On Fri Mar 8, 2024 at 12:01 AM CET, Andi Shyti wrote:
> > > Hi Theo,
> > >
> > > On Wed, Mar 06, 2024 at 06:59:23PM +0100, Théo Lebrun wrote:
> > > > IRQ_MASK and I2C_CLEAR_ALL_INTS both mask available interrupts. IRQ_MASK
> > > > removes top options (bits 29-31). I2C_CLEAR_ALL_INTS removes reserved
> > > > options including top bits. Keep the latter.
> > > > 
> > > > 31  29  27  25  23  21  19  17  15  13  11  09  07  05  03  01
> > > >   30  28  26  24  22  20  18  16  14  12  10  08  06  04  02  00
> > > > --- IRQ_MASK: --------------------------------------------------
> > > >       1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
> > > > 0 0 0
> > > > --- I2C_CLEAR_ALL_INTS: ----------------------------------------
> > > >       1     1 1       1 1 1 1 1                   1 1 1 1 1 1 1
> > > > 0 0 0   0 0     0 0 0           0 0 0 0 0 0 0 0 0
> > > > 
> > > > Notice I2C_CLEAR_ALL_INTS is more restrictive than IRQ_MASK.
> > > > 
> > > > Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
> > > > Signed-off-by: Théo Lebrun <theo.lebrun@bootlin.com>
> > >
> > > You did answer my question in v2, thanks, Theo!
> > 
> > Oops my mailer syntax is telling me that the lines starting with '---'
> > might cause issue as it might mark the end of commit messages. I'll fix
> > that in next revision. If it gets applied before that it should be
> > checked that part of the message doesn't get lost.
>
> mmhhh... right! No need to resend, if nothing else is needed from
> the series, please paste the commit message here and I will fix
> it.

The message would become the following (tab-indented). Both '---' turned
into '--' in the bit table. I confirmed `git am` does not truncate this
updated message.

	i2c: nomadik: simplify IRQ masking logic

	IRQ_MASK and I2C_CLEAR_ALL_INTS both mask available interrupts. IRQ_MASK
	removes top options (bits 29-31). I2C_CLEAR_ALL_INTS removes reserved
	options including top bits. Keep the latter.

	31  29  27  25  23  21  19  17  15  13  11  09  07  05  03  01
	  30  28  26  24  22  20  18  16  14  12  10  08  06  04  02  00
	-- IRQ_MASK: ---------------------------------------------------
	      1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
	0 0 0
	-- I2C_CLEAR_ALL_INTS: -----------------------------------------
	      1     1 1       1 1 1 1 1                   1 1 1 1 1 1 1
	0 0 0   0 0     0 0 0           0 0 0 0 0 0 0 0 0

	Notice I2C_CLEAR_ALL_INTS is more restrictive than IRQ_MASK.

	Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
	Signed-off-by: Théo Lebrun <theo.lebrun@bootlin.com>

Thanks for the quick follow-up!

--
Théo Lebrun, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
diff mbox series

Patch

diff --git a/drivers/i2c/busses/i2c-nomadik.c b/drivers/i2c/busses/i2c-nomadik.c
index cd511c884f99..80bdf7e42613 100644
--- a/drivers/i2c/busses/i2c-nomadik.c
+++ b/drivers/i2c/busses/i2c-nomadik.c
@@ -94,9 +94,6 @@ 
 /* some bits in ICR are reserved */
 #define I2C_CLEAR_ALL_INTS	0x131f007f
 
-/* first three msb bits are reserved */
-#define IRQ_MASK(mask)		(mask & 0x1fffffff)
-
 /* maximum threshold value */
 #define MAX_I2C_FIFO_THRESHOLD	15
 
@@ -249,8 +246,7 @@  static int flush_i2c_fifo(struct nmk_i2c_dev *priv)
  */
 static void disable_all_interrupts(struct nmk_i2c_dev *priv)
 {
-	u32 mask = IRQ_MASK(0);
-	writel(mask, priv->virtbase + I2C_IMSCR);
+	writel(0, priv->virtbase + I2C_IMSCR);
 }
 
 /**
@@ -259,9 +255,7 @@  static void disable_all_interrupts(struct nmk_i2c_dev *priv)
  */
 static void clear_all_interrupts(struct nmk_i2c_dev *priv)
 {
-	u32 mask;
-	mask = IRQ_MASK(I2C_CLEAR_ALL_INTS);
-	writel(mask, priv->virtbase + I2C_ICR);
+	writel(I2C_CLEAR_ALL_INTS, priv->virtbase + I2C_ICR);
 }
 
 /**
@@ -468,7 +462,7 @@  static int read_i2c(struct nmk_i2c_dev *priv, u16 flags)
 	else
 		irq_mask |= I2C_IT_MTDWS;
 
-	irq_mask = I2C_CLEAR_ALL_INTS & IRQ_MASK(irq_mask);
+	irq_mask &= I2C_CLEAR_ALL_INTS;
 
 	writel(readl(priv->virtbase + I2C_IMSCR) | irq_mask,
 	       priv->virtbase + I2C_IMSCR);
@@ -547,7 +541,7 @@  static int write_i2c(struct nmk_i2c_dev *priv, u16 flags)
 	else
 		irq_mask |= I2C_IT_MTDWS;
 
-	irq_mask = I2C_CLEAR_ALL_INTS & IRQ_MASK(irq_mask);
+	irq_mask &= I2C_CLEAR_ALL_INTS;
 
 	writel(readl(priv->virtbase + I2C_IMSCR) | irq_mask,
 	       priv->virtbase + I2C_IMSCR);
@@ -703,8 +697,8 @@  static int nmk_i2c_xfer(struct i2c_adapter *i2c_adap,
  */
 static int disable_interrupts(struct nmk_i2c_dev *priv, u32 irq)
 {
-	irq = IRQ_MASK(irq);
-	writel(readl(priv->virtbase + I2C_IMSCR) & ~(I2C_CLEAR_ALL_INTS & irq),
+	irq &= I2C_CLEAR_ALL_INTS;
+	writel(readl(priv->virtbase + I2C_IMSCR) & ~irq,
 	       priv->virtbase + I2C_IMSCR);
 	return 0;
 }