tangier_wdt.c 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Copyright (c) 2017 Intel Corporation
  4. */
  5. #include <common.h>
  6. #include <dm.h>
  7. #include <log.h>
  8. #include <wdt.h>
  9. #include <div64.h>
  10. #include <asm/scu.h>
  11. /* Hardware timeout in seconds */
  12. #define WDT_PRETIMEOUT 15
  13. #define WDT_TIMEOUT_MIN (1 + WDT_PRETIMEOUT)
  14. #define WDT_TIMEOUT_MAX 170
  15. /*
  16. * Note, firmware chooses 90 seconds as a default timeout for watchdog on
  17. * Intel Tangier SoC. It means that without handling it in the running code
  18. * the reboot will happen.
  19. */
  20. enum {
  21. SCU_WATCHDOG_START = 0,
  22. SCU_WATCHDOG_STOP = 1,
  23. SCU_WATCHDOG_KEEPALIVE = 2,
  24. SCU_WATCHDOG_SET_ACTION_ON_TIMEOUT = 3,
  25. };
  26. static int tangier_wdt_reset(struct udevice *dev)
  27. {
  28. scu_ipc_simple_command(IPCMSG_WATCHDOG_TIMER, SCU_WATCHDOG_KEEPALIVE);
  29. return 0;
  30. }
  31. static int tangier_wdt_stop(struct udevice *dev)
  32. {
  33. return scu_ipc_simple_command(IPCMSG_WATCHDOG_TIMER, SCU_WATCHDOG_STOP);
  34. }
  35. static int tangier_wdt_start(struct udevice *dev, u64 timeout_ms, ulong flags)
  36. {
  37. u32 timeout_sec;
  38. int in_size;
  39. struct ipc_wd_start {
  40. u32 pretimeout;
  41. u32 timeout;
  42. } ipc_wd_start;
  43. /* Calculate timeout in seconds and restrict to min and max value */
  44. do_div(timeout_ms, 1000);
  45. timeout_sec = clamp_t(u32, timeout_ms, WDT_TIMEOUT_MIN, WDT_TIMEOUT_MAX);
  46. /* Update values in the IPC request */
  47. ipc_wd_start.pretimeout = timeout_sec - WDT_PRETIMEOUT;
  48. ipc_wd_start.timeout = timeout_sec;
  49. /*
  50. * SCU expects the input size for watchdog IPC
  51. * to be based on 4 bytes
  52. */
  53. in_size = DIV_ROUND_UP(sizeof(ipc_wd_start), 4);
  54. scu_ipc_command(IPCMSG_WATCHDOG_TIMER, SCU_WATCHDOG_START,
  55. (u32 *)&ipc_wd_start, in_size, NULL, 0);
  56. return 0;
  57. }
  58. static const struct wdt_ops tangier_wdt_ops = {
  59. .reset = tangier_wdt_reset,
  60. .start = tangier_wdt_start,
  61. .stop = tangier_wdt_stop,
  62. };
  63. static const struct udevice_id tangier_wdt_ids[] = {
  64. { .compatible = "intel,tangier-wdt" },
  65. { /* sentinel */ }
  66. };
  67. static int tangier_wdt_probe(struct udevice *dev)
  68. {
  69. debug("%s: Probing wdt%u\n", __func__, dev->seq);
  70. return 0;
  71. }
  72. U_BOOT_DRIVER(wdt_tangier) = {
  73. .name = "wdt_tangier",
  74. .id = UCLASS_WDT,
  75. .of_match = tangier_wdt_ids,
  76. .ops = &tangier_wdt_ops,
  77. .probe = tangier_wdt_probe,
  78. };