aboutsummaryrefslogtreecommitdiffstats
path: root/sound/soc/codecs/max98095.c
diff options
context:
space:
mode:
Diffstat (limited to 'sound/soc/codecs/max98095.c')
-rw-r--r--sound/soc/codecs/max98095.c47
1 files changed, 39 insertions, 8 deletions
diff --git a/sound/soc/codecs/max98095.c b/sound/soc/codecs/max98095.c
index 03f0536e6f61..89ec00424880 100644
--- a/sound/soc/codecs/max98095.c
+++ b/sound/soc/codecs/max98095.c
@@ -15,6 +15,7 @@
15#include <linux/delay.h> 15#include <linux/delay.h>
16#include <linux/pm.h> 16#include <linux/pm.h>
17#include <linux/i2c.h> 17#include <linux/i2c.h>
18#include <linux/clk.h>
18#include <sound/core.h> 19#include <sound/core.h>
19#include <sound/pcm.h> 20#include <sound/pcm.h>
20#include <sound/pcm_params.h> 21#include <sound/pcm_params.h>
@@ -42,6 +43,7 @@ struct max98095_priv {
42 struct regmap *regmap; 43 struct regmap *regmap;
43 enum max98095_type devtype; 44 enum max98095_type devtype;
44 struct max98095_pdata *pdata; 45 struct max98095_pdata *pdata;
46 struct clk *mclk;
45 unsigned int sysclk; 47 unsigned int sysclk;
46 struct max98095_cdata dai[3]; 48 struct max98095_cdata dai[3];
47 const char **eq_texts; 49 const char **eq_texts;
@@ -612,7 +614,7 @@ static SOC_ENUM_SINGLE_DECL(max98095_dai3_dac_filter_enum,
612static int max98095_mic1pre_set(struct snd_kcontrol *kcontrol, 614static int max98095_mic1pre_set(struct snd_kcontrol *kcontrol,
613 struct snd_ctl_elem_value *ucontrol) 615 struct snd_ctl_elem_value *ucontrol)
614{ 616{
615 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); 617 struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol);
616 struct max98095_priv *max98095 = snd_soc_codec_get_drvdata(codec); 618 struct max98095_priv *max98095 = snd_soc_codec_get_drvdata(codec);
617 unsigned int sel = ucontrol->value.integer.value[0]; 619 unsigned int sel = ucontrol->value.integer.value[0];
618 620
@@ -626,7 +628,7 @@ static int max98095_mic1pre_set(struct snd_kcontrol *kcontrol,
626static int max98095_mic1pre_get(struct snd_kcontrol *kcontrol, 628static int max98095_mic1pre_get(struct snd_kcontrol *kcontrol,
627 struct snd_ctl_elem_value *ucontrol) 629 struct snd_ctl_elem_value *ucontrol)
628{ 630{
629 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); 631 struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol);
630 struct max98095_priv *max98095 = snd_soc_codec_get_drvdata(codec); 632 struct max98095_priv *max98095 = snd_soc_codec_get_drvdata(codec);
631 633
632 ucontrol->value.integer.value[0] = max98095->mic1pre; 634 ucontrol->value.integer.value[0] = max98095->mic1pre;
@@ -636,7 +638,7 @@ static int max98095_mic1pre_get(struct snd_kcontrol *kcontrol,
636static int max98095_mic2pre_set(struct snd_kcontrol *kcontrol, 638static int max98095_mic2pre_set(struct snd_kcontrol *kcontrol,
637 struct snd_ctl_elem_value *ucontrol) 639 struct snd_ctl_elem_value *ucontrol)
638{ 640{
639 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); 641 struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol);
640 struct max98095_priv *max98095 = snd_soc_codec_get_drvdata(codec); 642 struct max98095_priv *max98095 = snd_soc_codec_get_drvdata(codec);
641 unsigned int sel = ucontrol->value.integer.value[0]; 643 unsigned int sel = ucontrol->value.integer.value[0];
642 644
@@ -650,7 +652,7 @@ static int max98095_mic2pre_set(struct snd_kcontrol *kcontrol,
650static int max98095_mic2pre_get(struct snd_kcontrol *kcontrol, 652static int max98095_mic2pre_get(struct snd_kcontrol *kcontrol,
651 struct snd_ctl_elem_value *ucontrol) 653 struct snd_ctl_elem_value *ucontrol)
652{ 654{
653 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); 655 struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol);
654 struct max98095_priv *max98095 = snd_soc_codec_get_drvdata(codec); 656 struct max98095_priv *max98095 = snd_soc_codec_get_drvdata(codec);
655 657
656 ucontrol->value.integer.value[0] = max98095->mic2pre; 658 ucontrol->value.integer.value[0] = max98095->mic2pre;
@@ -1395,6 +1397,11 @@ static int max98095_dai_set_sysclk(struct snd_soc_dai *dai,
1395 if (freq == max98095->sysclk) 1397 if (freq == max98095->sysclk)
1396 return 0; 1398 return 0;
1397 1399
1400 if (!IS_ERR(max98095->mclk)) {
1401 freq = clk_round_rate(max98095->mclk, freq);
1402 clk_set_rate(max98095->mclk, freq);
1403 }
1404
1398 /* Setup clocks for slave mode, and using the PLL 1405 /* Setup clocks for slave mode, and using the PLL
1399 * PSCLK = 0x01 (when master clk is 10MHz to 20MHz) 1406 * PSCLK = 0x01 (when master clk is 10MHz to 20MHz)
1400 * 0x02 (when master clk is 20MHz to 40MHz).. 1407 * 0x02 (when master clk is 20MHz to 40MHz)..
@@ -1634,6 +1641,19 @@ static int max98095_set_bias_level(struct snd_soc_codec *codec,
1634 break; 1641 break;
1635 1642
1636 case SND_SOC_BIAS_PREPARE: 1643 case SND_SOC_BIAS_PREPARE:
1644 /*
1645 * SND_SOC_BIAS_PREPARE is called while preparing for a
1646 * transition to ON or away from ON. If current bias_level
1647 * is SND_SOC_BIAS_ON, then it is preparing for a transition
1648 * away from ON. Disable the clock in that case, otherwise
1649 * enable it.
1650 */
1651 if (!IS_ERR(max98095->mclk)) {
1652 if (codec->dapm.bias_level == SND_SOC_BIAS_ON)
1653 clk_disable_unprepare(max98095->mclk);
1654 else
1655 clk_prepare_enable(max98095->mclk);
1656 }
1637 break; 1657 break;
1638 1658
1639 case SND_SOC_BIAS_STANDBY: 1659 case SND_SOC_BIAS_STANDBY:
@@ -1737,7 +1757,7 @@ static int max98095_get_eq_channel(const char *name)
1737static int max98095_put_eq_enum(struct snd_kcontrol *kcontrol, 1757static int max98095_put_eq_enum(struct snd_kcontrol *kcontrol,
1738 struct snd_ctl_elem_value *ucontrol) 1758 struct snd_ctl_elem_value *ucontrol)
1739{ 1759{
1740 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); 1760 struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol);
1741 struct max98095_priv *max98095 = snd_soc_codec_get_drvdata(codec); 1761 struct max98095_priv *max98095 = snd_soc_codec_get_drvdata(codec);
1742 struct max98095_pdata *pdata = max98095->pdata; 1762 struct max98095_pdata *pdata = max98095->pdata;
1743 int channel = max98095_get_eq_channel(kcontrol->id.name); 1763 int channel = max98095_get_eq_channel(kcontrol->id.name);
@@ -1801,7 +1821,7 @@ static int max98095_put_eq_enum(struct snd_kcontrol *kcontrol,
1801static int max98095_get_eq_enum(struct snd_kcontrol *kcontrol, 1821static int max98095_get_eq_enum(struct snd_kcontrol *kcontrol,
1802 struct snd_ctl_elem_value *ucontrol) 1822 struct snd_ctl_elem_value *ucontrol)
1803{ 1823{
1804 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); 1824 struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol);
1805 struct max98095_priv *max98095 = snd_soc_codec_get_drvdata(codec); 1825 struct max98095_priv *max98095 = snd_soc_codec_get_drvdata(codec);
1806 int channel = max98095_get_eq_channel(kcontrol->id.name); 1826 int channel = max98095_get_eq_channel(kcontrol->id.name);
1807 struct max98095_cdata *cdata; 1827 struct max98095_cdata *cdata;
@@ -1891,7 +1911,7 @@ static int max98095_get_bq_channel(struct snd_soc_codec *codec,
1891static int max98095_put_bq_enum(struct snd_kcontrol *kcontrol, 1911static int max98095_put_bq_enum(struct snd_kcontrol *kcontrol,
1892 struct snd_ctl_elem_value *ucontrol) 1912 struct snd_ctl_elem_value *ucontrol)
1893{ 1913{
1894 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); 1914 struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol);
1895 struct max98095_priv *max98095 = snd_soc_codec_get_drvdata(codec); 1915 struct max98095_priv *max98095 = snd_soc_codec_get_drvdata(codec);
1896 struct max98095_pdata *pdata = max98095->pdata; 1916 struct max98095_pdata *pdata = max98095->pdata;
1897 int channel = max98095_get_bq_channel(codec, kcontrol->id.name); 1917 int channel = max98095_get_bq_channel(codec, kcontrol->id.name);
@@ -1952,7 +1972,7 @@ static int max98095_put_bq_enum(struct snd_kcontrol *kcontrol,
1952static int max98095_get_bq_enum(struct snd_kcontrol *kcontrol, 1972static int max98095_get_bq_enum(struct snd_kcontrol *kcontrol,
1953 struct snd_ctl_elem_value *ucontrol) 1973 struct snd_ctl_elem_value *ucontrol)
1954{ 1974{
1955 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); 1975 struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol);
1956 struct max98095_priv *max98095 = snd_soc_codec_get_drvdata(codec); 1976 struct max98095_priv *max98095 = snd_soc_codec_get_drvdata(codec);
1957 int channel = max98095_get_bq_channel(codec, kcontrol->id.name); 1977 int channel = max98095_get_bq_channel(codec, kcontrol->id.name);
1958 struct max98095_cdata *cdata; 1978 struct max98095_cdata *cdata;
@@ -2238,6 +2258,10 @@ static int max98095_probe(struct snd_soc_codec *codec)
2238 struct i2c_client *client; 2258 struct i2c_client *client;
2239 int ret = 0; 2259 int ret = 0;
2240 2260
2261 max98095->mclk = devm_clk_get(codec->dev, "mclk");
2262 if (PTR_ERR(max98095->mclk) == -EPROBE_DEFER)
2263 return -EPROBE_DEFER;
2264
2241 /* reset the codec, the DSP core, and disable all interrupts */ 2265 /* reset the codec, the DSP core, and disable all interrupts */
2242 max98095_reset(codec); 2266 max98095_reset(codec);
2243 2267
@@ -2399,10 +2423,17 @@ static const struct i2c_device_id max98095_i2c_id[] = {
2399}; 2423};
2400MODULE_DEVICE_TABLE(i2c, max98095_i2c_id); 2424MODULE_DEVICE_TABLE(i2c, max98095_i2c_id);
2401 2425
2426static const struct of_device_id max98095_of_match[] = {
2427 { .compatible = "maxim,max98095", },
2428 { }
2429};
2430MODULE_DEVICE_TABLE(of, max98095_of_match);
2431
2402static struct i2c_driver max98095_i2c_driver = { 2432static struct i2c_driver max98095_i2c_driver = {
2403 .driver = { 2433 .driver = {
2404 .name = "max98095", 2434 .name = "max98095",
2405 .owner = THIS_MODULE, 2435 .owner = THIS_MODULE,
2436 .of_match_table = of_match_ptr(max98095_of_match),
2406 }, 2437 },
2407 .probe = max98095_i2c_probe, 2438 .probe = max98095_i2c_probe,
2408 .remove = max98095_i2c_remove, 2439 .remove = max98095_i2c_remove,