video.c 49 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972
  1. /*
  2. * video.c - ACPI Video Driver
  3. *
  4. * Copyright (C) 2004 Luming Yu <luming.yu@intel.com>
  5. * Copyright (C) 2004 Bruno Ducrot <ducrot@poupinou.org>
  6. * Copyright (C) 2006 Thomas Tuttle <linux-kernel@ttuttle.net>
  7. *
  8. * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  9. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License as published by
  12. * the Free Software Foundation; either version 2 of the License, or (at
  13. * your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful, but
  16. * WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  18. * General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License along
  21. * with this program; if not, write to the Free Software Foundation, Inc.,
  22. * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
  23. *
  24. * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  25. */
  26. #include <linux/kernel.h>
  27. #include <linux/module.h>
  28. #include <linux/init.h>
  29. #include <linux/types.h>
  30. #include <linux/list.h>
  31. #include <linux/mutex.h>
  32. #include <linux/input.h>
  33. #include <linux/backlight.h>
  34. #include <linux/thermal.h>
  35. #include <linux/sort.h>
  36. #include <linux/pci.h>
  37. #include <linux/pci_ids.h>
  38. #include <linux/slab.h>
  39. #include <asm/uaccess.h>
  40. #include <linux/dmi.h>
  41. #include <acpi/acpi_bus.h>
  42. #include <acpi/acpi_drivers.h>
  43. #include <linux/suspend.h>
  44. #include <acpi/video.h>
  45. #include "internal.h"
  46. #define PREFIX "ACPI: "
  47. #define ACPI_VIDEO_BUS_NAME "Video Bus"
  48. #define ACPI_VIDEO_DEVICE_NAME "Video Device"
  49. #define ACPI_VIDEO_NOTIFY_SWITCH 0x80
  50. #define ACPI_VIDEO_NOTIFY_PROBE 0x81
  51. #define ACPI_VIDEO_NOTIFY_CYCLE 0x82
  52. #define ACPI_VIDEO_NOTIFY_NEXT_OUTPUT 0x83
  53. #define ACPI_VIDEO_NOTIFY_PREV_OUTPUT 0x84
  54. #define ACPI_VIDEO_NOTIFY_CYCLE_BRIGHTNESS 0x85
  55. #define ACPI_VIDEO_NOTIFY_INC_BRIGHTNESS 0x86
  56. #define ACPI_VIDEO_NOTIFY_DEC_BRIGHTNESS 0x87
  57. #define ACPI_VIDEO_NOTIFY_ZERO_BRIGHTNESS 0x88
  58. #define ACPI_VIDEO_NOTIFY_DISPLAY_OFF 0x89
  59. #define MAX_NAME_LEN 20
  60. #define _COMPONENT ACPI_VIDEO_COMPONENT
  61. ACPI_MODULE_NAME("video");
  62. MODULE_AUTHOR("Bruno Ducrot");
  63. MODULE_DESCRIPTION("ACPI Video Driver");
  64. MODULE_LICENSE("GPL");
  65. static bool brightness_switch_enabled = 1;
  66. module_param(brightness_switch_enabled, bool, 0644);
  67. /*
  68. * By default, we don't allow duplicate ACPI video bus devices
  69. * under the same VGA controller
  70. */
  71. static bool allow_duplicates;
  72. module_param(allow_duplicates, bool, 0644);
  73. /*
  74. * Some BIOSes claim they use minimum backlight at boot,
  75. * and this may bring dimming screen after boot
  76. */
  77. static bool use_bios_initial_backlight = 1;
  78. module_param(use_bios_initial_backlight, bool, 0644);
  79. static int register_count;
  80. static int acpi_video_bus_add(struct acpi_device *device);
  81. static int acpi_video_bus_remove(struct acpi_device *device);
  82. static void acpi_video_bus_notify(struct acpi_device *device, u32 event);
  83. static const struct acpi_device_id video_device_ids[] = {
  84. {ACPI_VIDEO_HID, 0},
  85. {"", 0},
  86. };
  87. MODULE_DEVICE_TABLE(acpi, video_device_ids);
  88. static struct acpi_driver acpi_video_bus = {
  89. .name = "video",
  90. .class = ACPI_VIDEO_CLASS,
  91. .ids = video_device_ids,
  92. .ops = {
  93. .add = acpi_video_bus_add,
  94. .remove = acpi_video_bus_remove,
  95. .notify = acpi_video_bus_notify,
  96. },
  97. };
  98. struct acpi_video_bus_flags {
  99. u8 multihead:1; /* can switch video heads */
  100. u8 rom:1; /* can retrieve a video rom */
  101. u8 post:1; /* can configure the head to */
  102. u8 reserved:5;
  103. };
  104. struct acpi_video_bus_cap {
  105. u8 _DOS:1; /* Enable/Disable output switching */
  106. u8 _DOD:1; /* Enumerate all devices attached to display adapter */
  107. u8 _ROM:1; /* Get ROM Data */
  108. u8 _GPD:1; /* Get POST Device */
  109. u8 _SPD:1; /* Set POST Device */
  110. u8 _VPO:1; /* Video POST Options */
  111. u8 reserved:2;
  112. };
  113. struct acpi_video_device_attrib {
  114. u32 display_index:4; /* A zero-based instance of the Display */
  115. u32 display_port_attachment:4; /* This field differentiates the display type */
  116. u32 display_type:4; /* Describe the specific type in use */
  117. u32 vendor_specific:4; /* Chipset Vendor Specific */
  118. u32 bios_can_detect:1; /* BIOS can detect the device */
  119. u32 depend_on_vga:1; /* Non-VGA output device whose power is related to
  120. the VGA device. */
  121. u32 pipe_id:3; /* For VGA multiple-head devices. */
  122. u32 reserved:10; /* Must be 0 */
  123. u32 device_id_scheme:1; /* Device ID Scheme */
  124. };
  125. struct acpi_video_enumerated_device {
  126. union {
  127. u32 int_val;
  128. struct acpi_video_device_attrib attrib;
  129. } value;
  130. struct acpi_video_device *bind_info;
  131. };
  132. struct acpi_video_bus {
  133. struct acpi_device *device;
  134. u8 dos_setting;
  135. struct acpi_video_enumerated_device *attached_array;
  136. u8 attached_count;
  137. struct acpi_video_bus_cap cap;
  138. struct acpi_video_bus_flags flags;
  139. struct list_head video_device_list;
  140. struct mutex device_list_lock; /* protects video_device_list */
  141. struct input_dev *input;
  142. char phys[32]; /* for input device */
  143. struct notifier_block pm_nb;
  144. };
  145. struct acpi_video_device_flags {
  146. u8 crt:1;
  147. u8 lcd:1;
  148. u8 tvout:1;
  149. u8 dvi:1;
  150. u8 bios:1;
  151. u8 unknown:1;
  152. u8 notify:1;
  153. u8 reserved:1;
  154. };
  155. struct acpi_video_device_cap {
  156. u8 _ADR:1; /* Return the unique ID */
  157. u8 _BCL:1; /* Query list of brightness control levels supported */
  158. u8 _BCM:1; /* Set the brightness level */
  159. u8 _BQC:1; /* Get current brightness level */
  160. u8 _BCQ:1; /* Some buggy BIOS uses _BCQ instead of _BQC */
  161. u8 _DDC:1; /* Return the EDID for this device */
  162. };
  163. struct acpi_video_brightness_flags {
  164. u8 _BCL_no_ac_battery_levels:1; /* no AC/Battery levels in _BCL */
  165. u8 _BCL_reversed:1; /* _BCL package is in a reversed order */
  166. u8 _BCL_use_index:1; /* levels in _BCL are index values */
  167. u8 _BCM_use_index:1; /* input of _BCM is an index value */
  168. u8 _BQC_use_index:1; /* _BQC returns an index value */
  169. };
  170. struct acpi_video_device_brightness {
  171. int curr;
  172. int count;
  173. int *levels;
  174. struct acpi_video_brightness_flags flags;
  175. };
  176. struct acpi_video_device {
  177. unsigned long device_id;
  178. struct acpi_video_device_flags flags;
  179. struct acpi_video_device_cap cap;
  180. struct list_head entry;
  181. struct acpi_video_bus *video;
  182. struct acpi_device *dev;
  183. struct acpi_video_device_brightness *brightness;
  184. struct backlight_device *backlight;
  185. struct thermal_cooling_device *cooling_dev;
  186. };
  187. static const char device_decode[][30] = {
  188. "motherboard VGA device",
  189. "PCI VGA device",
  190. "AGP VGA device",
  191. "UNKNOWN",
  192. };
  193. static void acpi_video_device_notify(acpi_handle handle, u32 event, void *data);
  194. static void acpi_video_device_rebind(struct acpi_video_bus *video);
  195. static void acpi_video_device_bind(struct acpi_video_bus *video,
  196. struct acpi_video_device *device);
  197. static int acpi_video_device_enumerate(struct acpi_video_bus *video);
  198. static int acpi_video_device_lcd_set_level(struct acpi_video_device *device,
  199. int level);
  200. static int acpi_video_device_lcd_get_level_current(
  201. struct acpi_video_device *device,
  202. unsigned long long *level, bool raw);
  203. static int acpi_video_get_next_level(struct acpi_video_device *device,
  204. u32 level_current, u32 event);
  205. static int acpi_video_switch_brightness(struct acpi_video_device *device,
  206. int event);
  207. /* backlight device sysfs support */
  208. static int acpi_video_get_brightness(struct backlight_device *bd)
  209. {
  210. unsigned long long cur_level;
  211. int i;
  212. struct acpi_video_device *vd = bl_get_data(bd);
  213. if (acpi_video_device_lcd_get_level_current(vd, &cur_level, false))
  214. return -EINVAL;
  215. for (i = 2; i < vd->brightness->count; i++) {
  216. if (vd->brightness->levels[i] == cur_level)
  217. /*
  218. * The first two entries are special - see page 575
  219. * of the ACPI spec 3.0
  220. */
  221. return i - 2;
  222. }
  223. return 0;
  224. }
  225. static int acpi_video_set_brightness(struct backlight_device *bd)
  226. {
  227. int request_level = bd->props.brightness + 2;
  228. struct acpi_video_device *vd = bl_get_data(bd);
  229. return acpi_video_device_lcd_set_level(vd,
  230. vd->brightness->levels[request_level]);
  231. }
  232. static const struct backlight_ops acpi_backlight_ops = {
  233. .get_brightness = acpi_video_get_brightness,
  234. .update_status = acpi_video_set_brightness,
  235. };
  236. /* thermal cooling device callbacks */
  237. static int video_get_max_state(struct thermal_cooling_device *cooling_dev, unsigned
  238. long *state)
  239. {
  240. struct acpi_device *device = cooling_dev->devdata;
  241. struct acpi_video_device *video = acpi_driver_data(device);
  242. *state = video->brightness->count - 3;
  243. return 0;
  244. }
  245. static int video_get_cur_state(struct thermal_cooling_device *cooling_dev, unsigned
  246. long *state)
  247. {
  248. struct acpi_device *device = cooling_dev->devdata;
  249. struct acpi_video_device *video = acpi_driver_data(device);
  250. unsigned long long level;
  251. int offset;
  252. if (acpi_video_device_lcd_get_level_current(video, &level, false))
  253. return -EINVAL;
  254. for (offset = 2; offset < video->brightness->count; offset++)
  255. if (level == video->brightness->levels[offset]) {
  256. *state = video->brightness->count - offset - 1;
  257. return 0;
  258. }
  259. return -EINVAL;
  260. }
  261. static int
  262. video_set_cur_state(struct thermal_cooling_device *cooling_dev, unsigned long state)
  263. {
  264. struct acpi_device *device = cooling_dev->devdata;
  265. struct acpi_video_device *video = acpi_driver_data(device);
  266. int level;
  267. if (state >= video->brightness->count - 2)
  268. return -EINVAL;
  269. state = video->brightness->count - state;
  270. level = video->brightness->levels[state - 1];
  271. return acpi_video_device_lcd_set_level(video, level);
  272. }
  273. static const struct thermal_cooling_device_ops video_cooling_ops = {
  274. .get_max_state = video_get_max_state,
  275. .get_cur_state = video_get_cur_state,
  276. .set_cur_state = video_set_cur_state,
  277. };
  278. /*
  279. * --------------------------------------------------------------------------
  280. * Video Management
  281. * --------------------------------------------------------------------------
  282. */
  283. static int
  284. acpi_video_device_lcd_query_levels(struct acpi_video_device *device,
  285. union acpi_object **levels)
  286. {
  287. int status;
  288. struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
  289. union acpi_object *obj;
  290. *levels = NULL;
  291. status = acpi_evaluate_object(device->dev->handle, "_BCL", NULL, &buffer);
  292. if (!ACPI_SUCCESS(status))
  293. return status;
  294. obj = (union acpi_object *)buffer.pointer;
  295. if (!obj || (obj->type != ACPI_TYPE_PACKAGE)) {
  296. printk(KERN_ERR PREFIX "Invalid _BCL data\n");
  297. status = -EFAULT;
  298. goto err;
  299. }
  300. *levels = obj;
  301. return 0;
  302. err:
  303. kfree(buffer.pointer);
  304. return status;
  305. }
  306. static int
  307. acpi_video_device_lcd_set_level(struct acpi_video_device *device, int level)
  308. {
  309. int status;
  310. union acpi_object arg0 = { ACPI_TYPE_INTEGER };
  311. struct acpi_object_list args = { 1, &arg0 };
  312. int state;
  313. arg0.integer.value = level;
  314. status = acpi_evaluate_object(device->dev->handle, "_BCM",
  315. &args, NULL);
  316. if (ACPI_FAILURE(status)) {
  317. ACPI_ERROR((AE_INFO, "Evaluating _BCM failed"));
  318. return -EIO;
  319. }
  320. device->brightness->curr = level;
  321. for (state = 2; state < device->brightness->count; state++)
  322. if (level == device->brightness->levels[state]) {
  323. if (device->backlight)
  324. device->backlight->props.brightness = state - 2;
  325. return 0;
  326. }
  327. ACPI_ERROR((AE_INFO, "Current brightness invalid"));
  328. return -EINVAL;
  329. }
  330. /*
  331. * For some buggy _BQC methods, we need to add a constant value to
  332. * the _BQC return value to get the actual current brightness level
  333. */
  334. static int bqc_offset_aml_bug_workaround;
  335. static int __init video_set_bqc_offset(const struct dmi_system_id *d)
  336. {
  337. bqc_offset_aml_bug_workaround = 9;
  338. return 0;
  339. }
  340. static int video_ignore_initial_backlight(const struct dmi_system_id *d)
  341. {
  342. use_bios_initial_backlight = 0;
  343. return 0;
  344. }
  345. static struct dmi_system_id video_dmi_table[] __initdata = {
  346. /*
  347. * Broken _BQC workaround http://bugzilla.kernel.org/show_bug.cgi?id=13121
  348. */
  349. {
  350. .callback = video_set_bqc_offset,
  351. .ident = "Acer Aspire 5720",
  352. .matches = {
  353. DMI_MATCH(DMI_BOARD_VENDOR, "Acer"),
  354. DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 5720"),
  355. },
  356. },
  357. {
  358. .callback = video_set_bqc_offset,
  359. .ident = "Acer Aspire 5710Z",
  360. .matches = {
  361. DMI_MATCH(DMI_BOARD_VENDOR, "Acer"),
  362. DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 5710Z"),
  363. },
  364. },
  365. {
  366. .callback = video_set_bqc_offset,
  367. .ident = "eMachines E510",
  368. .matches = {
  369. DMI_MATCH(DMI_BOARD_VENDOR, "EMACHINES"),
  370. DMI_MATCH(DMI_PRODUCT_NAME, "eMachines E510"),
  371. },
  372. },
  373. {
  374. .callback = video_set_bqc_offset,
  375. .ident = "Acer Aspire 5315",
  376. .matches = {
  377. DMI_MATCH(DMI_BOARD_VENDOR, "Acer"),
  378. DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 5315"),
  379. },
  380. },
  381. {
  382. .callback = video_set_bqc_offset,
  383. .ident = "Acer Aspire 7720",
  384. .matches = {
  385. DMI_MATCH(DMI_BOARD_VENDOR, "Acer"),
  386. DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 7720"),
  387. },
  388. },
  389. {
  390. .callback = video_ignore_initial_backlight,
  391. .ident = "HP Folio 13-2000",
  392. .matches = {
  393. DMI_MATCH(DMI_BOARD_VENDOR, "Hewlett-Packard"),
  394. DMI_MATCH(DMI_PRODUCT_NAME, "HP Folio 13 - 2000 Notebook PC"),
  395. },
  396. },
  397. {
  398. .callback = video_ignore_initial_backlight,
  399. .ident = "Fujitsu E753",
  400. .matches = {
  401. DMI_MATCH(DMI_BOARD_VENDOR, "FUJITSU"),
  402. DMI_MATCH(DMI_PRODUCT_NAME, "LIFEBOOK E753"),
  403. },
  404. },
  405. {
  406. .callback = video_ignore_initial_backlight,
  407. .ident = "HP Pavilion dm4",
  408. .matches = {
  409. DMI_MATCH(DMI_BOARD_VENDOR, "Hewlett-Packard"),
  410. DMI_MATCH(DMI_PRODUCT_NAME, "HP Pavilion dm4 Notebook PC"),
  411. },
  412. },
  413. {
  414. .callback = video_ignore_initial_backlight,
  415. .ident = "HP Pavilion g6 Notebook PC",
  416. .matches = {
  417. DMI_MATCH(DMI_BOARD_VENDOR, "Hewlett-Packard"),
  418. DMI_MATCH(DMI_PRODUCT_NAME, "HP Pavilion g6 Notebook PC"),
  419. },
  420. },
  421. {
  422. .callback = video_ignore_initial_backlight,
  423. .ident = "HP 1000 Notebook PC",
  424. .matches = {
  425. DMI_MATCH(DMI_BOARD_VENDOR, "Hewlett-Packard"),
  426. DMI_MATCH(DMI_PRODUCT_NAME, "HP 1000 Notebook PC"),
  427. },
  428. },
  429. {
  430. .callback = video_ignore_initial_backlight,
  431. .ident = "HP Pavilion m4",
  432. .matches = {
  433. DMI_MATCH(DMI_BOARD_VENDOR, "Hewlett-Packard"),
  434. DMI_MATCH(DMI_PRODUCT_NAME, "HP Pavilion m4 Notebook PC"),
  435. },
  436. },
  437. {}
  438. };
  439. static unsigned long long
  440. acpi_video_bqc_value_to_level(struct acpi_video_device *device,
  441. unsigned long long bqc_value)
  442. {
  443. unsigned long long level;
  444. if (device->brightness->flags._BQC_use_index) {
  445. /*
  446. * _BQC returns an index that doesn't account for
  447. * the first 2 items with special meaning, so we need
  448. * to compensate for that by offsetting ourselves
  449. */
  450. if (device->brightness->flags._BCL_reversed)
  451. bqc_value = device->brightness->count - 3 - bqc_value;
  452. level = device->brightness->levels[bqc_value + 2];
  453. } else {
  454. level = bqc_value;
  455. }
  456. level += bqc_offset_aml_bug_workaround;
  457. return level;
  458. }
  459. static int
  460. acpi_video_device_lcd_get_level_current(struct acpi_video_device *device,
  461. unsigned long long *level, bool raw)
  462. {
  463. acpi_status status = AE_OK;
  464. int i;
  465. if (device->cap._BQC || device->cap._BCQ) {
  466. char *buf = device->cap._BQC ? "_BQC" : "_BCQ";
  467. status = acpi_evaluate_integer(device->dev->handle, buf,
  468. NULL, level);
  469. if (ACPI_SUCCESS(status)) {
  470. if (raw) {
  471. /*
  472. * Caller has indicated he wants the raw
  473. * value returned by _BQC, so don't furtherly
  474. * mess with the value.
  475. */
  476. return 0;
  477. }
  478. *level = acpi_video_bqc_value_to_level(device, *level);
  479. for (i = 2; i < device->brightness->count; i++)
  480. if (device->brightness->levels[i] == *level) {
  481. device->brightness->curr = *level;
  482. return 0;
  483. }
  484. /*
  485. * BQC returned an invalid level.
  486. * Stop using it.
  487. */
  488. ACPI_WARNING((AE_INFO,
  489. "%s returned an invalid level",
  490. buf));
  491. device->cap._BQC = device->cap._BCQ = 0;
  492. } else {
  493. /*
  494. * Fixme:
  495. * should we return an error or ignore this failure?
  496. * dev->brightness->curr is a cached value which stores
  497. * the correct current backlight level in most cases.
  498. * ACPI video backlight still works w/ buggy _BQC.
  499. * http://bugzilla.kernel.org/show_bug.cgi?id=12233
  500. */
  501. ACPI_WARNING((AE_INFO, "Evaluating %s failed", buf));
  502. device->cap._BQC = device->cap._BCQ = 0;
  503. }
  504. }
  505. *level = device->brightness->curr;
  506. return 0;
  507. }
  508. static int
  509. acpi_video_device_EDID(struct acpi_video_device *device,
  510. union acpi_object **edid, ssize_t length)
  511. {
  512. int status;
  513. struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
  514. union acpi_object *obj;
  515. union acpi_object arg0 = { ACPI_TYPE_INTEGER };
  516. struct acpi_object_list args = { 1, &arg0 };
  517. *edid = NULL;
  518. if (!device)
  519. return -ENODEV;
  520. if (length == 128)
  521. arg0.integer.value = 1;
  522. else if (length == 256)
  523. arg0.integer.value = 2;
  524. else
  525. return -EINVAL;
  526. status = acpi_evaluate_object(device->dev->handle, "_DDC", &args, &buffer);
  527. if (ACPI_FAILURE(status))
  528. return -ENODEV;
  529. obj = buffer.pointer;
  530. if (obj && obj->type == ACPI_TYPE_BUFFER)
  531. *edid = obj;
  532. else {
  533. printk(KERN_ERR PREFIX "Invalid _DDC data\n");
  534. status = -EFAULT;
  535. kfree(obj);
  536. }
  537. return status;
  538. }
  539. /* bus */
  540. /*
  541. * Arg:
  542. * video : video bus device pointer
  543. * bios_flag :
  544. * 0. The system BIOS should NOT automatically switch(toggle)
  545. * the active display output.
  546. * 1. The system BIOS should automatically switch (toggle) the
  547. * active display output. No switch event.
  548. * 2. The _DGS value should be locked.
  549. * 3. The system BIOS should not automatically switch (toggle) the
  550. * active display output, but instead generate the display switch
  551. * event notify code.
  552. * lcd_flag :
  553. * 0. The system BIOS should automatically control the brightness level
  554. * of the LCD when the power changes from AC to DC
  555. * 1. The system BIOS should NOT automatically control the brightness
  556. * level of the LCD when the power changes from AC to DC.
  557. * Return Value:
  558. * -EINVAL wrong arg.
  559. */
  560. static int
  561. acpi_video_bus_DOS(struct acpi_video_bus *video, int bios_flag, int lcd_flag)
  562. {
  563. acpi_status status;
  564. union acpi_object arg0 = { ACPI_TYPE_INTEGER };
  565. struct acpi_object_list args = { 1, &arg0 };
  566. if (!video->cap._DOS)
  567. return 0;
  568. if (bios_flag < 0 || bios_flag > 3 || lcd_flag < 0 || lcd_flag > 1)
  569. return -EINVAL;
  570. arg0.integer.value = (lcd_flag << 2) | bios_flag;
  571. video->dos_setting = arg0.integer.value;
  572. status = acpi_evaluate_object(video->device->handle, "_DOS",
  573. &args, NULL);
  574. if (ACPI_FAILURE(status))
  575. return -EIO;
  576. return 0;
  577. }
  578. /*
  579. * Simple comparison function used to sort backlight levels.
  580. */
  581. static int
  582. acpi_video_cmp_level(const void *a, const void *b)
  583. {
  584. return *(int *)a - *(int *)b;
  585. }
  586. /*
  587. * Decides if _BQC/_BCQ for this system is usable
  588. *
  589. * We do this by changing the level first and then read out the current
  590. * brightness level, if the value does not match, find out if it is using
  591. * index. If not, clear the _BQC/_BCQ capability.
  592. */
  593. static int acpi_video_bqc_quirk(struct acpi_video_device *device,
  594. int max_level, int current_level)
  595. {
  596. struct acpi_video_device_brightness *br = device->brightness;
  597. int result;
  598. unsigned long long level;
  599. int test_level;
  600. /* don't mess with existing known broken systems */
  601. if (bqc_offset_aml_bug_workaround)
  602. return 0;
  603. /*
  604. * Some systems always report current brightness level as maximum
  605. * through _BQC, we need to test another value for them.
  606. */
  607. test_level = current_level == max_level ? br->levels[2] : max_level;
  608. result = acpi_video_device_lcd_set_level(device, test_level);
  609. if (result)
  610. return result;
  611. result = acpi_video_device_lcd_get_level_current(device, &level, true);
  612. if (result)
  613. return result;
  614. if (level != test_level) {
  615. /* buggy _BQC found, need to find out if it uses index */
  616. if (level < br->count) {
  617. if (br->flags._BCL_reversed)
  618. level = br->count - 3 - level;
  619. if (br->levels[level + 2] == test_level)
  620. br->flags._BQC_use_index = 1;
  621. }
  622. if (!br->flags._BQC_use_index)
  623. device->cap._BQC = device->cap._BCQ = 0;
  624. }
  625. return 0;
  626. }
  627. /*
  628. * Arg:
  629. * device : video output device (LCD, CRT, ..)
  630. *
  631. * Return Value:
  632. * Maximum brightness level
  633. *
  634. * Allocate and initialize device->brightness.
  635. */
  636. static int
  637. acpi_video_init_brightness(struct acpi_video_device *device)
  638. {
  639. union acpi_object *obj = NULL;
  640. int i, max_level = 0, count = 0, level_ac_battery = 0;
  641. unsigned long long level, level_old;
  642. union acpi_object *o;
  643. struct acpi_video_device_brightness *br = NULL;
  644. int result = -EINVAL;
  645. if (!ACPI_SUCCESS(acpi_video_device_lcd_query_levels(device, &obj))) {
  646. ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Could not query available "
  647. "LCD brightness level\n"));
  648. goto out;
  649. }
  650. if (obj->package.count < 2)
  651. goto out;
  652. br = kzalloc(sizeof(*br), GFP_KERNEL);
  653. if (!br) {
  654. printk(KERN_ERR "can't allocate memory\n");
  655. result = -ENOMEM;
  656. goto out;
  657. }
  658. br->levels = kmalloc((obj->package.count + 2) * sizeof *(br->levels),
  659. GFP_KERNEL);
  660. if (!br->levels) {
  661. result = -ENOMEM;
  662. goto out_free;
  663. }
  664. for (i = 0; i < obj->package.count; i++) {
  665. o = (union acpi_object *)&obj->package.elements[i];
  666. if (o->type != ACPI_TYPE_INTEGER) {
  667. printk(KERN_ERR PREFIX "Invalid data\n");
  668. continue;
  669. }
  670. br->levels[count] = (u32) o->integer.value;
  671. if (br->levels[count] > max_level)
  672. max_level = br->levels[count];
  673. count++;
  674. }
  675. /*
  676. * some buggy BIOS don't export the levels
  677. * when machine is on AC/Battery in _BCL package.
  678. * In this case, the first two elements in _BCL packages
  679. * are also supported brightness levels that OS should take care of.
  680. */
  681. for (i = 2; i < count; i++) {
  682. if (br->levels[i] == br->levels[0])
  683. level_ac_battery++;
  684. if (br->levels[i] == br->levels[1])
  685. level_ac_battery++;
  686. }
  687. if (level_ac_battery < 2) {
  688. level_ac_battery = 2 - level_ac_battery;
  689. br->flags._BCL_no_ac_battery_levels = 1;
  690. for (i = (count - 1 + level_ac_battery); i >= 2; i--)
  691. br->levels[i] = br->levels[i - level_ac_battery];
  692. count += level_ac_battery;
  693. } else if (level_ac_battery > 2)
  694. ACPI_ERROR((AE_INFO, "Too many duplicates in _BCL package"));
  695. /* Check if the _BCL package is in a reversed order */
  696. if (max_level == br->levels[2]) {
  697. br->flags._BCL_reversed = 1;
  698. sort(&br->levels[2], count - 2, sizeof(br->levels[2]),
  699. acpi_video_cmp_level, NULL);
  700. } else if (max_level != br->levels[count - 1])
  701. ACPI_ERROR((AE_INFO,
  702. "Found unordered _BCL package"));
  703. br->count = count;
  704. device->brightness = br;
  705. /* Check the input/output of _BQC/_BCL/_BCM */
  706. if ((max_level < 100) && (max_level <= (count - 2)))
  707. br->flags._BCL_use_index = 1;
  708. /*
  709. * _BCM is always consistent with _BCL,
  710. * at least for all the laptops we have ever seen.
  711. */
  712. br->flags._BCM_use_index = br->flags._BCL_use_index;
  713. /* _BQC uses INDEX while _BCL uses VALUE in some laptops */
  714. br->curr = level = max_level;
  715. if (!device->cap._BQC)
  716. goto set_level;
  717. result = acpi_video_device_lcd_get_level_current(device,
  718. &level_old, true);
  719. if (result)
  720. goto out_free_levels;
  721. result = acpi_video_bqc_quirk(device, max_level, level_old);
  722. if (result)
  723. goto out_free_levels;
  724. /*
  725. * cap._BQC may get cleared due to _BQC is found to be broken
  726. * in acpi_video_bqc_quirk, so check again here.
  727. */
  728. if (!device->cap._BQC)
  729. goto set_level;
  730. if (use_bios_initial_backlight) {
  731. level = acpi_video_bqc_value_to_level(device, level_old);
  732. /*
  733. * On some buggy laptops, _BQC returns an uninitialized
  734. * value when invoked for the first time, i.e.
  735. * level_old is invalid (no matter whether it's a level
  736. * or an index). Set the backlight to max_level in this case.
  737. */
  738. for (i = 2; i < br->count; i++)
  739. if (level_old == br->levels[i])
  740. break;
  741. if (i == br->count)
  742. level = max_level;
  743. }
  744. set_level:
  745. result = acpi_video_device_lcd_set_level(device, level);
  746. if (result)
  747. goto out_free_levels;
  748. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  749. "found %d brightness levels\n", count - 2));
  750. kfree(obj);
  751. return result;
  752. out_free_levels:
  753. kfree(br->levels);
  754. out_free:
  755. kfree(br);
  756. out:
  757. device->brightness = NULL;
  758. kfree(obj);
  759. return result;
  760. }
  761. /*
  762. * Arg:
  763. * device : video output device (LCD, CRT, ..)
  764. *
  765. * Return Value:
  766. * None
  767. *
  768. * Find out all required AML methods defined under the output
  769. * device.
  770. */
  771. static void acpi_video_device_find_cap(struct acpi_video_device *device)
  772. {
  773. acpi_handle h_dummy1;
  774. if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_ADR", &h_dummy1)))
  775. device->cap._ADR = 1;
  776. if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_BCL", &h_dummy1)))
  777. device->cap._BCL = 1;
  778. if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_BCM", &h_dummy1)))
  779. device->cap._BCM = 1;
  780. if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_BQC", &h_dummy1)))
  781. device->cap._BQC = 1;
  782. else if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_BCQ",
  783. &h_dummy1))) {
  784. printk(KERN_WARNING FW_BUG "_BCQ is used instead of _BQC\n");
  785. device->cap._BCQ = 1;
  786. }
  787. if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_DDC", &h_dummy1)))
  788. device->cap._DDC = 1;
  789. if (acpi_video_init_brightness(device))
  790. return;
  791. if (acpi_video_backlight_support()) {
  792. struct backlight_properties props;
  793. struct pci_dev *pdev;
  794. acpi_handle acpi_parent;
  795. struct device *parent = NULL;
  796. int result;
  797. static int count;
  798. char *name;
  799. name = kasprintf(GFP_KERNEL, "acpi_video%d", count);
  800. if (!name)
  801. return;
  802. count++;
  803. acpi_get_parent(device->dev->handle, &acpi_parent);
  804. pdev = acpi_get_pci_dev(acpi_parent);
  805. if (pdev) {
  806. parent = &pdev->dev;
  807. pci_dev_put(pdev);
  808. }
  809. memset(&props, 0, sizeof(struct backlight_properties));
  810. props.type = BACKLIGHT_FIRMWARE;
  811. props.max_brightness = device->brightness->count - 3;
  812. device->backlight = backlight_device_register(name,
  813. parent,
  814. device,
  815. &acpi_backlight_ops,
  816. &props);
  817. kfree(name);
  818. if (IS_ERR(device->backlight))
  819. return;
  820. /*
  821. * Save current brightness level in case we have to restore it
  822. * before acpi_video_device_lcd_set_level() is called next time.
  823. */
  824. device->backlight->props.brightness =
  825. acpi_video_get_brightness(device->backlight);
  826. device->cooling_dev = thermal_cooling_device_register("LCD",
  827. device->dev, &video_cooling_ops);
  828. if (IS_ERR(device->cooling_dev)) {
  829. /*
  830. * Set cooling_dev to NULL so we don't crash trying to
  831. * free it.
  832. * Also, why the hell we are returning early and
  833. * not attempt to register video output if cooling
  834. * device registration failed?
  835. * -- dtor
  836. */
  837. device->cooling_dev = NULL;
  838. return;
  839. }
  840. dev_info(&device->dev->dev, "registered as cooling_device%d\n",
  841. device->cooling_dev->id);
  842. result = sysfs_create_link(&device->dev->dev.kobj,
  843. &device->cooling_dev->device.kobj,
  844. "thermal_cooling");
  845. if (result)
  846. printk(KERN_ERR PREFIX "Create sysfs link\n");
  847. result = sysfs_create_link(&device->cooling_dev->device.kobj,
  848. &device->dev->dev.kobj, "device");
  849. if (result)
  850. printk(KERN_ERR PREFIX "Create sysfs link\n");
  851. } else {
  852. /* Remove the brightness object. */
  853. kfree(device->brightness->levels);
  854. kfree(device->brightness);
  855. device->brightness = NULL;
  856. }
  857. }
  858. /*
  859. * Arg:
  860. * device : video output device (VGA)
  861. *
  862. * Return Value:
  863. * None
  864. *
  865. * Find out all required AML methods defined under the video bus device.
  866. */
  867. static void acpi_video_bus_find_cap(struct acpi_video_bus *video)
  868. {
  869. acpi_handle h_dummy1;
  870. if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_DOS", &h_dummy1)))
  871. video->cap._DOS = 1;
  872. if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_DOD", &h_dummy1)))
  873. video->cap._DOD = 1;
  874. if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_ROM", &h_dummy1)))
  875. video->cap._ROM = 1;
  876. if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_GPD", &h_dummy1)))
  877. video->cap._GPD = 1;
  878. if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_SPD", &h_dummy1)))
  879. video->cap._SPD = 1;
  880. if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_VPO", &h_dummy1)))
  881. video->cap._VPO = 1;
  882. }
  883. /*
  884. * Check whether the video bus device has required AML method to
  885. * support the desired features
  886. */
  887. static int acpi_video_bus_check(struct acpi_video_bus *video)
  888. {
  889. acpi_status status = -ENOENT;
  890. struct pci_dev *dev;
  891. if (!video)
  892. return -EINVAL;
  893. dev = acpi_get_pci_dev(video->device->handle);
  894. if (!dev)
  895. return -ENODEV;
  896. pci_dev_put(dev);
  897. /*
  898. * Since there is no HID, CID and so on for VGA driver, we have
  899. * to check well known required nodes.
  900. */
  901. /* Does this device support video switching? */
  902. if (video->cap._DOS || video->cap._DOD) {
  903. if (!video->cap._DOS) {
  904. printk(KERN_WARNING FW_BUG
  905. "ACPI(%s) defines _DOD but not _DOS\n",
  906. acpi_device_bid(video->device));
  907. }
  908. video->flags.multihead = 1;
  909. status = 0;
  910. }
  911. /* Does this device support retrieving a video ROM? */
  912. if (video->cap._ROM) {
  913. video->flags.rom = 1;
  914. status = 0;
  915. }
  916. /* Does this device support configuring which video device to POST? */
  917. if (video->cap._GPD && video->cap._SPD && video->cap._VPO) {
  918. video->flags.post = 1;
  919. status = 0;
  920. }
  921. return status;
  922. }
  923. /*
  924. * --------------------------------------------------------------------------
  925. * Driver Interface
  926. * --------------------------------------------------------------------------
  927. */
  928. /* device interface */
  929. static struct acpi_video_device_attrib *
  930. acpi_video_get_device_attr(struct acpi_video_bus *video, unsigned long device_id)
  931. {
  932. struct acpi_video_enumerated_device *ids;
  933. int i;
  934. for (i = 0; i < video->attached_count; i++) {
  935. ids = &video->attached_array[i];
  936. if ((ids->value.int_val & 0xffff) == device_id)
  937. return &ids->value.attrib;
  938. }
  939. return NULL;
  940. }
  941. static int
  942. acpi_video_get_device_type(struct acpi_video_bus *video,
  943. unsigned long device_id)
  944. {
  945. struct acpi_video_enumerated_device *ids;
  946. int i;
  947. for (i = 0; i < video->attached_count; i++) {
  948. ids = &video->attached_array[i];
  949. if ((ids->value.int_val & 0xffff) == device_id)
  950. return ids->value.int_val;
  951. }
  952. return 0;
  953. }
  954. static int
  955. acpi_video_bus_get_one_device(struct acpi_device *device,
  956. struct acpi_video_bus *video)
  957. {
  958. unsigned long long device_id;
  959. int status, device_type;
  960. struct acpi_video_device *data;
  961. struct acpi_video_device_attrib *attribute;
  962. status =
  963. acpi_evaluate_integer(device->handle, "_ADR", NULL, &device_id);
  964. /* Some device omits _ADR, we skip them instead of fail */
  965. if (ACPI_FAILURE(status))
  966. return 0;
  967. data = kzalloc(sizeof(struct acpi_video_device), GFP_KERNEL);
  968. if (!data)
  969. return -ENOMEM;
  970. strcpy(acpi_device_name(device), ACPI_VIDEO_DEVICE_NAME);
  971. strcpy(acpi_device_class(device), ACPI_VIDEO_CLASS);
  972. device->driver_data = data;
  973. data->device_id = device_id;
  974. data->video = video;
  975. data->dev = device;
  976. attribute = acpi_video_get_device_attr(video, device_id);
  977. if (attribute && attribute->device_id_scheme) {
  978. switch (attribute->display_type) {
  979. case ACPI_VIDEO_DISPLAY_CRT:
  980. data->flags.crt = 1;
  981. break;
  982. case ACPI_VIDEO_DISPLAY_TV:
  983. data->flags.tvout = 1;
  984. break;
  985. case ACPI_VIDEO_DISPLAY_DVI:
  986. data->flags.dvi = 1;
  987. break;
  988. case ACPI_VIDEO_DISPLAY_LCD:
  989. data->flags.lcd = 1;
  990. break;
  991. default:
  992. data->flags.unknown = 1;
  993. break;
  994. }
  995. if (attribute->bios_can_detect)
  996. data->flags.bios = 1;
  997. } else {
  998. /* Check for legacy IDs */
  999. device_type = acpi_video_get_device_type(video, device_id);
  1000. /* Ignore bits 16 and 18-20 */
  1001. switch (device_type & 0xffe2ffff) {
  1002. case ACPI_VIDEO_DISPLAY_LEGACY_MONITOR:
  1003. data->flags.crt = 1;
  1004. break;
  1005. case ACPI_VIDEO_DISPLAY_LEGACY_PANEL:
  1006. data->flags.lcd = 1;
  1007. break;
  1008. case ACPI_VIDEO_DISPLAY_LEGACY_TV:
  1009. data->flags.tvout = 1;
  1010. break;
  1011. default:
  1012. data->flags.unknown = 1;
  1013. }
  1014. }
  1015. acpi_video_device_bind(video, data);
  1016. acpi_video_device_find_cap(data);
  1017. status = acpi_install_notify_handler(device->handle, ACPI_DEVICE_NOTIFY,
  1018. acpi_video_device_notify, data);
  1019. if (ACPI_FAILURE(status))
  1020. dev_err(&device->dev, "Error installing notify handler\n");
  1021. else
  1022. data->flags.notify = 1;
  1023. mutex_lock(&video->device_list_lock);
  1024. list_add_tail(&data->entry, &video->video_device_list);
  1025. mutex_unlock(&video->device_list_lock);
  1026. return status;
  1027. }
  1028. /*
  1029. * Arg:
  1030. * video : video bus device
  1031. *
  1032. * Return:
  1033. * none
  1034. *
  1035. * Enumerate the video device list of the video bus,
  1036. * bind the ids with the corresponding video devices
  1037. * under the video bus.
  1038. */
  1039. static void acpi_video_device_rebind(struct acpi_video_bus *video)
  1040. {
  1041. struct acpi_video_device *dev;
  1042. mutex_lock(&video->device_list_lock);
  1043. list_for_each_entry(dev, &video->video_device_list, entry)
  1044. acpi_video_device_bind(video, dev);
  1045. mutex_unlock(&video->device_list_lock);
  1046. }
  1047. /*
  1048. * Arg:
  1049. * video : video bus device
  1050. * device : video output device under the video
  1051. * bus
  1052. *
  1053. * Return:
  1054. * none
  1055. *
  1056. * Bind the ids with the corresponding video devices
  1057. * under the video bus.
  1058. */
  1059. static void
  1060. acpi_video_device_bind(struct acpi_video_bus *video,
  1061. struct acpi_video_device *device)
  1062. {
  1063. struct acpi_video_enumerated_device *ids;
  1064. int i;
  1065. for (i = 0; i < video->attached_count; i++) {
  1066. ids = &video->attached_array[i];
  1067. if (device->device_id == (ids->value.int_val & 0xffff)) {
  1068. ids->bind_info = device;
  1069. ACPI_DEBUG_PRINT((ACPI_DB_INFO, "device_bind %d\n", i));
  1070. }
  1071. }
  1072. }
  1073. /*
  1074. * Arg:
  1075. * video : video bus device
  1076. *
  1077. * Return:
  1078. * < 0 : error
  1079. *
  1080. * Call _DOD to enumerate all devices attached to display adapter
  1081. *
  1082. */
  1083. static int acpi_video_device_enumerate(struct acpi_video_bus *video)
  1084. {
  1085. int status;
  1086. int count;
  1087. int i;
  1088. struct acpi_video_enumerated_device *active_list;
  1089. struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
  1090. union acpi_object *dod = NULL;
  1091. union acpi_object *obj;
  1092. status = acpi_evaluate_object(video->device->handle, "_DOD", NULL, &buffer);
  1093. if (!ACPI_SUCCESS(status)) {
  1094. ACPI_EXCEPTION((AE_INFO, status, "Evaluating _DOD"));
  1095. return status;
  1096. }
  1097. dod = buffer.pointer;
  1098. if (!dod || (dod->type != ACPI_TYPE_PACKAGE)) {
  1099. ACPI_EXCEPTION((AE_INFO, status, "Invalid _DOD data"));
  1100. status = -EFAULT;
  1101. goto out;
  1102. }
  1103. ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found %d video heads in _DOD\n",
  1104. dod->package.count));
  1105. active_list = kcalloc(1 + dod->package.count,
  1106. sizeof(struct acpi_video_enumerated_device),
  1107. GFP_KERNEL);
  1108. if (!active_list) {
  1109. status = -ENOMEM;
  1110. goto out;
  1111. }
  1112. count = 0;
  1113. for (i = 0; i < dod->package.count; i++) {
  1114. obj = &dod->package.elements[i];
  1115. if (obj->type != ACPI_TYPE_INTEGER) {
  1116. printk(KERN_ERR PREFIX
  1117. "Invalid _DOD data in element %d\n", i);
  1118. continue;
  1119. }
  1120. active_list[count].value.int_val = obj->integer.value;
  1121. active_list[count].bind_info = NULL;
  1122. ACPI_DEBUG_PRINT((ACPI_DB_INFO, "dod element[%d] = %d\n", i,
  1123. (int)obj->integer.value));
  1124. count++;
  1125. }
  1126. kfree(video->attached_array);
  1127. video->attached_array = active_list;
  1128. video->attached_count = count;
  1129. out:
  1130. kfree(buffer.pointer);
  1131. return status;
  1132. }
  1133. static int
  1134. acpi_video_get_next_level(struct acpi_video_device *device,
  1135. u32 level_current, u32 event)
  1136. {
  1137. int min, max, min_above, max_below, i, l, delta = 255;
  1138. max = max_below = 0;
  1139. min = min_above = 255;
  1140. /* Find closest level to level_current */
  1141. for (i = 2; i < device->brightness->count; i++) {
  1142. l = device->brightness->levels[i];
  1143. if (abs(l - level_current) < abs(delta)) {
  1144. delta = l - level_current;
  1145. if (!delta)
  1146. break;
  1147. }
  1148. }
  1149. /* Ajust level_current to closest available level */
  1150. level_current += delta;
  1151. for (i = 2; i < device->brightness->count; i++) {
  1152. l = device->brightness->levels[i];
  1153. if (l < min)
  1154. min = l;
  1155. if (l > max)
  1156. max = l;
  1157. if (l < min_above && l > level_current)
  1158. min_above = l;
  1159. if (l > max_below && l < level_current)
  1160. max_below = l;
  1161. }
  1162. switch (event) {
  1163. case ACPI_VIDEO_NOTIFY_CYCLE_BRIGHTNESS:
  1164. return (level_current < max) ? min_above : min;
  1165. case ACPI_VIDEO_NOTIFY_INC_BRIGHTNESS:
  1166. return (level_current < max) ? min_above : max;
  1167. case ACPI_VIDEO_NOTIFY_DEC_BRIGHTNESS:
  1168. return (level_current > min) ? max_below : min;
  1169. case ACPI_VIDEO_NOTIFY_ZERO_BRIGHTNESS:
  1170. case ACPI_VIDEO_NOTIFY_DISPLAY_OFF:
  1171. return 0;
  1172. default:
  1173. return level_current;
  1174. }
  1175. }
  1176. static int
  1177. acpi_video_switch_brightness(struct acpi_video_device *device, int event)
  1178. {
  1179. unsigned long long level_current, level_next;
  1180. int result = -EINVAL;
  1181. /* no warning message if acpi_backlight=vendor is used */
  1182. if (!acpi_video_backlight_support())
  1183. return 0;
  1184. if (!device->brightness)
  1185. goto out;
  1186. result = acpi_video_device_lcd_get_level_current(device,
  1187. &level_current,
  1188. false);
  1189. if (result)
  1190. goto out;
  1191. level_next = acpi_video_get_next_level(device, level_current, event);
  1192. result = acpi_video_device_lcd_set_level(device, level_next);
  1193. if (!result)
  1194. backlight_force_update(device->backlight,
  1195. BACKLIGHT_UPDATE_HOTKEY);
  1196. out:
  1197. if (result)
  1198. printk(KERN_ERR PREFIX "Failed to switch the brightness\n");
  1199. return result;
  1200. }
  1201. int acpi_video_get_edid(struct acpi_device *device, int type, int device_id,
  1202. void **edid)
  1203. {
  1204. struct acpi_video_bus *video;
  1205. struct acpi_video_device *video_device;
  1206. union acpi_object *buffer = NULL;
  1207. acpi_status status;
  1208. int i, length;
  1209. if (!device || !acpi_driver_data(device))
  1210. return -EINVAL;
  1211. video = acpi_driver_data(device);
  1212. for (i = 0; i < video->attached_count; i++) {
  1213. video_device = video->attached_array[i].bind_info;
  1214. length = 256;
  1215. if (!video_device)
  1216. continue;
  1217. if (!video_device->cap._DDC)
  1218. continue;
  1219. if (type) {
  1220. switch (type) {
  1221. case ACPI_VIDEO_DISPLAY_CRT:
  1222. if (!video_device->flags.crt)
  1223. continue;
  1224. break;
  1225. case ACPI_VIDEO_DISPLAY_TV:
  1226. if (!video_device->flags.tvout)
  1227. continue;
  1228. break;
  1229. case ACPI_VIDEO_DISPLAY_DVI:
  1230. if (!video_device->flags.dvi)
  1231. continue;
  1232. break;
  1233. case ACPI_VIDEO_DISPLAY_LCD:
  1234. if (!video_device->flags.lcd)
  1235. continue;
  1236. break;
  1237. }
  1238. } else if (video_device->device_id != device_id) {
  1239. continue;
  1240. }
  1241. status = acpi_video_device_EDID(video_device, &buffer, length);
  1242. if (ACPI_FAILURE(status) || !buffer ||
  1243. buffer->type != ACPI_TYPE_BUFFER) {
  1244. length = 128;
  1245. status = acpi_video_device_EDID(video_device, &buffer,
  1246. length);
  1247. if (ACPI_FAILURE(status) || !buffer ||
  1248. buffer->type != ACPI_TYPE_BUFFER) {
  1249. continue;
  1250. }
  1251. }
  1252. *edid = buffer->buffer.pointer;
  1253. return length;
  1254. }
  1255. return -ENODEV;
  1256. }
  1257. EXPORT_SYMBOL(acpi_video_get_edid);
  1258. static int
  1259. acpi_video_bus_get_devices(struct acpi_video_bus *video,
  1260. struct acpi_device *device)
  1261. {
  1262. int status = 0;
  1263. struct acpi_device *dev;
  1264. /*
  1265. * There are systems where video module known to work fine regardless
  1266. * of broken _DOD and ignoring returned value here doesn't cause
  1267. * any issues later.
  1268. */
  1269. acpi_video_device_enumerate(video);
  1270. list_for_each_entry(dev, &device->children, node) {
  1271. status = acpi_video_bus_get_one_device(dev, video);
  1272. if (status) {
  1273. dev_err(&dev->dev, "Can't attach device\n");
  1274. break;
  1275. }
  1276. }
  1277. return status;
  1278. }
  1279. static int acpi_video_bus_put_one_device(struct acpi_video_device *device)
  1280. {
  1281. acpi_status status;
  1282. if (!device || !device->video)
  1283. return -ENOENT;
  1284. if (device->flags.notify) {
  1285. status = acpi_remove_notify_handler(device->dev->handle,
  1286. ACPI_DEVICE_NOTIFY, acpi_video_device_notify);
  1287. if (ACPI_FAILURE(status))
  1288. dev_err(&device->dev->dev,
  1289. "Can't remove video notify handler\n");
  1290. }
  1291. if (device->backlight) {
  1292. backlight_device_unregister(device->backlight);
  1293. device->backlight = NULL;
  1294. }
  1295. if (device->cooling_dev) {
  1296. sysfs_remove_link(&device->dev->dev.kobj,
  1297. "thermal_cooling");
  1298. sysfs_remove_link(&device->cooling_dev->device.kobj,
  1299. "device");
  1300. thermal_cooling_device_unregister(device->cooling_dev);
  1301. device->cooling_dev = NULL;
  1302. }
  1303. return 0;
  1304. }
  1305. static int acpi_video_bus_put_devices(struct acpi_video_bus *video)
  1306. {
  1307. int status;
  1308. struct acpi_video_device *dev, *next;
  1309. mutex_lock(&video->device_list_lock);
  1310. list_for_each_entry_safe(dev, next, &video->video_device_list, entry) {
  1311. status = acpi_video_bus_put_one_device(dev);
  1312. if (ACPI_FAILURE(status))
  1313. printk(KERN_WARNING PREFIX
  1314. "hhuuhhuu bug in acpi video driver.\n");
  1315. if (dev->brightness) {
  1316. kfree(dev->brightness->levels);
  1317. kfree(dev->brightness);
  1318. }
  1319. list_del(&dev->entry);
  1320. kfree(dev);
  1321. }
  1322. mutex_unlock(&video->device_list_lock);
  1323. return 0;
  1324. }
  1325. /* acpi_video interface */
  1326. /*
  1327. * Win8 requires setting bit2 of _DOS to let firmware know it shouldn't
  1328. * preform any automatic brightness change on receiving a notification.
  1329. */
  1330. static int acpi_video_bus_start_devices(struct acpi_video_bus *video)
  1331. {
  1332. return acpi_video_bus_DOS(video, 0,
  1333. acpi_video_backlight_quirks() ? 1 : 0);
  1334. }
  1335. static int acpi_video_bus_stop_devices(struct acpi_video_bus *video)
  1336. {
  1337. return acpi_video_bus_DOS(video, 0,
  1338. acpi_video_backlight_quirks() ? 0 : 1);
  1339. }
  1340. static void acpi_video_bus_notify(struct acpi_device *device, u32 event)
  1341. {
  1342. struct acpi_video_bus *video = acpi_driver_data(device);
  1343. struct input_dev *input;
  1344. int keycode = 0;
  1345. if (!video)
  1346. return;
  1347. input = video->input;
  1348. switch (event) {
  1349. case ACPI_VIDEO_NOTIFY_SWITCH: /* User requested a switch,
  1350. * most likely via hotkey. */
  1351. acpi_bus_generate_proc_event(device, event, 0);
  1352. keycode = KEY_SWITCHVIDEOMODE;
  1353. break;
  1354. case ACPI_VIDEO_NOTIFY_PROBE: /* User plugged in or removed a video
  1355. * connector. */
  1356. acpi_video_device_enumerate(video);
  1357. acpi_video_device_rebind(video);
  1358. acpi_bus_generate_proc_event(device, event, 0);
  1359. keycode = KEY_SWITCHVIDEOMODE;
  1360. break;
  1361. case ACPI_VIDEO_NOTIFY_CYCLE: /* Cycle Display output hotkey pressed. */
  1362. acpi_bus_generate_proc_event(device, event, 0);
  1363. keycode = KEY_SWITCHVIDEOMODE;
  1364. break;
  1365. case ACPI_VIDEO_NOTIFY_NEXT_OUTPUT: /* Next Display output hotkey pressed. */
  1366. acpi_bus_generate_proc_event(device, event, 0);
  1367. keycode = KEY_VIDEO_NEXT;
  1368. break;
  1369. case ACPI_VIDEO_NOTIFY_PREV_OUTPUT: /* previous Display output hotkey pressed. */
  1370. acpi_bus_generate_proc_event(device, event, 0);
  1371. keycode = KEY_VIDEO_PREV;
  1372. break;
  1373. default:
  1374. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  1375. "Unsupported event [0x%x]\n", event));
  1376. break;
  1377. }
  1378. if (acpi_notifier_call_chain(device, event, 0))
  1379. /* Something vetoed the keypress. */
  1380. keycode = 0;
  1381. if (keycode) {
  1382. input_report_key(input, keycode, 1);
  1383. input_sync(input);
  1384. input_report_key(input, keycode, 0);
  1385. input_sync(input);
  1386. }
  1387. return;
  1388. }
  1389. static void acpi_video_device_notify(acpi_handle handle, u32 event, void *data)
  1390. {
  1391. struct acpi_video_device *video_device = data;
  1392. struct acpi_device *device = NULL;
  1393. struct acpi_video_bus *bus;
  1394. struct input_dev *input;
  1395. int keycode = 0;
  1396. if (!video_device)
  1397. return;
  1398. device = video_device->dev;
  1399. bus = video_device->video;
  1400. input = bus->input;
  1401. switch (event) {
  1402. case ACPI_VIDEO_NOTIFY_CYCLE_BRIGHTNESS: /* Cycle brightness */
  1403. if (brightness_switch_enabled)
  1404. acpi_video_switch_brightness(video_device, event);
  1405. acpi_bus_generate_proc_event(device, event, 0);
  1406. keycode = KEY_BRIGHTNESS_CYCLE;
  1407. break;
  1408. case ACPI_VIDEO_NOTIFY_INC_BRIGHTNESS: /* Increase brightness */
  1409. if (brightness_switch_enabled)
  1410. acpi_video_switch_brightness(video_device, event);
  1411. acpi_bus_generate_proc_event(device, event, 0);
  1412. keycode = KEY_BRIGHTNESSUP;
  1413. break;
  1414. case ACPI_VIDEO_NOTIFY_DEC_BRIGHTNESS: /* Decrease brightness */
  1415. if (brightness_switch_enabled)
  1416. acpi_video_switch_brightness(video_device, event);
  1417. acpi_bus_generate_proc_event(device, event, 0);
  1418. keycode = KEY_BRIGHTNESSDOWN;
  1419. break;
  1420. case ACPI_VIDEO_NOTIFY_ZERO_BRIGHTNESS: /* zero brightness */
  1421. if (brightness_switch_enabled)
  1422. acpi_video_switch_brightness(video_device, event);
  1423. acpi_bus_generate_proc_event(device, event, 0);
  1424. keycode = KEY_BRIGHTNESS_ZERO;
  1425. break;
  1426. case ACPI_VIDEO_NOTIFY_DISPLAY_OFF: /* display device off */
  1427. if (brightness_switch_enabled)
  1428. acpi_video_switch_brightness(video_device, event);
  1429. acpi_bus_generate_proc_event(device, event, 0);
  1430. keycode = KEY_DISPLAY_OFF;
  1431. break;
  1432. default:
  1433. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  1434. "Unsupported event [0x%x]\n", event));
  1435. break;
  1436. }
  1437. acpi_notifier_call_chain(device, event, 0);
  1438. if (keycode) {
  1439. input_report_key(input, keycode, 1);
  1440. input_sync(input);
  1441. input_report_key(input, keycode, 0);
  1442. input_sync(input);
  1443. }
  1444. return;
  1445. }
  1446. static int acpi_video_resume(struct notifier_block *nb,
  1447. unsigned long val, void *ign)
  1448. {
  1449. struct acpi_video_bus *video;
  1450. struct acpi_video_device *video_device;
  1451. int i;
  1452. switch (val) {
  1453. case PM_HIBERNATION_PREPARE:
  1454. case PM_SUSPEND_PREPARE:
  1455. case PM_RESTORE_PREPARE:
  1456. return NOTIFY_DONE;
  1457. }
  1458. video = container_of(nb, struct acpi_video_bus, pm_nb);
  1459. dev_info(&video->device->dev, "Restoring backlight state\n");
  1460. for (i = 0; i < video->attached_count; i++) {
  1461. video_device = video->attached_array[i].bind_info;
  1462. if (video_device && video_device->backlight)
  1463. acpi_video_set_brightness(video_device->backlight);
  1464. }
  1465. return NOTIFY_OK;
  1466. }
  1467. static acpi_status
  1468. acpi_video_bus_match(acpi_handle handle, u32 level, void *context,
  1469. void **return_value)
  1470. {
  1471. struct acpi_device *device = context;
  1472. struct acpi_device *sibling;
  1473. int result;
  1474. if (handle == device->handle)
  1475. return AE_CTRL_TERMINATE;
  1476. result = acpi_bus_get_device(handle, &sibling);
  1477. if (result)
  1478. return AE_OK;
  1479. if (!strcmp(acpi_device_name(sibling), ACPI_VIDEO_BUS_NAME))
  1480. return AE_ALREADY_EXISTS;
  1481. return AE_OK;
  1482. }
  1483. static int instance;
  1484. static int acpi_video_bus_add(struct acpi_device *device)
  1485. {
  1486. struct acpi_video_bus *video;
  1487. struct input_dev *input;
  1488. int error;
  1489. acpi_status status;
  1490. status = acpi_walk_namespace(ACPI_TYPE_DEVICE,
  1491. device->parent->handle, 1,
  1492. acpi_video_bus_match, NULL,
  1493. device, NULL);
  1494. if (status == AE_ALREADY_EXISTS) {
  1495. printk(KERN_WARNING FW_BUG
  1496. "Duplicate ACPI video bus devices for the"
  1497. " same VGA controller, please try module "
  1498. "parameter \"video.allow_duplicates=1\""
  1499. "if the current driver doesn't work.\n");
  1500. if (!allow_duplicates)
  1501. return -ENODEV;
  1502. }
  1503. video = kzalloc(sizeof(struct acpi_video_bus), GFP_KERNEL);
  1504. if (!video)
  1505. return -ENOMEM;
  1506. /* a hack to fix the duplicate name "VID" problem on T61 */
  1507. if (!strcmp(device->pnp.bus_id, "VID")) {
  1508. if (instance)
  1509. device->pnp.bus_id[3] = '0' + instance;
  1510. instance++;
  1511. }
  1512. /* a hack to fix the duplicate name "VGA" problem on Pa 3553 */
  1513. if (!strcmp(device->pnp.bus_id, "VGA")) {
  1514. if (instance)
  1515. device->pnp.bus_id[3] = '0' + instance;
  1516. instance++;
  1517. }
  1518. video->device = device;
  1519. strcpy(acpi_device_name(device), ACPI_VIDEO_BUS_NAME);
  1520. strcpy(acpi_device_class(device), ACPI_VIDEO_CLASS);
  1521. device->driver_data = video;
  1522. acpi_video_bus_find_cap(video);
  1523. error = acpi_video_bus_check(video);
  1524. if (error)
  1525. goto err_free_video;
  1526. mutex_init(&video->device_list_lock);
  1527. INIT_LIST_HEAD(&video->video_device_list);
  1528. error = acpi_video_bus_get_devices(video, device);
  1529. if (error)
  1530. goto err_put_video;
  1531. video->input = input = input_allocate_device();
  1532. if (!input) {
  1533. error = -ENOMEM;
  1534. goto err_put_video;
  1535. }
  1536. error = acpi_video_bus_start_devices(video);
  1537. if (error)
  1538. goto err_free_input_dev;
  1539. snprintf(video->phys, sizeof(video->phys),
  1540. "%s/video/input0", acpi_device_hid(video->device));
  1541. input->name = acpi_device_name(video->device);
  1542. input->phys = video->phys;
  1543. input->id.bustype = BUS_HOST;
  1544. input->id.product = 0x06;
  1545. input->dev.parent = &device->dev;
  1546. input->evbit[0] = BIT(EV_KEY);
  1547. set_bit(KEY_SWITCHVIDEOMODE, input->keybit);
  1548. set_bit(KEY_VIDEO_NEXT, input->keybit);
  1549. set_bit(KEY_VIDEO_PREV, input->keybit);
  1550. set_bit(KEY_BRIGHTNESS_CYCLE, input->keybit);
  1551. set_bit(KEY_BRIGHTNESSUP, input->keybit);
  1552. set_bit(KEY_BRIGHTNESSDOWN, input->keybit);
  1553. set_bit(KEY_BRIGHTNESS_ZERO, input->keybit);
  1554. set_bit(KEY_DISPLAY_OFF, input->keybit);
  1555. printk(KERN_INFO PREFIX "%s [%s] (multi-head: %s rom: %s post: %s)\n",
  1556. ACPI_VIDEO_DEVICE_NAME, acpi_device_bid(device),
  1557. video->flags.multihead ? "yes" : "no",
  1558. video->flags.rom ? "yes" : "no",
  1559. video->flags.post ? "yes" : "no");
  1560. video->pm_nb.notifier_call = acpi_video_resume;
  1561. video->pm_nb.priority = 0;
  1562. error = register_pm_notifier(&video->pm_nb);
  1563. if (error)
  1564. goto err_stop_video;
  1565. error = input_register_device(input);
  1566. if (error)
  1567. goto err_unregister_pm_notifier;
  1568. return 0;
  1569. err_unregister_pm_notifier:
  1570. unregister_pm_notifier(&video->pm_nb);
  1571. err_stop_video:
  1572. acpi_video_bus_stop_devices(video);
  1573. err_free_input_dev:
  1574. input_free_device(input);
  1575. err_put_video:
  1576. acpi_video_bus_put_devices(video);
  1577. kfree(video->attached_array);
  1578. err_free_video:
  1579. kfree(video);
  1580. device->driver_data = NULL;
  1581. return error;
  1582. }
  1583. static int acpi_video_bus_remove(struct acpi_device *device)
  1584. {
  1585. struct acpi_video_bus *video = NULL;
  1586. if (!device || !acpi_driver_data(device))
  1587. return -EINVAL;
  1588. video = acpi_driver_data(device);
  1589. unregister_pm_notifier(&video->pm_nb);
  1590. acpi_video_bus_stop_devices(video);
  1591. acpi_video_bus_put_devices(video);
  1592. input_unregister_device(video->input);
  1593. kfree(video->attached_array);
  1594. kfree(video);
  1595. return 0;
  1596. }
  1597. static int __init is_i740(struct pci_dev *dev)
  1598. {
  1599. if (dev->device == 0x00D1)
  1600. return 1;
  1601. if (dev->device == 0x7000)
  1602. return 1;
  1603. return 0;
  1604. }
  1605. static int __init intel_opregion_present(void)
  1606. {
  1607. int opregion = 0;
  1608. struct pci_dev *dev = NULL;
  1609. u32 address;
  1610. for_each_pci_dev(dev) {
  1611. if ((dev->class >> 8) != PCI_CLASS_DISPLAY_VGA)
  1612. continue;
  1613. if (dev->vendor != PCI_VENDOR_ID_INTEL)
  1614. continue;
  1615. /* We don't want to poke around undefined i740 registers */
  1616. if (is_i740(dev))
  1617. continue;
  1618. pci_read_config_dword(dev, 0xfc, &address);
  1619. if (!address)
  1620. continue;
  1621. opregion = 1;
  1622. }
  1623. return opregion;
  1624. }
  1625. int acpi_video_register(void)
  1626. {
  1627. int result = 0;
  1628. if (register_count) {
  1629. /*
  1630. * if the function of acpi_video_register is already called,
  1631. * don't register the acpi_vide_bus again and return no error.
  1632. */
  1633. return 0;
  1634. }
  1635. result = acpi_bus_register_driver(&acpi_video_bus);
  1636. if (result < 0)
  1637. return -ENODEV;
  1638. /*
  1639. * When the acpi_video_bus is loaded successfully, increase
  1640. * the counter reference.
  1641. */
  1642. register_count = 1;
  1643. return 0;
  1644. }
  1645. EXPORT_SYMBOL(acpi_video_register);
  1646. void acpi_video_unregister(void)
  1647. {
  1648. if (!register_count) {
  1649. /*
  1650. * If the acpi video bus is already unloaded, don't
  1651. * unload it again and return directly.
  1652. */
  1653. return;
  1654. }
  1655. acpi_bus_unregister_driver(&acpi_video_bus);
  1656. register_count = 0;
  1657. return;
  1658. }
  1659. EXPORT_SYMBOL(acpi_video_unregister);
  1660. /*
  1661. * This is kind of nasty. Hardware using Intel chipsets may require
  1662. * the video opregion code to be run first in order to initialise
  1663. * state before any ACPI video calls are made. To handle this we defer
  1664. * registration of the video class until the opregion code has run.
  1665. */
  1666. static int __init acpi_video_init(void)
  1667. {
  1668. dmi_check_system(video_dmi_table);
  1669. if (intel_opregion_present())
  1670. return 0;
  1671. return acpi_video_register();
  1672. }
  1673. static void __exit acpi_video_exit(void)
  1674. {
  1675. acpi_video_unregister();
  1676. return;
  1677. }
  1678. module_init(acpi_video_init);
  1679. module_exit(acpi_video_exit);