cpm2_common.c 4.9 KB

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