mainstone.c 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. /*
  2. * PXA270-based Intel Mainstone platforms.
  3. *
  4. * Copyright (c) 2007 by Armin Kuster <akuster@kama-aina.net> or
  5. * <akuster@mvista.com>
  6. *
  7. * Code based on spitz platform by Andrzej Zaborowski <balrog@zabor.org>
  8. *
  9. * This code is licensed under the GNU GPL v2.
  10. *
  11. * Contributions after 2012-01-13 are licensed under the terms of the
  12. * GNU GPL, version 2 or (at your option) any later version.
  13. */
  14. #include "qemu/osdep.h"
  15. #include "qemu/error-report.h"
  16. #include "qapi/error.h"
  17. #include "hw/arm/pxa.h"
  18. #include "hw/arm/boot.h"
  19. #include "net/net.h"
  20. #include "hw/net/smc91c111.h"
  21. #include "hw/boards.h"
  22. #include "hw/block/flash.h"
  23. #include "hw/sysbus.h"
  24. #include "exec/address-spaces.h"
  25. #include "sysemu/qtest.h"
  26. #include "cpu.h"
  27. /* Device addresses */
  28. #define MST_FPGA_PHYS 0x08000000
  29. #define MST_ETH_PHYS 0x10000300
  30. #define MST_FLASH_0 0x00000000
  31. #define MST_FLASH_1 0x04000000
  32. /* IRQ definitions */
  33. #define MMC_IRQ 0
  34. #define USIM_IRQ 1
  35. #define USBC_IRQ 2
  36. #define ETHERNET_IRQ 3
  37. #define AC97_IRQ 4
  38. #define PEN_IRQ 5
  39. #define MSINS_IRQ 6
  40. #define EXBRD_IRQ 7
  41. #define S0_CD_IRQ 9
  42. #define S0_STSCHG_IRQ 10
  43. #define S0_IRQ 11
  44. #define S1_CD_IRQ 13
  45. #define S1_STSCHG_IRQ 14
  46. #define S1_IRQ 15
  47. static const struct keymap map[0xE0] = {
  48. [0 ... 0xDF] = { -1, -1 },
  49. [0x1e] = {0,0}, /* a */
  50. [0x30] = {0,1}, /* b */
  51. [0x2e] = {0,2}, /* c */
  52. [0x20] = {0,3}, /* d */
  53. [0x12] = {0,4}, /* e */
  54. [0x21] = {0,5}, /* f */
  55. [0x22] = {1,0}, /* g */
  56. [0x23] = {1,1}, /* h */
  57. [0x17] = {1,2}, /* i */
  58. [0x24] = {1,3}, /* j */
  59. [0x25] = {1,4}, /* k */
  60. [0x26] = {1,5}, /* l */
  61. [0x32] = {2,0}, /* m */
  62. [0x31] = {2,1}, /* n */
  63. [0x18] = {2,2}, /* o */
  64. [0x19] = {2,3}, /* p */
  65. [0x10] = {2,4}, /* q */
  66. [0x13] = {2,5}, /* r */
  67. [0x1f] = {3,0}, /* s */
  68. [0x14] = {3,1}, /* t */
  69. [0x16] = {3,2}, /* u */
  70. [0x2f] = {3,3}, /* v */
  71. [0x11] = {3,4}, /* w */
  72. [0x2d] = {3,5}, /* x */
  73. [0x34] = {4,0}, /* . */
  74. [0x15] = {4,2}, /* y */
  75. [0x2c] = {4,3}, /* z */
  76. [0x35] = {4,4}, /* / */
  77. [0xc7] = {5,0}, /* Home */
  78. [0x2a] = {5,1}, /* shift */
  79. /*
  80. * There are two matrix positions which map to space,
  81. * but QEMU can only use one of them for the reverse
  82. * mapping, so simply use the second one.
  83. */
  84. /* [0x39] = {5,2}, space */
  85. [0x39] = {5,3}, /* space */
  86. /*
  87. * Matrix position {5,4} and other keys are missing here.
  88. * TODO: Compare with Linux code and test real hardware.
  89. */
  90. [0x1c] = {5,4}, /* enter */
  91. [0x0e] = {5,5}, /* backspace */
  92. [0xc8] = {6,0}, /* up */
  93. [0xd0] = {6,1}, /* down */
  94. [0xcb] = {6,2}, /* left */
  95. [0xcd] = {6,3}, /* right */
  96. };
  97. enum mainstone_model_e { mainstone };
  98. #define MAINSTONE_RAM 0x04000000
  99. #define MAINSTONE_ROM 0x00800000
  100. #define MAINSTONE_FLASH 0x02000000
  101. static struct arm_boot_info mainstone_binfo = {
  102. .loader_start = PXA2XX_SDRAM_BASE,
  103. .ram_size = 0x04000000,
  104. };
  105. static void mainstone_common_init(MemoryRegion *address_space_mem,
  106. MachineState *machine,
  107. enum mainstone_model_e model, int arm_id)
  108. {
  109. uint32_t sector_len = 256 * 1024;
  110. hwaddr mainstone_flash_base[] = { MST_FLASH_0, MST_FLASH_1 };
  111. PXA2xxState *mpu;
  112. DeviceState *mst_irq;
  113. DriveInfo *dinfo;
  114. int i;
  115. int be;
  116. MemoryRegion *rom = g_new(MemoryRegion, 1);
  117. /* Setup CPU & memory */
  118. mpu = pxa270_init(address_space_mem, mainstone_binfo.ram_size,
  119. machine->cpu_type);
  120. memory_region_init_ram(rom, NULL, "mainstone.rom", MAINSTONE_ROM,
  121. &error_fatal);
  122. memory_region_set_readonly(rom, true);
  123. memory_region_add_subregion(address_space_mem, 0, rom);
  124. #ifdef TARGET_WORDS_BIGENDIAN
  125. be = 1;
  126. #else
  127. be = 0;
  128. #endif
  129. /* There are two 32MiB flash devices on the board */
  130. for (i = 0; i < 2; i ++) {
  131. dinfo = drive_get(IF_PFLASH, 0, i);
  132. if (!dinfo) {
  133. if (qtest_enabled()) {
  134. break;
  135. }
  136. error_report("Two flash images must be given with the "
  137. "'pflash' parameter");
  138. exit(1);
  139. }
  140. if (!pflash_cfi01_register(mainstone_flash_base[i],
  141. i ? "mainstone.flash1" : "mainstone.flash0",
  142. MAINSTONE_FLASH,
  143. blk_by_legacy_dinfo(dinfo),
  144. sector_len, 4, 0, 0, 0, 0, be)) {
  145. error_report("Error registering flash memory");
  146. exit(1);
  147. }
  148. }
  149. mst_irq = sysbus_create_simple("mainstone-fpga", MST_FPGA_PHYS,
  150. qdev_get_gpio_in(mpu->gpio, 0));
  151. /* setup keypad */
  152. pxa27x_register_keypad(mpu->kp, map, 0xe0);
  153. /* MMC/SD host */
  154. pxa2xx_mmci_handlers(mpu->mmc, NULL, qdev_get_gpio_in(mst_irq, MMC_IRQ));
  155. pxa2xx_pcmcia_set_irq_cb(mpu->pcmcia[0],
  156. qdev_get_gpio_in(mst_irq, S0_IRQ),
  157. qdev_get_gpio_in(mst_irq, S0_CD_IRQ));
  158. pxa2xx_pcmcia_set_irq_cb(mpu->pcmcia[1],
  159. qdev_get_gpio_in(mst_irq, S1_IRQ),
  160. qdev_get_gpio_in(mst_irq, S1_CD_IRQ));
  161. smc91c111_init(&nd_table[0], MST_ETH_PHYS,
  162. qdev_get_gpio_in(mst_irq, ETHERNET_IRQ));
  163. mainstone_binfo.board_id = arm_id;
  164. arm_load_kernel(mpu->cpu, machine, &mainstone_binfo);
  165. }
  166. static void mainstone_init(MachineState *machine)
  167. {
  168. mainstone_common_init(get_system_memory(), machine, mainstone, 0x196);
  169. }
  170. static void mainstone2_machine_init(MachineClass *mc)
  171. {
  172. mc->desc = "Mainstone II (PXA27x)";
  173. mc->init = mainstone_init;
  174. mc->ignore_memory_transaction_failures = true;
  175. mc->default_cpu_type = ARM_CPU_TYPE_NAME("pxa270-c5");
  176. }
  177. DEFINE_MACHINE("mainstone", mainstone2_machine_init)