imx2_wdt.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /*
  2. * Copyright (c) 2018, 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. #include "qemu/osdep.h"
  12. #include "qemu/bitops.h"
  13. #include "qemu/module.h"
  14. #include "sysemu/watchdog.h"
  15. #include "hw/misc/imx2_wdt.h"
  16. #define IMX2_WDT_WCR_WDA BIT(5) /* -> External Reset WDOG_B */
  17. #define IMX2_WDT_WCR_SRS BIT(4) /* -> Software Reset Signal */
  18. static uint64_t imx2_wdt_read(void *opaque, hwaddr addr,
  19. unsigned int size)
  20. {
  21. return 0;
  22. }
  23. static void imx2_wdt_write(void *opaque, hwaddr addr,
  24. uint64_t value, unsigned int size)
  25. {
  26. if (addr == IMX2_WDT_WCR &&
  27. (value & (IMX2_WDT_WCR_WDA | IMX2_WDT_WCR_SRS))) {
  28. watchdog_perform_action();
  29. }
  30. }
  31. static const MemoryRegionOps imx2_wdt_ops = {
  32. .read = imx2_wdt_read,
  33. .write = imx2_wdt_write,
  34. .endianness = DEVICE_NATIVE_ENDIAN,
  35. .impl = {
  36. /*
  37. * Our device would not work correctly if the guest was doing
  38. * unaligned access. This might not be a limitation on the
  39. * real device but in practice there is no reason for a guest
  40. * to access this device unaligned.
  41. */
  42. .min_access_size = 4,
  43. .max_access_size = 4,
  44. .unaligned = false,
  45. },
  46. };
  47. static void imx2_wdt_realize(DeviceState *dev, Error **errp)
  48. {
  49. IMX2WdtState *s = IMX2_WDT(dev);
  50. memory_region_init_io(&s->mmio, OBJECT(dev),
  51. &imx2_wdt_ops, s,
  52. TYPE_IMX2_WDT".mmio",
  53. IMX2_WDT_REG_NUM * sizeof(uint16_t));
  54. sysbus_init_mmio(SYS_BUS_DEVICE(dev), &s->mmio);
  55. }
  56. static void imx2_wdt_class_init(ObjectClass *klass, void *data)
  57. {
  58. DeviceClass *dc = DEVICE_CLASS(klass);
  59. dc->realize = imx2_wdt_realize;
  60. set_bit(DEVICE_CATEGORY_MISC, dc->categories);
  61. }
  62. static const TypeInfo imx2_wdt_info = {
  63. .name = TYPE_IMX2_WDT,
  64. .parent = TYPE_SYS_BUS_DEVICE,
  65. .instance_size = sizeof(IMX2WdtState),
  66. .class_init = imx2_wdt_class_init,
  67. };
  68. static WatchdogTimerModel model = {
  69. .wdt_name = "imx2-watchdog",
  70. .wdt_description = "i.MX2 Watchdog",
  71. };
  72. static void imx2_wdt_register_type(void)
  73. {
  74. watchdog_add_model(&model);
  75. type_register_static(&imx2_wdt_info);
  76. }
  77. type_init(imx2_wdt_register_type)