video_detect.c 17 KB

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