summaryrefslogtreecommitdiffstats
path: root/arch/arm/mach-rockchip/include/mach/debug_ll.h
blob: 9fde2976f1967be01de390f6ef9f828ca1cf9aea (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
65
66
67
68
69
70
71
72
73
#ifndef __MACH_DEBUG_LL_H__
#define __MACH_DEBUG_LL_H__

#include <common.h>
#include <io.h>
#include <mach/rk3188-regs.h>
#include <mach/rk3288-regs.h>

#ifdef CONFIG_ARCH_RK3188

#define UART_CLOCK		100000000
#define RK_DEBUG_SOC		RK3188
#define serial_out(a, v)	writeb(v, a)
#define serial_in(a)		readb(a)

#elif defined CONFIG_ARCH_RK3288

#define UART_CLOCK		24000000
#define RK_DEBUG_SOC		RK3288
#define serial_out(a, v)	writel(v, a)
#define serial_in(a)		readl(a)

#endif

#define __RK_UART_BASE(soc, num) soc##_UART##num##_BASE
#define RK_UART_BASE(soc, num) __RK_UART_BASE(soc, num)

#define LSR_THRE	0x20	/* Xmit holding register empty */
#define LCR_BKSE	0x80	/* Bank select enable */
#define LSR		(5 << 2)
#define THR		(0 << 2)
#define DLL		(0 << 2)
#define IER		(1 << 2)
#define DLM		(1 << 2)
#define FCR		(2 << 2)
#define LCR		(3 << 2)
#define MCR		(4 << 2)
#define MDR		(8 << 2)

static inline void INIT_LL(void)
{
	void __iomem *base = IOMEM(RK_UART_BASE(RK_DEBUG_SOC,
		CONFIG_DEBUG_ROCKCHIP_UART_PORT));
	unsigned int divisor = DIV_ROUND_CLOSEST(UART_CLOCK,
		16 * CONFIG_BAUDRATE);

	serial_out(base + LCR, 0x00);
	serial_out(base + IER, 0x00);
	serial_out(base + MDR, 0x07);
	serial_out(base + LCR, LCR_BKSE);
	serial_out(base + DLL, divisor & 0xff);
	serial_out(base + DLM, divisor >> 8);
	serial_out(base + LCR, 0x03);
	serial_out(base + MCR, 0x03);
	serial_out(base + FCR, 0x07);
	serial_out(base + MDR, 0x00);
}

static inline void PUTC_LL(char c)
{
	void __iomem *base = IOMEM(RK_UART_BASE(RK_DEBUG_SOC,
		CONFIG_DEBUG_ROCKCHIP_UART_PORT));

	/* Wait until there is space in the FIFO */
	while ((serial_in(base + LSR) & LSR_THRE) == 0)
		;
	/* Send the character */
	serial_out(base + THR, c);
	/* Wait to make sure it hits the line, in case we die too soon. */
	while ((serial_in(base + LSR) & LSR_THRE) == 0)
		;
}
#endif