mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH] i2c: designware: use proper type for writel argument
@ 2020-07-06  6:26 Ahmad Fatoum
  2020-07-09 14:20 ` Sascha Hauer
  0 siblings, 1 reply; 2+ messages in thread
From: Ahmad Fatoum @ 2020-07-06  6:26 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

We need to write DW_IC_ENABLE_ENABLE (1 << 0) to the register to enable,
but instead we were writing true. This happens to work, but is quite
unusual. Make the code more readable.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 drivers/i2c/busses/i2c-designware.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/drivers/i2c/busses/i2c-designware.c b/drivers/i2c/busses/i2c-designware.c
index 33f89148f0cc..bb9a0b7c4ad4 100644
--- a/drivers/i2c/busses/i2c-designware.c
+++ b/drivers/i2c/busses/i2c-designware.c
@@ -121,6 +121,8 @@ static inline struct dw_i2c_dev *to_dw_i2c_dev(struct i2c_adapter *a)
 
 static void i2c_dw_enable(struct dw_i2c_dev *dw, bool enable)
 {
+	u32 reg = 0;
+
 	/*
 	 * This subrotine is an implementation of an algorithm
 	 * described in "Cyclone V Hard Processor System Technical
@@ -128,12 +130,13 @@ static void i2c_dw_enable(struct dw_i2c_dev *dw, bool enable)
 	 */
 	int timeout = MAX_T_POLL_COUNT;
 
-	enable = enable ? DW_IC_ENABLE_ENABLE : 0;
+	if (enable)
+		reg |= DW_IC_ENABLE_ENABLE;
 
 	do {
 		uint32_t ic_enable_status;
 
-		writel(enable, dw->base + DW_IC_ENABLE);
+		writel(reg, dw->base + DW_IC_ENABLE);
 
 		ic_enable_status = readl(dw->base + DW_IC_ENABLE_STATUS);
 		if ((ic_enable_status & DW_IC_ENABLE_STATUS_IC_EN) == enable)
-- 
2.27.0


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] i2c: designware: use proper type for writel argument
  2020-07-06  6:26 [PATCH] i2c: designware: use proper type for writel argument Ahmad Fatoum
@ 2020-07-09 14:20 ` Sascha Hauer
  0 siblings, 0 replies; 2+ messages in thread
From: Sascha Hauer @ 2020-07-09 14:20 UTC (permalink / raw)
  To: Ahmad Fatoum; +Cc: barebox

On Mon, Jul 06, 2020 at 08:26:43AM +0200, Ahmad Fatoum wrote:
> We need to write DW_IC_ENABLE_ENABLE (1 << 0) to the register to enable,
> but instead we were writing true. This happens to work, but is quite
> unusual. Make the code more readable.
> 
> Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
> ---
>  drivers/i2c/busses/i2c-designware.c | 7 +++++--
>  1 file changed, 5 insertions(+), 2 deletions(-)

Applied, thanks

Sascha

> 
> diff --git a/drivers/i2c/busses/i2c-designware.c b/drivers/i2c/busses/i2c-designware.c
> index 33f89148f0cc..bb9a0b7c4ad4 100644
> --- a/drivers/i2c/busses/i2c-designware.c
> +++ b/drivers/i2c/busses/i2c-designware.c
> @@ -121,6 +121,8 @@ static inline struct dw_i2c_dev *to_dw_i2c_dev(struct i2c_adapter *a)
>  
>  static void i2c_dw_enable(struct dw_i2c_dev *dw, bool enable)
>  {
> +	u32 reg = 0;
> +
>  	/*
>  	 * This subrotine is an implementation of an algorithm
>  	 * described in "Cyclone V Hard Processor System Technical
> @@ -128,12 +130,13 @@ static void i2c_dw_enable(struct dw_i2c_dev *dw, bool enable)
>  	 */
>  	int timeout = MAX_T_POLL_COUNT;
>  
> -	enable = enable ? DW_IC_ENABLE_ENABLE : 0;
> +	if (enable)
> +		reg |= DW_IC_ENABLE_ENABLE;
>  
>  	do {
>  		uint32_t ic_enable_status;
>  
> -		writel(enable, dw->base + DW_IC_ENABLE);
> +		writel(reg, dw->base + DW_IC_ENABLE);
>  
>  		ic_enable_status = readl(dw->base + DW_IC_ENABLE_STATUS);
>  		if ((ic_enable_status & DW_IC_ENABLE_STATUS_IC_EN) == enable)
> -- 
> 2.27.0
> 
> 
> _______________________________________________
> barebox mailing list
> barebox@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/barebox
> 

-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2020-07-09 14:20 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-06  6:26 [PATCH] i2c: designware: use proper type for writel argument Ahmad Fatoum
2020-07-09 14:20 ` Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox