Skip to content

Commit 196430a

Browse files
authored
Merge pull request #807 from FrameworkComputer/lotus-uefi-app-mode
Lotus UEFI App mode and other host commands
2 parents b48624b + 2e516b5 commit 196430a

File tree

9 files changed

+200
-22
lines changed

9 files changed

+200
-22
lines changed

zephyr/program/lotus/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ zephyr_library_sources("src/board_host_command.c")
1111
zephyr_library_sources("src/cypress_pd_common.c")
1212
zephyr_library_sources("src/flash_storage.c")
1313
zephyr_library_sources("src/factory.c")
14+
zephyr_library_sources("src/uefi_app_mode.c")
1415
zephyr_library_sources("src/diagnostics.c")
1516
zephyr_library_sources("src/ucsi.c")
1617
zephyr_library_sources("src/als.c")

zephyr/program/lotus/include/board_host_command.h

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,5 +286,64 @@ struct ec_response_get_active_charge_pd_chip {
286286
uint8_t pd_chip;
287287
} __ec_align1;
288288

289+
/*****************************************************************************/
290+
/*
291+
* Enable/disable UEFI App mode
292+
*
293+
* Enable disables the power button functionality and allows to read it via
294+
* EC_CMD_UEFI_APP_BTN_STATUS host command instead.
295+
* This makes it possible to use it as a software button in a UEFI app.
296+
*/
297+
#define EC_CMD_UEFI_APP_MODE 0x3E19
298+
299+
struct ec_params_uefi_app_mode {
300+
/* 0x01 to enable, 0x00 to disable UEFI App mode */
301+
uint8_t flags;
302+
} __ec_align1;
303+
304+
/*****************************************************************************/
305+
/*
306+
* Read power button status
307+
*/
308+
#define EC_CMD_UEFI_APP_BTN_STATUS 0x3E1A
309+
310+
struct ec_response_uefi_app_btn_status {
311+
/* 0x00 if not pressed, 0x01 if pressed */
312+
uint8_t status;
313+
} __ec_align1;
314+
315+
/*****************************************************************************/
316+
/*
317+
* Check state of the Expansion Bay
318+
*/
319+
#define EC_CMD_EXPANSION_BAY_STATUS 0x3E1B
320+
321+
enum ec_expansion_bay_states {
322+
/* Valid module present and switch closed */
323+
MODULE_ENABLED = BIT(0),
324+
/* Board ID invalid */
325+
MODULE_FAULT = BIT(1),
326+
/* Hatch switch open/closed status */
327+
HATCH_SWITCH_CLOSED = BIT(2),
328+
};
329+
330+
struct ec_response_expansion_bay_status {
331+
/* Check ec_expansion_bay_states */
332+
uint8_t state;
333+
uint8_t board_id_0;
334+
uint8_t board_id_1;
335+
} __ec_align1;
336+
337+
/*****************************************************************************/
338+
/*
339+
* Get hardware diagnostics
340+
*/
341+
#define EC_CMD_GET_HW_DIAG 0x3E1C
342+
343+
/* See enum diagnostics_device_idx */
344+
struct ec_response_get_hw_diag {
345+
uint32_t hw_diagnostics;
346+
uint8_t bios_complete;
347+
} __ec_align1;
289348

290349
#endif /* __BOARD_HOST_COMMAND_H */

zephyr/program/lotus/include/diagnostics.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ enum diagnostics_device_idx {
4848
*/
4949
void set_diagnostic(enum diagnostics_device_idx idx, bool error);
5050

51+
uint32_t get_hw_diagnostic(void);
52+
uint8_t is_bios_complete(void);
53+
5154
void set_bios_diagnostic(uint8_t code);
5255

5356
void reset_diagnostics(void);
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/* Copyright 202 The ChromiumOS Authors
2+
* Use of this source code is governed by a BSD-style license that can be
3+
* found in the LICENSE file.
4+
*/
5+
6+
#ifndef __CROS_EC_UEFI_APP_MODE_H
7+
#define __CROS_EC_UEFI_APP_MODE_H
8+
9+
void uefi_app_mode_setting(uint8_t enable);
10+
11+
uint8_t uefi_app_btn_status(void);
12+
13+
#endif /* __CROS_EC_UEFI_APP_MODE_H */

zephyr/program/lotus/lotus/src/gpu.c

Lines changed: 35 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include "gpu.h"
1616
#include "board_adc.h"
1717
#include "board_function.h"
18+
#include "board_host_command.h"
1819
#include "console.h"
1920
#include "driver/temp_sensor/f75303.h"
2021
#include "extpower.h"
@@ -39,6 +40,9 @@ LOG_MODULE_REGISTER(gpu, LOG_LEVEL_DBG);
3940

4041
static int module_present;
4142
static int module_fault;
43+
static int gpu_id_0;
44+
static int gpu_id_1;
45+
static int switch_status;
4246

4347
bool gpu_present(void)
4448
{
@@ -84,9 +88,9 @@ DECLARE_HOOK(HOOK_INIT, update_thermal_configuration, HOOK_PRIO_DEFAULT + 2);
8488

8589
void check_gpu_module(void)
8690
{
87-
int gpu_id_0 = get_hardware_id(ADC_GPU_BOARD_ID_0);
88-
int gpu_id_1 = get_hardware_id(ADC_GPU_BOARD_ID_1);
89-
int switch_status = 0;
91+
gpu_id_0 = get_hardware_id(ADC_GPU_BOARD_ID_0);
92+
gpu_id_1 = get_hardware_id(ADC_GPU_BOARD_ID_1);
93+
switch_status = 0;
9094

9195
if (board_get_version() >= BOARD_VERSION_7) {
9296
gpio_enable_dt_interrupt(GPIO_INT_FROM_NODELABEL(int_beam_open));
@@ -100,15 +104,18 @@ void check_gpu_module(void)
100104
case VALID_BOARDID(BOARD_VERSION_12, BOARD_VERSION_12):
101105
LOG_DBG("Detected dual interposer device");
102106
module_present = 1;
107+
module_fault = 0;
103108
break;
104109
case VALID_BOARDID(BOARD_VERSION_11, BOARD_VERSION_15):
105110
case VALID_BOARDID(BOARD_VERSION_13, BOARD_VERSION_15):
106111
LOG_DBG("Detected single interposer device");
107112
module_present = 1;
113+
module_fault = 0;
108114
break;
109115
case VALID_BOARDID(BOARD_VERSION_15, BOARD_VERSION_15):
110116
LOG_DBG("No gpu module detected %d %d", gpu_id_0, gpu_id_1);
111117
module_present = 0;
118+
module_fault = 0;
112119
break;
113120
default:
114121
LOG_DBG("GPU module Fault");
@@ -161,24 +168,6 @@ DECLARE_DEFERRED(gpu_interposer_toggle_deferred);
161168

162169
__override void project_chassis_function(enum gpio_signal signal)
163170
{
164-
int open_state = gpio_pin_get_dt(GPIO_DT_FROM_NODELABEL(gpio_chassis_open_l));
165-
166-
/* The dGPU SW is SW3 at DVT phase */
167-
if (board_get_version() >= BOARD_VERSION_7)
168-
return;
169-
170-
if (!open_state) {
171-
/* Make sure the module is off as fast as possible! */
172-
LOG_DBG("Powering off GPU");
173-
gpio_pin_set_dt(GPIO_DT_FROM_NODELABEL(gpio_gpu_b_gpio02_ec), 0);
174-
gpio_pin_set_dt(GPIO_DT_FROM_NODELABEL(gpio_gpu_vsys_en), 0);
175-
gpio_pin_set_dt(GPIO_DT_FROM_NODELABEL(gpio_gpu_3v_5v_en), 0);
176-
gpio_pin_set_dt(GPIO_DT_FROM_NODELABEL(gpio_edp_mux_pwm_sw), 0);
177-
module_present = 0;
178-
update_thermal_configuration();
179-
} else {
180-
hook_call_deferred(&check_gpu_module_data, 50*MSEC);
181-
}
182171
}
183172

184173
void beam_open_interrupt(enum gpio_signal signal)
@@ -211,6 +200,7 @@ void beam_open_interrupt(enum gpio_signal signal)
211200
}
212201
} else
213202
gpu_interposer_toggle_count = 0;
203+
switch_status = 0;
214204
} else {
215205
hook_call_deferred(&check_gpu_module_data, 50*MSEC);
216206
}
@@ -322,3 +312,27 @@ void gpu_power_enable_handler(void)
322312
hook_call_deferred(&gpu_board_f75303_initial_data, 500 * MSEC);
323313

324314
}
315+
316+
static enum ec_status host_command_expansion_bay_status(struct host_cmd_handler_args *args)
317+
{
318+
struct ec_response_expansion_bay_status *r = args->response;
319+
320+
r->state = 0;
321+
if (module_present) {
322+
r->state |= MODULE_ENABLED;
323+
}
324+
if (module_fault) {
325+
r->state |= MODULE_FAULT;
326+
}
327+
if (switch_status) {
328+
r->state |= HATCH_SWITCH_CLOSED;
329+
}
330+
r->board_id_0 = gpu_id_0;
331+
r->board_id_1 = gpu_id_1;
332+
333+
args->response_size = sizeof(*r);
334+
335+
return EC_RES_SUCCESS;
336+
}
337+
DECLARE_HOST_COMMAND(EC_CMD_EXPANSION_BAY_STATUS, host_command_expansion_bay_status,
338+
EC_VER_MASK(0));

zephyr/program/lotus/lotus/src/project_diagnostics.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ void check_device_deferred(void)
4343
if (!(fan_get_rpm_actual(1) > 100) && !get_standalone_mode())
4444
set_diagnostic(DIAGNOSTICS_NO_LEFT_FAN, true);
4545

46+
/* TODO: Add something to know whether check has run or not */
47+
4648
/* Exit the duty mode and let thermal to control the fan */
4749
dptf_set_fan_duty_target(-1);
4850

zephyr/program/lotus/src/board_host_command.c

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include "lpc.h"
2828
#include "power_sequence.h"
2929
#include "system.h"
30+
#include "uefi_app_mode.h"
3031
#include "util.h"
3132
#include "zephyr_console_shim.h"
3233

@@ -227,6 +228,20 @@ static enum ec_status cmd_diagnosis(struct host_cmd_handler_args *args)
227228
DECLARE_HOST_COMMAND(EC_CMD_DIAGNOSIS, cmd_diagnosis,
228229
EC_VER_MASK(0));
229230

231+
static enum ec_status cmd_get_hw_diag(struct host_cmd_handler_args *args)
232+
{
233+
struct ec_response_get_hw_diag *r = args->response;
234+
235+
r->hw_diagnostics = get_hw_diagnostic();
236+
r->bios_complete = is_bios_complete();
237+
238+
args->response_size = sizeof(*r);
239+
240+
return EC_RES_SUCCESS;
241+
}
242+
DECLARE_HOST_COMMAND(EC_CMD_GET_HW_DIAG, cmd_get_hw_diag,
243+
EC_VER_MASK(0));
244+
230245
#ifdef CONFIG_BOARD_AZALEA
231246
static enum ec_status update_keyboard_matrix(struct host_cmd_handler_args *args)
232247
{
@@ -376,6 +391,34 @@ static enum ec_status get_active_charge_pd_chip(struct host_cmd_handler_args *ar
376391
}
377392
DECLARE_HOST_COMMAND(EC_CMD_GET_ACTIVE_CHARGE_PD_CHIP, get_active_charge_pd_chip, EC_VER_MASK(0));
378393

394+
#ifdef CONFIG_BOARD_LOTUS
395+
static enum ec_status host_command_uefi_app_mode(struct host_cmd_handler_args *args)
396+
{
397+
const struct ec_params_uefi_app_mode *p = args->params;
398+
int enable = 1;
399+
400+
if (p->flags)
401+
uefi_app_mode_setting(enable);
402+
else
403+
uefi_app_mode_setting(!enable);
404+
405+
return EC_SUCCESS;
406+
}
407+
DECLARE_HOST_COMMAND(EC_CMD_UEFI_APP_MODE, host_command_uefi_app_mode, EC_VER_MASK(0));
408+
409+
static enum ec_status host_command_uefi_app_btn_status(struct host_cmd_handler_args *args)
410+
{
411+
struct ec_response_uefi_app_btn_status *r = args->response;
412+
413+
r->status = uefi_app_btn_status();
414+
415+
args->response_size = sizeof(*r);
416+
417+
return EC_RES_SUCCESS;
418+
}
419+
DECLARE_HOST_COMMAND(EC_CMD_UEFI_APP_BTN_STATUS, host_command_uefi_app_btn_status, EC_VER_MASK(0));
420+
#endif /* CONFIG_BOARD_LOTUS */
421+
379422
/*******************************************************************************/
380423
/* EC console command for Project */
381424
/*******************************************************************************/

zephyr/program/lotus/src/diagnostics.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ uint32_t diagnostics_ctr;
3535
uint32_t bios_code;
3636

3737
uint8_t bios_complete;
38-
uint8_t fan_seen;
38+
uint8_t fan_seen; /* TODO: Unused so far */
3939
uint8_t run_diagnostics;
4040

4141
int standalone_mode;
@@ -157,3 +157,13 @@ static void diagnostics_check(void)
157157

158158
}
159159
DECLARE_HOOK(HOOK_CHIPSET_RESUME, diagnostics_check, HOOK_PRIO_DEFAULT);
160+
161+
uint32_t get_hw_diagnostic(void)
162+
{
163+
return hw_diagnostics;
164+
}
165+
166+
uint8_t is_bios_complete(void)
167+
{
168+
return bios_complete;
169+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
* Copyright 2023 The Chromium OS Authors. All rights reserved.
3+
* Use of this source code is governed by a BSD-style license that can be
4+
* found in the LICENSE file.
5+
*/
6+
7+
#include <zephyr/drivers/gpio.h>
8+
9+
#include "ec_commands.h"
10+
#include "uefi_app_mode.h"
11+
#include "gpio.h"
12+
#include "gpio/gpio_int.h"
13+
14+
static uint8_t uefi_app_enable;
15+
16+
void uefi_app_mode_setting(uint8_t enable)
17+
{
18+
uefi_app_enable = enable;
19+
20+
/* Ignored the power button signal if we are in UEFI app mode */
21+
/* TODO: Maybe add a hook when OS boots to enable the interrupt again, */
22+
/* if the app forgets to do it. */
23+
if (uefi_app_enable) {
24+
gpio_disable_dt_interrupt(GPIO_INT_FROM_NODELABEL(int_powerbtn));
25+
} else {
26+
gpio_enable_dt_interrupt(GPIO_INT_FROM_NODELABEL(int_powerbtn));
27+
}
28+
}
29+
30+
uint8_t uefi_app_btn_status(void)
31+
{
32+
return gpio_pin_get_dt(GPIO_DT_FROM_NODELABEL(gpio_on_off_btn_l)) == 1;
33+
}

0 commit comments

Comments
 (0)