Skip to content

Commit

Permalink
Conditionally compile USB-PD support
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
crawfxrd committed Jun 17, 2024
1 parent fc3bad2 commit b397d8c
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 22 deletions.
6 changes: 3 additions & 3 deletions src/board/system76/bonw15/board.mk
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand All @@ -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+=\
Expand Down
6 changes: 4 additions & 2 deletions src/board/system76/common/common.mk
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 11 additions & 0 deletions src/board/system76/common/include/board/usbpd.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
11 changes: 0 additions & 11 deletions src/board/system76/common/usbpd/none.c

This file was deleted.

6 changes: 3 additions & 3 deletions src/board/system76/oryp11/board.mk
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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+=\
Expand Down
6 changes: 3 additions & 3 deletions src/board/system76/serw13/board.mk
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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+=\
Expand Down

0 comments on commit b397d8c

Please sign in to comment.