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 #include "gpio.h" 26 27 /* Later initialisation functions. */ 28 29 void gpio_init2() 30 { 31 void *gpio_port_base; 32 33 /* LED enable. */ 34 35 gpio_port_base = jz4740_get_port((void *) GPIO_BASE, GPIO_PORT_LED); 36 jz4740_gpio_as_output(gpio_port_base, GPIO_LED_EN); 37 jz4740_gpio_set_pin(gpio_port_base, GPIO_LED_EN); 38 39 __harb_usb0_uhc(); 40 41 /* gpio_as_emc */ 42 43 gpio_port_base = jz4740_get_port((void *) GPIO_BASE, GPIO_PORT_EMC); 44 45 jz4740_gpio_ctrl_update(gpio_port_base, GPIO_GPALR, 0xC0000000, 0x40000000); 46 jz4740_gpio_ctrl_update(gpio_port_base, GPIO_GPAUR, 0x0000FFFF, 0x00005555); 47 48 /* gpio_as_dma */ 49 50 gpio_port_base = jz4740_get_port((void *) GPIO_BASE, GPIO_PORT_DMA); 51 52 jz4740_gpio_ctrl_update(gpio_port_base, GPIO_GPALR, 0xFF000000, 0x55000000); 53 jz4740_gpio_ctrl_update(gpio_port_base, GPIO_GPAUR, 0x00F00000, 0x00500000); 54 55 /* Initialise LCD pins. */ 56 57 /* gpio_as_lcd_master */ 58 59 gpio_port_base = jz4740_get_port((void *) GPIO_BASE, GPIO_PORT_LCD); 60 61 jz4740_gpio_ctrl_update(gpio_port_base, GPIO_GPALR, 0xFFFF0000, 0x55550000); 62 jz4740_gpio_ctrl_set(gpio_port_base, GPIO_GPAUR, 0x556A5555); 63 64 /* Initialise MSC pins. */ 65 66 /* gpio_as_msc */ 67 68 gpio_port_base = jz4740_get_port((void *) GPIO_BASE, GPIO_PORT_MSC); 69 70 jz4740_gpio_ctrl_update(gpio_port_base, GPIO_GPALR, 0x0000FFF0, 0x00005550); 71 } 72 73 void rtc_init() 74 { 75 /* NOTE: May only be accessible via I2C. */ 76 } 77 78 /* Timer routines. */ 79 80 unsigned long timestamp; 81 unsigned long lastdec; 82 83 /* 84 * Timer without interrupts. 85 */ 86 87 int timer_init() 88 { 89 __ost_set_clock(TIMER_CHAN, OST_TCSR_CKS_PCLK_256); 90 __ost_set_reload(TIMER_CHAN, TIMER_FDATA); 91 __ost_set_count(TIMER_CHAN, TIMER_FDATA); 92 __ost_enable_channel(TIMER_CHAN); 93 94 jz4740_cpm_start_clock((void *) CPM_BASE); 95 96 lastdec = TIMER_FDATA; 97 timestamp = 0; 98 99 return 0; 100 } 101 102 /* Timer interrupt activation. */ 103 104 void timer_init_irq() 105 { 106 __ost_enable_interrupt(TIMER_CHAN); 107 /* NOTE: Need flag clearing? */ 108 __intc_unmask_irq(TIMER_CHAN_IRQ); 109 } 110 111 void timer_clear() 112 { 113 __intc_ack_irq(TIMER_CHAN_IRQ); 114 __ost_clear_uf(TIMER_CHAN); 115 } 116 117 /* GPIO interrupt activation. */ 118 119 void gpio_init_irq() 120 { 121 gpio_port_base = jz4740_get_port((void *) GPIO_BASE, GPIO_PORT_POWER); 122 jz4740_gpio_as_irq(gpio_port_base, GPIO_POWER, gpio_irq_low_level); 123 __intc_unmask_irq(GPIO_IRQ); 124 } 125 126 int gpio_have_irq(uint8_t gpio) 127 { 128 gpio_port_base = jz4740_get_port((void *) GPIO_BASE, gpio / 32); 129 return jz4740_gpio_have_irq(gpio_port_base, gpio % 32); 130 } 131 132 /* Board startup detection. */ 133 134 int is_started() 135 { 136 return jz4740_cpm_have_clock((void *) CPM_BASE); 137 }