All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] spi: pl022: Fix calculate_effective_freq()
@ 2012-04-19  9:14 Viresh Kumar
       [not found] ` <a90e4161f6d2fa30827bedcc2b001dbb50585b46.1334826569.git.viresh.kumar-qxv4g6HH51o@public.gmane.org>
  0 siblings, 1 reply; 4+ messages in thread
From: Viresh Kumar @ 2012-04-19  9:14 UTC (permalink / raw)
  To: linus.walleij-QSEj5FYQhm4dnm+yROfE0A,
	grant.likely-s3s/WqlpOiPyB63q8FvJNQ
  Cc: spi-devel-general-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f, Viresh Kumar,
	spear-devel-nkJGhpqTU55BDgjK7y7TUQ, vinit.shenoy-qxv4g6HH51o

calculate_effective_freq() was still not optimized and there were cases when it
returned without error and with values of cpsr and scr as zero.

Also, the variable named found is not used well.

This patch targets to optimize and correct this routine. Tested for SPEAr.

Signed-off-by: Viresh Kumar <viresh.kumar-qxv4g6HH51o@public.gmane.org>
Tested-by: Vinit Kamalaksha Shenoy <vinit.shenoy-qxv4g6HH51o@public.gmane.org>
---
 drivers/spi/spi-pl022.c |   23 +++++++++++++++++------
 1 files changed, 17 insertions(+), 6 deletions(-)

diff --git a/drivers/spi/spi-pl022.c b/drivers/spi/spi-pl022.c
index 99d5f6d..490be03 100644
--- a/drivers/spi/spi-pl022.c
+++ b/drivers/spi/spi-pl022.c
@@ -1687,26 +1687,37 @@ static int calculate_effective_freq(struct pl022 *pl022, int freq, struct
 		while (scr <= SCR_MAX) {
 			tmp = spi_rate(rate, cpsdvsr, scr);
 
-			if (tmp > freq)
+			if (tmp > freq) {
+				/* we need lower freq */
 				scr++;
+				continue;
+			}
+
 			/*
-			 * If found exact value, update and break.
-			 * If found more closer value, update and continue.
+			 * If found exact value, mark found and break.
+			 * If found more closer value, update and break.
 			 */
-			else if ((tmp == freq) || (tmp > best_freq)) {
+			if (tmp > best_freq) {
 				best_freq = tmp;
 				best_cpsdvsr = cpsdvsr;
 				best_scr = scr;
 
 				if (tmp == freq)
-					break;
+					found = 1;
 			}
-			scr++;
+			/*
+			 * increased scr will give lower rates, which are not
+			 * required
+			 */
+			break;
 		}
 		cpsdvsr += 2;
 		scr = SCR_MIN;
 	}
 
+	WARN(!best_freq, "pl022: Matching cpsdvsr and scr not found for %d Hz rate \n",
+			freq);
+
 	clk_freq->cpsdvsr = (u8) (best_cpsdvsr & 0xFF);
 	clk_freq->scr = (u8) (best_scr & 0xFF);
 	dev_dbg(&pl022->adev->dev,
-- 
1.7.9


------------------------------------------------------------------------------
For Developers, A Lot Can Happen In A Second.
Boundary is the first to Know...and Tell You.
Monitor Your Applications in Ultra-Fine Resolution. Try it FREE!
http://p.sf.net/sfu/Boundary-d2dvs2

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

* Re: [PATCH] spi: pl022: Fix calculate_effective_freq()
       [not found] ` <a90e4161f6d2fa30827bedcc2b001dbb50585b46.1334826569.git.viresh.kumar-qxv4g6HH51o@public.gmane.org>
@ 2012-04-26  6:27   ` Viresh Kumar
  2012-04-26  8:29   ` Linus Walleij
  1 sibling, 0 replies; 4+ messages in thread
From: Viresh Kumar @ 2012-04-26  6:27 UTC (permalink / raw)
  To: linus.walleij-QSEj5FYQhm4dnm+yROfE0A
  Cc: spi-devel-general-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f, spear-devel,
	Vinit Kamalaksha SHENOY

On 4/19/2012 2:44 PM, Viresh KUMAR wrote:
> calculate_effective_freq() was still not optimized and there were cases when it
> returned without error and with values of cpsr and scr as zero.
> 
> Also, the variable named found is not used well.
> 
> This patch targets to optimize and correct this routine. Tested for SPEAr.
> 
> Signed-off-by: Viresh Kumar <viresh.kumar-qxv4g6HH51o@public.gmane.org>
> Tested-by: Vinit Kamalaksha Shenoy <vinit.shenoy-qxv4g6HH51o@public.gmane.org>

You forgot to review this :)

-- 
viresh

------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/

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

* Re: [PATCH] spi: pl022: Fix calculate_effective_freq()
       [not found] ` <a90e4161f6d2fa30827bedcc2b001dbb50585b46.1334826569.git.viresh.kumar-qxv4g6HH51o@public.gmane.org>
  2012-04-26  6:27   ` Viresh Kumar
@ 2012-04-26  8:29   ` Linus Walleij
       [not found]     ` <CACRpkdb7YuWAwXDzn+6TuZ_KDADi1KMy7_z-ngtVUx1B=e13mQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
  1 sibling, 1 reply; 4+ messages in thread
From: Linus Walleij @ 2012-04-26  8:29 UTC (permalink / raw)
  To: Viresh Kumar
  Cc: vinit.shenoy-qxv4g6HH51o, spear-devel-nkJGhpqTU55BDgjK7y7TUQ,
	spi-devel-general-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f, Chris Blair

On Thu, Apr 19, 2012 at 11:14 AM, Viresh Kumar <viresh.kumar-qxv4g6HH51o@public.gmane.org> wrote:

> calculate_effective_freq() was still not optimized and there were cases when it
> returned without error and with values of cpsr and scr as zero.
>
> Also, the variable named found is not used well.
>
> This patch targets to optimize and correct this routine. Tested for SPEAr.
>
> Signed-off-by: Viresh Kumar <viresh.kumar-qxv4g6HH51o@public.gmane.org>
> Tested-by: Vinit Kamalaksha Shenoy <vinit.shenoy-qxv4g6HH51o@public.gmane.org>

Looks good to me.
Acked-by: Linus Walleij <linus.walleij-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>

Yours,
Linus Walleij

------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/

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

* Re: [PATCH] spi: pl022: Fix calculate_effective_freq()
       [not found]     ` <CACRpkdb7YuWAwXDzn+6TuZ_KDADi1KMy7_z-ngtVUx1B=e13mQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
@ 2012-04-27 16:48       ` Grant Likely
  0 siblings, 0 replies; 4+ messages in thread
From: Grant Likely @ 2012-04-27 16:48 UTC (permalink / raw)
  To: Linus Walleij, Viresh Kumar
  Cc: spi-devel-general-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f,
	spear-devel-nkJGhpqTU55BDgjK7y7TUQ, vinit.shenoy-qxv4g6HH51o,
	Chris Blair

On Thu, 26 Apr 2012 10:29:19 +0200, Linus Walleij <linus.walleij-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org> wrote:
> On Thu, Apr 19, 2012 at 11:14 AM, Viresh Kumar <viresh.kumar-qxv4g6HH51o@public.gmane.org> wrote:
> 
> > calculate_effective_freq() was still not optimized and there were cases when it
> > returned without error and with values of cpsr and scr as zero.
> >
> > Also, the variable named found is not used well.
> >
> > This patch targets to optimize and correct this routine. Tested for SPEAr.
> >
> > Signed-off-by: Viresh Kumar <viresh.kumar-qxv4g6HH51o@public.gmane.org>
> > Tested-by: Vinit Kamalaksha Shenoy <vinit.shenoy-qxv4g6HH51o@public.gmane.org>
> 
> Looks good to me.
> Acked-by: Linus Walleij <linus.walleij-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>
> 
> Yours,
> Linus Walleij

Applied, thanks.

g.

-- 
Grant Likely, B.Sc, P.Eng.
Secret Lab Technologies, Ltd.

------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/

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

end of thread, other threads:[~2012-04-27 16:48 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-04-19  9:14 [PATCH] spi: pl022: Fix calculate_effective_freq() Viresh Kumar
     [not found] ` <a90e4161f6d2fa30827bedcc2b001dbb50585b46.1334826569.git.viresh.kumar-qxv4g6HH51o@public.gmane.org>
2012-04-26  6:27   ` Viresh Kumar
2012-04-26  8:29   ` Linus Walleij
     [not found]     ` <CACRpkdb7YuWAwXDzn+6TuZ_KDADi1KMy7_z-ngtVUx1B=e13mQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2012-04-27 16:48       ` Grant Likely

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.