video.c 51 KB

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