Mathew King | c135b82 | 2019-10-14 10:19:15 -0600 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
Mathew King | c135b82 | 2019-10-14 10:19:15 -0600 | [diff] [blame] | 4 | * |
| 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 King | c135b82 | 2019-10-14 10:19:15 -0600 | [diff] [blame] | 21 | |
| 22 | #include "chip.h" |
| 23 | |
| 24 | #define ACPI_DSM_PRIVACY_SCREEN_UUID "C7033113-8720-4CEB-9090-9D52B3E52D73" |
| 25 | |
Rajat Jain | 7ef06b0 | 2020-02-26 23:28:02 -0800 | [diff] [blame] | 26 | #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 King | c135b82 | 2019-10-14 10:19:15 -0600 | [diff] [blame] | 31 | static void privacy_screen_detect_cb(void *arg) |
| 32 | { |
Furquan Shaikh | a0b0d42 | 2020-02-21 09:57:54 -0800 | [diff] [blame] | 33 | struct drivers_gfx_generic_privacy_screen_config *config = arg; |
Mathew King | c135b82 | 2019-10-14 10:19:15 -0600 | [diff] [blame] | 34 | |
| 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 | } |
| 42 | static void privacy_screen_get_status_cb(void *arg) |
| 43 | { |
Furquan Shaikh | a0b0d42 | 2020-02-21 09:57:54 -0800 | [diff] [blame] | 44 | struct drivers_gfx_generic_privacy_screen_config *config = arg; |
Mathew King | c135b82 | 2019-10-14 10:19:15 -0600 | [diff] [blame] | 45 | |
| 46 | acpigen_emit_byte(RETURN_OP); |
| 47 | acpigen_emit_namestring(config->status_function); |
| 48 | } |
| 49 | static void privacy_screen_enable_cb(void *arg) |
| 50 | { |
Furquan Shaikh | a0b0d42 | 2020-02-21 09:57:54 -0800 | [diff] [blame] | 51 | struct drivers_gfx_generic_privacy_screen_config *config = arg; |
Mathew King | c135b82 | 2019-10-14 10:19:15 -0600 | [diff] [blame] | 52 | |
| 53 | acpigen_emit_namestring(config->enable_function); |
| 54 | } |
| 55 | static void privacy_screen_disable_cb(void *arg) |
| 56 | { |
Furquan Shaikh | a0b0d42 | 2020-02-21 09:57:54 -0800 | [diff] [blame] | 57 | struct drivers_gfx_generic_privacy_screen_config *config = arg; |
Mathew King | c135b82 | 2019-10-14 10:19:15 -0600 | [diff] [blame] | 58 | |
| 59 | acpigen_emit_namestring(config->disable_function); |
| 60 | } |
| 61 | |
| 62 | static 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 Jain | 7ef06b0 | 2020-02-26 23:28:02 -0800 | [diff] [blame] | 69 | static 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 | |
| 94 | static 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 King | c135b82 | 2019-10-14 10:19:15 -0600 | [diff] [blame] | 115 | static void gfx_fill_ssdt_generator(struct device *dev) |
| 116 | { |
| 117 | size_t i; |
Furquan Shaikh | a0b0d42 | 2020-02-21 09:57:54 -0800 | [diff] [blame] | 118 | struct drivers_gfx_generic_config *config = dev->chip_info; |
Mathew King | c135b82 | 2019-10-14 10:19:15 -0600 | [diff] [blame] | 119 | |
| 120 | const char *scope = acpi_device_scope(dev); |
| 121 | |
Rajat Jain | 7ef06b0 | 2020-02-26 23:28:02 -0800 | [diff] [blame] | 122 | if (!scope || !dev->enabled) |
Jacob Garber | 4519277 | 2020-02-01 13:04:11 -0700 | [diff] [blame] | 123 | return; |
| 124 | |
Mathew King | c135b82 | 2019-10-14 10:19:15 -0600 | [diff] [blame] | 125 | 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 King | c135b82 | 2019-10-14 10:19:15 -0600 | [diff] [blame] | 138 | acpigen_write_name_integer("_ADR", config->device[i].addr); |
| 139 | acpigen_write_name_integer("_STA", 0xF); |
Rajat Jain | 7ef06b0 | 2020-02-26 23:28:02 -0800 | [diff] [blame] | 140 | gfx_fill_privacy_screen_dsm(&config->device[i].privacy); |
Mathew King | c135b82 | 2019-10-14 10:19:15 -0600 | [diff] [blame] | 141 | acpigen_pop_len(); /* Device */ |
| 142 | } |
| 143 | acpigen_pop_len(); /* Scope */ |
| 144 | } |
| 145 | |
| 146 | static const char *gfx_acpi_name(const struct device *dev) |
| 147 | { |
Furquan Shaikh | a0b0d42 | 2020-02-21 09:57:54 -0800 | [diff] [blame] | 148 | struct drivers_gfx_generic_config *config = dev->chip_info; |
Mathew King | c135b82 | 2019-10-14 10:19:15 -0600 | [diff] [blame] | 149 | |
| 150 | return config->name ? : "GFX0"; |
| 151 | } |
| 152 | |
| 153 | static struct device_operations gfx_ops = { |
Nico Huber | 68680dd | 2020-03-31 17:34:52 +0200 | [diff] [blame^] | 154 | .acpi_name = gfx_acpi_name, |
| 155 | .acpi_fill_ssdt = gfx_fill_ssdt_generator, |
Mathew King | c135b82 | 2019-10-14 10:19:15 -0600 | [diff] [blame] | 156 | }; |
| 157 | |
| 158 | static void gfx_enable(struct device *dev) |
| 159 | { |
Furquan Shaikh | a0b0d42 | 2020-02-21 09:57:54 -0800 | [diff] [blame] | 160 | struct drivers_gfx_generic_config *config = dev->chip_info; |
Mathew King | c135b82 | 2019-10-14 10:19:15 -0600 | [diff] [blame] | 161 | |
Rajat Jain | 7ef06b0 | 2020-02-26 23:28:02 -0800 | [diff] [blame] | 162 | if (!config || !dev->enabled) |
Mathew King | c135b82 | 2019-10-14 10:19:15 -0600 | [diff] [blame] | 163 | return; |
| 164 | |
| 165 | dev->ops = &gfx_ops; |
| 166 | } |
| 167 | |
Furquan Shaikh | a0b0d42 | 2020-02-21 09:57:54 -0800 | [diff] [blame] | 168 | struct chip_operations drivers_gfx_generic_ops = { |
| 169 | CHIP_NAME("Generic Graphics Device") |
Mathew King | c135b82 | 2019-10-14 10:19:15 -0600 | [diff] [blame] | 170 | .enable_dev = gfx_enable |
| 171 | }; |
Rajat Jain | 7ef06b0 | 2020-02-26 23:28:02 -0800 | [diff] [blame] | 172 | |
| 173 | struct 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 | } |