mirror of
git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2025-09-04 20:19:47 +08:00
ALSA: hda - Fix power-saving during playing beep sound
While playing the digital beep tone, the codec shouldn't be turned off. This patch adds proper snd_hda_power_up()/down() calls at each time when the beep is played or off. Also, this fixes automatically an unnecessary codec power-up at detaching the beep device when the beep isn't being played. Signed-off-by: Takashi Iwai <tiwai@suse.de>
This commit is contained in:
parent
7504b6cd22
commit
e914b25e37
@ -39,13 +39,23 @@ static void snd_hda_generate_beep(struct work_struct *work)
|
|||||||
struct hda_beep *beep =
|
struct hda_beep *beep =
|
||||||
container_of(work, struct hda_beep, beep_work);
|
container_of(work, struct hda_beep, beep_work);
|
||||||
struct hda_codec *codec = beep->codec;
|
struct hda_codec *codec = beep->codec;
|
||||||
|
int tone;
|
||||||
|
|
||||||
if (!beep->enabled)
|
if (!beep->enabled)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
tone = beep->tone;
|
||||||
|
if (tone && !beep->playing) {
|
||||||
|
snd_hda_power_up(codec);
|
||||||
|
beep->playing = 1;
|
||||||
|
}
|
||||||
/* generate tone */
|
/* generate tone */
|
||||||
snd_hda_codec_write(codec, beep->nid, 0,
|
snd_hda_codec_write(codec, beep->nid, 0,
|
||||||
AC_VERB_SET_BEEP_CONTROL, beep->tone);
|
AC_VERB_SET_BEEP_CONTROL, tone);
|
||||||
|
if (!tone && beep->playing) {
|
||||||
|
beep->playing = 0;
|
||||||
|
snd_hda_power_down(codec);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-standard) Linear beep tone calculation for IDT/STAC codecs
|
/* (non-standard) Linear beep tone calculation for IDT/STAC codecs
|
||||||
@ -115,14 +125,23 @@ static int snd_hda_beep_event(struct input_dev *dev, unsigned int type,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void turn_off_beep(struct hda_beep *beep)
|
||||||
|
{
|
||||||
|
cancel_work_sync(&beep->beep_work);
|
||||||
|
if (beep->playing) {
|
||||||
|
/* turn off beep */
|
||||||
|
snd_hda_codec_write(beep->codec, beep->nid, 0,
|
||||||
|
AC_VERB_SET_BEEP_CONTROL, 0);
|
||||||
|
beep->playing = 0;
|
||||||
|
snd_hda_power_down(beep->codec);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static void snd_hda_do_detach(struct hda_beep *beep)
|
static void snd_hda_do_detach(struct hda_beep *beep)
|
||||||
{
|
{
|
||||||
input_unregister_device(beep->dev);
|
input_unregister_device(beep->dev);
|
||||||
beep->dev = NULL;
|
beep->dev = NULL;
|
||||||
cancel_work_sync(&beep->beep_work);
|
turn_off_beep(beep);
|
||||||
/* turn off beep for sure */
|
|
||||||
snd_hda_codec_write(beep->codec, beep->nid, 0,
|
|
||||||
AC_VERB_SET_BEEP_CONTROL, 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int snd_hda_do_attach(struct hda_beep *beep)
|
static int snd_hda_do_attach(struct hda_beep *beep)
|
||||||
@ -170,12 +189,8 @@ int snd_hda_enable_beep_device(struct hda_codec *codec, int enable)
|
|||||||
enable = !!enable;
|
enable = !!enable;
|
||||||
if (beep->enabled != enable) {
|
if (beep->enabled != enable) {
|
||||||
beep->enabled = enable;
|
beep->enabled = enable;
|
||||||
if (!enable) {
|
if (!enable)
|
||||||
cancel_work_sync(&beep->beep_work);
|
turn_off_beep(beep);
|
||||||
/* turn off beep */
|
|
||||||
snd_hda_codec_write(beep->codec, beep->nid, 0,
|
|
||||||
AC_VERB_SET_BEEP_CONTROL, 0);
|
|
||||||
}
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -36,6 +36,7 @@ struct hda_beep {
|
|||||||
hda_nid_t nid;
|
hda_nid_t nid;
|
||||||
unsigned int enabled:1;
|
unsigned int enabled:1;
|
||||||
unsigned int linear_tone:1; /* linear tone for IDT/STAC codec */
|
unsigned int linear_tone:1; /* linear tone for IDT/STAC codec */
|
||||||
|
unsigned int playing:1;
|
||||||
struct work_struct beep_work; /* scheduled task for beep event */
|
struct work_struct beep_work; /* scheduled task for beep event */
|
||||||
struct mutex mutex;
|
struct mutex mutex;
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user