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 | 95a962c | 2014-10-29 16:03:58 +0100 | [diff] [blame] | 23 | /** |
| 24 | * is_jack_detectable - Check whether the given pin is jack-detectable |
| 25 | * @codec: the HDA codec |
| 26 | * @nid: pin NID |
| 27 | * |
| 28 | * Check whether the given pin is capable to report the jack detection. |
| 29 | * The jack detection might not work by various reasons, e.g. the jack |
| 30 | * detection is prohibited in the codec level, the pin config has |
| 31 | * AC_DEFCFG_MISC_NO_PRESENCE bit, no unsol support, etc. |
| 32 | */ |
Takashi Iwai | a9c7417 | 2012-02-13 11:41:42 +0100 | [diff] [blame] | 33 | bool is_jack_detectable(struct hda_codec *codec, hda_nid_t nid) |
| 34 | { |
Takashi Iwai | 71b1e9e | 2012-02-13 11:55:02 +0100 | [diff] [blame] | 35 | if (codec->no_jack_detect) |
| 36 | return false; |
Takashi Iwai | a9c7417 | 2012-02-13 11:41:42 +0100 | [diff] [blame] | 37 | if (!(snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_PRES_DETECT)) |
| 38 | return false; |
David Henningsson | 5fe8e1e | 2012-09-07 07:25:44 +0200 | [diff] [blame] | 39 | if (get_defcfg_misc(snd_hda_codec_get_pincfg(codec, nid)) & |
| 40 | AC_DEFCFG_MISC_NO_PRESENCE) |
Takashi Iwai | a9c7417 | 2012-02-13 11:41:42 +0100 | [diff] [blame] | 41 | return false; |
Takashi Iwai | 76a19c6 | 2013-01-07 12:11:33 +0100 | [diff] [blame] | 42 | if (!(get_wcaps(codec, nid) & AC_WCAP_UNSOL_CAP) && |
| 43 | !codec->jackpoll_interval) |
Takashi Iwai | a9c7417 | 2012-02-13 11:41:42 +0100 | [diff] [blame] | 44 | return false; |
| 45 | return true; |
| 46 | } |
Takashi Iwai | 2698ea9 | 2013-12-18 07:45:52 +0100 | [diff] [blame] | 47 | EXPORT_SYMBOL_GPL(is_jack_detectable); |
Takashi Iwai | a9c7417 | 2012-02-13 11:41:42 +0100 | [diff] [blame] | 48 | |
Takashi Iwai | 1835a0f | 2011-10-27 22:12:46 +0200 | [diff] [blame] | 49 | /* execute pin sense measurement */ |
| 50 | static u32 read_pin_sense(struct hda_codec *codec, hda_nid_t nid) |
| 51 | { |
| 52 | u32 pincap; |
Takashi Iwai | 9cc159c | 2012-12-21 15:31:41 +0100 | [diff] [blame] | 53 | u32 val; |
Takashi Iwai | 1835a0f | 2011-10-27 22:12:46 +0200 | [diff] [blame] | 54 | |
| 55 | if (!codec->no_trigger_sense) { |
| 56 | pincap = snd_hda_query_pin_caps(codec, nid); |
| 57 | if (pincap & AC_PINCAP_TRIG_REQ) /* need trigger? */ |
| 58 | snd_hda_codec_read(codec, nid, 0, |
| 59 | AC_VERB_SET_PIN_SENSE, 0); |
| 60 | } |
Takashi Iwai | 9cc159c | 2012-12-21 15:31:41 +0100 | [diff] [blame] | 61 | val = snd_hda_codec_read(codec, nid, 0, |
Takashi Iwai | 1835a0f | 2011-10-27 22:12:46 +0200 | [diff] [blame] | 62 | AC_VERB_GET_PIN_SENSE, 0); |
Takashi Iwai | 9cc159c | 2012-12-21 15:31:41 +0100 | [diff] [blame] | 63 | if (codec->inv_jack_detect) |
| 64 | val ^= AC_PINSENSE_PRESENCE; |
| 65 | return val; |
Takashi Iwai | 1835a0f | 2011-10-27 22:12:46 +0200 | [diff] [blame] | 66 | } |
| 67 | |
| 68 | /** |
| 69 | * snd_hda_jack_tbl_get - query the jack-table entry for the given NID |
Takashi Iwai | a11e9b1 | 2014-10-29 15:06:01 +0100 | [diff] [blame] | 70 | * @codec: the HDA codec |
| 71 | * @nid: pin NID to refer to |
Takashi Iwai | 1835a0f | 2011-10-27 22:12:46 +0200 | [diff] [blame] | 72 | */ |
| 73 | struct hda_jack_tbl * |
| 74 | snd_hda_jack_tbl_get(struct hda_codec *codec, hda_nid_t nid) |
| 75 | { |
| 76 | struct hda_jack_tbl *jack = codec->jacktbl.list; |
| 77 | int i; |
| 78 | |
| 79 | if (!nid || !jack) |
| 80 | return NULL; |
| 81 | for (i = 0; i < codec->jacktbl.used; i++, jack++) |
| 82 | if (jack->nid == nid) |
| 83 | return jack; |
| 84 | return NULL; |
| 85 | } |
Takashi Iwai | 2698ea9 | 2013-12-18 07:45:52 +0100 | [diff] [blame] | 86 | EXPORT_SYMBOL_GPL(snd_hda_jack_tbl_get); |
Takashi Iwai | 1835a0f | 2011-10-27 22:12:46 +0200 | [diff] [blame] | 87 | |
| 88 | /** |
Takashi Iwai | 3a93897 | 2011-10-28 01:16:55 +0200 | [diff] [blame] | 89 | * snd_hda_jack_tbl_get_from_tag - query the jack-table entry for the given tag |
Takashi Iwai | a11e9b1 | 2014-10-29 15:06:01 +0100 | [diff] [blame] | 90 | * @codec: the HDA codec |
| 91 | * @tag: tag value to refer to |
Takashi Iwai | 3a93897 | 2011-10-28 01:16:55 +0200 | [diff] [blame] | 92 | */ |
| 93 | struct hda_jack_tbl * |
| 94 | snd_hda_jack_tbl_get_from_tag(struct hda_codec *codec, unsigned char tag) |
| 95 | { |
| 96 | struct hda_jack_tbl *jack = codec->jacktbl.list; |
| 97 | int i; |
| 98 | |
| 99 | if (!tag || !jack) |
| 100 | return NULL; |
| 101 | for (i = 0; i < codec->jacktbl.used; i++, jack++) |
| 102 | if (jack->tag == tag) |
| 103 | return jack; |
| 104 | return NULL; |
| 105 | } |
Takashi Iwai | 2698ea9 | 2013-12-18 07:45:52 +0100 | [diff] [blame] | 106 | EXPORT_SYMBOL_GPL(snd_hda_jack_tbl_get_from_tag); |
Takashi Iwai | 3a93897 | 2011-10-28 01:16:55 +0200 | [diff] [blame] | 107 | |
| 108 | /** |
Takashi Iwai | 1835a0f | 2011-10-27 22:12:46 +0200 | [diff] [blame] | 109 | * snd_hda_jack_tbl_new - create a jack-table entry for the given NID |
Takashi Iwai | a11e9b1 | 2014-10-29 15:06:01 +0100 | [diff] [blame] | 110 | * @codec: the HDA codec |
| 111 | * @nid: pin NID to assign |
Takashi Iwai | 1835a0f | 2011-10-27 22:12:46 +0200 | [diff] [blame] | 112 | */ |
Takashi Iwai | 81965f1 | 2014-09-11 14:22:03 +0200 | [diff] [blame] | 113 | static struct hda_jack_tbl * |
Takashi Iwai | 1835a0f | 2011-10-27 22:12:46 +0200 | [diff] [blame] | 114 | snd_hda_jack_tbl_new(struct hda_codec *codec, hda_nid_t nid) |
| 115 | { |
| 116 | struct hda_jack_tbl *jack = snd_hda_jack_tbl_get(codec, nid); |
| 117 | if (jack) |
| 118 | return jack; |
Takashi Iwai | 1835a0f | 2011-10-27 22:12:46 +0200 | [diff] [blame] | 119 | jack = snd_array_new(&codec->jacktbl); |
| 120 | if (!jack) |
| 121 | return NULL; |
| 122 | jack->nid = nid; |
| 123 | jack->jack_dirty = 1; |
Takashi Iwai | 3a93897 | 2011-10-28 01:16:55 +0200 | [diff] [blame] | 124 | jack->tag = codec->jacktbl.used; |
Takashi Iwai | 1835a0f | 2011-10-27 22:12:46 +0200 | [diff] [blame] | 125 | return jack; |
| 126 | } |
| 127 | |
| 128 | void snd_hda_jack_tbl_clear(struct hda_codec *codec) |
| 129 | { |
Takashi Iwai | 1a4f69d | 2014-09-11 15:22:46 +0200 | [diff] [blame] | 130 | struct hda_jack_tbl *jack = codec->jacktbl.list; |
| 131 | int i; |
| 132 | |
| 133 | for (i = 0; i < codec->jacktbl.used; i++, jack++) { |
| 134 | struct hda_jack_callback *cb, *next; |
Takashi Iwai | 31ef225 | 2011-12-01 17:41:36 +0100 | [diff] [blame] | 135 | #ifdef CONFIG_SND_HDA_INPUT_JACK |
Takashi Iwai | 1a4f69d | 2014-09-11 15:22:46 +0200 | [diff] [blame] | 136 | /* free jack instances manually when clearing/reconfiguring */ |
| 137 | if (!codec->bus->shutdown && jack->jack) |
| 138 | snd_device_free(codec->bus->card, jack->jack); |
| 139 | #endif |
| 140 | for (cb = jack->callback; cb; cb = next) { |
| 141 | next = cb->next; |
| 142 | kfree(cb); |
Takashi Iwai | 31ef225 | 2011-12-01 17:41:36 +0100 | [diff] [blame] | 143 | } |
| 144 | } |
Takashi Iwai | 1835a0f | 2011-10-27 22:12:46 +0200 | [diff] [blame] | 145 | snd_array_free(&codec->jacktbl); |
| 146 | } |
| 147 | |
Dylan Reid | 0619ba8 | 2012-11-19 19:48:07 +0100 | [diff] [blame] | 148 | #define get_jack_plug_state(sense) !!(sense & AC_PINSENSE_PRESENCE) |
| 149 | |
Takashi Iwai | 1835a0f | 2011-10-27 22:12:46 +0200 | [diff] [blame] | 150 | /* update the cached value and notification flag if needed */ |
| 151 | static void jack_detect_update(struct hda_codec *codec, |
| 152 | struct hda_jack_tbl *jack) |
| 153 | { |
David Henningsson | 80c8bfb | 2012-06-04 09:33:51 +0200 | [diff] [blame] | 154 | if (!jack->jack_dirty) |
| 155 | return; |
| 156 | |
| 157 | if (jack->phantom_jack) |
| 158 | jack->pin_sense = AC_PINSENSE_PRESENCE; |
| 159 | else |
Takashi Iwai | 35be544 | 2011-11-02 08:36:06 +0100 | [diff] [blame] | 160 | jack->pin_sense = read_pin_sense(codec, jack->nid); |
David Henningsson | 80c8bfb | 2012-06-04 09:33:51 +0200 | [diff] [blame] | 161 | |
Dylan Reid | 0619ba8 | 2012-11-19 19:48:07 +0100 | [diff] [blame] | 162 | /* A gating jack indicates the jack is invalid if gating is unplugged */ |
| 163 | if (jack->gating_jack && !snd_hda_jack_detect(codec, jack->gating_jack)) |
| 164 | jack->pin_sense &= ~AC_PINSENSE_PRESENCE; |
| 165 | |
David Henningsson | 80c8bfb | 2012-06-04 09:33:51 +0200 | [diff] [blame] | 166 | jack->jack_dirty = 0; |
Dylan Reid | 0619ba8 | 2012-11-19 19:48:07 +0100 | [diff] [blame] | 167 | |
| 168 | /* If a jack is gated by this one update it. */ |
| 169 | if (jack->gated_jack) { |
| 170 | struct hda_jack_tbl *gated = |
| 171 | snd_hda_jack_tbl_get(codec, jack->gated_jack); |
| 172 | if (gated) { |
| 173 | gated->jack_dirty = 1; |
| 174 | jack_detect_update(codec, gated); |
| 175 | } |
| 176 | } |
Takashi Iwai | 1835a0f | 2011-10-27 22:12:46 +0200 | [diff] [blame] | 177 | } |
| 178 | |
| 179 | /** |
| 180 | * snd_hda_set_dirty_all - Mark all the cached as dirty |
Takashi Iwai | a11e9b1 | 2014-10-29 15:06:01 +0100 | [diff] [blame] | 181 | * @codec: the HDA codec |
Takashi Iwai | 1835a0f | 2011-10-27 22:12:46 +0200 | [diff] [blame] | 182 | * |
| 183 | * This function sets the dirty flag to all entries of jack table. |
| 184 | * It's called from the resume path in hda_codec.c. |
| 185 | */ |
| 186 | void snd_hda_jack_set_dirty_all(struct hda_codec *codec) |
| 187 | { |
| 188 | struct hda_jack_tbl *jack = codec->jacktbl.list; |
| 189 | int i; |
| 190 | |
| 191 | for (i = 0; i < codec->jacktbl.used; i++, jack++) |
| 192 | if (jack->nid) |
| 193 | jack->jack_dirty = 1; |
| 194 | } |
Takashi Iwai | 2698ea9 | 2013-12-18 07:45:52 +0100 | [diff] [blame] | 195 | EXPORT_SYMBOL_GPL(snd_hda_jack_set_dirty_all); |
Takashi Iwai | 1835a0f | 2011-10-27 22:12:46 +0200 | [diff] [blame] | 196 | |
| 197 | /** |
| 198 | * snd_hda_pin_sense - execute pin sense measurement |
| 199 | * @codec: the CODEC to sense |
| 200 | * @nid: the pin NID to sense |
| 201 | * |
| 202 | * Execute necessary pin sense measurement and return its Presence Detect, |
| 203 | * Impedance, ELD Valid etc. status bits. |
| 204 | */ |
| 205 | u32 snd_hda_pin_sense(struct hda_codec *codec, hda_nid_t nid) |
| 206 | { |
| 207 | struct hda_jack_tbl *jack = snd_hda_jack_tbl_get(codec, nid); |
| 208 | if (jack) { |
| 209 | jack_detect_update(codec, jack); |
| 210 | return jack->pin_sense; |
| 211 | } |
| 212 | return read_pin_sense(codec, nid); |
| 213 | } |
Takashi Iwai | 2698ea9 | 2013-12-18 07:45:52 +0100 | [diff] [blame] | 214 | EXPORT_SYMBOL_GPL(snd_hda_pin_sense); |
Takashi Iwai | 1835a0f | 2011-10-27 22:12:46 +0200 | [diff] [blame] | 215 | |
| 216 | /** |
Takashi Iwai | 60ea8ca | 2013-07-19 16:59:46 +0200 | [diff] [blame] | 217 | * snd_hda_jack_detect_state - query pin Presence Detect status |
Takashi Iwai | 1835a0f | 2011-10-27 22:12:46 +0200 | [diff] [blame] | 218 | * @codec: the CODEC to sense |
| 219 | * @nid: the pin NID to sense |
| 220 | * |
Takashi Iwai | 60ea8ca | 2013-07-19 16:59:46 +0200 | [diff] [blame] | 221 | * Query and return the pin's Presence Detect status, as either |
| 222 | * HDA_JACK_NOT_PRESENT, HDA_JACK_PRESENT or HDA_JACK_PHANTOM. |
Takashi Iwai | 1835a0f | 2011-10-27 22:12:46 +0200 | [diff] [blame] | 223 | */ |
Takashi Iwai | 60ea8ca | 2013-07-19 16:59:46 +0200 | [diff] [blame] | 224 | int snd_hda_jack_detect_state(struct hda_codec *codec, hda_nid_t nid) |
Takashi Iwai | 1835a0f | 2011-10-27 22:12:46 +0200 | [diff] [blame] | 225 | { |
Takashi Iwai | 60ea8ca | 2013-07-19 16:59:46 +0200 | [diff] [blame] | 226 | struct hda_jack_tbl *jack = snd_hda_jack_tbl_get(codec, nid); |
| 227 | if (jack && jack->phantom_jack) |
| 228 | return HDA_JACK_PHANTOM; |
| 229 | else if (snd_hda_pin_sense(codec, nid) & AC_PINSENSE_PRESENCE) |
| 230 | return HDA_JACK_PRESENT; |
| 231 | else |
| 232 | return HDA_JACK_NOT_PRESENT; |
Takashi Iwai | 1835a0f | 2011-10-27 22:12:46 +0200 | [diff] [blame] | 233 | } |
Takashi Iwai | 2698ea9 | 2013-12-18 07:45:52 +0100 | [diff] [blame] | 234 | EXPORT_SYMBOL_GPL(snd_hda_jack_detect_state); |
Takashi Iwai | 1835a0f | 2011-10-27 22:12:46 +0200 | [diff] [blame] | 235 | |
| 236 | /** |
| 237 | * snd_hda_jack_detect_enable - enable the jack-detection |
Takashi Iwai | a11e9b1 | 2014-10-29 15:06:01 +0100 | [diff] [blame] | 238 | * @codec: the HDA codec |
| 239 | * @nid: pin NID to enable |
| 240 | * @func: callback function to register |
Takashi Iwai | bda17b82 | 2014-09-11 14:39:09 +0200 | [diff] [blame] | 241 | * |
| 242 | * In the case of error, the return value will be a pointer embedded with |
| 243 | * errno. Check and handle the return value appropriately with standard |
| 244 | * macros such as @IS_ERR() and @PTR_ERR(). |
Takashi Iwai | 1835a0f | 2011-10-27 22:12:46 +0200 | [diff] [blame] | 245 | */ |
Takashi Iwai | 1a4f69d | 2014-09-11 15:22:46 +0200 | [diff] [blame] | 246 | struct hda_jack_callback * |
Takashi Iwai | bda17b82 | 2014-09-11 14:39:09 +0200 | [diff] [blame] | 247 | snd_hda_jack_detect_enable_callback(struct hda_codec *codec, hda_nid_t nid, |
Takashi Iwai | 1a4f69d | 2014-09-11 15:22:46 +0200 | [diff] [blame] | 248 | hda_jack_callback_fn func) |
Takashi Iwai | 1835a0f | 2011-10-27 22:12:46 +0200 | [diff] [blame] | 249 | { |
Takashi Iwai | 1a4f69d | 2014-09-11 15:22:46 +0200 | [diff] [blame] | 250 | struct hda_jack_tbl *jack; |
| 251 | struct hda_jack_callback *callback = NULL; |
Takashi Iwai | bda17b82 | 2014-09-11 14:39:09 +0200 | [diff] [blame] | 252 | int err; |
| 253 | |
Takashi Iwai | 1a4f69d | 2014-09-11 15:22:46 +0200 | [diff] [blame] | 254 | jack = snd_hda_jack_tbl_new(codec, nid); |
Takashi Iwai | 1835a0f | 2011-10-27 22:12:46 +0200 | [diff] [blame] | 255 | if (!jack) |
Takashi Iwai | bda17b82 | 2014-09-11 14:39:09 +0200 | [diff] [blame] | 256 | return ERR_PTR(-ENOMEM); |
Takashi Iwai | 1a4f69d | 2014-09-11 15:22:46 +0200 | [diff] [blame] | 257 | if (func) { |
| 258 | callback = kzalloc(sizeof(*callback), GFP_KERNEL); |
| 259 | if (!callback) |
| 260 | return ERR_PTR(-ENOMEM); |
| 261 | callback->func = func; |
| 262 | callback->tbl = jack; |
| 263 | callback->next = jack->callback; |
| 264 | jack->callback = callback; |
| 265 | } |
| 266 | |
Takashi Iwai | 3a93897 | 2011-10-28 01:16:55 +0200 | [diff] [blame] | 267 | if (jack->jack_detect) |
Takashi Iwai | 1a4f69d | 2014-09-11 15:22:46 +0200 | [diff] [blame] | 268 | return callback; /* already registered */ |
Takashi Iwai | 3a93897 | 2011-10-28 01:16:55 +0200 | [diff] [blame] | 269 | jack->jack_detect = 1; |
David Henningsson | 34a9318 | 2012-10-17 14:45:05 +0200 | [diff] [blame] | 270 | if (codec->jackpoll_interval > 0) |
Takashi Iwai | 1a4f69d | 2014-09-11 15:22:46 +0200 | [diff] [blame] | 271 | return callback; /* No unsol if we're polling instead */ |
Takashi Iwai | bda17b82 | 2014-09-11 14:39:09 +0200 | [diff] [blame] | 272 | err = snd_hda_codec_write_cache(codec, nid, 0, |
Takashi Iwai | 1835a0f | 2011-10-27 22:12:46 +0200 | [diff] [blame] | 273 | AC_VERB_SET_UNSOLICITED_ENABLE, |
Takashi Iwai | 3a93897 | 2011-10-28 01:16:55 +0200 | [diff] [blame] | 274 | AC_USRSP_EN | jack->tag); |
Takashi Iwai | bda17b82 | 2014-09-11 14:39:09 +0200 | [diff] [blame] | 275 | if (err < 0) |
| 276 | return ERR_PTR(err); |
Takashi Iwai | 1a4f69d | 2014-09-11 15:22:46 +0200 | [diff] [blame] | 277 | return callback; |
Takashi Iwai | 1835a0f | 2011-10-27 22:12:46 +0200 | [diff] [blame] | 278 | } |
Takashi Iwai | 2698ea9 | 2013-12-18 07:45:52 +0100 | [diff] [blame] | 279 | EXPORT_SYMBOL_GPL(snd_hda_jack_detect_enable_callback); |
David Henningsson | 954df2a | 2012-09-25 11:30:59 +0200 | [diff] [blame] | 280 | |
Takashi Iwai | 95a962c | 2014-10-29 16:03:58 +0100 | [diff] [blame] | 281 | /** |
| 282 | * snd_hda_jack_detect_enable - Enable the jack detection on the given pin |
| 283 | * @codec: the HDA codec |
| 284 | * @nid: pin NID to enable jack detection |
| 285 | * |
| 286 | * Enable the jack detection with the default callback. Returns zero if |
| 287 | * successful or a negative error code. |
| 288 | */ |
Takashi Iwai | 62f949b | 2014-09-11 14:06:53 +0200 | [diff] [blame] | 289 | int snd_hda_jack_detect_enable(struct hda_codec *codec, hda_nid_t nid) |
David Henningsson | 954df2a | 2012-09-25 11:30:59 +0200 | [diff] [blame] | 290 | { |
Takashi Iwai | bda17b82 | 2014-09-11 14:39:09 +0200 | [diff] [blame] | 291 | return PTR_ERR_OR_ZERO(snd_hda_jack_detect_enable_callback(codec, nid, NULL)); |
David Henningsson | 954df2a | 2012-09-25 11:30:59 +0200 | [diff] [blame] | 292 | } |
Takashi Iwai | 2698ea9 | 2013-12-18 07:45:52 +0100 | [diff] [blame] | 293 | EXPORT_SYMBOL_GPL(snd_hda_jack_detect_enable); |
Takashi Iwai | 01a61e1 | 2011-10-28 00:03:22 +0200 | [diff] [blame] | 294 | |
Takashi Iwai | 01a61e1 | 2011-10-28 00:03:22 +0200 | [diff] [blame] | 295 | /** |
Dylan Reid | 0619ba8 | 2012-11-19 19:48:07 +0100 | [diff] [blame] | 296 | * snd_hda_jack_set_gating_jack - Set gating jack. |
Takashi Iwai | a11e9b1 | 2014-10-29 15:06:01 +0100 | [diff] [blame] | 297 | * @codec: the HDA codec |
| 298 | * @gated_nid: gated pin NID |
| 299 | * @gating_nid: gating pin NID |
Dylan Reid | 0619ba8 | 2012-11-19 19:48:07 +0100 | [diff] [blame] | 300 | * |
| 301 | * Indicates the gated jack is only valid when the gating jack is plugged. |
| 302 | */ |
| 303 | int snd_hda_jack_set_gating_jack(struct hda_codec *codec, hda_nid_t gated_nid, |
| 304 | hda_nid_t gating_nid) |
| 305 | { |
Chih-Chung Chang | bde7bc6 | 2013-08-05 16:38:42 +0800 | [diff] [blame] | 306 | struct hda_jack_tbl *gated = snd_hda_jack_tbl_new(codec, gated_nid); |
| 307 | struct hda_jack_tbl *gating = snd_hda_jack_tbl_new(codec, gating_nid); |
Dylan Reid | 0619ba8 | 2012-11-19 19:48:07 +0100 | [diff] [blame] | 308 | |
| 309 | if (!gated || !gating) |
| 310 | return -EINVAL; |
| 311 | |
| 312 | gated->gating_jack = gating_nid; |
| 313 | gating->gated_jack = gated_nid; |
| 314 | |
| 315 | return 0; |
| 316 | } |
Takashi Iwai | 2698ea9 | 2013-12-18 07:45:52 +0100 | [diff] [blame] | 317 | EXPORT_SYMBOL_GPL(snd_hda_jack_set_gating_jack); |
Dylan Reid | 0619ba8 | 2012-11-19 19:48:07 +0100 | [diff] [blame] | 318 | |
| 319 | /** |
Takashi Iwai | 01a61e1 | 2011-10-28 00:03:22 +0200 | [diff] [blame] | 320 | * snd_hda_jack_report_sync - sync the states of all jacks and report if changed |
Takashi Iwai | a11e9b1 | 2014-10-29 15:06:01 +0100 | [diff] [blame] | 321 | * @codec: the HDA codec |
Takashi Iwai | 01a61e1 | 2011-10-28 00:03:22 +0200 | [diff] [blame] | 322 | */ |
| 323 | void snd_hda_jack_report_sync(struct hda_codec *codec) |
| 324 | { |
Dylan Reid | 0619ba8 | 2012-11-19 19:48:07 +0100 | [diff] [blame] | 325 | struct hda_jack_tbl *jack; |
Takashi Iwai | 35be544 | 2011-11-02 08:36:06 +0100 | [diff] [blame] | 326 | int i, state; |
Takashi Iwai | 01a61e1 | 2011-10-28 00:03:22 +0200 | [diff] [blame] | 327 | |
Dylan Reid | 0619ba8 | 2012-11-19 19:48:07 +0100 | [diff] [blame] | 328 | /* update all jacks at first */ |
| 329 | jack = codec->jacktbl.list; |
| 330 | for (i = 0; i < codec->jacktbl.used; i++, jack++) |
| 331 | if (jack->nid) |
| 332 | jack_detect_update(codec, jack); |
| 333 | |
| 334 | /* report the updated jacks; it's done after updating all jacks |
| 335 | * to make sure that all gating jacks properly have been set |
| 336 | */ |
| 337 | jack = codec->jacktbl.list; |
Takashi Iwai | 01a61e1 | 2011-10-28 00:03:22 +0200 | [diff] [blame] | 338 | for (i = 0; i < codec->jacktbl.used; i++, jack++) |
| 339 | if (jack->nid) { |
David Henningsson | 0f56895 | 2013-11-07 13:38:24 +0100 | [diff] [blame] | 340 | if (!jack->kctl || jack->block_report) |
Takashi Iwai | cfc7c9d | 2011-11-11 17:53:03 +0100 | [diff] [blame] | 341 | continue; |
Takashi Iwai | 35be544 | 2011-11-02 08:36:06 +0100 | [diff] [blame] | 342 | state = get_jack_plug_state(jack->pin_sense); |
Takashi Iwai | aad37db | 2011-11-02 08:54:51 +0100 | [diff] [blame] | 343 | snd_kctl_jack_report(codec->bus->card, jack->kctl, state); |
Takashi Iwai | 31ef225 | 2011-12-01 17:41:36 +0100 | [diff] [blame] | 344 | #ifdef CONFIG_SND_HDA_INPUT_JACK |
| 345 | if (jack->jack) |
| 346 | snd_jack_report(jack->jack, |
| 347 | state ? jack->type : 0); |
| 348 | #endif |
Takashi Iwai | 01a61e1 | 2011-10-28 00:03:22 +0200 | [diff] [blame] | 349 | } |
| 350 | } |
Takashi Iwai | 2698ea9 | 2013-12-18 07:45:52 +0100 | [diff] [blame] | 351 | EXPORT_SYMBOL_GPL(snd_hda_jack_report_sync); |
Takashi Iwai | 01a61e1 | 2011-10-28 00:03:22 +0200 | [diff] [blame] | 352 | |
Takashi Iwai | 31ef225 | 2011-12-01 17:41:36 +0100 | [diff] [blame] | 353 | #ifdef CONFIG_SND_HDA_INPUT_JACK |
| 354 | /* guess the jack type from the pin-config */ |
| 355 | static int get_input_jack_type(struct hda_codec *codec, hda_nid_t nid) |
| 356 | { |
| 357 | unsigned int def_conf = snd_hda_codec_get_pincfg(codec, nid); |
| 358 | switch (get_defcfg_device(def_conf)) { |
| 359 | case AC_JACK_LINE_OUT: |
| 360 | case AC_JACK_SPEAKER: |
| 361 | return SND_JACK_LINEOUT; |
| 362 | case AC_JACK_HP_OUT: |
| 363 | return SND_JACK_HEADPHONE; |
| 364 | case AC_JACK_SPDIF_OUT: |
| 365 | case AC_JACK_DIG_OTHER_OUT: |
| 366 | return SND_JACK_AVOUT; |
| 367 | case AC_JACK_MIC_IN: |
| 368 | return SND_JACK_MICROPHONE; |
| 369 | default: |
| 370 | return SND_JACK_LINEIN; |
| 371 | } |
| 372 | } |
| 373 | |
| 374 | static void hda_free_jack_priv(struct snd_jack *jack) |
| 375 | { |
| 376 | struct hda_jack_tbl *jacks = jack->private_data; |
| 377 | jacks->nid = 0; |
| 378 | jacks->jack = NULL; |
| 379 | } |
| 380 | #endif |
| 381 | |
Takashi Iwai | 01a61e1 | 2011-10-28 00:03:22 +0200 | [diff] [blame] | 382 | /** |
| 383 | * snd_hda_jack_add_kctl - Add a kctl for the given pin |
Takashi Iwai | a11e9b1 | 2014-10-29 15:06:01 +0100 | [diff] [blame] | 384 | * @codec: the HDA codec |
| 385 | * @nid: pin NID to assign |
| 386 | * @name: string name for the jack |
| 387 | * @idx: index number for the jack |
| 388 | * @phantom_jack: flag to deal as a phantom jack |
Takashi Iwai | 01a61e1 | 2011-10-28 00:03:22 +0200 | [diff] [blame] | 389 | * |
| 390 | * This assigns a jack-detection kctl to the given pin. The kcontrol |
| 391 | * will have the given name and index. |
| 392 | */ |
David Henningsson | 80c8bfb | 2012-06-04 09:33:51 +0200 | [diff] [blame] | 393 | static int __snd_hda_jack_add_kctl(struct hda_codec *codec, hda_nid_t nid, |
| 394 | const char *name, int idx, bool phantom_jack) |
Takashi Iwai | 01a61e1 | 2011-10-28 00:03:22 +0200 | [diff] [blame] | 395 | { |
| 396 | struct hda_jack_tbl *jack; |
| 397 | struct snd_kcontrol *kctl; |
Takashi Iwai | 31ef225 | 2011-12-01 17:41:36 +0100 | [diff] [blame] | 398 | int err, state; |
Takashi Iwai | 01a61e1 | 2011-10-28 00:03:22 +0200 | [diff] [blame] | 399 | |
Takashi Iwai | 3a93897 | 2011-10-28 01:16:55 +0200 | [diff] [blame] | 400 | jack = snd_hda_jack_tbl_new(codec, nid); |
Takashi Iwai | 01a61e1 | 2011-10-28 00:03:22 +0200 | [diff] [blame] | 401 | if (!jack) |
| 402 | return 0; |
| 403 | if (jack->kctl) |
| 404 | return 0; /* already created */ |
Takashi Iwai | 35be544 | 2011-11-02 08:36:06 +0100 | [diff] [blame] | 405 | kctl = snd_kctl_jack_new(name, idx, codec); |
Takashi Iwai | 01a61e1 | 2011-10-28 00:03:22 +0200 | [diff] [blame] | 406 | if (!kctl) |
| 407 | return -ENOMEM; |
Takashi Iwai | 31ef225 | 2011-12-01 17:41:36 +0100 | [diff] [blame] | 408 | err = snd_hda_ctl_add(codec, nid, kctl); |
| 409 | if (err < 0) |
| 410 | return err; |
Takashi Iwai | 01a61e1 | 2011-10-28 00:03:22 +0200 | [diff] [blame] | 411 | jack->kctl = kctl; |
David Henningsson | 80c8bfb | 2012-06-04 09:33:51 +0200 | [diff] [blame] | 412 | jack->phantom_jack = !!phantom_jack; |
| 413 | |
Takashi Iwai | 31ef225 | 2011-12-01 17:41:36 +0100 | [diff] [blame] | 414 | state = snd_hda_jack_detect(codec, nid); |
| 415 | snd_kctl_jack_report(codec->bus->card, kctl, state); |
| 416 | #ifdef CONFIG_SND_HDA_INPUT_JACK |
David Henningsson | 80c8bfb | 2012-06-04 09:33:51 +0200 | [diff] [blame] | 417 | if (!phantom_jack) { |
| 418 | jack->type = get_input_jack_type(codec, nid); |
| 419 | err = snd_jack_new(codec->bus->card, name, jack->type, |
| 420 | &jack->jack); |
| 421 | if (err < 0) |
| 422 | return err; |
| 423 | jack->jack->private_data = jack; |
| 424 | jack->jack->private_free = hda_free_jack_priv; |
| 425 | snd_jack_report(jack->jack, state ? jack->type : 0); |
| 426 | } |
Takashi Iwai | 31ef225 | 2011-12-01 17:41:36 +0100 | [diff] [blame] | 427 | #endif |
Takashi Iwai | 01a61e1 | 2011-10-28 00:03:22 +0200 | [diff] [blame] | 428 | return 0; |
| 429 | } |
David Henningsson | 80c8bfb | 2012-06-04 09:33:51 +0200 | [diff] [blame] | 430 | |
Takashi Iwai | 95a962c | 2014-10-29 16:03:58 +0100 | [diff] [blame] | 431 | /** |
| 432 | * snd_hda_jack_add_kctl - Add a jack kctl for the given pin |
| 433 | * @codec: the HDA codec |
| 434 | * @nid: pin NID |
| 435 | * @name: the name string for the jack ctl |
| 436 | * @idx: the ctl index for the jack ctl |
| 437 | * |
| 438 | * This is a simple helper calling __snd_hda_jack_add_kctl(). |
| 439 | */ |
David Henningsson | 80c8bfb | 2012-06-04 09:33:51 +0200 | [diff] [blame] | 440 | int snd_hda_jack_add_kctl(struct hda_codec *codec, hda_nid_t nid, |
| 441 | const char *name, int idx) |
| 442 | { |
| 443 | return __snd_hda_jack_add_kctl(codec, nid, name, idx, false); |
| 444 | } |
Takashi Iwai | 2698ea9 | 2013-12-18 07:45:52 +0100 | [diff] [blame] | 445 | EXPORT_SYMBOL_GPL(snd_hda_jack_add_kctl); |
Takashi Iwai | 01a61e1 | 2011-10-28 00:03:22 +0200 | [diff] [blame] | 446 | |
Takashi Iwai | f46c329 | 2012-07-17 16:48:27 +0200 | [diff] [blame] | 447 | /* get the unique index number for the given kctl name */ |
| 448 | static int get_unique_index(struct hda_codec *codec, const char *name, int idx) |
| 449 | { |
| 450 | struct hda_jack_tbl *jack; |
| 451 | int i, len = strlen(name); |
| 452 | again: |
| 453 | jack = codec->jacktbl.list; |
| 454 | for (i = 0; i < codec->jacktbl.used; i++, jack++) { |
| 455 | /* jack->kctl.id contains "XXX Jack" name string with index */ |
| 456 | if (jack->kctl && |
| 457 | !strncmp(name, jack->kctl->id.name, len) && |
| 458 | !strcmp(" Jack", jack->kctl->id.name + len) && |
| 459 | jack->kctl->id.index == idx) { |
| 460 | idx++; |
| 461 | goto again; |
| 462 | } |
| 463 | } |
| 464 | return idx; |
| 465 | } |
| 466 | |
Takashi Iwai | 201e06f | 2011-11-16 15:33:26 +0100 | [diff] [blame] | 467 | static int add_jack_kctl(struct hda_codec *codec, hda_nid_t nid, |
David Henningsson | b26b511 | 2013-04-11 11:30:30 +0200 | [diff] [blame] | 468 | const struct auto_pin_cfg *cfg, |
| 469 | const char *base_name) |
Takashi Iwai | 01a61e1 | 2011-10-28 00:03:22 +0200 | [diff] [blame] | 470 | { |
Takashi Iwai | 3a93897 | 2011-10-28 01:16:55 +0200 | [diff] [blame] | 471 | unsigned int def_conf, conn; |
Takashi Iwai | 975cc02 | 2013-06-28 11:56:49 +0200 | [diff] [blame] | 472 | char name[SNDRV_CTL_ELEM_ID_NAME_MAXLEN]; |
Takashi Iwai | 201e06f | 2011-11-16 15:33:26 +0100 | [diff] [blame] | 473 | int idx, err; |
David Henningsson | 80c8bfb | 2012-06-04 09:33:51 +0200 | [diff] [blame] | 474 | bool phantom_jack; |
Takashi Iwai | 3a93897 | 2011-10-28 01:16:55 +0200 | [diff] [blame] | 475 | |
Takashi Iwai | 01a61e1 | 2011-10-28 00:03:22 +0200 | [diff] [blame] | 476 | if (!nid) |
| 477 | return 0; |
Takashi Iwai | 3a93897 | 2011-10-28 01:16:55 +0200 | [diff] [blame] | 478 | def_conf = snd_hda_codec_get_pincfg(codec, nid); |
| 479 | conn = get_defcfg_connect(def_conf); |
David Henningsson | 80c8bfb | 2012-06-04 09:33:51 +0200 | [diff] [blame] | 480 | if (conn == AC_JACK_PORT_NONE) |
Takashi Iwai | 3a93897 | 2011-10-28 01:16:55 +0200 | [diff] [blame] | 481 | return 0; |
David Henningsson | 80c8bfb | 2012-06-04 09:33:51 +0200 | [diff] [blame] | 482 | phantom_jack = (conn != AC_JACK_PORT_COMPLEX) || |
| 483 | !is_jack_detectable(codec, nid); |
Takashi Iwai | 3a93897 | 2011-10-28 01:16:55 +0200 | [diff] [blame] | 484 | |
David Henningsson | b26b511 | 2013-04-11 11:30:30 +0200 | [diff] [blame] | 485 | if (base_name) { |
| 486 | strlcpy(name, base_name, sizeof(name)); |
| 487 | idx = 0; |
| 488 | } else |
| 489 | snd_hda_get_pin_label(codec, nid, cfg, name, sizeof(name), &idx); |
David Henningsson | 80c8bfb | 2012-06-04 09:33:51 +0200 | [diff] [blame] | 490 | if (phantom_jack) |
| 491 | /* Example final name: "Internal Mic Phantom Jack" */ |
| 492 | strncat(name, " Phantom", sizeof(name) - strlen(name) - 1); |
Takashi Iwai | f46c329 | 2012-07-17 16:48:27 +0200 | [diff] [blame] | 493 | idx = get_unique_index(codec, name, idx); |
David Henningsson | 80c8bfb | 2012-06-04 09:33:51 +0200 | [diff] [blame] | 494 | err = __snd_hda_jack_add_kctl(codec, nid, name, idx, phantom_jack); |
Takashi Iwai | 3a93897 | 2011-10-28 01:16:55 +0200 | [diff] [blame] | 495 | if (err < 0) |
| 496 | return err; |
David Henningsson | 80c8bfb | 2012-06-04 09:33:51 +0200 | [diff] [blame] | 497 | |
| 498 | if (!phantom_jack) |
Takashi Iwai | 62f949b | 2014-09-11 14:06:53 +0200 | [diff] [blame] | 499 | return snd_hda_jack_detect_enable(codec, nid); |
David Henningsson | 80c8bfb | 2012-06-04 09:33:51 +0200 | [diff] [blame] | 500 | return 0; |
Takashi Iwai | 01a61e1 | 2011-10-28 00:03:22 +0200 | [diff] [blame] | 501 | } |
| 502 | |
| 503 | /** |
| 504 | * snd_hda_jack_add_kctls - Add kctls for all pins included in the given pincfg |
Takashi Iwai | a11e9b1 | 2014-10-29 15:06:01 +0100 | [diff] [blame] | 505 | * @codec: the HDA codec |
| 506 | * @cfg: pin config table to parse |
Takashi Iwai | 01a61e1 | 2011-10-28 00:03:22 +0200 | [diff] [blame] | 507 | */ |
| 508 | int snd_hda_jack_add_kctls(struct hda_codec *codec, |
| 509 | const struct auto_pin_cfg *cfg) |
| 510 | { |
| 511 | const hda_nid_t *p; |
Takashi Iwai | f46c329 | 2012-07-17 16:48:27 +0200 | [diff] [blame] | 512 | int i, err; |
Takashi Iwai | 01a61e1 | 2011-10-28 00:03:22 +0200 | [diff] [blame] | 513 | |
David Henningsson | b26b511 | 2013-04-11 11:30:30 +0200 | [diff] [blame] | 514 | for (i = 0; i < cfg->num_inputs; i++) { |
| 515 | /* If we have headphone mics; make sure they get the right name |
| 516 | before grabbed by output pins */ |
| 517 | if (cfg->inputs[i].is_headphone_mic) { |
| 518 | if (auto_cfg_hp_outs(cfg) == 1) |
| 519 | err = add_jack_kctl(codec, auto_cfg_hp_pins(cfg)[0], |
| 520 | cfg, "Headphone Mic"); |
| 521 | else |
| 522 | err = add_jack_kctl(codec, cfg->inputs[i].pin, |
| 523 | cfg, "Headphone Mic"); |
| 524 | } else |
| 525 | err = add_jack_kctl(codec, cfg->inputs[i].pin, cfg, |
| 526 | NULL); |
| 527 | if (err < 0) |
| 528 | return err; |
| 529 | } |
| 530 | |
Takashi Iwai | 01a61e1 | 2011-10-28 00:03:22 +0200 | [diff] [blame] | 531 | for (i = 0, p = cfg->line_out_pins; i < cfg->line_outs; i++, p++) { |
David Henningsson | b26b511 | 2013-04-11 11:30:30 +0200 | [diff] [blame] | 532 | err = add_jack_kctl(codec, *p, cfg, NULL); |
Takashi Iwai | 01a61e1 | 2011-10-28 00:03:22 +0200 | [diff] [blame] | 533 | if (err < 0) |
| 534 | return err; |
| 535 | } |
| 536 | for (i = 0, p = cfg->hp_pins; i < cfg->hp_outs; i++, p++) { |
| 537 | if (*p == *cfg->line_out_pins) /* might be duplicated */ |
| 538 | break; |
David Henningsson | b26b511 | 2013-04-11 11:30:30 +0200 | [diff] [blame] | 539 | err = add_jack_kctl(codec, *p, cfg, NULL); |
Takashi Iwai | 01a61e1 | 2011-10-28 00:03:22 +0200 | [diff] [blame] | 540 | if (err < 0) |
| 541 | return err; |
| 542 | } |
| 543 | for (i = 0, p = cfg->speaker_pins; i < cfg->speaker_outs; i++, p++) { |
| 544 | if (*p == *cfg->line_out_pins) /* might be duplicated */ |
| 545 | break; |
David Henningsson | b26b511 | 2013-04-11 11:30:30 +0200 | [diff] [blame] | 546 | err = add_jack_kctl(codec, *p, cfg, NULL); |
Takashi Iwai | 01a61e1 | 2011-10-28 00:03:22 +0200 | [diff] [blame] | 547 | if (err < 0) |
| 548 | return err; |
| 549 | } |
| 550 | for (i = 0, p = cfg->dig_out_pins; i < cfg->dig_outs; i++, p++) { |
David Henningsson | b26b511 | 2013-04-11 11:30:30 +0200 | [diff] [blame] | 551 | err = add_jack_kctl(codec, *p, cfg, NULL); |
Takashi Iwai | 01a61e1 | 2011-10-28 00:03:22 +0200 | [diff] [blame] | 552 | if (err < 0) |
| 553 | return err; |
| 554 | } |
David Henningsson | b26b511 | 2013-04-11 11:30:30 +0200 | [diff] [blame] | 555 | err = add_jack_kctl(codec, cfg->dig_in_pin, cfg, NULL); |
Takashi Iwai | 01a61e1 | 2011-10-28 00:03:22 +0200 | [diff] [blame] | 556 | if (err < 0) |
| 557 | return err; |
David Henningsson | b26b511 | 2013-04-11 11:30:30 +0200 | [diff] [blame] | 558 | err = add_jack_kctl(codec, cfg->mono_out_pin, cfg, NULL); |
Takashi Iwai | 01a61e1 | 2011-10-28 00:03:22 +0200 | [diff] [blame] | 559 | if (err < 0) |
| 560 | return err; |
| 561 | return 0; |
| 562 | } |
Takashi Iwai | 2698ea9 | 2013-12-18 07:45:52 +0100 | [diff] [blame] | 563 | EXPORT_SYMBOL_GPL(snd_hda_jack_add_kctls); |
David Henningsson | 954df2a | 2012-09-25 11:30:59 +0200 | [diff] [blame] | 564 | |
Dylan Reid | 0619ba8 | 2012-11-19 19:48:07 +0100 | [diff] [blame] | 565 | static void call_jack_callback(struct hda_codec *codec, |
| 566 | struct hda_jack_tbl *jack) |
| 567 | { |
Takashi Iwai | 1a4f69d | 2014-09-11 15:22:46 +0200 | [diff] [blame] | 568 | struct hda_jack_callback *cb; |
| 569 | |
| 570 | for (cb = jack->callback; cb; cb = cb->next) |
| 571 | cb->func(codec, cb); |
Dylan Reid | 0619ba8 | 2012-11-19 19:48:07 +0100 | [diff] [blame] | 572 | if (jack->gated_jack) { |
| 573 | struct hda_jack_tbl *gated = |
| 574 | snd_hda_jack_tbl_get(codec, jack->gated_jack); |
Takashi Iwai | 1a4f69d | 2014-09-11 15:22:46 +0200 | [diff] [blame] | 575 | if (gated) { |
| 576 | for (cb = gated->callback; cb; cb = cb->next) |
| 577 | cb->func(codec, cb); |
| 578 | } |
Dylan Reid | 0619ba8 | 2012-11-19 19:48:07 +0100 | [diff] [blame] | 579 | } |
| 580 | } |
| 581 | |
Takashi Iwai | 95a962c | 2014-10-29 16:03:58 +0100 | [diff] [blame] | 582 | /** |
| 583 | * snd_hda_jack_unsol_event - Handle an unsolicited event |
| 584 | * @codec: the HDA codec |
| 585 | * @res: the unsolicited event data |
| 586 | */ |
David Henningsson | 954df2a | 2012-09-25 11:30:59 +0200 | [diff] [blame] | 587 | void snd_hda_jack_unsol_event(struct hda_codec *codec, unsigned int res) |
| 588 | { |
| 589 | struct hda_jack_tbl *event; |
| 590 | int tag = (res >> AC_UNSOL_RES_TAG_SHIFT) & 0x7f; |
| 591 | |
| 592 | event = snd_hda_jack_tbl_get_from_tag(codec, tag); |
| 593 | if (!event) |
| 594 | return; |
| 595 | event->jack_dirty = 1; |
| 596 | |
Dylan Reid | 0619ba8 | 2012-11-19 19:48:07 +0100 | [diff] [blame] | 597 | call_jack_callback(codec, event); |
David Henningsson | 954df2a | 2012-09-25 11:30:59 +0200 | [diff] [blame] | 598 | snd_hda_jack_report_sync(codec); |
| 599 | } |
Takashi Iwai | 2698ea9 | 2013-12-18 07:45:52 +0100 | [diff] [blame] | 600 | EXPORT_SYMBOL_GPL(snd_hda_jack_unsol_event); |
David Henningsson | 954df2a | 2012-09-25 11:30:59 +0200 | [diff] [blame] | 601 | |
Takashi Iwai | 95a962c | 2014-10-29 16:03:58 +0100 | [diff] [blame] | 602 | /** |
| 603 | * snd_hda_jack_poll_all - Poll all jacks |
| 604 | * @codec: the HDA codec |
| 605 | * |
| 606 | * Poll all detectable jacks with dirty flag, update the status, call |
| 607 | * callbacks and call snd_hda_jack_report_sync() if any changes are found. |
| 608 | */ |
David Henningsson | 26a6cb6 | 2012-10-09 15:04:21 +0200 | [diff] [blame] | 609 | void snd_hda_jack_poll_all(struct hda_codec *codec) |
| 610 | { |
| 611 | struct hda_jack_tbl *jack = codec->jacktbl.list; |
| 612 | int i, changes = 0; |
| 613 | |
| 614 | for (i = 0; i < codec->jacktbl.used; i++, jack++) { |
| 615 | unsigned int old_sense; |
| 616 | if (!jack->nid || !jack->jack_dirty || jack->phantom_jack) |
| 617 | continue; |
| 618 | old_sense = get_jack_plug_state(jack->pin_sense); |
| 619 | jack_detect_update(codec, jack); |
| 620 | if (old_sense == get_jack_plug_state(jack->pin_sense)) |
| 621 | continue; |
| 622 | changes = 1; |
Dylan Reid | 0619ba8 | 2012-11-19 19:48:07 +0100 | [diff] [blame] | 623 | call_jack_callback(codec, jack); |
David Henningsson | 26a6cb6 | 2012-10-09 15:04:21 +0200 | [diff] [blame] | 624 | } |
| 625 | if (changes) |
| 626 | snd_hda_jack_report_sync(codec); |
| 627 | } |
Takashi Iwai | 2698ea9 | 2013-12-18 07:45:52 +0100 | [diff] [blame] | 628 | EXPORT_SYMBOL_GPL(snd_hda_jack_poll_all); |
David Henningsson | 26a6cb6 | 2012-10-09 15:04:21 +0200 | [diff] [blame] | 629 | |