{"id":2226328,"url":"http://patchwork.ozlabs.org/api/patches/2226328/?format=json","web_url":"http://patchwork.ozlabs.org/project/linux-pci/patch/20260422-pwrseq-m2-bt-v1-7-720d02545a64@oss.qualcomm.com/","project":{"id":28,"url":"http://patchwork.ozlabs.org/api/projects/28/?format=json","name":"Linux PCI development","link_name":"linux-pci","list_id":"linux-pci.vger.kernel.org","list_email":"linux-pci@vger.kernel.org","web_url":null,"scm_url":null,"webscm_url":null,"list_archive_url":"","list_archive_url_format":"","commit_url_format":""},"msgid":"<20260422-pwrseq-m2-bt-v1-7-720d02545a64@oss.qualcomm.com>","list_archive_url":null,"date":"2026-04-22T11:24:48","name":"[07/12] power: sequencing: pcie-m2: Create serdev for PCI devices present before probe","commit_ref":null,"pull_url":null,"state":"new","archived":false,"hash":"877693afd102efb53ba4382c9e49129cf54e1038","submitter":{"id":91277,"url":"http://patchwork.ozlabs.org/api/people/91277/?format=json","name":"Manivannan Sadhasivam via B4 Relay","email":"devnull+manivannan.sadhasivam.oss.qualcomm.com@kernel.org"},"delegate":null,"mbox":"http://patchwork.ozlabs.org/project/linux-pci/patch/20260422-pwrseq-m2-bt-v1-7-720d02545a64@oss.qualcomm.com/mbox/","series":[{"id":500992,"url":"http://patchwork.ozlabs.org/api/series/500992/?format=json","web_url":"http://patchwork.ozlabs.org/project/linux-pci/list/?series=500992","date":"2026-04-22T11:24:41","name":"Fixes/improvements for the PCI M.2 power sequencing driver","version":1,"mbox":"http://patchwork.ozlabs.org/series/500992/mbox/"}],"comments":"http://patchwork.ozlabs.org/api/patches/2226328/comments/","check":"pending","checks":"http://patchwork.ozlabs.org/api/patches/2226328/checks/","tags":{},"related":[],"headers":{"Return-Path":"\n <linux-pci+bounces-52959-incoming=patchwork.ozlabs.org@vger.kernel.org>","X-Original-To":["incoming@patchwork.ozlabs.org","linux-pci@vger.kernel.org"],"Delivered-To":"patchwork-incoming@legolas.ozlabs.org","Authentication-Results":["legolas.ozlabs.org;\n\tdkim=pass (2048-bit key;\n unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256\n header.s=k20201202 header.b=jkPF46Ua;\n\tdkim-atps=neutral","legolas.ozlabs.org;\n spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org\n (client-ip=172.105.105.114; helo=tor.lore.kernel.org;\n envelope-from=linux-pci+bounces-52959-incoming=patchwork.ozlabs.org@vger.kernel.org;\n receiver=patchwork.ozlabs.org)","smtp.subspace.kernel.org;\n\tdkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org\n header.b=\"jkPF46Ua\"","smtp.subspace.kernel.org;\n arc=none smtp.client-ip=10.30.226.201"],"Received":["from tor.lore.kernel.org (tor.lore.kernel.org [172.105.105.114])\n\t(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)\n\t key-exchange x25519)\n\t(No client certificate requested)\n\tby legolas.ozlabs.org (Postfix) with ESMTPS id 4g0xmz0Bv4z1yCv\n\tfor <incoming@patchwork.ozlabs.org>; Wed, 22 Apr 2026 21:28:35 +1000 (AEST)","from smtp.subspace.kernel.org (conduit.subspace.kernel.org\n [100.90.174.1])\n\tby tor.lore.kernel.org (Postfix) with ESMTP id 0B44D30786B0\n\tfor <incoming@patchwork.ozlabs.org>; Wed, 22 Apr 2026 11:25:51 +0000 (UTC)","from localhost.localdomain (localhost.localdomain [127.0.0.1])\n\tby smtp.subspace.kernel.org (Postfix) with ESMTP id 894B33D301F;\n\tWed, 22 Apr 2026 11:25:13 +0000 (UTC)","from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org\n [10.30.226.201])\n\t(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))\n\t(No client certificate requested)\n\tby smtp.subspace.kernel.org (Postfix) with ESMTPS id 01BCD3CFF64;\n\tWed, 22 Apr 2026 11:25:13 +0000 (UTC)","by smtp.kernel.org (Postfix) with ESMTPS id C815EC2BCFC;\n\tWed, 22 Apr 2026 11:25:12 +0000 (UTC)","from aws-us-west-2-korg-lkml-1.web.codeaurora.org\n (localhost.localdomain [127.0.0.1])\n\tby smtp.lore.kernel.org (Postfix) with ESMTP id C1367F5A8DD;\n\tWed, 22 Apr 2026 11:25:12 +0000 (UTC)"],"ARC-Seal":"i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116;\n\tt=1776857113; cv=none;\n b=Uk/fRsU6NerrGXRMs64g3xylBkXnIR4AdX+Pm1UBf7X+rtZchERy5/+WEq2Zn1cF5lDbfVQu9236YP4trMHxgwuzFuXT5gR63oncRfAB5N3zN4j7/7SaVLhPafgH21n7j6Q7oS2H1xfeCfzvZRV6KEyjDYwHezCn4qGaUlkd2yg=","ARC-Message-Signature":"i=1; a=rsa-sha256; d=subspace.kernel.org;\n\ts=arc-20240116; t=1776857113; c=relaxed/simple;\n\tbh=J5UBlxRINX616sHAIUpg5vnrM9/UWUYaECY6bNwQgdc=;\n\th=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References:\n\t In-Reply-To:To:Cc;\n b=M3fr+DJFs28HUysQ+Dq93CdsC1JwLwueBHRr1n6gLVoEUdlTFyZljA3MS0Q2xSCXA2CCk7FHJe/rUmDttaOosgdLfkuv0N1SOFnbsiZfIFRAmfHK1DAfAP0jrIVNICKUCUkj9nwWYziCYyAi+C89xlQ9307uDANy138EhB0Kfj0=","ARC-Authentication-Results":"i=1; smtp.subspace.kernel.org;\n dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org\n header.b=jkPF46Ua; arc=none smtp.client-ip=10.30.226.201","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org;\n\ts=k20201202; t=1776857112;\n\tbh=J5UBlxRINX616sHAIUpg5vnrM9/UWUYaECY6bNwQgdc=;\n\th=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From;\n\tb=jkPF46UaDCQDsujCNnGdPs454GmNrpOw/u8uuvo6yFnEXY/tpSGlP9OqG4qC2iudw\n\t 6xnnnm//JmzI+1H7xehBMu5hGUBFH0D4Eis+3jl03YFNWx2wvFAtF4nnP9CeZLZxoE\n\t iecuxRB5mS7mI7raNXMgIYpSPfcQtvgYDUIErcUg0q2cAYmyVXPUhY8FhHMsuBXbGO\n\t ydjq5XjiEZ+3+IViYg2ScN4MemCTA+SAhHV6iIQ3rFAdSrNKwAFF1bEV5lq31lsIce\n\t l5Y8eZ2f3jQ0DZywQpxuBgp6JhdDPT95Pmzuce3THrWw8OZtoa0pIBs9e9ehSJpu4G\n\t +Aq1UF+RlnQVQ==","From":"Manivannan Sadhasivam via B4 Relay\n <devnull+manivannan.sadhasivam.oss.qualcomm.com@kernel.org>","Date":"Wed, 22 Apr 2026 16:54:48 +0530","Subject":"[PATCH 07/12] power: sequencing: pcie-m2: Create serdev for PCI\n devices present before probe","Precedence":"bulk","X-Mailing-List":"linux-pci@vger.kernel.org","List-Id":"<linux-pci.vger.kernel.org>","List-Subscribe":"<mailto:linux-pci+subscribe@vger.kernel.org>","List-Unsubscribe":"<mailto:linux-pci+unsubscribe@vger.kernel.org>","MIME-Version":"1.0","Content-Type":"text/plain; charset=\"utf-8\"","Content-Transfer-Encoding":"7bit","Message-Id":"<20260422-pwrseq-m2-bt-v1-7-720d02545a64@oss.qualcomm.com>","References":"<20260422-pwrseq-m2-bt-v1-0-720d02545a64@oss.qualcomm.com>","In-Reply-To":"<20260422-pwrseq-m2-bt-v1-0-720d02545a64@oss.qualcomm.com>","To":"Bartosz Golaszewski <brgl@kernel.org>,\n Manivannan Sadhasivam <mani@kernel.org>,\n Marcel Holtmann <marcel@holtmann.org>,\n Luiz Augusto von Dentz <luiz.dentz@gmail.com>,\n Shuai Zhang <quic_shuaz@quicinc.com>","Cc":"linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org,\n linux-pci@vger.kernel.org, linux-arm-msm@vger.kernel.org,\n linux-bluetooth@vger.kernel.org, Wei Deng <wei.deng@oss.qualcomm.com>,\n Luiz Augusto von Dentz <luiz.von.dentz@intel.com>,\n Manivannan Sadhasivam <manivannan.sadhasivam@oss.qualcomm.com>","X-Mailer":"b4 0.15.0","X-Developer-Signature":"v=1; a=openpgp-sha256; l=5701;\n i=manivannan.sadhasivam@oss.qualcomm.com; h=from:subject:message-id;\n bh=KxccIL0wAbXZIjNEfSWb+27f0NvPCoI50tHq4aONrQs=;\n b=owEBbAGT/pANAwAKAVWfEeb+kc71AcsmYgBp6LAVbba+rmaoWNsPlB2IV19Sjs+xxhqc3+Nvv\n 4wQMp8j32WJATIEAAEKAB0WIQRnpUMqgUjL2KRYJ5dVnxHm/pHO9QUCaeiwFQAKCRBVnxHm/pHO\n 9ceQB/jmXhyv+IU0xoV41g0QAsVGsLDcguP0JPoHg+6zANCkUnyxVDC01ECWG1sT87CqbkQatNP\n A6tZzfebquQ7lY7QHu4bR0eHU1iIwjF8vlclN5B6HtumHDOlknbEE3lj/ATuJ/rWp0LQOMPSYgW\n nrBNYVDccO3t8vCM+LWe0mrnf2ae6qUa5jqS3nfOngknN7CWu3mL5+B/XaDT6iV9cMjedVZxGQo\n KVZvn4FzlJW0iEuxDRAiQjljVBl0jwctqdhsrvSINq+h68jOKbEz/n5R5gMc0wqNeUCeT97WW7J\n /PACoCeSEslXf+JX6FtULcPrP0SxSsWDW4gKdA4oXOO47QE=","X-Developer-Key":"i=manivannan.sadhasivam@oss.qualcomm.com; a=openpgp;\n fpr=C668AEC3C3188E4C611465E7488550E901166008","X-Endpoint-Received":"by B4 Relay for\n manivannan.sadhasivam@oss.qualcomm.com/default with auth_id=461","X-Original-From":"Manivannan Sadhasivam\n <manivannan.sadhasivam@oss.qualcomm.com>","Reply-To":"manivannan.sadhasivam@oss.qualcomm.com"},"content":"From: Manivannan Sadhasivam <manivannan.sadhasivam@oss.qualcomm.com>\n\nSo far, the driver is registering a notifier to create serdev for the PCI\ndevices that are going to be attached after probe. But it doesn't handle\nthe devices present before probe. Due to this, serdev is not getting\ncreated for those existing devices.\n\nHence, create serdev for PCI devices available before probe as well.\n\nNote that the serdev for available devices are created before\nregistering the notifier. There is a small window where a device could\nappear after pwrseq_pcie_m2_create_serdev(), before notifier registration.\nBut since M.2 cards are fixed to a slot, they are mostly added either\nbefore booting the host or after using hotplug. So this window is mostly\ntheoretical.\n\nSigned-off-by: Manivannan Sadhasivam <manivannan.sadhasivam@oss.qualcomm.com>\n---\n drivers/power/sequencing/pwrseq-pcie-m2.c | 83 ++++++++++++++++++++++++++-----\n 1 file changed, 70 insertions(+), 13 deletions(-)","diff":"diff --git a/drivers/power/sequencing/pwrseq-pcie-m2.c b/drivers/power/sequencing/pwrseq-pcie-m2.c\nindex bdc4391c87c9..b21fcc089580 100644\n--- a/drivers/power/sequencing/pwrseq-pcie-m2.c\n+++ b/drivers/power/sequencing/pwrseq-pcie-m2.c\n@@ -244,7 +244,7 @@ static int pwrseq_pcie_m2_create_bt_node(struct pwrseq_pcie_m2_ctx *ctx,\n \treturn ret;\n }\n \n-static int pwrseq_pcie_m2_create_serdev(struct pwrseq_pcie_m2_ctx *ctx,\n+static int __pwrseq_pcie_m2_create_serdev(struct pwrseq_pcie_m2_ctx *ctx,\n \t\t\t\t\tstruct pci_dev *pdev)\n {\n \tstruct serdev_controller *serdev_ctrl;\n@@ -267,6 +267,16 @@ static int pwrseq_pcie_m2_create_serdev(struct pwrseq_pcie_m2_ctx *ctx,\n \t\treturn 0;\n \t}\n \n+\t/* Bail out if the serdev device was already created for the PCI dev */\n+\tmutex_lock(&ctx->list_lock);\n+\tlist_for_each_entry(pci_dev, &ctx->pci_devices, list) {\n+\t\tif (pci_dev->pdev == pdev) {\n+\t\t\tmutex_unlock(&ctx->list_lock);\n+\t\t\treturn 0;\n+\t\t}\n+\t}\n+\tmutex_unlock(&ctx->list_lock);\n+\n \tpci_dev = kzalloc(sizeof(*pci_dev), GFP_KERNEL);\n \tif (!pci_dev) {\n \t\tret = -ENOMEM;\n@@ -376,7 +386,7 @@ static int pwrseq_pcie_m2_notify(struct notifier_block *nb, unsigned long action\n \tswitch (action) {\n \tcase BUS_NOTIFY_ADD_DEVICE:\n \t\tif (pci_match_id(pwrseq_m2_pci_ids, pdev)) {\n-\t\t\tret = pwrseq_pcie_m2_create_serdev(ctx, pdev);\n+\t\t\tret = __pwrseq_pcie_m2_create_serdev(ctx, pdev);\n \t\t\tif (ret)\n \t\t\t\treturn notifier_from_errno(ret);\n \t\t}\n@@ -408,7 +418,7 @@ static bool pwrseq_pcie_m2_check_remote_node(struct device *dev, u8 port, u8 end\n  * protocol device needs to be created manually with the help of the notifier\n  * of the discoverable bus like PCIe.\n  */\n-static int pwrseq_pcie_m2_register_notifier(struct pwrseq_pcie_m2_ctx *ctx, struct device *dev)\n+static int pwrseq_pcie_m2_register_notifier(struct pwrseq_pcie_m2_ctx *ctx)\n {\n \tint ret;\n \n@@ -416,18 +426,56 @@ static int pwrseq_pcie_m2_register_notifier(struct pwrseq_pcie_m2_ctx *ctx, stru\n \t * Register a PCI notifier for Key E connector that has PCIe as Port\n \t * 0/Endpoint 0 interface and Serial as Port 3/Endpoint 0 interface.\n \t */\n-\tif (pwrseq_pcie_m2_check_remote_node(dev, 3, 0, \"serial\")) {\n-\t\tif (pwrseq_pcie_m2_check_remote_node(dev, 0, 0, \"pcie\")) {\n-\t\t\tctx->dev = dev;\n-\t\t\tctx->nb.notifier_call = pwrseq_pcie_m2_notify;\n-\t\t\tret = bus_register_notifier(&pci_bus_type, &ctx->nb);\n-\t\t\tif (ret)\n-\t\t\t\treturn dev_err_probe(dev, ret,\n-\t\t\t\t\t\t     \"Failed to register notifier for serdev\\n\");\n+\tif (!pwrseq_pcie_m2_check_remote_node(ctx->dev, 3, 0, \"serial\") ||\n+\t    !pwrseq_pcie_m2_check_remote_node(ctx->dev, 0, 0, \"pcie\"))\n+\t\treturn 0;\n+\n+\tctx->nb.notifier_call = pwrseq_pcie_m2_notify;\n+\tret = bus_register_notifier(&pci_bus_type, &ctx->nb);\n+\tif (ret)\n+\t\treturn dev_err_probe(ctx->dev, ret,\n+\t\t\t\t     \"Failed to register notifier for serdev\\n\");\n+\treturn 0;\n+}\n+\n+static int pwrseq_pcie_m2_create_serdev(struct pwrseq_pcie_m2_ctx *ctx)\n+{\n+\tstruct pci_dev *pdev = NULL;\n+\tint ret;\n+\n+\tif (!pwrseq_pcie_m2_check_remote_node(ctx->dev, 3, 0, \"serial\") ||\n+\t    !pwrseq_pcie_m2_check_remote_node(ctx->dev, 0, 0, \"pcie\"))\n+\t\treturn 0;\n+\n+\tstruct device_node *pci_parent __free(device_node) =\n+\t\t\t\tof_graph_get_remote_node(dev_of_node(ctx->dev), 0, 0);\n+\tif (!pci_parent)\n+\t\treturn 0;\n+\n+\t/* Create serdev for existing PCI devices if required */\n+\tfor_each_pci_dev(pdev) {\n+\t\tif (!pdev->dev.parent || pci_parent != pdev->dev.parent->of_node)\n+\t\t\tcontinue;\n+\n+\t\tif (!pci_match_id(pwrseq_m2_pci_ids, pdev))\n+\t\t\tcontinue;\n+\n+\t\tret = __pwrseq_pcie_m2_create_serdev(ctx, pdev);\n+\t\tif (ret) {\n+\t\t\tdev_err_probe(ctx->dev, ret,\n+\t\t\t\t      \"Failed to create serdev for PCI device (%s)\\n\",\n+\t\t\t\t      pci_name(pdev));\n+\t\t\tpci_dev_put(pdev);\n+\t\t\tgoto err_remove_serdev;\n \t\t}\n \t}\n \n \treturn 0;\n+\n+err_remove_serdev:\n+\tpwrseq_pcie_m2_remove_serdev(ctx, NULL);\n+\n+\treturn ret;\n }\n \n static int pwrseq_pcie_m2_probe(struct platform_device *pdev)\n@@ -489,16 +537,25 @@ static int pwrseq_pcie_m2_probe(struct platform_device *pdev)\n \n \tmutex_init(&ctx->list_lock);\n \tINIT_LIST_HEAD(&ctx->pci_devices);\n+\tctx->dev = dev;\n+\n+\t/* Create serdev for available PCI devices (if required) */\n+\tret = pwrseq_pcie_m2_create_serdev(ctx);\n+\tif (ret)\n+\t\tgoto err_destroy_mutex;\n+\n \t/*\n \t * Register a notifier for creating protocol devices for\n \t * non-discoverable busses like UART.\n \t */\n-\tret = pwrseq_pcie_m2_register_notifier(ctx, dev);\n+\tret = pwrseq_pcie_m2_register_notifier(ctx);\n \tif (ret)\n-\t\tgoto err_destroy_mutex;\n+\t\tgoto err_remove_serdev;\n \n \treturn 0;\n \n+err_remove_serdev:\n+\tpwrseq_pcie_m2_remove_serdev(ctx, NULL);\n err_destroy_mutex:\n \tmutex_destroy(&ctx->list_lock);\n err_free_regulators:\n","prefixes":["07/12"]}