hda_local.h 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639
  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. extern const char *auto_pin_cfg_labels[AUTO_PIN_LAST];
  345. #define AUTO_CFG_MAX_OUTS 5
  346. #define AUTO_CFG_MAX_INS 8
  347. struct auto_pin_cfg_item {
  348. hda_nid_t pin;
  349. int type;
  350. };
  351. struct auto_pin_cfg;
  352. void snd_hda_get_input_pin_label(const struct auto_pin_cfg *cfg,
  353. int input, char *label);
  354. struct auto_pin_cfg {
  355. int line_outs;
  356. /* sorted in the order of Front/Surr/CLFE/Side */
  357. hda_nid_t line_out_pins[AUTO_CFG_MAX_OUTS];
  358. int speaker_outs;
  359. hda_nid_t speaker_pins[AUTO_CFG_MAX_OUTS];
  360. int hp_outs;
  361. int line_out_type; /* AUTO_PIN_XXX_OUT */
  362. hda_nid_t hp_pins[AUTO_CFG_MAX_OUTS];
  363. int num_inputs;
  364. struct auto_pin_cfg_item inputs[AUTO_CFG_MAX_INS];
  365. int dig_outs;
  366. hda_nid_t dig_out_pins[2];
  367. hda_nid_t dig_in_pin;
  368. hda_nid_t mono_out_pin;
  369. int dig_out_type[2]; /* HDA_PCM_TYPE_XXX */
  370. int dig_in_type; /* HDA_PCM_TYPE_XXX */
  371. };
  372. #define get_defcfg_connect(cfg) \
  373. ((cfg & AC_DEFCFG_PORT_CONN) >> AC_DEFCFG_PORT_CONN_SHIFT)
  374. #define get_defcfg_association(cfg) \
  375. ((cfg & AC_DEFCFG_DEF_ASSOC) >> AC_DEFCFG_ASSOC_SHIFT)
  376. #define get_defcfg_location(cfg) \
  377. ((cfg & AC_DEFCFG_LOCATION) >> AC_DEFCFG_LOCATION_SHIFT)
  378. #define get_defcfg_sequence(cfg) \
  379. (cfg & AC_DEFCFG_SEQUENCE)
  380. #define get_defcfg_device(cfg) \
  381. ((cfg & AC_DEFCFG_DEVICE) >> AC_DEFCFG_DEVICE_SHIFT)
  382. int snd_hda_parse_pin_def_config(struct hda_codec *codec,
  383. struct auto_pin_cfg *cfg,
  384. hda_nid_t *ignore_nids);
  385. /* amp values */
  386. #define AMP_IN_MUTE(idx) (0x7080 | ((idx)<<8))
  387. #define AMP_IN_UNMUTE(idx) (0x7000 | ((idx)<<8))
  388. #define AMP_OUT_MUTE 0xb080
  389. #define AMP_OUT_UNMUTE 0xb000
  390. #define AMP_OUT_ZERO 0xb000
  391. /* pinctl values */
  392. #define PIN_IN (AC_PINCTL_IN_EN)
  393. #define PIN_VREFHIZ (AC_PINCTL_IN_EN | AC_PINCTL_VREF_HIZ)
  394. #define PIN_VREF50 (AC_PINCTL_IN_EN | AC_PINCTL_VREF_50)
  395. #define PIN_VREFGRD (AC_PINCTL_IN_EN | AC_PINCTL_VREF_GRD)
  396. #define PIN_VREF80 (AC_PINCTL_IN_EN | AC_PINCTL_VREF_80)
  397. #define PIN_VREF100 (AC_PINCTL_IN_EN | AC_PINCTL_VREF_100)
  398. #define PIN_OUT (AC_PINCTL_OUT_EN)
  399. #define PIN_HP (AC_PINCTL_OUT_EN | AC_PINCTL_HP_EN)
  400. #define PIN_HP_AMP (AC_PINCTL_HP_EN)
  401. /*
  402. * get widget capabilities
  403. */
  404. static inline u32 get_wcaps(struct hda_codec *codec, hda_nid_t nid)
  405. {
  406. if (nid < codec->start_nid ||
  407. nid >= codec->start_nid + codec->num_nodes)
  408. return 0;
  409. return codec->wcaps[nid - codec->start_nid];
  410. }
  411. /* get the widget type from widget capability bits */
  412. #define get_wcaps_type(wcaps) (((wcaps) & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT)
  413. static inline unsigned int get_wcaps_channels(u32 wcaps)
  414. {
  415. unsigned int chans;
  416. chans = (wcaps & AC_WCAP_CHAN_CNT_EXT) >> 13;
  417. chans = ((chans << 1) | 1) + 1;
  418. return chans;
  419. }
  420. u32 query_amp_caps(struct hda_codec *codec, hda_nid_t nid, int direction);
  421. int snd_hda_override_amp_caps(struct hda_codec *codec, hda_nid_t nid, int dir,
  422. unsigned int caps);
  423. u32 snd_hda_query_pin_caps(struct hda_codec *codec, hda_nid_t nid);
  424. u32 snd_hda_pin_sense(struct hda_codec *codec, hda_nid_t nid);
  425. int snd_hda_jack_detect(struct hda_codec *codec, hda_nid_t nid);
  426. /* flags for hda_nid_item */
  427. #define HDA_NID_ITEM_AMP (1<<0)
  428. struct hda_nid_item {
  429. struct snd_kcontrol *kctl;
  430. unsigned int index;
  431. hda_nid_t nid;
  432. unsigned short flags;
  433. };
  434. int snd_hda_ctl_add(struct hda_codec *codec, hda_nid_t nid,
  435. struct snd_kcontrol *kctl);
  436. int snd_hda_add_nid(struct hda_codec *codec, struct snd_kcontrol *kctl,
  437. unsigned int index, hda_nid_t nid);
  438. void snd_hda_ctls_clear(struct hda_codec *codec);
  439. /*
  440. * hwdep interface
  441. */
  442. #ifdef CONFIG_SND_HDA_HWDEP
  443. int snd_hda_create_hwdep(struct hda_codec *codec);
  444. #else
  445. static inline int snd_hda_create_hwdep(struct hda_codec *codec) { return 0; }
  446. #endif
  447. #if defined(CONFIG_SND_HDA_POWER_SAVE) && defined(CONFIG_SND_HDA_HWDEP)
  448. int snd_hda_hwdep_add_power_sysfs(struct hda_codec *codec);
  449. #else
  450. static inline int snd_hda_hwdep_add_power_sysfs(struct hda_codec *codec)
  451. {
  452. return 0;
  453. }
  454. #endif
  455. #ifdef CONFIG_SND_HDA_RECONFIG
  456. int snd_hda_hwdep_add_sysfs(struct hda_codec *codec);
  457. #else
  458. static inline int snd_hda_hwdep_add_sysfs(struct hda_codec *codec)
  459. {
  460. return 0;
  461. }
  462. #endif
  463. #ifdef CONFIG_SND_HDA_RECONFIG
  464. const char *snd_hda_get_hint(struct hda_codec *codec, const char *key);
  465. int snd_hda_get_bool_hint(struct hda_codec *codec, const char *key);
  466. #else
  467. static inline
  468. const char *snd_hda_get_hint(struct hda_codec *codec, const char *key)
  469. {
  470. return NULL;
  471. }
  472. static inline
  473. int snd_hda_get_bool_hint(struct hda_codec *codec, const char *key)
  474. {
  475. return -ENOENT;
  476. }
  477. #endif
  478. /*
  479. * power-management
  480. */
  481. #ifdef CONFIG_SND_HDA_POWER_SAVE
  482. void snd_hda_schedule_power_save(struct hda_codec *codec);
  483. struct hda_amp_list {
  484. hda_nid_t nid;
  485. unsigned char dir;
  486. unsigned char idx;
  487. };
  488. struct hda_loopback_check {
  489. struct hda_amp_list *amplist;
  490. int power_on;
  491. };
  492. int snd_hda_check_amp_list_power(struct hda_codec *codec,
  493. struct hda_loopback_check *check,
  494. hda_nid_t nid);
  495. #endif /* CONFIG_SND_HDA_POWER_SAVE */
  496. /*
  497. * AMP control callbacks
  498. */
  499. /* retrieve parameters from private_value */
  500. #define get_amp_nid_(pv) ((pv) & 0xffff)
  501. #define get_amp_nid(kc) get_amp_nid_((kc)->private_value)
  502. #define get_amp_channels(kc) (((kc)->private_value >> 16) & 0x3)
  503. #define get_amp_direction(kc) (((kc)->private_value >> 18) & 0x1)
  504. #define get_amp_index(kc) (((kc)->private_value >> 19) & 0xf)
  505. #define get_amp_offset(kc) (((kc)->private_value >> 23) & 0x3f)
  506. /*
  507. * CEA Short Audio Descriptor data
  508. */
  509. struct cea_sad {
  510. int channels;
  511. int format; /* (format == 0) indicates invalid SAD */
  512. int rates;
  513. int sample_bits; /* for LPCM */
  514. int max_bitrate; /* for AC3...ATRAC */
  515. int profile; /* for WMAPRO */
  516. };
  517. #define ELD_FIXED_BYTES 20
  518. #define ELD_MAX_MNL 16
  519. #define ELD_MAX_SAD 16
  520. /*
  521. * ELD: EDID Like Data
  522. */
  523. struct hdmi_eld {
  524. bool monitor_present;
  525. bool eld_valid;
  526. int eld_size;
  527. int baseline_len;
  528. int eld_ver;
  529. int cea_edid_ver;
  530. char monitor_name[ELD_MAX_MNL + 1];
  531. int manufacture_id;
  532. int product_id;
  533. u64 port_id;
  534. int support_hdcp;
  535. int support_ai;
  536. int conn_type;
  537. int aud_synch_delay;
  538. int spk_alloc;
  539. int sad_count;
  540. struct cea_sad sad[ELD_MAX_SAD];
  541. #ifdef CONFIG_PROC_FS
  542. struct snd_info_entry *proc_entry;
  543. #endif
  544. };
  545. int snd_hdmi_get_eld_size(struct hda_codec *codec, hda_nid_t nid);
  546. int snd_hdmi_get_eld(struct hdmi_eld *, struct hda_codec *, hda_nid_t);
  547. void snd_hdmi_show_eld(struct hdmi_eld *eld);
  548. void hdmi_eld_update_pcm_info(struct hdmi_eld *eld, struct hda_pcm_stream *pcm,
  549. struct hda_pcm_stream *codec_pars);
  550. #ifdef CONFIG_PROC_FS
  551. int snd_hda_eld_proc_new(struct hda_codec *codec, struct hdmi_eld *eld,
  552. int index);
  553. void snd_hda_eld_proc_free(struct hda_codec *codec, struct hdmi_eld *eld);
  554. #else
  555. static inline int snd_hda_eld_proc_new(struct hda_codec *codec,
  556. struct hdmi_eld *eld,
  557. int index)
  558. {
  559. return 0;
  560. }
  561. static inline void snd_hda_eld_proc_free(struct hda_codec *codec,
  562. struct hdmi_eld *eld)
  563. {
  564. }
  565. #endif
  566. #define SND_PRINT_CHANNEL_ALLOCATION_ADVISED_BUFSIZE 80
  567. void snd_print_channel_allocation(int spk_alloc, char *buf, int buflen);
  568. #endif /* __SOUND_HDA_LOCAL_H */