1 /* SPDX-License-Identifier: GPL-2.0-only */
3 #include <acpi/acpigen.h>
4 #include <device/device.h>
5 #include <device/pci.h>
6 #include <device/pci_ids.h>
10 #define ACPI_DSM_PRIVACY_SCREEN_UUID "C7033113-8720-4CEB-9090-9D52B3E52D73"
12 #define ACPI_METHOD_EPS_PRESENT "EPSP"
13 #define ACPI_METHOD_EPS_STATE "EPSS"
14 #define ACPI_METHOD_EPS_ENABLE "EPSE"
15 #define ACPI_METHOD_EPS_DISABLE "EPSD"
17 static void privacy_screen_detect_cb(void *arg
)
19 struct drivers_gfx_generic_privacy_screen_config
*config
= arg
;
21 acpigen_write_store();
22 acpigen_emit_namestring(config
->detect_function
);
23 acpigen_emit_byte(LOCAL2_OP
);
24 acpigen_write_if_lequal_op_int(LOCAL2_OP
, 1);
25 acpigen_write_return_singleton_buffer(0xF);
28 static void privacy_screen_get_status_cb(void *arg
)
30 struct drivers_gfx_generic_privacy_screen_config
*config
= arg
;
32 acpigen_emit_byte(RETURN_OP
);
33 acpigen_emit_namestring(config
->status_function
);
35 static void privacy_screen_enable_cb(void *arg
)
37 struct drivers_gfx_generic_privacy_screen_config
*config
= arg
;
39 acpigen_emit_namestring(config
->enable_function
);
41 static void privacy_screen_disable_cb(void *arg
)
43 struct drivers_gfx_generic_privacy_screen_config
*config
= arg
;
45 acpigen_emit_namestring(config
->disable_function
);
48 static void (*privacy_screen_callbacks
[])(void *) = {
49 privacy_screen_detect_cb
,
50 privacy_screen_get_status_cb
,
51 privacy_screen_enable_cb
,
52 privacy_screen_disable_cb
,
55 static void privacy_gpio_acpigen(struct acpi_gpio
*gpio
)
58 acpigen_write_method(ACPI_METHOD_EPS_PRESENT
, 0);
59 acpigen_write_return_byte(1);
63 acpigen_write_method(ACPI_METHOD_EPS_STATE
, 0);
64 acpigen_get_rx_gpio(gpio
);
65 acpigen_emit_byte(RETURN_OP
);
66 acpigen_emit_byte(LOCAL0_OP
);
70 acpigen_write_method(ACPI_METHOD_EPS_ENABLE
, 0);
71 acpigen_enable_tx_gpio(gpio
);
75 acpigen_write_method(ACPI_METHOD_EPS_DISABLE
, 0);
76 acpigen_disable_tx_gpio(gpio
);
80 static void gfx_fill_privacy_screen_dsm(
81 struct drivers_gfx_generic_privacy_screen_config
*privacy
)
83 if (!privacy
->enabled
)
86 /* Populate ACPI methods, if EPS controlled via gpio */
87 if (privacy
->gpio
.pin_count
== 1) {
88 privacy_gpio_acpigen(&privacy
->gpio
);
89 privacy
->detect_function
= ACPI_METHOD_EPS_PRESENT
;
90 privacy
->status_function
= ACPI_METHOD_EPS_STATE
;
91 privacy
->enable_function
= ACPI_METHOD_EPS_ENABLE
;
92 privacy
->disable_function
= ACPI_METHOD_EPS_DISABLE
;
95 acpigen_write_dsm(ACPI_DSM_PRIVACY_SCREEN_UUID
,
96 privacy_screen_callbacks
,
97 ARRAY_SIZE(privacy_screen_callbacks
),
101 static void gfx_fill_ssdt_generator(const struct device
*dev
)
104 struct drivers_gfx_generic_config
*config
= dev
->chip_info
;
106 const char *scope
= acpi_device_scope(dev
);
111 acpigen_write_scope(scope
);
113 /* Method (_DOD, 0) */
114 acpigen_write_method("_DOD", 0);
115 acpigen_emit_byte(RETURN_OP
);
116 acpigen_write_package(config
->device_count
);
117 for (i
= 0; i
< config
->device_count
; i
++)
118 acpigen_write_dword(config
->device
[i
].addr
);
119 acpigen_pop_len(); /* End Package. */
120 acpigen_pop_len(); /* End Method. */
122 for (i
= 0; i
< config
->device_count
; i
++) {
123 acpigen_write_device(config
->device
[i
].name
);
124 if (config
->device
[i
].hid
)
125 acpigen_write_name_string("_HID", config
->device
[i
].hid
);
127 acpigen_write_name_integer("_ADR", config
->device
[i
].addr
);
129 acpigen_write_name_integer("_STA", 0xF);
130 gfx_fill_privacy_screen_dsm(&config
->device
[i
].privacy
);
131 acpigen_pop_len(); /* Device */
133 acpigen_pop_len(); /* Scope */
136 static const char *gfx_acpi_name(const struct device
*dev
)
138 struct drivers_gfx_generic_config
*config
= dev
->chip_info
;
140 return config
->name
? : "GFX0";
143 static struct device_operations gfx_ops
= {
144 .acpi_name
= gfx_acpi_name
,
145 .acpi_fill_ssdt
= gfx_fill_ssdt_generator
,
148 static void gfx_enable(struct device
*dev
)
150 struct drivers_gfx_generic_config
*config
= dev
->chip_info
;
152 if (!config
|| !dev
->enabled
)
158 struct chip_operations drivers_gfx_generic_ops
= {
159 CHIP_NAME("Generic Graphics Device")
160 .enable_dev
= gfx_enable