blob: e9c391b3209207e2ed913d11326e676f7a426274 [file] [log] [blame]
Sascha Hauercd737852012-03-09 09:11:32 +01001/*
2 * Copyright (C) 2008 Sascha Hauer <s.hauer@pengutronix.de>, Pengutronix
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 * 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 along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
16 */
17
Sascha Hauercd737852012-03-09 09:11:32 +010018#include <linux/clk.h>
Sascha Hauercd737852012-03-09 09:11:32 +010019#include <linux/clkdev.h>
Alexander Shiyanac361872014-05-20 20:43:49 +040020#include <linux/clk-provider.h>
Sascha Hauercd737852012-03-09 09:11:32 +010021#include <linux/err.h>
Alexander Shiyanac361872014-05-20 20:43:49 +040022#include <linux/init.h>
23#include <linux/of.h>
24#include <linux/of_address.h>
25#include <dt-bindings/clock/imx1-clock.h>
Sascha Hauercd737852012-03-09 09:11:32 +010026
Sascha Hauercd737852012-03-09 09:11:32 +010027#include "clk.h"
Shawn Guoe3372472012-09-13 21:01:00 +080028#include "common.h"
Shawn Guo50f2de62012-09-14 14:14:45 +080029#include "hardware.h"
Sascha Hauercd737852012-03-09 09:11:32 +010030
Sascha Hauercd737852012-03-09 09:11:32 +010031static const char *prem_sel_clks[] = { "clk32_premult", "clk16m", };
Alexander Shiyan402e4a42014-05-13 20:04:21 +040032static const char *clko_sel_clks[] = { "per1", "hclk", "clk48m", "clk16m",
33 "prem", "fclk", };
34
Alexander Shiyanac361872014-05-20 20:43:49 +040035static struct clk *clk[IMX1_CLK_MAX];
36static struct clk_onecell_data clk_data;
Sascha Hauercd737852012-03-09 09:11:32 +010037
Alexander Shiyanac361872014-05-20 20:43:49 +040038static void __iomem *ccm __initdata;
39#define CCM_CSCR (ccm + 0x0000)
40#define CCM_MPCTL0 (ccm + 0x0004)
41#define CCM_SPCTL0 (ccm + 0x000c)
42#define CCM_PCDR (ccm + 0x0020)
43#define SCM_GCCR (ccm + 0x0810)
Sascha Hauercd737852012-03-09 09:11:32 +010044
Alexander Shiyanac361872014-05-20 20:43:49 +040045static void __init _mx1_clocks_init(unsigned long fref)
Sascha Hauercd737852012-03-09 09:11:32 +010046{
Alexander Shiyanac361872014-05-20 20:43:49 +040047 unsigned i;
Sascha Hauercd737852012-03-09 09:11:32 +010048
Alexander Shiyanac361872014-05-20 20:43:49 +040049 clk[IMX1_CLK_DUMMY] = imx_clk_fixed("dummy", 0);
50 clk[IMX1_CLK_CLK32] = imx_obtain_fixed_clock("clk32", fref);
51 clk[IMX1_CLK_CLK16M_EXT] = imx_clk_fixed("clk16m_ext", 16000000);
52 clk[IMX1_CLK_CLK16M] = imx_clk_gate("clk16m", "clk16m_ext", CCM_CSCR, 17);
53 clk[IMX1_CLK_CLK32_PREMULT] = imx_clk_fixed_factor("clk32_premult", "clk32", 512, 1);
54 clk[IMX1_CLK_PREM] = imx_clk_mux("prem", CCM_CSCR, 16, 1, prem_sel_clks, ARRAY_SIZE(prem_sel_clks));
55 clk[IMX1_CLK_MPLL] = imx_clk_pllv1("mpll", "clk32_premult", CCM_MPCTL0);
56 clk[IMX1_CLK_MPLL_GATE] = imx_clk_gate("mpll_gate", "mpll", CCM_CSCR, 0);
57 clk[IMX1_CLK_SPLL] = imx_clk_pllv1("spll", "prem", CCM_SPCTL0);
58 clk[IMX1_CLK_SPLL_GATE] = imx_clk_gate("spll_gate", "spll", CCM_CSCR, 1);
59 clk[IMX1_CLK_MCU] = imx_clk_divider("mcu", "clk32_premult", CCM_CSCR, 15, 1);
60 clk[IMX1_CLK_FCLK] = imx_clk_divider("fclk", "mpll_gate", CCM_CSCR, 15, 1);
61 clk[IMX1_CLK_HCLK] = imx_clk_divider("hclk", "spll_gate", CCM_CSCR, 10, 4);
62 clk[IMX1_CLK_CLK48M] = imx_clk_divider("clk48m", "spll_gate", CCM_CSCR, 26, 3);
63 clk[IMX1_CLK_PER1] = imx_clk_divider("per1", "spll_gate", CCM_PCDR, 0, 4);
64 clk[IMX1_CLK_PER2] = imx_clk_divider("per2", "spll_gate", CCM_PCDR, 4, 4);
65 clk[IMX1_CLK_PER3] = imx_clk_divider("per3", "spll_gate", CCM_PCDR, 16, 7);
66 clk[IMX1_CLK_CLKO] = imx_clk_mux("clko", CCM_CSCR, 29, 3, clko_sel_clks, ARRAY_SIZE(clko_sel_clks));
67 clk[IMX1_CLK_UART3_GATE] = imx_clk_gate("uart3_gate", "hclk", SCM_GCCR, 6);
68 clk[IMX1_CLK_SSI2_GATE] = imx_clk_gate("ssi2_gate", "hclk", SCM_GCCR, 5);
69 clk[IMX1_CLK_BROM_GATE] = imx_clk_gate("brom_gate", "hclk", SCM_GCCR, 4);
70 clk[IMX1_CLK_DMA_GATE] = imx_clk_gate("dma_gate", "hclk", SCM_GCCR, 3);
71 clk[IMX1_CLK_CSI_GATE] = imx_clk_gate("csi_gate", "hclk", SCM_GCCR, 2);
72 clk[IMX1_CLK_MMA_GATE] = imx_clk_gate("mma_gate", "hclk", SCM_GCCR, 1);
73 clk[IMX1_CLK_USBD_GATE] = imx_clk_gate("usbd_gate", "clk48m", SCM_GCCR, 0);
Sascha Hauercd737852012-03-09 09:11:32 +010074
75 for (i = 0; i < ARRAY_SIZE(clk); i++)
76 if (IS_ERR(clk[i]))
77 pr_err("imx1 clk %d: register failed with %ld\n",
78 i, PTR_ERR(clk[i]));
79
Alexander Shiyanac361872014-05-20 20:43:49 +040080 clk_register_clkdev(clk[IMX1_CLK_PER1], "per", "imx-gpt.0");
81 clk_register_clkdev(clk[IMX1_CLK_HCLK], "ipg", "imx-gpt.0");
82}
83
84int __init mx1_clocks_init(unsigned long fref)
85{
86 ccm = MX1_IO_ADDRESS(MX1_CCM_BASE_ADDR);
87
88 _mx1_clocks_init(fref);
89
90 clk_register_clkdev(clk[IMX1_CLK_DMA_GATE], "ahb", "imx1-dma");
91 clk_register_clkdev(clk[IMX1_CLK_HCLK], "ipg", "imx1-dma");
92 clk_register_clkdev(clk[IMX1_CLK_PER1], "per", "imx1-uart.0");
93 clk_register_clkdev(clk[IMX1_CLK_HCLK], "ipg", "imx1-uart.0");
94 clk_register_clkdev(clk[IMX1_CLK_PER1], "per", "imx1-uart.1");
95 clk_register_clkdev(clk[IMX1_CLK_HCLK], "ipg", "imx1-uart.1");
96 clk_register_clkdev(clk[IMX1_CLK_PER1], "per", "imx1-uart.2");
97 clk_register_clkdev(clk[IMX1_CLK_UART3_GATE], "ipg", "imx1-uart.2");
98 clk_register_clkdev(clk[IMX1_CLK_HCLK], NULL, "imx1-i2c.0");
99 clk_register_clkdev(clk[IMX1_CLK_PER2], "per", "imx1-cspi.0");
100 clk_register_clkdev(clk[IMX1_CLK_DUMMY], "ipg", "imx1-cspi.0");
101 clk_register_clkdev(clk[IMX1_CLK_PER2], "per", "imx1-cspi.1");
102 clk_register_clkdev(clk[IMX1_CLK_DUMMY], "ipg", "imx1-cspi.1");
103 clk_register_clkdev(clk[IMX1_CLK_PER2], "per", "imx1-fb.0");
104 clk_register_clkdev(clk[IMX1_CLK_DUMMY], "ipg", "imx1-fb.0");
105 clk_register_clkdev(clk[IMX1_CLK_DUMMY], "ahb", "imx1-fb.0");
Sascha Hauercd737852012-03-09 09:11:32 +0100106
Sascha Hauer2cfb4512012-05-16 12:29:53 +0200107 mxc_timer_init(MX1_IO_ADDRESS(MX1_TIM1_BASE_ADDR), MX1_TIM1_INT);
Sascha Hauercd737852012-03-09 09:11:32 +0100108
109 return 0;
110}
Alexander Shiyanac361872014-05-20 20:43:49 +0400111
112static void __init mx1_clocks_init_dt(struct device_node *np)
113{
114 ccm = of_iomap(np, 0);
115 BUG_ON(!ccm);
116
117 _mx1_clocks_init(32768);
118
119 clk_data.clks = clk;
120 clk_data.clk_num = ARRAY_SIZE(clk);
121 of_clk_add_provider(np, of_clk_src_onecell_get, &clk_data);
122
123 mxc_timer_init_dt(of_find_compatible_node(NULL, NULL, "fsl,imx1-gpt"));
124}
125CLK_OF_DECLARE(imx1_ccm, "fsl,imx1-ccm", mx1_clocks_init_dt);