/drivers/acpi/video_detect.c

http://github.com/mirrors/linux · C · 480 lines · 367 code · 31 blank · 82 comment · 25 complexity · 73eeb0e16a1b508180caf1a1bdecf083 MD5 · raw file

  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 <linux/workqueue.h>
  35. #include <acpi/video.h>
  36. ACPI_MODULE_NAME("video");
  37. #define _COMPONENT ACPI_VIDEO_COMPONENT
  38. void acpi_video_unregister_backlight(void);
  39. static bool backlight_notifier_registered;
  40. static struct notifier_block backlight_nb;
  41. static struct work_struct backlight_notify_work;
  42. static enum acpi_backlight_type acpi_backlight_cmdline = acpi_backlight_undef;
  43. static enum acpi_backlight_type acpi_backlight_dmi = acpi_backlight_undef;
  44. static void acpi_video_parse_cmdline(void)
  45. {
  46. if (!strcmp("vendor", acpi_video_backlight_string))
  47. acpi_backlight_cmdline = acpi_backlight_vendor;
  48. if (!strcmp("video", acpi_video_backlight_string))
  49. acpi_backlight_cmdline = acpi_backlight_video;
  50. if (!strcmp("native", acpi_video_backlight_string))
  51. acpi_backlight_cmdline = acpi_backlight_native;
  52. if (!strcmp("none", acpi_video_backlight_string))
  53. acpi_backlight_cmdline = acpi_backlight_none;
  54. }
  55. static acpi_status
  56. find_video(acpi_handle handle, u32 lvl, void *context, void **rv)
  57. {
  58. long *cap = context;
  59. struct pci_dev *dev;
  60. struct acpi_device *acpi_dev;
  61. static const struct acpi_device_id video_ids[] = {
  62. {ACPI_VIDEO_HID, 0},
  63. {"", 0},
  64. };
  65. if (acpi_bus_get_device(handle, &acpi_dev))
  66. return AE_OK;
  67. if (!acpi_match_device_ids(acpi_dev, video_ids)) {
  68. dev = acpi_get_pci_dev(handle);
  69. if (!dev)
  70. return AE_OK;
  71. pci_dev_put(dev);
  72. *cap |= acpi_is_video_device(handle);
  73. }
  74. return AE_OK;
  75. }
  76. /* Force to use vendor driver when the ACPI device is known to be
  77. * buggy */
  78. static int video_detect_force_vendor(const struct dmi_system_id *d)
  79. {
  80. acpi_backlight_dmi = acpi_backlight_vendor;
  81. return 0;
  82. }
  83. static int video_detect_force_video(const struct dmi_system_id *d)
  84. {
  85. acpi_backlight_dmi = acpi_backlight_video;
  86. return 0;
  87. }
  88. static int video_detect_force_native(const struct dmi_system_id *d)
  89. {
  90. acpi_backlight_dmi = acpi_backlight_native;
  91. return 0;
  92. }
  93. static int video_detect_force_none(const struct dmi_system_id *d)
  94. {
  95. acpi_backlight_dmi = acpi_backlight_none;
  96. return 0;
  97. }
  98. static const struct dmi_system_id video_detect_dmi_table[] = {
  99. /* On Samsung X360, the BIOS will set a flag (VDRV) if generic
  100. * ACPI backlight device is used. This flag will definitively break
  101. * the backlight interface (even the vendor interface) until next
  102. * reboot. It's why we should prevent video.ko from being used here
  103. * and we can't rely on a later call to acpi_video_unregister().
  104. */
  105. {
  106. .callback = video_detect_force_vendor,
  107. .ident = "X360",
  108. .matches = {
  109. DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD."),
  110. DMI_MATCH(DMI_PRODUCT_NAME, "X360"),
  111. DMI_MATCH(DMI_BOARD_NAME, "X360"),
  112. },
  113. },
  114. {
  115. .callback = video_detect_force_vendor,
  116. .ident = "Asus UL30VT",
  117. .matches = {
  118. DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK Computer Inc."),
  119. DMI_MATCH(DMI_PRODUCT_NAME, "UL30VT"),
  120. },
  121. },
  122. {
  123. .callback = video_detect_force_vendor,
  124. .ident = "Asus UL30A",
  125. .matches = {
  126. DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK Computer Inc."),
  127. DMI_MATCH(DMI_PRODUCT_NAME, "UL30A"),
  128. },
  129. },
  130. {
  131. .callback = video_detect_force_vendor,
  132. .ident = "Sony VPCEH3U1E",
  133. .matches = {
  134. DMI_MATCH(DMI_SYS_VENDOR, "Sony Corporation"),
  135. DMI_MATCH(DMI_PRODUCT_NAME, "VPCEH3U1E"),
  136. },
  137. },
  138. /*
  139. * These models have a working acpi_video backlight control, and using
  140. * native backlight causes a regression where backlight does not work
  141. * when userspace is not handling brightness key events. Disable
  142. * native_backlight on these to fix this:
  143. * https://bugzilla.kernel.org/show_bug.cgi?id=81691
  144. */
  145. {
  146. .callback = video_detect_force_video,
  147. .ident = "ThinkPad T420",
  148. .matches = {
  149. DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
  150. DMI_MATCH(DMI_PRODUCT_VERSION, "ThinkPad T420"),
  151. },
  152. },
  153. {
  154. .callback = video_detect_force_video,
  155. .ident = "ThinkPad T520",
  156. .matches = {
  157. DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
  158. DMI_MATCH(DMI_PRODUCT_VERSION, "ThinkPad T520"),
  159. },
  160. },
  161. {
  162. .callback = video_detect_force_video,
  163. .ident = "ThinkPad X201s",
  164. .matches = {
  165. DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
  166. DMI_MATCH(DMI_PRODUCT_VERSION, "ThinkPad X201s"),
  167. },
  168. },
  169. {
  170. .callback = video_detect_force_video,
  171. .ident = "ThinkPad X201T",
  172. .matches = {
  173. DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
  174. DMI_MATCH(DMI_PRODUCT_VERSION, "ThinkPad X201T"),
  175. },
  176. },
  177. /* The native backlight controls do not work on some older machines */
  178. {
  179. /* https://bugs.freedesktop.org/show_bug.cgi?id=81515 */
  180. .callback = video_detect_force_video,
  181. .ident = "HP ENVY 15 Notebook",
  182. .matches = {
  183. DMI_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),
  184. DMI_MATCH(DMI_PRODUCT_NAME, "HP ENVY 15 Notebook PC"),
  185. },
  186. },
  187. {
  188. .callback = video_detect_force_video,
  189. .ident = "SAMSUNG 870Z5E/880Z5E/680Z5E",
  190. .matches = {
  191. DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD."),
  192. DMI_MATCH(DMI_PRODUCT_NAME, "870Z5E/880Z5E/680Z5E"),
  193. },
  194. },
  195. {
  196. .callback = video_detect_force_video,
  197. .ident = "SAMSUNG 370R4E/370R4V/370R5E/3570RE/370R5V",
  198. .matches = {
  199. DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD."),
  200. DMI_MATCH(DMI_PRODUCT_NAME,
  201. "370R4E/370R4V/370R5E/3570RE/370R5V"),
  202. },
  203. },
  204. {
  205. /* https://bugzilla.redhat.com/show_bug.cgi?id=1186097 */
  206. .callback = video_detect_force_video,
  207. .ident = "SAMSUNG 3570R/370R/470R/450R/510R/4450RV",
  208. .matches = {
  209. DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD."),
  210. DMI_MATCH(DMI_PRODUCT_NAME,
  211. "3570R/370R/470R/450R/510R/4450RV"),
  212. },
  213. },
  214. {
  215. /* https://bugzilla.redhat.com/show_bug.cgi?id=1557060 */
  216. .callback = video_detect_force_video,
  217. .ident = "SAMSUNG 670Z5E",
  218. .matches = {
  219. DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD."),
  220. DMI_MATCH(DMI_PRODUCT_NAME, "670Z5E"),
  221. },
  222. },
  223. {
  224. /* https://bugzilla.redhat.com/show_bug.cgi?id=1094948 */
  225. .callback = video_detect_force_video,
  226. .ident = "SAMSUNG 730U3E/740U3E",
  227. .matches = {
  228. DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD."),
  229. DMI_MATCH(DMI_PRODUCT_NAME, "730U3E/740U3E"),
  230. },
  231. },
  232. {
  233. /* https://bugs.freedesktop.org/show_bug.cgi?id=87286 */
  234. .callback = video_detect_force_video,
  235. .ident = "SAMSUNG 900X3C/900X3D/900X3E/900X4C/900X4D",
  236. .matches = {
  237. DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD."),
  238. DMI_MATCH(DMI_PRODUCT_NAME,
  239. "900X3C/900X3D/900X3E/900X4C/900X4D"),
  240. },
  241. },
  242. {
  243. /* https://bugzilla.redhat.com/show_bug.cgi?id=1272633 */
  244. .callback = video_detect_force_video,
  245. .ident = "Dell XPS14 L421X",
  246. .matches = {
  247. DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
  248. DMI_MATCH(DMI_PRODUCT_NAME, "XPS L421X"),
  249. },
  250. },
  251. {
  252. /* https://bugzilla.redhat.com/show_bug.cgi?id=1163574 */
  253. .callback = video_detect_force_video,
  254. .ident = "Dell XPS15 L521X",
  255. .matches = {
  256. DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
  257. DMI_MATCH(DMI_PRODUCT_NAME, "XPS L521X"),
  258. },
  259. },
  260. {
  261. /* https://bugzilla.kernel.org/show_bug.cgi?id=108971 */
  262. .callback = video_detect_force_video,
  263. .ident = "SAMSUNG 530U4E/540U4E",
  264. .matches = {
  265. DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD."),
  266. DMI_MATCH(DMI_PRODUCT_NAME, "530U4E/540U4E"),
  267. },
  268. },
  269. /* Non win8 machines which need native backlight nevertheless */
  270. {
  271. /* https://bugzilla.redhat.com/show_bug.cgi?id=1201530 */
  272. .callback = video_detect_force_native,
  273. .ident = "Lenovo Ideapad S405",
  274. .matches = {
  275. DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
  276. DMI_MATCH(DMI_BOARD_NAME, "Lenovo IdeaPad S405"),
  277. },
  278. },
  279. {
  280. /* https://bugzilla.redhat.com/show_bug.cgi?id=1187004 */
  281. .callback = video_detect_force_native,
  282. .ident = "Lenovo Ideapad Z570",
  283. .matches = {
  284. DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
  285. DMI_MATCH(DMI_PRODUCT_NAME, "102434U"),
  286. },
  287. },
  288. {
  289. .callback = video_detect_force_native,
  290. .ident = "Lenovo E41-25",
  291. .matches = {
  292. DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
  293. DMI_MATCH(DMI_PRODUCT_NAME, "81FS"),
  294. },
  295. },
  296. {
  297. .callback = video_detect_force_native,
  298. .ident = "Lenovo E41-45",
  299. .matches = {
  300. DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
  301. DMI_MATCH(DMI_PRODUCT_NAME, "82BK"),
  302. },
  303. },
  304. {
  305. /* https://bugzilla.redhat.com/show_bug.cgi?id=1217249 */
  306. .callback = video_detect_force_native,
  307. .ident = "Apple MacBook Pro 12,1",
  308. .matches = {
  309. DMI_MATCH(DMI_SYS_VENDOR, "Apple Inc."),
  310. DMI_MATCH(DMI_PRODUCT_NAME, "MacBookPro12,1"),
  311. },
  312. },
  313. {
  314. .callback = video_detect_force_native,
  315. .ident = "Dell Vostro V131",
  316. .matches = {
  317. DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
  318. DMI_MATCH(DMI_PRODUCT_NAME, "Vostro V131"),
  319. },
  320. },
  321. {
  322. /* https://bugzilla.redhat.com/show_bug.cgi?id=1123661 */
  323. .callback = video_detect_force_native,
  324. .ident = "Dell XPS 17 L702X",
  325. .matches = {
  326. DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
  327. DMI_MATCH(DMI_PRODUCT_NAME, "Dell System XPS L702X"),
  328. },
  329. },
  330. {
  331. .callback = video_detect_force_native,
  332. .ident = "Dell Precision 7510",
  333. .matches = {
  334. DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
  335. DMI_MATCH(DMI_PRODUCT_NAME, "Precision 7510"),
  336. },
  337. },
  338. {
  339. .callback = video_detect_force_native,
  340. .ident = "Acer Aspire 5738z",
  341. .matches = {
  342. DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
  343. DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 5738"),
  344. DMI_MATCH(DMI_BOARD_NAME, "JV50"),
  345. },
  346. },
  347. /*
  348. * Desktops which falsely report a backlight and which our heuristics
  349. * for this do not catch.
  350. */
  351. {
  352. .callback = video_detect_force_none,
  353. .ident = "Dell OptiPlex 9020M",
  354. .matches = {
  355. DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
  356. DMI_MATCH(DMI_PRODUCT_NAME, "OptiPlex 9020M"),
  357. },
  358. },
  359. {
  360. .callback = video_detect_force_none,
  361. .ident = "MSI MS-7721",
  362. .matches = {
  363. DMI_MATCH(DMI_SYS_VENDOR, "MSI"),
  364. DMI_MATCH(DMI_PRODUCT_NAME, "MS-7721"),
  365. },
  366. },
  367. { },
  368. };
  369. /* This uses a workqueue to avoid various locking ordering issues */
  370. static void acpi_video_backlight_notify_work(struct work_struct *work)
  371. {
  372. if (acpi_video_get_backlight_type() != acpi_backlight_video)
  373. acpi_video_unregister_backlight();
  374. }
  375. static int acpi_video_backlight_notify(struct notifier_block *nb,
  376. unsigned long val, void *bd)
  377. {
  378. struct backlight_device *backlight = bd;
  379. /* A raw bl registering may change video -> native */
  380. if (backlight->props.type == BACKLIGHT_RAW &&
  381. val == BACKLIGHT_REGISTERED)
  382. schedule_work(&backlight_notify_work);
  383. return NOTIFY_OK;
  384. }
  385. /*
  386. * Determine which type of backlight interface to use on this system,
  387. * First check cmdline, then dmi quirks, then do autodetect.
  388. *
  389. * The autodetect order is:
  390. * 1) Is the acpi-video backlight interface supported ->
  391. * no, use a vendor interface
  392. * 2) Is this a win8 "ready" BIOS and do we have a native interface ->
  393. * yes, use a native interface
  394. * 3) Else use the acpi-video interface
  395. *
  396. * Arguably the native on win8 check should be done first, but that would
  397. * be a behavior change, which may causes issues.
  398. */
  399. enum acpi_backlight_type acpi_video_get_backlight_type(void)
  400. {
  401. static DEFINE_MUTEX(init_mutex);
  402. static bool init_done;
  403. static long video_caps;
  404. /* Parse cmdline, dmi and acpi only once */
  405. mutex_lock(&init_mutex);
  406. if (!init_done) {
  407. acpi_video_parse_cmdline();
  408. dmi_check_system(video_detect_dmi_table);
  409. acpi_walk_namespace(ACPI_TYPE_DEVICE, ACPI_ROOT_OBJECT,
  410. ACPI_UINT32_MAX, find_video, NULL,
  411. &video_caps, NULL);
  412. INIT_WORK(&backlight_notify_work,
  413. acpi_video_backlight_notify_work);
  414. backlight_nb.notifier_call = acpi_video_backlight_notify;
  415. backlight_nb.priority = 0;
  416. if (backlight_register_notifier(&backlight_nb) == 0)
  417. backlight_notifier_registered = true;
  418. init_done = true;
  419. }
  420. mutex_unlock(&init_mutex);
  421. if (acpi_backlight_cmdline != acpi_backlight_undef)
  422. return acpi_backlight_cmdline;
  423. if (acpi_backlight_dmi != acpi_backlight_undef)
  424. return acpi_backlight_dmi;
  425. if (!(video_caps & ACPI_VIDEO_BACKLIGHT))
  426. return acpi_backlight_vendor;
  427. if (acpi_osi_is_win8() && backlight_device_get_by_type(BACKLIGHT_RAW))
  428. return acpi_backlight_native;
  429. return acpi_backlight_video;
  430. }
  431. EXPORT_SYMBOL(acpi_video_get_backlight_type);
  432. /*
  433. * Set the preferred backlight interface type based on DMI info.
  434. * This function allows DMI blacklists to be implemented by external
  435. * platform drivers instead of putting a big blacklist in video_detect.c
  436. */
  437. void acpi_video_set_dmi_backlight_type(enum acpi_backlight_type type)
  438. {
  439. acpi_backlight_dmi = type;
  440. /* Remove acpi-video backlight interface if it is no longer desired */
  441. if (acpi_video_get_backlight_type() != acpi_backlight_video)
  442. acpi_video_unregister_backlight();
  443. }
  444. EXPORT_SYMBOL(acpi_video_set_dmi_backlight_type);
  445. void __exit acpi_video_detect_exit(void)
  446. {
  447. if (backlight_notifier_registered)
  448. backlight_unregister_notifier(&backlight_nb);
  449. }