1 /* *********************************************************************
2 * Broadcom Common Firmware Environment (CFE)
4 * PC Console driver File: dev_pcconsole2.c
6 * A console driver for a PC-style keyboard and mouse
8 * This version is for USB keyboards. Someday we'll consolidate
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 ********************************************************************* */
54 #include "lib_types.h"
55 #include "lib_malloc.h"
56 #include "lib_printf.h"
57 #include "lib_string.h"
60 #include "cfe_device.h"
61 #include "cfe_timer.h"
63 #include "lib_physio.h"
67 #include "bsp_config.h"
71 /* *********************************************************************
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 /* *********************************************************************
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
,
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
= {
111 const cfe_driver_t pcconsole2
= {
120 /* *********************************************************************
122 ********************************************************************* */
124 #define KBD_QUEUE_LEN 32
126 typedef struct pcconsole_s
{
130 uint8_t kbd_data
[KBD_QUEUE_LEN
];
133 static pcconsole_t
*pcconsole_current
= NULL
;
135 /* *********************************************************************
136 * pcconsole_poll(ctx,ticks)
138 * Poll routine - check for new keyboard events
141 * ctx - device context
142 * ticks - current time
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
162 * drv - driver structure
169 ********************************************************************* */
171 static void pcconsole_probe(cfe_driver_t
*drv
,
172 unsigned long probe_a
, unsigned long probe_b
,
184 softc
= (pcconsole_t
*) KMALLOC(sizeof(pcconsole_t
),0);
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
;
207 vga_clear(&(softc
->vga
));
208 vga_setcursor(&(softc
->vga
),0,0);
213 static int pcconsole_read(cfe_devctx_t
*ctx
,iocb_buffer_t
*buffer
)
215 pcconsole_t
*softc
= ctx
->dev_softc
;
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
];
225 if (softc
->kbd_out
>= KBD_QUEUE_LEN
) {
231 buffer
->buf_retlen
= buffer
->buf_length
- blen
;
235 static int pcconsole_inpstat(cfe_devctx_t
*ctx
,iocb_inpstat_t
*inpstat
)
237 pcconsole_t
*softc
= ctx
->dev_softc
;
241 inpstat
->inp_status
= (softc
->kbd_in
!= softc
->kbd_out
);
246 static int pcconsole_write(cfe_devctx_t
*ctx
,iocb_buffer_t
*buffer
)
248 pcconsole_t
*softc
= ctx
->dev_softc
;
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
;
261 static int pcconsole_ioctl(cfe_devctx_t
*ctx
,iocb_buffer_t
*buffer
)
263 /* pcconsole_t *softc = ctx->dev_softc;*/
268 static int pcconsole_close(cfe_devctx_t
*ctx
)
270 /* pcconsole_t *softc = ctx->dev_softc;*/
271 pcconsole_current
= NULL
;
277 * Called by USB system to queue characters.
279 int pcconsole_enqueue(uint8_t ch
)
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
;