Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 170328
b: refs/heads/master
c: 13dab08
h: refs/heads/master
v: v3
  • Loading branch information
Jaroslav Kysela authored and Takashi Iwai committed Nov 16, 2009
1 parent b54719a commit b4bde37
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 17 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 123c07aeddd71fbb295842a8c19866e780b9a100
refs/heads/master: 13dab0808bb41b18888e1758a060a685deee1f30
42 changes: 27 additions & 15 deletions trunk/sound/pci/hda/hda_beep.c
Original file line number Diff line number Diff line change
Expand Up @@ -164,30 +164,41 @@ static void snd_hda_do_register(struct work_struct *work)
{
struct hda_beep *beep =
container_of(work, struct hda_beep, register_work);
int request;

mutex_lock(&beep->mutex);
request = beep->request_enable;
if (beep->enabled != request) {
if (!request) {
snd_hda_do_detach(beep);
} else {
if (snd_hda_do_attach(beep) < 0)
goto __out;
}
beep->enabled = request;
}
__out:
if (beep->enabled && !beep->dev)
snd_hda_do_attach(beep);
mutex_unlock(&beep->mutex);
}

static void snd_hda_do_unregister(struct work_struct *work)
{
struct hda_beep *beep =
container_of(work, struct hda_beep, unregister_work.work);

mutex_lock(&beep->mutex);
if (!beep->enabled && beep->dev)
snd_hda_do_detach(beep);
mutex_unlock(&beep->mutex);
}

int snd_hda_enable_beep_device(struct hda_codec *codec, int enable)
{
struct hda_beep *beep = codec->beep;
enable = !!enable;
if (beep && beep->enabled != enable) {
beep->request_enable = enable;
schedule_work(&beep->register_work);
if (beep == NULL)
return 0;
if (beep->enabled != enable) {
beep->enabled = enable;
if (enable) {
cancel_delayed_work(&beep->unregister_work);
schedule_work(&beep->register_work);
} else {
/* turn off beep */
snd_hda_codec_write_cache(beep->codec, beep->nid, 0,
AC_VERB_SET_BEEP_CONTROL, 0);
schedule_delayed_work(&beep->unregister_work, HZ);
}
return 1;
}
return 0;
Expand Down Expand Up @@ -215,6 +226,7 @@ int snd_hda_attach_beep_device(struct hda_codec *codec, int nid)
codec->beep = beep;

INIT_WORK(&beep->register_work, &snd_hda_do_register);
INIT_DELAYED_WORK(&beep->unregister_work, &snd_hda_do_unregister);
INIT_WORK(&beep->beep_work, &snd_hda_generate_beep);
mutex_init(&beep->mutex);

Expand Down
3 changes: 2 additions & 1 deletion trunk/sound/pci/hda/hda_beep.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ struct hda_beep {
unsigned int enabled:1;
unsigned int request_enable:1;
unsigned int linear_tone:1; /* linear tone for IDT/STAC codec */
struct work_struct register_work; /* scheduled task for beep event */
struct work_struct register_work; /* registration work */
struct delayed_work unregister_work; /* unregistration work */
struct work_struct beep_work; /* scheduled task for beep event */
struct mutex mutex;
};
Expand Down

0 comments on commit b4bde37

Please sign in to comment.