h3600.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514
  1. /*
  2. * Hardware definitions for Compaq iPAQ H3xxx Handheld Computers
  3. *
  4. * Copyright 2000,1 Compaq Computer Corporation.
  5. *
  6. * Use consistent with the GNU GPL is permitted,
  7. * provided that this copyright notice is
  8. * preserved in its entirety in all copies and derived works.
  9. *
  10. * COMPAQ COMPUTER CORPORATION MAKES NO WARRANTIES, EXPRESSED OR IMPLIED,
  11. * AS TO THE USEFULNESS OR CORRECTNESS OF THIS CODE OR ITS
  12. * FITNESS FOR ANY PARTICULAR PURPOSE.
  13. *
  14. * Author: Jamey Hicks.
  15. *
  16. * History:
  17. *
  18. * 2001-10-?? Andrew Christian Added support for iPAQ H3800
  19. * and abstracted EGPIO interface.
  20. *
  21. */
  22. #include <linux/module.h>
  23. #include <linux/init.h>
  24. #include <linux/kernel.h>
  25. #include <linux/tty.h>
  26. #include <linux/pm.h>
  27. #include <linux/device.h>
  28. #include <linux/mtd/mtd.h>
  29. #include <linux/mtd/partitions.h>
  30. #include <linux/serial_core.h>
  31. #include <asm/irq.h>
  32. #include <mach/hardware.h>
  33. #include <asm/mach-types.h>
  34. #include <asm/setup.h>
  35. #include <asm/mach/irq.h>
  36. #include <asm/mach/arch.h>
  37. #include <asm/mach/flash.h>
  38. #include <asm/mach/irda.h>
  39. #include <asm/mach/map.h>
  40. #include <asm/mach/serial_sa1100.h>
  41. #include <mach/h3600.h>
  42. #include <mach/h3600_gpio.h>
  43. #include "generic.h"
  44. struct ipaq_model_ops ipaq_model_ops;
  45. EXPORT_SYMBOL(ipaq_model_ops);
  46. static struct mtd_partition h3xxx_partitions[] = {
  47. {
  48. .name = "H3XXX boot firmware",
  49. .size = 0x00040000,
  50. .offset = 0,
  51. .mask_flags = MTD_WRITEABLE, /* force read-only */
  52. }, {
  53. #ifdef CONFIG_MTD_2PARTS_IPAQ
  54. .name = "H3XXX root jffs2",
  55. .size = MTDPART_SIZ_FULL,
  56. .offset = 0x00040000,
  57. #else
  58. .name = "H3XXX kernel",
  59. .size = 0x00080000,
  60. .offset = 0x00040000,
  61. }, {
  62. .name = "H3XXX params",
  63. .size = 0x00040000,
  64. .offset = 0x000C0000,
  65. }, {
  66. #ifdef CONFIG_JFFS2_FS
  67. .name = "H3XXX root jffs2",
  68. .size = MTDPART_SIZ_FULL,
  69. .offset = 0x00100000,
  70. #else
  71. .name = "H3XXX initrd",
  72. .size = 0x00100000,
  73. .offset = 0x00100000,
  74. }, {
  75. .name = "H3XXX root cramfs",
  76. .size = 0x00300000,
  77. .offset = 0x00200000,
  78. }, {
  79. .name = "H3XXX usr cramfs",
  80. .size = 0x00800000,
  81. .offset = 0x00500000,
  82. }, {
  83. .name = "H3XXX usr local",
  84. .size = MTDPART_SIZ_FULL,
  85. .offset = 0x00d00000,
  86. #endif
  87. #endif
  88. }
  89. };
  90. static void h3xxx_set_vpp(int vpp)
  91. {
  92. assign_h3600_egpio(IPAQ_EGPIO_VPP_ON, vpp);
  93. }
  94. static struct flash_platform_data h3xxx_flash_data = {
  95. .map_name = "cfi_probe",
  96. .set_vpp = h3xxx_set_vpp,
  97. .parts = h3xxx_partitions,
  98. .nr_parts = ARRAY_SIZE(h3xxx_partitions),
  99. };
  100. static struct resource h3xxx_flash_resource = {
  101. .start = SA1100_CS0_PHYS,
  102. .end = SA1100_CS0_PHYS + SZ_32M - 1,
  103. .flags = IORESOURCE_MEM,
  104. };
  105. /*
  106. * This turns the IRDA power on or off on the Compaq H3600
  107. */
  108. static int h3600_irda_set_power(struct device *dev, unsigned int state)
  109. {
  110. assign_h3600_egpio( IPAQ_EGPIO_IR_ON, state );
  111. return 0;
  112. }
  113. static void h3600_irda_set_speed(struct device *dev, unsigned int speed)
  114. {
  115. if (speed < 4000000) {
  116. clr_h3600_egpio(IPAQ_EGPIO_IR_FSEL);
  117. } else {
  118. set_h3600_egpio(IPAQ_EGPIO_IR_FSEL);
  119. }
  120. }
  121. static struct irda_platform_data h3600_irda_data = {
  122. .set_power = h3600_irda_set_power,
  123. .set_speed = h3600_irda_set_speed,
  124. };
  125. static void h3xxx_mach_init(void)
  126. {
  127. sa11x0_set_flash_data(&h3xxx_flash_data, &h3xxx_flash_resource, 1);
  128. sa11x0_set_irda_data(&h3600_irda_data);
  129. }
  130. /*
  131. * low-level UART features
  132. */
  133. static void h3600_uart_set_mctrl(struct uart_port *port, u_int mctrl)
  134. {
  135. if (port->mapbase == _Ser3UTCR0) {
  136. if (mctrl & TIOCM_RTS)
  137. GPCR = GPIO_H3600_COM_RTS;
  138. else
  139. GPSR = GPIO_H3600_COM_RTS;
  140. }
  141. }
  142. static u_int h3600_uart_get_mctrl(struct uart_port *port)
  143. {
  144. u_int ret = TIOCM_CD | TIOCM_CTS | TIOCM_DSR;
  145. if (port->mapbase == _Ser3UTCR0) {
  146. int gplr = GPLR;
  147. /* DCD and CTS bits are inverted in GPLR by RS232 transceiver */
  148. if (gplr & GPIO_H3600_COM_DCD)
  149. ret &= ~TIOCM_CD;
  150. if (gplr & GPIO_H3600_COM_CTS)
  151. ret &= ~TIOCM_CTS;
  152. }
  153. return ret;
  154. }
  155. static void h3600_uart_pm(struct uart_port *port, u_int state, u_int oldstate)
  156. {
  157. if (port->mapbase == _Ser2UTCR0) { /* TODO: REMOVE THIS */
  158. assign_h3600_egpio(IPAQ_EGPIO_IR_ON, !state);
  159. } else if (port->mapbase == _Ser3UTCR0) {
  160. assign_h3600_egpio(IPAQ_EGPIO_RS232_ON, !state);
  161. }
  162. }
  163. /*
  164. * Enable/Disable wake up events for this serial port.
  165. * Obviously, we only support this on the normal COM port.
  166. */
  167. static int h3600_uart_set_wake(struct uart_port *port, u_int enable)
  168. {
  169. int err = -EINVAL;
  170. if (port->mapbase == _Ser3UTCR0) {
  171. if (enable)
  172. PWER |= PWER_GPIO23 | PWER_GPIO25; /* DCD and CTS */
  173. else
  174. PWER &= ~(PWER_GPIO23 | PWER_GPIO25); /* DCD and CTS */
  175. err = 0;
  176. }
  177. return err;
  178. }
  179. static struct sa1100_port_fns h3600_port_fns __initdata = {
  180. .set_mctrl = h3600_uart_set_mctrl,
  181. .get_mctrl = h3600_uart_get_mctrl,
  182. .pm = h3600_uart_pm,
  183. .set_wake = h3600_uart_set_wake,
  184. };
  185. /*
  186. * helper for sa1100fb
  187. */
  188. static void h3xxx_lcd_power(int enable)
  189. {
  190. assign_h3600_egpio(IPAQ_EGPIO_LCD_POWER, enable);
  191. }
  192. static struct map_desc h3600_io_desc[] __initdata = {
  193. { /* static memory bank 2 CS#2 */
  194. .virtual = H3600_BANK_2_VIRT,
  195. .pfn = __phys_to_pfn(SA1100_CS2_PHYS),
  196. .length = 0x02800000,
  197. .type = MT_DEVICE
  198. }, { /* static memory bank 4 CS#4 */
  199. .virtual = H3600_BANK_4_VIRT,
  200. .pfn = __phys_to_pfn(SA1100_CS4_PHYS),
  201. .length = 0x00800000,
  202. .type = MT_DEVICE
  203. }, { /* EGPIO 0 CS#5 */
  204. .virtual = H3600_EGPIO_VIRT,
  205. .pfn = __phys_to_pfn(H3600_EGPIO_PHYS),
  206. .length = 0x01000000,
  207. .type = MT_DEVICE
  208. }
  209. };
  210. /*
  211. * Common map_io initialization
  212. */
  213. static void __init h3xxx_map_io(void)
  214. {
  215. sa1100_map_io();
  216. iotable_init(h3600_io_desc, ARRAY_SIZE(h3600_io_desc));
  217. sa1100_register_uart_fns(&h3600_port_fns);
  218. sa1100_register_uart(0, 3); /* Common serial port */
  219. // sa1100_register_uart(1, 1); /* Microcontroller on 3100/3600 */
  220. /* Ensure those pins are outputs and driving low */
  221. PPDR |= PPC_TXD4 | PPC_SCLK | PPC_SFRM;
  222. PPSR &= ~(PPC_TXD4 | PPC_SCLK | PPC_SFRM);
  223. /* Configure suspend conditions */
  224. PGSR = 0;
  225. PWER = PWER_GPIO0 | PWER_RTC;
  226. PCFR = PCFR_OPDE;
  227. PSDR = 0;
  228. sa1100fb_lcd_power = h3xxx_lcd_power;
  229. }
  230. static __inline__ void do_blank(int setp)
  231. {
  232. if (ipaq_model_ops.blank_callback)
  233. ipaq_model_ops.blank_callback(1-setp);
  234. }
  235. /************************* H3100 *************************/
  236. #ifdef CONFIG_SA1100_H3100
  237. #define H3100_EGPIO (*(volatile unsigned int *)H3600_EGPIO_VIRT)
  238. static unsigned int h3100_egpio = 0;
  239. static void h3100_control_egpio(enum ipaq_egpio_type x, int setp)
  240. {
  241. unsigned int egpio = 0;
  242. long gpio = 0;
  243. unsigned long flags;
  244. switch (x) {
  245. case IPAQ_EGPIO_LCD_POWER:
  246. egpio |= EGPIO_H3600_LCD_ON;
  247. gpio |= GPIO_H3100_LCD_3V_ON;
  248. do_blank(setp);
  249. break;
  250. case IPAQ_EGPIO_LCD_ENABLE:
  251. break;
  252. case IPAQ_EGPIO_CODEC_NRESET:
  253. egpio |= EGPIO_H3600_CODEC_NRESET;
  254. break;
  255. case IPAQ_EGPIO_AUDIO_ON:
  256. gpio |= GPIO_H3100_AUD_PWR_ON
  257. | GPIO_H3100_AUD_ON;
  258. break;
  259. case IPAQ_EGPIO_QMUTE:
  260. gpio |= GPIO_H3100_QMUTE;
  261. break;
  262. case IPAQ_EGPIO_OPT_NVRAM_ON:
  263. egpio |= EGPIO_H3600_OPT_NVRAM_ON;
  264. break;
  265. case IPAQ_EGPIO_OPT_ON:
  266. egpio |= EGPIO_H3600_OPT_ON;
  267. break;
  268. case IPAQ_EGPIO_CARD_RESET:
  269. egpio |= EGPIO_H3600_CARD_RESET;
  270. break;
  271. case IPAQ_EGPIO_OPT_RESET:
  272. egpio |= EGPIO_H3600_OPT_RESET;
  273. break;
  274. case IPAQ_EGPIO_IR_ON:
  275. gpio |= GPIO_H3100_IR_ON;
  276. break;
  277. case IPAQ_EGPIO_IR_FSEL:
  278. gpio |= GPIO_H3100_IR_FSEL;
  279. break;
  280. case IPAQ_EGPIO_RS232_ON:
  281. egpio |= EGPIO_H3600_RS232_ON;
  282. break;
  283. case IPAQ_EGPIO_VPP_ON:
  284. egpio |= EGPIO_H3600_VPP_ON;
  285. break;
  286. }
  287. if (egpio || gpio) {
  288. local_irq_save(flags);
  289. if (setp) {
  290. h3100_egpio |= egpio;
  291. GPSR = gpio;
  292. } else {
  293. h3100_egpio &= ~egpio;
  294. GPCR = gpio;
  295. }
  296. H3100_EGPIO = h3100_egpio;
  297. local_irq_restore(flags);
  298. }
  299. }
  300. static unsigned long h3100_read_egpio(void)
  301. {
  302. return h3100_egpio;
  303. }
  304. static int h3100_pm_callback(int req)
  305. {
  306. if (ipaq_model_ops.pm_callback_aux)
  307. return ipaq_model_ops.pm_callback_aux(req);
  308. return 0;
  309. }
  310. static struct ipaq_model_ops h3100_model_ops __initdata = {
  311. .generic_name = "3100",
  312. .control = h3100_control_egpio,
  313. .read = h3100_read_egpio,
  314. .pm_callback = h3100_pm_callback
  315. };
  316. #define H3100_DIRECT_EGPIO (GPIO_H3100_BT_ON \
  317. | GPIO_H3100_GPIO3 \
  318. | GPIO_H3100_QMUTE \
  319. | GPIO_H3100_LCD_3V_ON \
  320. | GPIO_H3100_AUD_ON \
  321. | GPIO_H3100_AUD_PWR_ON \
  322. | GPIO_H3100_IR_ON \
  323. | GPIO_H3100_IR_FSEL)
  324. static void __init h3100_map_io(void)
  325. {
  326. h3xxx_map_io();
  327. /* Initialize h3100-specific values here */
  328. GPCR = 0x0fffffff; /* All outputs are set low by default */
  329. GPDR = GPIO_H3600_COM_RTS | GPIO_H3600_L3_CLOCK |
  330. GPIO_H3600_L3_MODE | GPIO_H3600_L3_DATA |
  331. GPIO_H3600_CLK_SET1 | GPIO_H3600_CLK_SET0 |
  332. H3100_DIRECT_EGPIO;
  333. /* Older bootldrs put GPIO2-9 in alternate mode on the
  334. assumption that they are used for video */
  335. GAFR &= ~H3100_DIRECT_EGPIO;
  336. H3100_EGPIO = h3100_egpio;
  337. ipaq_model_ops = h3100_model_ops;
  338. }
  339. MACHINE_START(H3100, "Compaq iPAQ H3100")
  340. .phys_io = 0x80000000,
  341. .io_pg_offst = ((0xf8000000) >> 18) & 0xfffc,
  342. .boot_params = 0xc0000100,
  343. .map_io = h3100_map_io,
  344. .init_irq = sa1100_init_irq,
  345. .timer = &sa1100_timer,
  346. .init_machine = h3xxx_mach_init,
  347. MACHINE_END
  348. #endif /* CONFIG_SA1100_H3100 */
  349. /************************* H3600 *************************/
  350. #ifdef CONFIG_SA1100_H3600
  351. #define H3600_EGPIO (*(volatile unsigned int *)H3600_EGPIO_VIRT)
  352. static unsigned int h3600_egpio = EGPIO_H3600_RS232_ON;
  353. static void h3600_control_egpio(enum ipaq_egpio_type x, int setp)
  354. {
  355. unsigned int egpio = 0;
  356. unsigned long flags;
  357. switch (x) {
  358. case IPAQ_EGPIO_LCD_POWER:
  359. egpio |= EGPIO_H3600_LCD_ON |
  360. EGPIO_H3600_LCD_PCI |
  361. EGPIO_H3600_LCD_5V_ON |
  362. EGPIO_H3600_LVDD_ON;
  363. do_blank(setp);
  364. break;
  365. case IPAQ_EGPIO_LCD_ENABLE:
  366. break;
  367. case IPAQ_EGPIO_CODEC_NRESET:
  368. egpio |= EGPIO_H3600_CODEC_NRESET;
  369. break;
  370. case IPAQ_EGPIO_AUDIO_ON:
  371. egpio |= EGPIO_H3600_AUD_AMP_ON |
  372. EGPIO_H3600_AUD_PWR_ON;
  373. break;
  374. case IPAQ_EGPIO_QMUTE:
  375. egpio |= EGPIO_H3600_QMUTE;
  376. break;
  377. case IPAQ_EGPIO_OPT_NVRAM_ON:
  378. egpio |= EGPIO_H3600_OPT_NVRAM_ON;
  379. break;
  380. case IPAQ_EGPIO_OPT_ON:
  381. egpio |= EGPIO_H3600_OPT_ON;
  382. break;
  383. case IPAQ_EGPIO_CARD_RESET:
  384. egpio |= EGPIO_H3600_CARD_RESET;
  385. break;
  386. case IPAQ_EGPIO_OPT_RESET:
  387. egpio |= EGPIO_H3600_OPT_RESET;
  388. break;
  389. case IPAQ_EGPIO_IR_ON:
  390. egpio |= EGPIO_H3600_IR_ON;
  391. break;
  392. case IPAQ_EGPIO_IR_FSEL:
  393. egpio |= EGPIO_H3600_IR_FSEL;
  394. break;
  395. case IPAQ_EGPIO_RS232_ON:
  396. egpio |= EGPIO_H3600_RS232_ON;
  397. break;
  398. case IPAQ_EGPIO_VPP_ON:
  399. egpio |= EGPIO_H3600_VPP_ON;
  400. break;
  401. }
  402. if (egpio) {
  403. local_irq_save(flags);
  404. if (setp)
  405. h3600_egpio |= egpio;
  406. else
  407. h3600_egpio &= ~egpio;
  408. H3600_EGPIO = h3600_egpio;
  409. local_irq_restore(flags);
  410. }
  411. }
  412. static unsigned long h3600_read_egpio(void)
  413. {
  414. return h3600_egpio;
  415. }
  416. static int h3600_pm_callback(int req)
  417. {
  418. if (ipaq_model_ops.pm_callback_aux)
  419. return ipaq_model_ops.pm_callback_aux(req);
  420. return 0;
  421. }
  422. static struct ipaq_model_ops h3600_model_ops __initdata = {
  423. .generic_name = "3600",
  424. .control = h3600_control_egpio,
  425. .read = h3600_read_egpio,
  426. .pm_callback = h3600_pm_callback
  427. };
  428. static void __init h3600_map_io(void)
  429. {
  430. h3xxx_map_io();
  431. /* Initialize h3600-specific values here */
  432. GPCR = 0x0fffffff; /* All outputs are set low by default */
  433. GPDR = GPIO_H3600_COM_RTS | GPIO_H3600_L3_CLOCK |
  434. GPIO_H3600_L3_MODE | GPIO_H3600_L3_DATA |
  435. GPIO_H3600_CLK_SET1 | GPIO_H3600_CLK_SET0 |
  436. GPIO_LDD15 | GPIO_LDD14 | GPIO_LDD13 | GPIO_LDD12 |
  437. GPIO_LDD11 | GPIO_LDD10 | GPIO_LDD9 | GPIO_LDD8;
  438. H3600_EGPIO = h3600_egpio; /* Maintains across sleep? */
  439. ipaq_model_ops = h3600_model_ops;
  440. }
  441. MACHINE_START(H3600, "Compaq iPAQ H3600")
  442. .phys_io = 0x80000000,
  443. .io_pg_offst = ((0xf8000000) >> 18) & 0xfffc,
  444. .boot_params = 0xc0000100,
  445. .map_io = h3600_map_io,
  446. .init_irq = sa1100_init_irq,
  447. .timer = &sa1100_timer,
  448. .init_machine = h3xxx_mach_init,
  449. MACHINE_END
  450. #endif /* CONFIG_SA1100_H3600 */