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