hda_local.h 20 KB

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