Chinaunix首页 | 论坛 | 博客
  • 博客访问: 483577
  • 博文数量: 285
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 629
  • 用 户 组: 普通用户
  • 注册时间: 2013-10-14 17:53
个人简介

相信自己,快乐每一天

文章分类

全部博文(285)

分类: LINUX

2013-10-18 14:47:12

Dynamic Audio Power Management for Portable Devices
便携设备动态音频电源管理
===================================================

1. Description
1、概述
==============

Dynamic Audio Power Management (DAPM) is designed to allow portable
Linux devices to use the minimum amount of power within the audio
subsystem at all times. It is independent of other kernel PM and as
such, can easily co-exist with the other PM systems.
动态音频电源管理(DAPM)设计用来使便携Linux设备可以在任何时最小化音频子系统的电能。它独立于其它内核电源管理,因此容易与其它电源管理系统共存。

DAPM is also completely transparent to all user space applications as
all power switching is done within the ASoC core. No code changes or
recompiling are required for user space applications. DAPM makes power
switching decisions based upon any audio stream (capture/playback)
activity and audio mixer settings within the device.
DAPM对用户程序也是完全透明的,因为所有的电源切换都是在ASoC核内部进行的。用户程序无须修改代码或重新编译。DAPM的切换是依据设备内部的各音频流(捕获/回放)活动和音频混音机设置决定的。


DAPM spans the whole machine. It covers power control within the entire
audio subsystem, this includes internal codec power blocks and machine
level power systems.
DAPM扩展到整个机器。它包括整个音频子系统的电源控制。这包括内部解码器电源模块和机器级电源系统。

There are 4 power domains within DAPM
DAPM有4个电源域:

   1. Codec domain - VREF, VMID (core codec and audio power)
      Usually controlled at codec probe/remove and suspend/resume, although
      can be set at stream time if power is not needed for sidetone, etc.
1、解码器域-VREF,VMID(核解码器和音频电源)
   通常在解码器检测/移除和挂起/恢复时控制,虽然在不需电源或侧音时也可以在流时间设置。


   2. Platform/Machine domain - physically connected inputs and outputs
      Is platform/machine and user action specific, is configured by the
      machine driver and responds to asynchronous events e.g when HP
      are inserted
2、平台/机器域-有物理连接的输入输出
是平台/机器相关且用户动作相关的。由机器驱动配置HP插入时响应同步事件。

   3. Path domain - audio susbsystem signal paths
      Automatically set when mixer and mux settings are changed by the user.
      e.g. alsamixer, amixer.
3、路径域-音频子系统信号路径
混音机和复用器设置被用户改变时自动设置。如alsomixer,amixer.

   4. Stream domain - DACs and ADCs.
      Enabled and disabled when stream playback/capture is started and
      stopped respectively. e.g. aplay, arecord.
4、数据流域-DAC和ADC
流插放/捕获开始和停止时分别使能和禁用,如aplay,arecord.

All DAPM power switching decisions are made automatically by consulting an audio
routing map of the whole machine. This map is specific to each machine and
consists of the interconnections between every audio component (including
internal codec components). All audio components that effect power are called
widgets hereafter.


2. DAPM Widgets
===============

Audio DAPM widgets fall into a number of types:-

o Mixer      - Mixes several analog signals into a single analog signal.
o Mux        - An analog switch that outputs only one of many inputs.
o PGA        - A programmable gain amplifier or attenuation widget.
o ADC        - Analog to Digital Converter
o DAC        - Digital to Analog Converter
o Switch     - An analog switch
o Input      - A codec input pin
o Output     - A codec output pin
o Headphone  - Headphone (and optional Jack)
o Mic        - Mic (and optional Jack)
o Line       - Line Input/Output (and optional Jack)
o Speaker    - Speaker
o Pre        - Special PRE widget (exec before all others)
o Post       - Special POST widget (exec after all others)

(Widgets are defined in include/sound/soc-dapm.h)

Widgets are usually added in the codec driver and the machine driver. There are
convenience macros defined in soc-dapm.h that can be used to quickly build a
list of widgets of the codecs and machines DAPM widgets.

Most widgets have a name, register, shift and invert. Some widgets have extra
parameters for stream name and kcontrols.


2.1 Stream Domain Widgets
-------------------------

Stream Widgets relate to the stream power domain and only consist of ADCs
(analog to digital converters) and DACs (digital to analog converters).

Stream widgets have the following format:-

SND_SOC_DAPM_DAC(name, stream name, reg, shift, invert),

NOTE: the stream name must match the corresponding stream name in your codec
snd_soc_codec_dai.

e.g. stream widgets for HiFi playback and capture

SND_SOC_DAPM_DAC("HiFi DAC", "HiFi Playback", REG, 3, 1),
SND_SOC_DAPM_ADC("HiFi ADC", "HiFi Capture", REG, 2, 1),


2.2 Path Domain Widgets
-----------------------

Path domain widgets have a ability to control or affect the audio signal or
audio paths within the audio subsystem. They have the following form:-

SND_SOC_DAPM_PGA(name, reg, shift, invert, controls, num_controls)

Any widget kcontrols can be set using the controls and num_controls members.

e.g. Mixer widget (the kcontrols are declared first)

/* Output Mixer */
static const snd_kcontrol_new_t wm8731_output_mixer_controls[] = {
SOC_DAPM_SINGLE("Line Bypass Switch", WM8731_APANA, 3, 1, 0),
SOC_DAPM_SINGLE("Mic Sidetone Switch", WM8731_APANA, 5, 1, 0),
SOC_DAPM_SINGLE("HiFi Playback Switch", WM8731_APANA, 4, 1, 0),
};

SND_SOC_DAPM_MIXER("Output Mixer", WM8731_PWR, 4, 1, wm8731_output_mixer_controls,
    ARRAY_SIZE(wm8731_output_mixer_controls)),

If you dont want the mixer elements prefixed with the name of the mixer widget,
you can use SND_SOC_DAPM_MIXER_NAMED_CTL instead. the parameters are the same
as for SND_SOC_DAPM_MIXER.

2.3 Platform/Machine domain Widgets
-----------------------------------

Machine widgets are different from codec widgets in that they don't have a
codec register bit associated with them. A machine widget is assigned to each
machine audio component (non codec) that can be independently powered. e.g.

o Speaker Amp
o Microphone Bias
o Jack connectors

A machine widget can have an optional call back.

e.g. Jack connector widget for an external Mic that enables Mic Bias
when the Mic is inserted:-

static int spitz_mic_bias(struct snd_soc_dapm_widget* w, int event)
{
    gpio_set_value(SPITZ_GPIO_MIC_BIAS, SND_SOC_DAPM_EVENT_ON(event));
    return 0;
}

SND_SOC_DAPM_MIC("Mic Jack", spitz_mic_bias),


2.4 Codec Domain
----------------

The codec power domain has no widgets and is handled by the codecs DAPM event
handler. This handler is called when the codec powerstate is changed wrt to any
stream event or by kernel PM events.


2.5 Virtual Widgets
-------------------

Sometimes widgets exist in the codec or machine audio map that don't have any
corresponding soft power control. In this case it is necessary to create
a virtual widget - a widget with no control bits e.g.

SND_SOC_DAPM_MIXER("AC97 Mixer", SND_SOC_DAPM_NOPM, 0, 0, NULL, 0),

This can be used to merge to signal paths together in software.

After all the widgets have been defined, they can then be added to the DAPM
subsystem individually with a call to snd_soc_dapm_new_control().


3. Codec Widget Interconnections
================================

Widgets are connected to each other within the codec and machine by audio paths
(called interconnections). Each interconnection must be defined in order to
create a map of all audio paths between widgets.

This is easiest with a diagram of the codec (and schematic of the machine audio
system), as it requires joining widgets together via their audio signal paths.

e.g., from the WM8731 output mixer (wm8731.c)

The WM8731 output mixer has 3 inputs (sources)

1. Line Bypass Input
2. DAC (HiFi playback)
3. Mic Sidetone Input

Each input in this example has a kcontrol associated with it (defined in example
above) and is connected to the output mixer via it's kcontrol name. We can now
connect the destination widget (wrt audio signal) with it's source widgets.

    /* output mixer */
    {"Output Mixer", "Line Bypass Switch", "Line Input"},
    {"Output Mixer", "HiFi Playback Switch", "DAC"},
    {"Output Mixer", "Mic Sidetone Switch", "Mic Bias"},

So we have :-

    Destination Widget  <=== Path Name <=== Source Widget

Or:-

    Sink, Path, Source

Or :-

    "Output Mixer" is connected to the "DAC" via the "HiFi Playback Switch".

When there is no path name connecting widgets (e.g. a direct connection) we
pass NULL for the path name.

Interconnections are created with a call to:-

snd_soc_dapm_connect_input(codec, sink, path, source);

Finally, snd_soc_dapm_new_widgets(codec) must be called after all widgets and
interconnections have been registered with the core. This causes the core to
scan the codec and machine so that the internal DAPM state matches the
physical state of the machine.


3.1 Machine Widget Interconnections
-----------------------------------
Machine widget interconnections are created in the same way as codec ones and
directly connect the codec pins to machine level widgets.

e.g. connects the speaker out codec pins to the internal speaker.

    /* ext speaker connected to codec pins LOUT2, ROUT2  */
    {"Ext Spk", NULL , "ROUT2"},
    {"Ext Spk", NULL , "LOUT2"},

This allows the DAPM to power on and off pins that are connected (and in use)
and pins that are NC respectively.


4 Endpoint Widgets
===================
An endpoint is a start or end point (widget) of an audio signal within the
machine and includes the codec. e.g.

o Headphone Jack
o Internal Speaker
o Internal Mic
o Mic Jack
o Codec Pins

When a codec pin is NC it can be marked as not used with a call to

snd_soc_dapm_set_endpoint(codec, "Widget Name", 0);

The last argument is 0 for inactive and 1 for active. This way the pin and its
input widget will never be powered up and consume power.

This also applies to machine widgets. e.g. if a headphone is connected to a
jack then the jack can be marked active. If the headphone is removed, then
the headphone jack can be marked inactive.


5 DAPM Widget Events
====================

Some widgets can register their interest with the DAPM core in PM events.
e.g. A Speaker with an amplifier registers a widget so the amplifier can be
powered only when the spk is in use.

/* turn speaker amplifier on/off depending on use */
static int corgi_amp_event(struct snd_soc_dapm_widget *w, int event)
{
    gpio_set_value(CORGI_GPIO_APM_ON, SND_SOC_DAPM_EVENT_ON(event));
    return 0;
}

/* corgi machine dapm widgets */
static const struct snd_soc_dapm_widget wm8731_dapm_widgets =
    SND_SOC_DAPM_SPK("Ext Spk", corgi_amp_event);

Please see soc-dapm.h for all other widgets that support events.


5.1 Event types
---------------

The following event types are supported by event widgets.

/* dapm event types */
#define SND_SOC_DAPM_PRE_PMU    0x1     /* before widget power up */
#define SND_SOC_DAPM_POST_PMU    0x2        /* after widget power up */
#define SND_SOC_DAPM_PRE_PMD    0x4     /* before widget power down */
#define SND_SOC_DAPM_POST_PMD    0x8        /* after widget power down */
#define SND_SOC_DAPM_PRE_REG    0x10    /* before audio path setup */
#define SND_SOC_DAPM_POST_REG    0x20    /* after audio path setup */

君子注:
您现在所阅读的,是君子阅读Linux音频SoC驱动时,写下的文档译文。
君子写些译文,一方面是作为自己的笔记,帮助记忆,另一方面也希望能对他人有所帮助。
如果您能于君子的译文中有所收获,则吾心甚慰。
所有这几个文档原文,是见于linux-2.6.30/Documentation/sound/alsa/soc目录下的全部内容。
由于君子对音频方面的内容了解也不多,很多地方我自己也不理解,只是照着原文生硬的译出来。
其中错误愿来来访者之宾不吝指正。
张君再拜.
下面是所有九篇译文的详细网址,希望能对大家有用:

  1. linux音频alsa-uda134x驱动文档阅读之一(over-view)

  2. linux音频alsa-uda134x驱动文档阅读之二(时钟)

  3. linux音频alsa-uda134x驱动文档阅读之三(解码器)

  4. linux音频alsa-uda134x驱动文档阅读之四(数字音频接口)

  5. linux音频alsa-uda134x驱动文档阅读之五(动态音频电源管理)

  6. linux音频alsa-uda134x驱动文档阅读之六(插口)

  7. linux音频alsa-uda134x驱动文档阅读之七(机器驱动)

  8. linux音频alsa-uda134x驱动文档阅读之八(平台驱动)

  9. linux音频alsa-uda134x驱动文档阅读之九(咔咔声)

阅读(279) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~