h3600.c 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432
  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. void (*assign_h3600_egpio)(enum ipaq_egpio_type x, int level);
  45. EXPORT_SYMBOL(assign_h3600_egpio);
  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. .name = "H3XXX rootfs",
  54. .size = MTDPART_SIZ_FULL,
  55. .offset = 0x00040000,
  56. }
  57. };
  58. static void h3xxx_set_vpp(int vpp)
  59. {
  60. assign_h3600_egpio(IPAQ_EGPIO_VPP_ON, vpp);
  61. }
  62. static struct flash_platform_data h3xxx_flash_data = {
  63. .map_name = "cfi_probe",
  64. .set_vpp = h3xxx_set_vpp,
  65. .parts = h3xxx_partitions,
  66. .nr_parts = ARRAY_SIZE(h3xxx_partitions),
  67. };
  68. static struct resource h3xxx_flash_resource = {
  69. .start = SA1100_CS0_PHYS,
  70. .end = SA1100_CS0_PHYS + SZ_32M - 1,
  71. .flags = IORESOURCE_MEM,
  72. };
  73. /*
  74. * This turns the IRDA power on or off on the Compaq H3600
  75. */
  76. static int h3600_irda_set_power(struct device *dev, unsigned int state)
  77. {
  78. assign_h3600_egpio( IPAQ_EGPIO_IR_ON, state );
  79. return 0;
  80. }
  81. static void h3600_irda_set_speed(struct device *dev, unsigned int speed)
  82. {
  83. assign_h3600_egpio(IPAQ_EGPIO_IR_FSEL, !(speed < 4000000));
  84. }
  85. static struct irda_platform_data h3600_irda_data = {
  86. .set_power = h3600_irda_set_power,
  87. .set_speed = h3600_irda_set_speed,
  88. };
  89. static void h3xxx_mach_init(void)
  90. {
  91. sa11x0_set_flash_data(&h3xxx_flash_data, &h3xxx_flash_resource, 1);
  92. sa11x0_set_irda_data(&h3600_irda_data);
  93. }
  94. /*
  95. * low-level UART features
  96. */
  97. static void h3600_uart_set_mctrl(struct uart_port *port, u_int mctrl)
  98. {
  99. if (port->mapbase == _Ser3UTCR0) {
  100. if (mctrl & TIOCM_RTS)
  101. GPCR = GPIO_H3600_COM_RTS;
  102. else
  103. GPSR = GPIO_H3600_COM_RTS;
  104. }
  105. }
  106. static u_int h3600_uart_get_mctrl(struct uart_port *port)
  107. {
  108. u_int ret = TIOCM_CD | TIOCM_CTS | TIOCM_DSR;
  109. if (port->mapbase == _Ser3UTCR0) {
  110. int gplr = GPLR;
  111. /* DCD and CTS bits are inverted in GPLR by RS232 transceiver */
  112. if (gplr & GPIO_H3600_COM_DCD)
  113. ret &= ~TIOCM_CD;
  114. if (gplr & GPIO_H3600_COM_CTS)
  115. ret &= ~TIOCM_CTS;
  116. }
  117. return ret;
  118. }
  119. static void h3600_uart_pm(struct uart_port *port, u_int state, u_int oldstate)
  120. {
  121. if (port->mapbase == _Ser2UTCR0) { /* TODO: REMOVE THIS */
  122. assign_h3600_egpio(IPAQ_EGPIO_IR_ON, !state);
  123. } else if (port->mapbase == _Ser3UTCR0) {
  124. assign_h3600_egpio(IPAQ_EGPIO_RS232_ON, !state);
  125. }
  126. }
  127. /*
  128. * Enable/Disable wake up events for this serial port.
  129. * Obviously, we only support this on the normal COM port.
  130. */
  131. static int h3600_uart_set_wake(struct uart_port *port, u_int enable)
  132. {
  133. int err = -EINVAL;
  134. if (port->mapbase == _Ser3UTCR0) {
  135. if (enable)
  136. PWER |= PWER_GPIO23 | PWER_GPIO25; /* DCD and CTS */
  137. else
  138. PWER &= ~(PWER_GPIO23 | PWER_GPIO25); /* DCD and CTS */
  139. err = 0;
  140. }
  141. return err;
  142. }
  143. static struct sa1100_port_fns h3600_port_fns __initdata = {
  144. .set_mctrl = h3600_uart_set_mctrl,
  145. .get_mctrl = h3600_uart_get_mctrl,
  146. .pm = h3600_uart_pm,
  147. .set_wake = h3600_uart_set_wake,
  148. };
  149. /*
  150. * helper for sa1100fb
  151. */
  152. static void h3xxx_lcd_power(int enable)
  153. {
  154. assign_h3600_egpio(IPAQ_EGPIO_LCD_POWER, enable);
  155. }
  156. static struct map_desc h3600_io_desc[] __initdata = {
  157. { /* static memory bank 2 CS#2 */
  158. .virtual = H3600_BANK_2_VIRT,
  159. .pfn = __phys_to_pfn(SA1100_CS2_PHYS),
  160. .length = 0x02800000,
  161. .type = MT_DEVICE
  162. }, { /* static memory bank 4 CS#4 */
  163. .virtual = H3600_BANK_4_VIRT,
  164. .pfn = __phys_to_pfn(SA1100_CS4_PHYS),
  165. .length = 0x00800000,
  166. .type = MT_DEVICE
  167. }, { /* EGPIO 0 CS#5 */
  168. .virtual = H3600_EGPIO_VIRT,
  169. .pfn = __phys_to_pfn(H3600_EGPIO_PHYS),
  170. .length = 0x01000000,
  171. .type = MT_DEVICE
  172. }
  173. };
  174. /*
  175. * Common map_io initialization
  176. */
  177. static void __init h3xxx_map_io(void)
  178. {
  179. sa1100_map_io();
  180. iotable_init(h3600_io_desc, ARRAY_SIZE(h3600_io_desc));
  181. sa1100_register_uart_fns(&h3600_port_fns);
  182. sa1100_register_uart(0, 3); /* Common serial port */
  183. // sa1100_register_uart(1, 1); /* Microcontroller on 3100/3600 */
  184. /* Ensure those pins are outputs and driving low */
  185. PPDR |= PPC_TXD4 | PPC_SCLK | PPC_SFRM;
  186. PPSR &= ~(PPC_TXD4 | PPC_SCLK | PPC_SFRM);
  187. /* Configure suspend conditions */
  188. PGSR = 0;
  189. PWER = PWER_GPIO0 | PWER_RTC;
  190. PCFR = PCFR_OPDE;
  191. PSDR = 0;
  192. sa1100fb_lcd_power = h3xxx_lcd_power;
  193. }
  194. /************************* H3100 *************************/
  195. #ifdef CONFIG_SA1100_H3100
  196. #define H3100_EGPIO (*(volatile unsigned int *)H3600_EGPIO_VIRT)
  197. static unsigned int h3100_egpio = 0;
  198. static void h3100_control_egpio(enum ipaq_egpio_type x, int setp)
  199. {
  200. unsigned int egpio = 0;
  201. long gpio = 0;
  202. unsigned long flags;
  203. switch (x) {
  204. case IPAQ_EGPIO_LCD_POWER:
  205. egpio |= EGPIO_H3600_LCD_ON;
  206. gpio |= GPIO_H3100_LCD_3V_ON;
  207. break;
  208. case IPAQ_EGPIO_LCD_ENABLE:
  209. break;
  210. case IPAQ_EGPIO_CODEC_NRESET:
  211. egpio |= EGPIO_H3600_CODEC_NRESET;
  212. break;
  213. case IPAQ_EGPIO_AUDIO_ON:
  214. gpio |= GPIO_H3100_AUD_PWR_ON
  215. | GPIO_H3100_AUD_ON;
  216. break;
  217. case IPAQ_EGPIO_QMUTE:
  218. gpio |= GPIO_H3100_QMUTE;
  219. break;
  220. case IPAQ_EGPIO_OPT_NVRAM_ON:
  221. egpio |= EGPIO_H3600_OPT_NVRAM_ON;
  222. break;
  223. case IPAQ_EGPIO_OPT_ON:
  224. egpio |= EGPIO_H3600_OPT_ON;
  225. break;
  226. case IPAQ_EGPIO_CARD_RESET:
  227. egpio |= EGPIO_H3600_CARD_RESET;
  228. break;
  229. case IPAQ_EGPIO_OPT_RESET:
  230. egpio |= EGPIO_H3600_OPT_RESET;
  231. break;
  232. case IPAQ_EGPIO_IR_ON:
  233. gpio |= GPIO_H3100_IR_ON;
  234. break;
  235. case IPAQ_EGPIO_IR_FSEL:
  236. gpio |= GPIO_H3100_IR_FSEL;
  237. break;
  238. case IPAQ_EGPIO_RS232_ON:
  239. egpio |= EGPIO_H3600_RS232_ON;
  240. break;
  241. case IPAQ_EGPIO_VPP_ON:
  242. egpio |= EGPIO_H3600_VPP_ON;
  243. break;
  244. }
  245. if (egpio || gpio) {
  246. local_irq_save(flags);
  247. if (setp) {
  248. h3100_egpio |= egpio;
  249. GPSR = gpio;
  250. } else {
  251. h3100_egpio &= ~egpio;
  252. GPCR = gpio;
  253. }
  254. H3100_EGPIO = h3100_egpio;
  255. local_irq_restore(flags);
  256. }
  257. }
  258. #define H3100_DIRECT_EGPIO (GPIO_H3100_BT_ON \
  259. | GPIO_H3100_GPIO3 \
  260. | GPIO_H3100_QMUTE \
  261. | GPIO_H3100_LCD_3V_ON \
  262. | GPIO_H3100_AUD_ON \
  263. | GPIO_H3100_AUD_PWR_ON \
  264. | GPIO_H3100_IR_ON \
  265. | GPIO_H3100_IR_FSEL)
  266. static void __init h3100_map_io(void)
  267. {
  268. h3xxx_map_io();
  269. /* Initialize h3100-specific values here */
  270. GPCR = 0x0fffffff; /* All outputs are set low by default */
  271. GPDR = GPIO_H3600_COM_RTS | GPIO_H3600_L3_CLOCK |
  272. GPIO_H3600_L3_MODE | GPIO_H3600_L3_DATA |
  273. GPIO_H3600_CLK_SET1 | GPIO_H3600_CLK_SET0 |
  274. H3100_DIRECT_EGPIO;
  275. /* Older bootldrs put GPIO2-9 in alternate mode on the
  276. assumption that they are used for video */
  277. GAFR &= ~H3100_DIRECT_EGPIO;
  278. H3100_EGPIO = h3100_egpio;
  279. assign_h3600_egpio = h3100_control_egpio;
  280. }
  281. MACHINE_START(H3100, "Compaq iPAQ H3100")
  282. .phys_io = 0x80000000,
  283. .io_pg_offst = ((0xf8000000) >> 18) & 0xfffc,
  284. .boot_params = 0xc0000100,
  285. .map_io = h3100_map_io,
  286. .init_irq = sa1100_init_irq,
  287. .timer = &sa1100_timer,
  288. .init_machine = h3xxx_mach_init,
  289. MACHINE_END
  290. #endif /* CONFIG_SA1100_H3100 */
  291. /************************* H3600 *************************/
  292. #ifdef CONFIG_SA1100_H3600
  293. #define H3600_EGPIO (*(volatile unsigned int *)H3600_EGPIO_VIRT)
  294. static unsigned int h3600_egpio = EGPIO_H3600_RS232_ON;
  295. static void h3600_control_egpio(enum ipaq_egpio_type x, int setp)
  296. {
  297. unsigned int egpio = 0;
  298. unsigned long flags;
  299. switch (x) {
  300. case IPAQ_EGPIO_LCD_POWER:
  301. egpio |= EGPIO_H3600_LCD_ON |
  302. EGPIO_H3600_LCD_PCI |
  303. EGPIO_H3600_LCD_5V_ON |
  304. EGPIO_H3600_LVDD_ON;
  305. break;
  306. case IPAQ_EGPIO_LCD_ENABLE:
  307. break;
  308. case IPAQ_EGPIO_CODEC_NRESET:
  309. egpio |= EGPIO_H3600_CODEC_NRESET;
  310. break;
  311. case IPAQ_EGPIO_AUDIO_ON:
  312. egpio |= EGPIO_H3600_AUD_AMP_ON |
  313. EGPIO_H3600_AUD_PWR_ON;
  314. break;
  315. case IPAQ_EGPIO_QMUTE:
  316. egpio |= EGPIO_H3600_QMUTE;
  317. break;
  318. case IPAQ_EGPIO_OPT_NVRAM_ON:
  319. egpio |= EGPIO_H3600_OPT_NVRAM_ON;
  320. break;
  321. case IPAQ_EGPIO_OPT_ON:
  322. egpio |= EGPIO_H3600_OPT_ON;
  323. break;
  324. case IPAQ_EGPIO_CARD_RESET:
  325. egpio |= EGPIO_H3600_CARD_RESET;
  326. break;
  327. case IPAQ_EGPIO_OPT_RESET:
  328. egpio |= EGPIO_H3600_OPT_RESET;
  329. break;
  330. case IPAQ_EGPIO_IR_ON:
  331. egpio |= EGPIO_H3600_IR_ON;
  332. break;
  333. case IPAQ_EGPIO_IR_FSEL:
  334. egpio |= EGPIO_H3600_IR_FSEL;
  335. break;
  336. case IPAQ_EGPIO_RS232_ON:
  337. egpio |= EGPIO_H3600_RS232_ON;
  338. break;
  339. case IPAQ_EGPIO_VPP_ON:
  340. egpio |= EGPIO_H3600_VPP_ON;
  341. break;
  342. }
  343. if (egpio) {
  344. local_irq_save(flags);
  345. if (setp)
  346. h3600_egpio |= egpio;
  347. else
  348. h3600_egpio &= ~egpio;
  349. H3600_EGPIO = h3600_egpio;
  350. local_irq_restore(flags);
  351. }
  352. }
  353. static void __init h3600_map_io(void)
  354. {
  355. h3xxx_map_io();
  356. /* Initialize h3600-specific values here */
  357. GPCR = 0x0fffffff; /* All outputs are set low by default */
  358. GPDR = GPIO_H3600_COM_RTS | GPIO_H3600_L3_CLOCK |
  359. GPIO_H3600_L3_MODE | GPIO_H3600_L3_DATA |
  360. GPIO_H3600_CLK_SET1 | GPIO_H3600_CLK_SET0 |
  361. GPIO_LDD15 | GPIO_LDD14 | GPIO_LDD13 | GPIO_LDD12 |
  362. GPIO_LDD11 | GPIO_LDD10 | GPIO_LDD9 | GPIO_LDD8;
  363. H3600_EGPIO = h3600_egpio; /* Maintains across sleep? */
  364. assign_h3600_egpio = h3600_control_egpio;
  365. }
  366. MACHINE_START(H3600, "Compaq iPAQ H3600")
  367. .phys_io = 0x80000000,
  368. .io_pg_offst = ((0xf8000000) >> 18) & 0xfffc,
  369. .boot_params = 0xc0000100,
  370. .map_io = h3600_map_io,
  371. .init_irq = sa1100_init_irq,
  372. .timer = &sa1100_timer,
  373. .init_machine = h3xxx_mach_init,
  374. MACHINE_END
  375. #endif /* CONFIG_SA1100_H3600 */