1 /* *********************************************************************
2 * Broadcom Common Firmware Environment (CFE)
4 * PC Console driver File: dev_pcconsole.c
6 * A console driver for a PC-style keyboard and mouse
8 * Author: Mitch Lichtenberg (mpl@broadcom.com)
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 ********************************************************************* */
51 #include "lib_types.h"
52 #include "lib_malloc.h"
53 #include "lib_printf.h"
55 #include "cfe_device.h"
57 #include "lib_physio.h"
62 #include "bsp_config.h"
67 /* *********************************************************************
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)))
79 #define __ISAaddr(addr) ((physaddr_t)0x40000000+(addr))
82 #define cpu_isamap(x,y) __ISAaddr(x)
84 /* *********************************************************************
86 ********************************************************************* */
88 static void pcconsole_probe(cfe_driver_t
*drv
,
89 unsigned long probe_a
, unsigned long probe_b
,
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
= {
112 const cfe_driver_t pcconsole
= {
121 /* *********************************************************************
123 ********************************************************************* */
126 typedef struct pcconsole_s
{
134 /* *********************************************************************
135 * pcconsole_poll(ctx,ticks)
137 * Poll routine - check for new keyboard events
140 * ctx - device context
141 * ticks - current time
145 ********************************************************************* */
148 static void pcconsole_poll(cfe_devctx_t
*ctx
,int64_t ticks
)
150 pcconsole_t
*softc
= ctx
->dev_softc
;
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
168 * softc - console structure
172 ********************************************************************* */
174 static void pcconsole_waitcmdready(pcconsole_t
*softc
)
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
196 * ks - keyboard state
197 * leds - new LED state
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));
216 /* *********************************************************************
217 * pcconsole_probe(drv,probe_a,probe_b,probe_ptr)
219 * Probe routine. This routine sets up the pcconsole device
222 * drv - driver structure
229 ********************************************************************* */
231 static void pcconsole_probe(cfe_driver_t
*drv
,
232 unsigned long probe_a
, unsigned long probe_b
,
237 volatile uint8_t *isamem
;
245 softc
= (pcconsole_t
*) KMALLOC(sizeof(pcconsole_t
),0);
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);
273 static int pcconsole_read(cfe_devctx_t
*ctx
,iocb_buffer_t
*buffer
)
275 pcconsole_t
*softc
= ctx
->dev_softc
;
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);
289 buffer
->buf_retlen
= buffer
->buf_length
- blen
;
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;
304 static int pcconsole_write(cfe_devctx_t
*ctx
,iocb_buffer_t
*buffer
)
306 pcconsole_t
*softc
= ctx
->dev_softc
;
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
;
319 static int pcconsole_ioctl(cfe_devctx_t
*ctx
,iocb_buffer_t
*buffer
)
321 /* pcconsole_t *softc = ctx->dev_softc;*/
326 static int pcconsole_close(cfe_devctx_t
*ctx
)
328 /* pcconsole_t *softc = ctx->dev_softc;*/