February 16, 2008

Comercial Infrared (LIRC) on a Dell Inspiron 9100 - Part One

A couple of months ago I switched to using Gentoo Linux as my main operating system. My laptop, a Dell Inspiron 9100, has an infrared port, but I have never been able to use it for anything useful. I tried to set up LIRC (Linux Infrared Remote Control) in the past on other Linux distributions and even in Windows XP with WinLIRC, but had no success. It took a lot of reading and testing, but I finally have LIRC working. In this post, I describe how to set it up properly.

Hardware

The Dell Inspiron 9100 has a SMSC IrCC controller chip. These chips are present in many other laptops and this guide may help you even if you do not own the same laptop as me. The IrCC chips support both IRDA and CIR (Comercial Infrared) standards.

Configuring the hardware

Before installing any software, check which COMM port the infrared controller is assigned to. This setting is located in the BIOS, so reboot your laptop and locate it. Typically it is set to COMM2 and that is what I used. COMM2 also works with the IRDA driver, in case you may want to use that in the future. I tried using COMM1, but could not get it to work.

Installing LIRC

In order to receive remote control infrared signals in Linux, you need to install LIRC. In Gentoo, this involves emerging (installing) lirc or one of the higher level packages that depend on it. I personally use KDE so I would emerge kdelirc or the meta package kdeutils-meta with the lirc USE flag set.

Before you begin emerging, however, you need to set a couple of options in /etc/make.conf to properly install lirc. First, you need to define which devices you plan to use with lirc so the appropriate modules are build during the emerge process. This is controlled by the LIRC_DEVICES option in /etc/make.conf. You can set it to all and lirc will support all available devices. For our controller, only the SIR driver is needed, therefore: /etc/make.conf ... LIRC_DEVICES="sir" ... is sufficient.

For this particular device, I also enabled both the hardware-carrier and transmitter USE flags.

/etc/make.conf USE=" ... hardware-carrier transmitter ... "

I am not sure if they are necessary or useful, but I do not have time to test that given that I got it to work.

Now that these options are set, you can install lirc. In my configuration I set the lirc use flag and emerged kdeutils-meta.

/etc/make.conf USE=" ... lirc ... " # emerge kdeutils-meta

Configuration

After the packages have been successfully emerged, the LIRC kernel module, lirc_sir, needs to be configured.

Beforehand, however, make sure that the IRDA kernel module, smsc_ircc2, does not load automatically. This is unlikely, but it may happen that it is properly configured and able to load automatically on its own. Check with this command:

$ lsmod | grep smsc

If smsc_ircc2 is present, you need to blacklist it to prevent if from loading automatically. The lirc_sir and smsc_ircc2 modules cannot be loaded at the same time. To blacklist a module, edit /etc/modprobe.d/blacklist and add the following line, usually at the bottom:

/etc/modprobe.d/blacklist blacklist smsc-ircc2

After making sure that the IRDA module does not load, the LIRC module can be properly configured. Until recently I did not know about the modinfo command and I had no idea how to do this correctly. This command gives you information about the module and what options the module accepts. Here is an example output of the modinfo command on my lirc_sir module.

# modinfo lirc_sir filename: /lib/modules/2.6.22-suspend2-r2/misc/lirc_sir.ko license: GPL author: Milan Pikula description: Infrared receiver driver for SIR type serial ports depends: vermagic: 2.6.22-suspend2-r2 SMP mod_unload PENTIUM4 parm: io:I/O address base (0x3f8 or 0x2f8) (int) parm: irq:Interrupt (4 or 3) (int) parm: threshold:space detection threshold (3) (int) parm: debug:Enable debugging messages (bool)

Look at the "parm:" lines. These are the options that the lirc_sir module accepts. These can be specified while running the modprobe command. In order to load the lirc_sir module properly, the top three parameters need to be specified. When using COMM2, the following settings worked and properly loaded the module:

# modprobe lirc_sir io=0x2f8 irq=3 threshold=5

The first two parameters are specific to COMM2. The threshold parameter I have not explored in detail. I tried two, three (the default), four and five. Four and five were the two that worked so I chose five. You can experiment with those. I did not notice any negative site effects.

When the module loads successfully, you can test it with the mode2 program (run it as root). Just start the program and try pressing some keys on the remote while facing the receiver. You should see lines like to following start to appear.

# mode2 ... space 630 pulse 275 space 363 pulse 515 pulse 514 space 1763 pulse 514 space 1765 pulse 513 space 1798 ...

If the screen remains the same, then something is not correct. Verify the settings and maybe experiment with the threshold parameter. To terminate the program, press Ctrl-C. Now the module is properly configured. To preserve the settings, add a new file (I named mine lirc-sir) to /etc/modprobe.d/ with the following text.

/etc/modprobe.d/lirc-sir options lirc-sir io=0x2f8 irq=3 threshold=5

Then run modules-update to integrate the settings from this file.

# modules-update

Now, just typing modprobe lirc_sir will work. The options are looked up automatically. This module needs to be loaded before the lirc service is started. There are several ways to get this accomplished. The easy way it to just add lirc_sir to /etc/modules.autoload.d/kernel-2.6 or to the kernel-2.4 file if you do not use a 2.6 series kernel.

/etc/modules.autoload.d/kernel-2.6 ... lirc_sir

Starting LIRC

After the module is configured, the lirc daemon needs to be added to the start-up services. In Gentoo, the command is the following:

# rc-update add lircd default

In addition to lircd daemon, there is also a lircmd daemon. This daemon interprets button presses and sends them as mouse events to the system. I have not tried it yet, but it may make a nice follow-up post in the future.

From here you can follow the Configuring LIRC portion of the LIRC manual and everything should work.

In a follow up post I will demonstrate now to configure and use your remote in KDE.

References

No comments: