OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [rc203soc/] [sw/] [uClinux/] [arch/] [sparc/] [prom/] [console.c] - Blame information for rev 1777

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 1624 jcastillo
/* $Id: console.c,v 1.1 2005-12-20 09:49:32 jcastillo 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 <linux/config.h>
9
#include <asm/openprom.h>
10
#include <asm/oplib.h>
11
#include <linux/string.h>
12
 
13
/* Non blocking get character from console input device, returns -1
14
 * if no input was taken.  This can be used for polling.
15
 */
16
int
17
prom_nbgetchar(void)
18
{
19
        static char inc;
20
 
21
        switch(prom_vers) {
22
        case PROM_V0:
23
                return (*(romvec->pv_nbgetchar))();
24
                break;
25
        case PROM_V2:
26
        case PROM_V3:
27
        case PROM_P1275:
28
                if( (*(romvec->pv_v2devops).v2_dev_read)(*romvec->pv_v2bootargs.fd_stdin , &inc, 0x1) == 1)
29
                        return inc;
30
                return -1;
31
                break;
32
        case PROM_AP1000:
33
                return -1;
34
                break;
35
        };
36
        return 0; /* Ugh, we could spin forever on unsupported proms ;( */
37
}
38
 
39
/* Non blocking put character to console device, returns -1 if
40
 * unsuccessful.
41
 */
42
int
43
prom_nbputchar(char c)
44
{
45
        static char outc;
46
 
47
        switch(prom_vers) {
48
        case PROM_V0:
49
                return (*(romvec->pv_nbputchar))(c);
50
                break;
51
        case PROM_V2:
52
        case PROM_V3:
53
        case PROM_P1275:
54
                outc = c;
55
                if( (*(romvec->pv_v2devops).v2_dev_write)(*romvec->pv_v2bootargs.fd_stdout, &outc, 0x1) == 1)
56
                        return 0;
57
                return -1;
58
                break;
59
        case PROM_AP1000:
60
#if CONFIG_AP1000
61
                {
62
                  extern void ap_putchar(char );
63
                  ap_putchar(c);
64
                  return 0;
65
                }
66
#endif
67
                break;
68
        };
69
        return 0; /* Ugh, we could spin forever on unsupported proms ;( */
70
}
71
 
72
/* Blocking version of get character routine above. */
73
char
74
prom_getchar(void)
75
{
76
        int character;
77
        while((character = prom_nbgetchar()) == -1) ;
78
        return (char) character;
79
}
80
 
81
/* Blocking version of put character routine above. */
82
void
83
prom_putchar(char c)
84
{
85
        while(prom_nbputchar(c) == -1) ;
86
        return;
87
}
88
 
89
/* Query for input device type */
90
enum prom_input_device
91
prom_query_input_device()
92
{
93
        int st_p;
94
        char propb[64];
95
        char *p;
96
 
97
        switch(prom_vers) {
98
        case PROM_V0:
99
        case PROM_V2:
100
        default:
101
                switch(*romvec->pv_stdin) {
102
                case PROMDEV_KBD:       return PROMDEV_IKBD;
103
                case PROMDEV_TTYA:      return PROMDEV_ITTYA;
104
                case PROMDEV_TTYB:      return PROMDEV_ITTYB;
105
                default:
106
                        return PROMDEV_I_UNK;
107
                };
108
        case PROM_V3:
109
        case PROM_P1275:
110
                st_p = (*romvec->pv_v2devops.v2_inst2pkg)(*romvec->pv_v2bootargs.fd_stdin);
111
                if(prom_node_has_property(st_p, "keyboard"))
112
                        return PROMDEV_IKBD;
113
                prom_getproperty(st_p, "device_type", propb, sizeof(propb));
114
                if(strncmp(propb, "serial", sizeof("serial")))
115
                        return PROMDEV_I_UNK;
116
                prom_getproperty(prom_root_node, "stdin-path", propb, sizeof(propb));
117
                p = propb;
118
                while(*p) p++; p -= 2;
119
                if(p[0] == ':') {
120
                        if(p[1] == 'a')
121
                                return PROMDEV_ITTYA;
122
                        else if(p[1] == 'b')
123
                                return PROMDEV_ITTYB;
124
                }
125
                return PROMDEV_I_UNK;
126
        case PROM_AP1000:
127
                return PROMDEV_I_UNK;
128
        };
129
}
130
 
131
/* Query for output device type */
132
 
133
enum prom_output_device
134
prom_query_output_device()
135
{
136
        int st_p;
137
        char propb[64];
138
        char *p;
139
        int propl;
140
 
141
        switch(prom_vers) {
142
        case PROM_V0:
143
                switch(*romvec->pv_stdin) {
144
                case PROMDEV_SCREEN:    return PROMDEV_OSCREEN;
145
                case PROMDEV_TTYA:      return PROMDEV_OTTYA;
146
                case PROMDEV_TTYB:      return PROMDEV_OTTYB;
147
                };
148
                break;
149
        case PROM_V2:
150
        case PROM_V3:
151
        case PROM_P1275:
152
                st_p = (*romvec->pv_v2devops.v2_inst2pkg)(*romvec->pv_v2bootargs.fd_stdout);
153
                propl = prom_getproperty(st_p, "device_type", propb, sizeof(propb));
154
                if (propl >= 0 && propl == sizeof("display") &&
155
                        strncmp("display", propb, sizeof("display")) == 0)
156
                {
157
                        return PROMDEV_OSCREEN;
158
                }
159
                if(prom_vers == PROM_V3) {
160
                        if(strncmp("serial", propb, sizeof("serial")))
161
                                return PROMDEV_O_UNK;
162
                        prom_getproperty(prom_root_node, "stdout-path", propb, sizeof(propb));
163
                        p = propb;
164
                        while(*p) p++; p -= 2;
165
                        if(p[0]==':') {
166
                                if(p[1] == 'a')
167
                                        return PROMDEV_OTTYA;
168
                                else if(p[1] == 'b')
169
                                        return PROMDEV_OTTYB;
170
                        }
171
                        return PROMDEV_O_UNK;
172
                } else {
173
                        /* This works on SS-2 (an early OpenFirmware) still. */
174
                        switch(*romvec->pv_stdin) {
175
                        case PROMDEV_TTYA:      return PROMDEV_OTTYA;
176
                        case PROMDEV_TTYB:      return PROMDEV_OTTYB;
177
                        };
178
                }
179
                break;
180
        case PROM_AP1000:
181
                return PROMDEV_I_UNK;
182
        };
183
        return PROMDEV_O_UNK;
184
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.