h3600.c 11 KB

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