Linux ALSA Audio Driver Framework __php

Source: Internet
Author: User
Tags prepare

The link list structure in ALSA

In the ALSA design to many of the linked list structure, understanding these lists can better understand ALSA

A) card->devices

The establishment of Card->devices linked list facilitates the registration process and equipment management of card related equipment. Through this linked list, in the process of registering the equipment, you can add the equipment (including the equipment number, the corresponding operation pointers, etc.) into the list, and then traverse the list, the respective device call itself registration function will register itself, complete card related all equipment registration process.

b) snd_pcm_devices

The list structure is to link the existing PCM interface to the linked list, so as to facilitate the management of PCM.

c) snd_pcm_notify_list

This list is a common method for PCM registration, if only one snd_pcm_oss_notify is registered

, the PCM device found when traversing Snd_pcm_devices uses the notify. N_register for PCM registration.

D) card->controls

Cadr->controls linked list and card->devices linked list is similar, regardless of a responsible for the pipe equipment, a responsible for the control of the interface, the basic operation is similar, but there is no relevant registers in the PCM, so did not apply.

e) Snd_control_ioctls

Control-related lists, if snd_ctl_add in control, add control to this list.

f) timer->active_list_head

The list of timer-related

Nine The relation of each structure body and each module in the drive

A the correlation diagram between the various structures used by the Soc_core can be said to be the core layer in the system. As follows



From the above figure, the reason why most functions in Soc_core take Soc_device pointers as function parameters is also obvious.

and follow the Soc_core call relationship, that is, CPU----àplatform----àcodec, in the above structure is always a good embodiment.

An important structure is runtime, which represents the information of Dai Runtime.

b The above chart is based on Snd_soc_device, which is the analysis of the device-driven creation process. The following structure diagram is based on Snd_pcm_substream, mainly analyzing the process of obtaining the required structure from Substream in open,hw_params,write,read operations.

Ten The whole process of calling from the kernel to the driver

1. Open/dev/dsp

Open operation, through the previous structure diagram, we know that when the kernel calls the Open function, the first call is Soundcore_open, through the __look_for_unit find chain[3], that is, the DSP sound_unit pointer, The operation pointer to the value file is then assigned to the operation pointer of the DSP device file.

This method also applies to other files, for example, for/dev/mixer, when the open operation is invoked, the same call to Soundcore_open is done, and then the next action is to redefine the operation pointer of the file as the action pointer of the mixer file and invoke the Mixer_ The Open function in OPS,

Later, the operation of the file is to invoke the updated OPS.

Here is a call to open in PCM_OSS.C, the specific flow chart is as follows,

Specific,

Cpu_dai.ops->startup for At91_ssc_startup This function is mainly to set the transmission direction of the mask (serial port only allow one-way transmission)

Platform->pcm_ops->open for At91_pcm_open This function is mainly set At91_pcm_hardware, including Pcm_info,period_bytes_min,period_bytes_ Max

Periods_min,periods_max,buffer_bytes_max and so on,

Codec_dai->ops.startup is null

Machine->ops->startup is Epayment_snd_startup, the number of functions is mainly set Cpu_dai CLK for system clock At91_sysclk_mck, set codec_ Dai's CLK for PCMXXX_SYSCLK, and then make it possible to Codec_dai CLK


2. Open/dev/mixer

The approximate process of open/dev/mixer is similar to the above OPEN/DEV/DSP, except that the following action pointer is mixer OPS

The specific thing is to call the Snd_mixer_oss_open in MIXER_OSS.C, which basically completes the struct Snd_mixer_oss_file *fmixer,fmixer fill and assigns it to the file's private data.

3. Procedures for configuring parameters (DSP IOCTL)

The process of configuring parameters is implemented through IOCTL

For example, in the library file, the parameter settings are implemented through the IOCTL, generally including, sync,channel,fmt,rate and other parameters of the settings.

To set the sampling rate as an example, the flow chart is as follows,


Similarly, in the function Soc_pcm_hw_params, the CPUÀPLATFORMÀCODEC is still followed

The approximate order.

Specific,

A) Machine->ops->hw_params, (the machine is a dai_link structure pointer), for function Epayment_snd_hw_params, the main completion settings Cpu_dai,codec_da FMT of I, set Cpu_dai cmr_div and period (computed by sampling)

b) Codec_dai->ops.hw_params to pcmxxx_hw_params null

c) Cpu_dai->ops.hw_params for At91_ssc_hw_params, the main completion of initialization of a struct at91_pcm_dma_params *dma_params, and Dma_par AMS is populated, including the PDC Register,ssc_base,pdc_xfer_size (in bytes) and some of the SSC registers, such as RCMR, RFMR, TCMR, TFMR.

Finally, reset SSC and its PDC registers, request interrupts, interrupt service routines for At91_ssc_interrupt, and, during transmission, interrupt the service routines when they receive data and all data is sent out.

d) Platform->pcm_ops->hw_params for At91_pcm_hw_params, the main completion of the at91_runtime_data data filling, here is also populated with a Dma_intr_handl ER is AT91_PCM_DMA_IRQ (actually a hardware-generated interrupt)

The relationship between this interrupt service routine and the At91_ssc_interrupt interrupt mentioned above is,

In the At91_ssc_interrupt interrupt service routine, the interrupt type is judged first and then the interrupt service routine is called AT91_PCM_DMA_IRQ to complete the interrupt service.

and the main task of AT91_PCM_DMA_IRQ interrupt service is to

If the interrupt type is the interrupt after the end of the transmit data, reset the prtd->period_ptr pointer (if it happens to be dma_buffer_end, set to the Dma_buffer head pointer, or the pointer moves down period_size bytes), Set up PDC->XNPR and PDC->XNCR.

If the interrupt type is dma_buffer full, close the PDC first, reposition the prtd->period_ptr pointer (set to the Dma_buffer head pointer), set PDC->XPR,PDC->XCR, and then reopen the PDC.

4. Mixer_ioctl

Ditto, mixer's related operations are implemented through IOCTL, which does not even require read and write.

Because the PCMXXX does not support volume adjustment, slightly.

5. PCM Prepare

Snd_pcm_oss_make_ready is invoked to prepare before the synchronization clock and Write/read are set.

The same is done through IOCTL.

Flowchart similar,

-----àsnd_pcm_prepare First wait for the power, after

-----àsnd_pcm_action_nonatomic (&snd_pcm_action_prepare,

Substream, F_flags);

static struct Action_ops Snd_pcm_action_prepare = {

. pre_action = Snd_pcm_pre_prepare,

. do_action = Snd_pcm_do_prepare,

. post_action = Snd_pcm_post_prepare

};

-----àpre_action Check Runtime->status->state

-----àdo_action Call Substream->ops->prepare (Substream)

That is the Soc_pcm_prepare

-----àpost_action Settings Runtime->status->state

The same soc_pcm_prepare also follows the basic process of Soc_core invocation

------Àmachine->ops->prepare

Null

------Àplatform->pcm_ops->prepare

SSC PREPARE,SSC interrrupt DISABLE,PDC Disable

------Àcodec_dai->ops.prepare

Null

------Àcpu_dai->ops.prepare

SSC Enable

------Àsnd_soc_dapm_stream_event

Send event Snd_soc_dapm_stream_start to power management,

See power supply part of specific power management

6. PCM Write Method (Read)

The call procedure for the Write method also follows the ALSA architecture,

The detailed flow chart is as follows,

In snd_pcm_lib_write1, the Snd_pcm_lib_write_transfer function is called to complete the copy process of data from user space to kernel space, and the copy process is replicated in frames.

static struct Action_ops Snd_pcm_action_start = {

. pre_action = Snd_pcm_pre_start,

. do_action = Snd_pcm_do_start,

. undo_action = Snd_pcm_undo_start,

. post_action = Snd_pcm_post_start

};

-----àpre_action First Detect runtime->status->state and check if there is data left in playback buffer

-----àdo_action Call Substream->ops->trigger (Soc_pcm_trigger)

-----Àpost_action detects whether hibernation is set (and the minimum sleep is greater than 0), enters the hibernation event if set, and notifies the timer.

And the Soc_pcm_trigger call is as follows,

----Àcodec_dai->ops.trigger NULL

----Àplatform->pcm_ops->trigger At91_pcm_trigger

The main thing is to set up the PDC parameters and finally enable the PDC to transmit data

----Àcpu_dai->ops.trigger NULL

7 Close Method

The call procedure for the Close method also follows the ALSA architecture,

The detailed flow chart is as follows,

In Soc_pcm_hw_free, the invocation is as follows,

-----Àcodec_dai->dai_ops.digital_mute

Pull down the corresponding codec digital mute

-----Àmachine->ops->hw_free

Release all Dai_link-related parameters

-----Àplatform->pcm_ops->hw_free

Freeing DMA Resources

-----Àcodec_dai->ops.hw_free

Release of Codec_dai related parameters

-----Àcpu_dai->ops.hw_free

Release of Cpu_dai related parameters

In Soc_codec_close, the invocation is as follows,

-----Àcpu_dai->ops.shutdown

For At91_ssc_shutdown, set dma_param each parameter is empty, prohibit the control register of SSC, close SSC clock and so on.

-----Àcodec_dai->ops.shutdown

Null

-----Àmachine->ops->shutdown

Prohibit PCLK1

-----àplatform->pcm_ops->close

For At91_pcm_close, release At91_runtime_data

-----Àschedule_delayed_work (&socdev->delayed_work,

Msecs_to_jiffies (Pmdown_time));

Where the parameter pmdown_time is 5000

That is, the delay of 5 seconds after the completion of the work (to ensure that the work required to complete, this work for the last step), in the soc_probe mentioned the registration of this work, for the close_delayed_work.

Close_delayed_work, the power off event is sent to DAPM, power off, as follows Snd_soc_dapm_stream_event (codec, Codec_dai->playback.stream_name,

                             snd_soc_dapm_stream_stop)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.