blob: 10322dc2f557a22d5befcc17dd4a27d8b6604f89 [file] [log] [blame]
David S. Millerd979f172007-10-27 00:13:04 -07001/* console.c: Routines that deal with sending and receiving IO
Linus Torvalds1da177e2005-04-16 15:20:36 -07002 * to/from the current console device using the PROM.
3 *
David S. Millerd979f172007-10-27 00:13:04 -07004 * Copyright (C) 1995 David S. Miller (davem@davemloft.net)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005 * 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
16extern 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 */
David S. Millerd979f172007-10-27 00:13:04 -070021inline int
Linus Torvalds1da177e2005-04-16 15:20:36 -070022prom_nbgetchar(void)
23{
David S. Miller25edd692010-08-23 23:10:57 -070024 unsigned long args[7];
Linus Torvalds1da177e2005-04-16 15:20:36 -070025 char inc;
26
David S. Miller25edd692010-08-23 23:10:57 -070027 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)
Linus Torvalds1da177e2005-04-16 15:20:36 -070038 return inc;
David S. Miller25edd692010-08-23 23:10:57 -070039 return -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -070040}
41
42/* Non blocking put character to console device, returns -1 if
43 * unsuccessful.
44 */
David S. Millerd979f172007-10-27 00:13:04 -070045inline int
Linus Torvalds1da177e2005-04-16 15:20:36 -070046prom_nbputchar(char c)
47{
David S. Miller25edd692010-08-23 23:10:57 -070048 unsigned long args[7];
Linus Torvalds1da177e2005-04-16 15:20:36 -070049 char outc;
50
51 outc = c;
David S. Miller25edd692010-08-23 23:10:57 -070052
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)
Linus Torvalds1da177e2005-04-16 15:20:36 -070064 return 0;
65 else
66 return -1;
67}
68
69/* Blocking version of get character routine above. */
70char
71prom_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. */
79void
80prom_putchar(char c)
81{
82 prom_nbputchar(c);
Linus Torvalds1da177e2005-04-16 15:20:36 -070083}
84
85void
David S. Millerbff06d52005-09-22 20:11:33 -070086prom_puts(const char *s, int len)
Linus Torvalds1da177e2005-04-16 15:20:36 -070087{
David S. Miller25edd692010-08-23 23:10:57 -070088 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);
Linus Torvalds1da177e2005-04-16 15:20:36 -070099}