msp_serial.c 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  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 <linux/slab.h>
  30. #include <asm/bootinfo.h>
  31. #include <asm/io.h>
  32. #include <asm/processor.h>
  33. #include <asm/serial.h>
  34. #include <linux/serial_8250.h>
  35. #include <msp_prom.h>
  36. #include <msp_int.h>
  37. #include <msp_regs.h>
  38. struct msp_uart_data {
  39. int last_lcr;
  40. };
  41. static void msp_serial_out(struct uart_port *p, int offset, int value)
  42. {
  43. struct msp_uart_data *d = p->private_data;
  44. if (offset == UART_LCR)
  45. d->last_lcr = value;
  46. offset <<= p->regshift;
  47. writeb(value, p->membase + offset);
  48. }
  49. static unsigned int msp_serial_in(struct uart_port *p, int offset)
  50. {
  51. offset <<= p->regshift;
  52. return readb(p->membase + offset);
  53. }
  54. static int msp_serial_handle_irq(struct uart_port *p)
  55. {
  56. struct msp_uart_data *d = p->private_data;
  57. unsigned int iir = readb(p->membase + (UART_IIR << p->regshift));
  58. if (serial8250_handle_irq(p, iir)) {
  59. return 1;
  60. } else if ((iir & UART_IIR_BUSY) == UART_IIR_BUSY) {
  61. /*
  62. * The DesignWare APB UART has an Busy Detect (0x07) interrupt
  63. * meaning an LCR write attempt occurred while the UART was
  64. * busy. The interrupt must be cleared by reading the UART
  65. * status register (USR) and the LCR re-written.
  66. *
  67. * Note: MSP reserves 0x20 bytes of address space for the UART
  68. * and the USR is mapped in a separate block at an offset of
  69. * 0xc0 from the start of the UART.
  70. */
  71. (void)readb(p->membase + 0xc0);
  72. writeb(d->last_lcr, p->membase + (UART_LCR << p->regshift));
  73. return 1;
  74. }
  75. return 0;
  76. }
  77. void __init msp_serial_setup(void)
  78. {
  79. char *s;
  80. char *endp;
  81. struct uart_port up;
  82. unsigned int uartclk;
  83. memset(&up, 0, sizeof(up));
  84. /* Check if clock was specified in environment */
  85. s = prom_getenv("uartfreqhz");
  86. if(!(s && *s && (uartclk = simple_strtoul(s, &endp, 10)) && *endp == 0))
  87. uartclk = MSP_BASE_BAUD;
  88. ppfinit("UART clock set to %d\n", uartclk);
  89. /* Initialize first serial port */
  90. up.mapbase = MSP_UART0_BASE;
  91. up.membase = ioremap_nocache(up.mapbase, MSP_UART_REG_LEN);
  92. up.irq = MSP_INT_UART0;
  93. up.uartclk = uartclk;
  94. up.regshift = 2;
  95. up.iotype = UPIO_MEM;
  96. up.flags = ASYNC_BOOT_AUTOCONF | ASYNC_SKIP_TEST;
  97. up.type = PORT_16550A;
  98. up.line = 0;
  99. up.serial_out = msp_serial_out;
  100. up.serial_in = msp_serial_in;
  101. up.handle_irq = msp_serial_handle_irq;
  102. up.private_data = kzalloc(sizeof(struct msp_uart_data), GFP_KERNEL);
  103. if (!up.private_data) {
  104. pr_err("failed to allocate uart private data\n");
  105. return;
  106. }
  107. if (early_serial_setup(&up)) {
  108. kfree(up.private_data);
  109. pr_err("Early serial init of port 0 failed\n");
  110. }
  111. /* Initialize the second serial port, if one exists */
  112. switch (mips_machtype) {
  113. case MACH_MSP4200_EVAL:
  114. case MACH_MSP4200_GW:
  115. case MACH_MSP4200_FPGA:
  116. case MACH_MSP7120_EVAL:
  117. case MACH_MSP7120_GW:
  118. case MACH_MSP7120_FPGA:
  119. /* Enable UART1 on MSP4200 and MSP7120 */
  120. *GPIO_CFG2_REG = 0x00002299;
  121. break;
  122. default:
  123. return; /* No second serial port, good-bye. */
  124. }
  125. up.mapbase = MSP_UART1_BASE;
  126. up.membase = ioremap_nocache(up.mapbase, MSP_UART_REG_LEN);
  127. up.irq = MSP_INT_UART1;
  128. up.line = 1;
  129. up.private_data = (void*)UART1_STATUS_REG;
  130. if (early_serial_setup(&up)) {
  131. kfree(up.private_data);
  132. pr_err("Early serial init of port 1 failed\n");
  133. }
  134. }