The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: Michael Wu <michael@allwinnertech.com>
To: ulf.hansson@linaro.org, mripard@kernel.org, wens@csie.org,
	samuel@sholland.org, andre.przywara@arm.com
Cc: jernej.skrabec@gmail.com, linux-mmc@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org,
	linux-sunxi@lists.linux.dev, linux-kernel@vger.kernel.org,
	Michael Wu <michael@allwinnertech.com>
Subject: [PATCH 3/3] mmc: sunxi-mmc: use pll to increase clock speed
Date: Wed, 22 Dec 2021 11:15:57 +0800	[thread overview]
Message-ID: <20211222031557.34242-1-michael@allwinnertech.com> (raw)

Default clock soucre is 24M,if we want clock over 24M
We should use pll as clock source

Signed-off-by: Michael Wu <michael@allwinnertech.com>
---
 drivers/mmc/host/sunxi-mmc.c | 57 +++++++++++++++++++++++++++++++++++-
 1 file changed, 56 insertions(+), 1 deletion(-)

diff --git a/drivers/mmc/host/sunxi-mmc.c b/drivers/mmc/host/sunxi-mmc.c
index 7b47ec453fb6..0039ee58b303 100644
--- a/drivers/mmc/host/sunxi-mmc.c
+++ b/drivers/mmc/host/sunxi-mmc.c
@@ -756,6 +756,57 @@ static int sunxi_mmc_clk_set_phase(struct sunxi_mmc_host *host,
 	return 0;
 }
 
+/**
+ *
+ * sunxi_clk_get_parent() - get parent pll from dts
+ * @host:		sunxi_mmc_host struct point
+ * @@clock:		the clock frequency that requested
+ *
+ * Default clock source is 24M,if we want clock over 24M,We should use
+ * pll as clock soure
+ *
+ * Return:the 0:ok,other:failed
+ */
+static int sunxi_clk_get_parent(struct sunxi_mmc_host *host, u32 clock)
+{
+	struct clk *sclk = NULL;
+	char *sclk_name = NULL;
+	u32 src_clk = 0;
+	s32 err = 0;
+	struct device *dev = mmc_dev(host->mmc);
+
+	sclk = clk_get(dev, "osc24m");
+	sclk_name = "osc24m";
+
+	if (IS_ERR(sclk)) {
+		dev_err(mmc_dev(host->mmc), "Error to get source clock %s\n",
+				sclk_name);
+		return PTR_ERR(sclk);
+	}
+
+	src_clk = clk_get_rate(sclk);
+	if (clock > src_clk) {
+		clk_put(sclk);
+		sclk = clk_get(dev, "pll_periph");
+		sclk_name = "pll_periph";
+	}
+	if (IS_ERR(sclk)) {
+		dev_err(mmc_dev(host->mmc), "Error to get source clock %s\n",
+				sclk_name);
+		return PTR_ERR(sclk);
+	}
+
+	err = clk_set_parent(host->clk_mmc, sclk);
+	if (err) {
+		dev_err(mmc_dev(host->mmc), "set parent failed\n");
+		clk_put(sclk);
+		return err;
+	}
+	clk_put(sclk);
+	return 0;
+}
+
+
 static int sunxi_mmc_clk_set_rate(struct sunxi_mmc_host *host,
 				  struct mmc_ios *ios)
 {
@@ -801,7 +852,11 @@ static int sunxi_mmc_clk_set_rate(struct sunxi_mmc_host *host,
 			return ret;
 		}
 	}
-
+	/**
+	 * No check return value,because dts may not have osc24M, and pll_periph,
+	 * at that time,use default value from clk system
+	 */
+	sunxi_clk_get_parent(host, clock);
 	rate = clk_round_rate(host->clk_mmc, clock);
 	if (rate < 0) {
 		dev_err(mmc_dev(mmc), "error rounding clk to %d: %ld\n",
-- 
2.29.0


             reply	other threads:[~2021-12-22  3:16 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-12-22  3:15 Michael Wu [this message]
2021-12-22 10:49 ` [PATCH 3/3] mmc: sunxi-mmc: use pll to increase clock speed Andre Przywara

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=20211222031557.34242-1-michael@allwinnertech.com \
    --to=michael@allwinnertech.com \
    --cc=andre.przywara@arm.com \
    --cc=jernej.skrabec@gmail.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mmc@vger.kernel.org \
    --cc=linux-sunxi@lists.linux.dev \
    --cc=mripard@kernel.org \
    --cc=samuel@sholland.org \
    --cc=ulf.hansson@linaro.org \
    --cc=wens@csie.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: 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