blob: 21968ae6ed91add7b1fb23493606457caf35bc49 [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 Brownc2b67052007-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 */
Zhang Rui90af2cf2009-04-14 11:02:18 +0800773 for (i = 2; i < count; i++) {
774 if (br->levels[i] == br->levels[0])
Zhang Ruid32f6942009-03-18 16:27:12 +0800775 level_ac_battery++;
Zhang Rui90af2cf2009-04-14 11:02:18 +0800776 if (br->levels[i] == br->levels[1])
777 level_ac_battery++;
778 }
Zhang Rui935e5f22008-12-11 16:24:52 -0500779
Zhang Ruid32f6942009-03-18 16:27:12 +0800780 if (level_ac_battery < 2) {
781 level_ac_battery = 2 - level_ac_battery;
782 br->flags._BCL_no_ac_battery_levels = 1;
783 for (i = (count - 1 + level_ac_battery); i >= 2; i--)
784 br->levels[i] = br->levels[i - level_ac_battery];
785 count += level_ac_battery;
786 } else if (level_ac_battery > 2)
787 ACPI_ERROR((AE_INFO, "Too many duplicates in _BCL package\n"));
788
Zhang Ruid80fb992009-03-18 16:27:14 +0800789 /* Check if the _BCL package is in a reversed order */
790 if (max_level == br->levels[2]) {
791 br->flags._BCL_reversed = 1;
792 sort(&br->levels[2], count - 2, sizeof(br->levels[2]),
793 acpi_video_cmp_level, NULL);
794 } else if (max_level != br->levels[count - 1])
795 ACPI_ERROR((AE_INFO,
796 "Found unordered _BCL package\n"));
Julia Jomantaite469778c2008-06-23 22:50:42 +0100797
798 br->count = count;
799 device->brightness = br;
Zhang Rui1a7c6182009-03-18 16:27:16 +0800800
801 /* Check the input/output of _BQC/_BCL/_BCM */
802 if ((max_level < 100) && (max_level <= (count - 2)))
803 br->flags._BCL_use_index = 1;
804
805 /*
806 * _BCM is always consistent with _BCL,
807 * at least for all the laptops we have ever seen.
808 */
809 br->flags._BCM_use_index = br->flags._BCL_use_index;
810
811 /* _BQC uses INDEX while _BCL uses VALUE in some laptops */
812 br->curr = max_level;
813 result = acpi_video_device_lcd_get_level_current(device, &level_old);
814 if (result)
815 goto out_free_levels;
816
817 result = acpi_video_device_lcd_set_level(device, br->curr);
818 if (result)
819 goto out_free_levels;
820
821 result = acpi_video_device_lcd_get_level_current(device, &level);
822 if (result)
823 goto out_free_levels;
824
825 if ((level != level_old) && !br->flags._BCM_use_index) {
826 /* Note:
827 * This piece of code does not work correctly if the current
828 * brightness levels is 0.
829 * But I guess boxes that boot with such a dark screen are rare
830 * and no more code is needed to cover this specifial case.
831 */
832
833 if (level_ac_battery != 2) {
834 /*
835 * For now, we don't support the _BCL like this:
836 * 16, 15, 0, 1, 2, 3, ..., 14, 15, 16
837 * because we may mess up the index returned by _BQC.
838 * Plus: we have not got a box like this.
839 */
840 ACPI_ERROR((AE_INFO, "_BCL not supported\n"));
841 }
842 br->flags._BQC_use_index = 1;
843 }
844
Zhang Ruid32f6942009-03-18 16:27:12 +0800845 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
846 "found %d brightness levels\n", count - 2));
Julia Jomantaite469778c2008-06-23 22:50:42 +0100847 kfree(obj);
Zhang Rui1a7c6182009-03-18 16:27:16 +0800848 return result;
Julia Jomantaite469778c2008-06-23 22:50:42 +0100849
850out_free_levels:
851 kfree(br->levels);
852out_free:
853 kfree(br);
854out:
855 device->brightness = NULL;
856 kfree(obj);
Zhang Rui1a7c6182009-03-18 16:27:16 +0800857 return result;
Julia Jomantaite469778c2008-06-23 22:50:42 +0100858}
859
860/*
861 * Arg:
862 * device : video output device (LCD, CRT, ..)
863 *
864 * Return Value:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700865 * None
866 *
Julius Volz98fb8fe2007-02-20 16:38:40 +0100867 * Find out all required AML methods defined under the output
Linus Torvalds1da177e2005-04-16 15:20:36 -0700868 * device.
869 */
870
Len Brown4be44fc2005-08-05 00:44:28 -0400871static void acpi_video_device_find_cap(struct acpi_video_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700872{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700873 acpi_handle h_dummy1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700874
Linus Torvalds1da177e2005-04-16 15:20:36 -0700875
William Lee Irwin III98934de2007-12-12 03:56:55 -0800876 memset(&device->cap, 0, sizeof(device->cap));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700877
Patrick Mochel90130262006-05-19 16:54:48 -0400878 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_ADR", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700879 device->cap._ADR = 1;
880 }
Patrick Mochel90130262006-05-19 16:54:48 -0400881 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_BCL", &h_dummy1))) {
Len Brown4be44fc2005-08-05 00:44:28 -0400882 device->cap._BCL = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700883 }
Patrick Mochel90130262006-05-19 16:54:48 -0400884 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_BCM", &h_dummy1))) {
Len Brown4be44fc2005-08-05 00:44:28 -0400885 device->cap._BCM = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700886 }
Yu Luming2f3d0002006-11-11 02:40:34 +0800887 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle,"_BQC",&h_dummy1)))
888 device->cap._BQC = 1;
Zhang Ruic60d6382009-03-18 16:27:18 +0800889 else if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_BCQ",
890 &h_dummy1))) {
891 printk(KERN_WARNING FW_BUG "_BCQ is used instead of _BQC\n");
892 device->cap._BCQ = 1;
893 }
894
Patrick Mochel90130262006-05-19 16:54:48 -0400895 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_DDC", &h_dummy1))) {
Len Brown4be44fc2005-08-05 00:44:28 -0400896 device->cap._DDC = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700897 }
Patrick Mochel90130262006-05-19 16:54:48 -0400898 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_DCS", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700899 device->cap._DCS = 1;
900 }
Patrick Mochel90130262006-05-19 16:54:48 -0400901 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_DGS", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700902 device->cap._DGS = 1;
903 }
Patrick Mochel90130262006-05-19 16:54:48 -0400904 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_DSS", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700905 device->cap._DSS = 1;
906 }
907
Zhang Rui1a7c6182009-03-18 16:27:16 +0800908 if (acpi_video_backlight_support()) {
Zhang Rui702ed512008-01-17 15:51:22 +0800909 int result;
Yu Luming2f3d0002006-11-11 02:40:34 +0800910 static int count = 0;
911 char *name;
Zhang Rui1a7c6182009-03-18 16:27:16 +0800912
913 result = acpi_video_init_brightness(device);
914 if (result)
915 return;
Yu Luming2f3d0002006-11-11 02:40:34 +0800916 name = kzalloc(MAX_NAME_LEN, GFP_KERNEL);
917 if (!name)
918 return;
919
Yu Luming2f3d0002006-11-11 02:40:34 +0800920 sprintf(name, "acpi_video%d", count++);
Yu Luming2f3d0002006-11-11 02:40:34 +0800921 device->backlight = backlight_device_register(name,
Richard Purdie599a52d2007-02-10 23:07:48 +0000922 NULL, device, &acpi_backlight_ops);
Matthew Garrett38531e62007-12-26 02:03:26 +0000923 device->backlight->props.max_brightness = device->brightness->count-3;
Yu Luming2f3d0002006-11-11 02:40:34 +0800924 kfree(name);
Zhang Rui702ed512008-01-17 15:51:22 +0800925
926 device->cdev = thermal_cooling_device_register("LCD",
927 device->dev, &video_cooling_ops);
Thomas Sujith43ff39f2008-02-15 18:29:18 -0500928 if (IS_ERR(device->cdev))
929 return;
930
Greg Kroah-Hartmanfc3a8822008-05-02 06:02:41 +0200931 dev_info(&device->dev->dev, "registered as cooling_device%d\n",
932 device->cdev->id);
Julia Lawall90300622008-04-11 10:09:24 +0800933 result = sysfs_create_link(&device->dev->dev.kobj,
934 &device->cdev->device.kobj,
935 "thermal_cooling");
936 if (result)
937 printk(KERN_ERR PREFIX "Create sysfs link\n");
938 result = sysfs_create_link(&device->cdev->device.kobj,
939 &device->dev->dev.kobj, "device");
940 if (result)
941 printk(KERN_ERR PREFIX "Create sysfs link\n");
942
Yu Luming2f3d0002006-11-11 02:40:34 +0800943 }
Thomas Renningerc3d6de62008-08-01 17:37:55 +0200944
945 if (acpi_video_display_switch_support()) {
946
947 if (device->cap._DCS && device->cap._DSS) {
948 static int count;
949 char *name;
950 name = kzalloc(MAX_NAME_LEN, GFP_KERNEL);
951 if (!name)
952 return;
953 sprintf(name, "acpi_video%d", count++);
954 device->output_dev = video_output_register(name,
955 NULL, device, &acpi_output_properties);
956 kfree(name);
957 }
Luming Yu23b0f012007-05-09 21:07:05 +0800958 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700959}
960
961/*
962 * Arg:
963 * device : video output device (VGA)
964 *
965 * Return Value:
966 * None
967 *
Julius Volz98fb8fe2007-02-20 16:38:40 +0100968 * Find out all required AML methods defined under the video bus device.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700969 */
970
Len Brown4be44fc2005-08-05 00:44:28 -0400971static void acpi_video_bus_find_cap(struct acpi_video_bus *video)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700972{
Len Brown4be44fc2005-08-05 00:44:28 -0400973 acpi_handle h_dummy1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700974
William Lee Irwin III98934de2007-12-12 03:56:55 -0800975 memset(&video->cap, 0, sizeof(video->cap));
Patrick Mochel90130262006-05-19 16:54:48 -0400976 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_DOS", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700977 video->cap._DOS = 1;
978 }
Patrick Mochel90130262006-05-19 16:54:48 -0400979 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_DOD", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700980 video->cap._DOD = 1;
981 }
Patrick Mochel90130262006-05-19 16:54:48 -0400982 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_ROM", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700983 video->cap._ROM = 1;
984 }
Patrick Mochel90130262006-05-19 16:54:48 -0400985 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_GPD", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700986 video->cap._GPD = 1;
987 }
Patrick Mochel90130262006-05-19 16:54:48 -0400988 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_SPD", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700989 video->cap._SPD = 1;
990 }
Patrick Mochel90130262006-05-19 16:54:48 -0400991 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_VPO", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700992 video->cap._VPO = 1;
993 }
994}
995
996/*
997 * Check whether the video bus device has required AML method to
998 * support the desired features
999 */
1000
Len Brown4be44fc2005-08-05 00:44:28 -04001001static int acpi_video_bus_check(struct acpi_video_bus *video)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001002{
Len Brown4be44fc2005-08-05 00:44:28 -04001003 acpi_status status = -ENOENT;
Thomas Renninger22c13f92008-08-01 17:37:54 +02001004 struct device *dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001005
1006 if (!video)
Patrick Mocheld550d982006-06-27 00:41:40 -04001007 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001008
Thomas Renninger22c13f92008-08-01 17:37:54 +02001009 dev = acpi_get_physical_pci_device(video->device->handle);
1010 if (!dev)
1011 return -ENODEV;
1012 put_device(dev);
1013
Linus Torvalds1da177e2005-04-16 15:20:36 -07001014 /* Since there is no HID, CID and so on for VGA driver, we have
1015 * to check well known required nodes.
1016 */
1017
Julius Volz98fb8fe2007-02-20 16:38:40 +01001018 /* Does this device support video switching? */
Len Brown4be44fc2005-08-05 00:44:28 -04001019 if (video->cap._DOS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001020 video->flags.multihead = 1;
1021 status = 0;
1022 }
1023
Julius Volz98fb8fe2007-02-20 16:38:40 +01001024 /* Does this device support retrieving a video ROM? */
Len Brown4be44fc2005-08-05 00:44:28 -04001025 if (video->cap._ROM) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001026 video->flags.rom = 1;
1027 status = 0;
1028 }
1029
Julius Volz98fb8fe2007-02-20 16:38:40 +01001030 /* Does this device support configuring which video device to POST? */
Len Brown4be44fc2005-08-05 00:44:28 -04001031 if (video->cap._GPD && video->cap._SPD && video->cap._VPO) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001032 video->flags.post = 1;
1033 status = 0;
1034 }
1035
Patrick Mocheld550d982006-06-27 00:41:40 -04001036 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001037}
1038
1039/* --------------------------------------------------------------------------
1040 FS Interface (/proc)
1041 -------------------------------------------------------------------------- */
1042
Len Brown4be44fc2005-08-05 00:44:28 -04001043static struct proc_dir_entry *acpi_video_dir;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001044
1045/* video devices */
1046
Len Brown4be44fc2005-08-05 00:44:28 -04001047static int acpi_video_device_info_seq_show(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001048{
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001049 struct acpi_video_device *dev = seq->private;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001050
Linus Torvalds1da177e2005-04-16 15:20:36 -07001051
1052 if (!dev)
1053 goto end;
1054
1055 seq_printf(seq, "device_id: 0x%04x\n", (u32) dev->device_id);
1056 seq_printf(seq, "type: ");
1057 if (dev->flags.crt)
1058 seq_printf(seq, "CRT\n");
1059 else if (dev->flags.lcd)
1060 seq_printf(seq, "LCD\n");
1061 else if (dev->flags.tvout)
1062 seq_printf(seq, "TVOUT\n");
Rui Zhang82cae992007-01-03 23:40:53 -05001063 else if (dev->flags.dvi)
1064 seq_printf(seq, "DVI\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001065 else
1066 seq_printf(seq, "UNKNOWN\n");
1067
Len Brown4be44fc2005-08-05 00:44:28 -04001068 seq_printf(seq, "known by bios: %s\n", dev->flags.bios ? "yes" : "no");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001069
Len Brown4be44fc2005-08-05 00:44:28 -04001070 end:
Patrick Mocheld550d982006-06-27 00:41:40 -04001071 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001072}
1073
1074static int
Len Brown4be44fc2005-08-05 00:44:28 -04001075acpi_video_device_info_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001076{
1077 return single_open(file, acpi_video_device_info_seq_show,
1078 PDE(inode)->data);
1079}
1080
Len Brown4be44fc2005-08-05 00:44:28 -04001081static int acpi_video_device_state_seq_show(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001082{
Len Brown4be44fc2005-08-05 00:44:28 -04001083 int status;
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001084 struct acpi_video_device *dev = seq->private;
Matthew Wilcox27663c52008-10-10 02:22:59 -04001085 unsigned long long state;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001086
Linus Torvalds1da177e2005-04-16 15:20:36 -07001087
1088 if (!dev)
1089 goto end;
1090
1091 status = acpi_video_device_get_state(dev, &state);
1092 seq_printf(seq, "state: ");
1093 if (ACPI_SUCCESS(status))
Matthew Wilcox27663c52008-10-10 02:22:59 -04001094 seq_printf(seq, "0x%02llx\n", state);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001095 else
1096 seq_printf(seq, "<not supported>\n");
1097
1098 status = acpi_video_device_query(dev, &state);
1099 seq_printf(seq, "query: ");
1100 if (ACPI_SUCCESS(status))
Matthew Wilcox27663c52008-10-10 02:22:59 -04001101 seq_printf(seq, "0x%02llx\n", state);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001102 else
1103 seq_printf(seq, "<not supported>\n");
1104
Len Brown4be44fc2005-08-05 00:44:28 -04001105 end:
Patrick Mocheld550d982006-06-27 00:41:40 -04001106 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001107}
1108
1109static int
Len Brown4be44fc2005-08-05 00:44:28 -04001110acpi_video_device_state_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001111{
1112 return single_open(file, acpi_video_device_state_seq_show,
1113 PDE(inode)->data);
1114}
1115
1116static ssize_t
Len Brown4be44fc2005-08-05 00:44:28 -04001117acpi_video_device_write_state(struct file *file,
1118 const char __user * buffer,
1119 size_t count, loff_t * data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001120{
Len Brown4be44fc2005-08-05 00:44:28 -04001121 int status;
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001122 struct seq_file *m = file->private_data;
1123 struct acpi_video_device *dev = m->private;
Len Brown4be44fc2005-08-05 00:44:28 -04001124 char str[12] = { 0 };
1125 u32 state = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001126
Linus Torvalds1da177e2005-04-16 15:20:36 -07001127
1128 if (!dev || count + 1 > sizeof str)
Patrick Mocheld550d982006-06-27 00:41:40 -04001129 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001130
1131 if (copy_from_user(str, buffer, count))
Patrick Mocheld550d982006-06-27 00:41:40 -04001132 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001133
1134 str[count] = 0;
1135 state = simple_strtoul(str, NULL, 0);
Len Brown4be44fc2005-08-05 00:44:28 -04001136 state &= ((1ul << 31) | (1ul << 30) | (1ul << 0));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001137
1138 status = acpi_video_device_set_state(dev, state);
1139
1140 if (status)
Patrick Mocheld550d982006-06-27 00:41:40 -04001141 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001142
Patrick Mocheld550d982006-06-27 00:41:40 -04001143 return count;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001144}
1145
1146static int
Len Brown4be44fc2005-08-05 00:44:28 -04001147acpi_video_device_brightness_seq_show(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001148{
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001149 struct acpi_video_device *dev = seq->private;
Len Brown4be44fc2005-08-05 00:44:28 -04001150 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001151
Linus Torvalds1da177e2005-04-16 15:20:36 -07001152
1153 if (!dev || !dev->brightness) {
1154 seq_printf(seq, "<not supported>\n");
Patrick Mocheld550d982006-06-27 00:41:40 -04001155 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001156 }
1157
1158 seq_printf(seq, "levels: ");
Zhao Yakui0a3db1c2009-02-02 11:33:41 +08001159 for (i = 2; i < dev->brightness->count; i++)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001160 seq_printf(seq, " %d", dev->brightness->levels[i]);
1161 seq_printf(seq, "\ncurrent: %d\n", dev->brightness->curr);
1162
Patrick Mocheld550d982006-06-27 00:41:40 -04001163 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001164}
1165
1166static int
Len Brown4be44fc2005-08-05 00:44:28 -04001167acpi_video_device_brightness_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001168{
1169 return single_open(file, acpi_video_device_brightness_seq_show,
1170 PDE(inode)->data);
1171}
1172
1173static ssize_t
Len Brown4be44fc2005-08-05 00:44:28 -04001174acpi_video_device_write_brightness(struct file *file,
1175 const char __user * buffer,
1176 size_t count, loff_t * data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001177{
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001178 struct seq_file *m = file->private_data;
1179 struct acpi_video_device *dev = m->private;
Danny Baumannc88c5782007-11-02 13:47:53 +01001180 char str[5] = { 0 };
Len Brown4be44fc2005-08-05 00:44:28 -04001181 unsigned int level = 0;
1182 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001183
Linus Torvalds1da177e2005-04-16 15:20:36 -07001184
Thomas Renninger59d399d2005-11-08 05:27:00 -05001185 if (!dev || !dev->brightness || count + 1 > sizeof str)
Patrick Mocheld550d982006-06-27 00:41:40 -04001186 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001187
1188 if (copy_from_user(str, buffer, count))
Patrick Mocheld550d982006-06-27 00:41:40 -04001189 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001190
1191 str[count] = 0;
1192 level = simple_strtoul(str, NULL, 0);
Len Brown4be44fc2005-08-05 00:44:28 -04001193
Linus Torvalds1da177e2005-04-16 15:20:36 -07001194 if (level > 100)
Patrick Mocheld550d982006-06-27 00:41:40 -04001195 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001196
Julius Volz98fb8fe2007-02-20 16:38:40 +01001197 /* validate through the list of available levels */
Zhao Yakui0a3db1c2009-02-02 11:33:41 +08001198 for (i = 2; i < dev->brightness->count; i++)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001199 if (level == dev->brightness->levels[i]) {
Zhang Rui24450c72009-03-18 16:27:10 +08001200 if (!acpi_video_device_lcd_set_level(dev, level))
1201 return count;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001202 break;
1203 }
1204
Zhang Rui24450c72009-03-18 16:27:10 +08001205 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001206}
1207
Len Brown4be44fc2005-08-05 00:44:28 -04001208static int acpi_video_device_EDID_seq_show(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001209{
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001210 struct acpi_video_device *dev = seq->private;
Len Brown4be44fc2005-08-05 00:44:28 -04001211 int status;
1212 int i;
1213 union acpi_object *edid = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001214
Linus Torvalds1da177e2005-04-16 15:20:36 -07001215
1216 if (!dev)
1217 goto out;
1218
Len Brown4be44fc2005-08-05 00:44:28 -04001219 status = acpi_video_device_EDID(dev, &edid, 128);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001220 if (ACPI_FAILURE(status)) {
Len Brown4be44fc2005-08-05 00:44:28 -04001221 status = acpi_video_device_EDID(dev, &edid, 256);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001222 }
1223
1224 if (ACPI_FAILURE(status)) {
1225 goto out;
1226 }
1227
1228 if (edid && edid->type == ACPI_TYPE_BUFFER) {
1229 for (i = 0; i < edid->buffer.length; i++)
1230 seq_putc(seq, edid->buffer.pointer[i]);
1231 }
1232
Len Brown4be44fc2005-08-05 00:44:28 -04001233 out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001234 if (!edid)
1235 seq_printf(seq, "<not supported>\n");
1236 else
1237 kfree(edid);
1238
Patrick Mocheld550d982006-06-27 00:41:40 -04001239 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001240}
1241
1242static int
Len Brown4be44fc2005-08-05 00:44:28 -04001243acpi_video_device_EDID_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001244{
1245 return single_open(file, acpi_video_device_EDID_seq_show,
1246 PDE(inode)->data);
1247}
1248
Len Brown4be44fc2005-08-05 00:44:28 -04001249static int acpi_video_device_add_fs(struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001250{
Dmitry Torokhov251cb0b2007-11-05 11:43:34 -05001251 struct proc_dir_entry *entry, *device_dir;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001252 struct acpi_video_device *vid_dev;
1253
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001254 vid_dev = acpi_driver_data(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001255 if (!vid_dev)
Patrick Mocheld550d982006-06-27 00:41:40 -04001256 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001257
Dmitry Torokhov251cb0b2007-11-05 11:43:34 -05001258 device_dir = proc_mkdir(acpi_device_bid(device),
1259 vid_dev->video->dir);
1260 if (!device_dir)
1261 return -ENOMEM;
1262
Linus Torvalds1da177e2005-04-16 15:20:36 -07001263 /* 'info' [R] */
Alexey Dobriyane0066c4e2008-05-01 04:10:02 +04001264 entry = proc_create_data("info", S_IRUGO, device_dir,
Denis V. Lunevcf7acfa2008-04-29 01:02:27 -07001265 &acpi_video_device_info_fops, acpi_driver_data(device));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001266 if (!entry)
Dmitry Torokhov251cb0b2007-11-05 11:43:34 -05001267 goto err_remove_dir;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001268
1269 /* 'state' [R/W] */
Denis V. Lunevcf7acfa2008-04-29 01:02:27 -07001270 entry = proc_create_data("state", S_IFREG | S_IRUGO | S_IWUSR,
Alexey Dobriyane0066c4e2008-05-01 04:10:02 +04001271 device_dir,
Denis V. Lunevcf7acfa2008-04-29 01:02:27 -07001272 &acpi_video_device_state_fops,
1273 acpi_driver_data(device));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001274 if (!entry)
Dmitry Torokhov251cb0b2007-11-05 11:43:34 -05001275 goto err_remove_info;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001276
1277 /* 'brightness' [R/W] */
Denis V. Lunevcf7acfa2008-04-29 01:02:27 -07001278 entry = proc_create_data("brightness", S_IFREG | S_IRUGO | S_IWUSR,
Alexey Dobriyane0066c4e2008-05-01 04:10:02 +04001279 device_dir,
Denis V. Lunevcf7acfa2008-04-29 01:02:27 -07001280 &acpi_video_device_brightness_fops,
1281 acpi_driver_data(device));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001282 if (!entry)
Dmitry Torokhov251cb0b2007-11-05 11:43:34 -05001283 goto err_remove_state;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001284
1285 /* 'EDID' [R] */
Alexey Dobriyane0066c4e2008-05-01 04:10:02 +04001286 entry = proc_create_data("EDID", S_IRUGO, device_dir,
Denis V. Lunevcf7acfa2008-04-29 01:02:27 -07001287 &acpi_video_device_EDID_fops,
1288 acpi_driver_data(device));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001289 if (!entry)
Dmitry Torokhov251cb0b2007-11-05 11:43:34 -05001290 goto err_remove_brightness;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001291
Alexey Dobriyane0066c4e2008-05-01 04:10:02 +04001292 acpi_device_dir(device) = device_dir;
1293
Patrick Mocheld550d982006-06-27 00:41:40 -04001294 return 0;
Dmitry Torokhov251cb0b2007-11-05 11:43:34 -05001295
1296 err_remove_brightness:
1297 remove_proc_entry("brightness", device_dir);
1298 err_remove_state:
1299 remove_proc_entry("state", device_dir);
1300 err_remove_info:
1301 remove_proc_entry("info", device_dir);
1302 err_remove_dir:
1303 remove_proc_entry(acpi_device_bid(device), vid_dev->video->dir);
1304 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001305}
1306
Len Brown4be44fc2005-08-05 00:44:28 -04001307static int acpi_video_device_remove_fs(struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001308{
1309 struct acpi_video_device *vid_dev;
Dmitry Torokhov251cb0b2007-11-05 11:43:34 -05001310 struct proc_dir_entry *device_dir;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001311
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001312 vid_dev = acpi_driver_data(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001313 if (!vid_dev || !vid_dev->video || !vid_dev->video->dir)
Patrick Mocheld550d982006-06-27 00:41:40 -04001314 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001315
Dmitry Torokhov251cb0b2007-11-05 11:43:34 -05001316 device_dir = acpi_device_dir(device);
1317 if (device_dir) {
1318 remove_proc_entry("info", device_dir);
1319 remove_proc_entry("state", device_dir);
1320 remove_proc_entry("brightness", device_dir);
1321 remove_proc_entry("EDID", device_dir);
Len Brown4be44fc2005-08-05 00:44:28 -04001322 remove_proc_entry(acpi_device_bid(device), vid_dev->video->dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001323 acpi_device_dir(device) = NULL;
1324 }
1325
Patrick Mocheld550d982006-06-27 00:41:40 -04001326 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001327}
1328
Linus Torvalds1da177e2005-04-16 15:20:36 -07001329/* video bus */
Len Brown4be44fc2005-08-05 00:44:28 -04001330static int acpi_video_bus_info_seq_show(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001331{
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001332 struct acpi_video_bus *video = seq->private;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001333
Linus Torvalds1da177e2005-04-16 15:20:36 -07001334
1335 if (!video)
1336 goto end;
1337
1338 seq_printf(seq, "Switching heads: %s\n",
Len Brown4be44fc2005-08-05 00:44:28 -04001339 video->flags.multihead ? "yes" : "no");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001340 seq_printf(seq, "Video ROM: %s\n",
Len Brown4be44fc2005-08-05 00:44:28 -04001341 video->flags.rom ? "yes" : "no");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001342 seq_printf(seq, "Device to be POSTed on boot: %s\n",
Len Brown4be44fc2005-08-05 00:44:28 -04001343 video->flags.post ? "yes" : "no");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001344
Len Brown4be44fc2005-08-05 00:44:28 -04001345 end:
Patrick Mocheld550d982006-06-27 00:41:40 -04001346 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001347}
1348
Len Brown4be44fc2005-08-05 00:44:28 -04001349static int acpi_video_bus_info_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001350{
Len Brown4be44fc2005-08-05 00:44:28 -04001351 return single_open(file, acpi_video_bus_info_seq_show,
1352 PDE(inode)->data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001353}
1354
Len Brown4be44fc2005-08-05 00:44:28 -04001355static int acpi_video_bus_ROM_seq_show(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001356{
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001357 struct acpi_video_bus *video = seq->private;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001358
Linus Torvalds1da177e2005-04-16 15:20:36 -07001359
1360 if (!video)
1361 goto end;
1362
Harvey Harrison96b2dd12008-03-05 18:24:51 -08001363 printk(KERN_INFO PREFIX "Please implement %s\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001364 seq_printf(seq, "<TODO>\n");
1365
Len Brown4be44fc2005-08-05 00:44:28 -04001366 end:
Patrick Mocheld550d982006-06-27 00:41:40 -04001367 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001368}
1369
Len Brown4be44fc2005-08-05 00:44:28 -04001370static int acpi_video_bus_ROM_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001371{
1372 return single_open(file, acpi_video_bus_ROM_seq_show, PDE(inode)->data);
1373}
1374
Len Brown4be44fc2005-08-05 00:44:28 -04001375static int acpi_video_bus_POST_info_seq_show(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001376{
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001377 struct acpi_video_bus *video = seq->private;
Matthew Wilcox27663c52008-10-10 02:22:59 -04001378 unsigned long long options;
Len Brown4be44fc2005-08-05 00:44:28 -04001379 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001380
Linus Torvalds1da177e2005-04-16 15:20:36 -07001381
1382 if (!video)
1383 goto end;
1384
1385 status = acpi_video_bus_POST_options(video, &options);
1386 if (ACPI_SUCCESS(status)) {
1387 if (!(options & 1)) {
Len Brown4be44fc2005-08-05 00:44:28 -04001388 printk(KERN_WARNING PREFIX
1389 "The motherboard VGA device is not listed as a possible POST device.\n");
1390 printk(KERN_WARNING PREFIX
Julius Volz98fb8fe2007-02-20 16:38:40 +01001391 "This indicates a BIOS bug. Please contact the manufacturer.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001392 }
Frank Seidel4d939152009-02-04 17:03:07 +01001393 printk(KERN_WARNING "%llx\n", options);
Julius Volz98fb8fe2007-02-20 16:38:40 +01001394 seq_printf(seq, "can POST: <integrated video>");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001395 if (options & 2)
1396 seq_printf(seq, " <PCI video>");
1397 if (options & 4)
1398 seq_printf(seq, " <AGP video>");
1399 seq_putc(seq, '\n');
1400 } else
1401 seq_printf(seq, "<not supported>\n");
Len Brown4be44fc2005-08-05 00:44:28 -04001402 end:
Patrick Mocheld550d982006-06-27 00:41:40 -04001403 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001404}
1405
1406static int
Len Brown4be44fc2005-08-05 00:44:28 -04001407acpi_video_bus_POST_info_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001408{
Len Brown4be44fc2005-08-05 00:44:28 -04001409 return single_open(file, acpi_video_bus_POST_info_seq_show,
1410 PDE(inode)->data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001411}
1412
Len Brown4be44fc2005-08-05 00:44:28 -04001413static int acpi_video_bus_POST_seq_show(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001414{
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001415 struct acpi_video_bus *video = seq->private;
Len Brown4be44fc2005-08-05 00:44:28 -04001416 int status;
Matthew Wilcox27663c52008-10-10 02:22:59 -04001417 unsigned long long id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001418
Linus Torvalds1da177e2005-04-16 15:20:36 -07001419
1420 if (!video)
1421 goto end;
1422
Len Brown4be44fc2005-08-05 00:44:28 -04001423 status = acpi_video_bus_get_POST(video, &id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001424 if (!ACPI_SUCCESS(status)) {
1425 seq_printf(seq, "<not supported>\n");
1426 goto end;
1427 }
Julius Volz98fb8fe2007-02-20 16:38:40 +01001428 seq_printf(seq, "device POSTed is <%s>\n", device_decode[id & 3]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001429
Len Brown4be44fc2005-08-05 00:44:28 -04001430 end:
Patrick Mocheld550d982006-06-27 00:41:40 -04001431 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001432}
1433
Len Brown4be44fc2005-08-05 00:44:28 -04001434static int acpi_video_bus_DOS_seq_show(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001435{
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001436 struct acpi_video_bus *video = seq->private;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001437
Linus Torvalds1da177e2005-04-16 15:20:36 -07001438
Len Brown4be44fc2005-08-05 00:44:28 -04001439 seq_printf(seq, "DOS setting: <%d>\n", video->dos_setting);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001440
Patrick Mocheld550d982006-06-27 00:41:40 -04001441 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001442}
1443
Len Brown4be44fc2005-08-05 00:44:28 -04001444static int acpi_video_bus_POST_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001445{
Len Brown4be44fc2005-08-05 00:44:28 -04001446 return single_open(file, acpi_video_bus_POST_seq_show,
1447 PDE(inode)->data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001448}
1449
Len Brown4be44fc2005-08-05 00:44:28 -04001450static int acpi_video_bus_DOS_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001451{
1452 return single_open(file, acpi_video_bus_DOS_seq_show, PDE(inode)->data);
1453}
1454
1455static ssize_t
Len Brown4be44fc2005-08-05 00:44:28 -04001456acpi_video_bus_write_POST(struct file *file,
1457 const char __user * buffer,
1458 size_t count, loff_t * data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001459{
Len Brown4be44fc2005-08-05 00:44:28 -04001460 int status;
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001461 struct seq_file *m = file->private_data;
1462 struct acpi_video_bus *video = m->private;
Len Brown4be44fc2005-08-05 00:44:28 -04001463 char str[12] = { 0 };
Matthew Wilcox27663c52008-10-10 02:22:59 -04001464 unsigned long long opt, options;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001465
Linus Torvalds1da177e2005-04-16 15:20:36 -07001466
Linus Torvalds1da177e2005-04-16 15:20:36 -07001467 if (!video || count + 1 > sizeof str)
Patrick Mocheld550d982006-06-27 00:41:40 -04001468 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001469
1470 status = acpi_video_bus_POST_options(video, &options);
1471 if (!ACPI_SUCCESS(status))
Patrick Mocheld550d982006-06-27 00:41:40 -04001472 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001473
1474 if (copy_from_user(str, buffer, count))
Patrick Mocheld550d982006-06-27 00:41:40 -04001475 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001476
1477 str[count] = 0;
1478 opt = strtoul(str, NULL, 0);
1479 if (opt > 3)
Patrick Mocheld550d982006-06-27 00:41:40 -04001480 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001481
Julius Volz98fb8fe2007-02-20 16:38:40 +01001482 /* just in case an OEM 'forgot' the motherboard... */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001483 options |= 1;
1484
1485 if (options & (1ul << opt)) {
Len Brown4be44fc2005-08-05 00:44:28 -04001486 status = acpi_video_bus_set_POST(video, opt);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001487 if (!ACPI_SUCCESS(status))
Patrick Mocheld550d982006-06-27 00:41:40 -04001488 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001489
1490 }
1491
Patrick Mocheld550d982006-06-27 00:41:40 -04001492 return count;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001493}
1494
1495static ssize_t
Len Brown4be44fc2005-08-05 00:44:28 -04001496acpi_video_bus_write_DOS(struct file *file,
1497 const char __user * buffer,
1498 size_t count, loff_t * data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001499{
Len Brown4be44fc2005-08-05 00:44:28 -04001500 int status;
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001501 struct seq_file *m = file->private_data;
1502 struct acpi_video_bus *video = m->private;
Len Brown4be44fc2005-08-05 00:44:28 -04001503 char str[12] = { 0 };
1504 unsigned long opt;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001505
Linus Torvalds1da177e2005-04-16 15:20:36 -07001506
Linus Torvalds1da177e2005-04-16 15:20:36 -07001507 if (!video || count + 1 > sizeof str)
Patrick Mocheld550d982006-06-27 00:41:40 -04001508 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001509
1510 if (copy_from_user(str, buffer, count))
Patrick Mocheld550d982006-06-27 00:41:40 -04001511 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001512
1513 str[count] = 0;
1514 opt = strtoul(str, NULL, 0);
1515 if (opt > 7)
Patrick Mocheld550d982006-06-27 00:41:40 -04001516 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001517
Len Brown4be44fc2005-08-05 00:44:28 -04001518 status = acpi_video_bus_DOS(video, opt & 0x3, (opt & 0x4) >> 2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001519
1520 if (!ACPI_SUCCESS(status))
Patrick Mocheld550d982006-06-27 00:41:40 -04001521 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001522
Patrick Mocheld550d982006-06-27 00:41:40 -04001523 return count;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001524}
1525
Len Brown4be44fc2005-08-05 00:44:28 -04001526static int acpi_video_bus_add_fs(struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001527{
Dmitry Torokhov251cb0b2007-11-05 11:43:34 -05001528 struct acpi_video_bus *video = acpi_driver_data(device);
1529 struct proc_dir_entry *device_dir;
1530 struct proc_dir_entry *entry;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001531
Dmitry Torokhov251cb0b2007-11-05 11:43:34 -05001532 device_dir = proc_mkdir(acpi_device_bid(device), acpi_video_dir);
1533 if (!device_dir)
1534 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001535
Linus Torvalds1da177e2005-04-16 15:20:36 -07001536 /* 'info' [R] */
Alexey Dobriyane0066c4e2008-05-01 04:10:02 +04001537 entry = proc_create_data("info", S_IRUGO, device_dir,
Denis V. Lunevcf7acfa2008-04-29 01:02:27 -07001538 &acpi_video_bus_info_fops,
1539 acpi_driver_data(device));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001540 if (!entry)
Dmitry Torokhov251cb0b2007-11-05 11:43:34 -05001541 goto err_remove_dir;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001542
1543 /* 'ROM' [R] */
Alexey Dobriyane0066c4e2008-05-01 04:10:02 +04001544 entry = proc_create_data("ROM", S_IRUGO, device_dir,
Denis V. Lunevcf7acfa2008-04-29 01:02:27 -07001545 &acpi_video_bus_ROM_fops,
1546 acpi_driver_data(device));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001547 if (!entry)
Dmitry Torokhov251cb0b2007-11-05 11:43:34 -05001548 goto err_remove_info;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001549
1550 /* 'POST_info' [R] */
Alexey Dobriyane0066c4e2008-05-01 04:10:02 +04001551 entry = proc_create_data("POST_info", S_IRUGO, device_dir,
Denis V. Lunevcf7acfa2008-04-29 01:02:27 -07001552 &acpi_video_bus_POST_info_fops,
1553 acpi_driver_data(device));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001554 if (!entry)
Dmitry Torokhov251cb0b2007-11-05 11:43:34 -05001555 goto err_remove_rom;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001556
1557 /* 'POST' [R/W] */
Linus Torvalds08acd4f82008-04-30 11:52:52 -07001558 entry = proc_create_data("POST", S_IFREG | S_IRUGO | S_IWUSR,
Alexey Dobriyane0066c4e2008-05-01 04:10:02 +04001559 device_dir,
Denis V. Lunevcf7acfa2008-04-29 01:02:27 -07001560 &acpi_video_bus_POST_fops,
1561 acpi_driver_data(device));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001562 if (!entry)
Dmitry Torokhov251cb0b2007-11-05 11:43:34 -05001563 goto err_remove_post_info;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001564
1565 /* 'DOS' [R/W] */
Linus Torvalds08acd4f82008-04-30 11:52:52 -07001566 entry = proc_create_data("DOS", S_IFREG | S_IRUGO | S_IWUSR,
Alexey Dobriyane0066c4e2008-05-01 04:10:02 +04001567 device_dir,
Denis V. Lunevcf7acfa2008-04-29 01:02:27 -07001568 &acpi_video_bus_DOS_fops,
1569 acpi_driver_data(device));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001570 if (!entry)
Dmitry Torokhov251cb0b2007-11-05 11:43:34 -05001571 goto err_remove_post;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001572
Dmitry Torokhov251cb0b2007-11-05 11:43:34 -05001573 video->dir = acpi_device_dir(device) = device_dir;
Patrick Mocheld550d982006-06-27 00:41:40 -04001574 return 0;
Dmitry Torokhov251cb0b2007-11-05 11:43:34 -05001575
1576 err_remove_post:
1577 remove_proc_entry("POST", device_dir);
1578 err_remove_post_info:
1579 remove_proc_entry("POST_info", device_dir);
1580 err_remove_rom:
1581 remove_proc_entry("ROM", device_dir);
1582 err_remove_info:
1583 remove_proc_entry("info", device_dir);
1584 err_remove_dir:
1585 remove_proc_entry(acpi_device_bid(device), acpi_video_dir);
1586 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001587}
1588
Len Brown4be44fc2005-08-05 00:44:28 -04001589static int acpi_video_bus_remove_fs(struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001590{
Dmitry Torokhov251cb0b2007-11-05 11:43:34 -05001591 struct proc_dir_entry *device_dir = acpi_device_dir(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001592
Dmitry Torokhov251cb0b2007-11-05 11:43:34 -05001593 if (device_dir) {
1594 remove_proc_entry("info", device_dir);
1595 remove_proc_entry("ROM", device_dir);
1596 remove_proc_entry("POST_info", device_dir);
1597 remove_proc_entry("POST", device_dir);
1598 remove_proc_entry("DOS", device_dir);
Len Brown4be44fc2005-08-05 00:44:28 -04001599 remove_proc_entry(acpi_device_bid(device), acpi_video_dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001600 acpi_device_dir(device) = NULL;
1601 }
1602
Patrick Mocheld550d982006-06-27 00:41:40 -04001603 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001604}
1605
1606/* --------------------------------------------------------------------------
1607 Driver Interface
1608 -------------------------------------------------------------------------- */
1609
1610/* device interface */
Rui Zhang82cae992007-01-03 23:40:53 -05001611static struct acpi_video_device_attrib*
1612acpi_video_get_device_attr(struct acpi_video_bus *video, unsigned long device_id)
1613{
Dmitry Torokhov78eed022007-11-05 11:43:33 -05001614 struct acpi_video_enumerated_device *ids;
1615 int i;
Rui Zhang82cae992007-01-03 23:40:53 -05001616
Dmitry Torokhov78eed022007-11-05 11:43:33 -05001617 for (i = 0; i < video->attached_count; i++) {
1618 ids = &video->attached_array[i];
1619 if ((ids->value.int_val & 0xffff) == device_id)
1620 return &ids->value.attrib;
1621 }
1622
Rui Zhang82cae992007-01-03 23:40:53 -05001623 return NULL;
1624}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001625
1626static int
Len Brown4be44fc2005-08-05 00:44:28 -04001627acpi_video_bus_get_one_device(struct acpi_device *device,
1628 struct acpi_video_bus *video)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001629{
Matthew Wilcox27663c52008-10-10 02:22:59 -04001630 unsigned long long device_id;
Yu, Luming973bf492006-04-27 05:25:00 -04001631 int status;
Len Brown4be44fc2005-08-05 00:44:28 -04001632 struct acpi_video_device *data;
Rui Zhang82cae992007-01-03 23:40:53 -05001633 struct acpi_video_device_attrib* attribute;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001634
1635 if (!device || !video)
Patrick Mocheld550d982006-06-27 00:41:40 -04001636 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001637
Len Brown4be44fc2005-08-05 00:44:28 -04001638 status =
1639 acpi_evaluate_integer(device->handle, "_ADR", NULL, &device_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001640 if (ACPI_SUCCESS(status)) {
1641
Burman Yan36bcbec2006-12-19 12:56:11 -08001642 data = kzalloc(sizeof(struct acpi_video_device), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001643 if (!data)
Patrick Mocheld550d982006-06-27 00:41:40 -04001644 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001645
Linus Torvalds1da177e2005-04-16 15:20:36 -07001646 strcpy(acpi_device_name(device), ACPI_VIDEO_DEVICE_NAME);
1647 strcpy(acpi_device_class(device), ACPI_VIDEO_CLASS);
Pavel Machekdb89b4f2008-09-22 14:37:34 -07001648 device->driver_data = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001649
1650 data->device_id = device_id;
1651 data->video = video;
1652 data->dev = device;
1653
Rui Zhang82cae992007-01-03 23:40:53 -05001654 attribute = acpi_video_get_device_attr(video, device_id);
1655
1656 if((attribute != NULL) && attribute->device_id_scheme) {
1657 switch (attribute->display_type) {
1658 case ACPI_VIDEO_DISPLAY_CRT:
1659 data->flags.crt = 1;
1660 break;
1661 case ACPI_VIDEO_DISPLAY_TV:
1662 data->flags.tvout = 1;
1663 break;
1664 case ACPI_VIDEO_DISPLAY_DVI:
1665 data->flags.dvi = 1;
1666 break;
1667 case ACPI_VIDEO_DISPLAY_LCD:
1668 data->flags.lcd = 1;
1669 break;
1670 default:
1671 data->flags.unknown = 1;
1672 break;
1673 }
1674 if(attribute->bios_can_detect)
1675 data->flags.bios = 1;
1676 } else
Linus Torvalds1da177e2005-04-16 15:20:36 -07001677 data->flags.unknown = 1;
Len Brown4be44fc2005-08-05 00:44:28 -04001678
Linus Torvalds1da177e2005-04-16 15:20:36 -07001679 acpi_video_device_bind(video, data);
1680 acpi_video_device_find_cap(data);
1681
Patrick Mochel90130262006-05-19 16:54:48 -04001682 status = acpi_install_notify_handler(device->handle,
Len Brown4be44fc2005-08-05 00:44:28 -04001683 ACPI_DEVICE_NOTIFY,
1684 acpi_video_device_notify,
1685 data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001686 if (ACPI_FAILURE(status)) {
Lin Ming55ac9a02008-09-28 14:51:56 +08001687 printk(KERN_ERR PREFIX
1688 "Error installing notify handler\n");
Yu, Luming973bf492006-04-27 05:25:00 -04001689 if(data->brightness)
1690 kfree(data->brightness->levels);
1691 kfree(data->brightness);
1692 kfree(data);
1693 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001694 }
1695
Dmitry Torokhovbbac81f2007-11-05 11:43:32 -05001696 mutex_lock(&video->device_list_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001697 list_add_tail(&data->entry, &video->video_device_list);
Dmitry Torokhovbbac81f2007-11-05 11:43:32 -05001698 mutex_unlock(&video->device_list_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001699
1700 acpi_video_device_add_fs(device);
1701
Patrick Mocheld550d982006-06-27 00:41:40 -04001702 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001703 }
1704
Patrick Mocheld550d982006-06-27 00:41:40 -04001705 return -ENOENT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001706}
1707
1708/*
1709 * Arg:
1710 * video : video bus device
1711 *
1712 * Return:
1713 * none
1714 *
1715 * Enumerate the video device list of the video bus,
1716 * bind the ids with the corresponding video devices
1717 * under the video bus.
Len Brown4be44fc2005-08-05 00:44:28 -04001718 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001719
Len Brown4be44fc2005-08-05 00:44:28 -04001720static void acpi_video_device_rebind(struct acpi_video_bus *video)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001721{
Dmitry Torokhovff102ea2007-11-05 11:43:31 -05001722 struct acpi_video_device *dev;
1723
Dmitry Torokhovbbac81f2007-11-05 11:43:32 -05001724 mutex_lock(&video->device_list_lock);
Dmitry Torokhovff102ea2007-11-05 11:43:31 -05001725
1726 list_for_each_entry(dev, &video->video_device_list, entry)
Len Brown4be44fc2005-08-05 00:44:28 -04001727 acpi_video_device_bind(video, dev);
Dmitry Torokhovff102ea2007-11-05 11:43:31 -05001728
Dmitry Torokhovbbac81f2007-11-05 11:43:32 -05001729 mutex_unlock(&video->device_list_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001730}
1731
1732/*
1733 * Arg:
1734 * video : video bus device
1735 * device : video output device under the video
1736 * bus
1737 *
1738 * Return:
1739 * none
1740 *
1741 * Bind the ids with the corresponding video devices
1742 * under the video bus.
Len Brown4be44fc2005-08-05 00:44:28 -04001743 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001744
1745static void
Len Brown4be44fc2005-08-05 00:44:28 -04001746acpi_video_device_bind(struct acpi_video_bus *video,
1747 struct acpi_video_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001748{
Dmitry Torokhov78eed022007-11-05 11:43:33 -05001749 struct acpi_video_enumerated_device *ids;
Len Brown4be44fc2005-08-05 00:44:28 -04001750 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001751
Dmitry Torokhov78eed022007-11-05 11:43:33 -05001752 for (i = 0; i < video->attached_count; i++) {
1753 ids = &video->attached_array[i];
1754 if (device->device_id == (ids->value.int_val & 0xffff)) {
1755 ids->bind_info = device;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001756 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "device_bind %d\n", i));
1757 }
1758 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001759}
1760
1761/*
1762 * Arg:
1763 * video : video bus device
1764 *
1765 * Return:
1766 * < 0 : error
1767 *
1768 * Call _DOD to enumerate all devices attached to display adapter
1769 *
Len Brown4be44fc2005-08-05 00:44:28 -04001770 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001771
1772static int acpi_video_device_enumerate(struct acpi_video_bus *video)
1773{
Len Brown4be44fc2005-08-05 00:44:28 -04001774 int status;
1775 int count;
1776 int i;
Dmitry Torokhov78eed022007-11-05 11:43:33 -05001777 struct acpi_video_enumerated_device *active_list;
Len Brown4be44fc2005-08-05 00:44:28 -04001778 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
1779 union acpi_object *dod = NULL;
1780 union acpi_object *obj;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001781
Patrick Mochel90130262006-05-19 16:54:48 -04001782 status = acpi_evaluate_object(video->device->handle, "_DOD", NULL, &buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001783 if (!ACPI_SUCCESS(status)) {
Thomas Renningera6fc6722006-06-26 23:58:43 -04001784 ACPI_EXCEPTION((AE_INFO, status, "Evaluating _DOD"));
Patrick Mocheld550d982006-06-27 00:41:40 -04001785 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001786 }
1787
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001788 dod = buffer.pointer;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001789 if (!dod || (dod->type != ACPI_TYPE_PACKAGE)) {
Thomas Renningera6fc6722006-06-26 23:58:43 -04001790 ACPI_EXCEPTION((AE_INFO, status, "Invalid _DOD data"));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001791 status = -EFAULT;
1792 goto out;
1793 }
1794
1795 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found %d video heads in _DOD\n",
Len Brown4be44fc2005-08-05 00:44:28 -04001796 dod->package.count));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001797
Dmitry Torokhov78eed022007-11-05 11:43:33 -05001798 active_list = kcalloc(1 + dod->package.count,
1799 sizeof(struct acpi_video_enumerated_device),
1800 GFP_KERNEL);
1801 if (!active_list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001802 status = -ENOMEM;
1803 goto out;
1804 }
1805
1806 count = 0;
1807 for (i = 0; i < dod->package.count; i++) {
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001808 obj = &dod->package.elements[i];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001809
1810 if (obj->type != ACPI_TYPE_INTEGER) {
Dmitry Torokhov78eed022007-11-05 11:43:33 -05001811 printk(KERN_ERR PREFIX
1812 "Invalid _DOD data in element %d\n", i);
1813 continue;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001814 }
Dmitry Torokhov78eed022007-11-05 11:43:33 -05001815
1816 active_list[count].value.int_val = obj->integer.value;
1817 active_list[count].bind_info = NULL;
Len Brown4be44fc2005-08-05 00:44:28 -04001818 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "dod element[%d] = %d\n", i,
1819 (int)obj->integer.value));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001820 count++;
1821 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001822
Jesper Juhl6044ec82005-11-07 01:01:32 -08001823 kfree(video->attached_array);
Len Brown4be44fc2005-08-05 00:44:28 -04001824
Dmitry Torokhov78eed022007-11-05 11:43:33 -05001825 video->attached_array = active_list;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001826 video->attached_count = count;
Dmitry Torokhov78eed022007-11-05 11:43:33 -05001827
1828 out:
Len Brown02438d82006-06-30 03:19:10 -04001829 kfree(buffer.pointer);
Patrick Mocheld550d982006-06-27 00:41:40 -04001830 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001831}
1832
Len Brown4be44fc2005-08-05 00:44:28 -04001833static int
1834acpi_video_get_next_level(struct acpi_video_device *device,
1835 u32 level_current, u32 event)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001836{
Alexey Starikovskiy63f0edf2007-09-03 16:30:08 +04001837 int min, max, min_above, max_below, i, l, delta = 255;
Thomas Tuttlef4715182006-12-19 12:56:14 -08001838 max = max_below = 0;
1839 min = min_above = 255;
Alexey Starikovskiy63f0edf2007-09-03 16:30:08 +04001840 /* Find closest level to level_current */
Zhao Yakui0a3db1c2009-02-02 11:33:41 +08001841 for (i = 2; i < device->brightness->count; i++) {
Alexey Starikovskiy63f0edf2007-09-03 16:30:08 +04001842 l = device->brightness->levels[i];
1843 if (abs(l - level_current) < abs(delta)) {
1844 delta = l - level_current;
1845 if (!delta)
1846 break;
1847 }
1848 }
1849 /* Ajust level_current to closest available level */
1850 level_current += delta;
Zhao Yakui0a3db1c2009-02-02 11:33:41 +08001851 for (i = 2; i < device->brightness->count; i++) {
Thomas Tuttlef4715182006-12-19 12:56:14 -08001852 l = device->brightness->levels[i];
1853 if (l < min)
1854 min = l;
1855 if (l > max)
1856 max = l;
1857 if (l < min_above && l > level_current)
1858 min_above = l;
1859 if (l > max_below && l < level_current)
1860 max_below = l;
1861 }
1862
1863 switch (event) {
1864 case ACPI_VIDEO_NOTIFY_CYCLE_BRIGHTNESS:
1865 return (level_current < max) ? min_above : min;
1866 case ACPI_VIDEO_NOTIFY_INC_BRIGHTNESS:
1867 return (level_current < max) ? min_above : max;
1868 case ACPI_VIDEO_NOTIFY_DEC_BRIGHTNESS:
1869 return (level_current > min) ? max_below : min;
1870 case ACPI_VIDEO_NOTIFY_ZERO_BRIGHTNESS:
1871 case ACPI_VIDEO_NOTIFY_DISPLAY_OFF:
1872 return 0;
1873 default:
1874 return level_current;
1875 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001876}
1877
Zhang Ruic8890f92009-03-18 16:27:08 +08001878static int
Len Brown4be44fc2005-08-05 00:44:28 -04001879acpi_video_switch_brightness(struct acpi_video_device *device, int event)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001880{
Matthew Wilcox27663c52008-10-10 02:22:59 -04001881 unsigned long long level_current, level_next;
Zhang Ruic8890f92009-03-18 16:27:08 +08001882 int result = -EINVAL;
1883
Julia Jomantaite469778c2008-06-23 22:50:42 +01001884 if (!device->brightness)
Zhang Ruic8890f92009-03-18 16:27:08 +08001885 goto out;
1886
1887 result = acpi_video_device_lcd_get_level_current(device,
1888 &level_current);
1889 if (result)
1890 goto out;
1891
Linus Torvalds1da177e2005-04-16 15:20:36 -07001892 level_next = acpi_video_get_next_level(device, level_current, event);
Zhang Ruic8890f92009-03-18 16:27:08 +08001893
Zhang Rui24450c72009-03-18 16:27:10 +08001894 result = acpi_video_device_lcd_set_level(device, level_next);
Zhang Ruic8890f92009-03-18 16:27:08 +08001895
1896out:
1897 if (result)
1898 printk(KERN_ERR PREFIX "Failed to switch the brightness\n");
1899
1900 return result;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001901}
1902
1903static int
Len Brown4be44fc2005-08-05 00:44:28 -04001904acpi_video_bus_get_devices(struct acpi_video_bus *video,
1905 struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001906{
Len Brown4be44fc2005-08-05 00:44:28 -04001907 int status = 0;
Dmitry Torokhovff102ea2007-11-05 11:43:31 -05001908 struct acpi_device *dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001909
1910 acpi_video_device_enumerate(video);
1911
Dmitry Torokhovff102ea2007-11-05 11:43:31 -05001912 list_for_each_entry(dev, &device->children, node) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001913
1914 status = acpi_video_bus_get_one_device(dev, video);
1915 if (ACPI_FAILURE(status)) {
Lin Ming55ac9a02008-09-28 14:51:56 +08001916 printk(KERN_WARNING PREFIX
1917 "Cant attach device");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001918 continue;
1919 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001920 }
Patrick Mocheld550d982006-06-27 00:41:40 -04001921 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001922}
1923
Len Brown4be44fc2005-08-05 00:44:28 -04001924static int acpi_video_bus_put_one_device(struct acpi_video_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001925{
Karol Kozimor031ec772005-07-30 04:18:00 -04001926 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001927 struct acpi_video_bus *video;
1928
Linus Torvalds1da177e2005-04-16 15:20:36 -07001929
1930 if (!device || !device->video)
Patrick Mocheld550d982006-06-27 00:41:40 -04001931 return -ENOENT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001932
1933 video = device->video;
1934
Linus Torvalds1da177e2005-04-16 15:20:36 -07001935 acpi_video_device_remove_fs(device->dev);
1936
Patrick Mochel90130262006-05-19 16:54:48 -04001937 status = acpi_remove_notify_handler(device->dev->handle,
Len Brown4be44fc2005-08-05 00:44:28 -04001938 ACPI_DEVICE_NOTIFY,
1939 acpi_video_device_notify);
Richard Purdie599a52d2007-02-10 23:07:48 +00001940 backlight_device_unregister(device->backlight);
Zhang Rui702ed512008-01-17 15:51:22 +08001941 if (device->cdev) {
1942 sysfs_remove_link(&device->dev->dev.kobj,
1943 "thermal_cooling");
1944 sysfs_remove_link(&device->cdev->device.kobj,
1945 "device");
1946 thermal_cooling_device_unregister(device->cdev);
1947 device->cdev = NULL;
1948 }
Luming Yu23b0f012007-05-09 21:07:05 +08001949 video_output_unregister(device->output_dev);
Dmitry Torokhovff102ea2007-11-05 11:43:31 -05001950
Patrick Mocheld550d982006-06-27 00:41:40 -04001951 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001952}
1953
Len Brown4be44fc2005-08-05 00:44:28 -04001954static int acpi_video_bus_put_devices(struct acpi_video_bus *video)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001955{
Len Brown4be44fc2005-08-05 00:44:28 -04001956 int status;
Dmitry Torokhovff102ea2007-11-05 11:43:31 -05001957 struct acpi_video_device *dev, *next;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001958
Dmitry Torokhovbbac81f2007-11-05 11:43:32 -05001959 mutex_lock(&video->device_list_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001960
Dmitry Torokhovff102ea2007-11-05 11:43:31 -05001961 list_for_each_entry_safe(dev, next, &video->video_device_list, entry) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001962
Dmitry Torokhovff102ea2007-11-05 11:43:31 -05001963 status = acpi_video_bus_put_one_device(dev);
Len Brown4be44fc2005-08-05 00:44:28 -04001964 if (ACPI_FAILURE(status))
1965 printk(KERN_WARNING PREFIX
1966 "hhuuhhuu bug in acpi video driver.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001967
Dmitry Torokhovff102ea2007-11-05 11:43:31 -05001968 if (dev->brightness) {
1969 kfree(dev->brightness->levels);
1970 kfree(dev->brightness);
1971 }
1972 list_del(&dev->entry);
1973 kfree(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001974 }
1975
Dmitry Torokhovbbac81f2007-11-05 11:43:32 -05001976 mutex_unlock(&video->device_list_lock);
Dmitry Torokhovff102ea2007-11-05 11:43:31 -05001977
Patrick Mocheld550d982006-06-27 00:41:40 -04001978 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001979}
1980
1981/* acpi_video interface */
1982
Len Brown4be44fc2005-08-05 00:44:28 -04001983static int acpi_video_bus_start_devices(struct acpi_video_bus *video)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001984{
Zhang Ruia21101c2007-09-14 11:46:22 +08001985 return acpi_video_bus_DOS(video, 0, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001986}
1987
Len Brown4be44fc2005-08-05 00:44:28 -04001988static int acpi_video_bus_stop_devices(struct acpi_video_bus *video)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001989{
1990 return acpi_video_bus_DOS(video, 0, 1);
1991}
1992
Bjorn Helgaas70155582009-04-07 15:37:11 +00001993static void acpi_video_bus_notify(struct acpi_device *device, u32 event)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001994{
Bjorn Helgaas70155582009-04-07 15:37:11 +00001995 struct acpi_video_bus *video = acpi_driver_data(device);
Luming Yue9dab192007-08-20 18:23:53 +08001996 struct input_dev *input;
1997 int keycode;
1998
Linus Torvalds1da177e2005-04-16 15:20:36 -07001999 if (!video)
Patrick Mocheld550d982006-06-27 00:41:40 -04002000 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002001
Luming Yue9dab192007-08-20 18:23:53 +08002002 input = video->input;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002003
2004 switch (event) {
Julius Volz98fb8fe2007-02-20 16:38:40 +01002005 case ACPI_VIDEO_NOTIFY_SWITCH: /* User requested a switch,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002006 * most likely via hotkey. */
Len Brown14e04fb32007-08-23 15:20:26 -04002007 acpi_bus_generate_proc_event(device, event, 0);
Luming Yue9dab192007-08-20 18:23:53 +08002008 keycode = KEY_SWITCHVIDEOMODE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002009 break;
2010
Julius Volz98fb8fe2007-02-20 16:38:40 +01002011 case ACPI_VIDEO_NOTIFY_PROBE: /* User plugged in or removed a video
Linus Torvalds1da177e2005-04-16 15:20:36 -07002012 * connector. */
2013 acpi_video_device_enumerate(video);
2014 acpi_video_device_rebind(video);
Len Brown14e04fb32007-08-23 15:20:26 -04002015 acpi_bus_generate_proc_event(device, event, 0);
Luming Yue9dab192007-08-20 18:23:53 +08002016 keycode = KEY_SWITCHVIDEOMODE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002017 break;
2018
Len Brown4be44fc2005-08-05 00:44:28 -04002019 case ACPI_VIDEO_NOTIFY_CYCLE: /* Cycle Display output hotkey pressed. */
Len Brown25c87f72007-08-25 01:44:01 -04002020 acpi_bus_generate_proc_event(device, event, 0);
Luming Yue9dab192007-08-20 18:23:53 +08002021 keycode = KEY_SWITCHVIDEOMODE;
2022 break;
Len Brown4be44fc2005-08-05 00:44:28 -04002023 case ACPI_VIDEO_NOTIFY_NEXT_OUTPUT: /* Next Display output hotkey pressed. */
Len Brown25c87f72007-08-25 01:44:01 -04002024 acpi_bus_generate_proc_event(device, event, 0);
Luming Yue9dab192007-08-20 18:23:53 +08002025 keycode = KEY_VIDEO_NEXT;
2026 break;
Len Brown4be44fc2005-08-05 00:44:28 -04002027 case ACPI_VIDEO_NOTIFY_PREV_OUTPUT: /* previous Display output hotkey pressed. */
Len Brown14e04fb32007-08-23 15:20:26 -04002028 acpi_bus_generate_proc_event(device, event, 0);
Luming Yue9dab192007-08-20 18:23:53 +08002029 keycode = KEY_VIDEO_PREV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002030 break;
2031
2032 default:
Luming Yue9dab192007-08-20 18:23:53 +08002033 keycode = KEY_UNKNOWN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002034 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
Len Brown4be44fc2005-08-05 00:44:28 -04002035 "Unsupported event [0x%x]\n", event));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002036 break;
2037 }
2038
Zhang Rui7761f632008-01-25 14:48:12 +08002039 acpi_notifier_call_chain(device, event, 0);
Luming Yue9dab192007-08-20 18:23:53 +08002040 input_report_key(input, keycode, 1);
2041 input_sync(input);
2042 input_report_key(input, keycode, 0);
2043 input_sync(input);
2044
Patrick Mocheld550d982006-06-27 00:41:40 -04002045 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002046}
2047
Len Brown4be44fc2005-08-05 00:44:28 -04002048static void acpi_video_device_notify(acpi_handle handle, u32 event, void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002049{
Jan Engelhardt50dd0962006-10-01 00:28:50 +02002050 struct acpi_video_device *video_device = data;
Len Brown4be44fc2005-08-05 00:44:28 -04002051 struct acpi_device *device = NULL;
Luming Yue9dab192007-08-20 18:23:53 +08002052 struct acpi_video_bus *bus;
2053 struct input_dev *input;
2054 int keycode;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002055
Linus Torvalds1da177e2005-04-16 15:20:36 -07002056 if (!video_device)
Patrick Mocheld550d982006-06-27 00:41:40 -04002057 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002058
Patrick Mochele6afa0d2006-05-19 16:54:40 -04002059 device = video_device->dev;
Luming Yue9dab192007-08-20 18:23:53 +08002060 bus = video_device->video;
2061 input = bus->input;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002062
2063 switch (event) {
Len Brown4be44fc2005-08-05 00:44:28 -04002064 case ACPI_VIDEO_NOTIFY_CYCLE_BRIGHTNESS: /* Cycle brightness */
Zhang Rui8a681a42008-01-25 14:47:49 +08002065 if (brightness_switch_enabled)
2066 acpi_video_switch_brightness(video_device, event);
Len Brown25c87f72007-08-25 01:44:01 -04002067 acpi_bus_generate_proc_event(device, event, 0);
Luming Yue9dab192007-08-20 18:23:53 +08002068 keycode = KEY_BRIGHTNESS_CYCLE;
2069 break;
Len Brown4be44fc2005-08-05 00:44:28 -04002070 case ACPI_VIDEO_NOTIFY_INC_BRIGHTNESS: /* Increase brightness */
Zhang Rui8a681a42008-01-25 14:47:49 +08002071 if (brightness_switch_enabled)
2072 acpi_video_switch_brightness(video_device, event);
Len Brown25c87f72007-08-25 01:44:01 -04002073 acpi_bus_generate_proc_event(device, event, 0);
Luming Yue9dab192007-08-20 18:23:53 +08002074 keycode = KEY_BRIGHTNESSUP;
2075 break;
Len Brown4be44fc2005-08-05 00:44:28 -04002076 case ACPI_VIDEO_NOTIFY_DEC_BRIGHTNESS: /* Decrease brightness */
Zhang Rui8a681a42008-01-25 14:47:49 +08002077 if (brightness_switch_enabled)
2078 acpi_video_switch_brightness(video_device, event);
Len Brown25c87f72007-08-25 01:44:01 -04002079 acpi_bus_generate_proc_event(device, event, 0);
Luming Yue9dab192007-08-20 18:23:53 +08002080 keycode = KEY_BRIGHTNESSDOWN;
2081 break;
Len Brown4be44fc2005-08-05 00:44:28 -04002082 case ACPI_VIDEO_NOTIFY_ZERO_BRIGHTNESS: /* zero brightnesss */
Zhang Rui8a681a42008-01-25 14:47:49 +08002083 if (brightness_switch_enabled)
2084 acpi_video_switch_brightness(video_device, event);
Len Brown25c87f72007-08-25 01:44:01 -04002085 acpi_bus_generate_proc_event(device, event, 0);
Luming Yue9dab192007-08-20 18:23:53 +08002086 keycode = KEY_BRIGHTNESS_ZERO;
2087 break;
Len Brown4be44fc2005-08-05 00:44:28 -04002088 case ACPI_VIDEO_NOTIFY_DISPLAY_OFF: /* display device off */
Zhang Rui8a681a42008-01-25 14:47:49 +08002089 if (brightness_switch_enabled)
2090 acpi_video_switch_brightness(video_device, event);
Len Brown14e04fb32007-08-23 15:20:26 -04002091 acpi_bus_generate_proc_event(device, event, 0);
Luming Yue9dab192007-08-20 18:23:53 +08002092 keycode = KEY_DISPLAY_OFF;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002093 break;
2094 default:
Luming Yue9dab192007-08-20 18:23:53 +08002095 keycode = KEY_UNKNOWN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002096 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
Len Brown4be44fc2005-08-05 00:44:28 -04002097 "Unsupported event [0x%x]\n", event));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002098 break;
2099 }
Luming Yue9dab192007-08-20 18:23:53 +08002100
Zhang Rui7761f632008-01-25 14:48:12 +08002101 acpi_notifier_call_chain(device, event, 0);
Luming Yue9dab192007-08-20 18:23:53 +08002102 input_report_key(input, keycode, 1);
2103 input_sync(input);
2104 input_report_key(input, keycode, 0);
2105 input_sync(input);
2106
Patrick Mocheld550d982006-06-27 00:41:40 -04002107 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002108}
2109
Zhang Ruie6d9da12007-08-25 02:23:31 -04002110static int instance;
Matthew Garrett863c1492008-02-04 23:31:24 -08002111static int acpi_video_resume(struct acpi_device *device)
2112{
2113 struct acpi_video_bus *video;
2114 struct acpi_video_device *video_device;
2115 int i;
2116
2117 if (!device || !acpi_driver_data(device))
2118 return -EINVAL;
2119
2120 video = acpi_driver_data(device);
2121
2122 for (i = 0; i < video->attached_count; i++) {
2123 video_device = video->attached_array[i].bind_info;
2124 if (video_device && video_device->backlight)
2125 acpi_video_set_brightness(video_device->backlight);
2126 }
2127 return AE_OK;
2128}
2129
Len Brown4be44fc2005-08-05 00:44:28 -04002130static int acpi_video_bus_add(struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002131{
Dmitry Torokhovf51e8392007-11-05 11:43:30 -05002132 struct acpi_video_bus *video;
Luming Yue9dab192007-08-20 18:23:53 +08002133 struct input_dev *input;
Dmitry Torokhovf51e8392007-11-05 11:43:30 -05002134 int error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002135
Burman Yan36bcbec2006-12-19 12:56:11 -08002136 video = kzalloc(sizeof(struct acpi_video_bus), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002137 if (!video)
Patrick Mocheld550d982006-06-27 00:41:40 -04002138 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002139
Zhang Ruie6d9da12007-08-25 02:23:31 -04002140 /* a hack to fix the duplicate name "VID" problem on T61 */
2141 if (!strcmp(device->pnp.bus_id, "VID")) {
2142 if (instance)
2143 device->pnp.bus_id[3] = '0' + instance;
2144 instance ++;
2145 }
Zhao Yakuif3b39f12009-02-02 22:55:01 -05002146 /* a hack to fix the duplicate name "VGA" problem on Pa 3553 */
2147 if (!strcmp(device->pnp.bus_id, "VGA")) {
2148 if (instance)
2149 device->pnp.bus_id[3] = '0' + instance;
2150 instance++;
2151 }
Zhang Ruie6d9da12007-08-25 02:23:31 -04002152
Patrick Mochele6afa0d2006-05-19 16:54:40 -04002153 video->device = device;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002154 strcpy(acpi_device_name(device), ACPI_VIDEO_BUS_NAME);
2155 strcpy(acpi_device_class(device), ACPI_VIDEO_CLASS);
Pavel Machekdb89b4f2008-09-22 14:37:34 -07002156 device->driver_data = video;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002157
2158 acpi_video_bus_find_cap(video);
Dmitry Torokhovf51e8392007-11-05 11:43:30 -05002159 error = acpi_video_bus_check(video);
2160 if (error)
2161 goto err_free_video;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002162
Dmitry Torokhovf51e8392007-11-05 11:43:30 -05002163 error = acpi_video_bus_add_fs(device);
2164 if (error)
2165 goto err_free_video;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002166
Dmitry Torokhovbbac81f2007-11-05 11:43:32 -05002167 mutex_init(&video->device_list_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002168 INIT_LIST_HEAD(&video->video_device_list);
2169
2170 acpi_video_bus_get_devices(video, device);
2171 acpi_video_bus_start_devices(video);
2172
Luming Yue9dab192007-08-20 18:23:53 +08002173 video->input = input = input_allocate_device();
Dmitry Torokhovf51e8392007-11-05 11:43:30 -05002174 if (!input) {
2175 error = -ENOMEM;
Bjorn Helgaas70155582009-04-07 15:37:11 +00002176 goto err_stop_video;
Dmitry Torokhovf51e8392007-11-05 11:43:30 -05002177 }
Luming Yue9dab192007-08-20 18:23:53 +08002178
2179 snprintf(video->phys, sizeof(video->phys),
2180 "%s/video/input0", acpi_device_hid(video->device));
2181
2182 input->name = acpi_device_name(video->device);
2183 input->phys = video->phys;
2184 input->id.bustype = BUS_HOST;
2185 input->id.product = 0x06;
Dmitry Torokhov91c05c62007-11-05 11:43:29 -05002186 input->dev.parent = &device->dev;
Luming Yue9dab192007-08-20 18:23:53 +08002187 input->evbit[0] = BIT(EV_KEY);
2188 set_bit(KEY_SWITCHVIDEOMODE, input->keybit);
2189 set_bit(KEY_VIDEO_NEXT, input->keybit);
2190 set_bit(KEY_VIDEO_PREV, input->keybit);
2191 set_bit(KEY_BRIGHTNESS_CYCLE, input->keybit);
2192 set_bit(KEY_BRIGHTNESSUP, input->keybit);
2193 set_bit(KEY_BRIGHTNESSDOWN, input->keybit);
2194 set_bit(KEY_BRIGHTNESS_ZERO, input->keybit);
2195 set_bit(KEY_DISPLAY_OFF, input->keybit);
2196 set_bit(KEY_UNKNOWN, input->keybit);
Luming Yue9dab192007-08-20 18:23:53 +08002197
Dmitry Torokhovf51e8392007-11-05 11:43:30 -05002198 error = input_register_device(input);
2199 if (error)
2200 goto err_free_input_dev;
Luming Yue9dab192007-08-20 18:23:53 +08002201
Linus Torvalds1da177e2005-04-16 15:20:36 -07002202 printk(KERN_INFO PREFIX "%s [%s] (multi-head: %s rom: %s post: %s)\n",
Len Brown4be44fc2005-08-05 00:44:28 -04002203 ACPI_VIDEO_DEVICE_NAME, acpi_device_bid(device),
2204 video->flags.multihead ? "yes" : "no",
2205 video->flags.rom ? "yes" : "no",
2206 video->flags.post ? "yes" : "no");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002207
Dmitry Torokhovf51e8392007-11-05 11:43:30 -05002208 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002209
Dmitry Torokhovf51e8392007-11-05 11:43:30 -05002210 err_free_input_dev:
2211 input_free_device(input);
Dmitry Torokhovf51e8392007-11-05 11:43:30 -05002212 err_stop_video:
2213 acpi_video_bus_stop_devices(video);
2214 acpi_video_bus_put_devices(video);
2215 kfree(video->attached_array);
2216 acpi_video_bus_remove_fs(device);
2217 err_free_video:
2218 kfree(video);
Pavel Machekdb89b4f2008-09-22 14:37:34 -07002219 device->driver_data = NULL;
Dmitry Torokhovf51e8392007-11-05 11:43:30 -05002220
2221 return error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002222}
2223
Len Brown4be44fc2005-08-05 00:44:28 -04002224static int acpi_video_bus_remove(struct acpi_device *device, int type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002225{
Len Brown4be44fc2005-08-05 00:44:28 -04002226 struct acpi_video_bus *video = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002227
Linus Torvalds1da177e2005-04-16 15:20:36 -07002228
2229 if (!device || !acpi_driver_data(device))
Patrick Mocheld550d982006-06-27 00:41:40 -04002230 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002231
Jan Engelhardt50dd0962006-10-01 00:28:50 +02002232 video = acpi_driver_data(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002233
2234 acpi_video_bus_stop_devices(video);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002235 acpi_video_bus_put_devices(video);
2236 acpi_video_bus_remove_fs(device);
2237
Luming Yue9dab192007-08-20 18:23:53 +08002238 input_unregister_device(video->input);
Jesper Juhl6044ec82005-11-07 01:01:32 -08002239 kfree(video->attached_array);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002240 kfree(video);
2241
Patrick Mocheld550d982006-06-27 00:41:40 -04002242 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002243}
2244
Matthew Garrett74a365b2009-03-19 21:35:39 +00002245static int __init intel_opregion_present(void)
2246{
2247#if defined(CONFIG_DRM_I915) || defined(CONFIG_DRM_I915_MODULE)
2248 struct pci_dev *dev = NULL;
2249 u32 address;
2250
2251 for_each_pci_dev(dev) {
2252 if ((dev->class >> 8) != PCI_CLASS_DISPLAY_VGA)
2253 continue;
2254 if (dev->vendor != PCI_VENDOR_ID_INTEL)
2255 continue;
2256 pci_read_config_dword(dev, 0xfc, &address);
2257 if (!address)
2258 continue;
2259 return 1;
2260 }
2261#endif
2262 return 0;
2263}
2264
2265int acpi_video_register(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002266{
Len Brown4be44fc2005-08-05 00:44:28 -04002267 int result = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002268
Linus Torvalds1da177e2005-04-16 15:20:36 -07002269 acpi_video_dir = proc_mkdir(ACPI_VIDEO_CLASS, acpi_root_dir);
2270 if (!acpi_video_dir)
Patrick Mocheld550d982006-06-27 00:41:40 -04002271 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002272
2273 result = acpi_bus_register_driver(&acpi_video_bus);
2274 if (result < 0) {
2275 remove_proc_entry(ACPI_VIDEO_CLASS, acpi_root_dir);
Patrick Mocheld550d982006-06-27 00:41:40 -04002276 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002277 }
2278
Patrick Mocheld550d982006-06-27 00:41:40 -04002279 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002280}
Matthew Garrett74a365b2009-03-19 21:35:39 +00002281EXPORT_SYMBOL(acpi_video_register);
2282
2283/*
2284 * This is kind of nasty. Hardware using Intel chipsets may require
2285 * the video opregion code to be run first in order to initialise
2286 * state before any ACPI video calls are made. To handle this we defer
2287 * registration of the video class until the opregion code has run.
2288 */
2289
2290static int __init acpi_video_init(void)
2291{
2292 if (intel_opregion_present())
2293 return 0;
2294
2295 return acpi_video_register();
2296}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002297
Len Brown4be44fc2005-08-05 00:44:28 -04002298static void __exit acpi_video_exit(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002299{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002300
2301 acpi_bus_unregister_driver(&acpi_video_bus);
2302
2303 remove_proc_entry(ACPI_VIDEO_CLASS, acpi_root_dir);
2304
Patrick Mocheld550d982006-06-27 00:41:40 -04002305 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002306}
2307
2308module_init(acpi_video_init);
2309module_exit(acpi_video_exit);