blob: cee9a50fdf916b80abddc9642de2055fa0fc4557 [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;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700276 status = acpi_evaluate_integer(device->handle, "_DGS", NULL, state);
277
Patrick Mocheld550d982006-06-27 00:41:40 -0400278 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700279}
280
281static int
Len Brown4be44fc2005-08-05 00:44:28 -0400282acpi_video_device_get_state(struct acpi_video_device *device,
283 unsigned long *state)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700284{
Len Brown4be44fc2005-08-05 00:44:28 -0400285 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700286
Linus Torvalds1da177e2005-04-16 15:20:36 -0700287
288 status = acpi_evaluate_integer(device->handle, "_DCS", NULL, state);
289
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;
Luming Yu824b5582005-08-21 19:17:00 -0400303 status = acpi_evaluate_integer(device->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
319 status = acpi_evaluate_object(device->handle, "_BCL", NULL, &buffer);
320 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;
348 status = acpi_evaluate_object(device->handle, "_BCM", &args, NULL);
349
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
360 status = acpi_evaluate_integer(device->handle, "_BQC", NULL, level);
361
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
387 status = acpi_evaluate_object(device->handle, "_DDC", &args, &buffer);
388 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
417 status = acpi_evaluate_integer(video->handle, "_SPD", &args, &tmp);
418 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
Linus Torvalds1da177e2005-04-16 15:20:36 -0700429
430 status = acpi_evaluate_integer(video->handle, "_GPD", NULL, id);
431
Patrick Mocheld550d982006-06-27 00:41:40 -0400432 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700433}
434
435static int
Len Brown4be44fc2005-08-05 00:44:28 -0400436acpi_video_bus_POST_options(struct acpi_video_bus *video,
437 unsigned long *options)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700438{
Len Brown4be44fc2005-08-05 00:44:28 -0400439 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700440
441 status = acpi_evaluate_integer(video->handle, "_VPO", NULL, options);
442 *options &= 3;
443
Patrick Mocheld550d982006-06-27 00:41:40 -0400444 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700445}
446
447/*
448 * Arg:
449 * video : video bus device pointer
450 * bios_flag :
451 * 0. The system BIOS should NOT automatically switch(toggle)
452 * the active display output.
453 * 1. The system BIOS should automatically switch (toggle) the
454 * active display output. No swich event.
455 * 2. The _DGS value should be locked.
456 * 3. The system BIOS should not automatically switch (toggle) the
457 * active display output, but instead generate the display switch
458 * event notify code.
459 * lcd_flag :
460 * 0. The system BIOS should automatically control the brightness level
461 * of the LCD, when the power changes from AC to DC
462 * 1. The system BIOS should NOT automatically control the brightness
463 * level of the LCD, when the power changes from AC to DC.
464 * Return Value:
465 * -1 wrong arg.
466 */
467
468static int
Len Brown4be44fc2005-08-05 00:44:28 -0400469acpi_video_bus_DOS(struct acpi_video_bus *video, int bios_flag, int lcd_flag)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700470{
Len Brown4be44fc2005-08-05 00:44:28 -0400471 acpi_integer status = 0;
472 union acpi_object arg0 = { ACPI_TYPE_INTEGER };
473 struct acpi_object_list args = { 1, &arg0 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700474
Linus Torvalds1da177e2005-04-16 15:20:36 -0700475
Len Brown4be44fc2005-08-05 00:44:28 -0400476 if (bios_flag < 0 || bios_flag > 3 || lcd_flag < 0 || lcd_flag > 1) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700477 status = -1;
478 goto Failed;
479 }
480 arg0.integer.value = (lcd_flag << 2) | bios_flag;
481 video->dos_setting = arg0.integer.value;
482 acpi_evaluate_object(video->handle, "_DOS", &args, NULL);
483
Len Brown4be44fc2005-08-05 00:44:28 -0400484 Failed:
Patrick Mocheld550d982006-06-27 00:41:40 -0400485 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700486}
487
488/*
489 * Arg:
490 * device : video output device (LCD, CRT, ..)
491 *
492 * Return Value:
493 * None
494 *
495 * Find out all required AML method defined under the output
496 * device.
497 */
498
Len Brown4be44fc2005-08-05 00:44:28 -0400499static void acpi_video_device_find_cap(struct acpi_video_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700500{
Len Brown4be44fc2005-08-05 00:44:28 -0400501 acpi_integer status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700502 acpi_handle h_dummy1;
503 int i;
504 union acpi_object *obj = NULL;
505 struct acpi_video_device_brightness *br = NULL;
506
Linus Torvalds1da177e2005-04-16 15:20:36 -0700507
Len Brown4be44fc2005-08-05 00:44:28 -0400508 memset(&device->cap, 0, 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700509
Len Brown4be44fc2005-08-05 00:44:28 -0400510 if (ACPI_SUCCESS(acpi_get_handle(device->handle, "_ADR", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700511 device->cap._ADR = 1;
512 }
Len Brown4be44fc2005-08-05 00:44:28 -0400513 if (ACPI_SUCCESS(acpi_get_handle(device->handle, "_BCL", &h_dummy1))) {
514 device->cap._BCL = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700515 }
Len Brown4be44fc2005-08-05 00:44:28 -0400516 if (ACPI_SUCCESS(acpi_get_handle(device->handle, "_BCM", &h_dummy1))) {
517 device->cap._BCM = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700518 }
Len Brown4be44fc2005-08-05 00:44:28 -0400519 if (ACPI_SUCCESS(acpi_get_handle(device->handle, "_DDC", &h_dummy1))) {
520 device->cap._DDC = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700521 }
Len Brown4be44fc2005-08-05 00:44:28 -0400522 if (ACPI_SUCCESS(acpi_get_handle(device->handle, "_DCS", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700523 device->cap._DCS = 1;
524 }
Len Brown4be44fc2005-08-05 00:44:28 -0400525 if (ACPI_SUCCESS(acpi_get_handle(device->handle, "_DGS", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700526 device->cap._DGS = 1;
527 }
Len Brown4be44fc2005-08-05 00:44:28 -0400528 if (ACPI_SUCCESS(acpi_get_handle(device->handle, "_DSS", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700529 device->cap._DSS = 1;
530 }
531
532 status = acpi_video_device_lcd_query_levels(device, &obj);
533
534 if (obj && obj->type == ACPI_TYPE_PACKAGE && obj->package.count >= 2) {
535 int count = 0;
536 union acpi_object *o;
Len Brown4be44fc2005-08-05 00:44:28 -0400537
Paulo Marquesd1dd0c22005-03-30 22:39:49 -0500538 br = kmalloc(sizeof(*br), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700539 if (!br) {
540 printk(KERN_ERR "can't allocate memory\n");
541 } else {
Paulo Marquesd1dd0c22005-03-30 22:39:49 -0500542 memset(br, 0, sizeof(*br));
543 br->levels = kmalloc(obj->package.count *
Len Brown4be44fc2005-08-05 00:44:28 -0400544 sizeof *(br->levels), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700545 if (!br->levels)
546 goto out;
547
548 for (i = 0; i < obj->package.count; i++) {
Len Brown4be44fc2005-08-05 00:44:28 -0400549 o = (union acpi_object *)&obj->package.
550 elements[i];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700551 if (o->type != ACPI_TYPE_INTEGER) {
Len Brown64684632006-06-26 23:41:38 -0400552 printk(KERN_ERR PREFIX "Invalid data\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700553 continue;
554 }
555 br->levels[count] = (u32) o->integer.value;
556 count++;
557 }
Len Brown4be44fc2005-08-05 00:44:28 -0400558 out:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700559 if (count < 2) {
Paulo Marquesd1dd0c22005-03-30 22:39:49 -0500560 kfree(br->levels);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700561 kfree(br);
562 } else {
563 br->count = count;
564 device->brightness = br;
Len Brown4be44fc2005-08-05 00:44:28 -0400565 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
566 "found %d brightness levels\n",
567 count));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700568 }
569 }
570 }
571
Paulo Marquesd1dd0c22005-03-30 22:39:49 -0500572 kfree(obj);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700573
Patrick Mocheld550d982006-06-27 00:41:40 -0400574 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700575}
576
577/*
578 * Arg:
579 * device : video output device (VGA)
580 *
581 * Return Value:
582 * None
583 *
584 * Find out all required AML method defined under the video bus device.
585 */
586
Len Brown4be44fc2005-08-05 00:44:28 -0400587static void acpi_video_bus_find_cap(struct acpi_video_bus *video)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700588{
Len Brown4be44fc2005-08-05 00:44:28 -0400589 acpi_handle h_dummy1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700590
Len Brown4be44fc2005-08-05 00:44:28 -0400591 memset(&video->cap, 0, 4);
592 if (ACPI_SUCCESS(acpi_get_handle(video->handle, "_DOS", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700593 video->cap._DOS = 1;
594 }
Len Brown4be44fc2005-08-05 00:44:28 -0400595 if (ACPI_SUCCESS(acpi_get_handle(video->handle, "_DOD", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700596 video->cap._DOD = 1;
597 }
Len Brown4be44fc2005-08-05 00:44:28 -0400598 if (ACPI_SUCCESS(acpi_get_handle(video->handle, "_ROM", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700599 video->cap._ROM = 1;
600 }
Len Brown4be44fc2005-08-05 00:44:28 -0400601 if (ACPI_SUCCESS(acpi_get_handle(video->handle, "_GPD", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700602 video->cap._GPD = 1;
603 }
Len Brown4be44fc2005-08-05 00:44:28 -0400604 if (ACPI_SUCCESS(acpi_get_handle(video->handle, "_SPD", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700605 video->cap._SPD = 1;
606 }
Len Brown4be44fc2005-08-05 00:44:28 -0400607 if (ACPI_SUCCESS(acpi_get_handle(video->handle, "_VPO", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700608 video->cap._VPO = 1;
609 }
610}
611
612/*
613 * Check whether the video bus device has required AML method to
614 * support the desired features
615 */
616
Len Brown4be44fc2005-08-05 00:44:28 -0400617static int acpi_video_bus_check(struct acpi_video_bus *video)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700618{
Len Brown4be44fc2005-08-05 00:44:28 -0400619 acpi_status status = -ENOENT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700620
Linus Torvalds1da177e2005-04-16 15:20:36 -0700621
622 if (!video)
Patrick Mocheld550d982006-06-27 00:41:40 -0400623 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700624
625 /* Since there is no HID, CID and so on for VGA driver, we have
626 * to check well known required nodes.
627 */
628
629 /* Does this device able to support video switching ? */
Len Brown4be44fc2005-08-05 00:44:28 -0400630 if (video->cap._DOS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700631 video->flags.multihead = 1;
632 status = 0;
633 }
634
635 /* Does this device able to retrieve a retrieve a video ROM ? */
Len Brown4be44fc2005-08-05 00:44:28 -0400636 if (video->cap._ROM) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700637 video->flags.rom = 1;
638 status = 0;
639 }
640
641 /* Does this device able to configure which video device to POST ? */
Len Brown4be44fc2005-08-05 00:44:28 -0400642 if (video->cap._GPD && video->cap._SPD && video->cap._VPO) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700643 video->flags.post = 1;
644 status = 0;
645 }
646
Patrick Mocheld550d982006-06-27 00:41:40 -0400647 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700648}
649
650/* --------------------------------------------------------------------------
651 FS Interface (/proc)
652 -------------------------------------------------------------------------- */
653
Len Brown4be44fc2005-08-05 00:44:28 -0400654static struct proc_dir_entry *acpi_video_dir;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700655
656/* video devices */
657
Len Brown4be44fc2005-08-05 00:44:28 -0400658static int acpi_video_device_info_seq_show(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700659{
Len Brown4be44fc2005-08-05 00:44:28 -0400660 struct acpi_video_device *dev =
661 (struct acpi_video_device *)seq->private;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700662
Linus Torvalds1da177e2005-04-16 15:20:36 -0700663
664 if (!dev)
665 goto end;
666
667 seq_printf(seq, "device_id: 0x%04x\n", (u32) dev->device_id);
668 seq_printf(seq, "type: ");
669 if (dev->flags.crt)
670 seq_printf(seq, "CRT\n");
671 else if (dev->flags.lcd)
672 seq_printf(seq, "LCD\n");
673 else if (dev->flags.tvout)
674 seq_printf(seq, "TVOUT\n");
675 else
676 seq_printf(seq, "UNKNOWN\n");
677
Len Brown4be44fc2005-08-05 00:44:28 -0400678 seq_printf(seq, "known by bios: %s\n", dev->flags.bios ? "yes" : "no");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700679
Len Brown4be44fc2005-08-05 00:44:28 -0400680 end:
Patrick Mocheld550d982006-06-27 00:41:40 -0400681 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700682}
683
684static int
Len Brown4be44fc2005-08-05 00:44:28 -0400685acpi_video_device_info_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700686{
687 return single_open(file, acpi_video_device_info_seq_show,
688 PDE(inode)->data);
689}
690
Len Brown4be44fc2005-08-05 00:44:28 -0400691static int acpi_video_device_state_seq_show(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700692{
Len Brown4be44fc2005-08-05 00:44:28 -0400693 int status;
694 struct acpi_video_device *dev =
695 (struct acpi_video_device *)seq->private;
696 unsigned long state;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700697
Linus Torvalds1da177e2005-04-16 15:20:36 -0700698
699 if (!dev)
700 goto end;
701
702 status = acpi_video_device_get_state(dev, &state);
703 seq_printf(seq, "state: ");
704 if (ACPI_SUCCESS(status))
705 seq_printf(seq, "0x%02lx\n", state);
706 else
707 seq_printf(seq, "<not supported>\n");
708
709 status = acpi_video_device_query(dev, &state);
710 seq_printf(seq, "query: ");
711 if (ACPI_SUCCESS(status))
712 seq_printf(seq, "0x%02lx\n", state);
713 else
714 seq_printf(seq, "<not supported>\n");
715
Len Brown4be44fc2005-08-05 00:44:28 -0400716 end:
Patrick Mocheld550d982006-06-27 00:41:40 -0400717 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700718}
719
720static int
Len Brown4be44fc2005-08-05 00:44:28 -0400721acpi_video_device_state_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700722{
723 return single_open(file, acpi_video_device_state_seq_show,
724 PDE(inode)->data);
725}
726
727static ssize_t
Len Brown4be44fc2005-08-05 00:44:28 -0400728acpi_video_device_write_state(struct file *file,
729 const char __user * buffer,
730 size_t count, loff_t * data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700731{
Len Brown4be44fc2005-08-05 00:44:28 -0400732 int status;
733 struct seq_file *m = (struct seq_file *)file->private_data;
734 struct acpi_video_device *dev = (struct acpi_video_device *)m->private;
735 char str[12] = { 0 };
736 u32 state = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700737
Linus Torvalds1da177e2005-04-16 15:20:36 -0700738
739 if (!dev || count + 1 > sizeof str)
Patrick Mocheld550d982006-06-27 00:41:40 -0400740 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700741
742 if (copy_from_user(str, buffer, count))
Patrick Mocheld550d982006-06-27 00:41:40 -0400743 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700744
745 str[count] = 0;
746 state = simple_strtoul(str, NULL, 0);
Len Brown4be44fc2005-08-05 00:44:28 -0400747 state &= ((1ul << 31) | (1ul << 30) | (1ul << 0));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700748
749 status = acpi_video_device_set_state(dev, state);
750
751 if (status)
Patrick Mocheld550d982006-06-27 00:41:40 -0400752 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700753
Patrick Mocheld550d982006-06-27 00:41:40 -0400754 return count;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700755}
756
757static int
Len Brown4be44fc2005-08-05 00:44:28 -0400758acpi_video_device_brightness_seq_show(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700759{
Len Brown4be44fc2005-08-05 00:44:28 -0400760 struct acpi_video_device *dev =
761 (struct acpi_video_device *)seq->private;
762 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700763
Linus Torvalds1da177e2005-04-16 15:20:36 -0700764
765 if (!dev || !dev->brightness) {
766 seq_printf(seq, "<not supported>\n");
Patrick Mocheld550d982006-06-27 00:41:40 -0400767 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700768 }
769
770 seq_printf(seq, "levels: ");
771 for (i = 0; i < dev->brightness->count; i++)
772 seq_printf(seq, " %d", dev->brightness->levels[i]);
773 seq_printf(seq, "\ncurrent: %d\n", dev->brightness->curr);
774
Patrick Mocheld550d982006-06-27 00:41:40 -0400775 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700776}
777
778static int
Len Brown4be44fc2005-08-05 00:44:28 -0400779acpi_video_device_brightness_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700780{
781 return single_open(file, acpi_video_device_brightness_seq_show,
782 PDE(inode)->data);
783}
784
785static ssize_t
Len Brown4be44fc2005-08-05 00:44:28 -0400786acpi_video_device_write_brightness(struct file *file,
787 const char __user * buffer,
788 size_t count, loff_t * data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700789{
Len Brown4be44fc2005-08-05 00:44:28 -0400790 struct seq_file *m = (struct seq_file *)file->private_data;
791 struct acpi_video_device *dev = (struct acpi_video_device *)m->private;
792 char str[4] = { 0 };
793 unsigned int level = 0;
794 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700795
Linus Torvalds1da177e2005-04-16 15:20:36 -0700796
Thomas Renninger59d399d2005-11-08 05:27:00 -0500797 if (!dev || !dev->brightness || count + 1 > sizeof str)
Patrick Mocheld550d982006-06-27 00:41:40 -0400798 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700799
800 if (copy_from_user(str, buffer, count))
Patrick Mocheld550d982006-06-27 00:41:40 -0400801 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700802
803 str[count] = 0;
804 level = simple_strtoul(str, NULL, 0);
Len Brown4be44fc2005-08-05 00:44:28 -0400805
Linus Torvalds1da177e2005-04-16 15:20:36 -0700806 if (level > 100)
Patrick Mocheld550d982006-06-27 00:41:40 -0400807 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700808
809 /* validate though the list of available levels */
810 for (i = 0; i < dev->brightness->count; i++)
811 if (level == dev->brightness->levels[i]) {
Len Brown4be44fc2005-08-05 00:44:28 -0400812 if (ACPI_SUCCESS
813 (acpi_video_device_lcd_set_level(dev, level)))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700814 dev->brightness->curr = level;
815 break;
816 }
817
Patrick Mocheld550d982006-06-27 00:41:40 -0400818 return count;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700819}
820
Len Brown4be44fc2005-08-05 00:44:28 -0400821static int acpi_video_device_EDID_seq_show(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700822{
Len Brown4be44fc2005-08-05 00:44:28 -0400823 struct acpi_video_device *dev =
824 (struct acpi_video_device *)seq->private;
825 int status;
826 int i;
827 union acpi_object *edid = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700828
Linus Torvalds1da177e2005-04-16 15:20:36 -0700829
830 if (!dev)
831 goto out;
832
Len Brown4be44fc2005-08-05 00:44:28 -0400833 status = acpi_video_device_EDID(dev, &edid, 128);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700834 if (ACPI_FAILURE(status)) {
Len Brown4be44fc2005-08-05 00:44:28 -0400835 status = acpi_video_device_EDID(dev, &edid, 256);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700836 }
837
838 if (ACPI_FAILURE(status)) {
839 goto out;
840 }
841
842 if (edid && edid->type == ACPI_TYPE_BUFFER) {
843 for (i = 0; i < edid->buffer.length; i++)
844 seq_putc(seq, edid->buffer.pointer[i]);
845 }
846
Len Brown4be44fc2005-08-05 00:44:28 -0400847 out:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700848 if (!edid)
849 seq_printf(seq, "<not supported>\n");
850 else
851 kfree(edid);
852
Patrick Mocheld550d982006-06-27 00:41:40 -0400853 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700854}
855
856static int
Len Brown4be44fc2005-08-05 00:44:28 -0400857acpi_video_device_EDID_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700858{
859 return single_open(file, acpi_video_device_EDID_seq_show,
860 PDE(inode)->data);
861}
862
Len Brown4be44fc2005-08-05 00:44:28 -0400863static int acpi_video_device_add_fs(struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700864{
Len Brown4be44fc2005-08-05 00:44:28 -0400865 struct proc_dir_entry *entry = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700866 struct acpi_video_device *vid_dev;
867
Linus Torvalds1da177e2005-04-16 15:20:36 -0700868
869 if (!device)
Patrick Mocheld550d982006-06-27 00:41:40 -0400870 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700871
Len Brown4be44fc2005-08-05 00:44:28 -0400872 vid_dev = (struct acpi_video_device *)acpi_driver_data(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700873 if (!vid_dev)
Patrick Mocheld550d982006-06-27 00:41:40 -0400874 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700875
876 if (!acpi_device_dir(device)) {
877 acpi_device_dir(device) = proc_mkdir(acpi_device_bid(device),
Len Brown4be44fc2005-08-05 00:44:28 -0400878 vid_dev->video->dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700879 if (!acpi_device_dir(device))
Patrick Mocheld550d982006-06-27 00:41:40 -0400880 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700881 acpi_device_dir(device)->owner = THIS_MODULE;
882 }
883
884 /* 'info' [R] */
885 entry = create_proc_entry("info", S_IRUGO, acpi_device_dir(device));
886 if (!entry)
Patrick Mocheld550d982006-06-27 00:41:40 -0400887 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700888 else {
889 entry->proc_fops = &acpi_video_device_info_fops;
890 entry->data = acpi_driver_data(device);
891 entry->owner = THIS_MODULE;
892 }
893
894 /* 'state' [R/W] */
Len Brown4be44fc2005-08-05 00:44:28 -0400895 entry =
896 create_proc_entry("state", S_IFREG | S_IRUGO | S_IWUSR,
897 acpi_device_dir(device));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700898 if (!entry)
Patrick Mocheld550d982006-06-27 00:41:40 -0400899 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700900 else {
Arjan van de Vend479e902006-01-06 16:47:00 -0500901 acpi_video_device_state_fops.write = acpi_video_device_write_state;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700902 entry->proc_fops = &acpi_video_device_state_fops;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700903 entry->data = acpi_driver_data(device);
904 entry->owner = THIS_MODULE;
905 }
906
907 /* 'brightness' [R/W] */
Len Brown4be44fc2005-08-05 00:44:28 -0400908 entry =
909 create_proc_entry("brightness", S_IFREG | S_IRUGO | S_IWUSR,
910 acpi_device_dir(device));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700911 if (!entry)
Patrick Mocheld550d982006-06-27 00:41:40 -0400912 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700913 else {
Arjan van de Vend479e902006-01-06 16:47:00 -0500914 acpi_video_device_brightness_fops.write = acpi_video_device_write_brightness;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700915 entry->proc_fops = &acpi_video_device_brightness_fops;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700916 entry->data = acpi_driver_data(device);
917 entry->owner = THIS_MODULE;
918 }
919
920 /* 'EDID' [R] */
921 entry = create_proc_entry("EDID", S_IRUGO, acpi_device_dir(device));
922 if (!entry)
Patrick Mocheld550d982006-06-27 00:41:40 -0400923 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700924 else {
925 entry->proc_fops = &acpi_video_device_EDID_fops;
926 entry->data = acpi_driver_data(device);
927 entry->owner = THIS_MODULE;
928 }
929
Patrick Mocheld550d982006-06-27 00:41:40 -0400930 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700931}
932
Len Brown4be44fc2005-08-05 00:44:28 -0400933static int acpi_video_device_remove_fs(struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700934{
935 struct acpi_video_device *vid_dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700936
Len Brown4be44fc2005-08-05 00:44:28 -0400937 vid_dev = (struct acpi_video_device *)acpi_driver_data(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700938 if (!vid_dev || !vid_dev->video || !vid_dev->video->dir)
Patrick Mocheld550d982006-06-27 00:41:40 -0400939 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700940
941 if (acpi_device_dir(device)) {
942 remove_proc_entry("info", acpi_device_dir(device));
943 remove_proc_entry("state", acpi_device_dir(device));
944 remove_proc_entry("brightness", acpi_device_dir(device));
945 remove_proc_entry("EDID", acpi_device_dir(device));
Len Brown4be44fc2005-08-05 00:44:28 -0400946 remove_proc_entry(acpi_device_bid(device), vid_dev->video->dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700947 acpi_device_dir(device) = NULL;
948 }
949
Patrick Mocheld550d982006-06-27 00:41:40 -0400950 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700951}
952
Linus Torvalds1da177e2005-04-16 15:20:36 -0700953/* video bus */
Len Brown4be44fc2005-08-05 00:44:28 -0400954static int acpi_video_bus_info_seq_show(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700955{
Len Brown4be44fc2005-08-05 00:44:28 -0400956 struct acpi_video_bus *video = (struct acpi_video_bus *)seq->private;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700957
Linus Torvalds1da177e2005-04-16 15:20:36 -0700958
959 if (!video)
960 goto end;
961
962 seq_printf(seq, "Switching heads: %s\n",
Len Brown4be44fc2005-08-05 00:44:28 -0400963 video->flags.multihead ? "yes" : "no");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700964 seq_printf(seq, "Video ROM: %s\n",
Len Brown4be44fc2005-08-05 00:44:28 -0400965 video->flags.rom ? "yes" : "no");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700966 seq_printf(seq, "Device to be POSTed on boot: %s\n",
Len Brown4be44fc2005-08-05 00:44:28 -0400967 video->flags.post ? "yes" : "no");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700968
Len Brown4be44fc2005-08-05 00:44:28 -0400969 end:
Patrick Mocheld550d982006-06-27 00:41:40 -0400970 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700971}
972
Len Brown4be44fc2005-08-05 00:44:28 -0400973static int acpi_video_bus_info_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700974{
Len Brown4be44fc2005-08-05 00:44:28 -0400975 return single_open(file, acpi_video_bus_info_seq_show,
976 PDE(inode)->data);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700977}
978
Len Brown4be44fc2005-08-05 00:44:28 -0400979static int acpi_video_bus_ROM_seq_show(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700980{
Len Brown4be44fc2005-08-05 00:44:28 -0400981 struct acpi_video_bus *video = (struct acpi_video_bus *)seq->private;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700982
Linus Torvalds1da177e2005-04-16 15:20:36 -0700983
984 if (!video)
985 goto end;
986
987 printk(KERN_INFO PREFIX "Please implement %s\n", __FUNCTION__);
988 seq_printf(seq, "<TODO>\n");
989
Len Brown4be44fc2005-08-05 00:44:28 -0400990 end:
Patrick Mocheld550d982006-06-27 00:41:40 -0400991 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700992}
993
Len Brown4be44fc2005-08-05 00:44:28 -0400994static int acpi_video_bus_ROM_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700995{
996 return single_open(file, acpi_video_bus_ROM_seq_show, PDE(inode)->data);
997}
998
Len Brown4be44fc2005-08-05 00:44:28 -0400999static int acpi_video_bus_POST_info_seq_show(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001000{
Len Brown4be44fc2005-08-05 00:44:28 -04001001 struct acpi_video_bus *video = (struct acpi_video_bus *)seq->private;
1002 unsigned long options;
1003 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001004
Linus Torvalds1da177e2005-04-16 15:20:36 -07001005
1006 if (!video)
1007 goto end;
1008
1009 status = acpi_video_bus_POST_options(video, &options);
1010 if (ACPI_SUCCESS(status)) {
1011 if (!(options & 1)) {
Len Brown4be44fc2005-08-05 00:44:28 -04001012 printk(KERN_WARNING PREFIX
1013 "The motherboard VGA device is not listed as a possible POST device.\n");
1014 printk(KERN_WARNING PREFIX
1015 "This indicate a BIOS bug. Please contact the manufacturer.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001016 }
1017 printk("%lx\n", options);
1018 seq_printf(seq, "can POST: <intgrated video>");
1019 if (options & 2)
1020 seq_printf(seq, " <PCI video>");
1021 if (options & 4)
1022 seq_printf(seq, " <AGP video>");
1023 seq_putc(seq, '\n');
1024 } else
1025 seq_printf(seq, "<not supported>\n");
Len Brown4be44fc2005-08-05 00:44:28 -04001026 end:
Patrick Mocheld550d982006-06-27 00:41:40 -04001027 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001028}
1029
1030static int
Len Brown4be44fc2005-08-05 00:44:28 -04001031acpi_video_bus_POST_info_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001032{
Len Brown4be44fc2005-08-05 00:44:28 -04001033 return single_open(file, acpi_video_bus_POST_info_seq_show,
1034 PDE(inode)->data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001035}
1036
Len Brown4be44fc2005-08-05 00:44:28 -04001037static int acpi_video_bus_POST_seq_show(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001038{
Len Brown4be44fc2005-08-05 00:44:28 -04001039 struct acpi_video_bus *video = (struct acpi_video_bus *)seq->private;
1040 int status;
1041 unsigned long id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001042
Linus Torvalds1da177e2005-04-16 15:20:36 -07001043
1044 if (!video)
1045 goto end;
1046
Len Brown4be44fc2005-08-05 00:44:28 -04001047 status = acpi_video_bus_get_POST(video, &id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001048 if (!ACPI_SUCCESS(status)) {
1049 seq_printf(seq, "<not supported>\n");
1050 goto end;
1051 }
Len Brown4be44fc2005-08-05 00:44:28 -04001052 seq_printf(seq, "device posted is <%s>\n", device_decode[id & 3]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001053
Len Brown4be44fc2005-08-05 00:44:28 -04001054 end:
Patrick Mocheld550d982006-06-27 00:41:40 -04001055 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001056}
1057
Len Brown4be44fc2005-08-05 00:44:28 -04001058static int acpi_video_bus_DOS_seq_show(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001059{
Len Brown4be44fc2005-08-05 00:44:28 -04001060 struct acpi_video_bus *video = (struct acpi_video_bus *)seq->private;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001061
Linus Torvalds1da177e2005-04-16 15:20:36 -07001062
Len Brown4be44fc2005-08-05 00:44:28 -04001063 seq_printf(seq, "DOS setting: <%d>\n", video->dos_setting);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001064
Patrick Mocheld550d982006-06-27 00:41:40 -04001065 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001066}
1067
Len Brown4be44fc2005-08-05 00:44:28 -04001068static int acpi_video_bus_POST_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001069{
Len Brown4be44fc2005-08-05 00:44:28 -04001070 return single_open(file, acpi_video_bus_POST_seq_show,
1071 PDE(inode)->data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001072}
1073
Len Brown4be44fc2005-08-05 00:44:28 -04001074static int acpi_video_bus_DOS_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001075{
1076 return single_open(file, acpi_video_bus_DOS_seq_show, PDE(inode)->data);
1077}
1078
1079static ssize_t
Len Brown4be44fc2005-08-05 00:44:28 -04001080acpi_video_bus_write_POST(struct file *file,
1081 const char __user * buffer,
1082 size_t count, loff_t * data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001083{
Len Brown4be44fc2005-08-05 00:44:28 -04001084 int status;
1085 struct seq_file *m = (struct seq_file *)file->private_data;
1086 struct acpi_video_bus *video = (struct acpi_video_bus *)m->private;
1087 char str[12] = { 0 };
1088 unsigned long opt, options;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001089
Linus Torvalds1da177e2005-04-16 15:20:36 -07001090
Linus Torvalds1da177e2005-04-16 15:20:36 -07001091 if (!video || count + 1 > sizeof str)
Patrick Mocheld550d982006-06-27 00:41:40 -04001092 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001093
1094 status = acpi_video_bus_POST_options(video, &options);
1095 if (!ACPI_SUCCESS(status))
Patrick Mocheld550d982006-06-27 00:41:40 -04001096 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001097
1098 if (copy_from_user(str, buffer, count))
Patrick Mocheld550d982006-06-27 00:41:40 -04001099 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001100
1101 str[count] = 0;
1102 opt = strtoul(str, NULL, 0);
1103 if (opt > 3)
Patrick Mocheld550d982006-06-27 00:41:40 -04001104 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001105
1106 /* just in case an OEM 'forget' the motherboard... */
1107 options |= 1;
1108
1109 if (options & (1ul << opt)) {
Len Brown4be44fc2005-08-05 00:44:28 -04001110 status = acpi_video_bus_set_POST(video, opt);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001111 if (!ACPI_SUCCESS(status))
Patrick Mocheld550d982006-06-27 00:41:40 -04001112 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001113
1114 }
1115
Patrick Mocheld550d982006-06-27 00:41:40 -04001116 return count;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001117}
1118
1119static ssize_t
Len Brown4be44fc2005-08-05 00:44:28 -04001120acpi_video_bus_write_DOS(struct file *file,
1121 const char __user * buffer,
1122 size_t count, loff_t * data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001123{
Len Brown4be44fc2005-08-05 00:44:28 -04001124 int status;
1125 struct seq_file *m = (struct seq_file *)file->private_data;
1126 struct acpi_video_bus *video = (struct acpi_video_bus *)m->private;
1127 char str[12] = { 0 };
1128 unsigned long opt;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001129
Linus Torvalds1da177e2005-04-16 15:20:36 -07001130
Linus Torvalds1da177e2005-04-16 15:20:36 -07001131 if (!video || count + 1 > sizeof str)
Patrick Mocheld550d982006-06-27 00:41:40 -04001132 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001133
1134 if (copy_from_user(str, buffer, count))
Patrick Mocheld550d982006-06-27 00:41:40 -04001135 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001136
1137 str[count] = 0;
1138 opt = strtoul(str, NULL, 0);
1139 if (opt > 7)
Patrick Mocheld550d982006-06-27 00:41:40 -04001140 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001141
Len Brown4be44fc2005-08-05 00:44:28 -04001142 status = acpi_video_bus_DOS(video, opt & 0x3, (opt & 0x4) >> 2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001143
1144 if (!ACPI_SUCCESS(status))
Patrick Mocheld550d982006-06-27 00:41:40 -04001145 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001146
Patrick Mocheld550d982006-06-27 00:41:40 -04001147 return count;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001148}
1149
Len Brown4be44fc2005-08-05 00:44:28 -04001150static int acpi_video_bus_add_fs(struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001151{
Len Brown4be44fc2005-08-05 00:44:28 -04001152 struct proc_dir_entry *entry = NULL;
1153 struct acpi_video_bus *video;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001154
Linus Torvalds1da177e2005-04-16 15:20:36 -07001155
Len Brown4be44fc2005-08-05 00:44:28 -04001156 video = (struct acpi_video_bus *)acpi_driver_data(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001157
1158 if (!acpi_device_dir(device)) {
1159 acpi_device_dir(device) = proc_mkdir(acpi_device_bid(device),
Len Brown4be44fc2005-08-05 00:44:28 -04001160 acpi_video_dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001161 if (!acpi_device_dir(device))
Patrick Mocheld550d982006-06-27 00:41:40 -04001162 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001163 video->dir = acpi_device_dir(device);
1164 acpi_device_dir(device)->owner = THIS_MODULE;
1165 }
1166
1167 /* 'info' [R] */
1168 entry = create_proc_entry("info", S_IRUGO, acpi_device_dir(device));
1169 if (!entry)
Patrick Mocheld550d982006-06-27 00:41:40 -04001170 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001171 else {
1172 entry->proc_fops = &acpi_video_bus_info_fops;
1173 entry->data = acpi_driver_data(device);
1174 entry->owner = THIS_MODULE;
1175 }
1176
1177 /* 'ROM' [R] */
1178 entry = create_proc_entry("ROM", S_IRUGO, acpi_device_dir(device));
1179 if (!entry)
Patrick Mocheld550d982006-06-27 00:41:40 -04001180 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001181 else {
1182 entry->proc_fops = &acpi_video_bus_ROM_fops;
1183 entry->data = acpi_driver_data(device);
1184 entry->owner = THIS_MODULE;
1185 }
1186
1187 /* 'POST_info' [R] */
Len Brown4be44fc2005-08-05 00:44:28 -04001188 entry =
1189 create_proc_entry("POST_info", S_IRUGO, acpi_device_dir(device));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001190 if (!entry)
Patrick Mocheld550d982006-06-27 00:41:40 -04001191 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001192 else {
1193 entry->proc_fops = &acpi_video_bus_POST_info_fops;
1194 entry->data = acpi_driver_data(device);
1195 entry->owner = THIS_MODULE;
1196 }
1197
1198 /* 'POST' [R/W] */
Len Brown4be44fc2005-08-05 00:44:28 -04001199 entry =
1200 create_proc_entry("POST", S_IFREG | S_IRUGO | S_IRUSR,
1201 acpi_device_dir(device));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001202 if (!entry)
Patrick Mocheld550d982006-06-27 00:41:40 -04001203 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001204 else {
Arjan van de Vend479e902006-01-06 16:47:00 -05001205 acpi_video_bus_POST_fops.write = acpi_video_bus_write_POST;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001206 entry->proc_fops = &acpi_video_bus_POST_fops;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001207 entry->data = acpi_driver_data(device);
1208 entry->owner = THIS_MODULE;
1209 }
1210
1211 /* 'DOS' [R/W] */
Len Brown4be44fc2005-08-05 00:44:28 -04001212 entry =
1213 create_proc_entry("DOS", S_IFREG | S_IRUGO | S_IRUSR,
1214 acpi_device_dir(device));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001215 if (!entry)
Patrick Mocheld550d982006-06-27 00:41:40 -04001216 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001217 else {
Arjan van de Vend479e902006-01-06 16:47:00 -05001218 acpi_video_bus_DOS_fops.write = acpi_video_bus_write_DOS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001219 entry->proc_fops = &acpi_video_bus_DOS_fops;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001220 entry->data = acpi_driver_data(device);
1221 entry->owner = THIS_MODULE;
1222 }
1223
Patrick Mocheld550d982006-06-27 00:41:40 -04001224 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001225}
1226
Len Brown4be44fc2005-08-05 00:44:28 -04001227static int acpi_video_bus_remove_fs(struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001228{
Len Brown4be44fc2005-08-05 00:44:28 -04001229 struct acpi_video_bus *video;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001230
Linus Torvalds1da177e2005-04-16 15:20:36 -07001231
Len Brown4be44fc2005-08-05 00:44:28 -04001232 video = (struct acpi_video_bus *)acpi_driver_data(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001233
1234 if (acpi_device_dir(device)) {
1235 remove_proc_entry("info", acpi_device_dir(device));
1236 remove_proc_entry("ROM", acpi_device_dir(device));
1237 remove_proc_entry("POST_info", acpi_device_dir(device));
1238 remove_proc_entry("POST", acpi_device_dir(device));
1239 remove_proc_entry("DOS", acpi_device_dir(device));
Len Brown4be44fc2005-08-05 00:44:28 -04001240 remove_proc_entry(acpi_device_bid(device), acpi_video_dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001241 acpi_device_dir(device) = NULL;
1242 }
1243
Patrick Mocheld550d982006-06-27 00:41:40 -04001244 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001245}
1246
1247/* --------------------------------------------------------------------------
1248 Driver Interface
1249 -------------------------------------------------------------------------- */
1250
1251/* device interface */
1252
1253static int
Len Brown4be44fc2005-08-05 00:44:28 -04001254acpi_video_bus_get_one_device(struct acpi_device *device,
1255 struct acpi_video_bus *video)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001256{
Len Brown4be44fc2005-08-05 00:44:28 -04001257 unsigned long device_id;
Yu, Luming973bf492006-04-27 05:25:00 -04001258 int status;
Len Brown4be44fc2005-08-05 00:44:28 -04001259 struct acpi_video_device *data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001260
Linus Torvalds1da177e2005-04-16 15:20:36 -07001261
1262 if (!device || !video)
Patrick Mocheld550d982006-06-27 00:41:40 -04001263 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001264
Len Brown4be44fc2005-08-05 00:44:28 -04001265 status =
1266 acpi_evaluate_integer(device->handle, "_ADR", NULL, &device_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001267 if (ACPI_SUCCESS(status)) {
1268
1269 data = kmalloc(sizeof(struct acpi_video_device), GFP_KERNEL);
1270 if (!data)
Patrick Mocheld550d982006-06-27 00:41:40 -04001271 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001272
1273 memset(data, 0, sizeof(struct acpi_video_device));
1274
1275 data->handle = device->handle;
1276 strcpy(acpi_device_name(device), ACPI_VIDEO_DEVICE_NAME);
1277 strcpy(acpi_device_class(device), ACPI_VIDEO_CLASS);
1278 acpi_driver_data(device) = data;
1279
1280 data->device_id = device_id;
1281 data->video = video;
1282 data->dev = device;
1283
1284 switch (device_id & 0xffff) {
1285 case 0x0100:
1286 data->flags.crt = 1;
1287 break;
1288 case 0x0400:
1289 data->flags.lcd = 1;
1290 break;
1291 case 0x0200:
1292 data->flags.tvout = 1;
1293 break;
1294 default:
1295 data->flags.unknown = 1;
1296 break;
1297 }
Len Brown4be44fc2005-08-05 00:44:28 -04001298
Linus Torvalds1da177e2005-04-16 15:20:36 -07001299 acpi_video_device_bind(video, data);
1300 acpi_video_device_find_cap(data);
1301
1302 status = acpi_install_notify_handler(data->handle,
Len Brown4be44fc2005-08-05 00:44:28 -04001303 ACPI_DEVICE_NOTIFY,
1304 acpi_video_device_notify,
1305 data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001306 if (ACPI_FAILURE(status)) {
1307 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
Len Brown4be44fc2005-08-05 00:44:28 -04001308 "Error installing notify handler\n"));
Yu, Luming973bf492006-04-27 05:25:00 -04001309 if(data->brightness)
1310 kfree(data->brightness->levels);
1311 kfree(data->brightness);
1312 kfree(data);
1313 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001314 }
1315
1316 down(&video->sem);
1317 list_add_tail(&data->entry, &video->video_device_list);
1318 up(&video->sem);
1319
1320 acpi_video_device_add_fs(device);
1321
Patrick Mocheld550d982006-06-27 00:41:40 -04001322 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001323 }
1324
Patrick Mocheld550d982006-06-27 00:41:40 -04001325 return -ENOENT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001326}
1327
1328/*
1329 * Arg:
1330 * video : video bus device
1331 *
1332 * Return:
1333 * none
1334 *
1335 * Enumerate the video device list of the video bus,
1336 * bind the ids with the corresponding video devices
1337 * under the video bus.
Len Brown4be44fc2005-08-05 00:44:28 -04001338 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001339
Len Brown4be44fc2005-08-05 00:44:28 -04001340static void acpi_video_device_rebind(struct acpi_video_bus *video)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001341{
Len Brown4be44fc2005-08-05 00:44:28 -04001342 struct list_head *node, *next;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001343 list_for_each_safe(node, next, &video->video_device_list) {
Len Brown4be44fc2005-08-05 00:44:28 -04001344 struct acpi_video_device *dev =
1345 container_of(node, struct acpi_video_device, entry);
1346 acpi_video_device_bind(video, dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001347 }
1348}
1349
1350/*
1351 * Arg:
1352 * video : video bus device
1353 * device : video output device under the video
1354 * bus
1355 *
1356 * Return:
1357 * none
1358 *
1359 * Bind the ids with the corresponding video devices
1360 * under the video bus.
Len Brown4be44fc2005-08-05 00:44:28 -04001361 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001362
1363static void
Len Brown4be44fc2005-08-05 00:44:28 -04001364acpi_video_device_bind(struct acpi_video_bus *video,
1365 struct acpi_video_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001366{
Len Brown4be44fc2005-08-05 00:44:28 -04001367 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001368
1369#define IDS_VAL(i) video->attached_array[i].value.int_val
1370#define IDS_BIND(i) video->attached_array[i].bind_info
Len Brown4be44fc2005-08-05 00:44:28 -04001371
1372 for (i = 0; IDS_VAL(i) != ACPI_VIDEO_HEAD_INVALID &&
1373 i < video->attached_count; i++) {
1374 if (device->device_id == (IDS_VAL(i) & 0xffff)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001375 IDS_BIND(i) = device;
1376 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "device_bind %d\n", i));
1377 }
1378 }
1379#undef IDS_VAL
1380#undef IDS_BIND
1381}
1382
1383/*
1384 * Arg:
1385 * video : video bus device
1386 *
1387 * Return:
1388 * < 0 : error
1389 *
1390 * Call _DOD to enumerate all devices attached to display adapter
1391 *
Len Brown4be44fc2005-08-05 00:44:28 -04001392 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001393
1394static int acpi_video_device_enumerate(struct acpi_video_bus *video)
1395{
Len Brown4be44fc2005-08-05 00:44:28 -04001396 int status;
1397 int count;
1398 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001399 struct acpi_video_enumerated_device *active_device_list;
Len Brown4be44fc2005-08-05 00:44:28 -04001400 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
1401 union acpi_object *dod = NULL;
1402 union acpi_object *obj;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001403
Linus Torvalds1da177e2005-04-16 15:20:36 -07001404
1405 status = acpi_evaluate_object(video->handle, "_DOD", NULL, &buffer);
1406 if (!ACPI_SUCCESS(status)) {
Thomas Renningera6fc6722006-06-26 23:58:43 -04001407 ACPI_EXCEPTION((AE_INFO, status, "Evaluating _DOD"));
Patrick Mocheld550d982006-06-27 00:41:40 -04001408 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001409 }
1410
Len Brown4be44fc2005-08-05 00:44:28 -04001411 dod = (union acpi_object *)buffer.pointer;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001412 if (!dod || (dod->type != ACPI_TYPE_PACKAGE)) {
Thomas Renningera6fc6722006-06-26 23:58:43 -04001413 ACPI_EXCEPTION((AE_INFO, status, "Invalid _DOD data"));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001414 status = -EFAULT;
1415 goto out;
1416 }
1417
1418 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found %d video heads in _DOD\n",
Len Brown4be44fc2005-08-05 00:44:28 -04001419 dod->package.count));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001420
Len Brown4be44fc2005-08-05 00:44:28 -04001421 active_device_list = kmalloc((1 +
1422 dod->package.count) *
1423 sizeof(struct
1424 acpi_video_enumerated_device),
1425 GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001426
1427 if (!active_device_list) {
1428 status = -ENOMEM;
1429 goto out;
1430 }
1431
1432 count = 0;
1433 for (i = 0; i < dod->package.count; i++) {
Len Brown4be44fc2005-08-05 00:44:28 -04001434 obj = (union acpi_object *)&dod->package.elements[i];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001435
1436 if (obj->type != ACPI_TYPE_INTEGER) {
Len Brown64684632006-06-26 23:41:38 -04001437 printk(KERN_ERR PREFIX "Invalid _DOD data\n");
Len Brown4be44fc2005-08-05 00:44:28 -04001438 active_device_list[i].value.int_val =
1439 ACPI_VIDEO_HEAD_INVALID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001440 }
1441 active_device_list[i].value.int_val = obj->integer.value;
1442 active_device_list[i].bind_info = NULL;
Len Brown4be44fc2005-08-05 00:44:28 -04001443 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "dod element[%d] = %d\n", i,
1444 (int)obj->integer.value));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001445 count++;
1446 }
1447 active_device_list[count].value.int_val = ACPI_VIDEO_HEAD_END;
1448
Jesper Juhl6044ec82005-11-07 01:01:32 -08001449 kfree(video->attached_array);
Len Brown4be44fc2005-08-05 00:44:28 -04001450
Linus Torvalds1da177e2005-04-16 15:20:36 -07001451 video->attached_array = active_device_list;
1452 video->attached_count = count;
Len Brown4be44fc2005-08-05 00:44:28 -04001453 out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001454 acpi_os_free(buffer.pointer);
Patrick Mocheld550d982006-06-27 00:41:40 -04001455 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001456}
1457
1458/*
1459 * Arg:
1460 * video : video bus device
1461 * event : Nontify Event
1462 *
1463 * Return:
1464 * < 0 : error
1465 *
1466 * 1. Find out the current active output device.
1467 * 2. Identify the next output device to switch
1468 * 3. call _DSS to do actual switch.
Len Brown4be44fc2005-08-05 00:44:28 -04001469 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001470
Len Brown4be44fc2005-08-05 00:44:28 -04001471static int acpi_video_switch_output(struct acpi_video_bus *video, int event)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001472{
Len Brown4be44fc2005-08-05 00:44:28 -04001473 struct list_head *node, *next;
1474 struct acpi_video_device *dev = NULL;
1475 struct acpi_video_device *dev_next = NULL;
1476 struct acpi_video_device *dev_prev = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001477 unsigned long state;
1478 int status = 0;
1479
Linus Torvalds1da177e2005-04-16 15:20:36 -07001480
1481 list_for_each_safe(node, next, &video->video_device_list) {
Adrian Bunk73345712005-03-30 22:31:35 -05001482 dev = container_of(node, struct acpi_video_device, entry);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001483 status = acpi_video_device_get_state(dev, &state);
Len Brown4be44fc2005-08-05 00:44:28 -04001484 if (state & 0x2) {
1485 dev_next =
1486 container_of(node->next, struct acpi_video_device,
1487 entry);
1488 dev_prev =
1489 container_of(node->prev, struct acpi_video_device,
1490 entry);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001491 goto out;
1492 }
1493 }
1494 dev_next = container_of(node->next, struct acpi_video_device, entry);
1495 dev_prev = container_of(node->prev, struct acpi_video_device, entry);
Len Brown4be44fc2005-08-05 00:44:28 -04001496 out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001497 switch (event) {
1498 case ACPI_VIDEO_NOTIFY_CYCLE:
1499 case ACPI_VIDEO_NOTIFY_NEXT_OUTPUT:
1500 acpi_video_device_set_state(dev, 0);
1501 acpi_video_device_set_state(dev_next, 0x80000001);
1502 break;
1503 case ACPI_VIDEO_NOTIFY_PREV_OUTPUT:
1504 acpi_video_device_set_state(dev, 0);
1505 acpi_video_device_set_state(dev_prev, 0x80000001);
1506 default:
1507 break;
1508 }
1509
Patrick Mocheld550d982006-06-27 00:41:40 -04001510 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001511}
1512
Len Brown4be44fc2005-08-05 00:44:28 -04001513static int
1514acpi_video_get_next_level(struct acpi_video_device *device,
1515 u32 level_current, u32 event)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001516{
Len Brown4be44fc2005-08-05 00:44:28 -04001517 /*Fix me */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001518 return level_current;
1519}
1520
Linus Torvalds1da177e2005-04-16 15:20:36 -07001521static void
Len Brown4be44fc2005-08-05 00:44:28 -04001522acpi_video_switch_brightness(struct acpi_video_device *device, int event)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001523{
1524 unsigned long level_current, level_next;
1525 acpi_video_device_lcd_get_level_current(device, &level_current);
1526 level_next = acpi_video_get_next_level(device, level_current, event);
1527 acpi_video_device_lcd_set_level(device, level_next);
1528}
1529
1530static int
Len Brown4be44fc2005-08-05 00:44:28 -04001531acpi_video_bus_get_devices(struct acpi_video_bus *video,
1532 struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001533{
Len Brown4be44fc2005-08-05 00:44:28 -04001534 int status = 0;
1535 struct list_head *node, *next;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001536
Linus Torvalds1da177e2005-04-16 15:20:36 -07001537
1538 acpi_video_device_enumerate(video);
1539
1540 list_for_each_safe(node, next, &device->children) {
Len Brown4be44fc2005-08-05 00:44:28 -04001541 struct acpi_device *dev =
1542 list_entry(node, struct acpi_device, node);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001543
1544 if (!dev)
1545 continue;
1546
1547 status = acpi_video_bus_get_one_device(dev, video);
1548 if (ACPI_FAILURE(status)) {
Thomas Renningera6fc6722006-06-26 23:58:43 -04001549 ACPI_EXCEPTION((AE_INFO, status, "Cant attach device"));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001550 continue;
1551 }
1552
1553 }
Patrick Mocheld550d982006-06-27 00:41:40 -04001554 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001555}
1556
Len Brown4be44fc2005-08-05 00:44:28 -04001557static int acpi_video_bus_put_one_device(struct acpi_video_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001558{
Karol Kozimor031ec772005-07-30 04:18:00 -04001559 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001560 struct acpi_video_bus *video;
1561
Linus Torvalds1da177e2005-04-16 15:20:36 -07001562
1563 if (!device || !device->video)
Patrick Mocheld550d982006-06-27 00:41:40 -04001564 return -ENOENT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001565
1566 video = device->video;
1567
1568 down(&video->sem);
1569 list_del(&device->entry);
1570 up(&video->sem);
1571 acpi_video_device_remove_fs(device->dev);
1572
Karol Kozimor031ec772005-07-30 04:18:00 -04001573 status = acpi_remove_notify_handler(device->handle,
Len Brown4be44fc2005-08-05 00:44:28 -04001574 ACPI_DEVICE_NOTIFY,
1575 acpi_video_device_notify);
Karol Kozimor031ec772005-07-30 04:18:00 -04001576
Patrick Mocheld550d982006-06-27 00:41:40 -04001577 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001578}
1579
Len Brown4be44fc2005-08-05 00:44:28 -04001580static int acpi_video_bus_put_devices(struct acpi_video_bus *video)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001581{
Len Brown4be44fc2005-08-05 00:44:28 -04001582 int status;
1583 struct list_head *node, *next;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001584
Linus Torvalds1da177e2005-04-16 15:20:36 -07001585
1586 list_for_each_safe(node, next, &video->video_device_list) {
Len Brown4be44fc2005-08-05 00:44:28 -04001587 struct acpi_video_device *data =
1588 list_entry(node, struct acpi_video_device, entry);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001589 if (!data)
1590 continue;
1591
1592 status = acpi_video_bus_put_one_device(data);
Len Brown4be44fc2005-08-05 00:44:28 -04001593 if (ACPI_FAILURE(status))
1594 printk(KERN_WARNING PREFIX
1595 "hhuuhhuu bug in acpi video driver.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001596
Dave Jonesd384ea62006-06-24 00:33:08 -04001597 if (data->brightness)
Yu, Luming973bf492006-04-27 05:25:00 -04001598 kfree(data->brightness->levels);
Jesper Juhl6044ec82005-11-07 01:01:32 -08001599 kfree(data->brightness);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001600 kfree(data);
1601 }
1602
Patrick Mocheld550d982006-06-27 00:41:40 -04001603 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001604}
1605
1606/* acpi_video interface */
1607
Len Brown4be44fc2005-08-05 00:44:28 -04001608static int acpi_video_bus_start_devices(struct acpi_video_bus *video)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001609{
1610 return acpi_video_bus_DOS(video, 1, 0);
1611}
1612
Len Brown4be44fc2005-08-05 00:44:28 -04001613static int acpi_video_bus_stop_devices(struct acpi_video_bus *video)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001614{
1615 return acpi_video_bus_DOS(video, 0, 1);
1616}
1617
Len Brown4be44fc2005-08-05 00:44:28 -04001618static void acpi_video_bus_notify(acpi_handle handle, u32 event, void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001619{
Len Brown4be44fc2005-08-05 00:44:28 -04001620 struct acpi_video_bus *video = (struct acpi_video_bus *)data;
1621 struct acpi_device *device = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001622
Linus Torvalds1da177e2005-04-16 15:20:36 -07001623 printk("video bus notify\n");
1624
1625 if (!video)
Patrick Mocheld550d982006-06-27 00:41:40 -04001626 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001627
Patrick Mochele6afa0d2006-05-19 16:54:40 -04001628 device = video->device;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001629
1630 switch (event) {
1631 case ACPI_VIDEO_NOTIFY_SWITCH: /* User request that a switch occur,
1632 * most likely via hotkey. */
1633 acpi_bus_generate_event(device, event, 0);
1634 break;
1635
1636 case ACPI_VIDEO_NOTIFY_PROBE: /* User plug or remove a video
1637 * connector. */
1638 acpi_video_device_enumerate(video);
1639 acpi_video_device_rebind(video);
1640 acpi_video_switch_output(video, event);
1641 acpi_bus_generate_event(device, event, 0);
1642 break;
1643
Len Brown4be44fc2005-08-05 00:44:28 -04001644 case ACPI_VIDEO_NOTIFY_CYCLE: /* Cycle Display output hotkey pressed. */
1645 case ACPI_VIDEO_NOTIFY_NEXT_OUTPUT: /* Next Display output hotkey pressed. */
1646 case ACPI_VIDEO_NOTIFY_PREV_OUTPUT: /* previous Display output hotkey pressed. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001647 acpi_video_switch_output(video, event);
1648 acpi_bus_generate_event(device, event, 0);
1649 break;
1650
1651 default:
1652 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
Len Brown4be44fc2005-08-05 00:44:28 -04001653 "Unsupported event [0x%x]\n", event));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001654 break;
1655 }
1656
Patrick Mocheld550d982006-06-27 00:41:40 -04001657 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001658}
1659
Len Brown4be44fc2005-08-05 00:44:28 -04001660static void acpi_video_device_notify(acpi_handle handle, u32 event, void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001661{
Len Brown4be44fc2005-08-05 00:44:28 -04001662 struct acpi_video_device *video_device =
1663 (struct acpi_video_device *)data;
1664 struct acpi_device *device = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001665
Linus Torvalds1da177e2005-04-16 15:20:36 -07001666
1667 printk("video device notify\n");
1668 if (!video_device)
Patrick Mocheld550d982006-06-27 00:41:40 -04001669 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001670
Patrick Mochele6afa0d2006-05-19 16:54:40 -04001671 device = video_device->dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001672
1673 switch (event) {
Len Brown4be44fc2005-08-05 00:44:28 -04001674 case ACPI_VIDEO_NOTIFY_SWITCH: /* change in status (cycle output device) */
1675 case ACPI_VIDEO_NOTIFY_PROBE: /* change in status (output device status) */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001676 acpi_bus_generate_event(device, event, 0);
1677 break;
Len Brown4be44fc2005-08-05 00:44:28 -04001678 case ACPI_VIDEO_NOTIFY_CYCLE_BRIGHTNESS: /* Cycle brightness */
1679 case ACPI_VIDEO_NOTIFY_INC_BRIGHTNESS: /* Increase brightness */
1680 case ACPI_VIDEO_NOTIFY_DEC_BRIGHTNESS: /* Decrease brightness */
1681 case ACPI_VIDEO_NOTIFY_ZERO_BRIGHTNESS: /* zero brightnesss */
1682 case ACPI_VIDEO_NOTIFY_DISPLAY_OFF: /* display device off */
1683 acpi_video_switch_brightness(video_device, event);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001684 acpi_bus_generate_event(device, event, 0);
1685 break;
1686 default:
1687 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
Len Brown4be44fc2005-08-05 00:44:28 -04001688 "Unsupported event [0x%x]\n", event));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001689 break;
1690 }
Patrick Mocheld550d982006-06-27 00:41:40 -04001691 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001692}
1693
Len Brown4be44fc2005-08-05 00:44:28 -04001694static int acpi_video_bus_add(struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001695{
Len Brown4be44fc2005-08-05 00:44:28 -04001696 int result = 0;
1697 acpi_status status = 0;
1698 struct acpi_video_bus *video = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001699
Len Brown4be44fc2005-08-05 00:44:28 -04001700
Linus Torvalds1da177e2005-04-16 15:20:36 -07001701 if (!device)
Patrick Mocheld550d982006-06-27 00:41:40 -04001702 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001703
1704 video = kmalloc(sizeof(struct acpi_video_bus), GFP_KERNEL);
1705 if (!video)
Patrick Mocheld550d982006-06-27 00:41:40 -04001706 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001707 memset(video, 0, sizeof(struct acpi_video_bus));
1708
1709 video->handle = device->handle;
Patrick Mochele6afa0d2006-05-19 16:54:40 -04001710 video->device = device;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001711 strcpy(acpi_device_name(device), ACPI_VIDEO_BUS_NAME);
1712 strcpy(acpi_device_class(device), ACPI_VIDEO_CLASS);
1713 acpi_driver_data(device) = video;
1714
1715 acpi_video_bus_find_cap(video);
1716 result = acpi_video_bus_check(video);
1717 if (result)
1718 goto end;
1719
1720 result = acpi_video_bus_add_fs(device);
1721 if (result)
1722 goto end;
1723
1724 init_MUTEX(&video->sem);
1725 INIT_LIST_HEAD(&video->video_device_list);
1726
1727 acpi_video_bus_get_devices(video, device);
1728 acpi_video_bus_start_devices(video);
1729
1730 status = acpi_install_notify_handler(video->handle,
Len Brown4be44fc2005-08-05 00:44:28 -04001731 ACPI_DEVICE_NOTIFY,
1732 acpi_video_bus_notify, video);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001733 if (ACPI_FAILURE(status)) {
1734 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
Len Brown4be44fc2005-08-05 00:44:28 -04001735 "Error installing notify handler\n"));
Yu, Luming973bf492006-04-27 05:25:00 -04001736 acpi_video_bus_stop_devices(video);
1737 acpi_video_bus_put_devices(video);
1738 kfree(video->attached_array);
1739 acpi_video_bus_remove_fs(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001740 result = -ENODEV;
1741 goto end;
1742 }
1743
1744 printk(KERN_INFO PREFIX "%s [%s] (multi-head: %s rom: %s post: %s)\n",
Len Brown4be44fc2005-08-05 00:44:28 -04001745 ACPI_VIDEO_DEVICE_NAME, acpi_device_bid(device),
1746 video->flags.multihead ? "yes" : "no",
1747 video->flags.rom ? "yes" : "no",
1748 video->flags.post ? "yes" : "no");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001749
Len Brown4be44fc2005-08-05 00:44:28 -04001750 end:
Yu, Luming973bf492006-04-27 05:25:00 -04001751 if (result)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001752 kfree(video);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001753
Patrick Mocheld550d982006-06-27 00:41:40 -04001754 return result;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001755}
1756
Len Brown4be44fc2005-08-05 00:44:28 -04001757static int acpi_video_bus_remove(struct acpi_device *device, int type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001758{
Len Brown4be44fc2005-08-05 00:44:28 -04001759 acpi_status status = 0;
1760 struct acpi_video_bus *video = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001761
Linus Torvalds1da177e2005-04-16 15:20:36 -07001762
1763 if (!device || !acpi_driver_data(device))
Patrick Mocheld550d982006-06-27 00:41:40 -04001764 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001765
Len Brown4be44fc2005-08-05 00:44:28 -04001766 video = (struct acpi_video_bus *)acpi_driver_data(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001767
1768 acpi_video_bus_stop_devices(video);
1769
1770 status = acpi_remove_notify_handler(video->handle,
Len Brown4be44fc2005-08-05 00:44:28 -04001771 ACPI_DEVICE_NOTIFY,
1772 acpi_video_bus_notify);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001773
1774 acpi_video_bus_put_devices(video);
1775 acpi_video_bus_remove_fs(device);
1776
Jesper Juhl6044ec82005-11-07 01:01:32 -08001777 kfree(video->attached_array);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001778 kfree(video);
1779
Patrick Mocheld550d982006-06-27 00:41:40 -04001780 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001781}
1782
Linus Torvalds1da177e2005-04-16 15:20:36 -07001783static int
Len Brown4be44fc2005-08-05 00:44:28 -04001784acpi_video_bus_match(struct acpi_device *device, struct acpi_driver *driver)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001785{
Len Brown4be44fc2005-08-05 00:44:28 -04001786 acpi_handle h_dummy1;
1787 acpi_handle h_dummy2;
1788 acpi_handle h_dummy3;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001789
Linus Torvalds1da177e2005-04-16 15:20:36 -07001790
1791 if (!device || !driver)
Patrick Mocheld550d982006-06-27 00:41:40 -04001792 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001793
1794 /* Since there is no HID, CID for ACPI Video drivers, we have
1795 * to check well known required nodes for each feature we support.
1796 */
1797
1798 /* Does this device able to support video switching ? */
1799 if (ACPI_SUCCESS(acpi_get_handle(device->handle, "_DOD", &h_dummy1)) &&
1800 ACPI_SUCCESS(acpi_get_handle(device->handle, "_DOS", &h_dummy2)))
Patrick Mocheld550d982006-06-27 00:41:40 -04001801 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001802
1803 /* Does this device able to retrieve a video ROM ? */
1804 if (ACPI_SUCCESS(acpi_get_handle(device->handle, "_ROM", &h_dummy1)))
Patrick Mocheld550d982006-06-27 00:41:40 -04001805 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001806
1807 /* Does this device able to configure which video head to be POSTed ? */
1808 if (ACPI_SUCCESS(acpi_get_handle(device->handle, "_VPO", &h_dummy1)) &&
1809 ACPI_SUCCESS(acpi_get_handle(device->handle, "_GPD", &h_dummy2)) &&
1810 ACPI_SUCCESS(acpi_get_handle(device->handle, "_SPD", &h_dummy3)))
Patrick Mocheld550d982006-06-27 00:41:40 -04001811 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001812
Patrick Mocheld550d982006-06-27 00:41:40 -04001813 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001814}
1815
Len Brown4be44fc2005-08-05 00:44:28 -04001816static int __init acpi_video_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001817{
Len Brown4be44fc2005-08-05 00:44:28 -04001818 int result = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001819
Linus Torvalds1da177e2005-04-16 15:20:36 -07001820
1821 /*
Len Brown4be44fc2005-08-05 00:44:28 -04001822 acpi_dbg_level = 0xFFFFFFFF;
1823 acpi_dbg_layer = 0x08000000;
1824 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001825
1826 acpi_video_dir = proc_mkdir(ACPI_VIDEO_CLASS, acpi_root_dir);
1827 if (!acpi_video_dir)
Patrick Mocheld550d982006-06-27 00:41:40 -04001828 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001829 acpi_video_dir->owner = THIS_MODULE;
1830
1831 result = acpi_bus_register_driver(&acpi_video_bus);
1832 if (result < 0) {
1833 remove_proc_entry(ACPI_VIDEO_CLASS, acpi_root_dir);
Patrick Mocheld550d982006-06-27 00:41:40 -04001834 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001835 }
1836
Patrick Mocheld550d982006-06-27 00:41:40 -04001837 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001838}
1839
Len Brown4be44fc2005-08-05 00:44:28 -04001840static void __exit acpi_video_exit(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001841{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001842
1843 acpi_bus_unregister_driver(&acpi_video_bus);
1844
1845 remove_proc_entry(ACPI_VIDEO_CLASS, acpi_root_dir);
1846
Patrick Mocheld550d982006-06-27 00:41:40 -04001847 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001848}
1849
1850module_init(acpi_video_init);
1851module_exit(acpi_video_exit);