From patchwork Mon Mar 25 13:16:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 13602188 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id D2BC4C54E64 for ; Mon, 25 Mar 2024 13:18:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=jzTqASRPh3Df9e5M9FOcGgqt+aotmra2KD0FGAuDTOk=; b=4sCFM64AIXu+/i Sw2KeKaZci5AQXoWTIdmANwaVkgecAE4xfSKVQxn6gS8OTp85iNF/xUsu2VK+69vXskICCyYoNaYg wNwptsIKAJg9omey6848JqCJf5qI5dvcOpIYm0gvwCnD4DqTUk+irk+OFeAWZWIef4IkvYyXX5Bn+ WixnfkkMRDGS1nLThSFo5Rb0SRtlS5ZWESsKwvoXDmbRhWdnRGB0BHGQNLo7vs/KcAjEJJlkd7cgo FtDVa6mtC2nlMwpgeR4m/kRBp261cQBpV3zCMCPm9iCmkP8Yxfd/zVMg3OC0FkvS8Q6Nz6F/jUYAL 3rA8vUefHtHIgNeorrNg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rokD9-0000000HUxH-444z; Mon, 25 Mar 2024 13:18:00 +0000 Received: from mail-wm1-x329.google.com ([2a00:1450:4864:20::329]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rokCS-0000000HUVv-3PPv for linux-arm-kernel@lists.infradead.org; Mon, 25 Mar 2024 13:17:18 +0000 Received: by mail-wm1-x329.google.com with SMTP id 5b1f17b1804b1-41488f9708fso6334055e9.3 for ; Mon, 25 Mar 2024 06:17:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20230601.gappssmtp.com; s=20230601; t=1711372632; x=1711977432; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=VPKtETY44L+sLLhmL3uaX4nFnllKG+8eyvkbzTNtgX4=; b=ljwgVp1bIZJeGCbvjiZwbWBGY+zPZ8yOfIIzSoYYTC1VIDZCEojSiOZtb6f9KPdWwj uUo2cIammb/+HCnMY8ZLFeZKdreOvnLHYBxOxMBT/S6b48E4hzyJ/ny8ZI7q2qVIUWF8 ZyESjvkQiU7pZuc6p1098x8w2HcEWuvMFE4exhdA2w/sGqTgugyclX8UIemyIinugsoG XDah8Zt0gXiq/jdmGURhYCk7bzpO2Pm2/o5MpHRBH+myfMEXdhSZAt7n50jf9ziEYHb4 pCCR7Fq/5Wg+vEDh5F+8mH4ASS89OTy08pfLC6+xUXY9gGKb8nL2Ppvw3iAWKPpt1gOz 2m2Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711372632; x=1711977432; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=VPKtETY44L+sLLhmL3uaX4nFnllKG+8eyvkbzTNtgX4=; b=TsBfQbkIlLidh+WOPgzmlAh2MJksz9EIDEzn+kan1nICd5RqwIxAWTaQ3vh+/2LO1k h+6ufR8QOAnPDA/psA7bMygXpL0ROIPHBTh2ys9TaNP4h7O5kosK6x/ZOxrG3ttm6HsP dOJ+BYOiMY6pydkG94fjq5HQPQSZTURJB30dYKHINY0/Pj6fuyRciZnNZt1gRd2GMplV KRW6qcXTRHHc8/UdGkIS+tZrt5Ypw0qX/MHX8VtH639XqDOP2CZkKhqtB3vIMlqQJigV 2woeDRiJcpdIUv+yBZRzQ6pvyiKSRyCUAS7ZuzVmNAzBy835/CQUnsRBf+Lxeikx3PEM p2FA== X-Forwarded-Encrypted: i=1; AJvYcCWBLqUDiSpQnxYtL7phL4AICEeIsBwWZPGLg13S4TLPRkB3/l7V9hHY2VdvL2KSs89oPPBQfJamAMj/N8ImzC4JL7BvHLrJ+pyTgwYwYl9ENtFoLQI= X-Gm-Message-State: AOJu0Yz6qH1cbOTv22ivwZMwee+hefWib9JeHkIDpsqtJW4E0ToAZk+A VK0QfE81kwjDuczfUHnDUlnZpe/RCylS+7IEDbZbMazUzzpd9S8t6paH/BbHiAM= X-Google-Smtp-Source: AGHT+IE8S1Cqc4BSl1gj1NJjC/8Phc5hQVnSu5kD3rjt0a7CtT1C9cZCCiVYJzGQ4RLrhpqJ51Qh5g== X-Received: by 2002:a5d:4bd1:0:b0:33d:b2d7:6264 with SMTP id l17-20020a5d4bd1000000b0033db2d76264mr4900718wrt.51.1711372632066; Mon, 25 Mar 2024 06:17:12 -0700 (PDT) Received: from brgl-uxlite.home ([2a01:cb1d:75a:e000:861d:8b72:a859:4ce9]) by smtp.gmail.com with ESMTPSA id p11-20020a056000018b00b0033e75e5f280sm9485245wrx.113.2024.03.25.06.17.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Mar 2024 06:17:11 -0700 (PDT) From: Bartosz Golaszewski To: Marcel Holtmann , Luiz Augusto von Dentz , "David S . Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Kalle Valo , Bjorn Andersson , Konrad Dybcio , Liam Girdwood , Mark Brown , Catalin Marinas , Will Deacon , Bjorn Helgaas , Bartosz Golaszewski , Saravana Kannan , Geert Uytterhoeven , Arnd Bergmann , Neil Armstrong , Marek Szyprowski , Alex Elder , Srini Kandagatla , Greg Kroah-Hartman , Abel Vesa , Manivannan Sadhasivam , Lukas Wunner , Dmitry Baryshkov Cc: linux-bluetooth@vger.kernel.org, netdev@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-wireless@vger.kernel.org, linux-arm-msm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-pci@vger.kernel.org, linux-pm@vger.kernel.org, Bartosz Golaszewski Subject: [PATCH v6 10/16] PCI/pwrctl: reuse the OF node for power controlled devices Date: Mon, 25 Mar 2024 14:16:18 +0100 Message-Id: <20240325131624.26023-11-brgl@bgdev.pl> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240325131624.26023-1-brgl@bgdev.pl> References: <20240325131624.26023-1-brgl@bgdev.pl> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240325_061716_919390_9E8A832B X-CRM114-Status: GOOD ( 16.28 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org From: Bartosz Golaszewski With PCI power control we deal with two struct device objects bound to two different drivers but consuming the same OF node. We must not bind the pinctrl twice. To that end: before setting the OF node of the newly instantiated PCI device, check if a platform device consuming the same OF node doesn't already exist on the platform bus and - if so - mark the PCI device as reusing the OF node. Signed-off-by: Bartosz Golaszewski --- drivers/pci/of.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/drivers/pci/of.c b/drivers/pci/of.c index 51e3dd0ea5ab..b908fe1ae951 100644 --- a/drivers/pci/of.c +++ b/drivers/pci/of.c @@ -6,6 +6,7 @@ */ #define pr_fmt(fmt) "PCI: OF: " fmt +#include #include #include #include @@ -13,6 +14,7 @@ #include #include #include +#include #include "pci.h" #ifdef CONFIG_PCI @@ -25,16 +27,20 @@ */ int pci_set_of_node(struct pci_dev *dev) { - struct device_node *node; - if (!dev->bus->dev.of_node) return 0; - node = of_pci_find_child_device(dev->bus->dev.of_node, dev->devfn); + struct device_node *node __free(device_node) = + of_pci_find_child_device(dev->bus->dev.of_node, dev->devfn); if (!node) return 0; - device_set_node(&dev->dev, of_fwnode_handle(node)); + struct device *pdev __free(put_device) = + bus_find_device_by_of_node(&platform_bus_type, node); + if (pdev) + dev->bus->dev.of_node_reused = true; + + device_set_node(&dev->dev, of_fwnode_handle(no_free_ptr(node))); return 0; }