video.c 48 KB

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