puv3_pm.c 3.2 KB

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