hda_codec.h 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687
  1. /*
  2. * Universal Interface for Intel High Definition Audio Codec
  3. *
  4. * Copyright (c) 2004 Takashi Iwai <tiwai@suse.de>
  5. *
  6. * This program is free software; you can redistribute it and/or modify it
  7. * under the terms of the GNU General Public License as published by the Free
  8. * Software Foundation; either version 2 of the License, or (at your option)
  9. * any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful, but WITHOUT
  12. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  14. * more details.
  15. *
  16. * You should have received a copy of the GNU General Public License along with
  17. * this program; if not, write to the Free Software Foundation, Inc., 59
  18. * Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  19. */
  20. #ifndef __SOUND_HDA_CODEC_H
  21. #define __SOUND_HDA_CODEC_H
  22. #include <sound/info.h>
  23. #include <sound/control.h>
  24. #include <sound/pcm.h>
  25. #include <sound/hwdep.h>
  26. #include <sound/hda_verbs.h>
  27. /*
  28. * generic arrays
  29. */
  30. struct snd_array {
  31. unsigned int used;
  32. unsigned int alloced;
  33. unsigned int elem_size;
  34. unsigned int alloc_align;
  35. void *list;
  36. };
  37. void *snd_array_new(struct snd_array *array);
  38. void snd_array_free(struct snd_array *array);
  39. static inline void snd_array_init(struct snd_array *array, unsigned int size,
  40. unsigned int align)
  41. {
  42. array->elem_size = size;
  43. array->alloc_align = align;
  44. }
  45. static inline void *snd_array_elem(struct snd_array *array, unsigned int idx)
  46. {
  47. return array->list + idx * array->elem_size;
  48. }
  49. static inline unsigned int snd_array_index(struct snd_array *array, void *ptr)
  50. {
  51. return (unsigned long)(ptr - array->list) / array->elem_size;
  52. }
  53. /*
  54. * Structures
  55. */
  56. struct hda_bus;
  57. struct hda_beep;
  58. struct hda_codec;
  59. struct hda_pcm;
  60. struct hda_pcm_stream;
  61. struct hda_bus_unsolicited;
  62. /* NID type */
  63. typedef u16 hda_nid_t;
  64. /* bus operators */
  65. struct hda_bus_ops {
  66. /* send a single command */
  67. int (*command)(struct hda_bus *bus, unsigned int cmd);
  68. /* get a response from the last command */
  69. unsigned int (*get_response)(struct hda_bus *bus, unsigned int addr);
  70. /* free the private data */
  71. void (*private_free)(struct hda_bus *);
  72. /* attach a PCM stream */
  73. int (*attach_pcm)(struct hda_bus *bus, struct hda_codec *codec,
  74. struct hda_pcm *pcm);
  75. /* reset bus for retry verb */
  76. void (*bus_reset)(struct hda_bus *bus);
  77. #ifdef CONFIG_PM
  78. /* notify power-up/down from codec to controller */
  79. void (*pm_notify)(struct hda_bus *bus, bool power_up);
  80. #endif
  81. #ifdef CONFIG_SND_HDA_DSP_LOADER
  82. /* prepare DSP transfer */
  83. int (*load_dsp_prepare)(struct hda_bus *bus, unsigned int format,
  84. unsigned int byte_size,
  85. struct snd_dma_buffer *bufp);
  86. /* start/stop DSP transfer */
  87. void (*load_dsp_trigger)(struct hda_bus *bus, bool start);
  88. /* clean up DSP transfer */
  89. void (*load_dsp_cleanup)(struct hda_bus *bus,
  90. struct snd_dma_buffer *dmab);
  91. #endif
  92. };
  93. /* template to pass to the bus constructor */
  94. struct hda_bus_template {
  95. void *private_data;
  96. struct pci_dev *pci;
  97. const char *modelname;
  98. int *power_save;
  99. struct hda_bus_ops ops;
  100. };
  101. /*
  102. * codec bus
  103. *
  104. * each controller needs to creata a hda_bus to assign the accessor.
  105. * A hda_bus contains several codecs in the list codec_list.
  106. */
  107. struct hda_bus {
  108. struct snd_card *card;
  109. /* copied from template */
  110. void *private_data;
  111. struct pci_dev *pci;
  112. const char *modelname;
  113. int *power_save;
  114. struct hda_bus_ops ops;
  115. /* codec linked list */
  116. struct list_head codec_list;
  117. unsigned int num_codecs;
  118. /* link caddr -> codec */
  119. struct hda_codec *caddr_tbl[HDA_MAX_CODEC_ADDRESS + 1];
  120. struct mutex cmd_mutex;
  121. struct mutex prepare_mutex;
  122. /* unsolicited event queue */
  123. struct hda_bus_unsolicited *unsol;
  124. char workq_name[16];
  125. struct workqueue_struct *workq; /* common workqueue for codecs */
  126. /* assigned PCMs */
  127. DECLARE_BITMAP(pcm_dev_bits, SNDRV_PCM_DEVICES);
  128. /* misc op flags */
  129. unsigned int needs_damn_long_delay :1;
  130. unsigned int allow_bus_reset:1; /* allow bus reset at fatal error */
  131. unsigned int sync_write:1; /* sync after verb write */
  132. /* status for codec/controller */
  133. unsigned int shutdown :1; /* being unloaded */
  134. unsigned int rirb_error:1; /* error in codec communication */
  135. unsigned int response_reset:1; /* controller was reset */
  136. unsigned int in_reset:1; /* during reset operation */
  137. unsigned int power_keep_link_on:1; /* don't power off HDA link */
  138. unsigned int no_response_fallback:1; /* don't fallback at RIRB error */
  139. int primary_dig_out_type; /* primary digital out PCM type */
  140. };
  141. /*
  142. * codec preset
  143. *
  144. * Known codecs have the patch to build and set up the controls/PCMs
  145. * better than the generic parser.
  146. */
  147. struct hda_codec_preset {
  148. unsigned int id;
  149. unsigned int mask;
  150. unsigned int subs;
  151. unsigned int subs_mask;
  152. unsigned int rev;
  153. hda_nid_t afg, mfg;
  154. const char *name;
  155. int (*patch)(struct hda_codec *codec);
  156. };
  157. struct hda_codec_preset_list {
  158. const struct hda_codec_preset *preset;
  159. struct module *owner;
  160. struct list_head list;
  161. };
  162. /* initial hook */
  163. int snd_hda_add_codec_preset(struct hda_codec_preset_list *preset);
  164. int snd_hda_delete_codec_preset(struct hda_codec_preset_list *preset);
  165. /* ops set by the preset patch */
  166. struct hda_codec_ops {
  167. int (*build_controls)(struct hda_codec *codec);
  168. int (*build_pcms)(struct hda_codec *codec);
  169. int (*init)(struct hda_codec *codec);
  170. void (*free)(struct hda_codec *codec);
  171. void (*unsol_event)(struct hda_codec *codec, unsigned int res);
  172. void (*set_power_state)(struct hda_codec *codec, hda_nid_t fg,
  173. unsigned int power_state);
  174. #ifdef CONFIG_PM
  175. int (*suspend)(struct hda_codec *codec);
  176. int (*resume)(struct hda_codec *codec);
  177. int (*check_power_status)(struct hda_codec *codec, hda_nid_t nid);
  178. #endif
  179. void (*reboot_notify)(struct hda_codec *codec);
  180. };
  181. /* record for amp information cache */
  182. struct hda_cache_head {
  183. u32 key:31; /* hash key */
  184. u32 dirty:1;
  185. u16 val; /* assigned value */
  186. u16 next;
  187. };
  188. struct hda_amp_info {
  189. struct hda_cache_head head;
  190. u32 amp_caps; /* amp capabilities */
  191. u16 vol[2]; /* current volume & mute */
  192. };
  193. struct hda_cache_rec {
  194. u16 hash[64]; /* hash table for index */
  195. struct snd_array buf; /* record entries */
  196. };
  197. /* PCM callbacks */
  198. struct hda_pcm_ops {
  199. int (*open)(struct hda_pcm_stream *info, struct hda_codec *codec,
  200. struct snd_pcm_substream *substream);
  201. int (*close)(struct hda_pcm_stream *info, struct hda_codec *codec,
  202. struct snd_pcm_substream *substream);
  203. int (*prepare)(struct hda_pcm_stream *info, struct hda_codec *codec,
  204. unsigned int stream_tag, unsigned int format,
  205. struct snd_pcm_substream *substream);
  206. int (*cleanup)(struct hda_pcm_stream *info, struct hda_codec *codec,
  207. struct snd_pcm_substream *substream);
  208. unsigned int (*get_delay)(struct hda_pcm_stream *info,
  209. struct hda_codec *codec,
  210. struct snd_pcm_substream *substream);
  211. };
  212. /* PCM information for each substream */
  213. struct hda_pcm_stream {
  214. unsigned int substreams; /* number of substreams, 0 = not exist*/
  215. unsigned int channels_min; /* min. number of channels */
  216. unsigned int channels_max; /* max. number of channels */
  217. hda_nid_t nid; /* default NID to query rates/formats/bps, or set up */
  218. u32 rates; /* supported rates */
  219. u64 formats; /* supported formats (SNDRV_PCM_FMTBIT_) */
  220. unsigned int maxbps; /* supported max. bit per sample */
  221. const struct snd_pcm_chmap_elem *chmap; /* chmap to override */
  222. struct hda_pcm_ops ops;
  223. };
  224. /* PCM types */
  225. enum {
  226. HDA_PCM_TYPE_AUDIO,
  227. HDA_PCM_TYPE_SPDIF,
  228. HDA_PCM_TYPE_HDMI,
  229. HDA_PCM_TYPE_MODEM,
  230. HDA_PCM_NTYPES
  231. };
  232. /* for PCM creation */
  233. struct hda_pcm {
  234. char *name;
  235. struct hda_pcm_stream stream[2];
  236. unsigned int pcm_type; /* HDA_PCM_TYPE_XXX */
  237. int device; /* device number to assign */
  238. struct snd_pcm *pcm; /* assigned PCM instance */
  239. bool own_chmap; /* codec driver provides own channel maps */
  240. };
  241. /* codec information */
  242. struct hda_codec {
  243. struct hda_bus *bus;
  244. unsigned int addr; /* codec addr*/
  245. struct list_head list; /* list point */
  246. hda_nid_t afg; /* AFG node id */
  247. hda_nid_t mfg; /* MFG node id */
  248. /* ids */
  249. u8 afg_function_id;
  250. u8 mfg_function_id;
  251. u8 afg_unsol;
  252. u8 mfg_unsol;
  253. u32 vendor_id;
  254. u32 subsystem_id;
  255. u32 revision_id;
  256. /* detected preset */
  257. const struct hda_codec_preset *preset;
  258. struct module *owner;
  259. int (*parser)(struct hda_codec *codec);
  260. const char *vendor_name; /* codec vendor name */
  261. const char *chip_name; /* codec chip name */
  262. const char *modelname; /* model name for preset */
  263. /* set by patch */
  264. struct hda_codec_ops patch_ops;
  265. /* PCM to create, set by patch_ops.build_pcms callback */
  266. unsigned int num_pcms;
  267. struct hda_pcm *pcm_info;
  268. /* codec specific info */
  269. void *spec;
  270. /* beep device */
  271. struct hda_beep *beep;
  272. unsigned int beep_mode;
  273. /* widget capabilities cache */
  274. unsigned int num_nodes;
  275. hda_nid_t start_nid;
  276. u32 *wcaps;
  277. struct snd_array mixers; /* list of assigned mixer elements */
  278. struct snd_array nids; /* list of mapped mixer elements */
  279. struct hda_cache_rec amp_cache; /* cache for amp access */
  280. struct hda_cache_rec cmd_cache; /* cache for other commands */
  281. struct list_head conn_list; /* linked-list of connection-list */
  282. struct mutex spdif_mutex;
  283. struct mutex control_mutex;
  284. struct mutex hash_mutex;
  285. struct snd_array spdif_out;
  286. unsigned int spdif_in_enable; /* SPDIF input enable? */
  287. const hda_nid_t *slave_dig_outs; /* optional digital out slave widgets */
  288. struct snd_array init_pins; /* initial (BIOS) pin configurations */
  289. struct snd_array driver_pins; /* pin configs set by codec parser */
  290. struct snd_array cvt_setups; /* audio convert setups */
  291. #ifdef CONFIG_SND_HDA_HWDEP
  292. struct mutex user_mutex;
  293. struct snd_hwdep *hwdep; /* assigned hwdep device */
  294. struct snd_array init_verbs; /* additional init verbs */
  295. struct snd_array hints; /* additional hints */
  296. struct snd_array user_pins; /* default pin configs to override */
  297. #endif
  298. /* misc flags */
  299. unsigned int spdif_status_reset :1; /* needs to toggle SPDIF for each
  300. * status change
  301. * (e.g. Realtek codecs)
  302. */
  303. unsigned int pin_amp_workaround:1; /* pin out-amp takes index
  304. * (e.g. Conexant codecs)
  305. */
  306. unsigned int single_adc_amp:1; /* adc in-amp takes no index
  307. * (e.g. CX20549 codec)
  308. */
  309. unsigned int no_sticky_stream:1; /* no sticky-PCM stream assignment */
  310. unsigned int pins_shutup:1; /* pins are shut up */
  311. unsigned int no_trigger_sense:1; /* don't trigger at pin-sensing */
  312. unsigned int no_jack_detect:1; /* Machine has no jack-detection */
  313. unsigned int inv_eapd:1; /* broken h/w: inverted EAPD control */
  314. unsigned int inv_jack_detect:1; /* broken h/w: inverted detection bit */
  315. unsigned int pcm_format_first:1; /* PCM format must be set first */
  316. unsigned int epss:1; /* supporting EPSS? */
  317. unsigned int cached_write:1; /* write only to caches */
  318. unsigned int dp_mst:1; /* support DP1.2 Multi-stream transport */
  319. unsigned int dump_coef:1; /* dump processing coefs in codec proc file */
  320. #ifdef CONFIG_PM
  321. unsigned int power_on :1; /* current (global) power-state */
  322. unsigned int d3_stop_clk:1; /* support D3 operation without BCLK */
  323. unsigned int pm_up_notified:1; /* PM notified to controller */
  324. unsigned int in_pm:1; /* suspend/resume being performed */
  325. int power_transition; /* power-state in transition */
  326. int power_count; /* current (global) power refcount */
  327. struct delayed_work power_work; /* delayed task for powerdown */
  328. unsigned long power_on_acct;
  329. unsigned long power_off_acct;
  330. unsigned long power_jiffies;
  331. spinlock_t power_lock;
  332. #endif
  333. /* filter the requested power state per nid */
  334. unsigned int (*power_filter)(struct hda_codec *codec, hda_nid_t nid,
  335. unsigned int power_state);
  336. /* codec-specific additional proc output */
  337. void (*proc_widget_hook)(struct snd_info_buffer *buffer,
  338. struct hda_codec *codec, hda_nid_t nid);
  339. /* jack detection */
  340. struct snd_array jacktbl;
  341. unsigned long jackpoll_interval; /* In jiffies. Zero means no poll, rely on unsol events */
  342. struct delayed_work jackpoll_work;
  343. #ifdef CONFIG_SND_HDA_INPUT_JACK
  344. /* jack detection */
  345. struct snd_array jacks;
  346. #endif
  347. int depop_delay; /* depop delay in ms, -1 for default delay time */
  348. /* fix-up list */
  349. int fixup_id;
  350. const struct hda_fixup *fixup_list;
  351. const char *fixup_name;
  352. /* additional init verbs */
  353. struct snd_array verbs;
  354. };
  355. /* direction */
  356. enum {
  357. HDA_INPUT, HDA_OUTPUT
  358. };
  359. /* snd_hda_codec_read/write optional flags */
  360. #define HDA_RW_NO_RESPONSE_FALLBACK (1 << 0)
  361. /*
  362. * constructors
  363. */
  364. int snd_hda_bus_new(struct snd_card *card, const struct hda_bus_template *temp,
  365. struct hda_bus **busp);
  366. int snd_hda_codec_new(struct hda_bus *bus, unsigned int codec_addr,
  367. struct hda_codec **codecp);
  368. int snd_hda_codec_configure(struct hda_codec *codec);
  369. int snd_hda_codec_update_widgets(struct hda_codec *codec);
  370. /*
  371. * low level functions
  372. */
  373. unsigned int snd_hda_codec_read(struct hda_codec *codec, hda_nid_t nid,
  374. int flags,
  375. unsigned int verb, unsigned int parm);
  376. int snd_hda_codec_write(struct hda_codec *codec, hda_nid_t nid, int flags,
  377. unsigned int verb, unsigned int parm);
  378. #define snd_hda_param_read(codec, nid, param) \
  379. snd_hda_codec_read(codec, nid, 0, AC_VERB_PARAMETERS, param)
  380. int snd_hda_get_sub_nodes(struct hda_codec *codec, hda_nid_t nid,
  381. hda_nid_t *start_id);
  382. int snd_hda_get_connections(struct hda_codec *codec, hda_nid_t nid,
  383. hda_nid_t *conn_list, int max_conns);
  384. static inline int
  385. snd_hda_get_num_conns(struct hda_codec *codec, hda_nid_t nid)
  386. {
  387. return snd_hda_get_connections(codec, nid, NULL, 0);
  388. }
  389. int snd_hda_get_num_raw_conns(struct hda_codec *codec, hda_nid_t nid);
  390. int snd_hda_get_raw_connections(struct hda_codec *codec, hda_nid_t nid,
  391. hda_nid_t *conn_list, int max_conns);
  392. int snd_hda_get_conn_list(struct hda_codec *codec, hda_nid_t nid,
  393. const hda_nid_t **listp);
  394. int snd_hda_override_conn_list(struct hda_codec *codec, hda_nid_t nid, int nums,
  395. const hda_nid_t *list);
  396. int snd_hda_get_conn_index(struct hda_codec *codec, hda_nid_t mux,
  397. hda_nid_t nid, int recursive);
  398. int snd_hda_get_devices(struct hda_codec *codec, hda_nid_t nid,
  399. u8 *dev_list, int max_devices);
  400. int snd_hda_query_supported_pcm(struct hda_codec *codec, hda_nid_t nid,
  401. u32 *ratesp, u64 *formatsp, unsigned int *bpsp);
  402. struct hda_verb {
  403. hda_nid_t nid;
  404. u32 verb;
  405. u32 param;
  406. };
  407. void snd_hda_sequence_write(struct hda_codec *codec,
  408. const struct hda_verb *seq);
  409. /* unsolicited event */
  410. int snd_hda_queue_unsol_event(struct hda_bus *bus, u32 res, u32 res_ex);
  411. /* cached write */
  412. int snd_hda_codec_write_cache(struct hda_codec *codec, hda_nid_t nid,
  413. int flags, unsigned int verb, unsigned int parm);
  414. void snd_hda_sequence_write_cache(struct hda_codec *codec,
  415. const struct hda_verb *seq);
  416. int snd_hda_codec_update_cache(struct hda_codec *codec, hda_nid_t nid,
  417. int flags, unsigned int verb, unsigned int parm);
  418. void snd_hda_codec_resume_cache(struct hda_codec *codec);
  419. /* both for cmd & amp caches */
  420. void snd_hda_codec_flush_cache(struct hda_codec *codec);
  421. /* the struct for codec->pin_configs */
  422. struct hda_pincfg {
  423. hda_nid_t nid;
  424. unsigned char ctrl; /* original pin control value */
  425. unsigned char target; /* target pin control value */
  426. unsigned int cfg; /* default configuration */
  427. };
  428. unsigned int snd_hda_codec_get_pincfg(struct hda_codec *codec, hda_nid_t nid);
  429. int snd_hda_codec_set_pincfg(struct hda_codec *codec, hda_nid_t nid,
  430. unsigned int cfg);
  431. int snd_hda_add_pincfg(struct hda_codec *codec, struct snd_array *list,
  432. hda_nid_t nid, unsigned int cfg); /* for hwdep */
  433. void snd_hda_shutup_pins(struct hda_codec *codec);
  434. /* SPDIF controls */
  435. struct hda_spdif_out {
  436. hda_nid_t nid; /* Converter nid values relate to */
  437. unsigned int status; /* IEC958 status bits */
  438. unsigned short ctls; /* SPDIF control bits */
  439. };
  440. struct hda_spdif_out *snd_hda_spdif_out_of_nid(struct hda_codec *codec,
  441. hda_nid_t nid);
  442. void snd_hda_spdif_ctls_unassign(struct hda_codec *codec, int idx);
  443. void snd_hda_spdif_ctls_assign(struct hda_codec *codec, int idx, hda_nid_t nid);
  444. /*
  445. * Mixer
  446. */
  447. int snd_hda_build_controls(struct hda_bus *bus);
  448. int snd_hda_codec_build_controls(struct hda_codec *codec);
  449. /*
  450. * PCM
  451. */
  452. int snd_hda_build_pcms(struct hda_bus *bus);
  453. int snd_hda_codec_build_pcms(struct hda_codec *codec);
  454. int snd_hda_codec_prepare(struct hda_codec *codec,
  455. struct hda_pcm_stream *hinfo,
  456. unsigned int stream,
  457. unsigned int format,
  458. struct snd_pcm_substream *substream);
  459. void snd_hda_codec_cleanup(struct hda_codec *codec,
  460. struct hda_pcm_stream *hinfo,
  461. struct snd_pcm_substream *substream);
  462. void snd_hda_codec_setup_stream(struct hda_codec *codec, hda_nid_t nid,
  463. u32 stream_tag,
  464. int channel_id, int format);
  465. void __snd_hda_codec_cleanup_stream(struct hda_codec *codec, hda_nid_t nid,
  466. int do_now);
  467. #define snd_hda_codec_cleanup_stream(codec, nid) \
  468. __snd_hda_codec_cleanup_stream(codec, nid, 0)
  469. unsigned int snd_hda_calc_stream_format(unsigned int rate,
  470. unsigned int channels,
  471. unsigned int format,
  472. unsigned int maxbps,
  473. unsigned short spdif_ctls);
  474. int snd_hda_is_supported_format(struct hda_codec *codec, hda_nid_t nid,
  475. unsigned int format);
  476. extern const struct snd_pcm_chmap_elem snd_pcm_2_1_chmaps[];
  477. /*
  478. * Misc
  479. */
  480. void snd_hda_get_codec_name(struct hda_codec *codec, char *name, int namelen);
  481. void snd_hda_bus_reboot_notify(struct hda_bus *bus);
  482. void snd_hda_codec_set_power_to_all(struct hda_codec *codec, hda_nid_t fg,
  483. unsigned int power_state);
  484. int snd_hda_lock_devices(struct hda_bus *bus);
  485. void snd_hda_unlock_devices(struct hda_bus *bus);
  486. /*
  487. * power management
  488. */
  489. #ifdef CONFIG_PM
  490. int snd_hda_suspend(struct hda_bus *bus);
  491. int snd_hda_resume(struct hda_bus *bus);
  492. #endif
  493. static inline
  494. int hda_call_check_power_status(struct hda_codec *codec, hda_nid_t nid)
  495. {
  496. #ifdef CONFIG_PM
  497. if (codec->patch_ops.check_power_status)
  498. return codec->patch_ops.check_power_status(codec, nid);
  499. #endif
  500. return 0;
  501. }
  502. /*
  503. * get widget information
  504. */
  505. const char *snd_hda_get_jack_connectivity(u32 cfg);
  506. const char *snd_hda_get_jack_type(u32 cfg);
  507. const char *snd_hda_get_jack_location(u32 cfg);
  508. /*
  509. * power saving
  510. */
  511. #ifdef CONFIG_PM
  512. void snd_hda_power_save(struct hda_codec *codec, int delta, bool d3wait);
  513. void snd_hda_update_power_acct(struct hda_codec *codec);
  514. #else
  515. static inline void snd_hda_power_save(struct hda_codec *codec, int delta,
  516. bool d3wait) {}
  517. #endif
  518. /**
  519. * snd_hda_power_up - Power-up the codec
  520. * @codec: HD-audio codec
  521. *
  522. * Increment the power-up counter and power up the hardware really when
  523. * not turned on yet.
  524. */
  525. static inline void snd_hda_power_up(struct hda_codec *codec)
  526. {
  527. snd_hda_power_save(codec, 1, false);
  528. }
  529. /**
  530. * snd_hda_power_up_d3wait - Power-up the codec after waiting for any pending
  531. * D3 transition to complete. This differs from snd_hda_power_up() when
  532. * power_transition == -1. snd_hda_power_up sees this case as a nop,
  533. * snd_hda_power_up_d3wait waits for the D3 transition to complete then powers
  534. * back up.
  535. * @codec: HD-audio codec
  536. *
  537. * Cancel any power down operation hapenning on the work queue, then power up.
  538. */
  539. static inline void snd_hda_power_up_d3wait(struct hda_codec *codec)
  540. {
  541. snd_hda_power_save(codec, 1, true);
  542. }
  543. /**
  544. * snd_hda_power_down - Power-down the codec
  545. * @codec: HD-audio codec
  546. *
  547. * Decrement the power-up counter and schedules the power-off work if
  548. * the counter rearches to zero.
  549. */
  550. static inline void snd_hda_power_down(struct hda_codec *codec)
  551. {
  552. snd_hda_power_save(codec, -1, false);
  553. }
  554. /**
  555. * snd_hda_power_sync - Synchronize the power-save status
  556. * @codec: HD-audio codec
  557. *
  558. * Synchronize the actual power state with the power account;
  559. * called when power_save parameter is changed
  560. */
  561. static inline void snd_hda_power_sync(struct hda_codec *codec)
  562. {
  563. snd_hda_power_save(codec, 0, false);
  564. }
  565. #ifdef CONFIG_SND_HDA_PATCH_LOADER
  566. /*
  567. * patch firmware
  568. */
  569. int snd_hda_load_patch(struct hda_bus *bus, size_t size, const void *buf);
  570. #endif
  571. #ifdef CONFIG_SND_HDA_DSP_LOADER
  572. static inline int
  573. snd_hda_codec_load_dsp_prepare(struct hda_codec *codec, unsigned int format,
  574. unsigned int size,
  575. struct snd_dma_buffer *bufp)
  576. {
  577. return codec->bus->ops.load_dsp_prepare(codec->bus, format, size, bufp);
  578. }
  579. static inline void
  580. snd_hda_codec_load_dsp_trigger(struct hda_codec *codec, bool start)
  581. {
  582. return codec->bus->ops.load_dsp_trigger(codec->bus, start);
  583. }
  584. static inline void
  585. snd_hda_codec_load_dsp_cleanup(struct hda_codec *codec,
  586. struct snd_dma_buffer *dmab)
  587. {
  588. return codec->bus->ops.load_dsp_cleanup(codec->bus, dmab);
  589. }
  590. #else
  591. static inline int
  592. snd_hda_codec_load_dsp_prepare(struct hda_codec *codec, unsigned int format,
  593. unsigned int size,
  594. struct snd_dma_buffer *bufp)
  595. {
  596. return -ENOSYS;
  597. }
  598. static inline void
  599. snd_hda_codec_load_dsp_trigger(struct hda_codec *codec, bool start) {}
  600. static inline void
  601. snd_hda_codec_load_dsp_cleanup(struct hda_codec *codec,
  602. struct snd_dma_buffer *dmab) {}
  603. #endif
  604. #define EXPORT_SYMBOL_HDA(sym) EXPORT_SYMBOL_GPL(sym)
  605. #endif /* __SOUND_HDA_CODEC_H */