Rev 3947 | Rev 4148 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 3947 | Rev 4026 | ||
---|---|---|---|
Line 33... | Line 33... | ||
33 | */ |
33 | */ |
34 | /** @file |
34 | /** @file |
35 | * @brief i8042 port driver. |
35 | * @brief i8042 port driver. |
36 | */ |
36 | */ |
37 | 37 | ||
- | 38 | #include <ddi.h> |
|
- | 39 | #include <libarch/ddi.h> |
|
38 | #include <ipc/ipc.h> |
40 | #include <ipc/ipc.h> |
39 | #include <async.h> |
41 | #include <async.h> |
40 | #include <unistd.h> |
42 | #include <unistd.h> |
41 | #include <sysinfo.h> |
43 | #include <sysinfo.h> |
42 | #include <kbd_port.h> |
44 | #include <kbd_port.h> |
Line 64... | Line 66... | ||
64 | #define MOUSE_ACK 0xfa |
66 | #define MOUSE_ACK 0xfa |
65 | 67 | ||
66 | static irq_cmd_t i8042_cmds[] = { |
68 | static irq_cmd_t i8042_cmds[] = { |
67 | { |
69 | { |
68 | .cmd = CMD_PIO_READ_8, |
70 | .cmd = CMD_PIO_READ_8, |
69 | .addr = (void *) 0x64, |
71 | .addr = NULL, /* will be patched in run-time */ |
70 | .dstarg = 1 |
72 | .dstarg = 1 |
71 | }, |
73 | }, |
72 | { |
74 | { |
73 | .cmd = CMD_BTEST, |
75 | .cmd = CMD_BTEST, |
74 | .value = i8042_OUTPUT_FULL, |
76 | .value = i8042_OUTPUT_FULL, |
Line 80... | Line 82... | ||
80 | .value = 2, |
82 | .value = 2, |
81 | .srcarg = 3 |
83 | .srcarg = 3 |
82 | }, |
84 | }, |
83 | { |
85 | { |
84 | .cmd = CMD_PIO_READ_8, |
86 | .cmd = CMD_PIO_READ_8, |
85 | .addr = (void *) 0x60, |
87 | .addr = NULL, /* will be patched in run-time */ |
86 | .dstarg = 2 |
88 | .dstarg = 2 |
87 | }, |
89 | }, |
88 | { |
90 | { |
89 | .cmd = CMD_ACCEPT |
91 | .cmd = CMD_ACCEPT |
90 | } |
92 | } |
Line 93... | Line 95... | ||
93 | static irq_code_t i8042_kbd = { |
95 | static irq_code_t i8042_kbd = { |
94 | sizeof(i8042_cmds) / sizeof(irq_cmd_t), |
96 | sizeof(i8042_cmds) / sizeof(irq_cmd_t), |
95 | i8042_cmds |
97 | i8042_cmds |
96 | }; |
98 | }; |
97 | 99 | ||
- | 100 | static uintptr_t i8042_physical; |
|
- | 101 | static uintptr_t i8042_kernel; |
|
- | 102 | static i8042_t * i8042; |
|
- | 103 | ||
98 | static void wait_ready(void) { |
104 | static void wait_ready(void) { |
99 | while (i8042_status_read() & i8042_INPUT_FULL) |
105 | while (pio_read_8(&i8042->status) & i8042_INPUT_FULL) |
100 | ; |
106 | ; |
101 | } |
107 | } |
102 | 108 | ||
103 | static void i8042_irq_handler(ipc_callid_t iid, ipc_call_t *call); |
109 | static void i8042_irq_handler(ipc_callid_t iid, ipc_call_t *call); |
104 | 110 | ||
105 | int kbd_port_init(void) |
111 | int kbd_port_init(void) |
106 | { |
112 | { |
107 | // int i; |
- | |
108 | int mouseenabled = 0; |
113 | int mouseenabled = 0; |
- | 114 | void *vaddr; |
|
- | 115 | ||
- | 116 | i8042_physical = sysinfo_value("kbd.address.physical"); |
|
- | 117 | i8042_kernel = sysinfo_value("kbd.address.kernel"); |
|
- | 118 | if (pio_enable((void *) i8042_physical, sizeof(i8042_t), &vaddr) != 0) |
|
- | 119 | return -1; |
|
- | 120 | i8042 = vaddr; |
|
109 | 121 | ||
110 | async_set_interrupt_received(i8042_irq_handler); |
122 | async_set_interrupt_received(i8042_irq_handler); |
111 | iospace_enable(task_get_id(), (void *) i8042_DATA, 5); |
- | |
112 | 123 | ||
113 | /* Disable kbd, enable mouse */ |
124 | /* Disable kbd, enable mouse */ |
114 | i8042_command_write(i8042_CMD_KBD); |
125 | pio_write_8(&i8042->status, i8042_CMD_KBD); |
115 | wait_ready(); |
126 | wait_ready(); |
116 | i8042_command_write(i8042_CMD_KBD); |
127 | pio_write_8(&i8042->status, i8042_CMD_KBD); |
117 | wait_ready(); |
128 | wait_ready(); |
118 | i8042_data_write(i8042_KBD_DISABLE); |
129 | pio_write_8(&i8042->data, i8042_KBD_DISABLE); |
119 | wait_ready(); |
130 | wait_ready(); |
120 | 131 | ||
121 | /* Flush all current IO */ |
132 | /* Flush all current IO */ |
122 | while (i8042_status_read() & i8042_OUTPUT_FULL) |
133 | while (pio_read_8(&i8042->status) & i8042_OUTPUT_FULL) |
123 | i8042_data_read(); |
- | |
124 | - | ||
125 | /* Initialize mouse */ |
- | |
126 | /* i8042_command_write(i8042_CMD_MOUSE); |
134 | (void) pio_read_8(&i8042->data); |
127 | wait_ready(); |
- | |
128 | i8042_data_write(MOUSE_OUT_INIT); |
- | |
129 | wait_ready(); |
- | |
130 | |
135 | |
131 | int mouseanswer = 0; |
- | |
132 | for (i=0;i < 1000; i++) { |
- | |
133 | int status = i8042_status_read(); |
- | |
134 | if (status & i8042_OUTPUT_FULL) { |
- | |
135 | int data = i8042_data_read(); |
- | |
136 | if (status & i8042_MOUSE_DATA) { |
- | |
137 | mouseanswer = data; |
- | |
138 | break; |
- | |
139 | } |
- | |
140 | } |
- | |
141 | usleep(1000); |
- | |
142 | }*/ |
- | |
143 | // if (mouseanswer == MOUSE_ACK) { |
- | |
144 | // /* enable mouse */ |
- | |
145 | // mouseenabled = 1; |
- | |
146 | // |
- | |
147 | // ipc_register_irq(sysinfo_value("mouse.inr"), sysinfo_value("mouse.devno"), 0, &i8042_kbd); |
- | |
148 | // } |
- | |
149 | - | ||
150 | /* Enable kbd */ |
136 | /* Enable kbd */ |
- | 137 | i8042_kbd.cmds[0].addr = &((i8042_t *) i8042_kernel)->status; |
|
- | 138 | i8042_kbd.cmds[3].addr = &((i8042_t *) i8042_kernel)->data; |
|
151 | ipc_register_irq(sysinfo_value("kbd.inr"), sysinfo_value("kbd.devno"), 0, &i8042_kbd); |
139 | ipc_register_irq(sysinfo_value("kbd.inr"), sysinfo_value("kbd.devno"), 0, &i8042_kbd); |
152 | 140 | ||
153 | int newcontrol = i8042_KBD_IE | i8042_KBD_TRANSLATE; |
141 | int newcontrol = i8042_KBD_IE | i8042_KBD_TRANSLATE; |
154 | if (mouseenabled) |
142 | if (mouseenabled) |
155 | newcontrol |= i8042_MOUSE_IE; |
143 | newcontrol |= i8042_MOUSE_IE; |
156 | 144 | ||
157 | i8042_command_write(i8042_CMD_KBD); |
145 | pio_write_8(&i8042->status, i8042_CMD_KBD); |
158 | wait_ready(); |
146 | wait_ready(); |
159 | i8042_data_write(newcontrol); |
147 | pio_write_8(&i8042->data, newcontrol); |
160 | wait_ready(); |
148 | wait_ready(); |
161 | 149 | ||
162 | return 0; |
150 | return 0; |
163 | } |
151 | } |
164 | 152 | ||
165 | static void i8042_irq_handler(ipc_callid_t iid, ipc_call_t *call) |
153 | static void i8042_irq_handler(ipc_callid_t iid, ipc_call_t *call) |
166 | { |
154 | { |
167 | int status = IPC_GET_ARG1(*call); |
155 | int status = IPC_GET_ARG1(*call); |
168 | 156 | ||
169 | if ((status & i8042_MOUSE_DATA)) |
157 | if ((status & i8042_MOUSE_DATA)) |
170 | return 0; |
158 | return; |
171 | 159 | ||
172 | int scan_code = IPC_GET_ARG2(*call); |
160 | int scan_code = IPC_GET_ARG2(*call); |
173 | 161 | ||
174 | kbd_push_scancode(scan_code); |
162 | kbd_push_scancode(scan_code); |
175 | return 1; |
163 | return; |
176 | } |
164 | } |
177 | 165 | ||
178 | /** |
166 | /** |
179 | * @} |
167 | * @} |
180 | */ |
168 | */ |