m8xx_tty.c
上传用户:jlfgdled
上传日期:2013-04-10
资源大小:33168k
文件大小:7k
源码类别:

Linux/Unix编程

开发平台:

Unix_Linux

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