[alsa-devel] [PATCH v8 3/7] ALSA: jack: extend snd_jack_new to support phantom jack
Takashi Iwai
tiwai at suse.de
Wed Apr 22 13:30:32 CEST 2015
At Wed, 22 Apr 2015 14:03:49 +0800,
Jie Yang wrote:
>
> diff --git a/sound/core/jack.c b/sound/core/jack.c
> index b13d0b1..6c729ef 100644
> --- a/sound/core/jack.c
> +++ b/sound/core/jack.c
> @@ -198,6 +198,9 @@ 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.
> + * @phantom_jack: for phantom jack, only create needed kctl, won't create
> + * input device
> + * @initial_kctl: create kctl if true, also add it to the non-phantom jack kctl list
Better to align with the actual argument order.
> *
> * Creates a new jack object.
> *
> @@ -205,9 +208,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 = {
> @@ -216,26 +220,33 @@ 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);
> +
The function should return -ENOMEM if snd_jack_kctl_new() fails.
> 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)
> @@ -244,6 +255,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 && jack_kctl)
... then here no need to check both.
Takashi
More information about the Alsa-devel
mailing list