blob: 8e738266a66a9571f99405b19552f88fe4ab9133 [file] [log] [blame]
Thomas Gleixnerd2912cb2019-06-04 10:11:33 +02001// SPDX-License-Identifier: GPL-2.0-only
Jamie Ilesaf756552011-07-25 17:36:42 +01002/*
3 * Copyright (c) 2011 Picochip Ltd., Jamie Iles
4 *
Jamie Ilesaf756552011-07-25 17:36:42 +01005 * All enquiries to support@picochip.com
6 */
Jamie Iles1b46f872011-12-17 13:42:37 +00007#include <linux/delay.h>
Jamie Ilesaf756552011-07-25 17:36:42 +01008#include <linux/of.h>
9#include <linux/of_address.h>
Robin Holt7b6d8642013-07-08 16:01:40 -070010#include <linux/reboot.h>
Jamie Ilesaf756552011-07-25 17:36:42 +010011
12#include <asm/mach/arch.h>
Jamie Iles8f37a0b2011-12-12 20:21:39 +000013#include <asm/mach/map.h>
Jamie Ilesaf756552011-07-25 17:36:42 +010014
Rob Herring06413f12012-08-27 00:38:35 -050015#define PHYS_TO_IO(x) (((x) & 0x00ffffff) | 0xfe000000)
16#define PICOXCELL_PERIPH_BASE 0x80000000
17#define PICOXCELL_PERIPH_LENGTH SZ_4M
18
19#define WDT_CTRL_REG_EN_MASK (1 << 0)
20#define WDT_CTRL_REG_OFFS (0x00)
21#define WDT_TIMEOUT_REG_OFFS (0x04)
Jamie Iles1b46f872011-12-17 13:42:37 +000022static void __iomem *wdt_regs;
23
24/*
25 * The machine restart method can be called from an atomic context so we won't
26 * be able to ioremap the regs then.
27 */
28static void picoxcell_setup_restart(void)
29{
30 struct device_node *np = of_find_compatible_node(NULL, NULL,
31 "snps,dw-apb-wdg");
32 if (WARN(!np, "unable to setup watchdog restart"))
33 return;
34
35 wdt_regs = of_iomap(np, 0);
36 WARN(!wdt_regs, "failed to remap watchdog regs");
37}
38
Jamie Iles8f37a0b2011-12-12 20:21:39 +000039static 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,
43 .type = MT_DEVICE,
44};
45
46static void __init picoxcell_map_io(void)
47{
48 iotable_init(&io_map, 1);
49}
50
Jamie Ilesaf756552011-07-25 17:36:42 +010051static void __init picoxcell_init_machine(void)
52{
Jamie Iles1b46f872011-12-17 13:42:37 +000053 picoxcell_setup_restart();
Jamie Ilesaf756552011-07-25 17:36:42 +010054}
55
56static const char *picoxcell_dt_match[] = {
57 "picochip,pc3x2",
58 "picochip,pc3x3",
59 NULL
60};
61
Robin Holt7b6d8642013-07-08 16:01:40 -070062static void picoxcell_wdt_restart(enum reboot_mode mode, const char *cmd)
Jamie Iles1b46f872011-12-17 13:42:37 +000063{
64 /*
65 * Configure the watchdog to reset with the shortest possible timeout
66 * and give it chance to do the reset.
67 */
68 if (wdt_regs) {
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. */
72 mdelay(500);
73 }
74}
75
Jamie Ilesaf756552011-07-25 17:36:42 +010076DT_MACHINE_START(PICOXCELL, "Picochip picoXcell")
77 .map_io = picoxcell_map_io,
Jamie Ilesaf756552011-07-25 17:36:42 +010078 .init_machine = picoxcell_init_machine,
79 .dt_compat = picoxcell_dt_match,
Jamie Iles1b46f872011-12-17 13:42:37 +000080 .restart = picoxcell_wdt_restart,
Jamie Ilesaf756552011-07-25 17:36:42 +010081MACHINE_END