blob: b3075d73fc19e7f2bf765a4cff144aa27683334b [file] [log] [blame]
Adrian Bunk88278ca2008-05-19 16:53:02 -07001/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002 * 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>
Linus Torvalds1da177e2005-04-16 15:20:36 -070013#include <asm/oplib.h>
14#include <asm/system.h>
15#include <linux/string.h>
16
17extern void restore_current(void);
18
Linus Torvalds1da177e2005-04-16 15:20:36 -070019/* Non blocking get character from console input device, returns -1
20 * if no input was taken. This can be used for polling.
21 */
22int
23prom_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:
Linus Torvalds1da177e2005-04-16 15:20:36 -070032 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 */
54int
55prom_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:
Linus Torvalds1da177e2005-04-16 15:20:36 -070064 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. */
84char
85prom_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. */
93void
94prom_putchar(char c)
95{
96 while(prom_nbputchar(c) == -1) ;
97 return;
98}