blob: 4ebb609369e36895e0da7e68021eb6cbc962532e [file] [log] [blame]
Russell Kinga09e64f2008-08-05 16:14:15 +01001/*
2 * arch/arm/mach-at91/include/mach/uncompress.h
3 *
Jean-Christophe PLAGNIOL-VILLARD5f29d0a2012-02-15 18:44:40 +08004 * Copyright (C) 2003 SAN People
5 * Copyright (C) 2012 Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
Russell Kinga09e64f2008-08-05 16:14:15 +01006 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 */
21
22#ifndef __ASM_ARCH_UNCOMPRESS_H
23#define __ASM_ARCH_UNCOMPRESS_H
24
Russell Kingfced80c2008-09-06 12:10:45 +010025#include <linux/io.h>
Russell Kinga09e64f2008-08-05 16:14:15 +010026#include <linux/atmel_serial.h>
Rob Herring4091ac42012-02-29 13:07:39 -060027#include <mach/hardware.h>
Russell Kinga09e64f2008-08-05 16:14:15 +010028
Jean-Christophe PLAGNIOL-VILLARD5f29d0a2012-02-15 18:44:40 +080029#include <mach/at91_dbgu.h>
30#include <mach/cpu.h>
Russell Kinga09e64f2008-08-05 16:14:15 +010031
Jean-Christophe PLAGNIOL-VILLARDc40a7632012-02-15 18:35:40 +080032void __iomem *at91_uart;
33
Jean-Christophe PLAGNIOL-VILLARD5f29d0a2012-02-15 18:44:40 +080034static const u32 uarts_rm9200[] = {
35 AT91_BASE_DBGU0,
36 AT91RM9200_BASE_US0,
37 AT91RM9200_BASE_US1,
38 AT91RM9200_BASE_US2,
39 AT91RM9200_BASE_US3,
40 0,
41};
42
43static const u32 uarts_sam9260[] = {
44 AT91_BASE_DBGU0,
45 AT91SAM9260_BASE_US0,
46 AT91SAM9260_BASE_US1,
47 AT91SAM9260_BASE_US2,
48 AT91SAM9260_BASE_US3,
49 AT91SAM9260_BASE_US4,
50 AT91SAM9260_BASE_US5,
51 0,
52};
53
54static const u32 uarts_sam9261[] = {
55 AT91_BASE_DBGU0,
56 AT91SAM9261_BASE_US0,
57 AT91SAM9261_BASE_US1,
58 AT91SAM9261_BASE_US2,
59 0,
60};
61
62static const u32 uarts_sam9263[] = {
63 AT91_BASE_DBGU1,
64 AT91SAM9263_BASE_US0,
65 AT91SAM9263_BASE_US1,
66 AT91SAM9263_BASE_US2,
67 0,
68};
69
70static const u32 uarts_sam9g45[] = {
71 AT91_BASE_DBGU1,
72 AT91SAM9G45_BASE_US0,
73 AT91SAM9G45_BASE_US1,
74 AT91SAM9G45_BASE_US2,
75 AT91SAM9G45_BASE_US3,
76 0,
77};
78
79static const u32 uarts_sam9rl[] = {
80 AT91_BASE_DBGU0,
81 AT91SAM9RL_BASE_US0,
82 AT91SAM9RL_BASE_US1,
83 AT91SAM9RL_BASE_US2,
84 AT91SAM9RL_BASE_US3,
85 0,
86};
87
88static const u32 uarts_sam9x5[] = {
89 AT91_BASE_DBGU0,
90 AT91SAM9X5_BASE_USART0,
91 AT91SAM9X5_BASE_USART1,
92 AT91SAM9X5_BASE_USART2,
93 0,
94};
95
Nicolas Ferre726d32b2014-09-15 18:15:55 +020096static const u32 uarts_sama5d3[] = {
Bo Shenacbece32013-07-04 15:16:41 +080097 AT91_BASE_DBGU1,
98 SAMA5D3_BASE_USART0,
99 SAMA5D3_BASE_USART1,
100 SAMA5D3_BASE_USART2,
101 SAMA5D3_BASE_USART3,
102 0,
103};
104
Nicolas Ferre726d32b2014-09-15 18:15:55 +0200105static const u32 uarts_sama5d4[] = {
106 AT91_BASE_DBGU2,
107 SAMA5D4_BASE_USART3,
108 0,
109};
110
Arnd Bergmanndca4ba42012-09-14 20:10:19 +0000111static inline const u32* decomp_soc_detect(void __iomem *dbgu_base)
Jean-Christophe PLAGNIOL-VILLARD5f29d0a2012-02-15 18:44:40 +0800112{
113 u32 cidr, socid;
114
115 cidr = __raw_readl(dbgu_base + AT91_DBGU_CIDR);
116 socid = cidr & ~AT91_CIDR_VERSION;
117
118 switch (socid) {
119 case ARCH_ID_AT91RM9200:
120 return uarts_rm9200;
121
122 case ARCH_ID_AT91SAM9G20:
123 case ARCH_ID_AT91SAM9260:
124 return uarts_sam9260;
125
126 case ARCH_ID_AT91SAM9261:
127 return uarts_sam9261;
128
129 case ARCH_ID_AT91SAM9263:
130 return uarts_sam9263;
131
132 case ARCH_ID_AT91SAM9G45:
133 return uarts_sam9g45;
134
135 case ARCH_ID_AT91SAM9RL64:
136 return uarts_sam9rl;
137
Bo Shen6dd678e2013-07-04 15:16:42 +0800138 case ARCH_ID_AT91SAM9N12:
Jean-Christophe PLAGNIOL-VILLARD5f29d0a2012-02-15 18:44:40 +0800139 case ARCH_ID_AT91SAM9X5:
140 return uarts_sam9x5;
Bo Shenacbece32013-07-04 15:16:41 +0800141
Nicolas Ferre726d32b2014-09-15 18:15:55 +0200142 case ARCH_ID_SAMA5:
143 cidr = __raw_readl(dbgu_base + AT91_DBGU_EXID);
144 if (cidr & ARCH_EXID_SAMA5D3)
145 return uarts_sama5d3;
146 else if (cidr & ARCH_EXID_SAMA5D4)
147 return uarts_sama5d4;
148
149 break;
Jean-Christophe PLAGNIOL-VILLARD5f29d0a2012-02-15 18:44:40 +0800150 }
151
152 /* at91sam9g10 */
153 if ((cidr & ~AT91_CIDR_EXT) == ARCH_ID_AT91SAM9G10) {
154 return uarts_sam9261;
155 }
156 /* at91sam9xe */
157 else if ((cidr & AT91_CIDR_ARCH) == ARCH_FAMILY_AT91SAM9XE) {
158 return uarts_sam9260;
159 }
160
161 return NULL;
162}
163
Jean-Christophe PLAGNIOL-VILLARDc40a7632012-02-15 18:35:40 +0800164static inline void arch_decomp_setup(void)
165{
Jean-Christophe PLAGNIOL-VILLARD5f29d0a2012-02-15 18:44:40 +0800166 int i = 0;
167 const u32* usarts;
168
Arnd Bergmanndca4ba42012-09-14 20:10:19 +0000169 usarts = decomp_soc_detect((void __iomem *)AT91_BASE_DBGU0);
Jean-Christophe PLAGNIOL-VILLARD5f29d0a2012-02-15 18:44:40 +0800170 if (!usarts)
Arnd Bergmanndca4ba42012-09-14 20:10:19 +0000171 usarts = decomp_soc_detect((void __iomem *)AT91_BASE_DBGU1);
Nicolas Ferre726d32b2014-09-15 18:15:55 +0200172 if (!usarts)
173 usarts = decomp_soc_detect((void __iomem *)AT91_BASE_DBGU2);
Jean-Christophe PLAGNIOL-VILLARD5f29d0a2012-02-15 18:44:40 +0800174 if (!usarts) {
175 at91_uart = NULL;
176 return;
177 }
178
179 do {
180 /* physical address */
181 at91_uart = (void __iomem *)usarts[i];
182
183 if (__raw_readl(at91_uart + ATMEL_US_BRGR))
184 return;
185 i++;
186 } while (usarts[i]);
187
188 at91_uart = NULL;
Jean-Christophe PLAGNIOL-VILLARDc40a7632012-02-15 18:35:40 +0800189}
Jean-Christophe PLAGNIOL-VILLARD5f29d0a2012-02-15 18:44:40 +0800190
Russell Kinga09e64f2008-08-05 16:14:15 +0100191/*
192 * The following code assumes the serial port has already been
193 * initialized by the bootloader. If you didn't setup a port in
194 * your bootloader then nothing will appear (which might be desired).
195 *
196 * This does not append a newline
197 */
198static void putc(int c)
199{
Jean-Christophe PLAGNIOL-VILLARD5f29d0a2012-02-15 18:44:40 +0800200 if (!at91_uart)
201 return;
202
Jean-Christophe PLAGNIOL-VILLARDc40a7632012-02-15 18:35:40 +0800203 while (!(__raw_readl(at91_uart + ATMEL_US_CSR) & ATMEL_US_TXRDY))
Russell Kinga09e64f2008-08-05 16:14:15 +0100204 barrier();
Jean-Christophe PLAGNIOL-VILLARDc40a7632012-02-15 18:35:40 +0800205 __raw_writel(c, at91_uart + ATMEL_US_THR);
Russell Kinga09e64f2008-08-05 16:14:15 +0100206}
207
208static inline void flush(void)
209{
Jean-Christophe PLAGNIOL-VILLARD5f29d0a2012-02-15 18:44:40 +0800210 if (!at91_uart)
211 return;
212
Russell Kinga09e64f2008-08-05 16:14:15 +0100213 /* wait for transmission to complete */
Jean-Christophe PLAGNIOL-VILLARDc40a7632012-02-15 18:35:40 +0800214 while (!(__raw_readl(at91_uart + ATMEL_US_CSR) & ATMEL_US_TXEMPTY))
Russell Kinga09e64f2008-08-05 16:14:15 +0100215 barrier();
Russell Kinga09e64f2008-08-05 16:14:15 +0100216}
217
Russell Kinga09e64f2008-08-05 16:14:15 +0100218#endif