blob: 8f9a0b47a7fa8293860036c09516854109a310f1 [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>
Dinh Nguyencfda5902012-07-11 15:13:16 -050017#include <linux/dw_apb_timer.h>
Jamie Ilesaf756552011-07-25 17:36:42 +010018
19#include <asm/mach/arch.h>
20#include <asm/hardware/vic.h>
Jamie Iles8f37a0b2011-12-12 20:21:39 +000021#include <asm/mach/map.h>
Jamie Ilesaf756552011-07-25 17:36:42 +010022
23#include <mach/map.h>
24#include <mach/picoxcell_soc.h>
25
26#include "common.h"
27
Jamie Iles1b46f872011-12-17 13:42:37 +000028#define WDT_CTRL_REG_EN_MASK (1 << 0)
29#define WDT_CTRL_REG_OFFS (0x00)
30#define WDT_TIMEOUT_REG_OFFS (0x04)
31static void __iomem *wdt_regs;
32
33/*
34 * The machine restart method can be called from an atomic context so we won't
35 * be able to ioremap the regs then.
36 */
37static void picoxcell_setup_restart(void)
38{
39 struct device_node *np = of_find_compatible_node(NULL, NULL,
40 "snps,dw-apb-wdg");
41 if (WARN(!np, "unable to setup watchdog restart"))
42 return;
43
44 wdt_regs = of_iomap(np, 0);
45 WARN(!wdt_regs, "failed to remap watchdog regs");
46}
47
Jamie Iles8f37a0b2011-12-12 20:21:39 +000048static struct map_desc io_map __initdata = {
49 .virtual = PHYS_TO_IO(PICOXCELL_PERIPH_BASE),
50 .pfn = __phys_to_pfn(PICOXCELL_PERIPH_BASE),
51 .length = PICOXCELL_PERIPH_LENGTH,
52 .type = MT_DEVICE,
53};
54
55static void __init picoxcell_map_io(void)
56{
57 iotable_init(&io_map, 1);
58}
59
Jamie Ilesaf756552011-07-25 17:36:42 +010060static void __init picoxcell_init_machine(void)
61{
62 of_platform_populate(NULL, of_default_bus_match_table, NULL, NULL);
Jamie Iles1b46f872011-12-17 13:42:37 +000063 picoxcell_setup_restart();
Jamie Ilesaf756552011-07-25 17:36:42 +010064}
65
66static const char *picoxcell_dt_match[] = {
67 "picochip,pc3x2",
68 "picochip,pc3x3",
69 NULL
70};
71
72static const struct of_device_id vic_of_match[] __initconst = {
Jamie Ilesc05012c2011-11-03 17:29:03 +000073 { .compatible = "arm,pl192-vic", .data = vic_of_init, },
Jamie Ilesaf756552011-07-25 17:36:42 +010074 { /* Sentinel */ }
75};
76
77static void __init picoxcell_init_irq(void)
78{
Jamie Ilesc05012c2011-11-03 17:29:03 +000079 of_irq_init(vic_of_match);
Jamie Ilesaf756552011-07-25 17:36:42 +010080}
81
Jamie Iles1b46f872011-12-17 13:42:37 +000082static void picoxcell_wdt_restart(char mode, const char *cmd)
83{
84 /*
85 * Configure the watchdog to reset with the shortest possible timeout
86 * and give it chance to do the reset.
87 */
88 if (wdt_regs) {
89 writel_relaxed(WDT_CTRL_REG_EN_MASK, wdt_regs + WDT_CTRL_REG_OFFS);
90 writel_relaxed(0, wdt_regs + WDT_TIMEOUT_REG_OFFS);
91 /* No sleeping, possibly atomic. */
92 mdelay(500);
93 }
94}
95
Jamie Ilesaf756552011-07-25 17:36:42 +010096DT_MACHINE_START(PICOXCELL, "Picochip picoXcell")
97 .map_io = picoxcell_map_io,
Jamie Iles98e27a52011-12-12 20:17:37 +000098 .nr_irqs = NR_IRQS_LEGACY,
Jamie Ilesaf756552011-07-25 17:36:42 +010099 .init_irq = picoxcell_init_irq,
Jamie Ilesc05012c2011-11-03 17:29:03 +0000100 .handle_irq = vic_handle_irq,
Dinh Nguyencfda5902012-07-11 15:13:16 -0500101 .timer = &dw_apb_timer,
Jamie Ilesaf756552011-07-25 17:36:42 +0100102 .init_machine = picoxcell_init_machine,
103 .dt_compat = picoxcell_dt_match,
Jamie Iles1b46f872011-12-17 13:42:37 +0000104 .restart = picoxcell_wdt_restart,
Jamie Ilesaf756552011-07-25 17:36:42 +0100105MACHINE_END