^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * Driver for the LID cover switch of the Surface 3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Copyright (c) 2016 Red Hat Inc.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/acpi.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <linux/dmi.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <linux/input.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include <linux/mutex.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include <linux/platform_device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include <linux/spi/spi.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) MODULE_AUTHOR("Benjamin Tissoires <benjamin.tissoires@redhat.com>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) MODULE_DESCRIPTION("Surface 3 platform driver");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) MODULE_LICENSE("GPL");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #define ACPI_BUTTON_HID_LID "PNP0C0D"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) #define SPI_CTL_OBJ_NAME "SPI"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) #define SPI_TS_OBJ_NAME "NTRG"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) #define SURFACE3_LID_GUID "F7CC25EC-D20B-404C-8903-0ED4359C18AE"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) MODULE_ALIAS("wmi:" SURFACE3_LID_GUID);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) static const struct dmi_system_id surface3_dmi_table[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) #if defined(CONFIG_X86)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) .matches = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) DMI_MATCH(DMI_SYS_VENDOR, "Microsoft Corporation"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) DMI_MATCH(DMI_PRODUCT_NAME, "Surface 3"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) { }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) struct surface3_wmi {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) struct acpi_device *touchscreen_adev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) struct acpi_device *pnp0c0d_adev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) struct acpi_hotplug_context hp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) struct input_dev *input;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) static struct platform_device *s3_wmi_pdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) static struct surface3_wmi s3_wmi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) static DEFINE_MUTEX(s3_wmi_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) static int s3_wmi_query_block(const char *guid, int instance, int *ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) struct acpi_buffer output = { ACPI_ALLOCATE_BUFFER, NULL };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) acpi_status status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) union acpi_object *obj;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) int error = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) mutex_lock(&s3_wmi_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) status = wmi_query_block(guid, instance, &output);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) obj = output.pointer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) if (!obj || obj->type != ACPI_TYPE_INTEGER) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) if (obj) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) pr_err("query block returned object type: %d - buffer length:%d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) obj->type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) obj->type == ACPI_TYPE_BUFFER ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) obj->buffer.length : 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) error = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) goto out_free_unlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) *ret = obj->integer.value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) out_free_unlock:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) kfree(obj);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) mutex_unlock(&s3_wmi_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) static inline int s3_wmi_query_lid(int *ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) return s3_wmi_query_block(SURFACE3_LID_GUID, 0, ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) static int s3_wmi_send_lid_state(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) int ret, lid_sw;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) ret = s3_wmi_query_lid(&lid_sw);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) input_report_switch(s3_wmi.input, SW_LID, lid_sw);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) input_sync(s3_wmi.input);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) static int s3_wmi_hp_notify(struct acpi_device *adev, u32 value)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) return s3_wmi_send_lid_state();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) static acpi_status s3_wmi_attach_spi_device(acpi_handle handle,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) u32 level,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) void *data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) void **return_value)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) struct acpi_device *adev, **ts_adev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) if (acpi_bus_get_device(handle, &adev))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) return AE_OK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) ts_adev = data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) if (strncmp(acpi_device_bid(adev), SPI_TS_OBJ_NAME,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) strlen(SPI_TS_OBJ_NAME)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) return AE_OK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) if (*ts_adev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) pr_err("duplicate entry %s\n", SPI_TS_OBJ_NAME);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) return AE_OK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) *ts_adev = adev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) return AE_OK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) static int s3_wmi_check_platform_device(struct device *dev, void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) struct acpi_device *adev, *ts_adev = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) acpi_handle handle;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) acpi_status status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) /* ignore non ACPI devices */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) handle = ACPI_HANDLE(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) if (!handle || acpi_bus_get_device(handle, &adev))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) /* check for LID ACPI switch */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) if (!strcmp(ACPI_BUTTON_HID_LID, acpi_device_hid(adev))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) s3_wmi.pnp0c0d_adev = adev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) /* ignore non SPI controllers */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) if (strncmp(acpi_device_bid(adev), SPI_CTL_OBJ_NAME,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) strlen(SPI_CTL_OBJ_NAME)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) status = acpi_walk_namespace(ACPI_TYPE_DEVICE, handle, 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) s3_wmi_attach_spi_device, NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) &ts_adev, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) if (ACPI_FAILURE(status))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) dev_warn(dev, "failed to enumerate SPI slaves\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) if (!ts_adev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) s3_wmi.touchscreen_adev = ts_adev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) static int s3_wmi_create_and_register_input(struct platform_device *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) struct input_dev *input;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) input = devm_input_allocate_device(&pdev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) if (!input)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) input->name = "Lid Switch";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) input->phys = "button/input0";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) input->id.bustype = BUS_HOST;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) input->id.product = 0x0005;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) input_set_capability(input, EV_SW, SW_LID);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) error = input_register_device(input);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) goto out_err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) s3_wmi.input = input;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) out_err:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) input_free_device(s3_wmi.input);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) static int __init s3_wmi_probe(struct platform_device *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) if (!dmi_check_system(surface3_dmi_table))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) memset(&s3_wmi, 0, sizeof(s3_wmi));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) bus_for_each_dev(&platform_bus_type, NULL, NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) s3_wmi_check_platform_device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) if (!s3_wmi.touchscreen_adev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) acpi_bus_trim(s3_wmi.pnp0c0d_adev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) error = s3_wmi_create_and_register_input(pdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) goto restore_acpi_lid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) acpi_initialize_hp_context(s3_wmi.touchscreen_adev, &s3_wmi.hp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) s3_wmi_hp_notify, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) s3_wmi_send_lid_state();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) restore_acpi_lid:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) acpi_bus_scan(s3_wmi.pnp0c0d_adev->handle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) static int s3_wmi_remove(struct platform_device *device)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) /* remove the hotplug context from the acpi device */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) s3_wmi.touchscreen_adev->hp = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) /* reinstall the actual PNPC0C0D LID default handle */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) acpi_bus_scan(s3_wmi.pnp0c0d_adev->handle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) static int __maybe_unused s3_wmi_resume(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) s3_wmi_send_lid_state();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) static SIMPLE_DEV_PM_OPS(s3_wmi_pm, NULL, s3_wmi_resume);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) static struct platform_driver s3_wmi_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) .driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) .name = "surface3-wmi",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) .pm = &s3_wmi_pm,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) .remove = s3_wmi_remove,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) static int __init s3_wmi_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) s3_wmi_pdev = platform_device_alloc("surface3-wmi", -1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) if (!s3_wmi_pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) error = platform_device_add(s3_wmi_pdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) goto err_device_put;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) error = platform_driver_probe(&s3_wmi_driver, s3_wmi_probe);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) goto err_device_del;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) pr_info("Surface 3 WMI Extras loaded\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) err_device_del:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) platform_device_del(s3_wmi_pdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) err_device_put:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) platform_device_put(s3_wmi_pdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) static void __exit s3_wmi_exit(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) platform_device_unregister(s3_wmi_pdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) platform_driver_unregister(&s3_wmi_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) module_init(s3_wmi_init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) module_exit(s3_wmi_exit);