video.c 54 KB

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