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