Furquan Shaikh | c82aabc | 2020-04-23 13:59:00 -0700 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-or-later */ |
Furquan Shaikh | c82aabc | 2020-04-23 13:59:00 -0700 | [diff] [blame] | 2 | |
Furquan Shaikh | 76cedd2 | 2020-05-02 10:24:23 -0700 | [diff] [blame] | 3 | #include <acpi/acpi_device.h> |
Aaron Durbin | 77a062e | 2020-08-20 10:15:06 -0600 | [diff] [blame] | 4 | #include <acpi/acpigen.h> |
Furquan Shaikh | c82aabc | 2020-04-23 13:59:00 -0700 | [diff] [blame] | 5 | #include <device/pci.h> |
| 6 | #include <device/pci_ids.h> |
Nikolai Vyssotski | 95675d9 | 2021-02-09 13:01:07 -0600 | [diff] [blame] | 7 | #include <console/console.h> |
| 8 | #include <fsp/graphics.h> |
Furquan Shaikh | c82aabc | 2020-04-23 13:59:00 -0700 | [diff] [blame] | 9 | |
Aaron Durbin | 77a062e | 2020-08-20 10:15:06 -0600 | [diff] [blame] | 10 | #define ATIF_FUNCTION_VERIFY_INTERFACE 0x0 |
| 11 | struct atif_verify_interface_output { |
| 12 | uint16_t size; /* Size of this object, including size field */ |
| 13 | uint16_t version; |
| 14 | uint32_t supported_notifications; |
| 15 | uint32_t supported_functions; /* Bit n set if function n+1 supported. */ |
| 16 | }; |
| 17 | |
| 18 | #define ATIF_FUNCTION_QUERY_BRIGHTNESS_TRANSFER_CHARACTERISTICS 0x10 |
| 19 | # define ATIF_QBTC_REQUEST_LCD1 0 |
| 20 | /* error codes */ |
| 21 | # define ATIF_QBTC_ERROR_CODE_SUCCESS 0 |
| 22 | # define ATIF_QBTC_ERROR_CODE_FAILURE 1 |
| 23 | # define ATIF_QBTC_ERROR_CODE_DEVICE_NOT_SUPPORTED 2 |
| 24 | struct atif_brightness_input { |
| 25 | uint16_t size; |
| 26 | /* ATIF doc indicates this field is a word, but the kernel drivers uses a byte. */ |
| 27 | uint8_t requested_display; |
| 28 | }; |
| 29 | struct atif_brightness_output { |
| 30 | uint16_t size; /* Size of this object, including size field. */ |
| 31 | uint16_t flags; /* Currently all reserved. */ |
| 32 | uint8_t error_code; |
| 33 | /* default brightness fields currently ignored by Linux driver. */ |
| 34 | uint8_t default_brightness_ac; /* Percentage brightness when connected to AC. */ |
| 35 | uint8_t default_brightness_dc; /* Percentage brightness when connected to DC. */ |
| 36 | /* The following 2 fields are the only ones honored by Linux driver currently. */ |
| 37 | uint8_t min_input_signal_level; /* 0-255 corresponding to 0% */ |
| 38 | uint8_t max_input_signal_level; /* 0-255 corresponding to 100% */ |
| 39 | /* Array of data points consisting of: |
| 40 | * { uint8_t luminance_level; (percent) |
| 41 | * uint8_t input_signal_level; (0-255 in value) } |
| 42 | * Linux ignores these fields so no support currently. */ |
| 43 | uint8_t count_data_points; /* Count of data points. */ |
| 44 | }; |
| 45 | |
| 46 | static void generate_atif(const struct device *dev) |
| 47 | { |
| 48 | struct atif_verify_interface_output verify_output = { |
| 49 | .size = sizeof(verify_output), |
| 50 | .version = 1, |
| 51 | .supported_functions = |
| 52 | BIT(ATIF_FUNCTION_QUERY_BRIGHTNESS_TRANSFER_CHARACTERISTICS - 1), |
| 53 | }; |
| 54 | struct atif_brightness_output brightness_error = { |
| 55 | .size = sizeof(brightness_error), |
| 56 | .error_code = ATIF_QBTC_ERROR_CODE_DEVICE_NOT_SUPPORTED, |
| 57 | }; |
| 58 | struct atif_brightness_output brightness_out = { |
| 59 | .size = sizeof(brightness_out), |
| 60 | .error_code = ATIF_QBTC_ERROR_CODE_SUCCESS, |
| 61 | .min_input_signal_level = 0, |
| 62 | .max_input_signal_level = 255, |
| 63 | }; |
| 64 | |
| 65 | /* Scope (\_SB.PCI0.PBRA.IGFX) */ |
| 66 | acpigen_write_scope(acpi_device_path(dev)); |
| 67 | /* Method (ATIF, 2, NotSerialized) */ |
| 68 | acpigen_write_method("ATIF", 2); |
| 69 | /* ToInteger (Arg0, Local0) */ |
| 70 | acpigen_write_to_integer(ARG0_OP, LOCAL0_OP); |
| 71 | |
| 72 | /* If ((Local0 == Zero)) */ |
| 73 | acpigen_write_if_lequal_op_int(LOCAL0_OP, ATIF_FUNCTION_VERIFY_INTERFACE); |
| 74 | /* Return (Buffer (0x0C) { ... } */ |
| 75 | acpigen_write_return_byte_buffer((uint8_t *)(void *)&verify_output, |
| 76 | sizeof(verify_output)); |
| 77 | acpigen_pop_len(); /* if (LEqual(Local0, 0) */ |
| 78 | |
| 79 | /* ElseIf ((Local0 == 0x10)) */ |
| 80 | acpigen_write_else(); |
| 81 | acpigen_write_if_lequal_op_int(LOCAL0_OP, |
| 82 | ATIF_FUNCTION_QUERY_BRIGHTNESS_TRANSFER_CHARACTERISTICS); |
| 83 | /* CreateByteField (Arg1, 0x02, DISP) */ |
| 84 | acpigen_write_create_byte_field(ARG1_OP, |
| 85 | offsetof(struct atif_brightness_input, requested_display), "DISP"); |
| 86 | /* ToInteger (DISP, Local1) */ |
| 87 | acpigen_write_to_integer_from_namestring("DISP", LOCAL1_OP); |
| 88 | /* If ((Local1 == Zero)) */ |
| 89 | acpigen_write_if_lequal_op_int(LOCAL1_OP, ATIF_QBTC_REQUEST_LCD1); |
| 90 | /* Return (Buffer (0x0A) { ... } */ |
| 91 | acpigen_write_return_byte_buffer((uint8_t *)(void *)&brightness_out, |
| 92 | sizeof(brightness_out)); |
| 93 | acpigen_pop_len(); /* if (LEqual(Local2, ATIF_QBTC_REQUEST_LCD1) */ |
| 94 | /* Else */ |
| 95 | acpigen_write_else(); |
| 96 | /* Return (Buffer (0x0A) */ |
| 97 | acpigen_write_return_byte_buffer((uint8_t *)(void *)&brightness_error, |
| 98 | sizeof(brightness_error)); |
| 99 | acpigen_pop_len(); /* else */ |
| 100 | |
| 101 | acpigen_pop_len(); /* if (LEqual(Local0, 0x10) */ |
| 102 | acpigen_pop_len(); /* else */ |
| 103 | |
| 104 | acpigen_pop_len(); /* Method */ |
| 105 | acpigen_pop_len(); /* Scope */ |
| 106 | } |
| 107 | |
Raul E Rangel | da5e07e | 2020-04-29 15:55:33 -0600 | [diff] [blame] | 108 | static void graphics_fill_ssdt(const struct device *dev) |
Furquan Shaikh | f939df7 | 2020-04-23 14:13:02 -0700 | [diff] [blame] | 109 | { |
| 110 | acpi_device_write_pci_dev(dev); |
| 111 | pci_rom_ssdt(dev); |
Aaron Durbin | 77a062e | 2020-08-20 10:15:06 -0600 | [diff] [blame] | 112 | if (CONFIG(SOC_AMD_COMMON_BLOCK_GRAPHICS_ATIF)) |
| 113 | generate_atif(dev); |
Furquan Shaikh | f939df7 | 2020-04-23 14:13:02 -0700 | [diff] [blame] | 114 | } |
| 115 | |
Furquan Shaikh | c82aabc | 2020-04-23 13:59:00 -0700 | [diff] [blame] | 116 | static const char *graphics_acpi_name(const struct device *dev) |
| 117 | { |
| 118 | return "IGFX"; |
| 119 | } |
| 120 | |
Nikolai Vyssotski | 95675d9 | 2021-02-09 13:01:07 -0600 | [diff] [blame] | 121 | static void graphics_dev_init(struct device *const dev) |
| 122 | { |
| 123 | if (CONFIG(RUN_FSP_GOP)) { |
| 124 | struct resource *res = probe_resource(dev, PCI_BASE_ADDRESS_0); |
| 125 | |
| 126 | if (res && res->base) |
| 127 | fsp_report_framebuffer_info(res->base); |
| 128 | else |
| 129 | printk(BIOS_ERR, "%s: Unable to find resource for %s\n", |
| 130 | __func__, dev_path(dev)); |
| 131 | } |
| 132 | |
| 133 | /* Initialize PCI device, load/execute BIOS Option ROM */ |
| 134 | pci_dev_init(dev); |
| 135 | } |
| 136 | |
Furquan Shaikh | c82aabc | 2020-04-23 13:59:00 -0700 | [diff] [blame] | 137 | static const struct device_operations graphics_ops = { |
| 138 | .read_resources = pci_dev_read_resources, |
| 139 | .set_resources = pci_dev_set_resources, |
| 140 | .enable_resources = pci_dev_enable_resources, |
Nikolai Vyssotski | 95675d9 | 2021-02-09 13:01:07 -0600 | [diff] [blame] | 141 | .init = graphics_dev_init, |
Furquan Shaikh | c82aabc | 2020-04-23 13:59:00 -0700 | [diff] [blame] | 142 | .ops_pci = &pci_dev_ops_pci, |
| 143 | .write_acpi_tables = pci_rom_write_acpi_tables, |
Furquan Shaikh | f939df7 | 2020-04-23 14:13:02 -0700 | [diff] [blame] | 144 | .acpi_fill_ssdt = graphics_fill_ssdt, |
Furquan Shaikh | c82aabc | 2020-04-23 13:59:00 -0700 | [diff] [blame] | 145 | .acpi_name = graphics_acpi_name, |
| 146 | }; |
| 147 | |
| 148 | static const unsigned short pci_device_ids[] = { |
Felix Held | 2b48a60 | 2020-11-18 13:01:00 +0100 | [diff] [blame] | 149 | PCI_DEVICE_ID_ATI_FAM17H_MODEL18H_GPU, |
Furquan Shaikh | c82aabc | 2020-04-23 13:59:00 -0700 | [diff] [blame] | 150 | 0, |
| 151 | }; |
| 152 | |
| 153 | static const struct pci_driver graphics_driver __pci_driver = { |
| 154 | .ops = &graphics_ops, |
| 155 | .vendor = PCI_VENDOR_ID_ATI, |
| 156 | .devices = pci_device_ids, |
| 157 | }; |