video.c 54 KB

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