1 /* SPDX-License-Identifier: GPL-2.0-only */
3 #include <acpi/acpi_device.h>
4 #include <acpi/acpigen.h>
5 #include <device/device.h>
6 #include <device/path.h>
11 static struct acpi_dp
*gpio_keys_add_child_node(
12 struct drivers_generic_gpio_keys_config
*config
,
13 const char *parent_path
)
15 struct key_info
*key
= &config
->key
;
18 if (!key
->dev_name
|| !key
->linux_code
)
21 dsd
= acpi_dp_new_table(config
->key
.dev_name
);
23 acpi_dp_add_integer(dsd
, "linux,code", key
->linux_code
);
24 if (key
->linux_input_type
)
25 acpi_dp_add_integer(dsd
, "linux,input-type",
26 key
->linux_input_type
);
28 acpi_dp_add_string(dsd
, "label", key
->label
);
30 if (key
->wakeup_route
== WAKEUP_ROUTE_SCI
)
31 acpigen_write_PRW(key
->wake_gpe
, 3);
33 if (key
->wakeup_route
!= WAKEUP_ROUTE_DISABLED
) {
34 acpi_dp_add_integer(dsd
, "wakeup-source", 1);
35 acpi_dp_add_integer(dsd
, "wakeup-event-action",
36 key
->wakeup_event_action
);
39 if (key
->can_be_disabled
)
40 acpi_dp_add_integer(dsd
, "linux,can-disable",
41 key
->can_be_disabled
);
42 if (key
->debounce_interval
)
43 acpi_dp_add_integer(dsd
, "debounce-interval",
44 key
->debounce_interval
);
45 acpi_dp_add_gpio(dsd
, "gpios", parent_path
, 0, 0,
46 config
->gpio
.active_low
);
51 static void gpio_keys_fill_ssdt_generator(const struct device
*dev
)
53 struct drivers_generic_gpio_keys_config
*config
= dev
->chip_info
;
54 const char *scope
= acpi_device_scope(dev
);
55 const char *path
= acpi_device_path(dev
);
56 struct acpi_dp
*dsd
, *child
;
57 const char *drv_string
= config
->is_polled
? "gpio-keys-polled"
60 if (!scope
|| !path
|| !config
->gpio
.pin_count
)
64 acpigen_write_scope(scope
);
65 acpigen_write_device(acpi_device_name(dev
));
67 /* _HID is set to PRP0001 */
68 acpigen_write_name_string("_HID", ACPI_DT_NAMESPACE_HID
);
70 /* Resources - _CRS */
71 acpigen_write_name("_CRS");
72 acpigen_write_resourcetemplate_header();
73 acpi_device_write_gpio(&config
->gpio
);
74 acpigen_write_resourcetemplate_footer();
77 dsd
= acpi_dp_new_table("_DSD");
78 acpi_dp_add_string(dsd
, "compatible", drv_string
);
80 acpi_dp_add_string(dsd
, "label", config
->label
);
81 if (config
->is_polled
)
82 acpi_dp_add_integer(dsd
, "poll-interval",
83 config
->poll_interval
);
84 /* Child device defining key */
85 child
= gpio_keys_add_child_node(config
, path
);
87 acpi_dp_add_child(dsd
, "button-0", child
);
90 acpigen_pop_len(); /* Device */
91 acpigen_pop_len(); /* Scope */
94 static const char *gpio_keys_acpi_name(const struct device
*dev
)
96 struct drivers_generic_gpio_keys_config
*config
= dev
->chip_info
;
102 snprintf(name
, sizeof(name
), "K%03.3X", config
->gpio
.pins
[0]);
108 static struct device_operations gpio_keys_ops
= {
109 .read_resources
= noop_read_resources
,
110 .set_resources
= noop_set_resources
,
111 .acpi_name
= gpio_keys_acpi_name
,
112 .acpi_fill_ssdt
= gpio_keys_fill_ssdt_generator
,
115 static void gpio_keys_enable(struct device
*dev
)
117 dev
->ops
= &gpio_keys_ops
;
120 struct chip_operations drivers_generic_gpio_keys_ops
= {
121 CHIP_NAME("GPIO Keys")
122 .enable_dev
= gpio_keys_enable