aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/spi/spi-pl022.c
diff options
context:
space:
mode:
authorViresh Kumar <viresh.kumar@st.com>2012-04-19 05:14:21 -0400
committerGrant Likely <grant.likely@secretlab.ca>2012-04-27 12:47:51 -0400
commit5eb806a3a68920a9f373f18b03fa14852047e62b (patch)
tree0a5ecac4d4b8c729cefe70c6f406c17f274774db /drivers/spi/spi-pl022.c
parenteb798c641a34ae9cee9fcacfbe5dd40bd7777607 (diff)
spi/pl022: Fix calculate_effective_freq()
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@st.com> Tested-by: Vinit Kamalaksha Shenoy <vinit.shenoy@st.com> Acked-by: Linus Walleij <linus.walleij@linaro.org> Signed-off-by: Grant Likely <grant.likely@secretlab.ca>
Diffstat (limited to 'drivers/spi/spi-pl022.c')
-rw-r--r--drivers/spi/spi-pl022.c23
1 files changed, 17 insertions, 6 deletions
diff --git a/drivers/spi/spi-pl022.c b/drivers/spi/spi-pl022.c
index 1ead49dbebce..8aa44e7adaef 100644
--- a/drivers/spi/spi-pl022.c
+++ b/drivers/spi/spi-pl022.c
@@ -1681,26 +1681,37 @@ static int calculate_effective_freq(struct pl022 *pl022, int freq, struct
1681 while (scr <= SCR_MAX) { 1681 while (scr <= SCR_MAX) {
1682 tmp = spi_rate(rate, cpsdvsr, scr); 1682 tmp = spi_rate(rate, cpsdvsr, scr);
1683 1683
1684 if (tmp > freq) 1684 if (tmp > freq) {
1685 /* we need lower freq */
1685 scr++; 1686 scr++;
1687 continue;
1688 }
1689
1686 /* 1690 /*
1687 * If found exact value, update and break. 1691 * If found exact value, mark found and break.
1688 * If found more closer value, update and continue. 1692 * If found more closer value, update and break.
1689 */ 1693 */
1690 else if ((tmp == freq) || (tmp > best_freq)) { 1694 if (tmp > best_freq) {
1691 best_freq = tmp; 1695 best_freq = tmp;
1692 best_cpsdvsr = cpsdvsr; 1696 best_cpsdvsr = cpsdvsr;
1693 best_scr = scr; 1697 best_scr = scr;
1694 1698
1695 if (tmp == freq) 1699 if (tmp == freq)
1696 break; 1700 found = 1;
1697 } 1701 }
1698 scr++; 1702 /*
1703 * increased scr will give lower rates, which are not
1704 * required
1705 */
1706 break;
1699 } 1707 }
1700 cpsdvsr += 2; 1708 cpsdvsr += 2;
1701 scr = SCR_MIN; 1709 scr = SCR_MIN;
1702 } 1710 }
1703 1711
1712 WARN(!best_freq, "pl022: Matching cpsdvsr and scr not found for %d Hz rate \n",
1713 freq);
1714
1704 clk_freq->cpsdvsr = (u8) (best_cpsdvsr & 0xFF); 1715 clk_freq->cpsdvsr = (u8) (best_cpsdvsr & 0xFF);
1705 clk_freq->scr = (u8) (best_scr & 0xFF); 1716 clk_freq->scr = (u8) (best_scr & 0xFF);
1706 dev_dbg(&pl022->adev->dev, 1717 dev_dbg(&pl022->adev->dev,