Linux 2.6.25-rc4
[linux-2.6/next.git] / arch / sparc / prom / console.c
blob2a007a78441512be1fc7b5aa8af5656d660980aa
1 /* $Id: console.c,v 1.25 2001/10/30 04:54:22 davem Exp $
2 * console.c: Routines that deal with sending and receiving IO
3 * to/from the current console device using the PROM.
5 * Copyright (C) 1995 David S. Miller (davem@caip.rutgers.edu)
6 * Copyright (C) 1998 Pete Zaitcev <zaitcev@yahoo.com>
7 */
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>
18 extern void restore_current(void);
20 /* Non blocking get character from console input device, returns -1
21 * if no input was taken. This can be used for polling.
23 int
24 prom_nbgetchar(void)
26 static char inc;
27 int i = -1;
28 unsigned long flags;
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;
43 break;
44 default:
45 i = -1;
46 break;
48 restore_current();
49 spin_unlock_irqrestore(&prom_lock, flags);
50 return i; /* Ugh, we could spin forever on unsupported proms ;( */
53 /* Non blocking put character to console device, returns -1 if
54 * unsuccessful.
56 int
57 prom_nbputchar(char c)
59 static char outc;
60 unsigned long flags;
61 int i = -1;
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;
81 restore_current();
82 spin_unlock_irqrestore(&prom_lock, flags);
83 return i; /* Ugh, we could spin forever on unsupported proms ;( */
86 /* Blocking version of get character routine above. */
87 char
88 prom_getchar(void)
90 int character;
91 while((character = prom_nbgetchar()) == -1) ;
92 return (char) character;
95 /* Blocking version of put character routine above. */
96 void
97 prom_putchar(char c)
99 while(prom_nbputchar(c) == -1) ;
100 return;