1616#include <linux/of_device.h>
1717#include <linux/of_dma.h>
1818#include <linux/platform_device.h>
19+ #include <linux/pm_runtime.h>
1920#include <linux/soc/apple/rtkit.h>
2021
2122#include "dmaengine.h"
@@ -809,10 +810,19 @@ static int sio_probe(struct platform_device *pdev)
809810 if (IS_ERR (sio -> base ))
810811 return PTR_ERR (sio -> base );
811812
813+ pm_runtime_get_noresume (& pdev -> dev );
814+ pm_runtime_set_active (& pdev -> dev );
815+ err = devm_pm_runtime_enable (& pdev -> dev );
816+ if (err < 0 )
817+ return dev_err_probe (& pdev -> dev , err ,
818+ "pm_runtime_enable failed: %d\n" , err );
819+
812820 sio -> rtk = devm_apple_rtkit_init (& pdev -> dev , sio , NULL , 0 , & sio_rtkit_ops );
813- if (IS_ERR (sio -> rtk ))
814- return dev_err_probe (& pdev -> dev , PTR_ERR (sio -> rtk ),
815- "couldn't initialize rtkit\n" );
821+ if (IS_ERR (sio -> rtk )) {
822+ err = PTR_ERR (sio -> rtk );
823+ dev_err (& pdev -> dev , "couldn't initialize rtkit\n" );
824+ goto rpm_put ;
825+ }
816826 for (i = 1 ; i < SIO_NTAGS ; i ++ )
817827 init_completion (& sio -> tags .completions [i ]);
818828
@@ -881,7 +891,10 @@ static int sio_probe(struct platform_device *pdev)
881891 return dev_err_probe (& pdev -> dev , err , "failed to register with OF\n" );
882892 }
883893
884- return 0 ;
894+ rpm_put :
895+ pm_runtime_put (& pdev -> dev );
896+
897+ return err ;
885898}
886899
887900static void sio_remove (struct platform_device * pdev )
@@ -898,10 +911,26 @@ static const struct of_device_id sio_of_match[] = {
898911};
899912MODULE_DEVICE_TABLE (of , sio_of_match );
900913
914+ static __maybe_unused int sio_suspend (struct device * dev )
915+ {
916+ /*
917+ * TODO: SIO coproc sleep state
918+ */
919+ return 0 ;
920+ }
921+
922+ static __maybe_unused int sio_resume (struct device * dev )
923+ {
924+ return 0 ;
925+ }
926+
927+ static DEFINE_RUNTIME_DEV_PM_OPS (sio_pm_ops , sio_suspend , sio_resume , NULL) ;
928+
901929static struct platform_driver apple_sio_driver = {
902930 .driver = {
903931 .name = "apple-sio" ,
904932 .of_match_table = sio_of_match ,
933+ .pm = pm_ptr (& sio_pm_ops ),
905934 },
906935 .probe = sio_probe ,
907936 .remove = sio_remove ,
0 commit comments