mainstone.c 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  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 "hw.h"
  15. #include "pxa.h"
  16. #include "arm-misc.h"
  17. #include "net/net.h"
  18. #include "devices.h"
  19. #include "boards.h"
  20. #include "flash.h"
  21. #include "sysemu/blockdev.h"
  22. #include "sysbus.h"
  23. #include "exec/address-spaces.h"
  24. /* Device addresses */
  25. #define MST_FPGA_PHYS 0x08000000
  26. #define MST_ETH_PHYS 0x10000300
  27. #define MST_FLASH_0 0x00000000
  28. #define MST_FLASH_1 0x04000000
  29. /* IRQ definitions */
  30. #define MMC_IRQ 0
  31. #define USIM_IRQ 1
  32. #define USBC_IRQ 2
  33. #define ETHERNET_IRQ 3
  34. #define AC97_IRQ 4
  35. #define PEN_IRQ 5
  36. #define MSINS_IRQ 6
  37. #define EXBRD_IRQ 7
  38. #define S0_CD_IRQ 9
  39. #define S0_STSCHG_IRQ 10
  40. #define S0_IRQ 11
  41. #define S1_CD_IRQ 13
  42. #define S1_STSCHG_IRQ 14
  43. #define S1_IRQ 15
  44. static struct keymap map[0xE0] = {
  45. [0 ... 0xDF] = { -1, -1 },
  46. [0x1e] = {0,0}, /* a */
  47. [0x30] = {0,1}, /* b */
  48. [0x2e] = {0,2}, /* c */
  49. [0x20] = {0,3}, /* d */
  50. [0x12] = {0,4}, /* e */
  51. [0x21] = {0,5}, /* f */
  52. [0x22] = {1,0}, /* g */
  53. [0x23] = {1,1}, /* h */
  54. [0x17] = {1,2}, /* i */
  55. [0x24] = {1,3}, /* j */
  56. [0x25] = {1,4}, /* k */
  57. [0x26] = {1,5}, /* l */
  58. [0x32] = {2,0}, /* m */
  59. [0x31] = {2,1}, /* n */
  60. [0x18] = {2,2}, /* o */
  61. [0x19] = {2,3}, /* p */
  62. [0x10] = {2,4}, /* q */
  63. [0x13] = {2,5}, /* r */
  64. [0x1f] = {3,0}, /* s */
  65. [0x14] = {3,1}, /* t */
  66. [0x16] = {3,2}, /* u */
  67. [0x2f] = {3,3}, /* v */
  68. [0x11] = {3,4}, /* w */
  69. [0x2d] = {3,5}, /* x */
  70. [0x15] = {4,2}, /* y */
  71. [0x2c] = {4,3}, /* z */
  72. [0xc7] = {5,0}, /* Home */
  73. [0x2a] = {5,1}, /* shift */
  74. [0x39] = {5,2}, /* space */
  75. [0x39] = {5,3}, /* space */
  76. [0x1c] = {5,5}, /* enter */
  77. [0xc8] = {6,0}, /* up */
  78. [0xd0] = {6,1}, /* down */
  79. [0xcb] = {6,2}, /* left */
  80. [0xcd] = {6,3}, /* right */
  81. };
  82. enum mainstone_model_e { mainstone };
  83. #define MAINSTONE_RAM 0x04000000
  84. #define MAINSTONE_ROM 0x00800000
  85. #define MAINSTONE_FLASH 0x02000000
  86. static struct arm_boot_info mainstone_binfo = {
  87. .loader_start = PXA2XX_SDRAM_BASE,
  88. .ram_size = 0x04000000,
  89. };
  90. static void mainstone_common_init(MemoryRegion *address_space_mem,
  91. QEMUMachineInitArgs *args,
  92. enum mainstone_model_e model, int arm_id)
  93. {
  94. uint32_t sector_len = 256 * 1024;
  95. hwaddr mainstone_flash_base[] = { MST_FLASH_0, MST_FLASH_1 };
  96. PXA2xxState *mpu;
  97. DeviceState *mst_irq;
  98. DriveInfo *dinfo;
  99. int i;
  100. int be;
  101. MemoryRegion *rom = g_new(MemoryRegion, 1);
  102. const char *cpu_model = args->cpu_model;
  103. if (!cpu_model)
  104. cpu_model = "pxa270-c5";
  105. /* Setup CPU & memory */
  106. mpu = pxa270_init(address_space_mem, mainstone_binfo.ram_size, cpu_model);
  107. memory_region_init_ram(rom, "mainstone.rom", MAINSTONE_ROM);
  108. vmstate_register_ram_global(rom);
  109. memory_region_set_readonly(rom, true);
  110. memory_region_add_subregion(address_space_mem, 0, rom);
  111. #ifdef TARGET_WORDS_BIGENDIAN
  112. be = 1;
  113. #else
  114. be = 0;
  115. #endif
  116. /* There are two 32MiB flash devices on the board */
  117. for (i = 0; i < 2; i ++) {
  118. dinfo = drive_get(IF_PFLASH, 0, i);
  119. if (!dinfo) {
  120. fprintf(stderr, "Two flash images must be given with the "
  121. "'pflash' parameter\n");
  122. exit(1);
  123. }
  124. if (!pflash_cfi01_register(mainstone_flash_base[i], NULL,
  125. i ? "mainstone.flash1" : "mainstone.flash0",
  126. MAINSTONE_FLASH,
  127. dinfo->bdrv, sector_len,
  128. MAINSTONE_FLASH / sector_len, 4, 0, 0, 0, 0,
  129. be)) {
  130. fprintf(stderr, "qemu: Error registering flash memory.\n");
  131. exit(1);
  132. }
  133. }
  134. mst_irq = sysbus_create_simple("mainstone-fpga", MST_FPGA_PHYS,
  135. qdev_get_gpio_in(mpu->gpio, 0));
  136. /* setup keypad */
  137. printf("map addr %p\n", &map);
  138. pxa27x_register_keypad(mpu->kp, map, 0xe0);
  139. /* MMC/SD host */
  140. pxa2xx_mmci_handlers(mpu->mmc, NULL, qdev_get_gpio_in(mst_irq, MMC_IRQ));
  141. pxa2xx_pcmcia_set_irq_cb(mpu->pcmcia[0],
  142. qdev_get_gpio_in(mst_irq, S0_IRQ),
  143. qdev_get_gpio_in(mst_irq, S0_CD_IRQ));
  144. pxa2xx_pcmcia_set_irq_cb(mpu->pcmcia[1],
  145. qdev_get_gpio_in(mst_irq, S1_IRQ),
  146. qdev_get_gpio_in(mst_irq, S1_CD_IRQ));
  147. smc91c111_init(&nd_table[0], MST_ETH_PHYS,
  148. qdev_get_gpio_in(mst_irq, ETHERNET_IRQ));
  149. mainstone_binfo.kernel_filename = args->kernel_filename;
  150. mainstone_binfo.kernel_cmdline = args->kernel_cmdline;
  151. mainstone_binfo.initrd_filename = args->initrd_filename;
  152. mainstone_binfo.board_id = arm_id;
  153. arm_load_kernel(mpu->cpu, &mainstone_binfo);
  154. }
  155. static void mainstone_init(QEMUMachineInitArgs *args)
  156. {
  157. mainstone_common_init(get_system_memory(), args, mainstone, 0x196);
  158. }
  159. static QEMUMachine mainstone2_machine = {
  160. .name = "mainstone",
  161. .desc = "Mainstone II (PXA27x)",
  162. .init = mainstone_init,
  163. DEFAULT_MACHINE_OPTIONS,
  164. };
  165. static void mainstone_machine_init(void)
  166. {
  167. qemu_register_machine(&mainstone2_machine);
  168. }
  169. machine_init(mainstone_machine_init);