blob: a71736f004430fb595313bdeb184b506fb24afaf [file] [log] [blame]
Wu Zhangjinf6a27402009-07-02 23:20:20 +08001/* early printk support
2 *
3 * Copyright (c) 2009 Philippe Vachon <philippe@cowpig.ca>
Wu Zhangjindb54ff22009-10-16 14:17:16 +08004 * Copyright (c) 2009 Lemote Inc.
Wu Zhangjinf7a904d2010-01-04 17:16:51 +08005 * Author: Wu Zhangjin, wuzhangjin@gmail.com
Wu Zhangjinf6a27402009-07-02 23:20:20 +08006 *
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 Zhangjinf6a27402009-07-02 23:20:20 +080012#include <linux/serial_reg.h>
13
Wu Zhangjin5e983ff2009-07-02 23:23:03 +080014#include <loongson.h>
Wu Zhangjinf6a27402009-07-02 23:20:20 +080015
16#define PORT(base, offset) (u8 *)(base + offset)
17
Wu Zhangjindb54ff22009-10-16 14:17:16 +080018static inline unsigned int serial_in(unsigned char *base, int offset)
Wu Zhangjinf6a27402009-07-02 23:20:20 +080019{
20 return readb(PORT(base, offset));
21}
22
Wu Zhangjindb54ff22009-10-16 14:17:16 +080023static inline void serial_out(unsigned char *base, int offset, int value)
Wu Zhangjinf6a27402009-07-02 23:20:20 +080024{
25 writeb(value, PORT(base, offset));
26}
27
28void prom_putchar(char c)
29{
Wu Zhangjina3ed4952009-11-06 18:35:34 +080030 int timeout;
31 unsigned char *uart_base;
Wu Zhangjinf6a27402009-07-02 23:20:20 +080032
Wu Zhangjina3ed4952009-11-06 18:35:34 +080033 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 Zhangjinf6a27402009-07-02 23:20:20 +080038 ;
39
40 serial_out(uart_base, UART_TX, c);
41}