source: mainline/kernel/arch/arm32/src/mach/beaglebone/beaglebone.c@ 94d211e

Last change on this file since 94d211e was 94d211e, checked in by Jiří Zárevúcky <zarevucky.jiri@…>, 7 years ago

Change the way page flags work. TODO description

  • Property mode set to 100644
File size: 6.8 KB
Line 
1/*
2 * Copyright (c) 2012 Matteo Facchinetti
3 * Copyright (c) 2012 Maurizio Lombardi
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 *
10 * - Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * - Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * - The name of the author may not be used to endorse or promote products
16 * derived from this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 */
29/** @addtogroup arm32beaglebone
30 * @{
31 */
32/** @file
33 * @brief BeagleBone platform driver.
34 */
35
36#include <arch/exception.h>
37#include <arch/mach/beaglebone/beaglebone.h>
38#include <assert.h>
39#include <genarch/drivers/am335x/irc.h>
40#include <genarch/drivers/am335x/uart.h>
41#include <genarch/drivers/am335x/timer.h>
42#include <genarch/drivers/am335x/cm_per.h>
43#include <genarch/drivers/am335x/cm_dpll.h>
44#include <genarch/drivers/am335x/ctrl_module.h>
45#include <genarch/srln/srln.h>
46#include <interrupt.h>
47#include <ddi/ddi.h>
48#include <mm/km.h>
49
50#define BBONE_MEMORY_START 0x80000000 /* physical */
51#define BBONE_MEMORY_SIZE 0x10000000 /* 256 MB */
52
53static void bbone_init(void);
54static void bbone_timer_irq_start(void);
55static void bbone_cpu_halt(void);
56static void bbone_get_memory_extents(uintptr_t *start, size_t *size);
57static void bbone_irq_exception(unsigned int exc_no, istate_t *istate);
58static void bbone_frame_init(void);
59static void bbone_output_init(void);
60static void bbone_input_init(void);
61static size_t bbone_get_irq_count(void);
62static const char *bbone_get_platform_name(void);
63
64static struct beaglebone {
65 omap_irc_regs_t *irc_addr;
66 am335x_cm_per_regs_t *cm_per_addr;
67 am335x_cm_dpll_regs_t *cm_dpll_addr;
68 am335x_ctrl_module_t *ctrl_module;
69 am335x_timer_t timer;
70 omap_uart_t uart;
71} bbone;
72
73struct arm_machine_ops bbone_machine_ops = {
74 .machine_init = bbone_init,
75 .machine_timer_irq_start = bbone_timer_irq_start,
76 .machine_cpu_halt = bbone_cpu_halt,
77 .machine_get_memory_extents = bbone_get_memory_extents,
78 .machine_irq_exception = bbone_irq_exception,
79 .machine_frame_init = bbone_frame_init,
80 .machine_output_init = bbone_output_init,
81 .machine_input_init = bbone_input_init,
82 .machine_get_irq_count = bbone_get_irq_count,
83 .machine_get_platform_name = bbone_get_platform_name,
84};
85
86static void bbone_init(void)
87{
88 bbone.irc_addr = (void *) km_map(AM335x_IRC_BASE_ADDRESS,
89 AM335x_IRC_SIZE,
90 PAGE_READ_WRITE | PAGE_KERNEL | PAGE_NOT_CACHEABLE);
91
92 bbone.cm_per_addr = (void *) km_map(AM335x_CM_PER_BASE_ADDRESS,
93 AM335x_CM_PER_SIZE,
94 PAGE_READ_WRITE | PAGE_KERNEL | PAGE_NOT_CACHEABLE);
95
96 bbone.cm_dpll_addr = (void *) km_map(AM335x_CM_DPLL_BASE_ADDRESS,
97 AM335x_CM_DPLL_SIZE,
98 PAGE_READ_WRITE | PAGE_KERNEL | PAGE_NOT_CACHEABLE);
99
100 bbone.ctrl_module = (void *) km_map(AM335x_CTRL_MODULE_BASE_ADDRESS,
101 AM335x_CTRL_MODULE_SIZE,
102 PAGE_READ_WRITE | PAGE_KERNEL | PAGE_NOT_CACHEABLE);
103
104 assert(bbone.irc_addr != NULL);
105 assert(bbone.cm_per_addr != NULL);
106 assert(bbone.cm_dpll_addr != NULL);
107 assert(bbone.ctrl_module != NULL);
108
109 /* Initialize the interrupt controller */
110 omap_irc_init(bbone.irc_addr);
111}
112
113static irq_ownership_t bbone_timer_irq_claim(irq_t *irq)
114{
115 return IRQ_ACCEPT;
116}
117
118static void bbone_timer_irq_handler(irq_t *irq)
119{
120 am335x_timer_intr_ack(&bbone.timer);
121 spinlock_unlock(&irq->lock);
122 clock();
123 spinlock_lock(&irq->lock);
124}
125
126static void bbone_timer_irq_start(void)
127{
128 unsigned sysclk_freq;
129 errno_t rc;
130
131 /* Initialize the IRQ */
132 static irq_t timer_irq;
133 irq_initialize(&timer_irq);
134 timer_irq.inr = AM335x_DMTIMER2_IRQ;
135 timer_irq.claim = bbone_timer_irq_claim;
136 timer_irq.handler = bbone_timer_irq_handler;
137 irq_register(&timer_irq);
138
139 /* Enable the DMTIMER2 clock module */
140 am335x_clock_module_enable(bbone.cm_per_addr, DMTIMER2);
141 /* Select the SYSCLK as the clock source for the dmtimer2 module */
142 am335x_clock_source_select(bbone.cm_dpll_addr, DMTIMER2,
143 CLK_SRC_M_OSC);
144 /* Initialize the DMTIMER2 */
145 if (am335x_ctrl_module_clock_freq_get(bbone.ctrl_module,
146 &sysclk_freq) != EOK) {
147 printf("Cannot get the system clock frequency!\n");
148 return;
149 } else
150 printf("system clock running at %u hz\n", sysclk_freq);
151
152 rc = am335x_timer_init(&bbone.timer, DMTIMER2, HZ, sysclk_freq);
153 if (rc != EOK) {
154 printf("Timer initialization failed\n");
155 return;
156 }
157 /* Enable the interrupt */
158 omap_irc_enable(bbone.irc_addr, AM335x_DMTIMER2_IRQ);
159 /* Start the timer */
160 am335x_timer_start(&bbone.timer);
161}
162
163static void bbone_cpu_halt(void)
164{
165 while (1);
166}
167
168/** Get extents of available memory.
169 *
170 * @param start Place to store memory start address (physical).
171 * @param size Place to store memory size.
172 */
173static void bbone_get_memory_extents(uintptr_t *start, size_t *size)
174{
175 *start = BBONE_MEMORY_START;
176 *size = BBONE_MEMORY_SIZE;
177}
178
179static void bbone_irq_exception(unsigned int exc_no, istate_t *istate)
180{
181 const unsigned inum = omap_irc_inum_get(bbone.irc_addr);
182
183 irq_t *irq = irq_dispatch_and_lock(inum);
184 if (irq) {
185 /* The IRQ handler was found. */
186 irq->handler(irq);
187 spinlock_unlock(&irq->lock);
188 } else {
189 printf("Spurious interrupt\n");
190 }
191
192 omap_irc_irq_ack(bbone.irc_addr);
193}
194
195static void bbone_frame_init(void)
196{
197}
198
199static void bbone_output_init(void)
200{
201#ifdef CONFIG_OMAP_UART
202 const bool ok = omap_uart_init(&bbone.uart,
203 AM335x_UART0_IRQ, AM335x_UART0_BASE_ADDRESS,
204 AM335x_UART0_SIZE);
205
206 if (ok)
207 stdout_wire(&bbone.uart.outdev);
208#endif
209}
210
211static void bbone_input_init(void)
212{
213#ifdef CONFIG_OMAP_UART
214 srln_instance_t *srln_instance = srln_init();
215 if (srln_instance) {
216 indev_t *sink = stdin_wire();
217 indev_t *srln = srln_wire(srln_instance, sink);
218 omap_uart_input_wire(&bbone.uart, srln);
219 omap_irc_enable(bbone.irc_addr, AM335x_UART0_IRQ);
220 }
221#endif
222}
223
224size_t bbone_get_irq_count(void)
225{
226 return AM335x_IRC_IRQ_COUNT;
227}
228
229const char *bbone_get_platform_name(void)
230{
231 return "beaglebone";
232}
233
234/**
235 * @}
236 */
237
Note: See TracBrowser for help on using the repository browser.