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, 2016 Paul Boddie <paul@boddie.org.uk> 8 * 9 * This program is free software: you can redistribute it and/or modify 10 * it under the terms of the GNU General Public License as published by 11 * the Free Software Foundation, either version 3 of the License, or 12 * (at your option) any later version. 13 * 14 * This program is distributed in the hope that it will be useful, 15 * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 * GNU General Public License for more details. 18 * 19 * You should have received a copy of the GNU General Public License 20 * along with 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() 29 { 30 /* Initialise LCD pins. */ 31 32 __gpio_as_slcd_8bit(); 33 34 /* Initialise MSC pins. */ 35 36 __gpio_as_msc(); 37 38 /* Initialise other pins. */ 39 40 unsigned int i; 41 42 for (i = 0; i < GPIO_KEYIN_COUNT; i++){ 43 __gpio_as_input(GPIO_KEYIN_BASE + i); 44 __gpio_enable_pull(GPIO_KEYIN_BASE + i); 45 } 46 47 for (i = 0; i < GPIO_KEYOUT_COUNT; i++) { 48 __gpio_as_output(GPIO_KEYOUT_BASE + i); 49 __gpio_clear_pin(GPIO_KEYOUT_BASE + i); 50 } 51 52 /* Enable TP4, TP5 as UART0. */ 53 54 __gpio_jtag_to_uart0(); 55 56 __gpio_as_input(GPIO_KEYIN_8); 57 __gpio_enable_pull(GPIO_KEYIN_8); 58 59 __gpio_as_input(GPIO_POWER); 60 __gpio_enable_pull(GPIO_POWER); 61 62 __gpio_as_output(GPIO_AUDIO_POP); 63 __gpio_set_pin(GPIO_AUDIO_POP); 64 65 __gpio_as_output(GPIO_LCD_CS); 66 __gpio_clear_pin(GPIO_LCD_CS); 67 68 __gpio_as_output(GPIO_AMP_EN); 69 __gpio_clear_pin(GPIO_AMP_EN); 70 71 __gpio_as_output(GPIO_SDPW_EN); 72 __gpio_disable_pull(GPIO_SDPW_EN); 73 __gpio_clear_pin(GPIO_SDPW_EN); 74 75 __gpio_as_input(GPIO_SD_DETECT); 76 __gpio_disable_pull(GPIO_SD_DETECT); 77 78 __gpio_as_input(GPIO_USB_DETECT); 79 __gpio_enable_pull(GPIO_USB_DETECT); 80 81 /* Employ a PWM channel for the buzzer. */ 82 83 __gpio_as_pwm4(); 84 } 85 86 void cpm_init() 87 { 88 __cpm_stop_ipu(); 89 __cpm_stop_cim(); 90 __cpm_stop_i2c(); 91 __cpm_stop_ssi(); 92 __cpm_stop_uart1(); 93 __cpm_stop_sadc(); 94 __cpm_stop_uhc(); 95 __cpm_stop_udc(); 96 __cpm_stop_aic1(); 97 /* __cpm_stop_aic2();*/ 98 } 99 100 void rtc_init() 101 { 102 while ( !__rtc_write_ready()); 103 __rtc_enable_alarm(); /* enable alarm */ 104 105 while ( !__rtc_write_ready()); 106 REG_RTC_RGR = 0x00007fff; /* type value */ 107 108 while ( !__rtc_write_ready()); 109 REG_RTC_HWFCR = 0x0000ffe0; /* Power on delay 2s */ 110 111 while ( !__rtc_write_ready()); 112 REG_RTC_HRCR = 0x00000fe0; /* reset delay 125ms */ 113 } 114 115 /* Timer routines. */ 116 117 unsigned long timestamp; 118 unsigned long lastdec; 119 120 /* 121 * Timer without interrupts. 122 */ 123 124 void timer_init() 125 { 126 __tcu_disable_pwm_output(TIMER_CHAN); 127 __tcu_select_extalclk(TIMER_CHAN); 128 __tcu_select_clk_div256(TIMER_CHAN); 129 __tcu_set_count(TIMER_CHAN, 0); 130 __tcu_set_half_data(TIMER_CHAN, 0); 131 __tcu_set_full_data(TIMER_CHAN, TIMER_FDATA); 132 133 __tcu_mask_half_match_irq(TIMER_CHAN); 134 __tcu_mask_full_match_irq(TIMER_CHAN); 135 __tcu_start_timer_clock(TIMER_CHAN); 136 __tcu_start_counter(TIMER_CHAN); 137 138 __cpm_start_tcu(); 139 140 lastdec = 0; 141 timestamp = 0; 142 } 143 144 /* Timer interrupt activation. */ 145 146 void timer_init_irq() 147 { 148 __tcu_unmask_full_match_irq(TIMER_CHAN); 149 __tcu_clear_full_match_flag(TIMER_CHAN); 150 __intc_unmask_irq(TIMER_CHAN_IRQ); 151 } 152 153 void timer_clear() 154 { 155 __intc_ack_irq(TIMER_CHAN_IRQ); 156 __tcu_clear_full_match_flag(TIMER_CHAN); 157 } 158 159 /* GPIO interrupt activation. */ 160 161 void gpio_init_irq() 162 { 163 __gpio_as_irq_low_level(GPIO_POWER); 164 __intc_unmask_irq(GPIO_IRQ); 165 } 166 167 int gpio_have_irq(u8 gpio) 168 { 169 return (REG_GPIO_PXFLG(gpio / 32) & (1 << (gpio % 32))); 170 } 171 172 /* Board startup detection. */ 173 174 int is_started() 175 { 176 return REG_CPM_CLKGR != 0; 177 }