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