From: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com> To: Ulf Hansson <ulf.hansson@linaro.org> Cc: linux-mmc <linux-mmc@vger.kernel.org>, Simon <horms@verge.net.au>, Magnus <magnus.damm@gmail.com>, Linux-SH <linux-sh@vger.kernel.org>, Laurent <laurent.pinchart@ideasonboard.com>, Geert Uytterhoeven <geert@linux-m68k.org>, kobayashi <keita.kobayashi.ym@renesas.com> Subject: [PATCH 3/3 v5] mmc: sh_mmcif: calculate best clock with parent clock Date: Wed, 13 May 2015 02:18:22 +0000 [thread overview] Message-ID: <87617xfchj.wl%kuninori.morimoto.gx@renesas.com> (raw) In-Reply-To: <87a8x9fck7.wl%kuninori.morimoto.gx@renesas.com> From: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com> MMCIF IP on R-Car series has parent clock which can be set several rate, and it was not implemented on old SH-Mobile series (= SH-Mobile series parent clock was fixed rate) R-Car series MMCIF can use more high speed access if it setup parent clock. This patch adds parent clock setup method, and r8a7790/r8a7791 can use it. Signed-off-by: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com> Tested-by: Keita Kobayashi <keita.kobayashi.ym@renesas.com> --- v4 -> v5 - get clock data from compatible drivers/mmc/host/sh_mmcif.c | 92 ++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 83 insertions(+), 9 deletions(-) diff --git a/drivers/mmc/host/sh_mmcif.c b/drivers/mmc/host/sh_mmcif.c index e13c5f41..7ade263 100644 --- a/drivers/mmc/host/sh_mmcif.c +++ b/drivers/mmc/host/sh_mmcif.c @@ -57,6 +57,7 @@ #include <linux/mmc/slot-gpio.h> #include <linux/mod_devicetable.h> #include <linux/mutex.h> +#include <linux/of_device.h> #include <linux/pagemap.h> #include <linux/platform_device.h> #include <linux/pm_qos.h> @@ -224,6 +225,15 @@ enum sh_mmcif_wait_for { MMCIF_WAIT_FOR_STOP, }; +/* + * difference for each SoC + */ +struct sh_mmcif_ver { + u32 clkdiv_map; /* see CE_CLK_CTRL::CLKDIV */ + unsigned int pf_min; /* parent frequency min */ + unsigned int pf_max; /* parent frequency max */ +}; + struct sh_mmcif_host { struct mmc_host *mmc; struct mmc_request *mrq; @@ -248,6 +258,7 @@ struct sh_mmcif_host { bool ccs_enable; /* Command Completion Signal support */ bool clk_ctrl2_enable; struct mutex thread_lock; + const struct sh_mmcif_ver *ver; /* DMA support */ struct dma_chan *chan_rx; @@ -256,8 +267,16 @@ struct sh_mmcif_host { bool dma_active; }; +static const struct sh_mmcif_ver sh_mmcif_gen2 = { + .clkdiv_map = 0x3ff, + .pf_min = 12187500, + .pf_max = 97500000, +}; + static const struct of_device_id sh_mmcif_of_match[] = { { .compatible = "renesas,sh-mmcif" }, + { .compatible = "renesas,mmcif-r8a7790", .data = &sh_mmcif_gen2 }, + { .compatible = "renesas,mmcif-r8a7791", .data = &sh_mmcif_gen2 }, { } }; MODULE_DEVICE_TABLE(of, sh_mmcif_of_match); @@ -492,19 +511,56 @@ static void sh_mmcif_clock_control(struct sh_mmcif_host *host, unsigned int clk) struct sh_mmcif_plat_data *p = dev->platform_data; bool sup_pclk = p ? p->sup_pclk : false; unsigned int current_clk = clk_get_rate(host->clk); + unsigned int clkdiv; sh_mmcif_bitclr(host, MMCIF_CE_CLK_CTRL, CLK_ENABLE); sh_mmcif_bitclr(host, MMCIF_CE_CLK_CTRL, CLK_CLEAR); if (!clk) return; - if (sup_pclk && clk = current_clk) - sh_mmcif_bitset(host, MMCIF_CE_CLK_CTRL, CLK_SUP_PCLK); - else - sh_mmcif_bitset(host, MMCIF_CE_CLK_CTRL, CLK_CLEAR & - ((fls(DIV_ROUND_UP(current_clk, - clk) - 1) - 1) << 16)); + if (host->ver) { + const struct sh_mmcif_ver *ver = host->ver; + unsigned int freq, best_freq, myclk, div, diff_min, diff; + int i; + + clkdiv = 0; + diff_min = ~0; + best_freq = 0; + for (i = 31; i >= 0; i--) { + if (!((1 << i) & ver->clkdiv_map)) + continue; + + /* + * clk = parent_freq / div + * -> parent_freq = clk x div + */ + + div = 1 << (i + 1); + freq = clk_round_rate(host->clk, clk * div); + myclk = freq / div; + diff = (myclk > clk) ? myclk - clk : clk - myclk; + + if (diff <= diff_min) { + best_freq = freq; + clkdiv = i; + diff_min = diff; + } + } + + dev_dbg(dev, "clk %u/%u (%u, 0x%x)\n", + (best_freq / (1 << (clkdiv + 1))), clk, + best_freq, clkdiv); + + clk_set_rate(host->clk, best_freq); + clkdiv = clkdiv << 16; + } else if (sup_pclk && clk = current_clk) { + clkdiv = CLK_SUP_PCLK; + } else { + clkdiv = (fls(DIV_ROUND_UP(current_clk, clk) - 1) - 1) << 16; + } + + sh_mmcif_bitset(host, MMCIF_CE_CLK_CTRL, CLK_CLEAR & clkdiv); sh_mmcif_bitset(host, MMCIF_CE_CLK_CTRL, CLK_ENABLE); } @@ -1000,10 +1056,28 @@ static void sh_mmcif_request(struct mmc_host *mmc, struct mmc_request *mrq) static void sh_mmcif_clk_setup(struct sh_mmcif_host *host) { - unsigned int clk = clk_get_rate(host->clk); + struct device *dev = sh_mmcif_host_to_dev(host); + const struct of_device_id *of_id; + const struct sh_mmcif_ver *ver = NULL; + + of_id = of_match_device(sh_mmcif_of_match, dev); + if (of_id) + ver = of_id->data; + + if (ver) { + host->mmc->f_min = ver->pf_min / (1 << fls(ver->clkdiv_map)); + host->mmc->f_max = ver->pf_max / (1 << ffs(ver->clkdiv_map)); + + host->ver = ver; + } else { + unsigned int clk = clk_get_rate(host->clk); + + host->mmc->f_max = clk / 2; + host->mmc->f_min = clk / 512; + } - host->mmc->f_max = clk / 2; - host->mmc->f_min = clk / 512; + dev_dbg(dev, "clk max/min = %d/%d\n", + host->mmc->f_max, host->mmc->f_min); } static void sh_mmcif_set_power(struct sh_mmcif_host *host, struct mmc_ios *ios) -- 1.9.1
WARNING: multiple messages have this Message-ID (diff)
From: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com> To: Ulf Hansson <ulf.hansson@linaro.org> Cc: linux-mmc <linux-mmc@vger.kernel.org>, Simon <horms@verge.net.au>, Magnus <magnus.damm@gmail.com>, Linux-SH <linux-sh@vger.kernel.org>, Laurent <laurent.pinchart@ideasonboard.com>, Geert Uytterhoeven <geert@linux-m68k.org>, kobayashi <keita.kobayashi.ym@renesas.com> Subject: [PATCH 3/3 v5] mmc: sh_mmcif: calculate best clock with parent clock Date: Wed, 13 May 2015 02:18:22 +0000 [thread overview] Message-ID: <87617xfchj.wl%kuninori.morimoto.gx@renesas.com> (raw) In-Reply-To: <87a8x9fck7.wl%kuninori.morimoto.gx@renesas.com> From: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com> MMCIF IP on R-Car series has parent clock which can be set several rate, and it was not implemented on old SH-Mobile series (= SH-Mobile series parent clock was fixed rate) R-Car series MMCIF can use more high speed access if it setup parent clock. This patch adds parent clock setup method, and r8a7790/r8a7791 can use it. Signed-off-by: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com> Tested-by: Keita Kobayashi <keita.kobayashi.ym@renesas.com> --- v4 -> v5 - get clock data from compatible drivers/mmc/host/sh_mmcif.c | 92 ++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 83 insertions(+), 9 deletions(-) diff --git a/drivers/mmc/host/sh_mmcif.c b/drivers/mmc/host/sh_mmcif.c index e13c5f41..7ade263 100644 --- a/drivers/mmc/host/sh_mmcif.c +++ b/drivers/mmc/host/sh_mmcif.c @@ -57,6 +57,7 @@ #include <linux/mmc/slot-gpio.h> #include <linux/mod_devicetable.h> #include <linux/mutex.h> +#include <linux/of_device.h> #include <linux/pagemap.h> #include <linux/platform_device.h> #include <linux/pm_qos.h> @@ -224,6 +225,15 @@ enum sh_mmcif_wait_for { MMCIF_WAIT_FOR_STOP, }; +/* + * difference for each SoC + */ +struct sh_mmcif_ver { + u32 clkdiv_map; /* see CE_CLK_CTRL::CLKDIV */ + unsigned int pf_min; /* parent frequency min */ + unsigned int pf_max; /* parent frequency max */ +}; + struct sh_mmcif_host { struct mmc_host *mmc; struct mmc_request *mrq; @@ -248,6 +258,7 @@ struct sh_mmcif_host { bool ccs_enable; /* Command Completion Signal support */ bool clk_ctrl2_enable; struct mutex thread_lock; + const struct sh_mmcif_ver *ver; /* DMA support */ struct dma_chan *chan_rx; @@ -256,8 +267,16 @@ struct sh_mmcif_host { bool dma_active; }; +static const struct sh_mmcif_ver sh_mmcif_gen2 = { + .clkdiv_map = 0x3ff, + .pf_min = 12187500, + .pf_max = 97500000, +}; + static const struct of_device_id sh_mmcif_of_match[] = { { .compatible = "renesas,sh-mmcif" }, + { .compatible = "renesas,mmcif-r8a7790", .data = &sh_mmcif_gen2 }, + { .compatible = "renesas,mmcif-r8a7791", .data = &sh_mmcif_gen2 }, { } }; MODULE_DEVICE_TABLE(of, sh_mmcif_of_match); @@ -492,19 +511,56 @@ static void sh_mmcif_clock_control(struct sh_mmcif_host *host, unsigned int clk) struct sh_mmcif_plat_data *p = dev->platform_data; bool sup_pclk = p ? p->sup_pclk : false; unsigned int current_clk = clk_get_rate(host->clk); + unsigned int clkdiv; sh_mmcif_bitclr(host, MMCIF_CE_CLK_CTRL, CLK_ENABLE); sh_mmcif_bitclr(host, MMCIF_CE_CLK_CTRL, CLK_CLEAR); if (!clk) return; - if (sup_pclk && clk == current_clk) - sh_mmcif_bitset(host, MMCIF_CE_CLK_CTRL, CLK_SUP_PCLK); - else - sh_mmcif_bitset(host, MMCIF_CE_CLK_CTRL, CLK_CLEAR & - ((fls(DIV_ROUND_UP(current_clk, - clk) - 1) - 1) << 16)); + if (host->ver) { + const struct sh_mmcif_ver *ver = host->ver; + unsigned int freq, best_freq, myclk, div, diff_min, diff; + int i; + + clkdiv = 0; + diff_min = ~0; + best_freq = 0; + for (i = 31; i >= 0; i--) { + if (!((1 << i) & ver->clkdiv_map)) + continue; + + /* + * clk = parent_freq / div + * -> parent_freq = clk x div + */ + + div = 1 << (i + 1); + freq = clk_round_rate(host->clk, clk * div); + myclk = freq / div; + diff = (myclk > clk) ? myclk - clk : clk - myclk; + + if (diff <= diff_min) { + best_freq = freq; + clkdiv = i; + diff_min = diff; + } + } + + dev_dbg(dev, "clk %u/%u (%u, 0x%x)\n", + (best_freq / (1 << (clkdiv + 1))), clk, + best_freq, clkdiv); + + clk_set_rate(host->clk, best_freq); + clkdiv = clkdiv << 16; + } else if (sup_pclk && clk == current_clk) { + clkdiv = CLK_SUP_PCLK; + } else { + clkdiv = (fls(DIV_ROUND_UP(current_clk, clk) - 1) - 1) << 16; + } + + sh_mmcif_bitset(host, MMCIF_CE_CLK_CTRL, CLK_CLEAR & clkdiv); sh_mmcif_bitset(host, MMCIF_CE_CLK_CTRL, CLK_ENABLE); } @@ -1000,10 +1056,28 @@ static void sh_mmcif_request(struct mmc_host *mmc, struct mmc_request *mrq) static void sh_mmcif_clk_setup(struct sh_mmcif_host *host) { - unsigned int clk = clk_get_rate(host->clk); + struct device *dev = sh_mmcif_host_to_dev(host); + const struct of_device_id *of_id; + const struct sh_mmcif_ver *ver = NULL; + + of_id = of_match_device(sh_mmcif_of_match, dev); + if (of_id) + ver = of_id->data; + + if (ver) { + host->mmc->f_min = ver->pf_min / (1 << fls(ver->clkdiv_map)); + host->mmc->f_max = ver->pf_max / (1 << ffs(ver->clkdiv_map)); + + host->ver = ver; + } else { + unsigned int clk = clk_get_rate(host->clk); + + host->mmc->f_max = clk / 2; + host->mmc->f_min = clk / 512; + } - host->mmc->f_max = clk / 2; - host->mmc->f_min = clk / 512; + dev_dbg(dev, "clk max/min = %d/%d\n", + host->mmc->f_max, host->mmc->f_min); } static void sh_mmcif_set_power(struct sh_mmcif_host *host, struct mmc_ios *ios) -- 1.9.1
next prev parent reply other threads:[~2015-05-13 2:18 UTC|newest] Thread overview: 95+ messages / expand[flat|nested] mbox.gz Atom feed top [not found] <873840a4ch.wl%kuninori.morimoto.gx@renesas.com> 2015-04-21 3:49 ` mmc: sh_mmcif: add PLL support Kuninori Morimoto 2015-04-21 3:50 ` [PATCH 1/3] mmc: sh_mmcif: move mmcif_of_match to upside Kuninori Morimoto 2015-04-21 3:50 ` [PATCH 2/3] mmc: sh_mmcif: cleanup to use dev instead of &pdev->dev Kuninori Morimoto 2015-04-21 3:51 ` [PATCH 3/3] mmc: sh_mmcif: calculate best clock with PLL Kuninori Morimoto 2015-04-21 7:43 ` Kuninori Morimoto 2015-04-21 7:51 ` Laurent Pinchart 2015-04-21 7:58 ` Kuninori Morimoto 2015-04-21 7:53 ` [PATCH 0/3 v2] mmc: sh_mmcif: add PLL support Kuninori Morimoto 2015-04-21 7:54 ` [PATCH 1/3 v2] mmc: sh_mmcif: move mmcif_of_match to upside Kuninori Morimoto 2015-04-21 7:54 ` [PATCH 2/3 v2] mmc: sh_mmcif: cleanup to use dev instead of &pdev->dev Kuninori Morimoto 2015-04-21 7:55 ` [PATCH 3/3 v2] mmc: sh_mmcif: calculate best clock with parent clock Kuninori Morimoto 2015-04-21 8:23 ` [PATCH 0/3 v2] mmc: sh_mmcif: add PLL support Kuninori Morimoto 2015-04-21 8:26 ` [PATCH 0/3 v3] " Kuninori Morimoto 2015-04-21 8:26 ` [PATCH 1/3 v3] mmc: sh_mmcif: move mmcif_of_match to upside Kuninori Morimoto 2015-04-21 10:07 ` Geert Uytterhoeven 2015-04-21 10:07 ` Geert Uytterhoeven 2015-04-21 8:27 ` [PATCH 2/3 v3] mmc: sh_mmcif: cleanup to use dev instead of &pdev->dev Kuninori Morimoto 2015-04-21 10:07 ` Geert Uytterhoeven 2015-04-21 10:07 ` Geert Uytterhoeven 2015-04-21 8:31 ` [PATCH 3/3 v3] mmc: sh_mmcif: calculate best clock with parent clock Kuninori Morimoto 2015-04-21 8:31 ` Kuninori Morimoto 2015-04-21 10:31 ` Geert Uytterhoeven 2015-04-21 10:31 ` Geert Uytterhoeven 2015-04-21 13:07 ` Laurent Pinchart 2015-04-21 13:07 ` Laurent Pinchart 2015-04-22 1:05 ` Kuninori Morimoto 2015-05-04 1:04 ` Laurent Pinchart 2015-05-04 1:04 ` Laurent Pinchart 2015-05-11 2:15 ` Kuninori Morimoto 2015-05-11 2:15 ` Kuninori Morimoto 2015-04-22 1:04 ` Kuninori Morimoto 2015-04-22 7:49 ` Geert Uytterhoeven 2015-04-22 7:49 ` Geert Uytterhoeven 2015-04-22 8:18 ` Ulf Hansson 2015-04-22 8:18 ` Ulf Hansson 2015-04-22 8:22 ` Geert Uytterhoeven 2015-04-22 8:22 ` Geert Uytterhoeven 2015-04-22 9:16 ` Kuninori Morimoto 2015-04-23 8:11 ` [PATCH 0/7 v4] mmc: sh_mmcif: add parent clk support Kuninori Morimoto 2015-04-23 8:13 ` [PATCH 1/7 v4] mmc: sh_mmcif: move mmcif_of_match to upside Kuninori Morimoto 2015-04-23 8:14 ` [PATCH 2/7 v4] mmc: sh_mmcif: cleanup to use dev instead of &pdev->dev Kuninori Morimoto 2015-04-23 8:15 ` [PATCH 3/7 v4] mmc: sh_mmcif: remove unnecessary int clk from struct sh_mmcif_host Kuninori Morimoto 2015-04-23 8:15 ` Kuninori Morimoto 2015-04-23 10:01 ` Geert Uytterhoeven 2015-04-23 10:01 ` Geert Uytterhoeven 2015-04-23 8:16 ` [PATCH 4/7 v4] mmc: sh_mmcif: separate sh_mmcif_clk_update() into setup and prepare Kuninori Morimoto 2015-04-23 10:00 ` Geert Uytterhoeven 2015-04-23 10:00 ` Geert Uytterhoeven 2015-04-23 8:17 ` [PATCH 5/7 v4] mmc: sh_mmcif: calculate best clock with parent clock Kuninori Morimoto 2015-04-23 8:17 ` Kuninori Morimoto 2015-05-12 10:22 ` Laurent Pinchart 2015-05-12 10:22 ` Laurent Pinchart 2015-05-13 0:08 ` Kuninori Morimoto 2015-04-23 8:18 ` [PATCH 6/7 v4] ARM: shmobile: r8a7790: add MMCIF parent clock range Kuninori Morimoto 2015-05-07 5:26 ` Simon Horman 2015-05-07 5:26 ` Simon Horman 2015-05-11 2:53 ` Kuninori Morimoto 2015-05-11 5:39 ` Simon Horman 2015-05-11 5:39 ` Simon Horman 2015-04-23 8:18 ` [PATCH 7/7 v4] ARM: shmobile: r8a7791: " Kuninori Morimoto 2015-04-23 10:07 ` [PATCH 0/7 v4] mmc: sh_mmcif: add parent clk support Laurent Pinchart 2015-04-23 10:07 ` Laurent Pinchart 2015-05-05 8:33 ` Ulf Hansson 2015-05-05 8:33 ` Ulf Hansson 2015-05-13 2:16 ` [PATCH 0/3 v5] " Kuninori Morimoto 2015-05-13 2:17 ` [PATCH 1/3 v5] mmc: sh_mmcif: add sh_mmcif_host_to_dev() macro and use it Kuninori Morimoto 2015-05-13 2:17 ` Kuninori Morimoto 2015-05-13 2:18 ` [PATCH 2/3 v5] mmc: sh_mmcif: use sh_mmcif_xxx prefix for all functions Kuninori Morimoto 2015-05-13 2:18 ` Kuninori Morimoto [this message] 2015-05-13 2:18 ` [PATCH 3/3 v5] mmc: sh_mmcif: calculate best clock with parent clock Kuninori Morimoto 2015-05-13 7:55 ` Geert Uytterhoeven 2015-05-13 7:55 ` Geert Uytterhoeven 2015-05-13 8:37 ` Kuninori Morimoto 2015-05-13 8:43 ` Geert Uytterhoeven 2015-05-13 8:43 ` Geert Uytterhoeven 2015-05-13 9:27 ` Kuninori Morimoto 2015-05-14 7:20 ` [PATCH 0/3 v6] mmc: sh_mmcif: add parent clk support Kuninori Morimoto 2015-05-14 7:21 ` [PATCH 1/5 v6] mmc: sh_mmcif: add sh_mmcif_host_to_dev() macro and use it Kuninori Morimoto 2015-05-14 7:21 ` Kuninori Morimoto 2015-05-14 7:21 ` [PATCH 2/5 v6] mmc: sh_mmcif: use sh_mmcif_xxx prefix for all functions Kuninori Morimoto 2015-05-14 7:22 ` [PATCH 3/5 v6] mmc: sh_mmcif: calculate best clock with parent clock Kuninori Morimoto 2015-05-14 7:22 ` Kuninori Morimoto 2015-05-14 7:23 ` [PATCH 4/5 v6] ARM: shmobile: r8a7790: add MMCIF max-frequency Kuninori Morimoto 2015-05-14 7:23 ` [PATCH 5/5 v6] ARM: shmobile: r8a7791: " Kuninori Morimoto 2015-05-22 14:01 ` [PATCH 0/3 v6] mmc: sh_mmcif: add parent clk support Ulf Hansson 2015-05-22 14:01 ` Ulf Hansson 2015-05-25 0:24 ` Kuninori Morimoto 2015-05-25 0:50 ` Simon Horman 2015-05-25 0:50 ` Simon Horman 2015-05-25 0:26 ` Simon Horman 2015-05-25 0:26 ` Simon Horman 2015-05-25 0:38 ` Kuninori Morimoto 2015-05-25 8:44 ` Ulf Hansson 2015-05-25 8:44 ` Ulf Hansson 2015-05-25 9:38 ` Kuninori Morimoto
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=87617xfchj.wl%kuninori.morimoto.gx@renesas.com \ --to=kuninori.morimoto.gx@renesas.com \ --cc=geert@linux-m68k.org \ --cc=horms@verge.net.au \ --cc=keita.kobayashi.ym@renesas.com \ --cc=laurent.pinchart@ideasonboard.com \ --cc=linux-mmc@vger.kernel.org \ --cc=linux-sh@vger.kernel.org \ --cc=magnus.damm@gmail.com \ --cc=ulf.hansson@linaro.org \ /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: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
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.