The ALSA Driver API
Management of Cards and Devices #
Card Management #
snd_device_alloc() #
int Allocate and initialize struct device for sound devices
Parameters
struct device **dev_p: pointer to store the allocated devicestruct snd_card *card: card to assign, optional
Description
For releasing the allocated device, call put_device().
snd_card_new() #
int create and initialize a soundcard structure
Parameters
struct device *parent: the parent device objectint idx: card index (address) [0 ... (SNDRV_CARDS-1)]const char *xid: card identification (ASCII string)struct module *module: top level module for lockingint extra_size: allocate this extra size after the main soundcard structurestruct snd_card **card_ret: the pointer to store the created card instance
Description
The function allocates snd_card instance via kzalloc with the given space for the driver to use freely. The allocated struct is stored in the given card_ret pointer.
Return
Zero if successful or a negative error code.
snd_devm_card_new() #
int managed snd_card object creation
Parameters
struct device *parent: the parent device objectint idx: card index (address) [0 ... (SNDRV_CARDS-1)]const char *xid: card identification (ASCII string)struct module *module: top level module for lockingsize_t extra_size: allocate this extra size after the main soundcard structurestruct snd_card **card_ret: the pointer to store the created card instance
Description
This function works like snd_card_new() but manages the allocated resource
via devres, i.e. you don't need to free explicitly.
When a snd_card object is created with this function and registered via
snd_card_register(), the very first devres action to call snd_card_free()
is added automatically. In that way, the resource disconnection is assured
at first, then released in the expected order.
If an error happens at the probe before snd_card_register() is called and
there have been other devres resources, you'd need to free the card manually
via snd_card_free() call in the error; otherwise it may lead to UAF due to
devres call orders. You can use snd_card_free_on_error() helper for
handling it more easily.
Return
zero if successful, or a negative error code
snd_card_free_on_error() #
int a small helper for handling devm probe errors
Parameters
struct device *dev: the managed device objectint ret: the return code from the probe callback
Description
This function handles the explicit snd_card_free() call at the error from
the probe callback. It's just a small helper for simplifying the error
handling with the managed devices.
Return
zero if successful, or a negative error code
snd_card_ref() #
struct snd_card * Get the card object from the index
Parameters
int idx: the card index
Description
Returns a card object corresponding to the given index or NULL if not found.
Release the object via snd_card_unref().
Return
a card object or NULL
snd_card_disconnect() #
void disconnect all APIs from the file-operations (user space)
Parameters
struct snd_card *card: soundcard structure
Description
Disconnects all APIs from the file-operations (user space).
Return
Zero, otherwise a negative error code.
Note
-
The current implementation replaces all active file->f_op with special
dummy file operations (they do nothing except release).
snd_card_disconnect_sync() #
void disconnect card and wait until files get closed
Parameters
struct snd_card *card: card object to disconnect
Description
This calls snd_card_disconnect() for disconnecting all belonging components
and waits until all pending files get closed.
It assures that all accesses from user-space finished so that the driver
can release its resources gracefully.
snd_card_free_when_closed() #
void Disconnect the card, free it later eventually
Parameters
struct snd_card *card: soundcard structure
Description
Unlike snd_card_free(), this function doesn't try to release the card
resource immediately, but tries to disconnect at first. When the card
is still in use, the function returns before freeing the resources.
The card resources will be freed when the refcount gets to zero.
Return
zero if successful, or a negative error code
snd_card_free() #
void frees given soundcard structure
Parameters
struct snd_card *card: soundcard structure
Description
This function releases the soundcard structure and the all assigned devices automatically. That is, you don't have to release the devices by yourself.
This function waits until the all resources are properly released.
Return
Zero. Frees all associated devices and frees the control interface associated to given soundcard.
snd_card_set_id() #
void set card identification name
Parameters
struct snd_card *card: soundcard structureconst char *nid: new identification string
Description
This function sets the card identification and checks for name collisions.
snd_card_add_dev_attr() #
int Append a new sysfs attribute group to card
Parameters
struct snd_card *card: card instanceconst struct attribute_group *group: attribute group to append
Return
zero if successful, or a negative error code
snd_card_register() #
int register the soundcard
Parameters
struct snd_card *card: soundcard structure
Description
This function registers all the devices assigned to the soundcard. Until calling this, the ALSA control interface is blocked from the external accesses. Thus, you should call this function at the end of the initialization of the card.
Return
Zero otherwise a negative error code if the registration failed.
snd_component_add() #
int add a component string
Parameters
struct snd_card *card: soundcard structureconst char *component: the component id string
Description
This function adds the component id string to the supported list. The component can be referred from the alsa-lib.
Return
Zero otherwise a negative error code.
snd_card_file_add() #
int add the file to the file list of the card
Parameters
struct snd_card *card: soundcard structurestruct file *file: file pointer
Description
This function adds the file to the file linked-list of the card. This linked-list is used to keep tracking the connection state, and to avoid the release of busy resources by hotplug.
Return
zero or a negative error code.
snd_card_file_remove() #
int remove the file from the file list
Parameters
struct snd_card *card: soundcard structurestruct file *file: file pointer
Description
This function removes the file formerly added to the card via
snd_card_file_add() function.
If all files are removed and snd_card_free_when_closed() was
called beforehand, it processes the pending release of
resources.
Return
Zero or a negative error code.
snd_power_ref_and_wait() #
int wait until the card gets powered up
Parameters
struct snd_card *card: soundcard structure
Description
Take the power_ref reference count of the given card, and wait until the card gets powered up to SNDRV_CTL_POWER_D0 state. The refcount is down again while sleeping until power-up, hence this function can be used for syncing the floating control ops accesses, typically around calling control ops.
The caller needs to pull down the refcount via snd_power_unref() later
no matter whether the error is returned from this function or not.
Return
Zero if successful, or a negative error code.
snd_power_wait() #
int wait until the card gets powered up (old form)
Parameters
struct snd_card *card: soundcard structure
Description
Wait until the card gets powered up to SNDRV_CTL_POWER_D0 state.
Return
Zero if successful, or a negative error code.
Device Components #
snd_device_new() #
int create an ALSA device component
Parameters
struct snd_card *card: the card instanceenum snd_device_type type: the device type, SNDRV_DEV_XXXvoid *device_data: the data pointer of this deviceconst struct snd_device_ops *ops: the operator table
Description
Creates a new device component for the given data pointer. The device will be assigned to the card and managed together by the card.
The data pointer plays a role as the identifier, too, so the pointer address must be unique and unchanged.
Return
Zero if successful, or a negative error code on failure.
snd_device_disconnect() #
void disconnect the device
Parameters
struct snd_card *card: the card instancevoid *device_data: the data pointer to disconnect
Description
Turns the device into the disconnection state, invoking dev_disconnect callback, if the device was already registered.
Usually called from snd_card_disconnect().
Return
Zero if successful, or a negative error code on failure or if the device not found.
snd_device_free() #
void release the device from the card
Parameters
struct snd_card *card: the card instancevoid *device_data: the data pointer to release
Description
Removes the device from the list on the card and invokes the callbacks, dev_disconnect and dev_free, corresponding to the state. Then release the device.
snd_device_register() #
int register the device
Parameters
struct snd_card *card: the card instancevoid *device_data: the data pointer to register
Description
Registers the device which was already created via
snd_device_new(). Usually this is called from snd_card_register(),
but it can be called later if any new devices are created after
invocation of snd_card_register().
Return
Zero if successful, or a negative error code on failure or if the device not found.
Module requests and Device File Entries #
snd_request_card() #
void try to load the card module
Parameters
int card: the card number
Description
Tries to load the module "snd-card-X" for the given card number via request_module. Returns immediately if already loaded.
snd_lookup_minor_data() #
void * get user data of a registered device
Parameters
unsigned int minor: the minor numberint type: device type (SNDRV_DEVICE_TYPE_XXX)
Description
Checks that a minor device with the specified type is registered, and returns its user data pointer.
This function increments the reference counter of the card instance
if an associated instance with the given minor number and type is found.
The caller must call snd_card_unref() appropriately later.
Return
The user data pointer if the specified device is found. NULL
otherwise.
snd_register_device() #
int Register the ALSA device file for the card
Parameters
int type: the device type, SNDRV_DEVICE_TYPE_XXXstruct snd_card *card: the card instanceint dev: the device indexconst struct file_operations *f_ops: the file operationsvoid *private_data: user pointer for f_ops->open()struct device *device: the device to register
Description
Registers an ALSA device file for the given card. The operators have to be set in reg parameter.
Return
Zero if successful, or a negative error code on failure.
snd_unregister_device() #
int unregister the device on the given card
Parameters
struct device *dev: the device instance
Description
Unregisters the device file already registered via
snd_register_device().
Return
Zero if successful, or a negative error code on failure.
Memory Management Helpers #
copy_to_user_fromio() #
int copy data from mmio-space to user-space
Parameters
void __user *dst: the destination pointer on user-spaceconst volatile void __iomem *src: the source pointer on mmiosize_t count: the data size to copy in bytes
Description
Copies the data from mmio-space to user-space.
Return
Zero if successful, or non-zero on failure.
copy_to_iter_fromio() #
size_t copy data from mmio-space to iov_iter
Parameters
const void __iomem *src: the source pointer on mmiosize_t count: the data size to copy in bytesstruct iov_iter *dst: the destination iov_iter
Description
Copies the data from mmio-space to iov_iter.
Return
number of bytes to be copied
copy_from_user_toio() #
int copy data from user-space to mmio-space
Parameters
volatile void __iomem *dst: the destination pointer on mmio-spaceconst void __user *src: the source pointer on user-spacesize_t count: the data size to copy in bytes
Description
Copies the data from user-space to mmio-space.
Return
Zero if successful, or non-zero on failure.
copy_from_iter_toio() #
size_t copy data from iov_iter to mmio-space
Parameters
void __iomem *dst: the destination pointer on mmio-spacesize_t count: the data size to copy in bytesstruct iov_iter *src: the source iov_iter
Description
Copies the data from iov_iter to mmio-space.
Return
number of bytes to be copied
snd_dma_alloc_dir_pages() #
int allocate the buffer area according to the given type and direction
Parameters
int type: the DMA buffer typestruct device *device: the device pointerenum dma_data_direction dir: DMA directionsize_t size: the buffer size to allocatestruct snd_dma_buffer *dmab: buffer allocation record to store the allocated data
Description
Calls the memory-allocator function for the corresponding buffer type.
Return
Zero if the buffer with the given size is allocated successfully, otherwise a negative value on error.
snd_dma_alloc_pages_fallback() #
int allocate the buffer area according to the given type with fallback
Parameters
int type: the DMA buffer typestruct device *device: the device pointersize_t size: the buffer size to allocatestruct snd_dma_buffer *dmab: buffer allocation record to store the allocated data
Description
Calls the memory-allocator function for the corresponding buffer type. When no space is left, this function reduces the size and tries to allocate again. The size actually allocated is stored in res_size argument.
Return
Zero if the buffer with the given size is allocated successfully, otherwise a negative value on error.
snd_dma_free_pages() #
void release the allocated buffer
Parameters
struct snd_dma_buffer *dmab: the buffer allocation record to release
Description
Releases the allocated buffer via snd_dma_alloc_pages().
snd_devm_alloc_dir_pages() #
struct snd_dma_buffer * allocate the buffer and manage with devres
Parameters
struct device *dev: the device pointerint type: the DMA buffer typeenum dma_data_direction dir: DMA directionsize_t size: the buffer size to allocate
Description
Allocate buffer pages depending on the given type and manage using devres. The pages will be released automatically at the device removal.
Unlike snd_dma_alloc_pages(), this function requires the real device pointer,
hence it can't work with SNDRV_DMA_TYPE_CONTINUOUS or
SNDRV_DMA_TYPE_VMALLOC type.
Return
the snd_dma_buffer object at success, or NULL if failed
snd_dma_buffer_mmap() #
int perform mmap of the given DMA buffer
Parameters
struct snd_dma_buffer *dmab: buffer allocation informationstruct vm_area_struct *area: VM area information
Return
zero if successful, or a negative error code
snd_dma_buffer_sync() #
void sync DMA buffer between CPU and device
Parameters
struct snd_dma_buffer *dmab: buffer allocation informationenum snd_dma_sync_mode mode: sync mode
snd_sgbuf_get_addr() #
dma_addr_t return the physical address at the corresponding offset
Parameters
struct snd_dma_buffer *dmab: buffer allocation informationsize_t offset: offset in the ring buffer
Return
the physical address
snd_sgbuf_get_page() #
struct page * return the physical page at the corresponding offset
Parameters
struct snd_dma_buffer *dmab: buffer allocation informationsize_t offset: offset in the ring buffer
Return
the page pointer
snd_sgbuf_get_chunk_size() #
unsigned int compute the max chunk size with continuous pages on sg-buffer
Parameters
struct snd_dma_buffer *dmab: buffer allocation informationunsigned int ofs: offset in the ring bufferunsigned int size: the requested size
Return
the chunk size
PCM API #
PCM Core #
snd_pcm_format_name() #
const char * Return a name string for the given PCM format
Parameters
snd_pcm_format_t format: PCM format
Return
the format name string
snd_pcm_new_stream() #
int create a new PCM stream
Parameters
struct snd_pcm *pcm: the pcm instanceint stream: the stream direction, SNDRV_PCM_STREAM_XXXint substream_count: the number of substreams
Description
Creates a new stream for the pcm.
The corresponding stream on the pcm must have been empty before
calling this, i.e. zero must be given to the argument of
snd_pcm_new().
Return
Zero if successful, or a negative error code on failure.
snd_pcm_new() #
int create a new PCM instance
Parameters
struct snd_card *card: the card instanceconst char *id: the id stringint device: the device index (zero based)int playback_count: the number of substreams for playbackint capture_count: the number of substreams for capturestruct snd_pcm **rpcm: the pointer to store the new pcm instance
Description
Creates a new PCM instance.
The pcm operators have to be set afterwards to the new instance
via snd_pcm_set_ops().
Return
Zero if successful, or a negative error code on failure.
snd_pcm_new_internal() #
int create a new internal PCM instance
Parameters
struct snd_card *card: the card instanceconst char *id: the id stringint device: the device index (zero based - shared with normal PCMs)int playback_count: the number of substreams for playbackint capture_count: the number of substreams for capturestruct snd_pcm **rpcm: the pointer to store the new pcm instance
Description
Creates a new internal PCM instance with no userspace device or procfs entries. This is used by ASoC Back End PCMs in order to create a PCM that will only be used internally by kernel drivers. i.e. it cannot be opened by userspace. It provides existing ASoC components drivers with a substream and access to any private data.
The pcm operators have to be set afterwards to the new instance
via snd_pcm_set_ops().
Return
Zero if successful, or a negative error code on failure.
snd_pcm_notify() #
int Add/remove the notify list
Parameters
struct snd_pcm_notify *notify: PCM notify listint nfree: 0 = register, 1 = unregister
Description
This adds the given notifier to the global list so that the callback is called for each registered PCM devices. This exists only for PCM OSS emulation, so far.
Return
zero if successful, or a negative error code
snd_pcm_set_ops() #
void set the PCM operators
Parameters
struct snd_pcm *pcm: the pcm instanceint direction: stream direction, SNDRV_PCM_STREAM_XXXconst struct snd_pcm_ops *ops: the operator table
Description
Sets the given PCM operators to the pcm instance.
snd_pcm_set_sync_per_card() #
void set the PCM sync id with card number
Parameters
struct snd_pcm_substream *substream: the pcm substreamstruct snd_pcm_hw_params *params: modified hardware parametersconst unsigned char *id: identifier (max 12 bytes)unsigned int len: identifier length (max 12 bytes)
Description
Sets the PCM sync identifier for the card with zero padding.
User space or any user should use this 16-byte identifier for a comparison only to check if two IDs are similar or different. Special case is the identifier containing only zeros. Interpretation for this combination is - empty (not set). The contents of the identifier should not be interpreted in any other way.
The synchronization ID must be unique per clock source (usually one sound card, but multiple soundcard may use one PCM word clock source which means that they are fully synchronized).
This routine composes this ID using card number in first four bytes and 12-byte additional ID. When other ID composition is used (e.g. for multiple sound cards), make sure that the composition does not clash with this composition scheme.
snd_interval_refine() #
int refine the interval value of configurator
Parameters
struct snd_interval *i: the interval value to refineconst struct snd_interval *v: the interval value to refer to
Description
Refines the interval value with the reference value. The interval is changed to the range satisfying both intervals. The interval status (min, max, integer, etc.) are evaluated.
Return
Positive if the value is changed, zero if it's not changed, or a negative error code.
snd_interval_div() #
void refine the interval value with division
Parameters
const struct snd_interval *a: dividendconst struct snd_interval *b: divisorstruct snd_interval *c: quotient
Description
c = a / b
Returns non-zero if the value is changed, zero if not changed.
snd_interval_muldivk() #
void refine the interval value
Parameters
const struct snd_interval *a: dividend 1const struct snd_interval *b: dividend 2unsigned int k: divisor (as integer)struct snd_interval *c: result
Description
c = a * b / k
Returns non-zero if the value is changed, zero if not changed.
snd_interval_mulkdiv() #
void refine the interval value
Parameters
const struct snd_interval *a: dividend 1unsigned int k: dividend 2 (as integer)const struct snd_interval *b: divisorstruct snd_interval *c: result
Description
c = a * k / b
Returns non-zero if the value is changed, zero if not changed.
snd_interval_ratnum() #
int refine the interval value
Parameters
struct snd_interval *i: interval to refineunsigned int rats_count: number of ratnum_tconst struct snd_ratnum *rats: ratnum_t arrayunsigned int *nump: pointer to store the resultant numeratorunsigned int *denp: pointer to store the resultant denominator
Return
Positive if the value is changed, zero if it's not changed, or a negative error code.
snd_interval_ratden() #
int refine the interval value
Parameters
struct snd_interval *i: interval to refineunsigned int rats_count: number of struct ratdenconst struct snd_ratden *rats: struct ratden arrayunsigned int *nump: pointer to store the resultant numeratorunsigned int *denp: pointer to store the resultant denominator
Return
Positive if the value is changed, zero if it's not changed, or a negative error code.
snd_interval_list() #
int refine the interval value from the list
Parameters
struct snd_interval *i: the interval value to refineunsigned int count: the number of elements in the listconst unsigned int *list: the value listunsigned int mask: the bit-mask to evaluate
Description
Refines the interval value from the list. When mask is non-zero, only the elements corresponding to bit 1 are evaluated.
Return
Positive if the value is changed, zero if it's not changed, or a negative error code.
snd_interval_ranges() #
int refine the interval value from the list of ranges
Parameters
struct snd_interval *i: the interval value to refineunsigned int count: the number of elements in the list of rangesconst struct snd_interval *ranges: the ranges listunsigned int mask: the bit-mask to evaluate
Description
Refines the interval value from the list of ranges. When mask is non-zero, only the elements corresponding to bit 1 are evaluated.
Return
Positive if the value is changed, zero if it's not changed, or a negative error code.
snd_pcm_hw_rule_add() #
int add the hw-constraint rule
Parameters
struct snd_pcm_runtime *runtime: the pcm runtime instanceunsigned int cond: condition bitsint var: the variable to evaluatesnd_pcm_hw_rule_func_t func: the evaluation functionvoid *private: the private data pointer passed to functionint dep: the dependent variables...: variable arguments
Return
Zero if successful, or a negative error code on failure.
snd_pcm_hw_constraint_mask() #
int apply the given bitmap mask constraint
Parameters
struct snd_pcm_runtime *runtime: PCM runtime instancesnd_pcm_hw_param_t var: hw_params variable to apply the masku_int32_t mask: the bitmap mask
Description
Apply the constraint of the given bitmap mask to a 32-bit mask parameter.
Return
Zero if successful, or a negative error code on failure.
snd_pcm_hw_constraint_mask64() #
int apply the given bitmap mask constraint
Parameters
struct snd_pcm_runtime *runtime: PCM runtime instancesnd_pcm_hw_param_t var: hw_params variable to apply the masku_int64_t mask: the 64bit bitmap mask
Description
Apply the constraint of the given bitmap mask to a 64-bit mask parameter.
Return
Zero if successful, or a negative error code on failure.
snd_pcm_hw_constraint_integer() #
int apply an integer constraint to an interval
Parameters
struct snd_pcm_runtime *runtime: PCM runtime instancesnd_pcm_hw_param_t var: hw_params variable to apply the integer constraint
Description
Apply the constraint of integer to an interval parameter.
Return
Positive if the value is changed, zero if it's not changed, or a negative error code.
snd_pcm_hw_constraint_minmax() #
int apply a min/max range constraint to an interval
Parameters
struct snd_pcm_runtime *runtime: PCM runtime instancesnd_pcm_hw_param_t var: hw_params variable to apply the rangeunsigned int min: the minimal valueunsigned int max: the maximal value
Description
Apply the min/max range constraint to an interval parameter.
Return
Positive if the value is changed, zero if it's not changed, or a negative error code.
snd_pcm_hw_constraint_list() #
int apply a list of constraints to a parameter
Parameters
struct snd_pcm_runtime *runtime: PCM runtime instanceunsigned int cond: condition bitssnd_pcm_hw_param_t var: hw_params variable to apply the list constraintconst struct snd_pcm_hw_constraint_list *l: list
Description
Apply the list of constraints to an interval parameter.
Return
Zero if successful, or a negative error code on failure.
snd_pcm_hw_constraint_ranges() #
int apply list of range constraints to a parameter
Parameters
struct snd_pcm_runtime *runtime: PCM runtime instanceunsigned int cond: condition bitssnd_pcm_hw_param_t var: hw_params variable to apply the list of range constraintsconst struct snd_pcm_hw_constraint_ranges *r: ranges
Description
Apply the list of range constraints to an interval parameter.
Return
Zero if successful, or a negative error code on failure.
snd_pcm_hw_constraint_ratnums() #
int apply ratnums constraint to a parameter
Parameters
struct snd_pcm_runtime *runtime: PCM runtime instanceunsigned int cond: condition bitssnd_pcm_hw_param_t var: hw_params variable to apply the ratnums constraintconst struct snd_pcm_hw_constraint_ratnums *r: struct snd_ratnums constriants
Return
Zero if successful, or a negative error code on failure.
snd_pcm_hw_constraint_ratdens() #
int apply ratdens constraint to a parameter
Parameters
struct snd_pcm_runtime *runtime: PCM runtime instanceunsigned int cond: condition bitssnd_pcm_hw_param_t var: hw_params variable to apply the ratdens constraintconst struct snd_pcm_hw_constraint_ratdens *r: struct snd_ratdens constriants
Return
Zero if successful, or a negative error code on failure.
snd_pcm_hw_constraint_msbits() #
int add a hw constraint msbits rule
Parameters
struct snd_pcm_runtime *runtime: PCM runtime instanceunsigned int cond: condition bitsunsigned int width: sample bits widthunsigned int msbits: msbits width
Description
This constraint will set the number of most significant bits (msbits) if a sample format with the specified width has been select. If width is set to 0 the msbits will be set for any sample format with a width larger than the specified msbits.
Return
Zero if successful, or a negative error code on failure.
snd_pcm_hw_constraint_step() #
int add a hw constraint step rule
Parameters
struct snd_pcm_runtime *runtime: PCM runtime instanceunsigned int cond: condition bitssnd_pcm_hw_param_t var: hw_params variable to apply the step constraintunsigned long step: step size
Return
Zero if successful, or a negative error code on failure.
snd_pcm_hw_constraint_pow2() #
int add a hw constraint power-of-2 rule
Parameters
struct snd_pcm_runtime *runtime: PCM runtime instanceunsigned int cond: condition bitssnd_pcm_hw_param_t var: hw_params variable to apply the power-of-2 constraint
Return
Zero if successful, or a negative error code on failure.
snd_pcm_hw_rule_noresample() #
int add a rule to allow disabling hw resampling
Parameters
struct snd_pcm_runtime *runtime: PCM runtime instanceunsigned int base_rate: the rate at which the hardware does not resample
Return
Zero if successful, or a negative error code on failure.
snd_pcm_hw_param_value() #
int return params field var value
Parameters
const struct snd_pcm_hw_params *params: the hw_params instancesnd_pcm_hw_param_t var: parameter to retrieveint *dir: pointer to the direction (-1,0,1) orNULL
Return
The value for field var if it's fixed in configuration space
defined by params. -EINVAL otherwise.
snd_pcm_hw_param_first() #
int refine config space and return minimum value
Parameters
struct snd_pcm_substream *pcm: PCM instancestruct snd_pcm_hw_params *params: the hw_params instancesnd_pcm_hw_param_t var: parameter to retrieveint *dir: pointer to the direction (-1,0,1) orNULL
Description
Inside configuration space defined by params remove from var all values > minimum. Reduce configuration space accordingly.
Return
The minimum, or a negative error code on failure.
snd_pcm_hw_param_last() #
int refine config space and return maximum value
Parameters
struct snd_pcm_substream *pcm: PCM instancestruct snd_pcm_hw_params *params: the hw_params instancesnd_pcm_hw_param_t var: parameter to retrieveint *dir: pointer to the direction (-1,0,1) orNULL
Description
Inside configuration space defined by params remove from var all values < maximum. Reduce configuration space accordingly.
Return
The maximum, or a negative error code on failure.
snd_pcm_hw_params_bits() #
int Get the number of bits per the sample.
Parameters
const struct snd_pcm_hw_params *p: hardware parameters
Return
The number of bits per sample based on the format, subformat and msbits the specified hw params has.
snd_pcm_lib_ioctl() #
int a generic PCM ioctl callback
Parameters
struct snd_pcm_substream *substream: the pcm substream instanceunsigned int cmd: ioctl commandvoid *arg: ioctl argument
Description
Processes the generic ioctl commands for PCM. Can be passed as the ioctl callback for PCM ops.
Return
Zero if successful, or a negative error code on failure.
snd_pcm_period_elapsed_under_stream_lock() #
void update the status of runtime for the next period under acquired lock of PCM substream.
Parameters
struct snd_pcm_substream *substream: the instance of pcm substream.
Description
This function is called when the batch of audio data frames as the same size as the period of buffer is already processed in audio data transmission.
The call of function updates the status of runtime with the latest position of audio data transmission, checks overrun and underrun over buffer, awaken user processes from waiting for available audio data frames, sampling audio timestamp, and performs stop or drain the PCM substream according to configured threshold.
The function is intended to use for the case that PCM driver operates audio data frames under
acquired lock of PCM substream; e.g. in callback of any operation of snd_pcm_ops in process
context. In any interrupt context, it's preferrable to use snd_pcm_period_elapsed() instead
since lock of PCM substream should be acquired in advance.
Developer should pay enough attention that some callbacks in snd_pcm_ops are done by the call of
function:
- .pointer - to retrieve current position of audio data transmission by frame count or XRUN state.
- .trigger - with SNDRV_PCM_TRIGGER_STOP at XRUN or DRAINING state.
- .get_time_info - to retrieve audio time stamp if needed.
Even if more than one periods have elapsed since the last call, you have to call this only once.
snd_pcm_period_elapsed() #
void update the status of runtime for the next period by acquiring lock of PCM substream.
Parameters
struct snd_pcm_substream *substream: the instance of PCM substream.
Description
This function is mostly similar to snd_pcm_period_elapsed_under_stream_lock() except for
acquiring lock of PCM substream voluntarily.
It's typically called by any type of IRQ handler when hardware IRQ occurs to notify event that the batch of audio data frames as the same size as the period of buffer is already processed in audio data transmission.
snd_pcm_add_chmap_ctls() #
int create channel-mapping control elements
Parameters
struct snd_pcm *pcm: the assigned PCM instanceint stream: stream directionconst struct snd_pcm_chmap_elem *chmap: channel map elements (for query)int max_channels: the max number of channels for the streamunsigned long private_value: the value passed to each kcontrol's private_value fieldstruct snd_pcm_chmap **info_ret: store struct snd_pcm_chmap instance if non-NULL
Description
Create channel-mapping control elements assigned to the given PCM stream(s).
Return
Zero if successful, or a negative error value.
snd_pcm_stream_lock() #
void Lock the PCM stream
Parameters
struct snd_pcm_substream *substream: PCM substream
Description
This locks the PCM stream's spinlock or mutex depending on the nonatomic flag of the given substream. This also takes the global link rw lock (or rw sem), too, for avoiding the race with linked streams.
snd_pcm_stream_unlock() #
void Unlock the PCM stream
Parameters
struct snd_pcm_substream *substream: PCM substream
Description
This unlocks the PCM stream that has been locked via snd_pcm_stream_lock().
snd_pcm_stream_lock_irq() #
void Lock the PCM stream
Parameters
struct snd_pcm_substream *substream: PCM substream
Description
This locks the PCM stream like snd_pcm_stream_lock() and disables the local
IRQ (only when nonatomic is false). In nonatomic case, this is identical
as snd_pcm_stream_lock().
snd_pcm_stream_unlock_irq() #
void Unlock the PCM stream
Parameters
struct snd_pcm_substream *substream: PCM substream
Description
This is a counter-part of snd_pcm_stream_lock_irq().
snd_pcm_stream_unlock_irqrestore() #
void Unlock the PCM stream
Parameters
struct snd_pcm_substream *substream: PCM substreamunsigned long flags: irq flags
Description
This is a counter-part of snd_pcm_stream_lock_irqsave().
snd_pcm_hw_params_choose() #
int choose a configuration defined by params
Parameters
struct snd_pcm_substream *pcm: PCM instancestruct snd_pcm_hw_params *params: the hw_params instance
Description
Choose one configuration from configuration space defined by params. The configuration chosen is that obtained fixing in this order: first access, first format, first subformat, min channels, min rate, min period time, max buffer size, min tick time
Return
Zero if successful, or a negative error code on failure.
snd_pcm_start() #
int start all linked streams
Parameters
struct snd_pcm_substream *substream: the PCM substream instance
Return
Zero if successful, or a negative error code. The stream lock must be acquired before calling this function.
snd_pcm_stop() #
int try to stop all running streams in the substream group
Parameters
struct snd_pcm_substream *substream: the PCM substream instancesnd_pcm_state_t state: PCM state after stopping the stream
Description
The state of each stream is then changed to the given state unconditionally.
Return
Zero if successful, or a negative error code.
snd_pcm_drain_done() #
int stop the DMA only when the given stream is playback
Parameters
struct snd_pcm_substream *substream: the PCM substream
Description
After stopping, the state is changed to SETUP.
Unlike snd_pcm_stop(), this affects only the given stream.
Return
Zero if successful, or a negative error code.
snd_pcm_stop_xrun() #
int stop the running streams as XRUN
Parameters
struct snd_pcm_substream *substream: the PCM substream instance
Description
This stops the given running substream (and all linked substreams) as XRUN.
Unlike snd_pcm_stop(), this function takes the substream lock by itself.
Return
Zero if successful, or a negative error code.
snd_pcm_suspend_all() #
int trigger SUSPEND to all substreams in the given pcm
Parameters
struct snd_pcm *pcm: the PCM instance
Description
After this call, all streams are changed to SUSPENDED state.
Return
Zero if successful (or pcm is NULL), or a negative error code.
snd_pcm_prepare() #
int prepare the PCM substream to be triggerable
Parameters
struct snd_pcm_substream *substream: the PCM substream instancestruct file *file: file to refer f_flags
Return
Zero if successful, or a negative error code.
snd_pcm_kernel_ioctl() #
int Execute PCM ioctl in the kernel-space
Parameters
struct snd_pcm_substream *substream: PCM substreamunsigned int cmd: IOCTL cmdvoid *arg: IOCTL argument
Description
The function is provided primarily for OSS layer and USB gadget drivers, and it allows only the limited set of ioctls (hw_params, sw_params, prepare, start, drain, drop, forward).
Return
zero if successful, or a negative error code
snd_pcm_lib_default_mmap() #
int Default PCM data mmap function
Parameters
struct snd_pcm_substream *substream: PCM substreamstruct vm_area_struct *area: VMA
Description
This is the default mmap handler for PCM data. When mmap pcm_ops is NULL, this function is invoked implicitly.
Return
zero if successful, or a negative error code
snd_pcm_lib_mmap_iomem() #
int Default PCM data mmap function for I/O mem
Parameters
struct snd_pcm_substream *substream: PCM substreamstruct vm_area_struct *area: VMA
Description
When your hardware uses the iomapped pages as the hardware buffer and wants to mmap it, pass this function as mmap pcm_ops. Note that this is supposed to work only on limited architectures.
Return
zero if successful, or a negative error code
snd_pcm_stream_linked() #
int Check whether the substream is linked with others
Parameters
struct snd_pcm_substream *substream: substream to check
Return
true if the given substream is being linked with others
snd_pcm_stream_lock_irqsave() #
Lock the PCM stream
Parameters
substream: PCM substreamflags: irq flags
Description
This locks the PCM stream like snd_pcm_stream_lock() but with the local
IRQ (only when nonatomic is false). In nonatomic case, this is identical
as snd_pcm_stream_lock().
snd_pcm_stream_lock_irqsave_nested() #
Single-nested PCM stream locking
Parameters
substream: PCM substreamflags: irq flags
Description
This locks the PCM stream like snd_pcm_stream_lock_irqsave() but with
the single-depth lockdep subclass.
snd_pcm_group_for_each_entry() #
iterate over the linked substreams
Parameters
s: the iteratorsubstream: the substream
Description
Iterate over the all linked substreams to the given substream. When substream isn't linked with any others, this gives returns substream itself once.
snd_pcm_running() #
int Check whether the substream is in a running state
Parameters
struct snd_pcm_substream *substream: substream to check
Return
true if the given substream is in the state RUNNING, or in the state DRAINING for playback.
__snd_pcm_set_state() #
void Change the current PCM state
Parameters
struct snd_pcm_runtime *runtime: PCM runtime to setsnd_pcm_state_t state: the current state to set
Description
Call within the stream lock
bytes_to_samples() #
ssize_t Unit conversion of the size from bytes to samples
Parameters
struct snd_pcm_runtime *runtime: PCM runtime instancessize_t size: size in bytes
Return
the size in samples
bytes_to_frames() #
snd_pcm_sframes_t Unit conversion of the size from bytes to frames
Parameters
struct snd_pcm_runtime *runtime: PCM runtime instancessize_t size: size in bytes
Return
the size in frames
samples_to_bytes() #
ssize_t Unit conversion of the size from samples to bytes
Parameters
struct snd_pcm_runtime *runtime: PCM runtime instancessize_t size: size in samples
Return
the byte size
frames_to_bytes() #
ssize_t Unit conversion of the size from frames to bytes
Parameters
struct snd_pcm_runtime *runtime: PCM runtime instancesnd_pcm_sframes_t size: size in frames
Return
the byte size
frame_aligned() #
int Check whether the byte size is aligned to frames
Parameters
struct snd_pcm_runtime *runtime: PCM runtime instancessize_t bytes: size in bytes
Return
true if aligned, or false if not
snd_pcm_lib_buffer_bytes() #
size_t Get the buffer size of the current PCM in bytes
Parameters
struct snd_pcm_substream *substream: PCM substream
Return
buffer byte size
snd_pcm_lib_period_bytes() #
size_t Get the period size of the current PCM in bytes
Parameters
struct snd_pcm_substream *substream: PCM substream
Return
period byte size
snd_pcm_playback_avail() #
snd_pcm_uframes_t Get the available (writable) space for playback
Parameters
struct snd_pcm_runtime *runtime: PCM runtime instance
Description
Result is between 0 ... (boundary - 1)
Return
available frame size
snd_pcm_capture_avail() #
snd_pcm_uframes_t Get the available (readable) space for capture
Parameters
struct snd_pcm_runtime *runtime: PCM runtime instance
Description
Result is between 0 ... (boundary - 1)
Return
available frame size
snd_pcm_playback_hw_avail() #
snd_pcm_sframes_t Get the queued space for playback
Parameters
struct snd_pcm_runtime *runtime: PCM runtime instance
Return
available frame size
snd_pcm_capture_hw_avail() #
snd_pcm_sframes_t Get the free space for capture
Parameters
struct snd_pcm_runtime *runtime: PCM runtime instance
Return
available frame size
snd_pcm_playback_ready() #
int check whether the playback buffer is available
Parameters
struct snd_pcm_substream *substream: the pcm substream instance
Description
Checks whether enough free space is available on the playback buffer.
Return
Non-zero if available, or zero if not.
snd_pcm_capture_ready() #
int check whether the capture buffer is available
Parameters
struct snd_pcm_substream *substream: the pcm substream instance
Description
Checks whether enough capture data is available on the capture buffer.
Return
Non-zero if available, or zero if not.
snd_pcm_playback_data() #
int check whether any data exists on the playback buffer
Parameters
struct snd_pcm_substream *substream: the pcm substream instance
Description
Checks whether any data exists on the playback buffer.
Return
Non-zero if any data exists, or zero if not. If stop_threshold is bigger or equal to boundary, then this function returns always non-zero.
snd_pcm_playback_empty() #
int check whether the playback buffer is empty
Parameters
struct snd_pcm_substream *substream: the pcm substream instance
Description
Checks whether the playback buffer is empty.
Return
Non-zero if empty, or zero if not.
snd_pcm_capture_empty() #
int check whether the capture buffer is empty
Parameters
struct snd_pcm_substream *substream: the pcm substream instance
Description
Checks whether the capture buffer is empty.
Return
Non-zero if empty, or zero if not.
snd_pcm_trigger_done() #
void Mark the master substream
Parameters
struct snd_pcm_substream *substream: the pcm substream instancestruct snd_pcm_substream *master: the linked master substream
Description
When multiple substreams of the same card are linked and the hardware
supports the single-shot operation, the driver calls this in the loop
in snd_pcm_group_for_each_entry() for marking the substream as "done".
Then most of trigger operations are performed only to the given master
substream.
The trigger_master mark is cleared at timestamp updates at the end of trigger operations.
params_channels() #
unsigned int Get the number of channels from the hw params
Parameters
const struct snd_pcm_hw_params *p: hw params
Return
the number of channels
params_rate() #
unsigned int Get the sample rate from the hw params
Parameters
const struct snd_pcm_hw_params *p: hw params
Return
the sample rate
params_period_size() #
unsigned int Get the period size (in frames) from the hw params
Parameters
const struct snd_pcm_hw_params *p: hw params
Return
the period size in frames
params_periods() #
unsigned int Get the number of periods from the hw params
Parameters
const struct snd_pcm_hw_params *p: hw params
Return
the number of periods
params_buffer_size() #
unsigned int Get the buffer size (in frames) from the hw params
Parameters
const struct snd_pcm_hw_params *p: hw params
Return
the buffer size in frames
params_buffer_bytes() #
unsigned int Get the buffer size (in bytes) from the hw params
Parameters
const struct snd_pcm_hw_params *p: hw params
Return
the buffer size in bytes
snd_pcm_hw_constraint_single() #
int Constrain parameter to a single value
Parameters
struct snd_pcm_runtime *runtime: PCM runtime instancesnd_pcm_hw_param_t var: The hw_params variable to constrainunsigned int val: The value to constrain to
Return
Positive if the value is changed, zero if it's not changed, or a negative error code.
snd_pcm_format_cpu_endian() #
int Check the PCM format is CPU-endian
Parameters
snd_pcm_format_t format: the format to check
Return
1 if the given PCM format is CPU-endian, 0 if opposite, or a negative error code if endian not specified.
snd_pcm_set_sync() #
void set the PCM sync id
Parameters
struct snd_pcm_substream *substream: the pcm substream
Description
Use the default PCM sync identifier for the specific card.
snd_pcm_set_runtime_buffer() #
void Set the PCM runtime buffer
Parameters
struct snd_pcm_substream *substream: PCM substream to setstruct snd_dma_buffer *bufp: the buffer information, NULL to clear
Description
Copy the buffer information to runtime->dma_buffer when bufp is non-NULL. Otherwise it clears the current buffer information.
snd_pcm_gettime() #
void Fill the timespec64 depending on the timestamp mode
Parameters
struct snd_pcm_runtime *runtime: PCM runtime instancestruct timespec64 *tv: timespec64 to fill
snd_pcm_set_fixed_buffer() #
int Preallocate and set up the fixed size PCM buffer
Parameters
struct snd_pcm_substream *substream: the pcm substream instanceint type: DMA type (SNDRV_DMA_TYPE_*)struct device *data: DMA type dependent datasize_t size: the requested pre-allocation size in bytes
Description
This is a variant of snd_pcm_set_managed_buffer(), but this pre-allocates
only the given sized buffer and doesn't allow re-allocation nor dynamic
allocation of a larger buffer unlike the standard one.
The function may return -ENOMEM error, hence the caller must check it.
Return
zero if successful, or a negative error code
snd_pcm_set_fixed_buffer_all() #
int Preallocate and set up the fixed size PCM buffer
Parameters
struct snd_pcm *pcm: the pcm instanceint type: DMA type (SNDRV_DMA_TYPE_*)struct device *data: DMA type dependent datasize_t size: the requested pre-allocation size in bytes
Description
Apply the set up of the fixed buffer via snd_pcm_set_fixed_buffer() for
all substream. If any of allocation fails, it returns -ENOMEM, hence the
caller must check the return value.
Return
zero if successful, or a negative error code
snd_pcm_sgbuf_get_addr() #
dma_addr_t Get the DMA address at the corresponding offset
Parameters
struct snd_pcm_substream *substream: PCM substreamunsigned int ofs: byte offset
Return
DMA address
snd_pcm_sgbuf_get_chunk_size() #
unsigned int Compute the max size that fits within the contig. page from the given size
Parameters
struct snd_pcm_substream *substream: PCM substreamunsigned int ofs: byte offsetunsigned int size: byte size to examine
Return
chunk size
snd_pcm_limit_isa_dma_size() #
void Get the max size fitting with ISA DMA transfer
Parameters
int dma: DMA numbersize_t *max: pointer to store the max size
snd_pcm_direction_name() #
const char * Get a string naming the direction of a stream
Parameters
int direction: Stream's direction, one of SNDRV_PCM_STREAM_XXX
Description
Returns a string naming the direction of the stream.
snd_pcm_stream_str() #
const char * Get a string naming the direction of a stream
Parameters
struct snd_pcm_substream *substream: the pcm substream instance
Return
A string naming the direction of the stream.
snd_pcm_chmap_substream() #
struct snd_pcm_substream * get the PCM substream assigned to the given chmap info
Parameters
struct snd_pcm_chmap *info: chmap informationunsigned int idx: the substream number index
Return
the matched PCM substream, or NULL if not found
pcm_format_to_bits() #
u64 Strong-typed conversion of pcm_format to bitwise
Parameters
snd_pcm_format_t pcm_format: PCM format
Return
64bit mask corresponding to the given PCM format
pcm_for_each_format() #
helper to iterate for each format type
Parameters
f: the iterator variable in snd_pcm_format_t type
PCM Format Helpers #
snd_pcm_format_signed() #
int Check the PCM format is signed linear
Parameters
snd_pcm_format_t format: the format to check
Return
1 if the given PCM format is signed linear, 0 if unsigned linear, and a negative error code for non-linear formats.
snd_pcm_format_unsigned() #
int Check the PCM format is unsigned linear
Parameters
snd_pcm_format_t format: the format to check
Return
1 if the given PCM format is unsigned linear, 0 if signed linear, and a negative error code for non-linear formats.
snd_pcm_format_linear() #
int Check the PCM format is linear
Parameters
snd_pcm_format_t format: the format to check
Return
1 if the given PCM format is linear, 0 if not.
snd_pcm_format_little_endian() #
int Check the PCM format is little-endian
Parameters
snd_pcm_format_t format: the format to check
Return
1 if the given PCM format is little-endian, 0 if big-endian, or a negative error code if endian not specified.
snd_pcm_format_big_endian() #
int Check the PCM format is big-endian
Parameters
snd_pcm_format_t format: the format to check
Return
1 if the given PCM format is big-endian, 0 if little-endian, or a negative error code if endian not specified.
snd_pcm_format_width() #
int return the bit-width of the format
Parameters
snd_pcm_format_t format: the format to check
Return
The bit-width of the format, or a negative error code if unknown format.
snd_pcm_format_physical_width() #
int return the physical bit-width of the format
Parameters
snd_pcm_format_t format: the format to check
Return
The physical bit-width of the format, or a negative error code if unknown format.
snd_pcm_format_size() #
ssize_t return the byte size of samples on the given format
Parameters
snd_pcm_format_t format: the format to checksize_t samples: sampling rate
Return
The byte size of the given samples for the format, or a negative error code if unknown format.
snd_pcm_format_silence_64() #
const unsigned char * return the silent data in 8 bytes array
Parameters
snd_pcm_format_t format: the format to check
Return
The format pattern to fill or NULL if error.
snd_pcm_format_set_silence() #
int set the silence data on the buffer
Parameters
snd_pcm_format_t format: the PCM formatvoid *data: the buffer pointerunsigned int samples: the number of samples to set silence
Description
Sets the silence data on the buffer for the given samples.
Return
Zero if successful, or a negative error code on failure.
snd_pcm_hw_limit_rates() #
int determine rate_min/rate_max fields
Parameters
struct snd_pcm_hardware *hw: the pcm hw instance
Description
Determines the rate_min and rate_max fields from the rates bits of the given hw.
Return
Zero if successful.
snd_pcm_rate_to_rate_bit() #
unsigned int converts sample rate to SNDRV_PCM_RATE_xxx bit
Parameters
unsigned int rate: the sample rate to convert
Return
The SNDRV_PCM_RATE_xxx flag that corresponds to the given rate, or SNDRV_PCM_RATE_KNOT for an unknown rate.
snd_pcm_rate_bit_to_rate() #
unsigned int converts SNDRV_PCM_RATE_xxx bit to sample rate
Parameters
unsigned int rate_bit: the rate bit to convert
Return
The sample rate that corresponds to the given SNDRV_PCM_RATE_xxx flag or 0 for an unknown rate bit.
snd_pcm_rate_mask_intersect() #
unsigned int computes the intersection between two rate masks
Parameters
unsigned int rates_a: The first rate maskunsigned int rates_b: The second rate mask
Description
This function computes the rates that are supported by both rate masks passed to the function. It will take care of the special handling of SNDRV_PCM_RATE_CONTINUOUS and SNDRV_PCM_RATE_KNOT.
Return
A rate mask containing the rates that are supported by both rates_a and rates_b.
PCM Memory Management #
snd_pcm_lib_preallocate_free() #
void release the preallocated buffer of the specified substream.
Parameters
struct snd_pcm_substream *substream: the pcm substream instance
Description
Releases the pre-allocated buffer of the given substream.
snd_pcm_lib_preallocate_free_for_all() #
void release all pre-allocated buffers on the pcm
Parameters
struct snd_pcm *pcm: the pcm instance
Description
Releases all the pre-allocated buffers on the given pcm.
snd_pcm_lib_preallocate_pages() #
void pre-allocation for the given DMA type
Parameters
struct snd_pcm_substream *substream: the pcm substream instanceint type: DMA type (SNDRV_DMA_TYPE_*)struct device *data: DMA type dependent datasize_t size: the requested pre-allocation size in bytessize_t max: the max. allowed pre-allocation size
Description
Do pre-allocation for the given DMA buffer type.
snd_pcm_lib_preallocate_pages_for_all() #
void pre-allocation for continuous memory type (all substreams)
Parameters
struct snd_pcm *pcm: the pcm instanceint type: DMA type (SNDRV_DMA_TYPE_*)void *data: DMA type dependent datasize_t size: the requested pre-allocation size in bytessize_t max: the max. allowed pre-allocation size
Description
Do pre-allocation to all substreams of the given pcm for the specified DMA type.
snd_pcm_set_managed_buffer() #
int set up buffer management for a substream
Parameters
struct snd_pcm_substream *substream: the pcm substream instanceint type: DMA type (SNDRV_DMA_TYPE_*)struct device *data: DMA type dependent datasize_t size: the requested pre-allocation size in bytessize_t max: the max. allowed pre-allocation size
Description
Do pre-allocation for the given DMA buffer type, and set the managed buffer allocation mode to the given substream. In this mode, PCM core will allocate a buffer automatically before PCM hw_params ops call, and release the buffer after PCM hw_free ops call as well, so that the driver doesn't need to invoke the allocation and the release explicitly in its callback. When a buffer is actually allocated before the PCM hw_params call, it turns on the runtime buffer_changed flag for drivers changing their h/w parameters accordingly.
When size is non-zero and max is zero, this tries to allocate for only
the exact buffer size without fallback, and may return -ENOMEM.
Otherwise, the function tries to allocate smaller chunks if the allocation
fails. This is the behavior of snd_pcm_set_fixed_buffer().
When both size and max are zero, the function only sets up the buffer for later dynamic allocations. It's used typically for buffers with SNDRV_DMA_TYPE_VMALLOC type.
Upon successful buffer allocation and setup, the function returns 0.
Return
zero if successful, or a negative error code
snd_pcm_set_managed_buffer_all() #
int set up buffer management for all substreams for all substreams
Parameters
struct snd_pcm *pcm: the pcm instanceint type: DMA type (SNDRV_DMA_TYPE_*)struct device *data: DMA type dependent datasize_t size: the requested pre-allocation size in bytessize_t max: the max. allowed pre-allocation size
Description
Do pre-allocation to all substreams of the given pcm for the specified DMA type and size, and set the managed_buffer_alloc flag to each substream.
Return
zero if successful, or a negative error code
snd_pcm_lib_malloc_pages() #
int allocate the DMA buffer
Parameters
struct snd_pcm_substream *substream: the substream to allocate the DMA buffer tosize_t size: the requested buffer size in bytes
Description
Allocates the DMA buffer on the BUS type given earlier to
snd_pcm_lib_preallocate_xxx_pages().
Return
1 if the buffer is changed, 0 if not changed, or a negative code on failure.
snd_pcm_lib_free_pages() #
int release the allocated DMA buffer.
Parameters
struct snd_pcm_substream *substream: the substream to release the DMA buffer
Description
Releases the DMA buffer allocated via snd_pcm_lib_malloc_pages().
Return
Zero if successful, or a negative error code on failure.
PCM DMA Engine API #
snd_hwparams_to_dma_slave_config() #
int Convert hw_params to dma_slave_config
Parameters
const struct snd_pcm_substream *substream: PCM substreamconst struct snd_pcm_hw_params *params: hw_paramsstruct dma_slave_config *slave_config: DMA slave config
Description
This function can be used to initialize a dma_slave_config from a substream and hw_params in a dmaengine based PCM driver implementation.
Return
zero if successful, or a negative error code
snd_dmaengine_pcm_set_config_from_dai_data() #
void Initializes a dma slave config using DAI DMA data.
Parameters
const struct snd_pcm_substream *substream: PCM substreamconst struct snd_dmaengine_dai_dma_data *dma_data: DAI DMA datastruct dma_slave_config *slave_config: DMA slave configuration
Description
Initializes the {dst,src}_addr, {dst,src}_maxburst, {dst,src}_addr_width fields of the DMA slave config from the same fields of the DAI DMA data struct. The src and dst fields will be initialized depending on the direction of the substream. If the substream is a playback stream the dst fields will be initialized, if it is a capture stream the src fields will be initialized. The {dst,src}_addr_width field will only be initialized if the SND_DMAENGINE_PCM_DAI_FLAG_PACK flag is set or if the addr_width field of the DAI DMA data struct is not equal to DMA_SLAVE_BUSWIDTH_UNDEFINED. If both conditions are met the latter takes priority.
snd_dmaengine_pcm_trigger() #
int dmaengine based PCM trigger implementation
Parameters
struct snd_pcm_substream *substream: PCM substreamint cmd: Trigger command
Description
This function can be used as the PCM trigger callback for dmaengine based PCM driver implementations.
Return
0 on success, a negative error code otherwise
snd_dmaengine_pcm_pointer_no_residue() #
snd_pcm_uframes_t dmaengine based PCM pointer implementation
Parameters
struct snd_pcm_substream *substream: PCM substream
Description
This function is deprecated and should not be used by new drivers, as its results may be unreliable.
Return
PCM position in frames
snd_dmaengine_pcm_pointer() #
snd_pcm_uframes_t dmaengine based PCM pointer implementation
Parameters
struct snd_pcm_substream *substream: PCM substream
Description
This function can be used as the PCM pointer callback for dmaengine based PCM driver implementations.
Return
PCM position in frames
snd_dmaengine_pcm_request_channel() #
struct dma_chan * Request channel for the dmaengine PCM
Parameters
dma_filter_fn filter_fn: Filter function used to request the DMA channelvoid *filter_data: Data passed to the DMA filter function
Description
This function request a DMA channel for usage with dmaengine PCM.
Return
NULL or the requested DMA channel
snd_dmaengine_pcm_open() #
int Open a dmaengine based PCM substream
Parameters
struct snd_pcm_substream *substream: PCM substreamstruct dma_chan *chan: DMA channel to use for data transfers
Description
The function should usually be called from the pcm open callback. Note that this function will use private_data field of the substream's runtime. So it is not available to your pcm driver implementation.
Return
0 on success, a negative error code otherwise
snd_dmaengine_pcm_close() #
int Close a dmaengine based PCM substream
Parameters
struct snd_pcm_substream *substream: PCM substream
Return
0 on success, a negative error code otherwise
snd_dmaengine_pcm_close_release_chan() #
int Close a dmaengine based PCM substream and release channel
Parameters
struct snd_pcm_substream *substream: PCM substream
Description
Releases the DMA channel associated with the PCM substream.
Return
zero if successful, or a negative error code
snd_dmaengine_pcm_refine_runtime_hwparams() #
int Refine runtime hw params
Parameters
struct snd_pcm_substream *substream: PCM substreamstruct snd_dmaengine_dai_dma_data *dma_data: DAI DMA datastruct snd_pcm_hardware *hw: PCM hw paramsstruct dma_chan *chan: DMA channel to use for data transfers
Description
This function will query DMA capability, then refine the pcm hardware parameters.
Return
0 on success, a negative error code otherwise
snd_pcm_substream_to_dma_direction() #
enum dma_transfer_direction Get dma_transfer_direction for a PCM substream
Parameters
const struct snd_pcm_substream *substream: PCM substream
Return
DMA transfer direction
struct snd_dmaengine_dai_dma_data #
DAI DMA configuration data
Definition
;
Members
addr: Address of the DAI data source or destination register.addr_width: Width of the DAI data source or destination register.maxburst: Maximum number of words(note: words, as in units of the src_addr_width member, not bytes) that can be send to or received from the DAI in one burst.filter_data: Custom DMA channel filter data, this will usually be used when requesting the DMA channel.chan_name: Custom channel name to use when requesting DMA channel.fifo_size: FIFO size of the DAI controller in bytesflags: PCM_DAI flags, only SND_DMAENGINE_PCM_DAI_FLAG_PACK for nowperipheral_config: peripheral configuration for programming peripheral for dmaengine transferperipheral_size: peripheral configuration buffer sizeport_window_size: The length of the register area in words the data need to be accessed on the device side. It is only used for devices which is using an area instead of a single register to send/receive the data. Typically the DMA loops in this area in order to transfer the data.
struct snd_dmaengine_pcm_config #
Configuration data for dmaengine based PCM
Definition
;
Members
prepare_slave_config: Callback used to fill in the DMA slave_config for a PCM substream. Will be called from the PCM drivers hwparams callback.compat_request_channel: Callback to request a DMA channel for platforms which do not use devicetree.process: Callback used to apply processing on samples transferred from/to user space.name: Component name. If null, dev_name will be used.compat_filter_fn: Will be used as the filter function when requesting a channel for platforms which do not use devicetree. The filter parameter will be the DAI's DMA data.dma_dev: If set, request DMA channel on this device rather than the DAI device.chan_names: If set, these custom DMA channel names will be requested at registration time.pcm_hardware: snd_pcm_hardware struct to be used for the PCM.prealloc_buffer_size: Size of the preallocated audio buffer.
Note
If both compat_request_channel and compat_filter_fn are set compat_request_channel will be used to request the channel and compat_filter_fn will be ignored. Otherwise the channel will be requested using dma_request_channel with compat_filter_fn as the filter function.
Control/Mixer API #
General Control Interface #
snd_ctl_notify() #
void Send notification to user-space for a control change
Parameters
struct snd_card *card: the card to send notificationunsigned int mask: the event mask, SNDRV_CTL_EVENT_*struct snd_ctl_elem_id *id: the ctl element id to send notification
Description
This function adds an event record with the given id and mask, appends to the list and wakes up the user-space for notification. This can be called in the atomic context.
snd_ctl_notify_one() #
void Send notification to user-space for a control change
Parameters
struct snd_card *card: the card to send notificationunsigned int mask: the event mask, SNDRV_CTL_EVENT_*struct snd_kcontrol *kctl: the pointer with the control instanceunsigned int ioff: the additional offset to the control index
Description
This function calls snd_ctl_notify() and does additional jobs
like LED state changes.
snd_ctl_new() #
int create a new control instance with some elements
Parameters
struct snd_kcontrol **kctl: the pointer to store new control instanceunsigned int count: the number of elements in this controlunsigned int access: the default access flags for elements in this controlstruct snd_ctl_file *file: given when locking these elements
Description
Allocates a memory object for a new control instance. The instance has elements as many as the given number (count). Each element has given access permissions (access). Each element is locked when file is given.
Return
0 on success, error code on failure
snd_ctl_new1() #
struct snd_kcontrol * create a control instance from the template
Parameters
const struct snd_kcontrol_new *ncontrol: the initialization recordvoid *private_data: the private data to set
Description
Allocates a new struct snd_kcontrol instance and initialize from the given template. When the access field of ncontrol is 0, it's assumed as READWRITE access. When the count field is 0, it's assumes as one.
Return
The pointer of the newly generated instance, or NULL on failure.
snd_ctl_free_one() #
void release the control instance
Parameters
struct snd_kcontrol *kcontrol: the control instance
Description
Releases the control instance created via snd_ctl_new()
or snd_ctl_new1().
Don't call this after the control was added to the card.
snd_ctl_add() #
int add the control instance to the card
Parameters
struct snd_card *card: the card instancestruct snd_kcontrol *kcontrol: the control instance to add
Description
Adds the control instance created via snd_ctl_new() or
snd_ctl_new1() to the given card. Assigns also an unique
numid used for fast search.
It frees automatically the control which cannot be added.
Return
Zero if successful, or a negative error code on failure.
snd_ctl_replace() #
int replace the control instance of the card
Parameters
struct snd_card *card: the card instancestruct snd_kcontrol *kcontrol: the control instance to replacebool add_on_replace: add the control if not already added
Description
Replaces the given control. If the given control does not exist and the add_on_replace flag is set, the control is added. If the control exists, it is destroyed first.
It frees automatically the control which cannot be added or replaced.
Return
Zero if successful, or a negative error code on failure.
snd_ctl_remove() #
int remove the control from the card and release it
Parameters
struct snd_card *card: the card instancestruct snd_kcontrol *kcontrol: the control instance to remove
Description
Removes the control from the card and then releases the instance.
You don't need to call snd_ctl_free_one().
Passing NULL to kcontrol argument is allowed as noop.
Note that this function takes card->controls_rwsem lock internally.
Return
0 if successful, or a negative error code on failure.
snd_ctl_remove_id() #
int remove the control of the given id and release it
Parameters
struct snd_card *card: the card instancestruct snd_ctl_elem_id *id: the control id to remove
Description
Finds the control instance with the given id, removes it from the card list and releases it.
Return
0 if successful, or a negative error code on failure.
snd_ctl_remove_user_ctl() #
int remove and release the unlocked user control
Parameters
struct snd_ctl_file * file: active control handlestruct snd_ctl_elem_id *id: the control id to remove
Description
Finds the control instance with the given id, removes it from the card list and releases it.
Return
0 if successful, or a negative error code on failure.
snd_ctl_activate_id() #
int activate/inactivate the control of the given id
Parameters
struct snd_card *card: the card instancestruct snd_ctl_elem_id *id: the control id to activate/inactivateint active: non-zero to activate
Description
Finds the control instance with the given id, and activate or inactivate the control together with notification, if changed. The given ID data is filled with full information.
Return
0 if unchanged, 1 if changed, or a negative error code on failure.
snd_ctl_rename_id() #
int replace the id of a control on the card
Parameters
struct snd_card *card: the card instancestruct snd_ctl_elem_id *src_id: the old idstruct snd_ctl_elem_id *dst_id: the new id
Description
Finds the control with the old id from the card, and replaces the id with the new one.
The function tries to keep the already assigned numid while replacing the rest.
Note that this function should be used only in the card initialization phase. Calling after the card instantiation may cause issues with user-space expecting persistent numids.
Return
Zero if successful, or a negative error code on failure.
snd_ctl_rename() #
void rename the control on the card
Parameters
struct snd_card *card: the card instancestruct snd_kcontrol *kctl: the control to renameconst char *name: the new name
Description
Renames the specified control on the card to the new name.
Note that this function takes card->controls_rwsem lock internally.
snd_ctl_find_numid() #
struct snd_kcontrol * find the control instance with the given number-id
Parameters
struct snd_card *card: the card instanceunsigned int numid: the number-id to search
Description
Finds the control instance with the given number-id from the card.
Note that this function takes card->controls_rwlock lock internally.
Return
The pointer of the instance if found, or NULL if not.
snd_ctl_find_id() #
struct snd_kcontrol * find the control instance with the given id
Parameters
struct snd_card *card: the card instanceconst struct snd_ctl_elem_id *id: the id to search
Description
Finds the control instance with the given id from the card.
Note that this function takes card->controls_rwlock lock internally.
Return
The pointer of the instance if found, or NULL if not.
snd_ctl_register_ioctl() #
int register the device-specific control-ioctls
Parameters
snd_kctl_ioctl_func_t fcn: ioctl callback function
Description
called from each device manager like pcm.c, hwdep.c, etc.
Return
zero if successful, or a negative error code
snd_ctl_register_ioctl_compat() #
int register the device-specific 32bit compat control-ioctls
Parameters
snd_kctl_ioctl_func_t fcn: ioctl callback function
Return
zero if successful, or a negative error code
snd_ctl_unregister_ioctl() #
int de-register the device-specific control-ioctls
Parameters
snd_kctl_ioctl_func_t fcn: ioctl callback function to unregister
Return
zero if successful, or a negative error code
snd_ctl_unregister_ioctl_compat() #
int de-register the device-specific compat 32bit control-ioctls
Parameters
snd_kctl_ioctl_func_t fcn: ioctl callback function to unregister
Return
zero if successful, or a negative error code
snd_ctl_request_layer() #
int request to use the layer
Parameters
const char *module_name: Name of the kernel module (NULL == build-in)
Return
zero if successful, or an error code when the module cannot be loaded
snd_ctl_register_layer() #
void register new control layer
Parameters
struct snd_ctl_layer_ops *lops: operation structure
Description
The new layer can track all control elements and do additional operations on top (like audio LED handling).
snd_ctl_disconnect_layer() #
void disconnect control layer
Parameters
struct snd_ctl_layer_ops *lops: operation structure
Description
It is expected that the information about tracked cards is freed before this call (the disconnect callback is not called here).
snd_ctl_boolean_mono_info() #
int Helper function for a standard boolean info callback with a mono channel
Parameters
struct snd_kcontrol *kcontrol: the kcontrol instancestruct snd_ctl_elem_info *uinfo: info to store
Description
This is a function that can be used as info callback for a standard boolean control with a single mono channel.
Return
Zero (always successful)
snd_ctl_boolean_stereo_info() #
int Helper function for a standard boolean info callback with stereo two channels
Parameters
struct snd_kcontrol *kcontrol: the kcontrol instancestruct snd_ctl_elem_info *uinfo: info to store
Description
This is a function that can be used as info callback for a standard boolean control with stereo two channels.
Return
Zero (always successful)
snd_ctl_enum_info() #
int fills the info structure for an enumerated control
Parameters
struct snd_ctl_elem_info *info: the structure to be filledunsigned int channels: the number of the control's channels; often oneunsigned int items: the number of control values; also the size of namesconst char *const names[]: an array containing the names of all control values
Description
Sets all required fields in info to their appropriate values. If the control's accessibility is not the default (readable and writable), the caller has to fill info->access.
Return
Zero (always successful)
AC97 Codec API #
snd_ac97_write() #
void write a value on the given register
Parameters
struct snd_ac97 *ac97: the ac97 instanceunsigned short reg: the register to changeunsigned short value: the value to set
Description
Writes a value on the given register. This will invoke the write
callback directly after the register check.
This function doesn't change the register cache unlike
#snd_ca97_write_cache(), so use this only when you don't want to
reflect the change to the suspend/resume state.
snd_ac97_read() #
unsigned short read a value from the given register
Parameters
struct snd_ac97 *ac97: the ac97 instanceunsigned short reg: the register to read
Description
Reads a value from the given register. This will invoke the read callback directly after the register check.
Return
The read value.
snd_ac97_write_cache() #
void write a value on the given register and update the cache
Parameters
struct snd_ac97 *ac97: the ac97 instanceunsigned short reg: the register to changeunsigned short value: the value to set
Description
Writes a value on the given register and updates the register cache. The cached values are used for the cached-read and the suspend/resume.
snd_ac97_update() #
int update the value on the given register
Parameters
struct snd_ac97 *ac97: the ac97 instanceunsigned short reg: the register to changeunsigned short value: the value to set
Description
Compares the value with the register cache and updates the value only when the value is changed.
Return
1 if the value is changed, 0 if no change, or a negative code on failure.
snd_ac97_update_bits() #
int update the bits on the given register
Parameters
struct snd_ac97 *ac97: the ac97 instanceunsigned short reg: the register to changeunsigned short mask: the bit-mask to changeunsigned short value: the value to set
Description
Updates the masked-bits on the given register only when the value is changed.
Return
1 if the bits are changed, 0 if no change, or a negative code on failure.
snd_ac97_get_short_name() #
const char * retrieve codec name
Parameters
struct snd_ac97 *ac97: the codec instance
Return
The short identifying name of the codec.
snd_ac97_bus() #
int create an AC97 bus component
Parameters
struct snd_card *card: the card instanceint num: the bus numberconst struct snd_ac97_bus_ops *ops: the bus callbacks tablevoid *private_data: private data pointer for the new instancestruct snd_ac97_bus **rbus: the pointer to store the new AC97 bus instance.
Description
Creates an AC97 bus component. An struct snd_ac97_bus instance is newly allocated and initialized.
The ops table must include valid callbacks (at least read and write). The other callbacks, wait and reset, are not mandatory.
The clock is set to 48000. If another clock is needed, set
(*rbus)->clock manually.
The AC97 bus instance is registered as a low-level device, so you don't have to release it manually.
Return
Zero if successful, or a negative error code on failure.
snd_ac97_mixer() #
int create an Codec97 component
Parameters
struct snd_ac97_bus *bus: the AC97 bus which codec is attached tostruct snd_ac97_template *template: the template of ac97, including index, callbacks and the private data.struct snd_ac97 **rac97: the pointer to store the new ac97 instance.
Description
Creates an Codec97 component. An struct snd_ac97 instance is newly allocated and initialized from the template. The codec is then initialized by the standard procedure.
The template must include the codec number (num) and address (addr), and the private data (private_data).
The ac97 instance is registered as a low-level device, so you don't have to release it manually.
Return
Zero if successful, or a negative error code on failure.
snd_ac97_update_power() #
int update the powerdown register
Parameters
struct snd_ac97 *ac97: the codec instanceint reg: the rate register, e.g. AC97_PCM_FRONT_DAC_RATEint powerup: non-zero when power up the part
Description
Update the AC97 powerdown register bits of the given part.
Return
Zero.
snd_ac97_suspend() #
void General suspend function for AC97 codec
Parameters
struct snd_ac97 *ac97: the ac97 instance
Description
Suspends the codec, power down the chip.
snd_ac97_resume() #
void General resume function for AC97 codec
Parameters
struct snd_ac97 *ac97: the ac97 instance
Description
Do the standard resume procedure, power up and restoring the old register values.
snd_ac97_tune_hardware() #
int tune up the hardware
Parameters
struct snd_ac97 *ac97: the ac97 instanceconst struct ac97_quirk *quirk: quirk listconst char *override: explicit quirk value (overrides the list if non-NULL)
Description
Do some workaround for each pci device, such as renaming of the headphone (true line-out) control as "Master". The quirk-list must be terminated with a zero-filled entry.
Return
Zero if successful, or a negative error code on failure.
snd_ac97_set_rate() #
int change the rate of the given input/output.
Parameters
struct snd_ac97 *ac97: the ac97 instanceint reg: the register to changeunsigned int rate: the sample rate to set
Description
Changes the rate of the given input/output on the codec. If the codec doesn't support VAR, the rate must be 48000 (except for SPDIF).
The valid registers are AC97_PCM_MIC_ADC_RATE, AC97_PCM_FRONT_DAC_RATE, AC97_PCM_LR_ADC_RATE. AC97_PCM_SURR_DAC_RATE and AC97_PCM_LFE_DAC_RATE are accepted if the codec supports them. AC97_SPDIF is accepted as a pseudo register to modify the SPDIF status bits.
Return
Zero if successful, or a negative error code on failure.
snd_ac97_pcm_assign() #
int assign AC97 slots to given PCM streams
Parameters
struct snd_ac97_bus *bus: the ac97 bus instanceunsigned short pcms_count: count of PCMs to be assignedconst struct ac97_pcm *pcms: PCMs to be assigned
Description
It assigns available AC97 slots for given PCMs. If none or only some slots are available, pcm->xxx.slots and pcm->xxx.rslots[] members are reduced and might be zero.
Return
Zero if successful, or a negative error code on failure.
snd_ac97_pcm_open() #
int opens the given AC97 pcm
Parameters
struct ac97_pcm *pcm: the ac97 pcm instanceunsigned int rate: rate in Hz, if codec does not support VRA, this value must be 48000Hzenum ac97_pcm_cfg cfg: output stream characteristicsunsigned short slots: a subset of allocated slots (snd_ac97_pcm_assign) for this pcm
Description
It locks the specified slots and sets the given rate to AC97 registers.
Return
Zero if successful, or a negative error code on failure.
snd_ac97_pcm_close() #
int closes the given AC97 pcm
Parameters
struct ac97_pcm *pcm: the ac97 pcm instance
Description
It frees the locked AC97 slots.
Return
Zero.
snd_ac97_pcm_double_rate_rules() #
int set double rate constraints
Parameters
struct snd_pcm_runtime *runtime: the runtime of the ac97 front playback pcm
Description
Installs the hardware constraint rules to prevent using double rates and more than two channels at the same time.
Return
Zero if successful, or a negative error code on failure.
Virtual Master Control API #
snd_ctl_add_followers() #
int add multiple followers to vmaster
Parameters
struct snd_card *card: card instancestruct snd_kcontrol *master: the target vmaster kcontrol objectconst char * const *list: NULL-terminated list of name strings of followers to be added
Description
Adds the multiple follower kcontrols with the given names. Returns 0 for success or a negative error code.
snd_ctl_make_virtual_master() #
struct snd_kcontrol * Create a virtual master control
Parameters
char *name: name string of the control element to createconst unsigned int *tlv: optional TLV int array for dB information
Description
Creates a virtual master control with the given name string.
After creating a vmaster element, you can add the follower controls
via snd_ctl_add_follower() or snd_ctl_add_follower_uncached().
The optional argument tlv can be used to specify the TLV information for dB scale of the master control. It should be a single element with #SNDRV_CTL_TLVT_DB_SCALE, #SNDRV_CTL_TLV_DB_MINMAX or #SNDRV_CTL_TLVT_DB_MINMAX_MUTE type, and should be the max 0dB.
Return
The created control element, or NULL for errors (ENOMEM).
snd_ctl_add_vmaster_hook() #
int Add a hook to a vmaster control
Parameters
struct snd_kcontrol *kcontrol: vmaster kctl elementvoid (*hook)(void *private_data, int): the hook functionvoid *private_data: the private_data pointer to be saved
Description
Adds the given hook to the vmaster control element so that it's called at each time when the value is changed.
Return
Zero.
snd_ctl_sync_vmaster() #
void Sync the vmaster followers and hook
Parameters
struct snd_kcontrol *kcontrol: vmaster kctl elementbool hook_only: sync only the hook
Description
Forcibly call the put callback of each follower and call the hook function to synchronize with the current value of the given vmaster element. NOP when NULL is passed to kcontrol.
snd_ctl_apply_vmaster_followers() #
int Apply function to each vmaster follower
Parameters
struct snd_kcontrol *kctl: vmaster kctl elementint (*func)(struct snd_kcontrol *vfollower, struct snd_kcontrol *follower, void *arg): function to applyvoid *arg: optional function argument
Description
Apply the function func to each follower kctl of the given vmaster kctl.
Return
0 if successful, or a negative error code
snd_ctl_find_id_mixer() #
struct snd_kcontrol * find the control instance with the given name string
Parameters
struct snd_card *card: the card instanceconst char *name: the name string
Description
Finds the control instance with the given name and SNDRV_CTL_ELEM_IFACE_MIXER. Other fields are set to zero.
This is merely a wrapper to snd_ctl_find_id().
Return
The pointer of the instance if found, or NULL if not.
snd_ctl_add_follower() #
int Add a virtual follower control
Parameters
struct snd_kcontrol *master: vmaster elementstruct snd_kcontrol *follower: follower element to add
Description
Add a virtual follower control to the given master element created via
snd_ctl_create_virtual_master() beforehand.
All followers must be the same type (returning the same information via info callback). The function doesn't check it, so it's your responsibility.
Also, some additional limitations: at most two channels, logarithmic volume control (dB level) thus no linear volume, master can only attenuate the volume without gain
Return
Zero if successful or a negative error code.
snd_ctl_add_follower_uncached() #
int Add a virtual follower control
Parameters
struct snd_kcontrol *master: vmaster elementstruct snd_kcontrol *follower: follower element to add
Description
Add a virtual follower control to the given master.
Unlike snd_ctl_add_follower(), the element added via this function
is supposed to have volatile values, and get callback is called
at each time queried from the master.
When the control peeks the hardware values directly and the value can be changed by other means than the put callback of the element, this function should be used to keep the value always up-to-date.
Return
Zero if successful or a negative error code.
MIDI API #
Raw MIDI API #
snd_rawmidi_receive() #
int receive the input data from the device
Parameters
struct snd_rawmidi_substream *substream: the rawmidi substreamconst unsigned char *buffer: the buffer pointerint count: the data size to read
Description
Reads the data from the internal buffer.
Return
The size of read data, or a negative error code on failure.
snd_rawmidi_transmit_empty() #
int check whether the output buffer is empty
Parameters
struct snd_rawmidi_substream *substream: the rawmidi substream
Return
1 if the internal output buffer is empty, 0 if not.
snd_rawmidi_transmit_peek() #
int copy data from the internal buffer
Parameters
struct snd_rawmidi_substream *substream: the rawmidi substreamunsigned char *buffer: the buffer pointerint count: data size to transfer
Description
Copies data from the internal output buffer to the given buffer.
Call this in the interrupt handler when the midi output is ready,
and call snd_rawmidi_transmit_ack() after the transmission is
finished.
Return
The size of copied data, or a negative error code on failure.
snd_rawmidi_transmit_ack() #
int acknowledge the transmission
Parameters
struct snd_rawmidi_substream *substream: the rawmidi substreamint count: the transferred count
Description
Advances the hardware pointer for the internal output buffer with the given size and updates the condition. Call after the transmission is finished.
Return
The advanced size if successful, or a negative error code on failure.
snd_rawmidi_transmit() #
int copy from the buffer to the device
Parameters
struct snd_rawmidi_substream *substream: the rawmidi substreamunsigned char *buffer: the buffer pointerint count: the data size to transfer
Description
Copies data from the buffer to the device and advances the pointer.
Return
The copied size if successful, or a negative error code on failure.
snd_rawmidi_proceed() #
int Discard the all pending bytes and proceed
Parameters
struct snd_rawmidi_substream *substream: rawmidi substream
Return
the number of discarded bytes
snd_rawmidi_new() #
int create a rawmidi instance
Parameters
struct snd_card *card: the card instancechar *id: the id stringint device: the device indexint output_count: the number of output streamsint input_count: the number of input streamsstruct snd_rawmidi **rrawmidi: the pointer to store the new rawmidi instance
Description
Creates a new rawmidi instance.
Use snd_rawmidi_set_ops() to set the operators to the new instance.
Return
Zero if successful, or a negative error code on failure.
snd_rawmidi_set_ops() #
void set the rawmidi operators
Parameters
struct snd_rawmidi *rmidi: the rawmidi instanceint stream: the stream direction, SNDRV_RAWMIDI_STREAM_XXXconst struct snd_rawmidi_ops *ops: the operator table
Description
Sets the rawmidi operators for the given stream direction.
MPU401-UART API #
snd_mpu401_uart_interrupt() #
irqreturn_t generic MPU401-UART interrupt handler
Parameters
int irq: the irq numbervoid *dev_id: mpu401 instance
Description
Processes the interrupt for MPU401-UART i/o.
Return
IRQ_HANDLED if the interrupt was handled. IRQ_NONE otherwise.
snd_mpu401_uart_interrupt_tx() #
irqreturn_t generic MPU401-UART transmit irq handler
Parameters
int irq: the irq numbervoid *dev_id: mpu401 instance
Description
Processes the interrupt for MPU401-UART output.
Return
IRQ_HANDLED if the interrupt was handled. IRQ_NONE otherwise.
snd_mpu401_uart_new() #
int create an MPU401-UART instance
Parameters
struct snd_card *card: the card instanceint device: the device index, zero-basedunsigned short hardware: the hardware type, MPU401_HW_XXXXunsigned long port: the base address of MPU401 portunsigned int info_flags: bitflags MPU401_INFO_XXXint irq: the ISA irq number, -1 if not to be allocatedstruct snd_rawmidi ** rrawmidi: the pointer to store the new rawmidi instance
Description
Creates a new MPU-401 instance.
Note that the rawmidi instance is returned on the rrawmidi argument, not the mpu401 instance itself. To access to the mpu401 instance, cast from rawmidi->private_data (with struct snd_mpu401 magic-cast).
Return
Zero if successful, or a negative error code.
Proc Info API #
Proc Info Interface #
snd_info_get_line() #
int read one line from the procfs buffer
Parameters
struct snd_info_buffer *buffer: the procfs bufferchar *line: the buffer to storeint len: the max. buffer size
Description
Reads one line from the buffer and stores the string.
Return
Zero if successful, or 1 if error or EOF.
snd_info_get_str() #
const char * parse a string token
Parameters
char *dest: the buffer to store the string tokenconst char *src: the original stringint len: the max. length of token - 1
Description
Parses the original string and copy a token to the given string buffer.
Return
The updated pointer of the original string so that it can be used for the next call.
snd_info_create_module_entry() #
struct snd_info_entry * create an info entry for the given module
Parameters
struct module * module: the module pointerconst char *name: the file namestruct snd_info_entry *parent: the parent directory
Description
Creates a new info entry and assigns it to the given module.
Return
The pointer of the new instance, or NULL on failure.
snd_info_create_card_entry() #
struct snd_info_entry * create an info entry for the given card
Parameters
struct snd_card *card: the card instanceconst char *name: the file namestruct snd_info_entry * parent: the parent directory
Description
Creates a new info entry and assigns it to the given card.
Return
The pointer of the new instance, or NULL on failure.
snd_info_free_entry() #
void release the info entry
Parameters
struct snd_info_entry * entry: the info entry
Description
Releases the info entry.
snd_info_register() #
int register the info entry
Parameters
struct snd_info_entry *entry: the info entry
Description
Registers the proc info entry. The all children entries are registered recursively.
Return
Zero if successful, or a negative error code on failure.
snd_card_rw_proc_new() #
int Create a read/write text proc file entry for the card
Parameters
struct snd_card *card: the card instanceconst char *name: the file namevoid *private_data: the arbitrary private datavoid (*read)(struct snd_info_entry *, struct snd_info_buffer *): the read callbackvoid (*write)(struct snd_info_entry *entry, struct snd_info_buffer *buffer): the write callback, NULL for read-only
Description
This proc file entry will be registered via snd_card_register() call, and
it will be removed automatically at the card removal, too.
Return
zero if successful, or a negative error code
Compress Offload #
Compress Offload API #
snd_compr_stop_error() #
int Report a fatal error on a stream
Parameters
struct snd_compr_stream *stream: pointer to streamsnd_pcm_state_t state: state to transition the stream to
Description
Stop the stream and set its state.
Should be called with compressed device lock held.
Return
zero if successful, or a negative error code
snd_compr_task_finished() #
void Notify that the task was finished
Parameters
struct snd_compr_stream *stream: pointer to streamstruct snd_compr_task_runtime *task: runtime task structure
Description
Set the finished task state and notify waiters.
snd_compress_new() #
int create new compress device
Parameters
struct snd_card *card: sound card pointerint device: device numberint dirn: device direction, should be of type enum snd_compr_directionconst char *id: ID stringstruct snd_compr *compr: compress device pointer
Return
zero if successful, or a negative error code
struct snd_compressed_buffer #
compressed buffer
Definition
;
Members
fragment_size: size of buffer fragment in bytesfragments: number of such fragments
struct snd_compr_params #
compressed stream params
Definition
;
Members
buffer: buffer descriptioncodec: codec parametersno_wake_mode: dont wake on fragment elapsed
struct snd_compr_tstamp #
timestamp descriptor
Definition
;
Members
byte_offset: Byte offset in ring buffer to DSPcopied_total: Total number of bytes copied from/to ring buffer to/by DSPpcm_frames: Frames decoded or encoded by DSP. This field will evolve by large steps and should only be used to monitor encoding/decoding progress. It shall not be used for timing estimates.pcm_io_frames: Frames rendered or received by DSP into a mixer or an audio output/input. This field should be used for A/V sync or time estimates.sampling_rate: sampling rate of audio
struct snd_compr_tstamp64 #
timestamp descriptor with fields in 64 bit
Definition
;
Members
byte_offset: Byte offset in ring buffer to DSPcopied_total: Total number of bytes copied from/to ring buffer to/by DSPpcm_frames: Frames decoded or encoded by DSP. This field will evolve by large steps and should only be used to monitor encoding/decoding progress. It shall not be used for timing estimates.pcm_io_frames: Frames rendered or received by DSP into a mixer or an audio output/input. This field should be used for A/V sync or time estimates.sampling_rate: sampling rate of audio
struct snd_compr_avail #
avail descriptor
Definition
;
Members
avail: Number of bytes available in ring buffer for writing/readingtstamp: timestamp information
struct snd_compr_avail64 #
avail descriptor with tstamp in 64 bit format
Definition
;
Members
avail: Number of bytes available in ring buffer for writing/readingtstamp: timestamp information
struct snd_compr_caps #
caps descriptor
Definition
;
Members
num_codecs: number of codecs supporteddirection: direction supported. Of type snd_compr_directionmin_fragment_size: minimum fragment supported by DSPmax_fragment_size: maximum fragment supported by DSPmin_fragments: min fragments supported by DSPmax_fragments: max fragments supported by DSPcodecs: pointer to array of codecsreserved: reserved field
struct snd_compr_codec_caps #
query capability of codec
Definition
;
Members
codec: codec for which capability is queriednum_descriptors: number of codec descriptorsdescriptor: array of codec capability descriptor
enum sndrv_compress_encoder #
encoder metadata key
Constants
SNDRV_COMPRESS_ENCODER_PADDING: no of samples appended by the encoder at the end of the trackSNDRV_COMPRESS_ENCODER_DELAY: no of samples inserted by the encoder at the beginning of the track
struct snd_compr_metadata #
compressed stream metadata
Definition
;
Members
key: key idvalue: key value
struct snd_compr_task #
task primitive for non-realtime operation
Definition
;
Members
seqno: sequence number (task identifier)origin_seqno: previous sequence number (task identifier) - for reuseinput_fd: data input file descriptor (dma-buf)output_fd: data output file descriptor (dma-buf)input_size: filled data in bytes (from caller, must not exceed fragment size)flags: see SND_COMPRESS_TFLG_* definesreserved: reserved for future extension
enum snd_compr_state #
task state
Constants
SND_COMPRESS_TASK_STATE_IDLE: task is not queuedSND_COMPRESS_TASK_STATE_ACTIVE: task is in the queueSND_COMPRESS_TASK_STATE_FINISHED: task was processed, output is available
struct snd_compr_task_status #
task status
Definition
;
Members
seqno: sequence number (task identifier)input_size: filled data in bytes (from user space)output_size: filled data in bytes (from driver)output_flags: reserved for future (all zeros - from driver)state: actual task state (SND_COMPRESS_TASK_STATE_*)reserved: reserved for future extension
struct snd_enc_vorbis #
Vorbis encoder parameters
Definition
;
Members
quality: Sets encoding quality to n, between -1 (low) and 10 (high). In the default mode of operation, the quality level is 3. Normal quality range is 0 - 10.managed: Boolean. Set bitrate management mode. This turns off the normal VBR encoding, but allows hard or soft bitrate constraints to be enforced by the encoder. This mode can be slower, and may also be lower quality. It is primarily useful for streaming.max_bit_rate: Enabled only if managed is TRUEmin_bit_rate: Enabled only if managed is TRUEdownmix: Boolean. Downmix input from stereo to mono (has no effect on non-stereo streams). Useful for lower-bitrate encoding.
Description
These options were extracted from the OpenMAX IL spec and Gstreamer vorbisenc properties
For best quality users should specify VBR mode and set quality levels.
struct snd_enc_real #
RealAudio encoder parameters
Definition
;
Members
quant_bits: number of coupling quantization bits in the streamstart_region: coupling start region in the streamnum_regions: number of regions value
Description
These options were extracted from the OpenMAX IL spec
struct snd_enc_flac #
FLAC encoder parameters
Definition
;
Members
num: serial number, valid only for OGG formats needs to be set by applicationgain: Add replay gain tags
Description
These options were extracted from the FLAC online documentation at http://flac.sourceforge.net/documentation_tools_flac.html
To make the API simpler, it is assumed that the user will select quality profiles. Additional options that affect encoding quality and speed can be added at a later stage if needed.
By default the Subset format is used by encoders.
TAGS such as pictures, etc, cannot be handled by an offloaded encoder and are not supported in this API.
struct snd_dec_opus #
Opus decoder parameters (raw opus packets)
Definition
;
Members
version: Usually should be '1' but can be split into major (4 upper bits) and minor (4 lower bits) sub-fields.num_channels: Number of output channels.pre_skip: Number of samples to discard at 48 kHz.sample_rate: Sample rate of original input.output_gain: Gain to apply when decoding (in Q7.8 format).mapping_family: Order and meaning of output channels. Only values 0 and 1 are expected; values 2..255 are not recommended for playback.chan_map: Optional channel mapping table. Describes mapping of opus streams to decoded channels. Fields:chan_map.stream_count: Number of streams encoded in each Ogg packet.chan_map.coupled_count: Number of streams whose decoders are used for two channels.chan_map.channel_map: Which decoded channel to be used for each one. Supports only mapping families 0 and 1, max number of channels is 8.
Description
These options were extracted from RFC7845 Section 5.
struct snd_compr_task_runtime #
task runtime description
Definition
;
Members
list: list of all managed tasksinput: input DMA bufferoutput: output DMA bufferseqno: sequence numberinput_size: really used data in the input bufferoutput_size: really used data in the output bufferflags: see SND_COMPRESS_TFLG_*state: actual task stateprivate_value: used by the lowlevel driver (opaque)
struct snd_compr_runtime #
runtime stream description
Definition
;
Members
state: stream stateops: pointer to DSP callbacksbuffer: pointer to kernel buffer, valid only when not in mmap mode or DSP doesn't implement copybuffer_size: size of the above bufferfragment_size: size of buffer fragment in bytesfragments: number of such fragmentstotal_bytes_available: cumulative number of bytes made available in the ring buffertotal_bytes_transferred: cumulative bytes transferred by offload DSPsleep: poll sleepprivate_data: driver private data pointerdma_area: virtual buffer addressdma_addr: physical buffer address (not accessible from main CPU)dma_bytes: size of DMA areadma_buffer_p: runtime dma buffer pointeractive_tasks: count of active taskstotal_tasks: count of all taskstask_seqno: last task sequence number (!= 0)tasks: list of all tasks
struct snd_compr_stream #
compressed stream
Definition
;
Members
name: device nameops: pointer to DSP callbacksruntime: pointer to runtime structuredevice: device pointererror_work: delayed work used when closing the stream due to an errordirection: stream direction, playback/recordingmetadata_set: metadata set flag, true when setnext_track: has userspace signal next track transition, true when setpartial_drain: undergoing partial_drain for stream, true when setpause_in_draining: paused during draining state, true when setprivate_data: pointer to DSP private datadma_buffer: allocated buffer if any
struct snd_compr_ops #
compressed path DSP operations
Definition
;
Members
open: Open the compressed stream This callback is mandatory and shall keep dsp ready to receive the stream parameterfree: Close the compressed stream, mandatoryset_params: Sets the compressed stream parameters, mandatory This can be called in during stream creation only to set codec params and the stream propertiesget_params: retrieve the codec parameters, mandatoryset_metadata: Set the metadata values for a streamget_metadata: retrieves the requested metadata values from streamtrigger: Trigger operations like start, pause, resume, drain, stop. This callback is mandatorypointer: Retrieve current h/w pointer information. Mandatorycopy: Copy the compressed data to/from userspace, Optional Can't be implemented if DSP supports mmapmmap: DSP mmap method to mmap DSP memoryack: Ack for DSP when data is written to audio buffer, Optional Not valid if copy is implementedget_caps: Retrieve DSP capabilities, mandatoryget_codec_caps: Retrieve capabilities for a specific codec, mandatorytask_create: Create a set of input/output buffers for accel operationstask_start: Start (queue) a task for accel operationstask_stop: Stop (dequeue) a task for accel operationstask_free: Free a set of input/output buffers for accel operations
struct snd_compr #
Compressed device
Definition
;
Members
name: DSP device namedev: associated device instanceops: pointer to DSP callbacksprivate_data: pointer to DSP pvt datacard: sound card pointerdirection: Playback or capture directionlock: device lockdevice: device iduse_pause_in_draining: allow pause in draining, true when set
snd_compr_use_pause_in_draining() #
void Allow pause and resume in draining state
Parameters
struct snd_compr_stream *substream: compress substream to set
Description
Allow pause and resume in draining state. Only HW driver supports this transition can call this API.
snd_compr_set_runtime_buffer() #
void Set the Compress runtime buffer
Parameters
struct snd_compr_stream *stream: compress stream to setstruct snd_dma_buffer *bufp: the buffer information, NULL to clear
Description
Copy the buffer information to runtime buffer when bufp is non-NULL. Otherwise it clears the current buffer information.
ASoC #
ASoC Core API #
snd_soc_find_dai() #
struct snd_soc_dai * Find a registered DAI
Parameters
const struct snd_soc_dai_link_component *dlc: name of the DAI or the DAI driver and optional component info to match
Description
This function will search all registered components and their DAIs to find the DAI of the same name. The component's of_node and name should also match if being specified.
Return
pointer of DAI, or NULL if not found.
snd_soc_remove_pcm_runtime() #
void Remove a pcm_runtime from card
Parameters
struct snd_soc_card *card: The ASoC card to which the pcm_runtime hasstruct snd_soc_pcm_runtime *rtd: The pcm_runtime to remove
Description
This function removes a pcm_runtime from the ASoC card.
snd_soc_add_pcm_runtime() #
int Add a pcm_runtime dynamically via dai_link
Parameters
struct snd_soc_card *card: The ASoC card to which the pcm_runtime is addedstruct snd_soc_dai_link *dai_link: The DAI link to find pcm_runtime
Description
This function adds a pcm_runtime ASoC card by using dai_link.
Note
Topology can use this API to add pcm_runtime when probing the topology component. And machine drivers can still define static DAI links in dai_link array.
snd_soc_runtime_set_dai_fmt() #
int Change DAI link format for a ASoC runtime
Parameters
struct snd_soc_pcm_runtime *rtd: The runtime for which the DAI link format should be changedunsigned int dai_fmt: The new DAI link format
Description
This function updates the DAI link format for all DAIs connected to the DAI link for the specified runtime.
Note
For setups with a static format set the dai_fmt field in the corresponding snd_dai_link struct instead of using this function.
Returns 0 on success, otherwise a negative error code.
snd_soc_set_dmi_name() #
int Register DMI names to card
Parameters
struct snd_soc_card *card: The card to register DMI names
Description
An Intel machine driver may be used by many different devices but are difficult for userspace to differentiate, since machine drivers usually use their own name as the card short name and leave the card long name blank. To differentiate such devices and fix bugs due to lack of device-specific configurations, this function allows DMI info to be used as the sound card long name, in the format of "vendor-product-version-board" (Character '-' is used to separate different DMI fields here). This will help the user space to load the device-specific Use Case Manager (UCM) configurations for the card.
Possible card long names may be: DellInc.-XPS139343-01-0310JH ASUSTeKCOMPUTERINC.-T100TA-1.0-T100TA Circuitco-MinnowboardMaxD0PLATFORM-D0-MinnowBoardMAX
This function also supports flavoring the card longname to provide the extra differentiation, like "vendor-product-version-board-flavor".
We only keep number and alphabet characters and a few separator characters in the card long name since UCM in the user space uses the card long names as card configuration directory names and AudoConf cannot support special characters like SPACE.
Returns 0 on success, otherwise a negative error code.
snd_soc_cnew() #
struct snd_kcontrol * create new control
Parameters
const struct snd_kcontrol_new *_template: control templatevoid *data: control private dataconst char *long_name: control long nameconst char *prefix: control name prefix
Description
Create a new mixer control from a template control.
Returns 0 for success, else error.
snd_soc_add_component_controls() #
int Add an array of controls to a component.
Parameters
struct snd_soc_component *component: Component to add controls toconst struct snd_kcontrol_new *controls: Array of controls to addunsigned int num_controls: Number of elements in the array
Return
0 for success, else error.
snd_soc_add_card_controls() #
int add an array of controls to a SoC card. Convenience function to add a list of controls.
Parameters
struct snd_soc_card *soc_card: SoC card to add controls toconst struct snd_kcontrol_new *controls: array of controls to addint num_controls: number of elements in the array
Description
Return 0 for success, else error.
snd_soc_add_dai_controls() #
int add an array of controls to a DAI. Convenience function to add a list of controls.
Parameters
struct snd_soc_dai *dai: DAI to add controls toconst struct snd_kcontrol_new *controls: array of controls to addint num_controls: number of elements in the array
Description
Return 0 for success, else error.
snd_soc_register_card() #
int Register a card with the ASoC core
Parameters
struct snd_soc_card *card: Card to register
snd_soc_unregister_card() #
void Unregister a card with the ASoC core
Parameters
struct snd_soc_card *card: Card to unregister
snd_soc_register_dai() #
struct snd_soc_dai * Register a DAI dynamically & create its widgets
Parameters
struct snd_soc_component *component: The component the DAIs are registered forstruct snd_soc_dai_driver *dai_drv: DAI driver to use for the DAIbool legacy_dai_naming: iftrue, use legacy single-name format; iffalse, use multiple-name format;
Description
Topology can use this API to register DAIs when probing a component. These DAIs's widgets will be freed in the card cleanup and the DAIs will be freed in the component cleanup.
snd_soc_unregister_dais() #
void Unregister DAIs from the ASoC core
Parameters
struct snd_soc_component *component: The component for which the DAIs should be unregistered
snd_soc_register_dais() #
int Register a DAI with the ASoC core
Parameters
struct snd_soc_component *component: The component the DAIs are registered forstruct snd_soc_dai_driver *dai_drv: DAI driver to use for the DAIssize_t count: Number of DAIs
snd_soc_unregister_component_by_driver() #
void Unregister component using a given driver from the ASoC core
Parameters
struct device *dev: The device to unregisterconst struct snd_soc_component_driver *component_driver: The component driver to unregister
devm_snd_soc_register_component() #
int resource managed component registration
Parameters
struct device *dev: Device used to manage componentconst struct snd_soc_component_driver *cmpnt_drv: Component driverstruct snd_soc_dai_driver *dai_drv: DAI driverint num_dai: Number of DAIs to register
Description
Register a component with automatic unregistration when the device is unregistered.
devm_snd_soc_register_card() #
int resource managed card registration
Parameters
struct device *dev: Device used to manage cardstruct snd_soc_card *card: Card to register
Description
Register a card with automatic unregistration when the device is unregistered.
devm_snd_dmaengine_pcm_register() #
int resource managed dmaengine PCM registration
Parameters
struct device *dev: The parent device for the PCM deviceconst struct snd_dmaengine_pcm_config *config: Platform specific PCM configurationunsigned int flags: Platform specific quirks
Description
Register a dmaengine based PCM device with automatic unregistration when the device is unregistered.
snd_soc_component_set_sysclk() #
int configure COMPONENT system or master clock.
Parameters
struct snd_soc_component *component: COMPONENTint clk_id: DAI specific clock IDint source: Source for the clockunsigned int freq: new clock frequency in Hzint dir: new clock direction - input/output.
Description
Configures the CODEC master (MCLK) or system (SYSCLK) clocking.
snd_soc_component_set_jack() #
int configure component jack.
Parameters
struct snd_soc_component *component: COMPONENTsstruct snd_soc_jack *jack: structure to use for the jackvoid *data: can be used if codec driver need extra data for configuring jack
Description
Configures and enables jack detection function.
snd_soc_component_get_jack_type() #
int Parameters
struct snd_soc_component *component: COMPONENTs
Description
Returns the jack type of the component This can either be the supported type or one read from devicetree with the property: jack-type.
snd_soc_component_init_regmap() #
void Initialize regmap instance for the component
Parameters
struct snd_soc_component *component: The component for which to initialize the regmap instancestruct regmap *regmap: The regmap instance that should be used by the component
Description
This function allows deferred assignment of the regmap instance that is associated with the component. Only use this if the regmap instance is not yet ready when the component is registered. The function must also be called before the first IO attempt of the component.
snd_soc_component_exit_regmap() #
void De-initialize regmap instance for the component
Parameters
struct snd_soc_component *component: The component for which to de-initialize the regmap instance
Description
Calls regmap_exit() on the regmap instance associated to the component and
removes the regmap instance from the component.
This function should only be used if snd_soc_component_init_regmap() was used
to initialize the regmap instance.
snd_soc_component_read() #
unsigned int Read register value
Parameters
struct snd_soc_component *component: Component to read fromunsigned int reg: Register to read
Return
read value
snd_soc_component_write() #
int Write register value
Parameters
struct snd_soc_component *component: Component to write tounsigned int reg: Register to writeunsigned int val: Value to write to the register
Return
0 on success, a negative error code otherwise.
snd_soc_component_update_bits() #
int Perform read/modify/write cycle
Parameters
struct snd_soc_component *component: Component to updateunsigned int reg: Register to updateunsigned int mask: Mask that specifies which bits to updateunsigned int val: New value for the bits specified by mask
Return
1 if the operation was successful and the value of the register changed, 0 if the operation was successful, but the value did not change. Returns a negative error code otherwise.
snd_soc_component_update_bits_async() #
int Perform asynchronous read/modify/write cycle
Parameters
struct snd_soc_component *component: Component to updateunsigned int reg: Register to updateunsigned int mask: Mask that specifies which bits to updateunsigned int val: New value for the bits specified by mask
Description
This function is similar to snd_soc_component_update_bits(), but the update
operation is scheduled asynchronously. This means it may not be completed
when the function returns. To make sure that all scheduled updates have been
completed snd_soc_component_async_complete() must be called.
Return
1 if the operation was successful and the value of the register changed, 0 if the operation was successful, but the value did not change. Returns a negative error code otherwise.
snd_soc_component_read_field() #
unsigned int Read register field value
Parameters
struct snd_soc_component *component: Component to read fromunsigned int reg: Register to readunsigned int mask: mask of the register field
Return
read value of register field.
snd_soc_component_write_field() #
int write to register field
Parameters
struct snd_soc_component *component: Component to write tounsigned int reg: Register to writeunsigned int mask: mask of the register field to updateunsigned int val: value of the field to write
Return
1 for change, otherwise 0.
snd_soc_component_async_complete() #
void Ensure asynchronous I/O has completed
Parameters
struct snd_soc_component *component: Component for which to wait
Description
This function blocks until all asynchronous I/O which has previously been
scheduled using snd_soc_component_update_bits_async() has completed.
snd_soc_component_test_bits() #
int Test register for change
Parameters
struct snd_soc_component *component: componentunsigned int reg: Register to testunsigned int mask: Mask that specifies which bits to testunsigned int value: Value to test against
Description
Tests a register with a new value and checks if the new value is different from the old value.
Return
1 for change, otherwise 0.
snd_soc_runtime_action() #
void Increment/Decrement active count for PCM runtime components
Parameters
struct snd_soc_pcm_runtime *rtd: ASoC PCM runtime that is activatedint stream: Direction of the PCM streamint action: Activate stream if 1. Deactivate if -1.
Description
Increments/Decrements the active count for all the DAIs and components attached to a PCM runtime. Should typically be called when a stream is opened.
Must be called with the rtd->card->pcm_mutex being held
snd_soc_runtime_ignore_pmdown_time() #
bool Check whether to ignore the power down delay
Parameters
struct snd_soc_pcm_runtime *rtd: The ASoC PCM runtime that should be checked.
Description
This function checks whether the power down delay should be ignored for a specific PCM runtime. Returns true if the delay is 0, if the DAI link has been configured to ignore the delay, or if none of the components benefits from having the delay.
snd_soc_runtime_calc_hw() #
int Calculate hw limits for a PCM stream
Parameters
struct snd_soc_pcm_runtime *rtd: ASoC PCM runtimestruct snd_pcm_hardware *hw: PCM hardware parameters (output)int stream: Direction of the PCM stream
Description
Calculates the subset of stream parameters supported by all DAIs associated with the PCM stream.
snd_soc_info_enum_double() #
int enumerated double mixer info callback
Parameters
struct snd_kcontrol *kcontrol: mixer controlstruct snd_ctl_elem_info *uinfo: control element information
Description
Callback to provide information about a double enumerated mixer control.
Returns 0 for success.
snd_soc_get_enum_double() #
int enumerated double mixer get callback
Parameters
struct snd_kcontrol *kcontrol: mixer controlstruct snd_ctl_elem_value *ucontrol: control element information
Description
Callback to get the value of a double enumerated mixer.
Returns 0 for success.
snd_soc_put_enum_double() #
int enumerated double mixer put callback
Parameters
struct snd_kcontrol *kcontrol: mixer controlstruct snd_ctl_elem_value *ucontrol: control element information
Description
Callback to set the value of a double enumerated mixer.
Returns 0 for success.
snd_soc_info_volsw() #
int single mixer info callback with range.
Parameters
struct snd_kcontrol *kcontrol: mixer controlstruct snd_ctl_elem_info *uinfo: control element information
Description
Callback to provide information, with a range, about a single mixer control, or a double mixer control that spans 2 registers.
Returns 0 for success.
snd_soc_info_volsw_sx() #
int Mixer info callback for SX TLV controls
Parameters
struct snd_kcontrol *kcontrol: mixer controlstruct snd_ctl_elem_info *uinfo: control element information
Description
Callback to provide information about a single mixer control, or a double mixer control that spans 2 registers of the SX TLV type. SX TLV controls have a range that represents both positive and negative values either side of zero but without a sign bit. min is the minimum register value, max is the number of steps.
Returns 0 for success.
snd_soc_get_volsw() #
int single mixer get callback with range
Parameters
struct snd_kcontrol *kcontrol: mixer controlstruct snd_ctl_elem_value *ucontrol: control element information
Description
Callback to get the value, within a range, of a single mixer control, or a double mixer control that spans 2 registers.
Returns 0 for success.
snd_soc_put_volsw() #
int single mixer put callback with range
Parameters
struct snd_kcontrol *kcontrol: mixer controlstruct snd_ctl_elem_value *ucontrol: control element information
Description
Callback to set the value , within a range, of a single mixer control, or a double mixer control that spans 2 registers.
Returns 0 for success.
snd_soc_get_volsw_sx() #
int single mixer get callback
Parameters
struct snd_kcontrol *kcontrol: mixer controlstruct snd_ctl_elem_value *ucontrol: control element information
Description
Callback to get the value of a single mixer control, or a double mixer control that spans 2 registers.
Returns 0 for success.
snd_soc_put_volsw_sx() #
int double mixer set callback
Parameters
struct snd_kcontrol *kcontrol: mixer controlstruct snd_ctl_elem_value *ucontrol: control element information
Description
Callback to set the value of a double mixer control that spans 2 registers.
Returns 0 for success.
snd_soc_limit_volume() #
int Set new limit to an existing volume control.
Parameters
struct snd_soc_card *card: where to look for the controlconst char *name: Name of the controlint max: new maximum limit
Description
Return 0 for success, else error.
snd_soc_info_xr_sx() #
int signed multi register info callback
Parameters
struct snd_kcontrol *kcontrol: mreg controlstruct snd_ctl_elem_info *uinfo: control element information
Description
Callback to provide information of a control that can span multiple codec registers which together forms a single signed value. Note that unlike the non-xr variant of sx controls these may or may not include the sign bit, depending on nbits, and there is no shift.
Returns 0 for success.
snd_soc_get_xr_sx() #
int signed multi register get callback
Parameters
struct snd_kcontrol *kcontrol: mreg controlstruct snd_ctl_elem_value *ucontrol: control element information
Description
Callback to get the value of a control that can span multiple codec registers which together forms a single signed value. The control supports specifying total no of bits used to allow for bitfields across the multiple codec registers. Note that unlike the non-xr variant of sx controls these may or may not include the sign bit, depending on nbits, and there is no shift.
Returns 0 for success.
snd_soc_put_xr_sx() #
int signed multi register get callback
Parameters
struct snd_kcontrol *kcontrol: mreg controlstruct snd_ctl_elem_value *ucontrol: control element information
Description
Callback to set the value of a control that can span multiple codec registers which together forms a single signed value. The control supports specifying total no of bits used to allow for bitfields across the multiple codec registers. Note that unlike the non-xr variant of sx controls these may or may not include the sign bit, depending on nbits, and there is no shift.
Returns 0 for success.
snd_soc_get_strobe() #
int strobe get callback
Parameters
struct snd_kcontrol *kcontrol: mixer controlstruct snd_ctl_elem_value *ucontrol: control element information
Description
Callback get the value of a strobe mixer control.
Returns 0 for success.
snd_soc_put_strobe() #
int strobe put callback
Parameters
struct snd_kcontrol *kcontrol: mixer controlstruct snd_ctl_elem_value *ucontrol: control element information
Description
Callback strobe a register bit to high then low (or the inverse) in one pass of a single mixer enum control.
Returns 1 for success.
snd_soc_new_compress() #
int create a new compress.
Parameters
struct snd_soc_pcm_runtime *rtd: The runtime for which we will create compress
Return
0 for success, else error.
ASoC DAPM API #
snd_soc_dapm_kcontrol_to_widget() #
struct snd_soc_dapm_widget * Returns the widget associated to a kcontrol
Parameters
struct snd_kcontrol *kcontrol: The kcontrol
snd_soc_dapm_kcontrol_to_dapm() #
struct snd_soc_dapm_context * Returns the dapm context associated to a kcontrol
Parameters
struct snd_kcontrol *kcontrol: The kcontrol
Note
This function must only be used on kcontrols that are known to have been registered for a CODEC. Otherwise the behaviour is undefined.
snd_soc_dapm_kcontrol_to_component() #
struct snd_soc_component * Returns the component associated to a kcontrol
Parameters
struct snd_kcontrol *kcontrol: The kcontrol
Description
This function must only be used on DAPM contexts that are known to be part of a COMPONENT (e.g. in a COMPONENT driver). Otherwise the behavior is undefined
snd_soc_dapm_force_bias_level() #
int Sets the DAPM bias level
Parameters
struct snd_soc_dapm_context *dapm: The DAPM context for which to set the levelenum snd_soc_bias_level level: The level to set
Description
Forces the DAPM bias level to a specific state. It will call the bias level callback of DAPM context with the specified level. This will even happen if the context is already at the same level. Furthermore it will not go through the normal bias level sequencing, meaning any intermediate states between the current and the target state will not be entered.
Note that the change in bias level is only temporary and the next time
snd_soc_dapm_sync() is called the state will be set to the level as
determined by the DAPM core. The function is mainly intended to be used to
used during probe or resume from suspend to power up the device so
initialization can be done, before the DAPM core takes over.
snd_soc_dapm_init_bias_level() #
void Initialize DAPM bias level
Parameters
struct snd_soc_dapm_context *dapm: The DAPM context to initializeenum snd_soc_bias_level level: The DAPM level to initialize to
Description
This function only sets the driver internal state of the DAPM level and will not modify the state of the device. Hence it should not be used during normal operation, but only to synchronize the internal state to the device state. E.g. during driver probe to set the DAPM level to the one corresponding with the power-on reset state of the device.
To change the DAPM state of the device use snd_soc_dapm_set_bias_level().
snd_soc_dapm_set_bias_level() #
int set the bias level for the system
Parameters
struct snd_soc_dapm_context *dapm: DAPM contextenum snd_soc_bias_level level: level to configure
Description
Configure the bias (power) levels for the SoC audio device.
Returns 0 for success else error.
snd_soc_dapm_get_bias_level() #
enum snd_soc_bias_level Get current DAPM bias level
Parameters
struct snd_soc_dapm_context *dapm: The context for which to get the bias level
Return
The current bias level of the passed DAPM context.
snd_soc_dapm_dai_get_connected_widgets() #
int query audio path and it's widgets.
Parameters
struct snd_soc_dai *dai: the soc DAI.int stream: stream direction.struct snd_soc_dapm_widget_list **list: list of active widgets for this stream.bool (*custom_stop_condition)(struct snd_soc_dapm_widget *, enum snd_soc_dapm_direction): (optional) a function meant to stop the widget graph walk based on custom logic.
Description
Queries DAPM graph as to whether a valid audio stream path exists for the initial stream specified by name. This takes into account current mixer and mux kcontrol settings. Creates list of valid widgets.
Optionally, can be supplied with a function acting as a stopping condition. This function takes the dapm widget currently being examined and the walk direction as an arguments, it should return true if the walk should be stopped and false otherwise.
Returns the number of valid paths or negative error.
snd_soc_dapm_free_widget() #
void Free specified widget
Parameters
struct snd_soc_dapm_widget *w: widget to free
Description
Removes widget from all paths and frees memory occupied by it.
snd_soc_dapm_sync_unlocked() #
int scan and power dapm paths
Parameters
struct snd_soc_dapm_context *dapm: DAPM context
Description
Walks all dapm audio paths and powers widgets according to their stream or path usage.
Requires external locking.
Returns 0 for success.
snd_soc_dapm_sync() #
int scan and power dapm paths
Parameters
struct snd_soc_dapm_context *dapm: DAPM context
Description
Walks all dapm audio paths and powers widgets according to their stream or path usage.
Returns 0 for success.
snd_soc_dapm_add_routes() #
int Add routes between DAPM widgets
Parameters
struct snd_soc_dapm_context *dapm: DAPM contextconst struct snd_soc_dapm_route *route: audio routesint num: number of routes
Description
Connects 2 dapm widgets together via a named audio path. The sink is the widget receiving the audio signal, whilst the source is the sender of the audio signal.
Returns 0 for success else error. On error all resources can be freed
with a call to snd_soc_card_free().
snd_soc_dapm_del_routes() #
int Remove routes between DAPM widgets
Parameters
struct snd_soc_dapm_context *dapm: DAPM contextconst struct snd_soc_dapm_route *route: audio routesint num: number of routes
Description
Removes routes from the DAPM context.
snd_soc_dapm_new_widgets() #
int add new dapm widgets
Parameters
struct snd_soc_card *card: card to be checked for new dapm widgets
Description
Checks the codec for any new dapm widgets and creates them if found.
Returns 0 for success.
snd_soc_dapm_get_volsw() #
int dapm mixer get callback
Parameters
struct snd_kcontrol *kcontrol: mixer controlstruct snd_ctl_elem_value *ucontrol: control element information
Description
Callback to get the value of a dapm mixer control.
Returns 0 for success.
snd_soc_dapm_put_volsw() #
int dapm mixer set callback
Parameters
struct snd_kcontrol *kcontrol: mixer controlstruct snd_ctl_elem_value *ucontrol: control element information
Description
Callback to set the value of a dapm mixer control.
Returns 0 for success.
snd_soc_dapm_get_enum_double() #
int dapm enumerated double mixer get callback
Parameters
struct snd_kcontrol *kcontrol: mixer controlstruct snd_ctl_elem_value *ucontrol: control element information
Description
Callback to get the value of a dapm enumerated double mixer control.
Returns 0 for success.
snd_soc_dapm_put_enum_double() #
int dapm enumerated double mixer set callback
Parameters
struct snd_kcontrol *kcontrol: mixer controlstruct snd_ctl_elem_value *ucontrol: control element information
Description
Callback to set the value of a dapm enumerated double mixer control.
Returns 0 for success.
snd_soc_dapm_info_pin_switch() #
int Info for a pin switch
Parameters
struct snd_kcontrol *kcontrol: mixer controlstruct snd_ctl_elem_info *uinfo: control element information
Description
Callback to provide information about a pin switch control.
snd_soc_dapm_get_pin_switch() #
int Get information for a pin switch
Parameters
struct snd_kcontrol *kcontrol: mixer controlstruct snd_ctl_elem_value *ucontrol: Value
Description
Callback to provide information for a pin switch added at the card level.
snd_soc_dapm_get_component_pin_switch() #
int Get information for a pin switch
Parameters
struct snd_kcontrol *kcontrol: mixer controlstruct snd_ctl_elem_value *ucontrol: Value
Description
Callback to provide information for a pin switch added at the component level.
snd_soc_dapm_put_pin_switch() #
int Set information for a pin switch
Parameters
struct snd_kcontrol *kcontrol: mixer controlstruct snd_ctl_elem_value *ucontrol: Value
Description
Callback to provide information for a pin switch added at the card level.
snd_soc_dapm_put_component_pin_switch() #
int Set information for a pin switch
Parameters
struct snd_kcontrol *kcontrol: mixer controlstruct snd_ctl_elem_value *ucontrol: Value
Description
Callback to provide information for a pin switch added at the component level.
snd_soc_dapm_new_control() #
struct snd_soc_dapm_widget * create new dapm control
Parameters
struct snd_soc_dapm_context *dapm: DAPM contextconst struct snd_soc_dapm_widget *widget: widget template
Description
Creates new DAPM control based upon a template.
Returns a widget pointer on success or an error pointer on failure
snd_soc_dapm_new_controls() #
int create new dapm controls
Parameters
struct snd_soc_dapm_context *dapm: DAPM contextconst struct snd_soc_dapm_widget *widget: widget arrayunsigned int num: number of widgets
Description
Creates new DAPM controls based upon the templates.
Returns 0 for success else error.
snd_soc_dapm_new_dai_widgets() #
int Create new DAPM widgets
Parameters
struct snd_soc_dapm_context *dapm: DAPM contextstruct snd_soc_dai *dai: parent DAI
Description
Returns 0 on success, error code otherwise.
snd_soc_dapm_stream_event() #
void send a stream event to the dapm core
Parameters
struct snd_soc_pcm_runtime *rtd: PCM runtime dataint stream: stream nameint event: stream event
Description
Sends a stream event to the dapm core. The core then makes any necessary widget power changes.
Returns 0 for success else error.
snd_soc_dapm_enable_pin_unlocked() #
int enable pin.
Parameters
struct snd_soc_dapm_context *dapm: DAPM contextconst char *pin: pin name
Description
Enables input/output pin and its parents or children widgets iff there is a valid audio route and active audio stream.
Requires external locking.
NOTE
snd_soc_dapm_sync() needs to be called after this for DAPM to
do any widget power switching.
snd_soc_dapm_enable_pin() #
int enable pin.
Parameters
struct snd_soc_dapm_context *dapm: DAPM contextconst char *pin: pin name
Description
Enables input/output pin and its parents or children widgets iff there is a valid audio route and active audio stream.
NOTE
snd_soc_dapm_sync() needs to be called after this for DAPM to
do any widget power switching.
snd_soc_dapm_force_enable_pin_unlocked() #
int force a pin to be enabled
Parameters
struct snd_soc_dapm_context *dapm: DAPM contextconst char *pin: pin name
Description
Enables input/output pin regardless of any other state. This is intended for use with microphone bias supplies used in microphone jack detection.
Requires external locking.
NOTE
snd_soc_dapm_sync() needs to be called after this for DAPM to
do any widget power switching.
snd_soc_dapm_force_enable_pin() #
int force a pin to be enabled
Parameters
struct snd_soc_dapm_context *dapm: DAPM contextconst char *pin: pin name
Description
Enables input/output pin regardless of any other state. This is intended for use with microphone bias supplies used in microphone jack detection.
NOTE
snd_soc_dapm_sync() needs to be called after this for DAPM to
do any widget power switching.
snd_soc_dapm_disable_pin_unlocked() #
int disable pin.
Parameters
struct snd_soc_dapm_context *dapm: DAPM contextconst char *pin: pin name
Description
Disables input/output pin and its parents or children widgets.
Requires external locking.
NOTE
snd_soc_dapm_sync() needs to be called after this for DAPM to
do any widget power switching.
snd_soc_dapm_disable_pin() #
int disable pin.
Parameters
struct snd_soc_dapm_context *dapm: DAPM contextconst char *pin: pin name
Description
Disables input/output pin and its parents or children widgets.
NOTE
snd_soc_dapm_sync() needs to be called after this for DAPM to
do any widget power switching.
snd_soc_dapm_get_pin_status() #
int get audio pin status
Parameters
struct snd_soc_dapm_context *dapm: DAPM contextconst char *pin: audio signal pin endpoint (or start point)
Description
Get audio pin status - connected or disconnected.
Returns 1 for connected otherwise 0.
snd_soc_dapm_ignore_suspend() #
int ignore suspend status for DAPM endpoint
Parameters
struct snd_soc_dapm_context *dapm: DAPM contextconst char *pin: audio signal pin endpoint (or start point)
Description
Mark the given endpoint or pin as ignoring suspend. When the system is disabled a path between two endpoints flagged as ignoring suspend will not be disabled. The path must already be enabled via normal means at suspend time, it will not be turned on if it was not already enabled.
snd_soc_dapm_free() #
void free dapm resources
Parameters
struct snd_soc_dapm_context *dapm: DAPM context
Description
Free all dapm widgets and resources.
ASoC DMA Engine API #
snd_dmaengine_pcm_prepare_slave_config() #
int Generic prepare_slave_config callback
Parameters
struct snd_pcm_substream *substream: PCM substreamstruct snd_pcm_hw_params *params: hw_paramsstruct dma_slave_config *slave_config: DMA slave config to prepare
Description
This function can be used as a generic prepare_slave_config callback for platforms which make use of the snd_dmaengine_dai_dma_data struct for their DAI DMA data. Internally the function will first call snd_hwparams_to_dma_slave_config to fill in the slave config based on the hw_params, followed by snd_dmaengine_pcm_set_config_from_dai_data to fill in the remaining fields based on the DAI DMA data.
snd_dmaengine_pcm_register() #
int Register a dmaengine based PCM device
Parameters
struct device *dev: The parent device for the PCM deviceconst struct snd_dmaengine_pcm_config *config: Platform specific PCM configurationunsigned int flags: Platform specific quirks
snd_dmaengine_pcm_unregister() #
void Removes a dmaengine based PCM device
Parameters
struct device *dev: Parent device the PCM was register with
Description
Removes a dmaengine based PCM device previously registered with snd_dmaengine_pcm_register.
Miscellaneous Functions #
Hardware-Dependent Devices API #
snd_hwdep_new() #
int create a new hwdep instance
Parameters
struct snd_card *card: the card instancechar *id: the id stringint device: the device index (zero-based)struct snd_hwdep **rhwdep: the pointer to store the new hwdep instance
Description
Creates a new hwdep instance with the given index on the card. The callbacks (hwdep->ops) must be set on the returned instance after this call manually by the caller.
Return
Zero if successful, or a negative error code on failure.
Jack Abstraction Layer API #
enum snd_jack_types #
Jack types which can be reported
Constants
SND_JACK_HEADPHONE: HeadphoneSND_JACK_MICROPHONE: MicrophoneSND_JACK_HEADSET: HeadsetSND_JACK_LINEOUT: Line outSND_JACK_MECHANICAL: Mechanical switchSND_JACK_VIDEOOUT: Video outSND_JACK_AVOUT: AV (Audio Video) outSND_JACK_LINEIN: Line inSND_JACK_USB: USB audio deviceSND_JACK_BTN_0: Button 0SND_JACK_BTN_1: Button 1SND_JACK_BTN_2: Button 2SND_JACK_BTN_3: Button 3SND_JACK_BTN_4: Button 4SND_JACK_BTN_5: Button 5
Description
These values are used as a bitmask.
Note that this must be kept in sync with the lookup table in sound/core/jack.c.
snd_jack_add_new_kctl() #
int Create a new snd_jack_kctl and add it to jack
Parameters
struct snd_jack *jack: the jack instance which the kctl will attaching toconst char * name: the name for the snd_kcontrol objectint mask: a bitmask of enum snd_jack_type values that can be detected by this snd_jack_kctl object.
Description
Creates a new snd_kcontrol object and adds it to the jack kctl_list.
Return
Zero if successful, or a negative error code on failure.
snd_jack_new() #
int Create a new jack
Parameters
struct snd_card *card: the card instanceconst char *id: an identifying string for this jackint type: a bitmask of enum snd_jack_type values that can be detected by this jackstruct snd_jack **jjack: Used to provide the allocated jack object to the caller.bool initial_kctl: if true, create a kcontrol and add it to the jack list.bool phantom_jack: Don't create a input device for phantom jacks.
Description
Creates a new jack object.
Return
Zero if successful, or a negative error code on failure. On success jjack will be initialised.
snd_jack_set_key() #
int Set a key mapping on a jack
Parameters
struct snd_jack *jack: The jack to configureenum snd_jack_types type: Jack report type for this keyint keytype: Input layer key type to be reported
Description
Map a SND_JACK_BTN_* button type to an input layer key, allowing reporting of keys on accessories via the jack abstraction. If no mapping is provided but keys are enabled in the jack type then BTN_n numeric buttons will be reported.
If jacks are not reporting via the input API this call will have no effect.
Note that this is intended to be use by simple devices with small numbers of keys that can be reported. It is also possible to access the input device directly - devices with complex input capabilities on accessories should consider doing this rather than using this abstraction.
This function may only be called prior to registration of the jack.
Return
Zero if successful, or a negative error code on failure.
snd_jack_report() #
void Report the current status of a jack
Parameters
struct snd_jack *jack: The jack to report status forint status: The current status of the jack
Note
This function uses mutexes and should be called from a context which can sleep (such as a workqueue).
snd_soc_jack_report() #
void Report the current status for a jack
Parameters
struct snd_soc_jack *jack: the jackint status: a bitmask of enum snd_jack_type values that are currently detected.int mask: a bitmask of enum snd_jack_type values that being reported.
Description
If configured using snd_soc_jack_add_pins() then the associated
DAPM pins will be enabled or disabled as appropriate and DAPM
synchronised.
Note
This function uses mutexes and should be called from a context which can sleep (such as a workqueue).
snd_soc_jack_add_zones() #
int Associate voltage zones with jack
Parameters
struct snd_soc_jack *jack: ASoC jackint count: Number of zonesstruct snd_soc_jack_zone *zones: Array of zones
Description
After this function has been called the zones specified in the array will be associated with the jack.
snd_soc_jack_get_type() #
int Based on the mic bias value, this function returns the type of jack from the zones declared in the jack type
Parameters
struct snd_soc_jack *jack: ASoC jackint micbias_voltage: mic bias voltage at adc channel when jack is plugged in
Description
Based on the mic bias value passed, this function helps identify the type of jack from the already declared jack zones
snd_soc_jack_add_pins() #
int Associate DAPM pins with an ASoC jack
Parameters
struct snd_soc_jack *jack: ASoC jack created withsnd_soc_card_jack_new_pins()int count: Number of pinsstruct snd_soc_jack_pin *pins: Array of pins
Description
After this function has been called the DAPM pins specified in the pins array will have their status updated to reflect the current state of the jack whenever the jack status is updated.
snd_soc_jack_notifier_register() #
void Register a notifier for jack status
Parameters
struct snd_soc_jack *jack: ASoC jackstruct notifier_block *nb: Notifier block to register
Description
Register for notification of the current status of the jack. Note that it is not possible to report additional jack events in the callback from the notifier, this is intended to support applications such as enabling electrical detection only when a mechanical detection event has occurred.
snd_soc_jack_notifier_unregister() #
void Unregister a notifier for jack status
Parameters
struct snd_soc_jack *jack: ASoC jackstruct notifier_block *nb: Notifier block to unregister
Description
Stop notifying for status changes.
snd_soc_jack_add_gpios() #
int Associate GPIO pins with an ASoC jack
Parameters
struct snd_soc_jack *jack: ASoC jackint count: number of pinsstruct snd_soc_jack_gpio *gpios: array of gpio pins
Description
This function will request gpio, set data direction and request irq for each gpio in the array.
snd_soc_jack_add_gpiods() #
int Associate GPIO descriptor pins with an ASoC jack
Parameters
struct device *gpiod_dev: GPIO consumer devicestruct snd_soc_jack *jack: ASoC jackint count: number of pinsstruct snd_soc_jack_gpio *gpios: array of gpio pins
Description
This function will request gpio, set data direction and request irq for each gpio in the array.
snd_soc_jack_free_gpios() #
void Release GPIO pins' resources of an ASoC jack
Parameters
struct snd_soc_jack *jack: ASoC jackint count: number of pinsstruct snd_soc_jack_gpio *gpios: array of gpio pins
Description
Release gpio and irq resources for gpio pins associated with an ASoC jack.
ISA DMA Helpers #
snd_dma_program() #
void program an ISA DMA transfer
Parameters
unsigned long dma: the dma numberunsigned long addr: the physical address of the bufferunsigned int size: the DMA transfer sizeunsigned short mode: the DMA transfer mode, DMA_MODE_XXX
Description
Programs an ISA DMA transfer for the given buffer.
snd_dma_disable() #
void stop the ISA DMA transfer
Parameters
unsigned long dma: the dma number
Description
Stops the ISA DMA transfer.
snd_dma_pointer() #
unsigned int return the current pointer to DMA transfer buffer in bytes
Parameters
unsigned long dma: the dma numberunsigned int size: the dma transfer size
Return
The current pointer in DMA transfer buffer in bytes.
snd_devm_request_dma() #
int the managed version of request_dma()
Parameters
struct device *dev: the device pointerint dma: the dma numberconst char *name: the name string of the requester
Description
The requested DMA will be automatically released at unbinding via devres.
Return
zero on success, or a negative error code
Other Helper Macros #
snd_power_ref() #
void Take the reference count for power control
Parameters
struct snd_card *card: sound card object
Description
The power_ref reference of the card is used for managing to block
the snd_power_sync_ref() operation. This function increments the reference.
The counterpart snd_power_unref() has to be called appropriately later.
snd_power_unref() #
void Release the reference count for power control
Parameters
struct snd_card *card: sound card object
snd_power_sync_ref() #
void wait until the card power_ref is freed
Parameters
struct snd_card *card: sound card object
Description
This function is used to synchronize with the pending power_ref being released.
snd_card_unref() #
void Unreference the card object
Parameters
struct snd_card *card: the card object to unreference
Description
Call this function for the card object that was obtained via snd_card_ref()
or snd_lookup_minor_data().
snd_BUG() #
give a BUG warning message and stack trace
Description
Calls WARN() if CONFIG_SND_DEBUG is set.
Ignored when CONFIG_SND_DEBUG is not set.
snd_BUG_ON() #
debugging check macro
Parameters
cond: condition to evaluate
Description
Has the same behavior as WARN_ON when CONFIG_SND_DEBUG is set, otherwise just evaluates the conditional and returns the value.
register_sound_special_device() #
int register a special sound node
Parameters
const struct file_operations *fops: File operations for the driverint unit: Unit number to allocatestruct device *dev: device pointer
Description
Allocate a special sound device by minor number from the sound subsystem.
Return
The allocated number is returned on success. On failure, a negative error code is returned.
register_sound_mixer() #
int register a mixer device
Parameters
const struct file_operations *fops: File operations for the driverint dev: Unit number to allocate
Description
Allocate a mixer device. Unit is the number of the mixer requested. Pass -1 to request the next free mixer unit.
Return
On success, the allocated number is returned. On failure, a negative error code is returned.
register_sound_dsp() #
int register a DSP device
Parameters
const struct file_operations *fops: File operations for the driverint dev: Unit number to allocate
Description
Allocate a DSP device. Unit is the number of the DSP requested. Pass -1 to request the next free DSP unit.
This function allocates both the audio and dsp device entries together and will always allocate them as a matching pair - eg dsp3/audio3
Return
On success, the allocated number is returned. On failure, a negative error code is returned.
unregister_sound_special() #
void unregister a special sound device
Parameters
int unit: unit number to allocate
Description
Release a sound device that was allocated with
register_sound_special(). The unit passed is the return value from
the register function.
unregister_sound_mixer() #
void unregister a mixer
Parameters
int unit: unit number to allocate
Description
Release a sound device that was allocated with register_sound_mixer().
The unit passed is the return value from the register function.
unregister_sound_dsp() #
void unregister a DSP device
Parameters
int unit: unit number to allocate
Description
Release a sound device that was allocated with register_sound_dsp().
The unit passed is the return value from the register function.
Both of the allocated units are released together automatically.