hda_jack.c 17 KB

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