Skip to content

Commit ba4355a

Browse files
authored
Merge pull request #706 from FrameworkComputer/azalea.keyboard_issue
azalea: modify 8042 ibf handle.
2 parents 8e33f6f + d3ff9dd commit ba4355a

File tree

5 files changed

+88
-2
lines changed

5 files changed

+88
-2
lines changed

common/keyboard_8042.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,13 @@ void keyboard_host_write(int data, int is_cmd)
241241
task_wake(TASK_ID_KEYPROTO);
242242
}
243243

244+
#ifdef CONFIG_CUSTOMIZED_DESIGN
245+
int keyboard_host_write_avaliable(void)
246+
{
247+
return queue_count(&from_host);
248+
}
249+
#endif
250+
244251
/**
245252
* Enable keyboard IRQ generation.
246253
*

include/keyboard_8042.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,17 @@ void button_state_changed(enum keyboard_button_type button, int is_pressed);
2828
*/
2929
void keyboard_host_write(int data, int is_cmd);
3030

31+
#ifdef CONFIG_CUSTOMIZED_DESIGN
32+
/**
33+
* Get the amount of free 8042 buffer slots
34+
* this is used to put backpressure on the host
35+
* if the keyboard task gets too slow
36+
* @return bytes_avaliable
37+
*/
38+
int keyboard_host_write_avaliable(void);
39+
40+
#endif
41+
3142
/*
3243
* Board specific callback function when a key state is changed.
3344
*

zephyr/program/lotus/azalea/project.conf

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,6 @@ CONFIG_PLATFORM_EC_PWM_KBLIGHT=y
2424
CONFIG_PLATFORM_EC_KEYBOARD_VIVALDI=n
2525
CONFIG_PLATFORM_EC_KEYBOARD_CUSTOMIZATION=y
2626
CONFIG_PLATFORM_KEYBOARD_SCANCODE_CALLBACK=y
27+
28+
# Thrid party change
29+
CONFIG_THIRD_PARTY_CUSTOMIZED_DESIGN=y

zephyr/program/lotus/azalea/src/keyboard_customization.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,14 +87,14 @@ static char keycap_label[KEYBOARD_COLS_MAX][KEYBOARD_ROWS] = {
8787
KLLI_UNKNO, KLLI_UNKNO, KLLI_RIGHT, KLLI_LEFT},
8888
};
8989

90-
char get_keycap_label(uint8_t row, uint8_t col)
90+
uint8_t get_keycap_label(uint8_t row, uint8_t col)
9191
{
9292
if (col < KEYBOARD_COLS_MAX && row < KEYBOARD_ROWS)
9393
return keycap_label[col][row];
9494
return KLLI_UNKNO;
9595
}
9696

97-
void set_keycap_label(uint8_t row, uint8_t col, char val)
97+
void set_keycap_label(uint8_t row, uint8_t col, uint8_t val)
9898
{
9999
if (col < KEYBOARD_COLS_MAX && row < KEYBOARD_ROWS)
100100
keycap_label[col][row] = val;

zephyr/shim/src/espi.c

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -644,6 +644,70 @@ void lpc_aux_put_char(uint8_t chr, int send_irq)
644644
LOG_INF("AUX put %02x", kb_char);
645645
}
646646

647+
#ifdef CONFIG_THIRD_PARTY_CUSTOMIZED_DESIGN
648+
649+
/*
650+
* this can delay EC release irq and clear IBF
651+
* it will let host not send data too fast, make EC
652+
* have time to process 8042 data and also not lose data
653+
* after delay finish read HIKMDI clear IBF data and release 8042 irq
654+
*/
655+
static void lpc_kbc_irq_handle(void)
656+
{
657+
int rv;
658+
659+
rv = espi_write_lpc_request(espi_dev, E8042_RESUME_IRQ, 0);
660+
if (rv) {
661+
LOG_ERR("ESPI write failed: E8042_RESUME_IRQ = %d", rv);
662+
}
663+
}
664+
DECLARE_DEFERRED(lpc_kbc_irq_handle);
665+
666+
static void kbc_ibf_obe_handler(uint32_t data)
667+
{
668+
#ifdef HAS_TASK_KEYPROTO
669+
uint8_t is_ibf = is_8042_ibf(data);
670+
uint32_t status = I8042_AUX_DATA;
671+
uint32_t request;
672+
int rv;
673+
674+
if (is_ibf == HOST_KBC_EVT_IBF) {
675+
676+
/* reserve one buffer size for 8042 data handle. */
677+
if (keyboard_host_write_avaliable() <= 1) {
678+
/* Pause 8042 irq let KB task process data */
679+
rv = espi_write_lpc_request(espi_dev, E8042_PAUSE_IRQ, 0);
680+
if (rv) {
681+
LOG_ERR("ESPI write failed: E8042_PAUSE_IRQ = %d", rv);
682+
}
683+
684+
hook_call_deferred(&lpc_kbc_irq_handle_data, MSEC);
685+
} else {
686+
/* put data to queue and trigger 8042 task*/
687+
keyboard_host_write(get_8042_data(data), get_8042_type(data));
688+
689+
/* clear IBF let host send next data */
690+
rv = espi_read_lpc_request(espi_dev, E8042_CLEAR_IBF, &request);
691+
if (rv) {
692+
LOG_ERR("ESPI read failed: E8042_CLEAR_IBF = %d", rv);
693+
return;
694+
}
695+
}
696+
} else if (IS_ENABLED(CONFIG_8042_AUX)) {
697+
rv = espi_write_lpc_request(espi_dev, E8042_CLEAR_FLAG,
698+
&status);
699+
if (rv) {
700+
LOG_ERR("ESPI write failed: E8042_CLEAR_FLAG = %d", rv);
701+
}
702+
}
703+
704+
/* OBE data coming */
705+
if (is_ibf != HOST_KBC_EVT_IBF)
706+
task_wake(TASK_ID_KEYPROTO);
707+
708+
#endif
709+
}
710+
#else
647711
static void kbc_ibf_obe_handler(uint32_t data)
648712
{
649713
#ifdef HAS_TASK_KEYPROTO
@@ -663,6 +727,7 @@ static void kbc_ibf_obe_handler(uint32_t data)
663727
task_wake(TASK_ID_KEYPROTO);
664728
#endif
665729
}
730+
#endif
666731

667732
int lpc_keyboard_input_pending(void)
668733
{

0 commit comments

Comments
 (0)