serial.c 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294
  1. /*
  2. * linux/arch/arm/mach-omap1/serial.c
  3. *
  4. * OMAP1 serial support.
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License version 2 as
  8. * published by the Free Software Foundation.
  9. */
  10. #include <linux/module.h>
  11. #include <linux/kernel.h>
  12. #include <linux/init.h>
  13. #include <linux/irq.h>
  14. #include <linux/delay.h>
  15. #include <linux/serial.h>
  16. #include <linux/tty.h>
  17. #include <linux/serial_8250.h>
  18. #include <linux/serial_reg.h>
  19. #include <linux/clk.h>
  20. #include <linux/io.h>
  21. #include <asm/mach-types.h>
  22. #include <mach/board.h>
  23. #include <mach/mux.h>
  24. #include <mach/gpio.h>
  25. #include <mach/fpga.h>
  26. #ifdef CONFIG_PM
  27. #include <mach/pm.h>
  28. #endif
  29. static struct clk * uart1_ck;
  30. static struct clk * uart2_ck;
  31. static struct clk * uart3_ck;
  32. static inline unsigned int omap_serial_in(struct plat_serial8250_port *up,
  33. int offset)
  34. {
  35. offset <<= up->regshift;
  36. return (unsigned int)__raw_readb(up->membase + offset);
  37. }
  38. static inline void omap_serial_outp(struct plat_serial8250_port *p, int offset,
  39. int value)
  40. {
  41. offset <<= p->regshift;
  42. __raw_writeb(value, p->membase + offset);
  43. }
  44. /*
  45. * Internal UARTs need to be initialized for the 8250 autoconfig to work
  46. * properly. Note that the TX watermark initialization may not be needed
  47. * once the 8250.c watermark handling code is merged.
  48. */
  49. static void __init omap_serial_reset(struct plat_serial8250_port *p)
  50. {
  51. omap_serial_outp(p, UART_OMAP_MDR1, 0x07); /* disable UART */
  52. omap_serial_outp(p, UART_OMAP_SCR, 0x08); /* TX watermark */
  53. omap_serial_outp(p, UART_OMAP_MDR1, 0x00); /* enable UART */
  54. if (!cpu_is_omap15xx()) {
  55. omap_serial_outp(p, UART_OMAP_SYSC, 0x01);
  56. while (!(omap_serial_in(p, UART_OMAP_SYSC) & 0x01));
  57. }
  58. }
  59. static struct plat_serial8250_port serial_platform_data[] = {
  60. {
  61. .membase = IO_ADDRESS(OMAP_UART1_BASE),
  62. .mapbase = OMAP_UART1_BASE,
  63. .irq = INT_UART1,
  64. .flags = UPF_BOOT_AUTOCONF,
  65. .iotype = UPIO_MEM,
  66. .regshift = 2,
  67. .uartclk = OMAP16XX_BASE_BAUD * 16,
  68. },
  69. {
  70. .membase = IO_ADDRESS(OMAP_UART2_BASE),
  71. .mapbase = OMAP_UART2_BASE,
  72. .irq = INT_UART2,
  73. .flags = UPF_BOOT_AUTOCONF,
  74. .iotype = UPIO_MEM,
  75. .regshift = 2,
  76. .uartclk = OMAP16XX_BASE_BAUD * 16,
  77. },
  78. {
  79. .membase = IO_ADDRESS(OMAP_UART3_BASE),
  80. .mapbase = OMAP_UART3_BASE,
  81. .irq = INT_UART3,
  82. .flags = UPF_BOOT_AUTOCONF,
  83. .iotype = UPIO_MEM,
  84. .regshift = 2,
  85. .uartclk = OMAP16XX_BASE_BAUD * 16,
  86. },
  87. { },
  88. };
  89. static struct platform_device serial_device = {
  90. .name = "serial8250",
  91. .id = PLAT8250_DEV_PLATFORM,
  92. .dev = {
  93. .platform_data = serial_platform_data,
  94. },
  95. };
  96. /*
  97. * Note that on Innovator-1510 UART2 pins conflict with USB2.
  98. * By default UART2 does not work on Innovator-1510 if you have
  99. * USB OHCI enabled. To use UART2, you must disable USB2 first.
  100. */
  101. void __init omap_serial_init(void)
  102. {
  103. int i;
  104. const struct omap_uart_config *info;
  105. if (cpu_is_omap730()) {
  106. serial_platform_data[0].regshift = 0;
  107. serial_platform_data[1].regshift = 0;
  108. serial_platform_data[0].irq = INT_730_UART_MODEM_1;
  109. serial_platform_data[1].irq = INT_730_UART_MODEM_IRDA_2;
  110. }
  111. if (cpu_is_omap850()) {
  112. serial_platform_data[0].regshift = 0;
  113. serial_platform_data[1].regshift = 0;
  114. serial_platform_data[0].irq = INT_850_UART_MODEM_1;
  115. serial_platform_data[1].irq = INT_850_UART_MODEM_IRDA_2;
  116. }
  117. if (cpu_is_omap15xx()) {
  118. serial_platform_data[0].uartclk = OMAP1510_BASE_BAUD * 16;
  119. serial_platform_data[1].uartclk = OMAP1510_BASE_BAUD * 16;
  120. serial_platform_data[2].uartclk = OMAP1510_BASE_BAUD * 16;
  121. }
  122. info = omap_get_config(OMAP_TAG_UART, struct omap_uart_config);
  123. if (info == NULL)
  124. return;
  125. for (i = 0; i < OMAP_MAX_NR_PORTS; i++) {
  126. unsigned char reg;
  127. if (!((1 << i) & info->enabled_uarts)) {
  128. serial_platform_data[i].membase = NULL;
  129. serial_platform_data[i].mapbase = 0;
  130. continue;
  131. }
  132. switch (i) {
  133. case 0:
  134. uart1_ck = clk_get(NULL, "uart1_ck");
  135. if (IS_ERR(uart1_ck))
  136. printk("Could not get uart1_ck\n");
  137. else {
  138. clk_enable(uart1_ck);
  139. if (cpu_is_omap15xx())
  140. clk_set_rate(uart1_ck, 12000000);
  141. }
  142. if (cpu_is_omap15xx()) {
  143. omap_cfg_reg(UART1_TX);
  144. omap_cfg_reg(UART1_RTS);
  145. if (machine_is_omap_innovator()) {
  146. reg = fpga_read(OMAP1510_FPGA_POWER);
  147. reg |= OMAP1510_FPGA_PCR_COM1_EN;
  148. fpga_write(reg, OMAP1510_FPGA_POWER);
  149. udelay(10);
  150. }
  151. }
  152. break;
  153. case 1:
  154. uart2_ck = clk_get(NULL, "uart2_ck");
  155. if (IS_ERR(uart2_ck))
  156. printk("Could not get uart2_ck\n");
  157. else {
  158. clk_enable(uart2_ck);
  159. if (cpu_is_omap15xx())
  160. clk_set_rate(uart2_ck, 12000000);
  161. else
  162. clk_set_rate(uart2_ck, 48000000);
  163. }
  164. if (cpu_is_omap15xx()) {
  165. omap_cfg_reg(UART2_TX);
  166. omap_cfg_reg(UART2_RTS);
  167. if (machine_is_omap_innovator()) {
  168. reg = fpga_read(OMAP1510_FPGA_POWER);
  169. reg |= OMAP1510_FPGA_PCR_COM2_EN;
  170. fpga_write(reg, OMAP1510_FPGA_POWER);
  171. udelay(10);
  172. }
  173. }
  174. break;
  175. case 2:
  176. uart3_ck = clk_get(NULL, "uart3_ck");
  177. if (IS_ERR(uart3_ck))
  178. printk("Could not get uart3_ck\n");
  179. else {
  180. clk_enable(uart3_ck);
  181. if (cpu_is_omap15xx())
  182. clk_set_rate(uart3_ck, 12000000);
  183. }
  184. if (cpu_is_omap15xx()) {
  185. omap_cfg_reg(UART3_TX);
  186. omap_cfg_reg(UART3_RX);
  187. }
  188. break;
  189. }
  190. omap_serial_reset(&serial_platform_data[i]);
  191. }
  192. }
  193. #ifdef CONFIG_OMAP_SERIAL_WAKE
  194. static irqreturn_t omap_serial_wake_interrupt(int irq, void *dev_id)
  195. {
  196. /* Need to do something with serial port right after wake-up? */
  197. return IRQ_HANDLED;
  198. }
  199. /*
  200. * Reroutes serial RX lines to GPIO lines for the duration of
  201. * sleep to allow waking up the device from serial port even
  202. * in deep sleep.
  203. */
  204. void omap_serial_wake_trigger(int enable)
  205. {
  206. if (!cpu_is_omap16xx())
  207. return;
  208. if (uart1_ck != NULL) {
  209. if (enable)
  210. omap_cfg_reg(V14_16XX_GPIO37);
  211. else
  212. omap_cfg_reg(V14_16XX_UART1_RX);
  213. }
  214. if (uart2_ck != NULL) {
  215. if (enable)
  216. omap_cfg_reg(R9_16XX_GPIO18);
  217. else
  218. omap_cfg_reg(R9_16XX_UART2_RX);
  219. }
  220. if (uart3_ck != NULL) {
  221. if (enable)
  222. omap_cfg_reg(L14_16XX_GPIO49);
  223. else
  224. omap_cfg_reg(L14_16XX_UART3_RX);
  225. }
  226. }
  227. static void __init omap_serial_set_port_wakeup(int gpio_nr)
  228. {
  229. int ret;
  230. ret = gpio_request(gpio_nr, "UART wake");
  231. if (ret < 0) {
  232. printk(KERN_ERR "Could not request UART wake GPIO: %i\n",
  233. gpio_nr);
  234. return;
  235. }
  236. gpio_direction_input(gpio_nr);
  237. ret = request_irq(gpio_to_irq(gpio_nr), &omap_serial_wake_interrupt,
  238. IRQF_TRIGGER_RISING, "serial wakeup", NULL);
  239. if (ret) {
  240. gpio_free(gpio_nr);
  241. printk(KERN_ERR "No interrupt for UART wake GPIO: %i\n",
  242. gpio_nr);
  243. return;
  244. }
  245. enable_irq_wake(gpio_to_irq(gpio_nr));
  246. }
  247. static int __init omap_serial_wakeup_init(void)
  248. {
  249. if (!cpu_is_omap16xx())
  250. return 0;
  251. if (uart1_ck != NULL)
  252. omap_serial_set_port_wakeup(37);
  253. if (uart2_ck != NULL)
  254. omap_serial_set_port_wakeup(18);
  255. if (uart3_ck != NULL)
  256. omap_serial_set_port_wakeup(49);
  257. return 0;
  258. }
  259. late_initcall(omap_serial_wakeup_init);
  260. #endif /* CONFIG_OMAP_SERIAL_WAKE */
  261. static int __init omap_init(void)
  262. {
  263. return platform_device_register(&serial_device);
  264. }
  265. arch_initcall(omap_init);