sun6i-reboot.c 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /*
  2. * Allwinner A31 SoCs reset code
  3. *
  4. * Copyright (C) 2012-2014 Maxime Ripard
  5. *
  6. * Maxime Ripard <maxime.ripard@free-electrons.com>
  7. *
  8. * This file is licensed under the terms of the GNU General Public
  9. * License version 2. This program is licensed "as is" without any
  10. * warranty of any kind, whether express or implied.
  11. */
  12. #include <linux/delay.h>
  13. #include <linux/io.h>
  14. #include <linux/module.h>
  15. #include <linux/of_address.h>
  16. #include <linux/platform_device.h>
  17. #include <linux/reboot.h>
  18. #include <asm/system_misc.h>
  19. #define SUN6I_WATCHDOG1_IRQ_REG 0x00
  20. #define SUN6I_WATCHDOG1_CTRL_REG 0x10
  21. #define SUN6I_WATCHDOG1_CTRL_RESTART BIT(0)
  22. #define SUN6I_WATCHDOG1_CONFIG_REG 0x14
  23. #define SUN6I_WATCHDOG1_CONFIG_RESTART BIT(0)
  24. #define SUN6I_WATCHDOG1_CONFIG_IRQ BIT(1)
  25. #define SUN6I_WATCHDOG1_MODE_REG 0x18
  26. #define SUN6I_WATCHDOG1_MODE_ENABLE BIT(0)
  27. static void __iomem *wdt_base;
  28. static void sun6i_wdt_restart(enum reboot_mode mode, const char *cmd)
  29. {
  30. if (!wdt_base)
  31. return;
  32. /* Disable interrupts */
  33. writel(0, wdt_base + SUN6I_WATCHDOG1_IRQ_REG);
  34. /* We want to disable the IRQ and just reset the whole system */
  35. writel(SUN6I_WATCHDOG1_CONFIG_RESTART,
  36. wdt_base + SUN6I_WATCHDOG1_CONFIG_REG);
  37. /* Enable timer. The default and lowest interval value is 0.5s */
  38. writel(SUN6I_WATCHDOG1_MODE_ENABLE,
  39. wdt_base + SUN6I_WATCHDOG1_MODE_REG);
  40. /* Restart the watchdog. */
  41. writel(SUN6I_WATCHDOG1_CTRL_RESTART,
  42. wdt_base + SUN6I_WATCHDOG1_CTRL_REG);
  43. while (1) {
  44. mdelay(5);
  45. writel(SUN6I_WATCHDOG1_MODE_ENABLE,
  46. wdt_base + SUN6I_WATCHDOG1_MODE_REG);
  47. }
  48. }
  49. static int sun6i_reboot_probe(struct platform_device *pdev)
  50. {
  51. wdt_base = of_iomap(pdev->dev.of_node, 0);
  52. if (!wdt_base) {
  53. WARN(1, "failed to map watchdog base address");
  54. return -ENODEV;
  55. }
  56. arm_pm_restart = sun6i_wdt_restart;
  57. return 0;
  58. }
  59. static struct of_device_id sun6i_reboot_of_match[] = {
  60. { .compatible = "allwinner,sun6i-a31-wdt" },
  61. {}
  62. };
  63. static struct platform_driver sun6i_reboot_driver = {
  64. .probe = sun6i_reboot_probe,
  65. .driver = {
  66. .name = "sun6i-reboot",
  67. .of_match_table = sun6i_reboot_of_match,
  68. },
  69. };
  70. module_platform_driver(sun6i_reboot_driver);