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@51 | 78 | |
paul@51 | 79 | __gpio_as_pwm4(); |
paul@16 | 80 | } |
paul@16 | 81 | |
paul@16 | 82 | void cpm_init(void) |
paul@16 | 83 | { |
paul@16 | 84 | __cpm_stop_ipu(); |
paul@16 | 85 | __cpm_stop_cim(); |
paul@16 | 86 | __cpm_stop_i2c(); |
paul@16 | 87 | __cpm_stop_ssi(); |
paul@16 | 88 | __cpm_stop_uart1(); |
paul@16 | 89 | __cpm_stop_sadc(); |
paul@16 | 90 | __cpm_stop_uhc(); |
paul@16 | 91 | __cpm_stop_udc(); |
paul@16 | 92 | __cpm_stop_aic1(); |
paul@16 | 93 | /* __cpm_stop_aic2();*/ |
paul@16 | 94 | } |
paul@16 | 95 | |
paul@16 | 96 | void rtc_init(void) |
paul@16 | 97 | { |
paul@16 | 98 | while ( !__rtc_write_ready()); |
paul@16 | 99 | __rtc_enable_alarm(); /* enable alarm */ |
paul@16 | 100 | |
paul@16 | 101 | while ( !__rtc_write_ready()); |
paul@16 | 102 | REG_RTC_RGR = 0x00007fff; /* type value */ |
paul@16 | 103 | |
paul@16 | 104 | while ( !__rtc_write_ready()); |
paul@16 | 105 | REG_RTC_HWFCR = 0x0000ffe0; /* Power on delay 2s */ |
paul@16 | 106 | |
paul@16 | 107 | while ( !__rtc_write_ready()); |
paul@16 | 108 | REG_RTC_HRCR = 0x00000fe0; /* reset delay 125ms */ |
paul@16 | 109 | } |
paul@16 | 110 | |
paul@16 | 111 | /* Timer routines. */ |
paul@16 | 112 | |
paul@33 | 113 | unsigned long timestamp; |
paul@33 | 114 | unsigned long lastdec; |
paul@16 | 115 | |
paul@16 | 116 | /* |
paul@16 | 117 | * timer without interrupts |
paul@16 | 118 | */ |
paul@16 | 119 | |
paul@16 | 120 | int timer_init(void) |
paul@16 | 121 | { |
paul@50 | 122 | __tcu_select_extalclk(TIMER_CHAN); |
paul@50 | 123 | __tcu_select_clk_div256(TIMER_CHAN); |
paul@50 | 124 | __tcu_set_count(TIMER_CHAN, 0); |
paul@50 | 125 | __tcu_set_half_data(TIMER_CHAN, 0); |
paul@50 | 126 | __tcu_set_full_data(TIMER_CHAN, TIMER_FDATA); |
paul@16 | 127 | |
paul@50 | 128 | __tcu_mask_half_match_irq(TIMER_CHAN); |
paul@50 | 129 | __tcu_mask_full_match_irq(TIMER_CHAN); |
paul@50 | 130 | __tcu_start_timer_clock(TIMER_CHAN); |
paul@50 | 131 | __tcu_start_counter(TIMER_CHAN); |
paul@16 | 132 | |
paul@16 | 133 | lastdec = 0; |
paul@16 | 134 | timestamp = 0; |
paul@16 | 135 | |
paul@16 | 136 | return 0; |
paul@16 | 137 | } |
paul@51 | 138 | |
paul@51 | 139 | void buzzer_init(void) |
paul@51 | 140 | { |
paul@51 | 141 | volatile int i; |
paul@51 | 142 | |
paul@51 | 143 | __tcu_select_extalclk(4); |
paul@51 | 144 | __tcu_select_clk_div64(4); |
paul@51 | 145 | __tcu_enable_pwm_output(4); |
paul@51 | 146 | |
paul@51 | 147 | __tcu_set_full_data(4, 576); |
paul@51 | 148 | __tcu_set_half_data(4, 576 / 2); |
paul@51 | 149 | __tcu_set_count(4, 0); |
paul@51 | 150 | __tcu_start_counter(4); |
paul@51 | 151 | |
paul@51 | 152 | for (i = 0; i < 20000000; i++); |
paul@51 | 153 | |
paul@51 | 154 | __tcu_stop_counter(4); |
paul@51 | 155 | } |