ALSA: hda - add beep_mode module parameter

The beep_mode parameter for snd-hda-intel module allows to choose among
different digital beep device registation to the input layer.

0 = do not register to the input layer
1 = register to the input layer all time
2 = use "Beep Switch" control exported to user space mixer applications

Also, introduce CONFIG_SND_HDA_INPUT_BEEP_MODE for default value.

Signed-off-by: Jaroslav Kysela <perex@perex.cz>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
diff --git a/sound/pci/hda/hda_beep.c b/sound/pci/hda/hda_beep.c
index c819152..9e48798 100644
--- a/sound/pci/hda/hda_beep.c
+++ b/sound/pci/hda/hda_beep.c
@@ -190,14 +190,19 @@
 		return 0;
 	if (beep->enabled != enable) {
 		beep->enabled = enable;
-		if (enable) {
-			cancel_delayed_work(&beep->unregister_work);
-			schedule_work(&beep->register_work);
-		} else {
+		if (!enable) {
 			/* 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);
+		}
+		if (beep->mode == HDA_BEEP_MODE_SWREG) {
+			if (enable) {
+				cancel_delayed_work(&beep->unregister_work);
+				schedule_work(&beep->register_work);
+			} else {
+				schedule_delayed_work(&beep->unregister_work,
+									   HZ);
+			}
 		}
 		return 1;
 	}
@@ -223,6 +228,7 @@
 
 	beep->nid = nid;
 	beep->codec = codec;
+	beep->mode = codec->beep_mode;
 	codec->beep = beep;
 
 	INIT_WORK(&beep->register_work, &snd_hda_do_register);
@@ -230,6 +236,11 @@
 	INIT_WORK(&beep->beep_work, &snd_hda_generate_beep);
 	mutex_init(&beep->mutex);
 
+	if (beep->mode == HDA_BEEP_MODE_ON) {
+		beep->enabled = 1;
+		snd_hda_do_register(&beep->register_work);
+	}
+
 	return 0;
 }
 EXPORT_SYMBOL_HDA(snd_hda_attach_beep_device);