aboutsummaryrefslogtreecommitdiff
path: root/arch/powerpc/boot/uartlite.c
blob: f4249a74c36780b1f2a1b6d596189eb5b3a3c4df (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
57
58
59
60
61
62
63
64
/*
 * Xilinx UARTLITE bootloader driver
 *
 * Copyright (C) 2007 Secret Lab Technologies Ltd.
 *
 * This file is licensed under the terms of the GNU General Public License
 * version 2. This program is licensed "as is" without any warranty of any
 * kind, whether express or implied.
 */

#include <stdarg.h>
#include <stddef.h>
#include "types.h"
#include "string.h"
#include "stdio.h"
#include "io.h"
#include "ops.h"

static void * reg_base;

static int uartlite_open(void)
{
	/* Clear the RX FIFO */
	out_be32(reg_base + 0x0C, 0x2);
	return 0;
}

static void uartlite_putc(unsigned char c)
{
	while ((in_be32(reg_base + 0x8) & 0x08) != 0); /* spin */
	out_be32(reg_base + 0x4, c);
}

static unsigned char uartlite_getc(void)
{
	while ((in_be32(reg_base + 0x8) & 0x01) == 0); /* spin */
	return in_be32(reg_base);
}

static u8 uartlite_tstc(void)
{
	return ((in_be32(reg_base + 0x8) & 0x01) != 0);
}

int uartlite_console_init(void *devp, struct serial_console_data *scdp)
{
	int n;
	unsigned long reg_phys;

	n = getprop(devp, "virtual-reg", &reg_base, sizeof(reg_base));
	if (n != sizeof(reg_base)) {
		if (!dt_xlate_reg(devp, 0, &reg_phys, NULL))
			return -1;

		reg_base = (void *)reg_phys;
	}

	scdp->open = uartlite_open;
	scdp->putc = uartlite_putc;
	scdp->getc = uartlite_getc;
	scdp->tstc = uartlite_tstc;
	scdp->close = NULL;
	return 0;
}