Wu Zhangjin | f6a2740 | 2009-07-02 23:20:20 +0800 | [diff] [blame] | 1 | /* early printk support |
| 2 | * |
| 3 | * Copyright (c) 2009 Philippe Vachon <philippe@cowpig.ca> |
Wu Zhangjin | db54ff2 | 2009-10-16 14:17:16 +0800 | [diff] [blame] | 4 | * Copyright (c) 2009 Lemote Inc. |
Wu Zhangjin | f7a904d | 2010-01-04 17:16:51 +0800 | [diff] [blame] | 5 | * Author: Wu Zhangjin, wuzhangjin@gmail.com |
Wu Zhangjin | f6a2740 | 2009-07-02 23:20:20 +0800 | [diff] [blame] | 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify it |
| 8 | * under the terms of the GNU General Public License as published by the |
| 9 | * Free Software Foundation; either version 2 of the License, or (at your |
| 10 | * option) any later version. |
| 11 | */ |
Wu Zhangjin | f6a2740 | 2009-07-02 23:20:20 +0800 | [diff] [blame] | 12 | #include <linux/serial_reg.h> |
| 13 | |
Wu Zhangjin | 5e983ff | 2009-07-02 23:23:03 +0800 | [diff] [blame] | 14 | #include <loongson.h> |
Wu Zhangjin | f6a2740 | 2009-07-02 23:20:20 +0800 | [diff] [blame] | 15 | |
| 16 | #define PORT(base, offset) (u8 *)(base + offset) |
| 17 | |
Wu Zhangjin | db54ff2 | 2009-10-16 14:17:16 +0800 | [diff] [blame] | 18 | static inline unsigned int serial_in(unsigned char *base, int offset) |
Wu Zhangjin | f6a2740 | 2009-07-02 23:20:20 +0800 | [diff] [blame] | 19 | { |
| 20 | return readb(PORT(base, offset)); |
| 21 | } |
| 22 | |
Wu Zhangjin | db54ff2 | 2009-10-16 14:17:16 +0800 | [diff] [blame] | 23 | static inline void serial_out(unsigned char *base, int offset, int value) |
Wu Zhangjin | f6a2740 | 2009-07-02 23:20:20 +0800 | [diff] [blame] | 24 | { |
| 25 | writeb(value, PORT(base, offset)); |
| 26 | } |
| 27 | |
| 28 | void prom_putchar(char c) |
| 29 | { |
Wu Zhangjin | a3ed495 | 2009-11-06 18:35:34 +0800 | [diff] [blame] | 30 | int timeout; |
| 31 | unsigned char *uart_base; |
Wu Zhangjin | f6a2740 | 2009-07-02 23:20:20 +0800 | [diff] [blame] | 32 | |
Wu Zhangjin | a3ed495 | 2009-11-06 18:35:34 +0800 | [diff] [blame] | 33 | uart_base = (unsigned char *)_loongson_uart_base; |
| 34 | timeout = 1024; |
| 35 | |
| 36 | while (((serial_in(uart_base, UART_LSR) & UART_LSR_THRE) == 0) && |
| 37 | (timeout-- > 0)) |
Wu Zhangjin | f6a2740 | 2009-07-02 23:20:20 +0800 | [diff] [blame] | 38 | ; |
| 39 | |
| 40 | serial_out(uart_base, UART_TX, c); |
| 41 | } |