video.c 50 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041
  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 acpi_video_bus_add(struct acpi_device *device)
  1565. {
  1566. int result = 0;
  1567. acpi_status status = 0;
  1568. struct acpi_video_bus *video = NULL;
  1569. struct input_dev *input;
  1570. if (!device)
  1571. return -EINVAL;
  1572. video = kzalloc(sizeof(struct acpi_video_bus), GFP_KERNEL);
  1573. if (!video)
  1574. return -ENOMEM;
  1575. video->device = device;
  1576. strcpy(acpi_device_name(device), ACPI_VIDEO_BUS_NAME);
  1577. strcpy(acpi_device_class(device), ACPI_VIDEO_CLASS);
  1578. acpi_driver_data(device) = video;
  1579. acpi_video_bus_find_cap(video);
  1580. result = acpi_video_bus_check(video);
  1581. if (result)
  1582. goto end;
  1583. result = acpi_video_bus_add_fs(device);
  1584. if (result)
  1585. goto end;
  1586. init_MUTEX(&video->sem);
  1587. INIT_LIST_HEAD(&video->video_device_list);
  1588. acpi_video_bus_get_devices(video, device);
  1589. acpi_video_bus_start_devices(video);
  1590. status = acpi_install_notify_handler(device->handle,
  1591. ACPI_DEVICE_NOTIFY,
  1592. acpi_video_bus_notify, video);
  1593. if (ACPI_FAILURE(status)) {
  1594. ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
  1595. "Error installing notify handler\n"));
  1596. acpi_video_bus_stop_devices(video);
  1597. acpi_video_bus_put_devices(video);
  1598. kfree(video->attached_array);
  1599. acpi_video_bus_remove_fs(device);
  1600. result = -ENODEV;
  1601. goto end;
  1602. }
  1603. video->input = input = input_allocate_device();
  1604. snprintf(video->phys, sizeof(video->phys),
  1605. "%s/video/input0", acpi_device_hid(video->device));
  1606. input->name = acpi_device_name(video->device);
  1607. input->phys = video->phys;
  1608. input->id.bustype = BUS_HOST;
  1609. input->id.product = 0x06;
  1610. input->evbit[0] = BIT(EV_KEY);
  1611. set_bit(KEY_SWITCHVIDEOMODE, input->keybit);
  1612. set_bit(KEY_VIDEO_NEXT, input->keybit);
  1613. set_bit(KEY_VIDEO_PREV, input->keybit);
  1614. set_bit(KEY_BRIGHTNESS_CYCLE, input->keybit);
  1615. set_bit(KEY_BRIGHTNESSUP, input->keybit);
  1616. set_bit(KEY_BRIGHTNESSDOWN, input->keybit);
  1617. set_bit(KEY_BRIGHTNESS_ZERO, input->keybit);
  1618. set_bit(KEY_DISPLAY_OFF, input->keybit);
  1619. set_bit(KEY_UNKNOWN, input->keybit);
  1620. result = input_register_device(input);
  1621. if (result) {
  1622. acpi_remove_notify_handler(video->device->handle,
  1623. ACPI_DEVICE_NOTIFY,
  1624. acpi_video_bus_notify);
  1625. acpi_video_bus_stop_devices(video);
  1626. acpi_video_bus_put_devices(video);
  1627. kfree(video->attached_array);
  1628. acpi_video_bus_remove_fs(device);
  1629. goto end;
  1630. }
  1631. printk(KERN_INFO PREFIX "%s [%s] (multi-head: %s rom: %s post: %s)\n",
  1632. ACPI_VIDEO_DEVICE_NAME, acpi_device_bid(device),
  1633. video->flags.multihead ? "yes" : "no",
  1634. video->flags.rom ? "yes" : "no",
  1635. video->flags.post ? "yes" : "no");
  1636. end:
  1637. if (result)
  1638. kfree(video);
  1639. return result;
  1640. }
  1641. static int acpi_video_bus_remove(struct acpi_device *device, int type)
  1642. {
  1643. acpi_status status = 0;
  1644. struct acpi_video_bus *video = NULL;
  1645. if (!device || !acpi_driver_data(device))
  1646. return -EINVAL;
  1647. video = acpi_driver_data(device);
  1648. acpi_video_bus_stop_devices(video);
  1649. status = acpi_remove_notify_handler(video->device->handle,
  1650. ACPI_DEVICE_NOTIFY,
  1651. acpi_video_bus_notify);
  1652. acpi_video_bus_put_devices(video);
  1653. acpi_video_bus_remove_fs(device);
  1654. input_unregister_device(video->input);
  1655. kfree(video->attached_array);
  1656. kfree(video);
  1657. return 0;
  1658. }
  1659. static int __init acpi_video_init(void)
  1660. {
  1661. int result = 0;
  1662. /*
  1663. acpi_dbg_level = 0xFFFFFFFF;
  1664. acpi_dbg_layer = 0x08000000;
  1665. */
  1666. acpi_video_dir = proc_mkdir(ACPI_VIDEO_CLASS, acpi_root_dir);
  1667. if (!acpi_video_dir)
  1668. return -ENODEV;
  1669. acpi_video_dir->owner = THIS_MODULE;
  1670. result = acpi_bus_register_driver(&acpi_video_bus);
  1671. if (result < 0) {
  1672. remove_proc_entry(ACPI_VIDEO_CLASS, acpi_root_dir);
  1673. return -ENODEV;
  1674. }
  1675. return 0;
  1676. }
  1677. static void __exit acpi_video_exit(void)
  1678. {
  1679. acpi_bus_unregister_driver(&acpi_video_bus);
  1680. remove_proc_entry(ACPI_VIDEO_CLASS, acpi_root_dir);
  1681. return;
  1682. }
  1683. module_init(acpi_video_init);
  1684. module_exit(acpi_video_exit);