Steven J. Hill | 3070033 | 2012-05-30 21:02:49 +0000 | [diff] [blame] | 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) 2012 MIPS Technologies, Inc. All rights reserved. |
| 7 | */ |
| 8 | #include <linux/init.h> |
| 9 | #include <linux/console.h> |
| 10 | #include <linux/serial_reg.h> |
| 11 | #include <linux/io.h> |
| 12 | |
Ralf Baechle | 7034228 | 2013-01-22 12:59:30 +0100 | [diff] [blame] | 13 | #define SEAD_UART1_REGS_BASE 0xbf000800 /* ttyS1 = DB9 port */ |
| 14 | #define SEAD_UART0_REGS_BASE 0xbf000900 /* ttyS0 = USB port */ |
Steven J. Hill | 3070033 | 2012-05-30 21:02:49 +0000 | [diff] [blame] | 15 | #define PORT(base_addr, offset) ((unsigned int __iomem *)(base_addr+(offset)*4)) |
| 16 | |
| 17 | static char console_port = 1; |
| 18 | |
| 19 | static inline unsigned int serial_in(int offset, unsigned int base_addr) |
| 20 | { |
| 21 | return __raw_readl(PORT(base_addr, offset)) & 0xff; |
| 22 | } |
| 23 | |
| 24 | static inline void serial_out(int offset, int value, unsigned int base_addr) |
| 25 | { |
| 26 | __raw_writel(value, PORT(base_addr, offset)); |
| 27 | } |
| 28 | |
Steven J. Hill | 0be2abb | 2013-03-25 14:35:30 -0500 | [diff] [blame] | 29 | void __init fw_init_early_console(char port) |
Steven J. Hill | 3070033 | 2012-05-30 21:02:49 +0000 | [diff] [blame] | 30 | { |
| 31 | console_port = port; |
| 32 | } |
| 33 | |
| 34 | int prom_putchar(char c) |
| 35 | { |
| 36 | unsigned int base_addr; |
| 37 | |
| 38 | base_addr = console_port ? SEAD_UART1_REGS_BASE : SEAD_UART0_REGS_BASE; |
| 39 | |
| 40 | while ((serial_in(UART_LSR, base_addr) & UART_LSR_THRE) == 0) |
| 41 | ; |
| 42 | |
| 43 | serial_out(UART_TX, c, base_addr); |
| 44 | |
| 45 | return 1; |
| 46 | } |