video.c 51 KB

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