h3600.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521
  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 == _Ser2UTCR0) { /* TODO: REMOVE THIS */
  139. assign_h3600_egpio(IPAQ_EGPIO_IR_ON, !state);
  140. } else if (port->mapbase == _Ser3UTCR0) {
  141. assign_h3600_egpio(IPAQ_EGPIO_RS232_ON, !state);
  142. }
  143. }
  144. /*
  145. * Enable/Disable wake up events for this serial port.
  146. * Obviously, we only support this on the normal COM port.
  147. */
  148. static int h3xxx_uart_set_wake(struct uart_port *port, u_int enable)
  149. {
  150. int err = -EINVAL;
  151. if (port->mapbase == _Ser3UTCR0) {
  152. if (enable)
  153. PWER |= PWER_GPIO23 | PWER_GPIO25; /* DCD and CTS */
  154. else
  155. PWER &= ~(PWER_GPIO23 | PWER_GPIO25); /* DCD and CTS */
  156. err = 0;
  157. }
  158. return err;
  159. }
  160. static struct sa1100_port_fns h3xxx_port_fns __initdata = {
  161. .set_mctrl = h3xxx_uart_set_mctrl,
  162. .get_mctrl = h3xxx_uart_get_mctrl,
  163. .pm = h3xxx_uart_pm,
  164. .set_wake = h3xxx_uart_set_wake,
  165. };
  166. static void __init h3xxx_mach_init(void)
  167. {
  168. sa1100_register_uart_fns(&h3xxx_port_fns);
  169. sa11x0_register_mtd(&h3xxx_flash_data, &h3xxx_flash_resource, 1);
  170. }
  171. /*
  172. * helper for sa1100fb
  173. */
  174. static void h3xxx_lcd_power(int enable)
  175. {
  176. assign_h3600_egpio(IPAQ_EGPIO_LCD_POWER, enable);
  177. }
  178. static struct map_desc h3600_io_desc[] __initdata = {
  179. { /* static memory bank 2 CS#2 */
  180. .virtual = H3600_BANK_2_VIRT,
  181. .pfn = __phys_to_pfn(SA1100_CS2_PHYS),
  182. .length = 0x02800000,
  183. .type = MT_DEVICE
  184. }, { /* static memory bank 4 CS#4 */
  185. .virtual = H3600_BANK_4_VIRT,
  186. .pfn = __phys_to_pfn(SA1100_CS4_PHYS),
  187. .length = 0x00800000,
  188. .type = MT_DEVICE
  189. }, { /* EGPIO 0 CS#5 */
  190. .virtual = H3600_EGPIO_VIRT,
  191. .pfn = __phys_to_pfn(H3600_EGPIO_PHYS),
  192. .length = 0x01000000,
  193. .type = MT_DEVICE
  194. }
  195. };
  196. /*
  197. * Common map_io initialization
  198. */
  199. static void __init h3xxx_map_io(void)
  200. {
  201. sa1100_map_io();
  202. iotable_init(h3600_io_desc, ARRAY_SIZE(h3600_io_desc));
  203. sa1100_register_uart(0, 3); /* Common serial port */
  204. // sa1100_register_uart(1, 1); /* Microcontroller on 3100/3600 */
  205. /* Ensure those pins are outputs and driving low */
  206. PPDR |= PPC_TXD4 | PPC_SCLK | PPC_SFRM;
  207. PPSR &= ~(PPC_TXD4 | PPC_SCLK | PPC_SFRM);
  208. /* Configure suspend conditions */
  209. PGSR = 0;
  210. PWER = PWER_GPIO0;
  211. PCFR = PCFR_OPDE;
  212. PSDR = 0;
  213. sa1100fb_lcd_power = h3xxx_lcd_power;
  214. }
  215. /************************* H3100 *************************/
  216. #ifdef CONFIG_SA1100_H3100
  217. #define H3100_EGPIO (*(volatile unsigned int *)H3600_EGPIO_VIRT)
  218. static unsigned int h3100_egpio = 0;
  219. static void h3100_control_egpio(enum ipaq_egpio_type x, int setp)
  220. {
  221. unsigned int egpio = 0;
  222. long gpio = 0;
  223. unsigned long flags;
  224. switch (x) {
  225. case IPAQ_EGPIO_LCD_POWER:
  226. egpio |= EGPIO_H3600_LCD_ON;
  227. gpio |= GPIO_H3100_LCD_3V_ON;
  228. break;
  229. case IPAQ_EGPIO_LCD_ENABLE:
  230. break;
  231. case IPAQ_EGPIO_CODEC_NRESET:
  232. egpio |= EGPIO_H3600_CODEC_NRESET;
  233. break;
  234. case IPAQ_EGPIO_AUDIO_ON:
  235. gpio |= GPIO_H3100_AUD_PWR_ON
  236. | GPIO_H3100_AUD_ON;
  237. break;
  238. case IPAQ_EGPIO_QMUTE:
  239. gpio |= GPIO_H3100_QMUTE;
  240. break;
  241. case IPAQ_EGPIO_OPT_NVRAM_ON:
  242. egpio |= EGPIO_H3600_OPT_NVRAM_ON;
  243. break;
  244. case IPAQ_EGPIO_OPT_ON:
  245. egpio |= EGPIO_H3600_OPT_ON;
  246. break;
  247. case IPAQ_EGPIO_CARD_RESET:
  248. egpio |= EGPIO_H3600_CARD_RESET;
  249. break;
  250. case IPAQ_EGPIO_OPT_RESET:
  251. egpio |= EGPIO_H3600_OPT_RESET;
  252. break;
  253. case IPAQ_EGPIO_IR_ON:
  254. gpio |= GPIO_H3100_IR_ON;
  255. break;
  256. case IPAQ_EGPIO_IR_FSEL:
  257. gpio |= GPIO_H3100_IR_FSEL;
  258. break;
  259. case IPAQ_EGPIO_RS232_ON:
  260. egpio |= EGPIO_H3600_RS232_ON;
  261. break;
  262. case IPAQ_EGPIO_VPP_ON:
  263. egpio |= EGPIO_H3600_VPP_ON;
  264. break;
  265. }
  266. if (egpio || gpio) {
  267. local_irq_save(flags);
  268. if (setp) {
  269. h3100_egpio |= egpio;
  270. GPSR = gpio;
  271. } else {
  272. h3100_egpio &= ~egpio;
  273. GPCR = gpio;
  274. }
  275. H3100_EGPIO = h3100_egpio;
  276. local_irq_restore(flags);
  277. }
  278. }
  279. #define H3100_DIRECT_EGPIO (GPIO_H3100_BT_ON \
  280. | GPIO_H3100_GPIO3 \
  281. | GPIO_H3100_QMUTE \
  282. | GPIO_H3100_LCD_3V_ON \
  283. | GPIO_H3100_AUD_ON \
  284. | GPIO_H3100_AUD_PWR_ON \
  285. | GPIO_H3100_IR_ON \
  286. | GPIO_H3100_IR_FSEL)
  287. static void __init h3100_map_io(void)
  288. {
  289. h3xxx_map_io();
  290. /* Initialize h3100-specific values here */
  291. GPCR = 0x0fffffff; /* All outputs are set low by default */
  292. GPDR = GPIO_H3600_L3_CLOCK |
  293. GPIO_H3600_L3_MODE | GPIO_H3600_L3_DATA |
  294. GPIO_H3600_CLK_SET1 | GPIO_H3600_CLK_SET0 |
  295. H3100_DIRECT_EGPIO;
  296. /* Older bootldrs put GPIO2-9 in alternate mode on the
  297. assumption that they are used for video */
  298. GAFR &= ~H3100_DIRECT_EGPIO;
  299. H3100_EGPIO = h3100_egpio;
  300. assign_h3600_egpio = h3100_control_egpio;
  301. }
  302. /*
  303. * This turns the IRDA power on or off on the Compaq H3100
  304. */
  305. static int h3100_irda_set_power(struct device *dev, unsigned int state)
  306. {
  307. gpio_set_value(H3100_GPIO_IR_ON, state);
  308. return 0;
  309. }
  310. static void h3100_irda_set_speed(struct device *dev, unsigned int speed)
  311. {
  312. gpio_set_value(H3100_GPIO_IR_FSEL, !(speed < 4000000));
  313. }
  314. static struct irda_platform_data h3100_irda_data = {
  315. .set_power = h3100_irda_set_power,
  316. .set_speed = h3100_irda_set_speed,
  317. };
  318. static struct gpio_default_state h3100_default_gpio[] = {
  319. { H3100_GPIO_IR_ON, GPIO_MODE_OUT0, "IrDA power" },
  320. { H3100_GPIO_IR_FSEL, GPIO_MODE_OUT0, "IrDA fsel" },
  321. { H3XXX_GPIO_COM_DCD, GPIO_MODE_IN, "COM DCD" },
  322. { H3XXX_GPIO_COM_CTS, GPIO_MODE_IN, "COM CTS" },
  323. { H3XXX_GPIO_COM_RTS, GPIO_MODE_OUT0, "COM RTS" },
  324. };
  325. static void __init h3100_mach_init(void)
  326. {
  327. h3xxx_init_gpio(h3100_default_gpio, ARRAY_SIZE(h3100_default_gpio));
  328. h3xxx_mach_init();
  329. sa11x0_register_irda(&h3100_irda_data);
  330. }
  331. MACHINE_START(H3100, "Compaq iPAQ H3100")
  332. .phys_io = 0x80000000,
  333. .io_pg_offst = ((0xf8000000) >> 18) & 0xfffc,
  334. .boot_params = 0xc0000100,
  335. .map_io = h3100_map_io,
  336. .init_irq = sa1100_init_irq,
  337. .timer = &sa1100_timer,
  338. .init_machine = h3100_mach_init,
  339. MACHINE_END
  340. #endif /* CONFIG_SA1100_H3100 */
  341. /************************* H3600 *************************/
  342. #ifdef CONFIG_SA1100_H3600
  343. #define H3600_EGPIO (*(volatile unsigned int *)H3600_EGPIO_VIRT)
  344. static unsigned int h3600_egpio = EGPIO_H3600_RS232_ON;
  345. static void h3600_control_egpio(enum ipaq_egpio_type x, int setp)
  346. {
  347. unsigned int egpio = 0;
  348. unsigned long flags;
  349. switch (x) {
  350. case IPAQ_EGPIO_LCD_POWER:
  351. egpio |= EGPIO_H3600_LCD_ON |
  352. EGPIO_H3600_LCD_PCI |
  353. EGPIO_H3600_LCD_5V_ON |
  354. EGPIO_H3600_LVDD_ON;
  355. break;
  356. case IPAQ_EGPIO_LCD_ENABLE:
  357. break;
  358. case IPAQ_EGPIO_CODEC_NRESET:
  359. egpio |= EGPIO_H3600_CODEC_NRESET;
  360. break;
  361. case IPAQ_EGPIO_AUDIO_ON:
  362. egpio |= EGPIO_H3600_AUD_AMP_ON |
  363. EGPIO_H3600_AUD_PWR_ON;
  364. break;
  365. case IPAQ_EGPIO_QMUTE:
  366. egpio |= EGPIO_H3600_QMUTE;
  367. break;
  368. case IPAQ_EGPIO_OPT_NVRAM_ON:
  369. egpio |= EGPIO_H3600_OPT_NVRAM_ON;
  370. break;
  371. case IPAQ_EGPIO_OPT_ON:
  372. egpio |= EGPIO_H3600_OPT_ON;
  373. break;
  374. case IPAQ_EGPIO_CARD_RESET:
  375. egpio |= EGPIO_H3600_CARD_RESET;
  376. break;
  377. case IPAQ_EGPIO_OPT_RESET:
  378. egpio |= EGPIO_H3600_OPT_RESET;
  379. break;
  380. case IPAQ_EGPIO_IR_ON:
  381. egpio |= EGPIO_H3600_IR_ON;
  382. break;
  383. case IPAQ_EGPIO_IR_FSEL:
  384. egpio |= EGPIO_H3600_IR_FSEL;
  385. break;
  386. case IPAQ_EGPIO_RS232_ON:
  387. egpio |= EGPIO_H3600_RS232_ON;
  388. break;
  389. case IPAQ_EGPIO_VPP_ON:
  390. egpio |= EGPIO_H3600_VPP_ON;
  391. break;
  392. }
  393. if (egpio) {
  394. local_irq_save(flags);
  395. if (setp)
  396. h3600_egpio |= egpio;
  397. else
  398. h3600_egpio &= ~egpio;
  399. H3600_EGPIO = h3600_egpio;
  400. local_irq_restore(flags);
  401. }
  402. }
  403. static void __init h3600_map_io(void)
  404. {
  405. h3xxx_map_io();
  406. /* Initialize h3600-specific values here */
  407. GPCR = 0x0fffffff; /* All outputs are set low by default */
  408. GPDR = GPIO_H3600_L3_CLOCK |
  409. GPIO_H3600_L3_MODE | GPIO_H3600_L3_DATA |
  410. GPIO_H3600_CLK_SET1 | GPIO_H3600_CLK_SET0 |
  411. GPIO_LDD15 | GPIO_LDD14 | GPIO_LDD13 | GPIO_LDD12 |
  412. GPIO_LDD11 | GPIO_LDD10 | GPIO_LDD9 | GPIO_LDD8;
  413. H3600_EGPIO = h3600_egpio; /* Maintains across sleep? */
  414. assign_h3600_egpio = h3600_control_egpio;
  415. }
  416. /*
  417. * This turns the IRDA power on or off on the Compaq H3600
  418. */
  419. static int h3600_irda_set_power(struct device *dev, unsigned int state)
  420. {
  421. assign_h3600_egpio(IPAQ_EGPIO_IR_ON, state);
  422. return 0;
  423. }
  424. static void h3600_irda_set_speed(struct device *dev, unsigned int speed)
  425. {
  426. assign_h3600_egpio(IPAQ_EGPIO_IR_FSEL, !(speed < 4000000));
  427. }
  428. static struct irda_platform_data h3600_irda_data = {
  429. .set_power = h3600_irda_set_power,
  430. .set_speed = h3600_irda_set_speed,
  431. };
  432. static struct gpio_default_state h3600_default_gpio[] = {
  433. { H3XXX_GPIO_COM_DCD, GPIO_MODE_IN, "COM DCD" },
  434. { H3XXX_GPIO_COM_CTS, GPIO_MODE_IN, "COM CTS" },
  435. { H3XXX_GPIO_COM_RTS, GPIO_MODE_OUT0, "COM RTS" },
  436. };
  437. static void __init h3600_mach_init(void)
  438. {
  439. h3xxx_init_gpio(h3600_default_gpio, ARRAY_SIZE(h3600_default_gpio));
  440. h3xxx_mach_init();
  441. sa11x0_register_irda(&h3600_irda_data);
  442. }
  443. MACHINE_START(H3600, "Compaq iPAQ H3600")
  444. .phys_io = 0x80000000,
  445. .io_pg_offst = ((0xf8000000) >> 18) & 0xfffc,
  446. .boot_params = 0xc0000100,
  447. .map_io = h3600_map_io,
  448. .init_irq = sa1100_init_irq,
  449. .timer = &sa1100_timer,
  450. .init_machine = h3600_mach_init,
  451. MACHINE_END
  452. #endif /* CONFIG_SA1100_H3600 */