paul@16 | 1 | /* |
paul@16 | 2 | * Ben NanoNote board late initialisation, based on uboot-xburst and xburst-tools. |
paul@16 | 3 | * |
paul@33 | 4 | * Copyright (C) 2000-2009 Wolfgang Denk, DENX Software Engineering, <wd@denx.de> |
paul@33 | 5 | * Copyright (C) 2006 Ingenic Semiconductor, <jlwei@ingenic.cn> |
paul@16 | 6 | * Copyright (C) Xiangfu Liu <xiangfu.z@gmail.com> |
paul@33 | 7 | * Copyright (C) 2015 Paul Boddie <paul@boddie.org.uk> |
paul@16 | 8 | * |
paul@63 | 9 | * This program is free software: you can redistribute it and/or modify |
paul@63 | 10 | * it under the terms of the GNU General Public License as published by |
paul@63 | 11 | * the Free Software Foundation, either version 3 of the License, or |
paul@63 | 12 | * (at your option) any later version. |
paul@16 | 13 | * |
paul@63 | 14 | * This program is distributed in the hope that it will be useful, |
paul@63 | 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
paul@63 | 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
paul@63 | 17 | * GNU General Public License for more details. |
paul@16 | 18 | * |
paul@63 | 19 | * You should have received a copy of the GNU General Public License |
paul@63 | 20 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
paul@16 | 21 | */ |
paul@16 | 22 | |
paul@33 | 23 | #include "board.h" |
paul@16 | 24 | #include "nanonote.h" |
paul@16 | 25 | |
paul@16 | 26 | /* Later initialisation functions. */ |
paul@16 | 27 | |
paul@16 | 28 | void gpio_init2(void) |
paul@16 | 29 | { |
paul@16 | 30 | /* |
paul@16 | 31 | * Initialize LCD pins |
paul@16 | 32 | */ |
paul@16 | 33 | __gpio_as_slcd_8bit(); |
paul@16 | 34 | |
paul@16 | 35 | /* |
paul@16 | 36 | * Initialize MSC pins |
paul@16 | 37 | */ |
paul@16 | 38 | __gpio_as_msc(); |
paul@16 | 39 | |
paul@16 | 40 | /* |
paul@16 | 41 | * Initialize Other pins |
paul@16 | 42 | */ |
paul@16 | 43 | unsigned int i; |
paul@16 | 44 | for (i = 0; i < 7; i++){ |
paul@16 | 45 | __gpio_as_input(GPIO_KEYIN_BASE + i); |
paul@16 | 46 | __gpio_enable_pull(GPIO_KEYIN_BASE + i); |
paul@16 | 47 | } |
paul@16 | 48 | |
paul@16 | 49 | for (i = 0; i < 8; i++) { |
paul@16 | 50 | __gpio_as_output(GPIO_KEYOUT_BASE + i); |
paul@16 | 51 | __gpio_clear_pin(GPIO_KEYOUT_BASE + i); |
paul@16 | 52 | } |
paul@16 | 53 | |
paul@16 | 54 | /* enable the TP4, TP5 as UART0 */ |
paul@16 | 55 | __gpio_jtag_to_uart0(); |
paul@16 | 56 | |
paul@16 | 57 | __gpio_as_input(GPIO_KEYIN_8); |
paul@16 | 58 | __gpio_enable_pull(GPIO_KEYIN_8); |
paul@16 | 59 | |
paul@108 | 60 | __gpio_as_input(GPIO_POWER); |
paul@108 | 61 | __gpio_enable_pull(GPIO_POWER); |
paul@108 | 62 | |
paul@16 | 63 | __gpio_as_output(GPIO_AUDIO_POP); |
paul@16 | 64 | __gpio_set_pin(GPIO_AUDIO_POP); |
paul@16 | 65 | |
paul@16 | 66 | __gpio_as_output(GPIO_LCD_CS); |
paul@16 | 67 | __gpio_clear_pin(GPIO_LCD_CS); |
paul@16 | 68 | |
paul@16 | 69 | __gpio_as_output(GPIO_AMP_EN); |
paul@16 | 70 | __gpio_clear_pin(GPIO_AMP_EN); |
paul@16 | 71 | |
paul@16 | 72 | __gpio_as_output(GPIO_SDPW_EN); |
paul@16 | 73 | __gpio_disable_pull(GPIO_SDPW_EN); |
paul@16 | 74 | __gpio_clear_pin(GPIO_SDPW_EN); |
paul@16 | 75 | |
paul@16 | 76 | __gpio_as_input(GPIO_SD_DETECT); |
paul@16 | 77 | __gpio_disable_pull(GPIO_SD_DETECT); |
paul@16 | 78 | |
paul@16 | 79 | __gpio_as_input(GPIO_USB_DETECT); |
paul@16 | 80 | __gpio_enable_pull(GPIO_USB_DETECT); |
paul@16 | 81 | } |
paul@16 | 82 | |
paul@16 | 83 | void cpm_init(void) |
paul@16 | 84 | { |
paul@16 | 85 | __cpm_stop_ipu(); |
paul@16 | 86 | __cpm_stop_cim(); |
paul@16 | 87 | __cpm_stop_i2c(); |
paul@16 | 88 | __cpm_stop_ssi(); |
paul@16 | 89 | __cpm_stop_uart1(); |
paul@16 | 90 | __cpm_stop_sadc(); |
paul@16 | 91 | __cpm_stop_uhc(); |
paul@16 | 92 | __cpm_stop_udc(); |
paul@16 | 93 | __cpm_stop_aic1(); |
paul@16 | 94 | /* __cpm_stop_aic2();*/ |
paul@16 | 95 | } |
paul@16 | 96 | |
paul@16 | 97 | void rtc_init(void) |
paul@16 | 98 | { |
paul@16 | 99 | while ( !__rtc_write_ready()); |
paul@16 | 100 | __rtc_enable_alarm(); /* enable alarm */ |
paul@16 | 101 | |
paul@16 | 102 | while ( !__rtc_write_ready()); |
paul@16 | 103 | REG_RTC_RGR = 0x00007fff; /* type value */ |
paul@16 | 104 | |
paul@16 | 105 | while ( !__rtc_write_ready()); |
paul@16 | 106 | REG_RTC_HWFCR = 0x0000ffe0; /* Power on delay 2s */ |
paul@16 | 107 | |
paul@16 | 108 | while ( !__rtc_write_ready()); |
paul@16 | 109 | REG_RTC_HRCR = 0x00000fe0; /* reset delay 125ms */ |
paul@16 | 110 | } |
paul@16 | 111 | |
paul@16 | 112 | /* Timer routines. */ |
paul@16 | 113 | |
paul@33 | 114 | unsigned long timestamp; |
paul@33 | 115 | unsigned long lastdec; |
paul@16 | 116 | |
paul@16 | 117 | /* |
paul@68 | 118 | * Timer without interrupts. |
paul@16 | 119 | */ |
paul@16 | 120 | |
paul@53 | 121 | void timer_init(void) |
paul@16 | 122 | { |
paul@68 | 123 | __tcu_disable_pwm_output(TIMER_CHAN); |
paul@50 | 124 | __tcu_select_extalclk(TIMER_CHAN); |
paul@50 | 125 | __tcu_select_clk_div256(TIMER_CHAN); |
paul@50 | 126 | __tcu_set_count(TIMER_CHAN, 0); |
paul@50 | 127 | __tcu_set_half_data(TIMER_CHAN, 0); |
paul@50 | 128 | __tcu_set_full_data(TIMER_CHAN, TIMER_FDATA); |
paul@16 | 129 | |
paul@50 | 130 | __tcu_mask_half_match_irq(TIMER_CHAN); |
paul@50 | 131 | __tcu_mask_full_match_irq(TIMER_CHAN); |
paul@50 | 132 | __tcu_start_timer_clock(TIMER_CHAN); |
paul@50 | 133 | __tcu_start_counter(TIMER_CHAN); |
paul@16 | 134 | |
paul@68 | 135 | __cpm_start_tcu(); |
paul@68 | 136 | |
paul@16 | 137 | lastdec = 0; |
paul@16 | 138 | timestamp = 0; |
paul@16 | 139 | } |
paul@54 | 140 | |
paul@68 | 141 | /* Timer interrupt activation. */ |
paul@68 | 142 | |
paul@68 | 143 | void timer_init_irq(void) |
paul@68 | 144 | { |
paul@68 | 145 | __tcu_unmask_full_match_irq(TIMER_CHAN); |
paul@68 | 146 | __tcu_clear_full_match_flag(TIMER_CHAN); |
paul@68 | 147 | __intc_unmask_irq(TIMER_CHAN_IRQ); |
paul@68 | 148 | } |
paul@68 | 149 | |
paul@68 | 150 | /* Board startup detection. */ |
paul@68 | 151 | |
paul@54 | 152 | int is_started(void) |
paul@54 | 153 | { |
paul@54 | 154 | return REG_CPM_CLKGR != 0; |
paul@54 | 155 | } |