summaryrefslogtreecommitdiff
path: root/cpu/at32ap/at32ap700x/clk.c
diff options
context:
space:
mode:
authorHaavard Skinnemoen <haavard.skinnemoen@atmel.com>2009-03-23 10:22:41 +0100
committerHaavard Skinnemoen <haavard.skinnemoen@atmel.com>2009-03-23 10:22:41 +0100
commit8206bfae3ab7f99965136384360ba2de0c6f4c3b (patch)
treee11bf0fad2e418e6771e8db7dbcb6630a6053f0c /cpu/at32ap/at32ap700x/clk.c
parentee1702d75a30d076139d1841383a1fa7220a0e11 (diff)
parent58a518c3d8a2c7de11d414e8b903495daee7dc7e (diff)
downloadu-boot-imx-8206bfae3ab7f99965136384360ba2de0c6f4c3b.zip
u-boot-imx-8206bfae3ab7f99965136384360ba2de0c6f4c3b.tar.gz
u-boot-imx-8206bfae3ab7f99965136384360ba2de0c6f4c3b.tar.bz2
Merge branch 'mimc200'
Diffstat (limited to 'cpu/at32ap/at32ap700x/clk.c')
-rw-r--r--cpu/at32ap/at32ap700x/clk.c25
1 files changed, 25 insertions, 0 deletions
diff --git a/cpu/at32ap/at32ap700x/clk.c b/cpu/at32ap/at32ap700x/clk.c
index 2b1cd36..2c2e19c 100644
--- a/cpu/at32ap/at32ap700x/clk.c
+++ b/cpu/at32ap/at32ap700x/clk.c
@@ -25,6 +25,7 @@
#include <asm/arch/clk.h>
#include <asm/arch/memory-map.h>
+#include <asm/arch/portmux.h>
#include "sm.h"
@@ -66,3 +67,27 @@ void clk_init(void)
sm_writel(PM_MCCTRL, SM_BIT(PLLSEL));
#endif
}
+
+unsigned long __gclk_set_rate(unsigned int id, enum gclk_parent parent,
+ unsigned long rate, unsigned long parent_rate)
+{
+ unsigned long divider;
+
+ if (rate == 0 || parent_rate == 0) {
+ sm_writel(PM_GCCTRL(id), 0);
+ return 0;
+ }
+
+ divider = (parent_rate + rate / 2) / rate;
+ if (divider <= 1) {
+ sm_writel(PM_GCCTRL(id), parent | SM_BIT(CEN));
+ rate = parent_rate;
+ } else {
+ divider = min(255, divider / 2 - 1);
+ sm_writel(PM_GCCTRL(id), parent | SM_BIT(CEN) | SM_BIT(DIVEN)
+ | SM_BF(DIV, divider));
+ rate = parent_rate / (2 * (divider + 1));
+ }
+
+ return rate;
+}