Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp233653pxb; Mon, 13 Sep 2021 17:54:30 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxrJHCNemlwei6um4bjsbN5rvbeYemUdaGOSuO7ilt2JPQqRTdvPxUb3tAarbP9NITMA3t3 X-Received: by 2002:aa7:da45:: with SMTP id w5mr235965eds.266.1631580869991; Mon, 13 Sep 2021 17:54:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631580869; cv=none; d=google.com; s=arc-20160816; b=S3VDXRbQROePk0qsIYJNwpV6ROkTHUilXi/jx9ZHcOqx8ME+o/1/TK4PbGJ0Q66oVB qH+pKZmHOrVIQPsDZR3AIa8UEr5PaGfARDD1Y6JOSfvXbv/Dv2mxR5wajE8GEulWmdas CNCotmBAG2Wqf++49nyflIQo/oB7Qtw+LzOqgXHV8btFqB2GxpeZ5ogHOL8/2HCvlKJi BZQO19jRagltl8TqW8ADF1rbDv4pSe+8MF5ZUypKajt8vTCktqdC6YiP7MuWBJiD4Jfc 2kztMiwKzr+JURXkSczc2orf6arZPywrsvWPneeS6KRCvgD+09dM2c81+SUvS+/zTFBO 03jw== 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=R40lnuVOPDAFwKP0GhhfcPbfn0vxygOvWXALVRsAuHQ=; b=FGyB+b/K6Tc9BJiUMYvwZygvh7rsfdgUbloG3Nw/viDj74cJkt2tXbQjNl4M3SQro3 0Yz74sSQpGZSmeDKxH9V9YY+iKK73O02dW08v5NniCa2R/Bb++dFIGSb8Qf//TwBfich TuvXZ3caVJleA6LAut9UL/prTXon+nvIT33v/n82YNdzDHPi1yDy4m4uogCdDjemEtbs nhblKYBzt2xSqw6gXPTkvAZPNF/MDJntUMeUYxLLabnTT1urM0nc+DS0kuOiy0G4AU0P +BY3q8s/WXtOPE8WgHF+h7Jf0bE6r3vzVBpeDeDtw8PX6gmODhgJrALryYQM3Ch34lje SqwQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id og42si6106795ejc.692.2021.09.13.17.54.06; Mon, 13 Sep 2021 17:54:29 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240092AbhIMS1v (ORCPT + 99 others); Mon, 13 Sep 2021 14:27:51 -0400 Received: from mail.kernel.org ([198.145.29.99]:59704 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239601AbhIMS1X (ORCPT ); Mon, 13 Sep 2021 14:27:23 -0400 Received: from disco-boy.misterjones.org (disco-boy.misterjones.org [51.254.78.96]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 9B6216108B; Mon, 13 Sep 2021 18:26:07 +0000 (UTC) Received: from [198.52.44.129] (helo=wait-a-minute.lan) by disco-boy.misterjones.org with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1mPqeb-00AYPD-Vd; Mon, 13 Sep 2021 19:26:06 +0100 From: Marc Zyngier To: devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org Cc: Bjorn Helgaas , Rob Herring , Lorenzo Pieralisi , =?UTF-8?q?Krzysztof=20Wilczy=C5=84ski?= , Alyssa Rosenzweig , Stan Skowronek , Mark Kettenis , Sven Peter , Hector Martin , Robin Murphy , kernel-team@android.com Subject: [PATCH v3 05/10] PCI: apple: Set up reference clocks when probing Date: Mon, 13 Sep 2021 19:25:45 +0100 Message-Id: <20210913182550.264165-6-maz@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210913182550.264165-1-maz@kernel.org> References: <20210913182550.264165-1-maz@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SA-Exim-Connect-IP: 198.52.44.129 X-SA-Exim-Rcpt-To: devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org, bhelgaas@google.com, robh+dt@kernel.org, lorenzo.pieralisi@arm.com, kw@linux.com, alyssa@rosenzweig.io, stan@corellium.com, kettenis@openbsd.org, sven@svenpeter.dev, marcan@marcan.st, Robin.Murphy@arm.com, kernel-team@android.com X-SA-Exim-Mail-From: maz@kernel.org X-SA-Exim-Scanned: No (on disco-boy.misterjones.org); SAEximRunCond expanded to false Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Alyssa Rosenzweig Apple's PCIe controller requires clocks to be configured in order to bring up the hardware. Add the register pokes required to do so. Adapted from Corellium's driver via Mark Kettenis's U-Boot patches. Co-developed-by: Stan Skowronek Signed-off-by: Stan Skowronek Signed-off-by: Alyssa Rosenzweig Signed-off-by: Marc Zyngier Link: https://lore.kernel.org/r/20210816031621.240268-4-alyssa@rosenzweig.io --- drivers/pci/controller/pcie-apple.c | 44 +++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/drivers/pci/controller/pcie-apple.c b/drivers/pci/controller/pcie-apple.c index f3c414950a10..dabbfc2e1fb0 100644 --- a/drivers/pci/controller/pcie-apple.c +++ b/drivers/pci/controller/pcie-apple.c @@ -132,6 +132,46 @@ static inline void rmwl(u32 clr, u32 set, void __iomem *addr) writel_relaxed((readl_relaxed(addr) & ~clr) | set, addr); } +static int apple_pcie_setup_refclk(struct apple_pcie *pcie, + struct apple_pcie_port *port) +{ + u32 stat; + int res; + + res = readl_relaxed_poll_timeout(pcie->base + CORE_RC_PHYIF_STAT, stat, + stat & CORE_RC_PHYIF_STAT_REFCLK, + 100, 50000); + if (res < 0) + return res; + + rmwl(0, CORE_LANE_CTL_CFGACC, pcie->base + CORE_LANE_CTL(port->idx)); + rmwl(0, CORE_LANE_CFG_REFCLK0REQ, pcie->base + CORE_LANE_CFG(port->idx)); + + res = readl_relaxed_poll_timeout(pcie->base + CORE_LANE_CFG(port->idx), + stat, stat & CORE_LANE_CFG_REFCLK0ACK, + 100, 50000); + if (res < 0) + return res; + + rmwl(0, CORE_LANE_CFG_REFCLK1, pcie->base + CORE_LANE_CFG(port->idx)); + res = readl_relaxed_poll_timeout(pcie->base + CORE_LANE_CFG(port->idx), + stat, stat & CORE_LANE_CFG_REFCLK1, + 100, 50000); + + if (res < 0) + return res; + + rmwl(CORE_LANE_CTL_CFGACC, 0, pcie->base + CORE_LANE_CTL(port->idx)); + + /* Flush writes before enabling the clocks */ + dma_wmb(); + + rmwl(0, CORE_LANE_CFG_REFCLKEN, pcie->base + CORE_LANE_CFG(port->idx)); + rmwl(0, PORT_REFCLK_EN, port->base + PORT_REFCLK); + + return 0; +} + static int apple_pcie_setup_port(struct apple_pcie *pcie, struct device_node *np) { @@ -165,6 +205,10 @@ static int apple_pcie_setup_port(struct apple_pcie *pcie, rmwl(0, PORT_APPCLK_EN, port + PORT_APPCLK); + ret = apple_pcie_setup_refclk(pcie, port); + if (ret < 0) + return ret; + rmwl(0, PORT_PERST_OFF, port->base + PORT_PERST); gpiod_set_value(reset, 1); -- 2.30.2