All of lore.kernel.org
 help / color / mirror / Atom feed
From: Marek Vasut <marek.vasut@gmail.com>
To: Mark Brown <broonie@opensource.wolfsonmicro.com>,
	avorontsov@ru.mvista.com, Takashi Iwai <tiwai@suse.de>,
	Eric Miao <eric.y.miao@gmail.com>,
	alsa-devel@alsa-project.org, Russell King
Subject: [PATCH 4/4] Let wm97xx-battery use irq to detect charger state
Date: Thu, 23 Jul 2009 16:20:00 +0200	[thread overview]
Message-ID: <200907231620.01064.marek.vasut@gmail.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 323 bytes --]

Hi,

I split the "[PATCH 3/4] Convert WM97xx driver to use platform_data" patch 
into three smaller as Mark requested. These three will be:

[PATCH 2/4] Make wm97xx-core pass platform_data to battery, ts
[PATCH 3/4] Convert WM97xx battery to use platform_data
[PATCH 4/4] Let wm97xx-battery use irq to detect charger state

[-- Attachment #2: 0004-Let-wm97xx-battery-use-irq-to-detect-charger-state.patch --]
[-- Type: text/x-patch, Size: 2966 bytes --]

From 9dbdca1d8e9d0f66b0d3fa5b829c8dd438f8e2d5 Mon Sep 17 00:00:00 2001
From: root <root@rin.(none)>
Date: Thu, 23 Jul 2009 16:02:08 +0200
Subject: [PATCH 4/4] Let wm97xx-battery use irq to detect charger state

Signed-off-by: Marek Vasut <marek.vasut@gmail.com>
---
 drivers/power/wm97xx_battery.c |   30 ++++++++++++++++++++++++------
 1 files changed, 24 insertions(+), 6 deletions(-)

diff --git a/drivers/power/wm97xx_battery.c b/drivers/power/wm97xx_battery.c
index 9e38f4b..bda1c79 100644
--- a/drivers/power/wm97xx_battery.c
+++ b/drivers/power/wm97xx_battery.c
@@ -22,6 +22,7 @@
 #include <linux/spinlock.h>
 #include <linux/interrupt.h>
 #include <linux/gpio.h>
+#include <linux/irq.h>
 
 static DEFINE_MUTEX(bat_lock);
 static struct work_struct bat_work;
@@ -135,6 +136,12 @@ static void wm97xx_bat_work(struct work_struct *work)
 	wm97xx_bat_update(&bat_ps);
 }
 
+static irqreturn_t wm97xx_chrg_irq(int irq, void *data)
+{
+	schedule_work(&bat_work);
+	return IRQ_HANDLED;
+}
+
 #ifdef CONFIG_PM
 static int wm97xx_bat_suspend(struct platform_device *dev, pm_message_t state)
 {
@@ -170,13 +177,18 @@ static int __devinit wm97xx_bat_probe(struct platform_device *dev)
 		return -EINVAL;
 	}
 
-	if (pdata->charge_gpio >= 0 && gpio_is_valid(pdata->charge_gpio)) {
+	if (gpio_is_valid(pdata->charge_gpio)) {
 		ret = gpio_request(pdata->charge_gpio, "BATT CHRG");
 		if (ret)
 			goto err;
 		ret = gpio_direction_input(pdata->charge_gpio);
 		if (ret)
 			goto err2;
+		ret = request_irq(gpio_to_irq(pdata->charge_gpio),
+				wm97xx_chrg_irq, IRQF_DISABLED,
+				"AC Detect", 0);
+		if (ret)
+			goto err2;
 		props++;	/* POWER_SUPPLY_PROP_STATUS */
 	}
 
@@ -193,7 +205,7 @@ static int __devinit wm97xx_bat_probe(struct platform_device *dev)
 
 	prop = kzalloc(props * sizeof(*prop), GFP_KERNEL);
 	if (!prop)
-		goto err2;
+		goto err3;
 
 	prop[i++] = POWER_SUPPLY_PROP_PRESENT;
 	if (pdata->charge_gpio >= 0)
@@ -226,13 +238,17 @@ static int __devinit wm97xx_bat_probe(struct platform_device *dev)
 	if (!ret)
 		schedule_work(&bat_work);
 	else
-		goto err3;
+		goto err4;
 
 	return 0;
-err3:
+err4:
 	kfree(prop);
+err3:
+	if (gpio_is_valid(pdata->charge_gpio))
+		free_irq(gpio_to_irq(pdata->charge_gpio), dev);
 err2:
-	gpio_free(pdata->charge_gpio);
+	if (gpio_is_valid(pdata->charge_gpio))
+		gpio_free(pdata->charge_gpio);
 err:
 	return ret;
 }
@@ -242,8 +258,10 @@ static int __devexit wm97xx_bat_remove(struct platform_device *dev)
 	struct wm97xx_pdata *wmdata = dev->dev.platform_data;
 	struct wm97xx_batt_pdata *pdata = wmdata->batt_pdata;
 
-	if (pdata && pdata->charge_gpio && pdata->charge_gpio >= 0)
+	if (pdata && gpio_is_valid(pdata->charge_gpio)) {
+		free_irq(gpio_to_irq(pdata->charge_gpio), dev);
 		gpio_free(pdata->charge_gpio);
+	}
 	flush_scheduled_work();
 	power_supply_unregister(&bat_ps);
 	kfree(prop);
-- 
1.6.3.3


[-- Attachment #3: Type: text/plain, Size: 160 bytes --]

_______________________________________________
Alsa-devel mailing list
Alsa-devel@alsa-project.org
http://mailman.alsa-project.org/mailman/listinfo/alsa-devel

                 reply	other threads:[~2009-07-23 14:20 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=200907231620.01064.marek.vasut@gmail.com \
    --to=marek.vasut@gmail.com \
    --cc=alsa-devel@alsa-project.org \
    --cc=avorontsov@ru.mvista.com \
    --cc=broonie@opensource.wolfsonmicro.com \
    --cc=eric.y.miao@gmail.com \
    --cc=tiwai@suse.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.