palm.c 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  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 "qemu/osdep.h"
  20. #include "qapi/error.h"
  21. #include "audio/audio.h"
  22. #include "sysemu/sysemu.h"
  23. #include "sysemu/qtest.h"
  24. #include "ui/console.h"
  25. #include "hw/arm/omap.h"
  26. #include "hw/boards.h"
  27. #include "hw/arm/boot.h"
  28. #include "hw/input/tsc2xxx.h"
  29. #include "hw/irq.h"
  30. #include "hw/loader.h"
  31. #include "exec/address-spaces.h"
  32. #include "cpu.h"
  33. static uint64_t static_read(void *opaque, hwaddr offset, unsigned size)
  34. {
  35. uint32_t *val = (uint32_t *)opaque;
  36. uint32_t sizemask = 7 >> size;
  37. return *val >> ((offset & sizemask) << 3);
  38. }
  39. static void static_write(void *opaque, hwaddr offset, uint64_t value,
  40. unsigned size)
  41. {
  42. #ifdef SPY
  43. printf("%s: value %08lx written at " PA_FMT "\n",
  44. __func__, value, offset);
  45. #endif
  46. }
  47. static const MemoryRegionOps static_ops = {
  48. .read = static_read,
  49. .write = static_write,
  50. .valid.min_access_size = 1,
  51. .valid.max_access_size = 4,
  52. .endianness = DEVICE_NATIVE_ENDIAN,
  53. };
  54. /* Palm Tunsgten|E support */
  55. /* Shared GPIOs */
  56. #define PALMTE_USBDETECT_GPIO 0
  57. #define PALMTE_USB_OR_DC_GPIO 1
  58. #define PALMTE_TSC_GPIO 4
  59. #define PALMTE_PINTDAV_GPIO 6
  60. #define PALMTE_MMC_WP_GPIO 8
  61. #define PALMTE_MMC_POWER_GPIO 9
  62. #define PALMTE_HDQ_GPIO 11
  63. #define PALMTE_HEADPHONES_GPIO 14
  64. #define PALMTE_SPEAKER_GPIO 15
  65. /* MPU private GPIOs */
  66. #define PALMTE_DC_GPIO 2
  67. #define PALMTE_MMC_SWITCH_GPIO 4
  68. #define PALMTE_MMC1_GPIO 6
  69. #define PALMTE_MMC2_GPIO 7
  70. #define PALMTE_MMC3_GPIO 11
  71. static MouseTransformInfo palmte_pointercal = {
  72. .x = 320,
  73. .y = 320,
  74. .a = { -5909, 8, 22465308, 104, 7644, -1219972, 65536 },
  75. };
  76. static void palmte_microwire_setup(struct omap_mpu_state_s *cpu)
  77. {
  78. uWireSlave *tsc;
  79. tsc = tsc2102_init(qdev_get_gpio_in(cpu->gpio, PALMTE_PINTDAV_GPIO));
  80. omap_uwire_attach(cpu->microwire, tsc, 0);
  81. omap_mcbsp_i2s_attach(cpu->mcbsp1, tsc210x_codec(tsc));
  82. tsc210x_set_transform(tsc, &palmte_pointercal);
  83. }
  84. static struct {
  85. int row;
  86. int column;
  87. } palmte_keymap[0x80] = {
  88. [0 ... 0x7f] = { -1, -1 },
  89. [0x3b] = { 0, 0 }, /* F1 -> Calendar */
  90. [0x3c] = { 1, 0 }, /* F2 -> Contacts */
  91. [0x3d] = { 2, 0 }, /* F3 -> Tasks List */
  92. [0x3e] = { 3, 0 }, /* F4 -> Note Pad */
  93. [0x01] = { 4, 0 }, /* Esc -> Power */
  94. [0x4b] = { 0, 1 }, /* Left */
  95. [0x50] = { 1, 1 }, /* Down */
  96. [0x48] = { 2, 1 }, /* Up */
  97. [0x4d] = { 3, 1 }, /* Right */
  98. [0x4c] = { 4, 1 }, /* Centre */
  99. [0x39] = { 4, 1 }, /* Spc -> Centre */
  100. };
  101. static void palmte_button_event(void *opaque, int keycode)
  102. {
  103. struct omap_mpu_state_s *cpu = (struct omap_mpu_state_s *) opaque;
  104. if (palmte_keymap[keycode & 0x7f].row != -1)
  105. omap_mpuio_key(cpu->mpuio,
  106. palmte_keymap[keycode & 0x7f].row,
  107. palmte_keymap[keycode & 0x7f].column,
  108. !(keycode & 0x80));
  109. }
  110. static void palmte_onoff_gpios(void *opaque, int line, int level)
  111. {
  112. switch (line) {
  113. case 0:
  114. printf("%s: current to MMC/SD card %sabled.\n",
  115. __func__, level ? "dis" : "en");
  116. break;
  117. case 1:
  118. printf("%s: internal speaker amplifier %s.\n",
  119. __func__, level ? "down" : "on");
  120. break;
  121. /* These LCD & Audio output signals have not been identified yet. */
  122. case 2:
  123. case 3:
  124. case 4:
  125. printf("%s: LCD GPIO%i %s.\n",
  126. __func__, line - 1, level ? "high" : "low");
  127. break;
  128. case 5:
  129. case 6:
  130. printf("%s: Audio GPIO%i %s.\n",
  131. __func__, line - 4, level ? "high" : "low");
  132. break;
  133. }
  134. }
  135. static void palmte_gpio_setup(struct omap_mpu_state_s *cpu)
  136. {
  137. qemu_irq *misc_gpio;
  138. omap_mmc_handlers(cpu->mmc,
  139. qdev_get_gpio_in(cpu->gpio, PALMTE_MMC_WP_GPIO),
  140. qemu_irq_invert(omap_mpuio_in_get(cpu->mpuio)
  141. [PALMTE_MMC_SWITCH_GPIO]));
  142. misc_gpio = qemu_allocate_irqs(palmte_onoff_gpios, cpu, 7);
  143. qdev_connect_gpio_out(cpu->gpio, PALMTE_MMC_POWER_GPIO, misc_gpio[0]);
  144. qdev_connect_gpio_out(cpu->gpio, PALMTE_SPEAKER_GPIO, misc_gpio[1]);
  145. qdev_connect_gpio_out(cpu->gpio, 11, misc_gpio[2]);
  146. qdev_connect_gpio_out(cpu->gpio, 12, misc_gpio[3]);
  147. qdev_connect_gpio_out(cpu->gpio, 13, misc_gpio[4]);
  148. omap_mpuio_out_set(cpu->mpuio, 1, misc_gpio[5]);
  149. omap_mpuio_out_set(cpu->mpuio, 3, misc_gpio[6]);
  150. /* Reset some inputs to initial state. */
  151. qemu_irq_lower(qdev_get_gpio_in(cpu->gpio, PALMTE_USBDETECT_GPIO));
  152. qemu_irq_lower(qdev_get_gpio_in(cpu->gpio, PALMTE_USB_OR_DC_GPIO));
  153. qemu_irq_lower(qdev_get_gpio_in(cpu->gpio, 4));
  154. qemu_irq_lower(qdev_get_gpio_in(cpu->gpio, PALMTE_HEADPHONES_GPIO));
  155. qemu_irq_lower(omap_mpuio_in_get(cpu->mpuio)[PALMTE_DC_GPIO]);
  156. qemu_irq_raise(omap_mpuio_in_get(cpu->mpuio)[6]);
  157. qemu_irq_raise(omap_mpuio_in_get(cpu->mpuio)[7]);
  158. qemu_irq_raise(omap_mpuio_in_get(cpu->mpuio)[11]);
  159. }
  160. static struct arm_boot_info palmte_binfo = {
  161. .loader_start = OMAP_EMIFF_BASE,
  162. .ram_size = 0x02000000,
  163. .board_id = 0x331,
  164. };
  165. static void palmte_init(MachineState *machine)
  166. {
  167. MemoryRegion *address_space_mem = get_system_memory();
  168. struct omap_mpu_state_s *mpu;
  169. int flash_size = 0x00800000;
  170. static uint32_t cs0val = 0xffffffff;
  171. static uint32_t cs1val = 0x0000e1a0;
  172. static uint32_t cs2val = 0x0000e1a0;
  173. static uint32_t cs3val = 0xe1a0e1a0;
  174. int rom_size, rom_loaded = 0;
  175. MemoryRegion *dram = g_new(MemoryRegion, 1);
  176. MemoryRegion *flash = g_new(MemoryRegion, 1);
  177. MemoryRegion *cs = g_new(MemoryRegion, 4);
  178. memory_region_allocate_system_memory(dram, NULL, "omap1.dram",
  179. palmte_binfo.ram_size);
  180. memory_region_add_subregion(address_space_mem, OMAP_EMIFF_BASE, dram);
  181. mpu = omap310_mpu_init(dram, machine->cpu_type);
  182. /* External Flash (EMIFS) */
  183. memory_region_init_ram(flash, NULL, "palmte.flash", flash_size,
  184. &error_fatal);
  185. memory_region_set_readonly(flash, true);
  186. memory_region_add_subregion(address_space_mem, OMAP_CS0_BASE, flash);
  187. memory_region_init_io(&cs[0], NULL, &static_ops, &cs0val, "palmte-cs0",
  188. OMAP_CS0_SIZE - flash_size);
  189. memory_region_add_subregion(address_space_mem, OMAP_CS0_BASE + flash_size,
  190. &cs[0]);
  191. memory_region_init_io(&cs[1], NULL, &static_ops, &cs1val, "palmte-cs1",
  192. OMAP_CS1_SIZE);
  193. memory_region_add_subregion(address_space_mem, OMAP_CS1_BASE, &cs[1]);
  194. memory_region_init_io(&cs[2], NULL, &static_ops, &cs2val, "palmte-cs2",
  195. OMAP_CS2_SIZE);
  196. memory_region_add_subregion(address_space_mem, OMAP_CS2_BASE, &cs[2]);
  197. memory_region_init_io(&cs[3], NULL, &static_ops, &cs3val, "palmte-cs3",
  198. OMAP_CS3_SIZE);
  199. memory_region_add_subregion(address_space_mem, OMAP_CS3_BASE, &cs[3]);
  200. palmte_microwire_setup(mpu);
  201. qemu_add_kbd_event_handler(palmte_button_event, mpu);
  202. palmte_gpio_setup(mpu);
  203. /* Setup initial (reset) machine state */
  204. if (nb_option_roms) {
  205. rom_size = get_image_size(option_rom[0].name);
  206. if (rom_size > flash_size) {
  207. fprintf(stderr, "%s: ROM image too big (%x > %x)\n",
  208. __func__, rom_size, flash_size);
  209. rom_size = 0;
  210. }
  211. if (rom_size > 0) {
  212. rom_size = load_image_targphys(option_rom[0].name, OMAP_CS0_BASE,
  213. flash_size);
  214. rom_loaded = 1;
  215. }
  216. if (rom_size < 0) {
  217. fprintf(stderr, "%s: error loading '%s'\n",
  218. __func__, option_rom[0].name);
  219. }
  220. }
  221. if (!rom_loaded && !machine->kernel_filename && !qtest_enabled()) {
  222. fprintf(stderr, "Kernel or ROM image must be specified\n");
  223. exit(1);
  224. }
  225. /* Load the kernel. */
  226. arm_load_kernel(mpu->cpu, machine, &palmte_binfo);
  227. }
  228. static void palmte_machine_init(MachineClass *mc)
  229. {
  230. mc->desc = "Palm Tungsten|E aka. Cheetah PDA (OMAP310)";
  231. mc->init = palmte_init;
  232. mc->ignore_memory_transaction_failures = true;
  233. mc->default_cpu_type = ARM_CPU_TYPE_NAME("ti925t");
  234. }
  235. DEFINE_MACHINE("cheetah", palmte_machine_init)