From patchwork Mon Nov 20 17:06:03 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Th=C3=A9o_Lebrun?= X-Patchwork-Id: 167276 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2b07:b0:403:3b70:6f57 with SMTP id io7csp79473vqb; Mon, 20 Nov 2023 09:08:45 -0800 (PST) X-Google-Smtp-Source: AGHT+IEIl06Q+yM9IFxW3FCuq5YUepxSGk/Se4Kp7OekZYrzPKhVUz/VdXRw6SEcxlHqK1gFuBI0 X-Received: by 2002:a05:6a20:7351:b0:189:6cf6:849c with SMTP id v17-20020a056a20735100b001896cf6849cmr6932728pzc.15.1700500125000; Mon, 20 Nov 2023 09:08:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700500124; cv=none; d=google.com; s=arc-20160816; b=AG8b0/Jpw8EikDTK27/SWgZKkMpkv/oKkFI4oIrAqRgNIRZ5dq8Rh7P5BN2UveLn02 DTdm6ydeM8pfqDUwf4VSkZ+tcNuEVKNJSdAcsGoRX/ARJUDN/dNOD/S/EiwSIpIznrlg yCowz9guMkEQArpP8a5l90b3LQUtrP7FOJt/EKZWO7ew+Y/nSQrbmVt+Too6KfVTvLm8 C+DruFfjH++sne03TgjX3Srqb7ifs/6642n9RgexTu4o8OwarKBeg7fIiw3/Oh7iCe2E ZAz/jL0Hb2N5y5klbVehdm2BbC7HwZGzIJkyaaA5Bo+DVvmqhP122gO6whsdDHjFk6AB P+4A== 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.37 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 snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id 4-20020a631944000000b00578d460cd7esi8002995pgz.431.2023.11.20.09.08.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Nov 2023 09:08:44 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; 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.37 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 snail.vger.email (Postfix) with ESMTP id 350FF805DC26; Mon, 20 Nov 2023 09:06:37 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231845AbjKTRGU (ORCPT + 27 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 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_Cle?= =?utf-8?q?ment?= , =?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=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_PASS,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net 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 (snail.vger.email [0.0.0.0]); Mon, 20 Nov 2023 09:06:37 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1783103619088293988 X-GMAIL-MSGID: 1783103619088293988 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) {