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

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

beagleboardxm: Allow gpt1 interrupt. Ack timer interrupt on the handler.

  • Property mode set to 100644
File size: 5.8 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_irc/amdm37x_irc.h>
38#include <genarch/drivers/amdm37x_uart/amdm37x_uart.h>
39#include <genarch/drivers/amdm37x_gpt/amdm37x_gpt.h>
40#include <genarch/srln/srln.h>
41#include <interrupt.h>
42#include <mm/km.h>
43#include <ddi/ddi.h>
44#include <ddi/device.h>
45
46static void bbxm_init(void);
47static void bbxm_timer_irq_start(void);
48static void bbxm_cpu_halt(void);
49static void bbxm_get_memory_extents(uintptr_t *start, size_t *size);
50static void bbxm_irq_exception(unsigned int exc_no, istate_t *istate);
51static void bbxm_frame_init(void);
52static void bbxm_output_init(void);
53static void bbxm_input_init(void);
54static size_t bbxm_get_irq_count(void);
55static const char *bbxm_get_platform_name(void);
56
57#define BBXM_MEMORY_START 0x80000000 /* physical */
58#define BBXM_MEMORY_SIZE 0x20000000 /* 512 MB */
59
60static struct beagleboard {
61 amdm37x_irc_regs_t *irc_addr;
62 amdm37x_uart_t uart;
63 amdm37x_gpt_t timer;
64} beagleboard;
65
66struct arm_machine_ops bbxm_machine_ops = {
67 .machine_init = bbxm_init,
68 .machine_timer_irq_start = bbxm_timer_irq_start,
69 .machine_cpu_halt = bbxm_cpu_halt,
70 .machine_get_memory_extents = bbxm_get_memory_extents,
71 .machine_irq_exception = bbxm_irq_exception,
72 .machine_frame_init = bbxm_frame_init,
73 .machine_output_init = bbxm_output_init,
74 .machine_input_init = bbxm_input_init,
75 .machine_get_irq_count = bbxm_get_irq_count,
76 .machine_get_platform_name = bbxm_get_platform_name
77};
78
79static irq_ownership_t bb_timer_irq_claim(irq_t *irq)
80{
81 return IRQ_ACCEPT;
82}
83
84static void bb_timer_irq_handler(irq_t *irq)
85{
86 /*
87 * We are holding a lock which prevents preemption.
88 * Release the lock, call clock() and reacquire the lock again.
89 */
90 amdm37x_gpt_irq_ack(&beagleboard.timer);
91 spinlock_unlock(&irq->lock);
92 clock();
93 spinlock_lock(&irq->lock);
94}
95
96static void bbxm_init(void)
97{
98 /* Initialize interrupt controller */
99 beagleboard.irc_addr =
100 (void *) km_map(AMDM37x_IRC_BASE_ADDRESS, AMDM37x_IRC_SIZE,
101 PAGE_NOT_CACHEABLE);
102 amdm37x_irc_init(beagleboard.irc_addr);
103
104
105 /* Initialize timer, pick timer1, because it is in always-power domain
106 * and has special capabilities for regular ticks */
107 amdm37x_gpt_timer_ticks_init(&beagleboard.timer,
108 AMDM37x_GPT1_BASE_ADDRESS, AMDM37x_GPT1_SIZE, HZ);
109}
110
111static void bbxm_timer_irq_start(void)
112{
113 /* Initialize timer IRQ */
114 static irq_t timer_irq;
115 irq_initialize(&timer_irq);
116 timer_irq.devno = device_assign_devno();
117 timer_irq.inr = AMDM37x_GPT1_IRQ;
118 timer_irq.claim = bb_timer_irq_claim;
119 timer_irq.handler = bb_timer_irq_handler;
120 irq_register(&timer_irq);
121
122 /* Enable timer interrupt */
123 amdm37x_irc_enable(beagleboard.irc_addr, AMDM37x_GPT1_IRQ);
124
125 /* Start timer here */
126 amdm37x_gpt_timer_ticks_start(&beagleboard.timer);
127}
128
129static void bbxm_cpu_halt(void)
130{
131 while (1);
132}
133
134/** Get extents of available memory.
135 *
136 * @param start Place to store memory start address (physical).
137 * @param size Place to store memory size.
138 */
139static void bbxm_get_memory_extents(uintptr_t *start, size_t *size)
140{
141 *start = BBXM_MEMORY_START;
142 *size = BBXM_MEMORY_SIZE;
143}
144
145static void bbxm_irq_exception(unsigned int exc_no, istate_t *istate)
146{
147 const unsigned inum = amdm37x_irc_inum_get(beagleboard.irc_addr);
148 amdm37x_irc_irq_ack(beagleboard.irc_addr);
149
150 irq_t *irq = irq_dispatch_and_lock(inum);
151 if (irq) {
152 /* The IRQ handler was found. */
153 irq->handler(irq);
154 spinlock_unlock(&irq->lock);
155 } else {
156 /* Spurious interrupt.*/
157 printf("cpu%d: spurious interrupt (inum=%d)\n",
158 CPU->id, inum);
159 }
160}
161
162static void bbxm_frame_init(void)
163{
164}
165
166static void bbxm_output_init(void)
167{
168#ifdef CONFIG_FB
169#error "Frame buffer is not yet supported!"
170#endif
171 /* UART3 is wired to external RS232 connector */
172 const bool ok = amdm37x_uart_init(&beagleboard.uart,
173 AMDM37x_UART3_IRQ, AMDM37x_UART3_BASE_ADDRESS, AMDM37x_UART3_SIZE);
174 if (ok) {
175 stdout_wire(&beagleboard.uart.outdev);
176 }
177}
178
179static void bbxm_input_init(void)
180{
181 srln_instance_t *srln_instance = srln_init();
182 if (srln_instance) {
183 indev_t *sink = stdin_wire();
184 indev_t *srln = srln_wire(srln_instance, sink);
185 amdm37x_uart_input_wire(&beagleboard.uart, srln);
186 }
187}
188
189size_t bbxm_get_irq_count(void)
190{
191 return AMDM37x_IRC_IRQ_COUNT;
192}
193
194const char *bbxm_get_platform_name(void)
195{
196 return "beagleboardxm";
197}
198
199/**
200 * @}
201 */
Note: See TracBrowser for help on using the repository browser.