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:

tp_thermal /proc/acpi/ibm/thermal # provides us with 16 temperature inputs
 * 1) thinkfan 0.9 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) This file shows how to use sensor-specific temperature limits.
 * 7) First of all, you need to specify temperature inputs. On a Thinkpad, you can
 * 8) just use:
 * 1) That's why this program is called thinkfan: You gotta think for yourself.
 * 2) This file shows how to use sensor-specific temperature limits.
 * 3) First of all, you need to specify temperature inputs. On a Thinkpad, you can
 * 4) just use:
 * 1) This file shows how to use sensor-specific temperature limits.
 * 2) First of all, you need to specify temperature inputs. On a Thinkpad, you can
 * 3) just use:


 * 1) On other systems, you have to specify a file in /sys/class/hwmon for each
 * 2) sensor you want to use. They are numbered in their order of appearance.
 * 3) For example:
 * 4) hwmon /sys/class/hwmon5/temp2_input           #1
 * 5) hwmon /sys/class/hwmon0/device/temp3_input    #2
 * 6) If you want to read temperatures directly from the hard disk, thinkfan needs
 * 7) to be compiled with -DUSE_ATASMART. Then you can do:
 * 8) atasmart /dev/sda                             #3
 * 9) You can have as many temperature inputs as you like. You should at get the
 * 10) temperature from the CPU, the GPU and the hard disk.
 * 1) atasmart /dev/sda                             #3
 * 2) You can have as many temperature inputs as you like. You should at get the
 * 3) temperature from the CPU, the GPU and the hard disk.
 * 1) You can have as many temperature inputs as you like. You should at get the
 * 2) temperature from the CPU, the GPU and the hard disk.
 * 1) temperature from the CPU, the GPU and the hard disk.

tp_fan /proc/acpi/ibm/fan
 * 1) Next we specify the fan we want to use. On a Thinkpad, this is:
 * 1) Next we specify the fan we want to use. On a Thinkpad, this is:


 * 1) On anything other than a Thinkpad you'll probably use some PWM control file
 * 2) in /sys/class/hwmon. Remember that fan levels range from 0 to 255 and that
 * 3) they're just a number, not including the word "level" as seen below.
 * 4) A sysfs fan would be specified like this:
 * 5) pwm_fan /sys/class/hwmon/hwmon2/device/pwm1
 * 6) But remember you can only have one fan.
 * 1) pwm_fan /sys/class/hwmon/hwmon2/device/pwm1
 * 2) But remember you can only have one fan.
 * 1) But remember you can only have one fan.

{ "level 0"  # the fan level (0 0  0  0  0  0  0  0  0  0  0  0  0  0  0  0)      # LOWER limit (54 42 42 54 42 . 42 .  42 46 54 .  .  .  .  .)      # UPPER limit }
 * 1) Then you need to specify the temperature limits for each of the sensors.
 * 2) A dot means that the corresponding sensor should be ignored. The length of the
 * 3) UPPER and LOWER limits must be the same as the number of temperatures. In this
 * 4) example, /proc/acpi/ibm/thermal contains 16 sensors (on older thinkpads,
 * 5) there may be only 8), some of which are unused (hence the dots).
 * 6) A sysfs temperature input always contains only one sensor, so if you specify
 * 7) 5 sysfs files above, the length of your limits must be 5, too.
 * 8) I've come up with these preliminary settings for my Thinkpad T61p. They probably
 * 9) don't make sense for anything else, so you most definitely have to work
 * 10) something out for yourself.
 * 1) don't make sense for anything else, so you most definitely have to work
 * 2) something out for yourself.
 * 1) ^---^   This works for /proc/acpi/ibm/thermal.
 * 2)             for a PWM fan in /sys/class/hwmon it would have to be just
 * 3)             0 or "0".
 * 4)    Sensor count:
 * 5)    1  2  3  4  5  6  7  8  9  10 11 12 13 14 15 16
 * 1)    1  2  3  4  5  6  7  8  9  10 11 12 13 14 15 16

{ "level 1" (46 39 39 48 39 . 39 .  41 44 46 .  .  .  .  .)    (58 45 45 60 45 .  45 .  45 47 56 .  .  .  .  .) }
 * 1) ^---^ For a PWM fan you may have to use something around 30 to get the
 * 2) same speed.

{ "level 3" (52 43 43 57 43 . 43 .  43 45 51 .  .  .  .  .)    (62 48 48 67 48 .  48 .  48 48 57 .  .  .  .  .) }

{ "level 5" (56 46 46 65 46 . 46 .  46 46 52 .  .  .  .  .)    (66 49 49 69 49 .  49 .  49 49 58 .  .  .  .  .) }

{ "level 7" (63 47 47 67 47 . 47 .  47 47 50 .  .  .  .  .)    (73 55 55 83 60 .  60 .  60 60 64 .  .  .  .  .) }

{ "level disengaged" # nice idea: "level auto" can also be used. # but again: only numbers for sysfs. (69 50 50 75 55 . 55 .  55 55 55 .  .  .  .  .)    (99 99 99 99 99 .  99 .  99 99 99 .  .  .  .  .) }

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