How to make use of IrDA

From ThinkWiki
Revision as of 10:38, 7 January 2010 by Tonko (Talk | contribs) (Reverted edits by Hieuln (Talk) to last version by Tonko)
Jump to: navigation, search

The purpose of this document is to get the IrDA hardware in your ThinkPad operational, setting up communication to other devices is not covered. However, the external links section can prove useful for this.

Serial IR (SIR)

SIR is limited to serial datarates up to 115.2Kb/s

On modern distributions all configuration might be taken care of automatically by starting the irda service # service irda start. If not try the following;

To use it, run # irattach /dev/ttyS1 -s; modprobe ircomm-tty

Then turn on your IrDA-capable device and put it within range, and point your software (e.g., minicom) to /dev/irda0.

Kernel configuration

Edit /etc/modprobe.conf and add the following lines

alias tty-ldisc-11 irtty-sir
alias char-major-161 ircomm-tty

Fast IR (FIR)

FIR is the preferred mode of IrDA operation and operates at a maximum bandwidth of 4 Mbps

On modern distributions this should all be automatically handled by simply starting the idra service # service irda start. If not try the following;

Kernel configuration

Edit /etc/modprobe.conf and add the following lines

alias irda0 nsc-ircc

Make sure that setserial is in right directory (e.g not in /usr/bin/setserial).After that if irdadump still gives nothing try:

echo 1 > /proc/sys/net/irda/discovery

Known problems

  • If you read something like "ttyS1: LSR safety check engaged!" and "irattach: tcgetattr: Input/output error" in the system log, try limiting the FIR max baud rate (echo 57600 > /proc/sys/net/irda/max_baud_rate). This did the trick for me when I was trying to synchronize my Ericsson T39m with my Thinkpad R51 (multisync, evolution-2.8, KDE 3.5.5, openSUSE 10.2).
  • If you get an error in syslog like "nsc_ircc_open(), can't get iobase of 0x2f8" it probably means you have manually specified resources for IrDA in the BIOS. When you do that you effectively allow the serial driver to take control, and as a result the nsc_ircc driver can no longer take control of the resources. Options are to either restore the BIOS settings for IrDA to factory default, or you can work around it by using setserial to clear the resources before loading the nsc_ircc kernel module
setserial /dev/ttyS1 uart none port 0 irq 0; modprobe nsc_ircc

Some other things you might want to do with IrDA

  • add fast PPP support:
# modprobe irnet
  • if needed, limit further the size of the transmit window
# echo 1 > /proc/sys/net/irda/max_tx_window
  • set the connection speed to 4Mbit in FIR mode:
# echo 4000000 > /proc/sys/net/irda/max_baud_rate

LIRC and IrDA

LIRC allows the use of infrared remote controls with Linux as input devices. This can be especially useful to control applications like mplayer, xine, mythtv or boxee. Usually, IrDA ports are not compatible with LIRC, but you may have luck using lirc_sir, as follows;

NOTE!
lirc_sir is incompatible with the regular Linux IrDA drivers (nsc_ircc). You can only use one at a time, and will have to reboot before you can switch
NOTE!
Even if your successful in getting this to work, you might find that the distance between remote control and receiver on the ThinkPad cannot exceed ~50cm, rendering it effectively useless

Success reports

  • R40
  • T41

Failure reports

lirc_sir does not always work, particular on newer machines it seems the module loads when following these instructions, but the device /dev/lirc0 cannot be opened and returns a device or resource busy. You can simply test this by typing # cat /dev/lirc0

  • T60

Configuring lirc_sir

Go into your BIOS setup, and ensure that Infrared is fully enabled and that resources are assigned. I suggest using IO 2f8 and IRQ 3.

Boot into Linux, and first ensure the setserial program is installed. Running # /bin/setserial /dev/ttyS1 should return at this point:

/dev/ttyS1, UART: undefined, Port: 0x02f8, IRQ: 3

If setserial cannot be found, install the setserial package with your distributions package management software

Then create a file /etc/modprobe.d/lirc.conf with the following content:

# prevent nsc_ircc from loading (blacklist might not be enough)
blacklist nsc_ircc
install nsc_ircc /bin/true
# pass options to lirc_sir to load it on ttyS1
options lirc_sir io=0x2f8 irq=3
# ensure serial resources are cleared before loading lirc_sir
# not doing so can result in a device busy error, or can even hang your system
install lirc_sir /bin/setserial /dev/ttyS1 uart none port 0 irq 0; /sbin/modprobe --ignore-install lirc_sir

At this point it is best to reboot, to ensure that nsc_ircc was never loaded. Several things can go wrong if the steps are not followed accurately. You might get an error when loading lirc_sir that the device is busy, or your system may even hang.

Now do a # modprobe lirc_sir and check # dmesg output. You should see something like this:

lirc_dev: IR Remote Control driver registered, major 61
lirc_dev: lirc_register_plugin: sample_rate: 0
lirc_sir: I/O port 0x02f8, IRQ 3.
lirc_sir: Installed.

Configuring LIRC

If you did not yet install LIRC, then do so now using your distributions package management system.

Ubuntu

Make sure your /etc/lirc/hardware.conf looks like this:

REMOTE="SIR IrDA (built-in IR ports)"
REMOTE_MODULES="lirc_dev lirc_sir"
REMOTE_DRIVER=""
REMOTE_DEVICE="/dev/lirc0"
REMOTE_LIRCD_CONF=""
REMOTE_LIRCD_ARGS=""
TRANSMITTER="None"
TRANSMITTER_MODULES=""
TRANSMITTER_DRIVER=""
TRANSMITTER_DEVICE=""
TRANSMITTER_LIRCD_CONF=""
TRANSMITTER_LIRCD_ARGS=""
START_LIRCD="true"
START_LIRCMD=""
LOAD_MODULES=""
LIRCMD_CONF=""
FORCE_NONINTERACTIVE_RECONFIGURATION="false"

After this, start (or re-start) the lirc daemon, and set it to automatically start on bootup.

# service lirc restart
# update-rc.d lirc defaults

Fedora

On Fedora the default LIRC device is already set to /dev/lirc0

TODO
best way of ensuring lirc_sir is loaded before lircd is started? The config file /etc/sysconfig/lirc does not seem to help. Perhaps an alias line in the modules config file if someone knows the correct syntax?

# service lirc restart
# chkconfig lirc on

Testing LIRC

Now we are ready to test if we can receive IR data from a remote control.

Try running # irrecord -d /dev/lirc0 foo and follow the onscreen instructions. When asked keep a button on a remote pressed while pointing at the ThinkPad IR port and you should see dots appear.

You are now able to start configuring LIRC for your specific remote control.

Configuring remote controls is out of scope for this document and you should check the LIRC website for detailed instructions. But if your using Gnome you might want to try $ gnome-lirc-properties, or in the case of KDE $ kdelirc.

NOTE!
Current versions of gnome-lirc-properties (at least up to 0.3.1) do not support lirc_sir, you need to first edit /usr/share/gnome-lirc-properties/receivers.conf and add the following:
[Generic: IrDA SIR Receiver]
kernel-module = lirc_sir
device-nodes  = /dev/lirc0
After this you can select Generic - IrDA SIR Receiver from the drop down menus (autodetect will not pick it up)

External Sources