blob: d3a4518d40f392a6367526014cc4a91de7175c69 [file] [log] [blame]
Angel Pons8a3453f2020-04-02 23:48:19 +02001/* SPDX-License-Identifier: GPL-2.0-only */
Mathew Kingc135b822019-10-14 10:19:15 -06002
Furquan Shaikh76cedd22020-05-02 10:24:23 -07003#include <acpi/acpigen.h>
Mathew Kingc135b822019-10-14 10:19:15 -06004#include <console/console.h>
5#include <device/device.h>
6#include <device/pci.h>
7#include <device/pci_ids.h>
Mathew Kingc135b822019-10-14 10:19:15 -06008
9#include "chip.h"
10
11#define ACPI_DSM_PRIVACY_SCREEN_UUID "C7033113-8720-4CEB-9090-9D52B3E52D73"
12
Rajat Jain7ef06b02020-02-26 23:28:02 -080013#define ACPI_METHOD_EPS_PRESENT "EPSP"
14#define ACPI_METHOD_EPS_STATE "EPSS"
15#define ACPI_METHOD_EPS_ENABLE "EPSE"
16#define ACPI_METHOD_EPS_DISABLE "EPSD"
17
Mathew Kingc135b822019-10-14 10:19:15 -060018static void privacy_screen_detect_cb(void *arg)
19{
Furquan Shaikha0b0d422020-02-21 09:57:54 -080020 struct drivers_gfx_generic_privacy_screen_config *config = arg;
Mathew Kingc135b822019-10-14 10:19:15 -060021
22 acpigen_write_store();
23 acpigen_emit_namestring(config->detect_function);
24 acpigen_emit_byte(LOCAL2_OP);
25 acpigen_write_if_lequal_op_int(LOCAL2_OP, 1);
26 acpigen_write_return_singleton_buffer(0xF);
27 acpigen_pop_len();
28}
29static void privacy_screen_get_status_cb(void *arg)
30{
Furquan Shaikha0b0d422020-02-21 09:57:54 -080031 struct drivers_gfx_generic_privacy_screen_config *config = arg;
Mathew Kingc135b822019-10-14 10:19:15 -060032
33 acpigen_emit_byte(RETURN_OP);
34 acpigen_emit_namestring(config->status_function);
35}
36static void privacy_screen_enable_cb(void *arg)
37{
Furquan Shaikha0b0d422020-02-21 09:57:54 -080038 struct drivers_gfx_generic_privacy_screen_config *config = arg;
Mathew Kingc135b822019-10-14 10:19:15 -060039
40 acpigen_emit_namestring(config->enable_function);
41}
42static void privacy_screen_disable_cb(void *arg)
43{
Furquan Shaikha0b0d422020-02-21 09:57:54 -080044 struct drivers_gfx_generic_privacy_screen_config *config = arg;
Mathew Kingc135b822019-10-14 10:19:15 -060045
46 acpigen_emit_namestring(config->disable_function);
47}
48
49static void (*privacy_screen_callbacks[])(void *) = {
50 privacy_screen_detect_cb,
51 privacy_screen_get_status_cb,
52 privacy_screen_enable_cb,
53 privacy_screen_disable_cb,
54};
55
Rajat Jain7ef06b02020-02-26 23:28:02 -080056static void privacy_gpio_acpigen(struct acpi_gpio *gpio)
57{
58 /* EPS Present */
59 acpigen_write_method(ACPI_METHOD_EPS_PRESENT, 0);
60 acpigen_write_return_byte(1);
61 acpigen_pop_len();
62
63 /* EPS State */
64 acpigen_write_method(ACPI_METHOD_EPS_STATE, 0);
65 acpigen_get_rx_gpio(gpio);
66 acpigen_emit_byte(RETURN_OP);
67 acpigen_emit_byte(LOCAL0_OP);
68 acpigen_pop_len();
69
70 /* EPS Enable */
71 acpigen_write_method(ACPI_METHOD_EPS_ENABLE, 0);
72 acpigen_enable_tx_gpio(gpio);
73 acpigen_pop_len();
74
75 /* EPS Disable */
76 acpigen_write_method(ACPI_METHOD_EPS_DISABLE, 0);
77 acpigen_disable_tx_gpio(gpio);
78 acpigen_pop_len();
79}
80
81static void gfx_fill_privacy_screen_dsm(
82 struct drivers_gfx_generic_privacy_screen_config *privacy)
83{
84 if (!privacy->enabled)
85 return;
86
87 /* Populate ACPI methods, if EPS controlled via gpio */
88 if (privacy->gpio.pin_count == 1) {
89 privacy_gpio_acpigen(&privacy->gpio);
90 privacy->detect_function = ACPI_METHOD_EPS_PRESENT;
91 privacy->status_function = ACPI_METHOD_EPS_STATE;
92 privacy->enable_function = ACPI_METHOD_EPS_ENABLE;
93 privacy->disable_function = ACPI_METHOD_EPS_DISABLE;
94 }
95
96 acpigen_write_dsm(ACPI_DSM_PRIVACY_SCREEN_UUID,
97 privacy_screen_callbacks,
98 ARRAY_SIZE(privacy_screen_callbacks),
99 privacy);
100}
101
Furquan Shaikh7536a392020-04-24 21:59:21 -0700102static void gfx_fill_ssdt_generator(const struct device *dev)
Mathew Kingc135b822019-10-14 10:19:15 -0600103{
104 size_t i;
Furquan Shaikha0b0d422020-02-21 09:57:54 -0800105 struct drivers_gfx_generic_config *config = dev->chip_info;
Mathew Kingc135b822019-10-14 10:19:15 -0600106
107 const char *scope = acpi_device_scope(dev);
108
Karthikeyan Ramasubramaniand1c0f952020-11-02 16:26:52 -0700109 if (!scope)
Jacob Garber45192772020-02-01 13:04:11 -0700110 return;
111
Mathew Kingc135b822019-10-14 10:19:15 -0600112 acpigen_write_scope(scope);
113
114 /* Method (_DOD, 0) */
115 acpigen_write_method("_DOD", 0);
116 acpigen_emit_byte(RETURN_OP);
117 acpigen_write_package(config->device_count);
118 for (i = 0; i < config->device_count; i++)
119 acpigen_write_dword(config->device[i].addr);
120 acpigen_pop_len(); /* End Package. */
121 acpigen_pop_len(); /* End Method. */
122
123 for (i = 0; i < config->device_count; i++) {
124 acpigen_write_device(config->device[i].name);
Mathew Kingc135b822019-10-14 10:19:15 -0600125 acpigen_write_name_integer("_ADR", config->device[i].addr);
126 acpigen_write_name_integer("_STA", 0xF);
Rajat Jain7ef06b02020-02-26 23:28:02 -0800127 gfx_fill_privacy_screen_dsm(&config->device[i].privacy);
Mathew Kingc135b822019-10-14 10:19:15 -0600128 acpigen_pop_len(); /* Device */
129 }
130 acpigen_pop_len(); /* Scope */
131}
132
133static const char *gfx_acpi_name(const struct device *dev)
134{
Furquan Shaikha0b0d422020-02-21 09:57:54 -0800135 struct drivers_gfx_generic_config *config = dev->chip_info;
Mathew Kingc135b822019-10-14 10:19:15 -0600136
137 return config->name ? : "GFX0";
138}
139
140static struct device_operations gfx_ops = {
Nico Huber68680dd2020-03-31 17:34:52 +0200141 .acpi_name = gfx_acpi_name,
142 .acpi_fill_ssdt = gfx_fill_ssdt_generator,
Mathew Kingc135b822019-10-14 10:19:15 -0600143};
144
145static void gfx_enable(struct device *dev)
146{
Furquan Shaikha0b0d422020-02-21 09:57:54 -0800147 struct drivers_gfx_generic_config *config = dev->chip_info;
Mathew Kingc135b822019-10-14 10:19:15 -0600148
Rajat Jain7ef06b02020-02-26 23:28:02 -0800149 if (!config || !dev->enabled)
Mathew Kingc135b822019-10-14 10:19:15 -0600150 return;
151
152 dev->ops = &gfx_ops;
153}
154
Furquan Shaikha0b0d422020-02-21 09:57:54 -0800155struct chip_operations drivers_gfx_generic_ops = {
156 CHIP_NAME("Generic Graphics Device")
Mathew Kingc135b822019-10-14 10:19:15 -0600157 .enable_dev = gfx_enable
158};
Rajat Jain7ef06b02020-02-26 23:28:02 -0800159
160struct device *find_gfx_dev(void)
161{
162 struct device *dev;
163
164 for (dev = all_devices; dev; dev = dev->next) {
165 if (dev->chip_ops && dev->chip_ops == &drivers_gfx_generic_ops)
166 return dev;
167 }
168 return NULL;
169}