Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

media: mtk-cir: fix calculation of chk period

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.

Tested-by: Frank Wunderlich <frank-w@public-files.de>
Fixes: 528222d853f9 ("media: rc: harmonize infrared durations to microseconds")
Signed-off-by: Sean Young <sean@mess.org>
Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>

authored by

Sean Young and committed by
Mauro Carvalho Chehab
d904eb0b 44f28934

+3 -6
+3 -6
drivers/media/rc/mtk-cir.c
··· 151 151 { 152 152 u32 val; 153 153 154 - /* Period of raw software sampling in ns */ 155 - val = DIV_ROUND_CLOSEST(1000000000ul, 156 - clk_get_rate(ir->bus) / ir->data->div); 157 - 158 154 /* 159 155 * Period for software decoder used in the 160 156 * unit of raw software sampling 161 157 */ 162 - val = DIV_ROUND_CLOSEST(MTK_IR_SAMPLE, val); 158 + val = DIV_ROUND_CLOSEST(clk_get_rate(ir->bus), 159 + USEC_PER_SEC * ir->data->div / MTK_IR_SAMPLE); 163 160 164 161 dev_dbg(ir->dev, "@pwm clk = \t%lu\n", 165 162 clk_get_rate(ir->bus) / ir->data->div); ··· 409 412 mtk_irq_enable(ir, MTK_IRINT_EN); 410 413 411 414 dev_info(dev, "Initialized MT7623 IR driver, sample period = %dus\n", 412 - DIV_ROUND_CLOSEST(MTK_IR_SAMPLE, 1000)); 415 + MTK_IR_SAMPLE); 413 416 414 417 return 0; 415 418