Merge branch 'intel_idle+snb' into idle-release
[pandora-kernel.git] / arch / sparc / prom / console_64.c
1 /* console.c: Routines that deal with sending and receiving IO
2  *            to/from the current console device using the PROM.
3  *
4  * Copyright (C) 1995 David S. Miller (davem@davemloft.net)
5  * Copyright (C) 1996,1997 Jakub Jelinek (jj@sunsite.mff.cuni.cz)
6  */
7
8 #include <linux/types.h>
9 #include <linux/kernel.h>
10 #include <linux/sched.h>
11 #include <asm/openprom.h>
12 #include <asm/oplib.h>
13 #include <asm/system.h>
14 #include <linux/string.h>
15
16 extern int prom_stdin, prom_stdout;
17
18 /* Non blocking get character from console input device, returns -1
19  * if no input was taken.  This can be used for polling.
20  */
21 inline int
22 prom_nbgetchar(void)
23 {
24         unsigned long args[7];
25         char inc;
26
27         args[0] = (unsigned long) "read";
28         args[1] = 3;
29         args[2] = 1;
30         args[3] = (unsigned int) prom_stdin;
31         args[4] = (unsigned long) &inc;
32         args[5] = 1;
33         args[6] = (unsigned long) -1;
34
35         p1275_cmd_direct(args);
36
37         if (args[6] == 1)
38                 return inc;
39         return -1;
40 }
41
42 /* Non blocking put character to console device, returns -1 if
43  * unsuccessful.
44  */
45 inline int
46 prom_nbputchar(char c)
47 {
48         unsigned long args[7];
49         char outc;
50         
51         outc = c;
52
53         args[0] = (unsigned long) "write";
54         args[1] = 3;
55         args[2] = 1;
56         args[3] = (unsigned int) prom_stdout;
57         args[4] = (unsigned long) &outc;
58         args[5] = 1;
59         args[6] = (unsigned long) -1;
60
61         p1275_cmd_direct(args);
62
63         if (args[6] == 1)
64                 return 0;
65         else
66                 return -1;
67 }
68
69 /* Blocking version of get character routine above. */
70 char
71 prom_getchar(void)
72 {
73         int character;
74         while((character = prom_nbgetchar()) == -1) ;
75         return (char) character;
76 }
77
78 /* Blocking version of put character routine above. */
79 void
80 prom_putchar(char c)
81 {
82         prom_nbputchar(c);
83 }
84
85 void
86 prom_puts(const char *s, int len)
87 {
88         unsigned long args[7];
89
90         args[0] = (unsigned long) "write";
91         args[1] = 3;
92         args[2] = 1;
93         args[3] = (unsigned int) prom_stdout;
94         args[4] = (unsigned long) s;
95         args[5] = len;
96         args[6] = (unsigned long) -1;
97
98         p1275_cmd_direct(args);
99 }