Linux Audio

Check our new training course

Linux BSP upgrade and security maintenance

Need help to get security updates for your Linux BSP?
Loading...
v6.13.7
  1// SPDX-License-Identifier: GPL-2.0-only
  2// Copyright (C) 2013 Broadcom Corporation
  3
  4#include <linux/bitops.h>
  5#include <linux/device.h>
  6#include <linux/errno.h>
  7#include <linux/init.h>
  8#include <linux/io.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>
 20
 
 
 
 21static struct regmap *regmap;
 22static u32 rst_src_en;
 23static u32 sw_mstr_rst;
 24
 25struct reset_reg_mask {
 26	u32 rst_src_en_mask;
 27	u32 sw_mstr_rst_mask;
 28};
 29
 30static const struct reset_reg_mask *reset_masks;
 31
 32static int brcmstb_restart_handler(struct sys_off_data *data)
 
 33{
 34	int rc;
 35	u32 tmp;
 36
 37	rc = regmap_write(regmap, rst_src_en, reset_masks->rst_src_en_mask);
 38	if (rc) {
 39		pr_err("failed to write rst_src_en (%d)\n", rc);
 40		return NOTIFY_DONE;
 41	}
 42
 43	rc = regmap_read(regmap, rst_src_en, &tmp);
 44	if (rc) {
 45		pr_err("failed to read rst_src_en (%d)\n", rc);
 46		return NOTIFY_DONE;
 47	}
 48
 49	rc = regmap_write(regmap, sw_mstr_rst, reset_masks->sw_mstr_rst_mask);
 50	if (rc) {
 51		pr_err("failed to write sw_mstr_rst (%d)\n", rc);
 52		return NOTIFY_DONE;
 53	}
 54
 55	rc = regmap_read(regmap, sw_mstr_rst, &tmp);
 56	if (rc) {
 57		pr_err("failed to read sw_mstr_rst (%d)\n", rc);
 58		return NOTIFY_DONE;
 59	}
 60
 
 
 
 61	return NOTIFY_DONE;
 62}
 63
 
 
 
 
 
 64static const struct reset_reg_mask reset_bits_40nm = {
 65	.rst_src_en_mask = BIT(0),
 66	.sw_mstr_rst_mask = BIT(0),
 67};
 68
 69static const struct reset_reg_mask reset_bits_65nm = {
 70	.rst_src_en_mask = BIT(3),
 71	.sw_mstr_rst_mask = BIT(31),
 72};
 73
 
 
 
 
 
 
 74static int brcmstb_reboot_probe(struct platform_device *pdev)
 75{
 76	int rc;
 77	struct device_node *np = pdev->dev.of_node;
 78	unsigned int args[2];
 79
 80	reset_masks = device_get_match_data(&pdev->dev);
 81	if (!reset_masks) {
 82		pr_err("failed to get match data\n");
 83		return -EINVAL;
 84	}
 
 85
 86	regmap = syscon_regmap_lookup_by_phandle_args(np, "syscon", ARRAY_SIZE(args), args);
 87	if (IS_ERR(regmap)) {
 88		pr_err("failed to get syscon phandle\n");
 89		return -EINVAL;
 90	}
 91	rst_src_en = args[0];
 92	sw_mstr_rst = args[1];
 93
 94	rc = devm_register_sys_off_handler(&pdev->dev, SYS_OFF_MODE_RESTART,
 95					   128, brcmstb_restart_handler, NULL);
 
 
 
 
 
 
 
 
 
 
 
 
 
 96	if (rc)
 97		dev_err(&pdev->dev,
 98			"cannot register restart handler (err=%d)\n", rc);
 99
100	return rc;
101}
102
103static 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 },
106	{},
107};
108
109static struct platform_driver brcmstb_reboot_driver = {
110	.probe = brcmstb_reboot_probe,
111	.driver = {
112		.name = "brcmstb-reboot",
113		.of_match_table = of_match,
114	},
115};
116
117static int __init brcmstb_reboot_init(void)
118{
119	return platform_driver_register(&brcmstb_reboot_driver);
 
120}
121subsys_initcall(brcmstb_reboot_init);
v6.2
  1// SPDX-License-Identifier: GPL-2.0-only
  2// Copyright (C) 2013 Broadcom Corporation
  3
  4#include <linux/bitops.h>
  5#include <linux/device.h>
  6#include <linux/errno.h>
  7#include <linux/init.h>
  8#include <linux/io.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>
 20
 21#define RESET_SOURCE_ENABLE_REG 1
 22#define SW_MASTER_RESET_REG 2
 23
 24static struct regmap *regmap;
 25static u32 rst_src_en;
 26static u32 sw_mstr_rst;
 27
 28struct reset_reg_mask {
 29	u32 rst_src_en_mask;
 30	u32 sw_mstr_rst_mask;
 31};
 32
 33static const struct reset_reg_mask *reset_masks;
 34
 35static int brcmstb_restart_handler(struct notifier_block *this,
 36				   unsigned long mode, void *cmd)
 37{
 38	int rc;
 39	u32 tmp;
 40
 41	rc = regmap_write(regmap, rst_src_en, reset_masks->rst_src_en_mask);
 42	if (rc) {
 43		pr_err("failed to write rst_src_en (%d)\n", rc);
 44		return NOTIFY_DONE;
 45	}
 46
 47	rc = regmap_read(regmap, rst_src_en, &tmp);
 48	if (rc) {
 49		pr_err("failed to read rst_src_en (%d)\n", rc);
 50		return NOTIFY_DONE;
 51	}
 52
 53	rc = regmap_write(regmap, sw_mstr_rst, reset_masks->sw_mstr_rst_mask);
 54	if (rc) {
 55		pr_err("failed to write sw_mstr_rst (%d)\n", rc);
 56		return NOTIFY_DONE;
 57	}
 58
 59	rc = regmap_read(regmap, sw_mstr_rst, &tmp);
 60	if (rc) {
 61		pr_err("failed to read sw_mstr_rst (%d)\n", rc);
 62		return NOTIFY_DONE;
 63	}
 64
 65	while (1)
 66		;
 67
 68	return NOTIFY_DONE;
 69}
 70
 71static struct notifier_block brcmstb_restart_nb = {
 72	.notifier_call = brcmstb_restart_handler,
 73	.priority = 128,
 74};
 75
 76static const struct reset_reg_mask reset_bits_40nm = {
 77	.rst_src_en_mask = BIT(0),
 78	.sw_mstr_rst_mask = BIT(0),
 79};
 80
 81static const struct reset_reg_mask reset_bits_65nm = {
 82	.rst_src_en_mask = BIT(3),
 83	.sw_mstr_rst_mask = BIT(31),
 84};
 85
 86static const struct of_device_id of_match[] = {
 87	{ .compatible = "brcm,brcmstb-reboot", .data = &reset_bits_40nm },
 88	{ .compatible = "brcm,bcm7038-reboot", .data = &reset_bits_65nm },
 89	{},
 90};
 91
 92static int brcmstb_reboot_probe(struct platform_device *pdev)
 93{
 94	int rc;
 95	struct device_node *np = pdev->dev.of_node;
 96	const struct of_device_id *of_id;
 97
 98	of_id = of_match_node(of_match, np);
 99	if (!of_id) {
100		pr_err("failed to look up compatible string\n");
101		return -EINVAL;
102	}
103	reset_masks = of_id->data;
104
105	regmap = syscon_regmap_lookup_by_phandle(np, "syscon");
106	if (IS_ERR(regmap)) {
107		pr_err("failed to get syscon phandle\n");
108		return -EINVAL;
109	}
 
 
110
111	rc = of_property_read_u32_index(np, "syscon", RESET_SOURCE_ENABLE_REG,
112					&rst_src_en);
113	if (rc) {
114		pr_err("can't get rst_src_en offset (%d)\n", rc);
115		return -EINVAL;
116	}
117
118	rc = of_property_read_u32_index(np, "syscon", SW_MASTER_RESET_REG,
119					&sw_mstr_rst);
120	if (rc) {
121		pr_err("can't get sw_mstr_rst offset (%d)\n", rc);
122		return -EINVAL;
123	}
124
125	rc = register_restart_handler(&brcmstb_restart_nb);
126	if (rc)
127		dev_err(&pdev->dev,
128			"cannot register restart handler (err=%d)\n", rc);
129
130	return rc;
131}
132
 
 
 
 
 
 
133static struct platform_driver brcmstb_reboot_driver = {
134	.probe = brcmstb_reboot_probe,
135	.driver = {
136		.name = "brcmstb-reboot",
137		.of_match_table = of_match,
138	},
139};
140
141static int __init brcmstb_reboot_init(void)
142{
143	return platform_driver_probe(&brcmstb_reboot_driver,
144					brcmstb_reboot_probe);
145}
146subsys_initcall(brcmstb_reboot_init);