2 * Copyright (C) 2004-2006 Atmel Corporation
4 * Modified to support C structur SoC access by
5 * Andreas Bießmann <biessmann@corscience.de>
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 #include <asm/arch/clk.h>
26 #include <asm/arch/hardware.h>
28 #include "atmel_usart.h"
30 DECLARE_GLOBAL_DATA_PTR;
32 void serial_setbrg(void)
34 atmel_usart3_t *usart = (atmel_usart3_t *)CONFIG_USART_BASE;
35 unsigned long divisor;
36 unsigned long usart_hz;
40 * Baud Rate = --------------
43 usart_hz = get_usart_clk_rate(CONFIG_USART_ID);
44 divisor = (usart_hz / 16 + gd->baudrate / 2) / gd->baudrate;
45 writel(USART3_BF(CD, divisor), &usart->brgr);
50 atmel_usart3_t *usart = (atmel_usart3_t *)CONFIG_USART_BASE;
52 writel(USART3_BIT(RSTRX) | USART3_BIT(RSTTX), &usart->cr);
56 writel(USART3_BIT(RXEN) | USART3_BIT(TXEN), &usart->cr);
57 writel((USART3_BF(USART_MODE, USART3_USART_MODE_NORMAL)
58 | USART3_BF(USCLKS, USART3_USCLKS_MCK)
59 | USART3_BF(CHRL, USART3_CHRL_8)
60 | USART3_BF(PAR, USART3_PAR_NONE)
61 | USART3_BF(NBSTOP, USART3_NBSTOP_1)),
67 void serial_putc(char c)
69 atmel_usart3_t *usart = (atmel_usart3_t *)CONFIG_USART_BASE;
74 while (!(readl(&usart->csr) & USART3_BIT(TXRDY)));
75 writel(c, &usart->thr);
78 void serial_puts(const char *s)
86 atmel_usart3_t *usart = (atmel_usart3_t *)CONFIG_USART_BASE;
88 while (!(readl(&usart->csr) & USART3_BIT(RXRDY)))
90 return readl(&usart->rhr);
95 atmel_usart3_t *usart = (atmel_usart3_t *)CONFIG_USART_BASE;
96 return (readl(&usart->csr) & USART3_BIT(RXRDY)) != 0;