From: Tomasz Figa <tomasz.figa@gmail.com>
To: linux-mmc@vger.kernel.org
Cc: linux-samsung-soc@vger.kernel.org,
linux-arm-kernel@lists.infradead.org,
Ben Dooks <ben-linux@fluff.org>, Chris Ball <chris@printf.net>,
Jaehoon Chung <jh80.chung@samsung.com>,
Seungwon Jeon <tgih.jun@samsung.com>,
Marek Szyprowski <m.szyprowski@samsung.com>,
Tomasz Figa <tomasz.figa@gmail.com>
Subject: [PATCH 4/6] mmc: sdhci-s3c: Simplify min/max clock calculation
Date: Sat, 11 Jan 2014 22:39:04 +0100 [thread overview]
Message-ID: <1389476346-20396-5-git-send-email-tomasz.figa@gmail.com> (raw)
In-Reply-To: <1389476346-20396-1-git-send-email-tomasz.figa@gmail.com>
This patch reimplements functions calculating minimum and maximum clock
rates to leverage clock rate cache introduced by previous patches.
In addition, the calculation is simplified to just comparing input
clock rates (max case) or input clock rates divided by maximum divisor
(min case), which is basically what the original code did, but with much
more unnecessary work.
Signed-off-by: Tomasz Figa <tomasz.figa@gmail.com>
---
drivers/mmc/host/sdhci-s3c.c | 60 +++++++++++++++++++++++++++++---------------
1 file changed, 40 insertions(+), 20 deletions(-)
diff --git a/drivers/mmc/host/sdhci-s3c.c b/drivers/mmc/host/sdhci-s3c.c
index 7fde938..7e14db0 100644
--- a/drivers/mmc/host/sdhci-s3c.c
+++ b/drivers/mmc/host/sdhci-s3c.c
@@ -112,20 +112,16 @@ static void sdhci_s3c_check_sclk(struct sdhci_host *host)
static unsigned int sdhci_s3c_get_max_clk(struct sdhci_host *host)
{
struct sdhci_s3c *ourhost = to_s3c(host);
- struct clk *busclk;
- unsigned int rate, max;
- int clk;
+ unsigned long rate, max = 0;
+ int src;
/* note, a reset will reset the clock source */
sdhci_s3c_check_sclk(host);
- for (max = 0, clk = 0; clk < MAX_BUS_CLK; clk++) {
- busclk = ourhost->clk_bus[clk];
- if (!busclk)
- continue;
- rate = clk_get_rate(busclk);
+ for (src = 0; src < MAX_BUS_CLK; src++) {
+ rate = ourhost->clk_rates[src];
if (rate > max)
max = rate;
}
@@ -255,17 +251,17 @@ static void sdhci_s3c_set_clock(struct sdhci_host *host, unsigned int clock)
static unsigned int sdhci_s3c_get_min_clock(struct sdhci_host *host)
{
struct sdhci_s3c *ourhost = to_s3c(host);
- unsigned int delta, min = UINT_MAX;
+ unsigned long rate, min = ULONG_MAX;
int src;
for (src = 0; src < MAX_BUS_CLK; src++) {
- delta = sdhci_s3c_consider_clock(ourhost, src, 0);
- if (delta == UINT_MAX)
+ rate = ourhost->clk_rates[src] / 256;
+ if (!rate)
continue;
- /* delta is a negative value in this case */
- if (-delta < min)
- min = -delta;
+ if (rate < min)
+ min = rate;
}
+
return min;
}
@@ -273,20 +269,44 @@ static unsigned int sdhci_s3c_get_min_clock(struct sdhci_host *host)
static unsigned int sdhci_cmu_get_max_clock(struct sdhci_host *host)
{
struct sdhci_s3c *ourhost = to_s3c(host);
+ unsigned long rate, max = 0;
+ int src;
+
+ for (src = 0; src < MAX_BUS_CLK; src++) {
+ struct clk *clk;
+
+ clk = ourhost->clk_bus[src];
+ if (IS_ERR(clk))
+ continue;
+
+ rate = clk_round_rate(clk, ULONG_MAX);
+ if (rate > max)
+ max = rate;
+ }
- return clk_round_rate(ourhost->clk_bus[ourhost->cur_clk], UINT_MAX);
+ return max;
}
/* sdhci_cmu_get_min_clock - callback to get minimal supported clock value. */
static unsigned int sdhci_cmu_get_min_clock(struct sdhci_host *host)
{
struct sdhci_s3c *ourhost = to_s3c(host);
+ unsigned long rate, min = ULONG_MAX;
+ int src;
- /*
- * initial clock can be in the frequency range of
- * 100KHz-400KHz, so we set it as max value.
- */
- return clk_round_rate(ourhost->clk_bus[ourhost->cur_clk], 400000);
+ for (src = 0; src < MAX_BUS_CLK; src++) {
+ struct clk *clk;
+
+ clk = ourhost->clk_bus[src];
+ if (IS_ERR(clk))
+ continue;
+
+ rate = clk_round_rate(clk, 0);
+ if (rate < min)
+ min = rate;
+ }
+
+ return min;
}
/* sdhci_cmu_set_clock - callback on clock change.*/
--
1.8.5.2
next prev parent reply other threads:[~2014-01-11 21:39 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-01-11 21:39 [PATCH 0/6] mmc: sdhci-s3c: Fix base clock source management Tomasz Figa
2014-01-11 21:39 ` [PATCH 1/6] mmc: sdhci-s3c: Use shifts to divide by powers of two Tomasz Figa
2014-01-11 21:39 ` [PATCH 2/6] mmc: sdhci-s3c: Cache bus clock rates Tomasz Figa
2014-01-11 21:39 ` [PATCH 3/6] mmc: sdhci-s3c: Use correct condition to check for clock presence Tomasz Figa
2014-01-11 21:39 ` Tomasz Figa [this message]
2014-01-11 21:39 ` [PATCH 5/6] mmc: sdhci-s3c: Fix handling of bus clock switching Tomasz Figa
2014-01-11 21:39 ` [PATCH 6/6] mmc: sdhci-s3c: Do not allow frequencies higher than requested Tomasz Figa
2014-01-12 21:18 ` [PATCH 0/6] mmc: sdhci-s3c: Fix base clock source management Heiko Stübner
2014-01-13 5:47 ` Jaehoon Chung
2014-01-13 12:43 ` Tomasz Figa
2014-02-07 9:58 ` Tomasz Figa
2014-02-20 19:26 ` Tomasz Figa
2014-03-03 15:06 ` Tomasz Figa
2014-03-03 15:24 ` Chris Ball
2014-03-03 15:25 ` Tomasz Figa
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1389476346-20396-5-git-send-email-tomasz.figa@gmail.com \
--to=tomasz.figa@gmail.com \
--cc=ben-linux@fluff.org \
--cc=chris@printf.net \
--cc=jh80.chung@samsung.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-mmc@vger.kernel.org \
--cc=linux-samsung-soc@vger.kernel.org \
--cc=m.szyprowski@samsung.com \
--cc=tgih.jun@samsung.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).