video.c 50 KB

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