video.c 53 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, *device_dir;
  877. struct acpi_video_device *vid_dev;
  878. vid_dev = acpi_driver_data(device);
  879. if (!vid_dev)
  880. return -ENODEV;
  881. device_dir = proc_mkdir(acpi_device_bid(device),
  882. vid_dev->video->dir);
  883. if (!device_dir)
  884. return -ENOMEM;
  885. device_dir->owner = THIS_MODULE;
  886. /* 'info' [R] */
  887. entry = create_proc_entry("info", S_IRUGO, device_dir);
  888. if (!entry)
  889. goto err_remove_dir;
  890. entry->proc_fops = &acpi_video_device_info_fops;
  891. entry->data = acpi_driver_data(device);
  892. entry->owner = THIS_MODULE;
  893. /* 'state' [R/W] */
  894. entry = create_proc_entry("state", S_IFREG | S_IRUGO | S_IWUSR,
  895. device_dir);
  896. if (!entry)
  897. goto err_remove_info;
  898. acpi_video_device_state_fops.write = acpi_video_device_write_state;
  899. entry->proc_fops = &acpi_video_device_state_fops;
  900. entry->data = acpi_driver_data(device);
  901. entry->owner = THIS_MODULE;
  902. /* 'brightness' [R/W] */
  903. entry = create_proc_entry("brightness", S_IFREG | S_IRUGO | S_IWUSR,
  904. device_dir);
  905. if (!entry)
  906. goto err_remove_state;
  907. acpi_video_device_brightness_fops.write =
  908. acpi_video_device_write_brightness;
  909. entry->proc_fops = &acpi_video_device_brightness_fops;
  910. entry->data = acpi_driver_data(device);
  911. entry->owner = THIS_MODULE;
  912. /* 'EDID' [R] */
  913. entry = create_proc_entry("EDID", S_IRUGO, device_dir);
  914. if (!entry)
  915. goto err_remove_brightness;
  916. entry->proc_fops = &acpi_video_device_EDID_fops;
  917. entry->data = acpi_driver_data(device);
  918. entry->owner = THIS_MODULE;
  919. acpi_device_dir(device) = device_dir;
  920. return 0;
  921. err_remove_brightness:
  922. remove_proc_entry("brightness", device_dir);
  923. err_remove_state:
  924. remove_proc_entry("state", device_dir);
  925. err_remove_info:
  926. remove_proc_entry("info", device_dir);
  927. err_remove_dir:
  928. remove_proc_entry(acpi_device_bid(device), vid_dev->video->dir);
  929. return -ENOMEM;
  930. }
  931. static int acpi_video_device_remove_fs(struct acpi_device *device)
  932. {
  933. struct acpi_video_device *vid_dev;
  934. struct proc_dir_entry *device_dir;
  935. vid_dev = acpi_driver_data(device);
  936. if (!vid_dev || !vid_dev->video || !vid_dev->video->dir)
  937. return -ENODEV;
  938. device_dir = acpi_device_dir(device);
  939. if (device_dir) {
  940. remove_proc_entry("info", device_dir);
  941. remove_proc_entry("state", device_dir);
  942. remove_proc_entry("brightness", device_dir);
  943. remove_proc_entry("EDID", device_dir);
  944. remove_proc_entry(acpi_device_bid(device), vid_dev->video->dir);
  945. acpi_device_dir(device) = NULL;
  946. }
  947. return 0;
  948. }
  949. /* video bus */
  950. static int acpi_video_bus_info_seq_show(struct seq_file *seq, void *offset)
  951. {
  952. struct acpi_video_bus *video = seq->private;
  953. if (!video)
  954. goto end;
  955. seq_printf(seq, "Switching heads: %s\n",
  956. video->flags.multihead ? "yes" : "no");
  957. seq_printf(seq, "Video ROM: %s\n",
  958. video->flags.rom ? "yes" : "no");
  959. seq_printf(seq, "Device to be POSTed on boot: %s\n",
  960. video->flags.post ? "yes" : "no");
  961. end:
  962. return 0;
  963. }
  964. static int acpi_video_bus_info_open_fs(struct inode *inode, struct file *file)
  965. {
  966. return single_open(file, acpi_video_bus_info_seq_show,
  967. PDE(inode)->data);
  968. }
  969. static int acpi_video_bus_ROM_seq_show(struct seq_file *seq, void *offset)
  970. {
  971. struct acpi_video_bus *video = seq->private;
  972. if (!video)
  973. goto end;
  974. printk(KERN_INFO PREFIX "Please implement %s\n", __func__);
  975. seq_printf(seq, "<TODO>\n");
  976. end:
  977. return 0;
  978. }
  979. static int acpi_video_bus_ROM_open_fs(struct inode *inode, struct file *file)
  980. {
  981. return single_open(file, acpi_video_bus_ROM_seq_show, PDE(inode)->data);
  982. }
  983. static int acpi_video_bus_POST_info_seq_show(struct seq_file *seq, void *offset)
  984. {
  985. struct acpi_video_bus *video = seq->private;
  986. unsigned long options;
  987. int status;
  988. if (!video)
  989. goto end;
  990. status = acpi_video_bus_POST_options(video, &options);
  991. if (ACPI_SUCCESS(status)) {
  992. if (!(options & 1)) {
  993. printk(KERN_WARNING PREFIX
  994. "The motherboard VGA device is not listed as a possible POST device.\n");
  995. printk(KERN_WARNING PREFIX
  996. "This indicates a BIOS bug. Please contact the manufacturer.\n");
  997. }
  998. printk("%lx\n", options);
  999. seq_printf(seq, "can POST: <integrated video>");
  1000. if (options & 2)
  1001. seq_printf(seq, " <PCI video>");
  1002. if (options & 4)
  1003. seq_printf(seq, " <AGP video>");
  1004. seq_putc(seq, '\n');
  1005. } else
  1006. seq_printf(seq, "<not supported>\n");
  1007. end:
  1008. return 0;
  1009. }
  1010. static int
  1011. acpi_video_bus_POST_info_open_fs(struct inode *inode, struct file *file)
  1012. {
  1013. return single_open(file, acpi_video_bus_POST_info_seq_show,
  1014. PDE(inode)->data);
  1015. }
  1016. static int acpi_video_bus_POST_seq_show(struct seq_file *seq, void *offset)
  1017. {
  1018. struct acpi_video_bus *video = seq->private;
  1019. int status;
  1020. unsigned long id;
  1021. if (!video)
  1022. goto end;
  1023. status = acpi_video_bus_get_POST(video, &id);
  1024. if (!ACPI_SUCCESS(status)) {
  1025. seq_printf(seq, "<not supported>\n");
  1026. goto end;
  1027. }
  1028. seq_printf(seq, "device POSTed is <%s>\n", device_decode[id & 3]);
  1029. end:
  1030. return 0;
  1031. }
  1032. static int acpi_video_bus_DOS_seq_show(struct seq_file *seq, void *offset)
  1033. {
  1034. struct acpi_video_bus *video = seq->private;
  1035. seq_printf(seq, "DOS setting: <%d>\n", video->dos_setting);
  1036. return 0;
  1037. }
  1038. static int acpi_video_bus_POST_open_fs(struct inode *inode, struct file *file)
  1039. {
  1040. return single_open(file, acpi_video_bus_POST_seq_show,
  1041. PDE(inode)->data);
  1042. }
  1043. static int acpi_video_bus_DOS_open_fs(struct inode *inode, struct file *file)
  1044. {
  1045. return single_open(file, acpi_video_bus_DOS_seq_show, PDE(inode)->data);
  1046. }
  1047. static ssize_t
  1048. acpi_video_bus_write_POST(struct file *file,
  1049. const char __user * buffer,
  1050. size_t count, loff_t * data)
  1051. {
  1052. int status;
  1053. struct seq_file *m = file->private_data;
  1054. struct acpi_video_bus *video = m->private;
  1055. char str[12] = { 0 };
  1056. unsigned long opt, options;
  1057. if (!video || count + 1 > sizeof str)
  1058. return -EINVAL;
  1059. status = acpi_video_bus_POST_options(video, &options);
  1060. if (!ACPI_SUCCESS(status))
  1061. return -EINVAL;
  1062. if (copy_from_user(str, buffer, count))
  1063. return -EFAULT;
  1064. str[count] = 0;
  1065. opt = strtoul(str, NULL, 0);
  1066. if (opt > 3)
  1067. return -EFAULT;
  1068. /* just in case an OEM 'forgot' the motherboard... */
  1069. options |= 1;
  1070. if (options & (1ul << opt)) {
  1071. status = acpi_video_bus_set_POST(video, opt);
  1072. if (!ACPI_SUCCESS(status))
  1073. return -EFAULT;
  1074. }
  1075. return count;
  1076. }
  1077. static ssize_t
  1078. acpi_video_bus_write_DOS(struct file *file,
  1079. const char __user * buffer,
  1080. size_t count, loff_t * data)
  1081. {
  1082. int status;
  1083. struct seq_file *m = file->private_data;
  1084. struct acpi_video_bus *video = m->private;
  1085. char str[12] = { 0 };
  1086. unsigned long opt;
  1087. if (!video || count + 1 > sizeof str)
  1088. return -EINVAL;
  1089. if (copy_from_user(str, buffer, count))
  1090. return -EFAULT;
  1091. str[count] = 0;
  1092. opt = strtoul(str, NULL, 0);
  1093. if (opt > 7)
  1094. return -EFAULT;
  1095. status = acpi_video_bus_DOS(video, opt & 0x3, (opt & 0x4) >> 2);
  1096. if (!ACPI_SUCCESS(status))
  1097. return -EFAULT;
  1098. return count;
  1099. }
  1100. static int acpi_video_bus_add_fs(struct acpi_device *device)
  1101. {
  1102. struct acpi_video_bus *video = acpi_driver_data(device);
  1103. struct proc_dir_entry *device_dir;
  1104. struct proc_dir_entry *entry;
  1105. device_dir = proc_mkdir(acpi_device_bid(device), acpi_video_dir);
  1106. if (!device_dir)
  1107. return -ENOMEM;
  1108. device_dir->owner = THIS_MODULE;
  1109. /* 'info' [R] */
  1110. entry = create_proc_entry("info", S_IRUGO, device_dir);
  1111. if (!entry)
  1112. goto err_remove_dir;
  1113. entry->proc_fops = &acpi_video_bus_info_fops;
  1114. entry->data = acpi_driver_data(device);
  1115. entry->owner = THIS_MODULE;
  1116. /* 'ROM' [R] */
  1117. entry = create_proc_entry("ROM", S_IRUGO, device_dir);
  1118. if (!entry)
  1119. goto err_remove_info;
  1120. entry->proc_fops = &acpi_video_bus_ROM_fops;
  1121. entry->data = acpi_driver_data(device);
  1122. entry->owner = THIS_MODULE;
  1123. /* 'POST_info' [R] */
  1124. entry = create_proc_entry("POST_info", S_IRUGO, device_dir);
  1125. if (!entry)
  1126. goto err_remove_rom;
  1127. entry->proc_fops = &acpi_video_bus_POST_info_fops;
  1128. entry->data = acpi_driver_data(device);
  1129. entry->owner = THIS_MODULE;
  1130. /* 'POST' [R/W] */
  1131. entry = create_proc_entry("POST", S_IFREG | S_IRUGO | S_IRUSR,
  1132. device_dir);
  1133. if (!entry)
  1134. goto err_remove_post_info;
  1135. acpi_video_bus_POST_fops.write = acpi_video_bus_write_POST;
  1136. entry->proc_fops = &acpi_video_bus_POST_fops;
  1137. entry->data = acpi_driver_data(device);
  1138. entry->owner = THIS_MODULE;
  1139. /* 'DOS' [R/W] */
  1140. entry = create_proc_entry("DOS", S_IFREG | S_IRUGO | S_IRUSR,
  1141. device_dir);
  1142. if (!entry)
  1143. goto err_remove_post;
  1144. acpi_video_bus_DOS_fops.write = acpi_video_bus_write_DOS;
  1145. entry->proc_fops = &acpi_video_bus_DOS_fops;
  1146. entry->data = acpi_driver_data(device);
  1147. entry->owner = THIS_MODULE;
  1148. video->dir = acpi_device_dir(device) = device_dir;
  1149. return 0;
  1150. err_remove_post:
  1151. remove_proc_entry("POST", device_dir);
  1152. err_remove_post_info:
  1153. remove_proc_entry("POST_info", device_dir);
  1154. err_remove_rom:
  1155. remove_proc_entry("ROM", device_dir);
  1156. err_remove_info:
  1157. remove_proc_entry("info", device_dir);
  1158. err_remove_dir:
  1159. remove_proc_entry(acpi_device_bid(device), acpi_video_dir);
  1160. return -ENOMEM;
  1161. }
  1162. static int acpi_video_bus_remove_fs(struct acpi_device *device)
  1163. {
  1164. struct proc_dir_entry *device_dir = acpi_device_dir(device);
  1165. if (device_dir) {
  1166. remove_proc_entry("info", device_dir);
  1167. remove_proc_entry("ROM", device_dir);
  1168. remove_proc_entry("POST_info", device_dir);
  1169. remove_proc_entry("POST", device_dir);
  1170. remove_proc_entry("DOS", device_dir);
  1171. remove_proc_entry(acpi_device_bid(device), acpi_video_dir);
  1172. acpi_device_dir(device) = NULL;
  1173. }
  1174. return 0;
  1175. }
  1176. /* --------------------------------------------------------------------------
  1177. Driver Interface
  1178. -------------------------------------------------------------------------- */
  1179. /* device interface */
  1180. static struct acpi_video_device_attrib*
  1181. acpi_video_get_device_attr(struct acpi_video_bus *video, unsigned long device_id)
  1182. {
  1183. struct acpi_video_enumerated_device *ids;
  1184. int i;
  1185. for (i = 0; i < video->attached_count; i++) {
  1186. ids = &video->attached_array[i];
  1187. if ((ids->value.int_val & 0xffff) == device_id)
  1188. return &ids->value.attrib;
  1189. }
  1190. return NULL;
  1191. }
  1192. static int
  1193. acpi_video_bus_get_one_device(struct acpi_device *device,
  1194. struct acpi_video_bus *video)
  1195. {
  1196. unsigned long device_id;
  1197. int status;
  1198. struct acpi_video_device *data;
  1199. struct acpi_video_device_attrib* attribute;
  1200. if (!device || !video)
  1201. return -EINVAL;
  1202. status =
  1203. acpi_evaluate_integer(device->handle, "_ADR", NULL, &device_id);
  1204. if (ACPI_SUCCESS(status)) {
  1205. data = kzalloc(sizeof(struct acpi_video_device), GFP_KERNEL);
  1206. if (!data)
  1207. return -ENOMEM;
  1208. strcpy(acpi_device_name(device), ACPI_VIDEO_DEVICE_NAME);
  1209. strcpy(acpi_device_class(device), ACPI_VIDEO_CLASS);
  1210. acpi_driver_data(device) = data;
  1211. data->device_id = device_id;
  1212. data->video = video;
  1213. data->dev = device;
  1214. attribute = acpi_video_get_device_attr(video, device_id);
  1215. if((attribute != NULL) && attribute->device_id_scheme) {
  1216. switch (attribute->display_type) {
  1217. case ACPI_VIDEO_DISPLAY_CRT:
  1218. data->flags.crt = 1;
  1219. break;
  1220. case ACPI_VIDEO_DISPLAY_TV:
  1221. data->flags.tvout = 1;
  1222. break;
  1223. case ACPI_VIDEO_DISPLAY_DVI:
  1224. data->flags.dvi = 1;
  1225. break;
  1226. case ACPI_VIDEO_DISPLAY_LCD:
  1227. data->flags.lcd = 1;
  1228. break;
  1229. default:
  1230. data->flags.unknown = 1;
  1231. break;
  1232. }
  1233. if(attribute->bios_can_detect)
  1234. data->flags.bios = 1;
  1235. } else
  1236. data->flags.unknown = 1;
  1237. acpi_video_device_bind(video, data);
  1238. acpi_video_device_find_cap(data);
  1239. status = acpi_install_notify_handler(device->handle,
  1240. ACPI_DEVICE_NOTIFY,
  1241. acpi_video_device_notify,
  1242. data);
  1243. if (ACPI_FAILURE(status)) {
  1244. ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
  1245. "Error installing notify handler\n"));
  1246. if(data->brightness)
  1247. kfree(data->brightness->levels);
  1248. kfree(data->brightness);
  1249. kfree(data);
  1250. return -ENODEV;
  1251. }
  1252. mutex_lock(&video->device_list_lock);
  1253. list_add_tail(&data->entry, &video->video_device_list);
  1254. mutex_unlock(&video->device_list_lock);
  1255. acpi_video_device_add_fs(device);
  1256. return 0;
  1257. }
  1258. return -ENOENT;
  1259. }
  1260. /*
  1261. * Arg:
  1262. * video : video bus device
  1263. *
  1264. * Return:
  1265. * none
  1266. *
  1267. * Enumerate the video device list of the video bus,
  1268. * bind the ids with the corresponding video devices
  1269. * under the video bus.
  1270. */
  1271. static void acpi_video_device_rebind(struct acpi_video_bus *video)
  1272. {
  1273. struct acpi_video_device *dev;
  1274. mutex_lock(&video->device_list_lock);
  1275. list_for_each_entry(dev, &video->video_device_list, entry)
  1276. acpi_video_device_bind(video, dev);
  1277. mutex_unlock(&video->device_list_lock);
  1278. }
  1279. /*
  1280. * Arg:
  1281. * video : video bus device
  1282. * device : video output device under the video
  1283. * bus
  1284. *
  1285. * Return:
  1286. * none
  1287. *
  1288. * Bind the ids with the corresponding video devices
  1289. * under the video bus.
  1290. */
  1291. static void
  1292. acpi_video_device_bind(struct acpi_video_bus *video,
  1293. struct acpi_video_device *device)
  1294. {
  1295. struct acpi_video_enumerated_device *ids;
  1296. int i;
  1297. for (i = 0; i < video->attached_count; i++) {
  1298. ids = &video->attached_array[i];
  1299. if (device->device_id == (ids->value.int_val & 0xffff)) {
  1300. ids->bind_info = device;
  1301. ACPI_DEBUG_PRINT((ACPI_DB_INFO, "device_bind %d\n", i));
  1302. }
  1303. }
  1304. }
  1305. /*
  1306. * Arg:
  1307. * video : video bus device
  1308. *
  1309. * Return:
  1310. * < 0 : error
  1311. *
  1312. * Call _DOD to enumerate all devices attached to display adapter
  1313. *
  1314. */
  1315. static int acpi_video_device_enumerate(struct acpi_video_bus *video)
  1316. {
  1317. int status;
  1318. int count;
  1319. int i;
  1320. struct acpi_video_enumerated_device *active_list;
  1321. struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
  1322. union acpi_object *dod = NULL;
  1323. union acpi_object *obj;
  1324. status = acpi_evaluate_object(video->device->handle, "_DOD", NULL, &buffer);
  1325. if (!ACPI_SUCCESS(status)) {
  1326. ACPI_EXCEPTION((AE_INFO, status, "Evaluating _DOD"));
  1327. return status;
  1328. }
  1329. dod = buffer.pointer;
  1330. if (!dod || (dod->type != ACPI_TYPE_PACKAGE)) {
  1331. ACPI_EXCEPTION((AE_INFO, status, "Invalid _DOD data"));
  1332. status = -EFAULT;
  1333. goto out;
  1334. }
  1335. ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found %d video heads in _DOD\n",
  1336. dod->package.count));
  1337. active_list = kcalloc(1 + dod->package.count,
  1338. sizeof(struct acpi_video_enumerated_device),
  1339. GFP_KERNEL);
  1340. if (!active_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
  1349. "Invalid _DOD data in element %d\n", i);
  1350. continue;
  1351. }
  1352. active_list[count].value.int_val = obj->integer.value;
  1353. active_list[count].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. kfree(video->attached_array);
  1359. video->attached_array = active_list;
  1360. video->attached_count = count;
  1361. out:
  1362. kfree(buffer.pointer);
  1363. return status;
  1364. }
  1365. static int
  1366. acpi_video_get_next_level(struct acpi_video_device *device,
  1367. u32 level_current, u32 event)
  1368. {
  1369. int min, max, min_above, max_below, i, l, delta = 255;
  1370. max = max_below = 0;
  1371. min = min_above = 255;
  1372. /* Find closest level to level_current */
  1373. for (i = 0; i < device->brightness->count; i++) {
  1374. l = device->brightness->levels[i];
  1375. if (abs(l - level_current) < abs(delta)) {
  1376. delta = l - level_current;
  1377. if (!delta)
  1378. break;
  1379. }
  1380. }
  1381. /* Ajust level_current to closest available level */
  1382. level_current += delta;
  1383. for (i = 0; i < device->brightness->count; i++) {
  1384. l = device->brightness->levels[i];
  1385. if (l < min)
  1386. min = l;
  1387. if (l > max)
  1388. max = l;
  1389. if (l < min_above && l > level_current)
  1390. min_above = l;
  1391. if (l > max_below && l < level_current)
  1392. max_below = l;
  1393. }
  1394. switch (event) {
  1395. case ACPI_VIDEO_NOTIFY_CYCLE_BRIGHTNESS:
  1396. return (level_current < max) ? min_above : min;
  1397. case ACPI_VIDEO_NOTIFY_INC_BRIGHTNESS:
  1398. return (level_current < max) ? min_above : max;
  1399. case ACPI_VIDEO_NOTIFY_DEC_BRIGHTNESS:
  1400. return (level_current > min) ? max_below : min;
  1401. case ACPI_VIDEO_NOTIFY_ZERO_BRIGHTNESS:
  1402. case ACPI_VIDEO_NOTIFY_DISPLAY_OFF:
  1403. return 0;
  1404. default:
  1405. return level_current;
  1406. }
  1407. }
  1408. static void
  1409. acpi_video_switch_brightness(struct acpi_video_device *device, int event)
  1410. {
  1411. unsigned long level_current, level_next;
  1412. acpi_video_device_lcd_get_level_current(device, &level_current);
  1413. level_next = acpi_video_get_next_level(device, level_current, event);
  1414. acpi_video_device_lcd_set_level(device, level_next);
  1415. }
  1416. static int
  1417. acpi_video_bus_get_devices(struct acpi_video_bus *video,
  1418. struct acpi_device *device)
  1419. {
  1420. int status = 0;
  1421. struct acpi_device *dev;
  1422. acpi_video_device_enumerate(video);
  1423. list_for_each_entry(dev, &device->children, node) {
  1424. status = acpi_video_bus_get_one_device(dev, video);
  1425. if (ACPI_FAILURE(status)) {
  1426. ACPI_EXCEPTION((AE_INFO, status, "Cant attach device"));
  1427. continue;
  1428. }
  1429. }
  1430. return status;
  1431. }
  1432. static int acpi_video_bus_put_one_device(struct acpi_video_device *device)
  1433. {
  1434. acpi_status status;
  1435. struct acpi_video_bus *video;
  1436. if (!device || !device->video)
  1437. return -ENOENT;
  1438. video = device->video;
  1439. acpi_video_device_remove_fs(device->dev);
  1440. status = acpi_remove_notify_handler(device->dev->handle,
  1441. ACPI_DEVICE_NOTIFY,
  1442. acpi_video_device_notify);
  1443. backlight_device_unregister(device->backlight);
  1444. if (device->cdev) {
  1445. sysfs_remove_link(&device->dev->dev.kobj,
  1446. "thermal_cooling");
  1447. sysfs_remove_link(&device->cdev->device.kobj,
  1448. "device");
  1449. thermal_cooling_device_unregister(device->cdev);
  1450. device->cdev = NULL;
  1451. }
  1452. video_output_unregister(device->output_dev);
  1453. return 0;
  1454. }
  1455. static int acpi_video_bus_put_devices(struct acpi_video_bus *video)
  1456. {
  1457. int status;
  1458. struct acpi_video_device *dev, *next;
  1459. mutex_lock(&video->device_list_lock);
  1460. list_for_each_entry_safe(dev, next, &video->video_device_list, entry) {
  1461. status = acpi_video_bus_put_one_device(dev);
  1462. if (ACPI_FAILURE(status))
  1463. printk(KERN_WARNING PREFIX
  1464. "hhuuhhuu bug in acpi video driver.\n");
  1465. if (dev->brightness) {
  1466. kfree(dev->brightness->levels);
  1467. kfree(dev->brightness);
  1468. }
  1469. list_del(&dev->entry);
  1470. kfree(dev);
  1471. }
  1472. mutex_unlock(&video->device_list_lock);
  1473. return 0;
  1474. }
  1475. /* acpi_video interface */
  1476. static int acpi_video_bus_start_devices(struct acpi_video_bus *video)
  1477. {
  1478. return acpi_video_bus_DOS(video, 0, 0);
  1479. }
  1480. static int acpi_video_bus_stop_devices(struct acpi_video_bus *video)
  1481. {
  1482. return acpi_video_bus_DOS(video, 0, 1);
  1483. }
  1484. static void acpi_video_bus_notify(acpi_handle handle, u32 event, void *data)
  1485. {
  1486. struct acpi_video_bus *video = data;
  1487. struct acpi_device *device = NULL;
  1488. struct input_dev *input;
  1489. int keycode;
  1490. if (!video)
  1491. return;
  1492. device = video->device;
  1493. input = video->input;
  1494. switch (event) {
  1495. case ACPI_VIDEO_NOTIFY_SWITCH: /* User requested a switch,
  1496. * most likely via hotkey. */
  1497. acpi_bus_generate_proc_event(device, event, 0);
  1498. keycode = KEY_SWITCHVIDEOMODE;
  1499. break;
  1500. case ACPI_VIDEO_NOTIFY_PROBE: /* User plugged in or removed a video
  1501. * connector. */
  1502. acpi_video_device_enumerate(video);
  1503. acpi_video_device_rebind(video);
  1504. acpi_bus_generate_proc_event(device, event, 0);
  1505. keycode = KEY_SWITCHVIDEOMODE;
  1506. break;
  1507. case ACPI_VIDEO_NOTIFY_CYCLE: /* Cycle Display output hotkey pressed. */
  1508. acpi_bus_generate_proc_event(device, event, 0);
  1509. keycode = KEY_SWITCHVIDEOMODE;
  1510. break;
  1511. case ACPI_VIDEO_NOTIFY_NEXT_OUTPUT: /* Next Display output hotkey pressed. */
  1512. acpi_bus_generate_proc_event(device, event, 0);
  1513. keycode = KEY_VIDEO_NEXT;
  1514. break;
  1515. case ACPI_VIDEO_NOTIFY_PREV_OUTPUT: /* previous Display output hotkey pressed. */
  1516. acpi_bus_generate_proc_event(device, event, 0);
  1517. keycode = KEY_VIDEO_PREV;
  1518. break;
  1519. default:
  1520. keycode = KEY_UNKNOWN;
  1521. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  1522. "Unsupported event [0x%x]\n", event));
  1523. break;
  1524. }
  1525. acpi_notifier_call_chain(device, event, 0);
  1526. input_report_key(input, keycode, 1);
  1527. input_sync(input);
  1528. input_report_key(input, keycode, 0);
  1529. input_sync(input);
  1530. return;
  1531. }
  1532. static void acpi_video_device_notify(acpi_handle handle, u32 event, void *data)
  1533. {
  1534. struct acpi_video_device *video_device = data;
  1535. struct acpi_device *device = NULL;
  1536. struct acpi_video_bus *bus;
  1537. struct input_dev *input;
  1538. int keycode;
  1539. if (!video_device)
  1540. return;
  1541. device = video_device->dev;
  1542. bus = video_device->video;
  1543. input = bus->input;
  1544. switch (event) {
  1545. case ACPI_VIDEO_NOTIFY_CYCLE_BRIGHTNESS: /* Cycle brightness */
  1546. if (brightness_switch_enabled)
  1547. acpi_video_switch_brightness(video_device, event);
  1548. acpi_bus_generate_proc_event(device, event, 0);
  1549. keycode = KEY_BRIGHTNESS_CYCLE;
  1550. break;
  1551. case ACPI_VIDEO_NOTIFY_INC_BRIGHTNESS: /* Increase brightness */
  1552. if (brightness_switch_enabled)
  1553. acpi_video_switch_brightness(video_device, event);
  1554. acpi_bus_generate_proc_event(device, event, 0);
  1555. keycode = KEY_BRIGHTNESSUP;
  1556. break;
  1557. case ACPI_VIDEO_NOTIFY_DEC_BRIGHTNESS: /* Decrease brightness */
  1558. if (brightness_switch_enabled)
  1559. acpi_video_switch_brightness(video_device, event);
  1560. acpi_bus_generate_proc_event(device, event, 0);
  1561. keycode = KEY_BRIGHTNESSDOWN;
  1562. break;
  1563. case ACPI_VIDEO_NOTIFY_ZERO_BRIGHTNESS: /* zero brightnesss */
  1564. if (brightness_switch_enabled)
  1565. acpi_video_switch_brightness(video_device, event);
  1566. acpi_bus_generate_proc_event(device, event, 0);
  1567. keycode = KEY_BRIGHTNESS_ZERO;
  1568. break;
  1569. case ACPI_VIDEO_NOTIFY_DISPLAY_OFF: /* display device off */
  1570. if (brightness_switch_enabled)
  1571. acpi_video_switch_brightness(video_device, event);
  1572. acpi_bus_generate_proc_event(device, event, 0);
  1573. keycode = KEY_DISPLAY_OFF;
  1574. break;
  1575. default:
  1576. keycode = KEY_UNKNOWN;
  1577. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  1578. "Unsupported event [0x%x]\n", event));
  1579. break;
  1580. }
  1581. acpi_notifier_call_chain(device, event, 0);
  1582. input_report_key(input, keycode, 1);
  1583. input_sync(input);
  1584. input_report_key(input, keycode, 0);
  1585. input_sync(input);
  1586. return;
  1587. }
  1588. static int instance;
  1589. static int acpi_video_resume(struct acpi_device *device)
  1590. {
  1591. struct acpi_video_bus *video;
  1592. struct acpi_video_device *video_device;
  1593. int i;
  1594. if (!device || !acpi_driver_data(device))
  1595. return -EINVAL;
  1596. video = acpi_driver_data(device);
  1597. for (i = 0; i < video->attached_count; i++) {
  1598. video_device = video->attached_array[i].bind_info;
  1599. if (video_device && video_device->backlight)
  1600. acpi_video_set_brightness(video_device->backlight);
  1601. }
  1602. return AE_OK;
  1603. }
  1604. static int acpi_video_bus_add(struct acpi_device *device)
  1605. {
  1606. acpi_status status;
  1607. struct acpi_video_bus *video;
  1608. struct input_dev *input;
  1609. int error;
  1610. video = kzalloc(sizeof(struct acpi_video_bus), GFP_KERNEL);
  1611. if (!video)
  1612. return -ENOMEM;
  1613. /* a hack to fix the duplicate name "VID" problem on T61 */
  1614. if (!strcmp(device->pnp.bus_id, "VID")) {
  1615. if (instance)
  1616. device->pnp.bus_id[3] = '0' + instance;
  1617. instance ++;
  1618. }
  1619. video->device = device;
  1620. strcpy(acpi_device_name(device), ACPI_VIDEO_BUS_NAME);
  1621. strcpy(acpi_device_class(device), ACPI_VIDEO_CLASS);
  1622. acpi_driver_data(device) = video;
  1623. acpi_video_bus_find_cap(video);
  1624. error = acpi_video_bus_check(video);
  1625. if (error)
  1626. goto err_free_video;
  1627. error = acpi_video_bus_add_fs(device);
  1628. if (error)
  1629. goto err_free_video;
  1630. mutex_init(&video->device_list_lock);
  1631. INIT_LIST_HEAD(&video->video_device_list);
  1632. acpi_video_bus_get_devices(video, device);
  1633. acpi_video_bus_start_devices(video);
  1634. status = acpi_install_notify_handler(device->handle,
  1635. ACPI_DEVICE_NOTIFY,
  1636. acpi_video_bus_notify, video);
  1637. if (ACPI_FAILURE(status)) {
  1638. ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
  1639. "Error installing notify handler\n"));
  1640. error = -ENODEV;
  1641. goto err_stop_video;
  1642. }
  1643. video->input = input = input_allocate_device();
  1644. if (!input) {
  1645. error = -ENOMEM;
  1646. goto err_uninstall_notify;
  1647. }
  1648. snprintf(video->phys, sizeof(video->phys),
  1649. "%s/video/input0", acpi_device_hid(video->device));
  1650. input->name = acpi_device_name(video->device);
  1651. input->phys = video->phys;
  1652. input->id.bustype = BUS_HOST;
  1653. input->id.product = 0x06;
  1654. input->dev.parent = &device->dev;
  1655. input->evbit[0] = BIT(EV_KEY);
  1656. set_bit(KEY_SWITCHVIDEOMODE, input->keybit);
  1657. set_bit(KEY_VIDEO_NEXT, input->keybit);
  1658. set_bit(KEY_VIDEO_PREV, input->keybit);
  1659. set_bit(KEY_BRIGHTNESS_CYCLE, input->keybit);
  1660. set_bit(KEY_BRIGHTNESSUP, input->keybit);
  1661. set_bit(KEY_BRIGHTNESSDOWN, input->keybit);
  1662. set_bit(KEY_BRIGHTNESS_ZERO, input->keybit);
  1663. set_bit(KEY_DISPLAY_OFF, input->keybit);
  1664. set_bit(KEY_UNKNOWN, input->keybit);
  1665. error = input_register_device(input);
  1666. if (error)
  1667. goto err_free_input_dev;
  1668. printk(KERN_INFO PREFIX "%s [%s] (multi-head: %s rom: %s post: %s)\n",
  1669. ACPI_VIDEO_DEVICE_NAME, acpi_device_bid(device),
  1670. video->flags.multihead ? "yes" : "no",
  1671. video->flags.rom ? "yes" : "no",
  1672. video->flags.post ? "yes" : "no");
  1673. return 0;
  1674. err_free_input_dev:
  1675. input_free_device(input);
  1676. err_uninstall_notify:
  1677. acpi_remove_notify_handler(device->handle, ACPI_DEVICE_NOTIFY,
  1678. acpi_video_bus_notify);
  1679. err_stop_video:
  1680. acpi_video_bus_stop_devices(video);
  1681. acpi_video_bus_put_devices(video);
  1682. kfree(video->attached_array);
  1683. acpi_video_bus_remove_fs(device);
  1684. err_free_video:
  1685. kfree(video);
  1686. acpi_driver_data(device) = NULL;
  1687. return error;
  1688. }
  1689. static int acpi_video_bus_remove(struct acpi_device *device, int type)
  1690. {
  1691. acpi_status status = 0;
  1692. struct acpi_video_bus *video = NULL;
  1693. if (!device || !acpi_driver_data(device))
  1694. return -EINVAL;
  1695. video = acpi_driver_data(device);
  1696. acpi_video_bus_stop_devices(video);
  1697. status = acpi_remove_notify_handler(video->device->handle,
  1698. ACPI_DEVICE_NOTIFY,
  1699. acpi_video_bus_notify);
  1700. acpi_video_bus_put_devices(video);
  1701. acpi_video_bus_remove_fs(device);
  1702. input_unregister_device(video->input);
  1703. kfree(video->attached_array);
  1704. kfree(video);
  1705. return 0;
  1706. }
  1707. static int __init acpi_video_init(void)
  1708. {
  1709. int result = 0;
  1710. /*
  1711. acpi_dbg_level = 0xFFFFFFFF;
  1712. acpi_dbg_layer = 0x08000000;
  1713. */
  1714. acpi_video_dir = proc_mkdir(ACPI_VIDEO_CLASS, acpi_root_dir);
  1715. if (!acpi_video_dir)
  1716. return -ENODEV;
  1717. acpi_video_dir->owner = THIS_MODULE;
  1718. result = acpi_bus_register_driver(&acpi_video_bus);
  1719. if (result < 0) {
  1720. remove_proc_entry(ACPI_VIDEO_CLASS, acpi_root_dir);
  1721. return -ENODEV;
  1722. }
  1723. return 0;
  1724. }
  1725. static void __exit acpi_video_exit(void)
  1726. {
  1727. acpi_bus_unregister_driver(&acpi_video_bus);
  1728. remove_proc_entry(ACPI_VIDEO_CLASS, acpi_root_dir);
  1729. return;
  1730. }
  1731. module_init(acpi_video_init);
  1732. module_exit(acpi_video_exit);