Skip to content

Commit 6b9fcb4

Browse files
committed
lotus: Add UEFI App Mode
TODO: - [x] Add some comments to explain - [x] Test - [ ] Maybe add a hook when OS boots to enable the interrupt again, if the app forgets to do it. - [ ] Check formatting Signed-off-by: Daniel Schaefer <dhs@frame.work>
1 parent 59ea8cf commit 6b9fcb4

File tree

5 files changed

+101
-0
lines changed

5 files changed

+101
-0
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: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,5 +286,30 @@ 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;
289314

290315
#endif /* __BOARD_HOST_COMMAND_H */
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/src/board_host_command.c

Lines changed: 29 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

@@ -374,6 +375,34 @@ static enum ec_status get_active_charge_pd_chip(struct host_cmd_handler_args *ar
374375
}
375376
DECLARE_HOST_COMMAND(EC_CMD_GET_ACTIVE_CHARGE_PD_CHIP, get_active_charge_pd_chip, EC_VER_MASK(0));
376377

378+
#ifdef CONFIG_BOARD_LOTUS
379+
static enum ec_status host_command_uefi_app_mode(struct host_cmd_handler_args *args)
380+
{
381+
const struct ec_params_uefi_app_mode *p = args->params;
382+
int enable = 1;
383+
384+
if (p->flags)
385+
uefi_app_mode_setting(enable);
386+
else
387+
uefi_app_mode_setting(!enable);
388+
389+
return EC_SUCCESS;
390+
}
391+
DECLARE_HOST_COMMAND(EC_CMD_UEFI_APP_MODE, host_command_uefi_app_mode, EC_VER_MASK(0));
392+
393+
static enum ec_status host_command_uefi_app_btn_status(struct host_cmd_handler_args *args)
394+
{
395+
struct ec_response_uefi_app_btn_status *r = args->response;
396+
397+
r->status = uefi_app_btn_status();
398+
399+
args->response_size = sizeof(*r);
400+
401+
return EC_RES_SUCCESS;
402+
}
403+
DECLARE_HOST_COMMAND(EC_CMD_UEFI_APP_BTN_STATUS, host_command_uefi_app_btn_status, EC_VER_MASK(0));
404+
#endif /* CONFIG_BOARD_LOTUS */
405+
377406
/*******************************************************************************/
378407
/* EC console command for Project */
379408
/*******************************************************************************/
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)