clock.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  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/pll.h>
  22. #include <asm/mach/map.h>
  23. #include <mach/regs-clock.h>
  24. #include <mach/regs-s3c2443-clock.h>
  25. static unsigned int armdiv[8] = {
  26. [0] = 1,
  27. [1] = 2,
  28. [2] = 3,
  29. [3] = 4,
  30. [5] = 6,
  31. [7] = 8,
  32. };
  33. static struct clksrc_clk hsspi_eplldiv = {
  34. .clk = {
  35. .name = "hsspi-eplldiv",
  36. .parent = &clk_esysclk.clk,
  37. .ctrlbit = (1 << 14),
  38. .enable = s3c2443_clkcon_enable_s,
  39. },
  40. .reg_div = { .reg = S3C2443_CLKDIV1, .size = 2, .shift = 24 },
  41. };
  42. static struct clk *hsspi_sources[] = {
  43. [0] = &hsspi_eplldiv.clk,
  44. [1] = NULL, /* to fix */
  45. };
  46. static struct clksrc_clk hsspi_mux = {
  47. .clk = {
  48. .name = "hsspi-if",
  49. },
  50. .sources = &(struct clksrc_sources) {
  51. .sources = hsspi_sources,
  52. .nr_sources = ARRAY_SIZE(hsspi_sources),
  53. },
  54. .reg_src = { .reg = S3C2443_CLKSRC, .size = 1, .shift = 18 },
  55. };
  56. static struct clksrc_clk hsmmc_div[] = {
  57. [0] = {
  58. .clk = {
  59. .name = "hsmmc-div",
  60. .devname = "s3c-sdhci.0",
  61. .parent = &clk_esysclk.clk,
  62. },
  63. .reg_div = { .reg = S3C2416_CLKDIV2, .size = 2, .shift = 6 },
  64. },
  65. [1] = {
  66. .clk = {
  67. .name = "hsmmc-div",
  68. .devname = "s3c-sdhci.1",
  69. .parent = &clk_esysclk.clk,
  70. },
  71. .reg_div = { .reg = S3C2443_CLKDIV1, .size = 2, .shift = 6 },
  72. },
  73. };
  74. static struct clksrc_clk hsmmc_mux[] = {
  75. [0] = {
  76. .clk = {
  77. .name = "hsmmc-if",
  78. .devname = "s3c-sdhci.0",
  79. .ctrlbit = (1 << 6),
  80. .enable = s3c2443_clkcon_enable_s,
  81. },
  82. .sources = &(struct clksrc_sources) {
  83. .nr_sources = 2,
  84. .sources = (struct clk *[]) {
  85. [0] = &hsmmc_div[0].clk,
  86. [1] = NULL, /* to fix */
  87. },
  88. },
  89. .reg_src = { .reg = S3C2443_CLKSRC, .size = 1, .shift = 16 },
  90. },
  91. [1] = {
  92. .clk = {
  93. .name = "hsmmc-if",
  94. .devname = "s3c-sdhci.1",
  95. .ctrlbit = (1 << 12),
  96. .enable = s3c2443_clkcon_enable_s,
  97. },
  98. .sources = &(struct clksrc_sources) {
  99. .nr_sources = 2,
  100. .sources = (struct clk *[]) {
  101. [0] = &hsmmc_div[1].clk,
  102. [1] = NULL, /* to fix */
  103. },
  104. },
  105. .reg_src = { .reg = S3C2443_CLKSRC, .size = 1, .shift = 17 },
  106. },
  107. };
  108. static struct clk hsmmc0_clk = {
  109. .name = "hsmmc",
  110. .devname = "s3c-sdhci.0",
  111. .parent = &clk_h,
  112. .enable = s3c2443_clkcon_enable_h,
  113. .ctrlbit = S3C2416_HCLKCON_HSMMC0,
  114. };
  115. static inline unsigned int s3c2416_fclk_div(unsigned long clkcon0)
  116. {
  117. clkcon0 &= 7 << S3C2443_CLKDIV0_ARMDIV_SHIFT;
  118. return armdiv[clkcon0 >> S3C2443_CLKDIV0_ARMDIV_SHIFT];
  119. }
  120. void __init_or_cpufreq s3c2416_setup_clocks(void)
  121. {
  122. s3c2443_common_setup_clocks(s3c2416_get_pll, s3c2416_fclk_div);
  123. }
  124. static struct clksrc_clk *clksrcs[] __initdata = {
  125. &hsspi_eplldiv,
  126. &hsspi_mux,
  127. &hsmmc_div[0],
  128. &hsmmc_div[1],
  129. &hsmmc_mux[0],
  130. &hsmmc_mux[1],
  131. };
  132. void __init s3c2416_init_clocks(int xtal)
  133. {
  134. u32 epllcon = __raw_readl(S3C2443_EPLLCON);
  135. u32 epllcon1 = __raw_readl(S3C2443_EPLLCON+4);
  136. int ptr;
  137. /* s3c2416 EPLL compatible with s3c64xx */
  138. clk_epll.rate = s3c_get_pll6553x(xtal, epllcon, epllcon1);
  139. clk_epll.parent = &clk_epllref.clk;
  140. s3c2443_common_init_clocks(xtal, s3c2416_get_pll, s3c2416_fclk_div);
  141. for (ptr = 0; ptr < ARRAY_SIZE(clksrcs); ptr++)
  142. s3c_register_clksrc(clksrcs[ptr], 1);
  143. s3c24xx_register_clock(&hsmmc0_clk);
  144. s3c_pwmclk_init();
  145. }