-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathuart.c
82 lines (72 loc) · 1.98 KB
/
uart.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
/*
* (C) Copyright 2007-2012
* Allwinner Technology Co., Ltd. <www.allwinnertech.com>
* Tom Cubie <[email protected]>
*
* Early uart print for debugging.
*
* See file CREDITS for list of people who contributed to this
* project.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
* MA 02111-1307 USA
*/
#include "io.h"
#include "uart.h"
#include "clock.h"
#define CONFIG_CONS_INDEX 1
#define APB2_DIV (AW_CCM_BASE + 0x058)
#define APB2_GATE (AW_CCM_BASE + 0x06C)
#define APB2_RESET (AW_CCM_BASE + 0x2D8)
void clock_init_uart(void)
{
/* uart clock source is apb2 */
writel(APB2_CLK_SRC_OSC24M|
APB2_CLK_RATE_N_1|
APB2_CLK_RATE_M(1),
APB2_GATE);
/* open the clock for uart */
set_wbit(APB2_GATE, 1 << (APB2_GATE_UART_SHIFT +
CONFIG_CONS_INDEX - 1));
/* deassert uart reset */
set_wbit(APB2_RESET, 1 << (APB2_RESET_UART_SHIFT +
CONFIG_CONS_INDEX - 1));
}
void uart0_init(void)
{
clock_init_uart();
/* select dll dlh */
writel(0x80, UART0_LCR);
/* set baudrate */
writel(0, UART0_DLH);
writel(BAUD_115200, UART0_DLL);
/* set line control */
writel(LC_8_N_1, UART0_LCR);
}
#define TX_READY (readl(UART0_LSR) & (1 << 6))
void uart0_putc(char c)
{
while(!TX_READY)
;
writel(c, UART0_THR);
}
void uart0_puts(const char *s)
{
while(*s) {
if (*s == '\n')
uart0_putc('\r');
uart0_putc(*s++);
}
}