@@ -1043,6 +1043,88 @@ static int amd_sdw_clock_stop_exit(struct amd_sdw_manager *amd_manager)
10431043 return 0 ;
10441044}
10451045
1046+ static int amd_resume_child_device (struct device * dev , void * data )
1047+ {
1048+ struct sdw_slave * slave = dev_to_sdw_dev (dev );
1049+ int ret ;
1050+
1051+ if (!slave -> probed ) {
1052+ dev_dbg (dev , "skipping device, no probed driver\n" );
1053+ return 0 ;
1054+ }
1055+ if (!slave -> dev_num_sticky ) {
1056+ dev_dbg (dev , "skipping device, never detected on bus\n" );
1057+ return 0 ;
1058+ }
1059+ ret = pm_request_resume (dev );
1060+ if (ret < 0 ) {
1061+ dev_err (dev , "pm_request_resume failed: %d\n" , ret );
1062+ return ret ;
1063+ }
1064+ return 0 ;
1065+ }
1066+
1067+ static int __maybe_unused amd_pm_prepare (struct device * dev )
1068+ {
1069+ struct amd_sdw_manager * amd_manager = dev_get_drvdata (dev );
1070+ struct sdw_bus * bus = & amd_manager -> bus ;
1071+ int ret ;
1072+
1073+ if (bus -> prop .hw_disabled ) {
1074+ dev_dbg (bus -> dev , "SoundWire manager %d is disabled, ignoring\n" ,
1075+ bus -> link_id );
1076+ return 0 ;
1077+ }
1078+ /*
1079+ * When multiple peripheral devices connected over the same link, if SoundWire manager
1080+ * device is not in runtime suspend state, observed that device alerts are missing
1081+ * without pm_prepare on AMD platforms in clockstop mode0.
1082+ */
1083+ if (amd_manager -> power_mode_mask & AMD_SDW_CLK_STOP_MODE ) {
1084+ ret = pm_request_resume (dev );
1085+ if (ret < 0 ) {
1086+ dev_err (bus -> dev , "pm_request_resume failed: %d\n" , ret );
1087+ return 0 ;
1088+ }
1089+ }
1090+ /* To force peripheral devices to system level suspend state, resume the devices
1091+ * from runtime suspend state first. Without that unable to dispatch the alert
1092+ * status to peripheral driver during system level resume as they are in runtime
1093+ * suspend state.
1094+ */
1095+ ret = device_for_each_child (bus -> dev , NULL , amd_resume_child_device );
1096+ if (ret < 0 )
1097+ dev_err (dev , "amd_resume_child_device failed: %d\n" , ret );
1098+ return 0 ;
1099+ }
1100+
1101+ static int __maybe_unused amd_suspend (struct device * dev )
1102+ {
1103+ struct amd_sdw_manager * amd_manager = dev_get_drvdata (dev );
1104+ struct sdw_bus * bus = & amd_manager -> bus ;
1105+ int ret ;
1106+
1107+ if (bus -> prop .hw_disabled ) {
1108+ dev_dbg (bus -> dev , "SoundWire manager %d is disabled, ignoring\n" ,
1109+ bus -> link_id );
1110+ return 0 ;
1111+ }
1112+
1113+ if (amd_manager -> power_mode_mask & AMD_SDW_CLK_STOP_MODE ) {
1114+ return amd_sdw_clock_stop (amd_manager );
1115+ } else if (amd_manager -> power_mode_mask & AMD_SDW_POWER_OFF_MODE ) {
1116+ /*
1117+ * As per hardware programming sequence on AMD platforms,
1118+ * clock stop should be invoked first before powering-off
1119+ */
1120+ ret = amd_sdw_clock_stop (amd_manager );
1121+ if (ret )
1122+ return ret ;
1123+ return amd_deinit_sdw_manager (amd_manager );
1124+ }
1125+ return 0 ;
1126+ }
1127+
10461128static int __maybe_unused amd_suspend_runtime (struct device * dev )
10471129{
10481130 struct amd_sdw_manager * amd_manager = dev_get_drvdata (dev );
@@ -1105,6 +1187,8 @@ static int __maybe_unused amd_resume_runtime(struct device *dev)
11051187}
11061188
11071189static const struct dev_pm_ops amd_pm = {
1190+ .prepare = amd_pm_prepare ,
1191+ SET_SYSTEM_SLEEP_PM_OPS (amd_suspend , amd_resume_runtime )
11081192 SET_RUNTIME_PM_OPS (amd_suspend_runtime , amd_resume_runtime , NULL )
11091193};
11101194
0 commit comments