Thursday, February 25, 2016

Dispatches from the X1 front

The first-gen Thinkpad X1: possibly the best laptop I've ever owned. Lasted three years, compared to the usual 12-18 months. It still runs, but the battery is down to about 40 minutes, and the (second!) keyboard is starting to lose keys.

The third-gen Thinkpad X1 Carbon: a little annoying at first: no SD slot, no h/w kill switch for the wireless, no spill-through keyboard (wtf guys, that was brilliant!). About 6 months in, the video glitches started: there is a short which corrupts video memory while using wifi. The fix, of course, is a replacement system board, which is great if you have a spare third-gen X1 Thinkpad Carbon lying around and can just up and change workstations like it's no big. Workaround: rfkill block wifi, or just get used to the strobe effect.

The latest: Thinkpad X1 Yoga. And let's just put it out there: this doesn't work out of the box like the previous two did. Lenovo and Intel seem to have backed off of their Linux commitment, though that's probably half their users these days (errybody else on the mobile, right?)

Here's the rundown on getting the X1 Yoga up and running with a Linux install.


Basic Linux

Debian 8.3.0 AMD64 netinst ISO if you were wise enough to buy the OneLink+ RJ45 ethernet adapter; otherwise, use the regular (non-netinst) ISO.

Use unetbootin to make a USB flash drive image for this. Go into the BIOS on the X1 Yoga, enable F12 for boot device selection (just because), turn off secure boot, maybe enable diagnostic boot as well. No need to allow legacy BIOS installs, Debian will work just fine with uEFI (unlike FreeBSD where you need to use the 10.3-Beta or 11 memstick). Go through the install like you usually do. Your ethernet (if you have it) will be detected (again, unlike in FreeBSD).

Sound, APCI (suspend, hibernate, and battery status) and video card should all be working out of the box.


Wireless

Upgrade your kernel to 4.4.1 from the ubuntu PPA:
  http://kernel.ubuntu.com/~kernel-ppa/mainline/v4.4.1-wily/
This is per notes about a typo in the iwlwifi driver at
 https://bbs.archlinux.org/viewtopic.php?id=206831
Looking at the kernel source, 4.2.7 has the fix as well, but might as well go with the latest stable release of the kernel if we're upgrading.

You'll also need to upgrade the firmware, or your Wifi will not be recognized. There is a debian package in backports for this:
 https://packages.debian.org/jessie-backports/firmware-iwlwifi


Skylake P-State Fix

If you rebooted excitedly into your new kernel without following the rest of these steps, you're likely looking at a blank screen. That's because of a skylake p-state bug reported here:
 https://www.reddit.com/r/thinkpad/comments/410haw/yoga_260_wont_boot_ubuntu_with_kernel_4244_but/

This is because the kernel needs a command line parameter to not totally crap itself when it encounters Skylake's poor implementation of pstate.

To fix this, change the cmdline in /etc/default/grub to:
  GRUB_CMDLINE_LINUX_DEFAULT='intel_pstate=no_hwp quiet'

Don't forget to run update-grub when you're done.

Hopefully this will go away in 4.5; according to a commenter, that's what the kernel guys are trying for.


i915 Xorg Video fix

Of course, the fancy new kernel hosed your X windows, didn't it?

Not sure why there's such a tight coupling there, but never mind. This one's an easy fix, per http://comments.gmane.org/gmane.linux.debian.user/508779 . Download (and install) a new version of the xserver-xorg-video-intel package from backports:

https://packages.debian.org/jessie-backports/xserver-xorg-video-intel


Touchscreen

The touchscreen is recognized and configurable in X Windows, but does not respond to touch or stylus events. A bug report is open at the linuxwacom project.

The touchscreen (+ stylus) works out of the box once the firmware update is installed (via windows, sadly,so don't pave the drive until you've updated firmware). Make sure to perform a hard reset (60 sec with a paperclip in the bottom of the laptop) after the upgrade.

To disable the touchpad when entering tablet mode (note: the keyboard will be disabled by  the BIOS), create the file /etc/acpi/events/thinkpad-tablet-touchpad-off with the following contents:

event=ibm/hotkey LEN0068:00 00000080 000060f0
action=/usr/local/bin/touchpad_disable.sh


You can verify the hotkey parameter by running acpi_listen and folding the display back to tablet position.

Next, create the file /usr/local/bin/touchpad_disable.sh with the following contents:

export XAUTHORITY=`ls -1 /home/*/.Xauthority | head -n 1`
export DISPLAY=":`ls -1 /tmp/.X11-unix/ | sed -e s/^X//g | head -n 1`"
tp_dev='SynPS/2 Synaptics TouchPad'
state=`xinput list-props "$tp_dev" | grep 'Device Enabled' | cut -d':' -f2 | tr -d '\t '`
if [ $state -eq 1 ]
then
  xinput disable "$tp_dev"
else
  xinput enable "$tp_dev"
fi

You will need to give root access to the X server session for this. The quickhack version is to add xhost + & to ~/.xsessionrc, but it's better to do something like +root@localhost..


The Acer BMA150 accelerometer is detected as a joystick device, so various /sys/bus/iio -based screen orientation scripts like thinkpad-yoga-scripts won't work. An alternative is to define a Window Manager screen edge event that invokes a script to cycle through screen orientation rotations:

#!/bin/sh
# script to rotate screen (counter-clockwise) based on current orientation

conn_line=`xrandr | grep ' connected'`
dev=`echo "$conn_line" | cut -d' ' -f 1`
orient=`echo "$conn_line" | cut -d' ' -f 5`

case $orient in
  '(normal' )
    xrandr --output $dev --rotate left
    ;;
  'left' )
    xrandr --output $dev --rotate inverted
    ;;
  'inverted' )
    xrandr --output $dev --rotate right
    ;;
  'right' )
    xrandr --output $dev --rotate normal
    ;;
  * )
    xrandr --output $dev --rotate normal
    ;;
esac

Some other approaches are discussed in this Manjaro Linux post.


Fingerprint reader

Is not supported by fprint. USB ID: 138a:0090 (Validity, no product string in usb-devices).


Camera

Works out of the box. Driver is uvcvideo. VLC mirrors it without any problems:

vlc v4l:// :v4l-dev="/dev/video0" :v4l-adev="/dev/audio"


FreeBSD

You need to use a 10.3 (BETA3 or more current) UEFI memstick image to do the install with, of course, the OneLink ethernet adapter connected. Presently, no support for wifi or Xorg support (perhaps in 11?). To boot, add an entry in /etc/grub.d/40_custom as follows:

menuentry "FreeBSD 10.3-BETA3" {
  insmod chain
  set root=(hd0,gpt10)
  chainloader (hd0,gpt10)/boot/loader.efi
}

...replacing gpt10 with the partition number where FreeBSD was installed. This starts counting from 1, so the example here is the tenth partition on the first hard drive (hd0).

Note that for update-grub to correctly recognize the FreeBSD partition (and therefore find loader.efi), you should provide an fstab entry to specify the UFS partition type:

/dev/sda10      /home/bsd       ufs    ro,noauto,ufstype=ufs2       0       0

10 comments:

  1. Nice article. Thanks!

    I bought the same machine. Got most of it working. I tried to read /dev/input/js0, hoping to get accelerometer info as a joystick, but got "operation not permitted" even as root. Any idea whether it's possible to do that?

    Also any recommendation for a full screen sketching tool?

    ReplyDelete
  2. I read somewhere that the accelerometer in Thinkpads is used only to park the hard disk when dropping the device, and that it doesn't support direct reading.

    That doesn't make much sense with the new X1s, though, as hard drives are not an option. The HDAPS entry in ThinkWiki suggests using their own (tp-smapi) driver:
    http://www.thinkwiki.org/wiki/HDAPS#Input_device_support

    I wasn't too interested in accelerometer-based screen orientation (I tend to disable it on tablets where possible). Instead, I added a screen edge binding in Enlightenment that rotates the screen when a particular edge is clicked.

    For drawing apps, try mypaint (http://mypaint.org/about/). In Debian, 'apt-get install mypaint mypaint-data mypaint-data-extras'.

    ReplyDelete
  3. This article helped me a lot in order to get most of the things working.

    An addition to your script is enabling and disabling the 'TPPS/2 IBM TrackPoint' device, which disables the trackpoint and trackpoint buttons.

    I was wondering, if you know whether we can listen for the "tablet-mode" event in Linux like it seems to get dispatched in Windows. In windows tablet-mode is activated when flipping the screen only partly. In Linux, I can only get this to work with your script, which disables the touchpad only when the screen is fully flipped 360 degrees. Also, the event seems to get called multiple times sometimes, after whcih the devices have to be enabled manually when flipping back to normal mode.



    ReplyDelete
    Replies
    1. Good point -- I hadn't noticed the trackpoint was still active.

      Unfortunately, acpi_listen is the only way I could find to listen for events like changing to tablet-mode. My guess is that this is a driver-level issue: the Linux driver is not issue the same events as the Windows driver. There may also be a lid/screen accelerometer that Windows is reading.

      I suppose I'll have to get in touch with the thinkpad-acpi maintainers (http://www.thinkwiki.org/wiki/Thinkpad-acpi) and see if they can help.

      Might also be worth poking around in /sys/devices/platform/thinkpad_acpi and /sys/devices/platform/thinkpad_hwmon . I noticed that hotkey_mask is 0xff8c7ffb, while hotkey_all_mask is 0xfffffffb - so it's possible there is a disabled hotkey which will send tablet mode events.

      Delete
  4. Just wanted to say that wireless works out of the box with debian testing after installing firmware-iwlwifi from non-free.

    ReplyDelete
    Replies
    1. For me, wireless didn't work out of the box on Ubuntu 16.04, but eventually what worked for me was simply changing the kernel from 4.4.0 to the most recent handy one I could find using "apt-cache search linux-image-extra" (in my case 4.11.0-14).

      Delete
  5. Could I ask which version of ubuntu you installed?

    I'm trying to set up xubuntu on my X1 Yoga and the touchscreen isn't working: exactly as you said, the touchscreen is recognized and configurable but doesn't respond to touch/stylus events. I installed xubuntu 14.04 LTS then upgraded the kernel and also upgraded to 15.10, to no avail. I'm wondering what I could be doing wrong/differently...

    ReplyDelete
    Replies
    1. Debian 8.3, kernel manually upgraded to 4.4.1.

      Sounds like your system is stuck where mine was for awhile. I fixed it by applying the Lenovo firmware fix (see the Touchscreen section) and then doing a hard-reset.

      The Linux-Wacom guys say that a hard reset is needed every time you boot from Windows to Linux, but they have a patch to address that (see the struckthrough bug report link). I only use the Windows install to do firmware updates, so I only needed to do the hard-reset once.

      Delete
    2. Thanks so much for the quick response! I forgot to mention in my last comment that I did install the firmware update, but it looks like I just didn't do the hard reset correctly. Looking at the bug report helped. Now it works!! I'll go play around a bit with their patch for not resetting every time. (That's not as important for me, though, since I too very rarely use Windows.)

      Thanks for really useful article overall - one of the few articles currently out there for X1 Yoga + Linux :)

      Delete
  6. Hello,

    Thanks for the article, very helpful.

    Thought you might be interested in this script which can control the keyboard backlight:

    https://gist.github.com/vzaliva/0adba7bc40e2f31a0b5f802af2a63267

    (I didn't write it).

    cheers

    Matthew

    ReplyDelete