zx-reboot.c 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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. iounmap(base);
  53. iounmap(pcu_base);
  54. dev_err(&pdev->dev, "Register restart handler failed(err=%d)\n",
  55. err);
  56. }
  57. return err;
  58. }
  59. static const struct of_device_id zx_reboot_of_match[] = {
  60. { .compatible = "zte,sysctrl" },
  61. {}
  62. };
  63. static struct platform_driver zx_reboot_driver = {
  64. .probe = zx_reboot_probe,
  65. .driver = {
  66. .name = "zx-reboot",
  67. .of_match_table = zx_reboot_of_match,
  68. },
  69. };
  70. module_platform_driver(zx_reboot_driver);