Skip to content

Commit ca50410

Browse files
committed
ASoC: wm8962: Move interrupt initalisation to probe()
This is more idiomatic and fixes bugs in the error handling paths. Signed-off-by: Mark Brown <broonie@linaro.org>
1 parent 61e6cfa commit ca50410

File tree

1 file changed

+33
-35
lines changed

1 file changed

+33
-35
lines changed

sound/soc/codecs/wm8962.c

Lines changed: 33 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -3377,7 +3377,7 @@ static int wm8962_probe(struct snd_soc_codec *codec)
33773377
int ret;
33783378
struct wm8962_priv *wm8962 = snd_soc_codec_get_drvdata(codec);
33793379
struct wm8962_pdata *pdata = &wm8962->pdata;
3380-
int i, trigger, irq_pol;
3380+
int i;
33813381
bool dmicclk, dmicdat;
33823382

33833383
wm8962->codec = codec;
@@ -3506,36 +3506,6 @@ static int wm8962_probe(struct snd_soc_codec *codec)
35063506
wm8962_init_beep(codec);
35073507
wm8962_init_gpio(codec);
35083508

3509-
if (wm8962->irq) {
3510-
if (pdata->irq_active_low) {
3511-
trigger = IRQF_TRIGGER_LOW;
3512-
irq_pol = WM8962_IRQ_POL;
3513-
} else {
3514-
trigger = IRQF_TRIGGER_HIGH;
3515-
irq_pol = 0;
3516-
}
3517-
3518-
snd_soc_update_bits(codec, WM8962_INTERRUPT_CONTROL,
3519-
WM8962_IRQ_POL, irq_pol);
3520-
3521-
ret = request_threaded_irq(wm8962->irq, NULL, wm8962_irq,
3522-
trigger | IRQF_ONESHOT,
3523-
"wm8962", codec->dev);
3524-
if (ret != 0) {
3525-
dev_err(codec->dev, "Failed to request IRQ %d: %d\n",
3526-
wm8962->irq, ret);
3527-
wm8962->irq = 0;
3528-
/* Non-fatal */
3529-
} else {
3530-
/* Enable some IRQs by default */
3531-
snd_soc_update_bits(codec,
3532-
WM8962_INTERRUPT_STATUS_2_MASK,
3533-
WM8962_FLL_LOCK_EINT |
3534-
WM8962_TEMP_SHUT_EINT |
3535-
WM8962_FIFOS_ERR_EINT, 0);
3536-
}
3537-
}
3538-
35393509
return 0;
35403510
}
35413511

@@ -3544,9 +3514,6 @@ static int wm8962_remove(struct snd_soc_codec *codec)
35443514
struct wm8962_priv *wm8962 = snd_soc_codec_get_drvdata(codec);
35453515
int i;
35463516

3547-
if (wm8962->irq)
3548-
free_irq(wm8962->irq, codec);
3549-
35503517
cancel_delayed_work_sync(&wm8962->mic_work);
35513518

35523519
wm8962_free_gpio(codec);
@@ -3619,7 +3586,7 @@ static int wm8962_i2c_probe(struct i2c_client *i2c,
36193586
struct wm8962_pdata *pdata = dev_get_platdata(&i2c->dev);
36203587
struct wm8962_priv *wm8962;
36213588
unsigned int reg;
3622-
int ret, i;
3589+
int ret, i, irq_pol, trigger;
36233590

36243591
wm8962 = devm_kzalloc(&i2c->dev, sizeof(struct wm8962_priv),
36253592
GFP_KERNEL);
@@ -3714,6 +3681,37 @@ static int wm8962_i2c_probe(struct i2c_client *i2c,
37143681
ret);
37153682
}
37163683

3684+
if (wm8962->irq) {
3685+
if (pdata->irq_active_low) {
3686+
trigger = IRQF_TRIGGER_LOW;
3687+
irq_pol = WM8962_IRQ_POL;
3688+
} else {
3689+
trigger = IRQF_TRIGGER_HIGH;
3690+
irq_pol = 0;
3691+
}
3692+
3693+
regmap_update_bits(wm8962->regmap, WM8962_INTERRUPT_CONTROL,
3694+
WM8962_IRQ_POL, irq_pol);
3695+
3696+
ret = devm_request_threaded_irq(&i2c->dev, wm8962->irq, NULL,
3697+
wm8962_irq,
3698+
trigger | IRQF_ONESHOT,
3699+
"wm8962", &i2c->dev);
3700+
if (ret != 0) {
3701+
dev_err(&i2c->dev, "Failed to request IRQ %d: %d\n",
3702+
wm8962->irq, ret);
3703+
wm8962->irq = 0;
3704+
/* Non-fatal */
3705+
} else {
3706+
/* Enable some IRQs by default */
3707+
regmap_update_bits(wm8962->regmap,
3708+
WM8962_INTERRUPT_STATUS_2_MASK,
3709+
WM8962_FLL_LOCK_EINT |
3710+
WM8962_TEMP_SHUT_EINT |
3711+
WM8962_FIFOS_ERR_EINT, 0);
3712+
}
3713+
}
3714+
37173715
pm_runtime_enable(&i2c->dev);
37183716
pm_request_idle(&i2c->dev);
37193717

0 commit comments

Comments
 (0)