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