diff mbox series

[01/12] i2c: pxa: use official address byte helper

Message ID E1igWOT-0005Dp-Sb@rmk-PC.armlinux.org.uk
State Superseded
Headers show
Series i2c-pxa cleanups | expand

Commit Message

Russell King (Oracle) Dec. 15, 2019, 4:05 p.m. UTC
i2c-pxa was created before i2c_8bit_addr_from_msg() was implemented,
and used its own i2c_pxa_addr_byte() which is functionally the same.
Sadly, it was never updated to use this new helper. Switch it over.

Signed-off-by: Russell King <rmk+kernel@armlinux.org.uk>
---
 drivers/i2c/busses/i2c-pxa.c | 21 +++++++--------------
 1 file changed, 7 insertions(+), 14 deletions(-)

Comments

Peter Rosin Jan. 20, 2020, 5:03 p.m. UTC | #1
On 2019-12-15 17:05, Russell King wrote:
> i2c-pxa was created before i2c_8bit_addr_from_msg() was implemented,
> and used its own i2c_pxa_addr_byte() which is functionally the same.
> Sadly, it was never updated to use this new helper. Switch it over.
> 
> Signed-off-by: Russell King <rmk+kernel@armlinux.org.uk>
> ---
>  drivers/i2c/busses/i2c-pxa.c | 21 +++++++--------------
>  1 file changed, 7 insertions(+), 14 deletions(-)
> 
> diff --git a/drivers/i2c/busses/i2c-pxa.c b/drivers/i2c/busses/i2c-pxa.c
> index 2c3c3d6935c0..966000923e8e 100644
> --- a/drivers/i2c/busses/i2c-pxa.c
> +++ b/drivers/i2c/busses/i2c-pxa.c
> @@ -675,25 +675,18 @@ static void i2c_pxa_slave_stop(struct pxa_i2c *i2c)
>   * PXA I2C Master mode
>   */
>  
> -static inline unsigned int i2c_pxa_addr_byte(struct i2c_msg *msg)
> -{
> -	unsigned int addr = (msg->addr & 0x7f) << 1;
> -
> -	if (msg->flags & I2C_M_RD)
> -		addr |= 1;
> -
> -	return addr;
> -}
> -
>  static inline void i2c_pxa_start_message(struct pxa_i2c *i2c)
>  {
>  	u32 icr;
> +	u8 addr;
> +
> +	addr = i2c_8bit_addr_from_msg(i2c->msg);
>  
>  	/*
>  	 * Step 1: target slave address into IDBR
>  	 */
> -	writel(i2c_pxa_addr_byte(i2c->msg), _IDBR(i2c));
> -	i2c->req_slave_addr = i2c_pxa_addr_byte(i2c->msg);
> +	writel(addr, _IDBR(i2c));
> +	i2c->req_slave_addr = addr;

You are introducing a temporary variable (addr) here...

>  
>  	/*
>  	 * Step 2: initiate the write.
> @@ -1006,8 +999,8 @@ static void i2c_pxa_irq_txempty(struct pxa_i2c *i2c, u32 isr)
>  		/*
>  		 * Write the next address.
>  		 */
> -		writel(i2c_pxa_addr_byte(i2c->msg), _IDBR(i2c));
> -		i2c->req_slave_addr = i2c_pxa_addr_byte(i2c->msg);
> +		writel(i2c_8bit_addr_from_msg(i2c->msg), _IDBR(i2c));
> +		i2c->req_slave_addr = i2c_8bit_addr_from_msg(i2c->msg);

...but not here. But it seems like the same pattern. Any particular reason for
that difference?

Cheers,
Peter

>  
>  		/*
>  		 * And trigger a repeated start, and send the byte.
>
Russell King (Oracle) Jan. 20, 2020, 7:13 p.m. UTC | #2
On Mon, Jan 20, 2020 at 05:03:26PM +0000, Peter Rosin wrote:
> On 2019-12-15 17:05, Russell King wrote:
> > i2c-pxa was created before i2c_8bit_addr_from_msg() was implemented,
> > and used its own i2c_pxa_addr_byte() which is functionally the same.
> > Sadly, it was never updated to use this new helper. Switch it over.
> > 
> > Signed-off-by: Russell King <rmk+kernel@armlinux.org.uk>
> > ---
> >  drivers/i2c/busses/i2c-pxa.c | 21 +++++++--------------
> >  1 file changed, 7 insertions(+), 14 deletions(-)
> > 
> > diff --git a/drivers/i2c/busses/i2c-pxa.c b/drivers/i2c/busses/i2c-pxa.c
> > index 2c3c3d6935c0..966000923e8e 100644
> > --- a/drivers/i2c/busses/i2c-pxa.c
> > +++ b/drivers/i2c/busses/i2c-pxa.c
> > @@ -675,25 +675,18 @@ static void i2c_pxa_slave_stop(struct pxa_i2c *i2c)
> >   * PXA I2C Master mode
> >   */
> >  
> > -static inline unsigned int i2c_pxa_addr_byte(struct i2c_msg *msg)
> > -{
> > -	unsigned int addr = (msg->addr & 0x7f) << 1;
> > -
> > -	if (msg->flags & I2C_M_RD)
> > -		addr |= 1;
> > -
> > -	return addr;
> > -}
> > -
> >  static inline void i2c_pxa_start_message(struct pxa_i2c *i2c)
> >  {
> >  	u32 icr;
> > +	u8 addr;
> > +
> > +	addr = i2c_8bit_addr_from_msg(i2c->msg);
> >  
> >  	/*
> >  	 * Step 1: target slave address into IDBR
> >  	 */
> > -	writel(i2c_pxa_addr_byte(i2c->msg), _IDBR(i2c));
> > -	i2c->req_slave_addr = i2c_pxa_addr_byte(i2c->msg);
> > +	writel(addr, _IDBR(i2c));
> > +	i2c->req_slave_addr = addr;
> 
> You are introducing a temporary variable (addr) here...
> 
> >  
> >  	/*
> >  	 * Step 2: initiate the write.
> > @@ -1006,8 +999,8 @@ static void i2c_pxa_irq_txempty(struct pxa_i2c *i2c, u32 isr)
> >  		/*
> >  		 * Write the next address.
> >  		 */
> > -		writel(i2c_pxa_addr_byte(i2c->msg), _IDBR(i2c));
> > -		i2c->req_slave_addr = i2c_pxa_addr_byte(i2c->msg);
> > +		writel(i2c_8bit_addr_from_msg(i2c->msg), _IDBR(i2c));
> > +		i2c->req_slave_addr = i2c_8bit_addr_from_msg(i2c->msg);
> 
> ...but not here. But it seems like the same pattern. Any particular reason for
> that difference?

No real reason.  If I assign i2c->req_slave_addr first, I don't need
a separate variable...
diff mbox series

Patch

diff --git a/drivers/i2c/busses/i2c-pxa.c b/drivers/i2c/busses/i2c-pxa.c
index 2c3c3d6935c0..966000923e8e 100644
--- a/drivers/i2c/busses/i2c-pxa.c
+++ b/drivers/i2c/busses/i2c-pxa.c
@@ -675,25 +675,18 @@  static void i2c_pxa_slave_stop(struct pxa_i2c *i2c)
  * PXA I2C Master mode
  */
 
-static inline unsigned int i2c_pxa_addr_byte(struct i2c_msg *msg)
-{
-	unsigned int addr = (msg->addr & 0x7f) << 1;
-
-	if (msg->flags & I2C_M_RD)
-		addr |= 1;
-
-	return addr;
-}
-
 static inline void i2c_pxa_start_message(struct pxa_i2c *i2c)
 {
 	u32 icr;
+	u8 addr;
+
+	addr = i2c_8bit_addr_from_msg(i2c->msg);
 
 	/*
 	 * Step 1: target slave address into IDBR
 	 */
-	writel(i2c_pxa_addr_byte(i2c->msg), _IDBR(i2c));
-	i2c->req_slave_addr = i2c_pxa_addr_byte(i2c->msg);
+	writel(addr, _IDBR(i2c));
+	i2c->req_slave_addr = addr;
 
 	/*
 	 * Step 2: initiate the write.
@@ -1006,8 +999,8 @@  static void i2c_pxa_irq_txempty(struct pxa_i2c *i2c, u32 isr)
 		/*
 		 * Write the next address.
 		 */
-		writel(i2c_pxa_addr_byte(i2c->msg), _IDBR(i2c));
-		i2c->req_slave_addr = i2c_pxa_addr_byte(i2c->msg);
+		writel(i2c_8bit_addr_from_msg(i2c->msg), _IDBR(i2c));
+		i2c->req_slave_addr = i2c_8bit_addr_from_msg(i2c->msg);
 
 		/*
 		 * And trigger a repeated start, and send the byte.