serial.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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. /* UART clocks are off, let clock driver manage them */
  73. __raw_writel(0, LPC32XX_CLKPWR_UART_CLK_CTRL);
  74. for (i = 0; i < ARRAY_SIZE(uartinit_data); i++) {
  75. clk = clk_get(NULL, uartinit_data[i].uart_ck_name);
  76. if (!IS_ERR(clk)) {
  77. clk_enable(clk);
  78. }
  79. /* Setup UART clock modes for all UARTs, disable autoclock */
  80. clkmodes |= uartinit_data[i].ck_mode_mask;
  81. /* pre-UART clock divider set to 1 */
  82. __raw_writel(0x0101, uartinit_data[i].pdiv_clk_reg);
  83. /*
  84. * Force a flush of the RX FIFOs to work around a
  85. * HW bug
  86. */
  87. puart = uartinit_data[i].mapbase;
  88. __raw_writel(0xC1, LPC32XX_UART_IIR_FCR(puart));
  89. __raw_writel(0x00, LPC32XX_UART_DLL_FIFO(puart));
  90. j = LPC32XX_SUART_FIFO_SIZE;
  91. while (j--)
  92. tmp = __raw_readl(
  93. LPC32XX_UART_DLL_FIFO(puart));
  94. __raw_writel(0, LPC32XX_UART_IIR_FCR(puart));
  95. }
  96. /* This needs to be done after all UART clocks are setup */
  97. __raw_writel(clkmodes, LPC32XX_UARTCTL_CLKMODE);
  98. for (i = 0; i < ARRAY_SIZE(uartinit_data); i++) {
  99. /* Force a flush of the RX FIFOs to work around a HW bug */
  100. puart = uartinit_data[i].mapbase;
  101. __raw_writel(0xC1, LPC32XX_UART_IIR_FCR(puart));
  102. __raw_writel(0x00, LPC32XX_UART_DLL_FIFO(puart));
  103. j = LPC32XX_SUART_FIFO_SIZE;
  104. while (j--)
  105. tmp = __raw_readl(LPC32XX_UART_DLL_FIFO(puart));
  106. __raw_writel(0, LPC32XX_UART_IIR_FCR(puart));
  107. }
  108. /* Disable IrDA pulsing support on UART6 */
  109. tmp = __raw_readl(LPC32XX_UARTCTL_CTRL);
  110. tmp |= LPC32XX_UART_UART6_IRDAMOD_BYPASS;
  111. __raw_writel(tmp, LPC32XX_UARTCTL_CTRL);
  112. /* Disable UART5->USB transparent mode or USB won't work */
  113. tmp = __raw_readl(LPC32XX_UARTCTL_CTRL);
  114. tmp &= ~LPC32XX_UART_U5_ROUTE_TO_USB;
  115. __raw_writel(tmp, LPC32XX_UARTCTL_CTRL);
  116. }