blob: 346277f93cdac15a596cf03fe204bf350b57fb4a [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);
Bjorn Helgaas70155582009-04-07 15:37:11 +000082static void acpi_video_bus_notify(struct acpi_device *device, u32 event);
Linus Torvalds1da177e2005-04-16 15:20:36 -070083
Thomas Renninger1ba90e32007-07-23 14:44:41 +020084static const struct acpi_device_id video_device_ids[] = {
85 {ACPI_VIDEO_HID, 0},
86 {"", 0},
87};
88MODULE_DEVICE_TABLE(acpi, video_device_ids);
89
Linus Torvalds1da177e2005-04-16 15:20:36 -070090static struct acpi_driver acpi_video_bus = {
Len Brownc2b6705b2007-02-12 23:33:40 -050091 .name = "video",
Linus Torvalds1da177e2005-04-16 15:20:36 -070092 .class = ACPI_VIDEO_CLASS,
Thomas Renninger1ba90e32007-07-23 14:44:41 +020093 .ids = video_device_ids,
Linus Torvalds1da177e2005-04-16 15:20:36 -070094 .ops = {
95 .add = acpi_video_bus_add,
96 .remove = acpi_video_bus_remove,
Matthew Garrett863c1492008-02-04 23:31:24 -080097 .resume = acpi_video_resume,
Bjorn Helgaas70155582009-04-07 15:37:11 +000098 .notify = acpi_video_bus_notify,
Len Brown4be44fc2005-08-05 00:44:28 -040099 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100};
101
102struct acpi_video_bus_flags {
Len Brown4be44fc2005-08-05 00:44:28 -0400103 u8 multihead:1; /* can switch video heads */
104 u8 rom:1; /* can retrieve a video rom */
105 u8 post:1; /* can configure the head to */
106 u8 reserved:5;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107};
108
109struct acpi_video_bus_cap {
Len Brown4be44fc2005-08-05 00:44:28 -0400110 u8 _DOS:1; /*Enable/Disable output switching */
111 u8 _DOD:1; /*Enumerate all devices attached to display adapter */
112 u8 _ROM:1; /*Get ROM Data */
113 u8 _GPD:1; /*Get POST Device */
114 u8 _SPD:1; /*Set POST Device */
115 u8 _VPO:1; /*Video POST Options */
116 u8 reserved:2;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117};
118
Len Brown4be44fc2005-08-05 00:44:28 -0400119struct acpi_video_device_attrib {
120 u32 display_index:4; /* A zero-based instance of the Display */
Julius Volz98fb8fe2007-02-20 16:38:40 +0100121 u32 display_port_attachment:4; /*This field differentiates the display type */
Len Brown4be44fc2005-08-05 00:44:28 -0400122 u32 display_type:4; /*Describe the specific type in use */
Julius Volz98fb8fe2007-02-20 16:38:40 +0100123 u32 vendor_specific:4; /*Chipset Vendor Specific */
Len Brown4be44fc2005-08-05 00:44:28 -0400124 u32 bios_can_detect:1; /*BIOS can detect the device */
125 u32 depend_on_vga:1; /*Non-VGA output device whose power is related to
126 the VGA device. */
127 u32 pipe_id:3; /*For VGA multiple-head devices. */
128 u32 reserved:10; /*Must be 0 */
129 u32 device_id_scheme:1; /*Device ID Scheme */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130};
131
132struct acpi_video_enumerated_device {
133 union {
134 u32 int_val;
Len Brown4be44fc2005-08-05 00:44:28 -0400135 struct acpi_video_device_attrib attrib;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136 } value;
137 struct acpi_video_device *bind_info;
138};
139
140struct acpi_video_bus {
Patrick Mochele6afa0d2006-05-19 16:54:40 -0400141 struct acpi_device *device;
Len Brown4be44fc2005-08-05 00:44:28 -0400142 u8 dos_setting;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143 struct acpi_video_enumerated_device *attached_array;
Len Brown4be44fc2005-08-05 00:44:28 -0400144 u8 attached_count;
145 struct acpi_video_bus_cap cap;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146 struct acpi_video_bus_flags flags;
Len Brown4be44fc2005-08-05 00:44:28 -0400147 struct list_head video_device_list;
Dmitry Torokhovbbac81f2007-11-05 11:43:32 -0500148 struct mutex device_list_lock; /* protects video_device_list */
Len Brown4be44fc2005-08-05 00:44:28 -0400149 struct proc_dir_entry *dir;
Luming Yue9dab192007-08-20 18:23:53 +0800150 struct input_dev *input;
151 char phys[32]; /* for input device */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152};
153
154struct acpi_video_device_flags {
Len Brown4be44fc2005-08-05 00:44:28 -0400155 u8 crt:1;
156 u8 lcd:1;
157 u8 tvout:1;
Rui Zhang82cae992007-01-03 23:40:53 -0500158 u8 dvi:1;
Len Brown4be44fc2005-08-05 00:44:28 -0400159 u8 bios:1;
160 u8 unknown:1;
Rui Zhang82cae992007-01-03 23:40:53 -0500161 u8 reserved:2;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700162};
163
164struct acpi_video_device_cap {
Len Brown4be44fc2005-08-05 00:44:28 -0400165 u8 _ADR:1; /*Return the unique ID */
166 u8 _BCL:1; /*Query list of brightness control levels supported */
167 u8 _BCM:1; /*Set the brightness level */
Yu Luming2f3d0002006-11-11 02:40:34 +0800168 u8 _BQC:1; /* Get current brightness level */
Zhang Ruic60d6382009-03-18 16:27:18 +0800169 u8 _BCQ:1; /* Some buggy BIOS uses _BCQ instead of _BQC */
Len Brown4be44fc2005-08-05 00:44:28 -0400170 u8 _DDC:1; /*Return the EDID for this device */
171 u8 _DCS:1; /*Return status of output device */
172 u8 _DGS:1; /*Query graphics state */
173 u8 _DSS:1; /*Device state set */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700174};
175
Zhang Ruid32f6942009-03-18 16:27:12 +0800176struct acpi_video_brightness_flags {
177 u8 _BCL_no_ac_battery_levels:1; /* no AC/Battery levels in _BCL */
Zhang Ruid80fb992009-03-18 16:27:14 +0800178 u8 _BCL_reversed:1; /* _BCL package is in a reversed order*/
Zhang Rui1a7c6182009-03-18 16:27:16 +0800179 u8 _BCL_use_index:1; /* levels in _BCL are index values */
180 u8 _BCM_use_index:1; /* input of _BCM is an index value */
181 u8 _BQC_use_index:1; /* _BQC returns an index value */
Zhang Ruid32f6942009-03-18 16:27:12 +0800182};
183
Linus Torvalds1da177e2005-04-16 15:20:36 -0700184struct acpi_video_device_brightness {
Len Brown4be44fc2005-08-05 00:44:28 -0400185 int curr;
186 int count;
187 int *levels;
Zhang Ruid32f6942009-03-18 16:27:12 +0800188 struct acpi_video_brightness_flags flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700189};
190
191struct acpi_video_device {
Len Brown4be44fc2005-08-05 00:44:28 -0400192 unsigned long device_id;
193 struct acpi_video_device_flags flags;
194 struct acpi_video_device_cap cap;
195 struct list_head entry;
196 struct acpi_video_bus *video;
197 struct acpi_device *dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700198 struct acpi_video_device_brightness *brightness;
Yu Luming2f3d0002006-11-11 02:40:34 +0800199 struct backlight_device *backlight;
Zhang Rui702ed512008-01-17 15:51:22 +0800200 struct thermal_cooling_device *cdev;
Luming Yu23b0f012007-05-09 21:07:05 +0800201 struct output_device *output_dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700202};
203
Linus Torvalds1da177e2005-04-16 15:20:36 -0700204/* bus */
205static int acpi_video_bus_info_open_fs(struct inode *inode, struct file *file);
Jan Engelhardt070d8eb2009-01-12 00:07:55 +0100206static const struct file_operations acpi_video_bus_info_fops = {
Denis V. Lunevcf7acfa2008-04-29 01:02:27 -0700207 .owner = THIS_MODULE,
Len Brown4be44fc2005-08-05 00:44:28 -0400208 .open = acpi_video_bus_info_open_fs,
209 .read = seq_read,
210 .llseek = seq_lseek,
211 .release = single_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700212};
213
214static int acpi_video_bus_ROM_open_fs(struct inode *inode, struct file *file);
Jan Engelhardt070d8eb2009-01-12 00:07:55 +0100215static const struct file_operations acpi_video_bus_ROM_fops = {
Denis V. Lunevcf7acfa2008-04-29 01:02:27 -0700216 .owner = THIS_MODULE,
Len Brown4be44fc2005-08-05 00:44:28 -0400217 .open = acpi_video_bus_ROM_open_fs,
218 .read = seq_read,
219 .llseek = seq_lseek,
220 .release = single_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700221};
222
Len Brown4be44fc2005-08-05 00:44:28 -0400223static int acpi_video_bus_POST_info_open_fs(struct inode *inode,
224 struct file *file);
Jan Engelhardt070d8eb2009-01-12 00:07:55 +0100225static const struct file_operations acpi_video_bus_POST_info_fops = {
Denis V. Lunevcf7acfa2008-04-29 01:02:27 -0700226 .owner = THIS_MODULE,
Len Brown4be44fc2005-08-05 00:44:28 -0400227 .open = acpi_video_bus_POST_info_open_fs,
228 .read = seq_read,
229 .llseek = seq_lseek,
230 .release = single_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700231};
232
233static int acpi_video_bus_POST_open_fs(struct inode *inode, struct file *file);
Len Brownc07c9a72009-04-04 03:33:45 -0400234static ssize_t acpi_video_bus_write_POST(struct file *file,
Jan Engelhardtb7171ae2009-01-12 00:08:19 +0100235 const char __user *buffer, size_t count, loff_t *data);
236static const struct file_operations acpi_video_bus_POST_fops = {
Denis V. Lunevcf7acfa2008-04-29 01:02:27 -0700237 .owner = THIS_MODULE,
Len Brown4be44fc2005-08-05 00:44:28 -0400238 .open = acpi_video_bus_POST_open_fs,
239 .read = seq_read,
Jan Engelhardtb7171ae2009-01-12 00:08:19 +0100240 .write = acpi_video_bus_write_POST,
Len Brown4be44fc2005-08-05 00:44:28 -0400241 .llseek = seq_lseek,
242 .release = single_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700243};
244
Linus Torvalds1da177e2005-04-16 15:20:36 -0700245static int acpi_video_bus_DOS_open_fs(struct inode *inode, struct file *file);
Len Brownc07c9a72009-04-04 03:33:45 -0400246static ssize_t acpi_video_bus_write_DOS(struct file *file,
Jan Engelhardtb7171ae2009-01-12 00:08:19 +0100247 const char __user *buffer, size_t count, loff_t *data);
248static const struct file_operations acpi_video_bus_DOS_fops = {
Denis V. Lunevcf7acfa2008-04-29 01:02:27 -0700249 .owner = THIS_MODULE,
Len Brown4be44fc2005-08-05 00:44:28 -0400250 .open = acpi_video_bus_DOS_open_fs,
251 .read = seq_read,
Jan Engelhardtb7171ae2009-01-12 00:08:19 +0100252 .write = acpi_video_bus_write_DOS,
Len Brown4be44fc2005-08-05 00:44:28 -0400253 .llseek = seq_lseek,
254 .release = single_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700255};
256
257/* device */
Len Brown4be44fc2005-08-05 00:44:28 -0400258static int acpi_video_device_info_open_fs(struct inode *inode,
259 struct file *file);
Jan Engelhardt070d8eb2009-01-12 00:07:55 +0100260static const struct file_operations acpi_video_device_info_fops = {
Denis V. Lunevcf7acfa2008-04-29 01:02:27 -0700261 .owner = THIS_MODULE,
Len Brown4be44fc2005-08-05 00:44:28 -0400262 .open = acpi_video_device_info_open_fs,
263 .read = seq_read,
264 .llseek = seq_lseek,
265 .release = single_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700266};
267
Len Brown4be44fc2005-08-05 00:44:28 -0400268static int acpi_video_device_state_open_fs(struct inode *inode,
269 struct file *file);
Len Brownc07c9a72009-04-04 03:33:45 -0400270static ssize_t acpi_video_device_write_state(struct file *file,
Jan Engelhardtb7171ae2009-01-12 00:08:19 +0100271 const char __user *buffer, size_t count, loff_t *data);
272static const struct file_operations acpi_video_device_state_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_state_open_fs,
275 .read = seq_read,
Jan Engelhardtb7171ae2009-01-12 00:08:19 +0100276 .write = acpi_video_device_write_state,
Len Brown4be44fc2005-08-05 00:44:28 -0400277 .llseek = seq_lseek,
278 .release = single_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700279};
280
Len Brown4be44fc2005-08-05 00:44:28 -0400281static int acpi_video_device_brightness_open_fs(struct inode *inode,
282 struct file *file);
Len Brownc07c9a72009-04-04 03:33:45 -0400283static ssize_t acpi_video_device_write_brightness(struct file *file,
Jan Engelhardtb7171ae2009-01-12 00:08:19 +0100284 const char __user *buffer, size_t count, loff_t *data);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700285static struct file_operations acpi_video_device_brightness_fops = {
Denis V. Lunevcf7acfa2008-04-29 01:02:27 -0700286 .owner = THIS_MODULE,
Len Brown4be44fc2005-08-05 00:44:28 -0400287 .open = acpi_video_device_brightness_open_fs,
288 .read = seq_read,
Jan Engelhardtb7171ae2009-01-12 00:08:19 +0100289 .write = acpi_video_device_write_brightness,
Len Brown4be44fc2005-08-05 00:44:28 -0400290 .llseek = seq_lseek,
291 .release = single_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700292};
293
Len Brown4be44fc2005-08-05 00:44:28 -0400294static int acpi_video_device_EDID_open_fs(struct inode *inode,
295 struct file *file);
Jan Engelhardt070d8eb2009-01-12 00:07:55 +0100296static const struct file_operations acpi_video_device_EDID_fops = {
Denis V. Lunevcf7acfa2008-04-29 01:02:27 -0700297 .owner = THIS_MODULE,
Len Brown4be44fc2005-08-05 00:44:28 -0400298 .open = acpi_video_device_EDID_open_fs,
299 .read = seq_read,
300 .llseek = seq_lseek,
301 .release = single_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700302};
303
Jan Engelhardtb7171ae2009-01-12 00:08:19 +0100304static const char device_decode[][30] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700305 "motherboard VGA device",
306 "PCI VGA device",
307 "AGP VGA device",
308 "UNKNOWN",
309};
310
Len Brown4be44fc2005-08-05 00:44:28 -0400311static void acpi_video_device_notify(acpi_handle handle, u32 event, void *data);
312static void acpi_video_device_rebind(struct acpi_video_bus *video);
313static void acpi_video_device_bind(struct acpi_video_bus *video,
314 struct acpi_video_device *device);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700315static int acpi_video_device_enumerate(struct acpi_video_bus *video);
Yu Luming2f3d0002006-11-11 02:40:34 +0800316static int acpi_video_device_lcd_set_level(struct acpi_video_device *device,
317 int level);
318static int acpi_video_device_lcd_get_level_current(
319 struct acpi_video_device *device,
Matthew Wilcox27663c52008-10-10 02:22:59 -0400320 unsigned long long *level);
Len Brown4be44fc2005-08-05 00:44:28 -0400321static int acpi_video_get_next_level(struct acpi_video_device *device,
322 u32 level_current, u32 event);
Zhang Ruic8890f92009-03-18 16:27:08 +0800323static int acpi_video_switch_brightness(struct acpi_video_device *device,
Len Brown4be44fc2005-08-05 00:44:28 -0400324 int event);
Luming Yu23b0f012007-05-09 21:07:05 +0800325static int acpi_video_device_get_state(struct acpi_video_device *device,
Matthew Wilcox27663c52008-10-10 02:22:59 -0400326 unsigned long long *state);
Luming Yu23b0f012007-05-09 21:07:05 +0800327static int acpi_video_output_get(struct output_device *od);
328static int acpi_video_device_set_state(struct acpi_video_device *device, int state);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700329
Yu Luming2f3d0002006-11-11 02:40:34 +0800330/*backlight device sysfs support*/
331static int acpi_video_get_brightness(struct backlight_device *bd)
332{
Matthew Wilcox27663c52008-10-10 02:22:59 -0400333 unsigned long long cur_level;
Matthew Garrett38531e62007-12-26 02:03:26 +0000334 int i;
Yu Luming2f3d0002006-11-11 02:40:34 +0800335 struct acpi_video_device *vd =
Richard Purdie655bfd72007-07-09 12:17:24 +0100336 (struct acpi_video_device *)bl_get_data(bd);
Zhang Ruic8890f92009-03-18 16:27:08 +0800337
338 if (acpi_video_device_lcd_get_level_current(vd, &cur_level))
339 return -EINVAL;
Matthew Garrett38531e62007-12-26 02:03:26 +0000340 for (i = 2; i < vd->brightness->count; i++) {
341 if (vd->brightness->levels[i] == cur_level)
342 /* The first two entries are special - see page 575
343 of the ACPI spec 3.0 */
344 return i-2;
345 }
346 return 0;
Yu Luming2f3d0002006-11-11 02:40:34 +0800347}
348
349static int acpi_video_set_brightness(struct backlight_device *bd)
350{
Zhang Rui24450c72009-03-18 16:27:10 +0800351 int request_level = bd->props.brightness + 2;
Yu Luming2f3d0002006-11-11 02:40:34 +0800352 struct acpi_video_device *vd =
Richard Purdie655bfd72007-07-09 12:17:24 +0100353 (struct acpi_video_device *)bl_get_data(bd);
Zhang Rui24450c72009-03-18 16:27:10 +0800354
355 return acpi_video_device_lcd_set_level(vd,
356 vd->brightness->levels[request_level]);
Yu Luming2f3d0002006-11-11 02:40:34 +0800357}
358
Richard Purdie599a52d2007-02-10 23:07:48 +0000359static struct backlight_ops acpi_backlight_ops = {
360 .get_brightness = acpi_video_get_brightness,
361 .update_status = acpi_video_set_brightness,
362};
363
Luming Yu23b0f012007-05-09 21:07:05 +0800364/*video output device sysfs support*/
365static int acpi_video_output_get(struct output_device *od)
366{
Matthew Wilcox27663c52008-10-10 02:22:59 -0400367 unsigned long long state;
Luming Yu23b0f012007-05-09 21:07:05 +0800368 struct acpi_video_device *vd =
tonyj@suse.de60043422007-08-07 22:28:47 -0700369 (struct acpi_video_device *)dev_get_drvdata(&od->dev);
Luming Yu23b0f012007-05-09 21:07:05 +0800370 acpi_video_device_get_state(vd, &state);
371 return (int)state;
372}
373
374static int acpi_video_output_set(struct output_device *od)
375{
376 unsigned long state = od->request_state;
377 struct acpi_video_device *vd=
tonyj@suse.de60043422007-08-07 22:28:47 -0700378 (struct acpi_video_device *)dev_get_drvdata(&od->dev);
Luming Yu23b0f012007-05-09 21:07:05 +0800379 return acpi_video_device_set_state(vd, state);
380}
381
382static struct output_properties acpi_output_properties = {
383 .set_state = acpi_video_output_set,
384 .get_status = acpi_video_output_get,
385};
Zhang Rui702ed512008-01-17 15:51:22 +0800386
387
388/* thermal cooling device callbacks */
Matthew Garrett6503e5d2008-11-27 17:48:13 +0000389static int video_get_max_state(struct thermal_cooling_device *cdev, unsigned
390 long *state)
Zhang Rui702ed512008-01-17 15:51:22 +0800391{
392 struct acpi_device *device = cdev->devdata;
393 struct acpi_video_device *video = acpi_driver_data(device);
394
Matthew Garrett6503e5d2008-11-27 17:48:13 +0000395 *state = video->brightness->count - 3;
396 return 0;
Zhang Rui702ed512008-01-17 15:51:22 +0800397}
398
Matthew Garrett6503e5d2008-11-27 17:48:13 +0000399static int video_get_cur_state(struct thermal_cooling_device *cdev, unsigned
400 long *state)
Zhang Rui702ed512008-01-17 15:51:22 +0800401{
402 struct acpi_device *device = cdev->devdata;
403 struct acpi_video_device *video = acpi_driver_data(device);
Matthew Wilcox27663c52008-10-10 02:22:59 -0400404 unsigned long long level;
Matthew Garrett6503e5d2008-11-27 17:48:13 +0000405 int offset;
Zhang Rui702ed512008-01-17 15:51:22 +0800406
Zhang Ruic8890f92009-03-18 16:27:08 +0800407 if (acpi_video_device_lcd_get_level_current(video, &level))
408 return -EINVAL;
Matthew Garrett6503e5d2008-11-27 17:48:13 +0000409 for (offset = 2; offset < video->brightness->count; offset++)
410 if (level == video->brightness->levels[offset]) {
411 *state = video->brightness->count - offset - 1;
412 return 0;
413 }
Zhang Rui702ed512008-01-17 15:51:22 +0800414
415 return -EINVAL;
416}
417
418static int
Matthew Garrett6503e5d2008-11-27 17:48:13 +0000419video_set_cur_state(struct thermal_cooling_device *cdev, unsigned long state)
Zhang Rui702ed512008-01-17 15:51:22 +0800420{
421 struct acpi_device *device = cdev->devdata;
422 struct acpi_video_device *video = acpi_driver_data(device);
423 int level;
424
425 if ( state >= video->brightness->count - 2)
426 return -EINVAL;
427
428 state = video->brightness->count - state;
429 level = video->brightness->levels[state -1];
430 return acpi_video_device_lcd_set_level(video, level);
431}
432
433static struct thermal_cooling_device_ops video_cooling_ops = {
434 .get_max_state = video_get_max_state,
435 .get_cur_state = video_get_cur_state,
436 .set_cur_state = video_set_cur_state,
437};
438
Linus Torvalds1da177e2005-04-16 15:20:36 -0700439/* --------------------------------------------------------------------------
440 Video Management
441 -------------------------------------------------------------------------- */
442
443/* device */
444
445static int
Matthew Wilcox27663c52008-10-10 02:22:59 -0400446acpi_video_device_query(struct acpi_video_device *device, unsigned long long *state)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700447{
Len Brown4be44fc2005-08-05 00:44:28 -0400448 int status;
Patrick Mochel90130262006-05-19 16:54:48 -0400449
450 status = acpi_evaluate_integer(device->dev->handle, "_DGS", NULL, state);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700451
Patrick Mocheld550d982006-06-27 00:41:40 -0400452 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700453}
454
455static int
Len Brown4be44fc2005-08-05 00:44:28 -0400456acpi_video_device_get_state(struct acpi_video_device *device,
Matthew Wilcox27663c52008-10-10 02:22:59 -0400457 unsigned long long *state)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700458{
Len Brown4be44fc2005-08-05 00:44:28 -0400459 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700460
Patrick Mochel90130262006-05-19 16:54:48 -0400461 status = acpi_evaluate_integer(device->dev->handle, "_DCS", NULL, state);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700462
Patrick Mocheld550d982006-06-27 00:41:40 -0400463 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700464}
465
466static int
Len Brown4be44fc2005-08-05 00:44:28 -0400467acpi_video_device_set_state(struct acpi_video_device *device, int state)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700468{
Len Brown4be44fc2005-08-05 00:44:28 -0400469 int status;
470 union acpi_object arg0 = { ACPI_TYPE_INTEGER };
471 struct acpi_object_list args = { 1, &arg0 };
Matthew Wilcox27663c52008-10-10 02:22:59 -0400472 unsigned long long ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700473
Linus Torvalds1da177e2005-04-16 15:20:36 -0700474
475 arg0.integer.value = state;
Patrick Mochel90130262006-05-19 16:54:48 -0400476 status = acpi_evaluate_integer(device->dev->handle, "_DSS", &args, &ret);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700477
Patrick Mocheld550d982006-06-27 00:41:40 -0400478 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700479}
480
481static int
Len Brown4be44fc2005-08-05 00:44:28 -0400482acpi_video_device_lcd_query_levels(struct acpi_video_device *device,
483 union acpi_object **levels)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700484{
Len Brown4be44fc2005-08-05 00:44:28 -0400485 int status;
486 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
487 union acpi_object *obj;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700488
Linus Torvalds1da177e2005-04-16 15:20:36 -0700489
490 *levels = NULL;
491
Patrick Mochel90130262006-05-19 16:54:48 -0400492 status = acpi_evaluate_object(device->dev->handle, "_BCL", NULL, &buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700493 if (!ACPI_SUCCESS(status))
Patrick Mocheld550d982006-06-27 00:41:40 -0400494 return status;
Len Brown4be44fc2005-08-05 00:44:28 -0400495 obj = (union acpi_object *)buffer.pointer;
Adrian Bunk6665bda2006-03-11 10:12:00 -0500496 if (!obj || (obj->type != ACPI_TYPE_PACKAGE)) {
Len Brown64684632006-06-26 23:41:38 -0400497 printk(KERN_ERR PREFIX "Invalid _BCL data\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700498 status = -EFAULT;
499 goto err;
500 }
501
502 *levels = obj;
503
Patrick Mocheld550d982006-06-27 00:41:40 -0400504 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700505
Len Brown4be44fc2005-08-05 00:44:28 -0400506 err:
Jesper Juhl6044ec82005-11-07 01:01:32 -0800507 kfree(buffer.pointer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700508
Patrick Mocheld550d982006-06-27 00:41:40 -0400509 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700510}
511
512static int
Len Brown4be44fc2005-08-05 00:44:28 -0400513acpi_video_device_lcd_set_level(struct acpi_video_device *device, int level)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700514{
Zhang Rui24450c72009-03-18 16:27:10 +0800515 int status;
Len Brown4be44fc2005-08-05 00:44:28 -0400516 union acpi_object arg0 = { ACPI_TYPE_INTEGER };
517 struct acpi_object_list args = { 1, &arg0 };
Zhang Rui9e6dada2008-12-31 10:58:48 +0800518 int state;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700519
Linus Torvalds1da177e2005-04-16 15:20:36 -0700520 arg0.integer.value = level;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700521
Zhang Rui24450c72009-03-18 16:27:10 +0800522 status = acpi_evaluate_object(device->dev->handle, "_BCM",
523 &args, NULL);
524 if (ACPI_FAILURE(status)) {
525 ACPI_ERROR((AE_INFO, "Evaluating _BCM failed"));
526 return -EIO;
527 }
528
Alexey Starikovskiy4500ca82007-09-03 16:29:58 +0400529 device->brightness->curr = level;
Zhang Rui9e6dada2008-12-31 10:58:48 +0800530 for (state = 2; state < device->brightness->count; state++)
Zhang Rui24450c72009-03-18 16:27:10 +0800531 if (level == device->brightness->levels[state]) {
Zhang Rui1a7c6182009-03-18 16:27:16 +0800532 if (device->backlight)
533 device->backlight->props.brightness = state - 2;
Zhang Rui24450c72009-03-18 16:27:10 +0800534 return 0;
535 }
Zhang Rui9e6dada2008-12-31 10:58:48 +0800536
Zhang Rui24450c72009-03-18 16:27:10 +0800537 ACPI_ERROR((AE_INFO, "Current brightness invalid"));
538 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700539}
540
541static int
Len Brown4be44fc2005-08-05 00:44:28 -0400542acpi_video_device_lcd_get_level_current(struct acpi_video_device *device,
Matthew Wilcox27663c52008-10-10 02:22:59 -0400543 unsigned long long *level)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700544{
Zhang Ruic8890f92009-03-18 16:27:08 +0800545 acpi_status status = AE_OK;
546
Zhang Ruic60d6382009-03-18 16:27:18 +0800547 if (device->cap._BQC || device->cap._BCQ) {
548 char *buf = device->cap._BQC ? "_BQC" : "_BCQ";
549
550 status = acpi_evaluate_integer(device->dev->handle, buf,
Zhang Ruic8890f92009-03-18 16:27:08 +0800551 NULL, level);
552 if (ACPI_SUCCESS(status)) {
Zhang Rui1a7c6182009-03-18 16:27:16 +0800553 if (device->brightness->flags._BQC_use_index) {
554 if (device->brightness->flags._BCL_reversed)
555 *level = device->brightness->count
556 - 3 - (*level);
557 *level = device->brightness->levels[*level + 2];
558
559 }
Zhang Ruic8890f92009-03-18 16:27:08 +0800560 device->brightness->curr = *level;
561 return 0;
562 } else {
563 /* Fixme:
564 * should we return an error or ignore this failure?
565 * dev->brightness->curr is a cached value which stores
566 * the correct current backlight level in most cases.
567 * ACPI video backlight still works w/ buggy _BQC.
568 * http://bugzilla.kernel.org/show_bug.cgi?id=12233
569 */
Zhang Ruic60d6382009-03-18 16:27:18 +0800570 ACPI_WARNING((AE_INFO, "Evaluating %s failed", buf));
571 device->cap._BQC = device->cap._BCQ = 0;
Zhang Ruic8890f92009-03-18 16:27:08 +0800572 }
573 }
574
Alexey Starikovskiy4500ca82007-09-03 16:29:58 +0400575 *level = device->brightness->curr;
Zhang Ruic8890f92009-03-18 16:27:08 +0800576 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700577}
578
579static int
Len Brown4be44fc2005-08-05 00:44:28 -0400580acpi_video_device_EDID(struct acpi_video_device *device,
581 union acpi_object **edid, ssize_t length)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700582{
Len Brown4be44fc2005-08-05 00:44:28 -0400583 int status;
584 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
585 union acpi_object *obj;
586 union acpi_object arg0 = { ACPI_TYPE_INTEGER };
587 struct acpi_object_list args = { 1, &arg0 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700588
Linus Torvalds1da177e2005-04-16 15:20:36 -0700589
590 *edid = NULL;
591
592 if (!device)
Patrick Mocheld550d982006-06-27 00:41:40 -0400593 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700594 if (length == 128)
595 arg0.integer.value = 1;
596 else if (length == 256)
597 arg0.integer.value = 2;
598 else
Patrick Mocheld550d982006-06-27 00:41:40 -0400599 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700600
Patrick Mochel90130262006-05-19 16:54:48 -0400601 status = acpi_evaluate_object(device->dev->handle, "_DDC", &args, &buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700602 if (ACPI_FAILURE(status))
Patrick Mocheld550d982006-06-27 00:41:40 -0400603 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700604
Jan Engelhardt50dd0962006-10-01 00:28:50 +0200605 obj = buffer.pointer;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700606
607 if (obj && obj->type == ACPI_TYPE_BUFFER)
608 *edid = obj;
609 else {
Len Brown64684632006-06-26 23:41:38 -0400610 printk(KERN_ERR PREFIX "Invalid _DDC data\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700611 status = -EFAULT;
612 kfree(obj);
613 }
614
Patrick Mocheld550d982006-06-27 00:41:40 -0400615 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700616}
617
Linus Torvalds1da177e2005-04-16 15:20:36 -0700618/* bus */
619
620static int
Len Brown4be44fc2005-08-05 00:44:28 -0400621acpi_video_bus_set_POST(struct acpi_video_bus *video, unsigned long option)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700622{
Len Brown4be44fc2005-08-05 00:44:28 -0400623 int status;
Matthew Wilcox27663c52008-10-10 02:22:59 -0400624 unsigned long long tmp;
Len Brown4be44fc2005-08-05 00:44:28 -0400625 union acpi_object arg0 = { ACPI_TYPE_INTEGER };
626 struct acpi_object_list args = { 1, &arg0 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700627
Linus Torvalds1da177e2005-04-16 15:20:36 -0700628
629 arg0.integer.value = option;
630
Patrick Mochel90130262006-05-19 16:54:48 -0400631 status = acpi_evaluate_integer(video->device->handle, "_SPD", &args, &tmp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700632 if (ACPI_SUCCESS(status))
Len Brown4be44fc2005-08-05 00:44:28 -0400633 status = tmp ? (-EINVAL) : (AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700634
Patrick Mocheld550d982006-06-27 00:41:40 -0400635 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700636}
637
638static int
Matthew Wilcox27663c52008-10-10 02:22:59 -0400639acpi_video_bus_get_POST(struct acpi_video_bus *video, unsigned long long *id)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700640{
641 int status;
642
Patrick Mochel90130262006-05-19 16:54:48 -0400643 status = acpi_evaluate_integer(video->device->handle, "_GPD", NULL, id);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700644
Patrick Mocheld550d982006-06-27 00:41:40 -0400645 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700646}
647
648static int
Len Brown4be44fc2005-08-05 00:44:28 -0400649acpi_video_bus_POST_options(struct acpi_video_bus *video,
Matthew Wilcox27663c52008-10-10 02:22:59 -0400650 unsigned long long *options)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700651{
Len Brown4be44fc2005-08-05 00:44:28 -0400652 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700653
Patrick Mochel90130262006-05-19 16:54:48 -0400654 status = acpi_evaluate_integer(video->device->handle, "_VPO", NULL, options);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700655 *options &= 3;
656
Patrick Mocheld550d982006-06-27 00:41:40 -0400657 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700658}
659
660/*
661 * Arg:
662 * video : video bus device pointer
663 * bios_flag :
664 * 0. The system BIOS should NOT automatically switch(toggle)
665 * the active display output.
666 * 1. The system BIOS should automatically switch (toggle) the
Julius Volz98fb8fe2007-02-20 16:38:40 +0100667 * active display output. No switch event.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700668 * 2. The _DGS value should be locked.
669 * 3. The system BIOS should not automatically switch (toggle) the
670 * active display output, but instead generate the display switch
671 * event notify code.
672 * lcd_flag :
673 * 0. The system BIOS should automatically control the brightness level
Julius Volz98fb8fe2007-02-20 16:38:40 +0100674 * of the LCD when the power changes from AC to DC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700675 * 1. The system BIOS should NOT automatically control the brightness
Julius Volz98fb8fe2007-02-20 16:38:40 +0100676 * level of the LCD when the power changes from AC to DC.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700677 * Return Value:
678 * -1 wrong arg.
679 */
680
681static int
Len Brown4be44fc2005-08-05 00:44:28 -0400682acpi_video_bus_DOS(struct acpi_video_bus *video, int bios_flag, int lcd_flag)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700683{
Len Brown4be44fc2005-08-05 00:44:28 -0400684 acpi_integer status = 0;
685 union acpi_object arg0 = { ACPI_TYPE_INTEGER };
686 struct acpi_object_list args = { 1, &arg0 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700687
Linus Torvalds1da177e2005-04-16 15:20:36 -0700688
Len Brown4be44fc2005-08-05 00:44:28 -0400689 if (bios_flag < 0 || bios_flag > 3 || lcd_flag < 0 || lcd_flag > 1) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700690 status = -1;
691 goto Failed;
692 }
693 arg0.integer.value = (lcd_flag << 2) | bios_flag;
694 video->dos_setting = arg0.integer.value;
Patrick Mochel90130262006-05-19 16:54:48 -0400695 acpi_evaluate_object(video->device->handle, "_DOS", &args, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700696
Len Brown4be44fc2005-08-05 00:44:28 -0400697 Failed:
Patrick Mocheld550d982006-06-27 00:41:40 -0400698 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700699}
700
701/*
Zhang Rui935e5f22008-12-11 16:24:52 -0500702 * Simple comparison function used to sort backlight levels.
703 */
704
705static int
706acpi_video_cmp_level(const void *a, const void *b)
707{
708 return *(int *)a - *(int *)b;
709}
710
711/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700712 * Arg:
713 * device : video output device (LCD, CRT, ..)
714 *
715 * Return Value:
Julia Jomantaite469778c2008-06-23 22:50:42 +0100716 * Maximum brightness level
717 *
718 * Allocate and initialize device->brightness.
719 */
720
721static int
722acpi_video_init_brightness(struct acpi_video_device *device)
723{
724 union acpi_object *obj = NULL;
Zhang Ruid32f6942009-03-18 16:27:12 +0800725 int i, max_level = 0, count = 0, level_ac_battery = 0;
Zhang Rui1a7c6182009-03-18 16:27:16 +0800726 unsigned long long level, level_old;
Julia Jomantaite469778c2008-06-23 22:50:42 +0100727 union acpi_object *o;
728 struct acpi_video_device_brightness *br = NULL;
Zhang Rui1a7c6182009-03-18 16:27:16 +0800729 int result = -EINVAL;
Julia Jomantaite469778c2008-06-23 22:50:42 +0100730
731 if (!ACPI_SUCCESS(acpi_video_device_lcd_query_levels(device, &obj))) {
732 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Could not query available "
733 "LCD brightness level\n"));
734 goto out;
735 }
736
737 if (obj->package.count < 2)
738 goto out;
739
740 br = kzalloc(sizeof(*br), GFP_KERNEL);
741 if (!br) {
742 printk(KERN_ERR "can't allocate memory\n");
Zhang Rui1a7c6182009-03-18 16:27:16 +0800743 result = -ENOMEM;
Julia Jomantaite469778c2008-06-23 22:50:42 +0100744 goto out;
745 }
746
Zhang Ruid32f6942009-03-18 16:27:12 +0800747 br->levels = kmalloc((obj->package.count + 2) * sizeof *(br->levels),
Julia Jomantaite469778c2008-06-23 22:50:42 +0100748 GFP_KERNEL);
Zhang Rui1a7c6182009-03-18 16:27:16 +0800749 if (!br->levels) {
750 result = -ENOMEM;
Julia Jomantaite469778c2008-06-23 22:50:42 +0100751 goto out_free;
Zhang Rui1a7c6182009-03-18 16:27:16 +0800752 }
Julia Jomantaite469778c2008-06-23 22:50:42 +0100753
754 for (i = 0; i < obj->package.count; i++) {
755 o = (union acpi_object *)&obj->package.elements[i];
756 if (o->type != ACPI_TYPE_INTEGER) {
757 printk(KERN_ERR PREFIX "Invalid data\n");
758 continue;
759 }
760 br->levels[count] = (u32) o->integer.value;
761
762 if (br->levels[count] > max_level)
763 max_level = br->levels[count];
764 count++;
765 }
766
Zhang Ruid32f6942009-03-18 16:27:12 +0800767 /*
768 * some buggy BIOS don't export the levels
769 * when machine is on AC/Battery in _BCL package.
770 * In this case, the first two elements in _BCL packages
771 * are also supported brightness levels that OS should take care of.
772 */
773 for (i = 2; i < count; i++)
774 if (br->levels[i] == br->levels[0] ||
775 br->levels[i] == br->levels[1])
776 level_ac_battery++;
Zhang Rui935e5f22008-12-11 16:24:52 -0500777
Zhang Ruid32f6942009-03-18 16:27:12 +0800778 if (level_ac_battery < 2) {
779 level_ac_battery = 2 - level_ac_battery;
780 br->flags._BCL_no_ac_battery_levels = 1;
781 for (i = (count - 1 + level_ac_battery); i >= 2; i--)
782 br->levels[i] = br->levels[i - level_ac_battery];
783 count += level_ac_battery;
784 } else if (level_ac_battery > 2)
785 ACPI_ERROR((AE_INFO, "Too many duplicates in _BCL package\n"));
786
Zhang Ruid80fb992009-03-18 16:27:14 +0800787 /* Check if the _BCL package is in a reversed order */
788 if (max_level == br->levels[2]) {
789 br->flags._BCL_reversed = 1;
790 sort(&br->levels[2], count - 2, sizeof(br->levels[2]),
791 acpi_video_cmp_level, NULL);
792 } else if (max_level != br->levels[count - 1])
793 ACPI_ERROR((AE_INFO,
794 "Found unordered _BCL package\n"));
Julia Jomantaite469778c2008-06-23 22:50:42 +0100795
796 br->count = count;
797 device->brightness = br;
Zhang Rui1a7c6182009-03-18 16:27:16 +0800798
799 /* Check the input/output of _BQC/_BCL/_BCM */
800 if ((max_level < 100) && (max_level <= (count - 2)))
801 br->flags._BCL_use_index = 1;
802
803 /*
804 * _BCM is always consistent with _BCL,
805 * at least for all the laptops we have ever seen.
806 */
807 br->flags._BCM_use_index = br->flags._BCL_use_index;
808
809 /* _BQC uses INDEX while _BCL uses VALUE in some laptops */
Zhang Ruie047cca2009-04-09 14:24:35 +0800810 br->curr = level_old = max_level;
811
812 if (!device->cap._BQC)
813 goto set_level;
814
Zhang Rui1a7c6182009-03-18 16:27:16 +0800815 result = acpi_video_device_lcd_get_level_current(device, &level_old);
816 if (result)
817 goto out_free_levels;
818
Zhang Ruie047cca2009-04-09 14:24:35 +0800819 /*
820 * Set the level to maximum and check if _BQC uses indexed value
821 */
822 result = acpi_video_device_lcd_set_level(device, max_level);
Zhang Rui1a7c6182009-03-18 16:27:16 +0800823 if (result)
824 goto out_free_levels;
825
826 result = acpi_video_device_lcd_get_level_current(device, &level);
827 if (result)
828 goto out_free_levels;
829
Zhang Ruie047cca2009-04-09 14:24:35 +0800830 br->flags._BQC_use_index = (level == max_level ? 0 : 1);
Zhang Rui1a7c6182009-03-18 16:27:16 +0800831
Zhang Ruie047cca2009-04-09 14:24:35 +0800832 if (!br->flags._BQC_use_index)
833 goto set_level;
834
835 if (br->flags._BCL_reversed)
836 level_old = (br->count - 1) - level_old;
837 level_old = br->levels[level_old];
838
839set_level:
840 result = acpi_video_device_lcd_set_level(device, level_old);
841 if (result)
842 goto out_free_levels;
Zhang Rui1a7c6182009-03-18 16:27:16 +0800843
Zhang Ruid32f6942009-03-18 16:27:12 +0800844 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
845 "found %d brightness levels\n", count - 2));
Julia Jomantaite469778c2008-06-23 22:50:42 +0100846 kfree(obj);
Zhang Rui1a7c6182009-03-18 16:27:16 +0800847 return result;
Julia Jomantaite469778c2008-06-23 22:50:42 +0100848
849out_free_levels:
850 kfree(br->levels);
851out_free:
852 kfree(br);
853out:
854 device->brightness = NULL;
855 kfree(obj);
Zhang Rui1a7c6182009-03-18 16:27:16 +0800856 return result;
Julia Jomantaite469778c2008-06-23 22:50:42 +0100857}
858
859/*
860 * Arg:
861 * device : video output device (LCD, CRT, ..)
862 *
863 * Return Value:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700864 * None
865 *
Julius Volz98fb8fe2007-02-20 16:38:40 +0100866 * Find out all required AML methods defined under the output
Linus Torvalds1da177e2005-04-16 15:20:36 -0700867 * device.
868 */
869
Len Brown4be44fc2005-08-05 00:44:28 -0400870static void acpi_video_device_find_cap(struct acpi_video_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700871{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700872 acpi_handle h_dummy1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700873
Linus Torvalds1da177e2005-04-16 15:20:36 -0700874
William Lee Irwin III98934de2007-12-12 03:56:55 -0800875 memset(&device->cap, 0, sizeof(device->cap));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700876
Patrick Mochel90130262006-05-19 16:54:48 -0400877 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_ADR", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700878 device->cap._ADR = 1;
879 }
Patrick Mochel90130262006-05-19 16:54:48 -0400880 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_BCL", &h_dummy1))) {
Len Brown4be44fc2005-08-05 00:44:28 -0400881 device->cap._BCL = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700882 }
Patrick Mochel90130262006-05-19 16:54:48 -0400883 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_BCM", &h_dummy1))) {
Len Brown4be44fc2005-08-05 00:44:28 -0400884 device->cap._BCM = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700885 }
Yu Luming2f3d0002006-11-11 02:40:34 +0800886 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle,"_BQC",&h_dummy1)))
887 device->cap._BQC = 1;
Zhang Ruic60d6382009-03-18 16:27:18 +0800888 else if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_BCQ",
889 &h_dummy1))) {
890 printk(KERN_WARNING FW_BUG "_BCQ is used instead of _BQC\n");
891 device->cap._BCQ = 1;
892 }
893
Patrick Mochel90130262006-05-19 16:54:48 -0400894 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_DDC", &h_dummy1))) {
Len Brown4be44fc2005-08-05 00:44:28 -0400895 device->cap._DDC = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700896 }
Patrick Mochel90130262006-05-19 16:54:48 -0400897 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_DCS", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700898 device->cap._DCS = 1;
899 }
Patrick Mochel90130262006-05-19 16:54:48 -0400900 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_DGS", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700901 device->cap._DGS = 1;
902 }
Patrick Mochel90130262006-05-19 16:54:48 -0400903 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_DSS", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700904 device->cap._DSS = 1;
905 }
906
Zhang Rui1a7c6182009-03-18 16:27:16 +0800907 if (acpi_video_backlight_support()) {
Zhang Rui702ed512008-01-17 15:51:22 +0800908 int result;
Yu Luming2f3d0002006-11-11 02:40:34 +0800909 static int count = 0;
910 char *name;
Zhang Rui1a7c6182009-03-18 16:27:16 +0800911
912 result = acpi_video_init_brightness(device);
913 if (result)
914 return;
Yu Luming2f3d0002006-11-11 02:40:34 +0800915 name = kzalloc(MAX_NAME_LEN, GFP_KERNEL);
916 if (!name)
917 return;
918
Yu Luming2f3d0002006-11-11 02:40:34 +0800919 sprintf(name, "acpi_video%d", count++);
Yu Luming2f3d0002006-11-11 02:40:34 +0800920 device->backlight = backlight_device_register(name,
Richard Purdie599a52d2007-02-10 23:07:48 +0000921 NULL, device, &acpi_backlight_ops);
Matthew Garrett38531e62007-12-26 02:03:26 +0000922 device->backlight->props.max_brightness = device->brightness->count-3;
Yu Luming2f3d0002006-11-11 02:40:34 +0800923 kfree(name);
Zhang Rui702ed512008-01-17 15:51:22 +0800924
925 device->cdev = thermal_cooling_device_register("LCD",
926 device->dev, &video_cooling_ops);
Thomas Sujith43ff39f2008-02-15 18:29:18 -0500927 if (IS_ERR(device->cdev))
928 return;
929
Greg Kroah-Hartmanfc3a8822008-05-02 06:02:41 +0200930 dev_info(&device->dev->dev, "registered as cooling_device%d\n",
931 device->cdev->id);
Julia Lawall90300622008-04-11 10:09:24 +0800932 result = sysfs_create_link(&device->dev->dev.kobj,
933 &device->cdev->device.kobj,
934 "thermal_cooling");
935 if (result)
936 printk(KERN_ERR PREFIX "Create sysfs link\n");
937 result = sysfs_create_link(&device->cdev->device.kobj,
938 &device->dev->dev.kobj, "device");
939 if (result)
940 printk(KERN_ERR PREFIX "Create sysfs link\n");
941
Yu Luming2f3d0002006-11-11 02:40:34 +0800942 }
Thomas Renningerc3d6de62008-08-01 17:37:55 +0200943
944 if (acpi_video_display_switch_support()) {
945
946 if (device->cap._DCS && device->cap._DSS) {
947 static int count;
948 char *name;
949 name = kzalloc(MAX_NAME_LEN, GFP_KERNEL);
950 if (!name)
951 return;
952 sprintf(name, "acpi_video%d", count++);
953 device->output_dev = video_output_register(name,
954 NULL, device, &acpi_output_properties);
955 kfree(name);
956 }
Luming Yu23b0f012007-05-09 21:07:05 +0800957 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700958}
959
960/*
961 * Arg:
962 * device : video output device (VGA)
963 *
964 * Return Value:
965 * None
966 *
Julius Volz98fb8fe2007-02-20 16:38:40 +0100967 * Find out all required AML methods defined under the video bus device.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700968 */
969
Len Brown4be44fc2005-08-05 00:44:28 -0400970static void acpi_video_bus_find_cap(struct acpi_video_bus *video)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700971{
Len Brown4be44fc2005-08-05 00:44:28 -0400972 acpi_handle h_dummy1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700973
William Lee Irwin III98934de2007-12-12 03:56:55 -0800974 memset(&video->cap, 0, sizeof(video->cap));
Patrick Mochel90130262006-05-19 16:54:48 -0400975 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_DOS", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700976 video->cap._DOS = 1;
977 }
Patrick Mochel90130262006-05-19 16:54:48 -0400978 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_DOD", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700979 video->cap._DOD = 1;
980 }
Patrick Mochel90130262006-05-19 16:54:48 -0400981 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_ROM", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700982 video->cap._ROM = 1;
983 }
Patrick Mochel90130262006-05-19 16:54:48 -0400984 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_GPD", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700985 video->cap._GPD = 1;
986 }
Patrick Mochel90130262006-05-19 16:54:48 -0400987 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_SPD", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700988 video->cap._SPD = 1;
989 }
Patrick Mochel90130262006-05-19 16:54:48 -0400990 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_VPO", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700991 video->cap._VPO = 1;
992 }
993}
994
995/*
996 * Check whether the video bus device has required AML method to
997 * support the desired features
998 */
999
Len Brown4be44fc2005-08-05 00:44:28 -04001000static int acpi_video_bus_check(struct acpi_video_bus *video)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001001{
Len Brown4be44fc2005-08-05 00:44:28 -04001002 acpi_status status = -ENOENT;
Thomas Renninger22c13f92008-08-01 17:37:54 +02001003 struct device *dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001004
1005 if (!video)
Patrick Mocheld550d982006-06-27 00:41:40 -04001006 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001007
Thomas Renninger22c13f92008-08-01 17:37:54 +02001008 dev = acpi_get_physical_pci_device(video->device->handle);
1009 if (!dev)
1010 return -ENODEV;
1011 put_device(dev);
1012
Linus Torvalds1da177e2005-04-16 15:20:36 -07001013 /* Since there is no HID, CID and so on for VGA driver, we have
1014 * to check well known required nodes.
1015 */
1016
Julius Volz98fb8fe2007-02-20 16:38:40 +01001017 /* Does this device support video switching? */
Len Brown4be44fc2005-08-05 00:44:28 -04001018 if (video->cap._DOS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001019 video->flags.multihead = 1;
1020 status = 0;
1021 }
1022
Julius Volz98fb8fe2007-02-20 16:38:40 +01001023 /* Does this device support retrieving a video ROM? */
Len Brown4be44fc2005-08-05 00:44:28 -04001024 if (video->cap._ROM) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001025 video->flags.rom = 1;
1026 status = 0;
1027 }
1028
Julius Volz98fb8fe2007-02-20 16:38:40 +01001029 /* Does this device support configuring which video device to POST? */
Len Brown4be44fc2005-08-05 00:44:28 -04001030 if (video->cap._GPD && video->cap._SPD && video->cap._VPO) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001031 video->flags.post = 1;
1032 status = 0;
1033 }
1034
Patrick Mocheld550d982006-06-27 00:41:40 -04001035 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001036}
1037
1038/* --------------------------------------------------------------------------
1039 FS Interface (/proc)
1040 -------------------------------------------------------------------------- */
1041
Len Brown4be44fc2005-08-05 00:44:28 -04001042static struct proc_dir_entry *acpi_video_dir;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001043
1044/* video devices */
1045
Len Brown4be44fc2005-08-05 00:44:28 -04001046static int acpi_video_device_info_seq_show(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001047{
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001048 struct acpi_video_device *dev = seq->private;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001049
Linus Torvalds1da177e2005-04-16 15:20:36 -07001050
1051 if (!dev)
1052 goto end;
1053
1054 seq_printf(seq, "device_id: 0x%04x\n", (u32) dev->device_id);
1055 seq_printf(seq, "type: ");
1056 if (dev->flags.crt)
1057 seq_printf(seq, "CRT\n");
1058 else if (dev->flags.lcd)
1059 seq_printf(seq, "LCD\n");
1060 else if (dev->flags.tvout)
1061 seq_printf(seq, "TVOUT\n");
Rui Zhang82cae992007-01-03 23:40:53 -05001062 else if (dev->flags.dvi)
1063 seq_printf(seq, "DVI\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001064 else
1065 seq_printf(seq, "UNKNOWN\n");
1066
Len Brown4be44fc2005-08-05 00:44:28 -04001067 seq_printf(seq, "known by bios: %s\n", dev->flags.bios ? "yes" : "no");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001068
Len Brown4be44fc2005-08-05 00:44:28 -04001069 end:
Patrick Mocheld550d982006-06-27 00:41:40 -04001070 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001071}
1072
1073static int
Len Brown4be44fc2005-08-05 00:44:28 -04001074acpi_video_device_info_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001075{
1076 return single_open(file, acpi_video_device_info_seq_show,
1077 PDE(inode)->data);
1078}
1079
Len Brown4be44fc2005-08-05 00:44:28 -04001080static int acpi_video_device_state_seq_show(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001081{
Len Brown4be44fc2005-08-05 00:44:28 -04001082 int status;
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001083 struct acpi_video_device *dev = seq->private;
Matthew Wilcox27663c52008-10-10 02:22:59 -04001084 unsigned long long state;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001085
Linus Torvalds1da177e2005-04-16 15:20:36 -07001086
1087 if (!dev)
1088 goto end;
1089
1090 status = acpi_video_device_get_state(dev, &state);
1091 seq_printf(seq, "state: ");
1092 if (ACPI_SUCCESS(status))
Matthew Wilcox27663c52008-10-10 02:22:59 -04001093 seq_printf(seq, "0x%02llx\n", state);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001094 else
1095 seq_printf(seq, "<not supported>\n");
1096
1097 status = acpi_video_device_query(dev, &state);
1098 seq_printf(seq, "query: ");
1099 if (ACPI_SUCCESS(status))
Matthew Wilcox27663c52008-10-10 02:22:59 -04001100 seq_printf(seq, "0x%02llx\n", state);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001101 else
1102 seq_printf(seq, "<not supported>\n");
1103
Len Brown4be44fc2005-08-05 00:44:28 -04001104 end:
Patrick Mocheld550d982006-06-27 00:41:40 -04001105 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001106}
1107
1108static int
Len Brown4be44fc2005-08-05 00:44:28 -04001109acpi_video_device_state_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001110{
1111 return single_open(file, acpi_video_device_state_seq_show,
1112 PDE(inode)->data);
1113}
1114
1115static ssize_t
Len Brown4be44fc2005-08-05 00:44:28 -04001116acpi_video_device_write_state(struct file *file,
1117 const char __user * buffer,
1118 size_t count, loff_t * data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001119{
Len Brown4be44fc2005-08-05 00:44:28 -04001120 int status;
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001121 struct seq_file *m = file->private_data;
1122 struct acpi_video_device *dev = m->private;
Len Brown4be44fc2005-08-05 00:44:28 -04001123 char str[12] = { 0 };
1124 u32 state = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001125
Linus Torvalds1da177e2005-04-16 15:20:36 -07001126
1127 if (!dev || count + 1 > sizeof str)
Patrick Mocheld550d982006-06-27 00:41:40 -04001128 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001129
1130 if (copy_from_user(str, buffer, count))
Patrick Mocheld550d982006-06-27 00:41:40 -04001131 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001132
1133 str[count] = 0;
1134 state = simple_strtoul(str, NULL, 0);
Len Brown4be44fc2005-08-05 00:44:28 -04001135 state &= ((1ul << 31) | (1ul << 30) | (1ul << 0));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001136
1137 status = acpi_video_device_set_state(dev, state);
1138
1139 if (status)
Patrick Mocheld550d982006-06-27 00:41:40 -04001140 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001141
Patrick Mocheld550d982006-06-27 00:41:40 -04001142 return count;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001143}
1144
1145static int
Len Brown4be44fc2005-08-05 00:44:28 -04001146acpi_video_device_brightness_seq_show(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001147{
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001148 struct acpi_video_device *dev = seq->private;
Len Brown4be44fc2005-08-05 00:44:28 -04001149 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001150
Linus Torvalds1da177e2005-04-16 15:20:36 -07001151
1152 if (!dev || !dev->brightness) {
1153 seq_printf(seq, "<not supported>\n");
Patrick Mocheld550d982006-06-27 00:41:40 -04001154 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001155 }
1156
1157 seq_printf(seq, "levels: ");
Zhao Yakui0a3db1c2009-02-02 11:33:41 +08001158 for (i = 2; i < dev->brightness->count; i++)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001159 seq_printf(seq, " %d", dev->brightness->levels[i]);
1160 seq_printf(seq, "\ncurrent: %d\n", dev->brightness->curr);
1161
Patrick Mocheld550d982006-06-27 00:41:40 -04001162 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001163}
1164
1165static int
Len Brown4be44fc2005-08-05 00:44:28 -04001166acpi_video_device_brightness_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001167{
1168 return single_open(file, acpi_video_device_brightness_seq_show,
1169 PDE(inode)->data);
1170}
1171
1172static ssize_t
Len Brown4be44fc2005-08-05 00:44:28 -04001173acpi_video_device_write_brightness(struct file *file,
1174 const char __user * buffer,
1175 size_t count, loff_t * data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001176{
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001177 struct seq_file *m = file->private_data;
1178 struct acpi_video_device *dev = m->private;
Danny Baumannc88c5782007-11-02 13:47:53 +01001179 char str[5] = { 0 };
Len Brown4be44fc2005-08-05 00:44:28 -04001180 unsigned int level = 0;
1181 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001182
Linus Torvalds1da177e2005-04-16 15:20:36 -07001183
Thomas Renninger59d399d2005-11-08 05:27:00 -05001184 if (!dev || !dev->brightness || count + 1 > sizeof str)
Patrick Mocheld550d982006-06-27 00:41:40 -04001185 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001186
1187 if (copy_from_user(str, buffer, count))
Patrick Mocheld550d982006-06-27 00:41:40 -04001188 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001189
1190 str[count] = 0;
1191 level = simple_strtoul(str, NULL, 0);
Len Brown4be44fc2005-08-05 00:44:28 -04001192
Linus Torvalds1da177e2005-04-16 15:20:36 -07001193 if (level > 100)
Patrick Mocheld550d982006-06-27 00:41:40 -04001194 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001195
Julius Volz98fb8fe2007-02-20 16:38:40 +01001196 /* validate through the list of available levels */
Zhao Yakui0a3db1c2009-02-02 11:33:41 +08001197 for (i = 2; i < dev->brightness->count; i++)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001198 if (level == dev->brightness->levels[i]) {
Zhang Rui24450c72009-03-18 16:27:10 +08001199 if (!acpi_video_device_lcd_set_level(dev, level))
1200 return count;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001201 break;
1202 }
1203
Zhang Rui24450c72009-03-18 16:27:10 +08001204 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001205}
1206
Len Brown4be44fc2005-08-05 00:44:28 -04001207static int acpi_video_device_EDID_seq_show(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001208{
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001209 struct acpi_video_device *dev = seq->private;
Len Brown4be44fc2005-08-05 00:44:28 -04001210 int status;
1211 int i;
1212 union acpi_object *edid = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001213
Linus Torvalds1da177e2005-04-16 15:20:36 -07001214
1215 if (!dev)
1216 goto out;
1217
Len Brown4be44fc2005-08-05 00:44:28 -04001218 status = acpi_video_device_EDID(dev, &edid, 128);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001219 if (ACPI_FAILURE(status)) {
Len Brown4be44fc2005-08-05 00:44:28 -04001220 status = acpi_video_device_EDID(dev, &edid, 256);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001221 }
1222
1223 if (ACPI_FAILURE(status)) {
1224 goto out;
1225 }
1226
1227 if (edid && edid->type == ACPI_TYPE_BUFFER) {
1228 for (i = 0; i < edid->buffer.length; i++)
1229 seq_putc(seq, edid->buffer.pointer[i]);
1230 }
1231
Len Brown4be44fc2005-08-05 00:44:28 -04001232 out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001233 if (!edid)
1234 seq_printf(seq, "<not supported>\n");
1235 else
1236 kfree(edid);
1237
Patrick Mocheld550d982006-06-27 00:41:40 -04001238 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001239}
1240
1241static int
Len Brown4be44fc2005-08-05 00:44:28 -04001242acpi_video_device_EDID_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001243{
1244 return single_open(file, acpi_video_device_EDID_seq_show,
1245 PDE(inode)->data);
1246}
1247
Len Brown4be44fc2005-08-05 00:44:28 -04001248static int acpi_video_device_add_fs(struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001249{
Dmitry Torokhov251cb0b2007-11-05 11:43:34 -05001250 struct proc_dir_entry *entry, *device_dir;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001251 struct acpi_video_device *vid_dev;
1252
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001253 vid_dev = acpi_driver_data(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001254 if (!vid_dev)
Patrick Mocheld550d982006-06-27 00:41:40 -04001255 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001256
Dmitry Torokhov251cb0b2007-11-05 11:43:34 -05001257 device_dir = proc_mkdir(acpi_device_bid(device),
1258 vid_dev->video->dir);
1259 if (!device_dir)
1260 return -ENOMEM;
1261
Linus Torvalds1da177e2005-04-16 15:20:36 -07001262 /* 'info' [R] */
Alexey Dobriyane0066c4e2008-05-01 04:10:02 +04001263 entry = proc_create_data("info", S_IRUGO, device_dir,
Denis V. Lunevcf7acfa2008-04-29 01:02:27 -07001264 &acpi_video_device_info_fops, acpi_driver_data(device));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001265 if (!entry)
Dmitry Torokhov251cb0b2007-11-05 11:43:34 -05001266 goto err_remove_dir;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001267
1268 /* 'state' [R/W] */
Denis V. Lunevcf7acfa2008-04-29 01:02:27 -07001269 entry = proc_create_data("state", S_IFREG | S_IRUGO | S_IWUSR,
Alexey Dobriyane0066c4e2008-05-01 04:10:02 +04001270 device_dir,
Denis V. Lunevcf7acfa2008-04-29 01:02:27 -07001271 &acpi_video_device_state_fops,
1272 acpi_driver_data(device));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001273 if (!entry)
Dmitry Torokhov251cb0b2007-11-05 11:43:34 -05001274 goto err_remove_info;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001275
1276 /* 'brightness' [R/W] */
Denis V. Lunevcf7acfa2008-04-29 01:02:27 -07001277 entry = proc_create_data("brightness", S_IFREG | S_IRUGO | S_IWUSR,
Alexey Dobriyane0066c4e2008-05-01 04:10:02 +04001278 device_dir,
Denis V. Lunevcf7acfa2008-04-29 01:02:27 -07001279 &acpi_video_device_brightness_fops,
1280 acpi_driver_data(device));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001281 if (!entry)
Dmitry Torokhov251cb0b2007-11-05 11:43:34 -05001282 goto err_remove_state;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001283
1284 /* 'EDID' [R] */
Alexey Dobriyane0066c4e2008-05-01 04:10:02 +04001285 entry = proc_create_data("EDID", S_IRUGO, device_dir,
Denis V. Lunevcf7acfa2008-04-29 01:02:27 -07001286 &acpi_video_device_EDID_fops,
1287 acpi_driver_data(device));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001288 if (!entry)
Dmitry Torokhov251cb0b2007-11-05 11:43:34 -05001289 goto err_remove_brightness;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001290
Alexey Dobriyane0066c4e2008-05-01 04:10:02 +04001291 acpi_device_dir(device) = device_dir;
1292
Patrick Mocheld550d982006-06-27 00:41:40 -04001293 return 0;
Dmitry Torokhov251cb0b2007-11-05 11:43:34 -05001294
1295 err_remove_brightness:
1296 remove_proc_entry("brightness", device_dir);
1297 err_remove_state:
1298 remove_proc_entry("state", device_dir);
1299 err_remove_info:
1300 remove_proc_entry("info", device_dir);
1301 err_remove_dir:
1302 remove_proc_entry(acpi_device_bid(device), vid_dev->video->dir);
1303 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001304}
1305
Len Brown4be44fc2005-08-05 00:44:28 -04001306static int acpi_video_device_remove_fs(struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001307{
1308 struct acpi_video_device *vid_dev;
Dmitry Torokhov251cb0b2007-11-05 11:43:34 -05001309 struct proc_dir_entry *device_dir;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001310
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001311 vid_dev = acpi_driver_data(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001312 if (!vid_dev || !vid_dev->video || !vid_dev->video->dir)
Patrick Mocheld550d982006-06-27 00:41:40 -04001313 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001314
Dmitry Torokhov251cb0b2007-11-05 11:43:34 -05001315 device_dir = acpi_device_dir(device);
1316 if (device_dir) {
1317 remove_proc_entry("info", device_dir);
1318 remove_proc_entry("state", device_dir);
1319 remove_proc_entry("brightness", device_dir);
1320 remove_proc_entry("EDID", device_dir);
Len Brown4be44fc2005-08-05 00:44:28 -04001321 remove_proc_entry(acpi_device_bid(device), vid_dev->video->dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001322 acpi_device_dir(device) = NULL;
1323 }
1324
Patrick Mocheld550d982006-06-27 00:41:40 -04001325 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001326}
1327
Linus Torvalds1da177e2005-04-16 15:20:36 -07001328/* video bus */
Len Brown4be44fc2005-08-05 00:44:28 -04001329static int acpi_video_bus_info_seq_show(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001330{
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001331 struct acpi_video_bus *video = seq->private;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001332
Linus Torvalds1da177e2005-04-16 15:20:36 -07001333
1334 if (!video)
1335 goto end;
1336
1337 seq_printf(seq, "Switching heads: %s\n",
Len Brown4be44fc2005-08-05 00:44:28 -04001338 video->flags.multihead ? "yes" : "no");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001339 seq_printf(seq, "Video ROM: %s\n",
Len Brown4be44fc2005-08-05 00:44:28 -04001340 video->flags.rom ? "yes" : "no");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001341 seq_printf(seq, "Device to be POSTed on boot: %s\n",
Len Brown4be44fc2005-08-05 00:44:28 -04001342 video->flags.post ? "yes" : "no");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001343
Len Brown4be44fc2005-08-05 00:44:28 -04001344 end:
Patrick Mocheld550d982006-06-27 00:41:40 -04001345 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001346}
1347
Len Brown4be44fc2005-08-05 00:44:28 -04001348static int acpi_video_bus_info_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001349{
Len Brown4be44fc2005-08-05 00:44:28 -04001350 return single_open(file, acpi_video_bus_info_seq_show,
1351 PDE(inode)->data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001352}
1353
Len Brown4be44fc2005-08-05 00:44:28 -04001354static int acpi_video_bus_ROM_seq_show(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001355{
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001356 struct acpi_video_bus *video = seq->private;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001357
Linus Torvalds1da177e2005-04-16 15:20:36 -07001358
1359 if (!video)
1360 goto end;
1361
Harvey Harrison96b2dd12008-03-05 18:24:51 -08001362 printk(KERN_INFO PREFIX "Please implement %s\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001363 seq_printf(seq, "<TODO>\n");
1364
Len Brown4be44fc2005-08-05 00:44:28 -04001365 end:
Patrick Mocheld550d982006-06-27 00:41:40 -04001366 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001367}
1368
Len Brown4be44fc2005-08-05 00:44:28 -04001369static int acpi_video_bus_ROM_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001370{
1371 return single_open(file, acpi_video_bus_ROM_seq_show, PDE(inode)->data);
1372}
1373
Len Brown4be44fc2005-08-05 00:44:28 -04001374static int acpi_video_bus_POST_info_seq_show(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001375{
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001376 struct acpi_video_bus *video = seq->private;
Matthew Wilcox27663c52008-10-10 02:22:59 -04001377 unsigned long long options;
Len Brown4be44fc2005-08-05 00:44:28 -04001378 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001379
Linus Torvalds1da177e2005-04-16 15:20:36 -07001380
1381 if (!video)
1382 goto end;
1383
1384 status = acpi_video_bus_POST_options(video, &options);
1385 if (ACPI_SUCCESS(status)) {
1386 if (!(options & 1)) {
Len Brown4be44fc2005-08-05 00:44:28 -04001387 printk(KERN_WARNING PREFIX
1388 "The motherboard VGA device is not listed as a possible POST device.\n");
1389 printk(KERN_WARNING PREFIX
Julius Volz98fb8fe2007-02-20 16:38:40 +01001390 "This indicates a BIOS bug. Please contact the manufacturer.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001391 }
Frank Seidel4d939152009-02-04 17:03:07 +01001392 printk(KERN_WARNING "%llx\n", options);
Julius Volz98fb8fe2007-02-20 16:38:40 +01001393 seq_printf(seq, "can POST: <integrated video>");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001394 if (options & 2)
1395 seq_printf(seq, " <PCI video>");
1396 if (options & 4)
1397 seq_printf(seq, " <AGP video>");
1398 seq_putc(seq, '\n');
1399 } else
1400 seq_printf(seq, "<not supported>\n");
Len Brown4be44fc2005-08-05 00:44:28 -04001401 end:
Patrick Mocheld550d982006-06-27 00:41:40 -04001402 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001403}
1404
1405static int
Len Brown4be44fc2005-08-05 00:44:28 -04001406acpi_video_bus_POST_info_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001407{
Len Brown4be44fc2005-08-05 00:44:28 -04001408 return single_open(file, acpi_video_bus_POST_info_seq_show,
1409 PDE(inode)->data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001410}
1411
Len Brown4be44fc2005-08-05 00:44:28 -04001412static int acpi_video_bus_POST_seq_show(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001413{
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001414 struct acpi_video_bus *video = seq->private;
Len Brown4be44fc2005-08-05 00:44:28 -04001415 int status;
Matthew Wilcox27663c52008-10-10 02:22:59 -04001416 unsigned long long id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001417
Linus Torvalds1da177e2005-04-16 15:20:36 -07001418
1419 if (!video)
1420 goto end;
1421
Len Brown4be44fc2005-08-05 00:44:28 -04001422 status = acpi_video_bus_get_POST(video, &id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001423 if (!ACPI_SUCCESS(status)) {
1424 seq_printf(seq, "<not supported>\n");
1425 goto end;
1426 }
Julius Volz98fb8fe2007-02-20 16:38:40 +01001427 seq_printf(seq, "device POSTed is <%s>\n", device_decode[id & 3]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001428
Len Brown4be44fc2005-08-05 00:44:28 -04001429 end:
Patrick Mocheld550d982006-06-27 00:41:40 -04001430 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001431}
1432
Len Brown4be44fc2005-08-05 00:44:28 -04001433static int acpi_video_bus_DOS_seq_show(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001434{
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001435 struct acpi_video_bus *video = seq->private;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001436
Linus Torvalds1da177e2005-04-16 15:20:36 -07001437
Len Brown4be44fc2005-08-05 00:44:28 -04001438 seq_printf(seq, "DOS setting: <%d>\n", video->dos_setting);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001439
Patrick Mocheld550d982006-06-27 00:41:40 -04001440 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001441}
1442
Len Brown4be44fc2005-08-05 00:44:28 -04001443static int acpi_video_bus_POST_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001444{
Len Brown4be44fc2005-08-05 00:44:28 -04001445 return single_open(file, acpi_video_bus_POST_seq_show,
1446 PDE(inode)->data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001447}
1448
Len Brown4be44fc2005-08-05 00:44:28 -04001449static int acpi_video_bus_DOS_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001450{
1451 return single_open(file, acpi_video_bus_DOS_seq_show, PDE(inode)->data);
1452}
1453
1454static ssize_t
Len Brown4be44fc2005-08-05 00:44:28 -04001455acpi_video_bus_write_POST(struct file *file,
1456 const char __user * buffer,
1457 size_t count, loff_t * data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001458{
Len Brown4be44fc2005-08-05 00:44:28 -04001459 int status;
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001460 struct seq_file *m = file->private_data;
1461 struct acpi_video_bus *video = m->private;
Len Brown4be44fc2005-08-05 00:44:28 -04001462 char str[12] = { 0 };
Matthew Wilcox27663c52008-10-10 02:22:59 -04001463 unsigned long long opt, options;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001464
Linus Torvalds1da177e2005-04-16 15:20:36 -07001465
Linus Torvalds1da177e2005-04-16 15:20:36 -07001466 if (!video || count + 1 > sizeof str)
Patrick Mocheld550d982006-06-27 00:41:40 -04001467 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001468
1469 status = acpi_video_bus_POST_options(video, &options);
1470 if (!ACPI_SUCCESS(status))
Patrick Mocheld550d982006-06-27 00:41:40 -04001471 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001472
1473 if (copy_from_user(str, buffer, count))
Patrick Mocheld550d982006-06-27 00:41:40 -04001474 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001475
1476 str[count] = 0;
1477 opt = strtoul(str, NULL, 0);
1478 if (opt > 3)
Patrick Mocheld550d982006-06-27 00:41:40 -04001479 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001480
Julius Volz98fb8fe2007-02-20 16:38:40 +01001481 /* just in case an OEM 'forgot' the motherboard... */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001482 options |= 1;
1483
1484 if (options & (1ul << opt)) {
Len Brown4be44fc2005-08-05 00:44:28 -04001485 status = acpi_video_bus_set_POST(video, opt);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001486 if (!ACPI_SUCCESS(status))
Patrick Mocheld550d982006-06-27 00:41:40 -04001487 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001488
1489 }
1490
Patrick Mocheld550d982006-06-27 00:41:40 -04001491 return count;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001492}
1493
1494static ssize_t
Len Brown4be44fc2005-08-05 00:44:28 -04001495acpi_video_bus_write_DOS(struct file *file,
1496 const char __user * buffer,
1497 size_t count, loff_t * data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001498{
Len Brown4be44fc2005-08-05 00:44:28 -04001499 int status;
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001500 struct seq_file *m = file->private_data;
1501 struct acpi_video_bus *video = m->private;
Len Brown4be44fc2005-08-05 00:44:28 -04001502 char str[12] = { 0 };
1503 unsigned long opt;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001504
Linus Torvalds1da177e2005-04-16 15:20:36 -07001505
Linus Torvalds1da177e2005-04-16 15:20:36 -07001506 if (!video || count + 1 > sizeof str)
Patrick Mocheld550d982006-06-27 00:41:40 -04001507 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001508
1509 if (copy_from_user(str, buffer, count))
Patrick Mocheld550d982006-06-27 00:41:40 -04001510 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001511
1512 str[count] = 0;
1513 opt = strtoul(str, NULL, 0);
1514 if (opt > 7)
Patrick Mocheld550d982006-06-27 00:41:40 -04001515 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001516
Len Brown4be44fc2005-08-05 00:44:28 -04001517 status = acpi_video_bus_DOS(video, opt & 0x3, (opt & 0x4) >> 2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001518
1519 if (!ACPI_SUCCESS(status))
Patrick Mocheld550d982006-06-27 00:41:40 -04001520 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001521
Patrick Mocheld550d982006-06-27 00:41:40 -04001522 return count;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001523}
1524
Len Brown4be44fc2005-08-05 00:44:28 -04001525static int acpi_video_bus_add_fs(struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001526{
Dmitry Torokhov251cb0b2007-11-05 11:43:34 -05001527 struct acpi_video_bus *video = acpi_driver_data(device);
1528 struct proc_dir_entry *device_dir;
1529 struct proc_dir_entry *entry;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001530
Dmitry Torokhov251cb0b2007-11-05 11:43:34 -05001531 device_dir = proc_mkdir(acpi_device_bid(device), acpi_video_dir);
1532 if (!device_dir)
1533 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001534
Linus Torvalds1da177e2005-04-16 15:20:36 -07001535 /* 'info' [R] */
Alexey Dobriyane0066c4e2008-05-01 04:10:02 +04001536 entry = proc_create_data("info", S_IRUGO, device_dir,
Denis V. Lunevcf7acfa2008-04-29 01:02:27 -07001537 &acpi_video_bus_info_fops,
1538 acpi_driver_data(device));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001539 if (!entry)
Dmitry Torokhov251cb0b2007-11-05 11:43:34 -05001540 goto err_remove_dir;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001541
1542 /* 'ROM' [R] */
Alexey Dobriyane0066c4e2008-05-01 04:10:02 +04001543 entry = proc_create_data("ROM", S_IRUGO, device_dir,
Denis V. Lunevcf7acfa2008-04-29 01:02:27 -07001544 &acpi_video_bus_ROM_fops,
1545 acpi_driver_data(device));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001546 if (!entry)
Dmitry Torokhov251cb0b2007-11-05 11:43:34 -05001547 goto err_remove_info;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001548
1549 /* 'POST_info' [R] */
Alexey Dobriyane0066c4e2008-05-01 04:10:02 +04001550 entry = proc_create_data("POST_info", S_IRUGO, device_dir,
Denis V. Lunevcf7acfa2008-04-29 01:02:27 -07001551 &acpi_video_bus_POST_info_fops,
1552 acpi_driver_data(device));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001553 if (!entry)
Dmitry Torokhov251cb0b2007-11-05 11:43:34 -05001554 goto err_remove_rom;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001555
1556 /* 'POST' [R/W] */
Linus Torvalds08acd4f2008-04-30 11:52:52 -07001557 entry = proc_create_data("POST", S_IFREG | S_IRUGO | S_IWUSR,
Alexey Dobriyane0066c4e2008-05-01 04:10:02 +04001558 device_dir,
Denis V. Lunevcf7acfa2008-04-29 01:02:27 -07001559 &acpi_video_bus_POST_fops,
1560 acpi_driver_data(device));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001561 if (!entry)
Dmitry Torokhov251cb0b2007-11-05 11:43:34 -05001562 goto err_remove_post_info;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001563
1564 /* 'DOS' [R/W] */
Linus Torvalds08acd4f2008-04-30 11:52:52 -07001565 entry = proc_create_data("DOS", S_IFREG | S_IRUGO | S_IWUSR,
Alexey Dobriyane0066c4e2008-05-01 04:10:02 +04001566 device_dir,
Denis V. Lunevcf7acfa2008-04-29 01:02:27 -07001567 &acpi_video_bus_DOS_fops,
1568 acpi_driver_data(device));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001569 if (!entry)
Dmitry Torokhov251cb0b2007-11-05 11:43:34 -05001570 goto err_remove_post;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001571
Dmitry Torokhov251cb0b2007-11-05 11:43:34 -05001572 video->dir = acpi_device_dir(device) = device_dir;
Patrick Mocheld550d982006-06-27 00:41:40 -04001573 return 0;
Dmitry Torokhov251cb0b2007-11-05 11:43:34 -05001574
1575 err_remove_post:
1576 remove_proc_entry("POST", device_dir);
1577 err_remove_post_info:
1578 remove_proc_entry("POST_info", device_dir);
1579 err_remove_rom:
1580 remove_proc_entry("ROM", device_dir);
1581 err_remove_info:
1582 remove_proc_entry("info", device_dir);
1583 err_remove_dir:
1584 remove_proc_entry(acpi_device_bid(device), acpi_video_dir);
1585 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001586}
1587
Len Brown4be44fc2005-08-05 00:44:28 -04001588static int acpi_video_bus_remove_fs(struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001589{
Dmitry Torokhov251cb0b2007-11-05 11:43:34 -05001590 struct proc_dir_entry *device_dir = acpi_device_dir(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001591
Dmitry Torokhov251cb0b2007-11-05 11:43:34 -05001592 if (device_dir) {
1593 remove_proc_entry("info", device_dir);
1594 remove_proc_entry("ROM", device_dir);
1595 remove_proc_entry("POST_info", device_dir);
1596 remove_proc_entry("POST", device_dir);
1597 remove_proc_entry("DOS", device_dir);
Len Brown4be44fc2005-08-05 00:44:28 -04001598 remove_proc_entry(acpi_device_bid(device), acpi_video_dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001599 acpi_device_dir(device) = NULL;
1600 }
1601
Patrick Mocheld550d982006-06-27 00:41:40 -04001602 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001603}
1604
1605/* --------------------------------------------------------------------------
1606 Driver Interface
1607 -------------------------------------------------------------------------- */
1608
1609/* device interface */
Rui Zhang82cae992007-01-03 23:40:53 -05001610static struct acpi_video_device_attrib*
1611acpi_video_get_device_attr(struct acpi_video_bus *video, unsigned long device_id)
1612{
Dmitry Torokhov78eed022007-11-05 11:43:33 -05001613 struct acpi_video_enumerated_device *ids;
1614 int i;
Rui Zhang82cae992007-01-03 23:40:53 -05001615
Dmitry Torokhov78eed022007-11-05 11:43:33 -05001616 for (i = 0; i < video->attached_count; i++) {
1617 ids = &video->attached_array[i];
1618 if ((ids->value.int_val & 0xffff) == device_id)
1619 return &ids->value.attrib;
1620 }
1621
Rui Zhang82cae992007-01-03 23:40:53 -05001622 return NULL;
1623}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001624
1625static int
Len Brown4be44fc2005-08-05 00:44:28 -04001626acpi_video_bus_get_one_device(struct acpi_device *device,
1627 struct acpi_video_bus *video)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001628{
Matthew Wilcox27663c52008-10-10 02:22:59 -04001629 unsigned long long device_id;
Yu, Luming973bf492006-04-27 05:25:00 -04001630 int status;
Len Brown4be44fc2005-08-05 00:44:28 -04001631 struct acpi_video_device *data;
Rui Zhang82cae992007-01-03 23:40:53 -05001632 struct acpi_video_device_attrib* attribute;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001633
1634 if (!device || !video)
Patrick Mocheld550d982006-06-27 00:41:40 -04001635 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001636
Len Brown4be44fc2005-08-05 00:44:28 -04001637 status =
1638 acpi_evaluate_integer(device->handle, "_ADR", NULL, &device_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001639 if (ACPI_SUCCESS(status)) {
1640
Burman Yan36bcbec2006-12-19 12:56:11 -08001641 data = kzalloc(sizeof(struct acpi_video_device), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001642 if (!data)
Patrick Mocheld550d982006-06-27 00:41:40 -04001643 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001644
Linus Torvalds1da177e2005-04-16 15:20:36 -07001645 strcpy(acpi_device_name(device), ACPI_VIDEO_DEVICE_NAME);
1646 strcpy(acpi_device_class(device), ACPI_VIDEO_CLASS);
Pavel Machekdb89b4f2008-09-22 14:37:34 -07001647 device->driver_data = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001648
1649 data->device_id = device_id;
1650 data->video = video;
1651 data->dev = device;
1652
Rui Zhang82cae992007-01-03 23:40:53 -05001653 attribute = acpi_video_get_device_attr(video, device_id);
1654
1655 if((attribute != NULL) && attribute->device_id_scheme) {
1656 switch (attribute->display_type) {
1657 case ACPI_VIDEO_DISPLAY_CRT:
1658 data->flags.crt = 1;
1659 break;
1660 case ACPI_VIDEO_DISPLAY_TV:
1661 data->flags.tvout = 1;
1662 break;
1663 case ACPI_VIDEO_DISPLAY_DVI:
1664 data->flags.dvi = 1;
1665 break;
1666 case ACPI_VIDEO_DISPLAY_LCD:
1667 data->flags.lcd = 1;
1668 break;
1669 default:
1670 data->flags.unknown = 1;
1671 break;
1672 }
1673 if(attribute->bios_can_detect)
1674 data->flags.bios = 1;
1675 } else
Linus Torvalds1da177e2005-04-16 15:20:36 -07001676 data->flags.unknown = 1;
Len Brown4be44fc2005-08-05 00:44:28 -04001677
Linus Torvalds1da177e2005-04-16 15:20:36 -07001678 acpi_video_device_bind(video, data);
1679 acpi_video_device_find_cap(data);
1680
Patrick Mochel90130262006-05-19 16:54:48 -04001681 status = acpi_install_notify_handler(device->handle,
Len Brown4be44fc2005-08-05 00:44:28 -04001682 ACPI_DEVICE_NOTIFY,
1683 acpi_video_device_notify,
1684 data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001685 if (ACPI_FAILURE(status)) {
Lin Ming55ac9a02008-09-28 14:51:56 +08001686 printk(KERN_ERR PREFIX
1687 "Error installing notify handler\n");
Yu, Luming973bf492006-04-27 05:25:00 -04001688 if(data->brightness)
1689 kfree(data->brightness->levels);
1690 kfree(data->brightness);
1691 kfree(data);
1692 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001693 }
1694
Dmitry Torokhovbbac81f2007-11-05 11:43:32 -05001695 mutex_lock(&video->device_list_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001696 list_add_tail(&data->entry, &video->video_device_list);
Dmitry Torokhovbbac81f2007-11-05 11:43:32 -05001697 mutex_unlock(&video->device_list_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001698
1699 acpi_video_device_add_fs(device);
1700
Patrick Mocheld550d982006-06-27 00:41:40 -04001701 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001702 }
1703
Patrick Mocheld550d982006-06-27 00:41:40 -04001704 return -ENOENT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001705}
1706
1707/*
1708 * Arg:
1709 * video : video bus device
1710 *
1711 * Return:
1712 * none
1713 *
1714 * Enumerate the video device list of the video bus,
1715 * bind the ids with the corresponding video devices
1716 * under the video bus.
Len Brown4be44fc2005-08-05 00:44:28 -04001717 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001718
Len Brown4be44fc2005-08-05 00:44:28 -04001719static void acpi_video_device_rebind(struct acpi_video_bus *video)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001720{
Dmitry Torokhovff102ea2007-11-05 11:43:31 -05001721 struct acpi_video_device *dev;
1722
Dmitry Torokhovbbac81f2007-11-05 11:43:32 -05001723 mutex_lock(&video->device_list_lock);
Dmitry Torokhovff102ea2007-11-05 11:43:31 -05001724
1725 list_for_each_entry(dev, &video->video_device_list, entry)
Len Brown4be44fc2005-08-05 00:44:28 -04001726 acpi_video_device_bind(video, dev);
Dmitry Torokhovff102ea2007-11-05 11:43:31 -05001727
Dmitry Torokhovbbac81f2007-11-05 11:43:32 -05001728 mutex_unlock(&video->device_list_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001729}
1730
1731/*
1732 * Arg:
1733 * video : video bus device
1734 * device : video output device under the video
1735 * bus
1736 *
1737 * Return:
1738 * none
1739 *
1740 * Bind the ids with the corresponding video devices
1741 * under the video bus.
Len Brown4be44fc2005-08-05 00:44:28 -04001742 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001743
1744static void
Len Brown4be44fc2005-08-05 00:44:28 -04001745acpi_video_device_bind(struct acpi_video_bus *video,
1746 struct acpi_video_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001747{
Dmitry Torokhov78eed022007-11-05 11:43:33 -05001748 struct acpi_video_enumerated_device *ids;
Len Brown4be44fc2005-08-05 00:44:28 -04001749 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001750
Dmitry Torokhov78eed022007-11-05 11:43:33 -05001751 for (i = 0; i < video->attached_count; i++) {
1752 ids = &video->attached_array[i];
1753 if (device->device_id == (ids->value.int_val & 0xffff)) {
1754 ids->bind_info = device;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001755 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "device_bind %d\n", i));
1756 }
1757 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001758}
1759
1760/*
1761 * Arg:
1762 * video : video bus device
1763 *
1764 * Return:
1765 * < 0 : error
1766 *
1767 * Call _DOD to enumerate all devices attached to display adapter
1768 *
Len Brown4be44fc2005-08-05 00:44:28 -04001769 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001770
1771static int acpi_video_device_enumerate(struct acpi_video_bus *video)
1772{
Len Brown4be44fc2005-08-05 00:44:28 -04001773 int status;
1774 int count;
1775 int i;
Dmitry Torokhov78eed022007-11-05 11:43:33 -05001776 struct acpi_video_enumerated_device *active_list;
Len Brown4be44fc2005-08-05 00:44:28 -04001777 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
1778 union acpi_object *dod = NULL;
1779 union acpi_object *obj;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001780
Patrick Mochel90130262006-05-19 16:54:48 -04001781 status = acpi_evaluate_object(video->device->handle, "_DOD", NULL, &buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001782 if (!ACPI_SUCCESS(status)) {
Thomas Renningera6fc6722006-06-26 23:58:43 -04001783 ACPI_EXCEPTION((AE_INFO, status, "Evaluating _DOD"));
Patrick Mocheld550d982006-06-27 00:41:40 -04001784 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001785 }
1786
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001787 dod = buffer.pointer;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001788 if (!dod || (dod->type != ACPI_TYPE_PACKAGE)) {
Thomas Renningera6fc6722006-06-26 23:58:43 -04001789 ACPI_EXCEPTION((AE_INFO, status, "Invalid _DOD data"));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001790 status = -EFAULT;
1791 goto out;
1792 }
1793
1794 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found %d video heads in _DOD\n",
Len Brown4be44fc2005-08-05 00:44:28 -04001795 dod->package.count));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001796
Dmitry Torokhov78eed022007-11-05 11:43:33 -05001797 active_list = kcalloc(1 + dod->package.count,
1798 sizeof(struct acpi_video_enumerated_device),
1799 GFP_KERNEL);
1800 if (!active_list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001801 status = -ENOMEM;
1802 goto out;
1803 }
1804
1805 count = 0;
1806 for (i = 0; i < dod->package.count; i++) {
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001807 obj = &dod->package.elements[i];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001808
1809 if (obj->type != ACPI_TYPE_INTEGER) {
Dmitry Torokhov78eed022007-11-05 11:43:33 -05001810 printk(KERN_ERR PREFIX
1811 "Invalid _DOD data in element %d\n", i);
1812 continue;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001813 }
Dmitry Torokhov78eed022007-11-05 11:43:33 -05001814
1815 active_list[count].value.int_val = obj->integer.value;
1816 active_list[count].bind_info = NULL;
Len Brown4be44fc2005-08-05 00:44:28 -04001817 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "dod element[%d] = %d\n", i,
1818 (int)obj->integer.value));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001819 count++;
1820 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001821
Jesper Juhl6044ec82005-11-07 01:01:32 -08001822 kfree(video->attached_array);
Len Brown4be44fc2005-08-05 00:44:28 -04001823
Dmitry Torokhov78eed022007-11-05 11:43:33 -05001824 video->attached_array = active_list;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001825 video->attached_count = count;
Dmitry Torokhov78eed022007-11-05 11:43:33 -05001826
1827 out:
Len Brown02438d82006-06-30 03:19:10 -04001828 kfree(buffer.pointer);
Patrick Mocheld550d982006-06-27 00:41:40 -04001829 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001830}
1831
Len Brown4be44fc2005-08-05 00:44:28 -04001832static int
1833acpi_video_get_next_level(struct acpi_video_device *device,
1834 u32 level_current, u32 event)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001835{
Alexey Starikovskiy63f0edf2007-09-03 16:30:08 +04001836 int min, max, min_above, max_below, i, l, delta = 255;
Thomas Tuttlef4715182006-12-19 12:56:14 -08001837 max = max_below = 0;
1838 min = min_above = 255;
Alexey Starikovskiy63f0edf2007-09-03 16:30:08 +04001839 /* Find closest level to level_current */
Zhao Yakui0a3db1c2009-02-02 11:33:41 +08001840 for (i = 2; i < device->brightness->count; i++) {
Alexey Starikovskiy63f0edf2007-09-03 16:30:08 +04001841 l = device->brightness->levels[i];
1842 if (abs(l - level_current) < abs(delta)) {
1843 delta = l - level_current;
1844 if (!delta)
1845 break;
1846 }
1847 }
1848 /* Ajust level_current to closest available level */
1849 level_current += delta;
Zhao Yakui0a3db1c2009-02-02 11:33:41 +08001850 for (i = 2; i < device->brightness->count; i++) {
Thomas Tuttlef4715182006-12-19 12:56:14 -08001851 l = device->brightness->levels[i];
1852 if (l < min)
1853 min = l;
1854 if (l > max)
1855 max = l;
1856 if (l < min_above && l > level_current)
1857 min_above = l;
1858 if (l > max_below && l < level_current)
1859 max_below = l;
1860 }
1861
1862 switch (event) {
1863 case ACPI_VIDEO_NOTIFY_CYCLE_BRIGHTNESS:
1864 return (level_current < max) ? min_above : min;
1865 case ACPI_VIDEO_NOTIFY_INC_BRIGHTNESS:
1866 return (level_current < max) ? min_above : max;
1867 case ACPI_VIDEO_NOTIFY_DEC_BRIGHTNESS:
1868 return (level_current > min) ? max_below : min;
1869 case ACPI_VIDEO_NOTIFY_ZERO_BRIGHTNESS:
1870 case ACPI_VIDEO_NOTIFY_DISPLAY_OFF:
1871 return 0;
1872 default:
1873 return level_current;
1874 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001875}
1876
Zhang Ruic8890f92009-03-18 16:27:08 +08001877static int
Len Brown4be44fc2005-08-05 00:44:28 -04001878acpi_video_switch_brightness(struct acpi_video_device *device, int event)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001879{
Matthew Wilcox27663c52008-10-10 02:22:59 -04001880 unsigned long long level_current, level_next;
Zhang Ruic8890f92009-03-18 16:27:08 +08001881 int result = -EINVAL;
1882
Julia Jomantaite469778c2008-06-23 22:50:42 +01001883 if (!device->brightness)
Zhang Ruic8890f92009-03-18 16:27:08 +08001884 goto out;
1885
1886 result = acpi_video_device_lcd_get_level_current(device,
1887 &level_current);
1888 if (result)
1889 goto out;
1890
Linus Torvalds1da177e2005-04-16 15:20:36 -07001891 level_next = acpi_video_get_next_level(device, level_current, event);
Zhang Ruic8890f92009-03-18 16:27:08 +08001892
Zhang Rui24450c72009-03-18 16:27:10 +08001893 result = acpi_video_device_lcd_set_level(device, level_next);
Zhang Ruic8890f92009-03-18 16:27:08 +08001894
1895out:
1896 if (result)
1897 printk(KERN_ERR PREFIX "Failed to switch the brightness\n");
1898
1899 return result;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001900}
1901
1902static int
Len Brown4be44fc2005-08-05 00:44:28 -04001903acpi_video_bus_get_devices(struct acpi_video_bus *video,
1904 struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001905{
Len Brown4be44fc2005-08-05 00:44:28 -04001906 int status = 0;
Dmitry Torokhovff102ea2007-11-05 11:43:31 -05001907 struct acpi_device *dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001908
1909 acpi_video_device_enumerate(video);
1910
Dmitry Torokhovff102ea2007-11-05 11:43:31 -05001911 list_for_each_entry(dev, &device->children, node) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001912
1913 status = acpi_video_bus_get_one_device(dev, video);
1914 if (ACPI_FAILURE(status)) {
Lin Ming55ac9a02008-09-28 14:51:56 +08001915 printk(KERN_WARNING PREFIX
1916 "Cant attach device");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001917 continue;
1918 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001919 }
Patrick Mocheld550d982006-06-27 00:41:40 -04001920 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001921}
1922
Len Brown4be44fc2005-08-05 00:44:28 -04001923static int acpi_video_bus_put_one_device(struct acpi_video_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001924{
Karol Kozimor031ec772005-07-30 04:18:00 -04001925 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001926 struct acpi_video_bus *video;
1927
Linus Torvalds1da177e2005-04-16 15:20:36 -07001928
1929 if (!device || !device->video)
Patrick Mocheld550d982006-06-27 00:41:40 -04001930 return -ENOENT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001931
1932 video = device->video;
1933
Linus Torvalds1da177e2005-04-16 15:20:36 -07001934 acpi_video_device_remove_fs(device->dev);
1935
Patrick Mochel90130262006-05-19 16:54:48 -04001936 status = acpi_remove_notify_handler(device->dev->handle,
Len Brown4be44fc2005-08-05 00:44:28 -04001937 ACPI_DEVICE_NOTIFY,
1938 acpi_video_device_notify);
Richard Purdie599a52d2007-02-10 23:07:48 +00001939 backlight_device_unregister(device->backlight);
Zhang Rui702ed512008-01-17 15:51:22 +08001940 if (device->cdev) {
1941 sysfs_remove_link(&device->dev->dev.kobj,
1942 "thermal_cooling");
1943 sysfs_remove_link(&device->cdev->device.kobj,
1944 "device");
1945 thermal_cooling_device_unregister(device->cdev);
1946 device->cdev = NULL;
1947 }
Luming Yu23b0f012007-05-09 21:07:05 +08001948 video_output_unregister(device->output_dev);
Dmitry Torokhovff102ea2007-11-05 11:43:31 -05001949
Patrick Mocheld550d982006-06-27 00:41:40 -04001950 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001951}
1952
Len Brown4be44fc2005-08-05 00:44:28 -04001953static int acpi_video_bus_put_devices(struct acpi_video_bus *video)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001954{
Len Brown4be44fc2005-08-05 00:44:28 -04001955 int status;
Dmitry Torokhovff102ea2007-11-05 11:43:31 -05001956 struct acpi_video_device *dev, *next;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001957
Dmitry Torokhovbbac81f2007-11-05 11:43:32 -05001958 mutex_lock(&video->device_list_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001959
Dmitry Torokhovff102ea2007-11-05 11:43:31 -05001960 list_for_each_entry_safe(dev, next, &video->video_device_list, entry) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001961
Dmitry Torokhovff102ea2007-11-05 11:43:31 -05001962 status = acpi_video_bus_put_one_device(dev);
Len Brown4be44fc2005-08-05 00:44:28 -04001963 if (ACPI_FAILURE(status))
1964 printk(KERN_WARNING PREFIX
1965 "hhuuhhuu bug in acpi video driver.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001966
Dmitry Torokhovff102ea2007-11-05 11:43:31 -05001967 if (dev->brightness) {
1968 kfree(dev->brightness->levels);
1969 kfree(dev->brightness);
1970 }
1971 list_del(&dev->entry);
1972 kfree(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001973 }
1974
Dmitry Torokhovbbac81f2007-11-05 11:43:32 -05001975 mutex_unlock(&video->device_list_lock);
Dmitry Torokhovff102ea2007-11-05 11:43:31 -05001976
Patrick Mocheld550d982006-06-27 00:41:40 -04001977 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001978}
1979
1980/* acpi_video interface */
1981
Len Brown4be44fc2005-08-05 00:44:28 -04001982static int acpi_video_bus_start_devices(struct acpi_video_bus *video)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001983{
Zhang Ruia21101c2007-09-14 11:46:22 +08001984 return acpi_video_bus_DOS(video, 0, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001985}
1986
Len Brown4be44fc2005-08-05 00:44:28 -04001987static int acpi_video_bus_stop_devices(struct acpi_video_bus *video)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001988{
1989 return acpi_video_bus_DOS(video, 0, 1);
1990}
1991
Bjorn Helgaas70155582009-04-07 15:37:11 +00001992static void acpi_video_bus_notify(struct acpi_device *device, u32 event)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001993{
Bjorn Helgaas70155582009-04-07 15:37:11 +00001994 struct acpi_video_bus *video = acpi_driver_data(device);
Luming Yue9dab192007-08-20 18:23:53 +08001995 struct input_dev *input;
1996 int keycode;
1997
Linus Torvalds1da177e2005-04-16 15:20:36 -07001998 if (!video)
Patrick Mocheld550d982006-06-27 00:41:40 -04001999 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002000
Luming Yue9dab192007-08-20 18:23:53 +08002001 input = video->input;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002002
2003 switch (event) {
Julius Volz98fb8fe2007-02-20 16:38:40 +01002004 case ACPI_VIDEO_NOTIFY_SWITCH: /* User requested a switch,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002005 * most likely via hotkey. */
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
Julius Volz98fb8fe2007-02-20 16:38:40 +01002010 case ACPI_VIDEO_NOTIFY_PROBE: /* User plugged in or removed a video
Linus Torvalds1da177e2005-04-16 15:20:36 -07002011 * connector. */
2012 acpi_video_device_enumerate(video);
2013 acpi_video_device_rebind(video);
Len Brown14e04fb2007-08-23 15:20:26 -04002014 acpi_bus_generate_proc_event(device, event, 0);
Luming Yue9dab192007-08-20 18:23:53 +08002015 keycode = KEY_SWITCHVIDEOMODE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002016 break;
2017
Len Brown4be44fc2005-08-05 00:44:28 -04002018 case ACPI_VIDEO_NOTIFY_CYCLE: /* Cycle Display output hotkey pressed. */
Len Brown25c87f72007-08-25 01:44:01 -04002019 acpi_bus_generate_proc_event(device, event, 0);
Luming Yue9dab192007-08-20 18:23:53 +08002020 keycode = KEY_SWITCHVIDEOMODE;
2021 break;
Len Brown4be44fc2005-08-05 00:44:28 -04002022 case ACPI_VIDEO_NOTIFY_NEXT_OUTPUT: /* Next Display output hotkey pressed. */
Len Brown25c87f72007-08-25 01:44:01 -04002023 acpi_bus_generate_proc_event(device, event, 0);
Luming Yue9dab192007-08-20 18:23:53 +08002024 keycode = KEY_VIDEO_NEXT;
2025 break;
Len Brown4be44fc2005-08-05 00:44:28 -04002026 case ACPI_VIDEO_NOTIFY_PREV_OUTPUT: /* previous Display output hotkey pressed. */
Len Brown14e04fb2007-08-23 15:20:26 -04002027 acpi_bus_generate_proc_event(device, event, 0);
Luming Yue9dab192007-08-20 18:23:53 +08002028 keycode = KEY_VIDEO_PREV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002029 break;
2030
2031 default:
Luming Yue9dab192007-08-20 18:23:53 +08002032 keycode = KEY_UNKNOWN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002033 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
Len Brown4be44fc2005-08-05 00:44:28 -04002034 "Unsupported event [0x%x]\n", event));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002035 break;
2036 }
2037
Zhang Rui7761f632008-01-25 14:48:12 +08002038 acpi_notifier_call_chain(device, event, 0);
Luming Yue9dab192007-08-20 18:23:53 +08002039 input_report_key(input, keycode, 1);
2040 input_sync(input);
2041 input_report_key(input, keycode, 0);
2042 input_sync(input);
2043
Patrick Mocheld550d982006-06-27 00:41:40 -04002044 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002045}
2046
Len Brown4be44fc2005-08-05 00:44:28 -04002047static void acpi_video_device_notify(acpi_handle handle, u32 event, void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002048{
Jan Engelhardt50dd0962006-10-01 00:28:50 +02002049 struct acpi_video_device *video_device = data;
Len Brown4be44fc2005-08-05 00:44:28 -04002050 struct acpi_device *device = NULL;
Luming Yue9dab192007-08-20 18:23:53 +08002051 struct acpi_video_bus *bus;
2052 struct input_dev *input;
2053 int keycode;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002054
Linus Torvalds1da177e2005-04-16 15:20:36 -07002055 if (!video_device)
Patrick Mocheld550d982006-06-27 00:41:40 -04002056 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002057
Patrick Mochele6afa0d2006-05-19 16:54:40 -04002058 device = video_device->dev;
Luming Yue9dab192007-08-20 18:23:53 +08002059 bus = video_device->video;
2060 input = bus->input;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002061
2062 switch (event) {
Len Brown4be44fc2005-08-05 00:44:28 -04002063 case ACPI_VIDEO_NOTIFY_CYCLE_BRIGHTNESS: /* Cycle brightness */
Zhang Rui8a681a42008-01-25 14:47:49 +08002064 if (brightness_switch_enabled)
2065 acpi_video_switch_brightness(video_device, event);
Len Brown25c87f72007-08-25 01:44:01 -04002066 acpi_bus_generate_proc_event(device, event, 0);
Luming Yue9dab192007-08-20 18:23:53 +08002067 keycode = KEY_BRIGHTNESS_CYCLE;
2068 break;
Len Brown4be44fc2005-08-05 00:44:28 -04002069 case ACPI_VIDEO_NOTIFY_INC_BRIGHTNESS: /* Increase brightness */
Zhang Rui8a681a42008-01-25 14:47:49 +08002070 if (brightness_switch_enabled)
2071 acpi_video_switch_brightness(video_device, event);
Len Brown25c87f72007-08-25 01:44:01 -04002072 acpi_bus_generate_proc_event(device, event, 0);
Luming Yue9dab192007-08-20 18:23:53 +08002073 keycode = KEY_BRIGHTNESSUP;
2074 break;
Len Brown4be44fc2005-08-05 00:44:28 -04002075 case ACPI_VIDEO_NOTIFY_DEC_BRIGHTNESS: /* Decrease brightness */
Zhang Rui8a681a42008-01-25 14:47:49 +08002076 if (brightness_switch_enabled)
2077 acpi_video_switch_brightness(video_device, event);
Len Brown25c87f72007-08-25 01:44:01 -04002078 acpi_bus_generate_proc_event(device, event, 0);
Luming Yue9dab192007-08-20 18:23:53 +08002079 keycode = KEY_BRIGHTNESSDOWN;
2080 break;
Len Brown4be44fc2005-08-05 00:44:28 -04002081 case ACPI_VIDEO_NOTIFY_ZERO_BRIGHTNESS: /* zero brightnesss */
Zhang Rui8a681a42008-01-25 14:47:49 +08002082 if (brightness_switch_enabled)
2083 acpi_video_switch_brightness(video_device, event);
Len Brown25c87f72007-08-25 01:44:01 -04002084 acpi_bus_generate_proc_event(device, event, 0);
Luming Yue9dab192007-08-20 18:23:53 +08002085 keycode = KEY_BRIGHTNESS_ZERO;
2086 break;
Len Brown4be44fc2005-08-05 00:44:28 -04002087 case ACPI_VIDEO_NOTIFY_DISPLAY_OFF: /* display device off */
Zhang Rui8a681a42008-01-25 14:47:49 +08002088 if (brightness_switch_enabled)
2089 acpi_video_switch_brightness(video_device, event);
Len Brown14e04fb2007-08-23 15:20:26 -04002090 acpi_bus_generate_proc_event(device, event, 0);
Luming Yue9dab192007-08-20 18:23:53 +08002091 keycode = KEY_DISPLAY_OFF;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002092 break;
2093 default:
Luming Yue9dab192007-08-20 18:23:53 +08002094 keycode = KEY_UNKNOWN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002095 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
Len Brown4be44fc2005-08-05 00:44:28 -04002096 "Unsupported event [0x%x]\n", event));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002097 break;
2098 }
Luming Yue9dab192007-08-20 18:23:53 +08002099
Zhang Rui7761f632008-01-25 14:48:12 +08002100 acpi_notifier_call_chain(device, event, 0);
Luming Yue9dab192007-08-20 18:23:53 +08002101 input_report_key(input, keycode, 1);
2102 input_sync(input);
2103 input_report_key(input, keycode, 0);
2104 input_sync(input);
2105
Patrick Mocheld550d982006-06-27 00:41:40 -04002106 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002107}
2108
Zhang Ruie6d9da12007-08-25 02:23:31 -04002109static int instance;
Matthew Garrett863c1492008-02-04 23:31:24 -08002110static int acpi_video_resume(struct acpi_device *device)
2111{
2112 struct acpi_video_bus *video;
2113 struct acpi_video_device *video_device;
2114 int i;
2115
2116 if (!device || !acpi_driver_data(device))
2117 return -EINVAL;
2118
2119 video = acpi_driver_data(device);
2120
2121 for (i = 0; i < video->attached_count; i++) {
2122 video_device = video->attached_array[i].bind_info;
2123 if (video_device && video_device->backlight)
2124 acpi_video_set_brightness(video_device->backlight);
2125 }
2126 return AE_OK;
2127}
2128
Len Brown4be44fc2005-08-05 00:44:28 -04002129static int acpi_video_bus_add(struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002130{
Dmitry Torokhovf51e8392007-11-05 11:43:30 -05002131 struct acpi_video_bus *video;
Luming Yue9dab192007-08-20 18:23:53 +08002132 struct input_dev *input;
Dmitry Torokhovf51e8392007-11-05 11:43:30 -05002133 int error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002134
Burman Yan36bcbec2006-12-19 12:56:11 -08002135 video = kzalloc(sizeof(struct acpi_video_bus), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002136 if (!video)
Patrick Mocheld550d982006-06-27 00:41:40 -04002137 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002138
Zhang Ruie6d9da12007-08-25 02:23:31 -04002139 /* a hack to fix the duplicate name "VID" problem on T61 */
2140 if (!strcmp(device->pnp.bus_id, "VID")) {
2141 if (instance)
2142 device->pnp.bus_id[3] = '0' + instance;
2143 instance ++;
2144 }
Zhao Yakuif3b39f12009-02-02 22:55:01 -05002145 /* a hack to fix the duplicate name "VGA" problem on Pa 3553 */
2146 if (!strcmp(device->pnp.bus_id, "VGA")) {
2147 if (instance)
2148 device->pnp.bus_id[3] = '0' + instance;
2149 instance++;
2150 }
Zhang Ruie6d9da12007-08-25 02:23:31 -04002151
Patrick Mochele6afa0d2006-05-19 16:54:40 -04002152 video->device = device;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002153 strcpy(acpi_device_name(device), ACPI_VIDEO_BUS_NAME);
2154 strcpy(acpi_device_class(device), ACPI_VIDEO_CLASS);
Pavel Machekdb89b4f2008-09-22 14:37:34 -07002155 device->driver_data = video;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002156
2157 acpi_video_bus_find_cap(video);
Dmitry Torokhovf51e8392007-11-05 11:43:30 -05002158 error = acpi_video_bus_check(video);
2159 if (error)
2160 goto err_free_video;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002161
Dmitry Torokhovf51e8392007-11-05 11:43:30 -05002162 error = acpi_video_bus_add_fs(device);
2163 if (error)
2164 goto err_free_video;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002165
Dmitry Torokhovbbac81f2007-11-05 11:43:32 -05002166 mutex_init(&video->device_list_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002167 INIT_LIST_HEAD(&video->video_device_list);
2168
2169 acpi_video_bus_get_devices(video, device);
2170 acpi_video_bus_start_devices(video);
2171
Luming Yue9dab192007-08-20 18:23:53 +08002172 video->input = input = input_allocate_device();
Dmitry Torokhovf51e8392007-11-05 11:43:30 -05002173 if (!input) {
2174 error = -ENOMEM;
Bjorn Helgaas70155582009-04-07 15:37:11 +00002175 goto err_stop_video;
Dmitry Torokhovf51e8392007-11-05 11:43:30 -05002176 }
Luming Yue9dab192007-08-20 18:23:53 +08002177
2178 snprintf(video->phys, sizeof(video->phys),
2179 "%s/video/input0", acpi_device_hid(video->device));
2180
2181 input->name = acpi_device_name(video->device);
2182 input->phys = video->phys;
2183 input->id.bustype = BUS_HOST;
2184 input->id.product = 0x06;
Dmitry Torokhov91c05c62007-11-05 11:43:29 -05002185 input->dev.parent = &device->dev;
Luming Yue9dab192007-08-20 18:23:53 +08002186 input->evbit[0] = BIT(EV_KEY);
2187 set_bit(KEY_SWITCHVIDEOMODE, input->keybit);
2188 set_bit(KEY_VIDEO_NEXT, input->keybit);
2189 set_bit(KEY_VIDEO_PREV, input->keybit);
2190 set_bit(KEY_BRIGHTNESS_CYCLE, input->keybit);
2191 set_bit(KEY_BRIGHTNESSUP, input->keybit);
2192 set_bit(KEY_BRIGHTNESSDOWN, input->keybit);
2193 set_bit(KEY_BRIGHTNESS_ZERO, input->keybit);
2194 set_bit(KEY_DISPLAY_OFF, input->keybit);
2195 set_bit(KEY_UNKNOWN, input->keybit);
Luming Yue9dab192007-08-20 18:23:53 +08002196
Dmitry Torokhovf51e8392007-11-05 11:43:30 -05002197 error = input_register_device(input);
2198 if (error)
2199 goto err_free_input_dev;
Luming Yue9dab192007-08-20 18:23:53 +08002200
Linus Torvalds1da177e2005-04-16 15:20:36 -07002201 printk(KERN_INFO PREFIX "%s [%s] (multi-head: %s rom: %s post: %s)\n",
Len Brown4be44fc2005-08-05 00:44:28 -04002202 ACPI_VIDEO_DEVICE_NAME, acpi_device_bid(device),
2203 video->flags.multihead ? "yes" : "no",
2204 video->flags.rom ? "yes" : "no",
2205 video->flags.post ? "yes" : "no");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002206
Dmitry Torokhovf51e8392007-11-05 11:43:30 -05002207 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002208
Dmitry Torokhovf51e8392007-11-05 11:43:30 -05002209 err_free_input_dev:
2210 input_free_device(input);
Dmitry Torokhovf51e8392007-11-05 11:43:30 -05002211 err_stop_video:
2212 acpi_video_bus_stop_devices(video);
2213 acpi_video_bus_put_devices(video);
2214 kfree(video->attached_array);
2215 acpi_video_bus_remove_fs(device);
2216 err_free_video:
2217 kfree(video);
Pavel Machekdb89b4f2008-09-22 14:37:34 -07002218 device->driver_data = NULL;
Dmitry Torokhovf51e8392007-11-05 11:43:30 -05002219
2220 return error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002221}
2222
Len Brown4be44fc2005-08-05 00:44:28 -04002223static int acpi_video_bus_remove(struct acpi_device *device, int type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002224{
Len Brown4be44fc2005-08-05 00:44:28 -04002225 struct acpi_video_bus *video = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002226
Linus Torvalds1da177e2005-04-16 15:20:36 -07002227
2228 if (!device || !acpi_driver_data(device))
Patrick Mocheld550d982006-06-27 00:41:40 -04002229 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002230
Jan Engelhardt50dd0962006-10-01 00:28:50 +02002231 video = acpi_driver_data(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002232
2233 acpi_video_bus_stop_devices(video);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002234 acpi_video_bus_put_devices(video);
2235 acpi_video_bus_remove_fs(device);
2236
Luming Yue9dab192007-08-20 18:23:53 +08002237 input_unregister_device(video->input);
Jesper Juhl6044ec82005-11-07 01:01:32 -08002238 kfree(video->attached_array);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002239 kfree(video);
2240
Patrick Mocheld550d982006-06-27 00:41:40 -04002241 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002242}
2243
Matthew Garrett74a365b2009-03-19 21:35:39 +00002244static int __init intel_opregion_present(void)
2245{
2246#if defined(CONFIG_DRM_I915) || defined(CONFIG_DRM_I915_MODULE)
2247 struct pci_dev *dev = NULL;
2248 u32 address;
2249
2250 for_each_pci_dev(dev) {
2251 if ((dev->class >> 8) != PCI_CLASS_DISPLAY_VGA)
2252 continue;
2253 if (dev->vendor != PCI_VENDOR_ID_INTEL)
2254 continue;
2255 pci_read_config_dword(dev, 0xfc, &address);
2256 if (!address)
2257 continue;
2258 return 1;
2259 }
2260#endif
2261 return 0;
2262}
2263
2264int acpi_video_register(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002265{
Len Brown4be44fc2005-08-05 00:44:28 -04002266 int result = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002267
Linus Torvalds1da177e2005-04-16 15:20:36 -07002268 acpi_video_dir = proc_mkdir(ACPI_VIDEO_CLASS, acpi_root_dir);
2269 if (!acpi_video_dir)
Patrick Mocheld550d982006-06-27 00:41:40 -04002270 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002271
2272 result = acpi_bus_register_driver(&acpi_video_bus);
2273 if (result < 0) {
2274 remove_proc_entry(ACPI_VIDEO_CLASS, acpi_root_dir);
Patrick Mocheld550d982006-06-27 00:41:40 -04002275 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002276 }
2277
Patrick Mocheld550d982006-06-27 00:41:40 -04002278 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002279}
Matthew Garrett74a365b2009-03-19 21:35:39 +00002280EXPORT_SYMBOL(acpi_video_register);
2281
2282/*
2283 * This is kind of nasty. Hardware using Intel chipsets may require
2284 * the video opregion code to be run first in order to initialise
2285 * state before any ACPI video calls are made. To handle this we defer
2286 * registration of the video class until the opregion code has run.
2287 */
2288
2289static int __init acpi_video_init(void)
2290{
2291 if (intel_opregion_present())
2292 return 0;
2293
2294 return acpi_video_register();
2295}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002296
Len Brown4be44fc2005-08-05 00:44:28 -04002297static void __exit acpi_video_exit(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002298{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002299
2300 acpi_bus_unregister_driver(&acpi_video_bus);
2301
2302 remove_proc_entry(ACPI_VIDEO_CLASS, acpi_root_dir);
2303
Patrick Mocheld550d982006-06-27 00:41:40 -04002304 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002305}
2306
2307module_init(acpi_video_init);
2308module_exit(acpi_video_exit);