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@16 | 9 | * This program is free software; you can redistribute it and/or modify it under |
paul@16 | 10 | * the terms of the GNU General Public License as published by the Free Software |
paul@16 | 11 | * Foundation; either version 3 of the License, or (at your option) any later |
paul@16 | 12 | * version. |
paul@16 | 13 | * |
paul@16 | 14 | * This program is distributed in the hope that it will be useful, but WITHOUT |
paul@16 | 15 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
paul@16 | 16 | * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more |
paul@16 | 17 | * details. |
paul@16 | 18 | * |
paul@16 | 19 | * You should have received a copy of the GNU General Public License along with |
paul@16 | 20 | * 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@16 | 60 | __gpio_as_output(GPIO_AUDIO_POP); |
paul@16 | 61 | __gpio_set_pin(GPIO_AUDIO_POP); |
paul@16 | 62 | |
paul@16 | 63 | __gpio_as_output(GPIO_LCD_CS); |
paul@16 | 64 | __gpio_clear_pin(GPIO_LCD_CS); |
paul@16 | 65 | |
paul@16 | 66 | __gpio_as_output(GPIO_AMP_EN); |
paul@16 | 67 | __gpio_clear_pin(GPIO_AMP_EN); |
paul@16 | 68 | |
paul@16 | 69 | __gpio_as_output(GPIO_SDPW_EN); |
paul@16 | 70 | __gpio_disable_pull(GPIO_SDPW_EN); |
paul@16 | 71 | __gpio_clear_pin(GPIO_SDPW_EN); |
paul@16 | 72 | |
paul@16 | 73 | __gpio_as_input(GPIO_SD_DETECT); |
paul@16 | 74 | __gpio_disable_pull(GPIO_SD_DETECT); |
paul@16 | 75 | |
paul@16 | 76 | __gpio_as_input(GPIO_USB_DETECT); |
paul@16 | 77 | __gpio_enable_pull(GPIO_USB_DETECT); |
paul@16 | 78 | } |
paul@16 | 79 | |
paul@16 | 80 | void cpm_init(void) |
paul@16 | 81 | { |
paul@16 | 82 | __cpm_stop_ipu(); |
paul@16 | 83 | __cpm_stop_cim(); |
paul@16 | 84 | __cpm_stop_i2c(); |
paul@16 | 85 | __cpm_stop_ssi(); |
paul@16 | 86 | __cpm_stop_uart1(); |
paul@16 | 87 | __cpm_stop_sadc(); |
paul@16 | 88 | __cpm_stop_uhc(); |
paul@16 | 89 | __cpm_stop_udc(); |
paul@16 | 90 | __cpm_stop_aic1(); |
paul@16 | 91 | /* __cpm_stop_aic2();*/ |
paul@16 | 92 | } |
paul@16 | 93 | |
paul@16 | 94 | void rtc_init(void) |
paul@16 | 95 | { |
paul@16 | 96 | while ( !__rtc_write_ready()); |
paul@16 | 97 | __rtc_enable_alarm(); /* enable alarm */ |
paul@16 | 98 | |
paul@16 | 99 | while ( !__rtc_write_ready()); |
paul@16 | 100 | REG_RTC_RGR = 0x00007fff; /* type value */ |
paul@16 | 101 | |
paul@16 | 102 | while ( !__rtc_write_ready()); |
paul@16 | 103 | REG_RTC_HWFCR = 0x0000ffe0; /* Power on delay 2s */ |
paul@16 | 104 | |
paul@16 | 105 | while ( !__rtc_write_ready()); |
paul@16 | 106 | REG_RTC_HRCR = 0x00000fe0; /* reset delay 125ms */ |
paul@16 | 107 | } |
paul@16 | 108 | |
paul@16 | 109 | /* Timer routines. */ |
paul@16 | 110 | |
paul@33 | 111 | unsigned long timestamp; |
paul@33 | 112 | unsigned long lastdec; |
paul@16 | 113 | |
paul@16 | 114 | /* |
paul@16 | 115 | * timer without interrupts |
paul@16 | 116 | */ |
paul@16 | 117 | |
paul@53 | 118 | void timer_init(void) |
paul@16 | 119 | { |
paul@50 | 120 | __tcu_select_extalclk(TIMER_CHAN); |
paul@50 | 121 | __tcu_select_clk_div256(TIMER_CHAN); |
paul@50 | 122 | __tcu_set_count(TIMER_CHAN, 0); |
paul@50 | 123 | __tcu_set_half_data(TIMER_CHAN, 0); |
paul@50 | 124 | __tcu_set_full_data(TIMER_CHAN, TIMER_FDATA); |
paul@16 | 125 | |
paul@50 | 126 | __tcu_mask_half_match_irq(TIMER_CHAN); |
paul@50 | 127 | __tcu_mask_full_match_irq(TIMER_CHAN); |
paul@50 | 128 | __tcu_start_timer_clock(TIMER_CHAN); |
paul@50 | 129 | __tcu_start_counter(TIMER_CHAN); |
paul@16 | 130 | |
paul@16 | 131 | lastdec = 0; |
paul@16 | 132 | timestamp = 0; |
paul@16 | 133 | } |
paul@54 | 134 | |
paul@54 | 135 | int is_started(void) |
paul@54 | 136 | { |
paul@54 | 137 | return REG_CPM_CLKGR != 0; |
paul@54 | 138 | } |