Skip to content

Commit 3baffc4

Browse files
committed
ALSA: hda/intel: Refactoring PM code
Make unified suspend / resume helpers and call them from both the runtime- and the system-PM callbacks for simplifying code. There are slight changes of call orders, but there shouldn't be any functional difference after refactoring. Signed-off-by: Takashi Iwai <tiwai@suse.de>
1 parent fa9c98e commit 3baffc4

File tree

1 file changed

+69
-91
lines changed

1 file changed

+69
-91
lines changed

sound/pci/hda/hda_intel.c

Lines changed: 69 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -930,87 +930,109 @@ static int param_set_xint(const char *val, const struct kernel_param *kp)
930930
mutex_unlock(&card_list_lock);
931931
return 0;
932932
}
933-
#else
934-
#define azx_add_card_list(chip) /* NOP */
935-
#define azx_del_card_list(chip) /* NOP */
936-
#endif /* CONFIG_PM */
937933

938-
#ifdef CONFIG_PM_SLEEP
939934
/*
940935
* power management
941936
*/
942-
static int azx_suspend(struct device *dev)
937+
static bool azx_is_pm_ready(struct snd_card *card)
943938
{
944-
struct snd_card *card = dev_get_drvdata(dev);
945939
struct azx *chip;
946940
struct hda_intel *hda;
947-
struct hdac_bus *bus;
948941

949942
if (!card)
950-
return 0;
951-
943+
return false;
952944
chip = card->private_data;
953945
hda = container_of(chip, struct hda_intel, chip);
954946
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))
9551003
return 0;
9561004

1005+
chip = card->private_data;
9571006
bus = azx_bus(chip);
9581007
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);
9621009
if (bus->irq >= 0) {
9631010
free_irq(bus->irq, chip);
9641011
bus->irq = -1;
9651012
}
9661013

9671014
if (chip->msi)
9681015
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);
9721016

9731017
trace_azx_suspend(chip);
9741018
return 0;
9751019
}
9761020

9771021
static int azx_resume(struct device *dev)
9781022
{
979-
struct pci_dev *pci = to_pci_dev(dev);
9801023
struct snd_card *card = dev_get_drvdata(dev);
9811024
struct azx *chip;
982-
struct hda_intel *hda;
983-
struct hdac_bus *bus;
9841025

985-
if (!card)
1026+
if (!azx_is_pm_ready(card))
9861027
return 0;
9871028

9881029
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-
10001030
if (chip->msi)
1001-
if (pci_enable_msi(pci) < 0)
1031+
if (pci_enable_msi(chip->pci) < 0)
10021032
chip->msi = 0;
10031033
if (azx_acquire_irq(chip, 1) < 0)
10041034
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);
10141036
snd_power_change_state(card, SNDRV_CTL_POWER_D0);
10151037

10161038
trace_azx_resume(chip);
@@ -1045,35 +1067,22 @@ static int azx_thaw_noirq(struct device *dev)
10451067
}
10461068
#endif /* CONFIG_PM_SLEEP */
10471069

1048-
#ifdef CONFIG_PM
10491070
static int azx_runtime_suspend(struct device *dev)
10501071
{
10511072
struct snd_card *card = dev_get_drvdata(dev);
10521073
struct azx *chip;
1053-
struct hda_intel *hda;
10541074

1055-
if (!card)
1075+
if (!azx_is_pm_ready(card))
10561076
return 0;
1057-
10581077
chip = card->private_data;
1059-
hda = container_of(chip, struct hda_intel, chip);
1060-
if (chip->disabled || hda->init_failed)
1061-
return 0;
1062-
10631078
if (!azx_has_pm_runtime(chip))
10641079
return 0;
10651080

10661081
/* enable controller wake up event */
10671082
azx_writew(chip, WAKEEN, azx_readw(chip, WAKEEN) |
10681083
STATESTS_INT_MASK);
10691084

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);
10771086
trace_azx_runtime_suspend(chip);
10781087
return 0;
10791088
}
@@ -1082,51 +1091,18 @@ static int azx_runtime_resume(struct device *dev)
10821091
{
10831092
struct snd_card *card = dev_get_drvdata(dev);
10841093
struct azx *chip;
1085-
struct hda_intel *hda;
1086-
struct hdac_bus *bus;
1087-
struct hda_codec *codec;
1088-
int status;
10891094

1090-
if (!card)
1095+
if (!azx_is_pm_ready(card))
10911096
return 0;
1092-
10931097
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-
10991098
if (!azx_has_pm_runtime(chip))
11001099
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);
11201101

11211102
/* disable controller Wake Up event*/
11221103
azx_writew(chip, WAKEEN, azx_readw(chip, WAKEEN) &
11231104
~STATESTS_INT_MASK);
11241105

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-
11301106
trace_azx_runtime_resume(chip);
11311107
return 0;
11321108
}
@@ -1167,6 +1143,8 @@ static const struct dev_pm_ops azx_pm = {
11671143

11681144
#define AZX_PM_OPS &azx_pm
11691145
#else
1146+
#define azx_add_card_list(chip) /* NOP */
1147+
#define azx_del_card_list(chip) /* NOP */
11701148
#define AZX_PM_OPS NULL
11711149
#endif /* CONFIG_PM */
11721150

0 commit comments

Comments
 (0)