commproc.c 4.9 KB

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