summaryrefslogtreecommitdiffstats
path: root/target/linux/realtek/files/rtkload/prom_printf.c
blob: 7bf58cdb3cbcda1e94d7b134214b5b1aedb4e807 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/* 
 * Borrowed from arch/mips/r39xx/prom/init.c
 *
 */

/*
 * init.c: early initialisation code for R39XX Class PDAs
 *
 * Copyright (C) 1999 Harald Koerfgen
 *
 * $Id: prom_printf.c,v 1.2 2008/08/04 08:54:44 michael Exp $
 */



#define CONFIG_SERIAL

#include <stdarg.h>

//#include <linux/config.h>
#include <linux/autoconf.h>

#ifdef CONFIG_RTL_EB8186
#include <asm/rtl8181.h>
#endif

#if 1
	//#define __KERNEL__

	//#include <asm/types.h>		
	//#include <asm/serial.h>
	#include <asm/io.h>

	#define UART_THR	0x2000	
	#define UART_LSR	0x2014
	
	#define rtl_outb(port,val) outb(val,port) 	
	#define rtl_inb(port) inb(port)
#endif
       
void serial_outc(char c)
{
	int i=0;
    while (1)
    {
          i++;
                if (i >=0x6000)
                        break;

                if      (rtl_inb(UART_LSR) & 0x20)
                        break;
     }
     rtl_outb(UART_THR, c);
}
 

/*
 * Helpful for debugging :-)
 */
int prom_printf(const char * fmt, ...)
{
#ifdef CONFIG_SERIAL
	//extern void serial_outc(char);
	static char buf[1024];
	va_list args;
	char c;
	int i = 0;

	/*
	 * Printing messages via serial port
	 */
	va_start(args, fmt);
	vsprintf(buf, fmt, args);
	va_end(args);

	for (i = 0; buf[i] != '\0'; i++) {
		c = buf[i];
		if (c == '\n')
			serial_outc('\r');
		serial_outc(c);
	}

	return i;
#else
	return 0;
#endif
}