puv3_pm.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. /*
  2. * Power Management device simulation in PKUnity SoC
  3. *
  4. * Copyright (C) 2010-2012 Guan Xuetao
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License version 2 as
  8. * published by the Free Software Foundation, or any later version.
  9. * See the COPYING file in the top-level directory.
  10. */
  11. #include "qemu/osdep.h"
  12. #include "hw/sysbus.h"
  13. #include "qom/object.h"
  14. #undef DEBUG_PUV3
  15. #include "hw/unicore32/puv3.h"
  16. #include "qemu/module.h"
  17. #include "qemu/log.h"
  18. #define TYPE_PUV3_PM "puv3_pm"
  19. OBJECT_DECLARE_SIMPLE_TYPE(PUV3PMState, PUV3_PM)
  20. struct PUV3PMState {
  21. SysBusDevice parent_obj;
  22. MemoryRegion iomem;
  23. uint32_t reg_PMCR;
  24. uint32_t reg_PCGR;
  25. uint32_t reg_PLL_SYS_CFG;
  26. uint32_t reg_PLL_DDR_CFG;
  27. uint32_t reg_PLL_VGA_CFG;
  28. uint32_t reg_DIVCFG;
  29. };
  30. static uint64_t puv3_pm_read(void *opaque, hwaddr offset,
  31. unsigned size)
  32. {
  33. PUV3PMState *s = opaque;
  34. uint32_t ret = 0;
  35. switch (offset) {
  36. case 0x14:
  37. ret = s->reg_PCGR;
  38. break;
  39. case 0x18:
  40. ret = s->reg_PLL_SYS_CFG;
  41. break;
  42. case 0x1c:
  43. ret = s->reg_PLL_DDR_CFG;
  44. break;
  45. case 0x20:
  46. ret = s->reg_PLL_VGA_CFG;
  47. break;
  48. case 0x24:
  49. ret = s->reg_DIVCFG;
  50. break;
  51. case 0x28: /* PLL SYS STATUS */
  52. ret = 0x00002401;
  53. break;
  54. case 0x2c: /* PLL DDR STATUS */
  55. ret = 0x00100c00;
  56. break;
  57. case 0x30: /* PLL VGA STATUS */
  58. ret = 0x00003801;
  59. break;
  60. case 0x34: /* DIV STATUS */
  61. ret = 0x22f52015;
  62. break;
  63. case 0x38: /* SW RESET */
  64. ret = 0x0;
  65. break;
  66. case 0x44: /* PLL DFC DONE */
  67. ret = 0x7;
  68. break;
  69. default:
  70. qemu_log_mask(LOG_GUEST_ERROR,
  71. "%s: Bad read offset 0x%"HWADDR_PRIx"\n",
  72. __func__, offset);
  73. }
  74. DPRINTF("offset 0x%x, value 0x%x\n", offset, ret);
  75. return ret;
  76. }
  77. static void puv3_pm_write(void *opaque, hwaddr offset,
  78. uint64_t value, unsigned size)
  79. {
  80. PUV3PMState *s = opaque;
  81. switch (offset) {
  82. case 0x0:
  83. s->reg_PMCR = value;
  84. break;
  85. case 0x14:
  86. s->reg_PCGR = value;
  87. break;
  88. case 0x18:
  89. s->reg_PLL_SYS_CFG = value;
  90. break;
  91. case 0x1c:
  92. s->reg_PLL_DDR_CFG = value;
  93. break;
  94. case 0x20:
  95. s->reg_PLL_VGA_CFG = value;
  96. break;
  97. case 0x24:
  98. case 0x38:
  99. break;
  100. default:
  101. qemu_log_mask(LOG_GUEST_ERROR,
  102. "%s: Bad write offset 0x%"HWADDR_PRIx"\n",
  103. __func__, offset);
  104. }
  105. DPRINTF("offset 0x%x, value 0x%x\n", offset, value);
  106. }
  107. static const MemoryRegionOps puv3_pm_ops = {
  108. .read = puv3_pm_read,
  109. .write = puv3_pm_write,
  110. .impl = {
  111. .min_access_size = 4,
  112. .max_access_size = 4,
  113. },
  114. .endianness = DEVICE_NATIVE_ENDIAN,
  115. };
  116. static void puv3_pm_realize(DeviceState *dev, Error **errp)
  117. {
  118. PUV3PMState *s = PUV3_PM(dev);
  119. s->reg_PCGR = 0x0;
  120. memory_region_init_io(&s->iomem, OBJECT(s), &puv3_pm_ops, s, "puv3_pm",
  121. PUV3_REGS_OFFSET);
  122. sysbus_init_mmio(SYS_BUS_DEVICE(dev), &s->iomem);
  123. }
  124. static void puv3_pm_class_init(ObjectClass *klass, void *data)
  125. {
  126. DeviceClass *dc = DEVICE_CLASS(klass);
  127. dc->realize = puv3_pm_realize;
  128. }
  129. static const TypeInfo puv3_pm_info = {
  130. .name = TYPE_PUV3_PM,
  131. .parent = TYPE_SYS_BUS_DEVICE,
  132. .instance_size = sizeof(PUV3PMState),
  133. .class_init = puv3_pm_class_init,
  134. };
  135. static void puv3_pm_register_type(void)
  136. {
  137. type_register_static(&puv3_pm_info);
  138. }
  139. type_init(puv3_pm_register_type)