ramips: lzma-loader: use virtual memory segments for uart base address
[openwrt/staging/blocktrron.git] / target / linux / ramips / image / lzma-loader / src / board.c
1 /*
2 * Arch specific code for ramips based boards
3 *
4 * Copyright (C) 2013 John Crispin <blogic@openwrt.org>
5 * Copyright (C) 2018 Tobias Schramm <tobleminer@gmail.com>
6 * Copyright (C) 2023 Antonio Vázquez <antoniovazquezblanco@gmail.com>
7 *
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License version 2 as published
10 * by the Free Software Foundation.
11 */
12
13 #include <stdint.h>
14 #include <stddef.h>
15
16 #define KSEG0 0x80000000
17 #define KSEG1 0xa0000000
18
19 #define _ATYPE_ __PTRDIFF_TYPE__
20 #define _ATYPE32_ int
21
22 #define _ACAST32_ (_ATYPE_)(_ATYPE32_)
23
24 #define CPHYSADDR(a) ((_ACAST32_(a)) & 0x1fffffff)
25
26 #define KSEG0ADDR(a) (CPHYSADDR(a) | KSEG0)
27 #define KSEG1ADDR(a) (CPHYSADDR(a) | KSEG1)
28
29 #if defined(SOC_MT7620) || defined(SOC_RT3883)
30 #define UART_BASE KSEG1ADDR(0x10000c00)
31 #define UART_THR (UART_BASE + 0x04)
32 #define UART_LSR (UART_BASE + 0x1c)
33 #define UART_LSR_THRE_MASK 0x40
34 #elif defined(SOC_MT7621)
35 #define UART_BASE KSEG1ADDR(0x1e000c00)
36 #define UART_THR (UART_BASE + 0x00)
37 #define UART_LSR (UART_BASE + 0x14)
38 #define UART_LSR_THRE_MASK 0x20
39 #elif defined(SOC_RT305X)
40 #define UART_BASE KSEG1ADDR(0x10000500)
41 #define UART_THR (UART_BASE + 0x04)
42 #define UART_LSR (UART_BASE + 0x1c)
43 #define UART_LSR_THRE_MASK 0x20
44 #else
45 #error "Unsupported SOC..."
46 #endif
47
48 // Helper functions
49 #define READREG(r) (*(volatile uint32_t *)(r))
50 #define WRITEREG(r,v) (*(volatile uint32_t *)(r)) = v
51
52
53 void board_init(void)
54 {
55 }
56
57 void board_putc(int ch)
58 {
59 while ((READREG(UART_LSR) & UART_LSR_THRE_MASK) == 0);
60 WRITEREG(UART_THR, ch);
61 while ((READREG(UART_LSR) & UART_LSR_THRE_MASK) == 0);
62 }