Received: by 2002:ac0:8845:0:0:0:0:0 with SMTP id g63csp1670939img; Wed, 27 Feb 2019 03:30:22 -0800 (PST) X-Google-Smtp-Source: AHgI3IY9xl9B1AqNlHPZfdVoifb9bzA0O9yt86SGfsgFVZOegAktg2E4IboG2PSbQIOiEAK//RHj X-Received: by 2002:a63:3d7:: with SMTP id 206mr2460065pgd.350.1551267021868; Wed, 27 Feb 2019 03:30:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1551267021; cv=none; d=google.com; s=arc-20160816; b=xhJMbEE1dkYETYIbcmyJKfswP9p1yhcTmseuXwNF3vPrLDHr3I7S4Tqs+Tki75YnVQ 92rM478FpV7W5/nrT3w15drS5pTBKg40csRVEckNXdctbWOchmsLDNBbWPJKW5xYFAHz xtn4VIBtwpkWLg3GlkjhIY0XcQ9KUrG6unORWBUfporLq8cHdXP8rklERbFle9Zdv8gO F55pH+90noaZJ0G6v0X1YbJPhRuo2WoD5ql1PKyyefu8yIkIlVkcvXlVB6GQ8LhWslO+ U7QW5V+5bdoSyKR1lCU5Y/9Vy0nDpbujAB6o/wkvMuRcyR4WqKDj5LitnT1rq99h07mF jILA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:mime-version:user-agent:date :message-id:subject:autocrypt:openpgp:from:references:cc:to; bh=BndwyDljHGFfA0N2SSNp9bT20EOaMaBAJh3eMX4WEs0=; b=jubsMDf7v8TPytnntqWDPhF+Zg8p2ntMlSydRu4uyMWdjRNlguDsQUeclN524X55EG gIktr7AXSqbF9yioFv6N41Jd8IDl6I3EOjriM6+qVtXAUyQ9GnJUWGlVe/BfIvnTAqQq ZNyNMUMjZU+C4hfAWdrGivOHDWuJOOeB8Z6Hq2y/DBnIU50OJIvJn0WwF39ENfR0EpuY m/ufLzYA0/9V+cpoLMtjEooCX0kQx5y5lNtLF0ZkbweReu+BNxmxJFiImrYD0+vsqe1G WnIELL6AentR+t/+bXc5ZO7bjUgkvcniKXLfwehFdjxGZ/ut31YPAjq1QXUdd0b36/T6 kw8g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y184si14408713pgd.118.2019.02.27.03.30.05; Wed, 27 Feb 2019 03:30:21 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729123AbfB0Kzh (ORCPT + 99 others); Wed, 27 Feb 2019 05:55:37 -0500 Received: from metis.ext.pengutronix.de ([85.220.165.71]:36175 "EHLO metis.ext.pengutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726911AbfB0Kzg (ORCPT ); Wed, 27 Feb 2019 05:55:36 -0500 Received: from gallifrey.ext.pengutronix.de ([2001:67c:670:201:5054:ff:fe8d:eefb] helo=bjornoya.blackshift.org) by metis.ext.pengutronix.de with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1gyws6-0008NT-RI; Wed, 27 Feb 2019 11:55:30 +0100 Received: from [IPv6:2a03:f580:87bc:d400:f8eb:aafc:4bc:24e5] (unknown [IPv6:2a03:f580:87bc:d400:f8eb:aafc:4bc:24e5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-384) server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mkl@blackshift.org", Issuer "StartCom Class 1 Client CA" (not verified)) (Authenticated sender: mkl@blackshift.org) by smtp.blackshift.org (Postfix) with ESMTPSA id CE17B3DC03F; Wed, 27 Feb 2019 10:35:19 +0000 (UTC) To: Joakim Zhang , "linux-can@vger.kernel.org" Cc: "wg@grandegger.com" , "netdev@vger.kernel.org" , "linux-kernel@vger.kernel.org" , dl-linux-imx , Aisheng DONG References: <20181130085119.7948-1-qiangqing.zhang@nxp.com> From: Marc Kleine-Budde Openpgp: preference=signencrypt Autocrypt: addr=mkl@pengutronix.de; prefer-encrypt=mutual; keydata= mQINBFFVq30BEACtnSvtXHoeHJxG6nRULcvlkW6RuNwHKmrqoksispp43X8+nwqIFYgb8UaX zu8T6kZP2wEIpM9RjEL3jdBjZNCsjSS6x1qzpc2+2ivjdiJsqeaagIgvy2JWy7vUa4/PyGfx QyUeXOxdj59DvLwAx8I6hOgeHx2X/ntKAMUxwawYfPZpP3gwTNKc27dJWSomOLgp+gbmOmgc 6U5KwhAxPTEb3CsT5RicsC+uQQFumdl5I6XS+pbeXZndXwnj5t84M+HEj7RN6bUfV2WZO/AB Xt5+qFkC/AVUcj/dcHvZwQJlGeZxoi4veCoOT2MYqfR0ax1MmN+LVRvKm29oSyD4Ts/97cbs XsZDRxnEG3z/7Winiv0ZanclA7v7CQwrzsbpCv+oj+zokGuKasofzKdpywkjAfSE1zTyF+8K nxBAmzwEqeQ3iKqBc3AcCseqSPX53mPqmwvNVS2GqBpnOfY7Mxr1AEmxdEcRYbhG6Xdn+ACq Dq0Db3A++3PhMSaOu125uIAIwMXRJIzCXYSqXo8NIeo9tobk0C/9w3fUfMTrBDtSviLHqlp8 eQEP8+TDSmRP/CwmFHv36jd+XGmBHzW5I7qw0OORRwNFYBeEuiOIgxAfjjbLGHh9SRwEqXAL kw+WVTwh0MN1k7I9/CDVlGvc3yIKS0sA+wudYiselXzgLuP5cQARAQABtCZNYXJjIEtsZWlu ZS1CdWRkZSA8bWtsQHBlbmd1dHJvbml4LmR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fFCh2Peo7qYmFUaDdyiCxvFm+YcIeMZ8wO5udzkjDtP4lWKAn4tUcdcwMOT5d0I3q WATP4wFI8QktNBqF3VY47HFwF9PtNuOZIqeAquKezywUc5KqKdqEWCPx9pfLxBAh3GW2Zfjp lP6A5upKs2ktDZOC2HZXP4IJ1GTk8hnfS4ade8s9FNcwu9m3JlxcGKLPq5DnIbPVQI1UUR4F QyAqTtIdSpeFYbvH8D7pO4lxLSz2ZyBMk+aKKs6GL5MqEci8OcFW Subject: Re: [PATCH V4] can: flexcan: implement can Runtime PM Message-ID: <433080fe-4266-c140-1a1f-078480b8bf7b@pengutronix.de> Date: Wed, 27 Feb 2019 11:35:16 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.5.1 MIME-Version: 1.0 In-Reply-To: <20181130085119.7948-1-qiangqing.zhang@nxp.com> Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="LucLFBBEh0yyiadEaVzkNGtzk8ZvF9HYd" X-SA-Exim-Connect-IP: 2001:67c:670:201:5054:ff:fe8d:eefb X-SA-Exim-Mail-From: mkl@pengutronix.de X-SA-Exim-Scanned: No (on metis.ext.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-kernel@vger.kernel.org Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --LucLFBBEh0yyiadEaVzkNGtzk8ZvF9HYd Content-Type: multipart/mixed; boundary="dO1zM7kpYBVUYxlJzM6hyzrGfWmF8vsRr"; protected-headers="v1" From: Marc Kleine-Budde To: Joakim Zhang , "linux-can@vger.kernel.org" Cc: "wg@grandegger.com" , "netdev@vger.kernel.org" , "linux-kernel@vger.kernel.org" , dl-linux-imx , Aisheng DONG Message-ID: <433080fe-4266-c140-1a1f-078480b8bf7b@pengutronix.de> Subject: Re: [PATCH V4] can: flexcan: implement can Runtime PM References: <20181130085119.7948-1-qiangqing.zhang@nxp.com> In-Reply-To: <20181130085119.7948-1-qiangqing.zhang@nxp.com> --dO1zM7kpYBVUYxlJzM6hyzrGfWmF8vsRr Content-Type: text/plain; charset=utf-8 Content-Language: en-GB Content-Transfer-Encoding: quoted-printable On 11/30/18 9:53 AM, Joakim Zhang wrote: > From: Aisheng Dong >=20 > Flexcan will be disabled during suspend if no wakeup function required = and > enabled after resume accordingly. During this period, we could explicit= ly > disable clocks. > Since PM is optional, the clock is enabled at probe to guarante the > clock is running when PM is not enabled in the kernel. >=20 > Implement Runtime PM which will: > 1) Without CONFIG_PM, clock is running whether Flexcan up or down. > 2) With CONFIG_PM, clock enabled while Flexcan up and disabled when > Flexcan down. > 3) Disable clock when do system suspend and enable clock while system > resume. > 4) Make Power Domain framework be able to shutdown the corresponding > power domain of this device. >=20 > Signed-off-by: Aisheng Dong > Signed-off-by: Joakim Zhang > --- > ChangeLog: > V1->V2: > *rebased on patch "can: flexcan: add self wakeup support". > V2->V3: > *fix device fails to probe without CONFIG_PM. > V3->V4: > *runtime pm enable should ahead of registering device. > *disable device even if keeping the clocks on. > --- > drivers/net/can/flexcan.c | 111 +++++++++++++++++++++++++-------------= > 1 file changed, 73 insertions(+), 38 deletions(-) >=20 > diff --git a/drivers/net/can/flexcan.c b/drivers/net/can/flexcan.c > index 0f36eafe3ac1..cad42f20cfe5 100644 > --- a/drivers/net/can/flexcan.c > +++ b/drivers/net/can/flexcan.c > @@ -24,6 +24,7 @@ > #include > #include > #include > +#include > #include > #include > =20 > @@ -277,6 +278,7 @@ struct flexcan_priv { > u32 reg_imask1_default; > u32 reg_imask2_default; > =20 > + struct device *dev; > struct clk *clk_ipg; > struct clk *clk_per; > const struct flexcan_devtype_data *devtype_data; > @@ -444,6 +446,27 @@ static inline void flexcan_error_irq_disable(const= struct flexcan_priv *priv) > priv->write(reg_ctrl, ®s->ctrl); > } > =20 > +static int flexcan_clks_enable(const struct flexcan_priv *priv) > +{ > + int err; > + > + err =3D clk_prepare_enable(priv->clk_ipg); > + if (err) > + return err; > + > + err =3D clk_prepare_enable(priv->clk_per); > + if (err) > + clk_disable_unprepare(priv->clk_ipg); > + > + return err; > +} > + > +static void flexcan_clks_disable(const struct flexcan_priv *priv) > +{ > + clk_disable_unprepare(priv->clk_ipg); > + clk_disable_unprepare(priv->clk_per); The original code first disabled the per then the ipg. > +} > + > static inline int flexcan_transceiver_enable(const struct flexcan_priv= *priv) > { > if (!priv->reg_xceiver) > @@ -570,19 +593,13 @@ static int flexcan_get_berr_counter(const struct = net_device *dev, > const struct flexcan_priv *priv =3D netdev_priv(dev); > int err; > =20 > - err =3D clk_prepare_enable(priv->clk_ipg); > - if (err) > + err =3D pm_runtime_get_sync(priv->dev); > + if (err < 0) > return err; > =20 > - err =3D clk_prepare_enable(priv->clk_per); > - if (err) > - goto out_disable_ipg; > - > err =3D __flexcan_get_berr_counter(dev, bec); > =20 > - clk_disable_unprepare(priv->clk_per); > - out_disable_ipg: > - clk_disable_unprepare(priv->clk_ipg); > + pm_runtime_put(priv->dev); > =20 > return err; > } > @@ -1215,17 +1232,13 @@ static int flexcan_open(struct net_device *dev)= > struct flexcan_priv *priv =3D netdev_priv(dev); > int err; > =20 > - err =3D clk_prepare_enable(priv->clk_ipg); > - if (err) > + err =3D pm_runtime_get_sync(priv->dev); > + if (err < 0) > return err; > =20 > - err =3D clk_prepare_enable(priv->clk_per); > - if (err) > - goto out_disable_ipg; > - > err =3D open_candev(dev); > if (err) > - goto out_disable_per; > + goto out_disable_clks; nitpick: you do a pm_runtime_put, so rename the label... > =20 > err =3D request_irq(dev->irq, flexcan_irq, IRQF_SHARED, dev->name, de= v); > if (err) > @@ -1288,10 +1301,8 @@ static int flexcan_open(struct net_device *dev) > free_irq(dev->irq, dev); > out_close: > close_candev(dev); > - out_disable_per: > - clk_disable_unprepare(priv->clk_per); > - out_disable_ipg: > - clk_disable_unprepare(priv->clk_ipg); > + out_disable_clks: > + pm_runtime_put(priv->dev); =2E..to out_runtime_put > =20 > return err; > } > @@ -1306,10 +1317,9 @@ static int flexcan_close(struct net_device *dev)= > =20 > can_rx_offload_del(&priv->offload); > free_irq(dev->irq, dev); > - clk_disable_unprepare(priv->clk_per); > - clk_disable_unprepare(priv->clk_ipg); > =20 > close_candev(dev); > + pm_runtime_put(priv->dev); > =20 > can_led_event(dev, CAN_LED_EVENT_STOP); > =20 > @@ -1349,18 +1359,14 @@ static int register_flexcandev(struct net_devic= e *dev) > struct flexcan_regs __iomem *regs =3D priv->regs; > u32 reg, err; > =20 > - err =3D clk_prepare_enable(priv->clk_ipg); > + err =3D flexcan_clks_enable(priv); > if (err) > return err; > =20 > - err =3D clk_prepare_enable(priv->clk_per); > - if (err) > - goto out_disable_ipg; > - > /* select "bus clock", chip must be disabled */ > err =3D flexcan_chip_disable(priv); > if (err) > - goto out_disable_per; > + goto out_disable_clks; nitpick: The function is called lexcan_clks_disable(), so let's rename the label accordingly. > reg =3D priv->read(®s->ctrl); > reg |=3D FLEXCAN_CTRL_CLK_SRC; > priv->write(reg, ®s->ctrl); > @@ -1389,14 +1395,13 @@ static int register_flexcandev(struct net_devic= e *dev) > =20 > err =3D register_candev(dev); No error handling? > =20 > - /* disable core and turn off clocks */ Better move the pm_runtime_put() here and adjust the comment. > - out_chip_disable: > flexcan_chip_disable(priv); > - out_disable_per: > - clk_disable_unprepare(priv->clk_per); > - out_disable_ipg: > - clk_disable_unprepare(priv->clk_ipg); > + return 0; > =20 > + out_chip_disable: > + flexcan_chip_disable(priv); > + out_disable_clks: > + flexcan_clks_disable(priv); > return err; > } > =20 > @@ -1556,6 +1561,7 @@ static int flexcan_probe(struct platform_device *= pdev) > priv->write =3D flexcan_write_le; > } > =20 > + priv->dev =3D &pdev->dev; > priv->can.clock.freq =3D clock_freq; > priv->can.bittiming_const =3D &flexcan_bittiming_const; > priv->can.do_set_mode =3D flexcan_set_mode; > @@ -1569,6 +1575,10 @@ static int flexcan_probe(struct platform_device = *pdev) > priv->devtype_data =3D devtype_data; > priv->reg_xceiver =3D reg_xceiver; > =20 > + pm_runtime_get_noresume(&pdev->dev); > + pm_runtime_set_active(&pdev->dev); > + pm_runtime_enable(&pdev->dev); > + > err =3D register_flexcandev(dev); > if (err) { > dev_err(&pdev->dev, "registering netdev failed\n"); > @@ -1586,6 +1596,7 @@ static int flexcan_probe(struct platform_device *= pdev) > dev_info(&pdev->dev, "device registered (reg_base=3D%p, irq=3D%d)\n",= > priv->regs, dev->irq); > =20 > + pm_runtime_put(&pdev->dev); > return 0; > =20 > failed_register: > @@ -1598,6 +1609,7 @@ static int flexcan_remove(struct platform_device = *pdev) > struct net_device *dev =3D platform_get_drvdata(pdev); > =20 > unregister_flexcandev(dev); > + pm_runtime_disable(&pdev->dev); > free_candev(dev); > =20 > return 0; > @@ -1607,7 +1619,7 @@ static int __maybe_unused flexcan_suspend(struct = device *device) > { > struct net_device *dev =3D dev_get_drvdata(device); > struct flexcan_priv *priv =3D netdev_priv(dev); > - int err; > + int err =3D 0; > =20 > if (netif_running(dev)) { > /* if wakeup is enabled, enter stop mode > @@ -1620,20 +1632,22 @@ static int __maybe_unused flexcan_suspend(struc= t device *device) > err =3D flexcan_chip_disable(priv); > if (err) > return err; > + > + err =3D pm_runtime_force_suspend(device); > } > netif_stop_queue(dev); > netif_device_detach(dev); > } > priv->can.state =3D CAN_STATE_SLEEPING; > =20 > - return 0; > + return err; > } > =20 > static int __maybe_unused flexcan_resume(struct device *device) > { > struct net_device *dev =3D dev_get_drvdata(device); > struct flexcan_priv *priv =3D netdev_priv(dev); > - int err; > + int err =3D 0; > =20 > priv->can.state =3D CAN_STATE_ERROR_ACTIVE; > if (netif_running(dev)) { > @@ -1642,14 +1656,34 @@ static int __maybe_unused flexcan_resume(struct= device *device) > if (device_may_wakeup(device)) { > disable_irq_wake(dev->irq); > } else { > - err =3D flexcan_chip_enable(priv); > + err =3D pm_runtime_force_resume(device); > if (err) > return err; > + > + err =3D flexcan_chip_enable(priv); > } > } > + return err; > +} > + > +static int __maybe_unused flexcan_runtime_suspend(struct device *devic= e) > +{ > + struct net_device *dev =3D dev_get_drvdata(device); > + struct flexcan_priv *priv =3D netdev_priv(dev); > + > + flexcan_clks_disable(priv); > + > return 0; > } > =20 > +static int __maybe_unused flexcan_runtime_resume(struct device *device= ) > +{ > + struct net_device *dev =3D dev_get_drvdata(device); > + struct flexcan_priv *priv =3D netdev_priv(dev); > + > + return flexcan_clks_enable(priv); > +} > + > static int __maybe_unused flexcan_noirq_suspend(struct device *device)= > { > struct net_device *dev =3D dev_get_drvdata(device); > @@ -1676,6 +1710,7 @@ static int __maybe_unused flexcan_noirq_resume(st= ruct device *device) > =20 > static const struct dev_pm_ops flexcan_pm_ops =3D { > SET_SYSTEM_SLEEP_PM_OPS(flexcan_suspend, flexcan_resume) > + SET_RUNTIME_PM_OPS(flexcan_runtime_suspend, flexcan_runtime_resume, N= ULL) > SET_NOIRQ_SYSTEM_SLEEP_PM_OPS(flexcan_noirq_suspend, flexcan_noirq_re= sume) > }; > =20 >=20 Marc --=20 Pengutronix e.K. | Marc Kleine-Budde | Industrial Linux Solutions | Phone: +49-231-2826-924 | Vertretung West/Dortmund | Fax: +49-5121-206917-5555 | Amtsgericht Hildesheim, HRA 2686 | http://www.pengutronix.de | --dO1zM7kpYBVUYxlJzM6hyzrGfWmF8vsRr-- --LucLFBBEh0yyiadEaVzkNGtzk8ZvF9HYd Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- iQEzBAEBCgAdFiEEmvEkXzgOfc881GuFWsYho5HknSAFAlx2Z+QACgkQWsYho5Hk nSBa8wgAgaakeXyJ4+SfYMRKR37iNb2mMGZPj545mI66fqFo+TzZDxvaG0QHFTha jO9HReg9Y+8v186vWtFzsNxuQ3ZJQFFqoC0KiPciD2kYJpjfK5lbxMuvA7MMadod Xrqn2NLrwSpdm4OYH4ocu/AC/wqBhD0+IO+jvr1y0zJRjoMRxidkOo54tp74Z0Fd P+G5mdM7+SwfKdgT1WbV2bVlPnS/Z8TGfPMP572kwnvXV+L3/13mRdSw5ofXA9I4 IjXkHhdoVd/Add8aV74V4lX/hFmymdDLvyC4nmtLdoGmWQbRDrPeO/pZxW3z7QSd EwSj6dTpWdJ6cGRuktRmPIdM4ACZSQ== =OAgi -----END PGP SIGNATURE----- --LucLFBBEh0yyiadEaVzkNGtzk8ZvF9HYd--