video.c 52 KB

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