blob: b069fa6bb0e2219ede9c4e6bcd581764c6a778a3 [file] [log] [blame]
Jamie Ilesaf756552011-07-25 17:36:42 +01001/*
2 * Copyright (c) 2011 Picochip Ltd., Jamie Iles
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
7 *
8 * All enquiries to support@picochip.com
9 */
Jamie Iles1b46f872011-12-17 13:42:37 +000010#include <linux/delay.h>
Jamie Ilesaf756552011-07-25 17:36:42 +010011#include <linux/of.h>
12#include <linux/of_address.h>
13#include <linux/of_platform.h>
Dinh Nguyencfda5902012-07-11 15:13:16 -050014#include <linux/dw_apb_timer.h>
Jamie Ilesaf756552011-07-25 17:36:42 +010015
16#include <asm/mach/arch.h>
Jamie Iles8f37a0b2011-12-12 20:21:39 +000017#include <asm/mach/map.h>
Jamie Ilesaf756552011-07-25 17:36:42 +010018
Rob Herring06413f12012-08-27 00:38:35 -050019#define PHYS_TO_IO(x) (((x) & 0x00ffffff) | 0xfe000000)
20#define PICOXCELL_PERIPH_BASE 0x80000000
21#define PICOXCELL_PERIPH_LENGTH SZ_4M
22
23#define WDT_CTRL_REG_EN_MASK (1 << 0)
24#define WDT_CTRL_REG_OFFS (0x00)
25#define WDT_TIMEOUT_REG_OFFS (0x04)
Jamie Iles1b46f872011-12-17 13:42:37 +000026static void __iomem *wdt_regs;
27
28/*
29 * The machine restart method can be called from an atomic context so we won't
30 * be able to ioremap the regs then.
31 */
32static void picoxcell_setup_restart(void)
33{
34 struct device_node *np = of_find_compatible_node(NULL, NULL,
35 "snps,dw-apb-wdg");
36 if (WARN(!np, "unable to setup watchdog restart"))
37 return;
38
39 wdt_regs = of_iomap(np, 0);
40 WARN(!wdt_regs, "failed to remap watchdog regs");
41}
42
Jamie Iles8f37a0b2011-12-12 20:21:39 +000043static struct map_desc io_map __initdata = {
44 .virtual = PHYS_TO_IO(PICOXCELL_PERIPH_BASE),
45 .pfn = __phys_to_pfn(PICOXCELL_PERIPH_BASE),
46 .length = PICOXCELL_PERIPH_LENGTH,
47 .type = MT_DEVICE,
48};
49
50static void __init picoxcell_map_io(void)
51{
52 iotable_init(&io_map, 1);
53}
54
Jamie Ilesaf756552011-07-25 17:36:42 +010055static void __init picoxcell_init_machine(void)
56{
57 of_platform_populate(NULL, of_default_bus_match_table, NULL, NULL);
Jamie Iles1b46f872011-12-17 13:42:37 +000058 picoxcell_setup_restart();
Jamie Ilesaf756552011-07-25 17:36:42 +010059}
60
61static const char *picoxcell_dt_match[] = {
62 "picochip,pc3x2",
63 "picochip,pc3x3",
64 NULL
65};
66
Jamie Iles1b46f872011-12-17 13:42:37 +000067static void picoxcell_wdt_restart(char mode, const char *cmd)
68{
69 /*
70 * Configure the watchdog to reset with the shortest possible timeout
71 * and give it chance to do the reset.
72 */
73 if (wdt_regs) {
74 writel_relaxed(WDT_CTRL_REG_EN_MASK, wdt_regs + WDT_CTRL_REG_OFFS);
75 writel_relaxed(0, wdt_regs + WDT_TIMEOUT_REG_OFFS);
76 /* No sleeping, possibly atomic. */
77 mdelay(500);
78 }
79}
80
Jamie Ilesaf756552011-07-25 17:36:42 +010081DT_MACHINE_START(PICOXCELL, "Picochip picoXcell")
82 .map_io = picoxcell_map_io,
Jamie Iles98e27a52011-12-12 20:17:37 +000083 .nr_irqs = NR_IRQS_LEGACY,
Stephen Warren6bb27d72012-11-08 12:40:59 -070084 .init_time = dw_apb_timer_init,
Jamie Ilesaf756552011-07-25 17:36:42 +010085 .init_machine = picoxcell_init_machine,
86 .dt_compat = picoxcell_dt_match,
Jamie Iles1b46f872011-12-17 13:42:37 +000087 .restart = picoxcell_wdt_restart,
Jamie Ilesaf756552011-07-25 17:36:42 +010088MACHINE_END