]>
git.dujemihanovic.xyz Git - nameless-os.git/blob - kernel/drivers/input/ps2.c
050702426f39e9114ad5468e7754ba1177e0c46e
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
;
94 outb(PS2_DATA_PORT, PS2_DEV_RESET);
96 resp = inb(PS2_DATA_PORT);
97 } while (resp == RESEND);
99 if (resp == SELF_TEST_BAD || resp == SELF_TEST_BAD_2) {
101 kprint("ps2: Port 1 device self test failed!\n", 0);
103 kprint("ps2: No functioning devices, exiting!\n", 0);
106 } else { dev_1_test = 1; kprint("ps2: Port 1 device test successful\n", 0); }
112 while (resp == RESEND) {
114 outb(PS2_CMD_STS_PORT, PS2_CMD_PORT_2_WRITE);
116 outb(PS2_DATA_PORT, PS2_DEV_RESET);
118 resp = inb(PS2_DATA_PORT);
121 if (resp == SELF_TEST_BAD || resp == SELF_TEST_BAD_2) {
123 kprint("ps2: Port 2 device self test failed!\n", 0);
125 kprint("ps2: No functioning devices, exiting!\n", 0);
128 } else { dev_2_test = 1; kprint("ps2: Port 2 test successful\n", 0); }
133 outb(PS2_CMD_STS_PORT
, PS2_CMD_READ_CCB
);
135 ccb
= inb(PS2_DATA_PORT
);
137 SET(ccb
, PORT_1_IRQ
);
140 outb(PS2_CMD_STS_PORT
, PS2_CMD_WRITE_CCB
);
142 outb(PS2_DATA_PORT
, ccb
);
144 if (dev_2_test
&& dev_1_test
) return 1;
148 void ps2_output_wait()
151 status
= inb(PS2_CMD_STS_PORT
);
153 while (!IS_SET(status
, OUT_STATUS
)) status
= inb(PS2_CMD_STS_PORT
);
157 void ps2_input_wait()
160 status
= inb(PS2_CMD_STS_PORT
);
162 while (IS_SET(status
, IN_STATUS
)) status
= inb(PS2_CMD_STS_PORT
);