video.c 46 KB

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