@@ -183,128 +183,11 @@ int keyboard_get_kbhit() {
183183}
184184
185185void keyboard_init () {
186- unsigned char original_colors = get_color_fgbg ();
187- sleep_mini (3000000 );
188-
189186 unsigned char out ;
190- // disable PS/2 first port
191- ps2_controller_send_command (0XAD , 0 );
192- // disable PS/2 second port
193- ps2_controller_send_command (0XA7 , 0 );
194- // flush output buffer
195- wait_for_status_flag (STATUS_OUTPUT_BUFFER , 0 );
196-
197- out = ps2_controller_send_command (0X20 , 1 );
198- out = out & (~0b1000011 );
199- int dual_ps2_controller = 0 ;
200- if (out & (0b10000 )) {
201- dual_ps2_controller = 1 ;
202- }
203- print_log ("Init: Maybe dual PS2 Controller" , dual_ps2_controller );
204- ps2_controller_send_command_with_data (0x60 , out , 0 );
205-
206-
207- out = ps2_controller_send_command (0XAA , 1 );
208- if (out != 0x55 ) {
209- PANIC (out , "PS2 controller self test failed." );
210- }
211-
212- if (dual_ps2_controller ) {
213- ps2_controller_send_command (0XA8 , 0 );
214- out = ps2_controller_send_command (0X20 , 1 );
215- if (!(out & (0b10000 ))) {
216- dual_ps2_controller = 0 ;
217- print_log ("Init: Enabling PS2 port failed, thus disabling dual_ps2_controller" );
218- } else {
219- // disabling second port again.
220- ps2_controller_send_command (0xA7 , 0 );
221- }
222- }
223-
224- out = ps2_controller_send_command (0XAB , 1 );
225- if (out != 0x00 ) {
226- PANIC (out , "PS2 first port test failed." );
227- }
228- if (dual_ps2_controller ) {
229- out = ps2_controller_send_command (0XA9 , 1 );
230- if (out != 0x00 ) {
231- PANIC (out , "PS2 second port test failed." );
232- }
233- }
234-
235- print_log ("Init: Dual PS2 Controller: %d" , dual_ps2_controller );
236-
237- // enable first port
238- ps2_controller_send_command (0xAE , 0 );
239- if (dual_ps2_controller ) {
240- // enable second port
241- ps2_controller_send_command (0xA8 , 0 );
242- }
243-
187+ // disable scanning
244188 out = write_to_ps2_first_port (0xF5 , 1 );
245189 if (out != 0xFA ) {
246- PANIC (out , "disable scanning failed." );
247- }
248-
249- // enable interrupts
250- out = ps2_controller_send_command (0X20 , 1 );
251- out |= 0b11 ;
252- ps2_controller_send_command_with_data (0x60 , out , 0 );
253-
254-
255- // reset device
256- out = write_to_ps2_first_port (0xFF , 1 );
257- if (out != 0xFA ) {
258- PANIC (out , "reset ps/2 first failed" );
259- }
260- out = read_data_reply ();
261- if (out != 0xAA ) {
262- PANIC (out , "reset ps/2 first port, keyboard self test failed" );
263- }
264-
265- if (dual_ps2_controller ) {
266- // reset second port
267- out = write_to_ps2_second_port (0xFF , 1 );
268- if (out != 0xFA ) {
269- PANIC (out , "reset ps/2 second failed" );
270- }
271- out = read_data_reply ();
272- if (out != 0xAA ) {
273- PANIC (out , "reset ps/2 second port, mouse self test failed" );
274- }
275- }
276-
277- // detect device type
278- out = write_to_ps2_first_port (0xF2 , 1 );
279- if (out != 0xFA ) {
280- PANIC (out , "device identity failed." );
281- }
282- unsigned char dev_d0 = read_data_reply ();
283- unsigned char dev_d1 = read_data_reply ();
284-
285- // Testing for device 0xAB 0x83: MF2 keyboard
286- if (dev_d0 != 0xAB ) {
287- PANIC (dev_d0 , "testing for device id 0xAB 0x83, found xx 0x83." );
288- }
289- if (dev_d1 != 0x83 ) {
290- PANIC (dev_d1 , "testing for device id 0xAB 0x83, found 0xAB xx." );
291- }
292-
293- // Caps
294- write_to_ps2_first_port (0xED , 0 );
295- out = write_to_ps2_first_port (7 , 1 );
296- if (out != 0xFA ) {
297- PANIC (out , "caps failed" );
298- }
299- // get scan code
300- write_to_ps2_first_port (0xF0 , 0 );
301- out = write_to_ps2_first_port (0 , 1 );
302- if (out != 0xFA ) {
303- PANIC (out , "failed to get scan code" );
304- } else {
305- // Not yet working
306- // out = read_data_reply();
307- // PANIC(out, "got get scan code");
190+ PANIC (out , "disable scan failed" );
308191 }
309192
310193 // set scan code
@@ -320,6 +203,5 @@ void keyboard_init() {
320203 PANIC (out , "scan failed" );
321204 }
322205 keyboard_scanner_init ();
323- set_color_fgbg (original_colors );
324206 print_log ("[keyboard init] done." );
325- }
207+ }
0 commit comments