video.c 53 KB

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