radeon_acpi.c 19 KB

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