h3600.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898
  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. /* virtual physical length type */
  200. { H3600_BANK_2_VIRT, SA1100_CS2_PHYS, 0x02800000, MT_DEVICE }, /* static memory bank 2 CS#2 */
  201. { H3600_BANK_4_VIRT, SA1100_CS4_PHYS, 0x00800000, MT_DEVICE }, /* static memory bank 4 CS#4 */
  202. { H3600_EGPIO_VIRT, H3600_EGPIO_PHYS, 0x01000000, MT_DEVICE }, /* EGPIO 0 CS#5 */
  203. };
  204. /*
  205. * Common map_io initialization
  206. */
  207. static void __init h3xxx_map_io(void)
  208. {
  209. sa1100_map_io();
  210. iotable_init(h3600_io_desc, ARRAY_SIZE(h3600_io_desc));
  211. sa1100_register_uart_fns(&h3600_port_fns);
  212. sa1100_register_uart(0, 3); /* Common serial port */
  213. // sa1100_register_uart(1, 1); /* Microcontroller on 3100/3600 */
  214. /* Ensure those pins are outputs and driving low */
  215. PPDR |= PPC_TXD4 | PPC_SCLK | PPC_SFRM;
  216. PPSR &= ~(PPC_TXD4 | PPC_SCLK | PPC_SFRM);
  217. /* Configure suspend conditions */
  218. PGSR = 0;
  219. PWER = PWER_GPIO0 | PWER_RTC;
  220. PCFR = PCFR_OPDE;
  221. PSDR = 0;
  222. sa1100fb_lcd_power = h3xxx_lcd_power;
  223. }
  224. static __inline__ void do_blank(int setp)
  225. {
  226. if (ipaq_model_ops.blank_callback)
  227. ipaq_model_ops.blank_callback(1-setp);
  228. }
  229. /************************* H3100 *************************/
  230. #ifdef CONFIG_SA1100_H3100
  231. #define H3100_EGPIO (*(volatile unsigned int *)H3600_EGPIO_VIRT)
  232. static unsigned int h3100_egpio = 0;
  233. static void h3100_control_egpio(enum ipaq_egpio_type x, int setp)
  234. {
  235. unsigned int egpio = 0;
  236. long gpio = 0;
  237. unsigned long flags;
  238. switch (x) {
  239. case IPAQ_EGPIO_LCD_POWER:
  240. egpio |= EGPIO_H3600_LCD_ON;
  241. gpio |= GPIO_H3100_LCD_3V_ON;
  242. do_blank(setp);
  243. break;
  244. case IPAQ_EGPIO_LCD_ENABLE:
  245. break;
  246. case IPAQ_EGPIO_CODEC_NRESET:
  247. egpio |= EGPIO_H3600_CODEC_NRESET;
  248. break;
  249. case IPAQ_EGPIO_AUDIO_ON:
  250. gpio |= GPIO_H3100_AUD_PWR_ON
  251. | GPIO_H3100_AUD_ON;
  252. break;
  253. case IPAQ_EGPIO_QMUTE:
  254. gpio |= GPIO_H3100_QMUTE;
  255. break;
  256. case IPAQ_EGPIO_OPT_NVRAM_ON:
  257. egpio |= EGPIO_H3600_OPT_NVRAM_ON;
  258. break;
  259. case IPAQ_EGPIO_OPT_ON:
  260. egpio |= EGPIO_H3600_OPT_ON;
  261. break;
  262. case IPAQ_EGPIO_CARD_RESET:
  263. egpio |= EGPIO_H3600_CARD_RESET;
  264. break;
  265. case IPAQ_EGPIO_OPT_RESET:
  266. egpio |= EGPIO_H3600_OPT_RESET;
  267. break;
  268. case IPAQ_EGPIO_IR_ON:
  269. gpio |= GPIO_H3100_IR_ON;
  270. break;
  271. case IPAQ_EGPIO_IR_FSEL:
  272. gpio |= GPIO_H3100_IR_FSEL;
  273. break;
  274. case IPAQ_EGPIO_RS232_ON:
  275. egpio |= EGPIO_H3600_RS232_ON;
  276. break;
  277. case IPAQ_EGPIO_VPP_ON:
  278. egpio |= EGPIO_H3600_VPP_ON;
  279. break;
  280. }
  281. if (egpio || gpio) {
  282. local_irq_save(flags);
  283. if (setp) {
  284. h3100_egpio |= egpio;
  285. GPSR = gpio;
  286. } else {
  287. h3100_egpio &= ~egpio;
  288. GPCR = gpio;
  289. }
  290. H3100_EGPIO = h3100_egpio;
  291. local_irq_restore(flags);
  292. }
  293. }
  294. static unsigned long h3100_read_egpio(void)
  295. {
  296. return h3100_egpio;
  297. }
  298. static int h3100_pm_callback(int req)
  299. {
  300. if (ipaq_model_ops.pm_callback_aux)
  301. return ipaq_model_ops.pm_callback_aux(req);
  302. return 0;
  303. }
  304. static struct ipaq_model_ops h3100_model_ops __initdata = {
  305. .generic_name = "3100",
  306. .control = h3100_control_egpio,
  307. .read = h3100_read_egpio,
  308. .pm_callback = h3100_pm_callback
  309. };
  310. #define H3100_DIRECT_EGPIO (GPIO_H3100_BT_ON \
  311. | GPIO_H3100_GPIO3 \
  312. | GPIO_H3100_QMUTE \
  313. | GPIO_H3100_LCD_3V_ON \
  314. | GPIO_H3100_AUD_ON \
  315. | GPIO_H3100_AUD_PWR_ON \
  316. | GPIO_H3100_IR_ON \
  317. | GPIO_H3100_IR_FSEL)
  318. static void __init h3100_map_io(void)
  319. {
  320. h3xxx_map_io();
  321. /* Initialize h3100-specific values here */
  322. GPCR = 0x0fffffff; /* All outputs are set low by default */
  323. GPDR = GPIO_H3600_COM_RTS | GPIO_H3600_L3_CLOCK |
  324. GPIO_H3600_L3_MODE | GPIO_H3600_L3_DATA |
  325. GPIO_H3600_CLK_SET1 | GPIO_H3600_CLK_SET0 |
  326. H3100_DIRECT_EGPIO;
  327. /* Older bootldrs put GPIO2-9 in alternate mode on the
  328. assumption that they are used for video */
  329. GAFR &= ~H3100_DIRECT_EGPIO;
  330. H3100_EGPIO = h3100_egpio;
  331. ipaq_model_ops = h3100_model_ops;
  332. }
  333. MACHINE_START(H3100, "Compaq iPAQ H3100")
  334. .phys_ram = 0xc0000000,
  335. .phys_io = 0x80000000,
  336. .io_pg_offst = ((0xf8000000) >> 18) & 0xfffc,
  337. .boot_params = 0xc0000100,
  338. .map_io = h3100_map_io,
  339. .init_irq = sa1100_init_irq,
  340. .timer = &sa1100_timer,
  341. .init_machine = h3xxx_mach_init,
  342. MACHINE_END
  343. #endif /* CONFIG_SA1100_H3100 */
  344. /************************* H3600 *************************/
  345. #ifdef CONFIG_SA1100_H3600
  346. #define H3600_EGPIO (*(volatile unsigned int *)H3600_EGPIO_VIRT)
  347. static unsigned int h3600_egpio = EGPIO_H3600_RS232_ON;
  348. static void h3600_control_egpio(enum ipaq_egpio_type x, int setp)
  349. {
  350. unsigned int egpio = 0;
  351. unsigned long flags;
  352. switch (x) {
  353. case IPAQ_EGPIO_LCD_POWER:
  354. egpio |= EGPIO_H3600_LCD_ON |
  355. EGPIO_H3600_LCD_PCI |
  356. EGPIO_H3600_LCD_5V_ON |
  357. EGPIO_H3600_LVDD_ON;
  358. do_blank(setp);
  359. break;
  360. case IPAQ_EGPIO_LCD_ENABLE:
  361. break;
  362. case IPAQ_EGPIO_CODEC_NRESET:
  363. egpio |= EGPIO_H3600_CODEC_NRESET;
  364. break;
  365. case IPAQ_EGPIO_AUDIO_ON:
  366. egpio |= EGPIO_H3600_AUD_AMP_ON |
  367. EGPIO_H3600_AUD_PWR_ON;
  368. break;
  369. case IPAQ_EGPIO_QMUTE:
  370. egpio |= EGPIO_H3600_QMUTE;
  371. break;
  372. case IPAQ_EGPIO_OPT_NVRAM_ON:
  373. egpio |= EGPIO_H3600_OPT_NVRAM_ON;
  374. break;
  375. case IPAQ_EGPIO_OPT_ON:
  376. egpio |= EGPIO_H3600_OPT_ON;
  377. break;
  378. case IPAQ_EGPIO_CARD_RESET:
  379. egpio |= EGPIO_H3600_CARD_RESET;
  380. break;
  381. case IPAQ_EGPIO_OPT_RESET:
  382. egpio |= EGPIO_H3600_OPT_RESET;
  383. break;
  384. case IPAQ_EGPIO_IR_ON:
  385. egpio |= EGPIO_H3600_IR_ON;
  386. break;
  387. case IPAQ_EGPIO_IR_FSEL:
  388. egpio |= EGPIO_H3600_IR_FSEL;
  389. break;
  390. case IPAQ_EGPIO_RS232_ON:
  391. egpio |= EGPIO_H3600_RS232_ON;
  392. break;
  393. case IPAQ_EGPIO_VPP_ON:
  394. egpio |= EGPIO_H3600_VPP_ON;
  395. break;
  396. }
  397. if (egpio) {
  398. local_irq_save(flags);
  399. if (setp)
  400. h3600_egpio |= egpio;
  401. else
  402. h3600_egpio &= ~egpio;
  403. H3600_EGPIO = h3600_egpio;
  404. local_irq_restore(flags);
  405. }
  406. }
  407. static unsigned long h3600_read_egpio(void)
  408. {
  409. return h3600_egpio;
  410. }
  411. static int h3600_pm_callback(int req)
  412. {
  413. if (ipaq_model_ops.pm_callback_aux)
  414. return ipaq_model_ops.pm_callback_aux(req);
  415. return 0;
  416. }
  417. static struct ipaq_model_ops h3600_model_ops __initdata = {
  418. .generic_name = "3600",
  419. .control = h3600_control_egpio,
  420. .read = h3600_read_egpio,
  421. .pm_callback = h3600_pm_callback
  422. };
  423. static void __init h3600_map_io(void)
  424. {
  425. h3xxx_map_io();
  426. /* Initialize h3600-specific values here */
  427. GPCR = 0x0fffffff; /* All outputs are set low by default */
  428. GPDR = GPIO_H3600_COM_RTS | GPIO_H3600_L3_CLOCK |
  429. GPIO_H3600_L3_MODE | GPIO_H3600_L3_DATA |
  430. GPIO_H3600_CLK_SET1 | GPIO_H3600_CLK_SET0 |
  431. GPIO_LDD15 | GPIO_LDD14 | GPIO_LDD13 | GPIO_LDD12 |
  432. GPIO_LDD11 | GPIO_LDD10 | GPIO_LDD9 | GPIO_LDD8;
  433. H3600_EGPIO = h3600_egpio; /* Maintains across sleep? */
  434. ipaq_model_ops = h3600_model_ops;
  435. }
  436. MACHINE_START(H3600, "Compaq iPAQ H3600")
  437. .phys_ram = 0xc0000000,
  438. .phys_io = 0x80000000,
  439. .io_pg_offst = ((0xf8000000) >> 18) & 0xfffc,
  440. .boot_params = 0xc0000100,
  441. .map_io = h3600_map_io,
  442. .init_irq = sa1100_init_irq,
  443. .timer = &sa1100_timer,
  444. .init_machine = h3xxx_mach_init,
  445. MACHINE_END
  446. #endif /* CONFIG_SA1100_H3600 */
  447. #ifdef CONFIG_SA1100_H3800
  448. #define SET_ASIC1(x) \
  449. do {if (setp) { H3800_ASIC1_GPIO_OUT |= (x); } else { H3800_ASIC1_GPIO_OUT &= ~(x); }} while(0)
  450. #define SET_ASIC2(x) \
  451. do {if (setp) { H3800_ASIC2_GPIOPIOD |= (x); } else { H3800_ASIC2_GPIOPIOD &= ~(x); }} while(0)
  452. #define CLEAR_ASIC1(x) \
  453. do {if (setp) { H3800_ASIC1_GPIO_OUT &= ~(x); } else { H3800_ASIC1_GPIO_OUT |= (x); }} while(0)
  454. #define CLEAR_ASIC2(x) \
  455. do {if (setp) { H3800_ASIC2_GPIOPIOD &= ~(x); } else { H3800_ASIC2_GPIOPIOD |= (x); }} while(0)
  456. /*
  457. On screen enable, we get
  458. h3800_video_power_on(1)
  459. LCD controller starts
  460. h3800_video_lcd_enable(1)
  461. On screen disable, we get
  462. h3800_video_lcd_enable(0)
  463. LCD controller stops
  464. h3800_video_power_on(0)
  465. */
  466. static void h3800_video_power_on(int setp)
  467. {
  468. if (setp) {
  469. H3800_ASIC1_GPIO_OUT |= GPIO1_LCD_ON;
  470. msleep(30);
  471. H3800_ASIC1_GPIO_OUT |= GPIO1_VGL_ON;
  472. msleep(5);
  473. H3800_ASIC1_GPIO_OUT |= GPIO1_VGH_ON;
  474. msleep(50);
  475. H3800_ASIC1_GPIO_OUT |= GPIO1_LCD_5V_ON;
  476. msleep(5);
  477. } else {
  478. msleep(5);
  479. H3800_ASIC1_GPIO_OUT &= ~GPIO1_LCD_5V_ON;
  480. msleep(50);
  481. H3800_ASIC1_GPIO_OUT &= ~GPIO1_VGL_ON;
  482. msleep(5);
  483. H3800_ASIC1_GPIO_OUT &= ~GPIO1_VGH_ON;
  484. msleep(100);
  485. H3800_ASIC1_GPIO_OUT &= ~GPIO1_LCD_ON;
  486. }
  487. }
  488. static void h3800_video_lcd_enable(int setp)
  489. {
  490. if (setp) {
  491. msleep(17); // Wait one from before turning on
  492. H3800_ASIC1_GPIO_OUT |= GPIO1_LCD_PCI;
  493. } else {
  494. H3800_ASIC1_GPIO_OUT &= ~GPIO1_LCD_PCI;
  495. msleep(30); // Wait before turning off
  496. }
  497. }
  498. static void h3800_control_egpio(enum ipaq_egpio_type x, int setp)
  499. {
  500. switch (x) {
  501. case IPAQ_EGPIO_LCD_POWER:
  502. h3800_video_power_on(setp);
  503. break;
  504. case IPAQ_EGPIO_LCD_ENABLE:
  505. h3800_video_lcd_enable(setp);
  506. break;
  507. case IPAQ_EGPIO_CODEC_NRESET:
  508. case IPAQ_EGPIO_AUDIO_ON:
  509. case IPAQ_EGPIO_QMUTE:
  510. printk("%s: error - should not be called\n", __FUNCTION__);
  511. break;
  512. case IPAQ_EGPIO_OPT_NVRAM_ON:
  513. SET_ASIC2(GPIO2_OPT_ON_NVRAM);
  514. break;
  515. case IPAQ_EGPIO_OPT_ON:
  516. SET_ASIC2(GPIO2_OPT_ON);
  517. break;
  518. case IPAQ_EGPIO_CARD_RESET:
  519. SET_ASIC2(GPIO2_OPT_PCM_RESET);
  520. break;
  521. case IPAQ_EGPIO_OPT_RESET:
  522. SET_ASIC2(GPIO2_OPT_RESET);
  523. break;
  524. case IPAQ_EGPIO_IR_ON:
  525. CLEAR_ASIC1(GPIO1_IR_ON_N);
  526. break;
  527. case IPAQ_EGPIO_IR_FSEL:
  528. break;
  529. case IPAQ_EGPIO_RS232_ON:
  530. SET_ASIC1(GPIO1_RS232_ON);
  531. break;
  532. case IPAQ_EGPIO_VPP_ON:
  533. H3800_ASIC2_FlashWP_VPP_ON = setp;
  534. break;
  535. }
  536. }
  537. static unsigned long h3800_read_egpio(void)
  538. {
  539. return H3800_ASIC1_GPIO_OUT | (H3800_ASIC2_GPIOPIOD << 16);
  540. }
  541. /* We need to fix ASIC2 GPIO over suspend/resume. At the moment,
  542. it doesn't appear that ASIC1 GPIO has the same problem */
  543. static int h3800_pm_callback(int req)
  544. {
  545. static u16 asic1_data;
  546. static u16 asic2_data;
  547. int result = 0;
  548. printk("%s %d\n", __FUNCTION__, req);
  549. switch (req) {
  550. case PM_RESUME:
  551. MSC2 = (MSC2 & 0x0000ffff) | 0xE4510000; /* Set MSC2 correctly */
  552. H3800_ASIC2_GPIOPIOD = asic2_data;
  553. H3800_ASIC2_GPIODIR = GPIO2_PEN_IRQ
  554. | GPIO2_SD_DETECT
  555. | GPIO2_EAR_IN_N
  556. | GPIO2_USB_DETECT_N
  557. | GPIO2_SD_CON_SLT;
  558. H3800_ASIC1_GPIO_OUT = asic1_data;
  559. if (ipaq_model_ops.pm_callback_aux)
  560. result = ipaq_model_ops.pm_callback_aux(req);
  561. break;
  562. case PM_SUSPEND:
  563. if (ipaq_model_ops.pm_callback_aux &&
  564. ((result = ipaq_model_ops.pm_callback_aux(req)) != 0))
  565. return result;
  566. asic1_data = H3800_ASIC1_GPIO_OUT;
  567. asic2_data = H3800_ASIC2_GPIOPIOD;
  568. break;
  569. default:
  570. printk("%s: unrecognized PM callback\n", __FUNCTION__);
  571. break;
  572. }
  573. return result;
  574. }
  575. static struct ipaq_model_ops h3800_model_ops __initdata = {
  576. .generic_name = "3800",
  577. .control = h3800_control_egpio,
  578. .read = h3800_read_egpio,
  579. .pm_callback = h3800_pm_callback
  580. };
  581. #define MAX_ASIC_ISR_LOOPS 20
  582. /* The order of these is important - see #include <asm/arch/irqs.h> */
  583. static u32 kpio_irq_mask[] = {
  584. KPIO_KEY_ALL,
  585. KPIO_SPI_INT,
  586. KPIO_OWM_INT,
  587. KPIO_ADC_INT,
  588. KPIO_UART_0_INT,
  589. KPIO_UART_1_INT,
  590. KPIO_TIMER_0_INT,
  591. KPIO_TIMER_1_INT,
  592. KPIO_TIMER_2_INT
  593. };
  594. static u32 gpio_irq_mask[] = {
  595. GPIO2_PEN_IRQ,
  596. GPIO2_SD_DETECT,
  597. GPIO2_EAR_IN_N,
  598. GPIO2_USB_DETECT_N,
  599. GPIO2_SD_CON_SLT,
  600. };
  601. static void h3800_IRQ_demux(unsigned int irq, struct irqdesc *desc, struct pt_regs *regs)
  602. {
  603. int i;
  604. if (0) printk("%s: interrupt received\n", __FUNCTION__);
  605. desc->chip->ack(irq);
  606. for (i = 0; i < MAX_ASIC_ISR_LOOPS && (GPLR & GPIO_H3800_ASIC); i++) {
  607. u32 irq;
  608. int j;
  609. /* KPIO */
  610. irq = H3800_ASIC2_KPIINTFLAG;
  611. if (0) printk("%s KPIO 0x%08X\n", __FUNCTION__, irq);
  612. for (j = 0; j < H3800_KPIO_IRQ_COUNT; j++)
  613. if (irq & kpio_irq_mask[j])
  614. do_edge_IRQ(H3800_KPIO_IRQ_COUNT + j, irq_desc + H3800_KPIO_IRQ_COUNT + j, regs);
  615. /* GPIO2 */
  616. irq = H3800_ASIC2_GPIINTFLAG;
  617. if (0) printk("%s GPIO 0x%08X\n", __FUNCTION__, irq);
  618. for (j = 0; j < H3800_GPIO_IRQ_COUNT; j++)
  619. if (irq & gpio_irq_mask[j])
  620. do_edge_IRQ(H3800_GPIO_IRQ_COUNT + j, irq_desc + H3800_GPIO_IRQ_COUNT + j , regs);
  621. }
  622. if (i >= MAX_ASIC_ISR_LOOPS)
  623. printk("%s: interrupt processing overrun\n", __FUNCTION__);
  624. /* For level-based interrupts */
  625. desc->chip->unmask(irq);
  626. }
  627. static struct irqaction h3800_irq = {
  628. .name = "h3800_asic",
  629. .handler = h3800_IRQ_demux,
  630. .flags = SA_INTERRUPT | SA_TIMER,
  631. };
  632. u32 kpio_int_shadow = 0;
  633. /* mask_ack <- IRQ is first serviced.
  634. mask <- IRQ is disabled.
  635. unmask <- IRQ is enabled
  636. The INTCLR registers are poorly documented. I believe that writing
  637. a "1" to the register clears the specific interrupt, but the documentation
  638. indicates writing a "0" clears the interrupt. In any case, they shouldn't
  639. be read (that's the INTFLAG register)
  640. */
  641. static void h3800_mask_ack_kpio_irq(unsigned int irq)
  642. {
  643. u32 mask = kpio_irq_mask[irq - H3800_KPIO_IRQ_START];
  644. kpio_int_shadow &= ~mask;
  645. H3800_ASIC2_KPIINTSTAT = kpio_int_shadow;
  646. H3800_ASIC2_KPIINTCLR = mask;
  647. }
  648. static void h3800_mask_kpio_irq(unsigned int irq)
  649. {
  650. u32 mask = kpio_irq_mask[irq - H3800_KPIO_IRQ_START];
  651. kpio_int_shadow &= ~mask;
  652. H3800_ASIC2_KPIINTSTAT = kpio_int_shadow;
  653. }
  654. static void h3800_unmask_kpio_irq(unsigned int irq)
  655. {
  656. u32 mask = kpio_irq_mask[irq - H3800_KPIO_IRQ_START];
  657. kpio_int_shadow |= mask;
  658. H3800_ASIC2_KPIINTSTAT = kpio_int_shadow;
  659. }
  660. static void h3800_mask_ack_gpio_irq(unsigned int irq)
  661. {
  662. u32 mask = gpio_irq_mask[irq - H3800_GPIO_IRQ_START];
  663. H3800_ASIC2_GPIINTSTAT &= ~mask;
  664. H3800_ASIC2_GPIINTCLR = mask;
  665. }
  666. static void h3800_mask_gpio_irq(unsigned int irq)
  667. {
  668. u32 mask = gpio_irq_mask[irq - H3800_GPIO_IRQ_START];
  669. H3800_ASIC2_GPIINTSTAT &= ~mask;
  670. }
  671. static void h3800_unmask_gpio_irq(unsigned int irq)
  672. {
  673. u32 mask = gpio_irq_mask[irq - H3800_GPIO_IRQ_START];
  674. H3800_ASIC2_GPIINTSTAT |= mask;
  675. }
  676. static void __init h3800_init_irq(void)
  677. {
  678. int i;
  679. /* Initialize standard IRQs */
  680. sa1100_init_irq();
  681. /* Disable all IRQs and set up clock */
  682. H3800_ASIC2_KPIINTSTAT = 0; /* Disable all interrupts */
  683. H3800_ASIC2_GPIINTSTAT = 0;
  684. H3800_ASIC2_KPIINTCLR = 0; /* Clear all KPIO interrupts */
  685. H3800_ASIC2_GPIINTCLR = 0; /* Clear all GPIO interrupts */
  686. // H3800_ASIC2_KPIINTCLR = 0xffff; /* Clear all KPIO interrupts */
  687. // H3800_ASIC2_GPIINTCLR = 0xffff; /* Clear all GPIO interrupts */
  688. H3800_ASIC2_CLOCK_Enable |= ASIC2_CLOCK_EX0; /* 32 kHZ crystal on */
  689. H3800_ASIC2_INTR_ClockPrescale |= ASIC2_INTCPS_SET;
  690. H3800_ASIC2_INTR_ClockPrescale = ASIC2_INTCPS_CPS(0x0e) | ASIC2_INTCPS_SET;
  691. H3800_ASIC2_INTR_TimerSet = 1;
  692. #if 0
  693. for (i = 0; i < H3800_KPIO_IRQ_COUNT; i++) {
  694. int irq = i + H3800_KPIO_IRQ_START;
  695. irq_desc[irq].valid = 1;
  696. irq_desc[irq].probe_ok = 1;
  697. set_irq_chip(irq, &h3800_kpio_irqchip);
  698. }
  699. for (i = 0; i < H3800_GPIO_IRQ_COUNT; i++) {
  700. int irq = i + H3800_GPIO_IRQ_START;
  701. irq_desc[irq].valid = 1;
  702. irq_desc[irq].probe_ok = 1;
  703. set_irq_chip(irq, &h3800_gpio_irqchip);
  704. }
  705. #endif
  706. set_irq_type(IRQ_GPIO_H3800_ASIC, IRQT_RISING);
  707. set_irq_chained_handler(IRQ_GPIO_H3800_ASIC, &h3800_IRQ_demux);
  708. }
  709. #define ASIC1_OUTPUTS 0x7fff /* First 15 bits are used */
  710. static void __init h3800_map_io(void)
  711. {
  712. h3xxx_map_io();
  713. /* Add wakeup on AC plug/unplug */
  714. PWER |= PWER_GPIO12;
  715. /* Initialize h3800-specific values here */
  716. GPCR = 0x0fffffff; /* All outputs are set low by default */
  717. GAFR = GPIO_H3800_CLK_OUT |
  718. GPIO_LDD15 | GPIO_LDD14 | GPIO_LDD13 | GPIO_LDD12 |
  719. GPIO_LDD11 | GPIO_LDD10 | GPIO_LDD9 | GPIO_LDD8;
  720. GPDR = GPIO_H3800_CLK_OUT |
  721. GPIO_H3600_COM_RTS | GPIO_H3600_L3_CLOCK |
  722. GPIO_H3600_L3_MODE | GPIO_H3600_L3_DATA |
  723. GPIO_LDD15 | GPIO_LDD14 | GPIO_LDD13 | GPIO_LDD12 |
  724. GPIO_LDD11 | GPIO_LDD10 | GPIO_LDD9 | GPIO_LDD8;
  725. TUCR = TUCR_3_6864MHz; /* Seems to be used only for the Bluetooth UART */
  726. /* Fix the memory bus */
  727. MSC2 = (MSC2 & 0x0000ffff) | 0xE4510000;
  728. /* Set up ASIC #1 */
  729. H3800_ASIC1_GPIO_DIR = ASIC1_OUTPUTS; /* All outputs */
  730. H3800_ASIC1_GPIO_MASK = ASIC1_OUTPUTS; /* No interrupts */
  731. H3800_ASIC1_GPIO_SLEEP_MASK = ASIC1_OUTPUTS;
  732. H3800_ASIC1_GPIO_SLEEP_DIR = ASIC1_OUTPUTS;
  733. H3800_ASIC1_GPIO_SLEEP_OUT = GPIO1_EAR_ON_N;
  734. H3800_ASIC1_GPIO_BATT_FAULT_DIR = ASIC1_OUTPUTS;
  735. H3800_ASIC1_GPIO_BATT_FAULT_OUT = GPIO1_EAR_ON_N;
  736. H3800_ASIC1_GPIO_OUT = GPIO1_IR_ON_N
  737. | GPIO1_RS232_ON
  738. | GPIO1_EAR_ON_N;
  739. /* Set up ASIC #2 */
  740. H3800_ASIC2_GPIOPIOD = GPIO2_IN_Y1_N | GPIO2_IN_X1_N;
  741. H3800_ASIC2_GPOBFSTAT = GPIO2_IN_Y1_N | GPIO2_IN_X1_N;
  742. H3800_ASIC2_GPIODIR = GPIO2_PEN_IRQ
  743. | GPIO2_SD_DETECT
  744. | GPIO2_EAR_IN_N
  745. | GPIO2_USB_DETECT_N
  746. | GPIO2_SD_CON_SLT;
  747. /* TODO : Set sleep states & battery fault states */
  748. /* Clear VPP Enable */
  749. H3800_ASIC2_FlashWP_VPP_ON = 0;
  750. ipaq_model_ops = h3800_model_ops;
  751. }
  752. MACHINE_START(H3800, "Compaq iPAQ H3800")
  753. .phys_ram = 0xc0000000,
  754. .phys_io = 0x80000000,
  755. .io_pg_offst = ((0xf8000000) >> 18) & 0xfffc,
  756. .boot_params = 0xc0000100,
  757. .map_io = h3800_map_io,
  758. .init_irq = h3800_init_irq,
  759. .timer = &sa1100_timer,
  760. .init_machine = h3xxx_mach_init,
  761. MACHINE_END
  762. #endif /* CONFIG_SA1100_H3800 */