video.c 50 KB

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