video.c 50 KB

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