commproc.c 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  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. DECLARE_GLOBAL_DATA_PTR;
  23. void
  24. m8260_cpm_reset(void)
  25. {
  26. volatile immap_t *immr = (immap_t *)CFG_IMMR;
  27. volatile ulong count;
  28. /* Reclaim the DP memory for our use.
  29. */
  30. gd->dp_alloc_base = CPM_DATAONLY_BASE;
  31. gd->dp_alloc_top = gd->dp_alloc_base + CPM_DATAONLY_SIZE;
  32. /*
  33. * Reset CPM
  34. */
  35. immr->im_cpm.cp_cpcr = CPM_CR_RST;
  36. count = 0;
  37. do { /* Spin until command processed */
  38. __asm__ __volatile__ ("eieio");
  39. } while ((immr->im_cpm.cp_cpcr & CPM_CR_FLG) && ++count < 1000000);
  40. #ifdef CONFIG_HARD_I2C
  41. *((unsigned short*)(&immr->im_dprambase[PROFF_I2C_BASE])) = 0;
  42. #endif
  43. }
  44. /* Allocate some memory from the dual ported ram.
  45. * To help protocols with object alignment restrictions, we do that
  46. * if they ask.
  47. */
  48. uint
  49. m8260_cpm_dpalloc(uint size, uint align)
  50. {
  51. volatile immap_t *immr = (immap_t *)CFG_IMMR;
  52. uint retloc;
  53. uint align_mask, off;
  54. uint savebase;
  55. align_mask = align - 1;
  56. savebase = gd->dp_alloc_base;
  57. if ((off = (gd->dp_alloc_base & align_mask)) != 0)
  58. gd->dp_alloc_base += (align - off);
  59. if ((off = size & align_mask) != 0)
  60. size += align - off;
  61. if ((gd->dp_alloc_base + size) >= gd->dp_alloc_top) {
  62. gd->dp_alloc_base = savebase;
  63. panic("m8260_cpm_dpalloc: ran out of dual port ram!");
  64. }
  65. retloc = gd->dp_alloc_base;
  66. gd->dp_alloc_base += size;
  67. memset((void *)&immr->im_dprambase[retloc], 0, size);
  68. return(retloc);
  69. }
  70. /* We also own one page of host buffer space for the allocation of
  71. * UART "fifos" and the like.
  72. */
  73. uint
  74. m8260_cpm_hostalloc(uint size, uint align)
  75. {
  76. /* the host might not even have RAM yet - just use dual port RAM */
  77. return (m8260_cpm_dpalloc(size, align));
  78. }
  79. /* Set a baud rate generator. This needs lots of work. There are
  80. * eight BRGs, which can be connected to the CPM channels or output
  81. * as clocks. The BRGs are in two different block of internal
  82. * memory mapped space.
  83. * The baud rate clock is the system clock divided by something.
  84. * It was set up long ago during the initial boot phase and is
  85. * is given to us.
  86. * Baud rate clocks are zero-based in the driver code (as that maps
  87. * to port numbers). Documentation uses 1-based numbering.
  88. */
  89. #define BRG_INT_CLK gd->brg_clk
  90. #define BRG_UART_CLK (BRG_INT_CLK / 16)
  91. /* This function is used by UARTs, or anything else that uses a 16x
  92. * oversampled clock.
  93. */
  94. void
  95. m8260_cpm_setbrg(uint brg, uint rate)
  96. {
  97. volatile immap_t *immr = (immap_t *)CFG_IMMR;
  98. volatile uint *bp;
  99. uint cd = BRG_UART_CLK / rate;
  100. if ((BRG_UART_CLK % rate) < (rate / 2))
  101. cd--;
  102. if (brg < 4) {
  103. bp = (uint *)&immr->im_brgc1;
  104. }
  105. else {
  106. bp = (uint *)&immr->im_brgc5;
  107. brg -= 4;
  108. }
  109. bp += brg;
  110. *bp = (cd << 1) | CPM_BRG_EN;
  111. }
  112. /* This function is used to set high speed synchronous baud rate
  113. * clocks.
  114. */
  115. void
  116. m8260_cpm_fastbrg(uint brg, uint rate, int div16)
  117. {
  118. volatile immap_t *immr = (immap_t *)CFG_IMMR;
  119. volatile uint *bp;
  120. /* This is good enough to get SMCs running.....
  121. */
  122. if (brg < 4) {
  123. bp = (uint *)&immr->im_brgc1;
  124. }
  125. else {
  126. bp = (uint *)&immr->im_brgc5;
  127. brg -= 4;
  128. }
  129. bp += brg;
  130. *bp = (((((BRG_INT_CLK+rate-1)/rate)-1)&0xfff)<<1)|CPM_BRG_EN;
  131. if (div16)
  132. *bp |= CPM_BRG_DIV16;
  133. }
  134. /* This function is used to set baud rate generators using an external
  135. * clock source and 16x oversampling.
  136. */
  137. void
  138. m8260_cpm_extcbrg(uint brg, uint rate, uint extclk, int pinsel)
  139. {
  140. volatile immap_t *immr = (immap_t *)CFG_IMMR;
  141. volatile uint *bp;
  142. if (brg < 4) {
  143. bp = (uint *)&immr->im_brgc1;
  144. }
  145. else {
  146. bp = (uint *)&immr->im_brgc5;
  147. brg -= 4;
  148. }
  149. bp += brg;
  150. *bp = ((((((extclk/16)+rate-1)/rate)-1)&0xfff)<<1)|CPM_BRG_EN;
  151. if (pinsel == 0)
  152. *bp |= CPM_BRG_EXTC_CLK3_9;
  153. else
  154. *bp |= CPM_BRG_EXTC_CLK5_15;
  155. }
  156. #if defined(CONFIG_POST) || defined(CONFIG_LOGBUFFER)
  157. void post_word_store (ulong a)
  158. {
  159. volatile ulong *save_addr =
  160. (volatile ulong *)(CFG_IMMR + CPM_POST_WORD_ADDR);
  161. *save_addr = a;
  162. }
  163. ulong post_word_load (void)
  164. {
  165. volatile ulong *save_addr =
  166. (volatile ulong *)(CFG_IMMR + CPM_POST_WORD_ADDR);
  167. return *save_addr;
  168. }
  169. #endif /* CONFIG_POST || CONFIG_LOGBUFFER*/
  170. #ifdef CONFIG_BOOTCOUNT_LIMIT
  171. void bootcount_store (ulong a)
  172. {
  173. volatile ulong *save_addr =
  174. (volatile ulong *)(CFG_IMMR + CPM_BOOTCOUNT_ADDR);
  175. save_addr[0] = a;
  176. save_addr[1] = BOOTCOUNT_MAGIC;
  177. }
  178. ulong bootcount_load (void)
  179. {
  180. volatile ulong *save_addr =
  181. (volatile ulong *)(CFG_IMMR + CPM_BOOTCOUNT_ADDR);
  182. if (save_addr[1] != BOOTCOUNT_MAGIC)
  183. return 0;
  184. else
  185. return save_addr[0];
  186. }
  187. #endif /* CONFIG_BOOTCOUNT_LIMIT */