system76/common: Move touchpad handling to kbc_event

This commit is contained in:
Jeremy Soller
2020-12-29 10:14:57 -07:00
committed by Jeremy Soller
parent 31a908556b
commit fb6355f907
5 changed files with 19 additions and 44 deletions

View File

@ -7,8 +7,6 @@
#include <ec/kbc.h>
extern bool kbc_first;
extern bool kbc_second;
extern uint8_t kbc_leds;
void kbc_init(void);

View File

@ -1,8 +0,0 @@
// SPDX-License-Identifier: GPL-3.0-only
#ifndef _BOARD_TOUCHPAD_H
#define _BOARD_TOUCHPAD_H
void touchpad_event(void);
#endif // _BOARD_TOUCHPAD_H

View File

@ -25,9 +25,9 @@ void kbc_init(void) {
#define KBC_TIMEOUT 10000
// Enable first port - TODO
bool kbc_first = false;
static bool kbc_first = false;
// Enable second port - TODO
bool kbc_second = false;
static bool kbc_second = false;
// Translate from scancode set 2 to scancode set 1
// for basically no good reason
static bool kbc_translate = true;
@ -406,6 +406,20 @@ static void kbc_on_output_empty(struct Kbc * kbc) {
void kbc_event(struct Kbc * kbc) {
uint8_t sts;
// Read from touchpad when possible
if (kbc_second) {
*(PS2_TOUCHPAD.control) = 0x07;
if (state == KBC_STATE_NORMAL) {
uint8_t sts = *(PS2_TOUCHPAD.status);
*(PS2_TOUCHPAD.status) = sts;
if (sts & BIT(3)) {
state = KBC_STATE_TOUCHPAD;
}
}
} else {
ps2_reset(&PS2_TOUCHPAD);
}
// Read command/data while available
sts = kbc_status(kbc);
if (sts & KBC_STS_IBF) {

View File

@ -24,7 +24,6 @@
#include <board/pwm.h>
#include <board/smbus.h>
#include <board/smfi.h>
#include <board/touchpad.h>
#include <common/debug.h>
#include <common/macro.h>
#include <common/version.h>
@ -93,7 +92,7 @@ void main(void) {
uint32_t last_time = 0;
for(main_cycle = 0; ; main_cycle++) {
switch (main_cycle % 5) {
switch (main_cycle % 3) {
case 0:
// Handle power states
power_event();
@ -108,14 +107,6 @@ void main(void) {
}
break;
case 2:
// Passes through touchpad packets
touchpad_event();
break;
case 3:
// Checks for keyboard/mouse packets from host
kbc_event(&KBC);
break;
case 4:
// Handle lid close/open
lid_event();
break;
@ -143,6 +134,8 @@ void main(void) {
// Board-specific events
board_event();
// Checks for keyboard/mouse packets from host
kbc_event(&KBC);
// Handles ACPI communication
pmc_event(&PMC_1);
// AP/EC communication over SMFI

View File

@ -1,22 +0,0 @@
// SPDX-License-Identifier: GPL-3.0-only
#include <board/kbc.h>
#include <board/touchpad.h>
#include <common/debug.h>
#include <ec/ps2.h>
void touchpad_event(void) {
if (kbc_second) {
*(PS2_TOUCHPAD.control) = 0x07;
} else {
ps2_reset(&PS2_TOUCHPAD);
}
uint8_t status = *(PS2_TOUCHPAD.status);
*(PS2_TOUCHPAD.status) = status;
if (status & (1 << 3)) {
uint8_t data = *(PS2_TOUCHPAD.data);
TRACE("touchpad: %02X\n", data);
kbc_mouse(&KBC, data, 1000);
}
}