Jamie Iles | af75655 | 2011-07-25 17:36:42 +0100 | [diff] [blame] | 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 | */ |
Jamie Iles | 1b46f87 | 2011-12-17 13:42:37 +0000 | [diff] [blame] | 10 | #include <linux/delay.h> |
Jamie Iles | af75655 | 2011-07-25 17:36:42 +0100 | [diff] [blame] | 11 | #include <linux/irq.h> |
| 12 | #include <linux/irqdomain.h> |
| 13 | #include <linux/of.h> |
| 14 | #include <linux/of_address.h> |
Jamie Iles | c05012c | 2011-11-03 17:29:03 +0000 | [diff] [blame] | 15 | #include <linux/of_irq.h> |
Jamie Iles | af75655 | 2011-07-25 17:36:42 +0100 | [diff] [blame] | 16 | #include <linux/of_platform.h> |
Dinh Nguyen | cfda590 | 2012-07-11 15:13:16 -0500 | [diff] [blame] | 17 | #include <linux/dw_apb_timer.h> |
Jamie Iles | af75655 | 2011-07-25 17:36:42 +0100 | [diff] [blame] | 18 | |
| 19 | #include <asm/mach/arch.h> |
| 20 | #include <asm/hardware/vic.h> |
Jamie Iles | 8f37a0b | 2011-12-12 20:21:39 +0000 | [diff] [blame] | 21 | #include <asm/mach/map.h> |
Jamie Iles | af75655 | 2011-07-25 17:36:42 +0100 | [diff] [blame] | 22 | |
Jamie Iles | af75655 | 2011-07-25 17:36:42 +0100 | [diff] [blame] | 23 | #include "common.h" |
| 24 | |
Rob Herring | 06413f1 | 2012-08-27 00:38:35 -0500 | [diff] [blame] | 25 | #define PHYS_TO_IO(x) (((x) & 0x00ffffff) | 0xfe000000) |
| 26 | #define PICOXCELL_PERIPH_BASE 0x80000000 |
| 27 | #define PICOXCELL_PERIPH_LENGTH SZ_4M |
| 28 | |
| 29 | #define WDT_CTRL_REG_EN_MASK (1 << 0) |
| 30 | #define WDT_CTRL_REG_OFFS (0x00) |
| 31 | #define WDT_TIMEOUT_REG_OFFS (0x04) |
Jamie Iles | 1b46f87 | 2011-12-17 13:42:37 +0000 | [diff] [blame] | 32 | static void __iomem *wdt_regs; |
| 33 | |
| 34 | /* |
| 35 | * The machine restart method can be called from an atomic context so we won't |
| 36 | * be able to ioremap the regs then. |
| 37 | */ |
| 38 | static void picoxcell_setup_restart(void) |
| 39 | { |
| 40 | struct device_node *np = of_find_compatible_node(NULL, NULL, |
| 41 | "snps,dw-apb-wdg"); |
| 42 | if (WARN(!np, "unable to setup watchdog restart")) |
| 43 | return; |
| 44 | |
| 45 | wdt_regs = of_iomap(np, 0); |
| 46 | WARN(!wdt_regs, "failed to remap watchdog regs"); |
| 47 | } |
| 48 | |
Jamie Iles | 8f37a0b | 2011-12-12 20:21:39 +0000 | [diff] [blame] | 49 | static struct map_desc io_map __initdata = { |
| 50 | .virtual = PHYS_TO_IO(PICOXCELL_PERIPH_BASE), |
| 51 | .pfn = __phys_to_pfn(PICOXCELL_PERIPH_BASE), |
| 52 | .length = PICOXCELL_PERIPH_LENGTH, |
| 53 | .type = MT_DEVICE, |
| 54 | }; |
| 55 | |
| 56 | static void __init picoxcell_map_io(void) |
| 57 | { |
| 58 | iotable_init(&io_map, 1); |
| 59 | } |
| 60 | |
Jamie Iles | af75655 | 2011-07-25 17:36:42 +0100 | [diff] [blame] | 61 | static void __init picoxcell_init_machine(void) |
| 62 | { |
| 63 | of_platform_populate(NULL, of_default_bus_match_table, NULL, NULL); |
Jamie Iles | 1b46f87 | 2011-12-17 13:42:37 +0000 | [diff] [blame] | 64 | picoxcell_setup_restart(); |
Jamie Iles | af75655 | 2011-07-25 17:36:42 +0100 | [diff] [blame] | 65 | } |
| 66 | |
| 67 | static const char *picoxcell_dt_match[] = { |
| 68 | "picochip,pc3x2", |
| 69 | "picochip,pc3x3", |
| 70 | NULL |
| 71 | }; |
| 72 | |
| 73 | static const struct of_device_id vic_of_match[] __initconst = { |
Jamie Iles | c05012c | 2011-11-03 17:29:03 +0000 | [diff] [blame] | 74 | { .compatible = "arm,pl192-vic", .data = vic_of_init, }, |
Jamie Iles | af75655 | 2011-07-25 17:36:42 +0100 | [diff] [blame] | 75 | { /* Sentinel */ } |
| 76 | }; |
| 77 | |
| 78 | static void __init picoxcell_init_irq(void) |
| 79 | { |
Jamie Iles | c05012c | 2011-11-03 17:29:03 +0000 | [diff] [blame] | 80 | of_irq_init(vic_of_match); |
Jamie Iles | af75655 | 2011-07-25 17:36:42 +0100 | [diff] [blame] | 81 | } |
| 82 | |
Jamie Iles | 1b46f87 | 2011-12-17 13:42:37 +0000 | [diff] [blame] | 83 | static void picoxcell_wdt_restart(char mode, const char *cmd) |
| 84 | { |
| 85 | /* |
| 86 | * Configure the watchdog to reset with the shortest possible timeout |
| 87 | * and give it chance to do the reset. |
| 88 | */ |
| 89 | if (wdt_regs) { |
| 90 | writel_relaxed(WDT_CTRL_REG_EN_MASK, wdt_regs + WDT_CTRL_REG_OFFS); |
| 91 | writel_relaxed(0, wdt_regs + WDT_TIMEOUT_REG_OFFS); |
| 92 | /* No sleeping, possibly atomic. */ |
| 93 | mdelay(500); |
| 94 | } |
| 95 | } |
| 96 | |
Jamie Iles | af75655 | 2011-07-25 17:36:42 +0100 | [diff] [blame] | 97 | DT_MACHINE_START(PICOXCELL, "Picochip picoXcell") |
| 98 | .map_io = picoxcell_map_io, |
Jamie Iles | 98e27a5 | 2011-12-12 20:17:37 +0000 | [diff] [blame] | 99 | .nr_irqs = NR_IRQS_LEGACY, |
Jamie Iles | af75655 | 2011-07-25 17:36:42 +0100 | [diff] [blame] | 100 | .init_irq = picoxcell_init_irq, |
Jamie Iles | c05012c | 2011-11-03 17:29:03 +0000 | [diff] [blame] | 101 | .handle_irq = vic_handle_irq, |
Dinh Nguyen | cfda590 | 2012-07-11 15:13:16 -0500 | [diff] [blame] | 102 | .timer = &dw_apb_timer, |
Jamie Iles | af75655 | 2011-07-25 17:36:42 +0100 | [diff] [blame] | 103 | .init_machine = picoxcell_init_machine, |
| 104 | .dt_compat = picoxcell_dt_match, |
Jamie Iles | 1b46f87 | 2011-12-17 13:42:37 +0000 | [diff] [blame] | 105 | .restart = picoxcell_wdt_restart, |
Jamie Iles | af75655 | 2011-07-25 17:36:42 +0100 | [diff] [blame] | 106 | MACHINE_END |