clock.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  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. /* armdiv
  26. *
  27. * this clock is sourced from msysclk and can have a number of
  28. * divider values applied to it to then be fed into armclk.
  29. * The real clock definition is done in s3c2443-clock.c,
  30. * only the armdiv divisor table must be defined here.
  31. */
  32. static unsigned int armdiv[8] = {
  33. [0] = 1,
  34. [1] = 2,
  35. [2] = 3,
  36. [3] = 4,
  37. [5] = 6,
  38. [7] = 8,
  39. };
  40. static struct clksrc_clk hsspi_eplldiv = {
  41. .clk = {
  42. .name = "hsspi-eplldiv",
  43. .parent = &clk_esysclk.clk,
  44. .ctrlbit = (1 << 14),
  45. .enable = s3c2443_clkcon_enable_s,
  46. },
  47. .reg_div = { .reg = S3C2443_CLKDIV1, .size = 2, .shift = 24 },
  48. };
  49. static struct clk *hsspi_sources[] = {
  50. [0] = &hsspi_eplldiv.clk,
  51. [1] = NULL, /* to fix */
  52. };
  53. static struct clksrc_clk hsspi_mux = {
  54. .clk = {
  55. .name = "hsspi-if",
  56. },
  57. .sources = &(struct clksrc_sources) {
  58. .sources = hsspi_sources,
  59. .nr_sources = ARRAY_SIZE(hsspi_sources),
  60. },
  61. .reg_src = { .reg = S3C2443_CLKSRC, .size = 1, .shift = 18 },
  62. };
  63. static struct clksrc_clk hsmmc_div[] = {
  64. [0] = {
  65. .clk = {
  66. .name = "hsmmc-div",
  67. .devname = "s3c-sdhci.0",
  68. .parent = &clk_esysclk.clk,
  69. },
  70. .reg_div = { .reg = S3C2416_CLKDIV2, .size = 2, .shift = 6 },
  71. },
  72. [1] = {
  73. .clk = {
  74. .name = "hsmmc-div",
  75. .devname = "s3c-sdhci.1",
  76. .parent = &clk_esysclk.clk,
  77. },
  78. .reg_div = { .reg = S3C2443_CLKDIV1, .size = 2, .shift = 6 },
  79. },
  80. };
  81. static struct clksrc_clk hsmmc_mux0 = {
  82. .clk = {
  83. .name = "hsmmc-if",
  84. .devname = "s3c-sdhci.0",
  85. .ctrlbit = (1 << 6),
  86. .enable = s3c2443_clkcon_enable_s,
  87. },
  88. .sources = &(struct clksrc_sources) {
  89. .nr_sources = 2,
  90. .sources = (struct clk * []) {
  91. [0] = &hsmmc_div[0].clk,
  92. [1] = NULL, /* to fix */
  93. },
  94. },
  95. .reg_src = { .reg = S3C2443_CLKSRC, .size = 1, .shift = 16 },
  96. };
  97. static struct clksrc_clk hsmmc_mux1 = {
  98. .clk = {
  99. .name = "hsmmc-if",
  100. .devname = "s3c-sdhci.1",
  101. .ctrlbit = (1 << 12),
  102. .enable = s3c2443_clkcon_enable_s,
  103. },
  104. .sources = &(struct clksrc_sources) {
  105. .nr_sources = 2,
  106. .sources = (struct clk * []) {
  107. [0] = &hsmmc_div[1].clk,
  108. [1] = NULL, /* to fix */
  109. },
  110. },
  111. .reg_src = { .reg = S3C2443_CLKSRC, .size = 1, .shift = 17 },
  112. };
  113. static struct clk hsmmc0_clk = {
  114. .name = "hsmmc",
  115. .devname = "s3c-sdhci.0",
  116. .parent = &clk_h,
  117. .enable = s3c2443_clkcon_enable_h,
  118. .ctrlbit = S3C2416_HCLKCON_HSMMC0,
  119. };
  120. void __init_or_cpufreq s3c2416_setup_clocks(void)
  121. {
  122. s3c2443_common_setup_clocks(s3c2416_get_pll);
  123. }
  124. static struct clksrc_clk *clksrcs[] __initdata = {
  125. &hsspi_eplldiv,
  126. &hsspi_mux,
  127. &hsmmc_div[0],
  128. &hsmmc_div[1],
  129. &hsmmc_mux0,
  130. &hsmmc_mux1,
  131. };
  132. static struct clk_lookup s3c2416_clk_lookup[] = {
  133. CLKDEV_INIT("s3c-sdhci.0", "mmc_busclk.0", &hsmmc0_clk),
  134. CLKDEV_INIT("s3c-sdhci.0", "mmc_busclk.2", &hsmmc_mux0.clk),
  135. CLKDEV_INIT("s3c-sdhci.1", "mmc_busclk.2", &hsmmc_mux1.clk),
  136. };
  137. void __init s3c2416_init_clocks(int xtal)
  138. {
  139. u32 epllcon = __raw_readl(S3C2443_EPLLCON);
  140. u32 epllcon1 = __raw_readl(S3C2443_EPLLCON+4);
  141. int ptr;
  142. /* s3c2416 EPLL compatible with s3c64xx */
  143. clk_epll.rate = s3c_get_pll6553x(xtal, epllcon, epllcon1);
  144. clk_epll.parent = &clk_epllref.clk;
  145. s3c2443_common_init_clocks(xtal, s3c2416_get_pll,
  146. armdiv, ARRAY_SIZE(armdiv),
  147. S3C2416_CLKDIV0_ARMDIV_MASK);
  148. for (ptr = 0; ptr < ARRAY_SIZE(clksrcs); ptr++)
  149. s3c_register_clksrc(clksrcs[ptr], 1);
  150. s3c24xx_register_clock(&hsmmc0_clk);
  151. clkdev_add_table(s3c2416_clk_lookup, ARRAY_SIZE(s3c2416_clk_lookup));
  152. s3c_pwmclk_init();
  153. }