h3600.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508
  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/mfd/htc-egpio.h>
  29. #include <linux/mtd/mtd.h>
  30. #include <linux/mtd/partitions.h>
  31. #include <linux/serial_core.h>
  32. #include <linux/gpio.h>
  33. #include <linux/platform_device.h>
  34. #include <asm/irq.h>
  35. #include <mach/hardware.h>
  36. #include <asm/mach-types.h>
  37. #include <asm/setup.h>
  38. #include <asm/mach/irq.h>
  39. #include <asm/mach/arch.h>
  40. #include <asm/mach/flash.h>
  41. #include <asm/mach/irda.h>
  42. #include <asm/mach/map.h>
  43. #include <asm/mach/serial_sa1100.h>
  44. #include <mach/h3600.h>
  45. #include <mach/h3600_gpio.h>
  46. #include "generic.h"
  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. gpio_set_value(H3XXX_EGPIO_VPP_ON, vpp);
  101. }
  102. static int h3xxx_flash_init(void)
  103. {
  104. int err = gpio_request(H3XXX_EGPIO_VPP_ON, "Flash Vpp");
  105. if (err)
  106. return err;
  107. err = gpio_direction_output(H3XXX_EGPIO_VPP_ON, 0);
  108. if (err)
  109. gpio_free(H3XXX_EGPIO_VPP_ON);
  110. return err;
  111. }
  112. static void h3xxx_flash_exit(void)
  113. {
  114. gpio_free(H3XXX_EGPIO_VPP_ON);
  115. }
  116. static struct flash_platform_data h3xxx_flash_data = {
  117. .map_name = "cfi_probe",
  118. .set_vpp = h3xxx_set_vpp,
  119. .init = h3xxx_flash_init,
  120. .exit = h3xxx_flash_exit,
  121. .parts = h3xxx_partitions,
  122. .nr_parts = ARRAY_SIZE(h3xxx_partitions),
  123. };
  124. static struct resource h3xxx_flash_resource = {
  125. .start = SA1100_CS0_PHYS,
  126. .end = SA1100_CS0_PHYS + SZ_32M - 1,
  127. .flags = IORESOURCE_MEM,
  128. };
  129. /*
  130. * H3xxx uart support
  131. */
  132. static void h3xxx_uart_set_mctrl(struct uart_port *port, u_int mctrl)
  133. {
  134. if (port->mapbase == _Ser3UTCR0) {
  135. gpio_set_value(H3XXX_GPIO_COM_RTS, !(mctrl & TIOCM_RTS));
  136. }
  137. }
  138. static u_int h3xxx_uart_get_mctrl(struct uart_port *port)
  139. {
  140. u_int ret = TIOCM_CD | TIOCM_CTS | TIOCM_DSR;
  141. if (port->mapbase == _Ser3UTCR0) {
  142. /*
  143. * DCD and CTS bits are inverted in GPLR by RS232 transceiver
  144. */
  145. if (gpio_get_value(H3XXX_GPIO_COM_DCD))
  146. ret &= ~TIOCM_CD;
  147. if (gpio_get_value(H3XXX_GPIO_COM_CTS))
  148. ret &= ~TIOCM_CTS;
  149. }
  150. return ret;
  151. }
  152. static void h3xxx_uart_pm(struct uart_port *port, u_int state, u_int oldstate)
  153. {
  154. if (port->mapbase == _Ser3UTCR0)
  155. if (!gpio_request(H3XXX_EGPIO_RS232_ON, "RS232 transceiver")) {
  156. gpio_direction_output(H3XXX_EGPIO_RS232_ON, !state);
  157. gpio_free(H3XXX_EGPIO_RS232_ON);
  158. }
  159. }
  160. /*
  161. * Enable/Disable wake up events for this serial port.
  162. * Obviously, we only support this on the normal COM port.
  163. */
  164. static int h3xxx_uart_set_wake(struct uart_port *port, u_int enable)
  165. {
  166. int err = -EINVAL;
  167. if (port->mapbase == _Ser3UTCR0) {
  168. if (enable)
  169. PWER |= PWER_GPIO23 | PWER_GPIO25; /* DCD and CTS */
  170. else
  171. PWER &= ~(PWER_GPIO23 | PWER_GPIO25); /* DCD and CTS */
  172. err = 0;
  173. }
  174. return err;
  175. }
  176. static struct sa1100_port_fns h3xxx_port_fns __initdata = {
  177. .set_mctrl = h3xxx_uart_set_mctrl,
  178. .get_mctrl = h3xxx_uart_get_mctrl,
  179. .pm = h3xxx_uart_pm,
  180. .set_wake = h3xxx_uart_set_wake,
  181. };
  182. /*
  183. * EGPIO
  184. */
  185. static struct resource egpio_resources[] = {
  186. [0] = {
  187. .start = H3600_EGPIO_PHYS,
  188. .end = H3600_EGPIO_PHYS + 0x4 - 1,
  189. .flags = IORESOURCE_MEM,
  190. },
  191. };
  192. static struct htc_egpio_chip egpio_chips[] = {
  193. [0] = {
  194. .reg_start = 0,
  195. .gpio_base = H3XXX_EGPIO_BASE,
  196. .num_gpios = 16,
  197. .direction = HTC_EGPIO_OUTPUT,
  198. .initial_values = 0x0080, /* H3XXX_EGPIO_RS232_ON */
  199. },
  200. };
  201. static struct htc_egpio_platform_data egpio_info = {
  202. .reg_width = 16,
  203. .bus_width = 16,
  204. .chip = egpio_chips,
  205. .num_chips = ARRAY_SIZE(egpio_chips),
  206. };
  207. static struct platform_device h3xxx_egpio = {
  208. .name = "htc-egpio",
  209. .id = -1,
  210. .resource = egpio_resources,
  211. .num_resources = ARRAY_SIZE(egpio_resources),
  212. .dev = {
  213. .platform_data = &egpio_info,
  214. },
  215. };
  216. static struct platform_device *h3xxx_devices[] = {
  217. &h3xxx_egpio,
  218. };
  219. static void __init h3xxx_mach_init(void)
  220. {
  221. sa1100_register_uart_fns(&h3xxx_port_fns);
  222. sa11x0_register_mtd(&h3xxx_flash_data, &h3xxx_flash_resource, 1);
  223. platform_add_devices(h3xxx_devices, ARRAY_SIZE(h3xxx_devices));
  224. }
  225. static struct map_desc h3600_io_desc[] __initdata = {
  226. { /* static memory bank 2 CS#2 */
  227. .virtual = H3600_BANK_2_VIRT,
  228. .pfn = __phys_to_pfn(SA1100_CS2_PHYS),
  229. .length = 0x02800000,
  230. .type = MT_DEVICE
  231. }, { /* static memory bank 4 CS#4 */
  232. .virtual = H3600_BANK_4_VIRT,
  233. .pfn = __phys_to_pfn(SA1100_CS4_PHYS),
  234. .length = 0x00800000,
  235. .type = MT_DEVICE
  236. }, { /* EGPIO 0 CS#5 */
  237. .virtual = H3600_EGPIO_VIRT,
  238. .pfn = __phys_to_pfn(H3600_EGPIO_PHYS),
  239. .length = 0x01000000,
  240. .type = MT_DEVICE
  241. }
  242. };
  243. /*
  244. * Common map_io initialization
  245. */
  246. static void __init h3xxx_map_io(void)
  247. {
  248. sa1100_map_io();
  249. iotable_init(h3600_io_desc, ARRAY_SIZE(h3600_io_desc));
  250. sa1100_register_uart(0, 3); /* Common serial port */
  251. // sa1100_register_uart(1, 1); /* Microcontroller on 3100/3600 */
  252. /* Ensure those pins are outputs and driving low */
  253. PPDR |= PPC_TXD4 | PPC_SCLK | PPC_SFRM;
  254. PPSR &= ~(PPC_TXD4 | PPC_SCLK | PPC_SFRM);
  255. /* Configure suspend conditions */
  256. PGSR = 0;
  257. PWER = PWER_GPIO0;
  258. PCFR = PCFR_OPDE;
  259. PSDR = 0;
  260. }
  261. /************************* H3100 *************************/
  262. #ifdef CONFIG_SA1100_H3100
  263. #define H3100_DIRECT_EGPIO (GPIO_H3100_BT_ON \
  264. | GPIO_H3100_GPIO3 \
  265. | GPIO_H3100_QMUTE \
  266. | GPIO_H3100_LCD_3V_ON \
  267. | GPIO_H3100_AUD_ON \
  268. | GPIO_H3100_AUD_PWR_ON \
  269. | GPIO_H3100_IR_ON \
  270. | GPIO_H3100_IR_FSEL)
  271. /*
  272. * helper for sa1100fb
  273. */
  274. static void h3100_lcd_power(int enable)
  275. {
  276. if (!gpio_request(H3XXX_EGPIO_LCD_ON, "LCD ON")) {
  277. gpio_set_value(H3100_GPIO_LCD_3V_ON, enable);
  278. gpio_direction_output(H3XXX_EGPIO_LCD_ON, enable);
  279. gpio_free(H3XXX_EGPIO_LCD_ON);
  280. }
  281. }
  282. static void __init h3100_map_io(void)
  283. {
  284. h3xxx_map_io();
  285. sa1100fb_lcd_power = h3100_lcd_power;
  286. /* Initialize h3100-specific values here */
  287. GPCR = 0x0fffffff; /* All outputs are set low by default */
  288. GPDR = GPIO_H3600_L3_CLOCK |
  289. GPIO_H3600_L3_MODE | GPIO_H3600_L3_DATA |
  290. GPIO_H3600_CLK_SET1 | GPIO_H3600_CLK_SET0 |
  291. H3100_DIRECT_EGPIO;
  292. /* Older bootldrs put GPIO2-9 in alternate mode on the
  293. assumption that they are used for video */
  294. GAFR &= ~H3100_DIRECT_EGPIO;
  295. }
  296. /*
  297. * This turns the IRDA power on or off on the Compaq H3100
  298. */
  299. static int h3100_irda_set_power(struct device *dev, unsigned int state)
  300. {
  301. gpio_set_value(H3100_GPIO_IR_ON, state);
  302. return 0;
  303. }
  304. static void h3100_irda_set_speed(struct device *dev, unsigned int speed)
  305. {
  306. gpio_set_value(H3100_GPIO_IR_FSEL, !(speed < 4000000));
  307. }
  308. static struct irda_platform_data h3100_irda_data = {
  309. .set_power = h3100_irda_set_power,
  310. .set_speed = h3100_irda_set_speed,
  311. };
  312. static struct gpio_default_state h3100_default_gpio[] = {
  313. { H3100_GPIO_IR_ON, GPIO_MODE_OUT0, "IrDA power" },
  314. { H3100_GPIO_IR_FSEL, GPIO_MODE_OUT0, "IrDA fsel" },
  315. { H3XXX_GPIO_COM_DCD, GPIO_MODE_IN, "COM DCD" },
  316. { H3XXX_GPIO_COM_CTS, GPIO_MODE_IN, "COM CTS" },
  317. { H3XXX_GPIO_COM_RTS, GPIO_MODE_OUT0, "COM RTS" },
  318. { H3100_GPIO_LCD_3V_ON, GPIO_MODE_OUT0, "LCD 3v" },
  319. };
  320. static void __init h3100_mach_init(void)
  321. {
  322. h3xxx_init_gpio(h3100_default_gpio, ARRAY_SIZE(h3100_default_gpio));
  323. h3xxx_mach_init();
  324. sa11x0_register_irda(&h3100_irda_data);
  325. }
  326. MACHINE_START(H3100, "Compaq iPAQ H3100")
  327. .phys_io = 0x80000000,
  328. .io_pg_offst = ((0xf8000000) >> 18) & 0xfffc,
  329. .boot_params = 0xc0000100,
  330. .map_io = h3100_map_io,
  331. .init_irq = sa1100_init_irq,
  332. .timer = &sa1100_timer,
  333. .init_machine = h3100_mach_init,
  334. MACHINE_END
  335. #endif /* CONFIG_SA1100_H3100 */
  336. /************************* H3600 *************************/
  337. #ifdef CONFIG_SA1100_H3600
  338. /*
  339. * helper for sa1100fb
  340. */
  341. static void h3600_lcd_power(int enable)
  342. {
  343. if (gpio_request(H3XXX_EGPIO_LCD_ON, "LCD power"))
  344. goto err1;
  345. if (gpio_request(H3600_EGPIO_LCD_PCI, "LCD control"))
  346. goto err2;
  347. if (gpio_request(H3600_EGPIO_LCD_5V_ON, "LCD 5v"))
  348. goto err3;
  349. if (gpio_request(H3600_EGPIO_LVDD_ON, "LCD 9v/-6.5v"))
  350. goto err4;
  351. gpio_direction_output(H3XXX_EGPIO_LCD_ON, enable);
  352. gpio_direction_output(H3600_EGPIO_LCD_PCI, enable);
  353. gpio_direction_output(H3600_EGPIO_LCD_5V_ON, enable);
  354. gpio_direction_output(H3600_EGPIO_LVDD_ON, enable);
  355. gpio_free(H3600_EGPIO_LVDD_ON);
  356. err4: gpio_free(H3600_EGPIO_LCD_5V_ON);
  357. err3: gpio_free(H3600_EGPIO_LCD_PCI);
  358. err2: gpio_free(H3XXX_EGPIO_LCD_ON);
  359. err1: return;
  360. }
  361. static void __init h3600_map_io(void)
  362. {
  363. h3xxx_map_io();
  364. sa1100fb_lcd_power = h3600_lcd_power;
  365. /* Initialize h3600-specific values here */
  366. GPCR = 0x0fffffff; /* All outputs are set low by default */
  367. GPDR = GPIO_H3600_L3_CLOCK |
  368. GPIO_H3600_L3_MODE | GPIO_H3600_L3_DATA |
  369. GPIO_H3600_CLK_SET1 | GPIO_H3600_CLK_SET0;
  370. }
  371. /*
  372. * This turns the IRDA power on or off on the Compaq H3600
  373. */
  374. static int h3600_irda_set_power(struct device *dev, unsigned int state)
  375. {
  376. gpio_set_value(H3600_EGPIO_IR_ON, state);
  377. return 0;
  378. }
  379. static void h3600_irda_set_speed(struct device *dev, unsigned int speed)
  380. {
  381. gpio_set_value(H3600_EGPIO_IR_FSEL, !(speed < 4000000));
  382. }
  383. static int h3600_irda_startup(struct device *dev)
  384. {
  385. int err = gpio_request(H3600_EGPIO_IR_ON, "IrDA power");
  386. if (err)
  387. goto err1;
  388. err = gpio_direction_output(H3600_EGPIO_IR_ON, 0);
  389. if (err)
  390. goto err2;
  391. err = gpio_request(H3600_EGPIO_IR_FSEL, "IrDA fsel");
  392. if (err)
  393. goto err2;
  394. err = gpio_direction_output(H3600_EGPIO_IR_FSEL, 0);
  395. if (err)
  396. goto err3;
  397. return 0;
  398. err3: gpio_free(H3600_EGPIO_IR_FSEL);
  399. err2: gpio_free(H3600_EGPIO_IR_ON);
  400. err1: return err;
  401. }
  402. static void h3600_irda_shutdown(struct device *dev)
  403. {
  404. gpio_free(H3600_EGPIO_IR_ON);
  405. gpio_free(H3600_EGPIO_IR_FSEL);
  406. }
  407. static struct irda_platform_data h3600_irda_data = {
  408. .set_power = h3600_irda_set_power,
  409. .set_speed = h3600_irda_set_speed,
  410. .startup = h3600_irda_startup,
  411. .shutdown = h3600_irda_shutdown,
  412. };
  413. static struct gpio_default_state h3600_default_gpio[] = {
  414. { H3XXX_GPIO_COM_DCD, GPIO_MODE_IN, "COM DCD" },
  415. { H3XXX_GPIO_COM_CTS, GPIO_MODE_IN, "COM CTS" },
  416. { H3XXX_GPIO_COM_RTS, GPIO_MODE_OUT0, "COM RTS" },
  417. };
  418. static void __init h3600_mach_init(void)
  419. {
  420. h3xxx_init_gpio(h3600_default_gpio, ARRAY_SIZE(h3600_default_gpio));
  421. h3xxx_mach_init();
  422. sa11x0_register_irda(&h3600_irda_data);
  423. }
  424. MACHINE_START(H3600, "Compaq iPAQ H3600")
  425. .phys_io = 0x80000000,
  426. .io_pg_offst = ((0xf8000000) >> 18) & 0xfffc,
  427. .boot_params = 0xc0000100,
  428. .map_io = h3600_map_io,
  429. .init_irq = sa1100_init_irq,
  430. .timer = &sa1100_timer,
  431. .init_machine = h3600_mach_init,
  432. MACHINE_END
  433. #endif /* CONFIG_SA1100_H3600 */