omap_sdrc.c 4.7 KB

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