h3600.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518
  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 <linux/gpio.h>
  32. #include <asm/irq.h>
  33. #include <mach/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 <mach/h3600.h>
  43. #include <mach/h3600_gpio.h>
  44. #include "generic.h"
  45. void (*assign_h3600_egpio)(enum ipaq_egpio_type x, int level);
  46. EXPORT_SYMBOL(assign_h3600_egpio);
  47. struct gpio_default_state {
  48. int gpio;
  49. int mode;
  50. const char *name;
  51. };
  52. #define GPIO_MODE_IN -1
  53. #define GPIO_MODE_OUT0 0
  54. #define GPIO_MODE_OUT1 1
  55. static void h3xxx_init_gpio(struct gpio_default_state *s, size_t n)
  56. {
  57. while (n--) {
  58. const char *name = s->name;
  59. int err;
  60. if (!name)
  61. name = "[init]";
  62. err = gpio_request(s->gpio, name);
  63. if (err) {
  64. printk(KERN_ERR "gpio%u: unable to request: %d\n",
  65. s->gpio, err);
  66. continue;
  67. }
  68. if (s->mode >= 0) {
  69. err = gpio_direction_output(s->gpio, s->mode);
  70. } else {
  71. err = gpio_direction_input(s->gpio);
  72. }
  73. if (err) {
  74. printk(KERN_ERR "gpio%u: unable to set direction: %d\n",
  75. s->gpio, err);
  76. continue;
  77. }
  78. if (!s->name)
  79. gpio_free(s->gpio);
  80. s++;
  81. }
  82. }
  83. /*
  84. * H3xxx flash support
  85. */
  86. static struct mtd_partition h3xxx_partitions[] = {
  87. {
  88. .name = "H3XXX boot firmware",
  89. .size = 0x00040000,
  90. .offset = 0,
  91. .mask_flags = MTD_WRITEABLE, /* force read-only */
  92. }, {
  93. .name = "H3XXX rootfs",
  94. .size = MTDPART_SIZ_FULL,
  95. .offset = 0x00040000,
  96. }
  97. };
  98. static void h3xxx_set_vpp(int vpp)
  99. {
  100. assign_h3600_egpio(IPAQ_EGPIO_VPP_ON, vpp);
  101. }
  102. static struct flash_platform_data h3xxx_flash_data = {
  103. .map_name = "cfi_probe",
  104. .set_vpp = h3xxx_set_vpp,
  105. .parts = h3xxx_partitions,
  106. .nr_parts = ARRAY_SIZE(h3xxx_partitions),
  107. };
  108. static struct resource h3xxx_flash_resource = {
  109. .start = SA1100_CS0_PHYS,
  110. .end = SA1100_CS0_PHYS + SZ_32M - 1,
  111. .flags = IORESOURCE_MEM,
  112. };
  113. /*
  114. * H3xxx uart support
  115. */
  116. static void h3xxx_uart_set_mctrl(struct uart_port *port, u_int mctrl)
  117. {
  118. if (port->mapbase == _Ser3UTCR0) {
  119. gpio_set_value(H3XXX_GPIO_COM_RTS, !(mctrl & TIOCM_RTS));
  120. }
  121. }
  122. static u_int h3xxx_uart_get_mctrl(struct uart_port *port)
  123. {
  124. u_int ret = TIOCM_CD | TIOCM_CTS | TIOCM_DSR;
  125. if (port->mapbase == _Ser3UTCR0) {
  126. /*
  127. * DCD and CTS bits are inverted in GPLR by RS232 transceiver
  128. */
  129. if (gpio_get_value(H3XXX_GPIO_COM_DCD))
  130. ret &= ~TIOCM_CD;
  131. if (gpio_get_value(H3XXX_GPIO_COM_CTS))
  132. ret &= ~TIOCM_CTS;
  133. }
  134. return ret;
  135. }
  136. static void h3xxx_uart_pm(struct uart_port *port, u_int state, u_int oldstate)
  137. {
  138. if (port->mapbase == _Ser3UTCR0)
  139. assign_h3600_egpio(IPAQ_EGPIO_RS232_ON, !state);
  140. }
  141. /*
  142. * Enable/Disable wake up events for this serial port.
  143. * Obviously, we only support this on the normal COM port.
  144. */
  145. static int h3xxx_uart_set_wake(struct uart_port *port, u_int enable)
  146. {
  147. int err = -EINVAL;
  148. if (port->mapbase == _Ser3UTCR0) {
  149. if (enable)
  150. PWER |= PWER_GPIO23 | PWER_GPIO25; /* DCD and CTS */
  151. else
  152. PWER &= ~(PWER_GPIO23 | PWER_GPIO25); /* DCD and CTS */
  153. err = 0;
  154. }
  155. return err;
  156. }
  157. static struct sa1100_port_fns h3xxx_port_fns __initdata = {
  158. .set_mctrl = h3xxx_uart_set_mctrl,
  159. .get_mctrl = h3xxx_uart_get_mctrl,
  160. .pm = h3xxx_uart_pm,
  161. .set_wake = h3xxx_uart_set_wake,
  162. };
  163. static void __init h3xxx_mach_init(void)
  164. {
  165. sa1100_register_uart_fns(&h3xxx_port_fns);
  166. sa11x0_register_mtd(&h3xxx_flash_data, &h3xxx_flash_resource, 1);
  167. }
  168. /*
  169. * helper for sa1100fb
  170. */
  171. static void h3xxx_lcd_power(int enable)
  172. {
  173. assign_h3600_egpio(IPAQ_EGPIO_LCD_POWER, enable);
  174. }
  175. static struct map_desc h3600_io_desc[] __initdata = {
  176. { /* static memory bank 2 CS#2 */
  177. .virtual = H3600_BANK_2_VIRT,
  178. .pfn = __phys_to_pfn(SA1100_CS2_PHYS),
  179. .length = 0x02800000,
  180. .type = MT_DEVICE
  181. }, { /* static memory bank 4 CS#4 */
  182. .virtual = H3600_BANK_4_VIRT,
  183. .pfn = __phys_to_pfn(SA1100_CS4_PHYS),
  184. .length = 0x00800000,
  185. .type = MT_DEVICE
  186. }, { /* EGPIO 0 CS#5 */
  187. .virtual = H3600_EGPIO_VIRT,
  188. .pfn = __phys_to_pfn(H3600_EGPIO_PHYS),
  189. .length = 0x01000000,
  190. .type = MT_DEVICE
  191. }
  192. };
  193. /*
  194. * Common map_io initialization
  195. */
  196. static void __init h3xxx_map_io(void)
  197. {
  198. sa1100_map_io();
  199. iotable_init(h3600_io_desc, ARRAY_SIZE(h3600_io_desc));
  200. sa1100_register_uart(0, 3); /* Common serial port */
  201. // sa1100_register_uart(1, 1); /* Microcontroller on 3100/3600 */
  202. /* Ensure those pins are outputs and driving low */
  203. PPDR |= PPC_TXD4 | PPC_SCLK | PPC_SFRM;
  204. PPSR &= ~(PPC_TXD4 | PPC_SCLK | PPC_SFRM);
  205. /* Configure suspend conditions */
  206. PGSR = 0;
  207. PWER = PWER_GPIO0;
  208. PCFR = PCFR_OPDE;
  209. PSDR = 0;
  210. sa1100fb_lcd_power = h3xxx_lcd_power;
  211. }
  212. /************************* H3100 *************************/
  213. #ifdef CONFIG_SA1100_H3100
  214. #define H3100_EGPIO (*(volatile unsigned int *)H3600_EGPIO_VIRT)
  215. static unsigned int h3100_egpio = 0;
  216. static void h3100_control_egpio(enum ipaq_egpio_type x, int setp)
  217. {
  218. unsigned int egpio = 0;
  219. long gpio = 0;
  220. unsigned long flags;
  221. switch (x) {
  222. case IPAQ_EGPIO_LCD_POWER:
  223. egpio |= EGPIO_H3600_LCD_ON;
  224. gpio |= GPIO_H3100_LCD_3V_ON;
  225. break;
  226. case IPAQ_EGPIO_LCD_ENABLE:
  227. break;
  228. case IPAQ_EGPIO_CODEC_NRESET:
  229. egpio |= EGPIO_H3600_CODEC_NRESET;
  230. break;
  231. case IPAQ_EGPIO_AUDIO_ON:
  232. gpio |= GPIO_H3100_AUD_PWR_ON
  233. | GPIO_H3100_AUD_ON;
  234. break;
  235. case IPAQ_EGPIO_QMUTE:
  236. gpio |= GPIO_H3100_QMUTE;
  237. break;
  238. case IPAQ_EGPIO_OPT_NVRAM_ON:
  239. egpio |= EGPIO_H3600_OPT_NVRAM_ON;
  240. break;
  241. case IPAQ_EGPIO_OPT_ON:
  242. egpio |= EGPIO_H3600_OPT_ON;
  243. break;
  244. case IPAQ_EGPIO_CARD_RESET:
  245. egpio |= EGPIO_H3600_CARD_RESET;
  246. break;
  247. case IPAQ_EGPIO_OPT_RESET:
  248. egpio |= EGPIO_H3600_OPT_RESET;
  249. break;
  250. case IPAQ_EGPIO_IR_ON:
  251. gpio |= GPIO_H3100_IR_ON;
  252. break;
  253. case IPAQ_EGPIO_IR_FSEL:
  254. gpio |= GPIO_H3100_IR_FSEL;
  255. break;
  256. case IPAQ_EGPIO_RS232_ON:
  257. egpio |= EGPIO_H3600_RS232_ON;
  258. break;
  259. case IPAQ_EGPIO_VPP_ON:
  260. egpio |= EGPIO_H3600_VPP_ON;
  261. break;
  262. }
  263. if (egpio || gpio) {
  264. local_irq_save(flags);
  265. if (setp) {
  266. h3100_egpio |= egpio;
  267. GPSR = gpio;
  268. } else {
  269. h3100_egpio &= ~egpio;
  270. GPCR = gpio;
  271. }
  272. H3100_EGPIO = h3100_egpio;
  273. local_irq_restore(flags);
  274. }
  275. }
  276. #define H3100_DIRECT_EGPIO (GPIO_H3100_BT_ON \
  277. | GPIO_H3100_GPIO3 \
  278. | GPIO_H3100_QMUTE \
  279. | GPIO_H3100_LCD_3V_ON \
  280. | GPIO_H3100_AUD_ON \
  281. | GPIO_H3100_AUD_PWR_ON \
  282. | GPIO_H3100_IR_ON \
  283. | GPIO_H3100_IR_FSEL)
  284. static void __init h3100_map_io(void)
  285. {
  286. h3xxx_map_io();
  287. /* Initialize h3100-specific values here */
  288. GPCR = 0x0fffffff; /* All outputs are set low by default */
  289. GPDR = GPIO_H3600_L3_CLOCK |
  290. GPIO_H3600_L3_MODE | GPIO_H3600_L3_DATA |
  291. GPIO_H3600_CLK_SET1 | GPIO_H3600_CLK_SET0 |
  292. H3100_DIRECT_EGPIO;
  293. /* Older bootldrs put GPIO2-9 in alternate mode on the
  294. assumption that they are used for video */
  295. GAFR &= ~H3100_DIRECT_EGPIO;
  296. H3100_EGPIO = h3100_egpio;
  297. assign_h3600_egpio = h3100_control_egpio;
  298. }
  299. /*
  300. * This turns the IRDA power on or off on the Compaq H3100
  301. */
  302. static int h3100_irda_set_power(struct device *dev, unsigned int state)
  303. {
  304. gpio_set_value(H3100_GPIO_IR_ON, state);
  305. return 0;
  306. }
  307. static void h3100_irda_set_speed(struct device *dev, unsigned int speed)
  308. {
  309. gpio_set_value(H3100_GPIO_IR_FSEL, !(speed < 4000000));
  310. }
  311. static struct irda_platform_data h3100_irda_data = {
  312. .set_power = h3100_irda_set_power,
  313. .set_speed = h3100_irda_set_speed,
  314. };
  315. static struct gpio_default_state h3100_default_gpio[] = {
  316. { H3100_GPIO_IR_ON, GPIO_MODE_OUT0, "IrDA power" },
  317. { H3100_GPIO_IR_FSEL, GPIO_MODE_OUT0, "IrDA fsel" },
  318. { H3XXX_GPIO_COM_DCD, GPIO_MODE_IN, "COM DCD" },
  319. { H3XXX_GPIO_COM_CTS, GPIO_MODE_IN, "COM CTS" },
  320. { H3XXX_GPIO_COM_RTS, GPIO_MODE_OUT0, "COM RTS" },
  321. };
  322. static void __init h3100_mach_init(void)
  323. {
  324. h3xxx_init_gpio(h3100_default_gpio, ARRAY_SIZE(h3100_default_gpio));
  325. h3xxx_mach_init();
  326. sa11x0_register_irda(&h3100_irda_data);
  327. }
  328. MACHINE_START(H3100, "Compaq iPAQ H3100")
  329. .phys_io = 0x80000000,
  330. .io_pg_offst = ((0xf8000000) >> 18) & 0xfffc,
  331. .boot_params = 0xc0000100,
  332. .map_io = h3100_map_io,
  333. .init_irq = sa1100_init_irq,
  334. .timer = &sa1100_timer,
  335. .init_machine = h3100_mach_init,
  336. MACHINE_END
  337. #endif /* CONFIG_SA1100_H3100 */
  338. /************************* H3600 *************************/
  339. #ifdef CONFIG_SA1100_H3600
  340. #define H3600_EGPIO (*(volatile unsigned int *)H3600_EGPIO_VIRT)
  341. static unsigned int h3600_egpio = EGPIO_H3600_RS232_ON;
  342. static void h3600_control_egpio(enum ipaq_egpio_type x, int setp)
  343. {
  344. unsigned int egpio = 0;
  345. unsigned long flags;
  346. switch (x) {
  347. case IPAQ_EGPIO_LCD_POWER:
  348. egpio |= EGPIO_H3600_LCD_ON |
  349. EGPIO_H3600_LCD_PCI |
  350. EGPIO_H3600_LCD_5V_ON |
  351. EGPIO_H3600_LVDD_ON;
  352. break;
  353. case IPAQ_EGPIO_LCD_ENABLE:
  354. break;
  355. case IPAQ_EGPIO_CODEC_NRESET:
  356. egpio |= EGPIO_H3600_CODEC_NRESET;
  357. break;
  358. case IPAQ_EGPIO_AUDIO_ON:
  359. egpio |= EGPIO_H3600_AUD_AMP_ON |
  360. EGPIO_H3600_AUD_PWR_ON;
  361. break;
  362. case IPAQ_EGPIO_QMUTE:
  363. egpio |= EGPIO_H3600_QMUTE;
  364. break;
  365. case IPAQ_EGPIO_OPT_NVRAM_ON:
  366. egpio |= EGPIO_H3600_OPT_NVRAM_ON;
  367. break;
  368. case IPAQ_EGPIO_OPT_ON:
  369. egpio |= EGPIO_H3600_OPT_ON;
  370. break;
  371. case IPAQ_EGPIO_CARD_RESET:
  372. egpio |= EGPIO_H3600_CARD_RESET;
  373. break;
  374. case IPAQ_EGPIO_OPT_RESET:
  375. egpio |= EGPIO_H3600_OPT_RESET;
  376. break;
  377. case IPAQ_EGPIO_IR_ON:
  378. egpio |= EGPIO_H3600_IR_ON;
  379. break;
  380. case IPAQ_EGPIO_IR_FSEL:
  381. egpio |= EGPIO_H3600_IR_FSEL;
  382. break;
  383. case IPAQ_EGPIO_RS232_ON:
  384. egpio |= EGPIO_H3600_RS232_ON;
  385. break;
  386. case IPAQ_EGPIO_VPP_ON:
  387. egpio |= EGPIO_H3600_VPP_ON;
  388. break;
  389. }
  390. if (egpio) {
  391. local_irq_save(flags);
  392. if (setp)
  393. h3600_egpio |= egpio;
  394. else
  395. h3600_egpio &= ~egpio;
  396. H3600_EGPIO = h3600_egpio;
  397. local_irq_restore(flags);
  398. }
  399. }
  400. static void __init h3600_map_io(void)
  401. {
  402. h3xxx_map_io();
  403. /* Initialize h3600-specific values here */
  404. GPCR = 0x0fffffff; /* All outputs are set low by default */
  405. GPDR = GPIO_H3600_L3_CLOCK |
  406. GPIO_H3600_L3_MODE | GPIO_H3600_L3_DATA |
  407. GPIO_H3600_CLK_SET1 | GPIO_H3600_CLK_SET0 |
  408. GPIO_LDD15 | GPIO_LDD14 | GPIO_LDD13 | GPIO_LDD12 |
  409. GPIO_LDD11 | GPIO_LDD10 | GPIO_LDD9 | GPIO_LDD8;
  410. H3600_EGPIO = h3600_egpio; /* Maintains across sleep? */
  411. assign_h3600_egpio = h3600_control_egpio;
  412. }
  413. /*
  414. * This turns the IRDA power on or off on the Compaq H3600
  415. */
  416. static int h3600_irda_set_power(struct device *dev, unsigned int state)
  417. {
  418. assign_h3600_egpio(IPAQ_EGPIO_IR_ON, state);
  419. return 0;
  420. }
  421. static void h3600_irda_set_speed(struct device *dev, unsigned int speed)
  422. {
  423. assign_h3600_egpio(IPAQ_EGPIO_IR_FSEL, !(speed < 4000000));
  424. }
  425. static struct irda_platform_data h3600_irda_data = {
  426. .set_power = h3600_irda_set_power,
  427. .set_speed = h3600_irda_set_speed,
  428. };
  429. static struct gpio_default_state h3600_default_gpio[] = {
  430. { H3XXX_GPIO_COM_DCD, GPIO_MODE_IN, "COM DCD" },
  431. { H3XXX_GPIO_COM_CTS, GPIO_MODE_IN, "COM CTS" },
  432. { H3XXX_GPIO_COM_RTS, GPIO_MODE_OUT0, "COM RTS" },
  433. };
  434. static void __init h3600_mach_init(void)
  435. {
  436. h3xxx_init_gpio(h3600_default_gpio, ARRAY_SIZE(h3600_default_gpio));
  437. h3xxx_mach_init();
  438. sa11x0_register_irda(&h3600_irda_data);
  439. }
  440. MACHINE_START(H3600, "Compaq iPAQ H3600")
  441. .phys_io = 0x80000000,
  442. .io_pg_offst = ((0xf8000000) >> 18) & 0xfffc,
  443. .boot_params = 0xc0000100,
  444. .map_io = h3600_map_io,
  445. .init_irq = sa1100_init_irq,
  446. .timer = &sa1100_timer,
  447. .init_machine = h3600_mach_init,
  448. MACHINE_END
  449. #endif /* CONFIG_SA1100_H3600 */