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

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since c882505 was c882505, checked in by Beniamino Galvani <b.galvani@…>, 12 years ago

Merge arm926 and bcm2835 drivers for pl011 uart and move the code
under a generic directory

  • Property mode set to 100644
File size: 5.6 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 <genarch/drivers/pl011/pl011.h>
39#include <genarch/drivers/bcm2835/irc.h>
40#include <genarch/drivers/bcm2835/timer.h>
41#include <arch/mm/page.h>
42#include <mm/page.h>
43#include <mm/km.h>
44#include <genarch/fb/fb.h>
45#include <abi/fb/visuals.h>
46#include <genarch/srln/srln.h>
47#include <sysinfo/sysinfo.h>
48#include <interrupt.h>
49#include <ddi/ddi.h>
50#include <ddi/device.h>
51
52#define RPI_MEMORY_START 0
53/*
54 * TODO: size of available memory depends on hw model and
55 * bootloader configuration, we should detect it somehow.
56 * 128MB should be a safe value for now.
57 * */
58#define RPI_MEMORY_SIZE 0x08000000
59#define RPI_MEMORY_SKIP 0x8000
60
61static void raspberrypi_init(void);
62static void raspberrypi_timer_irq_start(void);
63static void raspberrypi_cpu_halt(void);
64static void raspberrypi_get_memory_extents(uintptr_t *start, size_t *size);
65static void raspberrypi_irq_exception(unsigned int exc_no, istate_t *istate);
66static void raspberrypi_frame_init(void);
67static void raspberrypi_output_init(void);
68static void raspberrypi_input_init(void);
69static size_t raspberrypi_get_irq_count(void);
70static const char *raspberrypi_get_platform_name(void);
71
72static struct {
73 pl011_uart_t uart;
74 bcm2835_irc_t *irc;
75 bcm2835_timer_t *timer;
76} raspi;
77
78struct arm_machine_ops raspberrypi_machine_ops = {
79 raspberrypi_init,
80 raspberrypi_timer_irq_start,
81 raspberrypi_cpu_halt,
82 raspberrypi_get_memory_extents,
83 raspberrypi_irq_exception,
84 raspberrypi_frame_init,
85 raspberrypi_output_init,
86 raspberrypi_input_init,
87 raspberrypi_get_irq_count,
88 raspberrypi_get_platform_name
89};
90
91static irq_ownership_t raspberrypi_timer_irq_claim(irq_t *irq)
92{
93 return IRQ_ACCEPT;
94}
95
96static void raspberrypi_timer_irq_handler(irq_t *irq)
97{
98 bcm2835_timer_irq_ack(raspi.timer);
99 spinlock_unlock(&irq->lock);
100 clock();
101 spinlock_lock(&irq->lock);
102}
103
104static void raspberrypi_init(void)
105{
106 /* Initialize interrupt controller */
107 raspi.irc = (void *) km_map(BCM2835_IRC_ADDR, sizeof(bcm2835_irc_t),
108 PAGE_NOT_CACHEABLE);
109 ASSERT(raspi.irc);
110 bcm2835_irc_init(raspi.irc);
111
112 /* Initialize system timer */
113 raspi.timer = (void *) km_map(BCM2835_TIMER_ADDR,
114 sizeof(bcm2835_timer_t),
115 PAGE_NOT_CACHEABLE);
116}
117
118static void raspberrypi_timer_irq_start(void)
119{
120 /* Initialize timer IRQ */
121 static irq_t timer_irq;
122 irq_initialize(&timer_irq);
123 timer_irq.devno = device_assign_devno();
124 timer_irq.inr = BCM2835_TIMER1_IRQ;
125 timer_irq.claim = raspberrypi_timer_irq_claim;
126 timer_irq.handler = raspberrypi_timer_irq_handler;
127 irq_register(&timer_irq);
128
129 bcm2835_irc_enable(raspi.irc, BCM2835_TIMER1_IRQ);
130 bcm2835_timer_start(raspi.timer);
131}
132
133static void raspberrypi_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 raspberrypi_get_memory_extents(uintptr_t *start, size_t *size)
144{
145 *start = RPI_MEMORY_START + RPI_MEMORY_SKIP;
146 *size = RPI_MEMORY_SIZE - RPI_MEMORY_SKIP;
147}
148
149static void raspberrypi_irq_exception(unsigned int exc_no, istate_t *istate)
150{
151 const unsigned inum = bcm2835_irc_inum_get(raspi.irc);
152
153 irq_t *irq = irq_dispatch_and_lock(inum);
154 if (irq) {
155 /* The IRQ handler was found. */
156 irq->handler(irq);
157 spinlock_unlock(&irq->lock);
158 } else {
159 /* Spurious interrupt.*/
160 printf("cpu%d: spurious interrupt (inum=%d)\n", CPU->id, inum);
161 bcm2835_irc_disable(raspi.irc, inum);
162 }
163}
164
165static void raspberrypi_frame_init(void)
166{
167}
168
169static void raspberrypi_output_init(void)
170{
171#ifdef CONFIG_PL011_UART
172 if (pl011_uart_init(&raspi.uart, BCM2835_UART_IRQ,
173 BCM2835_UART0_BASE_ADDRESS))
174 stdout_wire(&raspi.uart.outdev);
175#endif
176}
177
178static void raspberrypi_input_init(void)
179{
180 srln_instance_t *srln_instance = srln_init();
181 if (srln_instance) {
182 indev_t *sink = stdin_wire();
183 indev_t *srln = srln_wire(srln_instance, sink);
184
185 pl011_uart_input_wire(&raspi.uart, srln);
186 bcm2835_irc_enable(raspi.irc, BCM2835_UART_IRQ);
187 }
188}
189
190size_t raspberrypi_get_irq_count(void)
191{
192 return BCM2835_IRQ_COUNT;
193}
194
195const char *raspberrypi_get_platform_name(void)
196{
197 return "raspberrypi";
198}
199
200/** @}
201 */
Note: See TracBrowser for help on using the repository browser.