]> git.karo-electronics.de Git - linux-beck.git/blobdiff - sound/soc/codecs/wm8962.c
ASoC: Initial WM8962 IRQ support
[linux-beck.git] / sound / soc / codecs / wm8962.c
index 58ba2d3ca5339eefe285c57bf5d483084fd0e36e..4fa5de873c8b2b8792e119d219a8da60fa958106 100644 (file)
@@ -1342,7 +1342,7 @@ static int wm8962_set_fll(struct snd_soc_dai *dai, int fll_id, int source,
        struct wm8962_priv *wm8962 = snd_soc_codec_get_drvdata(codec);
        struct _fll_div fll_div;
        int ret;
-       int fll1 = snd_soc_read(codec, WM8962_FLL_CONTROL_1);
+       int fll1 = snd_soc_read(codec, WM8962_FLL_CONTROL_1) & WM8962_FLL_ENA;
 
        /* Any change? */
        if (source == wm8962->fll_src && Fref == wm8962->fll_fref &&
@@ -1461,6 +1461,29 @@ static struct snd_soc_dai_driver wm8962_dai = {
        .symmetric_rates = 1,
 };
 
+static irqreturn_t wm8962_irq(int irq, void *data)
+{
+       struct snd_soc_codec *codec = data;
+       int mask;
+       int active;
+
+       mask = snd_soc_read(codec, WM8962_INTERRUPT_STATUS_2);
+
+       active = snd_soc_read(codec, WM8962_INTERRUPT_STATUS_2);
+       active &= ~mask;
+
+       if (active & WM8962_FIFOS_ERR_EINT)
+               dev_err(codec->dev, "FIFO error\n");
+
+       if (active & WM8962_TEMP_SHUT_EINT)
+               dev_crit(codec->dev, "Thermal shutdown\n");
+
+       /* Acknowledge the interrupts */
+       snd_soc_write(codec, WM8962_INTERRUPT_STATUS_2, active);
+
+       return IRQ_HANDLED;
+}
+
 #ifdef CONFIG_PM
 static int wm8962_resume(struct snd_soc_codec *codec)
 {
@@ -1632,7 +1655,9 @@ static int wm8962_probe(struct snd_soc_codec *codec)
        int ret;
        struct wm8962_priv *wm8962 = snd_soc_codec_get_drvdata(codec);
        struct wm8962_pdata *pdata = dev_get_platdata(codec->dev);
-       int i;
+       struct i2c_client *i2c = container_of(codec->dev, struct i2c_client,
+                                             dev);
+       int i, trigger, irq_pol;
 
        wm8962->codec = codec;
 
@@ -1744,12 +1769,38 @@ static int wm8962_probe(struct snd_soc_codec *codec)
        wm8962->reg_cache[WM8962_HPOUTL_VOLUME] |= WM8962_HPOUT_VU;
        wm8962->reg_cache[WM8962_HPOUTR_VOLUME] |= WM8962_HPOUT_VU;
 
-       snd_soc_add_controls(codec, wm8962_snd_controls,
-                            ARRAY_SIZE(wm8962_snd_controls));
        wm8962_add_widgets(codec);
 
        wm8962_init_beep(codec);
 
+       if (i2c->irq) {
+               if (pdata && pdata->irq_active_low) {
+                       trigger = IRQF_TRIGGER_LOW;
+                       irq_pol = WM8962_IRQ_POL;
+               } else {
+                       trigger = IRQF_TRIGGER_HIGH;
+                       irq_pol = 0;
+               }
+
+               snd_soc_update_bits(codec, WM8962_INTERRUPT_CONTROL,
+                                   WM8962_IRQ_POL, irq_pol);
+
+               ret = request_threaded_irq(i2c->irq, NULL, wm8962_irq,
+                                          trigger | IRQF_ONESHOT,
+                                          "wm8962", codec);
+               if (ret != 0) {
+                       dev_err(codec->dev, "Failed to request IRQ %d: %d\n",
+                               i2c->irq, ret);
+                       /* Non-fatal */
+               } else {
+                       /* Enable error reporting IRQs by default */
+                       snd_soc_update_bits(codec,
+                                           WM8962_INTERRUPT_STATUS_2_MASK,
+                                           WM8962_TEMP_SHUT_EINT |
+                                           WM8962_FIFOS_ERR_EINT, 0);
+               }
+       }
+
        return 0;
 
 err_enable:
@@ -1764,8 +1815,13 @@ err:
 static int wm8962_remove(struct snd_soc_codec *codec)
 {
        struct wm8962_priv *wm8962 = snd_soc_codec_get_drvdata(codec);
+       struct i2c_client *i2c = container_of(codec->dev, struct i2c_client,
+                                             dev);
        int i;
 
+       if (i2c->irq)
+               free_irq(i2c->irq, codec);
+
        wm8962_free_beep(codec);
        for (i = 0; i < ARRAY_SIZE(wm8962->supplies); i++)
                regulator_unregister_notifier(wm8962->supplies[i].consumer,
@@ -1780,7 +1836,7 @@ static struct snd_soc_codec_driver soc_codec_dev_wm8962 = {
        .remove =       wm8962_remove,
        .resume =       wm8962_resume,
        .set_bias_level = wm8962_set_bias_level,
-       .reg_cache_size = WM8962_MAX_REGISTER,
+       .reg_cache_size = WM8962_MAX_REGISTER + 1,
        .reg_word_size = sizeof(u16),
        .reg_cache_default = wm8962_reg,
        .volatile_register = wm8962_volatile_register,
@@ -1823,7 +1879,7 @@ MODULE_DEVICE_TABLE(i2c, wm8962_i2c_id);
 
 static struct i2c_driver wm8962_i2c_driver = {
        .driver = {
-               .name = "WM8962",
+               .name = "wm8962",
                .owner = THIS_MODULE,
        },
        .probe =    wm8962_i2c_probe,