blob: 550cde57e12b89f59d4febdd725a209d8fb1a9a1 [file] [log] [blame]
Furquan Shaikhc82aabc2020-04-23 13:59:00 -07001/* SPDX-License-Identifier: GPL-2.0-or-later */
Furquan Shaikhc82aabc2020-04-23 13:59:00 -07002
Furquan Shaikh76cedd22020-05-02 10:24:23 -07003#include <acpi/acpi_device.h>
Aaron Durbin77a062e2020-08-20 10:15:06 -06004#include <acpi/acpigen.h>
Furquan Shaikhc82aabc2020-04-23 13:59:00 -07005#include <device/pci.h>
6#include <device/pci_ids.h>
Nikolai Vyssotski95675d92021-02-09 13:01:07 -06007#include <console/console.h>
8#include <fsp/graphics.h>
Nikolai Vyssotskiad68e692021-01-15 11:39:33 -06009#include <soc/intel/common/vbt.h>
Furquan Shaikhc82aabc2020-04-23 13:59:00 -070010
Aaron Durbin77a062e2020-08-20 10:15:06 -060011#define ATIF_FUNCTION_VERIFY_INTERFACE 0x0
12struct atif_verify_interface_output {
13 uint16_t size; /* Size of this object, including size field */
14 uint16_t version;
15 uint32_t supported_notifications;
16 uint32_t supported_functions; /* Bit n set if function n+1 supported. */
17};
18
19#define ATIF_FUNCTION_QUERY_BRIGHTNESS_TRANSFER_CHARACTERISTICS 0x10
20# define ATIF_QBTC_REQUEST_LCD1 0
21/* error codes */
22# define ATIF_QBTC_ERROR_CODE_SUCCESS 0
23# define ATIF_QBTC_ERROR_CODE_FAILURE 1
24# define ATIF_QBTC_ERROR_CODE_DEVICE_NOT_SUPPORTED 2
25struct atif_brightness_input {
26 uint16_t size;
27 /* ATIF doc indicates this field is a word, but the kernel drivers uses a byte. */
28 uint8_t requested_display;
29};
30struct atif_brightness_output {
31 uint16_t size; /* Size of this object, including size field. */
32 uint16_t flags; /* Currently all reserved. */
33 uint8_t error_code;
34 /* default brightness fields currently ignored by Linux driver. */
35 uint8_t default_brightness_ac; /* Percentage brightness when connected to AC. */
36 uint8_t default_brightness_dc; /* Percentage brightness when connected to DC. */
37 /* The following 2 fields are the only ones honored by Linux driver currently. */
38 uint8_t min_input_signal_level; /* 0-255 corresponding to 0% */
39 uint8_t max_input_signal_level; /* 0-255 corresponding to 100% */
40 /* Array of data points consisting of:
41 * { uint8_t luminance_level; (percent)
42 * uint8_t input_signal_level; (0-255 in value) }
43 * Linux ignores these fields so no support currently. */
44 uint8_t count_data_points; /* Count of data points. */
45};
46
47static void generate_atif(const struct device *dev)
48{
49 struct atif_verify_interface_output verify_output = {
50 .size = sizeof(verify_output),
51 .version = 1,
52 .supported_functions =
53 BIT(ATIF_FUNCTION_QUERY_BRIGHTNESS_TRANSFER_CHARACTERISTICS - 1),
54 };
55 struct atif_brightness_output brightness_error = {
56 .size = sizeof(brightness_error),
57 .error_code = ATIF_QBTC_ERROR_CODE_DEVICE_NOT_SUPPORTED,
58 };
59 struct atif_brightness_output brightness_out = {
60 .size = sizeof(brightness_out),
61 .error_code = ATIF_QBTC_ERROR_CODE_SUCCESS,
62 .min_input_signal_level = 0,
63 .max_input_signal_level = 255,
64 };
65
66 /* Scope (\_SB.PCI0.PBRA.IGFX) */
67 acpigen_write_scope(acpi_device_path(dev));
68 /* Method (ATIF, 2, NotSerialized) */
69 acpigen_write_method("ATIF", 2);
70 /* ToInteger (Arg0, Local0) */
71 acpigen_write_to_integer(ARG0_OP, LOCAL0_OP);
72
73 /* If ((Local0 == Zero)) */
74 acpigen_write_if_lequal_op_int(LOCAL0_OP, ATIF_FUNCTION_VERIFY_INTERFACE);
75 /* Return (Buffer (0x0C) { ... } */
76 acpigen_write_return_byte_buffer((uint8_t *)(void *)&verify_output,
77 sizeof(verify_output));
78 acpigen_pop_len(); /* if (LEqual(Local0, 0) */
79
80 /* ElseIf ((Local0 == 0x10)) */
81 acpigen_write_else();
82 acpigen_write_if_lequal_op_int(LOCAL0_OP,
83 ATIF_FUNCTION_QUERY_BRIGHTNESS_TRANSFER_CHARACTERISTICS);
84 /* CreateByteField (Arg1, 0x02, DISP) */
85 acpigen_write_create_byte_field(ARG1_OP,
86 offsetof(struct atif_brightness_input, requested_display), "DISP");
87 /* ToInteger (DISP, Local1) */
88 acpigen_write_to_integer_from_namestring("DISP", LOCAL1_OP);
89 /* If ((Local1 == Zero)) */
90 acpigen_write_if_lequal_op_int(LOCAL1_OP, ATIF_QBTC_REQUEST_LCD1);
91 /* Return (Buffer (0x0A) { ... } */
92 acpigen_write_return_byte_buffer((uint8_t *)(void *)&brightness_out,
93 sizeof(brightness_out));
94 acpigen_pop_len(); /* if (LEqual(Local2, ATIF_QBTC_REQUEST_LCD1) */
95 /* Else */
96 acpigen_write_else();
97 /* Return (Buffer (0x0A) */
98 acpigen_write_return_byte_buffer((uint8_t *)(void *)&brightness_error,
99 sizeof(brightness_error));
100 acpigen_pop_len(); /* else */
101
102 acpigen_pop_len(); /* if (LEqual(Local0, 0x10) */
103 acpigen_pop_len(); /* else */
104
105 acpigen_pop_len(); /* Method */
106 acpigen_pop_len(); /* Scope */
107}
108
Raul E Rangelda5e07e2020-04-29 15:55:33 -0600109static void graphics_fill_ssdt(const struct device *dev)
Furquan Shaikhf939df72020-04-23 14:13:02 -0700110{
111 acpi_device_write_pci_dev(dev);
112 pci_rom_ssdt(dev);
Aaron Durbin77a062e2020-08-20 10:15:06 -0600113 if (CONFIG(SOC_AMD_COMMON_BLOCK_GRAPHICS_ATIF))
114 generate_atif(dev);
Furquan Shaikhf939df72020-04-23 14:13:02 -0700115}
116
Furquan Shaikhc82aabc2020-04-23 13:59:00 -0700117static const char *graphics_acpi_name(const struct device *dev)
118{
119 return "IGFX";
120}
121
Nikolai Vyssotskiad68e692021-01-15 11:39:33 -0600122/*
123 * Even though AMD does not need VBT we still need to implement the
124 * vbt_get() function to not break the build with GOP driver enabled
125 * (see fsps_return_value_handler() in fsp2_0/silicon_init.c
126 */
127void *vbt_get(void)
128{
129 return NULL;
130}
131
Nikolai Vyssotski95675d92021-02-09 13:01:07 -0600132static void graphics_dev_init(struct device *const dev)
133{
134 if (CONFIG(RUN_FSP_GOP)) {
135 struct resource *res = probe_resource(dev, PCI_BASE_ADDRESS_0);
136
137 if (res && res->base)
138 fsp_report_framebuffer_info(res->base);
139 else
140 printk(BIOS_ERR, "%s: Unable to find resource for %s\n",
141 __func__, dev_path(dev));
142 }
143
144 /* Initialize PCI device, load/execute BIOS Option ROM */
145 pci_dev_init(dev);
146}
147
Furquan Shaikhc82aabc2020-04-23 13:59:00 -0700148static const struct device_operations graphics_ops = {
149 .read_resources = pci_dev_read_resources,
150 .set_resources = pci_dev_set_resources,
151 .enable_resources = pci_dev_enable_resources,
Nikolai Vyssotski95675d92021-02-09 13:01:07 -0600152 .init = graphics_dev_init,
Furquan Shaikhc82aabc2020-04-23 13:59:00 -0700153 .ops_pci = &pci_dev_ops_pci,
154 .write_acpi_tables = pci_rom_write_acpi_tables,
Furquan Shaikhf939df72020-04-23 14:13:02 -0700155 .acpi_fill_ssdt = graphics_fill_ssdt,
Furquan Shaikhc82aabc2020-04-23 13:59:00 -0700156 .acpi_name = graphics_acpi_name,
157};
158
159static const unsigned short pci_device_ids[] = {
Felix Held2b48a602020-11-18 13:01:00 +0100160 PCI_DEVICE_ID_ATI_FAM17H_MODEL18H_GPU,
Furquan Shaikhc82aabc2020-04-23 13:59:00 -0700161 0,
162};
163
164static const struct pci_driver graphics_driver __pci_driver = {
165 .ops = &graphics_ops,
166 .vendor = PCI_VENDOR_ID_ATI,
167 .devices = pci_device_ids,
168};