cmu.c 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  1. /*
  2. * cmu.c, Clock Mask Unit routines for the NEC VR4100 series.
  3. *
  4. * Copyright (C) 2001-2002 MontaVista Software Inc.
  5. * Author: Yoichi Yuasa <source@mvista.com>
  6. * Copyright (C) 2003-2005 Yoichi Yuasa <yuasa@linux-mips.org>
  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. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  21. */
  22. /*
  23. * Changes:
  24. * MontaVista Software Inc. <source@mvista.com>
  25. * - New creation, NEC VR4122 and VR4131 are supported.
  26. * - Added support for NEC VR4111 and VR4121.
  27. *
  28. * Yoichi Yuasa <yuasa@linux-mips.org>
  29. * - Added support for NEC VR4133.
  30. */
  31. #include <linux/init.h>
  32. #include <linux/ioport.h>
  33. #include <linux/module.h>
  34. #include <linux/smp.h>
  35. #include <linux/spinlock.h>
  36. #include <linux/types.h>
  37. #include <asm/cpu.h>
  38. #include <asm/io.h>
  39. #include <asm/vr41xx/vr41xx.h>
  40. #define CMU_TYPE1_BASE 0x0b000060UL
  41. #define CMU_TYPE1_SIZE 0x4
  42. #define CMU_TYPE2_BASE 0x0f000060UL
  43. #define CMU_TYPE2_SIZE 0x4
  44. #define CMU_TYPE3_BASE 0x0f000060UL
  45. #define CMU_TYPE3_SIZE 0x8
  46. #define CMUCLKMSK 0x0
  47. #define MSKPIU 0x0001
  48. #define MSKSIU 0x0002
  49. #define MSKAIU 0x0004
  50. #define MSKKIU 0x0008
  51. #define MSKFIR 0x0010
  52. #define MSKDSIU 0x0820
  53. #define MSKCSI 0x0040
  54. #define MSKPCIU 0x0080
  55. #define MSKSSIU 0x0100
  56. #define MSKSHSP 0x0200
  57. #define MSKFFIR 0x0400
  58. #define MSKSCSI 0x1000
  59. #define MSKPPCIU 0x2000
  60. #define CMUCLKMSK2 0x4
  61. #define MSKCEU 0x0001
  62. #define MSKMAC0 0x0002
  63. #define MSKMAC1 0x0004
  64. static void __iomem *cmu_base;
  65. static uint16_t cmuclkmsk, cmuclkmsk2;
  66. static DEFINE_SPINLOCK(cmu_lock);
  67. #define cmu_read(offset) readw(cmu_base + (offset))
  68. #define cmu_write(offset, value) writew((value), cmu_base + (offset))
  69. void vr41xx_supply_clock(vr41xx_clock_t clock)
  70. {
  71. spin_lock_irq(&cmu_lock);
  72. switch (clock) {
  73. case PIU_CLOCK:
  74. cmuclkmsk |= MSKPIU;
  75. break;
  76. case SIU_CLOCK:
  77. cmuclkmsk |= MSKSIU | MSKSSIU;
  78. break;
  79. case AIU_CLOCK:
  80. cmuclkmsk |= MSKAIU;
  81. break;
  82. case KIU_CLOCK:
  83. cmuclkmsk |= MSKKIU;
  84. break;
  85. case FIR_CLOCK:
  86. cmuclkmsk |= MSKFIR | MSKFFIR;
  87. break;
  88. case DSIU_CLOCK:
  89. if (current_cpu_type() == CPU_VR4111 ||
  90. current_cpu_type() == CPU_VR4121)
  91. cmuclkmsk |= MSKDSIU;
  92. else
  93. cmuclkmsk |= MSKSIU | MSKDSIU;
  94. break;
  95. case CSI_CLOCK:
  96. cmuclkmsk |= MSKCSI | MSKSCSI;
  97. break;
  98. case PCIU_CLOCK:
  99. cmuclkmsk |= MSKPCIU;
  100. break;
  101. case HSP_CLOCK:
  102. cmuclkmsk |= MSKSHSP;
  103. break;
  104. case PCI_CLOCK:
  105. cmuclkmsk |= MSKPPCIU;
  106. break;
  107. case CEU_CLOCK:
  108. cmuclkmsk2 |= MSKCEU;
  109. break;
  110. case ETHER0_CLOCK:
  111. cmuclkmsk2 |= MSKMAC0;
  112. break;
  113. case ETHER1_CLOCK:
  114. cmuclkmsk2 |= MSKMAC1;
  115. break;
  116. default:
  117. break;
  118. }
  119. if (clock == CEU_CLOCK || clock == ETHER0_CLOCK ||
  120. clock == ETHER1_CLOCK)
  121. cmu_write(CMUCLKMSK2, cmuclkmsk2);
  122. else
  123. cmu_write(CMUCLKMSK, cmuclkmsk);
  124. spin_unlock_irq(&cmu_lock);
  125. }
  126. EXPORT_SYMBOL_GPL(vr41xx_supply_clock);
  127. void vr41xx_mask_clock(vr41xx_clock_t clock)
  128. {
  129. spin_lock_irq(&cmu_lock);
  130. switch (clock) {
  131. case PIU_CLOCK:
  132. cmuclkmsk &= ~MSKPIU;
  133. break;
  134. case SIU_CLOCK:
  135. if (current_cpu_type() == CPU_VR4111 ||
  136. current_cpu_type() == CPU_VR4121) {
  137. cmuclkmsk &= ~(MSKSIU | MSKSSIU);
  138. } else {
  139. if (cmuclkmsk & MSKDSIU)
  140. cmuclkmsk &= ~MSKSSIU;
  141. else
  142. cmuclkmsk &= ~(MSKSIU | MSKSSIU);
  143. }
  144. break;
  145. case AIU_CLOCK:
  146. cmuclkmsk &= ~MSKAIU;
  147. break;
  148. case KIU_CLOCK:
  149. cmuclkmsk &= ~MSKKIU;
  150. break;
  151. case FIR_CLOCK:
  152. cmuclkmsk &= ~(MSKFIR | MSKFFIR);
  153. break;
  154. case DSIU_CLOCK:
  155. if (current_cpu_type() == CPU_VR4111 ||
  156. current_cpu_type() == CPU_VR4121) {
  157. cmuclkmsk &= ~MSKDSIU;
  158. } else {
  159. if (cmuclkmsk & MSKSSIU)
  160. cmuclkmsk &= ~MSKDSIU;
  161. else
  162. cmuclkmsk &= ~(MSKSIU | MSKDSIU);
  163. }
  164. break;
  165. case CSI_CLOCK:
  166. cmuclkmsk &= ~(MSKCSI | MSKSCSI);
  167. break;
  168. case PCIU_CLOCK:
  169. cmuclkmsk &= ~MSKPCIU;
  170. break;
  171. case HSP_CLOCK:
  172. cmuclkmsk &= ~MSKSHSP;
  173. break;
  174. case PCI_CLOCK:
  175. cmuclkmsk &= ~MSKPPCIU;
  176. break;
  177. case CEU_CLOCK:
  178. cmuclkmsk2 &= ~MSKCEU;
  179. break;
  180. case ETHER0_CLOCK:
  181. cmuclkmsk2 &= ~MSKMAC0;
  182. break;
  183. case ETHER1_CLOCK:
  184. cmuclkmsk2 &= ~MSKMAC1;
  185. break;
  186. default:
  187. break;
  188. }
  189. if (clock == CEU_CLOCK || clock == ETHER0_CLOCK ||
  190. clock == ETHER1_CLOCK)
  191. cmu_write(CMUCLKMSK2, cmuclkmsk2);
  192. else
  193. cmu_write(CMUCLKMSK, cmuclkmsk);
  194. spin_unlock_irq(&cmu_lock);
  195. }
  196. EXPORT_SYMBOL_GPL(vr41xx_mask_clock);
  197. static int __init vr41xx_cmu_init(void)
  198. {
  199. unsigned long start, size;
  200. switch (current_cpu_type()) {
  201. case CPU_VR4111:
  202. case CPU_VR4121:
  203. start = CMU_TYPE1_BASE;
  204. size = CMU_TYPE1_SIZE;
  205. break;
  206. case CPU_VR4122:
  207. case CPU_VR4131:
  208. start = CMU_TYPE2_BASE;
  209. size = CMU_TYPE2_SIZE;
  210. break;
  211. case CPU_VR4133:
  212. start = CMU_TYPE3_BASE;
  213. size = CMU_TYPE3_SIZE;
  214. break;
  215. default:
  216. panic("Unexpected CPU of NEC VR4100 series");
  217. break;
  218. }
  219. if (request_mem_region(start, size, "CMU") == NULL)
  220. return -EBUSY;
  221. cmu_base = ioremap(start, size);
  222. if (cmu_base == NULL) {
  223. release_mem_region(start, size);
  224. return -EBUSY;
  225. }
  226. cmuclkmsk = cmu_read(CMUCLKMSK);
  227. if (current_cpu_type() == CPU_VR4133)
  228. cmuclkmsk2 = cmu_read(CMUCLKMSK2);
  229. spin_lock_init(&cmu_lock);
  230. return 0;
  231. }
  232. core_initcall(vr41xx_cmu_init);