video.c 53 KB

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