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: 13560615 Received: from mail-lj1-f174.google.com (mail-lj1-f174.google.com [209.85.208.174]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B64CD1509A2 for ; Fri, 16 Feb 2024 20:33:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.174 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708115613; cv=none; b=U2fyFFl7TQjdUvyI7FVR/boOMuY7Bw3288OmNZjACveW3UdSRpoaMeKPesylpT8KEhxeQwo/3/hLKikkTUk1d583uqctjwQc/YSwSsR+ZKv7ENY5NRL4c+qYwJrvjG3Mj57F/7ncN+fGTuYwBbTL1ndqcdyLQSc0QfI9RAy8rIk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708115613; c=relaxed/simple; bh=iWQpZyVUYNR0FgdTLJWWfXolJLly1aZ0q2sdWcfiADU=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=XWlRi0G/jFvqkp6ShDQA+JjMeO9mO4YzUC4oBKhSyWo3JfEvVFPNIKm4wKIq3Zrzm6311b2m+265wSyyxFeafUrGqayWx/ymltEeMJHIVGcpTZQsL5k8DpPxcU849APUssVNNGwG/8ZyIYtOCuziFE+2kCz7h0xLvxJRBihKHcY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=bgdev.pl; spf=none smtp.mailfrom=bgdev.pl; dkim=pass (2048-bit key) header.d=bgdev-pl.20230601.gappssmtp.com header.i=@bgdev-pl.20230601.gappssmtp.com header.b=JlO18UXd; arc=none smtp.client-ip=209.85.208.174 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=bgdev.pl Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=bgdev.pl Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bgdev-pl.20230601.gappssmtp.com header.i=@bgdev-pl.20230601.gappssmtp.com header.b="JlO18UXd" Received: by mail-lj1-f174.google.com with SMTP id 38308e7fff4ca-2d109e82bd0so29995941fa.3 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=vger.kernel.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=JlO18UXdAY40EYPh5vQMlAFsIPsHixgABilZ9EkLiVRSYzLOSjW5w+ypfcbuMeHrfZ CjEn1EyR1b4/rA7fxre/BWWN0FumJvdbBNy7LiHW23Uu6JgXO3AM6b3HgrQuCxUexSO8 8XpfNDuMNPm8XbbzzOhjM0K5uGImrSyKsDGkLl9V7jvCAEkeoP4cJwkHiR5U34FMABTe qFXW5mmFrbqL/QQqcnHl68kZl3ACLvKxIv8BqgCo+nyqzzqAviso6s6C5/trv4oan69U Q0X06jqsaVauq/rzu3/3ZqSQftU65tbC/WCOJ4wIWUW7SJBKnuP/5gxaSFP1Pe861jde u2rg== 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=Jj+vEHukKItozc2tv+A4YyoK41dc6OvxsdbYZE3zEz6USmslIxTGfp3e2PWMqmtcXd BzpOPUC+zqS5SDynRTfp29j5V1Va/H8xS6t0f18IeF2Xe90GoYC5eCtSlXPz0c+VPLek awLRgsAz6PH90DD35rSD1BWcnBbDRRASyNj4ccHAe8KR4xeyPOgylShoiHgjRj+tGGvL VAAgBXIr2Q5ZsS3NRKfpbG3lkCBIvnZkhO4w7yifjQxHujnSJ7G3aYvx4a9YNw+7u8XM Yl1vgktxijQIip7V3xJBi1uyZwJarbK4N1YKzoms9JnKd2kXA3KLP/pG4yCcQWsfkpmc DBsg== X-Forwarded-Encrypted: i=1; AJvYcCUtI8ToGceAuOlCHc1wcQhmayswCSkYcIDaJUwdJghm81N43Cx778v9km33salySurqnVy5sOauAHy70RyGFbjZQpBQAvIQ X-Gm-Message-State: AOJu0YzxVeW4aH/g9rRPBXCdhQf4gTyMXQ9sDlFg6Xq0yL8xtpCmCoGb IxysINavQyRMBZ/RP/VDbEhKs8CJCp9FaGm6TTZzq3PnX8QwMKP4ATEqicE+d4E= 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> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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; }