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 #include "cpm.h" 26 27 /* Later initialisation functions. */ 28 29 void gpio_init2() 30 { 31 /* Initialise LCD pins. */ 32 33 __gpio_as_slcd_8bit(); 34 35 /* Initialise MSC pins. */ 36 37 __gpio_as_msc(); 38 39 /* Initialise other pins. */ 40 41 /* Enable TP4, TP5 as UART0. */ 42 43 __gpio_jtag_to_uart0(); 44 45 __gpio_as_input(GPIO_POWER); 46 __gpio_enable_pull(GPIO_POWER); 47 48 __gpio_as_output(GPIO_AUDIO_POP); 49 __gpio_set_pin(GPIO_AUDIO_POP); 50 51 __gpio_as_output(GPIO_LCD_CS); 52 __gpio_clear_pin(GPIO_LCD_CS); 53 54 __gpio_as_output(GPIO_AMP_EN); 55 __gpio_clear_pin(GPIO_AMP_EN); 56 57 __gpio_as_output(GPIO_SDPW_EN); 58 __gpio_disable_pull(GPIO_SDPW_EN); 59 __gpio_clear_pin(GPIO_SDPW_EN); 60 61 __gpio_as_input(GPIO_SD_DETECT); 62 __gpio_disable_pull(GPIO_SD_DETECT); 63 64 __gpio_as_input(GPIO_USB_DETECT); 65 __gpio_enable_pull(GPIO_USB_DETECT); 66 67 /* Employ a PWM channel for the buzzer. */ 68 69 __gpio_as_pwm4(); 70 } 71 72 void rtc_init() 73 { 74 while ( !__rtc_write_ready()); 75 __rtc_enable_alarm(); /* enable alarm */ 76 77 while ( !__rtc_write_ready()); 78 REG_RTC_RGR = 0x00007fff; /* type value */ 79 80 while ( !__rtc_write_ready()); 81 REG_RTC_HWFCR = 0x0000ffe0; /* Power on delay 2s */ 82 83 while ( !__rtc_write_ready()); 84 REG_RTC_HRCR = 0x00000fe0; /* reset delay 125ms */ 85 } 86 87 /* Timer routines. */ 88 89 unsigned long timestamp; 90 unsigned long lastdec; 91 92 /* 93 * Timer without interrupts. 94 */ 95 96 void timer_init() 97 { 98 __tcu_disable_pwm_output(TIMER_CHAN); 99 __tcu_select_extalclk(TIMER_CHAN); 100 __tcu_select_clk_div256(TIMER_CHAN); 101 __tcu_set_count(TIMER_CHAN, 0); 102 __tcu_set_half_data(TIMER_CHAN, 0); 103 __tcu_set_full_data(TIMER_CHAN, TIMER_FDATA); 104 105 __tcu_mask_half_match_irq(TIMER_CHAN); 106 __tcu_mask_full_match_irq(TIMER_CHAN); 107 __tcu_start_timer_clock(TIMER_CHAN); 108 __tcu_start_counter(TIMER_CHAN); 109 110 jz4740_cpm_start_clock((void *) CPM_BASE); 111 112 lastdec = 0; 113 timestamp = 0; 114 } 115 116 /* Timer interrupt activation. */ 117 118 void timer_init_irq() 119 { 120 __tcu_unmask_full_match_irq(TIMER_CHAN); 121 __tcu_clear_full_match_flag(TIMER_CHAN); 122 __intc_unmask_irq(TIMER_CHAN_IRQ); 123 } 124 125 void timer_clear() 126 { 127 __intc_ack_irq(TIMER_CHAN_IRQ); 128 __tcu_clear_full_match_flag(TIMER_CHAN); 129 } 130 131 /* GPIO interrupt activation. */ 132 133 void gpio_init_irq() 134 { 135 __gpio_as_irq_low_level(GPIO_POWER); 136 __intc_unmask_irq(GPIO_IRQ); 137 } 138 139 int gpio_have_irq(uint8_t gpio) 140 { 141 return (REG_GPIO_PXFLG(gpio / 32) & (1 << (gpio % 32))); 142 } 143 144 /* Board startup detection. */ 145 146 int is_started() 147 { 148 return jz4740_cpm_have_clock((void *) CPM_BASE); 149 }