blob: 9200a46c38bdda5eeb2f2af0bd69dc0ecfb0f883 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * video.c - ACPI Video Driver ($Revision:$)
3 *
4 * Copyright (C) 2004 Luming Yu <luming.yu@intel.com>
5 * Copyright (C) 2004 Bruno Ducrot <ducrot@poupinou.org>
Thomas Tuttlef4715182006-12-19 12:56:14 -08006 * Copyright (C) 2006 Thomas Tuttle <linux-kernel@ttuttle.net>
Linus Torvalds1da177e2005-04-16 15:20:36 -07007 *
8 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or (at
13 * your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful, but
16 * WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License along
21 * with this program; if not, write to the Free Software Foundation, Inc.,
22 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
23 *
24 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
25 */
26
27#include <linux/kernel.h>
28#include <linux/module.h>
29#include <linux/init.h>
30#include <linux/types.h>
31#include <linux/list.h>
32#include <linux/proc_fs.h>
33#include <linux/seq_file.h>
34
35#include <asm/uaccess.h>
36
37#include <acpi/acpi_bus.h>
38#include <acpi/acpi_drivers.h>
39
40#define ACPI_VIDEO_COMPONENT 0x08000000
41#define ACPI_VIDEO_CLASS "video"
42#define ACPI_VIDEO_DRIVER_NAME "ACPI Video Driver"
43#define ACPI_VIDEO_BUS_NAME "Video Bus"
44#define ACPI_VIDEO_DEVICE_NAME "Video Device"
45#define ACPI_VIDEO_NOTIFY_SWITCH 0x80
46#define ACPI_VIDEO_NOTIFY_PROBE 0x81
47#define ACPI_VIDEO_NOTIFY_CYCLE 0x82
48#define ACPI_VIDEO_NOTIFY_NEXT_OUTPUT 0x83
49#define ACPI_VIDEO_NOTIFY_PREV_OUTPUT 0x84
50
Thomas Tuttlef4715182006-12-19 12:56:14 -080051#define ACPI_VIDEO_NOTIFY_CYCLE_BRIGHTNESS 0x85
52#define ACPI_VIDEO_NOTIFY_INC_BRIGHTNESS 0x86
53#define ACPI_VIDEO_NOTIFY_DEC_BRIGHTNESS 0x87
54#define ACPI_VIDEO_NOTIFY_ZERO_BRIGHTNESS 0x88
55#define ACPI_VIDEO_NOTIFY_DISPLAY_OFF 0x89
Linus Torvalds1da177e2005-04-16 15:20:36 -070056
Linus Torvalds1da177e2005-04-16 15:20:36 -070057#define ACPI_VIDEO_HEAD_INVALID (~0u - 1)
58#define ACPI_VIDEO_HEAD_END (~0u)
59
Linus Torvalds1da177e2005-04-16 15:20:36 -070060#define _COMPONENT ACPI_VIDEO_COMPONENT
Len Brown4be44fc2005-08-05 00:44:28 -040061ACPI_MODULE_NAME("acpi_video")
Linus Torvalds1da177e2005-04-16 15:20:36 -070062
Len Brown4be44fc2005-08-05 00:44:28 -040063 MODULE_AUTHOR("Bruno Ducrot");
Linus Torvalds1da177e2005-04-16 15:20:36 -070064MODULE_DESCRIPTION(ACPI_VIDEO_DRIVER_NAME);
65MODULE_LICENSE("GPL");
66
Len Brown4be44fc2005-08-05 00:44:28 -040067static int acpi_video_bus_add(struct acpi_device *device);
68static int acpi_video_bus_remove(struct acpi_device *device, int type);
69static int acpi_video_bus_match(struct acpi_device *device,
70 struct acpi_driver *driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -070071
72static struct acpi_driver acpi_video_bus = {
73 .name = ACPI_VIDEO_DRIVER_NAME,
74 .class = ACPI_VIDEO_CLASS,
75 .ops = {
76 .add = acpi_video_bus_add,
77 .remove = acpi_video_bus_remove,
78 .match = acpi_video_bus_match,
Len Brown4be44fc2005-08-05 00:44:28 -040079 },
Linus Torvalds1da177e2005-04-16 15:20:36 -070080};
81
82struct acpi_video_bus_flags {
Len Brown4be44fc2005-08-05 00:44:28 -040083 u8 multihead:1; /* can switch video heads */
84 u8 rom:1; /* can retrieve a video rom */
85 u8 post:1; /* can configure the head to */
86 u8 reserved:5;
Linus Torvalds1da177e2005-04-16 15:20:36 -070087};
88
89struct acpi_video_bus_cap {
Len Brown4be44fc2005-08-05 00:44:28 -040090 u8 _DOS:1; /*Enable/Disable output switching */
91 u8 _DOD:1; /*Enumerate all devices attached to display adapter */
92 u8 _ROM:1; /*Get ROM Data */
93 u8 _GPD:1; /*Get POST Device */
94 u8 _SPD:1; /*Set POST Device */
95 u8 _VPO:1; /*Video POST Options */
96 u8 reserved:2;
Linus Torvalds1da177e2005-04-16 15:20:36 -070097};
98
Len Brown4be44fc2005-08-05 00:44:28 -040099struct acpi_video_device_attrib {
100 u32 display_index:4; /* A zero-based instance of the Display */
101 u32 display_port_attachment:4; /*This field differenates displays type */
102 u32 display_type:4; /*Describe the specific type in use */
103 u32 vendor_specific:4; /*Chipset Vendor Specifi */
104 u32 bios_can_detect:1; /*BIOS can detect the device */
105 u32 depend_on_vga:1; /*Non-VGA output device whose power is related to
106 the VGA device. */
107 u32 pipe_id:3; /*For VGA multiple-head devices. */
108 u32 reserved:10; /*Must be 0 */
109 u32 device_id_scheme:1; /*Device ID Scheme */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110};
111
112struct acpi_video_enumerated_device {
113 union {
114 u32 int_val;
Len Brown4be44fc2005-08-05 00:44:28 -0400115 struct acpi_video_device_attrib attrib;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116 } value;
117 struct acpi_video_device *bind_info;
118};
119
120struct acpi_video_bus {
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 unsigned long device_id;
160 struct acpi_video_device_flags flags;
161 struct acpi_video_device_cap cap;
162 struct list_head entry;
163 struct acpi_video_bus *video;
164 struct acpi_device *dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700165 struct acpi_video_device_brightness *brightness;
166};
167
Linus Torvalds1da177e2005-04-16 15:20:36 -0700168/* bus */
169static int acpi_video_bus_info_open_fs(struct inode *inode, struct file *file);
170static struct file_operations acpi_video_bus_info_fops = {
Len Brown4be44fc2005-08-05 00:44:28 -0400171 .open = acpi_video_bus_info_open_fs,
172 .read = seq_read,
173 .llseek = seq_lseek,
174 .release = single_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700175};
176
177static int acpi_video_bus_ROM_open_fs(struct inode *inode, struct file *file);
178static struct file_operations acpi_video_bus_ROM_fops = {
Len Brown4be44fc2005-08-05 00:44:28 -0400179 .open = acpi_video_bus_ROM_open_fs,
180 .read = seq_read,
181 .llseek = seq_lseek,
182 .release = single_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700183};
184
Len Brown4be44fc2005-08-05 00:44:28 -0400185static int acpi_video_bus_POST_info_open_fs(struct inode *inode,
186 struct file *file);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700187static struct file_operations acpi_video_bus_POST_info_fops = {
Len Brown4be44fc2005-08-05 00:44:28 -0400188 .open = acpi_video_bus_POST_info_open_fs,
189 .read = seq_read,
190 .llseek = seq_lseek,
191 .release = single_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700192};
193
194static int acpi_video_bus_POST_open_fs(struct inode *inode, struct file *file);
195static struct file_operations acpi_video_bus_POST_fops = {
Len Brown4be44fc2005-08-05 00:44:28 -0400196 .open = acpi_video_bus_POST_open_fs,
197 .read = seq_read,
198 .llseek = seq_lseek,
199 .release = single_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700200};
201
Linus Torvalds1da177e2005-04-16 15:20:36 -0700202static int acpi_video_bus_DOS_open_fs(struct inode *inode, struct file *file);
203static struct file_operations acpi_video_bus_DOS_fops = {
Len Brown4be44fc2005-08-05 00:44:28 -0400204 .open = acpi_video_bus_DOS_open_fs,
205 .read = seq_read,
206 .llseek = seq_lseek,
207 .release = single_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700208};
209
210/* device */
Len Brown4be44fc2005-08-05 00:44:28 -0400211static int acpi_video_device_info_open_fs(struct inode *inode,
212 struct file *file);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700213static struct file_operations acpi_video_device_info_fops = {
Len Brown4be44fc2005-08-05 00:44:28 -0400214 .open = acpi_video_device_info_open_fs,
215 .read = seq_read,
216 .llseek = seq_lseek,
217 .release = single_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700218};
219
Len Brown4be44fc2005-08-05 00:44:28 -0400220static int acpi_video_device_state_open_fs(struct inode *inode,
221 struct file *file);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700222static struct file_operations acpi_video_device_state_fops = {
Len Brown4be44fc2005-08-05 00:44:28 -0400223 .open = acpi_video_device_state_open_fs,
224 .read = seq_read,
225 .llseek = seq_lseek,
226 .release = single_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700227};
228
Len Brown4be44fc2005-08-05 00:44:28 -0400229static int acpi_video_device_brightness_open_fs(struct inode *inode,
230 struct file *file);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700231static struct file_operations acpi_video_device_brightness_fops = {
Len Brown4be44fc2005-08-05 00:44:28 -0400232 .open = acpi_video_device_brightness_open_fs,
233 .read = seq_read,
234 .llseek = seq_lseek,
235 .release = single_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700236};
237
Len Brown4be44fc2005-08-05 00:44:28 -0400238static int acpi_video_device_EDID_open_fs(struct inode *inode,
239 struct file *file);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700240static struct file_operations acpi_video_device_EDID_fops = {
Len Brown4be44fc2005-08-05 00:44:28 -0400241 .open = acpi_video_device_EDID_open_fs,
242 .read = seq_read,
243 .llseek = seq_lseek,
244 .release = single_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700245};
246
Len Brown4be44fc2005-08-05 00:44:28 -0400247static char device_decode[][30] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700248 "motherboard VGA device",
249 "PCI VGA device",
250 "AGP VGA device",
251 "UNKNOWN",
252};
253
Len Brown4be44fc2005-08-05 00:44:28 -0400254static void acpi_video_device_notify(acpi_handle handle, u32 event, void *data);
255static void acpi_video_device_rebind(struct acpi_video_bus *video);
256static void acpi_video_device_bind(struct acpi_video_bus *video,
257 struct acpi_video_device *device);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700258static int acpi_video_device_enumerate(struct acpi_video_bus *video);
Len Brown4be44fc2005-08-05 00:44:28 -0400259static int acpi_video_switch_output(struct acpi_video_bus *video, int event);
260static int acpi_video_get_next_level(struct acpi_video_device *device,
261 u32 level_current, u32 event);
262static void acpi_video_switch_brightness(struct acpi_video_device *device,
263 int event);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700264
265/* --------------------------------------------------------------------------
266 Video Management
267 -------------------------------------------------------------------------- */
268
269/* device */
270
271static int
Len Brown4be44fc2005-08-05 00:44:28 -0400272acpi_video_device_query(struct acpi_video_device *device, unsigned long *state)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700273{
Len Brown4be44fc2005-08-05 00:44:28 -0400274 int status;
Patrick Mochel90130262006-05-19 16:54:48 -0400275
276 status = acpi_evaluate_integer(device->dev->handle, "_DGS", NULL, state);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700277
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
Patrick Mochel90130262006-05-19 16:54:48 -0400287 status = acpi_evaluate_integer(device->dev->handle, "_DCS", NULL, state);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700288
Patrick Mocheld550d982006-06-27 00:41:40 -0400289 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700290}
291
292static int
Len Brown4be44fc2005-08-05 00:44:28 -0400293acpi_video_device_set_state(struct acpi_video_device *device, int state)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700294{
Len Brown4be44fc2005-08-05 00:44:28 -0400295 int status;
296 union acpi_object arg0 = { ACPI_TYPE_INTEGER };
297 struct acpi_object_list args = { 1, &arg0 };
Luming Yu824b5582005-08-21 19:17:00 -0400298 unsigned long ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700299
Linus Torvalds1da177e2005-04-16 15:20:36 -0700300
301 arg0.integer.value = state;
Patrick Mochel90130262006-05-19 16:54:48 -0400302 status = acpi_evaluate_integer(device->dev->handle, "_DSS", &args, &ret);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700303
Patrick Mocheld550d982006-06-27 00:41:40 -0400304 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700305}
306
307static int
Len Brown4be44fc2005-08-05 00:44:28 -0400308acpi_video_device_lcd_query_levels(struct acpi_video_device *device,
309 union acpi_object **levels)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700310{
Len Brown4be44fc2005-08-05 00:44:28 -0400311 int status;
312 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
313 union acpi_object *obj;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700314
Linus Torvalds1da177e2005-04-16 15:20:36 -0700315
316 *levels = NULL;
317
Patrick Mochel90130262006-05-19 16:54:48 -0400318 status = acpi_evaluate_object(device->dev->handle, "_BCL", NULL, &buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700319 if (!ACPI_SUCCESS(status))
Patrick Mocheld550d982006-06-27 00:41:40 -0400320 return status;
Len Brown4be44fc2005-08-05 00:44:28 -0400321 obj = (union acpi_object *)buffer.pointer;
Adrian Bunk6665bda2006-03-11 10:12:00 -0500322 if (!obj || (obj->type != ACPI_TYPE_PACKAGE)) {
Len Brown64684632006-06-26 23:41:38 -0400323 printk(KERN_ERR PREFIX "Invalid _BCL data\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700324 status = -EFAULT;
325 goto err;
326 }
327
328 *levels = obj;
329
Patrick Mocheld550d982006-06-27 00:41:40 -0400330 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700331
Len Brown4be44fc2005-08-05 00:44:28 -0400332 err:
Jesper Juhl6044ec82005-11-07 01:01:32 -0800333 kfree(buffer.pointer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700334
Patrick Mocheld550d982006-06-27 00:41:40 -0400335 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700336}
337
338static int
Len Brown4be44fc2005-08-05 00:44:28 -0400339acpi_video_device_lcd_set_level(struct acpi_video_device *device, int level)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700340{
Len Brown4be44fc2005-08-05 00:44:28 -0400341 int status;
342 union acpi_object arg0 = { ACPI_TYPE_INTEGER };
343 struct acpi_object_list args = { 1, &arg0 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700344
Linus Torvalds1da177e2005-04-16 15:20:36 -0700345
346 arg0.integer.value = level;
Patrick Mochel90130262006-05-19 16:54:48 -0400347 status = acpi_evaluate_object(device->dev->handle, "_BCM", &args, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700348
349 printk(KERN_DEBUG "set_level status: %x\n", status);
Patrick Mocheld550d982006-06-27 00:41:40 -0400350 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700351}
352
353static int
Len Brown4be44fc2005-08-05 00:44:28 -0400354acpi_video_device_lcd_get_level_current(struct acpi_video_device *device,
355 unsigned long *level)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700356{
Len Brown4be44fc2005-08-05 00:44:28 -0400357 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700358
Patrick Mochel90130262006-05-19 16:54:48 -0400359 status = acpi_evaluate_integer(device->dev->handle, "_BQC", NULL, level);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700360
Patrick Mocheld550d982006-06-27 00:41:40 -0400361 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700362}
363
364static int
Len Brown4be44fc2005-08-05 00:44:28 -0400365acpi_video_device_EDID(struct acpi_video_device *device,
366 union acpi_object **edid, ssize_t length)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700367{
Len Brown4be44fc2005-08-05 00:44:28 -0400368 int status;
369 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
370 union acpi_object *obj;
371 union acpi_object arg0 = { ACPI_TYPE_INTEGER };
372 struct acpi_object_list args = { 1, &arg0 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700373
Linus Torvalds1da177e2005-04-16 15:20:36 -0700374
375 *edid = NULL;
376
377 if (!device)
Patrick Mocheld550d982006-06-27 00:41:40 -0400378 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700379 if (length == 128)
380 arg0.integer.value = 1;
381 else if (length == 256)
382 arg0.integer.value = 2;
383 else
Patrick Mocheld550d982006-06-27 00:41:40 -0400384 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700385
Patrick Mochel90130262006-05-19 16:54:48 -0400386 status = acpi_evaluate_object(device->dev->handle, "_DDC", &args, &buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700387 if (ACPI_FAILURE(status))
Patrick Mocheld550d982006-06-27 00:41:40 -0400388 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700389
Len Brown4be44fc2005-08-05 00:44:28 -0400390 obj = (union acpi_object *)buffer.pointer;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700391
392 if (obj && obj->type == ACPI_TYPE_BUFFER)
393 *edid = obj;
394 else {
Len Brown64684632006-06-26 23:41:38 -0400395 printk(KERN_ERR PREFIX "Invalid _DDC data\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700396 status = -EFAULT;
397 kfree(obj);
398 }
399
Patrick Mocheld550d982006-06-27 00:41:40 -0400400 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700401}
402
Linus Torvalds1da177e2005-04-16 15:20:36 -0700403/* bus */
404
405static int
Len Brown4be44fc2005-08-05 00:44:28 -0400406acpi_video_bus_set_POST(struct acpi_video_bus *video, unsigned long option)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700407{
Len Brown4be44fc2005-08-05 00:44:28 -0400408 int status;
409 unsigned long tmp;
410 union acpi_object arg0 = { ACPI_TYPE_INTEGER };
411 struct acpi_object_list args = { 1, &arg0 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700412
Linus Torvalds1da177e2005-04-16 15:20:36 -0700413
414 arg0.integer.value = option;
415
Patrick Mochel90130262006-05-19 16:54:48 -0400416 status = acpi_evaluate_integer(video->device->handle, "_SPD", &args, &tmp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700417 if (ACPI_SUCCESS(status))
Len Brown4be44fc2005-08-05 00:44:28 -0400418 status = tmp ? (-EINVAL) : (AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700419
Patrick Mocheld550d982006-06-27 00:41:40 -0400420 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700421}
422
423static int
Len Brown4be44fc2005-08-05 00:44:28 -0400424acpi_video_bus_get_POST(struct acpi_video_bus *video, unsigned long *id)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700425{
426 int status;
427
Patrick Mochel90130262006-05-19 16:54:48 -0400428 status = acpi_evaluate_integer(video->device->handle, "_GPD", NULL, id);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700429
Patrick Mocheld550d982006-06-27 00:41:40 -0400430 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700431}
432
433static int
Len Brown4be44fc2005-08-05 00:44:28 -0400434acpi_video_bus_POST_options(struct acpi_video_bus *video,
435 unsigned long *options)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700436{
Len Brown4be44fc2005-08-05 00:44:28 -0400437 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700438
Patrick Mochel90130262006-05-19 16:54:48 -0400439 status = acpi_evaluate_integer(video->device->handle, "_VPO", NULL, options);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700440 *options &= 3;
441
Patrick Mocheld550d982006-06-27 00:41:40 -0400442 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700443}
444
445/*
446 * Arg:
447 * video : video bus device pointer
448 * bios_flag :
449 * 0. The system BIOS should NOT automatically switch(toggle)
450 * the active display output.
451 * 1. The system BIOS should automatically switch (toggle) the
452 * active display output. No swich event.
453 * 2. The _DGS value should be locked.
454 * 3. The system BIOS should not automatically switch (toggle) the
455 * active display output, but instead generate the display switch
456 * event notify code.
457 * lcd_flag :
458 * 0. The system BIOS should automatically control the brightness level
459 * of the LCD, when the power changes from AC to DC
460 * 1. The system BIOS should NOT automatically control the brightness
461 * level of the LCD, when the power changes from AC to DC.
462 * Return Value:
463 * -1 wrong arg.
464 */
465
466static int
Len Brown4be44fc2005-08-05 00:44:28 -0400467acpi_video_bus_DOS(struct acpi_video_bus *video, int bios_flag, int lcd_flag)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700468{
Len Brown4be44fc2005-08-05 00:44:28 -0400469 acpi_integer status = 0;
470 union acpi_object arg0 = { ACPI_TYPE_INTEGER };
471 struct acpi_object_list args = { 1, &arg0 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700472
Linus Torvalds1da177e2005-04-16 15:20:36 -0700473
Len Brown4be44fc2005-08-05 00:44:28 -0400474 if (bios_flag < 0 || bios_flag > 3 || lcd_flag < 0 || lcd_flag > 1) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700475 status = -1;
476 goto Failed;
477 }
478 arg0.integer.value = (lcd_flag << 2) | bios_flag;
479 video->dos_setting = arg0.integer.value;
Patrick Mochel90130262006-05-19 16:54:48 -0400480 acpi_evaluate_object(video->device->handle, "_DOS", &args, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700481
Len Brown4be44fc2005-08-05 00:44:28 -0400482 Failed:
Patrick Mocheld550d982006-06-27 00:41:40 -0400483 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700484}
485
486/*
487 * Arg:
488 * device : video output device (LCD, CRT, ..)
489 *
490 * Return Value:
491 * None
492 *
493 * Find out all required AML method defined under the output
494 * device.
495 */
496
Len Brown4be44fc2005-08-05 00:44:28 -0400497static void acpi_video_device_find_cap(struct acpi_video_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700498{
Len Brown4be44fc2005-08-05 00:44:28 -0400499 acpi_integer status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700500 acpi_handle h_dummy1;
501 int i;
502 union acpi_object *obj = NULL;
503 struct acpi_video_device_brightness *br = NULL;
504
Linus Torvalds1da177e2005-04-16 15:20:36 -0700505
Len Brown4be44fc2005-08-05 00:44:28 -0400506 memset(&device->cap, 0, 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700507
Patrick Mochel90130262006-05-19 16:54:48 -0400508 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_ADR", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700509 device->cap._ADR = 1;
510 }
Patrick Mochel90130262006-05-19 16:54:48 -0400511 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_BCL", &h_dummy1))) {
Len Brown4be44fc2005-08-05 00:44:28 -0400512 device->cap._BCL = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700513 }
Patrick Mochel90130262006-05-19 16:54:48 -0400514 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_BCM", &h_dummy1))) {
Len Brown4be44fc2005-08-05 00:44:28 -0400515 device->cap._BCM = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700516 }
Patrick Mochel90130262006-05-19 16:54:48 -0400517 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_DDC", &h_dummy1))) {
Len Brown4be44fc2005-08-05 00:44:28 -0400518 device->cap._DDC = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700519 }
Patrick Mochel90130262006-05-19 16:54:48 -0400520 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_DCS", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700521 device->cap._DCS = 1;
522 }
Patrick Mochel90130262006-05-19 16:54:48 -0400523 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_DGS", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700524 device->cap._DGS = 1;
525 }
Patrick Mochel90130262006-05-19 16:54:48 -0400526 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_DSS", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700527 device->cap._DSS = 1;
528 }
529
530 status = acpi_video_device_lcd_query_levels(device, &obj);
531
532 if (obj && obj->type == ACPI_TYPE_PACKAGE && obj->package.count >= 2) {
533 int count = 0;
534 union acpi_object *o;
Len Brown4be44fc2005-08-05 00:44:28 -0400535
Paulo Marquesd1dd0c22005-03-30 22:39:49 -0500536 br = kmalloc(sizeof(*br), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700537 if (!br) {
538 printk(KERN_ERR "can't allocate memory\n");
539 } else {
Paulo Marquesd1dd0c22005-03-30 22:39:49 -0500540 memset(br, 0, sizeof(*br));
541 br->levels = kmalloc(obj->package.count *
Len Brown4be44fc2005-08-05 00:44:28 -0400542 sizeof *(br->levels), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700543 if (!br->levels)
544 goto out;
545
546 for (i = 0; i < obj->package.count; i++) {
Len Brown4be44fc2005-08-05 00:44:28 -0400547 o = (union acpi_object *)&obj->package.
548 elements[i];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700549 if (o->type != ACPI_TYPE_INTEGER) {
Len Brown64684632006-06-26 23:41:38 -0400550 printk(KERN_ERR PREFIX "Invalid data\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700551 continue;
552 }
553 br->levels[count] = (u32) o->integer.value;
554 count++;
555 }
Len Brown4be44fc2005-08-05 00:44:28 -0400556 out:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700557 if (count < 2) {
Paulo Marquesd1dd0c22005-03-30 22:39:49 -0500558 kfree(br->levels);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700559 kfree(br);
560 } else {
561 br->count = count;
562 device->brightness = br;
Len Brown4be44fc2005-08-05 00:44:28 -0400563 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
564 "found %d brightness levels\n",
565 count));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700566 }
567 }
568 }
569
Paulo Marquesd1dd0c22005-03-30 22:39:49 -0500570 kfree(obj);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700571
Patrick Mocheld550d982006-06-27 00:41:40 -0400572 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700573}
574
575/*
576 * Arg:
577 * device : video output device (VGA)
578 *
579 * Return Value:
580 * None
581 *
582 * Find out all required AML method defined under the video bus device.
583 */
584
Len Brown4be44fc2005-08-05 00:44:28 -0400585static void acpi_video_bus_find_cap(struct acpi_video_bus *video)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700586{
Len Brown4be44fc2005-08-05 00:44:28 -0400587 acpi_handle h_dummy1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700588
Len Brown4be44fc2005-08-05 00:44:28 -0400589 memset(&video->cap, 0, 4);
Patrick Mochel90130262006-05-19 16:54:48 -0400590 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_DOS", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700591 video->cap._DOS = 1;
592 }
Patrick Mochel90130262006-05-19 16:54:48 -0400593 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_DOD", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700594 video->cap._DOD = 1;
595 }
Patrick Mochel90130262006-05-19 16:54:48 -0400596 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_ROM", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700597 video->cap._ROM = 1;
598 }
Patrick Mochel90130262006-05-19 16:54:48 -0400599 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_GPD", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700600 video->cap._GPD = 1;
601 }
Patrick Mochel90130262006-05-19 16:54:48 -0400602 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_SPD", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700603 video->cap._SPD = 1;
604 }
Patrick Mochel90130262006-05-19 16:54:48 -0400605 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_VPO", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700606 video->cap._VPO = 1;
607 }
608}
609
610/*
611 * Check whether the video bus device has required AML method to
612 * support the desired features
613 */
614
Len Brown4be44fc2005-08-05 00:44:28 -0400615static int acpi_video_bus_check(struct acpi_video_bus *video)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700616{
Len Brown4be44fc2005-08-05 00:44:28 -0400617 acpi_status status = -ENOENT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700618
Linus Torvalds1da177e2005-04-16 15:20:36 -0700619
620 if (!video)
Patrick Mocheld550d982006-06-27 00:41:40 -0400621 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700622
623 /* Since there is no HID, CID and so on for VGA driver, we have
624 * to check well known required nodes.
625 */
626
627 /* Does this device able to support video switching ? */
Len Brown4be44fc2005-08-05 00:44:28 -0400628 if (video->cap._DOS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700629 video->flags.multihead = 1;
630 status = 0;
631 }
632
633 /* Does this device able to retrieve a retrieve a video ROM ? */
Len Brown4be44fc2005-08-05 00:44:28 -0400634 if (video->cap._ROM) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700635 video->flags.rom = 1;
636 status = 0;
637 }
638
639 /* Does this device able to configure which video device to POST ? */
Len Brown4be44fc2005-08-05 00:44:28 -0400640 if (video->cap._GPD && video->cap._SPD && video->cap._VPO) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700641 video->flags.post = 1;
642 status = 0;
643 }
644
Patrick Mocheld550d982006-06-27 00:41:40 -0400645 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700646}
647
648/* --------------------------------------------------------------------------
649 FS Interface (/proc)
650 -------------------------------------------------------------------------- */
651
Len Brown4be44fc2005-08-05 00:44:28 -0400652static struct proc_dir_entry *acpi_video_dir;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700653
654/* video devices */
655
Len Brown4be44fc2005-08-05 00:44:28 -0400656static int acpi_video_device_info_seq_show(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700657{
Len Brown4be44fc2005-08-05 00:44:28 -0400658 struct acpi_video_device *dev =
659 (struct acpi_video_device *)seq->private;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700660
Linus Torvalds1da177e2005-04-16 15:20:36 -0700661
662 if (!dev)
663 goto end;
664
665 seq_printf(seq, "device_id: 0x%04x\n", (u32) dev->device_id);
666 seq_printf(seq, "type: ");
667 if (dev->flags.crt)
668 seq_printf(seq, "CRT\n");
669 else if (dev->flags.lcd)
670 seq_printf(seq, "LCD\n");
671 else if (dev->flags.tvout)
672 seq_printf(seq, "TVOUT\n");
673 else
674 seq_printf(seq, "UNKNOWN\n");
675
Len Brown4be44fc2005-08-05 00:44:28 -0400676 seq_printf(seq, "known by bios: %s\n", dev->flags.bios ? "yes" : "no");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700677
Len Brown4be44fc2005-08-05 00:44:28 -0400678 end:
Patrick Mocheld550d982006-06-27 00:41:40 -0400679 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700680}
681
682static int
Len Brown4be44fc2005-08-05 00:44:28 -0400683acpi_video_device_info_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700684{
685 return single_open(file, acpi_video_device_info_seq_show,
686 PDE(inode)->data);
687}
688
Len Brown4be44fc2005-08-05 00:44:28 -0400689static int acpi_video_device_state_seq_show(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700690{
Len Brown4be44fc2005-08-05 00:44:28 -0400691 int status;
692 struct acpi_video_device *dev =
693 (struct acpi_video_device *)seq->private;
694 unsigned long state;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700695
Linus Torvalds1da177e2005-04-16 15:20:36 -0700696
697 if (!dev)
698 goto end;
699
700 status = acpi_video_device_get_state(dev, &state);
701 seq_printf(seq, "state: ");
702 if (ACPI_SUCCESS(status))
703 seq_printf(seq, "0x%02lx\n", state);
704 else
705 seq_printf(seq, "<not supported>\n");
706
707 status = acpi_video_device_query(dev, &state);
708 seq_printf(seq, "query: ");
709 if (ACPI_SUCCESS(status))
710 seq_printf(seq, "0x%02lx\n", state);
711 else
712 seq_printf(seq, "<not supported>\n");
713
Len Brown4be44fc2005-08-05 00:44:28 -0400714 end:
Patrick Mocheld550d982006-06-27 00:41:40 -0400715 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700716}
717
718static int
Len Brown4be44fc2005-08-05 00:44:28 -0400719acpi_video_device_state_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700720{
721 return single_open(file, acpi_video_device_state_seq_show,
722 PDE(inode)->data);
723}
724
725static ssize_t
Len Brown4be44fc2005-08-05 00:44:28 -0400726acpi_video_device_write_state(struct file *file,
727 const char __user * buffer,
728 size_t count, loff_t * data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700729{
Len Brown4be44fc2005-08-05 00:44:28 -0400730 int status;
731 struct seq_file *m = (struct seq_file *)file->private_data;
732 struct acpi_video_device *dev = (struct acpi_video_device *)m->private;
733 char str[12] = { 0 };
734 u32 state = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700735
Linus Torvalds1da177e2005-04-16 15:20:36 -0700736
737 if (!dev || count + 1 > sizeof str)
Patrick Mocheld550d982006-06-27 00:41:40 -0400738 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700739
740 if (copy_from_user(str, buffer, count))
Patrick Mocheld550d982006-06-27 00:41:40 -0400741 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700742
743 str[count] = 0;
744 state = simple_strtoul(str, NULL, 0);
Len Brown4be44fc2005-08-05 00:44:28 -0400745 state &= ((1ul << 31) | (1ul << 30) | (1ul << 0));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700746
747 status = acpi_video_device_set_state(dev, state);
748
749 if (status)
Patrick Mocheld550d982006-06-27 00:41:40 -0400750 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700751
Patrick Mocheld550d982006-06-27 00:41:40 -0400752 return count;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700753}
754
755static int
Len Brown4be44fc2005-08-05 00:44:28 -0400756acpi_video_device_brightness_seq_show(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700757{
Len Brown4be44fc2005-08-05 00:44:28 -0400758 struct acpi_video_device *dev =
759 (struct acpi_video_device *)seq->private;
760 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700761
Linus Torvalds1da177e2005-04-16 15:20:36 -0700762
763 if (!dev || !dev->brightness) {
764 seq_printf(seq, "<not supported>\n");
Patrick Mocheld550d982006-06-27 00:41:40 -0400765 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700766 }
767
768 seq_printf(seq, "levels: ");
769 for (i = 0; i < dev->brightness->count; i++)
770 seq_printf(seq, " %d", dev->brightness->levels[i]);
771 seq_printf(seq, "\ncurrent: %d\n", dev->brightness->curr);
772
Patrick Mocheld550d982006-06-27 00:41:40 -0400773 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700774}
775
776static int
Len Brown4be44fc2005-08-05 00:44:28 -0400777acpi_video_device_brightness_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700778{
779 return single_open(file, acpi_video_device_brightness_seq_show,
780 PDE(inode)->data);
781}
782
783static ssize_t
Len Brown4be44fc2005-08-05 00:44:28 -0400784acpi_video_device_write_brightness(struct file *file,
785 const char __user * buffer,
786 size_t count, loff_t * data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700787{
Len Brown4be44fc2005-08-05 00:44:28 -0400788 struct seq_file *m = (struct seq_file *)file->private_data;
789 struct acpi_video_device *dev = (struct acpi_video_device *)m->private;
790 char str[4] = { 0 };
791 unsigned int level = 0;
792 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700793
Linus Torvalds1da177e2005-04-16 15:20:36 -0700794
Thomas Renninger59d399d2005-11-08 05:27:00 -0500795 if (!dev || !dev->brightness || count + 1 > sizeof str)
Patrick Mocheld550d982006-06-27 00:41:40 -0400796 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700797
798 if (copy_from_user(str, buffer, count))
Patrick Mocheld550d982006-06-27 00:41:40 -0400799 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700800
801 str[count] = 0;
802 level = simple_strtoul(str, NULL, 0);
Len Brown4be44fc2005-08-05 00:44:28 -0400803
Linus Torvalds1da177e2005-04-16 15:20:36 -0700804 if (level > 100)
Patrick Mocheld550d982006-06-27 00:41:40 -0400805 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700806
807 /* validate though the list of available levels */
808 for (i = 0; i < dev->brightness->count; i++)
809 if (level == dev->brightness->levels[i]) {
Len Brown4be44fc2005-08-05 00:44:28 -0400810 if (ACPI_SUCCESS
811 (acpi_video_device_lcd_set_level(dev, level)))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700812 dev->brightness->curr = level;
813 break;
814 }
815
Patrick Mocheld550d982006-06-27 00:41:40 -0400816 return count;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700817}
818
Len Brown4be44fc2005-08-05 00:44:28 -0400819static int acpi_video_device_EDID_seq_show(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700820{
Len Brown4be44fc2005-08-05 00:44:28 -0400821 struct acpi_video_device *dev =
822 (struct acpi_video_device *)seq->private;
823 int status;
824 int i;
825 union acpi_object *edid = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700826
Linus Torvalds1da177e2005-04-16 15:20:36 -0700827
828 if (!dev)
829 goto out;
830
Len Brown4be44fc2005-08-05 00:44:28 -0400831 status = acpi_video_device_EDID(dev, &edid, 128);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700832 if (ACPI_FAILURE(status)) {
Len Brown4be44fc2005-08-05 00:44:28 -0400833 status = acpi_video_device_EDID(dev, &edid, 256);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700834 }
835
836 if (ACPI_FAILURE(status)) {
837 goto out;
838 }
839
840 if (edid && edid->type == ACPI_TYPE_BUFFER) {
841 for (i = 0; i < edid->buffer.length; i++)
842 seq_putc(seq, edid->buffer.pointer[i]);
843 }
844
Len Brown4be44fc2005-08-05 00:44:28 -0400845 out:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700846 if (!edid)
847 seq_printf(seq, "<not supported>\n");
848 else
849 kfree(edid);
850
Patrick Mocheld550d982006-06-27 00:41:40 -0400851 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700852}
853
854static int
Len Brown4be44fc2005-08-05 00:44:28 -0400855acpi_video_device_EDID_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700856{
857 return single_open(file, acpi_video_device_EDID_seq_show,
858 PDE(inode)->data);
859}
860
Len Brown4be44fc2005-08-05 00:44:28 -0400861static int acpi_video_device_add_fs(struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700862{
Len Brown4be44fc2005-08-05 00:44:28 -0400863 struct proc_dir_entry *entry = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700864 struct acpi_video_device *vid_dev;
865
Linus Torvalds1da177e2005-04-16 15:20:36 -0700866
867 if (!device)
Patrick Mocheld550d982006-06-27 00:41:40 -0400868 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700869
Len Brown4be44fc2005-08-05 00:44:28 -0400870 vid_dev = (struct acpi_video_device *)acpi_driver_data(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700871 if (!vid_dev)
Patrick Mocheld550d982006-06-27 00:41:40 -0400872 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700873
874 if (!acpi_device_dir(device)) {
875 acpi_device_dir(device) = proc_mkdir(acpi_device_bid(device),
Len Brown4be44fc2005-08-05 00:44:28 -0400876 vid_dev->video->dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700877 if (!acpi_device_dir(device))
Patrick Mocheld550d982006-06-27 00:41:40 -0400878 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700879 acpi_device_dir(device)->owner = THIS_MODULE;
880 }
881
882 /* 'info' [R] */
883 entry = create_proc_entry("info", S_IRUGO, acpi_device_dir(device));
884 if (!entry)
Patrick Mocheld550d982006-06-27 00:41:40 -0400885 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700886 else {
887 entry->proc_fops = &acpi_video_device_info_fops;
888 entry->data = acpi_driver_data(device);
889 entry->owner = THIS_MODULE;
890 }
891
892 /* 'state' [R/W] */
Len Brown4be44fc2005-08-05 00:44:28 -0400893 entry =
894 create_proc_entry("state", S_IFREG | S_IRUGO | S_IWUSR,
895 acpi_device_dir(device));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700896 if (!entry)
Patrick Mocheld550d982006-06-27 00:41:40 -0400897 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700898 else {
Arjan van de Vend479e902006-01-06 16:47:00 -0500899 acpi_video_device_state_fops.write = acpi_video_device_write_state;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700900 entry->proc_fops = &acpi_video_device_state_fops;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700901 entry->data = acpi_driver_data(device);
902 entry->owner = THIS_MODULE;
903 }
904
905 /* 'brightness' [R/W] */
Len Brown4be44fc2005-08-05 00:44:28 -0400906 entry =
907 create_proc_entry("brightness", S_IFREG | S_IRUGO | S_IWUSR,
908 acpi_device_dir(device));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700909 if (!entry)
Patrick Mocheld550d982006-06-27 00:41:40 -0400910 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700911 else {
Arjan van de Vend479e902006-01-06 16:47:00 -0500912 acpi_video_device_brightness_fops.write = acpi_video_device_write_brightness;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700913 entry->proc_fops = &acpi_video_device_brightness_fops;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700914 entry->data = acpi_driver_data(device);
915 entry->owner = THIS_MODULE;
916 }
917
918 /* 'EDID' [R] */
919 entry = create_proc_entry("EDID", S_IRUGO, acpi_device_dir(device));
920 if (!entry)
Patrick Mocheld550d982006-06-27 00:41:40 -0400921 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700922 else {
923 entry->proc_fops = &acpi_video_device_EDID_fops;
924 entry->data = acpi_driver_data(device);
925 entry->owner = THIS_MODULE;
926 }
927
Patrick Mocheld550d982006-06-27 00:41:40 -0400928 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700929}
930
Len Brown4be44fc2005-08-05 00:44:28 -0400931static int acpi_video_device_remove_fs(struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700932{
933 struct acpi_video_device *vid_dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700934
Len Brown4be44fc2005-08-05 00:44:28 -0400935 vid_dev = (struct acpi_video_device *)acpi_driver_data(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700936 if (!vid_dev || !vid_dev->video || !vid_dev->video->dir)
Patrick Mocheld550d982006-06-27 00:41:40 -0400937 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700938
939 if (acpi_device_dir(device)) {
940 remove_proc_entry("info", acpi_device_dir(device));
941 remove_proc_entry("state", acpi_device_dir(device));
942 remove_proc_entry("brightness", acpi_device_dir(device));
943 remove_proc_entry("EDID", acpi_device_dir(device));
Len Brown4be44fc2005-08-05 00:44:28 -0400944 remove_proc_entry(acpi_device_bid(device), vid_dev->video->dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700945 acpi_device_dir(device) = NULL;
946 }
947
Patrick Mocheld550d982006-06-27 00:41:40 -0400948 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700949}
950
Linus Torvalds1da177e2005-04-16 15:20:36 -0700951/* video bus */
Len Brown4be44fc2005-08-05 00:44:28 -0400952static int acpi_video_bus_info_seq_show(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700953{
Len Brown4be44fc2005-08-05 00:44:28 -0400954 struct acpi_video_bus *video = (struct acpi_video_bus *)seq->private;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700955
Linus Torvalds1da177e2005-04-16 15:20:36 -0700956
957 if (!video)
958 goto end;
959
960 seq_printf(seq, "Switching heads: %s\n",
Len Brown4be44fc2005-08-05 00:44:28 -0400961 video->flags.multihead ? "yes" : "no");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700962 seq_printf(seq, "Video ROM: %s\n",
Len Brown4be44fc2005-08-05 00:44:28 -0400963 video->flags.rom ? "yes" : "no");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700964 seq_printf(seq, "Device to be POSTed on boot: %s\n",
Len Brown4be44fc2005-08-05 00:44:28 -0400965 video->flags.post ? "yes" : "no");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700966
Len Brown4be44fc2005-08-05 00:44:28 -0400967 end:
Patrick Mocheld550d982006-06-27 00:41:40 -0400968 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700969}
970
Len Brown4be44fc2005-08-05 00:44:28 -0400971static int acpi_video_bus_info_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700972{
Len Brown4be44fc2005-08-05 00:44:28 -0400973 return single_open(file, acpi_video_bus_info_seq_show,
974 PDE(inode)->data);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700975}
976
Len Brown4be44fc2005-08-05 00:44:28 -0400977static int acpi_video_bus_ROM_seq_show(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700978{
Len Brown4be44fc2005-08-05 00:44:28 -0400979 struct acpi_video_bus *video = (struct acpi_video_bus *)seq->private;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700980
Linus Torvalds1da177e2005-04-16 15:20:36 -0700981
982 if (!video)
983 goto end;
984
985 printk(KERN_INFO PREFIX "Please implement %s\n", __FUNCTION__);
986 seq_printf(seq, "<TODO>\n");
987
Len Brown4be44fc2005-08-05 00:44:28 -0400988 end:
Patrick Mocheld550d982006-06-27 00:41:40 -0400989 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700990}
991
Len Brown4be44fc2005-08-05 00:44:28 -0400992static int acpi_video_bus_ROM_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700993{
994 return single_open(file, acpi_video_bus_ROM_seq_show, PDE(inode)->data);
995}
996
Len Brown4be44fc2005-08-05 00:44:28 -0400997static int acpi_video_bus_POST_info_seq_show(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700998{
Len Brown4be44fc2005-08-05 00:44:28 -0400999 struct acpi_video_bus *video = (struct acpi_video_bus *)seq->private;
1000 unsigned long options;
1001 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001002
Linus Torvalds1da177e2005-04-16 15:20:36 -07001003
1004 if (!video)
1005 goto end;
1006
1007 status = acpi_video_bus_POST_options(video, &options);
1008 if (ACPI_SUCCESS(status)) {
1009 if (!(options & 1)) {
Len Brown4be44fc2005-08-05 00:44:28 -04001010 printk(KERN_WARNING PREFIX
1011 "The motherboard VGA device is not listed as a possible POST device.\n");
1012 printk(KERN_WARNING PREFIX
1013 "This indicate a BIOS bug. Please contact the manufacturer.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001014 }
1015 printk("%lx\n", options);
1016 seq_printf(seq, "can POST: <intgrated video>");
1017 if (options & 2)
1018 seq_printf(seq, " <PCI video>");
1019 if (options & 4)
1020 seq_printf(seq, " <AGP video>");
1021 seq_putc(seq, '\n');
1022 } else
1023 seq_printf(seq, "<not supported>\n");
Len Brown4be44fc2005-08-05 00:44:28 -04001024 end:
Patrick Mocheld550d982006-06-27 00:41:40 -04001025 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001026}
1027
1028static int
Len Brown4be44fc2005-08-05 00:44:28 -04001029acpi_video_bus_POST_info_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001030{
Len Brown4be44fc2005-08-05 00:44:28 -04001031 return single_open(file, acpi_video_bus_POST_info_seq_show,
1032 PDE(inode)->data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001033}
1034
Len Brown4be44fc2005-08-05 00:44:28 -04001035static int acpi_video_bus_POST_seq_show(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001036{
Len Brown4be44fc2005-08-05 00:44:28 -04001037 struct acpi_video_bus *video = (struct acpi_video_bus *)seq->private;
1038 int status;
1039 unsigned long id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001040
Linus Torvalds1da177e2005-04-16 15:20:36 -07001041
1042 if (!video)
1043 goto end;
1044
Len Brown4be44fc2005-08-05 00:44:28 -04001045 status = acpi_video_bus_get_POST(video, &id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001046 if (!ACPI_SUCCESS(status)) {
1047 seq_printf(seq, "<not supported>\n");
1048 goto end;
1049 }
Len Brown4be44fc2005-08-05 00:44:28 -04001050 seq_printf(seq, "device posted is <%s>\n", device_decode[id & 3]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001051
Len Brown4be44fc2005-08-05 00:44:28 -04001052 end:
Patrick Mocheld550d982006-06-27 00:41:40 -04001053 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001054}
1055
Len Brown4be44fc2005-08-05 00:44:28 -04001056static int acpi_video_bus_DOS_seq_show(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001057{
Len Brown4be44fc2005-08-05 00:44:28 -04001058 struct acpi_video_bus *video = (struct acpi_video_bus *)seq->private;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001059
Linus Torvalds1da177e2005-04-16 15:20:36 -07001060
Len Brown4be44fc2005-08-05 00:44:28 -04001061 seq_printf(seq, "DOS setting: <%d>\n", video->dos_setting);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001062
Patrick Mocheld550d982006-06-27 00:41:40 -04001063 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001064}
1065
Len Brown4be44fc2005-08-05 00:44:28 -04001066static int acpi_video_bus_POST_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001067{
Len Brown4be44fc2005-08-05 00:44:28 -04001068 return single_open(file, acpi_video_bus_POST_seq_show,
1069 PDE(inode)->data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001070}
1071
Len Brown4be44fc2005-08-05 00:44:28 -04001072static int acpi_video_bus_DOS_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001073{
1074 return single_open(file, acpi_video_bus_DOS_seq_show, PDE(inode)->data);
1075}
1076
1077static ssize_t
Len Brown4be44fc2005-08-05 00:44:28 -04001078acpi_video_bus_write_POST(struct file *file,
1079 const char __user * buffer,
1080 size_t count, loff_t * data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001081{
Len Brown4be44fc2005-08-05 00:44:28 -04001082 int status;
1083 struct seq_file *m = (struct seq_file *)file->private_data;
1084 struct acpi_video_bus *video = (struct acpi_video_bus *)m->private;
1085 char str[12] = { 0 };
1086 unsigned long opt, options;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001087
Linus Torvalds1da177e2005-04-16 15:20:36 -07001088
Linus Torvalds1da177e2005-04-16 15:20:36 -07001089 if (!video || count + 1 > sizeof str)
Patrick Mocheld550d982006-06-27 00:41:40 -04001090 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001091
1092 status = acpi_video_bus_POST_options(video, &options);
1093 if (!ACPI_SUCCESS(status))
Patrick Mocheld550d982006-06-27 00:41:40 -04001094 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001095
1096 if (copy_from_user(str, buffer, count))
Patrick Mocheld550d982006-06-27 00:41:40 -04001097 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001098
1099 str[count] = 0;
1100 opt = strtoul(str, NULL, 0);
1101 if (opt > 3)
Patrick Mocheld550d982006-06-27 00:41:40 -04001102 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001103
1104 /* just in case an OEM 'forget' the motherboard... */
1105 options |= 1;
1106
1107 if (options & (1ul << opt)) {
Len Brown4be44fc2005-08-05 00:44:28 -04001108 status = acpi_video_bus_set_POST(video, opt);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001109 if (!ACPI_SUCCESS(status))
Patrick Mocheld550d982006-06-27 00:41:40 -04001110 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001111
1112 }
1113
Patrick Mocheld550d982006-06-27 00:41:40 -04001114 return count;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001115}
1116
1117static ssize_t
Len Brown4be44fc2005-08-05 00:44:28 -04001118acpi_video_bus_write_DOS(struct file *file,
1119 const char __user * buffer,
1120 size_t count, loff_t * data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001121{
Len Brown4be44fc2005-08-05 00:44:28 -04001122 int status;
1123 struct seq_file *m = (struct seq_file *)file->private_data;
1124 struct acpi_video_bus *video = (struct acpi_video_bus *)m->private;
1125 char str[12] = { 0 };
1126 unsigned long opt;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001127
Linus Torvalds1da177e2005-04-16 15:20:36 -07001128
Linus Torvalds1da177e2005-04-16 15:20:36 -07001129 if (!video || count + 1 > sizeof str)
Patrick Mocheld550d982006-06-27 00:41:40 -04001130 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001131
1132 if (copy_from_user(str, buffer, count))
Patrick Mocheld550d982006-06-27 00:41:40 -04001133 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001134
1135 str[count] = 0;
1136 opt = strtoul(str, NULL, 0);
1137 if (opt > 7)
Patrick Mocheld550d982006-06-27 00:41:40 -04001138 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001139
Len Brown4be44fc2005-08-05 00:44:28 -04001140 status = acpi_video_bus_DOS(video, opt & 0x3, (opt & 0x4) >> 2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001141
1142 if (!ACPI_SUCCESS(status))
Patrick Mocheld550d982006-06-27 00:41:40 -04001143 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001144
Patrick Mocheld550d982006-06-27 00:41:40 -04001145 return count;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001146}
1147
Len Brown4be44fc2005-08-05 00:44:28 -04001148static int acpi_video_bus_add_fs(struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001149{
Len Brown4be44fc2005-08-05 00:44:28 -04001150 struct proc_dir_entry *entry = NULL;
1151 struct acpi_video_bus *video;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001152
Linus Torvalds1da177e2005-04-16 15:20:36 -07001153
Len Brown4be44fc2005-08-05 00:44:28 -04001154 video = (struct acpi_video_bus *)acpi_driver_data(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001155
1156 if (!acpi_device_dir(device)) {
1157 acpi_device_dir(device) = proc_mkdir(acpi_device_bid(device),
Len Brown4be44fc2005-08-05 00:44:28 -04001158 acpi_video_dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001159 if (!acpi_device_dir(device))
Patrick Mocheld550d982006-06-27 00:41:40 -04001160 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001161 video->dir = acpi_device_dir(device);
1162 acpi_device_dir(device)->owner = THIS_MODULE;
1163 }
1164
1165 /* 'info' [R] */
1166 entry = create_proc_entry("info", S_IRUGO, acpi_device_dir(device));
1167 if (!entry)
Patrick Mocheld550d982006-06-27 00:41:40 -04001168 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001169 else {
1170 entry->proc_fops = &acpi_video_bus_info_fops;
1171 entry->data = acpi_driver_data(device);
1172 entry->owner = THIS_MODULE;
1173 }
1174
1175 /* 'ROM' [R] */
1176 entry = create_proc_entry("ROM", S_IRUGO, acpi_device_dir(device));
1177 if (!entry)
Patrick Mocheld550d982006-06-27 00:41:40 -04001178 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001179 else {
1180 entry->proc_fops = &acpi_video_bus_ROM_fops;
1181 entry->data = acpi_driver_data(device);
1182 entry->owner = THIS_MODULE;
1183 }
1184
1185 /* 'POST_info' [R] */
Len Brown4be44fc2005-08-05 00:44:28 -04001186 entry =
1187 create_proc_entry("POST_info", S_IRUGO, acpi_device_dir(device));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001188 if (!entry)
Patrick Mocheld550d982006-06-27 00:41:40 -04001189 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001190 else {
1191 entry->proc_fops = &acpi_video_bus_POST_info_fops;
1192 entry->data = acpi_driver_data(device);
1193 entry->owner = THIS_MODULE;
1194 }
1195
1196 /* 'POST' [R/W] */
Len Brown4be44fc2005-08-05 00:44:28 -04001197 entry =
1198 create_proc_entry("POST", S_IFREG | S_IRUGO | S_IRUSR,
1199 acpi_device_dir(device));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001200 if (!entry)
Patrick Mocheld550d982006-06-27 00:41:40 -04001201 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001202 else {
Arjan van de Vend479e902006-01-06 16:47:00 -05001203 acpi_video_bus_POST_fops.write = acpi_video_bus_write_POST;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001204 entry->proc_fops = &acpi_video_bus_POST_fops;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001205 entry->data = acpi_driver_data(device);
1206 entry->owner = THIS_MODULE;
1207 }
1208
1209 /* 'DOS' [R/W] */
Len Brown4be44fc2005-08-05 00:44:28 -04001210 entry =
1211 create_proc_entry("DOS", S_IFREG | S_IRUGO | S_IRUSR,
1212 acpi_device_dir(device));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001213 if (!entry)
Patrick Mocheld550d982006-06-27 00:41:40 -04001214 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001215 else {
Arjan van de Vend479e902006-01-06 16:47:00 -05001216 acpi_video_bus_DOS_fops.write = acpi_video_bus_write_DOS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001217 entry->proc_fops = &acpi_video_bus_DOS_fops;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001218 entry->data = acpi_driver_data(device);
1219 entry->owner = THIS_MODULE;
1220 }
1221
Patrick Mocheld550d982006-06-27 00:41:40 -04001222 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001223}
1224
Len Brown4be44fc2005-08-05 00:44:28 -04001225static int acpi_video_bus_remove_fs(struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001226{
Len Brown4be44fc2005-08-05 00:44:28 -04001227 struct acpi_video_bus *video;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001228
Linus Torvalds1da177e2005-04-16 15:20:36 -07001229
Len Brown4be44fc2005-08-05 00:44:28 -04001230 video = (struct acpi_video_bus *)acpi_driver_data(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001231
1232 if (acpi_device_dir(device)) {
1233 remove_proc_entry("info", acpi_device_dir(device));
1234 remove_proc_entry("ROM", acpi_device_dir(device));
1235 remove_proc_entry("POST_info", acpi_device_dir(device));
1236 remove_proc_entry("POST", acpi_device_dir(device));
1237 remove_proc_entry("DOS", acpi_device_dir(device));
Len Brown4be44fc2005-08-05 00:44:28 -04001238 remove_proc_entry(acpi_device_bid(device), acpi_video_dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001239 acpi_device_dir(device) = NULL;
1240 }
1241
Patrick Mocheld550d982006-06-27 00:41:40 -04001242 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001243}
1244
1245/* --------------------------------------------------------------------------
1246 Driver Interface
1247 -------------------------------------------------------------------------- */
1248
1249/* device interface */
1250
1251static int
Len Brown4be44fc2005-08-05 00:44:28 -04001252acpi_video_bus_get_one_device(struct acpi_device *device,
1253 struct acpi_video_bus *video)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001254{
Len Brown4be44fc2005-08-05 00:44:28 -04001255 unsigned long device_id;
Yu, Luming973bf492006-04-27 05:25:00 -04001256 int status;
Len Brown4be44fc2005-08-05 00:44:28 -04001257 struct acpi_video_device *data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001258
Linus Torvalds1da177e2005-04-16 15:20:36 -07001259
1260 if (!device || !video)
Patrick Mocheld550d982006-06-27 00:41:40 -04001261 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001262
Len Brown4be44fc2005-08-05 00:44:28 -04001263 status =
1264 acpi_evaluate_integer(device->handle, "_ADR", NULL, &device_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001265 if (ACPI_SUCCESS(status)) {
1266
1267 data = kmalloc(sizeof(struct acpi_video_device), GFP_KERNEL);
1268 if (!data)
Patrick Mocheld550d982006-06-27 00:41:40 -04001269 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001270
1271 memset(data, 0, sizeof(struct acpi_video_device));
1272
Linus Torvalds1da177e2005-04-16 15:20:36 -07001273 strcpy(acpi_device_name(device), ACPI_VIDEO_DEVICE_NAME);
1274 strcpy(acpi_device_class(device), ACPI_VIDEO_CLASS);
1275 acpi_driver_data(device) = data;
1276
1277 data->device_id = device_id;
1278 data->video = video;
1279 data->dev = device;
1280
1281 switch (device_id & 0xffff) {
1282 case 0x0100:
1283 data->flags.crt = 1;
1284 break;
1285 case 0x0400:
1286 data->flags.lcd = 1;
1287 break;
1288 case 0x0200:
1289 data->flags.tvout = 1;
1290 break;
1291 default:
1292 data->flags.unknown = 1;
1293 break;
1294 }
Len Brown4be44fc2005-08-05 00:44:28 -04001295
Linus Torvalds1da177e2005-04-16 15:20:36 -07001296 acpi_video_device_bind(video, data);
1297 acpi_video_device_find_cap(data);
1298
Patrick Mochel90130262006-05-19 16:54:48 -04001299 status = acpi_install_notify_handler(device->handle,
Len Brown4be44fc2005-08-05 00:44:28 -04001300 ACPI_DEVICE_NOTIFY,
1301 acpi_video_device_notify,
1302 data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001303 if (ACPI_FAILURE(status)) {
1304 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
Len Brown4be44fc2005-08-05 00:44:28 -04001305 "Error installing notify handler\n"));
Yu, Luming973bf492006-04-27 05:25:00 -04001306 if(data->brightness)
1307 kfree(data->brightness->levels);
1308 kfree(data->brightness);
1309 kfree(data);
1310 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001311 }
1312
1313 down(&video->sem);
1314 list_add_tail(&data->entry, &video->video_device_list);
1315 up(&video->sem);
1316
1317 acpi_video_device_add_fs(device);
1318
Patrick Mocheld550d982006-06-27 00:41:40 -04001319 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001320 }
1321
Patrick Mocheld550d982006-06-27 00:41:40 -04001322 return -ENOENT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001323}
1324
1325/*
1326 * Arg:
1327 * video : video bus device
1328 *
1329 * Return:
1330 * none
1331 *
1332 * Enumerate the video device list of the video bus,
1333 * bind the ids with the corresponding video devices
1334 * under the video bus.
Len Brown4be44fc2005-08-05 00:44:28 -04001335 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001336
Len Brown4be44fc2005-08-05 00:44:28 -04001337static void acpi_video_device_rebind(struct acpi_video_bus *video)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001338{
Len Brown4be44fc2005-08-05 00:44:28 -04001339 struct list_head *node, *next;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001340 list_for_each_safe(node, next, &video->video_device_list) {
Len Brown4be44fc2005-08-05 00:44:28 -04001341 struct acpi_video_device *dev =
1342 container_of(node, struct acpi_video_device, entry);
1343 acpi_video_device_bind(video, dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001344 }
1345}
1346
1347/*
1348 * Arg:
1349 * video : video bus device
1350 * device : video output device under the video
1351 * bus
1352 *
1353 * Return:
1354 * none
1355 *
1356 * Bind the ids with the corresponding video devices
1357 * under the video bus.
Len Brown4be44fc2005-08-05 00:44:28 -04001358 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001359
1360static void
Len Brown4be44fc2005-08-05 00:44:28 -04001361acpi_video_device_bind(struct acpi_video_bus *video,
1362 struct acpi_video_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001363{
Len Brown4be44fc2005-08-05 00:44:28 -04001364 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001365
1366#define IDS_VAL(i) video->attached_array[i].value.int_val
1367#define IDS_BIND(i) video->attached_array[i].bind_info
Len Brown4be44fc2005-08-05 00:44:28 -04001368
1369 for (i = 0; IDS_VAL(i) != ACPI_VIDEO_HEAD_INVALID &&
1370 i < video->attached_count; i++) {
1371 if (device->device_id == (IDS_VAL(i) & 0xffff)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001372 IDS_BIND(i) = device;
1373 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "device_bind %d\n", i));
1374 }
1375 }
1376#undef IDS_VAL
1377#undef IDS_BIND
1378}
1379
1380/*
1381 * Arg:
1382 * video : video bus device
1383 *
1384 * Return:
1385 * < 0 : error
1386 *
1387 * Call _DOD to enumerate all devices attached to display adapter
1388 *
Len Brown4be44fc2005-08-05 00:44:28 -04001389 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001390
1391static int acpi_video_device_enumerate(struct acpi_video_bus *video)
1392{
Len Brown4be44fc2005-08-05 00:44:28 -04001393 int status;
1394 int count;
1395 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001396 struct acpi_video_enumerated_device *active_device_list;
Len Brown4be44fc2005-08-05 00:44:28 -04001397 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
1398 union acpi_object *dod = NULL;
1399 union acpi_object *obj;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001400
Patrick Mochel90130262006-05-19 16:54:48 -04001401 status = acpi_evaluate_object(video->device->handle, "_DOD", NULL, &buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001402 if (!ACPI_SUCCESS(status)) {
Thomas Renningera6fc6722006-06-26 23:58:43 -04001403 ACPI_EXCEPTION((AE_INFO, status, "Evaluating _DOD"));
Patrick Mocheld550d982006-06-27 00:41:40 -04001404 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001405 }
1406
Len Brown4be44fc2005-08-05 00:44:28 -04001407 dod = (union acpi_object *)buffer.pointer;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001408 if (!dod || (dod->type != ACPI_TYPE_PACKAGE)) {
Thomas Renningera6fc6722006-06-26 23:58:43 -04001409 ACPI_EXCEPTION((AE_INFO, status, "Invalid _DOD data"));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001410 status = -EFAULT;
1411 goto out;
1412 }
1413
1414 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found %d video heads in _DOD\n",
Len Brown4be44fc2005-08-05 00:44:28 -04001415 dod->package.count));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001416
Len Brown4be44fc2005-08-05 00:44:28 -04001417 active_device_list = kmalloc((1 +
1418 dod->package.count) *
1419 sizeof(struct
1420 acpi_video_enumerated_device),
1421 GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001422
1423 if (!active_device_list) {
1424 status = -ENOMEM;
1425 goto out;
1426 }
1427
1428 count = 0;
1429 for (i = 0; i < dod->package.count; i++) {
Len Brown4be44fc2005-08-05 00:44:28 -04001430 obj = (union acpi_object *)&dod->package.elements[i];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001431
1432 if (obj->type != ACPI_TYPE_INTEGER) {
Len Brown64684632006-06-26 23:41:38 -04001433 printk(KERN_ERR PREFIX "Invalid _DOD data\n");
Len Brown4be44fc2005-08-05 00:44:28 -04001434 active_device_list[i].value.int_val =
1435 ACPI_VIDEO_HEAD_INVALID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001436 }
1437 active_device_list[i].value.int_val = obj->integer.value;
1438 active_device_list[i].bind_info = NULL;
Len Brown4be44fc2005-08-05 00:44:28 -04001439 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "dod element[%d] = %d\n", i,
1440 (int)obj->integer.value));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001441 count++;
1442 }
1443 active_device_list[count].value.int_val = ACPI_VIDEO_HEAD_END;
1444
Jesper Juhl6044ec82005-11-07 01:01:32 -08001445 kfree(video->attached_array);
Len Brown4be44fc2005-08-05 00:44:28 -04001446
Linus Torvalds1da177e2005-04-16 15:20:36 -07001447 video->attached_array = active_device_list;
1448 video->attached_count = count;
Len Brown4be44fc2005-08-05 00:44:28 -04001449 out:
Len Brown02438d82006-06-30 03:19:10 -04001450 kfree(buffer.pointer);
Patrick Mocheld550d982006-06-27 00:41:40 -04001451 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001452}
1453
1454/*
1455 * Arg:
1456 * video : video bus device
1457 * event : Nontify Event
1458 *
1459 * Return:
1460 * < 0 : error
1461 *
1462 * 1. Find out the current active output device.
1463 * 2. Identify the next output device to switch
1464 * 3. call _DSS to do actual switch.
Len Brown4be44fc2005-08-05 00:44:28 -04001465 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001466
Len Brown4be44fc2005-08-05 00:44:28 -04001467static int acpi_video_switch_output(struct acpi_video_bus *video, int event)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001468{
Len Brown4be44fc2005-08-05 00:44:28 -04001469 struct list_head *node, *next;
1470 struct acpi_video_device *dev = NULL;
1471 struct acpi_video_device *dev_next = NULL;
1472 struct acpi_video_device *dev_prev = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001473 unsigned long state;
1474 int status = 0;
1475
Linus Torvalds1da177e2005-04-16 15:20:36 -07001476
1477 list_for_each_safe(node, next, &video->video_device_list) {
Adrian Bunk73345712005-03-30 22:31:35 -05001478 dev = container_of(node, struct acpi_video_device, entry);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001479 status = acpi_video_device_get_state(dev, &state);
Len Brown4be44fc2005-08-05 00:44:28 -04001480 if (state & 0x2) {
1481 dev_next =
1482 container_of(node->next, struct acpi_video_device,
1483 entry);
1484 dev_prev =
1485 container_of(node->prev, struct acpi_video_device,
1486 entry);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001487 goto out;
1488 }
1489 }
1490 dev_next = container_of(node->next, struct acpi_video_device, entry);
1491 dev_prev = container_of(node->prev, struct acpi_video_device, entry);
Len Brown4be44fc2005-08-05 00:44:28 -04001492 out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001493 switch (event) {
1494 case ACPI_VIDEO_NOTIFY_CYCLE:
1495 case ACPI_VIDEO_NOTIFY_NEXT_OUTPUT:
1496 acpi_video_device_set_state(dev, 0);
1497 acpi_video_device_set_state(dev_next, 0x80000001);
1498 break;
1499 case ACPI_VIDEO_NOTIFY_PREV_OUTPUT:
1500 acpi_video_device_set_state(dev, 0);
1501 acpi_video_device_set_state(dev_prev, 0x80000001);
1502 default:
1503 break;
1504 }
1505
Patrick Mocheld550d982006-06-27 00:41:40 -04001506 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001507}
1508
Len Brown4be44fc2005-08-05 00:44:28 -04001509static int
1510acpi_video_get_next_level(struct acpi_video_device *device,
1511 u32 level_current, u32 event)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001512{
Thomas Tuttlef4715182006-12-19 12:56:14 -08001513 int min, max, min_above, max_below, i, l;
1514 max = max_below = 0;
1515 min = min_above = 255;
1516 for (i = 0; i < device->brightness->count; i++) {
1517 l = device->brightness->levels[i];
1518 if (l < min)
1519 min = l;
1520 if (l > max)
1521 max = l;
1522 if (l < min_above && l > level_current)
1523 min_above = l;
1524 if (l > max_below && l < level_current)
1525 max_below = l;
1526 }
1527
1528 switch (event) {
1529 case ACPI_VIDEO_NOTIFY_CYCLE_BRIGHTNESS:
1530 return (level_current < max) ? min_above : min;
1531 case ACPI_VIDEO_NOTIFY_INC_BRIGHTNESS:
1532 return (level_current < max) ? min_above : max;
1533 case ACPI_VIDEO_NOTIFY_DEC_BRIGHTNESS:
1534 return (level_current > min) ? max_below : min;
1535 case ACPI_VIDEO_NOTIFY_ZERO_BRIGHTNESS:
1536 case ACPI_VIDEO_NOTIFY_DISPLAY_OFF:
1537 return 0;
1538 default:
1539 return level_current;
1540 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001541}
1542
Linus Torvalds1da177e2005-04-16 15:20:36 -07001543static void
Len Brown4be44fc2005-08-05 00:44:28 -04001544acpi_video_switch_brightness(struct acpi_video_device *device, int event)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001545{
1546 unsigned long level_current, level_next;
1547 acpi_video_device_lcd_get_level_current(device, &level_current);
1548 level_next = acpi_video_get_next_level(device, level_current, event);
1549 acpi_video_device_lcd_set_level(device, level_next);
1550}
1551
1552static int
Len Brown4be44fc2005-08-05 00:44:28 -04001553acpi_video_bus_get_devices(struct acpi_video_bus *video,
1554 struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001555{
Len Brown4be44fc2005-08-05 00:44:28 -04001556 int status = 0;
1557 struct list_head *node, *next;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001558
Linus Torvalds1da177e2005-04-16 15:20:36 -07001559
1560 acpi_video_device_enumerate(video);
1561
1562 list_for_each_safe(node, next, &device->children) {
Len Brown4be44fc2005-08-05 00:44:28 -04001563 struct acpi_device *dev =
1564 list_entry(node, struct acpi_device, node);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001565
1566 if (!dev)
1567 continue;
1568
1569 status = acpi_video_bus_get_one_device(dev, video);
1570 if (ACPI_FAILURE(status)) {
Thomas Renningera6fc6722006-06-26 23:58:43 -04001571 ACPI_EXCEPTION((AE_INFO, status, "Cant attach device"));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001572 continue;
1573 }
1574
1575 }
Patrick Mocheld550d982006-06-27 00:41:40 -04001576 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001577}
1578
Len Brown4be44fc2005-08-05 00:44:28 -04001579static int acpi_video_bus_put_one_device(struct acpi_video_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001580{
Karol Kozimor031ec772005-07-30 04:18:00 -04001581 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001582 struct acpi_video_bus *video;
1583
Linus Torvalds1da177e2005-04-16 15:20:36 -07001584
1585 if (!device || !device->video)
Patrick Mocheld550d982006-06-27 00:41:40 -04001586 return -ENOENT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001587
1588 video = device->video;
1589
1590 down(&video->sem);
1591 list_del(&device->entry);
1592 up(&video->sem);
1593 acpi_video_device_remove_fs(device->dev);
1594
Patrick Mochel90130262006-05-19 16:54:48 -04001595 status = acpi_remove_notify_handler(device->dev->handle,
Len Brown4be44fc2005-08-05 00:44:28 -04001596 ACPI_DEVICE_NOTIFY,
1597 acpi_video_device_notify);
Karol Kozimor031ec772005-07-30 04:18:00 -04001598
Patrick Mocheld550d982006-06-27 00:41:40 -04001599 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001600}
1601
Len Brown4be44fc2005-08-05 00:44:28 -04001602static int acpi_video_bus_put_devices(struct acpi_video_bus *video)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001603{
Len Brown4be44fc2005-08-05 00:44:28 -04001604 int status;
1605 struct list_head *node, *next;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001606
Linus Torvalds1da177e2005-04-16 15:20:36 -07001607
1608 list_for_each_safe(node, next, &video->video_device_list) {
Len Brown4be44fc2005-08-05 00:44:28 -04001609 struct acpi_video_device *data =
1610 list_entry(node, struct acpi_video_device, entry);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001611 if (!data)
1612 continue;
1613
1614 status = acpi_video_bus_put_one_device(data);
Len Brown4be44fc2005-08-05 00:44:28 -04001615 if (ACPI_FAILURE(status))
1616 printk(KERN_WARNING PREFIX
1617 "hhuuhhuu bug in acpi video driver.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001618
Dave Jonesd384ea62006-06-24 00:33:08 -04001619 if (data->brightness)
Yu, Luming973bf492006-04-27 05:25:00 -04001620 kfree(data->brightness->levels);
Jesper Juhl6044ec82005-11-07 01:01:32 -08001621 kfree(data->brightness);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001622 kfree(data);
1623 }
1624
Patrick Mocheld550d982006-06-27 00:41:40 -04001625 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001626}
1627
1628/* acpi_video interface */
1629
Len Brown4be44fc2005-08-05 00:44:28 -04001630static int acpi_video_bus_start_devices(struct acpi_video_bus *video)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001631{
1632 return acpi_video_bus_DOS(video, 1, 0);
1633}
1634
Len Brown4be44fc2005-08-05 00:44:28 -04001635static int acpi_video_bus_stop_devices(struct acpi_video_bus *video)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001636{
1637 return acpi_video_bus_DOS(video, 0, 1);
1638}
1639
Len Brown4be44fc2005-08-05 00:44:28 -04001640static void acpi_video_bus_notify(acpi_handle handle, u32 event, void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001641{
Len Brown4be44fc2005-08-05 00:44:28 -04001642 struct acpi_video_bus *video = (struct acpi_video_bus *)data;
1643 struct acpi_device *device = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001644
Linus Torvalds1da177e2005-04-16 15:20:36 -07001645 printk("video bus notify\n");
1646
1647 if (!video)
Patrick Mocheld550d982006-06-27 00:41:40 -04001648 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001649
Patrick Mochele6afa0d2006-05-19 16:54:40 -04001650 device = video->device;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001651
1652 switch (event) {
1653 case ACPI_VIDEO_NOTIFY_SWITCH: /* User request that a switch occur,
1654 * most likely via hotkey. */
1655 acpi_bus_generate_event(device, event, 0);
1656 break;
1657
1658 case ACPI_VIDEO_NOTIFY_PROBE: /* User plug or remove a video
1659 * connector. */
1660 acpi_video_device_enumerate(video);
1661 acpi_video_device_rebind(video);
1662 acpi_video_switch_output(video, event);
1663 acpi_bus_generate_event(device, event, 0);
1664 break;
1665
Len Brown4be44fc2005-08-05 00:44:28 -04001666 case ACPI_VIDEO_NOTIFY_CYCLE: /* Cycle Display output hotkey pressed. */
1667 case ACPI_VIDEO_NOTIFY_NEXT_OUTPUT: /* Next Display output hotkey pressed. */
1668 case ACPI_VIDEO_NOTIFY_PREV_OUTPUT: /* previous Display output hotkey pressed. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001669 acpi_video_switch_output(video, event);
1670 acpi_bus_generate_event(device, event, 0);
1671 break;
1672
1673 default:
1674 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
Len Brown4be44fc2005-08-05 00:44:28 -04001675 "Unsupported event [0x%x]\n", event));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001676 break;
1677 }
1678
Patrick Mocheld550d982006-06-27 00:41:40 -04001679 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001680}
1681
Len Brown4be44fc2005-08-05 00:44:28 -04001682static void acpi_video_device_notify(acpi_handle handle, u32 event, void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001683{
Len Brown4be44fc2005-08-05 00:44:28 -04001684 struct acpi_video_device *video_device =
1685 (struct acpi_video_device *)data;
1686 struct acpi_device *device = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001687
Linus Torvalds1da177e2005-04-16 15:20:36 -07001688
1689 printk("video device notify\n");
1690 if (!video_device)
Patrick Mocheld550d982006-06-27 00:41:40 -04001691 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001692
Patrick Mochele6afa0d2006-05-19 16:54:40 -04001693 device = video_device->dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001694
1695 switch (event) {
Len Brown4be44fc2005-08-05 00:44:28 -04001696 case ACPI_VIDEO_NOTIFY_SWITCH: /* change in status (cycle output device) */
1697 case ACPI_VIDEO_NOTIFY_PROBE: /* change in status (output device status) */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001698 acpi_bus_generate_event(device, event, 0);
1699 break;
Len Brown4be44fc2005-08-05 00:44:28 -04001700 case ACPI_VIDEO_NOTIFY_CYCLE_BRIGHTNESS: /* Cycle brightness */
1701 case ACPI_VIDEO_NOTIFY_INC_BRIGHTNESS: /* Increase brightness */
1702 case ACPI_VIDEO_NOTIFY_DEC_BRIGHTNESS: /* Decrease brightness */
1703 case ACPI_VIDEO_NOTIFY_ZERO_BRIGHTNESS: /* zero brightnesss */
1704 case ACPI_VIDEO_NOTIFY_DISPLAY_OFF: /* display device off */
1705 acpi_video_switch_brightness(video_device, event);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001706 acpi_bus_generate_event(device, event, 0);
1707 break;
1708 default:
1709 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
Len Brown4be44fc2005-08-05 00:44:28 -04001710 "Unsupported event [0x%x]\n", event));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001711 break;
1712 }
Patrick Mocheld550d982006-06-27 00:41:40 -04001713 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001714}
1715
Len Brown4be44fc2005-08-05 00:44:28 -04001716static int acpi_video_bus_add(struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001717{
Len Brown4be44fc2005-08-05 00:44:28 -04001718 int result = 0;
1719 acpi_status status = 0;
1720 struct acpi_video_bus *video = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001721
Len Brown4be44fc2005-08-05 00:44:28 -04001722
Linus Torvalds1da177e2005-04-16 15:20:36 -07001723 if (!device)
Patrick Mocheld550d982006-06-27 00:41:40 -04001724 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001725
1726 video = kmalloc(sizeof(struct acpi_video_bus), GFP_KERNEL);
1727 if (!video)
Patrick Mocheld550d982006-06-27 00:41:40 -04001728 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001729 memset(video, 0, sizeof(struct acpi_video_bus));
1730
Patrick Mochele6afa0d2006-05-19 16:54:40 -04001731 video->device = device;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001732 strcpy(acpi_device_name(device), ACPI_VIDEO_BUS_NAME);
1733 strcpy(acpi_device_class(device), ACPI_VIDEO_CLASS);
1734 acpi_driver_data(device) = video;
1735
1736 acpi_video_bus_find_cap(video);
1737 result = acpi_video_bus_check(video);
1738 if (result)
1739 goto end;
1740
1741 result = acpi_video_bus_add_fs(device);
1742 if (result)
1743 goto end;
1744
1745 init_MUTEX(&video->sem);
1746 INIT_LIST_HEAD(&video->video_device_list);
1747
1748 acpi_video_bus_get_devices(video, device);
1749 acpi_video_bus_start_devices(video);
1750
Patrick Mochel90130262006-05-19 16:54:48 -04001751 status = acpi_install_notify_handler(device->handle,
Len Brown4be44fc2005-08-05 00:44:28 -04001752 ACPI_DEVICE_NOTIFY,
1753 acpi_video_bus_notify, video);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001754 if (ACPI_FAILURE(status)) {
1755 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
Len Brown4be44fc2005-08-05 00:44:28 -04001756 "Error installing notify handler\n"));
Yu, Luming973bf492006-04-27 05:25:00 -04001757 acpi_video_bus_stop_devices(video);
1758 acpi_video_bus_put_devices(video);
1759 kfree(video->attached_array);
1760 acpi_video_bus_remove_fs(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001761 result = -ENODEV;
1762 goto end;
1763 }
1764
1765 printk(KERN_INFO PREFIX "%s [%s] (multi-head: %s rom: %s post: %s)\n",
Len Brown4be44fc2005-08-05 00:44:28 -04001766 ACPI_VIDEO_DEVICE_NAME, acpi_device_bid(device),
1767 video->flags.multihead ? "yes" : "no",
1768 video->flags.rom ? "yes" : "no",
1769 video->flags.post ? "yes" : "no");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001770
Len Brown4be44fc2005-08-05 00:44:28 -04001771 end:
Yu, Luming973bf492006-04-27 05:25:00 -04001772 if (result)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001773 kfree(video);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001774
Patrick Mocheld550d982006-06-27 00:41:40 -04001775 return result;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001776}
1777
Len Brown4be44fc2005-08-05 00:44:28 -04001778static int acpi_video_bus_remove(struct acpi_device *device, int type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001779{
Len Brown4be44fc2005-08-05 00:44:28 -04001780 acpi_status status = 0;
1781 struct acpi_video_bus *video = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001782
Linus Torvalds1da177e2005-04-16 15:20:36 -07001783
1784 if (!device || !acpi_driver_data(device))
Patrick Mocheld550d982006-06-27 00:41:40 -04001785 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001786
Len Brown4be44fc2005-08-05 00:44:28 -04001787 video = (struct acpi_video_bus *)acpi_driver_data(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001788
1789 acpi_video_bus_stop_devices(video);
1790
Patrick Mochel90130262006-05-19 16:54:48 -04001791 status = acpi_remove_notify_handler(video->device->handle,
Len Brown4be44fc2005-08-05 00:44:28 -04001792 ACPI_DEVICE_NOTIFY,
1793 acpi_video_bus_notify);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001794
1795 acpi_video_bus_put_devices(video);
1796 acpi_video_bus_remove_fs(device);
1797
Jesper Juhl6044ec82005-11-07 01:01:32 -08001798 kfree(video->attached_array);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001799 kfree(video);
1800
Patrick Mocheld550d982006-06-27 00:41:40 -04001801 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001802}
1803
Linus Torvalds1da177e2005-04-16 15:20:36 -07001804static int
Len Brown4be44fc2005-08-05 00:44:28 -04001805acpi_video_bus_match(struct acpi_device *device, struct acpi_driver *driver)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001806{
Len Brown4be44fc2005-08-05 00:44:28 -04001807 acpi_handle h_dummy1;
1808 acpi_handle h_dummy2;
1809 acpi_handle h_dummy3;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001810
Linus Torvalds1da177e2005-04-16 15:20:36 -07001811
1812 if (!device || !driver)
Patrick Mocheld550d982006-06-27 00:41:40 -04001813 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001814
1815 /* Since there is no HID, CID for ACPI Video drivers, we have
1816 * to check well known required nodes for each feature we support.
1817 */
1818
1819 /* Does this device able to support video switching ? */
1820 if (ACPI_SUCCESS(acpi_get_handle(device->handle, "_DOD", &h_dummy1)) &&
1821 ACPI_SUCCESS(acpi_get_handle(device->handle, "_DOS", &h_dummy2)))
Patrick Mocheld550d982006-06-27 00:41:40 -04001822 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001823
1824 /* Does this device able to retrieve a video ROM ? */
1825 if (ACPI_SUCCESS(acpi_get_handle(device->handle, "_ROM", &h_dummy1)))
Patrick Mocheld550d982006-06-27 00:41:40 -04001826 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001827
1828 /* Does this device able to configure which video head to be POSTed ? */
1829 if (ACPI_SUCCESS(acpi_get_handle(device->handle, "_VPO", &h_dummy1)) &&
1830 ACPI_SUCCESS(acpi_get_handle(device->handle, "_GPD", &h_dummy2)) &&
1831 ACPI_SUCCESS(acpi_get_handle(device->handle, "_SPD", &h_dummy3)))
Patrick Mocheld550d982006-06-27 00:41:40 -04001832 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001833
Patrick Mocheld550d982006-06-27 00:41:40 -04001834 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001835}
1836
Len Brown4be44fc2005-08-05 00:44:28 -04001837static int __init acpi_video_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001838{
Len Brown4be44fc2005-08-05 00:44:28 -04001839 int result = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001840
Linus Torvalds1da177e2005-04-16 15:20:36 -07001841
1842 /*
Len Brown4be44fc2005-08-05 00:44:28 -04001843 acpi_dbg_level = 0xFFFFFFFF;
1844 acpi_dbg_layer = 0x08000000;
1845 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001846
1847 acpi_video_dir = proc_mkdir(ACPI_VIDEO_CLASS, acpi_root_dir);
1848 if (!acpi_video_dir)
Patrick Mocheld550d982006-06-27 00:41:40 -04001849 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001850 acpi_video_dir->owner = THIS_MODULE;
1851
1852 result = acpi_bus_register_driver(&acpi_video_bus);
1853 if (result < 0) {
1854 remove_proc_entry(ACPI_VIDEO_CLASS, acpi_root_dir);
Patrick Mocheld550d982006-06-27 00:41:40 -04001855 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001856 }
1857
Patrick Mocheld550d982006-06-27 00:41:40 -04001858 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001859}
1860
Len Brown4be44fc2005-08-05 00:44:28 -04001861static void __exit acpi_video_exit(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001862{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001863
1864 acpi_bus_unregister_driver(&acpi_video_bus);
1865
1866 remove_proc_entry(ACPI_VIDEO_CLASS, acpi_root_dir);
1867
Patrick Mocheld550d982006-06-27 00:41:40 -04001868 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001869}
1870
1871module_init(acpi_video_init);
1872module_exit(acpi_video_exit);