summaryrefslogtreecommitdiffstats
path: root/drivers/power/reset/rmobile-reset.c
blob: 14682cd59e618d5f30a532952b61474e13cfa4f7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
// SPDX-License-Identifier: GPL-2.0
/*
 * Renesas R-Mobile Reset Driver
 *
 * Copyright (C) 2014 Glider bvba
 */

#include <linux/io.h>
#include <linux/module.h>
#include <linux/notifier.h>
#include <linux/of_address.h>
#include <linux/platform_device.h>
#include <linux/printk.h>
#include <linux/reboot.h>

/* SYSC Register Bank 2 */
#define RESCNT2		0x20		/* Reset Control Register 2 */

/* Reset Control Register 2 */
#define RESCNT2_PRES	0x80000000	/* Soft power-on reset */

static void __iomem *sysc_base2;

static int rmobile_reset_handler(struct sys_off_data *data)
{
	/* Let's assume we have acquired the HPB semaphore */
	writel(RESCNT2_PRES, sysc_base2 + RESCNT2);

	return NOTIFY_DONE;
}

static int rmobile_reset_probe(struct platform_device *pdev)
{
	int error;

	sysc_base2 = devm_platform_ioremap_resource(pdev, 1);
	if (IS_ERR(sysc_base2))
		return PTR_ERR(sysc_base2);

	error = devm_register_sys_off_handler(&pdev->dev,
					      SYS_OFF_MODE_RESTART,
					      SYS_OFF_PRIO_HIGH,
					      rmobile_reset_handler,
					      NULL);
	if (error) {
		dev_err(&pdev->dev,
			"cannot register restart handler (err=%d)\n", error);
		return error;
	}

	return 0;
}

static const struct of_device_id rmobile_reset_of_match[] = {
	{ .compatible = "renesas,sysc-rmobile", },
	{ /* sentinel */ }
};
MODULE_DEVICE_TABLE(of, rmobile_reset_of_match);

static struct platform_driver rmobile_reset_driver = {
	.probe = rmobile_reset_probe,
	.driver = {
		.name = "rmobile_reset",
		.of_match_table = rmobile_reset_of_match,
	},
};

module_platform_driver(rmobile_reset_driver);

MODULE_DESCRIPTION("Renesas R-Mobile Reset Driver");
MODULE_AUTHOR("Geert Uytterhoeven <geert+renesas@glider.be>");
MODULE_LICENSE("GPL v2");