@@ -88,6 +88,21 @@ void ir_lirc_raw_event(struct rc_dev *dev, struct ir_raw_event ev)
8888 wake_up_poll (& dev -> wait_poll , POLLIN | POLLRDNORM );
8989}
9090
91+ /**
92+ * ir_lirc_scancode_event() - Send scancode data to lirc to be relayed to
93+ * userspace
94+ * @dev: the struct rc_dev descriptor of the device
95+ * @lsc: the struct lirc_scancode describing the decoded scancode
96+ */
97+ void ir_lirc_scancode_event (struct rc_dev * dev , struct lirc_scancode * lsc )
98+ {
99+ lsc -> timestamp = ktime_get_ns ();
100+
101+ if (kfifo_put (& dev -> scancodes , * lsc ))
102+ wake_up_poll (& dev -> wait_poll , POLLIN | POLLRDNORM );
103+ }
104+ EXPORT_SYMBOL_GPL (ir_lirc_scancode_event );
105+
91106static int ir_lirc_open (struct inode * inode , struct file * file )
92107{
93108 struct rc_dev * dev = container_of (inode -> i_cdev , struct rc_dev ,
@@ -114,6 +129,8 @@ static int ir_lirc_open(struct inode *inode, struct file *file)
114129
115130 if (dev -> driver_type == RC_DRIVER_IR_RAW )
116131 kfifo_reset_out (& dev -> rawir );
132+ if (dev -> driver_type != RC_DRIVER_IR_RAW_TX )
133+ kfifo_reset_out (& dev -> scancodes );
117134
118135 dev -> lirc_open ++ ;
119136 file -> private_data = dev ;
@@ -288,7 +305,7 @@ static long ir_lirc_ioctl(struct file *filep, unsigned int cmd,
288305 switch (cmd ) {
289306 case LIRC_GET_FEATURES :
290307 if (dev -> driver_type == RC_DRIVER_IR_RAW ) {
291- val |= LIRC_CAN_REC_MODE2 ;
308+ val |= LIRC_CAN_REC_MODE2 | LIRC_CAN_REC_SCANCODE ;
292309 if (dev -> rx_resolution )
293310 val |= LIRC_CAN_GET_REC_RESOLUTION ;
294311 }
@@ -323,15 +340,17 @@ static long ir_lirc_ioctl(struct file *filep, unsigned int cmd,
323340 if (dev -> driver_type == RC_DRIVER_IR_RAW_TX )
324341 return - ENOTTY ;
325342
326- val = LIRC_MODE_MODE2 ;
343+ val = dev -> rec_mode ;
327344 break ;
328345
329346 case LIRC_SET_REC_MODE :
330347 if (dev -> driver_type == RC_DRIVER_IR_RAW_TX )
331348 return - ENOTTY ;
332349
333- if (val != LIRC_MODE_MODE2 )
350+ if (!( val == LIRC_MODE_MODE2 || val == LIRC_MODE_SCANCODE ) )
334351 return - EINVAL ;
352+
353+ dev -> rec_mode = val ;
335354 return 0 ;
336355
337356 case LIRC_GET_SEND_MODE :
@@ -471,31 +490,31 @@ static unsigned int ir_lirc_poll(struct file *file,
471490
472491 poll_wait (file , & rcdev -> wait_poll , wait );
473492
474- if (!rcdev -> registered )
493+ if (!rcdev -> registered ) {
475494 events = POLLHUP | POLLERR ;
476- else if (rcdev -> driver_type == RC_DRIVER_IR_RAW &&
477- !kfifo_is_empty (& rcdev -> rawir ))
478- events = POLLIN | POLLRDNORM ;
495+ } else if (rcdev -> driver_type != RC_DRIVER_IR_RAW_TX ) {
496+ if (rcdev -> rec_mode == LIRC_MODE_SCANCODE &&
497+ !kfifo_is_empty (& rcdev -> scancodes ))
498+ events = POLLIN | POLLRDNORM ;
499+
500+ if (rcdev -> rec_mode == LIRC_MODE_MODE2 &&
501+ !kfifo_is_empty (& rcdev -> rawir ))
502+ events = POLLIN | POLLRDNORM ;
503+ }
479504
480505 return events ;
481506}
482507
483- static ssize_t ir_lirc_read (struct file * file , char __user * buffer ,
484- size_t length , loff_t * ppos )
508+ static ssize_t ir_lirc_read_mode2 (struct file * file , char __user * buffer ,
509+ size_t length )
485510{
486511 struct rc_dev * rcdev = file -> private_data ;
487512 unsigned int copied ;
488513 int ret ;
489514
490- if (rcdev -> driver_type == RC_DRIVER_IR_RAW_TX )
491- return - EINVAL ;
492-
493515 if (length < sizeof (unsigned int ) || length % sizeof (unsigned int ))
494516 return - EINVAL ;
495517
496- if (!rcdev -> registered )
497- return - ENODEV ;
498-
499518 do {
500519 if (kfifo_is_empty (& rcdev -> rawir )) {
501520 if (file -> f_flags & O_NONBLOCK )
@@ -523,6 +542,61 @@ static ssize_t ir_lirc_read(struct file *file, char __user *buffer,
523542 return copied ;
524543}
525544
545+ static ssize_t ir_lirc_read_scancode (struct file * file , char __user * buffer ,
546+ size_t length )
547+ {
548+ struct rc_dev * rcdev = file -> private_data ;
549+ unsigned int copied ;
550+ int ret ;
551+
552+ if (length < sizeof (struct lirc_scancode ) ||
553+ length % sizeof (struct lirc_scancode ))
554+ return - EINVAL ;
555+
556+ do {
557+ if (kfifo_is_empty (& rcdev -> scancodes )) {
558+ if (file -> f_flags & O_NONBLOCK )
559+ return - EAGAIN ;
560+
561+ ret = wait_event_interruptible (rcdev -> wait_poll ,
562+ !kfifo_is_empty (& rcdev -> scancodes ) ||
563+ !rcdev -> registered );
564+ if (ret )
565+ return ret ;
566+ }
567+
568+ if (!rcdev -> registered )
569+ return - ENODEV ;
570+
571+ ret = mutex_lock_interruptible (& rcdev -> lock );
572+ if (ret )
573+ return ret ;
574+ ret = kfifo_to_user (& rcdev -> scancodes , buffer , length , & copied );
575+ mutex_unlock (& rcdev -> lock );
576+ if (ret )
577+ return ret ;
578+ } while (copied == 0 );
579+
580+ return copied ;
581+ }
582+
583+ static ssize_t ir_lirc_read (struct file * file , char __user * buffer ,
584+ size_t length , loff_t * ppos )
585+ {
586+ struct rc_dev * rcdev = file -> private_data ;
587+
588+ if (rcdev -> driver_type == RC_DRIVER_IR_RAW_TX )
589+ return - EINVAL ;
590+
591+ if (!rcdev -> registered )
592+ return - ENODEV ;
593+
594+ if (rcdev -> rec_mode == LIRC_MODE_MODE2 )
595+ return ir_lirc_read_mode2 (file , buffer , length );
596+ else /* LIRC_MODE_SCANCODE */
597+ return ir_lirc_read_scancode (file , buffer , length );
598+ }
599+
526600const struct file_operations lirc_fops = {
527601 .owner = THIS_MODULE ,
528602 .write = ir_lirc_transmit_ir ,
0 commit comments