source: mainline/kernel/arch/arm32/src/mach/beagleboardxm/beagleboardxm.c@ 59a72f8

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 59a72f8 was 59a72f8, checked in by Jan Vesely <jano.vesely@…>, 12 years ago

arm32, bbxm: Ingore ghost interrupt

  • Property mode set to 100644
File size: 6.0 KB
Line 
1/*
2 * Copyright (c) 2012 Jan Vesely
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * - Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * - Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * - The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28/** @addtogroup arm32beagleboardxm
29 * @{
30 */
31/** @file
32 * @brief BeagleBoard-xM platform driver.
33 */
34
35#include <arch/exception.h>
36#include <arch/mach/beagleboardxm/beagleboardxm.h>
37#include <genarch/drivers/amdm37x/uart.h>
38#include <genarch/drivers/amdm37x/irc.h>
39#include <genarch/drivers/amdm37x/gpt.h>
40#include <genarch/fb/fb.h>
41#include <genarch/srln/srln.h>
42#include <interrupt.h>
43#include <mm/km.h>
44#include <ddi/ddi.h>
45#include <ddi/device.h>
46
47static void bbxm_init(void);
48static void bbxm_timer_irq_start(void);
49static void bbxm_cpu_halt(void);
50static void bbxm_get_memory_extents(uintptr_t *start, size_t *size);
51static void bbxm_irq_exception(unsigned int exc_no, istate_t *istate);
52static void bbxm_frame_init(void);
53static void bbxm_output_init(void);
54static void bbxm_input_init(void);
55static size_t bbxm_get_irq_count(void);
56static const char *bbxm_get_platform_name(void);
57
58#define BBXM_MEMORY_START 0x80000000 /* physical */
59#define BBXM_MEMORY_SIZE 0x20000000 /* 512 MB */
60
61static struct beagleboard {
62 amdm37x_irc_regs_t *irc_addr;
63 omap_uart_t uart;
64 amdm37x_gpt_t timer;
65} beagleboard;
66
67struct arm_machine_ops bbxm_machine_ops = {
68 .machine_init = bbxm_init,
69 .machine_timer_irq_start = bbxm_timer_irq_start,
70 .machine_cpu_halt = bbxm_cpu_halt,
71 .machine_get_memory_extents = bbxm_get_memory_extents,
72 .machine_irq_exception = bbxm_irq_exception,
73 .machine_frame_init = bbxm_frame_init,
74 .machine_output_init = bbxm_output_init,
75 .machine_input_init = bbxm_input_init,
76 .machine_get_irq_count = bbxm_get_irq_count,
77 .machine_get_platform_name = bbxm_get_platform_name
78};
79
80static irq_ownership_t bb_timer_irq_claim(irq_t *irq)
81{
82 return IRQ_ACCEPT;
83}
84
85static void bb_timer_irq_handler(irq_t *irq)
86{
87 // FIXME Ignore the weird ghost interrupt
88 if (!amdm37x_gpt_irq_ack(&beagleboard.timer))
89 return;
90
91 /*
92 * We are holding a lock which prevents preemption.
93 * Release the lock, call clock() and reacquire the lock again.
94 */
95 spinlock_unlock(&irq->lock);
96 clock();
97 spinlock_lock(&irq->lock);
98}
99
100static void bbxm_init(void)
101{
102 /* Initialize interrupt controller */
103 beagleboard.irc_addr =
104 (void *) km_map(AMDM37x_IRC_BASE_ADDRESS, AMDM37x_IRC_SIZE,
105 PAGE_NOT_CACHEABLE);
106 ASSERT(beagleboard.irc_addr);
107 amdm37x_irc_init(beagleboard.irc_addr);
108
109 /* Initialize timer. Use timer1, because it is in WKUP power domain
110 * (always on) and has special capabilities for precise 1ms ticks */
111 amdm37x_gpt_timer_ticks_init(&beagleboard.timer,
112 AMDM37x_GPT1_BASE_ADDRESS, AMDM37x_GPT1_SIZE, HZ);
113}
114
115static void bbxm_timer_irq_start(void)
116{
117 /* Initialize timer IRQ */
118 static irq_t timer_irq;
119 irq_initialize(&timer_irq);
120 timer_irq.devno = device_assign_devno();
121 timer_irq.inr = AMDM37x_GPT1_IRQ;
122 timer_irq.claim = bb_timer_irq_claim;
123 timer_irq.handler = bb_timer_irq_handler;
124 irq_register(&timer_irq);
125
126 /* Enable timer interrupt */
127 amdm37x_irc_enable(beagleboard.irc_addr, AMDM37x_GPT1_IRQ);
128
129 /* Start timer here */
130 amdm37x_gpt_timer_ticks_start(&beagleboard.timer);
131}
132
133static void bbxm_cpu_halt(void)
134{
135 while (1);
136}
137
138/** Get extents of available memory.
139 *
140 * @param start Place to store memory start address (physical).
141 * @param size Place to store memory size.
142 */
143static void bbxm_get_memory_extents(uintptr_t *start, size_t *size)
144{
145 *start = BBXM_MEMORY_START;
146 *size = BBXM_MEMORY_SIZE;
147}
148
149static void bbxm_irq_exception(unsigned int exc_no, istate_t *istate)
150{
151 const unsigned inum = amdm37x_irc_inum_get(beagleboard.irc_addr);
152 amdm37x_irc_irq_ack(beagleboard.irc_addr);
153
154 irq_t *irq = irq_dispatch_and_lock(inum);
155 if (irq) {
156 /* The IRQ handler was found. */
157 irq->handler(irq);
158 spinlock_unlock(&irq->lock);
159 } else {
160 /* Spurious interrupt.*/
161 printf("cpu%d: spurious interrupt (inum=%d)\n",
162 CPU->id, inum);
163 }
164}
165
166static void bbxm_frame_init(void)
167{
168}
169
170static void bbxm_output_init(void)
171{
172#ifdef CONFIG_OMAP_UART
173 /* UART3 is wired to external RS232 connector */
174 const bool ok = omap_uart_init(&beagleboard.uart,
175 AMDM37x_UART3_IRQ, AMDM37x_UART3_BASE_ADDRESS, AMDM37x_UART3_SIZE);
176 if (ok) {
177 stdout_wire(&beagleboard.uart.outdev);
178 }
179#endif
180}
181
182static void bbxm_input_init(void)
183{
184#ifdef CONFIG_OMAP_UART
185 srln_instance_t *srln_instance = srln_init();
186 if (srln_instance) {
187 indev_t *sink = stdin_wire();
188 indev_t *srln = srln_wire(srln_instance, sink);
189 omap_uart_input_wire(&beagleboard.uart, srln);
190 amdm37x_irc_enable(beagleboard.irc_addr, AMDM37x_UART3_IRQ);
191 }
192#endif
193}
194
195size_t bbxm_get_irq_count(void)
196{
197 return AMDM37x_IRC_IRQ_COUNT;
198}
199
200const char *bbxm_get_platform_name(void)
201{
202 return "beagleboardxm";
203}
204
205/**
206 * @}
207 */
Note: See TracBrowser for help on using the repository browser.