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