omap_sdrc.c 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. /*
  2. * TI OMAP SDRAM controller emulation.
  3. *
  4. * Copyright (C) 2007-2008 Nokia Corporation
  5. * Written by Andrzej Zaborowski <andrew@openedhand.com>
  6. *
  7. * This program is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU General Public License as
  9. * published by the Free Software Foundation; either version 2 or
  10. * (at your option) any later version of the License.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License along
  18. * with this program; if not, see <http://www.gnu.org/licenses/>.
  19. */
  20. #include "qemu/osdep.h"
  21. #include "hw/arm/omap.h"
  22. /* SDRAM Controller Subsystem */
  23. struct omap_sdrc_s {
  24. MemoryRegion iomem;
  25. uint8_t config;
  26. };
  27. void omap_sdrc_reset(struct omap_sdrc_s *s)
  28. {
  29. s->config = 0x10;
  30. }
  31. static uint64_t omap_sdrc_read(void *opaque, hwaddr addr, unsigned size)
  32. {
  33. struct omap_sdrc_s *s = opaque;
  34. if (size != 4) {
  35. return omap_badwidth_read32(opaque, addr);
  36. }
  37. switch (addr) {
  38. case 0x00: /* SDRC_REVISION */
  39. return 0x20;
  40. case 0x10: /* SDRC_SYSCONFIG */
  41. return s->config;
  42. case 0x14: /* SDRC_SYSSTATUS */
  43. return 1; /* RESETDONE */
  44. case 0x40: /* SDRC_CS_CFG */
  45. case 0x44: /* SDRC_SHARING */
  46. case 0x48: /* SDRC_ERR_ADDR */
  47. case 0x4c: /* SDRC_ERR_TYPE */
  48. case 0x60: /* SDRC_DLLA_SCTRL */
  49. case 0x64: /* SDRC_DLLA_STATUS */
  50. case 0x68: /* SDRC_DLLB_CTRL */
  51. case 0x6c: /* SDRC_DLLB_STATUS */
  52. case 0x70: /* SDRC_POWER */
  53. case 0x80: /* SDRC_MCFG_0 */
  54. case 0x84: /* SDRC_MR_0 */
  55. case 0x88: /* SDRC_EMR1_0 */
  56. case 0x8c: /* SDRC_EMR2_0 */
  57. case 0x90: /* SDRC_EMR3_0 */
  58. case 0x94: /* SDRC_DCDL1_CTRL */
  59. case 0x98: /* SDRC_DCDL2_CTRL */
  60. case 0x9c: /* SDRC_ACTIM_CTRLA_0 */
  61. case 0xa0: /* SDRC_ACTIM_CTRLB_0 */
  62. case 0xa4: /* SDRC_RFR_CTRL_0 */
  63. case 0xa8: /* SDRC_MANUAL_0 */
  64. case 0xb0: /* SDRC_MCFG_1 */
  65. case 0xb4: /* SDRC_MR_1 */
  66. case 0xb8: /* SDRC_EMR1_1 */
  67. case 0xbc: /* SDRC_EMR2_1 */
  68. case 0xc0: /* SDRC_EMR3_1 */
  69. case 0xc4: /* SDRC_ACTIM_CTRLA_1 */
  70. case 0xc8: /* SDRC_ACTIM_CTRLB_1 */
  71. case 0xd4: /* SDRC_RFR_CTRL_1 */
  72. case 0xd8: /* SDRC_MANUAL_1 */
  73. return 0x00;
  74. }
  75. OMAP_BAD_REG(addr);
  76. return 0;
  77. }
  78. static void omap_sdrc_write(void *opaque, hwaddr addr,
  79. uint64_t value, unsigned size)
  80. {
  81. struct omap_sdrc_s *s = opaque;
  82. if (size != 4) {
  83. omap_badwidth_write32(opaque, addr, value);
  84. return;
  85. }
  86. switch (addr) {
  87. case 0x00: /* SDRC_REVISION */
  88. case 0x14: /* SDRC_SYSSTATUS */
  89. case 0x48: /* SDRC_ERR_ADDR */
  90. case 0x64: /* SDRC_DLLA_STATUS */
  91. case 0x6c: /* SDRC_DLLB_STATUS */
  92. OMAP_RO_REG(addr);
  93. return;
  94. case 0x10: /* SDRC_SYSCONFIG */
  95. if ((value >> 3) != 0x2)
  96. fprintf(stderr, "%s: bad SDRAM idle mode %i\n",
  97. __func__, (unsigned)value >> 3);
  98. if (value & 2)
  99. omap_sdrc_reset(s);
  100. s->config = value & 0x18;
  101. break;
  102. case 0x40: /* SDRC_CS_CFG */
  103. case 0x44: /* SDRC_SHARING */
  104. case 0x4c: /* SDRC_ERR_TYPE */
  105. case 0x60: /* SDRC_DLLA_SCTRL */
  106. case 0x68: /* SDRC_DLLB_CTRL */
  107. case 0x70: /* SDRC_POWER */
  108. case 0x80: /* SDRC_MCFG_0 */
  109. case 0x84: /* SDRC_MR_0 */
  110. case 0x88: /* SDRC_EMR1_0 */
  111. case 0x8c: /* SDRC_EMR2_0 */
  112. case 0x90: /* SDRC_EMR3_0 */
  113. case 0x94: /* SDRC_DCDL1_CTRL */
  114. case 0x98: /* SDRC_DCDL2_CTRL */
  115. case 0x9c: /* SDRC_ACTIM_CTRLA_0 */
  116. case 0xa0: /* SDRC_ACTIM_CTRLB_0 */
  117. case 0xa4: /* SDRC_RFR_CTRL_0 */
  118. case 0xa8: /* SDRC_MANUAL_0 */
  119. case 0xb0: /* SDRC_MCFG_1 */
  120. case 0xb4: /* SDRC_MR_1 */
  121. case 0xb8: /* SDRC_EMR1_1 */
  122. case 0xbc: /* SDRC_EMR2_1 */
  123. case 0xc0: /* SDRC_EMR3_1 */
  124. case 0xc4: /* SDRC_ACTIM_CTRLA_1 */
  125. case 0xc8: /* SDRC_ACTIM_CTRLB_1 */
  126. case 0xd4: /* SDRC_RFR_CTRL_1 */
  127. case 0xd8: /* SDRC_MANUAL_1 */
  128. break;
  129. default:
  130. OMAP_BAD_REG(addr);
  131. return;
  132. }
  133. }
  134. static const MemoryRegionOps omap_sdrc_ops = {
  135. .read = omap_sdrc_read,
  136. .write = omap_sdrc_write,
  137. .endianness = DEVICE_NATIVE_ENDIAN,
  138. };
  139. struct omap_sdrc_s *omap_sdrc_init(MemoryRegion *sysmem,
  140. hwaddr base)
  141. {
  142. struct omap_sdrc_s *s = g_new0(struct omap_sdrc_s, 1);
  143. omap_sdrc_reset(s);
  144. memory_region_init_io(&s->iomem, NULL, &omap_sdrc_ops, s, "omap.sdrc", 0x1000);
  145. memory_region_add_subregion(sysmem, base, &s->iomem);
  146. return s;
  147. }