puv3_pm.c 3.4 KB

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