@@ -930,87 +930,109 @@ static int param_set_xint(const char *val, const struct kernel_param *kp)
930
930
mutex_unlock (& card_list_lock );
931
931
return 0 ;
932
932
}
933
- #else
934
- #define azx_add_card_list (chip ) /* NOP */
935
- #define azx_del_card_list (chip ) /* NOP */
936
- #endif /* CONFIG_PM */
937
933
938
- #ifdef CONFIG_PM_SLEEP
939
934
/*
940
935
* power management
941
936
*/
942
- static int azx_suspend (struct device * dev )
937
+ static bool azx_is_pm_ready (struct snd_card * card )
943
938
{
944
- struct snd_card * card = dev_get_drvdata (dev );
945
939
struct azx * chip ;
946
940
struct hda_intel * hda ;
947
- struct hdac_bus * bus ;
948
941
949
942
if (!card )
950
- return 0 ;
951
-
943
+ return false;
952
944
chip = card -> private_data ;
953
945
hda = container_of (chip , struct hda_intel , chip );
954
946
if (chip -> disabled || hda -> init_failed || !chip -> running )
947
+ return false;
948
+ return true;
949
+ }
950
+
951
+ static void __azx_runtime_suspend (struct azx * chip )
952
+ {
953
+ struct hda_intel * hda = container_of (chip , struct hda_intel , chip );
954
+
955
+ azx_stop_chip (chip );
956
+ azx_enter_link_reset (chip );
957
+ azx_clear_irq_pending (chip );
958
+ if ((chip -> driver_caps & AZX_DCAPS_I915_POWERWELL ) &&
959
+ hda -> need_i915_power )
960
+ snd_hdac_display_power (azx_bus (chip ), false);
961
+ }
962
+
963
+ static void __azx_runtime_resume (struct azx * chip )
964
+ {
965
+ struct hda_intel * hda = container_of (chip , struct hda_intel , chip );
966
+ struct hdac_bus * bus = azx_bus (chip );
967
+ struct hda_codec * codec ;
968
+ int status ;
969
+
970
+ if (chip -> driver_caps & AZX_DCAPS_I915_POWERWELL ) {
971
+ snd_hdac_display_power (bus , true);
972
+ if (hda -> need_i915_power )
973
+ snd_hdac_i915_set_bclk (bus );
974
+ }
975
+
976
+ /* Read STATESTS before controller reset */
977
+ status = azx_readw (chip , STATESTS );
978
+
979
+ azx_init_pci (chip );
980
+ hda_intel_init_chip (chip , true);
981
+
982
+ if (status ) {
983
+ list_for_each_codec (codec , & chip -> bus )
984
+ if (status & (1 << codec -> addr ))
985
+ schedule_delayed_work (& codec -> jackpoll_work ,
986
+ codec -> jackpoll_interval );
987
+ }
988
+
989
+ /* power down again for link-controlled chips */
990
+ if ((chip -> driver_caps & AZX_DCAPS_I915_POWERWELL ) &&
991
+ !hda -> need_i915_power )
992
+ snd_hdac_display_power (bus , false);
993
+ }
994
+
995
+ #ifdef CONFIG_PM_SLEEP
996
+ static int azx_suspend (struct device * dev )
997
+ {
998
+ struct snd_card * card = dev_get_drvdata (dev );
999
+ struct azx * chip ;
1000
+ struct hdac_bus * bus ;
1001
+
1002
+ if (!azx_is_pm_ready (card ))
955
1003
return 0 ;
956
1004
1005
+ chip = card -> private_data ;
957
1006
bus = azx_bus (chip );
958
1007
snd_power_change_state (card , SNDRV_CTL_POWER_D3hot );
959
- azx_clear_irq_pending (chip );
960
- azx_stop_chip (chip );
961
- azx_enter_link_reset (chip );
1008
+ __azx_runtime_suspend (chip );
962
1009
if (bus -> irq >= 0 ) {
963
1010
free_irq (bus -> irq , chip );
964
1011
bus -> irq = -1 ;
965
1012
}
966
1013
967
1014
if (chip -> msi )
968
1015
pci_disable_msi (chip -> pci );
969
- if ((chip -> driver_caps & AZX_DCAPS_I915_POWERWELL )
970
- && hda -> need_i915_power )
971
- snd_hdac_display_power (bus , false);
972
1016
973
1017
trace_azx_suspend (chip );
974
1018
return 0 ;
975
1019
}
976
1020
977
1021
static int azx_resume (struct device * dev )
978
1022
{
979
- struct pci_dev * pci = to_pci_dev (dev );
980
1023
struct snd_card * card = dev_get_drvdata (dev );
981
1024
struct azx * chip ;
982
- struct hda_intel * hda ;
983
- struct hdac_bus * bus ;
984
1025
985
- if (!card )
1026
+ if (!azx_is_pm_ready ( card ) )
986
1027
return 0 ;
987
1028
988
1029
chip = card -> private_data ;
989
- hda = container_of (chip , struct hda_intel , chip );
990
- bus = azx_bus (chip );
991
- if (chip -> disabled || hda -> init_failed || !chip -> running )
992
- return 0 ;
993
-
994
- if (chip -> driver_caps & AZX_DCAPS_I915_POWERWELL ) {
995
- snd_hdac_display_power (bus , true);
996
- if (hda -> need_i915_power )
997
- snd_hdac_i915_set_bclk (bus );
998
- }
999
-
1000
1030
if (chip -> msi )
1001
- if (pci_enable_msi (pci ) < 0 )
1031
+ if (pci_enable_msi (chip -> pci ) < 0 )
1002
1032
chip -> msi = 0 ;
1003
1033
if (azx_acquire_irq (chip , 1 ) < 0 )
1004
1034
return - EIO ;
1005
- azx_init_pci (chip );
1006
-
1007
- hda_intel_init_chip (chip , true);
1008
-
1009
- /* power down again for link-controlled chips */
1010
- if ((chip -> driver_caps & AZX_DCAPS_I915_POWERWELL ) &&
1011
- !hda -> need_i915_power )
1012
- snd_hdac_display_power (bus , false);
1013
-
1035
+ __azx_runtime_resume (chip );
1014
1036
snd_power_change_state (card , SNDRV_CTL_POWER_D0 );
1015
1037
1016
1038
trace_azx_resume (chip );
@@ -1045,35 +1067,22 @@ static int azx_thaw_noirq(struct device *dev)
1045
1067
}
1046
1068
#endif /* CONFIG_PM_SLEEP */
1047
1069
1048
- #ifdef CONFIG_PM
1049
1070
static int azx_runtime_suspend (struct device * dev )
1050
1071
{
1051
1072
struct snd_card * card = dev_get_drvdata (dev );
1052
1073
struct azx * chip ;
1053
- struct hda_intel * hda ;
1054
1074
1055
- if (!card )
1075
+ if (!azx_is_pm_ready ( card ) )
1056
1076
return 0 ;
1057
-
1058
1077
chip = card -> private_data ;
1059
- hda = container_of (chip , struct hda_intel , chip );
1060
- if (chip -> disabled || hda -> init_failed )
1061
- return 0 ;
1062
-
1063
1078
if (!azx_has_pm_runtime (chip ))
1064
1079
return 0 ;
1065
1080
1066
1081
/* enable controller wake up event */
1067
1082
azx_writew (chip , WAKEEN , azx_readw (chip , WAKEEN ) |
1068
1083
STATESTS_INT_MASK );
1069
1084
1070
- azx_stop_chip (chip );
1071
- azx_enter_link_reset (chip );
1072
- azx_clear_irq_pending (chip );
1073
- if ((chip -> driver_caps & AZX_DCAPS_I915_POWERWELL )
1074
- && hda -> need_i915_power )
1075
- snd_hdac_display_power (azx_bus (chip ), false);
1076
-
1085
+ __azx_runtime_suspend (chip );
1077
1086
trace_azx_runtime_suspend (chip );
1078
1087
return 0 ;
1079
1088
}
@@ -1082,51 +1091,18 @@ static int azx_runtime_resume(struct device *dev)
1082
1091
{
1083
1092
struct snd_card * card = dev_get_drvdata (dev );
1084
1093
struct azx * chip ;
1085
- struct hda_intel * hda ;
1086
- struct hdac_bus * bus ;
1087
- struct hda_codec * codec ;
1088
- int status ;
1089
1094
1090
- if (!card )
1095
+ if (!azx_is_pm_ready ( card ) )
1091
1096
return 0 ;
1092
-
1093
1097
chip = card -> private_data ;
1094
- hda = container_of (chip , struct hda_intel , chip );
1095
- bus = azx_bus (chip );
1096
- if (chip -> disabled || hda -> init_failed )
1097
- return 0 ;
1098
-
1099
1098
if (!azx_has_pm_runtime (chip ))
1100
1099
return 0 ;
1101
-
1102
- if (chip -> driver_caps & AZX_DCAPS_I915_POWERWELL ) {
1103
- snd_hdac_display_power (bus , true);
1104
- if (hda -> need_i915_power )
1105
- snd_hdac_i915_set_bclk (bus );
1106
- }
1107
-
1108
- /* Read STATESTS before controller reset */
1109
- status = azx_readw (chip , STATESTS );
1110
-
1111
- azx_init_pci (chip );
1112
- hda_intel_init_chip (chip , true);
1113
-
1114
- if (status ) {
1115
- list_for_each_codec (codec , & chip -> bus )
1116
- if (status & (1 << codec -> addr ))
1117
- schedule_delayed_work (& codec -> jackpoll_work ,
1118
- codec -> jackpoll_interval );
1119
- }
1100
+ __azx_runtime_resume (chip );
1120
1101
1121
1102
/* disable controller Wake Up event*/
1122
1103
azx_writew (chip , WAKEEN , azx_readw (chip , WAKEEN ) &
1123
1104
~STATESTS_INT_MASK );
1124
1105
1125
- /* power down again for link-controlled chips */
1126
- if ((chip -> driver_caps & AZX_DCAPS_I915_POWERWELL ) &&
1127
- !hda -> need_i915_power )
1128
- snd_hdac_display_power (bus , false);
1129
-
1130
1106
trace_azx_runtime_resume (chip );
1131
1107
return 0 ;
1132
1108
}
@@ -1167,6 +1143,8 @@ static const struct dev_pm_ops azx_pm = {
1167
1143
1168
1144
#define AZX_PM_OPS &azx_pm
1169
1145
#else
1146
+ #define azx_add_card_list (chip ) /* NOP */
1147
+ #define azx_del_card_list (chip ) /* NOP */
1170
1148
#define AZX_PM_OPS NULL
1171
1149
#endif /* CONFIG_PM */
1172
1150
0 commit comments