clk-imx1.c 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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/kernel.h>
  18. #include <linux/init.h>
  19. #include <linux/clk.h>
  20. #include <linux/io.h>
  21. #include <linux/clkdev.h>
  22. #include <linux/err.h>
  23. #include "clk.h"
  24. #include "common.h"
  25. #include "hardware.h"
  26. /* CCM register addresses */
  27. #define IO_ADDR_CCM(off) (MX1_IO_ADDRESS(MX1_CCM_BASE_ADDR + (off)))
  28. #define CCM_CSCR IO_ADDR_CCM(0x0)
  29. #define CCM_MPCTL0 IO_ADDR_CCM(0x4)
  30. #define CCM_SPCTL0 IO_ADDR_CCM(0xc)
  31. #define CCM_PCDR IO_ADDR_CCM(0x20)
  32. /* SCM register addresses */
  33. #define IO_ADDR_SCM(off) (MX1_IO_ADDRESS(MX1_SCM_BASE_ADDR + (off)))
  34. #define SCM_GCCR IO_ADDR_SCM(0xc)
  35. static const char *prem_sel_clks[] = { "clk32_premult", "clk16m", };
  36. static const char *clko_sel_clks[] = { "per1", "hclk", "clk48m", "clk16m",
  37. "prem", "fclk", };
  38. enum imx1_clks {
  39. dummy, clk32, clk16m_ext, clk16m, clk32_premult, prem, mpll, mpll_gate,
  40. spll, spll_gate, mcu, fclk, hclk, clk48m, per1, per2, per3, clko,
  41. uart3_gate, ssi2_gate, brom_gate, dma_gate, csi_gate, mma_gate,
  42. usbd_gate, clk_max
  43. };
  44. static struct clk *clk[clk_max];
  45. int __init mx1_clocks_init(unsigned long fref)
  46. {
  47. int i;
  48. clk[dummy] = imx_clk_fixed("dummy", 0);
  49. clk[clk32] = imx_clk_fixed("clk32", fref);
  50. clk[clk16m_ext] = imx_clk_fixed("clk16m_ext", 16000000);
  51. clk[clk16m] = imx_clk_gate("clk16m", "clk16m_ext", CCM_CSCR, 17);
  52. clk[clk32_premult] = imx_clk_fixed_factor("clk32_premult", "clk32", 512, 1);
  53. clk[prem] = imx_clk_mux("prem", CCM_CSCR, 16, 1, prem_sel_clks,
  54. ARRAY_SIZE(prem_sel_clks));
  55. clk[mpll] = imx_clk_pllv1("mpll", "clk32_premult", CCM_MPCTL0);
  56. clk[mpll_gate] = imx_clk_gate("mpll_gate", "mpll", CCM_CSCR, 0);
  57. clk[spll] = imx_clk_pllv1("spll", "prem", CCM_SPCTL0);
  58. clk[spll_gate] = imx_clk_gate("spll_gate", "spll", CCM_CSCR, 1);
  59. clk[mcu] = imx_clk_divider("mcu", "clk32_premult", CCM_CSCR, 15, 1);
  60. clk[fclk] = imx_clk_divider("fclk", "mpll_gate", CCM_CSCR, 15, 1);
  61. clk[hclk] = imx_clk_divider("hclk", "spll_gate", CCM_CSCR, 10, 4);
  62. clk[clk48m] = imx_clk_divider("clk48m", "spll_gate", CCM_CSCR, 26, 3);
  63. clk[per1] = imx_clk_divider("per1", "spll_gate", CCM_PCDR, 0, 4);
  64. clk[per2] = imx_clk_divider("per2", "spll_gate", CCM_PCDR, 4, 4);
  65. clk[per3] = imx_clk_divider("per3", "spll_gate", CCM_PCDR, 16, 7);
  66. clk[clko] = imx_clk_mux("clko", CCM_CSCR, 29, 3, clko_sel_clks,
  67. ARRAY_SIZE(clko_sel_clks));
  68. clk[uart3_gate] = imx_clk_gate("uart3_gate", "hclk", SCM_GCCR, 6);
  69. clk[ssi2_gate] = imx_clk_gate("ssi2_gate", "hclk", SCM_GCCR, 5);
  70. clk[brom_gate] = imx_clk_gate("brom_gate", "hclk", SCM_GCCR, 4);
  71. clk[dma_gate] = imx_clk_gate("dma_gate", "hclk", SCM_GCCR, 3);
  72. clk[csi_gate] = imx_clk_gate("csi_gate", "hclk", SCM_GCCR, 2);
  73. clk[mma_gate] = imx_clk_gate("mma_gate", "hclk", SCM_GCCR, 1);
  74. clk[usbd_gate] = imx_clk_gate("usbd_gate", "clk48m", SCM_GCCR, 0);
  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. clk_register_clkdev(clk[dma_gate], "ahb", "imx1-dma");
  80. clk_register_clkdev(clk[hclk], "ipg", "imx1-dma");
  81. clk_register_clkdev(clk[per1], "per", "imx-gpt.0");
  82. clk_register_clkdev(clk[hclk], "ipg", "imx-gpt.0");
  83. clk_register_clkdev(clk[per1], "per", "imx1-uart.0");
  84. clk_register_clkdev(clk[hclk], "ipg", "imx1-uart.0");
  85. clk_register_clkdev(clk[per1], "per", "imx1-uart.1");
  86. clk_register_clkdev(clk[hclk], "ipg", "imx1-uart.1");
  87. clk_register_clkdev(clk[per1], "per", "imx1-uart.2");
  88. clk_register_clkdev(clk[uart3_gate], "ipg", "imx1-uart.2");
  89. clk_register_clkdev(clk[hclk], NULL, "imx1-i2c.0");
  90. clk_register_clkdev(clk[per2], "per", "imx1-cspi.0");
  91. clk_register_clkdev(clk[dummy], "ipg", "imx1-cspi.0");
  92. clk_register_clkdev(clk[per2], "per", "imx1-cspi.1");
  93. clk_register_clkdev(clk[dummy], "ipg", "imx1-cspi.1");
  94. clk_register_clkdev(clk[per2], "per", "imx1-fb.0");
  95. clk_register_clkdev(clk[dummy], "ipg", "imx1-fb.0");
  96. clk_register_clkdev(clk[dummy], "ahb", "imx1-fb.0");
  97. mxc_timer_init(MX1_IO_ADDRESS(MX1_TIM1_BASE_ADDR), MX1_TIM1_INT);
  98. return 0;
  99. }