clock.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. /* linux/arch/arm/mach-s3c2416/clock.c
  2. *
  3. * Copyright (c) 2010 Simtec Electronics
  4. * Copyright (c) 2010 Ben Dooks <ben-linux@fluff.org>
  5. *
  6. * S3C2416 Clock control support
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License, or
  11. * (at your option) any later version.
  12. */
  13. #include <linux/init.h>
  14. #include <linux/clk.h>
  15. #include <plat/s3c2416.h>
  16. #include <plat/s3c2443.h>
  17. #include <plat/clock.h>
  18. #include <plat/clock-clksrc.h>
  19. #include <plat/cpu.h>
  20. #include <plat/cpu-freq.h>
  21. #include <plat/pll6553x.h>
  22. #include <plat/pll.h>
  23. #include <asm/mach/map.h>
  24. #include <mach/regs-clock.h>
  25. #include <mach/regs-s3c2443-clock.h>
  26. static unsigned int armdiv[8] = {
  27. [0] = 1,
  28. [1] = 2,
  29. [2] = 3,
  30. [3] = 4,
  31. [5] = 6,
  32. [7] = 8,
  33. };
  34. /* ID to hardware numbering, 0 is HSMMC1, 1 is HSMMC0 */
  35. static struct clksrc_clk hsmmc_div[] = {
  36. [0] = {
  37. .clk = {
  38. .name = "hsmmc-div",
  39. .id = 1,
  40. .parent = &clk_esysclk.clk,
  41. },
  42. .reg_div = { .reg = S3C2416_CLKDIV2, .size = 2, .shift = 6 },
  43. },
  44. [1] = {
  45. .clk = {
  46. .name = "hsmmc-div",
  47. .id = 0,
  48. .parent = &clk_esysclk.clk,
  49. },
  50. .reg_div = { .reg = S3C2443_CLKDIV1, .size = 2, .shift = 6 },
  51. },
  52. };
  53. static struct clksrc_clk hsmmc_mux[] = {
  54. [0] = {
  55. .clk = {
  56. .id = 1,
  57. .name = "hsmmc-if",
  58. .ctrlbit = (1 << 6),
  59. .enable = s3c2443_clkcon_enable_s,
  60. },
  61. .sources = &(struct clksrc_sources) {
  62. .nr_sources = 2,
  63. .sources = (struct clk *[]) {
  64. [0] = &hsmmc_div[0].clk,
  65. [1] = NULL, /* to fix */
  66. },
  67. },
  68. .reg_src = { .reg = S3C2443_CLKSRC, .size = 1, .shift = 16 },
  69. },
  70. [1] = {
  71. .clk = {
  72. .id = 0,
  73. .name = "hsmmc-if",
  74. .ctrlbit = (1 << 12),
  75. .enable = s3c2443_clkcon_enable_s,
  76. },
  77. .sources = &(struct clksrc_sources) {
  78. .nr_sources = 2,
  79. .sources = (struct clk *[]) {
  80. [0] = &hsmmc_div[1].clk,
  81. [1] = NULL, /* to fix */
  82. },
  83. },
  84. .reg_src = { .reg = S3C2443_CLKSRC, .size = 1, .shift = 17 },
  85. },
  86. };
  87. static inline unsigned int s3c2416_fclk_div(unsigned long clkcon0)
  88. {
  89. clkcon0 &= 7 << S3C2443_CLKDIV0_ARMDIV_SHIFT;
  90. return armdiv[clkcon0 >> S3C2443_CLKDIV0_ARMDIV_SHIFT];
  91. }
  92. void __init_or_cpufreq s3c2416_setup_clocks(void)
  93. {
  94. s3c2443_common_setup_clocks(s3c2416_get_pll, s3c2416_fclk_div);
  95. }
  96. static struct clksrc_clk *clksrcs[] __initdata = {
  97. &hsmmc_div[0],
  98. &hsmmc_div[1],
  99. &hsmmc_mux[0],
  100. &hsmmc_mux[1],
  101. };
  102. void __init s3c2416_init_clocks(int xtal)
  103. {
  104. u32 epllcon = __raw_readl(S3C2443_EPLLCON);
  105. u32 epllcon1 = __raw_readl(S3C2443_EPLLCON+4);
  106. int ptr;
  107. /* s3c2416 EPLL compatible with s3c64xx */
  108. clk_epll.rate = s3c_get_pll6553x(xtal, epllcon, epllcon1);
  109. clk_epll.parent = &clk_epllref.clk;
  110. s3c2443_common_init_clocks(xtal, s3c2416_get_pll, s3c2416_fclk_div);
  111. for (ptr = 0; ptr < ARRAY_SIZE(clksrcs); ptr++)
  112. s3c_register_clksrc(clksrcs[ptr], 1);
  113. s3c_pwmclk_init();
  114. }