NanoPayload

stage2/board-minipc.c

216:95be7694d999
2017-06-28 Paul Boddie Employ structure member names to make initialisation clearer.
     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 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 cpm_init()    63 {    64 	__cpm_stop_all();    65 }    66     67 void rtc_init()    68 {    69 	/* NOTE: May only be accessible via I2C. */    70 }    71     72 /* Timer routines. */    73     74 unsigned long timestamp;    75 unsigned long lastdec;    76     77 /*    78  * Timer without interrupts.    79  */    80     81 int timer_init()    82 {    83         __ost_set_clock(TIMER_CHAN, OST_TCSR_CKS_PCLK_256);    84         __ost_set_reload(TIMER_CHAN, TIMER_FDATA);    85         __ost_set_count(TIMER_CHAN, TIMER_FDATA);    86         __ost_enable_channel(TIMER_CHAN);    87     88 	__cpm_start_ost();    89     90         lastdec = TIMER_FDATA;    91         timestamp = 0;    92     93         return 0;    94 }    95     96 /* Timer interrupt activation. */    97     98 void timer_init_irq()    99 {   100 	__ost_enable_interrupt(TIMER_CHAN);   101 	/* NOTE: Need flag clearing? */   102 	__intc_unmask_irq(TIMER_CHAN_IRQ);   103 }   104    105 void timer_clear()   106 {   107 	__intc_ack_irq(TIMER_CHAN_IRQ);   108 	__ost_clear_uf(TIMER_CHAN);   109 }   110    111 /* GPIO interrupt activation. */   112    113 void gpio_init_irq()   114 {   115 	__gpio_as_irq_low_level(GPIO_POWER);   116 	__intc_unmask_irq(GPIO_IRQ);   117 }   118    119 int gpio_have_irq(u8 gpio)   120 {   121 	return (REG_GPIO_GPFR(gpio / 32) & (1 << (gpio % 32)));   122 }   123    124 /* Board startup detection. */   125    126 int is_started()   127 {   128 	return REG_CPM_MSCR != 0;   129 }