mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Andrew Bresticker <abrestic@chromium.org>
To: Anton Vorontsov <anton@enomsg.org>,
	David Woodhouse <dwmw2@infradead.org>
Cc: Rhyland Klein <rklein@nvidia.com>,
	Darbha Sriharsha <dsriharsha@nvidia.com>,
	linux-kernel@vger.kernel.org,
	Andrew Bresticker <abrestic@chromium.org>
Subject: [PATCH] bq24735: don't attempt I2C accesses if charger is not present
Date: Thu, 26 Dec 2013 17:11:29 -0800	[thread overview]
Message-ID: <1388106689-26846-1-git-send-email-abrestic@chromium.org> (raw)

If we have an AC-detect GPIO for the charger and the charger is not
present during probe time, don't attempt I2C accesses to the charger
as they are not guaranteed to succeed.  The charger will be configured
once it is plugged in.  Also initialize the AC-detect GPIO as an input
so that its value can be read reliably before setting it up as an IRQ.

Signed-off-by: Andrew Bresticker <abrestic@chromium.org>
---
 drivers/power/bq24735-charger.c | 81 +++++++++++++++++++++++++----------------
 1 file changed, 49 insertions(+), 32 deletions(-)

diff --git a/drivers/power/bq24735-charger.c b/drivers/power/bq24735-charger.c
index d022b82..df3e215 100644
--- a/drivers/power/bq24735-charger.c
+++ b/drivers/power/bq24735-charger.c
@@ -47,6 +47,7 @@ struct bq24735 {
 	struct power_supply	charger;
 	struct i2c_client	*client;
 	struct bq24735_platform	*pdata;
+	bool			configured;
 };
 
 static inline struct bq24735 *to_bq24735(struct power_supply *psy)
@@ -178,10 +179,15 @@ static irqreturn_t bq24735_charger_isr(int irq, void *devid)
 	struct power_supply *psy = devid;
 	struct bq24735 *charger = to_bq24735(psy);
 
-	if (bq24735_charger_is_present(charger))
+	if (bq24735_charger_is_present(charger)) {
+		if (!charger->configured) {
+			bq24735_config_charger(charger);
+			charger->configured = true;
+		}
 		bq24735_enable_charging(charger);
-	else
+	} else {
 		bq24735_disable_charging(charger);
+	}
 
 	power_supply_changed(psy);
 
@@ -290,33 +296,10 @@ static int bq24735_charger_probe(struct i2c_client *client,
 
 	i2c_set_clientdata(client, charger);
 
-	ret = bq24735_read_word(client, BQ24735_MANUFACTURER_ID);
-	if (ret < 0) {
-		dev_err(&client->dev, "Failed to read manufacturer id : %d\n",
-			ret);
-		goto err_free_name;
-	} else if (ret != 0x0040) {
-		dev_err(&client->dev,
-			"manufacturer id mismatch. 0x0040 != 0x%04x\n", ret);
-		ret = -ENODEV;
-		goto err_free_name;
-	}
-
-	ret = bq24735_read_word(client, BQ24735_DEVICE_ID);
-	if (ret < 0) {
-		dev_err(&client->dev, "Failed to read device id : %d\n", ret);
-		goto err_free_name;
-	} else if (ret != 0x000B) {
-		dev_err(&client->dev,
-			"device id mismatch. 0x000b != 0x%04x\n", ret);
-		ret = -ENODEV;
-		goto err_free_name;
-	}
-
 	if (gpio_is_valid(charger->pdata->status_gpio)) {
-		ret = devm_gpio_request(&client->dev,
-					charger->pdata->status_gpio,
-					name);
+		ret = devm_gpio_request_one(&client->dev,
+						charger->pdata->status_gpio,
+						GPIOF_IN, name);
 		if (ret) {
 			dev_err(&client->dev,
 				"Failed GPIO request for GPIO %d: %d\n",
@@ -326,14 +309,48 @@ static int bq24735_charger_probe(struct i2c_client *client,
 		charger->pdata->status_gpio_valid = !ret;
 	}
 
-	ret = bq24735_config_charger(charger);
-	if (ret < 0) {
-		dev_err(&client->dev, "failed in configuring charger");
-		goto err_free_name;
+	/*
+	 * If we have an AC-detect GPIO and we know the charger is not
+	 * present, don't bother with trying to access it over I2C as it
+	 * may not resopnd.
+	 */
+	if (!charger->pdata->status_gpio_valid ||
+		bq24735_charger_is_present(charger)) {
+		ret = bq24735_read_word(client, BQ24735_MANUFACTURER_ID);
+		if (ret < 0) {
+			dev_err(&client->dev,
+				"Failed to read manufacturer id : %d\n", ret);
+			goto err_free_name;
+		} else if (ret != 0x0040) {
+			dev_err(&client->dev,
+				"manufacturer id mismatch. 0x0040 != 0x%04x\n",
+				ret);
+			ret = -ENODEV;
+			goto err_free_name;
+		}
+
+		ret = bq24735_read_word(client, BQ24735_DEVICE_ID);
+		if (ret < 0) {
+			dev_err(&client->dev, "Failed to read device id : %d\n",
+				ret);
+			goto err_free_name;
+		} else if (ret != 0x000B) {
+			dev_err(&client->dev,
+				"device id mismatch. 0x000b != 0x%04x\n", ret);
+			ret = -ENODEV;
+			goto err_free_name;
+		}
 	}
 
 	/* check for AC adapter presence */
 	if (bq24735_charger_is_present(charger)) {
+		ret = bq24735_config_charger(charger);
+		if (ret < 0) {
+			dev_err(&client->dev, "failed in configuring charger");
+			goto err_free_name;
+		}
+		charger->configured = true;
+
 		ret = bq24735_enable_charging(charger);
 		if (ret < 0) {
 			dev_err(&client->dev, "Failed to enable charging\n");
-- 
1.8.5.1


                 reply	other threads:[~2013-12-27  1:11 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=1388106689-26846-1-git-send-email-abrestic@chromium.org \
    --to=abrestic@chromium.org \
    --cc=anton@enomsg.org \
    --cc=dsriharsha@nvidia.com \
    --cc=dwmw2@infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rklein@nvidia.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®