rmobile-reset.c 2.1 KB

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