Sascha Hauer | 93421e4 | 2012-03-09 09:11:39 +0100 | [diff] [blame] | 1 | /* |
| 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 Hauer | 93421e4 | 2012-03-09 09:11:39 +0100 | [diff] [blame] | 10 | */ |
| 11 | |
Sascha Hauer | 93421e4 | 2012-03-09 09:11:39 +0100 | [diff] [blame] | 12 | #include <linux/clk-provider.h> |
Alexander Shiyan | 548694b | 2014-06-22 17:17:08 +0400 | [diff] [blame] | 13 | #include <linux/clkdev.h> |
Alexander Shiyan | 35bcaf0 | 2014-06-22 17:17:09 +0400 | [diff] [blame] | 14 | #include <linux/of.h> |
| 15 | #include <linux/of_address.h> |
| 16 | #include <dt-bindings/clock/imx21-clock.h> |
Shawn Guo | 0931aff | 2015-05-15 11:41:39 +0800 | [diff] [blame] | 17 | #include <soc/imx/timer.h> |
Shawn Guo | 0c83131 | 2015-04-25 18:43:45 +0800 | [diff] [blame] | 18 | #include <asm/irq.h> |
Sascha Hauer | 93421e4 | 2012-03-09 09:11:39 +0100 | [diff] [blame] | 19 | |
Sascha Hauer | 93421e4 | 2012-03-09 09:11:39 +0100 | [diff] [blame] | 20 | #include "clk.h" |
Shawn Guo | 0c83131 | 2015-04-25 18:43:45 +0800 | [diff] [blame] | 21 | |
| 22 | #define MX21_CCM_BASE_ADDR 0x10027000 |
| 23 | #define MX21_GPT1_BASE_ADDR 0x10003000 |
| 24 | #define MX21_INT_GPT1 (NR_IRQS_LEGACY + 26) |
Sascha Hauer | 93421e4 | 2012-03-09 09:11:39 +0100 | [diff] [blame] | 25 | |
Alexander Shiyan | 35bcaf0 | 2014-06-22 17:17:09 +0400 | [diff] [blame] | 26 | static void __iomem *ccm __initdata; |
Sascha Hauer | 93421e4 | 2012-03-09 09:11:39 +0100 | [diff] [blame] | 27 | |
| 28 | /* Register offsets */ |
Alexander Shiyan | 35bcaf0 | 2014-06-22 17:17:09 +0400 | [diff] [blame] | 29 | #define CCM_CSCR (ccm + 0x00) |
| 30 | #define CCM_MPCTL0 (ccm + 0x04) |
| 31 | #define CCM_SPCTL0 (ccm + 0x0c) |
| 32 | #define CCM_PCDR0 (ccm + 0x18) |
| 33 | #define CCM_PCDR1 (ccm + 0x1c) |
| 34 | #define CCM_PCCR0 (ccm + 0x20) |
| 35 | #define CCM_PCCR1 (ccm + 0x24) |
Sascha Hauer | 93421e4 | 2012-03-09 09:11:39 +0100 | [diff] [blame] | 36 | |
Alexander Shiyan | 6525169 | 2014-06-22 17:17:06 +0400 | [diff] [blame] | 37 | static const char *mpll_osc_sel_clks[] = { "ckih_gate", "ckih_div1p5", }; |
| 38 | static const char *mpll_sel_clks[] = { "fpm_gate", "mpll_osc_sel", }; |
| 39 | static const char *spll_sel_clks[] = { "fpm_gate", "mpll_osc_sel", }; |
| 40 | static const char *ssi_sel_clks[] = { "spll_gate", "mpll_gate", }; |
Sascha Hauer | 93421e4 | 2012-03-09 09:11:39 +0100 | [diff] [blame] | 41 | |
Alexander Shiyan | 35bcaf0 | 2014-06-22 17:17:09 +0400 | [diff] [blame] | 42 | static struct clk *clk[IMX21_CLK_MAX]; |
| 43 | static struct clk_onecell_data clk_data; |
Sascha Hauer | 93421e4 | 2012-03-09 09:11:39 +0100 | [diff] [blame] | 44 | |
Alexander Shiyan | 35bcaf0 | 2014-06-22 17:17:09 +0400 | [diff] [blame] | 45 | static void __init _mx21_clocks_init(unsigned long lref, unsigned long href) |
| 46 | { |
| 47 | BUG_ON(!ccm); |
| 48 | |
| 49 | clk[IMX21_CLK_DUMMY] = imx_clk_fixed("dummy", 0); |
| 50 | clk[IMX21_CLK_CKIL] = imx_obtain_fixed_clock("ckil", lref); |
| 51 | clk[IMX21_CLK_CKIH] = imx_obtain_fixed_clock("ckih", href); |
| 52 | clk[IMX21_CLK_FPM] = imx_clk_fixed_factor("fpm", "ckil", 512, 1); |
| 53 | clk[IMX21_CLK_CKIH_DIV1P5] = imx_clk_fixed_factor("ckih_div1p5", "ckih_gate", 2, 3); |
| 54 | |
| 55 | clk[IMX21_CLK_MPLL_GATE] = imx_clk_gate("mpll_gate", "mpll", CCM_CSCR, 0); |
| 56 | clk[IMX21_CLK_SPLL_GATE] = imx_clk_gate("spll_gate", "spll", CCM_CSCR, 1); |
| 57 | clk[IMX21_CLK_FPM_GATE] = imx_clk_gate("fpm_gate", "fpm", CCM_CSCR, 2); |
| 58 | clk[IMX21_CLK_CKIH_GATE] = imx_clk_gate_dis("ckih_gate", "ckih", CCM_CSCR, 3); |
| 59 | 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)); |
| 60 | clk[IMX21_CLK_IPG] = imx_clk_divider("ipg", "hclk", CCM_CSCR, 9, 1); |
| 61 | clk[IMX21_CLK_HCLK] = imx_clk_divider("hclk", "fclk", CCM_CSCR, 10, 4); |
| 62 | clk[IMX21_CLK_MPLL_SEL] = imx_clk_mux("mpll_sel", CCM_CSCR, 16, 1, mpll_sel_clks, ARRAY_SIZE(mpll_sel_clks)); |
| 63 | clk[IMX21_CLK_SPLL_SEL] = imx_clk_mux("spll_sel", CCM_CSCR, 17, 1, spll_sel_clks, ARRAY_SIZE(spll_sel_clks)); |
| 64 | clk[IMX21_CLK_SSI1_SEL] = imx_clk_mux("ssi1_sel", CCM_CSCR, 19, 1, ssi_sel_clks, ARRAY_SIZE(ssi_sel_clks)); |
| 65 | clk[IMX21_CLK_SSI2_SEL] = imx_clk_mux("ssi2_sel", CCM_CSCR, 20, 1, ssi_sel_clks, ARRAY_SIZE(ssi_sel_clks)); |
| 66 | clk[IMX21_CLK_USB_DIV] = imx_clk_divider("usb_div", "spll_gate", CCM_CSCR, 26, 3); |
| 67 | clk[IMX21_CLK_FCLK] = imx_clk_divider("fclk", "mpll_gate", CCM_CSCR, 29, 3); |
| 68 | |
Shawn Guo | 3bec5f8 | 2015-04-26 13:33:39 +0800 | [diff] [blame] | 69 | clk[IMX21_CLK_MPLL] = imx_clk_pllv1(IMX_PLLV1_IMX21, "mpll", "mpll_sel", CCM_MPCTL0); |
Alexander Shiyan | 35bcaf0 | 2014-06-22 17:17:09 +0400 | [diff] [blame] | 70 | |
Shawn Guo | 3bec5f8 | 2015-04-26 13:33:39 +0800 | [diff] [blame] | 71 | clk[IMX21_CLK_SPLL] = imx_clk_pllv1(IMX_PLLV1_IMX21, "spll", "spll_sel", CCM_SPCTL0); |
Alexander Shiyan | 35bcaf0 | 2014-06-22 17:17:09 +0400 | [diff] [blame] | 72 | |
| 73 | clk[IMX21_CLK_NFC_DIV] = imx_clk_divider("nfc_div", "fclk", CCM_PCDR0, 12, 4); |
| 74 | clk[IMX21_CLK_SSI1_DIV] = imx_clk_divider("ssi1_div", "ssi1_sel", CCM_PCDR0, 16, 6); |
| 75 | clk[IMX21_CLK_SSI2_DIV] = imx_clk_divider("ssi2_div", "ssi2_sel", CCM_PCDR0, 26, 6); |
| 76 | |
| 77 | clk[IMX21_CLK_PER1] = imx_clk_divider("per1", "mpll_gate", CCM_PCDR1, 0, 6); |
| 78 | clk[IMX21_CLK_PER2] = imx_clk_divider("per2", "mpll_gate", CCM_PCDR1, 8, 6); |
| 79 | clk[IMX21_CLK_PER3] = imx_clk_divider("per3", "mpll_gate", CCM_PCDR1, 16, 6); |
| 80 | clk[IMX21_CLK_PER4] = imx_clk_divider("per4", "mpll_gate", CCM_PCDR1, 24, 6); |
| 81 | |
| 82 | clk[IMX21_CLK_UART1_IPG_GATE] = imx_clk_gate("uart1_ipg_gate", "ipg", CCM_PCCR0, 0); |
| 83 | clk[IMX21_CLK_UART2_IPG_GATE] = imx_clk_gate("uart2_ipg_gate", "ipg", CCM_PCCR0, 1); |
| 84 | clk[IMX21_CLK_UART3_IPG_GATE] = imx_clk_gate("uart3_ipg_gate", "ipg", CCM_PCCR0, 2); |
| 85 | clk[IMX21_CLK_UART4_IPG_GATE] = imx_clk_gate("uart4_ipg_gate", "ipg", CCM_PCCR0, 3); |
| 86 | clk[IMX21_CLK_CSPI1_IPG_GATE] = imx_clk_gate("cspi1_ipg_gate", "ipg", CCM_PCCR0, 4); |
| 87 | clk[IMX21_CLK_CSPI2_IPG_GATE] = imx_clk_gate("cspi2_ipg_gate", "ipg", CCM_PCCR0, 5); |
| 88 | clk[IMX21_CLK_SSI1_GATE] = imx_clk_gate("ssi1_gate", "ipg", CCM_PCCR0, 6); |
| 89 | clk[IMX21_CLK_SSI2_GATE] = imx_clk_gate("ssi2_gate", "ipg", CCM_PCCR0, 7); |
| 90 | clk[IMX21_CLK_SDHC1_IPG_GATE] = imx_clk_gate("sdhc1_ipg_gate", "ipg", CCM_PCCR0, 9); |
| 91 | clk[IMX21_CLK_SDHC2_IPG_GATE] = imx_clk_gate("sdhc2_ipg_gate", "ipg", CCM_PCCR0, 10); |
| 92 | clk[IMX21_CLK_GPIO_GATE] = imx_clk_gate("gpio_gate", "ipg", CCM_PCCR0, 11); |
| 93 | clk[IMX21_CLK_I2C_GATE] = imx_clk_gate("i2c_gate", "ipg", CCM_PCCR0, 12); |
| 94 | clk[IMX21_CLK_DMA_GATE] = imx_clk_gate("dma_gate", "ipg", CCM_PCCR0, 13); |
| 95 | clk[IMX21_CLK_USB_GATE] = imx_clk_gate("usb_gate", "usb_div", CCM_PCCR0, 14); |
| 96 | clk[IMX21_CLK_EMMA_GATE] = imx_clk_gate("emma_gate", "ipg", CCM_PCCR0, 15); |
| 97 | clk[IMX21_CLK_SSI2_BAUD_GATE] = imx_clk_gate("ssi2_baud_gate", "ipg", CCM_PCCR0, 16); |
| 98 | clk[IMX21_CLK_SSI1_BAUD_GATE] = imx_clk_gate("ssi1_baud_gate", "ipg", CCM_PCCR0, 17); |
| 99 | clk[IMX21_CLK_LCDC_IPG_GATE] = imx_clk_gate("lcdc_ipg_gate", "ipg", CCM_PCCR0, 18); |
| 100 | clk[IMX21_CLK_NFC_GATE] = imx_clk_gate("nfc_gate", "nfc_div", CCM_PCCR0, 19); |
| 101 | clk[IMX21_CLK_SLCDC_HCLK_GATE] = imx_clk_gate("slcdc_hclk_gate", "hclk", CCM_PCCR0, 21); |
| 102 | clk[IMX21_CLK_PER4_GATE] = imx_clk_gate("per4_gate", "per4", CCM_PCCR0, 22); |
| 103 | clk[IMX21_CLK_BMI_GATE] = imx_clk_gate("bmi_gate", "hclk", CCM_PCCR0, 23); |
| 104 | clk[IMX21_CLK_USB_HCLK_GATE] = imx_clk_gate("usb_hclk_gate", "hclk", CCM_PCCR0, 24); |
| 105 | clk[IMX21_CLK_SLCDC_GATE] = imx_clk_gate("slcdc_gate", "hclk", CCM_PCCR0, 25); |
| 106 | clk[IMX21_CLK_LCDC_HCLK_GATE] = imx_clk_gate("lcdc_hclk_gate", "hclk", CCM_PCCR0, 26); |
| 107 | clk[IMX21_CLK_EMMA_HCLK_GATE] = imx_clk_gate("emma_hclk_gate", "hclk", CCM_PCCR0, 27); |
| 108 | clk[IMX21_CLK_BROM_GATE] = imx_clk_gate("brom_gate", "hclk", CCM_PCCR0, 28); |
| 109 | clk[IMX21_CLK_DMA_HCLK_GATE] = imx_clk_gate("dma_hclk_gate", "hclk", CCM_PCCR0, 30); |
| 110 | clk[IMX21_CLK_CSI_HCLK_GATE] = imx_clk_gate("csi_hclk_gate", "hclk", CCM_PCCR0, 31); |
| 111 | |
| 112 | clk[IMX21_CLK_CSPI3_IPG_GATE] = imx_clk_gate("cspi3_ipg_gate", "ipg", CCM_PCCR1, 23); |
| 113 | clk[IMX21_CLK_WDOG_GATE] = imx_clk_gate("wdog_gate", "ipg", CCM_PCCR1, 24); |
| 114 | clk[IMX21_CLK_GPT1_IPG_GATE] = imx_clk_gate("gpt1_ipg_gate", "ipg", CCM_PCCR1, 25); |
| 115 | clk[IMX21_CLK_GPT2_IPG_GATE] = imx_clk_gate("gpt2_ipg_gate", "ipg", CCM_PCCR1, 26); |
| 116 | clk[IMX21_CLK_GPT3_IPG_GATE] = imx_clk_gate("gpt3_ipg_gate", "ipg", CCM_PCCR1, 27); |
| 117 | clk[IMX21_CLK_PWM_IPG_GATE] = imx_clk_gate("pwm_ipg_gate", "ipg", CCM_PCCR1, 28); |
| 118 | clk[IMX21_CLK_RTC_GATE] = imx_clk_gate("rtc_gate", "ipg", CCM_PCCR1, 29); |
| 119 | clk[IMX21_CLK_KPP_GATE] = imx_clk_gate("kpp_gate", "ipg", CCM_PCCR1, 30); |
| 120 | clk[IMX21_CLK_OWIRE_GATE] = imx_clk_gate("owire_gate", "ipg", CCM_PCCR1, 31); |
| 121 | |
| 122 | imx_check_clocks(clk, ARRAY_SIZE(clk)); |
| 123 | } |
Sascha Hauer | 93421e4 | 2012-03-09 09:11:39 +0100 | [diff] [blame] | 124 | |
Sascha Hauer | 93421e4 | 2012-03-09 09:11:39 +0100 | [diff] [blame] | 125 | int __init mx21_clocks_init(unsigned long lref, unsigned long href) |
| 126 | { |
Alexander Shiyan | 35bcaf0 | 2014-06-22 17:17:09 +0400 | [diff] [blame] | 127 | ccm = ioremap(MX21_CCM_BASE_ADDR, SZ_2K); |
Alexander Shiyan | 6525169 | 2014-06-22 17:17:06 +0400 | [diff] [blame] | 128 | |
Alexander Shiyan | 35bcaf0 | 2014-06-22 17:17:09 +0400 | [diff] [blame] | 129 | _mx21_clocks_init(lref, href); |
Alexander Shiyan | 6525169 | 2014-06-22 17:17:06 +0400 | [diff] [blame] | 130 | |
Alexander Shiyan | 35bcaf0 | 2014-06-22 17:17:09 +0400 | [diff] [blame] | 131 | clk_register_clkdev(clk[IMX21_CLK_PER1], "per", "imx21-uart.0"); |
| 132 | clk_register_clkdev(clk[IMX21_CLK_UART1_IPG_GATE], "ipg", "imx21-uart.0"); |
| 133 | clk_register_clkdev(clk[IMX21_CLK_PER1], "per", "imx21-uart.1"); |
| 134 | clk_register_clkdev(clk[IMX21_CLK_UART2_IPG_GATE], "ipg", "imx21-uart.1"); |
| 135 | clk_register_clkdev(clk[IMX21_CLK_PER1], "per", "imx21-uart.2"); |
| 136 | clk_register_clkdev(clk[IMX21_CLK_UART3_IPG_GATE], "ipg", "imx21-uart.2"); |
| 137 | clk_register_clkdev(clk[IMX21_CLK_PER1], "per", "imx21-uart.3"); |
| 138 | clk_register_clkdev(clk[IMX21_CLK_UART4_IPG_GATE], "ipg", "imx21-uart.3"); |
| 139 | clk_register_clkdev(clk[IMX21_CLK_GPT1_IPG_GATE], "ipg", "imx-gpt.0"); |
| 140 | clk_register_clkdev(clk[IMX21_CLK_PER1], "per", "imx-gpt.0"); |
| 141 | clk_register_clkdev(clk[IMX21_CLK_PER2], "per", "imx21-cspi.0"); |
| 142 | clk_register_clkdev(clk[IMX21_CLK_CSPI1_IPG_GATE], "ipg", "imx21-cspi.0"); |
| 143 | clk_register_clkdev(clk[IMX21_CLK_PER2], "per", "imx21-cspi.1"); |
| 144 | clk_register_clkdev(clk[IMX21_CLK_CSPI2_IPG_GATE], "ipg", "imx21-cspi.1"); |
| 145 | clk_register_clkdev(clk[IMX21_CLK_PER2], "per", "imx21-cspi.2"); |
| 146 | clk_register_clkdev(clk[IMX21_CLK_CSPI3_IPG_GATE], "ipg", "imx21-cspi.2"); |
| 147 | clk_register_clkdev(clk[IMX21_CLK_PER3], "per", "imx21-fb.0"); |
| 148 | clk_register_clkdev(clk[IMX21_CLK_LCDC_IPG_GATE], "ipg", "imx21-fb.0"); |
| 149 | clk_register_clkdev(clk[IMX21_CLK_LCDC_HCLK_GATE], "ahb", "imx21-fb.0"); |
| 150 | clk_register_clkdev(clk[IMX21_CLK_USB_GATE], "per", "imx21-hcd.0"); |
| 151 | clk_register_clkdev(clk[IMX21_CLK_USB_HCLK_GATE], "ahb", "imx21-hcd.0"); |
| 152 | clk_register_clkdev(clk[IMX21_CLK_NFC_GATE], NULL, "imx21-nand.0"); |
| 153 | clk_register_clkdev(clk[IMX21_CLK_DMA_HCLK_GATE], "ahb", "imx21-dma"); |
| 154 | clk_register_clkdev(clk[IMX21_CLK_DMA_GATE], "ipg", "imx21-dma"); |
| 155 | clk_register_clkdev(clk[IMX21_CLK_WDOG_GATE], NULL, "imx2-wdt.0"); |
| 156 | clk_register_clkdev(clk[IMX21_CLK_I2C_GATE], NULL, "imx21-i2c.0"); |
| 157 | clk_register_clkdev(clk[IMX21_CLK_OWIRE_GATE], NULL, "mxc_w1.0"); |
Sascha Hauer | 93421e4 | 2012-03-09 09:11:39 +0100 | [diff] [blame] | 158 | |
Shawn Guo | 0931aff | 2015-05-15 11:41:39 +0800 | [diff] [blame] | 159 | mxc_timer_init(MX21_GPT1_BASE_ADDR, MX21_INT_GPT1, GPT_TYPE_IMX21); |
Sascha Hauer | 2cfb451 | 2012-05-16 12:29:53 +0200 | [diff] [blame] | 160 | |
Sascha Hauer | 93421e4 | 2012-03-09 09:11:39 +0100 | [diff] [blame] | 161 | return 0; |
| 162 | } |
Alexander Shiyan | 35bcaf0 | 2014-06-22 17:17:09 +0400 | [diff] [blame] | 163 | |
| 164 | static void __init mx21_clocks_init_dt(struct device_node *np) |
| 165 | { |
| 166 | ccm = of_iomap(np, 0); |
| 167 | |
| 168 | _mx21_clocks_init(32768, 26000000); |
| 169 | |
| 170 | clk_data.clks = clk; |
| 171 | clk_data.clk_num = ARRAY_SIZE(clk); |
| 172 | of_clk_add_provider(np, of_clk_src_onecell_get, &clk_data); |
Alexander Shiyan | 35bcaf0 | 2014-06-22 17:17:09 +0400 | [diff] [blame] | 173 | } |
| 174 | CLK_OF_DECLARE(imx27_ccm, "fsl,imx21-ccm", mx21_clocks_init_dt); |