blob: 53a9eb015d6b0fe889420a551de726e9b2b30fab [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>
6 *
7 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or (at
12 * your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License along
20 * with this program; if not, write to the Free Software Foundation, Inc.,
21 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
22 *
23 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
24 */
25
26#include <linux/kernel.h>
27#include <linux/module.h>
28#include <linux/init.h>
29#include <linux/types.h>
30#include <linux/list.h>
31#include <linux/proc_fs.h>
32#include <linux/seq_file.h>
33
34#include <asm/uaccess.h>
35
36#include <acpi/acpi_bus.h>
37#include <acpi/acpi_drivers.h>
38
39#define ACPI_VIDEO_COMPONENT 0x08000000
40#define ACPI_VIDEO_CLASS "video"
41#define ACPI_VIDEO_DRIVER_NAME "ACPI Video Driver"
42#define ACPI_VIDEO_BUS_NAME "Video Bus"
43#define ACPI_VIDEO_DEVICE_NAME "Video Device"
44#define ACPI_VIDEO_NOTIFY_SWITCH 0x80
45#define ACPI_VIDEO_NOTIFY_PROBE 0x81
46#define ACPI_VIDEO_NOTIFY_CYCLE 0x82
47#define ACPI_VIDEO_NOTIFY_NEXT_OUTPUT 0x83
48#define ACPI_VIDEO_NOTIFY_PREV_OUTPUT 0x84
49
50#define ACPI_VIDEO_NOTIFY_CYCLE_BRIGHTNESS 0x82
51#define ACPI_VIDEO_NOTIFY_INC_BRIGHTNESS 0x83
52#define ACPI_VIDEO_NOTIFY_DEC_BRIGHTNESS 0x84
53#define ACPI_VIDEO_NOTIFY_ZERO_BRIGHTNESS 0x85
54#define ACPI_VIDEO_NOTIFY_DISPLAY_OFF 0x86
55
Linus Torvalds1da177e2005-04-16 15:20:36 -070056#define ACPI_VIDEO_HEAD_INVALID (~0u - 1)
57#define ACPI_VIDEO_HEAD_END (~0u)
58
Linus Torvalds1da177e2005-04-16 15:20:36 -070059#define _COMPONENT ACPI_VIDEO_COMPONENT
Len Brown4be44fc2005-08-05 00:44:28 -040060ACPI_MODULE_NAME("acpi_video")
Linus Torvalds1da177e2005-04-16 15:20:36 -070061
Len Brown4be44fc2005-08-05 00:44:28 -040062 MODULE_AUTHOR("Bruno Ducrot");
Linus Torvalds1da177e2005-04-16 15:20:36 -070063MODULE_DESCRIPTION(ACPI_VIDEO_DRIVER_NAME);
64MODULE_LICENSE("GPL");
65
Len Brown4be44fc2005-08-05 00:44:28 -040066static int acpi_video_bus_add(struct acpi_device *device);
67static int acpi_video_bus_remove(struct acpi_device *device, int type);
68static int acpi_video_bus_match(struct acpi_device *device,
69 struct acpi_driver *driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -070070
71static struct acpi_driver acpi_video_bus = {
72 .name = ACPI_VIDEO_DRIVER_NAME,
73 .class = ACPI_VIDEO_CLASS,
74 .ops = {
75 .add = acpi_video_bus_add,
76 .remove = acpi_video_bus_remove,
77 .match = acpi_video_bus_match,
Len Brown4be44fc2005-08-05 00:44:28 -040078 },
Linus Torvalds1da177e2005-04-16 15:20:36 -070079};
80
81struct acpi_video_bus_flags {
Len Brown4be44fc2005-08-05 00:44:28 -040082 u8 multihead:1; /* can switch video heads */
83 u8 rom:1; /* can retrieve a video rom */
84 u8 post:1; /* can configure the head to */
85 u8 reserved:5;
Linus Torvalds1da177e2005-04-16 15:20:36 -070086};
87
88struct acpi_video_bus_cap {
Len Brown4be44fc2005-08-05 00:44:28 -040089 u8 _DOS:1; /*Enable/Disable output switching */
90 u8 _DOD:1; /*Enumerate all devices attached to display adapter */
91 u8 _ROM:1; /*Get ROM Data */
92 u8 _GPD:1; /*Get POST Device */
93 u8 _SPD:1; /*Set POST Device */
94 u8 _VPO:1; /*Video POST Options */
95 u8 reserved:2;
Linus Torvalds1da177e2005-04-16 15:20:36 -070096};
97
Len Brown4be44fc2005-08-05 00:44:28 -040098struct acpi_video_device_attrib {
99 u32 display_index:4; /* A zero-based instance of the Display */
100 u32 display_port_attachment:4; /*This field differenates displays type */
101 u32 display_type:4; /*Describe the specific type in use */
102 u32 vendor_specific:4; /*Chipset Vendor Specifi */
103 u32 bios_can_detect:1; /*BIOS can detect the device */
104 u32 depend_on_vga:1; /*Non-VGA output device whose power is related to
105 the VGA device. */
106 u32 pipe_id:3; /*For VGA multiple-head devices. */
107 u32 reserved:10; /*Must be 0 */
108 u32 device_id_scheme:1; /*Device ID Scheme */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109};
110
111struct acpi_video_enumerated_device {
112 union {
113 u32 int_val;
Len Brown4be44fc2005-08-05 00:44:28 -0400114 struct acpi_video_device_attrib attrib;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700115 } value;
116 struct acpi_video_device *bind_info;
117};
118
119struct acpi_video_bus {
Patrick Mochele6afa0d2006-05-19 16:54:40 -0400120 struct acpi_device *device;
Len Brown4be44fc2005-08-05 00:44:28 -0400121 u8 dos_setting;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122 struct acpi_video_enumerated_device *attached_array;
Len Brown4be44fc2005-08-05 00:44:28 -0400123 u8 attached_count;
124 struct acpi_video_bus_cap cap;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125 struct acpi_video_bus_flags flags;
Len Brown4be44fc2005-08-05 00:44:28 -0400126 struct semaphore sem;
127 struct list_head video_device_list;
128 struct proc_dir_entry *dir;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129};
130
131struct acpi_video_device_flags {
Len Brown4be44fc2005-08-05 00:44:28 -0400132 u8 crt:1;
133 u8 lcd:1;
134 u8 tvout:1;
135 u8 bios:1;
136 u8 unknown:1;
137 u8 reserved:3;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138};
139
140struct acpi_video_device_cap {
Len Brown4be44fc2005-08-05 00:44:28 -0400141 u8 _ADR:1; /*Return the unique ID */
142 u8 _BCL:1; /*Query list of brightness control levels supported */
143 u8 _BCM:1; /*Set the brightness level */
144 u8 _DDC:1; /*Return the EDID for this device */
145 u8 _DCS:1; /*Return status of output device */
146 u8 _DGS:1; /*Query graphics state */
147 u8 _DSS:1; /*Device state set */
148 u8 _reserved:1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700149};
150
151struct acpi_video_device_brightness {
Len Brown4be44fc2005-08-05 00:44:28 -0400152 int curr;
153 int count;
154 int *levels;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155};
156
157struct acpi_video_device {
Len Brown4be44fc2005-08-05 00:44:28 -0400158 unsigned long device_id;
159 struct acpi_video_device_flags flags;
160 struct acpi_video_device_cap cap;
161 struct list_head entry;
162 struct acpi_video_bus *video;
163 struct acpi_device *dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700164 struct acpi_video_device_brightness *brightness;
165};
166
Linus Torvalds1da177e2005-04-16 15:20:36 -0700167/* bus */
168static int acpi_video_bus_info_open_fs(struct inode *inode, struct file *file);
169static struct file_operations acpi_video_bus_info_fops = {
Len Brown4be44fc2005-08-05 00:44:28 -0400170 .open = acpi_video_bus_info_open_fs,
171 .read = seq_read,
172 .llseek = seq_lseek,
173 .release = single_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700174};
175
176static int acpi_video_bus_ROM_open_fs(struct inode *inode, struct file *file);
177static struct file_operations acpi_video_bus_ROM_fops = {
Len Brown4be44fc2005-08-05 00:44:28 -0400178 .open = acpi_video_bus_ROM_open_fs,
179 .read = seq_read,
180 .llseek = seq_lseek,
181 .release = single_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700182};
183
Len Brown4be44fc2005-08-05 00:44:28 -0400184static int acpi_video_bus_POST_info_open_fs(struct inode *inode,
185 struct file *file);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700186static struct file_operations acpi_video_bus_POST_info_fops = {
Len Brown4be44fc2005-08-05 00:44:28 -0400187 .open = acpi_video_bus_POST_info_open_fs,
188 .read = seq_read,
189 .llseek = seq_lseek,
190 .release = single_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700191};
192
193static int acpi_video_bus_POST_open_fs(struct inode *inode, struct file *file);
194static struct file_operations acpi_video_bus_POST_fops = {
Len Brown4be44fc2005-08-05 00:44:28 -0400195 .open = acpi_video_bus_POST_open_fs,
196 .read = seq_read,
197 .llseek = seq_lseek,
198 .release = single_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700199};
200
Linus Torvalds1da177e2005-04-16 15:20:36 -0700201static int acpi_video_bus_DOS_open_fs(struct inode *inode, struct file *file);
202static struct file_operations acpi_video_bus_DOS_fops = {
Len Brown4be44fc2005-08-05 00:44:28 -0400203 .open = acpi_video_bus_DOS_open_fs,
204 .read = seq_read,
205 .llseek = seq_lseek,
206 .release = single_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700207};
208
209/* device */
Len Brown4be44fc2005-08-05 00:44:28 -0400210static int acpi_video_device_info_open_fs(struct inode *inode,
211 struct file *file);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700212static struct file_operations acpi_video_device_info_fops = {
Len Brown4be44fc2005-08-05 00:44:28 -0400213 .open = acpi_video_device_info_open_fs,
214 .read = seq_read,
215 .llseek = seq_lseek,
216 .release = single_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700217};
218
Len Brown4be44fc2005-08-05 00:44:28 -0400219static int acpi_video_device_state_open_fs(struct inode *inode,
220 struct file *file);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700221static struct file_operations acpi_video_device_state_fops = {
Len Brown4be44fc2005-08-05 00:44:28 -0400222 .open = acpi_video_device_state_open_fs,
223 .read = seq_read,
224 .llseek = seq_lseek,
225 .release = single_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700226};
227
Len Brown4be44fc2005-08-05 00:44:28 -0400228static int acpi_video_device_brightness_open_fs(struct inode *inode,
229 struct file *file);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700230static struct file_operations acpi_video_device_brightness_fops = {
Len Brown4be44fc2005-08-05 00:44:28 -0400231 .open = acpi_video_device_brightness_open_fs,
232 .read = seq_read,
233 .llseek = seq_lseek,
234 .release = single_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700235};
236
Len Brown4be44fc2005-08-05 00:44:28 -0400237static int acpi_video_device_EDID_open_fs(struct inode *inode,
238 struct file *file);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700239static struct file_operations acpi_video_device_EDID_fops = {
Len Brown4be44fc2005-08-05 00:44:28 -0400240 .open = acpi_video_device_EDID_open_fs,
241 .read = seq_read,
242 .llseek = seq_lseek,
243 .release = single_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700244};
245
Len Brown4be44fc2005-08-05 00:44:28 -0400246static char device_decode[][30] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700247 "motherboard VGA device",
248 "PCI VGA device",
249 "AGP VGA device",
250 "UNKNOWN",
251};
252
Len Brown4be44fc2005-08-05 00:44:28 -0400253static void acpi_video_device_notify(acpi_handle handle, u32 event, void *data);
254static void acpi_video_device_rebind(struct acpi_video_bus *video);
255static void acpi_video_device_bind(struct acpi_video_bus *video,
256 struct acpi_video_device *device);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700257static int acpi_video_device_enumerate(struct acpi_video_bus *video);
Len Brown4be44fc2005-08-05 00:44:28 -0400258static int acpi_video_switch_output(struct acpi_video_bus *video, int event);
259static int acpi_video_get_next_level(struct acpi_video_device *device,
260 u32 level_current, u32 event);
261static void acpi_video_switch_brightness(struct acpi_video_device *device,
262 int event);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700263
264/* --------------------------------------------------------------------------
265 Video Management
266 -------------------------------------------------------------------------- */
267
268/* device */
269
270static int
Len Brown4be44fc2005-08-05 00:44:28 -0400271acpi_video_device_query(struct acpi_video_device *device, unsigned long *state)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700272{
Len Brown4be44fc2005-08-05 00:44:28 -0400273 int status;
Patrick Mochel90130262006-05-19 16:54:48 -0400274
275 status = acpi_evaluate_integer(device->dev->handle, "_DGS", NULL, state);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700276
Patrick Mocheld550d982006-06-27 00:41:40 -0400277 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700278}
279
280static int
Len Brown4be44fc2005-08-05 00:44:28 -0400281acpi_video_device_get_state(struct acpi_video_device *device,
282 unsigned long *state)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700283{
Len Brown4be44fc2005-08-05 00:44:28 -0400284 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700285
Patrick Mochel90130262006-05-19 16:54:48 -0400286 status = acpi_evaluate_integer(device->dev->handle, "_DCS", NULL, state);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700287
Patrick Mocheld550d982006-06-27 00:41:40 -0400288 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700289}
290
291static int
Len Brown4be44fc2005-08-05 00:44:28 -0400292acpi_video_device_set_state(struct acpi_video_device *device, int state)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700293{
Len Brown4be44fc2005-08-05 00:44:28 -0400294 int status;
295 union acpi_object arg0 = { ACPI_TYPE_INTEGER };
296 struct acpi_object_list args = { 1, &arg0 };
Luming Yu824b5582005-08-21 19:17:00 -0400297 unsigned long ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700298
Linus Torvalds1da177e2005-04-16 15:20:36 -0700299
300 arg0.integer.value = state;
Patrick Mochel90130262006-05-19 16:54:48 -0400301 status = acpi_evaluate_integer(device->dev->handle, "_DSS", &args, &ret);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700302
Patrick Mocheld550d982006-06-27 00:41:40 -0400303 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700304}
305
306static int
Len Brown4be44fc2005-08-05 00:44:28 -0400307acpi_video_device_lcd_query_levels(struct acpi_video_device *device,
308 union acpi_object **levels)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700309{
Len Brown4be44fc2005-08-05 00:44:28 -0400310 int status;
311 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
312 union acpi_object *obj;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700313
Linus Torvalds1da177e2005-04-16 15:20:36 -0700314
315 *levels = NULL;
316
Patrick Mochel90130262006-05-19 16:54:48 -0400317 status = acpi_evaluate_object(device->dev->handle, "_BCL", NULL, &buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700318 if (!ACPI_SUCCESS(status))
Patrick Mocheld550d982006-06-27 00:41:40 -0400319 return status;
Len Brown4be44fc2005-08-05 00:44:28 -0400320 obj = (union acpi_object *)buffer.pointer;
Adrian Bunk6665bda2006-03-11 10:12:00 -0500321 if (!obj || (obj->type != ACPI_TYPE_PACKAGE)) {
Len Brown64684632006-06-26 23:41:38 -0400322 printk(KERN_ERR PREFIX "Invalid _BCL data\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700323 status = -EFAULT;
324 goto err;
325 }
326
327 *levels = obj;
328
Patrick Mocheld550d982006-06-27 00:41:40 -0400329 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700330
Len Brown4be44fc2005-08-05 00:44:28 -0400331 err:
Jesper Juhl6044ec82005-11-07 01:01:32 -0800332 kfree(buffer.pointer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700333
Patrick Mocheld550d982006-06-27 00:41:40 -0400334 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700335}
336
337static int
Len Brown4be44fc2005-08-05 00:44:28 -0400338acpi_video_device_lcd_set_level(struct acpi_video_device *device, int level)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700339{
Len Brown4be44fc2005-08-05 00:44:28 -0400340 int status;
341 union acpi_object arg0 = { ACPI_TYPE_INTEGER };
342 struct acpi_object_list args = { 1, &arg0 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700343
Linus Torvalds1da177e2005-04-16 15:20:36 -0700344
345 arg0.integer.value = level;
Patrick Mochel90130262006-05-19 16:54:48 -0400346 status = acpi_evaluate_object(device->dev->handle, "_BCM", &args, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700347
348 printk(KERN_DEBUG "set_level status: %x\n", status);
Patrick Mocheld550d982006-06-27 00:41:40 -0400349 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700350}
351
352static int
Len Brown4be44fc2005-08-05 00:44:28 -0400353acpi_video_device_lcd_get_level_current(struct acpi_video_device *device,
354 unsigned long *level)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700355{
Len Brown4be44fc2005-08-05 00:44:28 -0400356 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700357
Patrick Mochel90130262006-05-19 16:54:48 -0400358 status = acpi_evaluate_integer(device->dev->handle, "_BQC", NULL, level);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700359
Patrick Mocheld550d982006-06-27 00:41:40 -0400360 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700361}
362
363static int
Len Brown4be44fc2005-08-05 00:44:28 -0400364acpi_video_device_EDID(struct acpi_video_device *device,
365 union acpi_object **edid, ssize_t length)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700366{
Len Brown4be44fc2005-08-05 00:44:28 -0400367 int status;
368 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
369 union acpi_object *obj;
370 union acpi_object arg0 = { ACPI_TYPE_INTEGER };
371 struct acpi_object_list args = { 1, &arg0 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700372
Linus Torvalds1da177e2005-04-16 15:20:36 -0700373
374 *edid = NULL;
375
376 if (!device)
Patrick Mocheld550d982006-06-27 00:41:40 -0400377 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700378 if (length == 128)
379 arg0.integer.value = 1;
380 else if (length == 256)
381 arg0.integer.value = 2;
382 else
Patrick Mocheld550d982006-06-27 00:41:40 -0400383 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700384
Patrick Mochel90130262006-05-19 16:54:48 -0400385 status = acpi_evaluate_object(device->dev->handle, "_DDC", &args, &buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700386 if (ACPI_FAILURE(status))
Patrick Mocheld550d982006-06-27 00:41:40 -0400387 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700388
Jan Engelhardt50dd0962006-10-01 00:28:50 +0200389 obj = buffer.pointer;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700390
391 if (obj && obj->type == ACPI_TYPE_BUFFER)
392 *edid = obj;
393 else {
Len Brown64684632006-06-26 23:41:38 -0400394 printk(KERN_ERR PREFIX "Invalid _DDC data\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700395 status = -EFAULT;
396 kfree(obj);
397 }
398
Patrick Mocheld550d982006-06-27 00:41:40 -0400399 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700400}
401
Linus Torvalds1da177e2005-04-16 15:20:36 -0700402/* bus */
403
404static int
Len Brown4be44fc2005-08-05 00:44:28 -0400405acpi_video_bus_set_POST(struct acpi_video_bus *video, unsigned long option)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700406{
Len Brown4be44fc2005-08-05 00:44:28 -0400407 int status;
408 unsigned long tmp;
409 union acpi_object arg0 = { ACPI_TYPE_INTEGER };
410 struct acpi_object_list args = { 1, &arg0 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700411
Linus Torvalds1da177e2005-04-16 15:20:36 -0700412
413 arg0.integer.value = option;
414
Patrick Mochel90130262006-05-19 16:54:48 -0400415 status = acpi_evaluate_integer(video->device->handle, "_SPD", &args, &tmp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700416 if (ACPI_SUCCESS(status))
Len Brown4be44fc2005-08-05 00:44:28 -0400417 status = tmp ? (-EINVAL) : (AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700418
Patrick Mocheld550d982006-06-27 00:41:40 -0400419 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700420}
421
422static int
Len Brown4be44fc2005-08-05 00:44:28 -0400423acpi_video_bus_get_POST(struct acpi_video_bus *video, unsigned long *id)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700424{
425 int status;
426
Patrick Mochel90130262006-05-19 16:54:48 -0400427 status = acpi_evaluate_integer(video->device->handle, "_GPD", NULL, id);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700428
Patrick Mocheld550d982006-06-27 00:41:40 -0400429 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700430}
431
432static int
Len Brown4be44fc2005-08-05 00:44:28 -0400433acpi_video_bus_POST_options(struct acpi_video_bus *video,
434 unsigned long *options)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700435{
Len Brown4be44fc2005-08-05 00:44:28 -0400436 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700437
Patrick Mochel90130262006-05-19 16:54:48 -0400438 status = acpi_evaluate_integer(video->device->handle, "_VPO", NULL, options);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700439 *options &= 3;
440
Patrick Mocheld550d982006-06-27 00:41:40 -0400441 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700442}
443
444/*
445 * Arg:
446 * video : video bus device pointer
447 * bios_flag :
448 * 0. The system BIOS should NOT automatically switch(toggle)
449 * the active display output.
450 * 1. The system BIOS should automatically switch (toggle) the
451 * active display output. No swich event.
452 * 2. The _DGS value should be locked.
453 * 3. The system BIOS should not automatically switch (toggle) the
454 * active display output, but instead generate the display switch
455 * event notify code.
456 * lcd_flag :
457 * 0. The system BIOS should automatically control the brightness level
458 * of the LCD, when the power changes from AC to DC
459 * 1. The system BIOS should NOT automatically control the brightness
460 * level of the LCD, when the power changes from AC to DC.
461 * Return Value:
462 * -1 wrong arg.
463 */
464
465static int
Len Brown4be44fc2005-08-05 00:44:28 -0400466acpi_video_bus_DOS(struct acpi_video_bus *video, int bios_flag, int lcd_flag)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700467{
Len Brown4be44fc2005-08-05 00:44:28 -0400468 acpi_integer status = 0;
469 union acpi_object arg0 = { ACPI_TYPE_INTEGER };
470 struct acpi_object_list args = { 1, &arg0 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700471
Linus Torvalds1da177e2005-04-16 15:20:36 -0700472
Len Brown4be44fc2005-08-05 00:44:28 -0400473 if (bios_flag < 0 || bios_flag > 3 || lcd_flag < 0 || lcd_flag > 1) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700474 status = -1;
475 goto Failed;
476 }
477 arg0.integer.value = (lcd_flag << 2) | bios_flag;
478 video->dos_setting = arg0.integer.value;
Patrick Mochel90130262006-05-19 16:54:48 -0400479 acpi_evaluate_object(video->device->handle, "_DOS", &args, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700480
Len Brown4be44fc2005-08-05 00:44:28 -0400481 Failed:
Patrick Mocheld550d982006-06-27 00:41:40 -0400482 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700483}
484
485/*
486 * Arg:
487 * device : video output device (LCD, CRT, ..)
488 *
489 * Return Value:
490 * None
491 *
492 * Find out all required AML method defined under the output
493 * device.
494 */
495
Len Brown4be44fc2005-08-05 00:44:28 -0400496static void acpi_video_device_find_cap(struct acpi_video_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700497{
Len Brown4be44fc2005-08-05 00:44:28 -0400498 acpi_integer status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700499 acpi_handle h_dummy1;
500 int i;
501 union acpi_object *obj = NULL;
502 struct acpi_video_device_brightness *br = NULL;
503
Linus Torvalds1da177e2005-04-16 15:20:36 -0700504
Len Brown4be44fc2005-08-05 00:44:28 -0400505 memset(&device->cap, 0, 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700506
Patrick Mochel90130262006-05-19 16:54:48 -0400507 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_ADR", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700508 device->cap._ADR = 1;
509 }
Patrick Mochel90130262006-05-19 16:54:48 -0400510 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_BCL", &h_dummy1))) {
Len Brown4be44fc2005-08-05 00:44:28 -0400511 device->cap._BCL = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700512 }
Patrick Mochel90130262006-05-19 16:54:48 -0400513 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_BCM", &h_dummy1))) {
Len Brown4be44fc2005-08-05 00:44:28 -0400514 device->cap._BCM = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700515 }
Patrick Mochel90130262006-05-19 16:54:48 -0400516 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_DDC", &h_dummy1))) {
Len Brown4be44fc2005-08-05 00:44:28 -0400517 device->cap._DDC = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700518 }
Patrick Mochel90130262006-05-19 16:54:48 -0400519 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_DCS", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700520 device->cap._DCS = 1;
521 }
Patrick Mochel90130262006-05-19 16:54:48 -0400522 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_DGS", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700523 device->cap._DGS = 1;
524 }
Patrick Mochel90130262006-05-19 16:54:48 -0400525 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_DSS", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700526 device->cap._DSS = 1;
527 }
528
529 status = acpi_video_device_lcd_query_levels(device, &obj);
530
531 if (obj && obj->type == ACPI_TYPE_PACKAGE && obj->package.count >= 2) {
532 int count = 0;
533 union acpi_object *o;
Len Brown4be44fc2005-08-05 00:44:28 -0400534
Paulo Marquesd1dd0c22005-03-30 22:39:49 -0500535 br = kmalloc(sizeof(*br), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700536 if (!br) {
537 printk(KERN_ERR "can't allocate memory\n");
538 } else {
Paulo Marquesd1dd0c22005-03-30 22:39:49 -0500539 memset(br, 0, sizeof(*br));
540 br->levels = kmalloc(obj->package.count *
Len Brown4be44fc2005-08-05 00:44:28 -0400541 sizeof *(br->levels), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700542 if (!br->levels)
543 goto out;
544
545 for (i = 0; i < obj->package.count; i++) {
Len Brown4be44fc2005-08-05 00:44:28 -0400546 o = (union acpi_object *)&obj->package.
547 elements[i];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700548 if (o->type != ACPI_TYPE_INTEGER) {
Len Brown64684632006-06-26 23:41:38 -0400549 printk(KERN_ERR PREFIX "Invalid data\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700550 continue;
551 }
552 br->levels[count] = (u32) o->integer.value;
553 count++;
554 }
Len Brown4be44fc2005-08-05 00:44:28 -0400555 out:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700556 if (count < 2) {
Paulo Marquesd1dd0c22005-03-30 22:39:49 -0500557 kfree(br->levels);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700558 kfree(br);
559 } else {
560 br->count = count;
561 device->brightness = br;
Len Brown4be44fc2005-08-05 00:44:28 -0400562 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
563 "found %d brightness levels\n",
564 count));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700565 }
566 }
567 }
568
Paulo Marquesd1dd0c22005-03-30 22:39:49 -0500569 kfree(obj);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700570
Patrick Mocheld550d982006-06-27 00:41:40 -0400571 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700572}
573
574/*
575 * Arg:
576 * device : video output device (VGA)
577 *
578 * Return Value:
579 * None
580 *
581 * Find out all required AML method defined under the video bus device.
582 */
583
Len Brown4be44fc2005-08-05 00:44:28 -0400584static void acpi_video_bus_find_cap(struct acpi_video_bus *video)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700585{
Len Brown4be44fc2005-08-05 00:44:28 -0400586 acpi_handle h_dummy1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700587
Len Brown4be44fc2005-08-05 00:44:28 -0400588 memset(&video->cap, 0, 4);
Patrick Mochel90130262006-05-19 16:54:48 -0400589 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_DOS", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700590 video->cap._DOS = 1;
591 }
Patrick Mochel90130262006-05-19 16:54:48 -0400592 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_DOD", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700593 video->cap._DOD = 1;
594 }
Patrick Mochel90130262006-05-19 16:54:48 -0400595 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_ROM", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700596 video->cap._ROM = 1;
597 }
Patrick Mochel90130262006-05-19 16:54:48 -0400598 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_GPD", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700599 video->cap._GPD = 1;
600 }
Patrick Mochel90130262006-05-19 16:54:48 -0400601 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_SPD", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700602 video->cap._SPD = 1;
603 }
Patrick Mochel90130262006-05-19 16:54:48 -0400604 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_VPO", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700605 video->cap._VPO = 1;
606 }
607}
608
609/*
610 * Check whether the video bus device has required AML method to
611 * support the desired features
612 */
613
Len Brown4be44fc2005-08-05 00:44:28 -0400614static int acpi_video_bus_check(struct acpi_video_bus *video)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700615{
Len Brown4be44fc2005-08-05 00:44:28 -0400616 acpi_status status = -ENOENT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700617
Linus Torvalds1da177e2005-04-16 15:20:36 -0700618
619 if (!video)
Patrick Mocheld550d982006-06-27 00:41:40 -0400620 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700621
622 /* Since there is no HID, CID and so on for VGA driver, we have
623 * to check well known required nodes.
624 */
625
626 /* Does this device able to support video switching ? */
Len Brown4be44fc2005-08-05 00:44:28 -0400627 if (video->cap._DOS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700628 video->flags.multihead = 1;
629 status = 0;
630 }
631
632 /* Does this device able to retrieve a retrieve a video ROM ? */
Len Brown4be44fc2005-08-05 00:44:28 -0400633 if (video->cap._ROM) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700634 video->flags.rom = 1;
635 status = 0;
636 }
637
638 /* Does this device able to configure which video device to POST ? */
Len Brown4be44fc2005-08-05 00:44:28 -0400639 if (video->cap._GPD && video->cap._SPD && video->cap._VPO) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700640 video->flags.post = 1;
641 status = 0;
642 }
643
Patrick Mocheld550d982006-06-27 00:41:40 -0400644 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700645}
646
647/* --------------------------------------------------------------------------
648 FS Interface (/proc)
649 -------------------------------------------------------------------------- */
650
Len Brown4be44fc2005-08-05 00:44:28 -0400651static struct proc_dir_entry *acpi_video_dir;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700652
653/* video devices */
654
Len Brown4be44fc2005-08-05 00:44:28 -0400655static int acpi_video_device_info_seq_show(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700656{
Jan Engelhardt50dd0962006-10-01 00:28:50 +0200657 struct acpi_video_device *dev = seq->private;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700658
Linus Torvalds1da177e2005-04-16 15:20:36 -0700659
660 if (!dev)
661 goto end;
662
663 seq_printf(seq, "device_id: 0x%04x\n", (u32) dev->device_id);
664 seq_printf(seq, "type: ");
665 if (dev->flags.crt)
666 seq_printf(seq, "CRT\n");
667 else if (dev->flags.lcd)
668 seq_printf(seq, "LCD\n");
669 else if (dev->flags.tvout)
670 seq_printf(seq, "TVOUT\n");
671 else
672 seq_printf(seq, "UNKNOWN\n");
673
Len Brown4be44fc2005-08-05 00:44:28 -0400674 seq_printf(seq, "known by bios: %s\n", dev->flags.bios ? "yes" : "no");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700675
Len Brown4be44fc2005-08-05 00:44:28 -0400676 end:
Patrick Mocheld550d982006-06-27 00:41:40 -0400677 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700678}
679
680static int
Len Brown4be44fc2005-08-05 00:44:28 -0400681acpi_video_device_info_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700682{
683 return single_open(file, acpi_video_device_info_seq_show,
684 PDE(inode)->data);
685}
686
Len Brown4be44fc2005-08-05 00:44:28 -0400687static int acpi_video_device_state_seq_show(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700688{
Len Brown4be44fc2005-08-05 00:44:28 -0400689 int status;
Jan Engelhardt50dd0962006-10-01 00:28:50 +0200690 struct acpi_video_device *dev = seq->private;
Len Brown4be44fc2005-08-05 00:44:28 -0400691 unsigned long state;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700692
Linus Torvalds1da177e2005-04-16 15:20:36 -0700693
694 if (!dev)
695 goto end;
696
697 status = acpi_video_device_get_state(dev, &state);
698 seq_printf(seq, "state: ");
699 if (ACPI_SUCCESS(status))
700 seq_printf(seq, "0x%02lx\n", state);
701 else
702 seq_printf(seq, "<not supported>\n");
703
704 status = acpi_video_device_query(dev, &state);
705 seq_printf(seq, "query: ");
706 if (ACPI_SUCCESS(status))
707 seq_printf(seq, "0x%02lx\n", state);
708 else
709 seq_printf(seq, "<not supported>\n");
710
Len Brown4be44fc2005-08-05 00:44:28 -0400711 end:
Patrick Mocheld550d982006-06-27 00:41:40 -0400712 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700713}
714
715static int
Len Brown4be44fc2005-08-05 00:44:28 -0400716acpi_video_device_state_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700717{
718 return single_open(file, acpi_video_device_state_seq_show,
719 PDE(inode)->data);
720}
721
722static ssize_t
Len Brown4be44fc2005-08-05 00:44:28 -0400723acpi_video_device_write_state(struct file *file,
724 const char __user * buffer,
725 size_t count, loff_t * data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700726{
Len Brown4be44fc2005-08-05 00:44:28 -0400727 int status;
Jan Engelhardt50dd0962006-10-01 00:28:50 +0200728 struct seq_file *m = file->private_data;
729 struct acpi_video_device *dev = m->private;
Len Brown4be44fc2005-08-05 00:44:28 -0400730 char str[12] = { 0 };
731 u32 state = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700732
Linus Torvalds1da177e2005-04-16 15:20:36 -0700733
734 if (!dev || count + 1 > sizeof str)
Patrick Mocheld550d982006-06-27 00:41:40 -0400735 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700736
737 if (copy_from_user(str, buffer, count))
Patrick Mocheld550d982006-06-27 00:41:40 -0400738 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700739
740 str[count] = 0;
741 state = simple_strtoul(str, NULL, 0);
Len Brown4be44fc2005-08-05 00:44:28 -0400742 state &= ((1ul << 31) | (1ul << 30) | (1ul << 0));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700743
744 status = acpi_video_device_set_state(dev, state);
745
746 if (status)
Patrick Mocheld550d982006-06-27 00:41:40 -0400747 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700748
Patrick Mocheld550d982006-06-27 00:41:40 -0400749 return count;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700750}
751
752static int
Len Brown4be44fc2005-08-05 00:44:28 -0400753acpi_video_device_brightness_seq_show(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700754{
Jan Engelhardt50dd0962006-10-01 00:28:50 +0200755 struct acpi_video_device *dev = seq->private;
Len Brown4be44fc2005-08-05 00:44:28 -0400756 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700757
Linus Torvalds1da177e2005-04-16 15:20:36 -0700758
759 if (!dev || !dev->brightness) {
760 seq_printf(seq, "<not supported>\n");
Patrick Mocheld550d982006-06-27 00:41:40 -0400761 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700762 }
763
764 seq_printf(seq, "levels: ");
765 for (i = 0; i < dev->brightness->count; i++)
766 seq_printf(seq, " %d", dev->brightness->levels[i]);
767 seq_printf(seq, "\ncurrent: %d\n", dev->brightness->curr);
768
Patrick Mocheld550d982006-06-27 00:41:40 -0400769 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700770}
771
772static int
Len Brown4be44fc2005-08-05 00:44:28 -0400773acpi_video_device_brightness_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700774{
775 return single_open(file, acpi_video_device_brightness_seq_show,
776 PDE(inode)->data);
777}
778
779static ssize_t
Len Brown4be44fc2005-08-05 00:44:28 -0400780acpi_video_device_write_brightness(struct file *file,
781 const char __user * buffer,
782 size_t count, loff_t * data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700783{
Jan Engelhardt50dd0962006-10-01 00:28:50 +0200784 struct seq_file *m = file->private_data;
785 struct acpi_video_device *dev = m->private;
Len Brown4be44fc2005-08-05 00:44:28 -0400786 char str[4] = { 0 };
787 unsigned int level = 0;
788 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700789
Linus Torvalds1da177e2005-04-16 15:20:36 -0700790
Thomas Renninger59d399d2005-11-08 05:27:00 -0500791 if (!dev || !dev->brightness || count + 1 > sizeof str)
Patrick Mocheld550d982006-06-27 00:41:40 -0400792 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700793
794 if (copy_from_user(str, buffer, count))
Patrick Mocheld550d982006-06-27 00:41:40 -0400795 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700796
797 str[count] = 0;
798 level = simple_strtoul(str, NULL, 0);
Len Brown4be44fc2005-08-05 00:44:28 -0400799
Linus Torvalds1da177e2005-04-16 15:20:36 -0700800 if (level > 100)
Patrick Mocheld550d982006-06-27 00:41:40 -0400801 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700802
803 /* validate though the list of available levels */
804 for (i = 0; i < dev->brightness->count; i++)
805 if (level == dev->brightness->levels[i]) {
Len Brown4be44fc2005-08-05 00:44:28 -0400806 if (ACPI_SUCCESS
807 (acpi_video_device_lcd_set_level(dev, level)))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700808 dev->brightness->curr = level;
809 break;
810 }
811
Patrick Mocheld550d982006-06-27 00:41:40 -0400812 return count;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700813}
814
Len Brown4be44fc2005-08-05 00:44:28 -0400815static int acpi_video_device_EDID_seq_show(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700816{
Jan Engelhardt50dd0962006-10-01 00:28:50 +0200817 struct acpi_video_device *dev = seq->private;
Len Brown4be44fc2005-08-05 00:44:28 -0400818 int status;
819 int i;
820 union acpi_object *edid = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700821
Linus Torvalds1da177e2005-04-16 15:20:36 -0700822
823 if (!dev)
824 goto out;
825
Len Brown4be44fc2005-08-05 00:44:28 -0400826 status = acpi_video_device_EDID(dev, &edid, 128);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700827 if (ACPI_FAILURE(status)) {
Len Brown4be44fc2005-08-05 00:44:28 -0400828 status = acpi_video_device_EDID(dev, &edid, 256);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700829 }
830
831 if (ACPI_FAILURE(status)) {
832 goto out;
833 }
834
835 if (edid && edid->type == ACPI_TYPE_BUFFER) {
836 for (i = 0; i < edid->buffer.length; i++)
837 seq_putc(seq, edid->buffer.pointer[i]);
838 }
839
Len Brown4be44fc2005-08-05 00:44:28 -0400840 out:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700841 if (!edid)
842 seq_printf(seq, "<not supported>\n");
843 else
844 kfree(edid);
845
Patrick Mocheld550d982006-06-27 00:41:40 -0400846 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700847}
848
849static int
Len Brown4be44fc2005-08-05 00:44:28 -0400850acpi_video_device_EDID_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700851{
852 return single_open(file, acpi_video_device_EDID_seq_show,
853 PDE(inode)->data);
854}
855
Len Brown4be44fc2005-08-05 00:44:28 -0400856static int acpi_video_device_add_fs(struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700857{
Len Brown4be44fc2005-08-05 00:44:28 -0400858 struct proc_dir_entry *entry = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700859 struct acpi_video_device *vid_dev;
860
Linus Torvalds1da177e2005-04-16 15:20:36 -0700861
862 if (!device)
Patrick Mocheld550d982006-06-27 00:41:40 -0400863 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700864
Jan Engelhardt50dd0962006-10-01 00:28:50 +0200865 vid_dev = acpi_driver_data(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700866 if (!vid_dev)
Patrick Mocheld550d982006-06-27 00:41:40 -0400867 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700868
869 if (!acpi_device_dir(device)) {
870 acpi_device_dir(device) = proc_mkdir(acpi_device_bid(device),
Len Brown4be44fc2005-08-05 00:44:28 -0400871 vid_dev->video->dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700872 if (!acpi_device_dir(device))
Patrick Mocheld550d982006-06-27 00:41:40 -0400873 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700874 acpi_device_dir(device)->owner = THIS_MODULE;
875 }
876
877 /* 'info' [R] */
878 entry = create_proc_entry("info", S_IRUGO, acpi_device_dir(device));
879 if (!entry)
Patrick Mocheld550d982006-06-27 00:41:40 -0400880 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700881 else {
882 entry->proc_fops = &acpi_video_device_info_fops;
883 entry->data = acpi_driver_data(device);
884 entry->owner = THIS_MODULE;
885 }
886
887 /* 'state' [R/W] */
Len Brown4be44fc2005-08-05 00:44:28 -0400888 entry =
889 create_proc_entry("state", S_IFREG | S_IRUGO | S_IWUSR,
890 acpi_device_dir(device));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700891 if (!entry)
Patrick Mocheld550d982006-06-27 00:41:40 -0400892 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700893 else {
Arjan van de Vend479e902006-01-06 16:47:00 -0500894 acpi_video_device_state_fops.write = acpi_video_device_write_state;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700895 entry->proc_fops = &acpi_video_device_state_fops;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700896 entry->data = acpi_driver_data(device);
897 entry->owner = THIS_MODULE;
898 }
899
900 /* 'brightness' [R/W] */
Len Brown4be44fc2005-08-05 00:44:28 -0400901 entry =
902 create_proc_entry("brightness", S_IFREG | S_IRUGO | S_IWUSR,
903 acpi_device_dir(device));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700904 if (!entry)
Patrick Mocheld550d982006-06-27 00:41:40 -0400905 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700906 else {
Arjan van de Vend479e902006-01-06 16:47:00 -0500907 acpi_video_device_brightness_fops.write = acpi_video_device_write_brightness;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700908 entry->proc_fops = &acpi_video_device_brightness_fops;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700909 entry->data = acpi_driver_data(device);
910 entry->owner = THIS_MODULE;
911 }
912
913 /* 'EDID' [R] */
914 entry = create_proc_entry("EDID", S_IRUGO, acpi_device_dir(device));
915 if (!entry)
Patrick Mocheld550d982006-06-27 00:41:40 -0400916 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700917 else {
918 entry->proc_fops = &acpi_video_device_EDID_fops;
919 entry->data = acpi_driver_data(device);
920 entry->owner = THIS_MODULE;
921 }
922
Patrick Mocheld550d982006-06-27 00:41:40 -0400923 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700924}
925
Len Brown4be44fc2005-08-05 00:44:28 -0400926static int acpi_video_device_remove_fs(struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700927{
928 struct acpi_video_device *vid_dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700929
Jan Engelhardt50dd0962006-10-01 00:28:50 +0200930 vid_dev = acpi_driver_data(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700931 if (!vid_dev || !vid_dev->video || !vid_dev->video->dir)
Patrick Mocheld550d982006-06-27 00:41:40 -0400932 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700933
934 if (acpi_device_dir(device)) {
935 remove_proc_entry("info", acpi_device_dir(device));
936 remove_proc_entry("state", acpi_device_dir(device));
937 remove_proc_entry("brightness", acpi_device_dir(device));
938 remove_proc_entry("EDID", acpi_device_dir(device));
Len Brown4be44fc2005-08-05 00:44:28 -0400939 remove_proc_entry(acpi_device_bid(device), vid_dev->video->dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700940 acpi_device_dir(device) = NULL;
941 }
942
Patrick Mocheld550d982006-06-27 00:41:40 -0400943 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700944}
945
Linus Torvalds1da177e2005-04-16 15:20:36 -0700946/* video bus */
Len Brown4be44fc2005-08-05 00:44:28 -0400947static int acpi_video_bus_info_seq_show(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700948{
Jan Engelhardt50dd0962006-10-01 00:28:50 +0200949 struct acpi_video_bus *video = seq->private;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700950
Linus Torvalds1da177e2005-04-16 15:20:36 -0700951
952 if (!video)
953 goto end;
954
955 seq_printf(seq, "Switching heads: %s\n",
Len Brown4be44fc2005-08-05 00:44:28 -0400956 video->flags.multihead ? "yes" : "no");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700957 seq_printf(seq, "Video ROM: %s\n",
Len Brown4be44fc2005-08-05 00:44:28 -0400958 video->flags.rom ? "yes" : "no");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700959 seq_printf(seq, "Device to be POSTed on boot: %s\n",
Len Brown4be44fc2005-08-05 00:44:28 -0400960 video->flags.post ? "yes" : "no");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700961
Len Brown4be44fc2005-08-05 00:44:28 -0400962 end:
Patrick Mocheld550d982006-06-27 00:41:40 -0400963 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700964}
965
Len Brown4be44fc2005-08-05 00:44:28 -0400966static int acpi_video_bus_info_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700967{
Len Brown4be44fc2005-08-05 00:44:28 -0400968 return single_open(file, acpi_video_bus_info_seq_show,
969 PDE(inode)->data);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700970}
971
Len Brown4be44fc2005-08-05 00:44:28 -0400972static int acpi_video_bus_ROM_seq_show(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700973{
Jan Engelhardt50dd0962006-10-01 00:28:50 +0200974 struct acpi_video_bus *video = seq->private;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700975
Linus Torvalds1da177e2005-04-16 15:20:36 -0700976
977 if (!video)
978 goto end;
979
980 printk(KERN_INFO PREFIX "Please implement %s\n", __FUNCTION__);
981 seq_printf(seq, "<TODO>\n");
982
Len Brown4be44fc2005-08-05 00:44:28 -0400983 end:
Patrick Mocheld550d982006-06-27 00:41:40 -0400984 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700985}
986
Len Brown4be44fc2005-08-05 00:44:28 -0400987static int acpi_video_bus_ROM_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700988{
989 return single_open(file, acpi_video_bus_ROM_seq_show, PDE(inode)->data);
990}
991
Len Brown4be44fc2005-08-05 00:44:28 -0400992static int acpi_video_bus_POST_info_seq_show(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700993{
Jan Engelhardt50dd0962006-10-01 00:28:50 +0200994 struct acpi_video_bus *video = seq->private;
Len Brown4be44fc2005-08-05 00:44:28 -0400995 unsigned long options;
996 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700997
Linus Torvalds1da177e2005-04-16 15:20:36 -0700998
999 if (!video)
1000 goto end;
1001
1002 status = acpi_video_bus_POST_options(video, &options);
1003 if (ACPI_SUCCESS(status)) {
1004 if (!(options & 1)) {
Len Brown4be44fc2005-08-05 00:44:28 -04001005 printk(KERN_WARNING PREFIX
1006 "The motherboard VGA device is not listed as a possible POST device.\n");
1007 printk(KERN_WARNING PREFIX
1008 "This indicate a BIOS bug. Please contact the manufacturer.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001009 }
1010 printk("%lx\n", options);
1011 seq_printf(seq, "can POST: <intgrated video>");
1012 if (options & 2)
1013 seq_printf(seq, " <PCI video>");
1014 if (options & 4)
1015 seq_printf(seq, " <AGP video>");
1016 seq_putc(seq, '\n');
1017 } else
1018 seq_printf(seq, "<not supported>\n");
Len Brown4be44fc2005-08-05 00:44:28 -04001019 end:
Patrick Mocheld550d982006-06-27 00:41:40 -04001020 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001021}
1022
1023static int
Len Brown4be44fc2005-08-05 00:44:28 -04001024acpi_video_bus_POST_info_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001025{
Len Brown4be44fc2005-08-05 00:44:28 -04001026 return single_open(file, acpi_video_bus_POST_info_seq_show,
1027 PDE(inode)->data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001028}
1029
Len Brown4be44fc2005-08-05 00:44:28 -04001030static int acpi_video_bus_POST_seq_show(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001031{
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001032 struct acpi_video_bus *video = seq->private;
Len Brown4be44fc2005-08-05 00:44:28 -04001033 int status;
1034 unsigned long id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001035
Linus Torvalds1da177e2005-04-16 15:20:36 -07001036
1037 if (!video)
1038 goto end;
1039
Len Brown4be44fc2005-08-05 00:44:28 -04001040 status = acpi_video_bus_get_POST(video, &id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001041 if (!ACPI_SUCCESS(status)) {
1042 seq_printf(seq, "<not supported>\n");
1043 goto end;
1044 }
Len Brown4be44fc2005-08-05 00:44:28 -04001045 seq_printf(seq, "device posted is <%s>\n", device_decode[id & 3]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001046
Len Brown4be44fc2005-08-05 00:44:28 -04001047 end:
Patrick Mocheld550d982006-06-27 00:41:40 -04001048 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001049}
1050
Len Brown4be44fc2005-08-05 00:44:28 -04001051static int acpi_video_bus_DOS_seq_show(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001052{
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001053 struct acpi_video_bus *video = seq->private;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001054
Linus Torvalds1da177e2005-04-16 15:20:36 -07001055
Len Brown4be44fc2005-08-05 00:44:28 -04001056 seq_printf(seq, "DOS setting: <%d>\n", video->dos_setting);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001057
Patrick Mocheld550d982006-06-27 00:41:40 -04001058 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001059}
1060
Len Brown4be44fc2005-08-05 00:44:28 -04001061static int acpi_video_bus_POST_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001062{
Len Brown4be44fc2005-08-05 00:44:28 -04001063 return single_open(file, acpi_video_bus_POST_seq_show,
1064 PDE(inode)->data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001065}
1066
Len Brown4be44fc2005-08-05 00:44:28 -04001067static int acpi_video_bus_DOS_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001068{
1069 return single_open(file, acpi_video_bus_DOS_seq_show, PDE(inode)->data);
1070}
1071
1072static ssize_t
Len Brown4be44fc2005-08-05 00:44:28 -04001073acpi_video_bus_write_POST(struct file *file,
1074 const char __user * buffer,
1075 size_t count, loff_t * data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001076{
Len Brown4be44fc2005-08-05 00:44:28 -04001077 int status;
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001078 struct seq_file *m = file->private_data;
1079 struct acpi_video_bus *video = m->private;
Len Brown4be44fc2005-08-05 00:44:28 -04001080 char str[12] = { 0 };
1081 unsigned long opt, options;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001082
Linus Torvalds1da177e2005-04-16 15:20:36 -07001083
Linus Torvalds1da177e2005-04-16 15:20:36 -07001084 if (!video || count + 1 > sizeof str)
Patrick Mocheld550d982006-06-27 00:41:40 -04001085 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001086
1087 status = acpi_video_bus_POST_options(video, &options);
1088 if (!ACPI_SUCCESS(status))
Patrick Mocheld550d982006-06-27 00:41:40 -04001089 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001090
1091 if (copy_from_user(str, buffer, count))
Patrick Mocheld550d982006-06-27 00:41:40 -04001092 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001093
1094 str[count] = 0;
1095 opt = strtoul(str, NULL, 0);
1096 if (opt > 3)
Patrick Mocheld550d982006-06-27 00:41:40 -04001097 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001098
1099 /* just in case an OEM 'forget' the motherboard... */
1100 options |= 1;
1101
1102 if (options & (1ul << opt)) {
Len Brown4be44fc2005-08-05 00:44:28 -04001103 status = acpi_video_bus_set_POST(video, opt);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001104 if (!ACPI_SUCCESS(status))
Patrick Mocheld550d982006-06-27 00:41:40 -04001105 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001106
1107 }
1108
Patrick Mocheld550d982006-06-27 00:41:40 -04001109 return count;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001110}
1111
1112static ssize_t
Len Brown4be44fc2005-08-05 00:44:28 -04001113acpi_video_bus_write_DOS(struct file *file,
1114 const char __user * buffer,
1115 size_t count, loff_t * data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001116{
Len Brown4be44fc2005-08-05 00:44:28 -04001117 int status;
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001118 struct seq_file *m = file->private_data;
1119 struct acpi_video_bus *video = m->private;
Len Brown4be44fc2005-08-05 00:44:28 -04001120 char str[12] = { 0 };
1121 unsigned long opt;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001122
Linus Torvalds1da177e2005-04-16 15:20:36 -07001123
Linus Torvalds1da177e2005-04-16 15:20:36 -07001124 if (!video || count + 1 > sizeof str)
Patrick Mocheld550d982006-06-27 00:41:40 -04001125 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001126
1127 if (copy_from_user(str, buffer, count))
Patrick Mocheld550d982006-06-27 00:41:40 -04001128 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001129
1130 str[count] = 0;
1131 opt = strtoul(str, NULL, 0);
1132 if (opt > 7)
Patrick Mocheld550d982006-06-27 00:41:40 -04001133 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001134
Len Brown4be44fc2005-08-05 00:44:28 -04001135 status = acpi_video_bus_DOS(video, opt & 0x3, (opt & 0x4) >> 2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001136
1137 if (!ACPI_SUCCESS(status))
Patrick Mocheld550d982006-06-27 00:41:40 -04001138 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001139
Patrick Mocheld550d982006-06-27 00:41:40 -04001140 return count;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001141}
1142
Len Brown4be44fc2005-08-05 00:44:28 -04001143static int acpi_video_bus_add_fs(struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001144{
Len Brown4be44fc2005-08-05 00:44:28 -04001145 struct proc_dir_entry *entry = NULL;
1146 struct acpi_video_bus *video;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001147
Linus Torvalds1da177e2005-04-16 15:20:36 -07001148
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001149 video = acpi_driver_data(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001150
1151 if (!acpi_device_dir(device)) {
1152 acpi_device_dir(device) = proc_mkdir(acpi_device_bid(device),
Len Brown4be44fc2005-08-05 00:44:28 -04001153 acpi_video_dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001154 if (!acpi_device_dir(device))
Patrick Mocheld550d982006-06-27 00:41:40 -04001155 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001156 video->dir = acpi_device_dir(device);
1157 acpi_device_dir(device)->owner = THIS_MODULE;
1158 }
1159
1160 /* 'info' [R] */
1161 entry = create_proc_entry("info", S_IRUGO, acpi_device_dir(device));
1162 if (!entry)
Patrick Mocheld550d982006-06-27 00:41:40 -04001163 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001164 else {
1165 entry->proc_fops = &acpi_video_bus_info_fops;
1166 entry->data = acpi_driver_data(device);
1167 entry->owner = THIS_MODULE;
1168 }
1169
1170 /* 'ROM' [R] */
1171 entry = create_proc_entry("ROM", S_IRUGO, acpi_device_dir(device));
1172 if (!entry)
Patrick Mocheld550d982006-06-27 00:41:40 -04001173 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001174 else {
1175 entry->proc_fops = &acpi_video_bus_ROM_fops;
1176 entry->data = acpi_driver_data(device);
1177 entry->owner = THIS_MODULE;
1178 }
1179
1180 /* 'POST_info' [R] */
Len Brown4be44fc2005-08-05 00:44:28 -04001181 entry =
1182 create_proc_entry("POST_info", S_IRUGO, acpi_device_dir(device));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001183 if (!entry)
Patrick Mocheld550d982006-06-27 00:41:40 -04001184 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001185 else {
1186 entry->proc_fops = &acpi_video_bus_POST_info_fops;
1187 entry->data = acpi_driver_data(device);
1188 entry->owner = THIS_MODULE;
1189 }
1190
1191 /* 'POST' [R/W] */
Len Brown4be44fc2005-08-05 00:44:28 -04001192 entry =
1193 create_proc_entry("POST", S_IFREG | S_IRUGO | S_IRUSR,
1194 acpi_device_dir(device));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001195 if (!entry)
Patrick Mocheld550d982006-06-27 00:41:40 -04001196 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001197 else {
Arjan van de Vend479e902006-01-06 16:47:00 -05001198 acpi_video_bus_POST_fops.write = acpi_video_bus_write_POST;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001199 entry->proc_fops = &acpi_video_bus_POST_fops;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001200 entry->data = acpi_driver_data(device);
1201 entry->owner = THIS_MODULE;
1202 }
1203
1204 /* 'DOS' [R/W] */
Len Brown4be44fc2005-08-05 00:44:28 -04001205 entry =
1206 create_proc_entry("DOS", S_IFREG | S_IRUGO | S_IRUSR,
1207 acpi_device_dir(device));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001208 if (!entry)
Patrick Mocheld550d982006-06-27 00:41:40 -04001209 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001210 else {
Arjan van de Vend479e902006-01-06 16:47:00 -05001211 acpi_video_bus_DOS_fops.write = acpi_video_bus_write_DOS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001212 entry->proc_fops = &acpi_video_bus_DOS_fops;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001213 entry->data = acpi_driver_data(device);
1214 entry->owner = THIS_MODULE;
1215 }
1216
Patrick Mocheld550d982006-06-27 00:41:40 -04001217 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001218}
1219
Len Brown4be44fc2005-08-05 00:44:28 -04001220static int acpi_video_bus_remove_fs(struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001221{
Len Brown4be44fc2005-08-05 00:44:28 -04001222 struct acpi_video_bus *video;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001223
Linus Torvalds1da177e2005-04-16 15:20:36 -07001224
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001225 video = acpi_driver_data(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001226
1227 if (acpi_device_dir(device)) {
1228 remove_proc_entry("info", acpi_device_dir(device));
1229 remove_proc_entry("ROM", acpi_device_dir(device));
1230 remove_proc_entry("POST_info", acpi_device_dir(device));
1231 remove_proc_entry("POST", acpi_device_dir(device));
1232 remove_proc_entry("DOS", acpi_device_dir(device));
Len Brown4be44fc2005-08-05 00:44:28 -04001233 remove_proc_entry(acpi_device_bid(device), acpi_video_dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001234 acpi_device_dir(device) = NULL;
1235 }
1236
Patrick Mocheld550d982006-06-27 00:41:40 -04001237 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001238}
1239
1240/* --------------------------------------------------------------------------
1241 Driver Interface
1242 -------------------------------------------------------------------------- */
1243
1244/* device interface */
1245
1246static int
Len Brown4be44fc2005-08-05 00:44:28 -04001247acpi_video_bus_get_one_device(struct acpi_device *device,
1248 struct acpi_video_bus *video)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001249{
Len Brown4be44fc2005-08-05 00:44:28 -04001250 unsigned long device_id;
Yu, Luming973bf492006-04-27 05:25:00 -04001251 int status;
Len Brown4be44fc2005-08-05 00:44:28 -04001252 struct acpi_video_device *data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001253
Linus Torvalds1da177e2005-04-16 15:20:36 -07001254
1255 if (!device || !video)
Patrick Mocheld550d982006-06-27 00:41:40 -04001256 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001257
Len Brown4be44fc2005-08-05 00:44:28 -04001258 status =
1259 acpi_evaluate_integer(device->handle, "_ADR", NULL, &device_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001260 if (ACPI_SUCCESS(status)) {
1261
1262 data = kmalloc(sizeof(struct acpi_video_device), GFP_KERNEL);
1263 if (!data)
Patrick Mocheld550d982006-06-27 00:41:40 -04001264 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001265
1266 memset(data, 0, sizeof(struct acpi_video_device));
1267
Linus Torvalds1da177e2005-04-16 15:20:36 -07001268 strcpy(acpi_device_name(device), ACPI_VIDEO_DEVICE_NAME);
1269 strcpy(acpi_device_class(device), ACPI_VIDEO_CLASS);
1270 acpi_driver_data(device) = data;
1271
1272 data->device_id = device_id;
1273 data->video = video;
1274 data->dev = device;
1275
1276 switch (device_id & 0xffff) {
1277 case 0x0100:
1278 data->flags.crt = 1;
1279 break;
1280 case 0x0400:
1281 data->flags.lcd = 1;
1282 break;
1283 case 0x0200:
1284 data->flags.tvout = 1;
1285 break;
1286 default:
1287 data->flags.unknown = 1;
1288 break;
1289 }
Len Brown4be44fc2005-08-05 00:44:28 -04001290
Linus Torvalds1da177e2005-04-16 15:20:36 -07001291 acpi_video_device_bind(video, data);
1292 acpi_video_device_find_cap(data);
1293
Patrick Mochel90130262006-05-19 16:54:48 -04001294 status = acpi_install_notify_handler(device->handle,
Len Brown4be44fc2005-08-05 00:44:28 -04001295 ACPI_DEVICE_NOTIFY,
1296 acpi_video_device_notify,
1297 data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001298 if (ACPI_FAILURE(status)) {
1299 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
Len Brown4be44fc2005-08-05 00:44:28 -04001300 "Error installing notify handler\n"));
Yu, Luming973bf492006-04-27 05:25:00 -04001301 if(data->brightness)
1302 kfree(data->brightness->levels);
1303 kfree(data->brightness);
1304 kfree(data);
1305 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001306 }
1307
1308 down(&video->sem);
1309 list_add_tail(&data->entry, &video->video_device_list);
1310 up(&video->sem);
1311
1312 acpi_video_device_add_fs(device);
1313
Patrick Mocheld550d982006-06-27 00:41:40 -04001314 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001315 }
1316
Patrick Mocheld550d982006-06-27 00:41:40 -04001317 return -ENOENT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001318}
1319
1320/*
1321 * Arg:
1322 * video : video bus device
1323 *
1324 * Return:
1325 * none
1326 *
1327 * Enumerate the video device list of the video bus,
1328 * bind the ids with the corresponding video devices
1329 * under the video bus.
Len Brown4be44fc2005-08-05 00:44:28 -04001330 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001331
Len Brown4be44fc2005-08-05 00:44:28 -04001332static void acpi_video_device_rebind(struct acpi_video_bus *video)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001333{
Len Brown4be44fc2005-08-05 00:44:28 -04001334 struct list_head *node, *next;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001335 list_for_each_safe(node, next, &video->video_device_list) {
Len Brown4be44fc2005-08-05 00:44:28 -04001336 struct acpi_video_device *dev =
1337 container_of(node, struct acpi_video_device, entry);
1338 acpi_video_device_bind(video, dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001339 }
1340}
1341
1342/*
1343 * Arg:
1344 * video : video bus device
1345 * device : video output device under the video
1346 * bus
1347 *
1348 * Return:
1349 * none
1350 *
1351 * Bind the ids with the corresponding video devices
1352 * under the video bus.
Len Brown4be44fc2005-08-05 00:44:28 -04001353 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001354
1355static void
Len Brown4be44fc2005-08-05 00:44:28 -04001356acpi_video_device_bind(struct acpi_video_bus *video,
1357 struct acpi_video_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001358{
Len Brown4be44fc2005-08-05 00:44:28 -04001359 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001360
1361#define IDS_VAL(i) video->attached_array[i].value.int_val
1362#define IDS_BIND(i) video->attached_array[i].bind_info
Len Brown4be44fc2005-08-05 00:44:28 -04001363
1364 for (i = 0; IDS_VAL(i) != ACPI_VIDEO_HEAD_INVALID &&
1365 i < video->attached_count; i++) {
1366 if (device->device_id == (IDS_VAL(i) & 0xffff)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001367 IDS_BIND(i) = device;
1368 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "device_bind %d\n", i));
1369 }
1370 }
1371#undef IDS_VAL
1372#undef IDS_BIND
1373}
1374
1375/*
1376 * Arg:
1377 * video : video bus device
1378 *
1379 * Return:
1380 * < 0 : error
1381 *
1382 * Call _DOD to enumerate all devices attached to display adapter
1383 *
Len Brown4be44fc2005-08-05 00:44:28 -04001384 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001385
1386static int acpi_video_device_enumerate(struct acpi_video_bus *video)
1387{
Len Brown4be44fc2005-08-05 00:44:28 -04001388 int status;
1389 int count;
1390 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001391 struct acpi_video_enumerated_device *active_device_list;
Len Brown4be44fc2005-08-05 00:44:28 -04001392 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
1393 union acpi_object *dod = NULL;
1394 union acpi_object *obj;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001395
Patrick Mochel90130262006-05-19 16:54:48 -04001396 status = acpi_evaluate_object(video->device->handle, "_DOD", NULL, &buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001397 if (!ACPI_SUCCESS(status)) {
Thomas Renningera6fc6722006-06-26 23:58:43 -04001398 ACPI_EXCEPTION((AE_INFO, status, "Evaluating _DOD"));
Patrick Mocheld550d982006-06-27 00:41:40 -04001399 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001400 }
1401
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001402 dod = buffer.pointer;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001403 if (!dod || (dod->type != ACPI_TYPE_PACKAGE)) {
Thomas Renningera6fc6722006-06-26 23:58:43 -04001404 ACPI_EXCEPTION((AE_INFO, status, "Invalid _DOD data"));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001405 status = -EFAULT;
1406 goto out;
1407 }
1408
1409 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found %d video heads in _DOD\n",
Len Brown4be44fc2005-08-05 00:44:28 -04001410 dod->package.count));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001411
Len Brown4be44fc2005-08-05 00:44:28 -04001412 active_device_list = kmalloc((1 +
1413 dod->package.count) *
1414 sizeof(struct
1415 acpi_video_enumerated_device),
1416 GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001417
1418 if (!active_device_list) {
1419 status = -ENOMEM;
1420 goto out;
1421 }
1422
1423 count = 0;
1424 for (i = 0; i < dod->package.count; i++) {
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001425 obj = &dod->package.elements[i];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001426
1427 if (obj->type != ACPI_TYPE_INTEGER) {
Len Brown64684632006-06-26 23:41:38 -04001428 printk(KERN_ERR PREFIX "Invalid _DOD data\n");
Len Brown4be44fc2005-08-05 00:44:28 -04001429 active_device_list[i].value.int_val =
1430 ACPI_VIDEO_HEAD_INVALID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001431 }
1432 active_device_list[i].value.int_val = obj->integer.value;
1433 active_device_list[i].bind_info = NULL;
Len Brown4be44fc2005-08-05 00:44:28 -04001434 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "dod element[%d] = %d\n", i,
1435 (int)obj->integer.value));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001436 count++;
1437 }
1438 active_device_list[count].value.int_val = ACPI_VIDEO_HEAD_END;
1439
Jesper Juhl6044ec82005-11-07 01:01:32 -08001440 kfree(video->attached_array);
Len Brown4be44fc2005-08-05 00:44:28 -04001441
Linus Torvalds1da177e2005-04-16 15:20:36 -07001442 video->attached_array = active_device_list;
1443 video->attached_count = count;
Len Brown4be44fc2005-08-05 00:44:28 -04001444 out:
Len Brown02438d82006-06-30 03:19:10 -04001445 kfree(buffer.pointer);
Patrick Mocheld550d982006-06-27 00:41:40 -04001446 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001447}
1448
1449/*
1450 * Arg:
1451 * video : video bus device
1452 * event : Nontify Event
1453 *
1454 * Return:
1455 * < 0 : error
1456 *
1457 * 1. Find out the current active output device.
1458 * 2. Identify the next output device to switch
1459 * 3. call _DSS to do actual switch.
Len Brown4be44fc2005-08-05 00:44:28 -04001460 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001461
Len Brown4be44fc2005-08-05 00:44:28 -04001462static int acpi_video_switch_output(struct acpi_video_bus *video, int event)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001463{
Len Brown4be44fc2005-08-05 00:44:28 -04001464 struct list_head *node, *next;
1465 struct acpi_video_device *dev = NULL;
1466 struct acpi_video_device *dev_next = NULL;
1467 struct acpi_video_device *dev_prev = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001468 unsigned long state;
1469 int status = 0;
1470
Linus Torvalds1da177e2005-04-16 15:20:36 -07001471
1472 list_for_each_safe(node, next, &video->video_device_list) {
Adrian Bunk73345712005-03-30 22:31:35 -05001473 dev = container_of(node, struct acpi_video_device, entry);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001474 status = acpi_video_device_get_state(dev, &state);
Len Brown4be44fc2005-08-05 00:44:28 -04001475 if (state & 0x2) {
1476 dev_next =
1477 container_of(node->next, struct acpi_video_device,
1478 entry);
1479 dev_prev =
1480 container_of(node->prev, struct acpi_video_device,
1481 entry);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001482 goto out;
1483 }
1484 }
1485 dev_next = container_of(node->next, struct acpi_video_device, entry);
1486 dev_prev = container_of(node->prev, struct acpi_video_device, entry);
Len Brown4be44fc2005-08-05 00:44:28 -04001487 out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001488 switch (event) {
1489 case ACPI_VIDEO_NOTIFY_CYCLE:
1490 case ACPI_VIDEO_NOTIFY_NEXT_OUTPUT:
1491 acpi_video_device_set_state(dev, 0);
1492 acpi_video_device_set_state(dev_next, 0x80000001);
1493 break;
1494 case ACPI_VIDEO_NOTIFY_PREV_OUTPUT:
1495 acpi_video_device_set_state(dev, 0);
1496 acpi_video_device_set_state(dev_prev, 0x80000001);
1497 default:
1498 break;
1499 }
1500
Patrick Mocheld550d982006-06-27 00:41:40 -04001501 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001502}
1503
Len Brown4be44fc2005-08-05 00:44:28 -04001504static int
1505acpi_video_get_next_level(struct acpi_video_device *device,
1506 u32 level_current, u32 event)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001507{
Len Brown4be44fc2005-08-05 00:44:28 -04001508 /*Fix me */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001509 return level_current;
1510}
1511
Linus Torvalds1da177e2005-04-16 15:20:36 -07001512static void
Len Brown4be44fc2005-08-05 00:44:28 -04001513acpi_video_switch_brightness(struct acpi_video_device *device, int event)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001514{
1515 unsigned long level_current, level_next;
1516 acpi_video_device_lcd_get_level_current(device, &level_current);
1517 level_next = acpi_video_get_next_level(device, level_current, event);
1518 acpi_video_device_lcd_set_level(device, level_next);
1519}
1520
1521static int
Len Brown4be44fc2005-08-05 00:44:28 -04001522acpi_video_bus_get_devices(struct acpi_video_bus *video,
1523 struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001524{
Len Brown4be44fc2005-08-05 00:44:28 -04001525 int status = 0;
1526 struct list_head *node, *next;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001527
Linus Torvalds1da177e2005-04-16 15:20:36 -07001528
1529 acpi_video_device_enumerate(video);
1530
1531 list_for_each_safe(node, next, &device->children) {
Len Brown4be44fc2005-08-05 00:44:28 -04001532 struct acpi_device *dev =
1533 list_entry(node, struct acpi_device, node);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001534
1535 if (!dev)
1536 continue;
1537
1538 status = acpi_video_bus_get_one_device(dev, video);
1539 if (ACPI_FAILURE(status)) {
Thomas Renningera6fc6722006-06-26 23:58:43 -04001540 ACPI_EXCEPTION((AE_INFO, status, "Cant attach device"));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001541 continue;
1542 }
1543
1544 }
Patrick Mocheld550d982006-06-27 00:41:40 -04001545 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001546}
1547
Len Brown4be44fc2005-08-05 00:44:28 -04001548static int acpi_video_bus_put_one_device(struct acpi_video_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001549{
Karol Kozimor031ec772005-07-30 04:18:00 -04001550 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001551 struct acpi_video_bus *video;
1552
Linus Torvalds1da177e2005-04-16 15:20:36 -07001553
1554 if (!device || !device->video)
Patrick Mocheld550d982006-06-27 00:41:40 -04001555 return -ENOENT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001556
1557 video = device->video;
1558
1559 down(&video->sem);
1560 list_del(&device->entry);
1561 up(&video->sem);
1562 acpi_video_device_remove_fs(device->dev);
1563
Patrick Mochel90130262006-05-19 16:54:48 -04001564 status = acpi_remove_notify_handler(device->dev->handle,
Len Brown4be44fc2005-08-05 00:44:28 -04001565 ACPI_DEVICE_NOTIFY,
1566 acpi_video_device_notify);
Karol Kozimor031ec772005-07-30 04:18:00 -04001567
Patrick Mocheld550d982006-06-27 00:41:40 -04001568 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001569}
1570
Len Brown4be44fc2005-08-05 00:44:28 -04001571static int acpi_video_bus_put_devices(struct acpi_video_bus *video)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001572{
Len Brown4be44fc2005-08-05 00:44:28 -04001573 int status;
1574 struct list_head *node, *next;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001575
Linus Torvalds1da177e2005-04-16 15:20:36 -07001576
1577 list_for_each_safe(node, next, &video->video_device_list) {
Len Brown4be44fc2005-08-05 00:44:28 -04001578 struct acpi_video_device *data =
1579 list_entry(node, struct acpi_video_device, entry);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001580 if (!data)
1581 continue;
1582
1583 status = acpi_video_bus_put_one_device(data);
Len Brown4be44fc2005-08-05 00:44:28 -04001584 if (ACPI_FAILURE(status))
1585 printk(KERN_WARNING PREFIX
1586 "hhuuhhuu bug in acpi video driver.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001587
Dave Jonesd384ea62006-06-24 00:33:08 -04001588 if (data->brightness)
Yu, Luming973bf492006-04-27 05:25:00 -04001589 kfree(data->brightness->levels);
Jesper Juhl6044ec82005-11-07 01:01:32 -08001590 kfree(data->brightness);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001591 kfree(data);
1592 }
1593
Patrick Mocheld550d982006-06-27 00:41:40 -04001594 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001595}
1596
1597/* acpi_video interface */
1598
Len Brown4be44fc2005-08-05 00:44:28 -04001599static int acpi_video_bus_start_devices(struct acpi_video_bus *video)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001600{
1601 return acpi_video_bus_DOS(video, 1, 0);
1602}
1603
Len Brown4be44fc2005-08-05 00:44:28 -04001604static int acpi_video_bus_stop_devices(struct acpi_video_bus *video)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001605{
1606 return acpi_video_bus_DOS(video, 0, 1);
1607}
1608
Len Brown4be44fc2005-08-05 00:44:28 -04001609static void acpi_video_bus_notify(acpi_handle handle, u32 event, void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001610{
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001611 struct acpi_video_bus *video = data;
Len Brown4be44fc2005-08-05 00:44:28 -04001612 struct acpi_device *device = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001613
Linus Torvalds1da177e2005-04-16 15:20:36 -07001614 printk("video bus notify\n");
1615
1616 if (!video)
Patrick Mocheld550d982006-06-27 00:41:40 -04001617 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001618
Patrick Mochele6afa0d2006-05-19 16:54:40 -04001619 device = video->device;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001620
1621 switch (event) {
1622 case ACPI_VIDEO_NOTIFY_SWITCH: /* User request that a switch occur,
1623 * most likely via hotkey. */
1624 acpi_bus_generate_event(device, event, 0);
1625 break;
1626
1627 case ACPI_VIDEO_NOTIFY_PROBE: /* User plug or remove a video
1628 * connector. */
1629 acpi_video_device_enumerate(video);
1630 acpi_video_device_rebind(video);
1631 acpi_video_switch_output(video, event);
1632 acpi_bus_generate_event(device, event, 0);
1633 break;
1634
Len Brown4be44fc2005-08-05 00:44:28 -04001635 case ACPI_VIDEO_NOTIFY_CYCLE: /* Cycle Display output hotkey pressed. */
1636 case ACPI_VIDEO_NOTIFY_NEXT_OUTPUT: /* Next Display output hotkey pressed. */
1637 case ACPI_VIDEO_NOTIFY_PREV_OUTPUT: /* previous Display output hotkey pressed. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001638 acpi_video_switch_output(video, event);
1639 acpi_bus_generate_event(device, event, 0);
1640 break;
1641
1642 default:
1643 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
Len Brown4be44fc2005-08-05 00:44:28 -04001644 "Unsupported event [0x%x]\n", event));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001645 break;
1646 }
1647
Patrick Mocheld550d982006-06-27 00:41:40 -04001648 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001649}
1650
Len Brown4be44fc2005-08-05 00:44:28 -04001651static void acpi_video_device_notify(acpi_handle handle, u32 event, void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001652{
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001653 struct acpi_video_device *video_device = data;
Len Brown4be44fc2005-08-05 00:44:28 -04001654 struct acpi_device *device = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001655
Linus Torvalds1da177e2005-04-16 15:20:36 -07001656
1657 printk("video device notify\n");
1658 if (!video_device)
Patrick Mocheld550d982006-06-27 00:41:40 -04001659 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001660
Patrick Mochele6afa0d2006-05-19 16:54:40 -04001661 device = video_device->dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001662
1663 switch (event) {
Len Brown4be44fc2005-08-05 00:44:28 -04001664 case ACPI_VIDEO_NOTIFY_SWITCH: /* change in status (cycle output device) */
1665 case ACPI_VIDEO_NOTIFY_PROBE: /* change in status (output device status) */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001666 acpi_bus_generate_event(device, event, 0);
1667 break;
Len Brown4be44fc2005-08-05 00:44:28 -04001668 case ACPI_VIDEO_NOTIFY_CYCLE_BRIGHTNESS: /* Cycle brightness */
1669 case ACPI_VIDEO_NOTIFY_INC_BRIGHTNESS: /* Increase brightness */
1670 case ACPI_VIDEO_NOTIFY_DEC_BRIGHTNESS: /* Decrease brightness */
1671 case ACPI_VIDEO_NOTIFY_ZERO_BRIGHTNESS: /* zero brightnesss */
1672 case ACPI_VIDEO_NOTIFY_DISPLAY_OFF: /* display device off */
1673 acpi_video_switch_brightness(video_device, event);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001674 acpi_bus_generate_event(device, event, 0);
1675 break;
1676 default:
1677 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
Len Brown4be44fc2005-08-05 00:44:28 -04001678 "Unsupported event [0x%x]\n", event));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001679 break;
1680 }
Patrick Mocheld550d982006-06-27 00:41:40 -04001681 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001682}
1683
Len Brown4be44fc2005-08-05 00:44:28 -04001684static int acpi_video_bus_add(struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001685{
Len Brown4be44fc2005-08-05 00:44:28 -04001686 int result = 0;
1687 acpi_status status = 0;
1688 struct acpi_video_bus *video = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001689
Len Brown4be44fc2005-08-05 00:44:28 -04001690
Linus Torvalds1da177e2005-04-16 15:20:36 -07001691 if (!device)
Patrick Mocheld550d982006-06-27 00:41:40 -04001692 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001693
1694 video = kmalloc(sizeof(struct acpi_video_bus), GFP_KERNEL);
1695 if (!video)
Patrick Mocheld550d982006-06-27 00:41:40 -04001696 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001697 memset(video, 0, sizeof(struct acpi_video_bus));
1698
Patrick Mochele6afa0d2006-05-19 16:54:40 -04001699 video->device = device;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001700 strcpy(acpi_device_name(device), ACPI_VIDEO_BUS_NAME);
1701 strcpy(acpi_device_class(device), ACPI_VIDEO_CLASS);
1702 acpi_driver_data(device) = video;
1703
1704 acpi_video_bus_find_cap(video);
1705 result = acpi_video_bus_check(video);
1706 if (result)
1707 goto end;
1708
1709 result = acpi_video_bus_add_fs(device);
1710 if (result)
1711 goto end;
1712
1713 init_MUTEX(&video->sem);
1714 INIT_LIST_HEAD(&video->video_device_list);
1715
1716 acpi_video_bus_get_devices(video, device);
1717 acpi_video_bus_start_devices(video);
1718
Patrick Mochel90130262006-05-19 16:54:48 -04001719 status = acpi_install_notify_handler(device->handle,
Len Brown4be44fc2005-08-05 00:44:28 -04001720 ACPI_DEVICE_NOTIFY,
1721 acpi_video_bus_notify, video);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001722 if (ACPI_FAILURE(status)) {
1723 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
Len Brown4be44fc2005-08-05 00:44:28 -04001724 "Error installing notify handler\n"));
Yu, Luming973bf492006-04-27 05:25:00 -04001725 acpi_video_bus_stop_devices(video);
1726 acpi_video_bus_put_devices(video);
1727 kfree(video->attached_array);
1728 acpi_video_bus_remove_fs(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001729 result = -ENODEV;
1730 goto end;
1731 }
1732
1733 printk(KERN_INFO PREFIX "%s [%s] (multi-head: %s rom: %s post: %s)\n",
Len Brown4be44fc2005-08-05 00:44:28 -04001734 ACPI_VIDEO_DEVICE_NAME, acpi_device_bid(device),
1735 video->flags.multihead ? "yes" : "no",
1736 video->flags.rom ? "yes" : "no",
1737 video->flags.post ? "yes" : "no");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001738
Len Brown4be44fc2005-08-05 00:44:28 -04001739 end:
Yu, Luming973bf492006-04-27 05:25:00 -04001740 if (result)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001741 kfree(video);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001742
Patrick Mocheld550d982006-06-27 00:41:40 -04001743 return result;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001744}
1745
Len Brown4be44fc2005-08-05 00:44:28 -04001746static int acpi_video_bus_remove(struct acpi_device *device, int type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001747{
Len Brown4be44fc2005-08-05 00:44:28 -04001748 acpi_status status = 0;
1749 struct acpi_video_bus *video = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001750
Linus Torvalds1da177e2005-04-16 15:20:36 -07001751
1752 if (!device || !acpi_driver_data(device))
Patrick Mocheld550d982006-06-27 00:41:40 -04001753 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001754
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001755 video = acpi_driver_data(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001756
1757 acpi_video_bus_stop_devices(video);
1758
Patrick Mochel90130262006-05-19 16:54:48 -04001759 status = acpi_remove_notify_handler(video->device->handle,
Len Brown4be44fc2005-08-05 00:44:28 -04001760 ACPI_DEVICE_NOTIFY,
1761 acpi_video_bus_notify);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001762
1763 acpi_video_bus_put_devices(video);
1764 acpi_video_bus_remove_fs(device);
1765
Jesper Juhl6044ec82005-11-07 01:01:32 -08001766 kfree(video->attached_array);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001767 kfree(video);
1768
Patrick Mocheld550d982006-06-27 00:41:40 -04001769 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001770}
1771
Linus Torvalds1da177e2005-04-16 15:20:36 -07001772static int
Len Brown4be44fc2005-08-05 00:44:28 -04001773acpi_video_bus_match(struct acpi_device *device, struct acpi_driver *driver)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001774{
Len Brown4be44fc2005-08-05 00:44:28 -04001775 acpi_handle h_dummy1;
1776 acpi_handle h_dummy2;
1777 acpi_handle h_dummy3;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001778
Linus Torvalds1da177e2005-04-16 15:20:36 -07001779
1780 if (!device || !driver)
Patrick Mocheld550d982006-06-27 00:41:40 -04001781 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001782
1783 /* Since there is no HID, CID for ACPI Video drivers, we have
1784 * to check well known required nodes for each feature we support.
1785 */
1786
1787 /* Does this device able to support video switching ? */
1788 if (ACPI_SUCCESS(acpi_get_handle(device->handle, "_DOD", &h_dummy1)) &&
1789 ACPI_SUCCESS(acpi_get_handle(device->handle, "_DOS", &h_dummy2)))
Patrick Mocheld550d982006-06-27 00:41:40 -04001790 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001791
1792 /* Does this device able to retrieve a video ROM ? */
1793 if (ACPI_SUCCESS(acpi_get_handle(device->handle, "_ROM", &h_dummy1)))
Patrick Mocheld550d982006-06-27 00:41:40 -04001794 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001795
1796 /* Does this device able to configure which video head to be POSTed ? */
1797 if (ACPI_SUCCESS(acpi_get_handle(device->handle, "_VPO", &h_dummy1)) &&
1798 ACPI_SUCCESS(acpi_get_handle(device->handle, "_GPD", &h_dummy2)) &&
1799 ACPI_SUCCESS(acpi_get_handle(device->handle, "_SPD", &h_dummy3)))
Patrick Mocheld550d982006-06-27 00:41:40 -04001800 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001801
Patrick Mocheld550d982006-06-27 00:41:40 -04001802 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001803}
1804
Len Brown4be44fc2005-08-05 00:44:28 -04001805static int __init acpi_video_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001806{
Len Brown4be44fc2005-08-05 00:44:28 -04001807 int result = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001808
Linus Torvalds1da177e2005-04-16 15:20:36 -07001809
1810 /*
Len Brown4be44fc2005-08-05 00:44:28 -04001811 acpi_dbg_level = 0xFFFFFFFF;
1812 acpi_dbg_layer = 0x08000000;
1813 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001814
1815 acpi_video_dir = proc_mkdir(ACPI_VIDEO_CLASS, acpi_root_dir);
1816 if (!acpi_video_dir)
Patrick Mocheld550d982006-06-27 00:41:40 -04001817 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001818 acpi_video_dir->owner = THIS_MODULE;
1819
1820 result = acpi_bus_register_driver(&acpi_video_bus);
1821 if (result < 0) {
1822 remove_proc_entry(ACPI_VIDEO_CLASS, acpi_root_dir);
Patrick Mocheld550d982006-06-27 00:41:40 -04001823 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001824 }
1825
Patrick Mocheld550d982006-06-27 00:41:40 -04001826 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001827}
1828
Len Brown4be44fc2005-08-05 00:44:28 -04001829static void __exit acpi_video_exit(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001830{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001831
1832 acpi_bus_unregister_driver(&acpi_video_bus);
1833
1834 remove_proc_entry(ACPI_VIDEO_CLASS, acpi_root_dir);
1835
Patrick Mocheld550d982006-06-27 00:41:40 -04001836 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001837}
1838
1839module_init(acpi_video_init);
1840module_exit(acpi_video_exit);