summaryrefslogtreecommitdiff
path: root/meta-openbmc-mods/meta-ast2500/recipes-bsp/u-boot/files/0006-Add-Aspeed-g5-interrupt-support.patch
blob: 4f90d6dfef2ba60eb858c455f57563890d022954 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
From e782f6a90468fee35877b78e248a17f39f67c94c Mon Sep 17 00:00:00 2001
From: Vernon Mauery <vernon.mauery@linux.intel.com>
Date: Wed, 14 Nov 2018 10:21:40 -0800
Subject: [PATCH] Add Aspeed g5 interrupt support

This adds a few new files to the board g5 directory. Several Intel
features require interrupts running in U-Boot, so this adds basic
interrupt registration and handling support.

Signed-off-by: Vernon Mauery <vernon.mauery@linux.intel.com>
Change-Id: Id7072f1408dcf364968b1b74f2192e50a22a82f0

---
 Kconfig                             |  13 +++
 arch/arm/lib/interrupts.c           |  11 +++
 board/aspeed/ast-g5/Makefile        |   3 +-
 board/aspeed/ast-g5/ast-g5-irq.c    | 176 ++++++++++++++++++++++++++++++++++++
 board/aspeed/ast-g5/ast-g5-irq.h    |  39 ++++++++
 board/aspeed/ast-g5/ast-g5.c        |   3 +
 board/aspeed/ast-g5/ast-g5.h        |   7 ++
 cmd/Kconfig                         |   5 +
 configs/ast_g5_ncsi_2boot_defconfig |   1 +
 configs/ast_g5_ncsi_defconfig       |   1 +
 configs/ast_g5_phy_defconfig        |   1 +
 11 files changed, 259 insertions(+), 1 deletion(-)
 create mode 100644 board/aspeed/ast-g5/ast-g5-irq.c
 create mode 100644 board/aspeed/ast-g5/ast-g5-irq.h
 create mode 100644 board/aspeed/ast-g5/ast-g5.h

diff --git a/Kconfig b/Kconfig
index 3ceff25..d6439d0 100644
--- a/Kconfig
+++ b/Kconfig
@@ -115,6 +115,19 @@ if EXPERT
 	  When disabling this, please check if malloc calls, maybe
 	  should be replaced by calloc - if one expects zeroed memory.
 endif
+
+config USE_IRQ
+	bool "Use interrupts"
+	default n
+
+config STACKSIZE_IRQ
+	int "Size for IRQ stack (only if USE_IRQ enabled)"
+	default 16384
+
+config STACKSIZE_FIQ
+	int "Size for FIQ stack (only if USE_IRQ enabled)"
+	default 16384
+
 endmenu		# General setup
 
 menu "Boot images"
diff --git a/arch/arm/lib/interrupts.c b/arch/arm/lib/interrupts.c
index ed83043..a96b3aa 100644
--- a/arch/arm/lib/interrupts.c
+++ b/arch/arm/lib/interrupts.c
@@ -94,6 +94,17 @@ int disable_interrupts (void)
 			     : "memory");
 	return (old & 0x80) == 0;
 }
+
+int global_interrupts_enabled(void)
+{
+	unsigned long old;
+	__asm__ __volatile__("mrs %0, cpsr\n"
+			     : "=r" (old)
+			     :
+			     : "memory");
+	return (old & 0x80) == 0;
+}
+
 #else
 int interrupt_init (void)
 {
diff --git a/board/aspeed/ast-g5/Makefile b/board/aspeed/ast-g5/Makefile
index d1d7f85..df4e639 100644
--- a/board/aspeed/ast-g5/Makefile
+++ b/board/aspeed/ast-g5/Makefile
@@ -1 +1,2 @@
-obj-y   = ast-g5.o
+obj-y += ast-g5.o
+obj-y += ast-g5-irq.o
diff --git a/board/aspeed/ast-g5/ast-g5-irq.c b/board/aspeed/ast-g5/ast-g5-irq.c
new file mode 100644
index 0000000..860f16c
--- /dev/null
+++ b/board/aspeed/ast-g5/ast-g5-irq.c
@@ -0,0 +1,176 @@
+/*
+ * Copyright 2018 Intel Corporation
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version
+ * 2 of the License, or (at your option) any later version.
+ */
+
+#include <common.h>
+#include <netdev.h>
+
+#include <asm/arch/ast_scu.h>
+#include <asm/arch/ast-sdmc.h>
+#include <asm/io.h>
+
+#include "ast-g5.h"
+#include "ast-g5-irq.h"
+
+DECLARE_GLOBAL_DATA_PTR;
+
+#ifdef CONFIG_USE_IRQ
+
+#define VIC_STATUS_L 0x80
+#define VIC_STATUS_H 0x84
+#define VIC_IRQ_SELECTION_L 0x98
+#define VIC_IRQ_SELECTION_H 0x9C
+#define VIC_ENABLE_L 0xA0
+#define VIC_ENABLE_H 0xA4
+#define VIC_ENABLE_CLEAR_L 0xA8
+#define VIC_ENABLE_CLEAR_H 0xAC
+#define VIC_INTERRUPT_CLEAR_L 0xD8
+#define VIC_INTERRUPT_CLEAR_H 0xDC
+
+#define VIC_CLEAR_ALL (~0)
+
+int arch_interrupt_init_early(void)
+{
+	writel(VIC_CLEAR_ALL, AST_VIC_BASE + VIC_ENABLE_CLEAR_L);
+	writel(VIC_CLEAR_ALL, AST_VIC_BASE + VIC_ENABLE_CLEAR_H);
+	return 0;
+}
+int arch_interrupt_init(void)
+{
+	return 0;
+}
+
+#define AST_IRQ_START_L 0
+#define AST_IRQ_END_L 31
+#define AST_IRQ_START_H 32
+#define AST_IRQ_END_H 63
+#define AST_IRQ_COUNT 64
+static interrupt_handler_t *handlers[AST_IRQ_COUNT] = {NULL};
+static unsigned long irq_total = 0;
+static unsigned long irq_counts[AST_IRQ_COUNT] = {0};
+
+int request_irq(int irq, interrupt_handler_t *handler)
+{
+	if (irq < AST_IRQ_START_L || irq > AST_IRQ_END_H) {
+		printf("irq %d out of range\n", irq);
+		return -1;
+	}
+	if (handlers[irq]) {
+		printf("irq %d already in use (%p)\n", irq, handlers[irq]);
+		return -1;
+	}
+	handlers[irq] = handler;
+	if (irq < AST_IRQ_START_H) {
+		writel((1 << irq), AST_VIC_BASE + VIC_ENABLE_L);
+	} else {
+		writel((1 << (irq - AST_IRQ_START_H)),
+		       AST_VIC_BASE + VIC_ENABLE_H);
+	}
+	return 0;
+}
+
+int release_irq(int irq)
+{
+	if (irq < AST_IRQ_START_L || irq > AST_IRQ_END_H) {
+		return -1;
+	}
+	if (handlers[irq]) {
+		handlers[irq] = NULL;
+		if (irq < AST_IRQ_START_H) {
+			writel((1 << irq), AST_VIC_BASE + VIC_ENABLE_CLEAR_L);
+		} else {
+			writel((1 << (irq - AST_IRQ_START_H)),
+			       AST_VIC_BASE + VIC_ENABLE_CLEAR_H);
+		}
+	}
+	return 0;
+}
+
+extern int global_interrupts_enabled(void);
+int do_irqinfo(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
+{
+	int i;
+	int enabled = global_interrupts_enabled();
+	unsigned long long irqs_enabled =
+		((unsigned long long)readl(AST_VIC_BASE + VIC_ENABLE_H))
+			<< AST_IRQ_START_H
+		| readl(AST_VIC_BASE + VIC_ENABLE_L);
+	printf("interrupts %sabled\n", (enabled ? "en" : "dis"));
+	for (i = AST_IRQ_START_L; i < AST_IRQ_COUNT; i++) {
+		printf("% 2i (% 3s): %lu\n", i,
+		       ((irqs_enabled & 1) ? "on" : "off"), irq_counts[i]);
+		irqs_enabled >>= 1;
+	}
+	printf("total: %lu\n", irq_total);
+	return 0;
+}
+
+void do_irq(struct pt_regs *pt_regs)
+{
+	uint32_t irq = readl(AST_VIC_BASE + VIC_STATUS_L);
+	int i;
+	irq_total++;
+	if (irq) {
+		// handler irq0-31
+		for (i = AST_IRQ_START_L; i <= AST_IRQ_END_L; i++) {
+			if (irq & (1 << i)) {
+				irq_counts[i]++;
+				/* mask */
+				writel((1 << i),
+				       AST_VIC_BASE + VIC_ENABLE_CLEAR_L);
+				if (handlers[i]) {
+					handlers[i](pt_regs);
+					/* clear */
+					writel((1 << i),
+					       AST_VIC_BASE
+						       + VIC_INTERRUPT_CLEAR_L);
+					/* unmask */
+					writel((1 << i),
+					       AST_VIC_BASE + VIC_ENABLE_L);
+				} else {
+					printf("unexpected interrupt %i; masking\n",
+					       i);
+					/* clear; do not unmask */
+					writel((1 << i),
+					       AST_VIC_BASE
+						       + VIC_INTERRUPT_CLEAR_L);
+				}
+			}
+		}
+	}
+	irq = readl(AST_VIC_BASE + VIC_STATUS_H);
+	if (irq) {
+		// handler irq32-63
+		for (i = AST_IRQ_START_H; i <= AST_IRQ_END_H; i++) {
+			if (irq & (1 << (i - AST_IRQ_START_H))) {
+				irq_counts[i]++;
+				/* mask */
+				writel((1 << (i - AST_IRQ_START_H)),
+				       AST_VIC_BASE + VIC_ENABLE_CLEAR_H);
+				if (handlers[i]) {
+					handlers[i](pt_regs);
+					/* clear */
+					writel((1 << (i - AST_IRQ_START_H)),
+					       AST_VIC_BASE
+						       + VIC_INTERRUPT_CLEAR_H);
+					/* unmask */
+					writel((1 << (i - AST_IRQ_START_H)),
+					       AST_VIC_BASE + VIC_ENABLE_H);
+				} else {
+					printf("unexpected interrupt %i; masking\n",
+					       i);
+					/* clear; do not unmask */
+					writel((1 << (i - AST_IRQ_START_H)),
+					       AST_VIC_BASE
+						       + VIC_INTERRUPT_CLEAR_H);
+				}
+			}
+		}
+	}
+}
+#endif
diff --git a/board/aspeed/ast-g5/ast-g5-irq.h b/board/aspeed/ast-g5/ast-g5-irq.h
new file mode 100644
index 0000000..703eeab
--- /dev/null
+++ b/board/aspeed/ast-g5/ast-g5-irq.h
@@ -0,0 +1,39 @@
+/*
+ * Copyright 2018 Intel Corporation
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version
+ * 2 of the License, or (at your option) any later version.
+ */
+
+#ifndef __AST_G5_IRQ_H__
+#define __AST_G5_IRQ_H__
+
+#include <common.h>
+
+#ifdef CONFIG_USE_IRQ
+
+int arch_interrupt_init_early(void);
+
+int request_irq(int irq, interrupt_handler_t *handler);
+
+int release_irq(int irq);
+
+#else /* CONFIG_USE_IRQ */
+
+int arch_interrupt_init_early(void) {
+	return 0;
+}
+
+int request_irq(int irq, interrupt_handler_t *handler) {
+	return -1;
+}
+
+int release_irq(int irq) {
+	return -1;
+}
+
+#endif /* CONFIG_USE_IRQ */
+
+#endif /* __AST_G5_IRQ_H__ */
diff --git a/board/aspeed/ast-g5/ast-g5.c b/board/aspeed/ast-g5/ast-g5.c
index b492003..2472aa3 100644
--- a/board/aspeed/ast-g5/ast-g5.c
+++ b/board/aspeed/ast-g5/ast-g5.c
@@ -14,6 +14,8 @@
 #include <asm/arch/ast-sdmc.h>
 #include <asm/io.h>
 
+#include "ast-g5.h"
+
 DECLARE_GLOBAL_DATA_PTR;
 
 int board_early_init_f(void)
@@ -22,6 +24,7 @@ int board_early_init_f(void)
 	ast_config_uart5_clk();
 	/*enable pass through*/
 	ast_enable_pass_through();
+	arch_interrupt_init_early();
 
 	return 0;
 }
diff --git a/board/aspeed/ast-g5/ast-g5.h b/board/aspeed/ast-g5/ast-g5.h
new file mode 100644
index 0000000..9fd10ec
--- /dev/null
+++ b/board/aspeed/ast-g5/ast-g5.h
@@ -0,0 +1,7 @@
+#ifndef _AST_G5_H_
+#define _AST_G5_H_
+
+#include <common.h>
+#include "ast-g5-irq.h"
+
+#endif /* _AST_G5_H_ */
diff --git a/cmd/Kconfig b/cmd/Kconfig
index d69b817..33be240 100644
--- a/cmd/Kconfig
+++ b/cmd/Kconfig
@@ -313,6 +313,11 @@ endmenu
 
 menu "Device access commands"
 
+config CMD_IRQ
+	bool "interrupts - enable/disable interrupts"
+	depends on USE_IRQ
+	default y
+
 config CMD_DM
 	bool "dm - Access to driver model information"
 	depends on DM
diff --git a/configs/ast_g5_ncsi_2boot_defconfig b/configs/ast_g5_ncsi_2boot_defconfig
index 2d28c86..d5b7894 100644
--- a/configs/ast_g5_ncsi_2boot_defconfig
+++ b/configs/ast_g5_ncsi_2boot_defconfig
@@ -33,3 +33,4 @@ CONFIG_CMD_CRC32=y
 CONFIG_LOOPW=y
 CONFIG_CMD_MEMTEST=y
 CONFIG_CMD_MX_CYCLIC=y
+CONFIG_USE_IRQ=y
diff --git a/configs/ast_g5_ncsi_defconfig b/configs/ast_g5_ncsi_defconfig
index 74029ed..9481e5f 100644
--- a/configs/ast_g5_ncsi_defconfig
+++ b/configs/ast_g5_ncsi_defconfig
@@ -11,3 +11,4 @@ CONFIG_HUSH_PARSER=y
 CONFIG_OF_LIBFDT=y
 CONFIG_SPI_FLASH=y
 CONFIG_SYS_NS16550=y
+CONFIG_USE_IRQ=y
diff --git a/configs/ast_g5_phy_defconfig b/configs/ast_g5_phy_defconfig
index 767f3af..4aefcf4 100644
--- a/configs/ast_g5_phy_defconfig
+++ b/configs/ast_g5_phy_defconfig
@@ -12,3 +12,4 @@ CONFIG_HUSH_PARSER=y
 CONFIG_OF_LIBFDT=y
 CONFIG_SPI_FLASH=y
 CONFIG_SYS_NS16550=y
+CONFIG_USE_IRQ=y