wdt_imx2.h 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /*
  2. * Copyright (c) 2017, Impinj, Inc.
  3. *
  4. * i.MX2 Watchdog IP block
  5. *
  6. * Author: Andrey Smirnov <andrew.smirnov@gmail.com>
  7. *
  8. * This work is licensed under the terms of the GNU GPL, version 2 or later.
  9. * See the COPYING file in the top-level directory.
  10. */
  11. #ifndef WDT_IMX2_H
  12. #define WDT_IMX2_H
  13. #include "qemu/bitops.h"
  14. #include "hw/sysbus.h"
  15. #include "hw/irq.h"
  16. #include "hw/ptimer.h"
  17. #include "qom/object.h"
  18. #define TYPE_IMX2_WDT "imx2.wdt"
  19. OBJECT_DECLARE_SIMPLE_TYPE(IMX2WdtState, IMX2_WDT)
  20. enum IMX2WdtRegisters {
  21. IMX2_WDT_WCR = 0x0000, /* Control Register */
  22. IMX2_WDT_WSR = 0x0002, /* Service Register */
  23. IMX2_WDT_WRSR = 0x0004, /* Reset Status Register */
  24. IMX2_WDT_WICR = 0x0006, /* Interrupt Control Register */
  25. IMX2_WDT_WMCR = 0x0008, /* Misc Register */
  26. };
  27. #define IMX2_WDT_MMIO_SIZE 0x000a
  28. /* Control Register definitions */
  29. #define IMX2_WDT_WCR_WT (0xFF << 8) /* Watchdog Timeout Field */
  30. #define IMX2_WDT_WCR_WDW BIT(7) /* WDOG Disable for Wait */
  31. #define IMX2_WDT_WCR_WDA BIT(5) /* WDOG Assertion */
  32. #define IMX2_WDT_WCR_SRS BIT(4) /* Software Reset Signal */
  33. #define IMX2_WDT_WCR_WDT BIT(3) /* WDOG Timeout Assertion */
  34. #define IMX2_WDT_WCR_WDE BIT(2) /* Watchdog Enable */
  35. #define IMX2_WDT_WCR_WDBG BIT(1) /* Watchdog Debug Enable */
  36. #define IMX2_WDT_WCR_WDZST BIT(0) /* Watchdog Timer Suspend */
  37. #define IMX2_WDT_WCR_LOCK_MASK (IMX2_WDT_WCR_WDZST | IMX2_WDT_WCR_WDBG \
  38. | IMX2_WDT_WCR_WDW)
  39. /* Service Register definitions */
  40. #define IMX2_WDT_SEQ1 0x5555 /* service sequence 1 */
  41. #define IMX2_WDT_SEQ2 0xAAAA /* service sequence 2 */
  42. /* Reset Status Register definitions */
  43. #define IMX2_WDT_WRSR_TOUT BIT(1) /* Reset due to Timeout */
  44. #define IMX2_WDT_WRSR_SFTW BIT(0) /* Reset due to software reset */
  45. /* Interrupt Control Register definitions */
  46. #define IMX2_WDT_WICR_WIE BIT(15) /* Interrupt Enable */
  47. #define IMX2_WDT_WICR_WTIS BIT(14) /* Interrupt Status */
  48. #define IMX2_WDT_WICR_WICT 0xff /* Interrupt Timeout */
  49. #define IMX2_WDT_WICR_WICT_DEF 0x04 /* Default interrupt timeout (2s) */
  50. #define IMX2_WDT_WICR_LOCK_MASK (IMX2_WDT_WICR_WIE | IMX2_WDT_WICR_WICT)
  51. /* Misc Control Register definitions */
  52. #define IMX2_WDT_WMCR_PDE BIT(0) /* Power-Down Enable */
  53. struct IMX2WdtState {
  54. /* <private> */
  55. SysBusDevice parent_obj;
  56. /*< public >*/
  57. MemoryRegion mmio;
  58. qemu_irq irq;
  59. struct ptimer_state *timer;
  60. struct ptimer_state *itimer;
  61. bool pretimeout_support;
  62. bool wicr_locked;
  63. uint16_t wcr;
  64. uint16_t wsr;
  65. uint16_t wrsr;
  66. uint16_t wicr;
  67. uint16_t wmcr;
  68. bool wcr_locked; /* affects WDZST, WDBG, and WDW */
  69. bool wcr_wde_locked; /* affects WDE */
  70. bool wcr_wdt_locked; /* affects WDT (never cleared) */
  71. };
  72. #endif /* WDT_IMX2_H */