Alex Deucher | efd4e41 | 2012-07-31 17:18:17 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2012 Advanced Micro Devices, Inc. |
| 3 | * |
| 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: |
| 10 | * |
| 11 | * The above copyright notice and this permission notice shall be included in |
| 12 | * all copies or substantial portions of the Software. |
| 13 | * |
| 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. |
| 21 | * |
| 22 | */ |
| 23 | |
Alberto Milone | d7a2952 | 2010-07-06 11:40:24 -0400 | [diff] [blame] | 24 | #include <linux/pci.h> |
| 25 | #include <linux/acpi.h> |
| 26 | #include <linux/slab.h> |
Alex Deucher | c491707 | 2012-07-31 17:14:35 -0400 | [diff] [blame] | 27 | #include <linux/power_supply.h> |
Alberto Milone | d7a2952 | 2010-07-06 11:40:24 -0400 | [diff] [blame] | 28 | #include <acpi/acpi_drivers.h> |
| 29 | #include <acpi/acpi_bus.h> |
Luca Tettamanti | fda4b25 | 2012-07-30 21:20:35 +0200 | [diff] [blame] | 30 | #include <acpi/video.h> |
Alberto Milone | d7a2952 | 2010-07-06 11:40:24 -0400 | [diff] [blame] | 31 | |
David Howells | 760285e | 2012-10-02 18:01:07 +0100 | [diff] [blame] | 32 | #include <drm/drmP.h> |
| 33 | #include <drm/drm_crtc_helper.h> |
Alberto Milone | d7a2952 | 2010-07-06 11:40:24 -0400 | [diff] [blame] | 34 | #include "radeon.h" |
Alex Deucher | 9e05b2f | 2012-07-18 13:28:52 -0400 | [diff] [blame] | 35 | #include "radeon_acpi.h" |
Luca Tettamanti | fda4b25 | 2012-07-30 21:20:35 +0200 | [diff] [blame] | 36 | #include "atom.h" |
Alberto Milone | d7a2952 | 2010-07-06 11:40:24 -0400 | [diff] [blame] | 37 | |
| 38 | #include <linux/vga_switcheroo.h> |
| 39 | |
Alex Deucher | c491707 | 2012-07-31 17:14:35 -0400 | [diff] [blame] | 40 | #define ACPI_AC_CLASS "ac_adapter" |
| 41 | |
| 42 | extern void radeon_pm_acpi_event_handler(struct radeon_device *rdev); |
| 43 | |
Luca Tettamanti | fd64ca8 | 2012-08-16 11:11:18 -0400 | [diff] [blame] | 44 | struct atif_verify_interface { |
| 45 | u16 size; /* structure size in bytes (includes size field) */ |
| 46 | u16 version; /* version */ |
| 47 | u32 notification_mask; /* supported notifications mask */ |
| 48 | u32 function_bits; /* supported functions bit vector */ |
| 49 | } __packed; |
| 50 | |
Luca Tettamanti | ce3cf82 | 2012-07-30 21:16:06 +0200 | [diff] [blame] | 51 | struct atif_system_params { |
Luca Tettamanti | fda4b25 | 2012-07-30 21:20:35 +0200 | [diff] [blame] | 52 | u16 size; /* structure size in bytes (includes size field) */ |
| 53 | u32 valid_mask; /* valid flags mask */ |
| 54 | u32 flags; /* flags */ |
| 55 | u8 command_code; /* notify command code */ |
| 56 | } __packed; |
| 57 | |
| 58 | struct atif_sbios_requests { |
| 59 | u16 size; /* structure size in bytes (includes size field) */ |
| 60 | u32 pending; /* pending sbios requests */ |
| 61 | u8 panel_exp_mode; /* panel expansion mode */ |
| 62 | u8 thermal_gfx; /* thermal state: target gfx controller */ |
| 63 | u8 thermal_state; /* thermal state: state id (0: exit state, non-0: state) */ |
| 64 | u8 forced_power_gfx; /* forced power state: target gfx controller */ |
| 65 | u8 forced_power_state; /* forced power state: state id */ |
| 66 | u8 system_power_src; /* system power source */ |
| 67 | u8 backlight_level; /* panel backlight level (0-255) */ |
Luca Tettamanti | ce3cf82 | 2012-07-30 21:16:06 +0200 | [diff] [blame] | 68 | } __packed; |
| 69 | |
| 70 | #define ATIF_NOTIFY_MASK 0x3 |
| 71 | #define ATIF_NOTIFY_NONE 0 |
| 72 | #define ATIF_NOTIFY_81 1 |
| 73 | #define ATIF_NOTIFY_N 2 |
| 74 | |
Alex Deucher | e3a1592 | 2012-08-16 11:13:43 -0400 | [diff] [blame] | 75 | struct atcs_verify_interface { |
| 76 | u16 size; /* structure size in bytes (includes size field) */ |
| 77 | u16 version; /* version */ |
| 78 | u32 function_bits; /* supported functions bit vector */ |
| 79 | } __packed; |
| 80 | |
Alex Deucher | dc50ba7 | 2013-06-26 00:33:35 -0400 | [diff] [blame^] | 81 | bool radeon_acpi_is_pcie_performance_request_supported(struct radeon_device *rdev) |
| 82 | { |
| 83 | /* XXX: query ATIF */ |
| 84 | |
| 85 | return false; |
| 86 | } |
| 87 | |
| 88 | int radeon_acpi_pcie_notify_device_ready(struct radeon_device *rdev) |
| 89 | { |
| 90 | /* XXX: call appropriate ATIF method */ |
| 91 | |
| 92 | return -EINVAL; |
| 93 | |
| 94 | } |
| 95 | |
| 96 | int radeon_acpi_pcie_performance_request(struct radeon_device *rdev, |
| 97 | u8 ref_req, bool advertise) |
| 98 | { |
| 99 | /* XXX: call appropriate ATIF method */ |
| 100 | |
| 101 | return -EINVAL; |
| 102 | } |
| 103 | |
Alberto Milone | d7a2952 | 2010-07-06 11:40:24 -0400 | [diff] [blame] | 104 | /* Call the ATIF method |
Alberto Milone | d7a2952 | 2010-07-06 11:40:24 -0400 | [diff] [blame] | 105 | */ |
Alex Deucher | c3c6516 | 2012-08-02 12:30:49 -0400 | [diff] [blame] | 106 | /** |
| 107 | * radeon_atif_call - call an ATIF method |
| 108 | * |
| 109 | * @handle: acpi handle |
| 110 | * @function: the ATIF function to execute |
| 111 | * @params: ATIF function params |
| 112 | * |
| 113 | * Executes the requested ATIF function (all asics). |
| 114 | * Returns a pointer to the acpi output buffer. |
| 115 | */ |
Luca Tettamanti | 8650467 | 2012-07-29 17:04:43 +0200 | [diff] [blame] | 116 | static union acpi_object *radeon_atif_call(acpi_handle handle, int function, |
| 117 | struct acpi_buffer *params) |
Alberto Milone | d7a2952 | 2010-07-06 11:40:24 -0400 | [diff] [blame] | 118 | { |
| 119 | acpi_status status; |
| 120 | union acpi_object atif_arg_elements[2]; |
| 121 | struct acpi_object_list atif_arg; |
Luca Tettamanti | 8650467 | 2012-07-29 17:04:43 +0200 | [diff] [blame] | 122 | struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL }; |
Alberto Milone | d7a2952 | 2010-07-06 11:40:24 -0400 | [diff] [blame] | 123 | |
| 124 | atif_arg.count = 2; |
| 125 | atif_arg.pointer = &atif_arg_elements[0]; |
| 126 | |
| 127 | atif_arg_elements[0].type = ACPI_TYPE_INTEGER; |
Luca Tettamanti | 8650467 | 2012-07-29 17:04:43 +0200 | [diff] [blame] | 128 | atif_arg_elements[0].integer.value = function; |
| 129 | |
| 130 | if (params) { |
| 131 | atif_arg_elements[1].type = ACPI_TYPE_BUFFER; |
| 132 | atif_arg_elements[1].buffer.length = params->length; |
| 133 | atif_arg_elements[1].buffer.pointer = params->pointer; |
| 134 | } else { |
| 135 | /* We need a second fake parameter */ |
| 136 | atif_arg_elements[1].type = ACPI_TYPE_INTEGER; |
| 137 | atif_arg_elements[1].integer.value = 0; |
| 138 | } |
Alberto Milone | d7a2952 | 2010-07-06 11:40:24 -0400 | [diff] [blame] | 139 | |
| 140 | status = acpi_evaluate_object(handle, "ATIF", &atif_arg, &buffer); |
| 141 | |
| 142 | /* Fail only if calling the method fails and ATIF is supported */ |
| 143 | if (ACPI_FAILURE(status) && status != AE_NOT_FOUND) { |
Jean Delvare | bc96f94 | 2011-11-30 17:26:36 +0100 | [diff] [blame] | 144 | DRM_DEBUG_DRIVER("failed to evaluate ATIF got %s\n", |
| 145 | acpi_format_exception(status)); |
Alberto Milone | d7a2952 | 2010-07-06 11:40:24 -0400 | [diff] [blame] | 146 | kfree(buffer.pointer); |
Luca Tettamanti | 8650467 | 2012-07-29 17:04:43 +0200 | [diff] [blame] | 147 | return NULL; |
Alberto Milone | d7a2952 | 2010-07-06 11:40:24 -0400 | [diff] [blame] | 148 | } |
| 149 | |
Luca Tettamanti | 8650467 | 2012-07-29 17:04:43 +0200 | [diff] [blame] | 150 | return buffer.pointer; |
Alberto Milone | d7a2952 | 2010-07-06 11:40:24 -0400 | [diff] [blame] | 151 | } |
| 152 | |
Alex Deucher | c3c6516 | 2012-08-02 12:30:49 -0400 | [diff] [blame] | 153 | /** |
| 154 | * radeon_atif_parse_notification - parse supported notifications |
| 155 | * |
| 156 | * @n: supported notifications struct |
| 157 | * @mask: supported notifications mask from ATIF |
| 158 | * |
| 159 | * Use the supported notifications mask from ATIF function |
| 160 | * ATIF_FUNCTION_VERIFY_INTERFACE to determine what notifications |
| 161 | * are supported (all asics). |
| 162 | */ |
Luca Tettamanti | fd64ca8 | 2012-08-16 11:11:18 -0400 | [diff] [blame] | 163 | static void radeon_atif_parse_notification(struct radeon_atif_notifications *n, u32 mask) |
| 164 | { |
| 165 | n->display_switch = mask & ATIF_DISPLAY_SWITCH_REQUEST_SUPPORTED; |
| 166 | n->expansion_mode_change = mask & ATIF_EXPANSION_MODE_CHANGE_REQUEST_SUPPORTED; |
| 167 | n->thermal_state = mask & ATIF_THERMAL_STATE_CHANGE_REQUEST_SUPPORTED; |
| 168 | n->forced_power_state = mask & ATIF_FORCED_POWER_STATE_CHANGE_REQUEST_SUPPORTED; |
| 169 | n->system_power_state = mask & ATIF_SYSTEM_POWER_SOURCE_CHANGE_REQUEST_SUPPORTED; |
| 170 | n->display_conf_change = mask & ATIF_DISPLAY_CONF_CHANGE_REQUEST_SUPPORTED; |
| 171 | n->px_gfx_switch = mask & ATIF_PX_GFX_SWITCH_REQUEST_SUPPORTED; |
| 172 | n->brightness_change = mask & ATIF_PANEL_BRIGHTNESS_CHANGE_REQUEST_SUPPORTED; |
| 173 | n->dgpu_display_event = mask & ATIF_DGPU_DISPLAY_EVENT_SUPPORTED; |
| 174 | } |
| 175 | |
Alex Deucher | c3c6516 | 2012-08-02 12:30:49 -0400 | [diff] [blame] | 176 | /** |
| 177 | * radeon_atif_parse_functions - parse supported functions |
| 178 | * |
| 179 | * @f: supported functions struct |
| 180 | * @mask: supported functions mask from ATIF |
| 181 | * |
| 182 | * Use the supported functions mask from ATIF function |
| 183 | * ATIF_FUNCTION_VERIFY_INTERFACE to determine what functions |
| 184 | * are supported (all asics). |
| 185 | */ |
Luca Tettamanti | fd64ca8 | 2012-08-16 11:11:18 -0400 | [diff] [blame] | 186 | static void radeon_atif_parse_functions(struct radeon_atif_functions *f, u32 mask) |
| 187 | { |
| 188 | f->system_params = mask & ATIF_GET_SYSTEM_PARAMETERS_SUPPORTED; |
| 189 | f->sbios_requests = mask & ATIF_GET_SYSTEM_BIOS_REQUESTS_SUPPORTED; |
| 190 | f->select_active_disp = mask & ATIF_SELECT_ACTIVE_DISPLAYS_SUPPORTED; |
| 191 | f->lid_state = mask & ATIF_GET_LID_STATE_SUPPORTED; |
| 192 | f->get_tv_standard = mask & ATIF_GET_TV_STANDARD_FROM_CMOS_SUPPORTED; |
| 193 | f->set_tv_standard = mask & ATIF_SET_TV_STANDARD_IN_CMOS_SUPPORTED; |
| 194 | f->get_panel_expansion_mode = mask & ATIF_GET_PANEL_EXPANSION_MODE_FROM_CMOS_SUPPORTED; |
| 195 | f->set_panel_expansion_mode = mask & ATIF_SET_PANEL_EXPANSION_MODE_IN_CMOS_SUPPORTED; |
| 196 | f->temperature_change = mask & ATIF_TEMPERATURE_CHANGE_NOTIFICATION_SUPPORTED; |
| 197 | f->graphics_device_types = mask & ATIF_GET_GRAPHICS_DEVICE_TYPES_SUPPORTED; |
| 198 | } |
| 199 | |
Alex Deucher | c3c6516 | 2012-08-02 12:30:49 -0400 | [diff] [blame] | 200 | /** |
| 201 | * radeon_atif_verify_interface - verify ATIF |
| 202 | * |
| 203 | * @handle: acpi handle |
| 204 | * @atif: radeon atif struct |
| 205 | * |
| 206 | * Execute the ATIF_FUNCTION_VERIFY_INTERFACE ATIF function |
| 207 | * to initialize ATIF and determine what features are supported |
| 208 | * (all asics). |
| 209 | * returns 0 on success, error on failure. |
| 210 | */ |
Luca Tettamanti | fd64ca8 | 2012-08-16 11:11:18 -0400 | [diff] [blame] | 211 | static int radeon_atif_verify_interface(acpi_handle handle, |
| 212 | struct radeon_atif *atif) |
| 213 | { |
| 214 | union acpi_object *info; |
| 215 | struct atif_verify_interface output; |
| 216 | size_t size; |
| 217 | int err = 0; |
| 218 | |
| 219 | info = radeon_atif_call(handle, ATIF_FUNCTION_VERIFY_INTERFACE, NULL); |
| 220 | if (!info) |
| 221 | return -EIO; |
| 222 | |
| 223 | memset(&output, 0, sizeof(output)); |
| 224 | |
| 225 | size = *(u16 *) info->buffer.pointer; |
| 226 | if (size < 12) { |
Luca Tettamanti | a187193 | 2012-10-03 15:00:19 +0200 | [diff] [blame] | 227 | DRM_INFO("ATIF buffer is too small: %zu\n", size); |
Luca Tettamanti | fd64ca8 | 2012-08-16 11:11:18 -0400 | [diff] [blame] | 228 | err = -EINVAL; |
| 229 | goto out; |
| 230 | } |
| 231 | size = min(sizeof(output), size); |
| 232 | |
| 233 | memcpy(&output, info->buffer.pointer, size); |
| 234 | |
| 235 | /* TODO: check version? */ |
| 236 | DRM_DEBUG_DRIVER("ATIF version %u\n", output.version); |
| 237 | |
| 238 | radeon_atif_parse_notification(&atif->notifications, output.notification_mask); |
| 239 | radeon_atif_parse_functions(&atif->functions, output.function_bits); |
| 240 | |
| 241 | out: |
| 242 | kfree(info); |
| 243 | return err; |
| 244 | } |
| 245 | |
Alex Deucher | c3c6516 | 2012-08-02 12:30:49 -0400 | [diff] [blame] | 246 | /** |
| 247 | * radeon_atif_get_notification_params - determine notify configuration |
| 248 | * |
| 249 | * @handle: acpi handle |
| 250 | * @n: atif notification configuration struct |
| 251 | * |
| 252 | * Execute the ATIF_FUNCTION_GET_SYSTEM_PARAMETERS ATIF function |
| 253 | * to determine if a notifier is used and if so which one |
| 254 | * (all asics). This is either Notify(VGA, 0x81) or Notify(VGA, n) |
| 255 | * where n is specified in the result if a notifier is used. |
| 256 | * Returns 0 on success, error on failure. |
| 257 | */ |
Luca Tettamanti | ce3cf82 | 2012-07-30 21:16:06 +0200 | [diff] [blame] | 258 | static int radeon_atif_get_notification_params(acpi_handle handle, |
| 259 | struct radeon_atif_notification_cfg *n) |
| 260 | { |
| 261 | union acpi_object *info; |
| 262 | struct atif_system_params params; |
| 263 | size_t size; |
| 264 | int err = 0; |
| 265 | |
| 266 | info = radeon_atif_call(handle, ATIF_FUNCTION_GET_SYSTEM_PARAMETERS, NULL); |
| 267 | if (!info) { |
| 268 | err = -EIO; |
| 269 | goto out; |
| 270 | } |
| 271 | |
| 272 | size = *(u16 *) info->buffer.pointer; |
| 273 | if (size < 10) { |
| 274 | err = -EINVAL; |
| 275 | goto out; |
| 276 | } |
| 277 | |
| 278 | memset(¶ms, 0, sizeof(params)); |
| 279 | size = min(sizeof(params), size); |
| 280 | memcpy(¶ms, info->buffer.pointer, size); |
| 281 | |
Luca Tettamanti | fda4b25 | 2012-07-30 21:20:35 +0200 | [diff] [blame] | 282 | DRM_DEBUG_DRIVER("SYSTEM_PARAMS: mask = %#x, flags = %#x\n", |
| 283 | params.flags, params.valid_mask); |
Luca Tettamanti | ce3cf82 | 2012-07-30 21:16:06 +0200 | [diff] [blame] | 284 | params.flags = params.flags & params.valid_mask; |
| 285 | |
| 286 | if ((params.flags & ATIF_NOTIFY_MASK) == ATIF_NOTIFY_NONE) { |
| 287 | n->enabled = false; |
| 288 | n->command_code = 0; |
| 289 | } else if ((params.flags & ATIF_NOTIFY_MASK) == ATIF_NOTIFY_81) { |
| 290 | n->enabled = true; |
| 291 | n->command_code = 0x81; |
| 292 | } else { |
| 293 | if (size < 11) { |
| 294 | err = -EINVAL; |
| 295 | goto out; |
| 296 | } |
| 297 | n->enabled = true; |
| 298 | n->command_code = params.command_code; |
| 299 | } |
| 300 | |
| 301 | out: |
Luca Tettamanti | fda4b25 | 2012-07-30 21:20:35 +0200 | [diff] [blame] | 302 | DRM_DEBUG_DRIVER("Notification %s, command code = %#x\n", |
| 303 | (n->enabled ? "enabled" : "disabled"), |
| 304 | n->command_code); |
Luca Tettamanti | ce3cf82 | 2012-07-30 21:16:06 +0200 | [diff] [blame] | 305 | kfree(info); |
| 306 | return err; |
| 307 | } |
| 308 | |
Alex Deucher | c3c6516 | 2012-08-02 12:30:49 -0400 | [diff] [blame] | 309 | /** |
| 310 | * radeon_atif_get_sbios_requests - get requested sbios event |
| 311 | * |
| 312 | * @handle: acpi handle |
| 313 | * @req: atif sbios request struct |
| 314 | * |
| 315 | * Execute the ATIF_FUNCTION_GET_SYSTEM_BIOS_REQUESTS ATIF function |
| 316 | * to determine what requests the sbios is making to the driver |
| 317 | * (all asics). |
| 318 | * Returns 0 on success, error on failure. |
| 319 | */ |
Luca Tettamanti | fda4b25 | 2012-07-30 21:20:35 +0200 | [diff] [blame] | 320 | static int radeon_atif_get_sbios_requests(acpi_handle handle, |
| 321 | struct atif_sbios_requests *req) |
| 322 | { |
| 323 | union acpi_object *info; |
| 324 | size_t size; |
| 325 | int count = 0; |
| 326 | |
| 327 | info = radeon_atif_call(handle, ATIF_FUNCTION_GET_SYSTEM_BIOS_REQUESTS, NULL); |
| 328 | if (!info) |
| 329 | return -EIO; |
| 330 | |
| 331 | size = *(u16 *)info->buffer.pointer; |
| 332 | if (size < 0xd) { |
| 333 | count = -EINVAL; |
| 334 | goto out; |
| 335 | } |
| 336 | memset(req, 0, sizeof(*req)); |
| 337 | |
| 338 | size = min(sizeof(*req), size); |
| 339 | memcpy(req, info->buffer.pointer, size); |
| 340 | DRM_DEBUG_DRIVER("SBIOS pending requests: %#x\n", req->pending); |
| 341 | |
| 342 | count = hweight32(req->pending); |
| 343 | |
| 344 | out: |
| 345 | kfree(info); |
| 346 | return count; |
| 347 | } |
| 348 | |
Alex Deucher | c3c6516 | 2012-08-02 12:30:49 -0400 | [diff] [blame] | 349 | /** |
| 350 | * radeon_atif_handler - handle ATIF notify requests |
| 351 | * |
| 352 | * @rdev: radeon_device pointer |
| 353 | * @event: atif sbios request struct |
| 354 | * |
| 355 | * Checks the acpi event and if it matches an atif event, |
| 356 | * handles it. |
| 357 | * Returns NOTIFY code |
| 358 | */ |
Luca Tettamanti | fda4b25 | 2012-07-30 21:20:35 +0200 | [diff] [blame] | 359 | int radeon_atif_handler(struct radeon_device *rdev, |
| 360 | struct acpi_bus_event *event) |
| 361 | { |
| 362 | struct radeon_atif *atif = &rdev->atif; |
| 363 | struct atif_sbios_requests req; |
| 364 | acpi_handle handle; |
| 365 | int count; |
| 366 | |
| 367 | DRM_DEBUG_DRIVER("event, device_class = %s, type = %#x\n", |
| 368 | event->device_class, event->type); |
| 369 | |
| 370 | if (strcmp(event->device_class, ACPI_VIDEO_CLASS) != 0) |
| 371 | return NOTIFY_DONE; |
| 372 | |
| 373 | if (!atif->notification_cfg.enabled || |
| 374 | event->type != atif->notification_cfg.command_code) |
| 375 | /* Not our event */ |
| 376 | return NOTIFY_DONE; |
| 377 | |
| 378 | /* Check pending SBIOS requests */ |
| 379 | handle = DEVICE_ACPI_HANDLE(&rdev->pdev->dev); |
| 380 | count = radeon_atif_get_sbios_requests(handle, &req); |
| 381 | |
| 382 | if (count <= 0) |
| 383 | return NOTIFY_DONE; |
| 384 | |
| 385 | DRM_DEBUG_DRIVER("ATIF: %d pending SBIOS requests\n", count); |
| 386 | |
| 387 | if (req.pending & ATIF_PANEL_BRIGHTNESS_CHANGE_REQUEST) { |
Alex Deucher | 37e9b6a | 2012-08-03 11:39:43 -0400 | [diff] [blame] | 388 | struct radeon_encoder *enc = atif->encoder_for_bl; |
Luca Tettamanti | fda4b25 | 2012-07-30 21:20:35 +0200 | [diff] [blame] | 389 | |
| 390 | if (enc) { |
Luca Tettamanti | fda4b25 | 2012-07-30 21:20:35 +0200 | [diff] [blame] | 391 | DRM_DEBUG_DRIVER("Changing brightness to %d\n", |
| 392 | req.backlight_level); |
| 393 | |
Alex Deucher | 37e9b6a | 2012-08-03 11:39:43 -0400 | [diff] [blame] | 394 | radeon_set_backlight_level(rdev, enc, req.backlight_level); |
Luca Tettamanti | fda4b25 | 2012-07-30 21:20:35 +0200 | [diff] [blame] | 395 | |
Alex Deucher | cd23492 | 2012-10-04 09:10:10 -0400 | [diff] [blame] | 396 | #if defined(CONFIG_BACKLIGHT_CLASS_DEVICE) || defined(CONFIG_BACKLIGHT_CLASS_DEVICE_MODULE) |
Alex Deucher | 37e9b6a | 2012-08-03 11:39:43 -0400 | [diff] [blame] | 397 | if (rdev->is_atom_bios) { |
| 398 | struct radeon_encoder_atom_dig *dig = enc->enc_priv; |
| 399 | backlight_force_update(dig->bl_dev, |
| 400 | BACKLIGHT_UPDATE_HOTKEY); |
| 401 | } else { |
| 402 | struct radeon_encoder_lvds *dig = enc->enc_priv; |
| 403 | backlight_force_update(dig->bl_dev, |
| 404 | BACKLIGHT_UPDATE_HOTKEY); |
| 405 | } |
Alex Deucher | cd23492 | 2012-10-04 09:10:10 -0400 | [diff] [blame] | 406 | #endif |
Luca Tettamanti | fda4b25 | 2012-07-30 21:20:35 +0200 | [diff] [blame] | 407 | } |
| 408 | } |
| 409 | /* TODO: check other events */ |
| 410 | |
Luca Tettamanti | 92fdf89 | 2012-08-02 11:39:38 -0400 | [diff] [blame] | 411 | /* We've handled the event, stop the notifier chain. The ACPI interface |
| 412 | * overloads ACPI_VIDEO_NOTIFY_PROBE, we don't want to send that to |
| 413 | * userspace if the event was generated only to signal a SBIOS |
| 414 | * request. |
| 415 | */ |
| 416 | return NOTIFY_BAD; |
Luca Tettamanti | fda4b25 | 2012-07-30 21:20:35 +0200 | [diff] [blame] | 417 | } |
| 418 | |
Alex Deucher | e3a1592 | 2012-08-16 11:13:43 -0400 | [diff] [blame] | 419 | /* Call the ATCS method |
| 420 | */ |
| 421 | /** |
| 422 | * radeon_atcs_call - call an ATCS method |
| 423 | * |
| 424 | * @handle: acpi handle |
| 425 | * @function: the ATCS function to execute |
| 426 | * @params: ATCS function params |
| 427 | * |
| 428 | * Executes the requested ATCS function (all asics). |
| 429 | * Returns a pointer to the acpi output buffer. |
| 430 | */ |
| 431 | static union acpi_object *radeon_atcs_call(acpi_handle handle, int function, |
| 432 | struct acpi_buffer *params) |
| 433 | { |
| 434 | acpi_status status; |
| 435 | union acpi_object atcs_arg_elements[2]; |
| 436 | struct acpi_object_list atcs_arg; |
| 437 | struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL }; |
| 438 | |
| 439 | atcs_arg.count = 2; |
| 440 | atcs_arg.pointer = &atcs_arg_elements[0]; |
| 441 | |
| 442 | atcs_arg_elements[0].type = ACPI_TYPE_INTEGER; |
| 443 | atcs_arg_elements[0].integer.value = function; |
| 444 | |
| 445 | if (params) { |
| 446 | atcs_arg_elements[1].type = ACPI_TYPE_BUFFER; |
| 447 | atcs_arg_elements[1].buffer.length = params->length; |
| 448 | atcs_arg_elements[1].buffer.pointer = params->pointer; |
| 449 | } else { |
| 450 | /* We need a second fake parameter */ |
| 451 | atcs_arg_elements[1].type = ACPI_TYPE_INTEGER; |
| 452 | atcs_arg_elements[1].integer.value = 0; |
| 453 | } |
| 454 | |
| 455 | status = acpi_evaluate_object(handle, "ATCS", &atcs_arg, &buffer); |
| 456 | |
| 457 | /* Fail only if calling the method fails and ATIF is supported */ |
| 458 | if (ACPI_FAILURE(status) && status != AE_NOT_FOUND) { |
| 459 | DRM_DEBUG_DRIVER("failed to evaluate ATCS got %s\n", |
| 460 | acpi_format_exception(status)); |
| 461 | kfree(buffer.pointer); |
| 462 | return NULL; |
| 463 | } |
| 464 | |
| 465 | return buffer.pointer; |
| 466 | } |
| 467 | |
| 468 | /** |
| 469 | * radeon_atcs_parse_functions - parse supported functions |
| 470 | * |
| 471 | * @f: supported functions struct |
| 472 | * @mask: supported functions mask from ATCS |
| 473 | * |
| 474 | * Use the supported functions mask from ATCS function |
| 475 | * ATCS_FUNCTION_VERIFY_INTERFACE to determine what functions |
| 476 | * are supported (all asics). |
| 477 | */ |
| 478 | static void radeon_atcs_parse_functions(struct radeon_atcs_functions *f, u32 mask) |
| 479 | { |
| 480 | f->get_ext_state = mask & ATCS_GET_EXTERNAL_STATE_SUPPORTED; |
| 481 | f->pcie_perf_req = mask & ATCS_PCIE_PERFORMANCE_REQUEST_SUPPORTED; |
| 482 | f->pcie_dev_rdy = mask & ATCS_PCIE_DEVICE_READY_NOTIFICATION_SUPPORTED; |
| 483 | f->pcie_bus_width = mask & ATCS_SET_PCIE_BUS_WIDTH_SUPPORTED; |
| 484 | } |
| 485 | |
| 486 | /** |
| 487 | * radeon_atcs_verify_interface - verify ATCS |
| 488 | * |
| 489 | * @handle: acpi handle |
| 490 | * @atcs: radeon atcs struct |
| 491 | * |
| 492 | * Execute the ATCS_FUNCTION_VERIFY_INTERFACE ATCS function |
| 493 | * to initialize ATCS and determine what features are supported |
| 494 | * (all asics). |
| 495 | * returns 0 on success, error on failure. |
| 496 | */ |
| 497 | static int radeon_atcs_verify_interface(acpi_handle handle, |
| 498 | struct radeon_atcs *atcs) |
| 499 | { |
| 500 | union acpi_object *info; |
| 501 | struct atcs_verify_interface output; |
| 502 | size_t size; |
| 503 | int err = 0; |
| 504 | |
| 505 | info = radeon_atcs_call(handle, ATCS_FUNCTION_VERIFY_INTERFACE, NULL); |
| 506 | if (!info) |
| 507 | return -EIO; |
| 508 | |
| 509 | memset(&output, 0, sizeof(output)); |
| 510 | |
| 511 | size = *(u16 *) info->buffer.pointer; |
| 512 | if (size < 8) { |
Luca Tettamanti | a187193 | 2012-10-03 15:00:19 +0200 | [diff] [blame] | 513 | DRM_INFO("ATCS buffer is too small: %zu\n", size); |
Alex Deucher | e3a1592 | 2012-08-16 11:13:43 -0400 | [diff] [blame] | 514 | err = -EINVAL; |
| 515 | goto out; |
| 516 | } |
| 517 | size = min(sizeof(output), size); |
| 518 | |
| 519 | memcpy(&output, info->buffer.pointer, size); |
| 520 | |
| 521 | /* TODO: check version? */ |
| 522 | DRM_DEBUG_DRIVER("ATCS version %u\n", output.version); |
| 523 | |
| 524 | radeon_atcs_parse_functions(&atcs->functions, output.function_bits); |
| 525 | |
| 526 | out: |
| 527 | kfree(info); |
| 528 | return err; |
| 529 | } |
| 530 | |
Alex Deucher | c3c6516 | 2012-08-02 12:30:49 -0400 | [diff] [blame] | 531 | /** |
| 532 | * radeon_acpi_event - handle notify events |
| 533 | * |
| 534 | * @nb: notifier block |
| 535 | * @val: val |
| 536 | * @data: acpi event |
| 537 | * |
| 538 | * Calls relevant radeon functions in response to various |
| 539 | * acpi events. |
| 540 | * Returns NOTIFY code |
| 541 | */ |
Alex Deucher | c491707 | 2012-07-31 17:14:35 -0400 | [diff] [blame] | 542 | static int radeon_acpi_event(struct notifier_block *nb, |
| 543 | unsigned long val, |
| 544 | void *data) |
| 545 | { |
| 546 | struct radeon_device *rdev = container_of(nb, struct radeon_device, acpi_nb); |
| 547 | struct acpi_bus_event *entry = (struct acpi_bus_event *)data; |
| 548 | |
| 549 | if (strcmp(entry->device_class, ACPI_AC_CLASS) == 0) { |
| 550 | if (power_supply_is_system_supplied() > 0) |
| 551 | DRM_DEBUG_DRIVER("pm: AC\n"); |
| 552 | else |
| 553 | DRM_DEBUG_DRIVER("pm: DC\n"); |
| 554 | |
| 555 | radeon_pm_acpi_event_handler(rdev); |
| 556 | } |
| 557 | |
| 558 | /* Check for pending SBIOS requests */ |
| 559 | return radeon_atif_handler(rdev, entry); |
Alberto Milone | d7a2952 | 2010-07-06 11:40:24 -0400 | [diff] [blame] | 560 | } |
| 561 | |
| 562 | /* Call all ACPI methods here */ |
Alex Deucher | c3c6516 | 2012-08-02 12:30:49 -0400 | [diff] [blame] | 563 | /** |
| 564 | * radeon_acpi_init - init driver acpi support |
| 565 | * |
| 566 | * @rdev: radeon_device pointer |
| 567 | * |
| 568 | * Verifies the AMD ACPI interfaces and registers with the acpi |
| 569 | * notifier chain (all asics). |
| 570 | * Returns 0 on success, error on failure. |
| 571 | */ |
Alberto Milone | d7a2952 | 2010-07-06 11:40:24 -0400 | [diff] [blame] | 572 | int radeon_acpi_init(struct radeon_device *rdev) |
| 573 | { |
| 574 | acpi_handle handle; |
Luca Tettamanti | ce3cf82 | 2012-07-30 21:16:06 +0200 | [diff] [blame] | 575 | struct radeon_atif *atif = &rdev->atif; |
Alex Deucher | e3a1592 | 2012-08-16 11:13:43 -0400 | [diff] [blame] | 576 | struct radeon_atcs *atcs = &rdev->atcs; |
Alberto Milone | d7a2952 | 2010-07-06 11:40:24 -0400 | [diff] [blame] | 577 | int ret; |
| 578 | |
Alberto Milone | d7a2952 | 2010-07-06 11:40:24 -0400 | [diff] [blame] | 579 | /* Get the device handle */ |
| 580 | handle = DEVICE_ACPI_HANDLE(&rdev->pdev->dev); |
| 581 | |
Jean Delvare | 48cc9b2 | 2011-11-30 17:36:39 +0100 | [diff] [blame] | 582 | /* No need to proceed if we're sure that ATIF is not supported */ |
| 583 | if (!ASIC_IS_AVIVO(rdev) || !rdev->bios || !handle) |
| 584 | return 0; |
| 585 | |
Alex Deucher | e3a1592 | 2012-08-16 11:13:43 -0400 | [diff] [blame] | 586 | /* Call the ATCS method */ |
| 587 | ret = radeon_atcs_verify_interface(handle, atcs); |
| 588 | if (ret) { |
| 589 | DRM_DEBUG_DRIVER("Call to ATCS verify_interface failed: %d\n", ret); |
| 590 | } |
Alberto Milone | d7a2952 | 2010-07-06 11:40:24 -0400 | [diff] [blame] | 591 | |
Alberto Milone | d7a2952 | 2010-07-06 11:40:24 -0400 | [diff] [blame] | 592 | /* Call the ATIF method */ |
Luca Tettamanti | ce3cf82 | 2012-07-30 21:16:06 +0200 | [diff] [blame] | 593 | ret = radeon_atif_verify_interface(handle, atif); |
| 594 | if (ret) { |
Alex Deucher | e3a1592 | 2012-08-16 11:13:43 -0400 | [diff] [blame] | 595 | DRM_DEBUG_DRIVER("Call to ATIF verify_interface failed: %d\n", ret); |
Luca Tettamanti | ce3cf82 | 2012-07-30 21:16:06 +0200 | [diff] [blame] | 596 | goto out; |
| 597 | } |
Alberto Milone | d7a2952 | 2010-07-06 11:40:24 -0400 | [diff] [blame] | 598 | |
Luca Tettamanti | fda4b25 | 2012-07-30 21:20:35 +0200 | [diff] [blame] | 599 | if (atif->notifications.brightness_change) { |
| 600 | struct drm_encoder *tmp; |
| 601 | struct radeon_encoder *target = NULL; |
| 602 | |
| 603 | /* Find the encoder controlling the brightness */ |
| 604 | list_for_each_entry(tmp, &rdev->ddev->mode_config.encoder_list, |
| 605 | head) { |
| 606 | struct radeon_encoder *enc = to_radeon_encoder(tmp); |
Luca Tettamanti | fda4b25 | 2012-07-30 21:20:35 +0200 | [diff] [blame] | 607 | |
| 608 | if ((enc->devices & (ATOM_DEVICE_LCD_SUPPORT)) && |
Alex Deucher | 37e9b6a | 2012-08-03 11:39:43 -0400 | [diff] [blame] | 609 | enc->enc_priv) { |
| 610 | if (rdev->is_atom_bios) { |
| 611 | struct radeon_encoder_atom_dig *dig = enc->enc_priv; |
| 612 | if (dig->bl_dev) { |
| 613 | target = enc; |
| 614 | break; |
| 615 | } |
| 616 | } else { |
| 617 | struct radeon_encoder_lvds *dig = enc->enc_priv; |
| 618 | if (dig->bl_dev) { |
| 619 | target = enc; |
| 620 | break; |
| 621 | } |
| 622 | } |
Luca Tettamanti | fda4b25 | 2012-07-30 21:20:35 +0200 | [diff] [blame] | 623 | } |
| 624 | } |
| 625 | |
Alex Deucher | 37e9b6a | 2012-08-03 11:39:43 -0400 | [diff] [blame] | 626 | atif->encoder_for_bl = target; |
Luca Tettamanti | fda4b25 | 2012-07-30 21:20:35 +0200 | [diff] [blame] | 627 | if (!target) { |
| 628 | /* Brightness change notification is enabled, but we |
| 629 | * didn't find a backlight controller, this should |
| 630 | * never happen. |
| 631 | */ |
| 632 | DRM_ERROR("Cannot find a backlight controller\n"); |
| 633 | } |
| 634 | } |
| 635 | |
Luca Tettamanti | ce3cf82 | 2012-07-30 21:16:06 +0200 | [diff] [blame] | 636 | if (atif->functions.sbios_requests && !atif->functions.system_params) { |
| 637 | /* XXX check this workraround, if sbios request function is |
| 638 | * present we have to see how it's configured in the system |
| 639 | * params |
| 640 | */ |
| 641 | atif->functions.system_params = true; |
| 642 | } |
| 643 | |
| 644 | if (atif->functions.system_params) { |
| 645 | ret = radeon_atif_get_notification_params(handle, |
| 646 | &atif->notification_cfg); |
| 647 | if (ret) { |
| 648 | DRM_DEBUG_DRIVER("Call to GET_SYSTEM_PARAMS failed: %d\n", |
| 649 | ret); |
| 650 | /* Disable notification */ |
| 651 | atif->notification_cfg.enabled = false; |
| 652 | } |
| 653 | } |
| 654 | |
| 655 | out: |
Alex Deucher | c491707 | 2012-07-31 17:14:35 -0400 | [diff] [blame] | 656 | rdev->acpi_nb.notifier_call = radeon_acpi_event; |
| 657 | register_acpi_notifier(&rdev->acpi_nb); |
| 658 | |
Luca Tettamanti | 8650467 | 2012-07-29 17:04:43 +0200 | [diff] [blame] | 659 | return ret; |
Alberto Milone | d7a2952 | 2010-07-06 11:40:24 -0400 | [diff] [blame] | 660 | } |
| 661 | |
Alex Deucher | c3c6516 | 2012-08-02 12:30:49 -0400 | [diff] [blame] | 662 | /** |
| 663 | * radeon_acpi_fini - tear down driver acpi support |
| 664 | * |
| 665 | * @rdev: radeon_device pointer |
| 666 | * |
| 667 | * Unregisters with the acpi notifier chain (all asics). |
| 668 | */ |
Alex Deucher | c491707 | 2012-07-31 17:14:35 -0400 | [diff] [blame] | 669 | void radeon_acpi_fini(struct radeon_device *rdev) |
| 670 | { |
| 671 | unregister_acpi_notifier(&rdev->acpi_nb); |
| 672 | } |