Ben Dooks | c116c1d | 2010-01-29 09:02:12 +0000 | [diff] [blame] | 1 | /* arch/arm/plat-samsung/include/plat/uncompress.h |
Ben Dooks | a14a26a | 2007-07-22 16:13:29 +0100 | [diff] [blame] | 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 | |
Nicolas Pitre | 8ea0de4 | 2011-04-28 17:00:17 -0400 | [diff] [blame] | 21 | unsigned int fifo_mask; |
| 22 | unsigned int fifo_max; |
Ben Dooks | a14a26a | 2007-07-22 16:13:29 +0100 | [diff] [blame] | 23 | |
| 24 | /* forward declerations */ |
| 25 | |
| 26 | static void arch_detect_cpu(void); |
| 27 | |
| 28 | /* defines for UART registers */ |
| 29 | |
Ben Dooks | a2b7ba9 | 2008-10-07 22:26:09 +0100 | [diff] [blame] | 30 | #include <plat/regs-serial.h> |
Ben Dooks | 180ee70 | 2008-10-30 10:14:32 +0000 | [diff] [blame] | 31 | #include <plat/regs-watchdog.h> |
Ben Dooks | a14a26a | 2007-07-22 16:13:29 +0100 | [diff] [blame] | 32 | |
| 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 Kim | 171c067 | 2012-02-10 11:57:53 +0900 | [diff] [blame] | 40 | #ifdef S3C_PA_UART |
Ben Dooks | e1a2bd1 | 2008-10-21 14:06:45 +0100 | [diff] [blame] | 41 | #define uart_base S3C_PA_UART + (S3C_UART_OFFSET * CONFIG_S3C_LOWLEVEL_UART_PORT) |
Kukjin Kim | 171c067 | 2012-02-10 11:57:53 +0900 | [diff] [blame] | 42 | #endif |
Ben Dooks | a14a26a | 2007-07-22 16:13:29 +0100 | [diff] [blame] | 43 | |
| 44 | static __inline__ void |
| 45 | uart_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 | |
| 53 | static __inline__ unsigned int |
| 54 | uart_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 | |
| 67 | static void putc(int ch) |
| 68 | { |
Tushar Behera | 437d8ac | 2013-06-04 09:49:10 +0530 | [diff] [blame] | 69 | if (!config_enabled(CONFIG_DEBUG_LL)) |
| 70 | return; |
| 71 | |
Ben Dooks | a14a26a | 2007-07-22 16:13:29 +0100 | [diff] [blame] | 72 | 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 | |
| 94 | static inline void flush(void) |
| 95 | { |
| 96 | } |
| 97 | |
Daniel Silverstone | 1144d65 | 2009-02-10 13:39:52 +0100 | [diff] [blame] | 98 | #define __raw_writel(d, ad) \ |
| 99 | do { \ |
| 100 | *((volatile unsigned int __force *)(ad)) = (d); \ |
| 101 | } while (0) |
Ben Dooks | a14a26a | 2007-07-22 16:13:29 +0100 | [diff] [blame] | 102 | |
Ben Dooks | a45f826 | 2007-07-22 16:16:51 +0100 | [diff] [blame] | 103 | #ifdef CONFIG_S3C_BOOT_ERROR_RESET |
Ben Dooks | a14a26a | 2007-07-22 16:13:29 +0100 | [diff] [blame] | 104 | |
| 105 | static 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 Dooks | e7aa6f4 | 2008-12-02 19:34:52 +0000 | [diff] [blame] | 121 | #ifdef CONFIG_S3C_BOOT_UART_FORCE_FIFO |
| 122 | static inline void arch_enable_uart_fifo(void) |
| 123 | { |
Tushar Behera | 437d8ac | 2013-06-04 09:49:10 +0530 | [diff] [blame] | 124 | u32 fifocon; |
| 125 | |
| 126 | if (!config_enabled(CONFIG_DEBUG_LL)) |
| 127 | return; |
| 128 | |
| 129 | fifocon = uart_rd(S3C2410_UFCON); |
Ben Dooks | e7aa6f4 | 2008-12-02 19:34:52 +0000 | [diff] [blame] | 130 | |
| 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 Dooks | a14a26a | 2007-07-22 16:13:29 +0100 | [diff] [blame] | 148 | static void |
| 149 | arch_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 Dooks | e7aa6f4 | 2008-12-02 19:34:52 +0000 | [diff] [blame] | 157 | |
| 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 Dooks | a14a26a | 2007-07-22 16:13:29 +0100 | [diff] [blame] | 163 | } |
| 164 | |
| 165 | |
| 166 | #endif /* __ASM_PLAT_UNCOMPRESS_H */ |