serial.c 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. /*
  2. * linux/arch/arm/mach-omap1/id.c
  3. *
  4. * OMAP1 CPU identification code
  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/config.h>
  11. #include <linux/module.h>
  12. #include <linux/kernel.h>
  13. #include <linux/init.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 <asm/io.h>
  20. #include <asm/mach-types.h>
  21. #include <asm/hardware/clock.h>
  22. #include <asm/arch/board.h>
  23. #include <asm/arch/mux.h>
  24. #include <asm/arch/fpga.h>
  25. static struct clk * uart1_ck = NULL;
  26. static struct clk * uart2_ck = NULL;
  27. static struct clk * uart3_ck = NULL;
  28. static inline unsigned int omap_serial_in(struct plat_serial8250_port *up,
  29. int offset)
  30. {
  31. offset <<= up->regshift;
  32. return (unsigned int)__raw_readb(up->membase + offset);
  33. }
  34. static inline void omap_serial_outp(struct plat_serial8250_port *p, int offset,
  35. int value)
  36. {
  37. offset <<= p->regshift;
  38. __raw_writeb(value, p->membase + offset);
  39. }
  40. /*
  41. * Internal UARTs need to be initialized for the 8250 autoconfig to work
  42. * properly. Note that the TX watermark initialization may not be needed
  43. * once the 8250.c watermark handling code is merged.
  44. */
  45. static void __init omap_serial_reset(struct plat_serial8250_port *p)
  46. {
  47. omap_serial_outp(p, UART_OMAP_MDR1, 0x07); /* disable UART */
  48. omap_serial_outp(p, UART_OMAP_SCR, 0x08); /* TX watermark */
  49. omap_serial_outp(p, UART_OMAP_MDR1, 0x00); /* enable UART */
  50. if (!cpu_is_omap1510()) {
  51. omap_serial_outp(p, UART_OMAP_SYSC, 0x01);
  52. while (!(omap_serial_in(p, UART_OMAP_SYSC) & 0x01));
  53. }
  54. }
  55. static struct plat_serial8250_port serial_platform_data[] = {
  56. {
  57. .membase = (char*)IO_ADDRESS(OMAP_UART1_BASE),
  58. .mapbase = (unsigned long)OMAP_UART1_BASE,
  59. .irq = INT_UART1,
  60. .flags = UPF_BOOT_AUTOCONF,
  61. .iotype = UPIO_MEM,
  62. .regshift = 2,
  63. .uartclk = OMAP16XX_BASE_BAUD * 16,
  64. },
  65. {
  66. .membase = (char*)IO_ADDRESS(OMAP_UART2_BASE),
  67. .mapbase = (unsigned long)OMAP_UART2_BASE,
  68. .irq = INT_UART2,
  69. .flags = UPF_BOOT_AUTOCONF,
  70. .iotype = UPIO_MEM,
  71. .regshift = 2,
  72. .uartclk = OMAP16XX_BASE_BAUD * 16,
  73. },
  74. {
  75. .membase = (char*)IO_ADDRESS(OMAP_UART3_BASE),
  76. .mapbase = (unsigned long)OMAP_UART3_BASE,
  77. .irq = INT_UART3,
  78. .flags = UPF_BOOT_AUTOCONF,
  79. .iotype = UPIO_MEM,
  80. .regshift = 2,
  81. .uartclk = OMAP16XX_BASE_BAUD * 16,
  82. },
  83. { },
  84. };
  85. static struct platform_device serial_device = {
  86. .name = "serial8250",
  87. .id = 0,
  88. .dev = {
  89. .platform_data = serial_platform_data,
  90. },
  91. };
  92. /*
  93. * Note that on Innovator-1510 UART2 pins conflict with USB2.
  94. * By default UART2 does not work on Innovator-1510 if you have
  95. * USB OHCI enabled. To use UART2, you must disable USB2 first.
  96. */
  97. void __init omap_serial_init(int ports[OMAP_MAX_NR_PORTS])
  98. {
  99. int i;
  100. if (cpu_is_omap730()) {
  101. serial_platform_data[0].regshift = 0;
  102. serial_platform_data[1].regshift = 0;
  103. serial_platform_data[0].irq = INT_730_UART_MODEM_1;
  104. serial_platform_data[1].irq = INT_730_UART_MODEM_IRDA_2;
  105. }
  106. if (cpu_is_omap1510()) {
  107. serial_platform_data[0].uartclk = OMAP1510_BASE_BAUD * 16;
  108. serial_platform_data[1].uartclk = OMAP1510_BASE_BAUD * 16;
  109. serial_platform_data[2].uartclk = OMAP1510_BASE_BAUD * 16;
  110. }
  111. for (i = 0; i < OMAP_MAX_NR_PORTS; i++) {
  112. unsigned char reg;
  113. if (ports[i] == 0) {
  114. serial_platform_data[i].membase = NULL;
  115. serial_platform_data[i].mapbase = 0;
  116. continue;
  117. }
  118. switch (i) {
  119. case 0:
  120. uart1_ck = clk_get(NULL, "uart1_ck");
  121. if (IS_ERR(uart1_ck))
  122. printk("Could not get uart1_ck\n");
  123. else {
  124. clk_use(uart1_ck);
  125. if (cpu_is_omap1510())
  126. clk_set_rate(uart1_ck, 12000000);
  127. }
  128. if (cpu_is_omap1510()) {
  129. omap_cfg_reg(UART1_TX);
  130. omap_cfg_reg(UART1_RTS);
  131. if (machine_is_omap_innovator()) {
  132. reg = fpga_read(OMAP1510_FPGA_POWER);
  133. reg |= OMAP1510_FPGA_PCR_COM1_EN;
  134. fpga_write(reg, OMAP1510_FPGA_POWER);
  135. udelay(10);
  136. }
  137. }
  138. break;
  139. case 1:
  140. uart2_ck = clk_get(NULL, "uart2_ck");
  141. if (IS_ERR(uart2_ck))
  142. printk("Could not get uart2_ck\n");
  143. else {
  144. clk_use(uart2_ck);
  145. if (cpu_is_omap1510())
  146. clk_set_rate(uart2_ck, 12000000);
  147. else
  148. clk_set_rate(uart2_ck, 48000000);
  149. }
  150. if (cpu_is_omap1510()) {
  151. omap_cfg_reg(UART2_TX);
  152. omap_cfg_reg(UART2_RTS);
  153. if (machine_is_omap_innovator()) {
  154. reg = fpga_read(OMAP1510_FPGA_POWER);
  155. reg |= OMAP1510_FPGA_PCR_COM2_EN;
  156. fpga_write(reg, OMAP1510_FPGA_POWER);
  157. udelay(10);
  158. }
  159. }
  160. break;
  161. case 2:
  162. uart3_ck = clk_get(NULL, "uart3_ck");
  163. if (IS_ERR(uart3_ck))
  164. printk("Could not get uart3_ck\n");
  165. else {
  166. clk_use(uart3_ck);
  167. if (cpu_is_omap1510())
  168. clk_set_rate(uart3_ck, 12000000);
  169. }
  170. if (cpu_is_omap1510()) {
  171. omap_cfg_reg(UART3_TX);
  172. omap_cfg_reg(UART3_RX);
  173. }
  174. break;
  175. }
  176. omap_serial_reset(&serial_platform_data[i]);
  177. }
  178. }
  179. static int __init omap_init(void)
  180. {
  181. return platform_device_register(&serial_device);
  182. }
  183. arch_initcall(omap_init);