Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp2247368imu; Thu, 29 Nov 2018 01:46:54 -0800 (PST) X-Google-Smtp-Source: AFSGD/XW12RvXEcgvnSncnV356HmJh9uSYyPRntXJqCxgXsODiI3tQ1CgIlkQxJzRJ9xQuialxb/ X-Received: by 2002:a62:7a8b:: with SMTP id v133mr717586pfc.159.1543484813959; Thu, 29 Nov 2018 01:46:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543484813; cv=none; d=google.com; s=arc-20160816; b=g4b+DtcTEgRIlBcMfIANmR5NdQuvUR01Uac5pb/evStKRpCidn+X1DNjeaAvcXf8nr 6uzOQGvUBBC7o0emkun9x8yXRuSMjozNuxfTgoKtlLObojNMfxwZSo6u1SgNOBFDOwtX StOWtYQyjGm/dGytlFTqCLKfuB6EHccX+TUYR1MzLNHtr2slttcNAUq+7XSpJmZtzmq6 RHHLMrGg5JPPmQaHW28jM2H6ukHOFqUF1n85+0fa/0n9yti++20fL/9FS5d9f003IbiQ vb7blPpj0Zh4yg8zbgvVO0A8T5u0N6MFMDlVAWmt/+v2N7D898GEDxwShe8yfes5xu9Q kGvQ== 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=P65DBob//EU8bzgNPiSFo7/XrJz5j/NoSxuiJ3kV6VA=; b=iLTFi2kLYkP59aEkLwxFeZWuoFx+7nM4xD+lL6lEzec+bCUUOU9xlAOlteADqLczr1 bSeFBsAgpY6unbpSKp46+oB346qukKvmoZ5SCqjdALfqDGDEw6O3MyNIqozg+6jcEJyo rhD/JrItD2t466ETbDM3NUBqMJCuir+scd2k5oQBnL1QOq1iDUNQjMizdjEpnBpL+NdS Ot1zyEbvLMVm+5H6NLFY9wrAEyE/RhL8GGmVKIZ2UoCzcc6KosCQJXpq9Bmrl+ZA3qa/ dLVNqYvxjx05Jje2LROVJqLWuPu+FlEwZ8BLiLTWwWI3FO13WHnsUjATY4MD4hKHPUVe MseA== 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 z143si1923078pfc.97.2018.11.29.01.46.39; Thu, 29 Nov 2018 01:46:53 -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 S1727481AbeK2Us4 (ORCPT + 99 others); Thu, 29 Nov 2018 15:48:56 -0500 Received: from metis.ext.pengutronix.de ([85.220.165.71]:37691 "EHLO metis.ext.pengutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726670AbeK2Us4 (ORCPT ); Thu, 29 Nov 2018 15:48:56 -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 1gSIrd-0005PC-Tw; Thu, 29 Nov 2018 10:44:06 +0100 Received: from [IPv6:2a03:f580:87bc:d400:e586:a438:6bdb:ffff] (unknown [IPv6:2a03:f580:87bc:d400:e586:a438:6bdb:ffff]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (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 EB6C13985F2; Thu, 29 Nov 2018 09:44:04 +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: <20181129080559.18572-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 ZS1CdWRkZSA8bWtsQHBlbmd1dHJvbml4LmRlPokCVAQTAQoAPgIbAwIeAQIXgAULCQgHAwUV CgkICwUWAgMBABYhBMFAC6CzmJ5vvH1bX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Rq49WSclOMvqDdh//wmfSAbkyn3EA6EMv9mxJHJvKW7PMXvO0Mk1uP/+VR3FudMXhZzz MUYlqpO3B/RmA7lPoMY5+Km8c4/6L9Bn0vcbGMH4piH0IuEK0px64oXtKfti47XrCX+EDpSn ZwhEnNjCKyAJTaangebRpvOwJUZUWVh+hpM5FMcwJGKvVXNmrmSj Subject: Re: [PATCH V3] can: flexcan: implement can Runtime PM Message-ID: <873ce967-5e94-28f0-608d-dc55d77ab182@pengutronix.de> Date: Thu, 29 Nov 2018 10:44:01 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.3.0 MIME-Version: 1.0 In-Reply-To: <20181129080559.18572-1-qiangqing.zhang@nxp.com> Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="eqXyd9DatNZcUohgZbTVBk0GHt0yL0VCL" 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) --eqXyd9DatNZcUohgZbTVBk0GHt0yL0VCL Content-Type: multipart/mixed; boundary="kcbtWtVZ3zKs4iFYUjsEOJw0WgcVVf0uj"; 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: <873ce967-5e94-28f0-608d-dc55d77ab182@pengutronix.de> Subject: Re: [PATCH V3] can: flexcan: implement can Runtime PM References: <20181129080559.18572-1-qiangqing.zhang@nxp.com> In-Reply-To: <20181129080559.18572-1-qiangqing.zhang@nxp.com> --kcbtWtVZ3zKs4iFYUjsEOJw0WgcVVf0uj Content-Type: text/plain; charset=utf-8 Content-Language: en-GB Content-Transfer-Encoding: quoted-printable On 11/29/18 9:08 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 opened or closed= =2E ACK > 2) With CONFIG_PM, clock enabled while Flexcan opened and disabled when= =2E..when closed? I think the sentence misses something at the end. And it doesn't work: > root@DistroKit:~ ifconfig can0 > can0 Link encap:UNSPEC HWaddr 00-00-00-00-00-00-00-00-00-00-00-00= -00-00-00-00 =20 > NOARP MTU:16 Metric:1 > RX packets:0 errors:0 dropped:0 overruns:0 frame:0 > TX packets:0 errors:0 dropped:0 overruns:0 carrier:0 > collisions:0 txqueuelen:10=20 > RX bytes:0 (0.0 B) TX bytes:0 (0.0 B) > Interrupt:34=20 >=20 > root@DistroKit:~ grep can /sys/kernel/debug/clk/clk_summary=20 > can_root 1 1 0 30000000 = 0 0 50000 > can2_serial 0 0 0 30000000 = 0 0 50000 > can1_serial 1 1 0 30000000 = 0 0 50000 > can2_ipg 0 0 0 66000= 000 0 0 50000 > can1_ipg 1 1 0 66000= 000 0 0 50000 can0 is down, while the can1_{serial,ipg} are enabled. > 3) Regardless of CONFIG_PM enabled or not, Flexcan runtime status is > SUSPENDED during Flexcan closed and ACTIVE when Flexcan opened. > 4) Make Power Domain framework be able to shutdown the corresponding po= wer > 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. > --- > drivers/net/can/flexcan.c | 107 +++++++++++++++++++++++++-------------= > 1 file changed, 70 insertions(+), 37 deletions(-) >=20 > diff --git a/drivers/net/can/flexcan.c b/drivers/net/can/flexcan.c > index 0f36eafe3ac1..cc62a97237db 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); > +} > + > 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; > =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); > =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; > reg =3D priv->read(®s->ctrl); > reg |=3D FLEXCAN_CTRL_CLK_SRC; > priv->write(reg, ®s->ctrl); > @@ -1389,13 +1395,12 @@ static int register_flexcandev(struct net_devic= e *dev) > =20 > err =3D register_candev(dev); > =20 > - /* disable core and turn off clocks */ Please disable the device, even if keeping the clocks on. > + return 0; > + > 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); > + out_disable_clks: > + flexcan_clks_disable(priv); > =20 > return err; > } > @@ -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; > @@ -1586,6 +1592,9 @@ 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_enable(&pdev->dev); > + pm_runtime_put(&pdev->dev); > + > return 0; > =20 > failed_register: > @@ -1598,6 +1607,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 +1617,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 +1630,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 +1654,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 +1708,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 | --kcbtWtVZ3zKs4iFYUjsEOJw0WgcVVf0uj-- --eqXyd9DatNZcUohgZbTVBk0GHt0yL0VCL Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- iQEzBAEBCgAdFiEENrCndlB/VnAEWuH5k9IU1zQoZfEFAlv/tOEACgkQk9IU1zQo ZfHHTAf/VMp+8c7dTVHHPNBgoENSzX1FNoNgq/50Tq/qn6S7vSj6e5sLKQVfu0Xx xQiTjn1T9Oo4Bt3V2K7UmNsMlr7wMQapQxXgIG7330sXqHdSGw0xCs9lIOEFP1sr 1iasD5aOzE5gK+WqelSm+rTm6SFu8CNXSbeItYKNKphEIGuXzIM2BqQJYqjEEUtM 73HEQYlhQfkn1k5nzznagOvpjCB7Un2/RMGUQgL72wZThN1lpnOjLASwjg6KAl5E sxJ6RB+13RFLfSL9+ee5n1UOeCPD04Si1Gerts4t6hC5A6NE83Sp0jQyiitK0lJy tP8zWGqCN7g+81sqXGxIoCeGdFxBRw== =i98g -----END PGP SIGNATURE----- --eqXyd9DatNZcUohgZbTVBk0GHt0yL0VCL--