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 | 71b1e9e | 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 | { |
David Henningsson | 80c8bfb | 2012-06-04 09:33:51 +0200 | [diff] [blame] | 130 | if (!jack->jack_dirty) |
| 131 | return; |
| 132 | |
| 133 | if (jack->phantom_jack) |
| 134 | jack->pin_sense = AC_PINSENSE_PRESENCE; |
| 135 | else |
Takashi Iwai | 35be544 | 2011-11-02 08:36:06 +0100 | [diff] [blame] | 136 | jack->pin_sense = read_pin_sense(codec, jack->nid); |
David Henningsson | 80c8bfb | 2012-06-04 09:33:51 +0200 | [diff] [blame] | 137 | |
| 138 | jack->jack_dirty = 0; |
Takashi Iwai | 1835a0f | 2011-10-27 22:12:46 +0200 | [diff] [blame] | 139 | } |
| 140 | |
| 141 | /** |
| 142 | * snd_hda_set_dirty_all - Mark all the cached as dirty |
| 143 | * |
| 144 | * This function sets the dirty flag to all entries of jack table. |
| 145 | * It's called from the resume path in hda_codec.c. |
| 146 | */ |
| 147 | void snd_hda_jack_set_dirty_all(struct hda_codec *codec) |
| 148 | { |
| 149 | struct hda_jack_tbl *jack = codec->jacktbl.list; |
| 150 | int i; |
| 151 | |
| 152 | for (i = 0; i < codec->jacktbl.used; i++, jack++) |
| 153 | if (jack->nid) |
| 154 | jack->jack_dirty = 1; |
| 155 | } |
| 156 | EXPORT_SYMBOL_HDA(snd_hda_jack_set_dirty_all); |
| 157 | |
| 158 | /** |
| 159 | * snd_hda_pin_sense - execute pin sense measurement |
| 160 | * @codec: the CODEC to sense |
| 161 | * @nid: the pin NID to sense |
| 162 | * |
| 163 | * Execute necessary pin sense measurement and return its Presence Detect, |
| 164 | * Impedance, ELD Valid etc. status bits. |
| 165 | */ |
| 166 | u32 snd_hda_pin_sense(struct hda_codec *codec, hda_nid_t nid) |
| 167 | { |
| 168 | struct hda_jack_tbl *jack = snd_hda_jack_tbl_get(codec, nid); |
| 169 | if (jack) { |
| 170 | jack_detect_update(codec, jack); |
| 171 | return jack->pin_sense; |
| 172 | } |
| 173 | return read_pin_sense(codec, nid); |
| 174 | } |
| 175 | EXPORT_SYMBOL_HDA(snd_hda_pin_sense); |
| 176 | |
Takashi Iwai | 35be544 | 2011-11-02 08:36:06 +0100 | [diff] [blame] | 177 | #define get_jack_plug_state(sense) !!(sense & AC_PINSENSE_PRESENCE) |
| 178 | |
Takashi Iwai | 1835a0f | 2011-10-27 22:12:46 +0200 | [diff] [blame] | 179 | /** |
| 180 | * snd_hda_jack_detect - query pin Presence Detect status |
| 181 | * @codec: the CODEC to sense |
| 182 | * @nid: the pin NID to sense |
| 183 | * |
| 184 | * Query and return the pin's Presence Detect status. |
| 185 | */ |
| 186 | int snd_hda_jack_detect(struct hda_codec *codec, hda_nid_t nid) |
| 187 | { |
| 188 | u32 sense = snd_hda_pin_sense(codec, nid); |
Takashi Iwai | 35be544 | 2011-11-02 08:36:06 +0100 | [diff] [blame] | 189 | return get_jack_plug_state(sense); |
Takashi Iwai | 1835a0f | 2011-10-27 22:12:46 +0200 | [diff] [blame] | 190 | } |
| 191 | EXPORT_SYMBOL_HDA(snd_hda_jack_detect); |
| 192 | |
| 193 | /** |
| 194 | * snd_hda_jack_detect_enable - enable the jack-detection |
| 195 | */ |
| 196 | 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] | 197 | unsigned char action) |
Takashi Iwai | 1835a0f | 2011-10-27 22:12:46 +0200 | [diff] [blame] | 198 | { |
| 199 | struct hda_jack_tbl *jack = snd_hda_jack_tbl_new(codec, nid); |
| 200 | if (!jack) |
| 201 | return -ENOMEM; |
Takashi Iwai | 3a93897 | 2011-10-28 01:16:55 +0200 | [diff] [blame] | 202 | if (jack->jack_detect) |
Takashi Iwai | 01a61e1 | 2011-10-28 00:03:22 +0200 | [diff] [blame] | 203 | return 0; /* already registered */ |
Takashi Iwai | 3a93897 | 2011-10-28 01:16:55 +0200 | [diff] [blame] | 204 | jack->jack_detect = 1; |
| 205 | if (action) |
| 206 | jack->action = action; |
Takashi Iwai | 1835a0f | 2011-10-27 22:12:46 +0200 | [diff] [blame] | 207 | return snd_hda_codec_write_cache(codec, nid, 0, |
| 208 | AC_VERB_SET_UNSOLICITED_ENABLE, |
Takashi Iwai | 3a93897 | 2011-10-28 01:16:55 +0200 | [diff] [blame] | 209 | AC_USRSP_EN | jack->tag); |
Takashi Iwai | 1835a0f | 2011-10-27 22:12:46 +0200 | [diff] [blame] | 210 | } |
| 211 | EXPORT_SYMBOL_HDA(snd_hda_jack_detect_enable); |
Takashi Iwai | 01a61e1 | 2011-10-28 00:03:22 +0200 | [diff] [blame] | 212 | |
Takashi Iwai | 01a61e1 | 2011-10-28 00:03:22 +0200 | [diff] [blame] | 213 | /** |
Takashi Iwai | 01a61e1 | 2011-10-28 00:03:22 +0200 | [diff] [blame] | 214 | * snd_hda_jack_report_sync - sync the states of all jacks and report if changed |
| 215 | */ |
| 216 | void snd_hda_jack_report_sync(struct hda_codec *codec) |
| 217 | { |
| 218 | struct hda_jack_tbl *jack = codec->jacktbl.list; |
Takashi Iwai | 35be544 | 2011-11-02 08:36:06 +0100 | [diff] [blame] | 219 | int i, state; |
Takashi Iwai | 01a61e1 | 2011-10-28 00:03:22 +0200 | [diff] [blame] | 220 | |
| 221 | for (i = 0; i < codec->jacktbl.used; i++, jack++) |
| 222 | if (jack->nid) { |
| 223 | jack_detect_update(codec, jack); |
Takashi Iwai | cfc7c9d | 2011-11-11 17:53:03 +0100 | [diff] [blame] | 224 | if (!jack->kctl) |
| 225 | continue; |
Takashi Iwai | 35be544 | 2011-11-02 08:36:06 +0100 | [diff] [blame] | 226 | state = get_jack_plug_state(jack->pin_sense); |
Takashi Iwai | aad37db | 2011-11-02 08:54:51 +0100 | [diff] [blame] | 227 | snd_kctl_jack_report(codec->bus->card, jack->kctl, state); |
Takashi Iwai | 31ef225 | 2011-12-01 17:41:36 +0100 | [diff] [blame] | 228 | #ifdef CONFIG_SND_HDA_INPUT_JACK |
| 229 | if (jack->jack) |
| 230 | snd_jack_report(jack->jack, |
| 231 | state ? jack->type : 0); |
| 232 | #endif |
Takashi Iwai | 01a61e1 | 2011-10-28 00:03:22 +0200 | [diff] [blame] | 233 | } |
| 234 | } |
| 235 | EXPORT_SYMBOL_HDA(snd_hda_jack_report_sync); |
| 236 | |
Takashi Iwai | 31ef225 | 2011-12-01 17:41:36 +0100 | [diff] [blame] | 237 | #ifdef CONFIG_SND_HDA_INPUT_JACK |
| 238 | /* guess the jack type from the pin-config */ |
| 239 | static int get_input_jack_type(struct hda_codec *codec, hda_nid_t nid) |
| 240 | { |
| 241 | unsigned int def_conf = snd_hda_codec_get_pincfg(codec, nid); |
| 242 | switch (get_defcfg_device(def_conf)) { |
| 243 | case AC_JACK_LINE_OUT: |
| 244 | case AC_JACK_SPEAKER: |
| 245 | return SND_JACK_LINEOUT; |
| 246 | case AC_JACK_HP_OUT: |
| 247 | return SND_JACK_HEADPHONE; |
| 248 | case AC_JACK_SPDIF_OUT: |
| 249 | case AC_JACK_DIG_OTHER_OUT: |
| 250 | return SND_JACK_AVOUT; |
| 251 | case AC_JACK_MIC_IN: |
| 252 | return SND_JACK_MICROPHONE; |
| 253 | default: |
| 254 | return SND_JACK_LINEIN; |
| 255 | } |
| 256 | } |
| 257 | |
| 258 | static void hda_free_jack_priv(struct snd_jack *jack) |
| 259 | { |
| 260 | struct hda_jack_tbl *jacks = jack->private_data; |
| 261 | jacks->nid = 0; |
| 262 | jacks->jack = NULL; |
| 263 | } |
| 264 | #endif |
| 265 | |
Takashi Iwai | 01a61e1 | 2011-10-28 00:03:22 +0200 | [diff] [blame] | 266 | /** |
| 267 | * snd_hda_jack_add_kctl - Add a kctl for the given pin |
| 268 | * |
| 269 | * This assigns a jack-detection kctl to the given pin. The kcontrol |
| 270 | * will have the given name and index. |
| 271 | */ |
David Henningsson | 80c8bfb | 2012-06-04 09:33:51 +0200 | [diff] [blame] | 272 | static int __snd_hda_jack_add_kctl(struct hda_codec *codec, hda_nid_t nid, |
| 273 | const char *name, int idx, bool phantom_jack) |
Takashi Iwai | 01a61e1 | 2011-10-28 00:03:22 +0200 | [diff] [blame] | 274 | { |
| 275 | struct hda_jack_tbl *jack; |
| 276 | struct snd_kcontrol *kctl; |
Takashi Iwai | 31ef225 | 2011-12-01 17:41:36 +0100 | [diff] [blame] | 277 | int err, state; |
Takashi Iwai | 01a61e1 | 2011-10-28 00:03:22 +0200 | [diff] [blame] | 278 | |
Takashi Iwai | 3a93897 | 2011-10-28 01:16:55 +0200 | [diff] [blame] | 279 | jack = snd_hda_jack_tbl_new(codec, nid); |
Takashi Iwai | 01a61e1 | 2011-10-28 00:03:22 +0200 | [diff] [blame] | 280 | if (!jack) |
| 281 | return 0; |
| 282 | if (jack->kctl) |
| 283 | return 0; /* already created */ |
Takashi Iwai | 35be544 | 2011-11-02 08:36:06 +0100 | [diff] [blame] | 284 | kctl = snd_kctl_jack_new(name, idx, codec); |
Takashi Iwai | 01a61e1 | 2011-10-28 00:03:22 +0200 | [diff] [blame] | 285 | if (!kctl) |
| 286 | return -ENOMEM; |
Takashi Iwai | 31ef225 | 2011-12-01 17:41:36 +0100 | [diff] [blame] | 287 | err = snd_hda_ctl_add(codec, nid, kctl); |
| 288 | if (err < 0) |
| 289 | return err; |
Takashi Iwai | 01a61e1 | 2011-10-28 00:03:22 +0200 | [diff] [blame] | 290 | jack->kctl = kctl; |
David Henningsson | 80c8bfb | 2012-06-04 09:33:51 +0200 | [diff] [blame] | 291 | jack->phantom_jack = !!phantom_jack; |
| 292 | |
Takashi Iwai | 31ef225 | 2011-12-01 17:41:36 +0100 | [diff] [blame] | 293 | state = snd_hda_jack_detect(codec, nid); |
| 294 | snd_kctl_jack_report(codec->bus->card, kctl, state); |
| 295 | #ifdef CONFIG_SND_HDA_INPUT_JACK |
David Henningsson | 80c8bfb | 2012-06-04 09:33:51 +0200 | [diff] [blame] | 296 | if (!phantom_jack) { |
| 297 | jack->type = get_input_jack_type(codec, nid); |
| 298 | err = snd_jack_new(codec->bus->card, name, jack->type, |
| 299 | &jack->jack); |
| 300 | if (err < 0) |
| 301 | return err; |
| 302 | jack->jack->private_data = jack; |
| 303 | jack->jack->private_free = hda_free_jack_priv; |
| 304 | snd_jack_report(jack->jack, state ? jack->type : 0); |
| 305 | } |
Takashi Iwai | 31ef225 | 2011-12-01 17:41:36 +0100 | [diff] [blame] | 306 | #endif |
Takashi Iwai | 01a61e1 | 2011-10-28 00:03:22 +0200 | [diff] [blame] | 307 | return 0; |
| 308 | } |
David Henningsson | 80c8bfb | 2012-06-04 09:33:51 +0200 | [diff] [blame] | 309 | |
| 310 | int snd_hda_jack_add_kctl(struct hda_codec *codec, hda_nid_t nid, |
| 311 | const char *name, int idx) |
| 312 | { |
| 313 | return __snd_hda_jack_add_kctl(codec, nid, name, idx, false); |
| 314 | } |
David Henningsson | d1cb620 | 2011-11-11 17:13:15 +0100 | [diff] [blame] | 315 | EXPORT_SYMBOL_HDA(snd_hda_jack_add_kctl); |
Takashi Iwai | 01a61e1 | 2011-10-28 00:03:22 +0200 | [diff] [blame] | 316 | |
Takashi Iwai | f46c329 | 2012-07-17 16:48:27 +0200 | [diff] [blame^] | 317 | /* get the unique index number for the given kctl name */ |
| 318 | static int get_unique_index(struct hda_codec *codec, const char *name, int idx) |
| 319 | { |
| 320 | struct hda_jack_tbl *jack; |
| 321 | int i, len = strlen(name); |
| 322 | again: |
| 323 | jack = codec->jacktbl.list; |
| 324 | for (i = 0; i < codec->jacktbl.used; i++, jack++) { |
| 325 | /* jack->kctl.id contains "XXX Jack" name string with index */ |
| 326 | if (jack->kctl && |
| 327 | !strncmp(name, jack->kctl->id.name, len) && |
| 328 | !strcmp(" Jack", jack->kctl->id.name + len) && |
| 329 | jack->kctl->id.index == idx) { |
| 330 | idx++; |
| 331 | goto again; |
| 332 | } |
| 333 | } |
| 334 | return idx; |
| 335 | } |
| 336 | |
Takashi Iwai | 201e06f | 2011-11-16 15:33:26 +0100 | [diff] [blame] | 337 | static int add_jack_kctl(struct hda_codec *codec, hda_nid_t nid, |
Takashi Iwai | f46c329 | 2012-07-17 16:48:27 +0200 | [diff] [blame^] | 338 | const struct auto_pin_cfg *cfg) |
Takashi Iwai | 01a61e1 | 2011-10-28 00:03:22 +0200 | [diff] [blame] | 339 | { |
Takashi Iwai | 3a93897 | 2011-10-28 01:16:55 +0200 | [diff] [blame] | 340 | unsigned int def_conf, conn; |
Takashi Iwai | 201e06f | 2011-11-16 15:33:26 +0100 | [diff] [blame] | 341 | char name[44]; |
| 342 | int idx, err; |
David Henningsson | 80c8bfb | 2012-06-04 09:33:51 +0200 | [diff] [blame] | 343 | bool phantom_jack; |
Takashi Iwai | 3a93897 | 2011-10-28 01:16:55 +0200 | [diff] [blame] | 344 | |
Takashi Iwai | 01a61e1 | 2011-10-28 00:03:22 +0200 | [diff] [blame] | 345 | if (!nid) |
| 346 | return 0; |
Takashi Iwai | 3a93897 | 2011-10-28 01:16:55 +0200 | [diff] [blame] | 347 | def_conf = snd_hda_codec_get_pincfg(codec, nid); |
| 348 | conn = get_defcfg_connect(def_conf); |
David Henningsson | 80c8bfb | 2012-06-04 09:33:51 +0200 | [diff] [blame] | 349 | if (conn == AC_JACK_PORT_NONE) |
Takashi Iwai | 3a93897 | 2011-10-28 01:16:55 +0200 | [diff] [blame] | 350 | return 0; |
David Henningsson | 80c8bfb | 2012-06-04 09:33:51 +0200 | [diff] [blame] | 351 | phantom_jack = (conn != AC_JACK_PORT_COMPLEX) || |
| 352 | !is_jack_detectable(codec, nid); |
Takashi Iwai | 3a93897 | 2011-10-28 01:16:55 +0200 | [diff] [blame] | 353 | |
Takashi Iwai | 201e06f | 2011-11-16 15:33:26 +0100 | [diff] [blame] | 354 | snd_hda_get_pin_label(codec, nid, cfg, name, sizeof(name), &idx); |
David Henningsson | 80c8bfb | 2012-06-04 09:33:51 +0200 | [diff] [blame] | 355 | if (phantom_jack) |
| 356 | /* Example final name: "Internal Mic Phantom Jack" */ |
| 357 | strncat(name, " Phantom", sizeof(name) - strlen(name) - 1); |
Takashi Iwai | f46c329 | 2012-07-17 16:48:27 +0200 | [diff] [blame^] | 358 | idx = get_unique_index(codec, name, idx); |
David Henningsson | 80c8bfb | 2012-06-04 09:33:51 +0200 | [diff] [blame] | 359 | err = __snd_hda_jack_add_kctl(codec, nid, name, idx, phantom_jack); |
Takashi Iwai | 3a93897 | 2011-10-28 01:16:55 +0200 | [diff] [blame] | 360 | if (err < 0) |
| 361 | return err; |
David Henningsson | 80c8bfb | 2012-06-04 09:33:51 +0200 | [diff] [blame] | 362 | |
| 363 | if (!phantom_jack) |
| 364 | return snd_hda_jack_detect_enable(codec, nid, 0); |
| 365 | return 0; |
Takashi Iwai | 01a61e1 | 2011-10-28 00:03:22 +0200 | [diff] [blame] | 366 | } |
| 367 | |
| 368 | /** |
| 369 | * 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] | 370 | */ |
| 371 | int snd_hda_jack_add_kctls(struct hda_codec *codec, |
| 372 | const struct auto_pin_cfg *cfg) |
| 373 | { |
| 374 | const hda_nid_t *p; |
Takashi Iwai | f46c329 | 2012-07-17 16:48:27 +0200 | [diff] [blame^] | 375 | int i, err; |
Takashi Iwai | 01a61e1 | 2011-10-28 00:03:22 +0200 | [diff] [blame] | 376 | |
| 377 | for (i = 0, p = cfg->line_out_pins; i < cfg->line_outs; i++, p++) { |
Takashi Iwai | f46c329 | 2012-07-17 16:48:27 +0200 | [diff] [blame^] | 378 | err = add_jack_kctl(codec, *p, cfg); |
Takashi Iwai | 01a61e1 | 2011-10-28 00:03:22 +0200 | [diff] [blame] | 379 | if (err < 0) |
| 380 | return err; |
| 381 | } |
| 382 | for (i = 0, p = cfg->hp_pins; i < cfg->hp_outs; i++, p++) { |
| 383 | if (*p == *cfg->line_out_pins) /* might be duplicated */ |
| 384 | break; |
Takashi Iwai | f46c329 | 2012-07-17 16:48:27 +0200 | [diff] [blame^] | 385 | err = add_jack_kctl(codec, *p, cfg); |
Takashi Iwai | 01a61e1 | 2011-10-28 00:03:22 +0200 | [diff] [blame] | 386 | if (err < 0) |
| 387 | return err; |
| 388 | } |
| 389 | for (i = 0, p = cfg->speaker_pins; i < cfg->speaker_outs; i++, p++) { |
| 390 | if (*p == *cfg->line_out_pins) /* might be duplicated */ |
| 391 | break; |
Takashi Iwai | f46c329 | 2012-07-17 16:48:27 +0200 | [diff] [blame^] | 392 | err = add_jack_kctl(codec, *p, cfg); |
Takashi Iwai | 01a61e1 | 2011-10-28 00:03:22 +0200 | [diff] [blame] | 393 | if (err < 0) |
| 394 | return err; |
| 395 | } |
| 396 | for (i = 0; i < cfg->num_inputs; i++) { |
Takashi Iwai | f46c329 | 2012-07-17 16:48:27 +0200 | [diff] [blame^] | 397 | err = add_jack_kctl(codec, cfg->inputs[i].pin, cfg); |
Takashi Iwai | 01a61e1 | 2011-10-28 00:03:22 +0200 | [diff] [blame] | 398 | if (err < 0) |
| 399 | return err; |
| 400 | } |
| 401 | for (i = 0, p = cfg->dig_out_pins; i < cfg->dig_outs; i++, p++) { |
Takashi Iwai | f46c329 | 2012-07-17 16:48:27 +0200 | [diff] [blame^] | 402 | err = add_jack_kctl(codec, *p, cfg); |
Takashi Iwai | 01a61e1 | 2011-10-28 00:03:22 +0200 | [diff] [blame] | 403 | if (err < 0) |
| 404 | return err; |
| 405 | } |
Takashi Iwai | f46c329 | 2012-07-17 16:48:27 +0200 | [diff] [blame^] | 406 | err = add_jack_kctl(codec, cfg->dig_in_pin, cfg); |
Takashi Iwai | 01a61e1 | 2011-10-28 00:03:22 +0200 | [diff] [blame] | 407 | if (err < 0) |
| 408 | return err; |
Takashi Iwai | f46c329 | 2012-07-17 16:48:27 +0200 | [diff] [blame^] | 409 | err = add_jack_kctl(codec, cfg->mono_out_pin, cfg); |
Takashi Iwai | 01a61e1 | 2011-10-28 00:03:22 +0200 | [diff] [blame] | 410 | if (err < 0) |
| 411 | return err; |
| 412 | return 0; |
| 413 | } |
| 414 | EXPORT_SYMBOL_HDA(snd_hda_jack_add_kctls); |