radeon_acpi.c 18 KB

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