Skip to content

Commit a7fbfd4

Browse files
superm1wsakernel
authored andcommitted
usb: typec: ucsi: Mark dGPUs as DEVICE scope
power_supply_is_system_supplied() checks whether any power supplies are present that aren't batteries to decide whether the system is running on DC or AC. Downstream drivers use this to make performance decisions. Navi dGPUs include an UCSI function that has been exported since commit 17631e8 ("i2c: designware: Add driver support for AMD NAVI GPU"). This UCSI function registers a power supply since commit 992a60e ("usb: typec: ucsi: register with power_supply class") but this is not a system power supply. As the power supply for a dGPU is only for powering devices connected to dGPU, create a device property to indicate that the UCSI endpoint is only for the scope of `POWER_SUPPLY_SCOPE_DEVICE`. Link: https://lore.kernel.org/lkml/[email protected]/ Reviewed-by: Evan Quan <[email protected]> Tested-by: Evan Quan <[email protected]> Signed-off-by: Mario Limonciello <[email protected]> Reviewed-by: Heikki Krogerus <[email protected]> Reviewed-by: Sebastian Reichel <[email protected]> Acked-by: Andi Shyti <[email protected]> Signed-off-by: Wolfram Sang <[email protected]>
1 parent 3152893 commit a7fbfd4

File tree

3 files changed

+29
-1
lines changed

3 files changed

+29
-1
lines changed

drivers/i2c/busses/i2c-designware-pcidrv.c

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include <linux/module.h>
2121
#include <linux/pci.h>
2222
#include <linux/pm_runtime.h>
23+
#include <linux/power_supply.h>
2324
#include <linux/sched.h>
2425
#include <linux/slab.h>
2526

@@ -234,6 +235,16 @@ static const struct dev_pm_ops i2c_dw_pm_ops = {
234235
SET_RUNTIME_PM_OPS(i2c_dw_pci_runtime_suspend, i2c_dw_pci_runtime_resume, NULL)
235236
};
236237

238+
static const struct property_entry dgpu_properties[] = {
239+
/* USB-C doesn't power the system */
240+
PROPERTY_ENTRY_U8("scope", POWER_SUPPLY_SCOPE_DEVICE),
241+
{}
242+
};
243+
244+
static const struct software_node dgpu_node = {
245+
.properties = dgpu_properties,
246+
};
247+
237248
static int i2c_dw_pci_probe(struct pci_dev *pdev,
238249
const struct pci_device_id *id)
239250
{
@@ -325,7 +336,7 @@ static int i2c_dw_pci_probe(struct pci_dev *pdev,
325336
}
326337

327338
if ((dev->flags & MODEL_MASK) == MODEL_AMD_NAVI_GPU) {
328-
dev->slave = i2c_new_ccgx_ucsi(&dev->adapter, dev->irq, NULL);
339+
dev->slave = i2c_new_ccgx_ucsi(&dev->adapter, dev->irq, &dgpu_node);
329340
if (IS_ERR(dev->slave))
330341
return dev_err_probe(dev->dev, PTR_ERR(dev->slave),
331342
"register UCSI failed\n");

drivers/i2c/busses/i2c-nvidia-gpu.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include <linux/platform_device.h>
1515
#include <linux/pm.h>
1616
#include <linux/pm_runtime.h>
17+
#include <linux/power_supply.h>
1718

1819
#include <asm/unaligned.h>
1920

@@ -261,6 +262,8 @@ MODULE_DEVICE_TABLE(pci, gpu_i2c_ids);
261262
static const struct property_entry ccgx_props[] = {
262263
/* Use FW built for NVIDIA GPU only */
263264
PROPERTY_ENTRY_STRING("firmware-name", "nvidia,gpu"),
265+
/* USB-C doesn't power the system */
266+
PROPERTY_ENTRY_U8("scope", POWER_SUPPLY_SCOPE_DEVICE),
264267
{ }
265268
};
266269

drivers/usb/typec/ucsi/psy.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,20 @@ static enum power_supply_property ucsi_psy_props[] = {
2727
POWER_SUPPLY_PROP_VOLTAGE_NOW,
2828
POWER_SUPPLY_PROP_CURRENT_MAX,
2929
POWER_SUPPLY_PROP_CURRENT_NOW,
30+
POWER_SUPPLY_PROP_SCOPE,
3031
};
3132

33+
static int ucsi_psy_get_scope(struct ucsi_connector *con,
34+
union power_supply_propval *val)
35+
{
36+
u8 scope = POWER_SUPPLY_SCOPE_UNKNOWN;
37+
struct device *dev = con->ucsi->dev;
38+
39+
device_property_read_u8(dev, "scope", &scope);
40+
val->intval = scope;
41+
return 0;
42+
}
43+
3244
static int ucsi_psy_get_online(struct ucsi_connector *con,
3345
union power_supply_propval *val)
3446
{
@@ -194,6 +206,8 @@ static int ucsi_psy_get_prop(struct power_supply *psy,
194206
return ucsi_psy_get_current_max(con, val);
195207
case POWER_SUPPLY_PROP_CURRENT_NOW:
196208
return ucsi_psy_get_current_now(con, val);
209+
case POWER_SUPPLY_PROP_SCOPE:
210+
return ucsi_psy_get_scope(con, val);
197211
default:
198212
return -EINVAL;
199213
}

0 commit comments

Comments
 (0)