2 * Copyright 2012 Advanced Micro Devices, Inc.
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20 * OTHER DEALINGS IN THE SOFTWARE.
24 #include <linux/pci.h>
25 #include <linux/acpi.h>
26 #include <linux/slab.h>
27 #include <linux/power_supply.h>
28 #include <linux/pm_runtime.h>
29 #include <acpi/video.h>
30 #include <acpi/actbl.h>
32 #include <drm/drm_crtc_helper.h>
34 #include "amdgpu_pm.h"
35 #include "amdgpu_display.h"
39 struct amdgpu_atif_notification_cfg {
44 struct amdgpu_atif_notifications {
46 bool forced_power_state;
47 bool system_power_state;
48 bool brightness_change;
49 bool dgpu_display_event;
50 bool gpu_package_power_limit;
53 struct amdgpu_atif_functions {
56 bool temperature_change;
57 bool query_backlight_transfer_characteristics;
59 bool external_gpu_information;
65 struct amdgpu_atif_notifications notifications;
66 struct amdgpu_atif_functions functions;
67 struct amdgpu_atif_notification_cfg notification_cfg;
68 #if defined(CONFIG_BACKLIGHT_CLASS_DEVICE) || defined(CONFIG_BACKLIGHT_CLASS_DEVICE_MODULE)
69 struct backlight_device *bd;
71 struct amdgpu_dm_backlight_caps backlight_caps;
74 struct amdgpu_atcs_functions {
84 struct amdgpu_atcs_functions functions;
87 /* Call the ATIF method
90 * amdgpu_atif_call - call an ATIF method
92 * @atif: atif structure
93 * @function: the ATIF function to execute
94 * @params: ATIF function params
96 * Executes the requested ATIF function (all asics).
97 * Returns a pointer to the acpi output buffer.
99 static union acpi_object *amdgpu_atif_call(struct amdgpu_atif *atif,
101 struct acpi_buffer *params)
104 union acpi_object atif_arg_elements[2];
105 struct acpi_object_list atif_arg;
106 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
109 atif_arg.pointer = &atif_arg_elements[0];
111 atif_arg_elements[0].type = ACPI_TYPE_INTEGER;
112 atif_arg_elements[0].integer.value = function;
115 atif_arg_elements[1].type = ACPI_TYPE_BUFFER;
116 atif_arg_elements[1].buffer.length = params->length;
117 atif_arg_elements[1].buffer.pointer = params->pointer;
119 /* We need a second fake parameter */
120 atif_arg_elements[1].type = ACPI_TYPE_INTEGER;
121 atif_arg_elements[1].integer.value = 0;
124 status = acpi_evaluate_object(atif->handle, NULL, &atif_arg,
127 /* Fail only if calling the method fails and ATIF is supported */
128 if (ACPI_FAILURE(status) && status != AE_NOT_FOUND) {
129 DRM_DEBUG_DRIVER("failed to evaluate ATIF got %s\n",
130 acpi_format_exception(status));
131 kfree(buffer.pointer);
135 return buffer.pointer;
139 * amdgpu_atif_parse_notification - parse supported notifications
141 * @n: supported notifications struct
142 * @mask: supported notifications mask from ATIF
144 * Use the supported notifications mask from ATIF function
145 * ATIF_FUNCTION_VERIFY_INTERFACE to determine what notifications
146 * are supported (all asics).
148 static void amdgpu_atif_parse_notification(struct amdgpu_atif_notifications *n, u32 mask)
150 n->thermal_state = mask & ATIF_THERMAL_STATE_CHANGE_REQUEST_SUPPORTED;
151 n->forced_power_state = mask & ATIF_FORCED_POWER_STATE_CHANGE_REQUEST_SUPPORTED;
152 n->system_power_state = mask & ATIF_SYSTEM_POWER_SOURCE_CHANGE_REQUEST_SUPPORTED;
153 n->brightness_change = mask & ATIF_PANEL_BRIGHTNESS_CHANGE_REQUEST_SUPPORTED;
154 n->dgpu_display_event = mask & ATIF_DGPU_DISPLAY_EVENT_SUPPORTED;
155 n->gpu_package_power_limit = mask & ATIF_GPU_PACKAGE_POWER_LIMIT_REQUEST_SUPPORTED;
159 * amdgpu_atif_parse_functions - parse supported functions
161 * @f: supported functions struct
162 * @mask: supported functions mask from ATIF
164 * Use the supported functions mask from ATIF function
165 * ATIF_FUNCTION_VERIFY_INTERFACE to determine what functions
166 * are supported (all asics).
168 static void amdgpu_atif_parse_functions(struct amdgpu_atif_functions *f, u32 mask)
170 f->system_params = mask & ATIF_GET_SYSTEM_PARAMETERS_SUPPORTED;
171 f->sbios_requests = mask & ATIF_GET_SYSTEM_BIOS_REQUESTS_SUPPORTED;
172 f->temperature_change = mask & ATIF_TEMPERATURE_CHANGE_NOTIFICATION_SUPPORTED;
173 f->query_backlight_transfer_characteristics =
174 mask & ATIF_QUERY_BACKLIGHT_TRANSFER_CHARACTERISTICS_SUPPORTED;
175 f->ready_to_undock = mask & ATIF_READY_TO_UNDOCK_NOTIFICATION_SUPPORTED;
176 f->external_gpu_information = mask & ATIF_GET_EXTERNAL_GPU_INFORMATION_SUPPORTED;
180 * amdgpu_atif_verify_interface - verify ATIF
182 * @atif: amdgpu atif struct
184 * Execute the ATIF_FUNCTION_VERIFY_INTERFACE ATIF function
185 * to initialize ATIF and determine what features are supported
187 * returns 0 on success, error on failure.
189 static int amdgpu_atif_verify_interface(struct amdgpu_atif *atif)
191 union acpi_object *info;
192 struct atif_verify_interface output;
196 info = amdgpu_atif_call(atif, ATIF_FUNCTION_VERIFY_INTERFACE, NULL);
200 memset(&output, 0, sizeof(output));
202 size = *(u16 *) info->buffer.pointer;
204 DRM_INFO("ATIF buffer is too small: %zu\n", size);
208 size = min(sizeof(output), size);
210 memcpy(&output, info->buffer.pointer, size);
212 /* TODO: check version? */
213 DRM_DEBUG_DRIVER("ATIF version %u\n", output.version);
215 amdgpu_atif_parse_notification(&atif->notifications, output.notification_mask);
216 amdgpu_atif_parse_functions(&atif->functions, output.function_bits);
223 static acpi_handle amdgpu_atif_probe_handle(acpi_handle dhandle)
225 acpi_handle handle = NULL;
226 char acpi_method_name[255] = { 0 };
227 struct acpi_buffer buffer = { sizeof(acpi_method_name), acpi_method_name };
230 /* For PX/HG systems, ATIF and ATPX are in the iGPU's namespace, on dGPU only
231 * systems, ATIF is in the dGPU's namespace.
233 status = acpi_get_handle(dhandle, "ATIF", &handle);
234 if (ACPI_SUCCESS(status))
237 if (amdgpu_has_atpx()) {
238 status = acpi_get_handle(amdgpu_atpx_get_dhandle(), "ATIF",
240 if (ACPI_SUCCESS(status))
244 DRM_DEBUG_DRIVER("No ATIF handle found\n");
247 acpi_get_name(handle, ACPI_FULL_PATHNAME, &buffer);
248 DRM_DEBUG_DRIVER("Found ATIF handle %s\n", acpi_method_name);
252 static acpi_handle amdgpu_atcs_probe_handle(acpi_handle dhandle)
254 acpi_handle handle = NULL;
255 char acpi_method_name[255] = { 0 };
256 struct acpi_buffer buffer = { sizeof(acpi_method_name), acpi_method_name };
259 /* For PX/HG systems, ATCS and ATPX are in the iGPU's namespace, on dGPU only
260 * systems, ATIF is in the dGPU's namespace.
262 status = acpi_get_handle(dhandle, "ATCS", &handle);
263 if (ACPI_SUCCESS(status))
266 if (amdgpu_has_atpx()) {
267 status = acpi_get_handle(amdgpu_atpx_get_dhandle(), "ATCS",
269 if (ACPI_SUCCESS(status))
273 DRM_DEBUG_DRIVER("No ATCS handle found\n");
276 acpi_get_name(handle, ACPI_FULL_PATHNAME, &buffer);
277 DRM_DEBUG_DRIVER("Found ATCS handle %s\n", acpi_method_name);
282 * amdgpu_atif_get_notification_params - determine notify configuration
286 * Execute the ATIF_FUNCTION_GET_SYSTEM_PARAMETERS ATIF function
287 * to determine if a notifier is used and if so which one
288 * (all asics). This is either Notify(VGA, 0x81) or Notify(VGA, n)
289 * where n is specified in the result if a notifier is used.
290 * Returns 0 on success, error on failure.
292 static int amdgpu_atif_get_notification_params(struct amdgpu_atif *atif)
294 union acpi_object *info;
295 struct amdgpu_atif_notification_cfg *n = &atif->notification_cfg;
296 struct atif_system_params params;
300 info = amdgpu_atif_call(atif, ATIF_FUNCTION_GET_SYSTEM_PARAMETERS,
307 size = *(u16 *) info->buffer.pointer;
313 memset(¶ms, 0, sizeof(params));
314 size = min(sizeof(params), size);
315 memcpy(¶ms, info->buffer.pointer, size);
317 DRM_DEBUG_DRIVER("SYSTEM_PARAMS: mask = %#x, flags = %#x\n",
318 params.flags, params.valid_mask);
319 params.flags = params.flags & params.valid_mask;
321 if ((params.flags & ATIF_NOTIFY_MASK) == ATIF_NOTIFY_NONE) {
324 } else if ((params.flags & ATIF_NOTIFY_MASK) == ATIF_NOTIFY_81) {
326 n->command_code = 0x81;
333 n->command_code = params.command_code;
337 DRM_DEBUG_DRIVER("Notification %s, command code = %#x\n",
338 (n->enabled ? "enabled" : "disabled"),
345 * amdgpu_atif_query_backlight_caps - get min and max backlight input signal
349 * Execute the QUERY_BRIGHTNESS_TRANSFER_CHARACTERISTICS ATIF function
350 * to determine the acceptable range of backlight values
352 * Backlight_caps.caps_valid will be set to true if the query is successful
354 * The input signals are in range 0-255
356 * This function assumes the display with backlight is the first LCD
358 * Returns 0 on success, error on failure.
360 static int amdgpu_atif_query_backlight_caps(struct amdgpu_atif *atif)
362 union acpi_object *info;
363 struct atif_qbtc_output characteristics;
364 struct atif_qbtc_arguments arguments;
365 struct acpi_buffer params;
369 arguments.size = sizeof(arguments);
370 arguments.requested_display = ATIF_QBTC_REQUEST_LCD1;
372 params.length = sizeof(arguments);
373 params.pointer = (void *)&arguments;
375 info = amdgpu_atif_call(atif,
376 ATIF_FUNCTION_QUERY_BRIGHTNESS_TRANSFER_CHARACTERISTICS,
383 size = *(u16 *) info->buffer.pointer;
389 memset(&characteristics, 0, sizeof(characteristics));
390 size = min(sizeof(characteristics), size);
391 memcpy(&characteristics, info->buffer.pointer, size);
393 atif->backlight_caps.caps_valid = true;
394 atif->backlight_caps.min_input_signal =
395 characteristics.min_input_signal;
396 atif->backlight_caps.max_input_signal =
397 characteristics.max_input_signal;
404 * amdgpu_atif_get_sbios_requests - get requested sbios event
407 * @req: atif sbios request struct
409 * Execute the ATIF_FUNCTION_GET_SYSTEM_BIOS_REQUESTS ATIF function
410 * to determine what requests the sbios is making to the driver
412 * Returns 0 on success, error on failure.
414 static int amdgpu_atif_get_sbios_requests(struct amdgpu_atif *atif,
415 struct atif_sbios_requests *req)
417 union acpi_object *info;
421 info = amdgpu_atif_call(atif, ATIF_FUNCTION_GET_SYSTEM_BIOS_REQUESTS,
426 size = *(u16 *)info->buffer.pointer;
431 memset(req, 0, sizeof(*req));
433 size = min(sizeof(*req), size);
434 memcpy(req, info->buffer.pointer, size);
435 DRM_DEBUG_DRIVER("SBIOS pending requests: %#x\n", req->pending);
437 count = hweight32(req->pending);
445 * amdgpu_atif_handler - handle ATIF notify requests
447 * @adev: amdgpu_device pointer
448 * @event: atif sbios request struct
450 * Checks the acpi event and if it matches an atif event,
454 * NOTIFY_BAD or NOTIFY_DONE, depending on the event.
456 static int amdgpu_atif_handler(struct amdgpu_device *adev,
457 struct acpi_bus_event *event)
459 struct amdgpu_atif *atif = adev->atif;
462 DRM_DEBUG_DRIVER("event, device_class = %s, type = %#x\n",
463 event->device_class, event->type);
465 if (strcmp(event->device_class, ACPI_VIDEO_CLASS) != 0)
468 /* Is this actually our event? */
470 !atif->notification_cfg.enabled ||
471 event->type != atif->notification_cfg.command_code) {
472 /* These events will generate keypresses otherwise */
473 if (event->type == ACPI_VIDEO_NOTIFY_PROBE)
479 if (atif->functions.sbios_requests) {
480 struct atif_sbios_requests req;
482 /* Check pending SBIOS requests */
483 count = amdgpu_atif_get_sbios_requests(atif, &req);
488 DRM_DEBUG_DRIVER("ATIF: %d pending SBIOS requests\n", count);
490 if (req.pending & ATIF_PANEL_BRIGHTNESS_CHANGE_REQUEST) {
491 #if defined(CONFIG_BACKLIGHT_CLASS_DEVICE) || defined(CONFIG_BACKLIGHT_CLASS_DEVICE_MODULE)
493 DRM_DEBUG_DRIVER("Changing brightness to %d\n",
494 req.backlight_level);
496 * XXX backlight_device_set_brightness() is
497 * hardwired to post BACKLIGHT_UPDATE_SYSFS.
498 * It probably should accept 'reason' parameter.
500 backlight_device_set_brightness(atif->bd, req.backlight_level);
505 if (req.pending & ATIF_DGPU_DISPLAY_EVENT) {
506 if (adev->flags & AMD_IS_PX) {
507 pm_runtime_get_sync(adev_to_drm(adev)->dev);
508 /* Just fire off a uevent and let userspace tell us what to do */
509 drm_helper_hpd_irq_event(adev_to_drm(adev));
510 pm_runtime_mark_last_busy(adev_to_drm(adev)->dev);
511 pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
514 /* TODO: check other events */
517 /* We've handled the event, stop the notifier chain. The ACPI interface
518 * overloads ACPI_VIDEO_NOTIFY_PROBE, we don't want to send that to
519 * userspace if the event was generated only to signal a SBIOS
525 /* Call the ATCS method
528 * amdgpu_atcs_call - call an ATCS method
530 * @atcs: atcs structure
531 * @function: the ATCS function to execute
532 * @params: ATCS function params
534 * Executes the requested ATCS function (all asics).
535 * Returns a pointer to the acpi output buffer.
537 static union acpi_object *amdgpu_atcs_call(struct amdgpu_atcs *atcs,
539 struct acpi_buffer *params)
542 union acpi_object atcs_arg_elements[2];
543 struct acpi_object_list atcs_arg;
544 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
547 atcs_arg.pointer = &atcs_arg_elements[0];
549 atcs_arg_elements[0].type = ACPI_TYPE_INTEGER;
550 atcs_arg_elements[0].integer.value = function;
553 atcs_arg_elements[1].type = ACPI_TYPE_BUFFER;
554 atcs_arg_elements[1].buffer.length = params->length;
555 atcs_arg_elements[1].buffer.pointer = params->pointer;
557 /* We need a second fake parameter */
558 atcs_arg_elements[1].type = ACPI_TYPE_INTEGER;
559 atcs_arg_elements[1].integer.value = 0;
562 status = acpi_evaluate_object(atcs->handle, "ATCS", &atcs_arg, &buffer);
564 /* Fail only if calling the method fails and ATIF is supported */
565 if (ACPI_FAILURE(status) && status != AE_NOT_FOUND) {
566 DRM_DEBUG_DRIVER("failed to evaluate ATCS got %s\n",
567 acpi_format_exception(status));
568 kfree(buffer.pointer);
572 return buffer.pointer;
576 * amdgpu_atcs_parse_functions - parse supported functions
578 * @f: supported functions struct
579 * @mask: supported functions mask from ATCS
581 * Use the supported functions mask from ATCS function
582 * ATCS_FUNCTION_VERIFY_INTERFACE to determine what functions
583 * are supported (all asics).
585 static void amdgpu_atcs_parse_functions(struct amdgpu_atcs_functions *f, u32 mask)
587 f->get_ext_state = mask & ATCS_GET_EXTERNAL_STATE_SUPPORTED;
588 f->pcie_perf_req = mask & ATCS_PCIE_PERFORMANCE_REQUEST_SUPPORTED;
589 f->pcie_dev_rdy = mask & ATCS_PCIE_DEVICE_READY_NOTIFICATION_SUPPORTED;
590 f->pcie_bus_width = mask & ATCS_SET_PCIE_BUS_WIDTH_SUPPORTED;
594 * amdgpu_atcs_verify_interface - verify ATCS
596 * @atcs: amdgpu atcs struct
598 * Execute the ATCS_FUNCTION_VERIFY_INTERFACE ATCS function
599 * to initialize ATCS and determine what features are supported
601 * returns 0 on success, error on failure.
603 static int amdgpu_atcs_verify_interface(struct amdgpu_atcs *atcs)
605 union acpi_object *info;
606 struct atcs_verify_interface output;
610 info = amdgpu_atcs_call(atcs, ATCS_FUNCTION_VERIFY_INTERFACE, NULL);
614 memset(&output, 0, sizeof(output));
616 size = *(u16 *) info->buffer.pointer;
618 DRM_INFO("ATCS buffer is too small: %zu\n", size);
622 size = min(sizeof(output), size);
624 memcpy(&output, info->buffer.pointer, size);
626 /* TODO: check version? */
627 DRM_DEBUG_DRIVER("ATCS version %u\n", output.version);
629 amdgpu_atcs_parse_functions(&atcs->functions, output.function_bits);
637 * amdgpu_acpi_is_pcie_performance_request_supported
639 * @adev: amdgpu_device pointer
641 * Check if the ATCS pcie_perf_req and pcie_dev_rdy methods
642 * are supported (all asics).
643 * returns true if supported, false if not.
645 bool amdgpu_acpi_is_pcie_performance_request_supported(struct amdgpu_device *adev)
647 struct amdgpu_atcs *atcs = adev->atcs;
651 if (atcs->functions.pcie_perf_req && atcs->functions.pcie_dev_rdy)
658 * amdgpu_acpi_pcie_notify_device_ready
660 * @adev: amdgpu_device pointer
662 * Executes the PCIE_DEVICE_READY_NOTIFICATION method
664 * returns 0 on success, error on failure.
666 int amdgpu_acpi_pcie_notify_device_ready(struct amdgpu_device *adev)
668 union acpi_object *info;
669 struct amdgpu_atcs *atcs = adev->atcs;
673 if (!atcs->functions.pcie_dev_rdy)
676 info = amdgpu_atcs_call(atcs, ATCS_FUNCTION_PCIE_DEVICE_READY_NOTIFICATION, NULL);
686 * amdgpu_acpi_pcie_performance_request
688 * @adev: amdgpu_device pointer
689 * @perf_req: requested perf level (pcie gen speed)
690 * @advertise: set advertise caps flag if set
692 * Executes the PCIE_PERFORMANCE_REQUEST method to
693 * change the pcie gen speed (all asics).
694 * returns 0 on success, error on failure.
696 int amdgpu_acpi_pcie_performance_request(struct amdgpu_device *adev,
697 u8 perf_req, bool advertise)
699 union acpi_object *info;
700 struct amdgpu_atcs *atcs = adev->atcs;
701 struct atcs_pref_req_input atcs_input;
702 struct atcs_pref_req_output atcs_output;
703 struct acpi_buffer params;
710 if (amdgpu_acpi_pcie_notify_device_ready(adev))
713 if (!atcs->functions.pcie_perf_req)
716 atcs_input.size = sizeof(struct atcs_pref_req_input);
717 /* client id (bit 2-0: func num, 7-3: dev num, 15-8: bus num) */
718 atcs_input.client_id = adev->pdev->devfn | (adev->pdev->bus->number << 8);
719 atcs_input.valid_flags_mask = ATCS_VALID_FLAGS_MASK;
720 atcs_input.flags = ATCS_WAIT_FOR_COMPLETION;
722 atcs_input.flags |= ATCS_ADVERTISE_CAPS;
723 atcs_input.req_type = ATCS_PCIE_LINK_SPEED;
724 atcs_input.perf_req = perf_req;
726 params.length = sizeof(struct atcs_pref_req_input);
727 params.pointer = &atcs_input;
730 info = amdgpu_atcs_call(atcs, ATCS_FUNCTION_PCIE_PERFORMANCE_REQUEST, ¶ms);
734 memset(&atcs_output, 0, sizeof(atcs_output));
736 size = *(u16 *) info->buffer.pointer;
738 DRM_INFO("ATCS buffer is too small: %zu\n", size);
742 size = min(sizeof(atcs_output), size);
744 memcpy(&atcs_output, info->buffer.pointer, size);
748 switch (atcs_output.ret_val) {
749 case ATCS_REQUEST_REFUSED:
752 case ATCS_REQUEST_COMPLETE:
754 case ATCS_REQUEST_IN_PROGRESS:
764 * amdgpu_acpi_event - handle notify events
766 * @nb: notifier block
770 * Calls relevant amdgpu functions in response to various
772 * Returns NOTIFY code
774 static int amdgpu_acpi_event(struct notifier_block *nb,
778 struct amdgpu_device *adev = container_of(nb, struct amdgpu_device, acpi_nb);
779 struct acpi_bus_event *entry = (struct acpi_bus_event *)data;
781 if (strcmp(entry->device_class, ACPI_AC_CLASS) == 0) {
782 if (power_supply_is_system_supplied() > 0)
783 DRM_DEBUG_DRIVER("pm: AC\n");
785 DRM_DEBUG_DRIVER("pm: DC\n");
787 amdgpu_pm_acpi_event_handler(adev);
790 /* Check for pending SBIOS requests */
791 return amdgpu_atif_handler(adev, entry);
794 /* Call all ACPI methods here */
796 * amdgpu_acpi_init - init driver acpi support
798 * @adev: amdgpu_device pointer
800 * Verifies the AMD ACPI interfaces and registers with the acpi
801 * notifier chain (all asics).
802 * Returns 0 on success, error on failure.
804 int amdgpu_acpi_init(struct amdgpu_device *adev)
806 acpi_handle handle, atif_handle, atcs_handle;
807 struct amdgpu_atif *atif;
808 struct amdgpu_atcs *atcs;
811 /* Get the device handle */
812 handle = ACPI_HANDLE(&adev->pdev->dev);
814 if (!adev->bios || !handle)
817 /* Probe for ATIF, and initialize it if found */
818 atif_handle = amdgpu_atif_probe_handle(handle);
822 atif = kzalloc(sizeof(*atif), GFP_KERNEL);
824 DRM_WARN("Not enough memory to initialize ATIF\n");
827 atif->handle = atif_handle;
829 /* Call the ATIF method */
830 ret = amdgpu_atif_verify_interface(atif);
832 DRM_DEBUG_DRIVER("Call to ATIF verify_interface failed: %d\n", ret);
838 #if defined(CONFIG_BACKLIGHT_CLASS_DEVICE) || defined(CONFIG_BACKLIGHT_CLASS_DEVICE_MODULE)
839 if (atif->notifications.brightness_change) {
840 if (amdgpu_device_has_dc_support(adev)) {
841 #if defined(CONFIG_DRM_AMD_DC)
842 struct amdgpu_display_manager *dm = &adev->dm;
843 if (dm->backlight_dev)
844 atif->bd = dm->backlight_dev;
847 struct drm_encoder *tmp;
849 /* Find the encoder controlling the brightness */
850 list_for_each_entry(tmp, &adev_to_drm(adev)->mode_config.encoder_list,
852 struct amdgpu_encoder *enc = to_amdgpu_encoder(tmp);
854 if ((enc->devices & (ATOM_DEVICE_LCD_SUPPORT)) &&
856 struct amdgpu_encoder_atom_dig *dig = enc->enc_priv;
858 atif->bd = dig->bl_dev;
867 if (atif->functions.sbios_requests && !atif->functions.system_params) {
868 /* XXX check this workraround, if sbios request function is
869 * present we have to see how it's configured in the system
872 atif->functions.system_params = true;
875 if (atif->functions.system_params) {
876 ret = amdgpu_atif_get_notification_params(atif);
878 DRM_DEBUG_DRIVER("Call to GET_SYSTEM_PARAMS failed: %d\n",
880 /* Disable notification */
881 atif->notification_cfg.enabled = false;
885 if (atif->functions.query_backlight_transfer_characteristics) {
886 ret = amdgpu_atif_query_backlight_caps(atif);
888 DRM_DEBUG_DRIVER("Call to QUERY_BACKLIGHT_TRANSFER_CHARACTERISTICS failed: %d\n",
890 atif->backlight_caps.caps_valid = false;
893 atif->backlight_caps.caps_valid = false;
897 /* Probe for ATCS, and initialize it if found */
898 atcs_handle = amdgpu_atcs_probe_handle(handle);
902 atcs = kzalloc(sizeof(*atcs), GFP_KERNEL);
904 DRM_WARN("Not enough memory to initialize ATCS\n");
907 atcs->handle = atcs_handle;
909 /* Call the ATCS method */
910 ret = amdgpu_atcs_verify_interface(atcs);
912 DRM_DEBUG_DRIVER("Call to ATCS verify_interface failed: %d\n", ret);
919 adev->acpi_nb.notifier_call = amdgpu_acpi_event;
920 register_acpi_notifier(&adev->acpi_nb);
925 void amdgpu_acpi_get_backlight_caps(struct amdgpu_device *adev,
926 struct amdgpu_dm_backlight_caps *caps)
929 caps->caps_valid = false;
932 caps->caps_valid = adev->atif->backlight_caps.caps_valid;
933 caps->min_input_signal = adev->atif->backlight_caps.min_input_signal;
934 caps->max_input_signal = adev->atif->backlight_caps.max_input_signal;
938 * amdgpu_acpi_fini - tear down driver acpi support
940 * @adev: amdgpu_device pointer
942 * Unregisters with the acpi notifier chain (all asics).
944 void amdgpu_acpi_fini(struct amdgpu_device *adev)
946 unregister_acpi_notifier(&adev->acpi_nb);
952 * amdgpu_acpi_is_s0ix_supported
954 * @adev: amdgpu_device_pointer
956 * returns true if supported, false if not.
958 bool amdgpu_acpi_is_s0ix_supported(struct amdgpu_device *adev)
960 #if defined(CONFIG_AMD_PMC) || defined(CONFIG_AMD_PMC_MODULE)
961 if (acpi_gbl_FADT.flags & ACPI_FADT_LOW_POWER_S0) {
962 if (adev->flags & AMD_IS_APU)