ARM: SAMSUNG: Fix switching FIFO in arch_enable_uart_fifo function
[cascardo/linux.git] / arch / arm / plat-samsung / include / plat / uncompress.h
1 /* arch/arm/plat-samsung/include/plat/uncompress.h
2  *
3  * Copyright 2003, 2007 Simtec Electronics
4  *      http://armlinux.simtec.co.uk/
5  *      Ben Dooks <ben@simtec.co.uk>
6  *
7  * S3C - uncompress code
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License version 2 as
11  * published by the Free Software Foundation.
12 */
13
14 #ifndef __ASM_PLAT_UNCOMPRESS_H
15 #define __ASM_PLAT_UNCOMPRESS_H
16
17 typedef unsigned int upf_t;     /* cannot include linux/serial_core.h */
18
19 /* uart setup */
20
21 unsigned int fifo_mask;
22 unsigned int fifo_max;
23
24 volatile u8 *uart_base;
25
26 /* forward declerations */
27
28 static void arch_detect_cpu(void);
29
30 /* defines for UART registers */
31
32 #include <plat/regs-serial.h>
33
34 /* working in physical space... */
35 #define S3C_WDOGREG(x)  ((S3C_PA_WDT + (x)))
36
37 #define S3C2410_WTCON   S3C_WDOGREG(0x00)
38 #define S3C2410_WTDAT   S3C_WDOGREG(0x04)
39 #define S3C2410_WTCNT   S3C_WDOGREG(0x08)
40
41 #define S3C2410_WTCON_RSTEN     (1 << 0)
42 #define S3C2410_WTCON_ENABLE    (1 << 5)
43
44 #define S3C2410_WTCON_DIV128    (3 << 3)
45
46 #define S3C2410_WTCON_PRESCALE(x)       ((x) << 8)
47
48 /* how many bytes we allow into the FIFO at a time in FIFO mode */
49 #define FIFO_MAX         (14)
50
51 static __inline__ void
52 uart_wr(unsigned int reg, unsigned int val)
53 {
54         volatile unsigned int *ptr;
55
56         ptr = (volatile unsigned int *)(reg + uart_base);
57         *ptr = val;
58 }
59
60 static __inline__ unsigned int
61 uart_rd(unsigned int reg)
62 {
63         volatile unsigned int *ptr;
64
65         ptr = (volatile unsigned int *)(reg + uart_base);
66         return *ptr;
67 }
68
69 /* we can deal with the case the UARTs are being run
70  * in FIFO mode, so that we don't hold up our execution
71  * waiting for tx to happen...
72 */
73
74 static void putc(int ch)
75 {
76         if (!config_enabled(CONFIG_DEBUG_LL))
77                 return;
78
79         if (uart_rd(S3C2410_UFCON) & S3C2410_UFCON_FIFOMODE) {
80                 int level;
81
82                 while (1) {
83                         level = uart_rd(S3C2410_UFSTAT);
84                         level &= fifo_mask;
85
86                         if (level < fifo_max)
87                                 break;
88                 }
89
90         } else {
91                 /* not using fifos */
92
93                 while ((uart_rd(S3C2410_UTRSTAT) & S3C2410_UTRSTAT_TXE) != S3C2410_UTRSTAT_TXE)
94                         barrier();
95         }
96
97         /* write byte to transmission register */
98         uart_wr(S3C2410_UTXH, ch);
99 }
100
101 static inline void flush(void)
102 {
103 }
104
105 #define __raw_writel(d, ad)                     \
106         do {                                                    \
107                 *((volatile unsigned int __force *)(ad)) = (d); \
108         } while (0)
109
110 #ifdef CONFIG_S3C_BOOT_ERROR_RESET
111
112 static void arch_decomp_error(const char *x)
113 {
114         putstr("\n\n");
115         putstr(x);
116         putstr("\n\n -- System resetting\n");
117
118         __raw_writel(0x4000, S3C2410_WTDAT);
119         __raw_writel(0x4000, S3C2410_WTCNT);
120         __raw_writel(S3C2410_WTCON_ENABLE | S3C2410_WTCON_DIV128 | S3C2410_WTCON_RSTEN | S3C2410_WTCON_PRESCALE(0x40), S3C2410_WTCON);
121
122         while(1);
123 }
124
125 #define arch_error arch_decomp_error
126 #endif
127
128 #ifdef CONFIG_S3C_BOOT_UART_FORCE_FIFO
129 static inline void arch_enable_uart_fifo(void)
130 {
131         u32 fifocon;
132
133         if (!config_enabled(CONFIG_DEBUG_LL))
134                 return;
135
136         fifocon = uart_rd(S3C2410_UFCON);
137
138         if (!(fifocon & S3C2410_UFCON_FIFOMODE)) {
139                 fifocon |= S3C2410_UFCON_RESETBOTH;
140                 uart_wr(S3C2410_UFCON, fifocon);
141
142                 /* wait for fifo reset to complete */
143                 while (1) {
144                         fifocon = uart_rd(S3C2410_UFCON);
145                         if (!(fifocon & S3C2410_UFCON_RESETBOTH))
146                                 break;
147                 }
148
149                 uart_wr(S3C2410_UFCON, S3C2410_UFCON_FIFOMODE);
150         }
151 }
152 #else
153 #define arch_enable_uart_fifo() do { } while(0)
154 #endif
155
156
157 static void
158 arch_decomp_setup(void)
159 {
160         /* we may need to setup the uart(s) here if we are not running
161          * on an BAST... the BAST will have left the uarts configured
162          * after calling linux.
163          */
164
165         arch_detect_cpu();
166
167         /* Enable the UART FIFOs if they where not enabled and our
168          * configuration says we should turn them on.
169          */
170
171         arch_enable_uart_fifo();
172 }
173
174
175 #endif /* __ASM_PLAT_UNCOMPRESS_H */