rmobile-reset.c 2.0 KB

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