GUI: Fix Tomato RAF theme for all builds. Compilation typo.
[tomato.git] / release / src-rt-6.x.4708 / cfe / cfe / pccons / dev_pcconsole2.c
blobe4fbc69ad5756ba48c1e236dbc3e6057c5043450
1 /* *********************************************************************
2 * Broadcom Common Firmware Environment (CFE)
3 *
4 * PC Console driver File: dev_pcconsole2.c
5 *
6 * A console driver for a PC-style keyboard and mouse
8 * This version is for USB keyboards. Someday we'll consolidate
9 * everything.
11 * Author: Mitch Lichtenberg (mpl@broadcom.com)
13 *********************************************************************
15 * Copyright 2000,2001,2002,2003
16 * Broadcom Corporation. All rights reserved.
18 * This software is furnished under license and may be used and
19 * copied only in accordance with the following terms and
20 * conditions. Subject to these conditions, you may download,
21 * copy, install, use, modify and distribute modified or unmodified
22 * copies of this software in source and/or binary form. No title
23 * or ownership is transferred hereby.
25 * 1) Any source code used, modified or distributed must reproduce
26 * and retain this copyright notice and list of conditions
27 * as they appear in the source file.
29 * 2) No right is granted to use any trade name, trademark, or
30 * logo of Broadcom Corporation. The "Broadcom Corporation"
31 * name may not be used to endorse or promote products derived
32 * from this software without the prior written permission of
33 * Broadcom Corporation.
35 * 3) THIS SOFTWARE IS PROVIDED "AS-IS" AND ANY EXPRESS OR
36 * IMPLIED WARRANTIES, INCLUDING BUT NOT LIMITED TO, ANY IMPLIED
37 * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
38 * PURPOSE, OR NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT
39 * SHALL BROADCOM BE LIABLE FOR ANY DAMAGES WHATSOEVER, AND IN
40 * PARTICULAR, BROADCOM SHALL NOT BE LIABLE FOR DIRECT, INDIRECT,
41 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
42 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
43 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
44 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
45 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
46 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE), EVEN IF ADVISED OF
47 * THE POSSIBILITY OF SUCH DAMAGE.
48 ********************************************************************* */
53 #include "sbmips.h"
54 #include "lib_types.h"
55 #include "lib_malloc.h"
56 #include "lib_printf.h"
57 #include "lib_string.h"
59 #include "cfe_iocb.h"
60 #include "cfe_device.h"
61 #include "cfe_timer.h"
63 #include "lib_physio.h"
65 #include "vga_subr.h"
67 #include "bsp_config.h"
68 #include "pcireg.h"
69 #include "pcivar.h"
71 /* *********************************************************************
72 * Constants
73 ********************************************************************* */
75 #define KBD_RXFULL 1 /* bit set if kb has data */
76 #define KBD_TXFULL 2 /* bit set if we can send cmd */
77 #define VGA_TEXTBUF_COLOR 0xB8000 /* VGA frame buffer */
79 #define __ISAaddr(x)(0x40000000+(x))
81 /* *********************************************************************
82 * Forward references
83 ********************************************************************* */
85 int pcconsole_enqueue(uint8_t ch);
87 static void pcconsole_probe(cfe_driver_t *drv,
88 unsigned long probe_a, unsigned long probe_b,
89 void *probe_ptr);
92 static int pcconsole_open(cfe_devctx_t *ctx);
93 static int pcconsole_read(cfe_devctx_t *ctx,iocb_buffer_t *buffer);
94 static int pcconsole_inpstat(cfe_devctx_t *ctx,iocb_inpstat_t *inpstat);
95 static int pcconsole_write(cfe_devctx_t *ctx,iocb_buffer_t *buffer);
96 static int pcconsole_ioctl(cfe_devctx_t *ctx,iocb_buffer_t *buffer);
97 static int pcconsole_close(cfe_devctx_t *ctx);
98 static void pcconsole_poll(cfe_devctx_t *ctx,int64_t ticks);
100 const static cfe_devdisp_t pcconsole_dispatch = {
101 pcconsole_open,
102 pcconsole_read,
103 pcconsole_inpstat,
104 pcconsole_write,
105 pcconsole_ioctl,
106 pcconsole_close,
107 pcconsole_poll,
108 NULL
111 const cfe_driver_t pcconsole2 = {
112 "PC Console (USB)",
113 "pcconsole",
114 CFE_DEV_SERIAL,
115 &pcconsole_dispatch,
116 pcconsole_probe
120 /* *********************************************************************
121 * Structures
122 ********************************************************************* */
124 #define KBD_QUEUE_LEN 32
126 typedef struct pcconsole_s {
127 vga_term_t vga;
128 int kbd_in;
129 int kbd_out;
130 uint8_t kbd_data[KBD_QUEUE_LEN];
131 } pcconsole_t;
133 static pcconsole_t *pcconsole_current = NULL;
135 /* *********************************************************************
136 * pcconsole_poll(ctx,ticks)
138 * Poll routine - check for new keyboard events
140 * Input parameters:
141 * ctx - device context
142 * ticks - current time
144 * Return value:
145 * nothing
146 ********************************************************************* */
149 static void pcconsole_poll(cfe_devctx_t *ctx,int64_t ticks)
151 /* No polling needed, USB will do the work for us */
156 /* *********************************************************************
157 * pcconsole_probe(drv,probe_a,probe_b,probe_ptr)
159 * Probe routine. This routine sets up the pcconsole device
161 * Input parameters:
162 * drv - driver structure
163 * probe_a
164 * probe_b
165 * probe_ptr
167 * Return value:
168 * nothing
169 ********************************************************************* */
171 static void pcconsole_probe(cfe_driver_t *drv,
172 unsigned long probe_a, unsigned long probe_b,
173 void *probe_ptr)
175 pcconsole_t *softc;
176 char descr[80];
179 * probe_a is
180 * probe_b is
181 * probe_ptr is
184 softc = (pcconsole_t *) KMALLOC(sizeof(pcconsole_t),0);
185 if (softc) {
187 memset(softc,0,sizeof(pcconsole_t));
189 vga_init(&(softc->vga),__ISAaddr(VGA_TEXTBUF_COLOR),outb);
191 xsprintf(descr,"%s",drv->drv_description,probe_a,probe_b);
192 cfe_attach(drv,softc,NULL,descr);
198 static int pcconsole_open(cfe_devctx_t *ctx)
200 pcconsole_t *softc = ctx->dev_softc;
202 pcconsole_current = softc;
204 softc->kbd_in = 0;
205 softc->kbd_out = 0;
207 vga_clear(&(softc->vga));
208 vga_setcursor(&(softc->vga),0,0);
210 return 0;
213 static int pcconsole_read(cfe_devctx_t *ctx,iocb_buffer_t *buffer)
215 pcconsole_t *softc = ctx->dev_softc;
216 unsigned char *bptr;
217 int blen;
219 bptr = buffer->buf_ptr;
220 blen = buffer->buf_length;
222 while ((blen > 0) && (softc->kbd_in != softc->kbd_out)) {
223 *bptr++ = softc->kbd_data[softc->kbd_out];
224 softc->kbd_out++;
225 if (softc->kbd_out >= KBD_QUEUE_LEN) {
226 softc->kbd_out = 0;
228 blen--;
231 buffer->buf_retlen = buffer->buf_length - blen;
232 return 0;
235 static int pcconsole_inpstat(cfe_devctx_t *ctx,iocb_inpstat_t *inpstat)
237 pcconsole_t *softc = ctx->dev_softc;
239 POLL();
241 inpstat->inp_status = (softc->kbd_in != softc->kbd_out);
243 return 0;
246 static int pcconsole_write(cfe_devctx_t *ctx,iocb_buffer_t *buffer)
248 pcconsole_t *softc = ctx->dev_softc;
249 unsigned char *bptr;
250 int blen;
252 bptr = buffer->buf_ptr;
253 blen = buffer->buf_length;
255 vga_writestr(&(softc->vga),bptr,7,blen);
257 buffer->buf_retlen = buffer->buf_length;
258 return 0;
261 static int pcconsole_ioctl(cfe_devctx_t *ctx,iocb_buffer_t *buffer)
263 /* pcconsole_t *softc = ctx->dev_softc;*/
265 return -1;
268 static int pcconsole_close(cfe_devctx_t *ctx)
270 /* pcconsole_t *softc = ctx->dev_softc;*/
271 pcconsole_current = NULL;
273 return 0;
277 * Called by USB system to queue characters.
279 int pcconsole_enqueue(uint8_t ch)
281 int newidx;
283 if (!pcconsole_current) return -1;
285 newidx = pcconsole_current->kbd_in+1;
286 if (newidx >= KBD_QUEUE_LEN) newidx = 0;
288 if (newidx == pcconsole_current->kbd_out) return -1;
290 pcconsole_current->kbd_data[pcconsole_current->kbd_in] = ch;
291 pcconsole_current->kbd_in = newidx;
293 return 0;