Merge branches 'gemini' and 'misc' into devel
[pandora-kernel.git] / arch / arm / mach-omap2 / include / mach / debug-macro.S
1 /* arch/arm/mach-omap2/include/mach/debug-macro.S
2  *
3  * Debugging macro include header
4  *
5  *  Copyright (C) 1994-1999 Russell King
6  *  Moved from linux/arch/arm/kernel/debug.S by Ben Dooks
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License version 2 as
10  * published by the Free Software Foundation.
11  *
12 */
13
14 #include <linux/serial_reg.h>
15
16 #include <asm/memory.h>
17
18 #include <plat/serial.h>
19
20 #define UART_OFFSET(addr)       ((addr) & 0x00ffffff)
21
22                 .pushsection .data
23 omap_uart_phys: .word   0
24 omap_uart_virt: .word   0
25 omap_uart_lsr:  .word   0
26                 .popsection
27
28                 /*
29                  * Note that this code won't work if the bootloader passes
30                  * a wrong machine ID number in r1. To debug, just hardcode
31                  * the desired UART phys and virt addresses temporarily into
32                  * the omap_uart_phys and omap_uart_virt above.
33                  */
34                 .macro  addruart, rx, tmp
35
36                 /* Use omap_uart_phys/virt if already configured */
37 10:             mrc     p15, 0, \rx, c1, c0
38                 tst     \rx, #1                 @ MMU enabled?
39                 ldreq   \rx, =omap_uart_phys    @ physical base address
40                 ldrne   \rx, =omap_uart_virt    @ virtual base address
41                 ldr     \rx, [\rx, #0]
42                 cmp     \rx, #0                 @ is port configured?
43                 bne     99f                     @ already configured
44
45                 /* Check the debug UART configuration set in uncompress.h */
46                 mrc     p15, 0, \rx, c1, c0
47                 tst     \rx, #1                 @ MMU enabled?
48                 ldreq   \rx, =OMAP_UART_INFO
49                 ldrne   \rx, =__phys_to_virt(OMAP_UART_INFO)
50                 ldr     \rx, [\rx, #0]
51
52                 /* Select the UART to use based on the UART1 scratchpad value */
53                 cmp     \rx, #0                 @ no port configured?
54                 beq     21f                     @ if none, try to use UART1
55                 cmp     \rx, #OMAP2UART1        @ OMAP2/3/4UART1
56                 beq     21f                     @ configure OMAP2/3/4UART1
57                 cmp     \rx, #OMAP2UART2        @ OMAP2/3/4UART2
58                 beq     22f                     @ configure OMAP2/3/4UART2
59                 cmp     \rx, #OMAP2UART3        @ only on 24xx
60                 beq     23f                     @ configure OMAP2UART3
61                 cmp     \rx, #OMAP3UART3        @ only on 34xx
62                 beq     33f                     @ configure OMAP3UART3
63                 cmp     \rx, #OMAP4UART3        @ only on 44xx
64                 beq     43f                     @ configure OMAP4UART3
65                 cmp     \rx, #OMAP3UART4        @ only on 36xx
66                 beq     34f                     @ configure OMAP3UART4
67                 cmp     \rx, #OMAP4UART4        @ only on 44xx
68                 beq     44f                     @ configure OMAP4UART4
69                 cmp     \rx, #ZOOM_UART         @ only on zoom2/3
70                 beq     95f                     @ configure ZOOM_UART
71
72                 /* Configure the UART offset from the phys/virt base */
73 21:             mov     \rx, #UART_OFFSET(OMAP2_UART1_BASE)     @ omap2/3/4
74                 b       98f
75 22:             mov     \rx, #UART_OFFSET(OMAP2_UART2_BASE)     @ omap2/3/4
76                 b       98f
77 23:             mov     \rx, #UART_OFFSET(OMAP2_UART3_BASE)
78                 b       98f
79 33:             mov     \rx, #UART_OFFSET(OMAP3_UART1_BASE)
80                 add     \rx, \rx, #0x00fb0000
81                 add     \rx, \rx, #0x00006000           @ OMAP3_UART3_BASE
82                 b       98f
83 34:             mov     \rx, #UART_OFFSET(OMAP3_UART1_BASE)
84                 add     \rx, \rx, #0x00fb0000
85                 add     \rx, \rx, #0x00028000           @ OMAP3_UART4_BASE
86                 b       98f
87 43:             mov     \rx, #UART_OFFSET(OMAP4_UART3_BASE)
88                 b       98f
89 44:             mov     \rx, #UART_OFFSET(OMAP4_UART4_BASE)
90                 b       98f
91 95:             ldr     \rx, =ZOOM_UART_BASE
92                 ldr     \tmp, =omap_uart_phys
93                 str     \rx, [\tmp, #0]
94                 ldr     \rx, =ZOOM_UART_VIRT
95                 ldr     \tmp, =omap_uart_virt
96                 str     \rx, [\tmp, #0]
97                 mov     \rx, #(UART_LSR << ZOOM_PORT_SHIFT)
98                 ldr     \tmp, =omap_uart_lsr
99                 str     \rx, [\tmp, #0]
100                 b       10b
101
102                 /* Store both phys and virt address for the uart */
103 98:             add     \rx, \rx, #0x48000000   @ phys base
104                 ldr     \tmp, =omap_uart_phys
105                 str     \rx, [\tmp, #0]
106                 sub     \rx, \rx, #0x48000000   @ phys base
107                 add     \rx, \rx, #0xfa000000   @ virt base
108                 ldr     \tmp, =omap_uart_virt
109                 str     \rx, [\tmp, #0]
110                 mov     \rx, #(UART_LSR << OMAP_PORT_SHIFT)
111                 ldr     \tmp, =omap_uart_lsr
112                 str     \rx, [\tmp, #0]
113
114                 b       10b
115 99:
116                 .endm
117
118                 .macro  senduart,rd,rx
119                 strb    \rd, [\rx]
120                 .endm
121
122                 .macro  busyuart,rd,rx
123 1001:           ldr     \rd, =omap_uart_lsr
124                 ldr     \rd, [\rd, #0]
125                 ldrb    \rd, [\rx, \rd]
126                 and     \rd, \rd, #(UART_LSR_TEMT | UART_LSR_THRE)
127                 teq     \rd, #(UART_LSR_TEMT | UART_LSR_THRE)
128                 bne     1001b
129                 .endm
130
131                 .macro  waituart,rd,rx
132                 .endm