Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nvc usb charge port #600

Open
wants to merge 4 commits into
base: dasharo
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion payloads/external/Makefile.mk
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,8 @@ $(obj)/UEFIPAYLOAD.fd: $(DOTCONFIG) $(IPXE_EFI)
CONFIG_EDK2_CPU_THROTTLING_THRESHOLD_OPTION=$(CONFIG_EDK2_CPU_THROTTLING_THRESHOLD_OPTION) \
CONFIG_EDK2_CPU_THROTTLING_THRESHOLD_DEFAULT=$(CONFIG_EDK2_CPU_THROTTLING_THRESHOLD_DEFAULT) \
CONFIG_CPU_MAX_TEMPERATURE=$(CONFIG_CPU_MAX_TEMPERATURE) \
CONFIG_EDK2_USE_LAPTOP_LID_LIB=$(CONFIG_EDK2_USE_LAPTOP_LID_LIB)
CONFIG_EDK2_USE_LAPTOP_LID_LIB=$(CONFIG_EDK2_USE_LAPTOP_LID_LIB) \
CONFIG_EDK2_USB_PORT_POWER_OPTION=$(CONFIG_EDK2_USB_PORT_POWER_OPTION)


$(obj)/ShimmedUniversalPayload.elf: $(DOTCONFIG)
Expand Down
8 changes: 8 additions & 0 deletions payloads/external/edk2/Kconfig.dasharo
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,14 @@ config EDK2_CPU_THROTTLING_THRESHOLD_DEFAULT
help
Board-specific CPU throttling threshold temperature default value

config EDK2_USB_PORT_POWER_OPTION
bool "Show USB Port Power option in Dasharo Power Configuration Menu"
default n
depends on EDK2_DASHARO_POWER_CONFIG
help
Shows the USB Port Power option in EDK2 power configuration submenu in
Dasharo System Features menu.

config EDK2_DASHARO_PCI_CONFIG
bool "Enable EDK2 Dasharo PCI/PCIe Configuration Menu"
default n
Expand Down
4 changes: 4 additions & 0 deletions payloads/external/edk2/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,10 @@ ifeq ($(CONFIG_EDK2_BATTERY_CONFIG_OPTION),y)
BUILD_STR += --pcd gDasharoSystemFeaturesTokenSpaceGuid.PcdPowerMenuShowBatteryThresholds=TRUE
endif

ifeq ($(CONFIG_EDK2_USB_PORT_POWER_OPTION),y)
BUILD_STR += --pcd gDasharoSystemFeaturesTokenSpaceGuid.PcdPowerMenuShowUsbPowerOption=TRUE
endif

endif # CONFIG_EDK2_DASHARO_POWER_CONFIG
# DASHARO_PCI_CONFIG = FALSE
ifeq ($(CONFIG_EDK2_DASHARO_PCI_CONFIG),y)
Expand Down
10 changes: 8 additions & 2 deletions src/ec/system76/ec/commands.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,14 @@

// Persistent option definitions
enum {
OPT_POWER_ON_AC = 0,
NUM_OPTIONS
OPT_POWER_ON_AC = 0,
OPT_KBLED_LEVEL_I,
OPT_KBLED_COLOR_I,
OPT_BAT_THRESHOLD_START,
OPT_BAT_THRESHOLD_STOP,
OPT_ALLOW_BAT_BOOST,
OPT_USB_POWER,
NUM_OPTIONS
};

uint8_t system76_ec_smfi_cmd(uint8_t cmd, uint8_t len, uint8_t *data);
Expand Down
16 changes: 16 additions & 0 deletions src/mainboard/clevo/adl-p/ramstage.c
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,21 @@ static void set_power_on_ac(void)
system76_ec_smfi_cmd(CMD_OPTION_SET, sizeof(cmd) / sizeof(uint8_t), (uint8_t *)&cmd);
}

static void set_usb_charge_port(void)
{
struct smfi_option_get_cmd {
uint8_t index;
uint8_t value;
} __packed cmd = {
OPT_USB_POWER,
0
};

cmd.value = dasharo_get_usb_port_power();

system76_ec_smfi_cmd(CMD_OPTION_SET, sizeof(cmd) / sizeof(uint8_t), (uint8_t *)&cmd);
}

static void mainboard_init(void *chip_info)
{
config_t *cfg = config_of_soc();
Expand All @@ -123,6 +138,7 @@ static void mainboard_init(void *chip_info)
set_camera_enablement();
set_battery_thresholds();
set_power_on_ac();
set_usb_charge_port();
}

#if CONFIG(GENERATE_SMBIOS_TABLES)
Expand Down
16 changes: 16 additions & 0 deletions src/mainboard/clevo/mtl-h/ramstage.c
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,21 @@ static void set_power_on_ac(void)
system76_ec_smfi_cmd(CMD_OPTION_SET, sizeof(cmd), (uint8_t *)&cmd);
}

static void set_usb_charge_port(void)
{
struct smfi_option_get_cmd {
uint8_t index;
uint8_t value;
} __packed cmd = {
OPT_USB_POWER,
0
};

cmd.value = dasharo_get_usb_port_power();

system76_ec_smfi_cmd(CMD_OPTION_SET, sizeof(cmd) / sizeof(uint8_t), (uint8_t *)&cmd);
}

void __weak variant_devtree_update(void)
{
/* Override dev tree settings per board */
Expand All @@ -125,6 +140,7 @@ static void mainboard_init(void *chip_info)
set_camera_enablement();
set_battery_thresholds();
set_power_on_ac();
set_usb_charge_port();

variant_devtree_update();
}
Expand Down
16 changes: 16 additions & 0 deletions src/mainboard/clevo/tgl-u/ramstage.c
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,21 @@ static void set_power_on_ac(void)
system76_ec_smfi_cmd(CMD_OPTION_SET, sizeof(cmd) / sizeof(uint8_t), (uint8_t *)&cmd);
}

static void set_usb_charge_port(void)
{
struct smfi_option_get_cmd {
uint8_t index;
uint8_t value;
} __packed cmd = {
OPT_USB_POWER,
0
};

cmd.value = dasharo_get_usb_port_power();

system76_ec_smfi_cmd(CMD_OPTION_SET, sizeof(cmd) / sizeof(uint8_t), (uint8_t *)&cmd);
}

static void init_mainboard(void *chip_info)
{
variant_configure_gpios();
Expand All @@ -125,6 +140,7 @@ static void init_mainboard(void *chip_info)
set_camera_enablement();
set_battery_thresholds();
set_power_on_ac();
set_usb_charge_port();
}

#if CONFIG(GENERATE_SMBIOS_TABLES)
Expand Down
16 changes: 16 additions & 0 deletions src/vendorcode/dasharo/include/dasharo/options.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,13 @@ enum cse_disable_mode {
ME_MODE_DISABLE_HMRFPO = 10
};

enum usb_port_power_opt {
USB_PORT_ON_WHEN_POWERED = 0,
USB_PORT_ALWAYS_ON = 1,
USB_PORT_WHEN_ON_AC = 2,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
USB_PORT_WHEN_ON_AC = 2,
USB_PORT_ON_WHEN_ON_AC = 2,

I think that makes more sense

};


struct watchdog_config {
bool wdt_enable;
uint16_t wdt_timeout;
Expand Down Expand Up @@ -77,6 +84,15 @@ enum cb_err dasharo_reset_options(void);
*/
uint8_t dasharo_get_power_on_after_fail(void);

/* Looks up Dasharo/"UsbPortPower" variable.
*
* Result:
* - 0 - Only when powered on (default)
* - 1 - Always Enabled
* - 2 - Enabled when on AC
*/
uint8_t dasharo_get_usb_port_power(void);

/* Looks up Dasharo/"PCIeResizeableBarsEnabled" variable if resizable PCIe BARs
* support was enabled at compile-time.
*
Expand Down
14 changes: 14 additions & 0 deletions src/vendorcode/dasharo/options.c
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,20 @@ uint8_t dasharo_get_power_on_after_fail(void)
return power_status;
}

uint8_t dasharo_get_usb_port_power(void)
{
uint8_t usb_port_power = USB_PORT_ON_WHEN_POWERED;

/* When present, EFI variable has higher priority. */
if (CONFIG(DRIVERS_EFI_VARIABLE_STORE))
read_u8_var("UsbPortPower", &usb_port_power);

if (usb_port_power > USB_PORT_WHEN_ON_AC)
return USB_PORT_ON_WHEN_POWERED;

return usb_port_power;
}

bool dasharo_resizeable_bars_enabled(void)
{
static bool enabled = false;
Expand Down