26
26
#include <linux/interrupt.h>
27
27
#include <linux/module.h>
28
28
#include <linux/platform_device.h>
29
+ #include <linux/pm_runtime.h>
29
30
#include <linux/clk.h>
30
31
#include <net/irda/wrapper.h>
31
32
#include <net/irda/irda_device.h>
@@ -145,7 +146,7 @@ struct sh_irda_xir_func {
145
146
struct sh_irda_self {
146
147
void __iomem * membase ;
147
148
unsigned int irq ;
148
- struct clk * clk ;
149
+ struct platform_device * pdev ;
149
150
150
151
struct net_device * ndev ;
151
152
@@ -694,7 +695,7 @@ static int sh_irda_open(struct net_device *ndev)
694
695
struct sh_irda_self * self = netdev_priv (ndev );
695
696
int err ;
696
697
697
- clk_enable ( self -> clk );
698
+ pm_runtime_get_sync ( & self -> pdev -> dev );
698
699
err = sh_irda_crc_init (self );
699
700
if (err )
700
701
goto open_err ;
@@ -718,7 +719,7 @@ static int sh_irda_open(struct net_device *ndev)
718
719
return 0 ;
719
720
720
721
open_err :
721
- clk_disable ( self -> clk );
722
+ pm_runtime_put_sync ( & self -> pdev -> dev );
722
723
723
724
return err ;
724
725
}
@@ -734,6 +735,7 @@ static int sh_irda_stop(struct net_device *ndev)
734
735
}
735
736
736
737
netif_stop_queue (ndev );
738
+ pm_runtime_put_sync (& self -> pdev -> dev );
737
739
738
740
dev_info (& ndev -> dev , "stoped\n" );
739
741
@@ -786,11 +788,8 @@ static int __devinit sh_irda_probe(struct platform_device *pdev)
786
788
if (err )
787
789
goto err_mem_2 ;
788
790
789
- self -> clk = clk_get (& pdev -> dev , NULL );
790
- if (IS_ERR (self -> clk )) {
791
- dev_err (& pdev -> dev , "cannot get irda clock\n" );
792
- goto err_mem_3 ;
793
- }
791
+ self -> pdev = pdev ;
792
+ pm_runtime_enable (& pdev -> dev );
794
793
795
794
irda_init_max_qos_capabilies (& self -> qos );
796
795
@@ -820,8 +819,7 @@ static int __devinit sh_irda_probe(struct platform_device *pdev)
820
819
goto exit ;
821
820
822
821
err_mem_4 :
823
- clk_put (self -> clk );
824
- err_mem_3 :
822
+ pm_runtime_disable (& pdev -> dev );
825
823
sh_irda_remove_iobuf (self );
826
824
err_mem_2 :
827
825
iounmap (self -> membase );
@@ -840,7 +838,7 @@ static int __devexit sh_irda_remove(struct platform_device *pdev)
840
838
return 0 ;
841
839
842
840
unregister_netdev (ndev );
843
- clk_put ( self -> clk );
841
+ pm_runtime_disable ( & pdev -> dev );
844
842
sh_irda_remove_iobuf (self );
845
843
iounmap (self -> membase );
846
844
free_netdev (ndev );
@@ -849,11 +847,29 @@ static int __devexit sh_irda_remove(struct platform_device *pdev)
849
847
return 0 ;
850
848
}
851
849
850
+ static int sh_irda_runtime_nop (struct device * dev )
851
+ {
852
+ /* Runtime PM callback shared between ->runtime_suspend()
853
+ * and ->runtime_resume(). Simply returns success.
854
+ *
855
+ * This driver re-initializes all registers after
856
+ * pm_runtime_get_sync() anyway so there is no need
857
+ * to save and restore registers here.
858
+ */
859
+ return 0 ;
860
+ }
861
+
862
+ static const struct dev_pm_ops sh_irda_pm_ops = {
863
+ .runtime_suspend = sh_irda_runtime_nop ,
864
+ .runtime_resume = sh_irda_runtime_nop ,
865
+ };
866
+
852
867
static struct platform_driver sh_irda_driver = {
853
868
.probe = sh_irda_probe ,
854
869
.remove = __devexit_p (sh_irda_remove ),
855
870
.driver = {
856
871
.name = DRIVER_NAME ,
872
+ .pm = & sh_irda_pm_ops ,
857
873
},
858
874
};
859
875
0 commit comments