linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] io: accel: kxcjk1013: restore the range after resume.
@ 2019-02-21  3:13 He, Bo
  2019-03-03 16:17 ` Jonathan Cameron
  0 siblings, 1 reply; 7+ messages in thread
From: He, Bo @ 2019-02-21  3:13 UTC (permalink / raw)
  To: linux-kernel, linux-iio, ic23, knaack.h, lars, pmeerw, Chen, Hu1

restore the range register in case kxcjk1013 power is off after suspend

we see the issue on some laptops, after system suspend and resume,
the CTRL_REG1 register changed from 0xc8 to 0x80, so acceleration range
is changed, the patch is to restore the acceleration range after resume.

Signed-off-by: he, bo <bo.he@intel.com>
Signed-off-by: Chen, Hu <hu1.chen@intel.com>
---
 drivers/iio/accel/kxcjk-1013.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/iio/accel/kxcjk-1013.c b/drivers/iio/accel/kxcjk-1013.c
index 7506bd9..c6bb3be 100644
--- a/drivers/iio/accel/kxcjk-1013.c
+++ b/drivers/iio/accel/kxcjk-1013.c
@@ -1340,6 +1340,7 @@ static int kxcjk1013_resume(struct device *dev)
 
 	mutex_lock(&data->mutex);
 	ret = kxcjk1013_set_mode(data, OPERATION);
+	ret += kxcjk1013_set_range(data, data->range);
 	mutex_unlock(&data->mutex);
 
 	return ret;
-- 
2.7.4




^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH] io: accel: kxcjk1013: restore the range after resume.
  2019-02-21  3:13 [PATCH] io: accel: kxcjk1013: restore the range after resume He, Bo
@ 2019-03-03 16:17 ` Jonathan Cameron
  2019-03-04  7:05   ` [PATCH v2] " Chen, Hu
  0 siblings, 1 reply; 7+ messages in thread
From: Jonathan Cameron @ 2019-03-03 16:17 UTC (permalink / raw)
  To: He, Bo; +Cc: linux-kernel, linux-iio, ic23, knaack.h, lars, pmeerw, Chen, Hu1

On Thu, 21 Feb 2019 03:13:44 +0000
"He, Bo" <bo.he@intel.com> wrote:

> restore the range register in case kxcjk1013 power is off after suspend
> 
> we see the issue on some laptops, after system suspend and resume,
> the CTRL_REG1 register changed from 0xc8 to 0x80, so acceleration range
> is changed, the patch is to restore the acceleration range after resume.
> 
> Signed-off-by: he, bo <bo.he@intel.com>
> Signed-off-by: Chen, Hu <hu1.chen@intel.com>
Please don't do the ret += trick, it obscures the return value
which we may want to know if anything goes wrong.
Handle each error independently.

Thanks,

Jonathan

> ---
>  drivers/iio/accel/kxcjk-1013.c | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/drivers/iio/accel/kxcjk-1013.c b/drivers/iio/accel/kxcjk-1013.c
> index 7506bd9..c6bb3be 100644
> --- a/drivers/iio/accel/kxcjk-1013.c
> +++ b/drivers/iio/accel/kxcjk-1013.c
> @@ -1340,6 +1340,7 @@ static int kxcjk1013_resume(struct device *dev)
>  
>  	mutex_lock(&data->mutex);
>  	ret = kxcjk1013_set_mode(data, OPERATION);
> +	ret += kxcjk1013_set_range(data, data->range);
>  	mutex_unlock(&data->mutex);
>  
>  	return ret;


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH v2] io: accel: kxcjk1013: restore the range after resume.
  2019-03-03 16:17 ` Jonathan Cameron
@ 2019-03-04  7:05   ` Chen, Hu
  2019-03-04  9:16     ` Hans de Goede
  0 siblings, 1 reply; 7+ messages in thread
From: Chen, Hu @ 2019-03-04  7:05 UTC (permalink / raw)
  Cc: hu1.chen, bo.he, he, Jonathan Cameron, Hartmut Knaack,
	Lars-Peter Clausen, Peter Meerwald-Stadler, Hans de Goede,
	Stephan Gerhold, linux-iio, linux-kernel

From: "he, bo" <bo.he@intel.com>

On some laptops, kxcjk1013 is powered off when system enters S3. We need
restore the range regiter during resume. Otherwise, the sensor doesn't
work properly after S3.

Signed-off-by: he, bo <bo.he@intel.com>
Signed-off-by: Chen, Hu <hu1.chen@intel.com>
---
Changes in v2:
- Handle return value independently in resume callback.

 drivers/iio/accel/kxcjk-1013.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/drivers/iio/accel/kxcjk-1013.c b/drivers/iio/accel/kxcjk-1013.c
index 7096e577b23f..17837e26bcf2 100644
--- a/drivers/iio/accel/kxcjk-1013.c
+++ b/drivers/iio/accel/kxcjk-1013.c
@@ -1437,6 +1437,11 @@ static int kxcjk1013_resume(struct device *dev)
 
 	mutex_lock(&data->mutex);
 	ret = kxcjk1013_set_mode(data, OPERATION);
+	if (ret < 0) {
+		mutex_unlock(&data->mutex);
+		return ret;
+	}
+	ret = kxcjk1013_set_range(data, data->range);
 	mutex_unlock(&data->mutex);
 
 	return ret;
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH v2] io: accel: kxcjk1013: restore the range after resume.
  2019-03-04  7:05   ` [PATCH v2] " Chen, Hu
@ 2019-03-04  9:16     ` Hans de Goede
  2019-03-06  2:32       ` [PATCH v3] " Chen, Hu
  0 siblings, 1 reply; 7+ messages in thread
From: Hans de Goede @ 2019-03-04  9:16 UTC (permalink / raw)
  To: Chen, Hu
  Cc: bo.he, Jonathan Cameron, Hartmut Knaack, Lars-Peter Clausen,
	Peter Meerwald-Stadler, Stephan Gerhold, linux-iio, linux-kernel

Hi,

On 04-03-19 08:05, Chen, Hu wrote:
> From: "he, bo" <bo.he@intel.com>
> 
> On some laptops, kxcjk1013 is powered off when system enters S3. We need
> restore the range regiter during resume. Otherwise, the sensor doesn't
> work properly after S3.
> 
> Signed-off-by: he, bo <bo.he@intel.com>
> Signed-off-by: Chen, Hu <hu1.chen@intel.com>

Thank you for the patch.

> ---
> Changes in v2:
> - Handle return value independently in resume callback.
> 
>   drivers/iio/accel/kxcjk-1013.c | 5 +++++
>   1 file changed, 5 insertions(+)
> 
> diff --git a/drivers/iio/accel/kxcjk-1013.c b/drivers/iio/accel/kxcjk-1013.c
> index 7096e577b23f..17837e26bcf2 100644
> --- a/drivers/iio/accel/kxcjk-1013.c
> +++ b/drivers/iio/accel/kxcjk-1013.c
> @@ -1437,6 +1437,11 @@ static int kxcjk1013_resume(struct device *dev)
>   
>   	mutex_lock(&data->mutex);
>   	ret = kxcjk1013_set_mode(data, OPERATION);
> +	if (ret < 0) {
> +		mutex_unlock(&data->mutex);
> +		return ret;
> +	}
> +	ret = kxcjk1013_set_range(data, data->range);
>   	mutex_unlock(&data->mutex);
>   
>   	return ret;


I'm not a fan of the extra unlock, IMHO it would be better to instead do:

  	mutex_lock(&data->mutex);
  	ret = kxcjk1013_set_mode(data, OPERATION);
	if (ret == 0)
		ret = kxcjk1013_set_range(data, data->range);
  	mutex_unlock(&data->mutex);

Regards,

Hans


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH v3] io: accel: kxcjk1013: restore the range after resume.
  2019-03-04  9:16     ` Hans de Goede
@ 2019-03-06  2:32       ` Chen, Hu
  2019-03-06  8:43         ` Hans de Goede
  0 siblings, 1 reply; 7+ messages in thread
From: Chen, Hu @ 2019-03-06  2:32 UTC (permalink / raw)
  Cc: hu1.chen, bo.he, he, Jonathan Cameron, Hartmut Knaack,
	Lars-Peter Clausen, Peter Meerwald-Stadler, Hans de Goede,
	Stephan Gerhold, linux-iio, linux-kernel

From: "he, bo" <bo.he@intel.com>

On some laptops, kxcjk1013 is powered off when system enters S3. We need
restore the range regiter during resume. Otherwise, the sensor doesn't
work properly after S3.

Signed-off-by: he, bo <bo.he@intel.com>
Signed-off-by: Chen, Hu <hu1.chen@intel.com>
---
 v3: Avoid unnecessary mutex_unlock (Hans).
 v2: Handle return value independently (Jonathan).

 drivers/iio/accel/kxcjk-1013.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/iio/accel/kxcjk-1013.c b/drivers/iio/accel/kxcjk-1013.c
index 7096e577b23f..50f3ff386bea 100644
--- a/drivers/iio/accel/kxcjk-1013.c
+++ b/drivers/iio/accel/kxcjk-1013.c
@@ -1437,6 +1437,8 @@ static int kxcjk1013_resume(struct device *dev)
 
 	mutex_lock(&data->mutex);
 	ret = kxcjk1013_set_mode(data, OPERATION);
+	if (ret == 0)
+		ret = kxcjk1013_set_range(data, data->range);
 	mutex_unlock(&data->mutex);
 
 	return ret;
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH v3] io: accel: kxcjk1013: restore the range after resume.
  2019-03-06  2:32       ` [PATCH v3] " Chen, Hu
@ 2019-03-06  8:43         ` Hans de Goede
  2019-03-09 17:32           ` Jonathan Cameron
  0 siblings, 1 reply; 7+ messages in thread
From: Hans de Goede @ 2019-03-06  8:43 UTC (permalink / raw)
  To: Chen, Hu
  Cc: bo.he, Jonathan Cameron, Hartmut Knaack, Lars-Peter Clausen,
	Peter Meerwald-Stadler, Stephan Gerhold, linux-iio, linux-kernel

Hi,

On 06-03-19 03:32, Chen, Hu wrote:
> From: "he, bo" <bo.he@intel.com>
> 
> On some laptops, kxcjk1013 is powered off when system enters S3. We need
> restore the range regiter during resume. Otherwise, the sensor doesn't
> work properly after S3.
> 
> Signed-off-by: he, bo <bo.he@intel.com>
> Signed-off-by: Chen, Hu <hu1.chen@intel.com>

Thanks, patch looks good to me:

Reviewed-by: Hans de Goede <hdegoede@redhat.com>

Regards,

Hans



> ---
>   v3: Avoid unnecessary mutex_unlock (Hans).
>   v2: Handle return value independently (Jonathan).
> 
>   drivers/iio/accel/kxcjk-1013.c | 2 ++
>   1 file changed, 2 insertions(+)
> 
> diff --git a/drivers/iio/accel/kxcjk-1013.c b/drivers/iio/accel/kxcjk-1013.c
> index 7096e577b23f..50f3ff386bea 100644
> --- a/drivers/iio/accel/kxcjk-1013.c
> +++ b/drivers/iio/accel/kxcjk-1013.c
> @@ -1437,6 +1437,8 @@ static int kxcjk1013_resume(struct device *dev)
>   
>   	mutex_lock(&data->mutex);
>   	ret = kxcjk1013_set_mode(data, OPERATION);
> +	if (ret == 0)
> +		ret = kxcjk1013_set_range(data, data->range);
>   	mutex_unlock(&data->mutex);
>   
>   	return ret;
> 

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH v3] io: accel: kxcjk1013: restore the range after resume.
  2019-03-06  8:43         ` Hans de Goede
@ 2019-03-09 17:32           ` Jonathan Cameron
  0 siblings, 0 replies; 7+ messages in thread
From: Jonathan Cameron @ 2019-03-09 17:32 UTC (permalink / raw)
  To: Hans de Goede
  Cc: Chen, Hu, bo.he, Hartmut Knaack, Lars-Peter Clausen,
	Peter Meerwald-Stadler, Stephan Gerhold, linux-iio, linux-kernel

On Wed, 6 Mar 2019 09:43:24 +0100
Hans de Goede <hdegoede@redhat.com> wrote:

> Hi,
> 
> On 06-03-19 03:32, Chen, Hu wrote:
> > From: "he, bo" <bo.he@intel.com>
> > 
> > On some laptops, kxcjk1013 is powered off when system enters S3. We need
> > restore the range regiter during resume. Otherwise, the sensor doesn't
> > work properly after S3.
> > 
> > Signed-off-by: he, bo <bo.he@intel.com>
> > Signed-off-by: Chen, Hu <hu1.chen@intel.com>  
> 
> Thanks, patch looks good to me:
I'd have had an ever so slight preference for a goto as I prefer
errors to be checked for rather than good paths (as that's the more
common pattern), but I don't care strongly enough to ask for
a v4!

> 
> Reviewed-by: Hans de Goede <hdegoede@redhat.com>
Applied to the fixes-togreg branch of iio.git and marked for stable.

Thanks,

Jonathan
> 
> Regards,
> 
> Hans
> 
> 
> 
> > ---
> >   v3: Avoid unnecessary mutex_unlock (Hans).
> >   v2: Handle return value independently (Jonathan).
> > 
> >   drivers/iio/accel/kxcjk-1013.c | 2 ++
> >   1 file changed, 2 insertions(+)
> > 
> > diff --git a/drivers/iio/accel/kxcjk-1013.c b/drivers/iio/accel/kxcjk-1013.c
> > index 7096e577b23f..50f3ff386bea 100644
> > --- a/drivers/iio/accel/kxcjk-1013.c
> > +++ b/drivers/iio/accel/kxcjk-1013.c
> > @@ -1437,6 +1437,8 @@ static int kxcjk1013_resume(struct device *dev)
> >   
> >   	mutex_lock(&data->mutex);
> >   	ret = kxcjk1013_set_mode(data, OPERATION);
> > +	if (ret == 0)
> > +		ret = kxcjk1013_set_range(data, data->range);
> >   	mutex_unlock(&data->mutex);
> >   
> >   	return ret;
> >   


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2019-03-09 17:32 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-02-21  3:13 [PATCH] io: accel: kxcjk1013: restore the range after resume He, Bo
2019-03-03 16:17 ` Jonathan Cameron
2019-03-04  7:05   ` [PATCH v2] " Chen, Hu
2019-03-04  9:16     ` Hans de Goede
2019-03-06  2:32       ` [PATCH v3] " Chen, Hu
2019-03-06  8:43         ` Hans de Goede
2019-03-09 17:32           ` Jonathan Cameron

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).