tangier_wdt.c 2.1 KB

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