Path: blob/master/arch/mips/cavium-octeon/serial.c
10820 views
/*1* This file is subject to the terms and conditions of the GNU General Public2* License. See the file "COPYING" in the main directory of this archive3* for more details.4*5* Copyright (C) 2004-2007 Cavium Networks6*/7#include <linux/console.h>8#include <linux/module.h>9#include <linux/init.h>10#include <linux/platform_device.h>11#include <linux/serial.h>12#include <linux/serial_8250.h>13#include <linux/serial_reg.h>14#include <linux/tty.h>15#include <linux/irq.h>1617#include <asm/time.h>1819#include <asm/octeon/octeon.h>2021#define DEBUG_UART 12223unsigned int octeon_serial_in(struct uart_port *up, int offset)24{25int rv = cvmx_read_csr((uint64_t)(up->membase + (offset << 3)));26if (offset == UART_IIR && (rv & 0xf) == 7) {27/* Busy interrupt, read the USR (39) and try again. */28cvmx_read_csr((uint64_t)(up->membase + (39 << 3)));29rv = cvmx_read_csr((uint64_t)(up->membase + (offset << 3)));30}31return rv;32}3334void octeon_serial_out(struct uart_port *up, int offset, int value)35{36/*37* If bits 6 or 7 of the OCTEON UART's LCR are set, it quits38* working.39*/40if (offset == UART_LCR)41value &= 0x9f;42cvmx_write_csr((uint64_t)(up->membase + (offset << 3)), (u8)value);43}4445/*46* Allocated in .bss, so it is all zeroed.47*/48#define OCTEON_MAX_UARTS 349static struct plat_serial8250_port octeon_uart8250_data[OCTEON_MAX_UARTS + 1];50static struct platform_device octeon_uart8250_device = {51.name = "serial8250",52.id = PLAT8250_DEV_PLATFORM,53.dev = {54.platform_data = octeon_uart8250_data,55},56};5758static void __init octeon_uart_set_common(struct plat_serial8250_port *p)59{60p->flags = ASYNC_SKIP_TEST | UPF_SHARE_IRQ | UPF_FIXED_TYPE;61p->type = PORT_OCTEON;62p->iotype = UPIO_MEM;63p->regshift = 3; /* I/O addresses are every 8 bytes */64if (octeon_is_simulation())65/* Make simulator output fast*/66p->uartclk = 115200 * 16;67else68p->uartclk = octeon_get_io_clock_rate();69p->serial_in = octeon_serial_in;70p->serial_out = octeon_serial_out;71}7273static int __init octeon_serial_init(void)74{75int enable_uart0;76int enable_uart1;77int enable_uart2;78struct plat_serial8250_port *p;7980#ifdef CONFIG_CAVIUM_OCTEON_2ND_KERNEL81/*82* If we are configured to run as the second of two kernels,83* disable uart0 and enable uart1. Uart0 is owned by the first84* kernel85*/86enable_uart0 = 0;87enable_uart1 = 1;88#else89/*90* We are configured for the first kernel. We'll enable uart091* if the bootloader told us to use 0, otherwise will enable92* uart 1.93*/94enable_uart0 = (octeon_get_boot_uart() == 0);95enable_uart1 = (octeon_get_boot_uart() == 1);96#ifdef CONFIG_KGDB97enable_uart1 = 1;98#endif99#endif100101/* Right now CN52XX is the only chip with a third uart */102enable_uart2 = OCTEON_IS_MODEL(OCTEON_CN52XX);103104p = octeon_uart8250_data;105if (enable_uart0) {106/* Add a ttyS device for hardware uart 0 */107octeon_uart_set_common(p);108p->membase = (void *) CVMX_MIO_UARTX_RBR(0);109p->mapbase = CVMX_MIO_UARTX_RBR(0) & ((1ull << 49) - 1);110p->irq = OCTEON_IRQ_UART0;111p++;112}113114if (enable_uart1) {115/* Add a ttyS device for hardware uart 1 */116octeon_uart_set_common(p);117p->membase = (void *) CVMX_MIO_UARTX_RBR(1);118p->mapbase = CVMX_MIO_UARTX_RBR(1) & ((1ull << 49) - 1);119p->irq = OCTEON_IRQ_UART1;120p++;121}122if (enable_uart2) {123/* Add a ttyS device for hardware uart 2 */124octeon_uart_set_common(p);125p->membase = (void *) CVMX_MIO_UART2_RBR;126p->mapbase = CVMX_MIO_UART2_RBR & ((1ull << 49) - 1);127p->irq = OCTEON_IRQ_UART2;128p++;129}130131BUG_ON(p > &octeon_uart8250_data[OCTEON_MAX_UARTS]);132133return platform_device_register(&octeon_uart8250_device);134}135136device_initcall(octeon_serial_init);137138139