1926deccbSFrançois Tigeot /*
2926deccbSFrançois Tigeot * Copyright 2012 Advanced Micro Devices, Inc.
3926deccbSFrançois Tigeot *
4926deccbSFrançois Tigeot * Permission is hereby granted, free of charge, to any person obtaining a
5926deccbSFrançois Tigeot * copy of this software and associated documentation files (the "Software"),
6926deccbSFrançois Tigeot * to deal in the Software without restriction, including without limitation
7926deccbSFrançois Tigeot * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8926deccbSFrançois Tigeot * and/or sell copies of the Software, and to permit persons to whom the
9926deccbSFrançois Tigeot * Software is furnished to do so, subject to the following conditions:
10926deccbSFrançois Tigeot *
11926deccbSFrançois Tigeot * The above copyright notice and this permission notice shall be included in
12926deccbSFrançois Tigeot * all copies or substantial portions of the Software.
13926deccbSFrançois Tigeot *
14926deccbSFrançois Tigeot * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15926deccbSFrançois Tigeot * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16926deccbSFrançois Tigeot * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17926deccbSFrançois Tigeot * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18926deccbSFrançois Tigeot * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19926deccbSFrançois Tigeot * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20926deccbSFrançois Tigeot * OTHER DEALINGS IN THE SOFTWARE.
21926deccbSFrançois Tigeot *
22926deccbSFrançois Tigeot * $FreeBSD: head/sys/dev/drm2/radeon/radeon_acpi.c 254885 2013-08-25 19:37:15Z dumbbell $
23926deccbSFrançois Tigeot */
24926deccbSFrançois Tigeot
25*1dedbd3bSFrançois Tigeot #include <linux/pci.h>
26*1dedbd3bSFrançois Tigeot #include <linux/acpi.h>
27*1dedbd3bSFrançois Tigeot #include <linux/power_supply.h>
28*1dedbd3bSFrançois Tigeot #include <linux/pm_runtime.h>
29*1dedbd3bSFrançois Tigeot #include <acpi/video.h>
30926deccbSFrançois Tigeot #include <drm/drmP.h>
31926deccbSFrançois Tigeot #include <drm/drm_crtc_helper.h>
32926deccbSFrançois Tigeot #include "radeon.h"
33926deccbSFrançois Tigeot #include "radeon_acpi.h"
34926deccbSFrançois Tigeot #include "atom.h"
35926deccbSFrançois Tigeot
36926deccbSFrançois Tigeot #define ACPI_AC_CLASS "ac_adapter"
37926deccbSFrançois Tigeot
38926deccbSFrançois Tigeot struct atif_verify_interface {
39926deccbSFrançois Tigeot u16 size; /* structure size in bytes (includes size field) */
40926deccbSFrançois Tigeot u16 version; /* version */
41926deccbSFrançois Tigeot u32 notification_mask; /* supported notifications mask */
42926deccbSFrançois Tigeot u32 function_bits; /* supported functions bit vector */
43926deccbSFrançois Tigeot } __packed;
44926deccbSFrançois Tigeot
45926deccbSFrançois Tigeot struct atif_system_params {
46926deccbSFrançois Tigeot u16 size; /* structure size in bytes (includes size field) */
47926deccbSFrançois Tigeot u32 valid_mask; /* valid flags mask */
48926deccbSFrançois Tigeot u32 flags; /* flags */
49926deccbSFrançois Tigeot u8 command_code; /* notify command code */
50926deccbSFrançois Tigeot } __packed;
51926deccbSFrançois Tigeot
52926deccbSFrançois Tigeot struct atif_sbios_requests {
53926deccbSFrançois Tigeot u16 size; /* structure size in bytes (includes size field) */
54926deccbSFrançois Tigeot u32 pending; /* pending sbios requests */
55926deccbSFrançois Tigeot u8 panel_exp_mode; /* panel expansion mode */
56926deccbSFrançois Tigeot u8 thermal_gfx; /* thermal state: target gfx controller */
57926deccbSFrançois Tigeot u8 thermal_state; /* thermal state: state id (0: exit state, non-0: state) */
58926deccbSFrançois Tigeot u8 forced_power_gfx; /* forced power state: target gfx controller */
59926deccbSFrançois Tigeot u8 forced_power_state; /* forced power state: state id */
60926deccbSFrançois Tigeot u8 system_power_src; /* system power source */
61926deccbSFrançois Tigeot u8 backlight_level; /* panel backlight level (0-255) */
62926deccbSFrançois Tigeot } __packed;
63926deccbSFrançois Tigeot
64926deccbSFrançois Tigeot #define ATIF_NOTIFY_MASK 0x3
65926deccbSFrançois Tigeot #define ATIF_NOTIFY_NONE 0
66926deccbSFrançois Tigeot #define ATIF_NOTIFY_81 1
67926deccbSFrançois Tigeot #define ATIF_NOTIFY_N 2
68926deccbSFrançois Tigeot
69926deccbSFrançois Tigeot struct atcs_verify_interface {
70926deccbSFrançois Tigeot u16 size; /* structure size in bytes (includes size field) */
71926deccbSFrançois Tigeot u16 version; /* version */
72926deccbSFrançois Tigeot u32 function_bits; /* supported functions bit vector */
73926deccbSFrançois Tigeot } __packed;
74926deccbSFrançois Tigeot
7557e252bfSMichael Neumann #define ATCS_VALID_FLAGS_MASK 0x3
7657e252bfSMichael Neumann
7757e252bfSMichael Neumann struct atcs_pref_req_input {
7857e252bfSMichael Neumann u16 size; /* structure size in bytes (includes size field) */
7957e252bfSMichael Neumann u16 client_id; /* client id (bit 2-0: func num, 7-3: dev num, 15-8: bus num) */
8057e252bfSMichael Neumann u16 valid_flags_mask; /* valid flags mask */
8157e252bfSMichael Neumann u16 flags; /* flags */
8257e252bfSMichael Neumann u8 req_type; /* request type */
8357e252bfSMichael Neumann u8 perf_req; /* performance request */
8457e252bfSMichael Neumann } __packed;
8557e252bfSMichael Neumann
8657e252bfSMichael Neumann struct atcs_pref_req_output {
8757e252bfSMichael Neumann u16 size; /* structure size in bytes (includes size field) */
8857e252bfSMichael Neumann u8 ret_val; /* return value */
8957e252bfSMichael Neumann } __packed;
9057e252bfSMichael Neumann
91926deccbSFrançois Tigeot /* Call the ATIF method
92926deccbSFrançois Tigeot */
93926deccbSFrançois Tigeot /**
94926deccbSFrançois Tigeot * radeon_atif_call - call an ATIF method
95926deccbSFrançois Tigeot *
96926deccbSFrançois Tigeot * @handle: acpi handle
97926deccbSFrançois Tigeot * @function: the ATIF function to execute
98926deccbSFrançois Tigeot * @params: ATIF function params
99926deccbSFrançois Tigeot *
100926deccbSFrançois Tigeot * Executes the requested ATIF function (all asics).
101926deccbSFrançois Tigeot * Returns a pointer to the acpi output buffer.
102926deccbSFrançois Tigeot */
radeon_atif_call(ACPI_HANDLE handle,int function,ACPI_BUFFER * params)103926deccbSFrançois Tigeot static ACPI_OBJECT *radeon_atif_call(ACPI_HANDLE handle, int function,
104926deccbSFrançois Tigeot ACPI_BUFFER *params)
105926deccbSFrançois Tigeot {
106926deccbSFrançois Tigeot ACPI_STATUS status;
107926deccbSFrançois Tigeot ACPI_OBJECT atif_arg_elements[2];
108926deccbSFrançois Tigeot ACPI_OBJECT_LIST atif_arg;
109926deccbSFrançois Tigeot ACPI_BUFFER buffer = { ACPI_ALLOCATE_BUFFER, NULL };
110926deccbSFrançois Tigeot
111926deccbSFrançois Tigeot atif_arg.Count = 2;
112926deccbSFrançois Tigeot atif_arg.Pointer = &atif_arg_elements[0];
113926deccbSFrançois Tigeot
114926deccbSFrançois Tigeot atif_arg_elements[0].Type = ACPI_TYPE_INTEGER;
115926deccbSFrançois Tigeot atif_arg_elements[0].Integer.Value = function;
116926deccbSFrançois Tigeot
117926deccbSFrançois Tigeot if (params) {
118926deccbSFrançois Tigeot atif_arg_elements[1].Type = ACPI_TYPE_BUFFER;
119926deccbSFrançois Tigeot atif_arg_elements[1].Buffer.Length = params->Length;
120926deccbSFrançois Tigeot atif_arg_elements[1].Buffer.Pointer = params->Pointer;
121926deccbSFrançois Tigeot } else {
122926deccbSFrançois Tigeot /* We need a second fake parameter */
123926deccbSFrançois Tigeot atif_arg_elements[1].Type = ACPI_TYPE_INTEGER;
124926deccbSFrançois Tigeot atif_arg_elements[1].Integer.Value = 0;
125926deccbSFrançois Tigeot }
126926deccbSFrançois Tigeot
127926deccbSFrançois Tigeot status = AcpiEvaluateObject(handle, "ATIF", &atif_arg, &buffer);
128926deccbSFrançois Tigeot
129926deccbSFrançois Tigeot /* Fail only if calling the method fails and ATIF is supported */
130926deccbSFrançois Tigeot if (ACPI_FAILURE(status) && status != AE_NOT_FOUND) {
131926deccbSFrançois Tigeot DRM_DEBUG_DRIVER("failed to evaluate ATIF got %s\n",
132926deccbSFrançois Tigeot AcpiFormatException(status));
133926deccbSFrançois Tigeot AcpiOsFree(buffer.Pointer);
134926deccbSFrançois Tigeot return NULL;
135926deccbSFrançois Tigeot }
136926deccbSFrançois Tigeot
137926deccbSFrançois Tigeot return buffer.Pointer;
138926deccbSFrançois Tigeot }
139926deccbSFrançois Tigeot
140926deccbSFrançois Tigeot /**
141926deccbSFrançois Tigeot * radeon_atif_parse_notification - parse supported notifications
142926deccbSFrançois Tigeot *
143926deccbSFrançois Tigeot * @n: supported notifications struct
144926deccbSFrançois Tigeot * @mask: supported notifications mask from ATIF
145926deccbSFrançois Tigeot *
146926deccbSFrançois Tigeot * Use the supported notifications mask from ATIF function
147926deccbSFrançois Tigeot * ATIF_FUNCTION_VERIFY_INTERFACE to determine what notifications
148926deccbSFrançois Tigeot * are supported (all asics).
149926deccbSFrançois Tigeot */
radeon_atif_parse_notification(struct radeon_atif_notifications * n,u32 mask)150926deccbSFrançois Tigeot static void radeon_atif_parse_notification(struct radeon_atif_notifications *n, u32 mask)
151926deccbSFrançois Tigeot {
152926deccbSFrançois Tigeot n->display_switch = mask & ATIF_DISPLAY_SWITCH_REQUEST_SUPPORTED;
153926deccbSFrançois Tigeot n->expansion_mode_change = mask & ATIF_EXPANSION_MODE_CHANGE_REQUEST_SUPPORTED;
154926deccbSFrançois Tigeot n->thermal_state = mask & ATIF_THERMAL_STATE_CHANGE_REQUEST_SUPPORTED;
155926deccbSFrançois Tigeot n->forced_power_state = mask & ATIF_FORCED_POWER_STATE_CHANGE_REQUEST_SUPPORTED;
156926deccbSFrançois Tigeot n->system_power_state = mask & ATIF_SYSTEM_POWER_SOURCE_CHANGE_REQUEST_SUPPORTED;
157926deccbSFrançois Tigeot n->display_conf_change = mask & ATIF_DISPLAY_CONF_CHANGE_REQUEST_SUPPORTED;
158926deccbSFrançois Tigeot n->px_gfx_switch = mask & ATIF_PX_GFX_SWITCH_REQUEST_SUPPORTED;
159926deccbSFrançois Tigeot n->brightness_change = mask & ATIF_PANEL_BRIGHTNESS_CHANGE_REQUEST_SUPPORTED;
160926deccbSFrançois Tigeot n->dgpu_display_event = mask & ATIF_DGPU_DISPLAY_EVENT_SUPPORTED;
161926deccbSFrançois Tigeot }
162926deccbSFrançois Tigeot
163926deccbSFrançois Tigeot /**
164926deccbSFrançois Tigeot * radeon_atif_parse_functions - parse supported functions
165926deccbSFrançois Tigeot *
166926deccbSFrançois Tigeot * @f: supported functions struct
167926deccbSFrançois Tigeot * @mask: supported functions mask from ATIF
168926deccbSFrançois Tigeot *
169926deccbSFrançois Tigeot * Use the supported functions mask from ATIF function
170926deccbSFrançois Tigeot * ATIF_FUNCTION_VERIFY_INTERFACE to determine what functions
171926deccbSFrançois Tigeot * are supported (all asics).
172926deccbSFrançois Tigeot */
radeon_atif_parse_functions(struct radeon_atif_functions * f,u32 mask)173926deccbSFrançois Tigeot static void radeon_atif_parse_functions(struct radeon_atif_functions *f, u32 mask)
174926deccbSFrançois Tigeot {
175926deccbSFrançois Tigeot f->system_params = mask & ATIF_GET_SYSTEM_PARAMETERS_SUPPORTED;
176926deccbSFrançois Tigeot f->sbios_requests = mask & ATIF_GET_SYSTEM_BIOS_REQUESTS_SUPPORTED;
177926deccbSFrançois Tigeot f->select_active_disp = mask & ATIF_SELECT_ACTIVE_DISPLAYS_SUPPORTED;
178926deccbSFrançois Tigeot f->lid_state = mask & ATIF_GET_LID_STATE_SUPPORTED;
179926deccbSFrançois Tigeot f->get_tv_standard = mask & ATIF_GET_TV_STANDARD_FROM_CMOS_SUPPORTED;
180926deccbSFrançois Tigeot f->set_tv_standard = mask & ATIF_SET_TV_STANDARD_IN_CMOS_SUPPORTED;
181926deccbSFrançois Tigeot f->get_panel_expansion_mode = mask & ATIF_GET_PANEL_EXPANSION_MODE_FROM_CMOS_SUPPORTED;
182926deccbSFrançois Tigeot f->set_panel_expansion_mode = mask & ATIF_SET_PANEL_EXPANSION_MODE_IN_CMOS_SUPPORTED;
183926deccbSFrançois Tigeot f->temperature_change = mask & ATIF_TEMPERATURE_CHANGE_NOTIFICATION_SUPPORTED;
184926deccbSFrançois Tigeot f->graphics_device_types = mask & ATIF_GET_GRAPHICS_DEVICE_TYPES_SUPPORTED;
185926deccbSFrançois Tigeot }
186926deccbSFrançois Tigeot
187926deccbSFrançois Tigeot /**
188926deccbSFrançois Tigeot * radeon_atif_verify_interface - verify ATIF
189926deccbSFrançois Tigeot *
190926deccbSFrançois Tigeot * @handle: acpi handle
191926deccbSFrançois Tigeot * @atif: radeon atif struct
192926deccbSFrançois Tigeot *
193926deccbSFrançois Tigeot * Execute the ATIF_FUNCTION_VERIFY_INTERFACE ATIF function
194926deccbSFrançois Tigeot * to initialize ATIF and determine what features are supported
195926deccbSFrançois Tigeot * (all asics).
196926deccbSFrançois Tigeot * returns 0 on success, error on failure.
197926deccbSFrançois Tigeot */
radeon_atif_verify_interface(ACPI_HANDLE handle,struct radeon_atif * atif)198926deccbSFrançois Tigeot static int radeon_atif_verify_interface(ACPI_HANDLE handle,
199926deccbSFrançois Tigeot struct radeon_atif *atif)
200926deccbSFrançois Tigeot {
201926deccbSFrançois Tigeot ACPI_OBJECT *info;
202926deccbSFrançois Tigeot struct atif_verify_interface output;
203926deccbSFrançois Tigeot size_t size;
204926deccbSFrançois Tigeot int err = 0;
205926deccbSFrançois Tigeot
206926deccbSFrançois Tigeot info = radeon_atif_call(handle, ATIF_FUNCTION_VERIFY_INTERFACE, NULL);
207926deccbSFrançois Tigeot if (!info)
208926deccbSFrançois Tigeot return -EIO;
209926deccbSFrançois Tigeot
210926deccbSFrançois Tigeot memset(&output, 0, sizeof(output));
211926deccbSFrançois Tigeot
212926deccbSFrançois Tigeot size = *(u16 *) info->Buffer.Pointer;
213926deccbSFrançois Tigeot if (size < 12) {
214926deccbSFrançois Tigeot DRM_INFO("ATIF buffer is too small: %zu\n", size);
215926deccbSFrançois Tigeot err = -EINVAL;
216926deccbSFrançois Tigeot goto out;
217926deccbSFrançois Tigeot }
218926deccbSFrançois Tigeot size = min(sizeof(output), size);
219926deccbSFrançois Tigeot
220926deccbSFrançois Tigeot memcpy(&output, info->Buffer.Pointer, size);
221926deccbSFrançois Tigeot
222926deccbSFrançois Tigeot /* TODO: check version? */
223926deccbSFrançois Tigeot DRM_DEBUG_DRIVER("ATIF version %u\n", output.version);
224926deccbSFrançois Tigeot
225926deccbSFrançois Tigeot radeon_atif_parse_notification(&atif->notifications, output.notification_mask);
226926deccbSFrançois Tigeot radeon_atif_parse_functions(&atif->functions, output.function_bits);
227926deccbSFrançois Tigeot
228926deccbSFrançois Tigeot out:
229926deccbSFrançois Tigeot AcpiOsFree(info);
230926deccbSFrançois Tigeot return err;
231926deccbSFrançois Tigeot }
232926deccbSFrançois Tigeot
233926deccbSFrançois Tigeot /**
234926deccbSFrançois Tigeot * radeon_atif_get_notification_params - determine notify configuration
235926deccbSFrançois Tigeot *
236926deccbSFrançois Tigeot * @handle: acpi handle
237926deccbSFrançois Tigeot * @n: atif notification configuration struct
238926deccbSFrançois Tigeot *
239926deccbSFrançois Tigeot * Execute the ATIF_FUNCTION_GET_SYSTEM_PARAMETERS ATIF function
240926deccbSFrançois Tigeot * to determine if a notifier is used and if so which one
241926deccbSFrançois Tigeot * (all asics). This is either Notify(VGA, 0x81) or Notify(VGA, n)
242926deccbSFrançois Tigeot * where n is specified in the result if a notifier is used.
243926deccbSFrançois Tigeot * Returns 0 on success, error on failure.
244926deccbSFrançois Tigeot */
radeon_atif_get_notification_params(ACPI_HANDLE handle,struct radeon_atif_notification_cfg * n)245926deccbSFrançois Tigeot static int radeon_atif_get_notification_params(ACPI_HANDLE handle,
246926deccbSFrançois Tigeot struct radeon_atif_notification_cfg *n)
247926deccbSFrançois Tigeot {
248926deccbSFrançois Tigeot ACPI_OBJECT *info;
249926deccbSFrançois Tigeot struct atif_system_params params;
250926deccbSFrançois Tigeot size_t size;
251926deccbSFrançois Tigeot int err = 0;
252926deccbSFrançois Tigeot
253926deccbSFrançois Tigeot info = radeon_atif_call(handle, ATIF_FUNCTION_GET_SYSTEM_PARAMETERS, NULL);
254926deccbSFrançois Tigeot if (!info) {
255926deccbSFrançois Tigeot err = -EIO;
256926deccbSFrançois Tigeot goto out;
257926deccbSFrançois Tigeot }
258926deccbSFrançois Tigeot
259926deccbSFrançois Tigeot size = *(u16 *) info->Buffer.Pointer;
260926deccbSFrançois Tigeot if (size < 10) {
261926deccbSFrançois Tigeot err = -EINVAL;
262926deccbSFrançois Tigeot goto out;
263926deccbSFrançois Tigeot }
264926deccbSFrançois Tigeot
265926deccbSFrançois Tigeot memset(¶ms, 0, sizeof(params));
266926deccbSFrançois Tigeot size = min(sizeof(params), size);
267926deccbSFrançois Tigeot memcpy(¶ms, info->Buffer.Pointer, size);
268926deccbSFrançois Tigeot
269926deccbSFrançois Tigeot DRM_DEBUG_DRIVER("SYSTEM_PARAMS: mask = %#x, flags = %#x\n",
270926deccbSFrançois Tigeot params.flags, params.valid_mask);
271926deccbSFrançois Tigeot params.flags = params.flags & params.valid_mask;
272926deccbSFrançois Tigeot
273926deccbSFrançois Tigeot if ((params.flags & ATIF_NOTIFY_MASK) == ATIF_NOTIFY_NONE) {
274926deccbSFrançois Tigeot n->enabled = false;
275926deccbSFrançois Tigeot n->command_code = 0;
276926deccbSFrançois Tigeot } else if ((params.flags & ATIF_NOTIFY_MASK) == ATIF_NOTIFY_81) {
277926deccbSFrançois Tigeot n->enabled = true;
278926deccbSFrançois Tigeot n->command_code = 0x81;
279926deccbSFrançois Tigeot } else {
280926deccbSFrançois Tigeot if (size < 11) {
281926deccbSFrançois Tigeot err = -EINVAL;
282926deccbSFrançois Tigeot goto out;
283926deccbSFrançois Tigeot }
284926deccbSFrançois Tigeot n->enabled = true;
285926deccbSFrançois Tigeot n->command_code = params.command_code;
286926deccbSFrançois Tigeot }
287926deccbSFrançois Tigeot
288926deccbSFrançois Tigeot out:
289926deccbSFrançois Tigeot DRM_DEBUG_DRIVER("Notification %s, command code = %#x\n",
290926deccbSFrançois Tigeot (n->enabled ? "enabled" : "disabled"),
291926deccbSFrançois Tigeot n->command_code);
292926deccbSFrançois Tigeot AcpiOsFree(info);
293926deccbSFrançois Tigeot return err;
294926deccbSFrançois Tigeot }
295926deccbSFrançois Tigeot
296926deccbSFrançois Tigeot /**
297926deccbSFrançois Tigeot * radeon_atif_get_sbios_requests - get requested sbios event
298926deccbSFrançois Tigeot *
299926deccbSFrançois Tigeot * @handle: acpi handle
300926deccbSFrançois Tigeot * @req: atif sbios request struct
301926deccbSFrançois Tigeot *
302926deccbSFrançois Tigeot * Execute the ATIF_FUNCTION_GET_SYSTEM_BIOS_REQUESTS ATIF function
303926deccbSFrançois Tigeot * to determine what requests the sbios is making to the driver
304926deccbSFrançois Tigeot * (all asics).
305926deccbSFrançois Tigeot * Returns 0 on success, error on failure.
306926deccbSFrançois Tigeot */
radeon_atif_get_sbios_requests(ACPI_HANDLE handle,struct atif_sbios_requests * req)307926deccbSFrançois Tigeot static int radeon_atif_get_sbios_requests(ACPI_HANDLE handle,
308926deccbSFrançois Tigeot struct atif_sbios_requests *req)
309926deccbSFrançois Tigeot {
310926deccbSFrançois Tigeot ACPI_OBJECT *info;
311926deccbSFrançois Tigeot size_t size;
312926deccbSFrançois Tigeot int count = 0;
313926deccbSFrançois Tigeot
314926deccbSFrançois Tigeot info = radeon_atif_call(handle, ATIF_FUNCTION_GET_SYSTEM_BIOS_REQUESTS, NULL);
315926deccbSFrançois Tigeot if (!info)
316926deccbSFrançois Tigeot return -EIO;
317926deccbSFrançois Tigeot
318926deccbSFrançois Tigeot size = *(u16 *)info->Buffer.Pointer;
319926deccbSFrançois Tigeot if (size < 0xd) {
320926deccbSFrançois Tigeot count = -EINVAL;
321926deccbSFrançois Tigeot goto out;
322926deccbSFrançois Tigeot }
323926deccbSFrançois Tigeot memset(req, 0, sizeof(*req));
324926deccbSFrançois Tigeot
325926deccbSFrançois Tigeot size = min(sizeof(*req), size);
326926deccbSFrançois Tigeot memcpy(req, info->Buffer.Pointer, size);
327926deccbSFrançois Tigeot DRM_DEBUG_DRIVER("SBIOS pending requests: %#x\n", req->pending);
328926deccbSFrançois Tigeot
329926deccbSFrançois Tigeot count = hweight32(req->pending);
330926deccbSFrançois Tigeot
331926deccbSFrançois Tigeot out:
332926deccbSFrançois Tigeot AcpiOsFree(info);
333926deccbSFrançois Tigeot return count;
334926deccbSFrançois Tigeot }
335926deccbSFrançois Tigeot
336926deccbSFrançois Tigeot /**
337926deccbSFrançois Tigeot * radeon_atif_handler - handle ATIF notify requests
338926deccbSFrançois Tigeot *
339926deccbSFrançois Tigeot * @rdev: radeon_device pointer
340926deccbSFrançois Tigeot * @event: atif sbios request struct
341926deccbSFrançois Tigeot *
342926deccbSFrançois Tigeot * Checks the acpi event and if it matches an atif event,
343926deccbSFrançois Tigeot * handles it.
344926deccbSFrançois Tigeot * Returns NOTIFY code
345926deccbSFrançois Tigeot */
radeon_atif_handler(struct radeon_device * rdev,UINT32 type)346926deccbSFrançois Tigeot void radeon_atif_handler(struct radeon_device *rdev,
347926deccbSFrançois Tigeot UINT32 type)
348926deccbSFrançois Tigeot {
349926deccbSFrançois Tigeot struct radeon_atif *atif = &rdev->atif;
350926deccbSFrançois Tigeot struct atif_sbios_requests req;
351926deccbSFrançois Tigeot ACPI_HANDLE handle;
352926deccbSFrançois Tigeot int count;
353926deccbSFrançois Tigeot
354926deccbSFrançois Tigeot DRM_DEBUG_DRIVER("event, type = %#x\n",
355926deccbSFrançois Tigeot type);
356926deccbSFrançois Tigeot
357926deccbSFrançois Tigeot if (!atif->notification_cfg.enabled ||
358926deccbSFrançois Tigeot type != atif->notification_cfg.command_code)
359926deccbSFrançois Tigeot /* Not our event */
360926deccbSFrançois Tigeot return;
361926deccbSFrançois Tigeot
362926deccbSFrançois Tigeot /* Check pending SBIOS requests */
363926deccbSFrançois Tigeot handle = rdev->acpi.handle;
364926deccbSFrançois Tigeot count = radeon_atif_get_sbios_requests(handle, &req);
365926deccbSFrançois Tigeot
366926deccbSFrançois Tigeot if (count <= 0)
367926deccbSFrançois Tigeot return;
368926deccbSFrançois Tigeot
369926deccbSFrançois Tigeot DRM_DEBUG_DRIVER("ATIF: %d pending SBIOS requests\n", count);
370926deccbSFrançois Tigeot
371926deccbSFrançois Tigeot if (req.pending & ATIF_PANEL_BRIGHTNESS_CHANGE_REQUEST) {
372926deccbSFrançois Tigeot struct radeon_encoder *enc = atif->encoder_for_bl;
373926deccbSFrançois Tigeot
374926deccbSFrançois Tigeot if (enc) {
375926deccbSFrançois Tigeot DRM_DEBUG_DRIVER("Changing brightness to %d\n",
376926deccbSFrançois Tigeot req.backlight_level);
377926deccbSFrançois Tigeot
378926deccbSFrançois Tigeot radeon_set_backlight_level(rdev, enc, req.backlight_level);
379926deccbSFrançois Tigeot
380926deccbSFrançois Tigeot #ifdef DUMBBELL_WIP
381926deccbSFrançois Tigeot if (rdev->is_atom_bios) {
382926deccbSFrançois Tigeot struct radeon_encoder_atom_dig *dig = enc->enc_priv;
383926deccbSFrançois Tigeot backlight_force_update(dig->bl_dev,
384926deccbSFrançois Tigeot BACKLIGHT_UPDATE_HOTKEY);
385926deccbSFrançois Tigeot } else {
386926deccbSFrançois Tigeot struct radeon_encoder_lvds *dig = enc->enc_priv;
387926deccbSFrançois Tigeot backlight_force_update(dig->bl_dev,
388926deccbSFrançois Tigeot BACKLIGHT_UPDATE_HOTKEY);
389926deccbSFrançois Tigeot }
390926deccbSFrançois Tigeot #endif /* DUMBBELL_WIP */
391926deccbSFrançois Tigeot }
392926deccbSFrançois Tigeot }
393926deccbSFrançois Tigeot /* TODO: check other events */
394926deccbSFrançois Tigeot
395926deccbSFrançois Tigeot /* We've handled the event, stop the notifier chain. The ACPI interface
396926deccbSFrançois Tigeot * overloads ACPI_VIDEO_NOTIFY_PROBE, we don't want to send that to
397926deccbSFrançois Tigeot * userspace if the event was generated only to signal a SBIOS
398926deccbSFrançois Tigeot * request.
399926deccbSFrançois Tigeot */
400926deccbSFrançois Tigeot }
401926deccbSFrançois Tigeot
402926deccbSFrançois Tigeot /* Call the ATCS method
403926deccbSFrançois Tigeot */
404926deccbSFrançois Tigeot /**
405926deccbSFrançois Tigeot * radeon_atcs_call - call an ATCS method
406926deccbSFrançois Tigeot *
407926deccbSFrançois Tigeot * @handle: acpi handle
408926deccbSFrançois Tigeot * @function: the ATCS function to execute
409926deccbSFrançois Tigeot * @params: ATCS function params
410926deccbSFrançois Tigeot *
411926deccbSFrançois Tigeot * Executes the requested ATCS function (all asics).
412926deccbSFrançois Tigeot * Returns a pointer to the acpi output buffer.
413926deccbSFrançois Tigeot */
radeon_atcs_call(ACPI_HANDLE handle,int function,ACPI_BUFFER * params)414926deccbSFrançois Tigeot static union acpi_object *radeon_atcs_call(ACPI_HANDLE handle, int function,
415926deccbSFrançois Tigeot ACPI_BUFFER *params)
416926deccbSFrançois Tigeot {
417926deccbSFrançois Tigeot ACPI_STATUS status;
418926deccbSFrançois Tigeot ACPI_OBJECT atcs_arg_elements[2];
419926deccbSFrançois Tigeot ACPI_OBJECT_LIST atcs_arg;
420926deccbSFrançois Tigeot ACPI_BUFFER buffer = { ACPI_ALLOCATE_BUFFER, NULL };
421926deccbSFrançois Tigeot
422926deccbSFrançois Tigeot atcs_arg.Count = 2;
423926deccbSFrançois Tigeot atcs_arg.Pointer = &atcs_arg_elements[0];
424926deccbSFrançois Tigeot
425926deccbSFrançois Tigeot atcs_arg_elements[0].Type = ACPI_TYPE_INTEGER;
426926deccbSFrançois Tigeot atcs_arg_elements[0].Integer.Value = function;
427926deccbSFrançois Tigeot
428926deccbSFrançois Tigeot if (params) {
429926deccbSFrançois Tigeot atcs_arg_elements[1].Type = ACPI_TYPE_BUFFER;
430926deccbSFrançois Tigeot atcs_arg_elements[1].Buffer.Length = params->Length;
431926deccbSFrançois Tigeot atcs_arg_elements[1].Buffer.Pointer = params->Pointer;
432926deccbSFrançois Tigeot } else {
433926deccbSFrançois Tigeot /* We need a second fake parameter */
434926deccbSFrançois Tigeot atcs_arg_elements[1].Type = ACPI_TYPE_INTEGER;
435926deccbSFrançois Tigeot atcs_arg_elements[1].Integer.Value = 0;
436926deccbSFrançois Tigeot }
437926deccbSFrançois Tigeot
438926deccbSFrançois Tigeot status = AcpiEvaluateObject(handle, "ATCS", &atcs_arg, &buffer);
439926deccbSFrançois Tigeot
440926deccbSFrançois Tigeot /* Fail only if calling the method fails and ATIF is supported */
441926deccbSFrançois Tigeot if (ACPI_FAILURE(status) && status != AE_NOT_FOUND) {
442926deccbSFrançois Tigeot DRM_DEBUG_DRIVER("failed to evaluate ATCS got %s\n",
443926deccbSFrançois Tigeot AcpiFormatException(status));
444926deccbSFrançois Tigeot AcpiOsFree(buffer.Pointer);
445926deccbSFrançois Tigeot return NULL;
446926deccbSFrançois Tigeot }
447926deccbSFrançois Tigeot
448926deccbSFrançois Tigeot return buffer.Pointer;
449926deccbSFrançois Tigeot }
450926deccbSFrançois Tigeot
451926deccbSFrançois Tigeot /**
452926deccbSFrançois Tigeot * radeon_atcs_parse_functions - parse supported functions
453926deccbSFrançois Tigeot *
454926deccbSFrançois Tigeot * @f: supported functions struct
455926deccbSFrançois Tigeot * @mask: supported functions mask from ATCS
456926deccbSFrançois Tigeot *
457926deccbSFrançois Tigeot * Use the supported functions mask from ATCS function
458926deccbSFrançois Tigeot * ATCS_FUNCTION_VERIFY_INTERFACE to determine what functions
459926deccbSFrançois Tigeot * are supported (all asics).
460926deccbSFrançois Tigeot */
radeon_atcs_parse_functions(struct radeon_atcs_functions * f,u32 mask)461926deccbSFrançois Tigeot static void radeon_atcs_parse_functions(struct radeon_atcs_functions *f, u32 mask)
462926deccbSFrançois Tigeot {
463926deccbSFrançois Tigeot f->get_ext_state = mask & ATCS_GET_EXTERNAL_STATE_SUPPORTED;
464926deccbSFrançois Tigeot f->pcie_perf_req = mask & ATCS_PCIE_PERFORMANCE_REQUEST_SUPPORTED;
465926deccbSFrançois Tigeot f->pcie_dev_rdy = mask & ATCS_PCIE_DEVICE_READY_NOTIFICATION_SUPPORTED;
466926deccbSFrançois Tigeot f->pcie_bus_width = mask & ATCS_SET_PCIE_BUS_WIDTH_SUPPORTED;
467926deccbSFrançois Tigeot }
468926deccbSFrançois Tigeot
469926deccbSFrançois Tigeot /**
470926deccbSFrançois Tigeot * radeon_atcs_verify_interface - verify ATCS
471926deccbSFrançois Tigeot *
472926deccbSFrançois Tigeot * @handle: acpi handle
473926deccbSFrançois Tigeot * @atcs: radeon atcs struct
474926deccbSFrançois Tigeot *
475926deccbSFrançois Tigeot * Execute the ATCS_FUNCTION_VERIFY_INTERFACE ATCS function
476926deccbSFrançois Tigeot * to initialize ATCS and determine what features are supported
477926deccbSFrançois Tigeot * (all asics).
478926deccbSFrançois Tigeot * returns 0 on success, error on failure.
479926deccbSFrançois Tigeot */
radeon_atcs_verify_interface(ACPI_HANDLE handle,struct radeon_atcs * atcs)480926deccbSFrançois Tigeot static int radeon_atcs_verify_interface(ACPI_HANDLE handle,
481926deccbSFrançois Tigeot struct radeon_atcs *atcs)
482926deccbSFrançois Tigeot {
483926deccbSFrançois Tigeot ACPI_OBJECT *info;
484926deccbSFrançois Tigeot struct atcs_verify_interface output;
485926deccbSFrançois Tigeot size_t size;
486926deccbSFrançois Tigeot int err = 0;
487926deccbSFrançois Tigeot
488926deccbSFrançois Tigeot info = radeon_atcs_call(handle, ATCS_FUNCTION_VERIFY_INTERFACE, NULL);
489926deccbSFrançois Tigeot if (!info)
490926deccbSFrançois Tigeot return -EIO;
491926deccbSFrançois Tigeot
492926deccbSFrançois Tigeot memset(&output, 0, sizeof(output));
493926deccbSFrançois Tigeot
494926deccbSFrançois Tigeot size = *(u16 *) info->Buffer.Pointer;
495926deccbSFrançois Tigeot if (size < 8) {
496926deccbSFrançois Tigeot DRM_INFO("ATCS buffer is too small: %zu\n", size);
497926deccbSFrançois Tigeot err = -EINVAL;
498926deccbSFrançois Tigeot goto out;
499926deccbSFrançois Tigeot }
500926deccbSFrançois Tigeot size = min(sizeof(output), size);
501926deccbSFrançois Tigeot
502926deccbSFrançois Tigeot memcpy(&output, info->Buffer.Pointer, size);
503926deccbSFrançois Tigeot
504926deccbSFrançois Tigeot /* TODO: check version? */
505926deccbSFrançois Tigeot DRM_DEBUG_DRIVER("ATCS version %u\n", output.version);
506926deccbSFrançois Tigeot
507926deccbSFrançois Tigeot radeon_atcs_parse_functions(&atcs->functions, output.function_bits);
508926deccbSFrançois Tigeot
509926deccbSFrançois Tigeot out:
510926deccbSFrançois Tigeot AcpiOsFree(info);
511926deccbSFrançois Tigeot return err;
512926deccbSFrançois Tigeot }
513926deccbSFrançois Tigeot
514926deccbSFrançois Tigeot /**
51557e252bfSMichael Neumann * radeon_acpi_is_pcie_performance_request_supported
51657e252bfSMichael Neumann *
51757e252bfSMichael Neumann * @rdev: radeon_device pointer
51857e252bfSMichael Neumann *
51957e252bfSMichael Neumann * Check if the ATCS pcie_perf_req and pcie_dev_rdy methods
52057e252bfSMichael Neumann * are supported (all asics).
52157e252bfSMichael Neumann * returns true if supported, false if not.
52257e252bfSMichael Neumann */
radeon_acpi_is_pcie_performance_request_supported(struct radeon_device * rdev)52357e252bfSMichael Neumann bool radeon_acpi_is_pcie_performance_request_supported(struct radeon_device *rdev)
52457e252bfSMichael Neumann {
52557e252bfSMichael Neumann struct radeon_atcs *atcs = &rdev->atcs;
52657e252bfSMichael Neumann
52757e252bfSMichael Neumann if (atcs->functions.pcie_perf_req && atcs->functions.pcie_dev_rdy)
52857e252bfSMichael Neumann return true;
52957e252bfSMichael Neumann
53057e252bfSMichael Neumann return false;
53157e252bfSMichael Neumann }
53257e252bfSMichael Neumann
53357e252bfSMichael Neumann /**
53457e252bfSMichael Neumann * radeon_acpi_pcie_notify_device_ready
53557e252bfSMichael Neumann *
53657e252bfSMichael Neumann * @rdev: radeon_device pointer
53757e252bfSMichael Neumann *
53857e252bfSMichael Neumann * Executes the PCIE_DEVICE_READY_NOTIFICATION method
53957e252bfSMichael Neumann * (all asics).
54057e252bfSMichael Neumann * returns 0 on success, error on failure.
54157e252bfSMichael Neumann */
radeon_acpi_pcie_notify_device_ready(struct radeon_device * rdev)54257e252bfSMichael Neumann int radeon_acpi_pcie_notify_device_ready(struct radeon_device *rdev)
54357e252bfSMichael Neumann {
54457e252bfSMichael Neumann #ifdef MN_TODO
54557e252bfSMichael Neumann acpi_handle handle;
54657e252bfSMichael Neumann union acpi_object *info;
54757e252bfSMichael Neumann struct radeon_atcs *atcs = &rdev->atcs;
54857e252bfSMichael Neumann
54957e252bfSMichael Neumann /* Get the device handle */
55057e252bfSMichael Neumann handle = DEVICE_ACPI_HANDLE(&rdev->pdev->dev);
55157e252bfSMichael Neumann if (!handle)
55257e252bfSMichael Neumann return -EINVAL;
55357e252bfSMichael Neumann
55457e252bfSMichael Neumann if (!atcs->functions.pcie_dev_rdy)
55557e252bfSMichael Neumann return -EINVAL;
55657e252bfSMichael Neumann
55757e252bfSMichael Neumann info = radeon_atcs_call(handle, ATCS_FUNCTION_PCIE_DEVICE_READY_NOTIFICATION, NULL);
55857e252bfSMichael Neumann if (!info)
55957e252bfSMichael Neumann return -EIO;
56057e252bfSMichael Neumann
56157e252bfSMichael Neumann kfree(info);
562c4ef309bSzrj
56357e252bfSMichael Neumann return 0;
56457e252bfSMichael Neumann #else
56557e252bfSMichael Neumann return -EINVAL;
56657e252bfSMichael Neumann #endif
56757e252bfSMichael Neumann }
56857e252bfSMichael Neumann
56957e252bfSMichael Neumann /**
57057e252bfSMichael Neumann * radeon_acpi_pcie_performance_request
57157e252bfSMichael Neumann *
57257e252bfSMichael Neumann * @rdev: radeon_device pointer
57357e252bfSMichael Neumann * @perf_req: requested perf level (pcie gen speed)
57457e252bfSMichael Neumann * @advertise: set advertise caps flag if set
57557e252bfSMichael Neumann *
57657e252bfSMichael Neumann * Executes the PCIE_PERFORMANCE_REQUEST method to
57757e252bfSMichael Neumann * change the pcie gen speed (all asics).
57857e252bfSMichael Neumann * returns 0 on success, error on failure.
57957e252bfSMichael Neumann */
radeon_acpi_pcie_performance_request(struct radeon_device * rdev,u8 perf_req,bool advertise)58057e252bfSMichael Neumann int radeon_acpi_pcie_performance_request(struct radeon_device *rdev,
58157e252bfSMichael Neumann u8 perf_req, bool advertise)
58257e252bfSMichael Neumann {
58357e252bfSMichael Neumann #ifdef MN_TODO
58457e252bfSMichael Neumann acpi_handle handle;
58557e252bfSMichael Neumann union acpi_object *info;
58657e252bfSMichael Neumann struct radeon_atcs *atcs = &rdev->atcs;
58757e252bfSMichael Neumann struct atcs_pref_req_input atcs_input;
58857e252bfSMichael Neumann struct atcs_pref_req_output atcs_output;
58957e252bfSMichael Neumann struct acpi_buffer params;
59057e252bfSMichael Neumann size_t size;
59157e252bfSMichael Neumann u32 retry = 3;
59257e252bfSMichael Neumann
59357e252bfSMichael Neumann /* Get the device handle */
59457e252bfSMichael Neumann handle = DEVICE_ACPI_HANDLE(&rdev->pdev->dev);
59557e252bfSMichael Neumann if (!handle)
59657e252bfSMichael Neumann return -EINVAL;
59757e252bfSMichael Neumann
59857e252bfSMichael Neumann if (!atcs->functions.pcie_perf_req)
59957e252bfSMichael Neumann return -EINVAL;
60057e252bfSMichael Neumann
60157e252bfSMichael Neumann atcs_input.size = sizeof(struct atcs_pref_req_input);
60257e252bfSMichael Neumann /* client id (bit 2-0: func num, 7-3: dev num, 15-8: bus num) */
60357e252bfSMichael Neumann atcs_input.client_id = rdev->pdev->devfn | (rdev->pdev->bus->number << 8);
60457e252bfSMichael Neumann atcs_input.valid_flags_mask = ATCS_VALID_FLAGS_MASK;
60557e252bfSMichael Neumann atcs_input.flags = ATCS_WAIT_FOR_COMPLETION;
60657e252bfSMichael Neumann if (advertise)
60757e252bfSMichael Neumann atcs_input.flags |= ATCS_ADVERTISE_CAPS;
60857e252bfSMichael Neumann atcs_input.req_type = ATCS_PCIE_LINK_SPEED;
60957e252bfSMichael Neumann atcs_input.perf_req = perf_req;
61057e252bfSMichael Neumann
61157e252bfSMichael Neumann params.length = sizeof(struct atcs_pref_req_input);
61257e252bfSMichael Neumann params.pointer = &atcs_input;
61357e252bfSMichael Neumann
61457e252bfSMichael Neumann while (retry--) {
61557e252bfSMichael Neumann info = radeon_atcs_call(handle, ATCS_FUNCTION_PCIE_PERFORMANCE_REQUEST, ¶ms);
61657e252bfSMichael Neumann if (!info)
61757e252bfSMichael Neumann return -EIO;
61857e252bfSMichael Neumann
61957e252bfSMichael Neumann memset(&atcs_output, 0, sizeof(atcs_output));
62057e252bfSMichael Neumann
62157e252bfSMichael Neumann size = *(u16 *) info->buffer.pointer;
62257e252bfSMichael Neumann if (size < 3) {
62357e252bfSMichael Neumann DRM_INFO("ATCS buffer is too small: %zu\n", size);
62457e252bfSMichael Neumann kfree(info);
62557e252bfSMichael Neumann return -EINVAL;
62657e252bfSMichael Neumann }
62757e252bfSMichael Neumann size = min(sizeof(atcs_output), size);
62857e252bfSMichael Neumann
62957e252bfSMichael Neumann memcpy(&atcs_output, info->buffer.pointer, size);
63057e252bfSMichael Neumann
63157e252bfSMichael Neumann kfree(info);
63257e252bfSMichael Neumann
63357e252bfSMichael Neumann switch (atcs_output.ret_val) {
63457e252bfSMichael Neumann case ATCS_REQUEST_REFUSED:
63557e252bfSMichael Neumann default:
63657e252bfSMichael Neumann return -EINVAL;
63757e252bfSMichael Neumann case ATCS_REQUEST_COMPLETE:
63857e252bfSMichael Neumann return 0;
63957e252bfSMichael Neumann case ATCS_REQUEST_IN_PROGRESS:
640c4ef309bSzrj udelay(10);
64157e252bfSMichael Neumann break;
64257e252bfSMichael Neumann }
64357e252bfSMichael Neumann }
64457e252bfSMichael Neumann
64557e252bfSMichael Neumann return 0;
64657e252bfSMichael Neumann #else
64757e252bfSMichael Neumann return -EINVAL;
64857e252bfSMichael Neumann #endif
64957e252bfSMichael Neumann }
65057e252bfSMichael Neumann
65157e252bfSMichael Neumann /**
652926deccbSFrançois Tigeot * radeon_acpi_event - handle notify events
653926deccbSFrançois Tigeot *
654926deccbSFrançois Tigeot * @nb: notifier block
655926deccbSFrançois Tigeot * @val: val
656926deccbSFrançois Tigeot * @data: acpi event
657926deccbSFrançois Tigeot *
658926deccbSFrançois Tigeot * Calls relevant radeon functions in response to various
659926deccbSFrançois Tigeot * acpi events.
660926deccbSFrançois Tigeot * Returns NOTIFY code
661926deccbSFrançois Tigeot */
radeon_acpi_event(ACPI_HANDLE handle,UINT32 type,void * context)662926deccbSFrançois Tigeot static void radeon_acpi_event(ACPI_HANDLE handle, UINT32 type,
663926deccbSFrançois Tigeot void *context)
664926deccbSFrançois Tigeot {
665926deccbSFrançois Tigeot struct radeon_device *rdev = (struct radeon_device *)context;
666926deccbSFrançois Tigeot
667926deccbSFrançois Tigeot #ifdef DUMBBELL_WIP
668926deccbSFrançois Tigeot if (strcmp(entry->device_class, ACPI_AC_CLASS) == 0) {
669926deccbSFrançois Tigeot if (power_supply_is_system_supplied() > 0)
670926deccbSFrançois Tigeot DRM_DEBUG_DRIVER("pm: AC\n");
671926deccbSFrançois Tigeot else
672926deccbSFrançois Tigeot DRM_DEBUG_DRIVER("pm: DC\n");
673926deccbSFrançois Tigeot
674926deccbSFrançois Tigeot radeon_pm_acpi_event_handler(rdev);
675926deccbSFrançois Tigeot }
676926deccbSFrançois Tigeot #endif /* DUMBBELL_WIP */
677926deccbSFrançois Tigeot
678926deccbSFrançois Tigeot /* Check for pending SBIOS requests */
679926deccbSFrançois Tigeot radeon_atif_handler(rdev, type);
680926deccbSFrançois Tigeot }
681926deccbSFrançois Tigeot
682926deccbSFrançois Tigeot /* Call all ACPI methods here */
683926deccbSFrançois Tigeot /**
684926deccbSFrançois Tigeot * radeon_acpi_init - init driver acpi support
685926deccbSFrançois Tigeot *
686926deccbSFrançois Tigeot * @rdev: radeon_device pointer
687926deccbSFrançois Tigeot *
688926deccbSFrançois Tigeot * Verifies the AMD ACPI interfaces and registers with the acpi
689926deccbSFrançois Tigeot * notifier chain (all asics).
690926deccbSFrançois Tigeot * Returns 0 on success, error on failure.
691926deccbSFrançois Tigeot */
radeon_acpi_init(struct radeon_device * rdev)692926deccbSFrançois Tigeot int radeon_acpi_init(struct radeon_device *rdev)
693926deccbSFrançois Tigeot {
694926deccbSFrançois Tigeot ACPI_HANDLE handle;
695926deccbSFrançois Tigeot struct radeon_atif *atif = &rdev->atif;
696926deccbSFrançois Tigeot struct radeon_atcs *atcs = &rdev->atcs;
697926deccbSFrançois Tigeot int ret;
698926deccbSFrançois Tigeot
699926deccbSFrançois Tigeot /* Get the device handle */
700fb572d17SFrançois Tigeot handle = acpi_get_handle(rdev->dev->bsddev);
701926deccbSFrançois Tigeot
702926deccbSFrançois Tigeot /* No need to proceed if we're sure that ATIF is not supported */
703926deccbSFrançois Tigeot if (!ASIC_IS_AVIVO(rdev) || !rdev->bios || !handle)
704926deccbSFrançois Tigeot return 0;
705926deccbSFrançois Tigeot
706926deccbSFrançois Tigeot /* Call the ATCS method */
707926deccbSFrançois Tigeot ret = radeon_atcs_verify_interface(handle, atcs);
708926deccbSFrançois Tigeot if (ret) {
709926deccbSFrançois Tigeot DRM_DEBUG_DRIVER("Call to ATCS verify_interface failed: %d\n", ret);
710926deccbSFrançois Tigeot }
711926deccbSFrançois Tigeot
712926deccbSFrançois Tigeot /* Call the ATIF method */
713926deccbSFrançois Tigeot ret = radeon_atif_verify_interface(handle, atif);
714926deccbSFrançois Tigeot if (ret) {
715926deccbSFrançois Tigeot DRM_DEBUG_DRIVER("Call to ATIF verify_interface failed: %d\n", ret);
716926deccbSFrançois Tigeot goto out;
717926deccbSFrançois Tigeot }
718926deccbSFrançois Tigeot
719926deccbSFrançois Tigeot if (atif->notifications.brightness_change) {
720926deccbSFrançois Tigeot struct drm_encoder *tmp;
721926deccbSFrançois Tigeot struct radeon_encoder *target = NULL;
722926deccbSFrançois Tigeot
723926deccbSFrançois Tigeot /* Find the encoder controlling the brightness */
724926deccbSFrançois Tigeot list_for_each_entry(tmp, &rdev->ddev->mode_config.encoder_list,
725926deccbSFrançois Tigeot head) {
726926deccbSFrançois Tigeot struct radeon_encoder *enc = to_radeon_encoder(tmp);
727926deccbSFrançois Tigeot
728926deccbSFrançois Tigeot if ((enc->devices & (ATOM_DEVICE_LCD_SUPPORT)) &&
729926deccbSFrançois Tigeot enc->enc_priv) {
730926deccbSFrançois Tigeot if (rdev->is_atom_bios) {
731926deccbSFrançois Tigeot struct radeon_encoder_atom_dig *dig = enc->enc_priv;
732926deccbSFrançois Tigeot if (dig->bl_dev) {
733926deccbSFrançois Tigeot target = enc;
734926deccbSFrançois Tigeot break;
735926deccbSFrançois Tigeot }
736926deccbSFrançois Tigeot } else {
737926deccbSFrançois Tigeot struct radeon_encoder_lvds *dig = enc->enc_priv;
738926deccbSFrançois Tigeot if (dig->bl_dev) {
739926deccbSFrançois Tigeot target = enc;
740926deccbSFrançois Tigeot break;
741926deccbSFrançois Tigeot }
742926deccbSFrançois Tigeot }
743926deccbSFrançois Tigeot }
744926deccbSFrançois Tigeot }
745926deccbSFrançois Tigeot
746926deccbSFrançois Tigeot atif->encoder_for_bl = target;
747926deccbSFrançois Tigeot }
748926deccbSFrançois Tigeot
749926deccbSFrançois Tigeot if (atif->functions.sbios_requests && !atif->functions.system_params) {
750926deccbSFrançois Tigeot /* XXX check this workraround, if sbios request function is
751926deccbSFrançois Tigeot * present we have to see how it's configured in the system
752926deccbSFrançois Tigeot * params
753926deccbSFrançois Tigeot */
754926deccbSFrançois Tigeot atif->functions.system_params = true;
755926deccbSFrançois Tigeot }
756926deccbSFrançois Tigeot
757926deccbSFrançois Tigeot if (atif->functions.system_params) {
758926deccbSFrançois Tigeot ret = radeon_atif_get_notification_params(handle,
759926deccbSFrançois Tigeot &atif->notification_cfg);
760926deccbSFrançois Tigeot if (ret) {
761926deccbSFrançois Tigeot DRM_DEBUG_DRIVER("Call to GET_SYSTEM_PARAMS failed: %d\n",
762926deccbSFrançois Tigeot ret);
763926deccbSFrançois Tigeot /* Disable notification */
764926deccbSFrançois Tigeot atif->notification_cfg.enabled = false;
765926deccbSFrançois Tigeot }
766926deccbSFrançois Tigeot }
767926deccbSFrançois Tigeot
768926deccbSFrançois Tigeot out:
769926deccbSFrançois Tigeot rdev->acpi.handle = handle;
770926deccbSFrançois Tigeot rdev->acpi.notifier_call = radeon_acpi_event;
771926deccbSFrançois Tigeot AcpiInstallNotifyHandler(handle, ACPI_DEVICE_NOTIFY,
772926deccbSFrançois Tigeot rdev->acpi.notifier_call, rdev);
773926deccbSFrançois Tigeot
774926deccbSFrançois Tigeot return ret;
775926deccbSFrançois Tigeot }
776926deccbSFrançois Tigeot
777926deccbSFrançois Tigeot /**
778926deccbSFrançois Tigeot * radeon_acpi_fini - tear down driver acpi support
779926deccbSFrançois Tigeot *
780926deccbSFrançois Tigeot * @rdev: radeon_device pointer
781926deccbSFrançois Tigeot *
782926deccbSFrançois Tigeot * Unregisters with the acpi notifier chain (all asics).
783926deccbSFrançois Tigeot */
radeon_acpi_fini(struct radeon_device * rdev)784926deccbSFrançois Tigeot void radeon_acpi_fini(struct radeon_device *rdev)
785926deccbSFrançois Tigeot {
786926deccbSFrançois Tigeot AcpiRemoveNotifyHandler(rdev->acpi.handle, ACPI_DEVICE_NOTIFY,
787926deccbSFrançois Tigeot rdev->acpi.notifier_call);
788926deccbSFrançois Tigeot }
789