@@ -1206,7 +1206,7 @@ static void snd_hda_codec_free(struct hda_codec *codec)
1206
1206
if (codec -> patch_ops .free )
1207
1207
codec -> patch_ops .free (codec );
1208
1208
#ifdef CONFIG_PM
1209
- if (codec -> power_on )
1209
+ if (! codec -> pm_down_notified ) /* cancel leftover refcounts */
1210
1210
hda_call_pm_notify (codec -> bus , false);
1211
1211
#endif
1212
1212
module_put (codec -> owner );
@@ -1222,7 +1222,7 @@ static void snd_hda_codec_free(struct hda_codec *codec)
1222
1222
static bool snd_hda_codec_get_supported_ps (struct hda_codec * codec ,
1223
1223
hda_nid_t fg , unsigned int power_state );
1224
1224
1225
- static void hda_set_power_state (struct hda_codec * codec , hda_nid_t fg ,
1225
+ static unsigned int hda_set_power_state (struct hda_codec * codec , hda_nid_t fg ,
1226
1226
unsigned int power_state );
1227
1227
1228
1228
/**
@@ -3564,18 +3564,14 @@ static unsigned int hda_sync_power_state(struct hda_codec *codec,
3564
3564
}
3565
3565
3566
3566
/*
3567
- * set power state of the codec
3567
+ * set power state of the codec, and return the power state
3568
3568
*/
3569
- static void hda_set_power_state (struct hda_codec * codec , hda_nid_t fg ,
3570
- unsigned int power_state )
3569
+ static unsigned int hda_set_power_state (struct hda_codec * codec , hda_nid_t fg ,
3570
+ unsigned int power_state )
3571
3571
{
3572
3572
int count ;
3573
3573
unsigned int state ;
3574
3574
3575
- #ifdef CONFIG_PM
3576
- codec -> d3_stop_clk_ok = 0 ;
3577
- #endif
3578
-
3579
3575
/* this delay seems necessary to avoid click noise at power-down */
3580
3576
if (power_state == AC_PWRST_D3 ) {
3581
3577
/* transition time less than 10ms for power down */
@@ -3599,11 +3595,7 @@ static void hda_set_power_state(struct hda_codec *codec, hda_nid_t fg,
3599
3595
break ;
3600
3596
}
3601
3597
3602
- #ifdef CONFIG_PM
3603
- if (!codec -> bus -> power_keep_link_on && power_state == AC_PWRST_D3
3604
- && codec -> d3_stop_clk && (state & AC_PWRST_CLK_STOP_OK ))
3605
- codec -> d3_stop_clk_ok = 1 ;
3606
- #endif
3598
+ return state ;
3607
3599
}
3608
3600
3609
3601
#ifdef CONFIG_SND_HDA_HWDEP
@@ -3620,13 +3612,16 @@ static inline void hda_exec_init_verbs(struct hda_codec *codec) {}
3620
3612
#ifdef CONFIG_PM
3621
3613
/*
3622
3614
* call suspend and power-down; used both from PM and power-save
3615
+ * this function returns the power state in the end
3623
3616
*/
3624
- static void hda_call_codec_suspend (struct hda_codec * codec )
3617
+ static unsigned int hda_call_codec_suspend (struct hda_codec * codec )
3625
3618
{
3619
+ unsigned int state ;
3620
+
3626
3621
if (codec -> patch_ops .suspend )
3627
3622
codec -> patch_ops .suspend (codec );
3628
3623
hda_cleanup_all_streams (codec );
3629
- hda_set_power_state (codec ,
3624
+ state = hda_set_power_state (codec ,
3630
3625
codec -> afg ? codec -> afg : codec -> mfg ,
3631
3626
AC_PWRST_D3 );
3632
3627
cancel_delayed_work (& codec -> power_work );
@@ -3637,6 +3632,7 @@ static void hda_call_codec_suspend(struct hda_codec *codec)
3637
3632
codec -> power_transition = 0 ;
3638
3633
codec -> power_jiffies = jiffies ;
3639
3634
spin_unlock (& codec -> power_lock );
3635
+ return state ;
3640
3636
}
3641
3637
3642
3638
/*
@@ -4438,6 +4434,7 @@ static void hda_power_work(struct work_struct *work)
4438
4434
struct hda_codec * codec =
4439
4435
container_of (work , struct hda_codec , power_work .work );
4440
4436
struct hda_bus * bus = codec -> bus ;
4437
+ unsigned int state ;
4441
4438
4442
4439
spin_lock (& codec -> power_lock );
4443
4440
if (codec -> power_transition > 0 ) { /* during power-up sequence? */
@@ -4451,9 +4448,12 @@ static void hda_power_work(struct work_struct *work)
4451
4448
}
4452
4449
spin_unlock (& codec -> power_lock );
4453
4450
4454
- hda_call_codec_suspend (codec );
4455
- if (codec -> d3_stop_clk_ok )
4451
+ state = hda_call_codec_suspend (codec );
4452
+ codec -> pm_down_notified = 0 ;
4453
+ if (!bus -> power_keep_link_on && (state & AC_PWRST_CLK_STOP_OK )) {
4454
+ codec -> pm_down_notified = 1 ;
4456
4455
hda_call_pm_notify (bus , false);
4456
+ }
4457
4457
}
4458
4458
4459
4459
static void hda_keep_power_on (struct hda_codec * codec )
@@ -4510,8 +4510,11 @@ static void __snd_hda_power_up(struct hda_codec *codec, bool wait_power_down)
4510
4510
codec -> power_transition = 1 ; /* avoid reentrance */
4511
4511
spin_unlock (& codec -> power_lock );
4512
4512
4513
- if (codec -> d3_stop_clk_ok ) /* flag set at suspend */
4513
+ if (codec -> pm_down_notified ) {
4514
+ codec -> pm_down_notified = 0 ;
4514
4515
hda_call_pm_notify (bus , true);
4516
+ }
4517
+
4515
4518
hda_call_codec_resume (codec );
4516
4519
4517
4520
spin_lock (& codec -> power_lock );
0 commit comments