video.c 52 KB

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