From patchwork Fri Jun 9 21:37:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sam Edwards X-Patchwork-Id: 1793243 X-Patchwork-Delegate: marek.vasut@gmail.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20221208 header.b=aJCTJbPD; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4QdDw90pBxz20Vx for ; Sat, 10 Jun 2023 07:38:17 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 7B82B86129; Fri, 9 Jun 2023 23:37:49 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="aJCTJbPD"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id C883A857D0; Fri, 9 Jun 2023 23:37:45 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-io1-xd2f.google.com (mail-io1-xd2f.google.com [IPv6:2607:f8b0:4864:20::d2f]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id A477D86128 for ; Fri, 9 Jun 2023 23:37:41 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=cfsworks@gmail.com Received: by mail-io1-xd2f.google.com with SMTP id ca18e2360f4ac-77493b3d18cso103889239f.0 for ; Fri, 09 Jun 2023 14:37:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1686346660; x=1688938660; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=3BlJMMJLTNG1KIIAi+FIYfquRlSjFhF8iJq/NWZeyww=; b=aJCTJbPDocNIVX3XhBVsFAo6NcUbcEebHmUvM1pulapZiJba9Xs1xW2TmN/On9z4Lu F1xdYqqcK8vUQd/oDlJM7iGFucFTnVpOqJh/sUOjIQ7t+1b4yuAn4GhjcCe/wggR0/vC pRfcfjbcLgmK83plu9xsqW7xsJQ6yvlQunpEoOhKUf4zO0WeTsXtyRmq3EyaRqP5/e6n iGYT+2kVKm+7mRkoOptMUxGyMJxT2d9aYx8foePsknOJDchMhn+ODVIqSMAGEOm+np/S vhN7xNoT+R3FcFtb/6xfXowkHgBilXvx0qFDY/IhHOzJMSDnAIGpgWyp8/bqiIhmNwGe ye9Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686346660; x=1688938660; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=3BlJMMJLTNG1KIIAi+FIYfquRlSjFhF8iJq/NWZeyww=; b=Z7Jt3XPFtgrKck9Ic+rTOhf/CKq9d1521KwpVWLILikO3uD8D+s8pj3kFpM7ih3tBN HLyrwFpNkYJ1H+8HoiT0ZdWrXBJk+pq7DQuAjb4KhwUa1LAhVNUQs1xPtG7xO+2+FIip VTbqrFPrGT8RQ8a7QjHi3ZC8FPAX/ZWdAGNA8EUUp4fYvlEmFRyQ7G6rZ+RT89HgUSeJ RpO9f33/a/iHm48p/y5sAFeGMELXSzs0UwngyChjp9N87cV1psQPKzjBa3cPQUjN9eHZ G55ckZk4d2mf43KDA+wo48rYSdqoNvBr8Z06qQF7hwDp2wEi7K/tQb969WH4SOjnItUj WMmw== X-Gm-Message-State: AC+VfDyM5TAEl3WRGJngx966/6qN8sTXBJ/uEGFvsnmW0/f+HrPnWIxn El6X2QWLUzLrAtV7p5MyqD1nJDjrpT4e1QET X-Google-Smtp-Source: ACHHUZ4pqz+2cpXQvBjm0rcN1jrRxa4vw4C3pMhUf4yX23yb255FPTMMv45z4RdXv9hRc0lUuxghDA== X-Received: by 2002:a5e:db41:0:b0:77a:c494:b4be with SMTP id r1-20020a5edb41000000b0077ac494b4bemr2790008iop.19.1686346660105; Fri, 09 Jun 2023 14:37:40 -0700 (PDT) Received: from celestia.nettie.lan ([2001:470:42c4:101:d264:8856:b4e9:a431]) by smtp.gmail.com with ESMTPSA id x6-20020a5e8306000000b0077a1b6f73b9sm1309187iom.41.2023.06.09.14.37.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 09 Jun 2023 14:37:39 -0700 (PDT) From: Sam Edwards X-Google-Original-From: Sam Edwards To: u-boot@lists.denx.de Cc: Andre Przywara , Jagan Teki , Marek Vasut , Sam Edwards Subject: [PATCH v2 2/2] usb: musb-new: sunxi: clarify the purpose of SRAM initialization Date: Fri, 9 Jun 2023 15:37:16 -0600 Message-Id: <20230609213716.107339-3-CFSworks@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230609213716.107339-1-CFSworks@gmail.com> References: <20230609213716.107339-1-CFSworks@gmail.com> MIME-Version: 1.0 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 This is largely a cosmetic change, with one functional distinction: We are now only setting BIT(0), and no longer clearing BIT(1). The A20 manual confirms the purpose and bitwidth of this field, and we have also been doing it this way for a while in Linux-land: The prior narrative about this initialization being about configuring a FIFO has pretty much been debunked for years now. This cleanup also adds a TODO comment about runtime discovery of the SYSCON base, per discussion with Andre. Signed-off-by: Sam Edwards Cc: Andre Przywara --- drivers/usb/musb-new/sunxi.c | 38 +++++++++++++++++++++++++++--------- 1 file changed, 29 insertions(+), 9 deletions(-) diff --git a/drivers/usb/musb-new/sunxi.c b/drivers/usb/musb-new/sunxi.c index 1111a67eaf..be7faaa11e 100644 --- a/drivers/usb/musb-new/sunxi.c +++ b/drivers/usb/musb-new/sunxi.c @@ -171,15 +171,29 @@ static void USBC_ForceVbusValidToHigh(__iomem void *base) musb_writel(base, USBC_REG_o_ISCR, reg_val); } -static void USBC_ConfigFIFO_Base(void) -{ - u32 reg_value; +/****************************************************************************** + * Non-USBC register access needed for initialization + ******************************************************************************/ - /* 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); +/* + * A10(s), A13, GR8, A20: + * switch ownership of SRAM block 'D' to the USB-OTG controller + */ +static void sunxi_musb_claim_sram(void) +{ + /* + * TODO: Do not use hardcoded SUNXI_SRAMC_BASE; find the syscon base by + * traversing this OTG device's `allwinner,sram` FDT property and + * working upward to the system controller. + */ + void *syscon_base = (void *)SUNXI_SRAMC_BASE; + + /* + * BIT(0) of SRAM_CTRL_REG1 (syscon+0x04) controls SRAM-D ownership: + * '0' -> exclusive access by CPU + * '1' -> exclusive access by USB0 + */ + setbits_le32(syscon_base + 0x04, BIT(0)); } /****************************************************************************** @@ -313,7 +327,13 @@ static int sunxi_musb_init(struct musb *musb) musb->isr = sunxi_musb_interrupt; if (glue->cfg->has_sram) { - USBC_ConfigFIFO_Base(); + /* + * This is an older USB-OTG controller that Allwinner did not + * endow with a dedicated SRAM block; it instead uses SRAM + * block 'D', ownership of which needs to be handed over by + * the CPU + */ + sunxi_musb_claim_sram(); } USBC_EnableDpDmPullUp(musb->mregs);