From b397d8ca302ae0b2729c85521a4ad42770409295 Mon Sep 17 00:00:00 2001 From: Tim Crawford Date: Thu, 18 Jan 2024 10:42:17 -0700 Subject: [PATCH] Conditionally compile USB-PD support Boards may not have USB-PD. Remove the need for a "none" option by only adding USB-PD sources when enabled. The resulting binary for boards with USB-PD enabled (addw3, bonw15, serw13) are identical. The binary for boards without USB-PD now have the empty calls optimized out. Signed-off-by: Tim Crawford --- src/board/system76/bonw15/board.mk | 6 +++--- src/board/system76/common/common.mk | 6 ++++-- src/board/system76/common/include/board/usbpd.h | 11 +++++++++++ src/board/system76/common/usbpd/none.c | 11 ----------- src/board/system76/oryp11/board.mk | 6 +++--- src/board/system76/serw13/board.mk | 6 +++--- 6 files changed, 24 insertions(+), 22 deletions(-) delete mode 100644 src/board/system76/common/usbpd/none.c diff --git a/src/board/system76/bonw15/board.mk b/src/board/system76/bonw15/board.mk index c855c0289..77123a3e2 100644 --- a/src/board/system76/bonw15/board.mk +++ b/src/board/system76/bonw15/board.mk @@ -29,8 +29,6 @@ CFLAGS+=-DI2C_SMBUS=I2C_4 # Set touchpad PS2 bus CFLAGS+=-DPS2_TOUCHPAD=PS2_3 -# Set USB-PD I2C bus -CFLAGS+=-DI2C_USBPD=I2C_1 # Set smart charger parameters # XXX: PRS1 and PRS2 are in parallel for adapter Rsense? @@ -43,7 +41,9 @@ CFLAGS+=\ -DCHARGER_INPUT_CURRENT=16920 # Set USB-PD parameters -USBPD=tps65987 +CONFIG_HAVE_USBPD = y +CONFIG_USBPD_TPS65987 = y +CFLAGS += -DI2C_USBPD=I2C_1 # Set CPU power limits in watts CFLAGS+=\ diff --git a/src/board/system76/common/common.mk b/src/board/system76/common/common.mk index 7c6158f5f..d7addcea6 100644 --- a/src/board/system76/common/common.mk +++ b/src/board/system76/common/common.mk @@ -76,8 +76,10 @@ CHARGER?=bq24780s board-common-y += charger/$(CHARGER).c # Add USB-PD -USBPD?=none -board-common-y += usbpd/$(USBPD).c +ifeq ($(CONFIG_HAVE_USBPD),y) +CFLAGS += -DCONFIG_HAVE_USBPD=1 +board-common-$(CONFIG_USBPD_TPS65987) += usbpd/tps65987.c +endif # Add keyboard ifndef KEYBOARD diff --git a/src/board/system76/common/include/board/usbpd.h b/src/board/system76/common/include/board/usbpd.h index 0be34f120..2b38e84a8 100644 --- a/src/board/system76/common/include/board/usbpd.h +++ b/src/board/system76/common/include/board/usbpd.h @@ -3,9 +3,20 @@ #ifndef _BOARD_USBPD_H #define _BOARD_USBPD_H +#if CONFIG_HAVE_USBPD + void usbpd_init(void); void usbpd_event(void); void usbpd_disable_charging(void); void usbpd_enable_charging(void); +#else + +static inline void usbpd_init(void) {} +static inline void usbpd_event(void) {} +static inline void usbpd_disable_charging(void) {} +static inline void usbpd_enable_charging(void) {} + +#endif + #endif // _BOARD_USBPD_H diff --git a/src/board/system76/common/usbpd/none.c b/src/board/system76/common/usbpd/none.c deleted file mode 100644 index dc8787e2e..000000000 --- a/src/board/system76/common/usbpd/none.c +++ /dev/null @@ -1,11 +0,0 @@ -// SPDX-License-Identifier: GPL-3.0-only - -#include - -void usbpd_init(void) {} - -void usbpd_event(void) {} - -void usbpd_disable_charging(void) {} - -void usbpd_enable_charging(void) {} diff --git a/src/board/system76/oryp11/board.mk b/src/board/system76/oryp11/board.mk index 6cf8e3f82..5dd7dbf11 100644 --- a/src/board/system76/oryp11/board.mk +++ b/src/board/system76/oryp11/board.mk @@ -31,8 +31,6 @@ CFLAGS+=-DI2C_SMBUS=I2C_4 # Set touchpad PS2 bus CFLAGS+=-DPS2_TOUCHPAD=PS2_3 -# Set USB-PD I2C bus -CFLAGS+=-DI2C_USBPD=I2C_1 # Set smart charger parameters # TODO: actually bq24800 @@ -45,7 +43,9 @@ CFLAGS+=\ -DCHARGER_INPUT_CURRENT=11500 # Set USB-PD parameters -USBPD=tps65987 +CONFIG_HAVE_USBPD = y +CONFIG_USBPD_TPS65987 = y +CFLAGS += -DI2C_USBPD=I2C_1 # Set CPU power limits in watts CFLAGS+=\ diff --git a/src/board/system76/serw13/board.mk b/src/board/system76/serw13/board.mk index 4ec278173..2e499cdbd 100644 --- a/src/board/system76/serw13/board.mk +++ b/src/board/system76/serw13/board.mk @@ -29,8 +29,6 @@ CFLAGS+=-DI2C_SMBUS=I2C_4 # Set touchpad PS2 bus CFLAGS+=-DPS2_TOUCHPAD=PS2_3 -# Set USB-PD I2C bus -CFLAGS+=-DI2C_USBPD=I2C_1 # Set smart charger parameters # TODO: actually bq24800 @@ -42,7 +40,9 @@ CFLAGS+=\ -DCHARGER_INPUT_CURRENT=14000 # Set USB-PD parameters -USBPD=tps65987 +CONFIG_HAVE_USBPD = y +CONFIG_USBPD_TPS65987 = y +CFLAGS += -DI2C_USBPD=I2C_1 # Set CPU power limits in watts CFLAGS+=\