video.c 48 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912
  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. *
  7. * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License as published by
  11. * the Free Software Foundation; either version 2 of the License, or (at
  12. * your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful, but
  15. * WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  17. * General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License along
  20. * with this program; if not, write to the Free Software Foundation, Inc.,
  21. * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
  22. *
  23. * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  24. */
  25. #include <linux/kernel.h>
  26. #include <linux/module.h>
  27. #include <linux/init.h>
  28. #include <linux/types.h>
  29. #include <linux/list.h>
  30. #include <linux/proc_fs.h>
  31. #include <linux/seq_file.h>
  32. #include <asm/uaccess.h>
  33. #include <acpi/acpi_bus.h>
  34. #include <acpi/acpi_drivers.h>
  35. #define ACPI_VIDEO_COMPONENT 0x08000000
  36. #define ACPI_VIDEO_CLASS "video"
  37. #define ACPI_VIDEO_DRIVER_NAME "ACPI Video Driver"
  38. #define ACPI_VIDEO_BUS_NAME "Video Bus"
  39. #define ACPI_VIDEO_DEVICE_NAME "Video Device"
  40. #define ACPI_VIDEO_NOTIFY_SWITCH 0x80
  41. #define ACPI_VIDEO_NOTIFY_PROBE 0x81
  42. #define ACPI_VIDEO_NOTIFY_CYCLE 0x82
  43. #define ACPI_VIDEO_NOTIFY_NEXT_OUTPUT 0x83
  44. #define ACPI_VIDEO_NOTIFY_PREV_OUTPUT 0x84
  45. #define ACPI_VIDEO_NOTIFY_CYCLE_BRIGHTNESS 0x82
  46. #define ACPI_VIDEO_NOTIFY_INC_BRIGHTNESS 0x83
  47. #define ACPI_VIDEO_NOTIFY_DEC_BRIGHTNESS 0x84
  48. #define ACPI_VIDEO_NOTIFY_ZERO_BRIGHTNESS 0x85
  49. #define ACPI_VIDEO_NOTIFY_DISPLAY_OFF 0x86
  50. #define ACPI_VIDEO_HEAD_INVALID (~0u - 1)
  51. #define ACPI_VIDEO_HEAD_END (~0u)
  52. #define _COMPONENT ACPI_VIDEO_COMPONENT
  53. ACPI_MODULE_NAME("acpi_video")
  54. MODULE_AUTHOR("Bruno Ducrot");
  55. MODULE_DESCRIPTION(ACPI_VIDEO_DRIVER_NAME);
  56. MODULE_LICENSE("GPL");
  57. static int acpi_video_bus_add(struct acpi_device *device);
  58. static int acpi_video_bus_remove(struct acpi_device *device, int type);
  59. static int acpi_video_bus_match(struct acpi_device *device,
  60. struct acpi_driver *driver);
  61. static struct acpi_driver acpi_video_bus = {
  62. .name = ACPI_VIDEO_DRIVER_NAME,
  63. .class = ACPI_VIDEO_CLASS,
  64. .ops = {
  65. .add = acpi_video_bus_add,
  66. .remove = acpi_video_bus_remove,
  67. .match = acpi_video_bus_match,
  68. },
  69. };
  70. struct acpi_video_bus_flags {
  71. u8 multihead:1; /* can switch video heads */
  72. u8 rom:1; /* can retrieve a video rom */
  73. u8 post:1; /* can configure the head to */
  74. u8 reserved:5;
  75. };
  76. struct acpi_video_bus_cap {
  77. u8 _DOS:1; /*Enable/Disable output switching */
  78. u8 _DOD:1; /*Enumerate all devices attached to display adapter */
  79. u8 _ROM:1; /*Get ROM Data */
  80. u8 _GPD:1; /*Get POST Device */
  81. u8 _SPD:1; /*Set POST Device */
  82. u8 _VPO:1; /*Video POST Options */
  83. u8 reserved:2;
  84. };
  85. struct acpi_video_device_attrib {
  86. u32 display_index:4; /* A zero-based instance of the Display */
  87. u32 display_port_attachment:4; /*This field differenates displays type */
  88. u32 display_type:4; /*Describe the specific type in use */
  89. u32 vendor_specific:4; /*Chipset Vendor Specifi */
  90. u32 bios_can_detect:1; /*BIOS can detect the device */
  91. u32 depend_on_vga:1; /*Non-VGA output device whose power is related to
  92. the VGA device. */
  93. u32 pipe_id:3; /*For VGA multiple-head devices. */
  94. u32 reserved:10; /*Must be 0 */
  95. u32 device_id_scheme:1; /*Device ID Scheme */
  96. };
  97. struct acpi_video_enumerated_device {
  98. union {
  99. u32 int_val;
  100. struct acpi_video_device_attrib attrib;
  101. } value;
  102. struct acpi_video_device *bind_info;
  103. };
  104. struct acpi_video_bus {
  105. acpi_handle handle;
  106. u8 dos_setting;
  107. struct acpi_video_enumerated_device *attached_array;
  108. u8 attached_count;
  109. struct acpi_video_bus_cap cap;
  110. struct acpi_video_bus_flags flags;
  111. struct semaphore sem;
  112. struct list_head video_device_list;
  113. struct proc_dir_entry *dir;
  114. };
  115. struct acpi_video_device_flags {
  116. u8 crt:1;
  117. u8 lcd:1;
  118. u8 tvout:1;
  119. u8 bios:1;
  120. u8 unknown:1;
  121. u8 reserved:3;
  122. };
  123. struct acpi_video_device_cap {
  124. u8 _ADR:1; /*Return the unique ID */
  125. u8 _BCL:1; /*Query list of brightness control levels supported */
  126. u8 _BCM:1; /*Set the brightness level */
  127. u8 _DDC:1; /*Return the EDID for this device */
  128. u8 _DCS:1; /*Return status of output device */
  129. u8 _DGS:1; /*Query graphics state */
  130. u8 _DSS:1; /*Device state set */
  131. u8 _reserved:1;
  132. };
  133. struct acpi_video_device_brightness {
  134. int curr;
  135. int count;
  136. int *levels;
  137. };
  138. struct acpi_video_device {
  139. acpi_handle handle;
  140. unsigned long device_id;
  141. struct acpi_video_device_flags flags;
  142. struct acpi_video_device_cap cap;
  143. struct list_head entry;
  144. struct acpi_video_bus *video;
  145. struct acpi_device *dev;
  146. struct acpi_video_device_brightness *brightness;
  147. };
  148. /* bus */
  149. static int acpi_video_bus_info_open_fs(struct inode *inode, struct file *file);
  150. static struct file_operations acpi_video_bus_info_fops = {
  151. .open = acpi_video_bus_info_open_fs,
  152. .read = seq_read,
  153. .llseek = seq_lseek,
  154. .release = single_release,
  155. };
  156. static int acpi_video_bus_ROM_open_fs(struct inode *inode, struct file *file);
  157. static struct file_operations acpi_video_bus_ROM_fops = {
  158. .open = acpi_video_bus_ROM_open_fs,
  159. .read = seq_read,
  160. .llseek = seq_lseek,
  161. .release = single_release,
  162. };
  163. static int acpi_video_bus_POST_info_open_fs(struct inode *inode,
  164. struct file *file);
  165. static struct file_operations acpi_video_bus_POST_info_fops = {
  166. .open = acpi_video_bus_POST_info_open_fs,
  167. .read = seq_read,
  168. .llseek = seq_lseek,
  169. .release = single_release,
  170. };
  171. static int acpi_video_bus_POST_open_fs(struct inode *inode, struct file *file);
  172. static struct file_operations acpi_video_bus_POST_fops = {
  173. .open = acpi_video_bus_POST_open_fs,
  174. .read = seq_read,
  175. .llseek = seq_lseek,
  176. .release = single_release,
  177. };
  178. static int acpi_video_bus_DOS_open_fs(struct inode *inode, struct file *file);
  179. static struct file_operations acpi_video_bus_DOS_fops = {
  180. .open = acpi_video_bus_DOS_open_fs,
  181. .read = seq_read,
  182. .llseek = seq_lseek,
  183. .release = single_release,
  184. };
  185. /* device */
  186. static int acpi_video_device_info_open_fs(struct inode *inode,
  187. struct file *file);
  188. static struct file_operations acpi_video_device_info_fops = {
  189. .open = acpi_video_device_info_open_fs,
  190. .read = seq_read,
  191. .llseek = seq_lseek,
  192. .release = single_release,
  193. };
  194. static int acpi_video_device_state_open_fs(struct inode *inode,
  195. struct file *file);
  196. static struct file_operations acpi_video_device_state_fops = {
  197. .open = acpi_video_device_state_open_fs,
  198. .read = seq_read,
  199. .llseek = seq_lseek,
  200. .release = single_release,
  201. };
  202. static int acpi_video_device_brightness_open_fs(struct inode *inode,
  203. struct file *file);
  204. static struct file_operations acpi_video_device_brightness_fops = {
  205. .open = acpi_video_device_brightness_open_fs,
  206. .read = seq_read,
  207. .llseek = seq_lseek,
  208. .release = single_release,
  209. };
  210. static int acpi_video_device_EDID_open_fs(struct inode *inode,
  211. struct file *file);
  212. static struct file_operations acpi_video_device_EDID_fops = {
  213. .open = acpi_video_device_EDID_open_fs,
  214. .read = seq_read,
  215. .llseek = seq_lseek,
  216. .release = single_release,
  217. };
  218. static char device_decode[][30] = {
  219. "motherboard VGA device",
  220. "PCI VGA device",
  221. "AGP VGA device",
  222. "UNKNOWN",
  223. };
  224. static void acpi_video_device_notify(acpi_handle handle, u32 event, void *data);
  225. static void acpi_video_device_rebind(struct acpi_video_bus *video);
  226. static void acpi_video_device_bind(struct acpi_video_bus *video,
  227. struct acpi_video_device *device);
  228. static int acpi_video_device_enumerate(struct acpi_video_bus *video);
  229. static int acpi_video_switch_output(struct acpi_video_bus *video, int event);
  230. static int acpi_video_get_next_level(struct acpi_video_device *device,
  231. u32 level_current, u32 event);
  232. static void acpi_video_switch_brightness(struct acpi_video_device *device,
  233. int event);
  234. /* --------------------------------------------------------------------------
  235. Video Management
  236. -------------------------------------------------------------------------- */
  237. /* device */
  238. static int
  239. acpi_video_device_query(struct acpi_video_device *device, unsigned long *state)
  240. {
  241. int status;
  242. ACPI_FUNCTION_TRACE("acpi_video_device_query");
  243. status = acpi_evaluate_integer(device->handle, "_DGS", NULL, state);
  244. return_VALUE(status);
  245. }
  246. static int
  247. acpi_video_device_get_state(struct acpi_video_device *device,
  248. unsigned long *state)
  249. {
  250. int status;
  251. ACPI_FUNCTION_TRACE("acpi_video_device_get_state");
  252. status = acpi_evaluate_integer(device->handle, "_DCS", NULL, state);
  253. return_VALUE(status);
  254. }
  255. static int
  256. acpi_video_device_set_state(struct acpi_video_device *device, int state)
  257. {
  258. int status;
  259. union acpi_object arg0 = { ACPI_TYPE_INTEGER };
  260. struct acpi_object_list args = { 1, &arg0 };
  261. unsigned long ret;
  262. ACPI_FUNCTION_TRACE("acpi_video_device_set_state");
  263. arg0.integer.value = state;
  264. status = acpi_evaluate_integer(device->handle, "_DSS", &args, &ret);
  265. return_VALUE(status);
  266. }
  267. static int
  268. acpi_video_device_lcd_query_levels(struct acpi_video_device *device,
  269. union acpi_object **levels)
  270. {
  271. int status;
  272. struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
  273. union acpi_object *obj;
  274. ACPI_FUNCTION_TRACE("acpi_video_device_lcd_query_levels");
  275. *levels = NULL;
  276. status = acpi_evaluate_object(device->handle, "_BCL", NULL, &buffer);
  277. if (!ACPI_SUCCESS(status))
  278. return_VALUE(status);
  279. obj = (union acpi_object *)buffer.pointer;
  280. if (!obj && (obj->type != ACPI_TYPE_PACKAGE)) {
  281. ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Invalid _BCL data\n"));
  282. status = -EFAULT;
  283. goto err;
  284. }
  285. *levels = obj;
  286. return_VALUE(0);
  287. err:
  288. if (buffer.pointer)
  289. kfree(buffer.pointer);
  290. return_VALUE(status);
  291. }
  292. static int
  293. acpi_video_device_lcd_set_level(struct acpi_video_device *device, int level)
  294. {
  295. int status;
  296. union acpi_object arg0 = { ACPI_TYPE_INTEGER };
  297. struct acpi_object_list args = { 1, &arg0 };
  298. ACPI_FUNCTION_TRACE("acpi_video_device_lcd_set_level");
  299. arg0.integer.value = level;
  300. status = acpi_evaluate_object(device->handle, "_BCM", &args, NULL);
  301. printk(KERN_DEBUG "set_level status: %x\n", status);
  302. return_VALUE(status);
  303. }
  304. static int
  305. acpi_video_device_lcd_get_level_current(struct acpi_video_device *device,
  306. unsigned long *level)
  307. {
  308. int status;
  309. ACPI_FUNCTION_TRACE("acpi_video_device_lcd_get_level_current");
  310. status = acpi_evaluate_integer(device->handle, "_BQC", NULL, level);
  311. return_VALUE(status);
  312. }
  313. static int
  314. acpi_video_device_EDID(struct acpi_video_device *device,
  315. union acpi_object **edid, ssize_t length)
  316. {
  317. int status;
  318. struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
  319. union acpi_object *obj;
  320. union acpi_object arg0 = { ACPI_TYPE_INTEGER };
  321. struct acpi_object_list args = { 1, &arg0 };
  322. ACPI_FUNCTION_TRACE("acpi_video_device_get_EDID");
  323. *edid = NULL;
  324. if (!device)
  325. return_VALUE(-ENODEV);
  326. if (length == 128)
  327. arg0.integer.value = 1;
  328. else if (length == 256)
  329. arg0.integer.value = 2;
  330. else
  331. return_VALUE(-EINVAL);
  332. status = acpi_evaluate_object(device->handle, "_DDC", &args, &buffer);
  333. if (ACPI_FAILURE(status))
  334. return_VALUE(-ENODEV);
  335. obj = (union acpi_object *)buffer.pointer;
  336. if (obj && obj->type == ACPI_TYPE_BUFFER)
  337. *edid = obj;
  338. else {
  339. ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Invalid _DDC data\n"));
  340. status = -EFAULT;
  341. kfree(obj);
  342. }
  343. return_VALUE(status);
  344. }
  345. /* bus */
  346. static int
  347. acpi_video_bus_set_POST(struct acpi_video_bus *video, unsigned long option)
  348. {
  349. int status;
  350. unsigned long tmp;
  351. union acpi_object arg0 = { ACPI_TYPE_INTEGER };
  352. struct acpi_object_list args = { 1, &arg0 };
  353. ACPI_FUNCTION_TRACE("acpi_video_bus_set_POST");
  354. arg0.integer.value = option;
  355. status = acpi_evaluate_integer(video->handle, "_SPD", &args, &tmp);
  356. if (ACPI_SUCCESS(status))
  357. status = tmp ? (-EINVAL) : (AE_OK);
  358. return_VALUE(status);
  359. }
  360. static int
  361. acpi_video_bus_get_POST(struct acpi_video_bus *video, unsigned long *id)
  362. {
  363. int status;
  364. ACPI_FUNCTION_TRACE("acpi_video_bus_get_POST");
  365. status = acpi_evaluate_integer(video->handle, "_GPD", NULL, id);
  366. return_VALUE(status);
  367. }
  368. static int
  369. acpi_video_bus_POST_options(struct acpi_video_bus *video,
  370. unsigned long *options)
  371. {
  372. int status;
  373. ACPI_FUNCTION_TRACE("acpi_video_bus_POST_options");
  374. status = acpi_evaluate_integer(video->handle, "_VPO", NULL, options);
  375. *options &= 3;
  376. return_VALUE(status);
  377. }
  378. /*
  379. * Arg:
  380. * video : video bus device pointer
  381. * bios_flag :
  382. * 0. The system BIOS should NOT automatically switch(toggle)
  383. * the active display output.
  384. * 1. The system BIOS should automatically switch (toggle) the
  385. * active display output. No swich event.
  386. * 2. The _DGS value should be locked.
  387. * 3. The system BIOS should not automatically switch (toggle) the
  388. * active display output, but instead generate the display switch
  389. * event notify code.
  390. * lcd_flag :
  391. * 0. The system BIOS should automatically control the brightness level
  392. * of the LCD, when the power changes from AC to DC
  393. * 1. The system BIOS should NOT automatically control the brightness
  394. * level of the LCD, when the power changes from AC to DC.
  395. * Return Value:
  396. * -1 wrong arg.
  397. */
  398. static int
  399. acpi_video_bus_DOS(struct acpi_video_bus *video, int bios_flag, int lcd_flag)
  400. {
  401. acpi_integer status = 0;
  402. union acpi_object arg0 = { ACPI_TYPE_INTEGER };
  403. struct acpi_object_list args = { 1, &arg0 };
  404. ACPI_FUNCTION_TRACE("acpi_video_bus_DOS");
  405. if (bios_flag < 0 || bios_flag > 3 || lcd_flag < 0 || lcd_flag > 1) {
  406. status = -1;
  407. goto Failed;
  408. }
  409. arg0.integer.value = (lcd_flag << 2) | bios_flag;
  410. video->dos_setting = arg0.integer.value;
  411. acpi_evaluate_object(video->handle, "_DOS", &args, NULL);
  412. Failed:
  413. return_VALUE(status);
  414. }
  415. /*
  416. * Arg:
  417. * device : video output device (LCD, CRT, ..)
  418. *
  419. * Return Value:
  420. * None
  421. *
  422. * Find out all required AML method defined under the output
  423. * device.
  424. */
  425. static void acpi_video_device_find_cap(struct acpi_video_device *device)
  426. {
  427. acpi_integer status;
  428. acpi_handle h_dummy1;
  429. int i;
  430. union acpi_object *obj = NULL;
  431. struct acpi_video_device_brightness *br = NULL;
  432. ACPI_FUNCTION_TRACE("acpi_video_device_find_cap");
  433. memset(&device->cap, 0, 4);
  434. if (ACPI_SUCCESS(acpi_get_handle(device->handle, "_ADR", &h_dummy1))) {
  435. device->cap._ADR = 1;
  436. }
  437. if (ACPI_SUCCESS(acpi_get_handle(device->handle, "_BCL", &h_dummy1))) {
  438. device->cap._BCL = 1;
  439. }
  440. if (ACPI_SUCCESS(acpi_get_handle(device->handle, "_BCM", &h_dummy1))) {
  441. device->cap._BCM = 1;
  442. }
  443. if (ACPI_SUCCESS(acpi_get_handle(device->handle, "_DDC", &h_dummy1))) {
  444. device->cap._DDC = 1;
  445. }
  446. if (ACPI_SUCCESS(acpi_get_handle(device->handle, "_DCS", &h_dummy1))) {
  447. device->cap._DCS = 1;
  448. }
  449. if (ACPI_SUCCESS(acpi_get_handle(device->handle, "_DGS", &h_dummy1))) {
  450. device->cap._DGS = 1;
  451. }
  452. if (ACPI_SUCCESS(acpi_get_handle(device->handle, "_DSS", &h_dummy1))) {
  453. device->cap._DSS = 1;
  454. }
  455. status = acpi_video_device_lcd_query_levels(device, &obj);
  456. if (obj && obj->type == ACPI_TYPE_PACKAGE && obj->package.count >= 2) {
  457. int count = 0;
  458. union acpi_object *o;
  459. br = kmalloc(sizeof(*br), GFP_KERNEL);
  460. if (!br) {
  461. printk(KERN_ERR "can't allocate memory\n");
  462. } else {
  463. memset(br, 0, sizeof(*br));
  464. br->levels = kmalloc(obj->package.count *
  465. sizeof *(br->levels), GFP_KERNEL);
  466. if (!br->levels)
  467. goto out;
  468. for (i = 0; i < obj->package.count; i++) {
  469. o = (union acpi_object *)&obj->package.
  470. elements[i];
  471. if (o->type != ACPI_TYPE_INTEGER) {
  472. ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
  473. "Invalid data\n"));
  474. continue;
  475. }
  476. br->levels[count] = (u32) o->integer.value;
  477. count++;
  478. }
  479. out:
  480. if (count < 2) {
  481. kfree(br->levels);
  482. kfree(br);
  483. } else {
  484. br->count = count;
  485. device->brightness = br;
  486. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  487. "found %d brightness levels\n",
  488. count));
  489. }
  490. }
  491. }
  492. kfree(obj);
  493. return_VOID;
  494. }
  495. /*
  496. * Arg:
  497. * device : video output device (VGA)
  498. *
  499. * Return Value:
  500. * None
  501. *
  502. * Find out all required AML method defined under the video bus device.
  503. */
  504. static void acpi_video_bus_find_cap(struct acpi_video_bus *video)
  505. {
  506. acpi_handle h_dummy1;
  507. memset(&video->cap, 0, 4);
  508. if (ACPI_SUCCESS(acpi_get_handle(video->handle, "_DOS", &h_dummy1))) {
  509. video->cap._DOS = 1;
  510. }
  511. if (ACPI_SUCCESS(acpi_get_handle(video->handle, "_DOD", &h_dummy1))) {
  512. video->cap._DOD = 1;
  513. }
  514. if (ACPI_SUCCESS(acpi_get_handle(video->handle, "_ROM", &h_dummy1))) {
  515. video->cap._ROM = 1;
  516. }
  517. if (ACPI_SUCCESS(acpi_get_handle(video->handle, "_GPD", &h_dummy1))) {
  518. video->cap._GPD = 1;
  519. }
  520. if (ACPI_SUCCESS(acpi_get_handle(video->handle, "_SPD", &h_dummy1))) {
  521. video->cap._SPD = 1;
  522. }
  523. if (ACPI_SUCCESS(acpi_get_handle(video->handle, "_VPO", &h_dummy1))) {
  524. video->cap._VPO = 1;
  525. }
  526. }
  527. /*
  528. * Check whether the video bus device has required AML method to
  529. * support the desired features
  530. */
  531. static int acpi_video_bus_check(struct acpi_video_bus *video)
  532. {
  533. acpi_status status = -ENOENT;
  534. ACPI_FUNCTION_TRACE("acpi_video_bus_check");
  535. if (!video)
  536. return_VALUE(-EINVAL);
  537. /* Since there is no HID, CID and so on for VGA driver, we have
  538. * to check well known required nodes.
  539. */
  540. /* Does this device able to support video switching ? */
  541. if (video->cap._DOS) {
  542. video->flags.multihead = 1;
  543. status = 0;
  544. }
  545. /* Does this device able to retrieve a retrieve a video ROM ? */
  546. if (video->cap._ROM) {
  547. video->flags.rom = 1;
  548. status = 0;
  549. }
  550. /* Does this device able to configure which video device to POST ? */
  551. if (video->cap._GPD && video->cap._SPD && video->cap._VPO) {
  552. video->flags.post = 1;
  553. status = 0;
  554. }
  555. return_VALUE(status);
  556. }
  557. /* --------------------------------------------------------------------------
  558. FS Interface (/proc)
  559. -------------------------------------------------------------------------- */
  560. static struct proc_dir_entry *acpi_video_dir;
  561. /* video devices */
  562. static int acpi_video_device_info_seq_show(struct seq_file *seq, void *offset)
  563. {
  564. struct acpi_video_device *dev =
  565. (struct acpi_video_device *)seq->private;
  566. ACPI_FUNCTION_TRACE("acpi_video_device_info_seq_show");
  567. if (!dev)
  568. goto end;
  569. seq_printf(seq, "device_id: 0x%04x\n", (u32) dev->device_id);
  570. seq_printf(seq, "type: ");
  571. if (dev->flags.crt)
  572. seq_printf(seq, "CRT\n");
  573. else if (dev->flags.lcd)
  574. seq_printf(seq, "LCD\n");
  575. else if (dev->flags.tvout)
  576. seq_printf(seq, "TVOUT\n");
  577. else
  578. seq_printf(seq, "UNKNOWN\n");
  579. seq_printf(seq, "known by bios: %s\n", dev->flags.bios ? "yes" : "no");
  580. end:
  581. return_VALUE(0);
  582. }
  583. static int
  584. acpi_video_device_info_open_fs(struct inode *inode, struct file *file)
  585. {
  586. return single_open(file, acpi_video_device_info_seq_show,
  587. PDE(inode)->data);
  588. }
  589. static int acpi_video_device_state_seq_show(struct seq_file *seq, void *offset)
  590. {
  591. int status;
  592. struct acpi_video_device *dev =
  593. (struct acpi_video_device *)seq->private;
  594. unsigned long state;
  595. ACPI_FUNCTION_TRACE("acpi_video_device_state_seq_show");
  596. if (!dev)
  597. goto end;
  598. status = acpi_video_device_get_state(dev, &state);
  599. seq_printf(seq, "state: ");
  600. if (ACPI_SUCCESS(status))
  601. seq_printf(seq, "0x%02lx\n", state);
  602. else
  603. seq_printf(seq, "<not supported>\n");
  604. status = acpi_video_device_query(dev, &state);
  605. seq_printf(seq, "query: ");
  606. if (ACPI_SUCCESS(status))
  607. seq_printf(seq, "0x%02lx\n", state);
  608. else
  609. seq_printf(seq, "<not supported>\n");
  610. end:
  611. return_VALUE(0);
  612. }
  613. static int
  614. acpi_video_device_state_open_fs(struct inode *inode, struct file *file)
  615. {
  616. return single_open(file, acpi_video_device_state_seq_show,
  617. PDE(inode)->data);
  618. }
  619. static ssize_t
  620. acpi_video_device_write_state(struct file *file,
  621. const char __user * buffer,
  622. size_t count, loff_t * data)
  623. {
  624. int status;
  625. struct seq_file *m = (struct seq_file *)file->private_data;
  626. struct acpi_video_device *dev = (struct acpi_video_device *)m->private;
  627. char str[12] = { 0 };
  628. u32 state = 0;
  629. ACPI_FUNCTION_TRACE("acpi_video_device_write_state");
  630. if (!dev || count + 1 > sizeof str)
  631. return_VALUE(-EINVAL);
  632. if (copy_from_user(str, buffer, count))
  633. return_VALUE(-EFAULT);
  634. str[count] = 0;
  635. state = simple_strtoul(str, NULL, 0);
  636. state &= ((1ul << 31) | (1ul << 30) | (1ul << 0));
  637. status = acpi_video_device_set_state(dev, state);
  638. if (status)
  639. return_VALUE(-EFAULT);
  640. return_VALUE(count);
  641. }
  642. static int
  643. acpi_video_device_brightness_seq_show(struct seq_file *seq, void *offset)
  644. {
  645. struct acpi_video_device *dev =
  646. (struct acpi_video_device *)seq->private;
  647. int i;
  648. ACPI_FUNCTION_TRACE("acpi_video_device_brightness_seq_show");
  649. if (!dev || !dev->brightness) {
  650. seq_printf(seq, "<not supported>\n");
  651. return_VALUE(0);
  652. }
  653. seq_printf(seq, "levels: ");
  654. for (i = 0; i < dev->brightness->count; i++)
  655. seq_printf(seq, " %d", dev->brightness->levels[i]);
  656. seq_printf(seq, "\ncurrent: %d\n", dev->brightness->curr);
  657. return_VALUE(0);
  658. }
  659. static int
  660. acpi_video_device_brightness_open_fs(struct inode *inode, struct file *file)
  661. {
  662. return single_open(file, acpi_video_device_brightness_seq_show,
  663. PDE(inode)->data);
  664. }
  665. static ssize_t
  666. acpi_video_device_write_brightness(struct file *file,
  667. const char __user * buffer,
  668. size_t count, loff_t * data)
  669. {
  670. struct seq_file *m = (struct seq_file *)file->private_data;
  671. struct acpi_video_device *dev = (struct acpi_video_device *)m->private;
  672. char str[4] = { 0 };
  673. unsigned int level = 0;
  674. int i;
  675. ACPI_FUNCTION_TRACE("acpi_video_device_write_brightness");
  676. if (!dev || count + 1 > sizeof str)
  677. return_VALUE(-EINVAL);
  678. if (copy_from_user(str, buffer, count))
  679. return_VALUE(-EFAULT);
  680. str[count] = 0;
  681. level = simple_strtoul(str, NULL, 0);
  682. if (level > 100)
  683. return_VALUE(-EFAULT);
  684. /* validate though the list of available levels */
  685. for (i = 0; i < dev->brightness->count; i++)
  686. if (level == dev->brightness->levels[i]) {
  687. if (ACPI_SUCCESS
  688. (acpi_video_device_lcd_set_level(dev, level)))
  689. dev->brightness->curr = level;
  690. break;
  691. }
  692. return_VALUE(count);
  693. }
  694. static int acpi_video_device_EDID_seq_show(struct seq_file *seq, void *offset)
  695. {
  696. struct acpi_video_device *dev =
  697. (struct acpi_video_device *)seq->private;
  698. int status;
  699. int i;
  700. union acpi_object *edid = NULL;
  701. ACPI_FUNCTION_TRACE("acpi_video_device_EDID_seq_show");
  702. if (!dev)
  703. goto out;
  704. status = acpi_video_device_EDID(dev, &edid, 128);
  705. if (ACPI_FAILURE(status)) {
  706. status = acpi_video_device_EDID(dev, &edid, 256);
  707. }
  708. if (ACPI_FAILURE(status)) {
  709. goto out;
  710. }
  711. if (edid && edid->type == ACPI_TYPE_BUFFER) {
  712. for (i = 0; i < edid->buffer.length; i++)
  713. seq_putc(seq, edid->buffer.pointer[i]);
  714. }
  715. out:
  716. if (!edid)
  717. seq_printf(seq, "<not supported>\n");
  718. else
  719. kfree(edid);
  720. return_VALUE(0);
  721. }
  722. static int
  723. acpi_video_device_EDID_open_fs(struct inode *inode, struct file *file)
  724. {
  725. return single_open(file, acpi_video_device_EDID_seq_show,
  726. PDE(inode)->data);
  727. }
  728. static int acpi_video_device_add_fs(struct acpi_device *device)
  729. {
  730. struct proc_dir_entry *entry = NULL;
  731. struct acpi_video_device *vid_dev;
  732. ACPI_FUNCTION_TRACE("acpi_video_device_add_fs");
  733. if (!device)
  734. return_VALUE(-ENODEV);
  735. vid_dev = (struct acpi_video_device *)acpi_driver_data(device);
  736. if (!vid_dev)
  737. return_VALUE(-ENODEV);
  738. if (!acpi_device_dir(device)) {
  739. acpi_device_dir(device) = proc_mkdir(acpi_device_bid(device),
  740. vid_dev->video->dir);
  741. if (!acpi_device_dir(device))
  742. return_VALUE(-ENODEV);
  743. acpi_device_dir(device)->owner = THIS_MODULE;
  744. }
  745. /* 'info' [R] */
  746. entry = create_proc_entry("info", S_IRUGO, acpi_device_dir(device));
  747. if (!entry)
  748. ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
  749. "Unable to create 'info' fs entry\n"));
  750. else {
  751. entry->proc_fops = &acpi_video_device_info_fops;
  752. entry->data = acpi_driver_data(device);
  753. entry->owner = THIS_MODULE;
  754. }
  755. /* 'state' [R/W] */
  756. entry =
  757. create_proc_entry("state", S_IFREG | S_IRUGO | S_IWUSR,
  758. acpi_device_dir(device));
  759. if (!entry)
  760. ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
  761. "Unable to create 'state' fs entry\n"));
  762. else {
  763. entry->proc_fops = &acpi_video_device_state_fops;
  764. entry->proc_fops->write = acpi_video_device_write_state;
  765. entry->data = acpi_driver_data(device);
  766. entry->owner = THIS_MODULE;
  767. }
  768. /* 'brightness' [R/W] */
  769. entry =
  770. create_proc_entry("brightness", S_IFREG | S_IRUGO | S_IWUSR,
  771. acpi_device_dir(device));
  772. if (!entry)
  773. ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
  774. "Unable to create 'brightness' fs entry\n"));
  775. else {
  776. entry->proc_fops = &acpi_video_device_brightness_fops;
  777. entry->proc_fops->write = acpi_video_device_write_brightness;
  778. entry->data = acpi_driver_data(device);
  779. entry->owner = THIS_MODULE;
  780. }
  781. /* 'EDID' [R] */
  782. entry = create_proc_entry("EDID", S_IRUGO, acpi_device_dir(device));
  783. if (!entry)
  784. ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
  785. "Unable to create 'brightness' fs entry\n"));
  786. else {
  787. entry->proc_fops = &acpi_video_device_EDID_fops;
  788. entry->data = acpi_driver_data(device);
  789. entry->owner = THIS_MODULE;
  790. }
  791. return_VALUE(0);
  792. }
  793. static int acpi_video_device_remove_fs(struct acpi_device *device)
  794. {
  795. struct acpi_video_device *vid_dev;
  796. ACPI_FUNCTION_TRACE("acpi_video_device_remove_fs");
  797. vid_dev = (struct acpi_video_device *)acpi_driver_data(device);
  798. if (!vid_dev || !vid_dev->video || !vid_dev->video->dir)
  799. return_VALUE(-ENODEV);
  800. if (acpi_device_dir(device)) {
  801. remove_proc_entry("info", acpi_device_dir(device));
  802. remove_proc_entry("state", acpi_device_dir(device));
  803. remove_proc_entry("brightness", acpi_device_dir(device));
  804. remove_proc_entry("EDID", acpi_device_dir(device));
  805. remove_proc_entry(acpi_device_bid(device), vid_dev->video->dir);
  806. acpi_device_dir(device) = NULL;
  807. }
  808. return_VALUE(0);
  809. }
  810. /* video bus */
  811. static int acpi_video_bus_info_seq_show(struct seq_file *seq, void *offset)
  812. {
  813. struct acpi_video_bus *video = (struct acpi_video_bus *)seq->private;
  814. ACPI_FUNCTION_TRACE("acpi_video_bus_info_seq_show");
  815. if (!video)
  816. goto end;
  817. seq_printf(seq, "Switching heads: %s\n",
  818. video->flags.multihead ? "yes" : "no");
  819. seq_printf(seq, "Video ROM: %s\n",
  820. video->flags.rom ? "yes" : "no");
  821. seq_printf(seq, "Device to be POSTed on boot: %s\n",
  822. video->flags.post ? "yes" : "no");
  823. end:
  824. return_VALUE(0);
  825. }
  826. static int acpi_video_bus_info_open_fs(struct inode *inode, struct file *file)
  827. {
  828. return single_open(file, acpi_video_bus_info_seq_show,
  829. PDE(inode)->data);
  830. }
  831. static int acpi_video_bus_ROM_seq_show(struct seq_file *seq, void *offset)
  832. {
  833. struct acpi_video_bus *video = (struct acpi_video_bus *)seq->private;
  834. ACPI_FUNCTION_TRACE("acpi_video_bus_ROM_seq_show");
  835. if (!video)
  836. goto end;
  837. printk(KERN_INFO PREFIX "Please implement %s\n", __FUNCTION__);
  838. seq_printf(seq, "<TODO>\n");
  839. end:
  840. return_VALUE(0);
  841. }
  842. static int acpi_video_bus_ROM_open_fs(struct inode *inode, struct file *file)
  843. {
  844. return single_open(file, acpi_video_bus_ROM_seq_show, PDE(inode)->data);
  845. }
  846. static int acpi_video_bus_POST_info_seq_show(struct seq_file *seq, void *offset)
  847. {
  848. struct acpi_video_bus *video = (struct acpi_video_bus *)seq->private;
  849. unsigned long options;
  850. int status;
  851. ACPI_FUNCTION_TRACE("acpi_video_bus_POST_info_seq_show");
  852. if (!video)
  853. goto end;
  854. status = acpi_video_bus_POST_options(video, &options);
  855. if (ACPI_SUCCESS(status)) {
  856. if (!(options & 1)) {
  857. printk(KERN_WARNING PREFIX
  858. "The motherboard VGA device is not listed as a possible POST device.\n");
  859. printk(KERN_WARNING PREFIX
  860. "This indicate a BIOS bug. Please contact the manufacturer.\n");
  861. }
  862. printk("%lx\n", options);
  863. seq_printf(seq, "can POST: <intgrated video>");
  864. if (options & 2)
  865. seq_printf(seq, " <PCI video>");
  866. if (options & 4)
  867. seq_printf(seq, " <AGP video>");
  868. seq_putc(seq, '\n');
  869. } else
  870. seq_printf(seq, "<not supported>\n");
  871. end:
  872. return_VALUE(0);
  873. }
  874. static int
  875. acpi_video_bus_POST_info_open_fs(struct inode *inode, struct file *file)
  876. {
  877. return single_open(file, acpi_video_bus_POST_info_seq_show,
  878. PDE(inode)->data);
  879. }
  880. static int acpi_video_bus_POST_seq_show(struct seq_file *seq, void *offset)
  881. {
  882. struct acpi_video_bus *video = (struct acpi_video_bus *)seq->private;
  883. int status;
  884. unsigned long id;
  885. ACPI_FUNCTION_TRACE("acpi_video_bus_POST_seq_show");
  886. if (!video)
  887. goto end;
  888. status = acpi_video_bus_get_POST(video, &id);
  889. if (!ACPI_SUCCESS(status)) {
  890. seq_printf(seq, "<not supported>\n");
  891. goto end;
  892. }
  893. seq_printf(seq, "device posted is <%s>\n", device_decode[id & 3]);
  894. end:
  895. return_VALUE(0);
  896. }
  897. static int acpi_video_bus_DOS_seq_show(struct seq_file *seq, void *offset)
  898. {
  899. struct acpi_video_bus *video = (struct acpi_video_bus *)seq->private;
  900. ACPI_FUNCTION_TRACE("acpi_video_bus_DOS_seq_show");
  901. seq_printf(seq, "DOS setting: <%d>\n", video->dos_setting);
  902. return_VALUE(0);
  903. }
  904. static int acpi_video_bus_POST_open_fs(struct inode *inode, struct file *file)
  905. {
  906. return single_open(file, acpi_video_bus_POST_seq_show,
  907. PDE(inode)->data);
  908. }
  909. static int acpi_video_bus_DOS_open_fs(struct inode *inode, struct file *file)
  910. {
  911. return single_open(file, acpi_video_bus_DOS_seq_show, PDE(inode)->data);
  912. }
  913. static ssize_t
  914. acpi_video_bus_write_POST(struct file *file,
  915. const char __user * buffer,
  916. size_t count, loff_t * data)
  917. {
  918. int status;
  919. struct seq_file *m = (struct seq_file *)file->private_data;
  920. struct acpi_video_bus *video = (struct acpi_video_bus *)m->private;
  921. char str[12] = { 0 };
  922. unsigned long opt, options;
  923. ACPI_FUNCTION_TRACE("acpi_video_bus_write_POST");
  924. if (!video || count + 1 > sizeof str)
  925. return_VALUE(-EINVAL);
  926. status = acpi_video_bus_POST_options(video, &options);
  927. if (!ACPI_SUCCESS(status))
  928. return_VALUE(-EINVAL);
  929. if (copy_from_user(str, buffer, count))
  930. return_VALUE(-EFAULT);
  931. str[count] = 0;
  932. opt = strtoul(str, NULL, 0);
  933. if (opt > 3)
  934. return_VALUE(-EFAULT);
  935. /* just in case an OEM 'forget' the motherboard... */
  936. options |= 1;
  937. if (options & (1ul << opt)) {
  938. status = acpi_video_bus_set_POST(video, opt);
  939. if (!ACPI_SUCCESS(status))
  940. return_VALUE(-EFAULT);
  941. }
  942. return_VALUE(count);
  943. }
  944. static ssize_t
  945. acpi_video_bus_write_DOS(struct file *file,
  946. const char __user * buffer,
  947. size_t count, loff_t * data)
  948. {
  949. int status;
  950. struct seq_file *m = (struct seq_file *)file->private_data;
  951. struct acpi_video_bus *video = (struct acpi_video_bus *)m->private;
  952. char str[12] = { 0 };
  953. unsigned long opt;
  954. ACPI_FUNCTION_TRACE("acpi_video_bus_write_DOS");
  955. if (!video || count + 1 > sizeof str)
  956. return_VALUE(-EINVAL);
  957. if (copy_from_user(str, buffer, count))
  958. return_VALUE(-EFAULT);
  959. str[count] = 0;
  960. opt = strtoul(str, NULL, 0);
  961. if (opt > 7)
  962. return_VALUE(-EFAULT);
  963. status = acpi_video_bus_DOS(video, opt & 0x3, (opt & 0x4) >> 2);
  964. if (!ACPI_SUCCESS(status))
  965. return_VALUE(-EFAULT);
  966. return_VALUE(count);
  967. }
  968. static int acpi_video_bus_add_fs(struct acpi_device *device)
  969. {
  970. struct proc_dir_entry *entry = NULL;
  971. struct acpi_video_bus *video;
  972. ACPI_FUNCTION_TRACE("acpi_video_bus_add_fs");
  973. video = (struct acpi_video_bus *)acpi_driver_data(device);
  974. if (!acpi_device_dir(device)) {
  975. acpi_device_dir(device) = proc_mkdir(acpi_device_bid(device),
  976. acpi_video_dir);
  977. if (!acpi_device_dir(device))
  978. return_VALUE(-ENODEV);
  979. video->dir = acpi_device_dir(device);
  980. acpi_device_dir(device)->owner = THIS_MODULE;
  981. }
  982. /* 'info' [R] */
  983. entry = create_proc_entry("info", S_IRUGO, acpi_device_dir(device));
  984. if (!entry)
  985. ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
  986. "Unable to create 'info' fs entry\n"));
  987. else {
  988. entry->proc_fops = &acpi_video_bus_info_fops;
  989. entry->data = acpi_driver_data(device);
  990. entry->owner = THIS_MODULE;
  991. }
  992. /* 'ROM' [R] */
  993. entry = create_proc_entry("ROM", S_IRUGO, acpi_device_dir(device));
  994. if (!entry)
  995. ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
  996. "Unable to create 'ROM' fs entry\n"));
  997. else {
  998. entry->proc_fops = &acpi_video_bus_ROM_fops;
  999. entry->data = acpi_driver_data(device);
  1000. entry->owner = THIS_MODULE;
  1001. }
  1002. /* 'POST_info' [R] */
  1003. entry =
  1004. create_proc_entry("POST_info", S_IRUGO, acpi_device_dir(device));
  1005. if (!entry)
  1006. ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
  1007. "Unable to create 'POST_info' fs entry\n"));
  1008. else {
  1009. entry->proc_fops = &acpi_video_bus_POST_info_fops;
  1010. entry->data = acpi_driver_data(device);
  1011. entry->owner = THIS_MODULE;
  1012. }
  1013. /* 'POST' [R/W] */
  1014. entry =
  1015. create_proc_entry("POST", S_IFREG | S_IRUGO | S_IRUSR,
  1016. acpi_device_dir(device));
  1017. if (!entry)
  1018. ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
  1019. "Unable to create 'POST' fs entry\n"));
  1020. else {
  1021. entry->proc_fops = &acpi_video_bus_POST_fops;
  1022. entry->proc_fops->write = acpi_video_bus_write_POST;
  1023. entry->data = acpi_driver_data(device);
  1024. entry->owner = THIS_MODULE;
  1025. }
  1026. /* 'DOS' [R/W] */
  1027. entry =
  1028. create_proc_entry("DOS", S_IFREG | S_IRUGO | S_IRUSR,
  1029. acpi_device_dir(device));
  1030. if (!entry)
  1031. ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
  1032. "Unable to create 'DOS' fs entry\n"));
  1033. else {
  1034. entry->proc_fops = &acpi_video_bus_DOS_fops;
  1035. entry->proc_fops->write = acpi_video_bus_write_DOS;
  1036. entry->data = acpi_driver_data(device);
  1037. entry->owner = THIS_MODULE;
  1038. }
  1039. return_VALUE(0);
  1040. }
  1041. static int acpi_video_bus_remove_fs(struct acpi_device *device)
  1042. {
  1043. struct acpi_video_bus *video;
  1044. ACPI_FUNCTION_TRACE("acpi_video_bus_remove_fs");
  1045. video = (struct acpi_video_bus *)acpi_driver_data(device);
  1046. if (acpi_device_dir(device)) {
  1047. remove_proc_entry("info", acpi_device_dir(device));
  1048. remove_proc_entry("ROM", acpi_device_dir(device));
  1049. remove_proc_entry("POST_info", acpi_device_dir(device));
  1050. remove_proc_entry("POST", acpi_device_dir(device));
  1051. remove_proc_entry("DOS", acpi_device_dir(device));
  1052. remove_proc_entry(acpi_device_bid(device), acpi_video_dir);
  1053. acpi_device_dir(device) = NULL;
  1054. }
  1055. return_VALUE(0);
  1056. }
  1057. /* --------------------------------------------------------------------------
  1058. Driver Interface
  1059. -------------------------------------------------------------------------- */
  1060. /* device interface */
  1061. static int
  1062. acpi_video_bus_get_one_device(struct acpi_device *device,
  1063. struct acpi_video_bus *video)
  1064. {
  1065. unsigned long device_id;
  1066. int status, result;
  1067. struct acpi_video_device *data;
  1068. ACPI_FUNCTION_TRACE("acpi_video_bus_get_one_device");
  1069. if (!device || !video)
  1070. return_VALUE(-EINVAL);
  1071. status =
  1072. acpi_evaluate_integer(device->handle, "_ADR", NULL, &device_id);
  1073. if (ACPI_SUCCESS(status)) {
  1074. data = kmalloc(sizeof(struct acpi_video_device), GFP_KERNEL);
  1075. if (!data)
  1076. return_VALUE(-ENOMEM);
  1077. memset(data, 0, sizeof(struct acpi_video_device));
  1078. data->handle = device->handle;
  1079. strcpy(acpi_device_name(device), ACPI_VIDEO_DEVICE_NAME);
  1080. strcpy(acpi_device_class(device), ACPI_VIDEO_CLASS);
  1081. acpi_driver_data(device) = data;
  1082. data->device_id = device_id;
  1083. data->video = video;
  1084. data->dev = device;
  1085. switch (device_id & 0xffff) {
  1086. case 0x0100:
  1087. data->flags.crt = 1;
  1088. break;
  1089. case 0x0400:
  1090. data->flags.lcd = 1;
  1091. break;
  1092. case 0x0200:
  1093. data->flags.tvout = 1;
  1094. break;
  1095. default:
  1096. data->flags.unknown = 1;
  1097. break;
  1098. }
  1099. acpi_video_device_bind(video, data);
  1100. acpi_video_device_find_cap(data);
  1101. status = acpi_install_notify_handler(data->handle,
  1102. ACPI_DEVICE_NOTIFY,
  1103. acpi_video_device_notify,
  1104. data);
  1105. if (ACPI_FAILURE(status)) {
  1106. ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
  1107. "Error installing notify handler\n"));
  1108. result = -ENODEV;
  1109. goto end;
  1110. }
  1111. down(&video->sem);
  1112. list_add_tail(&data->entry, &video->video_device_list);
  1113. up(&video->sem);
  1114. acpi_video_device_add_fs(device);
  1115. return_VALUE(0);
  1116. }
  1117. end:
  1118. return_VALUE(-ENOENT);
  1119. }
  1120. /*
  1121. * Arg:
  1122. * video : video bus device
  1123. *
  1124. * Return:
  1125. * none
  1126. *
  1127. * Enumerate the video device list of the video bus,
  1128. * bind the ids with the corresponding video devices
  1129. * under the video bus.
  1130. */
  1131. static void acpi_video_device_rebind(struct acpi_video_bus *video)
  1132. {
  1133. struct list_head *node, *next;
  1134. list_for_each_safe(node, next, &video->video_device_list) {
  1135. struct acpi_video_device *dev =
  1136. container_of(node, struct acpi_video_device, entry);
  1137. acpi_video_device_bind(video, dev);
  1138. }
  1139. }
  1140. /*
  1141. * Arg:
  1142. * video : video bus device
  1143. * device : video output device under the video
  1144. * bus
  1145. *
  1146. * Return:
  1147. * none
  1148. *
  1149. * Bind the ids with the corresponding video devices
  1150. * under the video bus.
  1151. */
  1152. static void
  1153. acpi_video_device_bind(struct acpi_video_bus *video,
  1154. struct acpi_video_device *device)
  1155. {
  1156. int i;
  1157. ACPI_FUNCTION_TRACE("acpi_video_device_bind");
  1158. #define IDS_VAL(i) video->attached_array[i].value.int_val
  1159. #define IDS_BIND(i) video->attached_array[i].bind_info
  1160. for (i = 0; IDS_VAL(i) != ACPI_VIDEO_HEAD_INVALID &&
  1161. i < video->attached_count; i++) {
  1162. if (device->device_id == (IDS_VAL(i) & 0xffff)) {
  1163. IDS_BIND(i) = device;
  1164. ACPI_DEBUG_PRINT((ACPI_DB_INFO, "device_bind %d\n", i));
  1165. }
  1166. }
  1167. #undef IDS_VAL
  1168. #undef IDS_BIND
  1169. }
  1170. /*
  1171. * Arg:
  1172. * video : video bus device
  1173. *
  1174. * Return:
  1175. * < 0 : error
  1176. *
  1177. * Call _DOD to enumerate all devices attached to display adapter
  1178. *
  1179. */
  1180. static int acpi_video_device_enumerate(struct acpi_video_bus *video)
  1181. {
  1182. int status;
  1183. int count;
  1184. int i;
  1185. struct acpi_video_enumerated_device *active_device_list;
  1186. struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
  1187. union acpi_object *dod = NULL;
  1188. union acpi_object *obj;
  1189. ACPI_FUNCTION_TRACE("acpi_video_device_enumerate");
  1190. status = acpi_evaluate_object(video->handle, "_DOD", NULL, &buffer);
  1191. if (!ACPI_SUCCESS(status)) {
  1192. ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Error evaluating _DOD\n"));
  1193. return_VALUE(status);
  1194. }
  1195. dod = (union acpi_object *)buffer.pointer;
  1196. if (!dod || (dod->type != ACPI_TYPE_PACKAGE)) {
  1197. ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Invalid _DOD data\n"));
  1198. status = -EFAULT;
  1199. goto out;
  1200. }
  1201. ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found %d video heads in _DOD\n",
  1202. dod->package.count));
  1203. active_device_list = kmalloc((1 +
  1204. dod->package.count) *
  1205. sizeof(struct
  1206. acpi_video_enumerated_device),
  1207. GFP_KERNEL);
  1208. if (!active_device_list) {
  1209. status = -ENOMEM;
  1210. goto out;
  1211. }
  1212. count = 0;
  1213. for (i = 0; i < dod->package.count; i++) {
  1214. obj = (union acpi_object *)&dod->package.elements[i];
  1215. if (obj->type != ACPI_TYPE_INTEGER) {
  1216. ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
  1217. "Invalid _DOD data\n"));
  1218. active_device_list[i].value.int_val =
  1219. ACPI_VIDEO_HEAD_INVALID;
  1220. }
  1221. active_device_list[i].value.int_val = obj->integer.value;
  1222. active_device_list[i].bind_info = NULL;
  1223. ACPI_DEBUG_PRINT((ACPI_DB_INFO, "dod element[%d] = %d\n", i,
  1224. (int)obj->integer.value));
  1225. count++;
  1226. }
  1227. active_device_list[count].value.int_val = ACPI_VIDEO_HEAD_END;
  1228. if (video->attached_array)
  1229. kfree(video->attached_array);
  1230. video->attached_array = active_device_list;
  1231. video->attached_count = count;
  1232. out:
  1233. acpi_os_free(buffer.pointer);
  1234. return_VALUE(status);
  1235. }
  1236. /*
  1237. * Arg:
  1238. * video : video bus device
  1239. * event : Nontify Event
  1240. *
  1241. * Return:
  1242. * < 0 : error
  1243. *
  1244. * 1. Find out the current active output device.
  1245. * 2. Identify the next output device to switch
  1246. * 3. call _DSS to do actual switch.
  1247. */
  1248. static int acpi_video_switch_output(struct acpi_video_bus *video, int event)
  1249. {
  1250. struct list_head *node, *next;
  1251. struct acpi_video_device *dev = NULL;
  1252. struct acpi_video_device *dev_next = NULL;
  1253. struct acpi_video_device *dev_prev = NULL;
  1254. unsigned long state;
  1255. int status = 0;
  1256. ACPI_FUNCTION_TRACE("acpi_video_switch_output");
  1257. list_for_each_safe(node, next, &video->video_device_list) {
  1258. dev = container_of(node, struct acpi_video_device, entry);
  1259. status = acpi_video_device_get_state(dev, &state);
  1260. if (state & 0x2) {
  1261. dev_next =
  1262. container_of(node->next, struct acpi_video_device,
  1263. entry);
  1264. dev_prev =
  1265. container_of(node->prev, struct acpi_video_device,
  1266. entry);
  1267. goto out;
  1268. }
  1269. }
  1270. dev_next = container_of(node->next, struct acpi_video_device, entry);
  1271. dev_prev = container_of(node->prev, struct acpi_video_device, entry);
  1272. out:
  1273. switch (event) {
  1274. case ACPI_VIDEO_NOTIFY_CYCLE:
  1275. case ACPI_VIDEO_NOTIFY_NEXT_OUTPUT:
  1276. acpi_video_device_set_state(dev, 0);
  1277. acpi_video_device_set_state(dev_next, 0x80000001);
  1278. break;
  1279. case ACPI_VIDEO_NOTIFY_PREV_OUTPUT:
  1280. acpi_video_device_set_state(dev, 0);
  1281. acpi_video_device_set_state(dev_prev, 0x80000001);
  1282. default:
  1283. break;
  1284. }
  1285. return_VALUE(status);
  1286. }
  1287. static int
  1288. acpi_video_get_next_level(struct acpi_video_device *device,
  1289. u32 level_current, u32 event)
  1290. {
  1291. /*Fix me */
  1292. return level_current;
  1293. }
  1294. static void
  1295. acpi_video_switch_brightness(struct acpi_video_device *device, int event)
  1296. {
  1297. unsigned long level_current, level_next;
  1298. acpi_video_device_lcd_get_level_current(device, &level_current);
  1299. level_next = acpi_video_get_next_level(device, level_current, event);
  1300. acpi_video_device_lcd_set_level(device, level_next);
  1301. }
  1302. static int
  1303. acpi_video_bus_get_devices(struct acpi_video_bus *video,
  1304. struct acpi_device *device)
  1305. {
  1306. int status = 0;
  1307. struct list_head *node, *next;
  1308. ACPI_FUNCTION_TRACE("acpi_video_get_devices");
  1309. acpi_video_device_enumerate(video);
  1310. list_for_each_safe(node, next, &device->children) {
  1311. struct acpi_device *dev =
  1312. list_entry(node, struct acpi_device, node);
  1313. if (!dev)
  1314. continue;
  1315. status = acpi_video_bus_get_one_device(dev, video);
  1316. if (ACPI_FAILURE(status)) {
  1317. ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
  1318. "Cant attach device\n"));
  1319. continue;
  1320. }
  1321. }
  1322. return_VALUE(status);
  1323. }
  1324. static int acpi_video_bus_put_one_device(struct acpi_video_device *device)
  1325. {
  1326. acpi_status status;
  1327. struct acpi_video_bus *video;
  1328. ACPI_FUNCTION_TRACE("acpi_video_bus_put_one_device");
  1329. if (!device || !device->video)
  1330. return_VALUE(-ENOENT);
  1331. video = device->video;
  1332. down(&video->sem);
  1333. list_del(&device->entry);
  1334. up(&video->sem);
  1335. acpi_video_device_remove_fs(device->dev);
  1336. status = acpi_remove_notify_handler(device->handle,
  1337. ACPI_DEVICE_NOTIFY,
  1338. acpi_video_device_notify);
  1339. if (ACPI_FAILURE(status))
  1340. ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
  1341. "Error removing notify handler\n"));
  1342. return_VALUE(0);
  1343. }
  1344. static int acpi_video_bus_put_devices(struct acpi_video_bus *video)
  1345. {
  1346. int status;
  1347. struct list_head *node, *next;
  1348. ACPI_FUNCTION_TRACE("acpi_video_bus_put_devices");
  1349. list_for_each_safe(node, next, &video->video_device_list) {
  1350. struct acpi_video_device *data =
  1351. list_entry(node, struct acpi_video_device, entry);
  1352. if (!data)
  1353. continue;
  1354. status = acpi_video_bus_put_one_device(data);
  1355. if (ACPI_FAILURE(status))
  1356. printk(KERN_WARNING PREFIX
  1357. "hhuuhhuu bug in acpi video driver.\n");
  1358. if (data->brightness)
  1359. kfree(data->brightness);
  1360. kfree(data);
  1361. }
  1362. return_VALUE(0);
  1363. }
  1364. /* acpi_video interface */
  1365. static int acpi_video_bus_start_devices(struct acpi_video_bus *video)
  1366. {
  1367. return acpi_video_bus_DOS(video, 1, 0);
  1368. }
  1369. static int acpi_video_bus_stop_devices(struct acpi_video_bus *video)
  1370. {
  1371. return acpi_video_bus_DOS(video, 0, 1);
  1372. }
  1373. static void acpi_video_bus_notify(acpi_handle handle, u32 event, void *data)
  1374. {
  1375. struct acpi_video_bus *video = (struct acpi_video_bus *)data;
  1376. struct acpi_device *device = NULL;
  1377. ACPI_FUNCTION_TRACE("acpi_video_bus_notify");
  1378. printk("video bus notify\n");
  1379. if (!video)
  1380. return_VOID;
  1381. if (acpi_bus_get_device(handle, &device))
  1382. return_VOID;
  1383. switch (event) {
  1384. case ACPI_VIDEO_NOTIFY_SWITCH: /* User request that a switch occur,
  1385. * most likely via hotkey. */
  1386. acpi_bus_generate_event(device, event, 0);
  1387. break;
  1388. case ACPI_VIDEO_NOTIFY_PROBE: /* User plug or remove a video
  1389. * connector. */
  1390. acpi_video_device_enumerate(video);
  1391. acpi_video_device_rebind(video);
  1392. acpi_video_switch_output(video, event);
  1393. acpi_bus_generate_event(device, event, 0);
  1394. break;
  1395. case ACPI_VIDEO_NOTIFY_CYCLE: /* Cycle Display output hotkey pressed. */
  1396. case ACPI_VIDEO_NOTIFY_NEXT_OUTPUT: /* Next Display output hotkey pressed. */
  1397. case ACPI_VIDEO_NOTIFY_PREV_OUTPUT: /* previous Display output hotkey pressed. */
  1398. acpi_video_switch_output(video, event);
  1399. acpi_bus_generate_event(device, event, 0);
  1400. break;
  1401. default:
  1402. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  1403. "Unsupported event [0x%x]\n", event));
  1404. break;
  1405. }
  1406. return_VOID;
  1407. }
  1408. static void acpi_video_device_notify(acpi_handle handle, u32 event, void *data)
  1409. {
  1410. struct acpi_video_device *video_device =
  1411. (struct acpi_video_device *)data;
  1412. struct acpi_device *device = NULL;
  1413. ACPI_FUNCTION_TRACE("acpi_video_device_notify");
  1414. printk("video device notify\n");
  1415. if (!video_device)
  1416. return_VOID;
  1417. if (acpi_bus_get_device(handle, &device))
  1418. return_VOID;
  1419. switch (event) {
  1420. case ACPI_VIDEO_NOTIFY_SWITCH: /* change in status (cycle output device) */
  1421. case ACPI_VIDEO_NOTIFY_PROBE: /* change in status (output device status) */
  1422. acpi_bus_generate_event(device, event, 0);
  1423. break;
  1424. case ACPI_VIDEO_NOTIFY_CYCLE_BRIGHTNESS: /* Cycle brightness */
  1425. case ACPI_VIDEO_NOTIFY_INC_BRIGHTNESS: /* Increase brightness */
  1426. case ACPI_VIDEO_NOTIFY_DEC_BRIGHTNESS: /* Decrease brightness */
  1427. case ACPI_VIDEO_NOTIFY_ZERO_BRIGHTNESS: /* zero brightnesss */
  1428. case ACPI_VIDEO_NOTIFY_DISPLAY_OFF: /* display device off */
  1429. acpi_video_switch_brightness(video_device, event);
  1430. acpi_bus_generate_event(device, event, 0);
  1431. break;
  1432. default:
  1433. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  1434. "Unsupported event [0x%x]\n", event));
  1435. break;
  1436. }
  1437. return_VOID;
  1438. }
  1439. static int acpi_video_bus_add(struct acpi_device *device)
  1440. {
  1441. int result = 0;
  1442. acpi_status status = 0;
  1443. struct acpi_video_bus *video = NULL;
  1444. ACPI_FUNCTION_TRACE("acpi_video_bus_add");
  1445. if (!device)
  1446. return_VALUE(-EINVAL);
  1447. video = kmalloc(sizeof(struct acpi_video_bus), GFP_KERNEL);
  1448. if (!video)
  1449. return_VALUE(-ENOMEM);
  1450. memset(video, 0, sizeof(struct acpi_video_bus));
  1451. video->handle = device->handle;
  1452. strcpy(acpi_device_name(device), ACPI_VIDEO_BUS_NAME);
  1453. strcpy(acpi_device_class(device), ACPI_VIDEO_CLASS);
  1454. acpi_driver_data(device) = video;
  1455. acpi_video_bus_find_cap(video);
  1456. result = acpi_video_bus_check(video);
  1457. if (result)
  1458. goto end;
  1459. result = acpi_video_bus_add_fs(device);
  1460. if (result)
  1461. goto end;
  1462. init_MUTEX(&video->sem);
  1463. INIT_LIST_HEAD(&video->video_device_list);
  1464. acpi_video_bus_get_devices(video, device);
  1465. acpi_video_bus_start_devices(video);
  1466. status = acpi_install_notify_handler(video->handle,
  1467. ACPI_DEVICE_NOTIFY,
  1468. acpi_video_bus_notify, video);
  1469. if (ACPI_FAILURE(status)) {
  1470. ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
  1471. "Error installing notify handler\n"));
  1472. result = -ENODEV;
  1473. goto end;
  1474. }
  1475. printk(KERN_INFO PREFIX "%s [%s] (multi-head: %s rom: %s post: %s)\n",
  1476. ACPI_VIDEO_DEVICE_NAME, acpi_device_bid(device),
  1477. video->flags.multihead ? "yes" : "no",
  1478. video->flags.rom ? "yes" : "no",
  1479. video->flags.post ? "yes" : "no");
  1480. end:
  1481. if (result) {
  1482. acpi_video_bus_remove_fs(device);
  1483. kfree(video);
  1484. }
  1485. return_VALUE(result);
  1486. }
  1487. static int acpi_video_bus_remove(struct acpi_device *device, int type)
  1488. {
  1489. acpi_status status = 0;
  1490. struct acpi_video_bus *video = NULL;
  1491. ACPI_FUNCTION_TRACE("acpi_video_bus_remove");
  1492. if (!device || !acpi_driver_data(device))
  1493. return_VALUE(-EINVAL);
  1494. video = (struct acpi_video_bus *)acpi_driver_data(device);
  1495. acpi_video_bus_stop_devices(video);
  1496. status = acpi_remove_notify_handler(video->handle,
  1497. ACPI_DEVICE_NOTIFY,
  1498. acpi_video_bus_notify);
  1499. if (ACPI_FAILURE(status))
  1500. ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
  1501. "Error removing notify handler\n"));
  1502. acpi_video_bus_put_devices(video);
  1503. acpi_video_bus_remove_fs(device);
  1504. if (video->attached_array)
  1505. kfree(video->attached_array);
  1506. kfree(video);
  1507. return_VALUE(0);
  1508. }
  1509. static int
  1510. acpi_video_bus_match(struct acpi_device *device, struct acpi_driver *driver)
  1511. {
  1512. acpi_handle h_dummy1;
  1513. acpi_handle h_dummy2;
  1514. acpi_handle h_dummy3;
  1515. ACPI_FUNCTION_TRACE("acpi_video_bus_match");
  1516. if (!device || !driver)
  1517. return_VALUE(-EINVAL);
  1518. /* Since there is no HID, CID for ACPI Video drivers, we have
  1519. * to check well known required nodes for each feature we support.
  1520. */
  1521. /* Does this device able to support video switching ? */
  1522. if (ACPI_SUCCESS(acpi_get_handle(device->handle, "_DOD", &h_dummy1)) &&
  1523. ACPI_SUCCESS(acpi_get_handle(device->handle, "_DOS", &h_dummy2)))
  1524. return_VALUE(0);
  1525. /* Does this device able to retrieve a video ROM ? */
  1526. if (ACPI_SUCCESS(acpi_get_handle(device->handle, "_ROM", &h_dummy1)))
  1527. return_VALUE(0);
  1528. /* Does this device able to configure which video head to be POSTed ? */
  1529. if (ACPI_SUCCESS(acpi_get_handle(device->handle, "_VPO", &h_dummy1)) &&
  1530. ACPI_SUCCESS(acpi_get_handle(device->handle, "_GPD", &h_dummy2)) &&
  1531. ACPI_SUCCESS(acpi_get_handle(device->handle, "_SPD", &h_dummy3)))
  1532. return_VALUE(0);
  1533. return_VALUE(-ENODEV);
  1534. }
  1535. static int __init acpi_video_init(void)
  1536. {
  1537. int result = 0;
  1538. ACPI_FUNCTION_TRACE("acpi_video_init");
  1539. /*
  1540. acpi_dbg_level = 0xFFFFFFFF;
  1541. acpi_dbg_layer = 0x08000000;
  1542. */
  1543. acpi_video_dir = proc_mkdir(ACPI_VIDEO_CLASS, acpi_root_dir);
  1544. if (!acpi_video_dir)
  1545. return_VALUE(-ENODEV);
  1546. acpi_video_dir->owner = THIS_MODULE;
  1547. result = acpi_bus_register_driver(&acpi_video_bus);
  1548. if (result < 0) {
  1549. remove_proc_entry(ACPI_VIDEO_CLASS, acpi_root_dir);
  1550. return_VALUE(-ENODEV);
  1551. }
  1552. return_VALUE(0);
  1553. }
  1554. static void __exit acpi_video_exit(void)
  1555. {
  1556. ACPI_FUNCTION_TRACE("acpi_video_exit");
  1557. acpi_bus_unregister_driver(&acpi_video_bus);
  1558. remove_proc_entry(ACPI_VIDEO_CLASS, acpi_root_dir);
  1559. return_VOID;
  1560. }
  1561. module_init(acpi_video_init);
  1562. module_exit(acpi_video_exit);