1 /* 2 * MiniPC 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) 2005-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 "minipc.h" 25 26 /* Later initialisation functions. */ 27 28 void gpio_init2() 29 { 30 /* LED enable. */ 31 32 __gpio_as_output(GPIO_LED_EN); 33 __gpio_set_pin(GPIO_LED_EN); 34 35 __harb_usb0_uhc(); 36 __gpio_as_emc(); 37 __gpio_as_dma(); 38 39 /* Initialise LCD pins. */ 40 41 __gpio_as_lcd_master(); 42 43 /* Initialise MSC pins. */ 44 45 __gpio_as_msc(); 46 47 /* Initialise other pins. */ 48 49 unsigned short i; 50 51 for (i = 0; i < GPIO_KEYIN_COUNT; i++) { 52 __gpio_as_input(GPIO_KEYIN_BASE + i); 53 __gpio_enable_pull(GPIO_KEYIN_BASE + i); 54 } 55 56 for (i = 0; i < GPIO_KEYOUT_COUNT; i++) { 57 __gpio_as_output(GPIO_KEYOUT_BASE + i); 58 __gpio_clear_pin(GPIO_KEYOUT_BASE + i); 59 } 60 } 61 62 void rtc_init() 63 { 64 /* NOTE: May only be accessible via I2C. */ 65 } 66 67 /* Timer routines. */ 68 69 unsigned long timestamp; 70 unsigned long lastdec; 71 72 /* 73 * Timer without interrupts. 74 */ 75 76 int timer_init() 77 { 78 __ost_set_clock(TIMER_CHAN, OST_TCSR_CKS_PCLK_256); 79 __ost_set_reload(TIMER_CHAN, TIMER_FDATA); 80 __ost_set_count(TIMER_CHAN, TIMER_FDATA); 81 __ost_enable_channel(TIMER_CHAN); 82 83 jz4740_cpm_start_clock((void *) CPM_BASE); 84 85 lastdec = TIMER_FDATA; 86 timestamp = 0; 87 88 return 0; 89 } 90 91 /* Timer interrupt activation. */ 92 93 void timer_init_irq() 94 { 95 __ost_enable_interrupt(TIMER_CHAN); 96 /* NOTE: Need flag clearing? */ 97 __intc_unmask_irq(TIMER_CHAN_IRQ); 98 } 99 100 void timer_clear() 101 { 102 __intc_ack_irq(TIMER_CHAN_IRQ); 103 __ost_clear_uf(TIMER_CHAN); 104 } 105 106 /* GPIO interrupt activation. */ 107 108 void gpio_init_irq() 109 { 110 __gpio_as_irq_low_level(GPIO_POWER); 111 __intc_unmask_irq(GPIO_IRQ); 112 } 113 114 int gpio_have_irq(uint8_t gpio) 115 { 116 return (REG_GPIO_GPFR(gpio / 32) & (1 << (gpio % 32))); 117 } 118 119 /* Board startup detection. */ 120 121 int is_started() 122 { 123 return jz4740_cpm_have_clock((void *) CPM_BASE); 124 }