2 * Ralink RT305X clock API
4 * Copyright (C) 2011 Gabor Juhos <juhosg@openwrt.org>
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License version 2 as published
8 * by the Free Software Foundation.
11 #include <linux/kernel.h>
12 #include <linux/module.h>
13 #include <linux/init.h>
14 #include <linux/err.h>
15 #include <linux/clk.h>
17 #include <asm/mach-ralink/common.h>
18 #include <asm/mach-ralink/rt305x.h>
19 #include <asm/mach-ralink/rt305x_regs.h>
26 static struct clk rt305x_cpu_clk;
27 static struct clk rt305x_sys_clk;
28 static struct clk rt305x_wdt_clk;
29 static struct clk rt305x_uart_clk;
31 void __init rt305x_clocks_init(void)
35 t = rt305x_sysc_rr(SYSC_REG_SYSTEM_CONFIG);
37 if (soc_is_rt305x() || soc_is_rt3350()) {
38 t = (t >> RT305X_SYSCFG_CPUCLK_SHIFT) &
39 RT305X_SYSCFG_CPUCLK_MASK;
41 case RT305X_SYSCFG_CPUCLK_LOW:
42 rt305x_cpu_clk.rate = 320000000;
44 case RT305X_SYSCFG_CPUCLK_HIGH:
45 rt305x_cpu_clk.rate = 384000000;
48 rt305x_sys_clk.rate = rt305x_cpu_clk.rate / 3;
49 rt305x_uart_clk.rate = rt305x_sys_clk.rate;
50 rt305x_wdt_clk.rate = rt305x_sys_clk.rate;
51 } else if (soc_is_rt3352()) {
52 t = (t >> RT3352_SYSCFG0_CPUCLK_SHIFT) &
53 RT3352_SYSCFG0_CPUCLK_MASK;
55 case RT3352_SYSCFG0_CPUCLK_LOW:
56 rt305x_cpu_clk.rate = 384000000;
58 case RT3352_SYSCFG0_CPUCLK_HIGH:
59 rt305x_cpu_clk.rate = 400000000;
62 rt305x_sys_clk.rate = rt305x_cpu_clk.rate / 3;
63 rt305x_uart_clk.rate = 40000000;
64 rt305x_wdt_clk.rate = rt305x_sys_clk.rate;
74 struct clk *clk_get(struct device *dev, const char *id)
76 if (!strcmp(id, "sys"))
77 return &rt305x_sys_clk;
79 if (!strcmp(id, "cpu"))
80 return &rt305x_cpu_clk;
82 if (!strcmp(id, "wdt"))
83 return &rt305x_wdt_clk;
85 if (!strcmp(id, "uart"))
86 return &rt305x_uart_clk;
88 return ERR_PTR(-ENOENT);
90 EXPORT_SYMBOL(clk_get);
92 int clk_enable(struct clk *clk)
96 EXPORT_SYMBOL(clk_enable);
98 void clk_disable(struct clk *clk)
101 EXPORT_SYMBOL(clk_disable);
103 unsigned long clk_get_rate(struct clk *clk)
107 EXPORT_SYMBOL(clk_get_rate);
109 void clk_put(struct clk *clk)
112 EXPORT_SYMBOL(clk_put);