hisi-reboot.c 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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. iounmap(base);
  47. return -EINVAL;
  48. }
  49. err = register_restart_handler(&hisi_restart_nb);
  50. if (err) {
  51. dev_err(&pdev->dev, "cannot register restart handler (err=%d)\n",
  52. err);
  53. iounmap(base);
  54. }
  55. return err;
  56. }
  57. static const struct of_device_id hisi_reboot_of_match[] = {
  58. { .compatible = "hisilicon,sysctrl" },
  59. {}
  60. };
  61. static struct platform_driver hisi_reboot_driver = {
  62. .probe = hisi_reboot_probe,
  63. .driver = {
  64. .name = "hisi-reboot",
  65. .of_match_table = hisi_reboot_of_match,
  66. },
  67. };
  68. module_platform_driver(hisi_reboot_driver);