[POWERPC] Virtex: Add uartlite bootwrapper driver
[platform/adaptation/renesas_rcar/renesas_kernel.git] / arch / powerpc / boot / uartlite.c
1 /*
2  * Xilinx UARTLITE bootloader driver
3  *
4  * Copyright (C) 2007 Secret Lab Technologies Ltd.
5  *
6  * This file is licensed under the terms of the GNU General Public License
7  * version 2. This program is licensed "as is" without any warranty of any
8  * kind, whether express or implied.
9  */
10
11 #include <stdarg.h>
12 #include <stddef.h>
13 #include "types.h"
14 #include "string.h"
15 #include "stdio.h"
16 #include "io.h"
17 #include "ops.h"
18
19 static void * reg_base;
20
21 static int uartlite_open(void)
22 {
23         /* Clear the RX FIFO */
24         out_be32(reg_base + 0x0C, 0x2);
25         return 0;
26 }
27
28 static void uartlite_putc(unsigned char c)
29 {
30         while ((in_be32(reg_base + 0x8) & 0x08) != 0); /* spin */
31         out_be32(reg_base + 0x4, c);
32 }
33
34 static unsigned char uartlite_getc(void)
35 {
36         while ((in_be32(reg_base + 0x8) & 0x01) == 0); /* spin */
37         return in_be32(reg_base);
38 }
39
40 static u8 uartlite_tstc(void)
41 {
42         return ((in_be32(reg_base + 0x8) & 0x01) != 0);
43 }
44
45 int uartlite_console_init(void *devp, struct serial_console_data *scdp)
46 {
47         int n;
48         unsigned long reg_phys;
49
50         n = getprop(devp, "virtual-reg", &reg_base, sizeof(reg_base));
51         if (n != sizeof(reg_base)) {
52                 if (!dt_xlate_reg(devp, 0, &reg_phys, NULL))
53                         return -1;
54
55                 reg_base = (void *)reg_phys;
56         }
57
58         scdp->open = uartlite_open;
59         scdp->putc = uartlite_putc;
60         scdp->getc = uartlite_getc;
61         scdp->tstc = uartlite_tstc;
62         scdp->close = NULL;
63         return 0;
64 }