blob: a2e8ae8b58214d6e702984e8b749b03ce3878acf [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/irq.h>
12#include <linux/irqdomain.h>
13#include <linux/of.h>
14#include <linux/of_address.h>
Jamie Ilesc05012c2011-11-03 17:29:03 +000015#include <linux/of_irq.h>
Jamie Ilesaf756552011-07-25 17:36:42 +010016#include <linux/of_platform.h>
17
18#include <asm/mach/arch.h>
19#include <asm/hardware/vic.h>
Jamie Iles8f37a0b2011-12-12 20:21:39 +000020#include <asm/mach/map.h>
Jamie Ilesaf756552011-07-25 17:36:42 +010021
22#include <mach/map.h>
23#include <mach/picoxcell_soc.h>
24
25#include "common.h"
26
Jamie Iles1b46f872011-12-17 13:42:37 +000027#define WDT_CTRL_REG_EN_MASK (1 << 0)
28#define WDT_CTRL_REG_OFFS (0x00)
29#define WDT_TIMEOUT_REG_OFFS (0x04)
30static void __iomem *wdt_regs;
31
32/*
33 * The machine restart method can be called from an atomic context so we won't
34 * be able to ioremap the regs then.
35 */
36static void picoxcell_setup_restart(void)
37{
38 struct device_node *np = of_find_compatible_node(NULL, NULL,
39 "snps,dw-apb-wdg");
40 if (WARN(!np, "unable to setup watchdog restart"))
41 return;
42
43 wdt_regs = of_iomap(np, 0);
44 WARN(!wdt_regs, "failed to remap watchdog regs");
45}
46
Jamie Iles8f37a0b2011-12-12 20:21:39 +000047static struct map_desc io_map __initdata = {
48 .virtual = PHYS_TO_IO(PICOXCELL_PERIPH_BASE),
49 .pfn = __phys_to_pfn(PICOXCELL_PERIPH_BASE),
50 .length = PICOXCELL_PERIPH_LENGTH,
51 .type = MT_DEVICE,
52};
53
54static void __init picoxcell_map_io(void)
55{
56 iotable_init(&io_map, 1);
57}
58
Jamie Ilesaf756552011-07-25 17:36:42 +010059static void __init picoxcell_init_machine(void)
60{
61 of_platform_populate(NULL, of_default_bus_match_table, NULL, NULL);
Jamie Iles1b46f872011-12-17 13:42:37 +000062 picoxcell_setup_restart();
Jamie Ilesaf756552011-07-25 17:36:42 +010063}
64
65static const char *picoxcell_dt_match[] = {
66 "picochip,pc3x2",
67 "picochip,pc3x3",
68 NULL
69};
70
71static const struct of_device_id vic_of_match[] __initconst = {
Jamie Ilesc05012c2011-11-03 17:29:03 +000072 { .compatible = "arm,pl192-vic", .data = vic_of_init, },
Jamie Ilesaf756552011-07-25 17:36:42 +010073 { /* Sentinel */ }
74};
75
76static void __init picoxcell_init_irq(void)
77{
Jamie Ilesc05012c2011-11-03 17:29:03 +000078 of_irq_init(vic_of_match);
Jamie Ilesaf756552011-07-25 17:36:42 +010079}
80
Jamie Iles1b46f872011-12-17 13:42:37 +000081static void picoxcell_wdt_restart(char mode, const char *cmd)
82{
83 /*
84 * Configure the watchdog to reset with the shortest possible timeout
85 * and give it chance to do the reset.
86 */
87 if (wdt_regs) {
88 writel_relaxed(WDT_CTRL_REG_EN_MASK, wdt_regs + WDT_CTRL_REG_OFFS);
89 writel_relaxed(0, wdt_regs + WDT_TIMEOUT_REG_OFFS);
90 /* No sleeping, possibly atomic. */
91 mdelay(500);
92 }
93}
94
Jamie Ilesaf756552011-07-25 17:36:42 +010095DT_MACHINE_START(PICOXCELL, "Picochip picoXcell")
96 .map_io = picoxcell_map_io,
Jamie Iles98e27a52011-12-12 20:17:37 +000097 .nr_irqs = NR_IRQS_LEGACY,
Jamie Ilesaf756552011-07-25 17:36:42 +010098 .init_irq = picoxcell_init_irq,
Jamie Ilesc05012c2011-11-03 17:29:03 +000099 .handle_irq = vic_handle_irq,
Jamie Ilesaf756552011-07-25 17:36:42 +0100100 .timer = &picoxcell_timer,
101 .init_machine = picoxcell_init_machine,
102 .dt_compat = picoxcell_dt_match,
Jamie Iles1b46f872011-12-17 13:42:37 +0000103 .restart = picoxcell_wdt_restart,
Jamie Ilesaf756552011-07-25 17:36:42 +0100104MACHINE_END