[574fb67] | 1 | /** |
---|
| 2 | * @file |
---|
| 3 | * |
---|
| 4 | * @ingroup mpc83xx |
---|
| 5 | * |
---|
| 6 | * @brief Source for BSP startup code. |
---|
| 7 | */ |
---|
[f610e83f] | 8 | |
---|
[dfef80e8] | 9 | /* |
---|
[6ec438e] | 10 | * Copyright (c) 2008-2014 embedded brains GmbH. All rights reserved. |
---|
| 11 | * |
---|
| 12 | * embedded brains GmbH |
---|
| 13 | * Dornierstr. 4 |
---|
| 14 | * 82178 Puchheim |
---|
| 15 | * Germany |
---|
| 16 | * <info@embedded-brains.de> |
---|
[574fb67] | 17 | * |
---|
[e570c313] | 18 | * The license and distribution terms for this file may be |
---|
| 19 | * found in the file LICENSE in this distribution or at |
---|
[c499856] | 20 | * http://www.rtems.org/license/LICENSE. |
---|
[dfef80e8] | 21 | */ |
---|
| 22 | |
---|
[24bf11e] | 23 | #include <rtems/counter.h> |
---|
| 24 | |
---|
[6ec438e] | 25 | #include <libchip/ns16550.h> |
---|
[8a54204] | 26 | |
---|
[574fb67] | 27 | #include <libcpu/powerpc-utility.h> |
---|
[f610e83f] | 28 | |
---|
[574fb67] | 29 | #include <bsp.h> |
---|
[2d2de4eb] | 30 | #include <bsp/vectors.h> |
---|
[d4886a06] | 31 | #include <bsp/bootcard.h> |
---|
[574fb67] | 32 | #include <bsp/irq-generic.h> |
---|
[f88da30] | 33 | #include <bsp/linker-symbols.h> |
---|
[ce0922e] | 34 | #include <bsp/u-boot.h> |
---|
[6ec438e] | 35 | #include <bsp/console-termios.h> |
---|
[574fb67] | 36 | |
---|
| 37 | /* Configuration parameters for console driver, ... */ |
---|
[42bf1b9] | 38 | unsigned int BSP_bus_frequency; |
---|
[f610e83f] | 39 | |
---|
[8bb00ac] | 40 | /* Configuration parameter for clock driver */ |
---|
| 41 | uint32_t bsp_time_base_frequency; |
---|
| 42 | |
---|
| 43 | /* Legacy */ |
---|
[574fb67] | 44 | uint32_t bsp_clicks_per_usec; |
---|
| 45 | |
---|
[bbbb8f0] | 46 | /* Default decrementer exception handler */ |
---|
| 47 | static int mpc83xx_decrementer_exception_handler( BSP_Exception_frame *frame, unsigned number) |
---|
| 48 | { |
---|
[d9be8024] | 49 | ppc_set_decrementer_register(UINT32_MAX); |
---|
[bbbb8f0] | 50 | |
---|
[d9be8024] | 51 | return 0; |
---|
[bbbb8f0] | 52 | } |
---|
[f610e83f] | 53 | |
---|
[65f868c] | 54 | uint32_t _CPU_Counter_frequency(void) |
---|
| 55 | { |
---|
| 56 | return bsp_time_base_frequency; |
---|
| 57 | } |
---|
| 58 | |
---|
[574fb67] | 59 | void bsp_start( void) |
---|
[f610e83f] | 60 | { |
---|
[d9be8024] | 61 | rtems_status_code sc = RTEMS_SUCCESSFUL; |
---|
[8a54204] | 62 | unsigned long i = 0; |
---|
[bbbb8f0] | 63 | |
---|
[d9be8024] | 64 | /* |
---|
| 65 | * Get CPU identification dynamically. Note that the get_ppc_cpu_type() function |
---|
| 66 | * store the result in global variables so that it can be used latter... |
---|
| 67 | */ |
---|
[6ec438e] | 68 | get_ppc_cpu_type(); |
---|
| 69 | get_ppc_cpu_revision(); |
---|
[574fb67] | 70 | |
---|
[d9be8024] | 71 | /* Basic CPU initialization */ |
---|
| 72 | cpu_init(); |
---|
[574fb67] | 73 | |
---|
[d9be8024] | 74 | /* |
---|
| 75 | * Enable instruction and data caches. Do not force writethrough mode. |
---|
| 76 | */ |
---|
[d3c32136] | 77 | |
---|
[1bb72a9] | 78 | #ifdef BSP_INSTRUCTION_CACHE_ENABLED |
---|
[d9be8024] | 79 | rtems_cache_enable_instruction(); |
---|
[d3c32136] | 80 | #endif |
---|
| 81 | |
---|
[1bb72a9] | 82 | #ifdef BSP_DATA_CACHE_ENABLED |
---|
[d9be8024] | 83 | rtems_cache_enable_data(); |
---|
[d3c32136] | 84 | #endif |
---|
| 85 | |
---|
[d9be8024] | 86 | /* |
---|
| 87 | * This is evaluated during runtime, so it should be ok to set it |
---|
| 88 | * before we initialize the drivers. |
---|
| 89 | */ |
---|
[574fb67] | 90 | |
---|
[d9be8024] | 91 | /* Initialize some device driver parameters */ |
---|
[574fb67] | 92 | |
---|
| 93 | #ifdef HAS_UBOOT |
---|
[f044f9c] | 94 | BSP_bus_frequency = bsp_uboot_board_info.bi_busfreq; |
---|
[574fb67] | 95 | #else /* HAS_UBOOT */ |
---|
[d9be8024] | 96 | BSP_bus_frequency = BSP_CLKIN_FRQ * BSP_SYSPLL_MF / BSP_SYSPLL_CKID; |
---|
[574fb67] | 97 | #endif /* HAS_UBOOT */ |
---|
[8bb00ac] | 98 | bsp_time_base_frequency = BSP_bus_frequency / 4; |
---|
| 99 | bsp_clicks_per_usec = bsp_time_base_frequency / 1000000; |
---|
[574fb67] | 100 | |
---|
[8a54204] | 101 | /* Initialize some console parameters */ |
---|
[6ec438e] | 102 | for (i = 0; i < console_device_count; ++i) { |
---|
| 103 | ns16550_context *ctx = (ns16550_context *) console_device_table[i].context; |
---|
| 104 | |
---|
| 105 | ctx->clock = BSP_bus_frequency; |
---|
[8a54204] | 106 | |
---|
| 107 | #ifdef HAS_UBOOT |
---|
[6ec438e] | 108 | ctx->initial_baud = bsp_uboot_board_info.bi_baudrate; |
---|
[8a54204] | 109 | #endif |
---|
| 110 | } |
---|
| 111 | |
---|
[d9be8024] | 112 | /* Initialize exception handler */ |
---|
[1bb72a9] | 113 | #ifndef BSP_DATA_CACHE_ENABLED |
---|
| 114 | ppc_exc_cache_wb_check = 0; |
---|
| 115 | #endif |
---|
[b1e8a58] | 116 | ppc_exc_initialize( |
---|
[f88da30] | 117 | (uintptr_t) bsp_section_work_begin, |
---|
| 118 | rtems_configuration_get_interrupt_stack_size() |
---|
[d9be8024] | 119 | ); |
---|
| 120 | |
---|
| 121 | /* Install default handler for the decrementer exception */ |
---|
[2d2de4eb] | 122 | sc = ppc_exc_set_handler( ASM_DEC_VECTOR, mpc83xx_decrementer_exception_handler); |
---|
| 123 | if (sc != RTEMS_SUCCESSFUL) { |
---|
[1c193a2] | 124 | rtems_panic("cannot install decrementer exception handler"); |
---|
[d9be8024] | 125 | } |
---|
| 126 | |
---|
| 127 | /* Initalize interrupt support */ |
---|
[dd8df59] | 128 | bsp_interrupt_initialize(); |
---|
[f610e83f] | 129 | |
---|
| 130 | #ifdef SHOW_MORE_INIT_SETTINGS |
---|
[d9be8024] | 131 | printk("Exit from bspstart\n"); |
---|
[f610e83f] | 132 | #endif |
---|
[574fb67] | 133 | } |
---|