hda_local.h 26 KB

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