blob: 38bf8b43fd19eba47111b3a068444927839f3b75 [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 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700485
Linus Torvalds1da177e2005-04-16 15:20:36 -0700486
487 arg0.integer.value = level;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700488
Alexey Starikovskiy4500ca82007-09-03 16:29:58 +0400489 if (device->cap._BCM)
490 status = acpi_evaluate_object(device->dev->handle, "_BCM",
491 &args, NULL);
492 device->brightness->curr = level;
Patrick Mocheld550d982006-06-27 00:41:40 -0400493 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700494}
495
496static int
Len Brown4be44fc2005-08-05 00:44:28 -0400497acpi_video_device_lcd_get_level_current(struct acpi_video_device *device,
Matthew Wilcox27663c52008-10-10 02:22:59 -0400498 unsigned long long *level)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700499{
Alexey Starikovskiy4500ca82007-09-03 16:29:58 +0400500 if (device->cap._BQC)
501 return acpi_evaluate_integer(device->dev->handle, "_BQC", NULL,
502 level);
503 *level = device->brightness->curr;
504 return AE_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700505}
506
507static int
Len Brown4be44fc2005-08-05 00:44:28 -0400508acpi_video_device_EDID(struct acpi_video_device *device,
509 union acpi_object **edid, ssize_t length)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700510{
Len Brown4be44fc2005-08-05 00:44:28 -0400511 int status;
512 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
513 union acpi_object *obj;
514 union acpi_object arg0 = { ACPI_TYPE_INTEGER };
515 struct acpi_object_list args = { 1, &arg0 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700516
Linus Torvalds1da177e2005-04-16 15:20:36 -0700517
518 *edid = NULL;
519
520 if (!device)
Patrick Mocheld550d982006-06-27 00:41:40 -0400521 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700522 if (length == 128)
523 arg0.integer.value = 1;
524 else if (length == 256)
525 arg0.integer.value = 2;
526 else
Patrick Mocheld550d982006-06-27 00:41:40 -0400527 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700528
Patrick Mochel90130262006-05-19 16:54:48 -0400529 status = acpi_evaluate_object(device->dev->handle, "_DDC", &args, &buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700530 if (ACPI_FAILURE(status))
Patrick Mocheld550d982006-06-27 00:41:40 -0400531 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700532
Jan Engelhardt50dd0962006-10-01 00:28:50 +0200533 obj = buffer.pointer;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700534
535 if (obj && obj->type == ACPI_TYPE_BUFFER)
536 *edid = obj;
537 else {
Len Brown64684632006-06-26 23:41:38 -0400538 printk(KERN_ERR PREFIX "Invalid _DDC data\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700539 status = -EFAULT;
540 kfree(obj);
541 }
542
Patrick Mocheld550d982006-06-27 00:41:40 -0400543 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700544}
545
Linus Torvalds1da177e2005-04-16 15:20:36 -0700546/* bus */
547
548static int
Len Brown4be44fc2005-08-05 00:44:28 -0400549acpi_video_bus_set_POST(struct acpi_video_bus *video, unsigned long option)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700550{
Len Brown4be44fc2005-08-05 00:44:28 -0400551 int status;
Matthew Wilcox27663c52008-10-10 02:22:59 -0400552 unsigned long long tmp;
Len Brown4be44fc2005-08-05 00:44:28 -0400553 union acpi_object arg0 = { ACPI_TYPE_INTEGER };
554 struct acpi_object_list args = { 1, &arg0 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700555
Linus Torvalds1da177e2005-04-16 15:20:36 -0700556
557 arg0.integer.value = option;
558
Patrick Mochel90130262006-05-19 16:54:48 -0400559 status = acpi_evaluate_integer(video->device->handle, "_SPD", &args, &tmp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700560 if (ACPI_SUCCESS(status))
Len Brown4be44fc2005-08-05 00:44:28 -0400561 status = tmp ? (-EINVAL) : (AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700562
Patrick Mocheld550d982006-06-27 00:41:40 -0400563 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700564}
565
566static int
Matthew Wilcox27663c52008-10-10 02:22:59 -0400567acpi_video_bus_get_POST(struct acpi_video_bus *video, unsigned long long *id)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700568{
569 int status;
570
Patrick Mochel90130262006-05-19 16:54:48 -0400571 status = acpi_evaluate_integer(video->device->handle, "_GPD", NULL, id);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700572
Patrick Mocheld550d982006-06-27 00:41:40 -0400573 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700574}
575
576static int
Len Brown4be44fc2005-08-05 00:44:28 -0400577acpi_video_bus_POST_options(struct acpi_video_bus *video,
Matthew Wilcox27663c52008-10-10 02:22:59 -0400578 unsigned long long *options)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700579{
Len Brown4be44fc2005-08-05 00:44:28 -0400580 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700581
Patrick Mochel90130262006-05-19 16:54:48 -0400582 status = acpi_evaluate_integer(video->device->handle, "_VPO", NULL, options);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700583 *options &= 3;
584
Patrick Mocheld550d982006-06-27 00:41:40 -0400585 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700586}
587
588/*
589 * Arg:
590 * video : video bus device pointer
591 * bios_flag :
592 * 0. The system BIOS should NOT automatically switch(toggle)
593 * the active display output.
594 * 1. The system BIOS should automatically switch (toggle) the
Julius Volz98fb8fe2007-02-20 16:38:40 +0100595 * active display output. No switch event.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700596 * 2. The _DGS value should be locked.
597 * 3. The system BIOS should not automatically switch (toggle) the
598 * active display output, but instead generate the display switch
599 * event notify code.
600 * lcd_flag :
601 * 0. The system BIOS should automatically control the brightness level
Julius Volz98fb8fe2007-02-20 16:38:40 +0100602 * of the LCD when the power changes from AC to DC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700603 * 1. The system BIOS should NOT automatically control the brightness
Julius Volz98fb8fe2007-02-20 16:38:40 +0100604 * level of the LCD when the power changes from AC to DC.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700605 * Return Value:
606 * -1 wrong arg.
607 */
608
609static int
Len Brown4be44fc2005-08-05 00:44:28 -0400610acpi_video_bus_DOS(struct acpi_video_bus *video, int bios_flag, int lcd_flag)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700611{
Len Brown4be44fc2005-08-05 00:44:28 -0400612 acpi_integer status = 0;
613 union acpi_object arg0 = { ACPI_TYPE_INTEGER };
614 struct acpi_object_list args = { 1, &arg0 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700615
Linus Torvalds1da177e2005-04-16 15:20:36 -0700616
Len Brown4be44fc2005-08-05 00:44:28 -0400617 if (bios_flag < 0 || bios_flag > 3 || lcd_flag < 0 || lcd_flag > 1) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700618 status = -1;
619 goto Failed;
620 }
621 arg0.integer.value = (lcd_flag << 2) | bios_flag;
622 video->dos_setting = arg0.integer.value;
Patrick Mochel90130262006-05-19 16:54:48 -0400623 acpi_evaluate_object(video->device->handle, "_DOS", &args, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700624
Len Brown4be44fc2005-08-05 00:44:28 -0400625 Failed:
Patrick Mocheld550d982006-06-27 00:41:40 -0400626 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700627}
628
629/*
Zhang Rui935e5f22008-12-11 16:24:52 -0500630 * Simple comparison function used to sort backlight levels.
631 */
632
633static int
634acpi_video_cmp_level(const void *a, const void *b)
635{
636 return *(int *)a - *(int *)b;
637}
638
639/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700640 * Arg:
641 * device : video output device (LCD, CRT, ..)
642 *
643 * Return Value:
Julia Jomantaite469778c2008-06-23 22:50:42 +0100644 * Maximum brightness level
645 *
646 * Allocate and initialize device->brightness.
647 */
648
649static int
650acpi_video_init_brightness(struct acpi_video_device *device)
651{
652 union acpi_object *obj = NULL;
653 int i, max_level = 0, count = 0;
654 union acpi_object *o;
655 struct acpi_video_device_brightness *br = NULL;
656
657 if (!ACPI_SUCCESS(acpi_video_device_lcd_query_levels(device, &obj))) {
658 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Could not query available "
659 "LCD brightness level\n"));
660 goto out;
661 }
662
663 if (obj->package.count < 2)
664 goto out;
665
666 br = kzalloc(sizeof(*br), GFP_KERNEL);
667 if (!br) {
668 printk(KERN_ERR "can't allocate memory\n");
669 goto out;
670 }
671
672 br->levels = kmalloc(obj->package.count * sizeof *(br->levels),
673 GFP_KERNEL);
674 if (!br->levels)
675 goto out_free;
676
677 for (i = 0; i < obj->package.count; i++) {
678 o = (union acpi_object *)&obj->package.elements[i];
679 if (o->type != ACPI_TYPE_INTEGER) {
680 printk(KERN_ERR PREFIX "Invalid data\n");
681 continue;
682 }
683 br->levels[count] = (u32) o->integer.value;
684
685 if (br->levels[count] > max_level)
686 max_level = br->levels[count];
687 count++;
688 }
689
Zhang Rui935e5f22008-12-11 16:24:52 -0500690 /* don't sort the first two brightness levels */
691 sort(&br->levels[2], count - 2, sizeof(br->levels[2]),
692 acpi_video_cmp_level, NULL);
693
Julia Jomantaite469778c2008-06-23 22:50:42 +0100694 if (count < 2)
695 goto out_free_levels;
696
697 br->count = count;
698 device->brightness = br;
699 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "found %d brightness levels\n", count));
700 kfree(obj);
701 return max_level;
702
703out_free_levels:
704 kfree(br->levels);
705out_free:
706 kfree(br);
707out:
708 device->brightness = NULL;
709 kfree(obj);
710 return 0;
711}
712
713/*
714 * Arg:
715 * device : video output device (LCD, CRT, ..)
716 *
717 * Return Value:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700718 * None
719 *
Julius Volz98fb8fe2007-02-20 16:38:40 +0100720 * Find out all required AML methods defined under the output
Linus Torvalds1da177e2005-04-16 15:20:36 -0700721 * device.
722 */
723
Len Brown4be44fc2005-08-05 00:44:28 -0400724static void acpi_video_device_find_cap(struct acpi_video_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700725{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700726 acpi_handle h_dummy1;
Yu Luming2f3d0002006-11-11 02:40:34 +0800727 u32 max_level = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700728
Linus Torvalds1da177e2005-04-16 15:20:36 -0700729
William Lee Irwin III98934de2007-12-12 03:56:55 -0800730 memset(&device->cap, 0, sizeof(device->cap));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700731
Patrick Mochel90130262006-05-19 16:54:48 -0400732 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_ADR", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700733 device->cap._ADR = 1;
734 }
Patrick Mochel90130262006-05-19 16:54:48 -0400735 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_BCL", &h_dummy1))) {
Len Brown4be44fc2005-08-05 00:44:28 -0400736 device->cap._BCL = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700737 }
Patrick Mochel90130262006-05-19 16:54:48 -0400738 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_BCM", &h_dummy1))) {
Len Brown4be44fc2005-08-05 00:44:28 -0400739 device->cap._BCM = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700740 }
Yu Luming2f3d0002006-11-11 02:40:34 +0800741 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle,"_BQC",&h_dummy1)))
742 device->cap._BQC = 1;
Patrick Mochel90130262006-05-19 16:54:48 -0400743 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_DDC", &h_dummy1))) {
Len Brown4be44fc2005-08-05 00:44:28 -0400744 device->cap._DDC = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700745 }
Patrick Mochel90130262006-05-19 16:54:48 -0400746 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_DCS", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700747 device->cap._DCS = 1;
748 }
Patrick Mochel90130262006-05-19 16:54:48 -0400749 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_DGS", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700750 device->cap._DGS = 1;
751 }
Patrick Mochel90130262006-05-19 16:54:48 -0400752 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_DSS", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700753 device->cap._DSS = 1;
754 }
755
Thomas Renningerc3d6de62008-08-01 17:37:55 +0200756 if (acpi_video_backlight_support())
757 max_level = acpi_video_init_brightness(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700758
Zhao Yakuic2c78902008-07-17 10:46:05 +0800759 if (device->cap._BCL && device->cap._BCM && max_level > 0) {
Zhang Rui702ed512008-01-17 15:51:22 +0800760 int result;
Yu Luming2f3d0002006-11-11 02:40:34 +0800761 static int count = 0;
762 char *name;
Yu Luming2f3d0002006-11-11 02:40:34 +0800763 name = kzalloc(MAX_NAME_LEN, GFP_KERNEL);
764 if (!name)
765 return;
766
Yu Luming2f3d0002006-11-11 02:40:34 +0800767 sprintf(name, "acpi_video%d", count++);
Yu Luming2f3d0002006-11-11 02:40:34 +0800768 device->backlight = backlight_device_register(name,
Richard Purdie599a52d2007-02-10 23:07:48 +0000769 NULL, device, &acpi_backlight_ops);
Matthew Garrett38531e62007-12-26 02:03:26 +0000770 device->backlight->props.max_brightness = device->brightness->count-3;
Zhao Yakuic2c78902008-07-17 10:46:05 +0800771 /*
772 * If there exists the _BQC object, the _BQC object will be
773 * called to get the current backlight brightness. Otherwise
774 * the brightness will be set to the maximum.
775 */
776 if (device->cap._BQC)
777 device->backlight->props.brightness =
778 acpi_video_get_brightness(device->backlight);
779 else
780 device->backlight->props.brightness =
781 device->backlight->props.max_brightness;
Richard Purdie599a52d2007-02-10 23:07:48 +0000782 backlight_update_status(device->backlight);
Yu Luming2f3d0002006-11-11 02:40:34 +0800783 kfree(name);
Zhang Rui702ed512008-01-17 15:51:22 +0800784
785 device->cdev = thermal_cooling_device_register("LCD",
786 device->dev, &video_cooling_ops);
Thomas Sujith43ff39f2008-02-15 18:29:18 -0500787 if (IS_ERR(device->cdev))
788 return;
789
Greg Kroah-Hartmanfc3a8822008-05-02 06:02:41 +0200790 dev_info(&device->dev->dev, "registered as cooling_device%d\n",
791 device->cdev->id);
Julia Lawall90300622008-04-11 10:09:24 +0800792 result = sysfs_create_link(&device->dev->dev.kobj,
793 &device->cdev->device.kobj,
794 "thermal_cooling");
795 if (result)
796 printk(KERN_ERR PREFIX "Create sysfs link\n");
797 result = sysfs_create_link(&device->cdev->device.kobj,
798 &device->dev->dev.kobj, "device");
799 if (result)
800 printk(KERN_ERR PREFIX "Create sysfs link\n");
801
Yu Luming2f3d0002006-11-11 02:40:34 +0800802 }
Thomas Renningerc3d6de62008-08-01 17:37:55 +0200803
804 if (acpi_video_display_switch_support()) {
805
806 if (device->cap._DCS && device->cap._DSS) {
807 static int count;
808 char *name;
809 name = kzalloc(MAX_NAME_LEN, GFP_KERNEL);
810 if (!name)
811 return;
812 sprintf(name, "acpi_video%d", count++);
813 device->output_dev = video_output_register(name,
814 NULL, device, &acpi_output_properties);
815 kfree(name);
816 }
Luming Yu23b0f012007-05-09 21:07:05 +0800817 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700818}
819
820/*
821 * Arg:
822 * device : video output device (VGA)
823 *
824 * Return Value:
825 * None
826 *
Julius Volz98fb8fe2007-02-20 16:38:40 +0100827 * Find out all required AML methods defined under the video bus device.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700828 */
829
Len Brown4be44fc2005-08-05 00:44:28 -0400830static void acpi_video_bus_find_cap(struct acpi_video_bus *video)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700831{
Len Brown4be44fc2005-08-05 00:44:28 -0400832 acpi_handle h_dummy1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700833
William Lee Irwin III98934de2007-12-12 03:56:55 -0800834 memset(&video->cap, 0, sizeof(video->cap));
Patrick Mochel90130262006-05-19 16:54:48 -0400835 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_DOS", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700836 video->cap._DOS = 1;
837 }
Patrick Mochel90130262006-05-19 16:54:48 -0400838 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_DOD", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700839 video->cap._DOD = 1;
840 }
Patrick Mochel90130262006-05-19 16:54:48 -0400841 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_ROM", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700842 video->cap._ROM = 1;
843 }
Patrick Mochel90130262006-05-19 16:54:48 -0400844 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_GPD", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700845 video->cap._GPD = 1;
846 }
Patrick Mochel90130262006-05-19 16:54:48 -0400847 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_SPD", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700848 video->cap._SPD = 1;
849 }
Patrick Mochel90130262006-05-19 16:54:48 -0400850 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_VPO", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700851 video->cap._VPO = 1;
852 }
853}
854
855/*
856 * Check whether the video bus device has required AML method to
857 * support the desired features
858 */
859
Len Brown4be44fc2005-08-05 00:44:28 -0400860static int acpi_video_bus_check(struct acpi_video_bus *video)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700861{
Len Brown4be44fc2005-08-05 00:44:28 -0400862 acpi_status status = -ENOENT;
Thomas Renninger22c13f92008-08-01 17:37:54 +0200863 struct device *dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700864
865 if (!video)
Patrick Mocheld550d982006-06-27 00:41:40 -0400866 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700867
Thomas Renninger22c13f92008-08-01 17:37:54 +0200868 dev = acpi_get_physical_pci_device(video->device->handle);
869 if (!dev)
870 return -ENODEV;
871 put_device(dev);
872
Linus Torvalds1da177e2005-04-16 15:20:36 -0700873 /* Since there is no HID, CID and so on for VGA driver, we have
874 * to check well known required nodes.
875 */
876
Julius Volz98fb8fe2007-02-20 16:38:40 +0100877 /* Does this device support video switching? */
Len Brown4be44fc2005-08-05 00:44:28 -0400878 if (video->cap._DOS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700879 video->flags.multihead = 1;
880 status = 0;
881 }
882
Julius Volz98fb8fe2007-02-20 16:38:40 +0100883 /* Does this device support retrieving a video ROM? */
Len Brown4be44fc2005-08-05 00:44:28 -0400884 if (video->cap._ROM) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700885 video->flags.rom = 1;
886 status = 0;
887 }
888
Julius Volz98fb8fe2007-02-20 16:38:40 +0100889 /* Does this device support configuring which video device to POST? */
Len Brown4be44fc2005-08-05 00:44:28 -0400890 if (video->cap._GPD && video->cap._SPD && video->cap._VPO) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700891 video->flags.post = 1;
892 status = 0;
893 }
894
Patrick Mocheld550d982006-06-27 00:41:40 -0400895 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700896}
897
898/* --------------------------------------------------------------------------
899 FS Interface (/proc)
900 -------------------------------------------------------------------------- */
901
Len Brown4be44fc2005-08-05 00:44:28 -0400902static struct proc_dir_entry *acpi_video_dir;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700903
904/* video devices */
905
Len Brown4be44fc2005-08-05 00:44:28 -0400906static int acpi_video_device_info_seq_show(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700907{
Jan Engelhardt50dd0962006-10-01 00:28:50 +0200908 struct acpi_video_device *dev = seq->private;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700909
Linus Torvalds1da177e2005-04-16 15:20:36 -0700910
911 if (!dev)
912 goto end;
913
914 seq_printf(seq, "device_id: 0x%04x\n", (u32) dev->device_id);
915 seq_printf(seq, "type: ");
916 if (dev->flags.crt)
917 seq_printf(seq, "CRT\n");
918 else if (dev->flags.lcd)
919 seq_printf(seq, "LCD\n");
920 else if (dev->flags.tvout)
921 seq_printf(seq, "TVOUT\n");
Rui Zhang82cae992007-01-03 23:40:53 -0500922 else if (dev->flags.dvi)
923 seq_printf(seq, "DVI\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700924 else
925 seq_printf(seq, "UNKNOWN\n");
926
Len Brown4be44fc2005-08-05 00:44:28 -0400927 seq_printf(seq, "known by bios: %s\n", dev->flags.bios ? "yes" : "no");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700928
Len Brown4be44fc2005-08-05 00:44:28 -0400929 end:
Patrick Mocheld550d982006-06-27 00:41:40 -0400930 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700931}
932
933static int
Len Brown4be44fc2005-08-05 00:44:28 -0400934acpi_video_device_info_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700935{
936 return single_open(file, acpi_video_device_info_seq_show,
937 PDE(inode)->data);
938}
939
Len Brown4be44fc2005-08-05 00:44:28 -0400940static int acpi_video_device_state_seq_show(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700941{
Len Brown4be44fc2005-08-05 00:44:28 -0400942 int status;
Jan Engelhardt50dd0962006-10-01 00:28:50 +0200943 struct acpi_video_device *dev = seq->private;
Matthew Wilcox27663c52008-10-10 02:22:59 -0400944 unsigned long long state;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700945
Linus Torvalds1da177e2005-04-16 15:20:36 -0700946
947 if (!dev)
948 goto end;
949
950 status = acpi_video_device_get_state(dev, &state);
951 seq_printf(seq, "state: ");
952 if (ACPI_SUCCESS(status))
Matthew Wilcox27663c52008-10-10 02:22:59 -0400953 seq_printf(seq, "0x%02llx\n", state);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700954 else
955 seq_printf(seq, "<not supported>\n");
956
957 status = acpi_video_device_query(dev, &state);
958 seq_printf(seq, "query: ");
959 if (ACPI_SUCCESS(status))
Matthew Wilcox27663c52008-10-10 02:22:59 -0400960 seq_printf(seq, "0x%02llx\n", state);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700961 else
962 seq_printf(seq, "<not supported>\n");
963
Len Brown4be44fc2005-08-05 00:44:28 -0400964 end:
Patrick Mocheld550d982006-06-27 00:41:40 -0400965 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700966}
967
968static int
Len Brown4be44fc2005-08-05 00:44:28 -0400969acpi_video_device_state_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700970{
971 return single_open(file, acpi_video_device_state_seq_show,
972 PDE(inode)->data);
973}
974
975static ssize_t
Len Brown4be44fc2005-08-05 00:44:28 -0400976acpi_video_device_write_state(struct file *file,
977 const char __user * buffer,
978 size_t count, loff_t * data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700979{
Len Brown4be44fc2005-08-05 00:44:28 -0400980 int status;
Jan Engelhardt50dd0962006-10-01 00:28:50 +0200981 struct seq_file *m = file->private_data;
982 struct acpi_video_device *dev = m->private;
Len Brown4be44fc2005-08-05 00:44:28 -0400983 char str[12] = { 0 };
984 u32 state = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700985
Linus Torvalds1da177e2005-04-16 15:20:36 -0700986
987 if (!dev || count + 1 > sizeof str)
Patrick Mocheld550d982006-06-27 00:41:40 -0400988 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700989
990 if (copy_from_user(str, buffer, count))
Patrick Mocheld550d982006-06-27 00:41:40 -0400991 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700992
993 str[count] = 0;
994 state = simple_strtoul(str, NULL, 0);
Len Brown4be44fc2005-08-05 00:44:28 -0400995 state &= ((1ul << 31) | (1ul << 30) | (1ul << 0));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700996
997 status = acpi_video_device_set_state(dev, state);
998
999 if (status)
Patrick Mocheld550d982006-06-27 00:41:40 -04001000 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001001
Patrick Mocheld550d982006-06-27 00:41:40 -04001002 return count;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001003}
1004
1005static int
Len Brown4be44fc2005-08-05 00:44:28 -04001006acpi_video_device_brightness_seq_show(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001007{
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001008 struct acpi_video_device *dev = seq->private;
Len Brown4be44fc2005-08-05 00:44:28 -04001009 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001010
Linus Torvalds1da177e2005-04-16 15:20:36 -07001011
1012 if (!dev || !dev->brightness) {
1013 seq_printf(seq, "<not supported>\n");
Patrick Mocheld550d982006-06-27 00:41:40 -04001014 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001015 }
1016
1017 seq_printf(seq, "levels: ");
1018 for (i = 0; i < dev->brightness->count; i++)
1019 seq_printf(seq, " %d", dev->brightness->levels[i]);
1020 seq_printf(seq, "\ncurrent: %d\n", dev->brightness->curr);
1021
Patrick Mocheld550d982006-06-27 00:41:40 -04001022 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001023}
1024
1025static int
Len Brown4be44fc2005-08-05 00:44:28 -04001026acpi_video_device_brightness_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001027{
1028 return single_open(file, acpi_video_device_brightness_seq_show,
1029 PDE(inode)->data);
1030}
1031
1032static ssize_t
Len Brown4be44fc2005-08-05 00:44:28 -04001033acpi_video_device_write_brightness(struct file *file,
1034 const char __user * buffer,
1035 size_t count, loff_t * data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001036{
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001037 struct seq_file *m = file->private_data;
1038 struct acpi_video_device *dev = m->private;
Danny Baumannc88c5782007-11-02 13:47:53 +01001039 char str[5] = { 0 };
Len Brown4be44fc2005-08-05 00:44:28 -04001040 unsigned int level = 0;
1041 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001042
Linus Torvalds1da177e2005-04-16 15:20:36 -07001043
Thomas Renninger59d399d2005-11-08 05:27:00 -05001044 if (!dev || !dev->brightness || count + 1 > sizeof str)
Patrick Mocheld550d982006-06-27 00:41:40 -04001045 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001046
1047 if (copy_from_user(str, buffer, count))
Patrick Mocheld550d982006-06-27 00:41:40 -04001048 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001049
1050 str[count] = 0;
1051 level = simple_strtoul(str, NULL, 0);
Len Brown4be44fc2005-08-05 00:44:28 -04001052
Linus Torvalds1da177e2005-04-16 15:20:36 -07001053 if (level > 100)
Patrick Mocheld550d982006-06-27 00:41:40 -04001054 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001055
Julius Volz98fb8fe2007-02-20 16:38:40 +01001056 /* validate through the list of available levels */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001057 for (i = 0; i < dev->brightness->count; i++)
1058 if (level == dev->brightness->levels[i]) {
Len Brown4be44fc2005-08-05 00:44:28 -04001059 if (ACPI_SUCCESS
1060 (acpi_video_device_lcd_set_level(dev, level)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001061 dev->brightness->curr = level;
1062 break;
1063 }
1064
Patrick Mocheld550d982006-06-27 00:41:40 -04001065 return count;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001066}
1067
Len Brown4be44fc2005-08-05 00:44:28 -04001068static int acpi_video_device_EDID_seq_show(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001069{
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001070 struct acpi_video_device *dev = seq->private;
Len Brown4be44fc2005-08-05 00:44:28 -04001071 int status;
1072 int i;
1073 union acpi_object *edid = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001074
Linus Torvalds1da177e2005-04-16 15:20:36 -07001075
1076 if (!dev)
1077 goto out;
1078
Len Brown4be44fc2005-08-05 00:44:28 -04001079 status = acpi_video_device_EDID(dev, &edid, 128);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001080 if (ACPI_FAILURE(status)) {
Len Brown4be44fc2005-08-05 00:44:28 -04001081 status = acpi_video_device_EDID(dev, &edid, 256);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001082 }
1083
1084 if (ACPI_FAILURE(status)) {
1085 goto out;
1086 }
1087
1088 if (edid && edid->type == ACPI_TYPE_BUFFER) {
1089 for (i = 0; i < edid->buffer.length; i++)
1090 seq_putc(seq, edid->buffer.pointer[i]);
1091 }
1092
Len Brown4be44fc2005-08-05 00:44:28 -04001093 out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001094 if (!edid)
1095 seq_printf(seq, "<not supported>\n");
1096 else
1097 kfree(edid);
1098
Patrick Mocheld550d982006-06-27 00:41:40 -04001099 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001100}
1101
1102static int
Len Brown4be44fc2005-08-05 00:44:28 -04001103acpi_video_device_EDID_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001104{
1105 return single_open(file, acpi_video_device_EDID_seq_show,
1106 PDE(inode)->data);
1107}
1108
Len Brown4be44fc2005-08-05 00:44:28 -04001109static int acpi_video_device_add_fs(struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001110{
Dmitry Torokhov251cb0b2007-11-05 11:43:34 -05001111 struct proc_dir_entry *entry, *device_dir;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001112 struct acpi_video_device *vid_dev;
1113
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001114 vid_dev = acpi_driver_data(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001115 if (!vid_dev)
Patrick Mocheld550d982006-06-27 00:41:40 -04001116 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001117
Dmitry Torokhov251cb0b2007-11-05 11:43:34 -05001118 device_dir = proc_mkdir(acpi_device_bid(device),
1119 vid_dev->video->dir);
1120 if (!device_dir)
1121 return -ENOMEM;
1122
1123 device_dir->owner = THIS_MODULE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001124
1125 /* 'info' [R] */
Alexey Dobriyane0066c4e2008-05-01 04:10:02 +04001126 entry = proc_create_data("info", S_IRUGO, device_dir,
Denis V. Lunevcf7acfa2008-04-29 01:02:27 -07001127 &acpi_video_device_info_fops, acpi_driver_data(device));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001128 if (!entry)
Dmitry Torokhov251cb0b2007-11-05 11:43:34 -05001129 goto err_remove_dir;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001130
1131 /* 'state' [R/W] */
Denis V. Lunevcf7acfa2008-04-29 01:02:27 -07001132 acpi_video_device_state_fops.write = acpi_video_device_write_state;
1133 entry = proc_create_data("state", S_IFREG | S_IRUGO | S_IWUSR,
Alexey Dobriyane0066c4e2008-05-01 04:10:02 +04001134 device_dir,
Denis V. Lunevcf7acfa2008-04-29 01:02:27 -07001135 &acpi_video_device_state_fops,
1136 acpi_driver_data(device));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001137 if (!entry)
Dmitry Torokhov251cb0b2007-11-05 11:43:34 -05001138 goto err_remove_info;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001139
1140 /* 'brightness' [R/W] */
Denis V. Lunevcf7acfa2008-04-29 01:02:27 -07001141 acpi_video_device_brightness_fops.write =
1142 acpi_video_device_write_brightness;
1143 entry = proc_create_data("brightness", S_IFREG | S_IRUGO | S_IWUSR,
Alexey Dobriyane0066c4e2008-05-01 04:10:02 +04001144 device_dir,
Denis V. Lunevcf7acfa2008-04-29 01:02:27 -07001145 &acpi_video_device_brightness_fops,
1146 acpi_driver_data(device));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001147 if (!entry)
Dmitry Torokhov251cb0b2007-11-05 11:43:34 -05001148 goto err_remove_state;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001149
1150 /* 'EDID' [R] */
Alexey Dobriyane0066c4e2008-05-01 04:10:02 +04001151 entry = proc_create_data("EDID", S_IRUGO, device_dir,
Denis V. Lunevcf7acfa2008-04-29 01:02:27 -07001152 &acpi_video_device_EDID_fops,
1153 acpi_driver_data(device));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001154 if (!entry)
Dmitry Torokhov251cb0b2007-11-05 11:43:34 -05001155 goto err_remove_brightness;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001156
Alexey Dobriyane0066c4e2008-05-01 04:10:02 +04001157 acpi_device_dir(device) = device_dir;
1158
Patrick Mocheld550d982006-06-27 00:41:40 -04001159 return 0;
Dmitry Torokhov251cb0b2007-11-05 11:43:34 -05001160
1161 err_remove_brightness:
1162 remove_proc_entry("brightness", device_dir);
1163 err_remove_state:
1164 remove_proc_entry("state", device_dir);
1165 err_remove_info:
1166 remove_proc_entry("info", device_dir);
1167 err_remove_dir:
1168 remove_proc_entry(acpi_device_bid(device), vid_dev->video->dir);
1169 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001170}
1171
Len Brown4be44fc2005-08-05 00:44:28 -04001172static int acpi_video_device_remove_fs(struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001173{
1174 struct acpi_video_device *vid_dev;
Dmitry Torokhov251cb0b2007-11-05 11:43:34 -05001175 struct proc_dir_entry *device_dir;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001176
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001177 vid_dev = acpi_driver_data(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001178 if (!vid_dev || !vid_dev->video || !vid_dev->video->dir)
Patrick Mocheld550d982006-06-27 00:41:40 -04001179 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001180
Dmitry Torokhov251cb0b2007-11-05 11:43:34 -05001181 device_dir = acpi_device_dir(device);
1182 if (device_dir) {
1183 remove_proc_entry("info", device_dir);
1184 remove_proc_entry("state", device_dir);
1185 remove_proc_entry("brightness", device_dir);
1186 remove_proc_entry("EDID", device_dir);
Len Brown4be44fc2005-08-05 00:44:28 -04001187 remove_proc_entry(acpi_device_bid(device), vid_dev->video->dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001188 acpi_device_dir(device) = NULL;
1189 }
1190
Patrick Mocheld550d982006-06-27 00:41:40 -04001191 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001192}
1193
Linus Torvalds1da177e2005-04-16 15:20:36 -07001194/* video bus */
Len Brown4be44fc2005-08-05 00:44:28 -04001195static int acpi_video_bus_info_seq_show(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001196{
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001197 struct acpi_video_bus *video = seq->private;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001198
Linus Torvalds1da177e2005-04-16 15:20:36 -07001199
1200 if (!video)
1201 goto end;
1202
1203 seq_printf(seq, "Switching heads: %s\n",
Len Brown4be44fc2005-08-05 00:44:28 -04001204 video->flags.multihead ? "yes" : "no");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001205 seq_printf(seq, "Video ROM: %s\n",
Len Brown4be44fc2005-08-05 00:44:28 -04001206 video->flags.rom ? "yes" : "no");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001207 seq_printf(seq, "Device to be POSTed on boot: %s\n",
Len Brown4be44fc2005-08-05 00:44:28 -04001208 video->flags.post ? "yes" : "no");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001209
Len Brown4be44fc2005-08-05 00:44:28 -04001210 end:
Patrick Mocheld550d982006-06-27 00:41:40 -04001211 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001212}
1213
Len Brown4be44fc2005-08-05 00:44:28 -04001214static int acpi_video_bus_info_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001215{
Len Brown4be44fc2005-08-05 00:44:28 -04001216 return single_open(file, acpi_video_bus_info_seq_show,
1217 PDE(inode)->data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001218}
1219
Len Brown4be44fc2005-08-05 00:44:28 -04001220static int acpi_video_bus_ROM_seq_show(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001221{
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001222 struct acpi_video_bus *video = seq->private;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001223
Linus Torvalds1da177e2005-04-16 15:20:36 -07001224
1225 if (!video)
1226 goto end;
1227
Harvey Harrison96b2dd12008-03-05 18:24:51 -08001228 printk(KERN_INFO PREFIX "Please implement %s\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001229 seq_printf(seq, "<TODO>\n");
1230
Len Brown4be44fc2005-08-05 00:44:28 -04001231 end:
Patrick Mocheld550d982006-06-27 00:41:40 -04001232 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001233}
1234
Len Brown4be44fc2005-08-05 00:44:28 -04001235static int acpi_video_bus_ROM_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001236{
1237 return single_open(file, acpi_video_bus_ROM_seq_show, PDE(inode)->data);
1238}
1239
Len Brown4be44fc2005-08-05 00:44:28 -04001240static int acpi_video_bus_POST_info_seq_show(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001241{
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001242 struct acpi_video_bus *video = seq->private;
Matthew Wilcox27663c52008-10-10 02:22:59 -04001243 unsigned long long options;
Len Brown4be44fc2005-08-05 00:44:28 -04001244 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001245
Linus Torvalds1da177e2005-04-16 15:20:36 -07001246
1247 if (!video)
1248 goto end;
1249
1250 status = acpi_video_bus_POST_options(video, &options);
1251 if (ACPI_SUCCESS(status)) {
1252 if (!(options & 1)) {
Len Brown4be44fc2005-08-05 00:44:28 -04001253 printk(KERN_WARNING PREFIX
1254 "The motherboard VGA device is not listed as a possible POST device.\n");
1255 printk(KERN_WARNING PREFIX
Julius Volz98fb8fe2007-02-20 16:38:40 +01001256 "This indicates a BIOS bug. Please contact the manufacturer.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001257 }
Matthew Wilcox27663c52008-10-10 02:22:59 -04001258 printk("%llx\n", options);
Julius Volz98fb8fe2007-02-20 16:38:40 +01001259 seq_printf(seq, "can POST: <integrated video>");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001260 if (options & 2)
1261 seq_printf(seq, " <PCI video>");
1262 if (options & 4)
1263 seq_printf(seq, " <AGP video>");
1264 seq_putc(seq, '\n');
1265 } else
1266 seq_printf(seq, "<not supported>\n");
Len Brown4be44fc2005-08-05 00:44:28 -04001267 end:
Patrick Mocheld550d982006-06-27 00:41:40 -04001268 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001269}
1270
1271static int
Len Brown4be44fc2005-08-05 00:44:28 -04001272acpi_video_bus_POST_info_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001273{
Len Brown4be44fc2005-08-05 00:44:28 -04001274 return single_open(file, acpi_video_bus_POST_info_seq_show,
1275 PDE(inode)->data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001276}
1277
Len Brown4be44fc2005-08-05 00:44:28 -04001278static int acpi_video_bus_POST_seq_show(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001279{
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001280 struct acpi_video_bus *video = seq->private;
Len Brown4be44fc2005-08-05 00:44:28 -04001281 int status;
Matthew Wilcox27663c52008-10-10 02:22:59 -04001282 unsigned long long id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001283
Linus Torvalds1da177e2005-04-16 15:20:36 -07001284
1285 if (!video)
1286 goto end;
1287
Len Brown4be44fc2005-08-05 00:44:28 -04001288 status = acpi_video_bus_get_POST(video, &id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001289 if (!ACPI_SUCCESS(status)) {
1290 seq_printf(seq, "<not supported>\n");
1291 goto end;
1292 }
Julius Volz98fb8fe2007-02-20 16:38:40 +01001293 seq_printf(seq, "device POSTed is <%s>\n", device_decode[id & 3]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001294
Len Brown4be44fc2005-08-05 00:44:28 -04001295 end:
Patrick Mocheld550d982006-06-27 00:41:40 -04001296 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001297}
1298
Len Brown4be44fc2005-08-05 00:44:28 -04001299static int acpi_video_bus_DOS_seq_show(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001300{
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001301 struct acpi_video_bus *video = seq->private;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001302
Linus Torvalds1da177e2005-04-16 15:20:36 -07001303
Len Brown4be44fc2005-08-05 00:44:28 -04001304 seq_printf(seq, "DOS setting: <%d>\n", video->dos_setting);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001305
Patrick Mocheld550d982006-06-27 00:41:40 -04001306 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001307}
1308
Len Brown4be44fc2005-08-05 00:44:28 -04001309static int acpi_video_bus_POST_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001310{
Len Brown4be44fc2005-08-05 00:44:28 -04001311 return single_open(file, acpi_video_bus_POST_seq_show,
1312 PDE(inode)->data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001313}
1314
Len Brown4be44fc2005-08-05 00:44:28 -04001315static int acpi_video_bus_DOS_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001316{
1317 return single_open(file, acpi_video_bus_DOS_seq_show, PDE(inode)->data);
1318}
1319
1320static ssize_t
Len Brown4be44fc2005-08-05 00:44:28 -04001321acpi_video_bus_write_POST(struct file *file,
1322 const char __user * buffer,
1323 size_t count, loff_t * data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001324{
Len Brown4be44fc2005-08-05 00:44:28 -04001325 int status;
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001326 struct seq_file *m = file->private_data;
1327 struct acpi_video_bus *video = m->private;
Len Brown4be44fc2005-08-05 00:44:28 -04001328 char str[12] = { 0 };
Matthew Wilcox27663c52008-10-10 02:22:59 -04001329 unsigned long long opt, options;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001330
Linus Torvalds1da177e2005-04-16 15:20:36 -07001331
Linus Torvalds1da177e2005-04-16 15:20:36 -07001332 if (!video || count + 1 > sizeof str)
Patrick Mocheld550d982006-06-27 00:41:40 -04001333 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001334
1335 status = acpi_video_bus_POST_options(video, &options);
1336 if (!ACPI_SUCCESS(status))
Patrick Mocheld550d982006-06-27 00:41:40 -04001337 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001338
1339 if (copy_from_user(str, buffer, count))
Patrick Mocheld550d982006-06-27 00:41:40 -04001340 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001341
1342 str[count] = 0;
1343 opt = strtoul(str, NULL, 0);
1344 if (opt > 3)
Patrick Mocheld550d982006-06-27 00:41:40 -04001345 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001346
Julius Volz98fb8fe2007-02-20 16:38:40 +01001347 /* just in case an OEM 'forgot' the motherboard... */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001348 options |= 1;
1349
1350 if (options & (1ul << opt)) {
Len Brown4be44fc2005-08-05 00:44:28 -04001351 status = acpi_video_bus_set_POST(video, opt);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001352 if (!ACPI_SUCCESS(status))
Patrick Mocheld550d982006-06-27 00:41:40 -04001353 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001354
1355 }
1356
Patrick Mocheld550d982006-06-27 00:41:40 -04001357 return count;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001358}
1359
1360static ssize_t
Len Brown4be44fc2005-08-05 00:44:28 -04001361acpi_video_bus_write_DOS(struct file *file,
1362 const char __user * buffer,
1363 size_t count, loff_t * data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001364{
Len Brown4be44fc2005-08-05 00:44:28 -04001365 int status;
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001366 struct seq_file *m = file->private_data;
1367 struct acpi_video_bus *video = m->private;
Len Brown4be44fc2005-08-05 00:44:28 -04001368 char str[12] = { 0 };
1369 unsigned long opt;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001370
Linus Torvalds1da177e2005-04-16 15:20:36 -07001371
Linus Torvalds1da177e2005-04-16 15:20:36 -07001372 if (!video || count + 1 > sizeof str)
Patrick Mocheld550d982006-06-27 00:41:40 -04001373 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001374
1375 if (copy_from_user(str, buffer, count))
Patrick Mocheld550d982006-06-27 00:41:40 -04001376 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001377
1378 str[count] = 0;
1379 opt = strtoul(str, NULL, 0);
1380 if (opt > 7)
Patrick Mocheld550d982006-06-27 00:41:40 -04001381 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001382
Len Brown4be44fc2005-08-05 00:44:28 -04001383 status = acpi_video_bus_DOS(video, opt & 0x3, (opt & 0x4) >> 2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001384
1385 if (!ACPI_SUCCESS(status))
Patrick Mocheld550d982006-06-27 00:41:40 -04001386 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001387
Patrick Mocheld550d982006-06-27 00:41:40 -04001388 return count;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001389}
1390
Len Brown4be44fc2005-08-05 00:44:28 -04001391static int acpi_video_bus_add_fs(struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001392{
Dmitry Torokhov251cb0b2007-11-05 11:43:34 -05001393 struct acpi_video_bus *video = acpi_driver_data(device);
1394 struct proc_dir_entry *device_dir;
1395 struct proc_dir_entry *entry;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001396
Dmitry Torokhov251cb0b2007-11-05 11:43:34 -05001397 device_dir = proc_mkdir(acpi_device_bid(device), acpi_video_dir);
1398 if (!device_dir)
1399 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001400
Dmitry Torokhov251cb0b2007-11-05 11:43:34 -05001401 device_dir->owner = THIS_MODULE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001402
1403 /* 'info' [R] */
Alexey Dobriyane0066c4e2008-05-01 04:10:02 +04001404 entry = proc_create_data("info", S_IRUGO, device_dir,
Denis V. Lunevcf7acfa2008-04-29 01:02:27 -07001405 &acpi_video_bus_info_fops,
1406 acpi_driver_data(device));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001407 if (!entry)
Dmitry Torokhov251cb0b2007-11-05 11:43:34 -05001408 goto err_remove_dir;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001409
1410 /* 'ROM' [R] */
Alexey Dobriyane0066c4e2008-05-01 04:10:02 +04001411 entry = proc_create_data("ROM", S_IRUGO, device_dir,
Denis V. Lunevcf7acfa2008-04-29 01:02:27 -07001412 &acpi_video_bus_ROM_fops,
1413 acpi_driver_data(device));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001414 if (!entry)
Dmitry Torokhov251cb0b2007-11-05 11:43:34 -05001415 goto err_remove_info;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001416
1417 /* 'POST_info' [R] */
Alexey Dobriyane0066c4e2008-05-01 04:10:02 +04001418 entry = proc_create_data("POST_info", S_IRUGO, device_dir,
Denis V. Lunevcf7acfa2008-04-29 01:02:27 -07001419 &acpi_video_bus_POST_info_fops,
1420 acpi_driver_data(device));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001421 if (!entry)
Dmitry Torokhov251cb0b2007-11-05 11:43:34 -05001422 goto err_remove_rom;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001423
1424 /* 'POST' [R/W] */
Denis V. Lunevcf7acfa2008-04-29 01:02:27 -07001425 acpi_video_bus_POST_fops.write = acpi_video_bus_write_POST;
Linus Torvalds08acd4f2008-04-30 11:52:52 -07001426 entry = proc_create_data("POST", S_IFREG | S_IRUGO | S_IWUSR,
Alexey Dobriyane0066c4e2008-05-01 04:10:02 +04001427 device_dir,
Denis V. Lunevcf7acfa2008-04-29 01:02:27 -07001428 &acpi_video_bus_POST_fops,
1429 acpi_driver_data(device));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001430 if (!entry)
Dmitry Torokhov251cb0b2007-11-05 11:43:34 -05001431 goto err_remove_post_info;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001432
1433 /* 'DOS' [R/W] */
Denis V. Lunevcf7acfa2008-04-29 01:02:27 -07001434 acpi_video_bus_DOS_fops.write = acpi_video_bus_write_DOS;
Linus Torvalds08acd4f2008-04-30 11:52:52 -07001435 entry = proc_create_data("DOS", S_IFREG | S_IRUGO | S_IWUSR,
Alexey Dobriyane0066c4e2008-05-01 04:10:02 +04001436 device_dir,
Denis V. Lunevcf7acfa2008-04-29 01:02:27 -07001437 &acpi_video_bus_DOS_fops,
1438 acpi_driver_data(device));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001439 if (!entry)
Dmitry Torokhov251cb0b2007-11-05 11:43:34 -05001440 goto err_remove_post;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001441
Dmitry Torokhov251cb0b2007-11-05 11:43:34 -05001442 video->dir = acpi_device_dir(device) = device_dir;
Patrick Mocheld550d982006-06-27 00:41:40 -04001443 return 0;
Dmitry Torokhov251cb0b2007-11-05 11:43:34 -05001444
1445 err_remove_post:
1446 remove_proc_entry("POST", device_dir);
1447 err_remove_post_info:
1448 remove_proc_entry("POST_info", device_dir);
1449 err_remove_rom:
1450 remove_proc_entry("ROM", device_dir);
1451 err_remove_info:
1452 remove_proc_entry("info", device_dir);
1453 err_remove_dir:
1454 remove_proc_entry(acpi_device_bid(device), acpi_video_dir);
1455 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001456}
1457
Len Brown4be44fc2005-08-05 00:44:28 -04001458static int acpi_video_bus_remove_fs(struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001459{
Dmitry Torokhov251cb0b2007-11-05 11:43:34 -05001460 struct proc_dir_entry *device_dir = acpi_device_dir(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001461
Dmitry Torokhov251cb0b2007-11-05 11:43:34 -05001462 if (device_dir) {
1463 remove_proc_entry("info", device_dir);
1464 remove_proc_entry("ROM", device_dir);
1465 remove_proc_entry("POST_info", device_dir);
1466 remove_proc_entry("POST", device_dir);
1467 remove_proc_entry("DOS", device_dir);
Len Brown4be44fc2005-08-05 00:44:28 -04001468 remove_proc_entry(acpi_device_bid(device), acpi_video_dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001469 acpi_device_dir(device) = NULL;
1470 }
1471
Patrick Mocheld550d982006-06-27 00:41:40 -04001472 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001473}
1474
1475/* --------------------------------------------------------------------------
1476 Driver Interface
1477 -------------------------------------------------------------------------- */
1478
1479/* device interface */
Rui Zhang82cae992007-01-03 23:40:53 -05001480static struct acpi_video_device_attrib*
1481acpi_video_get_device_attr(struct acpi_video_bus *video, unsigned long device_id)
1482{
Dmitry Torokhov78eed022007-11-05 11:43:33 -05001483 struct acpi_video_enumerated_device *ids;
1484 int i;
Rui Zhang82cae992007-01-03 23:40:53 -05001485
Dmitry Torokhov78eed022007-11-05 11:43:33 -05001486 for (i = 0; i < video->attached_count; i++) {
1487 ids = &video->attached_array[i];
1488 if ((ids->value.int_val & 0xffff) == device_id)
1489 return &ids->value.attrib;
1490 }
1491
Rui Zhang82cae992007-01-03 23:40:53 -05001492 return NULL;
1493}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001494
1495static int
Len Brown4be44fc2005-08-05 00:44:28 -04001496acpi_video_bus_get_one_device(struct acpi_device *device,
1497 struct acpi_video_bus *video)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001498{
Matthew Wilcox27663c52008-10-10 02:22:59 -04001499 unsigned long long device_id;
Yu, Luming973bf492006-04-27 05:25:00 -04001500 int status;
Len Brown4be44fc2005-08-05 00:44:28 -04001501 struct acpi_video_device *data;
Rui Zhang82cae992007-01-03 23:40:53 -05001502 struct acpi_video_device_attrib* attribute;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001503
1504 if (!device || !video)
Patrick Mocheld550d982006-06-27 00:41:40 -04001505 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001506
Len Brown4be44fc2005-08-05 00:44:28 -04001507 status =
1508 acpi_evaluate_integer(device->handle, "_ADR", NULL, &device_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001509 if (ACPI_SUCCESS(status)) {
1510
Burman Yan36bcbec2006-12-19 12:56:11 -08001511 data = kzalloc(sizeof(struct acpi_video_device), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001512 if (!data)
Patrick Mocheld550d982006-06-27 00:41:40 -04001513 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001514
Linus Torvalds1da177e2005-04-16 15:20:36 -07001515 strcpy(acpi_device_name(device), ACPI_VIDEO_DEVICE_NAME);
1516 strcpy(acpi_device_class(device), ACPI_VIDEO_CLASS);
Pavel Machekdb89b4f2008-09-22 14:37:34 -07001517 device->driver_data = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001518
1519 data->device_id = device_id;
1520 data->video = video;
1521 data->dev = device;
1522
Rui Zhang82cae992007-01-03 23:40:53 -05001523 attribute = acpi_video_get_device_attr(video, device_id);
1524
1525 if((attribute != NULL) && attribute->device_id_scheme) {
1526 switch (attribute->display_type) {
1527 case ACPI_VIDEO_DISPLAY_CRT:
1528 data->flags.crt = 1;
1529 break;
1530 case ACPI_VIDEO_DISPLAY_TV:
1531 data->flags.tvout = 1;
1532 break;
1533 case ACPI_VIDEO_DISPLAY_DVI:
1534 data->flags.dvi = 1;
1535 break;
1536 case ACPI_VIDEO_DISPLAY_LCD:
1537 data->flags.lcd = 1;
1538 break;
1539 default:
1540 data->flags.unknown = 1;
1541 break;
1542 }
1543 if(attribute->bios_can_detect)
1544 data->flags.bios = 1;
1545 } else
Linus Torvalds1da177e2005-04-16 15:20:36 -07001546 data->flags.unknown = 1;
Len Brown4be44fc2005-08-05 00:44:28 -04001547
Linus Torvalds1da177e2005-04-16 15:20:36 -07001548 acpi_video_device_bind(video, data);
1549 acpi_video_device_find_cap(data);
1550
Patrick Mochel90130262006-05-19 16:54:48 -04001551 status = acpi_install_notify_handler(device->handle,
Len Brown4be44fc2005-08-05 00:44:28 -04001552 ACPI_DEVICE_NOTIFY,
1553 acpi_video_device_notify,
1554 data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001555 if (ACPI_FAILURE(status)) {
Lin Ming55ac9a02008-09-28 14:51:56 +08001556 printk(KERN_ERR PREFIX
1557 "Error installing notify handler\n");
Yu, Luming973bf492006-04-27 05:25:00 -04001558 if(data->brightness)
1559 kfree(data->brightness->levels);
1560 kfree(data->brightness);
1561 kfree(data);
1562 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001563 }
1564
Dmitry Torokhovbbac81f2007-11-05 11:43:32 -05001565 mutex_lock(&video->device_list_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001566 list_add_tail(&data->entry, &video->video_device_list);
Dmitry Torokhovbbac81f2007-11-05 11:43:32 -05001567 mutex_unlock(&video->device_list_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001568
1569 acpi_video_device_add_fs(device);
1570
Patrick Mocheld550d982006-06-27 00:41:40 -04001571 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001572 }
1573
Patrick Mocheld550d982006-06-27 00:41:40 -04001574 return -ENOENT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001575}
1576
1577/*
1578 * Arg:
1579 * video : video bus device
1580 *
1581 * Return:
1582 * none
1583 *
1584 * Enumerate the video device list of the video bus,
1585 * bind the ids with the corresponding video devices
1586 * under the video bus.
Len Brown4be44fc2005-08-05 00:44:28 -04001587 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001588
Len Brown4be44fc2005-08-05 00:44:28 -04001589static void acpi_video_device_rebind(struct acpi_video_bus *video)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001590{
Dmitry Torokhovff102ea2007-11-05 11:43:31 -05001591 struct acpi_video_device *dev;
1592
Dmitry Torokhovbbac81f2007-11-05 11:43:32 -05001593 mutex_lock(&video->device_list_lock);
Dmitry Torokhovff102ea2007-11-05 11:43:31 -05001594
1595 list_for_each_entry(dev, &video->video_device_list, entry)
Len Brown4be44fc2005-08-05 00:44:28 -04001596 acpi_video_device_bind(video, dev);
Dmitry Torokhovff102ea2007-11-05 11:43:31 -05001597
Dmitry Torokhovbbac81f2007-11-05 11:43:32 -05001598 mutex_unlock(&video->device_list_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001599}
1600
1601/*
1602 * Arg:
1603 * video : video bus device
1604 * device : video output device under the video
1605 * bus
1606 *
1607 * Return:
1608 * none
1609 *
1610 * Bind the ids with the corresponding video devices
1611 * under the video bus.
Len Brown4be44fc2005-08-05 00:44:28 -04001612 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001613
1614static void
Len Brown4be44fc2005-08-05 00:44:28 -04001615acpi_video_device_bind(struct acpi_video_bus *video,
1616 struct acpi_video_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001617{
Dmitry Torokhov78eed022007-11-05 11:43:33 -05001618 struct acpi_video_enumerated_device *ids;
Len Brown4be44fc2005-08-05 00:44:28 -04001619 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001620
Dmitry Torokhov78eed022007-11-05 11:43:33 -05001621 for (i = 0; i < video->attached_count; i++) {
1622 ids = &video->attached_array[i];
1623 if (device->device_id == (ids->value.int_val & 0xffff)) {
1624 ids->bind_info = device;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001625 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "device_bind %d\n", i));
1626 }
1627 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001628}
1629
1630/*
1631 * Arg:
1632 * video : video bus device
1633 *
1634 * Return:
1635 * < 0 : error
1636 *
1637 * Call _DOD to enumerate all devices attached to display adapter
1638 *
Len Brown4be44fc2005-08-05 00:44:28 -04001639 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001640
1641static int acpi_video_device_enumerate(struct acpi_video_bus *video)
1642{
Len Brown4be44fc2005-08-05 00:44:28 -04001643 int status;
1644 int count;
1645 int i;
Dmitry Torokhov78eed022007-11-05 11:43:33 -05001646 struct acpi_video_enumerated_device *active_list;
Len Brown4be44fc2005-08-05 00:44:28 -04001647 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
1648 union acpi_object *dod = NULL;
1649 union acpi_object *obj;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001650
Patrick Mochel90130262006-05-19 16:54:48 -04001651 status = acpi_evaluate_object(video->device->handle, "_DOD", NULL, &buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001652 if (!ACPI_SUCCESS(status)) {
Thomas Renningera6fc6722006-06-26 23:58:43 -04001653 ACPI_EXCEPTION((AE_INFO, status, "Evaluating _DOD"));
Patrick Mocheld550d982006-06-27 00:41:40 -04001654 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001655 }
1656
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001657 dod = buffer.pointer;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001658 if (!dod || (dod->type != ACPI_TYPE_PACKAGE)) {
Thomas Renningera6fc6722006-06-26 23:58:43 -04001659 ACPI_EXCEPTION((AE_INFO, status, "Invalid _DOD data"));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001660 status = -EFAULT;
1661 goto out;
1662 }
1663
1664 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found %d video heads in _DOD\n",
Len Brown4be44fc2005-08-05 00:44:28 -04001665 dod->package.count));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001666
Dmitry Torokhov78eed022007-11-05 11:43:33 -05001667 active_list = kcalloc(1 + dod->package.count,
1668 sizeof(struct acpi_video_enumerated_device),
1669 GFP_KERNEL);
1670 if (!active_list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001671 status = -ENOMEM;
1672 goto out;
1673 }
1674
1675 count = 0;
1676 for (i = 0; i < dod->package.count; i++) {
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001677 obj = &dod->package.elements[i];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001678
1679 if (obj->type != ACPI_TYPE_INTEGER) {
Dmitry Torokhov78eed022007-11-05 11:43:33 -05001680 printk(KERN_ERR PREFIX
1681 "Invalid _DOD data in element %d\n", i);
1682 continue;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001683 }
Dmitry Torokhov78eed022007-11-05 11:43:33 -05001684
1685 active_list[count].value.int_val = obj->integer.value;
1686 active_list[count].bind_info = NULL;
Len Brown4be44fc2005-08-05 00:44:28 -04001687 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "dod element[%d] = %d\n", i,
1688 (int)obj->integer.value));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001689 count++;
1690 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001691
Jesper Juhl6044ec82005-11-07 01:01:32 -08001692 kfree(video->attached_array);
Len Brown4be44fc2005-08-05 00:44:28 -04001693
Dmitry Torokhov78eed022007-11-05 11:43:33 -05001694 video->attached_array = active_list;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001695 video->attached_count = count;
Dmitry Torokhov78eed022007-11-05 11:43:33 -05001696
1697 out:
Len Brown02438d82006-06-30 03:19:10 -04001698 kfree(buffer.pointer);
Patrick Mocheld550d982006-06-27 00:41:40 -04001699 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001700}
1701
Len Brown4be44fc2005-08-05 00:44:28 -04001702static int
1703acpi_video_get_next_level(struct acpi_video_device *device,
1704 u32 level_current, u32 event)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001705{
Alexey Starikovskiy63f0edf2007-09-03 16:30:08 +04001706 int min, max, min_above, max_below, i, l, delta = 255;
Thomas Tuttlef4715182006-12-19 12:56:14 -08001707 max = max_below = 0;
1708 min = min_above = 255;
Alexey Starikovskiy63f0edf2007-09-03 16:30:08 +04001709 /* Find closest level to level_current */
1710 for (i = 0; i < device->brightness->count; i++) {
1711 l = device->brightness->levels[i];
1712 if (abs(l - level_current) < abs(delta)) {
1713 delta = l - level_current;
1714 if (!delta)
1715 break;
1716 }
1717 }
1718 /* Ajust level_current to closest available level */
1719 level_current += delta;
Thomas Tuttlef4715182006-12-19 12:56:14 -08001720 for (i = 0; i < device->brightness->count; i++) {
1721 l = device->brightness->levels[i];
1722 if (l < min)
1723 min = l;
1724 if (l > max)
1725 max = l;
1726 if (l < min_above && l > level_current)
1727 min_above = l;
1728 if (l > max_below && l < level_current)
1729 max_below = l;
1730 }
1731
1732 switch (event) {
1733 case ACPI_VIDEO_NOTIFY_CYCLE_BRIGHTNESS:
1734 return (level_current < max) ? min_above : min;
1735 case ACPI_VIDEO_NOTIFY_INC_BRIGHTNESS:
1736 return (level_current < max) ? min_above : max;
1737 case ACPI_VIDEO_NOTIFY_DEC_BRIGHTNESS:
1738 return (level_current > min) ? max_below : min;
1739 case ACPI_VIDEO_NOTIFY_ZERO_BRIGHTNESS:
1740 case ACPI_VIDEO_NOTIFY_DISPLAY_OFF:
1741 return 0;
1742 default:
1743 return level_current;
1744 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001745}
1746
Linus Torvalds1da177e2005-04-16 15:20:36 -07001747static void
Len Brown4be44fc2005-08-05 00:44:28 -04001748acpi_video_switch_brightness(struct acpi_video_device *device, int event)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001749{
Matthew Wilcox27663c52008-10-10 02:22:59 -04001750 unsigned long long level_current, level_next;
Julia Jomantaite469778c2008-06-23 22:50:42 +01001751 if (!device->brightness)
1752 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001753 acpi_video_device_lcd_get_level_current(device, &level_current);
1754 level_next = acpi_video_get_next_level(device, level_current, event);
1755 acpi_video_device_lcd_set_level(device, level_next);
1756}
1757
1758static int
Len Brown4be44fc2005-08-05 00:44:28 -04001759acpi_video_bus_get_devices(struct acpi_video_bus *video,
1760 struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001761{
Len Brown4be44fc2005-08-05 00:44:28 -04001762 int status = 0;
Dmitry Torokhovff102ea2007-11-05 11:43:31 -05001763 struct acpi_device *dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001764
1765 acpi_video_device_enumerate(video);
1766
Dmitry Torokhovff102ea2007-11-05 11:43:31 -05001767 list_for_each_entry(dev, &device->children, node) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001768
1769 status = acpi_video_bus_get_one_device(dev, video);
1770 if (ACPI_FAILURE(status)) {
Lin Ming55ac9a02008-09-28 14:51:56 +08001771 printk(KERN_WARNING PREFIX
1772 "Cant attach device");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001773 continue;
1774 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001775 }
Patrick Mocheld550d982006-06-27 00:41:40 -04001776 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001777}
1778
Len Brown4be44fc2005-08-05 00:44:28 -04001779static int acpi_video_bus_put_one_device(struct acpi_video_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001780{
Karol Kozimor031ec772005-07-30 04:18:00 -04001781 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001782 struct acpi_video_bus *video;
1783
Linus Torvalds1da177e2005-04-16 15:20:36 -07001784
1785 if (!device || !device->video)
Patrick Mocheld550d982006-06-27 00:41:40 -04001786 return -ENOENT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001787
1788 video = device->video;
1789
Linus Torvalds1da177e2005-04-16 15:20:36 -07001790 acpi_video_device_remove_fs(device->dev);
1791
Patrick Mochel90130262006-05-19 16:54:48 -04001792 status = acpi_remove_notify_handler(device->dev->handle,
Len Brown4be44fc2005-08-05 00:44:28 -04001793 ACPI_DEVICE_NOTIFY,
1794 acpi_video_device_notify);
Richard Purdie599a52d2007-02-10 23:07:48 +00001795 backlight_device_unregister(device->backlight);
Zhang Rui702ed512008-01-17 15:51:22 +08001796 if (device->cdev) {
1797 sysfs_remove_link(&device->dev->dev.kobj,
1798 "thermal_cooling");
1799 sysfs_remove_link(&device->cdev->device.kobj,
1800 "device");
1801 thermal_cooling_device_unregister(device->cdev);
1802 device->cdev = NULL;
1803 }
Luming Yu23b0f012007-05-09 21:07:05 +08001804 video_output_unregister(device->output_dev);
Dmitry Torokhovff102ea2007-11-05 11:43:31 -05001805
Patrick Mocheld550d982006-06-27 00:41:40 -04001806 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001807}
1808
Len Brown4be44fc2005-08-05 00:44:28 -04001809static int acpi_video_bus_put_devices(struct acpi_video_bus *video)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001810{
Len Brown4be44fc2005-08-05 00:44:28 -04001811 int status;
Dmitry Torokhovff102ea2007-11-05 11:43:31 -05001812 struct acpi_video_device *dev, *next;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001813
Dmitry Torokhovbbac81f2007-11-05 11:43:32 -05001814 mutex_lock(&video->device_list_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001815
Dmitry Torokhovff102ea2007-11-05 11:43:31 -05001816 list_for_each_entry_safe(dev, next, &video->video_device_list, entry) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001817
Dmitry Torokhovff102ea2007-11-05 11:43:31 -05001818 status = acpi_video_bus_put_one_device(dev);
Len Brown4be44fc2005-08-05 00:44:28 -04001819 if (ACPI_FAILURE(status))
1820 printk(KERN_WARNING PREFIX
1821 "hhuuhhuu bug in acpi video driver.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001822
Dmitry Torokhovff102ea2007-11-05 11:43:31 -05001823 if (dev->brightness) {
1824 kfree(dev->brightness->levels);
1825 kfree(dev->brightness);
1826 }
1827 list_del(&dev->entry);
1828 kfree(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001829 }
1830
Dmitry Torokhovbbac81f2007-11-05 11:43:32 -05001831 mutex_unlock(&video->device_list_lock);
Dmitry Torokhovff102ea2007-11-05 11:43:31 -05001832
Patrick Mocheld550d982006-06-27 00:41:40 -04001833 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001834}
1835
1836/* acpi_video interface */
1837
Len Brown4be44fc2005-08-05 00:44:28 -04001838static int acpi_video_bus_start_devices(struct acpi_video_bus *video)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001839{
Zhang Ruia21101c2007-09-14 11:46:22 +08001840 return acpi_video_bus_DOS(video, 0, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001841}
1842
Len Brown4be44fc2005-08-05 00:44:28 -04001843static int acpi_video_bus_stop_devices(struct acpi_video_bus *video)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001844{
1845 return acpi_video_bus_DOS(video, 0, 1);
1846}
1847
Len Brown4be44fc2005-08-05 00:44:28 -04001848static void acpi_video_bus_notify(acpi_handle handle, u32 event, void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001849{
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001850 struct acpi_video_bus *video = data;
Len Brown4be44fc2005-08-05 00:44:28 -04001851 struct acpi_device *device = NULL;
Luming Yue9dab192007-08-20 18:23:53 +08001852 struct input_dev *input;
1853 int keycode;
1854
Linus Torvalds1da177e2005-04-16 15:20:36 -07001855 if (!video)
Patrick Mocheld550d982006-06-27 00:41:40 -04001856 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001857
Patrick Mochele6afa0d2006-05-19 16:54:40 -04001858 device = video->device;
Luming Yue9dab192007-08-20 18:23:53 +08001859 input = video->input;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001860
1861 switch (event) {
Julius Volz98fb8fe2007-02-20 16:38:40 +01001862 case ACPI_VIDEO_NOTIFY_SWITCH: /* User requested a switch,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001863 * most likely via hotkey. */
Len Brown14e04fb2007-08-23 15:20:26 -04001864 acpi_bus_generate_proc_event(device, event, 0);
Luming Yue9dab192007-08-20 18:23:53 +08001865 keycode = KEY_SWITCHVIDEOMODE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001866 break;
1867
Julius Volz98fb8fe2007-02-20 16:38:40 +01001868 case ACPI_VIDEO_NOTIFY_PROBE: /* User plugged in or removed a video
Linus Torvalds1da177e2005-04-16 15:20:36 -07001869 * connector. */
1870 acpi_video_device_enumerate(video);
1871 acpi_video_device_rebind(video);
Len Brown14e04fb2007-08-23 15:20:26 -04001872 acpi_bus_generate_proc_event(device, event, 0);
Luming Yue9dab192007-08-20 18:23:53 +08001873 keycode = KEY_SWITCHVIDEOMODE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001874 break;
1875
Len Brown4be44fc2005-08-05 00:44:28 -04001876 case ACPI_VIDEO_NOTIFY_CYCLE: /* Cycle Display output hotkey pressed. */
Len Brown25c87f72007-08-25 01:44:01 -04001877 acpi_bus_generate_proc_event(device, event, 0);
Luming Yue9dab192007-08-20 18:23:53 +08001878 keycode = KEY_SWITCHVIDEOMODE;
1879 break;
Len Brown4be44fc2005-08-05 00:44:28 -04001880 case ACPI_VIDEO_NOTIFY_NEXT_OUTPUT: /* Next Display output hotkey pressed. */
Len Brown25c87f72007-08-25 01:44:01 -04001881 acpi_bus_generate_proc_event(device, event, 0);
Luming Yue9dab192007-08-20 18:23:53 +08001882 keycode = KEY_VIDEO_NEXT;
1883 break;
Len Brown4be44fc2005-08-05 00:44:28 -04001884 case ACPI_VIDEO_NOTIFY_PREV_OUTPUT: /* previous Display output hotkey pressed. */
Len Brown14e04fb2007-08-23 15:20:26 -04001885 acpi_bus_generate_proc_event(device, event, 0);
Luming Yue9dab192007-08-20 18:23:53 +08001886 keycode = KEY_VIDEO_PREV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001887 break;
1888
1889 default:
Luming Yue9dab192007-08-20 18:23:53 +08001890 keycode = KEY_UNKNOWN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001891 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
Len Brown4be44fc2005-08-05 00:44:28 -04001892 "Unsupported event [0x%x]\n", event));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001893 break;
1894 }
1895
Zhang Rui7761f632008-01-25 14:48:12 +08001896 acpi_notifier_call_chain(device, event, 0);
Luming Yue9dab192007-08-20 18:23:53 +08001897 input_report_key(input, keycode, 1);
1898 input_sync(input);
1899 input_report_key(input, keycode, 0);
1900 input_sync(input);
1901
Patrick Mocheld550d982006-06-27 00:41:40 -04001902 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001903}
1904
Len Brown4be44fc2005-08-05 00:44:28 -04001905static void acpi_video_device_notify(acpi_handle handle, u32 event, void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001906{
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001907 struct acpi_video_device *video_device = data;
Len Brown4be44fc2005-08-05 00:44:28 -04001908 struct acpi_device *device = NULL;
Luming Yue9dab192007-08-20 18:23:53 +08001909 struct acpi_video_bus *bus;
1910 struct input_dev *input;
1911 int keycode;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001912
Linus Torvalds1da177e2005-04-16 15:20:36 -07001913 if (!video_device)
Patrick Mocheld550d982006-06-27 00:41:40 -04001914 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001915
Patrick Mochele6afa0d2006-05-19 16:54:40 -04001916 device = video_device->dev;
Luming Yue9dab192007-08-20 18:23:53 +08001917 bus = video_device->video;
1918 input = bus->input;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001919
1920 switch (event) {
Len Brown4be44fc2005-08-05 00:44:28 -04001921 case ACPI_VIDEO_NOTIFY_CYCLE_BRIGHTNESS: /* Cycle brightness */
Zhang Rui8a681a42008-01-25 14:47:49 +08001922 if (brightness_switch_enabled)
1923 acpi_video_switch_brightness(video_device, event);
Len Brown25c87f72007-08-25 01:44:01 -04001924 acpi_bus_generate_proc_event(device, event, 0);
Luming Yue9dab192007-08-20 18:23:53 +08001925 keycode = KEY_BRIGHTNESS_CYCLE;
1926 break;
Len Brown4be44fc2005-08-05 00:44:28 -04001927 case ACPI_VIDEO_NOTIFY_INC_BRIGHTNESS: /* Increase brightness */
Zhang Rui8a681a42008-01-25 14:47:49 +08001928 if (brightness_switch_enabled)
1929 acpi_video_switch_brightness(video_device, event);
Len Brown25c87f72007-08-25 01:44:01 -04001930 acpi_bus_generate_proc_event(device, event, 0);
Luming Yue9dab192007-08-20 18:23:53 +08001931 keycode = KEY_BRIGHTNESSUP;
1932 break;
Len Brown4be44fc2005-08-05 00:44:28 -04001933 case ACPI_VIDEO_NOTIFY_DEC_BRIGHTNESS: /* Decrease brightness */
Zhang Rui8a681a42008-01-25 14:47:49 +08001934 if (brightness_switch_enabled)
1935 acpi_video_switch_brightness(video_device, event);
Len Brown25c87f72007-08-25 01:44:01 -04001936 acpi_bus_generate_proc_event(device, event, 0);
Luming Yue9dab192007-08-20 18:23:53 +08001937 keycode = KEY_BRIGHTNESSDOWN;
1938 break;
Len Brown4be44fc2005-08-05 00:44:28 -04001939 case ACPI_VIDEO_NOTIFY_ZERO_BRIGHTNESS: /* zero brightnesss */
Zhang Rui8a681a42008-01-25 14:47:49 +08001940 if (brightness_switch_enabled)
1941 acpi_video_switch_brightness(video_device, event);
Len Brown25c87f72007-08-25 01:44:01 -04001942 acpi_bus_generate_proc_event(device, event, 0);
Luming Yue9dab192007-08-20 18:23:53 +08001943 keycode = KEY_BRIGHTNESS_ZERO;
1944 break;
Len Brown4be44fc2005-08-05 00:44:28 -04001945 case ACPI_VIDEO_NOTIFY_DISPLAY_OFF: /* display device off */
Zhang Rui8a681a42008-01-25 14:47:49 +08001946 if (brightness_switch_enabled)
1947 acpi_video_switch_brightness(video_device, event);
Len Brown14e04fb2007-08-23 15:20:26 -04001948 acpi_bus_generate_proc_event(device, event, 0);
Luming Yue9dab192007-08-20 18:23:53 +08001949 keycode = KEY_DISPLAY_OFF;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001950 break;
1951 default:
Luming Yue9dab192007-08-20 18:23:53 +08001952 keycode = KEY_UNKNOWN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001953 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
Len Brown4be44fc2005-08-05 00:44:28 -04001954 "Unsupported event [0x%x]\n", event));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001955 break;
1956 }
Luming Yue9dab192007-08-20 18:23:53 +08001957
Zhang Rui7761f632008-01-25 14:48:12 +08001958 acpi_notifier_call_chain(device, event, 0);
Luming Yue9dab192007-08-20 18:23:53 +08001959 input_report_key(input, keycode, 1);
1960 input_sync(input);
1961 input_report_key(input, keycode, 0);
1962 input_sync(input);
1963
Patrick Mocheld550d982006-06-27 00:41:40 -04001964 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001965}
1966
Zhang Ruie6d9da12007-08-25 02:23:31 -04001967static int instance;
Matthew Garrett863c1492008-02-04 23:31:24 -08001968static int acpi_video_resume(struct acpi_device *device)
1969{
1970 struct acpi_video_bus *video;
1971 struct acpi_video_device *video_device;
1972 int i;
1973
1974 if (!device || !acpi_driver_data(device))
1975 return -EINVAL;
1976
1977 video = acpi_driver_data(device);
1978
1979 for (i = 0; i < video->attached_count; i++) {
1980 video_device = video->attached_array[i].bind_info;
1981 if (video_device && video_device->backlight)
1982 acpi_video_set_brightness(video_device->backlight);
1983 }
1984 return AE_OK;
1985}
1986
Len Brown4be44fc2005-08-05 00:44:28 -04001987static int acpi_video_bus_add(struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001988{
Dmitry Torokhovf51e8392007-11-05 11:43:30 -05001989 acpi_status status;
1990 struct acpi_video_bus *video;
Luming Yue9dab192007-08-20 18:23:53 +08001991 struct input_dev *input;
Dmitry Torokhovf51e8392007-11-05 11:43:30 -05001992 int error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001993
Burman Yan36bcbec2006-12-19 12:56:11 -08001994 video = kzalloc(sizeof(struct acpi_video_bus), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001995 if (!video)
Patrick Mocheld550d982006-06-27 00:41:40 -04001996 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001997
Zhang Ruie6d9da12007-08-25 02:23:31 -04001998 /* a hack to fix the duplicate name "VID" problem on T61 */
1999 if (!strcmp(device->pnp.bus_id, "VID")) {
2000 if (instance)
2001 device->pnp.bus_id[3] = '0' + instance;
2002 instance ++;
2003 }
2004
Patrick Mochele6afa0d2006-05-19 16:54:40 -04002005 video->device = device;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002006 strcpy(acpi_device_name(device), ACPI_VIDEO_BUS_NAME);
2007 strcpy(acpi_device_class(device), ACPI_VIDEO_CLASS);
Pavel Machekdb89b4f2008-09-22 14:37:34 -07002008 device->driver_data = video;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002009
2010 acpi_video_bus_find_cap(video);
Dmitry Torokhovf51e8392007-11-05 11:43:30 -05002011 error = acpi_video_bus_check(video);
2012 if (error)
2013 goto err_free_video;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002014
Dmitry Torokhovf51e8392007-11-05 11:43:30 -05002015 error = acpi_video_bus_add_fs(device);
2016 if (error)
2017 goto err_free_video;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002018
Dmitry Torokhovbbac81f2007-11-05 11:43:32 -05002019 mutex_init(&video->device_list_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002020 INIT_LIST_HEAD(&video->video_device_list);
2021
2022 acpi_video_bus_get_devices(video, device);
2023 acpi_video_bus_start_devices(video);
2024
Patrick Mochel90130262006-05-19 16:54:48 -04002025 status = acpi_install_notify_handler(device->handle,
Len Brown4be44fc2005-08-05 00:44:28 -04002026 ACPI_DEVICE_NOTIFY,
2027 acpi_video_bus_notify, video);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002028 if (ACPI_FAILURE(status)) {
Lin Ming55ac9a02008-09-28 14:51:56 +08002029 printk(KERN_ERR PREFIX
2030 "Error installing notify handler\n");
Dmitry Torokhovf51e8392007-11-05 11:43:30 -05002031 error = -ENODEV;
2032 goto err_stop_video;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002033 }
2034
Luming Yue9dab192007-08-20 18:23:53 +08002035 video->input = input = input_allocate_device();
Dmitry Torokhovf51e8392007-11-05 11:43:30 -05002036 if (!input) {
2037 error = -ENOMEM;
2038 goto err_uninstall_notify;
2039 }
Luming Yue9dab192007-08-20 18:23:53 +08002040
2041 snprintf(video->phys, sizeof(video->phys),
2042 "%s/video/input0", acpi_device_hid(video->device));
2043
2044 input->name = acpi_device_name(video->device);
2045 input->phys = video->phys;
2046 input->id.bustype = BUS_HOST;
2047 input->id.product = 0x06;
Dmitry Torokhov91c05c62007-11-05 11:43:29 -05002048 input->dev.parent = &device->dev;
Luming Yue9dab192007-08-20 18:23:53 +08002049 input->evbit[0] = BIT(EV_KEY);
2050 set_bit(KEY_SWITCHVIDEOMODE, input->keybit);
2051 set_bit(KEY_VIDEO_NEXT, input->keybit);
2052 set_bit(KEY_VIDEO_PREV, input->keybit);
2053 set_bit(KEY_BRIGHTNESS_CYCLE, input->keybit);
2054 set_bit(KEY_BRIGHTNESSUP, input->keybit);
2055 set_bit(KEY_BRIGHTNESSDOWN, input->keybit);
2056 set_bit(KEY_BRIGHTNESS_ZERO, input->keybit);
2057 set_bit(KEY_DISPLAY_OFF, input->keybit);
2058 set_bit(KEY_UNKNOWN, input->keybit);
Luming Yue9dab192007-08-20 18:23:53 +08002059
Dmitry Torokhovf51e8392007-11-05 11:43:30 -05002060 error = input_register_device(input);
2061 if (error)
2062 goto err_free_input_dev;
Luming Yue9dab192007-08-20 18:23:53 +08002063
Linus Torvalds1da177e2005-04-16 15:20:36 -07002064 printk(KERN_INFO PREFIX "%s [%s] (multi-head: %s rom: %s post: %s)\n",
Len Brown4be44fc2005-08-05 00:44:28 -04002065 ACPI_VIDEO_DEVICE_NAME, acpi_device_bid(device),
2066 video->flags.multihead ? "yes" : "no",
2067 video->flags.rom ? "yes" : "no",
2068 video->flags.post ? "yes" : "no");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002069
Dmitry Torokhovf51e8392007-11-05 11:43:30 -05002070 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002071
Dmitry Torokhovf51e8392007-11-05 11:43:30 -05002072 err_free_input_dev:
2073 input_free_device(input);
2074 err_uninstall_notify:
2075 acpi_remove_notify_handler(device->handle, ACPI_DEVICE_NOTIFY,
2076 acpi_video_bus_notify);
2077 err_stop_video:
2078 acpi_video_bus_stop_devices(video);
2079 acpi_video_bus_put_devices(video);
2080 kfree(video->attached_array);
2081 acpi_video_bus_remove_fs(device);
2082 err_free_video:
2083 kfree(video);
Pavel Machekdb89b4f2008-09-22 14:37:34 -07002084 device->driver_data = NULL;
Dmitry Torokhovf51e8392007-11-05 11:43:30 -05002085
2086 return error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002087}
2088
Len Brown4be44fc2005-08-05 00:44:28 -04002089static int acpi_video_bus_remove(struct acpi_device *device, int type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002090{
Len Brown4be44fc2005-08-05 00:44:28 -04002091 acpi_status status = 0;
2092 struct acpi_video_bus *video = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002093
Linus Torvalds1da177e2005-04-16 15:20:36 -07002094
2095 if (!device || !acpi_driver_data(device))
Patrick Mocheld550d982006-06-27 00:41:40 -04002096 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002097
Jan Engelhardt50dd0962006-10-01 00:28:50 +02002098 video = acpi_driver_data(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002099
2100 acpi_video_bus_stop_devices(video);
2101
Patrick Mochel90130262006-05-19 16:54:48 -04002102 status = acpi_remove_notify_handler(video->device->handle,
Len Brown4be44fc2005-08-05 00:44:28 -04002103 ACPI_DEVICE_NOTIFY,
2104 acpi_video_bus_notify);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002105
2106 acpi_video_bus_put_devices(video);
2107 acpi_video_bus_remove_fs(device);
2108
Luming Yue9dab192007-08-20 18:23:53 +08002109 input_unregister_device(video->input);
Jesper Juhl6044ec82005-11-07 01:01:32 -08002110 kfree(video->attached_array);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002111 kfree(video);
2112
Patrick Mocheld550d982006-06-27 00:41:40 -04002113 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002114}
2115
Len Brown4be44fc2005-08-05 00:44:28 -04002116static int __init acpi_video_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002117{
Len Brown4be44fc2005-08-05 00:44:28 -04002118 int result = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002119
Linus Torvalds1da177e2005-04-16 15:20:36 -07002120 acpi_video_dir = proc_mkdir(ACPI_VIDEO_CLASS, acpi_root_dir);
2121 if (!acpi_video_dir)
Patrick Mocheld550d982006-06-27 00:41:40 -04002122 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002123 acpi_video_dir->owner = THIS_MODULE;
2124
2125 result = acpi_bus_register_driver(&acpi_video_bus);
2126 if (result < 0) {
2127 remove_proc_entry(ACPI_VIDEO_CLASS, acpi_root_dir);
Patrick Mocheld550d982006-06-27 00:41:40 -04002128 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002129 }
2130
Patrick Mocheld550d982006-06-27 00:41:40 -04002131 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002132}
2133
Len Brown4be44fc2005-08-05 00:44:28 -04002134static void __exit acpi_video_exit(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002135{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002136
2137 acpi_bus_unregister_driver(&acpi_video_bus);
2138
2139 remove_proc_entry(ACPI_VIDEO_CLASS, acpi_root_dir);
2140
Patrick Mocheld550d982006-06-27 00:41:40 -04002141 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002142}
2143
2144module_init(acpi_video_init);
2145module_exit(acpi_video_exit);