[PATCH 0/5] MAX17042 add support for maxim POR procedure

January 24th, 2012 - 12:30 pm ET by dirk.brandewie | Report spam
From: Dirk Brandewie <dirk.brandewie@gmail.com>

This patch set adds support for the power on reset procedure for the
max17042 battery fuel gauge and alert interrupts.

The accuracy of the fuel gauge is improved by configuring the fuel
gauge with the characterization data for the battery present in the
platform.


Changes since v3:
Patch added patch to fix scaling of VCELL register values reported

Capacity property now used the reported SOC register to account for
empty compensation in reported capacity.

Fixed sparse/smatch warnings

Changes since v2:

Dropped patch moving non-POR init to worker function.

Reorganized POR patch to only schedule worker thread if the fuel gauge
is in the POR state

Changes since v1:

Moved power_supply_register() back to the probe max17042_get_property()
will return -EAGAIN until the init function completes

Added support for interrupts from the alert pin if the platform has it
connected to an interrupt source.

Added fix for the values returned by POWER_SUPPLY_PROP_VOLTAGE_NOW
and POWER_SUPPLY_PROP_VOLTAGE_AVG.

Added Ack's from previous patch series


Bruce Robertson (1):
max17042: Fix value scaling for VCELL and avgVCELL

Dirk Brandewie (4):
max17042: Align register definitions with data sheet and init appnote
max17042: Add POR init procedure from Maxim appnote
max17042: Add support for signalling change in SOC
max17042: Change capacity property to use reported SOC register

drivers/power/max17042_battery.c | 452 +++++++++++++++++++++++++++++++-
include/linux/power/max17042_battery.h | 93 ++++++-
2 files changed, 522 insertions(+), 23 deletions(-)

1.7.7.5

To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
email Follow the discussionReplies 2 repliesReplies Make a reply

Similar topics

Replies

#1 dirk.brandewie
January 24th, 2012 - 12:30 pm ET | Report spam
From: Dirk Brandewie

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

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");
+ 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",
+ __func__);
+ }
+
reg = max17042_read_reg(chip->client, MAX17042_STATUS);

if (reg & STATUS_POR_BIT) {
1.7.7.5

To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Replies Reply to this message
#2 dirk.brandewie
January 24th, 2012 - 12:30 pm ET | Report spam
From: Dirk Brandewie

align the register names with max17042 data sheet removing
registers that are marked reserved that are not used.

Add register definitions defined in the maxim initialization appnote

Signed-off-by: Dirk Brandewie
Acked-by: MyungJoo Ham

include/linux/power/max17042_battery.h | 37 ++++++++++++++++++++++++-
1 files changed, 28 insertions(+), 9 deletions(-)

diff --git a/include/linux/power/max17042_battery.h b/include/linux/power/max17042_battery.h
index fe99211..67eeada 100644
a/include/linux/power/max17042_battery.h
+++ b/include/linux/power/max17042_battery.h
@@ -40,11 +40,11 @@ enum max17042_register {
MAX17042_VCELL = 0x09,
MAX17042_Current = 0x0A,
MAX17042_AvgCurrent = 0x0B,
- MAX17042_Qresidual = 0x0C,
+
MAX17042_SOC = 0x0D,
MAX17042_AvSOC = 0x0E,
MAX17042_RemCap = 0x0F,
- MAX17402_FullCAP = 0x10,
+ MAX17042_FullCAP = 0x10,
MAX17042_TTE = 0x11,
MAX17042_V_empty = 0x12,

@@ -62,14 +62,14 @@ enum max17042_register {
MAX17042_AvCap = 0x1F,
MAX17042_ManName = 0x20,
MAX17042_DevName = 0x21,
- MAX17042_DevChem = 0x22,

+ MAX17042_FullCAPNom = 0x23,
MAX17042_TempNom = 0x24,
- MAX17042_TempCold = 0x25,
+ MAX17042_TempLim = 0x25,
MAX17042_TempHot = 0x26,
MAX17042_AIN = 0x27,
MAX17042_LearnCFG = 0x28,
- MAX17042_SHFTCFG = 0x29,
+ MAX17042_FilterCFG = 0x29,
MAX17042_RelaxCFG = 0x2A,
MAX17042_MiscCFG = 0x2B,
MAX17042_TGAIN = 0x2C,
@@ -77,22 +77,41 @@ enum max17042_register {
MAX17042_CGAIN = 0x2E,
MAX17042_COFF = 0x2F,

- MAX17042_Q_empty = 0x33,
+ MAX17042_MaskSOC = 0x32,
+ MAX17042_SOC_empty = 0x33,
MAX17042_T_empty = 0x34,

+ MAX17042_FullCAP0 = 0x35,
+ MAX17042_LAvg_empty = 0x36,
+ MAX17042_FCTC = 0x37,
MAX17042_RCOMP0 = 0x38,
MAX17042_TempCo = 0x39,
- MAX17042_Rx = 0x3A,
- MAX17042_T_empty0 = 0x3B,
+ MAX17042_EmptyTempCo = 0x3A,
+ MAX17042_K_empty0 = 0x3B,
MAX17042_TaskPeriod = 0x3C,
MAX17042_FSTAT = 0x3D,

MAX17042_SHDNTIMER = 0x3F,

- MAX17042_VFRemCap = 0x4A,
+ MAX17042_dQacc = 0x45,
+ MAX17042_dPacc = 0x46,
+
+ MAX17042_VFSOC0 = 0x48,

MAX17042_QH = 0x4D,
MAX17042_QL = 0x4E,
+
+ MAX17042_VFSOC0Enable = 0x60,
+ MAX17042_MLOCKReg1 = 0x62,
+ MAX17042_MLOCKReg2 = 0x63,
+
+ MAX17042_MODELChrTbl = 0x80,
+
+ MAX17042_OCV = 0xEE,
+
+ MAX17042_OCVInternal = 0xFB,
+
+ MAX17042_VFSOC = 0xFF,
};

/*
1.7.7.5

To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
email Follow the discussion Replies Reply to this message
Help Create a new topicReplies Make a reply
Search Make your own search