video_detect.c 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. /*
  2. * Copyright (C) 2008 SuSE Linux Products GmbH
  3. * Thomas Renninger <trenn@suse.de>
  4. *
  5. * May be copied or modified under the terms of the GNU General Public License
  6. *
  7. * video_detect.c:
  8. * After PCI devices are glued with ACPI devices
  9. * acpi_get_pci_dev() can be called to identify ACPI graphics
  10. * devices for which a real graphics card is plugged in
  11. *
  12. * Now acpi_video_get_capabilities() can be called to check which
  13. * capabilities the graphics cards plugged in support. The check for general
  14. * video capabilities will be triggered by the first caller of
  15. * acpi_video_get_capabilities(NULL); which will happen when the first
  16. * backlight switching supporting driver calls:
  17. * acpi_video_backlight_support();
  18. *
  19. * Depending on whether ACPI graphics extensions (cmp. ACPI spec Appendix B)
  20. * are available, video.ko should be used to handle the device.
  21. *
  22. * Otherwise vendor specific drivers like thinkpad_acpi, asus-laptop,
  23. * sony_acpi,... can take care about backlight brightness.
  24. *
  25. * If CONFIG_ACPI_VIDEO is neither set as "compiled in" (y) nor as a module (m)
  26. * this file will not be compiled, acpi_video_get_capabilities() and
  27. * acpi_video_backlight_support() will always return 0 and vendor specific
  28. * drivers always can handle backlight.
  29. *
  30. */
  31. #include <linux/export.h>
  32. #include <linux/acpi.h>
  33. #include <linux/dmi.h>
  34. #include <linux/pci.h>
  35. #include "internal.h"
  36. ACPI_MODULE_NAME("video");
  37. #define _COMPONENT ACPI_VIDEO_COMPONENT
  38. static long acpi_video_support;
  39. static bool acpi_video_caps_checked;
  40. static acpi_status
  41. find_video(acpi_handle handle, u32 lvl, void *context, void **rv)
  42. {
  43. long *cap = context;
  44. struct pci_dev *dev;
  45. struct acpi_device *acpi_dev;
  46. static const struct acpi_device_id video_ids[] = {
  47. {ACPI_VIDEO_HID, 0},
  48. {"", 0},
  49. };
  50. if (acpi_bus_get_device(handle, &acpi_dev))
  51. return AE_OK;
  52. if (!acpi_match_device_ids(acpi_dev, video_ids)) {
  53. dev = acpi_get_pci_dev(handle);
  54. if (!dev)
  55. return AE_OK;
  56. pci_dev_put(dev);
  57. *cap |= acpi_is_video_device(handle);
  58. }
  59. return AE_OK;
  60. }
  61. /* Force to use vendor driver when the ACPI device is known to be
  62. * buggy */
  63. static int video_detect_force_vendor(const struct dmi_system_id *d)
  64. {
  65. acpi_video_support |= ACPI_VIDEO_BACKLIGHT_DMI_VENDOR;
  66. return 0;
  67. }
  68. static const struct dmi_system_id video_detect_dmi_table[] = {
  69. /* On Samsung X360, the BIOS will set a flag (VDRV) if generic
  70. * ACPI backlight device is used. This flag will definitively break
  71. * the backlight interface (even the vendor interface) untill next
  72. * reboot. It's why we should prevent video.ko from being used here
  73. * and we can't rely on a later call to acpi_video_unregister().
  74. */
  75. {
  76. .callback = video_detect_force_vendor,
  77. .ident = "X360",
  78. .matches = {
  79. DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD."),
  80. DMI_MATCH(DMI_PRODUCT_NAME, "X360"),
  81. DMI_MATCH(DMI_BOARD_NAME, "X360"),
  82. },
  83. },
  84. {
  85. .callback = video_detect_force_vendor,
  86. .ident = "Asus UL30VT",
  87. .matches = {
  88. DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK Computer Inc."),
  89. DMI_MATCH(DMI_PRODUCT_NAME, "UL30VT"),
  90. },
  91. },
  92. {
  93. .callback = video_detect_force_vendor,
  94. .ident = "Asus UL30A",
  95. .matches = {
  96. DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK Computer Inc."),
  97. DMI_MATCH(DMI_PRODUCT_NAME, "UL30A"),
  98. },
  99. },
  100. {
  101. .callback = video_detect_force_vendor,
  102. .ident = "Dell Inspiron 5737",
  103. .matches = {
  104. DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
  105. DMI_MATCH(DMI_PRODUCT_NAME, "Inspiron 5737"),
  106. },
  107. },
  108. { },
  109. };
  110. /*
  111. * Returns the video capabilities of a specific ACPI graphics device
  112. *
  113. * if NULL is passed as argument all ACPI devices are enumerated and
  114. * all graphics capabilities of physically present devices are
  115. * summarized and returned. This is cached and done only once.
  116. */
  117. static long acpi_video_get_capabilities(acpi_handle graphics_handle)
  118. {
  119. long caps = 0;
  120. struct acpi_device *tmp_dev;
  121. acpi_status status;
  122. if (acpi_video_caps_checked && graphics_handle == NULL)
  123. return acpi_video_support;
  124. if (!graphics_handle) {
  125. /* Only do the global walk through all graphics devices once */
  126. acpi_walk_namespace(ACPI_TYPE_DEVICE, ACPI_ROOT_OBJECT,
  127. ACPI_UINT32_MAX, find_video, NULL,
  128. &caps, NULL);
  129. /* There might be boot param flags set already... */
  130. acpi_video_support |= caps;
  131. acpi_video_caps_checked = 1;
  132. /* Add blacklists here. Be careful to use the right *DMI* bits
  133. * to still be able to override logic via boot params, e.g.:
  134. *
  135. * if (dmi_name_in_vendors("XY")) {
  136. * acpi_video_support |=
  137. * ACPI_VIDEO_BACKLIGHT_DMI_VENDOR;
  138. *}
  139. */
  140. dmi_check_system(video_detect_dmi_table);
  141. } else {
  142. status = acpi_bus_get_device(graphics_handle, &tmp_dev);
  143. if (ACPI_FAILURE(status)) {
  144. ACPI_EXCEPTION((AE_INFO, status, "Invalid device"));
  145. return 0;
  146. }
  147. acpi_walk_namespace(ACPI_TYPE_DEVICE, graphics_handle,
  148. ACPI_UINT32_MAX, find_video, NULL,
  149. &caps, NULL);
  150. }
  151. ACPI_DEBUG_PRINT((ACPI_DB_INFO, "We have 0x%lX video support %s %s\n",
  152. graphics_handle ? caps : acpi_video_support,
  153. graphics_handle ? "on device " : "in general",
  154. graphics_handle ? acpi_device_bid(tmp_dev) : ""));
  155. return caps;
  156. }
  157. static void acpi_video_caps_check(void)
  158. {
  159. /*
  160. * We must check whether the ACPI graphics device is physically plugged
  161. * in. Therefore this must be called after binding PCI and ACPI devices
  162. */
  163. if (!acpi_video_caps_checked)
  164. acpi_video_get_capabilities(NULL);
  165. }
  166. /* Promote the vendor interface instead of the generic video module.
  167. * This function allow DMI blacklists to be implemented by externals
  168. * platform drivers instead of putting a big blacklist in video_detect.c
  169. * After calling this function you will probably want to call
  170. * acpi_video_unregister() to make sure the video module is not loaded
  171. */
  172. void acpi_video_dmi_promote_vendor(void)
  173. {
  174. acpi_video_caps_check();
  175. acpi_video_support |= ACPI_VIDEO_BACKLIGHT_DMI_VENDOR;
  176. }
  177. EXPORT_SYMBOL(acpi_video_dmi_promote_vendor);
  178. /* Returns true if video.ko can do backlight switching */
  179. int acpi_video_backlight_support(void)
  180. {
  181. acpi_video_caps_check();
  182. /* First check for boot param -> highest prio */
  183. if (acpi_video_support & ACPI_VIDEO_BACKLIGHT_FORCE_VENDOR)
  184. return 0;
  185. else if (acpi_video_support & ACPI_VIDEO_BACKLIGHT_FORCE_VIDEO)
  186. return 1;
  187. /* Then check for DMI blacklist -> second highest prio */
  188. if (acpi_video_support & ACPI_VIDEO_BACKLIGHT_DMI_VENDOR)
  189. return 0;
  190. else if (acpi_video_support & ACPI_VIDEO_BACKLIGHT_DMI_VIDEO)
  191. return 1;
  192. /* Then go the default way */
  193. return acpi_video_support & ACPI_VIDEO_BACKLIGHT;
  194. }
  195. EXPORT_SYMBOL(acpi_video_backlight_support);
  196. /*
  197. * Use acpi_backlight=vendor/video to force that backlight switching
  198. * is processed by vendor specific acpi drivers or video.ko driver.
  199. */
  200. static int __init acpi_backlight(char *str)
  201. {
  202. if (str == NULL || *str == '\0')
  203. return 1;
  204. else {
  205. if (!strcmp("vendor", str))
  206. acpi_video_support |=
  207. ACPI_VIDEO_BACKLIGHT_FORCE_VENDOR;
  208. if (!strcmp("video", str))
  209. acpi_video_support |=
  210. ACPI_VIDEO_BACKLIGHT_FORCE_VIDEO;
  211. }
  212. return 1;
  213. }
  214. __setup("acpi_backlight=", acpi_backlight);