Received: by 2002:a05:6a10:c7d3:0:0:0:0 with SMTP id h19csp1403457pxy; Sun, 15 Aug 2021 20:19:15 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzj376u06tHz4bl5Z86WH8bkjyGMgufSEYH8T63uFdZMkbUUJZaDDatgpIKeg/Zv6dy1YQp X-Received: by 2002:a05:6402:30b6:: with SMTP id df22mr17053301edb.375.1629083955120; Sun, 15 Aug 2021 20:19:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1629083955; cv=none; d=google.com; s=arc-20160816; b=dl3a8SlE6G3cnzjCRsCURJ6opjFwodTY0mcM9+z10+1zI2Kqv3FDSCLsh4f2WxgfQv YEdjkV/T6JU0IzOkbqgK1FG4/DnNwzxqnFMx9bHZAFGw6ORhwEks9Io8CyC/cWU6yaxv st5tDe7YaM/Jp15+78Z+iKqo8HQ1BgByg4BmvXenIzMOkxLgqFnEaEEcw5fNkqTRiXk0 eLbUJaLAzNfgsKNEDVN8amSInEst6So7RmS4LWCVid6aHl7yHiRW7QBnnPt84s1BueaJ MDSs5jgrjaFlSKw10idcKZOIS5BllEDFGPxFn08BjPWeqTqv7lWPGNRDpIl7mS76Pbgd r/4g== 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=qydUTapeZJ7Mx2bgoewfc+jAn6gDo/UH1wAtAvSyYCc=; b=lOcsSDYMnAf078ZDzHBmrKI3S29g27DHJ3c7W8nZiIHjGFv9og6+O6helwOZZ0Hkee OI6VESpQXc8lwQg7kb6e7EWx2zcPGy3Y1x0Gw+Udhn4uY8oNs6/1eSjhD5lpIsiMqWTQ KXSs8ICOB8MvJNxArpwGF5BohJELH3wYSNg3d9ZnZnos0KMp8/ZlYQztHZCwrnQArs/x 9L4xV7C/kTigq0cueR/jt3S1ti3OoBusvEo4zMDMPjscXP5Hf0TAgBaDtyQ/LQW82MGJ PjprErqRYHrISWZ4x+4/DRaBw8N1zTs8yC1cgzj/M0ddi7OLkC4WapF1DWpxBjAn6L2w OqPA== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id dc21si9033691edb.493.2021.08.15.20.18.52; Sun, 15 Aug 2021 20:19:15 -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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232755AbhHPDRn (ORCPT + 99 others); Sun, 15 Aug 2021 23:17:43 -0400 Received: from [138.197.143.207] ([138.197.143.207]:45212 "EHLO rosenzweig.io" rhost-flags-FAIL-FAIL-OK-OK) by vger.kernel.org with ESMTP id S232628AbhHPDRm (ORCPT ); Sun, 15 Aug 2021 23:17:42 -0400 From: Alyssa Rosenzweig To: linux-pci@vger.kernel.org Cc: Bjorn Helgaas , Rob Herring , Lorenzo Pieralisi , =?UTF-8?q?Krzysztof=20Wilczy=C5=84ski?= , Alyssa Rosenzweig , Stan Skowronek , Marc Zyngier , Mark Kettenis , Sven Peter , Hector Martin , devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 3/6] PCI: apple: Set up reference clocks when probing Date: Sun, 15 Aug 2021 23:16:18 -0400 Message-Id: <20210816031621.240268-4-alyssa@rosenzweig.io> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210816031621.240268-1-alyssa@rosenzweig.io> References: <20210816031621.240268-1-alyssa@rosenzweig.io> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- drivers/pci/controller/pcie-apple.c | 47 +++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/drivers/pci/controller/pcie-apple.c b/drivers/pci/controller/pcie-apple.c index a1efcc3373ea..4ab767cf841b 100644 --- a/drivers/pci/controller/pcie-apple.c +++ b/drivers/pci/controller/pcie-apple.c @@ -126,6 +126,47 @@ 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(void __iomem *rc, + void __iomem *port, + unsigned int idx) +{ + u32 stat; + int res; + + res = readl_relaxed_poll_timeout(rc + CORE_RC_PHYIF_STAT, stat, + stat & CORE_RC_PHYIF_STAT_REFCLK, + 100, 50000); + if (res < 0) + return res; + + rmwl(0, CORE_LANE_CTL_CFGACC, rc + CORE_LANE_CTL(idx)); + rmwl(0, CORE_LANE_CFG_REFCLK0REQ, rc + CORE_LANE_CFG(idx)); + + res = readl_relaxed_poll_timeout(rc + CORE_LANE_CFG(idx), stat, + stat & CORE_LANE_CFG_REFCLK0ACK, + 100, 50000); + if (res < 0) + return res; + + rmwl(0, CORE_LANE_CFG_REFCLK1, rc + CORE_LANE_CFG(idx)); + res = readl_relaxed_poll_timeout(rc + CORE_LANE_CFG(idx), stat, + stat & CORE_LANE_CFG_REFCLK1, + 100, 50000); + + if (res < 0) + return res; + + rmwl(CORE_LANE_CTL_CFGACC, 0, rc + CORE_LANE_CTL(idx)); + + /* Flush writes before enabling the clocks */ + dma_wmb(); + + rmwl(0, CORE_LANE_CFG_REFCLKEN, rc + CORE_LANE_CFG(idx)); + rmwl(0, PORT_REFCLK_EN, port + PORT_REFCLK); + + return 0; +} + static int apple_pcie_setup_port(struct apple_pcie *pcie, struct gpio_desc *reset, unsigned int i) @@ -144,6 +185,12 @@ static int apple_pcie_setup_port(struct apple_pcie *pcie, if (readl_relaxed(port + PORT_LINKSTS) & PORT_LINKSTS_UP) return 0; + rmwl(0, PORT_APPCLK_EN, port + PORT_APPCLK); + + ret = apple_pcie_setup_refclk(pcie->rc, port, i); + if (ret < 0) + return ret; + rmwl(0, PORT_PERST_OFF, port + PORT_PERST); gpiod_set_value(reset, 1); -- 2.30.2