blob: a20279f7afc7536536c27772486920456cc3d447 [file] [log] [blame]
Mathew Kingc135b822019-10-14 10:19:15 -06001/*
2 * This file is part of the coreboot project.
3 *
Mathew Kingc135b822019-10-14 10:19:15 -06004 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; version 2 of the License.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 */
14
15#include <arch/acpigen.h>
16#include <console/console.h>
17#include <device/device.h>
18#include <device/pci.h>
19#include <device/pci_ids.h>
20#include <stdint.h>
Mathew Kingc135b822019-10-14 10:19:15 -060021
22#include "chip.h"
23
24#define ACPI_DSM_PRIVACY_SCREEN_UUID "C7033113-8720-4CEB-9090-9D52B3E52D73"
25
Rajat Jain7ef06b02020-02-26 23:28:02 -080026#define ACPI_METHOD_EPS_PRESENT "EPSP"
27#define ACPI_METHOD_EPS_STATE "EPSS"
28#define ACPI_METHOD_EPS_ENABLE "EPSE"
29#define ACPI_METHOD_EPS_DISABLE "EPSD"
30
Mathew Kingc135b822019-10-14 10:19:15 -060031static void privacy_screen_detect_cb(void *arg)
32{
Furquan Shaikha0b0d422020-02-21 09:57:54 -080033 struct drivers_gfx_generic_privacy_screen_config *config = arg;
Mathew Kingc135b822019-10-14 10:19:15 -060034
35 acpigen_write_store();
36 acpigen_emit_namestring(config->detect_function);
37 acpigen_emit_byte(LOCAL2_OP);
38 acpigen_write_if_lequal_op_int(LOCAL2_OP, 1);
39 acpigen_write_return_singleton_buffer(0xF);
40 acpigen_pop_len();
41}
42static void privacy_screen_get_status_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_byte(RETURN_OP);
47 acpigen_emit_namestring(config->status_function);
48}
49static void privacy_screen_enable_cb(void *arg)
50{
Furquan Shaikha0b0d422020-02-21 09:57:54 -080051 struct drivers_gfx_generic_privacy_screen_config *config = arg;
Mathew Kingc135b822019-10-14 10:19:15 -060052
53 acpigen_emit_namestring(config->enable_function);
54}
55static void privacy_screen_disable_cb(void *arg)
56{
Furquan Shaikha0b0d422020-02-21 09:57:54 -080057 struct drivers_gfx_generic_privacy_screen_config *config = arg;
Mathew Kingc135b822019-10-14 10:19:15 -060058
59 acpigen_emit_namestring(config->disable_function);
60}
61
62static void (*privacy_screen_callbacks[])(void *) = {
63 privacy_screen_detect_cb,
64 privacy_screen_get_status_cb,
65 privacy_screen_enable_cb,
66 privacy_screen_disable_cb,
67};
68
Rajat Jain7ef06b02020-02-26 23:28:02 -080069static void privacy_gpio_acpigen(struct acpi_gpio *gpio)
70{
71 /* EPS Present */
72 acpigen_write_method(ACPI_METHOD_EPS_PRESENT, 0);
73 acpigen_write_return_byte(1);
74 acpigen_pop_len();
75
76 /* EPS State */
77 acpigen_write_method(ACPI_METHOD_EPS_STATE, 0);
78 acpigen_get_rx_gpio(gpio);
79 acpigen_emit_byte(RETURN_OP);
80 acpigen_emit_byte(LOCAL0_OP);
81 acpigen_pop_len();
82
83 /* EPS Enable */
84 acpigen_write_method(ACPI_METHOD_EPS_ENABLE, 0);
85 acpigen_enable_tx_gpio(gpio);
86 acpigen_pop_len();
87
88 /* EPS Disable */
89 acpigen_write_method(ACPI_METHOD_EPS_DISABLE, 0);
90 acpigen_disable_tx_gpio(gpio);
91 acpigen_pop_len();
92}
93
94static void gfx_fill_privacy_screen_dsm(
95 struct drivers_gfx_generic_privacy_screen_config *privacy)
96{
97 if (!privacy->enabled)
98 return;
99
100 /* Populate ACPI methods, if EPS controlled via gpio */
101 if (privacy->gpio.pin_count == 1) {
102 privacy_gpio_acpigen(&privacy->gpio);
103 privacy->detect_function = ACPI_METHOD_EPS_PRESENT;
104 privacy->status_function = ACPI_METHOD_EPS_STATE;
105 privacy->enable_function = ACPI_METHOD_EPS_ENABLE;
106 privacy->disable_function = ACPI_METHOD_EPS_DISABLE;
107 }
108
109 acpigen_write_dsm(ACPI_DSM_PRIVACY_SCREEN_UUID,
110 privacy_screen_callbacks,
111 ARRAY_SIZE(privacy_screen_callbacks),
112 privacy);
113}
114
Mathew Kingc135b822019-10-14 10:19:15 -0600115static void gfx_fill_ssdt_generator(struct device *dev)
116{
117 size_t i;
Furquan Shaikha0b0d422020-02-21 09:57:54 -0800118 struct drivers_gfx_generic_config *config = dev->chip_info;
Mathew Kingc135b822019-10-14 10:19:15 -0600119
120 const char *scope = acpi_device_scope(dev);
121
Rajat Jain7ef06b02020-02-26 23:28:02 -0800122 if (!scope || !dev->enabled)
Jacob Garber45192772020-02-01 13:04:11 -0700123 return;
124
Mathew Kingc135b822019-10-14 10:19:15 -0600125 acpigen_write_scope(scope);
126
127 /* Method (_DOD, 0) */
128 acpigen_write_method("_DOD", 0);
129 acpigen_emit_byte(RETURN_OP);
130 acpigen_write_package(config->device_count);
131 for (i = 0; i < config->device_count; i++)
132 acpigen_write_dword(config->device[i].addr);
133 acpigen_pop_len(); /* End Package. */
134 acpigen_pop_len(); /* End Method. */
135
136 for (i = 0; i < config->device_count; i++) {
137 acpigen_write_device(config->device[i].name);
Mathew Kingc135b822019-10-14 10:19:15 -0600138 acpigen_write_name_integer("_ADR", config->device[i].addr);
139 acpigen_write_name_integer("_STA", 0xF);
Rajat Jain7ef06b02020-02-26 23:28:02 -0800140 gfx_fill_privacy_screen_dsm(&config->device[i].privacy);
Mathew Kingc135b822019-10-14 10:19:15 -0600141 acpigen_pop_len(); /* Device */
142 }
143 acpigen_pop_len(); /* Scope */
144}
145
146static const char *gfx_acpi_name(const struct device *dev)
147{
Furquan Shaikha0b0d422020-02-21 09:57:54 -0800148 struct drivers_gfx_generic_config *config = dev->chip_info;
Mathew Kingc135b822019-10-14 10:19:15 -0600149
150 return config->name ? : "GFX0";
151}
152
153static struct device_operations gfx_ops = {
Nico Huber68680dd2020-03-31 17:34:52 +0200154 .acpi_name = gfx_acpi_name,
155 .acpi_fill_ssdt = gfx_fill_ssdt_generator,
Mathew Kingc135b822019-10-14 10:19:15 -0600156};
157
158static void gfx_enable(struct device *dev)
159{
Furquan Shaikha0b0d422020-02-21 09:57:54 -0800160 struct drivers_gfx_generic_config *config = dev->chip_info;
Mathew Kingc135b822019-10-14 10:19:15 -0600161
Rajat Jain7ef06b02020-02-26 23:28:02 -0800162 if (!config || !dev->enabled)
Mathew Kingc135b822019-10-14 10:19:15 -0600163 return;
164
165 dev->ops = &gfx_ops;
166}
167
Furquan Shaikha0b0d422020-02-21 09:57:54 -0800168struct chip_operations drivers_gfx_generic_ops = {
169 CHIP_NAME("Generic Graphics Device")
Mathew Kingc135b822019-10-14 10:19:15 -0600170 .enable_dev = gfx_enable
171};
Rajat Jain7ef06b02020-02-26 23:28:02 -0800172
173struct device *find_gfx_dev(void)
174{
175 struct device *dev;
176
177 for (dev = all_devices; dev; dev = dev->next) {
178 if (dev->chip_ops && dev->chip_ops == &drivers_gfx_generic_ops)
179 return dev;
180 }
181 return NULL;
182}