[lantiq] cleanup patches
[openwrt.git] / target / linux / lantiq / files / arch / mips / lantiq / falcon / reset.c
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) 2011 Thomas Langer <thomas.langer@lantiq.com>
7  * Copyright (C) 2011 John Crispin <blogic@openwrt.org>
8  */
9
10 #include <linux/init.h>
11 #include <linux/io.h>
12 #include <linux/pm.h>
13 #include <asm/reboot.h>
14 #include <linux/export.h>
15
16 #include <lantiq_soc.h>
17
18 /* CPU0 Reset Source Register */
19 #define LTQ_SYS1_CPU0RS         0x0040
20 /* reset cause mask */
21 #define LTQ_CPU0RS_MASK         0x0003
22
23 int
24 ltq_reset_cause(void)
25 {
26         return ltq_sys1_r32(LTQ_SYS1_CPU0RS) & LTQ_CPU0RS_MASK;
27 }
28 EXPORT_SYMBOL_GPL(ltq_reset_cause);
29
30 #define BOOT_REG_BASE   (KSEG1 | 0x1F200000)
31 #define BOOT_PW1_REG    (BOOT_REG_BASE | 0x20)
32 #define BOOT_PW2_REG    (BOOT_REG_BASE | 0x24)
33 #define BOOT_PW1        0x4C545100
34 #define BOOT_PW2        0x0051544C
35
36 #define WDT_REG_BASE    (KSEG1 | 0x1F8803F0)
37 #define WDT_PW1         0x00BE0000
38 #define WDT_PW2         0x00DC0000
39
40 static void
41 ltq_machine_restart(char *command)
42 {
43         pr_notice("System restart\n");
44         local_irq_disable();
45
46         /* reboot magic */
47         ltq_w32(BOOT_PW1, (void *)BOOT_PW1_REG); /* 'LTQ\0' */
48         ltq_w32(BOOT_PW2, (void *)BOOT_PW2_REG); /* '\0QTL' */
49         ltq_w32(0, (void *)BOOT_REG_BASE); /* reset Bootreg RVEC */
50
51         /* watchdog magic */
52         ltq_w32(WDT_PW1, (void *)WDT_REG_BASE);
53         ltq_w32(WDT_PW2 |
54                 (0x3 << 26) | /* PWL */
55                 (0x2 << 24) | /* CLKDIV */
56                 (0x1 << 31) | /* enable */
57                 (1), /* reload */
58                 (void *)WDT_REG_BASE);
59         unreachable();
60 }
61
62 static void
63 ltq_machine_halt(void)
64 {
65         pr_notice("System halted.\n");
66         local_irq_disable();
67         unreachable();
68 }
69
70 static void
71 ltq_machine_power_off(void)
72 {
73         pr_notice("Please turn off the power now.\n");
74         local_irq_disable();
75         unreachable();
76 }
77
78 static int __init
79 mips_reboot_setup(void)
80 {
81         _machine_restart = ltq_machine_restart;
82         _machine_halt = ltq_machine_halt;
83         pm_power_off = ltq_machine_power_off;
84         return 0;
85 }
86
87 arch_initcall(mips_reboot_setup);