msp_serial.c 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. /*
  2. * The setup file for serial related hardware on PMC-Sierra MSP processors.
  3. *
  4. * Copyright 2005 PMC-Sierra, Inc.
  5. *
  6. * This program is free software; you can redistribute it and/or modify it
  7. * under the terms of the GNU General Public License as published by the
  8. * Free Software Foundation; either version 2 of the License, or (at your
  9. * option) any later version.
  10. *
  11. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
  12. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  13. * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
  14. * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
  15. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  16. * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  17. * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
  18. * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  19. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  20. * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  21. *
  22. * You should have received a copy of the GNU General Public License along
  23. * with this program; if not, write to the Free Software Foundation, Inc.,
  24. * 675 Mass Ave, Cambridge, MA 02139, USA.
  25. */
  26. #include <linux/serial.h>
  27. #include <linux/serial_core.h>
  28. #include <linux/serial_reg.h>
  29. #include <asm/bootinfo.h>
  30. #include <asm/io.h>
  31. #include <asm/processor.h>
  32. #include <asm/serial.h>
  33. #include <linux/serial_8250.h>
  34. #include <msp_prom.h>
  35. #include <msp_int.h>
  36. #include <msp_regs.h>
  37. #ifdef CONFIG_KGDB
  38. /*
  39. * kgdb uses serial port 1 so the console can remain on port 0.
  40. * To use port 0 change the definition to read as follows:
  41. * #define DEBUG_PORT_BASE KSEG1ADDR(MSP_UART0_BASE)
  42. */
  43. #define DEBUG_PORT_BASE KSEG1ADDR(MSP_UART1_BASE)
  44. int putDebugChar(char c)
  45. {
  46. volatile uint32_t *uart = (volatile uint32_t *)DEBUG_PORT_BASE;
  47. uint32_t val = (uint32_t)c;
  48. local_irq_disable();
  49. while( !(uart[5] & 0x20) ); /* Wait for TXRDY */
  50. uart[0] = val;
  51. while( !(uart[5] & 0x20) ); /* Wait for TXRDY */
  52. local_irq_enable();
  53. return 1;
  54. }
  55. char getDebugChar(void)
  56. {
  57. volatile uint32_t *uart = (volatile uint32_t *)DEBUG_PORT_BASE;
  58. uint32_t val;
  59. while( !(uart[5] & 0x01) ); /* Wait for RXRDY */
  60. val = uart[0];
  61. return (char)val;
  62. }
  63. void initDebugPort(unsigned int uartclk, unsigned int baudrate)
  64. {
  65. unsigned int baud_divisor = (uartclk + 8 * baudrate)/(16 * baudrate);
  66. /* Enable FIFOs */
  67. writeb(UART_FCR_ENABLE_FIFO | UART_FCR_CLEAR_RCVR |
  68. UART_FCR_CLEAR_XMIT | UART_FCR_TRIGGER_4,
  69. (char *)DEBUG_PORT_BASE + (UART_FCR * 4));
  70. /* Select brtc divisor */
  71. writeb(UART_LCR_DLAB, (char *)DEBUG_PORT_BASE + (UART_LCR * 4));
  72. /* Store divisor lsb */
  73. writeb(baud_divisor, (char *)DEBUG_PORT_BASE + (UART_TX * 4));
  74. /* Store divisor msb */
  75. writeb(baud_divisor >> 8, (char *)DEBUG_PORT_BASE + (UART_IER * 4));
  76. /* Set 8N1 mode */
  77. writeb(UART_LCR_WLEN8, (char *)DEBUG_PORT_BASE + (UART_LCR * 4));
  78. /* Disable flow control */
  79. writeb(0, (char *)DEBUG_PORT_BASE + (UART_MCR * 4));
  80. /* Disable receive interrupt(!) */
  81. writeb(0, (char *)DEBUG_PORT_BASE + (UART_IER * 4));
  82. }
  83. #endif
  84. void __init msp_serial_setup(void)
  85. {
  86. char *s;
  87. char *endp;
  88. struct uart_port up;
  89. unsigned int uartclk;
  90. memset(&up, 0, sizeof(up));
  91. /* Check if clock was specified in environment */
  92. s = prom_getenv("uartfreqhz");
  93. if(!(s && *s && (uartclk = simple_strtoul(s, &endp, 10)) && *endp == 0))
  94. uartclk = MSP_BASE_BAUD;
  95. ppfinit("UART clock set to %d\n", uartclk);
  96. /* Initialize first serial port */
  97. up.mapbase = MSP_UART0_BASE;
  98. up.membase = ioremap_nocache(up.mapbase, MSP_UART_REG_LEN);
  99. up.irq = MSP_INT_UART0;
  100. up.uartclk = uartclk;
  101. up.regshift = 2;
  102. up.iotype = UPIO_DWAPB; /* UPIO_MEM like */
  103. up.flags = ASYNC_BOOT_AUTOCONF | ASYNC_SKIP_TEST;
  104. up.type = PORT_16550A;
  105. up.line = 0;
  106. up.private_data = (void*)UART0_STATUS_REG;
  107. if (early_serial_setup(&up))
  108. printk(KERN_ERR "Early serial init of port 0 failed\n");
  109. /* Initialize the second serial port, if one exists */
  110. switch (mips_machtype) {
  111. case MACH_MSP4200_EVAL:
  112. case MACH_MSP4200_GW:
  113. case MACH_MSP4200_FPGA:
  114. case MACH_MSP7120_EVAL:
  115. case MACH_MSP7120_GW:
  116. case MACH_MSP7120_FPGA:
  117. /* Enable UART1 on MSP4200 and MSP7120 */
  118. *GPIO_CFG2_REG = 0x00002299;
  119. #ifdef CONFIG_KGDB
  120. /* Initialize UART1 for kgdb since PMON doesn't */
  121. if( DEBUG_PORT_BASE == KSEG1ADDR(MSP_UART1_BASE) ) {
  122. if( mips_machtype == MACH_MSP4200_FPGA
  123. || mips_machtype == MACH_MSP7120_FPGA )
  124. initDebugPort(uartclk, 19200);
  125. else
  126. initDebugPort(uartclk, 57600);
  127. }
  128. #endif
  129. break;
  130. default:
  131. return; /* No second serial port, good-bye. */
  132. }
  133. up.mapbase = MSP_UART1_BASE;
  134. up.membase = ioremap_nocache(up.mapbase, MSP_UART_REG_LEN);
  135. up.irq = MSP_INT_UART1;
  136. up.line = 1;
  137. up.private_data = (void*)UART1_STATUS_REG;
  138. if (early_serial_setup(&up))
  139. printk(KERN_ERR "Early serial init of port 1 failed\n");
  140. }