board-palmte.c 9.3 KB

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