blob: ce37af26ff8c6931b62e9459d7ffb7df1daf81ab [file] [log] [blame]
Sascha Hauerb8d41762012-03-19 12:36:57 +01001/*
2 * Copyright (C) 2011 Sascha Hauer, Pengutronix <s.hauer@pengutronix.de>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
7 *
8 */
9#include <linux/mm.h>
10#include <linux/delay.h>
11#include <linux/clk.h>
12#include <linux/io.h>
13#include <linux/clkdev.h>
Sebastian Hesselbarth4d9d18a2013-08-27 14:50:00 +020014#include <linux/clk-provider.h>
Sascha Hauerb8d41762012-03-19 12:36:57 +010015#include <linux/of.h>
16#include <linux/err.h>
Fabio Estevambfcc7bc2013-10-01 00:21:12 -030017#include <linux/of.h>
18#include <linux/of_address.h>
19#include <linux/of_irq.h>
Sascha Hauerb8d41762012-03-19 12:36:57 +010020
Sascha Hauerb8d41762012-03-19 12:36:57 +010021#include "crm-regs-imx5.h"
22#include "clk.h"
Shawn Guoe3372472012-09-13 21:01:00 +080023#include "common.h"
Shawn Guo50f2de62012-09-14 14:14:45 +080024#include "hardware.h"
Sascha Hauerb8d41762012-03-19 12:36:57 +010025
26/* Low-power Audio Playback Mode clock */
27static const char *lp_apm_sel[] = { "osc", };
28
29/* This is used multiple times */
30static const char *standard_pll_sel[] = { "pll1_sw", "pll2_sw", "pll3_sw", "lp_apm", };
31static const char *periph_apm_sel[] = { "pll1_sw", "pll3_sw", "lp_apm", };
32static const char *main_bus_sel[] = { "pll2_sw", "periph_apm", };
33static const char *per_lp_apm_sel[] = { "main_bus", "lp_apm", };
34static const char *per_root_sel[] = { "per_podf", "ipg", };
35static const char *esdhc_c_sel[] = { "esdhc_a_podf", "esdhc_b_podf", };
36static const char *esdhc_d_sel[] = { "esdhc_a_podf", "esdhc_b_podf", };
Shawn Guo13b3a072012-05-03 20:15:57 +080037static const char *ssi_apm_sels[] = { "ckih1", "lp_amp", "ckih2", };
38static const char *ssi_clk_sels[] = { "pll1_sw", "pll2_sw", "pll3_sw", "ssi_apm", };
39static const char *ssi3_clk_sels[] = { "ssi1_root_gate", "ssi2_root_gate", };
40static const char *ssi_ext1_com_sels[] = { "ssi_ext1_podf", "ssi1_root_gate", };
41static const char *ssi_ext2_com_sels[] = { "ssi_ext2_podf", "ssi2_root_gate", };
Sascha Hauerb8d41762012-03-19 12:36:57 +010042static const char *emi_slow_sel[] = { "main_bus", "ahb", };
43static const char *usb_phy_sel_str[] = { "osc", "usb_phy_podf", };
44static const char *mx51_ipu_di0_sel[] = { "di_pred", "osc", "ckih1", "tve_di", };
Sascha Hauer51f66192012-06-04 15:07:36 +020045static const char *mx53_ipu_di0_sel[] = { "di_pred", "osc", "ckih1", "di_pll4_podf", "dummy", "ldb_di0_gate", };
Sascha Hauerb8d41762012-03-19 12:36:57 +010046static const char *mx53_ldb_di0_sel[] = { "pll3_sw", "pll4_sw", };
47static const char *mx51_ipu_di1_sel[] = { "di_pred", "osc", "ckih1", "tve_di", "ipp_di1", };
Sascha Hauer51f66192012-06-04 15:07:36 +020048static const char *mx53_ipu_di1_sel[] = { "di_pred", "osc", "ckih1", "tve_di", "ipp_di1", "ldb_di1_gate", };
Sascha Hauerb8d41762012-03-19 12:36:57 +010049static const char *mx53_ldb_di1_sel[] = { "pll3_sw", "pll4_sw", };
50static const char *mx51_tve_ext_sel[] = { "osc", "ckih1", };
51static const char *mx53_tve_ext_sel[] = { "pll4_sw", "ckih1", };
Philipp Zabel3f487be2013-04-08 16:46:19 +020052static const char *mx51_tve_sel[] = { "tve_pred", "tve_ext_sel", };
Sascha Hauerb8d41762012-03-19 12:36:57 +010053static const char *ipu_sel[] = { "axi_a", "axi_b", "emi_slow_gate", "ahb", };
Philipp Zabel8ecb1672013-03-27 10:51:33 +010054static const char *gpu3d_sel[] = { "axi_a", "axi_b", "emi_slow_gate", "ahb" };
55static const char *gpu2d_sel[] = { "axi_a", "axi_b", "emi_slow_gate", "ahb" };
Sascha Hauerb8d41762012-03-19 12:36:57 +010056static const char *vpu_sel[] = { "axi_a", "axi_b", "emi_slow_gate", "ahb", };
Sascha Hauera745f032012-07-17 16:42:49 +020057static const char *mx53_can_sel[] = { "ipg", "ckih1", "ckih2", "lp_apm", };
Martin Fuzzey04b41e82013-03-19 17:57:01 +010058static const char *mx53_cko1_sel[] = {
59 "cpu_podf", "pll1_sw", "pll2_sw", "pll3_sw",
60 "emi_slow_podf", "pll4_sw", "nfc_podf", "dummy",
61 "di_pred", "dummy", "dummy", "ahb",
62 "ipg", "per_root", "ckil", "dummy",};
63static const char *mx53_cko2_sel[] = {
64 "dummy"/* dptc_core */, "dummy"/* dptc_perich */,
65 "dummy", "esdhc_a_podf",
66 "usboh3_podf", "dummy"/* wrck_clk_root */,
67 "ecspi_podf", "dummy"/* pll1_ref_clk */,
68 "esdhc_b_podf", "dummy"/* ddr_clk_root */,
69 "dummy"/* arm_axi_clk_root */, "dummy"/* usb_phy_out */,
70 "vpu_sel", "ipu_sel",
71 "osc", "ckih1",
72 "dummy", "esdhc_c_sel",
73 "ssi1_root_podf", "ssi2_root_podf",
74 "dummy", "dummy",
75 "dummy"/* lpsr_clk_root */, "dummy"/* pgc_clk_root */,
76 "dummy"/* tve_out */, "usb_phy_sel",
77 "tve_sel", "lp_apm",
78 "uart_root", "dummy"/* spdif0_clk_root */,
79 "dummy", "dummy", };
Philipp Zabelbeb2d1c2013-05-17 15:49:03 +020080static const char *mx51_spdif_xtal_sel[] = { "osc", "ckih", "ckih2", };
81static const char *mx53_spdif_xtal_sel[] = { "osc", "ckih", "ckih2", "pll4_sw", };
82static const char *spdif_sel[] = { "pll1_sw", "pll2_sw", "pll3_sw", "spdif_xtal_sel", };
83static const char *spdif0_com_sel[] = { "spdif0_podf", "ssi1_root_gate", };
84static const char *mx51_spdif1_com_sel[] = { "spdif1_podf", "ssi2_root_gate", };
85
Sascha Hauerb8d41762012-03-19 12:36:57 +010086
87enum imx5_clks {
88 dummy, ckil, osc, ckih1, ckih2, ahb, ipg, axi_a, axi_b, uart_pred,
89 uart_root, esdhc_a_pred, esdhc_b_pred, esdhc_c_s, esdhc_d_s,
90 emi_sel, emi_slow_podf, nfc_podf, ecspi_pred, ecspi_podf, usboh3_pred,
Philipp Zabeld24de492013-04-08 16:46:22 +020091 usboh3_podf, usb_phy_pred, usb_phy_podf, cpu_podf, di_pred, tve_di_unused,
Sascha Hauerb8d41762012-03-19 12:36:57 +010092 tve_s, uart1_ipg_gate, uart1_per_gate, uart2_ipg_gate,
93 uart2_per_gate, uart3_ipg_gate, uart3_per_gate, i2c1_gate, i2c2_gate,
94 gpt_ipg_gate, pwm1_ipg_gate, pwm1_hf_gate, pwm2_ipg_gate, pwm2_hf_gate,
Alexander Shiyan0f3557c2012-07-12 19:39:30 +040095 gpt_hf_gate, fec_gate, usboh3_per_gate, esdhc1_ipg_gate, esdhc2_ipg_gate,
Sascha Hauerb8d41762012-03-19 12:36:57 +010096 esdhc3_ipg_gate, esdhc4_ipg_gate, ssi1_ipg_gate, ssi2_ipg_gate,
97 ssi3_ipg_gate, ecspi1_ipg_gate, ecspi1_per_gate, ecspi2_ipg_gate,
98 ecspi2_per_gate, cspi_ipg_gate, sdma_gate, emi_slow_gate, ipu_s,
99 ipu_gate, nfc_gate, ipu_di1_gate, vpu_s, vpu_gate,
100 vpu_reference_gate, uart4_ipg_gate, uart4_per_gate, uart5_ipg_gate,
101 uart5_per_gate, tve_gate, tve_pred, esdhc1_per_gate, esdhc2_per_gate,
102 esdhc3_per_gate, esdhc4_per_gate, usb_phy_gate, hsi2c_gate,
103 mipi_hsc1_gate, mipi_hsc2_gate, mipi_esc_gate, mipi_hsp_gate,
104 ldb_di1_div_3_5, ldb_di1_div, ldb_di0_div_3_5, ldb_di0_div,
105 ldb_di1_gate, can2_serial_gate, can2_ipg_gate, i2c3_gate, lp_apm,
106 periph_apm, main_bus, ahb_max, aips_tz1, aips_tz2, tmax1, tmax2,
107 tmax3, spba, uart_sel, esdhc_a_sel, esdhc_b_sel, esdhc_a_podf,
108 esdhc_b_podf, ecspi_sel, usboh3_sel, usb_phy_sel, iim_gate,
109 usboh3_gate, emi_fast_gate, ipu_di0_gate,gpc_dvfs, pll1_sw, pll2_sw,
110 pll3_sw, ipu_di0_sel, ipu_di1_sel, tve_ext_sel, mx51_mipi, pll4_sw,
111 ldb_di1_sel, di_pll4_podf, ldb_di0_sel, ldb_di0_gate, usb_phy1_gate,
112 usb_phy2_gate, per_lp_apm, per_pred1, per_pred2, per_podf, per_root,
Shawn Guo13b3a072012-05-03 20:15:57 +0800113 ssi_apm, ssi1_root_sel, ssi2_root_sel, ssi3_root_sel, ssi_ext1_sel,
114 ssi_ext2_sel, ssi_ext1_com_sel, ssi_ext2_com_sel, ssi1_root_pred,
115 ssi1_root_podf, ssi2_root_pred, ssi2_root_podf, ssi_ext1_pred,
116 ssi_ext1_podf, ssi_ext2_pred, ssi_ext2_podf, ssi1_root_gate,
117 ssi2_root_gate, ssi3_root_gate, ssi_ext1_gate, ssi_ext2_gate,
Alexander Shiyand1e9e0e2012-07-12 19:39:28 +0400118 epit1_ipg_gate, epit1_hf_gate, epit2_ipg_gate, epit2_hf_gate,
Sascha Hauera745f032012-07-17 16:42:49 +0200119 can_sel, can1_serial_gate, can1_ipg_gate,
Philipp Zabel8ecb1672013-03-27 10:51:33 +0100120 owire_gate, gpu3d_s, gpu2d_s, gpu3d_gate, gpu2d_gate, garb_gate,
Martin Fuzzey04b41e82013-03-19 17:57:01 +0100121 cko1_sel, cko1_podf, cko1,
122 cko2_sel, cko2_podf, cko2,
Philipp Zabelbeb2d1c2013-05-17 15:49:03 +0200123 srtc_gate, pata_gate, sata_gate, spdif_xtal_sel, spdif0_sel,
124 spdif1_sel, spdif0_pred, spdif0_podf, spdif1_pred, spdif1_podf,
125 spdif0_com_s, spdif1_com_sel, spdif0_gate, spdif1_gate, spdif_ipg_gate,
Shawn Guoea257a02013-07-23 15:56:29 +0800126 ocram, clk_max
Sascha Hauerb8d41762012-03-19 12:36:57 +0100127};
128
129static struct clk *clk[clk_max];
Fabio Estevamf40f38d2012-11-21 13:43:05 -0200130static struct clk_onecell_data clk_data;
Sascha Hauerb8d41762012-03-19 12:36:57 +0100131
132static void __init mx5_clocks_common_init(unsigned long rate_ckil,
133 unsigned long rate_osc, unsigned long rate_ckih1,
134 unsigned long rate_ckih2)
135{
136 int i;
137
138 clk[dummy] = imx_clk_fixed("dummy", 0);
Martin Fuzzey75f83d02013-04-23 20:16:59 +0800139 clk[ckil] = imx_obtain_fixed_clock("ckil", rate_ckil);
140 clk[osc] = imx_obtain_fixed_clock("osc", rate_osc);
141 clk[ckih1] = imx_obtain_fixed_clock("ckih1", rate_ckih1);
142 clk[ckih2] = imx_obtain_fixed_clock("ckih2", rate_ckih2);
Sascha Hauerb8d41762012-03-19 12:36:57 +0100143
144 clk[lp_apm] = imx_clk_mux("lp_apm", MXC_CCM_CCSR, 9, 1,
145 lp_apm_sel, ARRAY_SIZE(lp_apm_sel));
146 clk[periph_apm] = imx_clk_mux("periph_apm", MXC_CCM_CBCMR, 12, 2,
147 periph_apm_sel, ARRAY_SIZE(periph_apm_sel));
148 clk[main_bus] = imx_clk_mux("main_bus", MXC_CCM_CBCDR, 25, 1,
149 main_bus_sel, ARRAY_SIZE(main_bus_sel));
Sascha Hauerc040be02012-05-16 12:01:40 +0200150 clk[per_lp_apm] = imx_clk_mux("per_lp_apm", MXC_CCM_CBCMR, 1, 1,
Sascha Hauerb8d41762012-03-19 12:36:57 +0100151 per_lp_apm_sel, ARRAY_SIZE(per_lp_apm_sel));
152 clk[per_pred1] = imx_clk_divider("per_pred1", "per_lp_apm", MXC_CCM_CBCDR, 6, 2);
153 clk[per_pred2] = imx_clk_divider("per_pred2", "per_pred1", MXC_CCM_CBCDR, 3, 3);
154 clk[per_podf] = imx_clk_divider("per_podf", "per_pred2", MXC_CCM_CBCDR, 0, 3);
Sascha Hauerc040be02012-05-16 12:01:40 +0200155 clk[per_root] = imx_clk_mux("per_root", MXC_CCM_CBCMR, 0, 1,
Sascha Hauerb8d41762012-03-19 12:36:57 +0100156 per_root_sel, ARRAY_SIZE(per_root_sel));
157 clk[ahb] = imx_clk_divider("ahb", "main_bus", MXC_CCM_CBCDR, 10, 3);
158 clk[ahb_max] = imx_clk_gate2("ahb_max", "ahb", MXC_CCM_CCGR0, 28);
159 clk[aips_tz1] = imx_clk_gate2("aips_tz1", "ahb", MXC_CCM_CCGR0, 24);
160 clk[aips_tz2] = imx_clk_gate2("aips_tz2", "ahb", MXC_CCM_CCGR0, 26);
161 clk[tmax1] = imx_clk_gate2("tmax1", "ahb", MXC_CCM_CCGR1, 0);
162 clk[tmax2] = imx_clk_gate2("tmax2", "ahb", MXC_CCM_CCGR1, 2);
163 clk[tmax3] = imx_clk_gate2("tmax3", "ahb", MXC_CCM_CCGR1, 4);
164 clk[spba] = imx_clk_gate2("spba", "ipg", MXC_CCM_CCGR5, 0);
165 clk[ipg] = imx_clk_divider("ipg", "ahb", MXC_CCM_CBCDR, 8, 2);
166 clk[axi_a] = imx_clk_divider("axi_a", "main_bus", MXC_CCM_CBCDR, 16, 3);
167 clk[axi_b] = imx_clk_divider("axi_b", "main_bus", MXC_CCM_CBCDR, 19, 3);
168 clk[uart_sel] = imx_clk_mux("uart_sel", MXC_CCM_CSCMR1, 24, 2,
169 standard_pll_sel, ARRAY_SIZE(standard_pll_sel));
170 clk[uart_pred] = imx_clk_divider("uart_pred", "uart_sel", MXC_CCM_CSCDR1, 3, 3);
171 clk[uart_root] = imx_clk_divider("uart_root", "uart_pred", MXC_CCM_CSCDR1, 0, 3);
172
173 clk[esdhc_a_sel] = imx_clk_mux("esdhc_a_sel", MXC_CCM_CSCMR1, 20, 2,
174 standard_pll_sel, ARRAY_SIZE(standard_pll_sel));
175 clk[esdhc_b_sel] = imx_clk_mux("esdhc_b_sel", MXC_CCM_CSCMR1, 16, 2,
176 standard_pll_sel, ARRAY_SIZE(standard_pll_sel));
177 clk[esdhc_a_pred] = imx_clk_divider("esdhc_a_pred", "esdhc_a_sel", MXC_CCM_CSCDR1, 16, 3);
178 clk[esdhc_a_podf] = imx_clk_divider("esdhc_a_podf", "esdhc_a_pred", MXC_CCM_CSCDR1, 11, 3);
179 clk[esdhc_b_pred] = imx_clk_divider("esdhc_b_pred", "esdhc_b_sel", MXC_CCM_CSCDR1, 22, 3);
180 clk[esdhc_b_podf] = imx_clk_divider("esdhc_b_podf", "esdhc_b_pred", MXC_CCM_CSCDR1, 19, 3);
181 clk[esdhc_c_s] = imx_clk_mux("esdhc_c_sel", MXC_CCM_CSCMR1, 19, 1, esdhc_c_sel, ARRAY_SIZE(esdhc_c_sel));
182 clk[esdhc_d_s] = imx_clk_mux("esdhc_d_sel", MXC_CCM_CSCMR1, 18, 1, esdhc_d_sel, ARRAY_SIZE(esdhc_d_sel));
183
184 clk[emi_sel] = imx_clk_mux("emi_sel", MXC_CCM_CBCDR, 26, 1,
185 emi_slow_sel, ARRAY_SIZE(emi_slow_sel));
186 clk[emi_slow_podf] = imx_clk_divider("emi_slow_podf", "emi_sel", MXC_CCM_CBCDR, 22, 3);
187 clk[nfc_podf] = imx_clk_divider("nfc_podf", "emi_slow_podf", MXC_CCM_CBCDR, 13, 3);
188 clk[ecspi_sel] = imx_clk_mux("ecspi_sel", MXC_CCM_CSCMR1, 4, 2,
189 standard_pll_sel, ARRAY_SIZE(standard_pll_sel));
190 clk[ecspi_pred] = imx_clk_divider("ecspi_pred", "ecspi_sel", MXC_CCM_CSCDR2, 25, 3);
191 clk[ecspi_podf] = imx_clk_divider("ecspi_podf", "ecspi_pred", MXC_CCM_CSCDR2, 19, 6);
192 clk[usboh3_sel] = imx_clk_mux("usboh3_sel", MXC_CCM_CSCMR1, 22, 2,
193 standard_pll_sel, ARRAY_SIZE(standard_pll_sel));
194 clk[usboh3_pred] = imx_clk_divider("usboh3_pred", "usboh3_sel", MXC_CCM_CSCDR1, 8, 3);
195 clk[usboh3_podf] = imx_clk_divider("usboh3_podf", "usboh3_pred", MXC_CCM_CSCDR1, 6, 2);
196 clk[usb_phy_pred] = imx_clk_divider("usb_phy_pred", "pll3_sw", MXC_CCM_CDCDR, 3, 3);
197 clk[usb_phy_podf] = imx_clk_divider("usb_phy_podf", "usb_phy_pred", MXC_CCM_CDCDR, 0, 3);
198 clk[usb_phy_sel] = imx_clk_mux("usb_phy_sel", MXC_CCM_CSCMR1, 26, 1,
199 usb_phy_sel_str, ARRAY_SIZE(usb_phy_sel_str));
200 clk[cpu_podf] = imx_clk_divider("cpu_podf", "pll1_sw", MXC_CCM_CACRR, 0, 3);
201 clk[di_pred] = imx_clk_divider("di_pred", "pll3_sw", MXC_CCM_CDCDR, 6, 3);
Sascha Hauerb8d41762012-03-19 12:36:57 +0100202 clk[iim_gate] = imx_clk_gate2("iim_gate", "ipg", MXC_CCM_CCGR0, 30);
203 clk[uart1_ipg_gate] = imx_clk_gate2("uart1_ipg_gate", "ipg", MXC_CCM_CCGR1, 6);
204 clk[uart1_per_gate] = imx_clk_gate2("uart1_per_gate", "uart_root", MXC_CCM_CCGR1, 8);
205 clk[uart2_ipg_gate] = imx_clk_gate2("uart2_ipg_gate", "ipg", MXC_CCM_CCGR1, 10);
206 clk[uart2_per_gate] = imx_clk_gate2("uart2_per_gate", "uart_root", MXC_CCM_CCGR1, 12);
207 clk[uart3_ipg_gate] = imx_clk_gate2("uart3_ipg_gate", "ipg", MXC_CCM_CCGR1, 14);
208 clk[uart3_per_gate] = imx_clk_gate2("uart3_per_gate", "uart_root", MXC_CCM_CCGR1, 16);
209 clk[i2c1_gate] = imx_clk_gate2("i2c1_gate", "per_root", MXC_CCM_CCGR1, 18);
210 clk[i2c2_gate] = imx_clk_gate2("i2c2_gate", "per_root", MXC_CCM_CCGR1, 20);
Sascha Hauerb8d41762012-03-19 12:36:57 +0100211 clk[pwm1_ipg_gate] = imx_clk_gate2("pwm1_ipg_gate", "ipg", MXC_CCM_CCGR2, 10);
Alexander Shiyan796b72c2012-07-12 19:39:29 +0400212 clk[pwm1_hf_gate] = imx_clk_gate2("pwm1_hf_gate", "per_root", MXC_CCM_CCGR2, 12);
Sascha Hauerb8d41762012-03-19 12:36:57 +0100213 clk[pwm2_ipg_gate] = imx_clk_gate2("pwm2_ipg_gate", "ipg", MXC_CCM_CCGR2, 14);
Alexander Shiyan796b72c2012-07-12 19:39:29 +0400214 clk[pwm2_hf_gate] = imx_clk_gate2("pwm2_hf_gate", "per_root", MXC_CCM_CCGR2, 16);
Alexander Shiyan0f3557c2012-07-12 19:39:30 +0400215 clk[gpt_ipg_gate] = imx_clk_gate2("gpt_ipg_gate", "ipg", MXC_CCM_CCGR2, 18);
216 clk[gpt_hf_gate] = imx_clk_gate2("gpt_hf_gate", "per_root", MXC_CCM_CCGR2, 20);
Sascha Hauerb8d41762012-03-19 12:36:57 +0100217 clk[fec_gate] = imx_clk_gate2("fec_gate", "ipg", MXC_CCM_CCGR2, 24);
218 clk[usboh3_gate] = imx_clk_gate2("usboh3_gate", "ipg", MXC_CCM_CCGR2, 26);
219 clk[usboh3_per_gate] = imx_clk_gate2("usboh3_per_gate", "usboh3_podf", MXC_CCM_CCGR2, 28);
220 clk[esdhc1_ipg_gate] = imx_clk_gate2("esdhc1_ipg_gate", "ipg", MXC_CCM_CCGR3, 0);
221 clk[esdhc2_ipg_gate] = imx_clk_gate2("esdhc2_ipg_gate", "ipg", MXC_CCM_CCGR3, 4);
222 clk[esdhc3_ipg_gate] = imx_clk_gate2("esdhc3_ipg_gate", "ipg", MXC_CCM_CCGR3, 8);
223 clk[esdhc4_ipg_gate] = imx_clk_gate2("esdhc4_ipg_gate", "ipg", MXC_CCM_CCGR3, 12);
224 clk[ssi1_ipg_gate] = imx_clk_gate2("ssi1_ipg_gate", "ipg", MXC_CCM_CCGR3, 16);
225 clk[ssi2_ipg_gate] = imx_clk_gate2("ssi2_ipg_gate", "ipg", MXC_CCM_CCGR3, 20);
226 clk[ssi3_ipg_gate] = imx_clk_gate2("ssi3_ipg_gate", "ipg", MXC_CCM_CCGR3, 24);
227 clk[ecspi1_ipg_gate] = imx_clk_gate2("ecspi1_ipg_gate", "ipg", MXC_CCM_CCGR4, 18);
228 clk[ecspi1_per_gate] = imx_clk_gate2("ecspi1_per_gate", "ecspi_podf", MXC_CCM_CCGR4, 20);
229 clk[ecspi2_ipg_gate] = imx_clk_gate2("ecspi2_ipg_gate", "ipg", MXC_CCM_CCGR4, 22);
230 clk[ecspi2_per_gate] = imx_clk_gate2("ecspi2_per_gate", "ecspi_podf", MXC_CCM_CCGR4, 24);
231 clk[cspi_ipg_gate] = imx_clk_gate2("cspi_ipg_gate", "ipg", MXC_CCM_CCGR4, 26);
232 clk[sdma_gate] = imx_clk_gate2("sdma_gate", "ipg", MXC_CCM_CCGR4, 30);
233 clk[emi_fast_gate] = imx_clk_gate2("emi_fast_gate", "dummy", MXC_CCM_CCGR5, 14);
234 clk[emi_slow_gate] = imx_clk_gate2("emi_slow_gate", "emi_slow_podf", MXC_CCM_CCGR5, 16);
235 clk[ipu_s] = imx_clk_mux("ipu_sel", MXC_CCM_CBCMR, 6, 2, ipu_sel, ARRAY_SIZE(ipu_sel));
236 clk[ipu_gate] = imx_clk_gate2("ipu_gate", "ipu_sel", MXC_CCM_CCGR5, 10);
237 clk[nfc_gate] = imx_clk_gate2("nfc_gate", "nfc_podf", MXC_CCM_CCGR5, 20);
238 clk[ipu_di0_gate] = imx_clk_gate2("ipu_di0_gate", "ipu_di0_sel", MXC_CCM_CCGR6, 10);
239 clk[ipu_di1_gate] = imx_clk_gate2("ipu_di1_gate", "ipu_di1_sel", MXC_CCM_CCGR6, 12);
Philipp Zabel8ecb1672013-03-27 10:51:33 +0100240 clk[gpu3d_s] = imx_clk_mux("gpu3d_sel", MXC_CCM_CBCMR, 4, 2, gpu3d_sel, ARRAY_SIZE(gpu3d_sel));
241 clk[gpu2d_s] = imx_clk_mux("gpu2d_sel", MXC_CCM_CBCMR, 16, 2, gpu2d_sel, ARRAY_SIZE(gpu2d_sel));
242 clk[gpu3d_gate] = imx_clk_gate2("gpu3d_gate", "gpu3d_sel", MXC_CCM_CCGR5, 2);
243 clk[garb_gate] = imx_clk_gate2("garb_gate", "axi_a", MXC_CCM_CCGR5, 4);
244 clk[gpu2d_gate] = imx_clk_gate2("gpu2d_gate", "gpu2d_sel", MXC_CCM_CCGR6, 14);
Sascha Hauerb8d41762012-03-19 12:36:57 +0100245 clk[vpu_s] = imx_clk_mux("vpu_sel", MXC_CCM_CBCMR, 14, 2, vpu_sel, ARRAY_SIZE(vpu_sel));
246 clk[vpu_gate] = imx_clk_gate2("vpu_gate", "vpu_sel", MXC_CCM_CCGR5, 6);
247 clk[vpu_reference_gate] = imx_clk_gate2("vpu_reference_gate", "osc", MXC_CCM_CCGR5, 8);
248 clk[uart4_ipg_gate] = imx_clk_gate2("uart4_ipg_gate", "ipg", MXC_CCM_CCGR7, 8);
249 clk[uart4_per_gate] = imx_clk_gate2("uart4_per_gate", "uart_root", MXC_CCM_CCGR7, 10);
250 clk[uart5_ipg_gate] = imx_clk_gate2("uart5_ipg_gate", "ipg", MXC_CCM_CCGR7, 12);
251 clk[uart5_per_gate] = imx_clk_gate2("uart5_per_gate", "uart_root", MXC_CCM_CCGR7, 14);
252 clk[gpc_dvfs] = imx_clk_gate2("gpc_dvfs", "dummy", MXC_CCM_CCGR5, 24);
253
Shawn Guo13b3a072012-05-03 20:15:57 +0800254 clk[ssi_apm] = imx_clk_mux("ssi_apm", MXC_CCM_CSCMR1, 8, 2, ssi_apm_sels, ARRAY_SIZE(ssi_apm_sels));
255 clk[ssi1_root_sel] = imx_clk_mux("ssi1_root_sel", MXC_CCM_CSCMR1, 14, 2, ssi_clk_sels, ARRAY_SIZE(ssi_clk_sels));
256 clk[ssi2_root_sel] = imx_clk_mux("ssi2_root_sel", MXC_CCM_CSCMR1, 12, 2, ssi_clk_sels, ARRAY_SIZE(ssi_clk_sels));
257 clk[ssi3_root_sel] = imx_clk_mux("ssi3_root_sel", MXC_CCM_CSCMR1, 11, 1, ssi3_clk_sels, ARRAY_SIZE(ssi3_clk_sels));
258 clk[ssi_ext1_sel] = imx_clk_mux("ssi_ext1_sel", MXC_CCM_CSCMR1, 28, 2, ssi_clk_sels, ARRAY_SIZE(ssi_clk_sels));
259 clk[ssi_ext2_sel] = imx_clk_mux("ssi_ext2_sel", MXC_CCM_CSCMR1, 30, 2, ssi_clk_sels, ARRAY_SIZE(ssi_clk_sels));
260 clk[ssi_ext1_com_sel] = imx_clk_mux("ssi_ext1_com_sel", MXC_CCM_CSCMR1, 0, 1, ssi_ext1_com_sels, ARRAY_SIZE(ssi_ext1_com_sels));
261 clk[ssi_ext2_com_sel] = imx_clk_mux("ssi_ext2_com_sel", MXC_CCM_CSCMR1, 1, 1, ssi_ext2_com_sels, ARRAY_SIZE(ssi_ext2_com_sels));
262 clk[ssi1_root_pred] = imx_clk_divider("ssi1_root_pred", "ssi1_root_sel", MXC_CCM_CS1CDR, 6, 3);
263 clk[ssi1_root_podf] = imx_clk_divider("ssi1_root_podf", "ssi1_root_pred", MXC_CCM_CS1CDR, 0, 6);
264 clk[ssi2_root_pred] = imx_clk_divider("ssi2_root_pred", "ssi2_root_sel", MXC_CCM_CS2CDR, 6, 3);
265 clk[ssi2_root_podf] = imx_clk_divider("ssi2_root_podf", "ssi2_root_pred", MXC_CCM_CS2CDR, 0, 6);
266 clk[ssi_ext1_pred] = imx_clk_divider("ssi_ext1_pred", "ssi_ext1_sel", MXC_CCM_CS1CDR, 22, 3);
267 clk[ssi_ext1_podf] = imx_clk_divider("ssi_ext1_podf", "ssi_ext1_pred", MXC_CCM_CS1CDR, 16, 6);
268 clk[ssi_ext2_pred] = imx_clk_divider("ssi_ext2_pred", "ssi_ext2_sel", MXC_CCM_CS2CDR, 22, 3);
269 clk[ssi_ext2_podf] = imx_clk_divider("ssi_ext2_podf", "ssi_ext2_pred", MXC_CCM_CS2CDR, 16, 6);
270 clk[ssi1_root_gate] = imx_clk_gate2("ssi1_root_gate", "ssi1_root_podf", MXC_CCM_CCGR3, 18);
271 clk[ssi2_root_gate] = imx_clk_gate2("ssi2_root_gate", "ssi2_root_podf", MXC_CCM_CCGR3, 22);
272 clk[ssi3_root_gate] = imx_clk_gate2("ssi3_root_gate", "ssi3_root_sel", MXC_CCM_CCGR3, 26);
273 clk[ssi_ext1_gate] = imx_clk_gate2("ssi_ext1_gate", "ssi_ext1_com_sel", MXC_CCM_CCGR3, 28);
274 clk[ssi_ext2_gate] = imx_clk_gate2("ssi_ext2_gate", "ssi_ext2_com_sel", MXC_CCM_CCGR3, 30);
Alexander Shiyand1e9e0e2012-07-12 19:39:28 +0400275 clk[epit1_ipg_gate] = imx_clk_gate2("epit1_ipg_gate", "ipg", MXC_CCM_CCGR2, 2);
276 clk[epit1_hf_gate] = imx_clk_gate2("epit1_hf_gate", "per_root", MXC_CCM_CCGR2, 4);
277 clk[epit2_ipg_gate] = imx_clk_gate2("epit2_ipg_gate", "ipg", MXC_CCM_CCGR2, 6);
278 clk[epit2_hf_gate] = imx_clk_gate2("epit2_hf_gate", "per_root", MXC_CCM_CCGR2, 8);
Martin Fuzzeyf1550a12013-01-29 16:46:12 +0100279 clk[owire_gate] = imx_clk_gate2("owire_gate", "per_root", MXC_CCM_CCGR2, 22);
Sascha Hauer5d530bb2013-04-04 11:25:08 +0200280 clk[srtc_gate] = imx_clk_gate2("srtc_gate", "per_root", MXC_CCM_CCGR4, 28);
281 clk[pata_gate] = imx_clk_gate2("pata_gate", "ipg", MXC_CCM_CCGR4, 0);
Philipp Zabelbeb2d1c2013-05-17 15:49:03 +0200282 clk[spdif0_sel] = imx_clk_mux("spdif0_sel", MXC_CCM_CSCMR2, 0, 2, spdif_sel, ARRAY_SIZE(spdif_sel));
283 clk[spdif0_pred] = imx_clk_divider("spdif0_pred", "spdif0_sel", MXC_CCM_CDCDR, 25, 3);
284 clk[spdif0_podf] = imx_clk_divider("spdif0_podf", "spdif0_pred", MXC_CCM_CDCDR, 19, 6);
285 clk[spdif0_com_s] = imx_clk_mux_flags("spdif0_com_sel", MXC_CCM_CSCMR2, 4, 1,
286 spdif0_com_sel, ARRAY_SIZE(spdif0_com_sel), CLK_SET_RATE_PARENT);
287 clk[spdif0_gate] = imx_clk_gate2("spdif0_gate", "spdif0_com_sel", MXC_CCM_CCGR5, 26);
288 clk[spdif_ipg_gate] = imx_clk_gate2("spdif_ipg_gate", "ipg", MXC_CCM_CCGR5, 30);
Shawn Guo13b3a072012-05-03 20:15:57 +0800289
Sascha Hauerb8d41762012-03-19 12:36:57 +0100290 for (i = 0; i < ARRAY_SIZE(clk); i++)
291 if (IS_ERR(clk[i]))
292 pr_err("i.MX5 clk %d: register failed with %ld\n",
293 i, PTR_ERR(clk[i]));
Martin Fuzzeyf1550a12013-01-29 16:46:12 +0100294
Alexander Shiyan0f3557c2012-07-12 19:39:30 +0400295 clk_register_clkdev(clk[gpt_hf_gate], "per", "imx-gpt.0");
Sascha Hauerb8d41762012-03-19 12:36:57 +0100296 clk_register_clkdev(clk[gpt_ipg_gate], "ipg", "imx-gpt.0");
297 clk_register_clkdev(clk[uart1_per_gate], "per", "imx21-uart.0");
298 clk_register_clkdev(clk[uart1_ipg_gate], "ipg", "imx21-uart.0");
299 clk_register_clkdev(clk[uart2_per_gate], "per", "imx21-uart.1");
300 clk_register_clkdev(clk[uart2_ipg_gate], "ipg", "imx21-uart.1");
301 clk_register_clkdev(clk[uart3_per_gate], "per", "imx21-uart.2");
302 clk_register_clkdev(clk[uart3_ipg_gate], "ipg", "imx21-uart.2");
303 clk_register_clkdev(clk[uart4_per_gate], "per", "imx21-uart.3");
304 clk_register_clkdev(clk[uart4_ipg_gate], "ipg", "imx21-uart.3");
305 clk_register_clkdev(clk[uart5_per_gate], "per", "imx21-uart.4");
306 clk_register_clkdev(clk[uart5_ipg_gate], "ipg", "imx21-uart.4");
307 clk_register_clkdev(clk[ecspi1_per_gate], "per", "imx51-ecspi.0");
308 clk_register_clkdev(clk[ecspi1_ipg_gate], "ipg", "imx51-ecspi.0");
309 clk_register_clkdev(clk[ecspi2_per_gate], "per", "imx51-ecspi.1");
310 clk_register_clkdev(clk[ecspi2_ipg_gate], "ipg", "imx51-ecspi.1");
Alexander Shiyane0c29dc2012-07-12 19:39:31 +0400311 clk_register_clkdev(clk[cspi_ipg_gate], NULL, "imx35-cspi.2");
Sascha Hauerb8d41762012-03-19 12:36:57 +0100312 clk_register_clkdev(clk[pwm1_ipg_gate], "pwm", "mxc_pwm.0");
313 clk_register_clkdev(clk[pwm2_ipg_gate], "pwm", "mxc_pwm.1");
Shawn Guo5bdfba22012-09-14 15:19:00 +0800314 clk_register_clkdev(clk[i2c1_gate], NULL, "imx21-i2c.0");
315 clk_register_clkdev(clk[i2c2_gate], NULL, "imx21-i2c.1");
Sascha Hauerb8d41762012-03-19 12:36:57 +0100316 clk_register_clkdev(clk[usboh3_per_gate], "per", "mxc-ehci.0");
317 clk_register_clkdev(clk[usboh3_gate], "ipg", "mxc-ehci.0");
318 clk_register_clkdev(clk[usboh3_gate], "ahb", "mxc-ehci.0");
319 clk_register_clkdev(clk[usboh3_per_gate], "per", "mxc-ehci.1");
320 clk_register_clkdev(clk[usboh3_gate], "ipg", "mxc-ehci.1");
321 clk_register_clkdev(clk[usboh3_gate], "ahb", "mxc-ehci.1");
322 clk_register_clkdev(clk[usboh3_per_gate], "per", "mxc-ehci.2");
323 clk_register_clkdev(clk[usboh3_gate], "ipg", "mxc-ehci.2");
324 clk_register_clkdev(clk[usboh3_gate], "ahb", "mxc-ehci.2");
Peter Chen61c4b562013-01-17 18:03:17 +0800325 clk_register_clkdev(clk[usboh3_per_gate], "per", "imx-udc-mx51");
326 clk_register_clkdev(clk[usboh3_gate], "ipg", "imx-udc-mx51");
327 clk_register_clkdev(clk[usboh3_gate], "ahb", "imx-udc-mx51");
Shawn Guo4d624352012-09-15 13:34:09 +0800328 clk_register_clkdev(clk[nfc_gate], NULL, "imx51-nand");
Sascha Hauerb8d41762012-03-19 12:36:57 +0100329 clk_register_clkdev(clk[ssi1_ipg_gate], NULL, "imx-ssi.0");
330 clk_register_clkdev(clk[ssi2_ipg_gate], NULL, "imx-ssi.1");
331 clk_register_clkdev(clk[ssi3_ipg_gate], NULL, "imx-ssi.2");
332 clk_register_clkdev(clk[sdma_gate], NULL, "imx35-sdma");
Sudeep KarkadaNagesha3d10a882013-09-10 18:59:48 +0100333 clk_register_clkdev(clk[cpu_podf], NULL, "cpu0");
Sascha Hauerb8d41762012-03-19 12:36:57 +0100334 clk_register_clkdev(clk[iim_gate], "iim", NULL);
335 clk_register_clkdev(clk[dummy], NULL, "imx2-wdt.0");
336 clk_register_clkdev(clk[dummy], NULL, "imx2-wdt.1");
337 clk_register_clkdev(clk[dummy], NULL, "imx-keypad");
Sascha Hauerb8d41762012-03-19 12:36:57 +0100338 clk_register_clkdev(clk[ipu_di1_gate], "di1", "imx-tve.0");
Robert Leeaa96a182012-05-21 17:50:27 -0500339 clk_register_clkdev(clk[gpc_dvfs], "gpc_dvfs", NULL);
Alexander Shiyand1e9e0e2012-07-12 19:39:28 +0400340 clk_register_clkdev(clk[epit1_ipg_gate], "ipg", "imx-epit.0");
341 clk_register_clkdev(clk[epit1_hf_gate], "per", "imx-epit.0");
342 clk_register_clkdev(clk[epit2_ipg_gate], "ipg", "imx-epit.1");
343 clk_register_clkdev(clk[epit2_hf_gate], "per", "imx-epit.1");
Sascha Hauerb8d41762012-03-19 12:36:57 +0100344
345 /* Set SDHC parents to be PLL2 */
346 clk_set_parent(clk[esdhc_a_sel], clk[pll2_sw]);
347 clk_set_parent(clk[esdhc_b_sel], clk[pll2_sw]);
348
349 /* move usb phy clk to 24MHz */
350 clk_set_parent(clk[usb_phy_sel], clk[osc]);
351
352 clk_prepare_enable(clk[gpc_dvfs]);
353 clk_prepare_enable(clk[ahb_max]); /* esdhc3 */
354 clk_prepare_enable(clk[aips_tz1]);
355 clk_prepare_enable(clk[aips_tz2]); /* fec */
356 clk_prepare_enable(clk[spba]);
357 clk_prepare_enable(clk[emi_fast_gate]); /* fec */
Shawn Guo68b05622012-08-02 22:28:49 +0800358 clk_prepare_enable(clk[emi_slow_gate]); /* eim */
Sascha Hauer9a2d4822012-06-05 13:53:32 +0200359 clk_prepare_enable(clk[mipi_hsc1_gate]);
360 clk_prepare_enable(clk[mipi_hsc2_gate]);
361 clk_prepare_enable(clk[mipi_esc_gate]);
362 clk_prepare_enable(clk[mipi_hsp_gate]);
Sascha Hauerb8d41762012-03-19 12:36:57 +0100363 clk_prepare_enable(clk[tmax1]);
364 clk_prepare_enable(clk[tmax2]); /* esdhc2, fec */
365 clk_prepare_enable(clk[tmax3]); /* esdhc1, esdhc4 */
366}
367
368int __init mx51_clocks_init(unsigned long rate_ckil, unsigned long rate_osc,
369 unsigned long rate_ckih1, unsigned long rate_ckih2)
370{
371 int i;
Sascha Hauer69155fd2012-12-11 10:08:50 +0100372 u32 val;
Fabio Estevamf40f38d2012-11-21 13:43:05 -0200373 struct device_node *np;
Sascha Hauerb8d41762012-03-19 12:36:57 +0100374
375 clk[pll1_sw] = imx_clk_pllv2("pll1_sw", "osc", MX51_DPLL1_BASE);
376 clk[pll2_sw] = imx_clk_pllv2("pll2_sw", "osc", MX51_DPLL2_BASE);
377 clk[pll3_sw] = imx_clk_pllv2("pll3_sw", "osc", MX51_DPLL3_BASE);
378 clk[ipu_di0_sel] = imx_clk_mux("ipu_di0_sel", MXC_CCM_CSCMR2, 26, 3,
379 mx51_ipu_di0_sel, ARRAY_SIZE(mx51_ipu_di0_sel));
380 clk[ipu_di1_sel] = imx_clk_mux("ipu_di1_sel", MXC_CCM_CSCMR2, 29, 3,
381 mx51_ipu_di1_sel, ARRAY_SIZE(mx51_ipu_di1_sel));
Philipp Zabel80f72d22013-04-08 16:46:23 +0200382 clk[tve_ext_sel] = imx_clk_mux_flags("tve_ext_sel", MXC_CCM_CSCMR1, 6, 1,
383 mx51_tve_ext_sel, ARRAY_SIZE(mx51_tve_ext_sel), CLK_SET_RATE_PARENT);
Philipp Zabel3f487be2013-04-08 16:46:19 +0200384 clk[tve_s] = imx_clk_mux("tve_sel", MXC_CCM_CSCMR1, 7, 1,
385 mx51_tve_sel, ARRAY_SIZE(mx51_tve_sel));
Sascha Hauerb8d41762012-03-19 12:36:57 +0100386 clk[tve_gate] = imx_clk_gate2("tve_gate", "tve_sel", MXC_CCM_CCGR2, 30);
387 clk[tve_pred] = imx_clk_divider("tve_pred", "pll3_sw", MXC_CCM_CDCDR, 28, 3);
388 clk[esdhc1_per_gate] = imx_clk_gate2("esdhc1_per_gate", "esdhc_a_podf", MXC_CCM_CCGR3, 2);
389 clk[esdhc2_per_gate] = imx_clk_gate2("esdhc2_per_gate", "esdhc_b_podf", MXC_CCM_CCGR3, 6);
390 clk[esdhc3_per_gate] = imx_clk_gate2("esdhc3_per_gate", "esdhc_c_sel", MXC_CCM_CCGR3, 10);
391 clk[esdhc4_per_gate] = imx_clk_gate2("esdhc4_per_gate", "esdhc_d_sel", MXC_CCM_CCGR3, 14);
392 clk[usb_phy_gate] = imx_clk_gate2("usb_phy_gate", "usb_phy_sel", MXC_CCM_CCGR2, 0);
393 clk[hsi2c_gate] = imx_clk_gate2("hsi2c_gate", "ipg", MXC_CCM_CCGR1, 22);
394 clk[mipi_hsc1_gate] = imx_clk_gate2("mipi_hsc1_gate", "ipg", MXC_CCM_CCGR4, 6);
395 clk[mipi_hsc2_gate] = imx_clk_gate2("mipi_hsc2_gate", "ipg", MXC_CCM_CCGR4, 8);
396 clk[mipi_esc_gate] = imx_clk_gate2("mipi_esc_gate", "ipg", MXC_CCM_CCGR4, 10);
397 clk[mipi_hsp_gate] = imx_clk_gate2("mipi_hsp_gate", "ipg", MXC_CCM_CCGR4, 12);
Philipp Zabelbeb2d1c2013-05-17 15:49:03 +0200398 clk[spdif_xtal_sel] = imx_clk_mux("spdif_xtal_sel", MXC_CCM_CSCMR1, 2, 2,
399 mx51_spdif_xtal_sel, ARRAY_SIZE(mx51_spdif_xtal_sel));
400 clk[spdif1_sel] = imx_clk_mux("spdif1_sel", MXC_CCM_CSCMR2, 2, 2,
401 spdif_sel, ARRAY_SIZE(spdif_sel));
Fabio Estevam5d5248a2013-09-05 16:02:57 -0300402 clk[spdif1_pred] = imx_clk_divider("spdif1_pred", "spdif1_sel", MXC_CCM_CDCDR, 16, 3);
Philipp Zabelbeb2d1c2013-05-17 15:49:03 +0200403 clk[spdif1_podf] = imx_clk_divider("spdif1_podf", "spdif1_pred", MXC_CCM_CDCDR, 9, 6);
404 clk[spdif1_com_sel] = imx_clk_mux("spdif1_com_sel", MXC_CCM_CSCMR2, 5, 1,
405 mx51_spdif1_com_sel, ARRAY_SIZE(mx51_spdif1_com_sel));
406 clk[spdif1_gate] = imx_clk_gate2("spdif1_gate", "spdif1_com_sel", MXC_CCM_CCGR5, 28);
Sascha Hauerb8d41762012-03-19 12:36:57 +0100407
408 for (i = 0; i < ARRAY_SIZE(clk); i++)
409 if (IS_ERR(clk[i]))
410 pr_err("i.MX51 clk %d: register failed with %ld\n",
411 i, PTR_ERR(clk[i]));
412
Fabio Estevamf40f38d2012-11-21 13:43:05 -0200413 np = of_find_compatible_node(NULL, NULL, "fsl,imx51-ccm");
414 clk_data.clks = clk;
415 clk_data.clk_num = ARRAY_SIZE(clk);
416 of_clk_add_provider(np, of_clk_src_onecell_get, &clk_data);
417
Sascha Hauerb8d41762012-03-19 12:36:57 +0100418 mx5_clocks_common_init(rate_ckil, rate_osc, rate_ckih1, rate_ckih2);
419
Shawn Guo5bdfba22012-09-14 15:19:00 +0800420 clk_register_clkdev(clk[hsi2c_gate], NULL, "imx21-i2c.2");
Sascha Hauerb8d41762012-03-19 12:36:57 +0100421 clk_register_clkdev(clk[mx51_mipi], "mipi_hsp", NULL);
422 clk_register_clkdev(clk[vpu_gate], NULL, "imx51-vpu.0");
423 clk_register_clkdev(clk[fec_gate], NULL, "imx27-fec.0");
Sascha Hauerb8d41762012-03-19 12:36:57 +0100424 clk_register_clkdev(clk[usb_phy_gate], "phy", "mxc-ehci.0");
425 clk_register_clkdev(clk[esdhc1_ipg_gate], "ipg", "sdhci-esdhc-imx51.0");
426 clk_register_clkdev(clk[dummy], "ahb", "sdhci-esdhc-imx51.0");
427 clk_register_clkdev(clk[esdhc1_per_gate], "per", "sdhci-esdhc-imx51.0");
428 clk_register_clkdev(clk[esdhc2_ipg_gate], "ipg", "sdhci-esdhc-imx51.1");
429 clk_register_clkdev(clk[dummy], "ahb", "sdhci-esdhc-imx51.1");
430 clk_register_clkdev(clk[esdhc2_per_gate], "per", "sdhci-esdhc-imx51.1");
431 clk_register_clkdev(clk[esdhc3_ipg_gate], "ipg", "sdhci-esdhc-imx51.2");
432 clk_register_clkdev(clk[dummy], "ahb", "sdhci-esdhc-imx51.2");
433 clk_register_clkdev(clk[esdhc3_per_gate], "per", "sdhci-esdhc-imx51.2");
434 clk_register_clkdev(clk[esdhc4_ipg_gate], "ipg", "sdhci-esdhc-imx51.3");
435 clk_register_clkdev(clk[dummy], "ahb", "sdhci-esdhc-imx51.3");
436 clk_register_clkdev(clk[esdhc4_per_gate], "per", "sdhci-esdhc-imx51.3");
437
438 /* set the usboh3 parent to pll2_sw */
439 clk_set_parent(clk[usboh3_sel], clk[pll2_sw]);
440
441 /* set SDHC root clock to 166.25MHZ*/
442 clk_set_rate(clk[esdhc_a_podf], 166250000);
443 clk_set_rate(clk[esdhc_b_podf], 166250000);
444
445 /* System timer */
Sascha Hauer2cfb4512012-05-16 12:29:53 +0200446 mxc_timer_init(MX51_IO_ADDRESS(MX51_GPT1_BASE_ADDR), MX51_INT_GPT);
Sascha Hauerb8d41762012-03-19 12:36:57 +0100447
448 clk_prepare_enable(clk[iim_gate]);
449 imx_print_silicon_rev("i.MX51", mx51_revision());
450 clk_disable_unprepare(clk[iim_gate]);
451
Sascha Hauer69155fd2012-12-11 10:08:50 +0100452 /*
453 * Reference Manual says: Functionality of CCDR[18] and CLPCR[23] is no
454 * longer supported. Set to one for better power saving.
455 *
456 * The effect of not setting these bits is that MIPI clocks can't be
457 * enabled without the IPU clock being enabled aswell.
458 */
459 val = readl(MXC_CCM_CCDR);
460 val |= 1 << 18;
461 writel(val, MXC_CCM_CCDR);
462
463 val = readl(MXC_CCM_CLPCR);
464 val |= 1 << 23;
465 writel(val, MXC_CCM_CLPCR);
466
Sascha Hauerb8d41762012-03-19 12:36:57 +0100467 return 0;
468}
469
Sebastian Hesselbarth4d9d18a2013-08-27 14:50:00 +0200470static void __init mx51_clocks_init_dt(struct device_node *np)
471{
472 mx51_clocks_init(0, 0, 0, 0);
473}
474CLK_OF_DECLARE(imx51_ccm, "fsl,imx51-ccm", mx51_clocks_init_dt);
475
476static void __init mx53_clocks_init(struct device_node *np)
Sascha Hauerb8d41762012-03-19 12:36:57 +0100477{
Fabio Estevambfcc7bc2013-10-01 00:21:12 -0300478 int i, irq;
Sascha Hauerb8d41762012-03-19 12:36:57 +0100479 unsigned long r;
Fabio Estevambfcc7bc2013-10-01 00:21:12 -0300480 void __iomem *base;
Sascha Hauerb8d41762012-03-19 12:36:57 +0100481
482 clk[pll1_sw] = imx_clk_pllv2("pll1_sw", "osc", MX53_DPLL1_BASE);
483 clk[pll2_sw] = imx_clk_pllv2("pll2_sw", "osc", MX53_DPLL2_BASE);
484 clk[pll3_sw] = imx_clk_pllv2("pll3_sw", "osc", MX53_DPLL3_BASE);
485 clk[pll4_sw] = imx_clk_pllv2("pll4_sw", "osc", MX53_DPLL4_BASE);
486
Sascha Hauerb8d41762012-03-19 12:36:57 +0100487 clk[ldb_di1_div_3_5] = imx_clk_fixed_factor("ldb_di1_div_3_5", "ldb_di1_sel", 2, 7);
Philipp Zabelcc7b6332013-03-27 18:30:41 +0100488 clk[ldb_di1_div] = imx_clk_divider_flags("ldb_di1_div", "ldb_di1_div_3_5", MXC_CCM_CSCMR2, 11, 1, 0);
489 clk[ldb_di1_sel] = imx_clk_mux_flags("ldb_di1_sel", MXC_CCM_CSCMR2, 9, 1,
490 mx53_ldb_di1_sel, ARRAY_SIZE(mx53_ldb_di1_sel), CLK_SET_RATE_PARENT);
Sascha Hauerb8d41762012-03-19 12:36:57 +0100491 clk[di_pll4_podf] = imx_clk_divider("di_pll4_podf", "pll4_sw", MXC_CCM_CDCDR, 16, 3);
Sascha Hauerb8d41762012-03-19 12:36:57 +0100492 clk[ldb_di0_div_3_5] = imx_clk_fixed_factor("ldb_di0_div_3_5", "ldb_di0_sel", 2, 7);
Philipp Zabelcc7b6332013-03-27 18:30:41 +0100493 clk[ldb_di0_div] = imx_clk_divider_flags("ldb_di0_div", "ldb_di0_div_3_5", MXC_CCM_CSCMR2, 10, 1, 0);
494 clk[ldb_di0_sel] = imx_clk_mux_flags("ldb_di0_sel", MXC_CCM_CSCMR2, 8, 1,
495 mx53_ldb_di0_sel, ARRAY_SIZE(mx53_ldb_di0_sel), CLK_SET_RATE_PARENT);
Sascha Hauerb8d41762012-03-19 12:36:57 +0100496 clk[ldb_di0_gate] = imx_clk_gate2("ldb_di0_gate", "ldb_di0_div", MXC_CCM_CCGR6, 28);
497 clk[ldb_di1_gate] = imx_clk_gate2("ldb_di1_gate", "ldb_di1_div", MXC_CCM_CCGR6, 30);
498 clk[ipu_di0_sel] = imx_clk_mux("ipu_di0_sel", MXC_CCM_CSCMR2, 26, 3,
499 mx53_ipu_di0_sel, ARRAY_SIZE(mx53_ipu_di0_sel));
500 clk[ipu_di1_sel] = imx_clk_mux("ipu_di1_sel", MXC_CCM_CSCMR2, 29, 3,
501 mx53_ipu_di1_sel, ARRAY_SIZE(mx53_ipu_di1_sel));
Philipp Zabelf550e702013-04-08 16:46:21 +0200502 clk[tve_ext_sel] = imx_clk_mux_flags("tve_ext_sel", MXC_CCM_CSCMR1, 6, 1,
503 mx53_tve_ext_sel, ARRAY_SIZE(mx53_tve_ext_sel), CLK_SET_RATE_PARENT);
Sascha Hauerb8d41762012-03-19 12:36:57 +0100504 clk[tve_gate] = imx_clk_gate2("tve_gate", "tve_pred", MXC_CCM_CCGR2, 30);
505 clk[tve_pred] = imx_clk_divider("tve_pred", "tve_ext_sel", MXC_CCM_CDCDR, 28, 3);
506 clk[esdhc1_per_gate] = imx_clk_gate2("esdhc1_per_gate", "esdhc_a_podf", MXC_CCM_CCGR3, 2);
507 clk[esdhc2_per_gate] = imx_clk_gate2("esdhc2_per_gate", "esdhc_c_sel", MXC_CCM_CCGR3, 6);
508 clk[esdhc3_per_gate] = imx_clk_gate2("esdhc3_per_gate", "esdhc_b_podf", MXC_CCM_CCGR3, 10);
509 clk[esdhc4_per_gate] = imx_clk_gate2("esdhc4_per_gate", "esdhc_d_sel", MXC_CCM_CCGR3, 14);
510 clk[usb_phy1_gate] = imx_clk_gate2("usb_phy1_gate", "usb_phy_sel", MXC_CCM_CCGR4, 10);
511 clk[usb_phy2_gate] = imx_clk_gate2("usb_phy2_gate", "usb_phy_sel", MXC_CCM_CCGR4, 12);
Sascha Hauera745f032012-07-17 16:42:49 +0200512 clk[can_sel] = imx_clk_mux("can_sel", MXC_CCM_CSCMR2, 6, 2,
513 mx53_can_sel, ARRAY_SIZE(mx53_can_sel));
514 clk[can1_serial_gate] = imx_clk_gate2("can1_serial_gate", "can_sel", MXC_CCM_CCGR6, 22);
515 clk[can1_ipg_gate] = imx_clk_gate2("can1_ipg_gate", "ipg", MXC_CCM_CCGR6, 20);
Shawn Guoea257a02013-07-23 15:56:29 +0800516 clk[ocram] = imx_clk_gate2("ocram", "ahb", MXC_CCM_CCGR6, 2);
Sascha Hauera745f032012-07-17 16:42:49 +0200517 clk[can2_serial_gate] = imx_clk_gate2("can2_serial_gate", "can_sel", MXC_CCM_CCGR4, 8);
518 clk[can2_ipg_gate] = imx_clk_gate2("can2_ipg_gate", "ipg", MXC_CCM_CCGR4, 6);
Sascha Hauerb8d41762012-03-19 12:36:57 +0100519 clk[i2c3_gate] = imx_clk_gate2("i2c3_gate", "per_root", MXC_CCM_CCGR1, 22);
Sascha Hauerc9a74f52013-05-17 15:49:02 +0200520 clk[sata_gate] = imx_clk_gate2("sata_gate", "ipg", MXC_CCM_CCGR4, 2);
Sascha Hauerb8d41762012-03-19 12:36:57 +0100521
Martin Fuzzey04b41e82013-03-19 17:57:01 +0100522 clk[cko1_sel] = imx_clk_mux("cko1_sel", MXC_CCM_CCOSR, 0, 4,
523 mx53_cko1_sel, ARRAY_SIZE(mx53_cko1_sel));
524 clk[cko1_podf] = imx_clk_divider("cko1_podf", "cko1_sel", MXC_CCM_CCOSR, 4, 3);
525 clk[cko1] = imx_clk_gate2("cko1", "cko1_podf", MXC_CCM_CCOSR, 7);
526
527 clk[cko2_sel] = imx_clk_mux("cko2_sel", MXC_CCM_CCOSR, 16, 5,
528 mx53_cko2_sel, ARRAY_SIZE(mx53_cko2_sel));
529 clk[cko2_podf] = imx_clk_divider("cko2_podf", "cko2_sel", MXC_CCM_CCOSR, 21, 3);
530 clk[cko2] = imx_clk_gate2("cko2", "cko2_podf", MXC_CCM_CCOSR, 24);
Philipp Zabelbeb2d1c2013-05-17 15:49:03 +0200531 clk[spdif_xtal_sel] = imx_clk_mux("spdif_xtal_sel", MXC_CCM_CSCMR1, 2, 2,
532 mx53_spdif_xtal_sel, ARRAY_SIZE(mx53_spdif_xtal_sel));
Martin Fuzzey04b41e82013-03-19 17:57:01 +0100533
Sascha Hauerb8d41762012-03-19 12:36:57 +0100534 for (i = 0; i < ARRAY_SIZE(clk); i++)
535 if (IS_ERR(clk[i]))
536 pr_err("i.MX53 clk %d: register failed with %ld\n",
537 i, PTR_ERR(clk[i]));
538
Fabio Estevamf40f38d2012-11-21 13:43:05 -0200539 clk_data.clks = clk;
540 clk_data.clk_num = ARRAY_SIZE(clk);
541 of_clk_add_provider(np, of_clk_src_onecell_get, &clk_data);
542
Sebastian Hesselbarth4d9d18a2013-08-27 14:50:00 +0200543 mx5_clocks_common_init(0, 0, 0, 0);
Sascha Hauerb8d41762012-03-19 12:36:57 +0100544
545 clk_register_clkdev(clk[vpu_gate], NULL, "imx53-vpu.0");
Shawn Guo5bdfba22012-09-14 15:19:00 +0800546 clk_register_clkdev(clk[i2c3_gate], NULL, "imx21-i2c.2");
Sascha Hauerb8d41762012-03-19 12:36:57 +0100547 clk_register_clkdev(clk[fec_gate], NULL, "imx25-fec.0");
Sascha Hauerb8d41762012-03-19 12:36:57 +0100548 clk_register_clkdev(clk[usb_phy1_gate], "usb_phy1", "mxc-ehci.0");
549 clk_register_clkdev(clk[esdhc1_ipg_gate], "ipg", "sdhci-esdhc-imx53.0");
550 clk_register_clkdev(clk[dummy], "ahb", "sdhci-esdhc-imx53.0");
551 clk_register_clkdev(clk[esdhc1_per_gate], "per", "sdhci-esdhc-imx53.0");
552 clk_register_clkdev(clk[esdhc2_ipg_gate], "ipg", "sdhci-esdhc-imx53.1");
553 clk_register_clkdev(clk[dummy], "ahb", "sdhci-esdhc-imx53.1");
554 clk_register_clkdev(clk[esdhc2_per_gate], "per", "sdhci-esdhc-imx53.1");
555 clk_register_clkdev(clk[esdhc3_ipg_gate], "ipg", "sdhci-esdhc-imx53.2");
556 clk_register_clkdev(clk[dummy], "ahb", "sdhci-esdhc-imx53.2");
557 clk_register_clkdev(clk[esdhc3_per_gate], "per", "sdhci-esdhc-imx53.2");
558 clk_register_clkdev(clk[esdhc4_ipg_gate], "ipg", "sdhci-esdhc-imx53.3");
559 clk_register_clkdev(clk[dummy], "ahb", "sdhci-esdhc-imx53.3");
560 clk_register_clkdev(clk[esdhc4_per_gate], "per", "sdhci-esdhc-imx53.3");
Sascha Hauerb8d41762012-03-19 12:36:57 +0100561
562 /* set SDHC root clock to 200MHZ*/
563 clk_set_rate(clk[esdhc_a_podf], 200000000);
564 clk_set_rate(clk[esdhc_b_podf], 200000000);
565
Sascha Hauerb8d41762012-03-19 12:36:57 +0100566 clk_prepare_enable(clk[iim_gate]);
567 imx_print_silicon_rev("i.MX53", mx53_revision());
568 clk_disable_unprepare(clk[iim_gate]);
569
570 r = clk_round_rate(clk[usboh3_per_gate], 54000000);
571 clk_set_rate(clk[usboh3_per_gate], r);
Fabio Estevambfcc7bc2013-10-01 00:21:12 -0300572
573 np = of_find_compatible_node(NULL, NULL, "fsl,imx53-gpt");
574 base = of_iomap(np, 0);
575 WARN_ON(!base);
576 irq = irq_of_parse_and_map(np, 0);
577 mxc_timer_init(base, irq);
Sascha Hauerb8d41762012-03-19 12:36:57 +0100578}
Sebastian Hesselbarth4d9d18a2013-08-27 14:50:00 +0200579CLK_OF_DECLARE(imx53_ccm, "fsl,imx53-ccm", mx53_clocks_init);