serial.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. /*
  2. * arch/arm/mach-lpc32xx/serial.c
  3. *
  4. * Author: Kevin Wells <kevin.wells@nxp.com>
  5. *
  6. * Copyright (C) 2010 NXP Semiconductors
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. */
  18. #include <linux/kernel.h>
  19. #include <linux/types.h>
  20. #include <linux/serial.h>
  21. #include <linux/serial_core.h>
  22. #include <linux/serial_reg.h>
  23. #include <linux/serial_8250.h>
  24. #include <linux/clk.h>
  25. #include <linux/io.h>
  26. #include <mach/hardware.h>
  27. #include <mach/platform.h>
  28. #include "common.h"
  29. #define LPC32XX_SUART_FIFO_SIZE 64
  30. struct uartinit {
  31. char *uart_ck_name;
  32. u32 ck_mode_mask;
  33. void __iomem *pdiv_clk_reg;
  34. resource_size_t mapbase;
  35. };
  36. static struct uartinit uartinit_data[] __initdata = {
  37. {
  38. .uart_ck_name = "uart5_ck",
  39. .ck_mode_mask =
  40. LPC32XX_UART_CLKMODE_LOAD(LPC32XX_UART_CLKMODE_ON, 5),
  41. .pdiv_clk_reg = LPC32XX_CLKPWR_UART5_CLK_CTRL,
  42. .mapbase = LPC32XX_UART5_BASE,
  43. },
  44. {
  45. .uart_ck_name = "uart3_ck",
  46. .ck_mode_mask =
  47. LPC32XX_UART_CLKMODE_LOAD(LPC32XX_UART_CLKMODE_ON, 3),
  48. .pdiv_clk_reg = LPC32XX_CLKPWR_UART3_CLK_CTRL,
  49. .mapbase = LPC32XX_UART3_BASE,
  50. },
  51. {
  52. .uart_ck_name = "uart4_ck",
  53. .ck_mode_mask =
  54. LPC32XX_UART_CLKMODE_LOAD(LPC32XX_UART_CLKMODE_ON, 4),
  55. .pdiv_clk_reg = LPC32XX_CLKPWR_UART4_CLK_CTRL,
  56. .mapbase = LPC32XX_UART4_BASE,
  57. },
  58. {
  59. .uart_ck_name = "uart6_ck",
  60. .ck_mode_mask =
  61. LPC32XX_UART_CLKMODE_LOAD(LPC32XX_UART_CLKMODE_ON, 6),
  62. .pdiv_clk_reg = LPC32XX_CLKPWR_UART6_CLK_CTRL,
  63. .mapbase = LPC32XX_UART6_BASE,
  64. },
  65. };
  66. void __init lpc32xx_serial_init(void)
  67. {
  68. u32 tmp, clkmodes = 0;
  69. struct clk *clk;
  70. unsigned int puart;
  71. int i, j;
  72. for (i = 0; i < ARRAY_SIZE(uartinit_data); i++) {
  73. clk = clk_get(NULL, uartinit_data[i].uart_ck_name);
  74. if (!IS_ERR(clk)) {
  75. clk_enable(clk);
  76. }
  77. /* Setup UART clock modes for all UARTs, disable autoclock */
  78. clkmodes |= uartinit_data[i].ck_mode_mask;
  79. /* pre-UART clock divider set to 1 */
  80. __raw_writel(0x0101, uartinit_data[i].pdiv_clk_reg);
  81. /*
  82. * Force a flush of the RX FIFOs to work around a
  83. * HW bug
  84. */
  85. puart = uartinit_data[i].mapbase;
  86. __raw_writel(0xC1, LPC32XX_UART_IIR_FCR(puart));
  87. __raw_writel(0x00, LPC32XX_UART_DLL_FIFO(puart));
  88. j = LPC32XX_SUART_FIFO_SIZE;
  89. while (j--)
  90. tmp = __raw_readl(
  91. LPC32XX_UART_DLL_FIFO(puart));
  92. __raw_writel(0, LPC32XX_UART_IIR_FCR(puart));
  93. }
  94. /* This needs to be done after all UART clocks are setup */
  95. __raw_writel(clkmodes, LPC32XX_UARTCTL_CLKMODE);
  96. for (i = 0; i < ARRAY_SIZE(uartinit_data); i++) {
  97. /* Force a flush of the RX FIFOs to work around a HW bug */
  98. puart = uartinit_data[i].mapbase;
  99. __raw_writel(0xC1, LPC32XX_UART_IIR_FCR(puart));
  100. __raw_writel(0x00, LPC32XX_UART_DLL_FIFO(puart));
  101. j = LPC32XX_SUART_FIFO_SIZE;
  102. while (j--)
  103. tmp = __raw_readl(LPC32XX_UART_DLL_FIFO(puart));
  104. __raw_writel(0, LPC32XX_UART_IIR_FCR(puart));
  105. }
  106. /* Disable IrDA pulsing support on UART6 */
  107. tmp = __raw_readl(LPC32XX_UARTCTL_CTRL);
  108. tmp |= LPC32XX_UART_UART6_IRDAMOD_BYPASS;
  109. __raw_writel(tmp, LPC32XX_UARTCTL_CTRL);
  110. /* Disable UART5->USB transparent mode or USB won't work */
  111. tmp = __raw_readl(LPC32XX_UARTCTL_CTRL);
  112. tmp &= ~LPC32XX_UART_U5_ROUTE_TO_USB;
  113. __raw_writel(tmp, LPC32XX_UARTCTL_CTRL);
  114. }