linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: mathieu.poirier@linaro.org
To: linux-kernel@vger.kernel.org, cbou@mail.ru, dwmw2@infradead.org
Cc: mathieu.poirier@linaro.org
Subject: [PATCH 37/57] power: ab8500_bm: Quick re-attach charging behaviour
Date: Tue, 25 Sep 2012 10:12:34 -0600	[thread overview]
Message-ID: <1348589574-25655-38-git-send-email-mathieu.poirier@linaro.org> (raw)
In-Reply-To: <1348589574-25655-1-git-send-email-mathieu.poirier@linaro.org>

From: Kalle Komierowski <karl.komierowski@stericsson.com>

Due to a bug in some AB8500 ASICs charger removal cannot always
be detected if the removal and reinsertion is done to close in time.
This patch detects above described case and handles the situation
so that charging will be kept turned on.

Signed-off-by: Kalle Komierowski <karl.komierowski@stericsson.com>
Signed-off-by: Mathieu Poirier <mathieu.poirier@linaro.org>
Reviewed-by: Marcus COOPER <marcus.xm.cooper@stericsson.com>
Reviewed-by: Jonas ABERG <jonas.aberg@stericsson.com>
Reviewed-by: Philippe LANGLAIS <philippe.langlais@stericsson.com>
---
 drivers/power/ab8500_charger.c            |  105 ++++++++++++++++++++++++++++-
 drivers/power/abx500_chargalg.c           |   31 ++++++++-
 include/linux/mfd/abx500/ux500_chargalg.h |    1 +
 3 files changed, 134 insertions(+), 3 deletions(-)

diff --git a/drivers/power/ab8500_charger.c b/drivers/power/ab8500_charger.c
index 8137ea5..70e7c5e 100644
--- a/drivers/power/ab8500_charger.c
+++ b/drivers/power/ab8500_charger.c
@@ -49,6 +49,7 @@
 #define VBUS_DET_DBNC100		0x02
 #define VBUS_DET_DBNC1			0x01
 #define OTP_ENABLE_WD			0x01
+#define DROP_COUNT_RESET		0x01
 
 #define MAIN_CH_INPUT_CURR_SHIFT	4
 #define VBUS_IN_CURR_LIM_SHIFT		4
@@ -1672,6 +1673,105 @@ static int ab8500_charger_usb_en(struct ux500_charger *charger,
 }
 
 /**
+ * ab8500_charger_usb_check_enable() - enable usb charging
+ * @charger:	pointer to the ux500_charger structure
+ * @vset:	charging voltage
+ * @iset:	charger output current
+ *
+ * Check if the VBUS charger has been disconnected and reconnected without
+ * AB8500 rising an interrupt. Returns 0 on success.
+ */
+static int ab8500_charger_usb_check_enable(struct ux500_charger *charger,
+	int vset, int iset)
+{
+	u8 usbch_ctrl1 = 0;
+	int ret = 0;
+
+	struct ab8500_charger *di = to_ab8500_charger_usb_device_info(charger);
+
+	if (!di->usb.charger_connected)
+		return ret;
+
+	ret = abx500_get_register_interruptible(di->dev, AB8500_CHARGER,
+				AB8500_USBCH_CTRL1_REG, &usbch_ctrl1);
+	if (ret < 0) {
+		dev_err(di->dev, "ab8500 read failed %d\n", __LINE__);
+		return ret;
+	}
+	dev_dbg(di->dev, "USB charger ctrl: 0x%02x\n", usbch_ctrl1);
+
+	if (!(usbch_ctrl1 & USB_CH_ENA)) {
+		dev_info(di->dev, "Charging has been disabled abnormally and will be re-enabled\n");
+
+		ret = abx500_mask_and_set_register_interruptible(di->dev,
+					AB8500_CHARGER, AB8500_CHARGER_CTRL,
+					DROP_COUNT_RESET, DROP_COUNT_RESET);
+		if (ret < 0) {
+			dev_err(di->dev, "ab8500 write failed %d\n", __LINE__);
+			return ret;
+		}
+
+		ret = ab8500_charger_usb_en(&di->usb_chg, true, vset, iset);
+		if (ret < 0) {
+			dev_err(di->dev, "Failed to enable VBUS charger %d\n",
+					__LINE__);
+			return ret;
+		}
+	}
+	return ret;
+}
+
+/**
+ * ab8500_charger_ac_check_enable() - enable usb charging
+ * @charger:	pointer to the ux500_charger structure
+ * @vset:	charging voltage
+ * @iset:	charger output current
+ *
+ * Check if the AC charger has been disconnected and reconnected without
+ * AB8500 rising an interrupt. Returns 0 on success.
+ */
+static int ab8500_charger_ac_check_enable(struct ux500_charger *charger,
+	int vset, int iset)
+{
+	u8 mainch_ctrl1 = 0;
+	int ret = 0;
+
+	struct ab8500_charger *di = to_ab8500_charger_ac_device_info(charger);
+
+	if (!di->ac.charger_connected)
+		return ret;
+
+	ret = abx500_get_register_interruptible(di->dev, AB8500_CHARGER,
+				AB8500_MCH_CTRL1, &mainch_ctrl1);
+	if (ret < 0) {
+		dev_err(di->dev, "ab8500 read failed %d\n", __LINE__);
+		return ret;
+	}
+	dev_dbg(di->dev, "AC charger ctrl: 0x%02x\n", mainch_ctrl1);
+
+	if (!(mainch_ctrl1 & MAIN_CH_ENA)) {
+		dev_info(di->dev, "Charging has been disabled abnormally and will be re-enabled\n");
+
+		ret = abx500_mask_and_set_register_interruptible(di->dev,
+					AB8500_CHARGER, AB8500_CHARGER_CTRL,
+					DROP_COUNT_RESET, DROP_COUNT_RESET);
+
+		if (ret < 0) {
+			dev_err(di->dev, "ab8500 write failed %d\n", __LINE__);
+			return ret;
+		}
+
+		ret = ab8500_charger_ac_en(&di->usb_chg, true, vset, iset);
+		if (ret < 0) {
+			dev_err(di->dev, "failed to enable AC charger %d\n",
+				__LINE__);
+			return ret;
+		}
+	}
+	return ret;
+}
+
+/**
  * ab8500_charger_watchdog_kick() - kick charger watchdog
  * @di:		pointer to the ab8500_charger structure
  *
@@ -1728,8 +1828,7 @@ static int ab8500_charger_update_charger_current(struct ux500_charger *charger,
 
 	/* Reset the main and usb drop input current measurement counter */
 	ret = abx500_set_register_interruptible(di->dev, AB8500_CHARGER,
-				AB8500_CHARGER_CTRL,
-				0x1);
+					AB8500_CHARGER_CTRL, DROP_COUNT_RESET);
 	if (ret) {
 		dev_err(di->dev, "%s write failed\n", __func__);
 		return ret;
@@ -3197,6 +3296,7 @@ static int __devinit ab8500_charger_probe(struct platform_device *pdev)
 	di->ac_chg.psy.num_supplicants = di->pdata->num_supplicants;
 	/* ux500_charger sub-class */
 	di->ac_chg.ops.enable = &ab8500_charger_ac_en;
+	di->ac_chg.ops.check_enable = &ab8500_charger_ac_check_enable;
 	di->ac_chg.ops.kick_wd = &ab8500_charger_watchdog_kick;
 	di->ac_chg.ops.update_curr = &ab8500_charger_update_charger_current;
 	di->ac_chg.max_out_volt = ab8500_charger_voltage_map[
@@ -3218,6 +3318,7 @@ static int __devinit ab8500_charger_probe(struct platform_device *pdev)
 	di->usb_chg.psy.num_supplicants = di->pdata->num_supplicants;
 	/* ux500_charger sub-class */
 	di->usb_chg.ops.enable = &ab8500_charger_usb_en;
+	di->usb_chg.ops.check_enable = &ab8500_charger_usb_check_enable;
 	di->usb_chg.ops.kick_wd = &ab8500_charger_watchdog_kick;
 	di->usb_chg.ops.update_curr = &ab8500_charger_update_charger_current;
 	di->usb_chg.max_out_volt = ab8500_charger_voltage_map[
diff --git a/drivers/power/abx500_chargalg.c b/drivers/power/abx500_chargalg.c
index 4e3d20f..9568f63 100644
--- a/drivers/power/abx500_chargalg.c
+++ b/drivers/power/abx500_chargalg.c
@@ -311,6 +311,29 @@ static void abx500_chargalg_state_to(struct abx500_chargalg *di,
 	di->charge_state = state;
 }
 
+static int abx500_chargalg_check_charger_enable(struct abx500_chargalg *di)
+{
+	switch (di->charge_state) {
+	case STATE_NORMAL:
+	case STATE_MAINTENANCE_A:
+	case STATE_MAINTENANCE_B:
+		break;
+	default:
+		return 0;
+	}
+
+	if (di->chg_info.charger_type & USB_CHG) {
+		return di->usb_chg->ops.check_enable(di->usb_chg,
+			di->bat->bat_type[di->bat->batt_id].normal_vol_lvl,
+			di->bat->bat_type[di->bat->batt_id].normal_cur_lvl);
+	} else if (di->chg_info.charger_type & AC_CHG) {
+		return di->ac_chg->ops.check_enable(di->ac_chg,
+			di->bat->bat_type[di->bat->batt_id].normal_vol_lvl,
+			di->bat->bat_type[di->bat->batt_id].normal_cur_lvl);
+	}
+	return -ENXIO;
+}
+
 /**
  * abx500_chargalg_check_charger_connection() - Check charger connection change
  * @di:		pointer to the abx500_chargalg structure
@@ -1220,6 +1243,7 @@ static void abx500_chargalg_external_power_changed(struct power_supply *psy)
 static void abx500_chargalg_algorithm(struct abx500_chargalg *di)
 {
 	int charger_status;
+	int ret;
 
 	/* Collect data from all power_supply class devices */
 	class_for_each_device(power_supply_class, NULL,
@@ -1228,8 +1252,13 @@ static void abx500_chargalg_algorithm(struct abx500_chargalg *di)
 	abx500_chargalg_end_of_charge(di);
 	abx500_chargalg_check_temp(di);
 	abx500_chargalg_check_charger_voltage(di);
-
 	charger_status = abx500_chargalg_check_charger_connection(di);
+
+	ret = abx500_chargalg_check_charger_enable(di);
+	if (ret < 0)
+		dev_err(di->dev, "Checking charger if enabled error: %d line: %d\n",
+				ret, __LINE__);
+
 	/*
 	 * First check if we have a charger connected.
 	 * Also we don't allow charging of unknown batteries if configured
diff --git a/include/linux/mfd/abx500/ux500_chargalg.h b/include/linux/mfd/abx500/ux500_chargalg.h
index d43ac0f..110d12f 100644
--- a/include/linux/mfd/abx500/ux500_chargalg.h
+++ b/include/linux/mfd/abx500/ux500_chargalg.h
@@ -17,6 +17,7 @@ struct ux500_charger;
 
 struct ux500_charger_ops {
 	int (*enable) (struct ux500_charger *, int, int, int);
+	int (*check_enable) (struct ux500_charger *, int, int);
 	int (*kick_wd) (struct ux500_charger *);
 	int (*update_curr) (struct ux500_charger *, int);
 };
-- 
1.7.5.4


  parent reply	other threads:[~2012-09-25 16:14 UTC|newest]

Thread overview: 108+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-09-25 16:11 [PATCH 00/57] power: Upgrade to ux500 battery management driver mathieu.poirier
2012-09-25 16:11 ` [PATCH 01/57] power: ab8500_bm: Charger current step-up/down mathieu.poirier
2012-09-28  3:41   ` Anton Vorontsov
2012-09-25 16:11 ` [PATCH 02/57] power: ab8500_bm: Don't clear the CCMuxOffset bit mathieu.poirier
2012-09-28  3:42   ` Anton Vorontsov
2012-09-25 16:12 ` [PATCH 03/57] power: ab8500_btemp: Detect battery type in workqueue mathieu.poirier
2012-09-25 16:12 ` [PATCH 04/57] power: ab8500: bm: movimg back to ab8500 platform data managment mathieu.poirier
2012-09-27  2:42   ` Anton Vorontsov
2012-09-27  2:53   ` Anton Vorontsov
2012-09-25 16:12 ` [PATCH 05/57] power: ab8500_bm: Rename the power_loss function mathieu.poirier
2012-09-25 16:12 ` [PATCH 06/57] power: ab8500_bm: Skip first CCEOC irq for instant current mathieu.poirier
2012-09-25 16:12 ` [PATCH 07/57] power: ab8500_bm: Detect removed charger mathieu.poirier
2012-09-27  3:09   ` Anton Vorontsov
2012-09-25 16:12 ` [PATCH 08/57] power: ab8500_fg: flush sync on suspend mathieu.poirier
2012-09-27  3:11   ` Anton Vorontsov
2012-09-25 16:12 ` [PATCH 09/57] power: ab8500_fg: usleep_range instead of short msleep mathieu.poirier
2012-09-27  2:36   ` Anton Vorontsov
2012-09-25 16:12 ` [PATCH 10/57] power: ab8500_charger: Handle gpadc errors mathieu.poirier
2012-09-25 16:12 ` [PATCH 11/57] power: Recharge condition not optimal for battery mathieu.poirier
2012-09-27  3:29   ` Anton Vorontsov
2012-09-25 16:12 ` [PATCH 12/57] power: ab8500_fg: balance IRQ enable mathieu.poirier
2012-09-25 16:12 ` [PATCH 13/57] power: ab8500_bm: Ignore false btemp low interrupt mathieu.poirier
2012-09-27  3:32   ` Anton Vorontsov
2012-09-25 16:12 ` [PATCH 14/57] power: Adds support for Car/Travel Adapters mathieu.poirier
2012-09-25 16:12 ` [PATCH 15/57] power: ab8500_fg: Round capacity output mathieu.poirier
2012-09-25 16:12 ` [PATCH 16/57] power: bm remove superfluous BTEMP thermal comp mathieu.poirier
2012-09-25 16:12 ` [PATCH 17/57] power: ab8500_bm: Added support for BATT_OVV mathieu.poirier
2012-09-27  3:36   ` Anton Vorontsov
2012-09-28 18:24     ` Mathieu Poirier
2012-09-28 18:26       ` Anton Vorontsov
2012-09-25 16:12 ` [PATCH 18/57] power: Add sysfs interfaces for capacity mathieu.poirier
2012-09-27  7:08   ` Anton Vorontsov
2012-09-28 18:26     ` Mathieu Poirier
2012-09-28 19:11       ` Anton Vorontsov
2012-09-25 16:12 ` [PATCH 19/57] power: remove unused defines mathieu.poirier
2012-09-25 16:12 ` [PATCH 20/57] power: Adds support for legacy USB chargers mathieu.poirier
2012-09-27  7:15   ` Anton Vorontsov
2012-09-25 16:12 ` [PATCH 21/57] power: Overflow in current calculation mathieu.poirier
2012-09-25 16:12 ` [PATCH 22/57] power: AB workaround for invalid charger mathieu.poirier
2012-09-25 16:12 ` [PATCH 23/57] power: Add plaform data charger configurables mathieu.poirier
2012-09-25 16:12 ` [PATCH 24/57] power: ab8500_fg: Adjust for RF bursts voltage drops mathieu.poirier
2012-09-25 16:12 ` [PATCH 25/57] power: ab8500: adaptation to ab version mathieu.poirier
2012-09-25 16:12 ` [PATCH 26/57] power: charge: update watchdog for pm2xxx support mathieu.poirier
2012-09-25 16:12 ` [PATCH 27/57] power: sysfs interface update mathieu.poirier
2012-09-27  7:20   ` Anton Vorontsov
2012-09-28 18:26     ` Mathieu Poirier
2012-09-25 16:12 ` [PATCH 28/57] power: ab8500 - Accessing Autopower register fails mathieu.poirier
2012-09-25 16:12 ` [PATCH 29/57] power: ab8500_fg: Goto INIT_RECOVERY when charger removed mathieu.poirier
2012-09-25 16:12 ` [PATCH 30/57] power: ab8500: Flush & sync all works mathieu.poirier
2012-09-27  7:23   ` Anton Vorontsov
2012-09-28 18:28     ` Mathieu Poirier
2012-09-28 19:54       ` Anton Vorontsov
2012-09-25 16:12 ` [PATCH 31/57] power: ab8500_fg: fix to use correct battery charge full design mathieu.poirier
2012-09-27  7:27   ` Anton Vorontsov
2012-09-25 16:12 ` [PATCH 32/57] power: ab8500_charger: Do not touch VBUSOVV bits mathieu.poirier
2012-09-25 16:12 ` [PATCH 33/57] power: u8500_charger: Delay for USB enumeration mathieu.poirier
2012-09-27  7:42   ` Anton Vorontsov
2012-09-28 16:56     ` Mathieu Poirier
2012-09-28 17:09       ` Anton Vorontsov
2012-09-25 16:12 ` [PATCH 34/57] power: ab8500_fg: add power cut feature for ab8505 mathieu.poirier
2012-09-28  0:01   ` Anton Vorontsov
2012-09-25 16:12 ` [PATCH 35/57] power: ab8500_fg: Report unscaled capacity mathieu.poirier
2012-09-25 16:12 ` [PATCH 36/57] power: add backup battery charge voltages mathieu.poirier
2012-09-25 16:12 ` mathieu.poirier [this message]
2012-09-28  0:13   ` [PATCH 37/57] power: ab8500_bm: Quick re-attach charging behaviour Anton Vorontsov
2012-09-25 16:12 ` [PATCH 38/57] power: l9540: Charge only mode fixes mathieu.poirier
2012-09-28  0:27   ` Anton Vorontsov
2012-09-28 18:32     ` Mathieu Poirier
2012-09-25 16:12 ` [PATCH 39/57] power: ab8500_charger: Prevent auto drop of VBUS mathieu.poirier
2012-09-28  0:52   ` Anton Vorontsov
2012-09-25 16:12 ` [PATCH 40/57] power: ab8500: ADC for battery thermistor mathieu.poirier
2012-09-28  0:57   ` Anton Vorontsov
2012-09-25 16:12 ` [PATCH 41/57] power: ab8500_btemp: Filter btemp readings mathieu.poirier
2012-09-25 16:12 ` [PATCH 42/57] power: charging: Allow capacity to raise from 1% mathieu.poirier
2012-09-25 16:12 ` [PATCH 43/57] power: charging: Add AB8505_USB_LINK_STATUS mathieu.poirier
2012-09-25 16:12 ` [PATCH 44/57] power: ab8500: remove unecesary define flag mathieu.poirier
2012-09-28  1:05   ` Anton Vorontsov
2012-09-25 16:12 ` [PATCH 45/57] power: ab8500: defer btemp filtering while init mathieu.poirier
2012-09-28  1:08   ` Anton Vorontsov
2012-09-25 16:12 ` [PATCH 46/57] power: chargealg: Realign with upstream version mathieu.poirier
2012-09-28  1:17   ` Anton Vorontsov
2012-09-25 16:12 ` [PATCH 47/57] power: Harmonising platform data declaration/handling mathieu.poirier
2012-09-28  1:11   ` Anton Vorontsov
2012-09-25 16:12 ` [PATCH 48/57] power: ab8500 : quick re-attach for ext charger mathieu.poirier
2012-09-28  1:19   ` Anton Vorontsov
2012-09-25 16:12 ` [PATCH 49/57] power: Cancelling status charging notification mathieu.poirier
2012-09-28  2:16   ` Anton Vorontsov
2012-09-25 16:12 ` [PATCH 50/57] power: ab8500-chargalg: update battery health on safety timer exp mathieu.poirier
2012-09-28  2:21   ` Anton Vorontsov
2012-09-25 16:12 ` [PATCH 51/57] power: ab8500: Re-alignment with internal developement mathieu.poirier
2012-09-28  2:35   ` Anton Vorontsov
2012-09-28  2:45     ` Anton Vorontsov
2012-09-25 16:12 ` [PATCH 52/57] power: abx500_chargalg: Use hrtimer mathieu.poirier
2012-09-28  2:47   ` Anton Vorontsov
2012-09-28 18:33     ` Mathieu Poirier
2012-09-28 19:41       ` Anton Vorontsov
2012-09-25 16:12 ` [PATCH 53/57] power: ab8500_fg: Moving structure definitions to header file mathieu.poirier
2012-09-28  2:51   ` Anton Vorontsov
2012-09-25 16:12 ` [PATCH 54/57] power: ab8500_charger: Use USBLink1Status Register mathieu.poirier
2012-09-28  2:56   ` Anton Vorontsov
2012-09-25 16:12 ` [PATCH 55/57] power: ab8500_charger: Add UsbLineCtrl2 reference mathieu.poirier
2012-09-28  2:58   ` Anton Vorontsov
2012-09-25 16:12 ` [PATCH 56/57] power: abx500_chargalg: Fix quick re-attach charger issue mathieu.poirier
2012-09-28  3:00   ` Anton Vorontsov
2012-09-25 16:12 ` [PATCH 57/57] power: ab8500_charger: Limit USB charger current mathieu.poirier
2012-09-27  3:38 ` [PATCH 00/57] power: Upgrade to ux500 battery management driver Anton Vorontsov
2012-09-27 22:08   ` Mathieu Poirier
2012-09-28  0:36     ` 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=1348589574-25655-38-git-send-email-mathieu.poirier@linaro.org \
    --to=mathieu.poirier@linaro.org \
    --cc=cbou@mail.ru \
    --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;
as well as URLs for NNTP newsgroup(s).