video.c 49 KB

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