This makes it possible for lircd to read from a lirc chardev, and not keep it busy. Note that this changes the default for timeout reports to on. lircd already enables timeout reports when it opens a lirc device, leaving them on until the next reboot.
Unified · Split
| @@ -28,7 +28,6 @@ · 27 unmodified lines | |||
| 28 | #include "rc-core-priv.h" | 28 | #include "rc-core-priv.h" |
| 29 | #include <uapi/linux/lirc.h> | 29 | #include <uapi/linux/lirc.h> |
| 30 | 30 | ||
| 31 | #define LOGHEAD "lirc_dev (%s[%d]): " | ||
| 32 | #define LIRCBUF_SIZE 256 | 31 | #define LIRCBUF_SIZE 256 |
| 33 | 32 | ||
| 34 | static dev_t lirc_base_dev; | 33 | static dev_t lirc_base_dev; |
| @@ -47,6 +46,8 @@ static struct class *lirc_class; · 12 unmodified lines | |||
| 47 | */ | 46 | */ |
| 48 | void ir_lirc_raw_event(struct rc_dev *dev, struct ir_raw_event ev) | 47 | void ir_lirc_raw_event(struct rc_dev *dev, struct ir_raw_event ev) |
| 49 | { | 48 | { |
| 49 | unsigned long flags; | ||
| 50 | struct lirc_fh *fh; | ||
| 50 | int sample; | 51 | int sample; |
| 51 | 52 | ||
| 52 | /* Packet start */ | 53 | /* Packet start */ |
| @@ -75,9 +76,6 @@ void ir_lirc_raw_event(struct rc_dev *dev, struct ir_raw_event ev) · 22 unmodified lines | |||
| 75 | dev->gap = true; | 76 | dev->gap = true; |
| 76 | dev->gap_duration = ev.duration; | 77 | dev->gap_duration = ev.duration; |
| 77 | 78 | ||
| 78 | if (!dev->send_timeout_reports) | ||
| 79 | return; | ||
| 80 | |||
| 81 | sample = LIRC_TIMEOUT(ev.duration / 1000); | 79 | sample = LIRC_TIMEOUT(ev.duration / 1000); |
| 82 | IR_dprintk(2, "timeout report (duration: %d)\n", sample); | 80 | IR_dprintk(2, "timeout report (duration: %d)\n", sample); |
| 83 | 81 | ||
| @@ -92,7 +90,11 @@ void ir_lirc_raw_event(struct rc_dev *dev, struct ir_raw_event ev) · 8 unmodified lines | |||
| 92 | dev->gap_duration = min_t(u64, dev->gap_duration, | 90 | dev->gap_duration = min_t(u64, dev->gap_duration, |
| 93 | LIRC_VALUE_MASK); | 91 | LIRC_VALUE_MASK); |
| 94 | 92 | ||
| 95 | kfifo_put(&dev->rawir, LIRC_SPACE(dev->gap_duration)); | 93 | spin_lock_irqsave(&dev->lirc_fh_lock, flags); |
| 94 | list_for_each_entry(fh, &dev->lirc_fh, list) | ||
| 95 | kfifo_put(&fh->rawir, | ||
| 96 | LIRC_SPACE(dev->gap_duration)); | ||
| 97 | spin_unlock_irqrestore(&dev->lirc_fh_lock, flags); | ||
| 96 | dev->gap = false; | 98 | dev->gap = false; |
| 97 | } | 99 | } |
| 98 | 100 | ||
| @@ -102,22 +104,35 @@ void ir_lirc_raw_event(struct rc_dev *dev, struct ir_raw_event ev) · 3 unmodified lines | |||
| 102 | TO_US(ev.duration), TO_STR(ev.pulse)); | 104 | TO_US(ev.duration), TO_STR(ev.pulse)); |
| 103 | } | 105 | } |
| 104 | 106 | ||
| 105 | kfifo_put(&dev->rawir, sample); | 107 | spin_lock_irqsave(&dev->lirc_fh_lock, flags); |
| 106 | wake_up_poll(&dev->wait_poll, POLLIN | POLLRDNORM); | 108 | list_for_each_entry(fh, &dev->lirc_fh, list) { |
| 109 | if (LIRC_IS_TIMEOUT(sample) && !fh->send_timeout_reports) | ||
| 110 | continue; | ||
| 111 | if (kfifo_put(&fh->rawir, sample)) | ||
| 112 | wake_up_poll(&fh->wait_poll, POLLIN | POLLRDNORM); | ||
| 113 | } | ||
| 114 | spin_unlock_irqrestore(&dev->lirc_fh_lock, flags); | ||
| 107 | } | 115 | } |
| 108 | 116 | ||
| 109 | /** | 117 | /** |
| 110 | * ir_lirc_scancode_event() - Send scancode data to lirc to be relayed to | 118 | * ir_lirc_scancode_event() - Send scancode data to lirc to be relayed to |
| 111 | * userspace | 119 | * userspace. This can be called in atomic context. |
| 112 | * @dev: the struct rc_dev descriptor of the device | 120 | * @dev: the struct rc_dev descriptor of the device |
| 113 | * @lsc: the struct lirc_scancode describing the decoded scancode | 121 | * @lsc: the struct lirc_scancode describing the decoded scancode |
| 114 | */ | 122 | */ |
| 115 | void ir_lirc_scancode_event(struct rc_dev *dev, struct lirc_scancode *lsc) | 123 | void ir_lirc_scancode_event(struct rc_dev *dev, struct lirc_scancode *lsc) |
| 116 | { | 124 | { |
| 125 | unsigned long flags; | ||
| 126 | struct lirc_fh *fh; | ||
| 127 | |||
| 117 | lsc->timestamp = ktime_get_ns(); | 128 | lsc->timestamp = ktime_get_ns(); |
| 118 | 129 | ||
| 119 | if (kfifo_put(&dev->scancodes, *lsc)) | 130 | spin_lock_irqsave(&dev->lirc_fh_lock, flags); |
| 120 | wake_up_poll(&dev->wait_poll, POLLIN | POLLRDNORM); | 131 | list_for_each_entry(fh, &dev->lirc_fh, list) { |
| 132 | if (kfifo_put(&fh->scancodes, *lsc)) | ||
| 133 | wake_up_poll(&fh->wait_poll, POLLIN | POLLRDNORM); | ||
| 134 | } | ||
| 135 | spin_unlock_irqrestore(&dev->lirc_fh_lock, flags); | ||
| 121 | } | 136 | } |
| 122 | EXPORT_SYMBOL_GPL(ir_lirc_scancode_event); | 137 | EXPORT_SYMBOL_GPL(ir_lirc_scancode_event); |
| 123 | 138 | ||
| @@ -125,55 +140,88 @@ static int ir_lirc_open(struct inode *inode, struct file *file) · 1 unmodified line | |||
| 125 | { | 140 | { |
| 126 | struct rc_dev *dev = container_of(inode->i_cdev, struct rc_dev, | 141 | struct rc_dev *dev = container_of(inode->i_cdev, struct rc_dev, |
| 127 | lirc_cdev); | 142 | lirc_cdev); |
| 143 | struct lirc_fh *fh = kzalloc(sizeof(*fh), GFP_KERNEL); | ||
| 144 | unsigned long flags; | ||
| 128 | int retval; | 145 | int retval; |
| 129 | 146 | ||
| 130 | retval = rc_open(dev); | 147 | if (!fh) |
| 131 | if (retval) | 148 | return -ENOMEM; |
| 132 | return retval; | ||
| 133 | 149 | ||
| 134 | retval = mutex_lock_interruptible(&dev->lock); | 150 | get_device(&dev->dev); |
| 135 | if (retval) | ||
| 136 | goto out_rc; | ||
| 137 | 151 | ||
| 138 | if (!dev->registered) { | 152 | if (!dev->registered) { |
| 139 | retval = -ENODEV; | 153 | retval = -ENODEV; |
| 140 | goto out_unlock; | 154 | goto out_fh; |
| 141 | } | 155 | } |
| 142 | 156 | ||
| 143 | if (dev->lirc_open) { | 157 | if (dev->driver_type == RC_DRIVER_IR_RAW) { |
| 144 | retval = -EBUSY; | 158 | if (kfifo_alloc(&fh->rawir, MAX_IR_EVENT_SIZE, GFP_KERNEL)) { |
| 145 | goto out_unlock; | 159 | retval = -ENOMEM; |
| 160 | goto out_fh; | ||
| 161 | } | ||
| 146 | } | 162 | } |
| 147 | 163 | ||
| 148 | if (dev->driver_type == RC_DRIVER_IR_RAW) | 164 | if (dev->driver_type != RC_DRIVER_IR_RAW_TX) { |
| 149 | kfifo_reset_out(&dev->rawir); | 165 | if (kfifo_alloc(&fh->scancodes, 32, GFP_KERNEL)) { |
| 150 | if (dev->driver_type != RC_DRIVER_IR_RAW_TX) | 166 | retval = -ENOMEM; |
| 151 | kfifo_reset_out(&dev->scancodes); | 167 | goto out_rawir; |
| 168 | } | ||
| 169 | } | ||
| 170 | |||
| 171 | fh->send_mode = LIRC_MODE_PULSE; | ||
| 172 | fh->rc = dev; | ||
| 173 | fh->send_timeout_reports = true; | ||
| 174 | |||
| 175 | if (dev->driver_type == RC_DRIVER_SCANCODE) | ||
| 176 | fh->rec_mode = LIRC_MODE_SCANCODE; | ||
| 177 | else | ||
| 178 | fh->rec_mode = LIRC_MODE_MODE2; | ||
| 179 | |||
| 180 | retval = rc_open(dev); | ||
| 181 | if (retval) | ||
| 182 | goto out_kfifo; | ||
| 183 | |||
| 184 | init_waitqueue_head(&fh->wait_poll); | ||
| 152 | 185 | ||
| 153 | dev->lirc_open++; | 186 | file->private_data = fh; |
| 154 | file->private_data = dev; | 187 | spin_lock_irqsave(&dev->lirc_fh_lock, flags); |
| 188 | list_add(&fh->list, &dev->lirc_fh); | ||
| 189 | spin_unlock_irqrestore(&dev->lirc_fh_lock, flags); | ||
| 155 | 190 | ||
| 156 | nonseekable_open(inode, file); | 191 | nonseekable_open(inode, file); |
| 157 | mutex_unlock(&dev->lock); | ||
| 158 | 192 | ||
| 159 | return 0; | 193 | return 0; |
| 194 | out_kfifo: | ||
| 195 | if (dev->driver_type != RC_DRIVER_IR_RAW_TX) | ||
| 196 | kfifo_free(&fh->scancodes); | ||
| 197 | out_rawir: | ||
| 198 | if (dev->driver_type == RC_DRIVER_IR_RAW) | ||
| 199 | kfifo_free(&fh->rawir); | ||
| 200 | out_fh: | ||
| 201 | kfree(fh); | ||
| 202 | put_device(&dev->dev); | ||
| 160 | 203 | ||
| 161 | out_unlock: | ||
| 162 | mutex_unlock(&dev->lock); | ||
| 163 | out_rc: | ||
| 164 | rc_close(dev); | ||
| 165 | return retval; | 204 | return retval; |
| 166 | } | 205 | } |
| 167 | 206 | ||
| 168 | static int ir_lirc_close(struct inode *inode, struct file *file) | 207 | static int ir_lirc_close(struct inode *inode, struct file *file) |
| 169 | { | 208 | { |
| 170 | struct rc_dev *dev = file->private_data; | 209 | struct lirc_fh *fh = file->private_data; |
| 210 | struct rc_dev *dev = fh->rc; | ||
| 211 | unsigned long flags; | ||
| 171 | 212 | ||
| 172 | mutex_lock(&dev->lock); | 213 | spin_lock_irqsave(&dev->lirc_fh_lock, flags); |
| 173 | dev->lirc_open--; | 214 | list_del(&fh->list); |
| 174 | mutex_unlock(&dev->lock); | 215 | spin_unlock_irqrestore(&dev->lirc_fh_lock, flags); |
| 216 | |||
| 217 | if (dev->driver_type == RC_DRIVER_IR_RAW) | ||
| 218 | kfifo_free(&fh->rawir); | ||
| 219 | if (dev->driver_type != RC_DRIVER_IR_RAW_TX) | ||
| 220 | kfifo_free(&fh->scancodes); | ||
| 221 | kfree(fh); | ||
| 175 | 222 | ||
| 176 | rc_close(dev); | 223 | rc_close(dev); |
| 224 | put_device(&dev->dev); | ||
| 177 | 225 | ||
| 178 | return 0; | 226 | return 0; |
| 179 | } | 227 | } |
| @@ -181,7 +229,8 @@ static int ir_lirc_close(struct inode *inode, struct file *file) · 1 unmodified line | |||
| 181 | static ssize_t ir_lirc_transmit_ir(struct file *file, const char __user *buf, | 229 | static ssize_t ir_lirc_transmit_ir(struct file *file, const char __user *buf, |
| 182 | size_t n, loff_t *ppos) | 230 | size_t n, loff_t *ppos) |
| 183 | { | 231 | { |
| 184 | struct rc_dev *dev = file->private_data; | 232 | struct lirc_fh *fh = file->private_data; |
| 233 | struct rc_dev *dev = fh->rc; | ||
| 185 | unsigned int *txbuf = NULL; | 234 | unsigned int *txbuf = NULL; |
| 186 | struct ir_raw_event *raw = NULL; | 235 | struct ir_raw_event *raw = NULL; |
| 187 | ssize_t ret = -EINVAL; | 236 | ssize_t ret = -EINVAL; |
| @@ -201,7 +250,7 @@ static ssize_t ir_lirc_transmit_ir(struct file *file, const char __user *buf, · 13 unmodified lines | |||
| 201 | goto out; | 250 | goto out; |
| 202 | } | 251 | } |
| 203 | 252 | ||
| 204 | if (dev->send_mode == LIRC_MODE_SCANCODE) { | 253 | if (fh->send_mode == LIRC_MODE_SCANCODE) { |
| 205 | struct lirc_scancode scan; | 254 | struct lirc_scancode scan; |
| 206 | 255 | ||
| 207 | if (n != sizeof(scan)) | 256 | if (n != sizeof(scan)) |
| @@ -276,7 +325,7 @@ static ssize_t ir_lirc_transmit_ir(struct file *file, const char __user *buf, · 68 unmodified lines | |||
| 276 | if (ret < 0) | 325 | if (ret < 0) |
| 277 | goto out; | 326 | goto out; |
| 278 | 327 | ||
| 279 | if (dev->send_mode == LIRC_MODE_SCANCODE) { | 328 | if (fh->send_mode == LIRC_MODE_SCANCODE) { |
| 280 | ret = n; | 329 | ret = n; |
| 281 | } else { | 330 | } else { |
| 282 | for (duration = i = 0; i < ret; i++) | 331 | for (duration = i = 0; i < ret; i++) |
| @@ -303,10 +352,11 @@ out: · 20 unmodified lines | |||
| 303 | return ret; | 352 | return ret; |
| 304 | } | 353 | } |
| 305 | 354 | ||
| 306 | static long ir_lirc_ioctl(struct file *filep, unsigned int cmd, | 355 | static long ir_lirc_ioctl(struct file *file, unsigned int cmd, |
| 307 | unsigned long arg) | 356 | unsigned long arg) |
| 308 | { | 357 | { |
| 309 | struct rc_dev *dev = filep->private_data; | 358 | struct lirc_fh *fh = file->private_data; |
| 359 | struct rc_dev *dev = fh->rc; | ||
| 310 | u32 __user *argp = (u32 __user *)(arg); | 360 | u32 __user *argp = (u32 __user *)(arg); |
| 311 | int ret = 0; | 361 | int ret = 0; |
| 312 | __u32 val = 0, tmp; | 362 | __u32 val = 0, tmp; |
| @@ -361,7 +411,7 @@ static long ir_lirc_ioctl(struct file *filep, unsigned int cmd, · 48 unmodified lines | |||
| 361 | if (dev->driver_type == RC_DRIVER_IR_RAW_TX) | 411 | if (dev->driver_type == RC_DRIVER_IR_RAW_TX) |
| 362 | return -ENOTTY; | 412 | return -ENOTTY; |
| 363 | 413 | ||
| 364 | val = dev->rec_mode; | 414 | val = fh->rec_mode; |
| 365 | break; | 415 | break; |
| 366 | 416 | ||
| 367 | case LIRC_SET_REC_MODE: | 417 | case LIRC_SET_REC_MODE: |
| @@ -379,14 +429,14 @@ static long ir_lirc_ioctl(struct file *filep, unsigned int cmd, · 11 unmodified lines | |||
| 379 | break; | 429 | break; |
| 380 | } | 430 | } |
| 381 | 431 | ||
| 382 | dev->rec_mode = val; | 432 | fh->rec_mode = val; |
| 383 | return 0; | 433 | return 0; |
| 384 | 434 | ||
| 385 | case LIRC_GET_SEND_MODE: | 435 | case LIRC_GET_SEND_MODE: |
| 386 | if (!dev->tx_ir) | 436 | if (!dev->tx_ir) |
| 387 | return -ENOTTY; | 437 | return -ENOTTY; |
| 388 | 438 | ||
| 389 | val = dev->send_mode; | 439 | val = fh->send_mode; |
| 390 | break; | 440 | break; |
| 391 | 441 | ||
| 392 | case LIRC_SET_SEND_MODE: | 442 | case LIRC_SET_SEND_MODE: |
| @@ -396,7 +446,7 @@ static long ir_lirc_ioctl(struct file *filep, unsigned int cmd, · 3 unmodified lines | |||
| 396 | if (!(val == LIRC_MODE_PULSE || val == LIRC_MODE_SCANCODE)) | 446 | if (!(val == LIRC_MODE_PULSE || val == LIRC_MODE_SCANCODE)) |
| 397 | return -EINVAL; | 447 | return -EINVAL; |
| 398 | 448 | ||
| 399 | dev->send_mode = val; | 449 | fh->send_mode = val; |
| 400 | return 0; | 450 | return 0; |
| 401 | 451 | ||
| 402 | /* TX settings */ | 452 | /* TX settings */ |
| @@ -430,7 +480,7 @@ static long ir_lirc_ioctl(struct file *filep, unsigned int cmd, · 27 unmodified lines | |||
| 430 | return -EINVAL; | 480 | return -EINVAL; |
| 431 | 481 | ||
| 432 | return dev->s_rx_carrier_range(dev, | 482 | return dev->s_rx_carrier_range(dev, |
| 433 | dev->carrier_low, | 483 | fh->carrier_low, |
| 434 | val); | 484 | val); |
| 435 | 485 | ||
| 436 | case LIRC_SET_REC_CARRIER_RANGE: | 486 | case LIRC_SET_REC_CARRIER_RANGE: |
| @@ -440,7 +490,7 @@ static long ir_lirc_ioctl(struct file *filep, unsigned int cmd, · 3 unmodified lines | |||
| 440 | if (val <= 0) | 490 | if (val <= 0) |
| 441 | return -EINVAL; | 491 | return -EINVAL; |
| 442 | 492 | ||
| 443 | dev->carrier_low = val; | 493 | fh->carrier_low = val; |
| 444 | return 0; | 494 | return 0; |
| 445 | 495 | ||
| 446 | case LIRC_GET_REC_RESOLUTION: | 496 | case LIRC_GET_REC_RESOLUTION: |
| @@ -498,7 +548,7 @@ static long ir_lirc_ioctl(struct file *filep, unsigned int cmd, · 51 unmodified lines | |||
| 498 | if (!dev->timeout) | 548 | if (!dev->timeout) |
| 499 | return -ENOTTY; | 549 | return -ENOTTY; |
| 500 | 550 | ||
| 501 | dev->send_timeout_reports = !!val; | 551 | fh->send_timeout_reports = !!val; |
| 502 | break; | 552 | break; |
| 503 | 553 | ||
| 504 | default: | 554 | default: |
| @@ -514,20 +564,21 @@ static long ir_lirc_ioctl(struct file *filep, unsigned int cmd, · 9 unmodified lines | |||
| 514 | static unsigned int ir_lirc_poll(struct file *file, | 564 | static unsigned int ir_lirc_poll(struct file *file, |
| 515 | struct poll_table_struct *wait) | 565 | struct poll_table_struct *wait) |
| 516 | { | 566 | { |
| 517 | struct rc_dev *rcdev = file->private_data; | 567 | struct lirc_fh *fh = file->private_data; |
| 568 | struct rc_dev *rcdev = fh->rc; | ||
| 518 | unsigned int events = 0; | 569 | unsigned int events = 0; |
| 519 | 570 | ||
| 520 | poll_wait(file, &rcdev->wait_poll, wait); | 571 | poll_wait(file, &fh->wait_poll, wait); |
| 521 | 572 | ||
| 522 | if (!rcdev->registered) { | 573 | if (!rcdev->registered) { |
| 523 | events = POLLHUP | POLLERR; | 574 | events = POLLHUP | POLLERR; |
| 524 | } else if (rcdev->driver_type != RC_DRIVER_IR_RAW_TX) { | 575 | } else if (rcdev->driver_type != RC_DRIVER_IR_RAW_TX) { |
| 525 | if (rcdev->rec_mode == LIRC_MODE_SCANCODE && | 576 | if (fh->rec_mode == LIRC_MODE_SCANCODE && |
| 526 | !kfifo_is_empty(&rcdev->scancodes)) | 577 | !kfifo_is_empty(&fh->scancodes)) |
| 527 | events = POLLIN | POLLRDNORM; | 578 | events = POLLIN | POLLRDNORM; |
| 528 | 579 | ||
| 529 | if (rcdev->rec_mode == LIRC_MODE_MODE2 && | 580 | if (fh->rec_mode == LIRC_MODE_MODE2 && |
| 530 | !kfifo_is_empty(&rcdev->rawir)) | 581 | !kfifo_is_empty(&fh->rawir)) |
| 531 | events = POLLIN | POLLRDNORM; | 582 | events = POLLIN | POLLRDNORM; |
| 532 | } | 583 | } |
| 533 | 584 | ||
| @@ -537,7 +588,8 @@ static unsigned int ir_lirc_poll(struct file *file, · 3 unmodified lines | |||
| 537 | static ssize_t ir_lirc_read_mode2(struct file *file, char __user *buffer, | 588 | static ssize_t ir_lirc_read_mode2(struct file *file, char __user *buffer, |
| 538 | size_t length) | 589 | size_t length) |
| 539 | { | 590 | { |
| 540 | struct rc_dev *rcdev = file->private_data; | 591 | struct lirc_fh *fh = file->private_data; |
| 592 | struct rc_dev *rcdev = fh->rc; | ||
| 541 | unsigned int copied; | 593 | unsigned int copied; |
| 542 | int ret; | 594 | int ret; |
| 543 | 595 | ||
| @@ -545,12 +597,12 @@ static ssize_t ir_lirc_read_mode2(struct file *file, char __user *buffer, · 1 unmodified line | |||
| 545 | return -EINVAL; | 597 | return -EINVAL; |
| 546 | 598 | ||
| 547 | do { | 599 | do { |
| 548 | if (kfifo_is_empty(&rcdev->rawir)) { | 600 | if (kfifo_is_empty(&fh->rawir)) { |
| 549 | if (file->f_flags & O_NONBLOCK) | 601 | if (file->f_flags & O_NONBLOCK) |
| 550 | return -EAGAIN; | 602 | return -EAGAIN; |
| 551 | 603 | ||
| 552 | ret = wait_event_interruptible(rcdev->wait_poll, | 604 | ret = wait_event_interruptible(fh->wait_poll, |
| 553 | !kfifo_is_empty(&rcdev->rawir) || | 605 | !kfifo_is_empty(&fh->rawir) || |
| 554 | !rcdev->registered); | 606 | !rcdev->registered); |
| 555 | if (ret) | 607 | if (ret) |
| 556 | return ret; | 608 | return ret; |
| @@ -562,7 +614,7 @@ static ssize_t ir_lirc_read_mode2(struct file *file, char __user *buffer, · 5 unmodified lines | |||
| 562 | ret = mutex_lock_interruptible(&rcdev->lock); | 614 | ret = mutex_lock_interruptible(&rcdev->lock); |
| 563 | if (ret) | 615 | if (ret) |
| 564 | return ret; | 616 | return ret; |
| 565 | ret = kfifo_to_user(&rcdev->rawir, buffer, length, &copied); | 617 | ret = kfifo_to_user(&fh->rawir, buffer, length, &copied); |
| 566 | mutex_unlock(&rcdev->lock); | 618 | mutex_unlock(&rcdev->lock); |
| 567 | if (ret) | 619 | if (ret) |
| 568 | return ret; | 620 | return ret; |
| @@ -574,7 +626,8 @@ static ssize_t ir_lirc_read_mode2(struct file *file, char __user *buffer, · 5 unmodified lines | |||
| 574 | static ssize_t ir_lirc_read_scancode(struct file *file, char __user *buffer, | 626 | static ssize_t ir_lirc_read_scancode(struct file *file, char __user *buffer, |
| 575 | size_t length) | 627 | size_t length) |
| 576 | { | 628 | { |
| 577 | struct rc_dev *rcdev = file->private_data; | 629 | struct lirc_fh *fh = file->private_data; |
| 630 | struct rc_dev *rcdev = fh->rc; | ||
| 578 | unsigned int copied; | 631 | unsigned int copied; |
| 579 | int ret; | 632 | int ret; |
| 580 | 633 | ||
| @@ -583,12 +636,12 @@ static ssize_t ir_lirc_read_scancode(struct file *file, char __user *buffer, · 2 unmodified lines | |||
| 583 | return -EINVAL; | 636 | return -EINVAL; |
| 584 | 637 | ||
| 585 | do { | 638 | do { |
| 586 | if (kfifo_is_empty(&rcdev->scancodes)) { | 639 | if (kfifo_is_empty(&fh->scancodes)) { |
| 587 | if (file->f_flags & O_NONBLOCK) | 640 | if (file->f_flags & O_NONBLOCK) |
| 588 | return -EAGAIN; | 641 | return -EAGAIN; |
| 589 | 642 | ||
| 590 | ret = wait_event_interruptible(rcdev->wait_poll, | 643 | ret = wait_event_interruptible(fh->wait_poll, |
| 591 | !kfifo_is_empty(&rcdev->scancodes) || | 644 | !kfifo_is_empty(&fh->scancodes) || |
| 592 | !rcdev->registered); | 645 | !rcdev->registered); |
| 593 | if (ret) | 646 | if (ret) |
| 594 | return ret; | 647 | return ret; |
| @@ -600,7 +653,7 @@ static ssize_t ir_lirc_read_scancode(struct file *file, char __user *buffer, · 5 unmodified lines | |||
| 600 | ret = mutex_lock_interruptible(&rcdev->lock); | 653 | ret = mutex_lock_interruptible(&rcdev->lock); |
| 601 | if (ret) | 654 | if (ret) |
| 602 | return ret; | 655 | return ret; |
| 603 | ret = kfifo_to_user(&rcdev->scancodes, buffer, length, &copied); | 656 | ret = kfifo_to_user(&fh->scancodes, buffer, length, &copied); |
| 604 | mutex_unlock(&rcdev->lock); | 657 | mutex_unlock(&rcdev->lock); |
| 605 | if (ret) | 658 | if (ret) |
| 606 | return ret; | 659 | return ret; |
| @@ -612,7 +665,8 @@ static ssize_t ir_lirc_read_scancode(struct file *file, char __user *buffer, · 5 unmodified lines | |||
| 612 | static ssize_t ir_lirc_read(struct file *file, char __user *buffer, | 665 | static ssize_t ir_lirc_read(struct file *file, char __user *buffer, |
| 613 | size_t length, loff_t *ppos) | 666 | size_t length, loff_t *ppos) |
| 614 | { | 667 | { |
| 615 | struct rc_dev *rcdev = file->private_data; | 668 | struct lirc_fh *fh = file->private_data; |
| 669 | struct rc_dev *rcdev = fh->rc; | ||
| 616 | 670 | ||
| 617 | if (rcdev->driver_type == RC_DRIVER_IR_RAW_TX) | 671 | if (rcdev->driver_type == RC_DRIVER_IR_RAW_TX) |
| 618 | return -EINVAL; | 672 | return -EINVAL; |
| @@ -620,7 +674,7 @@ static ssize_t ir_lirc_read(struct file *file, char __user *buffer, · 1 unmodified line | |||
| 620 | if (!rcdev->registered) | 674 | if (!rcdev->registered) |
| 621 | return -ENODEV; | 675 | return -ENODEV; |
| 622 | 676 | ||
| 623 | if (rcdev->rec_mode == LIRC_MODE_MODE2) | 677 | if (fh->rec_mode == LIRC_MODE_MODE2) |
| 624 | return ir_lirc_read_mode2(file, buffer, length); | 678 | return ir_lirc_read_mode2(file, buffer, length); |
| 625 | else /* LIRC_MODE_SCANCODE */ | 679 | else /* LIRC_MODE_SCANCODE */ |
| 626 | return ir_lirc_read_scancode(file, buffer, length); | 680 | return ir_lirc_read_scancode(file, buffer, length); |
| @@ -644,11 +698,6 @@ static void lirc_release_device(struct device *ld) · 17 unmodified lines | |||
| 644 | { | 698 | { |
| 645 | struct rc_dev *rcdev = container_of(ld, struct rc_dev, lirc_dev); | 699 | struct rc_dev *rcdev = container_of(ld, struct rc_dev, lirc_dev); |
| 646 | 700 | ||
| 647 | if (rcdev->driver_type == RC_DRIVER_IR_RAW) | ||
| 648 | kfifo_free(&rcdev->rawir); | ||
| 649 | if (rcdev->driver_type != RC_DRIVER_IR_RAW_TX) | ||
| 650 | kfifo_free(&rcdev->scancodes); | ||
| 651 | |||
| 652 | put_device(&rcdev->dev); | 701 | put_device(&rcdev->dev); |
| 653 | } | 702 | } |
| 654 | 703 | ||
| @@ -656,40 +705,20 @@ int ir_lirc_register(struct rc_dev *dev) · 1 unmodified line | |||
| 656 | { | 705 | { |
| 657 | int err, minor; | 706 | int err, minor; |
| 658 | 707 | ||
| 659 | device_initialize(&dev->lirc_dev); | ||
| 660 | dev->lirc_dev.class = lirc_class; | ||
| 661 | dev->lirc_dev.release = lirc_release_device; | ||
| 662 | dev->send_mode = LIRC_MODE_PULSE; | ||
| 663 | |||
| 664 | if (dev->driver_type == RC_DRIVER_SCANCODE) | ||
| 665 | dev->rec_mode = LIRC_MODE_SCANCODE; | ||
| 666 | else | ||
| 667 | dev->rec_mode = LIRC_MODE_MODE2; | ||
| 668 | |||
| 669 | if (dev->driver_type == RC_DRIVER_IR_RAW) { | ||
| 670 | if (kfifo_alloc(&dev->rawir, MAX_IR_EVENT_SIZE, GFP_KERNEL)) | ||
| 671 | return -ENOMEM; | ||
| 672 | } | ||
| 673 | |||
| 674 | if (dev->driver_type != RC_DRIVER_IR_RAW_TX) { | ||
| 675 | if (kfifo_alloc(&dev->scancodes, 32, GFP_KERNEL)) { | ||
| 676 | kfifo_free(&dev->rawir); | ||
| 677 | return -ENOMEM; | ||
| 678 | } | ||
| 679 | } | ||
| 680 | |||
| 681 | init_waitqueue_head(&dev->wait_poll); | ||
| 682 | |||
| 683 | minor = ida_simple_get(&lirc_ida, 0, RC_DEV_MAX, GFP_KERNEL); | 708 | minor = ida_simple_get(&lirc_ida, 0, RC_DEV_MAX, GFP_KERNEL); |
| 684 | if (minor < 0) { | 709 | if (minor < 0) |
| 685 | err = minor; | 710 | return minor; |
| 686 | goto out_kfifo; | ||
| 687 | } | ||
| 688 | 711 | ||
| 712 | device_initialize(&dev->lirc_dev); | ||
| 713 | dev->lirc_dev.class = lirc_class; | ||
| 689 | dev->lirc_dev.parent = &dev->dev; | 714 | dev->lirc_dev.parent = &dev->dev; |
| 715 | dev->lirc_dev.release = lirc_release_device; | ||
| 690 | dev->lirc_dev.devt = MKDEV(MAJOR(lirc_base_dev), minor); | 716 | dev->lirc_dev.devt = MKDEV(MAJOR(lirc_base_dev), minor); |
| 691 | dev_set_name(&dev->lirc_dev, "lirc%d", minor); | 717 | dev_set_name(&dev->lirc_dev, "lirc%d", minor); |
| 692 | 718 | ||
| 719 | INIT_LIST_HEAD(&dev->lirc_fh); | ||
| 720 | spin_lock_init(&dev->lirc_fh_lock); | ||
| 721 | |||
| 693 | cdev_init(&dev->lirc_cdev, &lirc_fops); | 722 | cdev_init(&dev->lirc_cdev, &lirc_fops); |
| 694 | 723 | ||
| 695 | err = cdev_device_add(&dev->lirc_cdev, &dev->lirc_dev); | 724 | err = cdev_device_add(&dev->lirc_cdev, &dev->lirc_dev); |
| @@ -705,32 +734,24 @@ int ir_lirc_register(struct rc_dev *dev) · 9 unmodified lines | |||
| 705 | 734 | ||
| 706 | out_ida: | 735 | out_ida: |
| 707 | ida_simple_remove(&lirc_ida, minor); | 736 | ida_simple_remove(&lirc_ida, minor); |
| 708 | out_kfifo: | ||
| 709 | if (dev->driver_type == RC_DRIVER_IR_RAW) | ||
| 710 | kfifo_free(&dev->rawir); | ||
| 711 | if (dev->driver_type != RC_DRIVER_IR_RAW_TX) | ||
| 712 | kfifo_free(&dev->scancodes); | ||
| 713 | return err; | 737 | return err; |
| 714 | } | 738 | } |
| 715 | 739 | ||
| 716 | void ir_lirc_unregister(struct rc_dev *dev) | 740 | void ir_lirc_unregister(struct rc_dev *dev) |
| 717 | { | 741 | { |
| 742 | unsigned long flags; | ||
| 743 | struct lirc_fh *fh; | ||
| 744 | |||
| 718 | dev_dbg(&dev->dev, "lirc_dev: driver %s unregistered from minor = %d\n", | 745 | dev_dbg(&dev->dev, "lirc_dev: driver %s unregistered from minor = %d\n", |
| 719 | dev->driver_name, MINOR(dev->lirc_dev.devt)); | 746 | dev->driver_name, MINOR(dev->lirc_dev.devt)); |
| 720 | 747 | ||
| 721 | mutex_lock(&dev->lock); | 748 | spin_lock_irqsave(&dev->lirc_fh_lock, flags); |
| 722 | 749 | list_for_each_entry(fh, &dev->lirc_fh, list) | |
| 723 | if (dev->lirc_open) { | 750 | wake_up_poll(&fh->wait_poll, POLLHUP | POLLERR); |
| 724 | dev_dbg(&dev->dev, LOGHEAD "releasing opened driver\n", | 751 | spin_unlock_irqrestore(&dev->lirc_fh_lock, flags); |
| 725 | dev->driver_name, MINOR(dev->lirc_dev.devt)); | ||
| 726 | wake_up_poll(&dev->wait_poll, POLLHUP); | ||
| 727 | } | ||
| 728 | |||
| 729 | mutex_unlock(&dev->lock); | ||
| 730 | 752 | ||
| 731 | cdev_device_del(&dev->lirc_cdev, &dev->lirc_dev); | 753 | cdev_device_del(&dev->lirc_cdev, &dev->lirc_dev); |
| 732 | ida_simple_remove(&lirc_ida, MINOR(dev->lirc_dev.devt)); | 754 | ida_simple_remove(&lirc_ida, MINOR(dev->lirc_dev.devt)); |
| 733 | put_device(&dev->lirc_dev); | ||
| 734 | } | 755 | } |
| 735 | 756 | ||
| 736 | int __init lirc_dev_init(void) | 757 | int __init lirc_dev_init(void) |
| @@ -68,6 +68,33 @@ enum rc_filter_type { · 67 unmodified lines | |||
| 68 | RC_FILTER_MAX | 68 | RC_FILTER_MAX |
| 69 | }; | 69 | }; |
| 70 | 70 | ||
| 71 | /** | ||
| 72 | * struct lirc_fh - represents an open lirc file | ||
| 73 | * @list: list of open file handles | ||
| 74 | * @rc: rcdev for this lirc chardev | ||
| 75 | * @carrier_low: when setting the carrier range, first the low end must be | ||
| 76 | * set with an ioctl and then the high end with another ioctl | ||
| 77 | * @send_timeout_reports: report timeouts in lirc raw IR. | ||
| 78 | * @rawir: queue for incoming raw IR | ||
| 79 | * @scancodes: queue for incoming decoded scancodes | ||
| 80 | * @wait_poll: poll struct for lirc device | ||
| 81 | * @send_mode: lirc mode for sending, either LIRC_MODE_SCANCODE or | ||
| 82 | * LIRC_MODE_PULSE | ||
| 83 | * @rec_mode: lirc mode for receiving, either LIRC_MODE_SCANCODE or | ||
| 84 | * LIRC_MODE_MODE2 | ||
| 85 | */ | ||
| 86 | struct lirc_fh { | ||
| 87 | struct list_head list; | ||
| 88 | struct rc_dev *rc; | ||
| 89 | int carrier_low; | ||
| 90 | bool send_timeout_reports; | ||
| 91 | DECLARE_KFIFO_PTR(rawir, unsigned int); | ||
| 92 | DECLARE_KFIFO_PTR(scancodes, struct lirc_scancode); | ||
| 93 | wait_queue_head_t wait_poll; | ||
| 94 | u8 send_mode; | ||
| 95 | u8 rec_mode; | ||
| 96 | }; | ||
| 97 | |||
| 71 | /** | 98 | /** |
| 72 | * struct rc_dev - represents a remote control device | 99 | * struct rc_dev - represents a remote control device |
| 73 | * @dev: driver model's view of this device | 100 | * @dev: driver model's view of this device |
| @@ -118,20 +145,11 @@ enum rc_filter_type { · 44 unmodified lines | |||
| 118 | * @tx_resolution: resolution (in ns) of output sampler | 145 | * @tx_resolution: resolution (in ns) of output sampler |
| 119 | * @lirc_dev: lirc device | 146 | * @lirc_dev: lirc device |
| 120 | * @lirc_cdev: lirc char cdev | 147 | * @lirc_cdev: lirc char cdev |
| 121 | * @lirc_open: count of the number of times the device has been opened | ||
| 122 | * @carrier_low: when setting the carrier range, first the low end must be | ||
| 123 | * set with an ioctl and then the high end with another ioctl | ||
| 124 | * @gap_start: time when gap starts | 148 | * @gap_start: time when gap starts |
| 125 | * @gap_duration: duration of initial gap | 149 | * @gap_duration: duration of initial gap |
| 126 | * @gap: true if we're in a gap | 150 | * @gap: true if we're in a gap |
| 127 | * @send_timeout_reports: report timeouts in lirc raw IR. | 151 | * @lirc_fh_lock: protects lirc_fh list |
| 128 | * @rawir: queue for incoming raw IR | 152 | * @lirc_fh: list of open files |
| 129 | * @scancodes: queue for incoming decoded scancodes | ||
| 130 | * @wait_poll: poll struct for lirc device | ||
| 131 | * @send_mode: lirc mode for sending, either LIRC_MODE_SCANCODE or | ||
| 132 | * LIRC_MODE_PULSE | ||
| 133 | * @rec_mode: lirc mode for receiving, either LIRC_MODE_SCANCODE or | ||
| 134 | * LIRC_MODE_MODE2 | ||
| 135 | * @registered: set to true by rc_register_device(), false by | 153 | * @registered: set to true by rc_register_device(), false by |
| 136 | * rc_unregister_device | 154 | * rc_unregister_device |
| 137 | * @change_protocol: allow changing the protocol used on hardware decoders | 155 | * @change_protocol: allow changing the protocol used on hardware decoders |
| @@ -196,17 +214,11 @@ struct rc_dev { · 58 unmodified lines | |||
| 196 | #ifdef CONFIG_LIRC | 214 | #ifdef CONFIG_LIRC |
| 197 | struct device lirc_dev; | 215 | struct device lirc_dev; |
| 198 | struct cdev lirc_cdev; | 216 | struct cdev lirc_cdev; |
| 199 | int lirc_open; | ||
| 200 | int carrier_low; | ||
| 201 | ktime_t gap_start; | 217 | ktime_t gap_start; |
| 202 | u64 gap_duration; | 218 | u64 gap_duration; |
| 203 | bool gap; | 219 | bool gap; |
| 204 | bool send_timeout_reports; | 220 | spinlock_t lirc_fh_lock; |
| 205 | DECLARE_KFIFO_PTR(rawir, unsigned int); | 221 | struct list_head lirc_fh; |
| 206 | DECLARE_KFIFO_PTR(scancodes, struct lirc_scancode); | ||
| 207 | wait_queue_head_t wait_poll; | ||
| 208 | u8 send_mode; | ||
| 209 | u8 rec_mode; | ||
| 210 | #endif | 222 | #endif |
| 211 | bool registered; | 223 | bool registered; |
| 212 | int (*change_protocol)(struct rc_dev *dev, u64 *rc_proto); | 224 | int (*change_protocol)(struct rc_dev *dev, u64 *rc_proto); |