palm.c 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288
  1. /*
  2. * PalmOne's (TM) PDAs.
  3. *
  4. * Copyright (C) 2006-2007 Andrzej Zaborowski <balrog@zabor.org>
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public License as
  8. * published by the Free Software Foundation; either version 2 or
  9. * (at your option) version 3 of the License.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License along
  17. * with this program; if not, see <http://www.gnu.org/licenses/>.
  18. */
  19. #include "hw.h"
  20. #include "audio/audio.h"
  21. #include "sysemu.h"
  22. #include "console.h"
  23. #include "omap.h"
  24. #include "boards.h"
  25. #include "arm-misc.h"
  26. #include "devices.h"
  27. #include "loader.h"
  28. #include "exec-memory.h"
  29. static uint32_t static_readb(void *opaque, target_phys_addr_t offset)
  30. {
  31. uint32_t *val = (uint32_t *) opaque;
  32. return *val >> ((offset & 3) << 3);
  33. }
  34. static uint32_t static_readh(void *opaque, target_phys_addr_t offset)
  35. {
  36. uint32_t *val = (uint32_t *) opaque;
  37. return *val >> ((offset & 1) << 3);
  38. }
  39. static uint32_t static_readw(void *opaque, target_phys_addr_t offset)
  40. {
  41. uint32_t *val = (uint32_t *) opaque;
  42. return *val >> ((offset & 0) << 3);
  43. }
  44. static void static_write(void *opaque, target_phys_addr_t offset,
  45. uint32_t value)
  46. {
  47. #ifdef SPY
  48. printf("%s: value %08lx written at " PA_FMT "\n",
  49. __FUNCTION__, value, offset);
  50. #endif
  51. }
  52. static const MemoryRegionOps static_ops = {
  53. .old_mmio = {
  54. .read = { static_readb, static_readh, static_readw, },
  55. .write = { static_write, static_write, static_write, },
  56. },
  57. .endianness = DEVICE_NATIVE_ENDIAN,
  58. };
  59. /* Palm Tunsgten|E support */
  60. /* Shared GPIOs */
  61. #define PALMTE_USBDETECT_GPIO 0
  62. #define PALMTE_USB_OR_DC_GPIO 1
  63. #define PALMTE_TSC_GPIO 4
  64. #define PALMTE_PINTDAV_GPIO 6
  65. #define PALMTE_MMC_WP_GPIO 8
  66. #define PALMTE_MMC_POWER_GPIO 9
  67. #define PALMTE_HDQ_GPIO 11
  68. #define PALMTE_HEADPHONES_GPIO 14
  69. #define PALMTE_SPEAKER_GPIO 15
  70. /* MPU private GPIOs */
  71. #define PALMTE_DC_GPIO 2
  72. #define PALMTE_MMC_SWITCH_GPIO 4
  73. #define PALMTE_MMC1_GPIO 6
  74. #define PALMTE_MMC2_GPIO 7
  75. #define PALMTE_MMC3_GPIO 11
  76. static MouseTransformInfo palmte_pointercal = {
  77. .x = 320,
  78. .y = 320,
  79. .a = { -5909, 8, 22465308, 104, 7644, -1219972, 65536 },
  80. };
  81. static void palmte_microwire_setup(struct omap_mpu_state_s *cpu)
  82. {
  83. uWireSlave *tsc;
  84. tsc = tsc2102_init(qdev_get_gpio_in(cpu->gpio, PALMTE_PINTDAV_GPIO));
  85. omap_uwire_attach(cpu->microwire, tsc, 0);
  86. omap_mcbsp_i2s_attach(cpu->mcbsp1, tsc210x_codec(tsc));
  87. tsc210x_set_transform(tsc, &palmte_pointercal);
  88. }
  89. static struct {
  90. int row;
  91. int column;
  92. } palmte_keymap[0x80] = {
  93. [0 ... 0x7f] = { -1, -1 },
  94. [0x3b] = { 0, 0 }, /* F1 -> Calendar */
  95. [0x3c] = { 1, 0 }, /* F2 -> Contacts */
  96. [0x3d] = { 2, 0 }, /* F3 -> Tasks List */
  97. [0x3e] = { 3, 0 }, /* F4 -> Note Pad */
  98. [0x01] = { 4, 0 }, /* Esc -> Power */
  99. [0x4b] = { 0, 1 }, /* Left */
  100. [0x50] = { 1, 1 }, /* Down */
  101. [0x48] = { 2, 1 }, /* Up */
  102. [0x4d] = { 3, 1 }, /* Right */
  103. [0x4c] = { 4, 1 }, /* Centre */
  104. [0x39] = { 4, 1 }, /* Spc -> Centre */
  105. };
  106. static void palmte_button_event(void *opaque, int keycode)
  107. {
  108. struct omap_mpu_state_s *cpu = (struct omap_mpu_state_s *) opaque;
  109. if (palmte_keymap[keycode & 0x7f].row != -1)
  110. omap_mpuio_key(cpu->mpuio,
  111. palmte_keymap[keycode & 0x7f].row,
  112. palmte_keymap[keycode & 0x7f].column,
  113. !(keycode & 0x80));
  114. }
  115. static void palmte_onoff_gpios(void *opaque, int line, int level)
  116. {
  117. switch (line) {
  118. case 0:
  119. printf("%s: current to MMC/SD card %sabled.\n",
  120. __FUNCTION__, level ? "dis" : "en");
  121. break;
  122. case 1:
  123. printf("%s: internal speaker amplifier %s.\n",
  124. __FUNCTION__, level ? "down" : "on");
  125. break;
  126. /* These LCD & Audio output signals have not been identified yet. */
  127. case 2:
  128. case 3:
  129. case 4:
  130. printf("%s: LCD GPIO%i %s.\n",
  131. __FUNCTION__, line - 1, level ? "high" : "low");
  132. break;
  133. case 5:
  134. case 6:
  135. printf("%s: Audio GPIO%i %s.\n",
  136. __FUNCTION__, line - 4, level ? "high" : "low");
  137. break;
  138. }
  139. }
  140. static void palmte_gpio_setup(struct omap_mpu_state_s *cpu)
  141. {
  142. qemu_irq *misc_gpio;
  143. omap_mmc_handlers(cpu->mmc,
  144. qdev_get_gpio_in(cpu->gpio, PALMTE_MMC_WP_GPIO),
  145. qemu_irq_invert(omap_mpuio_in_get(cpu->mpuio)
  146. [PALMTE_MMC_SWITCH_GPIO]));
  147. misc_gpio = qemu_allocate_irqs(palmte_onoff_gpios, cpu, 7);
  148. qdev_connect_gpio_out(cpu->gpio, PALMTE_MMC_POWER_GPIO, misc_gpio[0]);
  149. qdev_connect_gpio_out(cpu->gpio, PALMTE_SPEAKER_GPIO, misc_gpio[1]);
  150. qdev_connect_gpio_out(cpu->gpio, 11, misc_gpio[2]);
  151. qdev_connect_gpio_out(cpu->gpio, 12, misc_gpio[3]);
  152. qdev_connect_gpio_out(cpu->gpio, 13, misc_gpio[4]);
  153. omap_mpuio_out_set(cpu->mpuio, 1, misc_gpio[5]);
  154. omap_mpuio_out_set(cpu->mpuio, 3, misc_gpio[6]);
  155. /* Reset some inputs to initial state. */
  156. qemu_irq_lower(qdev_get_gpio_in(cpu->gpio, PALMTE_USBDETECT_GPIO));
  157. qemu_irq_lower(qdev_get_gpio_in(cpu->gpio, PALMTE_USB_OR_DC_GPIO));
  158. qemu_irq_lower(qdev_get_gpio_in(cpu->gpio, 4));
  159. qemu_irq_lower(qdev_get_gpio_in(cpu->gpio, PALMTE_HEADPHONES_GPIO));
  160. qemu_irq_lower(omap_mpuio_in_get(cpu->mpuio)[PALMTE_DC_GPIO]);
  161. qemu_irq_raise(omap_mpuio_in_get(cpu->mpuio)[6]);
  162. qemu_irq_raise(omap_mpuio_in_get(cpu->mpuio)[7]);
  163. qemu_irq_raise(omap_mpuio_in_get(cpu->mpuio)[11]);
  164. }
  165. static struct arm_boot_info palmte_binfo = {
  166. .loader_start = OMAP_EMIFF_BASE,
  167. .ram_size = 0x02000000,
  168. .board_id = 0x331,
  169. };
  170. static void palmte_init(ram_addr_t ram_size,
  171. const char *boot_device,
  172. const char *kernel_filename, const char *kernel_cmdline,
  173. const char *initrd_filename, const char *cpu_model)
  174. {
  175. MemoryRegion *address_space_mem = get_system_memory();
  176. struct omap_mpu_state_s *cpu;
  177. int flash_size = 0x00800000;
  178. int sdram_size = palmte_binfo.ram_size;
  179. static uint32_t cs0val = 0xffffffff;
  180. static uint32_t cs1val = 0x0000e1a0;
  181. static uint32_t cs2val = 0x0000e1a0;
  182. static uint32_t cs3val = 0xe1a0e1a0;
  183. int rom_size, rom_loaded = 0;
  184. DisplayState *ds = get_displaystate();
  185. MemoryRegion *flash = g_new(MemoryRegion, 1);
  186. MemoryRegion *cs = g_new(MemoryRegion, 4);
  187. cpu = omap310_mpu_init(address_space_mem, sdram_size, cpu_model);
  188. /* External Flash (EMIFS) */
  189. memory_region_init_ram(flash, NULL, "palmte.flash", flash_size);
  190. memory_region_set_readonly(flash, true);
  191. memory_region_add_subregion(address_space_mem, OMAP_CS0_BASE, flash);
  192. memory_region_init_io(&cs[0], &static_ops, &cs0val, "palmte-cs0",
  193. OMAP_CS0_SIZE - flash_size);
  194. memory_region_add_subregion(address_space_mem, OMAP_CS0_BASE + flash_size,
  195. &cs[0]);
  196. memory_region_init_io(&cs[1], &static_ops, &cs1val, "palmte-cs1",
  197. OMAP_CS1_SIZE);
  198. memory_region_add_subregion(address_space_mem, OMAP_CS1_BASE, &cs[1]);
  199. memory_region_init_io(&cs[2], &static_ops, &cs2val, "palmte-cs2",
  200. OMAP_CS2_SIZE);
  201. memory_region_add_subregion(address_space_mem, OMAP_CS2_BASE, &cs[2]);
  202. memory_region_init_io(&cs[3], &static_ops, &cs3val, "palmte-cs3",
  203. OMAP_CS3_SIZE);
  204. memory_region_add_subregion(address_space_mem, OMAP_CS3_BASE, &cs[3]);
  205. palmte_microwire_setup(cpu);
  206. qemu_add_kbd_event_handler(palmte_button_event, cpu);
  207. palmte_gpio_setup(cpu);
  208. /* Setup initial (reset) machine state */
  209. if (nb_option_roms) {
  210. rom_size = get_image_size(option_rom[0].name);
  211. if (rom_size > flash_size) {
  212. fprintf(stderr, "%s: ROM image too big (%x > %x)\n",
  213. __FUNCTION__, rom_size, flash_size);
  214. rom_size = 0;
  215. }
  216. if (rom_size > 0) {
  217. rom_size = load_image_targphys(option_rom[0].name, OMAP_CS0_BASE,
  218. flash_size);
  219. rom_loaded = 1;
  220. }
  221. if (rom_size < 0) {
  222. fprintf(stderr, "%s: error loading '%s'\n",
  223. __FUNCTION__, option_rom[0].name);
  224. }
  225. }
  226. if (!rom_loaded && !kernel_filename) {
  227. fprintf(stderr, "Kernel or ROM image must be specified\n");
  228. exit(1);
  229. }
  230. /* Load the kernel. */
  231. if (kernel_filename) {
  232. palmte_binfo.kernel_filename = kernel_filename;
  233. palmte_binfo.kernel_cmdline = kernel_cmdline;
  234. palmte_binfo.initrd_filename = initrd_filename;
  235. arm_load_kernel(cpu->env, &palmte_binfo);
  236. }
  237. /* FIXME: We shouldn't really be doing this here. The LCD controller
  238. will set the size once configured, so this just sets an initial
  239. size until the guest activates the display. */
  240. ds->surface = qemu_resize_displaysurface(ds, 320, 320);
  241. dpy_resize(ds);
  242. }
  243. static QEMUMachine palmte_machine = {
  244. .name = "cheetah",
  245. .desc = "Palm Tungsten|E aka. Cheetah PDA (OMAP310)",
  246. .init = palmte_init,
  247. };
  248. static void palmte_machine_init(void)
  249. {
  250. qemu_register_machine(&palmte_machine);
  251. }
  252. machine_init(palmte_machine_init);