blob: dba987e3b89f687c6b48488b385dd781e4122b37 [file] [log] [blame]
Sascha Hauer93421e42012-03-09 09:11:39 +01001/*
2 * Copyright 2004-2007 Freescale Semiconductor, Inc. All Rights Reserved.
3 * Copyright 2008 Juergen Beisert, kernel@pengutronix.de
4 * Copyright 2008 Martin Fuzzey, mfuzzey@gmail.com
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
Sascha Hauer93421e42012-03-09 09:11:39 +010010 */
11
12#include <linux/clk.h>
Sascha Hauer93421e42012-03-09 09:11:39 +010013#include <linux/clk-provider.h>
Alexander Shiyan548694b2014-06-22 17:17:08 +040014#include <linux/clkdev.h>
Alexander Shiyan35bcaf02014-06-22 17:17:09 +040015#include <linux/of.h>
16#include <linux/of_address.h>
17#include <dt-bindings/clock/imx21-clock.h>
Shawn Guo0931aff2015-05-15 11:41:39 +080018#include <soc/imx/timer.h>
Shawn Guo0c831312015-04-25 18:43:45 +080019#include <asm/irq.h>
Sascha Hauer93421e42012-03-09 09:11:39 +010020
Sascha Hauer93421e42012-03-09 09:11:39 +010021#include "clk.h"
Shawn Guo0c831312015-04-25 18:43:45 +080022
23#define MX21_CCM_BASE_ADDR 0x10027000
24#define MX21_GPT1_BASE_ADDR 0x10003000
25#define MX21_INT_GPT1 (NR_IRQS_LEGACY + 26)
Sascha Hauer93421e42012-03-09 09:11:39 +010026
Alexander Shiyan35bcaf02014-06-22 17:17:09 +040027static void __iomem *ccm __initdata;
Sascha Hauer93421e42012-03-09 09:11:39 +010028
29/* Register offsets */
Alexander Shiyan35bcaf02014-06-22 17:17:09 +040030#define CCM_CSCR (ccm + 0x00)
31#define CCM_MPCTL0 (ccm + 0x04)
32#define CCM_SPCTL0 (ccm + 0x0c)
33#define CCM_PCDR0 (ccm + 0x18)
34#define CCM_PCDR1 (ccm + 0x1c)
35#define CCM_PCCR0 (ccm + 0x20)
36#define CCM_PCCR1 (ccm + 0x24)
Sascha Hauer93421e42012-03-09 09:11:39 +010037
Alexander Shiyan65251692014-06-22 17:17:06 +040038static const char *mpll_osc_sel_clks[] = { "ckih_gate", "ckih_div1p5", };
39static const char *mpll_sel_clks[] = { "fpm_gate", "mpll_osc_sel", };
40static const char *spll_sel_clks[] = { "fpm_gate", "mpll_osc_sel", };
41static const char *ssi_sel_clks[] = { "spll_gate", "mpll_gate", };
Sascha Hauer93421e42012-03-09 09:11:39 +010042
Alexander Shiyan35bcaf02014-06-22 17:17:09 +040043static struct clk *clk[IMX21_CLK_MAX];
44static struct clk_onecell_data clk_data;
Sascha Hauer93421e42012-03-09 09:11:39 +010045
Alexander Shiyan35bcaf02014-06-22 17:17:09 +040046static void __init _mx21_clocks_init(unsigned long lref, unsigned long href)
47{
48 BUG_ON(!ccm);
49
50 clk[IMX21_CLK_DUMMY] = imx_clk_fixed("dummy", 0);
51 clk[IMX21_CLK_CKIL] = imx_obtain_fixed_clock("ckil", lref);
52 clk[IMX21_CLK_CKIH] = imx_obtain_fixed_clock("ckih", href);
53 clk[IMX21_CLK_FPM] = imx_clk_fixed_factor("fpm", "ckil", 512, 1);
54 clk[IMX21_CLK_CKIH_DIV1P5] = imx_clk_fixed_factor("ckih_div1p5", "ckih_gate", 2, 3);
55
56 clk[IMX21_CLK_MPLL_GATE] = imx_clk_gate("mpll_gate", "mpll", CCM_CSCR, 0);
57 clk[IMX21_CLK_SPLL_GATE] = imx_clk_gate("spll_gate", "spll", CCM_CSCR, 1);
58 clk[IMX21_CLK_FPM_GATE] = imx_clk_gate("fpm_gate", "fpm", CCM_CSCR, 2);
59 clk[IMX21_CLK_CKIH_GATE] = imx_clk_gate_dis("ckih_gate", "ckih", CCM_CSCR, 3);
60 clk[IMX21_CLK_MPLL_OSC_SEL] = imx_clk_mux("mpll_osc_sel", CCM_CSCR, 4, 1, mpll_osc_sel_clks, ARRAY_SIZE(mpll_osc_sel_clks));
61 clk[IMX21_CLK_IPG] = imx_clk_divider("ipg", "hclk", CCM_CSCR, 9, 1);
62 clk[IMX21_CLK_HCLK] = imx_clk_divider("hclk", "fclk", CCM_CSCR, 10, 4);
63 clk[IMX21_CLK_MPLL_SEL] = imx_clk_mux("mpll_sel", CCM_CSCR, 16, 1, mpll_sel_clks, ARRAY_SIZE(mpll_sel_clks));
64 clk[IMX21_CLK_SPLL_SEL] = imx_clk_mux("spll_sel", CCM_CSCR, 17, 1, spll_sel_clks, ARRAY_SIZE(spll_sel_clks));
65 clk[IMX21_CLK_SSI1_SEL] = imx_clk_mux("ssi1_sel", CCM_CSCR, 19, 1, ssi_sel_clks, ARRAY_SIZE(ssi_sel_clks));
66 clk[IMX21_CLK_SSI2_SEL] = imx_clk_mux("ssi2_sel", CCM_CSCR, 20, 1, ssi_sel_clks, ARRAY_SIZE(ssi_sel_clks));
67 clk[IMX21_CLK_USB_DIV] = imx_clk_divider("usb_div", "spll_gate", CCM_CSCR, 26, 3);
68 clk[IMX21_CLK_FCLK] = imx_clk_divider("fclk", "mpll_gate", CCM_CSCR, 29, 3);
69
Shawn Guo3bec5f82015-04-26 13:33:39 +080070 clk[IMX21_CLK_MPLL] = imx_clk_pllv1(IMX_PLLV1_IMX21, "mpll", "mpll_sel", CCM_MPCTL0);
Alexander Shiyan35bcaf02014-06-22 17:17:09 +040071
Shawn Guo3bec5f82015-04-26 13:33:39 +080072 clk[IMX21_CLK_SPLL] = imx_clk_pllv1(IMX_PLLV1_IMX21, "spll", "spll_sel", CCM_SPCTL0);
Alexander Shiyan35bcaf02014-06-22 17:17:09 +040073
74 clk[IMX21_CLK_NFC_DIV] = imx_clk_divider("nfc_div", "fclk", CCM_PCDR0, 12, 4);
75 clk[IMX21_CLK_SSI1_DIV] = imx_clk_divider("ssi1_div", "ssi1_sel", CCM_PCDR0, 16, 6);
76 clk[IMX21_CLK_SSI2_DIV] = imx_clk_divider("ssi2_div", "ssi2_sel", CCM_PCDR0, 26, 6);
77
78 clk[IMX21_CLK_PER1] = imx_clk_divider("per1", "mpll_gate", CCM_PCDR1, 0, 6);
79 clk[IMX21_CLK_PER2] = imx_clk_divider("per2", "mpll_gate", CCM_PCDR1, 8, 6);
80 clk[IMX21_CLK_PER3] = imx_clk_divider("per3", "mpll_gate", CCM_PCDR1, 16, 6);
81 clk[IMX21_CLK_PER4] = imx_clk_divider("per4", "mpll_gate", CCM_PCDR1, 24, 6);
82
83 clk[IMX21_CLK_UART1_IPG_GATE] = imx_clk_gate("uart1_ipg_gate", "ipg", CCM_PCCR0, 0);
84 clk[IMX21_CLK_UART2_IPG_GATE] = imx_clk_gate("uart2_ipg_gate", "ipg", CCM_PCCR0, 1);
85 clk[IMX21_CLK_UART3_IPG_GATE] = imx_clk_gate("uart3_ipg_gate", "ipg", CCM_PCCR0, 2);
86 clk[IMX21_CLK_UART4_IPG_GATE] = imx_clk_gate("uart4_ipg_gate", "ipg", CCM_PCCR0, 3);
87 clk[IMX21_CLK_CSPI1_IPG_GATE] = imx_clk_gate("cspi1_ipg_gate", "ipg", CCM_PCCR0, 4);
88 clk[IMX21_CLK_CSPI2_IPG_GATE] = imx_clk_gate("cspi2_ipg_gate", "ipg", CCM_PCCR0, 5);
89 clk[IMX21_CLK_SSI1_GATE] = imx_clk_gate("ssi1_gate", "ipg", CCM_PCCR0, 6);
90 clk[IMX21_CLK_SSI2_GATE] = imx_clk_gate("ssi2_gate", "ipg", CCM_PCCR0, 7);
91 clk[IMX21_CLK_SDHC1_IPG_GATE] = imx_clk_gate("sdhc1_ipg_gate", "ipg", CCM_PCCR0, 9);
92 clk[IMX21_CLK_SDHC2_IPG_GATE] = imx_clk_gate("sdhc2_ipg_gate", "ipg", CCM_PCCR0, 10);
93 clk[IMX21_CLK_GPIO_GATE] = imx_clk_gate("gpio_gate", "ipg", CCM_PCCR0, 11);
94 clk[IMX21_CLK_I2C_GATE] = imx_clk_gate("i2c_gate", "ipg", CCM_PCCR0, 12);
95 clk[IMX21_CLK_DMA_GATE] = imx_clk_gate("dma_gate", "ipg", CCM_PCCR0, 13);
96 clk[IMX21_CLK_USB_GATE] = imx_clk_gate("usb_gate", "usb_div", CCM_PCCR0, 14);
97 clk[IMX21_CLK_EMMA_GATE] = imx_clk_gate("emma_gate", "ipg", CCM_PCCR0, 15);
98 clk[IMX21_CLK_SSI2_BAUD_GATE] = imx_clk_gate("ssi2_baud_gate", "ipg", CCM_PCCR0, 16);
99 clk[IMX21_CLK_SSI1_BAUD_GATE] = imx_clk_gate("ssi1_baud_gate", "ipg", CCM_PCCR0, 17);
100 clk[IMX21_CLK_LCDC_IPG_GATE] = imx_clk_gate("lcdc_ipg_gate", "ipg", CCM_PCCR0, 18);
101 clk[IMX21_CLK_NFC_GATE] = imx_clk_gate("nfc_gate", "nfc_div", CCM_PCCR0, 19);
102 clk[IMX21_CLK_SLCDC_HCLK_GATE] = imx_clk_gate("slcdc_hclk_gate", "hclk", CCM_PCCR0, 21);
103 clk[IMX21_CLK_PER4_GATE] = imx_clk_gate("per4_gate", "per4", CCM_PCCR0, 22);
104 clk[IMX21_CLK_BMI_GATE] = imx_clk_gate("bmi_gate", "hclk", CCM_PCCR0, 23);
105 clk[IMX21_CLK_USB_HCLK_GATE] = imx_clk_gate("usb_hclk_gate", "hclk", CCM_PCCR0, 24);
106 clk[IMX21_CLK_SLCDC_GATE] = imx_clk_gate("slcdc_gate", "hclk", CCM_PCCR0, 25);
107 clk[IMX21_CLK_LCDC_HCLK_GATE] = imx_clk_gate("lcdc_hclk_gate", "hclk", CCM_PCCR0, 26);
108 clk[IMX21_CLK_EMMA_HCLK_GATE] = imx_clk_gate("emma_hclk_gate", "hclk", CCM_PCCR0, 27);
109 clk[IMX21_CLK_BROM_GATE] = imx_clk_gate("brom_gate", "hclk", CCM_PCCR0, 28);
110 clk[IMX21_CLK_DMA_HCLK_GATE] = imx_clk_gate("dma_hclk_gate", "hclk", CCM_PCCR0, 30);
111 clk[IMX21_CLK_CSI_HCLK_GATE] = imx_clk_gate("csi_hclk_gate", "hclk", CCM_PCCR0, 31);
112
113 clk[IMX21_CLK_CSPI3_IPG_GATE] = imx_clk_gate("cspi3_ipg_gate", "ipg", CCM_PCCR1, 23);
114 clk[IMX21_CLK_WDOG_GATE] = imx_clk_gate("wdog_gate", "ipg", CCM_PCCR1, 24);
115 clk[IMX21_CLK_GPT1_IPG_GATE] = imx_clk_gate("gpt1_ipg_gate", "ipg", CCM_PCCR1, 25);
116 clk[IMX21_CLK_GPT2_IPG_GATE] = imx_clk_gate("gpt2_ipg_gate", "ipg", CCM_PCCR1, 26);
117 clk[IMX21_CLK_GPT3_IPG_GATE] = imx_clk_gate("gpt3_ipg_gate", "ipg", CCM_PCCR1, 27);
118 clk[IMX21_CLK_PWM_IPG_GATE] = imx_clk_gate("pwm_ipg_gate", "ipg", CCM_PCCR1, 28);
119 clk[IMX21_CLK_RTC_GATE] = imx_clk_gate("rtc_gate", "ipg", CCM_PCCR1, 29);
120 clk[IMX21_CLK_KPP_GATE] = imx_clk_gate("kpp_gate", "ipg", CCM_PCCR1, 30);
121 clk[IMX21_CLK_OWIRE_GATE] = imx_clk_gate("owire_gate", "ipg", CCM_PCCR1, 31);
122
123 imx_check_clocks(clk, ARRAY_SIZE(clk));
124}
Sascha Hauer93421e42012-03-09 09:11:39 +0100125
Sascha Hauer93421e42012-03-09 09:11:39 +0100126int __init mx21_clocks_init(unsigned long lref, unsigned long href)
127{
Alexander Shiyan35bcaf02014-06-22 17:17:09 +0400128 ccm = ioremap(MX21_CCM_BASE_ADDR, SZ_2K);
Alexander Shiyan65251692014-06-22 17:17:06 +0400129
Alexander Shiyan35bcaf02014-06-22 17:17:09 +0400130 _mx21_clocks_init(lref, href);
Alexander Shiyan65251692014-06-22 17:17:06 +0400131
Alexander Shiyan35bcaf02014-06-22 17:17:09 +0400132 clk_register_clkdev(clk[IMX21_CLK_PER1], "per", "imx21-uart.0");
133 clk_register_clkdev(clk[IMX21_CLK_UART1_IPG_GATE], "ipg", "imx21-uart.0");
134 clk_register_clkdev(clk[IMX21_CLK_PER1], "per", "imx21-uart.1");
135 clk_register_clkdev(clk[IMX21_CLK_UART2_IPG_GATE], "ipg", "imx21-uart.1");
136 clk_register_clkdev(clk[IMX21_CLK_PER1], "per", "imx21-uart.2");
137 clk_register_clkdev(clk[IMX21_CLK_UART3_IPG_GATE], "ipg", "imx21-uart.2");
138 clk_register_clkdev(clk[IMX21_CLK_PER1], "per", "imx21-uart.3");
139 clk_register_clkdev(clk[IMX21_CLK_UART4_IPG_GATE], "ipg", "imx21-uart.3");
140 clk_register_clkdev(clk[IMX21_CLK_GPT1_IPG_GATE], "ipg", "imx-gpt.0");
141 clk_register_clkdev(clk[IMX21_CLK_PER1], "per", "imx-gpt.0");
142 clk_register_clkdev(clk[IMX21_CLK_PER2], "per", "imx21-cspi.0");
143 clk_register_clkdev(clk[IMX21_CLK_CSPI1_IPG_GATE], "ipg", "imx21-cspi.0");
144 clk_register_clkdev(clk[IMX21_CLK_PER2], "per", "imx21-cspi.1");
145 clk_register_clkdev(clk[IMX21_CLK_CSPI2_IPG_GATE], "ipg", "imx21-cspi.1");
146 clk_register_clkdev(clk[IMX21_CLK_PER2], "per", "imx21-cspi.2");
147 clk_register_clkdev(clk[IMX21_CLK_CSPI3_IPG_GATE], "ipg", "imx21-cspi.2");
148 clk_register_clkdev(clk[IMX21_CLK_PER3], "per", "imx21-fb.0");
149 clk_register_clkdev(clk[IMX21_CLK_LCDC_IPG_GATE], "ipg", "imx21-fb.0");
150 clk_register_clkdev(clk[IMX21_CLK_LCDC_HCLK_GATE], "ahb", "imx21-fb.0");
151 clk_register_clkdev(clk[IMX21_CLK_USB_GATE], "per", "imx21-hcd.0");
152 clk_register_clkdev(clk[IMX21_CLK_USB_HCLK_GATE], "ahb", "imx21-hcd.0");
153 clk_register_clkdev(clk[IMX21_CLK_NFC_GATE], NULL, "imx21-nand.0");
154 clk_register_clkdev(clk[IMX21_CLK_DMA_HCLK_GATE], "ahb", "imx21-dma");
155 clk_register_clkdev(clk[IMX21_CLK_DMA_GATE], "ipg", "imx21-dma");
156 clk_register_clkdev(clk[IMX21_CLK_WDOG_GATE], NULL, "imx2-wdt.0");
157 clk_register_clkdev(clk[IMX21_CLK_I2C_GATE], NULL, "imx21-i2c.0");
158 clk_register_clkdev(clk[IMX21_CLK_OWIRE_GATE], NULL, "mxc_w1.0");
Sascha Hauer93421e42012-03-09 09:11:39 +0100159
Shawn Guo0931aff2015-05-15 11:41:39 +0800160 mxc_timer_init(MX21_GPT1_BASE_ADDR, MX21_INT_GPT1, GPT_TYPE_IMX21);
Sascha Hauer2cfb4512012-05-16 12:29:53 +0200161
Sascha Hauer93421e42012-03-09 09:11:39 +0100162 return 0;
163}
Alexander Shiyan35bcaf02014-06-22 17:17:09 +0400164
165static void __init mx21_clocks_init_dt(struct device_node *np)
166{
167 ccm = of_iomap(np, 0);
168
169 _mx21_clocks_init(32768, 26000000);
170
171 clk_data.clks = clk;
172 clk_data.clk_num = ARRAY_SIZE(clk);
173 of_clk_add_provider(np, of_clk_src_onecell_get, &clk_data);
Alexander Shiyan35bcaf02014-06-22 17:17:09 +0400174}
175CLK_OF_DECLARE(imx27_ccm, "fsl,imx21-ccm", mx21_clocks_init_dt);