blob: e3ae62f588d097b7039d2e0d608b043759f018b6 [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 <device/device.h>
5#include <device/pci.h>
6#include <device/pci_ids.h>
Mathew Kingc135b822019-10-14 10:19:15 -06007
8#include "chip.h"
9
10#define ACPI_DSM_PRIVACY_SCREEN_UUID "C7033113-8720-4CEB-9090-9D52B3E52D73"
11
Rajat Jain7ef06b02020-02-26 23:28:02 -080012#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"
16
Mathew Kingc135b822019-10-14 10:19:15 -060017static void privacy_screen_detect_cb(void *arg)
18{
Furquan Shaikha0b0d422020-02-21 09:57:54 -080019 struct drivers_gfx_generic_privacy_screen_config *config = arg;
Mathew Kingc135b822019-10-14 10:19:15 -060020
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);
26 acpigen_pop_len();
27}
28static void privacy_screen_get_status_cb(void *arg)
29{
Furquan Shaikha0b0d422020-02-21 09:57:54 -080030 struct drivers_gfx_generic_privacy_screen_config *config = arg;
Mathew Kingc135b822019-10-14 10:19:15 -060031
32 acpigen_emit_byte(RETURN_OP);
33 acpigen_emit_namestring(config->status_function);
34}
35static void privacy_screen_enable_cb(void *arg)
36{
Furquan Shaikha0b0d422020-02-21 09:57:54 -080037 struct drivers_gfx_generic_privacy_screen_config *config = arg;
Mathew Kingc135b822019-10-14 10:19:15 -060038
39 acpigen_emit_namestring(config->enable_function);
40}
41static void privacy_screen_disable_cb(void *arg)
42{
Furquan Shaikha0b0d422020-02-21 09:57:54 -080043 struct drivers_gfx_generic_privacy_screen_config *config = arg;
Mathew Kingc135b822019-10-14 10:19:15 -060044
45 acpigen_emit_namestring(config->disable_function);
46}
47
48static 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,
53};
54
Rajat Jain7ef06b02020-02-26 23:28:02 -080055static void privacy_gpio_acpigen(struct acpi_gpio *gpio)
56{
57 /* EPS Present */
58 acpigen_write_method(ACPI_METHOD_EPS_PRESENT, 0);
59 acpigen_write_return_byte(1);
60 acpigen_pop_len();
61
62 /* EPS State */
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);
67 acpigen_pop_len();
68
69 /* EPS Enable */
70 acpigen_write_method(ACPI_METHOD_EPS_ENABLE, 0);
71 acpigen_enable_tx_gpio(gpio);
72 acpigen_pop_len();
73
74 /* EPS Disable */
75 acpigen_write_method(ACPI_METHOD_EPS_DISABLE, 0);
76 acpigen_disable_tx_gpio(gpio);
77 acpigen_pop_len();
78}
79
80static void gfx_fill_privacy_screen_dsm(
81 struct drivers_gfx_generic_privacy_screen_config *privacy)
82{
83 if (!privacy->enabled)
84 return;
85
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;
93 }
94
95 acpigen_write_dsm(ACPI_DSM_PRIVACY_SCREEN_UUID,
96 privacy_screen_callbacks,
97 ARRAY_SIZE(privacy_screen_callbacks),
98 privacy);
99}
100
Furquan Shaikh7536a392020-04-24 21:59:21 -0700101static void gfx_fill_ssdt_generator(const struct device *dev)
Mathew Kingc135b822019-10-14 10:19:15 -0600102{
103 size_t i;
Furquan Shaikha0b0d422020-02-21 09:57:54 -0800104 struct drivers_gfx_generic_config *config = dev->chip_info;
Mathew Kingc135b822019-10-14 10:19:15 -0600105
106 const char *scope = acpi_device_scope(dev);
107
Karthikeyan Ramasubramaniand1c0f952020-11-02 16:26:52 -0700108 if (!scope)
Jacob Garber45192772020-02-01 13:04:11 -0700109 return;
110
Mathew Kingc135b822019-10-14 10:19:15 -0600111 acpigen_write_scope(scope);
112
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. */
121
122 for (i = 0; i < config->device_count; i++) {
123 acpigen_write_device(config->device[i].name);
Tim Wawrzynczak67c778d2021-11-29 13:17:31 -0700124 if (config->device[i].hid)
125 acpigen_write_name_string("_HID", config->device[i].hid);
126 else
127 acpigen_write_name_integer("_ADR", config->device[i].addr);
128
Mathew Kingc135b822019-10-14 10:19:15 -0600129 acpigen_write_name_integer("_STA", 0xF);
Rajat Jain7ef06b02020-02-26 23:28:02 -0800130 gfx_fill_privacy_screen_dsm(&config->device[i].privacy);
Won Chung467c88b2023-04-10 20:35:58 +0000131
132 if (config->device[i].use_pld)
133 acpigen_write_pld(&config->device[i].pld);
134
Mathew Kingc135b822019-10-14 10:19:15 -0600135 acpigen_pop_len(); /* Device */
136 }
137 acpigen_pop_len(); /* Scope */
138}
139
140static const char *gfx_acpi_name(const struct device *dev)
141{
Furquan Shaikha0b0d422020-02-21 09:57:54 -0800142 struct drivers_gfx_generic_config *config = dev->chip_info;
Mathew Kingc135b822019-10-14 10:19:15 -0600143
144 return config->name ? : "GFX0";
145}
146
147static struct device_operations gfx_ops = {
Nico Huber68680dd2020-03-31 17:34:52 +0200148 .acpi_name = gfx_acpi_name,
149 .acpi_fill_ssdt = gfx_fill_ssdt_generator,
Mathew Kingc135b822019-10-14 10:19:15 -0600150};
151
152static void gfx_enable(struct device *dev)
153{
Furquan Shaikha0b0d422020-02-21 09:57:54 -0800154 struct drivers_gfx_generic_config *config = dev->chip_info;
Mathew Kingc135b822019-10-14 10:19:15 -0600155
Rajat Jain7ef06b02020-02-26 23:28:02 -0800156 if (!config || !dev->enabled)
Mathew Kingc135b822019-10-14 10:19:15 -0600157 return;
158
159 dev->ops = &gfx_ops;
160}
161
Furquan Shaikha0b0d422020-02-21 09:57:54 -0800162struct chip_operations drivers_gfx_generic_ops = {
Nicholas Sudsgaardbfb11be2024-01-30 09:53:46 +0900163 .name = "Generic Graphics Device",
Mathew Kingc135b822019-10-14 10:19:15 -0600164 .enable_dev = gfx_enable
165};