hda_local.h 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  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. /*
  25. * for mixer controls
  26. */
  27. #define HDA_COMPOSE_AMP_VAL(nid,chs,idx,dir) ((nid) | ((chs)<<16) | ((dir)<<18) | ((idx)<<19))
  28. #define HDA_CODEC_VOLUME_MONO_IDX(xname, xcidx, nid, channel, xindex, direction) \
  29. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xcidx, \
  30. .info = snd_hda_mixer_amp_volume_info, \
  31. .get = snd_hda_mixer_amp_volume_get, \
  32. .put = snd_hda_mixer_amp_volume_put, \
  33. .private_value = HDA_COMPOSE_AMP_VAL(nid, channel, xindex, direction) }
  34. #define HDA_CODEC_VOLUME_IDX(xname, xcidx, nid, xindex, direction) \
  35. HDA_CODEC_VOLUME_MONO_IDX(xname, xcidx, nid, 3, xindex, direction)
  36. #define HDA_CODEC_VOLUME_MONO(xname, nid, channel, xindex, direction) \
  37. HDA_CODEC_VOLUME_MONO_IDX(xname, 0, nid, channel, xindex, direction)
  38. #define HDA_CODEC_VOLUME(xname, nid, xindex, direction) \
  39. HDA_CODEC_VOLUME_MONO(xname, nid, 3, xindex, direction)
  40. #define HDA_CODEC_MUTE_MONO_IDX(xname, xcidx, nid, channel, xindex, direction) \
  41. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xcidx, \
  42. .info = snd_hda_mixer_amp_switch_info, \
  43. .get = snd_hda_mixer_amp_switch_get, \
  44. .put = snd_hda_mixer_amp_switch_put, \
  45. .private_value = HDA_COMPOSE_AMP_VAL(nid, channel, xindex, direction) }
  46. #define HDA_CODEC_MUTE_IDX(xname, xcidx, nid, xindex, direction) \
  47. HDA_CODEC_MUTE_MONO_IDX(xname, xcidx, nid, 3, xindex, direction)
  48. #define HDA_CODEC_MUTE_MONO(xname, nid, channel, xindex, direction) \
  49. HDA_CODEC_MUTE_MONO_IDX(xname, 0, nid, channel, xindex, direction)
  50. #define HDA_CODEC_MUTE(xname, nid, xindex, direction) \
  51. HDA_CODEC_MUTE_MONO(xname, nid, 3, xindex, direction)
  52. int snd_hda_mixer_amp_volume_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t *uinfo);
  53. int snd_hda_mixer_amp_volume_get(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol);
  54. int snd_hda_mixer_amp_volume_put(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol);
  55. int snd_hda_mixer_amp_switch_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t *uinfo);
  56. int snd_hda_mixer_amp_switch_get(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol);
  57. int snd_hda_mixer_amp_switch_put(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol);
  58. int snd_hda_create_spdif_out_ctls(struct hda_codec *codec, hda_nid_t nid);
  59. int snd_hda_create_spdif_in_ctls(struct hda_codec *codec, hda_nid_t nid);
  60. /*
  61. * input MUX helper
  62. */
  63. #define HDA_MAX_NUM_INPUTS 8
  64. struct hda_input_mux_item {
  65. const char *label;
  66. unsigned int index;
  67. };
  68. struct hda_input_mux {
  69. unsigned int num_items;
  70. struct hda_input_mux_item items[HDA_MAX_NUM_INPUTS];
  71. };
  72. int snd_hda_input_mux_info(const struct hda_input_mux *imux, snd_ctl_elem_info_t *uinfo);
  73. int snd_hda_input_mux_put(struct hda_codec *codec, const struct hda_input_mux *imux,
  74. snd_ctl_elem_value_t *ucontrol, hda_nid_t nid,
  75. unsigned int *cur_val);
  76. /*
  77. * Multi-channel / digital-out PCM helper
  78. */
  79. enum { HDA_FRONT, HDA_REAR, HDA_CLFE, HDA_SIDE }; /* index for dac_nidx */
  80. enum { HDA_DIG_NONE, HDA_DIG_EXCLUSIVE, HDA_DIG_ANALOG_DUP }; /* dig_out_used */
  81. struct hda_multi_out {
  82. int num_dacs; /* # of DACs, must be more than 1 */
  83. hda_nid_t *dac_nids; /* DAC list */
  84. hda_nid_t hp_nid; /* optional DAC for HP, 0 when not exists */
  85. hda_nid_t dig_out_nid; /* digital out audio widget */
  86. int max_channels; /* currently supported analog channels */
  87. int dig_out_used; /* current usage of digital out (HDA_DIG_XXX) */
  88. };
  89. int snd_hda_multi_out_dig_open(struct hda_codec *codec, struct hda_multi_out *mout);
  90. int snd_hda_multi_out_dig_close(struct hda_codec *codec, struct hda_multi_out *mout);
  91. int snd_hda_multi_out_analog_open(struct hda_codec *codec, struct hda_multi_out *mout,
  92. snd_pcm_substream_t *substream);
  93. int snd_hda_multi_out_analog_prepare(struct hda_codec *codec, struct hda_multi_out *mout,
  94. unsigned int stream_tag,
  95. unsigned int format,
  96. snd_pcm_substream_t *substream);
  97. int snd_hda_multi_out_analog_cleanup(struct hda_codec *codec, struct hda_multi_out *mout);
  98. /*
  99. * generic codec parser
  100. */
  101. int snd_hda_parse_generic_codec(struct hda_codec *codec);
  102. /*
  103. * generic proc interface
  104. */
  105. #ifdef CONFIG_PROC_FS
  106. int snd_hda_codec_proc_new(struct hda_codec *codec);
  107. #else
  108. static inline int snd_hda_codec_proc_new(struct hda_codec *codec) { return 0; }
  109. #endif
  110. /*
  111. * Misc
  112. */
  113. struct hda_board_config {
  114. const char *modelname;
  115. int config;
  116. unsigned short pci_subvendor;
  117. unsigned short pci_subdevice;
  118. };
  119. int snd_hda_check_board_config(struct hda_codec *codec, const struct hda_board_config *tbl);
  120. int snd_hda_add_new_ctls(struct hda_codec *codec, snd_kcontrol_new_t *knew);
  121. /*
  122. * power management
  123. */
  124. #ifdef CONFIG_PM
  125. int snd_hda_resume_ctls(struct hda_codec *codec, snd_kcontrol_new_t *knew);
  126. int snd_hda_resume_spdif_out(struct hda_codec *codec);
  127. int snd_hda_resume_spdif_in(struct hda_codec *codec);
  128. #endif
  129. /*
  130. * unsolicited event handler
  131. */
  132. #define HDA_UNSOL_QUEUE_SIZE 64
  133. struct hda_bus_unsolicited {
  134. /* ring buffer */
  135. u32 queue[HDA_UNSOL_QUEUE_SIZE * 2];
  136. unsigned int rp, wp;
  137. /* workqueue */
  138. struct workqueue_struct *workq;
  139. struct work_struct work;
  140. };
  141. /*
  142. * Helper for automatic ping configuration
  143. */
  144. enum {
  145. AUTO_PIN_MIC,
  146. AUTO_PIN_FRONT_MIC,
  147. AUTO_PIN_LINE,
  148. AUTO_PIN_FRONT_LINE,
  149. AUTO_PIN_CD,
  150. AUTO_PIN_AUX,
  151. AUTO_PIN_LAST
  152. };
  153. struct auto_pin_cfg {
  154. int line_outs;
  155. hda_nid_t line_out_pins[4]; /* sorted in the order of Front/Surr/CLFE/Side */
  156. hda_nid_t hp_pin;
  157. hda_nid_t input_pins[AUTO_PIN_LAST];
  158. hda_nid_t dig_out_pin;
  159. hda_nid_t dig_in_pin;
  160. };
  161. #define get_defcfg_connect(cfg) ((cfg & AC_DEFCFG_PORT_CONN) >> AC_DEFCFG_PORT_CONN_SHIFT)
  162. #define get_defcfg_association(cfg) ((cfg & AC_DEFCFG_DEF_ASSOC) >> AC_DEFCFG_ASSOC_SHIFT)
  163. #define get_defcfg_location(cfg) ((cfg & AC_DEFCFG_LOCATION) >> AC_DEFCFG_LOCATION_SHIFT)
  164. #define get_defcfg_sequence(cfg) (cfg & AC_DEFCFG_SEQUENCE)
  165. #define get_defcfg_device(cfg) ((cfg & AC_DEFCFG_DEVICE) >> AC_DEFCFG_DEVICE_SHIFT)
  166. int snd_hda_parse_pin_def_config(struct hda_codec *codec, struct auto_pin_cfg *cfg);
  167. #endif /* __SOUND_HDA_LOCAL_H */