Skip to content

Instantly share code, notes, and snippets.

@appsforartists
Last active February 27, 2024 09:56
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save appsforartists/da987a725ece3d2aa92052661549eb4c to your computer and use it in GitHub Desktop.
Save appsforartists/da987a725ece3d2aa92052661549eb4c to your computer and use it in GitHub Desktop.
Linux for the Lenovo Legion Go

I've been experimenting with running Linux (specifically NixOS) on the Legion Go. I intend to publish my configuration when it's in a good spot, but also thought it would be handy to have a shared space to document what we all learn in the mean time.

I'm admittedly new to both Linux and Nix, and appreciate any advice others can share too.

What's working

  • Touchscreen
  • Basic gamepad when both controllers are attached/detached
  • Rumble
  • Legion L+X to change perf modes
  • Sound + volume control
  • Power button (when not in Steam - I probably need to tweak my Jovian packages)
  • Trackpad
  • FPS mode (using the right controller as a mouse)
  • WiFi
  • USB keyboard
  • Bluetooth

What's not yet working

  • Rear paddles
  • Legion L/R buttons
  • Most buttons when only one controller is attached
  • Changing the display brightness (this seems to be a Steam gamescope problem - sudo xbacklight works)
  • The battery indicator
  • I tried running American McGee's Alice and the Go would abruptly turn off sometimes. I'm not sure if it's a heat management problem or a general stability problem. (I've been so busy trying to get this to work that I haven't had time to play much on it. I did finish Desk Job with no issues.)

What doesn't work

  • Booting from the SD card slot (doesn't appear in the boot menu)
  • Booting from a DVD (Apple SuperDrive over USB)

Setup

I shrunk the Windows partition to 200G, made a FAT32 boot partition, and formatted the rest as btrfs. home, swap, and nix are subvolumes in btrfs.

NixOS ships with an old kernel. The screen will flicker (unless it's being touched, or the CPU is under load) until you upgrade to the latest kernel.

The kernel needs a couple patches to fix the display orientation and enable the gamepad. I've submitted both for inclusion in the future kernel, but in the mean time, include this section in your configuration.nix to get the basics working:

  boot = lib.mkMerge [
    {
      initrd.kernelModules = ["amdgpu"];
      loader = {
        systemd-boot.enable = true;
        efi.canTouchEfiVariables = true;
      };
    }

    (lib.mkIf (lib.versionOlder pkgs.linux.version "6.8") {
      kernelPackages = lib.mkDefault pkgs.linuxPackages_latest;
      kernelPatches = [
        rec {
          name = "legion-go-display-quirk";
          patch = pkgs.fetchpatch {
            name = name + ".patch";
            url = "https://github.com/appsforartists/linux/compare/master...legion-go-display-quirk.patch";
            sha256 = "sha256-BfqrFUQutcTMlzQdsKvOLhRUIo+63S1imWab4QjBO6c=";
          };
        }
        rec {
          name = "legion-go-controllers";
          patch = pkgs.fetchpatch {
            name = name + ".patch";
            url = "https://github.com/appsforartists/linux/compare/master...legion-go-controllers.patch";
            sha256 = "sha256-2OX8hlsjbqANV1cwZjT4+e5pvLGSNQ/Eh92HK9yT6z4=";
          };
        }
      ];
    })
  ];

I'm using Jovian to run the SteamOS UI (gamescope) on my Go. Using Settings > Controller > Test Device Inputs > Setup Device Inputs, I was able to map the buttons under the D-pad (with the hamburger and change window icons) to menu and capture. This is both what they should have been mapped to originally, and enables gamescope to be usable (since it expects you have a menu button).

Things that need investigation/assistance

Better hardware support

I'm only a couple evenings into this project. I'm happy to have the basics working, but there's still plenty I haven't sorted out yet.

I know there are RyzenAdj and LenovoLegionLinux packages that are probably useful. I did try to use the latter by adding this to the above boot attribute set:

extraModulePackages = [config.boot.kernelPackages.lenovo-legion-module];

That put legion_cli on my command line, but it wasn't finding hwmon. I haven't yet investigated further, but I have shared the logs for onboarding a new device in that repo.

Gamepad paddles, Legion buttons, mapping

Since this was originally designed to be a Windows device, it appears the gamepads use the Xbox 360 controller API. That's supported in the Linux kernel by xpad.

I tried the simplest things (passing MAP_PADDLES into the config, or using the Xbox One controller API), but neither made the extra buttons functional. I also did some stabbing-in-the-dark with libinput and jstest, but couldn't find the events being sent by those buttons.

I suspect if we could log the data value being passed to xpad_process_packet, we could figure out the indicies for each of the missing buttons and wire up the mapping.

I'm new to Linux and not a C programmer, so I suspect others may have an easier time with this piece of the puzzle than I have so far.

Thanks

Massive thanks to @samueldr and @JovianExperiments for their help in this process so far. I wouldn't have ever been a kernel patcher without their encouragement and guidance.

Let's collaborate

If you've tried running Linux on your Legion Go, please share what you've learned (what worked, what didn't, and how you set it up) in the comments below. Let's get this thing working!

@DOOMMARINE117
Copy link

DOOMMARINE117 commented Dec 3, 2023

so its safe to install linux?

im planning on installing neptune os. its a debian distro.

@appsforartists
Copy link
Author

It's what I use exclusively. I occasionally boot Windows if I need to change the fan speed or wanna experiment with e.g. VR, but I do all my gaming in Linux.

@DOOMMARINE117
Copy link

It's what I use exclusively. I occasionally boot Windows if I need to change the fan speed or wanna experiment with e.g. VR, but I do all my gaming in Linux.

sweet, so i be fine then.

how do i install it? the same way i do on computer? just instead of pressing a key i press volume up?

@appsforartists
Copy link
Author

Volume up gets you the boot menu. You need an external USB with an installer on it; the SD card doesn't appear in the boot menu.

I'm using NixOS with Jovian to get the SteamOS UI. You can use whatever distro you like. Bazzite is another popular choice.

@DOOMMARINE117
Copy link

Volume up gets you the boot menu. You need an external USB with an installer on it; the SD card doesn't appear in the boot menu.

I'm using NixOS with Jovian to get the SteamOS UI. You can use whatever distro you like. Bazzite is another popular choice.

yeah i have a usb ready. i be playing mostly dvd games, gog and epic games.

i see, what does volume down do?

@DOOMMARINE117
Copy link

sounds like its pretty easy to install neptune is or other distros

@DOOMMARINE117
Copy link

Volume up gets you the boot menu. You need an external USB with an installer on it; the SD card doesn't appear in the boot menu.

I'm using NixOS with Jovian to get the SteamOS UI. You can use whatever distro you like. Bazzite is another popular choice.

I forgot to ask, should I dual boot or can it be fully Linux?

@DOOMMARINE117
Copy link

got it installed. everything works now. thanks.

@DOOMMARINE117
Copy link

im on the latest kernel all good. everything going smoothly now.

@HougeLangley
Copy link

Thanks for your patches.

For now, my Legion Go running on Gentoo and Steam Great. I write a ebuild build legiongo kernel for device.

This kernel mixed Xanmod patches, your patches, legion-linux patches.

Build with AOCC, benchmark so great.

photo_2023-12-24_19-48-21

@appsforartists
Copy link
Author

I haven't dug into any kernel patches/custom kernels yet beyond the two I needed to make it work.

What differences do you notice with Xanmod? I think I tried to add the Legion Linux patches once, but they didn't do anything for me.

@HougeLangley
Copy link

I haven't dug into any kernel patches/custom kernels yet beyond the two I needed to make it work.

What differences do you notice with Xanmod? I think I tried to add the Legion Linux patches once, but they didn't do anything for me.

FPS will be higher in Xanmod

@offalynne
Copy link

Great work ! WRT gamepad support, could you grab a binary and generate mappings for one and two handed mode for the SDL db for this configuration ? Thanks !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment