2626#include <linux/interrupt.h>
2727#include <linux/module.h>
2828#include <linux/platform_device.h>
29+ #include <linux/pm_runtime.h>
2930#include <linux/clk.h>
3031#include <net/irda/wrapper.h>
3132#include <net/irda/irda_device.h>
@@ -145,7 +146,7 @@ struct sh_irda_xir_func {
145146struct sh_irda_self {
146147 void __iomem * membase ;
147148 unsigned int irq ;
148- struct clk * clk ;
149+ struct platform_device * pdev ;
149150
150151 struct net_device * ndev ;
151152
@@ -694,7 +695,7 @@ static int sh_irda_open(struct net_device *ndev)
694695 struct sh_irda_self * self = netdev_priv (ndev );
695696 int err ;
696697
697- clk_enable ( self -> clk );
698+ pm_runtime_get_sync ( & self -> pdev -> dev );
698699 err = sh_irda_crc_init (self );
699700 if (err )
700701 goto open_err ;
@@ -718,7 +719,7 @@ static int sh_irda_open(struct net_device *ndev)
718719 return 0 ;
719720
720721open_err :
721- clk_disable ( self -> clk );
722+ pm_runtime_put_sync ( & self -> pdev -> dev );
722723
723724 return err ;
724725}
@@ -734,6 +735,7 @@ static int sh_irda_stop(struct net_device *ndev)
734735 }
735736
736737 netif_stop_queue (ndev );
738+ pm_runtime_put_sync (& self -> pdev -> dev );
737739
738740 dev_info (& ndev -> dev , "stoped\n" );
739741
@@ -786,11 +788,8 @@ static int __devinit sh_irda_probe(struct platform_device *pdev)
786788 if (err )
787789 goto err_mem_2 ;
788790
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 );
794793
795794 irda_init_max_qos_capabilies (& self -> qos );
796795
@@ -820,8 +819,7 @@ static int __devinit sh_irda_probe(struct platform_device *pdev)
820819 goto exit ;
821820
822821err_mem_4 :
823- clk_put (self -> clk );
824- err_mem_3 :
822+ pm_runtime_disable (& pdev -> dev );
825823 sh_irda_remove_iobuf (self );
826824err_mem_2 :
827825 iounmap (self -> membase );
@@ -840,7 +838,7 @@ static int __devexit sh_irda_remove(struct platform_device *pdev)
840838 return 0 ;
841839
842840 unregister_netdev (ndev );
843- clk_put ( self -> clk );
841+ pm_runtime_disable ( & pdev -> dev );
844842 sh_irda_remove_iobuf (self );
845843 iounmap (self -> membase );
846844 free_netdev (ndev );
@@ -849,11 +847,29 @@ static int __devexit sh_irda_remove(struct platform_device *pdev)
849847 return 0 ;
850848}
851849
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+
852867static struct platform_driver sh_irda_driver = {
853868 .probe = sh_irda_probe ,
854869 .remove = __devexit_p (sh_irda_remove ),
855870 .driver = {
856871 .name = DRIVER_NAME ,
872+ .pm = & sh_irda_pm_ops ,
857873 },
858874};
859875
0 commit comments