diff options
author | Takashi Iwai <tiwai@suse.de> | 2015-04-28 02:31:31 -0400 |
---|---|---|
committer | Takashi Iwai <tiwai@suse.de> | 2015-04-28 02:31:31 -0400 |
commit | 1962fcab4ee80e555bcc9d0f50e416800d474fa2 (patch) | |
tree | 945ba95f11016871f9d5241b7da2712f9367081a /sound/core/ctljack.c | |
parent | f1a77547c21fe942e95ebaadbc9200f26d138574 (diff) | |
parent | 12e180a27f3e066a4ed4a446d428fd117f168beb (diff) |
Merge branch 'topic/jack' into for-next
Diffstat (limited to 'sound/core/ctljack.c')
-rw-r--r-- | sound/core/ctljack.c | 41 |
1 files changed, 35 insertions, 6 deletions
diff --git a/sound/core/ctljack.c b/sound/core/ctljack.c index e4b38fbe51da..8f8d1033425c 100644 --- a/sound/core/ctljack.c +++ b/sound/core/ctljack.c | |||
@@ -31,19 +31,49 @@ static struct snd_kcontrol_new jack_detect_kctl = { | |||
31 | .get = jack_detect_kctl_get, | 31 | .get = jack_detect_kctl_get, |
32 | }; | 32 | }; |
33 | 33 | ||
34 | static int get_available_index(struct snd_card *card, const char *name) | ||
35 | { | ||
36 | struct snd_ctl_elem_id sid; | ||
37 | |||
38 | memset(&sid, 0, sizeof(sid)); | ||
39 | |||
40 | sid.index = 0; | ||
41 | sid.iface = SNDRV_CTL_ELEM_IFACE_CARD; | ||
42 | strlcpy(sid.name, name, sizeof(sid.name)); | ||
43 | |||
44 | while (snd_ctl_find_id(card, &sid)) | ||
45 | sid.index++; | ||
46 | |||
47 | return sid.index; | ||
48 | } | ||
49 | |||
50 | static void jack_kctl_name_gen(char *name, const char *src_name, int size) | ||
51 | { | ||
52 | size_t count = strlen(src_name); | ||
53 | bool need_cat = true; | ||
54 | |||
55 | /* remove redundant " Jack" from src_name */ | ||
56 | if (count >= 5) | ||
57 | need_cat = strncmp(&src_name[count - 5], " Jack", 5) ? true : false; | ||
58 | |||
59 | snprintf(name, size, need_cat ? "%s Jack" : "%s", src_name); | ||
60 | |||
61 | } | ||
62 | |||
34 | struct snd_kcontrol * | 63 | struct snd_kcontrol * |
35 | snd_kctl_jack_new(const char *name, int idx, void *private_data) | 64 | snd_kctl_jack_new(const char *name, struct snd_card *card) |
36 | { | 65 | { |
37 | struct snd_kcontrol *kctl; | 66 | struct snd_kcontrol *kctl; |
38 | kctl = snd_ctl_new1(&jack_detect_kctl, private_data); | 67 | |
68 | kctl = snd_ctl_new1(&jack_detect_kctl, NULL); | ||
39 | if (!kctl) | 69 | if (!kctl) |
40 | return NULL; | 70 | return NULL; |
41 | snprintf(kctl->id.name, sizeof(kctl->id.name), "%s Jack", name); | 71 | |
42 | kctl->id.index = idx; | 72 | jack_kctl_name_gen(kctl->id.name, name, sizeof(kctl->id.name)); |
73 | kctl->id.index = get_available_index(card, name); | ||
43 | kctl->private_value = 0; | 74 | kctl->private_value = 0; |
44 | return kctl; | 75 | return kctl; |
45 | } | 76 | } |
46 | EXPORT_SYMBOL_GPL(snd_kctl_jack_new); | ||
47 | 77 | ||
48 | void snd_kctl_jack_report(struct snd_card *card, | 78 | void snd_kctl_jack_report(struct snd_card *card, |
49 | struct snd_kcontrol *kctl, bool status) | 79 | struct snd_kcontrol *kctl, bool status) |
@@ -53,4 +83,3 @@ void snd_kctl_jack_report(struct snd_card *card, | |||
53 | kctl->private_value = status; | 83 | kctl->private_value = status; |
54 | snd_ctl_notify(card, SNDRV_CTL_EVENT_MASK_VALUE, &kctl->id); | 84 | snd_ctl_notify(card, SNDRV_CTL_EVENT_MASK_VALUE, &kctl->id); |
55 | } | 85 | } |
56 | EXPORT_SYMBOL_GPL(snd_kctl_jack_report); | ||