video.c 54 KB

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