parisc: add pdc_coproc_cfg_unlocked and set_firmware_width_unlocked
[linux-2.6.git] / arch / sparc / prom / console.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/sun4prom.h>
14 #include <asm/oplib.h>
15 #include <asm/system.h>
16 #include <linux/string.h>
17
18 extern void restore_current(void);
19
20 /* Non blocking get character from console input device, returns -1
21  * if no input was taken.  This can be used for polling.
22  */
23 int
24 prom_nbgetchar(void)
25 {
26         static char inc;
27         int i = -1;
28         unsigned long flags;
29
30         spin_lock_irqsave(&prom_lock, flags);
31         switch(prom_vers) {
32         case PROM_V0:
33         case PROM_SUN4:
34                 i = (*(romvec->pv_nbgetchar))();
35                 break;
36         case PROM_V2:
37         case PROM_V3:
38                 if( (*(romvec->pv_v2devops).v2_dev_read)(*romvec->pv_v2bootargs.fd_stdin , &inc, 0x1) == 1) {
39                         i = inc;
40                 } else {
41                         i = -1;
42                 }
43                 break;
44         default:
45                 i = -1;
46                 break;
47         };
48         restore_current();
49         spin_unlock_irqrestore(&prom_lock, flags);
50         return i; /* Ugh, we could spin forever on unsupported proms ;( */
51 }
52
53 /* Non blocking put character to console device, returns -1 if
54  * unsuccessful.
55  */
56 int
57 prom_nbputchar(char c)
58 {
59         static char outc;
60         unsigned long flags;
61         int i = -1;
62
63         spin_lock_irqsave(&prom_lock, flags);
64         switch(prom_vers) {
65         case PROM_V0:
66         case PROM_SUN4:
67                 i = (*(romvec->pv_nbputchar))(c);
68                 break;
69         case PROM_V2:
70         case PROM_V3:
71                 outc = c;
72                 if( (*(romvec->pv_v2devops).v2_dev_write)(*romvec->pv_v2bootargs.fd_stdout, &outc, 0x1) == 1)
73                         i = 0;
74                 else
75                         i = -1;
76                 break;
77         default:
78                 i = -1;
79                 break;
80         };
81         restore_current();
82         spin_unlock_irqrestore(&prom_lock, flags);
83         return i; /* Ugh, we could spin forever on unsupported proms ;( */
84 }
85
86 /* Blocking version of get character routine above. */
87 char
88 prom_getchar(void)
89 {
90         int character;
91         while((character = prom_nbgetchar()) == -1) ;
92         return (char) character;
93 }
94
95 /* Blocking version of put character routine above. */
96 void
97 prom_putchar(char c)
98 {
99         while(prom_nbputchar(c) == -1) ;
100         return;
101 }