blob: d11aa003fb120b8edb10ba38ca49067bcede8d3d (
plain)
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
|
void pl011_init(uintptr_t base, uint32 clock, uint32 baud)
{
struct pl01x_regs *regs = (struct pl01x_regs *)base;
uint32 divisor;
uint32 remainder;
uint32 fraction;
divisor = clock / (16 * baud);
remainder = clock % (16 * baud);
fraction = (8 * remainder + baud / 2) / baud;
writel(0, ®s->pl011_cr);
writel(0x7ff, ®s->pl011_icr);
writel(divisor, ®s->pl011_ibrd);
writel(fraction, ®s->pl011_fbrd);
writel((3 << 5) | (1 << 4), ®s->pl011_lcrh);
writel((1 << 0) | (1 << 8) | (1 << 9), ®s->pl011_cr);
}
void pl011_putc(uintptr_t base, char c)
{
struct pl01x_regs *regs = (struct pl01x_regs *)base;
while (readl(®s->fr) & UART_PL01x_FR_TXFF)
;
writel(c, ®s->dr);
}
int pl011_getc(uintptr_t base)
{
struct pl01x_regs *regs = (struct pl01x_regs *)base;
if (readl(®s->fr) & UART_PL01x_FR_RXFE)
return -1;
return readl(®s->dr) & 0xff;
}
|