cpm2_common.c 4.9 KB

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