hda_local.h 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737
  1. /* SPDX-License-Identifier: GPL-2.0-or-later */
  2. /*
  3. * Universal Interface for Intel High Definition Audio Codec
  4. *
  5. * Local helper functions
  6. *
  7. * Copyright (c) 2004 Takashi Iwai <[email protected]>
  8. */
  9. #ifndef __SOUND_HDA_LOCAL_H
  10. #define __SOUND_HDA_LOCAL_H
  11. /* We abuse kcontrol_new.subdev field to pass the NID corresponding to
  12. * the given new control. If id.subdev has a bit flag HDA_SUBDEV_NID_FLAG,
  13. * snd_hda_ctl_add() takes the lower-bit subdev value as a valid NID.
  14. *
  15. * Note that the subdevice field is cleared again before the real registration
  16. * in snd_hda_ctl_add(), so that this value won't appear in the outside.
  17. */
  18. #define HDA_SUBDEV_NID_FLAG (1U << 31)
  19. #define HDA_SUBDEV_AMP_FLAG (1U << 30)
  20. /*
  21. * for mixer controls
  22. */
  23. #define HDA_COMPOSE_AMP_VAL_OFS(nid,chs,idx,dir,ofs) \
  24. ((nid) | ((chs)<<16) | ((dir)<<18) | ((idx)<<19) | ((ofs)<<23))
  25. #define HDA_AMP_VAL_MIN_MUTE (1<<29)
  26. #define HDA_COMPOSE_AMP_VAL(nid,chs,idx,dir) \
  27. HDA_COMPOSE_AMP_VAL_OFS(nid, chs, idx, dir, 0)
  28. /* mono volume with index (index=0,1,...) (channel=1,2) */
  29. #define HDA_CODEC_VOLUME_MONO_IDX(xname, xcidx, nid, channel, xindex, dir, flags) \
  30. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xcidx, \
  31. .subdevice = HDA_SUBDEV_AMP_FLAG, \
  32. .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | \
  33. SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
  34. SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK, \
  35. .info = snd_hda_mixer_amp_volume_info, \
  36. .get = snd_hda_mixer_amp_volume_get, \
  37. .put = snd_hda_mixer_amp_volume_put, \
  38. .tlv = { .c = snd_hda_mixer_amp_tlv }, \
  39. .private_value = HDA_COMPOSE_AMP_VAL(nid, channel, xindex, dir) | flags }
  40. /* stereo volume with index */
  41. #define HDA_CODEC_VOLUME_IDX(xname, xcidx, nid, xindex, direction) \
  42. HDA_CODEC_VOLUME_MONO_IDX(xname, xcidx, nid, 3, xindex, direction, 0)
  43. /* mono volume */
  44. #define HDA_CODEC_VOLUME_MONO(xname, nid, channel, xindex, direction) \
  45. HDA_CODEC_VOLUME_MONO_IDX(xname, 0, nid, channel, xindex, direction, 0)
  46. /* stereo volume */
  47. #define HDA_CODEC_VOLUME(xname, nid, xindex, direction) \
  48. HDA_CODEC_VOLUME_MONO(xname, nid, 3, xindex, direction)
  49. /* stereo volume with min=mute */
  50. #define HDA_CODEC_VOLUME_MIN_MUTE(xname, nid, xindex, direction) \
  51. HDA_CODEC_VOLUME_MONO_IDX(xname, 0, nid, 3, xindex, direction, \
  52. HDA_AMP_VAL_MIN_MUTE)
  53. /* mono mute switch with index (index=0,1,...) (channel=1,2) */
  54. #define HDA_CODEC_MUTE_MONO_IDX(xname, xcidx, nid, channel, xindex, direction) \
  55. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xcidx, \
  56. .subdevice = HDA_SUBDEV_AMP_FLAG, \
  57. .info = snd_hda_mixer_amp_switch_info, \
  58. .get = snd_hda_mixer_amp_switch_get, \
  59. .put = snd_hda_mixer_amp_switch_put, \
  60. .private_value = HDA_COMPOSE_AMP_VAL(nid, channel, xindex, direction) }
  61. /* stereo mute switch with index */
  62. #define HDA_CODEC_MUTE_IDX(xname, xcidx, nid, xindex, direction) \
  63. HDA_CODEC_MUTE_MONO_IDX(xname, xcidx, nid, 3, xindex, direction)
  64. /* mono mute switch */
  65. #define HDA_CODEC_MUTE_MONO(xname, nid, channel, xindex, direction) \
  66. HDA_CODEC_MUTE_MONO_IDX(xname, 0, nid, channel, xindex, direction)
  67. /* stereo mute switch */
  68. #define HDA_CODEC_MUTE(xname, nid, xindex, direction) \
  69. HDA_CODEC_MUTE_MONO(xname, nid, 3, xindex, direction)
  70. #ifdef CONFIG_SND_HDA_INPUT_BEEP
  71. /* special beep mono mute switch with index (index=0,1,...) (channel=1,2) */
  72. #define HDA_CODEC_MUTE_BEEP_MONO_IDX(xname, xcidx, nid, channel, xindex, direction) \
  73. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xcidx, \
  74. .subdevice = HDA_SUBDEV_AMP_FLAG, \
  75. .info = snd_hda_mixer_amp_switch_info, \
  76. .get = snd_hda_mixer_amp_switch_get_beep, \
  77. .put = snd_hda_mixer_amp_switch_put_beep, \
  78. .private_value = HDA_COMPOSE_AMP_VAL(nid, channel, xindex, direction) }
  79. #else
  80. /* no digital beep - just the standard one */
  81. #define HDA_CODEC_MUTE_BEEP_MONO_IDX(xname, xcidx, nid, ch, xidx, dir) \
  82. HDA_CODEC_MUTE_MONO_IDX(xname, xcidx, nid, ch, xidx, dir)
  83. #endif /* CONFIG_SND_HDA_INPUT_BEEP */
  84. /* special beep mono mute switch */
  85. #define HDA_CODEC_MUTE_BEEP_MONO(xname, nid, channel, xindex, direction) \
  86. HDA_CODEC_MUTE_BEEP_MONO_IDX(xname, 0, nid, channel, xindex, direction)
  87. /* special beep stereo mute switch */
  88. #define HDA_CODEC_MUTE_BEEP(xname, nid, xindex, direction) \
  89. HDA_CODEC_MUTE_BEEP_MONO(xname, nid, 3, xindex, direction)
  90. extern const char *snd_hda_pcm_type_name[];
  91. int snd_hda_mixer_amp_volume_info(struct snd_kcontrol *kcontrol,
  92. struct snd_ctl_elem_info *uinfo);
  93. int snd_hda_mixer_amp_volume_get(struct snd_kcontrol *kcontrol,
  94. struct snd_ctl_elem_value *ucontrol);
  95. int snd_hda_mixer_amp_volume_put(struct snd_kcontrol *kcontrol,
  96. struct snd_ctl_elem_value *ucontrol);
  97. int snd_hda_mixer_amp_tlv(struct snd_kcontrol *kcontrol, int op_flag,
  98. unsigned int size, unsigned int __user *_tlv);
  99. int snd_hda_mixer_amp_switch_info(struct snd_kcontrol *kcontrol,
  100. struct snd_ctl_elem_info *uinfo);
  101. int snd_hda_mixer_amp_switch_get(struct snd_kcontrol *kcontrol,
  102. struct snd_ctl_elem_value *ucontrol);
  103. int snd_hda_mixer_amp_switch_put(struct snd_kcontrol *kcontrol,
  104. struct snd_ctl_elem_value *ucontrol);
  105. #ifdef CONFIG_SND_HDA_INPUT_BEEP
  106. int snd_hda_mixer_amp_switch_get_beep(struct snd_kcontrol *kcontrol,
  107. struct snd_ctl_elem_value *ucontrol);
  108. int snd_hda_mixer_amp_switch_put_beep(struct snd_kcontrol *kcontrol,
  109. struct snd_ctl_elem_value *ucontrol);
  110. #endif
  111. /* lowlevel accessor with caching; use carefully */
  112. #define snd_hda_codec_amp_read(codec, nid, ch, dir, idx) \
  113. snd_hdac_regmap_get_amp(&(codec)->core, nid, ch, dir, idx)
  114. int snd_hda_codec_amp_update(struct hda_codec *codec, hda_nid_t nid,
  115. int ch, int dir, int idx, int mask, int val);
  116. int snd_hda_codec_amp_stereo(struct hda_codec *codec, hda_nid_t nid,
  117. int direction, int idx, int mask, int val);
  118. int snd_hda_codec_amp_init(struct hda_codec *codec, hda_nid_t nid, int ch,
  119. int direction, int idx, int mask, int val);
  120. int snd_hda_codec_amp_init_stereo(struct hda_codec *codec, hda_nid_t nid,
  121. int dir, int idx, int mask, int val);
  122. void snd_hda_set_vmaster_tlv(struct hda_codec *codec, hda_nid_t nid, int dir,
  123. unsigned int *tlv);
  124. struct snd_kcontrol *snd_hda_find_mixer_ctl(struct hda_codec *codec,
  125. const char *name);
  126. int __snd_hda_add_vmaster(struct hda_codec *codec, char *name,
  127. unsigned int *tlv, const char * const *followers,
  128. const char *suffix, bool init_follower_vol,
  129. unsigned int access, struct snd_kcontrol **ctl_ret);
  130. #define snd_hda_add_vmaster(codec, name, tlv, followers, suffix, access) \
  131. __snd_hda_add_vmaster(codec, name, tlv, followers, suffix, true, access, NULL)
  132. int snd_hda_codec_reset(struct hda_codec *codec);
  133. void snd_hda_codec_disconnect_pcms(struct hda_codec *codec);
  134. #define snd_hda_regmap_sync(codec) snd_hdac_regmap_sync(&(codec)->core)
  135. struct hda_vmaster_mute_hook {
  136. /* below two fields must be filled by the caller of
  137. * snd_hda_add_vmaster_hook() beforehand
  138. */
  139. struct snd_kcontrol *sw_kctl;
  140. void (*hook)(void *, int);
  141. /* below are initialized automatically */
  142. struct hda_codec *codec;
  143. };
  144. int snd_hda_add_vmaster_hook(struct hda_codec *codec,
  145. struct hda_vmaster_mute_hook *hook);
  146. void snd_hda_sync_vmaster_hook(struct hda_vmaster_mute_hook *hook);
  147. /* amp value bits */
  148. #define HDA_AMP_MUTE 0x80
  149. #define HDA_AMP_UNMUTE 0x00
  150. #define HDA_AMP_VOLMASK 0x7f
  151. /*
  152. * SPDIF I/O
  153. */
  154. int snd_hda_create_dig_out_ctls(struct hda_codec *codec,
  155. hda_nid_t associated_nid,
  156. hda_nid_t cvt_nid, int type);
  157. #define snd_hda_create_spdif_out_ctls(codec, anid, cnid) \
  158. snd_hda_create_dig_out_ctls(codec, anid, cnid, HDA_PCM_TYPE_SPDIF)
  159. int snd_hda_create_spdif_in_ctls(struct hda_codec *codec, hda_nid_t nid);
  160. /*
  161. * input MUX helper
  162. */
  163. #define HDA_MAX_NUM_INPUTS 36
  164. struct hda_input_mux_item {
  165. char label[32];
  166. unsigned int index;
  167. };
  168. struct hda_input_mux {
  169. unsigned int num_items;
  170. struct hda_input_mux_item items[HDA_MAX_NUM_INPUTS];
  171. };
  172. int snd_hda_input_mux_info(const struct hda_input_mux *imux,
  173. struct snd_ctl_elem_info *uinfo);
  174. int snd_hda_input_mux_put(struct hda_codec *codec,
  175. const struct hda_input_mux *imux,
  176. struct snd_ctl_elem_value *ucontrol, hda_nid_t nid,
  177. unsigned int *cur_val);
  178. int snd_hda_add_imux_item(struct hda_codec *codec,
  179. struct hda_input_mux *imux, const char *label,
  180. int index, int *type_idx);
  181. /*
  182. * Multi-channel / digital-out PCM helper
  183. */
  184. enum { HDA_FRONT, HDA_REAR, HDA_CLFE, HDA_SIDE }; /* index for dac_nidx */
  185. enum { HDA_DIG_NONE, HDA_DIG_EXCLUSIVE, HDA_DIG_ANALOG_DUP }; /* dig_out_used */
  186. #define HDA_MAX_OUTS 5
  187. struct hda_multi_out {
  188. int num_dacs; /* # of DACs, must be more than 1 */
  189. const hda_nid_t *dac_nids; /* DAC list */
  190. hda_nid_t hp_nid; /* optional DAC for HP, 0 when not exists */
  191. hda_nid_t hp_out_nid[HDA_MAX_OUTS]; /* DACs for multiple HPs */
  192. hda_nid_t extra_out_nid[HDA_MAX_OUTS]; /* other (e.g. speaker) DACs */
  193. hda_nid_t dig_out_nid; /* digital out audio widget */
  194. const hda_nid_t *follower_dig_outs;
  195. int max_channels; /* currently supported analog channels */
  196. int dig_out_used; /* current usage of digital out (HDA_DIG_XXX) */
  197. int no_share_stream; /* don't share a stream with multiple pins */
  198. int share_spdif; /* share SPDIF pin */
  199. /* PCM information for both analog and SPDIF DACs */
  200. unsigned int analog_rates;
  201. unsigned int analog_maxbps;
  202. u64 analog_formats;
  203. unsigned int spdif_rates;
  204. unsigned int spdif_maxbps;
  205. u64 spdif_formats;
  206. };
  207. int snd_hda_create_spdif_share_sw(struct hda_codec *codec,
  208. struct hda_multi_out *mout);
  209. int snd_hda_multi_out_dig_open(struct hda_codec *codec,
  210. struct hda_multi_out *mout);
  211. int snd_hda_multi_out_dig_close(struct hda_codec *codec,
  212. struct hda_multi_out *mout);
  213. int snd_hda_multi_out_dig_prepare(struct hda_codec *codec,
  214. struct hda_multi_out *mout,
  215. unsigned int stream_tag,
  216. unsigned int format,
  217. struct snd_pcm_substream *substream);
  218. int snd_hda_multi_out_dig_cleanup(struct hda_codec *codec,
  219. struct hda_multi_out *mout);
  220. int snd_hda_multi_out_analog_open(struct hda_codec *codec,
  221. struct hda_multi_out *mout,
  222. struct snd_pcm_substream *substream,
  223. struct hda_pcm_stream *hinfo);
  224. int snd_hda_multi_out_analog_prepare(struct hda_codec *codec,
  225. struct hda_multi_out *mout,
  226. unsigned int stream_tag,
  227. unsigned int format,
  228. struct snd_pcm_substream *substream);
  229. int snd_hda_multi_out_analog_cleanup(struct hda_codec *codec,
  230. struct hda_multi_out *mout);
  231. /*
  232. * generic proc interface
  233. */
  234. #ifdef CONFIG_SND_PROC_FS
  235. int snd_hda_codec_proc_new(struct hda_codec *codec);
  236. #else
  237. static inline int snd_hda_codec_proc_new(struct hda_codec *codec) { return 0; }
  238. #endif
  239. #define SND_PRINT_BITS_ADVISED_BUFSIZE 16
  240. void snd_print_pcm_bits(int pcm, char *buf, int buflen);
  241. /*
  242. * Misc
  243. */
  244. int snd_hda_add_new_ctls(struct hda_codec *codec,
  245. const struct snd_kcontrol_new *knew);
  246. /*
  247. * Fix-up pin default configurations and add default verbs
  248. */
  249. struct hda_pintbl {
  250. hda_nid_t nid;
  251. u32 val;
  252. };
  253. struct hda_model_fixup {
  254. const int id;
  255. const char *name;
  256. };
  257. struct hda_fixup {
  258. int type;
  259. bool chained:1; /* call the chained fixup(s) after this */
  260. bool chained_before:1; /* call the chained fixup(s) before this */
  261. int chain_id;
  262. union {
  263. const struct hda_pintbl *pins;
  264. const struct hda_verb *verbs;
  265. void (*func)(struct hda_codec *codec,
  266. const struct hda_fixup *fix,
  267. int action);
  268. } v;
  269. };
  270. struct snd_hda_pin_quirk {
  271. unsigned int codec; /* Codec vendor/device ID */
  272. unsigned short subvendor; /* PCI subvendor ID */
  273. const struct hda_pintbl *pins; /* list of matching pins */
  274. #ifdef CONFIG_SND_DEBUG_VERBOSE
  275. const char *name;
  276. #endif
  277. int value; /* quirk value */
  278. };
  279. #ifdef CONFIG_SND_DEBUG_VERBOSE
  280. #define SND_HDA_PIN_QUIRK(_codec, _subvendor, _name, _value, _pins...) \
  281. { .codec = _codec,\
  282. .subvendor = _subvendor,\
  283. .name = _name,\
  284. .value = _value,\
  285. .pins = (const struct hda_pintbl[]) { _pins, {0, 0}} \
  286. }
  287. #else
  288. #define SND_HDA_PIN_QUIRK(_codec, _subvendor, _name, _value, _pins...) \
  289. { .codec = _codec,\
  290. .subvendor = _subvendor,\
  291. .value = _value,\
  292. .pins = (const struct hda_pintbl[]) { _pins, {0, 0}} \
  293. }
  294. #endif
  295. #define HDA_FIXUP_ID_NOT_SET -1
  296. #define HDA_FIXUP_ID_NO_FIXUP -2
  297. /* fixup types */
  298. enum {
  299. HDA_FIXUP_INVALID,
  300. HDA_FIXUP_PINS,
  301. HDA_FIXUP_VERBS,
  302. HDA_FIXUP_FUNC,
  303. HDA_FIXUP_PINCTLS,
  304. };
  305. /* fixup action definitions */
  306. enum {
  307. HDA_FIXUP_ACT_PRE_PROBE,
  308. HDA_FIXUP_ACT_PROBE,
  309. HDA_FIXUP_ACT_INIT,
  310. HDA_FIXUP_ACT_BUILD,
  311. HDA_FIXUP_ACT_FREE,
  312. };
  313. int snd_hda_add_verbs(struct hda_codec *codec, const struct hda_verb *list);
  314. void snd_hda_apply_verbs(struct hda_codec *codec);
  315. void snd_hda_apply_pincfgs(struct hda_codec *codec,
  316. const struct hda_pintbl *cfg);
  317. void snd_hda_apply_fixup(struct hda_codec *codec, int action);
  318. void __snd_hda_apply_fixup(struct hda_codec *codec, int id, int action, int depth);
  319. void snd_hda_pick_fixup(struct hda_codec *codec,
  320. const struct hda_model_fixup *models,
  321. const struct snd_pci_quirk *quirk,
  322. const struct hda_fixup *fixlist);
  323. void snd_hda_pick_pin_fixup(struct hda_codec *codec,
  324. const struct snd_hda_pin_quirk *pin_quirk,
  325. const struct hda_fixup *fixlist,
  326. bool match_all_pins);
  327. /* helper macros to retrieve pin default-config values */
  328. #define get_defcfg_connect(cfg) \
  329. ((cfg & AC_DEFCFG_PORT_CONN) >> AC_DEFCFG_PORT_CONN_SHIFT)
  330. #define get_defcfg_association(cfg) \
  331. ((cfg & AC_DEFCFG_DEF_ASSOC) >> AC_DEFCFG_ASSOC_SHIFT)
  332. #define get_defcfg_location(cfg) \
  333. ((cfg & AC_DEFCFG_LOCATION) >> AC_DEFCFG_LOCATION_SHIFT)
  334. #define get_defcfg_sequence(cfg) \
  335. (cfg & AC_DEFCFG_SEQUENCE)
  336. #define get_defcfg_device(cfg) \
  337. ((cfg & AC_DEFCFG_DEVICE) >> AC_DEFCFG_DEVICE_SHIFT)
  338. #define get_defcfg_misc(cfg) \
  339. ((cfg & AC_DEFCFG_MISC) >> AC_DEFCFG_MISC_SHIFT)
  340. /* amp values */
  341. #define AMP_IN_MUTE(idx) (0x7080 | ((idx)<<8))
  342. #define AMP_IN_UNMUTE(idx) (0x7000 | ((idx)<<8))
  343. #define AMP_OUT_MUTE 0xb080
  344. #define AMP_OUT_UNMUTE 0xb000
  345. #define AMP_OUT_ZERO 0xb000
  346. /* pinctl values */
  347. #define PIN_IN (AC_PINCTL_IN_EN)
  348. #define PIN_VREFHIZ (AC_PINCTL_IN_EN | AC_PINCTL_VREF_HIZ)
  349. #define PIN_VREF50 (AC_PINCTL_IN_EN | AC_PINCTL_VREF_50)
  350. #define PIN_VREFGRD (AC_PINCTL_IN_EN | AC_PINCTL_VREF_GRD)
  351. #define PIN_VREF80 (AC_PINCTL_IN_EN | AC_PINCTL_VREF_80)
  352. #define PIN_VREF100 (AC_PINCTL_IN_EN | AC_PINCTL_VREF_100)
  353. #define PIN_OUT (AC_PINCTL_OUT_EN)
  354. #define PIN_HP (AC_PINCTL_OUT_EN | AC_PINCTL_HP_EN)
  355. #define PIN_HP_AMP (AC_PINCTL_HP_EN)
  356. unsigned int snd_hda_get_default_vref(struct hda_codec *codec, hda_nid_t pin);
  357. unsigned int snd_hda_correct_pin_ctl(struct hda_codec *codec,
  358. hda_nid_t pin, unsigned int val);
  359. int _snd_hda_set_pin_ctl(struct hda_codec *codec, hda_nid_t pin,
  360. unsigned int val, bool cached);
  361. /**
  362. * _snd_hda_set_pin_ctl - Set a pin-control value safely
  363. * @codec: the codec instance
  364. * @pin: the pin NID to set the control
  365. * @val: the pin-control value (AC_PINCTL_* bits)
  366. *
  367. * This function sets the pin-control value to the given pin, but
  368. * filters out the invalid pin-control bits when the pin has no such
  369. * capabilities. For example, when PIN_HP is passed but the pin has no
  370. * HP-drive capability, the HP bit is omitted.
  371. *
  372. * The function doesn't check the input VREF capability bits, though.
  373. * Use snd_hda_get_default_vref() to guess the right value.
  374. * Also, this function is only for analog pins, not for HDMI pins.
  375. */
  376. static inline int
  377. snd_hda_set_pin_ctl(struct hda_codec *codec, hda_nid_t pin, unsigned int val)
  378. {
  379. return _snd_hda_set_pin_ctl(codec, pin, val, false);
  380. }
  381. /**
  382. * snd_hda_set_pin_ctl_cache - Set a pin-control value safely
  383. * @codec: the codec instance
  384. * @pin: the pin NID to set the control
  385. * @val: the pin-control value (AC_PINCTL_* bits)
  386. *
  387. * Just like snd_hda_set_pin_ctl() but write to cache as well.
  388. */
  389. static inline int
  390. snd_hda_set_pin_ctl_cache(struct hda_codec *codec, hda_nid_t pin,
  391. unsigned int val)
  392. {
  393. return _snd_hda_set_pin_ctl(codec, pin, val, true);
  394. }
  395. int snd_hda_codec_get_pin_target(struct hda_codec *codec, hda_nid_t nid);
  396. int snd_hda_codec_set_pin_target(struct hda_codec *codec, hda_nid_t nid,
  397. unsigned int val);
  398. #define for_each_hda_codec_node(nid, codec) \
  399. for ((nid) = (codec)->core.start_nid; (nid) < (codec)->core.end_nid; (nid)++)
  400. /* Set the codec power_state flag to indicate to allow unsol event handling;
  401. * see hda_codec_unsol_event() in hda_bind.c. Calling this might confuse the
  402. * state tracking, so use with care.
  403. */
  404. static inline void snd_hda_codec_allow_unsol_events(struct hda_codec *codec)
  405. {
  406. codec->core.dev.power.power_state = PMSG_ON;
  407. }
  408. /*
  409. * get widget capabilities
  410. */
  411. static inline u32 get_wcaps(struct hda_codec *codec, hda_nid_t nid)
  412. {
  413. if (nid < codec->core.start_nid ||
  414. nid >= codec->core.start_nid + codec->core.num_nodes)
  415. return 0;
  416. return codec->wcaps[nid - codec->core.start_nid];
  417. }
  418. /* get the widget type from widget capability bits */
  419. static inline int get_wcaps_type(unsigned int wcaps)
  420. {
  421. if (!wcaps)
  422. return -1; /* invalid type */
  423. return (wcaps & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
  424. }
  425. static inline unsigned int get_wcaps_channels(u32 wcaps)
  426. {
  427. unsigned int chans;
  428. chans = (wcaps & AC_WCAP_CHAN_CNT_EXT) >> 13;
  429. chans = ((chans << 1) | 1) + 1;
  430. return chans;
  431. }
  432. static inline void snd_hda_override_wcaps(struct hda_codec *codec,
  433. hda_nid_t nid, u32 val)
  434. {
  435. if (nid >= codec->core.start_nid &&
  436. nid < codec->core.start_nid + codec->core.num_nodes)
  437. codec->wcaps[nid - codec->core.start_nid] = val;
  438. }
  439. u32 query_amp_caps(struct hda_codec *codec, hda_nid_t nid, int direction);
  440. int snd_hda_override_amp_caps(struct hda_codec *codec, hda_nid_t nid, int dir,
  441. unsigned int caps);
  442. /**
  443. * snd_hda_query_pin_caps - Query PIN capabilities
  444. * @codec: the HD-auio codec
  445. * @nid: the NID to query
  446. *
  447. * Query PIN capabilities for the given widget.
  448. * Returns the obtained capability bits.
  449. *
  450. * When cap bits have been already read, this doesn't read again but
  451. * returns the cached value.
  452. */
  453. static inline u32
  454. snd_hda_query_pin_caps(struct hda_codec *codec, hda_nid_t nid)
  455. {
  456. return snd_hda_param_read(codec, nid, AC_PAR_PIN_CAP);
  457. }
  458. /**
  459. * snd_hda_override_pin_caps - Override the pin capabilities
  460. * @codec: the CODEC
  461. * @nid: the NID to override
  462. * @caps: the capability bits to set
  463. *
  464. * Override the cached PIN capabilitiy bits value by the given one.
  465. *
  466. * Returns zero if successful or a negative error code.
  467. */
  468. static inline int
  469. snd_hda_override_pin_caps(struct hda_codec *codec, hda_nid_t nid,
  470. unsigned int caps)
  471. {
  472. return snd_hdac_override_parm(&codec->core, nid, AC_PAR_PIN_CAP, caps);
  473. }
  474. bool snd_hda_check_amp_caps(struct hda_codec *codec, hda_nid_t nid,
  475. int dir, unsigned int bits);
  476. #define nid_has_mute(codec, nid, dir) \
  477. snd_hda_check_amp_caps(codec, nid, dir, (AC_AMPCAP_MUTE | AC_AMPCAP_MIN_MUTE))
  478. #define nid_has_volume(codec, nid, dir) \
  479. snd_hda_check_amp_caps(codec, nid, dir, AC_AMPCAP_NUM_STEPS)
  480. /* flags for hda_nid_item */
  481. #define HDA_NID_ITEM_AMP (1<<0)
  482. struct hda_nid_item {
  483. struct snd_kcontrol *kctl;
  484. unsigned int index;
  485. hda_nid_t nid;
  486. unsigned short flags;
  487. };
  488. int snd_hda_ctl_add(struct hda_codec *codec, hda_nid_t nid,
  489. struct snd_kcontrol *kctl);
  490. int snd_hda_add_nid(struct hda_codec *codec, struct snd_kcontrol *kctl,
  491. unsigned int index, hda_nid_t nid);
  492. void snd_hda_ctls_clear(struct hda_codec *codec);
  493. /*
  494. * hwdep interface
  495. */
  496. #ifdef CONFIG_SND_HDA_HWDEP
  497. int snd_hda_create_hwdep(struct hda_codec *codec);
  498. #else
  499. static inline int snd_hda_create_hwdep(struct hda_codec *codec) { return 0; }
  500. #endif
  501. void snd_hda_sysfs_init(struct hda_codec *codec);
  502. void snd_hda_sysfs_clear(struct hda_codec *codec);
  503. extern const struct attribute_group *snd_hda_dev_attr_groups[];
  504. #ifdef CONFIG_SND_HDA_RECONFIG
  505. const char *snd_hda_get_hint(struct hda_codec *codec, const char *key);
  506. int snd_hda_get_bool_hint(struct hda_codec *codec, const char *key);
  507. int snd_hda_get_int_hint(struct hda_codec *codec, const char *key, int *valp);
  508. #else
  509. static inline
  510. const char *snd_hda_get_hint(struct hda_codec *codec, const char *key)
  511. {
  512. return NULL;
  513. }
  514. static inline
  515. int snd_hda_get_bool_hint(struct hda_codec *codec, const char *key)
  516. {
  517. return -ENOENT;
  518. }
  519. static inline
  520. int snd_hda_get_int_hint(struct hda_codec *codec, const char *key, int *valp)
  521. {
  522. return -ENOENT;
  523. }
  524. #endif
  525. /*
  526. * power-management
  527. */
  528. void snd_hda_schedule_power_save(struct hda_codec *codec);
  529. struct hda_amp_list {
  530. hda_nid_t nid;
  531. unsigned char dir;
  532. unsigned char idx;
  533. };
  534. struct hda_loopback_check {
  535. const struct hda_amp_list *amplist;
  536. int power_on;
  537. };
  538. int snd_hda_check_amp_list_power(struct hda_codec *codec,
  539. struct hda_loopback_check *check,
  540. hda_nid_t nid);
  541. /* check whether the actual power state matches with the target state */
  542. static inline bool
  543. snd_hda_check_power_state(struct hda_codec *codec, hda_nid_t nid,
  544. unsigned int target_state)
  545. {
  546. return snd_hdac_check_power_state(&codec->core, nid, target_state);
  547. }
  548. static inline unsigned int snd_hda_sync_power_state(struct hda_codec *codec,
  549. hda_nid_t nid,
  550. unsigned int target_state)
  551. {
  552. return snd_hdac_sync_power_state(&codec->core, nid, target_state);
  553. }
  554. unsigned int snd_hda_codec_eapd_power_filter(struct hda_codec *codec,
  555. hda_nid_t nid,
  556. unsigned int power_state);
  557. void snd_hda_codec_shutdown(struct hda_codec *codec);
  558. /*
  559. * AMP control callbacks
  560. */
  561. /* retrieve parameters from private_value */
  562. #define get_amp_nid_(pv) ((pv) & 0xffff)
  563. #define get_amp_nid(kc) get_amp_nid_((kc)->private_value)
  564. #define get_amp_channels(kc) (((kc)->private_value >> 16) & 0x3)
  565. #define get_amp_direction_(pv) (((pv) >> 18) & 0x1)
  566. #define get_amp_direction(kc) get_amp_direction_((kc)->private_value)
  567. #define get_amp_index_(pv) (((pv) >> 19) & 0xf)
  568. #define get_amp_index(kc) get_amp_index_((kc)->private_value)
  569. #define get_amp_offset(kc) (((kc)->private_value >> 23) & 0x3f)
  570. #define get_amp_min_mute(kc) (((kc)->private_value >> 29) & 0x1)
  571. /*
  572. * enum control helper
  573. */
  574. int snd_hda_enum_helper_info(struct snd_kcontrol *kcontrol,
  575. struct snd_ctl_elem_info *uinfo,
  576. int num_items, const char * const *texts);
  577. #define snd_hda_enum_bool_helper_info(kcontrol, uinfo) \
  578. snd_hda_enum_helper_info(kcontrol, uinfo, 0, NULL)
  579. /*
  580. * CEA Short Audio Descriptor data
  581. */
  582. struct cea_sad {
  583. int channels;
  584. int format; /* (format == 0) indicates invalid SAD */
  585. int rates;
  586. int sample_bits; /* for LPCM */
  587. int max_bitrate; /* for AC3...ATRAC */
  588. int profile; /* for WMAPRO */
  589. };
  590. #define ELD_FIXED_BYTES 20
  591. #define ELD_MAX_SIZE 256
  592. #define ELD_MAX_MNL 16
  593. #define ELD_MAX_SAD 16
  594. /*
  595. * ELD: EDID Like Data
  596. */
  597. struct parsed_hdmi_eld {
  598. /*
  599. * all fields will be cleared before updating ELD
  600. */
  601. int baseline_len;
  602. int eld_ver;
  603. int cea_edid_ver;
  604. char monitor_name[ELD_MAX_MNL + 1];
  605. int manufacture_id;
  606. int product_id;
  607. u64 port_id;
  608. int support_hdcp;
  609. int support_ai;
  610. int conn_type;
  611. int aud_synch_delay;
  612. int spk_alloc;
  613. int sad_count;
  614. struct cea_sad sad[ELD_MAX_SAD];
  615. };
  616. struct hdmi_eld {
  617. bool monitor_present;
  618. bool eld_valid;
  619. int eld_size;
  620. char eld_buffer[ELD_MAX_SIZE];
  621. struct parsed_hdmi_eld info;
  622. };
  623. int snd_hdmi_get_eld_size(struct hda_codec *codec, hda_nid_t nid);
  624. int snd_hdmi_get_eld(struct hda_codec *codec, hda_nid_t nid,
  625. unsigned char *buf, int *eld_size);
  626. int snd_hdmi_parse_eld(struct hda_codec *codec, struct parsed_hdmi_eld *e,
  627. const unsigned char *buf, int size);
  628. void snd_hdmi_show_eld(struct hda_codec *codec, struct parsed_hdmi_eld *e);
  629. void snd_hdmi_eld_update_pcm_info(struct parsed_hdmi_eld *e,
  630. struct hda_pcm_stream *hinfo);
  631. int snd_hdmi_get_eld_ati(struct hda_codec *codec, hda_nid_t nid,
  632. unsigned char *buf, int *eld_size,
  633. bool rev3_or_later);
  634. #ifdef CONFIG_SND_PROC_FS
  635. void snd_hdmi_print_eld_info(struct hdmi_eld *eld,
  636. struct snd_info_buffer *buffer,
  637. hda_nid_t pin_nid, int dev_id, hda_nid_t cvt_nid);
  638. void snd_hdmi_write_eld_info(struct hdmi_eld *eld,
  639. struct snd_info_buffer *buffer);
  640. #endif
  641. #define SND_PRINT_CHANNEL_ALLOCATION_ADVISED_BUFSIZE 80
  642. void snd_print_channel_allocation(int spk_alloc, char *buf, int buflen);
  643. void snd_hda_codec_display_power(struct hda_codec *codec, bool enable);
  644. /*
  645. */
  646. #define codec_err(codec, fmt, args...) \
  647. dev_err(hda_codec_dev(codec), fmt, ##args)
  648. #define codec_warn(codec, fmt, args...) \
  649. dev_warn(hda_codec_dev(codec), fmt, ##args)
  650. #define codec_info(codec, fmt, args...) \
  651. dev_info(hda_codec_dev(codec), fmt, ##args)
  652. #define codec_dbg(codec, fmt, args...) \
  653. dev_dbg(hda_codec_dev(codec), fmt, ##args)
  654. #endif /* __SOUND_HDA_LOCAL_H */