2
* Copyright (c) 2001-2004 Jakub Jermar
3
* Copyright (c) 2006 Josef Cejka
6
* Redistribution and use in source and binary forms, with or without
7
* modification, are permitted provided that the following conditions
10
* - Redistributions of source code must retain the above copyright
11
* notice, this list of conditions and the following disclaimer.
12
* - Redistributions in binary form must reproduce the above copyright
13
* notice, this list of conditions and the following disclaimer in the
14
* documentation and/or other materials provided with the distribution.
15
* - The name of the author may not be used to endorse or promote products
16
* derived from this software without specific prior written permission.
18
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30
/** @addtogroup kbd_port
35
* @brief i8042 port driver.
39
#include <libarch/ddi.h>
49
/* Interesting bits for status register */
50
#define i8042_OUTPUT_FULL 0x1
51
#define i8042_INPUT_FULL 0x2
52
#define i8042_MOUSE_DATA 0x20
54
/* Command constants */
55
#define i8042_CMD_KBD 0x60
56
#define i8042_CMD_MOUSE 0xd4
58
/* Keyboard cmd byte */
59
#define i8042_KBD_IE 0x1
60
#define i8042_MOUSE_IE 0x2
61
#define i8042_KBD_DISABLE 0x10
62
#define i8042_MOUSE_DISABLE 0x20
63
#define i8042_KBD_TRANSLATE 0x40
66
#define MOUSE_OUT_INIT 0xf4
67
#define MOUSE_ACK 0xfa
69
static irq_cmd_t i8042_cmds[] = {
71
.cmd = CMD_PIO_READ_8,
72
.addr = NULL, /* will be patched in run-time */
77
.value = i8042_OUTPUT_FULL,
87
.cmd = CMD_PIO_READ_8,
88
.addr = NULL, /* will be patched in run-time */
96
static irq_code_t i8042_kbd = {
97
sizeof(i8042_cmds) / sizeof(irq_cmd_t),
101
static uintptr_t i8042_physical;
102
static uintptr_t i8042_kernel;
103
static i8042_t * i8042;
105
static void wait_ready(void) {
106
while (pio_read_8(&i8042->status) & i8042_INPUT_FULL)
110
static void i8042_irq_handler(ipc_callid_t iid, ipc_call_t *call);
112
int kbd_port_init(void)
114
int mouseenabled = 0;
117
i8042_physical = sysinfo_value("kbd.address.physical");
118
i8042_kernel = sysinfo_value("kbd.address.kernel");
119
if (pio_enable((void *) i8042_physical, sizeof(i8042_t), &vaddr) != 0)
123
async_set_interrupt_received(i8042_irq_handler);
125
/* Disable kbd, enable mouse */
126
pio_write_8(&i8042->status, i8042_CMD_KBD);
128
pio_write_8(&i8042->status, i8042_CMD_KBD);
130
pio_write_8(&i8042->data, i8042_KBD_DISABLE);
133
/* Flush all current IO */
134
while (pio_read_8(&i8042->status) & i8042_OUTPUT_FULL)
135
(void) pio_read_8(&i8042->data);
138
i8042_kbd.cmds[0].addr = (void *) &((i8042_t *) i8042_kernel)->status;
139
i8042_kbd.cmds[3].addr = (void *) &((i8042_t *) i8042_kernel)->data;
140
ipc_register_irq(sysinfo_value("kbd.inr"), device_assign_devno(), 0, &i8042_kbd);
142
int newcontrol = i8042_KBD_IE | i8042_KBD_TRANSLATE;
144
newcontrol |= i8042_MOUSE_IE;
146
pio_write_8(&i8042->status, i8042_CMD_KBD);
148
pio_write_8(&i8042->data, newcontrol);
154
void kbd_port_yield(void)
158
void kbd_port_reclaim(void)
162
static void i8042_irq_handler(ipc_callid_t iid, ipc_call_t *call)
164
int status = IPC_GET_ARG1(*call);
166
if ((status & i8042_MOUSE_DATA))
169
int scan_code = IPC_GET_ARG2(*call);
171
kbd_push_scancode(scan_code);