From nobody Thu Feb 12 12:29:38 2026 Received: from mail-wm1-f48.google.com (mail-wm1-f48.google.com [209.85.128.48]) (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 1216416C865 for ; Wed, 12 Jun 2024 08:20:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.48 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718180438; cv=none; b=QiczvrLxwXZ3aVkYqK9MVVDsu5Ee7BOLR1iwfXDKfsMLXRRslfUcmdYZFE/rat5LM7pBoMRyRzx4KjpjG27SzYLKv86wL05GECUmNnc3wfjwZgKECz4UMHMYpAC8o/eEPIaCG9pIlqJLJircHvcp5ynB85E8/puncQ1bUa5tBiU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718180438; c=relaxed/simple; bh=7ODnCMLyMATh86YrN1ZPmjwWRMHpwQW+fCV8rLwj58E=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ZfQRYBx4GO3lFTAMJgib4+5df8aC40tg004hqcRpSg3P6nxQBN0APF+G+0by8uFoCm4vEUd52DfLHS4QyrMaKe6IyFKJ4dFOVY9RZ8oCL04Ksx2uvA1LKo1TBod1LCTm+VFRAZgx2xDxXuVvQjDyYcET1Bi1qTVCmrl/UM/+w84= 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=TQxk5MYK; arc=none smtp.client-ip=209.85.128.48 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="TQxk5MYK" Received: by mail-wm1-f48.google.com with SMTP id 5b1f17b1804b1-4218180a122so13980075e9.1 for ; Wed, 12 Jun 2024 01:20:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20230601.gappssmtp.com; s=20230601; t=1718180434; x=1718785234; 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=R+tryJWSLGei4yj4mnd/Wwwy83ERVx62Yqnj8MX2+CY=; b=TQxk5MYKztGI6IXzOvLNSX1Njy4G7Hep1ykBwj6IhXYoOEw9pKxLtEzPd2wxtFb+cc YAUAbUsz81k3PQwwtmjrzngEVjQP4rLRn5UMo326cRTX8vPoPRci43fPmLaByxOTfn0s n/+BQV91CFCQfd7B9ahbGfKBH2G/7GNjglh78dz6WDDucsESrZa2P7YjtAmSGe2Otl4p mHrThXSC9sEbti4UNFlq3kAWDNBu0OM8OnN7vKzYrh2PdIGXrNLYaA54VLL23wbtVBDi 6AVHg/yCYS9XrSRZcSTyhPVEWqy7IoZ7N3QAegDDfM4e1rLHyOEZU1pu20naTZo6ShTL pYAg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718180434; x=1718785234; 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=R+tryJWSLGei4yj4mnd/Wwwy83ERVx62Yqnj8MX2+CY=; b=DFf0uSK8ckkfomoxH1zChOXaiCnZCTRhQfJgGQ/EdJodZvMBtVRGEk3qVyEOvQqq6N G7ASNz8fODrjsw7czeUf7EHTC3dxfje+d2eHgvI7zTOxurkBNgnPEIbw3cmTmuBQ4Zta Wsd+notYaOZK+Zgww4znI1WuYO2UDWnZrCacWddPULO2xtokrLa/tttakyUYrzP97ehh HYFpn2LsEWXdZQpsWJhIdsmnfHyIF1MweAnFYr6neFwcW4fW0XWrqa+kIcVJ1zEVwcyz hsEkDcA/+n8qO/mxDofGbp0XEGQsKBGkgaR0mSbiggrVpU/IbCEfecbX/FQcvf6L0kBC kPmw== X-Gm-Message-State: AOJu0YwRUjnXo3tSuTaH75RmP2HHHnXd+NLKnQao6Vvs5CRb55rmGxaf RR8jVcGWgcWeB3zaO+2N64Ryl8+l6R13H5sjITLEmqwnpvMlcRsLMxgHvmAbHZc= X-Google-Smtp-Source: AGHT+IFDFkTt9Hyalt1EORmsWnUvoaT3No0XLhTfumJCHtinnWuBc/50Y76gRwgEs1k/81gMqxtorg== X-Received: by 2002:a05:600c:1913:b0:422:727c:70b1 with SMTP id 5b1f17b1804b1-422861aed43mr12346085e9.8.1718180434362; Wed, 12 Jun 2024 01:20:34 -0700 (PDT) Received: from brgl-uxlite.home ([2a01:cb1d:8d3:3800:a172:4e8b:453e:2f03]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4229207d1a7sm6011775e9.1.2024.06.12.01.20.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Jun 2024 01:20:33 -0700 (PDT) From: Bartosz Golaszewski To: Bjorn Helgaas Cc: linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org, Bartosz Golaszewski , Amit Pundir , Neil Armstrong , Caleb Connolly Subject: [PATCH v9 1/5] PCI: Hold the rescan mutex when scanning for the first time Date: Wed, 12 Jun 2024 10:20:14 +0200 Message-ID: <20240612082019.19161-2-brgl@bgdev.pl> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240612082019.19161-1-brgl@bgdev.pl> References: <20240612082019.19161-1-brgl@bgdev.pl> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Bartosz Golaszewski With the introduction of PCI device power control drivers that will be able to trigger the port rescan when probing, we need to hold the rescan mutex during the initial pci_host_probe() too or the two could get in each other's way. Tested-by: Amit Pundir Tested-by: Neil Armstrong # on SM8550-QRD, SM86= 50-QRD & SM8650-HDK Tested-by: Caleb Connolly # OnePlus 8T Acked-by: Bjorn Helgaas Signed-off-by: Bartosz Golaszewski --- drivers/pci/probe.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c index bfeeaf2d1fa9..b14b9876c030 100644 --- a/drivers/pci/probe.c +++ b/drivers/pci/probe.c @@ -3083,7 +3083,9 @@ int pci_host_probe(struct pci_host_bridge *bridge) struct pci_bus *bus, *child; int ret; =20 + pci_lock_rescan_remove(); ret =3D pci_scan_root_bus_bridge(bridge); + pci_unlock_rescan_remove(); if (ret < 0) { dev_err(bridge->dev.parent, "Scanning root bridge failed"); return ret; --=20 2.40.1 From nobody Thu Feb 12 12:29:38 2026 Received: from mail-wm1-f53.google.com (mail-wm1-f53.google.com [209.85.128.53]) (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 6B92816D32E for ; Wed, 12 Jun 2024 08:20:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.53 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718180438; cv=none; b=WJpXI7MFOWgW9HqtLRKIyqltzQnXswUZLanTgJ0hyEIrYetiCCYFyDS9vXRQ0MyiKwFw6+PJ1YcncOGfQWvC2OxUCwXT+4iy8yB6D5AT8cYzhjlIuDCyn9I/PV1w8hjJ+Yf93H1Qsd+Kq15qBqFeF8zb8BIg4g02CSVPAyAp88U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718180438; c=relaxed/simple; bh=z26s4JsQKN7nhVU9IlT3jZC8JXh2Ex5Rgl+dEf47fr8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=UECMXUc78EmQXZ2b+J2nhqaNEzUGkAX54jIFokG+QJFd7twipcjirY8QrEtH/aPbhN3UcG80fvSR34UBcIU9XygxrPI/fEFx/N7Za7H6p6IXkQh9vGypte1cTJav7AUd9N3y/OhUtg/jeIoaFceIurDnqOZeKiNdLt1DN7OgyH8= 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=N7AdyKes; arc=none smtp.client-ip=209.85.128.53 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="N7AdyKes" Received: by mail-wm1-f53.google.com with SMTP id 5b1f17b1804b1-421cd1e5f93so14105275e9.0 for ; Wed, 12 Jun 2024 01:20:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20230601.gappssmtp.com; s=20230601; t=1718180436; x=1718785236; 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=CIW5MiXtA4tOd1cdWHl86xShNBL3C/n3QwINP9u0b7k=; b=N7AdyKesdnPpZgl+1aIaSQIskXCfXr4ZC+L4aAfeULB4n5ssKHQ3EbEv/rDNN4JAuc Zl2psvxp3bQWSbFuus08Gi1Svzd199PKGooghkryxkbZ5h2Kc2AMNq+hKXy9rmgVe1vE A189rDNGu+KI4Kjkjj7yVkoqrtJPCeNhHbX9eaG21tDGmw2tAeZ6uttmLxfVAkdEqDda YJBTFIlWRjRlqAFYjs+B9qDRCMtiFeX10gGvNd02YZLf65lIF9YpY2/TUGhnLP7mkITD Z9fh9rxww8YYyj+Ysqau0aitbuSPpv42e9y02ezgtbGtFYN89OXV94aoq61MLAgBE35A mmPQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718180436; x=1718785236; 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=CIW5MiXtA4tOd1cdWHl86xShNBL3C/n3QwINP9u0b7k=; b=WubFsD3/M3UXN9xhA4cZvoKuEUycw7Xr7Hxh8WG1+Zl3nDL1s+hew9drIK55NXvE1s uOH2Jo/Rr9tDEA91RY09dstF+hMDYGzn2WiR3/bvRgIjY0QB2eDAyfV3oTLqzVBbjhyG BpQa/sANSWJuDCQ9VgOMHFoD2nKBvOXGa3w9NzqkTp9+X1QbpuMBlTxrTPw/mZ4NIfKQ mcQlzeuY8Nk8rJmzVAteLLb5p65wBtSFLuEqqn7D1lHle8DHTDqDlaKkQ8/h/KmiH4XB SX4FbANi3GandMGDd544Fp0ozZcaREQQSHTXQEHK2+ELEWUD4Cux/FXAwLC7fQq9ZWIn VoGw== X-Gm-Message-State: AOJu0YwspczeIjBcNSWrWd0K60XFLHLwsxsWzwTS5+asHbTnSdUAt6Df ZMzTwYQgFF5BuHDPptDTrcTrqvgMgQ0mfMXZ/gfua6YoMIiBhtBqywgCcXb17rF3U++316CX5sH + X-Google-Smtp-Source: AGHT+IG9Rij3GV3AvhS8/gHaDIBHzVZNeS/qRg41WD1ilZnkGyrSf4ZGr67ktcUGtkFnv9o6bCtsNQ== X-Received: by 2002:a05:600c:474a:b0:422:8557:2ef9 with SMTP id 5b1f17b1804b1-422865ac148mr12520255e9.30.1718180435895; Wed, 12 Jun 2024 01:20:35 -0700 (PDT) Received: from brgl-uxlite.home ([2a01:cb1d:8d3:3800:a172:4e8b:453e:2f03]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4229207d1a7sm6011775e9.1.2024.06.12.01.20.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Jun 2024 01:20:34 -0700 (PDT) From: Bartosz Golaszewski To: Bjorn Helgaas Cc: linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org, Bartosz Golaszewski , Amit Pundir , Neil Armstrong , Caleb Connolly Subject: [PATCH v9 2/5] PCI/pwrctl: Reuse the OF node for power controlled devices Date: Wed, 12 Jun 2024 10:20:15 +0200 Message-ID: <20240612082019.19161-3-brgl@bgdev.pl> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240612082019.19161-1-brgl@bgdev.pl> References: <20240612082019.19161-1-brgl@bgdev.pl> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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. Tested-by: Amit Pundir Tested-by: Neil Armstrong # on SM8550-QRD, SM86= 50-QRD & SM8650-HDK Tested-by: Caleb Connolly # OnePlus 8T Acked-by: Bjorn Helgaas 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 48ba95e4ab05..dacea3fc5128 100644 --- a/drivers/pci/of.c +++ b/drivers/pci/of.c @@ -6,6 +6,7 @@ */ #define pr_fmt(fmt) "PCI: OF: " fmt =20 +#include #include #include #include @@ -13,6 +14,7 @@ #include #include #include +#include #include "pci.h" =20 #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; =20 - node =3D of_pci_find_child_device(dev->bus->dev.of_node, dev->devfn); + struct device_node *node __free(device_node) =3D + of_pci_find_child_device(dev->bus->dev.of_node, dev->devfn); if (!node) return 0; =20 - device_set_node(&dev->dev, of_fwnode_handle(node)); + struct device *pdev __free(put_device) =3D + bus_find_device_by_of_node(&platform_bus_type, node); + if (pdev) + dev->bus->dev.of_node_reused =3D true; + + device_set_node(&dev->dev, of_fwnode_handle(no_free_ptr(node))); return 0; } =20 --=20 2.40.1 From nobody Thu Feb 12 12:29:38 2026 Received: from mail-wr1-f52.google.com (mail-wr1-f52.google.com [209.85.221.52]) (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 4E5FF16D9A0 for ; Wed, 12 Jun 2024 08:20:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.52 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718180442; cv=none; b=KjfzI1NZv2JRwgcM/shvzpkyLR8p4X4JQmG4n2GLhpRC1FvZfcZ6wuXzGO792YkeOOr+j1VBsJnI2Dtefal6YaKbERw6iuTyQt1eh3tc9+LuXSN552Cu1/Xto7XHXdEyIIDO4ZmfRVhmg9fVN1e5bw5ik1uqlp3o6UtRhSfNscQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718180442; c=relaxed/simple; bh=7VTZIUP9nLWj7cfEX4XfkS/W4JY/pRDIPDXFaZGz00o=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=JCjU6tUExtgKi1l6nNLI5z8kYDFHG76kk1Lr+6t72VQwZi9pNDBbKdim/NnMcB5cTj1dB5nYvN/ybzG3sALtdkEwPFiT9CSw+Odjg+hL2EQ+kKA2Cwcl6WsSUiLiWGWHUEpxG1QTZNQ3IsTlAd/lzWGA9b15GVPufgB3gP7Ef48= 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=Dyb+QMyY; arc=none smtp.client-ip=209.85.221.52 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="Dyb+QMyY" Received: by mail-wr1-f52.google.com with SMTP id ffacd0b85a97d-35f2c9e23d3so396021f8f.0 for ; Wed, 12 Jun 2024 01:20:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20230601.gappssmtp.com; s=20230601; t=1718180438; x=1718785238; 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=RO4KK4ghKfkxpXvlbkG5KB2nyFFgyIDnrF9c5Yq0jtU=; b=Dyb+QMyY92SfPQc4JHqfMBQs3TqFOy1etS9uBVK3HHao5f3WdbuZK58pDKlVAQxmWB MrxGj57KHCHM6o6R8loD0mjzXQuT1UsonG056sascQXqktRQjeoBFP+r6KsGB+YfM1ct ZdYQPEOuq3CGSeb5HTJzEDBTHbvPSWwePpOKXmzakO3qgraIl8Yd+h+8XUzyoHCYGHsI siJUbpUygk6MUKaqI/YG6YkJexgSq4l4EZesegQY/2B5Vo/dyNT1FKmLflR4GyBRNtKS kOid3v+FYvSIS+7M0+G0fHRRZZv0BN1HI0qBBKVc0MgdWu1YDNhRHFTVjTq1HcThsy4n mIDg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718180438; x=1718785238; 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=RO4KK4ghKfkxpXvlbkG5KB2nyFFgyIDnrF9c5Yq0jtU=; b=tYc05n+95xt+ssWjYhQGWyKrPik7mr8N62fzkpnAhcgkmiOWNCLx8S3jISWzHDCq1E lEDPbcf5T4m1gYNA0yDFsPB8qs0v61dipQiSMO3sDXZv8+CNX0QQLFk37iCuRKYnmIAM t1IJj2YLy4hMSW0WGbk73v/+OfjrlRLmtxCkke1D0UFI+/JrZptHYCPobXtaNBj+Q0vy a7b6Gp5iR8FHJYLwwGnaVKzaHDaFmuA/YouWNL4HUMOKg7Nqhi+BruSISTMfJoxLoHdK DagL106hpM1epR5jL1aq0R89oO9D1S/aTwlNeztmeT9N4CxOeN1hpEXN/Yz8GkAiLW6D A75Q== X-Gm-Message-State: AOJu0YyrfHP5IA9W0LBEp7so0P59XO+KNznn/vvmJ/7Bsx/yqa5dh9j9 X/JLnWe8GWS06YrpM5B2g1SLfGoe05DFLk0icjtF1Pm5nwhL5F+i7RS2oewPCe8= X-Google-Smtp-Source: AGHT+IEKZ9Pm55ZC6EKvZuzsmQYoUGEHjUjFOoy/AGQANYWcyrqioou452tdej8ico1+a6TdVtsKRQ== X-Received: by 2002:a5d:61c4:0:b0:35f:20a0:db65 with SMTP id ffacd0b85a97d-35f2b3093e7mr4333679f8f.25.1718180437759; Wed, 12 Jun 2024 01:20:37 -0700 (PDT) Received: from brgl-uxlite.home ([2a01:cb1d:8d3:3800:a172:4e8b:453e:2f03]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4229207d1a7sm6011775e9.1.2024.06.12.01.20.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Jun 2024 01:20:36 -0700 (PDT) From: Bartosz Golaszewski To: Bjorn Helgaas Cc: linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org, Bartosz Golaszewski , Amit Pundir , Neil Armstrong , Caleb Connolly Subject: [PATCH v9 3/5] PCI/pwrctl: Create platform devices for child OF nodes of the port node Date: Wed, 12 Jun 2024 10:20:16 +0200 Message-ID: <20240612082019.19161-4-brgl@bgdev.pl> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240612082019.19161-1-brgl@bgdev.pl> References: <20240612082019.19161-1-brgl@bgdev.pl> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Bartosz Golaszewski In preparation for introducing PCI device power control - a set of library functions that will allow powering-up of PCI devices before they're detected on the PCI bus - we need to populate the devices defined on the device-tree. We are reusing the platform bus as it provides us with all the infrastructure we need to match the pwrctl drivers against the compatibles from OF nodes. These platform devices will be probed by the driver core and bound to the PCI pwrctl drivers we'll introduce later. Tested-by: Amit Pundir Tested-by: Neil Armstrong # on SM8550-QRD, SM86= 50-QRD & SM8650-HDK Tested-by: Caleb Connolly # OnePlus 8T Acked-by: Bjorn Helgaas Signed-off-by: Bartosz Golaszewski --- drivers/pci/bus.c | 9 +++++++++ drivers/pci/remove.c | 3 ++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/drivers/pci/bus.c b/drivers/pci/bus.c index dfc99b3cb958..e4735428814d 100644 --- a/drivers/pci/bus.c +++ b/drivers/pci/bus.c @@ -12,6 +12,7 @@ #include #include #include +#include #include #include =20 @@ -348,6 +349,14 @@ void pci_bus_add_device(struct pci_dev *dev) pci_warn(dev, "device attach failed (%d)\n", retval); =20 pci_dev_assign_added(dev, true); + + if (pci_is_bridge(dev)) { + retval =3D of_platform_populate(dev->dev.of_node, NULL, NULL, + &dev->dev); + if (retval) + pci_err(dev, "failed to populate child OF nodes (%d)\n", + retval); + } } EXPORT_SYMBOL_GPL(pci_bus_add_device); =20 diff --git a/drivers/pci/remove.c b/drivers/pci/remove.c index d749ea8250d6..910387e5bdbf 100644 --- a/drivers/pci/remove.c +++ b/drivers/pci/remove.c @@ -1,6 +1,7 @@ // SPDX-License-Identifier: GPL-2.0 #include #include +#include #include "pci.h" =20 static void pci_free_resources(struct pci_dev *dev) @@ -18,7 +19,7 @@ static void pci_stop_dev(struct pci_dev *dev) pci_pme_active(dev, false); =20 if (pci_dev_is_added(dev)) { - + of_platform_depopulate(&dev->dev); device_release_driver(&dev->dev); pci_proc_detach_device(dev); pci_remove_sysfs_dev_files(dev); --=20 2.40.1 From nobody Thu Feb 12 12:29:38 2026 Received: from mail-wm1-f43.google.com (mail-wm1-f43.google.com [209.85.128.43]) (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 5C53E16D9C7 for ; Wed, 12 Jun 2024 08:20:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.43 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718180442; cv=none; b=jhxyy8mGH3hOl+KBETHiduUOsW3V4Az8zgAy+4dSxj0n90XgQqZD7AbI1+050qR3G4dh6RIF4GKNSapgnY02RxRp//pey7HNo0pzPO9EU/CmqkVgz7Wy7hlJfRGS/RjZvS1+8ghq6uAIcjp7ElXGbBWq+Z24bQNItrkCXa47Bnw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718180442; c=relaxed/simple; bh=3I55DHAulbbEoTA5EUCCLPTwbajLGxkDU7b0CJPBtcI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=UBXjVFPOToDVnxmKDj2cD+dV0lS8gfSD6kz8ZB8UjnzaNoxmCi7kweiSNb2DZX70BZYlkY1kWWRrcFQ9Eq62KCaNzzjfr0NALtR6CK7k7fJYR8fCI4XSYL8/g0Rm1tq/2xydnCcKfyPKmHgVvSoGSA94TL0I7ndMwUN1+3dWPdU= 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=watJ9OOL; arc=none smtp.client-ip=209.85.128.43 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="watJ9OOL" Received: by mail-wm1-f43.google.com with SMTP id 5b1f17b1804b1-42121d27861so55659535e9.0 for ; Wed, 12 Jun 2024 01:20:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20230601.gappssmtp.com; s=20230601; t=1718180439; x=1718785239; 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=V6nWyzSOGPKA2Mp3CmNA7KjAfXA/ZmzYq1I3hH4dLqM=; b=watJ9OOLRd1pKafh59IdfrabLjAcH2HYJJC0N2EDlR3dR0m11ywvnSm8tvnbITItcN XJyapkaCJFbt8qIQ5bcyq5QJZ2UU9ui2+BbnG5H+fCuXZa/oW1PulYWjHA3IS1yNJ5W5 TyIY60Nh0ivny+Rfyi1ML7eQv9ZQHF18oPKzCGu448c2jq1pvkxeVHgqcBcLkh/mS0p3 hgfAcSNJGt4BExRGLFa3h4QAl1xzHtKZuGVKXMPFI+ZFnQig9yoKRKLhn7LvTjIGMWy1 T3D4alfXHbkdkEG1Ql3TuE5JoYpJIlMDKHbdjjkVPjA0C7dnaFXnYkQWpCVCJOdFfdeo OPVA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718180439; x=1718785239; 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=V6nWyzSOGPKA2Mp3CmNA7KjAfXA/ZmzYq1I3hH4dLqM=; b=WqfNFsRIHNG5rdeuIOgNGyg9CeaTDQZJwQVQEtKg9EODoTMi0RbLW4o7I0s9v0ES83 wxTJFi8wdZCCWQcQb9z7+fovDds2N3+kDdHxGPu+8DsZN35bKAVrWkR7K4LVj+0c06NV kOJ+LklhPmehP9UWI8R47EYn5p+CnrEpUoQbmm/eHrS08qoMoh0lRf+/3QDznQ54qkYq 1sHOHj/1RSh8IcYlY5DxKubhPDVyEqvfg6sJXgd8FPUQzEozYcsS534PN0VAD5TBR5HF RJmSu3+Dlk+7+jGNj2qWjTD9lS1ru42+pZen/g3uN0N9596ZVi3djzjr5xYj1vLMu3jw HAZw== X-Gm-Message-State: AOJu0YztDSdVonynPMcrJPuleS2EqJF3WEm0ssYwENL3AGLkGp42krL8 wT+QSpsGI8Gtih0IigB8PSp8URhtzpPD5cJsZXceLl7GNlqKXiyxnIatfRfpDXk= X-Google-Smtp-Source: AGHT+IE1VNUQncsgDZB4FM/BSg9evn/Ju00aOKUPpsizvWcPCK8uB3fqCVA+RR9HyRAvRPNaxvnm8A== X-Received: by 2002:a05:600c:3546:b0:422:47a:15c8 with SMTP id 5b1f17b1804b1-422863ad92cmr10563735e9.12.1718180438713; Wed, 12 Jun 2024 01:20:38 -0700 (PDT) Received: from brgl-uxlite.home ([2a01:cb1d:8d3:3800:a172:4e8b:453e:2f03]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4229207d1a7sm6011775e9.1.2024.06.12.01.20.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Jun 2024 01:20:38 -0700 (PDT) From: Bartosz Golaszewski To: Bjorn Helgaas Cc: linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org, Bartosz Golaszewski , Amit Pundir , Neil Armstrong , Caleb Connolly Subject: [PATCH v9 4/5] PCI/pwrctl: Add PCI power control core code Date: Wed, 12 Jun 2024 10:20:17 +0200 Message-ID: <20240612082019.19161-5-brgl@bgdev.pl> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240612082019.19161-1-brgl@bgdev.pl> References: <20240612082019.19161-1-brgl@bgdev.pl> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Bartosz Golaszewski Some PCI devices must be powered-on before they can be detected on the bus. Introduce a simple framework reusing the existing PCI OF infrastructure. The way this works is: a DT node representing a PCI device connected to the port can be matched against its power control platform driver. If the match succeeds, the driver is responsible for powering-up the device and calling pci_pwrctl_device_set_ready() which will trigger a PCI bus rescan as well as subscribe to PCI bus notifications. When the device is detected and created, we'll make it consume the same DT node that the platform device did. When the device is bound, we'll create a device link between it and the parent power control device. Tested-by: Amit Pundir Tested-by: Neil Armstrong # on SM8550-QRD, SM86= 50-QRD & SM8650-HDK Tested-by: Caleb Connolly # OnePlus 8T Acked-by: Bjorn Helgaas Signed-off-by: Bartosz Golaszewski --- MAINTAINERS | 8 +++ drivers/pci/Kconfig | 1 + drivers/pci/Makefile | 1 + drivers/pci/pwrctl/Kconfig | 8 +++ drivers/pci/pwrctl/Makefile | 4 ++ drivers/pci/pwrctl/core.c | 137 ++++++++++++++++++++++++++++++++++++ include/linux/pci-pwrctl.h | 51 ++++++++++++++ 7 files changed, 210 insertions(+) create mode 100644 drivers/pci/pwrctl/Kconfig create mode 100644 drivers/pci/pwrctl/Makefile create mode 100644 drivers/pci/pwrctl/core.c create mode 100644 include/linux/pci-pwrctl.h diff --git a/MAINTAINERS b/MAINTAINERS index 3ee6e0cbc630..d8350d11a18d 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -17411,6 +17411,14 @@ F: Documentation/driver-api/pci/p2pdma.rst F: drivers/pci/p2pdma.c F: include/linux/pci-p2pdma.h =20 +PCI POWER CONTROL +M: Bartosz Golaszewski +L: linux-pci@vger.kernel.org +S: Maintained +T: git git://git.kernel.org/pub/scm/linux/kernel/git/pci/pci.git +F: drivers/pci/pwrctl/* +F: include/linux/pci-pwrctl.h + PCI SUBSYSTEM M: Bjorn Helgaas L: linux-pci@vger.kernel.org diff --git a/drivers/pci/Kconfig b/drivers/pci/Kconfig index d35001589d88..aa4d1833f442 100644 --- a/drivers/pci/Kconfig +++ b/drivers/pci/Kconfig @@ -296,5 +296,6 @@ source "drivers/pci/hotplug/Kconfig" source "drivers/pci/controller/Kconfig" source "drivers/pci/endpoint/Kconfig" source "drivers/pci/switch/Kconfig" +source "drivers/pci/pwrctl/Kconfig" =20 endif diff --git a/drivers/pci/Makefile b/drivers/pci/Makefile index 175302036890..8ddad57934a6 100644 --- a/drivers/pci/Makefile +++ b/drivers/pci/Makefile @@ -9,6 +9,7 @@ obj-$(CONFIG_PCI) +=3D access.o bus.o probe.o host-bridge.= o \ =20 obj-$(CONFIG_PCI) +=3D msi/ obj-$(CONFIG_PCI) +=3D pcie/ +obj-$(CONFIG_PCI) +=3D pwrctl/ =20 ifdef CONFIG_PCI obj-$(CONFIG_PROC_FS) +=3D proc.o diff --git a/drivers/pci/pwrctl/Kconfig b/drivers/pci/pwrctl/Kconfig new file mode 100644 index 000000000000..96195395af69 --- /dev/null +++ b/drivers/pci/pwrctl/Kconfig @@ -0,0 +1,8 @@ +# SPDX-License-Identifier: GPL-2.0-only + +menu "PCI Power control drivers" + +config PCI_PWRCTL + tristate + +endmenu diff --git a/drivers/pci/pwrctl/Makefile b/drivers/pci/pwrctl/Makefile new file mode 100644 index 000000000000..52ae0640ef7b --- /dev/null +++ b/drivers/pci/pwrctl/Makefile @@ -0,0 +1,4 @@ +# SPDX-License-Identifier: GPL-2.0-only + +obj-$(CONFIG_PCI_PWRCTL) +=3D pci-pwrctl-core.o +pci-pwrctl-core-y :=3D core.o diff --git a/drivers/pci/pwrctl/core.c b/drivers/pci/pwrctl/core.c new file mode 100644 index 000000000000..feca26ad2f6a --- /dev/null +++ b/drivers/pci/pwrctl/core.c @@ -0,0 +1,137 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Copyright (C) 2024 Linaro Ltd. + */ + +#include +#include +#include +#include +#include +#include +#include + +static int pci_pwrctl_notify(struct notifier_block *nb, unsigned long acti= on, + void *data) +{ + struct pci_pwrctl *pwrctl =3D container_of(nb, struct pci_pwrctl, nb); + struct device *dev =3D data; + + if (dev_fwnode(dev) !=3D dev_fwnode(pwrctl->dev)) + return NOTIFY_DONE; + + switch (action) { + case BUS_NOTIFY_ADD_DEVICE: + /* + * We will have two struct device objects bound to two different + * drivers on different buses but consuming the same DT node. We + * must not bind the pins twice in this case but only once for + * the first device to be added. + * + * If we got here then the PCI device is the second after the + * power control platform device. Mark its OF node as reused. + */ + dev->of_node_reused =3D true; + break; + case BUS_NOTIFY_BOUND_DRIVER: + pwrctl->link =3D device_link_add(dev, pwrctl->dev, + DL_FLAG_AUTOREMOVE_CONSUMER); + if (!pwrctl->link) + dev_err(pwrctl->dev, "Failed to add device link\n"); + break; + case BUS_NOTIFY_UNBOUND_DRIVER: + if (pwrctl->link) + device_link_remove(dev, pwrctl->dev); + break; + } + + return NOTIFY_DONE; +} + +/** + * pci_pwrctl_device_set_ready() - Notify the pwrctl subsystem that the PCI + * device is powered-up and ready to be detected. + * + * @pwrctl: PCI power control data. + * + * Returns: + * 0 on success, negative error number on error. + * + * Note: + * This function returning 0 doesn't mean the device was detected. It mean= s, + * that the bus rescan was successfully started. The device will get bound= to + * its PCI driver asynchronously. + */ +int pci_pwrctl_device_set_ready(struct pci_pwrctl *pwrctl) +{ + int ret; + + if (!pwrctl->dev) + return -ENODEV; + + pwrctl->nb.notifier_call =3D pci_pwrctl_notify; + ret =3D bus_register_notifier(&pci_bus_type, &pwrctl->nb); + if (ret) + return ret; + + pci_lock_rescan_remove(); + pci_rescan_bus(to_pci_dev(pwrctl->dev->parent)->bus); + pci_unlock_rescan_remove(); + + return 0; +} +EXPORT_SYMBOL_GPL(pci_pwrctl_device_set_ready); + +/** + * pci_pwrctl_device_unset_ready() - Notify the pwrctl subsystem that the = PCI + * device is about to be powered-down. + * + * @pwrctl: PCI power control data. + */ +void pci_pwrctl_device_unset_ready(struct pci_pwrctl *pwrctl) +{ + /* + * We don't have to delete the link here. Typically, this function + * is only called when the power control device is being detached. If + * it is being detached then the child PCI device must have already + * been unbound too or the device core wouldn't let us unbind. + */ + bus_unregister_notifier(&pci_bus_type, &pwrctl->nb); +} +EXPORT_SYMBOL_GPL(pci_pwrctl_device_unset_ready); + +static void devm_pci_pwrctl_device_unset_ready(void *data) +{ + struct pci_pwrctl *pwrctl =3D data; + + pci_pwrctl_device_unset_ready(pwrctl); +} + +/** + * devm_pci_pwrctl_device_set_ready - Managed variant of + * pci_pwrctl_device_set_ready(). + * + * @dev: Device managing this pwrctl provider. + * @pwrctl: PCI power control data. + * + * Returns: + * 0 on success, negative error number on error. + */ +int devm_pci_pwrctl_device_set_ready(struct device *dev, + struct pci_pwrctl *pwrctl) +{ + int ret; + + ret =3D pci_pwrctl_device_set_ready(pwrctl); + if (ret) + return ret; + + return devm_add_action_or_reset(dev, + devm_pci_pwrctl_device_unset_ready, + pwrctl); +} +EXPORT_SYMBOL_GPL(devm_pci_pwrctl_device_set_ready); + +MODULE_AUTHOR("Bartosz Golaszewski "); +MODULE_DESCRIPTION("PCI Device Power Control core driver"); +MODULE_LICENSE("GPL"); diff --git a/include/linux/pci-pwrctl.h b/include/linux/pci-pwrctl.h new file mode 100644 index 000000000000..45e9cfe740e4 --- /dev/null +++ b/include/linux/pci-pwrctl.h @@ -0,0 +1,51 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* + * Copyright (C) 2024 Linaro Ltd. + */ + +#ifndef __PCI_PWRCTL_H__ +#define __PCI_PWRCTL_H__ + +#include + +struct device; +struct device_link; + +/* + * This is a simple framework for solving the issue of PCI devices that re= quire + * certain resources (regulators, GPIOs, clocks) to be enabled before the + * device can actually be detected on the PCI bus. + * + * The idea is to reuse the platform bus to populate OF nodes describing t= he + * PCI device and its resources, let these platform devices probe and enab= le + * relevant resources and then trigger a rescan of the PCI bus allowing fo= r the + * same device (with a second associated struct device) to be registered w= ith + * the PCI subsystem. + * + * To preserve a correct hierarchy for PCI power management and device res= et, + * we create a device link between the power control platform device (pare= nt) + * and the supplied PCI device (child). + */ + +/** + * struct pci_pwrctl - PCI device power control context. + * @dev: Address of the power controlling device. + * + * An object of this type must be allocated by the PCI power control devic= e and + * passed to the pwrctl subsystem to trigger a bus rescan and setup a devi= ce + * link with the device once it's up. + */ +struct pci_pwrctl { + struct device *dev; + + /* Private: don't use. */ + struct notifier_block nb; + struct device_link *link; +}; + +int pci_pwrctl_device_set_ready(struct pci_pwrctl *pwrctl); +void pci_pwrctl_device_unset_ready(struct pci_pwrctl *pwrctl); +int devm_pci_pwrctl_device_set_ready(struct device *dev, + struct pci_pwrctl *pwrctl); + +#endif /* __PCI_PWRCTL_H__ */ --=20 2.40.1 From nobody Thu Feb 12 12:29:38 2026 Received: from mail-wm1-f53.google.com (mail-wm1-f53.google.com [209.85.128.53]) (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 D780716DEAD for ; Wed, 12 Jun 2024 08:20:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.53 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718180443; cv=none; b=Rx3IjQl1iFsoj6svzGqii2WG3BLZM4ykzBUlv74E5u/6lHHWW0bjhHVH7XwJoN09vSZVOPiH4m/kTxEPFqJ5D1yeGVjoQMG6GM5Grq0ZsgNa99djK3BUy8HnTbFC/yqUKhQCYtejKxnxJtlCtQoYiAllJCD9F5EDNjix7JulIjo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718180443; c=relaxed/simple; bh=5vtUivy1WsDU2PhTRIW8MACVGYRRPVmSCnZVpABDwUE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=no2fUGXgUOGhvARVPmiIy2XYlBlLie7gJVDn8NQPuE3aT0DH0I1DVOcv/m7CLribq4c/M6Yvryl6mGDb2PddjHFdxMj/BEjP3rI6nTx4iJz2MmCYoEuJ2hSl2lUhxJfd/qYa+ocSSpydmxOS9Vhq3UZKsdBqhFHWcWcPRQvR3bg= 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=2DcswdaS; arc=none smtp.client-ip=209.85.128.53 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="2DcswdaS" Received: by mail-wm1-f53.google.com with SMTP id 5b1f17b1804b1-4217926991fso38597455e9.3 for ; Wed, 12 Jun 2024 01:20:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20230601.gappssmtp.com; s=20230601; t=1718180439; x=1718785239; 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=1cFlU09skU5ebmY9aZrVFHQpziQipb3LWw7NexBUGMI=; b=2DcswdaSS6aZygc0pVThMlOZ9iOPckBFvB4vKU2FNRN/t1YpZ/WEbZOahc6aYhwqdA kIAEvAUVXKJYjAk030svcnbAHlPLQMRmd6Q6gBfO41nEzZfqSkgMqXPUc09xUSfSsYcY 3RaqvhMcuLYqA7BcXSCh4JD4Yr/eKQiOkPZFZudqLYhebKC4Ihfgr5PN7jtKv7+l2l0v DocbMezNCrVx4uF4uYfNcyC+1qvbR/p13ytPm1iyy2p73nOZpKg6+t18Qm0zuZFVvX4v neRM5OqubD8vBmnVL1Ogo7q4QUrSubadDKw3C0/kVNiWMgQzJUnbu9JOGRppZm/u2Tou zJOQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718180439; x=1718785239; 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=1cFlU09skU5ebmY9aZrVFHQpziQipb3LWw7NexBUGMI=; b=IfCDn0tQyhCPZlumYoKB8SAYoaDZrbk8e3E8K6wKyQ1YvO7DgnLRYiPZXkjEge/oa5 MMavnU2msAxpwJDeAcHghE/rKc3+aFpeFkC98fnNnXna6fCyGJJ4DKL+wxaHCiIc9emI C5j9MX+ZFLBeZDi/fSbnapHvQFcN16ovtJmtSZgRIzkIYc8qckbIVlP22oQ1ea+9iGWO UugHW2+Dlory6ezYWFra9JPojsIspZJDOPj2lryW7ritdt10ouTGOkkSOf8sB9l3Ufen 9T0KoS4eWHcozgb7QvlXTTnb5rrc/MmyZLdGrg3U4nECd7Sk6YUxdz2paxgvjq+ohcEv SKgA== X-Gm-Message-State: AOJu0YyxJZiC2WPze5G/bopW//nN2G+AwhksiMSatXb6um+oDxpPk9KZ ix5IqKkWORDAznvizu8sTmEZioeilYqy9gHkefkQp3NwHEDCUT+kIqDkCxPP3z3YtAyYbWwXFHn F X-Google-Smtp-Source: AGHT+IG8D07JiT1OikPRU9OM3y52o+XEz5z7NSHVHfr6c9/AiaBnLF01R6R5X1X6UseMtXKeogHU9g== X-Received: by 2002:a05:600c:358b:b0:422:6765:2726 with SMTP id 5b1f17b1804b1-422865ad68fmr9616235e9.30.1718180439724; Wed, 12 Jun 2024 01:20:39 -0700 (PDT) Received: from brgl-uxlite.home ([2a01:cb1d:8d3:3800:a172:4e8b:453e:2f03]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4229207d1a7sm6011775e9.1.2024.06.12.01.20.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Jun 2024 01:20:39 -0700 (PDT) From: Bartosz Golaszewski To: Bjorn Helgaas Cc: linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org, Bartosz Golaszewski , Amit Pundir , Neil Armstrong , Caleb Connolly Subject: [PATCH v9 5/5] PCI/pwrctl: Add a PCI power control driver for power sequenced devices Date: Wed, 12 Jun 2024 10:20:18 +0200 Message-ID: <20240612082019.19161-6-brgl@bgdev.pl> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240612082019.19161-1-brgl@bgdev.pl> References: <20240612082019.19161-1-brgl@bgdev.pl> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Bartosz Golaszewski Add a PCI power control driver that's capable of correctly powering up devices using the power sequencing subsystem. The first users of this driver are the ath11k module on QCA6390 and ath12k on WCN7850. These packages require a certain delay between enabling the Bluetooth and WLAN modules and the power sequencing subsystem takes care of it behind the scenes. Tested-by: Amit Pundir Tested-by: Neil Armstrong # on SM8550-QRD, SM86= 50-QRD & SM8650-HDK Tested-by: Caleb Connolly # OnePlus 8T Acked-by: Bjorn Helgaas Signed-off-by: Bartosz Golaszewski --- drivers/pci/pwrctl/Kconfig | 9 +++ drivers/pci/pwrctl/Makefile | 2 + drivers/pci/pwrctl/pci-pwrctl-pwrseq.c | 89 ++++++++++++++++++++++++++ 3 files changed, 100 insertions(+) create mode 100644 drivers/pci/pwrctl/pci-pwrctl-pwrseq.c diff --git a/drivers/pci/pwrctl/Kconfig b/drivers/pci/pwrctl/Kconfig index 96195395af69..f1b824955d4b 100644 --- a/drivers/pci/pwrctl/Kconfig +++ b/drivers/pci/pwrctl/Kconfig @@ -5,4 +5,13 @@ menu "PCI Power control drivers" config PCI_PWRCTL tristate =20 +config PCI_PWRCTL_PWRSEQ + tristate "PCI Power Control driver using the Power Sequencing subsystem" + select POWER_SEQUENCING + select PCI_PWRCTL + default m if ((ATH11K_PCI || ATH12K) && ARCH_QCOM) + help + Enable support for the PCI power control driver for device + drivers using the Power Sequencing subsystem. + endmenu diff --git a/drivers/pci/pwrctl/Makefile b/drivers/pci/pwrctl/Makefile index 52ae0640ef7b..d308aae4800c 100644 --- a/drivers/pci/pwrctl/Makefile +++ b/drivers/pci/pwrctl/Makefile @@ -2,3 +2,5 @@ =20 obj-$(CONFIG_PCI_PWRCTL) +=3D pci-pwrctl-core.o pci-pwrctl-core-y :=3D core.o + +obj-$(CONFIG_PCI_PWRCTL_PWRSEQ) +=3D pci-pwrctl-pwrseq.o diff --git a/drivers/pci/pwrctl/pci-pwrctl-pwrseq.c b/drivers/pci/pwrctl/pc= i-pwrctl-pwrseq.c new file mode 100644 index 000000000000..c7a113a76c0c --- /dev/null +++ b/drivers/pci/pwrctl/pci-pwrctl-pwrseq.c @@ -0,0 +1,89 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Copyright (C) 2024 Linaro Ltd. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +struct pci_pwrctl_pwrseq_data { + struct pci_pwrctl ctx; + struct pwrseq_desc *pwrseq; +}; + +static void devm_pci_pwrctl_pwrseq_power_off(void *data) +{ + struct pwrseq_desc *pwrseq =3D data; + + pwrseq_power_off(pwrseq); +} + +static int pci_pwrctl_pwrseq_probe(struct platform_device *pdev) +{ + struct pci_pwrctl_pwrseq_data *data; + struct device *dev =3D &pdev->dev; + int ret; + + data =3D devm_kzalloc(dev, sizeof(*data), GFP_KERNEL); + if (!data) + return -ENOMEM; + + data->pwrseq =3D devm_pwrseq_get(dev, of_device_get_match_data(dev)); + if (IS_ERR(data->pwrseq)) + return dev_err_probe(dev, PTR_ERR(data->pwrseq), + "Failed to get the power sequencer\n"); + + ret =3D pwrseq_power_on(data->pwrseq); + if (ret) + return dev_err_probe(dev, ret, + "Failed to power-on the device\n"); + + ret =3D devm_add_action_or_reset(dev, devm_pci_pwrctl_pwrseq_power_off, + data->pwrseq); + if (ret) + return ret; + + data->ctx.dev =3D dev; + + ret =3D devm_pci_pwrctl_device_set_ready(dev, &data->ctx); + if (ret) + return dev_err_probe(dev, ret, + "Failed to register the pwrctl wrapper\n"); + + return 0; +} + +static const struct of_device_id pci_pwrctl_pwrseq_of_match[] =3D { + { + /* ATH11K in QCA6390 package. */ + .compatible =3D "pci17cb,1101", + .data =3D "wlan", + }, + { + /* ATH12K in WCN7850 package. */ + .compatible =3D "pci17cb,1107", + .data =3D "wlan", + }, + { } +}; +MODULE_DEVICE_TABLE(of, pci_pwrctl_pwrseq_of_match); + +static struct platform_driver pci_pwrctl_pwrseq_driver =3D { + .driver =3D { + .name =3D "pci-pwrctl-pwrseq", + .of_match_table =3D pci_pwrctl_pwrseq_of_match, + }, + .probe =3D pci_pwrctl_pwrseq_probe, +}; +module_platform_driver(pci_pwrctl_pwrseq_driver); + +MODULE_AUTHOR("Bartosz Golaszewski "); +MODULE_DESCRIPTION("Generic PCI Power Control module for power sequenced d= evices"); +MODULE_LICENSE("GPL"); --=20 2.40.1