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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
|
/* SPDX-License-Identifier: GPL-2.0-only */
#include <acpi/acpigen.h>
#include <console/console.h>
#include <device/device.h>
#include <device/pci.h>
#include <device/pci_ids.h>
#include <stdint.h>
#include "chip.h"
#define ACPI_DSM_PRIVACY_SCREEN_UUID "C7033113-8720-4CEB-9090-9D52B3E52D73"
#define ACPI_METHOD_EPS_PRESENT "EPSP"
#define ACPI_METHOD_EPS_STATE "EPSS"
#define ACPI_METHOD_EPS_ENABLE "EPSE"
#define ACPI_METHOD_EPS_DISABLE "EPSD"
static void privacy_screen_detect_cb(void *arg)
{
struct drivers_gfx_generic_privacy_screen_config *config = arg;
acpigen_write_store();
acpigen_emit_namestring(config->detect_function);
acpigen_emit_byte(LOCAL2_OP);
acpigen_write_if_lequal_op_int(LOCAL2_OP, 1);
acpigen_write_return_singleton_buffer(0xF);
acpigen_pop_len();
}
static void privacy_screen_get_status_cb(void *arg)
{
struct drivers_gfx_generic_privacy_screen_config *config = arg;
acpigen_emit_byte(RETURN_OP);
acpigen_emit_namestring(config->status_function);
}
static void privacy_screen_enable_cb(void *arg)
{
struct drivers_gfx_generic_privacy_screen_config *config = arg;
acpigen_emit_namestring(config->enable_function);
}
static void privacy_screen_disable_cb(void *arg)
{
struct drivers_gfx_generic_privacy_screen_config *config = arg;
acpigen_emit_namestring(config->disable_function);
}
static void (*privacy_screen_callbacks[])(void *) = {
privacy_screen_detect_cb,
privacy_screen_get_status_cb,
privacy_screen_enable_cb,
privacy_screen_disable_cb,
};
static void privacy_gpio_acpigen(struct acpi_gpio *gpio)
{
/* EPS Present */
acpigen_write_method(ACPI_METHOD_EPS_PRESENT, 0);
acpigen_write_return_byte(1);
acpigen_pop_len();
/* EPS State */
acpigen_write_method(ACPI_METHOD_EPS_STATE, 0);
acpigen_get_rx_gpio(gpio);
acpigen_emit_byte(RETURN_OP);
acpigen_emit_byte(LOCAL0_OP);
acpigen_pop_len();
/* EPS Enable */
acpigen_write_method(ACPI_METHOD_EPS_ENABLE, 0);
acpigen_enable_tx_gpio(gpio);
acpigen_pop_len();
/* EPS Disable */
acpigen_write_method(ACPI_METHOD_EPS_DISABLE, 0);
acpigen_disable_tx_gpio(gpio);
acpigen_pop_len();
}
static void gfx_fill_privacy_screen_dsm(
struct drivers_gfx_generic_privacy_screen_config *privacy)
{
if (!privacy->enabled)
return;
/* Populate ACPI methods, if EPS controlled via gpio */
if (privacy->gpio.pin_count == 1) {
privacy_gpio_acpigen(&privacy->gpio);
privacy->detect_function = ACPI_METHOD_EPS_PRESENT;
privacy->status_function = ACPI_METHOD_EPS_STATE;
privacy->enable_function = ACPI_METHOD_EPS_ENABLE;
privacy->disable_function = ACPI_METHOD_EPS_DISABLE;
}
acpigen_write_dsm(ACPI_DSM_PRIVACY_SCREEN_UUID,
privacy_screen_callbacks,
ARRAY_SIZE(privacy_screen_callbacks),
privacy);
}
static void gfx_fill_ssdt_generator(const struct device *dev)
{
size_t i;
struct drivers_gfx_generic_config *config = dev->chip_info;
const char *scope = acpi_device_scope(dev);
if (!scope || !dev->enabled)
return;
acpigen_write_scope(scope);
/* Method (_DOD, 0) */
acpigen_write_method("_DOD", 0);
acpigen_emit_byte(RETURN_OP);
acpigen_write_package(config->device_count);
for (i = 0; i < config->device_count; i++)
acpigen_write_dword(config->device[i].addr);
acpigen_pop_len(); /* End Package. */
acpigen_pop_len(); /* End Method. */
for (i = 0; i < config->device_count; i++) {
acpigen_write_device(config->device[i].name);
acpigen_write_name_integer("_ADR", config->device[i].addr);
acpigen_write_name_integer("_STA", 0xF);
gfx_fill_privacy_screen_dsm(&config->device[i].privacy);
acpigen_pop_len(); /* Device */
}
acpigen_pop_len(); /* Scope */
}
static const char *gfx_acpi_name(const struct device *dev)
{
struct drivers_gfx_generic_config *config = dev->chip_info;
return config->name ? : "GFX0";
}
static struct device_operations gfx_ops = {
.acpi_name = gfx_acpi_name,
.acpi_fill_ssdt = gfx_fill_ssdt_generator,
};
static void gfx_enable(struct device *dev)
{
struct drivers_gfx_generic_config *config = dev->chip_info;
if (!config || !dev->enabled)
return;
dev->ops = &gfx_ops;
}
struct chip_operations drivers_gfx_generic_ops = {
CHIP_NAME("Generic Graphics Device")
.enable_dev = gfx_enable
};
struct device *find_gfx_dev(void)
{
struct device *dev;
for (dev = all_devices; dev; dev = dev->next) {
if (dev->chip_ops && dev->chip_ops == &drivers_gfx_generic_ops)
return dev;
}
return NULL;
}
|