Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 7BE83C7EE23 for ; Mon, 5 Jun 2023 11:04:36 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 9BE5C846AF; Mon, 5 Jun 2023 13:04:33 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=fail (p=none dis=none) header.from=arm.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Received: by phobos.denx.de (Postfix, from userid 109) id 7CD09846AF; Mon, 5 Jun 2023 13:04:32 +0200 (CEST) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by phobos.denx.de (Postfix) with ESMTP id 7EE5684692 for ; Mon, 5 Jun 2023 13:04:29 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=andre.przywara@arm.com Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 47E5ED75; Mon, 5 Jun 2023 04:05:14 -0700 (PDT) Received: from donnerap.cambridge.arm.com (usa-sjc-imap-foss1.foss.arm.com [10.121.207.14]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id E5FDF3F587; Mon, 5 Jun 2023 04:04:27 -0700 (PDT) Date: Mon, 5 Jun 2023 12:04:24 +0100 From: Andre Przywara To: Sam Edwards Cc: u-boot@lists.denx.de, Jagan Teki , Marek Vasut , Maksim Kiselev Subject: Re: [PATCH 1/3] usb: musb-new: sunxi: do not attempt to access NULL SRAMC Message-ID: <20230605120424.7ed91fb4@donnerap.cambridge.arm.com> In-Reply-To: <20230602214958.167909-2-CFSworks@gmail.com> References: <20230602214958.167909-1-CFSworks@gmail.com> <20230602214958.167909-2-CFSworks@gmail.com> Organization: ARM X-Mailer: Claws Mail 3.18.0 (GTK+ 2.24.32; aarch64-unknown-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.8 at phobos.denx.de X-Virus-Status: Clean On Fri, 2 Jun 2023 15:49:56 -0600 Sam Edwards wrote: Hi Sam, thanks for taking care and sending patched! > I believe that some sunxis (ncat2?) lack a SRAMC block, > as accessing this region results in a data abort. Ah, that's a good find, but I think it goes a bit deeper: Just to be clear, "SRAMC" stands for "SRAM controller", not "SRAM memory block C" (which other SoCs have, but indeed not the D1/T113s). However we (sort of) have an "SRAM controller", although the manual and DT call this IP block "syscon" these days. The address currently in ncat2.h is just plain wrong, it's actually 0x3000000. Now looking at the Linux MUSB driver, only the older SoCs (A10, A20, F1C100s) need to switch some SRAM block to the OTG controller: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/usb/musb/sunxi.c#n817 So the code is already wrong, we should not touch SYSCON+0x04 for any newer SoCs, based on the compatible. We seem to be just lucky that newer syscons don't have any register at offset 0x4. And using SUNXI_SRAMC_BASE is somewhat dodgy to begin with, we should use the "allwinner,sram" property from the DT, although this is surely more complicated. Do you have spare cycles to convert this over to look at the DT for this SRAM part? For now you might just change the SRAM address in ncat2.h to 0x03000000, to be inline with the other SoCs. Cheers, Andre > Checking > that it's non-null before accessing it allows this to be > set to NULL for SoCs where it's not present. > > Signed-off-by: Sam Edwards > --- > drivers/usb/musb-new/sunxi.c | 16 +++++++++------- > 1 file changed, 9 insertions(+), 7 deletions(-) > > diff --git a/drivers/usb/musb-new/sunxi.c b/drivers/usb/musb-new/sunxi.c > index dc4cfc2194..6e60dd47e0 100644 > --- a/drivers/usb/musb-new/sunxi.c > +++ b/drivers/usb/musb-new/sunxi.c > @@ -174,13 +174,15 @@ static void USBC_ForceVbusValidToHigh(__iomem void *base) > > static void USBC_ConfigFIFO_Base(void) > { > - u32 reg_value; > - > - /* config usb fifo, 8kb mode */ > - reg_value = readl(SUNXI_SRAMC_BASE + 0x04); > - reg_value &= ~(0x03 << 0); > - reg_value |= BIT(0); > - writel(reg_value, SUNXI_SRAMC_BASE + 0x04); > + if (SUNXI_SRAMC_BASE) { > + u32 reg_value; > + > + /* config usb fifo, 8kb mode */ > + reg_value = readl(SUNXI_SRAMC_BASE + 0x04); > + reg_value &= ~(0x03 << 0); > + reg_value |= BIT(0); > + writel(reg_value, SUNXI_SRAMC_BASE + 0x04); > + } > } > > /******************************************************************************