blob: d64a142e5e10a6b9526a29950a717db575194be8 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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>
Thomas Tuttlef4715182006-12-19 12:56:14 -08006 * Copyright (C) 2006 Thomas Tuttle <linux-kernel@ttuttle.net>
Linus Torvalds1da177e2005-04-16 15:20:36 -07007 *
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
27#include <linux/kernel.h>
28#include <linux/module.h>
29#include <linux/init.h>
30#include <linux/types.h>
31#include <linux/list.h>
Dmitry Torokhovbbac81f2007-11-05 11:43:32 -050032#include <linux/mutex.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070033#include <linux/proc_fs.h>
34#include <linux/seq_file.h>
Luming Yue9dab192007-08-20 18:23:53 +080035#include <linux/input.h>
Yu Luming2f3d0002006-11-11 02:40:34 +080036#include <linux/backlight.h>
Zhang Rui702ed512008-01-17 15:51:22 +080037#include <linux/thermal.h>
Luming Yu23b0f012007-05-09 21:07:05 +080038#include <linux/video_output.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070039#include <asm/uaccess.h>
40
41#include <acpi/acpi_bus.h>
42#include <acpi/acpi_drivers.h>
43
44#define ACPI_VIDEO_COMPONENT 0x08000000
45#define ACPI_VIDEO_CLASS "video"
Linus Torvalds1da177e2005-04-16 15:20:36 -070046#define ACPI_VIDEO_BUS_NAME "Video Bus"
47#define ACPI_VIDEO_DEVICE_NAME "Video Device"
48#define ACPI_VIDEO_NOTIFY_SWITCH 0x80
49#define ACPI_VIDEO_NOTIFY_PROBE 0x81
50#define ACPI_VIDEO_NOTIFY_CYCLE 0x82
51#define ACPI_VIDEO_NOTIFY_NEXT_OUTPUT 0x83
52#define ACPI_VIDEO_NOTIFY_PREV_OUTPUT 0x84
53
Thomas Tuttlef4715182006-12-19 12:56:14 -080054#define ACPI_VIDEO_NOTIFY_CYCLE_BRIGHTNESS 0x85
55#define ACPI_VIDEO_NOTIFY_INC_BRIGHTNESS 0x86
56#define ACPI_VIDEO_NOTIFY_DEC_BRIGHTNESS 0x87
57#define ACPI_VIDEO_NOTIFY_ZERO_BRIGHTNESS 0x88
58#define ACPI_VIDEO_NOTIFY_DISPLAY_OFF 0x89
Linus Torvalds1da177e2005-04-16 15:20:36 -070059
Linus Torvalds1da177e2005-04-16 15:20:36 -070060#define ACPI_VIDEO_HEAD_INVALID (~0u - 1)
61#define ACPI_VIDEO_HEAD_END (~0u)
Yu Luming2f3d0002006-11-11 02:40:34 +080062#define MAX_NAME_LEN 20
Linus Torvalds1da177e2005-04-16 15:20:36 -070063
Rui Zhang82cae992007-01-03 23:40:53 -050064#define ACPI_VIDEO_DISPLAY_CRT 1
65#define ACPI_VIDEO_DISPLAY_TV 2
66#define ACPI_VIDEO_DISPLAY_DVI 3
67#define ACPI_VIDEO_DISPLAY_LCD 4
68
Linus Torvalds1da177e2005-04-16 15:20:36 -070069#define _COMPONENT ACPI_VIDEO_COMPONENT
Len Brownf52fd662007-02-12 22:42:12 -050070ACPI_MODULE_NAME("video");
Linus Torvalds1da177e2005-04-16 15:20:36 -070071
Len Brownf52fd662007-02-12 22:42:12 -050072MODULE_AUTHOR("Bruno Ducrot");
Len Brown7cda93e2007-02-12 23:50:02 -050073MODULE_DESCRIPTION("ACPI Video Driver");
Linus Torvalds1da177e2005-04-16 15:20:36 -070074MODULE_LICENSE("GPL");
75
Zhang Rui8a681a42008-01-25 14:47:49 +080076static int brightness_switch_enabled = 1;
77module_param(brightness_switch_enabled, bool, 0644);
78
Len Brown4be44fc2005-08-05 00:44:28 -040079static int acpi_video_bus_add(struct acpi_device *device);
80static int acpi_video_bus_remove(struct acpi_device *device, int type);
Matthew Garrett863c1492008-02-04 23:31:24 -080081static int acpi_video_resume(struct acpi_device *device);
Linus Torvalds1da177e2005-04-16 15:20:36 -070082
Thomas Renninger1ba90e32007-07-23 14:44:41 +020083static const struct acpi_device_id video_device_ids[] = {
84 {ACPI_VIDEO_HID, 0},
85 {"", 0},
86};
87MODULE_DEVICE_TABLE(acpi, video_device_ids);
88
Linus Torvalds1da177e2005-04-16 15:20:36 -070089static struct acpi_driver acpi_video_bus = {
Len Brownc2b67052007-02-12 23:33:40 -050090 .name = "video",
Linus Torvalds1da177e2005-04-16 15:20:36 -070091 .class = ACPI_VIDEO_CLASS,
Thomas Renninger1ba90e32007-07-23 14:44:41 +020092 .ids = video_device_ids,
Linus Torvalds1da177e2005-04-16 15:20:36 -070093 .ops = {
94 .add = acpi_video_bus_add,
95 .remove = acpi_video_bus_remove,
Matthew Garrett863c1492008-02-04 23:31:24 -080096 .resume = acpi_video_resume,
Len Brown4be44fc2005-08-05 00:44:28 -040097 },
Linus Torvalds1da177e2005-04-16 15:20:36 -070098};
99
100struct acpi_video_bus_flags {
Len Brown4be44fc2005-08-05 00:44:28 -0400101 u8 multihead:1; /* can switch video heads */
102 u8 rom:1; /* can retrieve a video rom */
103 u8 post:1; /* can configure the head to */
104 u8 reserved:5;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105};
106
107struct acpi_video_bus_cap {
Len Brown4be44fc2005-08-05 00:44:28 -0400108 u8 _DOS:1; /*Enable/Disable output switching */
109 u8 _DOD:1; /*Enumerate all devices attached to display adapter */
110 u8 _ROM:1; /*Get ROM Data */
111 u8 _GPD:1; /*Get POST Device */
112 u8 _SPD:1; /*Set POST Device */
113 u8 _VPO:1; /*Video POST Options */
114 u8 reserved:2;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700115};
116
Len Brown4be44fc2005-08-05 00:44:28 -0400117struct acpi_video_device_attrib {
118 u32 display_index:4; /* A zero-based instance of the Display */
Julius Volz98fb8fe2007-02-20 16:38:40 +0100119 u32 display_port_attachment:4; /*This field differentiates the display type */
Len Brown4be44fc2005-08-05 00:44:28 -0400120 u32 display_type:4; /*Describe the specific type in use */
Julius Volz98fb8fe2007-02-20 16:38:40 +0100121 u32 vendor_specific:4; /*Chipset Vendor Specific */
Len Brown4be44fc2005-08-05 00:44:28 -0400122 u32 bios_can_detect:1; /*BIOS can detect the device */
123 u32 depend_on_vga:1; /*Non-VGA output device whose power is related to
124 the VGA device. */
125 u32 pipe_id:3; /*For VGA multiple-head devices. */
126 u32 reserved:10; /*Must be 0 */
127 u32 device_id_scheme:1; /*Device ID Scheme */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128};
129
130struct acpi_video_enumerated_device {
131 union {
132 u32 int_val;
Len Brown4be44fc2005-08-05 00:44:28 -0400133 struct acpi_video_device_attrib attrib;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134 } value;
135 struct acpi_video_device *bind_info;
136};
137
138struct acpi_video_bus {
Patrick Mochele6afa0d2006-05-19 16:54:40 -0400139 struct acpi_device *device;
Len Brown4be44fc2005-08-05 00:44:28 -0400140 u8 dos_setting;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141 struct acpi_video_enumerated_device *attached_array;
Len Brown4be44fc2005-08-05 00:44:28 -0400142 u8 attached_count;
143 struct acpi_video_bus_cap cap;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144 struct acpi_video_bus_flags flags;
Len Brown4be44fc2005-08-05 00:44:28 -0400145 struct list_head video_device_list;
Dmitry Torokhovbbac81f2007-11-05 11:43:32 -0500146 struct mutex device_list_lock; /* protects video_device_list */
Len Brown4be44fc2005-08-05 00:44:28 -0400147 struct proc_dir_entry *dir;
Luming Yue9dab192007-08-20 18:23:53 +0800148 struct input_dev *input;
149 char phys[32]; /* for input device */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700150};
151
152struct acpi_video_device_flags {
Len Brown4be44fc2005-08-05 00:44:28 -0400153 u8 crt:1;
154 u8 lcd:1;
155 u8 tvout:1;
Rui Zhang82cae992007-01-03 23:40:53 -0500156 u8 dvi:1;
Len Brown4be44fc2005-08-05 00:44:28 -0400157 u8 bios:1;
158 u8 unknown:1;
Rui Zhang82cae992007-01-03 23:40:53 -0500159 u8 reserved:2;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700160};
161
162struct acpi_video_device_cap {
Len Brown4be44fc2005-08-05 00:44:28 -0400163 u8 _ADR:1; /*Return the unique ID */
164 u8 _BCL:1; /*Query list of brightness control levels supported */
165 u8 _BCM:1; /*Set the brightness level */
Yu Luming2f3d0002006-11-11 02:40:34 +0800166 u8 _BQC:1; /* Get current brightness level */
Len Brown4be44fc2005-08-05 00:44:28 -0400167 u8 _DDC:1; /*Return the EDID for this device */
168 u8 _DCS:1; /*Return status of output device */
169 u8 _DGS:1; /*Query graphics state */
170 u8 _DSS:1; /*Device state set */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700171};
172
173struct acpi_video_device_brightness {
Len Brown4be44fc2005-08-05 00:44:28 -0400174 int curr;
175 int count;
176 int *levels;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700177};
178
179struct acpi_video_device {
Len Brown4be44fc2005-08-05 00:44:28 -0400180 unsigned long device_id;
181 struct acpi_video_device_flags flags;
182 struct acpi_video_device_cap cap;
183 struct list_head entry;
184 struct acpi_video_bus *video;
185 struct acpi_device *dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700186 struct acpi_video_device_brightness *brightness;
Yu Luming2f3d0002006-11-11 02:40:34 +0800187 struct backlight_device *backlight;
Zhang Rui702ed512008-01-17 15:51:22 +0800188 struct thermal_cooling_device *cdev;
Luming Yu23b0f012007-05-09 21:07:05 +0800189 struct output_device *output_dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700190};
191
Linus Torvalds1da177e2005-04-16 15:20:36 -0700192/* bus */
193static int acpi_video_bus_info_open_fs(struct inode *inode, struct file *file);
194static struct file_operations acpi_video_bus_info_fops = {
Len Brown4be44fc2005-08-05 00:44:28 -0400195 .open = acpi_video_bus_info_open_fs,
196 .read = seq_read,
197 .llseek = seq_lseek,
198 .release = single_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700199};
200
201static int acpi_video_bus_ROM_open_fs(struct inode *inode, struct file *file);
202static struct file_operations acpi_video_bus_ROM_fops = {
Len Brown4be44fc2005-08-05 00:44:28 -0400203 .open = acpi_video_bus_ROM_open_fs,
204 .read = seq_read,
205 .llseek = seq_lseek,
206 .release = single_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700207};
208
Len Brown4be44fc2005-08-05 00:44:28 -0400209static int acpi_video_bus_POST_info_open_fs(struct inode *inode,
210 struct file *file);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700211static struct file_operations acpi_video_bus_POST_info_fops = {
Len Brown4be44fc2005-08-05 00:44:28 -0400212 .open = acpi_video_bus_POST_info_open_fs,
213 .read = seq_read,
214 .llseek = seq_lseek,
215 .release = single_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700216};
217
218static int acpi_video_bus_POST_open_fs(struct inode *inode, struct file *file);
219static struct file_operations acpi_video_bus_POST_fops = {
Len Brown4be44fc2005-08-05 00:44:28 -0400220 .open = acpi_video_bus_POST_open_fs,
221 .read = seq_read,
222 .llseek = seq_lseek,
223 .release = single_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700224};
225
Linus Torvalds1da177e2005-04-16 15:20:36 -0700226static int acpi_video_bus_DOS_open_fs(struct inode *inode, struct file *file);
227static struct file_operations acpi_video_bus_DOS_fops = {
Len Brown4be44fc2005-08-05 00:44:28 -0400228 .open = acpi_video_bus_DOS_open_fs,
229 .read = seq_read,
230 .llseek = seq_lseek,
231 .release = single_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700232};
233
234/* device */
Len Brown4be44fc2005-08-05 00:44:28 -0400235static int acpi_video_device_info_open_fs(struct inode *inode,
236 struct file *file);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700237static struct file_operations acpi_video_device_info_fops = {
Len Brown4be44fc2005-08-05 00:44:28 -0400238 .open = acpi_video_device_info_open_fs,
239 .read = seq_read,
240 .llseek = seq_lseek,
241 .release = single_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700242};
243
Len Brown4be44fc2005-08-05 00:44:28 -0400244static int acpi_video_device_state_open_fs(struct inode *inode,
245 struct file *file);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700246static struct file_operations acpi_video_device_state_fops = {
Len Brown4be44fc2005-08-05 00:44:28 -0400247 .open = acpi_video_device_state_open_fs,
248 .read = seq_read,
249 .llseek = seq_lseek,
250 .release = single_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700251};
252
Len Brown4be44fc2005-08-05 00:44:28 -0400253static int acpi_video_device_brightness_open_fs(struct inode *inode,
254 struct file *file);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700255static struct file_operations acpi_video_device_brightness_fops = {
Len Brown4be44fc2005-08-05 00:44:28 -0400256 .open = acpi_video_device_brightness_open_fs,
257 .read = seq_read,
258 .llseek = seq_lseek,
259 .release = single_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700260};
261
Len Brown4be44fc2005-08-05 00:44:28 -0400262static int acpi_video_device_EDID_open_fs(struct inode *inode,
263 struct file *file);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700264static struct file_operations acpi_video_device_EDID_fops = {
Len Brown4be44fc2005-08-05 00:44:28 -0400265 .open = acpi_video_device_EDID_open_fs,
266 .read = seq_read,
267 .llseek = seq_lseek,
268 .release = single_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700269};
270
Len Brown4be44fc2005-08-05 00:44:28 -0400271static char device_decode[][30] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700272 "motherboard VGA device",
273 "PCI VGA device",
274 "AGP VGA device",
275 "UNKNOWN",
276};
277
Len Brown4be44fc2005-08-05 00:44:28 -0400278static void acpi_video_device_notify(acpi_handle handle, u32 event, void *data);
279static void acpi_video_device_rebind(struct acpi_video_bus *video);
280static void acpi_video_device_bind(struct acpi_video_bus *video,
281 struct acpi_video_device *device);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700282static int acpi_video_device_enumerate(struct acpi_video_bus *video);
Yu Luming2f3d0002006-11-11 02:40:34 +0800283static int acpi_video_device_lcd_set_level(struct acpi_video_device *device,
284 int level);
285static int acpi_video_device_lcd_get_level_current(
286 struct acpi_video_device *device,
287 unsigned long *level);
Len Brown4be44fc2005-08-05 00:44:28 -0400288static int acpi_video_get_next_level(struct acpi_video_device *device,
289 u32 level_current, u32 event);
290static void acpi_video_switch_brightness(struct acpi_video_device *device,
291 int event);
Luming Yu23b0f012007-05-09 21:07:05 +0800292static int acpi_video_device_get_state(struct acpi_video_device *device,
293 unsigned long *state);
294static int acpi_video_output_get(struct output_device *od);
295static int acpi_video_device_set_state(struct acpi_video_device *device, int state);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700296
Yu Luming2f3d0002006-11-11 02:40:34 +0800297/*backlight device sysfs support*/
298static int acpi_video_get_brightness(struct backlight_device *bd)
299{
300 unsigned long cur_level;
Matthew Garrett38531e62007-12-26 02:03:26 +0000301 int i;
Yu Luming2f3d0002006-11-11 02:40:34 +0800302 struct acpi_video_device *vd =
Richard Purdie655bfd72007-07-09 12:17:24 +0100303 (struct acpi_video_device *)bl_get_data(bd);
Yu Luming2f3d0002006-11-11 02:40:34 +0800304 acpi_video_device_lcd_get_level_current(vd, &cur_level);
Matthew Garrett38531e62007-12-26 02:03:26 +0000305 for (i = 2; i < vd->brightness->count; i++) {
306 if (vd->brightness->levels[i] == cur_level)
307 /* The first two entries are special - see page 575
308 of the ACPI spec 3.0 */
309 return i-2;
310 }
311 return 0;
Yu Luming2f3d0002006-11-11 02:40:34 +0800312}
313
314static int acpi_video_set_brightness(struct backlight_device *bd)
315{
Matthew Garrett38531e62007-12-26 02:03:26 +0000316 int request_level = bd->props.brightness+2;
Yu Luming2f3d0002006-11-11 02:40:34 +0800317 struct acpi_video_device *vd =
Richard Purdie655bfd72007-07-09 12:17:24 +0100318 (struct acpi_video_device *)bl_get_data(bd);
Matthew Garrett38531e62007-12-26 02:03:26 +0000319 acpi_video_device_lcd_set_level(vd,
320 vd->brightness->levels[request_level]);
Yu Luming2f3d0002006-11-11 02:40:34 +0800321 return 0;
322}
323
Richard Purdie599a52d2007-02-10 23:07:48 +0000324static struct backlight_ops acpi_backlight_ops = {
325 .get_brightness = acpi_video_get_brightness,
326 .update_status = acpi_video_set_brightness,
327};
328
Luming Yu23b0f012007-05-09 21:07:05 +0800329/*video output device sysfs support*/
330static int acpi_video_output_get(struct output_device *od)
331{
332 unsigned long state;
333 struct acpi_video_device *vd =
tonyj@suse.de60043422007-08-07 22:28:47 -0700334 (struct acpi_video_device *)dev_get_drvdata(&od->dev);
Luming Yu23b0f012007-05-09 21:07:05 +0800335 acpi_video_device_get_state(vd, &state);
336 return (int)state;
337}
338
339static int acpi_video_output_set(struct output_device *od)
340{
341 unsigned long state = od->request_state;
342 struct acpi_video_device *vd=
tonyj@suse.de60043422007-08-07 22:28:47 -0700343 (struct acpi_video_device *)dev_get_drvdata(&od->dev);
Luming Yu23b0f012007-05-09 21:07:05 +0800344 return acpi_video_device_set_state(vd, state);
345}
346
347static struct output_properties acpi_output_properties = {
348 .set_state = acpi_video_output_set,
349 .get_status = acpi_video_output_get,
350};
Zhang Rui702ed512008-01-17 15:51:22 +0800351
352
353/* thermal cooling device callbacks */
354static int video_get_max_state(struct thermal_cooling_device *cdev, char *buf)
355{
356 struct acpi_device *device = cdev->devdata;
357 struct acpi_video_device *video = acpi_driver_data(device);
358
359 return sprintf(buf, "%d\n", video->brightness->count - 3);
360}
361
362static int video_get_cur_state(struct thermal_cooling_device *cdev, char *buf)
363{
364 struct acpi_device *device = cdev->devdata;
365 struct acpi_video_device *video = acpi_driver_data(device);
366 unsigned long level;
367 int state;
368
369 acpi_video_device_lcd_get_level_current(video, &level);
370 for (state = 2; state < video->brightness->count; state++)
371 if (level == video->brightness->levels[state])
372 return sprintf(buf, "%d\n",
373 video->brightness->count - state - 1);
374
375 return -EINVAL;
376}
377
378static int
379video_set_cur_state(struct thermal_cooling_device *cdev, unsigned int state)
380{
381 struct acpi_device *device = cdev->devdata;
382 struct acpi_video_device *video = acpi_driver_data(device);
383 int level;
384
385 if ( state >= video->brightness->count - 2)
386 return -EINVAL;
387
388 state = video->brightness->count - state;
389 level = video->brightness->levels[state -1];
390 return acpi_video_device_lcd_set_level(video, level);
391}
392
393static struct thermal_cooling_device_ops video_cooling_ops = {
394 .get_max_state = video_get_max_state,
395 .get_cur_state = video_get_cur_state,
396 .set_cur_state = video_set_cur_state,
397};
398
Linus Torvalds1da177e2005-04-16 15:20:36 -0700399/* --------------------------------------------------------------------------
400 Video Management
401 -------------------------------------------------------------------------- */
402
403/* device */
404
405static int
Len Brown4be44fc2005-08-05 00:44:28 -0400406acpi_video_device_query(struct acpi_video_device *device, unsigned long *state)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700407{
Len Brown4be44fc2005-08-05 00:44:28 -0400408 int status;
Patrick Mochel90130262006-05-19 16:54:48 -0400409
410 status = acpi_evaluate_integer(device->dev->handle, "_DGS", NULL, state);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700411
Patrick Mocheld550d982006-06-27 00:41:40 -0400412 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700413}
414
415static int
Len Brown4be44fc2005-08-05 00:44:28 -0400416acpi_video_device_get_state(struct acpi_video_device *device,
417 unsigned long *state)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700418{
Len Brown4be44fc2005-08-05 00:44:28 -0400419 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700420
Patrick Mochel90130262006-05-19 16:54:48 -0400421 status = acpi_evaluate_integer(device->dev->handle, "_DCS", NULL, state);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700422
Patrick Mocheld550d982006-06-27 00:41:40 -0400423 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700424}
425
426static int
Len Brown4be44fc2005-08-05 00:44:28 -0400427acpi_video_device_set_state(struct acpi_video_device *device, int state)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700428{
Len Brown4be44fc2005-08-05 00:44:28 -0400429 int status;
430 union acpi_object arg0 = { ACPI_TYPE_INTEGER };
431 struct acpi_object_list args = { 1, &arg0 };
Luming Yu824b5582005-08-21 19:17:00 -0400432 unsigned long ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700433
Linus Torvalds1da177e2005-04-16 15:20:36 -0700434
435 arg0.integer.value = state;
Patrick Mochel90130262006-05-19 16:54:48 -0400436 status = acpi_evaluate_integer(device->dev->handle, "_DSS", &args, &ret);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700437
Patrick Mocheld550d982006-06-27 00:41:40 -0400438 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700439}
440
441static int
Len Brown4be44fc2005-08-05 00:44:28 -0400442acpi_video_device_lcd_query_levels(struct acpi_video_device *device,
443 union acpi_object **levels)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700444{
Len Brown4be44fc2005-08-05 00:44:28 -0400445 int status;
446 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
447 union acpi_object *obj;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700448
Linus Torvalds1da177e2005-04-16 15:20:36 -0700449
450 *levels = NULL;
451
Patrick Mochel90130262006-05-19 16:54:48 -0400452 status = acpi_evaluate_object(device->dev->handle, "_BCL", NULL, &buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700453 if (!ACPI_SUCCESS(status))
Patrick Mocheld550d982006-06-27 00:41:40 -0400454 return status;
Len Brown4be44fc2005-08-05 00:44:28 -0400455 obj = (union acpi_object *)buffer.pointer;
Adrian Bunk6665bda2006-03-11 10:12:00 -0500456 if (!obj || (obj->type != ACPI_TYPE_PACKAGE)) {
Len Brown64684632006-06-26 23:41:38 -0400457 printk(KERN_ERR PREFIX "Invalid _BCL data\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700458 status = -EFAULT;
459 goto err;
460 }
461
462 *levels = obj;
463
Patrick Mocheld550d982006-06-27 00:41:40 -0400464 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700465
Len Brown4be44fc2005-08-05 00:44:28 -0400466 err:
Jesper Juhl6044ec82005-11-07 01:01:32 -0800467 kfree(buffer.pointer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700468
Patrick Mocheld550d982006-06-27 00:41:40 -0400469 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700470}
471
472static int
Len Brown4be44fc2005-08-05 00:44:28 -0400473acpi_video_device_lcd_set_level(struct acpi_video_device *device, int level)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700474{
Alexey Starikovskiy4500ca82007-09-03 16:29:58 +0400475 int status = AE_OK;
Len Brown4be44fc2005-08-05 00:44:28 -0400476 union acpi_object arg0 = { ACPI_TYPE_INTEGER };
477 struct acpi_object_list args = { 1, &arg0 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700478
Linus Torvalds1da177e2005-04-16 15:20:36 -0700479
480 arg0.integer.value = level;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700481
Alexey Starikovskiy4500ca82007-09-03 16:29:58 +0400482 if (device->cap._BCM)
483 status = acpi_evaluate_object(device->dev->handle, "_BCM",
484 &args, NULL);
485 device->brightness->curr = level;
Patrick Mocheld550d982006-06-27 00:41:40 -0400486 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700487}
488
489static int
Len Brown4be44fc2005-08-05 00:44:28 -0400490acpi_video_device_lcd_get_level_current(struct acpi_video_device *device,
491 unsigned long *level)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700492{
Alexey Starikovskiy4500ca82007-09-03 16:29:58 +0400493 if (device->cap._BQC)
494 return acpi_evaluate_integer(device->dev->handle, "_BQC", NULL,
495 level);
496 *level = device->brightness->curr;
497 return AE_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700498}
499
500static int
Len Brown4be44fc2005-08-05 00:44:28 -0400501acpi_video_device_EDID(struct acpi_video_device *device,
502 union acpi_object **edid, ssize_t length)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700503{
Len Brown4be44fc2005-08-05 00:44:28 -0400504 int status;
505 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
506 union acpi_object *obj;
507 union acpi_object arg0 = { ACPI_TYPE_INTEGER };
508 struct acpi_object_list args = { 1, &arg0 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700509
Linus Torvalds1da177e2005-04-16 15:20:36 -0700510
511 *edid = NULL;
512
513 if (!device)
Patrick Mocheld550d982006-06-27 00:41:40 -0400514 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700515 if (length == 128)
516 arg0.integer.value = 1;
517 else if (length == 256)
518 arg0.integer.value = 2;
519 else
Patrick Mocheld550d982006-06-27 00:41:40 -0400520 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700521
Patrick Mochel90130262006-05-19 16:54:48 -0400522 status = acpi_evaluate_object(device->dev->handle, "_DDC", &args, &buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700523 if (ACPI_FAILURE(status))
Patrick Mocheld550d982006-06-27 00:41:40 -0400524 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700525
Jan Engelhardt50dd0962006-10-01 00:28:50 +0200526 obj = buffer.pointer;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700527
528 if (obj && obj->type == ACPI_TYPE_BUFFER)
529 *edid = obj;
530 else {
Len Brown64684632006-06-26 23:41:38 -0400531 printk(KERN_ERR PREFIX "Invalid _DDC data\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700532 status = -EFAULT;
533 kfree(obj);
534 }
535
Patrick Mocheld550d982006-06-27 00:41:40 -0400536 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700537}
538
Linus Torvalds1da177e2005-04-16 15:20:36 -0700539/* bus */
540
541static int
Len Brown4be44fc2005-08-05 00:44:28 -0400542acpi_video_bus_set_POST(struct acpi_video_bus *video, unsigned long option)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700543{
Len Brown4be44fc2005-08-05 00:44:28 -0400544 int status;
545 unsigned long tmp;
546 union acpi_object arg0 = { ACPI_TYPE_INTEGER };
547 struct acpi_object_list args = { 1, &arg0 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700548
Linus Torvalds1da177e2005-04-16 15:20:36 -0700549
550 arg0.integer.value = option;
551
Patrick Mochel90130262006-05-19 16:54:48 -0400552 status = acpi_evaluate_integer(video->device->handle, "_SPD", &args, &tmp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700553 if (ACPI_SUCCESS(status))
Len Brown4be44fc2005-08-05 00:44:28 -0400554 status = tmp ? (-EINVAL) : (AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700555
Patrick Mocheld550d982006-06-27 00:41:40 -0400556 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700557}
558
559static int
Len Brown4be44fc2005-08-05 00:44:28 -0400560acpi_video_bus_get_POST(struct acpi_video_bus *video, unsigned long *id)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700561{
562 int status;
563
Patrick Mochel90130262006-05-19 16:54:48 -0400564 status = acpi_evaluate_integer(video->device->handle, "_GPD", NULL, id);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700565
Patrick Mocheld550d982006-06-27 00:41:40 -0400566 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700567}
568
569static int
Len Brown4be44fc2005-08-05 00:44:28 -0400570acpi_video_bus_POST_options(struct acpi_video_bus *video,
571 unsigned long *options)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700572{
Len Brown4be44fc2005-08-05 00:44:28 -0400573 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700574
Patrick Mochel90130262006-05-19 16:54:48 -0400575 status = acpi_evaluate_integer(video->device->handle, "_VPO", NULL, options);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700576 *options &= 3;
577
Patrick Mocheld550d982006-06-27 00:41:40 -0400578 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700579}
580
581/*
582 * Arg:
583 * video : video bus device pointer
584 * bios_flag :
585 * 0. The system BIOS should NOT automatically switch(toggle)
586 * the active display output.
587 * 1. The system BIOS should automatically switch (toggle) the
Julius Volz98fb8fe2007-02-20 16:38:40 +0100588 * active display output. No switch event.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700589 * 2. The _DGS value should be locked.
590 * 3. The system BIOS should not automatically switch (toggle) the
591 * active display output, but instead generate the display switch
592 * event notify code.
593 * lcd_flag :
594 * 0. The system BIOS should automatically control the brightness level
Julius Volz98fb8fe2007-02-20 16:38:40 +0100595 * of the LCD when the power changes from AC to DC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700596 * 1. The system BIOS should NOT automatically control the brightness
Julius Volz98fb8fe2007-02-20 16:38:40 +0100597 * level of the LCD when the power changes from AC to DC.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700598 * Return Value:
599 * -1 wrong arg.
600 */
601
602static int
Len Brown4be44fc2005-08-05 00:44:28 -0400603acpi_video_bus_DOS(struct acpi_video_bus *video, int bios_flag, int lcd_flag)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700604{
Len Brown4be44fc2005-08-05 00:44:28 -0400605 acpi_integer status = 0;
606 union acpi_object arg0 = { ACPI_TYPE_INTEGER };
607 struct acpi_object_list args = { 1, &arg0 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700608
Linus Torvalds1da177e2005-04-16 15:20:36 -0700609
Len Brown4be44fc2005-08-05 00:44:28 -0400610 if (bios_flag < 0 || bios_flag > 3 || lcd_flag < 0 || lcd_flag > 1) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700611 status = -1;
612 goto Failed;
613 }
614 arg0.integer.value = (lcd_flag << 2) | bios_flag;
615 video->dos_setting = arg0.integer.value;
Patrick Mochel90130262006-05-19 16:54:48 -0400616 acpi_evaluate_object(video->device->handle, "_DOS", &args, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700617
Len Brown4be44fc2005-08-05 00:44:28 -0400618 Failed:
Patrick Mocheld550d982006-06-27 00:41:40 -0400619 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700620}
621
622/*
623 * Arg:
624 * device : video output device (LCD, CRT, ..)
625 *
626 * Return Value:
627 * None
628 *
Julius Volz98fb8fe2007-02-20 16:38:40 +0100629 * Find out all required AML methods defined under the output
Linus Torvalds1da177e2005-04-16 15:20:36 -0700630 * device.
631 */
632
Len Brown4be44fc2005-08-05 00:44:28 -0400633static void acpi_video_device_find_cap(struct acpi_video_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700634{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700635 acpi_handle h_dummy1;
636 int i;
Yu Luming2f3d0002006-11-11 02:40:34 +0800637 u32 max_level = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700638 union acpi_object *obj = NULL;
639 struct acpi_video_device_brightness *br = NULL;
640
Linus Torvalds1da177e2005-04-16 15:20:36 -0700641
William Lee Irwin III98934de2007-12-12 03:56:55 -0800642 memset(&device->cap, 0, sizeof(device->cap));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700643
Patrick Mochel90130262006-05-19 16:54:48 -0400644 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_ADR", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700645 device->cap._ADR = 1;
646 }
Patrick Mochel90130262006-05-19 16:54:48 -0400647 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_BCL", &h_dummy1))) {
Len Brown4be44fc2005-08-05 00:44:28 -0400648 device->cap._BCL = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700649 }
Patrick Mochel90130262006-05-19 16:54:48 -0400650 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_BCM", &h_dummy1))) {
Len Brown4be44fc2005-08-05 00:44:28 -0400651 device->cap._BCM = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700652 }
Yu Luming2f3d0002006-11-11 02:40:34 +0800653 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle,"_BQC",&h_dummy1)))
654 device->cap._BQC = 1;
Patrick Mochel90130262006-05-19 16:54:48 -0400655 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_DDC", &h_dummy1))) {
Len Brown4be44fc2005-08-05 00:44:28 -0400656 device->cap._DDC = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700657 }
Patrick Mochel90130262006-05-19 16:54:48 -0400658 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_DCS", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700659 device->cap._DCS = 1;
660 }
Patrick Mochel90130262006-05-19 16:54:48 -0400661 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_DGS", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700662 device->cap._DGS = 1;
663 }
Patrick Mochel90130262006-05-19 16:54:48 -0400664 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_DSS", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700665 device->cap._DSS = 1;
666 }
667
Danny Kukawkaf70ac0e2007-07-03 01:33:53 -0400668 if (ACPI_SUCCESS(acpi_video_device_lcd_query_levels(device, &obj))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700669
Danny Kukawkaf70ac0e2007-07-03 01:33:53 -0400670 if (obj->package.count >= 2) {
671 int count = 0;
672 union acpi_object *o;
Len Brown4be44fc2005-08-05 00:44:28 -0400673
Danny Kukawkaf70ac0e2007-07-03 01:33:53 -0400674 br = kzalloc(sizeof(*br), GFP_KERNEL);
675 if (!br) {
676 printk(KERN_ERR "can't allocate memory\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700677 } else {
Danny Kukawkaf70ac0e2007-07-03 01:33:53 -0400678 br->levels = kmalloc(obj->package.count *
679 sizeof *(br->levels), GFP_KERNEL);
680 if (!br->levels)
681 goto out;
682
683 for (i = 0; i < obj->package.count; i++) {
684 o = (union acpi_object *)&obj->package.
685 elements[i];
686 if (o->type != ACPI_TYPE_INTEGER) {
687 printk(KERN_ERR PREFIX "Invalid data\n");
688 continue;
689 }
690 br->levels[count] = (u32) o->integer.value;
691
692 if (br->levels[count] > max_level)
693 max_level = br->levels[count];
694 count++;
695 }
696 out:
697 if (count < 2) {
698 kfree(br->levels);
699 kfree(br);
700 } else {
701 br->count = count;
702 device->brightness = br;
703 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
704 "found %d brightness levels\n",
705 count));
706 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700707 }
708 }
Danny Kukawkaf70ac0e2007-07-03 01:33:53 -0400709
710 } else {
711 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Could not query available LCD brightness level\n"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700712 }
713
Paulo Marquesd1dd0c22005-03-30 22:39:49 -0500714 kfree(obj);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700715
Danny Kukawkaf70ac0e2007-07-03 01:33:53 -0400716 if (device->cap._BCL && device->cap._BCM && device->cap._BQC && max_level > 0){
Zhang Rui702ed512008-01-17 15:51:22 +0800717 int result;
Yu Luming2f3d0002006-11-11 02:40:34 +0800718 static int count = 0;
719 char *name;
Yu Luming2f3d0002006-11-11 02:40:34 +0800720 name = kzalloc(MAX_NAME_LEN, GFP_KERNEL);
721 if (!name)
722 return;
723
Yu Luming2f3d0002006-11-11 02:40:34 +0800724 sprintf(name, "acpi_video%d", count++);
Yu Luming2f3d0002006-11-11 02:40:34 +0800725 device->backlight = backlight_device_register(name,
Richard Purdie599a52d2007-02-10 23:07:48 +0000726 NULL, device, &acpi_backlight_ops);
Matthew Garrett38531e62007-12-26 02:03:26 +0000727 device->backlight->props.max_brightness = device->brightness->count-3;
728 device->backlight->props.brightness = acpi_video_get_brightness(device->backlight);
Richard Purdie599a52d2007-02-10 23:07:48 +0000729 backlight_update_status(device->backlight);
Yu Luming2f3d0002006-11-11 02:40:34 +0800730 kfree(name);
Zhang Rui702ed512008-01-17 15:51:22 +0800731
732 device->cdev = thermal_cooling_device_register("LCD",
733 device->dev, &video_cooling_ops);
Thomas Sujith43ff39f2008-02-15 18:29:18 -0500734 if (IS_ERR(device->cdev))
735 return;
736
Zhang Rui702ed512008-01-17 15:51:22 +0800737 if (device->cdev) {
738 printk(KERN_INFO PREFIX
739 "%s is registered as cooling_device%d\n",
740 device->dev->dev.bus_id, device->cdev->id);
741 result = sysfs_create_link(&device->dev->dev.kobj,
742 &device->cdev->device.kobj,
743 "thermal_cooling");
744 if (result)
745 printk(KERN_ERR PREFIX "Create sysfs link\n");
746 result = sysfs_create_link(&device->cdev->device.kobj,
747 &device->dev->dev.kobj,
748 "device");
749 if (result)
750 printk(KERN_ERR PREFIX "Create sysfs link\n");
751 }
Yu Luming2f3d0002006-11-11 02:40:34 +0800752 }
Luming Yu23b0f012007-05-09 21:07:05 +0800753 if (device->cap._DCS && device->cap._DSS){
754 static int count = 0;
755 char *name;
756 name = kzalloc(MAX_NAME_LEN, GFP_KERNEL);
757 if (!name)
758 return;
759 sprintf(name, "acpi_video%d", count++);
760 device->output_dev = video_output_register(name,
761 NULL, device, &acpi_output_properties);
762 kfree(name);
763 }
Patrick Mocheld550d982006-06-27 00:41:40 -0400764 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700765}
766
767/*
768 * Arg:
769 * device : video output device (VGA)
770 *
771 * Return Value:
772 * None
773 *
Julius Volz98fb8fe2007-02-20 16:38:40 +0100774 * Find out all required AML methods defined under the video bus device.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700775 */
776
Len Brown4be44fc2005-08-05 00:44:28 -0400777static void acpi_video_bus_find_cap(struct acpi_video_bus *video)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700778{
Len Brown4be44fc2005-08-05 00:44:28 -0400779 acpi_handle h_dummy1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700780
William Lee Irwin III98934de2007-12-12 03:56:55 -0800781 memset(&video->cap, 0, sizeof(video->cap));
Patrick Mochel90130262006-05-19 16:54:48 -0400782 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_DOS", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700783 video->cap._DOS = 1;
784 }
Patrick Mochel90130262006-05-19 16:54:48 -0400785 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_DOD", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700786 video->cap._DOD = 1;
787 }
Patrick Mochel90130262006-05-19 16:54:48 -0400788 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_ROM", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700789 video->cap._ROM = 1;
790 }
Patrick Mochel90130262006-05-19 16:54:48 -0400791 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_GPD", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700792 video->cap._GPD = 1;
793 }
Patrick Mochel90130262006-05-19 16:54:48 -0400794 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_SPD", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700795 video->cap._SPD = 1;
796 }
Patrick Mochel90130262006-05-19 16:54:48 -0400797 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_VPO", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700798 video->cap._VPO = 1;
799 }
800}
801
802/*
803 * Check whether the video bus device has required AML method to
804 * support the desired features
805 */
806
Len Brown4be44fc2005-08-05 00:44:28 -0400807static int acpi_video_bus_check(struct acpi_video_bus *video)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700808{
Len Brown4be44fc2005-08-05 00:44:28 -0400809 acpi_status status = -ENOENT;
Matthew Garrett3fa2cdc2008-02-07 01:44:06 +0000810 long device_id;
811 struct device *dev;
812 struct acpi_device *device;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700813
814 if (!video)
Patrick Mocheld550d982006-06-27 00:41:40 -0400815 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700816
Matthew Garrett3fa2cdc2008-02-07 01:44:06 +0000817 device = video->device;
818
819 status =
820 acpi_evaluate_integer(device->handle, "_ADR", NULL, &device_id);
821
822 if (!ACPI_SUCCESS(status))
823 return -ENODEV;
824
825 /* We need to attempt to determine whether the _ADR refers to a
826 PCI device or not. There's no terribly good way to do this,
827 so the best we can hope for is to assume that there'll never
828 be a video device in the host bridge */
829 if (device_id >= 0x10000) {
830 /* It looks like a PCI device. Does it exist? */
831 dev = acpi_get_physical_device(device->handle);
832 } else {
833 /* It doesn't look like a PCI device. Does its parent
834 exist? */
835 acpi_handle phandle;
836 if (acpi_get_parent(device->handle, &phandle))
837 return -ENODEV;
838 dev = acpi_get_physical_device(phandle);
839 }
840 if (!dev)
841 return -ENODEV;
842 put_device(dev);
843
Linus Torvalds1da177e2005-04-16 15:20:36 -0700844 /* Since there is no HID, CID and so on for VGA driver, we have
845 * to check well known required nodes.
846 */
847
Julius Volz98fb8fe2007-02-20 16:38:40 +0100848 /* Does this device support video switching? */
Len Brown4be44fc2005-08-05 00:44:28 -0400849 if (video->cap._DOS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700850 video->flags.multihead = 1;
851 status = 0;
852 }
853
Julius Volz98fb8fe2007-02-20 16:38:40 +0100854 /* Does this device support retrieving a video ROM? */
Len Brown4be44fc2005-08-05 00:44:28 -0400855 if (video->cap._ROM) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700856 video->flags.rom = 1;
857 status = 0;
858 }
859
Julius Volz98fb8fe2007-02-20 16:38:40 +0100860 /* Does this device support configuring which video device to POST? */
Len Brown4be44fc2005-08-05 00:44:28 -0400861 if (video->cap._GPD && video->cap._SPD && video->cap._VPO) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700862 video->flags.post = 1;
863 status = 0;
864 }
865
Patrick Mocheld550d982006-06-27 00:41:40 -0400866 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700867}
868
869/* --------------------------------------------------------------------------
870 FS Interface (/proc)
871 -------------------------------------------------------------------------- */
872
Len Brown4be44fc2005-08-05 00:44:28 -0400873static struct proc_dir_entry *acpi_video_dir;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700874
875/* video devices */
876
Len Brown4be44fc2005-08-05 00:44:28 -0400877static int acpi_video_device_info_seq_show(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700878{
Jan Engelhardt50dd0962006-10-01 00:28:50 +0200879 struct acpi_video_device *dev = seq->private;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700880
Linus Torvalds1da177e2005-04-16 15:20:36 -0700881
882 if (!dev)
883 goto end;
884
885 seq_printf(seq, "device_id: 0x%04x\n", (u32) dev->device_id);
886 seq_printf(seq, "type: ");
887 if (dev->flags.crt)
888 seq_printf(seq, "CRT\n");
889 else if (dev->flags.lcd)
890 seq_printf(seq, "LCD\n");
891 else if (dev->flags.tvout)
892 seq_printf(seq, "TVOUT\n");
Rui Zhang82cae992007-01-03 23:40:53 -0500893 else if (dev->flags.dvi)
894 seq_printf(seq, "DVI\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700895 else
896 seq_printf(seq, "UNKNOWN\n");
897
Len Brown4be44fc2005-08-05 00:44:28 -0400898 seq_printf(seq, "known by bios: %s\n", dev->flags.bios ? "yes" : "no");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700899
Len Brown4be44fc2005-08-05 00:44:28 -0400900 end:
Patrick Mocheld550d982006-06-27 00:41:40 -0400901 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700902}
903
904static int
Len Brown4be44fc2005-08-05 00:44:28 -0400905acpi_video_device_info_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700906{
907 return single_open(file, acpi_video_device_info_seq_show,
908 PDE(inode)->data);
909}
910
Len Brown4be44fc2005-08-05 00:44:28 -0400911static int acpi_video_device_state_seq_show(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700912{
Len Brown4be44fc2005-08-05 00:44:28 -0400913 int status;
Jan Engelhardt50dd0962006-10-01 00:28:50 +0200914 struct acpi_video_device *dev = seq->private;
Len Brown4be44fc2005-08-05 00:44:28 -0400915 unsigned long state;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700916
Linus Torvalds1da177e2005-04-16 15:20:36 -0700917
918 if (!dev)
919 goto end;
920
921 status = acpi_video_device_get_state(dev, &state);
922 seq_printf(seq, "state: ");
923 if (ACPI_SUCCESS(status))
924 seq_printf(seq, "0x%02lx\n", state);
925 else
926 seq_printf(seq, "<not supported>\n");
927
928 status = acpi_video_device_query(dev, &state);
929 seq_printf(seq, "query: ");
930 if (ACPI_SUCCESS(status))
931 seq_printf(seq, "0x%02lx\n", state);
932 else
933 seq_printf(seq, "<not supported>\n");
934
Len Brown4be44fc2005-08-05 00:44:28 -0400935 end:
Patrick Mocheld550d982006-06-27 00:41:40 -0400936 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700937}
938
939static int
Len Brown4be44fc2005-08-05 00:44:28 -0400940acpi_video_device_state_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700941{
942 return single_open(file, acpi_video_device_state_seq_show,
943 PDE(inode)->data);
944}
945
946static ssize_t
Len Brown4be44fc2005-08-05 00:44:28 -0400947acpi_video_device_write_state(struct file *file,
948 const char __user * buffer,
949 size_t count, loff_t * data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700950{
Len Brown4be44fc2005-08-05 00:44:28 -0400951 int status;
Jan Engelhardt50dd0962006-10-01 00:28:50 +0200952 struct seq_file *m = file->private_data;
953 struct acpi_video_device *dev = m->private;
Len Brown4be44fc2005-08-05 00:44:28 -0400954 char str[12] = { 0 };
955 u32 state = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700956
Linus Torvalds1da177e2005-04-16 15:20:36 -0700957
958 if (!dev || count + 1 > sizeof str)
Patrick Mocheld550d982006-06-27 00:41:40 -0400959 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700960
961 if (copy_from_user(str, buffer, count))
Patrick Mocheld550d982006-06-27 00:41:40 -0400962 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700963
964 str[count] = 0;
965 state = simple_strtoul(str, NULL, 0);
Len Brown4be44fc2005-08-05 00:44:28 -0400966 state &= ((1ul << 31) | (1ul << 30) | (1ul << 0));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700967
968 status = acpi_video_device_set_state(dev, state);
969
970 if (status)
Patrick Mocheld550d982006-06-27 00:41:40 -0400971 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700972
Patrick Mocheld550d982006-06-27 00:41:40 -0400973 return count;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700974}
975
976static int
Len Brown4be44fc2005-08-05 00:44:28 -0400977acpi_video_device_brightness_seq_show(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700978{
Jan Engelhardt50dd0962006-10-01 00:28:50 +0200979 struct acpi_video_device *dev = seq->private;
Len Brown4be44fc2005-08-05 00:44:28 -0400980 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700981
Linus Torvalds1da177e2005-04-16 15:20:36 -0700982
983 if (!dev || !dev->brightness) {
984 seq_printf(seq, "<not supported>\n");
Patrick Mocheld550d982006-06-27 00:41:40 -0400985 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700986 }
987
988 seq_printf(seq, "levels: ");
989 for (i = 0; i < dev->brightness->count; i++)
990 seq_printf(seq, " %d", dev->brightness->levels[i]);
991 seq_printf(seq, "\ncurrent: %d\n", dev->brightness->curr);
992
Patrick Mocheld550d982006-06-27 00:41:40 -0400993 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700994}
995
996static int
Len Brown4be44fc2005-08-05 00:44:28 -0400997acpi_video_device_brightness_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700998{
999 return single_open(file, acpi_video_device_brightness_seq_show,
1000 PDE(inode)->data);
1001}
1002
1003static ssize_t
Len Brown4be44fc2005-08-05 00:44:28 -04001004acpi_video_device_write_brightness(struct file *file,
1005 const char __user * buffer,
1006 size_t count, loff_t * data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001007{
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001008 struct seq_file *m = file->private_data;
1009 struct acpi_video_device *dev = m->private;
Danny Baumannc88c5782007-11-02 13:47:53 +01001010 char str[5] = { 0 };
Len Brown4be44fc2005-08-05 00:44:28 -04001011 unsigned int level = 0;
1012 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001013
Linus Torvalds1da177e2005-04-16 15:20:36 -07001014
Thomas Renninger59d399d2005-11-08 05:27:00 -05001015 if (!dev || !dev->brightness || count + 1 > sizeof str)
Patrick Mocheld550d982006-06-27 00:41:40 -04001016 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001017
1018 if (copy_from_user(str, buffer, count))
Patrick Mocheld550d982006-06-27 00:41:40 -04001019 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001020
1021 str[count] = 0;
1022 level = simple_strtoul(str, NULL, 0);
Len Brown4be44fc2005-08-05 00:44:28 -04001023
Linus Torvalds1da177e2005-04-16 15:20:36 -07001024 if (level > 100)
Patrick Mocheld550d982006-06-27 00:41:40 -04001025 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001026
Julius Volz98fb8fe2007-02-20 16:38:40 +01001027 /* validate through the list of available levels */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001028 for (i = 0; i < dev->brightness->count; i++)
1029 if (level == dev->brightness->levels[i]) {
Len Brown4be44fc2005-08-05 00:44:28 -04001030 if (ACPI_SUCCESS
1031 (acpi_video_device_lcd_set_level(dev, level)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001032 dev->brightness->curr = level;
1033 break;
1034 }
1035
Patrick Mocheld550d982006-06-27 00:41:40 -04001036 return count;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001037}
1038
Len Brown4be44fc2005-08-05 00:44:28 -04001039static int acpi_video_device_EDID_seq_show(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001040{
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001041 struct acpi_video_device *dev = seq->private;
Len Brown4be44fc2005-08-05 00:44:28 -04001042 int status;
1043 int i;
1044 union acpi_object *edid = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001045
Linus Torvalds1da177e2005-04-16 15:20:36 -07001046
1047 if (!dev)
1048 goto out;
1049
Len Brown4be44fc2005-08-05 00:44:28 -04001050 status = acpi_video_device_EDID(dev, &edid, 128);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001051 if (ACPI_FAILURE(status)) {
Len Brown4be44fc2005-08-05 00:44:28 -04001052 status = acpi_video_device_EDID(dev, &edid, 256);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001053 }
1054
1055 if (ACPI_FAILURE(status)) {
1056 goto out;
1057 }
1058
1059 if (edid && edid->type == ACPI_TYPE_BUFFER) {
1060 for (i = 0; i < edid->buffer.length; i++)
1061 seq_putc(seq, edid->buffer.pointer[i]);
1062 }
1063
Len Brown4be44fc2005-08-05 00:44:28 -04001064 out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001065 if (!edid)
1066 seq_printf(seq, "<not supported>\n");
1067 else
1068 kfree(edid);
1069
Patrick Mocheld550d982006-06-27 00:41:40 -04001070 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001071}
1072
1073static int
Len Brown4be44fc2005-08-05 00:44:28 -04001074acpi_video_device_EDID_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001075{
1076 return single_open(file, acpi_video_device_EDID_seq_show,
1077 PDE(inode)->data);
1078}
1079
Len Brown4be44fc2005-08-05 00:44:28 -04001080static int acpi_video_device_add_fs(struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001081{
Len Brown4be44fc2005-08-05 00:44:28 -04001082 struct proc_dir_entry *entry = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001083 struct acpi_video_device *vid_dev;
1084
Linus Torvalds1da177e2005-04-16 15:20:36 -07001085
1086 if (!device)
Patrick Mocheld550d982006-06-27 00:41:40 -04001087 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001088
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001089 vid_dev = acpi_driver_data(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001090 if (!vid_dev)
Patrick Mocheld550d982006-06-27 00:41:40 -04001091 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001092
1093 if (!acpi_device_dir(device)) {
1094 acpi_device_dir(device) = proc_mkdir(acpi_device_bid(device),
Len Brown4be44fc2005-08-05 00:44:28 -04001095 vid_dev->video->dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001096 if (!acpi_device_dir(device))
Patrick Mocheld550d982006-06-27 00:41:40 -04001097 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001098 acpi_device_dir(device)->owner = THIS_MODULE;
1099 }
1100
1101 /* 'info' [R] */
1102 entry = create_proc_entry("info", S_IRUGO, acpi_device_dir(device));
1103 if (!entry)
Patrick Mocheld550d982006-06-27 00:41:40 -04001104 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001105 else {
1106 entry->proc_fops = &acpi_video_device_info_fops;
1107 entry->data = acpi_driver_data(device);
1108 entry->owner = THIS_MODULE;
1109 }
1110
1111 /* 'state' [R/W] */
Len Brown4be44fc2005-08-05 00:44:28 -04001112 entry =
1113 create_proc_entry("state", S_IFREG | S_IRUGO | S_IWUSR,
1114 acpi_device_dir(device));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001115 if (!entry)
Patrick Mocheld550d982006-06-27 00:41:40 -04001116 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001117 else {
Arjan van de Vend479e902006-01-06 16:47:00 -05001118 acpi_video_device_state_fops.write = acpi_video_device_write_state;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001119 entry->proc_fops = &acpi_video_device_state_fops;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001120 entry->data = acpi_driver_data(device);
1121 entry->owner = THIS_MODULE;
1122 }
1123
1124 /* 'brightness' [R/W] */
Len Brown4be44fc2005-08-05 00:44:28 -04001125 entry =
1126 create_proc_entry("brightness", S_IFREG | S_IRUGO | S_IWUSR,
1127 acpi_device_dir(device));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001128 if (!entry)
Patrick Mocheld550d982006-06-27 00:41:40 -04001129 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001130 else {
Arjan van de Vend479e902006-01-06 16:47:00 -05001131 acpi_video_device_brightness_fops.write = acpi_video_device_write_brightness;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001132 entry->proc_fops = &acpi_video_device_brightness_fops;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001133 entry->data = acpi_driver_data(device);
1134 entry->owner = THIS_MODULE;
1135 }
1136
1137 /* 'EDID' [R] */
1138 entry = create_proc_entry("EDID", S_IRUGO, acpi_device_dir(device));
1139 if (!entry)
Patrick Mocheld550d982006-06-27 00:41:40 -04001140 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001141 else {
1142 entry->proc_fops = &acpi_video_device_EDID_fops;
1143 entry->data = acpi_driver_data(device);
1144 entry->owner = THIS_MODULE;
1145 }
1146
Patrick Mocheld550d982006-06-27 00:41:40 -04001147 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001148}
1149
Len Brown4be44fc2005-08-05 00:44:28 -04001150static int acpi_video_device_remove_fs(struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001151{
1152 struct acpi_video_device *vid_dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001153
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001154 vid_dev = acpi_driver_data(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001155 if (!vid_dev || !vid_dev->video || !vid_dev->video->dir)
Patrick Mocheld550d982006-06-27 00:41:40 -04001156 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001157
1158 if (acpi_device_dir(device)) {
1159 remove_proc_entry("info", acpi_device_dir(device));
1160 remove_proc_entry("state", acpi_device_dir(device));
1161 remove_proc_entry("brightness", acpi_device_dir(device));
1162 remove_proc_entry("EDID", acpi_device_dir(device));
Len Brown4be44fc2005-08-05 00:44:28 -04001163 remove_proc_entry(acpi_device_bid(device), vid_dev->video->dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001164 acpi_device_dir(device) = NULL;
1165 }
1166
Patrick Mocheld550d982006-06-27 00:41:40 -04001167 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001168}
1169
Linus Torvalds1da177e2005-04-16 15:20:36 -07001170/* video bus */
Len Brown4be44fc2005-08-05 00:44:28 -04001171static int acpi_video_bus_info_seq_show(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001172{
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001173 struct acpi_video_bus *video = seq->private;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001174
Linus Torvalds1da177e2005-04-16 15:20:36 -07001175
1176 if (!video)
1177 goto end;
1178
1179 seq_printf(seq, "Switching heads: %s\n",
Len Brown4be44fc2005-08-05 00:44:28 -04001180 video->flags.multihead ? "yes" : "no");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001181 seq_printf(seq, "Video ROM: %s\n",
Len Brown4be44fc2005-08-05 00:44:28 -04001182 video->flags.rom ? "yes" : "no");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001183 seq_printf(seq, "Device to be POSTed on boot: %s\n",
Len Brown4be44fc2005-08-05 00:44:28 -04001184 video->flags.post ? "yes" : "no");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001185
Len Brown4be44fc2005-08-05 00:44:28 -04001186 end:
Patrick Mocheld550d982006-06-27 00:41:40 -04001187 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001188}
1189
Len Brown4be44fc2005-08-05 00:44:28 -04001190static int acpi_video_bus_info_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001191{
Len Brown4be44fc2005-08-05 00:44:28 -04001192 return single_open(file, acpi_video_bus_info_seq_show,
1193 PDE(inode)->data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001194}
1195
Len Brown4be44fc2005-08-05 00:44:28 -04001196static int acpi_video_bus_ROM_seq_show(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001197{
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001198 struct acpi_video_bus *video = seq->private;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001199
Linus Torvalds1da177e2005-04-16 15:20:36 -07001200
1201 if (!video)
1202 goto end;
1203
Harvey Harrison96b2dd12008-03-05 18:24:51 -08001204 printk(KERN_INFO PREFIX "Please implement %s\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001205 seq_printf(seq, "<TODO>\n");
1206
Len Brown4be44fc2005-08-05 00:44:28 -04001207 end:
Patrick Mocheld550d982006-06-27 00:41:40 -04001208 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001209}
1210
Len Brown4be44fc2005-08-05 00:44:28 -04001211static int acpi_video_bus_ROM_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001212{
1213 return single_open(file, acpi_video_bus_ROM_seq_show, PDE(inode)->data);
1214}
1215
Len Brown4be44fc2005-08-05 00:44:28 -04001216static int acpi_video_bus_POST_info_seq_show(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001217{
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001218 struct acpi_video_bus *video = seq->private;
Len Brown4be44fc2005-08-05 00:44:28 -04001219 unsigned long options;
1220 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001221
Linus Torvalds1da177e2005-04-16 15:20:36 -07001222
1223 if (!video)
1224 goto end;
1225
1226 status = acpi_video_bus_POST_options(video, &options);
1227 if (ACPI_SUCCESS(status)) {
1228 if (!(options & 1)) {
Len Brown4be44fc2005-08-05 00:44:28 -04001229 printk(KERN_WARNING PREFIX
1230 "The motherboard VGA device is not listed as a possible POST device.\n");
1231 printk(KERN_WARNING PREFIX
Julius Volz98fb8fe2007-02-20 16:38:40 +01001232 "This indicates a BIOS bug. Please contact the manufacturer.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001233 }
1234 printk("%lx\n", options);
Julius Volz98fb8fe2007-02-20 16:38:40 +01001235 seq_printf(seq, "can POST: <integrated video>");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001236 if (options & 2)
1237 seq_printf(seq, " <PCI video>");
1238 if (options & 4)
1239 seq_printf(seq, " <AGP video>");
1240 seq_putc(seq, '\n');
1241 } else
1242 seq_printf(seq, "<not supported>\n");
Len Brown4be44fc2005-08-05 00:44:28 -04001243 end:
Patrick Mocheld550d982006-06-27 00:41:40 -04001244 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001245}
1246
1247static int
Len Brown4be44fc2005-08-05 00:44:28 -04001248acpi_video_bus_POST_info_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001249{
Len Brown4be44fc2005-08-05 00:44:28 -04001250 return single_open(file, acpi_video_bus_POST_info_seq_show,
1251 PDE(inode)->data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001252}
1253
Len Brown4be44fc2005-08-05 00:44:28 -04001254static int acpi_video_bus_POST_seq_show(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001255{
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001256 struct acpi_video_bus *video = seq->private;
Len Brown4be44fc2005-08-05 00:44:28 -04001257 int status;
1258 unsigned long id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001259
Linus Torvalds1da177e2005-04-16 15:20:36 -07001260
1261 if (!video)
1262 goto end;
1263
Len Brown4be44fc2005-08-05 00:44:28 -04001264 status = acpi_video_bus_get_POST(video, &id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001265 if (!ACPI_SUCCESS(status)) {
1266 seq_printf(seq, "<not supported>\n");
1267 goto end;
1268 }
Julius Volz98fb8fe2007-02-20 16:38:40 +01001269 seq_printf(seq, "device POSTed is <%s>\n", device_decode[id & 3]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001270
Len Brown4be44fc2005-08-05 00:44:28 -04001271 end:
Patrick Mocheld550d982006-06-27 00:41:40 -04001272 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001273}
1274
Len Brown4be44fc2005-08-05 00:44:28 -04001275static int acpi_video_bus_DOS_seq_show(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001276{
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001277 struct acpi_video_bus *video = seq->private;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001278
Linus Torvalds1da177e2005-04-16 15:20:36 -07001279
Len Brown4be44fc2005-08-05 00:44:28 -04001280 seq_printf(seq, "DOS setting: <%d>\n", video->dos_setting);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001281
Patrick Mocheld550d982006-06-27 00:41:40 -04001282 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001283}
1284
Len Brown4be44fc2005-08-05 00:44:28 -04001285static int acpi_video_bus_POST_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001286{
Len Brown4be44fc2005-08-05 00:44:28 -04001287 return single_open(file, acpi_video_bus_POST_seq_show,
1288 PDE(inode)->data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001289}
1290
Len Brown4be44fc2005-08-05 00:44:28 -04001291static int acpi_video_bus_DOS_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001292{
1293 return single_open(file, acpi_video_bus_DOS_seq_show, PDE(inode)->data);
1294}
1295
1296static ssize_t
Len Brown4be44fc2005-08-05 00:44:28 -04001297acpi_video_bus_write_POST(struct file *file,
1298 const char __user * buffer,
1299 size_t count, loff_t * data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001300{
Len Brown4be44fc2005-08-05 00:44:28 -04001301 int status;
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001302 struct seq_file *m = file->private_data;
1303 struct acpi_video_bus *video = m->private;
Len Brown4be44fc2005-08-05 00:44:28 -04001304 char str[12] = { 0 };
1305 unsigned long opt, options;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001306
Linus Torvalds1da177e2005-04-16 15:20:36 -07001307
Linus Torvalds1da177e2005-04-16 15:20:36 -07001308 if (!video || count + 1 > sizeof str)
Patrick Mocheld550d982006-06-27 00:41:40 -04001309 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001310
1311 status = acpi_video_bus_POST_options(video, &options);
1312 if (!ACPI_SUCCESS(status))
Patrick Mocheld550d982006-06-27 00:41:40 -04001313 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001314
1315 if (copy_from_user(str, buffer, count))
Patrick Mocheld550d982006-06-27 00:41:40 -04001316 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001317
1318 str[count] = 0;
1319 opt = strtoul(str, NULL, 0);
1320 if (opt > 3)
Patrick Mocheld550d982006-06-27 00:41:40 -04001321 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001322
Julius Volz98fb8fe2007-02-20 16:38:40 +01001323 /* just in case an OEM 'forgot' the motherboard... */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001324 options |= 1;
1325
1326 if (options & (1ul << opt)) {
Len Brown4be44fc2005-08-05 00:44:28 -04001327 status = acpi_video_bus_set_POST(video, opt);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001328 if (!ACPI_SUCCESS(status))
Patrick Mocheld550d982006-06-27 00:41:40 -04001329 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001330
1331 }
1332
Patrick Mocheld550d982006-06-27 00:41:40 -04001333 return count;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001334}
1335
1336static ssize_t
Len Brown4be44fc2005-08-05 00:44:28 -04001337acpi_video_bus_write_DOS(struct file *file,
1338 const char __user * buffer,
1339 size_t count, loff_t * data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001340{
Len Brown4be44fc2005-08-05 00:44:28 -04001341 int status;
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001342 struct seq_file *m = file->private_data;
1343 struct acpi_video_bus *video = m->private;
Len Brown4be44fc2005-08-05 00:44:28 -04001344 char str[12] = { 0 };
1345 unsigned long opt;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001346
Linus Torvalds1da177e2005-04-16 15:20:36 -07001347
Linus Torvalds1da177e2005-04-16 15:20:36 -07001348 if (!video || count + 1 > sizeof str)
Patrick Mocheld550d982006-06-27 00:41:40 -04001349 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001350
1351 if (copy_from_user(str, buffer, count))
Patrick Mocheld550d982006-06-27 00:41:40 -04001352 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001353
1354 str[count] = 0;
1355 opt = strtoul(str, NULL, 0);
1356 if (opt > 7)
Patrick Mocheld550d982006-06-27 00:41:40 -04001357 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001358
Len Brown4be44fc2005-08-05 00:44:28 -04001359 status = acpi_video_bus_DOS(video, opt & 0x3, (opt & 0x4) >> 2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001360
1361 if (!ACPI_SUCCESS(status))
Patrick Mocheld550d982006-06-27 00:41:40 -04001362 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001363
Patrick Mocheld550d982006-06-27 00:41:40 -04001364 return count;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001365}
1366
Len Brown4be44fc2005-08-05 00:44:28 -04001367static int acpi_video_bus_add_fs(struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001368{
Matthew Garrett01195092008-01-17 03:39:36 +00001369 long device_id;
1370 int status;
Len Brown4be44fc2005-08-05 00:44:28 -04001371 struct proc_dir_entry *entry = NULL;
1372 struct acpi_video_bus *video;
Matthew Garrett01195092008-01-17 03:39:36 +00001373 struct device *dev;
1374
1375 status =
1376 acpi_evaluate_integer(device->handle, "_ADR", NULL, &device_id);
1377
1378 if (!ACPI_SUCCESS(status))
1379 return -ENODEV;
1380
1381 /* We need to attempt to determine whether the _ADR refers to a
1382 PCI device or not. There's no terribly good way to do this,
1383 so the best we can hope for is to assume that there'll never
1384 be a video device in the host bridge */
1385 if (device_id >= 0x10000) {
1386 /* It looks like a PCI device. Does it exist? */
1387 dev = acpi_get_physical_device(device->handle);
1388 } else {
1389 /* It doesn't look like a PCI device. Does its parent
1390 exist? */
1391 acpi_handle phandle;
1392 if (acpi_get_parent(device->handle, &phandle))
1393 return -ENODEV;
1394 dev = acpi_get_physical_device(phandle);
1395 }
1396 if (!dev)
1397 return -ENODEV;
1398 put_device(dev);
1399
Linus Torvalds1da177e2005-04-16 15:20:36 -07001400
Linus Torvalds1da177e2005-04-16 15:20:36 -07001401
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001402 video = acpi_driver_data(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001403
1404 if (!acpi_device_dir(device)) {
1405 acpi_device_dir(device) = proc_mkdir(acpi_device_bid(device),
Len Brown4be44fc2005-08-05 00:44:28 -04001406 acpi_video_dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001407 if (!acpi_device_dir(device))
Patrick Mocheld550d982006-06-27 00:41:40 -04001408 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001409 video->dir = acpi_device_dir(device);
1410 acpi_device_dir(device)->owner = THIS_MODULE;
1411 }
1412
1413 /* 'info' [R] */
1414 entry = create_proc_entry("info", S_IRUGO, acpi_device_dir(device));
1415 if (!entry)
Patrick Mocheld550d982006-06-27 00:41:40 -04001416 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001417 else {
1418 entry->proc_fops = &acpi_video_bus_info_fops;
1419 entry->data = acpi_driver_data(device);
1420 entry->owner = THIS_MODULE;
1421 }
1422
1423 /* 'ROM' [R] */
1424 entry = create_proc_entry("ROM", S_IRUGO, acpi_device_dir(device));
1425 if (!entry)
Patrick Mocheld550d982006-06-27 00:41:40 -04001426 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001427 else {
1428 entry->proc_fops = &acpi_video_bus_ROM_fops;
1429 entry->data = acpi_driver_data(device);
1430 entry->owner = THIS_MODULE;
1431 }
1432
1433 /* 'POST_info' [R] */
Len Brown4be44fc2005-08-05 00:44:28 -04001434 entry =
1435 create_proc_entry("POST_info", S_IRUGO, acpi_device_dir(device));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001436 if (!entry)
Patrick Mocheld550d982006-06-27 00:41:40 -04001437 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001438 else {
1439 entry->proc_fops = &acpi_video_bus_POST_info_fops;
1440 entry->data = acpi_driver_data(device);
1441 entry->owner = THIS_MODULE;
1442 }
1443
1444 /* 'POST' [R/W] */
Len Brown4be44fc2005-08-05 00:44:28 -04001445 entry =
1446 create_proc_entry("POST", S_IFREG | S_IRUGO | S_IRUSR,
1447 acpi_device_dir(device));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001448 if (!entry)
Patrick Mocheld550d982006-06-27 00:41:40 -04001449 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001450 else {
Arjan van de Vend479e902006-01-06 16:47:00 -05001451 acpi_video_bus_POST_fops.write = acpi_video_bus_write_POST;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001452 entry->proc_fops = &acpi_video_bus_POST_fops;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001453 entry->data = acpi_driver_data(device);
1454 entry->owner = THIS_MODULE;
1455 }
1456
1457 /* 'DOS' [R/W] */
Len Brown4be44fc2005-08-05 00:44:28 -04001458 entry =
1459 create_proc_entry("DOS", S_IFREG | S_IRUGO | S_IRUSR,
1460 acpi_device_dir(device));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001461 if (!entry)
Patrick Mocheld550d982006-06-27 00:41:40 -04001462 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001463 else {
Arjan van de Vend479e902006-01-06 16:47:00 -05001464 acpi_video_bus_DOS_fops.write = acpi_video_bus_write_DOS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001465 entry->proc_fops = &acpi_video_bus_DOS_fops;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001466 entry->data = acpi_driver_data(device);
1467 entry->owner = THIS_MODULE;
1468 }
1469
Patrick Mocheld550d982006-06-27 00:41:40 -04001470 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001471}
1472
Len Brown4be44fc2005-08-05 00:44:28 -04001473static int acpi_video_bus_remove_fs(struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001474{
Len Brown4be44fc2005-08-05 00:44:28 -04001475 struct acpi_video_bus *video;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001476
Linus Torvalds1da177e2005-04-16 15:20:36 -07001477
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001478 video = acpi_driver_data(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001479
1480 if (acpi_device_dir(device)) {
1481 remove_proc_entry("info", acpi_device_dir(device));
1482 remove_proc_entry("ROM", acpi_device_dir(device));
1483 remove_proc_entry("POST_info", acpi_device_dir(device));
1484 remove_proc_entry("POST", acpi_device_dir(device));
1485 remove_proc_entry("DOS", acpi_device_dir(device));
Len Brown4be44fc2005-08-05 00:44:28 -04001486 remove_proc_entry(acpi_device_bid(device), acpi_video_dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001487 acpi_device_dir(device) = NULL;
1488 }
1489
Patrick Mocheld550d982006-06-27 00:41:40 -04001490 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001491}
1492
1493/* --------------------------------------------------------------------------
1494 Driver Interface
1495 -------------------------------------------------------------------------- */
1496
1497/* device interface */
Rui Zhang82cae992007-01-03 23:40:53 -05001498static struct acpi_video_device_attrib*
1499acpi_video_get_device_attr(struct acpi_video_bus *video, unsigned long device_id)
1500{
1501 int count;
1502
1503 for(count = 0; count < video->attached_count; count++)
1504 if((video->attached_array[count].value.int_val & 0xffff) == device_id)
1505 return &(video->attached_array[count].value.attrib);
1506 return NULL;
1507}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001508
1509static int
Len Brown4be44fc2005-08-05 00:44:28 -04001510acpi_video_bus_get_one_device(struct acpi_device *device,
1511 struct acpi_video_bus *video)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001512{
Len Brown4be44fc2005-08-05 00:44:28 -04001513 unsigned long device_id;
Yu, Luming973bf492006-04-27 05:25:00 -04001514 int status;
Len Brown4be44fc2005-08-05 00:44:28 -04001515 struct acpi_video_device *data;
Rui Zhang82cae992007-01-03 23:40:53 -05001516 struct acpi_video_device_attrib* attribute;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001517
1518 if (!device || !video)
Patrick Mocheld550d982006-06-27 00:41:40 -04001519 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001520
Len Brown4be44fc2005-08-05 00:44:28 -04001521 status =
1522 acpi_evaluate_integer(device->handle, "_ADR", NULL, &device_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001523 if (ACPI_SUCCESS(status)) {
1524
Burman Yan36bcbec2006-12-19 12:56:11 -08001525 data = kzalloc(sizeof(struct acpi_video_device), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001526 if (!data)
Patrick Mocheld550d982006-06-27 00:41:40 -04001527 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001528
Linus Torvalds1da177e2005-04-16 15:20:36 -07001529 strcpy(acpi_device_name(device), ACPI_VIDEO_DEVICE_NAME);
1530 strcpy(acpi_device_class(device), ACPI_VIDEO_CLASS);
1531 acpi_driver_data(device) = data;
1532
1533 data->device_id = device_id;
1534 data->video = video;
1535 data->dev = device;
1536
Rui Zhang82cae992007-01-03 23:40:53 -05001537 attribute = acpi_video_get_device_attr(video, device_id);
1538
1539 if((attribute != NULL) && attribute->device_id_scheme) {
1540 switch (attribute->display_type) {
1541 case ACPI_VIDEO_DISPLAY_CRT:
1542 data->flags.crt = 1;
1543 break;
1544 case ACPI_VIDEO_DISPLAY_TV:
1545 data->flags.tvout = 1;
1546 break;
1547 case ACPI_VIDEO_DISPLAY_DVI:
1548 data->flags.dvi = 1;
1549 break;
1550 case ACPI_VIDEO_DISPLAY_LCD:
1551 data->flags.lcd = 1;
1552 break;
1553 default:
1554 data->flags.unknown = 1;
1555 break;
1556 }
1557 if(attribute->bios_can_detect)
1558 data->flags.bios = 1;
1559 } else
Linus Torvalds1da177e2005-04-16 15:20:36 -07001560 data->flags.unknown = 1;
Len Brown4be44fc2005-08-05 00:44:28 -04001561
Linus Torvalds1da177e2005-04-16 15:20:36 -07001562 acpi_video_device_bind(video, data);
1563 acpi_video_device_find_cap(data);
1564
Patrick Mochel90130262006-05-19 16:54:48 -04001565 status = acpi_install_notify_handler(device->handle,
Len Brown4be44fc2005-08-05 00:44:28 -04001566 ACPI_DEVICE_NOTIFY,
1567 acpi_video_device_notify,
1568 data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001569 if (ACPI_FAILURE(status)) {
1570 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
Len Brown4be44fc2005-08-05 00:44:28 -04001571 "Error installing notify handler\n"));
Yu, Luming973bf492006-04-27 05:25:00 -04001572 if(data->brightness)
1573 kfree(data->brightness->levels);
1574 kfree(data->brightness);
1575 kfree(data);
1576 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001577 }
1578
Dmitry Torokhovbbac81f2007-11-05 11:43:32 -05001579 mutex_lock(&video->device_list_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001580 list_add_tail(&data->entry, &video->video_device_list);
Dmitry Torokhovbbac81f2007-11-05 11:43:32 -05001581 mutex_unlock(&video->device_list_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001582
1583 acpi_video_device_add_fs(device);
1584
Patrick Mocheld550d982006-06-27 00:41:40 -04001585 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001586 }
1587
Patrick Mocheld550d982006-06-27 00:41:40 -04001588 return -ENOENT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001589}
1590
1591/*
1592 * Arg:
1593 * video : video bus device
1594 *
1595 * Return:
1596 * none
1597 *
1598 * Enumerate the video device list of the video bus,
1599 * bind the ids with the corresponding video devices
1600 * under the video bus.
Len Brown4be44fc2005-08-05 00:44:28 -04001601 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001602
Len Brown4be44fc2005-08-05 00:44:28 -04001603static void acpi_video_device_rebind(struct acpi_video_bus *video)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001604{
Dmitry Torokhovff102ea2007-11-05 11:43:31 -05001605 struct acpi_video_device *dev;
1606
Dmitry Torokhovbbac81f2007-11-05 11:43:32 -05001607 mutex_lock(&video->device_list_lock);
Dmitry Torokhovff102ea2007-11-05 11:43:31 -05001608
1609 list_for_each_entry(dev, &video->video_device_list, entry)
Len Brown4be44fc2005-08-05 00:44:28 -04001610 acpi_video_device_bind(video, dev);
Dmitry Torokhovff102ea2007-11-05 11:43:31 -05001611
Dmitry Torokhovbbac81f2007-11-05 11:43:32 -05001612 mutex_unlock(&video->device_list_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001613}
1614
1615/*
1616 * Arg:
1617 * video : video bus device
1618 * device : video output device under the video
1619 * bus
1620 *
1621 * Return:
1622 * none
1623 *
1624 * Bind the ids with the corresponding video devices
1625 * under the video bus.
Len Brown4be44fc2005-08-05 00:44:28 -04001626 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001627
1628static void
Len Brown4be44fc2005-08-05 00:44:28 -04001629acpi_video_device_bind(struct acpi_video_bus *video,
1630 struct acpi_video_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001631{
Len Brown4be44fc2005-08-05 00:44:28 -04001632 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001633
1634#define IDS_VAL(i) video->attached_array[i].value.int_val
1635#define IDS_BIND(i) video->attached_array[i].bind_info
Len Brown4be44fc2005-08-05 00:44:28 -04001636
1637 for (i = 0; IDS_VAL(i) != ACPI_VIDEO_HEAD_INVALID &&
1638 i < video->attached_count; i++) {
1639 if (device->device_id == (IDS_VAL(i) & 0xffff)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001640 IDS_BIND(i) = device;
1641 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "device_bind %d\n", i));
1642 }
1643 }
1644#undef IDS_VAL
1645#undef IDS_BIND
1646}
1647
1648/*
1649 * Arg:
1650 * video : video bus device
1651 *
1652 * Return:
1653 * < 0 : error
1654 *
1655 * Call _DOD to enumerate all devices attached to display adapter
1656 *
Len Brown4be44fc2005-08-05 00:44:28 -04001657 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001658
1659static int acpi_video_device_enumerate(struct acpi_video_bus *video)
1660{
Len Brown4be44fc2005-08-05 00:44:28 -04001661 int status;
1662 int count;
1663 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001664 struct acpi_video_enumerated_device *active_device_list;
Len Brown4be44fc2005-08-05 00:44:28 -04001665 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
1666 union acpi_object *dod = NULL;
1667 union acpi_object *obj;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001668
Patrick Mochel90130262006-05-19 16:54:48 -04001669 status = acpi_evaluate_object(video->device->handle, "_DOD", NULL, &buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001670 if (!ACPI_SUCCESS(status)) {
Thomas Renningera6fc6722006-06-26 23:58:43 -04001671 ACPI_EXCEPTION((AE_INFO, status, "Evaluating _DOD"));
Patrick Mocheld550d982006-06-27 00:41:40 -04001672 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001673 }
1674
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001675 dod = buffer.pointer;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001676 if (!dod || (dod->type != ACPI_TYPE_PACKAGE)) {
Thomas Renningera6fc6722006-06-26 23:58:43 -04001677 ACPI_EXCEPTION((AE_INFO, status, "Invalid _DOD data"));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001678 status = -EFAULT;
1679 goto out;
1680 }
1681
1682 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found %d video heads in _DOD\n",
Len Brown4be44fc2005-08-05 00:44:28 -04001683 dod->package.count));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001684
Len Brown4be44fc2005-08-05 00:44:28 -04001685 active_device_list = kmalloc((1 +
1686 dod->package.count) *
1687 sizeof(struct
1688 acpi_video_enumerated_device),
1689 GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001690
1691 if (!active_device_list) {
1692 status = -ENOMEM;
1693 goto out;
1694 }
1695
1696 count = 0;
1697 for (i = 0; i < dod->package.count; i++) {
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001698 obj = &dod->package.elements[i];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001699
1700 if (obj->type != ACPI_TYPE_INTEGER) {
Len Brown64684632006-06-26 23:41:38 -04001701 printk(KERN_ERR PREFIX "Invalid _DOD data\n");
Len Brown4be44fc2005-08-05 00:44:28 -04001702 active_device_list[i].value.int_val =
1703 ACPI_VIDEO_HEAD_INVALID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001704 }
1705 active_device_list[i].value.int_val = obj->integer.value;
1706 active_device_list[i].bind_info = NULL;
Len Brown4be44fc2005-08-05 00:44:28 -04001707 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "dod element[%d] = %d\n", i,
1708 (int)obj->integer.value));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001709 count++;
1710 }
1711 active_device_list[count].value.int_val = ACPI_VIDEO_HEAD_END;
1712
Jesper Juhl6044ec82005-11-07 01:01:32 -08001713 kfree(video->attached_array);
Len Brown4be44fc2005-08-05 00:44:28 -04001714
Linus Torvalds1da177e2005-04-16 15:20:36 -07001715 video->attached_array = active_device_list;
1716 video->attached_count = count;
Len Brown4be44fc2005-08-05 00:44:28 -04001717 out:
Len Brown02438d82006-06-30 03:19:10 -04001718 kfree(buffer.pointer);
Patrick Mocheld550d982006-06-27 00:41:40 -04001719 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001720}
1721
Len Brown4be44fc2005-08-05 00:44:28 -04001722static int
1723acpi_video_get_next_level(struct acpi_video_device *device,
1724 u32 level_current, u32 event)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001725{
Alexey Starikovskiy63f0edf2007-09-03 16:30:08 +04001726 int min, max, min_above, max_below, i, l, delta = 255;
Thomas Tuttlef4715182006-12-19 12:56:14 -08001727 max = max_below = 0;
1728 min = min_above = 255;
Alexey Starikovskiy63f0edf2007-09-03 16:30:08 +04001729 /* Find closest level to level_current */
1730 for (i = 0; i < device->brightness->count; i++) {
1731 l = device->brightness->levels[i];
1732 if (abs(l - level_current) < abs(delta)) {
1733 delta = l - level_current;
1734 if (!delta)
1735 break;
1736 }
1737 }
1738 /* Ajust level_current to closest available level */
1739 level_current += delta;
Thomas Tuttlef4715182006-12-19 12:56:14 -08001740 for (i = 0; i < device->brightness->count; i++) {
1741 l = device->brightness->levels[i];
1742 if (l < min)
1743 min = l;
1744 if (l > max)
1745 max = l;
1746 if (l < min_above && l > level_current)
1747 min_above = l;
1748 if (l > max_below && l < level_current)
1749 max_below = l;
1750 }
1751
1752 switch (event) {
1753 case ACPI_VIDEO_NOTIFY_CYCLE_BRIGHTNESS:
1754 return (level_current < max) ? min_above : min;
1755 case ACPI_VIDEO_NOTIFY_INC_BRIGHTNESS:
1756 return (level_current < max) ? min_above : max;
1757 case ACPI_VIDEO_NOTIFY_DEC_BRIGHTNESS:
1758 return (level_current > min) ? max_below : min;
1759 case ACPI_VIDEO_NOTIFY_ZERO_BRIGHTNESS:
1760 case ACPI_VIDEO_NOTIFY_DISPLAY_OFF:
1761 return 0;
1762 default:
1763 return level_current;
1764 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001765}
1766
Linus Torvalds1da177e2005-04-16 15:20:36 -07001767static void
Len Brown4be44fc2005-08-05 00:44:28 -04001768acpi_video_switch_brightness(struct acpi_video_device *device, int event)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001769{
1770 unsigned long level_current, level_next;
1771 acpi_video_device_lcd_get_level_current(device, &level_current);
1772 level_next = acpi_video_get_next_level(device, level_current, event);
1773 acpi_video_device_lcd_set_level(device, level_next);
1774}
1775
1776static int
Len Brown4be44fc2005-08-05 00:44:28 -04001777acpi_video_bus_get_devices(struct acpi_video_bus *video,
1778 struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001779{
Len Brown4be44fc2005-08-05 00:44:28 -04001780 int status = 0;
Dmitry Torokhovff102ea2007-11-05 11:43:31 -05001781 struct acpi_device *dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001782
1783 acpi_video_device_enumerate(video);
1784
Dmitry Torokhovff102ea2007-11-05 11:43:31 -05001785 list_for_each_entry(dev, &device->children, node) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001786
1787 status = acpi_video_bus_get_one_device(dev, video);
1788 if (ACPI_FAILURE(status)) {
Thomas Renningera6fc6722006-06-26 23:58:43 -04001789 ACPI_EXCEPTION((AE_INFO, status, "Cant attach device"));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001790 continue;
1791 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001792 }
Patrick Mocheld550d982006-06-27 00:41:40 -04001793 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001794}
1795
Len Brown4be44fc2005-08-05 00:44:28 -04001796static int acpi_video_bus_put_one_device(struct acpi_video_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001797{
Karol Kozimor031ec772005-07-30 04:18:00 -04001798 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001799 struct acpi_video_bus *video;
1800
Linus Torvalds1da177e2005-04-16 15:20:36 -07001801
1802 if (!device || !device->video)
Patrick Mocheld550d982006-06-27 00:41:40 -04001803 return -ENOENT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001804
1805 video = device->video;
1806
Linus Torvalds1da177e2005-04-16 15:20:36 -07001807 acpi_video_device_remove_fs(device->dev);
1808
Patrick Mochel90130262006-05-19 16:54:48 -04001809 status = acpi_remove_notify_handler(device->dev->handle,
Len Brown4be44fc2005-08-05 00:44:28 -04001810 ACPI_DEVICE_NOTIFY,
1811 acpi_video_device_notify);
Richard Purdie599a52d2007-02-10 23:07:48 +00001812 backlight_device_unregister(device->backlight);
Zhang Rui702ed512008-01-17 15:51:22 +08001813 if (device->cdev) {
1814 sysfs_remove_link(&device->dev->dev.kobj,
1815 "thermal_cooling");
1816 sysfs_remove_link(&device->cdev->device.kobj,
1817 "device");
1818 thermal_cooling_device_unregister(device->cdev);
1819 device->cdev = NULL;
1820 }
Luming Yu23b0f012007-05-09 21:07:05 +08001821 video_output_unregister(device->output_dev);
Dmitry Torokhovff102ea2007-11-05 11:43:31 -05001822
Patrick Mocheld550d982006-06-27 00:41:40 -04001823 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001824}
1825
Len Brown4be44fc2005-08-05 00:44:28 -04001826static int acpi_video_bus_put_devices(struct acpi_video_bus *video)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001827{
Len Brown4be44fc2005-08-05 00:44:28 -04001828 int status;
Dmitry Torokhovff102ea2007-11-05 11:43:31 -05001829 struct acpi_video_device *dev, *next;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001830
Dmitry Torokhovbbac81f2007-11-05 11:43:32 -05001831 mutex_lock(&video->device_list_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001832
Dmitry Torokhovff102ea2007-11-05 11:43:31 -05001833 list_for_each_entry_safe(dev, next, &video->video_device_list, entry) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001834
Dmitry Torokhovff102ea2007-11-05 11:43:31 -05001835 status = acpi_video_bus_put_one_device(dev);
Len Brown4be44fc2005-08-05 00:44:28 -04001836 if (ACPI_FAILURE(status))
1837 printk(KERN_WARNING PREFIX
1838 "hhuuhhuu bug in acpi video driver.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001839
Dmitry Torokhovff102ea2007-11-05 11:43:31 -05001840 if (dev->brightness) {
1841 kfree(dev->brightness->levels);
1842 kfree(dev->brightness);
1843 }
1844 list_del(&dev->entry);
1845 kfree(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001846 }
1847
Dmitry Torokhovbbac81f2007-11-05 11:43:32 -05001848 mutex_unlock(&video->device_list_lock);
Dmitry Torokhovff102ea2007-11-05 11:43:31 -05001849
Patrick Mocheld550d982006-06-27 00:41:40 -04001850 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001851}
1852
1853/* acpi_video interface */
1854
Len Brown4be44fc2005-08-05 00:44:28 -04001855static int acpi_video_bus_start_devices(struct acpi_video_bus *video)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001856{
Zhang Ruia21101c2007-09-14 11:46:22 +08001857 return acpi_video_bus_DOS(video, 0, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001858}
1859
Len Brown4be44fc2005-08-05 00:44:28 -04001860static int acpi_video_bus_stop_devices(struct acpi_video_bus *video)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001861{
1862 return acpi_video_bus_DOS(video, 0, 1);
1863}
1864
Len Brown4be44fc2005-08-05 00:44:28 -04001865static void acpi_video_bus_notify(acpi_handle handle, u32 event, void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001866{
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001867 struct acpi_video_bus *video = data;
Len Brown4be44fc2005-08-05 00:44:28 -04001868 struct acpi_device *device = NULL;
Luming Yue9dab192007-08-20 18:23:53 +08001869 struct input_dev *input;
1870 int keycode;
1871
Linus Torvalds1da177e2005-04-16 15:20:36 -07001872 if (!video)
Patrick Mocheld550d982006-06-27 00:41:40 -04001873 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001874
Patrick Mochele6afa0d2006-05-19 16:54:40 -04001875 device = video->device;
Luming Yue9dab192007-08-20 18:23:53 +08001876 input = video->input;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001877
1878 switch (event) {
Julius Volz98fb8fe2007-02-20 16:38:40 +01001879 case ACPI_VIDEO_NOTIFY_SWITCH: /* User requested a switch,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001880 * most likely via hotkey. */
Len Brown14e04fb32007-08-23 15:20:26 -04001881 acpi_bus_generate_proc_event(device, event, 0);
Luming Yue9dab192007-08-20 18:23:53 +08001882 keycode = KEY_SWITCHVIDEOMODE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001883 break;
1884
Julius Volz98fb8fe2007-02-20 16:38:40 +01001885 case ACPI_VIDEO_NOTIFY_PROBE: /* User plugged in or removed a video
Linus Torvalds1da177e2005-04-16 15:20:36 -07001886 * connector. */
1887 acpi_video_device_enumerate(video);
1888 acpi_video_device_rebind(video);
Len Brown14e04fb32007-08-23 15:20:26 -04001889 acpi_bus_generate_proc_event(device, event, 0);
Luming Yue9dab192007-08-20 18:23:53 +08001890 keycode = KEY_SWITCHVIDEOMODE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001891 break;
1892
Len Brown4be44fc2005-08-05 00:44:28 -04001893 case ACPI_VIDEO_NOTIFY_CYCLE: /* Cycle Display output hotkey pressed. */
Len Brown25c87f72007-08-25 01:44:01 -04001894 acpi_bus_generate_proc_event(device, event, 0);
Luming Yue9dab192007-08-20 18:23:53 +08001895 keycode = KEY_SWITCHVIDEOMODE;
1896 break;
Len Brown4be44fc2005-08-05 00:44:28 -04001897 case ACPI_VIDEO_NOTIFY_NEXT_OUTPUT: /* Next Display output hotkey pressed. */
Len Brown25c87f72007-08-25 01:44:01 -04001898 acpi_bus_generate_proc_event(device, event, 0);
Luming Yue9dab192007-08-20 18:23:53 +08001899 keycode = KEY_VIDEO_NEXT;
1900 break;
Len Brown4be44fc2005-08-05 00:44:28 -04001901 case ACPI_VIDEO_NOTIFY_PREV_OUTPUT: /* previous Display output hotkey pressed. */
Len Brown14e04fb32007-08-23 15:20:26 -04001902 acpi_bus_generate_proc_event(device, event, 0);
Luming Yue9dab192007-08-20 18:23:53 +08001903 keycode = KEY_VIDEO_PREV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001904 break;
1905
1906 default:
Luming Yue9dab192007-08-20 18:23:53 +08001907 keycode = KEY_UNKNOWN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001908 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
Len Brown4be44fc2005-08-05 00:44:28 -04001909 "Unsupported event [0x%x]\n", event));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001910 break;
1911 }
1912
Zhang Rui7761f632008-01-25 14:48:12 +08001913 acpi_notifier_call_chain(device, event, 0);
Luming Yue9dab192007-08-20 18:23:53 +08001914 input_report_key(input, keycode, 1);
1915 input_sync(input);
1916 input_report_key(input, keycode, 0);
1917 input_sync(input);
1918
Patrick Mocheld550d982006-06-27 00:41:40 -04001919 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001920}
1921
Len Brown4be44fc2005-08-05 00:44:28 -04001922static void acpi_video_device_notify(acpi_handle handle, u32 event, void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001923{
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001924 struct acpi_video_device *video_device = data;
Len Brown4be44fc2005-08-05 00:44:28 -04001925 struct acpi_device *device = NULL;
Luming Yue9dab192007-08-20 18:23:53 +08001926 struct acpi_video_bus *bus;
1927 struct input_dev *input;
1928 int keycode;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001929
Linus Torvalds1da177e2005-04-16 15:20:36 -07001930 if (!video_device)
Patrick Mocheld550d982006-06-27 00:41:40 -04001931 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001932
Patrick Mochele6afa0d2006-05-19 16:54:40 -04001933 device = video_device->dev;
Luming Yue9dab192007-08-20 18:23:53 +08001934 bus = video_device->video;
1935 input = bus->input;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001936
1937 switch (event) {
Len Brown4be44fc2005-08-05 00:44:28 -04001938 case ACPI_VIDEO_NOTIFY_CYCLE_BRIGHTNESS: /* Cycle brightness */
Zhang Rui8a681a42008-01-25 14:47:49 +08001939 if (brightness_switch_enabled)
1940 acpi_video_switch_brightness(video_device, event);
Len Brown25c87f72007-08-25 01:44:01 -04001941 acpi_bus_generate_proc_event(device, event, 0);
Luming Yue9dab192007-08-20 18:23:53 +08001942 keycode = KEY_BRIGHTNESS_CYCLE;
1943 break;
Len Brown4be44fc2005-08-05 00:44:28 -04001944 case ACPI_VIDEO_NOTIFY_INC_BRIGHTNESS: /* Increase brightness */
Zhang Rui8a681a42008-01-25 14:47:49 +08001945 if (brightness_switch_enabled)
1946 acpi_video_switch_brightness(video_device, event);
Len Brown25c87f72007-08-25 01:44:01 -04001947 acpi_bus_generate_proc_event(device, event, 0);
Luming Yue9dab192007-08-20 18:23:53 +08001948 keycode = KEY_BRIGHTNESSUP;
1949 break;
Len Brown4be44fc2005-08-05 00:44:28 -04001950 case ACPI_VIDEO_NOTIFY_DEC_BRIGHTNESS: /* Decrease brightness */
Zhang Rui8a681a42008-01-25 14:47:49 +08001951 if (brightness_switch_enabled)
1952 acpi_video_switch_brightness(video_device, event);
Len Brown25c87f72007-08-25 01:44:01 -04001953 acpi_bus_generate_proc_event(device, event, 0);
Luming Yue9dab192007-08-20 18:23:53 +08001954 keycode = KEY_BRIGHTNESSDOWN;
1955 break;
Len Brown4be44fc2005-08-05 00:44:28 -04001956 case ACPI_VIDEO_NOTIFY_ZERO_BRIGHTNESS: /* zero brightnesss */
Zhang Rui8a681a42008-01-25 14:47:49 +08001957 if (brightness_switch_enabled)
1958 acpi_video_switch_brightness(video_device, event);
Len Brown25c87f72007-08-25 01:44:01 -04001959 acpi_bus_generate_proc_event(device, event, 0);
Luming Yue9dab192007-08-20 18:23:53 +08001960 keycode = KEY_BRIGHTNESS_ZERO;
1961 break;
Len Brown4be44fc2005-08-05 00:44:28 -04001962 case ACPI_VIDEO_NOTIFY_DISPLAY_OFF: /* display device off */
Zhang Rui8a681a42008-01-25 14:47:49 +08001963 if (brightness_switch_enabled)
1964 acpi_video_switch_brightness(video_device, event);
Len Brown14e04fb32007-08-23 15:20:26 -04001965 acpi_bus_generate_proc_event(device, event, 0);
Luming Yue9dab192007-08-20 18:23:53 +08001966 keycode = KEY_DISPLAY_OFF;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001967 break;
1968 default:
Luming Yue9dab192007-08-20 18:23:53 +08001969 keycode = KEY_UNKNOWN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001970 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
Len Brown4be44fc2005-08-05 00:44:28 -04001971 "Unsupported event [0x%x]\n", event));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001972 break;
1973 }
Luming Yue9dab192007-08-20 18:23:53 +08001974
Zhang Rui7761f632008-01-25 14:48:12 +08001975 acpi_notifier_call_chain(device, event, 0);
Luming Yue9dab192007-08-20 18:23:53 +08001976 input_report_key(input, keycode, 1);
1977 input_sync(input);
1978 input_report_key(input, keycode, 0);
1979 input_sync(input);
1980
Patrick Mocheld550d982006-06-27 00:41:40 -04001981 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001982}
1983
Zhang Ruie6d9da12007-08-25 02:23:31 -04001984static int instance;
Matthew Garrett863c1492008-02-04 23:31:24 -08001985static int acpi_video_resume(struct acpi_device *device)
1986{
1987 struct acpi_video_bus *video;
1988 struct acpi_video_device *video_device;
1989 int i;
1990
1991 if (!device || !acpi_driver_data(device))
1992 return -EINVAL;
1993
1994 video = acpi_driver_data(device);
1995
1996 for (i = 0; i < video->attached_count; i++) {
1997 video_device = video->attached_array[i].bind_info;
1998 if (video_device && video_device->backlight)
1999 acpi_video_set_brightness(video_device->backlight);
2000 }
2001 return AE_OK;
2002}
2003
Len Brown4be44fc2005-08-05 00:44:28 -04002004static int acpi_video_bus_add(struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002005{
Dmitry Torokhovf51e8392007-11-05 11:43:30 -05002006 acpi_status status;
2007 struct acpi_video_bus *video;
Luming Yue9dab192007-08-20 18:23:53 +08002008 struct input_dev *input;
Dmitry Torokhovf51e8392007-11-05 11:43:30 -05002009 int error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002010
Burman Yan36bcbec2006-12-19 12:56:11 -08002011 video = kzalloc(sizeof(struct acpi_video_bus), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002012 if (!video)
Patrick Mocheld550d982006-06-27 00:41:40 -04002013 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002014
Zhang Ruie6d9da12007-08-25 02:23:31 -04002015 /* a hack to fix the duplicate name "VID" problem on T61 */
2016 if (!strcmp(device->pnp.bus_id, "VID")) {
2017 if (instance)
2018 device->pnp.bus_id[3] = '0' + instance;
2019 instance ++;
2020 }
2021
Patrick Mochele6afa0d2006-05-19 16:54:40 -04002022 video->device = device;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002023 strcpy(acpi_device_name(device), ACPI_VIDEO_BUS_NAME);
2024 strcpy(acpi_device_class(device), ACPI_VIDEO_CLASS);
2025 acpi_driver_data(device) = video;
2026
2027 acpi_video_bus_find_cap(video);
Dmitry Torokhovf51e8392007-11-05 11:43:30 -05002028 error = acpi_video_bus_check(video);
2029 if (error)
2030 goto err_free_video;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002031
Dmitry Torokhovf51e8392007-11-05 11:43:30 -05002032 error = acpi_video_bus_add_fs(device);
2033 if (error)
2034 goto err_free_video;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002035
Dmitry Torokhovbbac81f2007-11-05 11:43:32 -05002036 mutex_init(&video->device_list_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002037 INIT_LIST_HEAD(&video->video_device_list);
2038
2039 acpi_video_bus_get_devices(video, device);
2040 acpi_video_bus_start_devices(video);
2041
Patrick Mochel90130262006-05-19 16:54:48 -04002042 status = acpi_install_notify_handler(device->handle,
Len Brown4be44fc2005-08-05 00:44:28 -04002043 ACPI_DEVICE_NOTIFY,
2044 acpi_video_bus_notify, video);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002045 if (ACPI_FAILURE(status)) {
2046 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
Len Brown4be44fc2005-08-05 00:44:28 -04002047 "Error installing notify handler\n"));
Dmitry Torokhovf51e8392007-11-05 11:43:30 -05002048 error = -ENODEV;
2049 goto err_stop_video;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002050 }
2051
Luming Yue9dab192007-08-20 18:23:53 +08002052 video->input = input = input_allocate_device();
Dmitry Torokhovf51e8392007-11-05 11:43:30 -05002053 if (!input) {
2054 error = -ENOMEM;
2055 goto err_uninstall_notify;
2056 }
Luming Yue9dab192007-08-20 18:23:53 +08002057
2058 snprintf(video->phys, sizeof(video->phys),
2059 "%s/video/input0", acpi_device_hid(video->device));
2060
2061 input->name = acpi_device_name(video->device);
2062 input->phys = video->phys;
2063 input->id.bustype = BUS_HOST;
2064 input->id.product = 0x06;
Dmitry Torokhov91c05c62007-11-05 11:43:29 -05002065 input->dev.parent = &device->dev;
Luming Yue9dab192007-08-20 18:23:53 +08002066 input->evbit[0] = BIT(EV_KEY);
2067 set_bit(KEY_SWITCHVIDEOMODE, input->keybit);
2068 set_bit(KEY_VIDEO_NEXT, input->keybit);
2069 set_bit(KEY_VIDEO_PREV, input->keybit);
2070 set_bit(KEY_BRIGHTNESS_CYCLE, input->keybit);
2071 set_bit(KEY_BRIGHTNESSUP, input->keybit);
2072 set_bit(KEY_BRIGHTNESSDOWN, input->keybit);
2073 set_bit(KEY_BRIGHTNESS_ZERO, input->keybit);
2074 set_bit(KEY_DISPLAY_OFF, input->keybit);
2075 set_bit(KEY_UNKNOWN, input->keybit);
Luming Yue9dab192007-08-20 18:23:53 +08002076
Dmitry Torokhovf51e8392007-11-05 11:43:30 -05002077 error = input_register_device(input);
2078 if (error)
2079 goto err_free_input_dev;
Luming Yue9dab192007-08-20 18:23:53 +08002080
Linus Torvalds1da177e2005-04-16 15:20:36 -07002081 printk(KERN_INFO PREFIX "%s [%s] (multi-head: %s rom: %s post: %s)\n",
Len Brown4be44fc2005-08-05 00:44:28 -04002082 ACPI_VIDEO_DEVICE_NAME, acpi_device_bid(device),
2083 video->flags.multihead ? "yes" : "no",
2084 video->flags.rom ? "yes" : "no",
2085 video->flags.post ? "yes" : "no");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002086
Dmitry Torokhovf51e8392007-11-05 11:43:30 -05002087 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002088
Dmitry Torokhovf51e8392007-11-05 11:43:30 -05002089 err_free_input_dev:
2090 input_free_device(input);
2091 err_uninstall_notify:
2092 acpi_remove_notify_handler(device->handle, ACPI_DEVICE_NOTIFY,
2093 acpi_video_bus_notify);
2094 err_stop_video:
2095 acpi_video_bus_stop_devices(video);
2096 acpi_video_bus_put_devices(video);
2097 kfree(video->attached_array);
2098 acpi_video_bus_remove_fs(device);
2099 err_free_video:
2100 kfree(video);
2101 acpi_driver_data(device) = NULL;
2102
2103 return error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002104}
2105
Len Brown4be44fc2005-08-05 00:44:28 -04002106static int acpi_video_bus_remove(struct acpi_device *device, int type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002107{
Len Brown4be44fc2005-08-05 00:44:28 -04002108 acpi_status status = 0;
2109 struct acpi_video_bus *video = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002110
Linus Torvalds1da177e2005-04-16 15:20:36 -07002111
2112 if (!device || !acpi_driver_data(device))
Patrick Mocheld550d982006-06-27 00:41:40 -04002113 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002114
Jan Engelhardt50dd0962006-10-01 00:28:50 +02002115 video = acpi_driver_data(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002116
2117 acpi_video_bus_stop_devices(video);
2118
Patrick Mochel90130262006-05-19 16:54:48 -04002119 status = acpi_remove_notify_handler(video->device->handle,
Len Brown4be44fc2005-08-05 00:44:28 -04002120 ACPI_DEVICE_NOTIFY,
2121 acpi_video_bus_notify);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002122
2123 acpi_video_bus_put_devices(video);
2124 acpi_video_bus_remove_fs(device);
2125
Luming Yue9dab192007-08-20 18:23:53 +08002126 input_unregister_device(video->input);
Jesper Juhl6044ec82005-11-07 01:01:32 -08002127 kfree(video->attached_array);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002128 kfree(video);
2129
Patrick Mocheld550d982006-06-27 00:41:40 -04002130 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002131}
2132
Len Brown4be44fc2005-08-05 00:44:28 -04002133static int __init acpi_video_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002134{
Len Brown4be44fc2005-08-05 00:44:28 -04002135 int result = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002136
Linus Torvalds1da177e2005-04-16 15:20:36 -07002137
2138 /*
Len Brown4be44fc2005-08-05 00:44:28 -04002139 acpi_dbg_level = 0xFFFFFFFF;
2140 acpi_dbg_layer = 0x08000000;
2141 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002142
2143 acpi_video_dir = proc_mkdir(ACPI_VIDEO_CLASS, acpi_root_dir);
2144 if (!acpi_video_dir)
Patrick Mocheld550d982006-06-27 00:41:40 -04002145 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002146 acpi_video_dir->owner = THIS_MODULE;
2147
2148 result = acpi_bus_register_driver(&acpi_video_bus);
2149 if (result < 0) {
2150 remove_proc_entry(ACPI_VIDEO_CLASS, acpi_root_dir);
Patrick Mocheld550d982006-06-27 00:41:40 -04002151 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002152 }
2153
Patrick Mocheld550d982006-06-27 00:41:40 -04002154 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002155}
2156
Len Brown4be44fc2005-08-05 00:44:28 -04002157static void __exit acpi_video_exit(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002158{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002159
2160 acpi_bus_unregister_driver(&acpi_video_bus);
2161
2162 remove_proc_entry(ACPI_VIDEO_CLASS, acpi_root_dir);
2163
Patrick Mocheld550d982006-06-27 00:41:40 -04002164 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002165}
2166
2167module_init(acpi_video_init);
2168module_exit(acpi_video_exit);