1 /* $Id: console.c,v 1.9 1997/10/29 07:41:43 ecd 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) 1996,1997 Jakub Jelinek (jj@sunsite.mff.cuni.cz)
9 #include <linux/types.h>
10 #include <linux/kernel.h>
11 #include <linux/sched.h>
12 #include <asm/openprom.h>
13 #include <asm/oplib.h>
14 #include <asm/system.h>
15 #include <linux/string.h>
17 extern int prom_stdin, prom_stdout;
19 /* Non blocking get character from console input device, returns -1
20 * if no input was taken. This can be used for polling.
27 if (p1275_cmd("read", P1275_ARG(1,P1275_ARG_OUT_BUF)|
29 prom_stdin, &inc, P1275_SIZE(1)) == 1)
35 /* Non blocking put character to console device, returns -1 if
39 prom_nbputchar(char c)
44 if (p1275_cmd("write", P1275_ARG(1,P1275_ARG_IN_BUF)|
46 prom_stdout, &outc, P1275_SIZE(1)) == 1)
52 /* Blocking version of get character routine above. */
57 while((character = prom_nbgetchar()) == -1) ;
58 return (char) character;
61 /* Blocking version of put character routine above. */
70 prom_puts(const char *s, int len)
72 p1275_cmd("write", P1275_ARG(1,P1275_ARG_IN_BUF)|
74 prom_stdout, s, P1275_SIZE(len));
77 /* Query for input device type */
78 enum prom_input_device
79 prom_query_input_device(void)
84 st_p = prom_inst2pkg(prom_stdin);
85 if(prom_node_has_property(st_p, "keyboard"))
87 prom_getproperty(st_p, "device_type", propb, sizeof(propb));
88 if(strncmp(propb, "serial", 6))
90 /* FIXME: Is there any better way how to find out? */
91 memset(propb, 0, sizeof(propb));
92 st_p = prom_finddevice ("/options");
93 prom_getproperty(st_p, "input-device", propb, sizeof(propb));
96 * If we get here with propb == 'keyboard', we are on ttya, as
97 * the PROM defaulted to this due to 'no input device'.
99 if (!strncmp(propb, "keyboard", 8))
100 return PROMDEV_ITTYA;
102 if (!strncmp (propb, "rsc", 3))
105 if (!strncmp (propb, "virtual-console", 3))
106 return PROMDEV_IVCONS;
108 if (strncmp (propb, "tty", 3) || !propb[3])
109 return PROMDEV_I_UNK;
112 case 'a': return PROMDEV_ITTYA;
113 case 'b': return PROMDEV_ITTYB;
114 default: return PROMDEV_I_UNK;
118 /* Query for output device type */
120 enum prom_output_device
121 prom_query_output_device(void)
127 st_p = prom_inst2pkg(prom_stdout);
128 propl = prom_getproperty(st_p, "device_type", propb, sizeof(propb));
129 if (propl >= 0 && propl == sizeof("display") &&
130 strncmp("display", propb, sizeof("display")) == 0)
131 return PROMDEV_OSCREEN;
132 if(strncmp("serial", propb, 6))
133 return PROMDEV_O_UNK;
134 /* FIXME: Is there any better way how to find out? */
135 memset(propb, 0, sizeof(propb));
136 st_p = prom_finddevice ("/options");
137 prom_getproperty(st_p, "output-device", propb, sizeof(propb));
140 * If we get here with propb == 'screen', we are on ttya, as
141 * the PROM defaulted to this due to 'no input device'.
143 if (!strncmp(propb, "screen", 6))
144 return PROMDEV_OTTYA;
146 if (!strncmp (propb, "rsc", 3))
149 if (!strncmp (propb, "virtual-console", 3))
150 return PROMDEV_OVCONS;
152 if (strncmp (propb, "tty", 3) || !propb[3])
153 return PROMDEV_O_UNK;
156 case 'a': return PROMDEV_OTTYA;
157 case 'b': return PROMDEV_OTTYB;
158 default: return PROMDEV_O_UNK;