Update v5.4 patches

Changes:
- SAM:
  - Fix bug where second Surface Book 3 battery would be set up
    incorrectly.
  - Continued work on internal documentation and cleanup.
  - Other minor bugfixes.

- SAM-over-HID:
  - Add dGPU switch module for SB1.

- GPE:
  - Cleanup and formatting.

Links:
- SAM: c5f84f1f9a
- SAM-over-HID: 9d2a927ac8
- GPE: a9d97ed280
- kernel: ee5d2c7ad3
This commit is contained in:
Maximilian Luz 2020-09-08 16:35:49 +02:00
parent d3992b7362
commit 6836b92298
No known key found for this signature in database
GPG key ID: 70EC0937F6C26F02
8 changed files with 3032 additions and 676 deletions

View file

@ -28,3 +28,4 @@ CONFIG_SURFACE_3_BUTTON=m
CONFIG_SURFACE_3_POWER_OPREGION=m
CONFIG_SURFACE_PRO3_BUTTON=m
CONFIG_SURFACE_GPE=m
CONFIG_SURFACE_BOOK1_DGPU_SWITCH=m

View file

@ -1,4 +1,4 @@
From 39e02befec04246af9c03fb5889e3fb880023d7f Mon Sep 17 00:00:00 2001
From 9ee797e72c4320cbe95afc4f850b20173e0cb86b Mon Sep 17 00:00:00 2001
From: qzed <qzed@users.noreply.github.com>
Date: Tue, 17 Sep 2019 17:17:56 +0200
Subject: [PATCH 1/7] surface3-power

View file

@ -1,4 +1,4 @@
From b76b3c481adf002e8acf628a4a8937b6f51176a4 Mon Sep 17 00:00:00 2001
From af8e13a7363a7438b0d6da2ef251b0e508484c46 Mon Sep 17 00:00:00 2001
From: Chih-Wei Huang <cwhuang@linux.org.tw>
Date: Tue, 18 Sep 2018 11:01:37 +0800
Subject: [PATCH 2/7] surface3-oemb

View file

@ -1,4 +1,4 @@
From 769dda1fd68fcfb45c3d659072b13bac1fa59258 Mon Sep 17 00:00:00 2001
From 67016f2e5959bf4b033fffd54144536ce0046552 Mon Sep 17 00:00:00 2001
From: kitakar5525 <34676735+kitakar5525@users.noreply.github.com>
Date: Thu, 20 Feb 2020 16:51:11 +0900
Subject: [PATCH 3/7] wifi

View file

@ -1,4 +1,4 @@
From 5c6bb3181cd713454d69d8007eae9e389b57cb8d Mon Sep 17 00:00:00 2001
From 38639bf81bc9eb5fdbe0a071b37447057a3d4c1a Mon Sep 17 00:00:00 2001
From: Dorian Stoll <dorian.stoll@tmsp.io>
Date: Mon, 27 Jan 2020 21:16:20 +0100
Subject: [PATCH 4/7] ipts

File diff suppressed because it is too large Load diff

View file

@ -1,11 +1,15 @@
From 72e5c2eba0f5522a7c1279791588c3f35a05966d Mon Sep 17 00:00:00 2001
From a1bd46036728620ce894390591bee5f1892ac861 Mon Sep 17 00:00:00 2001
From: Maximilian Luz <luzmaximilian@gmail.com>
Date: Sat, 25 Jul 2020 17:19:53 +0200
Subject: [PATCH 6/7] surface-sam-over-hid
---
drivers/i2c/i2c-core-acpi.c | 35 +++++++++++++++++++++++++++++++++++
1 file changed, 35 insertions(+)
drivers/i2c/i2c-core-acpi.c | 35 +++++++
drivers/platform/x86/Kconfig | 7 ++
drivers/platform/x86/Makefile | 1 +
drivers/platform/x86/sb1_dgpu_sw.c | 162 +++++++++++++++++++++++++++++
4 files changed, 205 insertions(+)
create mode 100644 drivers/platform/x86/sb1_dgpu_sw.c
diff --git a/drivers/i2c/i2c-core-acpi.c b/drivers/i2c/i2c-core-acpi.c
index ce70b5288472c..5df647c4d9a51 100644
@ -60,6 +64,204 @@ index ce70b5288472c..5df647c4d9a51 100644
default:
dev_warn(&adapter->dev, "protocol 0x%02x not supported for client 0x%02x\n",
accessor_type, client->addr);
diff --git a/drivers/platform/x86/Kconfig b/drivers/platform/x86/Kconfig
index 348c795019fa4..5495e3702f656 100644
--- a/drivers/platform/x86/Kconfig
+++ b/drivers/platform/x86/Kconfig
@@ -1216,6 +1216,13 @@ config SURFACE_3_POWER_OPREGION
Select this option to enable support for ACPI operation
region of the Surface 3 battery platform driver.
+config SURFACE_BOOK1_DGPU_SWITCH
+ tristate "Surface Book 1 dGPU Switch Driver"
+ depends on ACPI && SYSFS
+ help
+ This driver provides a sysfs switch to set the power-state of the
+ discrete GPU found on the Microsoft Surface Book 1.
+
config INTEL_PUNIT_IPC
tristate "Intel P-Unit IPC Driver"
---help---
diff --git a/drivers/platform/x86/Makefile b/drivers/platform/x86/Makefile
index 6dd955ad9bf18..b3e0a2c6924b6 100644
--- a/drivers/platform/x86/Makefile
+++ b/drivers/platform/x86/Makefile
@@ -86,6 +86,7 @@ obj-$(CONFIG_TOUCHSCREEN_DMI) += touchscreen_dmi.o
obj-$(CONFIG_SURFACE_PRO3_BUTTON) += surfacepro3_button.o
obj-$(CONFIG_SURFACE_3_BUTTON) += surface3_button.o
obj-$(CONFIG_SURFACE_3_POWER_OPREGION) += surface3_power.o
+obj-$(CONFIG_SURFACE_BOOK1_DGPU_SWITCH) += sb1_dgpu_sw.o
obj-$(CONFIG_INTEL_PUNIT_IPC) += intel_punit_ipc.o
obj-$(CONFIG_INTEL_BXTWC_PMIC_TMU) += intel_bxtwc_tmu.o
obj-$(CONFIG_INTEL_TELEMETRY) += intel_telemetry_core.o \
diff --git a/drivers/platform/x86/sb1_dgpu_sw.c b/drivers/platform/x86/sb1_dgpu_sw.c
new file mode 100644
index 0000000000000..8c66ed5110fda
--- /dev/null
+++ b/drivers/platform/x86/sb1_dgpu_sw.c
@@ -0,0 +1,162 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/acpi.h>
+#include <linux/platform_device.h>
+
+
+#ifdef pr_fmt
+#undef pr_fmt
+#endif
+#define pr_fmt(fmt) "%s:%s: " fmt, KBUILD_MODNAME, __func__
+
+
+static const guid_t dgpu_sw_guid = GUID_INIT(0x6fd05c69, 0xcde3, 0x49f4,
+ 0x95, 0xed, 0xab, 0x16, 0x65, 0x49, 0x80, 0x35);
+
+#define DGPUSW_ACPI_PATH_DSM "\\_SB_.PCI0.LPCB.EC0_.VGBI"
+#define DGPUSW_ACPI_PATH_HGON "\\_SB_.PCI0.RP05.HGON"
+#define DGPUSW_ACPI_PATH_HGOF "\\_SB_.PCI0.RP05.HGOF"
+
+
+static int sb1_dgpu_sw_dsmcall(void)
+{
+ union acpi_object *ret;
+ acpi_handle handle;
+ acpi_status status;
+
+ status = acpi_get_handle(NULL, DGPUSW_ACPI_PATH_DSM, &handle);
+ if (status)
+ return -EINVAL;
+
+ ret = acpi_evaluate_dsm_typed(handle, &dgpu_sw_guid, 1, 1, NULL, ACPI_TYPE_BUFFER);
+ if (!ret)
+ return -EINVAL;
+
+ ACPI_FREE(ret);
+ return 0;
+}
+
+static int sb1_dgpu_sw_hgon(void)
+{
+ struct acpi_buffer buf = {ACPI_ALLOCATE_BUFFER, NULL};
+ acpi_status status;
+
+ status = acpi_evaluate_object(NULL, DGPUSW_ACPI_PATH_HGON, NULL, &buf);
+ if (status) {
+ pr_err("failed to run HGON: %d\n", status);
+ return -EINVAL;
+ }
+
+ if (buf.pointer)
+ ACPI_FREE(buf.pointer);
+
+ pr_info("turned-on dGPU via HGON\n");
+ return 0;
+}
+
+static int sb1_dgpu_sw_hgof(void)
+{
+ struct acpi_buffer buf = {ACPI_ALLOCATE_BUFFER, NULL};
+ acpi_status status;
+
+ status = acpi_evaluate_object(NULL, DGPUSW_ACPI_PATH_HGOF, NULL, &buf);
+ if (status) {
+ pr_err("failed to run HGOF: %d\n", status);
+ return -EINVAL;
+ }
+
+ if (buf.pointer)
+ ACPI_FREE(buf.pointer);
+
+ pr_info("turned-off dGPU via HGOF\n");
+ return 0;
+}
+
+
+static ssize_t dgpu_dsmcall_store(struct device *dev, struct device_attribute *attr,
+ const char *buf, size_t len)
+{
+ int status, value;
+
+ status = kstrtoint(buf, 0, &value);
+ if (status < 0)
+ return status;
+
+ if (value != 1)
+ return -EINVAL;
+
+ status = sb1_dgpu_sw_dsmcall();
+
+ return status < 0 ? status : len;
+}
+
+static ssize_t dgpu_power_store(struct device *dev, struct device_attribute *attr,
+ const char *buf, size_t len)
+{
+ bool power;
+ int status;
+
+ status = kstrtobool(buf, &power);
+ if (status < 0)
+ return status;
+
+ if (power)
+ status = sb1_dgpu_sw_hgon();
+ else
+ status = sb1_dgpu_sw_hgof();
+
+ return status < 0 ? status : len;
+}
+
+static DEVICE_ATTR_WO(dgpu_dsmcall);
+static DEVICE_ATTR_WO(dgpu_power);
+
+static struct attribute *sb1_dgpu_sw_attrs[] = {
+ &dev_attr_dgpu_dsmcall.attr,
+ &dev_attr_dgpu_power.attr,
+ NULL,
+};
+
+static const struct attribute_group sb1_dgpu_sw_attr_group = {
+ .attrs = sb1_dgpu_sw_attrs,
+};
+
+
+static int sb1_dgpu_sw_probe(struct platform_device *pdev)
+{
+ return sysfs_create_group(&pdev->dev.kobj, &sb1_dgpu_sw_attr_group);
+}
+
+static int sb1_dgpu_sw_remove(struct platform_device *pdev)
+{
+ sysfs_remove_group(&pdev->dev.kobj, &sb1_dgpu_sw_attr_group);
+ return 0;
+}
+
+/*
+ * The dGPU power seems to be actually handled by MSHW0040. However, that is
+ * also the power-/volume-button device with a mainline driver. So let's use
+ * MSHW0041 instead for now, which seems to be the LTCH (latch/DTX) device.
+ */
+static const struct acpi_device_id sb1_dgpu_sw_match[] = {
+ { "MSHW0041", },
+ { },
+};
+MODULE_DEVICE_TABLE(acpi, sb1_dgpu_sw_match);
+
+static struct platform_driver sb1_dgpu_sw = {
+ .probe = sb1_dgpu_sw_probe,
+ .remove = sb1_dgpu_sw_remove,
+ .driver = {
+ .name = "sb1_dgpu_sw",
+ .acpi_match_table = sb1_dgpu_sw_match,
+ .probe_type = PROBE_PREFER_ASYNCHRONOUS,
+ },
+};
+module_platform_driver(sb1_dgpu_sw);
+
+MODULE_AUTHOR("Maximilian Luz <luzmaximilian@gmail.com>");
+MODULE_DESCRIPTION("Discrete GPU Power-Switch for Surface Book 1");
+MODULE_LICENSE("GPL");
--
2.28.0

View file

@ -1,4 +1,4 @@
From cc404af53a4525d2a3016f2a710df3fb565f2bb8 Mon Sep 17 00:00:00 2001
From c94fb1b421f85277460595309e760ae336f22750 Mon Sep 17 00:00:00 2001
From: Maximilian Luz <luzmaximilian@gmail.com>
Date: Sun, 16 Aug 2020 23:39:56 +0200
Subject: [PATCH 7/7] surface-gpe
@ -6,17 +6,17 @@ Subject: [PATCH 7/7] surface-gpe
---
drivers/platform/x86/Kconfig | 9 +
drivers/platform/x86/Makefile | 1 +
drivers/platform/x86/surface_gpe.c | 302 +++++++++++++++++++++++++++++
3 files changed, 312 insertions(+)
drivers/platform/x86/surface_gpe.c | 299 +++++++++++++++++++++++++++++
3 files changed, 309 insertions(+)
create mode 100644 drivers/platform/x86/surface_gpe.c
diff --git a/drivers/platform/x86/Kconfig b/drivers/platform/x86/Kconfig
index 348c795019fa4..105a238328a2c 100644
index 5495e3702f656..e0af35fed2d50 100644
--- a/drivers/platform/x86/Kconfig
+++ b/drivers/platform/x86/Kconfig
@@ -1216,6 +1216,15 @@ config SURFACE_3_POWER_OPREGION
Select this option to enable support for ACPI operation
region of the Surface 3 battery platform driver.
@@ -1223,6 +1223,15 @@ config SURFACE_BOOK1_DGPU_SWITCH
This driver provides a sysfs switch to set the power-state of the
discrete GPU found on the Microsoft Surface Book 1.
+config SURFACE_GPE
+ tristate "Surface GPE/Lid Driver"
@ -31,23 +31,23 @@ index 348c795019fa4..105a238328a2c 100644
tristate "Intel P-Unit IPC Driver"
---help---
diff --git a/drivers/platform/x86/Makefile b/drivers/platform/x86/Makefile
index 6dd955ad9bf18..5db303f43bda7 100644
index b3e0a2c6924b6..c6e934a73a8d1 100644
--- a/drivers/platform/x86/Makefile
+++ b/drivers/platform/x86/Makefile
@@ -86,6 +86,7 @@ obj-$(CONFIG_TOUCHSCREEN_DMI) += touchscreen_dmi.o
obj-$(CONFIG_SURFACE_PRO3_BUTTON) += surfacepro3_button.o
@@ -87,6 +87,7 @@ obj-$(CONFIG_SURFACE_PRO3_BUTTON) += surfacepro3_button.o
obj-$(CONFIG_SURFACE_3_BUTTON) += surface3_button.o
obj-$(CONFIG_SURFACE_3_POWER_OPREGION) += surface3_power.o
obj-$(CONFIG_SURFACE_BOOK1_DGPU_SWITCH) += sb1_dgpu_sw.o
+obj-$(CONFIG_SURFACE_GPE) += surface_gpe.o
obj-$(CONFIG_INTEL_PUNIT_IPC) += intel_punit_ipc.o
obj-$(CONFIG_INTEL_BXTWC_PMIC_TMU) += intel_bxtwc_tmu.o
obj-$(CONFIG_INTEL_TELEMETRY) += intel_telemetry_core.o \
diff --git a/drivers/platform/x86/surface_gpe.c b/drivers/platform/x86/surface_gpe.c
new file mode 100644
index 0000000000000..3031a94cddeb7
index 0000000000000..4c141fef7a5f4
--- /dev/null
+++ b/drivers/platform/x86/surface_gpe.c
@@ -0,0 +1,302 @@
@@ -0,0 +1,299 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Surface GPE/Lid driver to enable wakeup from suspend via the lid by
@ -282,12 +282,9 @@ index 0000000000000..3031a94cddeb7
+{
+ const struct dmi_system_id *match;
+ const struct surface_lid_device *lid;
+
+ struct platform_device *pdev;
+ int status;
+
+ surface_gpe_device = NULL;
+
+ match = dmi_first_match(dmi_lid_device_table);
+ if (!match) {
+ pr_info(KBUILD_MODNAME": no device detected, exiting\n");