video.c 51 KB

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