2 * Copyright (C) 2011 Vladimir Zapolskiy <vz@mleia.com>
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
21 #include <asm/arch/cpu.h>
22 #include <asm/arch/clk.h>
23 #include <asm/arch/uart.h>
26 #include <linux/compiler.h>
28 DECLARE_GLOBAL_DATA_PTR;
30 static struct hsuart_regs *hsuart = (struct hsuart_regs *)HS_UART_BASE;
32 static void lpc32xx_serial_setbrg(void)
36 /* UART rate = PERIPH_CLK / ((HSU_RATE + 1) x 14) */
37 div = (get_serial_clock() / 14 + gd->baudrate / 2) / gd->baudrate - 1;
41 writel(div, &hsuart->rate);
44 static int lpc32xx_serial_getc(void)
46 while (!(readl(&hsuart->level) & HSUART_LEVEL_RX))
49 return readl(&hsuart->rx) & HSUART_RX_DATA;
52 static void lpc32xx_serial_putc(const char c)
54 writel(c, &hsuart->tx);
56 /* Wait for character to be sent */
57 while (readl(&hsuart->level) & HSUART_LEVEL_TX)
61 static int lpc32xx_serial_tstc(void)
63 if (readl(&hsuart->level) & HSUART_LEVEL_RX)
69 static int lpc32xx_serial_init(void)
71 lpc32xx_serial_setbrg();
73 /* Disable hardware RTS and CTS flow control, set up RX and TX FIFO */
74 writel(HSUART_CTRL_TMO_16 | HSUART_CTRL_HSU_OFFSET(20) |
75 HSUART_CTRL_HSU_RX_TRIG_32 | HSUART_CTRL_HSU_TX_TRIG_0,
80 static struct serial_device lpc32xx_serial_drv = {
81 .name = "lpc32xx_serial",
82 .start = lpc32xx_serial_init,
84 .setbrg = lpc32xx_serial_setbrg,
85 .putc = lpc32xx_serial_putc,
86 .puts = default_serial_puts,
87 .getc = lpc32xx_serial_getc,
88 .tstc = lpc32xx_serial_tstc,
91 void lpc32xx_serial_initialize(void)
93 serial_register(&lpc32xx_serial_drv);
96 __weak struct serial_device *default_serial_console(void)
98 return &lpc32xx_serial_drv;