Message ID | 20240301193831.3346-2-linux.amoon@gmail.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel+bounces-89034-ouuuleilei=gmail.com@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:fa17:b0:10a:f01:a869 with SMTP id ju23csp113507dyc; Fri, 1 Mar 2024 11:39:30 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVFvgvXv+33RurNrtUGKTonZ6kirUfWSJn/WhR9CgA9yHCJr3UReEQtpLX2D+QkmvTS4h1OL4Qt4Kdpf3eQRjGRoJlqhg== X-Google-Smtp-Source: AGHT+IEm/Vle9ALZB+QIt9zWZqxxc6++YpfhlkgV01VEltzw0ljLbTiId57OWADABddB36CT5gS+ X-Received: by 2002:ac8:5a09:0:b0:42e:c28e:ccbb with SMTP id n9-20020ac85a09000000b0042ec28eccbbmr2789163qta.46.1709321970017; Fri, 01 Mar 2024 11:39:30 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709321970; cv=pass; d=google.com; s=arc-20160816; b=FFbAlmcJD7gxu+PevTsTlXfK5s0LNG0dignpuwP8vLjfXaQUgklCsVItTB64SM5gmv sPfcHr9NlANtqT6aT1FeYBWOcqx+c40gCe2M97JztbGTEG6fg0YjTJc6u2gC+AISV09X Quzi2Y3CggZcrBvfVerhnyTxX9Rw4SSf+6jo7/oCAcdNunUn60NjVWaCDFE2pHRIxBUT 3fFWIF4QvPf4vcpUGLohoglxK+WIjQRjM5S1/e1FlNYNG5j8ptVgQ4mF4blycJzRORqz cx7GxC2aRsvZo3SFltW/0T1/Bk+t3fKvZw0CO8FRbpfieGlbLnfXWIQZUoAR22NoS46a XI8g== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=+XmK1KXUIgEldgLQ9Dj7dEfcJRP25Vkl9HU6FEdalXs=; fh=LbsWGIg5S/AixojrMqM+iVQG/7ZkFRQvK3jxiQlD3QQ=; b=Uo3mresiHdfOvYsCDQEaUOb8zQiCBfYw19r2T2WRUWYDN83Ll0cnqmKCnoKbazvW81 g1Wr3VZVkmLmaCJxu3Pv5185Ay3qfKqKOysVEkZU3N9yN7zV/rcnKwktq+HoAxMcA3Sl GN4SejAMcg0NDQSV1vt88YZ0U2NI5PM1lPSsSvyAFGdEazi4St9nl+1X4x0REHz1J9Rq Tc3GO1qgYhm+7xfR892hGYX40goWs7fE8RVVj61gfBTZgzN+OgxP6GUbVHq9BW1tcuaI swHSWbIAHnHhONiMPUSfCIVxYCGaTPVL5gMlPHcZzr9g6jc0pi/yDWKOo1o+Mp1ch7B/ rInA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=T7CNgKJF; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-89034-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-89034-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id h3-20020ac87d43000000b0042ec79f4afbsi260746qtb.404.2024.03.01.11.39.29 for <ouuuleilei@gmail.com> (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Mar 2024 11:39:30 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-89034-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=T7CNgKJF; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-89034-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-89034-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.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 ny.mirrors.kernel.org (Postfix) with ESMTPS id BBA0D1C232C2 for <ouuuleilei@gmail.com>; Fri, 1 Mar 2024 19:39:29 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D12243BB3E; Fri, 1 Mar 2024 19:39:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="T7CNgKJF" Received: from mail-pg1-f182.google.com (mail-pg1-f182.google.com [209.85.215.182]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 73FDA5C9A; Fri, 1 Mar 2024 19:39:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709321950; cv=none; b=ET9cywhHf69uYIstrHlvPT26iJew/3AjLz4u4r6HAt2bI0vFRR/qUMgAbpnHqffPUnWSxtXvFmWe4jw7FSLx62AuMhk476MSEg7Pa9LZbtHT3iCV0EjMPOS7ngt7jL/kco611Mi8nx8vwM9+0Td2BNpFwQ0aR2wA7bxiMScm2NY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709321950; c=relaxed/simple; bh=qzEiaIwCgvzo/jlLWGnfGMZS52j/5NljTf80U9c7pCY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=E52k/cfCoBnrmsVtVtIlI9+hZ/D/5c7lcydW1suk7TjFOY4hUCoXh3NKzkjFWOieNABEKYr4xvpEAuRZHevXOkO6Fjta862xwXz77z8JlxHyw7OxwMk6A4WVN+r7t6jeEqCgT35IP7wHn+Xc0QQnKd1mm1UkyQPj0Jk31b6jZjo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=T7CNgKJF; arc=none smtp.client-ip=209.85.215.182 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pg1-f182.google.com with SMTP id 41be03b00d2f7-5e152c757a5so1759878a12.2; Fri, 01 Mar 2024 11:39:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1709321949; x=1709926749; darn=vger.kernel.org; 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=+XmK1KXUIgEldgLQ9Dj7dEfcJRP25Vkl9HU6FEdalXs=; b=T7CNgKJF2ndd3WxavdWd7ssw71sUi6Epaif2SUi5oCPNTOetOran91fWM8AxZK8lO4 rbHtdNJN2PrU66X71FSjvYtz+lReLt0TUU42SeW2X9dbBhDeGMtGj95P0EZuu6sBTczW ThEkw7rUHfkROQBjTxDEcpA45+S3PjDg1PSN04N7SkriuwGYevMaTWcitzN6Kz6+SWdo xqk6XSkU7cO9K9EKnqxszHB9V/yYOIH/l5AaD68Zs8oVZrbZB4QoUTGFMXd4ZALw3avI GnKZiFNtNGlwO9yZSu08VKWudThqmP1SuKlB+qT6DDscXjsD3IEq0lKK1QXKoHvW84Wk +Ztg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709321949; x=1709926749; 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=+XmK1KXUIgEldgLQ9Dj7dEfcJRP25Vkl9HU6FEdalXs=; b=vEJyUfIPQcL8L5ClHUBjgfYsQJXMnFVbQag1x59FO8R2i5SOd1zQAjowG2yDkwkXwW GGrPLMqDP/NvMgDOUU1s/Xem2ZnS/T5xZvwFirDRPdiaEPHyylkfLGxbwrf7H/3raVfm CenJxI2WA3/fITHaRJP+qOqSSRYtZMb+OFV3odFbEGkR01u/2Nan/PMCRrhyuz2IInJV bWeZu1oP5ITNKeTRjOoMOAXa4DG0kv809g5ucJ7F13a0u+/mn/AkiOiBET23yoDsjFQT 1LoWL1l9gmj57PfQ7QiBkgbXWOt5u8ubEa1LKPS++iqTYp+5eEn4RA5LdVDGj8YykTE3 VASQ== X-Forwarded-Encrypted: i=1; AJvYcCXqHHTGvPXCqV90pIk5nB5GUk2YA0IjAmN70dE62RcESiFvhhJyQCLah7TRulevD24GchW9srVPEC2ylg/uuW/ElM5752I0nPFiJYRAz+Ci/mo/HSoLw4EmzKJucEXJT+5/xKreB4QHIEYTJQd6UdZOGDET9+BPr0mk1nQ6qVEKGBQpK85k0vsD5kc= X-Gm-Message-State: AOJu0YzVC/cU3oCS0wJfBav/wz9w2pDdz2NIrc9kVAafaqyZR75TiiS1 9yaL+IZYf6GRoJF4cyiYZGYnSqDLg6yecFd+/c5OMRbjy/NoZGn6 X-Received: by 2002:a17:902:fe82:b0:1db:8fd9:ba0d with SMTP id x2-20020a170902fe8200b001db8fd9ba0dmr2177685plm.23.1709321948602; Fri, 01 Mar 2024 11:39:08 -0800 (PST) Received: from localhost.localdomain ([113.30.217.222]) by smtp.gmail.com with ESMTPSA id u8-20020a170902e5c800b001dca6d1d572sm3837474plf.63.2024.03.01.11.39.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Mar 2024 11:39:08 -0800 (PST) From: Anand Moon <linux.amoon@gmail.com> To: Alan Stern <stern@rowland.harvard.edu>, Greg Kroah-Hartman <gregkh@linuxfoundation.org>, Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>, Alim Akhtar <alim.akhtar@samsung.com> Cc: Anand Moon <linux.amoon@gmail.com>, linux-usb@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-samsung-soc@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v1 1/4] usb: ehci-exynos: Use devm_clk_get_enabled() helpers Date: Sat, 2 Mar 2024 01:08:08 +0530 Message-ID: <20240301193831.3346-2-linux.amoon@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240301193831.3346-1-linux.amoon@gmail.com> References: <20240301193831.3346-1-linux.amoon@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: <linux-kernel.vger.kernel.org> List-Subscribe: <mailto:linux-kernel+subscribe@vger.kernel.org> List-Unsubscribe: <mailto:linux-kernel+unsubscribe@vger.kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1792353994060299124 X-GMAIL-MSGID: 1792353994060299124 |
Series |
[v1,1/4] usb: ehci-exynos: Use devm_clk_get_enabled() helpers
|
|
Commit Message
Anand Moon
March 1, 2024, 7:38 p.m. UTC
The devm_clk_get_enabled() helpers:
- call devm_clk_get()
- call clk_prepare_enable() and register what is needed in order to
call clk_disable_unprepare() when needed, as a managed resource.
This simplifies the code and avoids the calls to clk_disable_unprepare().
While at it, use dev_err_probe consistently, and use its return value
to return the error code.
Signed-off-by: Anand Moon <linux.amoon@gmail.com>
---
drivers/usb/host/ehci-exynos.c | 30 +++++-------------------------
1 file changed, 5 insertions(+), 25 deletions(-)
Comments
On Sat, Mar 02, 2024 at 01:08:08AM +0530, Anand Moon wrote: > The devm_clk_get_enabled() helpers: > - call devm_clk_get() > - call clk_prepare_enable() and register what is needed in order to > call clk_disable_unprepare() when needed, as a managed resource. > > This simplifies the code and avoids the calls to clk_disable_unprepare(). > > While at it, use dev_err_probe consistently, and use its return value > to return the error code. > > Signed-off-by: Anand Moon <linux.amoon@gmail.com> > --- > drivers/usb/host/ehci-exynos.c | 30 +++++------------------------- > 1 file changed, 5 insertions(+), 25 deletions(-) > > diff --git a/drivers/usb/host/ehci-exynos.c b/drivers/usb/host/ehci-exynos.c > index f644b131cc0b..05aa3d9c2a3b 100644 > --- a/drivers/usb/host/ehci-exynos.c > +++ b/drivers/usb/host/ehci-exynos.c > @@ -159,19 +159,12 @@ static int exynos_ehci_probe(struct platform_device *pdev) > > err = exynos_ehci_get_phy(&pdev->dev, exynos_ehci); > if (err) > - goto fail_clk; > - > - exynos_ehci->clk = devm_clk_get(&pdev->dev, "usbhost"); > - > - if (IS_ERR(exynos_ehci->clk)) { > - dev_err(&pdev->dev, "Failed to get usbhost clock\n"); > - err = PTR_ERR(exynos_ehci->clk); > - goto fail_clk; > - } > + goto fail_io; > > - err = clk_prepare_enable(exynos_ehci->clk); > - if (err) > - goto fail_clk; > + exynos_ehci->clk = devm_clk_get_enabled(&pdev->dev, "usbhost"); > + if (IS_ERR(exynos_ehci->clk)) > + return dev_err_probe(&pdev->dev, PTR_ERR(exynos_ehci->clk), > + "Failed to get usbhost clock\n"); What about the usb_put_hcd(hcd) call that used to happen here? Alan Stern > > hcd->regs = devm_platform_get_and_ioremap_resource(pdev, 0, &res); > if (IS_ERR(hcd->regs)) { > @@ -223,8 +216,6 @@ static int exynos_ehci_probe(struct platform_device *pdev) > exynos_ehci_phy_disable(&pdev->dev); > pdev->dev.of_node = exynos_ehci->of_node; > fail_io: > - clk_disable_unprepare(exynos_ehci->clk); > -fail_clk: > usb_put_hcd(hcd); > return err; > } > @@ -240,8 +231,6 @@ static void exynos_ehci_remove(struct platform_device *pdev) > > exynos_ehci_phy_disable(&pdev->dev); > > - clk_disable_unprepare(exynos_ehci->clk); > - > usb_put_hcd(hcd); > } > > @@ -249,7 +238,6 @@ static void exynos_ehci_remove(struct platform_device *pdev) > static int exynos_ehci_suspend(struct device *dev) > { > struct usb_hcd *hcd = dev_get_drvdata(dev); > - struct exynos_ehci_hcd *exynos_ehci = to_exynos_ehci(hcd); > > bool do_wakeup = device_may_wakeup(dev); > int rc; > @@ -260,25 +248,17 @@ static int exynos_ehci_suspend(struct device *dev) > > exynos_ehci_phy_disable(dev); > > - clk_disable_unprepare(exynos_ehci->clk); > - > return rc; > } > > static int exynos_ehci_resume(struct device *dev) > { > struct usb_hcd *hcd = dev_get_drvdata(dev); > - struct exynos_ehci_hcd *exynos_ehci = to_exynos_ehci(hcd); > int ret; > > - ret = clk_prepare_enable(exynos_ehci->clk); > - if (ret) > - return ret; > - > ret = exynos_ehci_phy_enable(dev); > if (ret) { > dev_err(dev, "Failed to enable USB phy\n"); > - clk_disable_unprepare(exynos_ehci->clk); > return ret; > } > > -- > 2.43.0 >
Hi Alan On Sat, 2 Mar 2024 at 01:49, Alan Stern <stern@rowland.harvard.edu> wrote: > > On Sat, Mar 02, 2024 at 01:08:08AM +0530, Anand Moon wrote: > > The devm_clk_get_enabled() helpers: > > - call devm_clk_get() > > - call clk_prepare_enable() and register what is needed in order to > > call clk_disable_unprepare() when needed, as a managed resource. > > > > This simplifies the code and avoids the calls to clk_disable_unprepare(). > > > > While at it, use dev_err_probe consistently, and use its return value > > to return the error code. > > > > Signed-off-by: Anand Moon <linux.amoon@gmail.com> > > --- > > drivers/usb/host/ehci-exynos.c | 30 +++++------------------------- > > 1 file changed, 5 insertions(+), 25 deletions(-) > > > > diff --git a/drivers/usb/host/ehci-exynos.c b/drivers/usb/host/ehci-exynos.c > > index f644b131cc0b..05aa3d9c2a3b 100644 > > --- a/drivers/usb/host/ehci-exynos.c > > +++ b/drivers/usb/host/ehci-exynos.c > > @@ -159,19 +159,12 @@ static int exynos_ehci_probe(struct platform_device *pdev) > > > > err = exynos_ehci_get_phy(&pdev->dev, exynos_ehci); > > if (err) > > - goto fail_clk; > > - > > - exynos_ehci->clk = devm_clk_get(&pdev->dev, "usbhost"); > > - > > - if (IS_ERR(exynos_ehci->clk)) { > > - dev_err(&pdev->dev, "Failed to get usbhost clock\n"); > > - err = PTR_ERR(exynos_ehci->clk); > > - goto fail_clk; > > - } > > + goto fail_io; > > > > - err = clk_prepare_enable(exynos_ehci->clk); > > - if (err) > > - goto fail_clk; > > + exynos_ehci->clk = devm_clk_get_enabled(&pdev->dev, "usbhost"); > > + if (IS_ERR(exynos_ehci->clk)) > > + return dev_err_probe(&pdev->dev, PTR_ERR(exynos_ehci->clk), > > + "Failed to get usbhost clock\n"); > > What about the usb_put_hcd(hcd) call that used to happen here? > Ok, I will update this in the next version. > Alan Stern Thanks -Anand
Le 01/03/2024 à 20:38, Anand Moon a écrit : > The devm_clk_get_enabled() helpers: > - call devm_clk_get() > - call clk_prepare_enable() and register what is needed in order to > call clk_disable_unprepare() when needed, as a managed resource. > > This simplifies the code and avoids the calls to clk_disable_unprepare(). > > While at it, use dev_err_probe consistently, and use its return value > to return the error code. > > Signed-off-by: Anand Moon <linux.amoon@gmail.com> > --- > drivers/usb/host/ehci-exynos.c | 30 +++++------------------------- > 1 file changed, 5 insertions(+), 25 deletions(-) > > diff --git a/drivers/usb/host/ehci-exynos.c b/drivers/usb/host/ehci-exynos.c > index f644b131cc0b..05aa3d9c2a3b 100644 > --- a/drivers/usb/host/ehci-exynos.c > +++ b/drivers/usb/host/ehci-exynos.c > @@ -159,19 +159,12 @@ static int exynos_ehci_probe(struct platform_device *pdev) > > err = exynos_ehci_get_phy(&pdev->dev, exynos_ehci); > if (err) > - goto fail_clk; > - > - exynos_ehci->clk = devm_clk_get(&pdev->dev, "usbhost"); > - > - if (IS_ERR(exynos_ehci->clk)) { > - dev_err(&pdev->dev, "Failed to get usbhost clock\n"); > - err = PTR_ERR(exynos_ehci->clk); > - goto fail_clk; > - } > + goto fail_io; > > - err = clk_prepare_enable(exynos_ehci->clk); > - if (err) > - goto fail_clk; > + exynos_ehci->clk = devm_clk_get_enabled(&pdev->dev, "usbhost"); > + if (IS_ERR(exynos_ehci->clk)) > + return dev_err_probe(&pdev->dev, PTR_ERR(exynos_ehci->clk), > + "Failed to get usbhost clock\n"); > > hcd->regs = devm_platform_get_and_ioremap_resource(pdev, 0, &res); > if (IS_ERR(hcd->regs)) { > @@ -223,8 +216,6 @@ static int exynos_ehci_probe(struct platform_device *pdev) > exynos_ehci_phy_disable(&pdev->dev); > pdev->dev.of_node = exynos_ehci->of_node; > fail_io: > - clk_disable_unprepare(exynos_ehci->clk); > -fail_clk: > usb_put_hcd(hcd); > return err; > } > @@ -240,8 +231,6 @@ static void exynos_ehci_remove(struct platform_device *pdev) > > exynos_ehci_phy_disable(&pdev->dev); > > - clk_disable_unprepare(exynos_ehci->clk); > - > usb_put_hcd(hcd); > } > > @@ -249,7 +238,6 @@ static void exynos_ehci_remove(struct platform_device *pdev) > static int exynos_ehci_suspend(struct device *dev) > { > struct usb_hcd *hcd = dev_get_drvdata(dev); > - struct exynos_ehci_hcd *exynos_ehci = to_exynos_ehci(hcd); > > bool do_wakeup = device_may_wakeup(dev); > int rc; > @@ -260,25 +248,17 @@ static int exynos_ehci_suspend(struct device *dev) > > exynos_ehci_phy_disable(dev); > > - clk_disable_unprepare(exynos_ehci->clk); Hi, I don't think that removing clk_[en|dis]abble from the suspend and resume function is correct. The goal is to stop some hardware when the system is suspended, in order to save some power. Why did you removed it? CJ > - > return rc; > } > > static int exynos_ehci_resume(struct device *dev) > { > struct usb_hcd *hcd = dev_get_drvdata(dev); > - struct exynos_ehci_hcd *exynos_ehci = to_exynos_ehci(hcd); > int ret; > > - ret = clk_prepare_enable(exynos_ehci->clk); > - if (ret) > - return ret; > - > ret = exynos_ehci_phy_enable(dev); > if (ret) { > dev_err(dev, "Failed to enable USB phy\n"); > - clk_disable_unprepare(exynos_ehci->clk); > return ret; > } >
Hi Christophe, On Sat, 2 Mar 2024 at 21:19, Christophe JAILLET <christophe.jaillet@wanadoo.fr> wrote: > > Le 01/03/2024 à 20:38, Anand Moon a écrit : > > The devm_clk_get_enabled() helpers: > > - call devm_clk_get() > > - call clk_prepare_enable() and register what is needed in order to > > call clk_disable_unprepare() when needed, as a managed resource. > > > > This simplifies the code and avoids the calls to clk_disable_unprepare(). > > > > While at it, use dev_err_probe consistently, and use its return value > > to return the error code. > > > > Signed-off-by: Anand Moon <linux.amoon@gmail.com> > > --- > > drivers/usb/host/ehci-exynos.c | 30 +++++------------------------- > > 1 file changed, 5 insertions(+), 25 deletions(-) > > > > diff --git a/drivers/usb/host/ehci-exynos.c b/drivers/usb/host/ehci-exynos.c > > index f644b131cc0b..05aa3d9c2a3b 100644 > > --- a/drivers/usb/host/ehci-exynos.c > > +++ b/drivers/usb/host/ehci-exynos.c > > @@ -159,19 +159,12 @@ static int exynos_ehci_probe(struct platform_device *pdev) > > > > err = exynos_ehci_get_phy(&pdev->dev, exynos_ehci); > > if (err) > > - goto fail_clk; > > - > > - exynos_ehci->clk = devm_clk_get(&pdev->dev, "usbhost"); > > - > > - if (IS_ERR(exynos_ehci->clk)) { > > - dev_err(&pdev->dev, "Failed to get usbhost clock\n"); > > - err = PTR_ERR(exynos_ehci->clk); > > - goto fail_clk; > > - } > > + goto fail_io; > > > > - err = clk_prepare_enable(exynos_ehci->clk); > > - if (err) > > - goto fail_clk; > > + exynos_ehci->clk = devm_clk_get_enabled(&pdev->dev, "usbhost"); > > + if (IS_ERR(exynos_ehci->clk)) > > + return dev_err_probe(&pdev->dev, PTR_ERR(exynos_ehci->clk), > > + "Failed to get usbhost clock\n"); > > > > hcd->regs = devm_platform_get_and_ioremap_resource(pdev, 0, &res); > > if (IS_ERR(hcd->regs)) { > > @@ -223,8 +216,6 @@ static int exynos_ehci_probe(struct platform_device *pdev) > > exynos_ehci_phy_disable(&pdev->dev); > > pdev->dev.of_node = exynos_ehci->of_node; > > fail_io: > > - clk_disable_unprepare(exynos_ehci->clk); > > -fail_clk: > > usb_put_hcd(hcd); > > return err; > > } > > @@ -240,8 +231,6 @@ static void exynos_ehci_remove(struct platform_device *pdev) > > > > exynos_ehci_phy_disable(&pdev->dev); > > > > - clk_disable_unprepare(exynos_ehci->clk); > > - > > usb_put_hcd(hcd); > > } > > > > @@ -249,7 +238,6 @@ static void exynos_ehci_remove(struct platform_device *pdev) > > static int exynos_ehci_suspend(struct device *dev) > > { > > struct usb_hcd *hcd = dev_get_drvdata(dev); > > - struct exynos_ehci_hcd *exynos_ehci = to_exynos_ehci(hcd); > > > > bool do_wakeup = device_may_wakeup(dev); > > int rc; > > @@ -260,25 +248,17 @@ static int exynos_ehci_suspend(struct device *dev) > > > > exynos_ehci_phy_disable(dev); > > > > - clk_disable_unprepare(exynos_ehci->clk); > > Hi, > > I don't think that removing clk_[en|dis]abble from the suspend and > resume function is correct. > > The goal is to stop some hardware when the system is suspended, in order > to save some power. Yes correct, > > Why did you removed it? > devm_clk_get_enabled function register callback for clk_prepare_enable and clk_disable_unprepare, so when the clock resource is not used it should get disabled. [0] https://elixir.bootlin.com/linux/latest/source/drivers/clk/clk-devres.c#L75 I have also tested with rtc suspend & resume and did not find any issue. > CJ Thanks -Anand > > > - > > return rc; > > } > > > > static int exynos_ehci_resume(struct device *dev) > > { > > struct usb_hcd *hcd = dev_get_drvdata(dev); > > - struct exynos_ehci_hcd *exynos_ehci = to_exynos_ehci(hcd); > > int ret; > > > > - ret = clk_prepare_enable(exynos_ehci->clk); > > - if (ret) > > - return ret; > > - > > ret = exynos_ehci_phy_enable(dev); > > if (ret) { > > dev_err(dev, "Failed to enable USB phy\n"); > > - clk_disable_unprepare(exynos_ehci->clk); > > return ret; > > } > > >
Le 02/03/2024 à 17:35, Anand Moon a écrit : > Hi Christophe, > > On Sat, 2 Mar 2024 at 21:19, Christophe JAILLET > <christophe.jaillet@wanadoo.fr> wrote: >> >> Le 01/03/2024 à 20:38, Anand Moon a écrit : >>> The devm_clk_get_enabled() helpers: >>> - call devm_clk_get() >>> - call clk_prepare_enable() and register what is needed in order to >>> call clk_disable_unprepare() when needed, as a managed resource. >>> >>> This simplifies the code and avoids the calls to clk_disable_unprepare(). >>> >>> While at it, use dev_err_probe consistently, and use its return value >>> to return the error code. >>> >>> Signed-off-by: Anand Moon <linux.amoon@gmail.com> >>> --- >>> drivers/usb/host/ehci-exynos.c | 30 +++++------------------------- >>> 1 file changed, 5 insertions(+), 25 deletions(-) >>> >>> diff --git a/drivers/usb/host/ehci-exynos.c b/drivers/usb/host/ehci-exynos.c >>> index f644b131cc0b..05aa3d9c2a3b 100644 >>> --- a/drivers/usb/host/ehci-exynos.c >>> +++ b/drivers/usb/host/ehci-exynos.c >>> @@ -159,19 +159,12 @@ static int exynos_ehci_probe(struct platform_device *pdev) >>> >>> err = exynos_ehci_get_phy(&pdev->dev, exynos_ehci); >>> if (err) >>> - goto fail_clk; >>> - >>> - exynos_ehci->clk = devm_clk_get(&pdev->dev, "usbhost"); >>> - >>> - if (IS_ERR(exynos_ehci->clk)) { >>> - dev_err(&pdev->dev, "Failed to get usbhost clock\n"); >>> - err = PTR_ERR(exynos_ehci->clk); >>> - goto fail_clk; >>> - } >>> + goto fail_io; >>> >>> - err = clk_prepare_enable(exynos_ehci->clk); >>> - if (err) >>> - goto fail_clk; >>> + exynos_ehci->clk = devm_clk_get_enabled(&pdev->dev, "usbhost"); >>> + if (IS_ERR(exynos_ehci->clk)) >>> + return dev_err_probe(&pdev->dev, PTR_ERR(exynos_ehci->clk), >>> + "Failed to get usbhost clock\n"); >>> >>> hcd->regs = devm_platform_get_and_ioremap_resource(pdev, 0, &res); >>> if (IS_ERR(hcd->regs)) { >>> @@ -223,8 +216,6 @@ static int exynos_ehci_probe(struct platform_device *pdev) >>> exynos_ehci_phy_disable(&pdev->dev); >>> pdev->dev.of_node = exynos_ehci->of_node; >>> fail_io: >>> - clk_disable_unprepare(exynos_ehci->clk); >>> -fail_clk: >>> usb_put_hcd(hcd); >>> return err; >>> } >>> @@ -240,8 +231,6 @@ static void exynos_ehci_remove(struct platform_device *pdev) >>> >>> exynos_ehci_phy_disable(&pdev->dev); >>> >>> - clk_disable_unprepare(exynos_ehci->clk); >>> - >>> usb_put_hcd(hcd); >>> } >>> >>> @@ -249,7 +238,6 @@ static void exynos_ehci_remove(struct platform_device *pdev) >>> static int exynos_ehci_suspend(struct device *dev) >>> { >>> struct usb_hcd *hcd = dev_get_drvdata(dev); >>> - struct exynos_ehci_hcd *exynos_ehci = to_exynos_ehci(hcd); >>> >>> bool do_wakeup = device_may_wakeup(dev); >>> int rc; >>> @@ -260,25 +248,17 @@ static int exynos_ehci_suspend(struct device *dev) >>> >>> exynos_ehci_phy_disable(dev); >>> >>> - clk_disable_unprepare(exynos_ehci->clk); >> >> Hi, >> >> I don't think that removing clk_[en|dis]abble from the suspend and >> resume function is correct. >> >> The goal is to stop some hardware when the system is suspended, in order >> to save some power. > Yes correct, >> >> Why did you removed it? >> > > devm_clk_get_enabled function register callback for clk_prepare_enable > and clk_disable_unprepare, so when the clock resource is not used it should get > disabled. Same explanation as in the other patch. The registered function is called when the driver is *unloaded*, not when it magically knows that some things can be disabled or enabled. CJ > > [0] https://elixir.bootlin.com/linux/latest/source/drivers/clk/clk-devres.c#L75 > > I have also tested with rtc suspend & resume and did not find any issue. > >> CJ > > Thanks > -Anand >> >>> - >>> return rc; >>> } >>> >>> static int exynos_ehci_resume(struct device *dev) >>> { >>> struct usb_hcd *hcd = dev_get_drvdata(dev); >>> - struct exynos_ehci_hcd *exynos_ehci = to_exynos_ehci(hcd); >>> int ret; >>> >>> - ret = clk_prepare_enable(exynos_ehci->clk); >>> - if (ret) >>> - return ret; >>> - >>> ret = exynos_ehci_phy_enable(dev); >>> if (ret) { >>> dev_err(dev, "Failed to enable USB phy\n"); >>> - clk_disable_unprepare(exynos_ehci->clk); >>> return ret; >>> } >>> >> > >
On Sat, Mar 02, 2024 at 10:05:46PM +0530, Anand Moon wrote: > On Sat, 2 Mar 2024 at 21:19, Christophe JAILLET > <christophe.jaillet@wanadoo.fr> wrote: > > Le 01/03/2024 à 20:38, Anand Moon a écrit : > > > The devm_clk_get_enabled() helpers: > > > - call devm_clk_get() > > > - call clk_prepare_enable() and register what is needed in order to > > > call clk_disable_unprepare() when needed, as a managed resource. > > > > > > This simplifies the code and avoids the calls to clk_disable_unprepare(). > > > > > > While at it, use dev_err_probe consistently, and use its return value > > > to return the error code. > > > @@ -260,25 +248,17 @@ static int exynos_ehci_suspend(struct device *dev) > > > > > > exynos_ehci_phy_disable(dev); > > > > > > - clk_disable_unprepare(exynos_ehci->clk); > > I don't think that removing clk_[en|dis]abble from the suspend and > > resume function is correct. > > > > The goal is to stop some hardware when the system is suspended, in order > > to save some power. > Yes correct, > > > > Why did you removed it? > devm_clk_get_enabled function register callback for clk_prepare_enable > and clk_disable_unprepare, so when the clock resource is not used it should get > disabled. > > [0] https://elixir.bootlin.com/linux/latest/source/drivers/clk/clk-devres.c#L75 > > I have also tested with rtc suspend & resume and did not find any issue. You seem to be totally confused about how devres works, and arguing back after Christophe points this out to you instead of going back and doing the homework you should have done before posting these patches is really not OK (e.g. as you're wasting other people's time). And you clearly did not test these patches enough to confirm that you didn't break the driver. Johan
Hi Johon, Christophe, On Mon, 4 Mar 2024 at 14:48, Johan Hovold <johan@kernel.org> wrote: > > On Sat, Mar 02, 2024 at 10:05:46PM +0530, Anand Moon wrote: > > On Sat, 2 Mar 2024 at 21:19, Christophe JAILLET > > <christophe.jaillet@wanadoo.fr> wrote: > > > Le 01/03/2024 à 20:38, Anand Moon a écrit : > > > > > The devm_clk_get_enabled() helpers: > > > > - call devm_clk_get() > > > > - call clk_prepare_enable() and register what is needed in order to > > > > call clk_disable_unprepare() when needed, as a managed resource. > > > > > > > > This simplifies the code and avoids the calls to clk_disable_unprepare(). > > > > > > > > While at it, use dev_err_probe consistently, and use its return value > > > > to return the error code. > > > > > @@ -260,25 +248,17 @@ static int exynos_ehci_suspend(struct device *dev) > > > > > > > > exynos_ehci_phy_disable(dev); > > > > > > > > - clk_disable_unprepare(exynos_ehci->clk); > > > > I don't think that removing clk_[en|dis]abble from the suspend and > > > resume function is correct. > > > > > > The goal is to stop some hardware when the system is suspended, in order > > > to save some power. > > Yes correct, > > > > > > Why did you removed it? > > > devm_clk_get_enabled function register callback for clk_prepare_enable > > and clk_disable_unprepare, so when the clock resource is not used it should get > > disabled. > > > > [0] https://elixir.bootlin.com/linux/latest/source/drivers/clk/clk-devres.c#L75 > > > > I have also tested with rtc suspend & resume and did not find any issue. > > You seem to be totally confused about how devres works, and arguing back > after Christophe points this out to you instead of going back and doing > the homework you should have done before posting these patches is really > not OK (e.g. as you're wasting other people's time). > Ok, It seems to have fallen short in my understanding.. > And you clearly did not test these patches enough to confirm that you > didn't break the driver. Ok I missed the failure of the ehci driver. while testing. [root@archl-xu4 alarm]# echo no > /sys/module/printk/parameters/console_suspend [root@archl-xu4 alarm]# echo no > /sys/module/printk/parameters/console_suspend [root@archl-xu4 alarm]# echo no > /sys/module/printk/parameters/console_suspend [root@archl-xu4 alarm]# time rtcwake -s 30 -m mem rtcwake: assuming RTC uses UTC ... rtcwake: wakeup from "mem" using /dev/rtc0 at Mon Mar 4 09:44:25 2024 [11969.792928] PM: suspend entry (deep) [11969.798423] Filesystems sync: 0.003 seconds [11969.819722] Freezing user space processes [11969.825818] Freezing user space processes completed (elapsed 0.003 seconds) [11969.831585] OOM killer disabled. [11969.834586] Freezing remaining freezable tasks [11969.841553] Freezing remaining freezable tasks completed (elapsed 0.002 seconds) [11969.919178] sd 0:0:0:0: [sda] Synchronizing SCSI cache [11970.091681] wake enabled for irq 129 (gpx0-4) [11970.135766] wake enabled for irq 149 (gpx0-3) [11970.157943] samsung-pinctrl 13400000.pinctrl: Setting external wakeup interrupt mask: 0xffffffe7 [11970.179304] Disabling non-boot CPUs ... [11970.276394] s3c2410-wdt 101d0000.watchdog: watchdog disabled [11970.281961] wake disabled for irq 149 (gpx0-3) [11970.288997] phy phy-12130000.phy.6: phy_power_on was called before phy_init [11970.358899] exynos-ohci 12120000.usb: init err (00000000 0000) [11970.363298] exynos-ohci 12120000.usb: can't restart, -75 [11970.368581] usb usb2: root hub lost power or was reset [11970.373819] wake disabled for irq 129 (gpx0-4) [11970.382641] xhci-hcd xhci-hcd.8.auto: xHC error in resume, USBSTS 0x411, Reinit [11970.383237] s3c-rtc 101e0000.rtc: rtc disabled, re-enabling [11970.383355] xhci-hcd xhci-hcd.9.auto: xHC error in resume, USBSTS 0x401, Reinit [11970.383376] usb usb5: root hub lost power or was reset [11970.383396] usb usb6: root hub lost power or was reset [11970.388471] usb usb3: root hub lost power or was reset [11970.416740] usb usb4: root hub lost power or was reset [11970.770122] usb 3-1: reset high-speed USB device number 2 using xhci-hcd [11971.100601] usb 4-1: reset SuperSpeed USB device number 3 using xhci-hcd [11971.569524] usb 3-1.2: reset high-speed USB device number 3 using xhci-hcd [11974.575262] OOM killer enabled. [11974.576964] Restarting tasks ... done. [11974.580608] r8152-cfgselector 6-1: USB disconnect, device number 4 [11974.589302] random: crng reseeded on system resumption [11974.596363] PM: suspend exit real 0m34.951s user 0m0.012s sys 0m0.259s [root@archl-xu4 alarm]# [11974.640778] mmc_host mmc0: Bus speed (slot 0) = 50000000Hz (slot req 400000Hz, actual 396825HZ div = 63) [11975.180552] mmc_host mmc0: Bus speed (slot 0) = 50000000Hz (slot req 52000000Hz, actual 50000000HZ div = 0) [11975.192142] mmc_host mmc0: Bus speed (slot 0) = 200000000Hz (slot req 200000000Hz, actual 200000000HZ div = 0) [11975.282474] mmc_host mmc0: Bus speed (slot 0) = 50000000Hz (slot req 52000000Hz, actual 50000000HZ div = 0) [11975.296174] mmc_host mmc0: Bus speed (slot 0) = 400000000Hz (slot req 200000000Hz, actual 200000000HZ div = 1) [11975.569457] usb 6-1: new SuperSpeed USB device number 5 using xhci-hcd [11975.614390] usb 6-1: New USB device found, idVendor=0bda, idProduct=8153, bcdDevice=30.00 [11975.622196] usb 6-1: New USB device strings: Mfr=1, Product=2, SerialNumber=6 [11975.629284] usb 6-1: Product: USB 10/100/1000 LAN [11975.633352] usb 6-1: Manufacturer: Realtek [11975.637458] usb 6-1: SerialNumber: 000001000000 [11975.871080] r8152-cfgselector 6-1: reset SuperSpeed USB device number 5 using xhci-hcd [11975.955112] r8152 6-1:1.0: load rtl8153a-3 v2 02/07/20 successfully [11976.032484] r8152 6-1:1.0 eth0: v1.12.13 [11976.134078] r8152 6-1:1.0 enu1: renamed from eth0 [root@archl-xu4 alarm]# [11981.522603] r8152 6-1:1.0 enu1: carrier on [root@archl-xu4 alarm]# > Ok, I will restore the clk changes in the suspend / resume functions in the next version and do thought testing. > Johan Thanks -Anand
diff --git a/drivers/usb/host/ehci-exynos.c b/drivers/usb/host/ehci-exynos.c index f644b131cc0b..05aa3d9c2a3b 100644 --- a/drivers/usb/host/ehci-exynos.c +++ b/drivers/usb/host/ehci-exynos.c @@ -159,19 +159,12 @@ static int exynos_ehci_probe(struct platform_device *pdev) err = exynos_ehci_get_phy(&pdev->dev, exynos_ehci); if (err) - goto fail_clk; - - exynos_ehci->clk = devm_clk_get(&pdev->dev, "usbhost"); - - if (IS_ERR(exynos_ehci->clk)) { - dev_err(&pdev->dev, "Failed to get usbhost clock\n"); - err = PTR_ERR(exynos_ehci->clk); - goto fail_clk; - } + goto fail_io; - err = clk_prepare_enable(exynos_ehci->clk); - if (err) - goto fail_clk; + exynos_ehci->clk = devm_clk_get_enabled(&pdev->dev, "usbhost"); + if (IS_ERR(exynos_ehci->clk)) + return dev_err_probe(&pdev->dev, PTR_ERR(exynos_ehci->clk), + "Failed to get usbhost clock\n"); hcd->regs = devm_platform_get_and_ioremap_resource(pdev, 0, &res); if (IS_ERR(hcd->regs)) { @@ -223,8 +216,6 @@ static int exynos_ehci_probe(struct platform_device *pdev) exynos_ehci_phy_disable(&pdev->dev); pdev->dev.of_node = exynos_ehci->of_node; fail_io: - clk_disable_unprepare(exynos_ehci->clk); -fail_clk: usb_put_hcd(hcd); return err; } @@ -240,8 +231,6 @@ static void exynos_ehci_remove(struct platform_device *pdev) exynos_ehci_phy_disable(&pdev->dev); - clk_disable_unprepare(exynos_ehci->clk); - usb_put_hcd(hcd); } @@ -249,7 +238,6 @@ static void exynos_ehci_remove(struct platform_device *pdev) static int exynos_ehci_suspend(struct device *dev) { struct usb_hcd *hcd = dev_get_drvdata(dev); - struct exynos_ehci_hcd *exynos_ehci = to_exynos_ehci(hcd); bool do_wakeup = device_may_wakeup(dev); int rc; @@ -260,25 +248,17 @@ static int exynos_ehci_suspend(struct device *dev) exynos_ehci_phy_disable(dev); - clk_disable_unprepare(exynos_ehci->clk); - return rc; } static int exynos_ehci_resume(struct device *dev) { struct usb_hcd *hcd = dev_get_drvdata(dev); - struct exynos_ehci_hcd *exynos_ehci = to_exynos_ehci(hcd); int ret; - ret = clk_prepare_enable(exynos_ehci->clk); - if (ret) - return ret; - ret = exynos_ehci_phy_enable(dev); if (ret) { dev_err(dev, "Failed to enable USB phy\n"); - clk_disable_unprepare(exynos_ehci->clk); return ret; }