2019-02-21 03:14:35

by He, Bo

[permalink] [raw]
Subject: [PATCH] io: accel: kxcjk1013: restore the range after resume.

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 <[email protected]>
Signed-off-by: Chen, Hu <[email protected]>
---
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





2019-03-03 16:18:09

by Jonathan Cameron

[permalink] [raw]
Subject: Re: [PATCH] io: accel: kxcjk1013: restore the range after resume.

On Thu, 21 Feb 2019 03:13:44 +0000
"He, Bo" <[email protected]> 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 <[email protected]>
> Signed-off-by: Chen, Hu <[email protected]>
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;


2019-03-04 07:24:47

by Chen Hu

[permalink] [raw]
Subject: [PATCH v2] io: accel: kxcjk1013: restore the range after resume.

From: "he, bo" <[email protected]>

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 <[email protected]>
Signed-off-by: Chen, Hu <[email protected]>
---
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


2019-03-04 09:18:57

by Hans de Goede

[permalink] [raw]
Subject: Re: [PATCH v2] io: accel: kxcjk1013: restore the range after resume.

Hi,

On 04-03-19 08:05, Chen, Hu wrote:
> From: "he, bo" <[email protected]>
>
> 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 <[email protected]>
> Signed-off-by: Chen, Hu <[email protected]>

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


2019-03-06 03:39:01

by Chen Hu

[permalink] [raw]
Subject: [PATCH v3] io: accel: kxcjk1013: restore the range after resume.

From: "he, bo" <[email protected]>

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 <[email protected]>
Signed-off-by: Chen, Hu <[email protected]>
---
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


2019-03-06 08:58:49

by Hans de Goede

[permalink] [raw]
Subject: Re: [PATCH v3] io: accel: kxcjk1013: restore the range after resume.

Hi,

On 06-03-19 03:32, Chen, Hu wrote:
> From: "he, bo" <[email protected]>
>
> 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 <[email protected]>
> Signed-off-by: Chen, Hu <[email protected]>

Thanks, patch looks good to me:

Reviewed-by: Hans de Goede <[email protected]>

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;
>

2019-03-09 17:32:56

by Jonathan Cameron

[permalink] [raw]
Subject: Re: [PATCH v3] io: accel: kxcjk1013: restore the range after resume.

On Wed, 6 Mar 2019 09:43:24 +0100
Hans de Goede <[email protected]> wrote:

> Hi,
>
> On 06-03-19 03:32, Chen, Hu wrote:
> > From: "he, bo" <[email protected]>
> >
> > 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 <[email protected]>
> > Signed-off-by: Chen, Hu <[email protected]>
>
> 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 <[email protected]>
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;
> >