Re: [PATCH v1 4/7] input: cyapa: fully support runtime suspend power management

2015-07-20 Thread Dmitry Torokhov
On Mon, Jun 15, 2015 at 05:01:34PM +0800, Dudley Du wrote:
> Fix the the runtime suspend power management not working issue when system
> starts up and before user touches the trackpad device.
> TEST=test on Chromebook.
> 
> Signed-off-by: Dudley Du 

Applied, thank you.

> ---
>  drivers/input/mouse/cyapa.c  | 79 
> +++-
>  drivers/input/mouse/cyapa.h  |  2 +-
>  drivers/input/mouse/cyapa_gen3.c |  4 +-
>  drivers/input/mouse/cyapa_gen5.c | 21 +++
>  drivers/input/mouse/cyapa_gen6.c |  4 +-
>  5 files changed, 72 insertions(+), 38 deletions(-)
> 
> diff --git a/drivers/input/mouse/cyapa.c b/drivers/input/mouse/cyapa.c
> index d2a24fc..9288948 100644
> --- a/drivers/input/mouse/cyapa.c
> +++ b/drivers/input/mouse/cyapa.c
> @@ -371,7 +371,7 @@ static int cyapa_detect(struct cyapa *cyapa)
>  static int cyapa_open(struct input_dev *input)
>  {
>   struct cyapa *cyapa = input_get_drvdata(input);
> - struct i2c_client *client = cyapa->client;
> + struct device *dev = >client->dev;
>   int error;
>  
>   error = mutex_lock_interruptible(>state_sync_lock);
> @@ -385,10 +385,9 @@ static int cyapa_open(struct input_dev *input)
>* when in operational mode.
>*/
>   error = cyapa->ops->set_power_mode(cyapa,
> - PWR_MODE_FULL_ACTIVE, 0);
> + PWR_MODE_FULL_ACTIVE, 0, false);
>   if (error) {
> - dev_warn(>dev,
> - "set active power failed: %d\n", error);
> + dev_warn(dev, "set active power failed: %d\n", error);
>   goto out;
>   }
>   } else {
> @@ -399,11 +398,15 @@ static int cyapa_open(struct input_dev *input)
>   }
>   }
>  
> - enable_irq(client->irq);
> - if (!pm_runtime_enabled(>dev)) {
> - pm_runtime_set_active(>dev);
> - pm_runtime_enable(>dev);
> + enable_irq(cyapa->client->irq);
> + if (!pm_runtime_enabled(dev)) {
> + pm_runtime_set_active(dev);
> + pm_runtime_enable(dev);
>   }
> +
> + pm_runtime_get_sync(dev);
> + pm_runtime_mark_last_busy(dev);
> + pm_runtime_put_sync_autosuspend(dev);
>  out:
>   mutex_unlock(>state_sync_lock);
>   return error;
> @@ -412,17 +415,17 @@ out:
>  static void cyapa_close(struct input_dev *input)
>  {
>   struct cyapa *cyapa = input_get_drvdata(input);
> - struct i2c_client *client = cyapa->client;
> + struct device *dev = >client->dev;
>  
>   mutex_lock(>state_sync_lock);
>  
> - disable_irq(client->irq);
> - if (pm_runtime_enabled(>dev))
> - pm_runtime_disable(>dev);
> - pm_runtime_set_suspended(>dev);
> + disable_irq(cyapa->client->irq);
> + if (pm_runtime_enabled(dev))
> + pm_runtime_disable(dev);
> + pm_runtime_set_suspended(dev);
>  
>   if (cyapa->operational)
> - cyapa->ops->set_power_mode(cyapa, PWR_MODE_OFF, 0);
> + cyapa->ops->set_power_mode(cyapa, PWR_MODE_OFF, 0, false);
>  
>   mutex_unlock(>state_sync_lock);
>  }
> @@ -533,7 +536,7 @@ static void cyapa_enable_irq_for_cmd(struct cyapa *cyapa)
>*/
>   if (!input || cyapa->operational)
>   cyapa->ops->set_power_mode(cyapa,
> - PWR_MODE_FULL_ACTIVE, 0);
> + PWR_MODE_FULL_ACTIVE, 0, false);
>   /* Gen3 always using polling mode for command. */
>   if (cyapa->gen >= CYAPA_GEN5)
>   enable_irq(cyapa->client->irq);
> @@ -548,7 +551,8 @@ static void cyapa_disable_irq_for_cmd(struct cyapa *cyapa)
>   if (cyapa->gen >= CYAPA_GEN5)
>   disable_irq(cyapa->client->irq);
>   if (!input || cyapa->operational)
> - cyapa->ops->set_power_mode(cyapa, PWR_MODE_OFF, 0);
> + cyapa->ops->set_power_mode(cyapa,
> +PWR_MODE_OFF, 0, false);
>   }
>  }
>  
> @@ -615,7 +619,7 @@ static int cyapa_initialize(struct cyapa *cyapa)
>  
>   /* Power down the device until we need it. */
>   if (cyapa->operational)
> - cyapa->ops->set_power_mode(cyapa, PWR_MODE_OFF, 0);
> + cyapa->ops->set_power_mode(cyapa, PWR_MODE_OFF, 0, false);
>  
>   return 0;
>  }
> @@ -631,7 +635,8 @@ static int cyapa_reinitialize(struct cyapa *cyapa)
>  
>   /* Avoid command failures when TP was in OFF state. */
>   if (cyapa->operational)
> - cyapa->ops->set_power_mode(cyapa, PWR_MODE_FULL_ACTIVE, 0);
> + cyapa->ops->set_power_mode(cyapa,
> +PWR_MODE_FULL_ACTIVE, 0, false);
>  
>   error = cyapa_detect(cyapa);
>   if (error)
> @@ -650,7 +655,8 @@ out:
>   if (!input || !input->users) {
> 

Re: [PATCH v1 4/7] input: cyapa: fully support runtime suspend power management

2015-07-20 Thread Dmitry Torokhov
On Mon, Jun 15, 2015 at 05:01:34PM +0800, Dudley Du wrote:
 Fix the the runtime suspend power management not working issue when system
 starts up and before user touches the trackpad device.
 TEST=test on Chromebook.
 
 Signed-off-by: Dudley Du d...@cypress.com

Applied, thank you.

 ---
  drivers/input/mouse/cyapa.c  | 79 
 +++-
  drivers/input/mouse/cyapa.h  |  2 +-
  drivers/input/mouse/cyapa_gen3.c |  4 +-
  drivers/input/mouse/cyapa_gen5.c | 21 +++
  drivers/input/mouse/cyapa_gen6.c |  4 +-
  5 files changed, 72 insertions(+), 38 deletions(-)
 
 diff --git a/drivers/input/mouse/cyapa.c b/drivers/input/mouse/cyapa.c
 index d2a24fc..9288948 100644
 --- a/drivers/input/mouse/cyapa.c
 +++ b/drivers/input/mouse/cyapa.c
 @@ -371,7 +371,7 @@ static int cyapa_detect(struct cyapa *cyapa)
  static int cyapa_open(struct input_dev *input)
  {
   struct cyapa *cyapa = input_get_drvdata(input);
 - struct i2c_client *client = cyapa-client;
 + struct device *dev = cyapa-client-dev;
   int error;
  
   error = mutex_lock_interruptible(cyapa-state_sync_lock);
 @@ -385,10 +385,9 @@ static int cyapa_open(struct input_dev *input)
* when in operational mode.
*/
   error = cyapa-ops-set_power_mode(cyapa,
 - PWR_MODE_FULL_ACTIVE, 0);
 + PWR_MODE_FULL_ACTIVE, 0, false);
   if (error) {
 - dev_warn(client-dev,
 - set active power failed: %d\n, error);
 + dev_warn(dev, set active power failed: %d\n, error);
   goto out;
   }
   } else {
 @@ -399,11 +398,15 @@ static int cyapa_open(struct input_dev *input)
   }
   }
  
 - enable_irq(client-irq);
 - if (!pm_runtime_enabled(client-dev)) {
 - pm_runtime_set_active(client-dev);
 - pm_runtime_enable(client-dev);
 + enable_irq(cyapa-client-irq);
 + if (!pm_runtime_enabled(dev)) {
 + pm_runtime_set_active(dev);
 + pm_runtime_enable(dev);
   }
 +
 + pm_runtime_get_sync(dev);
 + pm_runtime_mark_last_busy(dev);
 + pm_runtime_put_sync_autosuspend(dev);
  out:
   mutex_unlock(cyapa-state_sync_lock);
   return error;
 @@ -412,17 +415,17 @@ out:
  static void cyapa_close(struct input_dev *input)
  {
   struct cyapa *cyapa = input_get_drvdata(input);
 - struct i2c_client *client = cyapa-client;
 + struct device *dev = cyapa-client-dev;
  
   mutex_lock(cyapa-state_sync_lock);
  
 - disable_irq(client-irq);
 - if (pm_runtime_enabled(client-dev))
 - pm_runtime_disable(client-dev);
 - pm_runtime_set_suspended(client-dev);
 + disable_irq(cyapa-client-irq);
 + if (pm_runtime_enabled(dev))
 + pm_runtime_disable(dev);
 + pm_runtime_set_suspended(dev);
  
   if (cyapa-operational)
 - cyapa-ops-set_power_mode(cyapa, PWR_MODE_OFF, 0);
 + cyapa-ops-set_power_mode(cyapa, PWR_MODE_OFF, 0, false);
  
   mutex_unlock(cyapa-state_sync_lock);
  }
 @@ -533,7 +536,7 @@ static void cyapa_enable_irq_for_cmd(struct cyapa *cyapa)
*/
   if (!input || cyapa-operational)
   cyapa-ops-set_power_mode(cyapa,
 - PWR_MODE_FULL_ACTIVE, 0);
 + PWR_MODE_FULL_ACTIVE, 0, false);
   /* Gen3 always using polling mode for command. */
   if (cyapa-gen = CYAPA_GEN5)
   enable_irq(cyapa-client-irq);
 @@ -548,7 +551,8 @@ static void cyapa_disable_irq_for_cmd(struct cyapa *cyapa)
   if (cyapa-gen = CYAPA_GEN5)
   disable_irq(cyapa-client-irq);
   if (!input || cyapa-operational)
 - cyapa-ops-set_power_mode(cyapa, PWR_MODE_OFF, 0);
 + cyapa-ops-set_power_mode(cyapa,
 +PWR_MODE_OFF, 0, false);
   }
  }
  
 @@ -615,7 +619,7 @@ static int cyapa_initialize(struct cyapa *cyapa)
  
   /* Power down the device until we need it. */
   if (cyapa-operational)
 - cyapa-ops-set_power_mode(cyapa, PWR_MODE_OFF, 0);
 + cyapa-ops-set_power_mode(cyapa, PWR_MODE_OFF, 0, false);
  
   return 0;
  }
 @@ -631,7 +635,8 @@ static int cyapa_reinitialize(struct cyapa *cyapa)
  
   /* Avoid command failures when TP was in OFF state. */
   if (cyapa-operational)
 - cyapa-ops-set_power_mode(cyapa, PWR_MODE_FULL_ACTIVE, 0);
 + cyapa-ops-set_power_mode(cyapa,
 +PWR_MODE_FULL_ACTIVE, 0, false);
  
   error = cyapa_detect(cyapa);
   if (error)
 @@ -650,7 +655,8 @@ out:
   if (!input || !input-users) {
   /* Reset to power OFF state to save power when no user open. */
   

[PATCH v1 4/7] input: cyapa: fully support runtime suspend power management

2015-06-15 Thread Dudley Du
Fix the the runtime suspend power management not working issue when system
starts up and before user touches the trackpad device.
TEST=test on Chromebook.

Signed-off-by: Dudley Du 
---
 drivers/input/mouse/cyapa.c  | 79 +++-
 drivers/input/mouse/cyapa.h  |  2 +-
 drivers/input/mouse/cyapa_gen3.c |  4 +-
 drivers/input/mouse/cyapa_gen5.c | 21 +++
 drivers/input/mouse/cyapa_gen6.c |  4 +-
 5 files changed, 72 insertions(+), 38 deletions(-)

diff --git a/drivers/input/mouse/cyapa.c b/drivers/input/mouse/cyapa.c
index d2a24fc..9288948 100644
--- a/drivers/input/mouse/cyapa.c
+++ b/drivers/input/mouse/cyapa.c
@@ -371,7 +371,7 @@ static int cyapa_detect(struct cyapa *cyapa)
 static int cyapa_open(struct input_dev *input)
 {
struct cyapa *cyapa = input_get_drvdata(input);
-   struct i2c_client *client = cyapa->client;
+   struct device *dev = >client->dev;
int error;
 
error = mutex_lock_interruptible(>state_sync_lock);
@@ -385,10 +385,9 @@ static int cyapa_open(struct input_dev *input)
 * when in operational mode.
 */
error = cyapa->ops->set_power_mode(cyapa,
-   PWR_MODE_FULL_ACTIVE, 0);
+   PWR_MODE_FULL_ACTIVE, 0, false);
if (error) {
-   dev_warn(>dev,
-   "set active power failed: %d\n", error);
+   dev_warn(dev, "set active power failed: %d\n", error);
goto out;
}
} else {
@@ -399,11 +398,15 @@ static int cyapa_open(struct input_dev *input)
}
}
 
-   enable_irq(client->irq);
-   if (!pm_runtime_enabled(>dev)) {
-   pm_runtime_set_active(>dev);
-   pm_runtime_enable(>dev);
+   enable_irq(cyapa->client->irq);
+   if (!pm_runtime_enabled(dev)) {
+   pm_runtime_set_active(dev);
+   pm_runtime_enable(dev);
}
+
+   pm_runtime_get_sync(dev);
+   pm_runtime_mark_last_busy(dev);
+   pm_runtime_put_sync_autosuspend(dev);
 out:
mutex_unlock(>state_sync_lock);
return error;
@@ -412,17 +415,17 @@ out:
 static void cyapa_close(struct input_dev *input)
 {
struct cyapa *cyapa = input_get_drvdata(input);
-   struct i2c_client *client = cyapa->client;
+   struct device *dev = >client->dev;
 
mutex_lock(>state_sync_lock);
 
-   disable_irq(client->irq);
-   if (pm_runtime_enabled(>dev))
-   pm_runtime_disable(>dev);
-   pm_runtime_set_suspended(>dev);
+   disable_irq(cyapa->client->irq);
+   if (pm_runtime_enabled(dev))
+   pm_runtime_disable(dev);
+   pm_runtime_set_suspended(dev);
 
if (cyapa->operational)
-   cyapa->ops->set_power_mode(cyapa, PWR_MODE_OFF, 0);
+   cyapa->ops->set_power_mode(cyapa, PWR_MODE_OFF, 0, false);
 
mutex_unlock(>state_sync_lock);
 }
@@ -533,7 +536,7 @@ static void cyapa_enable_irq_for_cmd(struct cyapa *cyapa)
 */
if (!input || cyapa->operational)
cyapa->ops->set_power_mode(cyapa,
-   PWR_MODE_FULL_ACTIVE, 0);
+   PWR_MODE_FULL_ACTIVE, 0, false);
/* Gen3 always using polling mode for command. */
if (cyapa->gen >= CYAPA_GEN5)
enable_irq(cyapa->client->irq);
@@ -548,7 +551,8 @@ static void cyapa_disable_irq_for_cmd(struct cyapa *cyapa)
if (cyapa->gen >= CYAPA_GEN5)
disable_irq(cyapa->client->irq);
if (!input || cyapa->operational)
-   cyapa->ops->set_power_mode(cyapa, PWR_MODE_OFF, 0);
+   cyapa->ops->set_power_mode(cyapa,
+  PWR_MODE_OFF, 0, false);
}
 }
 
@@ -615,7 +619,7 @@ static int cyapa_initialize(struct cyapa *cyapa)
 
/* Power down the device until we need it. */
if (cyapa->operational)
-   cyapa->ops->set_power_mode(cyapa, PWR_MODE_OFF, 0);
+   cyapa->ops->set_power_mode(cyapa, PWR_MODE_OFF, 0, false);
 
return 0;
 }
@@ -631,7 +635,8 @@ static int cyapa_reinitialize(struct cyapa *cyapa)
 
/* Avoid command failures when TP was in OFF state. */
if (cyapa->operational)
-   cyapa->ops->set_power_mode(cyapa, PWR_MODE_FULL_ACTIVE, 0);
+   cyapa->ops->set_power_mode(cyapa,
+  PWR_MODE_FULL_ACTIVE, 0, false);
 
error = cyapa_detect(cyapa);
if (error)
@@ -650,7 +655,8 @@ out:
if (!input || !input->users) {
/* Reset to power OFF state to save power when no user open. */
if (cyapa->operational)
-   cyapa->ops->set_power_mode(cyapa, 

[PATCH v1 4/7] input: cyapa: fully support runtime suspend power management

2015-06-15 Thread Dudley Du
Fix the the runtime suspend power management not working issue when system
starts up and before user touches the trackpad device.
TEST=test on Chromebook.

Signed-off-by: Dudley Du d...@cypress.com
---
 drivers/input/mouse/cyapa.c  | 79 +++-
 drivers/input/mouse/cyapa.h  |  2 +-
 drivers/input/mouse/cyapa_gen3.c |  4 +-
 drivers/input/mouse/cyapa_gen5.c | 21 +++
 drivers/input/mouse/cyapa_gen6.c |  4 +-
 5 files changed, 72 insertions(+), 38 deletions(-)

diff --git a/drivers/input/mouse/cyapa.c b/drivers/input/mouse/cyapa.c
index d2a24fc..9288948 100644
--- a/drivers/input/mouse/cyapa.c
+++ b/drivers/input/mouse/cyapa.c
@@ -371,7 +371,7 @@ static int cyapa_detect(struct cyapa *cyapa)
 static int cyapa_open(struct input_dev *input)
 {
struct cyapa *cyapa = input_get_drvdata(input);
-   struct i2c_client *client = cyapa-client;
+   struct device *dev = cyapa-client-dev;
int error;
 
error = mutex_lock_interruptible(cyapa-state_sync_lock);
@@ -385,10 +385,9 @@ static int cyapa_open(struct input_dev *input)
 * when in operational mode.
 */
error = cyapa-ops-set_power_mode(cyapa,
-   PWR_MODE_FULL_ACTIVE, 0);
+   PWR_MODE_FULL_ACTIVE, 0, false);
if (error) {
-   dev_warn(client-dev,
-   set active power failed: %d\n, error);
+   dev_warn(dev, set active power failed: %d\n, error);
goto out;
}
} else {
@@ -399,11 +398,15 @@ static int cyapa_open(struct input_dev *input)
}
}
 
-   enable_irq(client-irq);
-   if (!pm_runtime_enabled(client-dev)) {
-   pm_runtime_set_active(client-dev);
-   pm_runtime_enable(client-dev);
+   enable_irq(cyapa-client-irq);
+   if (!pm_runtime_enabled(dev)) {
+   pm_runtime_set_active(dev);
+   pm_runtime_enable(dev);
}
+
+   pm_runtime_get_sync(dev);
+   pm_runtime_mark_last_busy(dev);
+   pm_runtime_put_sync_autosuspend(dev);
 out:
mutex_unlock(cyapa-state_sync_lock);
return error;
@@ -412,17 +415,17 @@ out:
 static void cyapa_close(struct input_dev *input)
 {
struct cyapa *cyapa = input_get_drvdata(input);
-   struct i2c_client *client = cyapa-client;
+   struct device *dev = cyapa-client-dev;
 
mutex_lock(cyapa-state_sync_lock);
 
-   disable_irq(client-irq);
-   if (pm_runtime_enabled(client-dev))
-   pm_runtime_disable(client-dev);
-   pm_runtime_set_suspended(client-dev);
+   disable_irq(cyapa-client-irq);
+   if (pm_runtime_enabled(dev))
+   pm_runtime_disable(dev);
+   pm_runtime_set_suspended(dev);
 
if (cyapa-operational)
-   cyapa-ops-set_power_mode(cyapa, PWR_MODE_OFF, 0);
+   cyapa-ops-set_power_mode(cyapa, PWR_MODE_OFF, 0, false);
 
mutex_unlock(cyapa-state_sync_lock);
 }
@@ -533,7 +536,7 @@ static void cyapa_enable_irq_for_cmd(struct cyapa *cyapa)
 */
if (!input || cyapa-operational)
cyapa-ops-set_power_mode(cyapa,
-   PWR_MODE_FULL_ACTIVE, 0);
+   PWR_MODE_FULL_ACTIVE, 0, false);
/* Gen3 always using polling mode for command. */
if (cyapa-gen = CYAPA_GEN5)
enable_irq(cyapa-client-irq);
@@ -548,7 +551,8 @@ static void cyapa_disable_irq_for_cmd(struct cyapa *cyapa)
if (cyapa-gen = CYAPA_GEN5)
disable_irq(cyapa-client-irq);
if (!input || cyapa-operational)
-   cyapa-ops-set_power_mode(cyapa, PWR_MODE_OFF, 0);
+   cyapa-ops-set_power_mode(cyapa,
+  PWR_MODE_OFF, 0, false);
}
 }
 
@@ -615,7 +619,7 @@ static int cyapa_initialize(struct cyapa *cyapa)
 
/* Power down the device until we need it. */
if (cyapa-operational)
-   cyapa-ops-set_power_mode(cyapa, PWR_MODE_OFF, 0);
+   cyapa-ops-set_power_mode(cyapa, PWR_MODE_OFF, 0, false);
 
return 0;
 }
@@ -631,7 +635,8 @@ static int cyapa_reinitialize(struct cyapa *cyapa)
 
/* Avoid command failures when TP was in OFF state. */
if (cyapa-operational)
-   cyapa-ops-set_power_mode(cyapa, PWR_MODE_FULL_ACTIVE, 0);
+   cyapa-ops-set_power_mode(cyapa,
+  PWR_MODE_FULL_ACTIVE, 0, false);
 
error = cyapa_detect(cyapa);
if (error)
@@ -650,7 +655,8 @@ out:
if (!input || !input-users) {
/* Reset to power OFF state to save power when no user open. */
if (cyapa-operational)
-