From 514cfd6dd72508b79030c8504764a73a7261b713 Mon Sep 17 00:00:00 2001 From: Mark Brown Date: Thu, 13 Dec 2012 17:29:00 +0900 Subject: ASoC: wm2000: Integrate with clock API Request MCLK as a clock and then enable it when carrying out a state transtion and while ANC is active, minimising system power consumption in idle modes. Signed-off-by: Mark Brown diff --git a/sound/soc/codecs/wm2000.c b/sound/soc/codecs/wm2000.c index 1cbe88f..0aba8ce 100644 --- a/sound/soc/codecs/wm2000.c +++ b/sound/soc/codecs/wm2000.c @@ -26,6 +26,7 @@ #include #include #include +#include #include #include #include @@ -62,6 +63,7 @@ enum wm2000_anc_mode { struct wm2000_priv { struct i2c_client *i2c; struct regmap *regmap; + struct clk *mclk; struct regulator_bulk_data supplies[WM2000_NUM_SUPPLIES]; @@ -550,6 +552,15 @@ static int wm2000_anc_transition(struct wm2000_priv *wm2000, return -EINVAL; } + /* Maintain clock while active */ + if (anc_transitions[i].source == ANC_OFF) { + ret = clk_prepare_enable(wm2000->mclk); + if (ret != 0) { + dev_err(&i2c->dev, "Failed to enable MCLK: %d\n", ret); + return ret; + } + } + for (j = 0; j < ARRAY_SIZE(anc_transitions[j].step); j++) { if (!anc_transitions[i].step[j]) break; @@ -559,7 +570,10 @@ static int wm2000_anc_transition(struct wm2000_priv *wm2000, return ret; } - return 0; + if (anc_transitions[i].dest == ANC_OFF) + clk_disable_unprepare(wm2000->mclk); + + return ret; } static int wm2000_anc_set_mode(struct wm2000_priv *wm2000) @@ -823,6 +837,13 @@ static int wm2000_i2c_probe(struct i2c_client *i2c, reg = wm2000_read(i2c, WM2000_REG_REVISON); dev_info(&i2c->dev, "revision %c\n", reg + 'A'); + wm2000->mclk = devm_clk_get(&i2c->dev, "MCLK"); + if (IS_ERR(wm2000->mclk)) { + ret = PTR_ERR(wm2000->mclk); + dev_err(&i2c->dev, "Failed to get MCLK: %d\n", ret); + goto err_supplies; + } + filename = "wm2000_anc.bin"; pdata = dev_get_platdata(&i2c->dev); if (pdata) { -- cgit v0.10.2 From d61100bbd18e8b3fc9406be55354dabd5e7525ec Mon Sep 17 00:00:00 2001 From: Mark Brown Date: Fri, 14 Dec 2012 15:16:58 +0900 Subject: ASoC: wm2000: Use clock API integration to configure MCLK divisor Since we are now using the clock API integration to manage MCLK we can now use clk_get_rate() to determine if we need to divide MCLK without relying on platform data. Signed-off-by: Mark Brown diff --git a/include/sound/wm2000.h b/include/sound/wm2000.h index aa388ca..4de81f4 100644 --- a/include/sound/wm2000.h +++ b/include/sound/wm2000.h @@ -15,9 +15,6 @@ struct wm2000_platform_data { /** Filename for system-specific image to download to device. */ const char *download_file; - /** Divide MCLK by 2 for system clock? */ - unsigned int mclkdiv2:1; - /** Disable speech clarity enhancement, for use when an * external algorithm is used. */ unsigned int speech_enh_disable:1; diff --git a/sound/soc/codecs/wm2000.c b/sound/soc/codecs/wm2000.c index 0aba8ce..85550dc 100644 --- a/sound/soc/codecs/wm2000.c +++ b/sound/soc/codecs/wm2000.c @@ -73,7 +73,6 @@ struct wm2000_priv { unsigned int anc_eng_ena:1; unsigned int spk_ena:1; - unsigned int mclk_div:1; unsigned int speech_clarity:1; int anc_download_size; @@ -133,6 +132,7 @@ static int wm2000_poll_bit(struct i2c_client *i2c, static int wm2000_power_up(struct i2c_client *i2c, int analogue) { struct wm2000_priv *wm2000 = dev_get_drvdata(&i2c->dev); + unsigned long rate; int ret; BUG_ON(wm2000->anc_mode != ANC_OFF); @@ -145,7 +145,8 @@ static int wm2000_power_up(struct i2c_client *i2c, int analogue) return ret; } - if (!wm2000->mclk_div) { + rate = clk_get_rate(wm2000->mclk); + if (rate <= 13500000) { dev_dbg(&i2c->dev, "Disabling MCLK divider\n"); wm2000_write(i2c, WM2000_REG_SYS_CTL2, WM2000_MCLK_DIV2_ENA_CLR); @@ -847,7 +848,6 @@ static int wm2000_i2c_probe(struct i2c_client *i2c, filename = "wm2000_anc.bin"; pdata = dev_get_platdata(&i2c->dev); if (pdata) { - wm2000->mclk_div = pdata->mclkdiv2; wm2000->speech_clarity = !pdata->speech_enh_disable; if (pdata->download_file) -- cgit v0.10.2 From 33e7546e199f123808699c65274283606114e225 Mon Sep 17 00:00:00 2001 From: Mark Brown Date: Tue, 22 Jan 2013 15:51:08 +0900 Subject: ASoC: wm2000: Expose some additional registers Signed-off-by: Mark Brown diff --git a/sound/soc/codecs/wm2000.c b/sound/soc/codecs/wm2000.c index 85550dc..627c454 100644 --- a/sound/soc/codecs/wm2000.c +++ b/sound/soc/codecs/wm2000.c @@ -717,6 +717,9 @@ static bool wm2000_readable_reg(struct device *dev, unsigned int reg) { switch (reg) { case WM2000_REG_SYS_START: + case WM2000_REG_ANC_GAIN_CTRL: + case WM2000_REG_MSE_TH1: + case WM2000_REG_MSE_TH2: case WM2000_REG_SPEECH_CLARITY: case WM2000_REG_SYS_WATCHDOG: case WM2000_REG_ANA_VMID_PD_TIME: diff --git a/sound/soc/codecs/wm2000.h b/sound/soc/codecs/wm2000.h index abcd82a..fb812cd 100644 --- a/sound/soc/codecs/wm2000.h +++ b/sound/soc/codecs/wm2000.h @@ -10,6 +10,9 @@ #define _WM2000_H #define WM2000_REG_SYS_START 0x8000 +#define WM2000_REG_ANC_GAIN_CTRL 0x8fa2 +#define WM2000_REG_MSE_TH2 0x8fdf +#define WM2000_REG_MSE_TH1 0x8fe0 #define WM2000_REG_SPEECH_CLARITY 0x8fef #define WM2000_REG_SYS_WATCHDOG 0x8ff6 #define WM2000_REG_ANA_VMID_PD_TIME 0x8ff7 -- cgit v0.10.2 From 3f3af6eeff3e048e27eb864519e779aedc194386 Mon Sep 17 00:00:00 2001 From: Mark Brown Date: Wed, 30 Jan 2013 21:35:44 +0800 Subject: ASoC: wm2000: Expose ANC gain adjustment No TLV information since it's not actually a direct gain control. Signed-off-by: Mark Brown diff --git a/sound/soc/codecs/wm2000.c b/sound/soc/codecs/wm2000.c index 627c454..cb7fa3c 100644 --- a/sound/soc/codecs/wm2000.c +++ b/sound/soc/codecs/wm2000.c @@ -650,6 +650,7 @@ static int wm2000_speaker_put(struct snd_kcontrol *kcontrol, } static const struct snd_kcontrol_new wm2000_controls[] = { + SOC_SINGLE("ANC Volume", WM2000_REG_ANC_GAIN_CTRL, 0, 255, 0), SOC_SINGLE_BOOL_EXT("WM2000 ANC Switch", 0, wm2000_anc_mode_get, wm2000_anc_mode_put), @@ -755,6 +756,8 @@ static int wm2000_probe(struct snd_soc_codec *codec) { struct wm2000_priv *wm2000 = dev_get_drvdata(codec->dev); + snd_soc_codec_set_cache_io(codec, 16, 8, SND_SOC_REGMAP); + /* This will trigger a transition to standby mode by default */ wm2000_anc_set_mode(wm2000); -- cgit v0.10.2