GUI: Fix Tomato RAF theme for all builds. Compilation typo.
[tomato.git] / release / src-rt-6.x.4708 / cfe / cfe / pccons / dev_pcconsole.c
blob0753466a14c6e0bdbbf8265c85e3bd782881cd74
1 /* *********************************************************************
2 * Broadcom Common Firmware Environment (CFE)
3 *
4 * PC Console driver File: dev_pcconsole.c
5 *
6 * A console driver for a PC-style keyboard and mouse
7 *
8 * Author: Mitch Lichtenberg (mpl@broadcom.com)
9 *
10 *********************************************************************
12 * Copyright 2000,2001,2002,2003
13 * Broadcom Corporation. All rights reserved.
15 * This software is furnished under license and may be used and
16 * copied only in accordance with the following terms and
17 * conditions. Subject to these conditions, you may download,
18 * copy, install, use, modify and distribute modified or unmodified
19 * copies of this software in source and/or binary form. No title
20 * or ownership is transferred hereby.
22 * 1) Any source code used, modified or distributed must reproduce
23 * and retain this copyright notice and list of conditions
24 * as they appear in the source file.
26 * 2) No right is granted to use any trade name, trademark, or
27 * logo of Broadcom Corporation. The "Broadcom Corporation"
28 * name may not be used to endorse or promote products derived
29 * from this software without the prior written permission of
30 * Broadcom Corporation.
32 * 3) THIS SOFTWARE IS PROVIDED "AS-IS" AND ANY EXPRESS OR
33 * IMPLIED WARRANTIES, INCLUDING BUT NOT LIMITED TO, ANY IMPLIED
34 * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
35 * PURPOSE, OR NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT
36 * SHALL BROADCOM BE LIABLE FOR ANY DAMAGES WHATSOEVER, AND IN
37 * PARTICULAR, BROADCOM SHALL NOT BE LIABLE FOR DIRECT, INDIRECT,
38 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
39 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
40 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
41 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
42 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
43 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE), EVEN IF ADVISED OF
44 * THE POSSIBILITY OF SUCH DAMAGE.
45 ********************************************************************* */
50 #include "sbmips.h"
51 #include "lib_types.h"
52 #include "lib_malloc.h"
53 #include "lib_printf.h"
54 #include "cfe_iocb.h"
55 #include "cfe_device.h"
57 #include "lib_physio.h"
59 #include "kbd_subr.h"
60 #include "vga_subr.h"
62 #include "bsp_config.h"
63 #include "pcireg.h"
64 #include "pcivar.h"
67 /* *********************************************************************
68 * Constants
69 ********************************************************************* */
71 #define KBD_RXFULL 1 /* bit set if kb has data */
72 #define KBD_TXFULL 2 /* bit set if we can send cmd */
73 #define VGA_TEXTBUF_COLOR 0xB8000 /* VGA frame buffer */
75 #if defined(_P5064_) || defined(_P6064_)
76 #define PCI_MEM_SPACE 0x10000000 /* 128MB: s/w configurable */
77 #define __ISAaddr(addr) ((physaddr_t)(PCI_MEM_SPACE+(addr)))
78 #else
79 #define __ISAaddr(addr) ((physaddr_t)0x40000000+(addr))
80 #endif
82 #define cpu_isamap(x,y) __ISAaddr(x)
84 /* *********************************************************************
85 * Forward references
86 ********************************************************************* */
88 static void pcconsole_probe(cfe_driver_t *drv,
89 unsigned long probe_a, unsigned long probe_b,
90 void *probe_ptr);
93 static int pcconsole_open(cfe_devctx_t *ctx);
94 static int pcconsole_read(cfe_devctx_t *ctx,iocb_buffer_t *buffer);
95 static int pcconsole_inpstat(cfe_devctx_t *ctx,iocb_inpstat_t *inpstat);
96 static int pcconsole_write(cfe_devctx_t *ctx,iocb_buffer_t *buffer);
97 static int pcconsole_ioctl(cfe_devctx_t *ctx,iocb_buffer_t *buffer);
98 static int pcconsole_close(cfe_devctx_t *ctx);
99 static void pcconsole_poll(cfe_devctx_t *ctx,int64_t ticks);
101 const static cfe_devdisp_t pcconsole_dispatch = {
102 pcconsole_open,
103 pcconsole_read,
104 pcconsole_inpstat,
105 pcconsole_write,
106 pcconsole_ioctl,
107 pcconsole_close,
108 pcconsole_poll,
109 NULL
112 const cfe_driver_t pcconsole = {
113 "PC Console",
114 "pcconsole",
115 CFE_DEV_SERIAL,
116 &pcconsole_dispatch,
117 pcconsole_probe
121 /* *********************************************************************
122 * Structures
123 ********************************************************************* */
126 typedef struct pcconsole_s {
127 vga_term_t vga;
128 keystate_t ks;
129 uint32_t kbd_status;
130 uint32_t kbd_data;
131 } pcconsole_t;
134 /* *********************************************************************
135 * pcconsole_poll(ctx,ticks)
137 * Poll routine - check for new keyboard events
139 * Input parameters:
140 * ctx - device context
141 * ticks - current time
143 * Return value:
144 * nothing
145 ********************************************************************* */
148 static void pcconsole_poll(cfe_devctx_t *ctx,int64_t ticks)
150 pcconsole_t *softc = ctx->dev_softc;
151 uint8_t status;
152 uint8_t b;
154 status = inb(softc->kbd_status);
156 if (status & KBD_RXFULL) {
157 b = inb(softc->kbd_data);
158 kbd_doscan(&(softc->ks),b);
162 /* *********************************************************************
163 * pcconsole_waitcmdready(softc)
165 * Wait for the keyboard to be ready to accept a command
167 * Input parameters:
168 * softc - console structure
170 * Return value:
171 * nothing
172 ********************************************************************* */
174 static void pcconsole_waitcmdready(pcconsole_t *softc)
176 uint8_t status;
177 uint8_t data;
179 for (;;) {
180 status = inb(softc->kbd_status); /* read status */
181 if (status & KBD_RXFULL) {
182 data = inb(softc->kbd_data); /* get data */
183 kbd_doscan(&(softc->ks),data); /* process scan codes */
185 if (!(status & KBD_TXFULL)) break; /* stop when kbd ready */
190 /* *********************************************************************
191 * pcconsole_setleds(ks,leds)
193 * Callback from the keyboard routines for setting the LEDS
195 * Input parameters:
196 * ks - keyboard state
197 * leds - new LED state
199 * Return value:
201 ********************************************************************* */
203 static int pcconsole_setleds(keystate_t *ks,int leds)
205 pcconsole_t *softc = kbd_getref(ks);
207 pcconsole_waitcmdready(softc);
208 outb(softc->kbd_data,KBDCMD_SETLEDS);
209 pcconsole_waitcmdready(softc);
210 outb(softc->kbd_data,(leds & 7));
212 return 0;
216 /* *********************************************************************
217 * pcconsole_probe(drv,probe_a,probe_b,probe_ptr)
219 * Probe routine. This routine sets up the pcconsole device
221 * Input parameters:
222 * drv - driver structure
223 * probe_a
224 * probe_b
225 * probe_ptr
227 * Return value:
228 * nothing
229 ********************************************************************* */
231 static void pcconsole_probe(cfe_driver_t *drv,
232 unsigned long probe_a, unsigned long probe_b,
233 void *probe_ptr)
235 pcconsole_t *softc;
236 char descr[80];
237 volatile uint8_t *isamem;
240 * probe_a is
241 * probe_b is
242 * probe_ptr is
245 softc = (pcconsole_t *) KMALLOC(sizeof(pcconsole_t),0);
246 if (softc) {
247 softc->kbd_status = 0x64;
248 softc->kbd_data = 0x60;
249 kbd_init(&(softc->ks),pcconsole_setleds,softc);
251 isamem = (volatile uint8_t *) ((uintptr_t)cpu_isamap(0,1024*1024));
252 vga_init(&(softc->vga),__ISAaddr(VGA_TEXTBUF_COLOR),outb);
254 xsprintf(descr,"%s",drv->drv_description,probe_a,probe_b);
255 cfe_attach(drv,softc,NULL,descr);
261 static int pcconsole_open(cfe_devctx_t *ctx)
263 pcconsole_t *softc = ctx->dev_softc;
265 outb(softc->kbd_data,KBDCMD_RESET); /* reset keyboard */
266 kbd_init(&(softc->ks),pcconsole_setleds,softc);
267 vga_clear(&(softc->vga));
268 vga_setcursor(&(softc->vga),0,0);
270 return 0;
273 static int pcconsole_read(cfe_devctx_t *ctx,iocb_buffer_t *buffer)
275 pcconsole_t *softc = ctx->dev_softc;
276 unsigned char *bptr;
277 int blen;
279 pcconsole_poll(ctx,0);
281 bptr = buffer->buf_ptr;
282 blen = buffer->buf_length;
284 while ((blen > 0) && (kbd_inpstat(&(softc->ks)))) {
285 *bptr++ = (kbd_read(&(softc->ks)) & 0xFF);
286 blen--;
289 buffer->buf_retlen = buffer->buf_length - blen;
290 return 0;
293 static int pcconsole_inpstat(cfe_devctx_t *ctx,iocb_inpstat_t *inpstat)
295 pcconsole_t *softc = ctx->dev_softc;
297 pcconsole_poll(ctx,0);
299 inpstat->inp_status = kbd_inpstat(&(softc->ks)) ? 1 : 0;
301 return 0;
304 static int pcconsole_write(cfe_devctx_t *ctx,iocb_buffer_t *buffer)
306 pcconsole_t *softc = ctx->dev_softc;
307 unsigned char *bptr;
308 int blen;
310 bptr = buffer->buf_ptr;
311 blen = buffer->buf_length;
313 vga_writestr(&(softc->vga),bptr,7,blen);
315 buffer->buf_retlen = buffer->buf_length;
316 return 0;
319 static int pcconsole_ioctl(cfe_devctx_t *ctx,iocb_buffer_t *buffer)
321 /* pcconsole_t *softc = ctx->dev_softc;*/
323 return -1;
326 static int pcconsole_close(cfe_devctx_t *ctx)
328 /* pcconsole_t *softc = ctx->dev_softc;*/
330 return 0;