video.c 52 KB

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