video.c 53 KB

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