hda_jack.h 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. /* SPDX-License-Identifier: GPL-2.0-or-later */
  2. /*
  3. * Jack-detection handling for HD-audio
  4. *
  5. * Copyright (c) 2011 Takashi Iwai <[email protected]>
  6. */
  7. #ifndef __SOUND_HDA_JACK_H
  8. #define __SOUND_HDA_JACK_H
  9. #include <linux/err.h>
  10. #include <sound/jack.h>
  11. struct auto_pin_cfg;
  12. struct hda_jack_tbl;
  13. struct hda_jack_callback;
  14. typedef void (*hda_jack_callback_fn) (struct hda_codec *, struct hda_jack_callback *);
  15. struct hda_jack_callback {
  16. hda_nid_t nid;
  17. int dev_id;
  18. hda_jack_callback_fn func;
  19. unsigned int private_data; /* arbitrary data */
  20. unsigned int unsol_res; /* unsolicited event bits */
  21. struct hda_jack_tbl *jack; /* associated jack entry */
  22. struct hda_jack_callback *next;
  23. };
  24. struct hda_jack_tbl {
  25. hda_nid_t nid;
  26. int dev_id;
  27. unsigned char tag; /* unsol event tag */
  28. struct hda_jack_callback *callback;
  29. /* jack-detection stuff */
  30. unsigned int pin_sense; /* cached pin-sense value */
  31. unsigned int jack_detect:1; /* capable of jack-detection? */
  32. unsigned int jack_dirty:1; /* needs to update? */
  33. unsigned int phantom_jack:1; /* a fixed, always present port? */
  34. unsigned int block_report:1; /* in a transitional state - do not report to userspace */
  35. hda_nid_t gating_jack; /* valid when gating jack plugged */
  36. hda_nid_t gated_jack; /* gated is dependent on this jack */
  37. hda_nid_t key_report_jack; /* key reports to this jack */
  38. int type;
  39. int button_state;
  40. struct snd_jack *jack;
  41. };
  42. struct hda_jack_keymap {
  43. enum snd_jack_types type;
  44. int key;
  45. };
  46. struct hda_jack_tbl *
  47. snd_hda_jack_tbl_get_mst(struct hda_codec *codec, hda_nid_t nid, int dev_id);
  48. /**
  49. * snd_hda_jack_tbl_get - query the jack-table entry for the given NID
  50. * @codec: the HDA codec
  51. * @nid: pin NID to refer to
  52. */
  53. static inline struct hda_jack_tbl *
  54. snd_hda_jack_tbl_get(struct hda_codec *codec, hda_nid_t nid)
  55. {
  56. return snd_hda_jack_tbl_get_mst(codec, nid, 0);
  57. }
  58. struct hda_jack_tbl *
  59. snd_hda_jack_tbl_get_from_tag(struct hda_codec *codec,
  60. unsigned char tag, int dev_id);
  61. void snd_hda_jack_tbl_disconnect(struct hda_codec *codec);
  62. void snd_hda_jack_tbl_clear(struct hda_codec *codec);
  63. void snd_hda_jack_set_dirty_all(struct hda_codec *codec);
  64. int snd_hda_jack_detect_enable(struct hda_codec *codec, hda_nid_t nid,
  65. int dev_id);
  66. struct hda_jack_callback *
  67. snd_hda_jack_detect_enable_callback_mst(struct hda_codec *codec, hda_nid_t nid,
  68. int dev_id, hda_jack_callback_fn func);
  69. /**
  70. * snd_hda_jack_detect_enable - enable the jack-detection
  71. * @codec: the HDA codec
  72. * @nid: pin NID to enable
  73. * @func: callback function to register
  74. *
  75. * In the case of error, the return value will be a pointer embedded with
  76. * errno. Check and handle the return value appropriately with standard
  77. * macros such as @IS_ERR() and @PTR_ERR().
  78. */
  79. static inline struct hda_jack_callback *
  80. snd_hda_jack_detect_enable_callback(struct hda_codec *codec, hda_nid_t nid,
  81. hda_jack_callback_fn cb)
  82. {
  83. return snd_hda_jack_detect_enable_callback_mst(codec, nid, 0, cb);
  84. }
  85. int snd_hda_jack_set_gating_jack(struct hda_codec *codec, hda_nid_t gated_nid,
  86. hda_nid_t gating_nid);
  87. int snd_hda_jack_bind_keymap(struct hda_codec *codec, hda_nid_t key_nid,
  88. const struct hda_jack_keymap *keymap,
  89. hda_nid_t jack_nid);
  90. void snd_hda_jack_set_button_state(struct hda_codec *codec, hda_nid_t jack_nid,
  91. int button_state);
  92. u32 snd_hda_jack_pin_sense(struct hda_codec *codec, hda_nid_t nid, int dev_id);
  93. /* the jack state returned from snd_hda_jack_detect_state() */
  94. enum {
  95. HDA_JACK_NOT_PRESENT, HDA_JACK_PRESENT, HDA_JACK_PHANTOM,
  96. };
  97. int snd_hda_jack_detect_state_mst(struct hda_codec *codec, hda_nid_t nid,
  98. int dev_id);
  99. /**
  100. * snd_hda_jack_detect_state - query pin Presence Detect status
  101. * @codec: the CODEC to sense
  102. * @nid: the pin NID to sense
  103. *
  104. * Query and return the pin's Presence Detect status, as either
  105. * HDA_JACK_NOT_PRESENT, HDA_JACK_PRESENT or HDA_JACK_PHANTOM.
  106. */
  107. static inline int
  108. snd_hda_jack_detect_state(struct hda_codec *codec, hda_nid_t nid)
  109. {
  110. return snd_hda_jack_detect_state_mst(codec, nid, 0);
  111. }
  112. /**
  113. * snd_hda_jack_detect_mst - Detect the jack
  114. * @codec: the HDA codec
  115. * @nid: pin NID to check jack detection
  116. * @dev_id: pin device entry id
  117. */
  118. static inline bool
  119. snd_hda_jack_detect_mst(struct hda_codec *codec, hda_nid_t nid, int dev_id)
  120. {
  121. return snd_hda_jack_detect_state_mst(codec, nid, dev_id) !=
  122. HDA_JACK_NOT_PRESENT;
  123. }
  124. /**
  125. * snd_hda_jack_detect - Detect the jack
  126. * @codec: the HDA codec
  127. * @nid: pin NID to check jack detection
  128. */
  129. static inline bool
  130. snd_hda_jack_detect(struct hda_codec *codec, hda_nid_t nid)
  131. {
  132. return snd_hda_jack_detect_mst(codec, nid, 0);
  133. }
  134. bool is_jack_detectable(struct hda_codec *codec, hda_nid_t nid);
  135. int snd_hda_jack_add_kctl_mst(struct hda_codec *codec, hda_nid_t nid,
  136. int dev_id, const char *name, bool phantom_jack,
  137. int type, const struct hda_jack_keymap *keymap);
  138. /**
  139. * snd_hda_jack_add_kctl - Add a kctl for the given pin
  140. * @codec: the HDA codec
  141. * @nid: pin NID to assign
  142. * @name: string name for the jack
  143. * @phantom_jack: flag to deal as a phantom jack
  144. * @type: jack type bits to be reported, 0 for guessing from pincfg
  145. * @keymap: optional jack / key mapping
  146. *
  147. * This assigns a jack-detection kctl to the given pin. The kcontrol
  148. * will have the given name and index.
  149. */
  150. static inline int
  151. snd_hda_jack_add_kctl(struct hda_codec *codec, hda_nid_t nid,
  152. const char *name, bool phantom_jack,
  153. int type, const struct hda_jack_keymap *keymap)
  154. {
  155. return snd_hda_jack_add_kctl_mst(codec, nid, 0,
  156. name, phantom_jack, type, keymap);
  157. }
  158. int snd_hda_jack_add_kctls(struct hda_codec *codec,
  159. const struct auto_pin_cfg *cfg);
  160. void snd_hda_jack_report_sync(struct hda_codec *codec);
  161. void snd_hda_jack_unsol_event(struct hda_codec *codec, unsigned int res);
  162. void snd_hda_jack_poll_all(struct hda_codec *codec);
  163. #endif /* __SOUND_HDA_JACK_H */