video.c 51 KB

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