omap_sdrc.c 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  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/hw.h"
  22. #include "hw/arm/omap.h"
  23. /* SDRAM Controller Subsystem */
  24. struct omap_sdrc_s {
  25. MemoryRegion iomem;
  26. uint8_t config;
  27. };
  28. void omap_sdrc_reset(struct omap_sdrc_s *s)
  29. {
  30. s->config = 0x10;
  31. }
  32. static uint64_t omap_sdrc_read(void *opaque, hwaddr addr,
  33. unsigned size)
  34. {
  35. struct omap_sdrc_s *s = (struct omap_sdrc_s *) opaque;
  36. if (size != 4) {
  37. return omap_badwidth_read32(opaque, addr);
  38. }
  39. switch (addr) {
  40. case 0x00: /* SDRC_REVISION */
  41. return 0x20;
  42. case 0x10: /* SDRC_SYSCONFIG */
  43. return s->config;
  44. case 0x14: /* SDRC_SYSSTATUS */
  45. return 1; /* RESETDONE */
  46. case 0x40: /* SDRC_CS_CFG */
  47. case 0x44: /* SDRC_SHARING */
  48. case 0x48: /* SDRC_ERR_ADDR */
  49. case 0x4c: /* SDRC_ERR_TYPE */
  50. case 0x60: /* SDRC_DLLA_SCTRL */
  51. case 0x64: /* SDRC_DLLA_STATUS */
  52. case 0x68: /* SDRC_DLLB_CTRL */
  53. case 0x6c: /* SDRC_DLLB_STATUS */
  54. case 0x70: /* SDRC_POWER */
  55. case 0x80: /* SDRC_MCFG_0 */
  56. case 0x84: /* SDRC_MR_0 */
  57. case 0x88: /* SDRC_EMR1_0 */
  58. case 0x8c: /* SDRC_EMR2_0 */
  59. case 0x90: /* SDRC_EMR3_0 */
  60. case 0x94: /* SDRC_DCDL1_CTRL */
  61. case 0x98: /* SDRC_DCDL2_CTRL */
  62. case 0x9c: /* SDRC_ACTIM_CTRLA_0 */
  63. case 0xa0: /* SDRC_ACTIM_CTRLB_0 */
  64. case 0xa4: /* SDRC_RFR_CTRL_0 */
  65. case 0xa8: /* SDRC_MANUAL_0 */
  66. case 0xb0: /* SDRC_MCFG_1 */
  67. case 0xb4: /* SDRC_MR_1 */
  68. case 0xb8: /* SDRC_EMR1_1 */
  69. case 0xbc: /* SDRC_EMR2_1 */
  70. case 0xc0: /* SDRC_EMR3_1 */
  71. case 0xc4: /* SDRC_ACTIM_CTRLA_1 */
  72. case 0xc8: /* SDRC_ACTIM_CTRLB_1 */
  73. case 0xd4: /* SDRC_RFR_CTRL_1 */
  74. case 0xd8: /* SDRC_MANUAL_1 */
  75. return 0x00;
  76. }
  77. OMAP_BAD_REG(addr);
  78. return 0;
  79. }
  80. static void omap_sdrc_write(void *opaque, hwaddr addr,
  81. uint64_t value, unsigned size)
  82. {
  83. struct omap_sdrc_s *s = (struct omap_sdrc_s *) opaque;
  84. if (size != 4) {
  85. omap_badwidth_write32(opaque, addr, value);
  86. return;
  87. }
  88. switch (addr) {
  89. case 0x00: /* SDRC_REVISION */
  90. case 0x14: /* SDRC_SYSSTATUS */
  91. case 0x48: /* SDRC_ERR_ADDR */
  92. case 0x64: /* SDRC_DLLA_STATUS */
  93. case 0x6c: /* SDRC_DLLB_STATUS */
  94. OMAP_RO_REG(addr);
  95. return;
  96. case 0x10: /* SDRC_SYSCONFIG */
  97. if ((value >> 3) != 0x2)
  98. fprintf(stderr, "%s: bad SDRAM idle mode %i\n",
  99. __func__, (unsigned)value >> 3);
  100. if (value & 2)
  101. omap_sdrc_reset(s);
  102. s->config = value & 0x18;
  103. break;
  104. case 0x40: /* SDRC_CS_CFG */
  105. case 0x44: /* SDRC_SHARING */
  106. case 0x4c: /* SDRC_ERR_TYPE */
  107. case 0x60: /* SDRC_DLLA_SCTRL */
  108. case 0x68: /* SDRC_DLLB_CTRL */
  109. case 0x70: /* SDRC_POWER */
  110. case 0x80: /* SDRC_MCFG_0 */
  111. case 0x84: /* SDRC_MR_0 */
  112. case 0x88: /* SDRC_EMR1_0 */
  113. case 0x8c: /* SDRC_EMR2_0 */
  114. case 0x90: /* SDRC_EMR3_0 */
  115. case 0x94: /* SDRC_DCDL1_CTRL */
  116. case 0x98: /* SDRC_DCDL2_CTRL */
  117. case 0x9c: /* SDRC_ACTIM_CTRLA_0 */
  118. case 0xa0: /* SDRC_ACTIM_CTRLB_0 */
  119. case 0xa4: /* SDRC_RFR_CTRL_0 */
  120. case 0xa8: /* SDRC_MANUAL_0 */
  121. case 0xb0: /* SDRC_MCFG_1 */
  122. case 0xb4: /* SDRC_MR_1 */
  123. case 0xb8: /* SDRC_EMR1_1 */
  124. case 0xbc: /* SDRC_EMR2_1 */
  125. case 0xc0: /* SDRC_EMR3_1 */
  126. case 0xc4: /* SDRC_ACTIM_CTRLA_1 */
  127. case 0xc8: /* SDRC_ACTIM_CTRLB_1 */
  128. case 0xd4: /* SDRC_RFR_CTRL_1 */
  129. case 0xd8: /* SDRC_MANUAL_1 */
  130. break;
  131. default:
  132. OMAP_BAD_REG(addr);
  133. return;
  134. }
  135. }
  136. static const MemoryRegionOps omap_sdrc_ops = {
  137. .read = omap_sdrc_read,
  138. .write = omap_sdrc_write,
  139. .endianness = DEVICE_NATIVE_ENDIAN,
  140. };
  141. struct omap_sdrc_s *omap_sdrc_init(MemoryRegion *sysmem,
  142. hwaddr base)
  143. {
  144. struct omap_sdrc_s *s = g_new0(struct omap_sdrc_s, 1);
  145. omap_sdrc_reset(s);
  146. memory_region_init_io(&s->iomem, NULL, &omap_sdrc_ops, s, "omap.sdrc", 0x1000);
  147. memory_region_add_subregion(sysmem, base, &s->iomem);
  148. return s;
  149. }