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 "drmP.h"
  31. #include "drm.h"
  32. #include "drm_sarea.h"
  33. #include "drm_crtc_helper.h"
  34. #include "radeon.h"
  35. #include "radeon_acpi.h"
  36. #include "atom.h"
  37. #include <linux/vga_switcheroo.h>
  38. #define ACPI_AC_CLASS "ac_adapter"
  39. extern void radeon_pm_acpi_event_handler(struct radeon_device *rdev);
  40. struct atif_verify_interface {
  41. u16 size; /* structure size in bytes (includes size field) */
  42. u16 version; /* version */
  43. u32 notification_mask; /* supported notifications mask */
  44. u32 function_bits; /* supported functions bit vector */
  45. } __packed;
  46. struct atif_system_params {
  47. u16 size; /* structure size in bytes (includes size field) */
  48. u32 valid_mask; /* valid flags mask */
  49. u32 flags; /* flags */
  50. u8 command_code; /* notify command code */
  51. } __packed;
  52. struct atif_sbios_requests {
  53. u16 size; /* structure size in bytes (includes size field) */
  54. u32 pending; /* pending sbios requests */
  55. u8 panel_exp_mode; /* panel expansion mode */
  56. u8 thermal_gfx; /* thermal state: target gfx controller */
  57. u8 thermal_state; /* thermal state: state id (0: exit state, non-0: state) */
  58. u8 forced_power_gfx; /* forced power state: target gfx controller */
  59. u8 forced_power_state; /* forced power state: state id */
  60. u8 system_power_src; /* system power source */
  61. u8 backlight_level; /* panel backlight level (0-255) */
  62. } __packed;
  63. #define ATIF_NOTIFY_MASK 0x3
  64. #define ATIF_NOTIFY_NONE 0
  65. #define ATIF_NOTIFY_81 1
  66. #define ATIF_NOTIFY_N 2
  67. struct atcs_verify_interface {
  68. u16 size; /* structure size in bytes (includes size field) */
  69. u16 version; /* version */
  70. u32 function_bits; /* supported functions bit vector */
  71. } __packed;
  72. /* Call the ATIF method
  73. */
  74. /**
  75. * radeon_atif_call - call an ATIF method
  76. *
  77. * @handle: acpi handle
  78. * @function: the ATIF function to execute
  79. * @params: ATIF function params
  80. *
  81. * Executes the requested ATIF function (all asics).
  82. * Returns a pointer to the acpi output buffer.
  83. */
  84. static union acpi_object *radeon_atif_call(acpi_handle handle, int function,
  85. struct acpi_buffer *params)
  86. {
  87. acpi_status status;
  88. union acpi_object atif_arg_elements[2];
  89. struct acpi_object_list atif_arg;
  90. struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
  91. atif_arg.count = 2;
  92. atif_arg.pointer = &atif_arg_elements[0];
  93. atif_arg_elements[0].type = ACPI_TYPE_INTEGER;
  94. atif_arg_elements[0].integer.value = function;
  95. if (params) {
  96. atif_arg_elements[1].type = ACPI_TYPE_BUFFER;
  97. atif_arg_elements[1].buffer.length = params->length;
  98. atif_arg_elements[1].buffer.pointer = params->pointer;
  99. } else {
  100. /* We need a second fake parameter */
  101. atif_arg_elements[1].type = ACPI_TYPE_INTEGER;
  102. atif_arg_elements[1].integer.value = 0;
  103. }
  104. status = acpi_evaluate_object(handle, "ATIF", &atif_arg, &buffer);
  105. /* Fail only if calling the method fails and ATIF is supported */
  106. if (ACPI_FAILURE(status) && status != AE_NOT_FOUND) {
  107. DRM_DEBUG_DRIVER("failed to evaluate ATIF got %s\n",
  108. acpi_format_exception(status));
  109. kfree(buffer.pointer);
  110. return NULL;
  111. }
  112. return buffer.pointer;
  113. }
  114. /**
  115. * radeon_atif_parse_notification - parse supported notifications
  116. *
  117. * @n: supported notifications struct
  118. * @mask: supported notifications mask from ATIF
  119. *
  120. * Use the supported notifications mask from ATIF function
  121. * ATIF_FUNCTION_VERIFY_INTERFACE to determine what notifications
  122. * are supported (all asics).
  123. */
  124. static void radeon_atif_parse_notification(struct radeon_atif_notifications *n, u32 mask)
  125. {
  126. n->display_switch = mask & ATIF_DISPLAY_SWITCH_REQUEST_SUPPORTED;
  127. n->expansion_mode_change = mask & ATIF_EXPANSION_MODE_CHANGE_REQUEST_SUPPORTED;
  128. n->thermal_state = mask & ATIF_THERMAL_STATE_CHANGE_REQUEST_SUPPORTED;
  129. n->forced_power_state = mask & ATIF_FORCED_POWER_STATE_CHANGE_REQUEST_SUPPORTED;
  130. n->system_power_state = mask & ATIF_SYSTEM_POWER_SOURCE_CHANGE_REQUEST_SUPPORTED;
  131. n->display_conf_change = mask & ATIF_DISPLAY_CONF_CHANGE_REQUEST_SUPPORTED;
  132. n->px_gfx_switch = mask & ATIF_PX_GFX_SWITCH_REQUEST_SUPPORTED;
  133. n->brightness_change = mask & ATIF_PANEL_BRIGHTNESS_CHANGE_REQUEST_SUPPORTED;
  134. n->dgpu_display_event = mask & ATIF_DGPU_DISPLAY_EVENT_SUPPORTED;
  135. }
  136. /**
  137. * radeon_atif_parse_functions - parse supported functions
  138. *
  139. * @f: supported functions struct
  140. * @mask: supported functions mask from ATIF
  141. *
  142. * Use the supported functions mask from ATIF function
  143. * ATIF_FUNCTION_VERIFY_INTERFACE to determine what functions
  144. * are supported (all asics).
  145. */
  146. static void radeon_atif_parse_functions(struct radeon_atif_functions *f, u32 mask)
  147. {
  148. f->system_params = mask & ATIF_GET_SYSTEM_PARAMETERS_SUPPORTED;
  149. f->sbios_requests = mask & ATIF_GET_SYSTEM_BIOS_REQUESTS_SUPPORTED;
  150. f->select_active_disp = mask & ATIF_SELECT_ACTIVE_DISPLAYS_SUPPORTED;
  151. f->lid_state = mask & ATIF_GET_LID_STATE_SUPPORTED;
  152. f->get_tv_standard = mask & ATIF_GET_TV_STANDARD_FROM_CMOS_SUPPORTED;
  153. f->set_tv_standard = mask & ATIF_SET_TV_STANDARD_IN_CMOS_SUPPORTED;
  154. f->get_panel_expansion_mode = mask & ATIF_GET_PANEL_EXPANSION_MODE_FROM_CMOS_SUPPORTED;
  155. f->set_panel_expansion_mode = mask & ATIF_SET_PANEL_EXPANSION_MODE_IN_CMOS_SUPPORTED;
  156. f->temperature_change = mask & ATIF_TEMPERATURE_CHANGE_NOTIFICATION_SUPPORTED;
  157. f->graphics_device_types = mask & ATIF_GET_GRAPHICS_DEVICE_TYPES_SUPPORTED;
  158. }
  159. /**
  160. * radeon_atif_verify_interface - verify ATIF
  161. *
  162. * @handle: acpi handle
  163. * @atif: radeon atif struct
  164. *
  165. * Execute the ATIF_FUNCTION_VERIFY_INTERFACE ATIF function
  166. * to initialize ATIF and determine what features are supported
  167. * (all asics).
  168. * returns 0 on success, error on failure.
  169. */
  170. static int radeon_atif_verify_interface(acpi_handle handle,
  171. struct radeon_atif *atif)
  172. {
  173. union acpi_object *info;
  174. struct atif_verify_interface output;
  175. size_t size;
  176. int err = 0;
  177. info = radeon_atif_call(handle, ATIF_FUNCTION_VERIFY_INTERFACE, NULL);
  178. if (!info)
  179. return -EIO;
  180. memset(&output, 0, sizeof(output));
  181. size = *(u16 *) info->buffer.pointer;
  182. if (size < 12) {
  183. DRM_INFO("ATIF buffer is too small: %lu\n", size);
  184. err = -EINVAL;
  185. goto out;
  186. }
  187. size = min(sizeof(output), size);
  188. memcpy(&output, info->buffer.pointer, size);
  189. /* TODO: check version? */
  190. DRM_DEBUG_DRIVER("ATIF version %u\n", output.version);
  191. radeon_atif_parse_notification(&atif->notifications, output.notification_mask);
  192. radeon_atif_parse_functions(&atif->functions, output.function_bits);
  193. out:
  194. kfree(info);
  195. return err;
  196. }
  197. /**
  198. * radeon_atif_get_notification_params - determine notify configuration
  199. *
  200. * @handle: acpi handle
  201. * @n: atif notification configuration struct
  202. *
  203. * Execute the ATIF_FUNCTION_GET_SYSTEM_PARAMETERS ATIF function
  204. * to determine if a notifier is used and if so which one
  205. * (all asics). This is either Notify(VGA, 0x81) or Notify(VGA, n)
  206. * where n is specified in the result if a notifier is used.
  207. * Returns 0 on success, error on failure.
  208. */
  209. static int radeon_atif_get_notification_params(acpi_handle handle,
  210. struct radeon_atif_notification_cfg *n)
  211. {
  212. union acpi_object *info;
  213. struct atif_system_params params;
  214. size_t size;
  215. int err = 0;
  216. info = radeon_atif_call(handle, ATIF_FUNCTION_GET_SYSTEM_PARAMETERS, NULL);
  217. if (!info) {
  218. err = -EIO;
  219. goto out;
  220. }
  221. size = *(u16 *) info->buffer.pointer;
  222. if (size < 10) {
  223. err = -EINVAL;
  224. goto out;
  225. }
  226. memset(&params, 0, sizeof(params));
  227. size = min(sizeof(params), size);
  228. memcpy(&params, info->buffer.pointer, size);
  229. DRM_DEBUG_DRIVER("SYSTEM_PARAMS: mask = %#x, flags = %#x\n",
  230. params.flags, params.valid_mask);
  231. params.flags = params.flags & params.valid_mask;
  232. if ((params.flags & ATIF_NOTIFY_MASK) == ATIF_NOTIFY_NONE) {
  233. n->enabled = false;
  234. n->command_code = 0;
  235. } else if ((params.flags & ATIF_NOTIFY_MASK) == ATIF_NOTIFY_81) {
  236. n->enabled = true;
  237. n->command_code = 0x81;
  238. } else {
  239. if (size < 11) {
  240. err = -EINVAL;
  241. goto out;
  242. }
  243. n->enabled = true;
  244. n->command_code = params.command_code;
  245. }
  246. out:
  247. DRM_DEBUG_DRIVER("Notification %s, command code = %#x\n",
  248. (n->enabled ? "enabled" : "disabled"),
  249. n->command_code);
  250. kfree(info);
  251. return err;
  252. }
  253. /**
  254. * radeon_atif_get_sbios_requests - get requested sbios event
  255. *
  256. * @handle: acpi handle
  257. * @req: atif sbios request struct
  258. *
  259. * Execute the ATIF_FUNCTION_GET_SYSTEM_BIOS_REQUESTS ATIF function
  260. * to determine what requests the sbios is making to the driver
  261. * (all asics).
  262. * Returns 0 on success, error on failure.
  263. */
  264. static int radeon_atif_get_sbios_requests(acpi_handle handle,
  265. struct atif_sbios_requests *req)
  266. {
  267. union acpi_object *info;
  268. size_t size;
  269. int count = 0;
  270. info = radeon_atif_call(handle, ATIF_FUNCTION_GET_SYSTEM_BIOS_REQUESTS, NULL);
  271. if (!info)
  272. return -EIO;
  273. size = *(u16 *)info->buffer.pointer;
  274. if (size < 0xd) {
  275. count = -EINVAL;
  276. goto out;
  277. }
  278. memset(req, 0, sizeof(*req));
  279. size = min(sizeof(*req), size);
  280. memcpy(req, info->buffer.pointer, size);
  281. DRM_DEBUG_DRIVER("SBIOS pending requests: %#x\n", req->pending);
  282. count = hweight32(req->pending);
  283. out:
  284. kfree(info);
  285. return count;
  286. }
  287. /**
  288. * radeon_atif_handler - handle ATIF notify requests
  289. *
  290. * @rdev: radeon_device pointer
  291. * @event: atif sbios request struct
  292. *
  293. * Checks the acpi event and if it matches an atif event,
  294. * handles it.
  295. * Returns NOTIFY code
  296. */
  297. int radeon_atif_handler(struct radeon_device *rdev,
  298. struct acpi_bus_event *event)
  299. {
  300. struct radeon_atif *atif = &rdev->atif;
  301. struct atif_sbios_requests req;
  302. acpi_handle handle;
  303. int count;
  304. DRM_DEBUG_DRIVER("event, device_class = %s, type = %#x\n",
  305. event->device_class, event->type);
  306. if (strcmp(event->device_class, ACPI_VIDEO_CLASS) != 0)
  307. return NOTIFY_DONE;
  308. if (!atif->notification_cfg.enabled ||
  309. event->type != atif->notification_cfg.command_code)
  310. /* Not our event */
  311. return NOTIFY_DONE;
  312. /* Check pending SBIOS requests */
  313. handle = DEVICE_ACPI_HANDLE(&rdev->pdev->dev);
  314. count = radeon_atif_get_sbios_requests(handle, &req);
  315. if (count <= 0)
  316. return NOTIFY_DONE;
  317. DRM_DEBUG_DRIVER("ATIF: %d pending SBIOS requests\n", count);
  318. if (req.pending & ATIF_PANEL_BRIGHTNESS_CHANGE_REQUEST) {
  319. struct radeon_encoder *enc = atif->encoder_for_bl;
  320. if (enc) {
  321. DRM_DEBUG_DRIVER("Changing brightness to %d\n",
  322. req.backlight_level);
  323. radeon_set_backlight_level(rdev, enc, req.backlight_level);
  324. if (rdev->is_atom_bios) {
  325. struct radeon_encoder_atom_dig *dig = enc->enc_priv;
  326. backlight_force_update(dig->bl_dev,
  327. BACKLIGHT_UPDATE_HOTKEY);
  328. } else {
  329. struct radeon_encoder_lvds *dig = enc->enc_priv;
  330. backlight_force_update(dig->bl_dev,
  331. BACKLIGHT_UPDATE_HOTKEY);
  332. }
  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: %lu\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. }