video.c 54 KB

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