video_detect.c 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. /*
  2. * Copyright (C) 2015 Red Hat Inc.
  3. * Hans de Goede <hdegoede@redhat.com>
  4. * Copyright (C) 2008 SuSE Linux Products GmbH
  5. * Thomas Renninger <trenn@suse.de>
  6. *
  7. * May be copied or modified under the terms of the GNU General Public License
  8. *
  9. * video_detect.c:
  10. * After PCI devices are glued with ACPI devices
  11. * acpi_get_pci_dev() can be called to identify ACPI graphics
  12. * devices for which a real graphics card is plugged in
  13. *
  14. * Depending on whether ACPI graphics extensions (cmp. ACPI spec Appendix B)
  15. * are available, video.ko should be used to handle the device.
  16. *
  17. * Otherwise vendor specific drivers like thinkpad_acpi, asus-laptop,
  18. * sony_acpi,... can take care about backlight brightness.
  19. *
  20. * Backlight drivers can use acpi_video_get_backlight_type() to determine
  21. * which driver should handle the backlight.
  22. *
  23. * If CONFIG_ACPI_VIDEO is neither set as "compiled in" (y) nor as a module (m)
  24. * this file will not be compiled and acpi_video_get_backlight_type() will
  25. * always return acpi_backlight_vendor.
  26. */
  27. #include <linux/export.h>
  28. #include <linux/acpi.h>
  29. #include <linux/backlight.h>
  30. #include <linux/dmi.h>
  31. #include <linux/module.h>
  32. #include <linux/pci.h>
  33. #include <linux/types.h>
  34. #include <acpi/video.h>
  35. ACPI_MODULE_NAME("video");
  36. #define _COMPONENT ACPI_VIDEO_COMPONENT
  37. static enum acpi_backlight_type acpi_backlight_cmdline = acpi_backlight_undef;
  38. static enum acpi_backlight_type acpi_backlight_dmi = acpi_backlight_undef;
  39. static void acpi_video_parse_cmdline(void)
  40. {
  41. if (!strcmp("vendor", acpi_video_backlight_string))
  42. acpi_backlight_cmdline = acpi_backlight_vendor;
  43. if (!strcmp("video", acpi_video_backlight_string))
  44. acpi_backlight_cmdline = acpi_backlight_video;
  45. if (!strcmp("native", acpi_video_backlight_string))
  46. acpi_backlight_cmdline = acpi_backlight_native;
  47. if (!strcmp("none", acpi_video_backlight_string))
  48. acpi_backlight_cmdline = acpi_backlight_none;
  49. }
  50. static acpi_status
  51. find_video(acpi_handle handle, u32 lvl, void *context, void **rv)
  52. {
  53. long *cap = context;
  54. struct pci_dev *dev;
  55. struct acpi_device *acpi_dev;
  56. static const struct acpi_device_id video_ids[] = {
  57. {ACPI_VIDEO_HID, 0},
  58. {"", 0},
  59. };
  60. if (acpi_bus_get_device(handle, &acpi_dev))
  61. return AE_OK;
  62. if (!acpi_match_device_ids(acpi_dev, video_ids)) {
  63. dev = acpi_get_pci_dev(handle);
  64. if (!dev)
  65. return AE_OK;
  66. pci_dev_put(dev);
  67. *cap |= acpi_is_video_device(handle);
  68. }
  69. return AE_OK;
  70. }
  71. /* Force to use vendor driver when the ACPI device is known to be
  72. * buggy */
  73. static int video_detect_force_vendor(const struct dmi_system_id *d)
  74. {
  75. acpi_backlight_dmi = acpi_backlight_vendor;
  76. return 0;
  77. }
  78. static const struct dmi_system_id video_detect_dmi_table[] = {
  79. /* On Samsung X360, the BIOS will set a flag (VDRV) if generic
  80. * ACPI backlight device is used. This flag will definitively break
  81. * the backlight interface (even the vendor interface) untill next
  82. * reboot. It's why we should prevent video.ko from being used here
  83. * and we can't rely on a later call to acpi_video_unregister().
  84. */
  85. {
  86. .callback = video_detect_force_vendor,
  87. .ident = "X360",
  88. .matches = {
  89. DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD."),
  90. DMI_MATCH(DMI_PRODUCT_NAME, "X360"),
  91. DMI_MATCH(DMI_BOARD_NAME, "X360"),
  92. },
  93. },
  94. {
  95. .callback = video_detect_force_vendor,
  96. .ident = "Asus UL30VT",
  97. .matches = {
  98. DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK Computer Inc."),
  99. DMI_MATCH(DMI_PRODUCT_NAME, "UL30VT"),
  100. },
  101. },
  102. {
  103. .callback = video_detect_force_vendor,
  104. .ident = "Asus UL30A",
  105. .matches = {
  106. DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK Computer Inc."),
  107. DMI_MATCH(DMI_PRODUCT_NAME, "UL30A"),
  108. },
  109. },
  110. {
  111. .callback = video_detect_force_vendor,
  112. .ident = "Dell Inspiron 5737",
  113. .matches = {
  114. DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
  115. DMI_MATCH(DMI_PRODUCT_NAME, "Inspiron 5737"),
  116. },
  117. },
  118. { },
  119. };
  120. /*
  121. * Determine which type of backlight interface to use on this system,
  122. * First check cmdline, then dmi quirks, then do autodetect.
  123. *
  124. * The autodetect order is:
  125. * 1) Is the acpi-video backlight interface supported ->
  126. * no, use a vendor interface
  127. * 2) Is this a win8 "ready" BIOS and do we have a native interface ->
  128. * yes, use a native interface
  129. * 3) Else use the acpi-video interface
  130. *
  131. * Arguably the native on win8 check should be done first, but that would
  132. * be a behavior change, which may causes issues.
  133. */
  134. enum acpi_backlight_type acpi_video_get_backlight_type(void)
  135. {
  136. static DEFINE_MUTEX(init_mutex);
  137. static bool init_done;
  138. static long video_caps;
  139. /* Parse cmdline, dmi and acpi only once */
  140. mutex_lock(&init_mutex);
  141. if (!init_done) {
  142. acpi_video_parse_cmdline();
  143. dmi_check_system(video_detect_dmi_table);
  144. acpi_walk_namespace(ACPI_TYPE_DEVICE, ACPI_ROOT_OBJECT,
  145. ACPI_UINT32_MAX, find_video, NULL,
  146. &video_caps, NULL);
  147. init_done = true;
  148. }
  149. mutex_unlock(&init_mutex);
  150. if (acpi_backlight_cmdline != acpi_backlight_undef)
  151. return acpi_backlight_cmdline;
  152. if (acpi_backlight_dmi != acpi_backlight_undef)
  153. return acpi_backlight_dmi;
  154. if (!(video_caps & ACPI_VIDEO_BACKLIGHT))
  155. return acpi_backlight_vendor;
  156. if (acpi_osi_is_win8() && backlight_device_registered(BACKLIGHT_RAW))
  157. return acpi_backlight_native;
  158. return acpi_backlight_video;
  159. }
  160. EXPORT_SYMBOL(acpi_video_get_backlight_type);
  161. /*
  162. * Set the preferred backlight interface type based on DMI info.
  163. * This function allows DMI blacklists to be implemented by external
  164. * platform drivers instead of putting a big blacklist in video_detect.c
  165. */
  166. void acpi_video_set_dmi_backlight_type(enum acpi_backlight_type type)
  167. {
  168. acpi_backlight_dmi = type;
  169. /* Remove acpi-video backlight interface if it is no longer desired */
  170. if (acpi_video_get_backlight_type() != acpi_backlight_video)
  171. acpi_video_unregister_backlight();
  172. }
  173. EXPORT_SYMBOL(acpi_video_set_dmi_backlight_type);
  174. /*
  175. * Compatiblity function, this is going away as soon as all drivers are
  176. * converted to acpi_video_set_dmi_backlight_type().
  177. *
  178. * Promote the vendor interface instead of the generic video module.
  179. * After calling this function you will probably want to call
  180. * acpi_video_unregister() to make sure the video module is not loaded
  181. */
  182. void acpi_video_dmi_promote_vendor(void)
  183. {
  184. acpi_video_set_dmi_backlight_type(acpi_backlight_vendor);
  185. }
  186. EXPORT_SYMBOL(acpi_video_dmi_promote_vendor);
  187. /*
  188. * Compatiblity function, this is going away as soon as all drivers are
  189. * converted to acpi_video_get_backlight_type().
  190. *
  191. * Returns true if video.ko can do backlight switching.
  192. */
  193. int acpi_video_backlight_support(void)
  194. {
  195. /*
  196. * This is done this way since vendor drivers call this to see
  197. * if they should load, and we do not want them to load for both
  198. * the acpi_backlight_video and acpi_backlight_native cases.
  199. */
  200. return acpi_video_get_backlight_type() != acpi_backlight_vendor;
  201. }
  202. EXPORT_SYMBOL(acpi_video_backlight_support);