From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=210.61.82.184 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796459662; b=LNPZRcxjDMmgnTQnbQ0p/qHXFMEy3w7jxN9I6cish8vgABWLO/mgGQ25N0Vvyr9/WXR+ o/lalrpeFZdlJyo7NHOiVvqIjOM6eomI139roUJcyM9f/wGUfRUXzP/e7SdsuOZozXCKs gNEe+JbQ7KWWdtD0xDQh6h8UPiSR54cG/JNLudzk3bPOwO8ywTZANG+WDbdjKyUFJN899 Gp5CoOwjhI8/eaJEgCIoH8PyCNS+kNWthXi8Rt7HwyuhuSRpeM2SqG0xqpU++w/Uu1VRM UCnsm5+C9X2htFqrkQqTJvy5AYty71cJgZ2EnkIGiEIs1IOd/d2uREIDdwRM+3jJulg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796459662; h=DMARC-Filter:X-UUID:DKIM-Signature:X-CID-P-RULE:X-CID-O-INFO: X-CID-META:X-CID-BVR:X-CID-BAS:X-CID-FACTOR:X-CID-RHF:X-UUID:Received: Received:Received:From:To:CC:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:MIME-Version:Content-Transfer-Encoding: Content-Type:X-MTK; bh=m1UPe8hVtGesuKYct5Uj73WFHy0omkFdekyjmCwmrZs=; b=t44cNxGlLdbI5ptxSfcdiALf/mXeHgS0ZdMbIp+yxor8MlGz6DEma9dgRQiGxvJfgFXi /A+GlTNZlXrmaCPdz11C04t5XnHnb8iexq7SaqVmx1F/VukHAM366eLGRrJ0PzjMkABj3 4CEl1va/RC5k+/YTCToxLwffWQ3vCjxWGrl4MFq9USguLlLGeZbO5tmqSAmrZeTiKGvaH 7eASiyxaCHnRaCD4Yih3GeOv7+iInct8AgvTfk+porjVva3ZaLqZjqDXR3vyUeVQl3goR Lpw9OvqFvyvQEITmNg5bTS5o0usyqGS8FYDaCIK9wcXMzNQtZ4hkum3hu2ZNSdNReXw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=mediatek.com; spf=pass smtp.mailfrom=mediatek.com; dkim=pass header.d=mediatek.com header.i=@mediatek.com header.a=rsa-sha256 header.s=dk header.b=etLwDm8U; arc=none smtp.remote-ip=210.61.82.184 Received: from mailgw02.mediatek.com (unknown [210.61.82.184]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 34B7960A2610; Sat, 5 Dec 2026 08:34:20 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 34B7960A2610 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=mediatek.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=mediatek.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=mediatek.com header.i=@mediatek.com header.a=rsa-sha256 header.s=dk header.b=etLwDm8U X-UUID: a5624e12f08611f1a7aecdb2598be72c-20261205 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=mediatek.com; s=dk; h=Content-Type:Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:CC:To:From; bh=m1UPe8hVtGesuKYct5Uj73WFHy0omkFdekyjmCwmrZs=; b=etLwDm8URskt0qLdbTfGr8yk+a1d5D99JvBHbAKEQkVSfWfiRsh5FBtQJv3jf1Nehq68yrkFE9UBJP59azH2Z84XqT1kxDbY6biDnA9UtLGLLMM1iRgLexjAtnHMHw5eUIkL1IxV6wqfnkDq2XyddwvJpMEUOoJbHyySDrLszf4=; X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.3.22,REQID:64675038-ce26-485e-91e3-d640efd48af1,IP:0,U RL:0,TC:0,Content:-25,EDM:0,RT:0,SF:0,FILE:0,BULK:0,RULE:Release_Ham,ACTIO N:release,TS:-25 X-CID-META: VersionHash:d36851b,CLOUDID:bf993767-4b51-4c95-bb1b-80ac6aad9c96,B ulkID:nil,BulkQuantity:0,SF:81|82|102|836|865|888|898,TC:-5,Content:0|15|5 0|99,EDM:-3,IP:nil,URL:0,File:130,RT:0,Bulk:nil,QS:nil,BEC:nil,COL:0,OSI:0 ,OSA:0,AV:0,LES:1,SPR:NO,DKR:0,DKP:0,BRR:0,BRE:0,ARC:0 X-CID-BVR: 2,SSN|SDN X-CID-BAS: 2,SSN|SDN,0,_ X-CID-FACTOR: TF_CID_SPAM_SNR X-CID-RHF: D41D8CD98F00B204E9800998ECF8427E X-UUID: a5624e12f08611f1a7aecdb2598be72c-20261205 Received: from mtkmbs10n1.mediatek.inc [(172.21.101.34)] by mailgw02.mediatek.com (envelope-from ) (Generic MTA with TLSv1.2 ECDHE-RSA-AES256-GCM-SHA384 256/256) with ESMTP id 2092530582; Sat, 05 Dec 2026 16:34:11 +0800 Received: from mtkmbs13n1.mediatek.inc (172.21.101.193) by MTKMBS14N1.mediatek.inc (172.21.101.75) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.56; Sat, 5 Dec 2026 16:34:06 +0800 Received: from gcnsap21.gcn.mediatek.inc (10.17.81.22) by mtkmbs13n1.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.2.2562.56 via Frontend Transport; Sat, 5 Dec 2026 16:34:05 +0800 From: Chunfeng Yun To: Mika Westerberg CC: Andreas Noever , Konrad Dybcio , Sven Peter , Yehezkel Bernat , Matthias Brugger , Greg Kroah-Hartman , AngeloGioacchino Del Regno , , , , , Chunfeng Yun Subject: [PATCH v4 11/14] thunderbolt: Add platform NHI driver Date: Sat, 5 Dec 2026 16:33:36 +0800 Message-ID: <20261205083342.4009278-12-chunfeng.yun@mediatek.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20261205083342.4009278-1-chunfeng.yun@mediatek.com> References: <20261205083342.4009278-1-chunfeng.yun@mediatek.com> X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-MTK: N Historically, the Thunderbolt/USB4 Native Host Interface (NHI) controller has been exposed as a PCI device handled by pci.c. However, some SoCs (such as MediaTek mt8901/mt8992) integrate the NHI as a memory-mapped platform device described via ACPI. To support platform-attached NHI controllers: Introduce platform.c to register a platform driver matching "ACPI0015" (ACPI). Because the primary interrupt is handled generically by the NHI core, no custom struct tb_nhi_ops hooks are required. Support an optional dedicated wake interrupt: on integrated SoCs, the MAC/PHY reside in a power domain whose clocks and power can be gated during sleep, preventing the primary NHI interrupt from acting as a wakeup source; so add an optional dedicated wakeup interrupt which comes from the always-on power domain; it is implementation specific. Signed-off-by: Chunfeng Yun --- v4: changes: * Drop nhi_platform_default_ops * Add struct tb_nhi_platform * Drop primary irq register and handle wake irq * Teardown via tb_nhi_remove * Drop pm_runtime_resume in nhi_suspend v3 changes: * Added 'depends on ACPI' to CONFIG_USB4_PLATFORM. * Drop OF matching. * Runtime PM Fix in Suspend. * Cleaner Wake IRQ Handling. * Kernel Coding Cleanups. v2 changes: * Added CONFIG_USB4_PLATFORM to build the platform driver as a separate module (thunderbolt_platform.ko), instead of statically embedding it into thunderbolt.o. * Renamed plat.c to platform.c, renamed internal functions from nhi_plat_* to nhi_platform_*, and updated the Device Tree compatible string from "thunderbolt-platform" to "usb4-nhi-platform". * Removed domain lifecycle changes (domain.c) and PCI driver cleanups (pci.c) from this patch, handled by previous patches. * Squashed the optional dedicated wake IRQ support (previously a separate patch in v1) directly into this patch. * Replaced the custom local ISR with the shared tb_nhi_isr(), adopted the renamed tb_nhi_probe() / tb_nhi_shutdown() / tb_nhi_pm_ops interfaces, and added -EPROBE_DEFER handling for the wake IRQ. --- drivers/thunderbolt/Kconfig | 10 +++ drivers/thunderbolt/Makefile | 3 + drivers/thunderbolt/platform.c | 155 +++++++++++++++++++++++++++++++++ 3 files changed, 168 insertions(+) create mode 100644 drivers/thunderbolt/platform.c diff --git a/drivers/thunderbolt/Kconfig b/drivers/thunderbolt/Kconfig index 80960555a364..2cf1997d4508 100644 --- a/drivers/thunderbolt/Kconfig +++ b/drivers/thunderbolt/Kconfig @@ -28,6 +28,16 @@ config USB4_PCI To compile this driver a module, choose M here. The module will be called thunderbolt_pci. +config USB4_PLATFORM + tristate "Support for platform USB4 and Thunderbolt controllers" + depends on ACPI + help + Say Y here to add support for the USB4 and Thunderbolt host routers + enumerated via ACPI (such as devices matching ACPI0015). + + To compile this driver as a module, choose M here. The module will be + called thunderbolt_platform. + config USB4_CONFIGFS def_tristate USB4 depends on CONFIGFS_FS && !(USB4=y && CONFIGFS_FS=m) diff --git a/drivers/thunderbolt/Makefile b/drivers/thunderbolt/Makefile index a563bf2b0345..334fa4ebdfc8 100644 --- a/drivers/thunderbolt/Makefile +++ b/drivers/thunderbolt/Makefile @@ -8,6 +8,9 @@ thunderbolt-objs += usb4_port.o nvm.o retimer.o quirks.o clx.o obj-${CONFIG_USB4_PCI} += thunderbolt_pci.o thunderbolt_pci-y := pci.o icm.o +obj-${CONFIG_USB4_PLATFORM} += thunderbolt_platform.o +thunderbolt_platform-y := platform.o + thunderbolt-${CONFIG_ACPI} += acpi.o thunderbolt-$(CONFIG_DEBUG_FS) += debugfs.o thunderbolt-$(CONFIG_USB4_CONFIGFS) += configfs.o diff --git a/drivers/thunderbolt/platform.c b/drivers/thunderbolt/platform.c new file mode 100644 index 000000000000..ce3bb65543c1 --- /dev/null +++ b/drivers/thunderbolt/platform.c @@ -0,0 +1,155 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Thunderbolt driver - NHI driver (Platform bus specific implementation) + * + * Author: Chunfeng Yun + */ + +#include +#include +#include +#include +#include +#include +#include + +#include "nhi.h" +#include "tb.h" + +/** + * struct tb_nhi_platform - NHI device connected over platform bus + * @nhi: Thunderbolt native host interface. + * @wake_irq: Optional dedicated wakeup interrupt. + */ +struct tb_nhi_platform { + struct tb_nhi nhi; + int wake_irq; +}; + +static inline struct tb_nhi_platform *nhi_to_platform(struct tb_nhi *nhi) +{ + return container_of(nhi, struct tb_nhi_platform, nhi); +} + +static int nhi_platform_probe(struct platform_device *pdev) +{ + struct device *dev = &pdev->dev; + struct tb_nhi_platform *nhi_plat; + struct tb_nhi *nhi; + int ret; + + nhi_plat = devm_kzalloc_obj(dev, *nhi_plat); + if (!nhi_plat) + return -ENOMEM; + + nhi = &nhi_plat->nhi; + nhi->dev = dev; + + nhi->iobase = devm_platform_ioremap_resource(pdev, 0); + if (IS_ERR(nhi->iobase)) + return PTR_ERR(nhi->iobase); + + ret = platform_get_irq(pdev, 0); + if (ret < 0) + return ret; + + nhi->irq = ret; + + /* + * Since the wake interrupt is implementation specific, make it + * optional. + */ + ret = platform_get_irq_optional(pdev, 1); + if (ret < 0 && ret != -ENXIO) + return dev_err_probe(dev, ret, "failed to get wake IRQ\n"); + if (ret > 0) + nhi_plat->wake_irq = ret; + + pm_runtime_set_active(dev); + pm_runtime_get_noresume(dev); + pm_runtime_enable(dev); + + /* Enable system wakeup capability */ + device_set_wakeup_capable(dev, true); + + if (nhi_plat->wake_irq) { + ret = dev_pm_set_dedicated_wake_irq(dev, nhi_plat->wake_irq); + if (ret) { + dev_err_probe(dev, ret, + "failed to set wake interrupt %d\n", + nhi_plat->wake_irq); + goto wake_irq_err; + } + } + + ret = tb_nhi_probe(nhi); + if (ret) + goto probe_err; + + device_enable_async_suspend(dev); + + return 0; + +probe_err: + if (nhi_plat->wake_irq) + dev_pm_clear_wake_irq(dev); + +wake_irq_err: + device_set_wakeup_capable(dev, false); + pm_runtime_put_noidle(dev); + pm_runtime_disable(dev); + pm_runtime_set_suspended(dev); + return ret; +} + +static void nhi_platform_do_remove(struct platform_device *pdev, bool reset) +{ + struct tb *tb = platform_get_drvdata(pdev); + struct device *dev = &pdev->dev; + struct tb_nhi *nhi = tb->nhi; + struct tb_nhi_platform *nhi_plat = nhi_to_platform(nhi); + + tb_nhi_remove(nhi, reset); + + if (nhi_plat->wake_irq) + dev_pm_clear_wake_irq(dev); + + device_set_wakeup_capable(dev, false); + pm_runtime_put_noidle(dev); + pm_runtime_disable(dev); + pm_runtime_set_suspended(dev); +} + +static void nhi_platform_remove(struct platform_device *pdev) +{ + nhi_platform_do_remove(pdev, false); +} + +static void nhi_platform_shutdown(struct platform_device *pdev) +{ + nhi_platform_do_remove(pdev, true); +} + +#ifdef CONFIG_ACPI +static const struct acpi_device_id nhi_platform_acpi_match[] = { + { "ACPI0015", 0 }, + { } +}; +MODULE_DEVICE_TABLE(acpi, nhi_platform_acpi_match); +#endif + +static struct platform_driver nhi_platform_driver = { + .probe = nhi_platform_probe, + .remove = nhi_platform_remove, + .shutdown = nhi_platform_shutdown, + .driver = { + .name = "thunderbolt", + .acpi_match_table = ACPI_PTR(nhi_platform_acpi_match), + .pm = &tb_nhi_pm_ops, + }, +}; + +module_platform_driver(nhi_platform_driver); +MODULE_ALIAS("platform:thunderbolt"); +MODULE_DESCRIPTION("Thunderbolt/USB4 platform host interface driver"); +MODULE_LICENSE("GPL"); -- 2.45.2