blob: a6f6a0e44afaf2e818a716288fc7ba34e1316ffc [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/* linux/include/asm-arm/arch-s3c2410/uncompress.h
2 *
3 * (c) 2003 Simtec Electronics
4 * Ben Dooks <ben@simtec.co.uk>
5 *
6 * S3C2410 - uncompress code
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 * Changelog:
13 * 22-May-2003 BJD Created
14 * 08-Sep-2003 BJD Moved to linux v2.6
15 * 12-Mar-2004 BJD Updated header protection
16 * 12-Oct-2004 BJD Take account of debug uart configuration
17 * 15-Nov-2004 BJD Fixed uart configuration
18 * 22-Feb-2005 BJD Added watchdog to uncompress
Lucas Correia Villa Realbd7b1702005-04-25 23:12:50 +010019 * 04-Apr-2005 LCVR Added support to S3C2400 (no cpuid at GSTATUS1)
Linus Torvalds1da177e2005-04-16 15:20:36 -070020*/
21
22#ifndef __ASM_ARCH_UNCOMPRESS_H
23#define __ASM_ARCH_UNCOMPRESS_H
24
25#include <linux/config.h>
26
27/* defines for UART registers */
28#include "asm/arch/regs-serial.h"
29#include "asm/arch/regs-gpio.h"
30#include "asm/arch/regs-watchdog.h"
31
32#include <asm/arch/map.h>
33
34/* working in physical space... */
35#undef S3C2410_GPIOREG
36#undef S3C2410_WDOGREG
37
Lucas Correia Villa Real0367a8d2006-01-26 15:20:50 +000038#define S3C2410_GPIOREG(x) ((S3C24XX_PA_GPIO + (x)))
39#define S3C2410_WDOGREG(x) ((S3C24XX_PA_WATCHDOG + (x)))
Linus Torvalds1da177e2005-04-16 15:20:36 -070040
41/* how many bytes we allow into the FIFO at a time in FIFO mode */
42#define FIFO_MAX (14)
43
Lucas Correia Villa Real0367a8d2006-01-26 15:20:50 +000044#define uart_base S3C24XX_PA_UART + (0x4000*CONFIG_S3C2410_LOWLEVEL_UART_PORT)
Linus Torvalds1da177e2005-04-16 15:20:36 -070045
46static __inline__ void
47uart_wr(unsigned int reg, unsigned int val)
48{
49 volatile unsigned int *ptr;
50
51 ptr = (volatile unsigned int *)(reg + uart_base);
52 *ptr = val;
53}
54
55static __inline__ unsigned int
56uart_rd(unsigned int reg)
57{
58 volatile unsigned int *ptr;
59
60 ptr = (volatile unsigned int *)(reg + uart_base);
61 return *ptr;
62}
63
64
65/* we can deal with the case the UARTs are being run
66 * in FIFO mode, so that we don't hold up our execution
67 * waiting for tx to happen...
68*/
69
Russell Kinga0815682006-03-28 10:24:33 +010070static void putc(int ch)
Linus Torvalds1da177e2005-04-16 15:20:36 -070071{
Lucas Correia Villa Realbd7b1702005-04-25 23:12:50 +010072 int cpuid = S3C2410_GSTATUS1_2410;
Linus Torvalds1da177e2005-04-16 15:20:36 -070073
Lucas Correia Villa Realbd7b1702005-04-25 23:12:50 +010074#ifndef CONFIG_CPU_S3C2400
75 cpuid = *((volatile unsigned int *)S3C2410_GSTATUS1);
Linus Torvalds1da177e2005-04-16 15:20:36 -070076 cpuid &= S3C2410_GSTATUS1_IDMASK;
Lucas Correia Villa Realbd7b1702005-04-25 23:12:50 +010077#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070078
Linus Torvalds1da177e2005-04-16 15:20:36 -070079 if (uart_rd(S3C2410_UFCON) & S3C2410_UFCON_FIFOMODE) {
80 int level;
81
82 while (1) {
83 level = uart_rd(S3C2410_UFSTAT);
84
85 if (cpuid == S3C2410_GSTATUS1_2440) {
86 level &= S3C2440_UFSTAT_TXMASK;
87 level >>= S3C2440_UFSTAT_TXSHIFT;
88 } else {
89 level &= S3C2410_UFSTAT_TXMASK;
90 level >>= S3C2410_UFSTAT_TXSHIFT;
91 }
92
93 if (level < FIFO_MAX)
94 break;
95 }
96
97 } else {
98 /* not using fifos */
99
Russell Kinga0815682006-03-28 10:24:33 +0100100 while ((uart_rd(S3C2410_UTRSTAT) & S3C2410_UTRSTAT_TXE) != S3C2410_UTRSTAT_TXE)
101 barrier();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102 }
103
104 /* write byte to transmission register */
105 uart_wr(S3C2410_UTXH, ch);
106}
107
Russell Kinga0815682006-03-28 10:24:33 +0100108static inline void flush(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110}
111
Ben Dooksf8c905d2005-11-08 22:43:05 +0000112#define __raw_writel(d,ad) do { *((volatile unsigned int *)(ad)) = (d); } while(0)
113
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114/* CONFIG_S3C2410_BOOT_WATCHDOG
115 *
116 * Simple boot-time watchdog setup, to reboot the system if there is
117 * any problem with the boot process
118*/
119
120#ifdef CONFIG_S3C2410_BOOT_WATCHDOG
121
122#define WDOG_COUNT (0xff00)
123
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124static inline void arch_decomp_wdog(void)
125{
126 __raw_writel(WDOG_COUNT, S3C2410_WTCNT);
127}
128
129static void arch_decomp_wdog_start(void)
130{
131 __raw_writel(WDOG_COUNT, S3C2410_WTDAT);
132 __raw_writel(WDOG_COUNT, S3C2410_WTCNT);
133 __raw_writel(S3C2410_WTCON_ENABLE | S3C2410_WTCON_DIV128 | S3C2410_WTCON_RSTEN | S3C2410_WTCON_PRESCALE(0x40), S3C2410_WTCON);
134}
135
136#else
137#define arch_decomp_wdog_start()
138#define arch_decomp_wdog()
139#endif
140
Ben Dooksf8c905d2005-11-08 22:43:05 +0000141#ifdef CONFIG_S3C2410_BOOT_ERROR_RESET
142
143static void arch_decomp_error(const char *x)
144{
145 putstr("\n\n");
146 putstr(x);
147 putstr("\n\n -- System resetting\n");
148
149 __raw_writel(0x4000, S3C2410_WTDAT);
150 __raw_writel(0x4000, S3C2410_WTCNT);
151 __raw_writel(S3C2410_WTCON_ENABLE | S3C2410_WTCON_DIV128 | S3C2410_WTCON_RSTEN | S3C2410_WTCON_PRESCALE(0x40), S3C2410_WTCON);
152
153 while(1);
154}
155
156#define arch_error arch_decomp_error
157#endif
158
Linus Torvalds1da177e2005-04-16 15:20:36 -0700159static void error(char *err);
160
161static void
162arch_decomp_setup(void)
163{
164 /* we may need to setup the uart(s) here if we are not running
165 * on an BAST... the BAST will have left the uarts configured
166 * after calling linux.
167 */
168
169 arch_decomp_wdog_start();
170}
171
172
173#endif /* __ASM_ARCH_UNCOMPRESS_H */