h3600.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487
  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/h3xxx.h>
  45. #include "generic.h"
  46. struct gpio_default_state {
  47. int gpio;
  48. int mode;
  49. const char *name;
  50. };
  51. #define GPIO_MODE_IN -1
  52. #define GPIO_MODE_OUT0 0
  53. #define GPIO_MODE_OUT1 1
  54. static void h3xxx_init_gpio(struct gpio_default_state *s, size_t n)
  55. {
  56. while (n--) {
  57. const char *name = s->name;
  58. int err;
  59. if (!name)
  60. name = "[init]";
  61. err = gpio_request(s->gpio, name);
  62. if (err) {
  63. printk(KERN_ERR "gpio%u: unable to request: %d\n",
  64. s->gpio, err);
  65. continue;
  66. }
  67. if (s->mode >= 0) {
  68. err = gpio_direction_output(s->gpio, s->mode);
  69. } else {
  70. err = gpio_direction_input(s->gpio);
  71. }
  72. if (err) {
  73. printk(KERN_ERR "gpio%u: unable to set direction: %d\n",
  74. s->gpio, err);
  75. continue;
  76. }
  77. if (!s->name)
  78. gpio_free(s->gpio);
  79. s++;
  80. }
  81. }
  82. /*
  83. * H3xxx flash support
  84. */
  85. static struct mtd_partition h3xxx_partitions[] = {
  86. {
  87. .name = "H3XXX boot firmware",
  88. .size = 0x00040000,
  89. .offset = 0,
  90. .mask_flags = MTD_WRITEABLE, /* force read-only */
  91. }, {
  92. .name = "H3XXX rootfs",
  93. .size = MTDPART_SIZ_FULL,
  94. .offset = 0x00040000,
  95. }
  96. };
  97. static void h3xxx_set_vpp(int vpp)
  98. {
  99. gpio_set_value(H3XXX_EGPIO_VPP_ON, vpp);
  100. }
  101. static int h3xxx_flash_init(void)
  102. {
  103. int err = gpio_request(H3XXX_EGPIO_VPP_ON, "Flash Vpp");
  104. if (err)
  105. return err;
  106. err = gpio_direction_output(H3XXX_EGPIO_VPP_ON, 0);
  107. if (err)
  108. gpio_free(H3XXX_EGPIO_VPP_ON);
  109. return err;
  110. }
  111. static void h3xxx_flash_exit(void)
  112. {
  113. gpio_free(H3XXX_EGPIO_VPP_ON);
  114. }
  115. static struct flash_platform_data h3xxx_flash_data = {
  116. .map_name = "cfi_probe",
  117. .set_vpp = h3xxx_set_vpp,
  118. .init = h3xxx_flash_init,
  119. .exit = h3xxx_flash_exit,
  120. .parts = h3xxx_partitions,
  121. .nr_parts = ARRAY_SIZE(h3xxx_partitions),
  122. };
  123. static struct resource h3xxx_flash_resource = {
  124. .start = SA1100_CS0_PHYS,
  125. .end = SA1100_CS0_PHYS + SZ_32M - 1,
  126. .flags = IORESOURCE_MEM,
  127. };
  128. /*
  129. * H3xxx uart support
  130. */
  131. static void h3xxx_uart_set_mctrl(struct uart_port *port, u_int mctrl)
  132. {
  133. if (port->mapbase == _Ser3UTCR0) {
  134. gpio_set_value(H3XXX_GPIO_COM_RTS, !(mctrl & TIOCM_RTS));
  135. }
  136. }
  137. static u_int h3xxx_uart_get_mctrl(struct uart_port *port)
  138. {
  139. u_int ret = TIOCM_CD | TIOCM_CTS | TIOCM_DSR;
  140. if (port->mapbase == _Ser3UTCR0) {
  141. /*
  142. * DCD and CTS bits are inverted in GPLR by RS232 transceiver
  143. */
  144. if (gpio_get_value(H3XXX_GPIO_COM_DCD))
  145. ret &= ~TIOCM_CD;
  146. if (gpio_get_value(H3XXX_GPIO_COM_CTS))
  147. ret &= ~TIOCM_CTS;
  148. }
  149. return ret;
  150. }
  151. static void h3xxx_uart_pm(struct uart_port *port, u_int state, u_int oldstate)
  152. {
  153. if (port->mapbase == _Ser3UTCR0)
  154. if (!gpio_request(H3XXX_EGPIO_RS232_ON, "RS232 transceiver")) {
  155. gpio_direction_output(H3XXX_EGPIO_RS232_ON, !state);
  156. gpio_free(H3XXX_EGPIO_RS232_ON);
  157. }
  158. }
  159. /*
  160. * Enable/Disable wake up events for this serial port.
  161. * Obviously, we only support this on the normal COM port.
  162. */
  163. static int h3xxx_uart_set_wake(struct uart_port *port, u_int enable)
  164. {
  165. int err = -EINVAL;
  166. if (port->mapbase == _Ser3UTCR0) {
  167. if (enable)
  168. PWER |= PWER_GPIO23 | PWER_GPIO25; /* DCD and CTS */
  169. else
  170. PWER &= ~(PWER_GPIO23 | PWER_GPIO25); /* DCD and CTS */
  171. err = 0;
  172. }
  173. return err;
  174. }
  175. static struct sa1100_port_fns h3xxx_port_fns __initdata = {
  176. .set_mctrl = h3xxx_uart_set_mctrl,
  177. .get_mctrl = h3xxx_uart_get_mctrl,
  178. .pm = h3xxx_uart_pm,
  179. .set_wake = h3xxx_uart_set_wake,
  180. };
  181. /*
  182. * EGPIO
  183. */
  184. static struct resource egpio_resources[] = {
  185. [0] = {
  186. .start = H3600_EGPIO_PHYS,
  187. .end = H3600_EGPIO_PHYS + 0x4 - 1,
  188. .flags = IORESOURCE_MEM,
  189. },
  190. };
  191. static struct htc_egpio_chip egpio_chips[] = {
  192. [0] = {
  193. .reg_start = 0,
  194. .gpio_base = H3XXX_EGPIO_BASE,
  195. .num_gpios = 16,
  196. .direction = HTC_EGPIO_OUTPUT,
  197. .initial_values = 0x0080, /* H3XXX_EGPIO_RS232_ON */
  198. },
  199. };
  200. static struct htc_egpio_platform_data egpio_info = {
  201. .reg_width = 16,
  202. .bus_width = 16,
  203. .chip = egpio_chips,
  204. .num_chips = ARRAY_SIZE(egpio_chips),
  205. };
  206. static struct platform_device h3xxx_egpio = {
  207. .name = "htc-egpio",
  208. .id = -1,
  209. .resource = egpio_resources,
  210. .num_resources = ARRAY_SIZE(egpio_resources),
  211. .dev = {
  212. .platform_data = &egpio_info,
  213. },
  214. };
  215. static struct platform_device *h3xxx_devices[] = {
  216. &h3xxx_egpio,
  217. };
  218. static void __init h3xxx_mach_init(void)
  219. {
  220. sa1100_register_uart_fns(&h3xxx_port_fns);
  221. sa11x0_register_mtd(&h3xxx_flash_data, &h3xxx_flash_resource, 1);
  222. platform_add_devices(h3xxx_devices, ARRAY_SIZE(h3xxx_devices));
  223. }
  224. static struct map_desc h3600_io_desc[] __initdata = {
  225. { /* static memory bank 2 CS#2 */
  226. .virtual = H3600_BANK_2_VIRT,
  227. .pfn = __phys_to_pfn(SA1100_CS2_PHYS),
  228. .length = 0x02800000,
  229. .type = MT_DEVICE
  230. }, { /* static memory bank 4 CS#4 */
  231. .virtual = H3600_BANK_4_VIRT,
  232. .pfn = __phys_to_pfn(SA1100_CS4_PHYS),
  233. .length = 0x00800000,
  234. .type = MT_DEVICE
  235. }, { /* EGPIO 0 CS#5 */
  236. .virtual = H3600_EGPIO_VIRT,
  237. .pfn = __phys_to_pfn(H3600_EGPIO_PHYS),
  238. .length = 0x01000000,
  239. .type = MT_DEVICE
  240. }
  241. };
  242. /*
  243. * Common map_io initialization
  244. */
  245. static void __init h3xxx_map_io(void)
  246. {
  247. sa1100_map_io();
  248. iotable_init(h3600_io_desc, ARRAY_SIZE(h3600_io_desc));
  249. sa1100_register_uart(0, 3); /* Common serial port */
  250. // sa1100_register_uart(1, 1); /* Microcontroller on 3100/3600 */
  251. /* Ensure those pins are outputs and driving low */
  252. PPDR |= PPC_TXD4 | PPC_SCLK | PPC_SFRM;
  253. PPSR &= ~(PPC_TXD4 | PPC_SCLK | PPC_SFRM);
  254. /* Configure suspend conditions */
  255. PGSR = 0;
  256. PWER = PWER_GPIO0;
  257. PCFR = PCFR_OPDE;
  258. PSDR = 0;
  259. GPCR = 0x0fffffff; /* All outputs are set low by default */
  260. GPDR = 0; /* Configure all GPIOs as input */
  261. }
  262. /************************* H3100 *************************/
  263. #ifdef CONFIG_SA1100_H3100
  264. /*
  265. * helper for sa1100fb
  266. */
  267. static void h3100_lcd_power(int enable)
  268. {
  269. if (!gpio_request(H3XXX_EGPIO_LCD_ON, "LCD ON")) {
  270. gpio_set_value(H3100_GPIO_LCD_3V_ON, enable);
  271. gpio_direction_output(H3XXX_EGPIO_LCD_ON, enable);
  272. gpio_free(H3XXX_EGPIO_LCD_ON);
  273. }
  274. }
  275. static void __init h3100_map_io(void)
  276. {
  277. h3xxx_map_io();
  278. sa1100fb_lcd_power = h3100_lcd_power;
  279. /* Older bootldrs put GPIO2-9 in alternate mode on the
  280. assumption that they are used for video */
  281. GAFR &= ~0x000001fb;
  282. }
  283. /*
  284. * This turns the IRDA power on or off on the Compaq H3100
  285. */
  286. static int h3100_irda_set_power(struct device *dev, unsigned int state)
  287. {
  288. gpio_set_value(H3100_GPIO_IR_ON, state);
  289. return 0;
  290. }
  291. static void h3100_irda_set_speed(struct device *dev, unsigned int speed)
  292. {
  293. gpio_set_value(H3100_GPIO_IR_FSEL, !(speed < 4000000));
  294. }
  295. static struct irda_platform_data h3100_irda_data = {
  296. .set_power = h3100_irda_set_power,
  297. .set_speed = h3100_irda_set_speed,
  298. };
  299. static struct gpio_default_state h3100_default_gpio[] = {
  300. { H3100_GPIO_IR_ON, GPIO_MODE_OUT0, "IrDA power" },
  301. { H3100_GPIO_IR_FSEL, GPIO_MODE_OUT0, "IrDA fsel" },
  302. { H3XXX_GPIO_COM_DCD, GPIO_MODE_IN, "COM DCD" },
  303. { H3XXX_GPIO_COM_CTS, GPIO_MODE_IN, "COM CTS" },
  304. { H3XXX_GPIO_COM_RTS, GPIO_MODE_OUT0, "COM RTS" },
  305. { H3100_GPIO_LCD_3V_ON, GPIO_MODE_OUT0, "LCD 3v" },
  306. };
  307. static void __init h3100_mach_init(void)
  308. {
  309. h3xxx_init_gpio(h3100_default_gpio, ARRAY_SIZE(h3100_default_gpio));
  310. h3xxx_mach_init();
  311. sa11x0_register_irda(&h3100_irda_data);
  312. }
  313. MACHINE_START(H3100, "Compaq iPAQ H3100")
  314. .phys_io = 0x80000000,
  315. .io_pg_offst = ((0xf8000000) >> 18) & 0xfffc,
  316. .boot_params = 0xc0000100,
  317. .map_io = h3100_map_io,
  318. .init_irq = sa1100_init_irq,
  319. .timer = &sa1100_timer,
  320. .init_machine = h3100_mach_init,
  321. MACHINE_END
  322. #endif /* CONFIG_SA1100_H3100 */
  323. /************************* H3600 *************************/
  324. #ifdef CONFIG_SA1100_H3600
  325. /*
  326. * helper for sa1100fb
  327. */
  328. static void h3600_lcd_power(int enable)
  329. {
  330. if (gpio_request(H3XXX_EGPIO_LCD_ON, "LCD power"))
  331. goto err1;
  332. if (gpio_request(H3600_EGPIO_LCD_PCI, "LCD control"))
  333. goto err2;
  334. if (gpio_request(H3600_EGPIO_LCD_5V_ON, "LCD 5v"))
  335. goto err3;
  336. if (gpio_request(H3600_EGPIO_LVDD_ON, "LCD 9v/-6.5v"))
  337. goto err4;
  338. gpio_direction_output(H3XXX_EGPIO_LCD_ON, enable);
  339. gpio_direction_output(H3600_EGPIO_LCD_PCI, enable);
  340. gpio_direction_output(H3600_EGPIO_LCD_5V_ON, enable);
  341. gpio_direction_output(H3600_EGPIO_LVDD_ON, enable);
  342. gpio_free(H3600_EGPIO_LVDD_ON);
  343. err4: gpio_free(H3600_EGPIO_LCD_5V_ON);
  344. err3: gpio_free(H3600_EGPIO_LCD_PCI);
  345. err2: gpio_free(H3XXX_EGPIO_LCD_ON);
  346. err1: return;
  347. }
  348. static void __init h3600_map_io(void)
  349. {
  350. h3xxx_map_io();
  351. sa1100fb_lcd_power = h3600_lcd_power;
  352. }
  353. /*
  354. * This turns the IRDA power on or off on the Compaq H3600
  355. */
  356. static int h3600_irda_set_power(struct device *dev, unsigned int state)
  357. {
  358. gpio_set_value(H3600_EGPIO_IR_ON, state);
  359. return 0;
  360. }
  361. static void h3600_irda_set_speed(struct device *dev, unsigned int speed)
  362. {
  363. gpio_set_value(H3600_EGPIO_IR_FSEL, !(speed < 4000000));
  364. }
  365. static int h3600_irda_startup(struct device *dev)
  366. {
  367. int err = gpio_request(H3600_EGPIO_IR_ON, "IrDA power");
  368. if (err)
  369. goto err1;
  370. err = gpio_direction_output(H3600_EGPIO_IR_ON, 0);
  371. if (err)
  372. goto err2;
  373. err = gpio_request(H3600_EGPIO_IR_FSEL, "IrDA fsel");
  374. if (err)
  375. goto err2;
  376. err = gpio_direction_output(H3600_EGPIO_IR_FSEL, 0);
  377. if (err)
  378. goto err3;
  379. return 0;
  380. err3: gpio_free(H3600_EGPIO_IR_FSEL);
  381. err2: gpio_free(H3600_EGPIO_IR_ON);
  382. err1: return err;
  383. }
  384. static void h3600_irda_shutdown(struct device *dev)
  385. {
  386. gpio_free(H3600_EGPIO_IR_ON);
  387. gpio_free(H3600_EGPIO_IR_FSEL);
  388. }
  389. static struct irda_platform_data h3600_irda_data = {
  390. .set_power = h3600_irda_set_power,
  391. .set_speed = h3600_irda_set_speed,
  392. .startup = h3600_irda_startup,
  393. .shutdown = h3600_irda_shutdown,
  394. };
  395. static struct gpio_default_state h3600_default_gpio[] = {
  396. { H3XXX_GPIO_COM_DCD, GPIO_MODE_IN, "COM DCD" },
  397. { H3XXX_GPIO_COM_CTS, GPIO_MODE_IN, "COM CTS" },
  398. { H3XXX_GPIO_COM_RTS, GPIO_MODE_OUT0, "COM RTS" },
  399. };
  400. static void __init h3600_mach_init(void)
  401. {
  402. h3xxx_init_gpio(h3600_default_gpio, ARRAY_SIZE(h3600_default_gpio));
  403. h3xxx_mach_init();
  404. sa11x0_register_irda(&h3600_irda_data);
  405. }
  406. MACHINE_START(H3600, "Compaq iPAQ H3600")
  407. .phys_io = 0x80000000,
  408. .io_pg_offst = ((0xf8000000) >> 18) & 0xfffc,
  409. .boot_params = 0xc0000100,
  410. .map_io = h3600_map_io,
  411. .init_irq = sa1100_init_irq,
  412. .timer = &sa1100_timer,
  413. .init_machine = h3600_mach_init,
  414. MACHINE_END
  415. #endif /* CONFIG_SA1100_H3600 */