1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copyright (c) 2011 Picochip Ltd., Jamie Iles
5 * All enquiries to support@picochip.com
7 #include <linux/delay.h>
9 #include <linux/of_address.h>
10 #include <linux/reboot.h>
12 #include <asm/mach/arch.h>
13 #include <asm/mach/map.h>
15 #define PHYS_TO_IO(x) (((x) & 0x00ffffff) | 0xfe000000)
16 #define PICOXCELL_PERIPH_BASE 0x80000000
17 #define PICOXCELL_PERIPH_LENGTH SZ_4M
19 #define WDT_CTRL_REG_EN_MASK (1 << 0)
20 #define WDT_CTRL_REG_OFFS (0x00)
21 #define WDT_TIMEOUT_REG_OFFS (0x04)
22 static void __iomem
*wdt_regs
;
25 * The machine restart method can be called from an atomic context so we won't
26 * be able to ioremap the regs then.
28 static void picoxcell_setup_restart(void)
30 struct device_node
*np
= of_find_compatible_node(NULL
, NULL
,
32 if (WARN(!np
, "unable to setup watchdog restart"))
35 wdt_regs
= of_iomap(np
, 0);
36 WARN(!wdt_regs
, "failed to remap watchdog regs");
39 static struct map_desc io_map __initdata
= {
40 .virtual = PHYS_TO_IO(PICOXCELL_PERIPH_BASE
),
41 .pfn
= __phys_to_pfn(PICOXCELL_PERIPH_BASE
),
42 .length
= PICOXCELL_PERIPH_LENGTH
,
46 static void __init
picoxcell_map_io(void)
48 iotable_init(&io_map
, 1);
51 static void __init
picoxcell_init_machine(void)
53 picoxcell_setup_restart();
56 static const char *picoxcell_dt_match
[] = {
62 static void picoxcell_wdt_restart(enum reboot_mode mode
, const char *cmd
)
65 * Configure the watchdog to reset with the shortest possible timeout
66 * and give it chance to do the reset.
69 writel_relaxed(WDT_CTRL_REG_EN_MASK
, wdt_regs
+ WDT_CTRL_REG_OFFS
);
70 writel_relaxed(0, wdt_regs
+ WDT_TIMEOUT_REG_OFFS
);
71 /* No sleeping, possibly atomic. */
76 DT_MACHINE_START(PICOXCELL
, "Picochip picoXcell")
77 .map_io
= picoxcell_map_io
,
78 .init_machine
= picoxcell_init_machine
,
79 .dt_compat
= picoxcell_dt_match
,
80 .restart
= picoxcell_wdt_restart
,