Lenovo Thinkpad W540

This article describes installation and configuration instructions for the Lenovo Thinkpad W540. Although several different configurations for the model exist, these instructions should work for all of them. Note that the model documented does not contain a WAN card, and other sources should be explored for configuration of the hardware.

Hardware

 * Intel® Core™ i7-4600M Processor (4M Cache, up to 3.60 GHz)
 * NVIDIA® Quadro® K1100M with Optimus
 * 15.6" FHD (1920 x 1080), anti-glare, 300 nits, 500:1 contrast ratio
 * 16GB PC3-12800 1600MHz DDR3L, non-parity, dual-channel capable DDRM
 * Integrated 720p HD Camera
 * 9-cell Li-Ion battery - 57++ (99.9Wh)
 * Fingerprint Reader
 * 4-in-1 card reader (MMC, SD, SDHC, SDXC), supports UHS-II SD card
 * 1 x Ethernet (RJ45)

Optional WAN Cards:
 * Ericsson N5321 Mobile Broadband HSPA+
 * Sierra Wireless EM7355 (mutually exclusive with M.2 SSD)

lspci
Use the following lspci output to determine what kernel drivers are used for the hardware. This is especially useful when configuring wifi (``iwlwifi`` is used). Note that even though a Core i7 is used in the configuration, ``lspci`` displays it as a Xeon. It is a 4th generation processor none the less.

lsusb
The following output can be used to determine the USB drivers. It also shows the vendor of the fingerprint reader, which is not configured in this guide.

Firmware
All of the required firmware, including the wifi driver should be available in the package.

Kernel
This does not include specific settings to, for example, the init system or graphics drivers being used on the system.

Note at the time this article was written, the kernel version used was 4.12.5.

Note: Bluetooth was not tested on this system. The kernel parameters enabled for Bluetooth are based on previous ThinkPad articles.

Video Card Setup with NVIDIA Binary Drivers
The laptop has a dual GPU setup operating on NVIDIA Optimus. The integrated intel card is what is attached to the laptop screen, and the discrete Quadro card is what interfaces with the outside HDMI and DisplayPort. It is possible to run the laptop without the discrete graphics card for better power usage, however doing so will sacrifice the ability to output to HDMI or Display Port. To do so, simply compile only for the intel driver, and X-server should pick everything up by default without any extra configuration.

The better option is to use the discrete card. Note that it's recommended to use the binary NVIDIA driver in place of the open source nouveau driver, as the binary driver offers the best performance, and features Prime Synchronization, which eliminates screen tearing (a prominent problem on the laptop as it uses hybrid graphics). The caveat is that the discrete card has no ability to turn off on the binary driver, thus offering worse battery performance compared to the nouveau driver.

To configure the system to use the binary driver, add to the VIDEO_CARDS field in make.conf:

Update the system, which should automatically install the NVIDIA driver package.

The X.org server configuration should look like this. This will enable PRIME on the device, allowing the machine to use both its discrete card for rendering, and intel card for displaying to laptop screen.

Prime Synchronization
To eliminate any screen tearing, PRIME Synchronization will need to be enabled. To do this, some NVIDIA kernel modules have to be loaded in at startup. Add the following entries to the nvidia.conf file in the modprobe.d folder:

Also, add the following lines to the user's when using startx or display manager start script:

After a restart, verify that prime is working and functioning by running xrandr, which should produce the following outputː

Alternatively, verify that Prime Synchronization is turned on by looking at the Prime Synchronization field under the eDP-1-1 field:

Thinkfan
Install Thinkfan:

When installation has been completed, find the sensors location:

Take note of the output. This will be the hwmon location for thinkfan configuration. Now edit the thinkfan.conf using a text editor.

Example config for thinkfan:

Add below line in :

options thinkpad_acpi fan_control=1

Now run thinkfan:

or via init.d

External resources

 * https://wiki.archlinux.org/index.php/PRIME
 * https://wiki.archlinux.org/index.php/NVIDIA_Optimus
 * https://wiki.archlinux.org/index.php/NVIDIA
 * https://github.com/vmatare/thinkfan