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

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since e8975278 was ae7d03c, checked in by Jiri Svoboda <jiri@…>, 7 years ago

Selected ccheck-proposed comment fixes.

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