zx-reboot.c 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /*
  2. * ZTE zx296702 SoC reset code
  3. *
  4. * Copyright (c) 2015 Linaro Ltd.
  5. *
  6. * Author: Jun Nie <jun.nie@linaro.org>
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License version 2 as
  10. * published by the Free Software Foundation.
  11. */
  12. #include <linux/delay.h>
  13. #include <linux/io.h>
  14. #include <linux/module.h>
  15. #include <linux/notifier.h>
  16. #include <linux/of_address.h>
  17. #include <linux/platform_device.h>
  18. #include <linux/reboot.h>
  19. static void __iomem *base;
  20. static void __iomem *pcu_base;
  21. static int zx_restart_handler(struct notifier_block *this,
  22. unsigned long mode, void *cmd)
  23. {
  24. writel_relaxed(1, base + 0xb0);
  25. writel_relaxed(1, pcu_base + 0x34);
  26. mdelay(50);
  27. pr_emerg("Unable to restart system\n");
  28. return NOTIFY_DONE;
  29. }
  30. static struct notifier_block zx_restart_nb = {
  31. .notifier_call = zx_restart_handler,
  32. .priority = 128,
  33. };
  34. static int zx_reboot_probe(struct platform_device *pdev)
  35. {
  36. struct device_node *np = pdev->dev.of_node;
  37. int err;
  38. base = of_iomap(np, 0);
  39. if (!base) {
  40. WARN(1, "failed to map base address");
  41. return -ENODEV;
  42. }
  43. np = of_find_compatible_node(NULL, NULL, "zte,zx296702-pcu");
  44. pcu_base = of_iomap(np, 0);
  45. if (!pcu_base) {
  46. iounmap(base);
  47. WARN(1, "failed to map pcu_base address");
  48. return -ENODEV;
  49. }
  50. err = register_restart_handler(&zx_restart_nb);
  51. if (err)
  52. dev_err(&pdev->dev, "Register restart handler failed(err=%d)\n",
  53. err);
  54. return err;
  55. }
  56. static const struct of_device_id zx_reboot_of_match[] = {
  57. { .compatible = "zte,sysctrl" },
  58. {}
  59. };
  60. static struct platform_driver zx_reboot_driver = {
  61. .probe = zx_reboot_probe,
  62. .driver = {
  63. .name = "zx-reboot",
  64. .of_match_table = zx_reboot_of_match,
  65. },
  66. };
  67. module_platform_driver(zx_reboot_driver);
  68. MODULE_DESCRIPTION("ZTE SoCs reset driver");
  69. MODULE_AUTHOR("Jun Nie <jun.nie@linaro.org>");
  70. MODULE_LICENSE("GPL v2");