summaryrefslogtreecommitdiff
path: root/drivers/hid/intel-thc-hid/intel-thc/intel-thc-wot.c
blob: 1291b4ea2cd8009225126a47b941ec3a5f119628 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
// SPDX-License-Identifier: GPL-2.0
/* Copyright (c) 2025 Intel Corporation */

#include <linux/acpi.h>
#include <linux/pm_wakeirq.h>

#include "intel-thc-dev.h"
#include "intel-thc-wot.h"

/**
 * thc_wot_config - Query and configure wake-on-touch feature
 * @thc_dev: Point to thc_device structure
 * @gpio_map: Point to ACPI GPIO resource mapping structure
 *
 * THC ACPI device only provides _CRS with GpioInt() resources, doesn't contain
 * _DSD to map this GPIO resource, so this function first registers wake GPIO
 * mapping manually, then queries wake-on-touch GPIO resource from ACPI,
 * if it exists and is wake-able, configure driver to enable it, otherwise,
 * return immediately.
 * This function will not return error as it doesn't impact major function.
 */
void thc_wot_config(struct thc_device *thc_dev, const struct acpi_gpio_mapping *gpio_map)
{
	struct acpi_device *adev;
	struct thc_wot *wot;
	int ret;

	if (!thc_dev)
		return;

	adev = ACPI_COMPANION(thc_dev->dev);
	if (!adev)
		return;

	wot = &thc_dev->wot;

	ret = acpi_dev_add_driver_gpios(adev, gpio_map);
	if (ret) {
		dev_warn(thc_dev->dev, "Can't add wake GPIO resource, ret = %d\n", ret);
		return;
	}

	wot->gpio_irq = acpi_dev_gpio_irq_wake_get_by(adev, "wake-on-touch", 0,
						      &wot->gpio_irq_wakeable);
	if (wot->gpio_irq <= 0) {
		dev_warn(thc_dev->dev, "Can't find wake GPIO resource\n");
		return;
	}

	if (!wot->gpio_irq_wakeable) {
		dev_warn(thc_dev->dev, "GPIO resource isn't wakeable\n");
		return;
	}

	ret = device_init_wakeup(thc_dev->dev, true);
	if (ret) {
		dev_warn(thc_dev->dev, "Failed to init wake up.\n");
		return;
	}

	ret = dev_pm_set_dedicated_wake_irq(thc_dev->dev, wot->gpio_irq);
	if (ret) {
		dev_warn(thc_dev->dev, "Failed to set wake up IRQ.\n");
		device_init_wakeup(thc_dev->dev, false);
	}
}
EXPORT_SYMBOL_NS_GPL(thc_wot_config, "INTEL_THC");

/**
 * thc_wot_unconfig - Unconfig wake-on-touch feature
 * @thc_dev: Point to thc_device structure
 *
 * Configure driver to disable wake-on-touch and release ACPI resource.
 */
void thc_wot_unconfig(struct thc_device *thc_dev)
{
	struct acpi_device *adev;

	if (!thc_dev)
		return;

	adev = ACPI_COMPANION(thc_dev->dev);
	if (!adev)
		return;

	if (thc_dev->wot.gpio_irq_wakeable)
		device_init_wakeup(thc_dev->dev, false);

	if (thc_dev->wot.gpio_irq > 0) {
		dev_pm_clear_wake_irq(thc_dev->dev);
		acpi_dev_remove_driver_gpios(adev);
	}
}
EXPORT_SYMBOL_NS_GPL(thc_wot_unconfig, "INTEL_THC");