Rev 3923 | Rev 4343 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 3923 | Rev 3924 | ||
---|---|---|---|
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 |
30 | /** @addtogroup kbd_port |
- | 31 | * @ingroup kbd |
|
31 | * @{ |
32 | * @{ |
32 | */ |
33 | */ |
33 | /** @file |
34 | /** @file |
- | 35 | * @brief i8042 port driver. |
|
34 | */ |
36 | */ |
35 | 37 | ||
36 | #include <ipc/ipc.h> |
38 | #include <ipc/ipc.h> |
37 | #include <async.h> |
39 | #include <async.h> |
38 | #include <unistd.h> |
40 | #include <unistd.h> |
39 | #include <sysinfo.h> |
41 | #include <sysinfo.h> |
40 | #include <kbd_port.h> |
42 | #include <kbd_port.h> |
41 | #include <kbd.h> |
43 | #include <kbd.h> |
42 | #include "i8042.h" |
44 | #include "i8042.h" |
43 | 45 | ||
44 | /* Interesting bits for status register */ |
46 | /* Interesting bits for status register */ |
45 | #define i8042_OUTPUT_FULL 0x1 |
47 | #define i8042_OUTPUT_FULL 0x1 |
46 | #define i8042_INPUT_FULL 0x2 |
48 | #define i8042_INPUT_FULL 0x2 |
47 | #define i8042_MOUSE_DATA 0x20 |
49 | #define i8042_MOUSE_DATA 0x20 |
48 | 50 | ||
49 | /* Command constants */ |
51 | /* Command constants */ |
50 | #define i8042_CMD_KBD 0x60 |
52 | #define i8042_CMD_KBD 0x60 |
51 | #define i8042_CMD_MOUSE 0xd4 |
53 | #define i8042_CMD_MOUSE 0xd4 |
52 | 54 | ||
53 | /* Keyboard cmd byte */ |
55 | /* Keyboard cmd byte */ |
54 | #define i8042_KBD_IE 0x1 |
56 | #define i8042_KBD_IE 0x1 |
55 | #define i8042_MOUSE_IE 0x2 |
57 | #define i8042_MOUSE_IE 0x2 |
56 | #define i8042_KBD_DISABLE 0x10 |
58 | #define i8042_KBD_DISABLE 0x10 |
57 | #define i8042_MOUSE_DISABLE 0x20 |
59 | #define i8042_MOUSE_DISABLE 0x20 |
58 | #define i8042_KBD_TRANSLATE 0x40 |
60 | #define i8042_KBD_TRANSLATE 0x40 |
59 | 61 | ||
60 | /* Mouse constants */ |
62 | /* Mouse constants */ |
61 | #define MOUSE_OUT_INIT 0xf4 |
63 | #define MOUSE_OUT_INIT 0xf4 |
62 | #define MOUSE_ACK 0xfa |
64 | #define MOUSE_ACK 0xfa |
63 | 65 | ||
64 | static irq_cmd_t i8042_cmds[2] = { |
66 | static irq_cmd_t i8042_cmds[2] = { |
65 | { CMD_PORT_READ_1, (void *) 0x64, 0, 1 }, |
67 | { CMD_PORT_READ_1, (void *) 0x64, 0, 1 }, |
66 | { CMD_PORT_READ_1, (void *) 0x60, 0, 2 } |
68 | { CMD_PORT_READ_1, (void *) 0x60, 0, 2 } |
67 | }; |
69 | }; |
68 | 70 | ||
69 | static irq_code_t i8042_kbd = { |
71 | static irq_code_t i8042_kbd = { |
70 | 2, |
72 | 2, |
71 | i8042_cmds |
73 | i8042_cmds |
72 | }; |
74 | }; |
73 | 75 | ||
74 | static void wait_ready(void) { |
76 | static void wait_ready(void) { |
75 | while (i8042_status_read() & i8042_INPUT_FULL) |
77 | while (i8042_status_read() & i8042_INPUT_FULL) |
76 | ; |
78 | ; |
77 | } |
79 | } |
78 | 80 | ||
79 | static void i8042_irq_handler(ipc_callid_t iid, ipc_call_t *call); |
81 | static void i8042_irq_handler(ipc_callid_t iid, ipc_call_t *call); |
80 | 82 | ||
81 | int kbd_port_init(void) |
83 | int kbd_port_init(void) |
82 | { |
84 | { |
83 | // int i; |
85 | // int i; |
84 | int mouseenabled = 0; |
86 | int mouseenabled = 0; |
85 | 87 | ||
86 | async_set_interrupt_received(i8042_irq_handler); |
88 | async_set_interrupt_received(i8042_irq_handler); |
87 | iospace_enable(task_get_id(), (void *) i8042_DATA, 5); |
89 | iospace_enable(task_get_id(), (void *) i8042_DATA, 5); |
88 | 90 | ||
89 | /* Disable kbd, enable mouse */ |
91 | /* Disable kbd, enable mouse */ |
90 | i8042_command_write(i8042_CMD_KBD); |
92 | i8042_command_write(i8042_CMD_KBD); |
91 | wait_ready(); |
93 | wait_ready(); |
92 | i8042_command_write(i8042_CMD_KBD); |
94 | i8042_command_write(i8042_CMD_KBD); |
93 | wait_ready(); |
95 | wait_ready(); |
94 | i8042_data_write(i8042_KBD_DISABLE); |
96 | i8042_data_write(i8042_KBD_DISABLE); |
95 | wait_ready(); |
97 | wait_ready(); |
96 | 98 | ||
97 | /* Flush all current IO */ |
99 | /* Flush all current IO */ |
98 | while (i8042_status_read() & i8042_OUTPUT_FULL) |
100 | while (i8042_status_read() & i8042_OUTPUT_FULL) |
99 | i8042_data_read(); |
101 | i8042_data_read(); |
100 | 102 | ||
101 | /* Initialize mouse */ |
103 | /* Initialize mouse */ |
102 | /* i8042_command_write(i8042_CMD_MOUSE); |
104 | /* i8042_command_write(i8042_CMD_MOUSE); |
103 | wait_ready(); |
105 | wait_ready(); |
104 | i8042_data_write(MOUSE_OUT_INIT); |
106 | i8042_data_write(MOUSE_OUT_INIT); |
105 | wait_ready(); |
107 | wait_ready(); |
106 | |
108 | |
107 | int mouseanswer = 0; |
109 | int mouseanswer = 0; |
108 | for (i=0;i < 1000; i++) { |
110 | for (i=0;i < 1000; i++) { |
109 | int status = i8042_status_read(); |
111 | int status = i8042_status_read(); |
110 | if (status & i8042_OUTPUT_FULL) { |
112 | if (status & i8042_OUTPUT_FULL) { |
111 | int data = i8042_data_read(); |
113 | int data = i8042_data_read(); |
112 | if (status & i8042_MOUSE_DATA) { |
114 | if (status & i8042_MOUSE_DATA) { |
113 | mouseanswer = data; |
115 | mouseanswer = data; |
114 | break; |
116 | break; |
115 | } |
117 | } |
116 | } |
118 | } |
117 | usleep(1000); |
119 | usleep(1000); |
118 | }*/ |
120 | }*/ |
119 | // if (mouseanswer == MOUSE_ACK) { |
121 | // if (mouseanswer == MOUSE_ACK) { |
120 | // /* enable mouse */ |
122 | // /* enable mouse */ |
121 | // mouseenabled = 1; |
123 | // mouseenabled = 1; |
122 | // |
124 | // |
123 | // ipc_register_irq(sysinfo_value("mouse.inr"), sysinfo_value("mouse.devno"), 0, &i8042_kbd); |
125 | // ipc_register_irq(sysinfo_value("mouse.inr"), sysinfo_value("mouse.devno"), 0, &i8042_kbd); |
124 | // } |
126 | // } |
125 | 127 | ||
126 | /* Enable kbd */ |
128 | /* Enable kbd */ |
127 | ipc_register_irq(sysinfo_value("kbd.inr"), sysinfo_value("kbd.devno"), 0, &i8042_kbd); |
129 | ipc_register_irq(sysinfo_value("kbd.inr"), sysinfo_value("kbd.devno"), 0, &i8042_kbd); |
128 | 130 | ||
129 | int newcontrol = i8042_KBD_IE | i8042_KBD_TRANSLATE; |
131 | int newcontrol = i8042_KBD_IE | i8042_KBD_TRANSLATE; |
130 | if (mouseenabled) |
132 | if (mouseenabled) |
131 | newcontrol |= i8042_MOUSE_IE; |
133 | newcontrol |= i8042_MOUSE_IE; |
132 | 134 | ||
133 | i8042_command_write(i8042_CMD_KBD); |
135 | i8042_command_write(i8042_CMD_KBD); |
134 | wait_ready(); |
136 | wait_ready(); |
135 | i8042_data_write(newcontrol); |
137 | i8042_data_write(newcontrol); |
136 | wait_ready(); |
138 | wait_ready(); |
137 | 139 | ||
138 | return 0; |
140 | return 0; |
139 | } |
141 | } |
140 | 142 | ||
141 | static void i8042_irq_handler(ipc_callid_t iid, ipc_call_t *call) |
143 | static void i8042_irq_handler(ipc_callid_t iid, ipc_call_t *call) |
142 | { |
144 | { |
143 | int status = IPC_GET_ARG1(*call); |
145 | int status = IPC_GET_ARG1(*call); |
144 | 146 | ||
145 | if ((status & i8042_MOUSE_DATA)) |
147 | if ((status & i8042_MOUSE_DATA)) |
146 | return 0; |
148 | return 0; |
147 | 149 | ||
148 | int scan_code = IPC_GET_ARG2(*call); |
150 | int scan_code = IPC_GET_ARG2(*call); |
149 | 151 | ||
150 | kbd_push_scancode(scan_code); |
152 | kbd_push_scancode(scan_code); |
151 | return 1; |
153 | return 1; |
152 | } |
154 | } |
153 | 155 | ||
154 | /** |
156 | /** |
155 | * @} |
157 | * @} |
156 | */ |
158 | */ |
157 | 159 |