commproc.c 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. /*
  2. * Adapted for Motorola MPC8560 chips
  3. * Xianghua Xiao <x.xiao@motorola.com>
  4. *
  5. * This file is based on "arch/ppc/8260_io/commproc.c" - here is it's
  6. * copyright notice:
  7. *
  8. * General Purpose functions for the global management of the
  9. * 8220 Communication Processor Module.
  10. * Copyright (c) 1999 Dan Malek (dmalek@jlc.net)
  11. * Copyright (c) 2000 MontaVista Software, Inc (source@mvista.com)
  12. * 2.3.99 Updates
  13. * Copyright (c) 2003 Motorola,Inc.
  14. *
  15. * In addition to the individual control of the communication
  16. * channels, there are a few functions that globally affect the
  17. * communication processor.
  18. *
  19. * Buffer descriptors must be allocated from the dual ported memory
  20. * space. The allocator for that is here. When the communication
  21. * process is reset, we reclaim the memory available. There is
  22. * currently no deallocator for this memory.
  23. */
  24. #include <common.h>
  25. #include <asm/cpm_85xx.h>
  26. #if defined(CONFIG_MPC8560)
  27. /*
  28. * because we have stack and init data in dual port ram
  29. * we must reduce the size
  30. */
  31. #undef CPM_DATAONLY_SIZE
  32. #define CPM_DATAONLY_SIZE ((uint)(8 * 1024) - CPM_DATAONLY_BASE)
  33. void
  34. m8560_cpm_reset(void)
  35. {
  36. DECLARE_GLOBAL_DATA_PTR;
  37. volatile immap_t *immr = (immap_t *)CFG_IMMR;
  38. volatile ulong count;
  39. gd = (gd_t *) (CFG_INIT_RAM_ADDR + CFG_GBL_DATA_OFFSET);
  40. /* Reclaim the DP memory for our use.
  41. */
  42. gd->dp_alloc_base = CPM_DATAONLY_BASE;
  43. gd->dp_alloc_top = gd->dp_alloc_base + CPM_DATAONLY_SIZE;
  44. /*
  45. * Reset CPM
  46. */
  47. immr->im_cpm.im_cpm_cp.cpcr = CPM_CR_RST;
  48. count = 0;
  49. do { /* Spin until command processed */
  50. __asm__ __volatile__ ("eieio");
  51. } while ((immr->im_cpm.im_cpm_cp.cpcr & CPM_CR_FLG) && ++count < 1000000);
  52. }
  53. /* Allocate some memory from the dual ported ram.
  54. * To help protocols with object alignment restrictions, we do that
  55. * if they ask.
  56. */
  57. uint
  58. m8560_cpm_dpalloc(uint size, uint align)
  59. {
  60. DECLARE_GLOBAL_DATA_PTR;
  61. volatile immap_t *immr = (immap_t *)CFG_IMMR;
  62. uint retloc;
  63. uint align_mask, off;
  64. uint savebase;
  65. align_mask = align - 1;
  66. savebase = gd->dp_alloc_base;
  67. if ((off = (gd->dp_alloc_base & align_mask)) != 0)
  68. gd->dp_alloc_base += (align - off);
  69. if ((off = size & align_mask) != 0)
  70. size += align - off;
  71. if ((gd->dp_alloc_base + size) >= gd->dp_alloc_top) {
  72. gd->dp_alloc_base = savebase;
  73. panic("m8560_cpm_dpalloc: ran out of dual port ram!");
  74. }
  75. retloc = gd->dp_alloc_base;
  76. gd->dp_alloc_base += size;
  77. memset((void *)&(immr->im_cpm.im_dprambase[retloc]), 0, size);
  78. return(retloc);
  79. }
  80. /* We also own one page of host buffer space for the allocation of
  81. * UART "fifos" and the like.
  82. */
  83. uint
  84. m8560_cpm_hostalloc(uint size, uint align)
  85. {
  86. /* the host might not even have RAM yet - just use dual port RAM */
  87. return (m8560_cpm_dpalloc(size, align));
  88. }
  89. /* Set a baud rate generator. This needs lots of work. There are
  90. * eight BRGs, which can be connected to the CPM channels or output
  91. * as clocks. The BRGs are in two different block of internal
  92. * memory mapped space.
  93. * The baud rate clock is the system clock divided by something.
  94. * It was set up long ago during the initial boot phase and is
  95. * is given to us.
  96. * Baud rate clocks are zero-based in the driver code (as that maps
  97. * to port numbers). Documentation uses 1-based numbering.
  98. */
  99. #define BRG_INT_CLK gd->brg_clk
  100. #define BRG_UART_CLK ((BRG_INT_CLK + 15) / 16)
  101. /* This function is used by UARTS, or anything else that uses a 16x
  102. * oversampled clock.
  103. */
  104. void
  105. m8560_cpm_setbrg(uint brg, uint rate)
  106. {
  107. DECLARE_GLOBAL_DATA_PTR;
  108. volatile immap_t *immr = (immap_t *)CFG_IMMR;
  109. volatile uint *bp;
  110. /* This is good enough to get SMCs running.....
  111. */
  112. if (brg < 4) {
  113. bp = (uint *)&(immr->im_cpm.im_cpm_brg1.brgc1);
  114. }
  115. else {
  116. bp = (uint *)&(immr->im_cpm.im_cpm_brg2.brgc5);
  117. brg -= 4;
  118. }
  119. bp += brg;
  120. *bp = (((((BRG_UART_CLK+rate-1)/rate)-1)&0xfff)<<1)|CPM_BRG_EN;
  121. }
  122. /* This function is used to set high speed synchronous baud rate
  123. * clocks.
  124. */
  125. void
  126. m8560_cpm_fastbrg(uint brg, uint rate, int div16)
  127. {
  128. DECLARE_GLOBAL_DATA_PTR;
  129. volatile immap_t *immr = (immap_t *)CFG_IMMR;
  130. volatile uint *bp;
  131. /* This is good enough to get SMCs running.....
  132. */
  133. if (brg < 4) {
  134. bp = (uint *)&(immr->im_cpm.im_cpm_brg1.brgc1);
  135. }
  136. else {
  137. bp = (uint *)&(immr->im_cpm.im_cpm_brg2.brgc5);
  138. brg -= 4;
  139. }
  140. bp += brg;
  141. *bp = (((((BRG_INT_CLK+rate-1)/rate)-1)&0xfff)<<1)|CPM_BRG_EN;
  142. if (div16)
  143. *bp |= CPM_BRG_DIV16;
  144. }
  145. /* This function is used to set baud rate generators using an external
  146. * clock source and 16x oversampling.
  147. */
  148. void
  149. m8560_cpm_extcbrg(uint brg, uint rate, uint extclk, int pinsel)
  150. {
  151. volatile immap_t *immr = (immap_t *)CFG_IMMR;
  152. volatile uint *bp;
  153. if (brg < 4) {
  154. bp = (uint *)&(immr->im_cpm.im_cpm_brg1.brgc1);
  155. }
  156. else {
  157. bp = (uint *)&(immr->im_cpm.im_cpm_brg2.brgc5);
  158. brg -= 4;
  159. }
  160. bp += brg;
  161. *bp = ((((((extclk/16)+rate-1)/rate)-1)&0xfff)<<1)|CPM_BRG_EN;
  162. if (pinsel == 0)
  163. *bp |= CPM_BRG_EXTC_CLK3_9;
  164. else
  165. *bp |= CPM_BRG_EXTC_CLK5_15;
  166. }
  167. #ifdef CONFIG_POST
  168. void post_word_store (ulong a)
  169. {
  170. volatile ulong *save_addr =
  171. (volatile ulong *)(CFG_IMMR + CPM_POST_WORD_ADDR);
  172. *save_addr = a;
  173. }
  174. ulong post_word_load (void)
  175. {
  176. volatile ulong *save_addr =
  177. (volatile ulong *)(CFG_IMMR + CPM_POST_WORD_ADDR);
  178. return *save_addr;
  179. }
  180. #endif /* CONFIG_POST */
  181. #endif /* CONFIG_MPC8560 */