video.c 49 KB

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