linux-surface icon indicating copy to clipboard operation
linux-surface copied to clipboard

Surface laptop studio 2

Open deb75 opened this issue 2 years ago • 133 comments

The surface laptop studio seems well supported by linux-surface.

Do you think linux-surface would also support the surface laptop studio 2 ?

Regards

deb75 avatar Oct 18 '23 20:10 deb75

It's hard to answer that without knowing anything about the device. If we're lucky, not much has changed under the hood. I'll certainly try to support it if I get some reports.

qzed avatar Oct 18 '23 20:10 qzed

Hi @qzed & @deb75

Here is the dmesg file: dmesg.txt

Device: Surface Laptop Studio 2 Distribution: Ubuntu (PopOS) Kernel version: Linux pop-os 6.5.6-surface #3 SMP PREEMPT_DYNAMIC Sun Oct 15 20:52:00 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux

@qzed if you require any further logs, please feel free to mention

CiaranWinna avatar Oct 24 '23 16:10 CiaranWinna

Thanks! The output of our diagnostics script (see https://github.com/linux-surface/linux-surface/wiki/Testers-and-Contributing#support-for-new-devices) would be great. That basically collects all the data we (generally) need to provide initial support (except for the additional testing that someone with a device would need to do, of course).

qzed avatar Oct 25 '23 17:10 qzed

Hi @qzed,

Sure! Here is the requested diagnostic files:

diagnostics.tar.gz acpidump.txt

CiaranWinna avatar Oct 26 '23 00:10 CiaranWinna

Thanks! I've got something to test for you now. Hopefully, this should enable the EC-related components (battery info, platform profile, tablet switch, keyboard/touchpad and related input devices). Essentially, I've copied the stuff that we use for the SLS1 and applied it to the SLS2, so if nothing changed it should work. It will definitely require a bit of follow-up testing (even if it works), but should hopefully get (at least some) things started.

To test, can you follow what I wrote here, just replace the feature/slg3 with feature/sls2.

qzed avatar Oct 26 '23 17:10 qzed

Hi @qzed , I have followed the steps here but the following error is coming up for "make clean all":

`user@pop-os:~/Desktop/Surface Linux/surface-aggregator-module/module$ make clean all

make -C /lib/modules/"6.5.7-surface-2"/build M=/home/user/Desktop/Surface Linux/surface-aggregator-module/module/src clean make[1]: Entering directory '/usr/src/linux-headers-6.5.7-surface-2' make[3]: *** No rule to make target 'Linux/surface-aggregator-module/module/src'. Stop. make[2]: *** [/usr/src/linux-headers-6.5.7-surface-2/Makefile:359: __build_one_by_one] Error 2 make[1]: *** [Makefile:234: __sub-make] Error 2 make[1]: Leaving directory '/usr/src/linux-headers-6.5.7-surface-2' make: *** [Makefile:31: clean] Error 2

user@pop-os:~/Desktop/Surface Linux/surface-aggregator-module/module `

CiaranWinna avatar Oct 31 '23 18:10 CiaranWinna

Ahh, took me a while to spot the issue: Paths in the makefile were not quoted, so it broke due to the witespace. This should be fixed now.

Can you run git pull in the surface-aggregator-module directory (or any of its subdirectories) and then try again from the make clean all?

qzed avatar Nov 01 '23 14:11 qzed

So apparently the SLS2 has two Touch Host Controller devices:

00:10.6 Digitizer Pen [0901]: Intel Corporation Device [8086:51d0] (rev 01)
        Subsystem: Microsoft Corporation Device [1414:0077]
00:10.7 Digitizer Pen [0901]: Intel Corporation Device [8086:51d1] (rev 01)
        Subsystem: Intel Corporation Device [8086:7270]

Presumably the first is the touchscreen, but I wonder what the second one is used for?

Unfortunately ithc currently fails to initialize them:

[    3.045865] ithc 0000:00:10.6: timed out waiting for reg 0x10bc mask 0x0000000f val 0x00000002
[   16.162518] ithc 0000:00:10.7: timed out waiting for reg 0x10bc mask 0x0000000f val 0x00000002

Can you please post your dmesg after restarting ithc with debugging enabled?

sudo modprobe -r ithc
sudo modprobe ithc logregs=1 dyndbg=+pflmt

quo avatar Nov 01 '23 19:11 quo

Hi @qzed & @quo

Here is the output from running make clean all after pulling latest changes: `user@pop-os:~/Desktop/Surface Linux/surface-aggregator-module/module$ make clean all

make -C /lib/modules/"6.5.7-surface-2"/build M="/home/user/Desktop/Surface Linux/surface-aggregator-module/module/src" clean make[1]: Entering directory '/usr/src/linux-headers-6.5.7-surface-2' Makefile:145: *** building multiple external modules is not supported. Stop. make[1]: Leaving directory '/usr/src/linux-headers-6.5.7-surface-2' make: *** [Makefile:31: clean] Error 2

user@pop-os:~/Desktop/Surface Linux/surface-aggregator-module/module$ `

After restarting ithc with debugging enabled, here is the dmesg file: dmesg.log

CiaranWinna avatar Nov 02 '23 14:11 CiaranWinna

If I understand that error correctly, it's another issue with the space in the path. Only this time it seems to be caused by the kernel makefile and not ours. Could you try moving the directory to some path without a space?

qzed avatar Nov 02 '23 20:11 qzed

Thanks. So from the dmesg it looks like the state register isn't doing anything.

I had a look inside the driver package for the SLS2. It looks like the THC has been renamed to the "Quick SPI" Host Controller. While the PCI device ID is the same and many of the old THC registers still seem to be used, the new UEFI Quick SPI driver also uses a bunch of previously unused/unknown registers. I haven't looked at the Windows Quick SPI driver yet.

I may try to continue reverse engineering this a bit more. But I think it's unlikely I'll be able to get it working without access to the actual hardware.

quo avatar Nov 03 '23 00:11 quo

Hi @qzed , As you mentioned, changing the directory corrected the issue. I got the following fatal error when running make modprobe-unload: user@pop-os:~/Desktop/Surface_Linux/surface-aggregator-module/module$ make modprobe-unload [sudo] password for ciaranwinnan: modprobe: FATAL: Module battery is builtin. modprobe: FATAL: Module ac is builtin. user@pop-os:~/Desktop/Surface_Linux/surface-aggregator-module/module$

After running make insmod battery stats and percentage now show up: Screenshot from 2023-11-03 00-51-25 Screenshot from 2023-11-03 01-11-06

Profiles are also active now: Screenshot from 2023-11-03 00-55-18

Keyboard is also working now.

Touchpad and touchscreen is not working

CiaranWinna avatar Nov 03 '23 00:11 CiaranWinna

@CiaranWinna Thanks! Could you also upload a dmesg log while the modules are loaded so that I can check that there are no other (obvious) issues?

For the touchpad, I'm assuming it's a similar issue as on the SLS1, so you could try adapting the quirk from here. You will likely need to change the MatchProduct line to the touchpad product ID (which you should be able to find via the dmesg log or sysfs).

We should also do some more proper testing on the HID-via-SAM devices and other SAM/EC components to make sure they haven't changed. But that's for after we have some preliminary support in the kernel.

qzed avatar Nov 03 '23 18:11 qzed

The modprobe: FATAL: Module ac is builtin you can ignore. The script responsible for loading/unloading the modules tries to unload the ac and battery modules before unloading the surface/SAM related modules. But we just do that so that userspace doesn't think that there's something wrong with the battery.

In your case, it seems that ac is built in and hence cannot be unloaded. It should just print the error but then continue on with the rest. In case of newer devices like the SLS2, it's also not really necessary to unload those two modules because they're not used in the first place.

qzed avatar Nov 03 '23 18:11 qzed

Hi @qzed , Thank you I will give that a go! Here is the dmesg.log after the modules have been loaded.

CiaranWinna avatar Nov 04 '23 09:11 CiaranWinna

Okay, so it looks like two HID devices have changed. Either they moved their address or removed them:

[  354.730342] surface_hid 01:15:01:03:00: unexpected descriptor length: got 0, expected 9
[  354.730358] surface_hid: probe of 01:15:01:03:00 failed with error -71
[  354.732415] surface_hid 01:15:01:08:00: unexpected descriptor length: got 0, expected 9
[  354.732432] surface_hid: probe of 01:15:01:08:00 failed with error -71

So the affected devices are

01:15:01:03:00 - previously touchpad
01:15:01:08:00 - previously sysctrl

So unless they merged the touchpad and keyboard HID devices, that might explain why the touchpad isn't working.

To figure out which HID devices are present on which addresses, can you run (with the modules loaded) the following commands and post their outputs? The script is also in the SAM repo. In particular, run

sudo ./scripts/ssam/hid.py hid-get-descriptor 1 x 1

replacing x with 0 up to (including) 15. This essentially tries to read the HID descriptor from the (sub-)device identified by the number x.

With x=1 and x=2. the command should definitely print something (1 was the keyboard, 2 was the pen stash on the SLS1). The x=3 should print an empty array (that was the touchpad, but as I've written above, that seems to have changed). If the script throws any errors, please post them as well (this should normally not happen).

We also may need to look at adding an entry for our Surface GPE driver, but that's for later after the other things work I guess.

qzed avatar Nov 05 '23 14:11 qzed

I suspect the touchpad is connected to the second THC.

From SurfaceLaptopStudio2_Win11_22621_23.074.39397.0/SurfaceUpdate/surfacehidfriendlynames/SurfaceHIDFriendlyNames.inf:

; Surface Laptop Studio 2 Touchpad
%DeviceDesc% = PenUtilityDesc, HID\VID_045E&UP:FF0D_U:0001
%DeviceDesc% = TouchpadCommunicationsDesc, HID\VID_045E&UP:FF0B_U:000F

And from SurfaceLaptopStudio2_Win11_22621_23.074.39397.0/SurfaceUpdate/surfacetrackpadcfu/SurfaceTouchpadG7CfuOverHidExtnPackage.inf:

%SurfaceTouchpadG7CfuOverHidExtnPackage.ExtensionDesc%=SurfaceTouchpadG7CfuOverHidExtnPackage, HID\VEN_8086&DEV_51D1&SUBSYS_72708086&Col03

PCI device ID 8086:51d1 is the second THC. The subsystem ID also matches.

The UP:FF0B makes me a little worried that it's not standard HID, and maybe heatmap based like the touchscreen.

The THC registers contain some left-over values from the UEFI Quick SPI initialization which contain the VID/PID of the touch devices:

[ 4861.318505] ithc 0000:00:10.6: reg 105c: 00000000 -> 0c5d045e
[ 4874.517427] ithc 0000:00:10.7: reg 105c: 00000000 -> 0c46045e

So THC0 = 045e:0c5d, THC1 = 045e:0c46. 0c5d shows up in filenames for touch/pen in the update package, but I can't find any references to 0c46.

quo avatar Nov 05 '23 17:11 quo

0c5d shows up in filenames for touch/pen in the update package, but I can't find any references to 0c46.

There is a TouchPenProcessor dll with that ID in the name:

dorian@desktop ~/Downloads/SurfaceUpdate % find . -name 'TouchPenProcessor*'
./surfacetouchmw/TouchPenProcessor0C5D.dll
./surfacetrackpadmw/TouchPenProcessor0C46.dll

These two dlls are also 19M each so maybe they forgot to strip the debug symbols again?

StollD avatar Nov 05 '23 17:11 StollD

You're right, I missed that dll somehow! Doesn't look like there's full debug symbols, but the dlls do contains some absolutely massive functions. Possibly someone cranked up the inlining settings to the max.

quo avatar Nov 05 '23 18:11 quo

Urgh... so looks like even the touchpad now needs a user-space service. That will probably be slightly annoying.

qzed avatar Nov 05 '23 18:11 qzed

Hi @qzed , Here is the requested output with modules loaded: ciaranwinnan@pop-os:~/Desktop/Surface_linux/surface-aggregator-module$ sudo ./scripts/ssam/hid.py hid-get-descriptor 1 0 1 [] ciaranwinnan@pop-os:~/Desktop/Surface_linux/surface-aggregator-module$

ciaranwinnan@pop-os:~/Desktop/Surface_linux/surface-aggregator-module$ sudo ./scripts/ssam/hid.py hid-get-descriptor 1 1 1 [5, 1, 9, 6, 161, 1, 133, 1, 21, 0, 37, 1, 117, 1, 149, 8, 5, 7, 25, 224, 41, 231, 129, 2, 117, 8, 149, 10, 25, 0, 41, 145, 38, 255, 0, 129, 0, 5, 12, 10, 192, 2, 161, 2, 26, 193, 2, 42, 198, 2, 149, 6, 177, 3, 192, 5, 8, 25, 1, 41, 3, 117, 1, 149, 3, 37, 1, 145, 2, 149, 5, 145, 1, 192, 5, 1, 9, 128, 161, 1, 133, 91, 21, 0, 37, 1, 117, 1, 149, 3, 9, 151, 9, 152, 9, 153, 129, 2, 149, 5, 129, 1, 192, 5, 12, 9, 1, 161, 1, 133, 3, 149, 1, 117, 16, 21, 0, 38, 255, 3, 25, 0, 42, 255, 3, 129, 0, 192, 5, 1, 9, 19, 161, 1, 133, 94, 117, 1, 149, 1, 21, 0, 37, 1, 5, 1, 9, 225, 129, 2, 149, 7, 129, 1, 192] ciaranwinnan@pop-os:~/Desktop/Surface_linux/surface-aggregator-module$

ciaranwinnan@pop-os:~/Desktop/Surface_linux/surface-aggregator-module$ sudo ./scripts/ssam/hid.py hid-get-descriptor 1 2 1 [5, 1, 9, 6, 161, 1, 133, 92, 21, 0, 37, 1, 117, 1, 149, 8, 5, 7, 25, 224, 41, 231, 129, 2, 25, 109, 41, 111, 117, 1, 149, 3, 129, 2, 149, 5, 129, 3, 192, 6, 244, 255, 9, 10, 161, 1, 9, 11, 161, 2, 133, 20, 9, 2, 21, 0, 38, 255, 0, 117, 8, 149, 6, 130, 2, 1, 9, 8, 21, 0, 37, 1, 117, 1, 149, 1, 129, 2, 9, 13, 21, 0, 37, 1, 117, 1, 149, 1, 129, 2, 9, 14, 21, 0, 37, 1, 117, 1, 149, 1, 129, 2, 117, 5, 149, 1, 129, 3, 9, 12, 21, 0, 37, 100, 117, 8, 149, 1, 129, 2, 192, 192, 6, 244, 255, 9, 1, 161, 1, 9, 7, 161, 2, 133, 84, 6, 15, 255, 9, 80, 21, 0, 38, 255, 0, 117, 8, 149, 4, 130, 2, 1, 6, 244, 255, 9, 2, 21, 0, 38, 255, 0, 117, 8, 149, 6, 130, 2, 1, 9, 8, 21, 0, 37, 1, 117, 1, 149, 1, 129, 2, 117, 7, 149, 1, 129, 1, 192, 9, 5, 161, 2, 133, 85, 6, 15, 255, 9, 80, 21, 0, 38, 255, 0, 117, 8, 149, 4, 146, 2, 1, 6, 244, 255, 9, 2, 21, 0, 38, 255, 0, 117, 8, 149, 6, 146, 2, 1, 9, 8, 21, 0, 37, 1, 117, 1, 149, 1, 145, 2, 117, 7, 149, 1, 145, 1, 9, 4, 21, 0, 38, 255, 0, 117, 8, 149, 8, 146, 2, 1, 192, 9, 6, 161, 2, 133, 86, 9, 3, 21, 0, 38, 255, 0, 117, 8, 149, 6, 178, 2, 1, 9, 9, 21, 0, 37, 1, 117, 1, 149, 1, 177, 2, 117, 7, 149, 1, 177, 1, 192, 192] ciaranwinnan@pop-os:~/Desktop/Surface_linux/surface-aggregator-module$

ciaranwinnan@pop-os:~/Desktop/Surface_linux/surface-aggregator-module$ sudo ./scripts/ssam/hid.py hid-get-descriptor 1 3 1 [] ciaranwinnan@pop-os:~/Desktop/Surface_linux/surface-aggregator-module$

ciaranwinnan@pop-os:~/Desktop/Surface_linux/surface-aggregator-module$ sudo ./scripts/ssam/hid.py hid-get-descriptor 1 4 1 [] ciaranwinnan@pop-os:~/Desktop/Surface_linux/surface-aggregator-module$

ciaranwinnan@pop-os:~/Desktop/Surface_linux/surface-aggregator-module$ sudo ./scripts/ssam/hid.py hid-get-descriptor 1 5 1 [] ciaranwinnan@pop-os:~/Desktop/Surface_linux/surface-aggregator-module$

ciaranwinnan@pop-os:~/Desktop/Surface_linux/surface-aggregator-module$ sudo ./scripts/ssam/hid.py hid-get-descriptor 1 6 1 [5, 32, 9, 1, 161, 1, 133, 137, 5, 32, 9, 65, 161, 0, 5, 32, 10, 9, 3, 21, 0, 37, 2, 117, 8, 149, 1, 161, 2, 10, 48, 8, 10, 49, 8, 10, 50, 8, 177, 0, 192, 10, 22, 3, 21, 0, 37, 5, 117, 8, 149, 1, 161, 2, 10, 64, 8, 10, 65, 8, 10, 66, 8, 10, 67, 8, 10, 68, 8, 10, 69, 8, 177, 0, 192, 10, 25, 3, 21, 0, 37, 5, 117, 8, 149, 1, 161, 2, 10, 80, 8, 10, 81, 8, 10, 82, 8, 10, 83, 8, 10, 84, 8, 10, 85, 8, 177, 0, 192, 10, 1, 2, 21, 0, 37, 6, 117, 8, 149, 1, 161, 2, 10, 0, 8, 10, 1, 8, 10, 2, 8, 10, 3, 8, 10, 4, 8, 10, 5, 8, 10, 6, 8, 177, 0, 192, 10, 14, 3, 21, 0, 39, 255, 255, 255, 127, 117, 32, 149, 1, 85, 0, 177, 2, 10, 4, 3, 21, 0, 39, 255, 255, 255, 255, 117, 32, 149, 1, 85, 0, 177, 2, 10, 209, 228, 21, 0, 38, 255, 255, 117, 16, 149, 1, 85, 14, 177, 2, 10, 209, 20, 177, 2, 10, 212, 20, 85, 12, 177, 2, 10, 213, 20, 177, 2, 10, 226, 4, 21, 0, 37, 1, 117, 8, 149, 1, 85, 0, 177, 2, 10, 227, 4, 177, 2, 5, 32, 10, 1, 2, 21, 0, 37, 6, 117, 8, 149, 1, 161, 2, 10, 0, 8, 10, 1, 8, 10, 2, 8, 10, 3, 8, 10, 4, 8, 10, 5, 8, 10, 6, 8, 129, 0, 192, 10, 2, 2, 21, 0, 37, 5, 117, 8, 149, 1, 161, 2, 10, 16, 8, 10, 17, 8, 10, 18, 8, 10, 19, 8, 10, 20, 8, 10, 21, 8, 129, 0, 192, 10, 209, 4, 23, 0, 0, 0, 0, 39, 255, 255, 255, 255, 117, 32, 149, 1, 85, 14, 129, 2, 10, 212, 4, 22, 0, 0, 38, 255, 255, 117, 16, 85, 12, 149, 1, 129, 2, 10, 213, 4, 129, 2, 192, 133, 177, 5, 32, 9, 138, 161, 0, 5, 32, 10, 9, 3, 21, 0, 37, 2, 117, 8, 149, 1, 161, 2, 10, 48, 8, 10, 49, 8, 10, 50, 8, 177, 0, 192, 10, 22, 3, 21, 0, 37, 5, 117, 8, 149, 1, 161, 2, 10, 64, 8, 10, 65, 8, 10, 66, 8, 10, 67, 8, 10, 68, 8, 10, 69, 8, 177, 0, 192, 10, 25, 3, 21, 0, 37, 5, 117, 8, 149, 1, 161, 2, 10, 80, 8, 10, 81, 8, 10, 82, 8, 10, 83, 8, 10, 84, 8, 10, 85, 8, 177, 0, 192, 10, 1, 2, 21, 0, 37, 6, 117, 8, 149, 1, 161, 2, 10, 0, 8, 10, 1, 8, 10, 2, 8, 10, 3, 8, 10, 4, 8, 10, 5, 8, 10, 6, 8, 177, 0, 192, 10, 14, 3, 21, 0, 39, 255, 255, 255, 127, 117, 32, 149, 1, 85, 0, 177, 2, 10, 131, 20, 21, 0, 38, 160, 140, 117, 16, 149, 1, 85, 14, 177, 2, 10, 4, 3, 21, 0, 39, 255, 255, 255, 127, 117, 32, 149, 1, 85, 0, 177, 2, 5, 32, 5, 32, 10, 1, 2, 21, 0, 37, 6, 117, 8, 149, 1, 161, 2, 10, 0, 8, 10, 1, 8, 10, 2, 8, 10, 3, 8, 10, 4, 8, 10, 5, 8, 10, 6, 8, 129, 0, 192, 10, 2, 2, 21, 0, 37, 5, 117, 8, 149, 1, 161, 2, 10, 16, 8, 10, 17, 8, 10, 18, 8, 10, 19, 8, 10, 20, 8, 10, 21, 8, 129, 0, 192, 10, 131, 4, 23, 1, 0, 0, 128, 39, 255, 255, 255, 127, 117, 32, 149, 4, 101, 0, 85, 10, 129, 2, 10, 136, 4, 22, 0, 0, 38, 255, 255, 117, 16, 149, 1, 161, 2, 10, 224, 8, 10, 225, 8, 10, 226, 8, 129, 0, 192, 192, 133, 161, 5, 32, 9, 115, 161, 0, 5, 32, 10, 9, 3, 21, 0, 37, 2, 117, 8, 149, 1, 161, 2, 10, 48, 8, 10, 49, 8, 10, 50, 8, 177, 0, 192, 10, 22, 3, 21, 0, 37, 5, 117, 8, 149, 1, 161, 2, 10, 64, 8, 10, 65, 8, 10, 66, 8, 10, 67, 8, 10, 68, 8, 10, 69, 8, 177, 0, 192, 10, 25, 3, 21, 0, 37, 5, 117, 8, 149, 1, 161, 2, 10, 80, 8, 10, 81, 8, 10, 82, 8, 10, 83, 8, 10, 84, 8, 10, 85, 8, 177, 0, 192, 10, 1, 2, 21, 0, 37, 6, 117, 8, 149, 1, 161, 2, 10, 0, 8, 10, 1, 8, 10, 2, 8, 10, 3, 8, 10, 4, 8, 10, 5, 8, 10, 6, 8, 177, 0, 192, 10, 14, 3, 21, 0, 39, 255, 255, 255, 127, 117, 32, 149, 1, 85, 0, 177, 2, 10, 4, 3, 21, 0, 39, 255, 255, 255, 127, 117, 32, 149, 1, 85, 0, 177, 2, 10, 82, 20, 21, 0, 38, 255, 255, 117, 16, 149, 1, 85, 13, 177, 2, 5, 32, 5, 32, 10, 1, 2, 21, 0, 37, 6, 117, 8, 149, 1, 161, 2, 10, 0, 8, 10, 1, 8, 10, 2, 8, 10, 3, 8, 10, 4, 8, 10, 5, 8, 10, 6, 8, 129, 0, 192, 10, 2, 2, 21, 0, 37, 5, 117, 8, 149, 1, 161, 2, 10, 16, 8, 10, 17, 8, 10, 18, 8, 10, 19, 8, 10, 20, 8, 10, 21, 8, 129, 0, 192, 10, 83, 4, 22, 1, 128, 38, 255, 127, 117, 16, 149, 1, 85, 13, 129, 2, 10, 84, 4, 22, 1, 128, 38, 255, 127, 117, 16, 149, 1, 85, 13, 129, 2, 10, 85, 4, 22, 1, 128, 38, 255, 127, 117, 16, 149, 1, 85, 13, 129, 2, 192, 133, 180, 5, 32, 9, 118, 161, 0, 5, 32, 10, 9, 3, 21, 0, 37, 2, 117, 8, 149, 1, 161, 2, 10, 48, 8, 10, 49, 8, 10, 50, 8, 177, 0, 192, 10, 22, 3, 21, 0, 37, 5, 117, 8, 149, 1, 161, 2, 10, 64, 8, 10, 65, 8, 10, 66, 8, 10, 67, 8, 10, 68, 8, 10, 69, 8, 177, 0, 192, 10, 25, 3, 21, 0, 37, 5, 117, 8, 149, 1, 161, 2, 10, 80, 8, 10, 81, 8, 10, 82, 8, 10, 83, 8, 10, 84, 8, 10, 85, 8, 177, 0, 192, 10, 1, 2, 21, 0, 37, 6, 117, 8, 149, 1, 161, 2, 10, 0, 8, 10, 1, 8, 10, 2, 8, 10, 3, 8, 10, 4, 8, 10, 5, 8, 10, 6, 8, 177, 0, 192, 10, 14, 3, 21, 0, 39, 255, 255, 255, 127, 117, 32, 149, 1, 85, 0, 177, 2, 10, 4, 3, 21, 0, 39, 255, 255, 255, 127, 117, 32, 149, 1, 85, 0, 177, 2, 10, 86, 20, 21, 0, 38, 255, 255, 117, 16, 149, 1, 85, 14, 177, 2, 5, 32, 5, 32, 10, 1, 2, 21, 0, 37, 6, 117, 8, 149, 1, 161, 2, 10, 0, 8, 10, 1, 8, 10, 2, 8, 10, 3, 8, 10, 4, 8, 10, 5, 8, 10, 6, 8, 129, 0, 192, 10, 2, 2, 21, 0, 37, 5, 117, 8, 149, 1, 161, 2, 10, 16, 8, 10, 17, 8, 10, 18, 8, 10, 19, 8, 10, 20, 8, 10, 21, 8, 129, 0, 192, 10, 87, 4, 23, 1, 0, 0, 128, 39, 255, 255, 255, 127, 117, 32, 149, 1, 85, 10, 129, 2, 10, 88, 4, 23, 1, 0, 0, 128, 39, 255, 255, 255, 127, 117, 32, 149, 1, 85, 10, 129, 2, 10, 89, 4, 23, 1, 0, 0, 128, 39, 255, 255, 255, 127, 117, 32, 149, 1, 85, 10, 129, 2, 192, 133, 165, 5, 32, 9, 124, 161, 0, 5, 32, 10, 9, 3, 21, 0, 37, 2, 117, 8, 149, 1, 161, 2, 10, 48, 8, 10, 49, 8, 10, 50, 8, 177, 0, 192, 10, 22, 3, 21, 0, 37, 5, 117, 8, 149, 1, 161, 2, 10, 64, 8, 10, 65, 8, 10, 66, 8, 10, 67, 8, 10, 68, 8, 10, 69, 8, 177, 0, 192, 10, 25, 3, 21, 0, 37, 5, 117, 8, 149, 1, 161, 2, 10, 80, 8, 10, 81, 8, 10, 82, 8, 10, 83, 8, 10, 84, 8, 10, 85, 8, 177, 0, 192, 10, 1, 2, 21, 0, 37, 6, 117, 8, 149, 1, 161, 2, 10, 0, 8, 10, 1, 8, 10, 2, 8, 10, 3, 8, 10, 4, 8, 10, 5, 8, 10, 6, 8, 177, 0, 192, 10, 14, 3, 21, 0, 39, 255, 255, 255, 127, 117, 32, 149, 1, 85, 0, 177, 2, 10, 4, 3, 21, 0, 39, 255, 255, 255, 127, 117, 32, 149, 1, 85, 0, 177, 2, 10, 82, 20, 21, 0, 38, 255, 255, 117, 16, 149, 1, 85, 13, 177, 2, 5, 32, 5, 32, 10, 1, 2, 21, 0, 37, 6, 117, 8, 149, 1, 161, 2, 10, 0, 8, 10, 1, 8, 10, 2, 8, 10, 3, 8, 10, 4, 8, 10, 5, 8, 10, 6, 8, 129, 0, 192, 10, 2, 2, 21, 0, 37, 5, 117, 8, 149, 1, 161, 2, 10, 16, 8, 10, 17, 8, 10, 18, 8, 10, 19, 8, 10, 20, 8, 10, 21, 8, 129, 0, 192, 10, 83, 4, 22, 1, 128, 38, 255, 127, 117, 16, 149, 1, 85, 13, 129, 2, 10, 84, 4, 129, 2, 10, 85, 4, 129, 2, 192, 133, 179, 5, 32, 9, 134, 161, 0, 5, 32, 10, 9, 3, 21, 0, 37, 2, 117, 8, 149, 1, 161, 2, 10, 48, 8, 10, 49, 8, 10, 50, 8, 177, 0, 192, 10, 22, 3, 21, 0, 37, 5, 117, 8, 149, 1, 161, 2, 10, 64, 8, 10, 65, 8, 10, 66, 8, 10, 67, 8, 10, 68, 8, 10, 69, 8, 177, 0, 192, 10, 25, 3, 21, 0, 37, 5, 117, 8, 149, 1, 161, 2, 10, 80, 8, 10, 81, 8, 10, 82, 8, 10, 83, 8, 10, 84, 8, 10, 85, 8, 177, 0, 192, 10, 1, 2, 21, 0, 37, 6, 117, 8, 149, 1, 161, 2, 10, 0, 8, 10, 1, 8, 10, 2, 8, 10, 3, 8, 10, 4, 8, 10, 5, 8, 10, 6, 8, 177, 0, 192, 10, 14, 3, 21, 0, 39, 255, 255, 255, 127, 117, 32, 149, 1, 85, 0, 177, 2, 10, 4, 3, 21, 0, 39, 255, 255, 255, 127, 117, 32, 149, 1, 85, 0, 177, 2, 10, 126, 20, 21, 0, 38, 255, 255, 117, 16, 149, 1, 85, 14, 177, 2, 5, 32, 5, 32, 10, 1, 2, 21, 0, 37, 6, 117, 8, 149, 1, 161, 2, 10, 0, 8, 10, 1, 8, 10, 2, 8, 10, 3, 8, 10, 4, 8, 10, 5, 8, 10, 6, 8, 129, 0, 192, 10, 2, 2, 21, 0, 37, 5, 117, 8, 149, 1, 161, 2, 10, 16, 8, 10, 17, 8, 10, 18, 8, 10, 19, 8, 10, 20, 8, 10, 21, 8, 129, 0, 192, 10, 127, 4, 22, 1, 128, 38, 255, 127, 117, 16, 149, 1, 85, 14, 129, 2, 10, 128, 4, 22, 1, 128, 38, 255, 127, 117, 16, 149, 1, 85, 14, 129, 2, 10, 129, 4, 22, 1, 128, 38, 255, 127, 117, 16, 149, 1, 85, 14, 129, 2, 10, 136, 4, 22, 0, 0, 38, 255, 255, 117, 16, 149, 1, 161, 2, 10, 224, 8, 10, 225, 8, 10, 226, 8, 129, 0, 192, 192, 133, 178, 5, 32, 9, 131, 161, 0, 5, 32, 10, 9, 3, 21, 0, 37, 2, 117, 8, 149, 1, 161, 2, 10, 48, 8, 10, 49, 8, 10, 50, 8, 177, 0, 192, 10, 22, 3, 21, 0, 37, 5, 117, 8, 149, 1, 161, 2, 10, 64, 8, 10, 65, 8, 10, 66, 8, 10, 67, 8, 10, 68, 8, 10, 69, 8, 177, 0, 192, 10, 25, 3, 21, 0, 37, 5, 117, 8, 149, 1, 161, 2, 10, 80, 8, 10, 81, 8, 10, 82, 8, 10, 83, 8, 10, 84, 8, 10, 85, 8, 177, 0, 192, 10, 1, 2, 21, 0, 37, 6, 117, 8, 149, 1, 161, 2, 10, 0, 8, 10, 1, 8, 10, 2, 8, 10, 3, 8, 10, 4, 8, 10, 5, 8, 10, 6, 8, 177, 0, 192, 10, 14, 3, 21, 0, 39, 255, 255, 255, 127, 117, 32, 149, 1, 85, 0, 177, 2, 10, 4, 3, 21, 0, 39, 255, 255, 255, 127, 117, 32, 149, 1, 85, 0, 177, 2, 10, 113, 20, 21, 0, 38, 255, 255, 117, 16, 149, 1, 85, 14, 177, 2, 5, 32, 5, 32, 10, 1, 2, 21, 0, 37, 6, 117, 8, 149, 1, 161, 2, 10, 0, 8, 10, 1, 8, 10, 2, 8, 10, 3, 8, 10, 4, 8, 10, 5, 8, 10, 6, 8, 129, 0, 192, 10, 2, 2, 21, 0, 37, 5, 117, 8, 149, 1, 161, 2, 10, 16, 8, 10, 17, 8, 10, 18, 8, 10, 19, 8, 10, 20, 8, 10, 21, 8, 129, 0, 192, 10, 118, 4, 22, 1, 128, 38, 255, 127, 117, 16, 149, 1, 85, 15, 129, 2, 10, 136, 4, 22, 0, 0, 38, 255, 255, 117, 16, 149, 1, 161, 2, 10, 224, 8, 10, 225, 8, 10, 226, 8, 129, 0, 192, 192, 133, 166, 5, 32, 9, 123, 161, 0, 5, 32, 10, 9, 3, 21, 0, 37, 2, 117, 8, 149, 1, 161, 2, 10, 48, 8, 10, 49, 8, 10, 50, 8, 177, 0, 192, 10, 22, 3, 21, 0, 37, 5, 117, 8, 149, 1, 161, 2, 10, 64, 8, 10, 65, 8, 10, 66, 8, 10, 67, 8, 10, 68, 8, 10, 69, 8, 177, 0, 192, 10, 25, 3, 21, 0, 37, 5, 117, 8, 149, 1, 161, 2, 10, 80, 8, 10, 81, 8, 10, 82, 8, 10, 83, 8, 10, 84, 8, 10, 85, 8, 177, 0, 192, 10, 1, 2, 21, 0, 37, 6, 117, 8, 149, 1, 161, 2, 10, 0, 8, 10, 1, 8, 10, 2, 8, 10, 3, 8, 10, 4, 8, 10, 5, 8, 10, 6, 8, 177, 0, 192, 10, 14, 3, 21, 0, 39, 255, 255, 255, 127, 117, 32, 149, 1, 85, 0, 177, 2, 10, 4, 3, 21, 0, 39, 255, 255, 255, 127, 117, 32, 149, 1, 85, 0, 177, 2, 10, 82, 20, 21, 0, 38, 255, 255, 117, 16, 149, 1, 85, 13, 177, 2, 5, 32, 5, 32, 10, 1, 2, 21, 0, 37, 6, 117, 8, 149, 1, 161, 2, 10, 0, 8, 10, 1, 8, 10, 2, 8, 10, 3, 8, 10, 4, 8, 10, 5, 8, 10, 6, 8, 129, 0, 192, 10, 2, 2, 21, 0, 37, 5, 117, 8, 149, 1, 161, 2, 10, 16, 8, 10, 17, 8, 10, 18, 8, 10, 19, 8, 10, 20, 8, 10, 21, 8, 129, 0, 192, 10, 83, 4, 22, 1, 128, 38, 255, 127, 117, 16, 149, 1, 85, 13, 129, 2, 10, 84, 4, 129, 2, 10, 85, 4, 129, 2, 192, 192] ciaranwinnan@pop-os:~/Desktop/Surface_linux/surface-aggregator-module$

ciaranwinnan@pop-os:~/Desktop/Surface_linux/surface-aggregator-module$ sudo ./scripts/ssam/hid.py hid-get-descriptor 1 7 1 [6, 0, 255, 10, 0, 249, 161, 1, 133, 50, 117, 16, 149, 2, 21, 0, 39, 255, 255, 0, 0, 10, 1, 249, 10, 6, 249, 177, 2, 117, 32, 149, 1, 39, 255, 255, 255, 127, 10, 2, 249, 177, 2, 117, 8, 149, 8, 38, 255, 0, 10, 3, 249, 178, 2, 1, 149, 16, 10, 4, 249, 178, 2, 1, 10, 5, 249, 178, 2, 1, 117, 16, 149, 1, 39, 255, 255, 0, 0, 10, 6, 249, 129, 2, 117, 8, 149, 1, 133, 51, 21, 0, 38, 255, 0, 10, 7, 249, 177, 2, 38, 1, 0, 10, 8, 249, 177, 2, 192] ciaranwinnan@pop-os:~/Desktop/Surface_linux/surface-aggregator-module$

ciaranwinnan@pop-os:~/Desktop/Surface_linux/surface-aggregator-module$ sudo ./scripts/ssam/hid.py hid-get-descriptor 1 8 1 [] ciaranwinnan@pop-os:~/Desktop/Surface_linux/surface-aggregator-module$

ciaranwinnan@pop-os:~/Desktop/Surface_linux/surface-aggregator-module$ sudo ./scripts/ssam/hid.py hid-get-descriptor 1 9 1 [] ciaranwinnan@pop-os:~/Desktop/Surface_linux/surface-aggregator-module$

ciaranwinnan@pop-os:~/Desktop/Surface_linux/surface-aggregator-module$ sudo ./scripts/ssam/hid.py hid-get-descriptor 1 10 1 [] ciaranwinnan@pop-os:~/Desktop/Surface_linux/surface-aggregator-module$

ciaranwinnan@pop-os:~/Desktop/Surface_linux/surface-aggregator-module$ sudo ./scripts/ssam/hid.py hid-get-descriptor 1 11 1 [] ciaranwinnan@pop-os:~/Desktop/Surface_linux/surface-aggregator-module$

ciaranwinnan@pop-os:~/Desktop/Surface_linux/surface-aggregator-module$ sudo ./scripts/ssam/hid.py hid-get-descriptor 1 12 1 [] ciaranwinnan@pop-os:~/Desktop/Surface_linux/surface-aggregator-module$

ciaranwinnan@pop-os:~/Desktop/Surface_linux/surface-aggregator-module$ sudo ./scripts/ssam/hid.py hid-get-descriptor 1 13 1 [] ciaranwinnan@pop-os:~/Desktop/Surface_linux/surface-aggregator-module$

ciaranwinnan@pop-os:~/Desktop/Surface_linux/surface-aggregator-module$ sudo ./scripts/ssam/hid.py hid-get-descriptor 1 14 1 [] ciaranwinnan@pop-os:~/Desktop/Surface_linux/surface-aggregator-module$

ciaranwinnan@pop-os:~/Desktop/Surface_linux/surface-aggregator-module$ sudo ./scripts/ssam/hid.py hid-get-descriptor 1 15 1 [] ciaranwinnan@pop-os:~/Desktop/Surface_linux/surface-aggregator-module$

CiaranWinna avatar Nov 05 '23 22:11 CiaranWinna

Hi,

As far as I understand, up to now, battery stats and keyboard are working, but not touchpad and touchscreen.

I just wanted to know at this stage if you think that linux-surface may support the SLS2 with some work, or if support will hopelessly be limited in some ways (no touchscreen, pen and/or touchpad)

Regards

deb75 avatar Nov 11 '23 13:11 deb75

@deb75 I can't say... Touchpad and touchscreen depend on ITHC, which I know next to nothing about. I guess @quo could make a more educated guess here. If ITHC works, we'll quite likely at least have touchscreen support. Depends on how similar the touchpad is to the touchscreen, but I guess that might also need some special processing or even a separate IPTSd. Unless we're in luck and it sends standard HID data (... but I guess that's unlikely since they ship a processor dll and drive it via ITHC in the first place). So that might take longer.

Apart from that, I'm confident that EC support (keyboard, battery stats) will land in our kernel soon, after which I'll send them upstream.

qzed avatar Nov 11 '23 14:11 qzed

@CiaranWinna Thanks, that looks good so far. Now, there's two things we should still check: Enabling/disabling of HID devices and the tablet mode switch.

For the first, can you (again with the modules loaded) run

./scripts/ssam/evreg.py reg1-disable 0x15 0x00 0x01

and verify that this disables the keyboard? Similarly, running

./scripts/ssam/evreg.py reg1-enable 0x15 0x00 0x01

should enable it again.

For the tablet mode/orientation switch, can you run sudo evtest and select the device with a name similar to Microsoft Surface POS Tablet Mode Switch. Then while that is running flip the display around into a tablet-like state and check that there is some output that indicates those changes (in particular, there should be a SW_TABLET_MODE value changing from 0 to 1. In addition can you run

cat /sys/bus/surface_aggregator/devices/01:26:01:00:01/state

in various states (e.g. tent-mode, tablet-mode, normal laptop mode). The output should also change accordingly.

It would be great if you could also post a dmesg log from doing those things, so that we can check if there were any errors.

qzed avatar Nov 11 '23 15:11 qzed

Depends on how similar the touchpad is to the touchscreen, but I guess that might also need some special processing or even a separate IPTSd. Unless we're in luck and it sends standard HID data (... but I guess that's unlikely since they ship a processor dll and drive it via ITHC in the first place). So that might take longer.

Dumping the HID report descriptor of the touchpad device and some HID traffic from windows could help, then I could start looking at the data and adapting iptsd.

Unfortunately, I have no idea how to do that under Windows.

StollD avatar Nov 11 '23 15:11 StollD

I've reverse engineered bits of the new touch stuff. Basically, the THC runs in an alternate mode called "Quick SPI". The mode is selected by the platform firmware, so I don't think we can set it back to "normal" mode.

Quick SPI aims to be compatible with the HID-over-SPI spec MS published. So theoretically, in this mode ithc should provide an SPI device which could then get picked up by Microsoft's spi-hid driver. (But it'll probably be easier to just handle the HID-over-SPI stuff inside ithc, at least initially.)

Initialization is a bit more involved than normal THC init. Some values need to be retrieved using ACPI calls and written to the correct registers. Reading the device config works a little differently. I think DMA works the same, although the buffers now use HID-over-SPI format.

I'll try to add Quick SPI support to the ithc driver when I have some time, maybe next month. Of course since I don't have the hardware myself, it's unlikely it'll work first try, we'll probably have to spend some time debugging.

quo avatar Nov 11 '23 20:11 quo

Hi @qzed , Here is the dmesg logs from disabling/enabling the keyboard:

I can confirm that the keyboard was successfully disabled and enabled

In regards to running sudo evtest, the command is not recognized: ciaranwinnan@pop-os:~/Desktop/Surface_linux/surface-aggregator-module$ sudo evtest sudo: evtest: command not found ciaranwinnan@pop-os:~/Desktop/Surface_linux/surface-aggregator-module$ I have also tried looking in the script directory and I can't find the evtest script. Is there a specific directory that this command must be run from?

CiaranWinna avatar Nov 11 '23 23:11 CiaranWinna

Thanks for checking! I guess you might need to install evtest first. E.g. run sudo apt install evtest.

qzed avatar Nov 12 '23 00:11 qzed

@StollD I've extracted the HID descriptors from the firmware files: hiddesc.zip

The touchpad seems to have the same enable/metadata/data reports as the touchscreen. So maybe it'll just work with iptsd with no/minor changes. It also has generic mouse and touchpad reports, presumably those will be used in fallback mode if multitouch is not enabled.

quo avatar Nov 12 '23 23:11 quo

I have also been trying to get linux to work on my SLS2, but have encountered some issues. I'm running ubuntu 20.04.6. The first problem is that ubuntu only boots if I first enter the Microsoft recovery menu, select "use a device" and choose ubuntu there. Putting ubuntu first in boot order and booting normally doesn't work. Grub shows up just fine, but when I choose ubuntu it shows these lines for a second or two, turns off and then goes back to Grub.

loading linux 5.15.0-88-generic... Loading initial ramdisk...

The second problem is that I can't boot the surface kernel no matter what. I get maybe 10-20 errors like these and then it just gets stuck and I have to force a shutdown. [ 3.045865] ithc 0000:00:10.6: timed out waiting for reg 0x10bc mask 0x0000000f val 0x00000002 [ 16.162518] ithc 0000:00:10.7: timed out waiting for reg 0x10bc mask 0x0000000f val 0x00000002

I have tried all this with Secure Boot on and off and have gone through the mok key enrollment using Mint. Does anybody have any pointers as to what I'm doing wrong?

moheppler avatar Nov 14 '23 00:11 moheppler