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