serial.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. /*
  2. * This file is subject to the terms and conditions of the GNU General Public
  3. * License. See the file "COPYING" in the main directory of this archive
  4. * for more details.
  5. *
  6. * Copyright (C) 2004-2007 Cavium Networks
  7. */
  8. #include <linux/console.h>
  9. #include <linux/module.h>
  10. #include <linux/init.h>
  11. #include <linux/platform_device.h>
  12. #include <linux/serial.h>
  13. #include <linux/serial_8250.h>
  14. #include <linux/serial_reg.h>
  15. #include <linux/tty.h>
  16. #include <linux/irq.h>
  17. #include <asm/time.h>
  18. #include <asm/octeon/octeon.h>
  19. #define DEBUG_UART 1
  20. unsigned int octeon_serial_in(struct uart_port *up, int offset)
  21. {
  22. int rv = cvmx_read_csr((uint64_t)(up->membase + (offset << 3)));
  23. if (offset == UART_IIR && (rv & 0xf) == 7) {
  24. /* Busy interrupt, read the USR (39) and try again. */
  25. cvmx_read_csr((uint64_t)(up->membase + (39 << 3)));
  26. rv = cvmx_read_csr((uint64_t)(up->membase + (offset << 3)));
  27. }
  28. return rv;
  29. }
  30. void octeon_serial_out(struct uart_port *up, int offset, int value)
  31. {
  32. /*
  33. * If bits 6 or 7 of the OCTEON UART's LCR are set, it quits
  34. * working.
  35. */
  36. if (offset == UART_LCR)
  37. value &= 0x9f;
  38. cvmx_write_csr((uint64_t)(up->membase + (offset << 3)), (u8)value);
  39. }
  40. static int octeon_serial_probe(struct platform_device *pdev)
  41. {
  42. int irq, res;
  43. struct resource *res_mem;
  44. struct uart_8250_port up;
  45. /* All adaptors have an irq. */
  46. irq = platform_get_irq(pdev, 0);
  47. if (irq < 0)
  48. return irq;
  49. memset(&up, 0, sizeof(up));
  50. up.port.flags = ASYNC_SKIP_TEST | UPF_SHARE_IRQ | UPF_FIXED_TYPE;
  51. up.port.type = PORT_OCTEON;
  52. up.port.iotype = UPIO_MEM;
  53. up.port.regshift = 3;
  54. up.port.dev = &pdev->dev;
  55. if (octeon_is_simulation())
  56. /* Make simulator output fast*/
  57. up.port.uartclk = 115200 * 16;
  58. else
  59. up.port.uartclk = octeon_get_io_clock_rate();
  60. up.port.serial_in = octeon_serial_in;
  61. up.port.serial_out = octeon_serial_out;
  62. up.port.irq = irq;
  63. res_mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  64. if (res_mem == NULL) {
  65. dev_err(&pdev->dev, "found no memory resource\n");
  66. return -ENXIO;
  67. }
  68. up.port.mapbase = res_mem->start;
  69. up.port.membase = ioremap(res_mem->start, resource_size(res_mem));
  70. res = serial8250_register_8250_port(&up);
  71. return res >= 0 ? 0 : res;
  72. }
  73. static struct of_device_id octeon_serial_match[] = {
  74. {
  75. .compatible = "cavium,octeon-3860-uart",
  76. },
  77. {},
  78. };
  79. MODULE_DEVICE_TABLE(of, octeon_serial_match);
  80. static struct platform_driver octeon_serial_driver = {
  81. .probe = octeon_serial_probe,
  82. .driver = {
  83. .owner = THIS_MODULE,
  84. .name = "octeon_serial",
  85. .of_match_table = octeon_serial_match,
  86. },
  87. };
  88. static int __init octeon_serial_init(void)
  89. {
  90. return platform_driver_register(&octeon_serial_driver);
  91. }
  92. late_initcall(octeon_serial_init);