Skip to content

Commit 4e3f0dc

Browse files
keyonjietiwai
authored andcommitted
ALSA: jack: extend snd_jack_new to support phantom jack
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>
1 parent b8dd086 commit 4e3f0dc

5 files changed

Lines changed: 33 additions & 17 deletions

File tree

‎include/sound/jack.h‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ struct snd_jack {
8787
#ifdef CONFIG_SND_JACK
8888

8989
int snd_jack_new(struct snd_card *card, const char *id, int type,
90-
struct snd_jack **jack);
90+
struct snd_jack **jack, bool initial_kctl, bool phantom_jack);
9191
int snd_jack_add_new_kctl(struct snd_jack *jack, const char * name, int mask);
9292
void snd_jack_set_parent(struct snd_jack *jack, struct device *parent);
9393
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);
9797

9898
#else
9999
static inline int snd_jack_new(struct snd_card *card, const char *id, int type,
100-
struct snd_jack **jack)
100+
struct snd_jack **jack, bool initial_kctl, bool phantom_jack)
101101
{
102102
return 0;
103103
}

‎sound/core/jack.c‎

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -191,16 +191,19 @@ EXPORT_SYMBOL(snd_jack_add_new_kctl);
191191
* @type: a bitmask of enum snd_jack_type values that can be detected by
192192
* this jack
193193
* @jjack: Used to provide the allocated jack object to the caller.
194+
* @initial_kctl: if true, create a kcontrol and add it to the jack list.
195+
* @phantom_jack: Don't create a input device for phantom jacks.
194196
*
195197
* Creates a new jack object.
196198
*
197199
* Return: Zero if successful, or a negative error code on failure.
198200
* On success @jjack will be initialised.
199201
*/
200202
int snd_jack_new(struct snd_card *card, const char *id, int type,
201-
struct snd_jack **jjack)
203+
struct snd_jack **jjack, bool initial_kctl, bool phantom_jack)
202204
{
203205
struct snd_jack *jack;
206+
struct snd_jack_kctl *jack_kctl = NULL;
204207
int err;
205208
int i;
206209
static struct snd_device_ops ops = {
@@ -209,26 +212,36 @@ int snd_jack_new(struct snd_card *card, const char *id, int type,
209212
.dev_disconnect = snd_jack_dev_disconnect,
210213
};
211214

215+
if (initial_kctl) {
216+
jack_kctl = snd_jack_kctl_new(card, id, type);
217+
if (!jack_kctl)
218+
return -ENOMEM;
219+
}
220+
212221
jack = kzalloc(sizeof(struct snd_jack), GFP_KERNEL);
213222
if (jack == NULL)
214223
return -ENOMEM;
215224

216225
jack->id = kstrdup(id, GFP_KERNEL);
217226

218-
jack->input_dev = input_allocate_device();
219-
if (jack->input_dev == NULL) {
220-
err = -ENOMEM;
221-
goto fail_input;
222-
}
227+
/* don't creat input device for phantom jack */
228+
if (!phantom_jack) {
229+
jack->input_dev = input_allocate_device();
230+
if (jack->input_dev == NULL) {
231+
err = -ENOMEM;
232+
goto fail_input;
233+
}
223234

224-
jack->input_dev->phys = "ALSA";
235+
jack->input_dev->phys = "ALSA";
225236

226-
jack->type = type;
237+
jack->type = type;
227238

228-
for (i = 0; i < SND_JACK_SWITCH_TYPES; i++)
229-
if (type & (1 << i))
230-
input_set_capability(jack->input_dev, EV_SW,
231-
jack_switch_types[i]);
239+
for (i = 0; i < SND_JACK_SWITCH_TYPES; i++)
240+
if (type & (1 << i))
241+
input_set_capability(jack->input_dev, EV_SW,
242+
jack_switch_types[i]);
243+
244+
}
232245

233246
err = snd_device_new(card, SNDRV_DEV_JACK, jack, &ops);
234247
if (err < 0)
@@ -237,6 +250,9 @@ int snd_jack_new(struct snd_card *card, const char *id, int type,
237250
jack->card = card;
238251
INIT_LIST_HEAD(&jack->kctl_list);
239252

253+
if (initial_kctl)
254+
snd_jack_kctl_add(jack, jack_kctl);
255+
240256
*jjack = jack;
241257

242258
return 0;

‎sound/pci/hda/hda_jack.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,7 @@ static int __snd_hda_jack_add_kctl(struct hda_codec *codec, hda_nid_t nid,
417417
if (!phantom_jack) {
418418
jack->type = get_input_jack_type(codec, nid);
419419
err = snd_jack_new(codec->card, name, jack->type,
420-
&jack->jack);
420+
&jack->jack, false, false);
421421
if (err < 0)
422422
return err;
423423
jack->jack->private_data = jack;

‎sound/pci/oxygen/xonar_wm87x6.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ static void xonar_ds_init(struct oxygen *chip)
286286
xonar_enable_output(chip);
287287

288288
snd_jack_new(chip->card, "Headphone",
289-
SND_JACK_HEADPHONE, &data->hp_jack);
289+
SND_JACK_HEADPHONE, &data->hp_jack, false, false);
290290
xonar_ds_handle_hp_jack(chip);
291291

292292
snd_component_add(chip->card, "WM8776");

‎sound/soc/soc-jack.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ int snd_soc_card_jack_new(struct snd_soc_card *card, const char *id, int type,
4848
INIT_LIST_HEAD(&jack->jack_zones);
4949
BLOCKING_INIT_NOTIFIER_HEAD(&jack->notifier);
5050

51-
ret = snd_jack_new(card->snd_card, id, type, &jack->jack);
51+
ret = snd_jack_new(card->snd_card, id, type, &jack->jack, false, false);
5252
if (ret)
5353
return ret;
5454

0 commit comments

Comments
 (0)