15
15
#include <linux/of.h>
16
16
#include <linux/platform_device.h>
17
17
#include <linux/pm_runtime.h>
18
+ #include <linux/pinctrl/consumer.h>
18
19
#include <linux/dma/mxs-dma.h>
19
20
#include "gpmi-nand.h"
20
21
#include "gpmi-regs.h"
@@ -737,9 +738,8 @@ static int bch_set_geometry(struct gpmi_nand_data *this)
737
738
if (ret )
738
739
return ret ;
739
740
740
- ret = pm_runtime_get_sync (this -> dev );
741
+ ret = pm_runtime_resume_and_get (this -> dev );
741
742
if (ret < 0 ) {
742
- pm_runtime_put_autosuspend (this -> dev );
743
743
return ret ;
744
744
}
745
745
@@ -2761,15 +2761,9 @@ static int gpmi_nand_probe(struct platform_device *pdev)
2761
2761
if (ret )
2762
2762
goto exit_acquire_resources ;
2763
2763
2764
- ret = __gpmi_enable_clk (this , true);
2765
- if (ret )
2766
- goto exit_acquire_resources ;
2767
-
2764
+ pm_runtime_enable (& pdev -> dev );
2768
2765
pm_runtime_set_autosuspend_delay (& pdev -> dev , 500 );
2769
2766
pm_runtime_use_autosuspend (& pdev -> dev );
2770
- pm_runtime_set_active (& pdev -> dev );
2771
- pm_runtime_enable (& pdev -> dev );
2772
- pm_runtime_get_sync (& pdev -> dev );
2773
2767
2774
2768
ret = gpmi_init (this );
2775
2769
if (ret )
@@ -2779,15 +2773,12 @@ static int gpmi_nand_probe(struct platform_device *pdev)
2779
2773
if (ret )
2780
2774
goto exit_nfc_init ;
2781
2775
2782
- pm_runtime_mark_last_busy (& pdev -> dev );
2783
- pm_runtime_put_autosuspend (& pdev -> dev );
2784
-
2785
2776
dev_info (this -> dev , "driver registered.\n" );
2786
2777
2787
2778
return 0 ;
2788
2779
2789
2780
exit_nfc_init :
2790
- pm_runtime_put (& pdev -> dev );
2781
+ pm_runtime_dont_use_autosuspend (& pdev -> dev );
2791
2782
pm_runtime_disable (& pdev -> dev );
2792
2783
release_resources (this );
2793
2784
exit_acquire_resources :
@@ -2801,32 +2792,37 @@ static void gpmi_nand_remove(struct platform_device *pdev)
2801
2792
struct nand_chip * chip = & this -> nand ;
2802
2793
int ret ;
2803
2794
2804
- pm_runtime_put_sync (& pdev -> dev );
2805
- pm_runtime_disable (& pdev -> dev );
2806
-
2807
2795
ret = mtd_device_unregister (nand_to_mtd (chip ));
2808
2796
WARN_ON (ret );
2809
2797
nand_cleanup (chip );
2810
2798
gpmi_free_dma_buffer (this );
2811
2799
release_resources (this );
2800
+ pm_runtime_dont_use_autosuspend (& pdev -> dev );
2801
+ pm_runtime_disable (& pdev -> dev );
2812
2802
}
2813
2803
2814
2804
static int gpmi_pm_suspend (struct device * dev )
2815
2805
{
2816
- struct gpmi_nand_data * this = dev_get_drvdata ( dev ) ;
2806
+ int ret ;
2817
2807
2818
- release_dma_channels (this );
2819
- return 0 ;
2808
+ pinctrl_pm_select_sleep_state (dev );
2809
+ ret = pm_runtime_force_suspend (dev );
2810
+
2811
+ return ret ;
2820
2812
}
2821
2813
2822
2814
static int gpmi_pm_resume (struct device * dev )
2823
2815
{
2824
2816
struct gpmi_nand_data * this = dev_get_drvdata (dev );
2825
2817
int ret ;
2826
2818
2827
- ret = acquire_dma_channels (this );
2828
- if (ret < 0 )
2819
+ ret = pm_runtime_force_resume (dev );
2820
+ if (ret ) {
2821
+ dev_err (this -> dev , "Error in resume %d\n" , ret );
2829
2822
return ret ;
2823
+ }
2824
+
2825
+ pinctrl_pm_select_default_state (dev );
2830
2826
2831
2827
/* re-init the GPMI registers */
2832
2828
ret = gpmi_init (this );
@@ -2849,18 +2845,29 @@ static int gpmi_pm_resume(struct device *dev)
2849
2845
return 0 ;
2850
2846
}
2851
2847
2852
- static int __maybe_unused gpmi_runtime_suspend (struct device * dev )
2848
+ #define gpmi_enable_clk (x ) __gpmi_enable_clk(x, true)
2849
+ #define gpmi_disable_clk (x ) __gpmi_enable_clk(x, false)
2850
+
2851
+ static int gpmi_runtime_suspend (struct device * dev )
2853
2852
{
2854
2853
struct gpmi_nand_data * this = dev_get_drvdata (dev );
2855
2854
2856
- return __gpmi_enable_clk (this , false);
2855
+ gpmi_disable_clk (this );
2856
+
2857
+ return 0 ;
2857
2858
}
2858
2859
2859
- static int __maybe_unused gpmi_runtime_resume (struct device * dev )
2860
+ static int gpmi_runtime_resume (struct device * dev )
2860
2861
{
2861
2862
struct gpmi_nand_data * this = dev_get_drvdata (dev );
2863
+ int ret ;
2864
+
2865
+ ret = gpmi_enable_clk (this );
2866
+ if (ret )
2867
+ return ret ;
2868
+
2869
+ return 0 ;
2862
2870
2863
- return __gpmi_enable_clk (this , true);
2864
2871
}
2865
2872
2866
2873
static const struct dev_pm_ops gpmi_pm_ops = {
0 commit comments