@@ -1027,7 +1027,7 @@ static int azx_suspend(struct device *dev)
1027
1027
chip = card -> private_data ;
1028
1028
bus = azx_bus (chip );
1029
1029
snd_power_change_state (card , SNDRV_CTL_POWER_D3hot );
1030
- __azx_runtime_suspend ( chip );
1030
+ pm_runtime_force_suspend ( dev );
1031
1031
if (bus -> irq >= 0 ) {
1032
1032
free_irq (bus -> irq , chip );
1033
1033
bus -> irq = -1 ;
@@ -1044,7 +1044,9 @@ static int azx_suspend(struct device *dev)
1044
1044
static int azx_resume (struct device * dev )
1045
1045
{
1046
1046
struct snd_card * card = dev_get_drvdata (dev );
1047
+ struct hda_codec * codec ;
1047
1048
struct azx * chip ;
1049
+ bool forced_resume = false;
1048
1050
1049
1051
if (!azx_is_pm_ready (card ))
1050
1052
return 0 ;
@@ -1055,7 +1057,20 @@ static int azx_resume(struct device *dev)
1055
1057
chip -> msi = 0 ;
1056
1058
if (azx_acquire_irq (chip , 1 ) < 0 )
1057
1059
return - EIO ;
1058
- __azx_runtime_resume (chip , false);
1060
+
1061
+ /* check for the forced resume */
1062
+ list_for_each_codec (codec , & chip -> bus ) {
1063
+ if (hda_codec_need_resume (codec )) {
1064
+ forced_resume = true;
1065
+ break ;
1066
+ }
1067
+ }
1068
+
1069
+ if (forced_resume )
1070
+ pm_runtime_get_noresume (dev );
1071
+ pm_runtime_force_resume (dev );
1072
+ if (forced_resume )
1073
+ pm_runtime_put (dev );
1059
1074
snd_power_change_state (card , SNDRV_CTL_POWER_D0 );
1060
1075
1061
1076
trace_azx_resume (chip );
@@ -1071,6 +1086,8 @@ static int azx_freeze_noirq(struct device *dev)
1071
1086
struct azx * chip = card -> private_data ;
1072
1087
struct pci_dev * pci = to_pci_dev (dev );
1073
1088
1089
+ if (!azx_is_pm_ready (card ))
1090
+ return 0 ;
1074
1091
if (chip -> driver_type == AZX_DRIVER_SKL )
1075
1092
pci_set_power_state (pci , PCI_D3hot );
1076
1093
@@ -1083,6 +1100,8 @@ static int azx_thaw_noirq(struct device *dev)
1083
1100
struct azx * chip = card -> private_data ;
1084
1101
struct pci_dev * pci = to_pci_dev (dev );
1085
1102
1103
+ if (!azx_is_pm_ready (card ))
1104
+ return 0 ;
1086
1105
if (chip -> driver_type == AZX_DRIVER_SKL )
1087
1106
pci_set_power_state (pci , PCI_D0 );
1088
1107
@@ -1098,12 +1117,12 @@ static int azx_runtime_suspend(struct device *dev)
1098
1117
if (!azx_is_pm_ready (card ))
1099
1118
return 0 ;
1100
1119
chip = card -> private_data ;
1101
- if (!azx_has_pm_runtime (chip ))
1102
- return 0 ;
1103
1120
1104
1121
/* enable controller wake up event */
1105
- azx_writew (chip , WAKEEN , azx_readw (chip , WAKEEN ) |
1106
- STATESTS_INT_MASK );
1122
+ if (snd_power_get_state (card ) == SNDRV_CTL_POWER_D0 ) {
1123
+ azx_writew (chip , WAKEEN , azx_readw (chip , WAKEEN ) |
1124
+ STATESTS_INT_MASK );
1125
+ }
1107
1126
1108
1127
__azx_runtime_suspend (chip );
1109
1128
trace_azx_runtime_suspend (chip );
@@ -1114,17 +1133,18 @@ static int azx_runtime_resume(struct device *dev)
1114
1133
{
1115
1134
struct snd_card * card = dev_get_drvdata (dev );
1116
1135
struct azx * chip ;
1136
+ bool from_rt = snd_power_get_state (card ) == SNDRV_CTL_POWER_D0 ;
1117
1137
1118
1138
if (!azx_is_pm_ready (card ))
1119
1139
return 0 ;
1120
1140
chip = card -> private_data ;
1121
- if (!azx_has_pm_runtime (chip ))
1122
- return 0 ;
1123
- __azx_runtime_resume (chip , true);
1141
+ __azx_runtime_resume (chip , from_rt );
1124
1142
1125
1143
/* disable controller Wake Up event*/
1126
- azx_writew (chip , WAKEEN , azx_readw (chip , WAKEEN ) &
1127
- ~STATESTS_INT_MASK );
1144
+ if (from_rt ) {
1145
+ azx_writew (chip , WAKEEN , azx_readw (chip , WAKEEN ) &
1146
+ ~STATESTS_INT_MASK );
1147
+ }
1128
1148
1129
1149
trace_azx_runtime_resume (chip );
1130
1150
return 0 ;
@@ -1199,10 +1219,8 @@ static void azx_vs_set_state(struct pci_dev *pci,
1199
1219
if (!disabled ) {
1200
1220
dev_info (chip -> card -> dev ,
1201
1221
"Start delayed initialization\n" );
1202
- if (azx_probe_continue (chip ) < 0 ) {
1222
+ if (azx_probe_continue (chip ) < 0 )
1203
1223
dev_err (chip -> card -> dev , "initialization error\n" );
1204
- hda -> init_failed = true;
1205
- }
1206
1224
}
1207
1225
} else {
1208
1226
dev_info (chip -> card -> dev , "%s via vga_switcheroo\n" ,
@@ -1335,12 +1353,15 @@ static int register_vga_switcheroo(struct azx *chip)
1335
1353
/*
1336
1354
* destructor
1337
1355
*/
1338
- static int azx_free (struct azx * chip )
1356
+ static void azx_free (struct azx * chip )
1339
1357
{
1340
1358
struct pci_dev * pci = chip -> pci ;
1341
1359
struct hda_intel * hda = container_of (chip , struct hda_intel , chip );
1342
1360
struct hdac_bus * bus = azx_bus (chip );
1343
1361
1362
+ if (hda -> freed )
1363
+ return ;
1364
+
1344
1365
if (azx_has_pm_runtime (chip ) && chip -> running )
1345
1366
pm_runtime_get_noresume (& pci -> dev );
1346
1367
chip -> running = 0 ;
@@ -1384,9 +1405,8 @@ static int azx_free(struct azx *chip)
1384
1405
1385
1406
if (chip -> driver_caps & AZX_DCAPS_I915_COMPONENT )
1386
1407
snd_hdac_i915_exit (bus );
1387
- kfree (hda );
1388
1408
1389
- return 0 ;
1409
+ hda -> freed = 1 ;
1390
1410
}
1391
1411
1392
1412
static int azx_dev_disconnect (struct snd_device * device )
@@ -1402,7 +1422,8 @@ static int azx_dev_disconnect(struct snd_device *device)
1402
1422
1403
1423
static int azx_dev_free (struct snd_device * device )
1404
1424
{
1405
- return azx_free (device -> device_data );
1425
+ azx_free (device -> device_data );
1426
+ return 0 ;
1406
1427
}
1407
1428
1408
1429
#ifdef SUPPORT_VGA_SWITCHEROO
@@ -1769,7 +1790,7 @@ static int azx_create(struct snd_card *card, struct pci_dev *pci,
1769
1790
if (err < 0 )
1770
1791
return err ;
1771
1792
1772
- hda = kzalloc ( sizeof (* hda ), GFP_KERNEL );
1793
+ hda = devm_kzalloc ( & pci -> dev , sizeof (* hda ), GFP_KERNEL );
1773
1794
if (!hda ) {
1774
1795
pci_disable_device (pci );
1775
1796
return - ENOMEM ;
@@ -1810,7 +1831,6 @@ static int azx_create(struct snd_card *card, struct pci_dev *pci,
1810
1831
1811
1832
err = azx_bus_init (chip , model [dev ]);
1812
1833
if (err < 0 ) {
1813
- kfree (hda );
1814
1834
pci_disable_device (pci );
1815
1835
return err ;
1816
1836
}
@@ -2005,7 +2025,7 @@ static int azx_first_init(struct azx *chip)
2005
2025
/* codec detection */
2006
2026
if (!azx_bus (chip )-> codec_mask ) {
2007
2027
dev_err (card -> dev , "no codecs found!\n" );
2008
- return - ENODEV ;
2028
+ /* keep running the rest for the runtime PM */
2009
2029
}
2010
2030
2011
2031
if (azx_acquire_irq (chip , 0 ) < 0 )
@@ -2027,24 +2047,15 @@ static void azx_firmware_cb(const struct firmware *fw, void *context)
2027
2047
{
2028
2048
struct snd_card * card = context ;
2029
2049
struct azx * chip = card -> private_data ;
2030
- struct pci_dev * pci = chip -> pci ;
2031
-
2032
- if (!fw ) {
2033
- dev_err (card -> dev , "Cannot load firmware, aborting\n" );
2034
- goto error ;
2035
- }
2036
2050
2037
- chip -> fw = fw ;
2051
+ if (fw )
2052
+ chip -> fw = fw ;
2053
+ else
2054
+ dev_err (card -> dev , "Cannot load firmware, continue without patching\n" );
2038
2055
if (!chip -> disabled ) {
2039
2056
/* continue probing */
2040
- if (azx_probe_continue (chip ))
2041
- goto error ;
2057
+ azx_probe_continue (chip );
2042
2058
}
2043
- return ; /* OK */
2044
-
2045
- error :
2046
- snd_card_free (card );
2047
- pci_set_drvdata (pci , NULL );
2048
2059
}
2049
2060
#endif
2050
2061
@@ -2308,9 +2319,11 @@ static int azx_probe_continue(struct azx *chip)
2308
2319
#endif
2309
2320
2310
2321
/* create codec instances */
2311
- err = azx_probe_codecs (chip , azx_max_codecs [chip -> driver_type ]);
2312
- if (err < 0 )
2313
- goto out_free ;
2322
+ if (bus -> codec_mask ) {
2323
+ err = azx_probe_codecs (chip , azx_max_codecs [chip -> driver_type ]);
2324
+ if (err < 0 )
2325
+ goto out_free ;
2326
+ }
2314
2327
2315
2328
#ifdef CONFIG_SND_HDA_PATCH_LOADER
2316
2329
if (chip -> fw ) {
@@ -2324,7 +2337,7 @@ static int azx_probe_continue(struct azx *chip)
2324
2337
#endif
2325
2338
}
2326
2339
#endif
2327
- if ((probe_only [dev ] & 1 ) == 0 ) {
2340
+ if (bus -> codec_mask && ! (probe_only [dev ] & 1 )) {
2328
2341
err = azx_codec_configure (chip );
2329
2342
if (err < 0 )
2330
2343
goto out_free ;
@@ -2341,17 +2354,23 @@ static int azx_probe_continue(struct azx *chip)
2341
2354
2342
2355
set_default_power_save (chip );
2343
2356
2344
- if (azx_has_pm_runtime (chip ))
2357
+ if (azx_has_pm_runtime (chip )) {
2358
+ pm_runtime_use_autosuspend (& pci -> dev );
2359
+ pm_runtime_allow (& pci -> dev );
2345
2360
pm_runtime_put_autosuspend (& pci -> dev );
2361
+ }
2346
2362
2347
2363
out_free :
2348
- if (err < 0 || !hda -> need_i915_power )
2364
+ if (err < 0 ) {
2365
+ azx_free (chip );
2366
+ return err ;
2367
+ }
2368
+
2369
+ if (!hda -> need_i915_power )
2349
2370
display_power (chip , false);
2350
- if (err < 0 )
2351
- hda -> init_failed = 1 ;
2352
2371
complete_all (& hda -> probe_wait );
2353
2372
to_hda_bus (bus )-> bus_probing = 0 ;
2354
- return err ;
2373
+ return 0 ;
2355
2374
}
2356
2375
2357
2376
static void azx_remove (struct pci_dev * pci )
0 commit comments