]>
git.ipfire.org Git - people/ms/u-boot.git/blob - drivers/atmel_usart.c
2 * Copyright (C) 2004-2006 Atmel Corporation
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 #ifdef CONFIG_ATMEL_USART
22 #include <asm/arch/platform.h>
24 #include "atmel_usart.h"
26 DECLARE_GLOBAL_DATA_PTR
;
28 void serial_setbrg(void)
30 unsigned long divisor
;
31 unsigned long usart_hz
;
35 * Baud Rate = --------------
38 usart_hz
= pm_get_clock_freq(gd
->console_uart
->resource
[0].u
.clock
.id
);
39 divisor
= (usart_hz
/ 16 + gd
->baudrate
/ 2) / gd
->baudrate
;
40 usart3_writel(gd
->console_uart
, BRGR
, USART3_BF(CD
, divisor
));
45 usart3_writel(gd
->console_uart
, CR
,
46 USART3_BIT(RSTRX
) | USART3_BIT(RSTTX
));
50 usart3_writel(gd
->console_uart
, CR
,
51 USART3_BIT(RXEN
) | USART3_BIT(TXEN
));
52 usart3_writel(gd
->console_uart
, MR
,
53 USART3_BF(USART_MODE
, USART3_USART_MODE_NORMAL
)
54 | USART3_BF(USCLKS
, USART3_USCLKS_MCK
)
55 | USART3_BF(CHRL
, USART3_CHRL_8
)
56 | USART3_BF(PAR
, USART3_PAR_NONE
)
57 | USART3_BF(NBSTOP
, USART3_NBSTOP_1
));
62 void serial_putc(char c
)
67 while (!(usart3_readl(gd
->console_uart
, CSR
) & USART3_BIT(TXRDY
))) ;
68 usart3_writel(gd
->console_uart
, THR
, c
);
71 void serial_puts(const char *s
)
79 while (!(usart3_readl(gd
->console_uart
, CSR
) & USART3_BIT(RXRDY
))) ;
80 return usart3_readl(gd
->console_uart
, RHR
);
85 return (usart3_readl(gd
->console_uart
, CSR
) & USART3_BIT(RXRDY
)) != 0;
88 #endif /* CONFIG_ATMEL_USART */