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

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since f6c6814 was f6c6814, checked in by Maurizio Lombardi <m.lombardi85@…>, 12 years ago

beaglebone: remove duplicated timer initialization

  • Property mode set to 100644
File size: 5.4 KB
Line 
1/*
2 * Copyright (c) 2012 Matteo Facchinetti
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 arm32beaglebone
29 * @{
30 */
31/** @file
32 * @brief BeagleBone platform driver.
33 */
34
35#include <arch/exception.h>
36#include <arch/mach/beaglebone/beaglebone.h>
37#include <genarch/drivers/am335x/irc.h>
38#include <genarch/drivers/am335x/uart.h>
39#include <genarch/drivers/am335x/timer.h>
40#include <genarch/srln/srln.h>
41#include <interrupt.h>
42#include <ddi/ddi.h>
43#include <ddi/device.h>
44#include <mm/km.h>
45
46#define BBONE_MEMORY_START 0x80000000 /* physical */
47#define BBONE_MEMORY_SIZE 0x10000000 /* 256 MB */
48
49static void bbone_init(void);
50static void bbone_timer_irq_start(void);
51static void bbone_cpu_halt(void);
52static void bbone_get_memory_extents(uintptr_t *start, size_t *size);
53static void bbone_irq_exception(unsigned int exc_no, istate_t *istate);
54static void bbone_frame_init(void);
55static void bbone_output_init(void);
56static void bbone_input_init(void);
57static size_t bbone_get_irq_count(void);
58static const char *bbone_get_platform_name(void);
59
60static struct beaglebone {
61 am335x_irc_regs_t *irc_addr;
62 am335x_timer_t timer;
63 am335x_uart_t uart;
64} bbone;
65
66struct arm_machine_ops bbone_machine_ops = {
67 .machine_init = bbone_init,
68 .machine_timer_irq_start = bbone_timer_irq_start,
69 .machine_cpu_halt = bbone_cpu_halt,
70 .machine_get_memory_extents = bbone_get_memory_extents,
71 .machine_irq_exception = bbone_irq_exception,
72 .machine_frame_init = bbone_frame_init,
73 .machine_output_init = bbone_output_init,
74 .machine_input_init = bbone_input_init,
75 .machine_get_irq_count = bbone_get_irq_count,
76 .machine_get_platform_name = bbone_get_platform_name,
77};
78
79static void bbone_init(void)
80{
81 /* Initialize the interrupt controller */
82 bbone.irc_addr = (void *) km_map(AM335x_IRC_BASE_ADDRESS,
83 AM335x_IRC_SIZE, PAGE_NOT_CACHEABLE);
84
85 am335x_irc_init(bbone.irc_addr);
86}
87
88static irq_ownership_t bbone_timer_irq_claim(irq_t *irq)
89{
90 return IRQ_ACCEPT;
91}
92
93static void bbone_timer_irq_handler(irq_t *irq)
94{
95 am335x_timer_intr_ack(&bbone.timer);
96 spinlock_unlock(&irq->lock);
97 clock();
98 spinlock_lock(&irq->lock);
99}
100
101static void bbone_timer_irq_start(void)
102{
103 /* Initialize the IRQ */
104 static irq_t timer_irq;
105 irq_initialize(&timer_irq);
106 timer_irq.devno = device_assign_devno();
107 timer_irq.inr = AM335x_DMTIMER0_IRQ;
108 timer_irq.claim = bbone_timer_irq_claim;
109 timer_irq.handler = bbone_timer_irq_handler;
110 irq_register(&timer_irq);
111
112 /* Initialize the DMTIMER0 */
113 am335x_timer_init(&bbone.timer, DMTIMER0, HZ);
114 /* Enable the interrupt */
115 am335x_irc_enable(bbone.irc_addr, AM335x_DMTIMER0_IRQ);
116 /* Start the timer */
117 am335x_timer_start(&bbone.timer);
118}
119
120static void bbone_cpu_halt(void)
121{
122 while (1);
123}
124
125/** Get extents of available memory.
126 *
127 * @param start Place to store memory start address (physical).
128 * @param size Place to store memory size.
129 */
130static void bbone_get_memory_extents(uintptr_t *start, size_t *size)
131{
132 *start = BBONE_MEMORY_START;
133 *size = BBONE_MEMORY_SIZE;
134}
135
136static void bbone_irq_exception(unsigned int exc_no, istate_t *istate)
137{
138 const unsigned inum = am335x_irc_inum_get(bbone.irc_addr);
139 am335x_irc_irq_ack(bbone.irc_addr);
140
141 irq_t *irq = irq_dispatch_and_lock(inum);
142 if (irq) {
143 /* The IRQ handler was found. */
144 irq->handler(irq);
145 spinlock_unlock(&irq->lock);
146 } else {
147 printf("Spurious interrupt\n");
148 }
149}
150
151static void bbone_frame_init(void)
152{
153}
154
155static void bbone_output_init(void)
156{
157 const bool ok = am335x_uart_init(&bbone.uart,
158 AM335x_UART0_IRQ, AM335x_UART0_BASE_ADDRESS,
159 AM335x_UART0_SIZE);
160
161 if (ok) {
162 stdout_wire(&bbone.uart.outdev);
163 printf("UART Ok\n");
164 }
165}
166
167static void bbone_input_init(void)
168{
169 srln_instance_t *srln_instance = srln_init();
170 if (srln_instance) {
171 indev_t *sink = stdin_wire();
172 indev_t *srln = srln_wire(srln_instance, sink);
173 am335x_uart_input_wire(&bbone.uart, srln);
174 am335x_irc_enable(bbone.irc_addr, AM335x_UART0_IRQ);
175 }
176}
177
178size_t bbone_get_irq_count(void)
179{
180 return AM335x_IRC_IRQ_COUNT;
181}
182
183const char *bbone_get_platform_name(void)
184{
185 return "beaglebone";
186}
187
188/**
189 * @}
190 */
191
Note: See TracBrowser for help on using the repository browser.