1/*
2 * Renesas R-Mobile Reset Driver
3 *
4 * Copyright (C) 2014 Glider bvba
5 *
6 * This file is subject to the terms and conditions of the GNU General Public
7 * License.  See the file "COPYING" in the main directory of this archive
8 * for more details.
9 */
10
11#include <linux/io.h>
12#include <linux/module.h>
13#include <linux/notifier.h>
14#include <linux/of_address.h>
15#include <linux/platform_device.h>
16#include <linux/printk.h>
17#include <linux/reboot.h>
18
19/* SYSC Register Bank 2 */
20#define RESCNT2		0x20		/* Reset Control Register 2 */
21
22/* Reset Control Register 2 */
23#define RESCNT2_PRES	0x80000000	/* Soft power-on reset */
24
25static void __iomem *sysc_base2;
26
27static int rmobile_reset_handler(struct notifier_block *this,
28				 unsigned long mode, void *cmd)
29{
30	pr_debug("%s %lu\n", __func__, mode);
31
32	/* Let's assume we have acquired the HPB semaphore */
33	writel(RESCNT2_PRES, sysc_base2 + RESCNT2);
34
35	return NOTIFY_DONE;
36}
37
38static struct notifier_block rmobile_reset_nb = {
39	.notifier_call = rmobile_reset_handler,
40	.priority = 192,
41};
42
43static int rmobile_reset_probe(struct platform_device *pdev)
44{
45	int error;
46
47	sysc_base2 = of_iomap(pdev->dev.of_node, 1);
48	if (!sysc_base2)
49		return -ENODEV;
50
51	error = register_restart_handler(&rmobile_reset_nb);
52	if (error) {
53		dev_err(&pdev->dev,
54			"cannot register restart handler (err=%d)\n", error);
55		goto fail_unmap;
56	}
57
58	return 0;
59
60fail_unmap:
61	iounmap(sysc_base2);
62	return error;
63}
64
65static int rmobile_reset_remove(struct platform_device *pdev)
66{
67	unregister_restart_handler(&rmobile_reset_nb);
68	iounmap(sysc_base2);
69	return 0;
70}
71
72static const struct of_device_id rmobile_reset_of_match[] = {
73	{ .compatible = "renesas,sysc-rmobile", },
74	{ /* sentinel */ }
75};
76MODULE_DEVICE_TABLE(of, rmobile_reset_of_match);
77
78static struct platform_driver rmobile_reset_driver = {
79	.probe = rmobile_reset_probe,
80	.remove = rmobile_reset_remove,
81	.driver = {
82		.name = "rmobile_reset",
83		.of_match_table = rmobile_reset_of_match,
84	},
85};
86
87module_platform_driver(rmobile_reset_driver);
88
89MODULE_DESCRIPTION("Renesas R-Mobile Reset Driver");
90MODULE_AUTHOR("Geert Uytterhoeven <geert+renesas@glider.be>");
91MODULE_LICENSE("GPL v2");
92