hisi-reboot.c 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /*
  2. * Hisilicon SoC reset code
  3. *
  4. * Copyright (c) 2014 Hisilicon Ltd.
  5. * Copyright (c) 2014 Linaro Ltd.
  6. *
  7. * Author: Haojian Zhuang <haojian.zhuang@linaro.org>
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License version 2 as
  11. * published by the Free Software Foundation.
  12. */
  13. #include <linux/delay.h>
  14. #include <linux/io.h>
  15. #include <linux/module.h>
  16. #include <linux/notifier.h>
  17. #include <linux/of_address.h>
  18. #include <linux/platform_device.h>
  19. #include <linux/reboot.h>
  20. #include <asm/proc-fns.h>
  21. static void __iomem *base;
  22. static u32 reboot_offset;
  23. static int hisi_restart_handler(struct notifier_block *this,
  24. unsigned long mode, void *cmd)
  25. {
  26. writel_relaxed(0xdeadbeef, base + reboot_offset);
  27. while (1)
  28. cpu_do_idle();
  29. return NOTIFY_DONE;
  30. }
  31. static struct notifier_block hisi_restart_nb = {
  32. .notifier_call = hisi_restart_handler,
  33. .priority = 128,
  34. };
  35. static int hisi_reboot_probe(struct platform_device *pdev)
  36. {
  37. struct device_node *np = pdev->dev.of_node;
  38. int err;
  39. base = of_iomap(np, 0);
  40. if (!base) {
  41. WARN(1, "failed to map base address");
  42. return -ENODEV;
  43. }
  44. if (of_property_read_u32(np, "reboot-offset", &reboot_offset) < 0) {
  45. pr_err("failed to find reboot-offset property\n");
  46. return -EINVAL;
  47. }
  48. err = register_restart_handler(&hisi_restart_nb);
  49. if (err)
  50. dev_err(&pdev->dev, "cannot register restart handler (err=%d)\n",
  51. err);
  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);