1<html><head><meta http-equiv="Content-Type" content="text/html; charset=ANSI_X3.4-1968"><title>LIRC Device Interface</title><meta name="generator" content="DocBook XSL Stylesheets V1.78.1"><link rel="home" href="index.html" title="LINUX MEDIA INFRASTRUCTURE API"><link rel="up" href="remote_controllers.html" title="Chapter 17. Remote Controllers"><link rel="prev" href="Remote_controllers_table_change.html" title="Changing default Remote Controller mappings"><link rel="next" href="media_common.html" title="Part IV. Media Controller API"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">LIRC Device Interface</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="Remote_controllers_table_change.html">Prev</a> </td><th width="60%" align="center">Chapter 17. Remote Controllers</th><td width="20%" align="right"> <a accesskey="n" href="media_common.html">Next</a></td></tr></table><hr></div><div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="lirc_dev"></a>LIRC Device Interface</h2></div></div></div><div class="toc"><dl class="toc"><dt><span class="section"><a href="lirc_dev.html#lirc_dev_intro">Introduction</a></span></dt><dt><span class="section"><a href="lirc_dev.html#lirc_read">LIRC read fop</a></span></dt><dt><span class="section"><a href="lirc_dev.html#lirc_write">LIRC write fop</a></span></dt><dt><span class="section"><a href="lirc_dev.html#lirc_ioctl">LIRC ioctl fop</a></span></dt></dl></div><div class="section"><div class="titlepage"><div><div><h3 class="title"><a name="lirc_dev_intro"></a>Introduction</h3></div></div></div><p>The LIRC device interface is a bi-directional interface for 2transporting raw IR data between userspace and kernelspace. Fundamentally, 3it is just a chardev (/dev/lircX, for X = 0, 1, 2, ...), with a number 4of standard struct file_operations defined on it. With respect to 5transporting raw IR data to and fro, the essential fops are read, write 6and ioctl.</p><p>Example dmesg output upon a driver registering w/LIRC:</p><div class="blockquote"><blockquote class="blockquote"><p>$ dmesg |grep lirc_dev</p><p>lirc_dev: IR Remote Control driver registered, major 248</p><p>rc rc0: lirc_dev: driver ir-lirc-codec (mceusb) registered at minor = 0</p></blockquote></div><p>What you should see for a chardev:</p><div class="blockquote"><blockquote class="blockquote"><p>$ ls -l /dev/lirc*</p><p>crw-rw---- 1 root root 248, 0 Jul 2 22:20 /dev/lirc0</p></blockquote></div></div><div class="section"><div class="titlepage"><div><div><h3 class="title"><a name="lirc_read"></a>LIRC read fop</h3></div></div></div><p>The lircd userspace daemon reads raw IR data from the LIRC chardev. The 7exact format of the data depends on what modes a driver supports, and what 8mode has been selected. lircd obtains supported modes and sets the active mode 9via the ioctl interface, detailed at <a class="xref" href="lirc_dev.html#lirc_ioctl" title="LIRC ioctl fop">the section called “LIRC ioctl fop”</a>. The generally 10preferred mode is LIRC_MODE_MODE2, in which packets containing an int value 11describing an IR signal are read from the chardev.</p><p>See also <a class="ulink" href="http://www.lirc.org/html/technical.html" target="_top">http://www.lirc.org/html/technical.html</a> for more info.</p></div><div class="section"><div class="titlepage"><div><div><h3 class="title"><a name="lirc_write"></a>LIRC write fop</h3></div></div></div><p>The data written to the chardev is a pulse/space sequence of integer 12values. Pulses and spaces are only marked implicitly by their position. The 13data must start and end with a pulse, therefore, the data must always include 14an uneven number of samples. The write function must block until the data has 15been transmitted by the hardware. If more data is provided than the hardware 16can send, the driver returns EINVAL.</p></div><div class="section"><div class="titlepage"><div><div><h3 class="title"><a name="lirc_ioctl"></a>LIRC ioctl fop</h3></div></div></div><div class="toc"><dl class="toc"><dt><span class="section"><a href="lirc_dev.html#lirc_dev_errors">Return Value</a></span></dt></dl></div><p>The LIRC device's ioctl definition is bound by the ioctl function 17definition of struct file_operations, leaving us with an unsigned int 18for the ioctl command and an unsigned long for the arg. For the purposes 19of ioctl portability across 32-bit and 64-bit, these values are capped 20to their 32-bit sizes.</p><p>The following ioctls can be used to change specific hardware settings. 21In general each driver should have a default set of settings. The driver 22implementation is expected to re-apply the default settings when the device 23is closed by user-space, so that every application opening the device can rely 24on working with the default settings initially.</p><div class="variablelist"><dl class="variablelist"><dt><span class="term">LIRC_GET_FEATURES</span></dt><dd><p>Obviously, get the underlying hardware device's features. If a driver 25 does not announce support of certain features, calling of the corresponding 26 ioctls is undefined.</p></dd><dt><span class="term">LIRC_GET_SEND_MODE</span></dt><dd><p>Get supported transmit mode. Only LIRC_MODE_PULSE is supported by lircd.</p></dd><dt><span class="term">LIRC_GET_REC_MODE</span></dt><dd><p>Get supported receive modes. Only LIRC_MODE_MODE2 and LIRC_MODE_LIRCCODE 27 are supported by lircd.</p></dd><dt><span class="term">LIRC_GET_SEND_CARRIER</span></dt><dd><p>Get carrier frequency (in Hz) currently used for transmit.</p></dd><dt><span class="term">LIRC_GET_REC_CARRIER</span></dt><dd><p>Get carrier frequency (in Hz) currently used for IR reception.</p></dd><dt><span class="term">LIRC_{G,S}ET_{SEND,REC}_DUTY_CYCLE</span></dt><dd><p>Get/set the duty cycle (from 0 to 100) of the carrier signal. Currently, 28 no special meaning is defined for 0 or 100, but this could be used to switch 29 off carrier generation in the future, so these values should be reserved.</p></dd><dt><span class="term">LIRC_GET_REC_RESOLUTION</span></dt><dd><p>Some receiver have maximum resolution which is defined by internal 30 sample rate or data format limitations. E.g. it's common that signals can 31 only be reported in 50 microsecond steps. This integer value is used by 32 lircd to automatically adjust the aeps tolerance value in the lircd 33 config file.</p></dd><dt><span class="term">LIRC_GET_M{IN,AX}_TIMEOUT</span></dt><dd><p>Some devices have internal timers that can be used to detect when 34 there's no IR activity for a long time. This can help lircd in detecting 35 that a IR signal is finished and can speed up the decoding process. 36 Returns an integer value with the minimum/maximum timeout that can be 37 set. Some devices have a fixed timeout, in that case both ioctls will 38 return the same value even though the timeout cannot be changed.</p></dd><dt><span class="term">LIRC_GET_M{IN,AX}_FILTER_{PULSE,SPACE}</span></dt><dd><p>Some devices are able to filter out spikes in the incoming signal 39 using given filter rules. These ioctls return the hardware capabilities 40 that describe the bounds of the possible filters. Filter settings depend 41 on the IR protocols that are expected. lircd derives the settings from 42 all protocols definitions found in its config file.</p></dd><dt><span class="term">LIRC_GET_LENGTH</span></dt><dd><p>Retrieves the code length in bits (only for LIRC_MODE_LIRCCODE). 43 Reads on the device must be done in blocks matching the bit count. 44 The bit could should be rounded up so that it matches full bytes.</p></dd><dt><span class="term">LIRC_SET_{SEND,REC}_MODE</span></dt><dd><p>Set send/receive mode. Largely obsolete for send, as only 45 LIRC_MODE_PULSE is supported.</p></dd><dt><span class="term">LIRC_SET_{SEND,REC}_CARRIER</span></dt><dd><p>Set send/receive carrier (in Hz).</p></dd><dt><span class="term">LIRC_SET_TRANSMITTER_MASK</span></dt><dd><p>This enables the given set of transmitters. The first transmitter 46 is encoded by the least significant bit, etc. When an invalid bit mask 47 is given, i.e. a bit is set, even though the device does not have so many 48 transitters, then this ioctl returns the number of available transitters 49 and does nothing otherwise.</p></dd><dt><span class="term">LIRC_SET_REC_TIMEOUT</span></dt><dd><p>Sets the integer value for IR inactivity timeout (cf. 50 LIRC_GET_MIN_TIMEOUT and LIRC_GET_MAX_TIMEOUT). A value of 0 (if 51 supported by the hardware) disables all hardware timeouts and data should 52 be reported as soon as possible. If the exact value cannot be set, then 53 the next possible value _greater_ than the given value should be set.</p></dd><dt><span class="term">LIRC_SET_REC_TIMEOUT_REPORTS</span></dt><dd><p>Enable (1) or disable (0) timeout reports in LIRC_MODE_MODE2. By 54 default, timeout reports should be turned off.</p></dd><dt><span class="term">LIRC_SET_REC_FILTER_{,PULSE,SPACE}</span></dt><dd><p>Pulses/spaces shorter than this are filtered out by hardware. If 55 filters cannot be set independently for pulse/space, the corresponding 56 ioctls must return an error and LIRC_SET_REC_FILTER shall be used instead.</p></dd><dt><span class="term">LIRC_SET_MEASURE_CARRIER_MODE</span></dt><dd><p>Enable (1)/disable (0) measure mode. If enabled, from the next key 57 press on, the driver will send LIRC_MODE2_FREQUENCY packets. By default 58 this should be turned off.</p></dd><dt><span class="term">LIRC_SET_REC_{DUTY_CYCLE,CARRIER}_RANGE</span></dt><dd><p>To set a range use LIRC_SET_REC_DUTY_CYCLE_RANGE/LIRC_SET_REC_CARRIER_RANGE 59 with the lower bound first and later LIRC_SET_REC_DUTY_CYCLE/LIRC_SET_REC_CARRIER 60 with the upper bound.</p></dd><dt><span class="term">LIRC_NOTIFY_DECODE</span></dt><dd><p>This ioctl is called by lircd whenever a successful decoding of an 61 incoming IR signal could be done. This can be used by supporting hardware 62 to give visual feedback to the user e.g. by flashing a LED.</p></dd><dt><span class="term">LIRC_SETUP_{START,END}</span></dt><dd><p>Setting of several driver parameters can be optimized by encapsulating 63 the according ioctl calls with LIRC_SETUP_START/LIRC_SETUP_END. When a 64 driver receives a LIRC_SETUP_START ioctl it can choose to not commit 65 further setting changes to the hardware until a LIRC_SETUP_END is received. 66 But this is open to the driver implementation and every driver must also 67 handle parameter changes which are not encapsulated by LIRC_SETUP_START 68 and LIRC_SETUP_END. Drivers can also choose to ignore these ioctls.</p></dd><dt><span class="term">LIRC_SET_WIDEBAND_RECEIVER</span></dt><dd><p>Some receivers are equipped with special wide band receiver which is intended 69 to be used to learn output of existing remote. 70 Calling that ioctl with (1) will enable it, and with (0) disable it. 71 This might be useful of receivers that have otherwise narrow band receiver 72 that prevents them to be used with some remotes. 73 Wide band receiver might also be more precise 74 On the other hand its disadvantage it usually reduced range of reception. 75 Note: wide band receiver might be implictly enabled if you enable 76 carrier reports. In that case it will be disabled as soon as you disable 77 carrier reports. Trying to disable wide band receiver while carrier 78 reports are active will do nothing.</p></dd></dl></div><div class="section"><div class="titlepage"><div><div><h4 class="title"><a name="lirc_dev_errors"></a>Return Value</h4></div></div></div><p>On success <span class="returnvalue">0</span> is returned, on error <span class="returnvalue">-1</span> and the <code class="varname">errno</code> variable is set appropriately. The generic error codes are described at the <a class="link" href="gen_errors.html#gen-errors" title="Table 19.1. Generic error codes">Generic Error Codes</a> chapter.</p></div></div></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="Remote_controllers_table_change.html">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="remote_controllers.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="media_common.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">Changing default Remote Controller mappings </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> Part IV. Media Controller API</td></tr></table></div></body></html> 79