blob: b5e35cd559eac130437657834aed2aa8ca1e74a4 [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>
Luming Yu23b0f012007-05-09 21:07:05 +080037#include <linux/video_output.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070038#include <asm/uaccess.h>
39
40#include <acpi/acpi_bus.h>
41#include <acpi/acpi_drivers.h>
42
43#define ACPI_VIDEO_COMPONENT 0x08000000
44#define ACPI_VIDEO_CLASS "video"
Linus Torvalds1da177e2005-04-16 15:20:36 -070045#define ACPI_VIDEO_BUS_NAME "Video Bus"
46#define ACPI_VIDEO_DEVICE_NAME "Video Device"
47#define ACPI_VIDEO_NOTIFY_SWITCH 0x80
48#define ACPI_VIDEO_NOTIFY_PROBE 0x81
49#define ACPI_VIDEO_NOTIFY_CYCLE 0x82
50#define ACPI_VIDEO_NOTIFY_NEXT_OUTPUT 0x83
51#define ACPI_VIDEO_NOTIFY_PREV_OUTPUT 0x84
52
Thomas Tuttlef4715182006-12-19 12:56:14 -080053#define ACPI_VIDEO_NOTIFY_CYCLE_BRIGHTNESS 0x85
54#define ACPI_VIDEO_NOTIFY_INC_BRIGHTNESS 0x86
55#define ACPI_VIDEO_NOTIFY_DEC_BRIGHTNESS 0x87
56#define ACPI_VIDEO_NOTIFY_ZERO_BRIGHTNESS 0x88
57#define ACPI_VIDEO_NOTIFY_DISPLAY_OFF 0x89
Linus Torvalds1da177e2005-04-16 15:20:36 -070058
Linus Torvalds1da177e2005-04-16 15:20:36 -070059#define ACPI_VIDEO_HEAD_INVALID (~0u - 1)
60#define ACPI_VIDEO_HEAD_END (~0u)
Yu Luming2f3d0002006-11-11 02:40:34 +080061#define MAX_NAME_LEN 20
Linus Torvalds1da177e2005-04-16 15:20:36 -070062
Rui Zhang82cae992007-01-03 23:40:53 -050063#define ACPI_VIDEO_DISPLAY_CRT 1
64#define ACPI_VIDEO_DISPLAY_TV 2
65#define ACPI_VIDEO_DISPLAY_DVI 3
66#define ACPI_VIDEO_DISPLAY_LCD 4
67
Linus Torvalds1da177e2005-04-16 15:20:36 -070068#define _COMPONENT ACPI_VIDEO_COMPONENT
Len Brownf52fd662007-02-12 22:42:12 -050069ACPI_MODULE_NAME("video");
Linus Torvalds1da177e2005-04-16 15:20:36 -070070
Len Brownf52fd662007-02-12 22:42:12 -050071MODULE_AUTHOR("Bruno Ducrot");
Len Brown7cda93e2007-02-12 23:50:02 -050072MODULE_DESCRIPTION("ACPI Video Driver");
Linus Torvalds1da177e2005-04-16 15:20:36 -070073MODULE_LICENSE("GPL");
74
Zhang Rui8a681a42008-01-25 14:47:49 +080075static int brightness_switch_enabled = 1;
76module_param(brightness_switch_enabled, bool, 0644);
77
Len Brown4be44fc2005-08-05 00:44:28 -040078static int acpi_video_bus_add(struct acpi_device *device);
79static int acpi_video_bus_remove(struct acpi_device *device, int type);
Matthew Garrett863c1492008-02-04 23:31:24 -080080static int acpi_video_resume(struct acpi_device *device);
Linus Torvalds1da177e2005-04-16 15:20:36 -070081
Thomas Renninger1ba90e32007-07-23 14:44:41 +020082static const struct acpi_device_id video_device_ids[] = {
83 {ACPI_VIDEO_HID, 0},
84 {"", 0},
85};
86MODULE_DEVICE_TABLE(acpi, video_device_ids);
87
Linus Torvalds1da177e2005-04-16 15:20:36 -070088static struct acpi_driver acpi_video_bus = {
Len Brownc2b67052007-02-12 23:33:40 -050089 .name = "video",
Linus Torvalds1da177e2005-04-16 15:20:36 -070090 .class = ACPI_VIDEO_CLASS,
Thomas Renninger1ba90e32007-07-23 14:44:41 +020091 .ids = video_device_ids,
Linus Torvalds1da177e2005-04-16 15:20:36 -070092 .ops = {
93 .add = acpi_video_bus_add,
94 .remove = acpi_video_bus_remove,
Matthew Garrett863c1492008-02-04 23:31:24 -080095 .resume = acpi_video_resume,
Len Brown4be44fc2005-08-05 00:44:28 -040096 },
Linus Torvalds1da177e2005-04-16 15:20:36 -070097};
98
99struct acpi_video_bus_flags {
Len Brown4be44fc2005-08-05 00:44:28 -0400100 u8 multihead:1; /* can switch video heads */
101 u8 rom:1; /* can retrieve a video rom */
102 u8 post:1; /* can configure the head to */
103 u8 reserved:5;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104};
105
106struct acpi_video_bus_cap {
Len Brown4be44fc2005-08-05 00:44:28 -0400107 u8 _DOS:1; /*Enable/Disable output switching */
108 u8 _DOD:1; /*Enumerate all devices attached to display adapter */
109 u8 _ROM:1; /*Get ROM Data */
110 u8 _GPD:1; /*Get POST Device */
111 u8 _SPD:1; /*Set POST Device */
112 u8 _VPO:1; /*Video POST Options */
113 u8 reserved:2;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114};
115
Len Brown4be44fc2005-08-05 00:44:28 -0400116struct acpi_video_device_attrib {
117 u32 display_index:4; /* A zero-based instance of the Display */
Julius Volz98fb8fe2007-02-20 16:38:40 +0100118 u32 display_port_attachment:4; /*This field differentiates the display type */
Len Brown4be44fc2005-08-05 00:44:28 -0400119 u32 display_type:4; /*Describe the specific type in use */
Julius Volz98fb8fe2007-02-20 16:38:40 +0100120 u32 vendor_specific:4; /*Chipset Vendor Specific */
Len Brown4be44fc2005-08-05 00:44:28 -0400121 u32 bios_can_detect:1; /*BIOS can detect the device */
122 u32 depend_on_vga:1; /*Non-VGA output device whose power is related to
123 the VGA device. */
124 u32 pipe_id:3; /*For VGA multiple-head devices. */
125 u32 reserved:10; /*Must be 0 */
126 u32 device_id_scheme:1; /*Device ID Scheme */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127};
128
129struct acpi_video_enumerated_device {
130 union {
131 u32 int_val;
Len Brown4be44fc2005-08-05 00:44:28 -0400132 struct acpi_video_device_attrib attrib;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133 } value;
134 struct acpi_video_device *bind_info;
135};
136
137struct acpi_video_bus {
Patrick Mochele6afa0d2006-05-19 16:54:40 -0400138 struct acpi_device *device;
Len Brown4be44fc2005-08-05 00:44:28 -0400139 u8 dos_setting;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140 struct acpi_video_enumerated_device *attached_array;
Len Brown4be44fc2005-08-05 00:44:28 -0400141 u8 attached_count;
142 struct acpi_video_bus_cap cap;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143 struct acpi_video_bus_flags flags;
Len Brown4be44fc2005-08-05 00:44:28 -0400144 struct list_head video_device_list;
Dmitry Torokhovbbac81f2007-11-05 11:43:32 -0500145 struct mutex device_list_lock; /* protects video_device_list */
Len Brown4be44fc2005-08-05 00:44:28 -0400146 struct proc_dir_entry *dir;
Luming Yue9dab192007-08-20 18:23:53 +0800147 struct input_dev *input;
148 char phys[32]; /* for input device */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700149};
150
151struct acpi_video_device_flags {
Len Brown4be44fc2005-08-05 00:44:28 -0400152 u8 crt:1;
153 u8 lcd:1;
154 u8 tvout:1;
Rui Zhang82cae992007-01-03 23:40:53 -0500155 u8 dvi:1;
Len Brown4be44fc2005-08-05 00:44:28 -0400156 u8 bios:1;
157 u8 unknown:1;
Rui Zhang82cae992007-01-03 23:40:53 -0500158 u8 reserved:2;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700159};
160
161struct acpi_video_device_cap {
Len Brown4be44fc2005-08-05 00:44:28 -0400162 u8 _ADR:1; /*Return the unique ID */
163 u8 _BCL:1; /*Query list of brightness control levels supported */
164 u8 _BCM:1; /*Set the brightness level */
Yu Luming2f3d0002006-11-11 02:40:34 +0800165 u8 _BQC:1; /* Get current brightness level */
Len Brown4be44fc2005-08-05 00:44:28 -0400166 u8 _DDC:1; /*Return the EDID for this device */
167 u8 _DCS:1; /*Return status of output device */
168 u8 _DGS:1; /*Query graphics state */
169 u8 _DSS:1; /*Device state set */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700170};
171
172struct acpi_video_device_brightness {
Len Brown4be44fc2005-08-05 00:44:28 -0400173 int curr;
174 int count;
175 int *levels;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700176};
177
178struct acpi_video_device {
Len Brown4be44fc2005-08-05 00:44:28 -0400179 unsigned long device_id;
180 struct acpi_video_device_flags flags;
181 struct acpi_video_device_cap cap;
182 struct list_head entry;
183 struct acpi_video_bus *video;
184 struct acpi_device *dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700185 struct acpi_video_device_brightness *brightness;
Yu Luming2f3d0002006-11-11 02:40:34 +0800186 struct backlight_device *backlight;
Luming Yu23b0f012007-05-09 21:07:05 +0800187 struct output_device *output_dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700188};
189
Linus Torvalds1da177e2005-04-16 15:20:36 -0700190/* bus */
191static int acpi_video_bus_info_open_fs(struct inode *inode, struct file *file);
192static struct file_operations acpi_video_bus_info_fops = {
Len Brown4be44fc2005-08-05 00:44:28 -0400193 .open = acpi_video_bus_info_open_fs,
194 .read = seq_read,
195 .llseek = seq_lseek,
196 .release = single_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700197};
198
199static int acpi_video_bus_ROM_open_fs(struct inode *inode, struct file *file);
200static struct file_operations acpi_video_bus_ROM_fops = {
Len Brown4be44fc2005-08-05 00:44:28 -0400201 .open = acpi_video_bus_ROM_open_fs,
202 .read = seq_read,
203 .llseek = seq_lseek,
204 .release = single_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700205};
206
Len Brown4be44fc2005-08-05 00:44:28 -0400207static int acpi_video_bus_POST_info_open_fs(struct inode *inode,
208 struct file *file);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700209static struct file_operations acpi_video_bus_POST_info_fops = {
Len Brown4be44fc2005-08-05 00:44:28 -0400210 .open = acpi_video_bus_POST_info_open_fs,
211 .read = seq_read,
212 .llseek = seq_lseek,
213 .release = single_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700214};
215
216static int acpi_video_bus_POST_open_fs(struct inode *inode, struct file *file);
217static struct file_operations acpi_video_bus_POST_fops = {
Len Brown4be44fc2005-08-05 00:44:28 -0400218 .open = acpi_video_bus_POST_open_fs,
219 .read = seq_read,
220 .llseek = seq_lseek,
221 .release = single_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700222};
223
Linus Torvalds1da177e2005-04-16 15:20:36 -0700224static int acpi_video_bus_DOS_open_fs(struct inode *inode, struct file *file);
225static struct file_operations acpi_video_bus_DOS_fops = {
Len Brown4be44fc2005-08-05 00:44:28 -0400226 .open = acpi_video_bus_DOS_open_fs,
227 .read = seq_read,
228 .llseek = seq_lseek,
229 .release = single_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700230};
231
232/* device */
Len Brown4be44fc2005-08-05 00:44:28 -0400233static int acpi_video_device_info_open_fs(struct inode *inode,
234 struct file *file);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700235static struct file_operations acpi_video_device_info_fops = {
Len Brown4be44fc2005-08-05 00:44:28 -0400236 .open = acpi_video_device_info_open_fs,
237 .read = seq_read,
238 .llseek = seq_lseek,
239 .release = single_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700240};
241
Len Brown4be44fc2005-08-05 00:44:28 -0400242static int acpi_video_device_state_open_fs(struct inode *inode,
243 struct file *file);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700244static struct file_operations acpi_video_device_state_fops = {
Len Brown4be44fc2005-08-05 00:44:28 -0400245 .open = acpi_video_device_state_open_fs,
246 .read = seq_read,
247 .llseek = seq_lseek,
248 .release = single_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700249};
250
Len Brown4be44fc2005-08-05 00:44:28 -0400251static int acpi_video_device_brightness_open_fs(struct inode *inode,
252 struct file *file);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700253static struct file_operations acpi_video_device_brightness_fops = {
Len Brown4be44fc2005-08-05 00:44:28 -0400254 .open = acpi_video_device_brightness_open_fs,
255 .read = seq_read,
256 .llseek = seq_lseek,
257 .release = single_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700258};
259
Len Brown4be44fc2005-08-05 00:44:28 -0400260static int acpi_video_device_EDID_open_fs(struct inode *inode,
261 struct file *file);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700262static struct file_operations acpi_video_device_EDID_fops = {
Len Brown4be44fc2005-08-05 00:44:28 -0400263 .open = acpi_video_device_EDID_open_fs,
264 .read = seq_read,
265 .llseek = seq_lseek,
266 .release = single_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700267};
268
Len Brown4be44fc2005-08-05 00:44:28 -0400269static char device_decode[][30] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700270 "motherboard VGA device",
271 "PCI VGA device",
272 "AGP VGA device",
273 "UNKNOWN",
274};
275
Len Brown4be44fc2005-08-05 00:44:28 -0400276static void acpi_video_device_notify(acpi_handle handle, u32 event, void *data);
277static void acpi_video_device_rebind(struct acpi_video_bus *video);
278static void acpi_video_device_bind(struct acpi_video_bus *video,
279 struct acpi_video_device *device);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700280static int acpi_video_device_enumerate(struct acpi_video_bus *video);
Yu Luming2f3d0002006-11-11 02:40:34 +0800281static int acpi_video_device_lcd_set_level(struct acpi_video_device *device,
282 int level);
283static int acpi_video_device_lcd_get_level_current(
284 struct acpi_video_device *device,
285 unsigned long *level);
Len Brown4be44fc2005-08-05 00:44:28 -0400286static int acpi_video_get_next_level(struct acpi_video_device *device,
287 u32 level_current, u32 event);
288static void acpi_video_switch_brightness(struct acpi_video_device *device,
289 int event);
Luming Yu23b0f012007-05-09 21:07:05 +0800290static int acpi_video_device_get_state(struct acpi_video_device *device,
291 unsigned long *state);
292static int acpi_video_output_get(struct output_device *od);
293static int acpi_video_device_set_state(struct acpi_video_device *device, int state);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700294
Yu Luming2f3d0002006-11-11 02:40:34 +0800295/*backlight device sysfs support*/
296static int acpi_video_get_brightness(struct backlight_device *bd)
297{
298 unsigned long cur_level;
299 struct acpi_video_device *vd =
Richard Purdie655bfd72007-07-09 12:17:24 +0100300 (struct acpi_video_device *)bl_get_data(bd);
Yu Luming2f3d0002006-11-11 02:40:34 +0800301 acpi_video_device_lcd_get_level_current(vd, &cur_level);
302 return (int) cur_level;
303}
304
305static int acpi_video_set_brightness(struct backlight_device *bd)
306{
Richard Purdie599a52d2007-02-10 23:07:48 +0000307 int request_level = bd->props.brightness;
Yu Luming2f3d0002006-11-11 02:40:34 +0800308 struct acpi_video_device *vd =
Richard Purdie655bfd72007-07-09 12:17:24 +0100309 (struct acpi_video_device *)bl_get_data(bd);
Yu Luming2f3d0002006-11-11 02:40:34 +0800310 acpi_video_device_lcd_set_level(vd, request_level);
311 return 0;
312}
313
Richard Purdie599a52d2007-02-10 23:07:48 +0000314static struct backlight_ops acpi_backlight_ops = {
315 .get_brightness = acpi_video_get_brightness,
316 .update_status = acpi_video_set_brightness,
317};
318
Luming Yu23b0f012007-05-09 21:07:05 +0800319/*video output device sysfs support*/
320static int acpi_video_output_get(struct output_device *od)
321{
322 unsigned long state;
323 struct acpi_video_device *vd =
tonyj@suse.de60043422007-08-07 22:28:47 -0700324 (struct acpi_video_device *)dev_get_drvdata(&od->dev);
Luming Yu23b0f012007-05-09 21:07:05 +0800325 acpi_video_device_get_state(vd, &state);
326 return (int)state;
327}
328
329static int acpi_video_output_set(struct output_device *od)
330{
331 unsigned long state = od->request_state;
332 struct acpi_video_device *vd=
tonyj@suse.de60043422007-08-07 22:28:47 -0700333 (struct acpi_video_device *)dev_get_drvdata(&od->dev);
Luming Yu23b0f012007-05-09 21:07:05 +0800334 return acpi_video_device_set_state(vd, state);
335}
336
337static struct output_properties acpi_output_properties = {
338 .set_state = acpi_video_output_set,
339 .get_status = acpi_video_output_get,
340};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700341/* --------------------------------------------------------------------------
342 Video Management
343 -------------------------------------------------------------------------- */
344
345/* device */
346
347static int
Len Brown4be44fc2005-08-05 00:44:28 -0400348acpi_video_device_query(struct acpi_video_device *device, unsigned long *state)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700349{
Len Brown4be44fc2005-08-05 00:44:28 -0400350 int status;
Patrick Mochel90130262006-05-19 16:54:48 -0400351
352 status = acpi_evaluate_integer(device->dev->handle, "_DGS", NULL, state);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700353
Patrick Mocheld550d982006-06-27 00:41:40 -0400354 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700355}
356
357static int
Len Brown4be44fc2005-08-05 00:44:28 -0400358acpi_video_device_get_state(struct acpi_video_device *device,
359 unsigned long *state)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700360{
Len Brown4be44fc2005-08-05 00:44:28 -0400361 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700362
Patrick Mochel90130262006-05-19 16:54:48 -0400363 status = acpi_evaluate_integer(device->dev->handle, "_DCS", NULL, state);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700364
Patrick Mocheld550d982006-06-27 00:41:40 -0400365 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700366}
367
368static int
Len Brown4be44fc2005-08-05 00:44:28 -0400369acpi_video_device_set_state(struct acpi_video_device *device, int state)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700370{
Len Brown4be44fc2005-08-05 00:44:28 -0400371 int status;
372 union acpi_object arg0 = { ACPI_TYPE_INTEGER };
373 struct acpi_object_list args = { 1, &arg0 };
Luming Yu824b5582005-08-21 19:17:00 -0400374 unsigned long ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700375
Linus Torvalds1da177e2005-04-16 15:20:36 -0700376
377 arg0.integer.value = state;
Patrick Mochel90130262006-05-19 16:54:48 -0400378 status = acpi_evaluate_integer(device->dev->handle, "_DSS", &args, &ret);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700379
Patrick Mocheld550d982006-06-27 00:41:40 -0400380 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700381}
382
383static int
Len Brown4be44fc2005-08-05 00:44:28 -0400384acpi_video_device_lcd_query_levels(struct acpi_video_device *device,
385 union acpi_object **levels)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700386{
Len Brown4be44fc2005-08-05 00:44:28 -0400387 int status;
388 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
389 union acpi_object *obj;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700390
Linus Torvalds1da177e2005-04-16 15:20:36 -0700391
392 *levels = NULL;
393
Patrick Mochel90130262006-05-19 16:54:48 -0400394 status = acpi_evaluate_object(device->dev->handle, "_BCL", NULL, &buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700395 if (!ACPI_SUCCESS(status))
Patrick Mocheld550d982006-06-27 00:41:40 -0400396 return status;
Len Brown4be44fc2005-08-05 00:44:28 -0400397 obj = (union acpi_object *)buffer.pointer;
Adrian Bunk6665bda2006-03-11 10:12:00 -0500398 if (!obj || (obj->type != ACPI_TYPE_PACKAGE)) {
Len Brown64684632006-06-26 23:41:38 -0400399 printk(KERN_ERR PREFIX "Invalid _BCL data\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700400 status = -EFAULT;
401 goto err;
402 }
403
404 *levels = obj;
405
Patrick Mocheld550d982006-06-27 00:41:40 -0400406 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700407
Len Brown4be44fc2005-08-05 00:44:28 -0400408 err:
Jesper Juhl6044ec82005-11-07 01:01:32 -0800409 kfree(buffer.pointer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700410
Patrick Mocheld550d982006-06-27 00:41:40 -0400411 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700412}
413
414static int
Len Brown4be44fc2005-08-05 00:44:28 -0400415acpi_video_device_lcd_set_level(struct acpi_video_device *device, int level)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700416{
Alexey Starikovskiy4500ca82007-09-03 16:29:58 +0400417 int status = AE_OK;
Len Brown4be44fc2005-08-05 00:44:28 -0400418 union acpi_object arg0 = { ACPI_TYPE_INTEGER };
419 struct acpi_object_list args = { 1, &arg0 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700420
Linus Torvalds1da177e2005-04-16 15:20:36 -0700421
422 arg0.integer.value = level;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700423
Alexey Starikovskiy4500ca82007-09-03 16:29:58 +0400424 if (device->cap._BCM)
425 status = acpi_evaluate_object(device->dev->handle, "_BCM",
426 &args, NULL);
427 device->brightness->curr = level;
Patrick Mocheld550d982006-06-27 00:41:40 -0400428 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700429}
430
431static int
Len Brown4be44fc2005-08-05 00:44:28 -0400432acpi_video_device_lcd_get_level_current(struct acpi_video_device *device,
433 unsigned long *level)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700434{
Alexey Starikovskiy4500ca82007-09-03 16:29:58 +0400435 if (device->cap._BQC)
436 return acpi_evaluate_integer(device->dev->handle, "_BQC", NULL,
437 level);
438 *level = device->brightness->curr;
439 return AE_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700440}
441
442static int
Len Brown4be44fc2005-08-05 00:44:28 -0400443acpi_video_device_EDID(struct acpi_video_device *device,
444 union acpi_object **edid, ssize_t length)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700445{
Len Brown4be44fc2005-08-05 00:44:28 -0400446 int status;
447 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
448 union acpi_object *obj;
449 union acpi_object arg0 = { ACPI_TYPE_INTEGER };
450 struct acpi_object_list args = { 1, &arg0 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700451
Linus Torvalds1da177e2005-04-16 15:20:36 -0700452
453 *edid = NULL;
454
455 if (!device)
Patrick Mocheld550d982006-06-27 00:41:40 -0400456 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700457 if (length == 128)
458 arg0.integer.value = 1;
459 else if (length == 256)
460 arg0.integer.value = 2;
461 else
Patrick Mocheld550d982006-06-27 00:41:40 -0400462 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700463
Patrick Mochel90130262006-05-19 16:54:48 -0400464 status = acpi_evaluate_object(device->dev->handle, "_DDC", &args, &buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700465 if (ACPI_FAILURE(status))
Patrick Mocheld550d982006-06-27 00:41:40 -0400466 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700467
Jan Engelhardt50dd0962006-10-01 00:28:50 +0200468 obj = buffer.pointer;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700469
470 if (obj && obj->type == ACPI_TYPE_BUFFER)
471 *edid = obj;
472 else {
Len Brown64684632006-06-26 23:41:38 -0400473 printk(KERN_ERR PREFIX "Invalid _DDC data\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700474 status = -EFAULT;
475 kfree(obj);
476 }
477
Patrick Mocheld550d982006-06-27 00:41:40 -0400478 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700479}
480
Linus Torvalds1da177e2005-04-16 15:20:36 -0700481/* bus */
482
483static int
Len Brown4be44fc2005-08-05 00:44:28 -0400484acpi_video_bus_set_POST(struct acpi_video_bus *video, unsigned long option)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700485{
Len Brown4be44fc2005-08-05 00:44:28 -0400486 int status;
487 unsigned long tmp;
488 union acpi_object arg0 = { ACPI_TYPE_INTEGER };
489 struct acpi_object_list args = { 1, &arg0 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700490
Linus Torvalds1da177e2005-04-16 15:20:36 -0700491
492 arg0.integer.value = option;
493
Patrick Mochel90130262006-05-19 16:54:48 -0400494 status = acpi_evaluate_integer(video->device->handle, "_SPD", &args, &tmp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700495 if (ACPI_SUCCESS(status))
Len Brown4be44fc2005-08-05 00:44:28 -0400496 status = tmp ? (-EINVAL) : (AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700497
Patrick Mocheld550d982006-06-27 00:41:40 -0400498 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700499}
500
501static int
Len Brown4be44fc2005-08-05 00:44:28 -0400502acpi_video_bus_get_POST(struct acpi_video_bus *video, unsigned long *id)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700503{
504 int status;
505
Patrick Mochel90130262006-05-19 16:54:48 -0400506 status = acpi_evaluate_integer(video->device->handle, "_GPD", NULL, id);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700507
Patrick Mocheld550d982006-06-27 00:41:40 -0400508 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700509}
510
511static int
Len Brown4be44fc2005-08-05 00:44:28 -0400512acpi_video_bus_POST_options(struct acpi_video_bus *video,
513 unsigned long *options)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700514{
Len Brown4be44fc2005-08-05 00:44:28 -0400515 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700516
Patrick Mochel90130262006-05-19 16:54:48 -0400517 status = acpi_evaluate_integer(video->device->handle, "_VPO", NULL, options);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700518 *options &= 3;
519
Patrick Mocheld550d982006-06-27 00:41:40 -0400520 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700521}
522
523/*
524 * Arg:
525 * video : video bus device pointer
526 * bios_flag :
527 * 0. The system BIOS should NOT automatically switch(toggle)
528 * the active display output.
529 * 1. The system BIOS should automatically switch (toggle) the
Julius Volz98fb8fe2007-02-20 16:38:40 +0100530 * active display output. No switch event.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700531 * 2. The _DGS value should be locked.
532 * 3. The system BIOS should not automatically switch (toggle) the
533 * active display output, but instead generate the display switch
534 * event notify code.
535 * lcd_flag :
536 * 0. The system BIOS should automatically control the brightness level
Julius Volz98fb8fe2007-02-20 16:38:40 +0100537 * of the LCD when the power changes from AC to DC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700538 * 1. The system BIOS should NOT automatically control the brightness
Julius Volz98fb8fe2007-02-20 16:38:40 +0100539 * level of the LCD when the power changes from AC to DC.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700540 * Return Value:
541 * -1 wrong arg.
542 */
543
544static int
Len Brown4be44fc2005-08-05 00:44:28 -0400545acpi_video_bus_DOS(struct acpi_video_bus *video, int bios_flag, int lcd_flag)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700546{
Len Brown4be44fc2005-08-05 00:44:28 -0400547 acpi_integer status = 0;
548 union acpi_object arg0 = { ACPI_TYPE_INTEGER };
549 struct acpi_object_list args = { 1, &arg0 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700550
Linus Torvalds1da177e2005-04-16 15:20:36 -0700551
Len Brown4be44fc2005-08-05 00:44:28 -0400552 if (bios_flag < 0 || bios_flag > 3 || lcd_flag < 0 || lcd_flag > 1) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700553 status = -1;
554 goto Failed;
555 }
556 arg0.integer.value = (lcd_flag << 2) | bios_flag;
557 video->dos_setting = arg0.integer.value;
Patrick Mochel90130262006-05-19 16:54:48 -0400558 acpi_evaluate_object(video->device->handle, "_DOS", &args, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700559
Len Brown4be44fc2005-08-05 00:44:28 -0400560 Failed:
Patrick Mocheld550d982006-06-27 00:41:40 -0400561 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700562}
563
564/*
565 * Arg:
566 * device : video output device (LCD, CRT, ..)
567 *
568 * Return Value:
569 * None
570 *
Julius Volz98fb8fe2007-02-20 16:38:40 +0100571 * Find out all required AML methods defined under the output
Linus Torvalds1da177e2005-04-16 15:20:36 -0700572 * device.
573 */
574
Len Brown4be44fc2005-08-05 00:44:28 -0400575static void acpi_video_device_find_cap(struct acpi_video_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700576{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700577 acpi_handle h_dummy1;
578 int i;
Yu Luming2f3d0002006-11-11 02:40:34 +0800579 u32 max_level = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700580 union acpi_object *obj = NULL;
581 struct acpi_video_device_brightness *br = NULL;
582
Linus Torvalds1da177e2005-04-16 15:20:36 -0700583
William Lee Irwin III98934de2007-12-12 03:56:55 -0800584 memset(&device->cap, 0, sizeof(device->cap));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700585
Patrick Mochel90130262006-05-19 16:54:48 -0400586 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_ADR", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700587 device->cap._ADR = 1;
588 }
Patrick Mochel90130262006-05-19 16:54:48 -0400589 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_BCL", &h_dummy1))) {
Len Brown4be44fc2005-08-05 00:44:28 -0400590 device->cap._BCL = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700591 }
Patrick Mochel90130262006-05-19 16:54:48 -0400592 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_BCM", &h_dummy1))) {
Len Brown4be44fc2005-08-05 00:44:28 -0400593 device->cap._BCM = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700594 }
Yu Luming2f3d0002006-11-11 02:40:34 +0800595 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle,"_BQC",&h_dummy1)))
596 device->cap._BQC = 1;
Patrick Mochel90130262006-05-19 16:54:48 -0400597 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_DDC", &h_dummy1))) {
Len Brown4be44fc2005-08-05 00:44:28 -0400598 device->cap._DDC = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700599 }
Patrick Mochel90130262006-05-19 16:54:48 -0400600 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_DCS", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700601 device->cap._DCS = 1;
602 }
Patrick Mochel90130262006-05-19 16:54:48 -0400603 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_DGS", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700604 device->cap._DGS = 1;
605 }
Patrick Mochel90130262006-05-19 16:54:48 -0400606 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_DSS", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700607 device->cap._DSS = 1;
608 }
609
Danny Kukawkaf70ac0e2007-07-03 01:33:53 -0400610 if (ACPI_SUCCESS(acpi_video_device_lcd_query_levels(device, &obj))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700611
Danny Kukawkaf70ac0e2007-07-03 01:33:53 -0400612 if (obj->package.count >= 2) {
613 int count = 0;
614 union acpi_object *o;
Len Brown4be44fc2005-08-05 00:44:28 -0400615
Danny Kukawkaf70ac0e2007-07-03 01:33:53 -0400616 br = kzalloc(sizeof(*br), GFP_KERNEL);
617 if (!br) {
618 printk(KERN_ERR "can't allocate memory\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700619 } else {
Danny Kukawkaf70ac0e2007-07-03 01:33:53 -0400620 br->levels = kmalloc(obj->package.count *
621 sizeof *(br->levels), GFP_KERNEL);
622 if (!br->levels)
623 goto out;
624
625 for (i = 0; i < obj->package.count; i++) {
626 o = (union acpi_object *)&obj->package.
627 elements[i];
628 if (o->type != ACPI_TYPE_INTEGER) {
629 printk(KERN_ERR PREFIX "Invalid data\n");
630 continue;
631 }
632 br->levels[count] = (u32) o->integer.value;
633
634 if (br->levels[count] > max_level)
635 max_level = br->levels[count];
636 count++;
637 }
638 out:
639 if (count < 2) {
640 kfree(br->levels);
641 kfree(br);
642 } else {
643 br->count = count;
644 device->brightness = br;
645 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
646 "found %d brightness levels\n",
647 count));
648 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700649 }
650 }
Danny Kukawkaf70ac0e2007-07-03 01:33:53 -0400651
652 } else {
653 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Could not query available LCD brightness level\n"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700654 }
655
Paulo Marquesd1dd0c22005-03-30 22:39:49 -0500656 kfree(obj);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700657
Danny Kukawkaf70ac0e2007-07-03 01:33:53 -0400658 if (device->cap._BCL && device->cap._BCM && device->cap._BQC && max_level > 0){
Yu Luming2f3d0002006-11-11 02:40:34 +0800659 unsigned long tmp;
660 static int count = 0;
661 char *name;
Yu Luming2f3d0002006-11-11 02:40:34 +0800662 name = kzalloc(MAX_NAME_LEN, GFP_KERNEL);
663 if (!name)
664 return;
665
Yu Luming2f3d0002006-11-11 02:40:34 +0800666 sprintf(name, "acpi_video%d", count++);
Yu Luming2f3d0002006-11-11 02:40:34 +0800667 acpi_video_device_lcd_get_level_current(device, &tmp);
Yu Luming2f3d0002006-11-11 02:40:34 +0800668 device->backlight = backlight_device_register(name,
Richard Purdie599a52d2007-02-10 23:07:48 +0000669 NULL, device, &acpi_backlight_ops);
670 device->backlight->props.max_brightness = max_level;
671 device->backlight->props.brightness = (int)tmp;
672 backlight_update_status(device->backlight);
673
Yu Luming2f3d0002006-11-11 02:40:34 +0800674 kfree(name);
675 }
Luming Yu23b0f012007-05-09 21:07:05 +0800676 if (device->cap._DCS && device->cap._DSS){
677 static int count = 0;
678 char *name;
679 name = kzalloc(MAX_NAME_LEN, GFP_KERNEL);
680 if (!name)
681 return;
682 sprintf(name, "acpi_video%d", count++);
683 device->output_dev = video_output_register(name,
684 NULL, device, &acpi_output_properties);
685 kfree(name);
686 }
Patrick Mocheld550d982006-06-27 00:41:40 -0400687 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700688}
689
690/*
691 * Arg:
692 * device : video output device (VGA)
693 *
694 * Return Value:
695 * None
696 *
Julius Volz98fb8fe2007-02-20 16:38:40 +0100697 * Find out all required AML methods defined under the video bus device.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700698 */
699
Len Brown4be44fc2005-08-05 00:44:28 -0400700static void acpi_video_bus_find_cap(struct acpi_video_bus *video)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700701{
Len Brown4be44fc2005-08-05 00:44:28 -0400702 acpi_handle h_dummy1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700703
William Lee Irwin III98934de2007-12-12 03:56:55 -0800704 memset(&video->cap, 0, sizeof(video->cap));
Patrick Mochel90130262006-05-19 16:54:48 -0400705 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_DOS", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700706 video->cap._DOS = 1;
707 }
Patrick Mochel90130262006-05-19 16:54:48 -0400708 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_DOD", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700709 video->cap._DOD = 1;
710 }
Patrick Mochel90130262006-05-19 16:54:48 -0400711 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_ROM", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700712 video->cap._ROM = 1;
713 }
Patrick Mochel90130262006-05-19 16:54:48 -0400714 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_GPD", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700715 video->cap._GPD = 1;
716 }
Patrick Mochel90130262006-05-19 16:54:48 -0400717 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_SPD", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700718 video->cap._SPD = 1;
719 }
Patrick Mochel90130262006-05-19 16:54:48 -0400720 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_VPO", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700721 video->cap._VPO = 1;
722 }
723}
724
725/*
726 * Check whether the video bus device has required AML method to
727 * support the desired features
728 */
729
Len Brown4be44fc2005-08-05 00:44:28 -0400730static int acpi_video_bus_check(struct acpi_video_bus *video)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700731{
Len Brown4be44fc2005-08-05 00:44:28 -0400732 acpi_status status = -ENOENT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700733
Linus Torvalds1da177e2005-04-16 15:20:36 -0700734
735 if (!video)
Patrick Mocheld550d982006-06-27 00:41:40 -0400736 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700737
738 /* Since there is no HID, CID and so on for VGA driver, we have
739 * to check well known required nodes.
740 */
741
Julius Volz98fb8fe2007-02-20 16:38:40 +0100742 /* Does this device support video switching? */
Len Brown4be44fc2005-08-05 00:44:28 -0400743 if (video->cap._DOS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700744 video->flags.multihead = 1;
745 status = 0;
746 }
747
Julius Volz98fb8fe2007-02-20 16:38:40 +0100748 /* Does this device support retrieving a video ROM? */
Len Brown4be44fc2005-08-05 00:44:28 -0400749 if (video->cap._ROM) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700750 video->flags.rom = 1;
751 status = 0;
752 }
753
Julius Volz98fb8fe2007-02-20 16:38:40 +0100754 /* Does this device support configuring which video device to POST? */
Len Brown4be44fc2005-08-05 00:44:28 -0400755 if (video->cap._GPD && video->cap._SPD && video->cap._VPO) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700756 video->flags.post = 1;
757 status = 0;
758 }
759
Patrick Mocheld550d982006-06-27 00:41:40 -0400760 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700761}
762
763/* --------------------------------------------------------------------------
764 FS Interface (/proc)
765 -------------------------------------------------------------------------- */
766
Len Brown4be44fc2005-08-05 00:44:28 -0400767static struct proc_dir_entry *acpi_video_dir;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700768
769/* video devices */
770
Len Brown4be44fc2005-08-05 00:44:28 -0400771static int acpi_video_device_info_seq_show(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700772{
Jan Engelhardt50dd0962006-10-01 00:28:50 +0200773 struct acpi_video_device *dev = seq->private;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700774
Linus Torvalds1da177e2005-04-16 15:20:36 -0700775
776 if (!dev)
777 goto end;
778
779 seq_printf(seq, "device_id: 0x%04x\n", (u32) dev->device_id);
780 seq_printf(seq, "type: ");
781 if (dev->flags.crt)
782 seq_printf(seq, "CRT\n");
783 else if (dev->flags.lcd)
784 seq_printf(seq, "LCD\n");
785 else if (dev->flags.tvout)
786 seq_printf(seq, "TVOUT\n");
Rui Zhang82cae992007-01-03 23:40:53 -0500787 else if (dev->flags.dvi)
788 seq_printf(seq, "DVI\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700789 else
790 seq_printf(seq, "UNKNOWN\n");
791
Len Brown4be44fc2005-08-05 00:44:28 -0400792 seq_printf(seq, "known by bios: %s\n", dev->flags.bios ? "yes" : "no");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700793
Len Brown4be44fc2005-08-05 00:44:28 -0400794 end:
Patrick Mocheld550d982006-06-27 00:41:40 -0400795 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700796}
797
798static int
Len Brown4be44fc2005-08-05 00:44:28 -0400799acpi_video_device_info_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700800{
801 return single_open(file, acpi_video_device_info_seq_show,
802 PDE(inode)->data);
803}
804
Len Brown4be44fc2005-08-05 00:44:28 -0400805static int acpi_video_device_state_seq_show(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700806{
Len Brown4be44fc2005-08-05 00:44:28 -0400807 int status;
Jan Engelhardt50dd0962006-10-01 00:28:50 +0200808 struct acpi_video_device *dev = seq->private;
Len Brown4be44fc2005-08-05 00:44:28 -0400809 unsigned long state;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700810
Linus Torvalds1da177e2005-04-16 15:20:36 -0700811
812 if (!dev)
813 goto end;
814
815 status = acpi_video_device_get_state(dev, &state);
816 seq_printf(seq, "state: ");
817 if (ACPI_SUCCESS(status))
818 seq_printf(seq, "0x%02lx\n", state);
819 else
820 seq_printf(seq, "<not supported>\n");
821
822 status = acpi_video_device_query(dev, &state);
823 seq_printf(seq, "query: ");
824 if (ACPI_SUCCESS(status))
825 seq_printf(seq, "0x%02lx\n", state);
826 else
827 seq_printf(seq, "<not supported>\n");
828
Len Brown4be44fc2005-08-05 00:44:28 -0400829 end:
Patrick Mocheld550d982006-06-27 00:41:40 -0400830 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700831}
832
833static int
Len Brown4be44fc2005-08-05 00:44:28 -0400834acpi_video_device_state_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700835{
836 return single_open(file, acpi_video_device_state_seq_show,
837 PDE(inode)->data);
838}
839
840static ssize_t
Len Brown4be44fc2005-08-05 00:44:28 -0400841acpi_video_device_write_state(struct file *file,
842 const char __user * buffer,
843 size_t count, loff_t * data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700844{
Len Brown4be44fc2005-08-05 00:44:28 -0400845 int status;
Jan Engelhardt50dd0962006-10-01 00:28:50 +0200846 struct seq_file *m = file->private_data;
847 struct acpi_video_device *dev = m->private;
Len Brown4be44fc2005-08-05 00:44:28 -0400848 char str[12] = { 0 };
849 u32 state = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700850
Linus Torvalds1da177e2005-04-16 15:20:36 -0700851
852 if (!dev || count + 1 > sizeof str)
Patrick Mocheld550d982006-06-27 00:41:40 -0400853 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700854
855 if (copy_from_user(str, buffer, count))
Patrick Mocheld550d982006-06-27 00:41:40 -0400856 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700857
858 str[count] = 0;
859 state = simple_strtoul(str, NULL, 0);
Len Brown4be44fc2005-08-05 00:44:28 -0400860 state &= ((1ul << 31) | (1ul << 30) | (1ul << 0));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700861
862 status = acpi_video_device_set_state(dev, state);
863
864 if (status)
Patrick Mocheld550d982006-06-27 00:41:40 -0400865 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700866
Patrick Mocheld550d982006-06-27 00:41:40 -0400867 return count;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700868}
869
870static int
Len Brown4be44fc2005-08-05 00:44:28 -0400871acpi_video_device_brightness_seq_show(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700872{
Jan Engelhardt50dd0962006-10-01 00:28:50 +0200873 struct acpi_video_device *dev = seq->private;
Len Brown4be44fc2005-08-05 00:44:28 -0400874 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700875
Linus Torvalds1da177e2005-04-16 15:20:36 -0700876
877 if (!dev || !dev->brightness) {
878 seq_printf(seq, "<not supported>\n");
Patrick Mocheld550d982006-06-27 00:41:40 -0400879 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700880 }
881
882 seq_printf(seq, "levels: ");
883 for (i = 0; i < dev->brightness->count; i++)
884 seq_printf(seq, " %d", dev->brightness->levels[i]);
885 seq_printf(seq, "\ncurrent: %d\n", dev->brightness->curr);
886
Patrick Mocheld550d982006-06-27 00:41:40 -0400887 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700888}
889
890static int
Len Brown4be44fc2005-08-05 00:44:28 -0400891acpi_video_device_brightness_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700892{
893 return single_open(file, acpi_video_device_brightness_seq_show,
894 PDE(inode)->data);
895}
896
897static ssize_t
Len Brown4be44fc2005-08-05 00:44:28 -0400898acpi_video_device_write_brightness(struct file *file,
899 const char __user * buffer,
900 size_t count, loff_t * data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700901{
Jan Engelhardt50dd0962006-10-01 00:28:50 +0200902 struct seq_file *m = file->private_data;
903 struct acpi_video_device *dev = m->private;
Danny Baumannc88c5782007-11-02 13:47:53 +0100904 char str[5] = { 0 };
Len Brown4be44fc2005-08-05 00:44:28 -0400905 unsigned int level = 0;
906 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700907
Linus Torvalds1da177e2005-04-16 15:20:36 -0700908
Thomas Renninger59d399d2005-11-08 05:27:00 -0500909 if (!dev || !dev->brightness || count + 1 > sizeof str)
Patrick Mocheld550d982006-06-27 00:41:40 -0400910 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700911
912 if (copy_from_user(str, buffer, count))
Patrick Mocheld550d982006-06-27 00:41:40 -0400913 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700914
915 str[count] = 0;
916 level = simple_strtoul(str, NULL, 0);
Len Brown4be44fc2005-08-05 00:44:28 -0400917
Linus Torvalds1da177e2005-04-16 15:20:36 -0700918 if (level > 100)
Patrick Mocheld550d982006-06-27 00:41:40 -0400919 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700920
Julius Volz98fb8fe2007-02-20 16:38:40 +0100921 /* validate through the list of available levels */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700922 for (i = 0; i < dev->brightness->count; i++)
923 if (level == dev->brightness->levels[i]) {
Len Brown4be44fc2005-08-05 00:44:28 -0400924 if (ACPI_SUCCESS
925 (acpi_video_device_lcd_set_level(dev, level)))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700926 dev->brightness->curr = level;
927 break;
928 }
929
Patrick Mocheld550d982006-06-27 00:41:40 -0400930 return count;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700931}
932
Len Brown4be44fc2005-08-05 00:44:28 -0400933static int acpi_video_device_EDID_seq_show(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700934{
Jan Engelhardt50dd0962006-10-01 00:28:50 +0200935 struct acpi_video_device *dev = seq->private;
Len Brown4be44fc2005-08-05 00:44:28 -0400936 int status;
937 int i;
938 union acpi_object *edid = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700939
Linus Torvalds1da177e2005-04-16 15:20:36 -0700940
941 if (!dev)
942 goto out;
943
Len Brown4be44fc2005-08-05 00:44:28 -0400944 status = acpi_video_device_EDID(dev, &edid, 128);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700945 if (ACPI_FAILURE(status)) {
Len Brown4be44fc2005-08-05 00:44:28 -0400946 status = acpi_video_device_EDID(dev, &edid, 256);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700947 }
948
949 if (ACPI_FAILURE(status)) {
950 goto out;
951 }
952
953 if (edid && edid->type == ACPI_TYPE_BUFFER) {
954 for (i = 0; i < edid->buffer.length; i++)
955 seq_putc(seq, edid->buffer.pointer[i]);
956 }
957
Len Brown4be44fc2005-08-05 00:44:28 -0400958 out:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700959 if (!edid)
960 seq_printf(seq, "<not supported>\n");
961 else
962 kfree(edid);
963
Patrick Mocheld550d982006-06-27 00:41:40 -0400964 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700965}
966
967static int
Len Brown4be44fc2005-08-05 00:44:28 -0400968acpi_video_device_EDID_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700969{
970 return single_open(file, acpi_video_device_EDID_seq_show,
971 PDE(inode)->data);
972}
973
Len Brown4be44fc2005-08-05 00:44:28 -0400974static int acpi_video_device_add_fs(struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700975{
Len Brown4be44fc2005-08-05 00:44:28 -0400976 struct proc_dir_entry *entry = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700977 struct acpi_video_device *vid_dev;
978
Linus Torvalds1da177e2005-04-16 15:20:36 -0700979
980 if (!device)
Patrick Mocheld550d982006-06-27 00:41:40 -0400981 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700982
Jan Engelhardt50dd0962006-10-01 00:28:50 +0200983 vid_dev = acpi_driver_data(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700984 if (!vid_dev)
Patrick Mocheld550d982006-06-27 00:41:40 -0400985 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700986
987 if (!acpi_device_dir(device)) {
988 acpi_device_dir(device) = proc_mkdir(acpi_device_bid(device),
Len Brown4be44fc2005-08-05 00:44:28 -0400989 vid_dev->video->dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700990 if (!acpi_device_dir(device))
Patrick Mocheld550d982006-06-27 00:41:40 -0400991 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700992 acpi_device_dir(device)->owner = THIS_MODULE;
993 }
994
995 /* 'info' [R] */
996 entry = create_proc_entry("info", S_IRUGO, acpi_device_dir(device));
997 if (!entry)
Patrick Mocheld550d982006-06-27 00:41:40 -0400998 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700999 else {
1000 entry->proc_fops = &acpi_video_device_info_fops;
1001 entry->data = acpi_driver_data(device);
1002 entry->owner = THIS_MODULE;
1003 }
1004
1005 /* 'state' [R/W] */
Len Brown4be44fc2005-08-05 00:44:28 -04001006 entry =
1007 create_proc_entry("state", S_IFREG | S_IRUGO | S_IWUSR,
1008 acpi_device_dir(device));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001009 if (!entry)
Patrick Mocheld550d982006-06-27 00:41:40 -04001010 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001011 else {
Arjan van de Vend479e902006-01-06 16:47:00 -05001012 acpi_video_device_state_fops.write = acpi_video_device_write_state;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001013 entry->proc_fops = &acpi_video_device_state_fops;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001014 entry->data = acpi_driver_data(device);
1015 entry->owner = THIS_MODULE;
1016 }
1017
1018 /* 'brightness' [R/W] */
Len Brown4be44fc2005-08-05 00:44:28 -04001019 entry =
1020 create_proc_entry("brightness", S_IFREG | S_IRUGO | S_IWUSR,
1021 acpi_device_dir(device));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001022 if (!entry)
Patrick Mocheld550d982006-06-27 00:41:40 -04001023 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001024 else {
Arjan van de Vend479e902006-01-06 16:47:00 -05001025 acpi_video_device_brightness_fops.write = acpi_video_device_write_brightness;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001026 entry->proc_fops = &acpi_video_device_brightness_fops;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001027 entry->data = acpi_driver_data(device);
1028 entry->owner = THIS_MODULE;
1029 }
1030
1031 /* 'EDID' [R] */
1032 entry = create_proc_entry("EDID", S_IRUGO, acpi_device_dir(device));
1033 if (!entry)
Patrick Mocheld550d982006-06-27 00:41:40 -04001034 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001035 else {
1036 entry->proc_fops = &acpi_video_device_EDID_fops;
1037 entry->data = acpi_driver_data(device);
1038 entry->owner = THIS_MODULE;
1039 }
1040
Patrick Mocheld550d982006-06-27 00:41:40 -04001041 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001042}
1043
Len Brown4be44fc2005-08-05 00:44:28 -04001044static int acpi_video_device_remove_fs(struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001045{
1046 struct acpi_video_device *vid_dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001047
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001048 vid_dev = acpi_driver_data(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001049 if (!vid_dev || !vid_dev->video || !vid_dev->video->dir)
Patrick Mocheld550d982006-06-27 00:41:40 -04001050 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001051
1052 if (acpi_device_dir(device)) {
1053 remove_proc_entry("info", acpi_device_dir(device));
1054 remove_proc_entry("state", acpi_device_dir(device));
1055 remove_proc_entry("brightness", acpi_device_dir(device));
1056 remove_proc_entry("EDID", acpi_device_dir(device));
Len Brown4be44fc2005-08-05 00:44:28 -04001057 remove_proc_entry(acpi_device_bid(device), vid_dev->video->dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001058 acpi_device_dir(device) = NULL;
1059 }
1060
Patrick Mocheld550d982006-06-27 00:41:40 -04001061 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001062}
1063
Linus Torvalds1da177e2005-04-16 15:20:36 -07001064/* video bus */
Len Brown4be44fc2005-08-05 00:44:28 -04001065static int acpi_video_bus_info_seq_show(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001066{
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001067 struct acpi_video_bus *video = seq->private;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001068
Linus Torvalds1da177e2005-04-16 15:20:36 -07001069
1070 if (!video)
1071 goto end;
1072
1073 seq_printf(seq, "Switching heads: %s\n",
Len Brown4be44fc2005-08-05 00:44:28 -04001074 video->flags.multihead ? "yes" : "no");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001075 seq_printf(seq, "Video ROM: %s\n",
Len Brown4be44fc2005-08-05 00:44:28 -04001076 video->flags.rom ? "yes" : "no");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001077 seq_printf(seq, "Device to be POSTed on boot: %s\n",
Len Brown4be44fc2005-08-05 00:44:28 -04001078 video->flags.post ? "yes" : "no");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001079
Len Brown4be44fc2005-08-05 00:44:28 -04001080 end:
Patrick Mocheld550d982006-06-27 00:41:40 -04001081 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001082}
1083
Len Brown4be44fc2005-08-05 00:44:28 -04001084static int acpi_video_bus_info_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001085{
Len Brown4be44fc2005-08-05 00:44:28 -04001086 return single_open(file, acpi_video_bus_info_seq_show,
1087 PDE(inode)->data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001088}
1089
Len Brown4be44fc2005-08-05 00:44:28 -04001090static int acpi_video_bus_ROM_seq_show(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001091{
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001092 struct acpi_video_bus *video = seq->private;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001093
Linus Torvalds1da177e2005-04-16 15:20:36 -07001094
1095 if (!video)
1096 goto end;
1097
1098 printk(KERN_INFO PREFIX "Please implement %s\n", __FUNCTION__);
1099 seq_printf(seq, "<TODO>\n");
1100
Len Brown4be44fc2005-08-05 00:44:28 -04001101 end:
Patrick Mocheld550d982006-06-27 00:41:40 -04001102 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001103}
1104
Len Brown4be44fc2005-08-05 00:44:28 -04001105static int acpi_video_bus_ROM_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001106{
1107 return single_open(file, acpi_video_bus_ROM_seq_show, PDE(inode)->data);
1108}
1109
Len Brown4be44fc2005-08-05 00:44:28 -04001110static int acpi_video_bus_POST_info_seq_show(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001111{
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001112 struct acpi_video_bus *video = seq->private;
Len Brown4be44fc2005-08-05 00:44:28 -04001113 unsigned long options;
1114 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001115
Linus Torvalds1da177e2005-04-16 15:20:36 -07001116
1117 if (!video)
1118 goto end;
1119
1120 status = acpi_video_bus_POST_options(video, &options);
1121 if (ACPI_SUCCESS(status)) {
1122 if (!(options & 1)) {
Len Brown4be44fc2005-08-05 00:44:28 -04001123 printk(KERN_WARNING PREFIX
1124 "The motherboard VGA device is not listed as a possible POST device.\n");
1125 printk(KERN_WARNING PREFIX
Julius Volz98fb8fe2007-02-20 16:38:40 +01001126 "This indicates a BIOS bug. Please contact the manufacturer.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001127 }
1128 printk("%lx\n", options);
Julius Volz98fb8fe2007-02-20 16:38:40 +01001129 seq_printf(seq, "can POST: <integrated video>");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001130 if (options & 2)
1131 seq_printf(seq, " <PCI video>");
1132 if (options & 4)
1133 seq_printf(seq, " <AGP video>");
1134 seq_putc(seq, '\n');
1135 } else
1136 seq_printf(seq, "<not supported>\n");
Len Brown4be44fc2005-08-05 00:44:28 -04001137 end:
Patrick Mocheld550d982006-06-27 00:41:40 -04001138 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001139}
1140
1141static int
Len Brown4be44fc2005-08-05 00:44:28 -04001142acpi_video_bus_POST_info_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001143{
Len Brown4be44fc2005-08-05 00:44:28 -04001144 return single_open(file, acpi_video_bus_POST_info_seq_show,
1145 PDE(inode)->data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001146}
1147
Len Brown4be44fc2005-08-05 00:44:28 -04001148static int acpi_video_bus_POST_seq_show(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001149{
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001150 struct acpi_video_bus *video = seq->private;
Len Brown4be44fc2005-08-05 00:44:28 -04001151 int status;
1152 unsigned long id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001153
Linus Torvalds1da177e2005-04-16 15:20:36 -07001154
1155 if (!video)
1156 goto end;
1157
Len Brown4be44fc2005-08-05 00:44:28 -04001158 status = acpi_video_bus_get_POST(video, &id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001159 if (!ACPI_SUCCESS(status)) {
1160 seq_printf(seq, "<not supported>\n");
1161 goto end;
1162 }
Julius Volz98fb8fe2007-02-20 16:38:40 +01001163 seq_printf(seq, "device POSTed is <%s>\n", device_decode[id & 3]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001164
Len Brown4be44fc2005-08-05 00:44:28 -04001165 end:
Patrick Mocheld550d982006-06-27 00:41:40 -04001166 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001167}
1168
Len Brown4be44fc2005-08-05 00:44:28 -04001169static int acpi_video_bus_DOS_seq_show(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001170{
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001171 struct acpi_video_bus *video = seq->private;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001172
Linus Torvalds1da177e2005-04-16 15:20:36 -07001173
Len Brown4be44fc2005-08-05 00:44:28 -04001174 seq_printf(seq, "DOS setting: <%d>\n", video->dos_setting);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001175
Patrick Mocheld550d982006-06-27 00:41:40 -04001176 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001177}
1178
Len Brown4be44fc2005-08-05 00:44:28 -04001179static int acpi_video_bus_POST_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001180{
Len Brown4be44fc2005-08-05 00:44:28 -04001181 return single_open(file, acpi_video_bus_POST_seq_show,
1182 PDE(inode)->data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001183}
1184
Len Brown4be44fc2005-08-05 00:44:28 -04001185static int acpi_video_bus_DOS_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001186{
1187 return single_open(file, acpi_video_bus_DOS_seq_show, PDE(inode)->data);
1188}
1189
1190static ssize_t
Len Brown4be44fc2005-08-05 00:44:28 -04001191acpi_video_bus_write_POST(struct file *file,
1192 const char __user * buffer,
1193 size_t count, loff_t * data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001194{
Len Brown4be44fc2005-08-05 00:44:28 -04001195 int status;
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001196 struct seq_file *m = file->private_data;
1197 struct acpi_video_bus *video = m->private;
Len Brown4be44fc2005-08-05 00:44:28 -04001198 char str[12] = { 0 };
1199 unsigned long opt, options;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001200
Linus Torvalds1da177e2005-04-16 15:20:36 -07001201
Linus Torvalds1da177e2005-04-16 15:20:36 -07001202 if (!video || count + 1 > sizeof str)
Patrick Mocheld550d982006-06-27 00:41:40 -04001203 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001204
1205 status = acpi_video_bus_POST_options(video, &options);
1206 if (!ACPI_SUCCESS(status))
Patrick Mocheld550d982006-06-27 00:41:40 -04001207 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001208
1209 if (copy_from_user(str, buffer, count))
Patrick Mocheld550d982006-06-27 00:41:40 -04001210 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001211
1212 str[count] = 0;
1213 opt = strtoul(str, NULL, 0);
1214 if (opt > 3)
Patrick Mocheld550d982006-06-27 00:41:40 -04001215 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001216
Julius Volz98fb8fe2007-02-20 16:38:40 +01001217 /* just in case an OEM 'forgot' the motherboard... */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001218 options |= 1;
1219
1220 if (options & (1ul << opt)) {
Len Brown4be44fc2005-08-05 00:44:28 -04001221 status = acpi_video_bus_set_POST(video, opt);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001222 if (!ACPI_SUCCESS(status))
Patrick Mocheld550d982006-06-27 00:41:40 -04001223 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001224
1225 }
1226
Patrick Mocheld550d982006-06-27 00:41:40 -04001227 return count;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001228}
1229
1230static ssize_t
Len Brown4be44fc2005-08-05 00:44:28 -04001231acpi_video_bus_write_DOS(struct file *file,
1232 const char __user * buffer,
1233 size_t count, loff_t * data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001234{
Len Brown4be44fc2005-08-05 00:44:28 -04001235 int status;
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001236 struct seq_file *m = file->private_data;
1237 struct acpi_video_bus *video = m->private;
Len Brown4be44fc2005-08-05 00:44:28 -04001238 char str[12] = { 0 };
1239 unsigned long opt;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001240
Linus Torvalds1da177e2005-04-16 15:20:36 -07001241
Linus Torvalds1da177e2005-04-16 15:20:36 -07001242 if (!video || count + 1 > sizeof str)
Patrick Mocheld550d982006-06-27 00:41:40 -04001243 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001244
1245 if (copy_from_user(str, buffer, count))
Patrick Mocheld550d982006-06-27 00:41:40 -04001246 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001247
1248 str[count] = 0;
1249 opt = strtoul(str, NULL, 0);
1250 if (opt > 7)
Patrick Mocheld550d982006-06-27 00:41:40 -04001251 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001252
Len Brown4be44fc2005-08-05 00:44:28 -04001253 status = acpi_video_bus_DOS(video, opt & 0x3, (opt & 0x4) >> 2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001254
1255 if (!ACPI_SUCCESS(status))
Patrick Mocheld550d982006-06-27 00:41:40 -04001256 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001257
Patrick Mocheld550d982006-06-27 00:41:40 -04001258 return count;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001259}
1260
Len Brown4be44fc2005-08-05 00:44:28 -04001261static int acpi_video_bus_add_fs(struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001262{
Len Brown4be44fc2005-08-05 00:44:28 -04001263 struct proc_dir_entry *entry = NULL;
1264 struct acpi_video_bus *video;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001265
Linus Torvalds1da177e2005-04-16 15:20:36 -07001266
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001267 video = acpi_driver_data(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001268
1269 if (!acpi_device_dir(device)) {
1270 acpi_device_dir(device) = proc_mkdir(acpi_device_bid(device),
Len Brown4be44fc2005-08-05 00:44:28 -04001271 acpi_video_dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001272 if (!acpi_device_dir(device))
Patrick Mocheld550d982006-06-27 00:41:40 -04001273 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001274 video->dir = acpi_device_dir(device);
1275 acpi_device_dir(device)->owner = THIS_MODULE;
1276 }
1277
1278 /* 'info' [R] */
1279 entry = create_proc_entry("info", S_IRUGO, acpi_device_dir(device));
1280 if (!entry)
Patrick Mocheld550d982006-06-27 00:41:40 -04001281 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001282 else {
1283 entry->proc_fops = &acpi_video_bus_info_fops;
1284 entry->data = acpi_driver_data(device);
1285 entry->owner = THIS_MODULE;
1286 }
1287
1288 /* 'ROM' [R] */
1289 entry = create_proc_entry("ROM", S_IRUGO, acpi_device_dir(device));
1290 if (!entry)
Patrick Mocheld550d982006-06-27 00:41:40 -04001291 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001292 else {
1293 entry->proc_fops = &acpi_video_bus_ROM_fops;
1294 entry->data = acpi_driver_data(device);
1295 entry->owner = THIS_MODULE;
1296 }
1297
1298 /* 'POST_info' [R] */
Len Brown4be44fc2005-08-05 00:44:28 -04001299 entry =
1300 create_proc_entry("POST_info", S_IRUGO, acpi_device_dir(device));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001301 if (!entry)
Patrick Mocheld550d982006-06-27 00:41:40 -04001302 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001303 else {
1304 entry->proc_fops = &acpi_video_bus_POST_info_fops;
1305 entry->data = acpi_driver_data(device);
1306 entry->owner = THIS_MODULE;
1307 }
1308
1309 /* 'POST' [R/W] */
Len Brown4be44fc2005-08-05 00:44:28 -04001310 entry =
1311 create_proc_entry("POST", S_IFREG | S_IRUGO | S_IRUSR,
1312 acpi_device_dir(device));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001313 if (!entry)
Patrick Mocheld550d982006-06-27 00:41:40 -04001314 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001315 else {
Arjan van de Vend479e902006-01-06 16:47:00 -05001316 acpi_video_bus_POST_fops.write = acpi_video_bus_write_POST;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001317 entry->proc_fops = &acpi_video_bus_POST_fops;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001318 entry->data = acpi_driver_data(device);
1319 entry->owner = THIS_MODULE;
1320 }
1321
1322 /* 'DOS' [R/W] */
Len Brown4be44fc2005-08-05 00:44:28 -04001323 entry =
1324 create_proc_entry("DOS", S_IFREG | S_IRUGO | S_IRUSR,
1325 acpi_device_dir(device));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001326 if (!entry)
Patrick Mocheld550d982006-06-27 00:41:40 -04001327 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001328 else {
Arjan van de Vend479e902006-01-06 16:47:00 -05001329 acpi_video_bus_DOS_fops.write = acpi_video_bus_write_DOS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001330 entry->proc_fops = &acpi_video_bus_DOS_fops;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001331 entry->data = acpi_driver_data(device);
1332 entry->owner = THIS_MODULE;
1333 }
1334
Patrick Mocheld550d982006-06-27 00:41:40 -04001335 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001336}
1337
Len Brown4be44fc2005-08-05 00:44:28 -04001338static int acpi_video_bus_remove_fs(struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001339{
Len Brown4be44fc2005-08-05 00:44:28 -04001340 struct acpi_video_bus *video;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001341
Linus Torvalds1da177e2005-04-16 15:20:36 -07001342
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001343 video = acpi_driver_data(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001344
1345 if (acpi_device_dir(device)) {
1346 remove_proc_entry("info", acpi_device_dir(device));
1347 remove_proc_entry("ROM", acpi_device_dir(device));
1348 remove_proc_entry("POST_info", acpi_device_dir(device));
1349 remove_proc_entry("POST", acpi_device_dir(device));
1350 remove_proc_entry("DOS", acpi_device_dir(device));
Len Brown4be44fc2005-08-05 00:44:28 -04001351 remove_proc_entry(acpi_device_bid(device), acpi_video_dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001352 acpi_device_dir(device) = NULL;
1353 }
1354
Patrick Mocheld550d982006-06-27 00:41:40 -04001355 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001356}
1357
1358/* --------------------------------------------------------------------------
1359 Driver Interface
1360 -------------------------------------------------------------------------- */
1361
1362/* device interface */
Rui Zhang82cae992007-01-03 23:40:53 -05001363static struct acpi_video_device_attrib*
1364acpi_video_get_device_attr(struct acpi_video_bus *video, unsigned long device_id)
1365{
1366 int count;
1367
1368 for(count = 0; count < video->attached_count; count++)
1369 if((video->attached_array[count].value.int_val & 0xffff) == device_id)
1370 return &(video->attached_array[count].value.attrib);
1371 return NULL;
1372}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001373
1374static int
Len Brown4be44fc2005-08-05 00:44:28 -04001375acpi_video_bus_get_one_device(struct acpi_device *device,
1376 struct acpi_video_bus *video)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001377{
Len Brown4be44fc2005-08-05 00:44:28 -04001378 unsigned long device_id;
Yu, Luming973bf492006-04-27 05:25:00 -04001379 int status;
Len Brown4be44fc2005-08-05 00:44:28 -04001380 struct acpi_video_device *data;
Rui Zhang82cae992007-01-03 23:40:53 -05001381 struct acpi_video_device_attrib* attribute;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001382
1383 if (!device || !video)
Patrick Mocheld550d982006-06-27 00:41:40 -04001384 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001385
Len Brown4be44fc2005-08-05 00:44:28 -04001386 status =
1387 acpi_evaluate_integer(device->handle, "_ADR", NULL, &device_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001388 if (ACPI_SUCCESS(status)) {
1389
Burman Yan36bcbec2006-12-19 12:56:11 -08001390 data = kzalloc(sizeof(struct acpi_video_device), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001391 if (!data)
Patrick Mocheld550d982006-06-27 00:41:40 -04001392 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001393
Linus Torvalds1da177e2005-04-16 15:20:36 -07001394 strcpy(acpi_device_name(device), ACPI_VIDEO_DEVICE_NAME);
1395 strcpy(acpi_device_class(device), ACPI_VIDEO_CLASS);
1396 acpi_driver_data(device) = data;
1397
1398 data->device_id = device_id;
1399 data->video = video;
1400 data->dev = device;
1401
Rui Zhang82cae992007-01-03 23:40:53 -05001402 attribute = acpi_video_get_device_attr(video, device_id);
1403
1404 if((attribute != NULL) && attribute->device_id_scheme) {
1405 switch (attribute->display_type) {
1406 case ACPI_VIDEO_DISPLAY_CRT:
1407 data->flags.crt = 1;
1408 break;
1409 case ACPI_VIDEO_DISPLAY_TV:
1410 data->flags.tvout = 1;
1411 break;
1412 case ACPI_VIDEO_DISPLAY_DVI:
1413 data->flags.dvi = 1;
1414 break;
1415 case ACPI_VIDEO_DISPLAY_LCD:
1416 data->flags.lcd = 1;
1417 break;
1418 default:
1419 data->flags.unknown = 1;
1420 break;
1421 }
1422 if(attribute->bios_can_detect)
1423 data->flags.bios = 1;
1424 } else
Linus Torvalds1da177e2005-04-16 15:20:36 -07001425 data->flags.unknown = 1;
Len Brown4be44fc2005-08-05 00:44:28 -04001426
Linus Torvalds1da177e2005-04-16 15:20:36 -07001427 acpi_video_device_bind(video, data);
1428 acpi_video_device_find_cap(data);
1429
Patrick Mochel90130262006-05-19 16:54:48 -04001430 status = acpi_install_notify_handler(device->handle,
Len Brown4be44fc2005-08-05 00:44:28 -04001431 ACPI_DEVICE_NOTIFY,
1432 acpi_video_device_notify,
1433 data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001434 if (ACPI_FAILURE(status)) {
1435 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
Len Brown4be44fc2005-08-05 00:44:28 -04001436 "Error installing notify handler\n"));
Yu, Luming973bf492006-04-27 05:25:00 -04001437 if(data->brightness)
1438 kfree(data->brightness->levels);
1439 kfree(data->brightness);
1440 kfree(data);
1441 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001442 }
1443
Dmitry Torokhovbbac81f2007-11-05 11:43:32 -05001444 mutex_lock(&video->device_list_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001445 list_add_tail(&data->entry, &video->video_device_list);
Dmitry Torokhovbbac81f2007-11-05 11:43:32 -05001446 mutex_unlock(&video->device_list_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001447
1448 acpi_video_device_add_fs(device);
1449
Patrick Mocheld550d982006-06-27 00:41:40 -04001450 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001451 }
1452
Patrick Mocheld550d982006-06-27 00:41:40 -04001453 return -ENOENT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001454}
1455
1456/*
1457 * Arg:
1458 * video : video bus device
1459 *
1460 * Return:
1461 * none
1462 *
1463 * Enumerate the video device list of the video bus,
1464 * bind the ids with the corresponding video devices
1465 * under the video bus.
Len Brown4be44fc2005-08-05 00:44:28 -04001466 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001467
Len Brown4be44fc2005-08-05 00:44:28 -04001468static void acpi_video_device_rebind(struct acpi_video_bus *video)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001469{
Dmitry Torokhovff102ea2007-11-05 11:43:31 -05001470 struct acpi_video_device *dev;
1471
Dmitry Torokhovbbac81f2007-11-05 11:43:32 -05001472 mutex_lock(&video->device_list_lock);
Dmitry Torokhovff102ea2007-11-05 11:43:31 -05001473
1474 list_for_each_entry(dev, &video->video_device_list, entry)
Len Brown4be44fc2005-08-05 00:44:28 -04001475 acpi_video_device_bind(video, dev);
Dmitry Torokhovff102ea2007-11-05 11:43:31 -05001476
Dmitry Torokhovbbac81f2007-11-05 11:43:32 -05001477 mutex_unlock(&video->device_list_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001478}
1479
1480/*
1481 * Arg:
1482 * video : video bus device
1483 * device : video output device under the video
1484 * bus
1485 *
1486 * Return:
1487 * none
1488 *
1489 * Bind the ids with the corresponding video devices
1490 * under the video bus.
Len Brown4be44fc2005-08-05 00:44:28 -04001491 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001492
1493static void
Len Brown4be44fc2005-08-05 00:44:28 -04001494acpi_video_device_bind(struct acpi_video_bus *video,
1495 struct acpi_video_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001496{
Len Brown4be44fc2005-08-05 00:44:28 -04001497 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001498
1499#define IDS_VAL(i) video->attached_array[i].value.int_val
1500#define IDS_BIND(i) video->attached_array[i].bind_info
Len Brown4be44fc2005-08-05 00:44:28 -04001501
1502 for (i = 0; IDS_VAL(i) != ACPI_VIDEO_HEAD_INVALID &&
1503 i < video->attached_count; i++) {
1504 if (device->device_id == (IDS_VAL(i) & 0xffff)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001505 IDS_BIND(i) = device;
1506 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "device_bind %d\n", i));
1507 }
1508 }
1509#undef IDS_VAL
1510#undef IDS_BIND
1511}
1512
1513/*
1514 * Arg:
1515 * video : video bus device
1516 *
1517 * Return:
1518 * < 0 : error
1519 *
1520 * Call _DOD to enumerate all devices attached to display adapter
1521 *
Len Brown4be44fc2005-08-05 00:44:28 -04001522 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001523
1524static int acpi_video_device_enumerate(struct acpi_video_bus *video)
1525{
Len Brown4be44fc2005-08-05 00:44:28 -04001526 int status;
1527 int count;
1528 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001529 struct acpi_video_enumerated_device *active_device_list;
Len Brown4be44fc2005-08-05 00:44:28 -04001530 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
1531 union acpi_object *dod = NULL;
1532 union acpi_object *obj;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001533
Patrick Mochel90130262006-05-19 16:54:48 -04001534 status = acpi_evaluate_object(video->device->handle, "_DOD", NULL, &buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001535 if (!ACPI_SUCCESS(status)) {
Thomas Renningera6fc6722006-06-26 23:58:43 -04001536 ACPI_EXCEPTION((AE_INFO, status, "Evaluating _DOD"));
Patrick Mocheld550d982006-06-27 00:41:40 -04001537 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001538 }
1539
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001540 dod = buffer.pointer;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001541 if (!dod || (dod->type != ACPI_TYPE_PACKAGE)) {
Thomas Renningera6fc6722006-06-26 23:58:43 -04001542 ACPI_EXCEPTION((AE_INFO, status, "Invalid _DOD data"));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001543 status = -EFAULT;
1544 goto out;
1545 }
1546
1547 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found %d video heads in _DOD\n",
Len Brown4be44fc2005-08-05 00:44:28 -04001548 dod->package.count));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001549
Len Brown4be44fc2005-08-05 00:44:28 -04001550 active_device_list = kmalloc((1 +
1551 dod->package.count) *
1552 sizeof(struct
1553 acpi_video_enumerated_device),
1554 GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001555
1556 if (!active_device_list) {
1557 status = -ENOMEM;
1558 goto out;
1559 }
1560
1561 count = 0;
1562 for (i = 0; i < dod->package.count; i++) {
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001563 obj = &dod->package.elements[i];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001564
1565 if (obj->type != ACPI_TYPE_INTEGER) {
Len Brown64684632006-06-26 23:41:38 -04001566 printk(KERN_ERR PREFIX "Invalid _DOD data\n");
Len Brown4be44fc2005-08-05 00:44:28 -04001567 active_device_list[i].value.int_val =
1568 ACPI_VIDEO_HEAD_INVALID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001569 }
1570 active_device_list[i].value.int_val = obj->integer.value;
1571 active_device_list[i].bind_info = NULL;
Len Brown4be44fc2005-08-05 00:44:28 -04001572 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "dod element[%d] = %d\n", i,
1573 (int)obj->integer.value));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001574 count++;
1575 }
1576 active_device_list[count].value.int_val = ACPI_VIDEO_HEAD_END;
1577
Jesper Juhl6044ec82005-11-07 01:01:32 -08001578 kfree(video->attached_array);
Len Brown4be44fc2005-08-05 00:44:28 -04001579
Linus Torvalds1da177e2005-04-16 15:20:36 -07001580 video->attached_array = active_device_list;
1581 video->attached_count = count;
Len Brown4be44fc2005-08-05 00:44:28 -04001582 out:
Len Brown02438d82006-06-30 03:19:10 -04001583 kfree(buffer.pointer);
Patrick Mocheld550d982006-06-27 00:41:40 -04001584 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001585}
1586
Len Brown4be44fc2005-08-05 00:44:28 -04001587static int
1588acpi_video_get_next_level(struct acpi_video_device *device,
1589 u32 level_current, u32 event)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001590{
Alexey Starikovskiy63f0edf2007-09-03 16:30:08 +04001591 int min, max, min_above, max_below, i, l, delta = 255;
Thomas Tuttlef4715182006-12-19 12:56:14 -08001592 max = max_below = 0;
1593 min = min_above = 255;
Alexey Starikovskiy63f0edf2007-09-03 16:30:08 +04001594 /* Find closest level to level_current */
1595 for (i = 0; i < device->brightness->count; i++) {
1596 l = device->brightness->levels[i];
1597 if (abs(l - level_current) < abs(delta)) {
1598 delta = l - level_current;
1599 if (!delta)
1600 break;
1601 }
1602 }
1603 /* Ajust level_current to closest available level */
1604 level_current += delta;
Thomas Tuttlef4715182006-12-19 12:56:14 -08001605 for (i = 0; i < device->brightness->count; i++) {
1606 l = device->brightness->levels[i];
1607 if (l < min)
1608 min = l;
1609 if (l > max)
1610 max = l;
1611 if (l < min_above && l > level_current)
1612 min_above = l;
1613 if (l > max_below && l < level_current)
1614 max_below = l;
1615 }
1616
1617 switch (event) {
1618 case ACPI_VIDEO_NOTIFY_CYCLE_BRIGHTNESS:
1619 return (level_current < max) ? min_above : min;
1620 case ACPI_VIDEO_NOTIFY_INC_BRIGHTNESS:
1621 return (level_current < max) ? min_above : max;
1622 case ACPI_VIDEO_NOTIFY_DEC_BRIGHTNESS:
1623 return (level_current > min) ? max_below : min;
1624 case ACPI_VIDEO_NOTIFY_ZERO_BRIGHTNESS:
1625 case ACPI_VIDEO_NOTIFY_DISPLAY_OFF:
1626 return 0;
1627 default:
1628 return level_current;
1629 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001630}
1631
Linus Torvalds1da177e2005-04-16 15:20:36 -07001632static void
Len Brown4be44fc2005-08-05 00:44:28 -04001633acpi_video_switch_brightness(struct acpi_video_device *device, int event)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001634{
1635 unsigned long level_current, level_next;
1636 acpi_video_device_lcd_get_level_current(device, &level_current);
1637 level_next = acpi_video_get_next_level(device, level_current, event);
1638 acpi_video_device_lcd_set_level(device, level_next);
1639}
1640
1641static int
Len Brown4be44fc2005-08-05 00:44:28 -04001642acpi_video_bus_get_devices(struct acpi_video_bus *video,
1643 struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001644{
Len Brown4be44fc2005-08-05 00:44:28 -04001645 int status = 0;
Dmitry Torokhovff102ea2007-11-05 11:43:31 -05001646 struct acpi_device *dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001647
1648 acpi_video_device_enumerate(video);
1649
Dmitry Torokhovff102ea2007-11-05 11:43:31 -05001650 list_for_each_entry(dev, &device->children, node) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001651
1652 status = acpi_video_bus_get_one_device(dev, video);
1653 if (ACPI_FAILURE(status)) {
Thomas Renningera6fc6722006-06-26 23:58:43 -04001654 ACPI_EXCEPTION((AE_INFO, status, "Cant attach device"));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001655 continue;
1656 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001657 }
Patrick Mocheld550d982006-06-27 00:41:40 -04001658 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001659}
1660
Len Brown4be44fc2005-08-05 00:44:28 -04001661static int acpi_video_bus_put_one_device(struct acpi_video_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001662{
Karol Kozimor031ec772005-07-30 04:18:00 -04001663 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001664 struct acpi_video_bus *video;
1665
Linus Torvalds1da177e2005-04-16 15:20:36 -07001666
1667 if (!device || !device->video)
Patrick Mocheld550d982006-06-27 00:41:40 -04001668 return -ENOENT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001669
1670 video = device->video;
1671
Linus Torvalds1da177e2005-04-16 15:20:36 -07001672 acpi_video_device_remove_fs(device->dev);
1673
Patrick Mochel90130262006-05-19 16:54:48 -04001674 status = acpi_remove_notify_handler(device->dev->handle,
Len Brown4be44fc2005-08-05 00:44:28 -04001675 ACPI_DEVICE_NOTIFY,
1676 acpi_video_device_notify);
Richard Purdie599a52d2007-02-10 23:07:48 +00001677 backlight_device_unregister(device->backlight);
Luming Yu23b0f012007-05-09 21:07:05 +08001678 video_output_unregister(device->output_dev);
Dmitry Torokhovff102ea2007-11-05 11:43:31 -05001679
Patrick Mocheld550d982006-06-27 00:41:40 -04001680 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001681}
1682
Len Brown4be44fc2005-08-05 00:44:28 -04001683static int acpi_video_bus_put_devices(struct acpi_video_bus *video)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001684{
Len Brown4be44fc2005-08-05 00:44:28 -04001685 int status;
Dmitry Torokhovff102ea2007-11-05 11:43:31 -05001686 struct acpi_video_device *dev, *next;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001687
Dmitry Torokhovbbac81f2007-11-05 11:43:32 -05001688 mutex_lock(&video->device_list_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001689
Dmitry Torokhovff102ea2007-11-05 11:43:31 -05001690 list_for_each_entry_safe(dev, next, &video->video_device_list, entry) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001691
Dmitry Torokhovff102ea2007-11-05 11:43:31 -05001692 status = acpi_video_bus_put_one_device(dev);
Len Brown4be44fc2005-08-05 00:44:28 -04001693 if (ACPI_FAILURE(status))
1694 printk(KERN_WARNING PREFIX
1695 "hhuuhhuu bug in acpi video driver.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001696
Dmitry Torokhovff102ea2007-11-05 11:43:31 -05001697 if (dev->brightness) {
1698 kfree(dev->brightness->levels);
1699 kfree(dev->brightness);
1700 }
1701 list_del(&dev->entry);
1702 kfree(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001703 }
1704
Dmitry Torokhovbbac81f2007-11-05 11:43:32 -05001705 mutex_unlock(&video->device_list_lock);
Dmitry Torokhovff102ea2007-11-05 11:43:31 -05001706
Patrick Mocheld550d982006-06-27 00:41:40 -04001707 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001708}
1709
1710/* acpi_video interface */
1711
Len Brown4be44fc2005-08-05 00:44:28 -04001712static int acpi_video_bus_start_devices(struct acpi_video_bus *video)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001713{
Zhang Ruia21101c2007-09-14 11:46:22 +08001714 return acpi_video_bus_DOS(video, 0, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001715}
1716
Len Brown4be44fc2005-08-05 00:44:28 -04001717static int acpi_video_bus_stop_devices(struct acpi_video_bus *video)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001718{
1719 return acpi_video_bus_DOS(video, 0, 1);
1720}
1721
Len Brown4be44fc2005-08-05 00:44:28 -04001722static void acpi_video_bus_notify(acpi_handle handle, u32 event, void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001723{
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001724 struct acpi_video_bus *video = data;
Len Brown4be44fc2005-08-05 00:44:28 -04001725 struct acpi_device *device = NULL;
Luming Yue9dab192007-08-20 18:23:53 +08001726 struct input_dev *input;
1727 int keycode;
1728
Linus Torvalds1da177e2005-04-16 15:20:36 -07001729 if (!video)
Patrick Mocheld550d982006-06-27 00:41:40 -04001730 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001731
Patrick Mochele6afa0d2006-05-19 16:54:40 -04001732 device = video->device;
Luming Yue9dab192007-08-20 18:23:53 +08001733 input = video->input;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001734
1735 switch (event) {
Julius Volz98fb8fe2007-02-20 16:38:40 +01001736 case ACPI_VIDEO_NOTIFY_SWITCH: /* User requested a switch,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001737 * most likely via hotkey. */
Len Brown14e04fb2007-08-23 15:20:26 -04001738 acpi_bus_generate_proc_event(device, event, 0);
Luming Yue9dab192007-08-20 18:23:53 +08001739 keycode = KEY_SWITCHVIDEOMODE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001740 break;
1741
Julius Volz98fb8fe2007-02-20 16:38:40 +01001742 case ACPI_VIDEO_NOTIFY_PROBE: /* User plugged in or removed a video
Linus Torvalds1da177e2005-04-16 15:20:36 -07001743 * connector. */
1744 acpi_video_device_enumerate(video);
1745 acpi_video_device_rebind(video);
Len Brown14e04fb2007-08-23 15:20:26 -04001746 acpi_bus_generate_proc_event(device, event, 0);
Luming Yue9dab192007-08-20 18:23:53 +08001747 keycode = KEY_SWITCHVIDEOMODE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001748 break;
1749
Len Brown4be44fc2005-08-05 00:44:28 -04001750 case ACPI_VIDEO_NOTIFY_CYCLE: /* Cycle Display output hotkey pressed. */
Len Brown25c87f72007-08-25 01:44:01 -04001751 acpi_bus_generate_proc_event(device, event, 0);
Luming Yue9dab192007-08-20 18:23:53 +08001752 keycode = KEY_SWITCHVIDEOMODE;
1753 break;
Len Brown4be44fc2005-08-05 00:44:28 -04001754 case ACPI_VIDEO_NOTIFY_NEXT_OUTPUT: /* Next Display output hotkey pressed. */
Len Brown25c87f72007-08-25 01:44:01 -04001755 acpi_bus_generate_proc_event(device, event, 0);
Luming Yue9dab192007-08-20 18:23:53 +08001756 keycode = KEY_VIDEO_NEXT;
1757 break;
Len Brown4be44fc2005-08-05 00:44:28 -04001758 case ACPI_VIDEO_NOTIFY_PREV_OUTPUT: /* previous Display output hotkey pressed. */
Len Brown14e04fb2007-08-23 15:20:26 -04001759 acpi_bus_generate_proc_event(device, event, 0);
Luming Yue9dab192007-08-20 18:23:53 +08001760 keycode = KEY_VIDEO_PREV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001761 break;
1762
1763 default:
Luming Yue9dab192007-08-20 18:23:53 +08001764 keycode = KEY_UNKNOWN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001765 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
Len Brown4be44fc2005-08-05 00:44:28 -04001766 "Unsupported event [0x%x]\n", event));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001767 break;
1768 }
1769
Zhang Rui7761f632008-01-25 14:48:12 +08001770 acpi_notifier_call_chain(device, event, 0);
Luming Yue9dab192007-08-20 18:23:53 +08001771 input_report_key(input, keycode, 1);
1772 input_sync(input);
1773 input_report_key(input, keycode, 0);
1774 input_sync(input);
1775
Patrick Mocheld550d982006-06-27 00:41:40 -04001776 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001777}
1778
Len Brown4be44fc2005-08-05 00:44:28 -04001779static void acpi_video_device_notify(acpi_handle handle, u32 event, void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001780{
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001781 struct acpi_video_device *video_device = data;
Len Brown4be44fc2005-08-05 00:44:28 -04001782 struct acpi_device *device = NULL;
Luming Yue9dab192007-08-20 18:23:53 +08001783 struct acpi_video_bus *bus;
1784 struct input_dev *input;
1785 int keycode;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001786
Linus Torvalds1da177e2005-04-16 15:20:36 -07001787 if (!video_device)
Patrick Mocheld550d982006-06-27 00:41:40 -04001788 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001789
Patrick Mochele6afa0d2006-05-19 16:54:40 -04001790 device = video_device->dev;
Luming Yue9dab192007-08-20 18:23:53 +08001791 bus = video_device->video;
1792 input = bus->input;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001793
1794 switch (event) {
Len Brown4be44fc2005-08-05 00:44:28 -04001795 case ACPI_VIDEO_NOTIFY_CYCLE_BRIGHTNESS: /* Cycle brightness */
Zhang Rui8a681a42008-01-25 14:47:49 +08001796 if (brightness_switch_enabled)
1797 acpi_video_switch_brightness(video_device, event);
Len Brown25c87f72007-08-25 01:44:01 -04001798 acpi_bus_generate_proc_event(device, event, 0);
Luming Yue9dab192007-08-20 18:23:53 +08001799 keycode = KEY_BRIGHTNESS_CYCLE;
1800 break;
Len Brown4be44fc2005-08-05 00:44:28 -04001801 case ACPI_VIDEO_NOTIFY_INC_BRIGHTNESS: /* Increase brightness */
Zhang Rui8a681a42008-01-25 14:47:49 +08001802 if (brightness_switch_enabled)
1803 acpi_video_switch_brightness(video_device, event);
Len Brown25c87f72007-08-25 01:44:01 -04001804 acpi_bus_generate_proc_event(device, event, 0);
Luming Yue9dab192007-08-20 18:23:53 +08001805 keycode = KEY_BRIGHTNESSUP;
1806 break;
Len Brown4be44fc2005-08-05 00:44:28 -04001807 case ACPI_VIDEO_NOTIFY_DEC_BRIGHTNESS: /* Decrease brightness */
Zhang Rui8a681a42008-01-25 14:47:49 +08001808 if (brightness_switch_enabled)
1809 acpi_video_switch_brightness(video_device, event);
Len Brown25c87f72007-08-25 01:44:01 -04001810 acpi_bus_generate_proc_event(device, event, 0);
Luming Yue9dab192007-08-20 18:23:53 +08001811 keycode = KEY_BRIGHTNESSDOWN;
1812 break;
Len Brown4be44fc2005-08-05 00:44:28 -04001813 case ACPI_VIDEO_NOTIFY_ZERO_BRIGHTNESS: /* zero brightnesss */
Zhang Rui8a681a42008-01-25 14:47:49 +08001814 if (brightness_switch_enabled)
1815 acpi_video_switch_brightness(video_device, event);
Len Brown25c87f72007-08-25 01:44:01 -04001816 acpi_bus_generate_proc_event(device, event, 0);
Luming Yue9dab192007-08-20 18:23:53 +08001817 keycode = KEY_BRIGHTNESS_ZERO;
1818 break;
Len Brown4be44fc2005-08-05 00:44:28 -04001819 case ACPI_VIDEO_NOTIFY_DISPLAY_OFF: /* display device off */
Zhang Rui8a681a42008-01-25 14:47:49 +08001820 if (brightness_switch_enabled)
1821 acpi_video_switch_brightness(video_device, event);
Len Brown14e04fb2007-08-23 15:20:26 -04001822 acpi_bus_generate_proc_event(device, event, 0);
Luming Yue9dab192007-08-20 18:23:53 +08001823 keycode = KEY_DISPLAY_OFF;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001824 break;
1825 default:
Luming Yue9dab192007-08-20 18:23:53 +08001826 keycode = KEY_UNKNOWN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001827 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
Len Brown4be44fc2005-08-05 00:44:28 -04001828 "Unsupported event [0x%x]\n", event));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001829 break;
1830 }
Luming Yue9dab192007-08-20 18:23:53 +08001831
Zhang Rui7761f632008-01-25 14:48:12 +08001832 acpi_notifier_call_chain(device, event, 0);
Luming Yue9dab192007-08-20 18:23:53 +08001833 input_report_key(input, keycode, 1);
1834 input_sync(input);
1835 input_report_key(input, keycode, 0);
1836 input_sync(input);
1837
Patrick Mocheld550d982006-06-27 00:41:40 -04001838 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001839}
1840
Zhang Ruie6d9da12007-08-25 02:23:31 -04001841static int instance;
Matthew Garrett863c1492008-02-04 23:31:24 -08001842static int acpi_video_resume(struct acpi_device *device)
1843{
1844 struct acpi_video_bus *video;
1845 struct acpi_video_device *video_device;
1846 int i;
1847
1848 if (!device || !acpi_driver_data(device))
1849 return -EINVAL;
1850
1851 video = acpi_driver_data(device);
1852
1853 for (i = 0; i < video->attached_count; i++) {
1854 video_device = video->attached_array[i].bind_info;
1855 if (video_device && video_device->backlight)
1856 acpi_video_set_brightness(video_device->backlight);
1857 }
1858 return AE_OK;
1859}
1860
Len Brown4be44fc2005-08-05 00:44:28 -04001861static int acpi_video_bus_add(struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001862{
Dmitry Torokhovf51e8392007-11-05 11:43:30 -05001863 acpi_status status;
1864 struct acpi_video_bus *video;
Luming Yue9dab192007-08-20 18:23:53 +08001865 struct input_dev *input;
Dmitry Torokhovf51e8392007-11-05 11:43:30 -05001866 int error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001867
Burman Yan36bcbec2006-12-19 12:56:11 -08001868 video = kzalloc(sizeof(struct acpi_video_bus), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001869 if (!video)
Patrick Mocheld550d982006-06-27 00:41:40 -04001870 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001871
Zhang Ruie6d9da12007-08-25 02:23:31 -04001872 /* a hack to fix the duplicate name "VID" problem on T61 */
1873 if (!strcmp(device->pnp.bus_id, "VID")) {
1874 if (instance)
1875 device->pnp.bus_id[3] = '0' + instance;
1876 instance ++;
1877 }
1878
Patrick Mochele6afa0d2006-05-19 16:54:40 -04001879 video->device = device;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001880 strcpy(acpi_device_name(device), ACPI_VIDEO_BUS_NAME);
1881 strcpy(acpi_device_class(device), ACPI_VIDEO_CLASS);
1882 acpi_driver_data(device) = video;
1883
1884 acpi_video_bus_find_cap(video);
Dmitry Torokhovf51e8392007-11-05 11:43:30 -05001885 error = acpi_video_bus_check(video);
1886 if (error)
1887 goto err_free_video;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001888
Dmitry Torokhovf51e8392007-11-05 11:43:30 -05001889 error = acpi_video_bus_add_fs(device);
1890 if (error)
1891 goto err_free_video;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001892
Dmitry Torokhovbbac81f2007-11-05 11:43:32 -05001893 mutex_init(&video->device_list_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001894 INIT_LIST_HEAD(&video->video_device_list);
1895
1896 acpi_video_bus_get_devices(video, device);
1897 acpi_video_bus_start_devices(video);
1898
Patrick Mochel90130262006-05-19 16:54:48 -04001899 status = acpi_install_notify_handler(device->handle,
Len Brown4be44fc2005-08-05 00:44:28 -04001900 ACPI_DEVICE_NOTIFY,
1901 acpi_video_bus_notify, video);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001902 if (ACPI_FAILURE(status)) {
1903 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
Len Brown4be44fc2005-08-05 00:44:28 -04001904 "Error installing notify handler\n"));
Dmitry Torokhovf51e8392007-11-05 11:43:30 -05001905 error = -ENODEV;
1906 goto err_stop_video;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001907 }
1908
Luming Yue9dab192007-08-20 18:23:53 +08001909 video->input = input = input_allocate_device();
Dmitry Torokhovf51e8392007-11-05 11:43:30 -05001910 if (!input) {
1911 error = -ENOMEM;
1912 goto err_uninstall_notify;
1913 }
Luming Yue9dab192007-08-20 18:23:53 +08001914
1915 snprintf(video->phys, sizeof(video->phys),
1916 "%s/video/input0", acpi_device_hid(video->device));
1917
1918 input->name = acpi_device_name(video->device);
1919 input->phys = video->phys;
1920 input->id.bustype = BUS_HOST;
1921 input->id.product = 0x06;
Dmitry Torokhov91c05c62007-11-05 11:43:29 -05001922 input->dev.parent = &device->dev;
Luming Yue9dab192007-08-20 18:23:53 +08001923 input->evbit[0] = BIT(EV_KEY);
1924 set_bit(KEY_SWITCHVIDEOMODE, input->keybit);
1925 set_bit(KEY_VIDEO_NEXT, input->keybit);
1926 set_bit(KEY_VIDEO_PREV, input->keybit);
1927 set_bit(KEY_BRIGHTNESS_CYCLE, input->keybit);
1928 set_bit(KEY_BRIGHTNESSUP, input->keybit);
1929 set_bit(KEY_BRIGHTNESSDOWN, input->keybit);
1930 set_bit(KEY_BRIGHTNESS_ZERO, input->keybit);
1931 set_bit(KEY_DISPLAY_OFF, input->keybit);
1932 set_bit(KEY_UNKNOWN, input->keybit);
Luming Yue9dab192007-08-20 18:23:53 +08001933
Dmitry Torokhovf51e8392007-11-05 11:43:30 -05001934 error = input_register_device(input);
1935 if (error)
1936 goto err_free_input_dev;
Luming Yue9dab192007-08-20 18:23:53 +08001937
Linus Torvalds1da177e2005-04-16 15:20:36 -07001938 printk(KERN_INFO PREFIX "%s [%s] (multi-head: %s rom: %s post: %s)\n",
Len Brown4be44fc2005-08-05 00:44:28 -04001939 ACPI_VIDEO_DEVICE_NAME, acpi_device_bid(device),
1940 video->flags.multihead ? "yes" : "no",
1941 video->flags.rom ? "yes" : "no",
1942 video->flags.post ? "yes" : "no");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001943
Dmitry Torokhovf51e8392007-11-05 11:43:30 -05001944 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001945
Dmitry Torokhovf51e8392007-11-05 11:43:30 -05001946 err_free_input_dev:
1947 input_free_device(input);
1948 err_uninstall_notify:
1949 acpi_remove_notify_handler(device->handle, ACPI_DEVICE_NOTIFY,
1950 acpi_video_bus_notify);
1951 err_stop_video:
1952 acpi_video_bus_stop_devices(video);
1953 acpi_video_bus_put_devices(video);
1954 kfree(video->attached_array);
1955 acpi_video_bus_remove_fs(device);
1956 err_free_video:
1957 kfree(video);
1958 acpi_driver_data(device) = NULL;
1959
1960 return error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001961}
1962
Len Brown4be44fc2005-08-05 00:44:28 -04001963static int acpi_video_bus_remove(struct acpi_device *device, int type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001964{
Len Brown4be44fc2005-08-05 00:44:28 -04001965 acpi_status status = 0;
1966 struct acpi_video_bus *video = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001967
Linus Torvalds1da177e2005-04-16 15:20:36 -07001968
1969 if (!device || !acpi_driver_data(device))
Patrick Mocheld550d982006-06-27 00:41:40 -04001970 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001971
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001972 video = acpi_driver_data(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001973
1974 acpi_video_bus_stop_devices(video);
1975
Patrick Mochel90130262006-05-19 16:54:48 -04001976 status = acpi_remove_notify_handler(video->device->handle,
Len Brown4be44fc2005-08-05 00:44:28 -04001977 ACPI_DEVICE_NOTIFY,
1978 acpi_video_bus_notify);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001979
1980 acpi_video_bus_put_devices(video);
1981 acpi_video_bus_remove_fs(device);
1982
Luming Yue9dab192007-08-20 18:23:53 +08001983 input_unregister_device(video->input);
Jesper Juhl6044ec82005-11-07 01:01:32 -08001984 kfree(video->attached_array);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001985 kfree(video);
1986
Patrick Mocheld550d982006-06-27 00:41:40 -04001987 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001988}
1989
Len Brown4be44fc2005-08-05 00:44:28 -04001990static int __init acpi_video_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001991{
Len Brown4be44fc2005-08-05 00:44:28 -04001992 int result = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001993
Linus Torvalds1da177e2005-04-16 15:20:36 -07001994
1995 /*
Len Brown4be44fc2005-08-05 00:44:28 -04001996 acpi_dbg_level = 0xFFFFFFFF;
1997 acpi_dbg_layer = 0x08000000;
1998 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001999
2000 acpi_video_dir = proc_mkdir(ACPI_VIDEO_CLASS, acpi_root_dir);
2001 if (!acpi_video_dir)
Patrick Mocheld550d982006-06-27 00:41:40 -04002002 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002003 acpi_video_dir->owner = THIS_MODULE;
2004
2005 result = acpi_bus_register_driver(&acpi_video_bus);
2006 if (result < 0) {
2007 remove_proc_entry(ACPI_VIDEO_CLASS, acpi_root_dir);
Patrick Mocheld550d982006-06-27 00:41:40 -04002008 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002009 }
2010
Patrick Mocheld550d982006-06-27 00:41:40 -04002011 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002012}
2013
Len Brown4be44fc2005-08-05 00:44:28 -04002014static void __exit acpi_video_exit(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002015{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002016
2017 acpi_bus_unregister_driver(&acpi_video_bus);
2018
2019 remove_proc_entry(ACPI_VIDEO_CLASS, acpi_root_dir);
2020
Patrick Mocheld550d982006-06-27 00:41:40 -04002021 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002022}
2023
2024module_init(acpi_video_init);
2025module_exit(acpi_video_exit);