s3c6400.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. /*
  2. * Driver for Samsung S3C6400 and S3C6410 SoC onboard UARTs.
  3. *
  4. * Copyright 2008 Openmoko, Inc.
  5. * Copyright 2008 Simtec Electronics
  6. * Ben Dooks <ben@simtec.co.uk>
  7. * http://armlinux.simtec.co.uk/
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License version 2 as
  11. * published by the Free Software Foundation.
  12. */
  13. #include <linux/module.h>
  14. #include <linux/ioport.h>
  15. #include <linux/io.h>
  16. #include <linux/platform_device.h>
  17. #include <linux/init.h>
  18. #include <linux/serial_core.h>
  19. #include <linux/serial.h>
  20. #include <asm/irq.h>
  21. #include <mach/hardware.h>
  22. #include <plat/regs-serial.h>
  23. #include "samsung.h"
  24. static int s3c6400_serial_setsource(struct uart_port *port,
  25. struct s3c24xx_uart_clksrc *clk)
  26. {
  27. unsigned long ucon = rd_regl(port, S3C2410_UCON);
  28. if (strcmp(clk->name, "uclk0") == 0) {
  29. ucon &= ~S3C6400_UCON_CLKMASK;
  30. ucon |= S3C6400_UCON_UCLK0;
  31. } else if (strcmp(clk->name, "uclk1") == 0)
  32. ucon |= S3C6400_UCON_UCLK1;
  33. else if (strcmp(clk->name, "pclk") == 0) {
  34. /* See notes about transitioning from UCLK to PCLK */
  35. ucon &= ~S3C6400_UCON_UCLK0;
  36. } else {
  37. printk(KERN_ERR "unknown clock source %s\n", clk->name);
  38. return -EINVAL;
  39. }
  40. wr_regl(port, S3C2410_UCON, ucon);
  41. return 0;
  42. }
  43. static int s3c6400_serial_getsource(struct uart_port *port,
  44. struct s3c24xx_uart_clksrc *clk)
  45. {
  46. u32 ucon = rd_regl(port, S3C2410_UCON);
  47. clk->divisor = 1;
  48. switch (ucon & S3C6400_UCON_CLKMASK) {
  49. case S3C6400_UCON_UCLK0:
  50. clk->name = "uclk0";
  51. break;
  52. case S3C6400_UCON_UCLK1:
  53. clk->name = "uclk1";
  54. break;
  55. case S3C6400_UCON_PCLK:
  56. case S3C6400_UCON_PCLK2:
  57. clk->name = "pclk";
  58. break;
  59. }
  60. return 0;
  61. }
  62. static int s3c6400_serial_resetport(struct uart_port *port,
  63. struct s3c2410_uartcfg *cfg)
  64. {
  65. unsigned long ucon = rd_regl(port, S3C2410_UCON);
  66. dbg("s3c6400_serial_resetport: port=%p (%08lx), cfg=%p\n",
  67. port, port->mapbase, cfg);
  68. /* ensure we don't change the clock settings... */
  69. ucon &= S3C6400_UCON_CLKMASK;
  70. wr_regl(port, S3C2410_UCON, ucon | cfg->ucon);
  71. wr_regl(port, S3C2410_ULCON, cfg->ulcon);
  72. /* reset both fifos */
  73. wr_regl(port, S3C2410_UFCON, cfg->ufcon | S3C2410_UFCON_RESETBOTH);
  74. wr_regl(port, S3C2410_UFCON, cfg->ufcon);
  75. return 0;
  76. }
  77. static struct s3c24xx_uart_info s3c6400_uart_inf = {
  78. .name = "Samsung S3C6400 UART",
  79. .type = PORT_S3C6400,
  80. .fifosize = 64,
  81. .has_divslot = 1,
  82. .rx_fifomask = S3C2440_UFSTAT_RXMASK,
  83. .rx_fifoshift = S3C2440_UFSTAT_RXSHIFT,
  84. .rx_fifofull = S3C2440_UFSTAT_RXFULL,
  85. .tx_fifofull = S3C2440_UFSTAT_TXFULL,
  86. .tx_fifomask = S3C2440_UFSTAT_TXMASK,
  87. .tx_fifoshift = S3C2440_UFSTAT_TXSHIFT,
  88. .get_clksrc = s3c6400_serial_getsource,
  89. .set_clksrc = s3c6400_serial_setsource,
  90. .reset_port = s3c6400_serial_resetport,
  91. };
  92. /* device management */
  93. static int s3c6400_serial_probe(struct platform_device *dev)
  94. {
  95. dbg("s3c6400_serial_probe: dev=%p\n", dev);
  96. return s3c24xx_serial_probe(dev, &s3c6400_uart_inf);
  97. }
  98. static struct platform_driver s3c6400_serial_driver = {
  99. .probe = s3c6400_serial_probe,
  100. .remove = __devexit_p(s3c24xx_serial_remove),
  101. .driver = {
  102. .name = "s3c6400-uart",
  103. .owner = THIS_MODULE,
  104. },
  105. };
  106. s3c24xx_console_init(&s3c6400_serial_driver, &s3c6400_uart_inf);
  107. static int __init s3c6400_serial_init(void)
  108. {
  109. return s3c24xx_serial_init(&s3c6400_serial_driver, &s3c6400_uart_inf);
  110. }
  111. static void __exit s3c6400_serial_exit(void)
  112. {
  113. platform_driver_unregister(&s3c6400_serial_driver);
  114. }
  115. module_init(s3c6400_serial_init);
  116. module_exit(s3c6400_serial_exit);
  117. MODULE_DESCRIPTION("Samsung S3C6400,S3C6410 SoC Serial port driver");
  118. MODULE_AUTHOR("Ben Dooks <ben@simtec.co.uk>");
  119. MODULE_LICENSE("GPL v2");
  120. MODULE_ALIAS("platform:s3c6400-uart");