imx7_gpr.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. /*
  2. * Copyright (c) 2018, Impinj, Inc.
  3. *
  4. * i.MX7 GPR IP block emulation code
  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. * Bare minimum emulation code needed to support being able to shut
  12. * down linux guest gracefully.
  13. */
  14. #include "qemu/osdep.h"
  15. #include "hw/misc/imx7_gpr.h"
  16. #include "qemu/log.h"
  17. #include "qemu/module.h"
  18. #include "trace.h"
  19. enum IMX7GPRRegisters {
  20. IOMUXC_GPR0 = 0x00,
  21. IOMUXC_GPR1 = 0x04,
  22. IOMUXC_GPR2 = 0x08,
  23. IOMUXC_GPR3 = 0x0c,
  24. IOMUXC_GPR4 = 0x10,
  25. IOMUXC_GPR5 = 0x14,
  26. IOMUXC_GPR6 = 0x18,
  27. IOMUXC_GPR7 = 0x1c,
  28. IOMUXC_GPR8 = 0x20,
  29. IOMUXC_GPR9 = 0x24,
  30. IOMUXC_GPR10 = 0x28,
  31. IOMUXC_GPR11 = 0x2c,
  32. IOMUXC_GPR12 = 0x30,
  33. IOMUXC_GPR13 = 0x34,
  34. IOMUXC_GPR14 = 0x38,
  35. IOMUXC_GPR15 = 0x3c,
  36. IOMUXC_GPR16 = 0x40,
  37. IOMUXC_GPR17 = 0x44,
  38. IOMUXC_GPR18 = 0x48,
  39. IOMUXC_GPR19 = 0x4c,
  40. IOMUXC_GPR20 = 0x50,
  41. IOMUXC_GPR21 = 0x54,
  42. IOMUXC_GPR22 = 0x58,
  43. };
  44. #define IMX7D_GPR1_IRQ_MASK BIT(12)
  45. #define IMX7D_GPR1_ENET1_TX_CLK_SEL_MASK BIT(13)
  46. #define IMX7D_GPR1_ENET2_TX_CLK_SEL_MASK BIT(14)
  47. #define IMX7D_GPR1_ENET_TX_CLK_SEL_MASK (0x3 << 13)
  48. #define IMX7D_GPR1_ENET1_CLK_DIR_MASK BIT(17)
  49. #define IMX7D_GPR1_ENET2_CLK_DIR_MASK BIT(18)
  50. #define IMX7D_GPR1_ENET_CLK_DIR_MASK (0x3 << 17)
  51. #define IMX7D_GPR5_CSI_MUX_CONTROL_MIPI BIT(4)
  52. #define IMX7D_GPR12_PCIE_PHY_REFCLK_SEL BIT(5)
  53. #define IMX7D_GPR22_PCIE_PHY_PLL_LOCKED BIT(31)
  54. static uint64_t imx7_gpr_read(void *opaque, hwaddr offset, unsigned size)
  55. {
  56. trace_imx7_gpr_read(offset);
  57. if (offset == IOMUXC_GPR22) {
  58. return IMX7D_GPR22_PCIE_PHY_PLL_LOCKED;
  59. }
  60. return 0;
  61. }
  62. static void imx7_gpr_write(void *opaque, hwaddr offset,
  63. uint64_t v, unsigned size)
  64. {
  65. trace_imx7_gpr_write(offset, v);
  66. }
  67. static const struct MemoryRegionOps imx7_gpr_ops = {
  68. .read = imx7_gpr_read,
  69. .write = imx7_gpr_write,
  70. .endianness = DEVICE_NATIVE_ENDIAN,
  71. .impl = {
  72. /*
  73. * Our device would not work correctly if the guest was doing
  74. * unaligned access. This might not be a limitation on the
  75. * real device but in practice there is no reason for a guest
  76. * to access this device unaligned.
  77. */
  78. .min_access_size = 4,
  79. .max_access_size = 4,
  80. .unaligned = false,
  81. },
  82. };
  83. static void imx7_gpr_init(Object *obj)
  84. {
  85. SysBusDevice *sd = SYS_BUS_DEVICE(obj);
  86. IMX7GPRState *s = IMX7_GPR(obj);
  87. memory_region_init_io(&s->mmio, obj, &imx7_gpr_ops, s,
  88. TYPE_IMX7_GPR, 64 * 1024);
  89. sysbus_init_mmio(sd, &s->mmio);
  90. }
  91. static void imx7_gpr_class_init(ObjectClass *klass, void *data)
  92. {
  93. DeviceClass *dc = DEVICE_CLASS(klass);
  94. dc->desc = "i.MX7 General Purpose Registers Module";
  95. }
  96. static const TypeInfo imx7_gpr_info = {
  97. .name = TYPE_IMX7_GPR,
  98. .parent = TYPE_SYS_BUS_DEVICE,
  99. .instance_size = sizeof(IMX7GPRState),
  100. .instance_init = imx7_gpr_init,
  101. .class_init = imx7_gpr_class_init,
  102. };
  103. static void imx7_gpr_register_type(void)
  104. {
  105. type_register_static(&imx7_gpr_info);
  106. }
  107. type_init(imx7_gpr_register_type)