From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-14.0 required=3.0 tests=BAYES_00,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5B229C4338F for ; Sun, 15 Aug 2021 09:20:10 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3E04D61042 for ; Sun, 15 Aug 2021 09:20:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237189AbhHOJUi (ORCPT ); Sun, 15 Aug 2021 05:20:38 -0400 Received: from mail.kernel.org ([198.145.29.99]:60828 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237118AbhHOJUb (ORCPT ); Sun, 15 Aug 2021 05:20:31 -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 D557B6103D; Sun, 15 Aug 2021 09:20:01 +0000 (UTC) Received: from 109-170-232-56.xdsl.murphx.net ([109.170.232.56] helo=wait-a-minute.misterjones.org) 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 1mFCJD-0055cv-GI; Sun, 15 Aug 2021 10:19:59 +0100 Date: Sun, 15 Aug 2021 10:19:59 +0100 Message-ID: <877dgn12v4.wl-maz@kernel.org> From: Marc Zyngier To: Alyssa Rosenzweig Cc: linux-pci@vger.kernel.org, Bjorn Helgaas , Rob Herring , Lorenzo Pieralisi , Krzysztof =?UTF-8?B?V2lsY3p5xYRza2k=?= , Stan Skowronek , Mark Kettenis , Sven Peter , Hector Martin , devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [RFC PATCH 2/2] PCI: apple: Add driver for the Apple M1 In-Reply-To: <87a6lj17d1.wl-maz@kernel.org> References: <20210815042525.36878-1-alyssa@rosenzweig.io> <20210815042525.36878-3-alyssa@rosenzweig.io> <87a6lj17d1.wl-maz@kernel.org> User-Agent: Wanderlust/2.15.9 (Almost Unreal) SEMI-EPG/1.14.7 (Harue) FLIM-LB/1.14.9 (=?UTF-8?B?R29qxY0=?=) APEL-LB/10.8 EasyPG/1.0.0 Emacs/27.1 (x86_64-pc-linux-gnu) MULE/6.0 (HANACHIRUSATO) MIME-Version: 1.0 (generated by SEMI-EPG 1.14.7 - "Harue") Content-Type: text/plain; charset=US-ASCII X-SA-Exim-Connect-IP: 109.170.232.56 X-SA-Exim-Rcpt-To: alyssa@rosenzweig.io, linux-pci@vger.kernel.org, bhelgaas@google.com, robh+dt@kernel.org, lorenzo.pieralisi@arm.com, kw@linux.com, stan@corellium.com, kettenis@openbsd.org, sven@svenpeter.dev, marcan@marcan.st, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org 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 On Sun, 15 Aug 2021 08:42:50 +0100, Marc Zyngier wrote: > > On Sun, 15 Aug 2021 05:25:25 +0100, > Alyssa Rosenzweig wrote: > > > > Add a driver for the PCIe controller found in Apple system-on-chips, > > particularly the Apple M1. This driver exposes the internal bus used for > > the USB type-A ports, Ethernet, Wi-Fi, and Bluetooth. This patch brings > > up the USB type-A ports and Ethernet. Bringing up the radios requires > > interfacing with the System Management Coprocessor via Apple's > > mailboxes, so that's left to a future patch. > > > > In this state, the driver consists of two major parts: hardware > > initialization and MSI handling. The hardware initialization is derived > > from Mark Kettenis's U-Boot patches which in turn is derived from > > Corellium's patches for the hardware. The rest of the driver is derived > > from Marc Zyngier's driver for the hardware. > > This really needs to be split into multiple patches: > > - PCI probing > - Clock management > - MSI implementation > > A couple of comments below: > > > > > Co-developed-by: Stan Skowronek > > Signed-off-by: Stan Skowronek > > Co-developed-by: Marc Zyngier > > Signed-off-by: Marc Zyngier > > Signed-off-by: Alyssa Rosenzweig > > --- > > MAINTAINERS | 1 + > > drivers/pci/controller/Kconfig | 13 + > > drivers/pci/controller/Makefile | 1 + > > drivers/pci/controller/pcie-apple.c | 466 ++++++++++++++++++++++++++++ > > 4 files changed, 481 insertions(+) > > create mode 100644 drivers/pci/controller/pcie-apple.c > > [...] One last comment before I put the laptop away and go hiking for the day: > > +static int apple_pcie_setup_refclk(void __iomem *rc, > > + void __iomem *port, > > + unsigned int idx) > > +{ > > + u32 stat; > > + int res; > > + > > + res = readl_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_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_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)); > > + udelay(1); > > + rmwl(0, CORE_LANE_CFG_REFCLKEN, rc + CORE_LANE_CFG(idx)); > > + > > + rmwl(0, PORT_REFCLK_EN, port + PORT_REFCLK); > > + > > + return 0; > > +} This really wants to be moved to its own clock driver, unless there is a strong guarantee that the clock tree isn't shared with anything else. I expect that parts of that clock tree will need to be refcounted, and that's where having a real clock driver will help. I also have the strong feeling that the clock hierarchy will need to be described in DT one way or another, if only to be able to cope with future revisions of this block. Thanks, M. -- Without deviation from the norm, progress is not possible.