hda_local.h 21 KB

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