2009-09-27 11:23:33 +03:00
|
|
|
#pypp 0
|
2013-05-12 16:46:11 +03:00
|
|
|
// vim: set filetype=cpp ://
|
2009-09-27 11:23:33 +03:00
|
|
|
// Iris: micro-kernel for a capability-based operating system.
|
|
|
|
// mips/nanonote/board.ccp: nanonote-specific definitions.
|
|
|
|
// Copyright 2009 Bas Wijnen <wijnen@debian.org>
|
|
|
|
//
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
#define ARCH
|
|
|
|
#define INIT
|
|
|
|
#include "kernel.hh"
|
|
|
|
|
|
|
|
void board_init ():
|
2009-09-27 22:14:38 +03:00
|
|
|
pll_init ()
|
2013-05-15 01:30:50 +03:00
|
|
|
// Stop all clocks, except the RTC and timer interrupt source.
|
|
|
|
CPM_CLKGR = 0x7fff & ~(CPM_CLKGR_RTC | CPM_CLKGR_TCU)
|
|
|
|
// Make sure the rtc is able to boot the device.
|
|
|
|
while !rtc_write_ready ():
|
|
|
|
rtc_enabled ()
|
|
|
|
while !rtc_write_ready ():
|
|
|
|
// Set wakeup assertion time, so it actually wakes up.
|
|
|
|
rtc_set_hrcr_val (0xfe0)
|
|
|
|
while !rtc_write_ready ():
|
|
|
|
// Set glitch detection to a low value.
|
|
|
|
rtc_set_hwfcr_val (0x1e0)
|
|
|
|
while !rtc_write_ready ():
|
|
|
|
// Allow rtc alarm to wake up device.
|
|
|
|
rtc_enable_alarm_wakeup ()
|
|
|
|
while !rtc_write_ready ():
|
2009-12-18 10:00:38 +02:00
|
|
|
// sdram memory.
|
2009-09-27 11:23:33 +03:00
|
|
|
gpio_as_sdram_16bit ()
|
2009-12-18 10:00:38 +02:00
|
|
|
// flash memory.
|
2009-09-27 11:23:33 +03:00
|
|
|
gpio_as_nand ()
|
2009-12-18 10:00:38 +02:00
|
|
|
// sound controller.
|
2009-09-27 11:23:33 +03:00
|
|
|
gpio_as_aic ()
|
2009-12-18 10:00:38 +02:00
|
|
|
// micro-sd controller.
|
2009-09-27 11:23:33 +03:00
|
|
|
gpio_as_msc ()
|
2009-12-18 10:00:38 +02:00
|
|
|
// display.
|
2009-10-31 10:32:23 +02:00
|
|
|
gpio_as_lcd_16bit ()
|
2009-12-18 10:00:38 +02:00
|
|
|
// buzzer.
|
2009-12-11 10:43:42 +02:00
|
|
|
gpio_as_pwm4 ()
|
2009-10-31 10:32:23 +02:00
|
|
|
// Set up memory.
|
2013-05-12 16:46:11 +03:00
|
|
|
setup_sdram ()
|
2009-10-31 10:32:23 +02:00
|
|
|
// Use some gpio pins for lcd.
|
|
|
|
gpio_as_gpio (2, (1 << 21) | (1 << 22) | (1 << 23))
|
|
|
|
gpio_as_output (2, (1 << 21) | (1 << 22) | (1 << 23))
|
2010-05-15 19:42:17 +03:00
|
|
|
// And some for sd/mmc.
|
|
|
|
gpio_as_gpio (3, (1 << 0) | (1 << 2))
|
|
|
|
gpio_as_output (3, 1 << 2)
|
|
|
|
gpio_as_input (3, 1 << 0)
|
|
|
|
gpio_disable_pull (3, (1 << 0) | (1 << 2))
|
|
|
|
// Disable power to sd/mmc by default.
|
|
|
|
gpio_set (3, 1 << 2)
|
2009-09-27 11:23:33 +03:00
|
|
|
// Set up keyboard: this breaks uart receive.
|
|
|
|
gpio_as_gpio (3, 0x05fc0000)
|
2009-12-11 10:43:42 +02:00
|
|
|
// Set up timed interrupts.
|
2013-05-12 16:46:11 +03:00
|
|
|
tcu_start_timer_clock (0)
|
2009-09-27 11:23:33 +03:00
|
|
|
tcu_stop_counter (0)
|
|
|
|
tcu_select_extalclk (0)
|
2009-09-30 00:48:33 +03:00
|
|
|
tcu_select_clk_div4 (0)
|
2009-09-27 11:23:33 +03:00
|
|
|
tcu_disable_pwm_output (0)
|
2009-09-30 00:48:33 +03:00
|
|
|
tcu_set_full_data (0, JZ_EXTAL / HZ / 4)
|
2009-09-27 11:23:33 +03:00
|
|
|
tcu_mask_half_match_irq (0)
|
|
|
|
tcu_clear_full_match_flag (0)
|
|
|
|
tcu_unmask_full_match_irq (0)
|
|
|
|
tcu_start_counter (0)
|
2009-12-18 10:00:38 +02:00
|
|
|
#ifndef NDEBUG
|
2011-01-15 03:10:46 +02:00
|
|
|
setup_uart ()
|
2010-01-24 22:34:24 +02:00
|
|
|
kdebug ("\n\nSerial port initialized\n")
|
2009-12-18 10:00:38 +02:00
|
|
|
#endif
|
2009-10-31 10:32:23 +02:00
|
|
|
|
2010-08-22 23:03:06 +03:00
|
|
|
static void sync_serial ():
|
|
|
|
#ifndef NDEBUG
|
2009-10-31 10:32:23 +02:00
|
|
|
// Wait for serial port to be done.
|
|
|
|
while !(UART0_LSR & UARTLSR_TEMT):
|
2010-08-22 23:03:06 +03:00
|
|
|
#endif
|
|
|
|
|
|
|
|
void arch_reboot ():
|
|
|
|
sync_serial ()
|
2009-10-31 10:32:23 +02:00
|
|
|
// Reboot.
|
|
|
|
wdt_select_extalclk ()
|
|
|
|
wdt_select_clk_div1 ()
|
|
|
|
wdt_set_data (1)
|
|
|
|
wdt_set_count (0)
|
|
|
|
wdt_start ()
|
|
|
|
// Wait for wdt to trigger reboot.
|
|
|
|
while true:
|
2010-08-10 11:09:50 +03:00
|
|
|
|
|
|
|
void arch_poweroff ():
|
2013-05-15 01:30:50 +03:00
|
|
|
// Make sure the rtc is running; it wakes the device up.
|
2010-08-10 11:09:50 +03:00
|
|
|
cpm_start_rtc ()
|
|
|
|
while !rtc_write_ready ():
|
|
|
|
rtc_enabled ()
|
|
|
|
while !rtc_write_ready ():
|
2013-05-15 01:30:50 +03:00
|
|
|
rtc_set_hwfcr_val (0x1e0)
|
|
|
|
while !rtc_write_ready ():
|
2013-05-12 16:46:11 +03:00
|
|
|
rtc_set_hrcr_val (0x7f)
|
|
|
|
while !rtc_write_ready ():
|
2012-09-26 20:03:36 +03:00
|
|
|
kdebug ("Power down.\n")
|
|
|
|
sync_serial ()
|
2010-08-10 11:09:50 +03:00
|
|
|
rtc_power_down ()
|
|
|
|
// Wait for power down to work.
|
2012-09-26 20:03:36 +03:00
|
|
|
while true:
|
|
|
|
asm ("wait")
|
|
|
|
|
|
|
|
void arch_suspend ():
|
|
|
|
sync_serial ()
|
|
|
|
// Suspend the system: go into SLEEP mode.
|
|
|
|
cpm_sleep_mode ()
|
|
|
|
asm ("wait")
|
|
|
|
cpm_idle_mode ()
|
2010-08-22 23:03:06 +03:00
|
|
|
|
2010-08-24 00:55:51 +03:00
|
|
|
// Boot into another kernel.
|
|
|
|
void arch_boot (unsigned address, unsigned arg):
|
2010-08-22 23:03:06 +03:00
|
|
|
sync_serial ()
|
|
|
|
arch_flush_cache ()
|
2010-08-24 00:55:51 +03:00
|
|
|
((void (*)(unsigned))address) (arg)
|