Received: by 2002:a05:7412:b130:b0:e2:908c:2ebd with SMTP id az48csp2372540rdb; Mon, 20 Nov 2023 09:08:41 -0800 (PST) X-Google-Smtp-Source: AGHT+IEVJ2rGI+LjdRP12H3tzU+syPOmEAe0YwUHNNUBMPHU4+bKLc+8pmvL814AYpXgq06VdRhW X-Received: by 2002:a05:6870:224e:b0:1e9:e923:9520 with SMTP id j14-20020a056870224e00b001e9e9239520mr9481994oaf.11.1700500121257; Mon, 20 Nov 2023 09:08:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700500121; cv=none; d=google.com; s=arc-20160816; b=Tmj+UpfHnfMpQELTzB8Da3sXhg5yLCup1cnDot9HXOK352acu27Z/BmZsJTxlahEqU ykkhQhZv2r/A1q7pirFT7l1Pu1mEPjF7U/oqtSzRsBLqxbooIskpTqrRjXxIWBaYY1IX QkHZKMjh4pSr21/FKxt/XIyGq2yQsaLMkZ7UukbJTt6lfbTV/HV/sOqyYgBa1cUJMFi/ uYg39nzxfOOEumMTmtyd88kP09tLmUBqzNWiUoIRdaO0ryn2bR4wz5ZNKlqk4w4k3lg7 5RpWfAaRD5JFtAJ2VsrAPnUtuYiYuRvQ1XWtmtxEOs4Bcr3X2zhEDIJ+XCdGsnKcwydI vSnQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:in-reply-to:references:message-id :content-transfer-encoding:mime-version:subject:date:from :dkim-signature; bh=QyeoyIjKWYnhadNlwnWChE/GqVDzf3ZKBilwOQ+lGlM=; fh=djCqQyCPITk/fGPikTLjejqXUdBjmgm6+WoI1E5KrDk=; b=phso+DLWCfhvnOABiADKolzMlTpEOg7Ug1Zfm+K6E8YRVJx7IuSritUwBdP2HEEtLh osxrPbFC/E/VPuYPOJY0yHV9y51MSaUn2BRnRwvUHOMkHwTqBwVThRtouWNGdoa+YvtS ariUdMcsHNqctx7zXti50fglJgWk+4zehRP7tU/DSK9mwvXacyZQnxEdEJDqy/LasThb 1bYUdpiVAxDf4N7SISli1fkEKo4XJRXmgJmb+6GmTKIoh8/ZpjAjhzyVCkSGyUuvsfrv 5p3ir7J846ILTVsWJ6Cj++1nYQjO/pvny3E2eYqEI9rCYl97NVG1x9fbkFYTY6Zja8Jg yNVQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=ZqmdI66z; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Return-Path: Received: from lipwig.vger.email (lipwig.vger.email. [23.128.96.33]) by mx.google.com with ESMTPS id g1-20020a056870d20100b001f94543bf8asi672120oac.175.2023.11.20.09.08.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Nov 2023 09:08:41 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) client-ip=23.128.96.33; Authentication-Results: mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=ZqmdI66z; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id 690A380436B4; Mon, 20 Nov 2023 09:07:07 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231839AbjKTRGU (ORCPT + 99 others); Mon, 20 Nov 2023 12:06:20 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46094 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229784AbjKTRGP (ORCPT ); Mon, 20 Nov 2023 12:06:15 -0500 Received: from relay4-d.mail.gandi.net (relay4-d.mail.gandi.net [217.70.183.196]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 39C40CB; Mon, 20 Nov 2023 09:06:11 -0800 (PST) Received: by mail.gandi.net (Postfix) with ESMTPSA id 3D902E000D; Mon, 20 Nov 2023 17:06:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1700499969; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=QyeoyIjKWYnhadNlwnWChE/GqVDzf3ZKBilwOQ+lGlM=; b=ZqmdI66z1vy8lWgmGU5/XHNerVlOhh8vrY35rXCsocJuovHqlABoeZpMuq+A1lizcvborJ 7rmOClkHFBTsjATqeTxyNG/BxA6y/J8DKS2HpJ4qGrlqLEtKXdD/RxZAhao/6aJBqWaTkU lLaqax7sJc507icl7mqUJ7Lgs7VhvIByEU2E9AjIRWRZMbRiPqAcZv75C6UVfBNJwGX6qo kETyAFJp1QO5QF/yY23b9RmMeu2v5N1rgPHdRUo7+IwnO1pi67rDHLTHjW00HqwukC5/Ru WE0upzToqBPx2Mp8unvEFMibO+vyyOmMbSGjztMIz2Er5RewGUQY4HanT1e+dw== From: =?utf-8?q?Th=C3=A9o_Lebrun?= Date: Mon, 20 Nov 2023 18:06:03 +0100 Subject: [PATCH v2 3/7] usb: cdns3-ti: move reg writes from probe into an init_hw helper MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit Message-Id: <20231120-j7200-usb-suspend-v2-3-038c7e4a3df4@bootlin.com> References: <20231120-j7200-usb-suspend-v2-0-038c7e4a3df4@bootlin.com> In-Reply-To: <20231120-j7200-usb-suspend-v2-0-038c7e4a3df4@bootlin.com> To: Greg Kroah-Hartman , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Roger Quadros , Peter Chen , Pawel Laszczak , Nishanth Menon , Vignesh Raghavendra , Tero Kristo Cc: linux-usb@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, "Thomas Petazzoni thomas.petazzoni"@bootlin.com, =?utf-8?q?Gr=C3=A9gory_Clement?= , =?utf-8?q?Th=C3=A9o_Lebrun?= X-Mailer: b4 0.12.3 X-GND-Sasl: theo.lebrun@bootlin.com X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (lipwig.vger.email [0.0.0.0]); Mon, 20 Nov 2023 09:07:07 -0800 (PST) The hardware initialisation register write sequence is only used at probe. To support suspend/resume with a controller losing power, we must redo this sequence of writes. Extract the register write sequence to a new cdns_ti_init_hw function to reuse it later down the road, at resume. We keep the devicetree-parsing aspect of the sequence in probe & add a new field in the private struct to remember the USB2 refclk rate code computation result. Signed-off-by: Théo Lebrun --- drivers/usb/cdns3/cdns3-ti.c | 76 ++++++++++++++++++++++++-------------------- 1 file changed, 41 insertions(+), 35 deletions(-) diff --git a/drivers/usb/cdns3/cdns3-ti.c b/drivers/usb/cdns3/cdns3-ti.c index dc1594acdcee..d4232b440e4e 100644 --- a/drivers/usb/cdns3/cdns3-ti.c +++ b/drivers/usb/cdns3/cdns3-ti.c @@ -57,6 +57,7 @@ struct cdns_ti { unsigned vbus_divider:1; struct clk *usb2_refclk; struct clk *lpm_clk; + int usb2_refclk_rate_code; }; static const int cdns_ti_rate_table[] = { /* in KHZ */ @@ -85,15 +86,50 @@ static inline void cdns_ti_writel(struct cdns_ti *data, u32 offset, u32 value) writel(value, data->usbss + offset); } +static void cdns_ti_init_hw(struct cdns_ti *data) +{ + u32 reg; + + /* assert RESET */ + reg = cdns_ti_readl(data, USBSS_W1); + reg &= ~USBSS_W1_PWRUP_RST; + cdns_ti_writel(data, USBSS_W1, reg); + + /* set static config */ + reg = cdns_ti_readl(data, USBSS_STATIC_CONFIG); + reg &= ~USBSS1_STATIC_PLL_REF_SEL_MASK; + reg |= data->usb2_refclk_rate_code << USBSS1_STATIC_PLL_REF_SEL_SHIFT; + + reg &= ~USBSS1_STATIC_VBUS_SEL_MASK; + if (data->vbus_divider) + reg |= 1 << USBSS1_STATIC_VBUS_SEL_SHIFT; + + cdns_ti_writel(data, USBSS_STATIC_CONFIG, reg); + reg = cdns_ti_readl(data, USBSS_STATIC_CONFIG); + + /* set USB2_ONLY mode if requested */ + reg = cdns_ti_readl(data, USBSS_W1); + if (data->usb2_only) + reg |= USBSS_W1_USB2_ONLY; + + /* set default modestrap */ + reg |= USBSS_W1_MODESTRAP_SEL; + reg &= ~USBSS_W1_MODESTRAP_MASK; + reg |= USBSS_MODESTRAP_MODE_NONE << USBSS_W1_MODESTRAP_SHIFT; + cdns_ti_writel(data, USBSS_W1, reg); + + /* de-assert RESET */ + reg |= USBSS_W1_PWRUP_RST; + cdns_ti_writel(data, USBSS_W1, reg); +} + static int cdns_ti_probe(struct platform_device *pdev) { struct device *dev = &pdev->dev; struct device_node *node = pdev->dev.of_node; struct cdns_ti *data; - int error; - u32 reg; - int rate_code, i; unsigned long rate; + int error, i; data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL); if (!data) @@ -133,41 +169,11 @@ static int cdns_ti_probe(struct platform_device *pdev) return -EINVAL; } - rate_code = i; - - /* assert RESET */ - reg = cdns_ti_readl(data, USBSS_W1); - reg &= ~USBSS_W1_PWRUP_RST; - cdns_ti_writel(data, USBSS_W1, reg); - - /* set static config */ - reg = cdns_ti_readl(data, USBSS_STATIC_CONFIG); - reg &= ~USBSS1_STATIC_PLL_REF_SEL_MASK; - reg |= rate_code << USBSS1_STATIC_PLL_REF_SEL_SHIFT; - - reg &= ~USBSS1_STATIC_VBUS_SEL_MASK; + data->usb2_refclk_rate_code = i; data->vbus_divider = device_property_read_bool(dev, "ti,vbus-divider"); - if (data->vbus_divider) - reg |= 1 << USBSS1_STATIC_VBUS_SEL_SHIFT; - - cdns_ti_writel(data, USBSS_STATIC_CONFIG, reg); - reg = cdns_ti_readl(data, USBSS_STATIC_CONFIG); - - /* set USB2_ONLY mode if requested */ - reg = cdns_ti_readl(data, USBSS_W1); data->usb2_only = device_property_read_bool(dev, "ti,usb2-only"); - if (data->usb2_only) - reg |= USBSS_W1_USB2_ONLY; - - /* set default modestrap */ - reg |= USBSS_W1_MODESTRAP_SEL; - reg &= ~USBSS_W1_MODESTRAP_MASK; - reg |= USBSS_MODESTRAP_MODE_NONE << USBSS_W1_MODESTRAP_SHIFT; - cdns_ti_writel(data, USBSS_W1, reg); - /* de-assert RESET */ - reg |= USBSS_W1_PWRUP_RST; - cdns_ti_writel(data, USBSS_W1, reg); + cdns_ti_init_hw(data); error = of_platform_populate(node, NULL, NULL, dev); if (error) { -- 2.42.0