linux-surface / linux-surface

Linux Kernel for Surface Devices
4.53k stars 202 forks source link

Support for Surface Laptop 6 #1432

Open leenozara opened 2 weeks ago

leenozara commented 2 weeks ago

I'm running the following commands on a Surface Laptop 6:

Preparation:

  1. Clone github.com/linux-surface/surface-aggregator-module and cd into it.
  2. Run sudo modprobe surface_aggregator_cdev

For Battery/Charger

Run the following commands and post the output of each

sudo ./scripts/ssam/ctrl.py request 0x02 0x01 0x02 0x01 0x01
sudo ./scripts/ssam/ctrl.py request 0x02 0x01 0x0d 0x01 0x01

For Internal HID Devices

Run the following command for $x = 0 until $x = 10 and post the output of each

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

For Type-Cover HID Devices

Run the following command for $x = 0 until $x = 10 and post the output of each

sudo ./scripts/ssam/hid.py hid-get-descriptor 2 $x 0
leenozara commented 2 weeks ago

For Battery/Charger

sudo ./scripts/ssam/ctrl.py request 0x02 0x01 0x02 0x01 0x01
00 00 00 00 00 54 ba 00 00 e6 b9 00 00 01 00 00 00 9c 1d 00 00 00 00 00 00 00 00 00 00 00 00 00 00 e8 03 00 00 ff ff ff ff ff ff ff ff e8 03 00 00 e8 03 00 00 0a 00 00 00 0a 00 00 00 31 32 39 32 32 33 34 30 30 32 00 00 00 00 00 00 00 00 00 00 00 37 30 32 37 37 35 37 33 35 30 00 4c 49 4f 4e 00 53 4d 50 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00

sudo ./scripts/ssam/ctrl.py request 0x02 0x01 0x0d 0x01 0x01
01 00 00 00

For Internal HID Devices

sudo ./scripts/ssam/hid.py hid-get-descriptor 1 0 0
[]

sudo ./scripts/ssam/hid.py hid-get-descriptor 1 1 0
[]

sudo ./scripts/ssam/hid.py hid-get-descriptor 1 2 0
[]

sudo ./scripts/ssam/hid.py hid-get-descriptor 1 3 0
[]

sudo ./scripts/ssam/hid.py hid-get-descriptor 1 4 0
[]

sudo ./scripts/ssam/hid.py hid-get-descriptor 1 5 0
[]

sudo ./scripts/ssam/hid.py hid-get-descriptor 1 6 0
[9, 33, 17, 1, 0, 1, 34, 97, 1]

sudo ./scripts/ssam/hid.py hid-get-descriptor 1 7 0
[9, 33, 17, 1, 0, 1, 34, 109, 0]

sudo ./scripts/ssam/hid.py hid-get-descriptor 1 8 0
[]

sudo ./scripts/ssam/hid.py hid-get-descriptor 1 9 0
[]

sudo ./scripts/ssam/hid.py hid-get-descriptor 1 10 0
[]

For Type-Cover HID Devices

sudo ./scripts/ssam/hid.py hid-get-descriptor 2 0 0
[9, 33, 17, 1, 0, 1, 34, 124, 3]

sudo ./scripts/ssam/hid.py hid-get-descriptor 2 1 0
[9, 33, 17, 1, 0, 1, 34, 155, 0]

sudo ./scripts/ssam/hid.py hid-get-descriptor 2 2 0
[]

sudo ./scripts/ssam/hid.py hid-get-descriptor 2 3 0
[9, 33, 17, 1, 0, 1, 34, 185, 2]

sudo ./scripts/ssam/hid.py hid-get-descriptor 2 4 0
[]

sudo ./scripts/ssam/hid.py hid-get-descriptor 2 5 0
[9, 33, 17, 1, 0, 1, 34, 78, 0]

sudo ./scripts/ssam/hid.py hid-get-descriptor 2 6 0
[]

sudo ./scripts/ssam/hid.py hid-get-descriptor 2 7 0
[]

sudo ./scripts/ssam/hid.py hid-get-descriptor 2 8 0
[]

sudo ./scripts/ssam/hid.py hid-get-descriptor 2 9 0
[]

sudo ./scripts/ssam/hid.py hid-get-descriptor 2 10 0
[]
qzed commented 2 weeks ago

I've only had a quick glance, but it looks pretty much like the SL5. The only difference I could spot is an additional node for (what based on other devices should be) HID-based sensors.

So adding something like

static const struct software_node *ssam_node_group_sl6[] = {
    &ssam_node_root,
    &ssam_node_bat_ac,
    &ssam_node_bat_main,
    &ssam_node_tmp_perf_profile,
    &ssam_node_hid_main_keyboard,
    &ssam_node_hid_main_touchpad,
    &ssam_node_hid_main_iid5,
    &ssam_node_hid_sam_sensors,
    &ssam_node_hid_sam_ucm_ucsi,
    NULL,
};

to surface_aggregator_registry.c should do the trick.

Note that this alone is not enough. We also need the repsective ACPI device ID for adding the entry here. For that, could you also run our "diagnostics" script (see here) and upload the archive it creates? This will gather some info about the system (including an ACPI dump), which we will need to figure out that ID.

leenozara commented 2 weeks ago

ACPI dump:

acpidump.txt

leenozara commented 2 weeks ago

diagnostics.sh full archive:

diagnostics.tar.gz

quo commented 1 week ago

So the touchscreen won't work with the version of ithc currently in the Surface kernel, because apparently Intel changed the final MTL device IDs from those that I found in an .inf file a while ago.

I figure it's probably better to just match on the vendor and class ID instead of device ID, since the THC is the only known PCI device that uses the pen input class: https://linux-hardware.org/?view=search&classid=09-01&typeid=all&busid=pci#list (the "Audio Controllers" are actually mislabeled THCs).

So I've made that change in https://github.com/quo/ithc-linux/commit/297427b576b6dc26ed95684aa57f3baeb1989348. (Tested on my SP7+.)

There also appears to be only one THC device on the PCI bus, even though ACPI contains configuration data for a second THC. So the touchpad is presumably not connected to a THC on the SL6.

EDIT: @leenozara You may be able to get the touchscreen working without updating the ithc driver, by forcing ithc to load using the following commands:

sudo modprobe -r ithc
echo ithc | sudo tee /sys/devices/pci0000:00/0000:00:10.0/driver_override
sudo modprobe ithc
leenozara commented 1 week ago

You may be able to get the touchscreen working without updating the ithc driver, by forcing ithc to load using the following commands

I tried this but no change, unfortunately.

quo commented 1 week ago

Can you post the output of the commands and the output of dmesg?

leenozara commented 1 week ago

Sure:

$ sudo modprobe -r ithc
$ echo ithc | sudo tee /sys/devices/pci0000:00/0000:00:10.0/driver_override
ithc
$ sudo modprobe ithc
$

dmesg:

[27019.646401] ithc 0000:00:10.0: ACPI config: InputHeaderAddr=0x1000 InputBodyAddr=0x1004 OutputBodyAddr=0x2000 ReadOpcode=0xeb WriteOpcode=0xe2 ReadMode=2 WriteMode=2 Frequency=32000000 LimitPacketSize=0 TxDelay=0 ActiveLTR=1023 IdleLTR=1023
[27020.736762] ithc 0000:00:10.0: timed out waiting for reg 0x1110 mask 0x00000010 val 0x00000010
[27020.736771] ithc 0000:00:10.0: wait_for_report: waitl failed with -110
[27020.736773] ithc 0000:00:10.0: ithc_quickspi_init: ithc_quickspi_init_hidspi failed with -110
[27020.736775] ithc 0000:00:10.0: ithc_init_device: ithc_quickspi_init failed with -110
[27020.736777] ithc 0000:00:10.0: ithc_start: ithc_init_device failed with -110
[27020.736780] ithc: probe of 0000:00:10.0 failed with error -110
quo commented 1 week ago

Ah crap. So Intel or MS changed something again. :( I'll have a better look at this in a few weeks.

leenozara commented 1 week ago

Let me know anytime I can help. Sadly I don't know much about hardware and driver development, otherwise I'd help with code. Maybe I can take a look at pull requests for previous new devices and see what was done there.

Getting keyboard, trackpad and battery status working at a minimum would be the most significant improvement.

qzed commented 1 week ago

The following patch should enable SAM support (and with that hopefully battery, keyboard, and touchpad). Would be great if you can test it. In particular temperature sensors and fan, because we haven't enabled and tested them on the SL5, but it looks like they should be there on the SL6.

From 5b8a335cbd8d47fca755d7772a452d0f86f35f9c Mon Sep 17 00:00:00 2001
From: Maximilian Luz <luzmaximilian@gmail.com>
Date: Sun, 5 May 2024 18:46:08 +0200
Subject: [PATCH] platform/surface: aggregator_registry: Add support for
 Surface Laptop 6

---
 .../surface/surface_aggregator_registry.c     | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

diff --git a/drivers/platform/surface/surface_aggregator_registry.c b/drivers/platform/surface/surface_aggregator_registry.c
index 058b6654a91af..07a4c4e1120d3 100644
--- a/drivers/platform/surface/surface_aggregator_registry.c
+++ b/drivers/platform/surface/surface_aggregator_registry.c
@@ -273,6 +273,22 @@ static const struct software_node *ssam_node_group_sl5[] = {
    NULL,
 };

+/* Devices for Surface Laptop 6. */
+static const struct software_node *ssam_node_group_sl6[] = {
+   &ssam_node_root,
+   &ssam_node_bat_ac,
+   &ssam_node_bat_main,
+   &ssam_node_tmp_perf_profile_with_fan,
+   &ssam_node_tmp_sensors,
+   &ssam_node_fan_speed,
+   &ssam_node_hid_main_keyboard,
+   &ssam_node_hid_main_touchpad,
+   &ssam_node_hid_main_iid5,
+   &ssam_node_hid_sam_sensors,
+   &ssam_node_hid_sam_ucm_ucsi,
+   NULL,
+};
+
 /* Devices for Surface Laptop Studio 1. */
 static const struct software_node *ssam_node_group_sls1[] = {
    &ssam_node_root,
@@ -403,6 +419,9 @@ static const struct acpi_device_id ssam_platform_hub_match[] = {
    /* Surface Laptop 5 */
    { "MSHW0350", (unsigned long)ssam_node_group_sl5 },

+   /* Surface Laptop 6 */
+   { "MSHW0530", (unsigned long)ssam_node_group_sl6 },
+
    /* Surface Laptop Go 1 */
    { "MSHW0118", (unsigned long)ssam_node_group_slg1 },

-- 
2.44.0
leenozara commented 1 week ago

Nice! I'll apply this patch tomorrow and update you here.

I have access to an SL5 so I can help with testing that after SL6.

leenozara commented 1 week ago

Hi @qzed your patch works:

sensors no load on battery power:

iwlwifi_1-virtual-0
Adapter: Virtual device
temp1:        +32.0°C  

surface_thermal-virtual-0
Adapter: Virtual device
I_RTS1:       +33.6°C  
I_RTS2:       +36.5°C  
I_RTS3:       +35.2°C  
I_RTS4:       +34.6°C  
I_RTS5:       +32.3°C  
I_RTS6:       +32.3°C  
I_RTS7:       +36.5°C  
I_RTS1:       +32.4°C  
I_RTS2:       +32.9°C  
I_RTS3:       +33.2°C  

nvme-pci-0100
Adapter: PCI adapter
Composite:    +34.9°C  (low  = -40.1°C, high = +83.8°C)
                       (crit = +87.8°C)
Sensor 1:     +45.9°C  (low  = -273.1°C, high = +65261.8°C)
Sensor 2:     +34.9°C  (low  = -273.1°C, high = +65261.8°C)

coretemp-isa-0000
Adapter: ISA adapter
Package id 0:  +46.0°C  (high = +110.0°C, crit = +110.0°C)
Core 0:        +42.0°C  (high = +110.0°C, crit = +110.0°C)
Core 1:        +42.0°C  (high = +110.0°C, crit = +110.0°C)
Core 2:        +42.0°C  (high = +110.0°C, crit = +110.0°C)
Core 3:        +42.0°C  (high = +110.0°C, crit = +110.0°C)
Core 4:        +41.0°C  (high = +110.0°C, crit = +110.0°C)
Core 5:        +41.0°C  (high = +110.0°C, crit = +110.0°C)
Core 6:        +41.0°C  (high = +110.0°C, crit = +110.0°C)
Core 7:        +41.0°C  (high = +110.0°C, crit = +110.0°C)
Core 8:        +42.0°C  (high = +110.0°C, crit = +110.0°C)
Core 12:       +43.0°C  (high = +110.0°C, crit = +110.0°C)
Core 16:       +41.0°C  (high = +110.0°C, crit = +110.0°C)
Core 20:       +41.0°C  (high = +110.0°C, crit = +110.0°C)
Core 24:       +44.0°C  (high = +110.0°C, crit = +110.0°C)
Core 28:       +41.0°C  (high = +110.0°C, crit = +110.0°C)
Core 32:       +45.0°C  (high = +110.0°C, crit = +110.0°C)
Core 33:       +45.0°C  (high = +110.0°C, crit = +110.0°C)

BAT1-virtual-0
Adapter: Virtual device
in0:           8.37 V  

surface_fan-virtual-0
Adapter: Virtual device
fan1:           0 RPM

sensors under load on battery power (compiling kernel make -j22) and 'balanced' power mode:

iwlwifi_1-virtual-0
Adapter: Virtual device
temp1:        +41.0°C  

surface_thermal-virtual-0
Adapter: Virtual device
I_RTS1:       +40.8°C  
I_RTS2:       +59.9°C  
I_RTS3:       +55.0°C  
I_RTS4:       +42.2°C  
I_RTS5:       +34.4°C  
I_RTS6:       +34.4°C  
I_RTS7:       +59.9°C  
I_RTS1:       +43.8°C  
I_RTS2:       +38.7°C  
I_RTS3:       +37.0°C  

nvme-pci-0100
Adapter: PCI adapter
Composite:    +48.9°C  (low  = -40.1°C, high = +83.8°C)
                       (crit = +87.8°C)
Sensor 1:     +63.9°C  (low  = -273.1°C, high = +65261.8°C)
Sensor 2:     +48.9°C  (low  = -273.1°C, high = +65261.8°C)

coretemp-isa-0000
Adapter: ISA adapter
Package id 0:  +78.0°C  (high = +110.0°C, crit = +110.0°C)
Core 0:        +75.0°C  (high = +110.0°C, crit = +110.0°C)
Core 1:        +75.0°C  (high = +110.0°C, crit = +110.0°C)
Core 2:        +74.0°C  (high = +110.0°C, crit = +110.0°C)
Core 3:        +74.0°C  (high = +110.0°C, crit = +110.0°C)
Core 4:        +74.0°C  (high = +110.0°C, crit = +110.0°C)
Core 5:        +74.0°C  (high = +110.0°C, crit = +110.0°C)
Core 6:        +74.0°C  (high = +110.0°C, crit = +110.0°C)
Core 7:        +74.0°C  (high = +110.0°C, crit = +110.0°C)
Core 8:        +77.0°C  (high = +110.0°C, crit = +110.0°C)
Core 12:       +78.0°C  (high = +110.0°C, crit = +110.0°C)
Core 16:       +75.0°C  (high = +110.0°C, crit = +110.0°C)
Core 20:       +79.0°C  (high = +110.0°C, crit = +110.0°C)
Core 24:       +76.0°C  (high = +110.0°C, crit = +110.0°C)
Core 28:       +76.0°C  (high = +110.0°C, crit = +110.0°C)
Core 32:       +76.0°C  (high = +110.0°C, crit = +110.0°C)
Core 33:       +76.0°C  (high = +110.0°C, crit = +110.0°C)

BAT1-virtual-0
Adapter: Virtual device
in0:           8.04 V  

surface_fan-virtual-0
Adapter: Virtual device
fan1:        4639 RPM

sensors under load plugged-in/charging (compiling kernel make -j22) and 'performance' power mode:

iwlwifi_1-virtual-0
Adapter: Virtual device
temp1:        +46.0°C  

surface_thermal-virtual-0
Adapter: Virtual device
I_RTS1:       +46.8°C  
I_RTS2:       +60.3°C  
I_RTS3:       +59.9°C  
I_RTS4:       +47.4°C  
I_RTS5:       +36.0°C  
I_RTS6:       +36.0°C  
I_RTS7:       +60.3°C  
I_RTS1:       +49.1°C  
I_RTS2:       +41.8°C  
I_RTS3:       +39.7°C  

nvme-pci-0100
Adapter: PCI adapter
Composite:    +53.9°C  (low  = -40.1°C, high = +83.8°C)
                       (crit = +87.8°C)
Sensor 1:     +69.8°C  (low  = -273.1°C, high = +65261.8°C)
Sensor 2:     +53.9°C  (low  = -273.1°C, high = +65261.8°C)

coretemp-isa-0000
Adapter: ISA adapter
Package id 0:  +79.0°C  (high = +110.0°C, crit = +110.0°C)
Core 0:        +76.0°C  (high = +110.0°C, crit = +110.0°C)
Core 1:        +76.0°C  (high = +110.0°C, crit = +110.0°C)
Core 2:        +76.0°C  (high = +110.0°C, crit = +110.0°C)
Core 3:        +77.0°C  (high = +110.0°C, crit = +110.0°C)
Core 4:        +75.0°C  (high = +110.0°C, crit = +110.0°C)
Core 5:        +75.0°C  (high = +110.0°C, crit = +110.0°C)
Core 6:        +75.0°C  (high = +110.0°C, crit = +110.0°C)
Core 7:        +75.0°C  (high = +110.0°C, crit = +110.0°C)
Core 8:        +78.0°C  (high = +110.0°C, crit = +110.0°C)
Core 12:       +79.0°C  (high = +110.0°C, crit = +110.0°C)
Core 16:       +76.0°C  (high = +110.0°C, crit = +110.0°C)
Core 20:       +79.0°C  (high = +110.0°C, crit = +110.0°C)
Core 24:       +77.0°C  (high = +110.0°C, crit = +110.0°C)
Core 28:       +76.0°C  (high = +110.0°C, crit = +110.0°C)
Core 32:       +79.0°C  (high = +110.0°C, crit = +110.0°C)
Core 33:       +79.0°C  (high = +110.0°C, crit = +110.0°C)

BAT1-virtual-0
Adapter: Virtual device
in0:           8.46 V  

surface_fan-virtual-0
Adapter: Virtual device
fan1:        7810 RPM

Are there any specifics diagnostics, commands, etc you'd like me to perform that would help?

leenozara commented 1 week ago

@quo The ithc modprobe commands now have a different error output:

sudo modprobe -r ithc
echo ithc | sudo tee /sys/devices/pci0000:00/0000:00:10.0/driver_override
sudo modprobe ithc

dmesg:

[  132.944327] ithc 0000:00:10.0: enabling device (0000 -> 0002)
[  132.947730] ithc 0000:00:10.0: ACPI config: InputHeaderAddr=0x1000 InputBodyAddr=0x1004 OutputBodyAddr=0x2000 ReadOpcode=0xeb WriteOpcode=0xe2 ReadMode=2 WriteMode=2 Frequency=32000000 LimitPacketSize=0 TxDelay=0 ActiveLTR=1023 IdleLTR=1023
[  133.138611] ithc 0000:00:10.0: SPI data size too small for device descriptor (4)
[  133.138617] ithc 0000:00:10.0: ithc_quickspi_init: ithc_quickspi_init_hidspi failed with -90
[  133.138620] ithc 0000:00:10.0: ithc_init_device: ithc_quickspi_init failed with -90
[  133.138622] ithc 0000:00:10.0: ithc_start: ithc_init_device failed with -90
[  133.138625] ithc: probe of 0000:00:10.0 failed with error -90
qzed commented 1 week ago

@leenozara Thanks! That looks like things are working. A dmesg log from when you applied that would still be nice though, to confirm that there are no errors or warnings. If that doesn't show anything out of the ordinary, I think we're good to apply it.

Apart from that: Since you mentioned you have access to a SL5, you could try adding/replacing the following nodes to the SL5 entry:

&ssam_node_tmp_perf_profile_with_fan,    // replaces ssam_node_tmp_perf_profile
&ssam_node_tmp_sensors,
&ssam_node_fan_speed,

And then maybe also try to run the two commands for the HID devices again on the SL5, just to make sure we're not missing anything (since the SL6 has an additional sensor device).

And I think it's best if you open a new issue for that so that we don't mix the two devices here.

leenozara commented 1 week ago

dmesg: dmesg.log

For SL5 I should have the device by end of the week. I'll set create a separate issue that pertains to testing linux-surface existing support for the SL5.

Thanks!

qzed commented 1 week ago

Looks like everything is working (for SAM at least).

@StollD if you have some time feel free to apply this. I'm away for the next three weeks and I'm not sure if I can manage to build/test/release anything during that time (only took the SPX with me...).

quo commented 1 week ago

@quo The ithc modprobe commands now have a different error output

Weird. But I don't think it's related to the SAM patch.

Can you try probing with debug logging enabled?

sudo modprobe -r ithc
echo ithc | sudo tee /sys/devices/pci0000:00/0000:00:10.0/driver_override
sudo modprobe ithc logregs=1 dyndbg=+pflmt

Please repeat a few times to see how repeatable/variable the errors are. And please attach the dmesg log here.

Could you also try if the following patch for ithc makes any difference?

diff --git a/src/ithc-quickspi.c b/src/ithc-quickspi.c
index 760e55e..7d3e506 100644
--- a/src/ithc-quickspi.c
+++ b/src/ithc-quickspi.c
@@ -323,6 +323,9 @@ static int ithc_quickspi_init_regs(struct ithc *ithc, const struct ithc_acpi_con
        QUICKSPI_CONFIG2_DISABLE_WRITE_ADDRESS_INCREMENT |
        QUICKSPI_CONFIG2_ENABLE_WRITE_STREAMING_MODE, 0);

+   bitsl_set(&ithc->regs->dma_rx[0].init_unknown, INIT_UNKNOWN_3);
+   bitsl_set(&ithc->regs->dma_rx[0].init_unknown, INIT_UNKNOWN_31);
+
    return 0;
 }