blob: ae578c096ad82ebb3590e941f57d9ee45ca308bb [file] [log] [blame]
Sascha Hauer6bbaec52012-03-08 22:24:12 +01001/*
2 * Copyright (C) 2009 by Sascha Hauer, Pengutronix
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
16 * MA 02110-1301, USA.
17 */
18
19#include <linux/kernel.h>
20#include <linux/init.h>
21#include <linux/list.h>
22#include <linux/clk.h>
23#include <linux/io.h>
24#include <linux/clkdev.h>
25#include <linux/err.h>
Sascha Haueref4bac52012-09-20 14:59:36 +020026#include <linux/of.h>
27#include <linux/of_address.h>
28#include <linux/of_irq.h>
Sascha Hauer6bbaec52012-03-08 22:24:12 +010029
Sascha Hauer6bbaec52012-03-08 22:24:12 +010030#include "clk.h"
Shawn Guoe3372472012-09-13 21:01:00 +080031#include "common.h"
Shawn Guo50f2de62012-09-14 14:14:45 +080032#include "hardware.h"
33#include "mx25.h"
Sascha Hauer6bbaec52012-03-08 22:24:12 +010034
35#define CRM_BASE MX25_IO_ADDRESS(MX25_CRM_BASE_ADDR)
36
37#define CCM_MPCTL 0x00
38#define CCM_UPCTL 0x04
39#define CCM_CCTL 0x08
40#define CCM_CGCR0 0x0C
41#define CCM_CGCR1 0x10
42#define CCM_CGCR2 0x14
43#define CCM_PCDR0 0x18
44#define CCM_PCDR1 0x1C
45#define CCM_PCDR2 0x20
46#define CCM_PCDR3 0x24
47#define CCM_RCSR 0x28
48#define CCM_CRDR 0x2C
49#define CCM_DCVR0 0x30
50#define CCM_DCVR1 0x34
51#define CCM_DCVR2 0x38
52#define CCM_DCVR3 0x3c
53#define CCM_LTR0 0x40
54#define CCM_LTR1 0x44
55#define CCM_LTR2 0x48
56#define CCM_LTR3 0x4c
57#define CCM_MCR 0x64
58
59#define ccm(x) (CRM_BASE + (x))
60
Sascha Haueref4bac52012-09-20 14:59:36 +020061static struct clk_onecell_data clk_data;
62
Sascha Hauer6bbaec52012-03-08 22:24:12 +010063static const char *cpu_sel_clks[] = { "mpll", "mpll_cpu_3_4", };
64static const char *per_sel_clks[] = { "ahb", "upll", };
Fabio Estevam46ae4242014-03-12 02:55:46 +080065static const char *cko_sel_clks[] = { "dummy", "osc", "cpu", "ahb",
66 "ipg", "dummy", "dummy", "dummy",
67 "dummy", "dummy", "per0", "per2",
68 "per13", "per14", "usbotg_ahb", "dummy",};
Sascha Hauer6bbaec52012-03-08 22:24:12 +010069
70enum mx25_clks {
71 dummy, osc, mpll, upll, mpll_cpu_3_4, cpu_sel, cpu, ahb, usb_div, ipg,
72 per0_sel, per1_sel, per2_sel, per3_sel, per4_sel, per5_sel, per6_sel,
73 per7_sel, per8_sel, per9_sel, per10_sel, per11_sel, per12_sel,
74 per13_sel, per14_sel, per15_sel, per0, per1, per2, per3, per4, per5,
75 per6, per7, per8, per9, per10, per11, per12, per13, per14, per15,
Sascha Hauerf6d33462012-10-09 10:04:57 +020076 csi_ipg_per, epit_ipg_per, esai_ipg_per, esdhc1_ipg_per, esdhc2_ipg_per,
77 gpt_ipg_per, i2c_ipg_per, lcdc_ipg_per, nfc_ipg_per, owire_ipg_per,
78 pwm_ipg_per, sim1_ipg_per, sim2_ipg_per, ssi1_ipg_per, ssi2_ipg_per,
79 uart_ipg_per, ata_ahb, reserved1, csi_ahb, emi_ahb, esai_ahb, esdhc1_ahb,
80 esdhc2_ahb, fec_ahb, lcdc_ahb, rtic_ahb, sdma_ahb, slcdc_ahb, usbotg_ahb,
81 reserved2, reserved3, reserved4, reserved5, can1_ipg, can2_ipg, csi_ipg,
82 cspi1_ipg, cspi2_ipg, cspi3_ipg, dryice_ipg, ect_ipg, epit1_ipg, epit2_ipg,
83 reserved6, esdhc1_ipg, esdhc2_ipg, fec_ipg, reserved7, reserved8, reserved9,
84 gpt1_ipg, gpt2_ipg, gpt3_ipg, gpt4_ipg, reserved10, reserved11, reserved12,
85 iim_ipg, reserved13, reserved14, kpp_ipg, lcdc_ipg, reserved15, pwm1_ipg,
86 pwm2_ipg, pwm3_ipg, pwm4_ipg, rngb_ipg, reserved16, scc_ipg, sdma_ipg,
87 sim1_ipg, sim2_ipg, slcdc_ipg, spba_ipg, ssi1_ipg, ssi2_ipg, tsc_ipg,
88 uart1_ipg, uart2_ipg, uart3_ipg, uart4_ipg, uart5_ipg, reserved17,
Fabio Estevam46ae4242014-03-12 02:55:46 +080089 wdt_ipg, cko_div, cko_sel, cko, clk_max
Sascha Hauer6bbaec52012-03-08 22:24:12 +010090};
91
92static struct clk *clk[clk_max];
93
Sascha Haueref4bac52012-09-20 14:59:36 +020094static int __init __mx25_clocks_init(unsigned long osc_rate)
Sascha Hauer6bbaec52012-03-08 22:24:12 +010095{
96 int i;
97
98 clk[dummy] = imx_clk_fixed("dummy", 0);
Sascha Haueref4bac52012-09-20 14:59:36 +020099 clk[osc] = imx_clk_fixed("osc", osc_rate);
Sascha Hauer6bbaec52012-03-08 22:24:12 +0100100 clk[mpll] = imx_clk_pllv1("mpll", "osc", ccm(CCM_MPCTL));
101 clk[upll] = imx_clk_pllv1("upll", "osc", ccm(CCM_UPCTL));
102 clk[mpll_cpu_3_4] = imx_clk_fixed_factor("mpll_cpu_3_4", "mpll", 3, 4);
103 clk[cpu_sel] = imx_clk_mux("cpu_sel", ccm(CCM_CCTL), 14, 1, cpu_sel_clks, ARRAY_SIZE(cpu_sel_clks));
104 clk[cpu] = imx_clk_divider("cpu", "cpu_sel", ccm(CCM_CCTL), 30, 2);
105 clk[ahb] = imx_clk_divider("ahb", "cpu", ccm(CCM_CCTL), 28, 2);
106 clk[usb_div] = imx_clk_divider("usb_div", "upll", ccm(CCM_CCTL), 16, 6);
107 clk[ipg] = imx_clk_fixed_factor("ipg", "ahb", 1, 2);
108 clk[per0_sel] = imx_clk_mux("per0_sel", ccm(CCM_MCR), 0, 1, per_sel_clks, ARRAY_SIZE(per_sel_clks));
109 clk[per1_sel] = imx_clk_mux("per1_sel", ccm(CCM_MCR), 1, 1, per_sel_clks, ARRAY_SIZE(per_sel_clks));
110 clk[per2_sel] = imx_clk_mux("per2_sel", ccm(CCM_MCR), 2, 1, per_sel_clks, ARRAY_SIZE(per_sel_clks));
111 clk[per3_sel] = imx_clk_mux("per3_sel", ccm(CCM_MCR), 3, 1, per_sel_clks, ARRAY_SIZE(per_sel_clks));
112 clk[per4_sel] = imx_clk_mux("per4_sel", ccm(CCM_MCR), 4, 1, per_sel_clks, ARRAY_SIZE(per_sel_clks));
113 clk[per5_sel] = imx_clk_mux("per5_sel", ccm(CCM_MCR), 5, 1, per_sel_clks, ARRAY_SIZE(per_sel_clks));
114 clk[per6_sel] = imx_clk_mux("per6_sel", ccm(CCM_MCR), 6, 1, per_sel_clks, ARRAY_SIZE(per_sel_clks));
115 clk[per7_sel] = imx_clk_mux("per7_sel", ccm(CCM_MCR), 7, 1, per_sel_clks, ARRAY_SIZE(per_sel_clks));
116 clk[per8_sel] = imx_clk_mux("per8_sel", ccm(CCM_MCR), 8, 1, per_sel_clks, ARRAY_SIZE(per_sel_clks));
117 clk[per9_sel] = imx_clk_mux("per9_sel", ccm(CCM_MCR), 9, 1, per_sel_clks, ARRAY_SIZE(per_sel_clks));
118 clk[per10_sel] = imx_clk_mux("per10_sel", ccm(CCM_MCR), 10, 1, per_sel_clks, ARRAY_SIZE(per_sel_clks));
119 clk[per11_sel] = imx_clk_mux("per11_sel", ccm(CCM_MCR), 11, 1, per_sel_clks, ARRAY_SIZE(per_sel_clks));
120 clk[per12_sel] = imx_clk_mux("per12_sel", ccm(CCM_MCR), 12, 1, per_sel_clks, ARRAY_SIZE(per_sel_clks));
121 clk[per13_sel] = imx_clk_mux("per13_sel", ccm(CCM_MCR), 13, 1, per_sel_clks, ARRAY_SIZE(per_sel_clks));
122 clk[per14_sel] = imx_clk_mux("per14_sel", ccm(CCM_MCR), 14, 1, per_sel_clks, ARRAY_SIZE(per_sel_clks));
123 clk[per15_sel] = imx_clk_mux("per15_sel", ccm(CCM_MCR), 15, 1, per_sel_clks, ARRAY_SIZE(per_sel_clks));
Fabio Estevam46ae4242014-03-12 02:55:46 +0800124 clk[cko_div] = imx_clk_divider("cko_div", "cko_sel", ccm(CCM_MCR), 24, 6);
125 clk[cko_sel] = imx_clk_mux("cko_sel", ccm(CCM_MCR), 20, 4, cko_sel_clks, ARRAY_SIZE(cko_sel_clks));
126 clk[cko] = imx_clk_gate("cko", "cko_div", ccm(CCM_MCR), 30);
Sascha Hauer6bbaec52012-03-08 22:24:12 +0100127 clk[per0] = imx_clk_divider("per0", "per0_sel", ccm(CCM_PCDR0), 0, 6);
128 clk[per1] = imx_clk_divider("per1", "per1_sel", ccm(CCM_PCDR0), 8, 6);
129 clk[per2] = imx_clk_divider("per2", "per2_sel", ccm(CCM_PCDR0), 16, 6);
130 clk[per3] = imx_clk_divider("per3", "per3_sel", ccm(CCM_PCDR0), 24, 6);
131 clk[per4] = imx_clk_divider("per4", "per4_sel", ccm(CCM_PCDR1), 0, 6);
132 clk[per5] = imx_clk_divider("per5", "per5_sel", ccm(CCM_PCDR1), 8, 6);
133 clk[per6] = imx_clk_divider("per6", "per6_sel", ccm(CCM_PCDR1), 16, 6);
134 clk[per7] = imx_clk_divider("per7", "per7_sel", ccm(CCM_PCDR1), 24, 6);
135 clk[per8] = imx_clk_divider("per8", "per8_sel", ccm(CCM_PCDR2), 0, 6);
136 clk[per9] = imx_clk_divider("per9", "per9_sel", ccm(CCM_PCDR2), 8, 6);
137 clk[per10] = imx_clk_divider("per10", "per10_sel", ccm(CCM_PCDR2), 16, 6);
138 clk[per11] = imx_clk_divider("per11", "per11_sel", ccm(CCM_PCDR2), 24, 6);
139 clk[per12] = imx_clk_divider("per12", "per12_sel", ccm(CCM_PCDR3), 0, 6);
140 clk[per13] = imx_clk_divider("per13", "per13_sel", ccm(CCM_PCDR3), 8, 6);
141 clk[per14] = imx_clk_divider("per14", "per14_sel", ccm(CCM_PCDR3), 16, 6);
142 clk[per15] = imx_clk_divider("per15", "per15_sel", ccm(CCM_PCDR3), 24, 6);
143 clk[csi_ipg_per] = imx_clk_gate("csi_ipg_per", "per0", ccm(CCM_CGCR0), 0);
Sascha Hauerf6d33462012-10-09 10:04:57 +0200144 clk[epit_ipg_per] = imx_clk_gate("epit_ipg_per", "per1", ccm(CCM_CGCR0), 1);
145 clk[esai_ipg_per] = imx_clk_gate("esai_ipg_per", "per2", ccm(CCM_CGCR0), 2);
Sascha Hauer6bbaec52012-03-08 22:24:12 +0100146 clk[esdhc1_ipg_per] = imx_clk_gate("esdhc1_ipg_per", "per3", ccm(CCM_CGCR0), 3);
147 clk[esdhc2_ipg_per] = imx_clk_gate("esdhc2_ipg_per", "per4", ccm(CCM_CGCR0), 4);
148 clk[gpt_ipg_per] = imx_clk_gate("gpt_ipg_per", "per5", ccm(CCM_CGCR0), 5);
149 clk[i2c_ipg_per] = imx_clk_gate("i2c_ipg_per", "per6", ccm(CCM_CGCR0), 6);
Sascha Hauera4bb8e62012-10-08 08:46:06 +0200150 clk[lcdc_ipg_per] = imx_clk_gate("lcdc_ipg_per", "per7", ccm(CCM_CGCR0), 7);
Sascha Hauer1f441c42012-10-09 10:03:00 +0200151 clk[nfc_ipg_per] = imx_clk_gate("nfc_ipg_per", "per8", ccm(CCM_CGCR0), 8);
Sascha Hauerf6d33462012-10-09 10:04:57 +0200152 clk[owire_ipg_per] = imx_clk_gate("owire_ipg_per", "per9", ccm(CCM_CGCR0), 9);
153 clk[pwm_ipg_per] = imx_clk_gate("pwm_ipg_per", "per10", ccm(CCM_CGCR0), 10);
154 clk[sim1_ipg_per] = imx_clk_gate("sim1_ipg_per", "per11", ccm(CCM_CGCR0), 11);
155 clk[sim2_ipg_per] = imx_clk_gate("sim2_ipg_per", "per12", ccm(CCM_CGCR0), 12);
Sascha Hauer6bbaec52012-03-08 22:24:12 +0100156 clk[ssi1_ipg_per] = imx_clk_gate("ssi1_ipg_per", "per13", ccm(CCM_CGCR0), 13);
157 clk[ssi2_ipg_per] = imx_clk_gate("ssi2_ipg_per", "per14", ccm(CCM_CGCR0), 14);
158 clk[uart_ipg_per] = imx_clk_gate("uart_ipg_per", "per15", ccm(CCM_CGCR0), 15);
Sascha Hauerf6d33462012-10-09 10:04:57 +0200159 clk[ata_ahb] = imx_clk_gate("ata_ahb", "ahb", ccm(CCM_CGCR0), 16);
160 /* CCM_CGCR0(17): reserved */
Sascha Hauer6bbaec52012-03-08 22:24:12 +0100161 clk[csi_ahb] = imx_clk_gate("csi_ahb", "ahb", ccm(CCM_CGCR0), 18);
Sascha Hauerf6d33462012-10-09 10:04:57 +0200162 clk[emi_ahb] = imx_clk_gate("emi_ahb", "ahb", ccm(CCM_CGCR0), 19);
163 clk[esai_ahb] = imx_clk_gate("esai_ahb", "ahb", ccm(CCM_CGCR0), 20);
Sascha Hauer6bbaec52012-03-08 22:24:12 +0100164 clk[esdhc1_ahb] = imx_clk_gate("esdhc1_ahb", "ahb", ccm(CCM_CGCR0), 21);
165 clk[esdhc2_ahb] = imx_clk_gate("esdhc2_ahb", "ahb", ccm(CCM_CGCR0), 22);
166 clk[fec_ahb] = imx_clk_gate("fec_ahb", "ahb", ccm(CCM_CGCR0), 23);
167 clk[lcdc_ahb] = imx_clk_gate("lcdc_ahb", "ahb", ccm(CCM_CGCR0), 24);
Sascha Hauerf6d33462012-10-09 10:04:57 +0200168 clk[rtic_ahb] = imx_clk_gate("rtic_ahb", "ahb", ccm(CCM_CGCR0), 25);
Sascha Hauer6bbaec52012-03-08 22:24:12 +0100169 clk[sdma_ahb] = imx_clk_gate("sdma_ahb", "ahb", ccm(CCM_CGCR0), 26);
Sascha Hauerf6d33462012-10-09 10:04:57 +0200170 clk[slcdc_ahb] = imx_clk_gate("slcdc_ahb", "ahb", ccm(CCM_CGCR0), 27);
Sascha Hauer6bbaec52012-03-08 22:24:12 +0100171 clk[usbotg_ahb] = imx_clk_gate("usbotg_ahb", "ahb", ccm(CCM_CGCR0), 28);
Sascha Hauerf6d33462012-10-09 10:04:57 +0200172 /* CCM_CGCR0(29-31): reserved */
173 /* CCM_CGCR1(0): reserved in datasheet, used as audmux in FSL kernel */
Sascha Hauer6bbaec52012-03-08 22:24:12 +0100174 clk[can1_ipg] = imx_clk_gate("can1_ipg", "ipg", ccm(CCM_CGCR1), 2);
175 clk[can2_ipg] = imx_clk_gate("can2_ipg", "ipg", ccm(CCM_CGCR1), 3);
176 clk[csi_ipg] = imx_clk_gate("csi_ipg", "ipg", ccm(CCM_CGCR1), 4);
177 clk[cspi1_ipg] = imx_clk_gate("cspi1_ipg", "ipg", ccm(CCM_CGCR1), 5);
178 clk[cspi2_ipg] = imx_clk_gate("cspi2_ipg", "ipg", ccm(CCM_CGCR1), 6);
179 clk[cspi3_ipg] = imx_clk_gate("cspi3_ipg", "ipg", ccm(CCM_CGCR1), 7);
180 clk[dryice_ipg] = imx_clk_gate("dryice_ipg", "ipg", ccm(CCM_CGCR1), 8);
Sascha Hauerf6d33462012-10-09 10:04:57 +0200181 clk[ect_ipg] = imx_clk_gate("ect_ipg", "ipg", ccm(CCM_CGCR1), 9);
182 clk[epit1_ipg] = imx_clk_gate("epit1_ipg", "ipg", ccm(CCM_CGCR1), 10);
183 clk[epit2_ipg] = imx_clk_gate("epit2_ipg", "ipg", ccm(CCM_CGCR1), 11);
184 /* CCM_CGCR1(12): reserved in datasheet, used as esai in FSL kernel */
Sascha Hauer6bbaec52012-03-08 22:24:12 +0100185 clk[esdhc1_ipg] = imx_clk_gate("esdhc1_ipg", "ipg", ccm(CCM_CGCR1), 13);
186 clk[esdhc2_ipg] = imx_clk_gate("esdhc2_ipg", "ipg", ccm(CCM_CGCR1), 14);
187 clk[fec_ipg] = imx_clk_gate("fec_ipg", "ipg", ccm(CCM_CGCR1), 15);
Sascha Hauerf6d33462012-10-09 10:04:57 +0200188 /* CCM_CGCR1(16): reserved in datasheet, used as gpio1 in FSL kernel */
189 /* CCM_CGCR1(17): reserved in datasheet, used as gpio2 in FSL kernel */
190 /* CCM_CGCR1(18): reserved in datasheet, used as gpio3 in FSL kernel */
191 clk[gpt1_ipg] = imx_clk_gate("gpt1_ipg", "ipg", ccm(CCM_CGCR1), 19);
192 clk[gpt2_ipg] = imx_clk_gate("gpt2_ipg", "ipg", ccm(CCM_CGCR1), 20);
193 clk[gpt3_ipg] = imx_clk_gate("gpt3_ipg", "ipg", ccm(CCM_CGCR1), 21);
194 clk[gpt4_ipg] = imx_clk_gate("gpt4_ipg", "ipg", ccm(CCM_CGCR1), 22);
195 /* CCM_CGCR1(23): reserved in datasheet, used as i2c1 in FSL kernel */
196 /* CCM_CGCR1(24): reserved in datasheet, used as i2c2 in FSL kernel */
197 /* CCM_CGCR1(25): reserved in datasheet, used as i2c3 in FSL kernel */
Sascha Hauer6bbaec52012-03-08 22:24:12 +0100198 clk[iim_ipg] = imx_clk_gate("iim_ipg", "ipg", ccm(CCM_CGCR1), 26);
Sascha Hauerf6d33462012-10-09 10:04:57 +0200199 /* CCM_CGCR1(27): reserved in datasheet, used as iomuxc in FSL kernel */
200 /* CCM_CGCR1(28): reserved in datasheet, used as kpp in FSL kernel */
Sascha Hauer6bbaec52012-03-08 22:24:12 +0100201 clk[kpp_ipg] = imx_clk_gate("kpp_ipg", "ipg", ccm(CCM_CGCR1), 28);
202 clk[lcdc_ipg] = imx_clk_gate("lcdc_ipg", "ipg", ccm(CCM_CGCR1), 29);
Sascha Hauerf6d33462012-10-09 10:04:57 +0200203 /* CCM_CGCR1(30): reserved in datasheet, used as owire in FSL kernel */
Sascha Hauer6bbaec52012-03-08 22:24:12 +0100204 clk[pwm1_ipg] = imx_clk_gate("pwm1_ipg", "ipg", ccm(CCM_CGCR1), 31);
205 clk[pwm2_ipg] = imx_clk_gate("pwm2_ipg", "ipg", ccm(CCM_CGCR2), 0);
206 clk[pwm3_ipg] = imx_clk_gate("pwm3_ipg", "ipg", ccm(CCM_CGCR2), 1);
207 clk[pwm4_ipg] = imx_clk_gate("pwm4_ipg", "ipg", ccm(CCM_CGCR2), 2);
Sascha Hauerf6d33462012-10-09 10:04:57 +0200208 clk[rngb_ipg] = imx_clk_gate("rngb_ipg", "ipg", ccm(CCM_CGCR2), 3);
209 /* CCM_CGCR2(4): reserved in datasheet, used as rtic in FSL kernel */
210 clk[scc_ipg] = imx_clk_gate("scc_ipg", "ipg", ccm(CCM_CGCR2), 5);
Sascha Hauer6bbaec52012-03-08 22:24:12 +0100211 clk[sdma_ipg] = imx_clk_gate("sdma_ipg", "ipg", ccm(CCM_CGCR2), 6);
Sascha Hauerf6d33462012-10-09 10:04:57 +0200212 clk[sim1_ipg] = imx_clk_gate("sim1_ipg", "ipg", ccm(CCM_CGCR2), 7);
213 clk[sim2_ipg] = imx_clk_gate("sim2_ipg", "ipg", ccm(CCM_CGCR2), 8);
214 clk[slcdc_ipg] = imx_clk_gate("slcdc_ipg", "ipg", ccm(CCM_CGCR2), 9);
215 clk[spba_ipg] = imx_clk_gate("spba_ipg", "ipg", ccm(CCM_CGCR2), 10);
Sascha Hauer6bbaec52012-03-08 22:24:12 +0100216 clk[ssi1_ipg] = imx_clk_gate("ssi1_ipg", "ipg", ccm(CCM_CGCR2), 11);
217 clk[ssi2_ipg] = imx_clk_gate("ssi2_ipg", "ipg", ccm(CCM_CGCR2), 12);
218 clk[tsc_ipg] = imx_clk_gate("tsc_ipg", "ipg", ccm(CCM_CGCR2), 13);
219 clk[uart1_ipg] = imx_clk_gate("uart1_ipg", "ipg", ccm(CCM_CGCR2), 14);
220 clk[uart2_ipg] = imx_clk_gate("uart2_ipg", "ipg", ccm(CCM_CGCR2), 15);
221 clk[uart3_ipg] = imx_clk_gate("uart3_ipg", "ipg", ccm(CCM_CGCR2), 16);
222 clk[uart4_ipg] = imx_clk_gate("uart4_ipg", "ipg", ccm(CCM_CGCR2), 17);
223 clk[uart5_ipg] = imx_clk_gate("uart5_ipg", "ipg", ccm(CCM_CGCR2), 18);
Sascha Hauerf6d33462012-10-09 10:04:57 +0200224 /* CCM_CGCR2(19): reserved in datasheet, but used as wdt in FSL kernel */
Sascha Hauer6bbaec52012-03-08 22:24:12 +0100225 clk[wdt_ipg] = imx_clk_gate("wdt_ipg", "ipg", ccm(CCM_CGCR2), 19);
226
227 for (i = 0; i < ARRAY_SIZE(clk); i++)
228 if (IS_ERR(clk[i]))
229 pr_err("i.MX25 clk %d: register failed with %ld\n",
230 i, PTR_ERR(clk[i]));
231
Sascha Hauerf6d33462012-10-09 10:04:57 +0200232 clk_prepare_enable(clk[emi_ahb]);
233
Steffen Trumtrar4b526ca52013-01-30 14:16:00 +0100234 /* Clock source for gpt must be derived from AHB */
235 clk_set_parent(clk[per5_sel], clk[ahb]);
236
Sascha Haueref4bac52012-09-20 14:59:36 +0200237 clk_register_clkdev(clk[ipg], "ipg", "imx-gpt.0");
238 clk_register_clkdev(clk[gpt_ipg_per], "per", "imx-gpt.0");
239
Fabio Estevam46ae4242014-03-12 02:55:46 +0800240 /*
241 * Let's initially set up CLKO parent as ipg, since this configuration
242 * is used on some imx25 board designs to clock the audio codec.
243 */
244 clk_set_parent(clk[cko_sel], clk[ipg]);
245
Sascha Haueref4bac52012-09-20 14:59:36 +0200246 return 0;
247}
248
249int __init mx25_clocks_init(void)
250{
251 __mx25_clocks_init(24000000);
252
Sascha Hauer6bbaec52012-03-08 22:24:12 +0100253 /* i.mx25 has the i.mx21 type uart */
254 clk_register_clkdev(clk[uart1_ipg], "ipg", "imx21-uart.0");
255 clk_register_clkdev(clk[uart_ipg_per], "per", "imx21-uart.0");
256 clk_register_clkdev(clk[uart2_ipg], "ipg", "imx21-uart.1");
257 clk_register_clkdev(clk[uart_ipg_per], "per", "imx21-uart.1");
258 clk_register_clkdev(clk[uart3_ipg], "ipg", "imx21-uart.2");
259 clk_register_clkdev(clk[uart_ipg_per], "per", "imx21-uart.2");
260 clk_register_clkdev(clk[uart4_ipg], "ipg", "imx21-uart.3");
261 clk_register_clkdev(clk[uart_ipg_per], "per", "imx21-uart.3");
262 clk_register_clkdev(clk[uart5_ipg], "ipg", "imx21-uart.4");
263 clk_register_clkdev(clk[uart_ipg_per], "per", "imx21-uart.4");
Sascha Hauer6bbaec52012-03-08 22:24:12 +0100264 clk_register_clkdev(clk[ipg], "ipg", "mxc-ehci.0");
265 clk_register_clkdev(clk[usbotg_ahb], "ahb", "mxc-ehci.0");
266 clk_register_clkdev(clk[usb_div], "per", "mxc-ehci.0");
267 clk_register_clkdev(clk[ipg], "ipg", "mxc-ehci.1");
268 clk_register_clkdev(clk[usbotg_ahb], "ahb", "mxc-ehci.1");
269 clk_register_clkdev(clk[usb_div], "per", "mxc-ehci.1");
270 clk_register_clkdev(clk[ipg], "ipg", "mxc-ehci.2");
271 clk_register_clkdev(clk[usbotg_ahb], "ahb", "mxc-ehci.2");
272 clk_register_clkdev(clk[usb_div], "per", "mxc-ehci.2");
Peter Chen61c4b562013-01-17 18:03:17 +0800273 clk_register_clkdev(clk[ipg], "ipg", "imx-udc-mx27");
274 clk_register_clkdev(clk[usbotg_ahb], "ahb", "imx-udc-mx27");
275 clk_register_clkdev(clk[usb_div], "per", "imx-udc-mx27");
Shawn Guo4d624352012-09-15 13:34:09 +0800276 clk_register_clkdev(clk[nfc_ipg_per], NULL, "imx25-nand.0");
Sascha Hauer6bbaec52012-03-08 22:24:12 +0100277 /* i.mx25 has the i.mx35 type cspi */
278 clk_register_clkdev(clk[cspi1_ipg], NULL, "imx35-cspi.0");
279 clk_register_clkdev(clk[cspi2_ipg], NULL, "imx35-cspi.1");
280 clk_register_clkdev(clk[cspi3_ipg], NULL, "imx35-cspi.2");
Sascha Hauer6bbaec52012-03-08 22:24:12 +0100281 clk_register_clkdev(clk[kpp_ipg], NULL, "imx-keypad");
282 clk_register_clkdev(clk[tsc_ipg], NULL, "mx25-adc");
Shawn Guo5bdfba22012-09-14 15:19:00 +0800283 clk_register_clkdev(clk[i2c_ipg_per], NULL, "imx21-i2c.0");
284 clk_register_clkdev(clk[i2c_ipg_per], NULL, "imx21-i2c.1");
285 clk_register_clkdev(clk[i2c_ipg_per], NULL, "imx21-i2c.2");
Sascha Hauer6bbaec52012-03-08 22:24:12 +0100286 clk_register_clkdev(clk[fec_ipg], "ipg", "imx25-fec.0");
287 clk_register_clkdev(clk[fec_ahb], "ahb", "imx25-fec.0");
288 clk_register_clkdev(clk[dryice_ipg], NULL, "imxdi_rtc.0");
Shawn Guoe69dc9a2012-09-16 19:59:53 +0800289 clk_register_clkdev(clk[lcdc_ipg_per], "per", "imx21-fb.0");
290 clk_register_clkdev(clk[lcdc_ipg], "ipg", "imx21-fb.0");
291 clk_register_clkdev(clk[lcdc_ahb], "ahb", "imx21-fb.0");
Sascha Hauer6bbaec52012-03-08 22:24:12 +0100292 clk_register_clkdev(clk[wdt_ipg], NULL, "imx2-wdt.0");
Fabio Estevam912bfe72012-08-19 14:05:59 -0300293 clk_register_clkdev(clk[ssi1_ipg], NULL, "imx-ssi.0");
294 clk_register_clkdev(clk[ssi2_ipg], NULL, "imx-ssi.1");
Sascha Hauer6bbaec52012-03-08 22:24:12 +0100295 clk_register_clkdev(clk[esdhc1_ipg_per], "per", "sdhci-esdhc-imx25.0");
296 clk_register_clkdev(clk[esdhc1_ipg], "ipg", "sdhci-esdhc-imx25.0");
297 clk_register_clkdev(clk[esdhc1_ahb], "ahb", "sdhci-esdhc-imx25.0");
298 clk_register_clkdev(clk[esdhc2_ipg_per], "per", "sdhci-esdhc-imx25.1");
299 clk_register_clkdev(clk[esdhc2_ipg], "ipg", "sdhci-esdhc-imx25.1");
300 clk_register_clkdev(clk[esdhc2_ahb], "ahb", "sdhci-esdhc-imx25.1");
Shawn Guo27b76482012-09-16 16:26:20 +0800301 clk_register_clkdev(clk[csi_ipg_per], "per", "imx25-camera.0");
302 clk_register_clkdev(clk[csi_ipg], "ipg", "imx25-camera.0");
303 clk_register_clkdev(clk[csi_ahb], "ahb", "imx25-camera.0");
Sascha Hauer6bbaec52012-03-08 22:24:12 +0100304 clk_register_clkdev(clk[dummy], "audmux", NULL);
305 clk_register_clkdev(clk[can1_ipg], NULL, "flexcan.0");
306 clk_register_clkdev(clk[can2_ipg], NULL, "flexcan.1");
307 /* i.mx25 has the i.mx35 type sdma */
308 clk_register_clkdev(clk[sdma_ipg], "ipg", "imx35-sdma");
309 clk_register_clkdev(clk[sdma_ahb], "ahb", "imx35-sdma");
310 clk_register_clkdev(clk[iim_ipg], "iim", NULL);
311
Sascha Hauer42a3f892012-09-18 10:05:31 +0200312 mxc_timer_init(MX25_IO_ADDRESS(MX25_GPT1_BASE_ADDR), MX25_INT_GPT1);
Sascha Haueref4bac52012-09-20 14:59:36 +0200313
314 return 0;
315}
316
317int __init mx25_clocks_init_dt(void)
318{
319 struct device_node *np;
Sascha Haueref4bac52012-09-20 14:59:36 +0200320 unsigned long osc_rate = 24000000;
321
322 /* retrieve the freqency of fixed clocks from device tree */
323 for_each_compatible_node(np, NULL, "fixed-clock") {
324 u32 rate;
325 if (of_property_read_u32(np, "clock-frequency", &rate))
326 continue;
327
328 if (of_device_is_compatible(np, "fsl,imx-osc"))
329 osc_rate = rate;
330 }
331
332 np = of_find_compatible_node(NULL, NULL, "fsl,imx25-ccm");
333 clk_data.clks = clk;
334 clk_data.clk_num = ARRAY_SIZE(clk);
335 of_clk_add_provider(np, of_clk_src_onecell_get, &clk_data);
336
337 __mx25_clocks_init(osc_rate);
338
Gilles Chanteperdrix876292d2014-04-05 17:57:45 +0200339 mxc_timer_init_dt(of_find_compatible_node(NULL, NULL, "fsl,imx25-gpt"));
Sascha Haueref4bac52012-09-20 14:59:36 +0200340
Sascha Hauer6bbaec52012-03-08 22:24:12 +0100341 return 0;
342}