linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Benson Leung <bleung@chromium.org>
To: rydberg@euromail.se, linux-input@vger.kernel.org,
	linux-kernel@vger.kernel.org, dmitry.torokhov@gmail.com
Cc: bleung@chromium.org, olofj@chromium.org, djkurtz@chromium.org,
	dudl@cypress.com
Subject: [PATCH 1/4] Input: cyapa - Move common initialization to cyapa_detect
Date: Wed, 13 Mar 2013 16:50:48 -0700	[thread overview]
Message-ID: <1363218651-22457-2-git-send-email-bleung@chromium.org> (raw)
In-Reply-To: <1363218651-22457-1-git-send-email-bleung@chromium.org>

cyapa_check_is_operational and cyapa_create_input_dev are common to
the probe and firmware update paths. Pull those out into
cyapa_detect.

Signed-off-by: Benson Leung <bleung@chromium.org>
---
 drivers/input/mouse/cyapa.c | 57 +++++++++++++++++++++++++++++++--------------
 1 file changed, 39 insertions(+), 18 deletions(-)

diff --git a/drivers/input/mouse/cyapa.c b/drivers/input/mouse/cyapa.c
index b409c3d..a631aca 100644
--- a/drivers/input/mouse/cyapa.c
+++ b/drivers/input/mouse/cyapa.c
@@ -823,6 +823,40 @@ err_free_device:
 	return ret;
 }
 
+static void cyapa_detect(struct cyapa *cyapa)
+{
+	struct device *dev = &cyapa->client->dev;
+	int ret;
+
+	ret = cyapa_check_is_operational(cyapa);
+	if (ret == -ETIMEDOUT)
+		dev_err(dev, "no device detected, %d\n", ret);
+	else if (ret)
+		dev_err(dev, "device detected, but not operational, %d\n", ret);
+
+	if (!cyapa->input) {
+		ret = cyapa_create_input_dev(cyapa);
+		if (ret)
+			dev_err(dev, "create input_dev instance failed, %d\n",
+				ret);
+
+		enable_irq(cyapa->irq);
+		/*
+		 * On some systems, a system crash / warm boot does not reset
+		 * the device's current power mode to FULL_ACTIVE.
+		 * If such an event happens during suspend, after the device
+		 * has been put in a low power mode, the device will still be
+		 * in low power mode on a subsequent boot, since there was
+		 * never a matching resume().
+		 * Handle this by always forcing full power here, when a
+		 * device is first detected to be in operational mode.
+		 */
+		ret = cyapa_set_power_mode(cyapa, PWR_MODE_FULL_ACTIVE);
+		if (ret)
+			dev_warn(dev, "set active power failed, %d\n", ret);
+	}
+}
+
 static int cyapa_probe(struct i2c_client *client,
 		       const struct i2c_device_id *dev_id)
 {
@@ -853,23 +887,8 @@ static int cyapa_probe(struct i2c_client *client,
 	if (adapter_func == CYAPA_ADAPTER_FUNC_SMBUS)
 		cyapa->smbus = true;
 	cyapa->state = CYAPA_STATE_NO_DEVICE;
-	ret = cyapa_check_is_operational(cyapa);
-	if (ret) {
-		dev_err(dev, "device not operational, %d\n", ret);
-		goto err_mem_free;
-	}
 
-	ret = cyapa_create_input_dev(cyapa);
-	if (ret) {
-		dev_err(dev, "create input_dev instance failed, %d\n", ret);
-		goto err_mem_free;
-	}
-
-	ret = cyapa_set_power_mode(cyapa, PWR_MODE_FULL_ACTIVE);
-	if (ret) {
-		dev_err(dev, "set active power failed, %d\n", ret);
-		goto err_unregister_device;
-	}
+	cyapa_detect(cyapa);
 
 	cyapa->irq = client->irq;
 	ret = request_threaded_irq(cyapa->irq,
@@ -886,8 +905,8 @@ static int cyapa_probe(struct i2c_client *client,
 	return 0;
 
 err_unregister_device:
-	input_unregister_device(cyapa->input);
-err_mem_free:
+	if (cyapa->input)
+		input_unregister_device(cyapa->input);
 	kfree(cyapa);
 
 	return ret;
@@ -937,6 +956,8 @@ static int cyapa_resume(struct device *dev)
 	if (device_may_wakeup(dev) && cyapa->irq_wake)
 		disable_irq_wake(cyapa->irq);
 
+	cyapa_detect(cyapa);
+
 	ret = cyapa_set_power_mode(cyapa, PWR_MODE_FULL_ACTIVE);
 	if (ret)
 		dev_warn(dev, "resume active power failed, %d\n", ret);
-- 
1.8.1.3


  reply	other threads:[~2013-03-13 23:51 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-03-13 23:50 [PATCH 0/4] Input: cyapa - Add firmware update feature Benson Leung
2013-03-13 23:50 ` Benson Leung [this message]
2013-03-16 19:40   ` [PATCH 1/4] Input: cyapa - Move common initialization to cyapa_detect Henrik Rydberg
2013-03-13 23:50 ` [PATCH 2/4] Input: cyapa - Firmware update via request firmware Benson Leung
2013-03-14  0:38   ` Dmitry Torokhov
2013-03-16 20:00   ` Henrik Rydberg
2013-03-19  0:37     ` Benson Leung
2013-03-19 21:52       ` Henrik Rydberg
2013-03-13 23:50 ` [PATCH 3/4] Input: cyapa - Allow filename to be changed in update_fw Benson Leung
2013-03-13 23:50 ` [PATCH 4/4] Input: cyapa - Add sysfs attrs for product_id and fw version Benson Leung

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=1363218651-22457-2-git-send-email-bleung@chromium.org \
    --to=bleung@chromium.org \
    --cc=djkurtz@chromium.org \
    --cc=dmitry.torokhov@gmail.com \
    --cc=dudl@cypress.com \
    --cc=linux-input@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=olofj@chromium.org \
    --cc=rydberg@euromail.se \
    /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).