blob: 6e99eea689c855f282f15871411c04d44734ba5c [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);
Linus Torvalds1da177e2005-04-16 15:20:36 -070068
69static struct acpi_driver acpi_video_bus = {
70 .name = ACPI_VIDEO_DRIVER_NAME,
71 .class = ACPI_VIDEO_CLASS,
Zhang Ruiae843332006-12-07 20:57:10 +080072 .ids = ACPI_VIDEO_HID,
Linus Torvalds1da177e2005-04-16 15:20:36 -070073 .ops = {
74 .add = acpi_video_bus_add,
75 .remove = acpi_video_bus_remove,
Len Brown4be44fc2005-08-05 00:44:28 -040076 },
Linus Torvalds1da177e2005-04-16 15:20:36 -070077};
78
79struct acpi_video_bus_flags {
Len Brown4be44fc2005-08-05 00:44:28 -040080 u8 multihead:1; /* can switch video heads */
81 u8 rom:1; /* can retrieve a video rom */
82 u8 post:1; /* can configure the head to */
83 u8 reserved:5;
Linus Torvalds1da177e2005-04-16 15:20:36 -070084};
85
86struct acpi_video_bus_cap {
Len Brown4be44fc2005-08-05 00:44:28 -040087 u8 _DOS:1; /*Enable/Disable output switching */
88 u8 _DOD:1; /*Enumerate all devices attached to display adapter */
89 u8 _ROM:1; /*Get ROM Data */
90 u8 _GPD:1; /*Get POST Device */
91 u8 _SPD:1; /*Set POST Device */
92 u8 _VPO:1; /*Video POST Options */
93 u8 reserved:2;
Linus Torvalds1da177e2005-04-16 15:20:36 -070094};
95
Len Brown4be44fc2005-08-05 00:44:28 -040096struct acpi_video_device_attrib {
97 u32 display_index:4; /* A zero-based instance of the Display */
98 u32 display_port_attachment:4; /*This field differenates displays type */
99 u32 display_type:4; /*Describe the specific type in use */
100 u32 vendor_specific:4; /*Chipset Vendor Specifi */
101 u32 bios_can_detect:1; /*BIOS can detect the device */
102 u32 depend_on_vga:1; /*Non-VGA output device whose power is related to
103 the VGA device. */
104 u32 pipe_id:3; /*For VGA multiple-head devices. */
105 u32 reserved:10; /*Must be 0 */
106 u32 device_id_scheme:1; /*Device ID Scheme */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107};
108
109struct acpi_video_enumerated_device {
110 union {
111 u32 int_val;
Len Brown4be44fc2005-08-05 00:44:28 -0400112 struct acpi_video_device_attrib attrib;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113 } value;
114 struct acpi_video_device *bind_info;
115};
116
117struct acpi_video_bus {
Patrick Mochele6afa0d2006-05-19 16:54:40 -0400118 struct acpi_device *device;
Len Brown4be44fc2005-08-05 00:44:28 -0400119 u8 dos_setting;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120 struct acpi_video_enumerated_device *attached_array;
Len Brown4be44fc2005-08-05 00:44:28 -0400121 u8 attached_count;
122 struct acpi_video_bus_cap cap;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123 struct acpi_video_bus_flags flags;
Len Brown4be44fc2005-08-05 00:44:28 -0400124 struct semaphore sem;
125 struct list_head video_device_list;
126 struct proc_dir_entry *dir;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127};
128
129struct acpi_video_device_flags {
Len Brown4be44fc2005-08-05 00:44:28 -0400130 u8 crt:1;
131 u8 lcd:1;
132 u8 tvout:1;
133 u8 bios:1;
134 u8 unknown:1;
135 u8 reserved:3;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136};
137
138struct acpi_video_device_cap {
Len Brown4be44fc2005-08-05 00:44:28 -0400139 u8 _ADR:1; /*Return the unique ID */
140 u8 _BCL:1; /*Query list of brightness control levels supported */
141 u8 _BCM:1; /*Set the brightness level */
142 u8 _DDC:1; /*Return the EDID for this device */
143 u8 _DCS:1; /*Return status of output device */
144 u8 _DGS:1; /*Query graphics state */
145 u8 _DSS:1; /*Device state set */
146 u8 _reserved:1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147};
148
149struct acpi_video_device_brightness {
Len Brown4be44fc2005-08-05 00:44:28 -0400150 int curr;
151 int count;
152 int *levels;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700153};
154
155struct acpi_video_device {
Len Brown4be44fc2005-08-05 00:44:28 -0400156 unsigned long device_id;
157 struct acpi_video_device_flags flags;
158 struct acpi_video_device_cap cap;
159 struct list_head entry;
160 struct acpi_video_bus *video;
161 struct acpi_device *dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700162 struct acpi_video_device_brightness *brightness;
163};
164
Linus Torvalds1da177e2005-04-16 15:20:36 -0700165/* bus */
166static int acpi_video_bus_info_open_fs(struct inode *inode, struct file *file);
167static struct file_operations acpi_video_bus_info_fops = {
Len Brown4be44fc2005-08-05 00:44:28 -0400168 .open = acpi_video_bus_info_open_fs,
169 .read = seq_read,
170 .llseek = seq_lseek,
171 .release = single_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700172};
173
174static int acpi_video_bus_ROM_open_fs(struct inode *inode, struct file *file);
175static struct file_operations acpi_video_bus_ROM_fops = {
Len Brown4be44fc2005-08-05 00:44:28 -0400176 .open = acpi_video_bus_ROM_open_fs,
177 .read = seq_read,
178 .llseek = seq_lseek,
179 .release = single_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180};
181
Len Brown4be44fc2005-08-05 00:44:28 -0400182static int acpi_video_bus_POST_info_open_fs(struct inode *inode,
183 struct file *file);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700184static struct file_operations acpi_video_bus_POST_info_fops = {
Len Brown4be44fc2005-08-05 00:44:28 -0400185 .open = acpi_video_bus_POST_info_open_fs,
186 .read = seq_read,
187 .llseek = seq_lseek,
188 .release = single_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700189};
190
191static int acpi_video_bus_POST_open_fs(struct inode *inode, struct file *file);
192static struct file_operations acpi_video_bus_POST_fops = {
Len Brown4be44fc2005-08-05 00:44:28 -0400193 .open = acpi_video_bus_POST_open_fs,
194 .read = seq_read,
195 .llseek = seq_lseek,
196 .release = single_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700197};
198
Linus Torvalds1da177e2005-04-16 15:20:36 -0700199static int acpi_video_bus_DOS_open_fs(struct inode *inode, struct file *file);
200static struct file_operations acpi_video_bus_DOS_fops = {
Len Brown4be44fc2005-08-05 00:44:28 -0400201 .open = acpi_video_bus_DOS_open_fs,
202 .read = seq_read,
203 .llseek = seq_lseek,
204 .release = single_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700205};
206
207/* device */
Len Brown4be44fc2005-08-05 00:44:28 -0400208static int acpi_video_device_info_open_fs(struct inode *inode,
209 struct file *file);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700210static struct file_operations acpi_video_device_info_fops = {
Len Brown4be44fc2005-08-05 00:44:28 -0400211 .open = acpi_video_device_info_open_fs,
212 .read = seq_read,
213 .llseek = seq_lseek,
214 .release = single_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700215};
216
Len Brown4be44fc2005-08-05 00:44:28 -0400217static int acpi_video_device_state_open_fs(struct inode *inode,
218 struct file *file);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700219static struct file_operations acpi_video_device_state_fops = {
Len Brown4be44fc2005-08-05 00:44:28 -0400220 .open = acpi_video_device_state_open_fs,
221 .read = seq_read,
222 .llseek = seq_lseek,
223 .release = single_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700224};
225
Len Brown4be44fc2005-08-05 00:44:28 -0400226static int acpi_video_device_brightness_open_fs(struct inode *inode,
227 struct file *file);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700228static struct file_operations acpi_video_device_brightness_fops = {
Len Brown4be44fc2005-08-05 00:44:28 -0400229 .open = acpi_video_device_brightness_open_fs,
230 .read = seq_read,
231 .llseek = seq_lseek,
232 .release = single_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700233};
234
Len Brown4be44fc2005-08-05 00:44:28 -0400235static int acpi_video_device_EDID_open_fs(struct inode *inode,
236 struct file *file);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700237static struct file_operations acpi_video_device_EDID_fops = {
Len Brown4be44fc2005-08-05 00:44:28 -0400238 .open = acpi_video_device_EDID_open_fs,
239 .read = seq_read,
240 .llseek = seq_lseek,
241 .release = single_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700242};
243
Len Brown4be44fc2005-08-05 00:44:28 -0400244static char device_decode[][30] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700245 "motherboard VGA device",
246 "PCI VGA device",
247 "AGP VGA device",
248 "UNKNOWN",
249};
250
Len Brown4be44fc2005-08-05 00:44:28 -0400251static void acpi_video_device_notify(acpi_handle handle, u32 event, void *data);
252static void acpi_video_device_rebind(struct acpi_video_bus *video);
253static void acpi_video_device_bind(struct acpi_video_bus *video,
254 struct acpi_video_device *device);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700255static int acpi_video_device_enumerate(struct acpi_video_bus *video);
Len Brown4be44fc2005-08-05 00:44:28 -0400256static int acpi_video_switch_output(struct acpi_video_bus *video, int event);
257static int acpi_video_get_next_level(struct acpi_video_device *device,
258 u32 level_current, u32 event);
259static void acpi_video_switch_brightness(struct acpi_video_device *device,
260 int event);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700261
262/* --------------------------------------------------------------------------
263 Video Management
264 -------------------------------------------------------------------------- */
265
266/* device */
267
268static int
Len Brown4be44fc2005-08-05 00:44:28 -0400269acpi_video_device_query(struct acpi_video_device *device, unsigned long *state)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700270{
Len Brown4be44fc2005-08-05 00:44:28 -0400271 int status;
Patrick Mochel90130262006-05-19 16:54:48 -0400272
273 status = acpi_evaluate_integer(device->dev->handle, "_DGS", NULL, state);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700274
Patrick Mocheld550d982006-06-27 00:41:40 -0400275 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700276}
277
278static int
Len Brown4be44fc2005-08-05 00:44:28 -0400279acpi_video_device_get_state(struct acpi_video_device *device,
280 unsigned long *state)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700281{
Len Brown4be44fc2005-08-05 00:44:28 -0400282 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700283
Patrick Mochel90130262006-05-19 16:54:48 -0400284 status = acpi_evaluate_integer(device->dev->handle, "_DCS", NULL, state);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700285
Patrick Mocheld550d982006-06-27 00:41:40 -0400286 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700287}
288
289static int
Len Brown4be44fc2005-08-05 00:44:28 -0400290acpi_video_device_set_state(struct acpi_video_device *device, int state)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700291{
Len Brown4be44fc2005-08-05 00:44:28 -0400292 int status;
293 union acpi_object arg0 = { ACPI_TYPE_INTEGER };
294 struct acpi_object_list args = { 1, &arg0 };
Luming Yu824b5582005-08-21 19:17:00 -0400295 unsigned long ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700296
Linus Torvalds1da177e2005-04-16 15:20:36 -0700297
298 arg0.integer.value = state;
Patrick Mochel90130262006-05-19 16:54:48 -0400299 status = acpi_evaluate_integer(device->dev->handle, "_DSS", &args, &ret);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700300
Patrick Mocheld550d982006-06-27 00:41:40 -0400301 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700302}
303
304static int
Len Brown4be44fc2005-08-05 00:44:28 -0400305acpi_video_device_lcd_query_levels(struct acpi_video_device *device,
306 union acpi_object **levels)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700307{
Len Brown4be44fc2005-08-05 00:44:28 -0400308 int status;
309 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
310 union acpi_object *obj;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700311
Linus Torvalds1da177e2005-04-16 15:20:36 -0700312
313 *levels = NULL;
314
Patrick Mochel90130262006-05-19 16:54:48 -0400315 status = acpi_evaluate_object(device->dev->handle, "_BCL", NULL, &buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700316 if (!ACPI_SUCCESS(status))
Patrick Mocheld550d982006-06-27 00:41:40 -0400317 return status;
Len Brown4be44fc2005-08-05 00:44:28 -0400318 obj = (union acpi_object *)buffer.pointer;
Adrian Bunk6665bda2006-03-11 10:12:00 -0500319 if (!obj || (obj->type != ACPI_TYPE_PACKAGE)) {
Len Brown64684632006-06-26 23:41:38 -0400320 printk(KERN_ERR PREFIX "Invalid _BCL data\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700321 status = -EFAULT;
322 goto err;
323 }
324
325 *levels = obj;
326
Patrick Mocheld550d982006-06-27 00:41:40 -0400327 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700328
Len Brown4be44fc2005-08-05 00:44:28 -0400329 err:
Jesper Juhl6044ec82005-11-07 01:01:32 -0800330 kfree(buffer.pointer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700331
Patrick Mocheld550d982006-06-27 00:41:40 -0400332 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700333}
334
335static int
Len Brown4be44fc2005-08-05 00:44:28 -0400336acpi_video_device_lcd_set_level(struct acpi_video_device *device, int level)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700337{
Len Brown4be44fc2005-08-05 00:44:28 -0400338 int status;
339 union acpi_object arg0 = { ACPI_TYPE_INTEGER };
340 struct acpi_object_list args = { 1, &arg0 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700341
Linus Torvalds1da177e2005-04-16 15:20:36 -0700342
343 arg0.integer.value = level;
Patrick Mochel90130262006-05-19 16:54:48 -0400344 status = acpi_evaluate_object(device->dev->handle, "_BCM", &args, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700345
346 printk(KERN_DEBUG "set_level status: %x\n", status);
Patrick Mocheld550d982006-06-27 00:41:40 -0400347 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700348}
349
350static int
Len Brown4be44fc2005-08-05 00:44:28 -0400351acpi_video_device_lcd_get_level_current(struct acpi_video_device *device,
352 unsigned long *level)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700353{
Len Brown4be44fc2005-08-05 00:44:28 -0400354 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700355
Patrick Mochel90130262006-05-19 16:54:48 -0400356 status = acpi_evaluate_integer(device->dev->handle, "_BQC", NULL, level);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700357
Patrick Mocheld550d982006-06-27 00:41:40 -0400358 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700359}
360
361static int
Len Brown4be44fc2005-08-05 00:44:28 -0400362acpi_video_device_EDID(struct acpi_video_device *device,
363 union acpi_object **edid, ssize_t length)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700364{
Len Brown4be44fc2005-08-05 00:44:28 -0400365 int status;
366 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
367 union acpi_object *obj;
368 union acpi_object arg0 = { ACPI_TYPE_INTEGER };
369 struct acpi_object_list args = { 1, &arg0 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700370
Linus Torvalds1da177e2005-04-16 15:20:36 -0700371
372 *edid = NULL;
373
374 if (!device)
Patrick Mocheld550d982006-06-27 00:41:40 -0400375 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700376 if (length == 128)
377 arg0.integer.value = 1;
378 else if (length == 256)
379 arg0.integer.value = 2;
380 else
Patrick Mocheld550d982006-06-27 00:41:40 -0400381 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700382
Patrick Mochel90130262006-05-19 16:54:48 -0400383 status = acpi_evaluate_object(device->dev->handle, "_DDC", &args, &buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700384 if (ACPI_FAILURE(status))
Patrick Mocheld550d982006-06-27 00:41:40 -0400385 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700386
Len Brown4be44fc2005-08-05 00:44:28 -0400387 obj = (union acpi_object *)buffer.pointer;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700388
389 if (obj && obj->type == ACPI_TYPE_BUFFER)
390 *edid = obj;
391 else {
Len Brown64684632006-06-26 23:41:38 -0400392 printk(KERN_ERR PREFIX "Invalid _DDC data\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700393 status = -EFAULT;
394 kfree(obj);
395 }
396
Patrick Mocheld550d982006-06-27 00:41:40 -0400397 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700398}
399
Linus Torvalds1da177e2005-04-16 15:20:36 -0700400/* bus */
401
402static int
Len Brown4be44fc2005-08-05 00:44:28 -0400403acpi_video_bus_set_POST(struct acpi_video_bus *video, unsigned long option)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700404{
Len Brown4be44fc2005-08-05 00:44:28 -0400405 int status;
406 unsigned long tmp;
407 union acpi_object arg0 = { ACPI_TYPE_INTEGER };
408 struct acpi_object_list args = { 1, &arg0 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700409
Linus Torvalds1da177e2005-04-16 15:20:36 -0700410
411 arg0.integer.value = option;
412
Patrick Mochel90130262006-05-19 16:54:48 -0400413 status = acpi_evaluate_integer(video->device->handle, "_SPD", &args, &tmp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700414 if (ACPI_SUCCESS(status))
Len Brown4be44fc2005-08-05 00:44:28 -0400415 status = tmp ? (-EINVAL) : (AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700416
Patrick Mocheld550d982006-06-27 00:41:40 -0400417 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700418}
419
420static int
Len Brown4be44fc2005-08-05 00:44:28 -0400421acpi_video_bus_get_POST(struct acpi_video_bus *video, unsigned long *id)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700422{
423 int status;
424
Patrick Mochel90130262006-05-19 16:54:48 -0400425 status = acpi_evaluate_integer(video->device->handle, "_GPD", NULL, id);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700426
Patrick Mocheld550d982006-06-27 00:41:40 -0400427 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700428}
429
430static int
Len Brown4be44fc2005-08-05 00:44:28 -0400431acpi_video_bus_POST_options(struct acpi_video_bus *video,
432 unsigned long *options)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700433{
Len Brown4be44fc2005-08-05 00:44:28 -0400434 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700435
Patrick Mochel90130262006-05-19 16:54:48 -0400436 status = acpi_evaluate_integer(video->device->handle, "_VPO", NULL, options);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700437 *options &= 3;
438
Patrick Mocheld550d982006-06-27 00:41:40 -0400439 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700440}
441
442/*
443 * Arg:
444 * video : video bus device pointer
445 * bios_flag :
446 * 0. The system BIOS should NOT automatically switch(toggle)
447 * the active display output.
448 * 1. The system BIOS should automatically switch (toggle) the
449 * active display output. No swich event.
450 * 2. The _DGS value should be locked.
451 * 3. The system BIOS should not automatically switch (toggle) the
452 * active display output, but instead generate the display switch
453 * event notify code.
454 * lcd_flag :
455 * 0. The system BIOS should automatically control the brightness level
456 * of the LCD, when the power changes from AC to DC
457 * 1. The system BIOS should NOT automatically control the brightness
458 * level of the LCD, when the power changes from AC to DC.
459 * Return Value:
460 * -1 wrong arg.
461 */
462
463static int
Len Brown4be44fc2005-08-05 00:44:28 -0400464acpi_video_bus_DOS(struct acpi_video_bus *video, int bios_flag, int lcd_flag)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700465{
Len Brown4be44fc2005-08-05 00:44:28 -0400466 acpi_integer status = 0;
467 union acpi_object arg0 = { ACPI_TYPE_INTEGER };
468 struct acpi_object_list args = { 1, &arg0 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700469
Linus Torvalds1da177e2005-04-16 15:20:36 -0700470
Len Brown4be44fc2005-08-05 00:44:28 -0400471 if (bios_flag < 0 || bios_flag > 3 || lcd_flag < 0 || lcd_flag > 1) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700472 status = -1;
473 goto Failed;
474 }
475 arg0.integer.value = (lcd_flag << 2) | bios_flag;
476 video->dos_setting = arg0.integer.value;
Patrick Mochel90130262006-05-19 16:54:48 -0400477 acpi_evaluate_object(video->device->handle, "_DOS", &args, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700478
Len Brown4be44fc2005-08-05 00:44:28 -0400479 Failed:
Patrick Mocheld550d982006-06-27 00:41:40 -0400480 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700481}
482
483/*
484 * Arg:
485 * device : video output device (LCD, CRT, ..)
486 *
487 * Return Value:
488 * None
489 *
490 * Find out all required AML method defined under the output
491 * device.
492 */
493
Len Brown4be44fc2005-08-05 00:44:28 -0400494static void acpi_video_device_find_cap(struct acpi_video_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700495{
Len Brown4be44fc2005-08-05 00:44:28 -0400496 acpi_integer status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700497 acpi_handle h_dummy1;
498 int i;
499 union acpi_object *obj = NULL;
500 struct acpi_video_device_brightness *br = NULL;
501
Linus Torvalds1da177e2005-04-16 15:20:36 -0700502
Len Brown4be44fc2005-08-05 00:44:28 -0400503 memset(&device->cap, 0, 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700504
Patrick Mochel90130262006-05-19 16:54:48 -0400505 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_ADR", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700506 device->cap._ADR = 1;
507 }
Patrick Mochel90130262006-05-19 16:54:48 -0400508 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_BCL", &h_dummy1))) {
Len Brown4be44fc2005-08-05 00:44:28 -0400509 device->cap._BCL = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700510 }
Patrick Mochel90130262006-05-19 16:54:48 -0400511 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_BCM", &h_dummy1))) {
Len Brown4be44fc2005-08-05 00:44:28 -0400512 device->cap._BCM = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700513 }
Patrick Mochel90130262006-05-19 16:54:48 -0400514 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_DDC", &h_dummy1))) {
Len Brown4be44fc2005-08-05 00:44:28 -0400515 device->cap._DDC = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700516 }
Patrick Mochel90130262006-05-19 16:54:48 -0400517 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_DCS", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700518 device->cap._DCS = 1;
519 }
Patrick Mochel90130262006-05-19 16:54:48 -0400520 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_DGS", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700521 device->cap._DGS = 1;
522 }
Patrick Mochel90130262006-05-19 16:54:48 -0400523 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_DSS", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700524 device->cap._DSS = 1;
525 }
526
527 status = acpi_video_device_lcd_query_levels(device, &obj);
528
529 if (obj && obj->type == ACPI_TYPE_PACKAGE && obj->package.count >= 2) {
530 int count = 0;
531 union acpi_object *o;
Len Brown4be44fc2005-08-05 00:44:28 -0400532
Paulo Marquesd1dd0c22005-03-30 22:39:49 -0500533 br = kmalloc(sizeof(*br), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700534 if (!br) {
535 printk(KERN_ERR "can't allocate memory\n");
536 } else {
Paulo Marquesd1dd0c22005-03-30 22:39:49 -0500537 memset(br, 0, sizeof(*br));
538 br->levels = kmalloc(obj->package.count *
Len Brown4be44fc2005-08-05 00:44:28 -0400539 sizeof *(br->levels), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700540 if (!br->levels)
541 goto out;
542
543 for (i = 0; i < obj->package.count; i++) {
Len Brown4be44fc2005-08-05 00:44:28 -0400544 o = (union acpi_object *)&obj->package.
545 elements[i];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700546 if (o->type != ACPI_TYPE_INTEGER) {
Len Brown64684632006-06-26 23:41:38 -0400547 printk(KERN_ERR PREFIX "Invalid data\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700548 continue;
549 }
550 br->levels[count] = (u32) o->integer.value;
551 count++;
552 }
Len Brown4be44fc2005-08-05 00:44:28 -0400553 out:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700554 if (count < 2) {
Paulo Marquesd1dd0c22005-03-30 22:39:49 -0500555 kfree(br->levels);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700556 kfree(br);
557 } else {
558 br->count = count;
559 device->brightness = br;
Len Brown4be44fc2005-08-05 00:44:28 -0400560 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
561 "found %d brightness levels\n",
562 count));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700563 }
564 }
565 }
566
Paulo Marquesd1dd0c22005-03-30 22:39:49 -0500567 kfree(obj);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700568
Patrick Mocheld550d982006-06-27 00:41:40 -0400569 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700570}
571
572/*
573 * Arg:
574 * device : video output device (VGA)
575 *
576 * Return Value:
577 * None
578 *
579 * Find out all required AML method defined under the video bus device.
580 */
581
Len Brown4be44fc2005-08-05 00:44:28 -0400582static void acpi_video_bus_find_cap(struct acpi_video_bus *video)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700583{
Len Brown4be44fc2005-08-05 00:44:28 -0400584 acpi_handle h_dummy1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700585
Len Brown4be44fc2005-08-05 00:44:28 -0400586 memset(&video->cap, 0, 4);
Patrick Mochel90130262006-05-19 16:54:48 -0400587 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_DOS", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700588 video->cap._DOS = 1;
589 }
Patrick Mochel90130262006-05-19 16:54:48 -0400590 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_DOD", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700591 video->cap._DOD = 1;
592 }
Patrick Mochel90130262006-05-19 16:54:48 -0400593 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_ROM", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700594 video->cap._ROM = 1;
595 }
Patrick Mochel90130262006-05-19 16:54:48 -0400596 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_GPD", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700597 video->cap._GPD = 1;
598 }
Patrick Mochel90130262006-05-19 16:54:48 -0400599 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_SPD", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700600 video->cap._SPD = 1;
601 }
Patrick Mochel90130262006-05-19 16:54:48 -0400602 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_VPO", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700603 video->cap._VPO = 1;
604 }
605}
606
607/*
608 * Check whether the video bus device has required AML method to
609 * support the desired features
610 */
611
Len Brown4be44fc2005-08-05 00:44:28 -0400612static int acpi_video_bus_check(struct acpi_video_bus *video)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700613{
Len Brown4be44fc2005-08-05 00:44:28 -0400614 acpi_status status = -ENOENT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700615
Linus Torvalds1da177e2005-04-16 15:20:36 -0700616
617 if (!video)
Patrick Mocheld550d982006-06-27 00:41:40 -0400618 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700619
620 /* Since there is no HID, CID and so on for VGA driver, we have
621 * to check well known required nodes.
622 */
623
624 /* Does this device able to support video switching ? */
Len Brown4be44fc2005-08-05 00:44:28 -0400625 if (video->cap._DOS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700626 video->flags.multihead = 1;
627 status = 0;
628 }
629
630 /* Does this device able to retrieve a retrieve a video ROM ? */
Len Brown4be44fc2005-08-05 00:44:28 -0400631 if (video->cap._ROM) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700632 video->flags.rom = 1;
633 status = 0;
634 }
635
636 /* Does this device able to configure which video device to POST ? */
Len Brown4be44fc2005-08-05 00:44:28 -0400637 if (video->cap._GPD && video->cap._SPD && video->cap._VPO) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700638 video->flags.post = 1;
639 status = 0;
640 }
641
Patrick Mocheld550d982006-06-27 00:41:40 -0400642 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700643}
644
645/* --------------------------------------------------------------------------
646 FS Interface (/proc)
647 -------------------------------------------------------------------------- */
648
Len Brown4be44fc2005-08-05 00:44:28 -0400649static struct proc_dir_entry *acpi_video_dir;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700650
651/* video devices */
652
Len Brown4be44fc2005-08-05 00:44:28 -0400653static int acpi_video_device_info_seq_show(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700654{
Len Brown4be44fc2005-08-05 00:44:28 -0400655 struct acpi_video_device *dev =
656 (struct acpi_video_device *)seq->private;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700657
Linus Torvalds1da177e2005-04-16 15:20:36 -0700658
659 if (!dev)
660 goto end;
661
662 seq_printf(seq, "device_id: 0x%04x\n", (u32) dev->device_id);
663 seq_printf(seq, "type: ");
664 if (dev->flags.crt)
665 seq_printf(seq, "CRT\n");
666 else if (dev->flags.lcd)
667 seq_printf(seq, "LCD\n");
668 else if (dev->flags.tvout)
669 seq_printf(seq, "TVOUT\n");
670 else
671 seq_printf(seq, "UNKNOWN\n");
672
Len Brown4be44fc2005-08-05 00:44:28 -0400673 seq_printf(seq, "known by bios: %s\n", dev->flags.bios ? "yes" : "no");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700674
Len Brown4be44fc2005-08-05 00:44:28 -0400675 end:
Patrick Mocheld550d982006-06-27 00:41:40 -0400676 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700677}
678
679static int
Len Brown4be44fc2005-08-05 00:44:28 -0400680acpi_video_device_info_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700681{
682 return single_open(file, acpi_video_device_info_seq_show,
683 PDE(inode)->data);
684}
685
Len Brown4be44fc2005-08-05 00:44:28 -0400686static int acpi_video_device_state_seq_show(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700687{
Len Brown4be44fc2005-08-05 00:44:28 -0400688 int status;
689 struct acpi_video_device *dev =
690 (struct acpi_video_device *)seq->private;
691 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;
728 struct seq_file *m = (struct seq_file *)file->private_data;
729 struct acpi_video_device *dev = (struct acpi_video_device *)m->private;
730 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{
Len Brown4be44fc2005-08-05 00:44:28 -0400755 struct acpi_video_device *dev =
756 (struct acpi_video_device *)seq->private;
757 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700758
Linus Torvalds1da177e2005-04-16 15:20:36 -0700759
760 if (!dev || !dev->brightness) {
761 seq_printf(seq, "<not supported>\n");
Patrick Mocheld550d982006-06-27 00:41:40 -0400762 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700763 }
764
765 seq_printf(seq, "levels: ");
766 for (i = 0; i < dev->brightness->count; i++)
767 seq_printf(seq, " %d", dev->brightness->levels[i]);
768 seq_printf(seq, "\ncurrent: %d\n", dev->brightness->curr);
769
Patrick Mocheld550d982006-06-27 00:41:40 -0400770 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700771}
772
773static int
Len Brown4be44fc2005-08-05 00:44:28 -0400774acpi_video_device_brightness_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700775{
776 return single_open(file, acpi_video_device_brightness_seq_show,
777 PDE(inode)->data);
778}
779
780static ssize_t
Len Brown4be44fc2005-08-05 00:44:28 -0400781acpi_video_device_write_brightness(struct file *file,
782 const char __user * buffer,
783 size_t count, loff_t * data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700784{
Len Brown4be44fc2005-08-05 00:44:28 -0400785 struct seq_file *m = (struct seq_file *)file->private_data;
786 struct acpi_video_device *dev = (struct acpi_video_device *)m->private;
787 char str[4] = { 0 };
788 unsigned int level = 0;
789 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700790
Linus Torvalds1da177e2005-04-16 15:20:36 -0700791
Thomas Renninger59d399d2005-11-08 05:27:00 -0500792 if (!dev || !dev->brightness || count + 1 > sizeof str)
Patrick Mocheld550d982006-06-27 00:41:40 -0400793 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700794
795 if (copy_from_user(str, buffer, count))
Patrick Mocheld550d982006-06-27 00:41:40 -0400796 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700797
798 str[count] = 0;
799 level = simple_strtoul(str, NULL, 0);
Len Brown4be44fc2005-08-05 00:44:28 -0400800
Linus Torvalds1da177e2005-04-16 15:20:36 -0700801 if (level > 100)
Patrick Mocheld550d982006-06-27 00:41:40 -0400802 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700803
804 /* validate though the list of available levels */
805 for (i = 0; i < dev->brightness->count; i++)
806 if (level == dev->brightness->levels[i]) {
Len Brown4be44fc2005-08-05 00:44:28 -0400807 if (ACPI_SUCCESS
808 (acpi_video_device_lcd_set_level(dev, level)))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700809 dev->brightness->curr = level;
810 break;
811 }
812
Patrick Mocheld550d982006-06-27 00:41:40 -0400813 return count;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700814}
815
Len Brown4be44fc2005-08-05 00:44:28 -0400816static int acpi_video_device_EDID_seq_show(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700817{
Len Brown4be44fc2005-08-05 00:44:28 -0400818 struct acpi_video_device *dev =
819 (struct acpi_video_device *)seq->private;
820 int status;
821 int i;
822 union acpi_object *edid = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700823
Linus Torvalds1da177e2005-04-16 15:20:36 -0700824
825 if (!dev)
826 goto out;
827
Len Brown4be44fc2005-08-05 00:44:28 -0400828 status = acpi_video_device_EDID(dev, &edid, 128);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700829 if (ACPI_FAILURE(status)) {
Len Brown4be44fc2005-08-05 00:44:28 -0400830 status = acpi_video_device_EDID(dev, &edid, 256);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700831 }
832
833 if (ACPI_FAILURE(status)) {
834 goto out;
835 }
836
837 if (edid && edid->type == ACPI_TYPE_BUFFER) {
838 for (i = 0; i < edid->buffer.length; i++)
839 seq_putc(seq, edid->buffer.pointer[i]);
840 }
841
Len Brown4be44fc2005-08-05 00:44:28 -0400842 out:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700843 if (!edid)
844 seq_printf(seq, "<not supported>\n");
845 else
846 kfree(edid);
847
Patrick Mocheld550d982006-06-27 00:41:40 -0400848 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700849}
850
851static int
Len Brown4be44fc2005-08-05 00:44:28 -0400852acpi_video_device_EDID_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700853{
854 return single_open(file, acpi_video_device_EDID_seq_show,
855 PDE(inode)->data);
856}
857
Len Brown4be44fc2005-08-05 00:44:28 -0400858static int acpi_video_device_add_fs(struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700859{
Len Brown4be44fc2005-08-05 00:44:28 -0400860 struct proc_dir_entry *entry = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700861 struct acpi_video_device *vid_dev;
862
Linus Torvalds1da177e2005-04-16 15:20:36 -0700863
864 if (!device)
Patrick Mocheld550d982006-06-27 00:41:40 -0400865 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700866
Len Brown4be44fc2005-08-05 00:44:28 -0400867 vid_dev = (struct acpi_video_device *)acpi_driver_data(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700868 if (!vid_dev)
Patrick Mocheld550d982006-06-27 00:41:40 -0400869 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700870
871 if (!acpi_device_dir(device)) {
872 acpi_device_dir(device) = proc_mkdir(acpi_device_bid(device),
Len Brown4be44fc2005-08-05 00:44:28 -0400873 vid_dev->video->dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700874 if (!acpi_device_dir(device))
Patrick Mocheld550d982006-06-27 00:41:40 -0400875 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700876 acpi_device_dir(device)->owner = THIS_MODULE;
877 }
878
879 /* 'info' [R] */
880 entry = create_proc_entry("info", S_IRUGO, acpi_device_dir(device));
881 if (!entry)
Patrick Mocheld550d982006-06-27 00:41:40 -0400882 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700883 else {
884 entry->proc_fops = &acpi_video_device_info_fops;
885 entry->data = acpi_driver_data(device);
886 entry->owner = THIS_MODULE;
887 }
888
889 /* 'state' [R/W] */
Len Brown4be44fc2005-08-05 00:44:28 -0400890 entry =
891 create_proc_entry("state", S_IFREG | S_IRUGO | S_IWUSR,
892 acpi_device_dir(device));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700893 if (!entry)
Patrick Mocheld550d982006-06-27 00:41:40 -0400894 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700895 else {
Arjan van de Vend479e902006-01-06 16:47:00 -0500896 acpi_video_device_state_fops.write = acpi_video_device_write_state;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700897 entry->proc_fops = &acpi_video_device_state_fops;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700898 entry->data = acpi_driver_data(device);
899 entry->owner = THIS_MODULE;
900 }
901
902 /* 'brightness' [R/W] */
Len Brown4be44fc2005-08-05 00:44:28 -0400903 entry =
904 create_proc_entry("brightness", S_IFREG | S_IRUGO | S_IWUSR,
905 acpi_device_dir(device));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700906 if (!entry)
Patrick Mocheld550d982006-06-27 00:41:40 -0400907 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700908 else {
Arjan van de Vend479e902006-01-06 16:47:00 -0500909 acpi_video_device_brightness_fops.write = acpi_video_device_write_brightness;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700910 entry->proc_fops = &acpi_video_device_brightness_fops;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700911 entry->data = acpi_driver_data(device);
912 entry->owner = THIS_MODULE;
913 }
914
915 /* 'EDID' [R] */
916 entry = create_proc_entry("EDID", S_IRUGO, acpi_device_dir(device));
917 if (!entry)
Patrick Mocheld550d982006-06-27 00:41:40 -0400918 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700919 else {
920 entry->proc_fops = &acpi_video_device_EDID_fops;
921 entry->data = acpi_driver_data(device);
922 entry->owner = THIS_MODULE;
923 }
924
Patrick Mocheld550d982006-06-27 00:41:40 -0400925 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700926}
927
Len Brown4be44fc2005-08-05 00:44:28 -0400928static int acpi_video_device_remove_fs(struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700929{
930 struct acpi_video_device *vid_dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700931
Len Brown4be44fc2005-08-05 00:44:28 -0400932 vid_dev = (struct acpi_video_device *)acpi_driver_data(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700933 if (!vid_dev || !vid_dev->video || !vid_dev->video->dir)
Patrick Mocheld550d982006-06-27 00:41:40 -0400934 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700935
936 if (acpi_device_dir(device)) {
937 remove_proc_entry("info", acpi_device_dir(device));
938 remove_proc_entry("state", acpi_device_dir(device));
939 remove_proc_entry("brightness", acpi_device_dir(device));
940 remove_proc_entry("EDID", acpi_device_dir(device));
Len Brown4be44fc2005-08-05 00:44:28 -0400941 remove_proc_entry(acpi_device_bid(device), vid_dev->video->dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700942 acpi_device_dir(device) = NULL;
943 }
944
Patrick Mocheld550d982006-06-27 00:41:40 -0400945 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700946}
947
Linus Torvalds1da177e2005-04-16 15:20:36 -0700948/* video bus */
Len Brown4be44fc2005-08-05 00:44:28 -0400949static int acpi_video_bus_info_seq_show(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700950{
Len Brown4be44fc2005-08-05 00:44:28 -0400951 struct acpi_video_bus *video = (struct acpi_video_bus *)seq->private;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700952
Linus Torvalds1da177e2005-04-16 15:20:36 -0700953
954 if (!video)
955 goto end;
956
957 seq_printf(seq, "Switching heads: %s\n",
Len Brown4be44fc2005-08-05 00:44:28 -0400958 video->flags.multihead ? "yes" : "no");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700959 seq_printf(seq, "Video ROM: %s\n",
Len Brown4be44fc2005-08-05 00:44:28 -0400960 video->flags.rom ? "yes" : "no");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700961 seq_printf(seq, "Device to be POSTed on boot: %s\n",
Len Brown4be44fc2005-08-05 00:44:28 -0400962 video->flags.post ? "yes" : "no");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700963
Len Brown4be44fc2005-08-05 00:44:28 -0400964 end:
Patrick Mocheld550d982006-06-27 00:41:40 -0400965 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700966}
967
Len Brown4be44fc2005-08-05 00:44:28 -0400968static int acpi_video_bus_info_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700969{
Len Brown4be44fc2005-08-05 00:44:28 -0400970 return single_open(file, acpi_video_bus_info_seq_show,
971 PDE(inode)->data);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700972}
973
Len Brown4be44fc2005-08-05 00:44:28 -0400974static int acpi_video_bus_ROM_seq_show(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700975{
Len Brown4be44fc2005-08-05 00:44:28 -0400976 struct acpi_video_bus *video = (struct acpi_video_bus *)seq->private;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700977
Linus Torvalds1da177e2005-04-16 15:20:36 -0700978
979 if (!video)
980 goto end;
981
982 printk(KERN_INFO PREFIX "Please implement %s\n", __FUNCTION__);
983 seq_printf(seq, "<TODO>\n");
984
Len Brown4be44fc2005-08-05 00:44:28 -0400985 end:
Patrick Mocheld550d982006-06-27 00:41:40 -0400986 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700987}
988
Len Brown4be44fc2005-08-05 00:44:28 -0400989static int acpi_video_bus_ROM_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700990{
991 return single_open(file, acpi_video_bus_ROM_seq_show, PDE(inode)->data);
992}
993
Len Brown4be44fc2005-08-05 00:44:28 -0400994static int acpi_video_bus_POST_info_seq_show(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700995{
Len Brown4be44fc2005-08-05 00:44:28 -0400996 struct acpi_video_bus *video = (struct acpi_video_bus *)seq->private;
997 unsigned long options;
998 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700999
Linus Torvalds1da177e2005-04-16 15:20:36 -07001000
1001 if (!video)
1002 goto end;
1003
1004 status = acpi_video_bus_POST_options(video, &options);
1005 if (ACPI_SUCCESS(status)) {
1006 if (!(options & 1)) {
Len Brown4be44fc2005-08-05 00:44:28 -04001007 printk(KERN_WARNING PREFIX
1008 "The motherboard VGA device is not listed as a possible POST device.\n");
1009 printk(KERN_WARNING PREFIX
1010 "This indicate a BIOS bug. Please contact the manufacturer.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001011 }
1012 printk("%lx\n", options);
1013 seq_printf(seq, "can POST: <intgrated video>");
1014 if (options & 2)
1015 seq_printf(seq, " <PCI video>");
1016 if (options & 4)
1017 seq_printf(seq, " <AGP video>");
1018 seq_putc(seq, '\n');
1019 } else
1020 seq_printf(seq, "<not supported>\n");
Len Brown4be44fc2005-08-05 00:44:28 -04001021 end:
Patrick Mocheld550d982006-06-27 00:41:40 -04001022 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001023}
1024
1025static int
Len Brown4be44fc2005-08-05 00:44:28 -04001026acpi_video_bus_POST_info_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001027{
Len Brown4be44fc2005-08-05 00:44:28 -04001028 return single_open(file, acpi_video_bus_POST_info_seq_show,
1029 PDE(inode)->data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001030}
1031
Len Brown4be44fc2005-08-05 00:44:28 -04001032static int acpi_video_bus_POST_seq_show(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001033{
Len Brown4be44fc2005-08-05 00:44:28 -04001034 struct acpi_video_bus *video = (struct acpi_video_bus *)seq->private;
1035 int status;
1036 unsigned long id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001037
Linus Torvalds1da177e2005-04-16 15:20:36 -07001038
1039 if (!video)
1040 goto end;
1041
Len Brown4be44fc2005-08-05 00:44:28 -04001042 status = acpi_video_bus_get_POST(video, &id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001043 if (!ACPI_SUCCESS(status)) {
1044 seq_printf(seq, "<not supported>\n");
1045 goto end;
1046 }
Len Brown4be44fc2005-08-05 00:44:28 -04001047 seq_printf(seq, "device posted is <%s>\n", device_decode[id & 3]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001048
Len Brown4be44fc2005-08-05 00:44:28 -04001049 end:
Patrick Mocheld550d982006-06-27 00:41:40 -04001050 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001051}
1052
Len Brown4be44fc2005-08-05 00:44:28 -04001053static int acpi_video_bus_DOS_seq_show(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001054{
Len Brown4be44fc2005-08-05 00:44:28 -04001055 struct acpi_video_bus *video = (struct acpi_video_bus *)seq->private;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001056
Linus Torvalds1da177e2005-04-16 15:20:36 -07001057
Len Brown4be44fc2005-08-05 00:44:28 -04001058 seq_printf(seq, "DOS setting: <%d>\n", video->dos_setting);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001059
Patrick Mocheld550d982006-06-27 00:41:40 -04001060 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001061}
1062
Len Brown4be44fc2005-08-05 00:44:28 -04001063static int acpi_video_bus_POST_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001064{
Len Brown4be44fc2005-08-05 00:44:28 -04001065 return single_open(file, acpi_video_bus_POST_seq_show,
1066 PDE(inode)->data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001067}
1068
Len Brown4be44fc2005-08-05 00:44:28 -04001069static int acpi_video_bus_DOS_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001070{
1071 return single_open(file, acpi_video_bus_DOS_seq_show, PDE(inode)->data);
1072}
1073
1074static ssize_t
Len Brown4be44fc2005-08-05 00:44:28 -04001075acpi_video_bus_write_POST(struct file *file,
1076 const char __user * buffer,
1077 size_t count, loff_t * data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001078{
Len Brown4be44fc2005-08-05 00:44:28 -04001079 int status;
1080 struct seq_file *m = (struct seq_file *)file->private_data;
1081 struct acpi_video_bus *video = (struct acpi_video_bus *)m->private;
1082 char str[12] = { 0 };
1083 unsigned long opt, options;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001084
Linus Torvalds1da177e2005-04-16 15:20:36 -07001085
Linus Torvalds1da177e2005-04-16 15:20:36 -07001086 if (!video || count + 1 > sizeof str)
Patrick Mocheld550d982006-06-27 00:41:40 -04001087 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001088
1089 status = acpi_video_bus_POST_options(video, &options);
1090 if (!ACPI_SUCCESS(status))
Patrick Mocheld550d982006-06-27 00:41:40 -04001091 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001092
1093 if (copy_from_user(str, buffer, count))
Patrick Mocheld550d982006-06-27 00:41:40 -04001094 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001095
1096 str[count] = 0;
1097 opt = strtoul(str, NULL, 0);
1098 if (opt > 3)
Patrick Mocheld550d982006-06-27 00:41:40 -04001099 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001100
1101 /* just in case an OEM 'forget' the motherboard... */
1102 options |= 1;
1103
1104 if (options & (1ul << opt)) {
Len Brown4be44fc2005-08-05 00:44:28 -04001105 status = acpi_video_bus_set_POST(video, opt);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001106 if (!ACPI_SUCCESS(status))
Patrick Mocheld550d982006-06-27 00:41:40 -04001107 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001108
1109 }
1110
Patrick Mocheld550d982006-06-27 00:41:40 -04001111 return count;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001112}
1113
1114static ssize_t
Len Brown4be44fc2005-08-05 00:44:28 -04001115acpi_video_bus_write_DOS(struct file *file,
1116 const char __user * buffer,
1117 size_t count, loff_t * data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001118{
Len Brown4be44fc2005-08-05 00:44:28 -04001119 int status;
1120 struct seq_file *m = (struct seq_file *)file->private_data;
1121 struct acpi_video_bus *video = (struct acpi_video_bus *)m->private;
1122 char str[12] = { 0 };
1123 unsigned long opt;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001124
Linus Torvalds1da177e2005-04-16 15:20:36 -07001125
Linus Torvalds1da177e2005-04-16 15:20:36 -07001126 if (!video || count + 1 > sizeof str)
Patrick Mocheld550d982006-06-27 00:41:40 -04001127 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001128
1129 if (copy_from_user(str, buffer, count))
Patrick Mocheld550d982006-06-27 00:41:40 -04001130 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001131
1132 str[count] = 0;
1133 opt = strtoul(str, NULL, 0);
1134 if (opt > 7)
Patrick Mocheld550d982006-06-27 00:41:40 -04001135 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001136
Len Brown4be44fc2005-08-05 00:44:28 -04001137 status = acpi_video_bus_DOS(video, opt & 0x3, (opt & 0x4) >> 2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001138
1139 if (!ACPI_SUCCESS(status))
Patrick Mocheld550d982006-06-27 00:41:40 -04001140 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001141
Patrick Mocheld550d982006-06-27 00:41:40 -04001142 return count;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001143}
1144
Len Brown4be44fc2005-08-05 00:44:28 -04001145static int acpi_video_bus_add_fs(struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001146{
Len Brown4be44fc2005-08-05 00:44:28 -04001147 struct proc_dir_entry *entry = NULL;
1148 struct acpi_video_bus *video;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001149
Linus Torvalds1da177e2005-04-16 15:20:36 -07001150
Len Brown4be44fc2005-08-05 00:44:28 -04001151 video = (struct acpi_video_bus *)acpi_driver_data(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001152
1153 if (!acpi_device_dir(device)) {
1154 acpi_device_dir(device) = proc_mkdir(acpi_device_bid(device),
Len Brown4be44fc2005-08-05 00:44:28 -04001155 acpi_video_dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001156 if (!acpi_device_dir(device))
Patrick Mocheld550d982006-06-27 00:41:40 -04001157 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001158 video->dir = acpi_device_dir(device);
1159 acpi_device_dir(device)->owner = THIS_MODULE;
1160 }
1161
1162 /* 'info' [R] */
1163 entry = create_proc_entry("info", S_IRUGO, acpi_device_dir(device));
1164 if (!entry)
Patrick Mocheld550d982006-06-27 00:41:40 -04001165 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001166 else {
1167 entry->proc_fops = &acpi_video_bus_info_fops;
1168 entry->data = acpi_driver_data(device);
1169 entry->owner = THIS_MODULE;
1170 }
1171
1172 /* 'ROM' [R] */
1173 entry = create_proc_entry("ROM", S_IRUGO, acpi_device_dir(device));
1174 if (!entry)
Patrick Mocheld550d982006-06-27 00:41:40 -04001175 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001176 else {
1177 entry->proc_fops = &acpi_video_bus_ROM_fops;
1178 entry->data = acpi_driver_data(device);
1179 entry->owner = THIS_MODULE;
1180 }
1181
1182 /* 'POST_info' [R] */
Len Brown4be44fc2005-08-05 00:44:28 -04001183 entry =
1184 create_proc_entry("POST_info", S_IRUGO, acpi_device_dir(device));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001185 if (!entry)
Patrick Mocheld550d982006-06-27 00:41:40 -04001186 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001187 else {
1188 entry->proc_fops = &acpi_video_bus_POST_info_fops;
1189 entry->data = acpi_driver_data(device);
1190 entry->owner = THIS_MODULE;
1191 }
1192
1193 /* 'POST' [R/W] */
Len Brown4be44fc2005-08-05 00:44:28 -04001194 entry =
1195 create_proc_entry("POST", S_IFREG | S_IRUGO | S_IRUSR,
1196 acpi_device_dir(device));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001197 if (!entry)
Patrick Mocheld550d982006-06-27 00:41:40 -04001198 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001199 else {
Arjan van de Vend479e902006-01-06 16:47:00 -05001200 acpi_video_bus_POST_fops.write = acpi_video_bus_write_POST;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001201 entry->proc_fops = &acpi_video_bus_POST_fops;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001202 entry->data = acpi_driver_data(device);
1203 entry->owner = THIS_MODULE;
1204 }
1205
1206 /* 'DOS' [R/W] */
Len Brown4be44fc2005-08-05 00:44:28 -04001207 entry =
1208 create_proc_entry("DOS", S_IFREG | S_IRUGO | S_IRUSR,
1209 acpi_device_dir(device));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001210 if (!entry)
Patrick Mocheld550d982006-06-27 00:41:40 -04001211 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001212 else {
Arjan van de Vend479e902006-01-06 16:47:00 -05001213 acpi_video_bus_DOS_fops.write = acpi_video_bus_write_DOS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001214 entry->proc_fops = &acpi_video_bus_DOS_fops;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001215 entry->data = acpi_driver_data(device);
1216 entry->owner = THIS_MODULE;
1217 }
1218
Patrick Mocheld550d982006-06-27 00:41:40 -04001219 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001220}
1221
Len Brown4be44fc2005-08-05 00:44:28 -04001222static int acpi_video_bus_remove_fs(struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001223{
Len Brown4be44fc2005-08-05 00:44:28 -04001224 struct acpi_video_bus *video;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001225
Linus Torvalds1da177e2005-04-16 15:20:36 -07001226
Len Brown4be44fc2005-08-05 00:44:28 -04001227 video = (struct acpi_video_bus *)acpi_driver_data(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001228
1229 if (acpi_device_dir(device)) {
1230 remove_proc_entry("info", acpi_device_dir(device));
1231 remove_proc_entry("ROM", acpi_device_dir(device));
1232 remove_proc_entry("POST_info", acpi_device_dir(device));
1233 remove_proc_entry("POST", acpi_device_dir(device));
1234 remove_proc_entry("DOS", acpi_device_dir(device));
Len Brown4be44fc2005-08-05 00:44:28 -04001235 remove_proc_entry(acpi_device_bid(device), acpi_video_dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001236 acpi_device_dir(device) = NULL;
1237 }
1238
Patrick Mocheld550d982006-06-27 00:41:40 -04001239 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001240}
1241
1242/* --------------------------------------------------------------------------
1243 Driver Interface
1244 -------------------------------------------------------------------------- */
1245
1246/* device interface */
1247
1248static int
Len Brown4be44fc2005-08-05 00:44:28 -04001249acpi_video_bus_get_one_device(struct acpi_device *device,
1250 struct acpi_video_bus *video)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001251{
Len Brown4be44fc2005-08-05 00:44:28 -04001252 unsigned long device_id;
Yu, Luming973bf492006-04-27 05:25:00 -04001253 int status;
Len Brown4be44fc2005-08-05 00:44:28 -04001254 struct acpi_video_device *data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001255
Linus Torvalds1da177e2005-04-16 15:20:36 -07001256
1257 if (!device || !video)
Patrick Mocheld550d982006-06-27 00:41:40 -04001258 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001259
Len Brown4be44fc2005-08-05 00:44:28 -04001260 status =
1261 acpi_evaluate_integer(device->handle, "_ADR", NULL, &device_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001262 if (ACPI_SUCCESS(status)) {
1263
1264 data = kmalloc(sizeof(struct acpi_video_device), GFP_KERNEL);
1265 if (!data)
Patrick Mocheld550d982006-06-27 00:41:40 -04001266 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001267
1268 memset(data, 0, sizeof(struct acpi_video_device));
1269
Linus Torvalds1da177e2005-04-16 15:20:36 -07001270 strcpy(acpi_device_name(device), ACPI_VIDEO_DEVICE_NAME);
1271 strcpy(acpi_device_class(device), ACPI_VIDEO_CLASS);
1272 acpi_driver_data(device) = data;
1273
1274 data->device_id = device_id;
1275 data->video = video;
1276 data->dev = device;
1277
1278 switch (device_id & 0xffff) {
1279 case 0x0100:
1280 data->flags.crt = 1;
1281 break;
1282 case 0x0400:
1283 data->flags.lcd = 1;
1284 break;
1285 case 0x0200:
1286 data->flags.tvout = 1;
1287 break;
1288 default:
1289 data->flags.unknown = 1;
1290 break;
1291 }
Len Brown4be44fc2005-08-05 00:44:28 -04001292
Linus Torvalds1da177e2005-04-16 15:20:36 -07001293 acpi_video_device_bind(video, data);
1294 acpi_video_device_find_cap(data);
1295
Patrick Mochel90130262006-05-19 16:54:48 -04001296 status = acpi_install_notify_handler(device->handle,
Len Brown4be44fc2005-08-05 00:44:28 -04001297 ACPI_DEVICE_NOTIFY,
1298 acpi_video_device_notify,
1299 data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001300 if (ACPI_FAILURE(status)) {
1301 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
Len Brown4be44fc2005-08-05 00:44:28 -04001302 "Error installing notify handler\n"));
Yu, Luming973bf492006-04-27 05:25:00 -04001303 if(data->brightness)
1304 kfree(data->brightness->levels);
1305 kfree(data->brightness);
1306 kfree(data);
1307 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001308 }
1309
1310 down(&video->sem);
1311 list_add_tail(&data->entry, &video->video_device_list);
1312 up(&video->sem);
1313
1314 acpi_video_device_add_fs(device);
1315
Patrick Mocheld550d982006-06-27 00:41:40 -04001316 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001317 }
1318
Patrick Mocheld550d982006-06-27 00:41:40 -04001319 return -ENOENT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001320}
1321
1322/*
1323 * Arg:
1324 * video : video bus device
1325 *
1326 * Return:
1327 * none
1328 *
1329 * Enumerate the video device list of the video bus,
1330 * bind the ids with the corresponding video devices
1331 * under the video bus.
Len Brown4be44fc2005-08-05 00:44:28 -04001332 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001333
Len Brown4be44fc2005-08-05 00:44:28 -04001334static void acpi_video_device_rebind(struct acpi_video_bus *video)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001335{
Len Brown4be44fc2005-08-05 00:44:28 -04001336 struct list_head *node, *next;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001337 list_for_each_safe(node, next, &video->video_device_list) {
Len Brown4be44fc2005-08-05 00:44:28 -04001338 struct acpi_video_device *dev =
1339 container_of(node, struct acpi_video_device, entry);
1340 acpi_video_device_bind(video, dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001341 }
1342}
1343
1344/*
1345 * Arg:
1346 * video : video bus device
1347 * device : video output device under the video
1348 * bus
1349 *
1350 * Return:
1351 * none
1352 *
1353 * Bind the ids with the corresponding video devices
1354 * under the video bus.
Len Brown4be44fc2005-08-05 00:44:28 -04001355 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001356
1357static void
Len Brown4be44fc2005-08-05 00:44:28 -04001358acpi_video_device_bind(struct acpi_video_bus *video,
1359 struct acpi_video_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001360{
Len Brown4be44fc2005-08-05 00:44:28 -04001361 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001362
1363#define IDS_VAL(i) video->attached_array[i].value.int_val
1364#define IDS_BIND(i) video->attached_array[i].bind_info
Len Brown4be44fc2005-08-05 00:44:28 -04001365
1366 for (i = 0; IDS_VAL(i) != ACPI_VIDEO_HEAD_INVALID &&
1367 i < video->attached_count; i++) {
1368 if (device->device_id == (IDS_VAL(i) & 0xffff)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001369 IDS_BIND(i) = device;
1370 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "device_bind %d\n", i));
1371 }
1372 }
1373#undef IDS_VAL
1374#undef IDS_BIND
1375}
1376
1377/*
1378 * Arg:
1379 * video : video bus device
1380 *
1381 * Return:
1382 * < 0 : error
1383 *
1384 * Call _DOD to enumerate all devices attached to display adapter
1385 *
Len Brown4be44fc2005-08-05 00:44:28 -04001386 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001387
1388static int acpi_video_device_enumerate(struct acpi_video_bus *video)
1389{
Len Brown4be44fc2005-08-05 00:44:28 -04001390 int status;
1391 int count;
1392 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001393 struct acpi_video_enumerated_device *active_device_list;
Len Brown4be44fc2005-08-05 00:44:28 -04001394 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
1395 union acpi_object *dod = NULL;
1396 union acpi_object *obj;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001397
Patrick Mochel90130262006-05-19 16:54:48 -04001398 status = acpi_evaluate_object(video->device->handle, "_DOD", NULL, &buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001399 if (!ACPI_SUCCESS(status)) {
Thomas Renningera6fc6722006-06-26 23:58:43 -04001400 ACPI_EXCEPTION((AE_INFO, status, "Evaluating _DOD"));
Patrick Mocheld550d982006-06-27 00:41:40 -04001401 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001402 }
1403
Len Brown4be44fc2005-08-05 00:44:28 -04001404 dod = (union acpi_object *)buffer.pointer;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001405 if (!dod || (dod->type != ACPI_TYPE_PACKAGE)) {
Thomas Renningera6fc6722006-06-26 23:58:43 -04001406 ACPI_EXCEPTION((AE_INFO, status, "Invalid _DOD data"));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001407 status = -EFAULT;
1408 goto out;
1409 }
1410
1411 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found %d video heads in _DOD\n",
Len Brown4be44fc2005-08-05 00:44:28 -04001412 dod->package.count));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001413
Len Brown4be44fc2005-08-05 00:44:28 -04001414 active_device_list = kmalloc((1 +
1415 dod->package.count) *
1416 sizeof(struct
1417 acpi_video_enumerated_device),
1418 GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001419
1420 if (!active_device_list) {
1421 status = -ENOMEM;
1422 goto out;
1423 }
1424
1425 count = 0;
1426 for (i = 0; i < dod->package.count; i++) {
Len Brown4be44fc2005-08-05 00:44:28 -04001427 obj = (union acpi_object *)&dod->package.elements[i];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001428
1429 if (obj->type != ACPI_TYPE_INTEGER) {
Len Brown64684632006-06-26 23:41:38 -04001430 printk(KERN_ERR PREFIX "Invalid _DOD data\n");
Len Brown4be44fc2005-08-05 00:44:28 -04001431 active_device_list[i].value.int_val =
1432 ACPI_VIDEO_HEAD_INVALID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001433 }
1434 active_device_list[i].value.int_val = obj->integer.value;
1435 active_device_list[i].bind_info = NULL;
Len Brown4be44fc2005-08-05 00:44:28 -04001436 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "dod element[%d] = %d\n", i,
1437 (int)obj->integer.value));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001438 count++;
1439 }
1440 active_device_list[count].value.int_val = ACPI_VIDEO_HEAD_END;
1441
Jesper Juhl6044ec82005-11-07 01:01:32 -08001442 kfree(video->attached_array);
Len Brown4be44fc2005-08-05 00:44:28 -04001443
Linus Torvalds1da177e2005-04-16 15:20:36 -07001444 video->attached_array = active_device_list;
1445 video->attached_count = count;
Len Brown4be44fc2005-08-05 00:44:28 -04001446 out:
Len Brown02438d82006-06-30 03:19:10 -04001447 kfree(buffer.pointer);
Patrick Mocheld550d982006-06-27 00:41:40 -04001448 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001449}
1450
1451/*
1452 * Arg:
1453 * video : video bus device
1454 * event : Nontify Event
1455 *
1456 * Return:
1457 * < 0 : error
1458 *
1459 * 1. Find out the current active output device.
1460 * 2. Identify the next output device to switch
1461 * 3. call _DSS to do actual switch.
Len Brown4be44fc2005-08-05 00:44:28 -04001462 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001463
Len Brown4be44fc2005-08-05 00:44:28 -04001464static int acpi_video_switch_output(struct acpi_video_bus *video, int event)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001465{
Len Brown4be44fc2005-08-05 00:44:28 -04001466 struct list_head *node, *next;
1467 struct acpi_video_device *dev = NULL;
1468 struct acpi_video_device *dev_next = NULL;
1469 struct acpi_video_device *dev_prev = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001470 unsigned long state;
1471 int status = 0;
1472
Linus Torvalds1da177e2005-04-16 15:20:36 -07001473
1474 list_for_each_safe(node, next, &video->video_device_list) {
Adrian Bunk73345712005-03-30 22:31:35 -05001475 dev = container_of(node, struct acpi_video_device, entry);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001476 status = acpi_video_device_get_state(dev, &state);
Len Brown4be44fc2005-08-05 00:44:28 -04001477 if (state & 0x2) {
1478 dev_next =
1479 container_of(node->next, struct acpi_video_device,
1480 entry);
1481 dev_prev =
1482 container_of(node->prev, struct acpi_video_device,
1483 entry);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001484 goto out;
1485 }
1486 }
1487 dev_next = container_of(node->next, struct acpi_video_device, entry);
1488 dev_prev = container_of(node->prev, struct acpi_video_device, entry);
Len Brown4be44fc2005-08-05 00:44:28 -04001489 out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001490 switch (event) {
1491 case ACPI_VIDEO_NOTIFY_CYCLE:
1492 case ACPI_VIDEO_NOTIFY_NEXT_OUTPUT:
1493 acpi_video_device_set_state(dev, 0);
1494 acpi_video_device_set_state(dev_next, 0x80000001);
1495 break;
1496 case ACPI_VIDEO_NOTIFY_PREV_OUTPUT:
1497 acpi_video_device_set_state(dev, 0);
1498 acpi_video_device_set_state(dev_prev, 0x80000001);
1499 default:
1500 break;
1501 }
1502
Patrick Mocheld550d982006-06-27 00:41:40 -04001503 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001504}
1505
Len Brown4be44fc2005-08-05 00:44:28 -04001506static int
1507acpi_video_get_next_level(struct acpi_video_device *device,
1508 u32 level_current, u32 event)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001509{
Len Brown4be44fc2005-08-05 00:44:28 -04001510 /*Fix me */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001511 return level_current;
1512}
1513
Linus Torvalds1da177e2005-04-16 15:20:36 -07001514static void
Len Brown4be44fc2005-08-05 00:44:28 -04001515acpi_video_switch_brightness(struct acpi_video_device *device, int event)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001516{
1517 unsigned long level_current, level_next;
1518 acpi_video_device_lcd_get_level_current(device, &level_current);
1519 level_next = acpi_video_get_next_level(device, level_current, event);
1520 acpi_video_device_lcd_set_level(device, level_next);
1521}
1522
1523static int
Len Brown4be44fc2005-08-05 00:44:28 -04001524acpi_video_bus_get_devices(struct acpi_video_bus *video,
1525 struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001526{
Len Brown4be44fc2005-08-05 00:44:28 -04001527 int status = 0;
1528 struct list_head *node, *next;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001529
Linus Torvalds1da177e2005-04-16 15:20:36 -07001530
1531 acpi_video_device_enumerate(video);
1532
1533 list_for_each_safe(node, next, &device->children) {
Len Brown4be44fc2005-08-05 00:44:28 -04001534 struct acpi_device *dev =
1535 list_entry(node, struct acpi_device, node);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001536
1537 if (!dev)
1538 continue;
1539
1540 status = acpi_video_bus_get_one_device(dev, video);
1541 if (ACPI_FAILURE(status)) {
Thomas Renningera6fc6722006-06-26 23:58:43 -04001542 ACPI_EXCEPTION((AE_INFO, status, "Cant attach device"));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001543 continue;
1544 }
1545
1546 }
Patrick Mocheld550d982006-06-27 00:41:40 -04001547 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001548}
1549
Len Brown4be44fc2005-08-05 00:44:28 -04001550static int acpi_video_bus_put_one_device(struct acpi_video_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001551{
Karol Kozimor031ec772005-07-30 04:18:00 -04001552 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001553 struct acpi_video_bus *video;
1554
Linus Torvalds1da177e2005-04-16 15:20:36 -07001555
1556 if (!device || !device->video)
Patrick Mocheld550d982006-06-27 00:41:40 -04001557 return -ENOENT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001558
1559 video = device->video;
1560
1561 down(&video->sem);
1562 list_del(&device->entry);
1563 up(&video->sem);
1564 acpi_video_device_remove_fs(device->dev);
1565
Patrick Mochel90130262006-05-19 16:54:48 -04001566 status = acpi_remove_notify_handler(device->dev->handle,
Len Brown4be44fc2005-08-05 00:44:28 -04001567 ACPI_DEVICE_NOTIFY,
1568 acpi_video_device_notify);
Karol Kozimor031ec772005-07-30 04:18:00 -04001569
Patrick Mocheld550d982006-06-27 00:41:40 -04001570 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001571}
1572
Len Brown4be44fc2005-08-05 00:44:28 -04001573static int acpi_video_bus_put_devices(struct acpi_video_bus *video)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001574{
Len Brown4be44fc2005-08-05 00:44:28 -04001575 int status;
1576 struct list_head *node, *next;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001577
Linus Torvalds1da177e2005-04-16 15:20:36 -07001578
1579 list_for_each_safe(node, next, &video->video_device_list) {
Len Brown4be44fc2005-08-05 00:44:28 -04001580 struct acpi_video_device *data =
1581 list_entry(node, struct acpi_video_device, entry);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001582 if (!data)
1583 continue;
1584
1585 status = acpi_video_bus_put_one_device(data);
Len Brown4be44fc2005-08-05 00:44:28 -04001586 if (ACPI_FAILURE(status))
1587 printk(KERN_WARNING PREFIX
1588 "hhuuhhuu bug in acpi video driver.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001589
Dave Jonesd384ea62006-06-24 00:33:08 -04001590 if (data->brightness)
Yu, Luming973bf492006-04-27 05:25:00 -04001591 kfree(data->brightness->levels);
Jesper Juhl6044ec82005-11-07 01:01:32 -08001592 kfree(data->brightness);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001593 kfree(data);
1594 }
1595
Patrick Mocheld550d982006-06-27 00:41:40 -04001596 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001597}
1598
1599/* acpi_video interface */
1600
Len Brown4be44fc2005-08-05 00:44:28 -04001601static int acpi_video_bus_start_devices(struct acpi_video_bus *video)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001602{
1603 return acpi_video_bus_DOS(video, 1, 0);
1604}
1605
Len Brown4be44fc2005-08-05 00:44:28 -04001606static int acpi_video_bus_stop_devices(struct acpi_video_bus *video)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001607{
1608 return acpi_video_bus_DOS(video, 0, 1);
1609}
1610
Len Brown4be44fc2005-08-05 00:44:28 -04001611static void acpi_video_bus_notify(acpi_handle handle, u32 event, void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001612{
Len Brown4be44fc2005-08-05 00:44:28 -04001613 struct acpi_video_bus *video = (struct acpi_video_bus *)data;
1614 struct acpi_device *device = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001615
Linus Torvalds1da177e2005-04-16 15:20:36 -07001616 printk("video bus notify\n");
1617
1618 if (!video)
Patrick Mocheld550d982006-06-27 00:41:40 -04001619 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001620
Patrick Mochele6afa0d2006-05-19 16:54:40 -04001621 device = video->device;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001622
1623 switch (event) {
1624 case ACPI_VIDEO_NOTIFY_SWITCH: /* User request that a switch occur,
1625 * most likely via hotkey. */
1626 acpi_bus_generate_event(device, event, 0);
1627 break;
1628
1629 case ACPI_VIDEO_NOTIFY_PROBE: /* User plug or remove a video
1630 * connector. */
1631 acpi_video_device_enumerate(video);
1632 acpi_video_device_rebind(video);
1633 acpi_video_switch_output(video, event);
1634 acpi_bus_generate_event(device, event, 0);
1635 break;
1636
Len Brown4be44fc2005-08-05 00:44:28 -04001637 case ACPI_VIDEO_NOTIFY_CYCLE: /* Cycle Display output hotkey pressed. */
1638 case ACPI_VIDEO_NOTIFY_NEXT_OUTPUT: /* Next Display output hotkey pressed. */
1639 case ACPI_VIDEO_NOTIFY_PREV_OUTPUT: /* previous Display output hotkey pressed. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001640 acpi_video_switch_output(video, event);
1641 acpi_bus_generate_event(device, event, 0);
1642 break;
1643
1644 default:
1645 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
Len Brown4be44fc2005-08-05 00:44:28 -04001646 "Unsupported event [0x%x]\n", event));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001647 break;
1648 }
1649
Patrick Mocheld550d982006-06-27 00:41:40 -04001650 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001651}
1652
Len Brown4be44fc2005-08-05 00:44:28 -04001653static void acpi_video_device_notify(acpi_handle handle, u32 event, void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001654{
Len Brown4be44fc2005-08-05 00:44:28 -04001655 struct acpi_video_device *video_device =
1656 (struct acpi_video_device *)data;
1657 struct acpi_device *device = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001658
Linus Torvalds1da177e2005-04-16 15:20:36 -07001659
1660 printk("video device notify\n");
1661 if (!video_device)
Patrick Mocheld550d982006-06-27 00:41:40 -04001662 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001663
Patrick Mochele6afa0d2006-05-19 16:54:40 -04001664 device = video_device->dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001665
1666 switch (event) {
Len Brown4be44fc2005-08-05 00:44:28 -04001667 case ACPI_VIDEO_NOTIFY_SWITCH: /* change in status (cycle output device) */
1668 case ACPI_VIDEO_NOTIFY_PROBE: /* change in status (output device status) */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001669 acpi_bus_generate_event(device, event, 0);
1670 break;
Len Brown4be44fc2005-08-05 00:44:28 -04001671 case ACPI_VIDEO_NOTIFY_CYCLE_BRIGHTNESS: /* Cycle brightness */
1672 case ACPI_VIDEO_NOTIFY_INC_BRIGHTNESS: /* Increase brightness */
1673 case ACPI_VIDEO_NOTIFY_DEC_BRIGHTNESS: /* Decrease brightness */
1674 case ACPI_VIDEO_NOTIFY_ZERO_BRIGHTNESS: /* zero brightnesss */
1675 case ACPI_VIDEO_NOTIFY_DISPLAY_OFF: /* display device off */
1676 acpi_video_switch_brightness(video_device, event);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001677 acpi_bus_generate_event(device, event, 0);
1678 break;
1679 default:
1680 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
Len Brown4be44fc2005-08-05 00:44:28 -04001681 "Unsupported event [0x%x]\n", event));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001682 break;
1683 }
Patrick Mocheld550d982006-06-27 00:41:40 -04001684 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001685}
1686
Len Brown4be44fc2005-08-05 00:44:28 -04001687static int acpi_video_bus_add(struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001688{
Len Brown4be44fc2005-08-05 00:44:28 -04001689 int result = 0;
1690 acpi_status status = 0;
1691 struct acpi_video_bus *video = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001692
Len Brown4be44fc2005-08-05 00:44:28 -04001693
Linus Torvalds1da177e2005-04-16 15:20:36 -07001694 if (!device)
Patrick Mocheld550d982006-06-27 00:41:40 -04001695 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001696
1697 video = kmalloc(sizeof(struct acpi_video_bus), GFP_KERNEL);
1698 if (!video)
Patrick Mocheld550d982006-06-27 00:41:40 -04001699 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001700 memset(video, 0, sizeof(struct acpi_video_bus));
1701
Patrick Mochele6afa0d2006-05-19 16:54:40 -04001702 video->device = device;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001703 strcpy(acpi_device_name(device), ACPI_VIDEO_BUS_NAME);
1704 strcpy(acpi_device_class(device), ACPI_VIDEO_CLASS);
1705 acpi_driver_data(device) = video;
1706
1707 acpi_video_bus_find_cap(video);
1708 result = acpi_video_bus_check(video);
1709 if (result)
1710 goto end;
1711
1712 result = acpi_video_bus_add_fs(device);
1713 if (result)
1714 goto end;
1715
1716 init_MUTEX(&video->sem);
1717 INIT_LIST_HEAD(&video->video_device_list);
1718
1719 acpi_video_bus_get_devices(video, device);
1720 acpi_video_bus_start_devices(video);
1721
Patrick Mochel90130262006-05-19 16:54:48 -04001722 status = acpi_install_notify_handler(device->handle,
Len Brown4be44fc2005-08-05 00:44:28 -04001723 ACPI_DEVICE_NOTIFY,
1724 acpi_video_bus_notify, video);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001725 if (ACPI_FAILURE(status)) {
1726 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
Len Brown4be44fc2005-08-05 00:44:28 -04001727 "Error installing notify handler\n"));
Yu, Luming973bf492006-04-27 05:25:00 -04001728 acpi_video_bus_stop_devices(video);
1729 acpi_video_bus_put_devices(video);
1730 kfree(video->attached_array);
1731 acpi_video_bus_remove_fs(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001732 result = -ENODEV;
1733 goto end;
1734 }
1735
1736 printk(KERN_INFO PREFIX "%s [%s] (multi-head: %s rom: %s post: %s)\n",
Len Brown4be44fc2005-08-05 00:44:28 -04001737 ACPI_VIDEO_DEVICE_NAME, acpi_device_bid(device),
1738 video->flags.multihead ? "yes" : "no",
1739 video->flags.rom ? "yes" : "no",
1740 video->flags.post ? "yes" : "no");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001741
Len Brown4be44fc2005-08-05 00:44:28 -04001742 end:
Yu, Luming973bf492006-04-27 05:25:00 -04001743 if (result)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001744 kfree(video);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001745
Patrick Mocheld550d982006-06-27 00:41:40 -04001746 return result;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001747}
1748
Len Brown4be44fc2005-08-05 00:44:28 -04001749static int acpi_video_bus_remove(struct acpi_device *device, int type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001750{
Len Brown4be44fc2005-08-05 00:44:28 -04001751 acpi_status status = 0;
1752 struct acpi_video_bus *video = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001753
Linus Torvalds1da177e2005-04-16 15:20:36 -07001754
1755 if (!device || !acpi_driver_data(device))
Patrick Mocheld550d982006-06-27 00:41:40 -04001756 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001757
Len Brown4be44fc2005-08-05 00:44:28 -04001758 video = (struct acpi_video_bus *)acpi_driver_data(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001759
1760 acpi_video_bus_stop_devices(video);
1761
Patrick Mochel90130262006-05-19 16:54:48 -04001762 status = acpi_remove_notify_handler(video->device->handle,
Len Brown4be44fc2005-08-05 00:44:28 -04001763 ACPI_DEVICE_NOTIFY,
1764 acpi_video_bus_notify);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001765
1766 acpi_video_bus_put_devices(video);
1767 acpi_video_bus_remove_fs(device);
1768
Jesper Juhl6044ec82005-11-07 01:01:32 -08001769 kfree(video->attached_array);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001770 kfree(video);
1771
Patrick Mocheld550d982006-06-27 00:41:40 -04001772 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001773}
1774
Len Brown4be44fc2005-08-05 00:44:28 -04001775static int __init acpi_video_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001776{
Len Brown4be44fc2005-08-05 00:44:28 -04001777 int result = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001778
Linus Torvalds1da177e2005-04-16 15:20:36 -07001779
1780 /*
Len Brown4be44fc2005-08-05 00:44:28 -04001781 acpi_dbg_level = 0xFFFFFFFF;
1782 acpi_dbg_layer = 0x08000000;
1783 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001784
1785 acpi_video_dir = proc_mkdir(ACPI_VIDEO_CLASS, acpi_root_dir);
1786 if (!acpi_video_dir)
Patrick Mocheld550d982006-06-27 00:41:40 -04001787 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001788 acpi_video_dir->owner = THIS_MODULE;
1789
1790 result = acpi_bus_register_driver(&acpi_video_bus);
1791 if (result < 0) {
1792 remove_proc_entry(ACPI_VIDEO_CLASS, acpi_root_dir);
Patrick Mocheld550d982006-06-27 00:41:40 -04001793 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001794 }
1795
Patrick Mocheld550d982006-06-27 00:41:40 -04001796 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001797}
1798
Len Brown4be44fc2005-08-05 00:44:28 -04001799static void __exit acpi_video_exit(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001800{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001801
1802 acpi_bus_unregister_driver(&acpi_video_bus);
1803
1804 remove_proc_entry(ACPI_VIDEO_CLASS, acpi_root_dir);
1805
Patrick Mocheld550d982006-06-27 00:41:40 -04001806 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001807}
1808
1809module_init(acpi_video_init);
1810module_exit(acpi_video_exit);