2
0

mchp_pfsoc_dmc.c 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. /*
  2. * Microchip PolarFire SoC DDR Memory Controller module emulation
  3. *
  4. * Copyright (c) 2020 Wind River Systems, Inc.
  5. *
  6. * Author:
  7. * Bin Meng <bin.meng@windriver.com>
  8. *
  9. * This program is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU General Public License as
  11. * published by the Free Software Foundation; either version 2 or
  12. * (at your option) version 3 of the License.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License along
  20. * with this program; if not, see <http://www.gnu.org/licenses/>.
  21. */
  22. #include "qemu/osdep.h"
  23. #include "qemu/bitops.h"
  24. #include "qemu/log.h"
  25. #include "qapi/error.h"
  26. #include "hw/sysbus.h"
  27. #include "hw/misc/mchp_pfsoc_dmc.h"
  28. /* DDR SGMII PHY module */
  29. #define SGMII_PHY_IOC_REG1 0x208
  30. #define SGMII_PHY_TRAINING_STATUS 0x814
  31. #define SGMII_PHY_DQ_DQS_ERR_DONE 0x834
  32. #define SGMII_PHY_DQDQS_STATUS1 0x84c
  33. #define SGMII_PHY_PVT_STAT 0xc20
  34. static uint64_t mchp_pfsoc_ddr_sgmii_phy_read(void *opaque, hwaddr offset,
  35. unsigned size)
  36. {
  37. uint32_t val = 0;
  38. static int training_status_bit;
  39. switch (offset) {
  40. case SGMII_PHY_IOC_REG1:
  41. /* See ddr_pvt_calibration() in HSS */
  42. val = BIT(4) | BIT(2);
  43. break;
  44. case SGMII_PHY_TRAINING_STATUS:
  45. /*
  46. * The codes logic emulates the training status change from
  47. * DDR_TRAINING_IP_SM_BCLKSCLK to DDR_TRAINING_IP_SM_DQ_DQS.
  48. *
  49. * See ddr_setup() in mss_ddr.c in the HSS source codes.
  50. */
  51. val = 1 << training_status_bit;
  52. training_status_bit = (training_status_bit + 1) % 5;
  53. break;
  54. case SGMII_PHY_DQ_DQS_ERR_DONE:
  55. /*
  56. * DDR_TRAINING_IP_SM_VERIFY state in ddr_setup(),
  57. * check that DQ/DQS training passed without error.
  58. */
  59. val = 8;
  60. break;
  61. case SGMII_PHY_DQDQS_STATUS1:
  62. /*
  63. * DDR_TRAINING_IP_SM_VERIFY state in ddr_setup(),
  64. * check that DQ/DQS calculated window is above 5 taps.
  65. */
  66. val = 0xff;
  67. break;
  68. case SGMII_PHY_PVT_STAT:
  69. /* See sgmii_channel_setup() in HSS */
  70. val = BIT(14) | BIT(6);
  71. break;
  72. default:
  73. qemu_log_mask(LOG_UNIMP, "%s: unimplemented device read "
  74. "(size %d, offset 0x%" HWADDR_PRIx ")\n",
  75. __func__, size, offset);
  76. break;
  77. }
  78. return val;
  79. }
  80. static void mchp_pfsoc_ddr_sgmii_phy_write(void *opaque, hwaddr offset,
  81. uint64_t value, unsigned size)
  82. {
  83. qemu_log_mask(LOG_UNIMP, "%s: unimplemented device write "
  84. "(size %d, value 0x%" PRIx64
  85. ", offset 0x%" HWADDR_PRIx ")\n",
  86. __func__, size, value, offset);
  87. }
  88. static const MemoryRegionOps mchp_pfsoc_ddr_sgmii_phy_ops = {
  89. .read = mchp_pfsoc_ddr_sgmii_phy_read,
  90. .write = mchp_pfsoc_ddr_sgmii_phy_write,
  91. .endianness = DEVICE_LITTLE_ENDIAN,
  92. };
  93. static void mchp_pfsoc_ddr_sgmii_phy_realize(DeviceState *dev, Error **errp)
  94. {
  95. MchpPfSoCDdrSgmiiPhyState *s = MCHP_PFSOC_DDR_SGMII_PHY(dev);
  96. memory_region_init_io(&s->sgmii_phy, OBJECT(dev),
  97. &mchp_pfsoc_ddr_sgmii_phy_ops, s,
  98. "mchp.pfsoc.ddr_sgmii_phy",
  99. MCHP_PFSOC_DDR_SGMII_PHY_REG_SIZE);
  100. sysbus_init_mmio(SYS_BUS_DEVICE(dev), &s->sgmii_phy);
  101. }
  102. static void mchp_pfsoc_ddr_sgmii_phy_class_init(ObjectClass *klass, void *data)
  103. {
  104. DeviceClass *dc = DEVICE_CLASS(klass);
  105. dc->desc = "Microchip PolarFire SoC DDR SGMII PHY module";
  106. dc->realize = mchp_pfsoc_ddr_sgmii_phy_realize;
  107. }
  108. static const TypeInfo mchp_pfsoc_ddr_sgmii_phy_info = {
  109. .name = TYPE_MCHP_PFSOC_DDR_SGMII_PHY,
  110. .parent = TYPE_SYS_BUS_DEVICE,
  111. .instance_size = sizeof(MchpPfSoCDdrSgmiiPhyState),
  112. .class_init = mchp_pfsoc_ddr_sgmii_phy_class_init,
  113. };
  114. static void mchp_pfsoc_ddr_sgmii_phy_register_types(void)
  115. {
  116. type_register_static(&mchp_pfsoc_ddr_sgmii_phy_info);
  117. }
  118. type_init(mchp_pfsoc_ddr_sgmii_phy_register_types)
  119. /* DDR CFG module */
  120. #define CFG_MT_DONE_ACK 0x4428
  121. #define CFG_STAT_DFI_INIT_COMPLETE 0x10034
  122. #define CFG_STAT_DFI_TRAINING_COMPLETE 0x10038
  123. static uint64_t mchp_pfsoc_ddr_cfg_read(void *opaque, hwaddr offset,
  124. unsigned size)
  125. {
  126. uint32_t val = 0;
  127. switch (offset) {
  128. case CFG_MT_DONE_ACK:
  129. /* memory test in MTC_test() */
  130. val = BIT(0);
  131. break;
  132. case CFG_STAT_DFI_INIT_COMPLETE:
  133. /* DDR_TRAINING_IP_SM_START_CHECK state in ddr_setup() */
  134. val = BIT(0);
  135. break;
  136. case CFG_STAT_DFI_TRAINING_COMPLETE:
  137. /* DDR_TRAINING_IP_SM_VERIFY state in ddr_setup() */
  138. val = BIT(0);
  139. break;
  140. default:
  141. qemu_log_mask(LOG_UNIMP, "%s: unimplemented device read "
  142. "(size %d, offset 0x%" HWADDR_PRIx ")\n",
  143. __func__, size, offset);
  144. break;
  145. }
  146. return val;
  147. }
  148. static void mchp_pfsoc_ddr_cfg_write(void *opaque, hwaddr offset,
  149. uint64_t value, unsigned size)
  150. {
  151. qemu_log_mask(LOG_UNIMP, "%s: unimplemented device write "
  152. "(size %d, value 0x%" PRIx64
  153. ", offset 0x%" HWADDR_PRIx ")\n",
  154. __func__, size, value, offset);
  155. }
  156. static const MemoryRegionOps mchp_pfsoc_ddr_cfg_ops = {
  157. .read = mchp_pfsoc_ddr_cfg_read,
  158. .write = mchp_pfsoc_ddr_cfg_write,
  159. .endianness = DEVICE_LITTLE_ENDIAN,
  160. };
  161. static void mchp_pfsoc_ddr_cfg_realize(DeviceState *dev, Error **errp)
  162. {
  163. MchpPfSoCDdrCfgState *s = MCHP_PFSOC_DDR_CFG(dev);
  164. memory_region_init_io(&s->cfg, OBJECT(dev),
  165. &mchp_pfsoc_ddr_cfg_ops, s,
  166. "mchp.pfsoc.ddr_cfg",
  167. MCHP_PFSOC_DDR_CFG_REG_SIZE);
  168. sysbus_init_mmio(SYS_BUS_DEVICE(dev), &s->cfg);
  169. }
  170. static void mchp_pfsoc_ddr_cfg_class_init(ObjectClass *klass, void *data)
  171. {
  172. DeviceClass *dc = DEVICE_CLASS(klass);
  173. dc->desc = "Microchip PolarFire SoC DDR CFG module";
  174. dc->realize = mchp_pfsoc_ddr_cfg_realize;
  175. }
  176. static const TypeInfo mchp_pfsoc_ddr_cfg_info = {
  177. .name = TYPE_MCHP_PFSOC_DDR_CFG,
  178. .parent = TYPE_SYS_BUS_DEVICE,
  179. .instance_size = sizeof(MchpPfSoCDdrCfgState),
  180. .class_init = mchp_pfsoc_ddr_cfg_class_init,
  181. };
  182. static void mchp_pfsoc_ddr_cfg_register_types(void)
  183. {
  184. type_register_static(&mchp_pfsoc_ddr_cfg_info);
  185. }
  186. type_init(mchp_pfsoc_ddr_cfg_register_types)