picoxcell: remove redundant common.h
[sfrench/cifs-2.6.git] / arch / arm / mach-picoxcell / common.c
1 /*
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  */
10 #include <linux/delay.h>
11 #include <linux/irq.h>
12 #include <linux/irqchip.h>
13 #include <linux/irqdomain.h>
14 #include <linux/of.h>
15 #include <linux/of_address.h>
16 #include <linux/of_irq.h>
17 #include <linux/of_platform.h>
18 #include <linux/dw_apb_timer.h>
19
20 #include <asm/mach/arch.h>
21 #include <asm/mach/map.h>
22
23 #define PHYS_TO_IO(x)                   (((x) & 0x00ffffff) | 0xfe000000)
24 #define PICOXCELL_PERIPH_BASE           0x80000000
25 #define PICOXCELL_PERIPH_LENGTH         SZ_4M
26
27 #define WDT_CTRL_REG_EN_MASK            (1 << 0)
28 #define WDT_CTRL_REG_OFFS               (0x00)
29 #define WDT_TIMEOUT_REG_OFFS            (0x04)
30 static 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  */
36 static 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
47 static 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
54 static void __init picoxcell_map_io(void)
55 {
56         iotable_init(&io_map, 1);
57 }
58
59 static void __init picoxcell_init_machine(void)
60 {
61         of_platform_populate(NULL, of_default_bus_match_table, NULL, NULL);
62         picoxcell_setup_restart();
63 }
64
65 static const char *picoxcell_dt_match[] = {
66         "picochip,pc3x2",
67         "picochip,pc3x3",
68         NULL
69 };
70
71 static void picoxcell_wdt_restart(char mode, const char *cmd)
72 {
73         /*
74          * Configure the watchdog to reset with the shortest possible timeout
75          * and give it chance to do the reset.
76          */
77         if (wdt_regs) {
78                 writel_relaxed(WDT_CTRL_REG_EN_MASK, wdt_regs + WDT_CTRL_REG_OFFS);
79                 writel_relaxed(0, wdt_regs + WDT_TIMEOUT_REG_OFFS);
80                 /* No sleeping, possibly atomic. */
81                 mdelay(500);
82         }
83 }
84
85 DT_MACHINE_START(PICOXCELL, "Picochip picoXcell")
86         .map_io         = picoxcell_map_io,
87         .nr_irqs        = NR_IRQS_LEGACY,
88         .init_irq       = irqchip_init,
89         .init_time      = dw_apb_timer_init,
90         .init_machine   = picoxcell_init_machine,
91         .dt_compat      = picoxcell_dt_match,
92         .restart        = picoxcell_wdt_restart,
93 MACHINE_END