blob: 862cefaff60229e939d2f37050bc3767d82e9420 [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 {
Len Brown4be44fc2005-08-05 00:44:28 -0400120 acpi_handle handle;
Patrick Mochele6afa0d2006-05-19 16:54:40 -0400121 struct acpi_device *device;
Len Brown4be44fc2005-08-05 00:44:28 -0400122 u8 dos_setting;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123 struct acpi_video_enumerated_device *attached_array;
Len Brown4be44fc2005-08-05 00:44:28 -0400124 u8 attached_count;
125 struct acpi_video_bus_cap cap;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126 struct acpi_video_bus_flags flags;
Len Brown4be44fc2005-08-05 00:44:28 -0400127 struct semaphore sem;
128 struct list_head video_device_list;
129 struct proc_dir_entry *dir;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130};
131
132struct acpi_video_device_flags {
Len Brown4be44fc2005-08-05 00:44:28 -0400133 u8 crt:1;
134 u8 lcd:1;
135 u8 tvout:1;
136 u8 bios:1;
137 u8 unknown:1;
138 u8 reserved:3;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139};
140
141struct acpi_video_device_cap {
Len Brown4be44fc2005-08-05 00:44:28 -0400142 u8 _ADR:1; /*Return the unique ID */
143 u8 _BCL:1; /*Query list of brightness control levels supported */
144 u8 _BCM:1; /*Set the brightness level */
145 u8 _DDC:1; /*Return the EDID for this device */
146 u8 _DCS:1; /*Return status of output device */
147 u8 _DGS:1; /*Query graphics state */
148 u8 _DSS:1; /*Device state set */
149 u8 _reserved:1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700150};
151
152struct acpi_video_device_brightness {
Len Brown4be44fc2005-08-05 00:44:28 -0400153 int curr;
154 int count;
155 int *levels;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156};
157
158struct acpi_video_device {
Len Brown4be44fc2005-08-05 00:44:28 -0400159 acpi_handle handle;
160 unsigned long device_id;
161 struct acpi_video_device_flags flags;
162 struct acpi_video_device_cap cap;
163 struct list_head entry;
164 struct acpi_video_bus *video;
165 struct acpi_device *dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700166 struct acpi_video_device_brightness *brightness;
167};
168
Linus Torvalds1da177e2005-04-16 15:20:36 -0700169/* bus */
170static int acpi_video_bus_info_open_fs(struct inode *inode, struct file *file);
171static struct file_operations acpi_video_bus_info_fops = {
Len Brown4be44fc2005-08-05 00:44:28 -0400172 .open = acpi_video_bus_info_open_fs,
173 .read = seq_read,
174 .llseek = seq_lseek,
175 .release = single_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700176};
177
178static int acpi_video_bus_ROM_open_fs(struct inode *inode, struct file *file);
179static struct file_operations acpi_video_bus_ROM_fops = {
Len Brown4be44fc2005-08-05 00:44:28 -0400180 .open = acpi_video_bus_ROM_open_fs,
181 .read = seq_read,
182 .llseek = seq_lseek,
183 .release = single_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700184};
185
Len Brown4be44fc2005-08-05 00:44:28 -0400186static int acpi_video_bus_POST_info_open_fs(struct inode *inode,
187 struct file *file);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700188static struct file_operations acpi_video_bus_POST_info_fops = {
Len Brown4be44fc2005-08-05 00:44:28 -0400189 .open = acpi_video_bus_POST_info_open_fs,
190 .read = seq_read,
191 .llseek = seq_lseek,
192 .release = single_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700193};
194
195static int acpi_video_bus_POST_open_fs(struct inode *inode, struct file *file);
196static struct file_operations acpi_video_bus_POST_fops = {
Len Brown4be44fc2005-08-05 00:44:28 -0400197 .open = acpi_video_bus_POST_open_fs,
198 .read = seq_read,
199 .llseek = seq_lseek,
200 .release = single_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700201};
202
Linus Torvalds1da177e2005-04-16 15:20:36 -0700203static int acpi_video_bus_DOS_open_fs(struct inode *inode, struct file *file);
204static struct file_operations acpi_video_bus_DOS_fops = {
Len Brown4be44fc2005-08-05 00:44:28 -0400205 .open = acpi_video_bus_DOS_open_fs,
206 .read = seq_read,
207 .llseek = seq_lseek,
208 .release = single_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700209};
210
211/* device */
Len Brown4be44fc2005-08-05 00:44:28 -0400212static int acpi_video_device_info_open_fs(struct inode *inode,
213 struct file *file);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700214static struct file_operations acpi_video_device_info_fops = {
Len Brown4be44fc2005-08-05 00:44:28 -0400215 .open = acpi_video_device_info_open_fs,
216 .read = seq_read,
217 .llseek = seq_lseek,
218 .release = single_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700219};
220
Len Brown4be44fc2005-08-05 00:44:28 -0400221static int acpi_video_device_state_open_fs(struct inode *inode,
222 struct file *file);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700223static struct file_operations acpi_video_device_state_fops = {
Len Brown4be44fc2005-08-05 00:44:28 -0400224 .open = acpi_video_device_state_open_fs,
225 .read = seq_read,
226 .llseek = seq_lseek,
227 .release = single_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700228};
229
Len Brown4be44fc2005-08-05 00:44:28 -0400230static int acpi_video_device_brightness_open_fs(struct inode *inode,
231 struct file *file);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700232static struct file_operations acpi_video_device_brightness_fops = {
Len Brown4be44fc2005-08-05 00:44:28 -0400233 .open = acpi_video_device_brightness_open_fs,
234 .read = seq_read,
235 .llseek = seq_lseek,
236 .release = single_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700237};
238
Len Brown4be44fc2005-08-05 00:44:28 -0400239static int acpi_video_device_EDID_open_fs(struct inode *inode,
240 struct file *file);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700241static struct file_operations acpi_video_device_EDID_fops = {
Len Brown4be44fc2005-08-05 00:44:28 -0400242 .open = acpi_video_device_EDID_open_fs,
243 .read = seq_read,
244 .llseek = seq_lseek,
245 .release = single_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700246};
247
Len Brown4be44fc2005-08-05 00:44:28 -0400248static char device_decode[][30] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700249 "motherboard VGA device",
250 "PCI VGA device",
251 "AGP VGA device",
252 "UNKNOWN",
253};
254
Len Brown4be44fc2005-08-05 00:44:28 -0400255static void acpi_video_device_notify(acpi_handle handle, u32 event, void *data);
256static void acpi_video_device_rebind(struct acpi_video_bus *video);
257static void acpi_video_device_bind(struct acpi_video_bus *video,
258 struct acpi_video_device *device);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700259static int acpi_video_device_enumerate(struct acpi_video_bus *video);
Len Brown4be44fc2005-08-05 00:44:28 -0400260static int acpi_video_switch_output(struct acpi_video_bus *video, int event);
261static int acpi_video_get_next_level(struct acpi_video_device *device,
262 u32 level_current, u32 event);
263static void acpi_video_switch_brightness(struct acpi_video_device *device,
264 int event);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700265
266/* --------------------------------------------------------------------------
267 Video Management
268 -------------------------------------------------------------------------- */
269
270/* device */
271
272static int
Len Brown4be44fc2005-08-05 00:44:28 -0400273acpi_video_device_query(struct acpi_video_device *device, unsigned long *state)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700274{
Len Brown4be44fc2005-08-05 00:44:28 -0400275 int status;
Patrick Mochel90130262006-05-19 16:54:48 -0400276
277 status = acpi_evaluate_integer(device->dev->handle, "_DGS", NULL, state);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700278
Patrick Mocheld550d982006-06-27 00:41:40 -0400279 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700280}
281
282static int
Len Brown4be44fc2005-08-05 00:44:28 -0400283acpi_video_device_get_state(struct acpi_video_device *device,
284 unsigned long *state)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700285{
Len Brown4be44fc2005-08-05 00:44:28 -0400286 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700287
Patrick Mochel90130262006-05-19 16:54:48 -0400288 status = acpi_evaluate_integer(device->dev->handle, "_DCS", NULL, state);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700289
Patrick Mocheld550d982006-06-27 00:41:40 -0400290 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700291}
292
293static int
Len Brown4be44fc2005-08-05 00:44:28 -0400294acpi_video_device_set_state(struct acpi_video_device *device, int state)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700295{
Len Brown4be44fc2005-08-05 00:44:28 -0400296 int status;
297 union acpi_object arg0 = { ACPI_TYPE_INTEGER };
298 struct acpi_object_list args = { 1, &arg0 };
Luming Yu824b5582005-08-21 19:17:00 -0400299 unsigned long ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700300
Linus Torvalds1da177e2005-04-16 15:20:36 -0700301
302 arg0.integer.value = state;
Patrick Mochel90130262006-05-19 16:54:48 -0400303 status = acpi_evaluate_integer(device->dev->handle, "_DSS", &args, &ret);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700304
Patrick Mocheld550d982006-06-27 00:41:40 -0400305 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700306}
307
308static int
Len Brown4be44fc2005-08-05 00:44:28 -0400309acpi_video_device_lcd_query_levels(struct acpi_video_device *device,
310 union acpi_object **levels)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700311{
Len Brown4be44fc2005-08-05 00:44:28 -0400312 int status;
313 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
314 union acpi_object *obj;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700315
Linus Torvalds1da177e2005-04-16 15:20:36 -0700316
317 *levels = NULL;
318
Patrick Mochel90130262006-05-19 16:54:48 -0400319 status = acpi_evaluate_object(device->dev->handle, "_BCL", NULL, &buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700320 if (!ACPI_SUCCESS(status))
Patrick Mocheld550d982006-06-27 00:41:40 -0400321 return status;
Len Brown4be44fc2005-08-05 00:44:28 -0400322 obj = (union acpi_object *)buffer.pointer;
Adrian Bunk6665bda2006-03-11 10:12:00 -0500323 if (!obj || (obj->type != ACPI_TYPE_PACKAGE)) {
Len Brown64684632006-06-26 23:41:38 -0400324 printk(KERN_ERR PREFIX "Invalid _BCL data\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700325 status = -EFAULT;
326 goto err;
327 }
328
329 *levels = obj;
330
Patrick Mocheld550d982006-06-27 00:41:40 -0400331 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700332
Len Brown4be44fc2005-08-05 00:44:28 -0400333 err:
Jesper Juhl6044ec82005-11-07 01:01:32 -0800334 kfree(buffer.pointer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700335
Patrick Mocheld550d982006-06-27 00:41:40 -0400336 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700337}
338
339static int
Len Brown4be44fc2005-08-05 00:44:28 -0400340acpi_video_device_lcd_set_level(struct acpi_video_device *device, int level)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700341{
Len Brown4be44fc2005-08-05 00:44:28 -0400342 int status;
343 union acpi_object arg0 = { ACPI_TYPE_INTEGER };
344 struct acpi_object_list args = { 1, &arg0 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700345
Linus Torvalds1da177e2005-04-16 15:20:36 -0700346
347 arg0.integer.value = level;
Patrick Mochel90130262006-05-19 16:54:48 -0400348 status = acpi_evaluate_object(device->dev->handle, "_BCM", &args, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700349
350 printk(KERN_DEBUG "set_level status: %x\n", status);
Patrick Mocheld550d982006-06-27 00:41:40 -0400351 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700352}
353
354static int
Len Brown4be44fc2005-08-05 00:44:28 -0400355acpi_video_device_lcd_get_level_current(struct acpi_video_device *device,
356 unsigned long *level)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700357{
Len Brown4be44fc2005-08-05 00:44:28 -0400358 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700359
Patrick Mochel90130262006-05-19 16:54:48 -0400360 status = acpi_evaluate_integer(device->dev->handle, "_BQC", NULL, level);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700361
Patrick Mocheld550d982006-06-27 00:41:40 -0400362 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700363}
364
365static int
Len Brown4be44fc2005-08-05 00:44:28 -0400366acpi_video_device_EDID(struct acpi_video_device *device,
367 union acpi_object **edid, ssize_t length)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700368{
Len Brown4be44fc2005-08-05 00:44:28 -0400369 int status;
370 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
371 union acpi_object *obj;
372 union acpi_object arg0 = { ACPI_TYPE_INTEGER };
373 struct acpi_object_list args = { 1, &arg0 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700374
Linus Torvalds1da177e2005-04-16 15:20:36 -0700375
376 *edid = NULL;
377
378 if (!device)
Patrick Mocheld550d982006-06-27 00:41:40 -0400379 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700380 if (length == 128)
381 arg0.integer.value = 1;
382 else if (length == 256)
383 arg0.integer.value = 2;
384 else
Patrick Mocheld550d982006-06-27 00:41:40 -0400385 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700386
Patrick Mochel90130262006-05-19 16:54:48 -0400387 status = acpi_evaluate_object(device->dev->handle, "_DDC", &args, &buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700388 if (ACPI_FAILURE(status))
Patrick Mocheld550d982006-06-27 00:41:40 -0400389 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700390
Len Brown4be44fc2005-08-05 00:44:28 -0400391 obj = (union acpi_object *)buffer.pointer;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700392
393 if (obj && obj->type == ACPI_TYPE_BUFFER)
394 *edid = obj;
395 else {
Len Brown64684632006-06-26 23:41:38 -0400396 printk(KERN_ERR PREFIX "Invalid _DDC data\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700397 status = -EFAULT;
398 kfree(obj);
399 }
400
Patrick Mocheld550d982006-06-27 00:41:40 -0400401 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700402}
403
Linus Torvalds1da177e2005-04-16 15:20:36 -0700404/* bus */
405
406static int
Len Brown4be44fc2005-08-05 00:44:28 -0400407acpi_video_bus_set_POST(struct acpi_video_bus *video, unsigned long option)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700408{
Len Brown4be44fc2005-08-05 00:44:28 -0400409 int status;
410 unsigned long tmp;
411 union acpi_object arg0 = { ACPI_TYPE_INTEGER };
412 struct acpi_object_list args = { 1, &arg0 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700413
Linus Torvalds1da177e2005-04-16 15:20:36 -0700414
415 arg0.integer.value = option;
416
Patrick Mochel90130262006-05-19 16:54:48 -0400417 status = acpi_evaluate_integer(video->device->handle, "_SPD", &args, &tmp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700418 if (ACPI_SUCCESS(status))
Len Brown4be44fc2005-08-05 00:44:28 -0400419 status = tmp ? (-EINVAL) : (AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700420
Patrick Mocheld550d982006-06-27 00:41:40 -0400421 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700422}
423
424static int
Len Brown4be44fc2005-08-05 00:44:28 -0400425acpi_video_bus_get_POST(struct acpi_video_bus *video, unsigned long *id)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700426{
427 int status;
428
Patrick Mochel90130262006-05-19 16:54:48 -0400429 status = acpi_evaluate_integer(video->device->handle, "_GPD", NULL, id);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700430
Patrick Mocheld550d982006-06-27 00:41:40 -0400431 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700432}
433
434static int
Len Brown4be44fc2005-08-05 00:44:28 -0400435acpi_video_bus_POST_options(struct acpi_video_bus *video,
436 unsigned long *options)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700437{
Len Brown4be44fc2005-08-05 00:44:28 -0400438 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700439
Patrick Mochel90130262006-05-19 16:54:48 -0400440 status = acpi_evaluate_integer(video->device->handle, "_VPO", NULL, options);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700441 *options &= 3;
442
Patrick Mocheld550d982006-06-27 00:41:40 -0400443 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700444}
445
446/*
447 * Arg:
448 * video : video bus device pointer
449 * bios_flag :
450 * 0. The system BIOS should NOT automatically switch(toggle)
451 * the active display output.
452 * 1. The system BIOS should automatically switch (toggle) the
453 * active display output. No swich event.
454 * 2. The _DGS value should be locked.
455 * 3. The system BIOS should not automatically switch (toggle) the
456 * active display output, but instead generate the display switch
457 * event notify code.
458 * lcd_flag :
459 * 0. The system BIOS should automatically control the brightness level
460 * of the LCD, when the power changes from AC to DC
461 * 1. The system BIOS should NOT automatically control the brightness
462 * level of the LCD, when the power changes from AC to DC.
463 * Return Value:
464 * -1 wrong arg.
465 */
466
467static int
Len Brown4be44fc2005-08-05 00:44:28 -0400468acpi_video_bus_DOS(struct acpi_video_bus *video, int bios_flag, int lcd_flag)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700469{
Len Brown4be44fc2005-08-05 00:44:28 -0400470 acpi_integer status = 0;
471 union acpi_object arg0 = { ACPI_TYPE_INTEGER };
472 struct acpi_object_list args = { 1, &arg0 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700473
Linus Torvalds1da177e2005-04-16 15:20:36 -0700474
Len Brown4be44fc2005-08-05 00:44:28 -0400475 if (bios_flag < 0 || bios_flag > 3 || lcd_flag < 0 || lcd_flag > 1) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700476 status = -1;
477 goto Failed;
478 }
479 arg0.integer.value = (lcd_flag << 2) | bios_flag;
480 video->dos_setting = arg0.integer.value;
Patrick Mochel90130262006-05-19 16:54:48 -0400481 acpi_evaluate_object(video->device->handle, "_DOS", &args, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700482
Len Brown4be44fc2005-08-05 00:44:28 -0400483 Failed:
Patrick Mocheld550d982006-06-27 00:41:40 -0400484 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700485}
486
487/*
488 * Arg:
489 * device : video output device (LCD, CRT, ..)
490 *
491 * Return Value:
492 * None
493 *
494 * Find out all required AML method defined under the output
495 * device.
496 */
497
Len Brown4be44fc2005-08-05 00:44:28 -0400498static void acpi_video_device_find_cap(struct acpi_video_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700499{
Len Brown4be44fc2005-08-05 00:44:28 -0400500 acpi_integer status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700501 acpi_handle h_dummy1;
502 int i;
503 union acpi_object *obj = NULL;
504 struct acpi_video_device_brightness *br = NULL;
505
Linus Torvalds1da177e2005-04-16 15:20:36 -0700506
Len Brown4be44fc2005-08-05 00:44:28 -0400507 memset(&device->cap, 0, 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700508
Patrick Mochel90130262006-05-19 16:54:48 -0400509 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_ADR", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700510 device->cap._ADR = 1;
511 }
Patrick Mochel90130262006-05-19 16:54:48 -0400512 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_BCL", &h_dummy1))) {
Len Brown4be44fc2005-08-05 00:44:28 -0400513 device->cap._BCL = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700514 }
Patrick Mochel90130262006-05-19 16:54:48 -0400515 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_BCM", &h_dummy1))) {
Len Brown4be44fc2005-08-05 00:44:28 -0400516 device->cap._BCM = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700517 }
Patrick Mochel90130262006-05-19 16:54:48 -0400518 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_DDC", &h_dummy1))) {
Len Brown4be44fc2005-08-05 00:44:28 -0400519 device->cap._DDC = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700520 }
Patrick Mochel90130262006-05-19 16:54:48 -0400521 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_DCS", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700522 device->cap._DCS = 1;
523 }
Patrick Mochel90130262006-05-19 16:54:48 -0400524 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_DGS", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700525 device->cap._DGS = 1;
526 }
Patrick Mochel90130262006-05-19 16:54:48 -0400527 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_DSS", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700528 device->cap._DSS = 1;
529 }
530
531 status = acpi_video_device_lcd_query_levels(device, &obj);
532
533 if (obj && obj->type == ACPI_TYPE_PACKAGE && obj->package.count >= 2) {
534 int count = 0;
535 union acpi_object *o;
Len Brown4be44fc2005-08-05 00:44:28 -0400536
Paulo Marquesd1dd0c22005-03-30 22:39:49 -0500537 br = kmalloc(sizeof(*br), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700538 if (!br) {
539 printk(KERN_ERR "can't allocate memory\n");
540 } else {
Paulo Marquesd1dd0c22005-03-30 22:39:49 -0500541 memset(br, 0, sizeof(*br));
542 br->levels = kmalloc(obj->package.count *
Len Brown4be44fc2005-08-05 00:44:28 -0400543 sizeof *(br->levels), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700544 if (!br->levels)
545 goto out;
546
547 for (i = 0; i < obj->package.count; i++) {
Len Brown4be44fc2005-08-05 00:44:28 -0400548 o = (union acpi_object *)&obj->package.
549 elements[i];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700550 if (o->type != ACPI_TYPE_INTEGER) {
Len Brown64684632006-06-26 23:41:38 -0400551 printk(KERN_ERR PREFIX "Invalid data\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700552 continue;
553 }
554 br->levels[count] = (u32) o->integer.value;
555 count++;
556 }
Len Brown4be44fc2005-08-05 00:44:28 -0400557 out:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700558 if (count < 2) {
Paulo Marquesd1dd0c22005-03-30 22:39:49 -0500559 kfree(br->levels);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700560 kfree(br);
561 } else {
562 br->count = count;
563 device->brightness = br;
Len Brown4be44fc2005-08-05 00:44:28 -0400564 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
565 "found %d brightness levels\n",
566 count));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700567 }
568 }
569 }
570
Paulo Marquesd1dd0c22005-03-30 22:39:49 -0500571 kfree(obj);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700572
Patrick Mocheld550d982006-06-27 00:41:40 -0400573 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700574}
575
576/*
577 * Arg:
578 * device : video output device (VGA)
579 *
580 * Return Value:
581 * None
582 *
583 * Find out all required AML method defined under the video bus device.
584 */
585
Len Brown4be44fc2005-08-05 00:44:28 -0400586static void acpi_video_bus_find_cap(struct acpi_video_bus *video)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700587{
Len Brown4be44fc2005-08-05 00:44:28 -0400588 acpi_handle h_dummy1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700589
Len Brown4be44fc2005-08-05 00:44:28 -0400590 memset(&video->cap, 0, 4);
Patrick Mochel90130262006-05-19 16:54:48 -0400591 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_DOS", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700592 video->cap._DOS = 1;
593 }
Patrick Mochel90130262006-05-19 16:54:48 -0400594 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_DOD", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700595 video->cap._DOD = 1;
596 }
Patrick Mochel90130262006-05-19 16:54:48 -0400597 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_ROM", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700598 video->cap._ROM = 1;
599 }
Patrick Mochel90130262006-05-19 16:54:48 -0400600 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_GPD", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700601 video->cap._GPD = 1;
602 }
Patrick Mochel90130262006-05-19 16:54:48 -0400603 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_SPD", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700604 video->cap._SPD = 1;
605 }
Patrick Mochel90130262006-05-19 16:54:48 -0400606 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_VPO", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700607 video->cap._VPO = 1;
608 }
609}
610
611/*
612 * Check whether the video bus device has required AML method to
613 * support the desired features
614 */
615
Len Brown4be44fc2005-08-05 00:44:28 -0400616static int acpi_video_bus_check(struct acpi_video_bus *video)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700617{
Len Brown4be44fc2005-08-05 00:44:28 -0400618 acpi_status status = -ENOENT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700619
Linus Torvalds1da177e2005-04-16 15:20:36 -0700620
621 if (!video)
Patrick Mocheld550d982006-06-27 00:41:40 -0400622 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700623
624 /* Since there is no HID, CID and so on for VGA driver, we have
625 * to check well known required nodes.
626 */
627
628 /* Does this device able to support video switching ? */
Len Brown4be44fc2005-08-05 00:44:28 -0400629 if (video->cap._DOS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700630 video->flags.multihead = 1;
631 status = 0;
632 }
633
634 /* Does this device able to retrieve a retrieve a video ROM ? */
Len Brown4be44fc2005-08-05 00:44:28 -0400635 if (video->cap._ROM) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700636 video->flags.rom = 1;
637 status = 0;
638 }
639
640 /* Does this device able to configure which video device to POST ? */
Len Brown4be44fc2005-08-05 00:44:28 -0400641 if (video->cap._GPD && video->cap._SPD && video->cap._VPO) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700642 video->flags.post = 1;
643 status = 0;
644 }
645
Patrick Mocheld550d982006-06-27 00:41:40 -0400646 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700647}
648
649/* --------------------------------------------------------------------------
650 FS Interface (/proc)
651 -------------------------------------------------------------------------- */
652
Len Brown4be44fc2005-08-05 00:44:28 -0400653static struct proc_dir_entry *acpi_video_dir;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700654
655/* video devices */
656
Len Brown4be44fc2005-08-05 00:44:28 -0400657static int acpi_video_device_info_seq_show(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700658{
Len Brown4be44fc2005-08-05 00:44:28 -0400659 struct acpi_video_device *dev =
660 (struct acpi_video_device *)seq->private;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700661
Linus Torvalds1da177e2005-04-16 15:20:36 -0700662
663 if (!dev)
664 goto end;
665
666 seq_printf(seq, "device_id: 0x%04x\n", (u32) dev->device_id);
667 seq_printf(seq, "type: ");
668 if (dev->flags.crt)
669 seq_printf(seq, "CRT\n");
670 else if (dev->flags.lcd)
671 seq_printf(seq, "LCD\n");
672 else if (dev->flags.tvout)
673 seq_printf(seq, "TVOUT\n");
674 else
675 seq_printf(seq, "UNKNOWN\n");
676
Len Brown4be44fc2005-08-05 00:44:28 -0400677 seq_printf(seq, "known by bios: %s\n", dev->flags.bios ? "yes" : "no");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700678
Len Brown4be44fc2005-08-05 00:44:28 -0400679 end:
Patrick Mocheld550d982006-06-27 00:41:40 -0400680 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700681}
682
683static int
Len Brown4be44fc2005-08-05 00:44:28 -0400684acpi_video_device_info_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700685{
686 return single_open(file, acpi_video_device_info_seq_show,
687 PDE(inode)->data);
688}
689
Len Brown4be44fc2005-08-05 00:44:28 -0400690static int acpi_video_device_state_seq_show(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700691{
Len Brown4be44fc2005-08-05 00:44:28 -0400692 int status;
693 struct acpi_video_device *dev =
694 (struct acpi_video_device *)seq->private;
695 unsigned long state;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700696
Linus Torvalds1da177e2005-04-16 15:20:36 -0700697
698 if (!dev)
699 goto end;
700
701 status = acpi_video_device_get_state(dev, &state);
702 seq_printf(seq, "state: ");
703 if (ACPI_SUCCESS(status))
704 seq_printf(seq, "0x%02lx\n", state);
705 else
706 seq_printf(seq, "<not supported>\n");
707
708 status = acpi_video_device_query(dev, &state);
709 seq_printf(seq, "query: ");
710 if (ACPI_SUCCESS(status))
711 seq_printf(seq, "0x%02lx\n", state);
712 else
713 seq_printf(seq, "<not supported>\n");
714
Len Brown4be44fc2005-08-05 00:44:28 -0400715 end:
Patrick Mocheld550d982006-06-27 00:41:40 -0400716 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700717}
718
719static int
Len Brown4be44fc2005-08-05 00:44:28 -0400720acpi_video_device_state_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700721{
722 return single_open(file, acpi_video_device_state_seq_show,
723 PDE(inode)->data);
724}
725
726static ssize_t
Len Brown4be44fc2005-08-05 00:44:28 -0400727acpi_video_device_write_state(struct file *file,
728 const char __user * buffer,
729 size_t count, loff_t * data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700730{
Len Brown4be44fc2005-08-05 00:44:28 -0400731 int status;
732 struct seq_file *m = (struct seq_file *)file->private_data;
733 struct acpi_video_device *dev = (struct acpi_video_device *)m->private;
734 char str[12] = { 0 };
735 u32 state = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700736
Linus Torvalds1da177e2005-04-16 15:20:36 -0700737
738 if (!dev || count + 1 > sizeof str)
Patrick Mocheld550d982006-06-27 00:41:40 -0400739 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700740
741 if (copy_from_user(str, buffer, count))
Patrick Mocheld550d982006-06-27 00:41:40 -0400742 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700743
744 str[count] = 0;
745 state = simple_strtoul(str, NULL, 0);
Len Brown4be44fc2005-08-05 00:44:28 -0400746 state &= ((1ul << 31) | (1ul << 30) | (1ul << 0));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700747
748 status = acpi_video_device_set_state(dev, state);
749
750 if (status)
Patrick Mocheld550d982006-06-27 00:41:40 -0400751 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700752
Patrick Mocheld550d982006-06-27 00:41:40 -0400753 return count;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700754}
755
756static int
Len Brown4be44fc2005-08-05 00:44:28 -0400757acpi_video_device_brightness_seq_show(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700758{
Len Brown4be44fc2005-08-05 00:44:28 -0400759 struct acpi_video_device *dev =
760 (struct acpi_video_device *)seq->private;
761 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700762
Linus Torvalds1da177e2005-04-16 15:20:36 -0700763
764 if (!dev || !dev->brightness) {
765 seq_printf(seq, "<not supported>\n");
Patrick Mocheld550d982006-06-27 00:41:40 -0400766 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700767 }
768
769 seq_printf(seq, "levels: ");
770 for (i = 0; i < dev->brightness->count; i++)
771 seq_printf(seq, " %d", dev->brightness->levels[i]);
772 seq_printf(seq, "\ncurrent: %d\n", dev->brightness->curr);
773
Patrick Mocheld550d982006-06-27 00:41:40 -0400774 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700775}
776
777static int
Len Brown4be44fc2005-08-05 00:44:28 -0400778acpi_video_device_brightness_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700779{
780 return single_open(file, acpi_video_device_brightness_seq_show,
781 PDE(inode)->data);
782}
783
784static ssize_t
Len Brown4be44fc2005-08-05 00:44:28 -0400785acpi_video_device_write_brightness(struct file *file,
786 const char __user * buffer,
787 size_t count, loff_t * data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700788{
Len Brown4be44fc2005-08-05 00:44:28 -0400789 struct seq_file *m = (struct seq_file *)file->private_data;
790 struct acpi_video_device *dev = (struct acpi_video_device *)m->private;
791 char str[4] = { 0 };
792 unsigned int level = 0;
793 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700794
Linus Torvalds1da177e2005-04-16 15:20:36 -0700795
Thomas Renninger59d399d2005-11-08 05:27:00 -0500796 if (!dev || !dev->brightness || count + 1 > sizeof str)
Patrick Mocheld550d982006-06-27 00:41:40 -0400797 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700798
799 if (copy_from_user(str, buffer, count))
Patrick Mocheld550d982006-06-27 00:41:40 -0400800 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700801
802 str[count] = 0;
803 level = simple_strtoul(str, NULL, 0);
Len Brown4be44fc2005-08-05 00:44:28 -0400804
Linus Torvalds1da177e2005-04-16 15:20:36 -0700805 if (level > 100)
Patrick Mocheld550d982006-06-27 00:41:40 -0400806 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700807
808 /* validate though the list of available levels */
809 for (i = 0; i < dev->brightness->count; i++)
810 if (level == dev->brightness->levels[i]) {
Len Brown4be44fc2005-08-05 00:44:28 -0400811 if (ACPI_SUCCESS
812 (acpi_video_device_lcd_set_level(dev, level)))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700813 dev->brightness->curr = level;
814 break;
815 }
816
Patrick Mocheld550d982006-06-27 00:41:40 -0400817 return count;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700818}
819
Len Brown4be44fc2005-08-05 00:44:28 -0400820static int acpi_video_device_EDID_seq_show(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700821{
Len Brown4be44fc2005-08-05 00:44:28 -0400822 struct acpi_video_device *dev =
823 (struct acpi_video_device *)seq->private;
824 int status;
825 int i;
826 union acpi_object *edid = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700827
Linus Torvalds1da177e2005-04-16 15:20:36 -0700828
829 if (!dev)
830 goto out;
831
Len Brown4be44fc2005-08-05 00:44:28 -0400832 status = acpi_video_device_EDID(dev, &edid, 128);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700833 if (ACPI_FAILURE(status)) {
Len Brown4be44fc2005-08-05 00:44:28 -0400834 status = acpi_video_device_EDID(dev, &edid, 256);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700835 }
836
837 if (ACPI_FAILURE(status)) {
838 goto out;
839 }
840
841 if (edid && edid->type == ACPI_TYPE_BUFFER) {
842 for (i = 0; i < edid->buffer.length; i++)
843 seq_putc(seq, edid->buffer.pointer[i]);
844 }
845
Len Brown4be44fc2005-08-05 00:44:28 -0400846 out:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700847 if (!edid)
848 seq_printf(seq, "<not supported>\n");
849 else
850 kfree(edid);
851
Patrick Mocheld550d982006-06-27 00:41:40 -0400852 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700853}
854
855static int
Len Brown4be44fc2005-08-05 00:44:28 -0400856acpi_video_device_EDID_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700857{
858 return single_open(file, acpi_video_device_EDID_seq_show,
859 PDE(inode)->data);
860}
861
Len Brown4be44fc2005-08-05 00:44:28 -0400862static int acpi_video_device_add_fs(struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700863{
Len Brown4be44fc2005-08-05 00:44:28 -0400864 struct proc_dir_entry *entry = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700865 struct acpi_video_device *vid_dev;
866
Linus Torvalds1da177e2005-04-16 15:20:36 -0700867
868 if (!device)
Patrick Mocheld550d982006-06-27 00:41:40 -0400869 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700870
Len Brown4be44fc2005-08-05 00:44:28 -0400871 vid_dev = (struct acpi_video_device *)acpi_driver_data(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700872 if (!vid_dev)
Patrick Mocheld550d982006-06-27 00:41:40 -0400873 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700874
875 if (!acpi_device_dir(device)) {
876 acpi_device_dir(device) = proc_mkdir(acpi_device_bid(device),
Len Brown4be44fc2005-08-05 00:44:28 -0400877 vid_dev->video->dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700878 if (!acpi_device_dir(device))
Patrick Mocheld550d982006-06-27 00:41:40 -0400879 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700880 acpi_device_dir(device)->owner = THIS_MODULE;
881 }
882
883 /* 'info' [R] */
884 entry = create_proc_entry("info", S_IRUGO, acpi_device_dir(device));
885 if (!entry)
Patrick Mocheld550d982006-06-27 00:41:40 -0400886 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700887 else {
888 entry->proc_fops = &acpi_video_device_info_fops;
889 entry->data = acpi_driver_data(device);
890 entry->owner = THIS_MODULE;
891 }
892
893 /* 'state' [R/W] */
Len Brown4be44fc2005-08-05 00:44:28 -0400894 entry =
895 create_proc_entry("state", S_IFREG | S_IRUGO | S_IWUSR,
896 acpi_device_dir(device));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700897 if (!entry)
Patrick Mocheld550d982006-06-27 00:41:40 -0400898 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700899 else {
Arjan van de Vend479e902006-01-06 16:47:00 -0500900 acpi_video_device_state_fops.write = acpi_video_device_write_state;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700901 entry->proc_fops = &acpi_video_device_state_fops;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700902 entry->data = acpi_driver_data(device);
903 entry->owner = THIS_MODULE;
904 }
905
906 /* 'brightness' [R/W] */
Len Brown4be44fc2005-08-05 00:44:28 -0400907 entry =
908 create_proc_entry("brightness", S_IFREG | S_IRUGO | S_IWUSR,
909 acpi_device_dir(device));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700910 if (!entry)
Patrick Mocheld550d982006-06-27 00:41:40 -0400911 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700912 else {
Arjan van de Vend479e902006-01-06 16:47:00 -0500913 acpi_video_device_brightness_fops.write = acpi_video_device_write_brightness;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700914 entry->proc_fops = &acpi_video_device_brightness_fops;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700915 entry->data = acpi_driver_data(device);
916 entry->owner = THIS_MODULE;
917 }
918
919 /* 'EDID' [R] */
920 entry = create_proc_entry("EDID", S_IRUGO, acpi_device_dir(device));
921 if (!entry)
Patrick Mocheld550d982006-06-27 00:41:40 -0400922 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700923 else {
924 entry->proc_fops = &acpi_video_device_EDID_fops;
925 entry->data = acpi_driver_data(device);
926 entry->owner = THIS_MODULE;
927 }
928
Patrick Mocheld550d982006-06-27 00:41:40 -0400929 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700930}
931
Len Brown4be44fc2005-08-05 00:44:28 -0400932static int acpi_video_device_remove_fs(struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700933{
934 struct acpi_video_device *vid_dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700935
Len Brown4be44fc2005-08-05 00:44:28 -0400936 vid_dev = (struct acpi_video_device *)acpi_driver_data(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700937 if (!vid_dev || !vid_dev->video || !vid_dev->video->dir)
Patrick Mocheld550d982006-06-27 00:41:40 -0400938 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700939
940 if (acpi_device_dir(device)) {
941 remove_proc_entry("info", acpi_device_dir(device));
942 remove_proc_entry("state", acpi_device_dir(device));
943 remove_proc_entry("brightness", acpi_device_dir(device));
944 remove_proc_entry("EDID", acpi_device_dir(device));
Len Brown4be44fc2005-08-05 00:44:28 -0400945 remove_proc_entry(acpi_device_bid(device), vid_dev->video->dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700946 acpi_device_dir(device) = NULL;
947 }
948
Patrick Mocheld550d982006-06-27 00:41:40 -0400949 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700950}
951
Linus Torvalds1da177e2005-04-16 15:20:36 -0700952/* video bus */
Len Brown4be44fc2005-08-05 00:44:28 -0400953static int acpi_video_bus_info_seq_show(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700954{
Len Brown4be44fc2005-08-05 00:44:28 -0400955 struct acpi_video_bus *video = (struct acpi_video_bus *)seq->private;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700956
Linus Torvalds1da177e2005-04-16 15:20:36 -0700957
958 if (!video)
959 goto end;
960
961 seq_printf(seq, "Switching heads: %s\n",
Len Brown4be44fc2005-08-05 00:44:28 -0400962 video->flags.multihead ? "yes" : "no");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700963 seq_printf(seq, "Video ROM: %s\n",
Len Brown4be44fc2005-08-05 00:44:28 -0400964 video->flags.rom ? "yes" : "no");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700965 seq_printf(seq, "Device to be POSTed on boot: %s\n",
Len Brown4be44fc2005-08-05 00:44:28 -0400966 video->flags.post ? "yes" : "no");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700967
Len Brown4be44fc2005-08-05 00:44:28 -0400968 end:
Patrick Mocheld550d982006-06-27 00:41:40 -0400969 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700970}
971
Len Brown4be44fc2005-08-05 00:44:28 -0400972static int acpi_video_bus_info_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700973{
Len Brown4be44fc2005-08-05 00:44:28 -0400974 return single_open(file, acpi_video_bus_info_seq_show,
975 PDE(inode)->data);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700976}
977
Len Brown4be44fc2005-08-05 00:44:28 -0400978static int acpi_video_bus_ROM_seq_show(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700979{
Len Brown4be44fc2005-08-05 00:44:28 -0400980 struct acpi_video_bus *video = (struct acpi_video_bus *)seq->private;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700981
Linus Torvalds1da177e2005-04-16 15:20:36 -0700982
983 if (!video)
984 goto end;
985
986 printk(KERN_INFO PREFIX "Please implement %s\n", __FUNCTION__);
987 seq_printf(seq, "<TODO>\n");
988
Len Brown4be44fc2005-08-05 00:44:28 -0400989 end:
Patrick Mocheld550d982006-06-27 00:41:40 -0400990 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700991}
992
Len Brown4be44fc2005-08-05 00:44:28 -0400993static int acpi_video_bus_ROM_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700994{
995 return single_open(file, acpi_video_bus_ROM_seq_show, PDE(inode)->data);
996}
997
Len Brown4be44fc2005-08-05 00:44:28 -0400998static int acpi_video_bus_POST_info_seq_show(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700999{
Len Brown4be44fc2005-08-05 00:44:28 -04001000 struct acpi_video_bus *video = (struct acpi_video_bus *)seq->private;
1001 unsigned long options;
1002 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001003
Linus Torvalds1da177e2005-04-16 15:20:36 -07001004
1005 if (!video)
1006 goto end;
1007
1008 status = acpi_video_bus_POST_options(video, &options);
1009 if (ACPI_SUCCESS(status)) {
1010 if (!(options & 1)) {
Len Brown4be44fc2005-08-05 00:44:28 -04001011 printk(KERN_WARNING PREFIX
1012 "The motherboard VGA device is not listed as a possible POST device.\n");
1013 printk(KERN_WARNING PREFIX
1014 "This indicate a BIOS bug. Please contact the manufacturer.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001015 }
1016 printk("%lx\n", options);
1017 seq_printf(seq, "can POST: <intgrated video>");
1018 if (options & 2)
1019 seq_printf(seq, " <PCI video>");
1020 if (options & 4)
1021 seq_printf(seq, " <AGP video>");
1022 seq_putc(seq, '\n');
1023 } else
1024 seq_printf(seq, "<not supported>\n");
Len Brown4be44fc2005-08-05 00:44:28 -04001025 end:
Patrick Mocheld550d982006-06-27 00:41:40 -04001026 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001027}
1028
1029static int
Len Brown4be44fc2005-08-05 00:44:28 -04001030acpi_video_bus_POST_info_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001031{
Len Brown4be44fc2005-08-05 00:44:28 -04001032 return single_open(file, acpi_video_bus_POST_info_seq_show,
1033 PDE(inode)->data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001034}
1035
Len Brown4be44fc2005-08-05 00:44:28 -04001036static int acpi_video_bus_POST_seq_show(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001037{
Len Brown4be44fc2005-08-05 00:44:28 -04001038 struct acpi_video_bus *video = (struct acpi_video_bus *)seq->private;
1039 int status;
1040 unsigned long id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001041
Linus Torvalds1da177e2005-04-16 15:20:36 -07001042
1043 if (!video)
1044 goto end;
1045
Len Brown4be44fc2005-08-05 00:44:28 -04001046 status = acpi_video_bus_get_POST(video, &id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001047 if (!ACPI_SUCCESS(status)) {
1048 seq_printf(seq, "<not supported>\n");
1049 goto end;
1050 }
Len Brown4be44fc2005-08-05 00:44:28 -04001051 seq_printf(seq, "device posted is <%s>\n", device_decode[id & 3]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001052
Len Brown4be44fc2005-08-05 00:44:28 -04001053 end:
Patrick Mocheld550d982006-06-27 00:41:40 -04001054 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001055}
1056
Len Brown4be44fc2005-08-05 00:44:28 -04001057static int acpi_video_bus_DOS_seq_show(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001058{
Len Brown4be44fc2005-08-05 00:44:28 -04001059 struct acpi_video_bus *video = (struct acpi_video_bus *)seq->private;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001060
Linus Torvalds1da177e2005-04-16 15:20:36 -07001061
Len Brown4be44fc2005-08-05 00:44:28 -04001062 seq_printf(seq, "DOS setting: <%d>\n", video->dos_setting);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001063
Patrick Mocheld550d982006-06-27 00:41:40 -04001064 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001065}
1066
Len Brown4be44fc2005-08-05 00:44:28 -04001067static int acpi_video_bus_POST_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001068{
Len Brown4be44fc2005-08-05 00:44:28 -04001069 return single_open(file, acpi_video_bus_POST_seq_show,
1070 PDE(inode)->data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001071}
1072
Len Brown4be44fc2005-08-05 00:44:28 -04001073static int acpi_video_bus_DOS_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001074{
1075 return single_open(file, acpi_video_bus_DOS_seq_show, PDE(inode)->data);
1076}
1077
1078static ssize_t
Len Brown4be44fc2005-08-05 00:44:28 -04001079acpi_video_bus_write_POST(struct file *file,
1080 const char __user * buffer,
1081 size_t count, loff_t * data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001082{
Len Brown4be44fc2005-08-05 00:44:28 -04001083 int status;
1084 struct seq_file *m = (struct seq_file *)file->private_data;
1085 struct acpi_video_bus *video = (struct acpi_video_bus *)m->private;
1086 char str[12] = { 0 };
1087 unsigned long opt, options;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001088
Linus Torvalds1da177e2005-04-16 15:20:36 -07001089
Linus Torvalds1da177e2005-04-16 15:20:36 -07001090 if (!video || count + 1 > sizeof str)
Patrick Mocheld550d982006-06-27 00:41:40 -04001091 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001092
1093 status = acpi_video_bus_POST_options(video, &options);
1094 if (!ACPI_SUCCESS(status))
Patrick Mocheld550d982006-06-27 00:41:40 -04001095 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001096
1097 if (copy_from_user(str, buffer, count))
Patrick Mocheld550d982006-06-27 00:41:40 -04001098 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001099
1100 str[count] = 0;
1101 opt = strtoul(str, NULL, 0);
1102 if (opt > 3)
Patrick Mocheld550d982006-06-27 00:41:40 -04001103 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001104
1105 /* just in case an OEM 'forget' the motherboard... */
1106 options |= 1;
1107
1108 if (options & (1ul << opt)) {
Len Brown4be44fc2005-08-05 00:44:28 -04001109 status = acpi_video_bus_set_POST(video, opt);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001110 if (!ACPI_SUCCESS(status))
Patrick Mocheld550d982006-06-27 00:41:40 -04001111 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001112
1113 }
1114
Patrick Mocheld550d982006-06-27 00:41:40 -04001115 return count;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001116}
1117
1118static ssize_t
Len Brown4be44fc2005-08-05 00:44:28 -04001119acpi_video_bus_write_DOS(struct file *file,
1120 const char __user * buffer,
1121 size_t count, loff_t * data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001122{
Len Brown4be44fc2005-08-05 00:44:28 -04001123 int status;
1124 struct seq_file *m = (struct seq_file *)file->private_data;
1125 struct acpi_video_bus *video = (struct acpi_video_bus *)m->private;
1126 char str[12] = { 0 };
1127 unsigned long opt;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001128
Linus Torvalds1da177e2005-04-16 15:20:36 -07001129
Linus Torvalds1da177e2005-04-16 15:20:36 -07001130 if (!video || count + 1 > sizeof str)
Patrick Mocheld550d982006-06-27 00:41:40 -04001131 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001132
1133 if (copy_from_user(str, buffer, count))
Patrick Mocheld550d982006-06-27 00:41:40 -04001134 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001135
1136 str[count] = 0;
1137 opt = strtoul(str, NULL, 0);
1138 if (opt > 7)
Patrick Mocheld550d982006-06-27 00:41:40 -04001139 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001140
Len Brown4be44fc2005-08-05 00:44:28 -04001141 status = acpi_video_bus_DOS(video, opt & 0x3, (opt & 0x4) >> 2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001142
1143 if (!ACPI_SUCCESS(status))
Patrick Mocheld550d982006-06-27 00:41:40 -04001144 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001145
Patrick Mocheld550d982006-06-27 00:41:40 -04001146 return count;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001147}
1148
Len Brown4be44fc2005-08-05 00:44:28 -04001149static int acpi_video_bus_add_fs(struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001150{
Len Brown4be44fc2005-08-05 00:44:28 -04001151 struct proc_dir_entry *entry = NULL;
1152 struct acpi_video_bus *video;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001153
Linus Torvalds1da177e2005-04-16 15:20:36 -07001154
Len Brown4be44fc2005-08-05 00:44:28 -04001155 video = (struct acpi_video_bus *)acpi_driver_data(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001156
1157 if (!acpi_device_dir(device)) {
1158 acpi_device_dir(device) = proc_mkdir(acpi_device_bid(device),
Len Brown4be44fc2005-08-05 00:44:28 -04001159 acpi_video_dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001160 if (!acpi_device_dir(device))
Patrick Mocheld550d982006-06-27 00:41:40 -04001161 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001162 video->dir = acpi_device_dir(device);
1163 acpi_device_dir(device)->owner = THIS_MODULE;
1164 }
1165
1166 /* 'info' [R] */
1167 entry = create_proc_entry("info", S_IRUGO, acpi_device_dir(device));
1168 if (!entry)
Patrick Mocheld550d982006-06-27 00:41:40 -04001169 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001170 else {
1171 entry->proc_fops = &acpi_video_bus_info_fops;
1172 entry->data = acpi_driver_data(device);
1173 entry->owner = THIS_MODULE;
1174 }
1175
1176 /* 'ROM' [R] */
1177 entry = create_proc_entry("ROM", S_IRUGO, acpi_device_dir(device));
1178 if (!entry)
Patrick Mocheld550d982006-06-27 00:41:40 -04001179 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001180 else {
1181 entry->proc_fops = &acpi_video_bus_ROM_fops;
1182 entry->data = acpi_driver_data(device);
1183 entry->owner = THIS_MODULE;
1184 }
1185
1186 /* 'POST_info' [R] */
Len Brown4be44fc2005-08-05 00:44:28 -04001187 entry =
1188 create_proc_entry("POST_info", S_IRUGO, acpi_device_dir(device));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001189 if (!entry)
Patrick Mocheld550d982006-06-27 00:41:40 -04001190 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001191 else {
1192 entry->proc_fops = &acpi_video_bus_POST_info_fops;
1193 entry->data = acpi_driver_data(device);
1194 entry->owner = THIS_MODULE;
1195 }
1196
1197 /* 'POST' [R/W] */
Len Brown4be44fc2005-08-05 00:44:28 -04001198 entry =
1199 create_proc_entry("POST", S_IFREG | S_IRUGO | S_IRUSR,
1200 acpi_device_dir(device));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001201 if (!entry)
Patrick Mocheld550d982006-06-27 00:41:40 -04001202 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001203 else {
Arjan van de Vend479e902006-01-06 16:47:00 -05001204 acpi_video_bus_POST_fops.write = acpi_video_bus_write_POST;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001205 entry->proc_fops = &acpi_video_bus_POST_fops;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001206 entry->data = acpi_driver_data(device);
1207 entry->owner = THIS_MODULE;
1208 }
1209
1210 /* 'DOS' [R/W] */
Len Brown4be44fc2005-08-05 00:44:28 -04001211 entry =
1212 create_proc_entry("DOS", S_IFREG | S_IRUGO | S_IRUSR,
1213 acpi_device_dir(device));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001214 if (!entry)
Patrick Mocheld550d982006-06-27 00:41:40 -04001215 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001216 else {
Arjan van de Vend479e902006-01-06 16:47:00 -05001217 acpi_video_bus_DOS_fops.write = acpi_video_bus_write_DOS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001218 entry->proc_fops = &acpi_video_bus_DOS_fops;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001219 entry->data = acpi_driver_data(device);
1220 entry->owner = THIS_MODULE;
1221 }
1222
Patrick Mocheld550d982006-06-27 00:41:40 -04001223 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001224}
1225
Len Brown4be44fc2005-08-05 00:44:28 -04001226static int acpi_video_bus_remove_fs(struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001227{
Len Brown4be44fc2005-08-05 00:44:28 -04001228 struct acpi_video_bus *video;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001229
Linus Torvalds1da177e2005-04-16 15:20:36 -07001230
Len Brown4be44fc2005-08-05 00:44:28 -04001231 video = (struct acpi_video_bus *)acpi_driver_data(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001232
1233 if (acpi_device_dir(device)) {
1234 remove_proc_entry("info", acpi_device_dir(device));
1235 remove_proc_entry("ROM", acpi_device_dir(device));
1236 remove_proc_entry("POST_info", acpi_device_dir(device));
1237 remove_proc_entry("POST", acpi_device_dir(device));
1238 remove_proc_entry("DOS", acpi_device_dir(device));
Len Brown4be44fc2005-08-05 00:44:28 -04001239 remove_proc_entry(acpi_device_bid(device), acpi_video_dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001240 acpi_device_dir(device) = NULL;
1241 }
1242
Patrick Mocheld550d982006-06-27 00:41:40 -04001243 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001244}
1245
1246/* --------------------------------------------------------------------------
1247 Driver Interface
1248 -------------------------------------------------------------------------- */
1249
1250/* device interface */
1251
1252static int
Len Brown4be44fc2005-08-05 00:44:28 -04001253acpi_video_bus_get_one_device(struct acpi_device *device,
1254 struct acpi_video_bus *video)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001255{
Len Brown4be44fc2005-08-05 00:44:28 -04001256 unsigned long device_id;
Yu, Luming973bf492006-04-27 05:25:00 -04001257 int status;
Len Brown4be44fc2005-08-05 00:44:28 -04001258 struct acpi_video_device *data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001259
Linus Torvalds1da177e2005-04-16 15:20:36 -07001260
1261 if (!device || !video)
Patrick Mocheld550d982006-06-27 00:41:40 -04001262 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001263
Len Brown4be44fc2005-08-05 00:44:28 -04001264 status =
1265 acpi_evaluate_integer(device->handle, "_ADR", NULL, &device_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001266 if (ACPI_SUCCESS(status)) {
1267
1268 data = kmalloc(sizeof(struct acpi_video_device), GFP_KERNEL);
1269 if (!data)
Patrick Mocheld550d982006-06-27 00:41:40 -04001270 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001271
1272 memset(data, 0, sizeof(struct acpi_video_device));
1273
1274 data->handle = device->handle;
1275 strcpy(acpi_device_name(device), ACPI_VIDEO_DEVICE_NAME);
1276 strcpy(acpi_device_class(device), ACPI_VIDEO_CLASS);
1277 acpi_driver_data(device) = data;
1278
1279 data->device_id = device_id;
1280 data->video = video;
1281 data->dev = device;
1282
1283 switch (device_id & 0xffff) {
1284 case 0x0100:
1285 data->flags.crt = 1;
1286 break;
1287 case 0x0400:
1288 data->flags.lcd = 1;
1289 break;
1290 case 0x0200:
1291 data->flags.tvout = 1;
1292 break;
1293 default:
1294 data->flags.unknown = 1;
1295 break;
1296 }
Len Brown4be44fc2005-08-05 00:44:28 -04001297
Linus Torvalds1da177e2005-04-16 15:20:36 -07001298 acpi_video_device_bind(video, data);
1299 acpi_video_device_find_cap(data);
1300
Patrick Mochel90130262006-05-19 16:54:48 -04001301 status = acpi_install_notify_handler(device->handle,
Len Brown4be44fc2005-08-05 00:44:28 -04001302 ACPI_DEVICE_NOTIFY,
1303 acpi_video_device_notify,
1304 data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001305 if (ACPI_FAILURE(status)) {
1306 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
Len Brown4be44fc2005-08-05 00:44:28 -04001307 "Error installing notify handler\n"));
Yu, Luming973bf492006-04-27 05:25:00 -04001308 if(data->brightness)
1309 kfree(data->brightness->levels);
1310 kfree(data->brightness);
1311 kfree(data);
1312 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001313 }
1314
1315 down(&video->sem);
1316 list_add_tail(&data->entry, &video->video_device_list);
1317 up(&video->sem);
1318
1319 acpi_video_device_add_fs(device);
1320
Patrick Mocheld550d982006-06-27 00:41:40 -04001321 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001322 }
1323
Patrick Mocheld550d982006-06-27 00:41:40 -04001324 return -ENOENT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001325}
1326
1327/*
1328 * Arg:
1329 * video : video bus device
1330 *
1331 * Return:
1332 * none
1333 *
1334 * Enumerate the video device list of the video bus,
1335 * bind the ids with the corresponding video devices
1336 * under the video bus.
Len Brown4be44fc2005-08-05 00:44:28 -04001337 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001338
Len Brown4be44fc2005-08-05 00:44:28 -04001339static void acpi_video_device_rebind(struct acpi_video_bus *video)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001340{
Len Brown4be44fc2005-08-05 00:44:28 -04001341 struct list_head *node, *next;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001342 list_for_each_safe(node, next, &video->video_device_list) {
Len Brown4be44fc2005-08-05 00:44:28 -04001343 struct acpi_video_device *dev =
1344 container_of(node, struct acpi_video_device, entry);
1345 acpi_video_device_bind(video, dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001346 }
1347}
1348
1349/*
1350 * Arg:
1351 * video : video bus device
1352 * device : video output device under the video
1353 * bus
1354 *
1355 * Return:
1356 * none
1357 *
1358 * Bind the ids with the corresponding video devices
1359 * under the video bus.
Len Brown4be44fc2005-08-05 00:44:28 -04001360 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001361
1362static void
Len Brown4be44fc2005-08-05 00:44:28 -04001363acpi_video_device_bind(struct acpi_video_bus *video,
1364 struct acpi_video_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001365{
Len Brown4be44fc2005-08-05 00:44:28 -04001366 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001367
1368#define IDS_VAL(i) video->attached_array[i].value.int_val
1369#define IDS_BIND(i) video->attached_array[i].bind_info
Len Brown4be44fc2005-08-05 00:44:28 -04001370
1371 for (i = 0; IDS_VAL(i) != ACPI_VIDEO_HEAD_INVALID &&
1372 i < video->attached_count; i++) {
1373 if (device->device_id == (IDS_VAL(i) & 0xffff)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001374 IDS_BIND(i) = device;
1375 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "device_bind %d\n", i));
1376 }
1377 }
1378#undef IDS_VAL
1379#undef IDS_BIND
1380}
1381
1382/*
1383 * Arg:
1384 * video : video bus device
1385 *
1386 * Return:
1387 * < 0 : error
1388 *
1389 * Call _DOD to enumerate all devices attached to display adapter
1390 *
Len Brown4be44fc2005-08-05 00:44:28 -04001391 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001392
1393static int acpi_video_device_enumerate(struct acpi_video_bus *video)
1394{
Len Brown4be44fc2005-08-05 00:44:28 -04001395 int status;
1396 int count;
1397 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001398 struct acpi_video_enumerated_device *active_device_list;
Len Brown4be44fc2005-08-05 00:44:28 -04001399 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
1400 union acpi_object *dod = NULL;
1401 union acpi_object *obj;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001402
Patrick Mochel90130262006-05-19 16:54:48 -04001403 status = acpi_evaluate_object(video->device->handle, "_DOD", NULL, &buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001404 if (!ACPI_SUCCESS(status)) {
Thomas Renningera6fc6722006-06-26 23:58:43 -04001405 ACPI_EXCEPTION((AE_INFO, status, "Evaluating _DOD"));
Patrick Mocheld550d982006-06-27 00:41:40 -04001406 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001407 }
1408
Len Brown4be44fc2005-08-05 00:44:28 -04001409 dod = (union acpi_object *)buffer.pointer;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001410 if (!dod || (dod->type != ACPI_TYPE_PACKAGE)) {
Thomas Renningera6fc6722006-06-26 23:58:43 -04001411 ACPI_EXCEPTION((AE_INFO, status, "Invalid _DOD data"));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001412 status = -EFAULT;
1413 goto out;
1414 }
1415
1416 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found %d video heads in _DOD\n",
Len Brown4be44fc2005-08-05 00:44:28 -04001417 dod->package.count));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001418
Len Brown4be44fc2005-08-05 00:44:28 -04001419 active_device_list = kmalloc((1 +
1420 dod->package.count) *
1421 sizeof(struct
1422 acpi_video_enumerated_device),
1423 GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001424
1425 if (!active_device_list) {
1426 status = -ENOMEM;
1427 goto out;
1428 }
1429
1430 count = 0;
1431 for (i = 0; i < dod->package.count; i++) {
Len Brown4be44fc2005-08-05 00:44:28 -04001432 obj = (union acpi_object *)&dod->package.elements[i];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001433
1434 if (obj->type != ACPI_TYPE_INTEGER) {
Len Brown64684632006-06-26 23:41:38 -04001435 printk(KERN_ERR PREFIX "Invalid _DOD data\n");
Len Brown4be44fc2005-08-05 00:44:28 -04001436 active_device_list[i].value.int_val =
1437 ACPI_VIDEO_HEAD_INVALID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001438 }
1439 active_device_list[i].value.int_val = obj->integer.value;
1440 active_device_list[i].bind_info = NULL;
Len Brown4be44fc2005-08-05 00:44:28 -04001441 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "dod element[%d] = %d\n", i,
1442 (int)obj->integer.value));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001443 count++;
1444 }
1445 active_device_list[count].value.int_val = ACPI_VIDEO_HEAD_END;
1446
Jesper Juhl6044ec82005-11-07 01:01:32 -08001447 kfree(video->attached_array);
Len Brown4be44fc2005-08-05 00:44:28 -04001448
Linus Torvalds1da177e2005-04-16 15:20:36 -07001449 video->attached_array = active_device_list;
1450 video->attached_count = count;
Len Brown4be44fc2005-08-05 00:44:28 -04001451 out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001452 acpi_os_free(buffer.pointer);
Patrick Mocheld550d982006-06-27 00:41:40 -04001453 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001454}
1455
1456/*
1457 * Arg:
1458 * video : video bus device
1459 * event : Nontify Event
1460 *
1461 * Return:
1462 * < 0 : error
1463 *
1464 * 1. Find out the current active output device.
1465 * 2. Identify the next output device to switch
1466 * 3. call _DSS to do actual switch.
Len Brown4be44fc2005-08-05 00:44:28 -04001467 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001468
Len Brown4be44fc2005-08-05 00:44:28 -04001469static int acpi_video_switch_output(struct acpi_video_bus *video, int event)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001470{
Len Brown4be44fc2005-08-05 00:44:28 -04001471 struct list_head *node, *next;
1472 struct acpi_video_device *dev = NULL;
1473 struct acpi_video_device *dev_next = NULL;
1474 struct acpi_video_device *dev_prev = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001475 unsigned long state;
1476 int status = 0;
1477
Linus Torvalds1da177e2005-04-16 15:20:36 -07001478
1479 list_for_each_safe(node, next, &video->video_device_list) {
Adrian Bunk73345712005-03-30 22:31:35 -05001480 dev = container_of(node, struct acpi_video_device, entry);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001481 status = acpi_video_device_get_state(dev, &state);
Len Brown4be44fc2005-08-05 00:44:28 -04001482 if (state & 0x2) {
1483 dev_next =
1484 container_of(node->next, struct acpi_video_device,
1485 entry);
1486 dev_prev =
1487 container_of(node->prev, struct acpi_video_device,
1488 entry);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001489 goto out;
1490 }
1491 }
1492 dev_next = container_of(node->next, struct acpi_video_device, entry);
1493 dev_prev = container_of(node->prev, struct acpi_video_device, entry);
Len Brown4be44fc2005-08-05 00:44:28 -04001494 out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001495 switch (event) {
1496 case ACPI_VIDEO_NOTIFY_CYCLE:
1497 case ACPI_VIDEO_NOTIFY_NEXT_OUTPUT:
1498 acpi_video_device_set_state(dev, 0);
1499 acpi_video_device_set_state(dev_next, 0x80000001);
1500 break;
1501 case ACPI_VIDEO_NOTIFY_PREV_OUTPUT:
1502 acpi_video_device_set_state(dev, 0);
1503 acpi_video_device_set_state(dev_prev, 0x80000001);
1504 default:
1505 break;
1506 }
1507
Patrick Mocheld550d982006-06-27 00:41:40 -04001508 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001509}
1510
Len Brown4be44fc2005-08-05 00:44:28 -04001511static int
1512acpi_video_get_next_level(struct acpi_video_device *device,
1513 u32 level_current, u32 event)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001514{
Len Brown4be44fc2005-08-05 00:44:28 -04001515 /*Fix me */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001516 return level_current;
1517}
1518
Linus Torvalds1da177e2005-04-16 15:20:36 -07001519static void
Len Brown4be44fc2005-08-05 00:44:28 -04001520acpi_video_switch_brightness(struct acpi_video_device *device, int event)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001521{
1522 unsigned long level_current, level_next;
1523 acpi_video_device_lcd_get_level_current(device, &level_current);
1524 level_next = acpi_video_get_next_level(device, level_current, event);
1525 acpi_video_device_lcd_set_level(device, level_next);
1526}
1527
1528static int
Len Brown4be44fc2005-08-05 00:44:28 -04001529acpi_video_bus_get_devices(struct acpi_video_bus *video,
1530 struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001531{
Len Brown4be44fc2005-08-05 00:44:28 -04001532 int status = 0;
1533 struct list_head *node, *next;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001534
Linus Torvalds1da177e2005-04-16 15:20:36 -07001535
1536 acpi_video_device_enumerate(video);
1537
1538 list_for_each_safe(node, next, &device->children) {
Len Brown4be44fc2005-08-05 00:44:28 -04001539 struct acpi_device *dev =
1540 list_entry(node, struct acpi_device, node);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001541
1542 if (!dev)
1543 continue;
1544
1545 status = acpi_video_bus_get_one_device(dev, video);
1546 if (ACPI_FAILURE(status)) {
Thomas Renningera6fc6722006-06-26 23:58:43 -04001547 ACPI_EXCEPTION((AE_INFO, status, "Cant attach device"));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001548 continue;
1549 }
1550
1551 }
Patrick Mocheld550d982006-06-27 00:41:40 -04001552 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001553}
1554
Len Brown4be44fc2005-08-05 00:44:28 -04001555static int acpi_video_bus_put_one_device(struct acpi_video_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001556{
Karol Kozimor031ec772005-07-30 04:18:00 -04001557 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001558 struct acpi_video_bus *video;
1559
Linus Torvalds1da177e2005-04-16 15:20:36 -07001560
1561 if (!device || !device->video)
Patrick Mocheld550d982006-06-27 00:41:40 -04001562 return -ENOENT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001563
1564 video = device->video;
1565
1566 down(&video->sem);
1567 list_del(&device->entry);
1568 up(&video->sem);
1569 acpi_video_device_remove_fs(device->dev);
1570
Patrick Mochel90130262006-05-19 16:54:48 -04001571 status = acpi_remove_notify_handler(device->dev->handle,
Len Brown4be44fc2005-08-05 00:44:28 -04001572 ACPI_DEVICE_NOTIFY,
1573 acpi_video_device_notify);
Karol Kozimor031ec772005-07-30 04:18:00 -04001574
Patrick Mocheld550d982006-06-27 00:41:40 -04001575 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001576}
1577
Len Brown4be44fc2005-08-05 00:44:28 -04001578static int acpi_video_bus_put_devices(struct acpi_video_bus *video)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001579{
Len Brown4be44fc2005-08-05 00:44:28 -04001580 int status;
1581 struct list_head *node, *next;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001582
Linus Torvalds1da177e2005-04-16 15:20:36 -07001583
1584 list_for_each_safe(node, next, &video->video_device_list) {
Len Brown4be44fc2005-08-05 00:44:28 -04001585 struct acpi_video_device *data =
1586 list_entry(node, struct acpi_video_device, entry);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001587 if (!data)
1588 continue;
1589
1590 status = acpi_video_bus_put_one_device(data);
Len Brown4be44fc2005-08-05 00:44:28 -04001591 if (ACPI_FAILURE(status))
1592 printk(KERN_WARNING PREFIX
1593 "hhuuhhuu bug in acpi video driver.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001594
Dave Jonesd384ea62006-06-24 00:33:08 -04001595 if (data->brightness)
Yu, Luming973bf492006-04-27 05:25:00 -04001596 kfree(data->brightness->levels);
Jesper Juhl6044ec82005-11-07 01:01:32 -08001597 kfree(data->brightness);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001598 kfree(data);
1599 }
1600
Patrick Mocheld550d982006-06-27 00:41:40 -04001601 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001602}
1603
1604/* acpi_video interface */
1605
Len Brown4be44fc2005-08-05 00:44:28 -04001606static int acpi_video_bus_start_devices(struct acpi_video_bus *video)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001607{
1608 return acpi_video_bus_DOS(video, 1, 0);
1609}
1610
Len Brown4be44fc2005-08-05 00:44:28 -04001611static int acpi_video_bus_stop_devices(struct acpi_video_bus *video)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001612{
1613 return acpi_video_bus_DOS(video, 0, 1);
1614}
1615
Len Brown4be44fc2005-08-05 00:44:28 -04001616static void acpi_video_bus_notify(acpi_handle handle, u32 event, void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001617{
Len Brown4be44fc2005-08-05 00:44:28 -04001618 struct acpi_video_bus *video = (struct acpi_video_bus *)data;
1619 struct acpi_device *device = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001620
Linus Torvalds1da177e2005-04-16 15:20:36 -07001621 printk("video bus notify\n");
1622
1623 if (!video)
Patrick Mocheld550d982006-06-27 00:41:40 -04001624 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001625
Patrick Mochele6afa0d2006-05-19 16:54:40 -04001626 device = video->device;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001627
1628 switch (event) {
1629 case ACPI_VIDEO_NOTIFY_SWITCH: /* User request that a switch occur,
1630 * most likely via hotkey. */
1631 acpi_bus_generate_event(device, event, 0);
1632 break;
1633
1634 case ACPI_VIDEO_NOTIFY_PROBE: /* User plug or remove a video
1635 * connector. */
1636 acpi_video_device_enumerate(video);
1637 acpi_video_device_rebind(video);
1638 acpi_video_switch_output(video, event);
1639 acpi_bus_generate_event(device, event, 0);
1640 break;
1641
Len Brown4be44fc2005-08-05 00:44:28 -04001642 case ACPI_VIDEO_NOTIFY_CYCLE: /* Cycle Display output hotkey pressed. */
1643 case ACPI_VIDEO_NOTIFY_NEXT_OUTPUT: /* Next Display output hotkey pressed. */
1644 case ACPI_VIDEO_NOTIFY_PREV_OUTPUT: /* previous Display output hotkey pressed. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001645 acpi_video_switch_output(video, event);
1646 acpi_bus_generate_event(device, event, 0);
1647 break;
1648
1649 default:
1650 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
Len Brown4be44fc2005-08-05 00:44:28 -04001651 "Unsupported event [0x%x]\n", event));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001652 break;
1653 }
1654
Patrick Mocheld550d982006-06-27 00:41:40 -04001655 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001656}
1657
Len Brown4be44fc2005-08-05 00:44:28 -04001658static void acpi_video_device_notify(acpi_handle handle, u32 event, void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001659{
Len Brown4be44fc2005-08-05 00:44:28 -04001660 struct acpi_video_device *video_device =
1661 (struct acpi_video_device *)data;
1662 struct acpi_device *device = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001663
Linus Torvalds1da177e2005-04-16 15:20:36 -07001664
1665 printk("video device notify\n");
1666 if (!video_device)
Patrick Mocheld550d982006-06-27 00:41:40 -04001667 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001668
Patrick Mochele6afa0d2006-05-19 16:54:40 -04001669 device = video_device->dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001670
1671 switch (event) {
Len Brown4be44fc2005-08-05 00:44:28 -04001672 case ACPI_VIDEO_NOTIFY_SWITCH: /* change in status (cycle output device) */
1673 case ACPI_VIDEO_NOTIFY_PROBE: /* change in status (output device status) */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001674 acpi_bus_generate_event(device, event, 0);
1675 break;
Len Brown4be44fc2005-08-05 00:44:28 -04001676 case ACPI_VIDEO_NOTIFY_CYCLE_BRIGHTNESS: /* Cycle brightness */
1677 case ACPI_VIDEO_NOTIFY_INC_BRIGHTNESS: /* Increase brightness */
1678 case ACPI_VIDEO_NOTIFY_DEC_BRIGHTNESS: /* Decrease brightness */
1679 case ACPI_VIDEO_NOTIFY_ZERO_BRIGHTNESS: /* zero brightnesss */
1680 case ACPI_VIDEO_NOTIFY_DISPLAY_OFF: /* display device off */
1681 acpi_video_switch_brightness(video_device, event);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001682 acpi_bus_generate_event(device, event, 0);
1683 break;
1684 default:
1685 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
Len Brown4be44fc2005-08-05 00:44:28 -04001686 "Unsupported event [0x%x]\n", event));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001687 break;
1688 }
Patrick Mocheld550d982006-06-27 00:41:40 -04001689 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001690}
1691
Len Brown4be44fc2005-08-05 00:44:28 -04001692static int acpi_video_bus_add(struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001693{
Len Brown4be44fc2005-08-05 00:44:28 -04001694 int result = 0;
1695 acpi_status status = 0;
1696 struct acpi_video_bus *video = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001697
Len Brown4be44fc2005-08-05 00:44:28 -04001698
Linus Torvalds1da177e2005-04-16 15:20:36 -07001699 if (!device)
Patrick Mocheld550d982006-06-27 00:41:40 -04001700 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001701
1702 video = kmalloc(sizeof(struct acpi_video_bus), GFP_KERNEL);
1703 if (!video)
Patrick Mocheld550d982006-06-27 00:41:40 -04001704 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001705 memset(video, 0, sizeof(struct acpi_video_bus));
1706
1707 video->handle = device->handle;
Patrick Mochele6afa0d2006-05-19 16:54:40 -04001708 video->device = device;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001709 strcpy(acpi_device_name(device), ACPI_VIDEO_BUS_NAME);
1710 strcpy(acpi_device_class(device), ACPI_VIDEO_CLASS);
1711 acpi_driver_data(device) = video;
1712
1713 acpi_video_bus_find_cap(video);
1714 result = acpi_video_bus_check(video);
1715 if (result)
1716 goto end;
1717
1718 result = acpi_video_bus_add_fs(device);
1719 if (result)
1720 goto end;
1721
1722 init_MUTEX(&video->sem);
1723 INIT_LIST_HEAD(&video->video_device_list);
1724
1725 acpi_video_bus_get_devices(video, device);
1726 acpi_video_bus_start_devices(video);
1727
Patrick Mochel90130262006-05-19 16:54:48 -04001728 status = acpi_install_notify_handler(device->handle,
Len Brown4be44fc2005-08-05 00:44:28 -04001729 ACPI_DEVICE_NOTIFY,
1730 acpi_video_bus_notify, video);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001731 if (ACPI_FAILURE(status)) {
1732 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
Len Brown4be44fc2005-08-05 00:44:28 -04001733 "Error installing notify handler\n"));
Yu, Luming973bf492006-04-27 05:25:00 -04001734 acpi_video_bus_stop_devices(video);
1735 acpi_video_bus_put_devices(video);
1736 kfree(video->attached_array);
1737 acpi_video_bus_remove_fs(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001738 result = -ENODEV;
1739 goto end;
1740 }
1741
1742 printk(KERN_INFO PREFIX "%s [%s] (multi-head: %s rom: %s post: %s)\n",
Len Brown4be44fc2005-08-05 00:44:28 -04001743 ACPI_VIDEO_DEVICE_NAME, acpi_device_bid(device),
1744 video->flags.multihead ? "yes" : "no",
1745 video->flags.rom ? "yes" : "no",
1746 video->flags.post ? "yes" : "no");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001747
Len Brown4be44fc2005-08-05 00:44:28 -04001748 end:
Yu, Luming973bf492006-04-27 05:25:00 -04001749 if (result)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001750 kfree(video);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001751
Patrick Mocheld550d982006-06-27 00:41:40 -04001752 return result;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001753}
1754
Len Brown4be44fc2005-08-05 00:44:28 -04001755static int acpi_video_bus_remove(struct acpi_device *device, int type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001756{
Len Brown4be44fc2005-08-05 00:44:28 -04001757 acpi_status status = 0;
1758 struct acpi_video_bus *video = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001759
Linus Torvalds1da177e2005-04-16 15:20:36 -07001760
1761 if (!device || !acpi_driver_data(device))
Patrick Mocheld550d982006-06-27 00:41:40 -04001762 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001763
Len Brown4be44fc2005-08-05 00:44:28 -04001764 video = (struct acpi_video_bus *)acpi_driver_data(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001765
1766 acpi_video_bus_stop_devices(video);
1767
Patrick Mochel90130262006-05-19 16:54:48 -04001768 status = acpi_remove_notify_handler(video->device->handle,
Len Brown4be44fc2005-08-05 00:44:28 -04001769 ACPI_DEVICE_NOTIFY,
1770 acpi_video_bus_notify);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001771
1772 acpi_video_bus_put_devices(video);
1773 acpi_video_bus_remove_fs(device);
1774
Jesper Juhl6044ec82005-11-07 01:01:32 -08001775 kfree(video->attached_array);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001776 kfree(video);
1777
Patrick Mocheld550d982006-06-27 00:41:40 -04001778 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001779}
1780
Linus Torvalds1da177e2005-04-16 15:20:36 -07001781static int
Len Brown4be44fc2005-08-05 00:44:28 -04001782acpi_video_bus_match(struct acpi_device *device, struct acpi_driver *driver)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001783{
Len Brown4be44fc2005-08-05 00:44:28 -04001784 acpi_handle h_dummy1;
1785 acpi_handle h_dummy2;
1786 acpi_handle h_dummy3;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001787
Linus Torvalds1da177e2005-04-16 15:20:36 -07001788
1789 if (!device || !driver)
Patrick Mocheld550d982006-06-27 00:41:40 -04001790 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001791
1792 /* Since there is no HID, CID for ACPI Video drivers, we have
1793 * to check well known required nodes for each feature we support.
1794 */
1795
1796 /* Does this device able to support video switching ? */
1797 if (ACPI_SUCCESS(acpi_get_handle(device->handle, "_DOD", &h_dummy1)) &&
1798 ACPI_SUCCESS(acpi_get_handle(device->handle, "_DOS", &h_dummy2)))
Patrick Mocheld550d982006-06-27 00:41:40 -04001799 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001800
1801 /* Does this device able to retrieve a video ROM ? */
1802 if (ACPI_SUCCESS(acpi_get_handle(device->handle, "_ROM", &h_dummy1)))
Patrick Mocheld550d982006-06-27 00:41:40 -04001803 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001804
1805 /* Does this device able to configure which video head to be POSTed ? */
1806 if (ACPI_SUCCESS(acpi_get_handle(device->handle, "_VPO", &h_dummy1)) &&
1807 ACPI_SUCCESS(acpi_get_handle(device->handle, "_GPD", &h_dummy2)) &&
1808 ACPI_SUCCESS(acpi_get_handle(device->handle, "_SPD", &h_dummy3)))
Patrick Mocheld550d982006-06-27 00:41:40 -04001809 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001810
Patrick Mocheld550d982006-06-27 00:41:40 -04001811 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001812}
1813
Len Brown4be44fc2005-08-05 00:44:28 -04001814static int __init acpi_video_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001815{
Len Brown4be44fc2005-08-05 00:44:28 -04001816 int result = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001817
Linus Torvalds1da177e2005-04-16 15:20:36 -07001818
1819 /*
Len Brown4be44fc2005-08-05 00:44:28 -04001820 acpi_dbg_level = 0xFFFFFFFF;
1821 acpi_dbg_layer = 0x08000000;
1822 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001823
1824 acpi_video_dir = proc_mkdir(ACPI_VIDEO_CLASS, acpi_root_dir);
1825 if (!acpi_video_dir)
Patrick Mocheld550d982006-06-27 00:41:40 -04001826 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001827 acpi_video_dir->owner = THIS_MODULE;
1828
1829 result = acpi_bus_register_driver(&acpi_video_bus);
1830 if (result < 0) {
1831 remove_proc_entry(ACPI_VIDEO_CLASS, acpi_root_dir);
Patrick Mocheld550d982006-06-27 00:41:40 -04001832 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001833 }
1834
Patrick Mocheld550d982006-06-27 00:41:40 -04001835 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001836}
1837
Len Brown4be44fc2005-08-05 00:44:28 -04001838static void __exit acpi_video_exit(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001839{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001840
1841 acpi_bus_unregister_driver(&acpi_video_bus);
1842
1843 remove_proc_entry(ACPI_VIDEO_CLASS, acpi_root_dir);
1844
Patrick Mocheld550d982006-06-27 00:41:40 -04001845 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001846}
1847
1848module_init(acpi_video_init);
1849module_exit(acpi_video_exit);