source: mainline/kernel/arch/arm32/src/mach/raspberrypi/raspberrypi.c@ 24abb85d

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 24abb85d was 24abb85d, checked in by Jakub Jermar <jakub@…>, 8 years ago

Remove SYS_DEVICE_ASSIGN_DEVNO

  • Property mode set to 100644
File size: 5.8 KB
Line 
1/*
2 * Copyright (c) 2013 Beniamino Galvani
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
29/** @addtogroup arm32raspberrypi
30 * @{
31 */
32/** @file
33 * @brief Raspberry PI platform driver.
34 */
35
36#include <arch/exception.h>
37#include <arch/mach/raspberrypi/raspberrypi.h>
38#include <assert.h>
39#include <genarch/drivers/pl011/pl011.h>
40#include <genarch/drivers/bcm2835/irc.h>
41#include <genarch/drivers/bcm2835/timer.h>
42#include <genarch/drivers/bcm2835/mbox.h>
43#include <arch/mm/page.h>
44#include <mm/page.h>
45#include <mm/km.h>
46#include <genarch/fb/fb.h>
47#include <abi/fb/visuals.h>
48#include <genarch/srln/srln.h>
49#include <sysinfo/sysinfo.h>
50#include <interrupt.h>
51#include <ddi/ddi.h>
52
53#define RPI_DEFAULT_MEMORY_START 0
54#define RPI_DEFAULT_MEMORY_SIZE 0x08000000
55#define RPI_MEMORY_SKIP 0x8000
56
57static void raspberrypi_init(void);
58static void raspberrypi_timer_irq_start(void);
59static void raspberrypi_cpu_halt(void);
60static void raspberrypi_get_memory_extents(uintptr_t *start, size_t *size);
61static void raspberrypi_irq_exception(unsigned int exc_no, istate_t *istate);
62static void raspberrypi_frame_init(void);
63static void raspberrypi_output_init(void);
64static void raspberrypi_input_init(void);
65static size_t raspberrypi_get_irq_count(void);
66static const char *raspberrypi_get_platform_name(void);
67
68static struct {
69 pl011_uart_t uart;
70 bcm2835_irc_t *irc;
71 bcm2835_timer_t *timer;
72} raspi;
73
74struct arm_machine_ops raspberrypi_machine_ops = {
75 raspberrypi_init,
76 raspberrypi_timer_irq_start,
77 raspberrypi_cpu_halt,
78 raspberrypi_get_memory_extents,
79 raspberrypi_irq_exception,
80 raspberrypi_frame_init,
81 raspberrypi_output_init,
82 raspberrypi_input_init,
83 raspberrypi_get_irq_count,
84 raspberrypi_get_platform_name
85};
86
87static irq_ownership_t raspberrypi_timer_irq_claim(irq_t *irq)
88{
89 return IRQ_ACCEPT;
90}
91
92static void raspberrypi_timer_irq_handler(irq_t *irq)
93{
94 bcm2835_timer_irq_ack(raspi.timer);
95 spinlock_unlock(&irq->lock);
96 clock();
97 spinlock_lock(&irq->lock);
98}
99
100static void raspberrypi_init(void)
101{
102 /* Initialize interrupt controller */
103 raspi.irc = (void *) km_map(BCM2835_IRC_ADDR, sizeof(bcm2835_irc_t),
104 PAGE_NOT_CACHEABLE);
105 assert(raspi.irc);
106 bcm2835_irc_init(raspi.irc);
107
108 /* Initialize system timer */
109 raspi.timer = (void *) km_map(BCM2835_TIMER_ADDR,
110 sizeof(bcm2835_timer_t),
111 PAGE_NOT_CACHEABLE);
112}
113
114static void raspberrypi_timer_irq_start(void)
115{
116 /* Initialize timer IRQ */
117 static irq_t timer_irq;
118 irq_initialize(&timer_irq);
119 timer_irq.inr = BCM2835_TIMER1_IRQ;
120 timer_irq.claim = raspberrypi_timer_irq_claim;
121 timer_irq.handler = raspberrypi_timer_irq_handler;
122 irq_register(&timer_irq);
123
124 bcm2835_irc_enable(raspi.irc, BCM2835_TIMER1_IRQ);
125 bcm2835_timer_start(raspi.timer);
126}
127
128static void raspberrypi_cpu_halt(void)
129{
130 while (1) ;
131}
132
133/** Get extents of available memory.
134 *
135 * @param start Place to store memory start address (physical).
136 * @param size Place to store memory size.
137 */
138static void raspberrypi_get_memory_extents(uintptr_t *start, size_t *size)
139{
140 uint32_t mbase, msize;
141
142 if (bcm2835_prop_get_memory(&mbase, &msize)) {
143 *start = mbase + RPI_MEMORY_SKIP;
144 *size = msize - RPI_MEMORY_SKIP;
145 } else {
146 /* Stick to safe default values */
147 *start = RPI_DEFAULT_MEMORY_START + RPI_MEMORY_SKIP;
148 *size = RPI_DEFAULT_MEMORY_SIZE - RPI_MEMORY_SKIP;
149 }
150}
151
152static void raspberrypi_irq_exception(unsigned int exc_no, istate_t *istate)
153{
154 const unsigned inum = bcm2835_irc_inum_get(raspi.irc);
155
156 irq_t *irq = irq_dispatch_and_lock(inum);
157 if (irq) {
158 /* The IRQ handler was found. */
159 irq->handler(irq);
160 spinlock_unlock(&irq->lock);
161 } else {
162 /* Spurious interrupt.*/
163 printf("cpu%d: spurious interrupt (inum=%d)\n", CPU->id, inum);
164 bcm2835_irc_disable(raspi.irc, inum);
165 }
166}
167
168static void raspberrypi_frame_init(void)
169{
170}
171
172static void raspberrypi_output_init(void)
173{
174#ifdef CONFIG_FB
175 fb_properties_t prop;
176 if (bcm2835_fb_init(&prop)) {
177 outdev_t *fb_dev = fb_init(&prop);
178 if (fb_dev)
179 stdout_wire(fb_dev);
180 }
181#endif
182
183#ifdef CONFIG_PL011_UART
184 if (pl011_uart_init(&raspi.uart, BCM2835_UART_IRQ,
185 BCM2835_UART0_BASE_ADDRESS))
186 stdout_wire(&raspi.uart.outdev);
187#endif
188}
189
190static void raspberrypi_input_init(void)
191{
192 srln_instance_t *srln_instance = srln_init();
193 if (srln_instance) {
194 indev_t *sink = stdin_wire();
195 indev_t *srln = srln_wire(srln_instance, sink);
196
197 pl011_uart_input_wire(&raspi.uart, srln);
198 bcm2835_irc_enable(raspi.irc, BCM2835_UART_IRQ);
199 }
200}
201
202size_t raspberrypi_get_irq_count(void)
203{
204 return BCM2835_IRQ_COUNT;
205}
206
207const char *raspberrypi_get_platform_name(void)
208{
209 return "raspberrypi";
210}
211
212/** @}
213 */
Note: See TracBrowser for help on using the repository browser.