Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp250629iob; Mon, 2 May 2022 18:33:27 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzW2CpXRSfCyC8K4EDMx33edVCsDFFvzJeLexXbOzOPpgTu5v0gb/Bn2v4BwfmRCjkpjFb4 X-Received: by 2002:a17:902:b085:b0:15d:325e:8649 with SMTP id p5-20020a170902b08500b0015d325e8649mr14398837plr.119.1651541607330; Mon, 02 May 2022 18:33:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651541607; cv=none; d=google.com; s=arc-20160816; b=WHYPrhBmyC70RYY75ENi3NgX1bDtNUP68GDGQN1BzTSMHZzk1mCG+0FSWFY03rS0Fb i+LUUFVIN1VfVt5rVSgLCig+jVfQ7R/YUP4mEHL8x2FQbPgEB3Xnc8t+fiskCSi2nEZV v0liRHehAQjTlsCRBS0PWw3rwYCktUoZxT+oDbL6XP10g4XxmcXLdqFOCSYVc6vYOyTs O9lKzBROAheLoAMDpb4O4EC3j4jKvOUTwhp2MdMILKRH2WnCFu6EeA2D7RmDoT7xfFTP jD2fudJmJ7kPkJDgUoXJGUGlx0Qc1zLolx6CCwKcXwXV1B0kHzs21xlcf5WROUNc8yq1 bTlg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=HIb8fm0eq7wBa3UYU/YvrDLWxo5rUVydLdKEFY7FaPg=; b=HDHOX0rmOgymAsfS45Fbp0EfHbi5Wm7lCdeWLmBsEx9gfdFOzmFcMBJMWyY1TVN4sB Do/balfoxK5hoaDF3xMP/57wwq7NYQXackFm2k8JXEcpuCIOAdHiURY6DWODl85MIhAr aj1rrAtIHw1ow0Hk5L3ED9y6/E8M+YRomtBwdOA+51+NdPVjU5Plq2FrGLVPiEM9Drc6 s8bwTq8UtiRfMs5SEzweM+Njn+eTZtw7RqiMNq+yC3/5+8FT/e+haMol/5UEY4E/DcHy GQlYbvKP4sLBV+nmShCNrG/3xD6ZzwoEu1QfsW5m/SeNCxJSHf6eX6m35QO6Y3O0CbQU KsEg== ARC-Authentication-Results: i=1; mx.google.com; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=marcan.st Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id z9-20020a170903018900b0015e91bd566esi7463629plg.27.2022.05.02.18.33.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 May 2022 18:33:27 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=marcan.st Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 2236A517D6; Mon, 2 May 2022 18:17:15 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1384248AbiEBJmh (ORCPT + 99 others); Mon, 2 May 2022 05:42:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44884 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1384295AbiEBJmb (ORCPT ); Mon, 2 May 2022 05:42:31 -0400 Received: from mail.marcansoft.com (marcansoft.com [212.63.210.85]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B824747577 for ; Mon, 2 May 2022 02:39:02 -0700 (PDT) Received: from [127.0.0.1] (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: hector@marcansoft.com) by mail.marcansoft.com (Postfix) with ESMTPSA id 4639E41982; Mon, 2 May 2022 09:38:58 +0000 (UTC) From: Hector Martin To: Marc Zyngier Cc: Hector Martin , Lorenzo Pieralisi , Rob Herring , =?UTF-8?q?Krzysztof=20Wilczy=C5=84ski?= , Bjorn Helgaas , Alyssa Rosenzweig , Sven Peter , linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 3/3] PCI: apple: Add support for optional PWREN GPIO Date: Mon, 2 May 2022 18:38:32 +0900 Message-Id: <20220502093832.32778-4-marcan@marcan.st> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220502093832.32778-1-marcan@marcan.st> References: <20220502093832.32778-1-marcan@marcan.st> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RDNS_NONE, SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org WiFi and SD card devices on M1 Macs have a separate power enable GPIO. Add support for this to the PCIe controller. This is modeled after how pcie-fu740 does it. Signed-off-by: Hector Martin --- drivers/pci/controller/pcie-apple.c | 35 ++++++++++++++++++++++++++--- 1 file changed, 32 insertions(+), 3 deletions(-) diff --git a/drivers/pci/controller/pcie-apple.c b/drivers/pci/controller/pcie-apple.c index e3aa2d461739..5b73c03ebe94 100644 --- a/drivers/pci/controller/pcie-apple.c +++ b/drivers/pci/controller/pcie-apple.c @@ -518,6 +518,16 @@ static int apple_pcie_probe_port(struct device_node *np) } gpiod_put(gd); + + gd = gpiod_get_from_of_node(np, "pwren-gpios", 0, + GPIOD_OUT_LOW, "PWREN"); + if (IS_ERR(gd)) { + if (PTR_ERR(gd) != -ENOENT) + return PTR_ERR(gd); + } else { + gpiod_put(gd); + } + return 0; } @@ -526,7 +536,7 @@ static int apple_pcie_setup_port(struct apple_pcie *pcie, { struct platform_device *platform = to_platform_device(pcie->dev); struct apple_pcie_port *port; - struct gpio_desc *reset; + struct gpio_desc *reset, *pwren = NULL; u32 stat, idx; int ret, i; @@ -535,6 +545,15 @@ static int apple_pcie_setup_port(struct apple_pcie *pcie, if (IS_ERR(reset)) return PTR_ERR(reset); + pwren = devm_gpiod_get_from_of_node(pcie->dev, np, "pwren-gpios", 0, + GPIOD_OUT_LOW, "PWREN"); + if (IS_ERR(pwren)) { + if (PTR_ERR(pwren) == -ENOENT) + pwren = NULL; + else + return PTR_ERR(pwren); + } + port = devm_kzalloc(pcie->dev, sizeof(*port), GFP_KERNEL); if (!port) return -ENOMEM; @@ -557,12 +576,22 @@ static int apple_pcie_setup_port(struct apple_pcie *pcie, /* Assert PERST# before setting up the clock */ gpiod_set_value_cansleep(reset, 1); + /* Power on the device if required */ + if (pwren) + gpiod_set_value_cansleep(pwren, 1); + ret = apple_pcie_setup_refclk(pcie, port); if (ret < 0) return ret; - /* The minimal Tperst-clk value is 100us (PCIe CEM r5.0, 2.9.2) */ - usleep_range(100, 200); + /* + * The minimal Tperst-clk value is 100us (PCIe CEM r5.0, 2.9.2) + * If powering up, the minimal Tpvperl is 100ms + */ + if (pwren) + msleep(100); + else + usleep_range(100, 200); /* Deassert PERST# */ rmw_set(PORT_PERST_OFF, port->base + PORT_PERST); -- 2.35.1