video.c 53 KB

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