board-palmte.c 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360
  1. /*
  2. * linux/arch/arm/mach-omap1/board-palmte.c
  3. *
  4. * Modified from board-generic.c
  5. *
  6. * Support for the Palm Tungsten E PDA.
  7. *
  8. * Original version : Laurent Gonzalez
  9. *
  10. * Maintainers : http://palmtelinux.sf.net
  11. * palmtelinux-developpers@lists.sf.net
  12. *
  13. * Copyright (c) 2006 Andrzej Zaborowski <balrog@zabor.org>
  14. *
  15. * This program is free software; you can redistribute it and/or modify
  16. * it under the terms of the GNU General Public License version 2 as
  17. * published by the Free Software Foundation.
  18. */
  19. #include <linux/kernel.h>
  20. #include <linux/init.h>
  21. #include <linux/input.h>
  22. #include <linux/platform_device.h>
  23. #include <linux/mtd/mtd.h>
  24. #include <linux/mtd/partitions.h>
  25. #include <linux/spi/spi.h>
  26. #include <linux/interrupt.h>
  27. #include <linux/apm-emulation.h>
  28. #include <mach/hardware.h>
  29. #include <asm/mach-types.h>
  30. #include <asm/mach/arch.h>
  31. #include <asm/mach/map.h>
  32. #include <asm/mach/flash.h>
  33. #include <mach/gpio.h>
  34. #include <mach/mux.h>
  35. #include <mach/usb.h>
  36. #include <mach/tc.h>
  37. #include <mach/dma.h>
  38. #include <mach/board.h>
  39. #include <mach/irda.h>
  40. #include <mach/keypad.h>
  41. #include <mach/common.h>
  42. static void __init omap_palmte_init_irq(void)
  43. {
  44. omap1_init_common_hw();
  45. omap_init_irq();
  46. omap_gpio_init();
  47. }
  48. static const int palmte_keymap[] = {
  49. KEY(0, 0, KEY_F1), /* Calendar */
  50. KEY(0, 1, KEY_F2), /* Contacts */
  51. KEY(0, 2, KEY_F3), /* Tasks List */
  52. KEY(0, 3, KEY_F4), /* Note Pad */
  53. KEY(0, 4, KEY_POWER),
  54. KEY(1, 0, KEY_LEFT),
  55. KEY(1, 1, KEY_DOWN),
  56. KEY(1, 2, KEY_UP),
  57. KEY(1, 3, KEY_RIGHT),
  58. KEY(1, 4, KEY_ENTER),
  59. 0,
  60. };
  61. static struct omap_kp_platform_data palmte_kp_data = {
  62. .rows = 8,
  63. .cols = 8,
  64. .keymap = (int *) palmte_keymap,
  65. .rep = 1,
  66. .delay = 12,
  67. };
  68. static struct resource palmte_kp_resources[] = {
  69. [0] = {
  70. .start = INT_KEYBOARD,
  71. .end = INT_KEYBOARD,
  72. .flags = IORESOURCE_IRQ,
  73. },
  74. };
  75. static struct platform_device palmte_kp_device = {
  76. .name = "omap-keypad",
  77. .id = -1,
  78. .dev = {
  79. .platform_data = &palmte_kp_data,
  80. },
  81. .num_resources = ARRAY_SIZE(palmte_kp_resources),
  82. .resource = palmte_kp_resources,
  83. };
  84. static struct mtd_partition palmte_rom_partitions[] = {
  85. /* PalmOS "Small ROM", contains the bootloader and the debugger */
  86. {
  87. .name = "smallrom",
  88. .offset = 0,
  89. .size = 0xa000,
  90. .mask_flags = MTD_WRITEABLE,
  91. },
  92. /* PalmOS "Big ROM", a filesystem with all the OS code and data */
  93. {
  94. .name = "bigrom",
  95. .offset = SZ_128K,
  96. /*
  97. * 0x5f0000 bytes big in the multi-language ("EFIGS") version,
  98. * 0x7b0000 bytes in the English-only ("enUS") version.
  99. */
  100. .size = 0x7b0000,
  101. .mask_flags = MTD_WRITEABLE,
  102. },
  103. };
  104. static struct flash_platform_data palmte_rom_data = {
  105. .map_name = "map_rom",
  106. .width = 2,
  107. .parts = palmte_rom_partitions,
  108. .nr_parts = ARRAY_SIZE(palmte_rom_partitions),
  109. };
  110. static struct resource palmte_rom_resource = {
  111. .start = OMAP_CS0_PHYS,
  112. .end = OMAP_CS0_PHYS + SZ_8M - 1,
  113. .flags = IORESOURCE_MEM,
  114. };
  115. static struct platform_device palmte_rom_device = {
  116. .name = "omapflash",
  117. .id = -1,
  118. .dev = {
  119. .platform_data = &palmte_rom_data,
  120. },
  121. .num_resources = 1,
  122. .resource = &palmte_rom_resource,
  123. };
  124. static struct platform_device palmte_lcd_device = {
  125. .name = "lcd_palmte",
  126. .id = -1,
  127. };
  128. static struct omap_backlight_config palmte_backlight_config = {
  129. .default_intensity = 0xa0,
  130. };
  131. static struct platform_device palmte_backlight_device = {
  132. .name = "omap-bl",
  133. .id = -1,
  134. .dev = {
  135. .platform_data = &palmte_backlight_config,
  136. },
  137. };
  138. static struct omap_irda_config palmte_irda_config = {
  139. .transceiver_cap = IR_SIRMODE,
  140. .rx_channel = OMAP_DMA_UART3_RX,
  141. .tx_channel = OMAP_DMA_UART3_TX,
  142. .dest_start = UART3_THR,
  143. .src_start = UART3_RHR,
  144. .tx_trigger = 0,
  145. .rx_trigger = 0,
  146. };
  147. static struct resource palmte_irda_resources[] = {
  148. [0] = {
  149. .start = INT_UART3,
  150. .end = INT_UART3,
  151. .flags = IORESOURCE_IRQ,
  152. },
  153. };
  154. static struct platform_device palmte_irda_device = {
  155. .name = "omapirda",
  156. .id = -1,
  157. .dev = {
  158. .platform_data = &palmte_irda_config,
  159. },
  160. .num_resources = ARRAY_SIZE(palmte_irda_resources),
  161. .resource = palmte_irda_resources,
  162. };
  163. static struct platform_device *palmte_devices[] __initdata = {
  164. &palmte_rom_device,
  165. &palmte_kp_device,
  166. &palmte_lcd_device,
  167. &palmte_backlight_device,
  168. &palmte_irda_device,
  169. };
  170. static struct omap_usb_config palmte_usb_config __initdata = {
  171. .register_dev = 1, /* Mini-B only receptacle */
  172. .hmc_mode = 0,
  173. .pins[0] = 2,
  174. };
  175. static struct omap_lcd_config palmte_lcd_config __initdata = {
  176. .ctrl_name = "internal",
  177. };
  178. static struct omap_uart_config palmte_uart_config __initdata = {
  179. .enabled_uarts = (1 << 0) | (1 << 1) | (0 << 2),
  180. };
  181. #ifdef CONFIG_APM
  182. /*
  183. * Values measured in 10 minute intervals averaged over 10 samples.
  184. * May differ slightly from device to device but should be accurate
  185. * enough to give basic idea of battery life left and trigger
  186. * potential alerts.
  187. */
  188. static const int palmte_battery_sample[] = {
  189. 2194, 2157, 2138, 2120,
  190. 2104, 2089, 2075, 2061,
  191. 2048, 2038, 2026, 2016,
  192. 2008, 1998, 1989, 1980,
  193. 1970, 1958, 1945, 1928,
  194. 1910, 1888, 1860, 1827,
  195. 1791, 1751, 1709, 1656,
  196. };
  197. #define INTERVAL 10
  198. #define BATTERY_HIGH_TRESHOLD 66
  199. #define BATTERY_LOW_TRESHOLD 33
  200. static void palmte_get_power_status(struct apm_power_info *info, int *battery)
  201. {
  202. int charging, batt, hi, lo, mid;
  203. charging = !gpio_get_value(PALMTE_DC_GPIO);
  204. batt = battery[0];
  205. if (charging)
  206. batt -= 60;
  207. hi = ARRAY_SIZE(palmte_battery_sample);
  208. lo = 0;
  209. info->battery_flag = 0;
  210. info->units = APM_UNITS_MINS;
  211. if (batt > palmte_battery_sample[lo]) {
  212. info->battery_life = 100;
  213. info->time = INTERVAL * ARRAY_SIZE(palmte_battery_sample);
  214. } else if (batt <= palmte_battery_sample[hi - 1]) {
  215. info->battery_life = 0;
  216. info->time = 0;
  217. } else {
  218. while (hi > lo + 1) {
  219. mid = (hi + lo) >> 1;
  220. if (batt <= palmte_battery_sample[mid])
  221. lo = mid;
  222. else
  223. hi = mid;
  224. }
  225. mid = palmte_battery_sample[lo] - palmte_battery_sample[hi];
  226. hi = palmte_battery_sample[lo] - batt;
  227. info->battery_life = 100 - (100 * lo + 100 * hi / mid) /
  228. ARRAY_SIZE(palmte_battery_sample);
  229. info->time = INTERVAL * (ARRAY_SIZE(palmte_battery_sample) -
  230. lo) - INTERVAL * hi / mid;
  231. }
  232. if (charging) {
  233. info->ac_line_status = APM_AC_ONLINE;
  234. info->battery_status = APM_BATTERY_STATUS_CHARGING;
  235. info->battery_flag |= APM_BATTERY_FLAG_CHARGING;
  236. } else {
  237. info->ac_line_status = APM_AC_OFFLINE;
  238. if (info->battery_life > BATTERY_HIGH_TRESHOLD)
  239. info->battery_status = APM_BATTERY_STATUS_HIGH;
  240. else if (info->battery_life > BATTERY_LOW_TRESHOLD)
  241. info->battery_status = APM_BATTERY_STATUS_LOW;
  242. else
  243. info->battery_status = APM_BATTERY_STATUS_CRITICAL;
  244. }
  245. if (info->battery_life > BATTERY_HIGH_TRESHOLD)
  246. info->battery_flag |= APM_BATTERY_FLAG_HIGH;
  247. else if (info->battery_life > BATTERY_LOW_TRESHOLD)
  248. info->battery_flag |= APM_BATTERY_FLAG_LOW;
  249. else
  250. info->battery_flag |= APM_BATTERY_FLAG_CRITICAL;
  251. }
  252. #else
  253. #define palmte_get_power_status NULL
  254. #endif
  255. static struct omap_board_config_kernel palmte_config[] __initdata = {
  256. { OMAP_TAG_USB, &palmte_usb_config },
  257. { OMAP_TAG_LCD, &palmte_lcd_config },
  258. { OMAP_TAG_UART, &palmte_uart_config },
  259. };
  260. static struct spi_board_info palmte_spi_info[] __initdata = {
  261. {
  262. .modalias = "tsc2102",
  263. .bus_num = 2, /* uWire (officially) */
  264. .chip_select = 0, /* As opposed to 3 */
  265. .irq = OMAP_GPIO_IRQ(PALMTE_PINTDAV_GPIO),
  266. .max_speed_hz = 8000000,
  267. },
  268. };
  269. static void palmte_headphones_detect(void *data, int state)
  270. {
  271. if (state) {
  272. /* Headphones connected, disable speaker */
  273. gpio_set_value(PALMTE_SPEAKER_GPIO, 0);
  274. printk(KERN_INFO "PM: speaker off\n");
  275. } else {
  276. /* Headphones unplugged, re-enable speaker */
  277. gpio_set_value(PALMTE_SPEAKER_GPIO, 1);
  278. printk(KERN_INFO "PM: speaker on\n");
  279. }
  280. }
  281. static void __init palmte_misc_gpio_setup(void)
  282. {
  283. /* Set TSC2102 PINTDAV pin as input (used by TSC2102 driver) */
  284. if (gpio_request(PALMTE_PINTDAV_GPIO, "TSC2102 PINTDAV") < 0) {
  285. printk(KERN_ERR "Could not reserve PINTDAV GPIO!\n");
  286. return;
  287. }
  288. gpio_direction_input(PALMTE_PINTDAV_GPIO);
  289. /* Set USB-or-DC-IN pin as input (unused) */
  290. if (gpio_request(PALMTE_USB_OR_DC_GPIO, "USB/DC-IN") < 0) {
  291. printk(KERN_ERR "Could not reserve cable signal GPIO!\n");
  292. return;
  293. }
  294. gpio_direction_input(PALMTE_USB_OR_DC_GPIO);
  295. }
  296. static void __init omap_palmte_init(void)
  297. {
  298. omap_board_config = palmte_config;
  299. omap_board_config_size = ARRAY_SIZE(palmte_config);
  300. platform_add_devices(palmte_devices, ARRAY_SIZE(palmte_devices));
  301. spi_register_board_info(palmte_spi_info, ARRAY_SIZE(palmte_spi_info));
  302. palmte_misc_gpio_setup();
  303. omap_serial_init();
  304. omap_register_i2c_bus(1, 100, NULL, 0);
  305. }
  306. static void __init omap_palmte_map_io(void)
  307. {
  308. omap1_map_common_io();
  309. }
  310. MACHINE_START(OMAP_PALMTE, "OMAP310 based Palm Tungsten E")
  311. .phys_io = 0xfff00000,
  312. .io_pg_offst = ((0xfef00000) >> 18) & 0xfffc,
  313. .boot_params = 0x10000100,
  314. .map_io = omap_palmte_map_io,
  315. .init_irq = omap_palmte_init_irq,
  316. .init_machine = omap_palmte_init,
  317. .timer = &omap_timer,
  318. MACHINE_END