aboutsummaryrefslogtreecommitdiffstats
path: root/sound/soc/codecs/max98088.c
diff options
context:
space:
mode:
Diffstat (limited to 'sound/soc/codecs/max98088.c')
-rw-r--r--sound/soc/codecs/max98088.c147
1 files changed, 134 insertions, 13 deletions
diff --git a/sound/soc/codecs/max98088.c b/sound/soc/codecs/max98088.c
index 4173b67c94d..e2ad10d2dea 100644
--- a/sound/soc/codecs/max98088.c
+++ b/sound/soc/codecs/max98088.c
@@ -25,6 +25,7 @@
25#include <linux/slab.h> 25#include <linux/slab.h>
26#include <asm/div64.h> 26#include <asm/div64.h>
27#include <sound/max98088.h> 27#include <sound/max98088.h>
28#include <sound/jack.h>
28#include "max98088.h" 29#include "max98088.h"
29 30
30enum max98088_type { 31enum max98088_type {
@@ -54,6 +55,8 @@ struct max98088_priv {
54 unsigned int mic1pre; 55 unsigned int mic1pre;
55 unsigned int mic2pre; 56 unsigned int mic2pre;
56 unsigned int extmic_mode; 57 unsigned int extmic_mode;
58 int irq;
59 struct snd_soc_jack *headset_jack;
57}; 60};
58 61
59static const u8 max98088_reg[M98088_REG_CNT] = { 62static const u8 max98088_reg[M98088_REG_CNT] = {
@@ -803,6 +806,7 @@ static const struct snd_kcontrol_new max98088_snd_controls[] = {
803 806
804 SOC_SINGLE("THD Limiter Threshold", M98088_REG_46_THDLMT_CFG, 4, 15, 0), 807 SOC_SINGLE("THD Limiter Threshold", M98088_REG_46_THDLMT_CFG, 4, 15, 0),
805 SOC_SINGLE("THD Limiter Time", M98088_REG_46_THDLMT_CFG, 0, 7, 0), 808 SOC_SINGLE("THD Limiter Time", M98088_REG_46_THDLMT_CFG, 0, 7, 0),
809 SOC_SINGLE("Digital Mic Enable", M98088_REG_48_CFG_MIC, 4, 3, 0),
806}; 810};
807 811
808/* Left speaker mixer switch */ 812/* Left speaker mixer switch */
@@ -1397,8 +1401,6 @@ static int max98088_dai_set_sysclk(struct snd_soc_dai *dai,
1397 if (freq == max98088->sysclk) 1401 if (freq == max98088->sysclk)
1398 return 0; 1402 return 0;
1399 1403
1400 max98088->sysclk = freq; /* remember current sysclk */
1401
1402 /* Setup clocks for slave mode, and using the PLL 1404 /* Setup clocks for slave mode, and using the PLL
1403 * PSCLK = 0x01 (when master clk is 10MHz to 20MHz) 1405 * PSCLK = 0x01 (when master clk is 10MHz to 20MHz)
1404 * 0x02 (when master clk is 20MHz to 30MHz).. 1406 * 0x02 (when master clk is 20MHz to 30MHz)..
@@ -1598,7 +1600,7 @@ static int max98088_dai2_digital_mute(struct snd_soc_dai *codec_dai, int mute)
1598 1600
1599static void max98088_sync_cache(struct snd_soc_codec *codec) 1601static void max98088_sync_cache(struct snd_soc_codec *codec)
1600{ 1602{
1601 u16 *reg_cache = codec->reg_cache; 1603 u8 *reg_cache = codec->reg_cache;
1602 int i; 1604 int i;
1603 1605
1604 if (!codec->cache_sync) 1606 if (!codec->cache_sync)
@@ -1636,6 +1638,9 @@ static int max98088_set_bias_level(struct snd_soc_codec *codec,
1636 if (codec->dapm.bias_level == SND_SOC_BIAS_OFF) 1638 if (codec->dapm.bias_level == SND_SOC_BIAS_OFF)
1637 max98088_sync_cache(codec); 1639 max98088_sync_cache(codec);
1638 1640
1641 snd_soc_update_bits(codec, M98088_REG_51_PWR_SYS,
1642 M98088_SHDNRUN, M98088_SHDNRUN);
1643
1639 snd_soc_update_bits(codec, M98088_REG_4C_PWR_EN_IN, 1644 snd_soc_update_bits(codec, M98088_REG_4C_PWR_EN_IN,
1640 M98088_MBEN, M98088_MBEN); 1645 M98088_MBEN, M98088_MBEN);
1641 break; 1646 break;
@@ -1643,6 +1648,8 @@ static int max98088_set_bias_level(struct snd_soc_codec *codec,
1643 case SND_SOC_BIAS_OFF: 1648 case SND_SOC_BIAS_OFF:
1644 snd_soc_update_bits(codec, M98088_REG_4C_PWR_EN_IN, 1649 snd_soc_update_bits(codec, M98088_REG_4C_PWR_EN_IN,
1645 M98088_MBEN, 0); 1650 M98088_MBEN, 0);
1651 snd_soc_update_bits(codec, M98088_REG_51_PWR_SYS,
1652 M98088_SHDNRUN, 0);
1646 codec->cache_sync = 1; 1653 codec->cache_sync = 1;
1647 break; 1654 break;
1648 } 1655 }
@@ -1910,6 +1917,7 @@ static void max98088_handle_pdata(struct snd_soc_codec *codec)
1910 struct max98088_priv *max98088 = snd_soc_codec_get_drvdata(codec); 1917 struct max98088_priv *max98088 = snd_soc_codec_get_drvdata(codec);
1911 struct max98088_pdata *pdata = max98088->pdata; 1918 struct max98088_pdata *pdata = max98088->pdata;
1912 u8 regval = 0; 1919 u8 regval = 0;
1920 unsigned int debounce_time;
1913 1921
1914 if (!pdata) { 1922 if (!pdata) {
1915 dev_dbg(codec->dev, "No platform data\n"); 1923 dev_dbg(codec->dev, "No platform data\n");
@@ -1935,26 +1943,98 @@ static void max98088_handle_pdata(struct snd_soc_codec *codec)
1935 /* Configure equalizers */ 1943 /* Configure equalizers */
1936 if (pdata->eq_cfgcnt) 1944 if (pdata->eq_cfgcnt)
1937 max98088_handle_eq_pdata(codec); 1945 max98088_handle_eq_pdata(codec);
1946
1947 /* Configure the debounce time */
1948 if (max98088->irq) {
1949 switch (pdata->debounce_time_ms) {
1950 case 25:
1951 debounce_time = M98088_JDEB_25;
1952 break;
1953 case 50:
1954 debounce_time = M98088_JDEB_50;
1955 break;
1956 case 100:
1957 debounce_time = M98088_JDEB_100;
1958 break;
1959 case 200:
1960 default:
1961 debounce_time = M98088_JDEB_200;
1962 }
1963 snd_soc_update_bits(codec, M98088_REG_4B_CFG_JACKDET,
1964 M98088_JDEB, debounce_time);
1965 }
1938} 1966}
1939 1967
1940#ifdef CONFIG_PM 1968int max98088_report_jack(struct snd_soc_codec *codec)
1941static int max98088_suspend(struct snd_soc_codec *codec, pm_message_t state)
1942{ 1969{
1943 max98088_set_bias_level(codec, SND_SOC_BIAS_OFF); 1970 struct max98088_priv *max98088 = snd_soc_codec_get_drvdata(codec);
1971 unsigned int value;
1972 int jack_report = 0;
1973
1974 /* Read the Jack Status Register*/
1975 value = snd_soc_read(codec, M98088_REG_02_JACK_STAUS);
1976
1977 if ((value & M98088_JKSNS_7) == 0)
1978 jack_report |= SND_JACK_HEADPHONE;
1979 if (value & M98088_JKSNS_6)
1980 jack_report |= SND_JACK_MICROPHONE;
1981
1982 snd_soc_jack_report(max98088->headset_jack,
1983 jack_report, SND_JACK_HEADSET);
1944 1984
1945 return 0; 1985 return 0;
1946} 1986}
1947 1987
1948static int max98088_resume(struct snd_soc_codec *codec) 1988static irqreturn_t max98088_jack_handler(int irq, void *data)
1949{ 1989{
1950 max98088_set_bias_level(codec, SND_SOC_BIAS_STANDBY); 1990 struct snd_soc_codec *codec = data;
1991
1992 /*clear the interrupt by reading the status register */
1993 snd_soc_read(codec, M98088_REG_00_IRQ_STATUS);
1994 max98088_report_jack(codec);
1995
1996 return IRQ_HANDLED;
1997}
1998
1999int max98088_headset_detect(struct snd_soc_codec *codec,
2000 struct snd_soc_jack *jack, enum snd_jack_types type)
2001{
2002 struct max98088_priv *max98088 = snd_soc_codec_get_drvdata(codec);
2003 max98088->headset_jack = jack;
2004
2005 if (max98088->irq) {
2006 if (type & SND_JACK_HEADSET) {
2007 /* headphone + microphone detection */
2008 snd_soc_update_bits(codec, M98088_REG_4E_BIAS_CNTL,
2009 M98088_JDWK, 0);
2010 } else {
2011 /* headphone detection only*/
2012 snd_soc_update_bits(codec, M98088_REG_4E_BIAS_CNTL,
2013 M98088_JDWK, 1);
2014 }
2015 /* Enable the Jack Detection Circuitry */
2016 snd_soc_update_bits(codec, M98088_REG_4B_CFG_JACKDET,
2017 M98088_JDETEN, M98088_JDETEN);
2018
2019 /*JDET is always set the first time JDETEN is set,
2020 so clear it*/
2021 snd_soc_read(codec, M98088_REG_00_IRQ_STATUS);
2022
2023 /*after setting JDETEN, JKSNS would be set after hw
2024 debounce time so wait before reading the status*/
2025 msleep(max98088->pdata->debounce_time_ms);
2026
2027 /*report jack status at boot-up*/
2028 max98088_report_jack(codec);
2029
2030 /*Enable the jack detection interrupt*/
2031 snd_soc_update_bits(codec, M98088_REG_0F_IRQ_ENABLE,
2032 M98088_IJDET, M98088_IJDET);
2033 }
1951 2034
1952 return 0; 2035 return 0;
1953} 2036}
1954#else 2037EXPORT_SYMBOL_GPL(max98088_headset_detect);
1955#define max98088_suspend NULL
1956#define max98088_resume NULL
1957#endif
1958 2038
1959static int max98088_probe(struct snd_soc_codec *codec) 2039static int max98088_probe(struct snd_soc_codec *codec)
1960{ 2040{
@@ -1963,6 +2043,7 @@ static int max98088_probe(struct snd_soc_codec *codec)
1963 int ret = 0; 2043 int ret = 0;
1964 2044
1965 codec->cache_sync = 1; 2045 codec->cache_sync = 1;
2046 codec->dapm.idle_bias_off = 1;
1966 2047
1967 ret = snd_soc_codec_set_cache_io(codec, 8, 8, SND_SOC_I2C); 2048 ret = snd_soc_codec_set_cache_io(codec, 8, 8, SND_SOC_I2C);
1968 if (ret != 0) { 2049 if (ret != 0) {
@@ -1993,13 +2074,26 @@ static int max98088_probe(struct snd_soc_codec *codec)
1993 max98088->mic2pre = 0; 2074 max98088->mic2pre = 0;
1994 2075
1995 ret = snd_soc_read(codec, M98088_REG_FF_REV_ID); 2076 ret = snd_soc_read(codec, M98088_REG_FF_REV_ID);
1996 if (ret < 0) { 2077 if (ret != 0x40) {
1997 dev_err(codec->dev, "Failed to read device revision: %d\n", 2078 dev_err(codec->dev, "Failed to read device revision: %d\n",
1998 ret); 2079 ret);
2080 ret = -ENODEV;
1999 goto err_access; 2081 goto err_access;
2000 } 2082 }
2001 dev_info(codec->dev, "revision %c\n", ret + 'A'); 2083 dev_info(codec->dev, "revision %c\n", ret + 'A');
2002 2084
2085 if (max98088->irq) {
2086 /* register an audio interrupt */
2087 ret = request_threaded_irq(max98088->irq, NULL,
2088 max98088_jack_handler,
2089 IRQF_TRIGGER_FALLING,
2090 "max98088", codec);
2091 if (ret) {
2092 dev_err(codec->dev, "Failed to request IRQ: %d\n", ret);
2093 goto err_access;
2094 }
2095 }
2096
2003 snd_soc_write(codec, M98088_REG_51_PWR_SYS, M98088_PWRSV); 2097 snd_soc_write(codec, M98088_REG_51_PWR_SYS, M98088_PWRSV);
2004 2098
2005 /* initialize registers cache to hardware default */ 2099 /* initialize registers cache to hardware default */
@@ -2039,6 +2133,32 @@ static int max98088_remove(struct snd_soc_codec *codec)
2039 return 0; 2133 return 0;
2040} 2134}
2041 2135
2136#ifdef CONFIG_PM
2137static int max98088_suspend(struct snd_soc_codec *codec, pm_message_t state)
2138{
2139 struct max98088_priv *max98088 = snd_soc_codec_get_drvdata(codec);
2140
2141 disable_irq(max98088->irq);
2142 max98088_set_bias_level(codec, SND_SOC_BIAS_OFF);
2143
2144 return 0;
2145}
2146
2147static int max98088_resume(struct snd_soc_codec *codec)
2148{
2149 struct max98088_priv *max98088 = snd_soc_codec_get_drvdata(codec);
2150
2151 max98088_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
2152 max98088_report_jack(codec);
2153 enable_irq(max98088->irq);
2154
2155 return 0;
2156}
2157#else
2158#define max98088_suspend NULL
2159#define max98088_resume NULL
2160#endif
2161
2042static struct snd_soc_codec_driver soc_codec_dev_max98088 = { 2162static struct snd_soc_codec_driver soc_codec_dev_max98088 = {
2043 .probe = max98088_probe, 2163 .probe = max98088_probe,
2044 .remove = max98088_remove, 2164 .remove = max98088_remove,
@@ -2070,6 +2190,7 @@ static int max98088_i2c_probe(struct i2c_client *i2c,
2070 i2c_set_clientdata(i2c, max98088); 2190 i2c_set_clientdata(i2c, max98088);
2071 max98088->control_data = i2c; 2191 max98088->control_data = i2c;
2072 max98088->pdata = i2c->dev.platform_data; 2192 max98088->pdata = i2c->dev.platform_data;
2193 max98088->irq = i2c->irq;
2073 2194
2074 ret = snd_soc_register_codec(&i2c->dev, 2195 ret = snd_soc_register_codec(&i2c->dev,
2075 &soc_codec_dev_max98088, &max98088_dai[0], 2); 2196 &soc_codec_dev_max98088, &max98088_dai[0], 2);