h3600.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910
  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/config.h>
  23. #include <linux/module.h>
  24. #include <linux/init.h>
  25. #include <linux/kernel.h>
  26. #include <linux/tty.h>
  27. #include <linux/pm.h>
  28. #include <linux/device.h>
  29. #include <linux/mtd/mtd.h>
  30. #include <linux/mtd/partitions.h>
  31. #include <linux/serial_core.h>
  32. #include <asm/irq.h>
  33. #include <asm/hardware.h>
  34. #include <asm/mach-types.h>
  35. #include <asm/setup.h>
  36. #include <asm/mach/irq.h>
  37. #include <asm/mach/arch.h>
  38. #include <asm/mach/flash.h>
  39. #include <asm/mach/irda.h>
  40. #include <asm/mach/map.h>
  41. #include <asm/mach/serial_sa1100.h>
  42. #include <asm/arch/h3600.h>
  43. #if defined (CONFIG_SA1100_H3600) || defined (CONFIG_SA1100_H3100)
  44. #include <asm/arch/h3600_gpio.h>
  45. #endif
  46. #ifdef CONFIG_SA1100_H3800
  47. #include <asm/arch/h3600_asic.h>
  48. #endif
  49. #include "generic.h"
  50. struct ipaq_model_ops ipaq_model_ops;
  51. EXPORT_SYMBOL(ipaq_model_ops);
  52. static struct mtd_partition h3xxx_partitions[] = {
  53. {
  54. .name = "H3XXX boot firmware",
  55. .size = 0x00040000,
  56. .offset = 0,
  57. .mask_flags = MTD_WRITEABLE, /* force read-only */
  58. }, {
  59. #ifdef CONFIG_MTD_2PARTS_IPAQ
  60. .name = "H3XXX root jffs2",
  61. .size = MTDPART_SIZ_FULL,
  62. .offset = 0x00040000,
  63. #else
  64. .name = "H3XXX kernel",
  65. .size = 0x00080000,
  66. .offset = 0x00040000,
  67. }, {
  68. .name = "H3XXX params",
  69. .size = 0x00040000,
  70. .offset = 0x000C0000,
  71. }, {
  72. #ifdef CONFIG_JFFS2_FS
  73. .name = "H3XXX root jffs2",
  74. .size = MTDPART_SIZ_FULL,
  75. .offset = 0x00100000,
  76. #else
  77. .name = "H3XXX initrd",
  78. .size = 0x00100000,
  79. .offset = 0x00100000,
  80. }, {
  81. .name = "H3XXX root cramfs",
  82. .size = 0x00300000,
  83. .offset = 0x00200000,
  84. }, {
  85. .name = "H3XXX usr cramfs",
  86. .size = 0x00800000,
  87. .offset = 0x00500000,
  88. }, {
  89. .name = "H3XXX usr local",
  90. .size = MTDPART_SIZ_FULL,
  91. .offset = 0x00d00000,
  92. #endif
  93. #endif
  94. }
  95. };
  96. static void h3xxx_set_vpp(int vpp)
  97. {
  98. assign_h3600_egpio(IPAQ_EGPIO_VPP_ON, vpp);
  99. }
  100. static struct flash_platform_data h3xxx_flash_data = {
  101. .map_name = "cfi_probe",
  102. .set_vpp = h3xxx_set_vpp,
  103. .parts = h3xxx_partitions,
  104. .nr_parts = ARRAY_SIZE(h3xxx_partitions),
  105. };
  106. static struct resource h3xxx_flash_resource = {
  107. .start = SA1100_CS0_PHYS,
  108. .end = SA1100_CS0_PHYS + SZ_32M - 1,
  109. .flags = IORESOURCE_MEM,
  110. };
  111. /*
  112. * This turns the IRDA power on or off on the Compaq H3600
  113. */
  114. static int h3600_irda_set_power(struct device *dev, unsigned int state)
  115. {
  116. assign_h3600_egpio( IPAQ_EGPIO_IR_ON, state );
  117. return 0;
  118. }
  119. static void h3600_irda_set_speed(struct device *dev, unsigned int speed)
  120. {
  121. if (speed < 4000000) {
  122. clr_h3600_egpio(IPAQ_EGPIO_IR_FSEL);
  123. } else {
  124. set_h3600_egpio(IPAQ_EGPIO_IR_FSEL);
  125. }
  126. }
  127. static struct irda_platform_data h3600_irda_data = {
  128. .set_power = h3600_irda_set_power,
  129. .set_speed = h3600_irda_set_speed,
  130. };
  131. static void h3xxx_mach_init(void)
  132. {
  133. sa11x0_set_flash_data(&h3xxx_flash_data, &h3xxx_flash_resource, 1);
  134. sa11x0_set_irda_data(&h3600_irda_data);
  135. }
  136. /*
  137. * low-level UART features
  138. */
  139. static void h3600_uart_set_mctrl(struct uart_port *port, u_int mctrl)
  140. {
  141. if (port->mapbase == _Ser3UTCR0) {
  142. if (mctrl & TIOCM_RTS)
  143. GPCR = GPIO_H3600_COM_RTS;
  144. else
  145. GPSR = GPIO_H3600_COM_RTS;
  146. }
  147. }
  148. static u_int h3600_uart_get_mctrl(struct uart_port *port)
  149. {
  150. u_int ret = TIOCM_CD | TIOCM_CTS | TIOCM_DSR;
  151. if (port->mapbase == _Ser3UTCR0) {
  152. int gplr = GPLR;
  153. /* DCD and CTS bits are inverted in GPLR by RS232 transceiver */
  154. if (gplr & GPIO_H3600_COM_DCD)
  155. ret &= ~TIOCM_CD;
  156. if (gplr & GPIO_H3600_COM_CTS)
  157. ret &= ~TIOCM_CTS;
  158. }
  159. return ret;
  160. }
  161. static void h3600_uart_pm(struct uart_port *port, u_int state, u_int oldstate)
  162. {
  163. if (port->mapbase == _Ser2UTCR0) { /* TODO: REMOVE THIS */
  164. assign_h3600_egpio(IPAQ_EGPIO_IR_ON, !state);
  165. } else if (port->mapbase == _Ser3UTCR0) {
  166. assign_h3600_egpio(IPAQ_EGPIO_RS232_ON, !state);
  167. }
  168. }
  169. /*
  170. * Enable/Disable wake up events for this serial port.
  171. * Obviously, we only support this on the normal COM port.
  172. */
  173. static int h3600_uart_set_wake(struct uart_port *port, u_int enable)
  174. {
  175. int err = -EINVAL;
  176. if (port->mapbase == _Ser3UTCR0) {
  177. if (enable)
  178. PWER |= PWER_GPIO23 | PWER_GPIO25; /* DCD and CTS */
  179. else
  180. PWER &= ~(PWER_GPIO23 | PWER_GPIO25); /* DCD and CTS */
  181. err = 0;
  182. }
  183. return err;
  184. }
  185. static struct sa1100_port_fns h3600_port_fns __initdata = {
  186. .set_mctrl = h3600_uart_set_mctrl,
  187. .get_mctrl = h3600_uart_get_mctrl,
  188. .pm = h3600_uart_pm,
  189. .set_wake = h3600_uart_set_wake,
  190. };
  191. /*
  192. * helper for sa1100fb
  193. */
  194. static void h3xxx_lcd_power(int enable)
  195. {
  196. assign_h3600_egpio(IPAQ_EGPIO_LCD_POWER, enable);
  197. }
  198. static struct map_desc h3600_io_desc[] __initdata = {
  199. { /* static memory bank 2 CS#2 */
  200. .virtual = H3600_BANK_2_VIRT,
  201. .pfn = __phys_to_pfn(SA1100_CS2_PHYS),
  202. .length = 0x02800000,
  203. .type = MT_DEVICE
  204. }, { /* static memory bank 4 CS#4 */
  205. .virtual = H3600_BANK_4_VIRT,
  206. .pfn = __phys_to_pfn(SA1100_CS4_PHYS),
  207. .length = 0x00800000,
  208. .type = MT_DEVICE
  209. }, { /* EGPIO 0 CS#5 */
  210. .virtual = H3600_EGPIO_VIRT,
  211. .pfn = __phys_to_pfn(H3600_EGPIO_PHYS),
  212. .length = 0x01000000,
  213. .type = MT_DEVICE
  214. }
  215. };
  216. /*
  217. * Common map_io initialization
  218. */
  219. static void __init h3xxx_map_io(void)
  220. {
  221. sa1100_map_io();
  222. iotable_init(h3600_io_desc, ARRAY_SIZE(h3600_io_desc));
  223. sa1100_register_uart_fns(&h3600_port_fns);
  224. sa1100_register_uart(0, 3); /* Common serial port */
  225. // sa1100_register_uart(1, 1); /* Microcontroller on 3100/3600 */
  226. /* Ensure those pins are outputs and driving low */
  227. PPDR |= PPC_TXD4 | PPC_SCLK | PPC_SFRM;
  228. PPSR &= ~(PPC_TXD4 | PPC_SCLK | PPC_SFRM);
  229. /* Configure suspend conditions */
  230. PGSR = 0;
  231. PWER = PWER_GPIO0 | PWER_RTC;
  232. PCFR = PCFR_OPDE;
  233. PSDR = 0;
  234. sa1100fb_lcd_power = h3xxx_lcd_power;
  235. }
  236. static __inline__ void do_blank(int setp)
  237. {
  238. if (ipaq_model_ops.blank_callback)
  239. ipaq_model_ops.blank_callback(1-setp);
  240. }
  241. /************************* H3100 *************************/
  242. #ifdef CONFIG_SA1100_H3100
  243. #define H3100_EGPIO (*(volatile unsigned int *)H3600_EGPIO_VIRT)
  244. static unsigned int h3100_egpio = 0;
  245. static void h3100_control_egpio(enum ipaq_egpio_type x, int setp)
  246. {
  247. unsigned int egpio = 0;
  248. long gpio = 0;
  249. unsigned long flags;
  250. switch (x) {
  251. case IPAQ_EGPIO_LCD_POWER:
  252. egpio |= EGPIO_H3600_LCD_ON;
  253. gpio |= GPIO_H3100_LCD_3V_ON;
  254. do_blank(setp);
  255. break;
  256. case IPAQ_EGPIO_LCD_ENABLE:
  257. break;
  258. case IPAQ_EGPIO_CODEC_NRESET:
  259. egpio |= EGPIO_H3600_CODEC_NRESET;
  260. break;
  261. case IPAQ_EGPIO_AUDIO_ON:
  262. gpio |= GPIO_H3100_AUD_PWR_ON
  263. | GPIO_H3100_AUD_ON;
  264. break;
  265. case IPAQ_EGPIO_QMUTE:
  266. gpio |= GPIO_H3100_QMUTE;
  267. break;
  268. case IPAQ_EGPIO_OPT_NVRAM_ON:
  269. egpio |= EGPIO_H3600_OPT_NVRAM_ON;
  270. break;
  271. case IPAQ_EGPIO_OPT_ON:
  272. egpio |= EGPIO_H3600_OPT_ON;
  273. break;
  274. case IPAQ_EGPIO_CARD_RESET:
  275. egpio |= EGPIO_H3600_CARD_RESET;
  276. break;
  277. case IPAQ_EGPIO_OPT_RESET:
  278. egpio |= EGPIO_H3600_OPT_RESET;
  279. break;
  280. case IPAQ_EGPIO_IR_ON:
  281. gpio |= GPIO_H3100_IR_ON;
  282. break;
  283. case IPAQ_EGPIO_IR_FSEL:
  284. gpio |= GPIO_H3100_IR_FSEL;
  285. break;
  286. case IPAQ_EGPIO_RS232_ON:
  287. egpio |= EGPIO_H3600_RS232_ON;
  288. break;
  289. case IPAQ_EGPIO_VPP_ON:
  290. egpio |= EGPIO_H3600_VPP_ON;
  291. break;
  292. }
  293. if (egpio || gpio) {
  294. local_irq_save(flags);
  295. if (setp) {
  296. h3100_egpio |= egpio;
  297. GPSR = gpio;
  298. } else {
  299. h3100_egpio &= ~egpio;
  300. GPCR = gpio;
  301. }
  302. H3100_EGPIO = h3100_egpio;
  303. local_irq_restore(flags);
  304. }
  305. }
  306. static unsigned long h3100_read_egpio(void)
  307. {
  308. return h3100_egpio;
  309. }
  310. static int h3100_pm_callback(int req)
  311. {
  312. if (ipaq_model_ops.pm_callback_aux)
  313. return ipaq_model_ops.pm_callback_aux(req);
  314. return 0;
  315. }
  316. static struct ipaq_model_ops h3100_model_ops __initdata = {
  317. .generic_name = "3100",
  318. .control = h3100_control_egpio,
  319. .read = h3100_read_egpio,
  320. .pm_callback = h3100_pm_callback
  321. };
  322. #define H3100_DIRECT_EGPIO (GPIO_H3100_BT_ON \
  323. | GPIO_H3100_GPIO3 \
  324. | GPIO_H3100_QMUTE \
  325. | GPIO_H3100_LCD_3V_ON \
  326. | GPIO_H3100_AUD_ON \
  327. | GPIO_H3100_AUD_PWR_ON \
  328. | GPIO_H3100_IR_ON \
  329. | GPIO_H3100_IR_FSEL)
  330. static void __init h3100_map_io(void)
  331. {
  332. h3xxx_map_io();
  333. /* Initialize h3100-specific values here */
  334. GPCR = 0x0fffffff; /* All outputs are set low by default */
  335. GPDR = GPIO_H3600_COM_RTS | GPIO_H3600_L3_CLOCK |
  336. GPIO_H3600_L3_MODE | GPIO_H3600_L3_DATA |
  337. GPIO_H3600_CLK_SET1 | GPIO_H3600_CLK_SET0 |
  338. H3100_DIRECT_EGPIO;
  339. /* Older bootldrs put GPIO2-9 in alternate mode on the
  340. assumption that they are used for video */
  341. GAFR &= ~H3100_DIRECT_EGPIO;
  342. H3100_EGPIO = h3100_egpio;
  343. ipaq_model_ops = h3100_model_ops;
  344. }
  345. MACHINE_START(H3100, "Compaq iPAQ H3100")
  346. .phys_ram = 0xc0000000,
  347. .phys_io = 0x80000000,
  348. .io_pg_offst = ((0xf8000000) >> 18) & 0xfffc,
  349. .boot_params = 0xc0000100,
  350. .map_io = h3100_map_io,
  351. .init_irq = sa1100_init_irq,
  352. .timer = &sa1100_timer,
  353. .init_machine = h3xxx_mach_init,
  354. MACHINE_END
  355. #endif /* CONFIG_SA1100_H3100 */
  356. /************************* H3600 *************************/
  357. #ifdef CONFIG_SA1100_H3600
  358. #define H3600_EGPIO (*(volatile unsigned int *)H3600_EGPIO_VIRT)
  359. static unsigned int h3600_egpio = EGPIO_H3600_RS232_ON;
  360. static void h3600_control_egpio(enum ipaq_egpio_type x, int setp)
  361. {
  362. unsigned int egpio = 0;
  363. unsigned long flags;
  364. switch (x) {
  365. case IPAQ_EGPIO_LCD_POWER:
  366. egpio |= EGPIO_H3600_LCD_ON |
  367. EGPIO_H3600_LCD_PCI |
  368. EGPIO_H3600_LCD_5V_ON |
  369. EGPIO_H3600_LVDD_ON;
  370. do_blank(setp);
  371. break;
  372. case IPAQ_EGPIO_LCD_ENABLE:
  373. break;
  374. case IPAQ_EGPIO_CODEC_NRESET:
  375. egpio |= EGPIO_H3600_CODEC_NRESET;
  376. break;
  377. case IPAQ_EGPIO_AUDIO_ON:
  378. egpio |= EGPIO_H3600_AUD_AMP_ON |
  379. EGPIO_H3600_AUD_PWR_ON;
  380. break;
  381. case IPAQ_EGPIO_QMUTE:
  382. egpio |= EGPIO_H3600_QMUTE;
  383. break;
  384. case IPAQ_EGPIO_OPT_NVRAM_ON:
  385. egpio |= EGPIO_H3600_OPT_NVRAM_ON;
  386. break;
  387. case IPAQ_EGPIO_OPT_ON:
  388. egpio |= EGPIO_H3600_OPT_ON;
  389. break;
  390. case IPAQ_EGPIO_CARD_RESET:
  391. egpio |= EGPIO_H3600_CARD_RESET;
  392. break;
  393. case IPAQ_EGPIO_OPT_RESET:
  394. egpio |= EGPIO_H3600_OPT_RESET;
  395. break;
  396. case IPAQ_EGPIO_IR_ON:
  397. egpio |= EGPIO_H3600_IR_ON;
  398. break;
  399. case IPAQ_EGPIO_IR_FSEL:
  400. egpio |= EGPIO_H3600_IR_FSEL;
  401. break;
  402. case IPAQ_EGPIO_RS232_ON:
  403. egpio |= EGPIO_H3600_RS232_ON;
  404. break;
  405. case IPAQ_EGPIO_VPP_ON:
  406. egpio |= EGPIO_H3600_VPP_ON;
  407. break;
  408. }
  409. if (egpio) {
  410. local_irq_save(flags);
  411. if (setp)
  412. h3600_egpio |= egpio;
  413. else
  414. h3600_egpio &= ~egpio;
  415. H3600_EGPIO = h3600_egpio;
  416. local_irq_restore(flags);
  417. }
  418. }
  419. static unsigned long h3600_read_egpio(void)
  420. {
  421. return h3600_egpio;
  422. }
  423. static int h3600_pm_callback(int req)
  424. {
  425. if (ipaq_model_ops.pm_callback_aux)
  426. return ipaq_model_ops.pm_callback_aux(req);
  427. return 0;
  428. }
  429. static struct ipaq_model_ops h3600_model_ops __initdata = {
  430. .generic_name = "3600",
  431. .control = h3600_control_egpio,
  432. .read = h3600_read_egpio,
  433. .pm_callback = h3600_pm_callback
  434. };
  435. static void __init h3600_map_io(void)
  436. {
  437. h3xxx_map_io();
  438. /* Initialize h3600-specific values here */
  439. GPCR = 0x0fffffff; /* All outputs are set low by default */
  440. GPDR = GPIO_H3600_COM_RTS | GPIO_H3600_L3_CLOCK |
  441. GPIO_H3600_L3_MODE | GPIO_H3600_L3_DATA |
  442. GPIO_H3600_CLK_SET1 | GPIO_H3600_CLK_SET0 |
  443. GPIO_LDD15 | GPIO_LDD14 | GPIO_LDD13 | GPIO_LDD12 |
  444. GPIO_LDD11 | GPIO_LDD10 | GPIO_LDD9 | GPIO_LDD8;
  445. H3600_EGPIO = h3600_egpio; /* Maintains across sleep? */
  446. ipaq_model_ops = h3600_model_ops;
  447. }
  448. MACHINE_START(H3600, "Compaq iPAQ H3600")
  449. .phys_ram = 0xc0000000,
  450. .phys_io = 0x80000000,
  451. .io_pg_offst = ((0xf8000000) >> 18) & 0xfffc,
  452. .boot_params = 0xc0000100,
  453. .map_io = h3600_map_io,
  454. .init_irq = sa1100_init_irq,
  455. .timer = &sa1100_timer,
  456. .init_machine = h3xxx_mach_init,
  457. MACHINE_END
  458. #endif /* CONFIG_SA1100_H3600 */
  459. #ifdef CONFIG_SA1100_H3800
  460. #define SET_ASIC1(x) \
  461. do {if (setp) { H3800_ASIC1_GPIO_OUT |= (x); } else { H3800_ASIC1_GPIO_OUT &= ~(x); }} while(0)
  462. #define SET_ASIC2(x) \
  463. do {if (setp) { H3800_ASIC2_GPIOPIOD |= (x); } else { H3800_ASIC2_GPIOPIOD &= ~(x); }} while(0)
  464. #define CLEAR_ASIC1(x) \
  465. do {if (setp) { H3800_ASIC1_GPIO_OUT &= ~(x); } else { H3800_ASIC1_GPIO_OUT |= (x); }} while(0)
  466. #define CLEAR_ASIC2(x) \
  467. do {if (setp) { H3800_ASIC2_GPIOPIOD &= ~(x); } else { H3800_ASIC2_GPIOPIOD |= (x); }} while(0)
  468. /*
  469. On screen enable, we get
  470. h3800_video_power_on(1)
  471. LCD controller starts
  472. h3800_video_lcd_enable(1)
  473. On screen disable, we get
  474. h3800_video_lcd_enable(0)
  475. LCD controller stops
  476. h3800_video_power_on(0)
  477. */
  478. static void h3800_video_power_on(int setp)
  479. {
  480. if (setp) {
  481. H3800_ASIC1_GPIO_OUT |= GPIO1_LCD_ON;
  482. msleep(30);
  483. H3800_ASIC1_GPIO_OUT |= GPIO1_VGL_ON;
  484. msleep(5);
  485. H3800_ASIC1_GPIO_OUT |= GPIO1_VGH_ON;
  486. msleep(50);
  487. H3800_ASIC1_GPIO_OUT |= GPIO1_LCD_5V_ON;
  488. msleep(5);
  489. } else {
  490. msleep(5);
  491. H3800_ASIC1_GPIO_OUT &= ~GPIO1_LCD_5V_ON;
  492. msleep(50);
  493. H3800_ASIC1_GPIO_OUT &= ~GPIO1_VGL_ON;
  494. msleep(5);
  495. H3800_ASIC1_GPIO_OUT &= ~GPIO1_VGH_ON;
  496. msleep(100);
  497. H3800_ASIC1_GPIO_OUT &= ~GPIO1_LCD_ON;
  498. }
  499. }
  500. static void h3800_video_lcd_enable(int setp)
  501. {
  502. if (setp) {
  503. msleep(17); // Wait one from before turning on
  504. H3800_ASIC1_GPIO_OUT |= GPIO1_LCD_PCI;
  505. } else {
  506. H3800_ASIC1_GPIO_OUT &= ~GPIO1_LCD_PCI;
  507. msleep(30); // Wait before turning off
  508. }
  509. }
  510. static void h3800_control_egpio(enum ipaq_egpio_type x, int setp)
  511. {
  512. switch (x) {
  513. case IPAQ_EGPIO_LCD_POWER:
  514. h3800_video_power_on(setp);
  515. break;
  516. case IPAQ_EGPIO_LCD_ENABLE:
  517. h3800_video_lcd_enable(setp);
  518. break;
  519. case IPAQ_EGPIO_CODEC_NRESET:
  520. case IPAQ_EGPIO_AUDIO_ON:
  521. case IPAQ_EGPIO_QMUTE:
  522. printk("%s: error - should not be called\n", __FUNCTION__);
  523. break;
  524. case IPAQ_EGPIO_OPT_NVRAM_ON:
  525. SET_ASIC2(GPIO2_OPT_ON_NVRAM);
  526. break;
  527. case IPAQ_EGPIO_OPT_ON:
  528. SET_ASIC2(GPIO2_OPT_ON);
  529. break;
  530. case IPAQ_EGPIO_CARD_RESET:
  531. SET_ASIC2(GPIO2_OPT_PCM_RESET);
  532. break;
  533. case IPAQ_EGPIO_OPT_RESET:
  534. SET_ASIC2(GPIO2_OPT_RESET);
  535. break;
  536. case IPAQ_EGPIO_IR_ON:
  537. CLEAR_ASIC1(GPIO1_IR_ON_N);
  538. break;
  539. case IPAQ_EGPIO_IR_FSEL:
  540. break;
  541. case IPAQ_EGPIO_RS232_ON:
  542. SET_ASIC1(GPIO1_RS232_ON);
  543. break;
  544. case IPAQ_EGPIO_VPP_ON:
  545. H3800_ASIC2_FlashWP_VPP_ON = setp;
  546. break;
  547. }
  548. }
  549. static unsigned long h3800_read_egpio(void)
  550. {
  551. return H3800_ASIC1_GPIO_OUT | (H3800_ASIC2_GPIOPIOD << 16);
  552. }
  553. /* We need to fix ASIC2 GPIO over suspend/resume. At the moment,
  554. it doesn't appear that ASIC1 GPIO has the same problem */
  555. static int h3800_pm_callback(int req)
  556. {
  557. static u16 asic1_data;
  558. static u16 asic2_data;
  559. int result = 0;
  560. printk("%s %d\n", __FUNCTION__, req);
  561. switch (req) {
  562. case PM_RESUME:
  563. MSC2 = (MSC2 & 0x0000ffff) | 0xE4510000; /* Set MSC2 correctly */
  564. H3800_ASIC2_GPIOPIOD = asic2_data;
  565. H3800_ASIC2_GPIODIR = GPIO2_PEN_IRQ
  566. | GPIO2_SD_DETECT
  567. | GPIO2_EAR_IN_N
  568. | GPIO2_USB_DETECT_N
  569. | GPIO2_SD_CON_SLT;
  570. H3800_ASIC1_GPIO_OUT = asic1_data;
  571. if (ipaq_model_ops.pm_callback_aux)
  572. result = ipaq_model_ops.pm_callback_aux(req);
  573. break;
  574. case PM_SUSPEND:
  575. if (ipaq_model_ops.pm_callback_aux &&
  576. ((result = ipaq_model_ops.pm_callback_aux(req)) != 0))
  577. return result;
  578. asic1_data = H3800_ASIC1_GPIO_OUT;
  579. asic2_data = H3800_ASIC2_GPIOPIOD;
  580. break;
  581. default:
  582. printk("%s: unrecognized PM callback\n", __FUNCTION__);
  583. break;
  584. }
  585. return result;
  586. }
  587. static struct ipaq_model_ops h3800_model_ops __initdata = {
  588. .generic_name = "3800",
  589. .control = h3800_control_egpio,
  590. .read = h3800_read_egpio,
  591. .pm_callback = h3800_pm_callback
  592. };
  593. #define MAX_ASIC_ISR_LOOPS 20
  594. /* The order of these is important - see #include <asm/arch/irqs.h> */
  595. static u32 kpio_irq_mask[] = {
  596. KPIO_KEY_ALL,
  597. KPIO_SPI_INT,
  598. KPIO_OWM_INT,
  599. KPIO_ADC_INT,
  600. KPIO_UART_0_INT,
  601. KPIO_UART_1_INT,
  602. KPIO_TIMER_0_INT,
  603. KPIO_TIMER_1_INT,
  604. KPIO_TIMER_2_INT
  605. };
  606. static u32 gpio_irq_mask[] = {
  607. GPIO2_PEN_IRQ,
  608. GPIO2_SD_DETECT,
  609. GPIO2_EAR_IN_N,
  610. GPIO2_USB_DETECT_N,
  611. GPIO2_SD_CON_SLT,
  612. };
  613. static void h3800_IRQ_demux(unsigned int irq, struct irqdesc *desc, struct pt_regs *regs)
  614. {
  615. int i;
  616. if (0) printk("%s: interrupt received\n", __FUNCTION__);
  617. desc->chip->ack(irq);
  618. for (i = 0; i < MAX_ASIC_ISR_LOOPS && (GPLR & GPIO_H3800_ASIC); i++) {
  619. u32 irq;
  620. int j;
  621. /* KPIO */
  622. irq = H3800_ASIC2_KPIINTFLAG;
  623. if (0) printk("%s KPIO 0x%08X\n", __FUNCTION__, irq);
  624. for (j = 0; j < H3800_KPIO_IRQ_COUNT; j++)
  625. if (irq & kpio_irq_mask[j])
  626. do_edge_IRQ(H3800_KPIO_IRQ_COUNT + j, irq_desc + H3800_KPIO_IRQ_COUNT + j, regs);
  627. /* GPIO2 */
  628. irq = H3800_ASIC2_GPIINTFLAG;
  629. if (0) printk("%s GPIO 0x%08X\n", __FUNCTION__, irq);
  630. for (j = 0; j < H3800_GPIO_IRQ_COUNT; j++)
  631. if (irq & gpio_irq_mask[j])
  632. do_edge_IRQ(H3800_GPIO_IRQ_COUNT + j, irq_desc + H3800_GPIO_IRQ_COUNT + j , regs);
  633. }
  634. if (i >= MAX_ASIC_ISR_LOOPS)
  635. printk("%s: interrupt processing overrun\n", __FUNCTION__);
  636. /* For level-based interrupts */
  637. desc->chip->unmask(irq);
  638. }
  639. static struct irqaction h3800_irq = {
  640. .name = "h3800_asic",
  641. .handler = h3800_IRQ_demux,
  642. .flags = SA_INTERRUPT | SA_TIMER,
  643. };
  644. u32 kpio_int_shadow = 0;
  645. /* mask_ack <- IRQ is first serviced.
  646. mask <- IRQ is disabled.
  647. unmask <- IRQ is enabled
  648. The INTCLR registers are poorly documented. I believe that writing
  649. a "1" to the register clears the specific interrupt, but the documentation
  650. indicates writing a "0" clears the interrupt. In any case, they shouldn't
  651. be read (that's the INTFLAG register)
  652. */
  653. static void h3800_mask_ack_kpio_irq(unsigned int irq)
  654. {
  655. u32 mask = kpio_irq_mask[irq - H3800_KPIO_IRQ_START];
  656. kpio_int_shadow &= ~mask;
  657. H3800_ASIC2_KPIINTSTAT = kpio_int_shadow;
  658. H3800_ASIC2_KPIINTCLR = mask;
  659. }
  660. static void h3800_mask_kpio_irq(unsigned int irq)
  661. {
  662. u32 mask = kpio_irq_mask[irq - H3800_KPIO_IRQ_START];
  663. kpio_int_shadow &= ~mask;
  664. H3800_ASIC2_KPIINTSTAT = kpio_int_shadow;
  665. }
  666. static void h3800_unmask_kpio_irq(unsigned int irq)
  667. {
  668. u32 mask = kpio_irq_mask[irq - H3800_KPIO_IRQ_START];
  669. kpio_int_shadow |= mask;
  670. H3800_ASIC2_KPIINTSTAT = kpio_int_shadow;
  671. }
  672. static void h3800_mask_ack_gpio_irq(unsigned int irq)
  673. {
  674. u32 mask = gpio_irq_mask[irq - H3800_GPIO_IRQ_START];
  675. H3800_ASIC2_GPIINTSTAT &= ~mask;
  676. H3800_ASIC2_GPIINTCLR = mask;
  677. }
  678. static void h3800_mask_gpio_irq(unsigned int irq)
  679. {
  680. u32 mask = gpio_irq_mask[irq - H3800_GPIO_IRQ_START];
  681. H3800_ASIC2_GPIINTSTAT &= ~mask;
  682. }
  683. static void h3800_unmask_gpio_irq(unsigned int irq)
  684. {
  685. u32 mask = gpio_irq_mask[irq - H3800_GPIO_IRQ_START];
  686. H3800_ASIC2_GPIINTSTAT |= mask;
  687. }
  688. static void __init h3800_init_irq(void)
  689. {
  690. int i;
  691. /* Initialize standard IRQs */
  692. sa1100_init_irq();
  693. /* Disable all IRQs and set up clock */
  694. H3800_ASIC2_KPIINTSTAT = 0; /* Disable all interrupts */
  695. H3800_ASIC2_GPIINTSTAT = 0;
  696. H3800_ASIC2_KPIINTCLR = 0; /* Clear all KPIO interrupts */
  697. H3800_ASIC2_GPIINTCLR = 0; /* Clear all GPIO interrupts */
  698. // H3800_ASIC2_KPIINTCLR = 0xffff; /* Clear all KPIO interrupts */
  699. // H3800_ASIC2_GPIINTCLR = 0xffff; /* Clear all GPIO interrupts */
  700. H3800_ASIC2_CLOCK_Enable |= ASIC2_CLOCK_EX0; /* 32 kHZ crystal on */
  701. H3800_ASIC2_INTR_ClockPrescale |= ASIC2_INTCPS_SET;
  702. H3800_ASIC2_INTR_ClockPrescale = ASIC2_INTCPS_CPS(0x0e) | ASIC2_INTCPS_SET;
  703. H3800_ASIC2_INTR_TimerSet = 1;
  704. #if 0
  705. for (i = 0; i < H3800_KPIO_IRQ_COUNT; i++) {
  706. int irq = i + H3800_KPIO_IRQ_START;
  707. irq_desc[irq].valid = 1;
  708. irq_desc[irq].probe_ok = 1;
  709. set_irq_chip(irq, &h3800_kpio_irqchip);
  710. }
  711. for (i = 0; i < H3800_GPIO_IRQ_COUNT; i++) {
  712. int irq = i + H3800_GPIO_IRQ_START;
  713. irq_desc[irq].valid = 1;
  714. irq_desc[irq].probe_ok = 1;
  715. set_irq_chip(irq, &h3800_gpio_irqchip);
  716. }
  717. #endif
  718. set_irq_type(IRQ_GPIO_H3800_ASIC, IRQT_RISING);
  719. set_irq_chained_handler(IRQ_GPIO_H3800_ASIC, &h3800_IRQ_demux);
  720. }
  721. #define ASIC1_OUTPUTS 0x7fff /* First 15 bits are used */
  722. static void __init h3800_map_io(void)
  723. {
  724. h3xxx_map_io();
  725. /* Add wakeup on AC plug/unplug */
  726. PWER |= PWER_GPIO12;
  727. /* Initialize h3800-specific values here */
  728. GPCR = 0x0fffffff; /* All outputs are set low by default */
  729. GAFR = GPIO_H3800_CLK_OUT |
  730. GPIO_LDD15 | GPIO_LDD14 | GPIO_LDD13 | GPIO_LDD12 |
  731. GPIO_LDD11 | GPIO_LDD10 | GPIO_LDD9 | GPIO_LDD8;
  732. GPDR = GPIO_H3800_CLK_OUT |
  733. GPIO_H3600_COM_RTS | GPIO_H3600_L3_CLOCK |
  734. GPIO_H3600_L3_MODE | GPIO_H3600_L3_DATA |
  735. GPIO_LDD15 | GPIO_LDD14 | GPIO_LDD13 | GPIO_LDD12 |
  736. GPIO_LDD11 | GPIO_LDD10 | GPIO_LDD9 | GPIO_LDD8;
  737. TUCR = TUCR_3_6864MHz; /* Seems to be used only for the Bluetooth UART */
  738. /* Fix the memory bus */
  739. MSC2 = (MSC2 & 0x0000ffff) | 0xE4510000;
  740. /* Set up ASIC #1 */
  741. H3800_ASIC1_GPIO_DIR = ASIC1_OUTPUTS; /* All outputs */
  742. H3800_ASIC1_GPIO_MASK = ASIC1_OUTPUTS; /* No interrupts */
  743. H3800_ASIC1_GPIO_SLEEP_MASK = ASIC1_OUTPUTS;
  744. H3800_ASIC1_GPIO_SLEEP_DIR = ASIC1_OUTPUTS;
  745. H3800_ASIC1_GPIO_SLEEP_OUT = GPIO1_EAR_ON_N;
  746. H3800_ASIC1_GPIO_BATT_FAULT_DIR = ASIC1_OUTPUTS;
  747. H3800_ASIC1_GPIO_BATT_FAULT_OUT = GPIO1_EAR_ON_N;
  748. H3800_ASIC1_GPIO_OUT = GPIO1_IR_ON_N
  749. | GPIO1_RS232_ON
  750. | GPIO1_EAR_ON_N;
  751. /* Set up ASIC #2 */
  752. H3800_ASIC2_GPIOPIOD = GPIO2_IN_Y1_N | GPIO2_IN_X1_N;
  753. H3800_ASIC2_GPOBFSTAT = GPIO2_IN_Y1_N | GPIO2_IN_X1_N;
  754. H3800_ASIC2_GPIODIR = GPIO2_PEN_IRQ
  755. | GPIO2_SD_DETECT
  756. | GPIO2_EAR_IN_N
  757. | GPIO2_USB_DETECT_N
  758. | GPIO2_SD_CON_SLT;
  759. /* TODO : Set sleep states & battery fault states */
  760. /* Clear VPP Enable */
  761. H3800_ASIC2_FlashWP_VPP_ON = 0;
  762. ipaq_model_ops = h3800_model_ops;
  763. }
  764. MACHINE_START(H3800, "Compaq iPAQ H3800")
  765. .phys_ram = 0xc0000000,
  766. .phys_io = 0x80000000,
  767. .io_pg_offst = ((0xf8000000) >> 18) & 0xfffc,
  768. .boot_params = 0xc0000100,
  769. .map_io = h3800_map_io,
  770. .init_irq = h3800_init_irq,
  771. .timer = &sa1100_timer,
  772. .init_machine = h3xxx_mach_init,
  773. MACHINE_END
  774. #endif /* CONFIG_SA1100_H3800 */