video.c 52 KB

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