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