video.c 54 KB

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