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