Takashi Iwai | 1835a0f | 2011-10-27 22:12:46 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Jack-detection handling for HD-audio |
| 3 | * |
| 4 | * Copyright (c) 2011 Takashi Iwai <tiwai@suse.de> |
| 5 | * |
| 6 | * This driver is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation; either version 2 of the License, or |
| 9 | * (at your option) any later version. |
| 10 | */ |
| 11 | |
| 12 | #include <linux/init.h> |
| 13 | #include <linux/slab.h> |
Takashi Iwai | bf815bf | 2011-11-16 14:28:33 +0100 | [diff] [blame] | 14 | #include <linux/export.h> |
Takashi Iwai | 1835a0f | 2011-10-27 22:12:46 +0200 | [diff] [blame] | 15 | #include <sound/core.h> |
Takashi Iwai | 01a61e1 | 2011-10-28 00:03:22 +0200 | [diff] [blame] | 16 | #include <sound/control.h> |
Takashi Iwai | aad37db | 2011-11-02 08:54:51 +0100 | [diff] [blame] | 17 | #include <sound/jack.h> |
Takashi Iwai | 1835a0f | 2011-10-27 22:12:46 +0200 | [diff] [blame] | 18 | #include "hda_codec.h" |
| 19 | #include "hda_local.h" |
Takashi Iwai | 128bc4b | 2012-05-07 17:42:31 +0200 | [diff] [blame^] | 20 | #include "hda_auto_parser.h" |
Takashi Iwai | 1835a0f | 2011-10-27 22:12:46 +0200 | [diff] [blame] | 21 | #include "hda_jack.h" |
| 22 | |
Takashi Iwai | a9c7417 | 2012-02-13 11:41:42 +0100 | [diff] [blame] | 23 | bool is_jack_detectable(struct hda_codec *codec, hda_nid_t nid) |
| 24 | { |
Takashi Iwai | 71b1e9e4 | 2012-02-13 11:55:02 +0100 | [diff] [blame] | 25 | if (codec->no_jack_detect) |
| 26 | return false; |
Takashi Iwai | a9c7417 | 2012-02-13 11:41:42 +0100 | [diff] [blame] | 27 | if (!(snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_PRES_DETECT)) |
| 28 | return false; |
| 29 | if (!codec->ignore_misc_bit && |
| 30 | (get_defcfg_misc(snd_hda_codec_get_pincfg(codec, nid)) & |
| 31 | AC_DEFCFG_MISC_NO_PRESENCE)) |
| 32 | return false; |
| 33 | if (!(get_wcaps(codec, nid) & AC_WCAP_UNSOL_CAP)) |
| 34 | return false; |
| 35 | return true; |
| 36 | } |
| 37 | EXPORT_SYMBOL_HDA(is_jack_detectable); |
| 38 | |
Takashi Iwai | 1835a0f | 2011-10-27 22:12:46 +0200 | [diff] [blame] | 39 | /* execute pin sense measurement */ |
| 40 | static u32 read_pin_sense(struct hda_codec *codec, hda_nid_t nid) |
| 41 | { |
| 42 | u32 pincap; |
| 43 | |
| 44 | if (!codec->no_trigger_sense) { |
| 45 | pincap = snd_hda_query_pin_caps(codec, nid); |
| 46 | if (pincap & AC_PINCAP_TRIG_REQ) /* need trigger? */ |
| 47 | snd_hda_codec_read(codec, nid, 0, |
| 48 | AC_VERB_SET_PIN_SENSE, 0); |
| 49 | } |
| 50 | return snd_hda_codec_read(codec, nid, 0, |
| 51 | AC_VERB_GET_PIN_SENSE, 0); |
| 52 | } |
| 53 | |
| 54 | /** |
| 55 | * snd_hda_jack_tbl_get - query the jack-table entry for the given NID |
| 56 | */ |
| 57 | struct hda_jack_tbl * |
| 58 | snd_hda_jack_tbl_get(struct hda_codec *codec, hda_nid_t nid) |
| 59 | { |
| 60 | struct hda_jack_tbl *jack = codec->jacktbl.list; |
| 61 | int i; |
| 62 | |
| 63 | if (!nid || !jack) |
| 64 | return NULL; |
| 65 | for (i = 0; i < codec->jacktbl.used; i++, jack++) |
| 66 | if (jack->nid == nid) |
| 67 | return jack; |
| 68 | return NULL; |
| 69 | } |
| 70 | EXPORT_SYMBOL_HDA(snd_hda_jack_tbl_get); |
| 71 | |
| 72 | /** |
Takashi Iwai | 3a93897 | 2011-10-28 01:16:55 +0200 | [diff] [blame] | 73 | * snd_hda_jack_tbl_get_from_tag - query the jack-table entry for the given tag |
| 74 | */ |
| 75 | struct hda_jack_tbl * |
| 76 | snd_hda_jack_tbl_get_from_tag(struct hda_codec *codec, unsigned char tag) |
| 77 | { |
| 78 | struct hda_jack_tbl *jack = codec->jacktbl.list; |
| 79 | int i; |
| 80 | |
| 81 | if (!tag || !jack) |
| 82 | return NULL; |
| 83 | for (i = 0; i < codec->jacktbl.used; i++, jack++) |
| 84 | if (jack->tag == tag) |
| 85 | return jack; |
| 86 | return NULL; |
| 87 | } |
| 88 | EXPORT_SYMBOL_HDA(snd_hda_jack_tbl_get_from_tag); |
| 89 | |
| 90 | /** |
Takashi Iwai | 1835a0f | 2011-10-27 22:12:46 +0200 | [diff] [blame] | 91 | * snd_hda_jack_tbl_new - create a jack-table entry for the given NID |
| 92 | */ |
| 93 | struct hda_jack_tbl * |
| 94 | snd_hda_jack_tbl_new(struct hda_codec *codec, hda_nid_t nid) |
| 95 | { |
| 96 | struct hda_jack_tbl *jack = snd_hda_jack_tbl_get(codec, nid); |
| 97 | if (jack) |
| 98 | return jack; |
| 99 | snd_array_init(&codec->jacktbl, sizeof(*jack), 16); |
| 100 | jack = snd_array_new(&codec->jacktbl); |
| 101 | if (!jack) |
| 102 | return NULL; |
| 103 | jack->nid = nid; |
| 104 | jack->jack_dirty = 1; |
Takashi Iwai | 3a93897 | 2011-10-28 01:16:55 +0200 | [diff] [blame] | 105 | jack->tag = codec->jacktbl.used; |
Takashi Iwai | 1835a0f | 2011-10-27 22:12:46 +0200 | [diff] [blame] | 106 | return jack; |
| 107 | } |
David Henningsson | d1cb620 | 2011-11-11 17:13:15 +0100 | [diff] [blame] | 108 | EXPORT_SYMBOL_HDA(snd_hda_jack_tbl_new); |
Takashi Iwai | 1835a0f | 2011-10-27 22:12:46 +0200 | [diff] [blame] | 109 | |
| 110 | void snd_hda_jack_tbl_clear(struct hda_codec *codec) |
| 111 | { |
Takashi Iwai | 31ef225 | 2011-12-01 17:41:36 +0100 | [diff] [blame] | 112 | #ifdef CONFIG_SND_HDA_INPUT_JACK |
| 113 | /* free jack instances manually when clearing/reconfiguring */ |
| 114 | if (!codec->bus->shutdown && codec->jacktbl.list) { |
| 115 | struct hda_jack_tbl *jack = codec->jacktbl.list; |
| 116 | int i; |
| 117 | for (i = 0; i < codec->jacktbl.used; i++, jack++) { |
| 118 | if (jack->jack) |
| 119 | snd_device_free(codec->bus->card, jack->jack); |
| 120 | } |
| 121 | } |
| 122 | #endif |
Takashi Iwai | 1835a0f | 2011-10-27 22:12:46 +0200 | [diff] [blame] | 123 | snd_array_free(&codec->jacktbl); |
| 124 | } |
| 125 | |
| 126 | /* update the cached value and notification flag if needed */ |
| 127 | static void jack_detect_update(struct hda_codec *codec, |
| 128 | struct hda_jack_tbl *jack) |
| 129 | { |
Takashi Iwai | 3a93897 | 2011-10-28 01:16:55 +0200 | [diff] [blame] | 130 | if (jack->jack_dirty || !jack->jack_detect) { |
Takashi Iwai | 35be544 | 2011-11-02 08:36:06 +0100 | [diff] [blame] | 131 | jack->pin_sense = read_pin_sense(codec, jack->nid); |
Takashi Iwai | 1835a0f | 2011-10-27 22:12:46 +0200 | [diff] [blame] | 132 | jack->jack_dirty = 0; |
| 133 | } |
| 134 | } |
| 135 | |
| 136 | /** |
| 137 | * snd_hda_set_dirty_all - Mark all the cached as dirty |
| 138 | * |
| 139 | * This function sets the dirty flag to all entries of jack table. |
| 140 | * It's called from the resume path in hda_codec.c. |
| 141 | */ |
| 142 | void snd_hda_jack_set_dirty_all(struct hda_codec *codec) |
| 143 | { |
| 144 | struct hda_jack_tbl *jack = codec->jacktbl.list; |
| 145 | int i; |
| 146 | |
| 147 | for (i = 0; i < codec->jacktbl.used; i++, jack++) |
| 148 | if (jack->nid) |
| 149 | jack->jack_dirty = 1; |
| 150 | } |
| 151 | EXPORT_SYMBOL_HDA(snd_hda_jack_set_dirty_all); |
| 152 | |
| 153 | /** |
| 154 | * snd_hda_pin_sense - execute pin sense measurement |
| 155 | * @codec: the CODEC to sense |
| 156 | * @nid: the pin NID to sense |
| 157 | * |
| 158 | * Execute necessary pin sense measurement and return its Presence Detect, |
| 159 | * Impedance, ELD Valid etc. status bits. |
| 160 | */ |
| 161 | u32 snd_hda_pin_sense(struct hda_codec *codec, hda_nid_t nid) |
| 162 | { |
| 163 | struct hda_jack_tbl *jack = snd_hda_jack_tbl_get(codec, nid); |
| 164 | if (jack) { |
| 165 | jack_detect_update(codec, jack); |
| 166 | return jack->pin_sense; |
| 167 | } |
| 168 | return read_pin_sense(codec, nid); |
| 169 | } |
| 170 | EXPORT_SYMBOL_HDA(snd_hda_pin_sense); |
| 171 | |
Takashi Iwai | 35be544 | 2011-11-02 08:36:06 +0100 | [diff] [blame] | 172 | #define get_jack_plug_state(sense) !!(sense & AC_PINSENSE_PRESENCE) |
| 173 | |
Takashi Iwai | 1835a0f | 2011-10-27 22:12:46 +0200 | [diff] [blame] | 174 | /** |
| 175 | * snd_hda_jack_detect - query pin Presence Detect status |
| 176 | * @codec: the CODEC to sense |
| 177 | * @nid: the pin NID to sense |
| 178 | * |
| 179 | * Query and return the pin's Presence Detect status. |
| 180 | */ |
| 181 | int snd_hda_jack_detect(struct hda_codec *codec, hda_nid_t nid) |
| 182 | { |
| 183 | u32 sense = snd_hda_pin_sense(codec, nid); |
Takashi Iwai | 35be544 | 2011-11-02 08:36:06 +0100 | [diff] [blame] | 184 | return get_jack_plug_state(sense); |
Takashi Iwai | 1835a0f | 2011-10-27 22:12:46 +0200 | [diff] [blame] | 185 | } |
| 186 | EXPORT_SYMBOL_HDA(snd_hda_jack_detect); |
| 187 | |
| 188 | /** |
| 189 | * snd_hda_jack_detect_enable - enable the jack-detection |
| 190 | */ |
| 191 | int snd_hda_jack_detect_enable(struct hda_codec *codec, hda_nid_t nid, |
Takashi Iwai | 3a93897 | 2011-10-28 01:16:55 +0200 | [diff] [blame] | 192 | unsigned char action) |
Takashi Iwai | 1835a0f | 2011-10-27 22:12:46 +0200 | [diff] [blame] | 193 | { |
| 194 | struct hda_jack_tbl *jack = snd_hda_jack_tbl_new(codec, nid); |
| 195 | if (!jack) |
| 196 | return -ENOMEM; |
Takashi Iwai | 3a93897 | 2011-10-28 01:16:55 +0200 | [diff] [blame] | 197 | if (jack->jack_detect) |
Takashi Iwai | 01a61e1 | 2011-10-28 00:03:22 +0200 | [diff] [blame] | 198 | return 0; /* already registered */ |
Takashi Iwai | 3a93897 | 2011-10-28 01:16:55 +0200 | [diff] [blame] | 199 | jack->jack_detect = 1; |
| 200 | if (action) |
| 201 | jack->action = action; |
Takashi Iwai | 1835a0f | 2011-10-27 22:12:46 +0200 | [diff] [blame] | 202 | return snd_hda_codec_write_cache(codec, nid, 0, |
| 203 | AC_VERB_SET_UNSOLICITED_ENABLE, |
Takashi Iwai | 3a93897 | 2011-10-28 01:16:55 +0200 | [diff] [blame] | 204 | AC_USRSP_EN | jack->tag); |
Takashi Iwai | 1835a0f | 2011-10-27 22:12:46 +0200 | [diff] [blame] | 205 | } |
| 206 | EXPORT_SYMBOL_HDA(snd_hda_jack_detect_enable); |
Takashi Iwai | 01a61e1 | 2011-10-28 00:03:22 +0200 | [diff] [blame] | 207 | |
Takashi Iwai | 01a61e1 | 2011-10-28 00:03:22 +0200 | [diff] [blame] | 208 | /** |
Takashi Iwai | 01a61e1 | 2011-10-28 00:03:22 +0200 | [diff] [blame] | 209 | * snd_hda_jack_report_sync - sync the states of all jacks and report if changed |
| 210 | */ |
| 211 | void snd_hda_jack_report_sync(struct hda_codec *codec) |
| 212 | { |
| 213 | struct hda_jack_tbl *jack = codec->jacktbl.list; |
Takashi Iwai | 35be544 | 2011-11-02 08:36:06 +0100 | [diff] [blame] | 214 | int i, state; |
Takashi Iwai | 01a61e1 | 2011-10-28 00:03:22 +0200 | [diff] [blame] | 215 | |
| 216 | for (i = 0; i < codec->jacktbl.used; i++, jack++) |
| 217 | if (jack->nid) { |
| 218 | jack_detect_update(codec, jack); |
Takashi Iwai | cfc7c9d | 2011-11-11 17:53:03 +0100 | [diff] [blame] | 219 | if (!jack->kctl) |
| 220 | continue; |
Takashi Iwai | 35be544 | 2011-11-02 08:36:06 +0100 | [diff] [blame] | 221 | state = get_jack_plug_state(jack->pin_sense); |
Takashi Iwai | aad37db | 2011-11-02 08:54:51 +0100 | [diff] [blame] | 222 | snd_kctl_jack_report(codec->bus->card, jack->kctl, state); |
Takashi Iwai | 31ef225 | 2011-12-01 17:41:36 +0100 | [diff] [blame] | 223 | #ifdef CONFIG_SND_HDA_INPUT_JACK |
| 224 | if (jack->jack) |
| 225 | snd_jack_report(jack->jack, |
| 226 | state ? jack->type : 0); |
| 227 | #endif |
Takashi Iwai | 01a61e1 | 2011-10-28 00:03:22 +0200 | [diff] [blame] | 228 | } |
| 229 | } |
| 230 | EXPORT_SYMBOL_HDA(snd_hda_jack_report_sync); |
| 231 | |
Takashi Iwai | 31ef225 | 2011-12-01 17:41:36 +0100 | [diff] [blame] | 232 | #ifdef CONFIG_SND_HDA_INPUT_JACK |
| 233 | /* guess the jack type from the pin-config */ |
| 234 | static int get_input_jack_type(struct hda_codec *codec, hda_nid_t nid) |
| 235 | { |
| 236 | unsigned int def_conf = snd_hda_codec_get_pincfg(codec, nid); |
| 237 | switch (get_defcfg_device(def_conf)) { |
| 238 | case AC_JACK_LINE_OUT: |
| 239 | case AC_JACK_SPEAKER: |
| 240 | return SND_JACK_LINEOUT; |
| 241 | case AC_JACK_HP_OUT: |
| 242 | return SND_JACK_HEADPHONE; |
| 243 | case AC_JACK_SPDIF_OUT: |
| 244 | case AC_JACK_DIG_OTHER_OUT: |
| 245 | return SND_JACK_AVOUT; |
| 246 | case AC_JACK_MIC_IN: |
| 247 | return SND_JACK_MICROPHONE; |
| 248 | default: |
| 249 | return SND_JACK_LINEIN; |
| 250 | } |
| 251 | } |
| 252 | |
| 253 | static void hda_free_jack_priv(struct snd_jack *jack) |
| 254 | { |
| 255 | struct hda_jack_tbl *jacks = jack->private_data; |
| 256 | jacks->nid = 0; |
| 257 | jacks->jack = NULL; |
| 258 | } |
| 259 | #endif |
| 260 | |
Takashi Iwai | 01a61e1 | 2011-10-28 00:03:22 +0200 | [diff] [blame] | 261 | /** |
| 262 | * snd_hda_jack_add_kctl - Add a kctl for the given pin |
| 263 | * |
| 264 | * This assigns a jack-detection kctl to the given pin. The kcontrol |
| 265 | * will have the given name and index. |
| 266 | */ |
| 267 | int snd_hda_jack_add_kctl(struct hda_codec *codec, hda_nid_t nid, |
| 268 | const char *name, int idx) |
| 269 | { |
| 270 | struct hda_jack_tbl *jack; |
| 271 | struct snd_kcontrol *kctl; |
Takashi Iwai | 31ef225 | 2011-12-01 17:41:36 +0100 | [diff] [blame] | 272 | int err, state; |
Takashi Iwai | 01a61e1 | 2011-10-28 00:03:22 +0200 | [diff] [blame] | 273 | |
Takashi Iwai | 3a93897 | 2011-10-28 01:16:55 +0200 | [diff] [blame] | 274 | jack = snd_hda_jack_tbl_new(codec, nid); |
Takashi Iwai | 01a61e1 | 2011-10-28 00:03:22 +0200 | [diff] [blame] | 275 | if (!jack) |
| 276 | return 0; |
| 277 | if (jack->kctl) |
| 278 | return 0; /* already created */ |
Takashi Iwai | 35be544 | 2011-11-02 08:36:06 +0100 | [diff] [blame] | 279 | kctl = snd_kctl_jack_new(name, idx, codec); |
Takashi Iwai | 01a61e1 | 2011-10-28 00:03:22 +0200 | [diff] [blame] | 280 | if (!kctl) |
| 281 | return -ENOMEM; |
Takashi Iwai | 31ef225 | 2011-12-01 17:41:36 +0100 | [diff] [blame] | 282 | err = snd_hda_ctl_add(codec, nid, kctl); |
| 283 | if (err < 0) |
| 284 | return err; |
Takashi Iwai | 01a61e1 | 2011-10-28 00:03:22 +0200 | [diff] [blame] | 285 | jack->kctl = kctl; |
Takashi Iwai | 31ef225 | 2011-12-01 17:41:36 +0100 | [diff] [blame] | 286 | state = snd_hda_jack_detect(codec, nid); |
| 287 | snd_kctl_jack_report(codec->bus->card, kctl, state); |
| 288 | #ifdef CONFIG_SND_HDA_INPUT_JACK |
| 289 | jack->type = get_input_jack_type(codec, nid); |
| 290 | err = snd_jack_new(codec->bus->card, name, jack->type, &jack->jack); |
| 291 | if (err < 0) |
| 292 | return err; |
| 293 | jack->jack->private_data = jack; |
| 294 | jack->jack->private_free = hda_free_jack_priv; |
| 295 | snd_jack_report(jack->jack, state ? jack->type : 0); |
| 296 | #endif |
Takashi Iwai | 01a61e1 | 2011-10-28 00:03:22 +0200 | [diff] [blame] | 297 | return 0; |
| 298 | } |
David Henningsson | d1cb620 | 2011-11-11 17:13:15 +0100 | [diff] [blame] | 299 | EXPORT_SYMBOL_HDA(snd_hda_jack_add_kctl); |
Takashi Iwai | 01a61e1 | 2011-10-28 00:03:22 +0200 | [diff] [blame] | 300 | |
Takashi Iwai | 201e06f | 2011-11-16 15:33:26 +0100 | [diff] [blame] | 301 | static int add_jack_kctl(struct hda_codec *codec, hda_nid_t nid, |
David Henningsson | 05c3b36 | 2012-01-31 09:04:15 +0100 | [diff] [blame] | 302 | const struct auto_pin_cfg *cfg, |
| 303 | char *lastname, int *lastidx) |
Takashi Iwai | 01a61e1 | 2011-10-28 00:03:22 +0200 | [diff] [blame] | 304 | { |
Takashi Iwai | 3a93897 | 2011-10-28 01:16:55 +0200 | [diff] [blame] | 305 | unsigned int def_conf, conn; |
Takashi Iwai | 201e06f | 2011-11-16 15:33:26 +0100 | [diff] [blame] | 306 | char name[44]; |
| 307 | int idx, err; |
Takashi Iwai | 3a93897 | 2011-10-28 01:16:55 +0200 | [diff] [blame] | 308 | |
Takashi Iwai | 01a61e1 | 2011-10-28 00:03:22 +0200 | [diff] [blame] | 309 | if (!nid) |
| 310 | return 0; |
| 311 | if (!is_jack_detectable(codec, nid)) |
| 312 | return 0; |
Takashi Iwai | 3a93897 | 2011-10-28 01:16:55 +0200 | [diff] [blame] | 313 | def_conf = snd_hda_codec_get_pincfg(codec, nid); |
| 314 | conn = get_defcfg_connect(def_conf); |
| 315 | if (conn != AC_JACK_PORT_COMPLEX) |
| 316 | return 0; |
| 317 | |
Takashi Iwai | 201e06f | 2011-11-16 15:33:26 +0100 | [diff] [blame] | 318 | snd_hda_get_pin_label(codec, nid, cfg, name, sizeof(name), &idx); |
David Henningsson | 05c3b36 | 2012-01-31 09:04:15 +0100 | [diff] [blame] | 319 | if (!strcmp(name, lastname) && idx == *lastidx) |
| 320 | idx++; |
| 321 | strncpy(lastname, name, 44); |
| 322 | *lastidx = idx; |
Takashi Iwai | 201e06f | 2011-11-16 15:33:26 +0100 | [diff] [blame] | 323 | err = snd_hda_jack_add_kctl(codec, nid, name, idx); |
Takashi Iwai | 3a93897 | 2011-10-28 01:16:55 +0200 | [diff] [blame] | 324 | if (err < 0) |
| 325 | return err; |
| 326 | return snd_hda_jack_detect_enable(codec, nid, 0); |
Takashi Iwai | 01a61e1 | 2011-10-28 00:03:22 +0200 | [diff] [blame] | 327 | } |
| 328 | |
| 329 | /** |
| 330 | * snd_hda_jack_add_kctls - Add kctls for all pins included in the given pincfg |
Takashi Iwai | 01a61e1 | 2011-10-28 00:03:22 +0200 | [diff] [blame] | 331 | */ |
| 332 | int snd_hda_jack_add_kctls(struct hda_codec *codec, |
| 333 | const struct auto_pin_cfg *cfg) |
| 334 | { |
| 335 | const hda_nid_t *p; |
David Henningsson | 05c3b36 | 2012-01-31 09:04:15 +0100 | [diff] [blame] | 336 | int i, err, lastidx = 0; |
| 337 | char lastname[44] = ""; |
Takashi Iwai | 01a61e1 | 2011-10-28 00:03:22 +0200 | [diff] [blame] | 338 | |
| 339 | for (i = 0, p = cfg->line_out_pins; i < cfg->line_outs; i++, p++) { |
David Henningsson | 05c3b36 | 2012-01-31 09:04:15 +0100 | [diff] [blame] | 340 | err = add_jack_kctl(codec, *p, cfg, lastname, &lastidx); |
Takashi Iwai | 01a61e1 | 2011-10-28 00:03:22 +0200 | [diff] [blame] | 341 | if (err < 0) |
| 342 | return err; |
| 343 | } |
| 344 | for (i = 0, p = cfg->hp_pins; i < cfg->hp_outs; i++, p++) { |
| 345 | if (*p == *cfg->line_out_pins) /* might be duplicated */ |
| 346 | break; |
David Henningsson | 05c3b36 | 2012-01-31 09:04:15 +0100 | [diff] [blame] | 347 | err = add_jack_kctl(codec, *p, cfg, lastname, &lastidx); |
Takashi Iwai | 01a61e1 | 2011-10-28 00:03:22 +0200 | [diff] [blame] | 348 | if (err < 0) |
| 349 | return err; |
| 350 | } |
| 351 | for (i = 0, p = cfg->speaker_pins; i < cfg->speaker_outs; i++, p++) { |
| 352 | if (*p == *cfg->line_out_pins) /* might be duplicated */ |
| 353 | break; |
David Henningsson | 05c3b36 | 2012-01-31 09:04:15 +0100 | [diff] [blame] | 354 | err = add_jack_kctl(codec, *p, cfg, lastname, &lastidx); |
Takashi Iwai | 01a61e1 | 2011-10-28 00:03:22 +0200 | [diff] [blame] | 355 | if (err < 0) |
| 356 | return err; |
| 357 | } |
| 358 | for (i = 0; i < cfg->num_inputs; i++) { |
David Henningsson | 05c3b36 | 2012-01-31 09:04:15 +0100 | [diff] [blame] | 359 | err = add_jack_kctl(codec, cfg->inputs[i].pin, cfg, lastname, &lastidx); |
Takashi Iwai | 01a61e1 | 2011-10-28 00:03:22 +0200 | [diff] [blame] | 360 | if (err < 0) |
| 361 | return err; |
| 362 | } |
| 363 | for (i = 0, p = cfg->dig_out_pins; i < cfg->dig_outs; i++, p++) { |
David Henningsson | 05c3b36 | 2012-01-31 09:04:15 +0100 | [diff] [blame] | 364 | err = add_jack_kctl(codec, *p, cfg, lastname, &lastidx); |
Takashi Iwai | 01a61e1 | 2011-10-28 00:03:22 +0200 | [diff] [blame] | 365 | if (err < 0) |
| 366 | return err; |
| 367 | } |
David Henningsson | 05c3b36 | 2012-01-31 09:04:15 +0100 | [diff] [blame] | 368 | err = add_jack_kctl(codec, cfg->dig_in_pin, cfg, lastname, &lastidx); |
Takashi Iwai | 01a61e1 | 2011-10-28 00:03:22 +0200 | [diff] [blame] | 369 | if (err < 0) |
| 370 | return err; |
David Henningsson | 05c3b36 | 2012-01-31 09:04:15 +0100 | [diff] [blame] | 371 | err = add_jack_kctl(codec, cfg->mono_out_pin, cfg, lastname, &lastidx); |
Takashi Iwai | 01a61e1 | 2011-10-28 00:03:22 +0200 | [diff] [blame] | 372 | if (err < 0) |
| 373 | return err; |
| 374 | return 0; |
| 375 | } |
| 376 | EXPORT_SYMBOL_HDA(snd_hda_jack_add_kctls); |