diff options
author | Dinh Nguyen <dinguyen@altera.com> | 2013-04-11 11:55:26 -0400 |
---|---|---|
committer | Olof Johansson <olof@lixom.net> | 2013-04-14 23:18:13 -0400 |
commit | 56c5c13f7080f9299a92b3fb6a1bf22689d607cc (patch) | |
tree | 2d2c1570166abefb89e0c6a85810308790e4e4a8 | |
parent | 042000b00344dbf25db2919c97cbd09be99ecf93 (diff) |
ARM: socfpga: Upgrade clk driver for socfpga to make use of dts clock entries
With this patch, the socfpga clk driver is able to query the clock and clock
rates appropriately.
Signed-off-by: Dinh Nguyen <dinguyen@altera.com>
Reviewed-by: Pavel Machek <pavel@denx.de>
Signed-off-by: Olof Johansson <olof@lixom.net>
-rw-r--r-- | arch/arm/mach-socfpga/socfpga.c | 6 | ||||
-rw-r--r-- | drivers/clk/socfpga/clk.c | 163 |
2 files changed, 148 insertions, 21 deletions
diff --git a/arch/arm/mach-socfpga/socfpga.c b/arch/arm/mach-socfpga/socfpga.c index 2cae16c1f265..46a051359f02 100644 --- a/arch/arm/mach-socfpga/socfpga.c +++ b/arch/arm/mach-socfpga/socfpga.c | |||
@@ -15,6 +15,7 @@ | |||
15 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | 15 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
16 | */ | 16 | */ |
17 | #include <linux/dw_apb_timer.h> | 17 | #include <linux/dw_apb_timer.h> |
18 | #include <linux/clk-provider.h> | ||
18 | #include <linux/irqchip.h> | 19 | #include <linux/irqchip.h> |
19 | #include <linux/of_address.h> | 20 | #include <linux/of_address.h> |
20 | #include <linux/of_irq.h> | 21 | #include <linux/of_irq.h> |
@@ -29,6 +30,7 @@ | |||
29 | void __iomem *socfpga_scu_base_addr = ((void __iomem *)(SOCFPGA_SCU_VIRT_BASE)); | 30 | void __iomem *socfpga_scu_base_addr = ((void __iomem *)(SOCFPGA_SCU_VIRT_BASE)); |
30 | void __iomem *sys_manager_base_addr; | 31 | void __iomem *sys_manager_base_addr; |
31 | void __iomem *rst_manager_base_addr; | 32 | void __iomem *rst_manager_base_addr; |
33 | void __iomem *clk_mgr_base_addr; | ||
32 | unsigned long cpu1start_addr; | 34 | unsigned long cpu1start_addr; |
33 | 35 | ||
34 | static struct map_desc scu_io_desc __initdata = { | 36 | static struct map_desc scu_io_desc __initdata = { |
@@ -77,6 +79,9 @@ void __init socfpga_sysmgr_init(void) | |||
77 | 79 | ||
78 | np = of_find_compatible_node(NULL, NULL, "altr,rst-mgr"); | 80 | np = of_find_compatible_node(NULL, NULL, "altr,rst-mgr"); |
79 | rst_manager_base_addr = of_iomap(np, 0); | 81 | rst_manager_base_addr = of_iomap(np, 0); |
82 | |||
83 | np = of_find_compatible_node(NULL, NULL, "altr,clk-mgr"); | ||
84 | clk_mgr_base_addr = of_iomap(np, 0); | ||
80 | } | 85 | } |
81 | 86 | ||
82 | static void __init socfpga_init_irq(void) | 87 | static void __init socfpga_init_irq(void) |
@@ -102,6 +107,7 @@ static void __init socfpga_cyclone5_init(void) | |||
102 | { | 107 | { |
103 | l2x0_of_init(0, ~0UL); | 108 | l2x0_of_init(0, ~0UL); |
104 | of_platform_populate(NULL, of_default_bus_match_table, NULL, NULL); | 109 | of_platform_populate(NULL, of_default_bus_match_table, NULL, NULL); |
110 | of_clk_init(NULL); | ||
105 | socfpga_init_clocks(); | 111 | socfpga_init_clocks(); |
106 | } | 112 | } |
107 | 113 | ||
diff --git a/drivers/clk/socfpga/clk.c b/drivers/clk/socfpga/clk.c index 2c855a6394ff..bd11315cf5ab 100644 --- a/drivers/clk/socfpga/clk.c +++ b/drivers/clk/socfpga/clk.c | |||
@@ -1,5 +1,6 @@ | |||
1 | /* | 1 | /* |
2 | * Copyright (C) 2012 Altera Corporation <www.altera.com> | 2 | * Copyright 2011-2012 Calxeda, Inc. |
3 | * Copyright (C) 2012-2013 Altera Corporation <www.altera.com> | ||
3 | * | 4 | * |
4 | * This program is free software; you can redistribute it and/or modify | 5 | * This program is free software; you can redistribute it and/or modify |
5 | * it under the terms of the GNU General Public License as published by | 6 | * it under the terms of the GNU General Public License as published by |
@@ -11,41 +12,161 @@ | |||
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 | * GNU General Public License for more details. | 13 | * GNU General Public License for more details. |
13 | * | 14 | * |
15 | * Based from clk-highbank.c | ||
16 | * | ||
14 | * You should have received a copy of the GNU General Public License | 17 | * You should have received a copy of the GNU General Public License |
15 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | 18 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
16 | */ | 19 | */ |
17 | #include <linux/clk.h> | 20 | #include <linux/clk.h> |
18 | #include <linux/clkdev.h> | 21 | #include <linux/clkdev.h> |
19 | #include <linux/clk-provider.h> | 22 | #include <linux/clk-provider.h> |
23 | #include <linux/io.h> | ||
24 | #include <linux/of.h> | ||
20 | 25 | ||
21 | #define SOCFPGA_OSC1_CLK 10000000 | 26 | /* Clock Manager offsets */ |
22 | #define SOCFPGA_MPU_CLK 800000000 | 27 | #define CLKMGR_CTRL 0x0 |
23 | #define SOCFPGA_MAIN_QSPI_CLK 432000000 | 28 | #define CLKMGR_BYPASS 0x4 |
24 | #define SOCFPGA_MAIN_NAND_SDMMC_CLK 250000000 | ||
25 | #define SOCFPGA_S2F_USR_CLK 125000000 | ||
26 | 29 | ||
27 | void __init socfpga_init_clocks(void) | 30 | /* Clock bypass bits */ |
31 | #define MAINPLL_BYPASS (1<<0) | ||
32 | #define SDRAMPLL_BYPASS (1<<1) | ||
33 | #define SDRAMPLL_SRC_BYPASS (1<<2) | ||
34 | #define PERPLL_BYPASS (1<<3) | ||
35 | #define PERPLL_SRC_BYPASS (1<<4) | ||
36 | |||
37 | #define SOCFPGA_PLL_BG_PWRDWN 0 | ||
38 | #define SOCFPGA_PLL_EXT_ENA 1 | ||
39 | #define SOCFPGA_PLL_PWR_DOWN 2 | ||
40 | #define SOCFPGA_PLL_DIVF_MASK 0x0000FFF8 | ||
41 | #define SOCFPGA_PLL_DIVF_SHIFT 3 | ||
42 | #define SOCFPGA_PLL_DIVQ_MASK 0x003F0000 | ||
43 | #define SOCFPGA_PLL_DIVQ_SHIFT 16 | ||
44 | |||
45 | extern void __iomem *clk_mgr_base_addr; | ||
46 | |||
47 | struct socfpga_clk { | ||
48 | struct clk_gate hw; | ||
49 | char *parent_name; | ||
50 | char *clk_name; | ||
51 | u32 fixed_div; | ||
52 | }; | ||
53 | #define to_socfpga_clk(p) container_of(p, struct socfpga_clk, hw.hw) | ||
54 | |||
55 | static unsigned long clk_pll_recalc_rate(struct clk_hw *hwclk, | ||
56 | unsigned long parent_rate) | ||
28 | { | 57 | { |
58 | struct socfpga_clk *socfpgaclk = to_socfpga_clk(hwclk); | ||
59 | unsigned long divf, divq, vco_freq, reg; | ||
60 | unsigned long bypass; | ||
61 | |||
62 | reg = readl(socfpgaclk->hw.reg); | ||
63 | bypass = readl(clk_mgr_base_addr + CLKMGR_BYPASS); | ||
64 | if (bypass & MAINPLL_BYPASS) | ||
65 | return parent_rate; | ||
66 | |||
67 | divf = (reg & SOCFPGA_PLL_DIVF_MASK) >> SOCFPGA_PLL_DIVF_SHIFT; | ||
68 | divq = (reg & SOCFPGA_PLL_DIVQ_MASK) >> SOCFPGA_PLL_DIVQ_SHIFT; | ||
69 | vco_freq = parent_rate * (divf + 1); | ||
70 | return vco_freq / (1 + divq); | ||
71 | } | ||
72 | |||
73 | |||
74 | static struct clk_ops clk_pll_ops = { | ||
75 | .recalc_rate = clk_pll_recalc_rate, | ||
76 | }; | ||
77 | |||
78 | static unsigned long clk_periclk_recalc_rate(struct clk_hw *hwclk, | ||
79 | unsigned long parent_rate) | ||
80 | { | ||
81 | struct socfpga_clk *socfpgaclk = to_socfpga_clk(hwclk); | ||
82 | u32 div; | ||
83 | |||
84 | if (socfpgaclk->fixed_div) | ||
85 | div = socfpgaclk->fixed_div; | ||
86 | else | ||
87 | div = ((readl(socfpgaclk->hw.reg) & 0x1ff) + 1); | ||
88 | |||
89 | return parent_rate / div; | ||
90 | } | ||
91 | |||
92 | static const struct clk_ops periclk_ops = { | ||
93 | .recalc_rate = clk_periclk_recalc_rate, | ||
94 | }; | ||
95 | |||
96 | static __init struct clk *socfpga_clk_init(struct device_node *node, | ||
97 | const struct clk_ops *ops) | ||
98 | { | ||
99 | u32 reg; | ||
29 | struct clk *clk; | 100 | struct clk *clk; |
101 | struct socfpga_clk *socfpga_clk; | ||
102 | const char *clk_name = node->name; | ||
103 | const char *parent_name; | ||
104 | struct clk_init_data init; | ||
105 | int rc; | ||
106 | u32 fixed_div; | ||
107 | |||
108 | rc = of_property_read_u32(node, "reg", ®); | ||
109 | if (WARN_ON(rc)) | ||
110 | return NULL; | ||
111 | |||
112 | socfpga_clk = kzalloc(sizeof(*socfpga_clk), GFP_KERNEL); | ||
113 | if (WARN_ON(!socfpga_clk)) | ||
114 | return NULL; | ||
115 | |||
116 | socfpga_clk->hw.reg = clk_mgr_base_addr + reg; | ||
117 | |||
118 | rc = of_property_read_u32(node, "fixed-divider", &fixed_div); | ||
119 | if (rc) | ||
120 | socfpga_clk->fixed_div = 0; | ||
121 | else | ||
122 | socfpga_clk->fixed_div = fixed_div; | ||
123 | |||
124 | of_property_read_string(node, "clock-output-names", &clk_name); | ||
125 | |||
126 | init.name = clk_name; | ||
127 | init.ops = ops; | ||
128 | init.flags = 0; | ||
129 | parent_name = of_clk_get_parent_name(node, 0); | ||
130 | init.parent_names = &parent_name; | ||
131 | init.num_parents = 1; | ||
30 | 132 | ||
31 | clk = clk_register_fixed_rate(NULL, "osc1_clk", NULL, CLK_IS_ROOT, SOCFPGA_OSC1_CLK); | 133 | socfpga_clk->hw.hw.init = &init; |
32 | clk_register_clkdev(clk, "osc1_clk", NULL); | ||
33 | 134 | ||
34 | clk = clk_register_fixed_rate(NULL, "mpu_clk", NULL, CLK_IS_ROOT, SOCFPGA_MPU_CLK); | 135 | if (strcmp(clk_name, "main_pll") || strcmp(clk_name, "periph_pll") || |
35 | clk_register_clkdev(clk, "mpu_clk", NULL); | 136 | strcmp(clk_name, "sdram_pll")) { |
137 | socfpga_clk->hw.bit_idx = SOCFPGA_PLL_EXT_ENA; | ||
138 | clk_pll_ops.enable = clk_gate_ops.enable; | ||
139 | clk_pll_ops.disable = clk_gate_ops.disable; | ||
140 | } | ||
36 | 141 | ||
37 | clk = clk_register_fixed_rate(NULL, "main_clk", NULL, CLK_IS_ROOT, SOCFPGA_MPU_CLK/2); | 142 | clk = clk_register(NULL, &socfpga_clk->hw.hw); |
38 | clk_register_clkdev(clk, "main_clk", NULL); | 143 | if (WARN_ON(IS_ERR(clk))) { |
144 | kfree(socfpga_clk); | ||
145 | return NULL; | ||
146 | } | ||
147 | rc = of_clk_add_provider(node, of_clk_src_simple_get, clk); | ||
148 | return clk; | ||
149 | } | ||
39 | 150 | ||
40 | clk = clk_register_fixed_rate(NULL, "dbg_base_clk", NULL, CLK_IS_ROOT, SOCFPGA_MPU_CLK/2); | 151 | static void __init socfpga_pll_init(struct device_node *node) |
41 | clk_register_clkdev(clk, "dbg_base_clk", NULL); | 152 | { |
153 | socfpga_clk_init(node, &clk_pll_ops); | ||
154 | } | ||
155 | CLK_OF_DECLARE(socfpga_pll, "altr,socfpga-pll-clock", socfpga_pll_init); | ||
42 | 156 | ||
43 | clk = clk_register_fixed_rate(NULL, "main_qspi_clk", NULL, CLK_IS_ROOT, SOCFPGA_MAIN_QSPI_CLK); | 157 | static void __init socfpga_periph_init(struct device_node *node) |
44 | clk_register_clkdev(clk, "main_qspi_clk", NULL); | 158 | { |
159 | socfpga_clk_init(node, &periclk_ops); | ||
160 | } | ||
161 | CLK_OF_DECLARE(socfpga_periph, "altr,socfpga-perip-clk", socfpga_periph_init); | ||
45 | 162 | ||
46 | clk = clk_register_fixed_rate(NULL, "main_nand_sdmmc_clk", NULL, CLK_IS_ROOT, SOCFPGA_MAIN_NAND_SDMMC_CLK); | 163 | void __init socfpga_init_clocks(void) |
47 | clk_register_clkdev(clk, "main_nand_sdmmc_clk", NULL); | 164 | { |
165 | struct clk *clk; | ||
166 | int ret; | ||
48 | 167 | ||
49 | clk = clk_register_fixed_rate(NULL, "s2f_usr_clk", NULL, CLK_IS_ROOT, SOCFPGA_S2F_USR_CLK); | 168 | clk = clk_register_fixed_factor(NULL, "smp_twd", "mpuclk", 0, 1, 4); |
50 | clk_register_clkdev(clk, "s2f_usr_clk", NULL); | 169 | ret = clk_register_clkdev(clk, NULL, "smp_twd"); |
170 | if (ret) | ||
171 | pr_err("smp_twd alias not registered\n"); | ||
51 | } | 172 | } |