ath79/mikrotik: use routerbootpart partitions
[oweals/openwrt.git] / target / linux / layerscape / patches-5.4 / 802-can-0025-can-flexcan-add-LPSR-mode-support-for-i.MX7D.patch
1 From 211c20a459a0fd4868ed22ecfc2b2186d9df6da0 Mon Sep 17 00:00:00 2001
2 From: Joakim Zhang <qiangqing.zhang@nxp.com>
3 Date: Tue, 30 Jul 2019 14:43:25 +0800
4 Subject: [PATCH] can: flexcan: add LPSR mode support for i.MX7D
5
6 For i.MX7D LPSR mode, the controller will lost power and got the
7 configuration state lost after system resume back.
8 So we need to set pinctrl state again and re-start chip to do
9 re-configuration after resume.
10
11 For wakeup case, it should not set pinctrl to sleep state by
12 pinctrl_pm_select_sleep_state.
13 For interface is not up before suspend case, we don't need
14 re-configure as it will be configured by user later by interface up.
15
16 Signed-off-by: Joakim Zhang <qiangqing.zhang@nxp.com>
17 ---
18  drivers/net/can/flexcan.c | 21 ++++++++++++++-------
19  1 file changed, 14 insertions(+), 7 deletions(-)
20
21 --- a/drivers/net/can/flexcan.c
22 +++ b/drivers/net/can/flexcan.c
23 @@ -26,6 +26,7 @@
24  #include <linux/platform_device.h>
25  #include <linux/pm_runtime.h>
26  #include <linux/regulator/consumer.h>
27 +#include <linux/pinctrl/consumer.h>
28  #include <linux/regmap.h>
29  
30  #define DRV_NAME                       "flexcan"
31 @@ -1920,7 +1921,7 @@ static int __maybe_unused flexcan_suspen
32  {
33         struct net_device *dev = dev_get_drvdata(device);
34         struct flexcan_priv *priv = netdev_priv(dev);
35 -       int err = 0;
36 +       int err;
37  
38         if (netif_running(dev)) {
39                 /* if wakeup is enabled, enter stop mode
40 @@ -1932,25 +1933,27 @@ static int __maybe_unused flexcan_suspen
41                         if (err)
42                                 return err;
43                 } else {
44 -                       err = flexcan_chip_disable(priv);
45 +                       flexcan_chip_stop(dev);
46 +
47 +                       err = pm_runtime_force_suspend(device);
48                         if (err)
49                                 return err;
50  
51 -                       err = pm_runtime_force_suspend(device);
52 +                       pinctrl_pm_select_sleep_state(device);
53                 }
54                 netif_stop_queue(dev);
55                 netif_device_detach(dev);
56         }
57         priv->can.state = CAN_STATE_SLEEPING;
58  
59 -       return err;
60 +       return 0;
61  }
62  
63  static int __maybe_unused flexcan_resume(struct device *device)
64  {
65         struct net_device *dev = dev_get_drvdata(device);
66         struct flexcan_priv *priv = netdev_priv(dev);
67 -       int err = 0;
68 +       int err;
69  
70         priv->can.state = CAN_STATE_ERROR_ACTIVE;
71         if (netif_running(dev)) {
72 @@ -1962,15 +1965,19 @@ static int __maybe_unused flexcan_resume
73                         if (err)
74                                 return err;
75                 } else {
76 +                       pinctrl_pm_select_default_state(device);
77 +
78                         err = pm_runtime_force_resume(device);
79                         if (err)
80                                 return err;
81  
82 -                       err = flexcan_chip_enable(priv);
83 +                       err = flexcan_chip_start(dev);
84 +                       if (err)
85 +                               return err;
86                 }
87         }
88  
89 -       return err;
90 +       return 0;
91  }
92  
93  static int __maybe_unused flexcan_runtime_suspend(struct device *device)