dataMonitoring.c 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. /*
  2. * R8A7740 processor support
  3. *
  4. * Copyright (C) 2011 Renesas Solutions Corp.
  5. * Copyright (C) 2011 Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  19. */
  20. #include <linux/init.h>
  21. #include <linux/kernel.h>
  22. #include <linux/io.h>
  23. #include <linux/sh_clk.h>
  24. #include <linux/clkdev.h>
  25. #include <mach/common.h>
  26. #include <mach/r8a7740.h>
  27. /*
  28. * | MDx | XTAL1/EXTAL1 | System | EXTALR |
  29. * Clock |-------+-----------------+ clock | 32.768 | RCLK
  30. * Mode | 2/1/0 | src MHz | source | KHz | source
  31. * -------+-------+-----------------+-----------+--------+----------
  32. * 0 | 0 0 0 | External 20~50 | XTAL1 | O | EXTALR
  33. * 1 | 0 0 1 | Crystal 20~30 | XTAL1 | O | EXTALR
  34. * 2 | 0 1 0 | External 40~50 | XTAL1 / 2 | O | EXTALR
  35. * 3 | 0 1 1 | Crystal 40~50 | XTAL1 / 2 | O | EXTALR
  36. * 4 | 1 0 0 | External 20~50 | XTAL1 | x | XTAL1 / 1024
  37. * 5 | 1 0 1 | Crystal 20~30 | XTAL1 | x | XTAL1 / 1024
  38. * 6 | 1 1 0 | External 40~50 | XTAL1 / 2 | x | XTAL1 / 2048
  39. * 7 | 1 1 1 | Crystal 40~50 | XTAL1 / 2 | x | XTAL1 / 2048
  40. */
  41. /* CPG registers */
  42. #define FRQCRA IOMEM(0xe6150000)
  43. #define FRQCRB IOMEM(0xe6150004)
  44. #define VCLKCR1 IOMEM(0xE6150008)
  45. #define VCLKCR2 IOMEM(0xE615000c)
  46. #define FRQCRC IOMEM(0xe61500e0)
  47. #define FSIACKCR IOMEM(0xe6150018)
  48. #define PLLC01CR IOMEM(0xe6150028)
  49. #define SUBCKCR IOMEM(0xe6150080)
  50. #define USBCKCR IOMEM(0xe615008c)
  51. #define MSTPSR0 IOMEM(0xe6150030)
  52. #define MSTPSR1 IOMEM(0xe6150038)
  53. #define MSTPSR2 IOMEM(0xe6150040)
  54. #define MSTPSR3 IOMEM(0xe6150048)
  55. #define MSTPSR4 IOMEM(0xe615004c)
  56. #define FSIBCKCR IOMEM(0xe6150090)
  57. #define HDMICKCR IOMEM(0xe6150094)
  58. #define SMSTPCR0 IOMEM(0xe6150130)
  59. #define SMSTPCR1 IOMEM(0xe6150134)
  60. #define SMSTPCR2 IOMEM(0xe6150138)
  61. #define SMSTPCR3 IOMEM(0xe615013c)
  62. #define SMSTPCR4 IOMEM(0xe6150140)
  63. #define FSIDIVA IOMEM(0xFE1F8000)
  64. #define FSIDIVB IOMEM(0xFE1F8008)
  65. /* Fixed 32 KHz root clock from EXTALR pin */
  66. static struct clk extalr_clk = {
  67. .rate = 32768,
  68. };
  69. /*
  70. * 25MHz default rate for the EXTAL1 root input clock.
  71. * If needed, reset this with clk_set_rate() from the platform code.
  72. */
  73. static struct clk extal1_clk = {
  74. .rate = 25000000,
  75. };
  76. /*
  77. * 48MHz default rate for the EXTAL2 root input clock.
  78. * If needed, reset this with clk_set_rate() from the platform code.
  79. */
  80. static struct clk extal2_clk = {
  81. .rate = 48000000,
  82. };
  83. /*
  84. * 27MHz default rate for the DV_CLKI root input clock.
  85. * If needed, reset this with clk_set_rate() from the platform code.
  86. */
  87. static struct clk dv_clk = {
  88. .rate = 27000000,
  89. };
  90. static unsigned long div_recalc(struct clk *clk)
  91. {
  92. return clk->parent->rate / (int)(clk->priv);
  93. }
  94. static struct sh_clk_ops div_clk_ops = {
  95. .recalc = div_recalc,
  96. };
  97. /* extal1 / 2 */
  98. static struct clk extal1_div2_clk = {
  99. .ops = &div_clk_ops,
  100. .priv = (void *)2,
  101. .parent = &extal1_clk,
  102. };
  103. /* extal1 / 1024 */
  104. static struct clk extal1_div1024_clk = {
  105. .ops = &div_clk_ops,
  106. .priv = (void *)1024,
  107. .parent = &extal1_clk,
  108. };
  109. /* extal1 / 2 / 1024 */
  110. static struct clk extal1_div2048_clk = {
  111. .ops = &div_clk_ops,
  112. .priv = (void *)1024,
  113. .parent = &extal1_div2_clk,
  114. };
  115. /* extal2 / 2 */
  116. static struct clk extal2_div2_clk = {
  117. .ops = &div_clk_ops,
  118. .priv = (void *)2,
  119. .parent = &extal2_clk,
  120. };
  121. static struct sh_clk_ops followparent_clk_ops = {
  122. .recalc = followparent_recalc,
  123. };
  124. /* Main clock */
  125. static struct clk system_clk = {
  126. .ops = &followparent_clk_ops,
  127. };
  128. static struct clk system_div2_clk = {
  129. .ops = &div_clk_ops,
  130. .priv = (void *)2,
  131. .parent = &system_clk,
  132. };
  133. /* r_clk */
  134. static struct clk r_clk = {
  135. .ops = &followparent_clk_ops,
  136. };
  137. /* PLLC0/PLLC1 */
  138. static unsigned long pllc01_recalc(struct clk *clk)
  139. {
  140. unsigned long mult = 1;
  141. if (__raw_readl(PLLC01CR) & (1 << 14))
  142. mult = ((__raw_readl(clk->enable_reg) >> 24) & 0x7f) + 1;
  143. return clk->parent->rate * mult;
  144. }
  145. static struct sh_clk_ops pllc01_clk_ops = {
  146. .recalc = pllc01_recalc,
  147. };
  148. static struct clk pllc0_clk = {
  149. .ops = &pllc01_clk_ops,
  150. .flags = CLK_ENABLE_ON_INIT,
  151. .parent = &system_clk,
  152. .enable_reg = (void __iomem *)FRQCRC,
  153. };
  154. static struct clk pllc1_clk = {
  155. .ops = &pllc01_clk_ops,
  156. .flags = CLK_ENABLE_ON_INIT,
  157. .parent = &system_div2_clk,
  158. .enable_reg = (void __iomem *)FRQCRA,
  159. };
  160. /* PLLC1 / 2 */
  161. static struct clk pllc1_div2_clk = {
  162. .ops = &div_clk_ops,
  163. .priv = (void *)2,
  164. .parent = &pllc1_clk,
  165. };
  166. /* USB clock */
  167. /*
  168. * USBCKCR is controlling usb24 clock
  169. * bit[7] : parent clock
  170. * bit[6] : clock divide rate