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