blob: 2ce5acb45f2dcf0fe77f1fe0f1d04d602efb0c83 [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 */
David S. Miller91921fe2010-11-17 10:22:56 -080022static int prom_nbgetchar(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -070023{
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:
Linus Torvalds1da177e2005-04-16 15:20:36 -070031 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 */
David S. Miller91921fe2010-11-17 10:22:56 -080053static int prom_nbputchar(char c)
Linus Torvalds1da177e2005-04-16 15:20:36 -070054{
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:
Linus Torvalds1da177e2005-04-16 15:20:36 -070062 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. */
82char
83prom_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. */
91void
92prom_putchar(char c)
93{
94 while(prom_nbputchar(c) == -1) ;
Linus Torvalds1da177e2005-04-16 15:20:36 -070095}