hda_local.h 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745
  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. int snd_hda_codec_amp_read(struct hda_codec *codec, hda_nid_t nid, int ch,
  126. int direction, int index);
  127. int snd_hda_codec_amp_update(struct hda_codec *codec, hda_nid_t nid, int ch,
  128. int direction, 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_codec_resume_amp(struct hda_codec *codec);
  136. /* it's alias but a bit clearer meaning */
  137. #define snd_hda_codec_flush_amp_cache(codec) \
  138. snd_hda_codec_resume_amp(codec)
  139. void snd_hda_set_vmaster_tlv(struct hda_codec *codec, hda_nid_t nid, int dir,
  140. unsigned int *tlv);
  141. struct snd_kcontrol *snd_hda_find_mixer_ctl(struct hda_codec *codec,
  142. const char *name);
  143. int __snd_hda_add_vmaster(struct hda_codec *codec, char *name,
  144. unsigned int *tlv, const char * const *slaves,
  145. const char *suffix, bool init_slave_vol,
  146. struct snd_kcontrol **ctl_ret);
  147. #define snd_hda_add_vmaster(codec, name, tlv, slaves, suffix) \
  148. __snd_hda_add_vmaster(codec, name, tlv, slaves, suffix, true, NULL)
  149. int snd_hda_codec_reset(struct hda_codec *codec);
  150. enum {
  151. HDA_VMUTE_OFF,
  152. HDA_VMUTE_ON,
  153. HDA_VMUTE_FOLLOW_MASTER,
  154. };
  155. struct hda_vmaster_mute_hook {
  156. /* below two fields must be filled by the caller of
  157. * snd_hda_add_vmaster_hook() beforehand
  158. */
  159. struct snd_kcontrol *sw_kctl;
  160. void (*hook)(void *, int);
  161. /* below are initialized automatically */
  162. unsigned int mute_mode; /* HDA_VMUTE_XXX */
  163. struct hda_codec *codec;
  164. };
  165. int snd_hda_add_vmaster_hook(struct hda_codec *codec,
  166. struct hda_vmaster_mute_hook *hook,
  167. bool expose_enum_ctl);
  168. void snd_hda_sync_vmaster_hook(struct hda_vmaster_mute_hook *hook);
  169. /* amp value bits */
  170. #define HDA_AMP_MUTE 0x80
  171. #define HDA_AMP_UNMUTE 0x00
  172. #define HDA_AMP_VOLMASK 0x7f
  173. /* mono switch binding multiple inputs */
  174. #define HDA_BIND_MUTE_MONO(xname, nid, channel, indices, direction) \
  175. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \
  176. .info = snd_hda_mixer_amp_switch_info, \
  177. .get = snd_hda_mixer_bind_switch_get, \
  178. .put = snd_hda_mixer_bind_switch_put, \
  179. .private_value = HDA_COMPOSE_AMP_VAL(nid, channel, indices, direction) }
  180. /* stereo switch binding multiple inputs */
  181. #define HDA_BIND_MUTE(xname,nid,indices,dir) \
  182. HDA_BIND_MUTE_MONO(xname,nid,3,indices,dir)
  183. int snd_hda_mixer_bind_switch_get(struct snd_kcontrol *kcontrol,
  184. struct snd_ctl_elem_value *ucontrol);
  185. int snd_hda_mixer_bind_switch_put(struct snd_kcontrol *kcontrol,
  186. struct snd_ctl_elem_value *ucontrol);
  187. /* more generic bound controls */
  188. struct hda_ctl_ops {
  189. snd_kcontrol_info_t *info;
  190. snd_kcontrol_get_t *get;
  191. snd_kcontrol_put_t *put;
  192. snd_kcontrol_tlv_rw_t *tlv;
  193. };
  194. extern struct hda_ctl_ops snd_hda_bind_vol; /* for bind-volume with TLV */
  195. extern struct hda_ctl_ops snd_hda_bind_sw; /* for bind-switch */
  196. struct hda_bind_ctls {
  197. struct hda_ctl_ops *ops;
  198. unsigned long values[];
  199. };
  200. int snd_hda_mixer_bind_ctls_info(struct snd_kcontrol *kcontrol,
  201. struct snd_ctl_elem_info *uinfo);
  202. int snd_hda_mixer_bind_ctls_get(struct snd_kcontrol *kcontrol,
  203. struct snd_ctl_elem_value *ucontrol);
  204. int snd_hda_mixer_bind_ctls_put(struct snd_kcontrol *kcontrol,
  205. struct snd_ctl_elem_value *ucontrol);
  206. int snd_hda_mixer_bind_tlv(struct snd_kcontrol *kcontrol, int op_flag,
  207. unsigned int size, unsigned int __user *tlv);
  208. #define HDA_BIND_VOL(xname, bindrec) \
  209. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
  210. .name = xname, \
  211. .access = SNDRV_CTL_ELEM_ACCESS_READWRITE |\
  212. SNDRV_CTL_ELEM_ACCESS_TLV_READ |\
  213. SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK,\
  214. .info = snd_hda_mixer_bind_ctls_info,\
  215. .get = snd_hda_mixer_bind_ctls_get,\
  216. .put = snd_hda_mixer_bind_ctls_put,\
  217. .tlv = { .c = snd_hda_mixer_bind_tlv },\
  218. .private_value = (long) (bindrec) }
  219. #define HDA_BIND_SW(xname, bindrec) \
  220. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER,\
  221. .name = xname, \
  222. .info = snd_hda_mixer_bind_ctls_info,\
  223. .get = snd_hda_mixer_bind_ctls_get,\
  224. .put = snd_hda_mixer_bind_ctls_put,\
  225. .private_value = (long) (bindrec) }
  226. /*
  227. * SPDIF I/O
  228. */
  229. int snd_hda_create_dig_out_ctls(struct hda_codec *codec,
  230. hda_nid_t associated_nid,
  231. hda_nid_t cvt_nid, int type);
  232. #define snd_hda_create_spdif_out_ctls(codec, anid, cnid) \
  233. snd_hda_create_dig_out_ctls(codec, anid, cnid, HDA_PCM_TYPE_SPDIF)
  234. int snd_hda_create_spdif_in_ctls(struct hda_codec *codec, hda_nid_t nid);
  235. /*
  236. * input MUX helper
  237. */
  238. #define HDA_MAX_NUM_INPUTS 16
  239. struct hda_input_mux_item {
  240. char label[32];
  241. unsigned int index;
  242. };
  243. struct hda_input_mux {
  244. unsigned int num_items;
  245. struct hda_input_mux_item items[HDA_MAX_NUM_INPUTS];
  246. };
  247. int snd_hda_input_mux_info(const struct hda_input_mux *imux,
  248. struct snd_ctl_elem_info *uinfo);
  249. int snd_hda_input_mux_put(struct hda_codec *codec,
  250. const struct hda_input_mux *imux,
  251. struct snd_ctl_elem_value *ucontrol, hda_nid_t nid,
  252. unsigned int *cur_val);
  253. int snd_hda_add_imux_item(struct hda_input_mux *imux, const char *label,
  254. int index, int *type_index_ret);
  255. /*
  256. * Channel mode helper
  257. */
  258. struct hda_channel_mode {
  259. int channels;
  260. const struct hda_verb *sequence;
  261. };
  262. int snd_hda_ch_mode_info(struct hda_codec *codec,
  263. struct snd_ctl_elem_info *uinfo,
  264. const struct hda_channel_mode *chmode,
  265. int num_chmodes);
  266. int snd_hda_ch_mode_get(struct hda_codec *codec,
  267. struct snd_ctl_elem_value *ucontrol,
  268. const struct hda_channel_mode *chmode,
  269. int num_chmodes,
  270. int max_channels);
  271. int snd_hda_ch_mode_put(struct hda_codec *codec,
  272. struct snd_ctl_elem_value *ucontrol,
  273. const struct hda_channel_mode *chmode,
  274. int num_chmodes,
  275. int *max_channelsp);
  276. /*
  277. * Multi-channel / digital-out PCM helper
  278. */
  279. enum { HDA_FRONT, HDA_REAR, HDA_CLFE, HDA_SIDE }; /* index for dac_nidx */
  280. enum { HDA_DIG_NONE, HDA_DIG_EXCLUSIVE, HDA_DIG_ANALOG_DUP }; /* dig_out_used */
  281. #define HDA_MAX_OUTS 5
  282. struct hda_multi_out {
  283. int num_dacs; /* # of DACs, must be more than 1 */
  284. const hda_nid_t *dac_nids; /* DAC list */
  285. hda_nid_t hp_nid; /* optional DAC for HP, 0 when not exists */
  286. hda_nid_t hp_out_nid[HDA_MAX_OUTS]; /* DACs for multiple HPs */
  287. hda_nid_t extra_out_nid[HDA_MAX_OUTS]; /* other (e.g. speaker) DACs */
  288. hda_nid_t dig_out_nid; /* digital out audio widget */
  289. const hda_nid_t *slave_dig_outs;
  290. int max_channels; /* currently supported analog channels */
  291. int dig_out_used; /* current usage of digital out (HDA_DIG_XXX) */
  292. int no_share_stream; /* don't share a stream with multiple pins */
  293. int share_spdif; /* share SPDIF pin */
  294. /* PCM information for both analog and SPDIF DACs */
  295. unsigned int analog_rates;
  296. unsigned int analog_maxbps;
  297. u64 analog_formats;
  298. unsigned int spdif_rates;
  299. unsigned int spdif_maxbps;
  300. u64 spdif_formats;
  301. };
  302. int snd_hda_create_spdif_share_sw(struct hda_codec *codec,
  303. struct hda_multi_out *mout);
  304. int snd_hda_multi_out_dig_open(struct hda_codec *codec,
  305. struct hda_multi_out *mout);
  306. int snd_hda_multi_out_dig_close(struct hda_codec *codec,
  307. struct hda_multi_out *mout);
  308. int snd_hda_multi_out_dig_prepare(struct hda_codec *codec,
  309. struct hda_multi_out *mout,
  310. unsigned int stream_tag,
  311. unsigned int format,
  312. struct snd_pcm_substream *substream);
  313. int snd_hda_multi_out_dig_cleanup(struct hda_codec *codec,
  314. struct hda_multi_out *mout);
  315. int snd_hda_multi_out_analog_open(struct hda_codec *codec,
  316. struct hda_multi_out *mout,
  317. struct snd_pcm_substream *substream,
  318. struct hda_pcm_stream *hinfo);
  319. int snd_hda_multi_out_analog_prepare(struct hda_codec *codec,
  320. struct hda_multi_out *mout,
  321. unsigned int stream_tag,
  322. unsigned int format,
  323. struct snd_pcm_substream *substream);
  324. int snd_hda_multi_out_analog_cleanup(struct hda_codec *codec,
  325. struct hda_multi_out *mout);
  326. /*
  327. * generic codec parser
  328. */
  329. #ifdef CONFIG_SND_HDA_GENERIC
  330. int snd_hda_parse_generic_codec(struct hda_codec *codec);
  331. #else
  332. static inline int snd_hda_parse_generic_codec(struct hda_codec *codec)
  333. {
  334. return -ENODEV;
  335. }
  336. #endif
  337. /*
  338. * generic proc interface
  339. */
  340. #ifdef CONFIG_PROC_FS
  341. int snd_hda_codec_proc_new(struct hda_codec *codec);
  342. #else
  343. static inline int snd_hda_codec_proc_new(struct hda_codec *codec) { return 0; }
  344. #endif
  345. #define SND_PRINT_BITS_ADVISED_BUFSIZE 16
  346. void snd_print_pcm_bits(int pcm, char *buf, int buflen);
  347. /*
  348. * Misc
  349. */
  350. int snd_hda_check_board_config(struct hda_codec *codec, int num_configs,
  351. const char * const *modelnames,
  352. const struct snd_pci_quirk *pci_list);
  353. int snd_hda_check_board_codec_sid_config(struct hda_codec *codec,
  354. int num_configs, const char * const *models,
  355. const struct snd_pci_quirk *tbl);
  356. int snd_hda_add_new_ctls(struct hda_codec *codec,
  357. const struct snd_kcontrol_new *knew);
  358. /*
  359. * Fix-up pin default configurations and add default verbs
  360. */
  361. struct hda_pintbl {
  362. hda_nid_t nid;
  363. u32 val;
  364. };
  365. struct hda_model_fixup {
  366. const int id;
  367. const char *name;
  368. };
  369. struct hda_fixup {
  370. int type;
  371. bool chained;
  372. int chain_id;
  373. union {
  374. const struct hda_pintbl *pins;
  375. const struct hda_verb *verbs;
  376. void (*func)(struct hda_codec *codec,
  377. const struct hda_fixup *fix,
  378. int action);
  379. } v;
  380. };
  381. /* fixup types */
  382. enum {
  383. HDA_FIXUP_INVALID,
  384. HDA_FIXUP_PINS,
  385. HDA_FIXUP_VERBS,
  386. HDA_FIXUP_FUNC,
  387. };
  388. /* fixup action definitions */
  389. enum {
  390. HDA_FIXUP_ACT_PRE_PROBE,
  391. HDA_FIXUP_ACT_PROBE,
  392. HDA_FIXUP_ACT_INIT,
  393. HDA_FIXUP_ACT_BUILD,
  394. };
  395. int snd_hda_add_verbs(struct hda_codec *codec, const struct hda_verb *list);
  396. void snd_hda_apply_verbs(struct hda_codec *codec);
  397. void snd_hda_apply_pincfgs(struct hda_codec *codec,
  398. const struct hda_pintbl *cfg);
  399. void snd_hda_apply_fixup(struct hda_codec *codec, int action);
  400. void snd_hda_pick_fixup(struct hda_codec *codec,
  401. const struct hda_model_fixup *models,
  402. const struct snd_pci_quirk *quirk,
  403. const struct hda_fixup *fixlist);
  404. /*
  405. * unsolicited event handler
  406. */
  407. #define HDA_UNSOL_QUEUE_SIZE 64
  408. struct hda_bus_unsolicited {
  409. /* ring buffer */
  410. u32 queue[HDA_UNSOL_QUEUE_SIZE * 2];
  411. unsigned int rp, wp;
  412. /* workqueue */
  413. struct work_struct work;
  414. struct hda_bus *bus;
  415. };
  416. /* helper macros to retrieve pin default-config values */
  417. #define get_defcfg_connect(cfg) \
  418. ((cfg & AC_DEFCFG_PORT_CONN) >> AC_DEFCFG_PORT_CONN_SHIFT)
  419. #define get_defcfg_association(cfg) \
  420. ((cfg & AC_DEFCFG_DEF_ASSOC) >> AC_DEFCFG_ASSOC_SHIFT)
  421. #define get_defcfg_location(cfg) \
  422. ((cfg & AC_DEFCFG_LOCATION) >> AC_DEFCFG_LOCATION_SHIFT)
  423. #define get_defcfg_sequence(cfg) \
  424. (cfg & AC_DEFCFG_SEQUENCE)
  425. #define get_defcfg_device(cfg) \
  426. ((cfg & AC_DEFCFG_DEVICE) >> AC_DEFCFG_DEVICE_SHIFT)
  427. #define get_defcfg_misc(cfg) \
  428. ((cfg & AC_DEFCFG_MISC) >> AC_DEFCFG_MISC_SHIFT)
  429. /* amp values */
  430. #define AMP_IN_MUTE(idx) (0x7080 | ((idx)<<8))
  431. #define AMP_IN_UNMUTE(idx) (0x7000 | ((idx)<<8))
  432. #define AMP_OUT_MUTE 0xb080
  433. #define AMP_OUT_UNMUTE 0xb000
  434. #define AMP_OUT_ZERO 0xb000
  435. /* pinctl values */
  436. #define PIN_IN (AC_PINCTL_IN_EN)
  437. #define PIN_VREFHIZ (AC_PINCTL_IN_EN | AC_PINCTL_VREF_HIZ)
  438. #define PIN_VREF50 (AC_PINCTL_IN_EN | AC_PINCTL_VREF_50)
  439. #define PIN_VREFGRD (AC_PINCTL_IN_EN | AC_PINCTL_VREF_GRD)
  440. #define PIN_VREF80 (AC_PINCTL_IN_EN | AC_PINCTL_VREF_80)
  441. #define PIN_VREF100 (AC_PINCTL_IN_EN | AC_PINCTL_VREF_100)
  442. #define PIN_OUT (AC_PINCTL_OUT_EN)
  443. #define PIN_HP (AC_PINCTL_OUT_EN | AC_PINCTL_HP_EN)
  444. #define PIN_HP_AMP (AC_PINCTL_HP_EN)
  445. unsigned int snd_hda_get_default_vref(struct hda_codec *codec, hda_nid_t pin);
  446. int _snd_hda_set_pin_ctl(struct hda_codec *codec, hda_nid_t pin,
  447. unsigned int val, bool cached);
  448. /**
  449. * _snd_hda_set_pin_ctl - Set a pin-control value safely
  450. * @codec: the codec instance
  451. * @pin: the pin NID to set the control
  452. * @val: the pin-control value (AC_PINCTL_* bits)
  453. *
  454. * This function sets the pin-control value to the given pin, but
  455. * filters out the invalid pin-control bits when the pin has no such
  456. * capabilities. For example, when PIN_HP is passed but the pin has no
  457. * HP-drive capability, the HP bit is omitted.
  458. *
  459. * The function doesn't check the input VREF capability bits, though.
  460. * Use snd_hda_get_default_vref() to guess the right value.
  461. * Also, this function is only for analog pins, not for HDMI pins.
  462. */
  463. static inline int
  464. snd_hda_set_pin_ctl(struct hda_codec *codec, hda_nid_t pin, unsigned int val)
  465. {
  466. return _snd_hda_set_pin_ctl(codec, pin, val, false);
  467. }
  468. /**
  469. * snd_hda_set_pin_ctl_cache - Set a pin-control value safely
  470. * @codec: the codec instance
  471. * @pin: the pin NID to set the control
  472. * @val: the pin-control value (AC_PINCTL_* bits)
  473. *
  474. * Just like snd_hda_set_pin_ctl() but write to cache as well.
  475. */
  476. static inline int
  477. snd_hda_set_pin_ctl_cache(struct hda_codec *codec, hda_nid_t pin,
  478. unsigned int val)
  479. {
  480. return _snd_hda_set_pin_ctl(codec, pin, val, true);
  481. }
  482. /*
  483. * get widget capabilities
  484. */
  485. static inline u32 get_wcaps(struct hda_codec *codec, hda_nid_t nid)
  486. {
  487. if (nid < codec->start_nid ||
  488. nid >= codec->start_nid + codec->num_nodes)
  489. return 0;
  490. return codec->wcaps[nid - codec->start_nid];
  491. }
  492. /* get the widget type from widget capability bits */
  493. static inline int get_wcaps_type(unsigned int wcaps)
  494. {
  495. if (!wcaps)
  496. return -1; /* invalid type */
  497. return (wcaps & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
  498. }
  499. static inline unsigned int get_wcaps_channels(u32 wcaps)
  500. {
  501. unsigned int chans;
  502. chans = (wcaps & AC_WCAP_CHAN_CNT_EXT) >> 13;
  503. chans = ((chans << 1) | 1) + 1;
  504. return chans;
  505. }
  506. u32 query_amp_caps(struct hda_codec *codec, hda_nid_t nid, int direction);
  507. int snd_hda_override_amp_caps(struct hda_codec *codec, hda_nid_t nid, int dir,
  508. unsigned int caps);
  509. u32 snd_hda_query_pin_caps(struct hda_codec *codec, hda_nid_t nid);
  510. int snd_hda_override_pin_caps(struct hda_codec *codec, hda_nid_t nid,
  511. unsigned int caps);
  512. /* flags for hda_nid_item */
  513. #define HDA_NID_ITEM_AMP (1<<0)
  514. struct hda_nid_item {
  515. struct snd_kcontrol *kctl;
  516. unsigned int index;
  517. hda_nid_t nid;
  518. unsigned short flags;
  519. };
  520. int snd_hda_ctl_add(struct hda_codec *codec, hda_nid_t nid,
  521. struct snd_kcontrol *kctl);
  522. int snd_hda_add_nid(struct hda_codec *codec, struct snd_kcontrol *kctl,
  523. unsigned int index, hda_nid_t nid);
  524. void snd_hda_ctls_clear(struct hda_codec *codec);
  525. /*
  526. * hwdep interface
  527. */
  528. #ifdef CONFIG_SND_HDA_HWDEP
  529. int snd_hda_create_hwdep(struct hda_codec *codec);
  530. #else
  531. static inline int snd_hda_create_hwdep(struct hda_codec *codec) { return 0; }
  532. #endif
  533. #if defined(CONFIG_PM) && defined(CONFIG_SND_HDA_HWDEP)
  534. int snd_hda_hwdep_add_power_sysfs(struct hda_codec *codec);
  535. #else
  536. static inline int snd_hda_hwdep_add_power_sysfs(struct hda_codec *codec)
  537. {
  538. return 0;
  539. }
  540. #endif
  541. #ifdef CONFIG_SND_HDA_RECONFIG
  542. int snd_hda_hwdep_add_sysfs(struct hda_codec *codec);
  543. #else
  544. static inline int snd_hda_hwdep_add_sysfs(struct hda_codec *codec)
  545. {
  546. return 0;
  547. }
  548. #endif
  549. #ifdef CONFIG_SND_HDA_RECONFIG
  550. const char *snd_hda_get_hint(struct hda_codec *codec, const char *key);
  551. int snd_hda_get_bool_hint(struct hda_codec *codec, const char *key);
  552. #else
  553. static inline
  554. const char *snd_hda_get_hint(struct hda_codec *codec, const char *key)
  555. {
  556. return NULL;
  557. }
  558. static inline
  559. int snd_hda_get_bool_hint(struct hda_codec *codec, const char *key)
  560. {
  561. return -ENOENT;
  562. }
  563. #endif
  564. /*
  565. * power-management
  566. */
  567. void snd_hda_schedule_power_save(struct hda_codec *codec);
  568. struct hda_amp_list {
  569. hda_nid_t nid;
  570. unsigned char dir;
  571. unsigned char idx;
  572. };
  573. struct hda_loopback_check {
  574. const struct hda_amp_list *amplist;
  575. int power_on;
  576. };
  577. int snd_hda_check_amp_list_power(struct hda_codec *codec,
  578. struct hda_loopback_check *check,
  579. hda_nid_t nid);
  580. /*
  581. * AMP control callbacks
  582. */
  583. /* retrieve parameters from private_value */
  584. #define get_amp_nid_(pv) ((pv) & 0xffff)
  585. #define get_amp_nid(kc) get_amp_nid_((kc)->private_value)
  586. #define get_amp_channels(kc) (((kc)->private_value >> 16) & 0x3)
  587. #define get_amp_direction_(pv) (((pv) >> 18) & 0x1)
  588. #define get_amp_direction(kc) get_amp_direction_((kc)->private_value)
  589. #define get_amp_index_(pv) (((pv) >> 19) & 0xf)
  590. #define get_amp_index(kc) get_amp_index_((kc)->private_value)
  591. #define get_amp_offset(kc) (((kc)->private_value >> 23) & 0x3f)
  592. #define get_amp_min_mute(kc) (((kc)->private_value >> 29) & 0x1)
  593. /*
  594. * enum control helper
  595. */
  596. int snd_hda_enum_helper_info(struct snd_kcontrol *kcontrol,
  597. struct snd_ctl_elem_info *uinfo,
  598. int num_entries, const char * const *texts);
  599. #define snd_hda_enum_bool_helper_info(kcontrol, uinfo) \
  600. snd_hda_enum_helper_info(kcontrol, uinfo, 0, NULL)
  601. /*
  602. * CEA Short Audio Descriptor data
  603. */
  604. struct cea_sad {
  605. int channels;
  606. int format; /* (format == 0) indicates invalid SAD */
  607. int rates;
  608. int sample_bits; /* for LPCM */
  609. int max_bitrate; /* for AC3...ATRAC */
  610. int profile; /* for WMAPRO */
  611. };
  612. #define ELD_FIXED_BYTES 20
  613. #define ELD_MAX_SIZE 256
  614. #define ELD_MAX_MNL 16
  615. #define ELD_MAX_SAD 16
  616. /*
  617. * ELD: EDID Like Data
  618. */
  619. struct hdmi_eld {
  620. bool monitor_present;
  621. bool eld_valid;
  622. int eld_size;
  623. int baseline_len;
  624. int eld_ver;
  625. int cea_edid_ver;
  626. char monitor_name[ELD_MAX_MNL + 1];
  627. int manufacture_id;
  628. int product_id;
  629. u64 port_id;
  630. int support_hdcp;
  631. int support_ai;
  632. int conn_type;
  633. int aud_synch_delay;
  634. int spk_alloc;
  635. int sad_count;
  636. struct cea_sad sad[ELD_MAX_SAD];
  637. /*
  638. * all fields above eld_buffer will be cleared before updating ELD
  639. */
  640. char eld_buffer[ELD_MAX_SIZE];
  641. #ifdef CONFIG_PROC_FS
  642. struct snd_info_entry *proc_entry;
  643. #endif
  644. };
  645. int snd_hdmi_get_eld_size(struct hda_codec *codec, hda_nid_t nid);
  646. int snd_hdmi_get_eld(struct hdmi_eld *, struct hda_codec *, hda_nid_t);
  647. void snd_hdmi_show_eld(struct hdmi_eld *eld);
  648. void snd_hdmi_eld_update_pcm_info(struct hdmi_eld *eld,
  649. struct hda_pcm_stream *hinfo);
  650. #ifdef CONFIG_PROC_FS
  651. int snd_hda_eld_proc_new(struct hda_codec *codec, struct hdmi_eld *eld,
  652. int index);
  653. void snd_hda_eld_proc_free(struct hda_codec *codec, struct hdmi_eld *eld);
  654. #else
  655. static inline int snd_hda_eld_proc_new(struct hda_codec *codec,
  656. struct hdmi_eld *eld,
  657. int index)
  658. {
  659. return 0;
  660. }
  661. static inline void snd_hda_eld_proc_free(struct hda_codec *codec,
  662. struct hdmi_eld *eld)
  663. {
  664. }
  665. #endif
  666. #define SND_PRINT_CHANNEL_ALLOCATION_ADVISED_BUFSIZE 80
  667. void snd_print_channel_allocation(int spk_alloc, char *buf, int buflen);
  668. #endif /* __SOUND_HDA_LOCAL_H */