video.c 50 KB

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