video.c 52 KB

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