linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] Input: Change msleep to usleep_range for small msecs
@ 2016-11-24 16:03 Aniroop Mathur
  2016-11-28 16:35 ` Aniroop Mathur
  0 siblings, 1 reply; 9+ messages in thread
From: Aniroop Mathur @ 2016-11-24 16:03 UTC (permalink / raw)
  To: dmitry.torokhov, linux-input, linux-kernel
  Cc: aniroop.mathur, s.samuel, r.mahale, Aniroop Mathur

msleep(1~20) may not do what the caller intends, and will often sleep longer.
(~20 ms actual sleep for any value given in the 1~20ms range)
This is not the desired behaviour for many cases like device resume time,
device suspend time, device enable time, etc.
Thus, change msleep to usleep_range for precise wakeups.

Signed-off-by: Aniroop Mathur <a.mathur@samsung.com>
---
 drivers/input/misc/bma150.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/input/misc/bma150.c b/drivers/input/misc/bma150.c
index 2124390..1fa8537 100644
--- a/drivers/input/misc/bma150.c
+++ b/drivers/input/misc/bma150.c
@@ -207,7 +207,7 @@ static int bma150_set_mode(struct bma150_data *bma150, u8 mode)
 		return error;
 
 	if (mode == BMA150_MODE_NORMAL)
-		msleep(2);
+		usleep_range(2000, 2100);
 
 	bma150->mode = mode;
 	return 0;
@@ -222,7 +222,7 @@ static int bma150_soft_reset(struct bma150_data *bma150)
 	if (error)
 		return error;
 
-	msleep(2);
+	usleep_range(2000, 2100);
 	return 0;
 }
 
-- 
2.6.2

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

* Re: [PATCH] Input: Change msleep to usleep_range for small msecs
  2016-11-24 16:03 [PATCH] Input: Change msleep to usleep_range for small msecs Aniroop Mathur
@ 2016-11-28 16:35 ` Aniroop Mathur
  2016-12-01  5:49   ` ZHANG Xu (BST/ESA3.1)
       [not found]   ` <CGME20161201054940epcas4p3ad9a27ce7fbfcd94ac71e13180b7fb66@epcas4p3.samsung.com>
  0 siblings, 2 replies; 9+ messages in thread
From: Aniroop Mathur @ 2016-11-28 16:35 UTC (permalink / raw)
  To: xu.zhang, Dmitry Torokhov, linux-input, linux-kernel
  Cc: Aniroop Mathur, s.samuel, r.mahale, Aniroop Mathur

Hello Mr. Albert Zhang,

I am Aniroop Mathur from Samsung R&D Institute, India.

I have submitted one patch as below for review to Linux Open Source.
The problem is that we do not have the hardware available with us to
test it and we would like to test it before actually applying it.
As you are the author of this driver, so I would like to request
you if you could help to test this patch or provide us the contact points
of individuals who could support to get this patch tested?

Thank you!

BR,
Aniroop Mathur


On Thu, Nov 24, 2016 at 9:33 PM, Aniroop Mathur <a.mathur@samsung.com> wrote:
> msleep(1~20) may not do what the caller intends, and will often sleep longer.
> (~20 ms actual sleep for any value given in the 1~20ms range)
> This is not the desired behaviour for many cases like device resume time,
> device suspend time, device enable time, etc.
> Thus, change msleep to usleep_range for precise wakeups.
>
> Signed-off-by: Aniroop Mathur <a.mathur@samsung.com>
> ---
>  drivers/input/misc/bma150.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/input/misc/bma150.c b/drivers/input/misc/bma150.c
> index 2124390..1fa8537 100644
> --- a/drivers/input/misc/bma150.c
> +++ b/drivers/input/misc/bma150.c
> @@ -207,7 +207,7 @@ static int bma150_set_mode(struct bma150_data *bma150, u8 mode)
>                 return error;
>
>         if (mode == BMA150_MODE_NORMAL)
> -               msleep(2);
> +               usleep_range(2000, 2100);
>
>         bma150->mode = mode;
>         return 0;
> @@ -222,7 +222,7 @@ static int bma150_soft_reset(struct bma150_data *bma150)
>         if (error)
>                 return error;
>
> -       msleep(2);
> +       usleep_range(2000, 2100);
>         return 0;
>  }
>
> --
> 2.6.2
>

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

* RE: [PATCH] Input: Change msleep to usleep_range for small msecs
  2016-11-28 16:35 ` Aniroop Mathur
@ 2016-12-01  5:49   ` ZHANG Xu (BST/ESA3.1)
       [not found]   ` <CGME20161201054940epcas4p3ad9a27ce7fbfcd94ac71e13180b7fb66@epcas4p3.samsung.com>
  1 sibling, 0 replies; 9+ messages in thread
From: ZHANG Xu (BST/ESA3.1) @ 2016-12-01  5:49 UTC (permalink / raw)
  To: Aniroop Mathur, Dmitry Torokhov, linux-input, linux-kernel
  Cc: Aniroop Mathur, s.samuel, r.mahale

Hello Aniroop Mathur

Thank you for your mail.

We have used the  usleep_range() function in our new product's driver and the verification result  is working.
Your patch for bma150 is definitely working for sure. 

Just one question need your answer.
To replace the msleep(2),   is  usleep_range(2000, 2100)  better  than usleep_range(2000, 2000)  ?

Best regards

Albert (Xu) ZHANG
BST/ESA3.1  




-----Original Message-----
From: mathur.aniroop@gmail.com [mailto:mathur.aniroop@gmail.com] On Behalf Of Aniroop Mathur
Sent: Tuesday, November 29, 2016 12:36 AM
To: ZHANG Xu (BST/ESA3.1) <Xu.Zhang@cn.bosch.com>; Dmitry Torokhov <dmitry.torokhov@gmail.com>; linux-input@vger.kernel.org; linux-kernel@vger.kernel.org
Cc: Aniroop Mathur <aniroop.mathur@gmail.com>; s.samuel@samsung.com; r.mahale@samsung.com; Aniroop Mathur <a.mathur@samsung.com>
Subject: Re: [PATCH] Input: Change msleep to usleep_range for small msecs

Hello Mr. Albert Zhang,

I am Aniroop Mathur from Samsung R&D Institute, India.

I have submitted one patch as below for review to Linux Open Source.
The problem is that we do not have the hardware available with us to
test it and we would like to test it before actually applying it.
As you are the author of this driver, so I would like to request
you if you could help to test this patch or provide us the contact points
of individuals who could support to get this patch tested?

Thank you!

BR,
Aniroop Mathur


On Thu, Nov 24, 2016 at 9:33 PM, Aniroop Mathur <a.mathur@samsung.com> wrote:
> msleep(1~20) may not do what the caller intends, and will often sleep longer.
> (~20 ms actual sleep for any value given in the 1~20ms range)
> This is not the desired behaviour for many cases like device resume time,
> device suspend time, device enable time, etc.
> Thus, change msleep to usleep_range for precise wakeups.
>
> Signed-off-by: Aniroop Mathur <a.mathur@samsung.com>
> ---
>  drivers/input/misc/bma150.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/input/misc/bma150.c b/drivers/input/misc/bma150.c
> index 2124390..1fa8537 100644
> --- a/drivers/input/misc/bma150.c
> +++ b/drivers/input/misc/bma150.c
> @@ -207,7 +207,7 @@ static int bma150_set_mode(struct bma150_data *bma150, u8 mode)
>                 return error;
>
>         if (mode == BMA150_MODE_NORMAL)
> -               msleep(2);
> +               usleep_range(2000, 2100);
>
>         bma150->mode = mode;
>         return 0;
> @@ -222,7 +222,7 @@ static int bma150_soft_reset(struct bma150_data *bma150)
>         if (error)
>                 return error;
>
> -       msleep(2);
> +       usleep_range(2000, 2100);
>         return 0;
>  }
>
> --
> 2.6.2
>

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

* RE: RE: [PATCH] Input: Change msleep to usleep_range for small msecs
       [not found]   ` <CGME20161201054940epcas4p3ad9a27ce7fbfcd94ac71e13180b7fb66@epcas4p3.samsung.com>
@ 2016-12-01 10:34     ` Aniroop Mathur
  2016-12-01 11:44       ` ZHANG Xu (BST/ESA3.1)
                         ` (2 more replies)
  0 siblings, 3 replies; 9+ messages in thread
From: Aniroop Mathur @ 2016-12-01 10:34 UTC (permalink / raw)
  To: ZHANG Xu (BST, Dmitry Torokhov, linux-input, linux-kernel
  Cc: Aniroop Mathur, SAMUEL SEQUEIRA, Rahul Mahale

[-- Attachment #1: Type: text/plain, Size: 3873 bytes --]

Dear Mr. Albert Zhang,

Thank you for your confirmation!

Yes, I think usleep_range(2000, 2100) is better than usleep_range(2000, 2000)
because delta time will allow the kernel to batch the processes who need to
wake up around same time and generate single interrupt to wake up all of them.
So this would be beneficial from power saving point of view.


--
Best Regards,
Aniroop Mathur

 
 
--------- Original Message ---------
Sender : ZHANG Xu (BST/ESA3.1) <Xu.Zhang@cn.bosch.com>
Date   : 2016-12-01 11:19 (GMT+5:30)
Title  : RE: [PATCH] Input: Change msleep to usleep_range for small msecs
 
Hello Aniroop Mathur
 
Thank you for your mail.
 
We have used the  usleep_range() function in our new product's driver and the verification result  is working.
Your patch for bma150 is definitely working for sure. 
 
Just one question need your answer.
To replace the msleep(2),   is  usleep_range(2000, 2100)  better  than usleep_range(2000, 2000)  ?
 
Best regards
 
Albert (Xu) ZHANG
BST/ESA3.1  
 
 
 
 
-----Original Message-----
From: mathur.aniroop@gmail.com [mailto:mathur.aniroop@gmail.com] On Behalf Of Aniroop Mathur
Sent: Tuesday, November 29, 2016 12:36 AM
To: ZHANG Xu (BST/ESA3.1) <Xu.Zhang@cn.bosch.com>; Dmitry Torokhov <dmitry.torokhov@gmail.com>; linux-input@vger.kernel.org; linux-kernel@vger.kernel.org
Cc: Aniroop Mathur <aniroop.mathur@gmail.com>; s.samuel@samsung.com; r.mahale@samsung.com; Aniroop Mathur <a.mathur@samsung.com>
Subject: Re: [PATCH] Input: Change msleep to usleep_range for small msecs
 
Hello Mr. Albert Zhang,
 
I am Aniroop Mathur from Samsung R&D Institute, India.
 
I have submitted one patch as below for review to Linux Open Source.
The problem is that we do not have the hardware available with us to
test it and we would like to test it before actually applying it.
As you are the author of this driver, so I would like to request
you if you could help to test this patch or provide us the contact points
of individuals who could support to get this patch tested?
 
Thank you!
 
BR,
Aniroop Mathur
 
 
On Thu, Nov 24, 2016 at 9:33 PM, Aniroop Mathur <a.mathur@samsung.com> wrote:
> msleep(1~20) may not do what the caller intends, and will often sleep longer.
> (~20 ms actual sleep for any value given in the 1~20ms range)
> This is not the desired behaviour for many cases like device resume time,
> device suspend time, device enable time, etc.
> Thus, change msleep to usleep_range for precise wakeups.
>
> Signed-off-by: Aniroop Mathur <a.mathur@samsung.com>
> ---
>  drivers/input/misc/bma150.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/input/misc/bma150.c b/drivers/input/misc/bma150.c
> index 2124390..1fa8537 100644
> --- a/drivers/input/misc/bma150.c
> +++ b/drivers/input/misc/bma150.c
> @@ -207,7 +207,7 @@ static int bma150_set_mode(struct bma150_data *bma150, u8 mode)
>                 return error;
>
>         if (mode == BMA150_MODE_NORMAL)
> -               msleep(2);
> +               usleep_range(2000, 2100);
>
>         bma150->mode = mode;
>         return 0;
> @@ -222,7 +222,7 @@ static int bma150_soft_reset(struct bma150_data *bma150)
>         if (error)
>                 return error;
>
> -       msleep(2);
> +       usleep_range(2000, 2100);
>         return 0;
>  }
>
> --
> 2.6.2
>
 

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

* RE: RE: [PATCH] Input: Change msleep to usleep_range for small msecs
  2016-12-01 10:34     ` Aniroop Mathur
@ 2016-12-01 11:44       ` ZHANG Xu (BST/ESA3.1)
  2016-12-01 15:50       ` RE: RE: [Please Apply][PATCH] Input: misc: bma150: " Aniroop Mathur
  2016-12-23  5:07       ` RE: [PATCH] Input: " ZHANG Xu (BST/ESA3.1)
  2 siblings, 0 replies; 9+ messages in thread
From: ZHANG Xu (BST/ESA3.1) @ 2016-12-01 11:44 UTC (permalink / raw)
  To: a.mathur, Dmitry Torokhov, linux-input, linux-kernel
  Cc: Aniroop Mathur, SAMUEL SEQUEIRA, Rahul Mahale

Dear Aniroop Mathur

Got your point. 
Thank you for your explanation!

Best regards

Albert (Xu) ZHANG
BST/ESA3.1  



-----Original Message-----
From: Aniroop Mathur [mailto:a.mathur@samsung.com] 
Sent: Thursday, December 01, 2016 6:34 PM
To: ZHANG Xu (BST/ESA3.1) <Xu.Zhang@cn.bosch.com>; Dmitry Torokhov <dmitry.torokhov@gmail.com>; linux-input@vger.kernel.org; linux-kernel@vger.kernel.org
Cc: Aniroop Mathur <aniroop.mathur@gmail.com>; SAMUEL SEQUEIRA <s.samuel@samsung.com>; Rahul Mahale <r.mahale@samsung.com>
Subject: RE: RE: [PATCH] Input: Change msleep to usleep_range for small msecs

Dear Mr. Albert Zhang,

Thank you for your confirmation!

Yes, I think usleep_range(2000, 2100) is better than usleep_range(2000, 2000)
because delta time will allow the kernel to batch the processes who need to
wake up around same time and generate single interrupt to wake up all of them.
So this would be beneficial from power saving point of view.


--
Best Regards,
Aniroop Mathur

 
 
--------- Original Message ---------
Sender : ZHANG Xu (BST/ESA3.1) <Xu.Zhang@cn.bosch.com>
Date   : 2016-12-01 11:19 (GMT+5:30)
Title  : RE: [PATCH] Input: Change msleep to usleep_range for small msecs
 
Hello Aniroop Mathur
 
Thank you for your mail.
 
We have used the  usleep_range() function in our new product's driver and the verification result  is working.
Your patch for bma150 is definitely working for sure. 
 
Just one question need your answer.
To replace the msleep(2),   is  usleep_range(2000, 2100)  better  than usleep_range(2000, 2000)  ?
 
Best regards
 
Albert (Xu) ZHANG
BST/ESA3.1  
 
 
 
 
-----Original Message-----
From: mathur.aniroop@gmail.com [mailto:mathur.aniroop@gmail.com] On Behalf Of Aniroop Mathur
Sent: Tuesday, November 29, 2016 12:36 AM
To: ZHANG Xu (BST/ESA3.1) <Xu.Zhang@cn.bosch.com>; Dmitry Torokhov <dmitry.torokhov@gmail.com>; linux-input@vger.kernel.org; linux-kernel@vger.kernel.org
Cc: Aniroop Mathur <aniroop.mathur@gmail.com>; s.samuel@samsung.com; r.mahale@samsung.com; Aniroop Mathur <a.mathur@samsung.com>
Subject: Re: [PATCH] Input: Change msleep to usleep_range for small msecs
 
Hello Mr. Albert Zhang,
 
I am Aniroop Mathur from Samsung R&D Institute, India.
 
I have submitted one patch as below for review to Linux Open Source.
The problem is that we do not have the hardware available with us to
test it and we would like to test it before actually applying it.
As you are the author of this driver, so I would like to request
you if you could help to test this patch or provide us the contact points
of individuals who could support to get this patch tested?
 
Thank you!
 
BR,
Aniroop Mathur
 
 
On Thu, Nov 24, 2016 at 9:33 PM, Aniroop Mathur <a.mathur@samsung.com> wrote:
> msleep(1~20) may not do what the caller intends, and will often sleep longer.
> (~20 ms actual sleep for any value given in the 1~20ms range)
> This is not the desired behaviour for many cases like device resume time,
> device suspend time, device enable time, etc.
> Thus, change msleep to usleep_range for precise wakeups.
>
> Signed-off-by: Aniroop Mathur <a.mathur@samsung.com>
> ---
>  drivers/input/misc/bma150.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/input/misc/bma150.c b/drivers/input/misc/bma150.c
> index 2124390..1fa8537 100644
> --- a/drivers/input/misc/bma150.c
> +++ b/drivers/input/misc/bma150.c
> @@ -207,7 +207,7 @@ static int bma150_set_mode(struct bma150_data *bma150, u8 mode)
>                 return error;
>
>         if (mode == BMA150_MODE_NORMAL)
> -               msleep(2);
> +               usleep_range(2000, 2100);
>
>         bma150->mode = mode;
>         return 0;
> @@ -222,7 +222,7 @@ static int bma150_soft_reset(struct bma150_data *bma150)
>         if (error)
>                 return error;
>
> -       msleep(2);
> +       usleep_range(2000, 2100);
>         return 0;
>  }
>
> --
> 2.6.2
>
 

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

* RE: RE: RE: [Please Apply][PATCH] Input: misc: bma150: Change msleep to usleep_range for small msecs
  2016-12-01 10:34     ` Aniroop Mathur
  2016-12-01 11:44       ` ZHANG Xu (BST/ESA3.1)
@ 2016-12-01 15:50       ` Aniroop Mathur
  2016-12-23  5:07       ` RE: [PATCH] Input: " ZHANG Xu (BST/ESA3.1)
  2 siblings, 0 replies; 9+ messages in thread
From: Aniroop Mathur @ 2016-12-01 15:50 UTC (permalink / raw)
  To: Dmitry Torokhov
  Cc: ZHANG Xu (BST, linux-input, linux-kernel, Aniroop Mathur,
	SAMUEL SEQUEIRA, Rahul Mahale

[-- Attachment #1: Type: text/plain, Size: 5177 bytes --]

Dear Mr. Torokhov,

As this patch is now verified, would you please apply it?

Thank you!

--
Best Regards,
Aniroop Mathur
Lead Engineer | System 1 - Sensor R&D
Samsung Research Institute India - Noida
Tel: 0120-6711111    Ext: 4018
Mob: +91 9971865523
Email: a.mathur@samsung.com

 
 
--------- Original Message ---------
Sender : ZHANG Xu (BST/ESA3.1) <Xu.Zhang@cn.bosch.com>
Date   : 2016-12-01 17:14 (GMT+5:30)
Title  : RE: RE: [PATCH] Input: Change msleep to usleep_range for small msecs
 
Dear Aniroop Mathur
 
Got your point. 
Thank you for your explanation!
 
Best regards
 
Albert (Xu) ZHANG
BST/ESA3.1  
 
 
 
-----Original Message-----
From: Aniroop Mathur [mailto:a.mathur@samsung.com] 
Sent: Thursday, December 01, 2016 6:34 PM
To: ZHANG Xu (BST/ESA3.1) <Xu.Zhang@cn.bosch.com>; Dmitry Torokhov <dmitry.torokhov@gmail.com>; linux-input@vger.kernel.org; linux-kernel@vger.kernel.org
Cc: Aniroop Mathur <aniroop.mathur@gmail.com>; SAMUEL SEQUEIRA <s.samuel@samsung.com>; Rahul Mahale <r.mahale@samsung.com>
Subject: RE: RE: [PATCH] Input: Change msleep to usleep_range for small msecs
 
Dear Mr. Albert Zhang,
 
Thank you for your confirmation!
 
Yes, I think usleep_range(2000, 2100) is better than usleep_range(2000, 2000)
because delta time will allow the kernel to batch the processes who need to
wake up around same time and generate single interrupt to wake up all of them.
So this would be beneficial from power saving point of view.
 
 
--
Best Regards,
Aniroop Mathur
 
 
 
--------- Original Message ---------
Sender : ZHANG Xu (BST/ESA3.1) <Xu.Zhang@cn.bosch.com>
Date   : 2016-12-01 11:19 (GMT+5:30)
Title  : RE: [PATCH] Input: Change msleep to usleep_range for small msecs
 
Hello Aniroop Mathur
 
Thank you for your mail.
 
We have used the  usleep_range() function in our new product's driver and the verification result  is working.
Your patch for bma150 is definitely working for sure. 
 
Just one question need your answer.
To replace the msleep(2),   is  usleep_range(2000, 2100)  better  than usleep_range(2000, 2000)  ?
 
Best regards
 
Albert (Xu) ZHANG
BST/ESA3.1  
 
 
 
 
-----Original Message-----
From: mathur.aniroop@gmail.com [mailto:mathur.aniroop@gmail.com] On Behalf Of Aniroop Mathur
Sent: Tuesday, November 29, 2016 12:36 AM
To: ZHANG Xu (BST/ESA3.1) <Xu.Zhang@cn.bosch.com>; Dmitry Torokhov <dmitry.torokhov@gmail.com>; linux-input@vger.kernel.org; linux-kernel@vger.kernel.org
Cc: Aniroop Mathur <aniroop.mathur@gmail.com>; s.samuel@samsung.com; r.mahale@samsung.com; Aniroop Mathur <a.mathur@samsung.com>
Subject: Re: [PATCH] Input: Change msleep to usleep_range for small msecs
 
Hello Mr. Albert Zhang,
 
I am Aniroop Mathur from Samsung R&D Institute, India.
 
I have submitted one patch as below for review to Linux Open Source.
The problem is that we do not have the hardware available with us to
test it and we would like to test it before actually applying it.
As you are the author of this driver, so I would like to request
you if you could help to test this patch or provide us the contact points
of individuals who could support to get this patch tested?
 
Thank you!
 
BR,
Aniroop Mathur
 
 
On Thu, Nov 24, 2016 at 9:33 PM, Aniroop Mathur <a.mathur@samsung.com> wrote:
> msleep(1~20) may not do what the caller intends, and will often sleep longer.
> (~20 ms actual sleep for any value given in the 1~20ms range)
> This is not the desired behaviour for many cases like device resume time,
> device suspend time, device enable time, etc.
> Thus, change msleep to usleep_range for precise wakeups.
>
> Signed-off-by: Aniroop Mathur <a.mathur@samsung.com>
> ---
>  drivers/input/misc/bma150.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/input/misc/bma150.c b/drivers/input/misc/bma150.c
> index 2124390..1fa8537 100644
> --- a/drivers/input/misc/bma150.c
> +++ b/drivers/input/misc/bma150.c
> @@ -207,7 +207,7 @@ static int bma150_set_mode(struct bma150_data *bma150, u8 mode)
>                 return error;
>
>         if (mode == BMA150_MODE_NORMAL)
> -               msleep(2);
> +               usleep_range(2000, 2100);
>
>         bma150->mode = mode;
>         return 0;
> @@ -222,7 +222,7 @@ static int bma150_soft_reset(struct bma150_data *bma150)
>         if (error)
>                 return error;
>
> -       msleep(2);
> +       usleep_range(2000, 2100);
>         return 0;
>  }
>
> --
> 2.6.2
>
 
 

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

* RE: RE: [PATCH] Input: Change msleep to usleep_range for small msecs
  2016-12-01 10:34     ` Aniroop Mathur
  2016-12-01 11:44       ` ZHANG Xu (BST/ESA3.1)
  2016-12-01 15:50       ` RE: RE: [Please Apply][PATCH] Input: misc: bma150: " Aniroop Mathur
@ 2016-12-23  5:07       ` ZHANG Xu (BST/ESA3.1)
  2 siblings, 0 replies; 9+ messages in thread
From: ZHANG Xu (BST/ESA3.1) @ 2016-12-23  5:07 UTC (permalink / raw)
  To: a.mathur, Dmitry Torokhov, linux-input, linux-kernel
  Cc: Aniroop Mathur, SAMUEL SEQUEIRA, Rahul Mahale

Dear Aniroop Mathur

Please see the acknowledgement below.

Best regards

Albert (Xu) ZHANG
BST/ESA3.1  

Tel. +86(21)2218-1283 



-----Original Message-----
From: Aniroop Mathur [mailto:a.mathur@samsung.com] 
Sent: Thursday, December 01, 2016 6:34 PM
To: ZHANG Xu (BST/ESA3.1) <Xu.Zhang@cn.bosch.com>; Dmitry Torokhov <dmitry.torokhov@gmail.com>; linux-input@vger.kernel.org; linux-kernel@vger.kernel.org
Cc: Aniroop Mathur <aniroop.mathur@gmail.com>; SAMUEL SEQUEIRA <s.samuel@samsung.com>; Rahul Mahale <r.mahale@samsung.com>
Subject: RE: RE: [PATCH] Input: Change msleep to usleep_range for small msecs

Dear Mr. Albert Zhang,

Thank you for your confirmation!

Yes, I think usleep_range(2000, 2100) is better than usleep_range(2000, 2000)
because delta time will allow the kernel to batch the processes who need to
wake up around same time and generate single interrupt to wake up all of them.
So this would be beneficial from power saving point of view.


--
Best Regards,
Aniroop Mathur

 
 
--------- Original Message ---------
Sender : ZHANG Xu (BST/ESA3.1) <Xu.Zhang@cn.bosch.com>
Date   : 2016-12-01 11:19 (GMT+5:30)
Title  : RE: [PATCH] Input: Change msleep to usleep_range for small msecs
 
Hello Aniroop Mathur
 
Thank you for your mail.
 
We have used the  usleep_range() function in our new product's driver and the verification result  is working.
Your patch for bma150 is definitely working for sure. 
 
Just one question need your answer.
To replace the msleep(2),   is  usleep_range(2000, 2100)  better  than usleep_range(2000, 2000)  ?
 
Best regards
 
Albert (Xu) ZHANG
BST/ESA3.1  
 
 
 
 
-----Original Message-----
From: mathur.aniroop@gmail.com [mailto:mathur.aniroop@gmail.com] On Behalf Of Aniroop Mathur
Sent: Tuesday, November 29, 2016 12:36 AM
To: ZHANG Xu (BST/ESA3.1) <Xu.Zhang@cn.bosch.com>; Dmitry Torokhov <dmitry.torokhov@gmail.com>; linux-input@vger.kernel.org; linux-kernel@vger.kernel.org
Cc: Aniroop Mathur <aniroop.mathur@gmail.com>; s.samuel@samsung.com; r.mahale@samsung.com; Aniroop Mathur <a.mathur@samsung.com>
Subject: Re: [PATCH] Input: Change msleep to usleep_range for small msecs
 
Hello Mr. Albert Zhang,
 
I am Aniroop Mathur from Samsung R&D Institute, India.
 
I have submitted one patch as below for review to Linux Open Source.
The problem is that we do not have the hardware available with us to
test it and we would like to test it before actually applying it.
As you are the author of this driver, so I would like to request
you if you could help to test this patch or provide us the contact points
of individuals who could support to get this patch tested?
 
Thank you!
 
BR,
Aniroop Mathur
 
 
On Thu, Nov 24, 2016 at 9:33 PM, Aniroop Mathur <a.mathur@samsung.com> wrote:
> msleep(1~20) may not do what the caller intends, and will often sleep longer.
> (~20 ms actual sleep for any value given in the 1~20ms range)
> This is not the desired behaviour for many cases like device resume time,
> device suspend time, device enable time, etc.
> Thus, change msleep to usleep_range for precise wakeups.
>
> Signed-off-by: Aniroop Mathur <a.mathur@samsung.com>
Acked by: Albert Zhang <xu.zhang@bosch-sensortec.com>
> ---
>  drivers/input/misc/bma150.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/input/misc/bma150.c b/drivers/input/misc/bma150.c
> index 2124390..1fa8537 100644
> --- a/drivers/input/misc/bma150.c
> +++ b/drivers/input/misc/bma150.c
> @@ -207,7 +207,7 @@ static int bma150_set_mode(struct bma150_data *bma150, u8 mode)
>                 return error;
>
>         if (mode == BMA150_MODE_NORMAL)
> -               msleep(2);
> +               usleep_range(2000, 2100);
>
>         bma150->mode = mode;
>         return 0;
> @@ -222,7 +222,7 @@ static int bma150_soft_reset(struct bma150_data *bma150)
>         if (error)
>                 return error;
>
> -       msleep(2);
> +       usleep_range(2000, 2100);
>         return 0;
>  }
>
> --
> 2.6.2
>
 

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

* Re: [PATCH] Input: Change msleep to usleep_range for small msecs
  2016-11-24 19:24 Aniroop Mathur
@ 2016-11-28  4:48 ` Dmitry Torokhov
  0 siblings, 0 replies; 9+ messages in thread
From: Dmitry Torokhov @ 2016-11-28  4:48 UTC (permalink / raw)
  To: Aniroop Mathur
  Cc: linux-input, linux-kernel, aniroop.mathur, s.samuel, r.mahale

Hi Aniroop,

On Fri, Nov 25, 2016 at 12:54:39AM +0530, Aniroop Mathur wrote:
> msleep(1~20) may not do what the caller intends, and will often sleep longer.
> (~20 ms actual sleep for any value given in the 1~20ms range)
> This is not the desired behaviour for many cases like device resume time,
> device suspend time, device enable time, data reading time, etc.
> Thus, change msleep to usleep_range for precise wakeups.
> 
> Signed-off-by: Aniroop Mathur <a.mathur@samsung.com>
> ---
>  drivers/input/gameport/ns558.c              |  4 ++--
>  drivers/input/joystick/adi.c                |  4 ++--
>  drivers/input/joystick/analog.c             | 12 ++++++------
>  drivers/input/joystick/gf2k.c               |  8 ++++----
>  drivers/input/joystick/sidewinder.c         | 24 ++++++++++++------------
>  drivers/input/keyboard/lm8323.c             |  2 +-
>  drivers/input/mouse/navpoint.c              |  2 +-
>  drivers/input/mouse/pxa930_trkball.c        |  2 +-
>  drivers/input/mouse/synaptics_i2c.c         |  6 +++---
>  drivers/input/touchscreen/ads7846.c         |  4 ++--
>  drivers/input/touchscreen/edt-ft5x06.c      |  4 ++--
>  drivers/input/touchscreen/w90p910_ts.c      |  4 ++--
>  drivers/input/touchscreen/zylonite-wm97xx.c |  4 ++--

This does make sense and probably even needed for the joystick drivers,
but I would like to make sure this is tested. Can you please split the
patch by driver and try to find people with the hardware to test this?

Thanks!

>  13 files changed, 40 insertions(+), 40 deletions(-)
> 
> diff --git a/drivers/input/gameport/ns558.c b/drivers/input/gameport/ns558.c
> index 7c21784..046cb28 100644
> --- a/drivers/input/gameport/ns558.c
> +++ b/drivers/input/gameport/ns558.c
> @@ -98,7 +98,7 @@ static int ns558_isa_probe(int io)
>  		release_region(io, 1);
>  		return -ENODEV;
>  	}
> -	msleep(3);
> +	usleep_range(3000, 3100);
>  /*
>   * After some time (4ms) the axes shouldn't change anymore.
>   */
> @@ -124,7 +124,7 @@ static int ns558_isa_probe(int io)
>  		outb(0xff, io & (-1 << i));
>  		for (j = b = 0; j < 1000; j++)
>  			if (inb(io & (-1 << i)) != inb((io & (-1 << i)) + (1 << i) - 1)) b++;
> -		msleep(3);
> +		usleep_range(3000, 3100);
>  
>  		if (b > 300) {				/* We allow 30% difference */
>  			release_region(io & (-1 << i), (1 << i));
> diff --git a/drivers/input/joystick/adi.c b/drivers/input/joystick/adi.c
> index d09cefa..f1955bf 100644
> --- a/drivers/input/joystick/adi.c
> +++ b/drivers/input/joystick/adi.c
> @@ -48,7 +48,7 @@ MODULE_LICENSE("GPL");
>  #define ADI_MAX_START		200	/* Trigger to packet timeout [200us] */
>  #define ADI_MAX_STROBE		40	/* Single bit timeout [40us] */
>  #define ADI_INIT_DELAY		10	/* Delay after init packet [10ms] */
> -#define ADI_DATA_DELAY		4	/* Delay after data packet [4ms] */
> +#define ADI_DATA_DELAY		4000	/* Delay after data packet [4000us] */
>  
>  #define ADI_MAX_LENGTH		256
>  #define ADI_MIN_LENGTH		8
> @@ -514,7 +514,7 @@ static int adi_connect(struct gameport *gameport, struct gameport_driver *drv)
>  
>  	msleep(ADI_INIT_DELAY);
>  	if (adi_read(port)) {
> -		msleep(ADI_DATA_DELAY);
> +		usleep_range(ADI_DATA_DELAY, ADI_DATA_DELAY + 100);
>  		adi_read(port);
>  	}
>  
> diff --git a/drivers/input/joystick/analog.c b/drivers/input/joystick/analog.c
> index 3d8ff09..2891704 100644
> --- a/drivers/input/joystick/analog.c
> +++ b/drivers/input/joystick/analog.c
> @@ -88,7 +88,7 @@ MODULE_PARM_DESC(map, "Describes analog joysticks type/capabilities");
>  #define ANALOG_EXTENSIONS	0x7ff00
>  #define ANALOG_GAMEPAD		0x80000
>  
> -#define ANALOG_MAX_TIME		3	/* 3 ms */
> +#define ANALOG_MAX_TIME		3000	/* 3000 us */
>  #define ANALOG_LOOP_TIME	2000	/* 2 * loop */
>  #define ANALOG_SAITEK_DELAY	200	/* 200 us */
>  #define ANALOG_SAITEK_TIME	2000	/* 2000 us */
> @@ -257,7 +257,7 @@ static int analog_cooked_read(struct analog_port *port)
>  	int i, j;
>  
>  	loopout = (ANALOG_LOOP_TIME * port->loop) / 1000;
> -	timeout = ANALOG_MAX_TIME * port->speed;
> +	timeout = (ANALOG_MAX_TIME / 1000) * port->speed;
>  
>  	local_irq_save(flags);
>  	gameport_trigger(gameport);
> @@ -625,20 +625,20 @@ static int analog_init_port(struct gameport *gameport, struct gameport_driver *d
>  
>  		gameport_trigger(gameport);
>  		t = gameport_read(gameport);
> -		msleep(ANALOG_MAX_TIME);
> +		usleep_range(ANALOG_MAX_TIME, ANALOG_MAX_TIME + 100);
>  		port->mask = (gameport_read(gameport) ^ t) & t & 0xf;
>  		port->fuzz = (port->speed * ANALOG_FUZZ_MAGIC) / port->loop / 1000 + ANALOG_FUZZ_BITS;
>  
>  		for (i = 0; i < ANALOG_INIT_RETRIES; i++) {
>  			if (!analog_cooked_read(port))
>  				break;
> -			msleep(ANALOG_MAX_TIME);
> +			usleep_range(ANALOG_MAX_TIME, ANALOG_MAX_TIME + 100);
>  		}
>  
>  		u = v = 0;
>  
> -		msleep(ANALOG_MAX_TIME);
> -		t = gameport_time(gameport, ANALOG_MAX_TIME * 1000);
> +		usleep_range(ANALOG_MAX_TIME, ANALOG_MAX_TIME + 100);
> +		t = gameport_time(gameport, ANALOG_MAX_TIME);
>  		gameport_trigger(gameport);
>  		while ((gameport_read(port->gameport) & port->mask) && (u < t))
>  			u++;
> diff --git a/drivers/input/joystick/gf2k.c b/drivers/input/joystick/gf2k.c
> index 0f519db..e9d5095 100644
> --- a/drivers/input/joystick/gf2k.c
> +++ b/drivers/input/joystick/gf2k.c
> @@ -42,7 +42,7 @@ MODULE_LICENSE("GPL");
>  
>  #define GF2K_START		400	/* The time we wait for the first bit [400 us] */
>  #define GF2K_STROBE		40	/* The time we wait for the first bit [40 us] */
> -#define GF2K_TIMEOUT		4	/* Wait for everything to settle [4 ms] */
> +#define GF2K_TIMEOUT		4000	/* Wait for everything to settle [4000 us] */
>  #define GF2K_LENGTH		80	/* Max number of triplets in a packet */
>  
>  /*
> @@ -138,7 +138,7 @@ static void gf2k_trigger_seq(struct gameport *gameport, short *seq)
>  	i = 0;
>          do {
>  		gameport_trigger(gameport);
> -		t = gameport_time(gameport, GF2K_TIMEOUT * 1000);
> +		t = gameport_time(gameport, GF2K_TIMEOUT);
>  		while ((gameport_read(gameport) & 1) && t) t--;
>                  udelay(seq[i]);
>          } while (seq[++i]);
> @@ -259,11 +259,11 @@ static int gf2k_connect(struct gameport *gameport, struct gameport_driver *drv)
>  
>  	gf2k_trigger_seq(gameport, gf2k_seq_reset);
>  
> -	msleep(GF2K_TIMEOUT);
> +	usleep_range(GF2K_TIMEOUT, GF2K_TIMEOUT + 100);
>  
>  	gf2k_trigger_seq(gameport, gf2k_seq_digital);
>  
> -	msleep(GF2K_TIMEOUT);
> +	usleep_range(GF2K_TIMEOUT, GF2K_TIMEOUT + 100);
>  
>  	if (gf2k_read_packet(gameport, GF2K_LENGTH, data) < 12) {
>  		err = -ENODEV;
> diff --git a/drivers/input/joystick/sidewinder.c b/drivers/input/joystick/sidewinder.c
> index 4a95b22..e5a1292 100644
> --- a/drivers/input/joystick/sidewinder.c
> +++ b/drivers/input/joystick/sidewinder.c
> @@ -50,7 +50,7 @@ MODULE_LICENSE("GPL");
>  
>  #define SW_START	600	/* The time we wait for the first bit [600 us] */
>  #define SW_STROBE	60	/* Max time per bit [60 us] */
> -#define SW_TIMEOUT	6	/* Wait for everything to settle [6 ms] */
> +#define SW_TIMEOUT	6000	/* Wait for everything to settle [6000 us] */
>  #define SW_KICK		45	/* Wait after A0 fall till kick [45 us] */
>  #define SW_END		8	/* Number of bits before end of packet to kick */
>  #define SW_FAIL		16	/* Number of packet read errors to fail and reinitialize */
> @@ -139,7 +139,7 @@ static int sw_read_packet(struct gameport *gameport, unsigned char *buf, int len
>  	unsigned char pending, u, v;
>  
>  	i = -id;						/* Don't care about data, only want ID */
> -	timeout = id ? gameport_time(gameport, SW_TIMEOUT * 1000) : 0; /* Set up global timeout for ID packet */
> +	timeout = id ? gameport_time(gameport, SW_TIMEOUT) : 0; /* Set up global timeout for ID packet */
>  	kick = id ? gameport_time(gameport, SW_KICK) : 0;	/* Set up kick timeout for ID packet */
>  	start = gameport_time(gameport, SW_START);
>  	strobe = gameport_time(gameport, SW_STROBE);
> @@ -248,7 +248,7 @@ static void sw_init_digital(struct gameport *gameport)
>  	i = 0;
>          do {
>                  gameport_trigger(gameport);			/* Trigger */
> -		t = gameport_time(gameport, SW_TIMEOUT * 1000);
> +		t = gameport_time(gameport, SW_TIMEOUT);
>  		while ((gameport_read(gameport) & 1) && t) t--;	/* Wait for axis to fall back to 0 */
>                  udelay(seq[i]);					/* Delay magic time */
>          } while (seq[++i]);
> @@ -483,13 +483,13 @@ static int sw_read(struct sw *sw)
>  		" - reinitializing joystick.\n", sw->gameport->phys);
>  
>  	if (!i && sw->type == SW_ID_3DP) {					/* 3D Pro can be in analog mode */
> -		mdelay(3 * SW_TIMEOUT);
> +		mdelay(3 * (SW_TIMEOUT / 1000));
>  		sw_init_digital(sw->gameport);
>  	}
>  
> -	mdelay(SW_TIMEOUT);
> +	mdelay(SW_TIMEOUT / 1000);
>  	i = sw_read_packet(sw->gameport, buf, SW_LENGTH, 0);			/* Read normal data packet */
> -	mdelay(SW_TIMEOUT);
> +	mdelay(SW_TIMEOUT / 1000);
>  	sw_read_packet(sw->gameport, buf, SW_LENGTH, i);			/* Read ID packet, this initializes the stick */
>  
>  	sw->fail = SW_FAIL;
> @@ -616,14 +616,14 @@ static int sw_connect(struct gameport *gameport, struct gameport_driver *drv)
>  		gameport->phys, gameport->io, gameport->speed);
>  
>  	i = sw_read_packet(gameport, buf, SW_LENGTH, 0);		/* Read normal packet */
> -	msleep(SW_TIMEOUT);
> +	usleep_range(SW_TIMEOUT, SW_TIMEOUT + 100);
>  	dbg("Init 1: Mode %d. Length %d.", m , i);
>  
>  	if (!i) {							/* No data. 3d Pro analog mode? */
>  		sw_init_digital(gameport);				/* Switch to digital */
> -		msleep(SW_TIMEOUT);
> +		usleep_range(SW_TIMEOUT, SW_TIMEOUT + 100);
>  		i = sw_read_packet(gameport, buf, SW_LENGTH, 0);	/* Retry reading packet */
> -		msleep(SW_TIMEOUT);
> +		usleep_range(SW_TIMEOUT, SW_TIMEOUT + 100);
>  		dbg("Init 1b: Length %d.", i);
>  		if (!i) {						/* No data -> FAIL */
>  			err = -ENODEV;
> @@ -636,7 +636,7 @@ static int sw_connect(struct gameport *gameport, struct gameport_driver *drv)
>  	dbg("Init 2: Mode %d. ID Length %d.", m, j);
>  
>  	if (j <= 0) {							/* Read ID failed. Happens in 1-bit mode on PP */
> -		msleep(SW_TIMEOUT);
> +		usleep_range(SW_TIMEOUT, SW_TIMEOUT + 100);
>  		i = sw_read_packet(gameport, buf, SW_LENGTH, 0);	/* Retry reading packet */
>  		m |= sw_guess_mode(buf, i);
>  		dbg("Init 2b: Mode %d. Length %d.", m, i);
> @@ -644,7 +644,7 @@ static int sw_connect(struct gameport *gameport, struct gameport_driver *drv)
>  			err = -ENODEV;
>  			goto fail2;
>  		}
> -		msleep(SW_TIMEOUT);
> +		usleep_range(SW_TIMEOUT, SW_TIMEOUT + 100);
>  		j = sw_read_packet(gameport, idbuf, SW_LENGTH, i);	/* Retry reading ID */
>  		dbg("Init 2c: ID Length %d.", j);
>  	}
> @@ -655,7 +655,7 @@ static int sw_connect(struct gameport *gameport, struct gameport_driver *drv)
>  
>  	do {
>  		k--;
> -		msleep(SW_TIMEOUT);
> +		usleep_range(SW_TIMEOUT, SW_TIMEOUT + 100);
>  		i = sw_read_packet(gameport, buf, SW_LENGTH, 0);	/* Read data packet */
>  		dbg("Init 3: Mode %d. Length %d. Last %d. Tries %d.", m, i, l, k);
>  
> diff --git a/drivers/input/keyboard/lm8323.c b/drivers/input/keyboard/lm8323.c
> index 21bea52..14679e9 100644
> --- a/drivers/input/keyboard/lm8323.c
> +++ b/drivers/input/keyboard/lm8323.c
> @@ -689,7 +689,7 @@ static int lm8323_probe(struct i2c_client *client,
>  			break;
>  		}
>  
> -		msleep(1);
> +		usleep_range(1000, 1100);
>  	}
>  
>  	lm8323_configure(lm);
> diff --git a/drivers/input/mouse/navpoint.c b/drivers/input/mouse/navpoint.c
> index d6e8f58..2ede00b 100644
> --- a/drivers/input/mouse/navpoint.c
> +++ b/drivers/input/mouse/navpoint.c
> @@ -166,7 +166,7 @@ static void navpoint_up(struct navpoint *navpoint)
>  	for (timeout = 100; timeout != 0; --timeout) {
>  		if (!(pxa_ssp_read_reg(ssp, SSSR) & SSSR_CSS))
>  			break;
> -		msleep(1);
> +		usleep_range(1000, 1100);
>  	}
>  
>  	if (timeout == 0)
> diff --git a/drivers/input/mouse/pxa930_trkball.c b/drivers/input/mouse/pxa930_trkball.c
> index 9b4d9a5..d8ac9f9 100644
> --- a/drivers/input/mouse/pxa930_trkball.c
> +++ b/drivers/input/mouse/pxa930_trkball.c
> @@ -85,7 +85,7 @@ static int write_tbcr(struct pxa930_trkball *trkball, int v)
>  	while (--i) {
>  		if (__raw_readl(trkball->mmio_base + TBCR) == v)
>  			break;
> -		msleep(1);
> +		usleep_range(1000, 1100);
>  	}
>  
>  	if (i == 0) {
> diff --git a/drivers/input/mouse/synaptics_i2c.c b/drivers/input/mouse/synaptics_i2c.c
> index aa7c5da..826ac65 100644
> --- a/drivers/input/mouse/synaptics_i2c.c
> +++ b/drivers/input/mouse/synaptics_i2c.c
> @@ -29,9 +29,9 @@
>   * after soft reset, we should wait for 1 ms
>   * before the device becomes operational
>   */
> -#define SOFT_RESET_DELAY_MS	3
> +#define SOFT_RESET_DELAY_US	3000
>  /* and after hard reset, we should wait for max 500ms */
> -#define HARD_RESET_DELAY_MS	500
> +#define HARD_RESET_DELAY_US	500000
>  
>  /* Registers by SMBus address */
>  #define PAGE_SEL_REG		0xff
> @@ -311,7 +311,7 @@ static int synaptics_i2c_reset_config(struct i2c_client *client)
>  	if (ret) {
>  		dev_err(&client->dev, "Unable to reset device\n");
>  	} else {
> -		msleep(SOFT_RESET_DELAY_MS);
> +		usleep_range(SOFT_RESET_DELAY_US, SOFT_RESET_DELAY_US + 100);
>  		ret = synaptics_i2c_config(client);
>  		if (ret)
>  			dev_err(&client->dev, "Unable to config device\n");
> diff --git a/drivers/input/touchscreen/ads7846.c b/drivers/input/touchscreen/ads7846.c
> index 1ce3ecb..b1a5a6c 100644
> --- a/drivers/input/touchscreen/ads7846.c
> +++ b/drivers/input/touchscreen/ads7846.c
> @@ -58,7 +58,7 @@
>   * files.
>   */
>  
> -#define TS_POLL_DELAY	1	/* ms delay before the first sample */
> +#define TS_POLL_DELAY	1000	/* us delay before the first sample */
>  #define TS_POLL_PERIOD	5	/* ms delay between samples */
>  
>  /* this driver doesn't aim at the peak continuous sample rate */
> @@ -857,7 +857,7 @@ static irqreturn_t ads7846_irq(int irq, void *handle)
>  	struct ads7846 *ts = handle;
>  
>  	/* Start with a small delay before checking pendown state */
> -	msleep(TS_POLL_DELAY);
> +	usleep_range(TS_POLL_DELAY, TS_POLL_DELAY + 100);
>  
>  	while (!ts->stopped && get_pendown_state(ts)) {
>  
> diff --git a/drivers/input/touchscreen/edt-ft5x06.c b/drivers/input/touchscreen/edt-ft5x06.c
> index 703e295..379dd31 100644
> --- a/drivers/input/touchscreen/edt-ft5x06.c
> +++ b/drivers/input/touchscreen/edt-ft5x06.c
> @@ -67,7 +67,7 @@
>  #define EDT_SWITCH_MODE_RETRIES		10
>  #define EDT_SWITCH_MODE_DELAY		5 /* msec */
>  #define EDT_RAW_DATA_RETRIES		100
> -#define EDT_RAW_DATA_DELAY		1 /* msec */
> +#define EDT_RAW_DATA_DELAY		1000 /* usec */
>  
>  enum edt_ver {
>  	M06,
> @@ -664,7 +664,7 @@ static ssize_t edt_ft5x06_debugfs_raw_data_read(struct file *file,
>  	}
>  
>  	do {
> -		msleep(EDT_RAW_DATA_DELAY);
> +		usleep_range(EDT_RAW_DATA_DELAY, EDT_RAW_DATA_DELAY + 100);
>  		val = edt_ft5x06_register_read(tsdata, 0x08);
>  		if (val < 1)
>  			break;
> diff --git a/drivers/input/touchscreen/w90p910_ts.c b/drivers/input/touchscreen/w90p910_ts.c
> index da6004e..3f14b5a 100644
> --- a/drivers/input/touchscreen/w90p910_ts.c
> +++ b/drivers/input/touchscreen/w90p910_ts.c
> @@ -171,9 +171,9 @@ static int w90p910_open(struct input_dev *dev)
>  	clk_enable(w90p910_ts->clk);
>  
>  	__raw_writel(ADC_RST1, w90p910_ts->ts_reg);
> -	msleep(1);
> +	usleep_range(1000, 1100);
>  	__raw_writel(ADC_RST0, w90p910_ts->ts_reg);
> -	msleep(1);
> +	usleep_range(1000, 1100);
>  
>  	/* set delay and screen type */
>  	val = __raw_readl(w90p910_ts->ts_reg + 0x04);
> diff --git a/drivers/input/touchscreen/zylonite-wm97xx.c b/drivers/input/touchscreen/zylonite-wm97xx.c
> index e2ccd68..cebd3a8 100644
> --- a/drivers/input/touchscreen/zylonite-wm97xx.c
> +++ b/drivers/input/touchscreen/zylonite-wm97xx.c
> @@ -81,7 +81,7 @@ static void wm97xx_acc_pen_up(struct wm97xx *wm)
>  {
>  	int i;
>  
> -	msleep(1);
> +	usleep_range(1000, 1100);
>  
>  	for (i = 0; i < 16; i++)
>  		MODR;
> @@ -98,7 +98,7 @@ static int wm97xx_acc_pen_down(struct wm97xx *wm)
>  	 * for samples.  The controller can't have a suitably low
>  	 * threshold set to use the notifications it gives.
>  	 */
> -	msleep(1);
> +	usleep_range(1000, 1100);
>  
>  	if (tries > 5) {
>  		tries = 0;
> -- 
> 2.6.2
> 

-- 
Dmitry

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

* [PATCH] Input: Change msleep to usleep_range for small msecs
@ 2016-11-24 19:24 Aniroop Mathur
  2016-11-28  4:48 ` Dmitry Torokhov
  0 siblings, 1 reply; 9+ messages in thread
From: Aniroop Mathur @ 2016-11-24 19:24 UTC (permalink / raw)
  To: dmitry.torokhov, linux-input, linux-kernel
  Cc: aniroop.mathur, s.samuel, r.mahale, Aniroop Mathur

msleep(1~20) may not do what the caller intends, and will often sleep longer.
(~20 ms actual sleep for any value given in the 1~20ms range)
This is not the desired behaviour for many cases like device resume time,
device suspend time, device enable time, data reading time, etc.
Thus, change msleep to usleep_range for precise wakeups.

Signed-off-by: Aniroop Mathur <a.mathur@samsung.com>
---
 drivers/input/gameport/ns558.c              |  4 ++--
 drivers/input/joystick/adi.c                |  4 ++--
 drivers/input/joystick/analog.c             | 12 ++++++------
 drivers/input/joystick/gf2k.c               |  8 ++++----
 drivers/input/joystick/sidewinder.c         | 24 ++++++++++++------------
 drivers/input/keyboard/lm8323.c             |  2 +-
 drivers/input/mouse/navpoint.c              |  2 +-
 drivers/input/mouse/pxa930_trkball.c        |  2 +-
 drivers/input/mouse/synaptics_i2c.c         |  6 +++---
 drivers/input/touchscreen/ads7846.c         |  4 ++--
 drivers/input/touchscreen/edt-ft5x06.c      |  4 ++--
 drivers/input/touchscreen/w90p910_ts.c      |  4 ++--
 drivers/input/touchscreen/zylonite-wm97xx.c |  4 ++--
 13 files changed, 40 insertions(+), 40 deletions(-)

diff --git a/drivers/input/gameport/ns558.c b/drivers/input/gameport/ns558.c
index 7c21784..046cb28 100644
--- a/drivers/input/gameport/ns558.c
+++ b/drivers/input/gameport/ns558.c
@@ -98,7 +98,7 @@ static int ns558_isa_probe(int io)
 		release_region(io, 1);
 		return -ENODEV;
 	}
-	msleep(3);
+	usleep_range(3000, 3100);
 /*
  * After some time (4ms) the axes shouldn't change anymore.
  */
@@ -124,7 +124,7 @@ static int ns558_isa_probe(int io)
 		outb(0xff, io & (-1 << i));
 		for (j = b = 0; j < 1000; j++)
 			if (inb(io & (-1 << i)) != inb((io & (-1 << i)) + (1 << i) - 1)) b++;
-		msleep(3);
+		usleep_range(3000, 3100);
 
 		if (b > 300) {				/* We allow 30% difference */
 			release_region(io & (-1 << i), (1 << i));
diff --git a/drivers/input/joystick/adi.c b/drivers/input/joystick/adi.c
index d09cefa..f1955bf 100644
--- a/drivers/input/joystick/adi.c
+++ b/drivers/input/joystick/adi.c
@@ -48,7 +48,7 @@ MODULE_LICENSE("GPL");
 #define ADI_MAX_START		200	/* Trigger to packet timeout [200us] */
 #define ADI_MAX_STROBE		40	/* Single bit timeout [40us] */
 #define ADI_INIT_DELAY		10	/* Delay after init packet [10ms] */
-#define ADI_DATA_DELAY		4	/* Delay after data packet [4ms] */
+#define ADI_DATA_DELAY		4000	/* Delay after data packet [4000us] */
 
 #define ADI_MAX_LENGTH		256
 #define ADI_MIN_LENGTH		8
@@ -514,7 +514,7 @@ static int adi_connect(struct gameport *gameport, struct gameport_driver *drv)
 
 	msleep(ADI_INIT_DELAY);
 	if (adi_read(port)) {
-		msleep(ADI_DATA_DELAY);
+		usleep_range(ADI_DATA_DELAY, ADI_DATA_DELAY + 100);
 		adi_read(port);
 	}
 
diff --git a/drivers/input/joystick/analog.c b/drivers/input/joystick/analog.c
index 3d8ff09..2891704 100644
--- a/drivers/input/joystick/analog.c
+++ b/drivers/input/joystick/analog.c
@@ -88,7 +88,7 @@ MODULE_PARM_DESC(map, "Describes analog joysticks type/capabilities");
 #define ANALOG_EXTENSIONS	0x7ff00
 #define ANALOG_GAMEPAD		0x80000
 
-#define ANALOG_MAX_TIME		3	/* 3 ms */
+#define ANALOG_MAX_TIME		3000	/* 3000 us */
 #define ANALOG_LOOP_TIME	2000	/* 2 * loop */
 #define ANALOG_SAITEK_DELAY	200	/* 200 us */
 #define ANALOG_SAITEK_TIME	2000	/* 2000 us */
@@ -257,7 +257,7 @@ static int analog_cooked_read(struct analog_port *port)
 	int i, j;
 
 	loopout = (ANALOG_LOOP_TIME * port->loop) / 1000;
-	timeout = ANALOG_MAX_TIME * port->speed;
+	timeout = (ANALOG_MAX_TIME / 1000) * port->speed;
 
 	local_irq_save(flags);
 	gameport_trigger(gameport);
@@ -625,20 +625,20 @@ static int analog_init_port(struct gameport *gameport, struct gameport_driver *d
 
 		gameport_trigger(gameport);
 		t = gameport_read(gameport);
-		msleep(ANALOG_MAX_TIME);
+		usleep_range(ANALOG_MAX_TIME, ANALOG_MAX_TIME + 100);
 		port->mask = (gameport_read(gameport) ^ t) & t & 0xf;
 		port->fuzz = (port->speed * ANALOG_FUZZ_MAGIC) / port->loop / 1000 + ANALOG_FUZZ_BITS;
 
 		for (i = 0; i < ANALOG_INIT_RETRIES; i++) {
 			if (!analog_cooked_read(port))
 				break;
-			msleep(ANALOG_MAX_TIME);
+			usleep_range(ANALOG_MAX_TIME, ANALOG_MAX_TIME + 100);
 		}
 
 		u = v = 0;
 
-		msleep(ANALOG_MAX_TIME);
-		t = gameport_time(gameport, ANALOG_MAX_TIME * 1000);
+		usleep_range(ANALOG_MAX_TIME, ANALOG_MAX_TIME + 100);
+		t = gameport_time(gameport, ANALOG_MAX_TIME);
 		gameport_trigger(gameport);
 		while ((gameport_read(port->gameport) & port->mask) && (u < t))
 			u++;
diff --git a/drivers/input/joystick/gf2k.c b/drivers/input/joystick/gf2k.c
index 0f519db..e9d5095 100644
--- a/drivers/input/joystick/gf2k.c
+++ b/drivers/input/joystick/gf2k.c
@@ -42,7 +42,7 @@ MODULE_LICENSE("GPL");
 
 #define GF2K_START		400	/* The time we wait for the first bit [400 us] */
 #define GF2K_STROBE		40	/* The time we wait for the first bit [40 us] */
-#define GF2K_TIMEOUT		4	/* Wait for everything to settle [4 ms] */
+#define GF2K_TIMEOUT		4000	/* Wait for everything to settle [4000 us] */
 #define GF2K_LENGTH		80	/* Max number of triplets in a packet */
 
 /*
@@ -138,7 +138,7 @@ static void gf2k_trigger_seq(struct gameport *gameport, short *seq)
 	i = 0;
         do {
 		gameport_trigger(gameport);
-		t = gameport_time(gameport, GF2K_TIMEOUT * 1000);
+		t = gameport_time(gameport, GF2K_TIMEOUT);
 		while ((gameport_read(gameport) & 1) && t) t--;
                 udelay(seq[i]);
         } while (seq[++i]);
@@ -259,11 +259,11 @@ static int gf2k_connect(struct gameport *gameport, struct gameport_driver *drv)
 
 	gf2k_trigger_seq(gameport, gf2k_seq_reset);
 
-	msleep(GF2K_TIMEOUT);
+	usleep_range(GF2K_TIMEOUT, GF2K_TIMEOUT + 100);
 
 	gf2k_trigger_seq(gameport, gf2k_seq_digital);
 
-	msleep(GF2K_TIMEOUT);
+	usleep_range(GF2K_TIMEOUT, GF2K_TIMEOUT + 100);
 
 	if (gf2k_read_packet(gameport, GF2K_LENGTH, data) < 12) {
 		err = -ENODEV;
diff --git a/drivers/input/joystick/sidewinder.c b/drivers/input/joystick/sidewinder.c
index 4a95b22..e5a1292 100644
--- a/drivers/input/joystick/sidewinder.c
+++ b/drivers/input/joystick/sidewinder.c
@@ -50,7 +50,7 @@ MODULE_LICENSE("GPL");
 
 #define SW_START	600	/* The time we wait for the first bit [600 us] */
 #define SW_STROBE	60	/* Max time per bit [60 us] */
-#define SW_TIMEOUT	6	/* Wait for everything to settle [6 ms] */
+#define SW_TIMEOUT	6000	/* Wait for everything to settle [6000 us] */
 #define SW_KICK		45	/* Wait after A0 fall till kick [45 us] */
 #define SW_END		8	/* Number of bits before end of packet to kick */
 #define SW_FAIL		16	/* Number of packet read errors to fail and reinitialize */
@@ -139,7 +139,7 @@ static int sw_read_packet(struct gameport *gameport, unsigned char *buf, int len
 	unsigned char pending, u, v;
 
 	i = -id;						/* Don't care about data, only want ID */
-	timeout = id ? gameport_time(gameport, SW_TIMEOUT * 1000) : 0; /* Set up global timeout for ID packet */
+	timeout = id ? gameport_time(gameport, SW_TIMEOUT) : 0; /* Set up global timeout for ID packet */
 	kick = id ? gameport_time(gameport, SW_KICK) : 0;	/* Set up kick timeout for ID packet */
 	start = gameport_time(gameport, SW_START);
 	strobe = gameport_time(gameport, SW_STROBE);
@@ -248,7 +248,7 @@ static void sw_init_digital(struct gameport *gameport)
 	i = 0;
         do {
                 gameport_trigger(gameport);			/* Trigger */
-		t = gameport_time(gameport, SW_TIMEOUT * 1000);
+		t = gameport_time(gameport, SW_TIMEOUT);
 		while ((gameport_read(gameport) & 1) && t) t--;	/* Wait for axis to fall back to 0 */
                 udelay(seq[i]);					/* Delay magic time */
         } while (seq[++i]);
@@ -483,13 +483,13 @@ static int sw_read(struct sw *sw)
 		" - reinitializing joystick.\n", sw->gameport->phys);
 
 	if (!i && sw->type == SW_ID_3DP) {					/* 3D Pro can be in analog mode */
-		mdelay(3 * SW_TIMEOUT);
+		mdelay(3 * (SW_TIMEOUT / 1000));
 		sw_init_digital(sw->gameport);
 	}
 
-	mdelay(SW_TIMEOUT);
+	mdelay(SW_TIMEOUT / 1000);
 	i = sw_read_packet(sw->gameport, buf, SW_LENGTH, 0);			/* Read normal data packet */
-	mdelay(SW_TIMEOUT);
+	mdelay(SW_TIMEOUT / 1000);
 	sw_read_packet(sw->gameport, buf, SW_LENGTH, i);			/* Read ID packet, this initializes the stick */
 
 	sw->fail = SW_FAIL;
@@ -616,14 +616,14 @@ static int sw_connect(struct gameport *gameport, struct gameport_driver *drv)
 		gameport->phys, gameport->io, gameport->speed);
 
 	i = sw_read_packet(gameport, buf, SW_LENGTH, 0);		/* Read normal packet */
-	msleep(SW_TIMEOUT);
+	usleep_range(SW_TIMEOUT, SW_TIMEOUT + 100);
 	dbg("Init 1: Mode %d. Length %d.", m , i);
 
 	if (!i) {							/* No data. 3d Pro analog mode? */
 		sw_init_digital(gameport);				/* Switch to digital */
-		msleep(SW_TIMEOUT);
+		usleep_range(SW_TIMEOUT, SW_TIMEOUT + 100);
 		i = sw_read_packet(gameport, buf, SW_LENGTH, 0);	/* Retry reading packet */
-		msleep(SW_TIMEOUT);
+		usleep_range(SW_TIMEOUT, SW_TIMEOUT + 100);
 		dbg("Init 1b: Length %d.", i);
 		if (!i) {						/* No data -> FAIL */
 			err = -ENODEV;
@@ -636,7 +636,7 @@ static int sw_connect(struct gameport *gameport, struct gameport_driver *drv)
 	dbg("Init 2: Mode %d. ID Length %d.", m, j);
 
 	if (j <= 0) {							/* Read ID failed. Happens in 1-bit mode on PP */
-		msleep(SW_TIMEOUT);
+		usleep_range(SW_TIMEOUT, SW_TIMEOUT + 100);
 		i = sw_read_packet(gameport, buf, SW_LENGTH, 0);	/* Retry reading packet */
 		m |= sw_guess_mode(buf, i);
 		dbg("Init 2b: Mode %d. Length %d.", m, i);
@@ -644,7 +644,7 @@ static int sw_connect(struct gameport *gameport, struct gameport_driver *drv)
 			err = -ENODEV;
 			goto fail2;
 		}
-		msleep(SW_TIMEOUT);
+		usleep_range(SW_TIMEOUT, SW_TIMEOUT + 100);
 		j = sw_read_packet(gameport, idbuf, SW_LENGTH, i);	/* Retry reading ID */
 		dbg("Init 2c: ID Length %d.", j);
 	}
@@ -655,7 +655,7 @@ static int sw_connect(struct gameport *gameport, struct gameport_driver *drv)
 
 	do {
 		k--;
-		msleep(SW_TIMEOUT);
+		usleep_range(SW_TIMEOUT, SW_TIMEOUT + 100);
 		i = sw_read_packet(gameport, buf, SW_LENGTH, 0);	/* Read data packet */
 		dbg("Init 3: Mode %d. Length %d. Last %d. Tries %d.", m, i, l, k);
 
diff --git a/drivers/input/keyboard/lm8323.c b/drivers/input/keyboard/lm8323.c
index 21bea52..14679e9 100644
--- a/drivers/input/keyboard/lm8323.c
+++ b/drivers/input/keyboard/lm8323.c
@@ -689,7 +689,7 @@ static int lm8323_probe(struct i2c_client *client,
 			break;
 		}
 
-		msleep(1);
+		usleep_range(1000, 1100);
 	}
 
 	lm8323_configure(lm);
diff --git a/drivers/input/mouse/navpoint.c b/drivers/input/mouse/navpoint.c
index d6e8f58..2ede00b 100644
--- a/drivers/input/mouse/navpoint.c
+++ b/drivers/input/mouse/navpoint.c
@@ -166,7 +166,7 @@ static void navpoint_up(struct navpoint *navpoint)
 	for (timeout = 100; timeout != 0; --timeout) {
 		if (!(pxa_ssp_read_reg(ssp, SSSR) & SSSR_CSS))
 			break;
-		msleep(1);
+		usleep_range(1000, 1100);
 	}
 
 	if (timeout == 0)
diff --git a/drivers/input/mouse/pxa930_trkball.c b/drivers/input/mouse/pxa930_trkball.c
index 9b4d9a5..d8ac9f9 100644
--- a/drivers/input/mouse/pxa930_trkball.c
+++ b/drivers/input/mouse/pxa930_trkball.c
@@ -85,7 +85,7 @@ static int write_tbcr(struct pxa930_trkball *trkball, int v)
 	while (--i) {
 		if (__raw_readl(trkball->mmio_base + TBCR) == v)
 			break;
-		msleep(1);
+		usleep_range(1000, 1100);
 	}
 
 	if (i == 0) {
diff --git a/drivers/input/mouse/synaptics_i2c.c b/drivers/input/mouse/synaptics_i2c.c
index aa7c5da..826ac65 100644
--- a/drivers/input/mouse/synaptics_i2c.c
+++ b/drivers/input/mouse/synaptics_i2c.c
@@ -29,9 +29,9 @@
  * after soft reset, we should wait for 1 ms
  * before the device becomes operational
  */
-#define SOFT_RESET_DELAY_MS	3
+#define SOFT_RESET_DELAY_US	3000
 /* and after hard reset, we should wait for max 500ms */
-#define HARD_RESET_DELAY_MS	500
+#define HARD_RESET_DELAY_US	500000
 
 /* Registers by SMBus address */
 #define PAGE_SEL_REG		0xff
@@ -311,7 +311,7 @@ static int synaptics_i2c_reset_config(struct i2c_client *client)
 	if (ret) {
 		dev_err(&client->dev, "Unable to reset device\n");
 	} else {
-		msleep(SOFT_RESET_DELAY_MS);
+		usleep_range(SOFT_RESET_DELAY_US, SOFT_RESET_DELAY_US + 100);
 		ret = synaptics_i2c_config(client);
 		if (ret)
 			dev_err(&client->dev, "Unable to config device\n");
diff --git a/drivers/input/touchscreen/ads7846.c b/drivers/input/touchscreen/ads7846.c
index 1ce3ecb..b1a5a6c 100644
--- a/drivers/input/touchscreen/ads7846.c
+++ b/drivers/input/touchscreen/ads7846.c
@@ -58,7 +58,7 @@
  * files.
  */
 
-#define TS_POLL_DELAY	1	/* ms delay before the first sample */
+#define TS_POLL_DELAY	1000	/* us delay before the first sample */
 #define TS_POLL_PERIOD	5	/* ms delay between samples */
 
 /* this driver doesn't aim at the peak continuous sample rate */
@@ -857,7 +857,7 @@ static irqreturn_t ads7846_irq(int irq, void *handle)
 	struct ads7846 *ts = handle;
 
 	/* Start with a small delay before checking pendown state */
-	msleep(TS_POLL_DELAY);
+	usleep_range(TS_POLL_DELAY, TS_POLL_DELAY + 100);
 
 	while (!ts->stopped && get_pendown_state(ts)) {
 
diff --git a/drivers/input/touchscreen/edt-ft5x06.c b/drivers/input/touchscreen/edt-ft5x06.c
index 703e295..379dd31 100644
--- a/drivers/input/touchscreen/edt-ft5x06.c
+++ b/drivers/input/touchscreen/edt-ft5x06.c
@@ -67,7 +67,7 @@
 #define EDT_SWITCH_MODE_RETRIES		10
 #define EDT_SWITCH_MODE_DELAY		5 /* msec */
 #define EDT_RAW_DATA_RETRIES		100
-#define EDT_RAW_DATA_DELAY		1 /* msec */
+#define EDT_RAW_DATA_DELAY		1000 /* usec */
 
 enum edt_ver {
 	M06,
@@ -664,7 +664,7 @@ static ssize_t edt_ft5x06_debugfs_raw_data_read(struct file *file,
 	}
 
 	do {
-		msleep(EDT_RAW_DATA_DELAY);
+		usleep_range(EDT_RAW_DATA_DELAY, EDT_RAW_DATA_DELAY + 100);
 		val = edt_ft5x06_register_read(tsdata, 0x08);
 		if (val < 1)
 			break;
diff --git a/drivers/input/touchscreen/w90p910_ts.c b/drivers/input/touchscreen/w90p910_ts.c
index da6004e..3f14b5a 100644
--- a/drivers/input/touchscreen/w90p910_ts.c
+++ b/drivers/input/touchscreen/w90p910_ts.c
@@ -171,9 +171,9 @@ static int w90p910_open(struct input_dev *dev)
 	clk_enable(w90p910_ts->clk);
 
 	__raw_writel(ADC_RST1, w90p910_ts->ts_reg);
-	msleep(1);
+	usleep_range(1000, 1100);
 	__raw_writel(ADC_RST0, w90p910_ts->ts_reg);
-	msleep(1);
+	usleep_range(1000, 1100);
 
 	/* set delay and screen type */
 	val = __raw_readl(w90p910_ts->ts_reg + 0x04);
diff --git a/drivers/input/touchscreen/zylonite-wm97xx.c b/drivers/input/touchscreen/zylonite-wm97xx.c
index e2ccd68..cebd3a8 100644
--- a/drivers/input/touchscreen/zylonite-wm97xx.c
+++ b/drivers/input/touchscreen/zylonite-wm97xx.c
@@ -81,7 +81,7 @@ static void wm97xx_acc_pen_up(struct wm97xx *wm)
 {
 	int i;
 
-	msleep(1);
+	usleep_range(1000, 1100);
 
 	for (i = 0; i < 16; i++)
 		MODR;
@@ -98,7 +98,7 @@ static int wm97xx_acc_pen_down(struct wm97xx *wm)
 	 * for samples.  The controller can't have a suitably low
 	 * threshold set to use the notifications it gives.
 	 */
-	msleep(1);
+	usleep_range(1000, 1100);
 
 	if (tries > 5) {
 		tries = 0;
-- 
2.6.2

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

end of thread, other threads:[~2016-12-23  5:07 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-11-24 16:03 [PATCH] Input: Change msleep to usleep_range for small msecs Aniroop Mathur
2016-11-28 16:35 ` Aniroop Mathur
2016-12-01  5:49   ` ZHANG Xu (BST/ESA3.1)
     [not found]   ` <CGME20161201054940epcas4p3ad9a27ce7fbfcd94ac71e13180b7fb66@epcas4p3.samsung.com>
2016-12-01 10:34     ` Aniroop Mathur
2016-12-01 11:44       ` ZHANG Xu (BST/ESA3.1)
2016-12-01 15:50       ` RE: RE: [Please Apply][PATCH] Input: misc: bma150: " Aniroop Mathur
2016-12-23  5:07       ` RE: [PATCH] Input: " ZHANG Xu (BST/ESA3.1)
2016-11-24 19:24 Aniroop Mathur
2016-11-28  4:48 ` Dmitry Torokhov

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