devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jeff LaBundy <jeff@labundy.com>
To: dmitry.torokhov@gmail.com, robh+dt@kernel.org
Cc: linux-input@vger.kernel.org, devicetree@vger.kernel.org,
	Jeff LaBundy <jeff@labundy.com>
Subject: [PATCH 7/9] Input: iqs5xx - suspend or resume regardless of users
Date: Thu,  4 Mar 2021 22:12:34 -0600	[thread overview]
Message-ID: <20210305041236.3489-8-jeff@labundy.com> (raw)
In-Reply-To: <20210305041236.3489-1-jeff@labundy.com>

The device should be allowed to enter its lowest-power state during
suspend, even if there are no users. Therefore, drop the check from
iqs5xx_suspend().

It follows that the same check must be removed from iqs5xx_resume()
since users are not guaranteed to be present upon resume, and there
would be no way to power the device back up.

This change makes iqs5xx_suspend() and iqs5xx_resume() both smaller
and easier to follow. And because these are the only functions that
call iqs5xx_set_state() now, call device_may_wakeup() from there to
avoid duplicate logic.

While here, collapse the return path for iqs5xx_set_state() to save
a few lines of code.

Signed-off-by: Jeff LaBundy <jeff@labundy.com>
---
 drivers/input/touchscreen/iqs5xx.c | 41 +++---------------------------
 1 file changed, 4 insertions(+), 37 deletions(-)

diff --git a/drivers/input/touchscreen/iqs5xx.c b/drivers/input/touchscreen/iqs5xx.c
index 350466ff6bbd..180d2618d8c6 100644
--- a/drivers/input/touchscreen/iqs5xx.c
+++ b/drivers/input/touchscreen/iqs5xx.c
@@ -39,9 +39,7 @@
 
 #define IQS5XX_SHOW_RESET	BIT(7)
 #define IQS5XX_ACK_RESET	BIT(7)
-
 #define IQS5XX_SUSPEND		BIT(0)
-#define IQS5XX_RESUME		0
 
 #define IQS5XX_SETUP_COMPLETE	BIT(6)
 #define IQS5XX_WDT		BIT(5)
@@ -442,7 +440,7 @@ static int iqs5xx_set_state(struct i2c_client *client, u8 state)
 	struct iqs5xx_private *iqs5xx = i2c_get_clientdata(client);
 	int error1, error2;
 
-	if (!iqs5xx->dev_id_info.bl_status)
+	if (!iqs5xx->dev_id_info.bl_status || device_may_wakeup(&client->dev))
 		return 0;
 
 	mutex_lock(&iqs5xx->lock);
@@ -462,10 +460,7 @@ static int iqs5xx_set_state(struct i2c_client *client, u8 state)
 
 	mutex_unlock(&iqs5xx->lock);
 
-	if (error1)
-		return error1;
-
-	return error2;
+	return error1 ? : error2;
 }
 
 static int iqs5xx_axis_init(struct i2c_client *client)
@@ -946,40 +941,12 @@ static const struct attribute_group iqs5xx_attr_group = {
 
 static int __maybe_unused iqs5xx_suspend(struct device *dev)
 {
-	struct iqs5xx_private *iqs5xx = dev_get_drvdata(dev);
-	struct input_dev *input = iqs5xx->input;
-	int error = 0;
-
-	if (!input || device_may_wakeup(dev))
-		return error;
-
-	mutex_lock(&input->mutex);
-
-	if (input_device_enabled(input))
-		error = iqs5xx_set_state(iqs5xx->client, IQS5XX_SUSPEND);
-
-	mutex_unlock(&input->mutex);
-
-	return error;
+	return iqs5xx_set_state(to_i2c_client(dev), IQS5XX_SUSPEND);
 }
 
 static int __maybe_unused iqs5xx_resume(struct device *dev)
 {
-	struct iqs5xx_private *iqs5xx = dev_get_drvdata(dev);
-	struct input_dev *input = iqs5xx->input;
-	int error = 0;
-
-	if (!input || device_may_wakeup(dev))
-		return error;
-
-	mutex_lock(&input->mutex);
-
-	if (input_device_enabled(input))
-		error = iqs5xx_set_state(iqs5xx->client, IQS5XX_RESUME);
-
-	mutex_unlock(&input->mutex);
-
-	return error;
+	return iqs5xx_set_state(to_i2c_client(dev), 0);
 }
 
 static SIMPLE_DEV_PM_OPS(iqs5xx_pm, iqs5xx_suspend, iqs5xx_resume);
-- 
2.17.1


  parent reply	other threads:[~2021-03-05  4:13 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-05  4:12 [PATCH 0/9] Input: iqs5xx - more enhancements and optimizations Jeff LaBundy
2021-03-05  4:12 ` [PATCH 1/9] Input: iqs5xx - update vendor's URL Jeff LaBundy
2021-03-05  4:12 ` [PATCH 2/9] Input: iqs5xx - optimize axis definition and validation Jeff LaBundy
2021-03-05  4:12 ` [PATCH 3/9] Input: iqs5xx - expose firmware revision to user space Jeff LaBundy
2021-03-05  4:12 ` [PATCH 4/9] Input: iqs5xx - remove superfluous revision validation Jeff LaBundy
2021-03-05  4:12 ` [PATCH 5/9] Input: iqs5xx - close bootloader using hardware reset Jeff LaBundy
2021-03-05  4:12 ` [PATCH 6/9] Input: iqs5xx - prevent interrupt storm during removal Jeff LaBundy
2021-03-05  4:12 ` Jeff LaBundy [this message]
2021-03-05  4:12 ` [PATCH 8/9] Input: iqs5xx - make reset GPIO optional Jeff LaBundy
2021-03-05  4:12 ` [PATCH 9/9] dt-bindings: input: iqs5xx: Convert to YAML Jeff LaBundy
2021-03-08 21:46   ` Rob Herring

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=20210305041236.3489-8-jeff@labundy.com \
    --to=jeff@labundy.com \
    --cc=devicetree@vger.kernel.org \
    --cc=dmitry.torokhov@gmail.com \
    --cc=linux-input@vger.kernel.org \
    --cc=robh+dt@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).