serial.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. /*
  2. * TI DaVinci serial driver
  3. *
  4. * Copyright (C) 2006 Texas Instruments.
  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 as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  19. *
  20. */
  21. #include <linux/kernel.h>
  22. #include <linux/init.h>
  23. #include <linux/serial_8250.h>
  24. #include <linux/serial_reg.h>
  25. #include <linux/platform_device.h>
  26. #include <linux/delay.h>
  27. #include <linux/clk.h>
  28. #include <linux/io.h>
  29. #include <asm/irq.h>
  30. #include <mach/hardware.h>
  31. #include <mach/serial.h>
  32. #include <mach/irqs.h>
  33. #include <mach/cputype.h>
  34. #include "clock.h"
  35. static inline unsigned int serial_read_reg(struct plat_serial8250_port *up,
  36. int offset)
  37. {
  38. offset <<= up->regshift;
  39. return (unsigned int)__raw_readl(IO_ADDRESS(up->mapbase) + offset);
  40. }
  41. static inline void serial_write_reg(struct plat_serial8250_port *p, int offset,
  42. int value)
  43. {
  44. offset <<= p->regshift;
  45. __raw_writel(value, IO_ADDRESS(p->mapbase) + offset);
  46. }
  47. static struct plat_serial8250_port serial_platform_data[] = {
  48. {
  49. .mapbase = DAVINCI_UART0_BASE,
  50. .irq = IRQ_UARTINT0,
  51. .flags = UPF_BOOT_AUTOCONF | UPF_SKIP_TEST |
  52. UPF_IOREMAP,
  53. .iotype = UPIO_MEM,
  54. .regshift = 2,
  55. },
  56. {
  57. .mapbase = DAVINCI_UART1_BASE,
  58. .irq = IRQ_UARTINT1,
  59. .flags = UPF_BOOT_AUTOCONF | UPF_SKIP_TEST |
  60. UPF_IOREMAP,
  61. .iotype = UPIO_MEM,
  62. .regshift = 2,
  63. },
  64. {
  65. .mapbase = DAVINCI_UART2_BASE,
  66. .irq = IRQ_UARTINT2,
  67. .flags = UPF_BOOT_AUTOCONF | UPF_SKIP_TEST |
  68. UPF_IOREMAP,
  69. .iotype = UPIO_MEM,
  70. .regshift = 2,
  71. },
  72. {
  73. .flags = 0
  74. },
  75. };
  76. static struct platform_device serial_device = {
  77. .name = "serial8250",
  78. .id = PLAT8250_DEV_PLATFORM,
  79. .dev = {
  80. .platform_data = serial_platform_data,
  81. },
  82. };
  83. static void __init davinci_serial_reset(struct plat_serial8250_port *p)
  84. {
  85. unsigned int pwremu = 0;
  86. serial_write_reg(p, UART_IER, 0); /* disable all interrupts */
  87. /* reset both transmitter and receiver: bits 14,13 = UTRST, URRST */
  88. serial_write_reg(p, UART_DAVINCI_PWREMU, pwremu);
  89. mdelay(10);
  90. pwremu |= (0x3 << 13);
  91. pwremu |= 0x1;
  92. serial_write_reg(p, UART_DAVINCI_PWREMU, pwremu);
  93. if (cpu_is_davinci_dm646x())
  94. serial_write_reg(p, UART_DM646X_SCR,
  95. UART_DM646X_SCR_TX_WATERMARK);
  96. }
  97. void __init davinci_serial_init(struct davinci_uart_config *info)
  98. {
  99. int i;
  100. char name[16];
  101. struct clk *uart_clk;
  102. struct device *dev = &serial_device.dev;
  103. /*
  104. * Make sure the serial ports are muxed on at this point.
  105. * You have to mux them off in device drivers later on
  106. * if not needed.
  107. */
  108. for (i = 0; i < DAVINCI_MAX_NR_UARTS; i++) {
  109. struct plat_serial8250_port *p = serial_platform_data + i;
  110. if (!(info->enabled_uarts & (1 << i))) {
  111. p->flags = 0;
  112. continue;
  113. }
  114. if (cpu_is_davinci_dm646x())
  115. p->iotype = UPIO_MEM32;
  116. if (cpu_is_davinci_dm355()) {
  117. if (i == 2) {
  118. p->mapbase = (unsigned long)DM355_UART2_BASE;
  119. p->irq = IRQ_DM355_UARTINT2;
  120. }
  121. }
  122. sprintf(name, "uart%d", i);
  123. uart_clk = clk_get(dev, name);
  124. if (IS_ERR(uart_clk))
  125. printk(KERN_ERR "%s:%d: failed to get UART%d clock\n",
  126. __func__, __LINE__, i);
  127. else {
  128. clk_enable(uart_clk);
  129. p->uartclk = clk_get_rate(uart_clk);
  130. davinci_serial_reset(p);
  131. }
  132. }
  133. }
  134. static int __init davinci_init(void)
  135. {
  136. return platform_device_register(&serial_device);
  137. }
  138. arch_initcall(davinci_init);