board-palmte.c 11 KB

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