blob: 5e5dda3a3027abfa1554a9b44c5ae636cd1e7133 [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
Yu Luming2f3d0002006-11-11 02:40:34 +080060#define MAX_NAME_LEN 20
Linus Torvalds1da177e2005-04-16 15:20:36 -070061
Rui Zhang82cae992007-01-03 23:40:53 -050062#define ACPI_VIDEO_DISPLAY_CRT 1
63#define ACPI_VIDEO_DISPLAY_TV 2
64#define ACPI_VIDEO_DISPLAY_DVI 3
65#define ACPI_VIDEO_DISPLAY_LCD 4
66
Linus Torvalds1da177e2005-04-16 15:20:36 -070067#define _COMPONENT ACPI_VIDEO_COMPONENT
Len Brownf52fd662007-02-12 22:42:12 -050068ACPI_MODULE_NAME("video");
Linus Torvalds1da177e2005-04-16 15:20:36 -070069
Len Brownf52fd662007-02-12 22:42:12 -050070MODULE_AUTHOR("Bruno Ducrot");
Len Brown7cda93e2007-02-12 23:50:02 -050071MODULE_DESCRIPTION("ACPI Video Driver");
Linus Torvalds1da177e2005-04-16 15:20:36 -070072MODULE_LICENSE("GPL");
73
Zhang Rui8a681a42008-01-25 14:47:49 +080074static int brightness_switch_enabled = 1;
75module_param(brightness_switch_enabled, bool, 0644);
76
Len Brown4be44fc2005-08-05 00:44:28 -040077static int acpi_video_bus_add(struct acpi_device *device);
78static int acpi_video_bus_remove(struct acpi_device *device, int type);
Matthew Garrett863c1492008-02-04 23:31:24 -080079static int acpi_video_resume(struct acpi_device *device);
Linus Torvalds1da177e2005-04-16 15:20:36 -070080
Thomas Renninger1ba90e32007-07-23 14:44:41 +020081static const struct acpi_device_id video_device_ids[] = {
82 {ACPI_VIDEO_HID, 0},
83 {"", 0},
84};
85MODULE_DEVICE_TABLE(acpi, video_device_ids);
86
Linus Torvalds1da177e2005-04-16 15:20:36 -070087static struct acpi_driver acpi_video_bus = {
Len Brownc2b67052007-02-12 23:33:40 -050088 .name = "video",
Linus Torvalds1da177e2005-04-16 15:20:36 -070089 .class = ACPI_VIDEO_CLASS,
Thomas Renninger1ba90e32007-07-23 14:44:41 +020090 .ids = video_device_ids,
Linus Torvalds1da177e2005-04-16 15:20:36 -070091 .ops = {
92 .add = acpi_video_bus_add,
93 .remove = acpi_video_bus_remove,
Matthew Garrett863c1492008-02-04 23:31:24 -080094 .resume = acpi_video_resume,
Len Brown4be44fc2005-08-05 00:44:28 -040095 },
Linus Torvalds1da177e2005-04-16 15:20:36 -070096};
97
98struct acpi_video_bus_flags {
Len Brown4be44fc2005-08-05 00:44:28 -040099 u8 multihead:1; /* can switch video heads */
100 u8 rom:1; /* can retrieve a video rom */
101 u8 post:1; /* can configure the head to */
102 u8 reserved:5;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103};
104
105struct acpi_video_bus_cap {
Len Brown4be44fc2005-08-05 00:44:28 -0400106 u8 _DOS:1; /*Enable/Disable output switching */
107 u8 _DOD:1; /*Enumerate all devices attached to display adapter */
108 u8 _ROM:1; /*Get ROM Data */
109 u8 _GPD:1; /*Get POST Device */
110 u8 _SPD:1; /*Set POST Device */
111 u8 _VPO:1; /*Video POST Options */
112 u8 reserved:2;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113};
114
Len Brown4be44fc2005-08-05 00:44:28 -0400115struct acpi_video_device_attrib {
116 u32 display_index:4; /* A zero-based instance of the Display */
Julius Volz98fb8fe2007-02-20 16:38:40 +0100117 u32 display_port_attachment:4; /*This field differentiates the display type */
Len Brown4be44fc2005-08-05 00:44:28 -0400118 u32 display_type:4; /*Describe the specific type in use */
Julius Volz98fb8fe2007-02-20 16:38:40 +0100119 u32 vendor_specific:4; /*Chipset Vendor Specific */
Len Brown4be44fc2005-08-05 00:44:28 -0400120 u32 bios_can_detect:1; /*BIOS can detect the device */
121 u32 depend_on_vga:1; /*Non-VGA output device whose power is related to
122 the VGA device. */
123 u32 pipe_id:3; /*For VGA multiple-head devices. */
124 u32 reserved:10; /*Must be 0 */
125 u32 device_id_scheme:1; /*Device ID Scheme */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126};
127
128struct acpi_video_enumerated_device {
129 union {
130 u32 int_val;
Len Brown4be44fc2005-08-05 00:44:28 -0400131 struct acpi_video_device_attrib attrib;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132 } value;
133 struct acpi_video_device *bind_info;
134};
135
136struct acpi_video_bus {
Patrick Mochele6afa0d2006-05-19 16:54:40 -0400137 struct acpi_device *device;
Len Brown4be44fc2005-08-05 00:44:28 -0400138 u8 dos_setting;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139 struct acpi_video_enumerated_device *attached_array;
Len Brown4be44fc2005-08-05 00:44:28 -0400140 u8 attached_count;
141 struct acpi_video_bus_cap cap;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142 struct acpi_video_bus_flags flags;
Len Brown4be44fc2005-08-05 00:44:28 -0400143 struct list_head video_device_list;
Dmitry Torokhovbbac81f2007-11-05 11:43:32 -0500144 struct mutex device_list_lock; /* protects video_device_list */
Len Brown4be44fc2005-08-05 00:44:28 -0400145 struct proc_dir_entry *dir;
Luming Yue9dab192007-08-20 18:23:53 +0800146 struct input_dev *input;
147 char phys[32]; /* for input device */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148};
149
150struct acpi_video_device_flags {
Len Brown4be44fc2005-08-05 00:44:28 -0400151 u8 crt:1;
152 u8 lcd:1;
153 u8 tvout:1;
Rui Zhang82cae992007-01-03 23:40:53 -0500154 u8 dvi:1;
Len Brown4be44fc2005-08-05 00:44:28 -0400155 u8 bios:1;
156 u8 unknown:1;
Rui Zhang82cae992007-01-03 23:40:53 -0500157 u8 reserved:2;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700158};
159
160struct acpi_video_device_cap {
Len Brown4be44fc2005-08-05 00:44:28 -0400161 u8 _ADR:1; /*Return the unique ID */
162 u8 _BCL:1; /*Query list of brightness control levels supported */
163 u8 _BCM:1; /*Set the brightness level */
Yu Luming2f3d0002006-11-11 02:40:34 +0800164 u8 _BQC:1; /* Get current brightness level */
Len Brown4be44fc2005-08-05 00:44:28 -0400165 u8 _DDC:1; /*Return the EDID for this device */
166 u8 _DCS:1; /*Return status of output device */
167 u8 _DGS:1; /*Query graphics state */
168 u8 _DSS:1; /*Device state set */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700169};
170
171struct acpi_video_device_brightness {
Len Brown4be44fc2005-08-05 00:44:28 -0400172 int curr;
173 int count;
174 int *levels;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700175};
176
177struct acpi_video_device {
Len Brown4be44fc2005-08-05 00:44:28 -0400178 unsigned long device_id;
179 struct acpi_video_device_flags flags;
180 struct acpi_video_device_cap cap;
181 struct list_head entry;
182 struct acpi_video_bus *video;
183 struct acpi_device *dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700184 struct acpi_video_device_brightness *brightness;
Yu Luming2f3d0002006-11-11 02:40:34 +0800185 struct backlight_device *backlight;
Zhang Rui702ed512008-01-17 15:51:22 +0800186 struct thermal_cooling_device *cdev;
Luming Yu23b0f012007-05-09 21:07:05 +0800187 struct output_device *output_dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700188};
189
Linus Torvalds1da177e2005-04-16 15:20:36 -0700190/* bus */
191static int acpi_video_bus_info_open_fs(struct inode *inode, struct file *file);
192static struct file_operations acpi_video_bus_info_fops = {
Denis V. Lunevcf7acfa2008-04-29 01:02:27 -0700193 .owner = THIS_MODULE,
Len Brown4be44fc2005-08-05 00:44:28 -0400194 .open = acpi_video_bus_info_open_fs,
195 .read = seq_read,
196 .llseek = seq_lseek,
197 .release = single_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700198};
199
200static int acpi_video_bus_ROM_open_fs(struct inode *inode, struct file *file);
201static struct file_operations acpi_video_bus_ROM_fops = {
Denis V. Lunevcf7acfa2008-04-29 01:02:27 -0700202 .owner = THIS_MODULE,
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 = {
Denis V. Lunevcf7acfa2008-04-29 01:02:27 -0700212 .owner = THIS_MODULE,
Len Brown4be44fc2005-08-05 00:44:28 -0400213 .open = acpi_video_bus_POST_info_open_fs,
214 .read = seq_read,
215 .llseek = seq_lseek,
216 .release = single_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700217};
218
219static int acpi_video_bus_POST_open_fs(struct inode *inode, struct file *file);
220static struct file_operations acpi_video_bus_POST_fops = {
Denis V. Lunevcf7acfa2008-04-29 01:02:27 -0700221 .owner = THIS_MODULE,
Len Brown4be44fc2005-08-05 00:44:28 -0400222 .open = acpi_video_bus_POST_open_fs,
223 .read = seq_read,
224 .llseek = seq_lseek,
225 .release = single_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700226};
227
Linus Torvalds1da177e2005-04-16 15:20:36 -0700228static int acpi_video_bus_DOS_open_fs(struct inode *inode, struct file *file);
229static struct file_operations acpi_video_bus_DOS_fops = {
Denis V. Lunevcf7acfa2008-04-29 01:02:27 -0700230 .owner = THIS_MODULE,
Len Brown4be44fc2005-08-05 00:44:28 -0400231 .open = acpi_video_bus_DOS_open_fs,
232 .read = seq_read,
233 .llseek = seq_lseek,
234 .release = single_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700235};
236
237/* device */
Len Brown4be44fc2005-08-05 00:44:28 -0400238static int acpi_video_device_info_open_fs(struct inode *inode,
239 struct file *file);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700240static struct file_operations acpi_video_device_info_fops = {
Denis V. Lunevcf7acfa2008-04-29 01:02:27 -0700241 .owner = THIS_MODULE,
Len Brown4be44fc2005-08-05 00:44:28 -0400242 .open = acpi_video_device_info_open_fs,
243 .read = seq_read,
244 .llseek = seq_lseek,
245 .release = single_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700246};
247
Len Brown4be44fc2005-08-05 00:44:28 -0400248static int acpi_video_device_state_open_fs(struct inode *inode,
249 struct file *file);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700250static struct file_operations acpi_video_device_state_fops = {
Denis V. Lunevcf7acfa2008-04-29 01:02:27 -0700251 .owner = THIS_MODULE,
Len Brown4be44fc2005-08-05 00:44:28 -0400252 .open = acpi_video_device_state_open_fs,
253 .read = seq_read,
254 .llseek = seq_lseek,
255 .release = single_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700256};
257
Len Brown4be44fc2005-08-05 00:44:28 -0400258static int acpi_video_device_brightness_open_fs(struct inode *inode,
259 struct file *file);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700260static struct file_operations acpi_video_device_brightness_fops = {
Denis V. Lunevcf7acfa2008-04-29 01:02:27 -0700261 .owner = THIS_MODULE,
Len Brown4be44fc2005-08-05 00:44:28 -0400262 .open = acpi_video_device_brightness_open_fs,
263 .read = seq_read,
264 .llseek = seq_lseek,
265 .release = single_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700266};
267
Len Brown4be44fc2005-08-05 00:44:28 -0400268static int acpi_video_device_EDID_open_fs(struct inode *inode,
269 struct file *file);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700270static struct file_operations acpi_video_device_EDID_fops = {
Denis V. Lunevcf7acfa2008-04-29 01:02:27 -0700271 .owner = THIS_MODULE,
Len Brown4be44fc2005-08-05 00:44:28 -0400272 .open = acpi_video_device_EDID_open_fs,
273 .read = seq_read,
274 .llseek = seq_lseek,
275 .release = single_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700276};
277
Len Brown4be44fc2005-08-05 00:44:28 -0400278static char device_decode[][30] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700279 "motherboard VGA device",
280 "PCI VGA device",
281 "AGP VGA device",
282 "UNKNOWN",
283};
284
Len Brown4be44fc2005-08-05 00:44:28 -0400285static void acpi_video_device_notify(acpi_handle handle, u32 event, void *data);
286static void acpi_video_device_rebind(struct acpi_video_bus *video);
287static void acpi_video_device_bind(struct acpi_video_bus *video,
288 struct acpi_video_device *device);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700289static int acpi_video_device_enumerate(struct acpi_video_bus *video);
Yu Luming2f3d0002006-11-11 02:40:34 +0800290static int acpi_video_device_lcd_set_level(struct acpi_video_device *device,
291 int level);
292static int acpi_video_device_lcd_get_level_current(
293 struct acpi_video_device *device,
294 unsigned long *level);
Len Brown4be44fc2005-08-05 00:44:28 -0400295static int acpi_video_get_next_level(struct acpi_video_device *device,
296 u32 level_current, u32 event);
297static void acpi_video_switch_brightness(struct acpi_video_device *device,
298 int event);
Luming Yu23b0f012007-05-09 21:07:05 +0800299static int acpi_video_device_get_state(struct acpi_video_device *device,
300 unsigned long *state);
301static int acpi_video_output_get(struct output_device *od);
302static int acpi_video_device_set_state(struct acpi_video_device *device, int state);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700303
Yu Luming2f3d0002006-11-11 02:40:34 +0800304/*backlight device sysfs support*/
305static int acpi_video_get_brightness(struct backlight_device *bd)
306{
307 unsigned long cur_level;
Matthew Garrett38531e62007-12-26 02:03:26 +0000308 int i;
Yu Luming2f3d0002006-11-11 02:40:34 +0800309 struct acpi_video_device *vd =
Richard Purdie655bfd72007-07-09 12:17:24 +0100310 (struct acpi_video_device *)bl_get_data(bd);
Yu Luming2f3d0002006-11-11 02:40:34 +0800311 acpi_video_device_lcd_get_level_current(vd, &cur_level);
Matthew Garrett38531e62007-12-26 02:03:26 +0000312 for (i = 2; i < vd->brightness->count; i++) {
313 if (vd->brightness->levels[i] == cur_level)
314 /* The first two entries are special - see page 575
315 of the ACPI spec 3.0 */
316 return i-2;
317 }
318 return 0;
Yu Luming2f3d0002006-11-11 02:40:34 +0800319}
320
321static int acpi_video_set_brightness(struct backlight_device *bd)
322{
Matthew Garrett38531e62007-12-26 02:03:26 +0000323 int request_level = bd->props.brightness+2;
Yu Luming2f3d0002006-11-11 02:40:34 +0800324 struct acpi_video_device *vd =
Richard Purdie655bfd72007-07-09 12:17:24 +0100325 (struct acpi_video_device *)bl_get_data(bd);
Matthew Garrett38531e62007-12-26 02:03:26 +0000326 acpi_video_device_lcd_set_level(vd,
327 vd->brightness->levels[request_level]);
Yu Luming2f3d0002006-11-11 02:40:34 +0800328 return 0;
329}
330
Richard Purdie599a52d2007-02-10 23:07:48 +0000331static struct backlight_ops acpi_backlight_ops = {
332 .get_brightness = acpi_video_get_brightness,
333 .update_status = acpi_video_set_brightness,
334};
335
Luming Yu23b0f012007-05-09 21:07:05 +0800336/*video output device sysfs support*/
337static int acpi_video_output_get(struct output_device *od)
338{
339 unsigned long state;
340 struct acpi_video_device *vd =
tonyj@suse.de60043422007-08-07 22:28:47 -0700341 (struct acpi_video_device *)dev_get_drvdata(&od->dev);
Luming Yu23b0f012007-05-09 21:07:05 +0800342 acpi_video_device_get_state(vd, &state);
343 return (int)state;
344}
345
346static int acpi_video_output_set(struct output_device *od)
347{
348 unsigned long state = od->request_state;
349 struct acpi_video_device *vd=
tonyj@suse.de60043422007-08-07 22:28:47 -0700350 (struct acpi_video_device *)dev_get_drvdata(&od->dev);
Luming Yu23b0f012007-05-09 21:07:05 +0800351 return acpi_video_device_set_state(vd, state);
352}
353
354static struct output_properties acpi_output_properties = {
355 .set_state = acpi_video_output_set,
356 .get_status = acpi_video_output_get,
357};
Zhang Rui702ed512008-01-17 15:51:22 +0800358
359
360/* thermal cooling device callbacks */
361static int video_get_max_state(struct thermal_cooling_device *cdev, char *buf)
362{
363 struct acpi_device *device = cdev->devdata;
364 struct acpi_video_device *video = acpi_driver_data(device);
365
366 return sprintf(buf, "%d\n", video->brightness->count - 3);
367}
368
369static int video_get_cur_state(struct thermal_cooling_device *cdev, char *buf)
370{
371 struct acpi_device *device = cdev->devdata;
372 struct acpi_video_device *video = acpi_driver_data(device);
373 unsigned long level;
374 int state;
375
376 acpi_video_device_lcd_get_level_current(video, &level);
377 for (state = 2; state < video->brightness->count; state++)
378 if (level == video->brightness->levels[state])
379 return sprintf(buf, "%d\n",
380 video->brightness->count - state - 1);
381
382 return -EINVAL;
383}
384
385static int
386video_set_cur_state(struct thermal_cooling_device *cdev, unsigned int state)
387{
388 struct acpi_device *device = cdev->devdata;
389 struct acpi_video_device *video = acpi_driver_data(device);
390 int level;
391
392 if ( state >= video->brightness->count - 2)
393 return -EINVAL;
394
395 state = video->brightness->count - state;
396 level = video->brightness->levels[state -1];
397 return acpi_video_device_lcd_set_level(video, level);
398}
399
400static struct thermal_cooling_device_ops video_cooling_ops = {
401 .get_max_state = video_get_max_state,
402 .get_cur_state = video_get_cur_state,
403 .set_cur_state = video_set_cur_state,
404};
405
Linus Torvalds1da177e2005-04-16 15:20:36 -0700406/* --------------------------------------------------------------------------
407 Video Management
408 -------------------------------------------------------------------------- */
409
410/* device */
411
412static int
Len Brown4be44fc2005-08-05 00:44:28 -0400413acpi_video_device_query(struct acpi_video_device *device, unsigned long *state)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700414{
Len Brown4be44fc2005-08-05 00:44:28 -0400415 int status;
Patrick Mochel90130262006-05-19 16:54:48 -0400416
417 status = acpi_evaluate_integer(device->dev->handle, "_DGS", NULL, state);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700418
Patrick Mocheld550d982006-06-27 00:41:40 -0400419 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700420}
421
422static int
Len Brown4be44fc2005-08-05 00:44:28 -0400423acpi_video_device_get_state(struct acpi_video_device *device,
424 unsigned long *state)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700425{
Len Brown4be44fc2005-08-05 00:44:28 -0400426 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700427
Patrick Mochel90130262006-05-19 16:54:48 -0400428 status = acpi_evaluate_integer(device->dev->handle, "_DCS", NULL, state);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700429
Patrick Mocheld550d982006-06-27 00:41:40 -0400430 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700431}
432
433static int
Len Brown4be44fc2005-08-05 00:44:28 -0400434acpi_video_device_set_state(struct acpi_video_device *device, int state)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700435{
Len Brown4be44fc2005-08-05 00:44:28 -0400436 int status;
437 union acpi_object arg0 = { ACPI_TYPE_INTEGER };
438 struct acpi_object_list args = { 1, &arg0 };
Luming Yu824b5582005-08-21 19:17:00 -0400439 unsigned long ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700440
Linus Torvalds1da177e2005-04-16 15:20:36 -0700441
442 arg0.integer.value = state;
Patrick Mochel90130262006-05-19 16:54:48 -0400443 status = acpi_evaluate_integer(device->dev->handle, "_DSS", &args, &ret);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700444
Patrick Mocheld550d982006-06-27 00:41:40 -0400445 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700446}
447
448static int
Len Brown4be44fc2005-08-05 00:44:28 -0400449acpi_video_device_lcd_query_levels(struct acpi_video_device *device,
450 union acpi_object **levels)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700451{
Len Brown4be44fc2005-08-05 00:44:28 -0400452 int status;
453 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
454 union acpi_object *obj;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700455
Linus Torvalds1da177e2005-04-16 15:20:36 -0700456
457 *levels = NULL;
458
Patrick Mochel90130262006-05-19 16:54:48 -0400459 status = acpi_evaluate_object(device->dev->handle, "_BCL", NULL, &buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700460 if (!ACPI_SUCCESS(status))
Patrick Mocheld550d982006-06-27 00:41:40 -0400461 return status;
Len Brown4be44fc2005-08-05 00:44:28 -0400462 obj = (union acpi_object *)buffer.pointer;
Adrian Bunk6665bda2006-03-11 10:12:00 -0500463 if (!obj || (obj->type != ACPI_TYPE_PACKAGE)) {
Len Brown64684632006-06-26 23:41:38 -0400464 printk(KERN_ERR PREFIX "Invalid _BCL data\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700465 status = -EFAULT;
466 goto err;
467 }
468
469 *levels = obj;
470
Patrick Mocheld550d982006-06-27 00:41:40 -0400471 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700472
Len Brown4be44fc2005-08-05 00:44:28 -0400473 err:
Jesper Juhl6044ec82005-11-07 01:01:32 -0800474 kfree(buffer.pointer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700475
Patrick Mocheld550d982006-06-27 00:41:40 -0400476 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700477}
478
479static int
Len Brown4be44fc2005-08-05 00:44:28 -0400480acpi_video_device_lcd_set_level(struct acpi_video_device *device, int level)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700481{
Alexey Starikovskiy4500ca82007-09-03 16:29:58 +0400482 int status = AE_OK;
Len Brown4be44fc2005-08-05 00:44:28 -0400483 union acpi_object arg0 = { ACPI_TYPE_INTEGER };
484 struct acpi_object_list args = { 1, &arg0 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700485
Linus Torvalds1da177e2005-04-16 15:20:36 -0700486
487 arg0.integer.value = level;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700488
Alexey Starikovskiy4500ca82007-09-03 16:29:58 +0400489 if (device->cap._BCM)
490 status = acpi_evaluate_object(device->dev->handle, "_BCM",
491 &args, NULL);
492 device->brightness->curr = level;
Patrick Mocheld550d982006-06-27 00:41:40 -0400493 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700494}
495
496static int
Len Brown4be44fc2005-08-05 00:44:28 -0400497acpi_video_device_lcd_get_level_current(struct acpi_video_device *device,
498 unsigned long *level)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700499{
Alexey Starikovskiy4500ca82007-09-03 16:29:58 +0400500 if (device->cap._BQC)
501 return acpi_evaluate_integer(device->dev->handle, "_BQC", NULL,
502 level);
503 *level = device->brightness->curr;
504 return AE_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700505}
506
507static int
Len Brown4be44fc2005-08-05 00:44:28 -0400508acpi_video_device_EDID(struct acpi_video_device *device,
509 union acpi_object **edid, ssize_t length)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700510{
Len Brown4be44fc2005-08-05 00:44:28 -0400511 int status;
512 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
513 union acpi_object *obj;
514 union acpi_object arg0 = { ACPI_TYPE_INTEGER };
515 struct acpi_object_list args = { 1, &arg0 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700516
Linus Torvalds1da177e2005-04-16 15:20:36 -0700517
518 *edid = NULL;
519
520 if (!device)
Patrick Mocheld550d982006-06-27 00:41:40 -0400521 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700522 if (length == 128)
523 arg0.integer.value = 1;
524 else if (length == 256)
525 arg0.integer.value = 2;
526 else
Patrick Mocheld550d982006-06-27 00:41:40 -0400527 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700528
Patrick Mochel90130262006-05-19 16:54:48 -0400529 status = acpi_evaluate_object(device->dev->handle, "_DDC", &args, &buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700530 if (ACPI_FAILURE(status))
Patrick Mocheld550d982006-06-27 00:41:40 -0400531 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700532
Jan Engelhardt50dd0962006-10-01 00:28:50 +0200533 obj = buffer.pointer;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700534
535 if (obj && obj->type == ACPI_TYPE_BUFFER)
536 *edid = obj;
537 else {
Len Brown64684632006-06-26 23:41:38 -0400538 printk(KERN_ERR PREFIX "Invalid _DDC data\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700539 status = -EFAULT;
540 kfree(obj);
541 }
542
Patrick Mocheld550d982006-06-27 00:41:40 -0400543 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700544}
545
Linus Torvalds1da177e2005-04-16 15:20:36 -0700546/* bus */
547
548static int
Len Brown4be44fc2005-08-05 00:44:28 -0400549acpi_video_bus_set_POST(struct acpi_video_bus *video, unsigned long option)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700550{
Len Brown4be44fc2005-08-05 00:44:28 -0400551 int status;
552 unsigned long tmp;
553 union acpi_object arg0 = { ACPI_TYPE_INTEGER };
554 struct acpi_object_list args = { 1, &arg0 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700555
Linus Torvalds1da177e2005-04-16 15:20:36 -0700556
557 arg0.integer.value = option;
558
Patrick Mochel90130262006-05-19 16:54:48 -0400559 status = acpi_evaluate_integer(video->device->handle, "_SPD", &args, &tmp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700560 if (ACPI_SUCCESS(status))
Len Brown4be44fc2005-08-05 00:44:28 -0400561 status = tmp ? (-EINVAL) : (AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700562
Patrick Mocheld550d982006-06-27 00:41:40 -0400563 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700564}
565
566static int
Len Brown4be44fc2005-08-05 00:44:28 -0400567acpi_video_bus_get_POST(struct acpi_video_bus *video, unsigned long *id)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700568{
569 int status;
570
Patrick Mochel90130262006-05-19 16:54:48 -0400571 status = acpi_evaluate_integer(video->device->handle, "_GPD", NULL, id);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700572
Patrick Mocheld550d982006-06-27 00:41:40 -0400573 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700574}
575
576static int
Len Brown4be44fc2005-08-05 00:44:28 -0400577acpi_video_bus_POST_options(struct acpi_video_bus *video,
578 unsigned long *options)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700579{
Len Brown4be44fc2005-08-05 00:44:28 -0400580 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700581
Patrick Mochel90130262006-05-19 16:54:48 -0400582 status = acpi_evaluate_integer(video->device->handle, "_VPO", NULL, options);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700583 *options &= 3;
584
Patrick Mocheld550d982006-06-27 00:41:40 -0400585 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700586}
587
588/*
589 * Arg:
590 * video : video bus device pointer
591 * bios_flag :
592 * 0. The system BIOS should NOT automatically switch(toggle)
593 * the active display output.
594 * 1. The system BIOS should automatically switch (toggle) the
Julius Volz98fb8fe2007-02-20 16:38:40 +0100595 * active display output. No switch event.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700596 * 2. The _DGS value should be locked.
597 * 3. The system BIOS should not automatically switch (toggle) the
598 * active display output, but instead generate the display switch
599 * event notify code.
600 * lcd_flag :
601 * 0. The system BIOS should automatically control the brightness level
Julius Volz98fb8fe2007-02-20 16:38:40 +0100602 * of the LCD when the power changes from AC to DC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700603 * 1. The system BIOS should NOT automatically control the brightness
Julius Volz98fb8fe2007-02-20 16:38:40 +0100604 * level of the LCD when the power changes from AC to DC.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700605 * Return Value:
606 * -1 wrong arg.
607 */
608
609static int
Len Brown4be44fc2005-08-05 00:44:28 -0400610acpi_video_bus_DOS(struct acpi_video_bus *video, int bios_flag, int lcd_flag)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700611{
Len Brown4be44fc2005-08-05 00:44:28 -0400612 acpi_integer status = 0;
613 union acpi_object arg0 = { ACPI_TYPE_INTEGER };
614 struct acpi_object_list args = { 1, &arg0 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700615
Linus Torvalds1da177e2005-04-16 15:20:36 -0700616
Len Brown4be44fc2005-08-05 00:44:28 -0400617 if (bios_flag < 0 || bios_flag > 3 || lcd_flag < 0 || lcd_flag > 1) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700618 status = -1;
619 goto Failed;
620 }
621 arg0.integer.value = (lcd_flag << 2) | bios_flag;
622 video->dos_setting = arg0.integer.value;
Patrick Mochel90130262006-05-19 16:54:48 -0400623 acpi_evaluate_object(video->device->handle, "_DOS", &args, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700624
Len Brown4be44fc2005-08-05 00:44:28 -0400625 Failed:
Patrick Mocheld550d982006-06-27 00:41:40 -0400626 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700627}
628
629/*
630 * Arg:
631 * device : video output device (LCD, CRT, ..)
632 *
633 * Return Value:
634 * None
635 *
Julius Volz98fb8fe2007-02-20 16:38:40 +0100636 * Find out all required AML methods defined under the output
Linus Torvalds1da177e2005-04-16 15:20:36 -0700637 * device.
638 */
639
Len Brown4be44fc2005-08-05 00:44:28 -0400640static void acpi_video_device_find_cap(struct acpi_video_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700641{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700642 acpi_handle h_dummy1;
643 int i;
Yu Luming2f3d0002006-11-11 02:40:34 +0800644 u32 max_level = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700645 union acpi_object *obj = NULL;
646 struct acpi_video_device_brightness *br = NULL;
647
Linus Torvalds1da177e2005-04-16 15:20:36 -0700648
William Lee Irwin III98934de2007-12-12 03:56:55 -0800649 memset(&device->cap, 0, sizeof(device->cap));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700650
Patrick Mochel90130262006-05-19 16:54:48 -0400651 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_ADR", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700652 device->cap._ADR = 1;
653 }
Patrick Mochel90130262006-05-19 16:54:48 -0400654 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_BCL", &h_dummy1))) {
Len Brown4be44fc2005-08-05 00:44:28 -0400655 device->cap._BCL = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700656 }
Patrick Mochel90130262006-05-19 16:54:48 -0400657 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_BCM", &h_dummy1))) {
Len Brown4be44fc2005-08-05 00:44:28 -0400658 device->cap._BCM = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700659 }
Yu Luming2f3d0002006-11-11 02:40:34 +0800660 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle,"_BQC",&h_dummy1)))
661 device->cap._BQC = 1;
Patrick Mochel90130262006-05-19 16:54:48 -0400662 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_DDC", &h_dummy1))) {
Len Brown4be44fc2005-08-05 00:44:28 -0400663 device->cap._DDC = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700664 }
Patrick Mochel90130262006-05-19 16:54:48 -0400665 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_DCS", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700666 device->cap._DCS = 1;
667 }
Patrick Mochel90130262006-05-19 16:54:48 -0400668 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_DGS", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700669 device->cap._DGS = 1;
670 }
Patrick Mochel90130262006-05-19 16:54:48 -0400671 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_DSS", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700672 device->cap._DSS = 1;
673 }
674
Danny Kukawkaf70ac0e2007-07-03 01:33:53 -0400675 if (ACPI_SUCCESS(acpi_video_device_lcd_query_levels(device, &obj))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700676
Danny Kukawkaf70ac0e2007-07-03 01:33:53 -0400677 if (obj->package.count >= 2) {
678 int count = 0;
679 union acpi_object *o;
Len Brown4be44fc2005-08-05 00:44:28 -0400680
Danny Kukawkaf70ac0e2007-07-03 01:33:53 -0400681 br = kzalloc(sizeof(*br), GFP_KERNEL);
682 if (!br) {
683 printk(KERN_ERR "can't allocate memory\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700684 } else {
Danny Kukawkaf70ac0e2007-07-03 01:33:53 -0400685 br->levels = kmalloc(obj->package.count *
686 sizeof *(br->levels), GFP_KERNEL);
687 if (!br->levels)
688 goto out;
689
690 for (i = 0; i < obj->package.count; i++) {
691 o = (union acpi_object *)&obj->package.
692 elements[i];
693 if (o->type != ACPI_TYPE_INTEGER) {
694 printk(KERN_ERR PREFIX "Invalid data\n");
695 continue;
696 }
697 br->levels[count] = (u32) o->integer.value;
698
699 if (br->levels[count] > max_level)
700 max_level = br->levels[count];
701 count++;
702 }
703 out:
704 if (count < 2) {
705 kfree(br->levels);
706 kfree(br);
707 } else {
708 br->count = count;
709 device->brightness = br;
710 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
711 "found %d brightness levels\n",
712 count));
713 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700714 }
715 }
Danny Kukawkaf70ac0e2007-07-03 01:33:53 -0400716
717 } else {
718 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Could not query available LCD brightness level\n"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700719 }
720
Paulo Marquesd1dd0c22005-03-30 22:39:49 -0500721 kfree(obj);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700722
Linus Torvalds797de7b2008-04-05 12:14:13 -0700723 if (device->cap._BCL && device->cap._BCM && device->cap._BQC && max_level > 0){
Zhang Rui702ed512008-01-17 15:51:22 +0800724 int result;
Yu Luming2f3d0002006-11-11 02:40:34 +0800725 static int count = 0;
726 char *name;
Yu Luming2f3d0002006-11-11 02:40:34 +0800727 name = kzalloc(MAX_NAME_LEN, GFP_KERNEL);
728 if (!name)
729 return;
730
Yu Luming2f3d0002006-11-11 02:40:34 +0800731 sprintf(name, "acpi_video%d", count++);
Yu Luming2f3d0002006-11-11 02:40:34 +0800732 device->backlight = backlight_device_register(name,
Richard Purdie599a52d2007-02-10 23:07:48 +0000733 NULL, device, &acpi_backlight_ops);
Matthew Garrett38531e62007-12-26 02:03:26 +0000734 device->backlight->props.max_brightness = device->brightness->count-3;
735 device->backlight->props.brightness = acpi_video_get_brightness(device->backlight);
Richard Purdie599a52d2007-02-10 23:07:48 +0000736 backlight_update_status(device->backlight);
Yu Luming2f3d0002006-11-11 02:40:34 +0800737 kfree(name);
Zhang Rui702ed512008-01-17 15:51:22 +0800738
739 device->cdev = thermal_cooling_device_register("LCD",
740 device->dev, &video_cooling_ops);
Thomas Sujith43ff39f2008-02-15 18:29:18 -0500741 if (IS_ERR(device->cdev))
742 return;
743
Julia Lawall90300622008-04-11 10:09:24 +0800744 printk(KERN_INFO PREFIX
745 "%s is registered as cooling_device%d\n",
746 device->dev->dev.bus_id, device->cdev->id);
747 result = sysfs_create_link(&device->dev->dev.kobj,
748 &device->cdev->device.kobj,
749 "thermal_cooling");
750 if (result)
751 printk(KERN_ERR PREFIX "Create sysfs link\n");
752 result = sysfs_create_link(&device->cdev->device.kobj,
753 &device->dev->dev.kobj, "device");
754 if (result)
755 printk(KERN_ERR PREFIX "Create sysfs link\n");
756
Yu Luming2f3d0002006-11-11 02:40:34 +0800757 }
Luming Yu23b0f012007-05-09 21:07:05 +0800758 if (device->cap._DCS && device->cap._DSS){
759 static int count = 0;
760 char *name;
761 name = kzalloc(MAX_NAME_LEN, GFP_KERNEL);
762 if (!name)
763 return;
764 sprintf(name, "acpi_video%d", count++);
765 device->output_dev = video_output_register(name,
766 NULL, device, &acpi_output_properties);
767 kfree(name);
768 }
Patrick Mocheld550d982006-06-27 00:41:40 -0400769 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700770}
771
772/*
773 * Arg:
774 * device : video output device (VGA)
775 *
776 * Return Value:
777 * None
778 *
Julius Volz98fb8fe2007-02-20 16:38:40 +0100779 * Find out all required AML methods defined under the video bus device.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700780 */
781
Len Brown4be44fc2005-08-05 00:44:28 -0400782static void acpi_video_bus_find_cap(struct acpi_video_bus *video)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700783{
Len Brown4be44fc2005-08-05 00:44:28 -0400784 acpi_handle h_dummy1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700785
William Lee Irwin III98934de2007-12-12 03:56:55 -0800786 memset(&video->cap, 0, sizeof(video->cap));
Patrick Mochel90130262006-05-19 16:54:48 -0400787 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_DOS", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700788 video->cap._DOS = 1;
789 }
Patrick Mochel90130262006-05-19 16:54:48 -0400790 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_DOD", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700791 video->cap._DOD = 1;
792 }
Patrick Mochel90130262006-05-19 16:54:48 -0400793 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_ROM", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700794 video->cap._ROM = 1;
795 }
Patrick Mochel90130262006-05-19 16:54:48 -0400796 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_GPD", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700797 video->cap._GPD = 1;
798 }
Patrick Mochel90130262006-05-19 16:54:48 -0400799 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_SPD", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700800 video->cap._SPD = 1;
801 }
Patrick Mochel90130262006-05-19 16:54:48 -0400802 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_VPO", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700803 video->cap._VPO = 1;
804 }
805}
806
807/*
808 * Check whether the video bus device has required AML method to
809 * support the desired features
810 */
811
Len Brown4be44fc2005-08-05 00:44:28 -0400812static int acpi_video_bus_check(struct acpi_video_bus *video)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700813{
Len Brown4be44fc2005-08-05 00:44:28 -0400814 acpi_status status = -ENOENT;
Len Brownf0d67522008-03-18 01:43:53 -0400815
Linus Torvalds1da177e2005-04-16 15:20:36 -0700816
817 if (!video)
Patrick Mocheld550d982006-06-27 00:41:40 -0400818 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700819
820 /* Since there is no HID, CID and so on for VGA driver, we have
821 * to check well known required nodes.
822 */
823
Julius Volz98fb8fe2007-02-20 16:38:40 +0100824 /* Does this device support video switching? */
Len Brown4be44fc2005-08-05 00:44:28 -0400825 if (video->cap._DOS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700826 video->flags.multihead = 1;
827 status = 0;
828 }
829
Julius Volz98fb8fe2007-02-20 16:38:40 +0100830 /* Does this device support retrieving a video ROM? */
Len Brown4be44fc2005-08-05 00:44:28 -0400831 if (video->cap._ROM) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700832 video->flags.rom = 1;
833 status = 0;
834 }
835
Julius Volz98fb8fe2007-02-20 16:38:40 +0100836 /* Does this device support configuring which video device to POST? */
Len Brown4be44fc2005-08-05 00:44:28 -0400837 if (video->cap._GPD && video->cap._SPD && video->cap._VPO) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700838 video->flags.post = 1;
839 status = 0;
840 }
841
Patrick Mocheld550d982006-06-27 00:41:40 -0400842 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700843}
844
845/* --------------------------------------------------------------------------
846 FS Interface (/proc)
847 -------------------------------------------------------------------------- */
848
Len Brown4be44fc2005-08-05 00:44:28 -0400849static struct proc_dir_entry *acpi_video_dir;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700850
851/* video devices */
852
Len Brown4be44fc2005-08-05 00:44:28 -0400853static int acpi_video_device_info_seq_show(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700854{
Jan Engelhardt50dd0962006-10-01 00:28:50 +0200855 struct acpi_video_device *dev = seq->private;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700856
Linus Torvalds1da177e2005-04-16 15:20:36 -0700857
858 if (!dev)
859 goto end;
860
861 seq_printf(seq, "device_id: 0x%04x\n", (u32) dev->device_id);
862 seq_printf(seq, "type: ");
863 if (dev->flags.crt)
864 seq_printf(seq, "CRT\n");
865 else if (dev->flags.lcd)
866 seq_printf(seq, "LCD\n");
867 else if (dev->flags.tvout)
868 seq_printf(seq, "TVOUT\n");
Rui Zhang82cae992007-01-03 23:40:53 -0500869 else if (dev->flags.dvi)
870 seq_printf(seq, "DVI\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700871 else
872 seq_printf(seq, "UNKNOWN\n");
873
Len Brown4be44fc2005-08-05 00:44:28 -0400874 seq_printf(seq, "known by bios: %s\n", dev->flags.bios ? "yes" : "no");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700875
Len Brown4be44fc2005-08-05 00:44:28 -0400876 end:
Patrick Mocheld550d982006-06-27 00:41:40 -0400877 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700878}
879
880static int
Len Brown4be44fc2005-08-05 00:44:28 -0400881acpi_video_device_info_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700882{
883 return single_open(file, acpi_video_device_info_seq_show,
884 PDE(inode)->data);
885}
886
Len Brown4be44fc2005-08-05 00:44:28 -0400887static int acpi_video_device_state_seq_show(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700888{
Len Brown4be44fc2005-08-05 00:44:28 -0400889 int status;
Jan Engelhardt50dd0962006-10-01 00:28:50 +0200890 struct acpi_video_device *dev = seq->private;
Len Brown4be44fc2005-08-05 00:44:28 -0400891 unsigned long state;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700892
Linus Torvalds1da177e2005-04-16 15:20:36 -0700893
894 if (!dev)
895 goto end;
896
897 status = acpi_video_device_get_state(dev, &state);
898 seq_printf(seq, "state: ");
899 if (ACPI_SUCCESS(status))
900 seq_printf(seq, "0x%02lx\n", state);
901 else
902 seq_printf(seq, "<not supported>\n");
903
904 status = acpi_video_device_query(dev, &state);
905 seq_printf(seq, "query: ");
906 if (ACPI_SUCCESS(status))
907 seq_printf(seq, "0x%02lx\n", state);
908 else
909 seq_printf(seq, "<not supported>\n");
910
Len Brown4be44fc2005-08-05 00:44:28 -0400911 end:
Patrick Mocheld550d982006-06-27 00:41:40 -0400912 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700913}
914
915static int
Len Brown4be44fc2005-08-05 00:44:28 -0400916acpi_video_device_state_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700917{
918 return single_open(file, acpi_video_device_state_seq_show,
919 PDE(inode)->data);
920}
921
922static ssize_t
Len Brown4be44fc2005-08-05 00:44:28 -0400923acpi_video_device_write_state(struct file *file,
924 const char __user * buffer,
925 size_t count, loff_t * data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700926{
Len Brown4be44fc2005-08-05 00:44:28 -0400927 int status;
Jan Engelhardt50dd0962006-10-01 00:28:50 +0200928 struct seq_file *m = file->private_data;
929 struct acpi_video_device *dev = m->private;
Len Brown4be44fc2005-08-05 00:44:28 -0400930 char str[12] = { 0 };
931 u32 state = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700932
Linus Torvalds1da177e2005-04-16 15:20:36 -0700933
934 if (!dev || count + 1 > sizeof str)
Patrick Mocheld550d982006-06-27 00:41:40 -0400935 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700936
937 if (copy_from_user(str, buffer, count))
Patrick Mocheld550d982006-06-27 00:41:40 -0400938 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700939
940 str[count] = 0;
941 state = simple_strtoul(str, NULL, 0);
Len Brown4be44fc2005-08-05 00:44:28 -0400942 state &= ((1ul << 31) | (1ul << 30) | (1ul << 0));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700943
944 status = acpi_video_device_set_state(dev, state);
945
946 if (status)
Patrick Mocheld550d982006-06-27 00:41:40 -0400947 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700948
Patrick Mocheld550d982006-06-27 00:41:40 -0400949 return count;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700950}
951
952static int
Len Brown4be44fc2005-08-05 00:44:28 -0400953acpi_video_device_brightness_seq_show(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700954{
Jan Engelhardt50dd0962006-10-01 00:28:50 +0200955 struct acpi_video_device *dev = seq->private;
Len Brown4be44fc2005-08-05 00:44:28 -0400956 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700957
Linus Torvalds1da177e2005-04-16 15:20:36 -0700958
959 if (!dev || !dev->brightness) {
960 seq_printf(seq, "<not supported>\n");
Patrick Mocheld550d982006-06-27 00:41:40 -0400961 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700962 }
963
964 seq_printf(seq, "levels: ");
965 for (i = 0; i < dev->brightness->count; i++)
966 seq_printf(seq, " %d", dev->brightness->levels[i]);
967 seq_printf(seq, "\ncurrent: %d\n", dev->brightness->curr);
968
Patrick Mocheld550d982006-06-27 00:41:40 -0400969 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700970}
971
972static int
Len Brown4be44fc2005-08-05 00:44:28 -0400973acpi_video_device_brightness_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700974{
975 return single_open(file, acpi_video_device_brightness_seq_show,
976 PDE(inode)->data);
977}
978
979static ssize_t
Len Brown4be44fc2005-08-05 00:44:28 -0400980acpi_video_device_write_brightness(struct file *file,
981 const char __user * buffer,
982 size_t count, loff_t * data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700983{
Jan Engelhardt50dd0962006-10-01 00:28:50 +0200984 struct seq_file *m = file->private_data;
985 struct acpi_video_device *dev = m->private;
Danny Baumannc88c5782007-11-02 13:47:53 +0100986 char str[5] = { 0 };
Len Brown4be44fc2005-08-05 00:44:28 -0400987 unsigned int level = 0;
988 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700989
Linus Torvalds1da177e2005-04-16 15:20:36 -0700990
Thomas Renninger59d399d2005-11-08 05:27:00 -0500991 if (!dev || !dev->brightness || count + 1 > sizeof str)
Patrick Mocheld550d982006-06-27 00:41:40 -0400992 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700993
994 if (copy_from_user(str, buffer, count))
Patrick Mocheld550d982006-06-27 00:41:40 -0400995 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700996
997 str[count] = 0;
998 level = simple_strtoul(str, NULL, 0);
Len Brown4be44fc2005-08-05 00:44:28 -0400999
Linus Torvalds1da177e2005-04-16 15:20:36 -07001000 if (level > 100)
Patrick Mocheld550d982006-06-27 00:41:40 -04001001 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001002
Julius Volz98fb8fe2007-02-20 16:38:40 +01001003 /* validate through the list of available levels */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001004 for (i = 0; i < dev->brightness->count; i++)
1005 if (level == dev->brightness->levels[i]) {
Len Brown4be44fc2005-08-05 00:44:28 -04001006 if (ACPI_SUCCESS
1007 (acpi_video_device_lcd_set_level(dev, level)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001008 dev->brightness->curr = level;
1009 break;
1010 }
1011
Patrick Mocheld550d982006-06-27 00:41:40 -04001012 return count;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001013}
1014
Len Brown4be44fc2005-08-05 00:44:28 -04001015static int acpi_video_device_EDID_seq_show(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001016{
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001017 struct acpi_video_device *dev = seq->private;
Len Brown4be44fc2005-08-05 00:44:28 -04001018 int status;
1019 int i;
1020 union acpi_object *edid = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001021
Linus Torvalds1da177e2005-04-16 15:20:36 -07001022
1023 if (!dev)
1024 goto out;
1025
Len Brown4be44fc2005-08-05 00:44:28 -04001026 status = acpi_video_device_EDID(dev, &edid, 128);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001027 if (ACPI_FAILURE(status)) {
Len Brown4be44fc2005-08-05 00:44:28 -04001028 status = acpi_video_device_EDID(dev, &edid, 256);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001029 }
1030
1031 if (ACPI_FAILURE(status)) {
1032 goto out;
1033 }
1034
1035 if (edid && edid->type == ACPI_TYPE_BUFFER) {
1036 for (i = 0; i < edid->buffer.length; i++)
1037 seq_putc(seq, edid->buffer.pointer[i]);
1038 }
1039
Len Brown4be44fc2005-08-05 00:44:28 -04001040 out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001041 if (!edid)
1042 seq_printf(seq, "<not supported>\n");
1043 else
1044 kfree(edid);
1045
Patrick Mocheld550d982006-06-27 00:41:40 -04001046 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001047}
1048
1049static int
Len Brown4be44fc2005-08-05 00:44:28 -04001050acpi_video_device_EDID_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001051{
1052 return single_open(file, acpi_video_device_EDID_seq_show,
1053 PDE(inode)->data);
1054}
1055
Len Brown4be44fc2005-08-05 00:44:28 -04001056static int acpi_video_device_add_fs(struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001057{
Dmitry Torokhov251cb0b2007-11-05 11:43:34 -05001058 struct proc_dir_entry *entry, *device_dir;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001059 struct acpi_video_device *vid_dev;
1060
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001061 vid_dev = acpi_driver_data(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001062 if (!vid_dev)
Patrick Mocheld550d982006-06-27 00:41:40 -04001063 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001064
Dmitry Torokhov251cb0b2007-11-05 11:43:34 -05001065 device_dir = proc_mkdir(acpi_device_bid(device),
1066 vid_dev->video->dir);
1067 if (!device_dir)
1068 return -ENOMEM;
1069
1070 device_dir->owner = THIS_MODULE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001071
1072 /* 'info' [R] */
Alexey Dobriyane0066c4e2008-05-01 04:10:02 +04001073 entry = proc_create_data("info", S_IRUGO, device_dir,
Denis V. Lunevcf7acfa2008-04-29 01:02:27 -07001074 &acpi_video_device_info_fops, acpi_driver_data(device));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001075 if (!entry)
Dmitry Torokhov251cb0b2007-11-05 11:43:34 -05001076 goto err_remove_dir;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001077
1078 /* 'state' [R/W] */
Denis V. Lunevcf7acfa2008-04-29 01:02:27 -07001079 acpi_video_device_state_fops.write = acpi_video_device_write_state;
1080 entry = proc_create_data("state", S_IFREG | S_IRUGO | S_IWUSR,
Alexey Dobriyane0066c4e2008-05-01 04:10:02 +04001081 device_dir,
Denis V. Lunevcf7acfa2008-04-29 01:02:27 -07001082 &acpi_video_device_state_fops,
1083 acpi_driver_data(device));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001084 if (!entry)
Dmitry Torokhov251cb0b2007-11-05 11:43:34 -05001085 goto err_remove_info;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001086
1087 /* 'brightness' [R/W] */
Denis V. Lunevcf7acfa2008-04-29 01:02:27 -07001088 acpi_video_device_brightness_fops.write =
1089 acpi_video_device_write_brightness;
1090 entry = proc_create_data("brightness", S_IFREG | S_IRUGO | S_IWUSR,
Alexey Dobriyane0066c4e2008-05-01 04:10:02 +04001091 device_dir,
Denis V. Lunevcf7acfa2008-04-29 01:02:27 -07001092 &acpi_video_device_brightness_fops,
1093 acpi_driver_data(device));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001094 if (!entry)
Dmitry Torokhov251cb0b2007-11-05 11:43:34 -05001095 goto err_remove_state;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001096
1097 /* 'EDID' [R] */
Alexey Dobriyane0066c4e2008-05-01 04:10:02 +04001098 entry = proc_create_data("EDID", S_IRUGO, device_dir,
Denis V. Lunevcf7acfa2008-04-29 01:02:27 -07001099 &acpi_video_device_EDID_fops,
1100 acpi_driver_data(device));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001101 if (!entry)
Dmitry Torokhov251cb0b2007-11-05 11:43:34 -05001102 goto err_remove_brightness;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001103
Alexey Dobriyane0066c4e2008-05-01 04:10:02 +04001104 acpi_device_dir(device) = device_dir;
1105
Patrick Mocheld550d982006-06-27 00:41:40 -04001106 return 0;
Dmitry Torokhov251cb0b2007-11-05 11:43:34 -05001107
1108 err_remove_brightness:
1109 remove_proc_entry("brightness", device_dir);
1110 err_remove_state:
1111 remove_proc_entry("state", device_dir);
1112 err_remove_info:
1113 remove_proc_entry("info", device_dir);
1114 err_remove_dir:
1115 remove_proc_entry(acpi_device_bid(device), vid_dev->video->dir);
1116 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001117}
1118
Len Brown4be44fc2005-08-05 00:44:28 -04001119static int acpi_video_device_remove_fs(struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001120{
1121 struct acpi_video_device *vid_dev;
Dmitry Torokhov251cb0b2007-11-05 11:43:34 -05001122 struct proc_dir_entry *device_dir;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001123
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001124 vid_dev = acpi_driver_data(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001125 if (!vid_dev || !vid_dev->video || !vid_dev->video->dir)
Patrick Mocheld550d982006-06-27 00:41:40 -04001126 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001127
Dmitry Torokhov251cb0b2007-11-05 11:43:34 -05001128 device_dir = acpi_device_dir(device);
1129 if (device_dir) {
1130 remove_proc_entry("info", device_dir);
1131 remove_proc_entry("state", device_dir);
1132 remove_proc_entry("brightness", device_dir);
1133 remove_proc_entry("EDID", device_dir);
Len Brown4be44fc2005-08-05 00:44:28 -04001134 remove_proc_entry(acpi_device_bid(device), vid_dev->video->dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001135 acpi_device_dir(device) = NULL;
1136 }
1137
Patrick Mocheld550d982006-06-27 00:41:40 -04001138 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001139}
1140
Linus Torvalds1da177e2005-04-16 15:20:36 -07001141/* video bus */
Len Brown4be44fc2005-08-05 00:44:28 -04001142static int acpi_video_bus_info_seq_show(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001143{
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001144 struct acpi_video_bus *video = seq->private;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001145
Linus Torvalds1da177e2005-04-16 15:20:36 -07001146
1147 if (!video)
1148 goto end;
1149
1150 seq_printf(seq, "Switching heads: %s\n",
Len Brown4be44fc2005-08-05 00:44:28 -04001151 video->flags.multihead ? "yes" : "no");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001152 seq_printf(seq, "Video ROM: %s\n",
Len Brown4be44fc2005-08-05 00:44:28 -04001153 video->flags.rom ? "yes" : "no");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001154 seq_printf(seq, "Device to be POSTed on boot: %s\n",
Len Brown4be44fc2005-08-05 00:44:28 -04001155 video->flags.post ? "yes" : "no");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001156
Len Brown4be44fc2005-08-05 00:44:28 -04001157 end:
Patrick Mocheld550d982006-06-27 00:41:40 -04001158 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001159}
1160
Len Brown4be44fc2005-08-05 00:44:28 -04001161static int acpi_video_bus_info_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001162{
Len Brown4be44fc2005-08-05 00:44:28 -04001163 return single_open(file, acpi_video_bus_info_seq_show,
1164 PDE(inode)->data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001165}
1166
Len Brown4be44fc2005-08-05 00:44:28 -04001167static int acpi_video_bus_ROM_seq_show(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001168{
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001169 struct acpi_video_bus *video = seq->private;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001170
Linus Torvalds1da177e2005-04-16 15:20:36 -07001171
1172 if (!video)
1173 goto end;
1174
Harvey Harrison96b2dd12008-03-05 18:24:51 -08001175 printk(KERN_INFO PREFIX "Please implement %s\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001176 seq_printf(seq, "<TODO>\n");
1177
Len Brown4be44fc2005-08-05 00:44:28 -04001178 end:
Patrick Mocheld550d982006-06-27 00:41:40 -04001179 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001180}
1181
Len Brown4be44fc2005-08-05 00:44:28 -04001182static int acpi_video_bus_ROM_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001183{
1184 return single_open(file, acpi_video_bus_ROM_seq_show, PDE(inode)->data);
1185}
1186
Len Brown4be44fc2005-08-05 00:44:28 -04001187static int acpi_video_bus_POST_info_seq_show(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001188{
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001189 struct acpi_video_bus *video = seq->private;
Len Brown4be44fc2005-08-05 00:44:28 -04001190 unsigned long options;
1191 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001192
Linus Torvalds1da177e2005-04-16 15:20:36 -07001193
1194 if (!video)
1195 goto end;
1196
1197 status = acpi_video_bus_POST_options(video, &options);
1198 if (ACPI_SUCCESS(status)) {
1199 if (!(options & 1)) {
Len Brown4be44fc2005-08-05 00:44:28 -04001200 printk(KERN_WARNING PREFIX
1201 "The motherboard VGA device is not listed as a possible POST device.\n");
1202 printk(KERN_WARNING PREFIX
Julius Volz98fb8fe2007-02-20 16:38:40 +01001203 "This indicates a BIOS bug. Please contact the manufacturer.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001204 }
1205 printk("%lx\n", options);
Julius Volz98fb8fe2007-02-20 16:38:40 +01001206 seq_printf(seq, "can POST: <integrated video>");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001207 if (options & 2)
1208 seq_printf(seq, " <PCI video>");
1209 if (options & 4)
1210 seq_printf(seq, " <AGP video>");
1211 seq_putc(seq, '\n');
1212 } else
1213 seq_printf(seq, "<not supported>\n");
Len Brown4be44fc2005-08-05 00:44:28 -04001214 end:
Patrick Mocheld550d982006-06-27 00:41:40 -04001215 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001216}
1217
1218static int
Len Brown4be44fc2005-08-05 00:44:28 -04001219acpi_video_bus_POST_info_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001220{
Len Brown4be44fc2005-08-05 00:44:28 -04001221 return single_open(file, acpi_video_bus_POST_info_seq_show,
1222 PDE(inode)->data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001223}
1224
Len Brown4be44fc2005-08-05 00:44:28 -04001225static int acpi_video_bus_POST_seq_show(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001226{
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001227 struct acpi_video_bus *video = seq->private;
Len Brown4be44fc2005-08-05 00:44:28 -04001228 int status;
1229 unsigned long id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001230
Linus Torvalds1da177e2005-04-16 15:20:36 -07001231
1232 if (!video)
1233 goto end;
1234
Len Brown4be44fc2005-08-05 00:44:28 -04001235 status = acpi_video_bus_get_POST(video, &id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001236 if (!ACPI_SUCCESS(status)) {
1237 seq_printf(seq, "<not supported>\n");
1238 goto end;
1239 }
Julius Volz98fb8fe2007-02-20 16:38:40 +01001240 seq_printf(seq, "device POSTed is <%s>\n", device_decode[id & 3]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001241
Len Brown4be44fc2005-08-05 00:44:28 -04001242 end:
Patrick Mocheld550d982006-06-27 00:41:40 -04001243 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001244}
1245
Len Brown4be44fc2005-08-05 00:44:28 -04001246static int acpi_video_bus_DOS_seq_show(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001247{
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001248 struct acpi_video_bus *video = seq->private;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001249
Linus Torvalds1da177e2005-04-16 15:20:36 -07001250
Len Brown4be44fc2005-08-05 00:44:28 -04001251 seq_printf(seq, "DOS setting: <%d>\n", video->dos_setting);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001252
Patrick Mocheld550d982006-06-27 00:41:40 -04001253 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001254}
1255
Len Brown4be44fc2005-08-05 00:44:28 -04001256static int acpi_video_bus_POST_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001257{
Len Brown4be44fc2005-08-05 00:44:28 -04001258 return single_open(file, acpi_video_bus_POST_seq_show,
1259 PDE(inode)->data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001260}
1261
Len Brown4be44fc2005-08-05 00:44:28 -04001262static int acpi_video_bus_DOS_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001263{
1264 return single_open(file, acpi_video_bus_DOS_seq_show, PDE(inode)->data);
1265}
1266
1267static ssize_t
Len Brown4be44fc2005-08-05 00:44:28 -04001268acpi_video_bus_write_POST(struct file *file,
1269 const char __user * buffer,
1270 size_t count, loff_t * data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001271{
Len Brown4be44fc2005-08-05 00:44:28 -04001272 int status;
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001273 struct seq_file *m = file->private_data;
1274 struct acpi_video_bus *video = m->private;
Len Brown4be44fc2005-08-05 00:44:28 -04001275 char str[12] = { 0 };
1276 unsigned long opt, options;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001277
Linus Torvalds1da177e2005-04-16 15:20:36 -07001278
Linus Torvalds1da177e2005-04-16 15:20:36 -07001279 if (!video || count + 1 > sizeof str)
Patrick Mocheld550d982006-06-27 00:41:40 -04001280 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001281
1282 status = acpi_video_bus_POST_options(video, &options);
1283 if (!ACPI_SUCCESS(status))
Patrick Mocheld550d982006-06-27 00:41:40 -04001284 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001285
1286 if (copy_from_user(str, buffer, count))
Patrick Mocheld550d982006-06-27 00:41:40 -04001287 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001288
1289 str[count] = 0;
1290 opt = strtoul(str, NULL, 0);
1291 if (opt > 3)
Patrick Mocheld550d982006-06-27 00:41:40 -04001292 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001293
Julius Volz98fb8fe2007-02-20 16:38:40 +01001294 /* just in case an OEM 'forgot' the motherboard... */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001295 options |= 1;
1296
1297 if (options & (1ul << opt)) {
Len Brown4be44fc2005-08-05 00:44:28 -04001298 status = acpi_video_bus_set_POST(video, opt);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001299 if (!ACPI_SUCCESS(status))
Patrick Mocheld550d982006-06-27 00:41:40 -04001300 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001301
1302 }
1303
Patrick Mocheld550d982006-06-27 00:41:40 -04001304 return count;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001305}
1306
1307static ssize_t
Len Brown4be44fc2005-08-05 00:44:28 -04001308acpi_video_bus_write_DOS(struct file *file,
1309 const char __user * buffer,
1310 size_t count, loff_t * data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001311{
Len Brown4be44fc2005-08-05 00:44:28 -04001312 int status;
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001313 struct seq_file *m = file->private_data;
1314 struct acpi_video_bus *video = m->private;
Len Brown4be44fc2005-08-05 00:44:28 -04001315 char str[12] = { 0 };
1316 unsigned long opt;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001317
Linus Torvalds1da177e2005-04-16 15:20:36 -07001318
Linus Torvalds1da177e2005-04-16 15:20:36 -07001319 if (!video || count + 1 > sizeof str)
Patrick Mocheld550d982006-06-27 00:41:40 -04001320 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001321
1322 if (copy_from_user(str, buffer, count))
Patrick Mocheld550d982006-06-27 00:41:40 -04001323 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001324
1325 str[count] = 0;
1326 opt = strtoul(str, NULL, 0);
1327 if (opt > 7)
Patrick Mocheld550d982006-06-27 00:41:40 -04001328 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001329
Len Brown4be44fc2005-08-05 00:44:28 -04001330 status = acpi_video_bus_DOS(video, opt & 0x3, (opt & 0x4) >> 2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001331
1332 if (!ACPI_SUCCESS(status))
Patrick Mocheld550d982006-06-27 00:41:40 -04001333 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001334
Patrick Mocheld550d982006-06-27 00:41:40 -04001335 return count;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001336}
1337
Len Brown4be44fc2005-08-05 00:44:28 -04001338static int acpi_video_bus_add_fs(struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001339{
Dmitry Torokhov251cb0b2007-11-05 11:43:34 -05001340 struct acpi_video_bus *video = acpi_driver_data(device);
1341 struct proc_dir_entry *device_dir;
1342 struct proc_dir_entry *entry;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001343
Dmitry Torokhov251cb0b2007-11-05 11:43:34 -05001344 device_dir = proc_mkdir(acpi_device_bid(device), acpi_video_dir);
1345 if (!device_dir)
1346 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001347
Dmitry Torokhov251cb0b2007-11-05 11:43:34 -05001348 device_dir->owner = THIS_MODULE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001349
1350 /* 'info' [R] */
Alexey Dobriyane0066c4e2008-05-01 04:10:02 +04001351 entry = proc_create_data("info", S_IRUGO, device_dir,
Denis V. Lunevcf7acfa2008-04-29 01:02:27 -07001352 &acpi_video_bus_info_fops,
1353 acpi_driver_data(device));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001354 if (!entry)
Dmitry Torokhov251cb0b2007-11-05 11:43:34 -05001355 goto err_remove_dir;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001356
1357 /* 'ROM' [R] */
Alexey Dobriyane0066c4e2008-05-01 04:10:02 +04001358 entry = proc_create_data("ROM", S_IRUGO, device_dir,
Denis V. Lunevcf7acfa2008-04-29 01:02:27 -07001359 &acpi_video_bus_ROM_fops,
1360 acpi_driver_data(device));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001361 if (!entry)
Dmitry Torokhov251cb0b2007-11-05 11:43:34 -05001362 goto err_remove_info;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001363
1364 /* 'POST_info' [R] */
Alexey Dobriyane0066c4e2008-05-01 04:10:02 +04001365 entry = proc_create_data("POST_info", S_IRUGO, device_dir,
Denis V. Lunevcf7acfa2008-04-29 01:02:27 -07001366 &acpi_video_bus_POST_info_fops,
1367 acpi_driver_data(device));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001368 if (!entry)
Dmitry Torokhov251cb0b2007-11-05 11:43:34 -05001369 goto err_remove_rom;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001370
1371 /* 'POST' [R/W] */
Denis V. Lunevcf7acfa2008-04-29 01:02:27 -07001372 acpi_video_bus_POST_fops.write = acpi_video_bus_write_POST;
Linus Torvalds08acd4f82008-04-30 11:52:52 -07001373 entry = proc_create_data("POST", S_IFREG | S_IRUGO | S_IWUSR,
Alexey Dobriyane0066c4e2008-05-01 04:10:02 +04001374 device_dir,
Denis V. Lunevcf7acfa2008-04-29 01:02:27 -07001375 &acpi_video_bus_POST_fops,
1376 acpi_driver_data(device));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001377 if (!entry)
Dmitry Torokhov251cb0b2007-11-05 11:43:34 -05001378 goto err_remove_post_info;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001379
1380 /* 'DOS' [R/W] */
Denis V. Lunevcf7acfa2008-04-29 01:02:27 -07001381 acpi_video_bus_DOS_fops.write = acpi_video_bus_write_DOS;
Linus Torvalds08acd4f82008-04-30 11:52:52 -07001382 entry = proc_create_data("DOS", S_IFREG | S_IRUGO | S_IWUSR,
Alexey Dobriyane0066c4e2008-05-01 04:10:02 +04001383 device_dir,
Denis V. Lunevcf7acfa2008-04-29 01:02:27 -07001384 &acpi_video_bus_DOS_fops,
1385 acpi_driver_data(device));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001386 if (!entry)
Dmitry Torokhov251cb0b2007-11-05 11:43:34 -05001387 goto err_remove_post;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001388
Dmitry Torokhov251cb0b2007-11-05 11:43:34 -05001389 video->dir = acpi_device_dir(device) = device_dir;
Patrick Mocheld550d982006-06-27 00:41:40 -04001390 return 0;
Dmitry Torokhov251cb0b2007-11-05 11:43:34 -05001391
1392 err_remove_post:
1393 remove_proc_entry("POST", device_dir);
1394 err_remove_post_info:
1395 remove_proc_entry("POST_info", device_dir);
1396 err_remove_rom:
1397 remove_proc_entry("ROM", device_dir);
1398 err_remove_info:
1399 remove_proc_entry("info", device_dir);
1400 err_remove_dir:
1401 remove_proc_entry(acpi_device_bid(device), acpi_video_dir);
1402 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001403}
1404
Len Brown4be44fc2005-08-05 00:44:28 -04001405static int acpi_video_bus_remove_fs(struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001406{
Dmitry Torokhov251cb0b2007-11-05 11:43:34 -05001407 struct proc_dir_entry *device_dir = acpi_device_dir(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001408
Dmitry Torokhov251cb0b2007-11-05 11:43:34 -05001409 if (device_dir) {
1410 remove_proc_entry("info", device_dir);
1411 remove_proc_entry("ROM", device_dir);
1412 remove_proc_entry("POST_info", device_dir);
1413 remove_proc_entry("POST", device_dir);
1414 remove_proc_entry("DOS", device_dir);
Len Brown4be44fc2005-08-05 00:44:28 -04001415 remove_proc_entry(acpi_device_bid(device), acpi_video_dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001416 acpi_device_dir(device) = NULL;
1417 }
1418
Patrick Mocheld550d982006-06-27 00:41:40 -04001419 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001420}
1421
1422/* --------------------------------------------------------------------------
1423 Driver Interface
1424 -------------------------------------------------------------------------- */
1425
1426/* device interface */
Rui Zhang82cae992007-01-03 23:40:53 -05001427static struct acpi_video_device_attrib*
1428acpi_video_get_device_attr(struct acpi_video_bus *video, unsigned long device_id)
1429{
Dmitry Torokhov78eed022007-11-05 11:43:33 -05001430 struct acpi_video_enumerated_device *ids;
1431 int i;
Rui Zhang82cae992007-01-03 23:40:53 -05001432
Dmitry Torokhov78eed022007-11-05 11:43:33 -05001433 for (i = 0; i < video->attached_count; i++) {
1434 ids = &video->attached_array[i];
1435 if ((ids->value.int_val & 0xffff) == device_id)
1436 return &ids->value.attrib;
1437 }
1438
Rui Zhang82cae992007-01-03 23:40:53 -05001439 return NULL;
1440}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001441
1442static int
Len Brown4be44fc2005-08-05 00:44:28 -04001443acpi_video_bus_get_one_device(struct acpi_device *device,
1444 struct acpi_video_bus *video)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001445{
Len Brown4be44fc2005-08-05 00:44:28 -04001446 unsigned long device_id;
Yu, Luming973bf492006-04-27 05:25:00 -04001447 int status;
Len Brown4be44fc2005-08-05 00:44:28 -04001448 struct acpi_video_device *data;
Rui Zhang82cae992007-01-03 23:40:53 -05001449 struct acpi_video_device_attrib* attribute;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001450
1451 if (!device || !video)
Patrick Mocheld550d982006-06-27 00:41:40 -04001452 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001453
Len Brown4be44fc2005-08-05 00:44:28 -04001454 status =
1455 acpi_evaluate_integer(device->handle, "_ADR", NULL, &device_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001456 if (ACPI_SUCCESS(status)) {
1457
Burman Yan36bcbec2006-12-19 12:56:11 -08001458 data = kzalloc(sizeof(struct acpi_video_device), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001459 if (!data)
Patrick Mocheld550d982006-06-27 00:41:40 -04001460 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001461
Linus Torvalds1da177e2005-04-16 15:20:36 -07001462 strcpy(acpi_device_name(device), ACPI_VIDEO_DEVICE_NAME);
1463 strcpy(acpi_device_class(device), ACPI_VIDEO_CLASS);
1464 acpi_driver_data(device) = data;
1465
1466 data->device_id = device_id;
1467 data->video = video;
1468 data->dev = device;
1469
Rui Zhang82cae992007-01-03 23:40:53 -05001470 attribute = acpi_video_get_device_attr(video, device_id);
1471
1472 if((attribute != NULL) && attribute->device_id_scheme) {
1473 switch (attribute->display_type) {
1474 case ACPI_VIDEO_DISPLAY_CRT:
1475 data->flags.crt = 1;
1476 break;
1477 case ACPI_VIDEO_DISPLAY_TV:
1478 data->flags.tvout = 1;
1479 break;
1480 case ACPI_VIDEO_DISPLAY_DVI:
1481 data->flags.dvi = 1;
1482 break;
1483 case ACPI_VIDEO_DISPLAY_LCD:
1484 data->flags.lcd = 1;
1485 break;
1486 default:
1487 data->flags.unknown = 1;
1488 break;
1489 }
1490 if(attribute->bios_can_detect)
1491 data->flags.bios = 1;
1492 } else
Linus Torvalds1da177e2005-04-16 15:20:36 -07001493 data->flags.unknown = 1;
Len Brown4be44fc2005-08-05 00:44:28 -04001494
Linus Torvalds1da177e2005-04-16 15:20:36 -07001495 acpi_video_device_bind(video, data);
1496 acpi_video_device_find_cap(data);
1497
Patrick Mochel90130262006-05-19 16:54:48 -04001498 status = acpi_install_notify_handler(device->handle,
Len Brown4be44fc2005-08-05 00:44:28 -04001499 ACPI_DEVICE_NOTIFY,
1500 acpi_video_device_notify,
1501 data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001502 if (ACPI_FAILURE(status)) {
1503 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
Len Brown4be44fc2005-08-05 00:44:28 -04001504 "Error installing notify handler\n"));
Yu, Luming973bf492006-04-27 05:25:00 -04001505 if(data->brightness)
1506 kfree(data->brightness->levels);
1507 kfree(data->brightness);
1508 kfree(data);
1509 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001510 }
1511
Dmitry Torokhovbbac81f2007-11-05 11:43:32 -05001512 mutex_lock(&video->device_list_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001513 list_add_tail(&data->entry, &video->video_device_list);
Dmitry Torokhovbbac81f2007-11-05 11:43:32 -05001514 mutex_unlock(&video->device_list_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001515
1516 acpi_video_device_add_fs(device);
1517
Patrick Mocheld550d982006-06-27 00:41:40 -04001518 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001519 }
1520
Patrick Mocheld550d982006-06-27 00:41:40 -04001521 return -ENOENT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001522}
1523
1524/*
1525 * Arg:
1526 * video : video bus device
1527 *
1528 * Return:
1529 * none
1530 *
1531 * Enumerate the video device list of the video bus,
1532 * bind the ids with the corresponding video devices
1533 * under the video bus.
Len Brown4be44fc2005-08-05 00:44:28 -04001534 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001535
Len Brown4be44fc2005-08-05 00:44:28 -04001536static void acpi_video_device_rebind(struct acpi_video_bus *video)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001537{
Dmitry Torokhovff102ea2007-11-05 11:43:31 -05001538 struct acpi_video_device *dev;
1539
Dmitry Torokhovbbac81f2007-11-05 11:43:32 -05001540 mutex_lock(&video->device_list_lock);
Dmitry Torokhovff102ea2007-11-05 11:43:31 -05001541
1542 list_for_each_entry(dev, &video->video_device_list, entry)
Len Brown4be44fc2005-08-05 00:44:28 -04001543 acpi_video_device_bind(video, dev);
Dmitry Torokhovff102ea2007-11-05 11:43:31 -05001544
Dmitry Torokhovbbac81f2007-11-05 11:43:32 -05001545 mutex_unlock(&video->device_list_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001546}
1547
1548/*
1549 * Arg:
1550 * video : video bus device
1551 * device : video output device under the video
1552 * bus
1553 *
1554 * Return:
1555 * none
1556 *
1557 * Bind the ids with the corresponding video devices
1558 * under the video bus.
Len Brown4be44fc2005-08-05 00:44:28 -04001559 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001560
1561static void
Len Brown4be44fc2005-08-05 00:44:28 -04001562acpi_video_device_bind(struct acpi_video_bus *video,
1563 struct acpi_video_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001564{
Dmitry Torokhov78eed022007-11-05 11:43:33 -05001565 struct acpi_video_enumerated_device *ids;
Len Brown4be44fc2005-08-05 00:44:28 -04001566 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001567
Dmitry Torokhov78eed022007-11-05 11:43:33 -05001568 for (i = 0; i < video->attached_count; i++) {
1569 ids = &video->attached_array[i];
1570 if (device->device_id == (ids->value.int_val & 0xffff)) {
1571 ids->bind_info = device;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001572 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "device_bind %d\n", i));
1573 }
1574 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001575}
1576
1577/*
1578 * Arg:
1579 * video : video bus device
1580 *
1581 * Return:
1582 * < 0 : error
1583 *
1584 * Call _DOD to enumerate all devices attached to display adapter
1585 *
Len Brown4be44fc2005-08-05 00:44:28 -04001586 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001587
1588static int acpi_video_device_enumerate(struct acpi_video_bus *video)
1589{
Len Brown4be44fc2005-08-05 00:44:28 -04001590 int status;
1591 int count;
1592 int i;
Dmitry Torokhov78eed022007-11-05 11:43:33 -05001593 struct acpi_video_enumerated_device *active_list;
Len Brown4be44fc2005-08-05 00:44:28 -04001594 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
1595 union acpi_object *dod = NULL;
1596 union acpi_object *obj;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001597
Patrick Mochel90130262006-05-19 16:54:48 -04001598 status = acpi_evaluate_object(video->device->handle, "_DOD", NULL, &buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001599 if (!ACPI_SUCCESS(status)) {
Thomas Renningera6fc6722006-06-26 23:58:43 -04001600 ACPI_EXCEPTION((AE_INFO, status, "Evaluating _DOD"));
Patrick Mocheld550d982006-06-27 00:41:40 -04001601 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001602 }
1603
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001604 dod = buffer.pointer;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001605 if (!dod || (dod->type != ACPI_TYPE_PACKAGE)) {
Thomas Renningera6fc6722006-06-26 23:58:43 -04001606 ACPI_EXCEPTION((AE_INFO, status, "Invalid _DOD data"));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001607 status = -EFAULT;
1608 goto out;
1609 }
1610
1611 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found %d video heads in _DOD\n",
Len Brown4be44fc2005-08-05 00:44:28 -04001612 dod->package.count));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001613
Dmitry Torokhov78eed022007-11-05 11:43:33 -05001614 active_list = kcalloc(1 + dod->package.count,
1615 sizeof(struct acpi_video_enumerated_device),
1616 GFP_KERNEL);
1617 if (!active_list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001618 status = -ENOMEM;
1619 goto out;
1620 }
1621
1622 count = 0;
1623 for (i = 0; i < dod->package.count; i++) {
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001624 obj = &dod->package.elements[i];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001625
1626 if (obj->type != ACPI_TYPE_INTEGER) {
Dmitry Torokhov78eed022007-11-05 11:43:33 -05001627 printk(KERN_ERR PREFIX
1628 "Invalid _DOD data in element %d\n", i);
1629 continue;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001630 }
Dmitry Torokhov78eed022007-11-05 11:43:33 -05001631
1632 active_list[count].value.int_val = obj->integer.value;
1633 active_list[count].bind_info = NULL;
Len Brown4be44fc2005-08-05 00:44:28 -04001634 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "dod element[%d] = %d\n", i,
1635 (int)obj->integer.value));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001636 count++;
1637 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001638
Jesper Juhl6044ec82005-11-07 01:01:32 -08001639 kfree(video->attached_array);
Len Brown4be44fc2005-08-05 00:44:28 -04001640
Dmitry Torokhov78eed022007-11-05 11:43:33 -05001641 video->attached_array = active_list;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001642 video->attached_count = count;
Dmitry Torokhov78eed022007-11-05 11:43:33 -05001643
1644 out:
Len Brown02438d82006-06-30 03:19:10 -04001645 kfree(buffer.pointer);
Patrick Mocheld550d982006-06-27 00:41:40 -04001646 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001647}
1648
Len Brown4be44fc2005-08-05 00:44:28 -04001649static int
1650acpi_video_get_next_level(struct acpi_video_device *device,
1651 u32 level_current, u32 event)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001652{
Alexey Starikovskiy63f0edf2007-09-03 16:30:08 +04001653 int min, max, min_above, max_below, i, l, delta = 255;
Thomas Tuttlef4715182006-12-19 12:56:14 -08001654 max = max_below = 0;
1655 min = min_above = 255;
Alexey Starikovskiy63f0edf2007-09-03 16:30:08 +04001656 /* Find closest level to level_current */
1657 for (i = 0; i < device->brightness->count; i++) {
1658 l = device->brightness->levels[i];
1659 if (abs(l - level_current) < abs(delta)) {
1660 delta = l - level_current;
1661 if (!delta)
1662 break;
1663 }
1664 }
1665 /* Ajust level_current to closest available level */
1666 level_current += delta;
Thomas Tuttlef4715182006-12-19 12:56:14 -08001667 for (i = 0; i < device->brightness->count; i++) {
1668 l = device->brightness->levels[i];
1669 if (l < min)
1670 min = l;
1671 if (l > max)
1672 max = l;
1673 if (l < min_above && l > level_current)
1674 min_above = l;
1675 if (l > max_below && l < level_current)
1676 max_below = l;
1677 }
1678
1679 switch (event) {
1680 case ACPI_VIDEO_NOTIFY_CYCLE_BRIGHTNESS:
1681 return (level_current < max) ? min_above : min;
1682 case ACPI_VIDEO_NOTIFY_INC_BRIGHTNESS:
1683 return (level_current < max) ? min_above : max;
1684 case ACPI_VIDEO_NOTIFY_DEC_BRIGHTNESS:
1685 return (level_current > min) ? max_below : min;
1686 case ACPI_VIDEO_NOTIFY_ZERO_BRIGHTNESS:
1687 case ACPI_VIDEO_NOTIFY_DISPLAY_OFF:
1688 return 0;
1689 default:
1690 return level_current;
1691 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001692}
1693
Linus Torvalds1da177e2005-04-16 15:20:36 -07001694static void
Len Brown4be44fc2005-08-05 00:44:28 -04001695acpi_video_switch_brightness(struct acpi_video_device *device, int event)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001696{
1697 unsigned long level_current, level_next;
1698 acpi_video_device_lcd_get_level_current(device, &level_current);
1699 level_next = acpi_video_get_next_level(device, level_current, event);
1700 acpi_video_device_lcd_set_level(device, level_next);
1701}
1702
1703static int
Len Brown4be44fc2005-08-05 00:44:28 -04001704acpi_video_bus_get_devices(struct acpi_video_bus *video,
1705 struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001706{
Len Brown4be44fc2005-08-05 00:44:28 -04001707 int status = 0;
Dmitry Torokhovff102ea2007-11-05 11:43:31 -05001708 struct acpi_device *dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001709
1710 acpi_video_device_enumerate(video);
1711
Dmitry Torokhovff102ea2007-11-05 11:43:31 -05001712 list_for_each_entry(dev, &device->children, node) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001713
1714 status = acpi_video_bus_get_one_device(dev, video);
1715 if (ACPI_FAILURE(status)) {
Thomas Renningera6fc6722006-06-26 23:58:43 -04001716 ACPI_EXCEPTION((AE_INFO, status, "Cant attach device"));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001717 continue;
1718 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001719 }
Patrick Mocheld550d982006-06-27 00:41:40 -04001720 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001721}
1722
Len Brown4be44fc2005-08-05 00:44:28 -04001723static int acpi_video_bus_put_one_device(struct acpi_video_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001724{
Karol Kozimor031ec772005-07-30 04:18:00 -04001725 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001726 struct acpi_video_bus *video;
1727
Linus Torvalds1da177e2005-04-16 15:20:36 -07001728
1729 if (!device || !device->video)
Patrick Mocheld550d982006-06-27 00:41:40 -04001730 return -ENOENT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001731
1732 video = device->video;
1733
Linus Torvalds1da177e2005-04-16 15:20:36 -07001734 acpi_video_device_remove_fs(device->dev);
1735
Patrick Mochel90130262006-05-19 16:54:48 -04001736 status = acpi_remove_notify_handler(device->dev->handle,
Len Brown4be44fc2005-08-05 00:44:28 -04001737 ACPI_DEVICE_NOTIFY,
1738 acpi_video_device_notify);
Richard Purdie599a52d2007-02-10 23:07:48 +00001739 backlight_device_unregister(device->backlight);
Zhang Rui702ed512008-01-17 15:51:22 +08001740 if (device->cdev) {
1741 sysfs_remove_link(&device->dev->dev.kobj,
1742 "thermal_cooling");
1743 sysfs_remove_link(&device->cdev->device.kobj,
1744 "device");
1745 thermal_cooling_device_unregister(device->cdev);
1746 device->cdev = NULL;
1747 }
Luming Yu23b0f012007-05-09 21:07:05 +08001748 video_output_unregister(device->output_dev);
Dmitry Torokhovff102ea2007-11-05 11:43:31 -05001749
Patrick Mocheld550d982006-06-27 00:41:40 -04001750 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001751}
1752
Len Brown4be44fc2005-08-05 00:44:28 -04001753static int acpi_video_bus_put_devices(struct acpi_video_bus *video)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001754{
Len Brown4be44fc2005-08-05 00:44:28 -04001755 int status;
Dmitry Torokhovff102ea2007-11-05 11:43:31 -05001756 struct acpi_video_device *dev, *next;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001757
Dmitry Torokhovbbac81f2007-11-05 11:43:32 -05001758 mutex_lock(&video->device_list_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001759
Dmitry Torokhovff102ea2007-11-05 11:43:31 -05001760 list_for_each_entry_safe(dev, next, &video->video_device_list, entry) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001761
Dmitry Torokhovff102ea2007-11-05 11:43:31 -05001762 status = acpi_video_bus_put_one_device(dev);
Len Brown4be44fc2005-08-05 00:44:28 -04001763 if (ACPI_FAILURE(status))
1764 printk(KERN_WARNING PREFIX
1765 "hhuuhhuu bug in acpi video driver.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001766
Dmitry Torokhovff102ea2007-11-05 11:43:31 -05001767 if (dev->brightness) {
1768 kfree(dev->brightness->levels);
1769 kfree(dev->brightness);
1770 }
1771 list_del(&dev->entry);
1772 kfree(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001773 }
1774
Dmitry Torokhovbbac81f2007-11-05 11:43:32 -05001775 mutex_unlock(&video->device_list_lock);
Dmitry Torokhovff102ea2007-11-05 11:43:31 -05001776
Patrick Mocheld550d982006-06-27 00:41:40 -04001777 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001778}
1779
1780/* acpi_video interface */
1781
Len Brown4be44fc2005-08-05 00:44:28 -04001782static int acpi_video_bus_start_devices(struct acpi_video_bus *video)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001783{
Zhang Ruia21101c2007-09-14 11:46:22 +08001784 return acpi_video_bus_DOS(video, 0, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001785}
1786
Len Brown4be44fc2005-08-05 00:44:28 -04001787static int acpi_video_bus_stop_devices(struct acpi_video_bus *video)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001788{
1789 return acpi_video_bus_DOS(video, 0, 1);
1790}
1791
Len Brown4be44fc2005-08-05 00:44:28 -04001792static void acpi_video_bus_notify(acpi_handle handle, u32 event, void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001793{
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001794 struct acpi_video_bus *video = data;
Len Brown4be44fc2005-08-05 00:44:28 -04001795 struct acpi_device *device = NULL;
Luming Yue9dab192007-08-20 18:23:53 +08001796 struct input_dev *input;
1797 int keycode;
1798
Linus Torvalds1da177e2005-04-16 15:20:36 -07001799 if (!video)
Patrick Mocheld550d982006-06-27 00:41:40 -04001800 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001801
Patrick Mochele6afa0d2006-05-19 16:54:40 -04001802 device = video->device;
Luming Yue9dab192007-08-20 18:23:53 +08001803 input = video->input;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001804
1805 switch (event) {
Julius Volz98fb8fe2007-02-20 16:38:40 +01001806 case ACPI_VIDEO_NOTIFY_SWITCH: /* User requested a switch,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001807 * most likely via hotkey. */
Len Brown14e04fb2007-08-23 15:20:26 -04001808 acpi_bus_generate_proc_event(device, event, 0);
Luming Yue9dab192007-08-20 18:23:53 +08001809 keycode = KEY_SWITCHVIDEOMODE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001810 break;
1811
Julius Volz98fb8fe2007-02-20 16:38:40 +01001812 case ACPI_VIDEO_NOTIFY_PROBE: /* User plugged in or removed a video
Linus Torvalds1da177e2005-04-16 15:20:36 -07001813 * connector. */
1814 acpi_video_device_enumerate(video);
1815 acpi_video_device_rebind(video);
Len Brown14e04fb2007-08-23 15:20:26 -04001816 acpi_bus_generate_proc_event(device, event, 0);
Luming Yue9dab192007-08-20 18:23:53 +08001817 keycode = KEY_SWITCHVIDEOMODE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001818 break;
1819
Len Brown4be44fc2005-08-05 00:44:28 -04001820 case ACPI_VIDEO_NOTIFY_CYCLE: /* Cycle Display output hotkey pressed. */
Len Brown25c87f72007-08-25 01:44:01 -04001821 acpi_bus_generate_proc_event(device, event, 0);
Luming Yue9dab192007-08-20 18:23:53 +08001822 keycode = KEY_SWITCHVIDEOMODE;
1823 break;
Len Brown4be44fc2005-08-05 00:44:28 -04001824 case ACPI_VIDEO_NOTIFY_NEXT_OUTPUT: /* Next Display output hotkey pressed. */
Len Brown25c87f72007-08-25 01:44:01 -04001825 acpi_bus_generate_proc_event(device, event, 0);
Luming Yue9dab192007-08-20 18:23:53 +08001826 keycode = KEY_VIDEO_NEXT;
1827 break;
Len Brown4be44fc2005-08-05 00:44:28 -04001828 case ACPI_VIDEO_NOTIFY_PREV_OUTPUT: /* previous Display output hotkey pressed. */
Len Brown14e04fb2007-08-23 15:20:26 -04001829 acpi_bus_generate_proc_event(device, event, 0);
Luming Yue9dab192007-08-20 18:23:53 +08001830 keycode = KEY_VIDEO_PREV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001831 break;
1832
1833 default:
Luming Yue9dab192007-08-20 18:23:53 +08001834 keycode = KEY_UNKNOWN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001835 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
Len Brown4be44fc2005-08-05 00:44:28 -04001836 "Unsupported event [0x%x]\n", event));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001837 break;
1838 }
1839
Zhang Rui7761f632008-01-25 14:48:12 +08001840 acpi_notifier_call_chain(device, event, 0);
Luming Yue9dab192007-08-20 18:23:53 +08001841 input_report_key(input, keycode, 1);
1842 input_sync(input);
1843 input_report_key(input, keycode, 0);
1844 input_sync(input);
1845
Patrick Mocheld550d982006-06-27 00:41:40 -04001846 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001847}
1848
Len Brown4be44fc2005-08-05 00:44:28 -04001849static void acpi_video_device_notify(acpi_handle handle, u32 event, void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001850{
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001851 struct acpi_video_device *video_device = data;
Len Brown4be44fc2005-08-05 00:44:28 -04001852 struct acpi_device *device = NULL;
Luming Yue9dab192007-08-20 18:23:53 +08001853 struct acpi_video_bus *bus;
1854 struct input_dev *input;
1855 int keycode;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001856
Linus Torvalds1da177e2005-04-16 15:20:36 -07001857 if (!video_device)
Patrick Mocheld550d982006-06-27 00:41:40 -04001858 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001859
Patrick Mochele6afa0d2006-05-19 16:54:40 -04001860 device = video_device->dev;
Luming Yue9dab192007-08-20 18:23:53 +08001861 bus = video_device->video;
1862 input = bus->input;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001863
1864 switch (event) {
Len Brown4be44fc2005-08-05 00:44:28 -04001865 case ACPI_VIDEO_NOTIFY_CYCLE_BRIGHTNESS: /* Cycle brightness */
Zhang Rui8a681a42008-01-25 14:47:49 +08001866 if (brightness_switch_enabled)
1867 acpi_video_switch_brightness(video_device, event);
Len Brown25c87f72007-08-25 01:44:01 -04001868 acpi_bus_generate_proc_event(device, event, 0);
Luming Yue9dab192007-08-20 18:23:53 +08001869 keycode = KEY_BRIGHTNESS_CYCLE;
1870 break;
Len Brown4be44fc2005-08-05 00:44:28 -04001871 case ACPI_VIDEO_NOTIFY_INC_BRIGHTNESS: /* Increase brightness */
Zhang Rui8a681a42008-01-25 14:47:49 +08001872 if (brightness_switch_enabled)
1873 acpi_video_switch_brightness(video_device, event);
Len Brown25c87f72007-08-25 01:44:01 -04001874 acpi_bus_generate_proc_event(device, event, 0);
Luming Yue9dab192007-08-20 18:23:53 +08001875 keycode = KEY_BRIGHTNESSUP;
1876 break;
Len Brown4be44fc2005-08-05 00:44:28 -04001877 case ACPI_VIDEO_NOTIFY_DEC_BRIGHTNESS: /* Decrease brightness */
Zhang Rui8a681a42008-01-25 14:47:49 +08001878 if (brightness_switch_enabled)
1879 acpi_video_switch_brightness(video_device, event);
Len Brown25c87f72007-08-25 01:44:01 -04001880 acpi_bus_generate_proc_event(device, event, 0);
Luming Yue9dab192007-08-20 18:23:53 +08001881 keycode = KEY_BRIGHTNESSDOWN;
1882 break;
Len Brown4be44fc2005-08-05 00:44:28 -04001883 case ACPI_VIDEO_NOTIFY_ZERO_BRIGHTNESS: /* zero brightnesss */
Zhang Rui8a681a42008-01-25 14:47:49 +08001884 if (brightness_switch_enabled)
1885 acpi_video_switch_brightness(video_device, event);
Len Brown25c87f72007-08-25 01:44:01 -04001886 acpi_bus_generate_proc_event(device, event, 0);
Luming Yue9dab192007-08-20 18:23:53 +08001887 keycode = KEY_BRIGHTNESS_ZERO;
1888 break;
Len Brown4be44fc2005-08-05 00:44:28 -04001889 case ACPI_VIDEO_NOTIFY_DISPLAY_OFF: /* display device off */
Zhang Rui8a681a42008-01-25 14:47:49 +08001890 if (brightness_switch_enabled)
1891 acpi_video_switch_brightness(video_device, event);
Len Brown14e04fb2007-08-23 15:20:26 -04001892 acpi_bus_generate_proc_event(device, event, 0);
Luming Yue9dab192007-08-20 18:23:53 +08001893 keycode = KEY_DISPLAY_OFF;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001894 break;
1895 default:
Luming Yue9dab192007-08-20 18:23:53 +08001896 keycode = KEY_UNKNOWN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001897 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
Len Brown4be44fc2005-08-05 00:44:28 -04001898 "Unsupported event [0x%x]\n", event));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001899 break;
1900 }
Luming Yue9dab192007-08-20 18:23:53 +08001901
Zhang Rui7761f632008-01-25 14:48:12 +08001902 acpi_notifier_call_chain(device, event, 0);
Luming Yue9dab192007-08-20 18:23:53 +08001903 input_report_key(input, keycode, 1);
1904 input_sync(input);
1905 input_report_key(input, keycode, 0);
1906 input_sync(input);
1907
Patrick Mocheld550d982006-06-27 00:41:40 -04001908 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001909}
1910
Zhang Ruie6d9da12007-08-25 02:23:31 -04001911static int instance;
Matthew Garrett863c1492008-02-04 23:31:24 -08001912static int acpi_video_resume(struct acpi_device *device)
1913{
1914 struct acpi_video_bus *video;
1915 struct acpi_video_device *video_device;
1916 int i;
1917
1918 if (!device || !acpi_driver_data(device))
1919 return -EINVAL;
1920
1921 video = acpi_driver_data(device);
1922
1923 for (i = 0; i < video->attached_count; i++) {
1924 video_device = video->attached_array[i].bind_info;
1925 if (video_device && video_device->backlight)
1926 acpi_video_set_brightness(video_device->backlight);
1927 }
1928 return AE_OK;
1929}
1930
Len Brown4be44fc2005-08-05 00:44:28 -04001931static int acpi_video_bus_add(struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001932{
Dmitry Torokhovf51e8392007-11-05 11:43:30 -05001933 acpi_status status;
1934 struct acpi_video_bus *video;
Luming Yue9dab192007-08-20 18:23:53 +08001935 struct input_dev *input;
Dmitry Torokhovf51e8392007-11-05 11:43:30 -05001936 int error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001937
Burman Yan36bcbec2006-12-19 12:56:11 -08001938 video = kzalloc(sizeof(struct acpi_video_bus), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001939 if (!video)
Patrick Mocheld550d982006-06-27 00:41:40 -04001940 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001941
Zhang Ruie6d9da12007-08-25 02:23:31 -04001942 /* a hack to fix the duplicate name "VID" problem on T61 */
1943 if (!strcmp(device->pnp.bus_id, "VID")) {
1944 if (instance)
1945 device->pnp.bus_id[3] = '0' + instance;
1946 instance ++;
1947 }
1948
Patrick Mochele6afa0d2006-05-19 16:54:40 -04001949 video->device = device;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001950 strcpy(acpi_device_name(device), ACPI_VIDEO_BUS_NAME);
1951 strcpy(acpi_device_class(device), ACPI_VIDEO_CLASS);
1952 acpi_driver_data(device) = video;
1953
1954 acpi_video_bus_find_cap(video);
Dmitry Torokhovf51e8392007-11-05 11:43:30 -05001955 error = acpi_video_bus_check(video);
1956 if (error)
1957 goto err_free_video;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001958
Dmitry Torokhovf51e8392007-11-05 11:43:30 -05001959 error = acpi_video_bus_add_fs(device);
1960 if (error)
1961 goto err_free_video;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001962
Dmitry Torokhovbbac81f2007-11-05 11:43:32 -05001963 mutex_init(&video->device_list_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001964 INIT_LIST_HEAD(&video->video_device_list);
1965
1966 acpi_video_bus_get_devices(video, device);
1967 acpi_video_bus_start_devices(video);
1968
Patrick Mochel90130262006-05-19 16:54:48 -04001969 status = acpi_install_notify_handler(device->handle,
Len Brown4be44fc2005-08-05 00:44:28 -04001970 ACPI_DEVICE_NOTIFY,
1971 acpi_video_bus_notify, video);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001972 if (ACPI_FAILURE(status)) {
1973 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
Len Brown4be44fc2005-08-05 00:44:28 -04001974 "Error installing notify handler\n"));
Dmitry Torokhovf51e8392007-11-05 11:43:30 -05001975 error = -ENODEV;
1976 goto err_stop_video;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001977 }
1978
Luming Yue9dab192007-08-20 18:23:53 +08001979 video->input = input = input_allocate_device();
Dmitry Torokhovf51e8392007-11-05 11:43:30 -05001980 if (!input) {
1981 error = -ENOMEM;
1982 goto err_uninstall_notify;
1983 }
Luming Yue9dab192007-08-20 18:23:53 +08001984
1985 snprintf(video->phys, sizeof(video->phys),
1986 "%s/video/input0", acpi_device_hid(video->device));
1987
1988 input->name = acpi_device_name(video->device);
1989 input->phys = video->phys;
1990 input->id.bustype = BUS_HOST;
1991 input->id.product = 0x06;
Dmitry Torokhov91c05c62007-11-05 11:43:29 -05001992 input->dev.parent = &device->dev;
Luming Yue9dab192007-08-20 18:23:53 +08001993 input->evbit[0] = BIT(EV_KEY);
1994 set_bit(KEY_SWITCHVIDEOMODE, input->keybit);
1995 set_bit(KEY_VIDEO_NEXT, input->keybit);
1996 set_bit(KEY_VIDEO_PREV, input->keybit);
1997 set_bit(KEY_BRIGHTNESS_CYCLE, input->keybit);
1998 set_bit(KEY_BRIGHTNESSUP, input->keybit);
1999 set_bit(KEY_BRIGHTNESSDOWN, input->keybit);
2000 set_bit(KEY_BRIGHTNESS_ZERO, input->keybit);
2001 set_bit(KEY_DISPLAY_OFF, input->keybit);
2002 set_bit(KEY_UNKNOWN, input->keybit);
Luming Yue9dab192007-08-20 18:23:53 +08002003
Dmitry Torokhovf51e8392007-11-05 11:43:30 -05002004 error = input_register_device(input);
2005 if (error)
2006 goto err_free_input_dev;
Luming Yue9dab192007-08-20 18:23:53 +08002007
Linus Torvalds1da177e2005-04-16 15:20:36 -07002008 printk(KERN_INFO PREFIX "%s [%s] (multi-head: %s rom: %s post: %s)\n",
Len Brown4be44fc2005-08-05 00:44:28 -04002009 ACPI_VIDEO_DEVICE_NAME, acpi_device_bid(device),
2010 video->flags.multihead ? "yes" : "no",
2011 video->flags.rom ? "yes" : "no",
2012 video->flags.post ? "yes" : "no");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002013
Dmitry Torokhovf51e8392007-11-05 11:43:30 -05002014 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002015
Dmitry Torokhovf51e8392007-11-05 11:43:30 -05002016 err_free_input_dev:
2017 input_free_device(input);
2018 err_uninstall_notify:
2019 acpi_remove_notify_handler(device->handle, ACPI_DEVICE_NOTIFY,
2020 acpi_video_bus_notify);
2021 err_stop_video:
2022 acpi_video_bus_stop_devices(video);
2023 acpi_video_bus_put_devices(video);
2024 kfree(video->attached_array);
2025 acpi_video_bus_remove_fs(device);
2026 err_free_video:
2027 kfree(video);
2028 acpi_driver_data(device) = NULL;
2029
2030 return error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002031}
2032
Len Brown4be44fc2005-08-05 00:44:28 -04002033static int acpi_video_bus_remove(struct acpi_device *device, int type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002034{
Len Brown4be44fc2005-08-05 00:44:28 -04002035 acpi_status status = 0;
2036 struct acpi_video_bus *video = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002037
Linus Torvalds1da177e2005-04-16 15:20:36 -07002038
2039 if (!device || !acpi_driver_data(device))
Patrick Mocheld550d982006-06-27 00:41:40 -04002040 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002041
Jan Engelhardt50dd0962006-10-01 00:28:50 +02002042 video = acpi_driver_data(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002043
2044 acpi_video_bus_stop_devices(video);
2045
Patrick Mochel90130262006-05-19 16:54:48 -04002046 status = acpi_remove_notify_handler(video->device->handle,
Len Brown4be44fc2005-08-05 00:44:28 -04002047 ACPI_DEVICE_NOTIFY,
2048 acpi_video_bus_notify);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002049
2050 acpi_video_bus_put_devices(video);
2051 acpi_video_bus_remove_fs(device);
2052
Luming Yue9dab192007-08-20 18:23:53 +08002053 input_unregister_device(video->input);
Jesper Juhl6044ec82005-11-07 01:01:32 -08002054 kfree(video->attached_array);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002055 kfree(video);
2056
Patrick Mocheld550d982006-06-27 00:41:40 -04002057 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002058}
2059
Len Brown4be44fc2005-08-05 00:44:28 -04002060static int __init acpi_video_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002061{
Len Brown4be44fc2005-08-05 00:44:28 -04002062 int result = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002063
Linus Torvalds1da177e2005-04-16 15:20:36 -07002064
2065 /*
Len Brown4be44fc2005-08-05 00:44:28 -04002066 acpi_dbg_level = 0xFFFFFFFF;
2067 acpi_dbg_layer = 0x08000000;
2068 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002069
2070 acpi_video_dir = proc_mkdir(ACPI_VIDEO_CLASS, acpi_root_dir);
2071 if (!acpi_video_dir)
Patrick Mocheld550d982006-06-27 00:41:40 -04002072 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002073 acpi_video_dir->owner = THIS_MODULE;
2074
2075 result = acpi_bus_register_driver(&acpi_video_bus);
2076 if (result < 0) {
2077 remove_proc_entry(ACPI_VIDEO_CLASS, acpi_root_dir);
Patrick Mocheld550d982006-06-27 00:41:40 -04002078 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002079 }
2080
Patrick Mocheld550d982006-06-27 00:41:40 -04002081 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002082}
2083
Len Brown4be44fc2005-08-05 00:44:28 -04002084static void __exit acpi_video_exit(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002085{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002086
2087 acpi_bus_unregister_driver(&acpi_video_bus);
2088
2089 remove_proc_entry(ACPI_VIDEO_CLASS, acpi_root_dir);
2090
Patrick Mocheld550d982006-06-27 00:41:40 -04002091 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002092}
2093
2094module_init(acpi_video_init);
2095module_exit(acpi_video_exit);