board-palmte.c 10 KB

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