2 * Copyright (C) 2013 Broadcom Corporation
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License as
6 * published by the Free Software Foundation version 2.
8 * This program is distributed "as is" WITHOUT ANY WARRANTY of any
9 * kind, whether express or implied; without even the implied warranty
10 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
14 #include <linux/device.h>
15 #include <linux/errno.h>
16 #include <linux/init.h>
18 #include <linux/jiffies.h>
19 #include <linux/of_address.h>
20 #include <linux/of_irq.h>
21 #include <linux/of_platform.h>
22 #include <linux/platform_device.h>
23 #include <linux/printk.h>
24 #include <linux/reboot.h>
25 #include <linux/regmap.h>
26 #include <linux/smp.h>
27 #include <linux/mfd/syscon.h>
29 #include <asm/system_misc.h>
31 #define RESET_SOURCE_ENABLE_REG 1
32 #define SW_MASTER_RESET_REG 2
34 static struct regmap *regmap;
35 static u32 rst_src_en;
36 static u32 sw_mstr_rst;
38 static void brcmstb_reboot(enum reboot_mode mode, const char *cmd)
43 rc = regmap_write(regmap, rst_src_en, 1);
45 pr_err("failed to write rst_src_en (%d)\n", rc);
49 rc = regmap_read(regmap, rst_src_en, &tmp);
51 pr_err("failed to read rst_src_en (%d)\n", rc);
55 rc = regmap_write(regmap, sw_mstr_rst, 1);
57 pr_err("failed to write sw_mstr_rst (%d)\n", rc);
61 rc = regmap_read(regmap, sw_mstr_rst, &tmp);
63 pr_err("failed to read sw_mstr_rst (%d)\n", rc);
71 static int brcmstb_reboot_probe(struct platform_device *pdev)
74 struct device_node *np = pdev->dev.of_node;
76 regmap = syscon_regmap_lookup_by_phandle(np, "syscon");
78 pr_err("failed to get syscon phandle\n");
82 rc = of_property_read_u32_index(np, "syscon", RESET_SOURCE_ENABLE_REG,
85 pr_err("can't get rst_src_en offset (%d)\n", rc);
89 rc = of_property_read_u32_index(np, "syscon", SW_MASTER_RESET_REG,
92 pr_err("can't get sw_mstr_rst offset (%d)\n", rc);
96 arm_pm_restart = brcmstb_reboot;
101 static const struct of_device_id of_match[] = {
102 { .compatible = "brcm,brcmstb-reboot", },
106 static struct platform_driver brcmstb_reboot_driver = {
107 .probe = brcmstb_reboot_probe,
109 .name = "brcmstb-reboot",
110 .owner = THIS_MODULE,
111 .of_match_table = of_match,
115 static int __init brcmstb_reboot_init(void)
117 return platform_driver_probe(&brcmstb_reboot_driver,
118 brcmstb_reboot_probe);
120 subsys_initcall(brcmstb_reboot_init);