Rev 3924 | Rev 4026 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 3924 | Rev 3947 | ||
---|---|---|---|
1 | /* |
1 | /* |
2 | * Copyright (c) 2001-2004 Jakub Jermar |
2 | * Copyright (c) 2001-2004 Jakub Jermar |
3 | * Copyright (c) 2006 Josef Cejka |
3 | * Copyright (c) 2006 Josef Cejka |
4 | * All rights reserved. |
4 | * All rights reserved. |
5 | * |
5 | * |
6 | * Redistribution and use in source and binary forms, with or without |
6 | * Redistribution and use in source and binary forms, with or without |
7 | * modification, are permitted provided that the following conditions |
7 | * modification, are permitted provided that the following conditions |
8 | * are met: |
8 | * are met: |
9 | * |
9 | * |
10 | * - Redistributions of source code must retain the above copyright |
10 | * - Redistributions of source code must retain the above copyright |
11 | * notice, this list of conditions and the following disclaimer. |
11 | * notice, this list of conditions and the following disclaimer. |
12 | * - Redistributions in binary form must reproduce the above copyright |
12 | * - Redistributions in binary form must reproduce the above copyright |
13 | * notice, this list of conditions and the following disclaimer in the |
13 | * notice, this list of conditions and the following disclaimer in the |
14 | * documentation and/or other materials provided with the distribution. |
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 |
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. |
16 | * derived from this software without specific prior written permission. |
17 | * |
17 | * |
18 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
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 |
19 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
20 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
20 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
21 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
21 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
22 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
22 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
23 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
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 |
24 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
25 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
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 |
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. |
27 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
28 | */ |
28 | */ |
29 | 29 | ||
30 | /** @addtogroup kbd_port |
30 | /** @addtogroup kbd_port |
31 | * @ingroup kbd |
31 | * @ingroup kbd |
32 | * @{ |
32 | * @{ |
33 | */ |
33 | */ |
34 | /** @file |
34 | /** @file |
35 | * @brief i8042 port driver. |
35 | * @brief i8042 port driver. |
36 | */ |
36 | */ |
37 | 37 | ||
38 | #include <ipc/ipc.h> |
38 | #include <ipc/ipc.h> |
39 | #include <async.h> |
39 | #include <async.h> |
40 | #include <unistd.h> |
40 | #include <unistd.h> |
41 | #include <sysinfo.h> |
41 | #include <sysinfo.h> |
42 | #include <kbd_port.h> |
42 | #include <kbd_port.h> |
43 | #include <kbd.h> |
43 | #include <kbd.h> |
44 | #include "i8042.h" |
44 | #include "i8042.h" |
45 | 45 | ||
46 | /* Interesting bits for status register */ |
46 | /* Interesting bits for status register */ |
47 | #define i8042_OUTPUT_FULL 0x1 |
47 | #define i8042_OUTPUT_FULL 0x1 |
48 | #define i8042_INPUT_FULL 0x2 |
48 | #define i8042_INPUT_FULL 0x2 |
49 | #define i8042_MOUSE_DATA 0x20 |
49 | #define i8042_MOUSE_DATA 0x20 |
50 | 50 | ||
51 | /* Command constants */ |
51 | /* Command constants */ |
52 | #define i8042_CMD_KBD 0x60 |
52 | #define i8042_CMD_KBD 0x60 |
53 | #define i8042_CMD_MOUSE 0xd4 |
53 | #define i8042_CMD_MOUSE 0xd4 |
54 | 54 | ||
55 | /* Keyboard cmd byte */ |
55 | /* Keyboard cmd byte */ |
56 | #define i8042_KBD_IE 0x1 |
56 | #define i8042_KBD_IE 0x1 |
57 | #define i8042_MOUSE_IE 0x2 |
57 | #define i8042_MOUSE_IE 0x2 |
58 | #define i8042_KBD_DISABLE 0x10 |
58 | #define i8042_KBD_DISABLE 0x10 |
59 | #define i8042_MOUSE_DISABLE 0x20 |
59 | #define i8042_MOUSE_DISABLE 0x20 |
60 | #define i8042_KBD_TRANSLATE 0x40 |
60 | #define i8042_KBD_TRANSLATE 0x40 |
61 | 61 | ||
62 | /* Mouse constants */ |
62 | /* Mouse constants */ |
63 | #define MOUSE_OUT_INIT 0xf4 |
63 | #define MOUSE_OUT_INIT 0xf4 |
64 | #define MOUSE_ACK 0xfa |
64 | #define MOUSE_ACK 0xfa |
65 | 65 | ||
66 | static irq_cmd_t i8042_cmds[2] = { |
66 | static irq_cmd_t i8042_cmds[] = { |
- | 67 | { |
|
- | 68 | .cmd = CMD_PIO_READ_8, |
|
67 | { CMD_PORT_READ_1, (void *) 0x64, 0, 1 }, |
69 | .addr = (void *) 0x64, |
- | 70 | .dstarg = 1 |
|
- | 71 | }, |
|
- | 72 | { |
|
- | 73 | .cmd = CMD_BTEST, |
|
- | 74 | .value = i8042_OUTPUT_FULL, |
|
- | 75 | .srcarg = 1, |
|
- | 76 | .dstarg = 3 |
|
- | 77 | }, |
|
- | 78 | { |
|
- | 79 | .cmd = CMD_PREDICATE, |
|
- | 80 | .value = 2, |
|
- | 81 | .srcarg = 3 |
|
- | 82 | }, |
|
- | 83 | { |
|
- | 84 | .cmd = CMD_PIO_READ_8, |
|
68 | { CMD_PORT_READ_1, (void *) 0x60, 0, 2 } |
85 | .addr = (void *) 0x60, |
- | 86 | .dstarg = 2 |
|
- | 87 | }, |
|
- | 88 | { |
|
- | 89 | .cmd = CMD_ACCEPT |
|
- | 90 | } |
|
69 | }; |
91 | }; |
70 | 92 | ||
71 | static irq_code_t i8042_kbd = { |
93 | static irq_code_t i8042_kbd = { |
72 | 2, |
94 | sizeof(i8042_cmds) / sizeof(irq_cmd_t), |
73 | i8042_cmds |
95 | i8042_cmds |
74 | }; |
96 | }; |
75 | 97 | ||
76 | static void wait_ready(void) { |
98 | static void wait_ready(void) { |
77 | while (i8042_status_read() & i8042_INPUT_FULL) |
99 | while (i8042_status_read() & i8042_INPUT_FULL) |
78 | ; |
100 | ; |
79 | } |
101 | } |
80 | 102 | ||
81 | static void i8042_irq_handler(ipc_callid_t iid, ipc_call_t *call); |
103 | static void i8042_irq_handler(ipc_callid_t iid, ipc_call_t *call); |
82 | 104 | ||
83 | int kbd_port_init(void) |
105 | int kbd_port_init(void) |
84 | { |
106 | { |
85 | // int i; |
107 | // int i; |
86 | int mouseenabled = 0; |
108 | int mouseenabled = 0; |
87 | 109 | ||
88 | async_set_interrupt_received(i8042_irq_handler); |
110 | async_set_interrupt_received(i8042_irq_handler); |
89 | iospace_enable(task_get_id(), (void *) i8042_DATA, 5); |
111 | iospace_enable(task_get_id(), (void *) i8042_DATA, 5); |
90 | 112 | ||
91 | /* Disable kbd, enable mouse */ |
113 | /* Disable kbd, enable mouse */ |
92 | i8042_command_write(i8042_CMD_KBD); |
114 | i8042_command_write(i8042_CMD_KBD); |
93 | wait_ready(); |
115 | wait_ready(); |
94 | i8042_command_write(i8042_CMD_KBD); |
116 | i8042_command_write(i8042_CMD_KBD); |
95 | wait_ready(); |
117 | wait_ready(); |
96 | i8042_data_write(i8042_KBD_DISABLE); |
118 | i8042_data_write(i8042_KBD_DISABLE); |
97 | wait_ready(); |
119 | wait_ready(); |
98 | 120 | ||
99 | /* Flush all current IO */ |
121 | /* Flush all current IO */ |
100 | while (i8042_status_read() & i8042_OUTPUT_FULL) |
122 | while (i8042_status_read() & i8042_OUTPUT_FULL) |
101 | i8042_data_read(); |
123 | i8042_data_read(); |
102 | 124 | ||
103 | /* Initialize mouse */ |
125 | /* Initialize mouse */ |
104 | /* i8042_command_write(i8042_CMD_MOUSE); |
126 | /* i8042_command_write(i8042_CMD_MOUSE); |
105 | wait_ready(); |
127 | wait_ready(); |
106 | i8042_data_write(MOUSE_OUT_INIT); |
128 | i8042_data_write(MOUSE_OUT_INIT); |
107 | wait_ready(); |
129 | wait_ready(); |
108 | |
130 | |
109 | int mouseanswer = 0; |
131 | int mouseanswer = 0; |
110 | for (i=0;i < 1000; i++) { |
132 | for (i=0;i < 1000; i++) { |
111 | int status = i8042_status_read(); |
133 | int status = i8042_status_read(); |
112 | if (status & i8042_OUTPUT_FULL) { |
134 | if (status & i8042_OUTPUT_FULL) { |
113 | int data = i8042_data_read(); |
135 | int data = i8042_data_read(); |
114 | if (status & i8042_MOUSE_DATA) { |
136 | if (status & i8042_MOUSE_DATA) { |
115 | mouseanswer = data; |
137 | mouseanswer = data; |
116 | break; |
138 | break; |
117 | } |
139 | } |
118 | } |
140 | } |
119 | usleep(1000); |
141 | usleep(1000); |
120 | }*/ |
142 | }*/ |
121 | // if (mouseanswer == MOUSE_ACK) { |
143 | // if (mouseanswer == MOUSE_ACK) { |
122 | // /* enable mouse */ |
144 | // /* enable mouse */ |
123 | // mouseenabled = 1; |
145 | // mouseenabled = 1; |
124 | // |
146 | // |
125 | // ipc_register_irq(sysinfo_value("mouse.inr"), sysinfo_value("mouse.devno"), 0, &i8042_kbd); |
147 | // ipc_register_irq(sysinfo_value("mouse.inr"), sysinfo_value("mouse.devno"), 0, &i8042_kbd); |
126 | // } |
148 | // } |
127 | 149 | ||
128 | /* Enable kbd */ |
150 | /* Enable kbd */ |
129 | ipc_register_irq(sysinfo_value("kbd.inr"), sysinfo_value("kbd.devno"), 0, &i8042_kbd); |
151 | ipc_register_irq(sysinfo_value("kbd.inr"), sysinfo_value("kbd.devno"), 0, &i8042_kbd); |
130 | 152 | ||
131 | int newcontrol = i8042_KBD_IE | i8042_KBD_TRANSLATE; |
153 | int newcontrol = i8042_KBD_IE | i8042_KBD_TRANSLATE; |
132 | if (mouseenabled) |
154 | if (mouseenabled) |
133 | newcontrol |= i8042_MOUSE_IE; |
155 | newcontrol |= i8042_MOUSE_IE; |
134 | 156 | ||
135 | i8042_command_write(i8042_CMD_KBD); |
157 | i8042_command_write(i8042_CMD_KBD); |
136 | wait_ready(); |
158 | wait_ready(); |
137 | i8042_data_write(newcontrol); |
159 | i8042_data_write(newcontrol); |
138 | wait_ready(); |
160 | wait_ready(); |
139 | 161 | ||
140 | return 0; |
162 | return 0; |
141 | } |
163 | } |
142 | 164 | ||
143 | static void i8042_irq_handler(ipc_callid_t iid, ipc_call_t *call) |
165 | static void i8042_irq_handler(ipc_callid_t iid, ipc_call_t *call) |
144 | { |
166 | { |
145 | int status = IPC_GET_ARG1(*call); |
167 | int status = IPC_GET_ARG1(*call); |
146 | 168 | ||
147 | if ((status & i8042_MOUSE_DATA)) |
169 | if ((status & i8042_MOUSE_DATA)) |
148 | return 0; |
170 | return 0; |
149 | 171 | ||
150 | int scan_code = IPC_GET_ARG2(*call); |
172 | int scan_code = IPC_GET_ARG2(*call); |
151 | 173 | ||
152 | kbd_push_scancode(scan_code); |
174 | kbd_push_scancode(scan_code); |
153 | return 1; |
175 | return 1; |
154 | } |
176 | } |
155 | 177 | ||
156 | /** |
178 | /** |
157 | * @} |
179 | * @} |
158 | */ |
180 | */ |
159 | 181 |