mchp_pfsoc_ioscb.c 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  1. /*
  2. * Microchip PolarFire SoC IOSCB 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_ioscb.h"
  28. /*
  29. * The whole IOSCB module registers map into the system address at 0x3000_0000,
  30. * named as "System Port 0 (AXI-D0)".
  31. */
  32. #define IOSCB_WHOLE_REG_SIZE 0x10000000
  33. #define IOSCB_SUBMOD_REG_SIZE 0x1000
  34. /*
  35. * There are many sub-modules in the IOSCB module.
  36. * See Microchip PolarFire SoC documentation (Register_Map.zip),
  37. * Register Map/PF_SoC_RegMap_V1_1/MPFS250T/mpfs250t_ioscb_memmap_dri.htm
  38. *
  39. * The following are sub-modules offsets that are of concern.
  40. */
  41. #define IOSCB_LANE01_BASE 0x06500000
  42. #define IOSCB_LANE23_BASE 0x06510000
  43. #define IOSCB_CTRL_BASE 0x07020000
  44. #define IOSCB_CFG_BASE 0x07080000
  45. #define IOSCB_PLL_MSS_BASE 0x0E001000
  46. #define IOSCB_CFM_MSS_BASE 0x0E002000
  47. #define IOSCB_PLL_DDR_BASE 0x0E010000
  48. #define IOSCB_BC_DDR_BASE 0x0E020000
  49. #define IOSCB_IO_CALIB_DDR_BASE 0x0E040000
  50. #define IOSCB_PLL_SGMII_BASE 0x0E080000
  51. #define IOSCB_DLL_SGMII_BASE 0x0E100000
  52. #define IOSCB_CFM_SGMII_BASE 0x0E200000
  53. #define IOSCB_BC_SGMII_BASE 0x0E400000
  54. #define IOSCB_IO_CALIB_SGMII_BASE 0x0E800000
  55. static uint64_t mchp_pfsoc_dummy_read(void *opaque, hwaddr offset,
  56. unsigned size)
  57. {
  58. qemu_log_mask(LOG_UNIMP, "%s: unimplemented device read "
  59. "(size %d, offset 0x%" HWADDR_PRIx ")\n",
  60. __func__, size, offset);
  61. return 0;
  62. }
  63. static void mchp_pfsoc_dummy_write(void *opaque, hwaddr offset,
  64. uint64_t value, unsigned size)
  65. {
  66. qemu_log_mask(LOG_UNIMP, "%s: unimplemented device write "
  67. "(size %d, value 0x%" PRIx64
  68. ", offset 0x%" HWADDR_PRIx ")\n",
  69. __func__, size, value, offset);
  70. }
  71. static const MemoryRegionOps mchp_pfsoc_dummy_ops = {
  72. .read = mchp_pfsoc_dummy_read,
  73. .write = mchp_pfsoc_dummy_write,
  74. .endianness = DEVICE_LITTLE_ENDIAN,
  75. };
  76. /* All PLL modules in IOSCB have the same register layout */
  77. #define PLL_CTRL 0x04
  78. static uint64_t mchp_pfsoc_pll_read(void *opaque, hwaddr offset,
  79. unsigned size)
  80. {
  81. uint32_t val = 0;
  82. switch (offset) {
  83. case PLL_CTRL:
  84. /* PLL is locked */
  85. val = BIT(25);
  86. break;
  87. default:
  88. qemu_log_mask(LOG_UNIMP, "%s: unimplemented device read "
  89. "(size %d, offset 0x%" HWADDR_PRIx ")\n",
  90. __func__, size, offset);
  91. break;
  92. }
  93. return val;
  94. }
  95. static const MemoryRegionOps mchp_pfsoc_pll_ops = {
  96. .read = mchp_pfsoc_pll_read,
  97. .write = mchp_pfsoc_dummy_write,
  98. .endianness = DEVICE_LITTLE_ENDIAN,
  99. };
  100. /* IO_CALIB_DDR submodule */
  101. #define IO_CALIB_DDR_IOC_REG1 0x08
  102. static uint64_t mchp_pfsoc_io_calib_ddr_read(void *opaque, hwaddr offset,
  103. unsigned size)
  104. {
  105. uint32_t val = 0;
  106. switch (offset) {
  107. case IO_CALIB_DDR_IOC_REG1:
  108. /* calibration completed */
  109. val = BIT(2);
  110. break;
  111. default:
  112. qemu_log_mask(LOG_UNIMP, "%s: unimplemented device read "
  113. "(size %d, offset 0x%" HWADDR_PRIx ")\n",
  114. __func__, size, offset);
  115. break;
  116. }
  117. return val;
  118. }
  119. static const MemoryRegionOps mchp_pfsoc_io_calib_ddr_ops = {
  120. .read = mchp_pfsoc_io_calib_ddr_read,
  121. .write = mchp_pfsoc_dummy_write,
  122. .endianness = DEVICE_LITTLE_ENDIAN,
  123. };
  124. static void mchp_pfsoc_ioscb_realize(DeviceState *dev, Error **errp)
  125. {
  126. MchpPfSoCIoscbState *s = MCHP_PFSOC_IOSCB(dev);
  127. SysBusDevice *sbd = SYS_BUS_DEVICE(dev);
  128. memory_region_init(&s->container, OBJECT(s),
  129. "mchp.pfsoc.ioscb", IOSCB_WHOLE_REG_SIZE);
  130. sysbus_init_mmio(sbd, &s->container);
  131. /* add subregions for all sub-modules in IOSCB */
  132. memory_region_init_io(&s->lane01, OBJECT(s), &mchp_pfsoc_dummy_ops, s,
  133. "mchp.pfsoc.ioscb.lane01", IOSCB_SUBMOD_REG_SIZE);
  134. memory_region_add_subregion(&s->container, IOSCB_LANE01_BASE, &s->lane01);
  135. memory_region_init_io(&s->lane23, OBJECT(s), &mchp_pfsoc_dummy_ops, s,
  136. "mchp.pfsoc.ioscb.lane23", IOSCB_SUBMOD_REG_SIZE);
  137. memory_region_add_subregion(&s->container, IOSCB_LANE23_BASE, &s->lane23);
  138. memory_region_init_io(&s->ctrl, OBJECT(s), &mchp_pfsoc_dummy_ops, s,
  139. "mchp.pfsoc.ioscb.ctrl", IOSCB_SUBMOD_REG_SIZE);
  140. memory_region_add_subregion(&s->container, IOSCB_CTRL_BASE, &s->ctrl);
  141. memory_region_init_io(&s->cfg, OBJECT(s), &mchp_pfsoc_dummy_ops, s,
  142. "mchp.pfsoc.ioscb.cfg", IOSCB_SUBMOD_REG_SIZE);
  143. memory_region_add_subregion(&s->container, IOSCB_CFG_BASE, &s->cfg);
  144. memory_region_init_io(&s->pll_mss, OBJECT(s), &mchp_pfsoc_pll_ops, s,
  145. "mchp.pfsoc.ioscb.pll_mss", IOSCB_SUBMOD_REG_SIZE);
  146. memory_region_add_subregion(&s->container, IOSCB_PLL_MSS_BASE, &s->pll_mss);
  147. memory_region_init_io(&s->cfm_mss, OBJECT(s), &mchp_pfsoc_dummy_ops, s,
  148. "mchp.pfsoc.ioscb.cfm_mss", IOSCB_SUBMOD_REG_SIZE);
  149. memory_region_add_subregion(&s->container, IOSCB_CFM_MSS_BASE, &s->cfm_mss);
  150. memory_region_init_io(&s->pll_ddr, OBJECT(s), &mchp_pfsoc_pll_ops, s,
  151. "mchp.pfsoc.ioscb.pll_ddr", IOSCB_SUBMOD_REG_SIZE);
  152. memory_region_add_subregion(&s->container, IOSCB_PLL_DDR_BASE, &s->pll_ddr);
  153. memory_region_init_io(&s->bc_ddr, OBJECT(s), &mchp_pfsoc_dummy_ops, s,
  154. "mchp.pfsoc.ioscb.bc_ddr", IOSCB_SUBMOD_REG_SIZE);
  155. memory_region_add_subregion(&s->container, IOSCB_BC_DDR_BASE, &s->bc_ddr);
  156. memory_region_init_io(&s->io_calib_ddr, OBJECT(s),
  157. &mchp_pfsoc_io_calib_ddr_ops, s,
  158. "mchp.pfsoc.ioscb.io_calib_ddr",
  159. IOSCB_SUBMOD_REG_SIZE);
  160. memory_region_add_subregion(&s->container, IOSCB_IO_CALIB_DDR_BASE,
  161. &s->io_calib_ddr);
  162. memory_region_init_io(&s->pll_sgmii, OBJECT(s), &mchp_pfsoc_pll_ops, s,
  163. "mchp.pfsoc.ioscb.pll_sgmii", IOSCB_SUBMOD_REG_SIZE);
  164. memory_region_add_subregion(&s->container, IOSCB_PLL_SGMII_BASE,
  165. &s->pll_sgmii);
  166. memory_region_init_io(&s->dll_sgmii, OBJECT(s), &mchp_pfsoc_dummy_ops, s,
  167. "mchp.pfsoc.ioscb.dll_sgmii", IOSCB_SUBMOD_REG_SIZE);
  168. memory_region_add_subregion(&s->container, IOSCB_DLL_SGMII_BASE,
  169. &s->dll_sgmii);
  170. memory_region_init_io(&s->cfm_sgmii, OBJECT(s), &mchp_pfsoc_dummy_ops, s,
  171. "mchp.pfsoc.ioscb.cfm_sgmii", IOSCB_SUBMOD_REG_SIZE);
  172. memory_region_add_subregion(&s->container, IOSCB_CFM_SGMII_BASE,
  173. &s->cfm_sgmii);
  174. memory_region_init_io(&s->bc_sgmii, OBJECT(s), &mchp_pfsoc_dummy_ops, s,
  175. "mchp.pfsoc.ioscb.bc_sgmii", IOSCB_SUBMOD_REG_SIZE);
  176. memory_region_add_subregion(&s->container, IOSCB_BC_SGMII_BASE,
  177. &s->bc_sgmii);
  178. memory_region_init_io(&s->io_calib_sgmii, OBJECT(s), &mchp_pfsoc_dummy_ops,
  179. s, "mchp.pfsoc.ioscb.io_calib_sgmii",
  180. IOSCB_SUBMOD_REG_SIZE);
  181. memory_region_add_subregion(&s->container, IOSCB_IO_CALIB_SGMII_BASE,
  182. &s->io_calib_sgmii);
  183. }
  184. static void mchp_pfsoc_ioscb_class_init(ObjectClass *klass, void *data)
  185. {
  186. DeviceClass *dc = DEVICE_CLASS(klass);
  187. dc->desc = "Microchip PolarFire SoC IOSCB modules";
  188. dc->realize = mchp_pfsoc_ioscb_realize;
  189. }
  190. static const TypeInfo mchp_pfsoc_ioscb_info = {
  191. .name = TYPE_MCHP_PFSOC_IOSCB,
  192. .parent = TYPE_SYS_BUS_DEVICE,
  193. .instance_size = sizeof(MchpPfSoCIoscbState),
  194. .class_init = mchp_pfsoc_ioscb_class_init,
  195. };
  196. static void mchp_pfsoc_ioscb_register_types(void)
  197. {
  198. type_register_static(&mchp_pfsoc_ioscb_info);
  199. }
  200. type_init(mchp_pfsoc_ioscb_register_types)