Skip to content

Commit 9ff7d4b

Browse files
committed
Move USB-PD support to a driver
- 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 757cd5d commit 9ff7d4b

File tree

11 files changed

+39
-36
lines changed

11 files changed

+39
-36
lines changed

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,8 @@ 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
44+
CONFIG_USBPD_I2C = 1
4645

4746
# Set CPU power limits in watts
4847
CONFIG_POWER_LIMIT_AC = 330

src/board/system76/bonw15/board.mk

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,8 @@ 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
41+
CONFIG_USBPD_I2C = 1
4342

4443
# Set CPU power limits in watts
4544
CONFIG_POWER_LIMIT_AC = 330

src/board/system76/common/common.mk

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -111,13 +111,6 @@ CFLAGS += -DCHARGER_PSYS_GAIN=$(CONFIG_CHARGER_PSYS_GAIN)
111111
endif
112112
endif
113113

114-
# Add USB-PD
115-
ifeq ($(CONFIG_HAVE_USBPD),y)
116-
CFLAGS += -DCONFIG_HAVE_USBPD=1
117-
board-common-$(CONFIG_USBPD_TPS65987) += usbpd/tps65987.c
118-
CFLAGS += -DI2C_USBPD=$(CONFIG_I2C_USBPD)
119-
endif
120-
121114
# Add keyboard
122115
ifndef KEYBOARD
123116
$(error KEYBOARD is not set by the board)

src/board/system76/common/main.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,11 @@
2323
#include <board/pwm.h>
2424
#include <board/smbus.h>
2525
#include <board/smfi.h>
26-
#include <board/usbpd.h>
2726
#include <common/debug.h>
2827
#include <common/macro.h>
2928
#include <common/version.h>
3029
#include <drivers/dgpu/dgpu.h>
30+
#include <drivers/usbpd/usbpd.h>
3131
#include <ec/ec.h>
3232

3333
#if CONFIG_PLATFORM_INTEL

src/board/system76/common/power/intel.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
#include <board/pmc.h>
1818
#include <board/pnp.h>
1919
#include <board/wireless.h>
20-
#include <board/usbpd.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/oryp11/board.mk

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,8 @@ 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
42+
CONFIG_USBPD_I2C = 1
4443

4544
# Set CPU power limits in watts
4645
CONFIG_POWER_LIMIT_AC = 230

src/board/system76/oryp12/board.mk

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,8 @@ 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
39+
CONFIG_USBPD_I2C = 1
4140

4241
# Set CPU power limits in watts
4342
CONFIG_POWER_LIMIT_AC = 230

src/board/system76/serw13/board.mk

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,8 @@ 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
41+
CONFIG_USBPD_I2C = 1
4342

4443
# Set CPU power limits in watts
4544
CONFIG_POWER_LIMIT_AC = 280

src/drivers/usbpd/Makefile.mk

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# SPDX-License-Identifier: GPL-3.0-only
2+
# SPDX-FileCopyrightText: 2025 System76, Inc.
3+
4+
ifneq ($(CONFIG_DRIVERS_USBPD_TPS65987),)
5+
CONFIG_HAVE_USBPD = y
6+
endif
7+
8+
ifeq ($(CONFIG_HAVE_USBPD),y)
9+
10+
CFLAGS += -DCONFIG_HAVE_USBPD=1
11+
CFLAGS += -DUSBPD_I2C=I2C_$(CONFIG_USBPD_I2C)
12+
13+
drivers-$(CONFIG_DRIVERS_USBPD_TPS65987) += tps65987.c
14+
15+
endif

src/board/system76/common/usbpd/tps65987.c renamed to src/drivers/usbpd/tps65987.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
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 "usbpd.h"
67
#include <board/battery.h>
78
#include <board/gpio.h>
89
#include <board/power.h>
9-
#include <board/usbpd.h>
1010
#include <common/debug.h>
1111
#include <ec/i2c.h>
1212

@@ -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)