cpm2_common.c 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. /*
  2. * General Purpose functions for the global management of the
  3. * 8260 Communication Processor Module.
  4. * Copyright (c) 1999-2001 Dan Malek <dan@embeddedalley.com>
  5. * Copyright (c) 2000 MontaVista Software, Inc (source@mvista.com)
  6. * 2.3.99 Updates
  7. *
  8. * 2006 (c) MontaVista Software, Inc.
  9. * Vitaly Bordug <vbordug@ru.mvista.com>
  10. * Merged to arch/powerpc from arch/ppc/syslib/cpm2_common.c
  11. *
  12. * This file is licensed under the terms of the GNU General Public License
  13. * version 2. This program is licensed "as is" without any warranty of any
  14. * kind, whether express or implied.
  15. */
  16. /*
  17. *
  18. * In addition to the individual control of the communication
  19. * channels, there are a few functions that globally affect the
  20. * communication processor.
  21. *
  22. * Buffer descriptors must be allocated from the dual ported memory
  23. * space. The allocator for that is here. When the communication
  24. * process is reset, we reclaim the memory available. There is
  25. * currently no deallocator for this memory.
  26. */
  27. #include <linux/errno.h>
  28. #include <linux/sched.h>
  29. #include <linux/kernel.h>
  30. #include <linux/param.h>
  31. #include <linux/string.h>
  32. #include <linux/mm.h>
  33. #include <linux/interrupt.h>
  34. #include <linux/module.h>
  35. #include <asm/io.h>
  36. #include <asm/irq.h>
  37. #include <asm/mpc8260.h>
  38. #include <asm/page.h>
  39. #include <asm/pgtable.h>
  40. #include <asm/cpm2.h>
  41. #include <asm/rheap.h>
  42. #include <asm/fs_pd.h>
  43. #include <sysdev/fsl_soc.h>
  44. static void cpm2_dpinit(void);
  45. cpm_cpm2_t *cpmp; /* Pointer to comm processor space */
  46. /* We allocate this here because it is used almost exclusively for
  47. * the communication processor devices.
  48. */
  49. cpm2_map_t *cpm2_immr;
  50. #define CPM_MAP_SIZE (0x40000) /* 256k - the PQ3 reserve this amount
  51. of space for CPM as it is larger
  52. than on PQ2 */
  53. void
  54. cpm2_reset(void)
  55. {
  56. cpm2_immr = (cpm2_map_t *)ioremap(CPM_MAP_ADDR, CPM_MAP_SIZE);
  57. /* Reclaim the DP memory for our use.
  58. */
  59. cpm2_dpinit();
  60. /* Tell everyone where the comm processor resides.
  61. */
  62. cpmp = &cpm2_immr->im_cpm;
  63. }
  64. /* Set a baud rate generator. This needs lots of work. There are
  65. * eight BRGs, which can be connected to the CPM channels or output
  66. * as clocks. The BRGs are in two different block of internal
  67. * memory mapped space.
  68. * The baud rate clock is the system clock divided by something.
  69. * It was set up long ago during the initial boot phase and is
  70. * is given to us.
  71. * Baud rate clocks are zero-based in the driver code (as that maps
  72. * to port numbers). Documentation uses 1-based numbering.
  73. */
  74. #define BRG_INT_CLK (get_brgfreq())
  75. #define BRG_UART_CLK (BRG_INT_CLK/16)
  76. /* This function is used by UARTS, or anything else that uses a 16x
  77. * oversampled clock.
  78. */
  79. void
  80. cpm_setbrg(uint brg, uint rate)
  81. {
  82. volatile uint *bp;
  83. /* This is good enough to get SMCs running.....
  84. */
  85. if (brg < 4) {
  86. bp = (uint *)&cpm2_immr->im_brgc1;
  87. } else {
  88. bp = (uint *)&cpm2_immr->im_brgc5;
  89. brg -= 4;
  90. }
  91. bp += brg;
  92. *bp = ((BRG_UART_CLK / rate) << 1) | CPM_BRG_EN;
  93. }
  94. /* This function is used to set high speed synchronous baud rate
  95. * clocks.
  96. */
  97. void
  98. cpm2_fastbrg(uint brg, uint rate, int div16)
  99. {
  100. volatile uint *bp;
  101. if (brg < 4) {
  102. bp = (uint *)&cpm2_immr->im_brgc1;
  103. }
  104. else {
  105. bp = (uint *)&cpm2_immr->im_brgc5;
  106. brg -= 4;
  107. }
  108. bp += brg;
  109. *bp = ((BRG_INT_CLK / rate) << 1) | CPM_BRG_EN;
  110. if (div16)
  111. *bp |= CPM_BRG_DIV16;
  112. }
  113. /*
  114. * dpalloc / dpfree bits.
  115. */
  116. static spinlock_t cpm_dpmem_lock;
  117. /* 16 blocks should be enough to satisfy all requests
  118. * until the memory subsystem goes up... */
  119. static rh_block_t cpm_boot_dpmem_rh_block[16];
  120. static rh_info_t cpm_dpmem_info;
  121. static void cpm2_dpinit(void)
  122. {
  123. spin_lock_init(&cpm_dpmem_lock);
  124. /* initialize the info header */
  125. rh_init(&cpm_dpmem_info, 1,
  126. sizeof(cpm_boot_dpmem_rh_block) /
  127. sizeof(cpm_boot_dpmem_rh_block[0]),
  128. cpm_boot_dpmem_rh_block);
  129. /* Attach the usable dpmem area */
  130. /* XXX: This is actually crap. CPM_DATAONLY_BASE and
  131. * CPM_DATAONLY_SIZE is only a subset of the available dpram. It
  132. * varies with the processor and the microcode patches activated.
  133. * But the following should be at least safe.
  134. */
  135. rh_attach_region(&cpm_dpmem_info, (void *)CPM_DATAONLY_BASE,
  136. CPM_DATAONLY_SIZE);
  137. }
  138. /* This function returns an index into the DPRAM area.
  139. */
  140. uint cpm_dpalloc(uint size, uint align)
  141. {
  142. void *start;
  143. unsigned long flags;
  144. spin_lock_irqsave(&cpm_dpmem_lock, flags);
  145. cpm_dpmem_info.alignment = align;
  146. start = rh_alloc(&cpm_dpmem_info, size, "commproc");
  147. spin_unlock_irqrestore(&cpm_dpmem_lock, flags);
  148. return (uint)start;
  149. }
  150. EXPORT_SYMBOL(cpm_dpalloc);
  151. int cpm_dpfree(uint offset)
  152. {
  153. int ret;
  154. unsigned long flags;
  155. spin_lock_irqsave(&cpm_dpmem_lock, flags);
  156. ret = rh_free(&cpm_dpmem_info, (void *)offset);
  157. spin_unlock_irqrestore(&cpm_dpmem_lock, flags);
  158. return ret;
  159. }
  160. EXPORT_SYMBOL(cpm_dpfree);
  161. /* not sure if this is ever needed */
  162. uint cpm_dpalloc_fixed(uint offset, uint size, uint align)
  163. {
  164. void *start;
  165. unsigned long flags;
  166. spin_lock_irqsave(&cpm_dpmem_lock, flags);
  167. cpm_dpmem_info.alignment = align;
  168. start = rh_alloc_fixed(&cpm_dpmem_info, (void *)offset, size, "commproc");
  169. spin_unlock_irqrestore(&cpm_dpmem_lock, flags);
  170. return (uint)start;
  171. }
  172. EXPORT_SYMBOL(cpm_dpalloc_fixed);
  173. void cpm_dpdump(void)
  174. {
  175. rh_dump(&cpm_dpmem_info);
  176. }
  177. EXPORT_SYMBOL(cpm_dpdump);
  178. void *cpm_dpram_addr(uint offset)
  179. {
  180. return (void *)&cpm2_immr->im_dprambase[offset];
  181. }
  182. EXPORT_SYMBOL(cpm_dpram_addr);