xref: /openbmc/linux/arch/sparc/prom/console_32.c (revision fd589a8f)
1 /*
2  * console.c: Routines that deal with sending and receiving IO
3  *            to/from the current console device using the PROM.
4  *
5  * Copyright (C) 1995 David S. Miller (davem@caip.rutgers.edu)
6  * Copyright (C) 1998 Pete Zaitcev <zaitcev@yahoo.com>
7  */
8 
9 #include <linux/types.h>
10 #include <linux/kernel.h>
11 #include <linux/sched.h>
12 #include <asm/openprom.h>
13 #include <asm/oplib.h>
14 #include <asm/system.h>
15 #include <linux/string.h>
16 
17 extern void restore_current(void);
18 
19 /* Non blocking get character from console input device, returns -1
20  * if no input was taken.  This can be used for polling.
21  */
22 int
23 prom_nbgetchar(void)
24 {
25 	static char inc;
26 	int i = -1;
27 	unsigned long flags;
28 
29 	spin_lock_irqsave(&prom_lock, flags);
30 	switch(prom_vers) {
31 	case PROM_V0:
32 		i = (*(romvec->pv_nbgetchar))();
33 		break;
34 	case PROM_V2:
35 	case PROM_V3:
36 		if( (*(romvec->pv_v2devops).v2_dev_read)(*romvec->pv_v2bootargs.fd_stdin , &inc, 0x1) == 1) {
37 			i = inc;
38 		} else {
39 			i = -1;
40 		}
41 		break;
42 	default:
43 		i = -1;
44 		break;
45 	};
46 	restore_current();
47 	spin_unlock_irqrestore(&prom_lock, flags);
48 	return i; /* Ugh, we could spin forever on unsupported proms ;( */
49 }
50 
51 /* Non blocking put character to console device, returns -1 if
52  * unsuccessful.
53  */
54 int
55 prom_nbputchar(char c)
56 {
57 	static char outc;
58 	unsigned long flags;
59 	int i = -1;
60 
61 	spin_lock_irqsave(&prom_lock, flags);
62 	switch(prom_vers) {
63 	case PROM_V0:
64 		i = (*(romvec->pv_nbputchar))(c);
65 		break;
66 	case PROM_V2:
67 	case PROM_V3:
68 		outc = c;
69 		if( (*(romvec->pv_v2devops).v2_dev_write)(*romvec->pv_v2bootargs.fd_stdout, &outc, 0x1) == 1)
70 			i = 0;
71 		else
72 			i = -1;
73 		break;
74 	default:
75 		i = -1;
76 		break;
77 	};
78 	restore_current();
79 	spin_unlock_irqrestore(&prom_lock, flags);
80 	return i; /* Ugh, we could spin forever on unsupported proms ;( */
81 }
82 
83 /* Blocking version of get character routine above. */
84 char
85 prom_getchar(void)
86 {
87 	int character;
88 	while((character = prom_nbgetchar()) == -1) ;
89 	return (char) character;
90 }
91 
92 /* Blocking version of put character routine above. */
93 void
94 prom_putchar(char c)
95 {
96 	while(prom_nbputchar(c) == -1) ;
97 	return;
98 }
99