video.c 46 KB

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