]>
git.dujemihanovic.xyz Git - nameless-os.git/blob - kernel/drivers/input/ps2.c
e765b24bcbcd316fa9448df3cfbacd14afaaa964
8 uint8_t ccb
, is_2channel
, port_1_test
, port_2_test
;
10 kprint("ps2: Begin initializing PS/2 controller\n", 0);
11 outb(PS2_CMD_STS_PORT
, PS2_CMD_PORT_2_DISABLE
);
13 outb(PS2_CMD_STS_PORT
, PS2_CMD_PORT_1_DISABLE
);
17 outb(PS2_CMD_STS_PORT
, PS2_CMD_READ_CCB
);
19 ccb
= inb(PS2_DATA_PORT
);
26 outb(PS2_CMD_STS_PORT
, PS2_CMD_WRITE_CCB
);
28 outb(PS2_DATA_PORT
, ccb
);
31 outb(PS2_CMD_STS_PORT
, PS2_CMD_CONTROLLER_TEST
);
33 if (inb(PS2_DATA_PORT
) != PS2_CONTROLLER_GOOD
) {
34 kprint("ps2: Controller self test failed, exiting!\n", 0);
39 outb(PS2_CMD_STS_PORT
, PS2_CMD_PORT_2_ENABLE
);
41 outb(PS2_CMD_STS_PORT
, PS2_CMD_READ_CCB
);
43 ccb
= inb(PS2_DATA_PORT
);
45 if (ccb
& PORT_2_CLK
!= PORT_2_CLK
) {
47 kprint("ps2: Controller is single-channel\n", 0);
50 kprint("ps2: Controller is dual-channel\n", 0);
52 outb(PS2_CMD_STS_PORT
, PS2_CMD_PORT_2_DISABLE
);
56 outb(PS2_CMD_STS_PORT
, PS2_CMD_PORT_1_TEST
);
59 if (inb(PS2_DATA_PORT
) != 0) {
61 kprint("ps2: Port 1 test failed!\n", 0);
63 kprint("ps2: No functional port, exiting!\n", 0);
66 } else port_1_test
= 1;
70 outb(PS2_CMD_STS_PORT
, PS2_CMD_PORT_2_TEST
);
73 if (inb(PS2_DATA_PORT
) != 0) {
75 kprint("ps2: Port 2 test failed!", 0);
77 kprint("ps2: No functional port, exiting!\n", 0);
80 } else port_2_test
= 1;
83 if (port_1_test
) { ps2_input_wait(); outb(PS2_CMD_STS_PORT
, PS2_CMD_PORT_1_ENABLE
); }
84 if (port_2_test
) { ps2_input_wait(); outb(PS2_CMD_STS_PORT
, PS2_CMD_PORT_2_ENABLE
); }
86 int dev_1_test
, dev_2_test
;
93 outb(PS2_DATA_PORT
, PS2_DEV_RESET
);
95 resp
= inb(PS2_DATA_PORT
);
96 } while (resp
== RESEND
);
98 if (resp
== SELF_TEST_BAD
|| resp
== SELF_TEST_BAD_2
) {
100 kprint("ps2: Port 1 device self test failed!\n", 0);
102 kprint("ps2: No functioning devices, exiting!\n", 0);
105 } else { dev_1_test
= 1; kprint("ps2: Port 1 device test successful\n", 0); }
116 outb(PS2_CMD_STS_PORT
, PS2_CMD_PORT_2_WRITE
);
118 outb(PS2_DATA_PORT
, PS2_DEV_RESET
);
120 resp
= inb(PS2_DATA_PORT
);
121 } while (resp
== RESEND
);
123 if (resp
== SELF_TEST_BAD
|| resp
== SELF_TEST_BAD_2
) {
125 kprint("ps2: Port 2 device self test failed!\n", 0);
127 kprint("ps2: No functioning devices, exiting!\n", 0);
130 } else { dev_2_test
= 1; kprint("ps2: Port 2 device test successful\n", 0); }
136 outb(PS2_CMD_STS_PORT
, PS2_CMD_READ_CCB
);
138 ccb
= inb(PS2_DATA_PORT
);
140 SET(ccb
, PORT_1_IRQ
);
143 outb(PS2_CMD_STS_PORT
, PS2_CMD_WRITE_CCB
);
145 outb(PS2_DATA_PORT
, ccb
);
147 if (dev_2_test
&& dev_1_test
) return 1;
151 void ps2_output_wait()
154 status
= inb(PS2_CMD_STS_PORT
);
156 while (!IS_SET(status
, OUT_STATUS
)) status
= inb(PS2_CMD_STS_PORT
);
160 void ps2_input_wait()
163 status
= inb(PS2_CMD_STS_PORT
);
165 while (IS_SET(status
, IN_STATUS
)) status
= inb(PS2_CMD_STS_PORT
);