paul@39 | 1 | /* |
paul@39 | 2 | * MiniPC board late initialisation, based on uboot-xburst and xburst-tools. |
paul@39 | 3 | * |
paul@39 | 4 | * Copyright (C) 2000-2009 Wolfgang Denk, DENX Software Engineering, <wd@denx.de> |
paul@39 | 5 | * Copyright (C) 2005-2006 Ingenic Semiconductor, <jlwei@ingenic.cn> |
paul@39 | 6 | * Copyright (C) Xiangfu Liu <xiangfu.z@gmail.com> |
paul@217 | 7 | * Copyright (C) 2015, 2016, 2017 Paul Boddie <paul@boddie.org.uk> |
paul@39 | 8 | * |
paul@63 | 9 | * This program is free software: you can redistribute it and/or modify |
paul@63 | 10 | * it under the terms of the GNU General Public License as published by |
paul@63 | 11 | * the Free Software Foundation, either version 3 of the License, or |
paul@63 | 12 | * (at your option) any later version. |
paul@39 | 13 | * |
paul@63 | 14 | * This program is distributed in the hope that it will be useful, |
paul@63 | 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
paul@63 | 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
paul@63 | 17 | * GNU General Public License for more details. |
paul@39 | 18 | * |
paul@63 | 19 | * You should have received a copy of the GNU General Public License |
paul@63 | 20 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
paul@39 | 21 | */ |
paul@39 | 22 | |
paul@39 | 23 | #include "board.h" |
paul@39 | 24 | #include "minipc.h" |
paul@233 | 25 | #include "gpio.h" |
paul@39 | 26 | |
paul@39 | 27 | /* Later initialisation functions. */ |
paul@39 | 28 | |
paul@195 | 29 | void gpio_init2() |
paul@39 | 30 | { |
paul@233 | 31 | void *gpio_port_base; |
paul@233 | 32 | |
paul@204 | 33 | /* LED enable. */ |
paul@204 | 34 | |
paul@233 | 35 | gpio_port_base = jz4740_get_port((void *) GPIO_BASE, GPIO_PORT_LED); |
paul@233 | 36 | jz4740_gpio_as_output(gpio_port_base, GPIO_LED_EN); |
paul@233 | 37 | jz4740_gpio_set_pin(gpio_port_base, GPIO_LED_EN); |
paul@39 | 38 | |
paul@39 | 39 | __harb_usb0_uhc(); |
paul@233 | 40 | |
paul@233 | 41 | /* gpio_as_emc */ |
paul@233 | 42 | |
paul@233 | 43 | gpio_port_base = jz4740_get_port((void *) GPIO_BASE, GPIO_PORT_EMC); |
paul@233 | 44 | |
paul@233 | 45 | jz4740_gpio_ctrl_update(gpio_port_base, GPIO_GPALR, 0xC0000000, 0x40000000); |
paul@233 | 46 | jz4740_gpio_ctrl_update(gpio_port_base, GPIO_GPAUR, 0x0000FFFF, 0x00005555); |
paul@233 | 47 | |
paul@233 | 48 | /* gpio_as_dma */ |
paul@233 | 49 | |
paul@233 | 50 | gpio_port_base = jz4740_get_port((void *) GPIO_BASE, GPIO_PORT_DMA); |
paul@233 | 51 | |
paul@233 | 52 | jz4740_gpio_ctrl_update(gpio_port_base, GPIO_GPALR, 0xFF000000, 0x55000000); |
paul@233 | 53 | jz4740_gpio_ctrl_update(gpio_port_base, GPIO_GPAUR, 0x00F00000, 0x00500000); |
paul@39 | 54 | |
paul@204 | 55 | /* Initialise LCD pins. */ |
paul@204 | 56 | |
paul@233 | 57 | /* gpio_as_lcd_master */ |
paul@233 | 58 | |
paul@233 | 59 | gpio_port_base = jz4740_get_port((void *) GPIO_BASE, GPIO_PORT_LCD); |
paul@233 | 60 | |
paul@233 | 61 | jz4740_gpio_ctrl_update(gpio_port_base, GPIO_GPALR, 0xFFFF0000, 0x55550000); |
paul@233 | 62 | jz4740_gpio_ctrl_set(gpio_port_base, GPIO_GPAUR, 0x556A5555); |
paul@39 | 63 | |
paul@204 | 64 | /* Initialise MSC pins. */ |
paul@204 | 65 | |
paul@233 | 66 | /* gpio_as_msc */ |
paul@204 | 67 | |
paul@233 | 68 | gpio_port_base = jz4740_get_port((void *) GPIO_BASE, GPIO_PORT_MSC); |
paul@204 | 69 | |
paul@233 | 70 | jz4740_gpio_ctrl_update(gpio_port_base, GPIO_GPALR, 0x0000FFF0, 0x00005550); |
paul@39 | 71 | } |
paul@39 | 72 | |
paul@195 | 73 | void rtc_init() |
paul@39 | 74 | { |
paul@39 | 75 | /* NOTE: May only be accessible via I2C. */ |
paul@39 | 76 | } |
paul@39 | 77 | |
paul@39 | 78 | /* Timer routines. */ |
paul@39 | 79 | |
paul@39 | 80 | unsigned long timestamp; |
paul@39 | 81 | unsigned long lastdec; |
paul@39 | 82 | |
paul@39 | 83 | /* |
paul@68 | 84 | * Timer without interrupts. |
paul@39 | 85 | */ |
paul@39 | 86 | |
paul@195 | 87 | int timer_init() |
paul@39 | 88 | { |
paul@39 | 89 | __ost_set_clock(TIMER_CHAN, OST_TCSR_CKS_PCLK_256); |
paul@39 | 90 | __ost_set_reload(TIMER_CHAN, TIMER_FDATA); |
paul@39 | 91 | __ost_set_count(TIMER_CHAN, TIMER_FDATA); |
paul@39 | 92 | __ost_enable_channel(TIMER_CHAN); |
paul@39 | 93 | |
paul@230 | 94 | jz4740_cpm_start_clock((void *) CPM_BASE); |
paul@68 | 95 | |
paul@39 | 96 | lastdec = TIMER_FDATA; |
paul@39 | 97 | timestamp = 0; |
paul@39 | 98 | |
paul@39 | 99 | return 0; |
paul@39 | 100 | } |
paul@55 | 101 | |
paul@68 | 102 | /* Timer interrupt activation. */ |
paul@68 | 103 | |
paul@195 | 104 | void timer_init_irq() |
paul@68 | 105 | { |
paul@68 | 106 | __ost_enable_interrupt(TIMER_CHAN); |
paul@68 | 107 | /* NOTE: Need flag clearing? */ |
paul@68 | 108 | __intc_unmask_irq(TIMER_CHAN_IRQ); |
paul@68 | 109 | } |
paul@68 | 110 | |
paul@195 | 111 | void timer_clear() |
paul@153 | 112 | { |
paul@153 | 113 | __intc_ack_irq(TIMER_CHAN_IRQ); |
paul@153 | 114 | __ost_clear_uf(TIMER_CHAN); |
paul@153 | 115 | } |
paul@153 | 116 | |
paul@197 | 117 | /* GPIO interrupt activation. */ |
paul@197 | 118 | |
paul@197 | 119 | void gpio_init_irq() |
paul@197 | 120 | { |
paul@233 | 121 | gpio_port_base = jz4740_get_port((void *) GPIO_BASE, GPIO_PORT_POWER); |
paul@233 | 122 | jz4740_gpio_as_irq(gpio_port_base, GPIO_POWER, gpio_irq_low_level); |
paul@197 | 123 | __intc_unmask_irq(GPIO_IRQ); |
paul@197 | 124 | } |
paul@197 | 125 | |
paul@217 | 126 | int gpio_have_irq(uint8_t gpio) |
paul@197 | 127 | { |
paul@233 | 128 | gpio_port_base = jz4740_get_port((void *) GPIO_BASE, gpio / 32); |
paul@233 | 129 | return jz4740_gpio_have_irq(gpio_port_base, gpio % 32); |
paul@197 | 130 | } |
paul@197 | 131 | |
paul@68 | 132 | /* Board startup detection. */ |
paul@68 | 133 | |
paul@195 | 134 | int is_started() |
paul@55 | 135 | { |
paul@230 | 136 | return jz4740_cpm_have_clock((void *) CPM_BASE); |
paul@55 | 137 | } |