]> git.karo-electronics.de Git - karo-tx-linux.git/blob - arch/sparc/prom/console_32.c
2ce5acb45f2dcf0fe77f1fe0f1d04d602efb0c83
[karo-tx-linux.git] / arch / sparc / prom / console_32.c
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 static int prom_nbgetchar(void)
23 {
24         static char inc;
25         int i = -1;
26         unsigned long flags;
27
28         spin_lock_irqsave(&prom_lock, flags);
29         switch(prom_vers) {
30         case PROM_V0:
31                 i = (*(romvec->pv_nbgetchar))();
32                 break;
33         case PROM_V2:
34         case PROM_V3:
35                 if( (*(romvec->pv_v2devops).v2_dev_read)(*romvec->pv_v2bootargs.fd_stdin , &inc, 0x1) == 1) {
36                         i = inc;
37                 } else {
38                         i = -1;
39                 }
40                 break;
41         default:
42                 i = -1;
43                 break;
44         };
45         restore_current();
46         spin_unlock_irqrestore(&prom_lock, flags);
47         return i; /* Ugh, we could spin forever on unsupported proms ;( */
48 }
49
50 /* Non blocking put character to console device, returns -1 if
51  * unsuccessful.
52  */
53 static int prom_nbputchar(char c)
54 {
55         static char outc;
56         unsigned long flags;
57         int i = -1;
58
59         spin_lock_irqsave(&prom_lock, flags);
60         switch(prom_vers) {
61         case PROM_V0:
62                 i = (*(romvec->pv_nbputchar))(c);
63                 break;
64         case PROM_V2:
65         case PROM_V3:
66                 outc = c;
67                 if( (*(romvec->pv_v2devops).v2_dev_write)(*romvec->pv_v2bootargs.fd_stdout, &outc, 0x1) == 1)
68                         i = 0;
69                 else
70                         i = -1;
71                 break;
72         default:
73                 i = -1;
74                 break;
75         };
76         restore_current();
77         spin_unlock_irqrestore(&prom_lock, flags);
78         return i; /* Ugh, we could spin forever on unsupported proms ;( */
79 }
80
81 /* Blocking version of get character routine above. */
82 char
83 prom_getchar(void)
84 {
85         int character;
86         while((character = prom_nbgetchar()) == -1) ;
87         return (char) character;
88 }
89
90 /* Blocking version of put character routine above. */
91 void
92 prom_putchar(char c)
93 {
94         while(prom_nbputchar(c) == -1) ;
95 }