puv3_pm.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  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. #undef DEBUG_PUV3
  14. #include "hw/unicore32/puv3.h"
  15. #include "qemu/module.h"
  16. #include "qemu/log.h"
  17. #define TYPE_PUV3_PM "puv3_pm"
  18. #define PUV3_PM(obj) OBJECT_CHECK(PUV3PMState, (obj), TYPE_PUV3_PM)
  19. typedef struct PUV3PMState {
  20. SysBusDevice parent_obj;
  21. MemoryRegion iomem;
  22. uint32_t reg_PMCR;
  23. uint32_t reg_PCGR;
  24. uint32_t reg_PLL_SYS_CFG;
  25. uint32_t reg_PLL_DDR_CFG;
  26. uint32_t reg_PLL_VGA_CFG;
  27. uint32_t reg_DIVCFG;
  28. } PUV3PMState;
  29. static uint64_t puv3_pm_read(void *opaque, hwaddr offset,
  30. unsigned size)
  31. {
  32. PUV3PMState *s = opaque;
  33. uint32_t ret = 0;
  34. switch (offset) {
  35. case 0x14:
  36. ret = s->reg_PCGR;
  37. break;
  38. case 0x18:
  39. ret = s->reg_PLL_SYS_CFG;
  40. break;
  41. case 0x1c:
  42. ret = s->reg_PLL_DDR_CFG;
  43. break;
  44. case 0x20:
  45. ret = s->reg_PLL_VGA_CFG;
  46. break;
  47. case 0x24:
  48. ret = s->reg_DIVCFG;
  49. break;
  50. case 0x28: /* PLL SYS STATUS */
  51. ret = 0x00002401;
  52. break;
  53. case 0x2c: /* PLL DDR STATUS */
  54. ret = 0x00100c00;
  55. break;
  56. case 0x30: /* PLL VGA STATUS */
  57. ret = 0x00003801;
  58. break;
  59. case 0x34: /* DIV STATUS */
  60. ret = 0x22f52015;
  61. break;
  62. case 0x38: /* SW RESET */
  63. ret = 0x0;
  64. break;
  65. case 0x44: /* PLL DFC DONE */
  66. ret = 0x7;
  67. break;
  68. default:
  69. qemu_log_mask(LOG_GUEST_ERROR,
  70. "%s: Bad read offset 0x%"HWADDR_PRIx"\n",
  71. __func__, offset);
  72. }
  73. DPRINTF("offset 0x%x, value 0x%x\n", offset, ret);
  74. return ret;
  75. }
  76. static void puv3_pm_write(void *opaque, hwaddr offset,
  77. uint64_t value, unsigned size)
  78. {
  79. PUV3PMState *s = opaque;
  80. switch (offset) {
  81. case 0x0:
  82. s->reg_PMCR = value;
  83. break;
  84. case 0x14:
  85. s->reg_PCGR = value;
  86. break;
  87. case 0x18:
  88. s->reg_PLL_SYS_CFG = value;
  89. break;
  90. case 0x1c:
  91. s->reg_PLL_DDR_CFG = value;
  92. break;
  93. case 0x20:
  94. s->reg_PLL_VGA_CFG = value;
  95. break;
  96. case 0x24:
  97. case 0x38:
  98. break;
  99. default:
  100. qemu_log_mask(LOG_GUEST_ERROR,
  101. "%s: Bad write offset 0x%"HWADDR_PRIx"\n",
  102. __func__, offset);
  103. }
  104. DPRINTF("offset 0x%x, value 0x%x\n", offset, value);
  105. }
  106. static const MemoryRegionOps puv3_pm_ops = {
  107. .read = puv3_pm_read,
  108. .write = puv3_pm_write,
  109. .impl = {
  110. .min_access_size = 4,
  111. .max_access_size = 4,
  112. },
  113. .endianness = DEVICE_NATIVE_ENDIAN,
  114. };
  115. static void puv3_pm_realize(DeviceState *dev, Error **errp)
  116. {
  117. PUV3PMState *s = PUV3_PM(dev);
  118. s->reg_PCGR = 0x0;
  119. memory_region_init_io(&s->iomem, OBJECT(s), &puv3_pm_ops, s, "puv3_pm",
  120. PUV3_REGS_OFFSET);
  121. sysbus_init_mmio(SYS_BUS_DEVICE(dev), &s->iomem);
  122. }
  123. static void puv3_pm_class_init(ObjectClass *klass, void *data)
  124. {
  125. DeviceClass *dc = DEVICE_CLASS(klass);
  126. dc->realize = puv3_pm_realize;
  127. }
  128. static const TypeInfo puv3_pm_info = {
  129. .name = TYPE_PUV3_PM,
  130. .parent = TYPE_SYS_BUS_DEVICE,
  131. .instance_size = sizeof(PUV3PMState),
  132. .class_init = puv3_pm_class_init,
  133. };
  134. static void puv3_pm_register_type(void)
  135. {
  136. type_register_static(&puv3_pm_info);
  137. }
  138. type_init(puv3_pm_register_type)