diff mbox series

media: mtk-cir: fix calculation of chk period

Message ID 20201128165728.29756-1-sean@mess.org (mailing list archive)
State New, archived
Headers show
Series media: mtk-cir: fix calculation of chk period | expand

Commit Message

Sean Young Nov. 28, 2020, 4:57 p.m. UTC
Since commit 528222d853f9 ("media: rc: harmonize infrared durations to
microseconds"), the calculation of the chk period is wrong. As a result,
all reported IR will have incorrect timings.

Now that the calculations are done in microseconds rather than nanoseconds,
we can fold the calculations in a simpler form with less rounding error.

Cc: Frank Wunderlich <frank-w@public-files.de>
Fixes: 528222d853f9 ("media: rc: harmonize infrared durations to microseconds")
Signed-off-by: Sean Young <sean@mess.org>
---
 drivers/media/rc/mtk-cir.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)

Comments

Sean Young Nov. 29, 2020, 9:38 a.m. UTC | #1
Hi Frank,

On Sat, Nov 28, 2020 at 04:57:28PM +0000, Sean Young wrote:
> Since commit 528222d853f9 ("media: rc: harmonize infrared durations to
> microseconds"), the calculation of the chk period is wrong. As a result,
> all reported IR will have incorrect timings.
> 
> Now that the calculations are done in microseconds rather than nanoseconds,
> we can fold the calculations in a simpler form with less rounding error.

Would you be able to test this change please? That would be super-helpful.

Thank you,

Sean

> 
> Cc: Frank Wunderlich <frank-w@public-files.de>
> Fixes: 528222d853f9 ("media: rc: harmonize infrared durations to microseconds")
> Signed-off-by: Sean Young <sean@mess.org>
> ---
>  drivers/media/rc/mtk-cir.c | 7 ++-----
>  1 file changed, 2 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/media/rc/mtk-cir.c b/drivers/media/rc/mtk-cir.c
> index 5051a5e5244b..cdfb1eded306 100644
> --- a/drivers/media/rc/mtk-cir.c
> +++ b/drivers/media/rc/mtk-cir.c
> @@ -151,15 +151,12 @@ static inline u32 mtk_chk_period(struct mtk_ir *ir)
>  {
>  	u32 val;
>  
> -	/* Period of raw software sampling in ns */
> -	val = DIV_ROUND_CLOSEST(1000000000ul,
> -				clk_get_rate(ir->bus) / ir->data->div);
> -
>  	/*
>  	 * Period for software decoder used in the
>  	 * unit of raw software sampling
>  	 */
> -	val = DIV_ROUND_CLOSEST(MTK_IR_SAMPLE, val);
> +	val = DIV_ROUND_CLOSEST(MTK_IR_SAMPLE * clk_get_rate(ir->bus),
> +				USEC_PER_SEC * ir->data->div);
>  
>  	dev_dbg(ir->dev, "@pwm clk  = \t%lu\n",
>  		clk_get_rate(ir->bus) / ir->data->div);
> -- 
> 2.28.0
diff mbox series

Patch

diff --git a/drivers/media/rc/mtk-cir.c b/drivers/media/rc/mtk-cir.c
index 5051a5e5244b..cdfb1eded306 100644
--- a/drivers/media/rc/mtk-cir.c
+++ b/drivers/media/rc/mtk-cir.c
@@ -151,15 +151,12 @@  static inline u32 mtk_chk_period(struct mtk_ir *ir)
 {
 	u32 val;
 
-	/* Period of raw software sampling in ns */
-	val = DIV_ROUND_CLOSEST(1000000000ul,
-				clk_get_rate(ir->bus) / ir->data->div);
-
 	/*
 	 * Period for software decoder used in the
 	 * unit of raw software sampling
 	 */
-	val = DIV_ROUND_CLOSEST(MTK_IR_SAMPLE, val);
+	val = DIV_ROUND_CLOSEST(MTK_IR_SAMPLE * clk_get_rate(ir->bus),
+				USEC_PER_SEC * ir->data->div);
 
 	dev_dbg(ir->dev, "@pwm clk  = \t%lu\n",
 		clk_get_rate(ir->bus) / ir->data->div);