Angel Pons | 8a3453f | 2020-04-02 23:48:19 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Mathew King | c135b82 | 2019-10-14 10:19:15 -0600 | [diff] [blame] | 2 | |
Furquan Shaikh | 76cedd2 | 2020-05-02 10:24:23 -0700 | [diff] [blame] | 3 | #include <acpi/acpigen.h> |
Mathew King | c135b82 | 2019-10-14 10:19:15 -0600 | [diff] [blame] | 4 | #include <console/console.h> |
| 5 | #include <device/device.h> |
| 6 | #include <device/pci.h> |
| 7 | #include <device/pci_ids.h> |
Mathew King | c135b82 | 2019-10-14 10:19:15 -0600 | [diff] [blame] | 8 | |
| 9 | #include "chip.h" |
| 10 | |
| 11 | #define ACPI_DSM_PRIVACY_SCREEN_UUID "C7033113-8720-4CEB-9090-9D52B3E52D73" |
| 12 | |
Rajat Jain | 7ef06b0 | 2020-02-26 23:28:02 -0800 | [diff] [blame] | 13 | #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 King | c135b82 | 2019-10-14 10:19:15 -0600 | [diff] [blame] | 18 | static void privacy_screen_detect_cb(void *arg) |
| 19 | { |
Furquan Shaikh | a0b0d42 | 2020-02-21 09:57:54 -0800 | [diff] [blame] | 20 | struct drivers_gfx_generic_privacy_screen_config *config = arg; |
Mathew King | c135b82 | 2019-10-14 10:19:15 -0600 | [diff] [blame] | 21 | |
| 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 | } |
| 29 | static void privacy_screen_get_status_cb(void *arg) |
| 30 | { |
Furquan Shaikh | a0b0d42 | 2020-02-21 09:57:54 -0800 | [diff] [blame] | 31 | struct drivers_gfx_generic_privacy_screen_config *config = arg; |
Mathew King | c135b82 | 2019-10-14 10:19:15 -0600 | [diff] [blame] | 32 | |
| 33 | acpigen_emit_byte(RETURN_OP); |
| 34 | acpigen_emit_namestring(config->status_function); |
| 35 | } |
| 36 | static void privacy_screen_enable_cb(void *arg) |
| 37 | { |
Furquan Shaikh | a0b0d42 | 2020-02-21 09:57:54 -0800 | [diff] [blame] | 38 | struct drivers_gfx_generic_privacy_screen_config *config = arg; |
Mathew King | c135b82 | 2019-10-14 10:19:15 -0600 | [diff] [blame] | 39 | |
| 40 | acpigen_emit_namestring(config->enable_function); |
| 41 | } |
| 42 | static void privacy_screen_disable_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_namestring(config->disable_function); |
| 47 | } |
| 48 | |
| 49 | static 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 Jain | 7ef06b0 | 2020-02-26 23:28:02 -0800 | [diff] [blame] | 56 | static 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 | |
| 81 | static 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 Shaikh | 7536a39 | 2020-04-24 21:59:21 -0700 | [diff] [blame] | 102 | static void gfx_fill_ssdt_generator(const struct device *dev) |
Mathew King | c135b82 | 2019-10-14 10:19:15 -0600 | [diff] [blame] | 103 | { |
| 104 | size_t i; |
Furquan Shaikh | a0b0d42 | 2020-02-21 09:57:54 -0800 | [diff] [blame] | 105 | struct drivers_gfx_generic_config *config = dev->chip_info; |
Mathew King | c135b82 | 2019-10-14 10:19:15 -0600 | [diff] [blame] | 106 | |
| 107 | const char *scope = acpi_device_scope(dev); |
| 108 | |
Rajat Jain | 7ef06b0 | 2020-02-26 23:28:02 -0800 | [diff] [blame] | 109 | if (!scope || !dev->enabled) |
Jacob Garber | 4519277 | 2020-02-01 13:04:11 -0700 | [diff] [blame] | 110 | return; |
| 111 | |
Mathew King | c135b82 | 2019-10-14 10:19:15 -0600 | [diff] [blame] | 112 | 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 King | c135b82 | 2019-10-14 10:19:15 -0600 | [diff] [blame] | 125 | acpigen_write_name_integer("_ADR", config->device[i].addr); |
| 126 | acpigen_write_name_integer("_STA", 0xF); |
Rajat Jain | 7ef06b0 | 2020-02-26 23:28:02 -0800 | [diff] [blame] | 127 | gfx_fill_privacy_screen_dsm(&config->device[i].privacy); |
Mathew King | c135b82 | 2019-10-14 10:19:15 -0600 | [diff] [blame] | 128 | acpigen_pop_len(); /* Device */ |
| 129 | } |
| 130 | acpigen_pop_len(); /* Scope */ |
| 131 | } |
| 132 | |
| 133 | static const char *gfx_acpi_name(const struct device *dev) |
| 134 | { |
Furquan Shaikh | a0b0d42 | 2020-02-21 09:57:54 -0800 | [diff] [blame] | 135 | struct drivers_gfx_generic_config *config = dev->chip_info; |
Mathew King | c135b82 | 2019-10-14 10:19:15 -0600 | [diff] [blame] | 136 | |
| 137 | return config->name ? : "GFX0"; |
| 138 | } |
| 139 | |
| 140 | static struct device_operations gfx_ops = { |
Nico Huber | 68680dd | 2020-03-31 17:34:52 +0200 | [diff] [blame] | 141 | .acpi_name = gfx_acpi_name, |
| 142 | .acpi_fill_ssdt = gfx_fill_ssdt_generator, |
Mathew King | c135b82 | 2019-10-14 10:19:15 -0600 | [diff] [blame] | 143 | }; |
| 144 | |
| 145 | static void gfx_enable(struct device *dev) |
| 146 | { |
Furquan Shaikh | a0b0d42 | 2020-02-21 09:57:54 -0800 | [diff] [blame] | 147 | struct drivers_gfx_generic_config *config = dev->chip_info; |
Mathew King | c135b82 | 2019-10-14 10:19:15 -0600 | [diff] [blame] | 148 | |
Rajat Jain | 7ef06b0 | 2020-02-26 23:28:02 -0800 | [diff] [blame] | 149 | if (!config || !dev->enabled) |
Mathew King | c135b82 | 2019-10-14 10:19:15 -0600 | [diff] [blame] | 150 | return; |
| 151 | |
| 152 | dev->ops = &gfx_ops; |
| 153 | } |
| 154 | |
Furquan Shaikh | a0b0d42 | 2020-02-21 09:57:54 -0800 | [diff] [blame] | 155 | struct chip_operations drivers_gfx_generic_ops = { |
| 156 | CHIP_NAME("Generic Graphics Device") |
Mathew King | c135b82 | 2019-10-14 10:19:15 -0600 | [diff] [blame] | 157 | .enable_dev = gfx_enable |
| 158 | }; |
Rajat Jain | 7ef06b0 | 2020-02-26 23:28:02 -0800 | [diff] [blame] | 159 | |
| 160 | struct 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 | } |