clk-imx1.c 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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. #include <linux/clkdev.h>
  18. #include <linux/clk-provider.h>
  19. #include <linux/err.h>
  20. #include <linux/init.h>
  21. #include <linux/of.h>
  22. #include <linux/of_address.h>
  23. #include <dt-bindings/clock/imx1-clock.h>
  24. #include <soc/imx/timer.h>
  25. #include <asm/irq.h>
  26. #include "clk.h"
  27. #define MX1_CCM_BASE_ADDR 0x0021b000
  28. #define MX1_TIM1_BASE_ADDR 0x00220000
  29. #define MX1_TIM1_INT (NR_IRQS_LEGACY + 59)
  30. static const char *prem_sel_clks[] = { "clk32_premult", "clk16m", };
  31. static const char *clko_sel_clks[] = { "per1", "hclk", "clk48m", "clk16m",
  32. "prem", "fclk", };
  33. static struct clk *clk[IMX1_CLK_MAX];
  34. static struct clk_onecell_data clk_data;
  35. static void __iomem *ccm __initdata;
  36. #define CCM_CSCR (ccm + 0x0000)
  37. #define CCM_MPCTL0 (ccm + 0x0004)
  38. #define CCM_SPCTL0 (ccm + 0x000c)
  39. #define CCM_PCDR (ccm + 0x0020)
  40. #define SCM_GCCR (ccm + 0x0810)
  41. static void __init _mx1_clocks_init(unsigned long fref)
  42. {
  43. clk[IMX1_CLK_DUMMY] = imx_clk_fixed("dummy", 0);
  44. clk[IMX1_CLK_CLK32] = imx_obtain_fixed_clock("clk32", fref);
  45. clk[IMX1_CLK_CLK16M_EXT] = imx_clk_fixed("clk16m_ext", 16000000);
  46. clk[IMX1_CLK_CLK16M] = imx_clk_gate("clk16m", "clk16m_ext", CCM_CSCR, 17);
  47. clk[IMX1_CLK_CLK32_PREMULT] = imx_clk_fixed_factor("clk32_premult", "clk32", 512, 1);
  48. clk[IMX1_CLK_PREM] = imx_clk_mux("prem", CCM_CSCR, 16, 1, prem_sel_clks, ARRAY_SIZE(prem_sel_clks));
  49. clk[IMX1_CLK_MPLL] = imx_clk_pllv1(IMX_PLLV1_IMX1, "mpll", "clk32_premult", CCM_MPCTL0);
  50. clk[IMX1_CLK_MPLL_GATE] = imx_clk_gate("mpll_gate", "mpll", CCM_CSCR, 0);
  51. clk[IMX1_CLK_SPLL] = imx_clk_pllv1(IMX_PLLV1_IMX1, "spll", "prem", CCM_SPCTL0);
  52. clk[IMX1_CLK_SPLL_GATE] = imx_clk_gate("spll_gate", "spll", CCM_CSCR, 1);
  53. clk[IMX1_CLK_MCU] = imx_clk_divider("mcu", "clk32_premult", CCM_CSCR, 15, 1);
  54. clk[IMX1_CLK_FCLK] = imx_clk_divider("fclk", "mpll_gate", CCM_CSCR, 15, 1);
  55. clk[IMX1_CLK_HCLK] = imx_clk_divider("hclk", "spll_gate", CCM_CSCR, 10, 4);
  56. clk[IMX1_CLK_CLK48M] = imx_clk_divider("clk48m", "spll_gate", CCM_CSCR, 26, 3);
  57. clk[IMX1_CLK_PER1] = imx_clk_divider("per1", "spll_gate", CCM_PCDR, 0, 4);
  58. clk[IMX1_CLK_PER2] = imx_clk_divider("per2", "spll_gate", CCM_PCDR, 4, 4);
  59. clk[IMX1_CLK_PER3] = imx_clk_divider("per3", "spll_gate", CCM_PCDR, 16, 7);
  60. clk[IMX1_CLK_CLKO] = imx_clk_mux("clko", CCM_CSCR, 29, 3, clko_sel_clks, ARRAY_SIZE(clko_sel_clks));
  61. clk[IMX1_CLK_UART3_GATE] = imx_clk_gate("uart3_gate", "hclk", SCM_GCCR, 6);
  62. clk[IMX1_CLK_SSI2_GATE] = imx_clk_gate("ssi2_gate", "hclk", SCM_GCCR, 5);
  63. clk[IMX1_CLK_BROM_GATE] = imx_clk_gate("brom_gate", "hclk", SCM_GCCR, 4);
  64. clk[IMX1_CLK_DMA_GATE] = imx_clk_gate("dma_gate", "hclk", SCM_GCCR, 3);
  65. clk[IMX1_CLK_CSI_GATE] = imx_clk_gate("csi_gate", "hclk", SCM_GCCR, 2);
  66. clk[IMX1_CLK_MMA_GATE] = imx_clk_gate("mma_gate", "hclk", SCM_GCCR, 1);
  67. clk[IMX1_CLK_USBD_GATE] = imx_clk_gate("usbd_gate", "clk48m", SCM_GCCR, 0);
  68. imx_check_clocks(clk, ARRAY_SIZE(clk));
  69. }
  70. int __init mx1_clocks_init(unsigned long fref)
  71. {
  72. ccm = ioremap(MX1_CCM_BASE_ADDR, SZ_4K);
  73. BUG_ON(!ccm);
  74. _mx1_clocks_init(fref);
  75. clk_register_clkdev(clk[IMX1_CLK_PER1], "per", "imx-gpt.0");
  76. clk_register_clkdev(clk[IMX1_CLK_HCLK], "ipg", "imx-gpt.0");
  77. clk_register_clkdev(clk[IMX1_CLK_DMA_GATE], "ahb", "imx1-dma");
  78. clk_register_clkdev(clk[IMX1_CLK_HCLK], "ipg", "imx1-dma");
  79. clk_register_clkdev(clk[IMX1_CLK_PER1], "per", "imx1-uart.0");
  80. clk_register_clkdev(clk[IMX1_CLK_HCLK], "ipg", "imx1-uart.0");
  81. clk_register_clkdev(clk[IMX1_CLK_PER1], "per", "imx1-uart.1");
  82. clk_register_clkdev(clk[IMX1_CLK_HCLK], "ipg", "imx1-uart.1");
  83. clk_register_clkdev(clk[IMX1_CLK_PER1], "per", "imx1-uart.2");
  84. clk_register_clkdev(clk[IMX1_CLK_UART3_GATE], "ipg", "imx1-uart.2");
  85. clk_register_clkdev(clk[IMX1_CLK_HCLK], NULL, "imx1-i2c.0");
  86. clk_register_clkdev(clk[IMX1_CLK_PER2], "per", "imx1-cspi.0");
  87. clk_register_clkdev(clk[IMX1_CLK_DUMMY], "ipg", "imx1-cspi.0");
  88. clk_register_clkdev(clk[IMX1_CLK_PER2], "per", "imx1-cspi.1");
  89. clk_register_clkdev(clk[IMX1_CLK_DUMMY], "ipg", "imx1-cspi.1");
  90. clk_register_clkdev(clk[IMX1_CLK_PER2], "per", "imx1-fb.0");
  91. clk_register_clkdev(clk[IMX1_CLK_DUMMY], "ipg", "imx1-fb.0");
  92. clk_register_clkdev(clk[IMX1_CLK_DUMMY], "ahb", "imx1-fb.0");
  93. mxc_timer_init(MX1_TIM1_BASE_ADDR, MX1_TIM1_INT, GPT_TYPE_IMX1);
  94. return 0;
  95. }
  96. static void __init mx1_clocks_init_dt(struct device_node *np)
  97. {
  98. ccm = of_iomap(np, 0);
  99. BUG_ON(!ccm);
  100. _mx1_clocks_init(32768);
  101. clk_data.clks = clk;
  102. clk_data.clk_num = ARRAY_SIZE(clk);
  103. of_clk_add_provider(np, of_clk_src_onecell_get, &clk_data);
  104. }
  105. CLK_OF_DECLARE(imx1_ccm, "fsl,imx1-ccm", mx1_clocks_init_dt);