Sascha Hauer | cd73785 | 2012-03-09 09:11:32 +0100 | [diff] [blame] | 1 | /* |
| 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 | |
| 18 | #include <linux/kernel.h> |
| 19 | #include <linux/init.h> |
| 20 | #include <linux/clk.h> |
| 21 | #include <linux/io.h> |
| 22 | #include <linux/clkdev.h> |
| 23 | #include <linux/err.h> |
| 24 | |
| 25 | #include <mach/hardware.h> |
Shawn Guo | e337247 | 2012-09-13 21:01:00 +0800 | [diff] [blame] | 26 | |
Sascha Hauer | cd73785 | 2012-03-09 09:11:32 +0100 | [diff] [blame] | 27 | #include "clk.h" |
Shawn Guo | e337247 | 2012-09-13 21:01:00 +0800 | [diff] [blame] | 28 | #include "common.h" |
Sascha Hauer | cd73785 | 2012-03-09 09:11:32 +0100 | [diff] [blame] | 29 | |
| 30 | /* CCM register addresses */ |
| 31 | #define IO_ADDR_CCM(off) (MX1_IO_ADDRESS(MX1_CCM_BASE_ADDR + (off))) |
| 32 | |
| 33 | #define CCM_CSCR IO_ADDR_CCM(0x0) |
| 34 | #define CCM_MPCTL0 IO_ADDR_CCM(0x4) |
| 35 | #define CCM_SPCTL0 IO_ADDR_CCM(0xc) |
| 36 | #define CCM_PCDR IO_ADDR_CCM(0x20) |
| 37 | |
| 38 | /* SCM register addresses */ |
| 39 | #define IO_ADDR_SCM(off) (MX1_IO_ADDRESS(MX1_SCM_BASE_ADDR + (off))) |
| 40 | |
| 41 | #define SCM_GCCR IO_ADDR_SCM(0xc) |
| 42 | |
| 43 | static const char *prem_sel_clks[] = { "clk32_premult", "clk16m", }; |
| 44 | static const char *clko_sel_clks[] = { "per1", "hclk", "clk48m", "clk16m", "prem", |
| 45 | "fclk", }; |
| 46 | enum imx1_clks { |
| 47 | dummy, clk32, clk16m_ext, clk16m, clk32_premult, prem, mpll, spll, mcu, |
| 48 | fclk, hclk, clk48m, per1, per2, per3, clko, dma_gate, csi_gate, |
| 49 | mma_gate, usbd_gate, clk_max |
| 50 | }; |
| 51 | |
| 52 | static struct clk *clk[clk_max]; |
| 53 | |
| 54 | int __init mx1_clocks_init(unsigned long fref) |
| 55 | { |
| 56 | int i; |
| 57 | |
| 58 | clk[dummy] = imx_clk_fixed("dummy", 0); |
| 59 | clk[clk32] = imx_clk_fixed("clk32", fref); |
| 60 | clk[clk16m_ext] = imx_clk_fixed("clk16m_ext", 16000000); |
| 61 | clk[clk16m] = imx_clk_gate("clk16m", "clk16m_ext", CCM_CSCR, 17); |
| 62 | clk[clk32_premult] = imx_clk_fixed_factor("clk32_premult", "clk32", 512, 1); |
| 63 | clk[prem] = imx_clk_mux("prem", CCM_CSCR, 16, 1, prem_sel_clks, |
| 64 | ARRAY_SIZE(prem_sel_clks)); |
| 65 | clk[mpll] = imx_clk_pllv1("mpll", "clk32_premult", CCM_MPCTL0); |
| 66 | clk[spll] = imx_clk_pllv1("spll", "prem", CCM_SPCTL0); |
| 67 | clk[mcu] = imx_clk_divider("mcu", "clk32_premult", CCM_CSCR, 15, 1); |
| 68 | clk[fclk] = imx_clk_divider("fclk", "mpll", CCM_CSCR, 15, 1); |
| 69 | clk[hclk] = imx_clk_divider("hclk", "spll", CCM_CSCR, 10, 4); |
| 70 | clk[clk48m] = imx_clk_divider("clk48m", "spll", CCM_CSCR, 26, 3); |
| 71 | clk[per1] = imx_clk_divider("per1", "spll", CCM_PCDR, 0, 4); |
| 72 | clk[per2] = imx_clk_divider("per2", "spll", CCM_PCDR, 4, 4); |
| 73 | clk[per3] = imx_clk_divider("per3", "spll", CCM_PCDR, 16, 7); |
| 74 | clk[clko] = imx_clk_mux("clko", CCM_CSCR, 29, 3, clko_sel_clks, |
| 75 | ARRAY_SIZE(clko_sel_clks)); |
| 76 | clk[dma_gate] = imx_clk_gate("dma_gate", "hclk", SCM_GCCR, 4); |
| 77 | clk[csi_gate] = imx_clk_gate("csi_gate", "hclk", SCM_GCCR, 2); |
| 78 | clk[mma_gate] = imx_clk_gate("mma_gate", "hclk", SCM_GCCR, 1); |
| 79 | clk[usbd_gate] = imx_clk_gate("usbd_gate", "clk48m", SCM_GCCR, 0); |
| 80 | |
| 81 | for (i = 0; i < ARRAY_SIZE(clk); i++) |
| 82 | if (IS_ERR(clk[i])) |
| 83 | pr_err("imx1 clk %d: register failed with %ld\n", |
| 84 | i, PTR_ERR(clk[i])); |
| 85 | |
Shawn Guo | e51d0f0 | 2012-09-15 21:11:28 +0800 | [diff] [blame^] | 86 | clk_register_clkdev(clk[dma_gate], "ahb", "imx1-dma"); |
| 87 | clk_register_clkdev(clk[hclk], "ipg", "imx1-dma"); |
Sascha Hauer | cd73785 | 2012-03-09 09:11:32 +0100 | [diff] [blame] | 88 | clk_register_clkdev(clk[csi_gate], NULL, "mx1-camera.0"); |
| 89 | clk_register_clkdev(clk[mma_gate], "mma", NULL); |
| 90 | clk_register_clkdev(clk[usbd_gate], NULL, "imx_udc.0"); |
| 91 | clk_register_clkdev(clk[per1], "per", "imx-gpt.0"); |
| 92 | clk_register_clkdev(clk[hclk], "ipg", "imx-gpt.0"); |
| 93 | clk_register_clkdev(clk[per1], "per", "imx1-uart.0"); |
| 94 | clk_register_clkdev(clk[hclk], "ipg", "imx1-uart.0"); |
| 95 | clk_register_clkdev(clk[per1], "per", "imx1-uart.1"); |
| 96 | clk_register_clkdev(clk[hclk], "ipg", "imx1-uart.1"); |
| 97 | clk_register_clkdev(clk[per1], "per", "imx1-uart.2"); |
| 98 | clk_register_clkdev(clk[hclk], "ipg", "imx1-uart.2"); |
Shawn Guo | 5bdfba2 | 2012-09-14 15:19:00 +0800 | [diff] [blame] | 99 | clk_register_clkdev(clk[hclk], NULL, "imx1-i2c.0"); |
Sascha Hauer | cd73785 | 2012-03-09 09:11:32 +0100 | [diff] [blame] | 100 | clk_register_clkdev(clk[per2], "per", "imx1-cspi.0"); |
| 101 | clk_register_clkdev(clk[dummy], "ipg", "imx1-cspi.0"); |
| 102 | clk_register_clkdev(clk[per2], "per", "imx1-cspi.1"); |
| 103 | clk_register_clkdev(clk[dummy], "ipg", "imx1-cspi.1"); |
| 104 | clk_register_clkdev(clk[per2], NULL, "imx-mmc.0"); |
| 105 | clk_register_clkdev(clk[per2], "per", "imx-fb.0"); |
| 106 | clk_register_clkdev(clk[dummy], "ipg", "imx-fb.0"); |
| 107 | clk_register_clkdev(clk[dummy], "ahb", "imx-fb.0"); |
| 108 | clk_register_clkdev(clk[hclk], "mshc", NULL); |
| 109 | clk_register_clkdev(clk[per3], "ssi", NULL); |
Shawn Guo | bb1d34a | 2012-09-15 14:26:14 +0800 | [diff] [blame] | 110 | clk_register_clkdev(clk[clk32], NULL, "imx1-rtc.0"); |
Sascha Hauer | cd73785 | 2012-03-09 09:11:32 +0100 | [diff] [blame] | 111 | clk_register_clkdev(clk[clko], "clko", NULL); |
| 112 | |
Sascha Hauer | 2cfb451 | 2012-05-16 12:29:53 +0200 | [diff] [blame] | 113 | mxc_timer_init(MX1_IO_ADDRESS(MX1_TIM1_BASE_ADDR), MX1_TIM1_INT); |
Sascha Hauer | cd73785 | 2012-03-09 09:11:32 +0100 | [diff] [blame] | 114 | |
| 115 | return 0; |
| 116 | } |