1 // SPDX-License-Identifier: GPL-2.0-only
2 // Copyright (C) 2013 Broadcom Corporation
4 #include <linux/bitops.h>
5 #include <linux/device.h>
6 #include <linux/errno.h>
7 #include <linux/init.h>
9 #include <linux/jiffies.h>
10 #include <linux/notifier.h>
11 #include <linux/of_address.h>
12 #include <linux/of_irq.h>
13 #include <linux/of_platform.h>
14 #include <linux/platform_device.h>
15 #include <linux/printk.h>
16 #include <linux/reboot.h>
17 #include <linux/regmap.h>
18 #include <linux/smp.h>
19 #include <linux/mfd/syscon.h>
21 static struct regmap *regmap;
22 static u32 rst_src_en;
23 static u32 sw_mstr_rst;
25 struct reset_reg_mask {
30 static const struct reset_reg_mask *reset_masks;
32 static int brcmstb_restart_handler(struct sys_off_data *data)
37 rc = regmap_write(regmap, rst_src_en, reset_masks->rst_src_en_mask);
39 pr_err("failed to write rst_src_en (%d)\n", rc);
43 rc = regmap_read(regmap, rst_src_en, &tmp);
45 pr_err("failed to read rst_src_en (%d)\n", rc);
49 rc = regmap_write(regmap, sw_mstr_rst, reset_masks->sw_mstr_rst_mask);
51 pr_err("failed to write sw_mstr_rst (%d)\n", rc);
55 rc = regmap_read(regmap, sw_mstr_rst, &tmp);
57 pr_err("failed to read sw_mstr_rst (%d)\n", rc);
64 static const struct reset_reg_mask reset_bits_40nm = {
65 .rst_src_en_mask = BIT(0),
66 .sw_mstr_rst_mask = BIT(0),
69 static const struct reset_reg_mask reset_bits_65nm = {
70 .rst_src_en_mask = BIT(3),
71 .sw_mstr_rst_mask = BIT(31),
74 static int brcmstb_reboot_probe(struct platform_device *pdev)
77 struct device_node *np = pdev->dev.of_node;
80 reset_masks = device_get_match_data(&pdev->dev);
82 pr_err("failed to get match data\n");
86 regmap = syscon_regmap_lookup_by_phandle_args(np, "syscon", ARRAY_SIZE(args), args);
88 pr_err("failed to get syscon phandle\n");
92 sw_mstr_rst = args[1];
94 rc = devm_register_sys_off_handler(&pdev->dev, SYS_OFF_MODE_RESTART,
95 128, brcmstb_restart_handler, NULL);
98 "cannot register restart handler (err=%d)\n", rc);
103 static const struct of_device_id of_match[] = {
104 { .compatible = "brcm,brcmstb-reboot", .data = &reset_bits_40nm },
105 { .compatible = "brcm,bcm7038-reboot", .data = &reset_bits_65nm },
109 static struct platform_driver brcmstb_reboot_driver = {
110 .probe = brcmstb_reboot_probe,
112 .name = "brcmstb-reboot",
113 .of_match_table = of_match,
117 static int __init brcmstb_reboot_init(void)
119 return platform_driver_register(&brcmstb_reboot_driver);
121 subsys_initcall(brcmstb_reboot_init);