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