blob: 02b66d723d1a04b46dc288f88b0c0a710bc52350 [file] [log] [blame]
Ben Dooksc116c1d2010-01-29 09:02:12 +00001/* arch/arm/plat-samsung/include/plat/uncompress.h
Ben Dooksa14a26a2007-07-22 16:13:29 +01002 *
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
17typedef unsigned int upf_t; /* cannot include linux/serial_core.h */
18
19/* uart setup */
20
Nicolas Pitre8ea0de42011-04-28 17:00:17 -040021unsigned int fifo_mask;
22unsigned int fifo_max;
Ben Dooksa14a26a2007-07-22 16:13:29 +010023
24/* forward declerations */
25
26static void arch_detect_cpu(void);
27
28/* defines for UART registers */
29
Ben Dooksa2b7ba92008-10-07 22:26:09 +010030#include <plat/regs-serial.h>
Ben Dooks180ee702008-10-30 10:14:32 +000031#include <plat/regs-watchdog.h>
Ben Dooksa14a26a2007-07-22 16:13:29 +010032
33/* working in physical space... */
34#undef S3C2410_WDOGREG
35#define S3C2410_WDOGREG(x) ((S3C24XX_PA_WATCHDOG + (x)))
36
37/* how many bytes we allow into the FIFO at a time in FIFO mode */
38#define FIFO_MAX (14)
39
Kukjin Kim171c0672012-02-10 11:57:53 +090040#ifdef S3C_PA_UART
Ben Dookse1a2bd12008-10-21 14:06:45 +010041#define uart_base S3C_PA_UART + (S3C_UART_OFFSET * CONFIG_S3C_LOWLEVEL_UART_PORT)
Kukjin Kim171c0672012-02-10 11:57:53 +090042#endif
Ben Dooksa14a26a2007-07-22 16:13:29 +010043
44static __inline__ void
45uart_wr(unsigned int reg, unsigned int val)
46{
47 volatile unsigned int *ptr;
48
49 ptr = (volatile unsigned int *)(reg + uart_base);
50 *ptr = val;
51}
52
53static __inline__ unsigned int
54uart_rd(unsigned int reg)
55{
56 volatile unsigned int *ptr;
57
58 ptr = (volatile unsigned int *)(reg + uart_base);
59 return *ptr;
60}
61
62/* we can deal with the case the UARTs are being run
63 * in FIFO mode, so that we don't hold up our execution
64 * waiting for tx to happen...
65*/
66
67static void putc(int ch)
68{
Tushar Behera437d8ac2013-06-04 09:49:10 +053069 if (!config_enabled(CONFIG_DEBUG_LL))
70 return;
71
Ben Dooksa14a26a2007-07-22 16:13:29 +010072 if (uart_rd(S3C2410_UFCON) & S3C2410_UFCON_FIFOMODE) {
73 int level;
74
75 while (1) {
76 level = uart_rd(S3C2410_UFSTAT);
77 level &= fifo_mask;
78
79 if (level < fifo_max)
80 break;
81 }
82
83 } else {
84 /* not using fifos */
85
86 while ((uart_rd(S3C2410_UTRSTAT) & S3C2410_UTRSTAT_TXE) != S3C2410_UTRSTAT_TXE)
87 barrier();
88 }
89
90 /* write byte to transmission register */
91 uart_wr(S3C2410_UTXH, ch);
92}
93
94static inline void flush(void)
95{
96}
97
Daniel Silverstone1144d652009-02-10 13:39:52 +010098#define __raw_writel(d, ad) \
99 do { \
100 *((volatile unsigned int __force *)(ad)) = (d); \
101 } while (0)
Ben Dooksa14a26a2007-07-22 16:13:29 +0100102
Ben Dooksa45f8262007-07-22 16:16:51 +0100103#ifdef CONFIG_S3C_BOOT_ERROR_RESET
Ben Dooksa14a26a2007-07-22 16:13:29 +0100104
105static void arch_decomp_error(const char *x)
106{
107 putstr("\n\n");
108 putstr(x);
109 putstr("\n\n -- System resetting\n");
110
111 __raw_writel(0x4000, S3C2410_WTDAT);
112 __raw_writel(0x4000, S3C2410_WTCNT);
113 __raw_writel(S3C2410_WTCON_ENABLE | S3C2410_WTCON_DIV128 | S3C2410_WTCON_RSTEN | S3C2410_WTCON_PRESCALE(0x40), S3C2410_WTCON);
114
115 while(1);
116}
117
118#define arch_error arch_decomp_error
119#endif
120
Ben Dookse7aa6f42008-12-02 19:34:52 +0000121#ifdef CONFIG_S3C_BOOT_UART_FORCE_FIFO
122static inline void arch_enable_uart_fifo(void)
123{
Tushar Behera437d8ac2013-06-04 09:49:10 +0530124 u32 fifocon;
125
126 if (!config_enabled(CONFIG_DEBUG_LL))
127 return;
128
129 fifocon = uart_rd(S3C2410_UFCON);
Ben Dookse7aa6f42008-12-02 19:34:52 +0000130
131 if (!(fifocon & S3C2410_UFCON_FIFOMODE)) {
132 fifocon |= S3C2410_UFCON_RESETBOTH;
133 uart_wr(S3C2410_UFCON, fifocon);
134
135 /* wait for fifo reset to complete */
136 while (1) {
137 fifocon = uart_rd(S3C2410_UFCON);
138 if (!(fifocon & S3C2410_UFCON_RESETBOTH))
139 break;
140 }
141 }
142}
143#else
144#define arch_enable_uart_fifo() do { } while(0)
145#endif
146
147
Ben Dooksa14a26a2007-07-22 16:13:29 +0100148static void
149arch_decomp_setup(void)
150{
151 /* we may need to setup the uart(s) here if we are not running
152 * on an BAST... the BAST will have left the uarts configured
153 * after calling linux.
154 */
155
156 arch_detect_cpu();
Ben Dookse7aa6f42008-12-02 19:34:52 +0000157
158 /* Enable the UART FIFOs if they where not enabled and our
159 * configuration says we should turn them on.
160 */
161
162 arch_enable_uart_fifo();
Ben Dooksa14a26a2007-07-22 16:13:29 +0100163}
164
165
166#endif /* __ASM_PLAT_UNCOMPRESS_H */