blob: 67cc36dc9b82fe94b7430628076191e3a6246894 [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>
Zhang Rui935e5f22008-12-11 16:24:52 -050039#include <linux/sort.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070040#include <asm/uaccess.h>
41
42#include <acpi/acpi_bus.h>
43#include <acpi/acpi_drivers.h>
44
Linus Torvalds1da177e2005-04-16 15:20:36 -070045#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 Brownc2b6705b2007-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,
Matthew Wilcox27663c52008-10-10 02:22:59 -0400294 unsigned long 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,
Matthew Wilcox27663c52008-10-10 02:22:59 -0400300 unsigned long long *state);
Luming Yu23b0f012007-05-09 21:07:05 +0800301static 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{
Matthew Wilcox27663c52008-10-10 02:22:59 -0400307 unsigned long 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{
Matthew Wilcox27663c52008-10-10 02:22:59 -0400339 unsigned long long state;
Luming Yu23b0f012007-05-09 21:07:05 +0800340 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);
Matthew Wilcox27663c52008-10-10 02:22:59 -0400373 unsigned long long level;
Zhang Rui702ed512008-01-17 15:51:22 +0800374 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
Matthew Wilcox27663c52008-10-10 02:22:59 -0400413acpi_video_device_query(struct acpi_video_device *device, unsigned long 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,
Matthew Wilcox27663c52008-10-10 02:22:59 -0400424 unsigned long 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 };
Matthew Wilcox27663c52008-10-10 02:22:59 -0400439 unsigned long 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 };
Zhang Rui9e6dada2008-12-31 10:58:48 +0800485 int state;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700486
Linus Torvalds1da177e2005-04-16 15:20:36 -0700487
488 arg0.integer.value = level;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700489
Alexey Starikovskiy4500ca82007-09-03 16:29:58 +0400490 if (device->cap._BCM)
491 status = acpi_evaluate_object(device->dev->handle, "_BCM",
492 &args, NULL);
493 device->brightness->curr = level;
Zhang Rui9e6dada2008-12-31 10:58:48 +0800494 for (state = 2; state < device->brightness->count; state++)
495 if (level == device->brightness->levels[state])
496 device->backlight->props.brightness = state - 2;
497
Patrick Mocheld550d982006-06-27 00:41:40 -0400498 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700499}
500
501static int
Len Brown4be44fc2005-08-05 00:44:28 -0400502acpi_video_device_lcd_get_level_current(struct acpi_video_device *device,
Matthew Wilcox27663c52008-10-10 02:22:59 -0400503 unsigned long long *level)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700504{
Alexey Starikovskiy4500ca82007-09-03 16:29:58 +0400505 if (device->cap._BQC)
506 return acpi_evaluate_integer(device->dev->handle, "_BQC", NULL,
507 level);
508 *level = device->brightness->curr;
509 return AE_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700510}
511
512static int
Len Brown4be44fc2005-08-05 00:44:28 -0400513acpi_video_device_EDID(struct acpi_video_device *device,
514 union acpi_object **edid, ssize_t length)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700515{
Len Brown4be44fc2005-08-05 00:44:28 -0400516 int status;
517 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
518 union acpi_object *obj;
519 union acpi_object arg0 = { ACPI_TYPE_INTEGER };
520 struct acpi_object_list args = { 1, &arg0 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700521
Linus Torvalds1da177e2005-04-16 15:20:36 -0700522
523 *edid = NULL;
524
525 if (!device)
Patrick Mocheld550d982006-06-27 00:41:40 -0400526 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700527 if (length == 128)
528 arg0.integer.value = 1;
529 else if (length == 256)
530 arg0.integer.value = 2;
531 else
Patrick Mocheld550d982006-06-27 00:41:40 -0400532 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700533
Patrick Mochel90130262006-05-19 16:54:48 -0400534 status = acpi_evaluate_object(device->dev->handle, "_DDC", &args, &buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700535 if (ACPI_FAILURE(status))
Patrick Mocheld550d982006-06-27 00:41:40 -0400536 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700537
Jan Engelhardt50dd0962006-10-01 00:28:50 +0200538 obj = buffer.pointer;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700539
540 if (obj && obj->type == ACPI_TYPE_BUFFER)
541 *edid = obj;
542 else {
Len Brown64684632006-06-26 23:41:38 -0400543 printk(KERN_ERR PREFIX "Invalid _DDC data\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700544 status = -EFAULT;
545 kfree(obj);
546 }
547
Patrick Mocheld550d982006-06-27 00:41:40 -0400548 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700549}
550
Linus Torvalds1da177e2005-04-16 15:20:36 -0700551/* bus */
552
553static int
Len Brown4be44fc2005-08-05 00:44:28 -0400554acpi_video_bus_set_POST(struct acpi_video_bus *video, unsigned long option)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700555{
Len Brown4be44fc2005-08-05 00:44:28 -0400556 int status;
Matthew Wilcox27663c52008-10-10 02:22:59 -0400557 unsigned long long tmp;
Len Brown4be44fc2005-08-05 00:44:28 -0400558 union acpi_object arg0 = { ACPI_TYPE_INTEGER };
559 struct acpi_object_list args = { 1, &arg0 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700560
Linus Torvalds1da177e2005-04-16 15:20:36 -0700561
562 arg0.integer.value = option;
563
Patrick Mochel90130262006-05-19 16:54:48 -0400564 status = acpi_evaluate_integer(video->device->handle, "_SPD", &args, &tmp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700565 if (ACPI_SUCCESS(status))
Len Brown4be44fc2005-08-05 00:44:28 -0400566 status = tmp ? (-EINVAL) : (AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700567
Patrick Mocheld550d982006-06-27 00:41:40 -0400568 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700569}
570
571static int
Matthew Wilcox27663c52008-10-10 02:22:59 -0400572acpi_video_bus_get_POST(struct acpi_video_bus *video, unsigned long long *id)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700573{
574 int status;
575
Patrick Mochel90130262006-05-19 16:54:48 -0400576 status = acpi_evaluate_integer(video->device->handle, "_GPD", NULL, id);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700577
Patrick Mocheld550d982006-06-27 00:41:40 -0400578 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700579}
580
581static int
Len Brown4be44fc2005-08-05 00:44:28 -0400582acpi_video_bus_POST_options(struct acpi_video_bus *video,
Matthew Wilcox27663c52008-10-10 02:22:59 -0400583 unsigned long long *options)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700584{
Len Brown4be44fc2005-08-05 00:44:28 -0400585 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700586
Patrick Mochel90130262006-05-19 16:54:48 -0400587 status = acpi_evaluate_integer(video->device->handle, "_VPO", NULL, options);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700588 *options &= 3;
589
Patrick Mocheld550d982006-06-27 00:41:40 -0400590 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700591}
592
593/*
594 * Arg:
595 * video : video bus device pointer
596 * bios_flag :
597 * 0. The system BIOS should NOT automatically switch(toggle)
598 * the active display output.
599 * 1. The system BIOS should automatically switch (toggle) the
Julius Volz98fb8fe2007-02-20 16:38:40 +0100600 * active display output. No switch event.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700601 * 2. The _DGS value should be locked.
602 * 3. The system BIOS should not automatically switch (toggle) the
603 * active display output, but instead generate the display switch
604 * event notify code.
605 * lcd_flag :
606 * 0. The system BIOS should automatically control the brightness level
Julius Volz98fb8fe2007-02-20 16:38:40 +0100607 * of the LCD when the power changes from AC to DC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700608 * 1. The system BIOS should NOT automatically control the brightness
Julius Volz98fb8fe2007-02-20 16:38:40 +0100609 * level of the LCD when the power changes from AC to DC.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700610 * Return Value:
611 * -1 wrong arg.
612 */
613
614static int
Len Brown4be44fc2005-08-05 00:44:28 -0400615acpi_video_bus_DOS(struct acpi_video_bus *video, int bios_flag, int lcd_flag)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700616{
Len Brown4be44fc2005-08-05 00:44:28 -0400617 acpi_integer status = 0;
618 union acpi_object arg0 = { ACPI_TYPE_INTEGER };
619 struct acpi_object_list args = { 1, &arg0 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700620
Linus Torvalds1da177e2005-04-16 15:20:36 -0700621
Len Brown4be44fc2005-08-05 00:44:28 -0400622 if (bios_flag < 0 || bios_flag > 3 || lcd_flag < 0 || lcd_flag > 1) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700623 status = -1;
624 goto Failed;
625 }
626 arg0.integer.value = (lcd_flag << 2) | bios_flag;
627 video->dos_setting = arg0.integer.value;
Patrick Mochel90130262006-05-19 16:54:48 -0400628 acpi_evaluate_object(video->device->handle, "_DOS", &args, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700629
Len Brown4be44fc2005-08-05 00:44:28 -0400630 Failed:
Patrick Mocheld550d982006-06-27 00:41:40 -0400631 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700632}
633
634/*
Zhang Rui935e5f22008-12-11 16:24:52 -0500635 * Simple comparison function used to sort backlight levels.
636 */
637
638static int
639acpi_video_cmp_level(const void *a, const void *b)
640{
641 return *(int *)a - *(int *)b;
642}
643
644/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700645 * Arg:
646 * device : video output device (LCD, CRT, ..)
647 *
648 * Return Value:
Julia Jomantaite469778c2008-06-23 22:50:42 +0100649 * Maximum brightness level
650 *
651 * Allocate and initialize device->brightness.
652 */
653
654static int
655acpi_video_init_brightness(struct acpi_video_device *device)
656{
657 union acpi_object *obj = NULL;
658 int i, max_level = 0, count = 0;
659 union acpi_object *o;
660 struct acpi_video_device_brightness *br = NULL;
661
662 if (!ACPI_SUCCESS(acpi_video_device_lcd_query_levels(device, &obj))) {
663 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Could not query available "
664 "LCD brightness level\n"));
665 goto out;
666 }
667
668 if (obj->package.count < 2)
669 goto out;
670
671 br = kzalloc(sizeof(*br), GFP_KERNEL);
672 if (!br) {
673 printk(KERN_ERR "can't allocate memory\n");
674 goto out;
675 }
676
677 br->levels = kmalloc(obj->package.count * sizeof *(br->levels),
678 GFP_KERNEL);
679 if (!br->levels)
680 goto out_free;
681
682 for (i = 0; i < obj->package.count; i++) {
683 o = (union acpi_object *)&obj->package.elements[i];
684 if (o->type != ACPI_TYPE_INTEGER) {
685 printk(KERN_ERR PREFIX "Invalid data\n");
686 continue;
687 }
688 br->levels[count] = (u32) o->integer.value;
689
690 if (br->levels[count] > max_level)
691 max_level = br->levels[count];
692 count++;
693 }
694
Zhang Rui935e5f22008-12-11 16:24:52 -0500695 /* don't sort the first two brightness levels */
696 sort(&br->levels[2], count - 2, sizeof(br->levels[2]),
697 acpi_video_cmp_level, NULL);
698
Julia Jomantaite469778c2008-06-23 22:50:42 +0100699 if (count < 2)
700 goto out_free_levels;
701
702 br->count = count;
703 device->brightness = br;
704 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "found %d brightness levels\n", count));
705 kfree(obj);
706 return max_level;
707
708out_free_levels:
709 kfree(br->levels);
710out_free:
711 kfree(br);
712out:
713 device->brightness = NULL;
714 kfree(obj);
715 return 0;
716}
717
718/*
719 * Arg:
720 * device : video output device (LCD, CRT, ..)
721 *
722 * Return Value:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700723 * None
724 *
Julius Volz98fb8fe2007-02-20 16:38:40 +0100725 * Find out all required AML methods defined under the output
Linus Torvalds1da177e2005-04-16 15:20:36 -0700726 * device.
727 */
728
Len Brown4be44fc2005-08-05 00:44:28 -0400729static void acpi_video_device_find_cap(struct acpi_video_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700730{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700731 acpi_handle h_dummy1;
Yu Luming2f3d0002006-11-11 02:40:34 +0800732 u32 max_level = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700733
Linus Torvalds1da177e2005-04-16 15:20:36 -0700734
William Lee Irwin III98934de2007-12-12 03:56:55 -0800735 memset(&device->cap, 0, sizeof(device->cap));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700736
Patrick Mochel90130262006-05-19 16:54:48 -0400737 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_ADR", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700738 device->cap._ADR = 1;
739 }
Patrick Mochel90130262006-05-19 16:54:48 -0400740 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_BCL", &h_dummy1))) {
Len Brown4be44fc2005-08-05 00:44:28 -0400741 device->cap._BCL = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700742 }
Patrick Mochel90130262006-05-19 16:54:48 -0400743 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_BCM", &h_dummy1))) {
Len Brown4be44fc2005-08-05 00:44:28 -0400744 device->cap._BCM = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700745 }
Yu Luming2f3d0002006-11-11 02:40:34 +0800746 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle,"_BQC",&h_dummy1)))
747 device->cap._BQC = 1;
Patrick Mochel90130262006-05-19 16:54:48 -0400748 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_DDC", &h_dummy1))) {
Len Brown4be44fc2005-08-05 00:44:28 -0400749 device->cap._DDC = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700750 }
Patrick Mochel90130262006-05-19 16:54:48 -0400751 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_DCS", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700752 device->cap._DCS = 1;
753 }
Patrick Mochel90130262006-05-19 16:54:48 -0400754 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_DGS", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700755 device->cap._DGS = 1;
756 }
Patrick Mochel90130262006-05-19 16:54:48 -0400757 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_DSS", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700758 device->cap._DSS = 1;
759 }
760
Thomas Renningerc3d6de62008-08-01 17:37:55 +0200761 if (acpi_video_backlight_support())
762 max_level = acpi_video_init_brightness(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700763
Zhao Yakuic2c78902008-07-17 10:46:05 +0800764 if (device->cap._BCL && device->cap._BCM && max_level > 0) {
Zhang Rui702ed512008-01-17 15:51:22 +0800765 int result;
Yu Luming2f3d0002006-11-11 02:40:34 +0800766 static int count = 0;
767 char *name;
Yu Luming2f3d0002006-11-11 02:40:34 +0800768 name = kzalloc(MAX_NAME_LEN, GFP_KERNEL);
769 if (!name)
770 return;
771
Yu Luming2f3d0002006-11-11 02:40:34 +0800772 sprintf(name, "acpi_video%d", count++);
Yu Luming2f3d0002006-11-11 02:40:34 +0800773 device->backlight = backlight_device_register(name,
Richard Purdie599a52d2007-02-10 23:07:48 +0000774 NULL, device, &acpi_backlight_ops);
Matthew Garrett38531e62007-12-26 02:03:26 +0000775 device->backlight->props.max_brightness = device->brightness->count-3;
Zhao Yakuic2c78902008-07-17 10:46:05 +0800776 /*
777 * If there exists the _BQC object, the _BQC object will be
778 * called to get the current backlight brightness. Otherwise
779 * the brightness will be set to the maximum.
780 */
781 if (device->cap._BQC)
782 device->backlight->props.brightness =
783 acpi_video_get_brightness(device->backlight);
784 else
785 device->backlight->props.brightness =
786 device->backlight->props.max_brightness;
Richard Purdie599a52d2007-02-10 23:07:48 +0000787 backlight_update_status(device->backlight);
Yu Luming2f3d0002006-11-11 02:40:34 +0800788 kfree(name);
Zhang Rui702ed512008-01-17 15:51:22 +0800789
790 device->cdev = thermal_cooling_device_register("LCD",
791 device->dev, &video_cooling_ops);
Thomas Sujith43ff39f2008-02-15 18:29:18 -0500792 if (IS_ERR(device->cdev))
793 return;
794
Greg Kroah-Hartmanfc3a8822008-05-02 06:02:41 +0200795 dev_info(&device->dev->dev, "registered as cooling_device%d\n",
796 device->cdev->id);
Julia Lawall90300622008-04-11 10:09:24 +0800797 result = sysfs_create_link(&device->dev->dev.kobj,
798 &device->cdev->device.kobj,
799 "thermal_cooling");
800 if (result)
801 printk(KERN_ERR PREFIX "Create sysfs link\n");
802 result = sysfs_create_link(&device->cdev->device.kobj,
803 &device->dev->dev.kobj, "device");
804 if (result)
805 printk(KERN_ERR PREFIX "Create sysfs link\n");
806
Yu Luming2f3d0002006-11-11 02:40:34 +0800807 }
Thomas Renningerc3d6de62008-08-01 17:37:55 +0200808
809 if (acpi_video_display_switch_support()) {
810
811 if (device->cap._DCS && device->cap._DSS) {
812 static int count;
813 char *name;
814 name = kzalloc(MAX_NAME_LEN, GFP_KERNEL);
815 if (!name)
816 return;
817 sprintf(name, "acpi_video%d", count++);
818 device->output_dev = video_output_register(name,
819 NULL, device, &acpi_output_properties);
820 kfree(name);
821 }
Luming Yu23b0f012007-05-09 21:07:05 +0800822 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700823}
824
825/*
826 * Arg:
827 * device : video output device (VGA)
828 *
829 * Return Value:
830 * None
831 *
Julius Volz98fb8fe2007-02-20 16:38:40 +0100832 * Find out all required AML methods defined under the video bus device.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700833 */
834
Len Brown4be44fc2005-08-05 00:44:28 -0400835static void acpi_video_bus_find_cap(struct acpi_video_bus *video)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700836{
Len Brown4be44fc2005-08-05 00:44:28 -0400837 acpi_handle h_dummy1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700838
William Lee Irwin III98934de2007-12-12 03:56:55 -0800839 memset(&video->cap, 0, sizeof(video->cap));
Patrick Mochel90130262006-05-19 16:54:48 -0400840 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_DOS", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700841 video->cap._DOS = 1;
842 }
Patrick Mochel90130262006-05-19 16:54:48 -0400843 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_DOD", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700844 video->cap._DOD = 1;
845 }
Patrick Mochel90130262006-05-19 16:54:48 -0400846 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_ROM", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700847 video->cap._ROM = 1;
848 }
Patrick Mochel90130262006-05-19 16:54:48 -0400849 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_GPD", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700850 video->cap._GPD = 1;
851 }
Patrick Mochel90130262006-05-19 16:54:48 -0400852 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_SPD", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700853 video->cap._SPD = 1;
854 }
Patrick Mochel90130262006-05-19 16:54:48 -0400855 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_VPO", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700856 video->cap._VPO = 1;
857 }
858}
859
860/*
861 * Check whether the video bus device has required AML method to
862 * support the desired features
863 */
864
Len Brown4be44fc2005-08-05 00:44:28 -0400865static int acpi_video_bus_check(struct acpi_video_bus *video)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700866{
Len Brown4be44fc2005-08-05 00:44:28 -0400867 acpi_status status = -ENOENT;
Thomas Renninger22c13f92008-08-01 17:37:54 +0200868 struct device *dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700869
870 if (!video)
Patrick Mocheld550d982006-06-27 00:41:40 -0400871 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700872
Thomas Renninger22c13f92008-08-01 17:37:54 +0200873 dev = acpi_get_physical_pci_device(video->device->handle);
874 if (!dev)
875 return -ENODEV;
876 put_device(dev);
877
Linus Torvalds1da177e2005-04-16 15:20:36 -0700878 /* Since there is no HID, CID and so on for VGA driver, we have
879 * to check well known required nodes.
880 */
881
Julius Volz98fb8fe2007-02-20 16:38:40 +0100882 /* Does this device support video switching? */
Len Brown4be44fc2005-08-05 00:44:28 -0400883 if (video->cap._DOS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700884 video->flags.multihead = 1;
885 status = 0;
886 }
887
Julius Volz98fb8fe2007-02-20 16:38:40 +0100888 /* Does this device support retrieving a video ROM? */
Len Brown4be44fc2005-08-05 00:44:28 -0400889 if (video->cap._ROM) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700890 video->flags.rom = 1;
891 status = 0;
892 }
893
Julius Volz98fb8fe2007-02-20 16:38:40 +0100894 /* Does this device support configuring which video device to POST? */
Len Brown4be44fc2005-08-05 00:44:28 -0400895 if (video->cap._GPD && video->cap._SPD && video->cap._VPO) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700896 video->flags.post = 1;
897 status = 0;
898 }
899
Patrick Mocheld550d982006-06-27 00:41:40 -0400900 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700901}
902
903/* --------------------------------------------------------------------------
904 FS Interface (/proc)
905 -------------------------------------------------------------------------- */
906
Len Brown4be44fc2005-08-05 00:44:28 -0400907static struct proc_dir_entry *acpi_video_dir;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700908
909/* video devices */
910
Len Brown4be44fc2005-08-05 00:44:28 -0400911static int acpi_video_device_info_seq_show(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700912{
Jan Engelhardt50dd0962006-10-01 00:28:50 +0200913 struct acpi_video_device *dev = seq->private;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700914
Linus Torvalds1da177e2005-04-16 15:20:36 -0700915
916 if (!dev)
917 goto end;
918
919 seq_printf(seq, "device_id: 0x%04x\n", (u32) dev->device_id);
920 seq_printf(seq, "type: ");
921 if (dev->flags.crt)
922 seq_printf(seq, "CRT\n");
923 else if (dev->flags.lcd)
924 seq_printf(seq, "LCD\n");
925 else if (dev->flags.tvout)
926 seq_printf(seq, "TVOUT\n");
Rui Zhang82cae992007-01-03 23:40:53 -0500927 else if (dev->flags.dvi)
928 seq_printf(seq, "DVI\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700929 else
930 seq_printf(seq, "UNKNOWN\n");
931
Len Brown4be44fc2005-08-05 00:44:28 -0400932 seq_printf(seq, "known by bios: %s\n", dev->flags.bios ? "yes" : "no");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700933
Len Brown4be44fc2005-08-05 00:44:28 -0400934 end:
Patrick Mocheld550d982006-06-27 00:41:40 -0400935 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700936}
937
938static int
Len Brown4be44fc2005-08-05 00:44:28 -0400939acpi_video_device_info_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700940{
941 return single_open(file, acpi_video_device_info_seq_show,
942 PDE(inode)->data);
943}
944
Len Brown4be44fc2005-08-05 00:44:28 -0400945static int acpi_video_device_state_seq_show(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700946{
Len Brown4be44fc2005-08-05 00:44:28 -0400947 int status;
Jan Engelhardt50dd0962006-10-01 00:28:50 +0200948 struct acpi_video_device *dev = seq->private;
Matthew Wilcox27663c52008-10-10 02:22:59 -0400949 unsigned long long state;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700950
Linus Torvalds1da177e2005-04-16 15:20:36 -0700951
952 if (!dev)
953 goto end;
954
955 status = acpi_video_device_get_state(dev, &state);
956 seq_printf(seq, "state: ");
957 if (ACPI_SUCCESS(status))
Matthew Wilcox27663c52008-10-10 02:22:59 -0400958 seq_printf(seq, "0x%02llx\n", state);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700959 else
960 seq_printf(seq, "<not supported>\n");
961
962 status = acpi_video_device_query(dev, &state);
963 seq_printf(seq, "query: ");
964 if (ACPI_SUCCESS(status))
Matthew Wilcox27663c52008-10-10 02:22:59 -0400965 seq_printf(seq, "0x%02llx\n", state);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700966 else
967 seq_printf(seq, "<not supported>\n");
968
Len Brown4be44fc2005-08-05 00:44:28 -0400969 end:
Patrick Mocheld550d982006-06-27 00:41:40 -0400970 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700971}
972
973static int
Len Brown4be44fc2005-08-05 00:44:28 -0400974acpi_video_device_state_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700975{
976 return single_open(file, acpi_video_device_state_seq_show,
977 PDE(inode)->data);
978}
979
980static ssize_t
Len Brown4be44fc2005-08-05 00:44:28 -0400981acpi_video_device_write_state(struct file *file,
982 const char __user * buffer,
983 size_t count, loff_t * data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700984{
Len Brown4be44fc2005-08-05 00:44:28 -0400985 int status;
Jan Engelhardt50dd0962006-10-01 00:28:50 +0200986 struct seq_file *m = file->private_data;
987 struct acpi_video_device *dev = m->private;
Len Brown4be44fc2005-08-05 00:44:28 -0400988 char str[12] = { 0 };
989 u32 state = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700990
Linus Torvalds1da177e2005-04-16 15:20:36 -0700991
992 if (!dev || count + 1 > sizeof str)
Patrick Mocheld550d982006-06-27 00:41:40 -0400993 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700994
995 if (copy_from_user(str, buffer, count))
Patrick Mocheld550d982006-06-27 00:41:40 -0400996 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700997
998 str[count] = 0;
999 state = simple_strtoul(str, NULL, 0);
Len Brown4be44fc2005-08-05 00:44:28 -04001000 state &= ((1ul << 31) | (1ul << 30) | (1ul << 0));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001001
1002 status = acpi_video_device_set_state(dev, state);
1003
1004 if (status)
Patrick Mocheld550d982006-06-27 00:41:40 -04001005 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001006
Patrick Mocheld550d982006-06-27 00:41:40 -04001007 return count;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001008}
1009
1010static int
Len Brown4be44fc2005-08-05 00:44:28 -04001011acpi_video_device_brightness_seq_show(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001012{
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001013 struct acpi_video_device *dev = seq->private;
Len Brown4be44fc2005-08-05 00:44:28 -04001014 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001015
Linus Torvalds1da177e2005-04-16 15:20:36 -07001016
1017 if (!dev || !dev->brightness) {
1018 seq_printf(seq, "<not supported>\n");
Patrick Mocheld550d982006-06-27 00:41:40 -04001019 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001020 }
1021
1022 seq_printf(seq, "levels: ");
Zhao Yakui0a3db1c2009-02-02 11:33:41 +08001023 for (i = 2; i < dev->brightness->count; i++)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001024 seq_printf(seq, " %d", dev->brightness->levels[i]);
1025 seq_printf(seq, "\ncurrent: %d\n", dev->brightness->curr);
1026
Patrick Mocheld550d982006-06-27 00:41:40 -04001027 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001028}
1029
1030static int
Len Brown4be44fc2005-08-05 00:44:28 -04001031acpi_video_device_brightness_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001032{
1033 return single_open(file, acpi_video_device_brightness_seq_show,
1034 PDE(inode)->data);
1035}
1036
1037static ssize_t
Len Brown4be44fc2005-08-05 00:44:28 -04001038acpi_video_device_write_brightness(struct file *file,
1039 const char __user * buffer,
1040 size_t count, loff_t * data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001041{
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001042 struct seq_file *m = file->private_data;
1043 struct acpi_video_device *dev = m->private;
Danny Baumannc88c5782007-11-02 13:47:53 +01001044 char str[5] = { 0 };
Len Brown4be44fc2005-08-05 00:44:28 -04001045 unsigned int level = 0;
1046 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001047
Linus Torvalds1da177e2005-04-16 15:20:36 -07001048
Thomas Renninger59d399d2005-11-08 05:27:00 -05001049 if (!dev || !dev->brightness || count + 1 > sizeof str)
Patrick Mocheld550d982006-06-27 00:41:40 -04001050 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001051
1052 if (copy_from_user(str, buffer, count))
Patrick Mocheld550d982006-06-27 00:41:40 -04001053 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001054
1055 str[count] = 0;
1056 level = simple_strtoul(str, NULL, 0);
Len Brown4be44fc2005-08-05 00:44:28 -04001057
Linus Torvalds1da177e2005-04-16 15:20:36 -07001058 if (level > 100)
Patrick Mocheld550d982006-06-27 00:41:40 -04001059 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001060
Julius Volz98fb8fe2007-02-20 16:38:40 +01001061 /* validate through the list of available levels */
Zhao Yakui0a3db1c2009-02-02 11:33:41 +08001062 for (i = 2; i < dev->brightness->count; i++)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001063 if (level == dev->brightness->levels[i]) {
Len Brown4be44fc2005-08-05 00:44:28 -04001064 if (ACPI_SUCCESS
1065 (acpi_video_device_lcd_set_level(dev, level)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001066 dev->brightness->curr = level;
1067 break;
1068 }
1069
Patrick Mocheld550d982006-06-27 00:41:40 -04001070 return count;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001071}
1072
Len Brown4be44fc2005-08-05 00:44:28 -04001073static int acpi_video_device_EDID_seq_show(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001074{
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001075 struct acpi_video_device *dev = seq->private;
Len Brown4be44fc2005-08-05 00:44:28 -04001076 int status;
1077 int i;
1078 union acpi_object *edid = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001079
Linus Torvalds1da177e2005-04-16 15:20:36 -07001080
1081 if (!dev)
1082 goto out;
1083
Len Brown4be44fc2005-08-05 00:44:28 -04001084 status = acpi_video_device_EDID(dev, &edid, 128);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001085 if (ACPI_FAILURE(status)) {
Len Brown4be44fc2005-08-05 00:44:28 -04001086 status = acpi_video_device_EDID(dev, &edid, 256);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001087 }
1088
1089 if (ACPI_FAILURE(status)) {
1090 goto out;
1091 }
1092
1093 if (edid && edid->type == ACPI_TYPE_BUFFER) {
1094 for (i = 0; i < edid->buffer.length; i++)
1095 seq_putc(seq, edid->buffer.pointer[i]);
1096 }
1097
Len Brown4be44fc2005-08-05 00:44:28 -04001098 out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001099 if (!edid)
1100 seq_printf(seq, "<not supported>\n");
1101 else
1102 kfree(edid);
1103
Patrick Mocheld550d982006-06-27 00:41:40 -04001104 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001105}
1106
1107static int
Len Brown4be44fc2005-08-05 00:44:28 -04001108acpi_video_device_EDID_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001109{
1110 return single_open(file, acpi_video_device_EDID_seq_show,
1111 PDE(inode)->data);
1112}
1113
Len Brown4be44fc2005-08-05 00:44:28 -04001114static int acpi_video_device_add_fs(struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001115{
Dmitry Torokhov251cb0b2007-11-05 11:43:34 -05001116 struct proc_dir_entry *entry, *device_dir;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001117 struct acpi_video_device *vid_dev;
1118
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001119 vid_dev = acpi_driver_data(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001120 if (!vid_dev)
Patrick Mocheld550d982006-06-27 00:41:40 -04001121 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001122
Dmitry Torokhov251cb0b2007-11-05 11:43:34 -05001123 device_dir = proc_mkdir(acpi_device_bid(device),
1124 vid_dev->video->dir);
1125 if (!device_dir)
1126 return -ENOMEM;
1127
Linus Torvalds1da177e2005-04-16 15:20:36 -07001128 /* 'info' [R] */
Alexey Dobriyane0066c4e2008-05-01 04:10:02 +04001129 entry = proc_create_data("info", S_IRUGO, device_dir,
Denis V. Lunevcf7acfa2008-04-29 01:02:27 -07001130 &acpi_video_device_info_fops, acpi_driver_data(device));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001131 if (!entry)
Dmitry Torokhov251cb0b2007-11-05 11:43:34 -05001132 goto err_remove_dir;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001133
1134 /* 'state' [R/W] */
Denis V. Lunevcf7acfa2008-04-29 01:02:27 -07001135 acpi_video_device_state_fops.write = acpi_video_device_write_state;
1136 entry = proc_create_data("state", S_IFREG | S_IRUGO | S_IWUSR,
Alexey Dobriyane0066c4e2008-05-01 04:10:02 +04001137 device_dir,
Denis V. Lunevcf7acfa2008-04-29 01:02:27 -07001138 &acpi_video_device_state_fops,
1139 acpi_driver_data(device));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001140 if (!entry)
Dmitry Torokhov251cb0b2007-11-05 11:43:34 -05001141 goto err_remove_info;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001142
1143 /* 'brightness' [R/W] */
Denis V. Lunevcf7acfa2008-04-29 01:02:27 -07001144 acpi_video_device_brightness_fops.write =
1145 acpi_video_device_write_brightness;
1146 entry = proc_create_data("brightness", S_IFREG | S_IRUGO | S_IWUSR,
Alexey Dobriyane0066c4e2008-05-01 04:10:02 +04001147 device_dir,
Denis V. Lunevcf7acfa2008-04-29 01:02:27 -07001148 &acpi_video_device_brightness_fops,
1149 acpi_driver_data(device));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001150 if (!entry)
Dmitry Torokhov251cb0b2007-11-05 11:43:34 -05001151 goto err_remove_state;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001152
1153 /* 'EDID' [R] */
Alexey Dobriyane0066c4e2008-05-01 04:10:02 +04001154 entry = proc_create_data("EDID", S_IRUGO, device_dir,
Denis V. Lunevcf7acfa2008-04-29 01:02:27 -07001155 &acpi_video_device_EDID_fops,
1156 acpi_driver_data(device));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001157 if (!entry)
Dmitry Torokhov251cb0b2007-11-05 11:43:34 -05001158 goto err_remove_brightness;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001159
Alexey Dobriyane0066c4e2008-05-01 04:10:02 +04001160 acpi_device_dir(device) = device_dir;
1161
Patrick Mocheld550d982006-06-27 00:41:40 -04001162 return 0;
Dmitry Torokhov251cb0b2007-11-05 11:43:34 -05001163
1164 err_remove_brightness:
1165 remove_proc_entry("brightness", device_dir);
1166 err_remove_state:
1167 remove_proc_entry("state", device_dir);
1168 err_remove_info:
1169 remove_proc_entry("info", device_dir);
1170 err_remove_dir:
1171 remove_proc_entry(acpi_device_bid(device), vid_dev->video->dir);
1172 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001173}
1174
Len Brown4be44fc2005-08-05 00:44:28 -04001175static int acpi_video_device_remove_fs(struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001176{
1177 struct acpi_video_device *vid_dev;
Dmitry Torokhov251cb0b2007-11-05 11:43:34 -05001178 struct proc_dir_entry *device_dir;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001179
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001180 vid_dev = acpi_driver_data(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001181 if (!vid_dev || !vid_dev->video || !vid_dev->video->dir)
Patrick Mocheld550d982006-06-27 00:41:40 -04001182 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001183
Dmitry Torokhov251cb0b2007-11-05 11:43:34 -05001184 device_dir = acpi_device_dir(device);
1185 if (device_dir) {
1186 remove_proc_entry("info", device_dir);
1187 remove_proc_entry("state", device_dir);
1188 remove_proc_entry("brightness", device_dir);
1189 remove_proc_entry("EDID", device_dir);
Len Brown4be44fc2005-08-05 00:44:28 -04001190 remove_proc_entry(acpi_device_bid(device), vid_dev->video->dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001191 acpi_device_dir(device) = NULL;
1192 }
1193
Patrick Mocheld550d982006-06-27 00:41:40 -04001194 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001195}
1196
Linus Torvalds1da177e2005-04-16 15:20:36 -07001197/* video bus */
Len Brown4be44fc2005-08-05 00:44:28 -04001198static int acpi_video_bus_info_seq_show(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001199{
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001200 struct acpi_video_bus *video = seq->private;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001201
Linus Torvalds1da177e2005-04-16 15:20:36 -07001202
1203 if (!video)
1204 goto end;
1205
1206 seq_printf(seq, "Switching heads: %s\n",
Len Brown4be44fc2005-08-05 00:44:28 -04001207 video->flags.multihead ? "yes" : "no");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001208 seq_printf(seq, "Video ROM: %s\n",
Len Brown4be44fc2005-08-05 00:44:28 -04001209 video->flags.rom ? "yes" : "no");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001210 seq_printf(seq, "Device to be POSTed on boot: %s\n",
Len Brown4be44fc2005-08-05 00:44:28 -04001211 video->flags.post ? "yes" : "no");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001212
Len Brown4be44fc2005-08-05 00:44:28 -04001213 end:
Patrick Mocheld550d982006-06-27 00:41:40 -04001214 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001215}
1216
Len Brown4be44fc2005-08-05 00:44:28 -04001217static int acpi_video_bus_info_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001218{
Len Brown4be44fc2005-08-05 00:44:28 -04001219 return single_open(file, acpi_video_bus_info_seq_show,
1220 PDE(inode)->data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001221}
1222
Len Brown4be44fc2005-08-05 00:44:28 -04001223static int acpi_video_bus_ROM_seq_show(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001224{
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001225 struct acpi_video_bus *video = seq->private;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001226
Linus Torvalds1da177e2005-04-16 15:20:36 -07001227
1228 if (!video)
1229 goto end;
1230
Harvey Harrison96b2dd12008-03-05 18:24:51 -08001231 printk(KERN_INFO PREFIX "Please implement %s\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001232 seq_printf(seq, "<TODO>\n");
1233
Len Brown4be44fc2005-08-05 00:44:28 -04001234 end:
Patrick Mocheld550d982006-06-27 00:41:40 -04001235 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001236}
1237
Len Brown4be44fc2005-08-05 00:44:28 -04001238static int acpi_video_bus_ROM_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001239{
1240 return single_open(file, acpi_video_bus_ROM_seq_show, PDE(inode)->data);
1241}
1242
Len Brown4be44fc2005-08-05 00:44:28 -04001243static int acpi_video_bus_POST_info_seq_show(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001244{
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001245 struct acpi_video_bus *video = seq->private;
Matthew Wilcox27663c52008-10-10 02:22:59 -04001246 unsigned long long options;
Len Brown4be44fc2005-08-05 00:44:28 -04001247 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001248
Linus Torvalds1da177e2005-04-16 15:20:36 -07001249
1250 if (!video)
1251 goto end;
1252
1253 status = acpi_video_bus_POST_options(video, &options);
1254 if (ACPI_SUCCESS(status)) {
1255 if (!(options & 1)) {
Len Brown4be44fc2005-08-05 00:44:28 -04001256 printk(KERN_WARNING PREFIX
1257 "The motherboard VGA device is not listed as a possible POST device.\n");
1258 printk(KERN_WARNING PREFIX
Julius Volz98fb8fe2007-02-20 16:38:40 +01001259 "This indicates a BIOS bug. Please contact the manufacturer.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001260 }
Frank Seidel4d939152009-02-04 17:03:07 +01001261 printk(KERN_WARNING "%llx\n", options);
Julius Volz98fb8fe2007-02-20 16:38:40 +01001262 seq_printf(seq, "can POST: <integrated video>");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001263 if (options & 2)
1264 seq_printf(seq, " <PCI video>");
1265 if (options & 4)
1266 seq_printf(seq, " <AGP video>");
1267 seq_putc(seq, '\n');
1268 } else
1269 seq_printf(seq, "<not supported>\n");
Len Brown4be44fc2005-08-05 00:44:28 -04001270 end:
Patrick Mocheld550d982006-06-27 00:41:40 -04001271 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001272}
1273
1274static int
Len Brown4be44fc2005-08-05 00:44:28 -04001275acpi_video_bus_POST_info_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001276{
Len Brown4be44fc2005-08-05 00:44:28 -04001277 return single_open(file, acpi_video_bus_POST_info_seq_show,
1278 PDE(inode)->data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001279}
1280
Len Brown4be44fc2005-08-05 00:44:28 -04001281static int acpi_video_bus_POST_seq_show(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001282{
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001283 struct acpi_video_bus *video = seq->private;
Len Brown4be44fc2005-08-05 00:44:28 -04001284 int status;
Matthew Wilcox27663c52008-10-10 02:22:59 -04001285 unsigned long long id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001286
Linus Torvalds1da177e2005-04-16 15:20:36 -07001287
1288 if (!video)
1289 goto end;
1290
Len Brown4be44fc2005-08-05 00:44:28 -04001291 status = acpi_video_bus_get_POST(video, &id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001292 if (!ACPI_SUCCESS(status)) {
1293 seq_printf(seq, "<not supported>\n");
1294 goto end;
1295 }
Julius Volz98fb8fe2007-02-20 16:38:40 +01001296 seq_printf(seq, "device POSTed is <%s>\n", device_decode[id & 3]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001297
Len Brown4be44fc2005-08-05 00:44:28 -04001298 end:
Patrick Mocheld550d982006-06-27 00:41:40 -04001299 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001300}
1301
Len Brown4be44fc2005-08-05 00:44:28 -04001302static int acpi_video_bus_DOS_seq_show(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001303{
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001304 struct acpi_video_bus *video = seq->private;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001305
Linus Torvalds1da177e2005-04-16 15:20:36 -07001306
Len Brown4be44fc2005-08-05 00:44:28 -04001307 seq_printf(seq, "DOS setting: <%d>\n", video->dos_setting);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001308
Patrick Mocheld550d982006-06-27 00:41:40 -04001309 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001310}
1311
Len Brown4be44fc2005-08-05 00:44:28 -04001312static int acpi_video_bus_POST_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001313{
Len Brown4be44fc2005-08-05 00:44:28 -04001314 return single_open(file, acpi_video_bus_POST_seq_show,
1315 PDE(inode)->data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001316}
1317
Len Brown4be44fc2005-08-05 00:44:28 -04001318static int acpi_video_bus_DOS_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001319{
1320 return single_open(file, acpi_video_bus_DOS_seq_show, PDE(inode)->data);
1321}
1322
1323static ssize_t
Len Brown4be44fc2005-08-05 00:44:28 -04001324acpi_video_bus_write_POST(struct file *file,
1325 const char __user * buffer,
1326 size_t count, loff_t * data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001327{
Len Brown4be44fc2005-08-05 00:44:28 -04001328 int status;
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001329 struct seq_file *m = file->private_data;
1330 struct acpi_video_bus *video = m->private;
Len Brown4be44fc2005-08-05 00:44:28 -04001331 char str[12] = { 0 };
Matthew Wilcox27663c52008-10-10 02:22:59 -04001332 unsigned long long opt, options;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001333
Linus Torvalds1da177e2005-04-16 15:20:36 -07001334
Linus Torvalds1da177e2005-04-16 15:20:36 -07001335 if (!video || count + 1 > sizeof str)
Patrick Mocheld550d982006-06-27 00:41:40 -04001336 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001337
1338 status = acpi_video_bus_POST_options(video, &options);
1339 if (!ACPI_SUCCESS(status))
Patrick Mocheld550d982006-06-27 00:41:40 -04001340 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001341
1342 if (copy_from_user(str, buffer, count))
Patrick Mocheld550d982006-06-27 00:41:40 -04001343 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001344
1345 str[count] = 0;
1346 opt = strtoul(str, NULL, 0);
1347 if (opt > 3)
Patrick Mocheld550d982006-06-27 00:41:40 -04001348 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001349
Julius Volz98fb8fe2007-02-20 16:38:40 +01001350 /* just in case an OEM 'forgot' the motherboard... */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001351 options |= 1;
1352
1353 if (options & (1ul << opt)) {
Len Brown4be44fc2005-08-05 00:44:28 -04001354 status = acpi_video_bus_set_POST(video, opt);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001355 if (!ACPI_SUCCESS(status))
Patrick Mocheld550d982006-06-27 00:41:40 -04001356 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001357
1358 }
1359
Patrick Mocheld550d982006-06-27 00:41:40 -04001360 return count;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001361}
1362
1363static ssize_t
Len Brown4be44fc2005-08-05 00:44:28 -04001364acpi_video_bus_write_DOS(struct file *file,
1365 const char __user * buffer,
1366 size_t count, loff_t * data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001367{
Len Brown4be44fc2005-08-05 00:44:28 -04001368 int status;
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001369 struct seq_file *m = file->private_data;
1370 struct acpi_video_bus *video = m->private;
Len Brown4be44fc2005-08-05 00:44:28 -04001371 char str[12] = { 0 };
1372 unsigned long opt;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001373
Linus Torvalds1da177e2005-04-16 15:20:36 -07001374
Linus Torvalds1da177e2005-04-16 15:20:36 -07001375 if (!video || count + 1 > sizeof str)
Patrick Mocheld550d982006-06-27 00:41:40 -04001376 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001377
1378 if (copy_from_user(str, buffer, count))
Patrick Mocheld550d982006-06-27 00:41:40 -04001379 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001380
1381 str[count] = 0;
1382 opt = strtoul(str, NULL, 0);
1383 if (opt > 7)
Patrick Mocheld550d982006-06-27 00:41:40 -04001384 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001385
Len Brown4be44fc2005-08-05 00:44:28 -04001386 status = acpi_video_bus_DOS(video, opt & 0x3, (opt & 0x4) >> 2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001387
1388 if (!ACPI_SUCCESS(status))
Patrick Mocheld550d982006-06-27 00:41:40 -04001389 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001390
Patrick Mocheld550d982006-06-27 00:41:40 -04001391 return count;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001392}
1393
Len Brown4be44fc2005-08-05 00:44:28 -04001394static int acpi_video_bus_add_fs(struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001395{
Dmitry Torokhov251cb0b2007-11-05 11:43:34 -05001396 struct acpi_video_bus *video = acpi_driver_data(device);
1397 struct proc_dir_entry *device_dir;
1398 struct proc_dir_entry *entry;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001399
Dmitry Torokhov251cb0b2007-11-05 11:43:34 -05001400 device_dir = proc_mkdir(acpi_device_bid(device), acpi_video_dir);
1401 if (!device_dir)
1402 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001403
Linus Torvalds1da177e2005-04-16 15:20:36 -07001404 /* 'info' [R] */
Alexey Dobriyane0066c4e2008-05-01 04:10:02 +04001405 entry = proc_create_data("info", S_IRUGO, device_dir,
Denis V. Lunevcf7acfa2008-04-29 01:02:27 -07001406 &acpi_video_bus_info_fops,
1407 acpi_driver_data(device));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001408 if (!entry)
Dmitry Torokhov251cb0b2007-11-05 11:43:34 -05001409 goto err_remove_dir;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001410
1411 /* 'ROM' [R] */
Alexey Dobriyane0066c4e2008-05-01 04:10:02 +04001412 entry = proc_create_data("ROM", S_IRUGO, device_dir,
Denis V. Lunevcf7acfa2008-04-29 01:02:27 -07001413 &acpi_video_bus_ROM_fops,
1414 acpi_driver_data(device));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001415 if (!entry)
Dmitry Torokhov251cb0b2007-11-05 11:43:34 -05001416 goto err_remove_info;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001417
1418 /* 'POST_info' [R] */
Alexey Dobriyane0066c4e2008-05-01 04:10:02 +04001419 entry = proc_create_data("POST_info", S_IRUGO, device_dir,
Denis V. Lunevcf7acfa2008-04-29 01:02:27 -07001420 &acpi_video_bus_POST_info_fops,
1421 acpi_driver_data(device));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001422 if (!entry)
Dmitry Torokhov251cb0b2007-11-05 11:43:34 -05001423 goto err_remove_rom;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001424
1425 /* 'POST' [R/W] */
Denis V. Lunevcf7acfa2008-04-29 01:02:27 -07001426 acpi_video_bus_POST_fops.write = acpi_video_bus_write_POST;
Linus Torvalds08acd4f2008-04-30 11:52:52 -07001427 entry = proc_create_data("POST", S_IFREG | S_IRUGO | S_IWUSR,
Alexey Dobriyane0066c4e2008-05-01 04:10:02 +04001428 device_dir,
Denis V. Lunevcf7acfa2008-04-29 01:02:27 -07001429 &acpi_video_bus_POST_fops,
1430 acpi_driver_data(device));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001431 if (!entry)
Dmitry Torokhov251cb0b2007-11-05 11:43:34 -05001432 goto err_remove_post_info;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001433
1434 /* 'DOS' [R/W] */
Denis V. Lunevcf7acfa2008-04-29 01:02:27 -07001435 acpi_video_bus_DOS_fops.write = acpi_video_bus_write_DOS;
Linus Torvalds08acd4f2008-04-30 11:52:52 -07001436 entry = proc_create_data("DOS", S_IFREG | S_IRUGO | S_IWUSR,
Alexey Dobriyane0066c4e2008-05-01 04:10:02 +04001437 device_dir,
Denis V. Lunevcf7acfa2008-04-29 01:02:27 -07001438 &acpi_video_bus_DOS_fops,
1439 acpi_driver_data(device));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001440 if (!entry)
Dmitry Torokhov251cb0b2007-11-05 11:43:34 -05001441 goto err_remove_post;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001442
Dmitry Torokhov251cb0b2007-11-05 11:43:34 -05001443 video->dir = acpi_device_dir(device) = device_dir;
Patrick Mocheld550d982006-06-27 00:41:40 -04001444 return 0;
Dmitry Torokhov251cb0b2007-11-05 11:43:34 -05001445
1446 err_remove_post:
1447 remove_proc_entry("POST", device_dir);
1448 err_remove_post_info:
1449 remove_proc_entry("POST_info", device_dir);
1450 err_remove_rom:
1451 remove_proc_entry("ROM", device_dir);
1452 err_remove_info:
1453 remove_proc_entry("info", device_dir);
1454 err_remove_dir:
1455 remove_proc_entry(acpi_device_bid(device), acpi_video_dir);
1456 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001457}
1458
Len Brown4be44fc2005-08-05 00:44:28 -04001459static int acpi_video_bus_remove_fs(struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001460{
Dmitry Torokhov251cb0b2007-11-05 11:43:34 -05001461 struct proc_dir_entry *device_dir = acpi_device_dir(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001462
Dmitry Torokhov251cb0b2007-11-05 11:43:34 -05001463 if (device_dir) {
1464 remove_proc_entry("info", device_dir);
1465 remove_proc_entry("ROM", device_dir);
1466 remove_proc_entry("POST_info", device_dir);
1467 remove_proc_entry("POST", device_dir);
1468 remove_proc_entry("DOS", device_dir);
Len Brown4be44fc2005-08-05 00:44:28 -04001469 remove_proc_entry(acpi_device_bid(device), acpi_video_dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001470 acpi_device_dir(device) = NULL;
1471 }
1472
Patrick Mocheld550d982006-06-27 00:41:40 -04001473 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001474}
1475
1476/* --------------------------------------------------------------------------
1477 Driver Interface
1478 -------------------------------------------------------------------------- */
1479
1480/* device interface */
Rui Zhang82cae992007-01-03 23:40:53 -05001481static struct acpi_video_device_attrib*
1482acpi_video_get_device_attr(struct acpi_video_bus *video, unsigned long device_id)
1483{
Dmitry Torokhov78eed022007-11-05 11:43:33 -05001484 struct acpi_video_enumerated_device *ids;
1485 int i;
Rui Zhang82cae992007-01-03 23:40:53 -05001486
Dmitry Torokhov78eed022007-11-05 11:43:33 -05001487 for (i = 0; i < video->attached_count; i++) {
1488 ids = &video->attached_array[i];
1489 if ((ids->value.int_val & 0xffff) == device_id)
1490 return &ids->value.attrib;
1491 }
1492
Rui Zhang82cae992007-01-03 23:40:53 -05001493 return NULL;
1494}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001495
1496static int
Len Brown4be44fc2005-08-05 00:44:28 -04001497acpi_video_bus_get_one_device(struct acpi_device *device,
1498 struct acpi_video_bus *video)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001499{
Matthew Wilcox27663c52008-10-10 02:22:59 -04001500 unsigned long long device_id;
Yu, Luming973bf492006-04-27 05:25:00 -04001501 int status;
Len Brown4be44fc2005-08-05 00:44:28 -04001502 struct acpi_video_device *data;
Rui Zhang82cae992007-01-03 23:40:53 -05001503 struct acpi_video_device_attrib* attribute;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001504
1505 if (!device || !video)
Patrick Mocheld550d982006-06-27 00:41:40 -04001506 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001507
Len Brown4be44fc2005-08-05 00:44:28 -04001508 status =
1509 acpi_evaluate_integer(device->handle, "_ADR", NULL, &device_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001510 if (ACPI_SUCCESS(status)) {
1511
Burman Yan36bcbec2006-12-19 12:56:11 -08001512 data = kzalloc(sizeof(struct acpi_video_device), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001513 if (!data)
Patrick Mocheld550d982006-06-27 00:41:40 -04001514 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001515
Linus Torvalds1da177e2005-04-16 15:20:36 -07001516 strcpy(acpi_device_name(device), ACPI_VIDEO_DEVICE_NAME);
1517 strcpy(acpi_device_class(device), ACPI_VIDEO_CLASS);
Pavel Machekdb89b4f2008-09-22 14:37:34 -07001518 device->driver_data = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001519
1520 data->device_id = device_id;
1521 data->video = video;
1522 data->dev = device;
1523
Rui Zhang82cae992007-01-03 23:40:53 -05001524 attribute = acpi_video_get_device_attr(video, device_id);
1525
1526 if((attribute != NULL) && attribute->device_id_scheme) {
1527 switch (attribute->display_type) {
1528 case ACPI_VIDEO_DISPLAY_CRT:
1529 data->flags.crt = 1;
1530 break;
1531 case ACPI_VIDEO_DISPLAY_TV:
1532 data->flags.tvout = 1;
1533 break;
1534 case ACPI_VIDEO_DISPLAY_DVI:
1535 data->flags.dvi = 1;
1536 break;
1537 case ACPI_VIDEO_DISPLAY_LCD:
1538 data->flags.lcd = 1;
1539 break;
1540 default:
1541 data->flags.unknown = 1;
1542 break;
1543 }
1544 if(attribute->bios_can_detect)
1545 data->flags.bios = 1;
1546 } else
Linus Torvalds1da177e2005-04-16 15:20:36 -07001547 data->flags.unknown = 1;
Len Brown4be44fc2005-08-05 00:44:28 -04001548
Linus Torvalds1da177e2005-04-16 15:20:36 -07001549 acpi_video_device_bind(video, data);
1550 acpi_video_device_find_cap(data);
1551
Patrick Mochel90130262006-05-19 16:54:48 -04001552 status = acpi_install_notify_handler(device->handle,
Len Brown4be44fc2005-08-05 00:44:28 -04001553 ACPI_DEVICE_NOTIFY,
1554 acpi_video_device_notify,
1555 data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001556 if (ACPI_FAILURE(status)) {
Lin Ming55ac9a02008-09-28 14:51:56 +08001557 printk(KERN_ERR PREFIX
1558 "Error installing notify handler\n");
Yu, Luming973bf492006-04-27 05:25:00 -04001559 if(data->brightness)
1560 kfree(data->brightness->levels);
1561 kfree(data->brightness);
1562 kfree(data);
1563 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001564 }
1565
Dmitry Torokhovbbac81f2007-11-05 11:43:32 -05001566 mutex_lock(&video->device_list_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001567 list_add_tail(&data->entry, &video->video_device_list);
Dmitry Torokhovbbac81f2007-11-05 11:43:32 -05001568 mutex_unlock(&video->device_list_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001569
1570 acpi_video_device_add_fs(device);
1571
Patrick Mocheld550d982006-06-27 00:41:40 -04001572 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001573 }
1574
Patrick Mocheld550d982006-06-27 00:41:40 -04001575 return -ENOENT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001576}
1577
1578/*
1579 * Arg:
1580 * video : video bus device
1581 *
1582 * Return:
1583 * none
1584 *
1585 * Enumerate the video device list of the video bus,
1586 * bind the ids with the corresponding video devices
1587 * under the video bus.
Len Brown4be44fc2005-08-05 00:44:28 -04001588 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001589
Len Brown4be44fc2005-08-05 00:44:28 -04001590static void acpi_video_device_rebind(struct acpi_video_bus *video)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001591{
Dmitry Torokhovff102ea2007-11-05 11:43:31 -05001592 struct acpi_video_device *dev;
1593
Dmitry Torokhovbbac81f2007-11-05 11:43:32 -05001594 mutex_lock(&video->device_list_lock);
Dmitry Torokhovff102ea2007-11-05 11:43:31 -05001595
1596 list_for_each_entry(dev, &video->video_device_list, entry)
Len Brown4be44fc2005-08-05 00:44:28 -04001597 acpi_video_device_bind(video, dev);
Dmitry Torokhovff102ea2007-11-05 11:43:31 -05001598
Dmitry Torokhovbbac81f2007-11-05 11:43:32 -05001599 mutex_unlock(&video->device_list_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001600}
1601
1602/*
1603 * Arg:
1604 * video : video bus device
1605 * device : video output device under the video
1606 * bus
1607 *
1608 * Return:
1609 * none
1610 *
1611 * Bind the ids with the corresponding video devices
1612 * under the video bus.
Len Brown4be44fc2005-08-05 00:44:28 -04001613 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001614
1615static void
Len Brown4be44fc2005-08-05 00:44:28 -04001616acpi_video_device_bind(struct acpi_video_bus *video,
1617 struct acpi_video_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001618{
Dmitry Torokhov78eed022007-11-05 11:43:33 -05001619 struct acpi_video_enumerated_device *ids;
Len Brown4be44fc2005-08-05 00:44:28 -04001620 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001621
Dmitry Torokhov78eed022007-11-05 11:43:33 -05001622 for (i = 0; i < video->attached_count; i++) {
1623 ids = &video->attached_array[i];
1624 if (device->device_id == (ids->value.int_val & 0xffff)) {
1625 ids->bind_info = device;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001626 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "device_bind %d\n", i));
1627 }
1628 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001629}
1630
1631/*
1632 * Arg:
1633 * video : video bus device
1634 *
1635 * Return:
1636 * < 0 : error
1637 *
1638 * Call _DOD to enumerate all devices attached to display adapter
1639 *
Len Brown4be44fc2005-08-05 00:44:28 -04001640 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001641
1642static int acpi_video_device_enumerate(struct acpi_video_bus *video)
1643{
Len Brown4be44fc2005-08-05 00:44:28 -04001644 int status;
1645 int count;
1646 int i;
Dmitry Torokhov78eed022007-11-05 11:43:33 -05001647 struct acpi_video_enumerated_device *active_list;
Len Brown4be44fc2005-08-05 00:44:28 -04001648 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
1649 union acpi_object *dod = NULL;
1650 union acpi_object *obj;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001651
Patrick Mochel90130262006-05-19 16:54:48 -04001652 status = acpi_evaluate_object(video->device->handle, "_DOD", NULL, &buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001653 if (!ACPI_SUCCESS(status)) {
Thomas Renningera6fc6722006-06-26 23:58:43 -04001654 ACPI_EXCEPTION((AE_INFO, status, "Evaluating _DOD"));
Patrick Mocheld550d982006-06-27 00:41:40 -04001655 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001656 }
1657
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001658 dod = buffer.pointer;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001659 if (!dod || (dod->type != ACPI_TYPE_PACKAGE)) {
Thomas Renningera6fc6722006-06-26 23:58:43 -04001660 ACPI_EXCEPTION((AE_INFO, status, "Invalid _DOD data"));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001661 status = -EFAULT;
1662 goto out;
1663 }
1664
1665 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found %d video heads in _DOD\n",
Len Brown4be44fc2005-08-05 00:44:28 -04001666 dod->package.count));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001667
Dmitry Torokhov78eed022007-11-05 11:43:33 -05001668 active_list = kcalloc(1 + dod->package.count,
1669 sizeof(struct acpi_video_enumerated_device),
1670 GFP_KERNEL);
1671 if (!active_list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001672 status = -ENOMEM;
1673 goto out;
1674 }
1675
1676 count = 0;
1677 for (i = 0; i < dod->package.count; i++) {
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001678 obj = &dod->package.elements[i];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001679
1680 if (obj->type != ACPI_TYPE_INTEGER) {
Dmitry Torokhov78eed022007-11-05 11:43:33 -05001681 printk(KERN_ERR PREFIX
1682 "Invalid _DOD data in element %d\n", i);
1683 continue;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001684 }
Dmitry Torokhov78eed022007-11-05 11:43:33 -05001685
1686 active_list[count].value.int_val = obj->integer.value;
1687 active_list[count].bind_info = NULL;
Len Brown4be44fc2005-08-05 00:44:28 -04001688 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "dod element[%d] = %d\n", i,
1689 (int)obj->integer.value));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001690 count++;
1691 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001692
Jesper Juhl6044ec82005-11-07 01:01:32 -08001693 kfree(video->attached_array);
Len Brown4be44fc2005-08-05 00:44:28 -04001694
Dmitry Torokhov78eed022007-11-05 11:43:33 -05001695 video->attached_array = active_list;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001696 video->attached_count = count;
Dmitry Torokhov78eed022007-11-05 11:43:33 -05001697
1698 out:
Len Brown02438d82006-06-30 03:19:10 -04001699 kfree(buffer.pointer);
Patrick Mocheld550d982006-06-27 00:41:40 -04001700 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001701}
1702
Len Brown4be44fc2005-08-05 00:44:28 -04001703static int
1704acpi_video_get_next_level(struct acpi_video_device *device,
1705 u32 level_current, u32 event)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001706{
Alexey Starikovskiy63f0edf2007-09-03 16:30:08 +04001707 int min, max, min_above, max_below, i, l, delta = 255;
Thomas Tuttlef4715182006-12-19 12:56:14 -08001708 max = max_below = 0;
1709 min = min_above = 255;
Alexey Starikovskiy63f0edf2007-09-03 16:30:08 +04001710 /* Find closest level to level_current */
Zhao Yakui0a3db1c2009-02-02 11:33:41 +08001711 for (i = 2; i < device->brightness->count; i++) {
Alexey Starikovskiy63f0edf2007-09-03 16:30:08 +04001712 l = device->brightness->levels[i];
1713 if (abs(l - level_current) < abs(delta)) {
1714 delta = l - level_current;
1715 if (!delta)
1716 break;
1717 }
1718 }
1719 /* Ajust level_current to closest available level */
1720 level_current += delta;
Zhao Yakui0a3db1c2009-02-02 11:33:41 +08001721 for (i = 2; i < device->brightness->count; i++) {
Thomas Tuttlef4715182006-12-19 12:56:14 -08001722 l = device->brightness->levels[i];
1723 if (l < min)
1724 min = l;
1725 if (l > max)
1726 max = l;
1727 if (l < min_above && l > level_current)
1728 min_above = l;
1729 if (l > max_below && l < level_current)
1730 max_below = l;
1731 }
1732
1733 switch (event) {
1734 case ACPI_VIDEO_NOTIFY_CYCLE_BRIGHTNESS:
1735 return (level_current < max) ? min_above : min;
1736 case ACPI_VIDEO_NOTIFY_INC_BRIGHTNESS:
1737 return (level_current < max) ? min_above : max;
1738 case ACPI_VIDEO_NOTIFY_DEC_BRIGHTNESS:
1739 return (level_current > min) ? max_below : min;
1740 case ACPI_VIDEO_NOTIFY_ZERO_BRIGHTNESS:
1741 case ACPI_VIDEO_NOTIFY_DISPLAY_OFF:
1742 return 0;
1743 default:
1744 return level_current;
1745 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001746}
1747
Linus Torvalds1da177e2005-04-16 15:20:36 -07001748static void
Len Brown4be44fc2005-08-05 00:44:28 -04001749acpi_video_switch_brightness(struct acpi_video_device *device, int event)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001750{
Matthew Wilcox27663c52008-10-10 02:22:59 -04001751 unsigned long long level_current, level_next;
Julia Jomantaite469778c2008-06-23 22:50:42 +01001752 if (!device->brightness)
1753 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001754 acpi_video_device_lcd_get_level_current(device, &level_current);
1755 level_next = acpi_video_get_next_level(device, level_current, event);
1756 acpi_video_device_lcd_set_level(device, level_next);
1757}
1758
1759static int
Len Brown4be44fc2005-08-05 00:44:28 -04001760acpi_video_bus_get_devices(struct acpi_video_bus *video,
1761 struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001762{
Len Brown4be44fc2005-08-05 00:44:28 -04001763 int status = 0;
Dmitry Torokhovff102ea2007-11-05 11:43:31 -05001764 struct acpi_device *dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001765
1766 acpi_video_device_enumerate(video);
1767
Dmitry Torokhovff102ea2007-11-05 11:43:31 -05001768 list_for_each_entry(dev, &device->children, node) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001769
1770 status = acpi_video_bus_get_one_device(dev, video);
1771 if (ACPI_FAILURE(status)) {
Lin Ming55ac9a02008-09-28 14:51:56 +08001772 printk(KERN_WARNING PREFIX
1773 "Cant attach device");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001774 continue;
1775 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001776 }
Patrick Mocheld550d982006-06-27 00:41:40 -04001777 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001778}
1779
Len Brown4be44fc2005-08-05 00:44:28 -04001780static int acpi_video_bus_put_one_device(struct acpi_video_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001781{
Karol Kozimor031ec772005-07-30 04:18:00 -04001782 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001783 struct acpi_video_bus *video;
1784
Linus Torvalds1da177e2005-04-16 15:20:36 -07001785
1786 if (!device || !device->video)
Patrick Mocheld550d982006-06-27 00:41:40 -04001787 return -ENOENT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001788
1789 video = device->video;
1790
Linus Torvalds1da177e2005-04-16 15:20:36 -07001791 acpi_video_device_remove_fs(device->dev);
1792
Patrick Mochel90130262006-05-19 16:54:48 -04001793 status = acpi_remove_notify_handler(device->dev->handle,
Len Brown4be44fc2005-08-05 00:44:28 -04001794 ACPI_DEVICE_NOTIFY,
1795 acpi_video_device_notify);
Richard Purdie599a52d2007-02-10 23:07:48 +00001796 backlight_device_unregister(device->backlight);
Zhang Rui702ed512008-01-17 15:51:22 +08001797 if (device->cdev) {
1798 sysfs_remove_link(&device->dev->dev.kobj,
1799 "thermal_cooling");
1800 sysfs_remove_link(&device->cdev->device.kobj,
1801 "device");
1802 thermal_cooling_device_unregister(device->cdev);
1803 device->cdev = NULL;
1804 }
Luming Yu23b0f012007-05-09 21:07:05 +08001805 video_output_unregister(device->output_dev);
Dmitry Torokhovff102ea2007-11-05 11:43:31 -05001806
Patrick Mocheld550d982006-06-27 00:41:40 -04001807 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001808}
1809
Len Brown4be44fc2005-08-05 00:44:28 -04001810static int acpi_video_bus_put_devices(struct acpi_video_bus *video)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001811{
Len Brown4be44fc2005-08-05 00:44:28 -04001812 int status;
Dmitry Torokhovff102ea2007-11-05 11:43:31 -05001813 struct acpi_video_device *dev, *next;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001814
Dmitry Torokhovbbac81f2007-11-05 11:43:32 -05001815 mutex_lock(&video->device_list_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001816
Dmitry Torokhovff102ea2007-11-05 11:43:31 -05001817 list_for_each_entry_safe(dev, next, &video->video_device_list, entry) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001818
Dmitry Torokhovff102ea2007-11-05 11:43:31 -05001819 status = acpi_video_bus_put_one_device(dev);
Len Brown4be44fc2005-08-05 00:44:28 -04001820 if (ACPI_FAILURE(status))
1821 printk(KERN_WARNING PREFIX
1822 "hhuuhhuu bug in acpi video driver.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001823
Dmitry Torokhovff102ea2007-11-05 11:43:31 -05001824 if (dev->brightness) {
1825 kfree(dev->brightness->levels);
1826 kfree(dev->brightness);
1827 }
1828 list_del(&dev->entry);
1829 kfree(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001830 }
1831
Dmitry Torokhovbbac81f2007-11-05 11:43:32 -05001832 mutex_unlock(&video->device_list_lock);
Dmitry Torokhovff102ea2007-11-05 11:43:31 -05001833
Patrick Mocheld550d982006-06-27 00:41:40 -04001834 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001835}
1836
1837/* acpi_video interface */
1838
Len Brown4be44fc2005-08-05 00:44:28 -04001839static int acpi_video_bus_start_devices(struct acpi_video_bus *video)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001840{
Zhang Ruia21101c2007-09-14 11:46:22 +08001841 return acpi_video_bus_DOS(video, 0, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001842}
1843
Len Brown4be44fc2005-08-05 00:44:28 -04001844static int acpi_video_bus_stop_devices(struct acpi_video_bus *video)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001845{
1846 return acpi_video_bus_DOS(video, 0, 1);
1847}
1848
Len Brown4be44fc2005-08-05 00:44:28 -04001849static void acpi_video_bus_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_bus *video = data;
Len Brown4be44fc2005-08-05 00:44:28 -04001852 struct acpi_device *device = NULL;
Luming Yue9dab192007-08-20 18:23:53 +08001853 struct input_dev *input;
1854 int keycode;
1855
Linus Torvalds1da177e2005-04-16 15:20:36 -07001856 if (!video)
Patrick Mocheld550d982006-06-27 00:41:40 -04001857 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001858
Patrick Mochele6afa0d2006-05-19 16:54:40 -04001859 device = video->device;
Luming Yue9dab192007-08-20 18:23:53 +08001860 input = video->input;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001861
1862 switch (event) {
Julius Volz98fb8fe2007-02-20 16:38:40 +01001863 case ACPI_VIDEO_NOTIFY_SWITCH: /* User requested a switch,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001864 * most likely via hotkey. */
Len Brown14e04fb2007-08-23 15:20:26 -04001865 acpi_bus_generate_proc_event(device, event, 0);
Luming Yue9dab192007-08-20 18:23:53 +08001866 keycode = KEY_SWITCHVIDEOMODE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001867 break;
1868
Julius Volz98fb8fe2007-02-20 16:38:40 +01001869 case ACPI_VIDEO_NOTIFY_PROBE: /* User plugged in or removed a video
Linus Torvalds1da177e2005-04-16 15:20:36 -07001870 * connector. */
1871 acpi_video_device_enumerate(video);
1872 acpi_video_device_rebind(video);
Len Brown14e04fb2007-08-23 15:20:26 -04001873 acpi_bus_generate_proc_event(device, event, 0);
Luming Yue9dab192007-08-20 18:23:53 +08001874 keycode = KEY_SWITCHVIDEOMODE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001875 break;
1876
Len Brown4be44fc2005-08-05 00:44:28 -04001877 case ACPI_VIDEO_NOTIFY_CYCLE: /* Cycle Display output hotkey pressed. */
Len Brown25c87f72007-08-25 01:44:01 -04001878 acpi_bus_generate_proc_event(device, event, 0);
Luming Yue9dab192007-08-20 18:23:53 +08001879 keycode = KEY_SWITCHVIDEOMODE;
1880 break;
Len Brown4be44fc2005-08-05 00:44:28 -04001881 case ACPI_VIDEO_NOTIFY_NEXT_OUTPUT: /* Next Display output hotkey pressed. */
Len Brown25c87f72007-08-25 01:44:01 -04001882 acpi_bus_generate_proc_event(device, event, 0);
Luming Yue9dab192007-08-20 18:23:53 +08001883 keycode = KEY_VIDEO_NEXT;
1884 break;
Len Brown4be44fc2005-08-05 00:44:28 -04001885 case ACPI_VIDEO_NOTIFY_PREV_OUTPUT: /* previous Display output hotkey pressed. */
Len Brown14e04fb2007-08-23 15:20:26 -04001886 acpi_bus_generate_proc_event(device, event, 0);
Luming Yue9dab192007-08-20 18:23:53 +08001887 keycode = KEY_VIDEO_PREV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001888 break;
1889
1890 default:
Luming Yue9dab192007-08-20 18:23:53 +08001891 keycode = KEY_UNKNOWN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001892 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
Len Brown4be44fc2005-08-05 00:44:28 -04001893 "Unsupported event [0x%x]\n", event));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001894 break;
1895 }
1896
Zhang Rui7761f632008-01-25 14:48:12 +08001897 acpi_notifier_call_chain(device, event, 0);
Luming Yue9dab192007-08-20 18:23:53 +08001898 input_report_key(input, keycode, 1);
1899 input_sync(input);
1900 input_report_key(input, keycode, 0);
1901 input_sync(input);
1902
Patrick Mocheld550d982006-06-27 00:41:40 -04001903 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001904}
1905
Len Brown4be44fc2005-08-05 00:44:28 -04001906static void acpi_video_device_notify(acpi_handle handle, u32 event, void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001907{
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001908 struct acpi_video_device *video_device = data;
Len Brown4be44fc2005-08-05 00:44:28 -04001909 struct acpi_device *device = NULL;
Luming Yue9dab192007-08-20 18:23:53 +08001910 struct acpi_video_bus *bus;
1911 struct input_dev *input;
1912 int keycode;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001913
Linus Torvalds1da177e2005-04-16 15:20:36 -07001914 if (!video_device)
Patrick Mocheld550d982006-06-27 00:41:40 -04001915 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001916
Patrick Mochele6afa0d2006-05-19 16:54:40 -04001917 device = video_device->dev;
Luming Yue9dab192007-08-20 18:23:53 +08001918 bus = video_device->video;
1919 input = bus->input;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001920
1921 switch (event) {
Len Brown4be44fc2005-08-05 00:44:28 -04001922 case ACPI_VIDEO_NOTIFY_CYCLE_BRIGHTNESS: /* Cycle brightness */
Zhang Rui8a681a42008-01-25 14:47:49 +08001923 if (brightness_switch_enabled)
1924 acpi_video_switch_brightness(video_device, event);
Len Brown25c87f72007-08-25 01:44:01 -04001925 acpi_bus_generate_proc_event(device, event, 0);
Luming Yue9dab192007-08-20 18:23:53 +08001926 keycode = KEY_BRIGHTNESS_CYCLE;
1927 break;
Len Brown4be44fc2005-08-05 00:44:28 -04001928 case ACPI_VIDEO_NOTIFY_INC_BRIGHTNESS: /* Increase brightness */
Zhang Rui8a681a42008-01-25 14:47:49 +08001929 if (brightness_switch_enabled)
1930 acpi_video_switch_brightness(video_device, event);
Len Brown25c87f72007-08-25 01:44:01 -04001931 acpi_bus_generate_proc_event(device, event, 0);
Luming Yue9dab192007-08-20 18:23:53 +08001932 keycode = KEY_BRIGHTNESSUP;
1933 break;
Len Brown4be44fc2005-08-05 00:44:28 -04001934 case ACPI_VIDEO_NOTIFY_DEC_BRIGHTNESS: /* Decrease brightness */
Zhang Rui8a681a42008-01-25 14:47:49 +08001935 if (brightness_switch_enabled)
1936 acpi_video_switch_brightness(video_device, event);
Len Brown25c87f72007-08-25 01:44:01 -04001937 acpi_bus_generate_proc_event(device, event, 0);
Luming Yue9dab192007-08-20 18:23:53 +08001938 keycode = KEY_BRIGHTNESSDOWN;
1939 break;
Len Brown4be44fc2005-08-05 00:44:28 -04001940 case ACPI_VIDEO_NOTIFY_ZERO_BRIGHTNESS: /* zero brightnesss */
Zhang Rui8a681a42008-01-25 14:47:49 +08001941 if (brightness_switch_enabled)
1942 acpi_video_switch_brightness(video_device, event);
Len Brown25c87f72007-08-25 01:44:01 -04001943 acpi_bus_generate_proc_event(device, event, 0);
Luming Yue9dab192007-08-20 18:23:53 +08001944 keycode = KEY_BRIGHTNESS_ZERO;
1945 break;
Len Brown4be44fc2005-08-05 00:44:28 -04001946 case ACPI_VIDEO_NOTIFY_DISPLAY_OFF: /* display device off */
Zhang Rui8a681a42008-01-25 14:47:49 +08001947 if (brightness_switch_enabled)
1948 acpi_video_switch_brightness(video_device, event);
Len Brown14e04fb2007-08-23 15:20:26 -04001949 acpi_bus_generate_proc_event(device, event, 0);
Luming Yue9dab192007-08-20 18:23:53 +08001950 keycode = KEY_DISPLAY_OFF;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001951 break;
1952 default:
Luming Yue9dab192007-08-20 18:23:53 +08001953 keycode = KEY_UNKNOWN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001954 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
Len Brown4be44fc2005-08-05 00:44:28 -04001955 "Unsupported event [0x%x]\n", event));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001956 break;
1957 }
Luming Yue9dab192007-08-20 18:23:53 +08001958
Zhang Rui7761f632008-01-25 14:48:12 +08001959 acpi_notifier_call_chain(device, event, 0);
Luming Yue9dab192007-08-20 18:23:53 +08001960 input_report_key(input, keycode, 1);
1961 input_sync(input);
1962 input_report_key(input, keycode, 0);
1963 input_sync(input);
1964
Patrick Mocheld550d982006-06-27 00:41:40 -04001965 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001966}
1967
Zhang Ruie6d9da12007-08-25 02:23:31 -04001968static int instance;
Matthew Garrett863c1492008-02-04 23:31:24 -08001969static int acpi_video_resume(struct acpi_device *device)
1970{
1971 struct acpi_video_bus *video;
1972 struct acpi_video_device *video_device;
1973 int i;
1974
1975 if (!device || !acpi_driver_data(device))
1976 return -EINVAL;
1977
1978 video = acpi_driver_data(device);
1979
1980 for (i = 0; i < video->attached_count; i++) {
1981 video_device = video->attached_array[i].bind_info;
1982 if (video_device && video_device->backlight)
1983 acpi_video_set_brightness(video_device->backlight);
1984 }
1985 return AE_OK;
1986}
1987
Len Brown4be44fc2005-08-05 00:44:28 -04001988static int acpi_video_bus_add(struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001989{
Dmitry Torokhovf51e8392007-11-05 11:43:30 -05001990 acpi_status status;
1991 struct acpi_video_bus *video;
Luming Yue9dab192007-08-20 18:23:53 +08001992 struct input_dev *input;
Dmitry Torokhovf51e8392007-11-05 11:43:30 -05001993 int error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001994
Burman Yan36bcbec2006-12-19 12:56:11 -08001995 video = kzalloc(sizeof(struct acpi_video_bus), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001996 if (!video)
Patrick Mocheld550d982006-06-27 00:41:40 -04001997 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001998
Zhang Ruie6d9da12007-08-25 02:23:31 -04001999 /* a hack to fix the duplicate name "VID" problem on T61 */
2000 if (!strcmp(device->pnp.bus_id, "VID")) {
2001 if (instance)
2002 device->pnp.bus_id[3] = '0' + instance;
2003 instance ++;
2004 }
Zhao Yakuif3b39f12009-02-02 22:55:01 -05002005 /* a hack to fix the duplicate name "VGA" problem on Pa 3553 */
2006 if (!strcmp(device->pnp.bus_id, "VGA")) {
2007 if (instance)
2008 device->pnp.bus_id[3] = '0' + instance;
2009 instance++;
2010 }
Zhang Ruie6d9da12007-08-25 02:23:31 -04002011
Patrick Mochele6afa0d2006-05-19 16:54:40 -04002012 video->device = device;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002013 strcpy(acpi_device_name(device), ACPI_VIDEO_BUS_NAME);
2014 strcpy(acpi_device_class(device), ACPI_VIDEO_CLASS);
Pavel Machekdb89b4f2008-09-22 14:37:34 -07002015 device->driver_data = video;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002016
2017 acpi_video_bus_find_cap(video);
Dmitry Torokhovf51e8392007-11-05 11:43:30 -05002018 error = acpi_video_bus_check(video);
2019 if (error)
2020 goto err_free_video;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002021
Dmitry Torokhovf51e8392007-11-05 11:43:30 -05002022 error = acpi_video_bus_add_fs(device);
2023 if (error)
2024 goto err_free_video;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002025
Dmitry Torokhovbbac81f2007-11-05 11:43:32 -05002026 mutex_init(&video->device_list_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002027 INIT_LIST_HEAD(&video->video_device_list);
2028
2029 acpi_video_bus_get_devices(video, device);
2030 acpi_video_bus_start_devices(video);
2031
Patrick Mochel90130262006-05-19 16:54:48 -04002032 status = acpi_install_notify_handler(device->handle,
Len Brown4be44fc2005-08-05 00:44:28 -04002033 ACPI_DEVICE_NOTIFY,
2034 acpi_video_bus_notify, video);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002035 if (ACPI_FAILURE(status)) {
Lin Ming55ac9a02008-09-28 14:51:56 +08002036 printk(KERN_ERR PREFIX
2037 "Error installing notify handler\n");
Dmitry Torokhovf51e8392007-11-05 11:43:30 -05002038 error = -ENODEV;
2039 goto err_stop_video;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002040 }
2041
Luming Yue9dab192007-08-20 18:23:53 +08002042 video->input = input = input_allocate_device();
Dmitry Torokhovf51e8392007-11-05 11:43:30 -05002043 if (!input) {
2044 error = -ENOMEM;
2045 goto err_uninstall_notify;
2046 }
Luming Yue9dab192007-08-20 18:23:53 +08002047
2048 snprintf(video->phys, sizeof(video->phys),
2049 "%s/video/input0", acpi_device_hid(video->device));
2050
2051 input->name = acpi_device_name(video->device);
2052 input->phys = video->phys;
2053 input->id.bustype = BUS_HOST;
2054 input->id.product = 0x06;
Dmitry Torokhov91c05c62007-11-05 11:43:29 -05002055 input->dev.parent = &device->dev;
Luming Yue9dab192007-08-20 18:23:53 +08002056 input->evbit[0] = BIT(EV_KEY);
2057 set_bit(KEY_SWITCHVIDEOMODE, input->keybit);
2058 set_bit(KEY_VIDEO_NEXT, input->keybit);
2059 set_bit(KEY_VIDEO_PREV, input->keybit);
2060 set_bit(KEY_BRIGHTNESS_CYCLE, input->keybit);
2061 set_bit(KEY_BRIGHTNESSUP, input->keybit);
2062 set_bit(KEY_BRIGHTNESSDOWN, input->keybit);
2063 set_bit(KEY_BRIGHTNESS_ZERO, input->keybit);
2064 set_bit(KEY_DISPLAY_OFF, input->keybit);
2065 set_bit(KEY_UNKNOWN, input->keybit);
Luming Yue9dab192007-08-20 18:23:53 +08002066
Dmitry Torokhovf51e8392007-11-05 11:43:30 -05002067 error = input_register_device(input);
2068 if (error)
2069 goto err_free_input_dev;
Luming Yue9dab192007-08-20 18:23:53 +08002070
Linus Torvalds1da177e2005-04-16 15:20:36 -07002071 printk(KERN_INFO PREFIX "%s [%s] (multi-head: %s rom: %s post: %s)\n",
Len Brown4be44fc2005-08-05 00:44:28 -04002072 ACPI_VIDEO_DEVICE_NAME, acpi_device_bid(device),
2073 video->flags.multihead ? "yes" : "no",
2074 video->flags.rom ? "yes" : "no",
2075 video->flags.post ? "yes" : "no");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002076
Dmitry Torokhovf51e8392007-11-05 11:43:30 -05002077 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002078
Dmitry Torokhovf51e8392007-11-05 11:43:30 -05002079 err_free_input_dev:
2080 input_free_device(input);
2081 err_uninstall_notify:
2082 acpi_remove_notify_handler(device->handle, ACPI_DEVICE_NOTIFY,
2083 acpi_video_bus_notify);
2084 err_stop_video:
2085 acpi_video_bus_stop_devices(video);
2086 acpi_video_bus_put_devices(video);
2087 kfree(video->attached_array);
2088 acpi_video_bus_remove_fs(device);
2089 err_free_video:
2090 kfree(video);
Pavel Machekdb89b4f2008-09-22 14:37:34 -07002091 device->driver_data = NULL;
Dmitry Torokhovf51e8392007-11-05 11:43:30 -05002092
2093 return error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002094}
2095
Len Brown4be44fc2005-08-05 00:44:28 -04002096static int acpi_video_bus_remove(struct acpi_device *device, int type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002097{
Len Brown4be44fc2005-08-05 00:44:28 -04002098 acpi_status status = 0;
2099 struct acpi_video_bus *video = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002100
Linus Torvalds1da177e2005-04-16 15:20:36 -07002101
2102 if (!device || !acpi_driver_data(device))
Patrick Mocheld550d982006-06-27 00:41:40 -04002103 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002104
Jan Engelhardt50dd0962006-10-01 00:28:50 +02002105 video = acpi_driver_data(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002106
2107 acpi_video_bus_stop_devices(video);
2108
Patrick Mochel90130262006-05-19 16:54:48 -04002109 status = acpi_remove_notify_handler(video->device->handle,
Len Brown4be44fc2005-08-05 00:44:28 -04002110 ACPI_DEVICE_NOTIFY,
2111 acpi_video_bus_notify);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002112
2113 acpi_video_bus_put_devices(video);
2114 acpi_video_bus_remove_fs(device);
2115
Luming Yue9dab192007-08-20 18:23:53 +08002116 input_unregister_device(video->input);
Jesper Juhl6044ec82005-11-07 01:01:32 -08002117 kfree(video->attached_array);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002118 kfree(video);
2119
Patrick Mocheld550d982006-06-27 00:41:40 -04002120 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002121}
2122
Len Brown4be44fc2005-08-05 00:44:28 -04002123static int __init acpi_video_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002124{
Len Brown4be44fc2005-08-05 00:44:28 -04002125 int result = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002126
Linus Torvalds1da177e2005-04-16 15:20:36 -07002127 acpi_video_dir = proc_mkdir(ACPI_VIDEO_CLASS, acpi_root_dir);
2128 if (!acpi_video_dir)
Patrick Mocheld550d982006-06-27 00:41:40 -04002129 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002130
2131 result = acpi_bus_register_driver(&acpi_video_bus);
2132 if (result < 0) {
2133 remove_proc_entry(ACPI_VIDEO_CLASS, acpi_root_dir);
Patrick Mocheld550d982006-06-27 00:41:40 -04002134 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002135 }
2136
Patrick Mocheld550d982006-06-27 00:41:40 -04002137 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002138}
2139
Len Brown4be44fc2005-08-05 00:44:28 -04002140static void __exit acpi_video_exit(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002141{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002142
2143 acpi_bus_unregister_driver(&acpi_video_bus);
2144
2145 remove_proc_entry(ACPI_VIDEO_CLASS, acpi_root_dir);
2146
Patrick Mocheld550d982006-06-27 00:41:40 -04002147 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002148}
2149
2150module_init(acpi_video_init);
2151module_exit(acpi_video_exit);