diff mbox

[1/4] i2c: designware: No need to disable already disabled controller

Message ID 1400164644-3222-2-git-send-email-mika.westerberg@linux.intel.com
State Rejected
Headers show

Commit Message

Mika Westerberg May 15, 2014, 2:37 p.m. UTC
If the controller is already in desired state (enabled/disabled) there is
no point in setting its state again.

Signed-off-by: Mika Westerberg <mika.westerberg@linux.intel.com>
---
 drivers/i2c/busses/i2c-designware-core.c | 4 ++++
 1 file changed, 4 insertions(+)

Comments

Wolfram Sang June 2, 2014, 4:12 p.m. UTC | #1
On Thu, May 15, 2014 at 05:37:21PM +0300, Mika Westerberg wrote:
> If the controller is already in desired state (enabled/disabled) there is
> no point in setting its state again.
> 
> Signed-off-by: Mika Westerberg <mika.westerberg@linux.intel.com>
> ---

Does it have a side-effect when setting then enable bit again? Otherwise
it will exit the loop immediately on the first try. Not too bad IMO
given the additional code saved.

>  drivers/i2c/busses/i2c-designware-core.c | 4 ++++
>  1 file changed, 4 insertions(+)
> 
> diff --git a/drivers/i2c/busses/i2c-designware-core.c b/drivers/i2c/busses/i2c-designware-core.c
> index b58ecf19e767..b0792675b970 100644
> --- a/drivers/i2c/busses/i2c-designware-core.c
> +++ b/drivers/i2c/busses/i2c-designware-core.c
> @@ -258,6 +258,10 @@ static void __i2c_dw_enable(struct dw_i2c_dev *dev, bool enable)
>  {
>  	int timeout = 100;
>  
> +	/* In case the controller is already in desired state */
> +	if ((dw_readl(dev, DW_IC_ENABLE_STATUS) & 1) == enable)
> +		return;
> +
>  	do {
>  		dw_writel(dev, enable, DW_IC_ENABLE);
>  		if ((dw_readl(dev, DW_IC_ENABLE_STATUS) & 1) == enable)
> -- 
> 2.0.0.rc2
>
Mika Westerberg June 2, 2014, 5:34 p.m. UTC | #2
On Mon, Jun 02, 2014 at 06:12:34PM +0200, Wolfram Sang wrote:
> On Thu, May 15, 2014 at 05:37:21PM +0300, Mika Westerberg wrote:
> > If the controller is already in desired state (enabled/disabled) there is
> > no point in setting its state again.
> > 
> > Signed-off-by: Mika Westerberg <mika.westerberg@linux.intel.com>
> > ---
> 
> Does it have a side-effect when setting then enable bit again? Otherwise
> it will exit the loop immediately on the first try. Not too bad IMO
> given the additional code saved.

AFAICT there shouldn't be any side effect. So the $subject patch just
saves one register write in the best case. You are right, maybe it's not
worth adding 3 extra lines of code just for that :)

> 
> >  drivers/i2c/busses/i2c-designware-core.c | 4 ++++
> >  1 file changed, 4 insertions(+)
> > 
> > diff --git a/drivers/i2c/busses/i2c-designware-core.c b/drivers/i2c/busses/i2c-designware-core.c
> > index b58ecf19e767..b0792675b970 100644
> > --- a/drivers/i2c/busses/i2c-designware-core.c
> > +++ b/drivers/i2c/busses/i2c-designware-core.c
> > @@ -258,6 +258,10 @@ static void __i2c_dw_enable(struct dw_i2c_dev *dev, bool enable)
> >  {
> >  	int timeout = 100;
> >  
> > +	/* In case the controller is already in desired state */
> > +	if ((dw_readl(dev, DW_IC_ENABLE_STATUS) & 1) == enable)
> > +		return;
> > +
> >  	do {
> >  		dw_writel(dev, enable, DW_IC_ENABLE);
> >  		if ((dw_readl(dev, DW_IC_ENABLE_STATUS) & 1) == enable)
> > -- 
> > 2.0.0.rc2
> > 


--
To unsubscribe from this list: send the line "unsubscribe linux-i2c" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Wolfram Sang June 2, 2014, 5:36 p.m. UTC | #3
On Mon, Jun 02, 2014 at 08:34:08PM +0300, Mika Westerberg wrote:
> On Mon, Jun 02, 2014 at 06:12:34PM +0200, Wolfram Sang wrote:
> > On Thu, May 15, 2014 at 05:37:21PM +0300, Mika Westerberg wrote:
> > > If the controller is already in desired state (enabled/disabled) there is
> > > no point in setting its state again.
> > > 
> > > Signed-off-by: Mika Westerberg <mika.westerberg@linux.intel.com>
> > > ---
> > 
> > Does it have a side-effect when setting then enable bit again? Otherwise
> > it will exit the loop immediately on the first try. Not too bad IMO
> > given the additional code saved.
> 
> AFAICT there shouldn't be any side effect. So the $subject patch just
> saves one register write in the best case. You are right, maybe it's not
> worth adding 3 extra lines of code just for that :)

:) Okay, so I'll drop it.
diff mbox

Patch

diff --git a/drivers/i2c/busses/i2c-designware-core.c b/drivers/i2c/busses/i2c-designware-core.c
index b58ecf19e767..b0792675b970 100644
--- a/drivers/i2c/busses/i2c-designware-core.c
+++ b/drivers/i2c/busses/i2c-designware-core.c
@@ -258,6 +258,10 @@  static void __i2c_dw_enable(struct dw_i2c_dev *dev, bool enable)
 {
 	int timeout = 100;
 
+	/* In case the controller is already in desired state */
+	if ((dw_readl(dev, DW_IC_ENABLE_STATUS) & 1) == enable)
+		return;
+
 	do {
 		dw_writel(dev, enable, DW_IC_ENABLE);
 		if ((dw_readl(dev, DW_IC_ENABLE_STATUS) & 1) == enable)