// SPDX-License-Identifier: GPL-2.0-or-later /* * Universal Interface for Intel High Definition Audio Codec * * Copyright (c) 2004 Takashi Iwai <[email protected]> */ #include <linux/init.h> #include <linux/delay.h> #include <linux/slab.h> #include <linux/mutex.h> #include <linux/module.h> #include <linux/pm.h> #include <linux/pm_runtime.h> #include <sound/core.h> #include <sound/hda_codec.h> #include <sound/asoundef.h> #include <sound/tlv.h> #include <sound/initval.h> #include <sound/jack.h> #include "hda_local.h" #include "hda_beep.h" #include "hda_jack.h" #include <sound/hda_hwdep.h> #include <sound/hda_component.h> #define codec_in_pm(codec) … #define hda_codec_is_power_on(codec) … #define codec_has_epss(codec) … #define codec_has_clkstop(codec) … /* * Send and receive a verb - passed to exec_verb override for hdac_device */ static int codec_exec_verb(struct hdac_device *dev, unsigned int cmd, unsigned int flags, unsigned int *res) { … } /** * snd_hda_sequence_write - sequence writes * @codec: the HDA codec * @seq: VERB array to send * * Send the commands sequentially from the given array. * The array must be terminated with NID=0. */ void snd_hda_sequence_write(struct hda_codec *codec, const struct hda_verb *seq) { … } EXPORT_SYMBOL_GPL(…); /* connection list element */ struct hda_conn_list { … }; /* look up the cached results */ static struct hda_conn_list * lookup_conn_list(struct hda_codec *codec, hda_nid_t nid) { … } static int add_conn_list(struct hda_codec *codec, hda_nid_t nid, int len, const hda_nid_t *list) { … } static void remove_conn_list(struct hda_codec *codec) { … } /* read the connection and add to the cache */ static int read_and_add_raw_conns(struct hda_codec *codec, hda_nid_t nid) { … } /** * snd_hda_get_conn_list - get connection list * @codec: the HDA codec * @nid: NID to parse * @listp: the pointer to store NID list * * Parses the connection list of the given widget and stores the pointer * to the list of NIDs. * * Returns the number of connections, or a negative error code. * * Note that the returned pointer isn't protected against the list * modification. If snd_hda_override_conn_list() might be called * concurrently, protect with a mutex appropriately. */ int snd_hda_get_conn_list(struct hda_codec *codec, hda_nid_t nid, const hda_nid_t **listp) { … } EXPORT_SYMBOL_GPL(…); /** * snd_hda_get_connections - copy connection list * @codec: the HDA codec * @nid: NID to parse * @conn_list: connection list array; when NULL, checks only the size * @max_conns: max. number of connections to store * * Parses the connection list of the given widget and stores the list * of NIDs. * * Returns the number of connections, or a negative error code. */ int snd_hda_get_connections(struct hda_codec *codec, hda_nid_t nid, hda_nid_t *conn_list, int max_conns) { … } EXPORT_SYMBOL_GPL(…); /** * snd_hda_override_conn_list - add/modify the connection-list to cache * @codec: the HDA codec * @nid: NID to parse * @len: number of connection list entries * @list: the list of connection entries * * Add or modify the given connection-list to the cache. If the corresponding * cache already exists, invalidate it and append a new one. * * Returns zero or a negative error code. */ int snd_hda_override_conn_list(struct hda_codec *codec, hda_nid_t nid, int len, const hda_nid_t *list) { … } EXPORT_SYMBOL_GPL(…); /** * snd_hda_get_conn_index - get the connection index of the given NID * @codec: the HDA codec * @mux: NID containing the list * @nid: NID to select * @recursive: 1 when searching NID recursively, otherwise 0 * * Parses the connection list of the widget @mux and checks whether the * widget @nid is present. If it is, return the connection index. * Otherwise it returns -1. */ int snd_hda_get_conn_index(struct hda_codec *codec, hda_nid_t mux, hda_nid_t nid, int recursive) { … } EXPORT_SYMBOL_GPL(…); /** * snd_hda_get_num_devices - get DEVLIST_LEN parameter of the given widget * @codec: the HDA codec * @nid: NID of the pin to parse * * Get the device entry number on the given widget. This is a feature of * DP MST audio. Each pin can have several device entries in it. */ unsigned int snd_hda_get_num_devices(struct hda_codec *codec, hda_nid_t nid) { … } EXPORT_SYMBOL_GPL(…); /** * snd_hda_get_devices - copy device list without cache * @codec: the HDA codec * @nid: NID of the pin to parse * @dev_list: device list array * @max_devices: max. number of devices to store * * Copy the device list. This info is dynamic and so not cached. * Currently called only from hda_proc.c, so not exported. */ int snd_hda_get_devices(struct hda_codec *codec, hda_nid_t nid, u8 *dev_list, int max_devices) { … } /** * snd_hda_get_dev_select - get device entry select on the pin * @codec: the HDA codec * @nid: NID of the pin to get device entry select * * Get the devcie entry select on the pin. Return the device entry * id selected on the pin. Return 0 means the first device entry * is selected or MST is not supported. */ int snd_hda_get_dev_select(struct hda_codec *codec, hda_nid_t nid) { … } EXPORT_SYMBOL_GPL(…); /** * snd_hda_set_dev_select - set device entry select on the pin * @codec: the HDA codec * @nid: NID of the pin to set device entry select * @dev_id: device entry id to be set * * Set the device entry select on the pin nid. */ int snd_hda_set_dev_select(struct hda_codec *codec, hda_nid_t nid, int dev_id) { … } EXPORT_SYMBOL_GPL(…); /* * read widget caps for each widget and store in cache */ static int read_widget_caps(struct hda_codec *codec, hda_nid_t fg_node) { … } /* read all pin default configurations and save codec->init_pins */ static int read_pin_defaults(struct hda_codec *codec) { … } /* look up the given pin config list and return the item matching with NID */ static struct hda_pincfg *look_up_pincfg(struct hda_codec *codec, struct snd_array *array, hda_nid_t nid) { … } /* set the current pin config value for the given NID. * the value is cached, and read via snd_hda_codec_get_pincfg() */ int snd_hda_add_pincfg(struct hda_codec *codec, struct snd_array *list, hda_nid_t nid, unsigned int cfg) { … } /** * snd_hda_codec_set_pincfg - Override a pin default configuration * @codec: the HDA codec * @nid: NID to set the pin config * @cfg: the pin default config value * * Override a pin default configuration value in the cache. * This value can be read by snd_hda_codec_get_pincfg() in a higher * priority than the real hardware value. */ int snd_hda_codec_set_pincfg(struct hda_codec *codec, hda_nid_t nid, unsigned int cfg) { … } EXPORT_SYMBOL_GPL(…); /** * snd_hda_codec_get_pincfg - Obtain a pin-default configuration * @codec: the HDA codec * @nid: NID to get the pin config * * Get the current pin config value of the given pin NID. * If the pincfg value is cached or overridden via sysfs or driver, * returns the cached value. */ unsigned int snd_hda_codec_get_pincfg(struct hda_codec *codec, hda_nid_t nid) { … } EXPORT_SYMBOL_GPL(…); /** * snd_hda_codec_set_pin_target - remember the current pinctl target value * @codec: the HDA codec * @nid: pin NID * @val: assigned pinctl value * * This function stores the given value to a pinctl target value in the * pincfg table. This isn't always as same as the actually written value * but can be referred at any time via snd_hda_codec_get_pin_target(). */ int snd_hda_codec_set_pin_target(struct hda_codec *codec, hda_nid_t nid, unsigned int val) { … } EXPORT_SYMBOL_GPL(…); /** * snd_hda_codec_get_pin_target - return the current pinctl target value * @codec: the HDA codec * @nid: pin NID */ int snd_hda_codec_get_pin_target(struct hda_codec *codec, hda_nid_t nid) { … } EXPORT_SYMBOL_GPL(…); /** * snd_hda_shutup_pins - Shut up all pins * @codec: the HDA codec * * Clear all pin controls to shup up before suspend for avoiding click noise. * The controls aren't cached so that they can be resumed properly. */ void snd_hda_shutup_pins(struct hda_codec *codec) { … } EXPORT_SYMBOL_GPL(…); /* Restore the pin controls cleared previously via snd_hda_shutup_pins() */ static void restore_shutup_pins(struct hda_codec *codec) { … } static void hda_jackpoll_work(struct work_struct *work) { … } /* release all pincfg lists */ static void free_init_pincfgs(struct hda_codec *codec) { … } /* * audio-converter setup caches */ struct hda_cvt_setup { … }; /* get or create a cache entry for the given audio converter NID */ static struct hda_cvt_setup * get_hda_cvt_setup(struct hda_codec *codec, hda_nid_t nid) { … } /* * PCM device */ void snd_hda_codec_pcm_put(struct hda_pcm *pcm) { … } EXPORT_SYMBOL_GPL(…); struct hda_pcm *snd_hda_codec_pcm_new(struct hda_codec *codec, const char *fmt, ...) { … } EXPORT_SYMBOL_GPL(…); /* * codec destructor */ void snd_hda_codec_disconnect_pcms(struct hda_codec *codec) { … } static void codec_release_pcms(struct hda_codec *codec) { … } /** * snd_hda_codec_cleanup_for_unbind - Prepare codec for removal * @codec: codec device to cleanup */ void snd_hda_codec_cleanup_for_unbind(struct hda_codec *codec) { … } EXPORT_SYMBOL_GPL(…); static unsigned int hda_set_power_state(struct hda_codec *codec, unsigned int power_state); /* enable/disable display power per codec */ void snd_hda_codec_display_power(struct hda_codec *codec, bool enable) { … } /** * snd_hda_codec_register - Finalize codec initialization * @codec: codec device to register * * Also called from hda_bind.c */ void snd_hda_codec_register(struct hda_codec *codec) { … } EXPORT_SYMBOL_GPL(…); static int snd_hda_codec_dev_register(struct snd_device *device) { … } /** * snd_hda_codec_unregister - Unregister specified codec device * @codec: codec device to unregister */ void snd_hda_codec_unregister(struct hda_codec *codec) { … } EXPORT_SYMBOL_GPL(…); static int snd_hda_codec_dev_free(struct snd_device *device) { … } static void snd_hda_codec_dev_release(struct device *dev) { … } #define DEV_NAME_LEN … /** * snd_hda_codec_device_init - allocate HDA codec device * @bus: codec's parent bus * @codec_addr: the codec address on the parent bus * @fmt: format string for the device's name * * Returns newly allocated codec device or ERR_PTR() on failure. */ struct hda_codec * snd_hda_codec_device_init(struct hda_bus *bus, unsigned int codec_addr, const char *fmt, ...) { … } EXPORT_SYMBOL_GPL(…); /** * snd_hda_codec_new - create a HDA codec * @bus: the bus to assign * @card: card for this codec * @codec_addr: the codec address * @codecp: the pointer to store the generated codec * * Returns 0 if successful, or a negative error code. */ int snd_hda_codec_new(struct hda_bus *bus, struct snd_card *card, unsigned int codec_addr, struct hda_codec **codecp) { … } EXPORT_SYMBOL_GPL(…); int snd_hda_codec_device_new(struct hda_bus *bus, struct snd_card *card, unsigned int codec_addr, struct hda_codec *codec, bool snddev_managed) { … } EXPORT_SYMBOL_GPL(…); /** * snd_hda_codec_update_widgets - Refresh widget caps and pin defaults * @codec: the HDA codec * * Forcibly refresh the all widget caps and the init pin configurations of * the given codec. */ int snd_hda_codec_update_widgets(struct hda_codec *codec) { … } EXPORT_SYMBOL_GPL(…); /* update the stream-id if changed */ static void update_pcm_stream_id(struct hda_codec *codec, struct hda_cvt_setup *p, hda_nid_t nid, u32 stream_tag, int channel_id) { … } /* update the format-id if changed */ static void update_pcm_format(struct hda_codec *codec, struct hda_cvt_setup *p, hda_nid_t nid, int format) { … } /** * snd_hda_codec_setup_stream - set up the codec for streaming * @codec: the CODEC to set up * @nid: the NID to set up * @stream_tag: stream tag to pass, it's between 0x1 and 0xf. * @channel_id: channel id to pass, zero based. * @format: stream format. */ void snd_hda_codec_setup_stream(struct hda_codec *codec, hda_nid_t nid, u32 stream_tag, int channel_id, int format) { … } EXPORT_SYMBOL_GPL(…); static void really_cleanup_stream(struct hda_codec *codec, struct hda_cvt_setup *q); /** * __snd_hda_codec_cleanup_stream - clean up the codec for closing * @codec: the CODEC to clean up * @nid: the NID to clean up * @do_now: really clean up the stream instead of clearing the active flag */ void __snd_hda_codec_cleanup_stream(struct hda_codec *codec, hda_nid_t nid, int do_now) { … } EXPORT_SYMBOL_GPL(…); static void really_cleanup_stream(struct hda_codec *codec, struct hda_cvt_setup *q) { … } /* clean up the all conflicting obsolete streams */ static void purify_inactive_streams(struct hda_codec *codec) { … } /* clean up all streams; called from suspend */ static void hda_cleanup_all_streams(struct hda_codec *codec) { … } /* * amp access functions */ /** * query_amp_caps - query AMP capabilities * @codec: the HD-auio codec * @nid: the NID to query * @direction: either #HDA_INPUT or #HDA_OUTPUT * * Query AMP capabilities for the given widget and direction. * Returns the obtained capability bits. * * When cap bits have been already read, this doesn't read again but * returns the cached value. */ u32 query_amp_caps(struct hda_codec *codec, hda_nid_t nid, int direction) { … } EXPORT_SYMBOL_GPL(…); /** * snd_hda_check_amp_caps - query AMP capabilities * @codec: the HD-audio codec * @nid: the NID to query * @dir: either #HDA_INPUT or #HDA_OUTPUT * @bits: bit mask to check the result * * Check whether the widget has the given amp capability for the direction. */ bool snd_hda_check_amp_caps(struct hda_codec *codec, hda_nid_t nid, int dir, unsigned int bits) { … } EXPORT_SYMBOL_GPL(…); /** * snd_hda_override_amp_caps - Override the AMP capabilities * @codec: the CODEC to clean up * @nid: the NID to clean up * @dir: either #HDA_INPUT or #HDA_OUTPUT * @caps: the capability bits to set * * Override the cached AMP caps bits value by the given one. * This function is useful if the driver needs to adjust the AMP ranges, * e.g. limit to 0dB, etc. * * Returns zero if successful or a negative error code. */ int snd_hda_override_amp_caps(struct hda_codec *codec, hda_nid_t nid, int dir, unsigned int caps) { … } EXPORT_SYMBOL_GPL(…); static unsigned int encode_amp(struct hda_codec *codec, hda_nid_t nid, int ch, int dir, int idx) { … } /** * snd_hda_codec_amp_update - update the AMP mono value * @codec: HD-audio codec * @nid: NID to read the AMP value * @ch: channel to update (0 or 1) * @dir: #HDA_INPUT or #HDA_OUTPUT * @idx: the index value (only for input direction) * @mask: bit mask to set * @val: the bits value to set * * Update the AMP values for the given channel, direction and index. */ int snd_hda_codec_amp_update(struct hda_codec *codec, hda_nid_t nid, int ch, int dir, int idx, int mask, int val) { … } EXPORT_SYMBOL_GPL(…); /** * snd_hda_codec_amp_stereo - update the AMP stereo values * @codec: HD-audio codec * @nid: NID to read the AMP value * @direction: #HDA_INPUT or #HDA_OUTPUT * @idx: the index value (only for input direction) * @mask: bit mask to set * @val: the bits value to set * * Update the AMP values like snd_hda_codec_amp_update(), but for a * stereo widget with the same mask and value. */ int snd_hda_codec_amp_stereo(struct hda_codec *codec, hda_nid_t nid, int direction, int idx, int mask, int val) { … } EXPORT_SYMBOL_GPL(…); /** * snd_hda_codec_amp_init - initialize the AMP value * @codec: the HDA codec * @nid: NID to read the AMP value * @ch: channel (left=0 or right=1) * @dir: #HDA_INPUT or #HDA_OUTPUT * @idx: the index value (only for input direction) * @mask: bit mask to set * @val: the bits value to set * * Works like snd_hda_codec_amp_update() but it writes the value only at * the first access. If the amp was already initialized / updated beforehand, * this does nothing. */ int snd_hda_codec_amp_init(struct hda_codec *codec, hda_nid_t nid, int ch, int dir, int idx, int mask, int val) { … } EXPORT_SYMBOL_GPL(…); /** * snd_hda_codec_amp_init_stereo - initialize the stereo AMP value * @codec: the HDA codec * @nid: NID to read the AMP value * @dir: #HDA_INPUT or #HDA_OUTPUT * @idx: the index value (only for input direction) * @mask: bit mask to set * @val: the bits value to set * * Call snd_hda_codec_amp_init() for both stereo channels. */ int snd_hda_codec_amp_init_stereo(struct hda_codec *codec, hda_nid_t nid, int dir, int idx, int mask, int val) { … } EXPORT_SYMBOL_GPL(…); static u32 get_amp_max_value(struct hda_codec *codec, hda_nid_t nid, int dir, unsigned int ofs) { … } /** * snd_hda_mixer_amp_volume_info - Info callback for a standard AMP mixer * @kcontrol: referred ctl element * @uinfo: pointer to get/store the data * * The control element is supposed to have the private_value field * set up via HDA_COMPOSE_AMP_VAL*() or related macros. */ int snd_hda_mixer_amp_volume_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) { … } EXPORT_SYMBOL_GPL(…); static inline unsigned int read_amp_value(struct hda_codec *codec, hda_nid_t nid, int ch, int dir, int idx, unsigned int ofs) { … } static inline int update_amp_value(struct hda_codec *codec, hda_nid_t nid, int ch, int dir, int idx, unsigned int ofs, unsigned int val) { … } /** * snd_hda_mixer_amp_volume_get - Get callback for a standard AMP mixer volume * @kcontrol: ctl element * @ucontrol: pointer to get/store the data * * The control element is supposed to have the private_value field * set up via HDA_COMPOSE_AMP_VAL*() or related macros. */ int snd_hda_mixer_amp_volume_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { … } EXPORT_SYMBOL_GPL(…); /** * snd_hda_mixer_amp_volume_put - Put callback for a standard AMP mixer volume * @kcontrol: ctl element * @ucontrol: pointer to get/store the data * * The control element is supposed to have the private_value field * set up via HDA_COMPOSE_AMP_VAL*() or related macros. */ int snd_hda_mixer_amp_volume_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { … } EXPORT_SYMBOL_GPL(…); /* inquiry the amp caps and convert to TLV */ static void get_ctl_amp_tlv(struct snd_kcontrol *kcontrol, unsigned int *tlv) { … } /** * snd_hda_mixer_amp_tlv - TLV callback for a standard AMP mixer volume * @kcontrol: ctl element * @op_flag: operation flag * @size: byte size of input TLV * @_tlv: TLV data * * The control element is supposed to have the private_value field * set up via HDA_COMPOSE_AMP_VAL*() or related macros. */ int snd_hda_mixer_amp_tlv(struct snd_kcontrol *kcontrol, int op_flag, unsigned int size, unsigned int __user *_tlv) { … } EXPORT_SYMBOL_GPL(…); /** * snd_hda_set_vmaster_tlv - Set TLV for a virtual master control * @codec: HD-audio codec * @nid: NID of a reference widget * @dir: #HDA_INPUT or #HDA_OUTPUT * @tlv: TLV data to be stored, at least 4 elements * * Set (static) TLV data for a virtual master volume using the AMP caps * obtained from the reference NID. * The volume range is recalculated as if the max volume is 0dB. */ void snd_hda_set_vmaster_tlv(struct hda_codec *codec, hda_nid_t nid, int dir, unsigned int *tlv) { … } EXPORT_SYMBOL_GPL(…); /* find a mixer control element with the given name */ static struct snd_kcontrol * find_mixer_ctl(struct hda_codec *codec, const char *name, int dev, int idx) { … } /** * snd_hda_find_mixer_ctl - Find a mixer control element with the given name * @codec: HD-audio codec * @name: ctl id name string * * Get the control element with the given id string and IFACE_MIXER. */ struct snd_kcontrol *snd_hda_find_mixer_ctl(struct hda_codec *codec, const char *name) { … } EXPORT_SYMBOL_GPL(…); static int find_empty_mixer_ctl_idx(struct hda_codec *codec, const char *name, int start_idx) { … } /** * snd_hda_ctl_add - Add a control element and assign to the codec * @codec: HD-audio codec * @nid: corresponding NID (optional) * @kctl: the control element to assign * * Add the given control element to an array inside the codec instance. * All control elements belonging to a codec are supposed to be added * by this function so that a proper clean-up works at the free or * reconfiguration time. * * If non-zero @nid is passed, the NID is assigned to the control element. * The assignment is shown in the codec proc file. * * snd_hda_ctl_add() checks the control subdev id field whether * #HDA_SUBDEV_NID_FLAG bit is set. If set (and @nid is zero), the lower * bits value is taken as the NID to assign. The #HDA_NID_ITEM_AMP bit * specifies if kctl->private_value is a HDA amplifier value. */ int snd_hda_ctl_add(struct hda_codec *codec, hda_nid_t nid, struct snd_kcontrol *kctl) { … } EXPORT_SYMBOL_GPL(…); /** * snd_hda_add_nid - Assign a NID to a control element * @codec: HD-audio codec * @nid: corresponding NID (optional) * @kctl: the control element to assign * @index: index to kctl * * Add the given control element to an array inside the codec instance. * This function is used when #snd_hda_ctl_add cannot be used for 1:1 * NID:KCTL mapping - for example "Capture Source" selector. */ int snd_hda_add_nid(struct hda_codec *codec, struct snd_kcontrol *kctl, unsigned int index, hda_nid_t nid) { … } EXPORT_SYMBOL_GPL(…); /** * snd_hda_ctls_clear - Clear all controls assigned to the given codec * @codec: HD-audio codec */ void snd_hda_ctls_clear(struct hda_codec *codec) { … } /** * snd_hda_lock_devices - pseudo device locking * @bus: the BUS * * toggle card->shutdown to allow/disallow the device access (as a hack) */ int snd_hda_lock_devices(struct hda_bus *bus) { … } EXPORT_SYMBOL_GPL(…); /** * snd_hda_unlock_devices - pseudo device unlocking * @bus: the BUS */ void snd_hda_unlock_devices(struct hda_bus *bus) { … } EXPORT_SYMBOL_GPL(…); /** * snd_hda_codec_reset - Clear all objects assigned to the codec * @codec: HD-audio codec * * This frees the all PCM and control elements assigned to the codec, and * clears the caches and restores the pin default configurations. * * When a device is being used, it returns -EBSY. If successfully freed, * returns zero. */ int snd_hda_codec_reset(struct hda_codec *codec) { … } map_follower_func_t; /* apply the function to all matching follower ctls in the mixer list */ static int map_followers(struct hda_codec *codec, const char * const *followers, const char *suffix, map_follower_func_t func, void *data) { … } static int check_follower_present(struct hda_codec *codec, void *data, struct snd_kcontrol *sctl) { … } /* call kctl->put with the given value(s) */ static int put_kctl_with_value(struct snd_kcontrol *kctl, int val) { … } struct follower_init_arg { … }; /* initialize the follower volume with 0dB via snd_ctl_apply_vmaster_followers() */ static int init_follower_0dB(struct snd_kcontrol *follower, struct snd_kcontrol *kctl, void *_arg) { … } /* unmute the follower via snd_ctl_apply_vmaster_followers() */ static int init_follower_unmute(struct snd_kcontrol *follower, struct snd_kcontrol *kctl, void *_arg) { … } static int add_follower(struct hda_codec *codec, void *data, struct snd_kcontrol *follower) { … } /** * __snd_hda_add_vmaster - create a virtual master control and add followers * @codec: HD-audio codec * @name: vmaster control name * @tlv: TLV data (optional) * @followers: follower control names (optional) * @suffix: suffix string to each follower name (optional) * @init_follower_vol: initialize followers to unmute/0dB * @access: kcontrol access rights * @ctl_ret: store the vmaster kcontrol in return * * Create a virtual master control with the given name. The TLV data * must be either NULL or a valid data. * * @followers is a NULL-terminated array of strings, each of which is a * follower control name. All controls with these names are assigned to * the new virtual master control. * * This function returns zero if successful or a negative error code. */ int __snd_hda_add_vmaster(struct hda_codec *codec, char *name, unsigned int *tlv, const char * const *followers, const char *suffix, bool init_follower_vol, unsigned int access, struct snd_kcontrol **ctl_ret) { … } EXPORT_SYMBOL_GPL(…); /* meta hook to call each driver's vmaster hook */ static void vmaster_hook(void *private_data, int enabled) { … } /** * snd_hda_add_vmaster_hook - Add a vmaster hw specific hook * @codec: the HDA codec * @hook: the vmaster hook object * * Add a hw specific hook (like EAPD) with the given vmaster switch kctl. */ int snd_hda_add_vmaster_hook(struct hda_codec *codec, struct hda_vmaster_mute_hook *hook) { … } EXPORT_SYMBOL_GPL(…); /** * snd_hda_sync_vmaster_hook - Sync vmaster hook * @hook: the vmaster hook * * Call the hook with the current value for synchronization. * Should be called in init callback. */ void snd_hda_sync_vmaster_hook(struct hda_vmaster_mute_hook *hook) { … } EXPORT_SYMBOL_GPL(…); /** * snd_hda_mixer_amp_switch_info - Info callback for a standard AMP mixer switch * @kcontrol: referred ctl element * @uinfo: pointer to get/store the data * * The control element is supposed to have the private_value field * set up via HDA_COMPOSE_AMP_VAL*() or related macros. */ int snd_hda_mixer_amp_switch_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) { … } EXPORT_SYMBOL_GPL(…); /** * snd_hda_mixer_amp_switch_get - Get callback for a standard AMP mixer switch * @kcontrol: ctl element * @ucontrol: pointer to get/store the data * * The control element is supposed to have the private_value field * set up via HDA_COMPOSE_AMP_VAL*() or related macros. */ int snd_hda_mixer_amp_switch_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { … } EXPORT_SYMBOL_GPL(…); /** * snd_hda_mixer_amp_switch_put - Put callback for a standard AMP mixer switch * @kcontrol: ctl element * @ucontrol: pointer to get/store the data * * The control element is supposed to have the private_value field * set up via HDA_COMPOSE_AMP_VAL*() or related macros. */ int snd_hda_mixer_amp_switch_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { … } EXPORT_SYMBOL_GPL(…); /* * SPDIF out controls */ static int snd_hda_spdif_mask_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) { … } static int snd_hda_spdif_cmask_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { … } static int snd_hda_spdif_pmask_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { … } static int snd_hda_spdif_default_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { … } /* convert from SPDIF status bits to HDA SPDIF bits * bit 0 (DigEn) is always set zero (to be filled later) */ static unsigned short convert_from_spdif_status(unsigned int sbits) { … } /* convert to SPDIF status bits from HDA SPDIF bits */ static unsigned int convert_to_spdif_status(unsigned short val) { … } /* set digital convert verbs both for the given NID and its followers */ static void set_dig_out(struct hda_codec *codec, hda_nid_t nid, int mask, int val) { … } static inline void set_dig_out_convert(struct hda_codec *codec, hda_nid_t nid, int dig1, int dig2) { … } static int snd_hda_spdif_default_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { … } #define snd_hda_spdif_out_switch_info … static int snd_hda_spdif_out_switch_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { … } static inline void set_spdif_ctls(struct hda_codec *codec, hda_nid_t nid, int dig1, int dig2) { … } static int snd_hda_spdif_out_switch_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { … } static const struct snd_kcontrol_new dig_mixes[] = …; /** * snd_hda_create_dig_out_ctls - create Output SPDIF-related controls * @codec: the HDA codec * @associated_nid: NID that new ctls associated with * @cvt_nid: converter NID * @type: HDA_PCM_TYPE_* * Creates controls related with the digital output. * Called from each patch supporting the digital out. * * Returns 0 if successful, or a negative error code. */ int snd_hda_create_dig_out_ctls(struct hda_codec *codec, hda_nid_t associated_nid, hda_nid_t cvt_nid, int type) { … } EXPORT_SYMBOL_GPL(…); /** * snd_hda_spdif_out_of_nid - get the hda_spdif_out entry from the given NID * @codec: the HDA codec * @nid: widget NID * * call within spdif_mutex lock */ struct hda_spdif_out *snd_hda_spdif_out_of_nid(struct hda_codec *codec, hda_nid_t nid) { … } EXPORT_SYMBOL_GPL(…); /** * snd_hda_spdif_ctls_unassign - Unassign the given SPDIF ctl * @codec: the HDA codec * @idx: the SPDIF ctl index * * Unassign the widget from the given SPDIF control. */ void snd_hda_spdif_ctls_unassign(struct hda_codec *codec, int idx) { … } EXPORT_SYMBOL_GPL(…); /** * snd_hda_spdif_ctls_assign - Assign the SPDIF controls to the given NID * @codec: the HDA codec * @idx: the SPDIF ctl idx * @nid: widget NID * * Assign the widget to the SPDIF control with the given index. */ void snd_hda_spdif_ctls_assign(struct hda_codec *codec, int idx, hda_nid_t nid) { … } EXPORT_SYMBOL_GPL(…); /* * SPDIF sharing with analog output */ static int spdif_share_sw_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { … } static int spdif_share_sw_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { … } static const struct snd_kcontrol_new spdif_share_sw = …; /** * snd_hda_create_spdif_share_sw - create Default PCM switch * @codec: the HDA codec * @mout: multi-out instance */ int snd_hda_create_spdif_share_sw(struct hda_codec *codec, struct hda_multi_out *mout) { … } EXPORT_SYMBOL_GPL(…); /* * SPDIF input */ #define snd_hda_spdif_in_switch_info … static int snd_hda_spdif_in_switch_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { … } static int snd_hda_spdif_in_switch_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { … } static int snd_hda_spdif_in_status_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { … } static const struct snd_kcontrol_new dig_in_ctls[] = …; /** * snd_hda_create_spdif_in_ctls - create Input SPDIF-related controls * @codec: the HDA codec * @nid: audio in widget NID * * Creates controls related with the SPDIF input. * Called from each patch supporting the SPDIF in. * * Returns 0 if successful, or a negative error code. */ int snd_hda_create_spdif_in_ctls(struct hda_codec *codec, hda_nid_t nid) { … } EXPORT_SYMBOL_GPL(…); /** * snd_hda_codec_set_power_to_all - Set the power state to all widgets * @codec: the HDA codec * @fg: function group (not used now) * @power_state: the power state to set (AC_PWRST_*) * * Set the given power state to all widgets that have the power control. * If the codec has power_filter set, it evaluates the power state and * filter out if it's unchanged as D3. */ void snd_hda_codec_set_power_to_all(struct hda_codec *codec, hda_nid_t fg, unsigned int power_state) { … } EXPORT_SYMBOL_GPL(…); /** * snd_hda_codec_eapd_power_filter - A power filter callback for EAPD * @codec: the HDA codec * @nid: widget NID * @power_state: power state to evalue * * Don't power down the widget if it controls eapd and EAPD_BTLENABLE is set. * This can be used a codec power_filter callback. */ unsigned int snd_hda_codec_eapd_power_filter(struct hda_codec *codec, hda_nid_t nid, unsigned int power_state) { … } EXPORT_SYMBOL_GPL(…); /* * set power state of the codec, and return the power state */ static unsigned int hda_set_power_state(struct hda_codec *codec, unsigned int power_state) { … } /* sync power states of all widgets; * this is called at the end of codec parsing */ static void sync_power_up_states(struct hda_codec *codec) { … } #ifdef CONFIG_SND_HDA_RECONFIG /* execute additional init verbs */ static void hda_exec_init_verbs(struct hda_codec *codec) { … } #else static inline void hda_exec_init_verbs(struct hda_codec *codec) {} #endif /* update the power on/off account with the current jiffies */ static void update_power_acct(struct hda_codec *codec, bool on) { … } void snd_hda_update_power_acct(struct hda_codec *codec) { … } /* * call suspend and power-down; used both from PM and power-save * this function returns the power state in the end */ static unsigned int hda_call_codec_suspend(struct hda_codec *codec) { … } /* * kick up codec; used both from PM and power-save */ static void hda_call_codec_resume(struct hda_codec *codec) { … } static int hda_codec_runtime_suspend(struct device *dev) { … } static int hda_codec_runtime_resume(struct device *dev) { … } static int hda_codec_pm_prepare(struct device *dev) { … } static void hda_codec_pm_complete(struct device *dev) { … } static int hda_codec_pm_suspend(struct device *dev) { … } static int hda_codec_pm_resume(struct device *dev) { … } static int hda_codec_pm_freeze(struct device *dev) { … } static int hda_codec_pm_thaw(struct device *dev) { … } static int hda_codec_pm_restore(struct device *dev) { … } /* referred in hda_bind.c */ const struct dev_pm_ops hda_codec_driver_pm = …; /* suspend the codec at shutdown; called from driver's shutdown callback */ void snd_hda_codec_shutdown(struct hda_codec *codec) { … } /* * add standard channel maps if not specified */ static int add_std_chmaps(struct hda_codec *codec) { … } /* default channel maps for 2.1 speakers; * since HD-audio supports only stereo, odd number channels are omitted */ const struct snd_pcm_chmap_elem snd_pcm_2_1_chmaps[] = …; EXPORT_SYMBOL_GPL(…); int snd_hda_codec_build_controls(struct hda_codec *codec) { … } EXPORT_SYMBOL_GPL(…); /* * PCM stuff */ static int hda_pcm_default_open_close(struct hda_pcm_stream *hinfo, struct hda_codec *codec, struct snd_pcm_substream *substream) { … } static int hda_pcm_default_prepare(struct hda_pcm_stream *hinfo, struct hda_codec *codec, unsigned int stream_tag, unsigned int format, struct snd_pcm_substream *substream) { … } static int hda_pcm_default_cleanup(struct hda_pcm_stream *hinfo, struct hda_codec *codec, struct snd_pcm_substream *substream) { … } static int set_pcm_default_values(struct hda_codec *codec, struct hda_pcm_stream *info) { … } /* * codec prepare/cleanup entries */ /** * snd_hda_codec_prepare - Prepare a stream * @codec: the HDA codec * @hinfo: PCM information * @stream: stream tag to assign * @format: format id to assign * @substream: PCM substream to assign * * Calls the prepare callback set by the codec with the given arguments. * Clean up the inactive streams when successful. */ int snd_hda_codec_prepare(struct hda_codec *codec, struct hda_pcm_stream *hinfo, unsigned int stream, unsigned int format, struct snd_pcm_substream *substream) { … } EXPORT_SYMBOL_GPL(…); /** * snd_hda_codec_cleanup - Clean up stream resources * @codec: the HDA codec * @hinfo: PCM information * @substream: PCM substream * * Calls the cleanup callback set by the codec with the given arguments. */ void snd_hda_codec_cleanup(struct hda_codec *codec, struct hda_pcm_stream *hinfo, struct snd_pcm_substream *substream) { … } EXPORT_SYMBOL_GPL(…); /* global */ const char *snd_hda_pcm_type_name[HDA_PCM_NTYPES] = …; /* * get the empty PCM device number to assign */ static int get_empty_pcm_device(struct hda_bus *bus, unsigned int type) { … } /* call build_pcms ops of the given codec and set up the default parameters */ int snd_hda_codec_parse_pcms(struct hda_codec *codec) { … } EXPORT_SYMBOL_GPL(…); /* assign all PCMs of the given codec */ int snd_hda_codec_build_pcms(struct hda_codec *codec) { … } /** * snd_hda_add_new_ctls - create controls from the array * @codec: the HDA codec * @knew: the array of struct snd_kcontrol_new * * This helper function creates and add new controls in the given array. * The array must be terminated with an empty entry as terminator. * * Returns 0 if successful, or a negative error code. */ int snd_hda_add_new_ctls(struct hda_codec *codec, const struct snd_kcontrol_new *knew) { … } EXPORT_SYMBOL_GPL(…); /** * snd_hda_codec_set_power_save - Configure codec's runtime PM * @codec: codec device to configure * @delay: autosuspend delay */ void snd_hda_codec_set_power_save(struct hda_codec *codec, int delay) { … } EXPORT_SYMBOL_GPL(…); /** * snd_hda_set_power_save - reprogram autosuspend for the given delay * @bus: HD-audio bus * @delay: autosuspend delay in msec, 0 = off * * Synchronize the runtime PM autosuspend state from the power_save option. */ void snd_hda_set_power_save(struct hda_bus *bus, int delay) { … } EXPORT_SYMBOL_GPL(…); /** * snd_hda_check_amp_list_power - Check the amp list and update the power * @codec: HD-audio codec * @check: the object containing an AMP list and the status * @nid: NID to check / update * * Check whether the given NID is in the amp list. If it's in the list, * check the current AMP status, and update the power-status according * to the mute status. * * This function is supposed to be set or called from the check_power_status * patch ops. */ int snd_hda_check_amp_list_power(struct hda_codec *codec, struct hda_loopback_check *check, hda_nid_t nid) { … } EXPORT_SYMBOL_GPL(…); /* * input MUX helper */ /** * snd_hda_input_mux_info - Info callback helper for the input-mux enum * @imux: imux helper object * @uinfo: pointer to get/store the data */ int snd_hda_input_mux_info(const struct hda_input_mux *imux, struct snd_ctl_elem_info *uinfo) { … } EXPORT_SYMBOL_GPL(…); /** * snd_hda_input_mux_put - Put callback helper for the input-mux enum * @codec: the HDA codec * @imux: imux helper object * @ucontrol: pointer to get/store the data * @nid: input mux NID * @cur_val: pointer to get/store the current imux value */ int snd_hda_input_mux_put(struct hda_codec *codec, const struct hda_input_mux *imux, struct snd_ctl_elem_value *ucontrol, hda_nid_t nid, unsigned int *cur_val) { … } EXPORT_SYMBOL_GPL(…); /** * snd_hda_enum_helper_info - Helper for simple enum ctls * @kcontrol: ctl element * @uinfo: pointer to get/store the data * @num_items: number of enum items * @texts: enum item string array * * process kcontrol info callback of a simple string enum array * when @num_items is 0 or @texts is NULL, assume a boolean enum array */ int snd_hda_enum_helper_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo, int num_items, const char * const *texts) { … } EXPORT_SYMBOL_GPL(…); /* * Multi-channel / digital-out PCM helper functions */ /* setup SPDIF output stream */ static void setup_dig_out_stream(struct hda_codec *codec, hda_nid_t nid, unsigned int stream_tag, unsigned int format) { … } static void cleanup_dig_out_stream(struct hda_codec *codec, hda_nid_t nid) { … } /** * snd_hda_multi_out_dig_open - open the digital out in the exclusive mode * @codec: the HDA codec * @mout: hda_multi_out object */ int snd_hda_multi_out_dig_open(struct hda_codec *codec, struct hda_multi_out *mout) { … } EXPORT_SYMBOL_GPL(…); /** * snd_hda_multi_out_dig_prepare - prepare the digital out stream * @codec: the HDA codec * @mout: hda_multi_out object * @stream_tag: stream tag to assign * @format: format id to assign * @substream: PCM substream to assign */ int snd_hda_multi_out_dig_prepare(struct hda_codec *codec, struct hda_multi_out *mout, unsigned int stream_tag, unsigned int format, struct snd_pcm_substream *substream) { … } EXPORT_SYMBOL_GPL(…); /** * snd_hda_multi_out_dig_cleanup - clean-up the digital out stream * @codec: the HDA codec * @mout: hda_multi_out object */ int snd_hda_multi_out_dig_cleanup(struct hda_codec *codec, struct hda_multi_out *mout) { … } EXPORT_SYMBOL_GPL(…); /** * snd_hda_multi_out_dig_close - release the digital out stream * @codec: the HDA codec * @mout: hda_multi_out object */ int snd_hda_multi_out_dig_close(struct hda_codec *codec, struct hda_multi_out *mout) { … } EXPORT_SYMBOL_GPL(…); /** * snd_hda_multi_out_analog_open - open analog outputs * @codec: the HDA codec * @mout: hda_multi_out object * @substream: PCM substream to assign * @hinfo: PCM information to assign * * Open analog outputs and set up the hw-constraints. * If the digital outputs can be opened as follower, open the digital * outputs, too. */ int snd_hda_multi_out_analog_open(struct hda_codec *codec, struct hda_multi_out *mout, struct snd_pcm_substream *substream, struct hda_pcm_stream *hinfo) { … } EXPORT_SYMBOL_GPL(…); /** * snd_hda_multi_out_analog_prepare - Preapre the analog outputs. * @codec: the HDA codec * @mout: hda_multi_out object * @stream_tag: stream tag to assign * @format: format id to assign * @substream: PCM substream to assign * * Set up the i/o for analog out. * When the digital out is available, copy the front out to digital out, too. */ int snd_hda_multi_out_analog_prepare(struct hda_codec *codec, struct hda_multi_out *mout, unsigned int stream_tag, unsigned int format, struct snd_pcm_substream *substream) { … } EXPORT_SYMBOL_GPL(…); /** * snd_hda_multi_out_analog_cleanup - clean up the setting for analog out * @codec: the HDA codec * @mout: hda_multi_out object */ int snd_hda_multi_out_analog_cleanup(struct hda_codec *codec, struct hda_multi_out *mout) { … } EXPORT_SYMBOL_GPL(…); /** * snd_hda_get_default_vref - Get the default (mic) VREF pin bits * @codec: the HDA codec * @pin: referred pin NID * * Guess the suitable VREF pin bits to be set as the pin-control value. * Note: the function doesn't set the AC_PINCTL_IN_EN bit. */ unsigned int snd_hda_get_default_vref(struct hda_codec *codec, hda_nid_t pin) { … } EXPORT_SYMBOL_GPL(…); /** * snd_hda_correct_pin_ctl - correct the pin ctl value for matching with the pin cap * @codec: the HDA codec * @pin: referred pin NID * @val: pin ctl value to audit */ unsigned int snd_hda_correct_pin_ctl(struct hda_codec *codec, hda_nid_t pin, unsigned int val) { … } EXPORT_SYMBOL_GPL(…); /** * _snd_hda_set_pin_ctl - Helper to set pin ctl value * @codec: the HDA codec * @pin: referred pin NID * @val: pin control value to set * @cached: access over codec pinctl cache or direct write * * This function is a helper to set a pin ctl value more safely. * It corrects the pin ctl value via snd_hda_correct_pin_ctl(), stores the * value in pin target array via snd_hda_codec_set_pin_target(), then * actually writes the value via either snd_hda_codec_write_cache() or * snd_hda_codec_write() depending on @cached flag. */ int _snd_hda_set_pin_ctl(struct hda_codec *codec, hda_nid_t pin, unsigned int val, bool cached) { … } EXPORT_SYMBOL_GPL(…); /** * snd_hda_add_imux_item - Add an item to input_mux * @codec: the HDA codec * @imux: imux helper object * @label: the name of imux item to assign * @index: index number of imux item to assign * @type_idx: pointer to store the resultant label index * * When the same label is used already in the existing items, the number * suffix is appended to the label. This label index number is stored * to type_idx when non-NULL pointer is given. */ int snd_hda_add_imux_item(struct hda_codec *codec, struct hda_input_mux *imux, const char *label, int index, int *type_idx) { … } EXPORT_SYMBOL_GPL(…); /** * snd_hda_bus_reset_codecs - Reset the bus * @bus: HD-audio bus */ void snd_hda_bus_reset_codecs(struct hda_bus *bus) { … } /** * snd_print_pcm_bits - Print the supported PCM fmt bits to the string buffer * @pcm: PCM caps bits * @buf: the string buffer to write * @buflen: the max buffer length * * used by hda_proc.c and hda_eld.c */ void snd_print_pcm_bits(int pcm, char *buf, int buflen) { … } EXPORT_SYMBOL_GPL(…); MODULE_DESCRIPTION(…) …; MODULE_LICENSE(…) …;