From patchwork Fri Feb 16 20:32:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 13560658 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 026C8C48295 for ; Fri, 16 Feb 2024 20:35:01 +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=OwUT69+RJCR4pm FgqKEDuYE3InDWfTrTwIXA1yxvfomXpbtEXVxuYSudy4WlmpRA8cYpahofEPCrSdxn69pGKY85mPy 1sVUxW76ZV+3KLwAk/LEXIgW0hja0a9WlPlCGHVS6DTzO5FcJq0DMIkvfnBO6UilCHPsrl4XdHlCq X9Dr2QEcuEf51xOngllF+6KukcwsGgF/0yiieEgUnDm/ozBogfNwtiBSry5VKDlikRNVZwV7XRtk1 AmJP9BggNYLWsy2Z27ruvt/fg/q4s2D5QVotVE82THo369gpBKhtwqD4akNdFrfgi4wWC6SgSLoeE aQfghHY2hixYS5tpWKZw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rb4v5-00000003eeh-1huk; Fri, 16 Feb 2024 20:34:51 +0000 Received: from desiato.infradead.org ([2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rb4tv-00000003dsf-2lJO for linux-arm-kernel@bombadil.infradead.org; Fri, 16 Feb 2024 20:33:39 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=Content-Transfer-Encoding:MIME-Version :References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=VPKtETY44L+sLLhmL3uaX4nFnllKG+8eyvkbzTNtgX4=; b=IrIO/C26VhZ/Kua6E2MVDwH1al Bc6doZRK5fwNVacVBuUVFDZBK1co6H18pvfUxmgdA/5Ncw4nYZ0Yoh7LuvEt1Pet6uSyMvB2MjePT UZEypbcjySrCe6/SSujq0djiOOc/GPyG4afvSxgxygJ2NXhL/5G4oO2XAhwvXXj+8JHsOkEUh/MrD l8jHAE1r9yw3gpyR+VgFRK+ig4NDuarJGt+19kZCQS7UlBcZN0uZjNLBJy8pG+wPQPi6sBe9r16xm zvSR7dIDPsRMP+TuFgzEMIJsTE1F+MF/4f1tw0W+p6CGE0632j2wbukelLa8tlv8YEwHiUQ6sLDt8 5GddJMwQ==; Received: from mail-lj1-x22d.google.com ([2a00:1450:4864:20::22d]) by desiato.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rb4tp-000000001sv-4AVq for linux-arm-kernel@lists.infradead.org; Fri, 16 Feb 2024 20:33:38 +0000 Received: by mail-lj1-x22d.google.com with SMTP id 38308e7fff4ca-2d11c55d7f2so34620521fa.2 for ; Fri, 16 Feb 2024 12:33:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20230601.gappssmtp.com; s=20230601; t=1708115608; x=1708720408; 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=oKgs8InNoR0YyfXpdP9PEWmwYnGlVB9JqH4uDPICDPACTDSqr8Kl8G4jhgFucffdeW prdauL5AaDak7WVuVpqaz7poQ+CSQNtYQZ7IoMtia/ND2eow4t8DHsdU8+AteCGrLa3I UIQ491zdzzA93IGyUhPAbQG5t4pECcKYFwS2BF6UUVkot99dbuOn0BszQGY6D6QBO9ph mksIznw+PbYB+NiBMrE7wODjxeXjykv/268Oa3HiK4I4N74jPFMhDQPePCEGOcTD2Mxu V0MfjnfY1WGWSBl+kw/rnxe2v6NNt7+R2+wL/Lk+AqyiBhEhmhrImpRG53dZ9Mc2e61e C8iw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708115608; x=1708720408; 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=ZjLFJe0VE4puIM8YHyUlZoWFLSC9Ft6dpTOTRY8AbFGgLOQZVsqBuiIwlAoW6BBKBa 1P75C4iW2uH+TDCwzReCI9wDl3rDhsmaSdT9Luli7bfU1CExNgB6BJeuu8XFqmONuBL8 3xtx11j4gD1EGHexbr3wdg2DZtdS+QNiAgijxoJ66iWhUeOg7sQ6poAT2RguMhQOQgrJ 3MJT0GjU3z4gixQuF/+fETP6zMG6EA//TSI0brYgzz/eyj+4ipE8zLPXyxjXri3qiMpg ehr6Ar19a2rREWFLpqbT25KT6TFZ8KASHxDbAAwOazbiMk466Li+G9bh1/IbSZ13Wnnc syDA== X-Forwarded-Encrypted: i=1; AJvYcCUXi8m7uCkbkxD/GC53Ol+/7NlBMszA5gnO5+zhIYJzuIBlQTlNe7dsjhbMQc3EiRw613p9Sxi0CwfW+SKf2Njstuo/U4WxeOTfGm9V9vnMkxzZwlI= X-Gm-Message-State: AOJu0YxqPqNZWRR2dl/DHvOtUnJqRK+JCswEY4r5ZE76QtIt5wn8+b1V Nuu8S7mFpSXPUozO7RTQOSn14Ixb43QC0vqPBGN5WrUcRXXpzSbG+bvlRR70ce4= X-Google-Smtp-Source: AGHT+IEA6PoShhob8vA8LHOTLObGA6LSgflaMRnbW+2bPuCja7p6p6LxUhdbKaL3IWhCeNx0gCY0nA== X-Received: by 2002:a2e:9198:0:b0:2d0:cfe6:4364 with SMTP id f24-20020a2e9198000000b002d0cfe64364mr4325724ljg.36.1708115608679; Fri, 16 Feb 2024 12:33:28 -0800 (PST) Received: from brgl-uxlite.home ([2a01:cb1d:334:ac00:7758:12d:16:5f19]) by smtp.gmail.com with ESMTPSA id m5-20020a05600c4f4500b0041253d0acd6sm1420528wmq.47.2024.02.16.12.33.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Feb 2024 12:33:28 -0800 (PST) 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 v5 11/18] PCI/pwrctl: reuse the OF node for power controlled devices Date: Fri, 16 Feb 2024 21:32:08 +0100 Message-Id: <20240216203215.40870-12-brgl@bgdev.pl> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240216203215.40870-1-brgl@bgdev.pl> References: <20240216203215.40870-1-brgl@bgdev.pl> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240216_203335_433926_3D1E1073 X-CRM114-Status: GOOD ( 15.68 ) 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; }