Skip to content

Commit

Permalink
[ALSA] ASoC: Clarify API for bias configuration
Browse files Browse the repository at this point in the history
Currently the ASoC core configures the bias levels in the system using
a callback on codecs and machines called 'dapm_event', passing it PCI
style power levels as SNDRV_CTL_POWER_ constants. This is more obscure
than it needs to be and has caused confusion to driver authors,
especially given that DAPM is also performing power management.

Address this by renaming the callback function to 'set_bias_level' and
using constants explicitly representing the off, standby, pre-on and on
states which DAPM transitions through.

Also unexport the API for setting bias level: there are currently no
in-tree users of this API other than the core itself and it is likely
that the core would need to be extended to cater for any users.

Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
Cc: Jarkko Nikula <jarkko.nikula@nokia.com>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
  • Loading branch information
Mark Brown authored and Jaroslav Kysela committed May 19, 2008
1 parent 1ef6ab7 commit 0be9898
Show file tree
Hide file tree
Showing 10 changed files with 150 additions and 130 deletions.
3 changes: 2 additions & 1 deletion include/sound/soc-dapm.h
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,8 @@ int snd_soc_dapm_add_routes(struct snd_soc_codec *codec,
/* dapm events */
int snd_soc_dapm_stream_event(struct snd_soc_codec *codec, char *stream,
int event);
int snd_soc_dapm_device_event(struct snd_soc_device *socdev, int event);
int snd_soc_dapm_set_bias_level(struct snd_soc_device *socdev,
enum snd_soc_bias_level level);

/* dapm sys fs - used by the core */
int snd_soc_dapm_sys_add(struct device *dev);
Expand Down
28 changes: 24 additions & 4 deletions include/sound/soc.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,24 @@
.get = xhandler_get, .put = xhandler_put, \
.private_value = (unsigned long)&xenum }

/*
* Bias levels
*
* @ON: Bias is fully on for audio playback and capture operations.
* @PREPARE: Prepare for audio operations. Called before DAPM switching for
* stream start and stop operations.
* @STANDBY: Low power standby state when no playback/capture operations are
* in progress. NOTE: The transition time between STANDBY and ON
* should be as fast as possible and no longer than 10ms.
* @OFF: Power Off. No restrictions on transition times.
*/
enum snd_soc_bias_level {
SND_SOC_BIAS_ON,
SND_SOC_BIAS_PREPARE,
SND_SOC_BIAS_STANDBY,
SND_SOC_BIAS_OFF,
};

/*
* Digital Audio Interface (DAI) types
*/
Expand Down Expand Up @@ -356,7 +374,8 @@ struct snd_soc_codec {
struct mutex mutex;

/* callbacks */
int (*dapm_event)(struct snd_soc_codec *codec, int event);
int (*set_bias_level)(struct snd_soc_codec *,
enum snd_soc_bias_level level);

/* runtime */
struct snd_card *card;
Expand All @@ -378,8 +397,8 @@ struct snd_soc_codec {
/* dapm */
struct list_head dapm_widgets;
struct list_head dapm_paths;
unsigned int dapm_state;
unsigned int suspend_dapm_state;
enum snd_soc_bias_level bias_level;
enum snd_soc_bias_level suspend_bias_level;
struct delayed_work delayed_work;

/* codec DAI's */
Expand Down Expand Up @@ -449,7 +468,8 @@ struct snd_soc_machine {
int (*resume_post)(struct platform_device *pdev);

/* callbacks */
int (*dapm_event)(struct snd_soc_machine *, int event);
int (*set_bias_level)(struct snd_soc_machine *,
enum snd_soc_bias_level level);

/* CPU <--> Codec DAI links */
struct snd_soc_dai_link *dai_link;
Expand Down
26 changes: 13 additions & 13 deletions sound/soc/codecs/tlv320aic3x.c
Original file line number Diff line number Diff line change
Expand Up @@ -847,13 +847,14 @@ static int aic3x_set_dai_fmt(struct snd_soc_codec_dai *codec_dai,
return 0;
}

static int aic3x_dapm_event(struct snd_soc_codec *codec, int event)
static int aic3x_set_bias_level(struct snd_soc_codec *codec,
enum snd_soc_bias_level level)
{
struct aic3x_priv *aic3x = codec->private_data;
u8 reg;

switch (event) {
case SNDRV_CTL_POWER_D0:
switch (level) {
case SND_SOC_BIAS_ON:
/* all power is driven by DAPM system */
if (aic3x->master) {
/* enable pll */
Expand All @@ -862,10 +863,9 @@ static int aic3x_dapm_event(struct snd_soc_codec *codec, int event)
reg | PLL_ENABLE);
}
break;
case SNDRV_CTL_POWER_D1:
case SNDRV_CTL_POWER_D2:
case SND_SOC_BIAS_PREPARE:
break;
case SNDRV_CTL_POWER_D3hot:
case SND_SOC_BIAS_STANDBY:
/*
* all power is driven by DAPM system,
* so output power is safe if bypass was set
Expand All @@ -877,7 +877,7 @@ static int aic3x_dapm_event(struct snd_soc_codec *codec, int event)
reg & ~PLL_ENABLE);
}
break;
case SNDRV_CTL_POWER_D3cold:
case SND_SOC_BIAS_OFF:
/* force all power off */
reg = aic3x_read_reg_cache(codec, LINE1L_2_LADC_CTRL);
aic3x_write(codec, LINE1L_2_LADC_CTRL, reg & ~LADC_PWR_ON);
Expand Down Expand Up @@ -913,7 +913,7 @@ static int aic3x_dapm_event(struct snd_soc_codec *codec, int event)
}
break;
}
codec->dapm_state = event;
codec->bias_level = level;

return 0;
}
Expand Down Expand Up @@ -979,7 +979,7 @@ static int aic3x_suspend(struct platform_device *pdev, pm_message_t state)
struct snd_soc_device *socdev = platform_get_drvdata(pdev);
struct snd_soc_codec *codec = socdev->codec;

aic3x_dapm_event(codec, SNDRV_CTL_POWER_D3cold);
aic3x_set_bias_level(codec, SND_SOC_BIAS_OFF);

return 0;
}
Expand All @@ -999,7 +999,7 @@ static int aic3x_resume(struct platform_device *pdev)
codec->hw_write(codec->control_data, data, 2);
}

aic3x_dapm_event(codec, codec->suspend_dapm_state);
aic3x_set_bias_level(codec, codec->suspend_bias_level);

return 0;
}
Expand All @@ -1018,7 +1018,7 @@ static int aic3x_init(struct snd_soc_device *socdev)
codec->owner = THIS_MODULE;
codec->read = aic3x_read_reg_cache;
codec->write = aic3x_write;
codec->dapm_event = aic3x_dapm_event;
codec->set_bias_level = aic3x_set_bias_level;
codec->dai = &aic3x_dai;
codec->num_dai = 1;
codec->reg_cache_size = sizeof(aic3x_reg);
Expand Down Expand Up @@ -1100,7 +1100,7 @@ static int aic3x_init(struct snd_soc_device *socdev)
aic3x_write(codec, LINE2R_2_MONOLOPM_VOL, DEFAULT_VOL);

/* off, with power on */
aic3x_dapm_event(codec, SNDRV_CTL_POWER_D3hot);
aic3x_set_bias_level(codec, SND_SOC_BIAS_STANDBY);

/* setup GPIO functions */
aic3x_write(codec, AIC3X_GPIO1_REG, (setup->gpio_func[0] & 0xf) << 4);
Expand Down Expand Up @@ -1271,7 +1271,7 @@ static int aic3x_remove(struct platform_device *pdev)

/* power down chip */
if (codec->control_data)
aic3x_dapm_event(codec, SNDRV_CTL_POWER_D3);
aic3x_set_bias_level(codec, SND_SOC_BIAS_OFF);

snd_soc_free_pcms(socdev);
snd_soc_dapm_free(socdev);
Expand Down
28 changes: 14 additions & 14 deletions sound/soc/codecs/wm8731.c
Original file line number Diff line number Diff line change
Expand Up @@ -435,29 +435,29 @@ static int wm8731_set_dai_fmt(struct snd_soc_codec_dai *codec_dai,
return 0;
}

static int wm8731_dapm_event(struct snd_soc_codec *codec, int event)
static int wm8731_set_bias_level(struct snd_soc_codec *codec,
enum snd_soc_bias_level level)
{
u16 reg = wm8731_read_reg_cache(codec, WM8731_PWR) & 0xff7f;

switch (event) {
case SNDRV_CTL_POWER_D0: /* full On */
switch (level) {
case SND_SOC_BIAS_ON:
/* vref/mid, osc on, dac unmute */
wm8731_write(codec, WM8731_PWR, reg);
break;
case SNDRV_CTL_POWER_D1: /* partial On */
case SNDRV_CTL_POWER_D2: /* partial On */
case SND_SOC_BIAS_PREPARE:
break;
case SNDRV_CTL_POWER_D3hot: /* Off, with power */
case SND_SOC_BIAS_STANDBY:
/* everything off except vref/vmid, */
wm8731_write(codec, WM8731_PWR, reg | 0x0040);
break;
case SNDRV_CTL_POWER_D3cold: /* Off, without power */
case SND_SOC_BIAS_OFF:
/* everything off, dac mute, inactive */
wm8731_write(codec, WM8731_ACTIVE, 0x0);
wm8731_write(codec, WM8731_PWR, 0xffff);
break;
}
codec->dapm_state = event;
codec->bias_level = level;
return 0;
}

Expand Down Expand Up @@ -503,7 +503,7 @@ static int wm8731_suspend(struct platform_device *pdev, pm_message_t state)
struct snd_soc_codec *codec = socdev->codec;

wm8731_write(codec, WM8731_ACTIVE, 0x0);
wm8731_dapm_event(codec, SNDRV_CTL_POWER_D3cold);
wm8731_set_bias_level(codec, SND_SOC_BIAS_OFF);
return 0;
}

Expand All @@ -521,8 +521,8 @@ static int wm8731_resume(struct platform_device *pdev)
data[1] = cache[i] & 0x00ff;
codec->hw_write(codec->control_data, data, 2);
}
wm8731_dapm_event(codec, SNDRV_CTL_POWER_D3hot);
wm8731_dapm_event(codec, codec->suspend_dapm_state);
wm8731_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
wm8731_set_bias_level(codec, codec->suspend_bias_level);
return 0;
}

Expand All @@ -539,7 +539,7 @@ static int wm8731_init(struct snd_soc_device *socdev)
codec->owner = THIS_MODULE;
codec->read = wm8731_read_reg_cache;
codec->write = wm8731_write;
codec->dapm_event = wm8731_dapm_event;
codec->set_bias_level = wm8731_set_bias_level;
codec->dai = &wm8731_dai;
codec->num_dai = 1;
codec->reg_cache_size = sizeof(wm8731_reg);
Expand All @@ -557,7 +557,7 @@ static int wm8731_init(struct snd_soc_device *socdev)
}

/* power on device */
wm8731_dapm_event(codec, SNDRV_CTL_POWER_D3hot);
wm8731_set_bias_level(codec, SND_SOC_BIAS_STANDBY);

/* set the update bits */
reg = wm8731_read_reg_cache(codec, WM8731_LOUT1V);
Expand Down Expand Up @@ -730,7 +730,7 @@ static int wm8731_remove(struct platform_device *pdev)
struct snd_soc_codec *codec = socdev->codec;

if (codec->control_data)
wm8731_dapm_event(codec, SNDRV_CTL_POWER_D3cold);
wm8731_set_bias_level(codec, SND_SOC_BIAS_OFF);

snd_soc_free_pcms(socdev);
snd_soc_dapm_free(socdev);
Expand Down
36 changes: 18 additions & 18 deletions sound/soc/codecs/wm8750.c
Original file line number Diff line number Diff line change
Expand Up @@ -686,29 +686,29 @@ static int wm8750_mute(struct snd_soc_codec_dai *dai, int mute)
return 0;
}

static int wm8750_dapm_event(struct snd_soc_codec *codec, int event)
static int wm8750_set_bias_level(struct snd_soc_codec *codec,
enum snd_soc_bias_level level)
{
u16 pwr_reg = wm8750_read_reg_cache(codec, WM8750_PWR1) & 0xfe3e;

switch (event) {
case SNDRV_CTL_POWER_D0: /* full On */
switch (level) {
case SND_SOC_BIAS_ON:
/* set vmid to 50k and unmute dac */
wm8750_write(codec, WM8750_PWR1, pwr_reg | 0x00c0);
break;
case SNDRV_CTL_POWER_D1: /* partial On */
case SNDRV_CTL_POWER_D2: /* partial On */
case SND_SOC_BIAS_PREPARE:
/* set vmid to 5k for quick power up */
wm8750_write(codec, WM8750_PWR1, pwr_reg | 0x01c1);
break;
case SNDRV_CTL_POWER_D3hot: /* Off, with power */
case SND_SOC_BIAS_STANDBY:
/* mute dac and set vmid to 500k, enable VREF */
wm8750_write(codec, WM8750_PWR1, pwr_reg | 0x0141);
break;
case SNDRV_CTL_POWER_D3cold: /* Off, without power */
case SND_SOC_BIAS_OFF:
wm8750_write(codec, WM8750_PWR1, 0x0001);
break;
}
codec->dapm_state = event;
codec->bias_level = level;
return 0;
}

Expand Down Expand Up @@ -748,15 +748,15 @@ static void wm8750_work(struct work_struct *work)
{
struct snd_soc_codec *codec =
container_of(work, struct snd_soc_codec, delayed_work.work);
wm8750_dapm_event(codec, codec->dapm_state);
wm8750_set_bias_level(codec, codec->bias_level);
}

static int wm8750_suspend(struct platform_device *pdev, pm_message_t state)
{
struct snd_soc_device *socdev = platform_get_drvdata(pdev);
struct snd_soc_codec *codec = socdev->codec;

wm8750_dapm_event(codec, SNDRV_CTL_POWER_D3cold);
wm8750_set_bias_level(codec, SND_SOC_BIAS_OFF);
return 0;
}

Expand All @@ -777,12 +777,12 @@ static int wm8750_resume(struct platform_device *pdev)
codec->hw_write(codec->control_data, data, 2);
}

wm8750_dapm_event(codec, SNDRV_CTL_POWER_D3hot);
wm8750_set_bias_level(codec, SND_SOC_BIAS_STANDBY);

/* charge wm8750 caps */
if (codec->suspend_dapm_state == SNDRV_CTL_POWER_D0) {
wm8750_dapm_event(codec, SNDRV_CTL_POWER_D2);
codec->dapm_state = SNDRV_CTL_POWER_D0;
if (codec->suspend_bias_level == SND_SOC_BIAS_ON) {
wm8750_set_bias_level(codec, SND_SOC_BIAS_PREPARE);
codec->bias_level = SND_SOC_BIAS_ON;
schedule_delayed_work(&codec->delayed_work,
msecs_to_jiffies(1000));
}
Expand All @@ -803,7 +803,7 @@ static int wm8750_init(struct snd_soc_device *socdev)
codec->owner = THIS_MODULE;
codec->read = wm8750_read_reg_cache;
codec->write = wm8750_write;
codec->dapm_event = wm8750_dapm_event;
codec->set_bias_level = wm8750_set_bias_level;
codec->dai = &wm8750_dai;
codec->num_dai = 1;
codec->reg_cache_size = sizeof(wm8750_reg);
Expand All @@ -821,8 +821,8 @@ static int wm8750_init(struct snd_soc_device *socdev)
}

/* charge output caps */
wm8750_dapm_event(codec, SNDRV_CTL_POWER_D2);
codec->dapm_state = SNDRV_CTL_POWER_D3hot;
wm8750_set_bias_level(codec, SND_SOC_BIAS_PREPARE);
codec->bias_level = SND_SOC_BIAS_STANDBY;
schedule_delayed_work(&codec->delayed_work, msecs_to_jiffies(1000));

/* set the update bits */
Expand Down Expand Up @@ -1021,7 +1021,7 @@ static int wm8750_remove(struct platform_device *pdev)
struct snd_soc_codec *codec = socdev->codec;

if (codec->control_data)
wm8750_dapm_event(codec, SNDRV_CTL_POWER_D3cold);
wm8750_set_bias_level(codec, SND_SOC_BIAS_OFF);
run_delayed_work(&codec->delayed_work);
snd_soc_free_pcms(socdev);
snd_soc_dapm_free(socdev);
Expand Down
Loading

0 comments on commit 0be9898

Please sign in to comment.