hisi-reboot.c 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Hisilicon SoC reset code
  4. *
  5. * Copyright (c) 2014 Hisilicon Ltd.
  6. * Copyright (c) 2014 Linaro Ltd.
  7. *
  8. * Author: Haojian Zhuang <haojian.zhuang@linaro.org>
  9. */
  10. #include <linux/delay.h>
  11. #include <linux/io.h>
  12. #include <linux/module.h>
  13. #include <linux/notifier.h>
  14. #include <linux/of_address.h>
  15. #include <linux/platform_device.h>
  16. #include <linux/reboot.h>
  17. #include <asm/proc-fns.h>
  18. static void __iomem *base;
  19. static u32 reboot_offset;
  20. static int hisi_restart_handler(struct notifier_block *this,
  21. unsigned long mode, void *cmd)
  22. {
  23. writel_relaxed(0xdeadbeef, base + reboot_offset);
  24. while (1)
  25. cpu_do_idle();
  26. return NOTIFY_DONE;
  27. }
  28. static struct notifier_block hisi_restart_nb = {
  29. .notifier_call = hisi_restart_handler,
  30. .priority = 128,
  31. };
  32. static int hisi_reboot_probe(struct platform_device *pdev)
  33. {
  34. struct device_node *np = pdev->dev.of_node;
  35. int err;
  36. base = of_iomap(np, 0);
  37. if (!base) {
  38. WARN(1, "failed to map base address");
  39. return -ENODEV;
  40. }
  41. if (of_property_read_u32(np, "reboot-offset", &reboot_offset) < 0) {
  42. pr_err("failed to find reboot-offset property\n");
  43. iounmap(base);
  44. return -EINVAL;
  45. }
  46. err = register_restart_handler(&hisi_restart_nb);
  47. if (err) {
  48. dev_err(&pdev->dev, "cannot register restart handler (err=%d)\n",
  49. err);
  50. iounmap(base);
  51. }
  52. return err;
  53. }
  54. static const struct of_device_id hisi_reboot_of_match[] = {
  55. { .compatible = "hisilicon,sysctrl" },
  56. {}
  57. };
  58. static struct platform_driver hisi_reboot_driver = {
  59. .probe = hisi_reboot_probe,
  60. .driver = {
  61. .name = "hisi-reboot",
  62. .of_match_table = hisi_reboot_of_match,
  63. },
  64. };
  65. module_platform_driver(hisi_reboot_driver);