video.c 50 KB

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