root/arch/sparc/prom/console.c

/* [previous][next][first][last][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. prom_nbgetchar
  2. prom_nbputchar
  3. prom_getchar
  4. prom_putchar
  5. prom_query_input_device
  6. prom_query_output_device

   1 /* $Id: console.c,v 1.5 1995/11/25 00:59:54 davem Exp $
   2  * 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  */
   7 
   8 #include <asm/openprom.h>
   9 #include <asm/oplib.h>
  10 #include <linux/string.h>
  11 
  12 /* Non blocking get character from console input device, returns -1
  13  * if no input was taken.  This can be used for polling.
  14  */
  15 int
  16 prom_nbgetchar(void)
     /* [previous][next][first][last][top][bottom][index][help] */
  17 {
  18         static char inc;
  19 
  20         switch(prom_vers) {
  21         case PROM_V0:
  22                 return (*(romvec->pv_nbgetchar))();
  23                 break;
  24         case PROM_V2:
  25         case PROM_V3:
  26         case PROM_P1275:
  27                 if( (*(romvec->pv_v2devops).v2_dev_read)(*romvec->pv_v2bootargs.fd_stdin , &inc, 0x1) == 1)
  28                         return inc;
  29                 return -1;
  30                 break;
  31         };
  32         return 0; /* Ugh, we could spin forever on unsupported proms ;( */
  33 }
  34 
  35 /* Non blocking put character to console device, returns -1 if
  36  * unsuccessful.
  37  */
  38 int
  39 prom_nbputchar(char c)
     /* [previous][next][first][last][top][bottom][index][help] */
  40 {
  41         static char outc;
  42 
  43         switch(prom_vers) {
  44         case PROM_V0:
  45                 return (*(romvec->pv_nbputchar))(c);
  46                 break;
  47         case PROM_V2:
  48         case PROM_V3:
  49         case PROM_P1275:
  50                 outc = c;
  51                 if( (*(romvec->pv_v2devops).v2_dev_write)(*romvec->pv_v2bootargs.fd_stdout, &outc, 0x1) == 1)
  52                         return 0;
  53                 return -1;
  54                 break;
  55         };
  56         return 0; /* Ugh, we could spin forever on unsupported proms ;( */
  57 }
  58 
  59 /* Blocking version of get character routine above. */
  60 char
  61 prom_getchar(void)
     /* [previous][next][first][last][top][bottom][index][help] */
  62 {
  63         int character;
  64         while((character = prom_nbgetchar()) == -1) ;
  65         return (char) character;
  66 }
  67 
  68 /* Blocking version of put character routine above. */
  69 void
  70 prom_putchar(char c)
     /* [previous][next][first][last][top][bottom][index][help] */
  71 {
  72         while(prom_nbputchar(c) == -1) ;
  73         return;
  74 }
  75 
  76 /* Query for input device type */
  77 enum prom_input_device
  78 prom_query_input_device()
     /* [previous][next][first][last][top][bottom][index][help] */
  79 {
  80         switch(*romvec->pv_stdin) {
  81         case PROMDEV_KBD:       return PROMDEV_IKBD;
  82         case PROMDEV_TTYA:      return PROMDEV_ITTYA;
  83         case PROMDEV_TTYB:      return PROMDEV_ITTYB;
  84         default:
  85                 return PROMDEV_I_UNK;
  86         };
  87 }
  88 
  89 /* Query for output device type */
  90 
  91 enum prom_output_device
  92 prom_query_output_device()
     /* [previous][next][first][last][top][bottom][index][help] */
  93 {
  94         int st_p;
  95         char propb[ sizeof("display") ];
  96         int propl;
  97 
  98         switch(prom_vers) {
  99         case PROM_V0:
 100                 switch(*romvec->pv_stdin) {
 101                 case PROMDEV_SCREEN:    return PROMDEV_OSCREEN;
 102                 case PROMDEV_TTYA:      return PROMDEV_OTTYA;
 103                 case PROMDEV_TTYB:      return PROMDEV_OTTYB;
 104                 };
 105                 break;
 106         case PROM_V2:
 107         case PROM_V3:
 108         case PROM_P1275:
 109                 st_p = (*romvec->pv_v2devops.v2_inst2pkg)(*romvec->pv_v2bootargs.fd_stdout);
 110                 propl = prom_getproperty(st_p, "device_type", propb, sizeof(propb));
 111                 if (propl >= 0 && propl == sizeof("display") &&
 112                         strncmp("display", propb, sizeof("display")) == 0)
 113                 {
 114                         return PROMDEV_OSCREEN;
 115                 }
 116                 /* This works on SS-2 (an early OpenFirmware) still. */
 117                 /* XXX fix for serial cases at SS-5.                 */
 118                 switch(*romvec->pv_stdin) {
 119                 case PROMDEV_TTYA:      return PROMDEV_OTTYA;
 120                 case PROMDEV_TTYB:      return PROMDEV_OTTYB;
 121                 };
 122                 break;
 123         };
 124         return PROMDEV_O_UNK;
 125 }

/* [previous][next][first][last][top][bottom][index][help] */