serial.c 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. /*
  2. * arch/arm/mach-omap2/serial.c
  3. *
  4. * OMAP2 serial support.
  5. *
  6. * Copyright (C) 2005 Nokia Corporation
  7. * Author: Paul Mundt <paul.mundt@nokia.com>
  8. *
  9. * Based off of arch/arm/mach-omap/omap1/serial.c
  10. *
  11. * This file is subject to the terms and conditions of the GNU General Public
  12. * License. See the file "COPYING" in the main directory of this archive
  13. * for more details.
  14. */
  15. #include <linux/kernel.h>
  16. #include <linux/init.h>
  17. #include <linux/serial_8250.h>
  18. #include <linux/serial_reg.h>
  19. #include <linux/clk.h>
  20. #include <asm/io.h>
  21. #include <asm/arch/common.h>
  22. #include <asm/arch/board.h>
  23. static struct clk * uart1_ick = NULL;
  24. static struct clk * uart1_fck = NULL;
  25. static struct clk * uart2_ick = NULL;
  26. static struct clk * uart2_fck = NULL;
  27. static struct clk * uart3_ick = NULL;
  28. static struct clk * uart3_fck = NULL;
  29. static struct plat_serial8250_port serial_platform_data[] = {
  30. {
  31. .membase = (char *)IO_ADDRESS(OMAP_UART1_BASE),
  32. .mapbase = (unsigned long)OMAP_UART1_BASE,
  33. .irq = 72,
  34. .flags = UPF_BOOT_AUTOCONF,
  35. .iotype = UPIO_MEM,
  36. .regshift = 2,
  37. .uartclk = OMAP16XX_BASE_BAUD * 16,
  38. }, {
  39. .membase = (char *)IO_ADDRESS(OMAP_UART2_BASE),
  40. .mapbase = (unsigned long)OMAP_UART2_BASE,
  41. .irq = 73,
  42. .flags = UPF_BOOT_AUTOCONF,
  43. .iotype = UPIO_MEM,
  44. .regshift = 2,
  45. .uartclk = OMAP16XX_BASE_BAUD * 16,
  46. }, {
  47. .membase = (char *)IO_ADDRESS(OMAP_UART3_BASE),
  48. .mapbase = (unsigned long)OMAP_UART3_BASE,
  49. .irq = 74,
  50. .flags = UPF_BOOT_AUTOCONF,
  51. .iotype = UPIO_MEM,
  52. .regshift = 2,
  53. .uartclk = OMAP16XX_BASE_BAUD * 16,
  54. }, {
  55. .flags = 0
  56. }
  57. };
  58. static inline unsigned int serial_read_reg(struct plat_serial8250_port *up,
  59. int offset)
  60. {
  61. offset <<= up->regshift;
  62. return (unsigned int)__raw_readb(up->membase + offset);
  63. }
  64. static inline void serial_write_reg(struct plat_serial8250_port *p, int offset,
  65. int value)
  66. {
  67. offset <<= p->regshift;
  68. __raw_writeb(value, (unsigned long)(p->membase + offset));
  69. }
  70. /*
  71. * Internal UARTs need to be initialized for the 8250 autoconfig to work
  72. * properly. Note that the TX watermark initialization may not be needed
  73. * once the 8250.c watermark handling code is merged.
  74. */
  75. static inline void __init omap_serial_reset(struct plat_serial8250_port *p)
  76. {
  77. serial_write_reg(p, UART_OMAP_MDR1, 0x07);
  78. serial_write_reg(p, UART_OMAP_SCR, 0x08);
  79. serial_write_reg(p, UART_OMAP_MDR1, 0x00);
  80. serial_write_reg(p, UART_OMAP_SYSC, 0x01);
  81. }
  82. void __init omap_serial_init()
  83. {
  84. int i;
  85. const struct omap_uart_config *info;
  86. /*
  87. * Make sure the serial ports are muxed on at this point.
  88. * You have to mux them off in device drivers later on
  89. * if not needed.
  90. */
  91. info = omap_get_config(OMAP_TAG_UART,
  92. struct omap_uart_config);
  93. if (info == NULL)
  94. return;
  95. for (i = 0; i < OMAP_MAX_NR_PORTS; i++) {
  96. struct plat_serial8250_port *p = serial_platform_data + i;
  97. if (!(info->enabled_uarts & (1 << i))) {
  98. p->membase = 0;
  99. p->mapbase = 0;
  100. continue;
  101. }
  102. switch (i) {
  103. case 0:
  104. uart1_ick = clk_get(NULL, "uart1_ick");
  105. if (IS_ERR(uart1_ick))
  106. printk("Could not get uart1_ick\n");
  107. else {
  108. clk_enable(uart1_ick);
  109. }
  110. uart1_fck = clk_get(NULL, "uart1_fck");
  111. if (IS_ERR(uart1_fck))
  112. printk("Could not get uart1_fck\n");
  113. else {
  114. clk_enable(uart1_fck);
  115. }
  116. break;
  117. case 1:
  118. uart2_ick = clk_get(NULL, "uart2_ick");
  119. if (IS_ERR(uart2_ick))
  120. printk("Could not get uart2_ick\n");
  121. else {
  122. clk_enable(uart2_ick);
  123. }
  124. uart2_fck = clk_get(NULL, "uart2_fck");
  125. if (IS_ERR(uart2_fck))
  126. printk("Could not get uart2_fck\n");
  127. else {
  128. clk_enable(uart2_fck);
  129. }
  130. break;
  131. case 2:
  132. uart3_ick = clk_get(NULL, "uart3_ick");
  133. if (IS_ERR(uart3_ick))
  134. printk("Could not get uart3_ick\n");
  135. else {
  136. clk_enable(uart3_ick);
  137. }
  138. uart3_fck = clk_get(NULL, "uart3_fck");
  139. if (IS_ERR(uart3_fck))
  140. printk("Could not get uart3_fck\n");
  141. else {
  142. clk_enable(uart3_fck);
  143. }
  144. break;
  145. }
  146. omap_serial_reset(p);
  147. }
  148. }
  149. static struct platform_device serial_device = {
  150. .name = "serial8250",
  151. .id = PLAT8250_DEV_PLATFORM,
  152. .dev = {
  153. .platform_data = serial_platform_data,
  154. },
  155. };
  156. static int __init omap_init(void)
  157. {
  158. return platform_device_register(&serial_device);
  159. }
  160. arch_initcall(omap_init);