devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Hans de Goede <hdegoede@redhat.com>
To: Ulf Hansson <ulf.hansson@linaro.org>,
	Maxime Ripard <maxime.ripard@free-electrons.com>,
	Chen-Yu Tsai <wens@csie.org>
Cc: devicetree <devicetree@vger.kernel.org>,
	linux-mmc@vger.kernel.org, Icenowy Zheng <icenowy@aosc.xyz>,
	linux-arm-kernel@lists.infradead.org,
	Hans de Goede <hdegoede@redhat.com>
Subject: [PATCH v2 3/5] mmc: sunxi: Factor out clock phase setting code into a helper function
Date: Sat, 30 Jul 2016 16:25:46 +0200	[thread overview]
Message-ID: <1469888748-26085-4-git-send-email-hdegoede@redhat.com> (raw)
In-Reply-To: <1469888748-26085-1-git-send-email-hdegoede@redhat.com>

Add a sunxi_mmc_clk_set_phase() helper function.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
---
Changes in v2:
-New patch in v2 of this patch-set
---
 drivers/mmc/host/sunxi-mmc.c | 61 ++++++++++++++++++++++++--------------------
 1 file changed, 33 insertions(+), 28 deletions(-)

diff --git a/drivers/mmc/host/sunxi-mmc.c b/drivers/mmc/host/sunxi-mmc.c
index 9f44c83..b631b5c 100644
--- a/drivers/mmc/host/sunxi-mmc.c
+++ b/drivers/mmc/host/sunxi-mmc.c
@@ -657,12 +657,39 @@ static int sunxi_mmc_oclk_onoff(struct sunxi_mmc_host *host, u32 oclk_en)
 	return 0;
 }
 
+static int sunxi_mmc_clk_set_phase(struct sunxi_mmc_host *host,
+				   struct mmc_ios *ios, u32 rate)
+{
+	int index;
+
+	/* determine delays */
+	if (rate <= 400000) {
+		index = SDXC_CLK_400K;
+	} else if (rate <= 25000000) {
+		index = SDXC_CLK_25M;
+	} else if (rate <= 52000000) {
+		if (ios->timing != MMC_TIMING_UHS_DDR50 &&
+		    ios->timing != MMC_TIMING_MMC_DDR52) {
+			index = SDXC_CLK_50M;
+		} else if (ios->bus_width == MMC_BUS_WIDTH_8) {
+			index = SDXC_CLK_50M_DDR_8BIT;
+		} else {
+			index = SDXC_CLK_50M_DDR;
+		}
+	} else {
+		return -EINVAL;
+	}
+
+	clk_set_phase(host->clk_sample, host->cfg->clk_delays[index].sample);
+	clk_set_phase(host->clk_output, host->cfg->clk_delays[index].output);
+
+	return 0;
+}
+
 static int sunxi_mmc_clk_set_rate(struct sunxi_mmc_host *host,
 				  struct mmc_ios *ios)
 {
-	const struct sunxi_mmc_clk_delay *clk_delays = host->cfg->clk_delays;
-	u32 rate, oclk_dly, rval, sclk_dly;
-	u32 clock = ios->clock;
+	u32 rate, rval, clock = ios->clock;
 	int ret;
 
 	/* 8 bit DDR requires a higher module clock */
@@ -697,31 +724,9 @@ static int sunxi_mmc_clk_set_rate(struct sunxi_mmc_host *host,
 	}
 	mmc_writel(host, REG_CLKCR, rval);
 
-	/* determine delays */
-	if (rate <= 400000) {
-		oclk_dly = clk_delays[SDXC_CLK_400K].output;
-		sclk_dly = clk_delays[SDXC_CLK_400K].sample;
-	} else if (rate <= 25000000) {
-		oclk_dly = clk_delays[SDXC_CLK_25M].output;
-		sclk_dly = clk_delays[SDXC_CLK_25M].sample;
-	} else if (rate <= 52000000) {
-		if (ios->timing != MMC_TIMING_UHS_DDR50 &&
-		    ios->timing != MMC_TIMING_MMC_DDR52) {
-			oclk_dly = clk_delays[SDXC_CLK_50M].output;
-			sclk_dly = clk_delays[SDXC_CLK_50M].sample;
-		} else if (ios->bus_width == MMC_BUS_WIDTH_8) {
-			oclk_dly = clk_delays[SDXC_CLK_50M_DDR_8BIT].output;
-			sclk_dly = clk_delays[SDXC_CLK_50M_DDR_8BIT].sample;
-		} else {
-			oclk_dly = clk_delays[SDXC_CLK_50M_DDR].output;
-			sclk_dly = clk_delays[SDXC_CLK_50M_DDR].sample;
-		}
-	} else {
-		return -EINVAL;
-	}
-
-	clk_set_phase(host->clk_sample, sclk_dly);
-	clk_set_phase(host->clk_output, oclk_dly);
+	ret = sunxi_mmc_clk_set_phase(host, ios, rate);
+	if (ret)
+		return ret;
 
 	return sunxi_mmc_oclk_onoff(host, 1);
 }
-- 
2.7.4

  parent reply	other threads:[~2016-07-30 14:25 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-07-30 14:25 [PATCH v2 0/5] mmc: sunxi: sun4i / sun5i do not have sample clocks Hans de Goede
2016-07-30 14:25 ` [PATCH v2 1/5] mmc: sunxi: Disable sample clks on remove Hans de Goede
2016-07-30 15:13   ` Maxime Ripard
2016-07-30 14:25 ` [PATCH v2 2/5] mmc: sunxi: Introduce a sunxi_mmc_cfg struct Hans de Goede
2016-07-30 15:14   ` Maxime Ripard
2016-07-30 14:25 ` Hans de Goede [this message]
2016-07-30 15:14   ` [PATCH v2 3/5] mmc: sunxi: Factor out clock phase setting code into a helper function Maxime Ripard
2016-07-30 15:18   ` Icenowy Zheng
2016-07-30 14:25 ` [PATCH v2 4/5] mmc: sunxi: sun4i / sun5i do not have sample clocks Hans de Goede
2016-07-30 15:15   ` Maxime Ripard
2016-08-01 16:39   ` Rob Herring
2016-07-30 14:25 ` [PATCH v2 5/5] ARM: dts: sunxi: Use new sun7i-a20-mmc compatible on sun7i and newer Hans de Goede
2016-07-30 15:16   ` Maxime Ripard
2016-07-31 14:17     ` Hans de Goede
2016-08-01 13:11   ` Andre Przywara
2016-08-02 13:58     ` Hans de Goede
2016-08-22  7:54     ` Maxime Ripard
2016-08-22  9:02       ` Andre Przywara
2016-08-22 13:38 ` [PATCH v2 0/5] mmc: sunxi: sun4i / sun5i do not have sample clocks Ulf Hansson

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=1469888748-26085-4-git-send-email-hdegoede@redhat.com \
    --to=hdegoede@redhat.com \
    --cc=devicetree@vger.kernel.org \
    --cc=icenowy@aosc.xyz \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-mmc@vger.kernel.org \
    --cc=maxime.ripard@free-electrons.com \
    --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;
as well as URLs for NNTP newsgroup(s).