[PATCH 06/11] ASoC: codecs: rt298: Move irq registration and cleanup

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Currently irq is registered when i2c driver is loaded, it is unnecessary
when component is unused. Initialize irq only when we probe ASoC
component.

Signed-off-by: Amadeusz Sławiński <amadeuszx.slawinski@xxxxxxxxxxxxxxx>
Reviewed-by: Cezary Rojewski <cezary.rojewski@xxxxxxxxx>
---
 sound/soc/codecs/rt298.c | 43 +++++++++++++++++-----------------------
 1 file changed, 18 insertions(+), 25 deletions(-)

diff --git a/sound/soc/codecs/rt298.c b/sound/soc/codecs/rt298.c
index 1a27e5e63289..078810f2ec7b 100644
--- a/sound/soc/codecs/rt298.c
+++ b/sound/soc/codecs/rt298.c
@@ -1009,13 +1009,22 @@ static irqreturn_t rt298_irq(int irq, void *data)
 static int rt298_probe(struct snd_soc_component *component)
 {
 	struct rt298_priv *rt298 = snd_soc_component_get_drvdata(component);
+	int ret;
 
 	rt298->component = component;
 	INIT_DELAYED_WORK(&rt298->jack_detect_work, rt298_jack_detect_work);
 
-	if (rt298->i2c->irq)
-		schedule_delayed_work(&rt298->jack_detect_work,
-				      msecs_to_jiffies(1250));
+	if (rt298->i2c->irq) {
+		ret = request_threaded_irq(rt298->i2c->irq, NULL, rt298_irq,
+					   IRQF_TRIGGER_HIGH | IRQF_ONESHOT, "rt298", rt298);
+		if (ret) {
+			dev_err(&rt298->i2c->dev, "Failed to reguest IRQ: %d\n", ret);
+			return ret;
+		}
+
+		schedule_delayed_work(&rt298->jack_detect_work, msecs_to_jiffies(1250));
+	}
+
 	return 0;
 }
 
@@ -1023,7 +1032,12 @@ static void rt298_remove(struct snd_soc_component *component)
 {
 	struct rt298_priv *rt298 = snd_soc_component_get_drvdata(component);
 
-	cancel_delayed_work_sync(&rt298->jack_detect_work);
+	if (rt298->i2c->irq) {
+		cancel_delayed_work_sync(&rt298->jack_detect_work);
+
+		disable_irq(rt298->i2c->irq);
+		free_irq(rt298->i2c->irq, rt298);
+	}
 }
 
 #ifdef CONFIG_PM
@@ -1275,16 +1289,6 @@ static int rt298_i2c_probe(struct i2c_client *i2c)
 
 	rt298->is_hp_in = -1;
 
-	if (rt298->i2c->irq) {
-		ret = request_threaded_irq(rt298->i2c->irq, NULL, rt298_irq,
-			IRQF_TRIGGER_HIGH | IRQF_ONESHOT, "rt298", rt298);
-		if (ret != 0) {
-			dev_err(&i2c->dev,
-				"Failed to reguest IRQ: %d\n", ret);
-			return ret;
-		}
-	}
-
 	ret = devm_snd_soc_register_component(&i2c->dev,
 				     &soc_component_dev_rt298,
 				     rt298_dai, ARRAY_SIZE(rt298_dai));
@@ -1292,17 +1296,6 @@ static int rt298_i2c_probe(struct i2c_client *i2c)
 	return ret;
 }
 
-static int rt298_i2c_remove(struct i2c_client *i2c)
-{
-	struct rt298_priv *rt298 = i2c_get_clientdata(i2c);
-
-	if (i2c->irq)
-		free_irq(i2c->irq, rt298);
-
-	return 0;
-}
-
-
 static struct i2c_driver rt298_i2c_driver = {
 	.driver = {
 		   .name = "rt298",
-- 
2.25.1




[Index of Archives]     [ALSA User]     [Linux Audio Users]     [Pulse Audio]     [Kernel Archive]     [Asterisk PBX]     [Photo Sharing]     [Linux Sound]     [Video 4 Linux]     [Gimp]     [Yosemite News]

  Powered by Linux