Skip to contentSkip to conversation

xhci-pci: Set AMD Renoir USB controller to D3 when shutdown

PATCH In review Aaron Ma 4 participants 9 messages Feb 4, 2021 – Feb 22, 2021

Subsystems (3)
lore
Share & tools
lore

Aaron Ma

author
#0 lore raw

PATCH 1/1 xhci-pci: Set AMD Renoir USB controller to D3 when shutdown

On AMD Renoir/Cezanne platforms, when set "Always on USB" to "On" in BIOS, USB controller will consume more power than 0.03w.

Set it to D3cold when shutdown, S5 power consumption will be 0.03w lower. The USB can charge other devices as before.
USB controller works fine after power on and reboot.

---
 drivers/usb/host/xhci-pci.c | 8 ++++++++
 drivers/usb/host/xhci.h     | 1 +
 2 files changed, 9 insertions(+)
drivers/usb/host/xhci-pci.c +8 -0
index 84da8406d5b4..a31be1ba927f 100644
@@ -62,6 +62,7 @@
 #define PCI_DEVICE_ID_AMD_PROMONTORYA_3			0x43ba
 #define PCI_DEVICE_ID_AMD_PROMONTORYA_2			0x43bb
 #define PCI_DEVICE_ID_AMD_PROMONTORYA_1			0x43bc
+#define PCI_DEVICE_ID_AMD_RENOIR_USB31			0x1639
 #define PCI_DEVICE_ID_ASMEDIA_1042_XHCI			0x1042
 #define PCI_DEVICE_ID_ASMEDIA_1042A_XHCI		0x1142
 #define PCI_DEVICE_ID_ASMEDIA_1142_XHCI			0x1242
@@ -171,6 +172,10 @@ static void xhci_pci_quirks(struct device *dev, struct xhci_hcd *xhci)
 	if (pdev->vendor == PCI_VENDOR_ID_AMD)
 		xhci->quirks |= XHCI_TRUST_TX_LENGTH;
 
+	if (pdev->vendor == PCI_VENDOR_ID_AMD &&
+		pdev->device == PCI_DEVICE_ID_AMD_RENOIR_USB31)
+		xhci->quirks |= XHCI_SHUTDOWN_D3COLD;
+
 	if ((pdev->vendor == PCI_VENDOR_ID_AMD) &&
 		((pdev->device == PCI_DEVICE_ID_AMD_PROMONTORYA_4) ||
 		(pdev->device == PCI_DEVICE_ID_AMD_PROMONTORYA_3) ||
@@ -594,6 +599,9 @@ static void xhci_pci_shutdown(struct usb_hcd *hcd)
 	/* Yet another workaround for spurious wakeups at shutdown with HSW */
 	if (xhci->quirks & XHCI_SPURIOUS_WAKEUP)
 		pci_set_power_state(pdev, PCI_D3hot);
+
+	if (xhci->quirks & XHCI_SHUTDOWN_D3COLD)
+		pci_set_power_state(pdev, PCI_D3cold);
 }
 #endif /* CONFIG_PM */
 
drivers/usb/host/xhci.h +1 -0
index 25e57bc9c3cc..0684193da4bd 100644
@@ -1883,6 +1883,7 @@ struct xhci_hcd {
 #define XHCI_SKIP_PHY_INIT	BIT_ULL(37)
 #define XHCI_DISABLE_SPARSE	BIT_ULL(38)
 #define XHCI_SG_TRB_CACHE_SIZE_QUIRK	BIT_ULL(39)
+#define XHCI_SHUTDOWN_D3COLD	BIT_ULL(40)
 
 	unsigned int		num_active_eps;
 	unsigned int		limit_active_eps;
Signature · 1 line
2.30.0
#1 lore raw
Quoted 7 lines · Aaron Ma

On AMD Renoir/Cezanne platforms, when set "Always on USB" to "On" in BIOS, USB controller will consume more power than 0.03w.

Set it to D3cold when shutdown, S5 power consumption will be 0.03w lower. The USB can charge other devices as before.
USB controller works fine after power on and reboot.

Can you please test the following patch, which should address the root cause:
https://lore.kernel.org/linux-acpi/[email protected]/

It also helps another AMD laptop on S5:
https://bugs.launchpad.net/ubuntu/+source/linux/+bug/1912935

We don't need to put bandage on drivers one by one once the patch with alternative approach is in upstream.

Kai-Heng

Quoted 55 lines
---
 drivers/usb/host/xhci-pci.c | 8 ++++++++
 drivers/usb/host/xhci.h     | 1 +
 2 files changed, 9 insertions(+)
drivers/usb/host/xhci-pci.c +8 -0
index 84da8406d5b4..a31be1ba927f 100644
@@ -62,6 +62,7 @@
 #define PCI_DEVICE_ID_AMD_PROMONTORYA_3                        0x43ba
 #define PCI_DEVICE_ID_AMD_PROMONTORYA_2                        0x43bb
 #define PCI_DEVICE_ID_AMD_PROMONTORYA_1                        0x43bc
+#define PCI_DEVICE_ID_AMD_RENOIR_USB31                 0x1639
 #define PCI_DEVICE_ID_ASMEDIA_1042_XHCI                        0x1042
 #define PCI_DEVICE_ID_ASMEDIA_1042A_XHCI               0x1142
 #define PCI_DEVICE_ID_ASMEDIA_1142_XHCI                        0x1242
@@ -171,6 +172,10 @@ static void xhci_pci_quirks(struct device *dev, struct xhci_hcd *xhci)
        if (pdev->vendor == PCI_VENDOR_ID_AMD)
                xhci->quirks |= XHCI_TRUST_TX_LENGTH;
 
+       if (pdev->vendor == PCI_VENDOR_ID_AMD &&
+               pdev->device == PCI_DEVICE_ID_AMD_RENOIR_USB31)
+               xhci->quirks |= XHCI_SHUTDOWN_D3COLD;
+
        if ((pdev->vendor == PCI_VENDOR_ID_AMD) &&
                ((pdev->device == PCI_DEVICE_ID_AMD_PROMONTORYA_4) ||
                (pdev->device == PCI_DEVICE_ID_AMD_PROMONTORYA_3) ||
@@ -594,6 +599,9 @@ static void xhci_pci_shutdown(struct usb_hcd *hcd)
        /* Yet another workaround for spurious wakeups at shutdown with HSW */
        if (xhci->quirks & XHCI_SPURIOUS_WAKEUP)
                pci_set_power_state(pdev, PCI_D3hot);
+
+       if (xhci->quirks & XHCI_SHUTDOWN_D3COLD)
+               pci_set_power_state(pdev, PCI_D3cold);
 }
 #endif /* CONFIG_PM */
 
drivers/usb/host/xhci.h +1 -1
index 25e57bc9c3cc..0684193da4bd 100644
@@ -1883,6 +1883,7 @@ struct xhci_hcd {
 #define XHCI_SKIP_PHY_INIT     BIT_ULL(37)
 #define XHCI_DISABLE_SPARSE    BIT_ULL(38)
 #define XHCI_SG_TRB_CACHE_SIZE_QUIRK   BIT_ULL(39)
+#define XHCI_SHUTDOWN_D3COLD   BIT_ULL(40)
 
        unsigned int            num_active_eps;
        unsigned int            limit_active_eps;
--

2.30.0

author
#2 lore raw
Quoted 6 lines · Kai-Heng Feng

Can you please test the following patch, which should address the root cause:
https://lore.kernel.org/linux-acpi/[email protected]/

It also helps another AMD laptop on S5:
https://bugs.launchpad.net/ubuntu/+source/linux/+bug/1912935

No, this patch doesn't help on ThinkPad AMD platform.

Aaron

Quoted 4 lines

We don't need to put bandage on drivers one by one once the patch with alternative approach is in upstream.

Kai-Heng

Acked-by
#3 lore raw
Quoted 11 lines · Aaron Ma
Quoted 6 lines · Kai-Heng Feng

Can you please test the following patch, which should address the root cause:
https://lore.kernel.org/linux-acpi/[email protected]/

It also helps another AMD laptop on S5:
https://bugs.launchpad.net/ubuntu/+source/linux/+bug/1912935

No, this patch doesn't help on ThinkPad AMD platform.

Thanks for the confirmation!

Quoted 7 lines

Aaron

Quoted 4 lines

We don't need to put bandage on drivers one by one once the patch with alternative approach is in upstream.

Kai-Heng

#4 lore raw
Quoted 11 lines · Kai-Heng Feng
Quoted 10 lines · Aaron Ma
Quoted 6 lines · Kai-Heng Feng

Can you please test the following patch, which should address the root cause:
https://lore.kernel.org/linux-acpi/[email protected]/

It also helps another AMD laptop on S5:
https://bugs.launchpad.net/ubuntu/+source/linux/+bug/1912935

Quoted 5 lines
Quoted 1 line

No, this patch doesn't help on ThinkPad AMD platform.

Thanks for the confirmation!

Mathias, want me to take this in my tree now, or are you going to send me more patches for 5.12-rc1?

thanks,

greg k-h

#5 lore raw
Quoted 12 lines · Greg Kroah-Hartman
Quoted 11 lines · Kai-Heng Feng
Quoted 10 lines · Aaron Ma
Quoted 6 lines · Kai-Heng Feng

Can you please test the following patch, which should address the root cause:
https://lore.kernel.org/linux-acpi/[email protected]/

It also helps another AMD laptop on S5:
https://bugs.launchpad.net/ubuntu/+source/linux/+bug/1912935

Quoted 9 lines
Quoted 5 lines
Quoted 1 line

No, this patch doesn't help on ThinkPad AMD platform.

Thanks for the confirmation!

Mathias, want me to take this in my tree now, or are you going to send me more patches for 5.12-rc1?

Nothing more for 5.12-rc1 from me.

Could this be a PCI quirk instead of xhci?
Maybe there is some PCI flag for this already, haven't checked yet.

We want a specific PCI device to go to PCI D3cold at PCI shutdown...

If not, then adding this to xhci is fine for me as well

Thanks
-Mathias

#6 lore raw
Quoted 23 lines · Mathias Nyman
Quoted 12 lines · Greg Kroah-Hartman
Quoted 11 lines · Kai-Heng Feng
Quoted 10 lines · Aaron Ma
Quoted 6 lines · Kai-Heng Feng

Can you please test the following patch, which should address the root cause:
https://lore.kernel.org/linux-acpi/[email protected]/

It also helps another AMD laptop on S5:
https://bugs.launchpad.net/ubuntu/+source/linux/+bug/1912935

Quoted 9 lines
Quoted 5 lines
Quoted 1 line

No, this patch doesn't help on ThinkPad AMD platform.

Thanks for the confirmation!

Mathias, want me to take this in my tree now, or are you going to send me more patches for 5.12-rc1?

Quoted 6 lines

Nothing more for 5.12-rc1 from me.

Could this be a PCI quirk instead of xhci?
Maybe there is some PCI flag for this already, haven't checked yet.

We want a specific PCI device to go to PCI D3cold at PCI shutdown...

There probably is. Kay-Heng, can you look into doing that instead?

thanks,

greg k-h

author
#7 lore raw
Quoted 24 lines · Greg Kroah-Hartman
Quoted 23 lines · Mathias Nyman
Quoted 21 lines · Greg Kroah-Hartman
Quoted 11 lines · Kai-Heng Feng
Quoted 10 lines · Aaron Ma
Quoted 6 lines · Kai-Heng Feng

Can you please test the following patch, which should address the root cause:
https://lore.kernel.org/linux-acpi/[email protected]/

It also helps another AMD laptop on S5:
https://bugs.launchpad.net/ubuntu/+source/linux/+bug/1912935

Quoted 5 lines
Quoted 1 line

No, this patch doesn't help on ThinkPad AMD platform.

Thanks for the confirmation!

Mathias, want me to take this in my tree now, or are you going to send me more patches for 5.12-rc1?

Quoted 9 lines
Quoted 6 lines

Nothing more for 5.12-rc1 from me.

Could this be a PCI quirk instead of xhci?
Maybe there is some PCI flag for this already, haven't checked yet.

We want a specific PCI device to go to PCI D3cold at PCI shutdown...

There probably is. Kay-Heng, can you look into doing that instead?

There is no such PCI quirk, usually it calls driver to shutdown.

Regards,
Aaron

Quoted 4 lines

thanks,

greg k-h

#8 lore raw
Quoted 33 lines · Aaron Ma
Quoted 29 lines · Greg Kroah-Hartman
Quoted 28 lines · Mathias Nyman
Quoted 12 lines · Greg Kroah-Hartman
Quoted 11 lines · Kai-Heng Feng
Quoted 10 lines · Aaron Ma
Quoted 6 lines · Kai-Heng Feng

Can you please test the following patch, which should address the root cause:
https://lore.kernel.org/linux-acpi/[email protected]/

It also helps another AMD laptop on S5:
https://bugs.launchpad.net/ubuntu/+source/linux/+bug/1912935

Quoted 9 lines
Quoted 5 lines
Quoted 1 line

No, this patch doesn't help on ThinkPad AMD platform.

Thanks for the confirmation!

Mathias, want me to take this in my tree now, or are you going to send me more patches for 5.12-rc1?

Nothing more for 5.12-rc1 from me.

Could this be a PCI quirk instead of xhci?
Maybe there is some PCI flag for this already, haven't checked yet.

Quoted 6 lines
Quoted 4 lines
Quoted 1 line

We want a specific PCI device to go to PCI D3cold at PCI shutdown...

There probably is. Kay-Heng, can you look into doing that instead?

There is no such PCI quirk, usually it calls driver to shutdown.

Let me work on it. There are other devices need to be in D3 for shutdown, a generic approach across all devices will be better.

Kai-Heng

Quoted 8 lines

Regards,
Aaron

Quoted 4 lines

thanks,

greg k-h