| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-or-later |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * LIRC base driver |
|---|
| 3 | 4 | * |
|---|
| 4 | 5 | * 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 | | - * |
|---|
| 16 | 6 | */ |
|---|
| 17 | 7 | |
|---|
| 18 | 8 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
|---|
| .. | .. |
|---|
| 40 | 30 | static struct class *lirc_class; |
|---|
| 41 | 31 | |
|---|
| 42 | 32 | /** |
|---|
| 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 |
|---|
| 44 | 34 | * |
|---|
| 45 | 35 | * @dev: the struct rc_dev descriptor of the device |
|---|
| 46 | 36 | * @ev: the struct ir_raw_event descriptor of the pulse/space |
|---|
| 47 | 37 | */ |
|---|
| 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) |
|---|
| 49 | 39 | { |
|---|
| 50 | 40 | unsigned long flags; |
|---|
| 51 | 41 | struct lirc_fh *fh; |
|---|
| .. | .. |
|---|
| 77 | 67 | dev->gap = true; |
|---|
| 78 | 68 | dev->gap_duration = ev.duration; |
|---|
| 79 | 69 | |
|---|
| 80 | | - sample = LIRC_TIMEOUT(ev.duration / 1000); |
|---|
| 70 | + sample = LIRC_TIMEOUT(ev.duration); |
|---|
| 81 | 71 | dev_dbg(&dev->dev, "timeout report (duration: %d)\n", sample); |
|---|
| 82 | 72 | |
|---|
| 83 | 73 | /* Normal sample */ |
|---|
| 84 | 74 | } else { |
|---|
| 85 | 75 | 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(), |
|---|
| 87 | 77 | dev->gap_start)); |
|---|
| 88 | 78 | |
|---|
| 89 | | - /* Convert to ms and cap by LIRC_VALUE_MASK */ |
|---|
| 90 | | - do_div(dev->gap_duration, 1000); |
|---|
| 79 | + /* Cap by LIRC_VALUE_MASK */ |
|---|
| 91 | 80 | dev->gap_duration = min_t(u64, dev->gap_duration, |
|---|
| 92 | 81 | LIRC_VALUE_MASK); |
|---|
| 93 | 82 | |
|---|
| .. | .. |
|---|
| 99 | 88 | dev->gap = false; |
|---|
| 100 | 89 | } |
|---|
| 101 | 90 | |
|---|
| 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); |
|---|
| 104 | 93 | 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)); |
|---|
| 106 | 95 | } |
|---|
| 107 | 96 | |
|---|
| 108 | 97 | /* |
|---|
| .. | .. |
|---|
| 122 | 111 | } |
|---|
| 123 | 112 | |
|---|
| 124 | 113 | /** |
|---|
| 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 |
|---|
| 126 | 115 | * userspace. This can be called in atomic context. |
|---|
| 127 | 116 | * @dev: the struct rc_dev descriptor of the device |
|---|
| 128 | 117 | * @lsc: the struct lirc_scancode describing the decoded scancode |
|---|
| 129 | 118 | */ |
|---|
| 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) |
|---|
| 131 | 120 | { |
|---|
| 132 | 121 | unsigned long flags; |
|---|
| 133 | 122 | struct lirc_fh *fh; |
|---|
| .. | .. |
|---|
| 141 | 130 | } |
|---|
| 142 | 131 | spin_unlock_irqrestore(&dev->lirc_fh_lock, flags); |
|---|
| 143 | 132 | } |
|---|
| 144 | | -EXPORT_SYMBOL_GPL(ir_lirc_scancode_event); |
|---|
| 133 | +EXPORT_SYMBOL_GPL(lirc_scancode_event); |
|---|
| 145 | 134 | |
|---|
| 146 | | -static int ir_lirc_open(struct inode *inode, struct file *file) |
|---|
| 135 | +static int lirc_open(struct inode *inode, struct file *file) |
|---|
| 147 | 136 | { |
|---|
| 148 | 137 | struct rc_dev *dev = container_of(inode->i_cdev, struct rc_dev, |
|---|
| 149 | 138 | lirc_cdev); |
|---|
| .. | .. |
|---|
| 195 | 184 | list_add(&fh->list, &dev->lirc_fh); |
|---|
| 196 | 185 | spin_unlock_irqrestore(&dev->lirc_fh_lock, flags); |
|---|
| 197 | 186 | |
|---|
| 198 | | - nonseekable_open(inode, file); |
|---|
| 187 | + stream_open(inode, file); |
|---|
| 199 | 188 | |
|---|
| 200 | 189 | return 0; |
|---|
| 201 | 190 | out_kfifo: |
|---|
| .. | .. |
|---|
| 211 | 200 | return retval; |
|---|
| 212 | 201 | } |
|---|
| 213 | 202 | |
|---|
| 214 | | -static int ir_lirc_close(struct inode *inode, struct file *file) |
|---|
| 203 | +static int lirc_close(struct inode *inode, struct file *file) |
|---|
| 215 | 204 | { |
|---|
| 216 | 205 | struct lirc_fh *fh = file->private_data; |
|---|
| 217 | 206 | struct rc_dev *dev = fh->rc; |
|---|
| .. | .. |
|---|
| 233 | 222 | return 0; |
|---|
| 234 | 223 | } |
|---|
| 235 | 224 | |
|---|
| 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) |
|---|
| 238 | 227 | { |
|---|
| 239 | 228 | struct lirc_fh *fh = file->private_data; |
|---|
| 240 | 229 | struct rc_dev *dev = fh->rc; |
|---|
| .. | .. |
|---|
| 279 | 268 | goto out_unlock; |
|---|
| 280 | 269 | } |
|---|
| 281 | 270 | |
|---|
| 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. */ |
|---|
| 288 | 272 | if (scan.scancode > U32_MAX || |
|---|
| 289 | 273 | !rc_validate_scancode(scan.rc_proto, scan.scancode)) { |
|---|
| 290 | 274 | ret = -EINVAL; |
|---|
| .. | .. |
|---|
| 311 | 295 | } |
|---|
| 312 | 296 | |
|---|
| 313 | 297 | 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; |
|---|
| 316 | 299 | |
|---|
| 317 | 300 | if (dev->s_tx_carrier) { |
|---|
| 318 | 301 | int carrier = ir_raw_encode_carrier(scan.rc_proto); |
|---|
| .. | .. |
|---|
| 340 | 323 | } |
|---|
| 341 | 324 | |
|---|
| 342 | 325 | 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]) { |
|---|
| 344 | 327 | ret = -EINVAL; |
|---|
| 345 | 328 | goto out_kfree; |
|---|
| 346 | 329 | } |
|---|
| .. | .. |
|---|
| 380 | 363 | return ret; |
|---|
| 381 | 364 | } |
|---|
| 382 | 365 | |
|---|
| 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) |
|---|
| 385 | 367 | { |
|---|
| 386 | 368 | struct lirc_fh *fh = file->private_data; |
|---|
| 387 | 369 | struct rc_dev *dev = fh->rc; |
|---|
| .. | .. |
|---|
| 532 | 514 | if (!dev->rx_resolution) |
|---|
| 533 | 515 | ret = -ENOTTY; |
|---|
| 534 | 516 | else |
|---|
| 535 | | - val = dev->rx_resolution / 1000; |
|---|
| 517 | + val = dev->rx_resolution; |
|---|
| 536 | 518 | break; |
|---|
| 537 | 519 | |
|---|
| 538 | 520 | case LIRC_SET_WIDEBAND_RECEIVER: |
|---|
| .. | .. |
|---|
| 554 | 536 | if (!dev->max_timeout) |
|---|
| 555 | 537 | ret = -ENOTTY; |
|---|
| 556 | 538 | else |
|---|
| 557 | | - val = DIV_ROUND_UP(dev->min_timeout, 1000); |
|---|
| 539 | + val = dev->min_timeout; |
|---|
| 558 | 540 | break; |
|---|
| 559 | 541 | |
|---|
| 560 | 542 | case LIRC_GET_MAX_TIMEOUT: |
|---|
| 561 | 543 | if (!dev->max_timeout) |
|---|
| 562 | 544 | ret = -ENOTTY; |
|---|
| 563 | 545 | else |
|---|
| 564 | | - val = dev->max_timeout / 1000; |
|---|
| 546 | + val = dev->max_timeout; |
|---|
| 565 | 547 | break; |
|---|
| 566 | 548 | |
|---|
| 567 | 549 | case LIRC_SET_REC_TIMEOUT: |
|---|
| 568 | 550 | if (!dev->max_timeout) { |
|---|
| 569 | 551 | ret = -ENOTTY; |
|---|
| 570 | | - } else if (val > U32_MAX / 1000) { |
|---|
| 571 | | - /* Check for multiply overflow */ |
|---|
| 572 | | - ret = -EINVAL; |
|---|
| 573 | 552 | } 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) |
|---|
| 577 | 554 | ret = -EINVAL; |
|---|
| 578 | 555 | else if (dev->s_timeout) |
|---|
| 579 | | - ret = dev->s_timeout(dev, tmp); |
|---|
| 556 | + ret = dev->s_timeout(dev, val); |
|---|
| 580 | 557 | else |
|---|
| 581 | | - dev->timeout = tmp; |
|---|
| 558 | + dev->timeout = val; |
|---|
| 582 | 559 | } |
|---|
| 583 | 560 | break; |
|---|
| 584 | 561 | |
|---|
| .. | .. |
|---|
| 586 | 563 | if (!dev->timeout) |
|---|
| 587 | 564 | ret = -ENOTTY; |
|---|
| 588 | 565 | else |
|---|
| 589 | | - val = DIV_ROUND_UP(dev->timeout, 1000); |
|---|
| 566 | + val = dev->timeout; |
|---|
| 590 | 567 | break; |
|---|
| 591 | 568 | |
|---|
| 592 | 569 | case LIRC_SET_REC_TIMEOUT_REPORTS: |
|---|
| .. | .. |
|---|
| 608 | 585 | return ret; |
|---|
| 609 | 586 | } |
|---|
| 610 | 587 | |
|---|
| 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) |
|---|
| 612 | 589 | { |
|---|
| 613 | 590 | struct lirc_fh *fh = file->private_data; |
|---|
| 614 | 591 | struct rc_dev *rcdev = fh->rc; |
|---|
| .. | .. |
|---|
| 631 | 608 | return events; |
|---|
| 632 | 609 | } |
|---|
| 633 | 610 | |
|---|
| 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) |
|---|
| 636 | 613 | { |
|---|
| 637 | 614 | struct lirc_fh *fh = file->private_data; |
|---|
| 638 | 615 | struct rc_dev *rcdev = fh->rc; |
|---|
| .. | .. |
|---|
| 669 | 646 | return copied; |
|---|
| 670 | 647 | } |
|---|
| 671 | 648 | |
|---|
| 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) |
|---|
| 674 | 651 | { |
|---|
| 675 | 652 | struct lirc_fh *fh = file->private_data; |
|---|
| 676 | 653 | struct rc_dev *rcdev = fh->rc; |
|---|
| .. | .. |
|---|
| 708 | 685 | return copied; |
|---|
| 709 | 686 | } |
|---|
| 710 | 687 | |
|---|
| 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) |
|---|
| 713 | 690 | { |
|---|
| 714 | 691 | struct lirc_fh *fh = file->private_data; |
|---|
| 715 | 692 | struct rc_dev *rcdev = fh->rc; |
|---|
| .. | .. |
|---|
| 721 | 698 | return -ENODEV; |
|---|
| 722 | 699 | |
|---|
| 723 | 700 | if (fh->rec_mode == LIRC_MODE_MODE2) |
|---|
| 724 | | - return ir_lirc_read_mode2(file, buffer, length); |
|---|
| 701 | + return lirc_read_mode2(file, buffer, length); |
|---|
| 725 | 702 | else /* LIRC_MODE_SCANCODE */ |
|---|
| 726 | | - return ir_lirc_read_scancode(file, buffer, length); |
|---|
| 703 | + return lirc_read_scancode(file, buffer, length); |
|---|
| 727 | 704 | } |
|---|
| 728 | 705 | |
|---|
| 729 | 706 | static const struct file_operations lirc_fops = { |
|---|
| 730 | 707 | .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, |
|---|
| 740 | 715 | .llseek = no_llseek, |
|---|
| 741 | 716 | }; |
|---|
| 742 | 717 | |
|---|
| .. | .. |
|---|
| 747 | 722 | put_device(&rcdev->dev); |
|---|
| 748 | 723 | } |
|---|
| 749 | 724 | |
|---|
| 750 | | -int ir_lirc_register(struct rc_dev *dev) |
|---|
| 725 | +int lirc_register(struct rc_dev *dev) |
|---|
| 751 | 726 | { |
|---|
| 752 | 727 | const char *rx_type, *tx_type; |
|---|
| 753 | 728 | int err, minor; |
|---|
| .. | .. |
|---|
| 801 | 776 | return err; |
|---|
| 802 | 777 | } |
|---|
| 803 | 778 | |
|---|
| 804 | | -void ir_lirc_unregister(struct rc_dev *dev) |
|---|
| 779 | +void lirc_unregister(struct rc_dev *dev) |
|---|
| 805 | 780 | { |
|---|
| 806 | 781 | unsigned long flags; |
|---|
| 807 | 782 | struct lirc_fh *fh; |
|---|
| .. | .. |
|---|
| 828 | 803 | return PTR_ERR(lirc_class); |
|---|
| 829 | 804 | } |
|---|
| 830 | 805 | |
|---|
| 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"); |
|---|
| 833 | 807 | if (retval) { |
|---|
| 834 | 808 | class_destroy(lirc_class); |
|---|
| 835 | 809 | pr_err("alloc_chrdev_region failed\n"); |
|---|