hda_local.h 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683
  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, \
  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_put_beep(struct snd_kcontrol *kcontrol,
  120. struct snd_ctl_elem_value *ucontrol);
  121. #endif
  122. /* lowlevel accessor with caching; use carefully */
  123. int snd_hda_codec_amp_read(struct hda_codec *codec, hda_nid_t nid, int ch,
  124. int direction, int index);
  125. int snd_hda_codec_amp_update(struct hda_codec *codec, hda_nid_t nid, int ch,
  126. int direction, int idx, int mask, int val);
  127. int snd_hda_codec_amp_stereo(struct hda_codec *codec, hda_nid_t nid,
  128. int dir, int idx, int mask, int val);
  129. #ifdef SND_HDA_NEEDS_RESUME
  130. void snd_hda_codec_resume_amp(struct hda_codec *codec);
  131. #endif
  132. void snd_hda_set_vmaster_tlv(struct hda_codec *codec, hda_nid_t nid, int dir,
  133. unsigned int *tlv);
  134. struct snd_kcontrol *snd_hda_find_mixer_ctl(struct hda_codec *codec,
  135. const char *name);
  136. int snd_hda_add_vmaster(struct hda_codec *codec, char *name,
  137. unsigned int *tlv, const char * const *slaves);
  138. int snd_hda_codec_reset(struct hda_codec *codec);
  139. /* amp value bits */
  140. #define HDA_AMP_MUTE 0x80
  141. #define HDA_AMP_UNMUTE 0x00
  142. #define HDA_AMP_VOLMASK 0x7f
  143. /* mono switch binding multiple inputs */
  144. #define HDA_BIND_MUTE_MONO(xname, nid, channel, indices, direction) \
  145. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \
  146. .info = snd_hda_mixer_amp_switch_info, \
  147. .get = snd_hda_mixer_bind_switch_get, \
  148. .put = snd_hda_mixer_bind_switch_put, \
  149. .private_value = HDA_COMPOSE_AMP_VAL(nid, channel, indices, direction) }
  150. /* stereo switch binding multiple inputs */
  151. #define HDA_BIND_MUTE(xname,nid,indices,dir) \
  152. HDA_BIND_MUTE_MONO(xname,nid,3,indices,dir)
  153. int snd_hda_mixer_bind_switch_get(struct snd_kcontrol *kcontrol,
  154. struct snd_ctl_elem_value *ucontrol);
  155. int snd_hda_mixer_bind_switch_put(struct snd_kcontrol *kcontrol,
  156. struct snd_ctl_elem_value *ucontrol);
  157. /* more generic bound controls */
  158. struct hda_ctl_ops {
  159. snd_kcontrol_info_t *info;
  160. snd_kcontrol_get_t *get;
  161. snd_kcontrol_put_t *put;
  162. snd_kcontrol_tlv_rw_t *tlv;
  163. };
  164. extern struct hda_ctl_ops snd_hda_bind_vol; /* for bind-volume with TLV */
  165. extern struct hda_ctl_ops snd_hda_bind_sw; /* for bind-switch */
  166. struct hda_bind_ctls {
  167. struct hda_ctl_ops *ops;
  168. unsigned long values[];
  169. };
  170. int snd_hda_mixer_bind_ctls_info(struct snd_kcontrol *kcontrol,
  171. struct snd_ctl_elem_info *uinfo);
  172. int snd_hda_mixer_bind_ctls_get(struct snd_kcontrol *kcontrol,
  173. struct snd_ctl_elem_value *ucontrol);
  174. int snd_hda_mixer_bind_ctls_put(struct snd_kcontrol *kcontrol,
  175. struct snd_ctl_elem_value *ucontrol);
  176. int snd_hda_mixer_bind_tlv(struct snd_kcontrol *kcontrol, int op_flag,
  177. unsigned int size, unsigned int __user *tlv);
  178. #define HDA_BIND_VOL(xname, bindrec) \
  179. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
  180. .name = xname, \
  181. .access = SNDRV_CTL_ELEM_ACCESS_READWRITE |\
  182. SNDRV_CTL_ELEM_ACCESS_TLV_READ |\
  183. SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK,\
  184. .info = snd_hda_mixer_bind_ctls_info,\
  185. .get = snd_hda_mixer_bind_ctls_get,\
  186. .put = snd_hda_mixer_bind_ctls_put,\
  187. .tlv = { .c = snd_hda_mixer_bind_tlv },\
  188. .private_value = (long) (bindrec) }
  189. #define HDA_BIND_SW(xname, bindrec) \
  190. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER,\
  191. .name = xname, \
  192. .info = snd_hda_mixer_bind_ctls_info,\
  193. .get = snd_hda_mixer_bind_ctls_get,\
  194. .put = snd_hda_mixer_bind_ctls_put,\
  195. .private_value = (long) (bindrec) }
  196. /*
  197. * SPDIF I/O
  198. */
  199. int snd_hda_create_spdif_out_ctls(struct hda_codec *codec, hda_nid_t nid);
  200. int snd_hda_create_spdif_in_ctls(struct hda_codec *codec, hda_nid_t nid);
  201. /*
  202. * input MUX helper
  203. */
  204. #define HDA_MAX_NUM_INPUTS 16
  205. struct hda_input_mux_item {
  206. char label[32];
  207. unsigned int index;
  208. };
  209. struct hda_input_mux {
  210. unsigned int num_items;
  211. struct hda_input_mux_item items[HDA_MAX_NUM_INPUTS];
  212. };
  213. int snd_hda_input_mux_info(const struct hda_input_mux *imux,
  214. struct snd_ctl_elem_info *uinfo);
  215. int snd_hda_input_mux_put(struct hda_codec *codec,
  216. const struct hda_input_mux *imux,
  217. struct snd_ctl_elem_value *ucontrol, hda_nid_t nid,
  218. unsigned int *cur_val);
  219. /*
  220. * Channel mode helper
  221. */
  222. struct hda_channel_mode {
  223. int channels;
  224. const struct hda_verb *sequence;
  225. };
  226. int snd_hda_ch_mode_info(struct hda_codec *codec,
  227. struct snd_ctl_elem_info *uinfo,
  228. const struct hda_channel_mode *chmode,
  229. int num_chmodes);
  230. int snd_hda_ch_mode_get(struct hda_codec *codec,
  231. struct snd_ctl_elem_value *ucontrol,
  232. const struct hda_channel_mode *chmode,
  233. int num_chmodes,
  234. int max_channels);
  235. int snd_hda_ch_mode_put(struct hda_codec *codec,
  236. struct snd_ctl_elem_value *ucontrol,
  237. const struct hda_channel_mode *chmode,
  238. int num_chmodes,
  239. int *max_channelsp);
  240. /*
  241. * Multi-channel / digital-out PCM helper
  242. */
  243. enum { HDA_FRONT, HDA_REAR, HDA_CLFE, HDA_SIDE }; /* index for dac_nidx */
  244. enum { HDA_DIG_NONE, HDA_DIG_EXCLUSIVE, HDA_DIG_ANALOG_DUP }; /* dig_out_used */
  245. struct hda_multi_out {
  246. int num_dacs; /* # of DACs, must be more than 1 */
  247. hda_nid_t *dac_nids; /* DAC list */
  248. hda_nid_t hp_nid; /* optional DAC for HP, 0 when not exists */
  249. hda_nid_t extra_out_nid[3]; /* optional DACs, 0 when not exists */
  250. hda_nid_t dig_out_nid; /* digital out audio widget */
  251. hda_nid_t *slave_dig_outs;
  252. int max_channels; /* currently supported analog channels */
  253. int dig_out_used; /* current usage of digital out (HDA_DIG_XXX) */
  254. int no_share_stream; /* don't share a stream with multiple pins */
  255. int share_spdif; /* share SPDIF pin */
  256. /* PCM information for both analog and SPDIF DACs */
  257. unsigned int analog_rates;
  258. unsigned int analog_maxbps;
  259. u64 analog_formats;
  260. unsigned int spdif_rates;
  261. unsigned int spdif_maxbps;
  262. u64 spdif_formats;
  263. };
  264. int snd_hda_create_spdif_share_sw(struct hda_codec *codec,
  265. struct hda_multi_out *mout);
  266. int snd_hda_multi_out_dig_open(struct hda_codec *codec,
  267. struct hda_multi_out *mout);
  268. int snd_hda_multi_out_dig_close(struct hda_codec *codec,
  269. struct hda_multi_out *mout);
  270. int snd_hda_multi_out_dig_prepare(struct hda_codec *codec,
  271. struct hda_multi_out *mout,
  272. unsigned int stream_tag,
  273. unsigned int format,
  274. struct snd_pcm_substream *substream);
  275. int snd_hda_multi_out_dig_cleanup(struct hda_codec *codec,
  276. struct hda_multi_out *mout);
  277. int snd_hda_multi_out_analog_open(struct hda_codec *codec,
  278. struct hda_multi_out *mout,
  279. struct snd_pcm_substream *substream,
  280. struct hda_pcm_stream *hinfo);
  281. int snd_hda_multi_out_analog_prepare(struct hda_codec *codec,
  282. struct hda_multi_out *mout,
  283. unsigned int stream_tag,
  284. unsigned int format,
  285. struct snd_pcm_substream *substream);
  286. int snd_hda_multi_out_analog_cleanup(struct hda_codec *codec,
  287. struct hda_multi_out *mout);
  288. /*
  289. * generic codec parser
  290. */
  291. #ifdef CONFIG_SND_HDA_GENERIC
  292. int snd_hda_parse_generic_codec(struct hda_codec *codec);
  293. #else
  294. static inline int snd_hda_parse_generic_codec(struct hda_codec *codec)
  295. {
  296. return -ENODEV;
  297. }
  298. #endif
  299. /*
  300. * generic proc interface
  301. */
  302. #ifdef CONFIG_PROC_FS
  303. int snd_hda_codec_proc_new(struct hda_codec *codec);
  304. #else
  305. static inline int snd_hda_codec_proc_new(struct hda_codec *codec) { return 0; }
  306. #endif
  307. #define SND_PRINT_RATES_ADVISED_BUFSIZE 80
  308. void snd_print_pcm_rates(int pcm, char *buf, int buflen);
  309. #define SND_PRINT_BITS_ADVISED_BUFSIZE 16
  310. void snd_print_pcm_bits(int pcm, char *buf, int buflen);
  311. /*
  312. * Misc
  313. */
  314. int snd_hda_check_board_config(struct hda_codec *codec, int num_configs,
  315. const char * const *modelnames,
  316. const struct snd_pci_quirk *pci_list);
  317. int snd_hda_check_board_codec_sid_config(struct hda_codec *codec,
  318. int num_configs, const char * const *models,
  319. const struct snd_pci_quirk *tbl);
  320. int snd_hda_add_new_ctls(struct hda_codec *codec,
  321. struct snd_kcontrol_new *knew);
  322. /*
  323. * unsolicited event handler
  324. */
  325. #define HDA_UNSOL_QUEUE_SIZE 64
  326. struct hda_bus_unsolicited {
  327. /* ring buffer */
  328. u32 queue[HDA_UNSOL_QUEUE_SIZE * 2];
  329. unsigned int rp, wp;
  330. /* workqueue */
  331. struct work_struct work;
  332. struct hda_bus *bus;
  333. };
  334. /*
  335. * Helper for automatic pin configuration
  336. */
  337. enum {
  338. AUTO_PIN_MIC,
  339. AUTO_PIN_LINE_IN,
  340. AUTO_PIN_CD,
  341. AUTO_PIN_AUX,
  342. AUTO_PIN_LAST
  343. };
  344. enum {
  345. AUTO_PIN_LINE_OUT,
  346. AUTO_PIN_SPEAKER_OUT,
  347. AUTO_PIN_HP_OUT
  348. };
  349. #define AUTO_CFG_MAX_OUTS 5
  350. #define AUTO_CFG_MAX_INS 8
  351. struct auto_pin_cfg_item {
  352. hda_nid_t pin;
  353. int type;
  354. };
  355. struct auto_pin_cfg;
  356. const char *hda_get_input_pin_label(struct hda_codec *codec, hda_nid_t pin,
  357. int check_location);
  358. const char *hda_get_autocfg_input_label(struct hda_codec *codec,
  359. const struct auto_pin_cfg *cfg,
  360. int input);
  361. int snd_hda_add_imux_item(struct hda_input_mux *imux, const char *label,
  362. int index, int *type_index_ret);
  363. enum {
  364. INPUT_PIN_ATTR_UNUSED, /* pin not connected */
  365. INPUT_PIN_ATTR_INT, /* internal mic/line-in */
  366. INPUT_PIN_ATTR_DOCK, /* docking mic/line-in */
  367. INPUT_PIN_ATTR_NORMAL, /* mic/line-in jack */
  368. INPUT_PIN_ATTR_FRONT, /* mic/line-in jack in front */
  369. INPUT_PIN_ATTR_REAR, /* mic/line-in jack in rear */
  370. };
  371. int snd_hda_get_input_pin_attr(unsigned int def_conf);
  372. struct auto_pin_cfg {
  373. int line_outs;
  374. /* sorted in the order of Front/Surr/CLFE/Side */
  375. hda_nid_t line_out_pins[AUTO_CFG_MAX_OUTS];
  376. int speaker_outs;
  377. hda_nid_t speaker_pins[AUTO_CFG_MAX_OUTS];
  378. int hp_outs;
  379. int line_out_type; /* AUTO_PIN_XXX_OUT */
  380. hda_nid_t hp_pins[AUTO_CFG_MAX_OUTS];
  381. int num_inputs;
  382. struct auto_pin_cfg_item inputs[AUTO_CFG_MAX_INS];
  383. int dig_outs;
  384. hda_nid_t dig_out_pins[2];
  385. hda_nid_t dig_in_pin;
  386. hda_nid_t mono_out_pin;
  387. int dig_out_type[2]; /* HDA_PCM_TYPE_XXX */
  388. int dig_in_type; /* HDA_PCM_TYPE_XXX */
  389. };
  390. #define get_defcfg_connect(cfg) \
  391. ((cfg & AC_DEFCFG_PORT_CONN) >> AC_DEFCFG_PORT_CONN_SHIFT)
  392. #define get_defcfg_association(cfg) \
  393. ((cfg & AC_DEFCFG_DEF_ASSOC) >> AC_DEFCFG_ASSOC_SHIFT)
  394. #define get_defcfg_location(cfg) \
  395. ((cfg & AC_DEFCFG_LOCATION) >> AC_DEFCFG_LOCATION_SHIFT)
  396. #define get_defcfg_sequence(cfg) \
  397. (cfg & AC_DEFCFG_SEQUENCE)
  398. #define get_defcfg_device(cfg) \
  399. ((cfg & AC_DEFCFG_DEVICE) >> AC_DEFCFG_DEVICE_SHIFT)
  400. int snd_hda_parse_pin_def_config(struct hda_codec *codec,
  401. struct auto_pin_cfg *cfg,
  402. hda_nid_t *ignore_nids);
  403. /* amp values */
  404. #define AMP_IN_MUTE(idx) (0x7080 | ((idx)<<8))
  405. #define AMP_IN_UNMUTE(idx) (0x7000 | ((idx)<<8))
  406. #define AMP_OUT_MUTE 0xb080
  407. #define AMP_OUT_UNMUTE 0xb000
  408. #define AMP_OUT_ZERO 0xb000
  409. /* pinctl values */
  410. #define PIN_IN (AC_PINCTL_IN_EN)
  411. #define PIN_VREFHIZ (AC_PINCTL_IN_EN | AC_PINCTL_VREF_HIZ)
  412. #define PIN_VREF50 (AC_PINCTL_IN_EN | AC_PINCTL_VREF_50)
  413. #define PIN_VREFGRD (AC_PINCTL_IN_EN | AC_PINCTL_VREF_GRD)
  414. #define PIN_VREF80 (AC_PINCTL_IN_EN | AC_PINCTL_VREF_80)
  415. #define PIN_VREF100 (AC_PINCTL_IN_EN | AC_PINCTL_VREF_100)
  416. #define PIN_OUT (AC_PINCTL_OUT_EN)
  417. #define PIN_HP (AC_PINCTL_OUT_EN | AC_PINCTL_HP_EN)
  418. #define PIN_HP_AMP (AC_PINCTL_HP_EN)
  419. /*
  420. * get widget capabilities
  421. */
  422. static inline u32 get_wcaps(struct hda_codec *codec, hda_nid_t nid)
  423. {
  424. if (nid < codec->start_nid ||
  425. nid >= codec->start_nid + codec->num_nodes)
  426. return 0;
  427. return codec->wcaps[nid - codec->start_nid];
  428. }
  429. /* get the widget type from widget capability bits */
  430. #define get_wcaps_type(wcaps) (((wcaps) & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT)
  431. static inline unsigned int get_wcaps_channels(u32 wcaps)
  432. {
  433. unsigned int chans;
  434. chans = (wcaps & AC_WCAP_CHAN_CNT_EXT) >> 13;
  435. chans = ((chans << 1) | 1) + 1;
  436. return chans;
  437. }
  438. u32 query_amp_caps(struct hda_codec *codec, hda_nid_t nid, int direction);
  439. int snd_hda_override_amp_caps(struct hda_codec *codec, hda_nid_t nid, int dir,
  440. unsigned int caps);
  441. u32 snd_hda_query_pin_caps(struct hda_codec *codec, hda_nid_t nid);
  442. u32 snd_hda_pin_sense(struct hda_codec *codec, hda_nid_t nid);
  443. int snd_hda_jack_detect(struct hda_codec *codec, hda_nid_t nid);
  444. /* flags for hda_nid_item */
  445. #define HDA_NID_ITEM_AMP (1<<0)
  446. struct hda_nid_item {
  447. struct snd_kcontrol *kctl;
  448. unsigned int index;
  449. hda_nid_t nid;
  450. unsigned short flags;
  451. };
  452. int snd_hda_ctl_add(struct hda_codec *codec, hda_nid_t nid,
  453. struct snd_kcontrol *kctl);
  454. int snd_hda_add_nid(struct hda_codec *codec, struct snd_kcontrol *kctl,
  455. unsigned int index, hda_nid_t nid);
  456. void snd_hda_ctls_clear(struct hda_codec *codec);
  457. /*
  458. * hwdep interface
  459. */
  460. #ifdef CONFIG_SND_HDA_HWDEP
  461. int snd_hda_create_hwdep(struct hda_codec *codec);
  462. #else
  463. static inline int snd_hda_create_hwdep(struct hda_codec *codec) { return 0; }
  464. #endif
  465. #if defined(CONFIG_SND_HDA_POWER_SAVE) && defined(CONFIG_SND_HDA_HWDEP)
  466. int snd_hda_hwdep_add_power_sysfs(struct hda_codec *codec);
  467. #else
  468. static inline int snd_hda_hwdep_add_power_sysfs(struct hda_codec *codec)
  469. {
  470. return 0;
  471. }
  472. #endif
  473. #ifdef CONFIG_SND_HDA_RECONFIG
  474. int snd_hda_hwdep_add_sysfs(struct hda_codec *codec);
  475. #else
  476. static inline int snd_hda_hwdep_add_sysfs(struct hda_codec *codec)
  477. {
  478. return 0;
  479. }
  480. #endif
  481. #ifdef CONFIG_SND_HDA_RECONFIG
  482. const char *snd_hda_get_hint(struct hda_codec *codec, const char *key);
  483. int snd_hda_get_bool_hint(struct hda_codec *codec, const char *key);
  484. #else
  485. static inline
  486. const char *snd_hda_get_hint(struct hda_codec *codec, const char *key)
  487. {
  488. return NULL;
  489. }
  490. static inline
  491. int snd_hda_get_bool_hint(struct hda_codec *codec, const char *key)
  492. {
  493. return -ENOENT;
  494. }
  495. #endif
  496. /*
  497. * power-management
  498. */
  499. #ifdef CONFIG_SND_HDA_POWER_SAVE
  500. void snd_hda_schedule_power_save(struct hda_codec *codec);
  501. struct hda_amp_list {
  502. hda_nid_t nid;
  503. unsigned char dir;
  504. unsigned char idx;
  505. };
  506. struct hda_loopback_check {
  507. struct hda_amp_list *amplist;
  508. int power_on;
  509. };
  510. int snd_hda_check_amp_list_power(struct hda_codec *codec,
  511. struct hda_loopback_check *check,
  512. hda_nid_t nid);
  513. #endif /* CONFIG_SND_HDA_POWER_SAVE */
  514. /*
  515. * AMP control callbacks
  516. */
  517. /* retrieve parameters from private_value */
  518. #define get_amp_nid_(pv) ((pv) & 0xffff)
  519. #define get_amp_nid(kc) get_amp_nid_((kc)->private_value)
  520. #define get_amp_channels(kc) (((kc)->private_value >> 16) & 0x3)
  521. #define get_amp_direction(kc) (((kc)->private_value >> 18) & 0x1)
  522. #define get_amp_index(kc) (((kc)->private_value >> 19) & 0xf)
  523. #define get_amp_offset(kc) (((kc)->private_value >> 23) & 0x3f)
  524. #define get_amp_min_mute(kc) (((kc)->private_value >> 29) & 0x1)
  525. /*
  526. * CEA Short Audio Descriptor data
  527. */
  528. struct cea_sad {
  529. int channels;
  530. int format; /* (format == 0) indicates invalid SAD */
  531. int rates;
  532. int sample_bits; /* for LPCM */
  533. int max_bitrate; /* for AC3...ATRAC */
  534. int profile; /* for WMAPRO */
  535. };
  536. #define ELD_FIXED_BYTES 20
  537. #define ELD_MAX_MNL 16
  538. #define ELD_MAX_SAD 16
  539. /*
  540. * ELD: EDID Like Data
  541. */
  542. struct hdmi_eld {
  543. bool monitor_present;
  544. bool eld_valid;
  545. int eld_size;
  546. int baseline_len;
  547. int eld_ver;
  548. int cea_edid_ver;
  549. char monitor_name[ELD_MAX_MNL + 1];
  550. int manufacture_id;
  551. int product_id;
  552. u64 port_id;
  553. int support_hdcp;
  554. int support_ai;
  555. int conn_type;
  556. int aud_synch_delay;
  557. int spk_alloc;
  558. int sad_count;
  559. struct cea_sad sad[ELD_MAX_SAD];
  560. #ifdef CONFIG_PROC_FS
  561. struct snd_info_entry *proc_entry;
  562. #endif
  563. };
  564. int snd_hdmi_get_eld_size(struct hda_codec *codec, hda_nid_t nid);
  565. int snd_hdmi_get_eld(struct hdmi_eld *, struct hda_codec *, hda_nid_t);
  566. void snd_hdmi_show_eld(struct hdmi_eld *eld);
  567. void hdmi_eld_update_pcm_info(struct hdmi_eld *eld, struct hda_pcm_stream *pcm,
  568. struct hda_pcm_stream *codec_pars);
  569. #ifdef CONFIG_PROC_FS
  570. int snd_hda_eld_proc_new(struct hda_codec *codec, struct hdmi_eld *eld,
  571. int index);
  572. void snd_hda_eld_proc_free(struct hda_codec *codec, struct hdmi_eld *eld);
  573. #else
  574. static inline int snd_hda_eld_proc_new(struct hda_codec *codec,
  575. struct hdmi_eld *eld,
  576. int index)
  577. {
  578. return 0;
  579. }
  580. static inline void snd_hda_eld_proc_free(struct hda_codec *codec,
  581. struct hdmi_eld *eld)
  582. {
  583. }
  584. #endif
  585. #define SND_PRINT_CHANNEL_ALLOCATION_ADVISED_BUFSIZE 80
  586. void snd_print_channel_allocation(int spk_alloc, char *buf, int buflen);
  587. /*
  588. * Input-jack notification support
  589. */
  590. #ifdef CONFIG_SND_HDA_INPUT_JACK
  591. int snd_hda_input_jack_add(struct hda_codec *codec, hda_nid_t nid, int type,
  592. const char *name);
  593. void snd_hda_input_jack_report(struct hda_codec *codec, hda_nid_t nid);
  594. void snd_hda_input_jack_free(struct hda_codec *codec);
  595. #else /* CONFIG_SND_HDA_INPUT_JACK */
  596. static inline int snd_hda_input_jack_add(struct hda_codec *codec,
  597. hda_nid_t nid, int type,
  598. const char *name)
  599. {
  600. return 0;
  601. }
  602. static inline void snd_hda_input_jack_report(struct hda_codec *codec,
  603. hda_nid_t nid)
  604. {
  605. }
  606. static inline void snd_hda_input_jack_free(struct hda_codec *codec)
  607. {
  608. }
  609. #endif /* CONFIG_SND_HDA_INPUT_JACK */
  610. #endif /* __SOUND_HDA_LOCAL_H */