From c2569830b1e7a38397e9111375560a2a2f48f821 Mon Sep 17 00:00:00 2001 From: Tim Crawford Date: Mon, 8 Sep 2025 18:00:46 -0600 Subject: [PATCH 1/3] Move dGPU support from common to drivers - Boards select the specific `DRIVERS_DGPU_*` config - Boards no longer select `HAVE_DGPU` directly - `I2C_DGPU` is renamed to `DGPU_I2C` - I2C controller selection is just the integer index Does not address the fact the bonw14 uses the I2C controller declared for dGPU access for KBLED access. Signed-off-by: Tim Crawford --- Makefile | 6 ++++- src/app/main/Makefile.mk | 6 ----- src/app/main/acpi.c | 2 +- src/app/main/fan.c | 2 +- src/app/main/kbled/bonw14.c | 6 ++--- src/app/main/main.c | 2 +- src/app/main/scratch.c | 2 +- src/board/system76/addw1/Makefile.mk | 3 +-- src/board/system76/addw2/Makefile.mk | 3 +-- src/board/system76/addw3/Makefile.mk | 3 +-- src/board/system76/addw4/Makefile.mk | 3 +-- src/board/system76/bonw14/Makefile.mk | 3 +-- src/board/system76/bonw15-b/Makefile.mk | 3 +-- src/board/system76/bonw15/Makefile.mk | 3 +-- src/board/system76/galp5/Makefile.mk | 3 +-- src/board/system76/gaze15/Makefile.mk | 3 +-- src/board/system76/gaze16-3050/Makefile.mk | 3 +-- src/board/system76/gaze16-3060-b/Makefile.mk | 3 +-- src/board/system76/gaze16-3060/Makefile.mk | 3 +-- src/board/system76/gaze17-3050/Makefile.mk | 3 +-- src/board/system76/gaze17-3060-b/Makefile.mk | 3 +-- src/board/system76/gaze17-3060/Makefile.mk | 3 +-- src/board/system76/gaze18/Makefile.mk | 3 +-- src/board/system76/gaze20/Makefile.mk | 3 +-- src/board/system76/oryp10/Makefile.mk | 3 +-- src/board/system76/oryp11/Makefile.mk | 3 +-- src/board/system76/oryp12/Makefile.mk | 3 +-- src/board/system76/oryp5/Makefile.mk | 3 +-- src/board/system76/oryp6/Makefile.mk | 3 +-- src/board/system76/oryp7/Makefile.mk | 3 +-- src/board/system76/oryp8/Makefile.mk | 3 +-- src/board/system76/oryp9/Makefile.mk | 3 +-- src/board/system76/serw13/Makefile.mk | 3 +-- src/drivers/Makefile.mk | 12 +++++++++ src/drivers/dgpu/Makefile.mk | 25 +++++++++++++++++++ .../main/include/app => drivers/dgpu}/dgpu.h | 6 ++--- .../main/dgpu.c => drivers/dgpu/nvidia.c} | 6 ++--- 37 files changed, 81 insertions(+), 72 deletions(-) create mode 100644 src/drivers/Makefile.mk create mode 100644 src/drivers/dgpu/Makefile.mk rename src/{app/main/include/app => drivers/dgpu}/dgpu.h (85%) rename src/{app/main/dgpu.c => drivers/dgpu/nvidia.c} (90%) diff --git a/Makefile b/Makefile index 41740d791..d89a050c9 100644 --- a/Makefile +++ b/Makefile @@ -28,10 +28,12 @@ all: $(BUILD)/ec.rom $(info Built $(VERSION) for $(BOARD)) ./scripts/check-home-segment.sh +CFLAGS = -Isrc/ + # Include common source COMMON_DIR=src/common INCLUDE += $(COMMON_DIR)/Makefile.mk -CFLAGS=-I$(COMMON_DIR)/include -D__FIRMWARE_VERSION__=$(VERSION) +CFLAGS += -I$(COMMON_DIR)/include -D__FIRMWARE_VERSION__=$(VERSION) include $(COMMON_DIR)/Makefile.mk SRC += $(foreach src, $(common-y), $(COMMON_DIR)/$(src)) @@ -66,6 +68,8 @@ CFLAGS += -I$(APP_DIR)/include include $(APP_DIR)/Makefile.mk SRC += $(foreach src,$(app-y),$(APP_DIR)/$(src)) +include src/drivers/Makefile.mk + include $(ARCH_DIR)/toolchain.mk # TODO: Generate config file as part of build. diff --git a/src/app/main/Makefile.mk b/src/app/main/Makefile.mk index 4a328311f..1ec3eae1b 100644 --- a/src/app/main/Makefile.mk +++ b/src/app/main/Makefile.mk @@ -3,7 +3,6 @@ app-y += acpi.c app-y += battery.c app-y += config.c -app-$(CONFIG_HAVE_DGPU) += dgpu.c app-y += ecpm.c app-$(CONFIG_BUS_ESPI) += espi.c app-y += fan.c @@ -69,11 +68,6 @@ CFLAGS += -DCONFIG_PECI_OVER_ESPI=1 endif endif -ifeq ($(CONFIG_HAVE_DGPU),y) -CFLAGS += -DCONFIG_HAVE_DGPU=1 -CFLAGS += -DI2C_DGPU=$(CONFIG_I2C_DGPU) -endif - # Fan configs ifneq ($(CONFIG_FAN1_PWM),) CFLAGS += -DFAN1_PWM=$(CONFIG_FAN1_PWM) diff --git a/src/app/main/acpi.c b/src/app/main/acpi.c index 42816843d..aecbe3fbe 100644 --- a/src/app/main/acpi.c +++ b/src/app/main/acpi.c @@ -2,7 +2,6 @@ #include #include -#include #include #include #include @@ -10,6 +9,7 @@ #include #include #include +#include #if CONFIG_PLATFORM_INTEL #include diff --git a/src/app/main/fan.c b/src/app/main/fan.c index 7adb04602..9f7614914 100644 --- a/src/app/main/fan.c +++ b/src/app/main/fan.c @@ -1,10 +1,10 @@ // SPDX-License-Identifier: GPL-3.0-only #include -#include #include #include #include +#include #include #if CONFIG_PLATFORM_INTEL diff --git a/src/app/main/kbled/bonw14.c b/src/app/main/kbled/bonw14.c index 6383cf901..ef9b7cc11 100644 --- a/src/app/main/kbled/bonw14.c +++ b/src/app/main/kbled/bonw14.c @@ -9,7 +9,7 @@ void kbled_init(void) { kbled_kind = KBLED_RGB; - i2c_reset(&I2C_DGPU, true); + i2c_reset(&DGPU_I2C, true); // Force SMBUS B design to 100kHZ SCLKTSB = 0b10; @@ -17,11 +17,11 @@ void kbled_init(void) { void kbled_reset(void) { uint8_t value = 0xE4; - int16_t res = i2c_set(&I2C_DGPU, 0x2D, 0xA0, &value, 1); + int16_t res = i2c_set(&DGPU_I2C, 0x2D, 0xA0, &value, 1); DEBUG("kbled_reset 0x2D: %d\n", res); //value = 0xC4; - //res = i2c_set(&I2C_DGPU, 0x66, 0xA0, &value, 1); + //res = i2c_set(&DGPU_I2C, 0x66, 0xA0, &value, 1); //DEBUG("kbled_reset 0x66: %d\n", res); // Set brightness and color diff --git a/src/app/main/main.c b/src/app/main/main.c index d5aaf4fd9..7950b718c 100644 --- a/src/app/main/main.c +++ b/src/app/main/main.c @@ -2,7 +2,6 @@ #include #include -#include #include #include #include @@ -25,6 +24,7 @@ #include #include #include +#include #include #if CONFIG_PLATFORM_INTEL diff --git a/src/app/main/scratch.c b/src/app/main/scratch.c index 4d89686e5..02a66c036 100644 --- a/src/app/main/scratch.c +++ b/src/app/main/scratch.c @@ -1,9 +1,9 @@ // SPDX-License-Identifier: GPL-3.0-only -#include #include #include #include +#include #include #include diff --git a/src/board/system76/addw1/Makefile.mk b/src/board/system76/addw1/Makefile.mk index 69b85e81b..16424a9c1 100644 --- a/src/board/system76/addw1/Makefile.mk +++ b/src/board/system76/addw1/Makefile.mk @@ -36,8 +36,7 @@ CONFIG_POWER_LIMIT_AC = 180 CONFIG_POWER_LIMIT_DC = 45 # Enable dGPU support -CONFIG_HAVE_DGPU = y -CONFIG_I2C_DGPU = I2C_1 +CONFIG_DRIVERS_DGPU_NVIDIA = y # Fan configs CONFIG_FAN1_PWM = DCR2 diff --git a/src/board/system76/addw2/Makefile.mk b/src/board/system76/addw2/Makefile.mk index b3dbb4935..8406c74b2 100644 --- a/src/board/system76/addw2/Makefile.mk +++ b/src/board/system76/addw2/Makefile.mk @@ -36,8 +36,7 @@ CONFIG_POWER_LIMIT_AC = 180 CONFIG_POWER_LIMIT_DC = 45 # Enable dGPU support -CONFIG_HAVE_DGPU = y -CONFIG_I2C_DGPU = I2C_1 +CONFIG_DRIVERS_DGPU_NVIDIA = y # Fan configs CONFIG_FAN1_PWM = DCR2 diff --git a/src/board/system76/addw3/Makefile.mk b/src/board/system76/addw3/Makefile.mk index 118bae85b..d6192dd9e 100644 --- a/src/board/system76/addw3/Makefile.mk +++ b/src/board/system76/addw3/Makefile.mk @@ -42,8 +42,7 @@ CONFIG_POWER_LIMIT_AC = 280 CONFIG_POWER_LIMIT_DC = 55 # Enable dGPU support -CONFIG_HAVE_DGPU = y -CONFIG_I2C_DGPU = I2C_1 +CONFIG_DRIVERS_DGPU_NVIDIA = y # Fan configs CONFIG_FAN1_PWM = DCR2 diff --git a/src/board/system76/addw4/Makefile.mk b/src/board/system76/addw4/Makefile.mk index 1ddd87e0b..a61af4b28 100644 --- a/src/board/system76/addw4/Makefile.mk +++ b/src/board/system76/addw4/Makefile.mk @@ -38,8 +38,7 @@ CONFIG_POWER_LIMIT_AC = 230 CONFIG_POWER_LIMIT_DC = 45 # Enable DGPU support -CONFIG_HAVE_DGPU = y -CONFIG_I2C_DGPU = I2C_1 +CONFIG_DRIVERS_DGPU_NVIDIA = y # Fan configs CONFIG_FAN1_PWM = DCR2 diff --git a/src/board/system76/bonw14/Makefile.mk b/src/board/system76/bonw14/Makefile.mk index 2353dbd1a..fd1250c20 100644 --- a/src/board/system76/bonw14/Makefile.mk +++ b/src/board/system76/bonw14/Makefile.mk @@ -36,8 +36,7 @@ CONFIG_POWER_LIMIT_AC = 180 CONFIG_POWER_LIMIT_DC = 45 # Enable dGPU support -CONFIG_HAVE_DGPU = y -CONFIG_I2C_DGPU = I2C_1 +CONFIG_DRIVERS_DGPU_NVIDIA = y # Fan configs CONFIG_FAN1_PWM = DCR2 diff --git a/src/board/system76/bonw15-b/Makefile.mk b/src/board/system76/bonw15-b/Makefile.mk index d1da7b8bf..105b99006 100644 --- a/src/board/system76/bonw15-b/Makefile.mk +++ b/src/board/system76/bonw15-b/Makefile.mk @@ -49,8 +49,7 @@ CONFIG_POWER_LIMIT_AC = 330 CONFIG_POWER_LIMIT_DC = 55 # Enable dGPU support -CONFIG_HAVE_DGPU = y -CONFIG_I2C_DGPU = I2C_1 +CONFIG_DRIVERS_DGPU_NVIDIA = y # Fan configs CONFIG_FAN1_PWM = DCR2 diff --git a/src/board/system76/bonw15/Makefile.mk b/src/board/system76/bonw15/Makefile.mk index 3fa519475..6ca3a141f 100644 --- a/src/board/system76/bonw15/Makefile.mk +++ b/src/board/system76/bonw15/Makefile.mk @@ -46,8 +46,7 @@ CONFIG_POWER_LIMIT_AC = 330 CONFIG_POWER_LIMIT_DC = 55 # Enable dGPU support -CONFIG_HAVE_DGPU = y -CONFIG_I2C_DGPU = I2C_1 +CONFIG_DRIVERS_DGPU_NVIDIA = y # Fan configs CONFIG_FAN1_PWM = DCR2 diff --git a/src/board/system76/galp5/Makefile.mk b/src/board/system76/galp5/Makefile.mk index c06f60fa1..e37c828d3 100644 --- a/src/board/system76/galp5/Makefile.mk +++ b/src/board/system76/galp5/Makefile.mk @@ -39,8 +39,7 @@ CONFIG_POWER_LIMIT_AC = 65 CONFIG_POWER_LIMIT_DC = 45 # Enable dGPU support -CONFIG_HAVE_DGPU = y -CONFIG_I2C_DGPU = I2C_1 +CONFIG_DRIVERS_DGPU_NVIDIA = y # Fan configs CONFIG_FAN1_PWM = DCR2 diff --git a/src/board/system76/gaze15/Makefile.mk b/src/board/system76/gaze15/Makefile.mk index 4bfeeafef..d8dc9dae7 100644 --- a/src/board/system76/gaze15/Makefile.mk +++ b/src/board/system76/gaze15/Makefile.mk @@ -36,8 +36,7 @@ CONFIG_POWER_LIMIT_AC = 180 CONFIG_POWER_LIMIT_DC = 45 # Enable dGPU support -CONFIG_HAVE_DGPU = y -CONFIG_I2C_DGPU = I2C_1 +CONFIG_DRIVERS_DGPU_NVIDIA = y # Fan configs CONFIG_FAN1_PWM = DCR2 diff --git a/src/board/system76/gaze16-3050/Makefile.mk b/src/board/system76/gaze16-3050/Makefile.mk index 148fb1130..f18b8df94 100644 --- a/src/board/system76/gaze16-3050/Makefile.mk +++ b/src/board/system76/gaze16-3050/Makefile.mk @@ -38,8 +38,7 @@ CONFIG_POWER_LIMIT_AC = 180 CONFIG_POWER_LIMIT_DC = 45 # Enable dGPU support -CONFIG_HAVE_DGPU = y -CONFIG_I2C_DGPU = I2C_1 +CONFIG_DRIVERS_DGPU_NVIDIA = y # Fan configs CONFIG_FAN1_PWM = DCR2 diff --git a/src/board/system76/gaze16-3060-b/Makefile.mk b/src/board/system76/gaze16-3060-b/Makefile.mk index 6f5fa5790..dd001647d 100644 --- a/src/board/system76/gaze16-3060-b/Makefile.mk +++ b/src/board/system76/gaze16-3060-b/Makefile.mk @@ -41,8 +41,7 @@ CONFIG_POWER_LIMIT_AC = 180 CONFIG_POWER_LIMIT_DC = 45 # Enable dGPU support -CONFIG_HAVE_DGPU = y -CONFIG_I2C_DGPU = I2C_1 +CONFIG_DRIVERS_DGPU_NVIDIA = y # Fan configs CONFIG_FAN1_PWM = DCR2 diff --git a/src/board/system76/gaze16-3060/Makefile.mk b/src/board/system76/gaze16-3060/Makefile.mk index 1db875caa..91cd21cc2 100644 --- a/src/board/system76/gaze16-3060/Makefile.mk +++ b/src/board/system76/gaze16-3060/Makefile.mk @@ -38,8 +38,7 @@ CONFIG_POWER_LIMIT_AC = 180 CONFIG_POWER_LIMIT_DC = 45 # Enable dGPU support -CONFIG_HAVE_DGPU = y -CONFIG_I2C_DGPU = I2C_1 +CONFIG_DRIVERS_DGPU_NVIDIA = y # Fan configs CONFIG_FAN1_PWM = DCR2 diff --git a/src/board/system76/gaze17-3050/Makefile.mk b/src/board/system76/gaze17-3050/Makefile.mk index 865958057..6f0b7add1 100644 --- a/src/board/system76/gaze17-3050/Makefile.mk +++ b/src/board/system76/gaze17-3050/Makefile.mk @@ -39,8 +39,7 @@ CONFIG_POWER_LIMIT_AC = 180 CONFIG_POWER_LIMIT_DC = 45 # Enable dGPU support -CONFIG_HAVE_DGPU = y -CONFIG_I2C_DGPU = I2C_1 +CONFIG_DRIVERS_DGPU_NVIDIA = y # Fan configs CONFIG_FAN1_PWM = DCR2 diff --git a/src/board/system76/gaze17-3060-b/Makefile.mk b/src/board/system76/gaze17-3060-b/Makefile.mk index 8d36d7920..b0049f816 100644 --- a/src/board/system76/gaze17-3060-b/Makefile.mk +++ b/src/board/system76/gaze17-3060-b/Makefile.mk @@ -42,8 +42,7 @@ CONFIG_POWER_LIMIT_AC = 180 CONFIG_POWER_LIMIT_DC = 45 # Enable dGPU support -CONFIG_HAVE_DGPU = y -CONFIG_I2C_DGPU = I2C_1 +CONFIG_DRIVERS_DGPU_NVIDIA = y # Fan configs CONFIG_FAN1_PWM = DCR2 diff --git a/src/board/system76/gaze17-3060/Makefile.mk b/src/board/system76/gaze17-3060/Makefile.mk index 3d5e39cd2..bed0a5226 100644 --- a/src/board/system76/gaze17-3060/Makefile.mk +++ b/src/board/system76/gaze17-3060/Makefile.mk @@ -39,8 +39,7 @@ CONFIG_POWER_LIMIT_AC = 180 CONFIG_POWER_LIMIT_DC = 45 # Enable dGPU support -CONFIG_HAVE_DGPU = y -CONFIG_I2C_DGPU = I2C_1 +CONFIG_DRIVERS_DGPU_NVIDIA = y # Fan configs CONFIG_FAN1_PWM = DCR2 diff --git a/src/board/system76/gaze18/Makefile.mk b/src/board/system76/gaze18/Makefile.mk index fe1fb1b76..b86620408 100644 --- a/src/board/system76/gaze18/Makefile.mk +++ b/src/board/system76/gaze18/Makefile.mk @@ -41,8 +41,7 @@ CONFIG_POWER_LIMIT_AC = 150 CONFIG_POWER_LIMIT_DC = 45 # Enable dGPU support -CONFIG_HAVE_DGPU = y -CONFIG_I2C_DGPU = I2C_1 +CONFIG_DRIVERS_DGPU_NVIDIA = y # Fan configs CONFIG_FAN1_PWM = DCR2 diff --git a/src/board/system76/gaze20/Makefile.mk b/src/board/system76/gaze20/Makefile.mk index 5a70b0683..10922f315 100644 --- a/src/board/system76/gaze20/Makefile.mk +++ b/src/board/system76/gaze20/Makefile.mk @@ -37,8 +37,7 @@ CONFIG_POWER_LIMIT_AC = 180 CONFIG_POWER_LIMIT_DC = 45 # Enable DGPU support -CONFIG_HAVE_DGPU = y -CONFIG_I2C_DGPU = I2C_1 +CONFIG_DRIVERS_DGPU_NVIDIA = y # Fan configs CONFIG_FAN1_PWM = DCR2 diff --git a/src/board/system76/oryp10/Makefile.mk b/src/board/system76/oryp10/Makefile.mk index 795850244..47122f9d2 100644 --- a/src/board/system76/oryp10/Makefile.mk +++ b/src/board/system76/oryp10/Makefile.mk @@ -45,8 +45,7 @@ CONFIG_POWER_LIMIT_AC = 180 CONFIG_POWER_LIMIT_DC = 45 # Enable dGPU support -CONFIG_HAVE_DGPU = y -CONFIG_I2C_DGPU = I2C_1 +CONFIG_DRIVERS_DGPU_NVIDIA = y # Fan configs CONFIG_FAN1_PWM = DCR2 diff --git a/src/board/system76/oryp11/Makefile.mk b/src/board/system76/oryp11/Makefile.mk index 3f7c7bea2..bef36563b 100644 --- a/src/board/system76/oryp11/Makefile.mk +++ b/src/board/system76/oryp11/Makefile.mk @@ -47,8 +47,7 @@ CONFIG_POWER_LIMIT_AC = 230 CONFIG_POWER_LIMIT_DC = 55 # Enable dGPU support -CONFIG_HAVE_DGPU = y -CONFIG_I2C_DGPU = I2C_1 +CONFIG_DRIVERS_DGPU_NVIDIA = y # Fan configs CONFIG_FAN1_PWM = DCR2 diff --git a/src/board/system76/oryp12/Makefile.mk b/src/board/system76/oryp12/Makefile.mk index 672c5dd8a..0e9711c13 100644 --- a/src/board/system76/oryp12/Makefile.mk +++ b/src/board/system76/oryp12/Makefile.mk @@ -44,8 +44,7 @@ CONFIG_POWER_LIMIT_AC = 230 CONFIG_POWER_LIMIT_DC = 55 # Enable DGPU support -CONFIG_HAVE_DGPU = y -CONFIG_I2C_DGPU = I2C_1 +CONFIG_DRIVERS_DGPU_NVIDIA = y # Fan configs CONFIG_FAN1_PWM = DCR2 diff --git a/src/board/system76/oryp5/Makefile.mk b/src/board/system76/oryp5/Makefile.mk index 980d9aa4e..9b4a033b9 100644 --- a/src/board/system76/oryp5/Makefile.mk +++ b/src/board/system76/oryp5/Makefile.mk @@ -38,8 +38,7 @@ CONFIG_POWER_LIMIT_AC = 180 CONFIG_POWER_LIMIT_DC = 45 # Enable dGPU support -CONFIG_HAVE_DGPU = y -CONFIG_I2C_DGPU = I2C_1 +CONFIG_DRIVERS_DGPU_NVIDIA = y # Fan configs CONFIG_FAN1_PWM = DCR2 diff --git a/src/board/system76/oryp6/Makefile.mk b/src/board/system76/oryp6/Makefile.mk index 08d276c36..e9e1990de 100644 --- a/src/board/system76/oryp6/Makefile.mk +++ b/src/board/system76/oryp6/Makefile.mk @@ -36,8 +36,7 @@ CONFIG_POWER_LIMIT_AC = 180 CONFIG_POWER_LIMIT_DC = 45 # Enable dGPU support -CONFIG_HAVE_DGPU = y -CONFIG_I2C_DGPU = I2C_1 +CONFIG_DRIVERS_DGPU_NVIDIA = y # Fan configs CONFIG_FAN1_PWM = DCR2 diff --git a/src/board/system76/oryp7/Makefile.mk b/src/board/system76/oryp7/Makefile.mk index 08d276c36..e9e1990de 100644 --- a/src/board/system76/oryp7/Makefile.mk +++ b/src/board/system76/oryp7/Makefile.mk @@ -36,8 +36,7 @@ CONFIG_POWER_LIMIT_AC = 180 CONFIG_POWER_LIMIT_DC = 45 # Enable dGPU support -CONFIG_HAVE_DGPU = y -CONFIG_I2C_DGPU = I2C_1 +CONFIG_DRIVERS_DGPU_NVIDIA = y # Fan configs CONFIG_FAN1_PWM = DCR2 diff --git a/src/board/system76/oryp8/Makefile.mk b/src/board/system76/oryp8/Makefile.mk index 33754ed9a..ba28e38b1 100644 --- a/src/board/system76/oryp8/Makefile.mk +++ b/src/board/system76/oryp8/Makefile.mk @@ -37,8 +37,7 @@ CONFIG_POWER_LIMIT_AC = 180 CONFIG_POWER_LIMIT_DC = 45 # Enable dGPU support -CONFIG_HAVE_DGPU = y -CONFIG_I2C_DGPU = I2C_1 +CONFIG_DRIVERS_DGPU_NVIDIA = y # Fan configs CONFIG_FAN1_PWM = DCR2 diff --git a/src/board/system76/oryp9/Makefile.mk b/src/board/system76/oryp9/Makefile.mk index 7e77ed34d..cf94b7e9b 100644 --- a/src/board/system76/oryp9/Makefile.mk +++ b/src/board/system76/oryp9/Makefile.mk @@ -42,8 +42,7 @@ CONFIG_POWER_LIMIT_AC = 180 CONFIG_POWER_LIMIT_DC = 45 # Enable dGPU support -CONFIG_HAVE_DGPU = y -CONFIG_I2C_DGPU = I2C_1 +CONFIG_DRIVERS_DGPU_NVIDIA = y # Fan configs CONFIG_FAN1_PWM = DCR2 diff --git a/src/board/system76/serw13/Makefile.mk b/src/board/system76/serw13/Makefile.mk index 716673974..8610524c5 100644 --- a/src/board/system76/serw13/Makefile.mk +++ b/src/board/system76/serw13/Makefile.mk @@ -46,8 +46,7 @@ CONFIG_POWER_LIMIT_AC = 280 CONFIG_POWER_LIMIT_DC = 55 # Enable dGPU support -CONFIG_HAVE_DGPU = y -CONFIG_I2C_DGPU = I2C_1 +CONFIG_DRIVERS_DGPU_NVIDIA = y # Fan configs CONFIG_FAN1_PWM = DCR2 diff --git a/src/drivers/Makefile.mk b/src/drivers/Makefile.mk new file mode 100644 index 000000000..69e733b1e --- /dev/null +++ b/src/drivers/Makefile.mk @@ -0,0 +1,12 @@ +# SPDX-License-Identifier: GPL-3.0-only +# SPDX-FileCopyrightText: 2025 System76, Inc. + +subdirs-y := $(wildcard src/drivers/*) + +$(foreach subdir,$(subdirs-y), \ + $(if $(wildcard $(subdir)/Makefile.mk), \ + $(eval drivers-y:=) \ + $(eval include $(subdir)/Makefile.mk) \ + $(eval INCLUDE+=$(subdir)/Makefile.mk) \ + $(foreach src,$(drivers-y), \ + $(eval SRC+=$(addprefix $(subdir)/,$(src)))))) diff --git a/src/drivers/dgpu/Makefile.mk b/src/drivers/dgpu/Makefile.mk new file mode 100644 index 000000000..15ed3b08f --- /dev/null +++ b/src/drivers/dgpu/Makefile.mk @@ -0,0 +1,25 @@ +# SPDX-License-Identifier: GPL-3.0-only +# SPDX-FileCopyrightText: 2025 System76, Inc. + +# Discrete GPU (dGPU) support. +# +# Options: +# - `CONFIG_DGPU_I2C`: Board may override the I2C device index to use. + +ifeq ($(CONFIG_DRIVERS_DGPU_NVIDIA),y) +CONFIG_HAVE_DGPU = y +endif + +ifeq ($(CONFIG_HAVE_DGPU),y) + +CFLAGS += -DCONFIG_HAVE_DGPU=1 + +ifeq ($(CONFIG_DGPU_I2C),) +CONFIG_DGPU_I2C = 1 +endif + +CFLAGS += -DDGPU_I2C=I2C_$(CONFIG_DGPU_I2C) + +drivers-$(CONFIG_DRIVERS_DGPU_NVIDIA) += nvidia.c + +endif diff --git a/src/app/main/include/app/dgpu.h b/src/drivers/dgpu/dgpu.h similarity index 85% rename from src/app/main/include/app/dgpu.h rename to src/drivers/dgpu/dgpu.h index 18ab0a4a0..e1cd28a09 100644 --- a/src/app/main/include/app/dgpu.h +++ b/src/drivers/dgpu/dgpu.h @@ -1,7 +1,7 @@ // SPDX-License-Identifier: GPL-3.0-only -#ifndef _APP_DGPU_H -#define _APP_DGPU_H +#ifndef _DRIVERS_DGPU_H +#define _DRIVERS_DGPU_H #include #include @@ -27,4 +27,4 @@ static inline void dgpu_read_temp(void) {} #endif // CONFIG_HAVE_DGPU -#endif // _APP_DGPU_H +#endif // _DRIVERS_DGPU_H diff --git a/src/app/main/dgpu.c b/src/drivers/dgpu/nvidia.c similarity index 90% rename from src/app/main/dgpu.c rename to src/drivers/dgpu/nvidia.c index 85b749e33..dd353b98c 100644 --- a/src/app/main/dgpu.c +++ b/src/drivers/dgpu/nvidia.c @@ -1,6 +1,6 @@ // SPDX-License-Identifier: GPL-3.0-only -#include +#include "dgpu.h" #include #include #include @@ -14,13 +14,13 @@ static int16_t dgpu_temps[4] = { 0 }; void dgpu_init(void) { // Set up for i2c usage - i2c_reset(&I2C_DGPU, true); + i2c_reset(&DGPU_I2C, true); } bool dgpu_get_temp(int16_t *const data) { if (gpio_get(&DGPU_PWR_EN) && !gpio_get(&GC6_FB_EN)) { int8_t rlts; - int16_t res = i2c_get(&I2C_DGPU, 0x4F, 0x00, &rlts, 1); + int16_t res = i2c_get(&DGPU_I2C, 0x4F, 0x00, &rlts, 1); if (res == 1) { *data = (int16_t)rlts; return true; From 88da2031a4d40c44555e8f1fc6688933b46f3c61 Mon Sep 17 00:00:00 2001 From: Tim Crawford Date: Mon, 8 Sep 2025 18:14:02 -0600 Subject: [PATCH 2/3] Move USB-PD support from common to drivers - Boards select the specific `DRIVERS_USBPD_*` config - Boards no longer select `HAVE_USBPD` directly - `I2C_USBPD` is renamed to `USBPD_I2C` - I2C controller selection is just the integer index Signed-off-by: Tim Crawford --- src/app/main/Makefile.mk | 7 ------ src/app/main/main.c | 2 +- src/app/main/power/intel.c | 2 +- src/board/system76/bonw15-b/Makefile.mk | 4 +-- src/board/system76/bonw15/Makefile.mk | 4 +-- src/board/system76/oryp11/Makefile.mk | 4 +-- src/board/system76/oryp12/Makefile.mk | 4 +-- src/board/system76/serw13/Makefile.mk | 4 +-- src/drivers/usbpd/Makefile.mk | 25 +++++++++++++++++++ src/{app/main => drivers}/usbpd/tps65987.c | 18 ++++++------- .../include/app => drivers/usbpd}/usbpd.h | 6 ++--- 11 files changed, 44 insertions(+), 36 deletions(-) create mode 100644 src/drivers/usbpd/Makefile.mk rename src/{app/main => drivers}/usbpd/tps65987.c (93%) rename src/{app/main/include/app => drivers/usbpd}/usbpd.h (83%) diff --git a/src/app/main/Makefile.mk b/src/app/main/Makefile.mk index 1ec3eae1b..f1770ef40 100644 --- a/src/app/main/Makefile.mk +++ b/src/app/main/Makefile.mk @@ -106,13 +106,6 @@ CFLAGS += -DCHARGER_PSYS_GAIN=$(CONFIG_CHARGER_PSYS_GAIN) endif endif -# Add USB-PD -ifeq ($(CONFIG_HAVE_USBPD),y) -CFLAGS += -DCONFIG_HAVE_USBPD=1 -app-$(CONFIG_USBPD_TPS65987) += usbpd/tps65987.c -CFLAGS += -DI2C_USBPD=$(CONFIG_I2C_USBPD) -endif - # Add keyboard ifndef KEYBOARD $(error KEYBOARD is not set by the board) diff --git a/src/app/main/main.c b/src/app/main/main.c index 7950b718c..34148fca3 100644 --- a/src/app/main/main.c +++ b/src/app/main/main.c @@ -15,7 +15,6 @@ #include #include #include -#include #include #include #include @@ -25,6 +24,7 @@ #include #include #include +#include #include #if CONFIG_PLATFORM_INTEL diff --git a/src/app/main/power/intel.c b/src/app/main/power/intel.c index 6af2614f8..bc9b37a0d 100644 --- a/src/app/main/power/intel.c +++ b/src/app/main/power/intel.c @@ -13,12 +13,12 @@ #include #include #include -#include #include #include #include #include #include +#include #if CONFIG_BUS_ESPI #include diff --git a/src/board/system76/bonw15-b/Makefile.mk b/src/board/system76/bonw15-b/Makefile.mk index 105b99006..9ef1e2daa 100644 --- a/src/board/system76/bonw15-b/Makefile.mk +++ b/src/board/system76/bonw15-b/Makefile.mk @@ -40,9 +40,7 @@ CONFIG_CHARGER_CHARGE_VOLTAGE = 17400 CONFIG_CHARGER_INPUT_CURRENT = 16920 # Set USB-PD parameters -CONFIG_HAVE_USBPD = y -CONFIG_USBPD_TPS65987 = y -CONFIG_I2C_USBPD = I2C_1 +CONFIG_DRIVERS_USBPD_TPS65987 = y # Set CPU power limits in watts CONFIG_POWER_LIMIT_AC = 330 diff --git a/src/board/system76/bonw15/Makefile.mk b/src/board/system76/bonw15/Makefile.mk index 6ca3a141f..52b850c43 100644 --- a/src/board/system76/bonw15/Makefile.mk +++ b/src/board/system76/bonw15/Makefile.mk @@ -37,9 +37,7 @@ CONFIG_CHARGER_CHARGE_VOLTAGE = 17400 CONFIG_CHARGER_INPUT_CURRENT = 16920 # Set USB-PD parameters -CONFIG_HAVE_USBPD = y -CONFIG_USBPD_TPS65987 = y -CONFIG_I2C_USBPD = I2C_1 +CONFIG_DRIVERS_USBPD_TPS65987 = y # Set CPU power limits in watts CONFIG_POWER_LIMIT_AC = 330 diff --git a/src/board/system76/oryp11/Makefile.mk b/src/board/system76/oryp11/Makefile.mk index bef36563b..b7fef1dbf 100644 --- a/src/board/system76/oryp11/Makefile.mk +++ b/src/board/system76/oryp11/Makefile.mk @@ -38,9 +38,7 @@ CONFIG_CHARGER_CHARGE_VOLTAGE = 17600 CONFIG_CHARGER_INPUT_CURRENT = 11500 # Set USB-PD parameters -CONFIG_HAVE_USBPD = y -CONFIG_USBPD_TPS65987 = y -CONFIG_I2C_USBPD = I2C_1 +CONFIG_DRIVERS_USBPD_TPS65987 = y # Set CPU power limits in watts CONFIG_POWER_LIMIT_AC = 230 diff --git a/src/board/system76/oryp12/Makefile.mk b/src/board/system76/oryp12/Makefile.mk index 0e9711c13..939e67d13 100644 --- a/src/board/system76/oryp12/Makefile.mk +++ b/src/board/system76/oryp12/Makefile.mk @@ -35,9 +35,7 @@ CONFIG_CHARGER_CHARGE_VOLTAGE = 17600 CONFIG_CHARGER_INPUT_CURRENT = 11500 # Set USB-PD parameters -CONFIG_HAVE_USBPD = y -CONFIG_USBPD_TPS65987 = y -CONFIG_I2C_USBPD = I2C_1 +CONFIG_DRIVERS_USBPD_TPS65987 = y # Set CPU power limits in watts CONFIG_POWER_LIMIT_AC = 230 diff --git a/src/board/system76/serw13/Makefile.mk b/src/board/system76/serw13/Makefile.mk index 8610524c5..bd6b2b178 100644 --- a/src/board/system76/serw13/Makefile.mk +++ b/src/board/system76/serw13/Makefile.mk @@ -37,9 +37,7 @@ CONFIG_CHARGER_CHARGE_VOLTAGE = 13050 CONFIG_CHARGER_INPUT_CURRENT = 14000 # Set USB-PD parameters -CONFIG_HAVE_USBPD = y -CONFIG_USBPD_TPS65987 = y -CONFIG_I2C_USBPD = I2C_1 +CONFIG_DRIVERS_USBPD_TPS65987 = y # Set CPU power limits in watts CONFIG_POWER_LIMIT_AC = 280 diff --git a/src/drivers/usbpd/Makefile.mk b/src/drivers/usbpd/Makefile.mk new file mode 100644 index 000000000..bd8f2d00c --- /dev/null +++ b/src/drivers/usbpd/Makefile.mk @@ -0,0 +1,25 @@ +# SPDX-License-Identifier: GPL-3.0-only +# SPDX-FileCopyrightText: 2025 System76, Inc. + +# USB Power Delivery (USB-PD) support. +# +# Options: +# - `CONFIG_USBPD_I2C`: Board may override the I2C device index to use. + +ifeq ($(CONFIG_DRIVERS_USBPD_TPS65987),y) +CONFIG_HAVE_USBPD = y +endif + +ifeq ($(CONFIG_HAVE_USBPD),y) + +CFLAGS += -DCONFIG_HAVE_USBPD=1 + +ifeq ($(CONFIG_USBPD_I2C),) +CONFIG_USBPD_I2C = 1 +endif + +CFLAGS += -DUSBPD_I2C=I2C_$(CONFIG_USBPD_I2C) + +drivers-$(CONFIG_DRIVERS_USBPD_TPS65987) += tps65987.c + +endif diff --git a/src/app/main/usbpd/tps65987.c b/src/drivers/usbpd/tps65987.c similarity index 93% rename from src/app/main/usbpd/tps65987.c rename to src/drivers/usbpd/tps65987.c index 5260408e7..60b5e7253 100644 --- a/src/app/main/usbpd/tps65987.c +++ b/src/drivers/usbpd/tps65987.c @@ -3,7 +3,7 @@ // USB-PD driver for TPS65987 and the mostly compatible TPS65993 and TPS65994. // I2C register reference: https://www.ti.com/lit/ug/slvubh2b/slvubh2b.pdf -#include +#include "usbpd.h" #include #include #include @@ -15,12 +15,12 @@ #define REG_ACTIVE_CONTRACT_PDO 0x34 void usbpd_init(void) { - i2c_reset(&I2C_USBPD, true); + i2c_reset(&USBPD_I2C, true); } static int16_t usbpd_current_limit(void) { uint8_t value[7] = { 0 }; - int16_t res = i2c_get(&I2C_USBPD, USBPD_ADDRESS, REG_ACTIVE_CONTRACT_PDO, value, sizeof(value)); + int16_t res = i2c_get(&USBPD_I2C, USBPD_ADDRESS, REG_ACTIVE_CONTRACT_PDO, value, sizeof(value)); if (res == 7) { if (value[0] == 6) { uint32_t pdo = ((uint32_t)value[1]) | (((uint32_t)value[2]) << 8) | @@ -72,7 +72,7 @@ static void usbpd_dump(void) { // Dump all registers for debugging for (uint8_t reg = 0x00; reg < 0x40; reg += 1) { uint8_t value[65] = { 0 }; - int16_t res = i2c_get(&I2C_USBPD, USBPD_ADDRESS, reg, value, sizeof(value)); + int16_t res = i2c_get(&USBPD_I2C, USBPD_ADDRESS, reg, value, sizeof(value)); if (res < 0) { DEBUG("USBPD %02X ERROR %04X\n", reg, res); } else { @@ -168,7 +168,7 @@ static int16_t usbpd_aneg(void) { int16_t res; uint8_t cmd[5] = { 4, 'A', 'N', 'e', 'g' }; - res = i2c_set(&I2C_USBPD, USBPD_ADDRESS, 0x08, cmd, sizeof(cmd)); + res = i2c_set(&USBPD_I2C, USBPD_ADDRESS, 0x08, cmd, sizeof(cmd)); if (res < 0) { return res; } @@ -185,7 +185,7 @@ void usbpd_disable_charging(void) { // Read current value uint8_t value[2] = { 0 }; - res = i2c_get(&I2C_USBPD, USBPD_ADDRESS, 0x33, value, sizeof(value)); + res = i2c_get(&USBPD_I2C, USBPD_ADDRESS, 0x33, value, sizeof(value)); if (res < 0) { DEBUG("ERR %04X\n", -res); return; @@ -200,7 +200,7 @@ void usbpd_disable_charging(void) { // Enable only the first TX sink PDO (5V) value[0] = 1; value[1] = 1; - res = i2c_set(&I2C_USBPD, USBPD_ADDRESS, 0x33, value, sizeof(value)); + res = i2c_set(&USBPD_I2C, USBPD_ADDRESS, 0x33, value, sizeof(value)); if (res < 0) { DEBUG("ERR %04X\n", -res); return; @@ -223,7 +223,7 @@ void usbpd_enable_charging(void) { // Read current value uint8_t value[2] = { 0 }; - res = i2c_get(&I2C_USBPD, USBPD_ADDRESS, 0x33, value, sizeof(value)); + res = i2c_get(&USBPD_I2C, USBPD_ADDRESS, 0x33, value, sizeof(value)); if (res < 0) { DEBUG("ERR %04X\n", -res); return; @@ -238,7 +238,7 @@ void usbpd_enable_charging(void) { // Enable the first two TX sink PDO (5V and 20V) value[0] = 1; value[1] = 2; - res = i2c_set(&I2C_USBPD, USBPD_ADDRESS, 0x33, value, sizeof(value)); + res = i2c_set(&USBPD_I2C, USBPD_ADDRESS, 0x33, value, sizeof(value)); if (res < 0) { DEBUG("ERR %04X\n", -res); return; diff --git a/src/app/main/include/app/usbpd.h b/src/drivers/usbpd/usbpd.h similarity index 83% rename from src/app/main/include/app/usbpd.h rename to src/drivers/usbpd/usbpd.h index 47fd5a037..15c2e5643 100644 --- a/src/app/main/include/app/usbpd.h +++ b/src/drivers/usbpd/usbpd.h @@ -1,7 +1,7 @@ // SPDX-License-Identifier: GPL-3.0-only -#ifndef _APP_USBPD_H -#define _APP_USBPD_H +#ifndef _DRIVERS_USBPD_H +#define _DRIVERS_USBPD_H #if CONFIG_HAVE_USBPD @@ -19,4 +19,4 @@ static inline void usbpd_enable_charging(void) {} #endif -#endif // _APP_USBPD_H +#endif // _DRIVERS_USBPD_H From 82870383e7680911a1a74bc9549348e92b039313 Mon Sep 17 00:00:00 2001 From: Tim Crawford Date: Tue, 18 Nov 2025 13:29:36 -0700 Subject: [PATCH 3/3] Move security support from common to drivers - No board change; continue selecting `SECURITY` config - Security state enum moved to driver header - Update related doc Signed-off-by: Tim Crawford --- docs/security.md | 17 +++++++----- src/app/main/Makefile.mk | 5 ---- src/app/main/include/app/security.h | 13 --------- src/app/main/power/intel.c | 2 +- src/app/main/security.c | 2 +- src/app/main/smfi.c | 2 +- src/common/include/common/command.h | 11 -------- src/drivers/security/Makefile.mk | 19 +++++++++++++ src/drivers/security/security.c | 41 +++++++++++++++++++++++++++++ src/drivers/security/security.h | 23 ++++++++++++++++ 10 files changed, 97 insertions(+), 38 deletions(-) delete mode 100644 src/app/main/include/app/security.h create mode 100644 src/drivers/security/Makefile.mk create mode 100644 src/drivers/security/security.c create mode 100644 src/drivers/security/security.h diff --git a/docs/security.md b/docs/security.md index 7fb686b46..e5b0f73bb 100644 --- a/docs/security.md +++ b/docs/security.md @@ -1,13 +1,18 @@ # Firmware security The firmware security feature can be configured by setting `CONFIG_SECURITY=1` -in the `src/board/system76/[board]/board.mk` file. This feature prevents +in the `src/board/system76//board.mk` file. This feature prevents programming the EC firmware at runtime, unless the EC is unlocked with the `system76-ectool security unlock` command. After this, on the next reboot, the -EC will respond to the SPI and reset commands. On boards where the `ME_WE` GPIO -exists, it will be set high when the EC security state is unlocked. +EC will respond to the SPI and reset commands. + +This feature will drive the `ME_WE` pin high when the state is unlocked. On +Intel hosts, this pin is connected to `HDA_SDO` and will disable security +policies set in the flash descriptor. + +- `HDA_SDO`: Flash Descriptor Security Override Other firmware components can use this state to perform their own locking and -unlocking primitives. For example, in `coreboot`, flash regions may be locked -when the EC security state is locked. In `EDK2`, a physical presence dialog may -be shown when the EC security state is unlocked. +unlocking primitives. For example, in coreboot, flash regions may be locked +when the EC security state is locked. In the UEFI payload, a physical presence +dialog may be shown when the EC security state is unlocked. diff --git a/src/app/main/Makefile.mk b/src/app/main/Makefile.mk index f1770ef40..73101a00b 100644 --- a/src/app/main/Makefile.mk +++ b/src/app/main/Makefile.mk @@ -18,7 +18,6 @@ app-y += pnp.c app-y += ps2.c app-y += pwm.c app-y += scratch.c -app-$(CONFIG_SECURITY) += security.c app-y += smbus.c app-y += smfi.c app-y += stdio.c @@ -40,10 +39,6 @@ CFLAGS += -DI2C_SMBUS=$(CONFIG_I2C_SMBUS) # Uncomment to enable I2C debug on 0x76 #CFLAGS+=-DI2C_DEBUGGER=0x76 -ifeq ($(CONFIG_SECURITY),y) -CFLAGS+=-DCONFIG_SECURITY=1 -endif - ifeq ($(CONFIG_PLATFORM_INTEL),y) app-y += peci.c app-y += power/intel.c diff --git a/src/app/main/include/app/security.h b/src/app/main/include/app/security.h deleted file mode 100644 index caafb79f0..000000000 --- a/src/app/main/include/app/security.h +++ /dev/null @@ -1,13 +0,0 @@ -// SPDX-License-Identifier: GPL-3.0-only - -#ifndef _APP_SECURITY_H -#define _APP_SECURITY_H - -#include -#include - -enum SecurityState security_get(void); -bool security_set(enum SecurityState state); -bool security_power(void); - -#endif // _APP_SECURITY_H diff --git a/src/app/main/power/intel.c b/src/app/main/power/intel.c index bc9b37a0d..a6afbb3d1 100644 --- a/src/app/main/power/intel.c +++ b/src/app/main/power/intel.c @@ -26,7 +26,7 @@ #endif #if CONFIG_SECURITY -#include +#include #endif // CONFIG_SECURITY #define GPIO_SET_DEBUG(G, V) \ diff --git a/src/app/main/security.c b/src/app/main/security.c index edb1bae0e..011d88f97 100644 --- a/src/app/main/security.c +++ b/src/app/main/security.c @@ -1,6 +1,6 @@ // SPDX-License-Identifier: GPL-3.0-only -#include +#include "security.h" #include static enum SecurityState security_state = SECURITY_STATE_LOCK; diff --git a/src/app/main/smfi.c b/src/app/main/smfi.c index 4ec73ffec..5c61b75f2 100644 --- a/src/app/main/smfi.c +++ b/src/app/main/smfi.c @@ -22,7 +22,7 @@ #include #if CONFIG_SECURITY -#include +#include #endif // CONFIG_SECURITY #endif // !defined(__SCRATCH__) diff --git a/src/common/include/common/command.h b/src/common/include/common/command.h index 0e17e51f4..ecec85bd0 100644 --- a/src/common/include/common/command.h +++ b/src/common/include/common/command.h @@ -77,15 +77,4 @@ enum CommandSpiFlag { #define CMD_LED_INDEX_ALL 0xFF -enum SecurityState { - // Default value, flashing is prevented, cannot be set with CMD_SECURITY_SET - SECURITY_STATE_LOCK = 0, - // Flashing is allowed, cannot be set with CMD_SECURITY_SET - SECURITY_STATE_UNLOCK = 1, - // Flashing will be prevented on the next reboot - SECURITY_STATE_PREPARE_LOCK = 2, - // Flashing will be allowed on the next reboot - SECURITY_STATE_PREPARE_UNLOCK = 3, -}; - #endif // _COMMON_COMMAND_H diff --git a/src/drivers/security/Makefile.mk b/src/drivers/security/Makefile.mk new file mode 100644 index 000000000..d019dc640 --- /dev/null +++ b/src/drivers/security/Makefile.mk @@ -0,0 +1,19 @@ +# SPDX-License-Identifier: GPL-3.0-only +# SPDX-FileCopyrightText: 2025 System76, Inc. + +# Firmware security state feature. +# +# Requires: +# - Board must declare the `ME_WE` pin. +# +# External integrations: +# - system76/coreboot: `ec/system76/ec` config `EC_SYSTEM76_EC_LOCKDOWN`. +# - system76/firmware-setup: UEFI protocol for physical presence prompt. + +ifeq ($(CONFIG_SECURITY),y) + +CFLAGS += -DCONFIG_SECURITY=1 + +drivers-y += security.c + +endif diff --git a/src/drivers/security/security.c b/src/drivers/security/security.c new file mode 100644 index 000000000..011d88f97 --- /dev/null +++ b/src/drivers/security/security.c @@ -0,0 +1,41 @@ +// SPDX-License-Identifier: GPL-3.0-only + +#include "security.h" +#include + +static enum SecurityState security_state = SECURITY_STATE_LOCK; + +enum SecurityState security_get(void) { + return security_state; +} + +bool security_set(enum SecurityState state) { + switch (state) { + // Allow prepare states to be set + case SECURITY_STATE_PREPARE_LOCK: + case SECURITY_STATE_PREPARE_UNLOCK: + security_state = state; + return true; + // Any other states will be ignored + default: + return false; + } +} + +bool security_power(void) { + switch (security_state) { + // Apply lock state and power on + case SECURITY_STATE_PREPARE_LOCK: + gpio_set(&ME_WE, false); + security_state = SECURITY_STATE_LOCK; + return true; + // Apply unlock state and power on + case SECURITY_STATE_PREPARE_UNLOCK: + gpio_set(&ME_WE, true); + security_state = SECURITY_STATE_UNLOCK; + return true; + // Any other states will be ignored + default: + return false; + } +} diff --git a/src/drivers/security/security.h b/src/drivers/security/security.h new file mode 100644 index 000000000..3583f813a --- /dev/null +++ b/src/drivers/security/security.h @@ -0,0 +1,23 @@ +// SPDX-License-Identifier: GPL-3.0-only + +#ifndef _DRIVERS_SECURITY_H +#define _DRIVERS_SECURITY_H + +#include + +enum SecurityState { + // Default value, flashing is prevented, cannot be set with CMD_SECURITY_SET + SECURITY_STATE_LOCK = 0, + // Flashing is allowed, cannot be set with CMD_SECURITY_SET + SECURITY_STATE_UNLOCK = 1, + // Flashing will be prevented on the next reboot + SECURITY_STATE_PREPARE_LOCK = 2, + // Flashing will be allowed on the next reboot + SECURITY_STATE_PREPARE_UNLOCK = 3, +}; + +enum SecurityState security_get(void); +bool security_set(enum SecurityState state); +bool security_power(void); + +#endif // _DRIVERS_SECURITY_H