David S. Miller | d979f17 | 2007-10-27 00:13:04 -0700 | [diff] [blame] | 1 | /* console.c: Routines that deal with sending and receiving IO |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | * to/from the current console device using the PROM. |
| 3 | * |
David S. Miller | d979f17 | 2007-10-27 00:13:04 -0700 | [diff] [blame] | 4 | * Copyright (C) 1995 David S. Miller (davem@davemloft.net) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | */ |
David S. Miller | 91921fe | 2010-11-17 10:22:56 -0800 | [diff] [blame^] | 21 | static int prom_nbgetchar(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 22 | { |
David S. Miller | 25edd69 | 2010-08-23 23:10:57 -0700 | [diff] [blame] | 23 | unsigned long args[7]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 24 | char inc; |
| 25 | |
David S. Miller | 25edd69 | 2010-08-23 23:10:57 -0700 | [diff] [blame] | 26 | args[0] = (unsigned long) "read"; |
| 27 | args[1] = 3; |
| 28 | args[2] = 1; |
| 29 | args[3] = (unsigned int) prom_stdin; |
| 30 | args[4] = (unsigned long) &inc; |
| 31 | args[5] = 1; |
| 32 | args[6] = (unsigned long) -1; |
| 33 | |
| 34 | p1275_cmd_direct(args); |
| 35 | |
| 36 | if (args[6] == 1) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | return inc; |
David S. Miller | 25edd69 | 2010-08-23 23:10:57 -0700 | [diff] [blame] | 38 | return -1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | } |
| 40 | |
| 41 | /* Non blocking put character to console device, returns -1 if |
| 42 | * unsuccessful. |
| 43 | */ |
David S. Miller | 91921fe | 2010-11-17 10:22:56 -0800 | [diff] [blame^] | 44 | static int prom_nbputchar(char c) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | { |
David S. Miller | 25edd69 | 2010-08-23 23:10:57 -0700 | [diff] [blame] | 46 | unsigned long args[7]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 47 | char outc; |
| 48 | |
| 49 | outc = c; |
David S. Miller | 25edd69 | 2010-08-23 23:10:57 -0700 | [diff] [blame] | 50 | |
| 51 | args[0] = (unsigned long) "write"; |
| 52 | args[1] = 3; |
| 53 | args[2] = 1; |
| 54 | args[3] = (unsigned int) prom_stdout; |
| 55 | args[4] = (unsigned long) &outc; |
| 56 | args[5] = 1; |
| 57 | args[6] = (unsigned long) -1; |
| 58 | |
| 59 | p1275_cmd_direct(args); |
| 60 | |
| 61 | if (args[6] == 1) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 62 | return 0; |
| 63 | else |
| 64 | return -1; |
| 65 | } |
| 66 | |
| 67 | /* Blocking version of get character routine above. */ |
| 68 | char |
| 69 | prom_getchar(void) |
| 70 | { |
| 71 | int character; |
| 72 | while((character = prom_nbgetchar()) == -1) ; |
| 73 | return (char) character; |
| 74 | } |
| 75 | |
| 76 | /* Blocking version of put character routine above. */ |
| 77 | void |
| 78 | prom_putchar(char c) |
| 79 | { |
| 80 | prom_nbputchar(c); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 81 | } |