Skip to contentSkip to conversation

EXYNOS: clock: add the get_mmc_clk function

PATCH New Jaehoon Chung 2 participants 2 messages Jul 3, 2012 – Aug 30, 2012

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 2/4 EXYNOS: clock: add the get_mmc_clk function

To get more exactly sclk value, used the get_mmc_clk.

---
 arch/arm/cpu/armv7/exynos/clock.c      |   78 ++++++++++++++++++++++++++++++++
 arch/arm/include/asm/arch-exynos/clk.h |    1 +
 2 files changed, 79 insertions(+), 0 deletions(-)
arch/arm/cpu/armv7/exynos/clock.c +78 -0
index 2f7048b..90fa45c 100644
@@ -360,6 +360,44 @@ static unsigned long exynos5_get_uart_clk(int dev_index)
 	return uclk;
 }
 
+/* exynos4: return mmc clock frequency */
+static unsigned long exynos4_get_mmc_clk(int dev_index)
+{
+	struct exynos4_clock *clk =
+		(struct exynos4_clock *)samsung_get_base_clock();
+	unsigned long uclk, sclk;
+	unsigned int sel;
+	unsigned int ratio;
+	unsigned int pre_ratio;
+
+	sel = readl(&clk->src_fsys);
+	sel = (sel >> (dev_index << 2)) & 0xf;
+
+	if (sel == 0x6)
+		sclk = get_pll_clk(MPLL);
+	else if (sel == 0x7)
+		sclk = get_pll_clk(EPLL);
+	else if (sel == 0x8)
+		sclk = get_pll_clk(VPLL);
+	else
+		return 0;
+
+	if (dev_index == 0) {
+		ratio = readl(&clk->div_fsys0);
+		pre_ratio = readl(&clk->div_fsys0);
+	} else if (dev_index == 4) {
+		ratio = readl(&clk->div_fsys3);
+		pre_ratio = readl(&clk->div_fsys3);
+	} else
+		return 0;
+
+	ratio = ratio & 0xf;
+	pre_ratio = (pre_ratio >> (dev_index + 8)) & 0xff;
+	uclk = (sclk /(ratio + 1))/(pre_ratio + 1);
+
+	return uclk;
+}
+
 /* exynos4: set the mmc clock */
 static void exynos4_set_mmc_clk(int dev_index, unsigned int div)
 {
@@ -387,6 +425,38 @@ static void exynos4_set_mmc_clk(int dev_index, unsigned int div)
 	writel(val, addr);
 }
 
+/* exynos5: return mmc clock frequency */
+static unsigned long exynos5_get_mmc_clk(int dev_index)
+{
+	struct exynos5_clock *clk =
+		(struct exynos5_clock *)samsung_get_base_clock();
+	unsigned long uclk, sclk;
+	unsigned int sel;
+	unsigned int ratio;
+	unsigned int pre_ratio;
+
+	sel = readl(&clk->src_fsys);
+	sel = (sel >> (dev_index << 2)) & 0xf;
+
+	if (sel == 0x6)
+		sclk = get_pll_clk(MPLL);
+	else if (sel == 0x7)
+		sclk = get_pll_clk(EPLL);
+	else if (sel == 0x8)
+		sclk = get_pll_clk(VPLL);
+	else
+		return 0;
+
+	ratio = readl(&clk->div_fsys1);
+	ratio = (ratio >> (dev_index << 2)) & 0xf;
+	pre_ratio = readl(&clk->div_fsys1);
+	pre_ratio = (pre_ratio >> ((dev_index<< 4) + 8)) & 0xff;
+
+	uclk = (sclk /(ratio + 1))/(pre_ratio + 1);
+
+	return uclk;
+}
+
 /* exynos5: set the mmc clock */
 static void exynos5_set_mmc_clk(int dev_index, unsigned int div)
 {
@@ -446,6 +516,14 @@ unsigned long get_uart_clk(int dev_index)
 		return exynos4_get_uart_clk(dev_index);
 }
 
+unsigned long get_mmc_clk(int dev_index)
+{
+	if (cpu_is_exynos5())
+		return exynos5_get_mmc_clk(dev_index);
+	else
+		return exynos4_get_mmc_clk(dev_index);
+}
+
 void set_mmc_clk(int dev_index, unsigned int div)
 {
 	if (cpu_is_exynos5())
arch/arm/include/asm/arch-exynos/clk.h +1 -0
index ff0f641..9e9d390 100644
@@ -31,6 +31,7 @@
 unsigned long get_pll_clk(int pllreg);
 unsigned long get_arm_clk(void);
 unsigned long get_pwm_clk(void);
+unsigned long get_mmc_clk(int dev_index);
 unsigned long get_uart_clk(int dev_index);
 void set_mmc_clk(int dev_index, unsigned int div);
 
#1 lore raw

PATCH 2/4 EXYNOS: clock: add the get_mmc_clk function

Quoted 11 lines · Jaehoon Chung

To get more exactly sclk value, used the get_mmc_clk.

---
 arch/arm/cpu/armv7/exynos/clock.c      |   78 ++++++++++++++++++++++++++++++++
 arch/arm/include/asm/arch-exynos/clk.h |    1 +
arch/arm/cpu/armv7/exynos/clock.c +2 -0
+/* exynos4: return mmc clock frequency */
+static unsigned long exynos4_get_mmc_clk(int dev_index)

arch/arm/cpu/armv7/exynos/clock.c static unsigned long exynos5_get_uart_clk(int dev_index) · line 374

Quoted 10 lines
arch/arm/cpu/armv7/exynos/clock.c +10 -0
+{
+       struct exynos4_clock *clk =
+               (struct exynos4_clock *)samsung_get_base_clock();
+       unsigned long uclk, sclk;
+       unsigned int sel;
+       unsigned int ratio;
+       unsigned int pre_ratio;
+
+       sel = readl(&clk->src_fsys);
+       sel = (sel >> (dev_index << 2)) & 0xf;

I think it would be more clear, here, if you did:

sel = (sel >> (4 * dev_index)) & 0xf;

It makes it obvious that you're shifting a value by 4 bits per device.

arch/arm/cpu/armv7/exynos/clock.c static void exynos4_set_mmc_clk(int dev_index, unsigned int div) · line 439

Quoted 12 lines
arch/arm/cpu/armv7/exynos/clock.c +12 -0
+/* exynos5: return mmc clock frequency */
+static unsigned long exynos5_get_mmc_clk(int dev_index)
+{
+       struct exynos5_clock *clk =
+               (struct exynos5_clock *)samsung_get_base_clock();
+       unsigned long uclk, sclk;
+       unsigned int sel;
+       unsigned int ratio;
+       unsigned int pre_ratio;
+
+       sel = readl(&clk->src_fsys);
+       sel = (sel >> (dev_index << 2)) & 0xf;

Same comment here about dev_index * 4

arch/arm/cpu/armv7/exynos/clock.c static void exynos4_set_mmc_clk(int dev_index, unsigned int div) · line 451

Quoted 12 lines
arch/arm/cpu/armv7/exynos/clock.c +12 -0
+
+       if (sel == 0x6)
+               sclk = get_pll_clk(MPLL);
+       else if (sel == 0x7)
+               sclk = get_pll_clk(EPLL);
+       else if (sel == 0x8)
+               sclk = get_pll_clk(VPLL);
+       else
+               return 0;
+
+       ratio = readl(&clk->div_fsys1);
+       ratio = (ratio >> (dev_index << 2)) & 0xf;

And here.

arch/arm/cpu/armv7/exynos/clock.c unsigned long get_uart_clk(int dev_index) · line 525

Quoted 7 lines
arch/arm/cpu/armv7/exynos/clock.c +7 -0
+unsigned long get_mmc_clk(int dev_index)
+{
+       if (cpu_is_exynos5())
+               return exynos5_get_mmc_clk(dev_index);
+       else
+               return exynos4_get_mmc_clk(dev_index);
+}

This is a very generic name, and could interfere with the generic layer if it ever has a similarly-named function.

Quoted 2 lines

+
void set_mmc_clk(int dev_index, unsigned int div)

This isn't part of your patch, but this is *also* too generic of a name.

Andy