video.c 54 KB

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