s3c2440.c 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. /*
  2. * Driver for Samsung S3C2440 and S3C2442 SoC onboard UARTs.
  3. *
  4. * Ben Dooks, Copyright (c) 2003-2008 Simtec Electronics
  5. * http://armlinux.simtec.co.uk/
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License version 2 as
  9. * published by the Free Software Foundation.
  10. */
  11. #include <linux/module.h>
  12. #include <linux/ioport.h>
  13. #include <linux/io.h>
  14. #include <linux/platform_device.h>
  15. #include <linux/init.h>
  16. #include <linux/serial_core.h>
  17. #include <linux/serial.h>
  18. #include <asm/irq.h>
  19. #include <mach/hardware.h>
  20. #include <plat/regs-serial.h>
  21. #include <mach/regs-gpio.h>
  22. #include "samsung.h"
  23. static int s3c2440_serial_setsource(struct uart_port *port,
  24. struct s3c24xx_uart_clksrc *clk)
  25. {
  26. unsigned long ucon = rd_regl(port, S3C2410_UCON);
  27. /* todo - proper fclk<>nonfclk switch. */
  28. ucon &= ~S3C2440_UCON_CLKMASK;
  29. if (strcmp(clk->name, "uclk") == 0)
  30. ucon |= S3C2440_UCON_UCLK;
  31. else if (strcmp(clk->name, "pclk") == 0)
  32. ucon |= S3C2440_UCON_PCLK;
  33. else if (strcmp(clk->name, "fclk") == 0)
  34. ucon |= S3C2440_UCON_FCLK;
  35. else {
  36. printk(KERN_ERR "unknown clock source %s\n", clk->name);
  37. return -EINVAL;
  38. }
  39. wr_regl(port, S3C2410_UCON, ucon);
  40. return 0;
  41. }
  42. static int s3c2440_serial_getsource(struct uart_port *port,
  43. struct s3c24xx_uart_clksrc *clk)
  44. {
  45. unsigned long ucon = rd_regl(port, S3C2410_UCON);
  46. unsigned long ucon0, ucon1, ucon2;
  47. switch (ucon & S3C2440_UCON_CLKMASK) {
  48. case S3C2440_UCON_UCLK:
  49. clk->divisor = 1;
  50. clk->name = "uclk";
  51. break;
  52. case S3C2440_UCON_PCLK:
  53. case S3C2440_UCON_PCLK2:
  54. clk->divisor = 1;
  55. clk->name = "pclk";
  56. break;
  57. case S3C2440_UCON_FCLK:
  58. /* the fun of calculating the uart divisors on
  59. * the s3c2440 */
  60. ucon0 = __raw_readl(S3C24XX_VA_UART0 + S3C2410_UCON);
  61. ucon1 = __raw_readl(S3C24XX_VA_UART1 + S3C2410_UCON);
  62. ucon2 = __raw_readl(S3C24XX_VA_UART2 + S3C2410_UCON);
  63. printk("ucons: %08lx, %08lx, %08lx\n", ucon0, ucon1, ucon2);
  64. ucon0 &= S3C2440_UCON0_DIVMASK;
  65. ucon1 &= S3C2440_UCON1_DIVMASK;
  66. ucon2 &= S3C2440_UCON2_DIVMASK;
  67. if (ucon0 != 0) {
  68. clk->divisor = ucon0 >> S3C2440_UCON_DIVSHIFT;
  69. clk->divisor += 6;
  70. } else if (ucon1 != 0) {
  71. clk->divisor = ucon1 >> S3C2440_UCON_DIVSHIFT;
  72. clk->divisor += 21;
  73. } else if (ucon2 != 0) {
  74. clk->divisor = ucon2 >> S3C2440_UCON_DIVSHIFT;
  75. clk->divisor += 36;
  76. } else {
  77. /* manual calims 44, seems to be 9 */
  78. clk->divisor = 9;
  79. }
  80. clk->name = "fclk";
  81. break;
  82. }
  83. return 0;
  84. }
  85. static int s3c2440_serial_resetport(struct uart_port *port,
  86. struct s3c2410_uartcfg *cfg)
  87. {
  88. unsigned long ucon = rd_regl(port, S3C2410_UCON);
  89. dbg("s3c2440_serial_resetport: port=%p (%08lx), cfg=%p\n",
  90. port, port->mapbase, cfg);
  91. /* ensure we don't change the clock settings... */
  92. ucon &= (S3C2440_UCON0_DIVMASK | (3<<10));
  93. wr_regl(port, S3C2410_UCON, ucon | cfg->ucon);
  94. wr_regl(port, S3C2410_ULCON, cfg->ulcon);
  95. /* reset both fifos */
  96. wr_regl(port, S3C2410_UFCON, cfg->ufcon | S3C2410_UFCON_RESETBOTH);
  97. wr_regl(port, S3C2410_UFCON, cfg->ufcon);
  98. return 0;
  99. }
  100. static struct s3c24xx_uart_info s3c2440_uart_inf = {
  101. .name = "Samsung S3C2440 UART",
  102. .type = PORT_S3C2440,
  103. .fifosize = 64,
  104. .rx_fifomask = S3C2440_UFSTAT_RXMASK,
  105. .rx_fifoshift = S3C2440_UFSTAT_RXSHIFT,
  106. .rx_fifofull = S3C2440_UFSTAT_RXFULL,
  107. .tx_fifofull = S3C2440_UFSTAT_TXFULL,
  108. .tx_fifomask = S3C2440_UFSTAT_TXMASK,
  109. .tx_fifoshift = S3C2440_UFSTAT_TXSHIFT,
  110. .get_clksrc = s3c2440_serial_getsource,
  111. .set_clksrc = s3c2440_serial_setsource,
  112. .reset_port = s3c2440_serial_resetport,
  113. };
  114. /* device management */
  115. static int s3c2440_serial_probe(struct platform_device *dev)
  116. {
  117. dbg("s3c2440_serial_probe: dev=%p\n", dev);
  118. return s3c24xx_serial_probe(dev, &s3c2440_uart_inf);
  119. }
  120. static struct platform_driver s3c2440_serial_driver = {
  121. .probe = s3c2440_serial_probe,
  122. .remove = __devexit_p(s3c24xx_serial_remove),
  123. .driver = {
  124. .name = "s3c2440-uart",
  125. .owner = THIS_MODULE,
  126. },
  127. };
  128. static int __init s3c2440_serial_init(void)
  129. {
  130. return s3c24xx_serial_init(&s3c2440_serial_driver, &s3c2440_uart_inf);
  131. }
  132. static void __exit s3c2440_serial_exit(void)
  133. {
  134. platform_driver_unregister(&s3c2440_serial_driver);
  135. }
  136. module_init(s3c2440_serial_init);
  137. module_exit(s3c2440_serial_exit);
  138. MODULE_DESCRIPTION("Samsung S3C2440,S3C2442 SoC Serial port driver");
  139. MODULE_AUTHOR("Ben Dooks <ben@simtec.co.uk>");
  140. MODULE_LICENSE("GPL v2");
  141. MODULE_ALIAS("platform:s3c2440-uart");