0001
0002
0003
0004
0005
0006
0007
0008 #ifndef __SOUND_HDA_CODEC_H
0009 #define __SOUND_HDA_CODEC_H
0010
0011 #include <linux/refcount.h>
0012 #include <linux/mod_devicetable.h>
0013 #include <sound/info.h>
0014 #include <sound/control.h>
0015 #include <sound/pcm.h>
0016 #include <sound/hwdep.h>
0017 #include <sound/hdaudio.h>
0018 #include <sound/hda_verbs.h>
0019 #include <sound/hda_regmap.h>
0020
0021 #define IS_BXT(pci) ((pci)->vendor == 0x8086 && (pci)->device == 0x5a98)
0022 #define IS_CFL(pci) ((pci)->vendor == 0x8086 && (pci)->device == 0xa348)
0023
0024
0025
0026
0027
0028 struct hda_bus;
0029 struct hda_beep;
0030 struct hda_codec;
0031 struct hda_pcm;
0032 struct hda_pcm_stream;
0033
0034
0035
0036
0037
0038
0039
0040 struct hda_bus {
0041 struct hdac_bus core;
0042
0043 struct snd_card *card;
0044
0045 struct pci_dev *pci;
0046 const char *modelname;
0047
0048 struct mutex prepare_mutex;
0049
0050
0051 DECLARE_BITMAP(pcm_dev_bits, SNDRV_PCM_DEVICES);
0052
0053
0054 unsigned int allow_bus_reset:1;
0055
0056 unsigned int shutdown :1;
0057 unsigned int response_reset:1;
0058 unsigned int in_reset:1;
0059 unsigned int no_response_fallback:1;
0060 unsigned int bus_probing :1;
0061 unsigned int keep_power:1;
0062 unsigned int jackpoll_in_suspend:1;
0063
0064
0065
0066 int primary_dig_out_type;
0067 unsigned int mixer_assigned;
0068 };
0069
0070
0071 #define to_hda_bus(bus) container_of(bus, struct hda_bus, core)
0072
0073
0074
0075
0076
0077
0078
0079 typedef int (*hda_codec_patch_t)(struct hda_codec *);
0080
0081 #define HDA_CODEC_ID_SKIP_PROBE 0x00000001
0082 #define HDA_CODEC_ID_GENERIC_HDMI 0x00000101
0083 #define HDA_CODEC_ID_GENERIC 0x00000201
0084
0085 #define HDA_CODEC_REV_ENTRY(_vid, _rev, _name, _patch) \
0086 { .vendor_id = (_vid), .rev_id = (_rev), .name = (_name), \
0087 .api_version = HDA_DEV_LEGACY, \
0088 .driver_data = (unsigned long)(_patch) }
0089 #define HDA_CODEC_ENTRY(_vid, _name, _patch) \
0090 HDA_CODEC_REV_ENTRY(_vid, 0, _name, _patch)
0091
0092 struct hda_codec_driver {
0093 struct hdac_driver core;
0094 const struct hda_device_id *id;
0095 };
0096
0097 int __hda_codec_driver_register(struct hda_codec_driver *drv, const char *name,
0098 struct module *owner);
0099 #define hda_codec_driver_register(drv) \
0100 __hda_codec_driver_register(drv, KBUILD_MODNAME, THIS_MODULE)
0101 void hda_codec_driver_unregister(struct hda_codec_driver *drv);
0102 #define module_hda_codec_driver(drv) \
0103 module_driver(drv, hda_codec_driver_register, \
0104 hda_codec_driver_unregister)
0105
0106
0107 struct hda_codec_ops {
0108 int (*build_controls)(struct hda_codec *codec);
0109 int (*build_pcms)(struct hda_codec *codec);
0110 int (*init)(struct hda_codec *codec);
0111 void (*free)(struct hda_codec *codec);
0112 void (*unsol_event)(struct hda_codec *codec, unsigned int res);
0113 void (*set_power_state)(struct hda_codec *codec, hda_nid_t fg,
0114 unsigned int power_state);
0115 #ifdef CONFIG_PM
0116 int (*suspend)(struct hda_codec *codec);
0117 int (*resume)(struct hda_codec *codec);
0118 int (*check_power_status)(struct hda_codec *codec, hda_nid_t nid);
0119 #endif
0120 void (*stream_pm)(struct hda_codec *codec, hda_nid_t nid, bool on);
0121 };
0122
0123
0124 struct hda_pcm_ops {
0125 int (*open)(struct hda_pcm_stream *info, struct hda_codec *codec,
0126 struct snd_pcm_substream *substream);
0127 int (*close)(struct hda_pcm_stream *info, struct hda_codec *codec,
0128 struct snd_pcm_substream *substream);
0129 int (*prepare)(struct hda_pcm_stream *info, struct hda_codec *codec,
0130 unsigned int stream_tag, unsigned int format,
0131 struct snd_pcm_substream *substream);
0132 int (*cleanup)(struct hda_pcm_stream *info, struct hda_codec *codec,
0133 struct snd_pcm_substream *substream);
0134 unsigned int (*get_delay)(struct hda_pcm_stream *info,
0135 struct hda_codec *codec,
0136 struct snd_pcm_substream *substream);
0137 };
0138
0139
0140 struct hda_pcm_stream {
0141 unsigned int substreams;
0142 unsigned int channels_min;
0143 unsigned int channels_max;
0144 hda_nid_t nid;
0145 u32 rates;
0146 u64 formats;
0147 unsigned int maxbps;
0148 const struct snd_pcm_chmap_elem *chmap;
0149 struct hda_pcm_ops ops;
0150 };
0151
0152
0153 enum {
0154 HDA_PCM_TYPE_AUDIO,
0155 HDA_PCM_TYPE_SPDIF,
0156 HDA_PCM_TYPE_HDMI,
0157 HDA_PCM_TYPE_MODEM,
0158 HDA_PCM_NTYPES
0159 };
0160
0161 #define SNDRV_PCM_INVALID_DEVICE (-1)
0162
0163 struct hda_pcm {
0164 char *name;
0165 struct hda_pcm_stream stream[2];
0166 unsigned int pcm_type;
0167 int device;
0168 struct snd_pcm *pcm;
0169 bool own_chmap;
0170
0171 struct hda_codec *codec;
0172 struct list_head list;
0173 unsigned int disconnected:1;
0174 };
0175
0176
0177 struct hda_codec {
0178 struct hdac_device core;
0179 struct hda_bus *bus;
0180 struct snd_card *card;
0181 unsigned int addr;
0182 u32 probe_id;
0183
0184
0185 const struct hda_device_id *preset;
0186 const char *modelname;
0187
0188
0189 struct hda_codec_ops patch_ops;
0190
0191
0192 struct list_head pcm_list_head;
0193 refcount_t pcm_ref;
0194 wait_queue_head_t remove_sleep;
0195
0196
0197 void *spec;
0198
0199
0200 struct hda_beep *beep;
0201 unsigned int beep_mode;
0202
0203
0204 u32 *wcaps;
0205
0206 struct snd_array mixers;
0207 struct snd_array nids;
0208
0209 struct list_head conn_list;
0210
0211 struct mutex spdif_mutex;
0212 struct mutex control_mutex;
0213 struct snd_array spdif_out;
0214 unsigned int spdif_in_enable;
0215 const hda_nid_t *follower_dig_outs;
0216 struct snd_array init_pins;
0217 struct snd_array driver_pins;
0218 struct snd_array cvt_setups;
0219
0220 struct mutex user_mutex;
0221 #ifdef CONFIG_SND_HDA_RECONFIG
0222 struct snd_array init_verbs;
0223 struct snd_array hints;
0224 struct snd_array user_pins;
0225 #endif
0226
0227 #ifdef CONFIG_SND_HDA_HWDEP
0228 struct snd_hwdep *hwdep;
0229 #endif
0230
0231
0232 unsigned int configured:1;
0233 unsigned int in_freeing:1;
0234 unsigned int display_power_control:1;
0235 unsigned int spdif_status_reset :1;
0236
0237
0238
0239 unsigned int pin_amp_workaround:1;
0240
0241
0242 unsigned int single_adc_amp:1;
0243
0244
0245 unsigned int no_sticky_stream:1;
0246 unsigned int pins_shutup:1;
0247 unsigned int no_trigger_sense:1;
0248 unsigned int no_jack_detect:1;
0249 unsigned int inv_eapd:1;
0250 unsigned int inv_jack_detect:1;
0251 unsigned int pcm_format_first:1;
0252 unsigned int cached_write:1;
0253 unsigned int dp_mst:1;
0254 unsigned int dump_coef:1;
0255 unsigned int power_save_node:1;
0256 unsigned int auto_runtime_pm:1;
0257 unsigned int force_pin_prefix:1;
0258 unsigned int link_down_at_suspend:1;
0259 unsigned int relaxed_resume:1;
0260 unsigned int forced_resume:1;
0261 unsigned int mst_no_extra_pcms:1;
0262
0263 #ifdef CONFIG_PM
0264 unsigned long power_on_acct;
0265 unsigned long power_off_acct;
0266 unsigned long power_jiffies;
0267 #endif
0268
0269
0270 unsigned int (*power_filter)(struct hda_codec *codec, hda_nid_t nid,
0271 unsigned int power_state);
0272
0273
0274 void (*proc_widget_hook)(struct snd_info_buffer *buffer,
0275 struct hda_codec *codec, hda_nid_t nid);
0276
0277
0278 struct snd_array jacktbl;
0279 unsigned long jackpoll_interval;
0280 struct delayed_work jackpoll_work;
0281
0282 int depop_delay;
0283
0284
0285 int fixup_id;
0286 const struct hda_fixup *fixup_list;
0287 const char *fixup_name;
0288
0289
0290 struct snd_array verbs;
0291 };
0292
0293 #define dev_to_hda_codec(_dev) container_of(_dev, struct hda_codec, core.dev)
0294 #define hda_codec_dev(_dev) (&(_dev)->core.dev)
0295
0296 #define hdac_to_hda_priv(_hdac) \
0297 container_of(_hdac, struct hdac_hda_priv, codec.core)
0298 #define hdac_to_hda_codec(_hdac) container_of(_hdac, struct hda_codec, core)
0299
0300 #define list_for_each_codec(c, bus) \
0301 list_for_each_entry(c, &(bus)->core.codec_list, core.list)
0302 #define list_for_each_codec_safe(c, n, bus) \
0303 list_for_each_entry_safe(c, n, &(bus)->core.codec_list, core.list)
0304
0305
0306 #define HDA_RW_NO_RESPONSE_FALLBACK (1 << 0)
0307
0308
0309
0310
0311 __printf(3, 4) struct hda_codec *
0312 snd_hda_codec_device_init(struct hda_bus *bus, unsigned int codec_addr,
0313 const char *fmt, ...);
0314 int snd_hda_codec_new(struct hda_bus *bus, struct snd_card *card,
0315 unsigned int codec_addr, struct hda_codec **codecp);
0316 int snd_hda_codec_device_new(struct hda_bus *bus, struct snd_card *card,
0317 unsigned int codec_addr, struct hda_codec *codec,
0318 bool snddev_managed);
0319 int snd_hda_codec_configure(struct hda_codec *codec);
0320 int snd_hda_codec_update_widgets(struct hda_codec *codec);
0321 void snd_hda_codec_register(struct hda_codec *codec);
0322 void snd_hda_codec_unregister(struct hda_codec *codec);
0323 void snd_hda_codec_cleanup_for_unbind(struct hda_codec *codec);
0324
0325
0326
0327
0328 static inline unsigned int
0329 snd_hda_codec_read(struct hda_codec *codec, hda_nid_t nid,
0330 int flags,
0331 unsigned int verb, unsigned int parm)
0332 {
0333 return snd_hdac_codec_read(&codec->core, nid, flags, verb, parm);
0334 }
0335
0336 static inline int
0337 snd_hda_codec_write(struct hda_codec *codec, hda_nid_t nid, int flags,
0338 unsigned int verb, unsigned int parm)
0339 {
0340 return snd_hdac_codec_write(&codec->core, nid, flags, verb, parm);
0341 }
0342
0343 #define snd_hda_param_read(codec, nid, param) \
0344 snd_hdac_read_parm(&(codec)->core, nid, param)
0345 #define snd_hda_get_sub_nodes(codec, nid, start_nid) \
0346 snd_hdac_get_sub_nodes(&(codec)->core, nid, start_nid)
0347 int snd_hda_get_connections(struct hda_codec *codec, hda_nid_t nid,
0348 hda_nid_t *conn_list, int max_conns);
0349 static inline int
0350 snd_hda_get_num_conns(struct hda_codec *codec, hda_nid_t nid)
0351 {
0352 return snd_hda_get_connections(codec, nid, NULL, 0);
0353 }
0354
0355 #define snd_hda_get_raw_connections(codec, nid, list, max_conns) \
0356 snd_hdac_get_connections(&(codec)->core, nid, list, max_conns)
0357 #define snd_hda_get_num_raw_conns(codec, nid) \
0358 snd_hdac_get_connections(&(codec)->core, nid, NULL, 0)
0359
0360 int snd_hda_get_conn_list(struct hda_codec *codec, hda_nid_t nid,
0361 const hda_nid_t **listp);
0362 int snd_hda_override_conn_list(struct hda_codec *codec, hda_nid_t nid, int nums,
0363 const hda_nid_t *list);
0364 int snd_hda_get_conn_index(struct hda_codec *codec, hda_nid_t mux,
0365 hda_nid_t nid, int recursive);
0366 unsigned int snd_hda_get_num_devices(struct hda_codec *codec, hda_nid_t nid);
0367 int snd_hda_get_devices(struct hda_codec *codec, hda_nid_t nid,
0368 u8 *dev_list, int max_devices);
0369 int snd_hda_get_dev_select(struct hda_codec *codec, hda_nid_t nid);
0370 int snd_hda_set_dev_select(struct hda_codec *codec, hda_nid_t nid, int dev_id);
0371
0372 struct hda_verb {
0373 hda_nid_t nid;
0374 u32 verb;
0375 u32 param;
0376 };
0377
0378 void snd_hda_sequence_write(struct hda_codec *codec,
0379 const struct hda_verb *seq);
0380
0381
0382 static inline int
0383 snd_hda_codec_write_cache(struct hda_codec *codec, hda_nid_t nid,
0384 int flags, unsigned int verb, unsigned int parm)
0385 {
0386 return snd_hdac_regmap_write(&codec->core, nid, verb, parm);
0387 }
0388
0389
0390 struct hda_pincfg {
0391 hda_nid_t nid;
0392 unsigned char ctrl;
0393 unsigned char target;
0394 unsigned int cfg;
0395 };
0396
0397 unsigned int snd_hda_codec_get_pincfg(struct hda_codec *codec, hda_nid_t nid);
0398 int snd_hda_codec_set_pincfg(struct hda_codec *codec, hda_nid_t nid,
0399 unsigned int cfg);
0400 int snd_hda_add_pincfg(struct hda_codec *codec, struct snd_array *list,
0401 hda_nid_t nid, unsigned int cfg);
0402 void snd_hda_shutup_pins(struct hda_codec *codec);
0403
0404
0405 struct hda_spdif_out {
0406 hda_nid_t nid;
0407 unsigned int status;
0408 unsigned short ctls;
0409 };
0410 struct hda_spdif_out *snd_hda_spdif_out_of_nid(struct hda_codec *codec,
0411 hda_nid_t nid);
0412 void snd_hda_spdif_ctls_unassign(struct hda_codec *codec, int idx);
0413 void snd_hda_spdif_ctls_assign(struct hda_codec *codec, int idx, hda_nid_t nid);
0414
0415
0416
0417
0418 int snd_hda_codec_build_controls(struct hda_codec *codec);
0419
0420
0421
0422
0423 int snd_hda_codec_parse_pcms(struct hda_codec *codec);
0424 int snd_hda_codec_build_pcms(struct hda_codec *codec);
0425
0426 __printf(2, 3)
0427 struct hda_pcm *snd_hda_codec_pcm_new(struct hda_codec *codec,
0428 const char *fmt, ...);
0429
0430 void snd_hda_codec_cleanup_for_unbind(struct hda_codec *codec);
0431
0432 static inline void snd_hda_codec_pcm_get(struct hda_pcm *pcm)
0433 {
0434 refcount_inc(&pcm->codec->pcm_ref);
0435 }
0436 void snd_hda_codec_pcm_put(struct hda_pcm *pcm);
0437
0438 int snd_hda_codec_prepare(struct hda_codec *codec,
0439 struct hda_pcm_stream *hinfo,
0440 unsigned int stream,
0441 unsigned int format,
0442 struct snd_pcm_substream *substream);
0443 void snd_hda_codec_cleanup(struct hda_codec *codec,
0444 struct hda_pcm_stream *hinfo,
0445 struct snd_pcm_substream *substream);
0446
0447 void snd_hda_codec_setup_stream(struct hda_codec *codec, hda_nid_t nid,
0448 u32 stream_tag,
0449 int channel_id, int format);
0450 void __snd_hda_codec_cleanup_stream(struct hda_codec *codec, hda_nid_t nid,
0451 int do_now);
0452 #define snd_hda_codec_cleanup_stream(codec, nid) \
0453 __snd_hda_codec_cleanup_stream(codec, nid, 0)
0454
0455 #define snd_hda_query_supported_pcm(codec, nid, ratesp, fmtsp, bpsp) \
0456 snd_hdac_query_supported_pcm(&(codec)->core, nid, ratesp, fmtsp, bpsp)
0457 #define snd_hda_is_supported_format(codec, nid, fmt) \
0458 snd_hdac_is_supported_format(&(codec)->core, nid, fmt)
0459
0460 extern const struct snd_pcm_chmap_elem snd_pcm_2_1_chmaps[];
0461
0462 int snd_hda_attach_pcm_stream(struct hda_bus *_bus, struct hda_codec *codec,
0463 struct hda_pcm *cpcm);
0464
0465
0466
0467
0468 void snd_hda_get_codec_name(struct hda_codec *codec, char *name, int namelen);
0469 void snd_hda_codec_set_power_to_all(struct hda_codec *codec, hda_nid_t fg,
0470 unsigned int power_state);
0471
0472 int snd_hda_lock_devices(struct hda_bus *bus);
0473 void snd_hda_unlock_devices(struct hda_bus *bus);
0474 void snd_hda_bus_reset(struct hda_bus *bus);
0475 void snd_hda_bus_reset_codecs(struct hda_bus *bus);
0476
0477 int snd_hda_codec_set_name(struct hda_codec *codec, const char *name);
0478
0479
0480
0481
0482 extern const struct dev_pm_ops hda_codec_driver_pm;
0483
0484 static inline
0485 int hda_call_check_power_status(struct hda_codec *codec, hda_nid_t nid)
0486 {
0487 #ifdef CONFIG_PM
0488 if (codec->patch_ops.check_power_status)
0489 return codec->patch_ops.check_power_status(codec, nid);
0490 #endif
0491 return 0;
0492 }
0493
0494
0495
0496
0497 #define snd_hda_power_up(codec) snd_hdac_power_up(&(codec)->core)
0498 #define snd_hda_power_up_pm(codec) snd_hdac_power_up_pm(&(codec)->core)
0499 #define snd_hda_power_down(codec) snd_hdac_power_down(&(codec)->core)
0500 #define snd_hda_power_down_pm(codec) snd_hdac_power_down_pm(&(codec)->core)
0501 #ifdef CONFIG_PM
0502 void snd_hda_codec_set_power_save(struct hda_codec *codec, int delay);
0503 void snd_hda_set_power_save(struct hda_bus *bus, int delay);
0504 void snd_hda_update_power_acct(struct hda_codec *codec);
0505 #else
0506 static inline void snd_hda_codec_set_power_save(struct hda_codec *codec, int delay) {}
0507 static inline void snd_hda_set_power_save(struct hda_bus *bus, int delay) {}
0508 #endif
0509
0510 static inline bool hda_codec_need_resume(struct hda_codec *codec)
0511 {
0512 return !codec->relaxed_resume && codec->jacktbl.used;
0513 }
0514
0515 #ifdef CONFIG_SND_HDA_PATCH_LOADER
0516
0517
0518
0519 int snd_hda_load_patch(struct hda_bus *bus, size_t size, const void *buf);
0520 #endif
0521
0522 #ifdef CONFIG_SND_HDA_DSP_LOADER
0523 int snd_hda_codec_load_dsp_prepare(struct hda_codec *codec, unsigned int format,
0524 unsigned int size,
0525 struct snd_dma_buffer *bufp);
0526 void snd_hda_codec_load_dsp_trigger(struct hda_codec *codec, bool start);
0527 void snd_hda_codec_load_dsp_cleanup(struct hda_codec *codec,
0528 struct snd_dma_buffer *dmab);
0529 #else
0530 static inline int
0531 snd_hda_codec_load_dsp_prepare(struct hda_codec *codec, unsigned int format,
0532 unsigned int size,
0533 struct snd_dma_buffer *bufp)
0534 {
0535 return -ENOSYS;
0536 }
0537 static inline void
0538 snd_hda_codec_load_dsp_trigger(struct hda_codec *codec, bool start) {}
0539 static inline void
0540 snd_hda_codec_load_dsp_cleanup(struct hda_codec *codec,
0541 struct snd_dma_buffer *dmab) {}
0542 #endif
0543
0544 #endif