m8xx_tty.c 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  1. /* Minimal serial functions needed to send messages out the serial
  2. * port on the MBX console.
  3. *
  4. * The MBX uxes SMC1 for the serial port. We reset the port and use
  5. * only the first BD that EPPC-Bug set up as a character FIFO.
  6. *
  7. * Later versions (at least 1.4, maybe earlier) of the MBX EPPC-Bug
  8. * use COM1 instead of SMC1 as the console port. This kinda sucks
  9. * for the rest of the kernel, so here we force the use of SMC1 again.
  10. */
  11. #include <linux/config.h>
  12. #include <linux/types.h>
  13. #include <asm/uaccess.h>
  14. #include <asm/mpc8xx.h>
  15. #include <asm/commproc.h>
  16. #ifdef CONFIG_MBX
  17. #define MBX_CSR1 ((volatile u_char *)0xfa100000)
  18. #define CSR1_COMEN (u_char)0x02
  19. #endif
  20. #ifdef TQM_SMC2_CONSOLE
  21. #define PROFF_CONS PROFF_SMC2
  22. #define CPM_CR_CH_CONS CPM_CR_CH_SMC2
  23. #define SMC_INDEX 1
  24. static volatile iop8xx_t *iopp = (iop8xx_t *)&(((immap_t *)IMAP_ADDR)->im_ioport);
  25. #else
  26. #define PROFF_CONS PROFF_SMC1
  27. #define CPM_CR_CH_CONS CPM_CR_CH_SMC1
  28. #define SMC_INDEX 0
  29. #endif
  30. static cpm8xx_t *cpmp = (cpm8xx_t *)&(((immap_t *)IMAP_ADDR)->im_cpm);
  31. unsigned long
  32. serial_init(int ignored, bd_t *bd)
  33. {
  34. volatile smc_t *sp;
  35. volatile smc_uart_t *up;
  36. volatile cbd_t *tbdf, *rbdf;
  37. volatile cpm8xx_t *cp;
  38. uint dpaddr, memaddr;
  39. #ifndef CONFIG_MBX
  40. uint ui;
  41. #endif
  42. cp = cpmp;
  43. sp = (smc_t*)&(cp->cp_smc[SMC_INDEX]);
  44. up = (smc_uart_t *)&cp->cp_dparam[PROFF_CONS];
  45. /* Disable transmitter/receiver.
  46. */
  47. sp->smc_smcmr &= ~(SMCMR_REN | SMCMR_TEN);
  48. #ifdef CONFIG_FADS
  49. /* Enable SMC1/2 transceivers.
  50. */
  51. *((volatile uint *)BCSR1) &= ~(BCSR1_RS232EN_1|BCSR1_RS232EN_2);
  52. #endif
  53. #ifndef CONFIG_MBX
  54. {
  55. /* Initialize SMCx and use it for the console port.
  56. */
  57. /* Enable SDMA.
  58. */
  59. ((immap_t *)IMAP_ADDR)->im_siu_conf.sc_sdcr = 1;
  60. #ifdef TQM_SMC2_CONSOLE
  61. /* Use Port A for SMC2 instead of other functions.
  62. */
  63. iopp->iop_papar |= 0x00c0;
  64. iopp->iop_padir &= ~0x00c0;
  65. iopp->iop_paodr &= ~0x00c0;
  66. #else
  67. /* Use Port B for SMCs instead of other functions.
  68. */
  69. cp->cp_pbpar |= 0x00000cc0;
  70. cp->cp_pbdir &= ~0x00000cc0;
  71. cp->cp_pbodr &= ~0x00000cc0;
  72. #endif
  73. /* Allocate space for two buffer descriptors in the DP ram.
  74. * For now, this address seems OK, but it may have to
  75. * change with newer versions of the firmware.
  76. */
  77. dpaddr = 0x0800;
  78. /* Grab a few bytes from the top of memory for SMC FIFOs.
  79. */
  80. memaddr = (bd->bi_memsize - 32) & ~15;
  81. /* Set the physical address of the host memory buffers in
  82. * the buffer descriptors.
  83. */
  84. rbdf = (cbd_t *)&cp->cp_dpmem[dpaddr];
  85. rbdf->cbd_bufaddr = memaddr;
  86. rbdf->cbd_sc = 0;
  87. tbdf = rbdf + 1;
  88. tbdf->cbd_bufaddr = memaddr+4;
  89. tbdf->cbd_sc = 0;
  90. /* Set up the uart parameters in the parameter ram.
  91. */
  92. up->smc_rbase = dpaddr;
  93. up->smc_tbase = dpaddr+sizeof(cbd_t);
  94. up->smc_rfcr = SMC_EB;
  95. up->smc_tfcr = SMC_EB;
  96. /* Set UART mode, 8 bit, no parity, one stop.
  97. * Enable receive and transmit.
  98. */
  99. sp->smc_smcmr = smcr_mk_clen(9) | SMCMR_SM_UART;
  100. /* Mask all interrupts and remove anything pending.
  101. */
  102. sp->smc_smcm = 0;
  103. sp->smc_smce = 0xff;
  104. /* Set up the baud rate generator.
  105. * See 8xx_io/commproc.c for details.
  106. * This wires BRG1 to SMC1 and BRG2 to SMC2;
  107. */
  108. cp->cp_simode = 0x10000000;
  109. ui = bd->bi_intfreq / 16 / bd->bi_baudrate;
  110. #ifdef TQM_SMC2_CONSOLE
  111. cp->cp_brgc2 =
  112. #else
  113. cp->cp_brgc1 =
  114. #endif
  115. ((ui - 1) < 4096)
  116. ? (((ui - 1) << 1) | CPM_BRG_EN)
  117. : ((((ui / 16) - 1) << 1) | CPM_BRG_EN | CPM_BRG_DIV16);
  118. #else /* CONFIG_MBX */
  119. if (*MBX_CSR1 & CSR1_COMEN) {
  120. /* COM1 is enabled. Initialize SMC1 and use it for
  121. * the console port.
  122. */
  123. /* Enable SDMA.
  124. */
  125. ((immap_t *)IMAP_ADDR)->im_siu_conf.sc_sdcr = 1;
  126. /* Use Port B for SMCs instead of other functions.
  127. */
  128. cp->cp_pbpar |= 0x00000cc0;
  129. cp->cp_pbdir &= ~0x00000cc0;
  130. cp->cp_pbodr &= ~0x00000cc0;
  131. /* Allocate space for two buffer descriptors in the DP ram.
  132. * For now, this address seems OK, but it may have to
  133. * change with newer versions of the firmware.
  134. */
  135. dpaddr = 0x0800;
  136. /* Grab a few bytes from the top of memory. EPPC-Bug isn't
  137. * running any more, so we can do this.
  138. */
  139. memaddr = (bd->bi_memsize - 32) & ~15;
  140. /* Set the physical address of the host memory buffers in
  141. * the buffer descriptors.
  142. */
  143. rbdf = (cbd_t *)&cp->cp_dpmem[dpaddr];
  144. rbdf->cbd_bufaddr = memaddr;
  145. rbdf->cbd_sc = 0;
  146. tbdf = rbdf + 1;
  147. tbdf->cbd_bufaddr = memaddr+4;
  148. tbdf->cbd_sc = 0;
  149. /* Set up the uart parameters in the parameter ram.
  150. */
  151. up->smc_rbase = dpaddr;
  152. up->smc_tbase = dpaddr+sizeof(cbd_t);
  153. up->smc_rfcr = SMC_EB;
  154. up->smc_tfcr = SMC_EB;
  155. /* Set UART mode, 8 bit, no parity, one stop.
  156. * Enable receive and transmit.
  157. */
  158. sp->smc_smcmr = smcr_mk_clen(9) | SMCMR_SM_UART;
  159. /* Mask all interrupts and remove anything pending.
  160. */
  161. sp->smc_smcm = 0;
  162. sp->smc_smce = 0xff;
  163. /* Set up the baud rate generator.
  164. * See 8xx_io/commproc.c for details.
  165. */
  166. cp->cp_simode = 0x10000000;
  167. cp->cp_brgc1 =
  168. (((bd->bi_intfreq/16) / 9600) << 1) | CPM_BRG_EN;
  169. /* Enable SMC1 for console output.
  170. */
  171. *MBX_CSR1 &= ~CSR1_COMEN;
  172. }
  173. else {
  174. #endif /* ndef CONFIG_MBX */
  175. /* SMCx is used as console port.
  176. */
  177. tbdf = (cbd_t *)&cp->cp_dpmem[up->smc_tbase];
  178. rbdf = (cbd_t *)&cp->cp_dpmem[up->smc_rbase];
  179. /* Issue a stop transmit, and wait for it.
  180. */
  181. cp->cp_cpcr = mk_cr_cmd(CPM_CR_CH_CONS,
  182. CPM_CR_STOP_TX) | CPM_CR_FLG;
  183. while (cp->cp_cpcr & CPM_CR_FLG);
  184. }
  185. /* Make the first buffer the only buffer.
  186. */
  187. tbdf->cbd_sc |= BD_SC_WRAP;
  188. rbdf->cbd_sc |= BD_SC_EMPTY | BD_SC_WRAP;
  189. /* Single character receive.
  190. */
  191. up->smc_mrblr = 1;
  192. up->smc_maxidl = 0;
  193. /* Initialize Tx/Rx parameters.
  194. */
  195. cp->cp_cpcr = mk_cr_cmd(CPM_CR_CH_CONS, CPM_CR_INIT_TRX) | CPM_CR_FLG;
  196. while (cp->cp_cpcr & CPM_CR_FLG);
  197. /* Enable transmitter/receiver.
  198. */
  199. sp->smc_smcmr |= SMCMR_REN | SMCMR_TEN;
  200. /* This is ignored.
  201. */
  202. return 0;
  203. }
  204. void
  205. serial_putc(void *ignored, const char c)
  206. {
  207. volatile cbd_t *tbdf;
  208. volatile char *buf;
  209. volatile smc_uart_t *up;
  210. up = (smc_uart_t *)&cpmp->cp_dparam[PROFF_CONS];
  211. tbdf = (cbd_t *)&cpmp->cp_dpmem[up->smc_tbase];
  212. /* Wait for last character to go.
  213. */
  214. buf = (char *)tbdf->cbd_bufaddr;
  215. while (tbdf->cbd_sc & BD_SC_READY);
  216. *buf = c;
  217. tbdf->cbd_datlen = 1;
  218. tbdf->cbd_sc |= BD_SC_READY;
  219. }
  220. char
  221. serial_getc(void *ignored)
  222. {
  223. volatile cbd_t *rbdf;
  224. volatile char *buf;
  225. volatile smc_uart_t *up;
  226. char c;
  227. up = (smc_uart_t *)&cpmp->cp_dparam[PROFF_CONS];
  228. rbdf = (cbd_t *)&cpmp->cp_dpmem[up->smc_rbase];
  229. /* Wait for character to show up.
  230. */
  231. buf = (char *)rbdf->cbd_bufaddr;
  232. while (rbdf->cbd_sc & BD_SC_EMPTY);
  233. c = *buf;
  234. rbdf->cbd_sc |= BD_SC_EMPTY;
  235. return(c);
  236. }
  237. int
  238. serial_tstc(void *ignored)
  239. {
  240. volatile cbd_t *rbdf;
  241. volatile smc_uart_t *up;
  242. up = (smc_uart_t *)&cpmp->cp_dparam[PROFF_CONS];
  243. rbdf = (cbd_t *)&cpmp->cp_dpmem[up->smc_rbase];
  244. return(!(rbdf->cbd_sc & BD_SC_EMPTY));
  245. }