Received: by 2002:ab2:788f:0:b0:1ee:8f2e:70ae with SMTP id b15csp604325lqi; Thu, 7 Mar 2024 06:40:01 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVs0T8bDSi/e/V35I13y/6R89mI0KVOzFMf7p9pOEIMZUhlj0+OcThl8Vy2dgqYiSdDQ0F8Uyxtr6sjkx7tOlPcYhtowCMvM1bxsW6eDw== X-Google-Smtp-Source: AGHT+IFHh5Rm3KTgLABgBRAXpvZ4flCyVNabS7PfNUXraqwo8GVKYOPW3h/hDdcC5I+SRgMSh5Mi X-Received: by 2002:a05:6a20:6a06:b0:1a1:7529:194d with SMTP id p6-20020a056a206a0600b001a17529194dmr1788322pzk.11.1709822401603; Thu, 07 Mar 2024 06:40:01 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709822401; cv=pass; d=google.com; s=arc-20160816; b=U/e/tuSsfvm6XWqfsgjHx9+U6mz28zs0LHg+8k4Yhkt5UceP+qK7NQCJ35nx1cTlQ2 xfMDh8l/kvrb0K1kig2yE0q3Ah6Fesqx/OqpE+GOOHoJI3BLN2MliRqhcGqthUpREh8o lLkAYs8tqsMIEeO9sLMZP7Ad7MYhZ4vam/ZeincSXZyk4YS3Xs7oNtwOlIC7TEjt/BrP eXuyk6Y1gT3iatZ396bwT0A2vGn1VPx9b6SElL1Zh0kSK19KOpAROKaEDqSquQJmwfzW wd2zcel9IyoLYv0uocb8rEFW/SVdNoFzwoTS1yJV9Ve9j1vtIr4uh/Wa9GWyZu95ySyo Lu3Q== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:references:to:cc:subject:from:message-id:date :content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:dkim-signature; bh=DyyvLt3PFqGEcHS9MBOofH4aGB4ndkaOSLBfw95+8NY=; fh=ZQKm7WlQdqY4mdZ3v/Li9gKmhFgh1dK+MswwiZhVHYw=; b=ppdmLHZ9HAw34BA/7pFPz2XbM8fS+OTsmKEzixK/n611X65nZ7rZ9y8l38jWyIQtWA c4XL+2GC2RgKC+4sek5G9zokPs12FpbVoRiLH0aWrpZPreq/MGyjhendDSv2T7Yv0Iuq 9obEKUAnu3e7bqV/NG3JrzZL+nd0bprLcTuG9KDxOWBrRiTsMe25eeXpxzY8NQXdzHS2 d/Ohd6gZGABzbizKy3pIdgw77uvp1AyK32G87oOf+M/mhQ3pmW6yBKnLZjRvv7gbSD4Q lOgoFYCSzX+BoEzjmX3Tat0515v5cIi8iWxQf+EImgNW55Sd5NUJiIy2qTtgNAVsq/xZ Mo0A==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=KUvVw+Y0; arc=pass (i=1 spf=pass spfdomain=bootlin.com dkim=pass dkdomain=bootlin.com dmarc=pass fromdomain=bootlin.com); spf=pass (google.com: domain of linux-kernel+bounces-95754-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-95754-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id g15-20020a056a000b8f00b006e6660588f2si331027pfj.227.2024.03.07.06.40.01 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Mar 2024 06:40:01 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-95754-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=KUvVw+Y0; arc=pass (i=1 spf=pass spfdomain=bootlin.com dkim=pass dkdomain=bootlin.com dmarc=pass fromdomain=bootlin.com); spf=pass (google.com: domain of linux-kernel+bounces-95754-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-95754-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id DFA7E288B86 for ; Thu, 7 Mar 2024 14:40:00 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 5435F1EB23; Thu, 7 Mar 2024 14:39:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="KUvVw+Y0" Received: from relay4-d.mail.gandi.net (relay4-d.mail.gandi.net [217.70.183.196]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 791801B96E; Thu, 7 Mar 2024 14:39:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.196 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709822368; cv=none; b=Mp263hkAvLv78rWwUdPze7jM+Njf2sCRsp7JMQOTaoQOE/Ur7N0HHgax+MUZgbw25o1vccN8a1G6e8PaYDGv7CTAUwPMs/oTIY632VSJXzjOMZboWsGXLx7IE54tq+lzjhLpHgOBHOHtLyxaFcvAbCz10rRkwjf53BMA00yuIh8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709822368; c=relaxed/simple; bh=1wda9rVFemYUpjfFp/MVZ9nQg/5x5u0oC4XBV/jPWOA=; h=Mime-Version:Content-Type:Date:Message-Id:From:Subject:Cc:To: References:In-Reply-To; b=i3Kgy7IldpVvEL+PdXmRahd7U8im/McxGJ2wTzfu207IDseQQ+PAw//PrkauBGHI8fq8/3zFeMYM/WMzTjIcIGao2caHO0dVADbwrh7W7UcY0Y2T5NVwfiuqJoddbabkXIf/ZMFUQICybV1zb0OP5qHffKDCYilfG3xkMXqs5BY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=KUvVw+Y0; arc=none smtp.client-ip=217.70.183.196 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bootlin.com Received: by mail.gandi.net (Postfix) with ESMTPSA id D65D3E000D; Thu, 7 Mar 2024 14:39:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1709822357; 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=DyyvLt3PFqGEcHS9MBOofH4aGB4ndkaOSLBfw95+8NY=; b=KUvVw+Y01jMAdb7/WuVobY4KF3yUKmM23k9AgcVjHc/v5OwMpPfYQ4ZgVXW3tRHpjZGuPi 938qrKHa+lMcaX+rAnjITZIzrZWJLGP0FI/6LyDu6CZdYfR3Ig9b3SzffXnNEDNyVmVKGi UUuO75aY3JPLLly0cdYMCCxDVzR+LQ8W+CPLo2J96wObP+emCBrFhPMEB/CUpC/zRf7sQ4 TSipvoVusU1LiQXGZw+6Et2ykxxFnvj689jZgGU/bsjVSy/iVgJn0Kz2AnXQf3dICGHhEe GtZrD40tK6eSXTpacy4F6dnwfRzpyhDXLI1i7c7AzPI7y0k48UOIbCKJQZA/BA== Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=UTF-8 Date: Thu, 07 Mar 2024 15:39:15 +0100 Message-Id: From: =?utf-8?q?Th=C3=A9o_Lebrun?= Subject: Re: [PATCH v4 3/9] usb: cdns3-ti: move reg writes from probe into ->runtime_resume() Cc: "Thomas Petazzoni" , =?utf-8?q?Gr=C3=A9gory_Clement?= , "Kevin Hilman" , "Alan Stern" , , , , To: "Roger Quadros" , "Greg Kroah-Hartman" , "Rob Herring" , "Krzysztof Kozlowski" , "Conor Dooley" , "Peter Chen" , "Pawel Laszczak" , "Nishanth Menon" , "Vignesh Raghavendra" , "Tero Kristo" X-Mailer: aerc 0.15.2 References: <20240307-j7200-usb-suspend-v4-0-5ec7615431f3@bootlin.com> <20240307-j7200-usb-suspend-v4-3-5ec7615431f3@bootlin.com> In-Reply-To: X-GND-Sasl: theo.lebrun@bootlin.com Hello Roger, On Thu Mar 7, 2024 at 1:31 PM CET, Roger Quadros wrote: > Hi, > > On 07/03/2024 11:55, Th=C3=A9o Lebrun wrote: > > The hardware initialisation register write sequence is only used at > > probe. Move it from being done at explicitely at probe to being done > > implicitely by pm_runtime_get_sync() that calls ->runtime_resume(). > > explicitly / implicitly > > >=20 > > Keep devicetree parsing in probe and add a new field in the private > > struct to remember the USB2 refclk rate code computation result. > >=20 > > This opens the door to having the init sequence being executed later > > down the road, at system-wide resume for example. This is NOT currently > > happening because runtime PM is disabled at suspend without the > > refcount being affected. > >=20 > > Signed-off-by: Th=C3=A9o Lebrun > > --- > > drivers/usb/cdns3/cdns3-ti.c | 90 +++++++++++++++++++++++++-----------= -------- > > 1 file changed, 52 insertions(+), 38 deletions(-) > >=20 > > diff --git a/drivers/usb/cdns3/cdns3-ti.c b/drivers/usb/cdns3/cdns3-ti.= c > > index 5945c4b1e11f..4c8a557e6a6f 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; > > }; > > =20 > > static const int cdns_ti_rate_table[] =3D { /* in KHZ */ > > @@ -90,10 +91,8 @@ static int cdns_ti_probe(struct platform_device *pde= v) > > struct device *dev =3D &pdev->dev; > > struct device_node *node =3D pdev->dev.of_node; > > struct cdns_ti *data; > > - int error; > > - u32 reg; > > - int rate_code, i; > > unsigned long rate; > > + int error, i; > > =20 > > data =3D devm_kzalloc(dev, sizeof(*data), GFP_KERNEL); > > if (!data) > > @@ -133,7 +132,9 @@ static int cdns_ti_probe(struct platform_device *pd= ev) > > return -EINVAL; > > } > > =20 > > - rate_code =3D i; > > + data->usb2_refclk_rate_code =3D i; > > + data->vbus_divider =3D device_property_read_bool(dev, "ti,vbus-divide= r"); > > + data->usb2_only =3D device_property_read_bool(dev, "ti,usb2-only"); > > =20 > > pm_runtime_enable(dev); > > error =3D pm_runtime_get_sync(dev); > > @@ -142,40 +143,6 @@ static int cdns_ti_probe(struct platform_device *p= dev) > > goto err; > > } > > =20 > > - /* assert RESET */ > > - reg =3D cdns_ti_readl(data, USBSS_W1); > > - reg &=3D ~USBSS_W1_PWRUP_RST; > > - cdns_ti_writel(data, USBSS_W1, reg); > > - > > - /* set static config */ > > - reg =3D cdns_ti_readl(data, USBSS_STATIC_CONFIG); > > - reg &=3D ~USBSS1_STATIC_PLL_REF_SEL_MASK; > > - reg |=3D rate_code << USBSS1_STATIC_PLL_REF_SEL_SHIFT; > > - > > - reg &=3D ~USBSS1_STATIC_VBUS_SEL_MASK; > > - data->vbus_divider =3D device_property_read_bool(dev, "ti,vbus-divide= r"); > > - if (data->vbus_divider) > > - reg |=3D 1 << USBSS1_STATIC_VBUS_SEL_SHIFT; > > - > > - cdns_ti_writel(data, USBSS_STATIC_CONFIG, reg); > > - reg =3D cdns_ti_readl(data, USBSS_STATIC_CONFIG); > > - > > - /* set USB2_ONLY mode if requested */ > > - reg =3D cdns_ti_readl(data, USBSS_W1); > > - data->usb2_only =3D device_property_read_bool(dev, "ti,usb2-only"); > > - if (data->usb2_only) > > - reg |=3D USBSS_W1_USB2_ONLY; > > - > > - /* set default modestrap */ > > - reg |=3D USBSS_W1_MODESTRAP_SEL; > > - reg &=3D ~USBSS_W1_MODESTRAP_MASK; > > - reg |=3D USBSS_MODESTRAP_MODE_NONE << USBSS_W1_MODESTRAP_SHIFT; > > - cdns_ti_writel(data, USBSS_W1, reg); > > - > > - /* de-assert RESET */ > > - reg |=3D USBSS_W1_PWRUP_RST; > > - cdns_ti_writel(data, USBSS_W1, reg); > > - > > error =3D of_platform_populate(node, NULL, NULL, dev); > > if (error) { > > dev_err(dev, "failed to create children: %d\n", error); > > @@ -211,6 +178,52 @@ static void cdns_ti_remove(struct platform_device = *pdev) > > platform_set_drvdata(pdev, NULL); > > } > > =20 > > +static int cdns_ti_runtime_resume(struct device *dev) > > +{ > > + struct cdns_ti *data =3D dev_get_drvdata(dev); > > + u32 reg; > > + > > + /* assert RESET */ > > + reg =3D cdns_ti_readl(data, USBSS_W1); > > + reg &=3D ~USBSS_W1_PWRUP_RST; > > + cdns_ti_writel(data, USBSS_W1, reg); > > + > > + /* set static config */ > > + reg =3D cdns_ti_readl(data, USBSS_STATIC_CONFIG); > > + reg &=3D ~USBSS1_STATIC_PLL_REF_SEL_MASK; > > + reg |=3D data->usb2_refclk_rate_code << USBSS1_STATIC_PLL_REF_SEL_SHI= FT; > > + > > + reg &=3D ~USBSS1_STATIC_VBUS_SEL_MASK; > > + > > + if (data->vbus_divider) > > + reg |=3D 1 << USBSS1_STATIC_VBUS_SEL_SHIFT; > > + > > + cdns_ti_writel(data, USBSS_STATIC_CONFIG, reg); > > + reg =3D cdns_ti_readl(data, USBSS_STATIC_CONFIG); > > + > > + /* set USB2_ONLY mode if requested */ > > + reg =3D cdns_ti_readl(data, USBSS_W1); > > + > > + if (data->usb2_only) > > + reg |=3D USBSS_W1_USB2_ONLY; > > + > > + /* set default modestrap */ > > + reg |=3D USBSS_W1_MODESTRAP_SEL; > > + reg &=3D ~USBSS_W1_MODESTRAP_MASK; > > + reg |=3D USBSS_MODESTRAP_MODE_NONE << USBSS_W1_MODESTRAP_SHIFT; > > + cdns_ti_writel(data, USBSS_W1, reg); > > + > > + /* de-assert RESET */ > > + reg |=3D USBSS_W1_PWRUP_RST; > > + cdns_ti_writel(data, USBSS_W1, reg); > > I don't think USB controller requires a reset and re-init between > runtime suspend/resume. > > What you need is reset/re-init during system Resume on certain platforms. > So you should move this part of code into a helper function and call it > from .probe() and .system_resume() Runtime resume is being called at probe() and system-wide resume. See our runtime_resume() implementation as that helper function you are describing. A previous revision did what you are recommending. We leaned towards the current version. See: https://lore.kernel.org/lkml/7h34wxfmwn.fsf@baylibre.com/ Also, assuming we enable runtime PM, a reset and re-init after runtime suspend would be the right thing to do anyways. My reading of drivers/pmdomain/core.c tells me that if our device goes to runtime suspend, domains will be shut down. Our controller will be reset and we'll need to re-init it. The GENPD_FLAG_RPM_ALWAYS_ON flag is of interest to avoid the PD to be shut down during runtime PM. Regards, -- Th=C3=A9o Lebrun, Bootlin Embedded Linux and Kernel engineering https://bootlin.com