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 your system to use the binary driver, add to your VIDEO_CARDS field in make.conf:

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

Your 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:

You will also have to being used,add the following lines to your  or display manager start script:

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

You can also 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 you must find your sensors location:

Take note the output. this will be your hwmon location for thinkfan configuration file and now you can edit your thinkfan.conf using your preferred text editor.

Example config for thinkfan:


 * 1) thinkfan 0.7 example config file
 * 2) ATTENTION: There is only very basic sanity checking on the configuration.
 * 3) That means you can set your temperature limits as insane as you like. You
 * 4) can do anything stupid, e.g. turn off your fan when your CPU reaches 70°C.
 * 5) That's why this program is called THINKfan: You gotta think for yourself.
 * 6) IBM/Lenovo Thinkpads (thinkpad_acpi, /proc/acpi/ibm)
 * 7) IMPORTANT:
 * 8) To keep your HD from overheating, you have to specify a correction value for
 * 9) the sensor that has the HD's temperature. You need to do this because
 * 10) thinkfan uses only the highest temperature it can find in the system, and
 * 11) that'll most likely never be your HD, as most HDs are already out of spec
 * 12) when they reach 55 °C.
 * 13) Correction values are applied from left to right in the same order as the
 * 14) temperatures are read from the file.
 * 15) For example:
 * 16) tp_thermal /proc/acpi/ibm/thermal (0, 0, 10)
 * 17) will add a fixed value of 10 °C the 3rd value read from that file. Check out
 * 18) http://www.thinkwiki.org/wiki/Thermal_Sensors to find out how much you may
 * 19) want to add to certain temperatures.
 * 1) thinkfan uses only the highest temperature it can find in the system, and
 * 2) that'll most likely never be your HD, as most HDs are already out of spec
 * 3) when they reach 55 °C.
 * 4) Correction values are applied from left to right in the same order as the
 * 5) temperatures are read from the file.
 * 6) For example:
 * 7) tp_thermal /proc/acpi/ibm/thermal (0, 0, 10)
 * 8) will add a fixed value of 10 °C the 3rd value read from that file. Check out
 * 9) http://www.thinkwiki.org/wiki/Thermal_Sensors to find out how much you may
 * 10) want to add to certain temperatures.
 * 1) want to add to certain temperatures.

tp_fan /proc/acpi/ibm/fan
 * 1) use legacy fan control


 * 1) disable using sysfs pwm
 * 2) pwm_fan /sys/devices/platform/thinkpad_hwmon/pwm1

hwmon /sys/devices/platform/thinkpad_hwmon/hwmon/hwmon2/temp1_input

(0,    0,      42) (1,     40,     47) (2,     45,     52) (3,     50,     57) (4,     55,     62) (5,     60,     77) (7,     67,     93) (127,   85,     32767)
 * 1)  Syntax:
 * 2)  (LEVEL, LOW, HIGH)
 * 3)  LEVEL is the fan level to use (0-7 with thinkpad_acpi)
 * 4)  LOW is the temperature at which to step down to the previous level
 * 5)  HIGH is the temperature at which to step up to the next level
 * 6)  All numbers are integers.

Add below line in /etc/modprobe.d/thinkfan.conf

options thinkpad_acpi fan_control=1

Now you can 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