hc
2024-05-13 9d77db3c730780c8ef5ccd4b66403ff5675cfe4e
kernel/drivers/media/rc/lirc_dev.c
....@@ -1,18 +1,8 @@
1
+// SPDX-License-Identifier: GPL-2.0-or-later
12 /*
23 * LIRC base driver
34 *
45 * by Artur Lipowski <alipowski@interia.pl>
5
- *
6
- * This program is free software; you can redistribute it and/or modify
7
- * it under the terms of the GNU General Public License as published by
8
- * the Free Software Foundation; either version 2 of the License, or
9
- * (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.
15
- *
166 */
177
188 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
....@@ -40,12 +30,12 @@
4030 static struct class *lirc_class;
4131
4232 /**
43
- * ir_lirc_raw_event() - Send raw IR data to lirc to be relayed to userspace
33
+ * lirc_raw_event() - Send raw IR data to lirc to be relayed to userspace
4434 *
4535 * @dev: the struct rc_dev descriptor of the device
4636 * @ev: the struct ir_raw_event descriptor of the pulse/space
4737 */
48
-void ir_lirc_raw_event(struct rc_dev *dev, struct ir_raw_event ev)
38
+void lirc_raw_event(struct rc_dev *dev, struct ir_raw_event ev)
4939 {
5040 unsigned long flags;
5141 struct lirc_fh *fh;
....@@ -77,17 +67,16 @@
7767 dev->gap = true;
7868 dev->gap_duration = ev.duration;
7969
80
- sample = LIRC_TIMEOUT(ev.duration / 1000);
70
+ sample = LIRC_TIMEOUT(ev.duration);
8171 dev_dbg(&dev->dev, "timeout report (duration: %d)\n", sample);
8272
8373 /* Normal sample */
8474 } else {
8575 if (dev->gap) {
86
- dev->gap_duration += ktime_to_ns(ktime_sub(ktime_get(),
76
+ dev->gap_duration += ktime_to_us(ktime_sub(ktime_get(),
8777 dev->gap_start));
8878
89
- /* Convert to ms and cap by LIRC_VALUE_MASK */
90
- do_div(dev->gap_duration, 1000);
79
+ /* Cap by LIRC_VALUE_MASK */
9180 dev->gap_duration = min_t(u64, dev->gap_duration,
9281 LIRC_VALUE_MASK);
9382
....@@ -99,10 +88,10 @@
9988 dev->gap = false;
10089 }
10190
102
- sample = ev.pulse ? LIRC_PULSE(ev.duration / 1000) :
103
- LIRC_SPACE(ev.duration / 1000);
91
+ sample = ev.pulse ? LIRC_PULSE(ev.duration) :
92
+ LIRC_SPACE(ev.duration);
10493 dev_dbg(&dev->dev, "delivering %uus %s to lirc_dev\n",
105
- TO_US(ev.duration), TO_STR(ev.pulse));
94
+ ev.duration, TO_STR(ev.pulse));
10695 }
10796
10897 /*
....@@ -122,12 +111,12 @@
122111 }
123112
124113 /**
125
- * ir_lirc_scancode_event() - Send scancode data to lirc to be relayed to
114
+ * lirc_scancode_event() - Send scancode data to lirc to be relayed to
126115 * userspace. This can be called in atomic context.
127116 * @dev: the struct rc_dev descriptor of the device
128117 * @lsc: the struct lirc_scancode describing the decoded scancode
129118 */
130
-void ir_lirc_scancode_event(struct rc_dev *dev, struct lirc_scancode *lsc)
119
+void lirc_scancode_event(struct rc_dev *dev, struct lirc_scancode *lsc)
131120 {
132121 unsigned long flags;
133122 struct lirc_fh *fh;
....@@ -141,9 +130,9 @@
141130 }
142131 spin_unlock_irqrestore(&dev->lirc_fh_lock, flags);
143132 }
144
-EXPORT_SYMBOL_GPL(ir_lirc_scancode_event);
133
+EXPORT_SYMBOL_GPL(lirc_scancode_event);
145134
146
-static int ir_lirc_open(struct inode *inode, struct file *file)
135
+static int lirc_open(struct inode *inode, struct file *file)
147136 {
148137 struct rc_dev *dev = container_of(inode->i_cdev, struct rc_dev,
149138 lirc_cdev);
....@@ -195,7 +184,7 @@
195184 list_add(&fh->list, &dev->lirc_fh);
196185 spin_unlock_irqrestore(&dev->lirc_fh_lock, flags);
197186
198
- nonseekable_open(inode, file);
187
+ stream_open(inode, file);
199188
200189 return 0;
201190 out_kfifo:
....@@ -211,7 +200,7 @@
211200 return retval;
212201 }
213202
214
-static int ir_lirc_close(struct inode *inode, struct file *file)
203
+static int lirc_close(struct inode *inode, struct file *file)
215204 {
216205 struct lirc_fh *fh = file->private_data;
217206 struct rc_dev *dev = fh->rc;
....@@ -233,8 +222,8 @@
233222 return 0;
234223 }
235224
236
-static ssize_t ir_lirc_transmit_ir(struct file *file, const char __user *buf,
237
- size_t n, loff_t *ppos)
225
+static ssize_t lirc_transmit(struct file *file, const char __user *buf,
226
+ size_t n, loff_t *ppos)
238227 {
239228 struct lirc_fh *fh = file->private_data;
240229 struct rc_dev *dev = fh->rc;
....@@ -279,12 +268,7 @@
279268 goto out_unlock;
280269 }
281270
282
- /*
283
- * The scancode field in lirc_scancode is 64-bit simply
284
- * to future-proof it, since there are IR protocols encode
285
- * use more than 32 bits. For now only 32-bit protocols
286
- * are supported.
287
- */
271
+ /* We only have encoders for 32-bit protocols. */
288272 if (scan.scancode > U32_MAX ||
289273 !rc_validate_scancode(scan.rc_proto, scan.scancode)) {
290274 ret = -EINVAL;
....@@ -311,8 +295,7 @@
311295 }
312296
313297 for (i = 0; i < count; i++)
314
- /* Convert from NS to US */
315
- txbuf[i] = DIV_ROUND_UP(raw[i].duration, 1000);
298
+ txbuf[i] = raw[i].duration;
316299
317300 if (dev->s_tx_carrier) {
318301 int carrier = ir_raw_encode_carrier(scan.rc_proto);
....@@ -340,7 +323,7 @@
340323 }
341324
342325 for (i = 0; i < count; i++) {
343
- if (txbuf[i] > IR_MAX_DURATION / 1000 - duration || !txbuf[i]) {
326
+ if (txbuf[i] > IR_MAX_DURATION - duration || !txbuf[i]) {
344327 ret = -EINVAL;
345328 goto out_kfree;
346329 }
....@@ -380,8 +363,7 @@
380363 return ret;
381364 }
382365
383
-static long ir_lirc_ioctl(struct file *file, unsigned int cmd,
384
- unsigned long arg)
366
+static long lirc_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
385367 {
386368 struct lirc_fh *fh = file->private_data;
387369 struct rc_dev *dev = fh->rc;
....@@ -532,7 +514,7 @@
532514 if (!dev->rx_resolution)
533515 ret = -ENOTTY;
534516 else
535
- val = dev->rx_resolution / 1000;
517
+ val = dev->rx_resolution;
536518 break;
537519
538520 case LIRC_SET_WIDEBAND_RECEIVER:
....@@ -554,31 +536,26 @@
554536 if (!dev->max_timeout)
555537 ret = -ENOTTY;
556538 else
557
- val = DIV_ROUND_UP(dev->min_timeout, 1000);
539
+ val = dev->min_timeout;
558540 break;
559541
560542 case LIRC_GET_MAX_TIMEOUT:
561543 if (!dev->max_timeout)
562544 ret = -ENOTTY;
563545 else
564
- val = dev->max_timeout / 1000;
546
+ val = dev->max_timeout;
565547 break;
566548
567549 case LIRC_SET_REC_TIMEOUT:
568550 if (!dev->max_timeout) {
569551 ret = -ENOTTY;
570
- } else if (val > U32_MAX / 1000) {
571
- /* Check for multiply overflow */
572
- ret = -EINVAL;
573552 } else {
574
- u32 tmp = val * 1000;
575
-
576
- if (tmp < dev->min_timeout || tmp > dev->max_timeout)
553
+ if (val < dev->min_timeout || val > dev->max_timeout)
577554 ret = -EINVAL;
578555 else if (dev->s_timeout)
579
- ret = dev->s_timeout(dev, tmp);
556
+ ret = dev->s_timeout(dev, val);
580557 else
581
- dev->timeout = tmp;
558
+ dev->timeout = val;
582559 }
583560 break;
584561
....@@ -586,7 +563,7 @@
586563 if (!dev->timeout)
587564 ret = -ENOTTY;
588565 else
589
- val = DIV_ROUND_UP(dev->timeout, 1000);
566
+ val = dev->timeout;
590567 break;
591568
592569 case LIRC_SET_REC_TIMEOUT_REPORTS:
....@@ -608,7 +585,7 @@
608585 return ret;
609586 }
610587
611
-static __poll_t ir_lirc_poll(struct file *file, struct poll_table_struct *wait)
588
+static __poll_t lirc_poll(struct file *file, struct poll_table_struct *wait)
612589 {
613590 struct lirc_fh *fh = file->private_data;
614591 struct rc_dev *rcdev = fh->rc;
....@@ -631,8 +608,8 @@
631608 return events;
632609 }
633610
634
-static ssize_t ir_lirc_read_mode2(struct file *file, char __user *buffer,
635
- size_t length)
611
+static ssize_t lirc_read_mode2(struct file *file, char __user *buffer,
612
+ size_t length)
636613 {
637614 struct lirc_fh *fh = file->private_data;
638615 struct rc_dev *rcdev = fh->rc;
....@@ -669,8 +646,8 @@
669646 return copied;
670647 }
671648
672
-static ssize_t ir_lirc_read_scancode(struct file *file, char __user *buffer,
673
- size_t length)
649
+static ssize_t lirc_read_scancode(struct file *file, char __user *buffer,
650
+ size_t length)
674651 {
675652 struct lirc_fh *fh = file->private_data;
676653 struct rc_dev *rcdev = fh->rc;
....@@ -708,8 +685,8 @@
708685 return copied;
709686 }
710687
711
-static ssize_t ir_lirc_read(struct file *file, char __user *buffer,
712
- size_t length, loff_t *ppos)
688
+static ssize_t lirc_read(struct file *file, char __user *buffer, size_t length,
689
+ loff_t *ppos)
713690 {
714691 struct lirc_fh *fh = file->private_data;
715692 struct rc_dev *rcdev = fh->rc;
....@@ -721,22 +698,20 @@
721698 return -ENODEV;
722699
723700 if (fh->rec_mode == LIRC_MODE_MODE2)
724
- return ir_lirc_read_mode2(file, buffer, length);
701
+ return lirc_read_mode2(file, buffer, length);
725702 else /* LIRC_MODE_SCANCODE */
726
- return ir_lirc_read_scancode(file, buffer, length);
703
+ return lirc_read_scancode(file, buffer, length);
727704 }
728705
729706 static const struct file_operations lirc_fops = {
730707 .owner = THIS_MODULE,
731
- .write = ir_lirc_transmit_ir,
732
- .unlocked_ioctl = ir_lirc_ioctl,
733
-#ifdef CONFIG_COMPAT
734
- .compat_ioctl = ir_lirc_ioctl,
735
-#endif
736
- .read = ir_lirc_read,
737
- .poll = ir_lirc_poll,
738
- .open = ir_lirc_open,
739
- .release = ir_lirc_close,
708
+ .write = lirc_transmit,
709
+ .unlocked_ioctl = lirc_ioctl,
710
+ .compat_ioctl = compat_ptr_ioctl,
711
+ .read = lirc_read,
712
+ .poll = lirc_poll,
713
+ .open = lirc_open,
714
+ .release = lirc_close,
740715 .llseek = no_llseek,
741716 };
742717
....@@ -747,7 +722,7 @@
747722 put_device(&rcdev->dev);
748723 }
749724
750
-int ir_lirc_register(struct rc_dev *dev)
725
+int lirc_register(struct rc_dev *dev)
751726 {
752727 const char *rx_type, *tx_type;
753728 int err, minor;
....@@ -801,7 +776,7 @@
801776 return err;
802777 }
803778
804
-void ir_lirc_unregister(struct rc_dev *dev)
779
+void lirc_unregister(struct rc_dev *dev)
805780 {
806781 unsigned long flags;
807782 struct lirc_fh *fh;
....@@ -828,8 +803,7 @@
828803 return PTR_ERR(lirc_class);
829804 }
830805
831
- retval = alloc_chrdev_region(&lirc_base_dev, 0, RC_DEV_MAX,
832
- "BaseRemoteCtl");
806
+ retval = alloc_chrdev_region(&lirc_base_dev, 0, RC_DEV_MAX, "lirc");
833807 if (retval) {
834808 class_destroy(lirc_class);
835809 pr_err("alloc_chrdev_region failed\n");