public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Anton Vorontsov <cbouatmailru@gmail.com>
To: Dmitry Baryshkov <dbaryshkov@gmail.com>
Cc: linux-kernel@vger.kernel.org, cbou@mail.ru, dwmw2@infradead.org
Subject: [PATCH 2/2] pda_power: implement polling
Date: Fri, 4 Jan 2008 03:32:43 +0300	[thread overview]
Message-ID: <20080104003243.GB12308@zarina> (raw)
In-Reply-To: <20080104002907.GA767@zarina>


Signed-off-by: Anton Vorontsov <cbouatmailru@gmail.com>
---

Untested, just to show the idea.

 drivers/power/pda_power.c |   40 ++++++++++++++++++++++++++++++++++++++++
 include/linux/pda_power.h |    1 +
 2 files changed, 41 insertions(+), 0 deletions(-)

diff --git a/drivers/power/pda_power.c b/drivers/power/pda_power.c
index 153e3b1..8e9aec3 100644
--- a/drivers/power/pda_power.c
+++ b/drivers/power/pda_power.c
@@ -32,6 +32,8 @@ static struct pda_power_pdata *pdata;
 static struct resource *ac_irq, *usb_irq;
 static struct timer_list charger_timer;
 static struct timer_list supply_timer;
+static struct timer_list polling_timer;
+static int polling;
 
 enum {
 	PDA_PSY_OFFLINE = 0,
@@ -166,6 +168,28 @@ static irqreturn_t power_changed_isr(int irq, void *power_supply)
 	return IRQ_HANDLED;
 }
 
+static void polling_timer_func(unsigned long unused)
+{
+	int changed = 0;
+
+	dev_vdbg(dev, "polling...\n");
+
+	update_status();
+
+	if (!ac_irq && new_ac_status != ac_status) {
+		ac_status = PDA_PSY_TO_CHANGE;
+		changed = 1;
+	}
+
+	if (!usb_irq && new_usb_status != usb_status) {
+		usb_status = PDA_PSY_TO_CHANGE;
+		changed = 1;
+	}
+
+	if (changed)
+		psy_changed();
+}
+
 static int pda_power_probe(struct platform_device *pdev)
 {
 	int ret = 0;
@@ -190,6 +214,9 @@ static int pda_power_probe(struct platform_device *pdev)
 	if (!pdata->wait_for_charger)
 		pdata->wait_for_charger = 500;
 
+	if (!pdata->polling_interval)
+		pdata->polling_interval = 2000;
+
 	setup_timer(&charger_timer, charger_timer_func, 0);
 	setup_timer(&supply_timer, supply_timer_func, 0);
 
@@ -219,6 +246,8 @@ static int pda_power_probe(struct platform_device *pdev)
 				dev_err(dev, "request ac irq failed\n");
 				goto ac_irq_failed;
 			}
+		} else {
+			polling = 1;
 		}
 	}
 
@@ -238,9 +267,18 @@ static int pda_power_probe(struct platform_device *pdev)
 				dev_err(dev, "request usb irq failed\n");
 				goto usb_irq_failed;
 			}
+		} else {
+			polling = 1;
 		}
 	}
 
+	if (polling) {
+		dev_dbg(dev, "will poll for status\n");
+		setup_timer(&polling_timer, polling_timer_func, 0);
+		mod_timer(&polling_timer,
+			  jiffies + msecs_to_jiffies(pdata->polling_interval));
+	}
+
 	return 0;
 
 usb_irq_failed:
@@ -264,6 +302,8 @@ static int pda_power_remove(struct platform_device *pdev)
 	if (pdata->is_ac_online && ac_irq)
 		free_irq(ac_irq->start, &pda_psy_ac);
 
+	if (polling)
+		del_timer_sync(&polling_timer);
 	del_timer_sync(&charger_timer);
 	del_timer_sync(&supply_timer);
 
diff --git a/include/linux/pda_power.h b/include/linux/pda_power.h
index 1375f15..225beb1 100644
--- a/include/linux/pda_power.h
+++ b/include/linux/pda_power.h
@@ -26,6 +26,7 @@ struct pda_power_pdata {
 
 	unsigned int wait_for_status; /* msecs, default is 500 */
 	unsigned int wait_for_charger; /* msecs, default is 500 */
+	unsigned int polling_interval; /* msecs, default is 2000 */
 };
 
 #endif /* __PDA_POWER_H__ */
-- 
1.5.2.4

  parent reply	other threads:[~2008-01-04  0:45 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-01-03  0:53 [PATCH] pda-power: only register available psu Dmitry Baryshkov
2008-01-04  0:29 ` Anton Vorontsov
2008-01-04  0:32   ` [PATCH 1/2] pda_power: various cleanups Anton Vorontsov
2008-01-04  0:32   ` Anton Vorontsov [this message]
2008-01-04  1:31   ` [PATCH] pda-power: only register available psu Dmitry

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=20080104003243.GB12308@zarina \
    --to=cbouatmailru@gmail.com \
    --cc=cbou@mail.ru \
    --cc=dbaryshkov@gmail.com \
    --cc=dwmw2@infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox