palm.c 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  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, write to the Free Software Foundation, Inc.,
  18. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  19. */
  20. #include "hw.h"
  21. #include "audio/audio.h"
  22. #include "sysemu.h"
  23. #include "console.h"
  24. #include "omap.h"
  25. #include "boards.h"
  26. #include "arm-misc.h"
  27. #include "devices.h"
  28. static uint32_t static_readb(void *opaque, target_phys_addr_t offset)
  29. {
  30. uint32_t *val = (uint32_t *) opaque;
  31. return *val >> ((offset & 3) << 3);
  32. }
  33. static uint32_t static_readh(void *opaque, target_phys_addr_t offset)
  34. {
  35. uint32_t *val = (uint32_t *) opaque;
  36. return *val >> ((offset & 1) << 3);
  37. }
  38. static uint32_t static_readw(void *opaque, target_phys_addr_t offset)
  39. {
  40. uint32_t *val = (uint32_t *) opaque;
  41. return *val >> ((offset & 0) << 3);
  42. }
  43. static void static_write(void *opaque, target_phys_addr_t offset,
  44. uint32_t value)
  45. {
  46. #ifdef SPY
  47. printf("%s: value %08lx written at " PA_FMT "\n",
  48. __FUNCTION__, value, offset);
  49. #endif
  50. }
  51. static CPUReadMemoryFunc *static_readfn[] = {
  52. static_readb,
  53. static_readh,
  54. static_readw,
  55. };
  56. static CPUWriteMemoryFunc *static_writefn[] = {
  57. static_write,
  58. static_write,
  59. static_write,
  60. };
  61. /* Palm Tunsgten|E support */
  62. /* Shared GPIOs */
  63. #define PALMTE_USBDETECT_GPIO 0
  64. #define PALMTE_USB_OR_DC_GPIO 1
  65. #define PALMTE_TSC_GPIO 4
  66. #define PALMTE_PINTDAV_GPIO 6
  67. #define PALMTE_MMC_WP_GPIO 8
  68. #define PALMTE_MMC_POWER_GPIO 9
  69. #define PALMTE_HDQ_GPIO 11
  70. #define PALMTE_HEADPHONES_GPIO 14
  71. #define PALMTE_SPEAKER_GPIO 15
  72. /* MPU private GPIOs */
  73. #define PALMTE_DC_GPIO 2
  74. #define PALMTE_MMC_SWITCH_GPIO 4
  75. #define PALMTE_MMC1_GPIO 6
  76. #define PALMTE_MMC2_GPIO 7
  77. #define PALMTE_MMC3_GPIO 11
  78. static struct mouse_transform_info_s palmte_pointercal = {
  79. .x = 320,
  80. .y = 320,
  81. .a = { -5909, 8, 22465308, 104, 7644, -1219972, 65536 },
  82. };
  83. static void palmte_microwire_setup(struct omap_mpu_state_s *cpu)
  84. {
  85. struct uwire_slave_s *tsc;
  86. AudioState *audio = 0;
  87. #ifdef HAS_AUDIO
  88. audio = AUD_init();
  89. #endif
  90. tsc = tsc2102_init(omap_gpio_in_get(cpu->gpio)[PALMTE_PINTDAV_GPIO],
  91. audio);
  92. omap_uwire_attach(cpu->microwire, tsc, 0);
  93. omap_mcbsp_i2s_attach(cpu->mcbsp1, tsc210x_codec(tsc));
  94. tsc210x_set_transform(tsc, &palmte_pointercal);
  95. }
  96. static struct {
  97. int row;
  98. int column;
  99. } palmte_keymap[0x80] = {
  100. [0 ... 0x7f] = { -1, -1 },
  101. [0x3b] = { 0, 0 }, /* F1 -> Calendar */
  102. [0x3c] = { 1, 0 }, /* F2 -> Contacts */
  103. [0x3d] = { 2, 0 }, /* F3 -> Tasks List */
  104. [0x3e] = { 3, 0 }, /* F4 -> Note Pad */
  105. [0x01] = { 4, 0 }, /* Esc -> Power */
  106. [0x4b] = { 0, 1 }, /* Left */
  107. [0x50] = { 1, 1 }, /* Down */
  108. [0x48] = { 2, 1 }, /* Up */
  109. [0x4d] = { 3, 1 }, /* Right */
  110. [0x4c] = { 4, 1 }, /* Centre */
  111. [0x39] = { 4, 1 }, /* Spc -> Centre */
  112. };
  113. static void palmte_button_event(void *opaque, int keycode)
  114. {
  115. struct omap_mpu_state_s *cpu = (struct omap_mpu_state_s *) opaque;
  116. if (palmte_keymap[keycode & 0x7f].row != -1)
  117. omap_mpuio_key(cpu->mpuio,
  118. palmte_keymap[keycode & 0x7f].row,
  119. palmte_keymap[keycode & 0x7f].column,
  120. !(keycode & 0x80));
  121. }
  122. static void palmte_onoff_gpios(void *opaque, int line, int level)
  123. {
  124. switch (line) {
  125. case 0:
  126. printf("%s: current to MMC/SD card %sabled.\n",
  127. __FUNCTION__, level ? "dis" : "en");
  128. break;
  129. case 1:
  130. printf("%s: internal speaker amplifier %s.\n",
  131. __FUNCTION__, level ? "down" : "on");
  132. break;
  133. /* These LCD & Audio output signals have not been identified yet. */
  134. case 2:
  135. case 3:
  136. case 4:
  137. printf("%s: LCD GPIO%i %s.\n",
  138. __FUNCTION__, line - 1, level ? "high" : "low");
  139. break;
  140. case 5:
  141. case 6:
  142. printf("%s: Audio GPIO%i %s.\n",
  143. __FUNCTION__, line - 4, level ? "high" : "low");
  144. break;
  145. }
  146. }
  147. static void palmte_gpio_setup(struct omap_mpu_state_s *cpu)
  148. {
  149. qemu_irq *misc_gpio;
  150. omap_mmc_handlers(cpu->mmc,
  151. omap_gpio_in_get(cpu->gpio)[PALMTE_MMC_WP_GPIO],
  152. qemu_irq_invert(omap_mpuio_in_get(cpu->mpuio)
  153. [PALMTE_MMC_SWITCH_GPIO]));
  154. misc_gpio = qemu_allocate_irqs(palmte_onoff_gpios, cpu, 7);
  155. omap_gpio_out_set(cpu->gpio, PALMTE_MMC_POWER_GPIO, misc_gpio[0]);
  156. omap_gpio_out_set(cpu->gpio, PALMTE_SPEAKER_GPIO, misc_gpio[1]);
  157. omap_gpio_out_set(cpu->gpio, 11, misc_gpio[2]);
  158. omap_gpio_out_set(cpu->gpio, 12, misc_gpio[3]);
  159. omap_gpio_out_set(cpu->gpio, 13, misc_gpio[4]);
  160. omap_mpuio_out_set(cpu->mpuio, 1, misc_gpio[5]);
  161. omap_mpuio_out_set(cpu->mpuio, 3, misc_gpio[6]);
  162. /* Reset some inputs to initial state. */
  163. qemu_irq_lower(omap_gpio_in_get(cpu->gpio)[PALMTE_USBDETECT_GPIO]);
  164. qemu_irq_lower(omap_gpio_in_get(cpu->gpio)[PALMTE_USB_OR_DC_GPIO]);
  165. qemu_irq_lower(omap_gpio_in_get(cpu->gpio)[4]);
  166. qemu_irq_lower(omap_gpio_in_get(cpu->gpio)[PALMTE_HEADPHONES_GPIO]);
  167. qemu_irq_lower(omap_mpuio_in_get(cpu->mpuio)[PALMTE_DC_GPIO]);
  168. qemu_irq_raise(omap_mpuio_in_get(cpu->mpuio)[6]);
  169. qemu_irq_raise(omap_mpuio_in_get(cpu->mpuio)[7]);
  170. qemu_irq_raise(omap_mpuio_in_get(cpu->mpuio)[11]);
  171. }
  172. static struct arm_boot_info palmte_binfo = {
  173. .loader_start = OMAP_EMIFF_BASE,
  174. .ram_size = 0x02000000,
  175. .board_id = 0x331,
  176. };
  177. static void palmte_init(ram_addr_t ram_size, int vga_ram_size,
  178. const char *boot_device,
  179. const char *kernel_filename, const char *kernel_cmdline,
  180. const char *initrd_filename, const char *cpu_model)
  181. {
  182. struct omap_mpu_state_s *cpu;
  183. int flash_size = 0x00800000;
  184. int sdram_size = palmte_binfo.ram_size;
  185. int io;
  186. static uint32_t cs0val = 0xffffffff;
  187. static uint32_t cs1val = 0x0000e1a0;
  188. static uint32_t cs2val = 0x0000e1a0;
  189. static uint32_t cs3val = 0xe1a0e1a0;
  190. ram_addr_t phys_flash;
  191. int rom_size, rom_loaded = 0;
  192. DisplayState *ds = get_displaystate();
  193. if (ram_size < flash_size + sdram_size + OMAP15XX_SRAM_SIZE) {
  194. fprintf(stderr, "This architecture uses %i bytes of memory\n",
  195. flash_size + sdram_size + OMAP15XX_SRAM_SIZE);
  196. exit(1);
  197. }
  198. cpu = omap310_mpu_init(sdram_size, cpu_model);
  199. /* External Flash (EMIFS) */
  200. cpu_register_physical_memory(OMAP_CS0_BASE, flash_size,
  201. (phys_flash = qemu_ram_alloc(flash_size)) | IO_MEM_ROM);
  202. io = cpu_register_io_memory(0, static_readfn, static_writefn, &cs0val);
  203. cpu_register_physical_memory(OMAP_CS0_BASE + flash_size,
  204. OMAP_CS0_SIZE - flash_size, io);
  205. io = cpu_register_io_memory(0, static_readfn, static_writefn, &cs1val);
  206. cpu_register_physical_memory(OMAP_CS1_BASE, OMAP_CS1_SIZE, io);
  207. io = cpu_register_io_memory(0, static_readfn, static_writefn, &cs2val);
  208. cpu_register_physical_memory(OMAP_CS2_BASE, OMAP_CS2_SIZE, io);
  209. io = cpu_register_io_memory(0, static_readfn, static_writefn, &cs3val);
  210. cpu_register_physical_memory(OMAP_CS3_BASE, OMAP_CS3_SIZE, io);
  211. palmte_microwire_setup(cpu);
  212. qemu_add_kbd_event_handler(palmte_button_event, cpu);
  213. palmte_gpio_setup(cpu);
  214. /* Setup initial (reset) machine state */
  215. if (nb_option_roms) {
  216. rom_size = get_image_size(option_rom[0]);
  217. if (rom_size > flash_size)
  218. fprintf(stderr, "%s: ROM image too big (%x > %x)\n",
  219. __FUNCTION__, rom_size, flash_size);
  220. else if (rom_size > 0 && load_image(option_rom[0],
  221. phys_ram_base + phys_flash) > 0) {
  222. rom_loaded = 1;
  223. cpu->env->regs[15] = 0x00000000;
  224. } else
  225. fprintf(stderr, "%s: error loading '%s'\n",
  226. __FUNCTION__, option_rom[0]);
  227. }
  228. if (!rom_loaded && !kernel_filename) {
  229. fprintf(stderr, "Kernel or ROM image must be specified\n");
  230. exit(1);
  231. }
  232. /* Load the kernel. */
  233. if (kernel_filename) {
  234. /* Start at bootloader. */
  235. cpu->env->regs[15] = palmte_binfo.loader_start;
  236. palmte_binfo.kernel_filename = kernel_filename;
  237. palmte_binfo.kernel_cmdline = kernel_cmdline;
  238. palmte_binfo.initrd_filename = initrd_filename;
  239. arm_load_kernel(cpu->env, &palmte_binfo);
  240. }
  241. /* FIXME: We shouldn't really be doing this here. The LCD controller
  242. will set the size once configured, so this just sets an initial
  243. size until the guest activates the display. */
  244. ds->surface = qemu_resize_displaysurface(ds->surface, 320, 320, 32, 4 * 320);
  245. dpy_resize(ds);
  246. }
  247. QEMUMachine palmte_machine = {
  248. .name = "cheetah",
  249. .desc = "Palm Tungsten|E aka. Cheetah PDA (OMAP310)",
  250. .init = palmte_init,
  251. .ram_require = (0x02000000 + 0x00800000 + OMAP15XX_SRAM_SIZE) |
  252. RAMSIZE_FIXED,
  253. };