video.c 53 KB

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