video.c 53 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108
  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 (IS_ERR(device->cdev))
  622. return;
  623. printk(KERN_INFO PREFIX
  624. "%s is registered as cooling_device%d\n",
  625. device->dev->dev.bus_id, device->cdev->id);
  626. result = sysfs_create_link(&device->dev->dev.kobj,
  627. &device->cdev->device.kobj,
  628. "thermal_cooling");
  629. if (result)
  630. printk(KERN_ERR PREFIX "Create sysfs link\n");
  631. result = sysfs_create_link(&device->cdev->device.kobj,
  632. &device->dev->dev.kobj, "device");
  633. if (result)
  634. printk(KERN_ERR PREFIX "Create sysfs link\n");
  635. }
  636. if (device->cap._DCS && device->cap._DSS){
  637. static int count = 0;
  638. char *name;
  639. name = kzalloc(MAX_NAME_LEN, GFP_KERNEL);
  640. if (!name)
  641. return;
  642. sprintf(name, "acpi_video%d", count++);
  643. device->output_dev = video_output_register(name,
  644. NULL, device, &acpi_output_properties);
  645. kfree(name);
  646. }
  647. return;
  648. }
  649. /*
  650. * Arg:
  651. * device : video output device (VGA)
  652. *
  653. * Return Value:
  654. * None
  655. *
  656. * Find out all required AML methods defined under the video bus device.
  657. */
  658. static void acpi_video_bus_find_cap(struct acpi_video_bus *video)
  659. {
  660. acpi_handle h_dummy1;
  661. memset(&video->cap, 0, sizeof(video->cap));
  662. if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_DOS", &h_dummy1))) {
  663. video->cap._DOS = 1;
  664. }
  665. if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_DOD", &h_dummy1))) {
  666. video->cap._DOD = 1;
  667. }
  668. if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_ROM", &h_dummy1))) {
  669. video->cap._ROM = 1;
  670. }
  671. if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_GPD", &h_dummy1))) {
  672. video->cap._GPD = 1;
  673. }
  674. if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_SPD", &h_dummy1))) {
  675. video->cap._SPD = 1;
  676. }
  677. if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_VPO", &h_dummy1))) {
  678. video->cap._VPO = 1;
  679. }
  680. }
  681. /*
  682. * Check whether the video bus device has required AML method to
  683. * support the desired features
  684. */
  685. static int acpi_video_bus_check(struct acpi_video_bus *video)
  686. {
  687. acpi_status status = -ENOENT;
  688. if (!video)
  689. return -EINVAL;
  690. /* Since there is no HID, CID and so on for VGA driver, we have
  691. * to check well known required nodes.
  692. */
  693. /* Does this device support video switching? */
  694. if (video->cap._DOS) {
  695. video->flags.multihead = 1;
  696. status = 0;
  697. }
  698. /* Does this device support retrieving a video ROM? */
  699. if (video->cap._ROM) {
  700. video->flags.rom = 1;
  701. status = 0;
  702. }
  703. /* Does this device support configuring which video device to POST? */
  704. if (video->cap._GPD && video->cap._SPD && video->cap._VPO) {
  705. video->flags.post = 1;
  706. status = 0;
  707. }
  708. return status;
  709. }
  710. /* --------------------------------------------------------------------------
  711. FS Interface (/proc)
  712. -------------------------------------------------------------------------- */
  713. static struct proc_dir_entry *acpi_video_dir;
  714. /* video devices */
  715. static int acpi_video_device_info_seq_show(struct seq_file *seq, void *offset)
  716. {
  717. struct acpi_video_device *dev = seq->private;
  718. if (!dev)
  719. goto end;
  720. seq_printf(seq, "device_id: 0x%04x\n", (u32) dev->device_id);
  721. seq_printf(seq, "type: ");
  722. if (dev->flags.crt)
  723. seq_printf(seq, "CRT\n");
  724. else if (dev->flags.lcd)
  725. seq_printf(seq, "LCD\n");
  726. else if (dev->flags.tvout)
  727. seq_printf(seq, "TVOUT\n");
  728. else if (dev->flags.dvi)
  729. seq_printf(seq, "DVI\n");
  730. else
  731. seq_printf(seq, "UNKNOWN\n");
  732. seq_printf(seq, "known by bios: %s\n", dev->flags.bios ? "yes" : "no");
  733. end:
  734. return 0;
  735. }
  736. static int
  737. acpi_video_device_info_open_fs(struct inode *inode, struct file *file)
  738. {
  739. return single_open(file, acpi_video_device_info_seq_show,
  740. PDE(inode)->data);
  741. }
  742. static int acpi_video_device_state_seq_show(struct seq_file *seq, void *offset)
  743. {
  744. int status;
  745. struct acpi_video_device *dev = seq->private;
  746. unsigned long state;
  747. if (!dev)
  748. goto end;
  749. status = acpi_video_device_get_state(dev, &state);
  750. seq_printf(seq, "state: ");
  751. if (ACPI_SUCCESS(status))
  752. seq_printf(seq, "0x%02lx\n", state);
  753. else
  754. seq_printf(seq, "<not supported>\n");
  755. status = acpi_video_device_query(dev, &state);
  756. seq_printf(seq, "query: ");
  757. if (ACPI_SUCCESS(status))
  758. seq_printf(seq, "0x%02lx\n", state);
  759. else
  760. seq_printf(seq, "<not supported>\n");
  761. end:
  762. return 0;
  763. }
  764. static int
  765. acpi_video_device_state_open_fs(struct inode *inode, struct file *file)
  766. {
  767. return single_open(file, acpi_video_device_state_seq_show,
  768. PDE(inode)->data);
  769. }
  770. static ssize_t
  771. acpi_video_device_write_state(struct file *file,
  772. const char __user * buffer,
  773. size_t count, loff_t * data)
  774. {
  775. int status;
  776. struct seq_file *m = file->private_data;
  777. struct acpi_video_device *dev = m->private;
  778. char str[12] = { 0 };
  779. u32 state = 0;
  780. if (!dev || count + 1 > sizeof str)
  781. return -EINVAL;
  782. if (copy_from_user(str, buffer, count))
  783. return -EFAULT;
  784. str[count] = 0;
  785. state = simple_strtoul(str, NULL, 0);
  786. state &= ((1ul << 31) | (1ul << 30) | (1ul << 0));
  787. status = acpi_video_device_set_state(dev, state);
  788. if (status)
  789. return -EFAULT;
  790. return count;
  791. }
  792. static int
  793. acpi_video_device_brightness_seq_show(struct seq_file *seq, void *offset)
  794. {
  795. struct acpi_video_device *dev = seq->private;
  796. int i;
  797. if (!dev || !dev->brightness) {
  798. seq_printf(seq, "<not supported>\n");
  799. return 0;
  800. }
  801. seq_printf(seq, "levels: ");
  802. for (i = 0; i < dev->brightness->count; i++)
  803. seq_printf(seq, " %d", dev->brightness->levels[i]);
  804. seq_printf(seq, "\ncurrent: %d\n", dev->brightness->curr);
  805. return 0;
  806. }
  807. static int
  808. acpi_video_device_brightness_open_fs(struct inode *inode, struct file *file)
  809. {
  810. return single_open(file, acpi_video_device_brightness_seq_show,
  811. PDE(inode)->data);
  812. }
  813. static ssize_t
  814. acpi_video_device_write_brightness(struct file *file,
  815. const char __user * buffer,
  816. size_t count, loff_t * data)
  817. {
  818. struct seq_file *m = file->private_data;
  819. struct acpi_video_device *dev = m->private;
  820. char str[5] = { 0 };
  821. unsigned int level = 0;
  822. int i;
  823. if (!dev || !dev->brightness || count + 1 > sizeof str)
  824. return -EINVAL;
  825. if (copy_from_user(str, buffer, count))
  826. return -EFAULT;
  827. str[count] = 0;
  828. level = simple_strtoul(str, NULL, 0);
  829. if (level > 100)
  830. return -EFAULT;
  831. /* validate through the list of available levels */
  832. for (i = 0; i < dev->brightness->count; i++)
  833. if (level == dev->brightness->levels[i]) {
  834. if (ACPI_SUCCESS
  835. (acpi_video_device_lcd_set_level(dev, level)))
  836. dev->brightness->curr = level;
  837. break;
  838. }
  839. return count;
  840. }
  841. static int acpi_video_device_EDID_seq_show(struct seq_file *seq, void *offset)
  842. {
  843. struct acpi_video_device *dev = seq->private;
  844. int status;
  845. int i;
  846. union acpi_object *edid = NULL;
  847. if (!dev)
  848. goto out;
  849. status = acpi_video_device_EDID(dev, &edid, 128);
  850. if (ACPI_FAILURE(status)) {
  851. status = acpi_video_device_EDID(dev, &edid, 256);
  852. }
  853. if (ACPI_FAILURE(status)) {
  854. goto out;
  855. }
  856. if (edid && edid->type == ACPI_TYPE_BUFFER) {
  857. for (i = 0; i < edid->buffer.length; i++)
  858. seq_putc(seq, edid->buffer.pointer[i]);
  859. }
  860. out:
  861. if (!edid)
  862. seq_printf(seq, "<not supported>\n");
  863. else
  864. kfree(edid);
  865. return 0;
  866. }
  867. static int
  868. acpi_video_device_EDID_open_fs(struct inode *inode, struct file *file)
  869. {
  870. return single_open(file, acpi_video_device_EDID_seq_show,
  871. PDE(inode)->data);
  872. }
  873. static int acpi_video_device_add_fs(struct acpi_device *device)
  874. {
  875. struct proc_dir_entry *entry = NULL;
  876. struct acpi_video_device *vid_dev;
  877. if (!device)
  878. return -ENODEV;
  879. vid_dev = acpi_driver_data(device);
  880. if (!vid_dev)
  881. return -ENODEV;
  882. if (!acpi_device_dir(device)) {
  883. acpi_device_dir(device) = proc_mkdir(acpi_device_bid(device),
  884. vid_dev->video->dir);
  885. if (!acpi_device_dir(device))
  886. return -ENODEV;
  887. acpi_device_dir(device)->owner = THIS_MODULE;
  888. }
  889. /* 'info' [R] */
  890. entry = create_proc_entry("info", S_IRUGO, acpi_device_dir(device));
  891. if (!entry)
  892. return -ENODEV;
  893. else {
  894. entry->proc_fops = &acpi_video_device_info_fops;
  895. entry->data = acpi_driver_data(device);
  896. entry->owner = THIS_MODULE;
  897. }
  898. /* 'state' [R/W] */
  899. entry =
  900. create_proc_entry("state", S_IFREG | S_IRUGO | S_IWUSR,
  901. acpi_device_dir(device));
  902. if (!entry)
  903. return -ENODEV;
  904. else {
  905. acpi_video_device_state_fops.write = acpi_video_device_write_state;
  906. entry->proc_fops = &acpi_video_device_state_fops;
  907. entry->data = acpi_driver_data(device);
  908. entry->owner = THIS_MODULE;
  909. }
  910. /* 'brightness' [R/W] */
  911. entry =
  912. create_proc_entry("brightness", S_IFREG | S_IRUGO | S_IWUSR,
  913. acpi_device_dir(device));
  914. if (!entry)
  915. return -ENODEV;
  916. else {
  917. acpi_video_device_brightness_fops.write = acpi_video_device_write_brightness;
  918. entry->proc_fops = &acpi_video_device_brightness_fops;
  919. entry->data = acpi_driver_data(device);
  920. entry->owner = THIS_MODULE;
  921. }
  922. /* 'EDID' [R] */
  923. entry = create_proc_entry("EDID", S_IRUGO, acpi_device_dir(device));
  924. if (!entry)
  925. return -ENODEV;
  926. else {
  927. entry->proc_fops = &acpi_video_device_EDID_fops;
  928. entry->data = acpi_driver_data(device);
  929. entry->owner = THIS_MODULE;
  930. }
  931. return 0;
  932. }
  933. static int acpi_video_device_remove_fs(struct acpi_device *device)
  934. {
  935. struct acpi_video_device *vid_dev;
  936. vid_dev = acpi_driver_data(device);
  937. if (!vid_dev || !vid_dev->video || !vid_dev->video->dir)
  938. return -ENODEV;
  939. if (acpi_device_dir(device)) {
  940. remove_proc_entry("info", acpi_device_dir(device));
  941. remove_proc_entry("state", acpi_device_dir(device));
  942. remove_proc_entry("brightness", acpi_device_dir(device));
  943. remove_proc_entry("EDID", acpi_device_dir(device));
  944. remove_proc_entry(acpi_device_bid(device), vid_dev->video->dir);
  945. acpi_device_dir(device) = NULL;
  946. }
  947. return 0;
  948. }
  949. /* video bus */
  950. static int acpi_video_bus_info_seq_show(struct seq_file *seq, void *offset)
  951. {
  952. struct acpi_video_bus *video = seq->private;
  953. if (!video)
  954. goto end;
  955. seq_printf(seq, "Switching heads: %s\n",
  956. video->flags.multihead ? "yes" : "no");
  957. seq_printf(seq, "Video ROM: %s\n",
  958. video->flags.rom ? "yes" : "no");
  959. seq_printf(seq, "Device to be POSTed on boot: %s\n",
  960. video->flags.post ? "yes" : "no");
  961. end:
  962. return 0;
  963. }
  964. static int acpi_video_bus_info_open_fs(struct inode *inode, struct file *file)
  965. {
  966. return single_open(file, acpi_video_bus_info_seq_show,
  967. PDE(inode)->data);
  968. }
  969. static int acpi_video_bus_ROM_seq_show(struct seq_file *seq, void *offset)
  970. {
  971. struct acpi_video_bus *video = seq->private;
  972. if (!video)
  973. goto end;
  974. printk(KERN_INFO PREFIX "Please implement %s\n", __func__);
  975. seq_printf(seq, "<TODO>\n");
  976. end:
  977. return 0;
  978. }
  979. static int acpi_video_bus_ROM_open_fs(struct inode *inode, struct file *file)
  980. {
  981. return single_open(file, acpi_video_bus_ROM_seq_show, PDE(inode)->data);
  982. }
  983. static int acpi_video_bus_POST_info_seq_show(struct seq_file *seq, void *offset)
  984. {
  985. struct acpi_video_bus *video = seq->private;
  986. unsigned long options;
  987. int status;
  988. if (!video)
  989. goto end;
  990. status = acpi_video_bus_POST_options(video, &options);
  991. if (ACPI_SUCCESS(status)) {
  992. if (!(options & 1)) {
  993. printk(KERN_WARNING PREFIX
  994. "The motherboard VGA device is not listed as a possible POST device.\n");
  995. printk(KERN_WARNING PREFIX
  996. "This indicates a BIOS bug. Please contact the manufacturer.\n");
  997. }
  998. printk("%lx\n", options);
  999. seq_printf(seq, "can POST: <integrated video>");
  1000. if (options & 2)
  1001. seq_printf(seq, " <PCI video>");
  1002. if (options & 4)
  1003. seq_printf(seq, " <AGP video>");
  1004. seq_putc(seq, '\n');
  1005. } else
  1006. seq_printf(seq, "<not supported>\n");
  1007. end:
  1008. return 0;
  1009. }
  1010. static int
  1011. acpi_video_bus_POST_info_open_fs(struct inode *inode, struct file *file)
  1012. {
  1013. return single_open(file, acpi_video_bus_POST_info_seq_show,
  1014. PDE(inode)->data);
  1015. }
  1016. static int acpi_video_bus_POST_seq_show(struct seq_file *seq, void *offset)
  1017. {
  1018. struct acpi_video_bus *video = seq->private;
  1019. int status;
  1020. unsigned long id;
  1021. if (!video)
  1022. goto end;
  1023. status = acpi_video_bus_get_POST(video, &id);
  1024. if (!ACPI_SUCCESS(status)) {
  1025. seq_printf(seq, "<not supported>\n");
  1026. goto end;
  1027. }
  1028. seq_printf(seq, "device POSTed is <%s>\n", device_decode[id & 3]);
  1029. end:
  1030. return 0;
  1031. }
  1032. static int acpi_video_bus_DOS_seq_show(struct seq_file *seq, void *offset)
  1033. {
  1034. struct acpi_video_bus *video = seq->private;
  1035. seq_printf(seq, "DOS setting: <%d>\n", video->dos_setting);
  1036. return 0;
  1037. }
  1038. static int acpi_video_bus_POST_open_fs(struct inode *inode, struct file *file)
  1039. {
  1040. return single_open(file, acpi_video_bus_POST_seq_show,
  1041. PDE(inode)->data);
  1042. }
  1043. static int acpi_video_bus_DOS_open_fs(struct inode *inode, struct file *file)
  1044. {
  1045. return single_open(file, acpi_video_bus_DOS_seq_show, PDE(inode)->data);
  1046. }
  1047. static ssize_t
  1048. acpi_video_bus_write_POST(struct file *file,
  1049. const char __user * buffer,
  1050. size_t count, loff_t * data)
  1051. {
  1052. int status;
  1053. struct seq_file *m = file->private_data;
  1054. struct acpi_video_bus *video = m->private;
  1055. char str[12] = { 0 };
  1056. unsigned long opt, options;
  1057. if (!video || count + 1 > sizeof str)
  1058. return -EINVAL;
  1059. status = acpi_video_bus_POST_options(video, &options);
  1060. if (!ACPI_SUCCESS(status))
  1061. return -EINVAL;
  1062. if (copy_from_user(str, buffer, count))
  1063. return -EFAULT;
  1064. str[count] = 0;
  1065. opt = strtoul(str, NULL, 0);
  1066. if (opt > 3)
  1067. return -EFAULT;
  1068. /* just in case an OEM 'forgot' the motherboard... */
  1069. options |= 1;
  1070. if (options & (1ul << opt)) {
  1071. status = acpi_video_bus_set_POST(video, opt);
  1072. if (!ACPI_SUCCESS(status))
  1073. return -EFAULT;
  1074. }
  1075. return count;
  1076. }
  1077. static ssize_t
  1078. acpi_video_bus_write_DOS(struct file *file,
  1079. const char __user * buffer,
  1080. size_t count, loff_t * data)
  1081. {
  1082. int status;
  1083. struct seq_file *m = file->private_data;
  1084. struct acpi_video_bus *video = m->private;
  1085. char str[12] = { 0 };
  1086. unsigned long opt;
  1087. if (!video || count + 1 > sizeof str)
  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 > 7)
  1094. return -EFAULT;
  1095. status = acpi_video_bus_DOS(video, opt & 0x3, (opt & 0x4) >> 2);
  1096. if (!ACPI_SUCCESS(status))
  1097. return -EFAULT;
  1098. return count;
  1099. }
  1100. static int acpi_video_bus_add_fs(struct acpi_device *device)
  1101. {
  1102. struct proc_dir_entry *entry = NULL;
  1103. struct acpi_video_bus *video;
  1104. video = acpi_driver_data(device);
  1105. if (!acpi_device_dir(device)) {
  1106. acpi_device_dir(device) = proc_mkdir(acpi_device_bid(device),
  1107. acpi_video_dir);
  1108. if (!acpi_device_dir(device))
  1109. return -ENODEV;
  1110. video->dir = acpi_device_dir(device);
  1111. acpi_device_dir(device)->owner = THIS_MODULE;
  1112. }
  1113. /* 'info' [R] */
  1114. entry = create_proc_entry("info", S_IRUGO, acpi_device_dir(device));
  1115. if (!entry)
  1116. return -ENODEV;
  1117. else {
  1118. entry->proc_fops = &acpi_video_bus_info_fops;
  1119. entry->data = acpi_driver_data(device);
  1120. entry->owner = THIS_MODULE;
  1121. }
  1122. /* 'ROM' [R] */
  1123. entry = create_proc_entry("ROM", S_IRUGO, acpi_device_dir(device));
  1124. if (!entry)
  1125. return -ENODEV;
  1126. else {
  1127. entry->proc_fops = &acpi_video_bus_ROM_fops;
  1128. entry->data = acpi_driver_data(device);
  1129. entry->owner = THIS_MODULE;
  1130. }
  1131. /* 'POST_info' [R] */
  1132. entry =
  1133. create_proc_entry("POST_info", S_IRUGO, acpi_device_dir(device));
  1134. if (!entry)
  1135. return -ENODEV;
  1136. else {
  1137. entry->proc_fops = &acpi_video_bus_POST_info_fops;
  1138. entry->data = acpi_driver_data(device);
  1139. entry->owner = THIS_MODULE;
  1140. }
  1141. /* 'POST' [R/W] */
  1142. entry =
  1143. create_proc_entry("POST", S_IFREG | S_IRUGO | S_IRUSR,
  1144. acpi_device_dir(device));
  1145. if (!entry)
  1146. return -ENODEV;
  1147. else {
  1148. acpi_video_bus_POST_fops.write = acpi_video_bus_write_POST;
  1149. entry->proc_fops = &acpi_video_bus_POST_fops;
  1150. entry->data = acpi_driver_data(device);
  1151. entry->owner = THIS_MODULE;
  1152. }
  1153. /* 'DOS' [R/W] */
  1154. entry =
  1155. create_proc_entry("DOS", S_IFREG | S_IRUGO | S_IRUSR,
  1156. acpi_device_dir(device));
  1157. if (!entry)
  1158. return -ENODEV;
  1159. else {
  1160. acpi_video_bus_DOS_fops.write = acpi_video_bus_write_DOS;
  1161. entry->proc_fops = &acpi_video_bus_DOS_fops;
  1162. entry->data = acpi_driver_data(device);
  1163. entry->owner = THIS_MODULE;
  1164. }
  1165. return 0;
  1166. }
  1167. static int acpi_video_bus_remove_fs(struct acpi_device *device)
  1168. {
  1169. struct acpi_video_bus *video;
  1170. video = acpi_driver_data(device);
  1171. if (acpi_device_dir(device)) {
  1172. remove_proc_entry("info", acpi_device_dir(device));
  1173. remove_proc_entry("ROM", acpi_device_dir(device));
  1174. remove_proc_entry("POST_info", acpi_device_dir(device));
  1175. remove_proc_entry("POST", acpi_device_dir(device));
  1176. remove_proc_entry("DOS", acpi_device_dir(device));
  1177. remove_proc_entry(acpi_device_bid(device), acpi_video_dir);
  1178. acpi_device_dir(device) = NULL;
  1179. }
  1180. return 0;
  1181. }
  1182. /* --------------------------------------------------------------------------
  1183. Driver Interface
  1184. -------------------------------------------------------------------------- */
  1185. /* device interface */
  1186. static struct acpi_video_device_attrib*
  1187. acpi_video_get_device_attr(struct acpi_video_bus *video, unsigned long device_id)
  1188. {
  1189. int count;
  1190. for(count = 0; count < video->attached_count; count++)
  1191. if((video->attached_array[count].value.int_val & 0xffff) == device_id)
  1192. return &(video->attached_array[count].value.attrib);
  1193. return NULL;
  1194. }
  1195. static int
  1196. acpi_video_bus_get_one_device(struct acpi_device *device,
  1197. struct acpi_video_bus *video)
  1198. {
  1199. unsigned long device_id;
  1200. int status;
  1201. struct acpi_video_device *data;
  1202. struct acpi_video_device_attrib* attribute;
  1203. if (!device || !video)
  1204. return -EINVAL;
  1205. status =
  1206. acpi_evaluate_integer(device->handle, "_ADR", NULL, &device_id);
  1207. if (ACPI_SUCCESS(status)) {
  1208. data = kzalloc(sizeof(struct acpi_video_device), GFP_KERNEL);
  1209. if (!data)
  1210. return -ENOMEM;
  1211. strcpy(acpi_device_name(device), ACPI_VIDEO_DEVICE_NAME);
  1212. strcpy(acpi_device_class(device), ACPI_VIDEO_CLASS);
  1213. acpi_driver_data(device) = data;
  1214. data->device_id = device_id;
  1215. data->video = video;
  1216. data->dev = device;
  1217. attribute = acpi_video_get_device_attr(video, device_id);
  1218. if((attribute != NULL) && attribute->device_id_scheme) {
  1219. switch (attribute->display_type) {
  1220. case ACPI_VIDEO_DISPLAY_CRT:
  1221. data->flags.crt = 1;
  1222. break;
  1223. case ACPI_VIDEO_DISPLAY_TV:
  1224. data->flags.tvout = 1;
  1225. break;
  1226. case ACPI_VIDEO_DISPLAY_DVI:
  1227. data->flags.dvi = 1;
  1228. break;
  1229. case ACPI_VIDEO_DISPLAY_LCD:
  1230. data->flags.lcd = 1;
  1231. break;
  1232. default:
  1233. data->flags.unknown = 1;
  1234. break;
  1235. }
  1236. if(attribute->bios_can_detect)
  1237. data->flags.bios = 1;
  1238. } else
  1239. data->flags.unknown = 1;
  1240. acpi_video_device_bind(video, data);
  1241. acpi_video_device_find_cap(data);
  1242. status = acpi_install_notify_handler(device->handle,
  1243. ACPI_DEVICE_NOTIFY,
  1244. acpi_video_device_notify,
  1245. data);
  1246. if (ACPI_FAILURE(status)) {
  1247. ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
  1248. "Error installing notify handler\n"));
  1249. if(data->brightness)
  1250. kfree(data->brightness->levels);
  1251. kfree(data->brightness);
  1252. kfree(data);
  1253. return -ENODEV;
  1254. }
  1255. mutex_lock(&video->device_list_lock);
  1256. list_add_tail(&data->entry, &video->video_device_list);
  1257. mutex_unlock(&video->device_list_lock);
  1258. acpi_video_device_add_fs(device);
  1259. return 0;
  1260. }
  1261. return -ENOENT;
  1262. }
  1263. /*
  1264. * Arg:
  1265. * video : video bus device
  1266. *
  1267. * Return:
  1268. * none
  1269. *
  1270. * Enumerate the video device list of the video bus,
  1271. * bind the ids with the corresponding video devices
  1272. * under the video bus.
  1273. */
  1274. static void acpi_video_device_rebind(struct acpi_video_bus *video)
  1275. {
  1276. struct acpi_video_device *dev;
  1277. mutex_lock(&video->device_list_lock);
  1278. list_for_each_entry(dev, &video->video_device_list, entry)
  1279. acpi_video_device_bind(video, dev);
  1280. mutex_unlock(&video->device_list_lock);
  1281. }
  1282. /*
  1283. * Arg:
  1284. * video : video bus device
  1285. * device : video output device under the video
  1286. * bus
  1287. *
  1288. * Return:
  1289. * none
  1290. *
  1291. * Bind the ids with the corresponding video devices
  1292. * under the video bus.
  1293. */
  1294. static void
  1295. acpi_video_device_bind(struct acpi_video_bus *video,
  1296. struct acpi_video_device *device)
  1297. {
  1298. int i;
  1299. #define IDS_VAL(i) video->attached_array[i].value.int_val
  1300. #define IDS_BIND(i) video->attached_array[i].bind_info
  1301. for (i = 0; IDS_VAL(i) != ACPI_VIDEO_HEAD_INVALID &&
  1302. i < video->attached_count; i++) {
  1303. if (device->device_id == (IDS_VAL(i) & 0xffff)) {
  1304. IDS_BIND(i) = device;
  1305. ACPI_DEBUG_PRINT((ACPI_DB_INFO, "device_bind %d\n", i));
  1306. }
  1307. }
  1308. #undef IDS_VAL
  1309. #undef IDS_BIND
  1310. }
  1311. /*
  1312. * Arg:
  1313. * video : video bus device
  1314. *
  1315. * Return:
  1316. * < 0 : error
  1317. *
  1318. * Call _DOD to enumerate all devices attached to display adapter
  1319. *
  1320. */
  1321. static int acpi_video_device_enumerate(struct acpi_video_bus *video)
  1322. {
  1323. int status;
  1324. int count;
  1325. int i;
  1326. struct acpi_video_enumerated_device *active_device_list;
  1327. struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
  1328. union acpi_object *dod = NULL;
  1329. union acpi_object *obj;
  1330. status = acpi_evaluate_object(video->device->handle, "_DOD", NULL, &buffer);
  1331. if (!ACPI_SUCCESS(status)) {
  1332. ACPI_EXCEPTION((AE_INFO, status, "Evaluating _DOD"));
  1333. return status;
  1334. }
  1335. dod = buffer.pointer;
  1336. if (!dod || (dod->type != ACPI_TYPE_PACKAGE)) {
  1337. ACPI_EXCEPTION((AE_INFO, status, "Invalid _DOD data"));
  1338. status = -EFAULT;
  1339. goto out;
  1340. }
  1341. ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found %d video heads in _DOD\n",
  1342. dod->package.count));
  1343. active_device_list = kmalloc((1 +
  1344. dod->package.count) *
  1345. sizeof(struct
  1346. acpi_video_enumerated_device),
  1347. GFP_KERNEL);
  1348. if (!active_device_list) {
  1349. status = -ENOMEM;
  1350. goto out;
  1351. }
  1352. count = 0;
  1353. for (i = 0; i < dod->package.count; i++) {
  1354. obj = &dod->package.elements[i];
  1355. if (obj->type != ACPI_TYPE_INTEGER) {
  1356. printk(KERN_ERR PREFIX "Invalid _DOD data\n");
  1357. active_device_list[i].value.int_val =
  1358. ACPI_VIDEO_HEAD_INVALID;
  1359. }
  1360. active_device_list[i].value.int_val = obj->integer.value;
  1361. active_device_list[i].bind_info = NULL;
  1362. ACPI_DEBUG_PRINT((ACPI_DB_INFO, "dod element[%d] = %d\n", i,
  1363. (int)obj->integer.value));
  1364. count++;
  1365. }
  1366. active_device_list[count].value.int_val = ACPI_VIDEO_HEAD_END;
  1367. kfree(video->attached_array);
  1368. video->attached_array = active_device_list;
  1369. video->attached_count = count;
  1370. out:
  1371. kfree(buffer.pointer);
  1372. return status;
  1373. }
  1374. static int
  1375. acpi_video_get_next_level(struct acpi_video_device *device,
  1376. u32 level_current, u32 event)
  1377. {
  1378. int min, max, min_above, max_below, i, l, delta = 255;
  1379. max = max_below = 0;
  1380. min = min_above = 255;
  1381. /* Find closest level to level_current */
  1382. for (i = 0; i < device->brightness->count; i++) {
  1383. l = device->brightness->levels[i];
  1384. if (abs(l - level_current) < abs(delta)) {
  1385. delta = l - level_current;
  1386. if (!delta)
  1387. break;
  1388. }
  1389. }
  1390. /* Ajust level_current to closest available level */
  1391. level_current += delta;
  1392. for (i = 0; i < device->brightness->count; i++) {
  1393. l = device->brightness->levels[i];
  1394. if (l < min)
  1395. min = l;
  1396. if (l > max)
  1397. max = l;
  1398. if (l < min_above && l > level_current)
  1399. min_above = l;
  1400. if (l > max_below && l < level_current)
  1401. max_below = l;
  1402. }
  1403. switch (event) {
  1404. case ACPI_VIDEO_NOTIFY_CYCLE_BRIGHTNESS:
  1405. return (level_current < max) ? min_above : min;
  1406. case ACPI_VIDEO_NOTIFY_INC_BRIGHTNESS:
  1407. return (level_current < max) ? min_above : max;
  1408. case ACPI_VIDEO_NOTIFY_DEC_BRIGHTNESS:
  1409. return (level_current > min) ? max_below : min;
  1410. case ACPI_VIDEO_NOTIFY_ZERO_BRIGHTNESS:
  1411. case ACPI_VIDEO_NOTIFY_DISPLAY_OFF:
  1412. return 0;
  1413. default:
  1414. return level_current;
  1415. }
  1416. }
  1417. static void
  1418. acpi_video_switch_brightness(struct acpi_video_device *device, int event)
  1419. {
  1420. unsigned long level_current, level_next;
  1421. acpi_video_device_lcd_get_level_current(device, &level_current);
  1422. level_next = acpi_video_get_next_level(device, level_current, event);
  1423. acpi_video_device_lcd_set_level(device, level_next);
  1424. }
  1425. static int
  1426. acpi_video_bus_get_devices(struct acpi_video_bus *video,
  1427. struct acpi_device *device)
  1428. {
  1429. int status = 0;
  1430. struct acpi_device *dev;
  1431. acpi_video_device_enumerate(video);
  1432. list_for_each_entry(dev, &device->children, node) {
  1433. status = acpi_video_bus_get_one_device(dev, video);
  1434. if (ACPI_FAILURE(status)) {
  1435. ACPI_EXCEPTION((AE_INFO, status, "Cant attach device"));
  1436. continue;
  1437. }
  1438. }
  1439. return status;
  1440. }
  1441. static int acpi_video_bus_put_one_device(struct acpi_video_device *device)
  1442. {
  1443. acpi_status status;
  1444. struct acpi_video_bus *video;
  1445. if (!device || !device->video)
  1446. return -ENOENT;
  1447. video = device->video;
  1448. acpi_video_device_remove_fs(device->dev);
  1449. status = acpi_remove_notify_handler(device->dev->handle,
  1450. ACPI_DEVICE_NOTIFY,
  1451. acpi_video_device_notify);
  1452. backlight_device_unregister(device->backlight);
  1453. if (device->cdev) {
  1454. sysfs_remove_link(&device->dev->dev.kobj,
  1455. "thermal_cooling");
  1456. sysfs_remove_link(&device->cdev->device.kobj,
  1457. "device");
  1458. thermal_cooling_device_unregister(device->cdev);
  1459. device->cdev = NULL;
  1460. }
  1461. video_output_unregister(device->output_dev);
  1462. return 0;
  1463. }
  1464. static int acpi_video_bus_put_devices(struct acpi_video_bus *video)
  1465. {
  1466. int status;
  1467. struct acpi_video_device *dev, *next;
  1468. mutex_lock(&video->device_list_lock);
  1469. list_for_each_entry_safe(dev, next, &video->video_device_list, entry) {
  1470. status = acpi_video_bus_put_one_device(dev);
  1471. if (ACPI_FAILURE(status))
  1472. printk(KERN_WARNING PREFIX
  1473. "hhuuhhuu bug in acpi video driver.\n");
  1474. if (dev->brightness) {
  1475. kfree(dev->brightness->levels);
  1476. kfree(dev->brightness);
  1477. }
  1478. list_del(&dev->entry);
  1479. kfree(dev);
  1480. }
  1481. mutex_unlock(&video->device_list_lock);
  1482. return 0;
  1483. }
  1484. /* acpi_video interface */
  1485. static int acpi_video_bus_start_devices(struct acpi_video_bus *video)
  1486. {
  1487. return acpi_video_bus_DOS(video, 0, 0);
  1488. }
  1489. static int acpi_video_bus_stop_devices(struct acpi_video_bus *video)
  1490. {
  1491. return acpi_video_bus_DOS(video, 0, 1);
  1492. }
  1493. static void acpi_video_bus_notify(acpi_handle handle, u32 event, void *data)
  1494. {
  1495. struct acpi_video_bus *video = data;
  1496. struct acpi_device *device = NULL;
  1497. struct input_dev *input;
  1498. int keycode;
  1499. if (!video)
  1500. return;
  1501. device = video->device;
  1502. input = video->input;
  1503. switch (event) {
  1504. case ACPI_VIDEO_NOTIFY_SWITCH: /* User requested a switch,
  1505. * most likely via hotkey. */
  1506. acpi_bus_generate_proc_event(device, event, 0);
  1507. keycode = KEY_SWITCHVIDEOMODE;
  1508. break;
  1509. case ACPI_VIDEO_NOTIFY_PROBE: /* User plugged in or removed a video
  1510. * connector. */
  1511. acpi_video_device_enumerate(video);
  1512. acpi_video_device_rebind(video);
  1513. acpi_bus_generate_proc_event(device, event, 0);
  1514. keycode = KEY_SWITCHVIDEOMODE;
  1515. break;
  1516. case ACPI_VIDEO_NOTIFY_CYCLE: /* Cycle Display output hotkey pressed. */
  1517. acpi_bus_generate_proc_event(device, event, 0);
  1518. keycode = KEY_SWITCHVIDEOMODE;
  1519. break;
  1520. case ACPI_VIDEO_NOTIFY_NEXT_OUTPUT: /* Next Display output hotkey pressed. */
  1521. acpi_bus_generate_proc_event(device, event, 0);
  1522. keycode = KEY_VIDEO_NEXT;
  1523. break;
  1524. case ACPI_VIDEO_NOTIFY_PREV_OUTPUT: /* previous Display output hotkey pressed. */
  1525. acpi_bus_generate_proc_event(device, event, 0);
  1526. keycode = KEY_VIDEO_PREV;
  1527. break;
  1528. default:
  1529. keycode = KEY_UNKNOWN;
  1530. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  1531. "Unsupported event [0x%x]\n", event));
  1532. break;
  1533. }
  1534. acpi_notifier_call_chain(device, event, 0);
  1535. input_report_key(input, keycode, 1);
  1536. input_sync(input);
  1537. input_report_key(input, keycode, 0);
  1538. input_sync(input);
  1539. return;
  1540. }
  1541. static void acpi_video_device_notify(acpi_handle handle, u32 event, void *data)
  1542. {
  1543. struct acpi_video_device *video_device = data;
  1544. struct acpi_device *device = NULL;
  1545. struct acpi_video_bus *bus;
  1546. struct input_dev *input;
  1547. int keycode;
  1548. if (!video_device)
  1549. return;
  1550. device = video_device->dev;
  1551. bus = video_device->video;
  1552. input = bus->input;
  1553. switch (event) {
  1554. case ACPI_VIDEO_NOTIFY_CYCLE_BRIGHTNESS: /* Cycle brightness */
  1555. if (brightness_switch_enabled)
  1556. acpi_video_switch_brightness(video_device, event);
  1557. acpi_bus_generate_proc_event(device, event, 0);
  1558. keycode = KEY_BRIGHTNESS_CYCLE;
  1559. break;
  1560. case ACPI_VIDEO_NOTIFY_INC_BRIGHTNESS: /* Increase brightness */
  1561. if (brightness_switch_enabled)
  1562. acpi_video_switch_brightness(video_device, event);
  1563. acpi_bus_generate_proc_event(device, event, 0);
  1564. keycode = KEY_BRIGHTNESSUP;
  1565. break;
  1566. case ACPI_VIDEO_NOTIFY_DEC_BRIGHTNESS: /* Decrease brightness */
  1567. if (brightness_switch_enabled)
  1568. acpi_video_switch_brightness(video_device, event);
  1569. acpi_bus_generate_proc_event(device, event, 0);
  1570. keycode = KEY_BRIGHTNESSDOWN;
  1571. break;
  1572. case ACPI_VIDEO_NOTIFY_ZERO_BRIGHTNESS: /* zero brightnesss */
  1573. if (brightness_switch_enabled)
  1574. acpi_video_switch_brightness(video_device, event);
  1575. acpi_bus_generate_proc_event(device, event, 0);
  1576. keycode = KEY_BRIGHTNESS_ZERO;
  1577. break;
  1578. case ACPI_VIDEO_NOTIFY_DISPLAY_OFF: /* display device off */
  1579. if (brightness_switch_enabled)
  1580. acpi_video_switch_brightness(video_device, event);
  1581. acpi_bus_generate_proc_event(device, event, 0);
  1582. keycode = KEY_DISPLAY_OFF;
  1583. break;
  1584. default:
  1585. keycode = KEY_UNKNOWN;
  1586. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  1587. "Unsupported event [0x%x]\n", event));
  1588. break;
  1589. }
  1590. acpi_notifier_call_chain(device, event, 0);
  1591. input_report_key(input, keycode, 1);
  1592. input_sync(input);
  1593. input_report_key(input, keycode, 0);
  1594. input_sync(input);
  1595. return;
  1596. }
  1597. static int instance;
  1598. static int acpi_video_resume(struct acpi_device *device)
  1599. {
  1600. struct acpi_video_bus *video;
  1601. struct acpi_video_device *video_device;
  1602. int i;
  1603. if (!device || !acpi_driver_data(device))
  1604. return -EINVAL;
  1605. video = acpi_driver_data(device);
  1606. for (i = 0; i < video->attached_count; i++) {
  1607. video_device = video->attached_array[i].bind_info;
  1608. if (video_device && video_device->backlight)
  1609. acpi_video_set_brightness(video_device->backlight);
  1610. }
  1611. return AE_OK;
  1612. }
  1613. static int acpi_video_bus_add(struct acpi_device *device)
  1614. {
  1615. acpi_status status;
  1616. struct acpi_video_bus *video;
  1617. struct input_dev *input;
  1618. int error;
  1619. video = kzalloc(sizeof(struct acpi_video_bus), GFP_KERNEL);
  1620. if (!video)
  1621. return -ENOMEM;
  1622. /* a hack to fix the duplicate name "VID" problem on T61 */
  1623. if (!strcmp(device->pnp.bus_id, "VID")) {
  1624. if (instance)
  1625. device->pnp.bus_id[3] = '0' + instance;
  1626. instance ++;
  1627. }
  1628. video->device = device;
  1629. strcpy(acpi_device_name(device), ACPI_VIDEO_BUS_NAME);
  1630. strcpy(acpi_device_class(device), ACPI_VIDEO_CLASS);
  1631. acpi_driver_data(device) = video;
  1632. acpi_video_bus_find_cap(video);
  1633. error = acpi_video_bus_check(video);
  1634. if (error)
  1635. goto err_free_video;
  1636. error = acpi_video_bus_add_fs(device);
  1637. if (error)
  1638. goto err_free_video;
  1639. mutex_init(&video->device_list_lock);
  1640. INIT_LIST_HEAD(&video->video_device_list);
  1641. acpi_video_bus_get_devices(video, device);
  1642. acpi_video_bus_start_devices(video);
  1643. status = acpi_install_notify_handler(device->handle,
  1644. ACPI_DEVICE_NOTIFY,
  1645. acpi_video_bus_notify, video);
  1646. if (ACPI_FAILURE(status)) {
  1647. ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
  1648. "Error installing notify handler\n"));
  1649. error = -ENODEV;
  1650. goto err_stop_video;
  1651. }
  1652. video->input = input = input_allocate_device();
  1653. if (!input) {
  1654. error = -ENOMEM;
  1655. goto err_uninstall_notify;
  1656. }
  1657. snprintf(video->phys, sizeof(video->phys),
  1658. "%s/video/input0", acpi_device_hid(video->device));
  1659. input->name = acpi_device_name(video->device);
  1660. input->phys = video->phys;
  1661. input->id.bustype = BUS_HOST;
  1662. input->id.product = 0x06;
  1663. input->dev.parent = &device->dev;
  1664. input->evbit[0] = BIT(EV_KEY);
  1665. set_bit(KEY_SWITCHVIDEOMODE, input->keybit);
  1666. set_bit(KEY_VIDEO_NEXT, input->keybit);
  1667. set_bit(KEY_VIDEO_PREV, input->keybit);
  1668. set_bit(KEY_BRIGHTNESS_CYCLE, input->keybit);
  1669. set_bit(KEY_BRIGHTNESSUP, input->keybit);
  1670. set_bit(KEY_BRIGHTNESSDOWN, input->keybit);
  1671. set_bit(KEY_BRIGHTNESS_ZERO, input->keybit);
  1672. set_bit(KEY_DISPLAY_OFF, input->keybit);
  1673. set_bit(KEY_UNKNOWN, input->keybit);
  1674. error = input_register_device(input);
  1675. if (error)
  1676. goto err_free_input_dev;
  1677. printk(KERN_INFO PREFIX "%s [%s] (multi-head: %s rom: %s post: %s)\n",
  1678. ACPI_VIDEO_DEVICE_NAME, acpi_device_bid(device),
  1679. video->flags.multihead ? "yes" : "no",
  1680. video->flags.rom ? "yes" : "no",
  1681. video->flags.post ? "yes" : "no");
  1682. return 0;
  1683. err_free_input_dev:
  1684. input_free_device(input);
  1685. err_uninstall_notify:
  1686. acpi_remove_notify_handler(device->handle, ACPI_DEVICE_NOTIFY,
  1687. acpi_video_bus_notify);
  1688. err_stop_video:
  1689. acpi_video_bus_stop_devices(video);
  1690. acpi_video_bus_put_devices(video);
  1691. kfree(video->attached_array);
  1692. acpi_video_bus_remove_fs(device);
  1693. err_free_video:
  1694. kfree(video);
  1695. acpi_driver_data(device) = NULL;
  1696. return error;
  1697. }
  1698. static int acpi_video_bus_remove(struct acpi_device *device, int type)
  1699. {
  1700. acpi_status status = 0;
  1701. struct acpi_video_bus *video = NULL;
  1702. if (!device || !acpi_driver_data(device))
  1703. return -EINVAL;
  1704. video = acpi_driver_data(device);
  1705. acpi_video_bus_stop_devices(video);
  1706. status = acpi_remove_notify_handler(video->device->handle,
  1707. ACPI_DEVICE_NOTIFY,
  1708. acpi_video_bus_notify);
  1709. acpi_video_bus_put_devices(video);
  1710. acpi_video_bus_remove_fs(device);
  1711. input_unregister_device(video->input);
  1712. kfree(video->attached_array);
  1713. kfree(video);
  1714. return 0;
  1715. }
  1716. static int __init acpi_video_init(void)
  1717. {
  1718. int result = 0;
  1719. /*
  1720. acpi_dbg_level = 0xFFFFFFFF;
  1721. acpi_dbg_layer = 0x08000000;
  1722. */
  1723. acpi_video_dir = proc_mkdir(ACPI_VIDEO_CLASS, acpi_root_dir);
  1724. if (!acpi_video_dir)
  1725. return -ENODEV;
  1726. acpi_video_dir->owner = THIS_MODULE;
  1727. result = acpi_bus_register_driver(&acpi_video_bus);
  1728. if (result < 0) {
  1729. remove_proc_entry(ACPI_VIDEO_CLASS, acpi_root_dir);
  1730. return -ENODEV;
  1731. }
  1732. return 0;
  1733. }
  1734. static void __exit acpi_video_exit(void)
  1735. {
  1736. acpi_bus_unregister_driver(&acpi_video_bus);
  1737. remove_proc_entry(ACPI_VIDEO_CLASS, acpi_root_dir);
  1738. return;
  1739. }
  1740. module_init(acpi_video_init);
  1741. module_exit(acpi_video_exit);