| 1 | /* |
| 2 | * This program is free software; you can redistribute it and/or modify it |
| 3 | * under the terms of the GNU General Public License version 2 as published |
| 4 | * by the Free Software Foundation. |
| 5 | * |
| 6 | * Copyright (C) 2010 John Crispin <blogic@openwrt.org> |
| 7 | */ |
| 8 | |
| 9 | #include <linux/init.h> |
| 10 | #include <linux/io.h> |
| 11 | #include <linux/ioport.h> |
| 12 | #include <linux/pm.h> |
| 13 | #include <linux/module.h> |
| 14 | #include <asm/reboot.h> |
| 15 | |
| 16 | #include <lantiq_soc.h> |
| 17 | #include "../machtypes.h" |
| 18 | #include <base_reg.h> |
| 19 | #include <sys1_reg.h> |
| 20 | #include <boot_reg.h> |
| 21 | #include <ebu_reg.h> |
| 22 | |
| 23 | static struct svip_reg_sys1 *const sys1 = (struct svip_reg_sys1 *)LTQ_SYS1_BASE; |
| 24 | static struct svip_reg_ebu *const ebu = (struct svip_reg_ebu *)LTQ_EBU_BASE; |
| 25 | |
| 26 | #define CPLD_CMDREG3 ((volatile unsigned char*)(KSEG1 + 0x120000f3)) |
| 27 | extern void switchip_reset(void); |
| 28 | |
| 29 | static void ltq_machine_restart(char *command) |
| 30 | { |
| 31 | printk(KERN_NOTICE "System restart\n"); |
| 32 | local_irq_disable(); |
| 33 | |
| 34 | if (mips_machtype == LANTIQ_MACH_EASY33016 || |
| 35 | mips_machtype == LANTIQ_MACH_EASY336) { |
| 36 | /* We just use the CPLD function to reset the entire system as a |
| 37 | workaround for the switch reset problem */ |
| 38 | local_irq_disable(); |
| 39 | ebu_w32(0x120000f1, addr_sel_2); |
| 40 | ebu_w32(0x404027ff, con_2); |
| 41 | |
| 42 | if (mips_machtype == LANTIQ_MACH_EASY336) |
| 43 | /* set bit 0 to reset SVIP */ |
| 44 | *CPLD_CMDREG3 = (1<<0); |
| 45 | else |
| 46 | /* set bit 7 to reset SVIP, set bit 3 to reset xT */ |
| 47 | *CPLD_CMDREG3 = (1<<7) | (1<<3); |
| 48 | } else { |
| 49 | *LTQ_BOOT_RVEC(0) = 0; |
| 50 | /* reset all except PER, SUBSYS and CPU0 */ |
| 51 | sys1_w32(0x00043F3E, rreqr); |
| 52 | /* release WDT0 reset */ |
| 53 | sys1_w32(0x00000100, rrlsr); |
| 54 | /* restore reset value for clock enables */ |
| 55 | sys1_w32(~0x0c000040, clkclr); |
| 56 | /* reset SUBSYS (incl. DDR2) and CPU0 */ |
| 57 | sys1_w32(0x00030001, rbtr); |
| 58 | } |
| 59 | |
| 60 | for (;;) |
| 61 | ; |
| 62 | } |
| 63 | |
| 64 | static void ltq_machine_halt(void) |
| 65 | { |
| 66 | printk(KERN_NOTICE "System halted.\n"); |
| 67 | local_irq_disable(); |
| 68 | for (;;) |
| 69 | ; |
| 70 | } |
| 71 | |
| 72 | static void ltq_machine_power_off(void) |
| 73 | { |
| 74 | printk(KERN_NOTICE "Please turn off the power now.\n"); |
| 75 | local_irq_disable(); |
| 76 | for (;;) |
| 77 | ; |
| 78 | } |
| 79 | |
| 80 | /* This function is used by the watchdog driver */ |
| 81 | int ltq_reset_cause(void) |
| 82 | { |
| 83 | return 0; |
| 84 | } |
| 85 | EXPORT_SYMBOL_GPL(ltq_reset_cause); |
| 86 | |
| 87 | static int __init mips_reboot_setup(void) |
| 88 | { |
| 89 | _machine_restart = ltq_machine_restart; |
| 90 | _machine_halt = ltq_machine_halt; |
| 91 | pm_power_off = ltq_machine_power_off; |
| 92 | return 0; |
| 93 | } |
| 94 | |
| 95 | arch_initcall(mips_reboot_setup); |
| 96 | |