blob: f393f65f3923acd39343a65b1e50d3845d2806c6 [file] [log] [blame]
David Daney5b3b1682009-01-08 16:46:40 -08001/*
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>
David Howellsca4d3e672010-10-07 14:08:54 +010016#include <linux/irq.h>
David Daney5b3b1682009-01-08 16:46:40 -080017
18#include <asm/time.h>
19
20#include <asm/octeon/octeon.h>
21
David Daney5b3b1682009-01-08 16:46:40 -080022#define DEBUG_UART 1
David Daney5b3b1682009-01-08 16:46:40 -080023
24unsigned int octeon_serial_in(struct uart_port *up, int offset)
25{
26 int rv = cvmx_read_csr((uint64_t)(up->membase + (offset << 3)));
27 if (offset == UART_IIR && (rv & 0xf) == 7) {
28 /* Busy interrupt, read the USR (39) and try again. */
29 cvmx_read_csr((uint64_t)(up->membase + (39 << 3)));
30 rv = cvmx_read_csr((uint64_t)(up->membase + (offset << 3)));
31 }
32 return rv;
33}
34
35void octeon_serial_out(struct uart_port *up, int offset, int value)
36{
37 /*
38 * If bits 6 or 7 of the OCTEON UART's LCR are set, it quits
39 * working.
40 */
41 if (offset == UART_LCR)
42 value &= 0x9f;
43 cvmx_write_csr((uint64_t)(up->membase + (offset << 3)), (u8)value);
44}
45
Greg Kroah-Hartman28eb0e42012-12-21 14:04:39 -080046static int octeon_serial_probe(struct platform_device *pdev)
David Daneyb59b2842012-07-05 18:12:40 +020047{
48 int irq, res;
49 struct resource *res_mem;
David Daney640de632012-08-14 09:42:39 -070050 struct uart_8250_port up;
David Daneyb59b2842012-07-05 18:12:40 +020051
52 /* All adaptors have an irq. */
53 irq = platform_get_irq(pdev, 0);
54 if (irq < 0)
55 return irq;
56
David Daney640de632012-08-14 09:42:39 -070057 memset(&up, 0, sizeof(up));
David Daneyb59b2842012-07-05 18:12:40 +020058
David Daney640de632012-08-14 09:42:39 -070059 up.port.flags = ASYNC_SKIP_TEST | UPF_SHARE_IRQ | UPF_FIXED_TYPE;
60 up.port.type = PORT_OCTEON;
61 up.port.iotype = UPIO_MEM;
62 up.port.regshift = 3;
63 up.port.dev = &pdev->dev;
David Daneyb59b2842012-07-05 18:12:40 +020064
65 if (octeon_is_simulation())
66 /* Make simulator output fast*/
David Daney640de632012-08-14 09:42:39 -070067 up.port.uartclk = 115200 * 16;
David Daneyb59b2842012-07-05 18:12:40 +020068 else
David Daney640de632012-08-14 09:42:39 -070069 up.port.uartclk = octeon_get_io_clock_rate();
David Daneyb59b2842012-07-05 18:12:40 +020070
David Daney640de632012-08-14 09:42:39 -070071 up.port.serial_in = octeon_serial_in;
72 up.port.serial_out = octeon_serial_out;
73 up.port.irq = irq;
David Daneyb59b2842012-07-05 18:12:40 +020074
75 res_mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
76 if (res_mem == NULL) {
77 dev_err(&pdev->dev, "found no memory resource\n");
78 return -ENXIO;
79 }
David Daney640de632012-08-14 09:42:39 -070080 up.port.mapbase = res_mem->start;
81 up.port.membase = ioremap(res_mem->start, resource_size(res_mem));
David Daneyb59b2842012-07-05 18:12:40 +020082
David Daney640de632012-08-14 09:42:39 -070083 res = serial8250_register_8250_port(&up);
David Daneyb59b2842012-07-05 18:12:40 +020084
85 return res >= 0 ? 0 : res;
86}
87
88static struct of_device_id octeon_serial_match[] = {
89 {
90 .compatible = "cavium,octeon-3860-uart",
91 },
92 {},
93};
94MODULE_DEVICE_TABLE(of, octeon_serial_match);
95
96static struct platform_driver octeon_serial_driver = {
97 .probe = octeon_serial_probe,
98 .driver = {
99 .owner = THIS_MODULE,
100 .name = "octeon_serial",
101 .of_match_table = octeon_serial_match,
David Daney5b3b1682009-01-08 16:46:40 -0800102 },
103};
104
David Daney5b3b1682009-01-08 16:46:40 -0800105static int __init octeon_serial_init(void)
106{
David Daneyb59b2842012-07-05 18:12:40 +0200107 return platform_driver_register(&octeon_serial_driver);
David Daney5b3b1682009-01-08 16:46:40 -0800108}
David Daneyb59b2842012-07-05 18:12:40 +0200109late_initcall(octeon_serial_init);