1515#include <linux/of.h>
1616#include <linux/platform_device.h>
1717#include <linux/pm_runtime.h>
18+ #include <linux/pinctrl/consumer.h>
1819#include <linux/dma/mxs-dma.h>
1920#include "gpmi-nand.h"
2021#include "gpmi-regs.h"
@@ -737,9 +738,8 @@ static int bch_set_geometry(struct gpmi_nand_data *this)
737738 if (ret )
738739 return ret ;
739740
740- ret = pm_runtime_get_sync (this -> dev );
741+ ret = pm_runtime_resume_and_get (this -> dev );
741742 if (ret < 0 ) {
742- pm_runtime_put_autosuspend (this -> dev );
743743 return ret ;
744744 }
745745
@@ -2761,15 +2761,9 @@ static int gpmi_nand_probe(struct platform_device *pdev)
27612761 if (ret )
27622762 goto exit_acquire_resources ;
27632763
2764- ret = __gpmi_enable_clk (this , true);
2765- if (ret )
2766- goto exit_acquire_resources ;
2767-
2764+ pm_runtime_enable (& pdev -> dev );
27682765 pm_runtime_set_autosuspend_delay (& pdev -> dev , 500 );
27692766 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 );
27732767
27742768 ret = gpmi_init (this );
27752769 if (ret )
@@ -2779,15 +2773,12 @@ static int gpmi_nand_probe(struct platform_device *pdev)
27792773 if (ret )
27802774 goto exit_nfc_init ;
27812775
2782- pm_runtime_mark_last_busy (& pdev -> dev );
2783- pm_runtime_put_autosuspend (& pdev -> dev );
2784-
27852776 dev_info (this -> dev , "driver registered.\n" );
27862777
27872778 return 0 ;
27882779
27892780exit_nfc_init :
2790- pm_runtime_put (& pdev -> dev );
2781+ pm_runtime_dont_use_autosuspend (& pdev -> dev );
27912782 pm_runtime_disable (& pdev -> dev );
27922783 release_resources (this );
27932784exit_acquire_resources :
@@ -2801,32 +2792,37 @@ static void gpmi_nand_remove(struct platform_device *pdev)
28012792 struct nand_chip * chip = & this -> nand ;
28022793 int ret ;
28032794
2804- pm_runtime_put_sync (& pdev -> dev );
2805- pm_runtime_disable (& pdev -> dev );
2806-
28072795 ret = mtd_device_unregister (nand_to_mtd (chip ));
28082796 WARN_ON (ret );
28092797 nand_cleanup (chip );
28102798 gpmi_free_dma_buffer (this );
28112799 release_resources (this );
2800+ pm_runtime_dont_use_autosuspend (& pdev -> dev );
2801+ pm_runtime_disable (& pdev -> dev );
28122802}
28132803
28142804static int gpmi_pm_suspend (struct device * dev )
28152805{
2816- struct gpmi_nand_data * this = dev_get_drvdata ( dev ) ;
2806+ int ret ;
28172807
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 ;
28202812}
28212813
28222814static int gpmi_pm_resume (struct device * dev )
28232815{
28242816 struct gpmi_nand_data * this = dev_get_drvdata (dev );
28252817 int ret ;
28262818
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 );
28292822 return ret ;
2823+ }
2824+
2825+ pinctrl_pm_select_default_state (dev );
28302826
28312827 /* re-init the GPMI registers */
28322828 ret = gpmi_init (this );
@@ -2849,18 +2845,29 @@ static int gpmi_pm_resume(struct device *dev)
28492845 return 0 ;
28502846}
28512847
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 )
28532852{
28542853 struct gpmi_nand_data * this = dev_get_drvdata (dev );
28552854
2856- return __gpmi_enable_clk (this , false);
2855+ gpmi_disable_clk (this );
2856+
2857+ return 0 ;
28572858}
28582859
2859- static int __maybe_unused gpmi_runtime_resume (struct device * dev )
2860+ static int gpmi_runtime_resume (struct device * dev )
28602861{
28612862 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 ;
28622870
2863- return __gpmi_enable_clk (this , true);
28642871}
28652872
28662873static const struct dev_pm_ops gpmi_pm_ops = {
0 commit comments