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, 2017 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 /* Enable TP4, TP5 as UART0. */ 41 42 __gpio_jtag_to_uart0(); 43 44 __gpio_as_input(GPIO_POWER); 45 __gpio_enable_pull(GPIO_POWER); 46 47 __gpio_as_output(GPIO_AUDIO_POP); 48 __gpio_set_pin(GPIO_AUDIO_POP); 49 50 __gpio_as_output(GPIO_LCD_CS); 51 __gpio_clear_pin(GPIO_LCD_CS); 52 53 __gpio_as_output(GPIO_AMP_EN); 54 __gpio_clear_pin(GPIO_AMP_EN); 55 56 __gpio_as_output(GPIO_SDPW_EN); 57 __gpio_disable_pull(GPIO_SDPW_EN); 58 __gpio_clear_pin(GPIO_SDPW_EN); 59 60 __gpio_as_input(GPIO_SD_DETECT); 61 __gpio_disable_pull(GPIO_SD_DETECT); 62 63 __gpio_as_input(GPIO_USB_DETECT); 64 __gpio_enable_pull(GPIO_USB_DETECT); 65 66 /* Employ a PWM channel for the buzzer. */ 67 68 __gpio_as_pwm4(); 69 } 70 71 void cpm_init() 72 { 73 __cpm_stop_ipu(); 74 __cpm_stop_cim(); 75 __cpm_stop_i2c(); 76 __cpm_stop_ssi(); 77 __cpm_stop_uart1(); 78 __cpm_stop_sadc(); 79 __cpm_stop_uhc(); 80 __cpm_stop_udc(); 81 __cpm_stop_aic1(); 82 /* __cpm_stop_aic2();*/ 83 } 84 85 void rtc_init() 86 { 87 while ( !__rtc_write_ready()); 88 __rtc_enable_alarm(); /* enable alarm */ 89 90 while ( !__rtc_write_ready()); 91 REG_RTC_RGR = 0x00007fff; /* type value */ 92 93 while ( !__rtc_write_ready()); 94 REG_RTC_HWFCR = 0x0000ffe0; /* Power on delay 2s */ 95 96 while ( !__rtc_write_ready()); 97 REG_RTC_HRCR = 0x00000fe0; /* reset delay 125ms */ 98 } 99 100 /* Timer routines. */ 101 102 unsigned long timestamp; 103 unsigned long lastdec; 104 105 /* 106 * Timer without interrupts. 107 */ 108 109 void timer_init() 110 { 111 __tcu_disable_pwm_output(TIMER_CHAN); 112 __tcu_select_extalclk(TIMER_CHAN); 113 __tcu_select_clk_div256(TIMER_CHAN); 114 __tcu_set_count(TIMER_CHAN, 0); 115 __tcu_set_half_data(TIMER_CHAN, 0); 116 __tcu_set_full_data(TIMER_CHAN, TIMER_FDATA); 117 118 __tcu_mask_half_match_irq(TIMER_CHAN); 119 __tcu_mask_full_match_irq(TIMER_CHAN); 120 __tcu_start_timer_clock(TIMER_CHAN); 121 __tcu_start_counter(TIMER_CHAN); 122 123 __cpm_start_tcu(); 124 125 lastdec = 0; 126 timestamp = 0; 127 } 128 129 /* Timer interrupt activation. */ 130 131 void timer_init_irq() 132 { 133 __tcu_unmask_full_match_irq(TIMER_CHAN); 134 __tcu_clear_full_match_flag(TIMER_CHAN); 135 __intc_unmask_irq(TIMER_CHAN_IRQ); 136 } 137 138 void timer_clear() 139 { 140 __intc_ack_irq(TIMER_CHAN_IRQ); 141 __tcu_clear_full_match_flag(TIMER_CHAN); 142 } 143 144 /* GPIO interrupt activation. */ 145 146 void gpio_init_irq() 147 { 148 __gpio_as_irq_low_level(GPIO_POWER); 149 __intc_unmask_irq(GPIO_IRQ); 150 } 151 152 int gpio_have_irq(uint8_t gpio) 153 { 154 return (REG_GPIO_PXFLG(gpio / 32) & (1 << (gpio % 32))); 155 } 156 157 /* Board startup detection. */ 158 159 int is_started() 160 { 161 return REG_CPM_CLKGR != 0; 162 }