1 /* SPDX-License-Identifier: GPL-2.0-only */
3 #include <acpi/acpi_device.h>
4 #include <acpi/acpigen.h>
5 #include <device/device.h>
10 static struct acpi_dp
*gpio_keys_add_child_node(
11 struct drivers_generic_gpio_keys_config
*config
,
12 const char *parent_path
)
14 struct key_info
*key
= &config
->key
;
17 if (!key
->dev_name
|| !key
->linux_code
)
20 dsd
= acpi_dp_new_table(config
->key
.dev_name
);
22 acpi_dp_add_integer(dsd
, "linux,code", key
->linux_code
);
23 if (key
->linux_input_type
)
24 acpi_dp_add_integer(dsd
, "linux,input-type",
25 key
->linux_input_type
);
27 acpi_dp_add_string(dsd
, "label", key
->label
);
29 if (key
->wakeup_route
== WAKEUP_ROUTE_SCI
)
30 acpigen_write_PRW(key
->wake_gpe
, 3);
32 if (key
->wakeup_route
!= WAKEUP_ROUTE_DISABLED
) {
33 acpi_dp_add_integer(dsd
, "wakeup-source", 1);
34 acpi_dp_add_integer(dsd
, "wakeup-event-action",
35 key
->wakeup_event_action
);
38 if (key
->can_be_disabled
)
39 acpi_dp_add_integer(dsd
, "linux,can-disable",
40 key
->can_be_disabled
);
41 if (key
->debounce_interval
)
42 acpi_dp_add_integer(dsd
, "debounce-interval",
43 key
->debounce_interval
);
44 acpi_dp_add_gpio(dsd
, "gpios", parent_path
, 0, 0,
45 config
->gpio
.active_low
);
50 static void gpio_keys_fill_ssdt_generator(const struct device
*dev
)
52 struct drivers_generic_gpio_keys_config
*config
= dev
->chip_info
;
53 const char *scope
= acpi_device_scope(dev
);
54 const char *path
= acpi_device_path(dev
);
55 struct acpi_dp
*dsd
, *child
;
56 const char *drv_string
= config
->is_polled
? "gpio-keys-polled"
59 if (!scope
|| !path
|| !config
->gpio
.pin_count
)
63 acpigen_write_scope(scope
);
64 acpigen_write_device(acpi_device_name(dev
));
66 /* _HID is set to PRP0001 */
67 acpigen_write_name_string("_HID", ACPI_DT_NAMESPACE_HID
);
69 /* Resources - _CRS */
70 acpigen_write_name("_CRS");
71 acpigen_write_resourcetemplate_header();
72 acpi_device_write_gpio(&config
->gpio
);
73 acpigen_write_resourcetemplate_footer();
76 dsd
= acpi_dp_new_table("_DSD");
77 acpi_dp_add_string(dsd
, "compatible", drv_string
);
79 acpi_dp_add_string(dsd
, "label", config
->label
);
80 if (config
->is_polled
)
81 acpi_dp_add_integer(dsd
, "poll-interval",
82 config
->poll_interval
);
83 /* Child device defining key */
84 child
= gpio_keys_add_child_node(config
, path
);
86 acpi_dp_add_child(dsd
, "button-0", child
);
89 acpigen_write_STA(acpi_device_status(dev
));
91 acpigen_pop_len(); /* Device */
92 acpigen_pop_len(); /* Scope */
95 static const char *gpio_keys_acpi_name(const struct device
*dev
)
97 struct drivers_generic_gpio_keys_config
*config
= dev
->chip_info
;
103 snprintf(name
, sizeof(name
), "K%03.3X", config
->gpio
.pins
[0]);
109 static struct device_operations gpio_keys_ops
= {
110 .read_resources
= noop_read_resources
,
111 .set_resources
= noop_set_resources
,
112 .acpi_name
= gpio_keys_acpi_name
,
113 .acpi_fill_ssdt
= gpio_keys_fill_ssdt_generator
,
116 static void gpio_keys_enable(struct device
*dev
)
118 dev
->ops
= &gpio_keys_ops
;
121 struct chip_operations drivers_generic_gpio_keys_ops
= {
123 .enable_dev
= gpio_keys_enable