]> git.proxmox.com Git - mirror_ubuntu-eoan-kernel.git/commitdiff
ALSA: jack: extend snd_jack_new to support phantom jack
authorJie Yang <yang.jie@intel.com>
Mon, 27 Apr 2015 13:20:58 +0000 (21:20 +0800)
committerTakashi Iwai <tiwai@suse.de>
Mon, 27 Apr 2015 19:37:41 +0000 (21:37 +0200)
Dont create input devices for phantom jacks.

Here, we extend snd_jack_new() to support phantom jack creating:
pass in a bool param for [non-]phantom flag, and a bool param
initial_jack to indicate whether we need to create a kctl at
this stage.

We can also add a kctl to the jack after its created meaning we
can now integrate the HDA and ASoC jacks.

Signed-off-by: Jie Yang <yang.jie@intel.com>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
include/sound/jack.h
sound/core/jack.c
sound/pci/hda/hda_jack.c
sound/pci/oxygen/xonar_wm87x6.c
sound/soc/soc-jack.c

index 433b13b891259af8ae7940377f02f588629edf11..23bede121c78b97cd0df352d9aeb2fb36a148f85 100644 (file)
@@ -87,7 +87,7 @@ struct snd_jack {
 #ifdef CONFIG_SND_JACK
 
 int snd_jack_new(struct snd_card *card, const char *id, int type,
-                struct snd_jack **jack);
+                struct snd_jack **jack, bool initial_kctl, bool phantom_jack);
 int snd_jack_add_new_kctl(struct snd_jack *jack, const char * name, int mask);
 void snd_jack_set_parent(struct snd_jack *jack, struct device *parent);
 int snd_jack_set_key(struct snd_jack *jack, enum snd_jack_types type,
@@ -97,7 +97,7 @@ void snd_jack_report(struct snd_jack *jack, int status);
 
 #else
 static inline int snd_jack_new(struct snd_card *card, const char *id, int type,
-                              struct snd_jack **jack)
+                              struct snd_jack **jack, bool initial_kctl, bool phantom_jack)
 {
        return 0;
 }
index 067d37d14e640c5313545b5b88be85b7fa5da12d..b34187b072ea6a1370d1fab4095b3d096256e76b 100644 (file)
@@ -191,6 +191,8 @@ EXPORT_SYMBOL(snd_jack_add_new_kctl);
  * @type:  a bitmask of enum snd_jack_type values that can be detected by
  *         this jack
  * @jjack: Used to provide the allocated jack object to the caller.
+ * @initial_kctl: if true, create a kcontrol and add it to the jack list.
+ * @phantom_jack: Don't create a input device for phantom jacks.
  *
  * Creates a new jack object.
  *
@@ -198,9 +200,10 @@ EXPORT_SYMBOL(snd_jack_add_new_kctl);
  * On success @jjack will be initialised.
  */
 int snd_jack_new(struct snd_card *card, const char *id, int type,
-                struct snd_jack **jjack)
+                struct snd_jack **jjack, bool initial_kctl, bool phantom_jack)
 {
        struct snd_jack *jack;
+       struct snd_jack_kctl *jack_kctl = NULL;
        int err;
        int i;
        static struct snd_device_ops ops = {
@@ -209,26 +212,36 @@ int snd_jack_new(struct snd_card *card, const char *id, int type,
                .dev_disconnect = snd_jack_dev_disconnect,
        };
 
+       if (initial_kctl) {
+               jack_kctl = snd_jack_kctl_new(card, id, type);
+               if (!jack_kctl)
+                       return -ENOMEM;
+       }
+
        jack = kzalloc(sizeof(struct snd_jack), GFP_KERNEL);
        if (jack == NULL)
                return -ENOMEM;
 
        jack->id = kstrdup(id, GFP_KERNEL);
 
-       jack->input_dev = input_allocate_device();
-       if (jack->input_dev == NULL) {
-               err = -ENOMEM;
-               goto fail_input;
-       }
+       /* don't creat input device for phantom jack */
+       if (!phantom_jack) {
+               jack->input_dev = input_allocate_device();
+               if (jack->input_dev == NULL) {
+                       err = -ENOMEM;
+                       goto fail_input;
+               }
 
-       jack->input_dev->phys = "ALSA";
+               jack->input_dev->phys = "ALSA";
 
-       jack->type = type;
+               jack->type = type;
 
-       for (i = 0; i < SND_JACK_SWITCH_TYPES; i++)
-               if (type & (1 << i))
-                       input_set_capability(jack->input_dev, EV_SW,
-                                            jack_switch_types[i]);
+               for (i = 0; i < SND_JACK_SWITCH_TYPES; i++)
+                       if (type & (1 << i))
+                               input_set_capability(jack->input_dev, EV_SW,
+                                                    jack_switch_types[i]);
+
+       }
 
        err = snd_device_new(card, SNDRV_DEV_JACK, jack, &ops);
        if (err < 0)
@@ -237,6 +250,9 @@ int snd_jack_new(struct snd_card *card, const char *id, int type,
        jack->card = card;
        INIT_LIST_HEAD(&jack->kctl_list);
 
+       if (initial_kctl)
+               snd_jack_kctl_add(jack, jack_kctl);
+
        *jjack = jack;
 
        return 0;
index 05b49aa8af6c69c8409c2f2de8f10efbacaa96f9..16281c69bcd6e3080e6a041a23aa4db4c631fec7 100644 (file)
@@ -417,7 +417,7 @@ static int __snd_hda_jack_add_kctl(struct hda_codec *codec, hda_nid_t nid,
        if (!phantom_jack) {
                jack->type = get_input_jack_type(codec, nid);
                err = snd_jack_new(codec->card, name, jack->type,
-                                  &jack->jack);
+                                  &jack->jack, false, false);
                if (err < 0)
                        return err;
                jack->jack->private_data = jack;
index 6ce68604c25e4834460b3c0533e8b1eaca511151..90ac479f389f88eacaeed65942900a002b8acea1 100644 (file)
@@ -286,7 +286,7 @@ static void xonar_ds_init(struct oxygen *chip)
        xonar_enable_output(chip);
 
        snd_jack_new(chip->card, "Headphone",
-                    SND_JACK_HEADPHONE, &data->hp_jack);
+                    SND_JACK_HEADPHONE, &data->hp_jack, false, false);
        xonar_ds_handle_hp_jack(chip);
 
        snd_component_add(chip->card, "WM8776");
index 9f60c25c4568e7e1280e1ca28058c48c0ca65efa..70a9bdd5f3e3684278f44acacab8a24f1ef13ee3 100644 (file)
@@ -48,7 +48,7 @@ int snd_soc_card_jack_new(struct snd_soc_card *card, const char *id, int type,
        INIT_LIST_HEAD(&jack->jack_zones);
        BLOCKING_INIT_NOTIFIER_HEAD(&jack->notifier);
 
-       ret = snd_jack_new(card->snd_card, id, type, &jack->jack);
+       ret = snd_jack_new(card->snd_card, id, type, &jack->jack, false, false);
        if (ret)
                return ret;