commproc.c 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. /*
  2. * Adapted for Motorola MPC8560 chips
  3. * Xianghua Xiao <x.xiao@motorola.com>
  4. *
  5. * This file is based on "arch/powerpc/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. DECLARE_GLOBAL_DATA_PTR;
  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. volatile ccsr_cpm_t *cpm = (ccsr_cpm_t *)CONFIG_SYS_MPC85xx_CPM_ADDR;
  37. volatile ulong count;
  38. gd = (gd_t *) (CONFIG_SYS_INIT_RAM_ADDR + CONFIG_SYS_GBL_DATA_OFFSET);
  39. /* Reclaim the DP memory for our use.
  40. */
  41. gd->dp_alloc_base = CPM_DATAONLY_BASE;
  42. gd->dp_alloc_top = gd->dp_alloc_base + CPM_DATAONLY_SIZE;
  43. /*
  44. * Reset CPM
  45. */
  46. cpm->im_cpm_cp.cpcr = CPM_CR_RST;
  47. count = 0;
  48. do { /* Spin until command processed */
  49. __asm__ __volatile__ ("eieio");
  50. } while ((cpm->im_cpm_cp.cpcr & CPM_CR_FLG) && ++count < 1000000);
  51. }
  52. /* Allocate some memory from the dual ported ram.
  53. * To help protocols with object alignment restrictions, we do that
  54. * if they ask.
  55. */
  56. uint
  57. m8560_cpm_dpalloc(uint size, uint align)
  58. {
  59. volatile ccsr_cpm_t *cpm = (ccsr_cpm_t *)CONFIG_SYS_MPC85xx_CPM_ADDR;
  60. uint retloc;
  61. uint align_mask, off;
  62. uint savebase;
  63. align_mask = align - 1;
  64. savebase = gd->dp_alloc_base;
  65. if ((off = (gd->dp_alloc_base & align_mask)) != 0)
  66. gd->dp_alloc_base += (align - off);
  67. if ((off = size & align_mask) != 0)
  68. size += align - off;
  69. if ((gd->dp_alloc_base + size) >= gd->dp_alloc_top) {
  70. gd->dp_alloc_base = savebase;
  71. panic("m8560_cpm_dpalloc: ran out of dual port ram!");
  72. }
  73. retloc = gd->dp_alloc_base;
  74. gd->dp_alloc_base += size;
  75. memset((void *)&(cpm->im_dprambase[retloc]), 0, size);
  76. return(retloc);
  77. }
  78. /* We also own one page of host buffer space for the allocation of
  79. * UART "fifos" and the like.
  80. */
  81. uint
  82. m8560_cpm_hostalloc(uint size, uint align)
  83. {
  84. /* the host might not even have RAM yet - just use dual port RAM */
  85. return (m8560_cpm_dpalloc(size, align));
  86. }
  87. /* Set a baud rate generator. This needs lots of work. There are
  88. * eight BRGs, which can be connected to the CPM channels or output
  89. * as clocks. The BRGs are in two different block of internal
  90. * memory mapped space.
  91. * The baud rate clock is the system clock divided by something.
  92. * It was set up long ago during the initial boot phase and is
  93. * is given to us.
  94. * Baud rate clocks are zero-based in the driver code (as that maps
  95. * to port numbers). Documentation uses 1-based numbering.
  96. */
  97. #define BRG_INT_CLK gd->brg_clk
  98. #define BRG_UART_CLK ((BRG_INT_CLK + 15) / 16)
  99. /* This function is used by UARTS, or anything else that uses a 16x
  100. * oversampled clock.
  101. */
  102. void
  103. m8560_cpm_setbrg(uint brg, uint rate)
  104. {
  105. volatile ccsr_cpm_t *cpm = (ccsr_cpm_t *)CONFIG_SYS_MPC85xx_CPM_ADDR;
  106. volatile uint *bp;
  107. /* This is good enough to get SMCs running.....
  108. */
  109. if (brg < 4) {
  110. bp = (uint *)&(cpm->im_cpm_brg1.brgc1);
  111. }
  112. else {
  113. bp = (uint *)&(cpm->im_cpm_brg2.brgc5);
  114. brg -= 4;
  115. }
  116. bp += brg;
  117. *bp = (((((BRG_UART_CLK+rate-1)/rate)-1)&0xfff)<<1)|CPM_BRG_EN;
  118. }
  119. /* This function is used to set high speed synchronous baud rate
  120. * clocks.
  121. */
  122. void
  123. m8560_cpm_fastbrg(uint brg, uint rate, int div16)
  124. {
  125. volatile ccsr_cpm_t *cpm = (ccsr_cpm_t *)CONFIG_SYS_MPC85xx_CPM_ADDR;
  126. volatile uint *bp;
  127. /* This is good enough to get SMCs running.....
  128. */
  129. if (brg < 4) {
  130. bp = (uint *)&(cpm->im_cpm_brg1.brgc1);
  131. }
  132. else {
  133. bp = (uint *)&(cpm->im_cpm_brg2.brgc5);
  134. brg -= 4;
  135. }
  136. bp += brg;
  137. *bp = (((((BRG_INT_CLK+rate-1)/rate)-1)&0xfff)<<1)|CPM_BRG_EN;
  138. if (div16)
  139. *bp |= CPM_BRG_DIV16;
  140. }
  141. /* This function is used to set baud rate generators using an external
  142. * clock source and 16x oversampling.
  143. */
  144. void
  145. m8560_cpm_extcbrg(uint brg, uint rate, uint extclk, int pinsel)
  146. {
  147. volatile ccsr_cpm_t *cpm = (ccsr_cpm_t *)CONFIG_SYS_MPC85xx_CPM_ADDR;
  148. volatile uint *bp;
  149. if (brg < 4) {
  150. bp = (uint *)&(cpm->im_cpm_brg1.brgc1);
  151. }
  152. else {
  153. bp = (uint *)&(cpm->im_cpm_brg2.brgc5);
  154. brg -= 4;
  155. }
  156. bp += brg;
  157. *bp = ((((((extclk/16)+rate-1)/rate)-1)&0xfff)<<1)|CPM_BRG_EN;
  158. if (pinsel == 0)
  159. *bp |= CPM_BRG_EXTC_CLK3_9;
  160. else
  161. *bp |= CPM_BRG_EXTC_CLK5_15;
  162. }