All of lore.kernel.org
 help / color / mirror / Atom feed
From: dirk.brandewie@gmail.com
To: linux-kernel@vger.kernel.org
Cc: cbouatmailru@gmail.com, dg77.kim@samsung.com,
	kyungmin.park@samsung.com, myungjoo.ham@samsung.com,
	Jason.Wortham@maxim-ic.com, bruce.e.robertson@intel.com,
	Dirk Brandewie <dirk.brandewie@gmail.com>
Subject: [PATCH 3/5] max17042: Add support for signalling change in SOC
Date: Tue, 24 Jan 2012 09:26:06 -0800	[thread overview]
Message-ID: <1327425968-21195-4-git-send-email-dirk.brandewie@gmail.com> (raw)
In-Reply-To: <1327425968-21195-1-git-send-email-dirk.brandewie@gmail.com>

From: Dirk Brandewie <dirk.brandewie@gmail.com>

If platform has the alert pin attached to an interrupt source have the
driver signal a change in the SOC every 1 percent.

Signed-off-by: Dirk Brandewie <dirk.brandewie@gmail.com>
---
 drivers/power/max17042_battery.c |   53 ++++++++++++++++++++++++++++++++++++++
 1 files changed, 53 insertions(+), 0 deletions(-)

diff --git a/drivers/power/max17042_battery.c b/drivers/power/max17042_battery.c
index fce502c..e0a4430 100644
--- a/drivers/power/max17042_battery.c
+++ b/drivers/power/max17042_battery.c
@@ -27,6 +27,7 @@
 #include <linux/slab.h>
 #include <linux/i2c.h>
 #include <linux/delay.h>
+#include <linux/interrupt.h>
 #include <linux/mod_devicetable.h>
 #include <linux/power_supply.h>
 #include <linux/power/max17042_battery.h>
@@ -43,6 +44,11 @@
 #define STATUS_SMX_BIT         (1 << 14)
 #define STATUS_BR_BIT          (1 << 15)
 
+/* Interrupt mask bits */
+#define CONFIG_ALRT_BIT_ENBL	(1 << 2)
+#define STATUS_INTR_SOC_BIT	(1 << 14)
+#define STATUS_INTR_LOW_SOC_BIT	(1 << 10)
+
 #define VFSOC0_LOCK		0x0000
 #define VFSOC0_UNLOCK		0x0080
 #define MODEL_UNLOCK1	0X0059
@@ -522,6 +528,39 @@ static int max17042_init_chip(struct max17042_chip *chip)
 	return 0;
 }
 
+static void max17042_set_soc_threshold(struct max17042_chip *chip, u16 off)
+{
+	u16 soc, soc_tr;
+
+	/* program interrupt thesholds such that we should
+	 * get interrupt for every 'off' perc change in the soc
+	 */
+	soc = max17042_read_reg(chip->client, MAX17042_RepSOC) >> 8;
+	soc_tr = (soc + off) << 8;
+	soc_tr |= (soc - off);
+	max17042_write_reg(chip->client, MAX17042_SALRT_Th, soc_tr);
+}
+
+static irqreturn_t max17042_intr_handler(int id, void *dev)
+{
+	return IRQ_WAKE_THREAD;
+}
+
+static irqreturn_t max17042_thread_handler(int id, void *dev)
+{
+	struct max17042_chip *chip = dev;
+	u16 val;
+
+	val = max17042_read_reg(chip->client, MAX17042_STATUS);
+	if ((val & STATUS_INTR_SOC_BIT) ||
+		(val & STATUS_INTR_LOW_SOC_BIT)) {
+		dev_info(&chip->client->dev, "SOC threshold INTR\n");
+		max17042_set_soc_threshold(chip, 1);
+	}
+
+	power_supply_changed(&chip->battery);
+	return IRQ_HANDLED;
+}
 
 static void max17042_init_worker(struct work_struct *work)
 {
@@ -584,6 +623,20 @@ static int __devinit max17042_probe(struct i2c_client *client,
 				MAX17042_DEFAULT_SNS_RESISTOR;
 	}
 
+	if (client->irq) {
+		ret = request_threaded_irq(client->irq, max17042_intr_handler,
+						max17042_thread_handler,
+						0, chip->battery.name, chip);
+		if (!ret) {
+			reg =  max17042_read_reg(client, MAX17042_CONFIG);
+			reg |= CONFIG_ALRT_BIT_ENBL;
+			max17042_write_reg(client, MAX17042_CONFIG, reg);
+			max17042_set_soc_threshold(chip, 1);
+		} else
+			dev_err(&client->dev, "%s(): cannot get IRQ\n",
+				__func__);
+	}
+
 	reg = max17042_read_reg(chip->client, MAX17042_STATUS);
 
 	if (reg & STATUS_POR_BIT) {
-- 
1.7.7.5


  parent reply	other threads:[~2012-01-24 17:28 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-01-24 17:26 [PATCH 0/5] MAX17042 add support for maxim POR procedure dirk.brandewie
2012-01-24 17:26 ` [PATCH 1/5] max17042: Align register definitions with data sheet and init appnote dirk.brandewie
2012-01-24 17:26 ` [PATCH 2/5] max17042: Add POR init procedure from Maxim appnote dirk.brandewie
2012-01-24 17:26 ` dirk.brandewie [this message]
2012-01-24 17:26 ` [PATCH 4/5] max17042: Fix value scaling for VCELL and avgVCELL dirk.brandewie
2012-03-13 18:19   ` Anton Vorontsov
2012-03-13 21:00     ` bruce robertson
2012-03-13 21:04       ` Jason Wortham
2012-03-13 22:59         ` Dirk Brandewie
2012-03-14  0:04           ` Jason Wortham
2012-03-13 23:18         ` bruce robertson
2012-03-14  0:37           ` Jason Wortham
2012-01-24 17:26 ` [PATCH 5/5] max17042: Change capacity property to use reported SOC register dirk.brandewie
2012-03-13 18:34   ` Anton Vorontsov
2012-03-13 22:54     ` Dirk Brandewie
2012-02-28 16:17 ` [PATCH 0/5] MAX17042 add support for maxim POR procedure Dirk Brandewie
2012-03-13 18:48 ` Anton Vorontsov

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=1327425968-21195-4-git-send-email-dirk.brandewie@gmail.com \
    --to=dirk.brandewie@gmail.com \
    --cc=Jason.Wortham@maxim-ic.com \
    --cc=bruce.e.robertson@intel.com \
    --cc=cbouatmailru@gmail.com \
    --cc=dg77.kim@samsung.com \
    --cc=kyungmin.park@samsung.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=myungjoo.ham@samsung.com \
    /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.