usb: xhci-pci: Add Power handling for Card readers on Apple systems
Subsystems (2)
PATCH 1/1 usb: xhci-pci: Add Power handling for Card readers on Apple systems
Add Power handling for Card readers on Apple systems using SPWR ACPI method, SPWR(1) turns on the card reader, SPWR(0) turns off the card reader, on newer systems SPWR just write a variable in EC. On previous systems it writes to GPIO pins.
It also used by the macOS driver with the function AppleUSB30XHCICardReaderPort::setDevicePower in AppleUSBXHCIPCI.kext.
(This should fix https://bugzilla.kernel.org/show_bug.cgi?id=111201
But thats not confirmed)
(Tested on iMac20,1)
--- drivers/usb/host/xhci-pci.c | 17 +++++++++++++++++ drivers/usb/host/xhci.h | 1 + 2 files changed, 18 insertions(+)
drivers/usb/host/xhci-pci.c +17 -0
@@ -15,6 +15,7 @@#include <linux/reset.h> #include <linux/suspend.h> #include <linux/bitfield.h> +#include <linux/platform_data/x86/apple.h> #include "xhci.h" #include "xhci-trace.h"
@@ -517,6 +518,16 @@ static void xhci_pci_quirks(struct device *dev, struct xhci_hcd *xhci)if (xhci->hci_version >=0x120 ) xhci->quirks |=XHCI_DEFAULT_PM_RUNTIME_ALLOW ; +/* On Apple Machine with Card readers, we have to use SPWR(0/1) to turn +* off/on the card reader, And on boot the card reader is off, so we turn +* it on. +*/ +if (x86_apple_machine &&ACPI_HANDLE (&pdev->dev) && +acpi_has_method (ACPI_HANDLE (&pdev->dev),"SPWR" )) { +acpi_execute_simple_method (ACPI_HANDLE (&pdev->dev),"SPWR" ,1 ); + xhci->quirks |=XHCI_APPLE_CARD_READER_POWER ; + } +if (xhci->quirks &XHCI_RESET_ON_RESUME )xhci_dbg_trace (xhci, trace_xhci_dbg_quirks,"QUIRK: Resetting on resume" );
@@ -853,6 +864,9 @@ static int xhci_pci_suspend(struct usb_hcd *hcd, bool do_wakeup)/* synchronize irq when using MSI-X */ xhci_msix_sync_irqs (xhci); +if (xhci->quirks &XHCI_APPLE_CARD_READER_POWER ) +acpi_execute_simple_method (ACPI_HANDLE (&pdev->dev),"SPWR" ,0 ); +if (ret && (xhci->quirks &XHCI_SSIC_PORT_UNUSED ))xhci_ssic_port_unused_quirk (hcd, false);
@@ -895,6 +909,9 @@ static int xhci_pci_resume(struct usb_hcd *hcd, pm_message_t msg)if (xhci->quirks &XHCI_PME_STUCK_QUIRK )xhci_pme_quirk (hcd); +if (xhci->quirks &XHCI_APPLE_CARD_READER_POWER ) +acpi_execute_simple_method (ACPI_HANDLE (&pdev->dev),"SPWR" ,1 ); +return xhci_resume (xhci, power_lost, is_auto_resume); }
drivers/usb/host/xhci.h +1 -0
@@ -1652,6 +1652,7 @@ struct xhci_hcd {#define XHCI_CDNS_SCTX_QUIRK BIT_ULL(48)#define XHCI_ETRON_HOST BIT_ULL(49)#define XHCI_LIMIT_ENDPOINT_INTERVAL_9 BIT_ULL(50) +#define XHCI_APPLE_CARD_READER_POWER BIT_ULL(51)unsigned int num_active_eps;unsigned int limit_active_eps;
Signature · 1 line
2.55.0
[email protected]
AI reviewThank you for your contribution! Sashiko AI review found 2 potential issues to consider: - [High] usb: xhci-pci: build failure when CONFIG_ACPI is disabled - [Medium] usb: xhci-pci…
Thank you for your contribution! Sashiko AI review found 2 potential issues to consider:
- [High] usb: xhci-pci: build failure when CONFIG_ACPI is disabled
- [Medium] usb: xhci-pci: xhci_pci_suspend() powers off card reader when suspend fails
--
commit 6b73237773664917a89fc903fc5b335cb19cc8a0
Author: Atharva Tiwari <[email protected]>
usb: xhci-pci: Add Power handling for Card readers on Apple systems
This commit adds power handling for card readers on x86 Apple systems by evaluating the SPWR ACPI method during xhci-pci probe, suspend, and resume.
Quoted 4 lines
drivers/usb/host/xhci-pci.c +0
-0
[ ... ]
drivers/usb/host/xhci-pci.c static void xhci_pci_quirks(struct device *dev, struct xhci_hcd *xhci) · line 529
Quoted 13 lines
drivers/usb/host/xhci-pci.c +9
-0@@ -517,6 +518,16 @@ static void xhci_pci_quirks(struct device *dev, struct xhci_hcd *xhci)if (xhci->hci_version >=0x120 ) xhci->quirks |=XHCI_DEFAULT_PM_RUNTIME_ALLOW ; +/* On Apple Machine with Card readers, we have to use SPWR(0/1) to turn +* off/on the card reader, And on boot the card reader is off, so we turn +* it on. +*/ +if (x86_apple_machine &&ACPI_HANDLE (&pdev->dev) && +acpi_has_method (ACPI_HANDLE (&pdev->dev),"SPWR" )) { +acpi_execute_simple_method (ACPI_HANDLE (&pdev->dev),"SPWR" ,1 ); + xhci->quirks |=XHCI_APPLE_CARD_READER_POWER ; + }
[Severity: High]
Does calling acpi_execute_simple_method() here and in xhci_pci_suspend() and xhci_pci_resume() break the build when CONFIG_ACPI is disabled?
include/acpi/acpi_bus.h declares acpi_execute_simple_method() only inside #ifdef CONFIG_ACPI and provides no stub for !CONFIG_ACPI, whereas CONFIG_USB_XHCI_PCI does not depend on CONFIG_ACPI.
drivers/usb/host/xhci-pci.c static int xhci_pci_suspend(struct usb_hcd *hcd, bool do_wakeup) · line 871
Quoted 9 lines
drivers/usb/host/xhci-pci.c +3
-0@@ -853,6 +864,9 @@ static int xhci_pci_suspend(struct usb_hcd *hcd, bool do_wakeup)/* synchronize irq when using MSI-X */ xhci_msix_sync_irqs (xhci); +if (xhci->quirks &XHCI_APPLE_CARD_READER_POWER ) +acpi_execute_simple_method (ACPI_HANDLE (&pdev->dev),"SPWR" ,0 ); +if (ret && (xhci->quirks &XHCI_SSIC_PORT_UNUSED ))xhci_ssic_port_unused_quirk (hcd, false);
[Severity: Medium]
Should SPWR(0) be skipped when xhci_suspend() returns an error in ret?
If xhci_suspend() fails, suspend_common() aborts the suspend without calling xhci_pci_resume(), leaving the card reader powered off while the host controller remains active.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1