blob: ae427100a1efd4544f0d3ee881ffcb1547f0e2bc [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>
Matthew Garrett74a365b2009-03-19 21:35:39 +000040#include <linux/pci.h>
41#include <linux/pci_ids.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070042#include <asm/uaccess.h>
43
44#include <acpi/acpi_bus.h>
45#include <acpi/acpi_drivers.h>
46
Linus Torvalds1da177e2005-04-16 15:20:36 -070047#define ACPI_VIDEO_CLASS "video"
Linus Torvalds1da177e2005-04-16 15:20:36 -070048#define ACPI_VIDEO_BUS_NAME "Video Bus"
49#define ACPI_VIDEO_DEVICE_NAME "Video Device"
50#define ACPI_VIDEO_NOTIFY_SWITCH 0x80
51#define ACPI_VIDEO_NOTIFY_PROBE 0x81
52#define ACPI_VIDEO_NOTIFY_CYCLE 0x82
53#define ACPI_VIDEO_NOTIFY_NEXT_OUTPUT 0x83
54#define ACPI_VIDEO_NOTIFY_PREV_OUTPUT 0x84
55
Thomas Tuttlef4715182006-12-19 12:56:14 -080056#define ACPI_VIDEO_NOTIFY_CYCLE_BRIGHTNESS 0x85
57#define ACPI_VIDEO_NOTIFY_INC_BRIGHTNESS 0x86
58#define ACPI_VIDEO_NOTIFY_DEC_BRIGHTNESS 0x87
59#define ACPI_VIDEO_NOTIFY_ZERO_BRIGHTNESS 0x88
60#define ACPI_VIDEO_NOTIFY_DISPLAY_OFF 0x89
Linus Torvalds1da177e2005-04-16 15:20:36 -070061
Yu Luming2f3d0002006-11-11 02:40:34 +080062#define MAX_NAME_LEN 20
Linus Torvalds1da177e2005-04-16 15:20:36 -070063
Rui Zhang82cae992007-01-03 23:40:53 -050064#define ACPI_VIDEO_DISPLAY_CRT 1
65#define ACPI_VIDEO_DISPLAY_TV 2
66#define ACPI_VIDEO_DISPLAY_DVI 3
67#define ACPI_VIDEO_DISPLAY_LCD 4
68
Linus Torvalds1da177e2005-04-16 15:20:36 -070069#define _COMPONENT ACPI_VIDEO_COMPONENT
Len Brownf52fd662007-02-12 22:42:12 -050070ACPI_MODULE_NAME("video");
Linus Torvalds1da177e2005-04-16 15:20:36 -070071
Len Brownf52fd662007-02-12 22:42:12 -050072MODULE_AUTHOR("Bruno Ducrot");
Len Brown7cda93e2007-02-12 23:50:02 -050073MODULE_DESCRIPTION("ACPI Video Driver");
Linus Torvalds1da177e2005-04-16 15:20:36 -070074MODULE_LICENSE("GPL");
75
Zhang Rui8a681a42008-01-25 14:47:49 +080076static int brightness_switch_enabled = 1;
77module_param(brightness_switch_enabled, bool, 0644);
78
Len Brown4be44fc2005-08-05 00:44:28 -040079static int acpi_video_bus_add(struct acpi_device *device);
80static int acpi_video_bus_remove(struct acpi_device *device, int type);
Matthew Garrett863c1492008-02-04 23:31:24 -080081static int acpi_video_resume(struct acpi_device *device);
Linus Torvalds1da177e2005-04-16 15:20:36 -070082
Thomas Renninger1ba90e32007-07-23 14:44:41 +020083static const struct acpi_device_id video_device_ids[] = {
84 {ACPI_VIDEO_HID, 0},
85 {"", 0},
86};
87MODULE_DEVICE_TABLE(acpi, video_device_ids);
88
Linus Torvalds1da177e2005-04-16 15:20:36 -070089static struct acpi_driver acpi_video_bus = {
Len Brownc2b67052007-02-12 23:33:40 -050090 .name = "video",
Linus Torvalds1da177e2005-04-16 15:20:36 -070091 .class = ACPI_VIDEO_CLASS,
Thomas Renninger1ba90e32007-07-23 14:44:41 +020092 .ids = video_device_ids,
Linus Torvalds1da177e2005-04-16 15:20:36 -070093 .ops = {
94 .add = acpi_video_bus_add,
95 .remove = acpi_video_bus_remove,
Matthew Garrett863c1492008-02-04 23:31:24 -080096 .resume = acpi_video_resume,
Len Brown4be44fc2005-08-05 00:44:28 -040097 },
Linus Torvalds1da177e2005-04-16 15:20:36 -070098};
99
100struct acpi_video_bus_flags {
Len Brown4be44fc2005-08-05 00:44:28 -0400101 u8 multihead:1; /* can switch video heads */
102 u8 rom:1; /* can retrieve a video rom */
103 u8 post:1; /* can configure the head to */
104 u8 reserved:5;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105};
106
107struct acpi_video_bus_cap {
Len Brown4be44fc2005-08-05 00:44:28 -0400108 u8 _DOS:1; /*Enable/Disable output switching */
109 u8 _DOD:1; /*Enumerate all devices attached to display adapter */
110 u8 _ROM:1; /*Get ROM Data */
111 u8 _GPD:1; /*Get POST Device */
112 u8 _SPD:1; /*Set POST Device */
113 u8 _VPO:1; /*Video POST Options */
114 u8 reserved:2;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700115};
116
Len Brown4be44fc2005-08-05 00:44:28 -0400117struct acpi_video_device_attrib {
118 u32 display_index:4; /* A zero-based instance of the Display */
Julius Volz98fb8fe2007-02-20 16:38:40 +0100119 u32 display_port_attachment:4; /*This field differentiates the display type */
Len Brown4be44fc2005-08-05 00:44:28 -0400120 u32 display_type:4; /*Describe the specific type in use */
Julius Volz98fb8fe2007-02-20 16:38:40 +0100121 u32 vendor_specific:4; /*Chipset Vendor Specific */
Len Brown4be44fc2005-08-05 00:44:28 -0400122 u32 bios_can_detect:1; /*BIOS can detect the device */
123 u32 depend_on_vga:1; /*Non-VGA output device whose power is related to
124 the VGA device. */
125 u32 pipe_id:3; /*For VGA multiple-head devices. */
126 u32 reserved:10; /*Must be 0 */
127 u32 device_id_scheme:1; /*Device ID Scheme */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128};
129
130struct acpi_video_enumerated_device {
131 union {
132 u32 int_val;
Len Brown4be44fc2005-08-05 00:44:28 -0400133 struct acpi_video_device_attrib attrib;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134 } value;
135 struct acpi_video_device *bind_info;
136};
137
138struct acpi_video_bus {
Patrick Mochele6afa0d2006-05-19 16:54:40 -0400139 struct acpi_device *device;
Len Brown4be44fc2005-08-05 00:44:28 -0400140 u8 dos_setting;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141 struct acpi_video_enumerated_device *attached_array;
Len Brown4be44fc2005-08-05 00:44:28 -0400142 u8 attached_count;
143 struct acpi_video_bus_cap cap;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144 struct acpi_video_bus_flags flags;
Len Brown4be44fc2005-08-05 00:44:28 -0400145 struct list_head video_device_list;
Dmitry Torokhovbbac81f2007-11-05 11:43:32 -0500146 struct mutex device_list_lock; /* protects video_device_list */
Len Brown4be44fc2005-08-05 00:44:28 -0400147 struct proc_dir_entry *dir;
Luming Yue9dab192007-08-20 18:23:53 +0800148 struct input_dev *input;
149 char phys[32]; /* for input device */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700150};
151
152struct acpi_video_device_flags {
Len Brown4be44fc2005-08-05 00:44:28 -0400153 u8 crt:1;
154 u8 lcd:1;
155 u8 tvout:1;
Rui Zhang82cae992007-01-03 23:40:53 -0500156 u8 dvi:1;
Len Brown4be44fc2005-08-05 00:44:28 -0400157 u8 bios:1;
158 u8 unknown:1;
Rui Zhang82cae992007-01-03 23:40:53 -0500159 u8 reserved:2;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700160};
161
162struct acpi_video_device_cap {
Len Brown4be44fc2005-08-05 00:44:28 -0400163 u8 _ADR:1; /*Return the unique ID */
164 u8 _BCL:1; /*Query list of brightness control levels supported */
165 u8 _BCM:1; /*Set the brightness level */
Yu Luming2f3d0002006-11-11 02:40:34 +0800166 u8 _BQC:1; /* Get current brightness level */
Zhang Ruic60d6382009-03-18 16:27:18 +0800167 u8 _BCQ:1; /* Some buggy BIOS uses _BCQ instead of _BQC */
Len Brown4be44fc2005-08-05 00:44:28 -0400168 u8 _DDC:1; /*Return the EDID for this device */
169 u8 _DCS:1; /*Return status of output device */
170 u8 _DGS:1; /*Query graphics state */
171 u8 _DSS:1; /*Device state set */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700172};
173
Zhang Ruid32f6942009-03-18 16:27:12 +0800174struct acpi_video_brightness_flags {
175 u8 _BCL_no_ac_battery_levels:1; /* no AC/Battery levels in _BCL */
Zhang Ruid80fb992009-03-18 16:27:14 +0800176 u8 _BCL_reversed:1; /* _BCL package is in a reversed order*/
Zhang Rui1a7c6182009-03-18 16:27:16 +0800177 u8 _BCL_use_index:1; /* levels in _BCL are index values */
178 u8 _BCM_use_index:1; /* input of _BCM is an index value */
179 u8 _BQC_use_index:1; /* _BQC returns an index value */
Zhang Ruid32f6942009-03-18 16:27:12 +0800180};
181
Linus Torvalds1da177e2005-04-16 15:20:36 -0700182struct acpi_video_device_brightness {
Len Brown4be44fc2005-08-05 00:44:28 -0400183 int curr;
184 int count;
185 int *levels;
Zhang Ruid32f6942009-03-18 16:27:12 +0800186 struct acpi_video_brightness_flags flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700187};
188
189struct acpi_video_device {
Len Brown4be44fc2005-08-05 00:44:28 -0400190 unsigned long device_id;
191 struct acpi_video_device_flags flags;
192 struct acpi_video_device_cap cap;
193 struct list_head entry;
194 struct acpi_video_bus *video;
195 struct acpi_device *dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700196 struct acpi_video_device_brightness *brightness;
Yu Luming2f3d0002006-11-11 02:40:34 +0800197 struct backlight_device *backlight;
Zhang Rui702ed512008-01-17 15:51:22 +0800198 struct thermal_cooling_device *cdev;
Luming Yu23b0f012007-05-09 21:07:05 +0800199 struct output_device *output_dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700200};
201
Linus Torvalds1da177e2005-04-16 15:20:36 -0700202/* bus */
203static int acpi_video_bus_info_open_fs(struct inode *inode, struct file *file);
204static struct file_operations acpi_video_bus_info_fops = {
Denis V. Lunevcf7acfa2008-04-29 01:02:27 -0700205 .owner = THIS_MODULE,
Len Brown4be44fc2005-08-05 00:44:28 -0400206 .open = acpi_video_bus_info_open_fs,
207 .read = seq_read,
208 .llseek = seq_lseek,
209 .release = single_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700210};
211
212static int acpi_video_bus_ROM_open_fs(struct inode *inode, struct file *file);
213static struct file_operations acpi_video_bus_ROM_fops = {
Denis V. Lunevcf7acfa2008-04-29 01:02:27 -0700214 .owner = THIS_MODULE,
Len Brown4be44fc2005-08-05 00:44:28 -0400215 .open = acpi_video_bus_ROM_open_fs,
216 .read = seq_read,
217 .llseek = seq_lseek,
218 .release = single_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700219};
220
Len Brown4be44fc2005-08-05 00:44:28 -0400221static int acpi_video_bus_POST_info_open_fs(struct inode *inode,
222 struct file *file);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700223static struct file_operations acpi_video_bus_POST_info_fops = {
Denis V. Lunevcf7acfa2008-04-29 01:02:27 -0700224 .owner = THIS_MODULE,
Len Brown4be44fc2005-08-05 00:44:28 -0400225 .open = acpi_video_bus_POST_info_open_fs,
226 .read = seq_read,
227 .llseek = seq_lseek,
228 .release = single_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700229};
230
231static int acpi_video_bus_POST_open_fs(struct inode *inode, struct file *file);
232static struct file_operations acpi_video_bus_POST_fops = {
Denis V. Lunevcf7acfa2008-04-29 01:02:27 -0700233 .owner = THIS_MODULE,
Len Brown4be44fc2005-08-05 00:44:28 -0400234 .open = acpi_video_bus_POST_open_fs,
235 .read = seq_read,
236 .llseek = seq_lseek,
237 .release = single_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700238};
239
Linus Torvalds1da177e2005-04-16 15:20:36 -0700240static int acpi_video_bus_DOS_open_fs(struct inode *inode, struct file *file);
241static struct file_operations acpi_video_bus_DOS_fops = {
Denis V. Lunevcf7acfa2008-04-29 01:02:27 -0700242 .owner = THIS_MODULE,
Len Brown4be44fc2005-08-05 00:44:28 -0400243 .open = acpi_video_bus_DOS_open_fs,
244 .read = seq_read,
245 .llseek = seq_lseek,
246 .release = single_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700247};
248
249/* device */
Len Brown4be44fc2005-08-05 00:44:28 -0400250static int acpi_video_device_info_open_fs(struct inode *inode,
251 struct file *file);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700252static struct file_operations acpi_video_device_info_fops = {
Denis V. Lunevcf7acfa2008-04-29 01:02:27 -0700253 .owner = THIS_MODULE,
Len Brown4be44fc2005-08-05 00:44:28 -0400254 .open = acpi_video_device_info_open_fs,
255 .read = seq_read,
256 .llseek = seq_lseek,
257 .release = single_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700258};
259
Len Brown4be44fc2005-08-05 00:44:28 -0400260static int acpi_video_device_state_open_fs(struct inode *inode,
261 struct file *file);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700262static struct file_operations acpi_video_device_state_fops = {
Denis V. Lunevcf7acfa2008-04-29 01:02:27 -0700263 .owner = THIS_MODULE,
Len Brown4be44fc2005-08-05 00:44:28 -0400264 .open = acpi_video_device_state_open_fs,
265 .read = seq_read,
266 .llseek = seq_lseek,
267 .release = single_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700268};
269
Len Brown4be44fc2005-08-05 00:44:28 -0400270static int acpi_video_device_brightness_open_fs(struct inode *inode,
271 struct file *file);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700272static struct file_operations acpi_video_device_brightness_fops = {
Denis V. Lunevcf7acfa2008-04-29 01:02:27 -0700273 .owner = THIS_MODULE,
Len Brown4be44fc2005-08-05 00:44:28 -0400274 .open = acpi_video_device_brightness_open_fs,
275 .read = seq_read,
276 .llseek = seq_lseek,
277 .release = single_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700278};
279
Len Brown4be44fc2005-08-05 00:44:28 -0400280static int acpi_video_device_EDID_open_fs(struct inode *inode,
281 struct file *file);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700282static struct file_operations acpi_video_device_EDID_fops = {
Denis V. Lunevcf7acfa2008-04-29 01:02:27 -0700283 .owner = THIS_MODULE,
Len Brown4be44fc2005-08-05 00:44:28 -0400284 .open = acpi_video_device_EDID_open_fs,
285 .read = seq_read,
286 .llseek = seq_lseek,
287 .release = single_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700288};
289
Len Brown4be44fc2005-08-05 00:44:28 -0400290static char device_decode[][30] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700291 "motherboard VGA device",
292 "PCI VGA device",
293 "AGP VGA device",
294 "UNKNOWN",
295};
296
Len Brown4be44fc2005-08-05 00:44:28 -0400297static void acpi_video_device_notify(acpi_handle handle, u32 event, void *data);
298static void acpi_video_device_rebind(struct acpi_video_bus *video);
299static void acpi_video_device_bind(struct acpi_video_bus *video,
300 struct acpi_video_device *device);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700301static int acpi_video_device_enumerate(struct acpi_video_bus *video);
Yu Luming2f3d0002006-11-11 02:40:34 +0800302static int acpi_video_device_lcd_set_level(struct acpi_video_device *device,
303 int level);
304static int acpi_video_device_lcd_get_level_current(
305 struct acpi_video_device *device,
Matthew Wilcox27663c52008-10-10 02:22:59 -0400306 unsigned long long *level);
Len Brown4be44fc2005-08-05 00:44:28 -0400307static int acpi_video_get_next_level(struct acpi_video_device *device,
308 u32 level_current, u32 event);
Zhang Ruic8890f92009-03-18 16:27:08 +0800309static int acpi_video_switch_brightness(struct acpi_video_device *device,
Len Brown4be44fc2005-08-05 00:44:28 -0400310 int event);
Luming Yu23b0f012007-05-09 21:07:05 +0800311static int acpi_video_device_get_state(struct acpi_video_device *device,
Matthew Wilcox27663c52008-10-10 02:22:59 -0400312 unsigned long long *state);
Luming Yu23b0f012007-05-09 21:07:05 +0800313static int acpi_video_output_get(struct output_device *od);
314static int acpi_video_device_set_state(struct acpi_video_device *device, int state);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700315
Yu Luming2f3d0002006-11-11 02:40:34 +0800316/*backlight device sysfs support*/
317static int acpi_video_get_brightness(struct backlight_device *bd)
318{
Matthew Wilcox27663c52008-10-10 02:22:59 -0400319 unsigned long long cur_level;
Matthew Garrett38531e62007-12-26 02:03:26 +0000320 int i;
Yu Luming2f3d0002006-11-11 02:40:34 +0800321 struct acpi_video_device *vd =
Richard Purdie655bfd72007-07-09 12:17:24 +0100322 (struct acpi_video_device *)bl_get_data(bd);
Zhang Ruic8890f92009-03-18 16:27:08 +0800323
324 if (acpi_video_device_lcd_get_level_current(vd, &cur_level))
325 return -EINVAL;
Matthew Garrett38531e62007-12-26 02:03:26 +0000326 for (i = 2; i < vd->brightness->count; i++) {
327 if (vd->brightness->levels[i] == cur_level)
328 /* The first two entries are special - see page 575
329 of the ACPI spec 3.0 */
330 return i-2;
331 }
332 return 0;
Yu Luming2f3d0002006-11-11 02:40:34 +0800333}
334
335static int acpi_video_set_brightness(struct backlight_device *bd)
336{
Zhang Rui24450c72009-03-18 16:27:10 +0800337 int request_level = bd->props.brightness + 2;
Yu Luming2f3d0002006-11-11 02:40:34 +0800338 struct acpi_video_device *vd =
Richard Purdie655bfd72007-07-09 12:17:24 +0100339 (struct acpi_video_device *)bl_get_data(bd);
Zhang Rui24450c72009-03-18 16:27:10 +0800340
341 return acpi_video_device_lcd_set_level(vd,
342 vd->brightness->levels[request_level]);
Yu Luming2f3d0002006-11-11 02:40:34 +0800343}
344
Richard Purdie599a52d2007-02-10 23:07:48 +0000345static struct backlight_ops acpi_backlight_ops = {
346 .get_brightness = acpi_video_get_brightness,
347 .update_status = acpi_video_set_brightness,
348};
349
Luming Yu23b0f012007-05-09 21:07:05 +0800350/*video output device sysfs support*/
351static int acpi_video_output_get(struct output_device *od)
352{
Matthew Wilcox27663c52008-10-10 02:22:59 -0400353 unsigned long long state;
Luming Yu23b0f012007-05-09 21:07:05 +0800354 struct acpi_video_device *vd =
tonyj@suse.de60043422007-08-07 22:28:47 -0700355 (struct acpi_video_device *)dev_get_drvdata(&od->dev);
Luming Yu23b0f012007-05-09 21:07:05 +0800356 acpi_video_device_get_state(vd, &state);
357 return (int)state;
358}
359
360static int acpi_video_output_set(struct output_device *od)
361{
362 unsigned long state = od->request_state;
363 struct acpi_video_device *vd=
tonyj@suse.de60043422007-08-07 22:28:47 -0700364 (struct acpi_video_device *)dev_get_drvdata(&od->dev);
Luming Yu23b0f012007-05-09 21:07:05 +0800365 return acpi_video_device_set_state(vd, state);
366}
367
368static struct output_properties acpi_output_properties = {
369 .set_state = acpi_video_output_set,
370 .get_status = acpi_video_output_get,
371};
Zhang Rui702ed512008-01-17 15:51:22 +0800372
373
374/* thermal cooling device callbacks */
375static int video_get_max_state(struct thermal_cooling_device *cdev, char *buf)
376{
377 struct acpi_device *device = cdev->devdata;
378 struct acpi_video_device *video = acpi_driver_data(device);
379
380 return sprintf(buf, "%d\n", video->brightness->count - 3);
381}
382
383static int video_get_cur_state(struct thermal_cooling_device *cdev, char *buf)
384{
385 struct acpi_device *device = cdev->devdata;
386 struct acpi_video_device *video = acpi_driver_data(device);
Matthew Wilcox27663c52008-10-10 02:22:59 -0400387 unsigned long long level;
Zhang Rui702ed512008-01-17 15:51:22 +0800388 int state;
389
Zhang Ruic8890f92009-03-18 16:27:08 +0800390 if (acpi_video_device_lcd_get_level_current(video, &level))
391 return -EINVAL;
Zhang Rui702ed512008-01-17 15:51:22 +0800392 for (state = 2; state < video->brightness->count; state++)
393 if (level == video->brightness->levels[state])
394 return sprintf(buf, "%d\n",
395 video->brightness->count - state - 1);
396
397 return -EINVAL;
398}
399
400static int
401video_set_cur_state(struct thermal_cooling_device *cdev, unsigned int state)
402{
403 struct acpi_device *device = cdev->devdata;
404 struct acpi_video_device *video = acpi_driver_data(device);
405 int level;
406
407 if ( state >= video->brightness->count - 2)
408 return -EINVAL;
409
410 state = video->brightness->count - state;
411 level = video->brightness->levels[state -1];
412 return acpi_video_device_lcd_set_level(video, level);
413}
414
415static struct thermal_cooling_device_ops video_cooling_ops = {
416 .get_max_state = video_get_max_state,
417 .get_cur_state = video_get_cur_state,
418 .set_cur_state = video_set_cur_state,
419};
420
Linus Torvalds1da177e2005-04-16 15:20:36 -0700421/* --------------------------------------------------------------------------
422 Video Management
423 -------------------------------------------------------------------------- */
424
425/* device */
426
427static int
Matthew Wilcox27663c52008-10-10 02:22:59 -0400428acpi_video_device_query(struct acpi_video_device *device, unsigned long long *state)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700429{
Len Brown4be44fc2005-08-05 00:44:28 -0400430 int status;
Patrick Mochel90130262006-05-19 16:54:48 -0400431
432 status = acpi_evaluate_integer(device->dev->handle, "_DGS", NULL, state);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700433
Patrick Mocheld550d982006-06-27 00:41:40 -0400434 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700435}
436
437static int
Len Brown4be44fc2005-08-05 00:44:28 -0400438acpi_video_device_get_state(struct acpi_video_device *device,
Matthew Wilcox27663c52008-10-10 02:22:59 -0400439 unsigned long long *state)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700440{
Len Brown4be44fc2005-08-05 00:44:28 -0400441 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700442
Patrick Mochel90130262006-05-19 16:54:48 -0400443 status = acpi_evaluate_integer(device->dev->handle, "_DCS", NULL, state);
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_set_state(struct acpi_video_device *device, int state)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700450{
Len Brown4be44fc2005-08-05 00:44:28 -0400451 int status;
452 union acpi_object arg0 = { ACPI_TYPE_INTEGER };
453 struct acpi_object_list args = { 1, &arg0 };
Matthew Wilcox27663c52008-10-10 02:22:59 -0400454 unsigned long long ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700455
Linus Torvalds1da177e2005-04-16 15:20:36 -0700456
457 arg0.integer.value = state;
Patrick Mochel90130262006-05-19 16:54:48 -0400458 status = acpi_evaluate_integer(device->dev->handle, "_DSS", &args, &ret);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700459
Patrick Mocheld550d982006-06-27 00:41:40 -0400460 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700461}
462
463static int
Len Brown4be44fc2005-08-05 00:44:28 -0400464acpi_video_device_lcd_query_levels(struct acpi_video_device *device,
465 union acpi_object **levels)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700466{
Len Brown4be44fc2005-08-05 00:44:28 -0400467 int status;
468 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
469 union acpi_object *obj;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700470
Linus Torvalds1da177e2005-04-16 15:20:36 -0700471
472 *levels = NULL;
473
Patrick Mochel90130262006-05-19 16:54:48 -0400474 status = acpi_evaluate_object(device->dev->handle, "_BCL", NULL, &buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700475 if (!ACPI_SUCCESS(status))
Patrick Mocheld550d982006-06-27 00:41:40 -0400476 return status;
Len Brown4be44fc2005-08-05 00:44:28 -0400477 obj = (union acpi_object *)buffer.pointer;
Adrian Bunk6665bda2006-03-11 10:12:00 -0500478 if (!obj || (obj->type != ACPI_TYPE_PACKAGE)) {
Len Brown64684632006-06-26 23:41:38 -0400479 printk(KERN_ERR PREFIX "Invalid _BCL data\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700480 status = -EFAULT;
481 goto err;
482 }
483
484 *levels = obj;
485
Patrick Mocheld550d982006-06-27 00:41:40 -0400486 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700487
Len Brown4be44fc2005-08-05 00:44:28 -0400488 err:
Jesper Juhl6044ec82005-11-07 01:01:32 -0800489 kfree(buffer.pointer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700490
Patrick Mocheld550d982006-06-27 00:41:40 -0400491 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700492}
493
494static int
Len Brown4be44fc2005-08-05 00:44:28 -0400495acpi_video_device_lcd_set_level(struct acpi_video_device *device, int level)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700496{
Zhang Rui24450c72009-03-18 16:27:10 +0800497 int status;
Len Brown4be44fc2005-08-05 00:44:28 -0400498 union acpi_object arg0 = { ACPI_TYPE_INTEGER };
499 struct acpi_object_list args = { 1, &arg0 };
Zhang Rui9e6dada2008-12-31 10:58:48 +0800500 int state;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700501
Linus Torvalds1da177e2005-04-16 15:20:36 -0700502 arg0.integer.value = level;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700503
Zhang Rui24450c72009-03-18 16:27:10 +0800504 status = acpi_evaluate_object(device->dev->handle, "_BCM",
505 &args, NULL);
506 if (ACPI_FAILURE(status)) {
507 ACPI_ERROR((AE_INFO, "Evaluating _BCM failed"));
508 return -EIO;
509 }
510
Alexey Starikovskiy4500ca82007-09-03 16:29:58 +0400511 device->brightness->curr = level;
Zhang Rui9e6dada2008-12-31 10:58:48 +0800512 for (state = 2; state < device->brightness->count; state++)
Zhang Rui24450c72009-03-18 16:27:10 +0800513 if (level == device->brightness->levels[state]) {
Zhang Rui1a7c6182009-03-18 16:27:16 +0800514 if (device->backlight)
515 device->backlight->props.brightness = state - 2;
Zhang Rui24450c72009-03-18 16:27:10 +0800516 return 0;
517 }
Zhang Rui9e6dada2008-12-31 10:58:48 +0800518
Zhang Rui24450c72009-03-18 16:27:10 +0800519 ACPI_ERROR((AE_INFO, "Current brightness invalid"));
520 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700521}
522
523static int
Len Brown4be44fc2005-08-05 00:44:28 -0400524acpi_video_device_lcd_get_level_current(struct acpi_video_device *device,
Matthew Wilcox27663c52008-10-10 02:22:59 -0400525 unsigned long long *level)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700526{
Zhang Ruic8890f92009-03-18 16:27:08 +0800527 acpi_status status = AE_OK;
528
Zhang Ruic60d6382009-03-18 16:27:18 +0800529 if (device->cap._BQC || device->cap._BCQ) {
530 char *buf = device->cap._BQC ? "_BQC" : "_BCQ";
531
532 status = acpi_evaluate_integer(device->dev->handle, buf,
Zhang Ruic8890f92009-03-18 16:27:08 +0800533 NULL, level);
534 if (ACPI_SUCCESS(status)) {
Zhang Rui1a7c6182009-03-18 16:27:16 +0800535 if (device->brightness->flags._BQC_use_index) {
536 if (device->brightness->flags._BCL_reversed)
537 *level = device->brightness->count
538 - 3 - (*level);
539 *level = device->brightness->levels[*level + 2];
540
541 }
Zhang Ruic8890f92009-03-18 16:27:08 +0800542 device->brightness->curr = *level;
543 return 0;
544 } else {
545 /* Fixme:
546 * should we return an error or ignore this failure?
547 * dev->brightness->curr is a cached value which stores
548 * the correct current backlight level in most cases.
549 * ACPI video backlight still works w/ buggy _BQC.
550 * http://bugzilla.kernel.org/show_bug.cgi?id=12233
551 */
Zhang Ruic60d6382009-03-18 16:27:18 +0800552 ACPI_WARNING((AE_INFO, "Evaluating %s failed", buf));
553 device->cap._BQC = device->cap._BCQ = 0;
Zhang Ruic8890f92009-03-18 16:27:08 +0800554 }
555 }
556
Alexey Starikovskiy4500ca82007-09-03 16:29:58 +0400557 *level = device->brightness->curr;
Zhang Ruic8890f92009-03-18 16:27:08 +0800558 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700559}
560
561static int
Len Brown4be44fc2005-08-05 00:44:28 -0400562acpi_video_device_EDID(struct acpi_video_device *device,
563 union acpi_object **edid, ssize_t length)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700564{
Len Brown4be44fc2005-08-05 00:44:28 -0400565 int status;
566 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
567 union acpi_object *obj;
568 union acpi_object arg0 = { ACPI_TYPE_INTEGER };
569 struct acpi_object_list args = { 1, &arg0 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700570
Linus Torvalds1da177e2005-04-16 15:20:36 -0700571
572 *edid = NULL;
573
574 if (!device)
Patrick Mocheld550d982006-06-27 00:41:40 -0400575 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700576 if (length == 128)
577 arg0.integer.value = 1;
578 else if (length == 256)
579 arg0.integer.value = 2;
580 else
Patrick Mocheld550d982006-06-27 00:41:40 -0400581 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700582
Patrick Mochel90130262006-05-19 16:54:48 -0400583 status = acpi_evaluate_object(device->dev->handle, "_DDC", &args, &buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700584 if (ACPI_FAILURE(status))
Patrick Mocheld550d982006-06-27 00:41:40 -0400585 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700586
Jan Engelhardt50dd0962006-10-01 00:28:50 +0200587 obj = buffer.pointer;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700588
589 if (obj && obj->type == ACPI_TYPE_BUFFER)
590 *edid = obj;
591 else {
Len Brown64684632006-06-26 23:41:38 -0400592 printk(KERN_ERR PREFIX "Invalid _DDC data\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700593 status = -EFAULT;
594 kfree(obj);
595 }
596
Patrick Mocheld550d982006-06-27 00:41:40 -0400597 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700598}
599
Linus Torvalds1da177e2005-04-16 15:20:36 -0700600/* bus */
601
602static int
Len Brown4be44fc2005-08-05 00:44:28 -0400603acpi_video_bus_set_POST(struct acpi_video_bus *video, unsigned long option)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700604{
Len Brown4be44fc2005-08-05 00:44:28 -0400605 int status;
Matthew Wilcox27663c52008-10-10 02:22:59 -0400606 unsigned long long tmp;
Len Brown4be44fc2005-08-05 00:44:28 -0400607 union acpi_object arg0 = { ACPI_TYPE_INTEGER };
608 struct acpi_object_list args = { 1, &arg0 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700609
Linus Torvalds1da177e2005-04-16 15:20:36 -0700610
611 arg0.integer.value = option;
612
Patrick Mochel90130262006-05-19 16:54:48 -0400613 status = acpi_evaluate_integer(video->device->handle, "_SPD", &args, &tmp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700614 if (ACPI_SUCCESS(status))
Len Brown4be44fc2005-08-05 00:44:28 -0400615 status = tmp ? (-EINVAL) : (AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700616
Patrick Mocheld550d982006-06-27 00:41:40 -0400617 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700618}
619
620static int
Matthew Wilcox27663c52008-10-10 02:22:59 -0400621acpi_video_bus_get_POST(struct acpi_video_bus *video, unsigned long long *id)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700622{
623 int status;
624
Patrick Mochel90130262006-05-19 16:54:48 -0400625 status = acpi_evaluate_integer(video->device->handle, "_GPD", NULL, id);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700626
Patrick Mocheld550d982006-06-27 00:41:40 -0400627 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700628}
629
630static int
Len Brown4be44fc2005-08-05 00:44:28 -0400631acpi_video_bus_POST_options(struct acpi_video_bus *video,
Matthew Wilcox27663c52008-10-10 02:22:59 -0400632 unsigned long long *options)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700633{
Len Brown4be44fc2005-08-05 00:44:28 -0400634 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700635
Patrick Mochel90130262006-05-19 16:54:48 -0400636 status = acpi_evaluate_integer(video->device->handle, "_VPO", NULL, options);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700637 *options &= 3;
638
Patrick Mocheld550d982006-06-27 00:41:40 -0400639 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700640}
641
642/*
643 * Arg:
644 * video : video bus device pointer
645 * bios_flag :
646 * 0. The system BIOS should NOT automatically switch(toggle)
647 * the active display output.
648 * 1. The system BIOS should automatically switch (toggle) the
Julius Volz98fb8fe2007-02-20 16:38:40 +0100649 * active display output. No switch event.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700650 * 2. The _DGS value should be locked.
651 * 3. The system BIOS should not automatically switch (toggle) the
652 * active display output, but instead generate the display switch
653 * event notify code.
654 * lcd_flag :
655 * 0. The system BIOS should automatically control the brightness level
Julius Volz98fb8fe2007-02-20 16:38:40 +0100656 * of the LCD when the power changes from AC to DC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700657 * 1. The system BIOS should NOT automatically control the brightness
Julius Volz98fb8fe2007-02-20 16:38:40 +0100658 * level of the LCD when the power changes from AC to DC.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700659 * Return Value:
660 * -1 wrong arg.
661 */
662
663static int
Len Brown4be44fc2005-08-05 00:44:28 -0400664acpi_video_bus_DOS(struct acpi_video_bus *video, int bios_flag, int lcd_flag)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700665{
Len Brown4be44fc2005-08-05 00:44:28 -0400666 acpi_integer status = 0;
667 union acpi_object arg0 = { ACPI_TYPE_INTEGER };
668 struct acpi_object_list args = { 1, &arg0 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700669
Linus Torvalds1da177e2005-04-16 15:20:36 -0700670
Len Brown4be44fc2005-08-05 00:44:28 -0400671 if (bios_flag < 0 || bios_flag > 3 || lcd_flag < 0 || lcd_flag > 1) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700672 status = -1;
673 goto Failed;
674 }
675 arg0.integer.value = (lcd_flag << 2) | bios_flag;
676 video->dos_setting = arg0.integer.value;
Patrick Mochel90130262006-05-19 16:54:48 -0400677 acpi_evaluate_object(video->device->handle, "_DOS", &args, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700678
Len Brown4be44fc2005-08-05 00:44:28 -0400679 Failed:
Patrick Mocheld550d982006-06-27 00:41:40 -0400680 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700681}
682
683/*
Zhang Rui935e5f22008-12-11 16:24:52 -0500684 * Simple comparison function used to sort backlight levels.
685 */
686
687static int
688acpi_video_cmp_level(const void *a, const void *b)
689{
690 return *(int *)a - *(int *)b;
691}
692
693/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700694 * Arg:
695 * device : video output device (LCD, CRT, ..)
696 *
697 * Return Value:
Julia Jomantaite469778c2008-06-23 22:50:42 +0100698 * Maximum brightness level
699 *
700 * Allocate and initialize device->brightness.
701 */
702
703static int
704acpi_video_init_brightness(struct acpi_video_device *device)
705{
706 union acpi_object *obj = NULL;
Zhang Ruid32f6942009-03-18 16:27:12 +0800707 int i, max_level = 0, count = 0, level_ac_battery = 0;
Zhang Rui1a7c6182009-03-18 16:27:16 +0800708 unsigned long long level, level_old;
Julia Jomantaite469778c2008-06-23 22:50:42 +0100709 union acpi_object *o;
710 struct acpi_video_device_brightness *br = NULL;
Zhang Rui1a7c6182009-03-18 16:27:16 +0800711 int result = -EINVAL;
Julia Jomantaite469778c2008-06-23 22:50:42 +0100712
713 if (!ACPI_SUCCESS(acpi_video_device_lcd_query_levels(device, &obj))) {
714 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Could not query available "
715 "LCD brightness level\n"));
716 goto out;
717 }
718
719 if (obj->package.count < 2)
720 goto out;
721
722 br = kzalloc(sizeof(*br), GFP_KERNEL);
723 if (!br) {
724 printk(KERN_ERR "can't allocate memory\n");
Zhang Rui1a7c6182009-03-18 16:27:16 +0800725 result = -ENOMEM;
Julia Jomantaite469778c2008-06-23 22:50:42 +0100726 goto out;
727 }
728
Zhang Ruid32f6942009-03-18 16:27:12 +0800729 br->levels = kmalloc((obj->package.count + 2) * sizeof *(br->levels),
Julia Jomantaite469778c2008-06-23 22:50:42 +0100730 GFP_KERNEL);
Zhang Rui1a7c6182009-03-18 16:27:16 +0800731 if (!br->levels) {
732 result = -ENOMEM;
Julia Jomantaite469778c2008-06-23 22:50:42 +0100733 goto out_free;
Zhang Rui1a7c6182009-03-18 16:27:16 +0800734 }
Julia Jomantaite469778c2008-06-23 22:50:42 +0100735
736 for (i = 0; i < obj->package.count; i++) {
737 o = (union acpi_object *)&obj->package.elements[i];
738 if (o->type != ACPI_TYPE_INTEGER) {
739 printk(KERN_ERR PREFIX "Invalid data\n");
740 continue;
741 }
742 br->levels[count] = (u32) o->integer.value;
743
744 if (br->levels[count] > max_level)
745 max_level = br->levels[count];
746 count++;
747 }
748
Zhang Ruid32f6942009-03-18 16:27:12 +0800749 /*
750 * some buggy BIOS don't export the levels
751 * when machine is on AC/Battery in _BCL package.
752 * In this case, the first two elements in _BCL packages
753 * are also supported brightness levels that OS should take care of.
754 */
755 for (i = 2; i < count; i++)
756 if (br->levels[i] == br->levels[0] ||
757 br->levels[i] == br->levels[1])
758 level_ac_battery++;
759
760 if (level_ac_battery < 2) {
761 level_ac_battery = 2 - level_ac_battery;
762 br->flags._BCL_no_ac_battery_levels = 1;
763 for (i = (count - 1 + level_ac_battery); i >= 2; i--)
764 br->levels[i] = br->levels[i - level_ac_battery];
765 count += level_ac_battery;
766 } else if (level_ac_battery > 2)
767 ACPI_ERROR((AE_INFO, "Too many duplicates in _BCL package\n"));
768
Zhang Ruid80fb992009-03-18 16:27:14 +0800769 /* Check if the _BCL package is in a reversed order */
770 if (max_level == br->levels[2]) {
771 br->flags._BCL_reversed = 1;
772 sort(&br->levels[2], count - 2, sizeof(br->levels[2]),
773 acpi_video_cmp_level, NULL);
774 } else if (max_level != br->levels[count - 1])
775 ACPI_ERROR((AE_INFO,
776 "Found unordered _BCL package\n"));
Zhang Rui935e5f22008-12-11 16:24:52 -0500777
Julia Jomantaite469778c2008-06-23 22:50:42 +0100778 br->count = count;
779 device->brightness = br;
Zhang Rui1a7c6182009-03-18 16:27:16 +0800780
781 /* Check the input/output of _BQC/_BCL/_BCM */
782 if ((max_level < 100) && (max_level <= (count - 2)))
783 br->flags._BCL_use_index = 1;
784
785 /*
786 * _BCM is always consistent with _BCL,
787 * at least for all the laptops we have ever seen.
788 */
789 br->flags._BCM_use_index = br->flags._BCL_use_index;
790
791 /* _BQC uses INDEX while _BCL uses VALUE in some laptops */
792 br->curr = max_level;
793 result = acpi_video_device_lcd_get_level_current(device, &level_old);
794 if (result)
795 goto out_free_levels;
796
797 result = acpi_video_device_lcd_set_level(device, br->curr);
798 if (result)
799 goto out_free_levels;
800
801 result = acpi_video_device_lcd_get_level_current(device, &level);
802 if (result)
803 goto out_free_levels;
804
805 if ((level != level_old) && !br->flags._BCM_use_index) {
806 /* Note:
807 * This piece of code does not work correctly if the current
808 * brightness levels is 0.
809 * But I guess boxes that boot with such a dark screen are rare
810 * and no more code is needed to cover this specifial case.
811 */
812
813 if (level_ac_battery != 2) {
814 /*
815 * For now, we don't support the _BCL like this:
816 * 16, 15, 0, 1, 2, 3, ..., 14, 15, 16
817 * because we may mess up the index returned by _BQC.
818 * Plus: we have not got a box like this.
819 */
820 ACPI_ERROR((AE_INFO, "_BCL not supported\n"));
821 }
822 br->flags._BQC_use_index = 1;
823 }
824
Zhang Ruid32f6942009-03-18 16:27:12 +0800825 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
826 "found %d brightness levels\n", count - 2));
Julia Jomantaite469778c2008-06-23 22:50:42 +0100827 kfree(obj);
Zhang Rui1a7c6182009-03-18 16:27:16 +0800828 return result;
Julia Jomantaite469778c2008-06-23 22:50:42 +0100829
830out_free_levels:
831 kfree(br->levels);
832out_free:
833 kfree(br);
834out:
835 device->brightness = NULL;
836 kfree(obj);
Zhang Rui1a7c6182009-03-18 16:27:16 +0800837 return result;
Julia Jomantaite469778c2008-06-23 22:50:42 +0100838}
839
840/*
841 * Arg:
842 * device : video output device (LCD, CRT, ..)
843 *
844 * Return Value:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700845 * None
846 *
Julius Volz98fb8fe2007-02-20 16:38:40 +0100847 * Find out all required AML methods defined under the output
Linus Torvalds1da177e2005-04-16 15:20:36 -0700848 * device.
849 */
850
Len Brown4be44fc2005-08-05 00:44:28 -0400851static void acpi_video_device_find_cap(struct acpi_video_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700852{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700853 acpi_handle h_dummy1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700854
Linus Torvalds1da177e2005-04-16 15:20:36 -0700855
William Lee Irwin III98934de2007-12-12 03:56:55 -0800856 memset(&device->cap, 0, sizeof(device->cap));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700857
Patrick Mochel90130262006-05-19 16:54:48 -0400858 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_ADR", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700859 device->cap._ADR = 1;
860 }
Patrick Mochel90130262006-05-19 16:54:48 -0400861 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_BCL", &h_dummy1))) {
Len Brown4be44fc2005-08-05 00:44:28 -0400862 device->cap._BCL = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700863 }
Patrick Mochel90130262006-05-19 16:54:48 -0400864 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_BCM", &h_dummy1))) {
Len Brown4be44fc2005-08-05 00:44:28 -0400865 device->cap._BCM = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700866 }
Yu Luming2f3d0002006-11-11 02:40:34 +0800867 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle,"_BQC",&h_dummy1)))
868 device->cap._BQC = 1;
Zhang Ruic60d6382009-03-18 16:27:18 +0800869 else if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_BCQ",
870 &h_dummy1))) {
871 printk(KERN_WARNING FW_BUG "_BCQ is used instead of _BQC\n");
872 device->cap._BCQ = 1;
873 }
874
Patrick Mochel90130262006-05-19 16:54:48 -0400875 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_DDC", &h_dummy1))) {
Len Brown4be44fc2005-08-05 00:44:28 -0400876 device->cap._DDC = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700877 }
Patrick Mochel90130262006-05-19 16:54:48 -0400878 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_DCS", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700879 device->cap._DCS = 1;
880 }
Patrick Mochel90130262006-05-19 16:54:48 -0400881 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_DGS", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700882 device->cap._DGS = 1;
883 }
Patrick Mochel90130262006-05-19 16:54:48 -0400884 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_DSS", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700885 device->cap._DSS = 1;
886 }
887
Zhang Rui1a7c6182009-03-18 16:27:16 +0800888 if (acpi_video_backlight_support()) {
Zhang Rui702ed512008-01-17 15:51:22 +0800889 int result;
Yu Luming2f3d0002006-11-11 02:40:34 +0800890 static int count = 0;
891 char *name;
Zhang Rui1a7c6182009-03-18 16:27:16 +0800892
893 result = acpi_video_init_brightness(device);
894 if (result)
895 return;
Yu Luming2f3d0002006-11-11 02:40:34 +0800896 name = kzalloc(MAX_NAME_LEN, GFP_KERNEL);
897 if (!name)
898 return;
899
Yu Luming2f3d0002006-11-11 02:40:34 +0800900 sprintf(name, "acpi_video%d", count++);
Yu Luming2f3d0002006-11-11 02:40:34 +0800901 device->backlight = backlight_device_register(name,
Richard Purdie599a52d2007-02-10 23:07:48 +0000902 NULL, device, &acpi_backlight_ops);
Matthew Garrett38531e62007-12-26 02:03:26 +0000903 device->backlight->props.max_brightness = device->brightness->count-3;
Yu Luming2f3d0002006-11-11 02:40:34 +0800904 kfree(name);
Zhang Rui702ed512008-01-17 15:51:22 +0800905
906 device->cdev = thermal_cooling_device_register("LCD",
907 device->dev, &video_cooling_ops);
Thomas Sujith43ff39f2008-02-15 18:29:18 -0500908 if (IS_ERR(device->cdev))
909 return;
910
Greg Kroah-Hartmanfc3a8822008-05-02 06:02:41 +0200911 dev_info(&device->dev->dev, "registered as cooling_device%d\n",
912 device->cdev->id);
Julia Lawall90300622008-04-11 10:09:24 +0800913 result = sysfs_create_link(&device->dev->dev.kobj,
914 &device->cdev->device.kobj,
915 "thermal_cooling");
916 if (result)
917 printk(KERN_ERR PREFIX "Create sysfs link\n");
918 result = sysfs_create_link(&device->cdev->device.kobj,
919 &device->dev->dev.kobj, "device");
920 if (result)
921 printk(KERN_ERR PREFIX "Create sysfs link\n");
922
Yu Luming2f3d0002006-11-11 02:40:34 +0800923 }
Thomas Renningerc3d6de62008-08-01 17:37:55 +0200924
925 if (acpi_video_display_switch_support()) {
926
927 if (device->cap._DCS && device->cap._DSS) {
928 static int count;
929 char *name;
930 name = kzalloc(MAX_NAME_LEN, GFP_KERNEL);
931 if (!name)
932 return;
933 sprintf(name, "acpi_video%d", count++);
934 device->output_dev = video_output_register(name,
935 NULL, device, &acpi_output_properties);
936 kfree(name);
937 }
Luming Yu23b0f012007-05-09 21:07:05 +0800938 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700939}
940
941/*
942 * Arg:
943 * device : video output device (VGA)
944 *
945 * Return Value:
946 * None
947 *
Julius Volz98fb8fe2007-02-20 16:38:40 +0100948 * Find out all required AML methods defined under the video bus device.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700949 */
950
Len Brown4be44fc2005-08-05 00:44:28 -0400951static void acpi_video_bus_find_cap(struct acpi_video_bus *video)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700952{
Len Brown4be44fc2005-08-05 00:44:28 -0400953 acpi_handle h_dummy1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700954
William Lee Irwin III98934de2007-12-12 03:56:55 -0800955 memset(&video->cap, 0, sizeof(video->cap));
Patrick Mochel90130262006-05-19 16:54:48 -0400956 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_DOS", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700957 video->cap._DOS = 1;
958 }
Patrick Mochel90130262006-05-19 16:54:48 -0400959 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_DOD", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700960 video->cap._DOD = 1;
961 }
Patrick Mochel90130262006-05-19 16:54:48 -0400962 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_ROM", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700963 video->cap._ROM = 1;
964 }
Patrick Mochel90130262006-05-19 16:54:48 -0400965 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_GPD", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700966 video->cap._GPD = 1;
967 }
Patrick Mochel90130262006-05-19 16:54:48 -0400968 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_SPD", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700969 video->cap._SPD = 1;
970 }
Patrick Mochel90130262006-05-19 16:54:48 -0400971 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_VPO", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700972 video->cap._VPO = 1;
973 }
974}
975
976/*
977 * Check whether the video bus device has required AML method to
978 * support the desired features
979 */
980
Len Brown4be44fc2005-08-05 00:44:28 -0400981static int acpi_video_bus_check(struct acpi_video_bus *video)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700982{
Len Brown4be44fc2005-08-05 00:44:28 -0400983 acpi_status status = -ENOENT;
Thomas Renninger22c13f92008-08-01 17:37:54 +0200984 struct device *dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700985
986 if (!video)
Patrick Mocheld550d982006-06-27 00:41:40 -0400987 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700988
Thomas Renninger22c13f92008-08-01 17:37:54 +0200989 dev = acpi_get_physical_pci_device(video->device->handle);
990 if (!dev)
991 return -ENODEV;
992 put_device(dev);
993
Linus Torvalds1da177e2005-04-16 15:20:36 -0700994 /* Since there is no HID, CID and so on for VGA driver, we have
995 * to check well known required nodes.
996 */
997
Julius Volz98fb8fe2007-02-20 16:38:40 +0100998 /* Does this device support video switching? */
Len Brown4be44fc2005-08-05 00:44:28 -0400999 if (video->cap._DOS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001000 video->flags.multihead = 1;
1001 status = 0;
1002 }
1003
Julius Volz98fb8fe2007-02-20 16:38:40 +01001004 /* Does this device support retrieving a video ROM? */
Len Brown4be44fc2005-08-05 00:44:28 -04001005 if (video->cap._ROM) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001006 video->flags.rom = 1;
1007 status = 0;
1008 }
1009
Julius Volz98fb8fe2007-02-20 16:38:40 +01001010 /* Does this device support configuring which video device to POST? */
Len Brown4be44fc2005-08-05 00:44:28 -04001011 if (video->cap._GPD && video->cap._SPD && video->cap._VPO) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001012 video->flags.post = 1;
1013 status = 0;
1014 }
1015
Patrick Mocheld550d982006-06-27 00:41:40 -04001016 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001017}
1018
1019/* --------------------------------------------------------------------------
1020 FS Interface (/proc)
1021 -------------------------------------------------------------------------- */
1022
Len Brown4be44fc2005-08-05 00:44:28 -04001023static struct proc_dir_entry *acpi_video_dir;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001024
1025/* video devices */
1026
Len Brown4be44fc2005-08-05 00:44:28 -04001027static int acpi_video_device_info_seq_show(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001028{
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001029 struct acpi_video_device *dev = seq->private;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001030
Linus Torvalds1da177e2005-04-16 15:20:36 -07001031
1032 if (!dev)
1033 goto end;
1034
1035 seq_printf(seq, "device_id: 0x%04x\n", (u32) dev->device_id);
1036 seq_printf(seq, "type: ");
1037 if (dev->flags.crt)
1038 seq_printf(seq, "CRT\n");
1039 else if (dev->flags.lcd)
1040 seq_printf(seq, "LCD\n");
1041 else if (dev->flags.tvout)
1042 seq_printf(seq, "TVOUT\n");
Rui Zhang82cae992007-01-03 23:40:53 -05001043 else if (dev->flags.dvi)
1044 seq_printf(seq, "DVI\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001045 else
1046 seq_printf(seq, "UNKNOWN\n");
1047
Len Brown4be44fc2005-08-05 00:44:28 -04001048 seq_printf(seq, "known by bios: %s\n", dev->flags.bios ? "yes" : "no");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001049
Len Brown4be44fc2005-08-05 00:44:28 -04001050 end:
Patrick Mocheld550d982006-06-27 00:41:40 -04001051 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001052}
1053
1054static int
Len Brown4be44fc2005-08-05 00:44:28 -04001055acpi_video_device_info_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001056{
1057 return single_open(file, acpi_video_device_info_seq_show,
1058 PDE(inode)->data);
1059}
1060
Len Brown4be44fc2005-08-05 00:44:28 -04001061static int acpi_video_device_state_seq_show(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001062{
Len Brown4be44fc2005-08-05 00:44:28 -04001063 int status;
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001064 struct acpi_video_device *dev = seq->private;
Matthew Wilcox27663c52008-10-10 02:22:59 -04001065 unsigned long long state;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001066
Linus Torvalds1da177e2005-04-16 15:20:36 -07001067
1068 if (!dev)
1069 goto end;
1070
1071 status = acpi_video_device_get_state(dev, &state);
1072 seq_printf(seq, "state: ");
1073 if (ACPI_SUCCESS(status))
Matthew Wilcox27663c52008-10-10 02:22:59 -04001074 seq_printf(seq, "0x%02llx\n", state);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001075 else
1076 seq_printf(seq, "<not supported>\n");
1077
1078 status = acpi_video_device_query(dev, &state);
1079 seq_printf(seq, "query: ");
1080 if (ACPI_SUCCESS(status))
Matthew Wilcox27663c52008-10-10 02:22:59 -04001081 seq_printf(seq, "0x%02llx\n", state);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001082 else
1083 seq_printf(seq, "<not supported>\n");
1084
Len Brown4be44fc2005-08-05 00:44:28 -04001085 end:
Patrick Mocheld550d982006-06-27 00:41:40 -04001086 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001087}
1088
1089static int
Len Brown4be44fc2005-08-05 00:44:28 -04001090acpi_video_device_state_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001091{
1092 return single_open(file, acpi_video_device_state_seq_show,
1093 PDE(inode)->data);
1094}
1095
1096static ssize_t
Len Brown4be44fc2005-08-05 00:44:28 -04001097acpi_video_device_write_state(struct file *file,
1098 const char __user * buffer,
1099 size_t count, loff_t * data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001100{
Len Brown4be44fc2005-08-05 00:44:28 -04001101 int status;
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001102 struct seq_file *m = file->private_data;
1103 struct acpi_video_device *dev = m->private;
Len Brown4be44fc2005-08-05 00:44:28 -04001104 char str[12] = { 0 };
1105 u32 state = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001106
Linus Torvalds1da177e2005-04-16 15:20:36 -07001107
1108 if (!dev || count + 1 > sizeof str)
Patrick Mocheld550d982006-06-27 00:41:40 -04001109 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001110
1111 if (copy_from_user(str, buffer, count))
Patrick Mocheld550d982006-06-27 00:41:40 -04001112 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001113
1114 str[count] = 0;
1115 state = simple_strtoul(str, NULL, 0);
Len Brown4be44fc2005-08-05 00:44:28 -04001116 state &= ((1ul << 31) | (1ul << 30) | (1ul << 0));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001117
1118 status = acpi_video_device_set_state(dev, state);
1119
1120 if (status)
Patrick Mocheld550d982006-06-27 00:41:40 -04001121 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001122
Patrick Mocheld550d982006-06-27 00:41:40 -04001123 return count;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001124}
1125
1126static int
Len Brown4be44fc2005-08-05 00:44:28 -04001127acpi_video_device_brightness_seq_show(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001128{
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001129 struct acpi_video_device *dev = seq->private;
Len Brown4be44fc2005-08-05 00:44:28 -04001130 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001131
Linus Torvalds1da177e2005-04-16 15:20:36 -07001132
1133 if (!dev || !dev->brightness) {
1134 seq_printf(seq, "<not supported>\n");
Patrick Mocheld550d982006-06-27 00:41:40 -04001135 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001136 }
1137
1138 seq_printf(seq, "levels: ");
Zhao Yakui0a3db1c2009-02-02 11:33:41 +08001139 for (i = 2; i < dev->brightness->count; i++)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001140 seq_printf(seq, " %d", dev->brightness->levels[i]);
1141 seq_printf(seq, "\ncurrent: %d\n", dev->brightness->curr);
1142
Patrick Mocheld550d982006-06-27 00:41:40 -04001143 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001144}
1145
1146static int
Len Brown4be44fc2005-08-05 00:44:28 -04001147acpi_video_device_brightness_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001148{
1149 return single_open(file, acpi_video_device_brightness_seq_show,
1150 PDE(inode)->data);
1151}
1152
1153static ssize_t
Len Brown4be44fc2005-08-05 00:44:28 -04001154acpi_video_device_write_brightness(struct file *file,
1155 const char __user * buffer,
1156 size_t count, loff_t * data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001157{
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001158 struct seq_file *m = file->private_data;
1159 struct acpi_video_device *dev = m->private;
Danny Baumannc88c5782007-11-02 13:47:53 +01001160 char str[5] = { 0 };
Len Brown4be44fc2005-08-05 00:44:28 -04001161 unsigned int level = 0;
1162 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001163
Linus Torvalds1da177e2005-04-16 15:20:36 -07001164
Thomas Renninger59d399d2005-11-08 05:27:00 -05001165 if (!dev || !dev->brightness || count + 1 > sizeof str)
Patrick Mocheld550d982006-06-27 00:41:40 -04001166 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001167
1168 if (copy_from_user(str, buffer, count))
Patrick Mocheld550d982006-06-27 00:41:40 -04001169 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001170
1171 str[count] = 0;
1172 level = simple_strtoul(str, NULL, 0);
Len Brown4be44fc2005-08-05 00:44:28 -04001173
Linus Torvalds1da177e2005-04-16 15:20:36 -07001174 if (level > 100)
Patrick Mocheld550d982006-06-27 00:41:40 -04001175 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001176
Julius Volz98fb8fe2007-02-20 16:38:40 +01001177 /* validate through the list of available levels */
Zhao Yakui0a3db1c2009-02-02 11:33:41 +08001178 for (i = 2; i < dev->brightness->count; i++)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001179 if (level == dev->brightness->levels[i]) {
Zhang Rui24450c72009-03-18 16:27:10 +08001180 if (!acpi_video_device_lcd_set_level(dev, level))
1181 return count;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001182 break;
1183 }
1184
Zhang Rui24450c72009-03-18 16:27:10 +08001185 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001186}
1187
Len Brown4be44fc2005-08-05 00:44:28 -04001188static int acpi_video_device_EDID_seq_show(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001189{
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001190 struct acpi_video_device *dev = seq->private;
Len Brown4be44fc2005-08-05 00:44:28 -04001191 int status;
1192 int i;
1193 union acpi_object *edid = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001194
Linus Torvalds1da177e2005-04-16 15:20:36 -07001195
1196 if (!dev)
1197 goto out;
1198
Len Brown4be44fc2005-08-05 00:44:28 -04001199 status = acpi_video_device_EDID(dev, &edid, 128);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001200 if (ACPI_FAILURE(status)) {
Len Brown4be44fc2005-08-05 00:44:28 -04001201 status = acpi_video_device_EDID(dev, &edid, 256);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001202 }
1203
1204 if (ACPI_FAILURE(status)) {
1205 goto out;
1206 }
1207
1208 if (edid && edid->type == ACPI_TYPE_BUFFER) {
1209 for (i = 0; i < edid->buffer.length; i++)
1210 seq_putc(seq, edid->buffer.pointer[i]);
1211 }
1212
Len Brown4be44fc2005-08-05 00:44:28 -04001213 out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001214 if (!edid)
1215 seq_printf(seq, "<not supported>\n");
1216 else
1217 kfree(edid);
1218
Patrick Mocheld550d982006-06-27 00:41:40 -04001219 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001220}
1221
1222static int
Len Brown4be44fc2005-08-05 00:44:28 -04001223acpi_video_device_EDID_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001224{
1225 return single_open(file, acpi_video_device_EDID_seq_show,
1226 PDE(inode)->data);
1227}
1228
Len Brown4be44fc2005-08-05 00:44:28 -04001229static int acpi_video_device_add_fs(struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001230{
Dmitry Torokhov251cb0b2007-11-05 11:43:34 -05001231 struct proc_dir_entry *entry, *device_dir;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001232 struct acpi_video_device *vid_dev;
1233
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001234 vid_dev = acpi_driver_data(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001235 if (!vid_dev)
Patrick Mocheld550d982006-06-27 00:41:40 -04001236 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001237
Dmitry Torokhov251cb0b2007-11-05 11:43:34 -05001238 device_dir = proc_mkdir(acpi_device_bid(device),
1239 vid_dev->video->dir);
1240 if (!device_dir)
1241 return -ENOMEM;
1242
1243 device_dir->owner = THIS_MODULE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001244
1245 /* 'info' [R] */
Alexey Dobriyane0066c4e2008-05-01 04:10:02 +04001246 entry = proc_create_data("info", S_IRUGO, device_dir,
Denis V. Lunevcf7acfa2008-04-29 01:02:27 -07001247 &acpi_video_device_info_fops, acpi_driver_data(device));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001248 if (!entry)
Dmitry Torokhov251cb0b2007-11-05 11:43:34 -05001249 goto err_remove_dir;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001250
1251 /* 'state' [R/W] */
Denis V. Lunevcf7acfa2008-04-29 01:02:27 -07001252 acpi_video_device_state_fops.write = acpi_video_device_write_state;
1253 entry = proc_create_data("state", S_IFREG | S_IRUGO | S_IWUSR,
Alexey Dobriyane0066c4e2008-05-01 04:10:02 +04001254 device_dir,
Denis V. Lunevcf7acfa2008-04-29 01:02:27 -07001255 &acpi_video_device_state_fops,
1256 acpi_driver_data(device));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001257 if (!entry)
Dmitry Torokhov251cb0b2007-11-05 11:43:34 -05001258 goto err_remove_info;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001259
1260 /* 'brightness' [R/W] */
Denis V. Lunevcf7acfa2008-04-29 01:02:27 -07001261 acpi_video_device_brightness_fops.write =
1262 acpi_video_device_write_brightness;
1263 entry = proc_create_data("brightness", S_IFREG | S_IRUGO | S_IWUSR,
Alexey Dobriyane0066c4e2008-05-01 04:10:02 +04001264 device_dir,
Denis V. Lunevcf7acfa2008-04-29 01:02:27 -07001265 &acpi_video_device_brightness_fops,
1266 acpi_driver_data(device));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001267 if (!entry)
Dmitry Torokhov251cb0b2007-11-05 11:43:34 -05001268 goto err_remove_state;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001269
1270 /* 'EDID' [R] */
Alexey Dobriyane0066c4e2008-05-01 04:10:02 +04001271 entry = proc_create_data("EDID", S_IRUGO, device_dir,
Denis V. Lunevcf7acfa2008-04-29 01:02:27 -07001272 &acpi_video_device_EDID_fops,
1273 acpi_driver_data(device));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001274 if (!entry)
Dmitry Torokhov251cb0b2007-11-05 11:43:34 -05001275 goto err_remove_brightness;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001276
Alexey Dobriyane0066c4e2008-05-01 04:10:02 +04001277 acpi_device_dir(device) = device_dir;
1278
Patrick Mocheld550d982006-06-27 00:41:40 -04001279 return 0;
Dmitry Torokhov251cb0b2007-11-05 11:43:34 -05001280
1281 err_remove_brightness:
1282 remove_proc_entry("brightness", device_dir);
1283 err_remove_state:
1284 remove_proc_entry("state", device_dir);
1285 err_remove_info:
1286 remove_proc_entry("info", device_dir);
1287 err_remove_dir:
1288 remove_proc_entry(acpi_device_bid(device), vid_dev->video->dir);
1289 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001290}
1291
Len Brown4be44fc2005-08-05 00:44:28 -04001292static int acpi_video_device_remove_fs(struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001293{
1294 struct acpi_video_device *vid_dev;
Dmitry Torokhov251cb0b2007-11-05 11:43:34 -05001295 struct proc_dir_entry *device_dir;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001296
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001297 vid_dev = acpi_driver_data(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001298 if (!vid_dev || !vid_dev->video || !vid_dev->video->dir)
Patrick Mocheld550d982006-06-27 00:41:40 -04001299 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001300
Dmitry Torokhov251cb0b2007-11-05 11:43:34 -05001301 device_dir = acpi_device_dir(device);
1302 if (device_dir) {
1303 remove_proc_entry("info", device_dir);
1304 remove_proc_entry("state", device_dir);
1305 remove_proc_entry("brightness", device_dir);
1306 remove_proc_entry("EDID", device_dir);
Len Brown4be44fc2005-08-05 00:44:28 -04001307 remove_proc_entry(acpi_device_bid(device), vid_dev->video->dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001308 acpi_device_dir(device) = NULL;
1309 }
1310
Patrick Mocheld550d982006-06-27 00:41:40 -04001311 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001312}
1313
Linus Torvalds1da177e2005-04-16 15:20:36 -07001314/* video bus */
Len Brown4be44fc2005-08-05 00:44:28 -04001315static int acpi_video_bus_info_seq_show(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001316{
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001317 struct acpi_video_bus *video = seq->private;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001318
Linus Torvalds1da177e2005-04-16 15:20:36 -07001319
1320 if (!video)
1321 goto end;
1322
1323 seq_printf(seq, "Switching heads: %s\n",
Len Brown4be44fc2005-08-05 00:44:28 -04001324 video->flags.multihead ? "yes" : "no");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001325 seq_printf(seq, "Video ROM: %s\n",
Len Brown4be44fc2005-08-05 00:44:28 -04001326 video->flags.rom ? "yes" : "no");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001327 seq_printf(seq, "Device to be POSTed on boot: %s\n",
Len Brown4be44fc2005-08-05 00:44:28 -04001328 video->flags.post ? "yes" : "no");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001329
Len Brown4be44fc2005-08-05 00:44:28 -04001330 end:
Patrick Mocheld550d982006-06-27 00:41:40 -04001331 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001332}
1333
Len Brown4be44fc2005-08-05 00:44:28 -04001334static int acpi_video_bus_info_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001335{
Len Brown4be44fc2005-08-05 00:44:28 -04001336 return single_open(file, acpi_video_bus_info_seq_show,
1337 PDE(inode)->data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001338}
1339
Len Brown4be44fc2005-08-05 00:44:28 -04001340static int acpi_video_bus_ROM_seq_show(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001341{
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001342 struct acpi_video_bus *video = seq->private;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001343
Linus Torvalds1da177e2005-04-16 15:20:36 -07001344
1345 if (!video)
1346 goto end;
1347
Harvey Harrison96b2dd12008-03-05 18:24:51 -08001348 printk(KERN_INFO PREFIX "Please implement %s\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001349 seq_printf(seq, "<TODO>\n");
1350
Len Brown4be44fc2005-08-05 00:44:28 -04001351 end:
Patrick Mocheld550d982006-06-27 00:41:40 -04001352 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001353}
1354
Len Brown4be44fc2005-08-05 00:44:28 -04001355static int acpi_video_bus_ROM_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001356{
1357 return single_open(file, acpi_video_bus_ROM_seq_show, PDE(inode)->data);
1358}
1359
Len Brown4be44fc2005-08-05 00:44:28 -04001360static int acpi_video_bus_POST_info_seq_show(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001361{
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001362 struct acpi_video_bus *video = seq->private;
Matthew Wilcox27663c52008-10-10 02:22:59 -04001363 unsigned long long options;
Len Brown4be44fc2005-08-05 00:44:28 -04001364 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001365
Linus Torvalds1da177e2005-04-16 15:20:36 -07001366
1367 if (!video)
1368 goto end;
1369
1370 status = acpi_video_bus_POST_options(video, &options);
1371 if (ACPI_SUCCESS(status)) {
1372 if (!(options & 1)) {
Len Brown4be44fc2005-08-05 00:44:28 -04001373 printk(KERN_WARNING PREFIX
1374 "The motherboard VGA device is not listed as a possible POST device.\n");
1375 printk(KERN_WARNING PREFIX
Julius Volz98fb8fe2007-02-20 16:38:40 +01001376 "This indicates a BIOS bug. Please contact the manufacturer.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001377 }
Frank Seidel4d939152009-02-04 17:03:07 +01001378 printk(KERN_WARNING "%llx\n", options);
Julius Volz98fb8fe2007-02-20 16:38:40 +01001379 seq_printf(seq, "can POST: <integrated video>");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001380 if (options & 2)
1381 seq_printf(seq, " <PCI video>");
1382 if (options & 4)
1383 seq_printf(seq, " <AGP video>");
1384 seq_putc(seq, '\n');
1385 } else
1386 seq_printf(seq, "<not supported>\n");
Len Brown4be44fc2005-08-05 00:44:28 -04001387 end:
Patrick Mocheld550d982006-06-27 00:41:40 -04001388 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001389}
1390
1391static int
Len Brown4be44fc2005-08-05 00:44:28 -04001392acpi_video_bus_POST_info_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001393{
Len Brown4be44fc2005-08-05 00:44:28 -04001394 return single_open(file, acpi_video_bus_POST_info_seq_show,
1395 PDE(inode)->data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001396}
1397
Len Brown4be44fc2005-08-05 00:44:28 -04001398static int acpi_video_bus_POST_seq_show(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001399{
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001400 struct acpi_video_bus *video = seq->private;
Len Brown4be44fc2005-08-05 00:44:28 -04001401 int status;
Matthew Wilcox27663c52008-10-10 02:22:59 -04001402 unsigned long long id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001403
Linus Torvalds1da177e2005-04-16 15:20:36 -07001404
1405 if (!video)
1406 goto end;
1407
Len Brown4be44fc2005-08-05 00:44:28 -04001408 status = acpi_video_bus_get_POST(video, &id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001409 if (!ACPI_SUCCESS(status)) {
1410 seq_printf(seq, "<not supported>\n");
1411 goto end;
1412 }
Julius Volz98fb8fe2007-02-20 16:38:40 +01001413 seq_printf(seq, "device POSTed is <%s>\n", device_decode[id & 3]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001414
Len Brown4be44fc2005-08-05 00:44:28 -04001415 end:
Patrick Mocheld550d982006-06-27 00:41:40 -04001416 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001417}
1418
Len Brown4be44fc2005-08-05 00:44:28 -04001419static int acpi_video_bus_DOS_seq_show(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001420{
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001421 struct acpi_video_bus *video = seq->private;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001422
Linus Torvalds1da177e2005-04-16 15:20:36 -07001423
Len Brown4be44fc2005-08-05 00:44:28 -04001424 seq_printf(seq, "DOS setting: <%d>\n", video->dos_setting);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001425
Patrick Mocheld550d982006-06-27 00:41:40 -04001426 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001427}
1428
Len Brown4be44fc2005-08-05 00:44:28 -04001429static int acpi_video_bus_POST_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001430{
Len Brown4be44fc2005-08-05 00:44:28 -04001431 return single_open(file, acpi_video_bus_POST_seq_show,
1432 PDE(inode)->data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001433}
1434
Len Brown4be44fc2005-08-05 00:44:28 -04001435static int acpi_video_bus_DOS_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001436{
1437 return single_open(file, acpi_video_bus_DOS_seq_show, PDE(inode)->data);
1438}
1439
1440static ssize_t
Len Brown4be44fc2005-08-05 00:44:28 -04001441acpi_video_bus_write_POST(struct file *file,
1442 const char __user * buffer,
1443 size_t count, loff_t * data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001444{
Len Brown4be44fc2005-08-05 00:44:28 -04001445 int status;
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001446 struct seq_file *m = file->private_data;
1447 struct acpi_video_bus *video = m->private;
Len Brown4be44fc2005-08-05 00:44:28 -04001448 char str[12] = { 0 };
Matthew Wilcox27663c52008-10-10 02:22:59 -04001449 unsigned long long opt, options;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001450
Linus Torvalds1da177e2005-04-16 15:20:36 -07001451
Linus Torvalds1da177e2005-04-16 15:20:36 -07001452 if (!video || count + 1 > sizeof str)
Patrick Mocheld550d982006-06-27 00:41:40 -04001453 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001454
1455 status = acpi_video_bus_POST_options(video, &options);
1456 if (!ACPI_SUCCESS(status))
Patrick Mocheld550d982006-06-27 00:41:40 -04001457 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001458
1459 if (copy_from_user(str, buffer, count))
Patrick Mocheld550d982006-06-27 00:41:40 -04001460 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001461
1462 str[count] = 0;
1463 opt = strtoul(str, NULL, 0);
1464 if (opt > 3)
Patrick Mocheld550d982006-06-27 00:41:40 -04001465 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001466
Julius Volz98fb8fe2007-02-20 16:38:40 +01001467 /* just in case an OEM 'forgot' the motherboard... */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001468 options |= 1;
1469
1470 if (options & (1ul << opt)) {
Len Brown4be44fc2005-08-05 00:44:28 -04001471 status = acpi_video_bus_set_POST(video, opt);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001472 if (!ACPI_SUCCESS(status))
Patrick Mocheld550d982006-06-27 00:41:40 -04001473 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001474
1475 }
1476
Patrick Mocheld550d982006-06-27 00:41:40 -04001477 return count;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001478}
1479
1480static ssize_t
Len Brown4be44fc2005-08-05 00:44:28 -04001481acpi_video_bus_write_DOS(struct file *file,
1482 const char __user * buffer,
1483 size_t count, loff_t * data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001484{
Len Brown4be44fc2005-08-05 00:44:28 -04001485 int status;
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001486 struct seq_file *m = file->private_data;
1487 struct acpi_video_bus *video = m->private;
Len Brown4be44fc2005-08-05 00:44:28 -04001488 char str[12] = { 0 };
1489 unsigned long opt;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001490
Linus Torvalds1da177e2005-04-16 15:20:36 -07001491
Linus Torvalds1da177e2005-04-16 15:20:36 -07001492 if (!video || count + 1 > sizeof str)
Patrick Mocheld550d982006-06-27 00:41:40 -04001493 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001494
1495 if (copy_from_user(str, buffer, count))
Patrick Mocheld550d982006-06-27 00:41:40 -04001496 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001497
1498 str[count] = 0;
1499 opt = strtoul(str, NULL, 0);
1500 if (opt > 7)
Patrick Mocheld550d982006-06-27 00:41:40 -04001501 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001502
Len Brown4be44fc2005-08-05 00:44:28 -04001503 status = acpi_video_bus_DOS(video, opt & 0x3, (opt & 0x4) >> 2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001504
1505 if (!ACPI_SUCCESS(status))
Patrick Mocheld550d982006-06-27 00:41:40 -04001506 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001507
Patrick Mocheld550d982006-06-27 00:41:40 -04001508 return count;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001509}
1510
Len Brown4be44fc2005-08-05 00:44:28 -04001511static int acpi_video_bus_add_fs(struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001512{
Dmitry Torokhov251cb0b2007-11-05 11:43:34 -05001513 struct acpi_video_bus *video = acpi_driver_data(device);
1514 struct proc_dir_entry *device_dir;
1515 struct proc_dir_entry *entry;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001516
Dmitry Torokhov251cb0b2007-11-05 11:43:34 -05001517 device_dir = proc_mkdir(acpi_device_bid(device), acpi_video_dir);
1518 if (!device_dir)
1519 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001520
Dmitry Torokhov251cb0b2007-11-05 11:43:34 -05001521 device_dir->owner = THIS_MODULE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001522
1523 /* 'info' [R] */
Alexey Dobriyane0066c4e2008-05-01 04:10:02 +04001524 entry = proc_create_data("info", S_IRUGO, device_dir,
Denis V. Lunevcf7acfa2008-04-29 01:02:27 -07001525 &acpi_video_bus_info_fops,
1526 acpi_driver_data(device));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001527 if (!entry)
Dmitry Torokhov251cb0b2007-11-05 11:43:34 -05001528 goto err_remove_dir;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001529
1530 /* 'ROM' [R] */
Alexey Dobriyane0066c4e2008-05-01 04:10:02 +04001531 entry = proc_create_data("ROM", S_IRUGO, device_dir,
Denis V. Lunevcf7acfa2008-04-29 01:02:27 -07001532 &acpi_video_bus_ROM_fops,
1533 acpi_driver_data(device));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001534 if (!entry)
Dmitry Torokhov251cb0b2007-11-05 11:43:34 -05001535 goto err_remove_info;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001536
1537 /* 'POST_info' [R] */
Alexey Dobriyane0066c4e2008-05-01 04:10:02 +04001538 entry = proc_create_data("POST_info", S_IRUGO, device_dir,
Denis V. Lunevcf7acfa2008-04-29 01:02:27 -07001539 &acpi_video_bus_POST_info_fops,
1540 acpi_driver_data(device));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001541 if (!entry)
Dmitry Torokhov251cb0b2007-11-05 11:43:34 -05001542 goto err_remove_rom;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001543
1544 /* 'POST' [R/W] */
Denis V. Lunevcf7acfa2008-04-29 01:02:27 -07001545 acpi_video_bus_POST_fops.write = acpi_video_bus_write_POST;
Linus Torvalds08acd4f2008-04-30 11:52:52 -07001546 entry = proc_create_data("POST", S_IFREG | S_IRUGO | S_IWUSR,
Alexey Dobriyane0066c4e2008-05-01 04:10:02 +04001547 device_dir,
Denis V. Lunevcf7acfa2008-04-29 01:02:27 -07001548 &acpi_video_bus_POST_fops,
1549 acpi_driver_data(device));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001550 if (!entry)
Dmitry Torokhov251cb0b2007-11-05 11:43:34 -05001551 goto err_remove_post_info;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001552
1553 /* 'DOS' [R/W] */
Denis V. Lunevcf7acfa2008-04-29 01:02:27 -07001554 acpi_video_bus_DOS_fops.write = acpi_video_bus_write_DOS;
Linus Torvalds08acd4f2008-04-30 11:52:52 -07001555 entry = proc_create_data("DOS", S_IFREG | S_IRUGO | S_IWUSR,
Alexey Dobriyane0066c4e2008-05-01 04:10:02 +04001556 device_dir,
Denis V. Lunevcf7acfa2008-04-29 01:02:27 -07001557 &acpi_video_bus_DOS_fops,
1558 acpi_driver_data(device));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001559 if (!entry)
Dmitry Torokhov251cb0b2007-11-05 11:43:34 -05001560 goto err_remove_post;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001561
Dmitry Torokhov251cb0b2007-11-05 11:43:34 -05001562 video->dir = acpi_device_dir(device) = device_dir;
Patrick Mocheld550d982006-06-27 00:41:40 -04001563 return 0;
Dmitry Torokhov251cb0b2007-11-05 11:43:34 -05001564
1565 err_remove_post:
1566 remove_proc_entry("POST", device_dir);
1567 err_remove_post_info:
1568 remove_proc_entry("POST_info", device_dir);
1569 err_remove_rom:
1570 remove_proc_entry("ROM", device_dir);
1571 err_remove_info:
1572 remove_proc_entry("info", device_dir);
1573 err_remove_dir:
1574 remove_proc_entry(acpi_device_bid(device), acpi_video_dir);
1575 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001576}
1577
Len Brown4be44fc2005-08-05 00:44:28 -04001578static int acpi_video_bus_remove_fs(struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001579{
Dmitry Torokhov251cb0b2007-11-05 11:43:34 -05001580 struct proc_dir_entry *device_dir = acpi_device_dir(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001581
Dmitry Torokhov251cb0b2007-11-05 11:43:34 -05001582 if (device_dir) {
1583 remove_proc_entry("info", device_dir);
1584 remove_proc_entry("ROM", device_dir);
1585 remove_proc_entry("POST_info", device_dir);
1586 remove_proc_entry("POST", device_dir);
1587 remove_proc_entry("DOS", device_dir);
Len Brown4be44fc2005-08-05 00:44:28 -04001588 remove_proc_entry(acpi_device_bid(device), acpi_video_dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001589 acpi_device_dir(device) = NULL;
1590 }
1591
Patrick Mocheld550d982006-06-27 00:41:40 -04001592 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001593}
1594
1595/* --------------------------------------------------------------------------
1596 Driver Interface
1597 -------------------------------------------------------------------------- */
1598
1599/* device interface */
Rui Zhang82cae992007-01-03 23:40:53 -05001600static struct acpi_video_device_attrib*
1601acpi_video_get_device_attr(struct acpi_video_bus *video, unsigned long device_id)
1602{
Dmitry Torokhov78eed022007-11-05 11:43:33 -05001603 struct acpi_video_enumerated_device *ids;
1604 int i;
Rui Zhang82cae992007-01-03 23:40:53 -05001605
Dmitry Torokhov78eed022007-11-05 11:43:33 -05001606 for (i = 0; i < video->attached_count; i++) {
1607 ids = &video->attached_array[i];
1608 if ((ids->value.int_val & 0xffff) == device_id)
1609 return &ids->value.attrib;
1610 }
1611
Rui Zhang82cae992007-01-03 23:40:53 -05001612 return NULL;
1613}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001614
1615static int
Len Brown4be44fc2005-08-05 00:44:28 -04001616acpi_video_bus_get_one_device(struct acpi_device *device,
1617 struct acpi_video_bus *video)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001618{
Matthew Wilcox27663c52008-10-10 02:22:59 -04001619 unsigned long long device_id;
Yu, Luming973bf492006-04-27 05:25:00 -04001620 int status;
Len Brown4be44fc2005-08-05 00:44:28 -04001621 struct acpi_video_device *data;
Rui Zhang82cae992007-01-03 23:40:53 -05001622 struct acpi_video_device_attrib* attribute;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001623
1624 if (!device || !video)
Patrick Mocheld550d982006-06-27 00:41:40 -04001625 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001626
Len Brown4be44fc2005-08-05 00:44:28 -04001627 status =
1628 acpi_evaluate_integer(device->handle, "_ADR", NULL, &device_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001629 if (ACPI_SUCCESS(status)) {
1630
Burman Yan36bcbec2006-12-19 12:56:11 -08001631 data = kzalloc(sizeof(struct acpi_video_device), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001632 if (!data)
Patrick Mocheld550d982006-06-27 00:41:40 -04001633 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001634
Linus Torvalds1da177e2005-04-16 15:20:36 -07001635 strcpy(acpi_device_name(device), ACPI_VIDEO_DEVICE_NAME);
1636 strcpy(acpi_device_class(device), ACPI_VIDEO_CLASS);
Pavel Machekdb89b4f2008-09-22 14:37:34 -07001637 device->driver_data = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001638
1639 data->device_id = device_id;
1640 data->video = video;
1641 data->dev = device;
1642
Rui Zhang82cae992007-01-03 23:40:53 -05001643 attribute = acpi_video_get_device_attr(video, device_id);
1644
1645 if((attribute != NULL) && attribute->device_id_scheme) {
1646 switch (attribute->display_type) {
1647 case ACPI_VIDEO_DISPLAY_CRT:
1648 data->flags.crt = 1;
1649 break;
1650 case ACPI_VIDEO_DISPLAY_TV:
1651 data->flags.tvout = 1;
1652 break;
1653 case ACPI_VIDEO_DISPLAY_DVI:
1654 data->flags.dvi = 1;
1655 break;
1656 case ACPI_VIDEO_DISPLAY_LCD:
1657 data->flags.lcd = 1;
1658 break;
1659 default:
1660 data->flags.unknown = 1;
1661 break;
1662 }
1663 if(attribute->bios_can_detect)
1664 data->flags.bios = 1;
1665 } else
Linus Torvalds1da177e2005-04-16 15:20:36 -07001666 data->flags.unknown = 1;
Len Brown4be44fc2005-08-05 00:44:28 -04001667
Linus Torvalds1da177e2005-04-16 15:20:36 -07001668 acpi_video_device_bind(video, data);
1669 acpi_video_device_find_cap(data);
1670
Patrick Mochel90130262006-05-19 16:54:48 -04001671 status = acpi_install_notify_handler(device->handle,
Len Brown4be44fc2005-08-05 00:44:28 -04001672 ACPI_DEVICE_NOTIFY,
1673 acpi_video_device_notify,
1674 data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001675 if (ACPI_FAILURE(status)) {
Lin Ming55ac9a02008-09-28 14:51:56 +08001676 printk(KERN_ERR PREFIX
1677 "Error installing notify handler\n");
Yu, Luming973bf492006-04-27 05:25:00 -04001678 if(data->brightness)
1679 kfree(data->brightness->levels);
1680 kfree(data->brightness);
1681 kfree(data);
1682 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001683 }
1684
Dmitry Torokhovbbac81f2007-11-05 11:43:32 -05001685 mutex_lock(&video->device_list_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001686 list_add_tail(&data->entry, &video->video_device_list);
Dmitry Torokhovbbac81f2007-11-05 11:43:32 -05001687 mutex_unlock(&video->device_list_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001688
1689 acpi_video_device_add_fs(device);
1690
Patrick Mocheld550d982006-06-27 00:41:40 -04001691 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001692 }
1693
Patrick Mocheld550d982006-06-27 00:41:40 -04001694 return -ENOENT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001695}
1696
1697/*
1698 * Arg:
1699 * video : video bus device
1700 *
1701 * Return:
1702 * none
1703 *
1704 * Enumerate the video device list of the video bus,
1705 * bind the ids with the corresponding video devices
1706 * under the video bus.
Len Brown4be44fc2005-08-05 00:44:28 -04001707 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001708
Len Brown4be44fc2005-08-05 00:44:28 -04001709static void acpi_video_device_rebind(struct acpi_video_bus *video)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001710{
Dmitry Torokhovff102ea2007-11-05 11:43:31 -05001711 struct acpi_video_device *dev;
1712
Dmitry Torokhovbbac81f2007-11-05 11:43:32 -05001713 mutex_lock(&video->device_list_lock);
Dmitry Torokhovff102ea2007-11-05 11:43:31 -05001714
1715 list_for_each_entry(dev, &video->video_device_list, entry)
Len Brown4be44fc2005-08-05 00:44:28 -04001716 acpi_video_device_bind(video, dev);
Dmitry Torokhovff102ea2007-11-05 11:43:31 -05001717
Dmitry Torokhovbbac81f2007-11-05 11:43:32 -05001718 mutex_unlock(&video->device_list_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001719}
1720
1721/*
1722 * Arg:
1723 * video : video bus device
1724 * device : video output device under the video
1725 * bus
1726 *
1727 * Return:
1728 * none
1729 *
1730 * Bind the ids with the corresponding video devices
1731 * under the video bus.
Len Brown4be44fc2005-08-05 00:44:28 -04001732 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001733
1734static void
Len Brown4be44fc2005-08-05 00:44:28 -04001735acpi_video_device_bind(struct acpi_video_bus *video,
1736 struct acpi_video_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001737{
Dmitry Torokhov78eed022007-11-05 11:43:33 -05001738 struct acpi_video_enumerated_device *ids;
Len Brown4be44fc2005-08-05 00:44:28 -04001739 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001740
Dmitry Torokhov78eed022007-11-05 11:43:33 -05001741 for (i = 0; i < video->attached_count; i++) {
1742 ids = &video->attached_array[i];
1743 if (device->device_id == (ids->value.int_val & 0xffff)) {
1744 ids->bind_info = device;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001745 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "device_bind %d\n", i));
1746 }
1747 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001748}
1749
1750/*
1751 * Arg:
1752 * video : video bus device
1753 *
1754 * Return:
1755 * < 0 : error
1756 *
1757 * Call _DOD to enumerate all devices attached to display adapter
1758 *
Len Brown4be44fc2005-08-05 00:44:28 -04001759 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001760
1761static int acpi_video_device_enumerate(struct acpi_video_bus *video)
1762{
Len Brown4be44fc2005-08-05 00:44:28 -04001763 int status;
1764 int count;
1765 int i;
Dmitry Torokhov78eed022007-11-05 11:43:33 -05001766 struct acpi_video_enumerated_device *active_list;
Len Brown4be44fc2005-08-05 00:44:28 -04001767 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
1768 union acpi_object *dod = NULL;
1769 union acpi_object *obj;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001770
Patrick Mochel90130262006-05-19 16:54:48 -04001771 status = acpi_evaluate_object(video->device->handle, "_DOD", NULL, &buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001772 if (!ACPI_SUCCESS(status)) {
Thomas Renningera6fc6722006-06-26 23:58:43 -04001773 ACPI_EXCEPTION((AE_INFO, status, "Evaluating _DOD"));
Patrick Mocheld550d982006-06-27 00:41:40 -04001774 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001775 }
1776
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001777 dod = buffer.pointer;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001778 if (!dod || (dod->type != ACPI_TYPE_PACKAGE)) {
Thomas Renningera6fc6722006-06-26 23:58:43 -04001779 ACPI_EXCEPTION((AE_INFO, status, "Invalid _DOD data"));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001780 status = -EFAULT;
1781 goto out;
1782 }
1783
1784 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found %d video heads in _DOD\n",
Len Brown4be44fc2005-08-05 00:44:28 -04001785 dod->package.count));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001786
Dmitry Torokhov78eed022007-11-05 11:43:33 -05001787 active_list = kcalloc(1 + dod->package.count,
1788 sizeof(struct acpi_video_enumerated_device),
1789 GFP_KERNEL);
1790 if (!active_list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001791 status = -ENOMEM;
1792 goto out;
1793 }
1794
1795 count = 0;
1796 for (i = 0; i < dod->package.count; i++) {
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001797 obj = &dod->package.elements[i];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001798
1799 if (obj->type != ACPI_TYPE_INTEGER) {
Dmitry Torokhov78eed022007-11-05 11:43:33 -05001800 printk(KERN_ERR PREFIX
1801 "Invalid _DOD data in element %d\n", i);
1802 continue;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001803 }
Dmitry Torokhov78eed022007-11-05 11:43:33 -05001804
1805 active_list[count].value.int_val = obj->integer.value;
1806 active_list[count].bind_info = NULL;
Len Brown4be44fc2005-08-05 00:44:28 -04001807 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "dod element[%d] = %d\n", i,
1808 (int)obj->integer.value));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001809 count++;
1810 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001811
Jesper Juhl6044ec82005-11-07 01:01:32 -08001812 kfree(video->attached_array);
Len Brown4be44fc2005-08-05 00:44:28 -04001813
Dmitry Torokhov78eed022007-11-05 11:43:33 -05001814 video->attached_array = active_list;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001815 video->attached_count = count;
Dmitry Torokhov78eed022007-11-05 11:43:33 -05001816
1817 out:
Len Brown02438d82006-06-30 03:19:10 -04001818 kfree(buffer.pointer);
Patrick Mocheld550d982006-06-27 00:41:40 -04001819 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001820}
1821
Len Brown4be44fc2005-08-05 00:44:28 -04001822static int
1823acpi_video_get_next_level(struct acpi_video_device *device,
1824 u32 level_current, u32 event)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001825{
Alexey Starikovskiy63f0edf2007-09-03 16:30:08 +04001826 int min, max, min_above, max_below, i, l, delta = 255;
Thomas Tuttlef4715182006-12-19 12:56:14 -08001827 max = max_below = 0;
1828 min = min_above = 255;
Alexey Starikovskiy63f0edf2007-09-03 16:30:08 +04001829 /* Find closest level to level_current */
Zhao Yakui0a3db1c2009-02-02 11:33:41 +08001830 for (i = 2; i < device->brightness->count; i++) {
Alexey Starikovskiy63f0edf2007-09-03 16:30:08 +04001831 l = device->brightness->levels[i];
1832 if (abs(l - level_current) < abs(delta)) {
1833 delta = l - level_current;
1834 if (!delta)
1835 break;
1836 }
1837 }
1838 /* Ajust level_current to closest available level */
1839 level_current += delta;
Zhao Yakui0a3db1c2009-02-02 11:33:41 +08001840 for (i = 2; i < device->brightness->count; i++) {
Thomas Tuttlef4715182006-12-19 12:56:14 -08001841 l = device->brightness->levels[i];
1842 if (l < min)
1843 min = l;
1844 if (l > max)
1845 max = l;
1846 if (l < min_above && l > level_current)
1847 min_above = l;
1848 if (l > max_below && l < level_current)
1849 max_below = l;
1850 }
1851
1852 switch (event) {
1853 case ACPI_VIDEO_NOTIFY_CYCLE_BRIGHTNESS:
1854 return (level_current < max) ? min_above : min;
1855 case ACPI_VIDEO_NOTIFY_INC_BRIGHTNESS:
1856 return (level_current < max) ? min_above : max;
1857 case ACPI_VIDEO_NOTIFY_DEC_BRIGHTNESS:
1858 return (level_current > min) ? max_below : min;
1859 case ACPI_VIDEO_NOTIFY_ZERO_BRIGHTNESS:
1860 case ACPI_VIDEO_NOTIFY_DISPLAY_OFF:
1861 return 0;
1862 default:
1863 return level_current;
1864 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001865}
1866
Zhang Ruic8890f92009-03-18 16:27:08 +08001867static int
Len Brown4be44fc2005-08-05 00:44:28 -04001868acpi_video_switch_brightness(struct acpi_video_device *device, int event)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001869{
Matthew Wilcox27663c52008-10-10 02:22:59 -04001870 unsigned long long level_current, level_next;
Zhang Ruic8890f92009-03-18 16:27:08 +08001871 int result = -EINVAL;
1872
Julia Jomantaite469778c2008-06-23 22:50:42 +01001873 if (!device->brightness)
Zhang Ruic8890f92009-03-18 16:27:08 +08001874 goto out;
1875
1876 result = acpi_video_device_lcd_get_level_current(device,
1877 &level_current);
1878 if (result)
1879 goto out;
1880
Linus Torvalds1da177e2005-04-16 15:20:36 -07001881 level_next = acpi_video_get_next_level(device, level_current, event);
Zhang Ruic8890f92009-03-18 16:27:08 +08001882
Zhang Rui24450c72009-03-18 16:27:10 +08001883 result = acpi_video_device_lcd_set_level(device, level_next);
Zhang Ruic8890f92009-03-18 16:27:08 +08001884
1885out:
1886 if (result)
1887 printk(KERN_ERR PREFIX "Failed to switch the brightness\n");
1888
1889 return result;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001890}
1891
1892static int
Len Brown4be44fc2005-08-05 00:44:28 -04001893acpi_video_bus_get_devices(struct acpi_video_bus *video,
1894 struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001895{
Len Brown4be44fc2005-08-05 00:44:28 -04001896 int status = 0;
Dmitry Torokhovff102ea2007-11-05 11:43:31 -05001897 struct acpi_device *dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001898
1899 acpi_video_device_enumerate(video);
1900
Dmitry Torokhovff102ea2007-11-05 11:43:31 -05001901 list_for_each_entry(dev, &device->children, node) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001902
1903 status = acpi_video_bus_get_one_device(dev, video);
1904 if (ACPI_FAILURE(status)) {
Lin Ming55ac9a02008-09-28 14:51:56 +08001905 printk(KERN_WARNING PREFIX
1906 "Cant attach device");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001907 continue;
1908 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001909 }
Patrick Mocheld550d982006-06-27 00:41:40 -04001910 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001911}
1912
Len Brown4be44fc2005-08-05 00:44:28 -04001913static int acpi_video_bus_put_one_device(struct acpi_video_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001914{
Karol Kozimor031ec772005-07-30 04:18:00 -04001915 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001916 struct acpi_video_bus *video;
1917
Linus Torvalds1da177e2005-04-16 15:20:36 -07001918
1919 if (!device || !device->video)
Patrick Mocheld550d982006-06-27 00:41:40 -04001920 return -ENOENT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001921
1922 video = device->video;
1923
Linus Torvalds1da177e2005-04-16 15:20:36 -07001924 acpi_video_device_remove_fs(device->dev);
1925
Patrick Mochel90130262006-05-19 16:54:48 -04001926 status = acpi_remove_notify_handler(device->dev->handle,
Len Brown4be44fc2005-08-05 00:44:28 -04001927 ACPI_DEVICE_NOTIFY,
1928 acpi_video_device_notify);
Richard Purdie599a52d2007-02-10 23:07:48 +00001929 backlight_device_unregister(device->backlight);
Zhang Rui702ed512008-01-17 15:51:22 +08001930 if (device->cdev) {
1931 sysfs_remove_link(&device->dev->dev.kobj,
1932 "thermal_cooling");
1933 sysfs_remove_link(&device->cdev->device.kobj,
1934 "device");
1935 thermal_cooling_device_unregister(device->cdev);
1936 device->cdev = NULL;
1937 }
Luming Yu23b0f012007-05-09 21:07:05 +08001938 video_output_unregister(device->output_dev);
Dmitry Torokhovff102ea2007-11-05 11:43:31 -05001939
Patrick Mocheld550d982006-06-27 00:41:40 -04001940 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001941}
1942
Len Brown4be44fc2005-08-05 00:44:28 -04001943static int acpi_video_bus_put_devices(struct acpi_video_bus *video)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001944{
Len Brown4be44fc2005-08-05 00:44:28 -04001945 int status;
Dmitry Torokhovff102ea2007-11-05 11:43:31 -05001946 struct acpi_video_device *dev, *next;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001947
Dmitry Torokhovbbac81f2007-11-05 11:43:32 -05001948 mutex_lock(&video->device_list_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001949
Dmitry Torokhovff102ea2007-11-05 11:43:31 -05001950 list_for_each_entry_safe(dev, next, &video->video_device_list, entry) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001951
Dmitry Torokhovff102ea2007-11-05 11:43:31 -05001952 status = acpi_video_bus_put_one_device(dev);
Len Brown4be44fc2005-08-05 00:44:28 -04001953 if (ACPI_FAILURE(status))
1954 printk(KERN_WARNING PREFIX
1955 "hhuuhhuu bug in acpi video driver.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001956
Dmitry Torokhovff102ea2007-11-05 11:43:31 -05001957 if (dev->brightness) {
1958 kfree(dev->brightness->levels);
1959 kfree(dev->brightness);
1960 }
1961 list_del(&dev->entry);
1962 kfree(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001963 }
1964
Dmitry Torokhovbbac81f2007-11-05 11:43:32 -05001965 mutex_unlock(&video->device_list_lock);
Dmitry Torokhovff102ea2007-11-05 11:43:31 -05001966
Patrick Mocheld550d982006-06-27 00:41:40 -04001967 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001968}
1969
1970/* acpi_video interface */
1971
Len Brown4be44fc2005-08-05 00:44:28 -04001972static int acpi_video_bus_start_devices(struct acpi_video_bus *video)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001973{
Zhang Ruia21101c2007-09-14 11:46:22 +08001974 return acpi_video_bus_DOS(video, 0, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001975}
1976
Len Brown4be44fc2005-08-05 00:44:28 -04001977static int acpi_video_bus_stop_devices(struct acpi_video_bus *video)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001978{
1979 return acpi_video_bus_DOS(video, 0, 1);
1980}
1981
Len Brown4be44fc2005-08-05 00:44:28 -04001982static void acpi_video_bus_notify(acpi_handle handle, u32 event, void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001983{
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001984 struct acpi_video_bus *video = data;
Len Brown4be44fc2005-08-05 00:44:28 -04001985 struct acpi_device *device = NULL;
Luming Yue9dab192007-08-20 18:23:53 +08001986 struct input_dev *input;
1987 int keycode;
1988
Linus Torvalds1da177e2005-04-16 15:20:36 -07001989 if (!video)
Patrick Mocheld550d982006-06-27 00:41:40 -04001990 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001991
Patrick Mochele6afa0d2006-05-19 16:54:40 -04001992 device = video->device;
Luming Yue9dab192007-08-20 18:23:53 +08001993 input = video->input;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001994
1995 switch (event) {
Julius Volz98fb8fe2007-02-20 16:38:40 +01001996 case ACPI_VIDEO_NOTIFY_SWITCH: /* User requested a switch,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001997 * most likely via hotkey. */
Len Brown14e04fb2007-08-23 15:20:26 -04001998 acpi_bus_generate_proc_event(device, event, 0);
Luming Yue9dab192007-08-20 18:23:53 +08001999 keycode = KEY_SWITCHVIDEOMODE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002000 break;
2001
Julius Volz98fb8fe2007-02-20 16:38:40 +01002002 case ACPI_VIDEO_NOTIFY_PROBE: /* User plugged in or removed a video
Linus Torvalds1da177e2005-04-16 15:20:36 -07002003 * connector. */
2004 acpi_video_device_enumerate(video);
2005 acpi_video_device_rebind(video);
Len Brown14e04fb2007-08-23 15:20:26 -04002006 acpi_bus_generate_proc_event(device, event, 0);
Luming Yue9dab192007-08-20 18:23:53 +08002007 keycode = KEY_SWITCHVIDEOMODE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002008 break;
2009
Len Brown4be44fc2005-08-05 00:44:28 -04002010 case ACPI_VIDEO_NOTIFY_CYCLE: /* Cycle Display output hotkey pressed. */
Len Brown25c87f72007-08-25 01:44:01 -04002011 acpi_bus_generate_proc_event(device, event, 0);
Luming Yue9dab192007-08-20 18:23:53 +08002012 keycode = KEY_SWITCHVIDEOMODE;
2013 break;
Len Brown4be44fc2005-08-05 00:44:28 -04002014 case ACPI_VIDEO_NOTIFY_NEXT_OUTPUT: /* Next Display output hotkey pressed. */
Len Brown25c87f72007-08-25 01:44:01 -04002015 acpi_bus_generate_proc_event(device, event, 0);
Luming Yue9dab192007-08-20 18:23:53 +08002016 keycode = KEY_VIDEO_NEXT;
2017 break;
Len Brown4be44fc2005-08-05 00:44:28 -04002018 case ACPI_VIDEO_NOTIFY_PREV_OUTPUT: /* previous Display output hotkey pressed. */
Len Brown14e04fb2007-08-23 15:20:26 -04002019 acpi_bus_generate_proc_event(device, event, 0);
Luming Yue9dab192007-08-20 18:23:53 +08002020 keycode = KEY_VIDEO_PREV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002021 break;
2022
2023 default:
Luming Yue9dab192007-08-20 18:23:53 +08002024 keycode = KEY_UNKNOWN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002025 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
Len Brown4be44fc2005-08-05 00:44:28 -04002026 "Unsupported event [0x%x]\n", event));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002027 break;
2028 }
2029
Zhang Rui7761f632008-01-25 14:48:12 +08002030 acpi_notifier_call_chain(device, event, 0);
Luming Yue9dab192007-08-20 18:23:53 +08002031 input_report_key(input, keycode, 1);
2032 input_sync(input);
2033 input_report_key(input, keycode, 0);
2034 input_sync(input);
2035
Patrick Mocheld550d982006-06-27 00:41:40 -04002036 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002037}
2038
Len Brown4be44fc2005-08-05 00:44:28 -04002039static void acpi_video_device_notify(acpi_handle handle, u32 event, void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002040{
Jan Engelhardt50dd0962006-10-01 00:28:50 +02002041 struct acpi_video_device *video_device = data;
Len Brown4be44fc2005-08-05 00:44:28 -04002042 struct acpi_device *device = NULL;
Luming Yue9dab192007-08-20 18:23:53 +08002043 struct acpi_video_bus *bus;
2044 struct input_dev *input;
2045 int keycode;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002046
Linus Torvalds1da177e2005-04-16 15:20:36 -07002047 if (!video_device)
Patrick Mocheld550d982006-06-27 00:41:40 -04002048 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002049
Patrick Mochele6afa0d2006-05-19 16:54:40 -04002050 device = video_device->dev;
Luming Yue9dab192007-08-20 18:23:53 +08002051 bus = video_device->video;
2052 input = bus->input;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002053
2054 switch (event) {
Len Brown4be44fc2005-08-05 00:44:28 -04002055 case ACPI_VIDEO_NOTIFY_CYCLE_BRIGHTNESS: /* Cycle brightness */
Zhang Rui8a681a42008-01-25 14:47:49 +08002056 if (brightness_switch_enabled)
2057 acpi_video_switch_brightness(video_device, event);
Len Brown25c87f72007-08-25 01:44:01 -04002058 acpi_bus_generate_proc_event(device, event, 0);
Luming Yue9dab192007-08-20 18:23:53 +08002059 keycode = KEY_BRIGHTNESS_CYCLE;
2060 break;
Len Brown4be44fc2005-08-05 00:44:28 -04002061 case ACPI_VIDEO_NOTIFY_INC_BRIGHTNESS: /* Increase brightness */
Zhang Rui8a681a42008-01-25 14:47:49 +08002062 if (brightness_switch_enabled)
2063 acpi_video_switch_brightness(video_device, event);
Len Brown25c87f72007-08-25 01:44:01 -04002064 acpi_bus_generate_proc_event(device, event, 0);
Luming Yue9dab192007-08-20 18:23:53 +08002065 keycode = KEY_BRIGHTNESSUP;
2066 break;
Len Brown4be44fc2005-08-05 00:44:28 -04002067 case ACPI_VIDEO_NOTIFY_DEC_BRIGHTNESS: /* Decrease brightness */
Zhang Rui8a681a42008-01-25 14:47:49 +08002068 if (brightness_switch_enabled)
2069 acpi_video_switch_brightness(video_device, event);
Len Brown25c87f72007-08-25 01:44:01 -04002070 acpi_bus_generate_proc_event(device, event, 0);
Luming Yue9dab192007-08-20 18:23:53 +08002071 keycode = KEY_BRIGHTNESSDOWN;
2072 break;
Len Brown4be44fc2005-08-05 00:44:28 -04002073 case ACPI_VIDEO_NOTIFY_ZERO_BRIGHTNESS: /* zero brightnesss */
Zhang Rui8a681a42008-01-25 14:47:49 +08002074 if (brightness_switch_enabled)
2075 acpi_video_switch_brightness(video_device, event);
Len Brown25c87f72007-08-25 01:44:01 -04002076 acpi_bus_generate_proc_event(device, event, 0);
Luming Yue9dab192007-08-20 18:23:53 +08002077 keycode = KEY_BRIGHTNESS_ZERO;
2078 break;
Len Brown4be44fc2005-08-05 00:44:28 -04002079 case ACPI_VIDEO_NOTIFY_DISPLAY_OFF: /* display device off */
Zhang Rui8a681a42008-01-25 14:47:49 +08002080 if (brightness_switch_enabled)
2081 acpi_video_switch_brightness(video_device, event);
Len Brown14e04fb2007-08-23 15:20:26 -04002082 acpi_bus_generate_proc_event(device, event, 0);
Luming Yue9dab192007-08-20 18:23:53 +08002083 keycode = KEY_DISPLAY_OFF;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002084 break;
2085 default:
Luming Yue9dab192007-08-20 18:23:53 +08002086 keycode = KEY_UNKNOWN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002087 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
Len Brown4be44fc2005-08-05 00:44:28 -04002088 "Unsupported event [0x%x]\n", event));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002089 break;
2090 }
Luming Yue9dab192007-08-20 18:23:53 +08002091
Zhang Rui7761f632008-01-25 14:48:12 +08002092 acpi_notifier_call_chain(device, event, 0);
Luming Yue9dab192007-08-20 18:23:53 +08002093 input_report_key(input, keycode, 1);
2094 input_sync(input);
2095 input_report_key(input, keycode, 0);
2096 input_sync(input);
2097
Patrick Mocheld550d982006-06-27 00:41:40 -04002098 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002099}
2100
Zhang Ruie6d9da12007-08-25 02:23:31 -04002101static int instance;
Matthew Garrett863c1492008-02-04 23:31:24 -08002102static int acpi_video_resume(struct acpi_device *device)
2103{
2104 struct acpi_video_bus *video;
2105 struct acpi_video_device *video_device;
2106 int i;
2107
2108 if (!device || !acpi_driver_data(device))
2109 return -EINVAL;
2110
2111 video = acpi_driver_data(device);
2112
2113 for (i = 0; i < video->attached_count; i++) {
2114 video_device = video->attached_array[i].bind_info;
2115 if (video_device && video_device->backlight)
2116 acpi_video_set_brightness(video_device->backlight);
2117 }
2118 return AE_OK;
2119}
2120
Len Brown4be44fc2005-08-05 00:44:28 -04002121static int acpi_video_bus_add(struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002122{
Dmitry Torokhovf51e8392007-11-05 11:43:30 -05002123 acpi_status status;
2124 struct acpi_video_bus *video;
Luming Yue9dab192007-08-20 18:23:53 +08002125 struct input_dev *input;
Dmitry Torokhovf51e8392007-11-05 11:43:30 -05002126 int error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002127
Burman Yan36bcbec2006-12-19 12:56:11 -08002128 video = kzalloc(sizeof(struct acpi_video_bus), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002129 if (!video)
Patrick Mocheld550d982006-06-27 00:41:40 -04002130 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002131
Zhang Ruie6d9da12007-08-25 02:23:31 -04002132 /* a hack to fix the duplicate name "VID" problem on T61 */
2133 if (!strcmp(device->pnp.bus_id, "VID")) {
2134 if (instance)
2135 device->pnp.bus_id[3] = '0' + instance;
2136 instance ++;
2137 }
Zhao Yakuif3b39f12009-02-02 22:55:01 -05002138 /* a hack to fix the duplicate name "VGA" problem on Pa 3553 */
2139 if (!strcmp(device->pnp.bus_id, "VGA")) {
2140 if (instance)
2141 device->pnp.bus_id[3] = '0' + instance;
2142 instance++;
2143 }
Zhang Ruie6d9da12007-08-25 02:23:31 -04002144
Patrick Mochele6afa0d2006-05-19 16:54:40 -04002145 video->device = device;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002146 strcpy(acpi_device_name(device), ACPI_VIDEO_BUS_NAME);
2147 strcpy(acpi_device_class(device), ACPI_VIDEO_CLASS);
Pavel Machekdb89b4f2008-09-22 14:37:34 -07002148 device->driver_data = video;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002149
2150 acpi_video_bus_find_cap(video);
Dmitry Torokhovf51e8392007-11-05 11:43:30 -05002151 error = acpi_video_bus_check(video);
2152 if (error)
2153 goto err_free_video;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002154
Dmitry Torokhovf51e8392007-11-05 11:43:30 -05002155 error = acpi_video_bus_add_fs(device);
2156 if (error)
2157 goto err_free_video;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002158
Dmitry Torokhovbbac81f2007-11-05 11:43:32 -05002159 mutex_init(&video->device_list_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002160 INIT_LIST_HEAD(&video->video_device_list);
2161
2162 acpi_video_bus_get_devices(video, device);
2163 acpi_video_bus_start_devices(video);
2164
Patrick Mochel90130262006-05-19 16:54:48 -04002165 status = acpi_install_notify_handler(device->handle,
Len Brown4be44fc2005-08-05 00:44:28 -04002166 ACPI_DEVICE_NOTIFY,
2167 acpi_video_bus_notify, video);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002168 if (ACPI_FAILURE(status)) {
Lin Ming55ac9a02008-09-28 14:51:56 +08002169 printk(KERN_ERR PREFIX
2170 "Error installing notify handler\n");
Dmitry Torokhovf51e8392007-11-05 11:43:30 -05002171 error = -ENODEV;
2172 goto err_stop_video;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002173 }
2174
Luming Yue9dab192007-08-20 18:23:53 +08002175 video->input = input = input_allocate_device();
Dmitry Torokhovf51e8392007-11-05 11:43:30 -05002176 if (!input) {
2177 error = -ENOMEM;
2178 goto err_uninstall_notify;
2179 }
Luming Yue9dab192007-08-20 18:23:53 +08002180
2181 snprintf(video->phys, sizeof(video->phys),
2182 "%s/video/input0", acpi_device_hid(video->device));
2183
2184 input->name = acpi_device_name(video->device);
2185 input->phys = video->phys;
2186 input->id.bustype = BUS_HOST;
2187 input->id.product = 0x06;
Dmitry Torokhov91c05c62007-11-05 11:43:29 -05002188 input->dev.parent = &device->dev;
Luming Yue9dab192007-08-20 18:23:53 +08002189 input->evbit[0] = BIT(EV_KEY);
2190 set_bit(KEY_SWITCHVIDEOMODE, input->keybit);
2191 set_bit(KEY_VIDEO_NEXT, input->keybit);
2192 set_bit(KEY_VIDEO_PREV, input->keybit);
2193 set_bit(KEY_BRIGHTNESS_CYCLE, input->keybit);
2194 set_bit(KEY_BRIGHTNESSUP, input->keybit);
2195 set_bit(KEY_BRIGHTNESSDOWN, input->keybit);
2196 set_bit(KEY_BRIGHTNESS_ZERO, input->keybit);
2197 set_bit(KEY_DISPLAY_OFF, input->keybit);
2198 set_bit(KEY_UNKNOWN, input->keybit);
Luming Yue9dab192007-08-20 18:23:53 +08002199
Dmitry Torokhovf51e8392007-11-05 11:43:30 -05002200 error = input_register_device(input);
2201 if (error)
2202 goto err_free_input_dev;
Luming Yue9dab192007-08-20 18:23:53 +08002203
Linus Torvalds1da177e2005-04-16 15:20:36 -07002204 printk(KERN_INFO PREFIX "%s [%s] (multi-head: %s rom: %s post: %s)\n",
Len Brown4be44fc2005-08-05 00:44:28 -04002205 ACPI_VIDEO_DEVICE_NAME, acpi_device_bid(device),
2206 video->flags.multihead ? "yes" : "no",
2207 video->flags.rom ? "yes" : "no",
2208 video->flags.post ? "yes" : "no");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002209
Dmitry Torokhovf51e8392007-11-05 11:43:30 -05002210 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002211
Dmitry Torokhovf51e8392007-11-05 11:43:30 -05002212 err_free_input_dev:
2213 input_free_device(input);
2214 err_uninstall_notify:
2215 acpi_remove_notify_handler(device->handle, ACPI_DEVICE_NOTIFY,
2216 acpi_video_bus_notify);
2217 err_stop_video:
2218 acpi_video_bus_stop_devices(video);
2219 acpi_video_bus_put_devices(video);
2220 kfree(video->attached_array);
2221 acpi_video_bus_remove_fs(device);
2222 err_free_video:
2223 kfree(video);
Pavel Machekdb89b4f2008-09-22 14:37:34 -07002224 device->driver_data = NULL;
Dmitry Torokhovf51e8392007-11-05 11:43:30 -05002225
2226 return error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002227}
2228
Len Brown4be44fc2005-08-05 00:44:28 -04002229static int acpi_video_bus_remove(struct acpi_device *device, int type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002230{
Len Brown4be44fc2005-08-05 00:44:28 -04002231 acpi_status status = 0;
2232 struct acpi_video_bus *video = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002233
Linus Torvalds1da177e2005-04-16 15:20:36 -07002234
2235 if (!device || !acpi_driver_data(device))
Patrick Mocheld550d982006-06-27 00:41:40 -04002236 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002237
Jan Engelhardt50dd0962006-10-01 00:28:50 +02002238 video = acpi_driver_data(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002239
2240 acpi_video_bus_stop_devices(video);
2241
Patrick Mochel90130262006-05-19 16:54:48 -04002242 status = acpi_remove_notify_handler(video->device->handle,
Len Brown4be44fc2005-08-05 00:44:28 -04002243 ACPI_DEVICE_NOTIFY,
2244 acpi_video_bus_notify);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002245
2246 acpi_video_bus_put_devices(video);
2247 acpi_video_bus_remove_fs(device);
2248
Luming Yue9dab192007-08-20 18:23:53 +08002249 input_unregister_device(video->input);
Jesper Juhl6044ec82005-11-07 01:01:32 -08002250 kfree(video->attached_array);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002251 kfree(video);
2252
Patrick Mocheld550d982006-06-27 00:41:40 -04002253 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002254}
2255
Matthew Garrett74a365b2009-03-19 21:35:39 +00002256static int __init intel_opregion_present(void)
2257{
2258#if defined(CONFIG_DRM_I915) || defined(CONFIG_DRM_I915_MODULE)
2259 struct pci_dev *dev = NULL;
2260 u32 address;
2261
2262 for_each_pci_dev(dev) {
2263 if ((dev->class >> 8) != PCI_CLASS_DISPLAY_VGA)
2264 continue;
2265 if (dev->vendor != PCI_VENDOR_ID_INTEL)
2266 continue;
2267 pci_read_config_dword(dev, 0xfc, &address);
2268 if (!address)
2269 continue;
2270 return 1;
2271 }
2272#endif
2273 return 0;
2274}
2275
2276int acpi_video_register(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002277{
Len Brown4be44fc2005-08-05 00:44:28 -04002278 int result = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002279
Linus Torvalds1da177e2005-04-16 15:20:36 -07002280 acpi_video_dir = proc_mkdir(ACPI_VIDEO_CLASS, acpi_root_dir);
2281 if (!acpi_video_dir)
Patrick Mocheld550d982006-06-27 00:41:40 -04002282 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002283 acpi_video_dir->owner = THIS_MODULE;
2284
2285 result = acpi_bus_register_driver(&acpi_video_bus);
2286 if (result < 0) {
2287 remove_proc_entry(ACPI_VIDEO_CLASS, acpi_root_dir);
Patrick Mocheld550d982006-06-27 00:41:40 -04002288 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002289 }
2290
Patrick Mocheld550d982006-06-27 00:41:40 -04002291 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002292}
Matthew Garrett74a365b2009-03-19 21:35:39 +00002293EXPORT_SYMBOL(acpi_video_register);
2294
2295/*
2296 * This is kind of nasty. Hardware using Intel chipsets may require
2297 * the video opregion code to be run first in order to initialise
2298 * state before any ACPI video calls are made. To handle this we defer
2299 * registration of the video class until the opregion code has run.
2300 */
2301
2302static int __init acpi_video_init(void)
2303{
2304 if (intel_opregion_present())
2305 return 0;
2306
2307 return acpi_video_register();
2308}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002309
Len Brown4be44fc2005-08-05 00:44:28 -04002310static void __exit acpi_video_exit(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002311{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002312
2313 acpi_bus_unregister_driver(&acpi_video_bus);
2314
2315 remove_proc_entry(ACPI_VIDEO_CLASS, acpi_root_dir);
2316
Patrick Mocheld550d982006-06-27 00:41:40 -04002317 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002318}
2319
2320module_init(acpi_video_init);
2321module_exit(acpi_video_exit);