Skip to content

Commit 6539230

Browse files
crawfxrdjackpot51
authored andcommitted
Move USB-PD support from main app 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 <tcrawford@system76.com>
1 parent 04242b0 commit 6539230

11 files changed

Lines changed: 44 additions & 36 deletions

File tree

src/app/main/Makefile.mk

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -106,13 +106,6 @@ CFLAGS += -DCHARGER_PSYS_GAIN=$(CONFIG_CHARGER_PSYS_GAIN)
106106
endif
107107
endif
108108

109-
# Add USB-PD
110-
ifeq ($(CONFIG_HAVE_USBPD),y)
111-
CFLAGS += -DCONFIG_HAVE_USBPD=1
112-
app-$(CONFIG_USBPD_TPS65987) += usbpd/tps65987.c
113-
CFLAGS += -DI2C_USBPD=$(CONFIG_I2C_USBPD)
114-
endif
115-
116109
# Add keyboard
117110
ifndef KEYBOARD
118111
$(error KEYBOARD is not set by the board)

src/app/main/main.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
#include <app/pwm.h>
1616
#include <app/smbus.h>
1717
#include <app/smfi.h>
18-
#include <app/usbpd.h>
1918
#include <arch/arch.h>
2019
#include <arch/delay.h>
2120
#include <arch/time.h>
@@ -25,6 +24,7 @@
2524
#include <common/macro.h>
2625
#include <common/version.h>
2726
#include <drivers/dgpu/dgpu.h>
27+
#include <drivers/usbpd/usbpd.h>
2828
#include <ec/ec.h>
2929

3030
#if CONFIG_PLATFORM_INTEL

src/app/main/power/intel.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@
1313
#include <app/peci.h>
1414
#include <app/pmc.h>
1515
#include <app/pnp.h>
16-
#include <app/usbpd.h>
1716
#include <app/wireless.h>
1817
#include <arch/delay.h>
1918
#include <arch/time.h>
2019
#include <board/gpio.h>
2120
#include <common/debug.h>
21+
#include <drivers/usbpd/usbpd.h>
2222

2323
#if CONFIG_BUS_ESPI
2424
#include <ec/espi.h>

src/board/system76/bonw15-b/Makefile.mk

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,7 @@ CONFIG_CHARGER_CHARGE_VOLTAGE = 17400
4040
CONFIG_CHARGER_INPUT_CURRENT = 16920
4141

4242
# Set USB-PD parameters
43-
CONFIG_HAVE_USBPD = y
44-
CONFIG_USBPD_TPS65987 = y
45-
CONFIG_I2C_USBPD = I2C_1
43+
CONFIG_DRIVERS_USBPD_TPS65987 = y
4644

4745
# Set CPU power limits in watts
4846
CONFIG_POWER_LIMIT_AC = 330

src/board/system76/bonw15/Makefile.mk

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,7 @@ CONFIG_CHARGER_CHARGE_VOLTAGE = 17400
3737
CONFIG_CHARGER_INPUT_CURRENT = 16920
3838

3939
# Set USB-PD parameters
40-
CONFIG_HAVE_USBPD = y
41-
CONFIG_USBPD_TPS65987 = y
42-
CONFIG_I2C_USBPD = I2C_1
40+
CONFIG_DRIVERS_USBPD_TPS65987 = y
4341

4442
# Set CPU power limits in watts
4543
CONFIG_POWER_LIMIT_AC = 330

src/board/system76/oryp11/Makefile.mk

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,7 @@ CONFIG_CHARGER_CHARGE_VOLTAGE = 17600
3838
CONFIG_CHARGER_INPUT_CURRENT = 11500
3939

4040
# Set USB-PD parameters
41-
CONFIG_HAVE_USBPD = y
42-
CONFIG_USBPD_TPS65987 = y
43-
CONFIG_I2C_USBPD = I2C_1
41+
CONFIG_DRIVERS_USBPD_TPS65987 = y
4442

4543
# Set CPU power limits in watts
4644
CONFIG_POWER_LIMIT_AC = 230

src/board/system76/oryp12/Makefile.mk

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,7 @@ CONFIG_CHARGER_CHARGE_VOLTAGE = 17600
3535
CONFIG_CHARGER_INPUT_CURRENT = 11500
3636

3737
# Set USB-PD parameters
38-
CONFIG_HAVE_USBPD = y
39-
CONFIG_USBPD_TPS65987 = y
40-
CONFIG_I2C_USBPD = I2C_1
38+
CONFIG_DRIVERS_USBPD_TPS65987 = y
4139

4240
# Set CPU power limits in watts
4341
CONFIG_POWER_LIMIT_AC = 230

src/board/system76/serw13/Makefile.mk

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,7 @@ CONFIG_CHARGER_CHARGE_VOLTAGE = 13050
3737
CONFIG_CHARGER_INPUT_CURRENT = 14000
3838

3939
# Set USB-PD parameters
40-
CONFIG_HAVE_USBPD = y
41-
CONFIG_USBPD_TPS65987 = y
42-
CONFIG_I2C_USBPD = I2C_1
40+
CONFIG_DRIVERS_USBPD_TPS65987 = y
4341

4442
# Set CPU power limits in watts
4543
CONFIG_POWER_LIMIT_AC = 280

src/drivers/usbpd/Makefile.mk

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# SPDX-License-Identifier: GPL-3.0-only
2+
# SPDX-FileCopyrightText: 2025 System76, Inc.
3+
4+
# USB Power Delivery (USB-PD) support.
5+
#
6+
# Options:
7+
# - `CONFIG_USBPD_I2C`: Board may override the I2C device index to use.
8+
9+
ifeq ($(CONFIG_DRIVERS_USBPD_TPS65987),y)
10+
CONFIG_HAVE_USBPD = y
11+
endif
12+
13+
ifeq ($(CONFIG_HAVE_USBPD),y)
14+
15+
CFLAGS += -DCONFIG_HAVE_USBPD=1
16+
17+
ifeq ($(CONFIG_USBPD_I2C),)
18+
CONFIG_USBPD_I2C = 1
19+
endif
20+
21+
CFLAGS += -DUSBPD_I2C=I2C_$(CONFIG_USBPD_I2C)
22+
23+
drivers-$(CONFIG_DRIVERS_USBPD_TPS65987) += tps65987.c
24+
25+
endif
Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// USB-PD driver for TPS65987 and the mostly compatible TPS65993 and TPS65994.
44
// I2C register reference: https://www.ti.com/lit/ug/slvubh2b/slvubh2b.pdf
55

6-
#include <app/usbpd.h>
6+
#include "usbpd.h"
77
#include <app/battery.h>
88
#include <app/power.h>
99
#include <board/gpio.h>
@@ -15,12 +15,12 @@
1515
#define REG_ACTIVE_CONTRACT_PDO 0x34
1616

1717
void usbpd_init(void) {
18-
i2c_reset(&I2C_USBPD, true);
18+
i2c_reset(&USBPD_I2C, true);
1919
}
2020

2121
static int16_t usbpd_current_limit(void) {
2222
uint8_t value[7] = { 0 };
23-
int16_t res = i2c_get(&I2C_USBPD, USBPD_ADDRESS, REG_ACTIVE_CONTRACT_PDO, value, sizeof(value));
23+
int16_t res = i2c_get(&USBPD_I2C, USBPD_ADDRESS, REG_ACTIVE_CONTRACT_PDO, value, sizeof(value));
2424
if (res == 7) {
2525
if (value[0] == 6) {
2626
uint32_t pdo = ((uint32_t)value[1]) | (((uint32_t)value[2]) << 8) |
@@ -72,7 +72,7 @@ static void usbpd_dump(void) {
7272
// Dump all registers for debugging
7373
for (uint8_t reg = 0x00; reg < 0x40; reg += 1) {
7474
uint8_t value[65] = { 0 };
75-
int16_t res = i2c_get(&I2C_USBPD, USBPD_ADDRESS, reg, value, sizeof(value));
75+
int16_t res = i2c_get(&USBPD_I2C, USBPD_ADDRESS, reg, value, sizeof(value));
7676
if (res < 0) {
7777
DEBUG("USBPD %02X ERROR %04X\n", reg, res);
7878
} else {
@@ -168,7 +168,7 @@ static int16_t usbpd_aneg(void) {
168168
int16_t res;
169169

170170
uint8_t cmd[5] = { 4, 'A', 'N', 'e', 'g' };
171-
res = i2c_set(&I2C_USBPD, USBPD_ADDRESS, 0x08, cmd, sizeof(cmd));
171+
res = i2c_set(&USBPD_I2C, USBPD_ADDRESS, 0x08, cmd, sizeof(cmd));
172172
if (res < 0) {
173173
return res;
174174
}
@@ -185,7 +185,7 @@ void usbpd_disable_charging(void) {
185185

186186
// Read current value
187187
uint8_t value[2] = { 0 };
188-
res = i2c_get(&I2C_USBPD, USBPD_ADDRESS, 0x33, value, sizeof(value));
188+
res = i2c_get(&USBPD_I2C, USBPD_ADDRESS, 0x33, value, sizeof(value));
189189
if (res < 0) {
190190
DEBUG("ERR %04X\n", -res);
191191
return;
@@ -200,7 +200,7 @@ void usbpd_disable_charging(void) {
200200
// Enable only the first TX sink PDO (5V)
201201
value[0] = 1;
202202
value[1] = 1;
203-
res = i2c_set(&I2C_USBPD, USBPD_ADDRESS, 0x33, value, sizeof(value));
203+
res = i2c_set(&USBPD_I2C, USBPD_ADDRESS, 0x33, value, sizeof(value));
204204
if (res < 0) {
205205
DEBUG("ERR %04X\n", -res);
206206
return;
@@ -223,7 +223,7 @@ void usbpd_enable_charging(void) {
223223

224224
// Read current value
225225
uint8_t value[2] = { 0 };
226-
res = i2c_get(&I2C_USBPD, USBPD_ADDRESS, 0x33, value, sizeof(value));
226+
res = i2c_get(&USBPD_I2C, USBPD_ADDRESS, 0x33, value, sizeof(value));
227227
if (res < 0) {
228228
DEBUG("ERR %04X\n", -res);
229229
return;
@@ -238,7 +238,7 @@ void usbpd_enable_charging(void) {
238238
// Enable the first two TX sink PDO (5V and 20V)
239239
value[0] = 1;
240240
value[1] = 2;
241-
res = i2c_set(&I2C_USBPD, USBPD_ADDRESS, 0x33, value, sizeof(value));
241+
res = i2c_set(&USBPD_I2C, USBPD_ADDRESS, 0x33, value, sizeof(value));
242242
if (res < 0) {
243243
DEBUG("ERR %04X\n", -res);
244244
return;

0 commit comments

Comments
 (0)