2021-06-29 12:46:10 +00:00
|
|
|
From 0b0cfb7a6cf0fa9be3992a3d434fe6d39ab61bf6 Mon Sep 17 00:00:00 2001
|
2020-12-16 16:00:17 +00:00
|
|
|
From: Maximilian Luz <luzmaximilian@gmail.com>
|
|
|
|
Date: Sat, 31 Oct 2020 20:46:33 +0100
|
|
|
|
Subject: [PATCH] PCI: Add sysfs attribute for PCI device power state
|
|
|
|
|
|
|
|
While most PCI power-states can be queried from user-space via lspci,
|
|
|
|
this has some limits. Specifically, lspci fails to provide an accurate
|
|
|
|
value when the device is in D3cold as it has to resume the device before
|
|
|
|
it can access its power state via the configuration space, leading to it
|
|
|
|
reporting D0 or another on-state. Thus lspci can, for example, not be
|
|
|
|
used to diagnose power-consumption issues for devices that can enter
|
|
|
|
D3cold or to ensure that devices properly enter D3cold at all.
|
|
|
|
|
|
|
|
To alleviate this issue, introduce a new sysfs device attribute for the
|
|
|
|
PCI power state, showing the current power state as seen by the kernel.
|
|
|
|
|
|
|
|
Signed-off-by: Maximilian Luz <luzmaximilian@gmail.com>
|
|
|
|
Patchset: surface-hotplug
|
|
|
|
---
|
|
|
|
Documentation/ABI/testing/sysfs-bus-pci | 9 +++++++++
|
|
|
|
drivers/pci/pci-sysfs.c | 12 ++++++++++++
|
|
|
|
2 files changed, 21 insertions(+)
|
|
|
|
|
|
|
|
diff --git a/Documentation/ABI/testing/sysfs-bus-pci b/Documentation/ABI/testing/sysfs-bus-pci
|
|
|
|
index 77ad9ec3c801..25c9c39770c6 100644
|
|
|
|
--- a/Documentation/ABI/testing/sysfs-bus-pci
|
|
|
|
+++ b/Documentation/ABI/testing/sysfs-bus-pci
|
|
|
|
@@ -366,3 +366,12 @@ Contact: Heiner Kallweit <hkallweit1@gmail.com>
|
|
|
|
Description: If ASPM is supported for an endpoint, these files can be
|
|
|
|
used to disable or enable the individual power management
|
|
|
|
states. Write y/1/on to enable, n/0/off to disable.
|
|
|
|
+
|
|
|
|
+What: /sys/bus/pci/devices/.../power_state
|
|
|
|
+Date: November 2020
|
|
|
|
+Contact: Linux PCI developers <linux-pci@vger.kernel.org>
|
|
|
|
+Description:
|
|
|
|
+ This file contains the current PCI power state of the device.
|
|
|
|
+ The value comes from the PCI kernel device state and can be one
|
|
|
|
+ of: "unknown", "error", "D0", D1", "D2", "D3hot", "D3cold".
|
|
|
|
+ The file is read only.
|
|
|
|
diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c
|
|
|
|
index d15c881e2e7e..b15f754e6346 100644
|
|
|
|
--- a/drivers/pci/pci-sysfs.c
|
|
|
|
+++ b/drivers/pci/pci-sysfs.c
|
|
|
|
@@ -124,6 +124,17 @@ static ssize_t cpulistaffinity_show(struct device *dev,
|
|
|
|
}
|
|
|
|
static DEVICE_ATTR_RO(cpulistaffinity);
|
|
|
|
|
|
|
|
+/* PCI power state */
|
|
|
|
+static ssize_t power_state_show(struct device *dev,
|
|
|
|
+ struct device_attribute *attr, char *buf)
|
|
|
|
+{
|
|
|
|
+ struct pci_dev *pci_dev = to_pci_dev(dev);
|
|
|
|
+ pci_power_t state = READ_ONCE(pci_dev->current_state);
|
|
|
|
+
|
|
|
|
+ return sprintf(buf, "%s\n", pci_power_name(state));
|
|
|
|
+}
|
|
|
|
+static DEVICE_ATTR_RO(power_state);
|
|
|
|
+
|
|
|
|
/* show resources */
|
|
|
|
static ssize_t resource_show(struct device *dev, struct device_attribute *attr,
|
|
|
|
char *buf)
|
|
|
|
@@ -581,6 +592,7 @@ static ssize_t driver_override_show(struct device *dev,
|
|
|
|
static DEVICE_ATTR_RW(driver_override);
|
|
|
|
|
|
|
|
static struct attribute *pci_dev_attrs[] = {
|
|
|
|
+ &dev_attr_power_state.attr,
|
|
|
|
&dev_attr_resource.attr,
|
|
|
|
&dev_attr_vendor.attr,
|
|
|
|
&dev_attr_device.attr,
|
|
|
|
--
|
2021-06-13 21:00:11 +00:00
|
|
|
2.32.0
|
2020-12-16 16:00:17 +00:00
|
|
|
|
2021-06-29 12:46:10 +00:00
|
|
|
From eb3eaa3eb2005d8d10b1d1a2a8c9cf2817cc4a21 Mon Sep 17 00:00:00 2001
|
2020-12-16 16:00:17 +00:00
|
|
|
From: Maximilian Luz <luzmaximilian@gmail.com>
|
|
|
|
Date: Mon, 14 Dec 2020 20:50:59 +0100
|
|
|
|
Subject: [PATCH] platform/x86: Add Surface Hotplug driver
|
|
|
|
|
|
|
|
Add a driver to handle out-of-band hot-plug signaling for the discrete
|
|
|
|
GPU (dGPU) on Microsoft Surface Book 2 and 3 devices. This driver is
|
|
|
|
required to properly detect hot-plugging of the dGPU and relay the
|
|
|
|
appropriate signal to the PCIe hot-plug driver core.
|
|
|
|
|
|
|
|
Signed-off-by: Maximilian Luz <luzmaximilian@gmail.com>
|
|
|
|
Patchset: surface-hotplug
|
|
|
|
---
|
2021-02-15 20:36:42 +00:00
|
|
|
drivers/platform/x86/Kconfig | 20 ++
|
2020-12-16 16:00:17 +00:00
|
|
|
drivers/platform/x86/Makefile | 1 +
|
2021-02-15 20:36:42 +00:00
|
|
|
drivers/platform/x86/surface_hotplug.c | 282 +++++++++++++++++++++++++
|
|
|
|
3 files changed, 303 insertions(+)
|
2020-12-16 16:00:17 +00:00
|
|
|
create mode 100644 drivers/platform/x86/surface_hotplug.c
|
|
|
|
|
|
|
|
diff --git a/drivers/platform/x86/Kconfig b/drivers/platform/x86/Kconfig
|
2021-05-29 13:25:21 +00:00
|
|
|
index d44d3fb9ca72..533998040530 100644
|
2020-12-16 16:00:17 +00:00
|
|
|
--- a/drivers/platform/x86/Kconfig
|
|
|
|
+++ b/drivers/platform/x86/Kconfig
|
2021-02-15 20:36:42 +00:00
|
|
|
@@ -1012,6 +1012,26 @@ config SURFACE_GPE
|
2020-12-16 16:00:17 +00:00
|
|
|
accordingly. It is required on those devices to allow wake-ups from
|
|
|
|
suspend by opening the lid.
|
|
|
|
|
|
|
|
+config SURFACE_HOTPLUG
|
|
|
|
+ tristate "Surface Hot-Plug System Driver"
|
|
|
|
+ depends on ACPI
|
|
|
|
+ default m
|
|
|
|
+ help
|
2021-02-15 20:36:42 +00:00
|
|
|
+ Driver for out-of-band hot-plug event signaling on Microsoft Surface
|
|
|
|
+ devices with hot-pluggable PCIe cards.
|
2020-12-16 16:00:17 +00:00
|
|
|
+
|
2021-02-15 20:36:42 +00:00
|
|
|
+ This driver is used on Surface Book (2 and 3) devices with a
|
|
|
|
+ hot-pluggable discrete GPU (dGPU). When not in use, the dGPU on those
|
|
|
|
+ devices can enter D3cold, which prevents in-band (standard) PCIe
|
|
|
|
+ hot-plug signaling. Thus, without this driver, detaching the base
|
|
|
|
+ containing the dGPU will not correctly update the state of the
|
|
|
|
+ corresponding PCIe device if it is in D3cold. This driver adds support
|
|
|
|
+ for out-of-band hot-plug notifications, ensuring that the device state
|
|
|
|
+ is properly updated even when the device in question is in D3cold.
|
|
|
|
+
|
|
|
|
+ Select M or Y here, if you want to (fully) support hot-plugging of
|
|
|
|
+ dGPU devices on the Surface Book 2 and/or 3 during D3cold.
|
2020-12-16 16:00:17 +00:00
|
|
|
+
|
|
|
|
config SURFACE_BOOK1_DGPU_SWITCH
|
|
|
|
tristate "Surface Book 1 dGPU Switch Driver"
|
|
|
|
depends on ACPI && SYSFS
|
|
|
|
diff --git a/drivers/platform/x86/Makefile b/drivers/platform/x86/Makefile
|
2021-02-15 20:36:42 +00:00
|
|
|
index 2e0a2896c78d..f552cbfb7914 100644
|
2020-12-16 16:00:17 +00:00
|
|
|
--- a/drivers/platform/x86/Makefile
|
|
|
|
+++ b/drivers/platform/x86/Makefile
|
2021-02-15 20:36:42 +00:00
|
|
|
@@ -94,6 +94,7 @@ obj-$(CONFIG_SURFACE_3_BUTTON) += surface3_button.o
|
2020-12-16 16:00:17 +00:00
|
|
|
obj-$(CONFIG_SURFACE_3_POWER_OPREGION) += surface3_power.o
|
|
|
|
obj-$(CONFIG_SURFACE_PRO3_BUTTON) += surfacepro3_button.o
|
|
|
|
obj-$(CONFIG_SURFACE_GPE) += surface_gpe.o
|
|
|
|
+obj-$(CONFIG_SURFACE_HOTPLUG) += surface_hotplug.o
|
|
|
|
obj-$(CONFIG_SURFACE_BOOK1_DGPU_SWITCH) += sb1_dgpu_sw.o
|
|
|
|
|
|
|
|
# MSI
|
|
|
|
diff --git a/drivers/platform/x86/surface_hotplug.c b/drivers/platform/x86/surface_hotplug.c
|
|
|
|
new file mode 100644
|
2021-02-15 20:36:42 +00:00
|
|
|
index 000000000000..cfcc15cfbacb
|
2020-12-16 16:00:17 +00:00
|
|
|
--- /dev/null
|
|
|
|
+++ b/drivers/platform/x86/surface_hotplug.c
|
2021-02-15 20:36:42 +00:00
|
|
|
@@ -0,0 +1,282 @@
|
2020-12-16 16:00:17 +00:00
|
|
|
+// SPDX-License-Identifier: GPL-2.0+
|
|
|
|
+/*
|
2021-02-15 20:36:42 +00:00
|
|
|
+ * Surface Book (2 and later) hot-plug driver.
|
2020-12-16 16:00:17 +00:00
|
|
|
+ *
|
|
|
|
+ * Surface Book devices (can) have a hot-pluggable discrete GPU (dGPU). This
|
|
|
|
+ * driver is responsible for out-of-band hot-plug event signaling on these
|
|
|
|
+ * devices. It is specifically required when the hot-plug device is in D3cold
|
|
|
|
+ * and can thus not generate PCIe hot-plug events itself.
|
|
|
|
+ *
|
|
|
|
+ * Event signaling is handled via ACPI, which will generate the appropriate
|
|
|
|
+ * device-check notifications to be picked up by the PCIe hot-plug driver.
|
|
|
|
+ *
|
2021-02-15 20:36:42 +00:00
|
|
|
+ * Copyright (C) 2019-2021 Maximilian Luz <luzmaximilian@gmail.com>
|
2020-12-16 16:00:17 +00:00
|
|
|
+ */
|
|
|
|
+
|
|
|
|
+#include <linux/acpi.h>
|
|
|
|
+#include <linux/gpio.h>
|
|
|
|
+#include <linux/interrupt.h>
|
|
|
|
+#include <linux/kernel.h>
|
|
|
|
+#include <linux/module.h>
|
|
|
|
+#include <linux/mutex.h>
|
|
|
|
+#include <linux/platform_device.h>
|
|
|
|
+
|
|
|
|
+static const struct acpi_gpio_params shps_base_presence_int = { 0, 0, false };
|
|
|
|
+static const struct acpi_gpio_params shps_base_presence = { 1, 0, false };
|
|
|
|
+static const struct acpi_gpio_params shps_device_power_int = { 2, 0, false };
|
|
|
|
+static const struct acpi_gpio_params shps_device_power = { 3, 0, false };
|
|
|
|
+static const struct acpi_gpio_params shps_device_presence_int = { 4, 0, false };
|
|
|
|
+static const struct acpi_gpio_params shps_device_presence = { 5, 0, false };
|
|
|
|
+
|
|
|
|
+static const struct acpi_gpio_mapping shps_acpi_gpios[] = {
|
|
|
|
+ { "base_presence-int-gpio", &shps_base_presence_int, 1 },
|
|
|
|
+ { "base_presence-gpio", &shps_base_presence, 1 },
|
|
|
|
+ { "device_power-int-gpio", &shps_device_power_int, 1 },
|
|
|
|
+ { "device_power-gpio", &shps_device_power, 1 },
|
|
|
|
+ { "device_presence-int-gpio", &shps_device_presence_int, 1 },
|
|
|
|
+ { "device_presence-gpio", &shps_device_presence, 1 },
|
|
|
|
+ { },
|
|
|
|
+};
|
|
|
|
+
|
|
|
|
+/* 5515a847-ed55-4b27-8352-cd320e10360a */
|
|
|
|
+static const guid_t shps_dsm_guid =
|
2021-02-15 20:36:42 +00:00
|
|
|
+ GUID_INIT(0x5515a847, 0xed55, 0x4b27, 0x83, 0x52, 0xcd, 0x32, 0x0e, 0x10, 0x36, 0x0a);
|
2020-12-16 16:00:17 +00:00
|
|
|
+
|
|
|
|
+#define SHPS_DSM_REVISION 1
|
|
|
|
+
|
|
|
|
+enum shps_dsm_fn {
|
|
|
|
+ SHPS_DSM_FN_PCI_NUM_ENTRIES = 0x01,
|
|
|
|
+ SHPS_DSM_FN_PCI_GET_ENTRIES = 0x02,
|
|
|
|
+ SHPS_DSM_FN_IRQ_BASE_PRESENCE = 0x03,
|
|
|
|
+ SHPS_DSM_FN_IRQ_DEVICE_POWER = 0x04,
|
|
|
|
+ SHPS_DSM_FN_IRQ_DEVICE_PRESENCE = 0x05,
|
|
|
|
+};
|
|
|
|
+
|
|
|
|
+enum shps_irq_type {
|
2021-02-15 20:36:42 +00:00
|
|
|
+ /* NOTE: Must be in order of enum shps_dsm_fn above. */
|
2020-12-16 16:00:17 +00:00
|
|
|
+ SHPS_IRQ_TYPE_BASE_PRESENCE = 0,
|
|
|
|
+ SHPS_IRQ_TYPE_DEVICE_POWER = 1,
|
|
|
|
+ SHPS_IRQ_TYPE_DEVICE_PRESENCE = 2,
|
|
|
|
+ SHPS_NUM_IRQS,
|
|
|
|
+};
|
|
|
|
+
|
|
|
|
+static const char *const shps_gpio_names[] = {
|
|
|
|
+ [SHPS_IRQ_TYPE_BASE_PRESENCE] = "base_presence",
|
|
|
|
+ [SHPS_IRQ_TYPE_DEVICE_POWER] = "device_power",
|
|
|
|
+ [SHPS_IRQ_TYPE_DEVICE_PRESENCE] = "device_presence",
|
|
|
|
+};
|
|
|
|
+
|
|
|
|
+struct shps_device {
|
2021-02-15 20:36:42 +00:00
|
|
|
+ struct mutex lock[SHPS_NUM_IRQS]; /* Protects update in shps_dsm_notify_irq() */
|
2020-12-16 16:00:17 +00:00
|
|
|
+ struct gpio_desc *gpio[SHPS_NUM_IRQS];
|
|
|
|
+ unsigned int irq[SHPS_NUM_IRQS];
|
|
|
|
+};
|
|
|
|
+
|
|
|
|
+#define SHPS_IRQ_NOT_PRESENT ((unsigned int)-1)
|
|
|
|
+
|
2021-02-15 20:36:42 +00:00
|
|
|
+static enum shps_dsm_fn shps_dsm_fn_for_irq(enum shps_irq_type type)
|
|
|
|
+{
|
|
|
|
+ return SHPS_DSM_FN_IRQ_BASE_PRESENCE + type;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+static void shps_dsm_notify_irq(struct platform_device *pdev, enum shps_irq_type type)
|
2020-12-16 16:00:17 +00:00
|
|
|
+{
|
|
|
|
+ struct shps_device *sdev = platform_get_drvdata(pdev);
|
|
|
|
+ acpi_handle handle = ACPI_HANDLE(&pdev->dev);
|
|
|
|
+ union acpi_object *result;
|
|
|
|
+ union acpi_object param;
|
|
|
|
+ int value;
|
|
|
|
+
|
|
|
|
+ mutex_lock(&sdev->lock[type]);
|
|
|
|
+
|
|
|
|
+ value = gpiod_get_value_cansleep(sdev->gpio[type]);
|
|
|
|
+ if (value < 0) {
|
|
|
|
+ mutex_unlock(&sdev->lock[type]);
|
2021-02-15 20:36:42 +00:00
|
|
|
+ dev_err(&pdev->dev, "failed to get gpio: %d (irq=%d)\n", type, value);
|
2020-12-16 16:00:17 +00:00
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+
|
2021-02-15 20:36:42 +00:00
|
|
|
+ dev_dbg(&pdev->dev, "IRQ notification via DSM (irq=%d, value=%d)\n", type, value);
|
2020-12-16 16:00:17 +00:00
|
|
|
+
|
|
|
|
+ param.type = ACPI_TYPE_INTEGER;
|
|
|
|
+ param.integer.value = value;
|
|
|
|
+
|
|
|
|
+ result = acpi_evaluate_dsm(handle, &shps_dsm_guid, SHPS_DSM_REVISION,
|
2021-02-15 20:36:42 +00:00
|
|
|
+ shps_dsm_fn_for_irq(type), ¶m);
|
2020-12-16 16:00:17 +00:00
|
|
|
+
|
|
|
|
+ if (!result) {
|
2021-02-15 20:36:42 +00:00
|
|
|
+ dev_err(&pdev->dev, "IRQ notification via DSM failed (irq=%d, gpio=%d)\n",
|
2020-12-16 16:00:17 +00:00
|
|
|
+ type, value);
|
|
|
|
+
|
2021-02-15 20:36:42 +00:00
|
|
|
+ } else if (result->type != ACPI_TYPE_BUFFER) {
|
2020-12-16 16:00:17 +00:00
|
|
|
+ dev_err(&pdev->dev,
|
|
|
|
+ "IRQ notification via DSM failed: unexpected result type (irq=%d, gpio=%d)\n",
|
|
|
|
+ type, value);
|
|
|
|
+
|
2021-02-15 20:36:42 +00:00
|
|
|
+ } else if (result->buffer.length != 1 || result->buffer.pointer[0] != 0) {
|
2020-12-16 16:00:17 +00:00
|
|
|
+ dev_err(&pdev->dev,
|
|
|
|
+ "IRQ notification via DSM failed: unexpected result value (irq=%d, gpio=%d)\n",
|
|
|
|
+ type, value);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ mutex_unlock(&sdev->lock[type]);
|
2021-02-15 20:36:42 +00:00
|
|
|
+
|
|
|
|
+ if (result)
|
|
|
|
+ ACPI_FREE(result);
|
2020-12-16 16:00:17 +00:00
|
|
|
+}
|
|
|
|
+
|
|
|
|
+static irqreturn_t shps_handle_irq(int irq, void *data)
|
|
|
|
+{
|
|
|
|
+ struct platform_device *pdev = data;
|
|
|
|
+ struct shps_device *sdev = platform_get_drvdata(pdev);
|
|
|
|
+ int type;
|
|
|
|
+
|
|
|
|
+ /* Figure out which IRQ we're handling. */
|
|
|
|
+ for (type = 0; type < SHPS_NUM_IRQS; type++)
|
|
|
|
+ if (irq == sdev->irq[type])
|
|
|
|
+ break;
|
|
|
|
+
|
|
|
|
+ /* We should have found our interrupt, if not: this is a bug. */
|
|
|
|
+ if (WARN(type >= SHPS_NUM_IRQS, "invalid IRQ number: %d\n", irq))
|
|
|
|
+ return IRQ_HANDLED;
|
|
|
|
+
|
|
|
|
+ /* Forward interrupt to ACPI via DSM. */
|
|
|
|
+ shps_dsm_notify_irq(pdev, type);
|
|
|
|
+ return IRQ_HANDLED;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+static int shps_setup_irq(struct platform_device *pdev, enum shps_irq_type type)
|
|
|
|
+{
|
|
|
|
+ unsigned long flags = IRQF_ONESHOT | IRQF_TRIGGER_FALLING | IRQF_TRIGGER_RISING;
|
|
|
|
+ struct shps_device *sdev = platform_get_drvdata(pdev);
|
|
|
|
+ struct gpio_desc *gpiod;
|
|
|
|
+ acpi_handle handle = ACPI_HANDLE(&pdev->dev);
|
|
|
|
+ const char *irq_name;
|
2021-02-15 20:36:42 +00:00
|
|
|
+ const int dsm = shps_dsm_fn_for_irq(type);
|
2020-12-16 16:00:17 +00:00
|
|
|
+ int status, irq;
|
|
|
|
+
|
2021-02-15 20:36:42 +00:00
|
|
|
+ /*
|
|
|
|
+ * Only set up interrupts that we actually need: The Surface Book 3
|
|
|
|
+ * does not have a DSM for base presence, so don't set up an interrupt
|
|
|
|
+ * for that.
|
|
|
|
+ */
|
2020-12-16 16:00:17 +00:00
|
|
|
+ if (!acpi_check_dsm(handle, &shps_dsm_guid, SHPS_DSM_REVISION, BIT(dsm))) {
|
2021-02-15 20:36:42 +00:00
|
|
|
+ dev_dbg(&pdev->dev, "IRQ notification via DSM not present (irq=%d)\n", type);
|
2020-12-16 16:00:17 +00:00
|
|
|
+ return 0;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ gpiod = devm_gpiod_get(&pdev->dev, shps_gpio_names[type], GPIOD_ASIS);
|
|
|
|
+ if (IS_ERR(gpiod))
|
|
|
|
+ return PTR_ERR(gpiod);
|
|
|
|
+
|
|
|
|
+ irq = gpiod_to_irq(gpiod);
|
|
|
|
+ if (irq < 0)
|
|
|
|
+ return irq;
|
|
|
|
+
|
|
|
|
+ irq_name = devm_kasprintf(&pdev->dev, GFP_KERNEL, "shps-irq-%d", type);
|
|
|
|
+ if (!irq_name)
|
|
|
|
+ return -ENOMEM;
|
|
|
|
+
|
|
|
|
+ status = devm_request_threaded_irq(&pdev->dev, irq, NULL, shps_handle_irq,
|
|
|
|
+ flags, irq_name, pdev);
|
|
|
|
+ if (status)
|
|
|
|
+ return status;
|
|
|
|
+
|
|
|
|
+ dev_dbg(&pdev->dev, "set up irq %d as type %d\n", irq, type);
|
|
|
|
+
|
|
|
|
+ sdev->gpio[type] = gpiod;
|
|
|
|
+ sdev->irq[type] = irq;
|
|
|
|
+
|
|
|
|
+ return 0;
|
|
|
|
+}
|
|
|
|
+
|
2021-02-15 20:36:42 +00:00
|
|
|
+static int surface_hotplug_remove(struct platform_device *pdev)
|
|
|
|
+{
|
|
|
|
+ struct shps_device *sdev = platform_get_drvdata(pdev);
|
|
|
|
+ int i;
|
|
|
|
+
|
|
|
|
+ /* Ensure that IRQs have been fully handled and won't trigger any more. */
|
|
|
|
+ for (i = 0; i < SHPS_NUM_IRQS; i++) {
|
|
|
|
+ if (sdev->irq[i] != SHPS_IRQ_NOT_PRESENT)
|
|
|
|
+ disable_irq(sdev->irq[i]);
|
|
|
|
+
|
|
|
|
+ mutex_destroy(&sdev->lock[i]);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return 0;
|
|
|
|
+}
|
|
|
|
+
|
2020-12-16 16:00:17 +00:00
|
|
|
+static int surface_hotplug_probe(struct platform_device *pdev)
|
|
|
|
+{
|
|
|
|
+ struct shps_device *sdev;
|
|
|
|
+ int status, i;
|
|
|
|
+
|
2021-02-15 20:36:42 +00:00
|
|
|
+ /*
|
|
|
|
+ * The MSHW0153 device is also present on the Surface Laptop 3,
|
|
|
|
+ * however that doesn't have a hot-pluggable PCIe device. It also
|
|
|
|
+ * doesn't have any GPIO interrupts/pins under the MSHW0153, so filter
|
|
|
|
+ * it out here.
|
|
|
|
+ */
|
2020-12-16 16:00:17 +00:00
|
|
|
+ if (gpiod_count(&pdev->dev, NULL) < 0)
|
|
|
|
+ return -ENODEV;
|
|
|
|
+
|
|
|
|
+ status = devm_acpi_dev_add_driver_gpios(&pdev->dev, shps_acpi_gpios);
|
|
|
|
+ if (status)
|
|
|
|
+ return status;
|
|
|
|
+
|
|
|
|
+ sdev = devm_kzalloc(&pdev->dev, sizeof(*sdev), GFP_KERNEL);
|
|
|
|
+ if (!sdev)
|
|
|
|
+ return -ENOMEM;
|
|
|
|
+
|
|
|
|
+ platform_set_drvdata(pdev, sdev);
|
|
|
|
+
|
2021-02-15 20:36:42 +00:00
|
|
|
+ /*
|
|
|
|
+ * Initialize IRQs so that we can safely call surface_hotplug_remove()
|
|
|
|
+ * on errors.
|
|
|
|
+ */
|
|
|
|
+ for (i = 0; i < SHPS_NUM_IRQS; i++)
|
|
|
|
+ sdev->irq[i] = SHPS_IRQ_NOT_PRESENT;
|
|
|
|
+
|
2020-12-16 16:00:17 +00:00
|
|
|
+ /* Set up IRQs. */
|
|
|
|
+ for (i = 0; i < SHPS_NUM_IRQS; i++) {
|
|
|
|
+ mutex_init(&sdev->lock[i]);
|
|
|
|
+
|
|
|
|
+ status = shps_setup_irq(pdev, i);
|
|
|
|
+ if (status) {
|
2021-02-15 20:36:42 +00:00
|
|
|
+ dev_err(&pdev->dev, "failed to set up IRQ %d: %d\n", i, status);
|
|
|
|
+ goto err;
|
2020-12-16 16:00:17 +00:00
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /* Ensure everything is up-to-date. */
|
|
|
|
+ for (i = 0; i < SHPS_NUM_IRQS; i++)
|
|
|
|
+ if (sdev->irq[i] != SHPS_IRQ_NOT_PRESENT)
|
|
|
|
+ shps_dsm_notify_irq(pdev, i);
|
|
|
|
+
|
|
|
|
+ return 0;
|
|
|
|
+
|
2021-02-15 20:36:42 +00:00
|
|
|
+err:
|
|
|
|
+ surface_hotplug_remove(pdev);
|
|
|
|
+ return status;
|
2020-12-16 16:00:17 +00:00
|
|
|
+}
|
|
|
|
+
|
|
|
|
+static const struct acpi_device_id surface_hotplug_acpi_match[] = {
|
|
|
|
+ { "MSHW0153", 0 },
|
|
|
|
+ { },
|
|
|
|
+};
|
|
|
|
+MODULE_DEVICE_TABLE(acpi, surface_hotplug_acpi_match);
|
|
|
|
+
|
|
|
|
+static struct platform_driver surface_hotplug_driver = {
|
|
|
|
+ .probe = surface_hotplug_probe,
|
|
|
|
+ .remove = surface_hotplug_remove,
|
|
|
|
+ .driver = {
|
|
|
|
+ .name = "surface_hotplug",
|
|
|
|
+ .acpi_match_table = surface_hotplug_acpi_match,
|
|
|
|
+ .probe_type = PROBE_PREFER_ASYNCHRONOUS,
|
|
|
|
+ },
|
|
|
|
+};
|
|
|
|
+module_platform_driver(surface_hotplug_driver);
|
|
|
|
+
|
|
|
|
+MODULE_AUTHOR("Maximilian Luz <luzmaximilian@gmail.com>");
|
|
|
|
+MODULE_DESCRIPTION("Surface Hot-Plug Signaling Driver for Surface Book Devices");
|
|
|
|
+MODULE_LICENSE("GPL");
|
|
|
|
--
|
2021-06-13 21:00:11 +00:00
|
|
|
2.32.0
|
2020-12-16 16:00:17 +00:00
|
|
|
|