Skip to content

Commit 233785e

Browse files
committed
Lotus: add the host command to control the input module detect mode
Signed-off-by: Josh-Tsai <josh_tsai@compal.com>
1 parent 516b320 commit 233785e

File tree

4 files changed

+63
-8
lines changed

4 files changed

+63
-8
lines changed

zephyr/program/lotus/include/board_host_command.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,10 @@ struct ec_response_chassis_counter {
244244
*/
245245
#define EC_CMD_CHECK_DECK_STATE 0x3E16
246246

247+
struct ec_params_deck_state {
248+
uint8_t mode;
249+
} __ec_align1;
250+
247251
struct ec_response_deck_state {
248252
uint8_t input_deck_board_id[8];
249253
uint8_t deck_state;

zephyr/program/lotus/include/lotus/input_module.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,4 +50,8 @@ int get_deck_state(void);
5050

5151
void input_modules_powerdown(void);
5252

53+
void set_detect_mode(int mode);
54+
55+
int get_detect_mode(void);
56+
5357
#endif /*__BOARD_INPUT_MODULE_H__*/

zephyr/program/lotus/lotus/src/input_module.c

Lines changed: 44 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ LOG_MODULE_REGISTER(inputmodule, LOG_LEVEL_INF);
2828

2929
int oc_count;
3030
int force_on;
31+
int detect_mode;
3132
int hub_board_id[8]; /* EC console Debug use */
3233
enum input_deck_state deck_state;
3334

@@ -36,6 +37,17 @@ void module_oc_interrupt(enum gpio_signal signal)
3637
oc_count++;
3738
}
3839

40+
void set_detect_mode(int mode)
41+
{
42+
detect_mode = mode;
43+
}
44+
45+
int get_detect_mode(void)
46+
{
47+
return detect_mode;
48+
}
49+
50+
3951
static void set_hub_mux(uint8_t input)
4052
{
4153
gpio_pin_set_dt(GPIO_DT_FROM_NODELABEL(gpio_mux_a0),
@@ -72,9 +84,15 @@ static void scan_c_deck(bool full_scan)
7284

7385
static void board_input_module_init(void)
7486
{
75-
deck_state = DECK_OFF;
87+
/* need to wait bios_function_init() to update detect mode */
88+
if (detect_mode == 0x02)
89+
deck_state = DECK_FORCE_ON;
90+
else if (detect_mode == 0x04)
91+
deck_state = DECK_FORCE_OFF;
92+
else
93+
deck_state = DECK_OFF;
7694
}
77-
DECLARE_HOOK(HOOK_INIT, board_input_module_init, HOOK_PRIO_DEFAULT);
95+
DECLARE_HOOK(HOOK_INIT, board_input_module_init, HOOK_PRIO_DEFAULT + 2);
7896

7997
static void poll_c_deck(void)
8098
{
@@ -127,17 +145,24 @@ DECLARE_HOOK(HOOK_TICK, poll_c_deck, HOOK_PRIO_DEFAULT);
127145

128146
static void input_modules_powerup(void)
129147
{
130-
if (deck_state != DECK_FORCE_ON && deck_state != DECK_FORCE_ON)
148+
if (deck_state == DECK_FORCE_ON)
149+
gpio_pin_set_dt(GPIO_DT_FROM_NODELABEL(gpio_hub_b_pwr_en), 1);
150+
else if (deck_state != DECK_FORCE_ON && deck_state != DECK_FORCE_ON)
131151
deck_state = DECK_DISCONNECTED;
152+
132153
}
133154
DECLARE_HOOK(HOOK_CHIPSET_STARTUP, input_modules_powerup, HOOK_PRIO_DEFAULT);
134155

135156
void input_modules_powerdown(void)
136157
{
137-
deck_state = DECK_OFF;
138-
gpio_pin_set_dt(GPIO_DT_FROM_NODELABEL(gpio_hub_b_pwr_en), 0);
139-
/* Hub mux input 6 is NC, so lower power draw by disconnecting all PD*/
140-
set_hub_mux(TOP_ROW_NOT_CONNECTED);
158+
if (deck_state == DECK_FORCE_ON)
159+
gpio_pin_set_dt(GPIO_DT_FROM_NODELABEL(gpio_hub_b_pwr_en), 0);
160+
else if (deck_state != DECK_FORCE_ON && deck_state != DECK_FORCE_ON) {
161+
deck_state = DECK_OFF;
162+
gpio_pin_set_dt(GPIO_DT_FROM_NODELABEL(gpio_hub_b_pwr_en), 0);
163+
/* Hub mux input 6 is NC, so lower power draw by disconnecting all PD */
164+
set_hub_mux(TOP_ROW_NOT_CONNECTED);
165+
}
141166
}
142167

143168
int get_deck_state(void)
@@ -148,9 +173,21 @@ int get_deck_state(void)
148173
/* Host command */
149174
static enum ec_status check_deck_state(struct host_cmd_handler_args *args)
150175
{
176+
const struct ec_params_deck_state *p = args->params;
151177
struct ec_response_deck_state *r = args->response;
152178
int idx;
153179

180+
/* set mode */
181+
if (p->mode == 0x01)
182+
deck_state = DECK_DISCONNECTED;
183+
else if (p->mode == 0x02)
184+
deck_state = DECK_FORCE_ON;
185+
else if (p->mode == 0x04)
186+
deck_state = DECK_FORCE_OFF;
187+
188+
set_detect_mode(p->mode);
189+
190+
/* return deck status */
154191
for (idx = 0; idx < 8; idx++)
155192
r->input_deck_board_id[idx] = (uint8_t)hub_board_id[idx];
156193

zephyr/program/lotus/src/board_function.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@
1919
#include "util.h"
2020
#include "zephyr_console_shim.h"
2121

22+
#ifdef CONFIG_BOARD_LOTUS
23+
#include "input_module.h"
24+
#endif
25+
2226
/* Console output macros */
2327
#define CPRINTS(format, args...) cprints(CC_HOSTCMD, format, ##args)
2428
#define CPRINTF(format, args...) cprintf(CC_HOSTCMD, format, ##args)
@@ -64,7 +68,10 @@ void bios_function_detect(void)
6468
system_set_bbram(SYSTEM_BBRAM_IDX_BIOS_FUNCTION, ac_boot_status());
6569

6670
flash_storage_update(FLASH_FLAGS_STANDALONE, get_standalone_mode() ? 1 : 0);
67-
flash_storage_commit();
71+
#ifdef CONFIG_BOARD_LOTUS
72+
flash_storage_update(FLASH_FLAGS_INPUT_MODULE_POWER, get_detect_mode());
73+
#endif
74+
flash_storage_commit();
6875
}
6976

7077
int chassis_cmd_clear(int type)
@@ -140,6 +147,9 @@ static void bios_function_init(void)
140147
if (flash_storage_get(FLASH_FLAGS_STANDALONE))
141148
set_standalone_mode(1);
142149

150+
#ifdef CONFIG_BOARD_LOTUS
151+
set_detect_mode(flash_storage_get(FLASH_FLAGS_INPUT_MODULE_POWER));
152+
#endif
143153
check_chassis_open(1);
144154
hook_call_deferred(&board_customer_tick_data, 1000 * MSEC);
145155
}

0 commit comments

Comments
 (0)