hc
2024-05-13 9d77db3c730780c8ef5ccd4b66403ff5675cfe4e
kernel/drivers/media/rc/mtk-cir.c
....@@ -1,17 +1,8 @@
1
+// SPDX-License-Identifier: GPL-2.0-or-later
12 /*
23 * Driver for Mediatek IR Receiver Controller
34 *
45 * Copyright (C) 2017 Sean Wang <sean.wang@mediatek.com>
5
- *
6
- * This program is free software; you can redistribute it and/or
7
- * modify it under the terms of the GNU General Public License as
8
- * published by the Free Software Foundation; either version 2 of
9
- * the License, or (at your option) any later version.
10
- *
11
- * This program is distributed in the hope that it will be useful,
12
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
- * GNU General Public License for more details.
156 */
167
178 #include <linux/clk.h>
....@@ -61,8 +52,8 @@
6152 #define MTK_IR_END(v, p) ((v) == MTK_MAX_SAMPLES && (p) == 0)
6253 /* Number of registers to record the pulse width */
6354 #define MTK_CHKDATA_SZ 17
64
-/* Sample period in ns */
65
-#define MTK_IR_SAMPLE 46000
55
+/* Sample period in us */
56
+#define MTK_IR_SAMPLE 46
6657
6758 enum mtk_fields {
6859 /* Register to setting software sampling period */
....@@ -160,15 +151,12 @@
160151 {
161152 u32 val;
162153
163
- /* Period of raw software sampling in ns */
164
- val = DIV_ROUND_CLOSEST(1000000000ul,
165
- clk_get_rate(ir->bus) / ir->data->div);
166
-
167154 /*
168155 * Period for software decoder used in the
169156 * unit of raw software sampling
170157 */
171
- 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);
172160
173161 dev_dbg(ir->dev, "@pwm clk = \t%lu\n",
174162 clk_get_rate(ir->bus) / ir->data->div);
....@@ -217,7 +205,7 @@
217205 struct mtk_ir *ir = dev_id;
218206 u8 wid = 0;
219207 u32 i, j, val;
220
- DEFINE_IR_RAW_EVENT(rawir);
208
+ struct ir_raw_event rawir = {};
221209
222210 /*
223211 * Reset decoder state machine explicitly is required
....@@ -334,10 +322,8 @@
334322
335323 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
336324 ir->base = devm_ioremap_resource(dev, res);
337
- if (IS_ERR(ir->base)) {
338
- dev_err(dev, "failed to map registers\n");
325
+ if (IS_ERR(ir->base))
339326 return PTR_ERR(ir->base);
340
- }
341327
342328 ir->rc = devm_rc_allocate_device(dev, RC_DRIVER_IR_RAW);
343329 if (!ir->rc) {
....@@ -356,7 +342,7 @@
356342 ir->rc->map_name = map_name ?: RC_MAP_EMPTY;
357343 ir->rc->dev.parent = dev;
358344 ir->rc->driver_name = MTK_IR_DEV;
359
- ir->rc->allowed_protocols = RC_PROTO_BIT_ALL;
345
+ ir->rc->allowed_protocols = RC_PROTO_BIT_ALL_IR_DECODER;
360346 ir->rc->rx_resolution = MTK_IR_SAMPLE;
361347 ir->rc->timeout = MTK_MAX_SAMPLES * (MTK_IR_SAMPLE + 1);
362348
....@@ -369,10 +355,8 @@
369355 platform_set_drvdata(pdev, ir);
370356
371357 ir->irq = platform_get_irq(pdev, 0);
372
- if (ir->irq < 0) {
373
- dev_err(dev, "no irq resource\n");
358
+ if (ir->irq < 0)
374359 return -ENODEV;
375
- }
376360
377361 if (clk_prepare_enable(ir->clk)) {
378362 dev_err(dev, "try to enable ir_clk failed\n");
....@@ -425,7 +409,7 @@
425409 mtk_irq_enable(ir, MTK_IRINT_EN);
426410
427411 dev_info(dev, "Initialized MT7623 IR driver, sample period = %dus\n",
428
- DIV_ROUND_CLOSEST(MTK_IR_SAMPLE, 1000));
412
+ MTK_IR_SAMPLE);
429413
430414 return 0;
431415