Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-only
0002 // Copyright (C) 2013 Broadcom Corporation
0003 
0004 #include <linux/bitops.h>
0005 #include <linux/device.h>
0006 #include <linux/errno.h>
0007 #include <linux/init.h>
0008 #include <linux/io.h>
0009 #include <linux/jiffies.h>
0010 #include <linux/notifier.h>
0011 #include <linux/of_address.h>
0012 #include <linux/of_irq.h>
0013 #include <linux/of_platform.h>
0014 #include <linux/platform_device.h>
0015 #include <linux/printk.h>
0016 #include <linux/reboot.h>
0017 #include <linux/regmap.h>
0018 #include <linux/smp.h>
0019 #include <linux/mfd/syscon.h>
0020 
0021 #define RESET_SOURCE_ENABLE_REG 1
0022 #define SW_MASTER_RESET_REG 2
0023 
0024 static struct regmap *regmap;
0025 static u32 rst_src_en;
0026 static u32 sw_mstr_rst;
0027 
0028 struct reset_reg_mask {
0029     u32 rst_src_en_mask;
0030     u32 sw_mstr_rst_mask;
0031 };
0032 
0033 static const struct reset_reg_mask *reset_masks;
0034 
0035 static int brcmstb_restart_handler(struct notifier_block *this,
0036                    unsigned long mode, void *cmd)
0037 {
0038     int rc;
0039     u32 tmp;
0040 
0041     rc = regmap_write(regmap, rst_src_en, reset_masks->rst_src_en_mask);
0042     if (rc) {
0043         pr_err("failed to write rst_src_en (%d)\n", rc);
0044         return NOTIFY_DONE;
0045     }
0046 
0047     rc = regmap_read(regmap, rst_src_en, &tmp);
0048     if (rc) {
0049         pr_err("failed to read rst_src_en (%d)\n", rc);
0050         return NOTIFY_DONE;
0051     }
0052 
0053     rc = regmap_write(regmap, sw_mstr_rst, reset_masks->sw_mstr_rst_mask);
0054     if (rc) {
0055         pr_err("failed to write sw_mstr_rst (%d)\n", rc);
0056         return NOTIFY_DONE;
0057     }
0058 
0059     rc = regmap_read(regmap, sw_mstr_rst, &tmp);
0060     if (rc) {
0061         pr_err("failed to read sw_mstr_rst (%d)\n", rc);
0062         return NOTIFY_DONE;
0063     }
0064 
0065     while (1)
0066         ;
0067 
0068     return NOTIFY_DONE;
0069 }
0070 
0071 static struct notifier_block brcmstb_restart_nb = {
0072     .notifier_call = brcmstb_restart_handler,
0073     .priority = 128,
0074 };
0075 
0076 static const struct reset_reg_mask reset_bits_40nm = {
0077     .rst_src_en_mask = BIT(0),
0078     .sw_mstr_rst_mask = BIT(0),
0079 };
0080 
0081 static const struct reset_reg_mask reset_bits_65nm = {
0082     .rst_src_en_mask = BIT(3),
0083     .sw_mstr_rst_mask = BIT(31),
0084 };
0085 
0086 static const struct of_device_id of_match[] = {
0087     { .compatible = "brcm,brcmstb-reboot", .data = &reset_bits_40nm },
0088     { .compatible = "brcm,bcm7038-reboot", .data = &reset_bits_65nm },
0089     {},
0090 };
0091 
0092 static int brcmstb_reboot_probe(struct platform_device *pdev)
0093 {
0094     int rc;
0095     struct device_node *np = pdev->dev.of_node;
0096     const struct of_device_id *of_id;
0097 
0098     of_id = of_match_node(of_match, np);
0099     if (!of_id) {
0100         pr_err("failed to look up compatible string\n");
0101         return -EINVAL;
0102     }
0103     reset_masks = of_id->data;
0104 
0105     regmap = syscon_regmap_lookup_by_phandle(np, "syscon");
0106     if (IS_ERR(regmap)) {
0107         pr_err("failed to get syscon phandle\n");
0108         return -EINVAL;
0109     }
0110 
0111     rc = of_property_read_u32_index(np, "syscon", RESET_SOURCE_ENABLE_REG,
0112                     &rst_src_en);
0113     if (rc) {
0114         pr_err("can't get rst_src_en offset (%d)\n", rc);
0115         return -EINVAL;
0116     }
0117 
0118     rc = of_property_read_u32_index(np, "syscon", SW_MASTER_RESET_REG,
0119                     &sw_mstr_rst);
0120     if (rc) {
0121         pr_err("can't get sw_mstr_rst offset (%d)\n", rc);
0122         return -EINVAL;
0123     }
0124 
0125     rc = register_restart_handler(&brcmstb_restart_nb);
0126     if (rc)
0127         dev_err(&pdev->dev,
0128             "cannot register restart handler (err=%d)\n", rc);
0129 
0130     return rc;
0131 }
0132 
0133 static struct platform_driver brcmstb_reboot_driver = {
0134     .probe = brcmstb_reboot_probe,
0135     .driver = {
0136         .name = "brcmstb-reboot",
0137         .of_match_table = of_match,
0138     },
0139 };
0140 
0141 static int __init brcmstb_reboot_init(void)
0142 {
0143     return platform_driver_probe(&brcmstb_reboot_driver,
0144                     brcmstb_reboot_probe);
0145 }
0146 subsys_initcall(brcmstb_reboot_init);