video.c 51 KB

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