From patchwork Wed Jun 12 08:20:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 13694621 X-Patchwork-Delegate: bhelgaas@google.com Received: from mail-wm1-f50.google.com (mail-wm1-f50.google.com [209.85.128.50]) (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 0594E16C857 for ; Wed, 12 Jun 2024 08:20:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.50 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718180437; cv=none; b=RdyabnnH0TpKjGhzJosmYYbvCBo7j2r42i4swxz3n+uCbIshEsAarWvhludDPWquZCq38DPcA4byIuhrVZfsrDdvQSUJAWTxE/yaPZiSgKmNszFWTmvwu7s/MZ6MvA9cZ+iW12Ebw1fWcEyx0OzU1gwetSMVcl7cGcUg/PQfoF0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718180437; c=relaxed/simple; bh=7ODnCMLyMATh86YrN1ZPmjwWRMHpwQW+fCV8rLwj58E=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=gSLpPFGlHYv3v6ZUEmxjJnmkFYrNEobhn8Pl4yzYm1fbJ8rTA7cVwsXnJndJ/rBD1qnIV5dpVnN9Es64TvHHKf8+Vnrv6Fh2WN3B4etGS9yveUnsR0/HZzW+UxzMsG66NFIMVbuIf+X4qn54nGOUP3iNCgTkBqxACPQLg73ZU5s= 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.50 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-f50.google.com with SMTP id 5b1f17b1804b1-42281d8cd2dso4242325e9.3 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=MlDMUleXapvzgJ70MPSlXLZw9sdI3iAz/L5dgNmpBmyHrN+myhxeW4M8tJcpXn16qt LNhzew31B1FxA4hQy8lk9Yy7hj+OdPPLlfNUK6TUfsnPspnzHCtaKE4fKxK4BvZjK3PV I3CBJaIiCS/TNiYzePrLCeRXiCavFv1yHmIMGHGnxtyYV0GjnA6ed5dS5gj+J1jVySyl MqBFu7iXjppR1AblHTFDBHww1/VcTsYL+S2FmV+dxkBLd3kwrNfhO2q9PORDWzOCcVUR NHG+aG2d15pnhPZ6yVJHProgu+djX98z4hXZaeB97LnswVIxcNRtGJLtz9qcRGOyiQYK Hr5A== X-Forwarded-Encrypted: i=1; AJvYcCWmCp3Lz4mojDdnPiqdT12Usddvu8PduepgCdjGHd0yLyKQkNV8SiJzI0K5A9p8KUCbMRT92nXgsiyrf1C4R59nvIRf+06ideOL X-Gm-Message-State: AOJu0YyWvs+BNsrcWmzsIXHSGd1tNFj8K7vtwpcmyHp7BmEo5VYbefKd aUW4h72RaASmoBZ14xunRU6PJQR2hKkSiE4eWjoyCBChGx2rhW3wF+UrYPfTFVU= 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-pci@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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, SM8650-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; + pci_lock_rescan_remove(); ret = pci_scan_root_bus_bridge(bridge); + pci_unlock_rescan_remove(); if (ret < 0) { dev_err(bridge->dev.parent, "Scanning root bridge failed"); return ret; From patchwork Wed Jun 12 08:20:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 13694622 X-Patchwork-Delegate: bhelgaas@google.com Received: from mail-wm1-f42.google.com (mail-wm1-f42.google.com [209.85.128.42]) (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 70BE616D337 for ; Wed, 12 Jun 2024 08:20:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.42 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718180439; cv=none; b=BoLToJV7ArbTB27bsY6VKVi3jbxWRDlSIwkbYyr4Q9hhbEytd7ALuXW2OOzLwxUtD+xxidA/UTYcQ+xwUojjpskVBtsELxvCQSC/39UYqUFzRQIe9vPy9oGDkMUN2hFdEiSU/GwsJDhzPaZEBZcU7YHts0TWFRlZkN+60a9iVoM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718180439; c=relaxed/simple; bh=z26s4JsQKN7nhVU9IlT3jZC8JXh2Ex5Rgl+dEf47fr8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=B+qfqynv0jOdeHs2twFVw84gtIzIRPhP6rZndQ+LVAUyGZ72sw2lKPw+mSPY2Wn1OZPOM+nyB3eon5EuhkZnRPtpReOJ+c5XBIehSbJuxPoXjOm6uSJdyp61qVpjY3VQWGfFnqpwT9KTd+lFQOEDOfq4mW357QaIuSRJfom+eUA= 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.42 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-f42.google.com with SMTP id 5b1f17b1804b1-42281d8cd2dso4242445e9.3 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=NGJ744Fuu6dmXmGIhspSrqnsQkE+BhyxOqe4yyEqnvV0hRWSvEi3+rQIwitBae270O LIZEuZLrnte0FdPiAZOn8fbsXBjpaWJIX6r2xRkfyIn0p9px+ng8CbJQX2np5cJRwfLe ZMAC90DgLLsPCJFDK1vVdB/8yMYr1Xh7TEwGg2MUPAK782pCmFP6K+lOMuYgHLnk8jMp Ug7IYHKf+yoAaszydowyT+f78ZT2ozsAjL9KtWbhyYmF+midRIXd+9+94ckdRHwLZ0Kr R/xT/FoV4tVj2AQH2drghHCFnD3olHlStOrVTZ+1ipKBjb0crtvpiiIAdFNNSA2ZgEq7 C2QQ== X-Forwarded-Encrypted: i=1; AJvYcCUoyYBFFWyel7G0H1+gdQb7IQGuKDZVqm4idVBbDQuutMJmoFyyChW/20G2LXz3+MGiiwe3DqUAhCVpZAUtoKLGAJsmbBGk6dBl X-Gm-Message-State: AOJu0Yw47klQ6iY/Kn+w2urERllq7P2EA6MBulGBrnMe242TB+eq91JK 2C8UvMh9iR3io8krS1LBJdw8RrCtomkxh+eEYf90UbQolDWkZXciU/fs65a81EQ= 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-pci@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. Tested-by: Amit Pundir Tested-by: Neil Armstrong # on SM8550-QRD, SM8650-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 +#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; } From patchwork Wed Jun 12 08:20:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 13694623 X-Patchwork-Delegate: bhelgaas@google.com Received: from mail-wr1-f50.google.com (mail-wr1-f50.google.com [209.85.221.50]) (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 514D816D9A1 for ; Wed, 12 Jun 2024 08:20:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.50 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718180440; cv=none; b=fQnxtY5fl3jNMlpzILyXxqGcqGM7q61hp7HuW6/1l5eQv8RfzAxdoxBTuHyO3bSDRYOAyOvXxBibMUzTgFfRzgNgoxmZuTdxKjEhXTL1r+LqMGKiif6hROMpw8jG9J47MBpt+u7OQqxiP6krJFzzcHY/SBgadADuWe1KUxXzezU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718180440; c=relaxed/simple; bh=7VTZIUP9nLWj7cfEX4XfkS/W4JY/pRDIPDXFaZGz00o=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=JC4uNYOCxAqs0x3jcjrhbC4Q2+wD2wrwWJQYqzqslqa9ya7wVbimakA4dd6ruMkQxllRJL6/Sx8AkAoSZIlXc50FygUTYFjfHIWxnkOrycfpALXpnVJP7+Q6yR/C5c6IjvgBS6omRP7CVHuORAiMBYcxf+edpQEQx4B9jvl3Rzs= 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.50 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-f50.google.com with SMTP id ffacd0b85a97d-35f2c0b7701so376375f8f.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=msHKEUA87zsSos/nbxcgXKVPpnBzIz/c+CTmPdYoqu0k1j1Fswl54dLtXhwYaohwVJ LD/FVHzN7IcQ5g+Q6KDEHJxwpYUMrrUYro2Ez3yVYjAZxXakOFAkk60961EXlOiTRUJj fD/6sXYvdaExfbmdbSK/JJecrPKJH8g80fTndwqI8+G/k9Uw7i7R8sPKDvVOm1S6eUQk doyGDXvZ7HCorzQGORae+59JwRpX9RwoV6xufO9NMmT/vwxAl+gF1U+WCANV14x5+MTx wG9bI6dIpE5MzlotS4CfDxq200++BFO+2VB3zUwg+Db9I8wO+4reyc0us1hKMVWpdmIm tuuQ== X-Forwarded-Encrypted: i=1; AJvYcCVEIYnCBULOvUiAB7AA0I+QP7KyD8kL4H6nF1O8XagRILZgFezn/o2Vw4FO1zo6imBghL1XZAo4lr9ulCCwOqt/+kw7H6EUcR4b X-Gm-Message-State: AOJu0Yw/kjxLGTLL3aRAJSDohfugj4svIPvlMgTPAMcWgWXIXkTDtdB0 s4RAMljmn49HvbAJPbmm9+Tof29pJMi23IDkZOKtKUx97ZUzaU2j4/oLk0SEGfs= 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-pci@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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, SM8650-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 @@ -348,6 +349,14 @@ void pci_bus_add_device(struct pci_dev *dev) pci_warn(dev, "device attach failed (%d)\n", retval); pci_dev_assign_added(dev, true); + + if (pci_is_bridge(dev)) { + retval = 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); 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" 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); 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); From patchwork Wed Jun 12 08:20:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 13694624 X-Patchwork-Delegate: bhelgaas@google.com Received: from mail-wm1-f47.google.com (mail-wm1-f47.google.com [209.85.128.47]) (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 40AB016D9C3 for ; Wed, 12 Jun 2024 08:20:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.47 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718180441; cv=none; b=ULSVNGqS16kcCOWj2eCZpWr5HXAfHtDlKGHgL0vD69JJ4GREJ0S9s2OhSUhJdZIEiYJo71dB+P5o/hqDpLbdaGcAvCW6a2zcKtxjIrC6yR0Ju22dT603xD3NCNraDzfTuJuuOkskk2CnAzD/fku7jMnFSlC2SVzLr+nd3pKiSE4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718180441; c=relaxed/simple; bh=3I55DHAulbbEoTA5EUCCLPTwbajLGxkDU7b0CJPBtcI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=qpx8sOrbSGzi6rgeAx/qRrVFWCimSSPzl+Kshlf17/hGy5GzDGi4KUHo1dSxZD98OoyT+eb237pHW+7ojde2PqH5OSvw3mXfpyKsf4AXQtFCo22F5VC1tEiwXjGKOvFew8XFwVvzObMaCaZzMIjpYo9kv2blLQhe1rFeVeW/Pa0= 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.47 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-f47.google.com with SMTP id 5b1f17b1804b1-421798185f0so35470095e9.1 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=p6iS5u1yyrd3raI07tQC8bINePn7PwoReIY9YHIcQImx6NWWqBrF/Bm4kQ1t1NCMFW GvKodS27HrAT0rGYsAOemQ/AB7rwhba2OLeNwSmtgXVXj4GwamODYQ0yfiUodMt5elHU 0VbrTvB6MgGBzc9iV7e+J83u4Wp8W3RxGoBoYMhlfFU8CcgSkqq5kpRck3M/SY3JbEck 7StOX162ZhC8ZLOpYlWjW/gM1xYXCgXJF18jmlo9k++vaj9vxoJGAg3Hmqpq9Rl7qNmk gXZFyy87jrFVRLQFBUG3eeUUO+ZZJjbOLj1P9efJy1T4J7CgwGWceVilJ01hWKH5LQET +7wA== X-Forwarded-Encrypted: i=1; AJvYcCXiwwpDWydIOJ3kHKZUpk7mu+OmryeDaoeVZ/mSIss41WHT/sxVdT2ihQXXa6kqk1RuslcGz+v+SynYdCN8AH0iKC8n40nPz/Sk X-Gm-Message-State: AOJu0YxWPvvM/ACR9MZU6/qzm+dvcbVEyI2wu/xJEQIzwVAWjz9wLbtX t6tHv4E7aR6Xosz42JOnlIhG1xzXumesUZfayP7qBteAgppglDgDhAkJPNQW/tE= 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-pci@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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, SM8650-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 +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" 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) += access.o bus.o probe.o host-bridge.o \ obj-$(CONFIG_PCI) += msi/ obj-$(CONFIG_PCI) += pcie/ +obj-$(CONFIG_PCI) += pwrctl/ ifdef CONFIG_PCI obj-$(CONFIG_PROC_FS) += 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) += pci-pwrctl-core.o +pci-pwrctl-core-y := 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 action, + void *data) +{ + struct pci_pwrctl *pwrctl = container_of(nb, struct pci_pwrctl, nb); + struct device *dev = data; + + if (dev_fwnode(dev) != 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 = true; + break; + case BUS_NOTIFY_BOUND_DRIVER: + pwrctl->link = 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 means, + * 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 = pci_pwrctl_notify; + ret = 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 = 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 = 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 require + * 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 the + * PCI device and its resources, let these platform devices probe and enable + * relevant resources and then trigger a rescan of the PCI bus allowing for the + * same device (with a second associated struct device) to be registered with + * the PCI subsystem. + * + * To preserve a correct hierarchy for PCI power management and device reset, + * we create a device link between the power control platform device (parent) + * 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 device and + * passed to the pwrctl subsystem to trigger a bus rescan and setup a device + * 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__ */ From patchwork Wed Jun 12 08:20: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: 13694625 X-Patchwork-Delegate: bhelgaas@google.com Received: from mail-wm1-f52.google.com (mail-wm1-f52.google.com [209.85.128.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 2C84716D9DF for ; Wed, 12 Jun 2024 08:20:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.52 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718180442; cv=none; b=MqJbBw4aXNXRCWyiO/AQmIn9dqGGr4AfLN9kWGlngNxTU9VJZtClvVe90Pel5ItRKcu2kNPUaPT+BuvOiJl9HXy9kLYJnstsIkgNa72gXb91GaR3tjaRqmVVX5tw08IATN3i5seBmevtNHvTcBjArYF/uULhS8duzd338vdpGr0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718180442; c=relaxed/simple; bh=5vtUivy1WsDU2PhTRIW8MACVGYRRPVmSCnZVpABDwUE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=C2KqMLTTWvv9Jiatfv2CAVUAD4Ug1FLV+2E55hENWrknEraeIwYzo4Cu9KjsqD7sh5XtIISmBStWWFwzubeirO9vjuaUmlRLxqnDa+sAVI2lmHPdwopmMANgW/KvmowGoJFPaHVfEYgRGhrdsnbg2vAhu2NMN2U6PloVnayOfX8= 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.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="2DcswdaS" Received: by mail-wm1-f52.google.com with SMTP id 5b1f17b1804b1-4210aa012e5so19886995e9.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=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=SofGWWt5/ogqupQ/JYqqqipJGCG16vaBskwHOA9qBa7HYT4pKoxuSPKfDXSqk2BKN6 B3/2WVrN0IU2yf6tuG/sFj5rtVNQrMcUq3oQEdDpxpNeM4ivPTVyN6b1Ee+7c3d5ScC3 Xyj4sn7iiOrdlfDCZty6cRs585PU3eMdybBKEbJVwB0302zXYcPipFmyEbWPMRLz/7Bj +olWEMFzfSUz8/2YIbtIHcMvkvFXnj+8/v0KG+iopFdOenZ1kCcPlnPTEkw3PszRJywF ocp5RVp2kgiCzVXhl/u2E83bwSxXoBj8UlHg5Nb/FjIPn0DshrJGso5H/lKcg2YPJShs Lzvw== X-Forwarded-Encrypted: i=1; AJvYcCWbAVq5Wc5K+92L4hO0vC4jBdEaIfm2Mj2n/1aQlk7pkEVvsWaztnRCeof/rVmbxfpjIb5hv9pWpgx6m+6Emu9GItnnwF/P8NLo X-Gm-Message-State: AOJu0Yx+5xWKMM9FqD4zCHw5cqZfZXIVpsEL0/KOcvZQqYbXNVM15tlJ Muu7gGcSbPlROAGOoFP4JNZMworiU3Oy1KSs/zyHrFrI6TwaDXFhOikQMe0Uae8= 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-pci@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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, SM8650-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 +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 @@ obj-$(CONFIG_PCI_PWRCTL) += pci-pwrctl-core.o pci-pwrctl-core-y := core.o + +obj-$(CONFIG_PCI_PWRCTL_PWRSEQ) += pci-pwrctl-pwrseq.o diff --git a/drivers/pci/pwrctl/pci-pwrctl-pwrseq.c b/drivers/pci/pwrctl/pci-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 = data; + + pwrseq_power_off(pwrseq); +} + +static int pci_pwrctl_pwrseq_probe(struct platform_device *pdev) +{ + struct pci_pwrctl_pwrseq_data *data; + struct device *dev = &pdev->dev; + int ret; + + data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL); + if (!data) + return -ENOMEM; + + data->pwrseq = 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 = pwrseq_power_on(data->pwrseq); + if (ret) + return dev_err_probe(dev, ret, + "Failed to power-on the device\n"); + + ret = devm_add_action_or_reset(dev, devm_pci_pwrctl_pwrseq_power_off, + data->pwrseq); + if (ret) + return ret; + + data->ctx.dev = dev; + + ret = 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[] = { + { + /* ATH11K in QCA6390 package. */ + .compatible = "pci17cb,1101", + .data = "wlan", + }, + { + /* ATH12K in WCN7850 package. */ + .compatible = "pci17cb,1107", + .data = "wlan", + }, + { } +}; +MODULE_DEVICE_TABLE(of, pci_pwrctl_pwrseq_of_match); + +static struct platform_driver pci_pwrctl_pwrseq_driver = { + .driver = { + .name = "pci-pwrctl-pwrseq", + .of_match_table = pci_pwrctl_pwrseq_of_match, + }, + .probe = 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 devices"); +MODULE_LICENSE("GPL");