blob: 9feb633087a9b5f0e56cbd089c80f41a7f2e6095 [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;
121 u8 dos_setting;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122 struct acpi_video_enumerated_device *attached_array;
Len Brown4be44fc2005-08-05 00:44:28 -0400123 u8 attached_count;
124 struct acpi_video_bus_cap cap;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125 struct acpi_video_bus_flags flags;
Len Brown4be44fc2005-08-05 00:44:28 -0400126 struct semaphore sem;
127 struct list_head video_device_list;
128 struct proc_dir_entry *dir;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129};
130
131struct acpi_video_device_flags {
Len Brown4be44fc2005-08-05 00:44:28 -0400132 u8 crt:1;
133 u8 lcd:1;
134 u8 tvout:1;
135 u8 bios:1;
136 u8 unknown:1;
137 u8 reserved:3;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138};
139
140struct acpi_video_device_cap {
Len Brown4be44fc2005-08-05 00:44:28 -0400141 u8 _ADR:1; /*Return the unique ID */
142 u8 _BCL:1; /*Query list of brightness control levels supported */
143 u8 _BCM:1; /*Set the brightness level */
144 u8 _DDC:1; /*Return the EDID for this device */
145 u8 _DCS:1; /*Return status of output device */
146 u8 _DGS:1; /*Query graphics state */
147 u8 _DSS:1; /*Device state set */
148 u8 _reserved:1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700149};
150
151struct acpi_video_device_brightness {
Len Brown4be44fc2005-08-05 00:44:28 -0400152 int curr;
153 int count;
154 int *levels;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155};
156
157struct acpi_video_device {
Len Brown4be44fc2005-08-05 00:44:28 -0400158 acpi_handle handle;
159 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;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700275 status = acpi_evaluate_integer(device->handle, "_DGS", NULL, state);
276
Patrick Mocheld550d982006-06-27 00:41:40 -0400277 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700278}
279
280static int
Len Brown4be44fc2005-08-05 00:44:28 -0400281acpi_video_device_get_state(struct acpi_video_device *device,
282 unsigned long *state)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700283{
Len Brown4be44fc2005-08-05 00:44:28 -0400284 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700285
Linus Torvalds1da177e2005-04-16 15:20:36 -0700286
287 status = acpi_evaluate_integer(device->handle, "_DCS", NULL, state);
288
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;
Luming Yu824b5582005-08-21 19:17:00 -0400302 status = acpi_evaluate_integer(device->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
318 status = acpi_evaluate_object(device->handle, "_BCL", NULL, &buffer);
319 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;
347 status = acpi_evaluate_object(device->handle, "_BCM", &args, NULL);
348
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
359 status = acpi_evaluate_integer(device->handle, "_BQC", NULL, level);
360
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
386 status = acpi_evaluate_object(device->handle, "_DDC", &args, &buffer);
387 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
416 status = acpi_evaluate_integer(video->handle, "_SPD", &args, &tmp);
417 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
Linus Torvalds1da177e2005-04-16 15:20:36 -0700428
429 status = acpi_evaluate_integer(video->handle, "_GPD", NULL, id);
430
Patrick Mocheld550d982006-06-27 00:41:40 -0400431 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700432}
433
434static int
Len Brown4be44fc2005-08-05 00:44:28 -0400435acpi_video_bus_POST_options(struct acpi_video_bus *video,
436 unsigned long *options)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700437{
Len Brown4be44fc2005-08-05 00:44:28 -0400438 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700439
440 status = acpi_evaluate_integer(video->handle, "_VPO", NULL, options);
441 *options &= 3;
442
Patrick Mocheld550d982006-06-27 00:41:40 -0400443 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700444}
445
446/*
447 * Arg:
448 * video : video bus device pointer
449 * bios_flag :
450 * 0. The system BIOS should NOT automatically switch(toggle)
451 * the active display output.
452 * 1. The system BIOS should automatically switch (toggle) the
453 * active display output. No swich event.
454 * 2. The _DGS value should be locked.
455 * 3. The system BIOS should not automatically switch (toggle) the
456 * active display output, but instead generate the display switch
457 * event notify code.
458 * lcd_flag :
459 * 0. The system BIOS should automatically control the brightness level
460 * of the LCD, when the power changes from AC to DC
461 * 1. The system BIOS should NOT automatically control the brightness
462 * level of the LCD, when the power changes from AC to DC.
463 * Return Value:
464 * -1 wrong arg.
465 */
466
467static int
Len Brown4be44fc2005-08-05 00:44:28 -0400468acpi_video_bus_DOS(struct acpi_video_bus *video, int bios_flag, int lcd_flag)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700469{
Len Brown4be44fc2005-08-05 00:44:28 -0400470 acpi_integer status = 0;
471 union acpi_object arg0 = { ACPI_TYPE_INTEGER };
472 struct acpi_object_list args = { 1, &arg0 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700473
Linus Torvalds1da177e2005-04-16 15:20:36 -0700474
Len Brown4be44fc2005-08-05 00:44:28 -0400475 if (bios_flag < 0 || bios_flag > 3 || lcd_flag < 0 || lcd_flag > 1) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700476 status = -1;
477 goto Failed;
478 }
479 arg0.integer.value = (lcd_flag << 2) | bios_flag;
480 video->dos_setting = arg0.integer.value;
481 acpi_evaluate_object(video->handle, "_DOS", &args, NULL);
482
Len Brown4be44fc2005-08-05 00:44:28 -0400483 Failed:
Patrick Mocheld550d982006-06-27 00:41:40 -0400484 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700485}
486
487/*
488 * Arg:
489 * device : video output device (LCD, CRT, ..)
490 *
491 * Return Value:
492 * None
493 *
494 * Find out all required AML method defined under the output
495 * device.
496 */
497
Len Brown4be44fc2005-08-05 00:44:28 -0400498static void acpi_video_device_find_cap(struct acpi_video_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700499{
Len Brown4be44fc2005-08-05 00:44:28 -0400500 acpi_integer status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700501 acpi_handle h_dummy1;
502 int i;
503 union acpi_object *obj = NULL;
504 struct acpi_video_device_brightness *br = NULL;
505
Linus Torvalds1da177e2005-04-16 15:20:36 -0700506
Len Brown4be44fc2005-08-05 00:44:28 -0400507 memset(&device->cap, 0, 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700508
Len Brown4be44fc2005-08-05 00:44:28 -0400509 if (ACPI_SUCCESS(acpi_get_handle(device->handle, "_ADR", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700510 device->cap._ADR = 1;
511 }
Len Brown4be44fc2005-08-05 00:44:28 -0400512 if (ACPI_SUCCESS(acpi_get_handle(device->handle, "_BCL", &h_dummy1))) {
513 device->cap._BCL = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700514 }
Len Brown4be44fc2005-08-05 00:44:28 -0400515 if (ACPI_SUCCESS(acpi_get_handle(device->handle, "_BCM", &h_dummy1))) {
516 device->cap._BCM = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700517 }
Len Brown4be44fc2005-08-05 00:44:28 -0400518 if (ACPI_SUCCESS(acpi_get_handle(device->handle, "_DDC", &h_dummy1))) {
519 device->cap._DDC = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700520 }
Len Brown4be44fc2005-08-05 00:44:28 -0400521 if (ACPI_SUCCESS(acpi_get_handle(device->handle, "_DCS", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700522 device->cap._DCS = 1;
523 }
Len Brown4be44fc2005-08-05 00:44:28 -0400524 if (ACPI_SUCCESS(acpi_get_handle(device->handle, "_DGS", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700525 device->cap._DGS = 1;
526 }
Len Brown4be44fc2005-08-05 00:44:28 -0400527 if (ACPI_SUCCESS(acpi_get_handle(device->handle, "_DSS", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700528 device->cap._DSS = 1;
529 }
530
531 status = acpi_video_device_lcd_query_levels(device, &obj);
532
533 if (obj && obj->type == ACPI_TYPE_PACKAGE && obj->package.count >= 2) {
534 int count = 0;
535 union acpi_object *o;
Len Brown4be44fc2005-08-05 00:44:28 -0400536
Paulo Marquesd1dd0c22005-03-30 22:39:49 -0500537 br = kmalloc(sizeof(*br), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700538 if (!br) {
539 printk(KERN_ERR "can't allocate memory\n");
540 } else {
Paulo Marquesd1dd0c22005-03-30 22:39:49 -0500541 memset(br, 0, sizeof(*br));
542 br->levels = kmalloc(obj->package.count *
Len Brown4be44fc2005-08-05 00:44:28 -0400543 sizeof *(br->levels), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700544 if (!br->levels)
545 goto out;
546
547 for (i = 0; i < obj->package.count; i++) {
Len Brown4be44fc2005-08-05 00:44:28 -0400548 o = (union acpi_object *)&obj->package.
549 elements[i];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700550 if (o->type != ACPI_TYPE_INTEGER) {
Len Brown64684632006-06-26 23:41:38 -0400551 printk(KERN_ERR PREFIX "Invalid data\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700552 continue;
553 }
554 br->levels[count] = (u32) o->integer.value;
555 count++;
556 }
Len Brown4be44fc2005-08-05 00:44:28 -0400557 out:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700558 if (count < 2) {
Paulo Marquesd1dd0c22005-03-30 22:39:49 -0500559 kfree(br->levels);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700560 kfree(br);
561 } else {
562 br->count = count;
563 device->brightness = br;
Len Brown4be44fc2005-08-05 00:44:28 -0400564 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
565 "found %d brightness levels\n",
566 count));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700567 }
568 }
569 }
570
Paulo Marquesd1dd0c22005-03-30 22:39:49 -0500571 kfree(obj);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700572
Patrick Mocheld550d982006-06-27 00:41:40 -0400573 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700574}
575
576/*
577 * Arg:
578 * device : video output device (VGA)
579 *
580 * Return Value:
581 * None
582 *
583 * Find out all required AML method defined under the video bus device.
584 */
585
Len Brown4be44fc2005-08-05 00:44:28 -0400586static void acpi_video_bus_find_cap(struct acpi_video_bus *video)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700587{
Len Brown4be44fc2005-08-05 00:44:28 -0400588 acpi_handle h_dummy1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700589
Len Brown4be44fc2005-08-05 00:44:28 -0400590 memset(&video->cap, 0, 4);
591 if (ACPI_SUCCESS(acpi_get_handle(video->handle, "_DOS", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700592 video->cap._DOS = 1;
593 }
Len Brown4be44fc2005-08-05 00:44:28 -0400594 if (ACPI_SUCCESS(acpi_get_handle(video->handle, "_DOD", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700595 video->cap._DOD = 1;
596 }
Len Brown4be44fc2005-08-05 00:44:28 -0400597 if (ACPI_SUCCESS(acpi_get_handle(video->handle, "_ROM", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700598 video->cap._ROM = 1;
599 }
Len Brown4be44fc2005-08-05 00:44:28 -0400600 if (ACPI_SUCCESS(acpi_get_handle(video->handle, "_GPD", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700601 video->cap._GPD = 1;
602 }
Len Brown4be44fc2005-08-05 00:44:28 -0400603 if (ACPI_SUCCESS(acpi_get_handle(video->handle, "_SPD", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700604 video->cap._SPD = 1;
605 }
Len Brown4be44fc2005-08-05 00:44:28 -0400606 if (ACPI_SUCCESS(acpi_get_handle(video->handle, "_VPO", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700607 video->cap._VPO = 1;
608 }
609}
610
611/*
612 * Check whether the video bus device has required AML method to
613 * support the desired features
614 */
615
Len Brown4be44fc2005-08-05 00:44:28 -0400616static int acpi_video_bus_check(struct acpi_video_bus *video)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700617{
Len Brown4be44fc2005-08-05 00:44:28 -0400618 acpi_status status = -ENOENT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700619
Linus Torvalds1da177e2005-04-16 15:20:36 -0700620
621 if (!video)
Patrick Mocheld550d982006-06-27 00:41:40 -0400622 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700623
624 /* Since there is no HID, CID and so on for VGA driver, we have
625 * to check well known required nodes.
626 */
627
628 /* Does this device able to support video switching ? */
Len Brown4be44fc2005-08-05 00:44:28 -0400629 if (video->cap._DOS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700630 video->flags.multihead = 1;
631 status = 0;
632 }
633
634 /* Does this device able to retrieve a retrieve a video ROM ? */
Len Brown4be44fc2005-08-05 00:44:28 -0400635 if (video->cap._ROM) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700636 video->flags.rom = 1;
637 status = 0;
638 }
639
640 /* Does this device able to configure which video device to POST ? */
Len Brown4be44fc2005-08-05 00:44:28 -0400641 if (video->cap._GPD && video->cap._SPD && video->cap._VPO) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700642 video->flags.post = 1;
643 status = 0;
644 }
645
Patrick Mocheld550d982006-06-27 00:41:40 -0400646 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700647}
648
649/* --------------------------------------------------------------------------
650 FS Interface (/proc)
651 -------------------------------------------------------------------------- */
652
Len Brown4be44fc2005-08-05 00:44:28 -0400653static struct proc_dir_entry *acpi_video_dir;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700654
655/* video devices */
656
Len Brown4be44fc2005-08-05 00:44:28 -0400657static int acpi_video_device_info_seq_show(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700658{
Len Brown4be44fc2005-08-05 00:44:28 -0400659 struct acpi_video_device *dev =
660 (struct acpi_video_device *)seq->private;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700661
Linus Torvalds1da177e2005-04-16 15:20:36 -0700662
663 if (!dev)
664 goto end;
665
666 seq_printf(seq, "device_id: 0x%04x\n", (u32) dev->device_id);
667 seq_printf(seq, "type: ");
668 if (dev->flags.crt)
669 seq_printf(seq, "CRT\n");
670 else if (dev->flags.lcd)
671 seq_printf(seq, "LCD\n");
672 else if (dev->flags.tvout)
673 seq_printf(seq, "TVOUT\n");
674 else
675 seq_printf(seq, "UNKNOWN\n");
676
Len Brown4be44fc2005-08-05 00:44:28 -0400677 seq_printf(seq, "known by bios: %s\n", dev->flags.bios ? "yes" : "no");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700678
Len Brown4be44fc2005-08-05 00:44:28 -0400679 end:
Patrick Mocheld550d982006-06-27 00:41:40 -0400680 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700681}
682
683static int
Len Brown4be44fc2005-08-05 00:44:28 -0400684acpi_video_device_info_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700685{
686 return single_open(file, acpi_video_device_info_seq_show,
687 PDE(inode)->data);
688}
689
Len Brown4be44fc2005-08-05 00:44:28 -0400690static int acpi_video_device_state_seq_show(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700691{
Len Brown4be44fc2005-08-05 00:44:28 -0400692 int status;
693 struct acpi_video_device *dev =
694 (struct acpi_video_device *)seq->private;
695 unsigned long state;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700696
Linus Torvalds1da177e2005-04-16 15:20:36 -0700697
698 if (!dev)
699 goto end;
700
701 status = acpi_video_device_get_state(dev, &state);
702 seq_printf(seq, "state: ");
703 if (ACPI_SUCCESS(status))
704 seq_printf(seq, "0x%02lx\n", state);
705 else
706 seq_printf(seq, "<not supported>\n");
707
708 status = acpi_video_device_query(dev, &state);
709 seq_printf(seq, "query: ");
710 if (ACPI_SUCCESS(status))
711 seq_printf(seq, "0x%02lx\n", state);
712 else
713 seq_printf(seq, "<not supported>\n");
714
Len Brown4be44fc2005-08-05 00:44:28 -0400715 end:
Patrick Mocheld550d982006-06-27 00:41:40 -0400716 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700717}
718
719static int
Len Brown4be44fc2005-08-05 00:44:28 -0400720acpi_video_device_state_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700721{
722 return single_open(file, acpi_video_device_state_seq_show,
723 PDE(inode)->data);
724}
725
726static ssize_t
Len Brown4be44fc2005-08-05 00:44:28 -0400727acpi_video_device_write_state(struct file *file,
728 const char __user * buffer,
729 size_t count, loff_t * data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700730{
Len Brown4be44fc2005-08-05 00:44:28 -0400731 int status;
732 struct seq_file *m = (struct seq_file *)file->private_data;
733 struct acpi_video_device *dev = (struct acpi_video_device *)m->private;
734 char str[12] = { 0 };
735 u32 state = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700736
Linus Torvalds1da177e2005-04-16 15:20:36 -0700737
738 if (!dev || count + 1 > sizeof str)
Patrick Mocheld550d982006-06-27 00:41:40 -0400739 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700740
741 if (copy_from_user(str, buffer, count))
Patrick Mocheld550d982006-06-27 00:41:40 -0400742 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700743
744 str[count] = 0;
745 state = simple_strtoul(str, NULL, 0);
Len Brown4be44fc2005-08-05 00:44:28 -0400746 state &= ((1ul << 31) | (1ul << 30) | (1ul << 0));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700747
748 status = acpi_video_device_set_state(dev, state);
749
750 if (status)
Patrick Mocheld550d982006-06-27 00:41:40 -0400751 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700752
Patrick Mocheld550d982006-06-27 00:41:40 -0400753 return count;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700754}
755
756static int
Len Brown4be44fc2005-08-05 00:44:28 -0400757acpi_video_device_brightness_seq_show(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700758{
Len Brown4be44fc2005-08-05 00:44:28 -0400759 struct acpi_video_device *dev =
760 (struct acpi_video_device *)seq->private;
761 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700762
Linus Torvalds1da177e2005-04-16 15:20:36 -0700763
764 if (!dev || !dev->brightness) {
765 seq_printf(seq, "<not supported>\n");
Patrick Mocheld550d982006-06-27 00:41:40 -0400766 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700767 }
768
769 seq_printf(seq, "levels: ");
770 for (i = 0; i < dev->brightness->count; i++)
771 seq_printf(seq, " %d", dev->brightness->levels[i]);
772 seq_printf(seq, "\ncurrent: %d\n", dev->brightness->curr);
773
Patrick Mocheld550d982006-06-27 00:41:40 -0400774 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700775}
776
777static int
Len Brown4be44fc2005-08-05 00:44:28 -0400778acpi_video_device_brightness_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700779{
780 return single_open(file, acpi_video_device_brightness_seq_show,
781 PDE(inode)->data);
782}
783
784static ssize_t
Len Brown4be44fc2005-08-05 00:44:28 -0400785acpi_video_device_write_brightness(struct file *file,
786 const char __user * buffer,
787 size_t count, loff_t * data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700788{
Len Brown4be44fc2005-08-05 00:44:28 -0400789 struct seq_file *m = (struct seq_file *)file->private_data;
790 struct acpi_video_device *dev = (struct acpi_video_device *)m->private;
791 char str[4] = { 0 };
792 unsigned int level = 0;
793 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700794
Linus Torvalds1da177e2005-04-16 15:20:36 -0700795
Thomas Renninger59d399d2005-11-08 05:27:00 -0500796 if (!dev || !dev->brightness || count + 1 > sizeof str)
Patrick Mocheld550d982006-06-27 00:41:40 -0400797 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700798
799 if (copy_from_user(str, buffer, count))
Patrick Mocheld550d982006-06-27 00:41:40 -0400800 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700801
802 str[count] = 0;
803 level = simple_strtoul(str, NULL, 0);
Len Brown4be44fc2005-08-05 00:44:28 -0400804
Linus Torvalds1da177e2005-04-16 15:20:36 -0700805 if (level > 100)
Patrick Mocheld550d982006-06-27 00:41:40 -0400806 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700807
808 /* validate though the list of available levels */
809 for (i = 0; i < dev->brightness->count; i++)
810 if (level == dev->brightness->levels[i]) {
Len Brown4be44fc2005-08-05 00:44:28 -0400811 if (ACPI_SUCCESS
812 (acpi_video_device_lcd_set_level(dev, level)))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700813 dev->brightness->curr = level;
814 break;
815 }
816
Patrick Mocheld550d982006-06-27 00:41:40 -0400817 return count;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700818}
819
Len Brown4be44fc2005-08-05 00:44:28 -0400820static int acpi_video_device_EDID_seq_show(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700821{
Len Brown4be44fc2005-08-05 00:44:28 -0400822 struct acpi_video_device *dev =
823 (struct acpi_video_device *)seq->private;
824 int status;
825 int i;
826 union acpi_object *edid = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700827
Linus Torvalds1da177e2005-04-16 15:20:36 -0700828
829 if (!dev)
830 goto out;
831
Len Brown4be44fc2005-08-05 00:44:28 -0400832 status = acpi_video_device_EDID(dev, &edid, 128);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700833 if (ACPI_FAILURE(status)) {
Len Brown4be44fc2005-08-05 00:44:28 -0400834 status = acpi_video_device_EDID(dev, &edid, 256);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700835 }
836
837 if (ACPI_FAILURE(status)) {
838 goto out;
839 }
840
841 if (edid && edid->type == ACPI_TYPE_BUFFER) {
842 for (i = 0; i < edid->buffer.length; i++)
843 seq_putc(seq, edid->buffer.pointer[i]);
844 }
845
Len Brown4be44fc2005-08-05 00:44:28 -0400846 out:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700847 if (!edid)
848 seq_printf(seq, "<not supported>\n");
849 else
850 kfree(edid);
851
Patrick Mocheld550d982006-06-27 00:41:40 -0400852 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700853}
854
855static int
Len Brown4be44fc2005-08-05 00:44:28 -0400856acpi_video_device_EDID_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700857{
858 return single_open(file, acpi_video_device_EDID_seq_show,
859 PDE(inode)->data);
860}
861
Len Brown4be44fc2005-08-05 00:44:28 -0400862static int acpi_video_device_add_fs(struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700863{
Len Brown4be44fc2005-08-05 00:44:28 -0400864 struct proc_dir_entry *entry = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700865 struct acpi_video_device *vid_dev;
866
Linus Torvalds1da177e2005-04-16 15:20:36 -0700867
868 if (!device)
Patrick Mocheld550d982006-06-27 00:41:40 -0400869 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700870
Len Brown4be44fc2005-08-05 00:44:28 -0400871 vid_dev = (struct acpi_video_device *)acpi_driver_data(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700872 if (!vid_dev)
Patrick Mocheld550d982006-06-27 00:41:40 -0400873 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700874
875 if (!acpi_device_dir(device)) {
876 acpi_device_dir(device) = proc_mkdir(acpi_device_bid(device),
Len Brown4be44fc2005-08-05 00:44:28 -0400877 vid_dev->video->dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700878 if (!acpi_device_dir(device))
Patrick Mocheld550d982006-06-27 00:41:40 -0400879 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700880 acpi_device_dir(device)->owner = THIS_MODULE;
881 }
882
883 /* 'info' [R] */
884 entry = create_proc_entry("info", S_IRUGO, acpi_device_dir(device));
885 if (!entry)
Patrick Mocheld550d982006-06-27 00:41:40 -0400886 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700887 else {
888 entry->proc_fops = &acpi_video_device_info_fops;
889 entry->data = acpi_driver_data(device);
890 entry->owner = THIS_MODULE;
891 }
892
893 /* 'state' [R/W] */
Len Brown4be44fc2005-08-05 00:44:28 -0400894 entry =
895 create_proc_entry("state", S_IFREG | S_IRUGO | S_IWUSR,
896 acpi_device_dir(device));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700897 if (!entry)
Patrick Mocheld550d982006-06-27 00:41:40 -0400898 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700899 else {
Arjan van de Vend479e902006-01-06 16:47:00 -0500900 acpi_video_device_state_fops.write = acpi_video_device_write_state;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700901 entry->proc_fops = &acpi_video_device_state_fops;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700902 entry->data = acpi_driver_data(device);
903 entry->owner = THIS_MODULE;
904 }
905
906 /* 'brightness' [R/W] */
Len Brown4be44fc2005-08-05 00:44:28 -0400907 entry =
908 create_proc_entry("brightness", S_IFREG | S_IRUGO | S_IWUSR,
909 acpi_device_dir(device));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700910 if (!entry)
Patrick Mocheld550d982006-06-27 00:41:40 -0400911 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700912 else {
Arjan van de Vend479e902006-01-06 16:47:00 -0500913 acpi_video_device_brightness_fops.write = acpi_video_device_write_brightness;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700914 entry->proc_fops = &acpi_video_device_brightness_fops;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700915 entry->data = acpi_driver_data(device);
916 entry->owner = THIS_MODULE;
917 }
918
919 /* 'EDID' [R] */
920 entry = create_proc_entry("EDID", S_IRUGO, acpi_device_dir(device));
921 if (!entry)
Patrick Mocheld550d982006-06-27 00:41:40 -0400922 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700923 else {
924 entry->proc_fops = &acpi_video_device_EDID_fops;
925 entry->data = acpi_driver_data(device);
926 entry->owner = THIS_MODULE;
927 }
928
Patrick Mocheld550d982006-06-27 00:41:40 -0400929 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700930}
931
Len Brown4be44fc2005-08-05 00:44:28 -0400932static int acpi_video_device_remove_fs(struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700933{
934 struct acpi_video_device *vid_dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700935
Len Brown4be44fc2005-08-05 00:44:28 -0400936 vid_dev = (struct acpi_video_device *)acpi_driver_data(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700937 if (!vid_dev || !vid_dev->video || !vid_dev->video->dir)
Patrick Mocheld550d982006-06-27 00:41:40 -0400938 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700939
940 if (acpi_device_dir(device)) {
941 remove_proc_entry("info", acpi_device_dir(device));
942 remove_proc_entry("state", acpi_device_dir(device));
943 remove_proc_entry("brightness", acpi_device_dir(device));
944 remove_proc_entry("EDID", acpi_device_dir(device));
Len Brown4be44fc2005-08-05 00:44:28 -0400945 remove_proc_entry(acpi_device_bid(device), vid_dev->video->dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700946 acpi_device_dir(device) = NULL;
947 }
948
Patrick Mocheld550d982006-06-27 00:41:40 -0400949 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700950}
951
Linus Torvalds1da177e2005-04-16 15:20:36 -0700952/* video bus */
Len Brown4be44fc2005-08-05 00:44:28 -0400953static int acpi_video_bus_info_seq_show(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700954{
Len Brown4be44fc2005-08-05 00:44:28 -0400955 struct acpi_video_bus *video = (struct acpi_video_bus *)seq->private;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700956
Linus Torvalds1da177e2005-04-16 15:20:36 -0700957
958 if (!video)
959 goto end;
960
961 seq_printf(seq, "Switching heads: %s\n",
Len Brown4be44fc2005-08-05 00:44:28 -0400962 video->flags.multihead ? "yes" : "no");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700963 seq_printf(seq, "Video ROM: %s\n",
Len Brown4be44fc2005-08-05 00:44:28 -0400964 video->flags.rom ? "yes" : "no");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700965 seq_printf(seq, "Device to be POSTed on boot: %s\n",
Len Brown4be44fc2005-08-05 00:44:28 -0400966 video->flags.post ? "yes" : "no");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700967
Len Brown4be44fc2005-08-05 00:44:28 -0400968 end:
Patrick Mocheld550d982006-06-27 00:41:40 -0400969 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700970}
971
Len Brown4be44fc2005-08-05 00:44:28 -0400972static int acpi_video_bus_info_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700973{
Len Brown4be44fc2005-08-05 00:44:28 -0400974 return single_open(file, acpi_video_bus_info_seq_show,
975 PDE(inode)->data);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700976}
977
Len Brown4be44fc2005-08-05 00:44:28 -0400978static int acpi_video_bus_ROM_seq_show(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700979{
Len Brown4be44fc2005-08-05 00:44:28 -0400980 struct acpi_video_bus *video = (struct acpi_video_bus *)seq->private;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700981
Linus Torvalds1da177e2005-04-16 15:20:36 -0700982
983 if (!video)
984 goto end;
985
986 printk(KERN_INFO PREFIX "Please implement %s\n", __FUNCTION__);
987 seq_printf(seq, "<TODO>\n");
988
Len Brown4be44fc2005-08-05 00:44:28 -0400989 end:
Patrick Mocheld550d982006-06-27 00:41:40 -0400990 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700991}
992
Len Brown4be44fc2005-08-05 00:44:28 -0400993static int acpi_video_bus_ROM_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700994{
995 return single_open(file, acpi_video_bus_ROM_seq_show, PDE(inode)->data);
996}
997
Len Brown4be44fc2005-08-05 00:44:28 -0400998static int acpi_video_bus_POST_info_seq_show(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700999{
Len Brown4be44fc2005-08-05 00:44:28 -04001000 struct acpi_video_bus *video = (struct acpi_video_bus *)seq->private;
1001 unsigned long options;
1002 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001003
Linus Torvalds1da177e2005-04-16 15:20:36 -07001004
1005 if (!video)
1006 goto end;
1007
1008 status = acpi_video_bus_POST_options(video, &options);
1009 if (ACPI_SUCCESS(status)) {
1010 if (!(options & 1)) {
Len Brown4be44fc2005-08-05 00:44:28 -04001011 printk(KERN_WARNING PREFIX
1012 "The motherboard VGA device is not listed as a possible POST device.\n");
1013 printk(KERN_WARNING PREFIX
1014 "This indicate a BIOS bug. Please contact the manufacturer.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001015 }
1016 printk("%lx\n", options);
1017 seq_printf(seq, "can POST: <intgrated video>");
1018 if (options & 2)
1019 seq_printf(seq, " <PCI video>");
1020 if (options & 4)
1021 seq_printf(seq, " <AGP video>");
1022 seq_putc(seq, '\n');
1023 } else
1024 seq_printf(seq, "<not supported>\n");
Len Brown4be44fc2005-08-05 00:44:28 -04001025 end:
Patrick Mocheld550d982006-06-27 00:41:40 -04001026 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001027}
1028
1029static int
Len Brown4be44fc2005-08-05 00:44:28 -04001030acpi_video_bus_POST_info_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001031{
Len Brown4be44fc2005-08-05 00:44:28 -04001032 return single_open(file, acpi_video_bus_POST_info_seq_show,
1033 PDE(inode)->data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001034}
1035
Len Brown4be44fc2005-08-05 00:44:28 -04001036static int acpi_video_bus_POST_seq_show(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001037{
Len Brown4be44fc2005-08-05 00:44:28 -04001038 struct acpi_video_bus *video = (struct acpi_video_bus *)seq->private;
1039 int status;
1040 unsigned long id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001041
Linus Torvalds1da177e2005-04-16 15:20:36 -07001042
1043 if (!video)
1044 goto end;
1045
Len Brown4be44fc2005-08-05 00:44:28 -04001046 status = acpi_video_bus_get_POST(video, &id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001047 if (!ACPI_SUCCESS(status)) {
1048 seq_printf(seq, "<not supported>\n");
1049 goto end;
1050 }
Len Brown4be44fc2005-08-05 00:44:28 -04001051 seq_printf(seq, "device posted is <%s>\n", device_decode[id & 3]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001052
Len Brown4be44fc2005-08-05 00:44:28 -04001053 end:
Patrick Mocheld550d982006-06-27 00:41:40 -04001054 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001055}
1056
Len Brown4be44fc2005-08-05 00:44:28 -04001057static int acpi_video_bus_DOS_seq_show(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001058{
Len Brown4be44fc2005-08-05 00:44:28 -04001059 struct acpi_video_bus *video = (struct acpi_video_bus *)seq->private;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001060
Linus Torvalds1da177e2005-04-16 15:20:36 -07001061
Len Brown4be44fc2005-08-05 00:44:28 -04001062 seq_printf(seq, "DOS setting: <%d>\n", video->dos_setting);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001063
Patrick Mocheld550d982006-06-27 00:41:40 -04001064 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001065}
1066
Len Brown4be44fc2005-08-05 00:44:28 -04001067static int acpi_video_bus_POST_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001068{
Len Brown4be44fc2005-08-05 00:44:28 -04001069 return single_open(file, acpi_video_bus_POST_seq_show,
1070 PDE(inode)->data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001071}
1072
Len Brown4be44fc2005-08-05 00:44:28 -04001073static int acpi_video_bus_DOS_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001074{
1075 return single_open(file, acpi_video_bus_DOS_seq_show, PDE(inode)->data);
1076}
1077
1078static ssize_t
Len Brown4be44fc2005-08-05 00:44:28 -04001079acpi_video_bus_write_POST(struct file *file,
1080 const char __user * buffer,
1081 size_t count, loff_t * data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001082{
Len Brown4be44fc2005-08-05 00:44:28 -04001083 int status;
1084 struct seq_file *m = (struct seq_file *)file->private_data;
1085 struct acpi_video_bus *video = (struct acpi_video_bus *)m->private;
1086 char str[12] = { 0 };
1087 unsigned long opt, options;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001088
Linus Torvalds1da177e2005-04-16 15:20:36 -07001089
Linus Torvalds1da177e2005-04-16 15:20:36 -07001090 if (!video || count + 1 > sizeof str)
Patrick Mocheld550d982006-06-27 00:41:40 -04001091 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001092
1093 status = acpi_video_bus_POST_options(video, &options);
1094 if (!ACPI_SUCCESS(status))
Patrick Mocheld550d982006-06-27 00:41:40 -04001095 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001096
1097 if (copy_from_user(str, buffer, count))
Patrick Mocheld550d982006-06-27 00:41:40 -04001098 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001099
1100 str[count] = 0;
1101 opt = strtoul(str, NULL, 0);
1102 if (opt > 3)
Patrick Mocheld550d982006-06-27 00:41:40 -04001103 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001104
1105 /* just in case an OEM 'forget' the motherboard... */
1106 options |= 1;
1107
1108 if (options & (1ul << opt)) {
Len Brown4be44fc2005-08-05 00:44:28 -04001109 status = acpi_video_bus_set_POST(video, opt);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001110 if (!ACPI_SUCCESS(status))
Patrick Mocheld550d982006-06-27 00:41:40 -04001111 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001112
1113 }
1114
Patrick Mocheld550d982006-06-27 00:41:40 -04001115 return count;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001116}
1117
1118static ssize_t
Len Brown4be44fc2005-08-05 00:44:28 -04001119acpi_video_bus_write_DOS(struct file *file,
1120 const char __user * buffer,
1121 size_t count, loff_t * data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001122{
Len Brown4be44fc2005-08-05 00:44:28 -04001123 int status;
1124 struct seq_file *m = (struct seq_file *)file->private_data;
1125 struct acpi_video_bus *video = (struct acpi_video_bus *)m->private;
1126 char str[12] = { 0 };
1127 unsigned long opt;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001128
Linus Torvalds1da177e2005-04-16 15:20:36 -07001129
Linus Torvalds1da177e2005-04-16 15:20:36 -07001130 if (!video || count + 1 > sizeof str)
Patrick Mocheld550d982006-06-27 00:41:40 -04001131 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001132
1133 if (copy_from_user(str, buffer, count))
Patrick Mocheld550d982006-06-27 00:41:40 -04001134 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001135
1136 str[count] = 0;
1137 opt = strtoul(str, NULL, 0);
1138 if (opt > 7)
Patrick Mocheld550d982006-06-27 00:41:40 -04001139 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001140
Len Brown4be44fc2005-08-05 00:44:28 -04001141 status = acpi_video_bus_DOS(video, opt & 0x3, (opt & 0x4) >> 2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001142
1143 if (!ACPI_SUCCESS(status))
Patrick Mocheld550d982006-06-27 00:41:40 -04001144 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001145
Patrick Mocheld550d982006-06-27 00:41:40 -04001146 return count;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001147}
1148
Len Brown4be44fc2005-08-05 00:44:28 -04001149static int acpi_video_bus_add_fs(struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001150{
Len Brown4be44fc2005-08-05 00:44:28 -04001151 struct proc_dir_entry *entry = NULL;
1152 struct acpi_video_bus *video;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001153
Linus Torvalds1da177e2005-04-16 15:20:36 -07001154
Len Brown4be44fc2005-08-05 00:44:28 -04001155 video = (struct acpi_video_bus *)acpi_driver_data(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001156
1157 if (!acpi_device_dir(device)) {
1158 acpi_device_dir(device) = proc_mkdir(acpi_device_bid(device),
Len Brown4be44fc2005-08-05 00:44:28 -04001159 acpi_video_dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001160 if (!acpi_device_dir(device))
Patrick Mocheld550d982006-06-27 00:41:40 -04001161 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001162 video->dir = acpi_device_dir(device);
1163 acpi_device_dir(device)->owner = THIS_MODULE;
1164 }
1165
1166 /* 'info' [R] */
1167 entry = create_proc_entry("info", S_IRUGO, acpi_device_dir(device));
1168 if (!entry)
Patrick Mocheld550d982006-06-27 00:41:40 -04001169 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001170 else {
1171 entry->proc_fops = &acpi_video_bus_info_fops;
1172 entry->data = acpi_driver_data(device);
1173 entry->owner = THIS_MODULE;
1174 }
1175
1176 /* 'ROM' [R] */
1177 entry = create_proc_entry("ROM", S_IRUGO, acpi_device_dir(device));
1178 if (!entry)
Patrick Mocheld550d982006-06-27 00:41:40 -04001179 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001180 else {
1181 entry->proc_fops = &acpi_video_bus_ROM_fops;
1182 entry->data = acpi_driver_data(device);
1183 entry->owner = THIS_MODULE;
1184 }
1185
1186 /* 'POST_info' [R] */
Len Brown4be44fc2005-08-05 00:44:28 -04001187 entry =
1188 create_proc_entry("POST_info", S_IRUGO, acpi_device_dir(device));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001189 if (!entry)
Patrick Mocheld550d982006-06-27 00:41:40 -04001190 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001191 else {
1192 entry->proc_fops = &acpi_video_bus_POST_info_fops;
1193 entry->data = acpi_driver_data(device);
1194 entry->owner = THIS_MODULE;
1195 }
1196
1197 /* 'POST' [R/W] */
Len Brown4be44fc2005-08-05 00:44:28 -04001198 entry =
1199 create_proc_entry("POST", S_IFREG | S_IRUGO | S_IRUSR,
1200 acpi_device_dir(device));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001201 if (!entry)
Patrick Mocheld550d982006-06-27 00:41:40 -04001202 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001203 else {
Arjan van de Vend479e902006-01-06 16:47:00 -05001204 acpi_video_bus_POST_fops.write = acpi_video_bus_write_POST;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001205 entry->proc_fops = &acpi_video_bus_POST_fops;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001206 entry->data = acpi_driver_data(device);
1207 entry->owner = THIS_MODULE;
1208 }
1209
1210 /* 'DOS' [R/W] */
Len Brown4be44fc2005-08-05 00:44:28 -04001211 entry =
1212 create_proc_entry("DOS", S_IFREG | S_IRUGO | S_IRUSR,
1213 acpi_device_dir(device));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001214 if (!entry)
Patrick Mocheld550d982006-06-27 00:41:40 -04001215 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001216 else {
Arjan van de Vend479e902006-01-06 16:47:00 -05001217 acpi_video_bus_DOS_fops.write = acpi_video_bus_write_DOS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001218 entry->proc_fops = &acpi_video_bus_DOS_fops;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001219 entry->data = acpi_driver_data(device);
1220 entry->owner = THIS_MODULE;
1221 }
1222
Patrick Mocheld550d982006-06-27 00:41:40 -04001223 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001224}
1225
Len Brown4be44fc2005-08-05 00:44:28 -04001226static int acpi_video_bus_remove_fs(struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001227{
Len Brown4be44fc2005-08-05 00:44:28 -04001228 struct acpi_video_bus *video;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001229
Linus Torvalds1da177e2005-04-16 15:20:36 -07001230
Len Brown4be44fc2005-08-05 00:44:28 -04001231 video = (struct acpi_video_bus *)acpi_driver_data(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001232
1233 if (acpi_device_dir(device)) {
1234 remove_proc_entry("info", acpi_device_dir(device));
1235 remove_proc_entry("ROM", acpi_device_dir(device));
1236 remove_proc_entry("POST_info", acpi_device_dir(device));
1237 remove_proc_entry("POST", acpi_device_dir(device));
1238 remove_proc_entry("DOS", acpi_device_dir(device));
Len Brown4be44fc2005-08-05 00:44:28 -04001239 remove_proc_entry(acpi_device_bid(device), acpi_video_dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001240 acpi_device_dir(device) = NULL;
1241 }
1242
Patrick Mocheld550d982006-06-27 00:41:40 -04001243 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001244}
1245
1246/* --------------------------------------------------------------------------
1247 Driver Interface
1248 -------------------------------------------------------------------------- */
1249
1250/* device interface */
1251
1252static int
Len Brown4be44fc2005-08-05 00:44:28 -04001253acpi_video_bus_get_one_device(struct acpi_device *device,
1254 struct acpi_video_bus *video)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001255{
Len Brown4be44fc2005-08-05 00:44:28 -04001256 unsigned long device_id;
Yu, Luming973bf492006-04-27 05:25:00 -04001257 int status;
Len Brown4be44fc2005-08-05 00:44:28 -04001258 struct acpi_video_device *data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001259
Linus Torvalds1da177e2005-04-16 15:20:36 -07001260
1261 if (!device || !video)
Patrick Mocheld550d982006-06-27 00:41:40 -04001262 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001263
Len Brown4be44fc2005-08-05 00:44:28 -04001264 status =
1265 acpi_evaluate_integer(device->handle, "_ADR", NULL, &device_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001266 if (ACPI_SUCCESS(status)) {
1267
1268 data = kmalloc(sizeof(struct acpi_video_device), GFP_KERNEL);
1269 if (!data)
Patrick Mocheld550d982006-06-27 00:41:40 -04001270 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001271
1272 memset(data, 0, sizeof(struct acpi_video_device));
1273
1274 data->handle = device->handle;
1275 strcpy(acpi_device_name(device), ACPI_VIDEO_DEVICE_NAME);
1276 strcpy(acpi_device_class(device), ACPI_VIDEO_CLASS);
1277 acpi_driver_data(device) = data;
1278
1279 data->device_id = device_id;
1280 data->video = video;
1281 data->dev = device;
1282
1283 switch (device_id & 0xffff) {
1284 case 0x0100:
1285 data->flags.crt = 1;
1286 break;
1287 case 0x0400:
1288 data->flags.lcd = 1;
1289 break;
1290 case 0x0200:
1291 data->flags.tvout = 1;
1292 break;
1293 default:
1294 data->flags.unknown = 1;
1295 break;
1296 }
Len Brown4be44fc2005-08-05 00:44:28 -04001297
Linus Torvalds1da177e2005-04-16 15:20:36 -07001298 acpi_video_device_bind(video, data);
1299 acpi_video_device_find_cap(data);
1300
1301 status = acpi_install_notify_handler(data->handle,
Len Brown4be44fc2005-08-05 00:44:28 -04001302 ACPI_DEVICE_NOTIFY,
1303 acpi_video_device_notify,
1304 data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001305 if (ACPI_FAILURE(status)) {
1306 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
Len Brown4be44fc2005-08-05 00:44:28 -04001307 "Error installing notify handler\n"));
Yu, Luming973bf492006-04-27 05:25:00 -04001308 if(data->brightness)
1309 kfree(data->brightness->levels);
1310 kfree(data->brightness);
1311 kfree(data);
1312 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001313 }
1314
1315 down(&video->sem);
1316 list_add_tail(&data->entry, &video->video_device_list);
1317 up(&video->sem);
1318
1319 acpi_video_device_add_fs(device);
1320
Patrick Mocheld550d982006-06-27 00:41:40 -04001321 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001322 }
1323
Patrick Mocheld550d982006-06-27 00:41:40 -04001324 return -ENOENT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001325}
1326
1327/*
1328 * Arg:
1329 * video : video bus device
1330 *
1331 * Return:
1332 * none
1333 *
1334 * Enumerate the video device list of the video bus,
1335 * bind the ids with the corresponding video devices
1336 * under the video bus.
Len Brown4be44fc2005-08-05 00:44:28 -04001337 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001338
Len Brown4be44fc2005-08-05 00:44:28 -04001339static void acpi_video_device_rebind(struct acpi_video_bus *video)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001340{
Len Brown4be44fc2005-08-05 00:44:28 -04001341 struct list_head *node, *next;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001342 list_for_each_safe(node, next, &video->video_device_list) {
Len Brown4be44fc2005-08-05 00:44:28 -04001343 struct acpi_video_device *dev =
1344 container_of(node, struct acpi_video_device, entry);
1345 acpi_video_device_bind(video, dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001346 }
1347}
1348
1349/*
1350 * Arg:
1351 * video : video bus device
1352 * device : video output device under the video
1353 * bus
1354 *
1355 * Return:
1356 * none
1357 *
1358 * Bind the ids with the corresponding video devices
1359 * under the video bus.
Len Brown4be44fc2005-08-05 00:44:28 -04001360 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001361
1362static void
Len Brown4be44fc2005-08-05 00:44:28 -04001363acpi_video_device_bind(struct acpi_video_bus *video,
1364 struct acpi_video_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001365{
Len Brown4be44fc2005-08-05 00:44:28 -04001366 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001367
1368#define IDS_VAL(i) video->attached_array[i].value.int_val
1369#define IDS_BIND(i) video->attached_array[i].bind_info
Len Brown4be44fc2005-08-05 00:44:28 -04001370
1371 for (i = 0; IDS_VAL(i) != ACPI_VIDEO_HEAD_INVALID &&
1372 i < video->attached_count; i++) {
1373 if (device->device_id == (IDS_VAL(i) & 0xffff)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001374 IDS_BIND(i) = device;
1375 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "device_bind %d\n", i));
1376 }
1377 }
1378#undef IDS_VAL
1379#undef IDS_BIND
1380}
1381
1382/*
1383 * Arg:
1384 * video : video bus device
1385 *
1386 * Return:
1387 * < 0 : error
1388 *
1389 * Call _DOD to enumerate all devices attached to display adapter
1390 *
Len Brown4be44fc2005-08-05 00:44:28 -04001391 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001392
1393static int acpi_video_device_enumerate(struct acpi_video_bus *video)
1394{
Len Brown4be44fc2005-08-05 00:44:28 -04001395 int status;
1396 int count;
1397 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001398 struct acpi_video_enumerated_device *active_device_list;
Len Brown4be44fc2005-08-05 00:44:28 -04001399 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
1400 union acpi_object *dod = NULL;
1401 union acpi_object *obj;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001402
Linus Torvalds1da177e2005-04-16 15:20:36 -07001403
1404 status = acpi_evaluate_object(video->handle, "_DOD", NULL, &buffer);
1405 if (!ACPI_SUCCESS(status)) {
Thomas Renningera6fc6722006-06-26 23:58:43 -04001406 ACPI_EXCEPTION((AE_INFO, status, "Evaluating _DOD"));
Patrick Mocheld550d982006-06-27 00:41:40 -04001407 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001408 }
1409
Len Brown4be44fc2005-08-05 00:44:28 -04001410 dod = (union acpi_object *)buffer.pointer;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001411 if (!dod || (dod->type != ACPI_TYPE_PACKAGE)) {
Thomas Renningera6fc6722006-06-26 23:58:43 -04001412 ACPI_EXCEPTION((AE_INFO, status, "Invalid _DOD data"));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001413 status = -EFAULT;
1414 goto out;
1415 }
1416
1417 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found %d video heads in _DOD\n",
Len Brown4be44fc2005-08-05 00:44:28 -04001418 dod->package.count));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001419
Len Brown4be44fc2005-08-05 00:44:28 -04001420 active_device_list = kmalloc((1 +
1421 dod->package.count) *
1422 sizeof(struct
1423 acpi_video_enumerated_device),
1424 GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001425
1426 if (!active_device_list) {
1427 status = -ENOMEM;
1428 goto out;
1429 }
1430
1431 count = 0;
1432 for (i = 0; i < dod->package.count; i++) {
Len Brown4be44fc2005-08-05 00:44:28 -04001433 obj = (union acpi_object *)&dod->package.elements[i];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001434
1435 if (obj->type != ACPI_TYPE_INTEGER) {
Len Brown64684632006-06-26 23:41:38 -04001436 printk(KERN_ERR PREFIX "Invalid _DOD data\n");
Len Brown4be44fc2005-08-05 00:44:28 -04001437 active_device_list[i].value.int_val =
1438 ACPI_VIDEO_HEAD_INVALID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001439 }
1440 active_device_list[i].value.int_val = obj->integer.value;
1441 active_device_list[i].bind_info = NULL;
Len Brown4be44fc2005-08-05 00:44:28 -04001442 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "dod element[%d] = %d\n", i,
1443 (int)obj->integer.value));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001444 count++;
1445 }
1446 active_device_list[count].value.int_val = ACPI_VIDEO_HEAD_END;
1447
Jesper Juhl6044ec82005-11-07 01:01:32 -08001448 kfree(video->attached_array);
Len Brown4be44fc2005-08-05 00:44:28 -04001449
Linus Torvalds1da177e2005-04-16 15:20:36 -07001450 video->attached_array = active_device_list;
1451 video->attached_count = count;
Len Brown4be44fc2005-08-05 00:44:28 -04001452 out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001453 acpi_os_free(buffer.pointer);
Patrick Mocheld550d982006-06-27 00:41:40 -04001454 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001455}
1456
1457/*
1458 * Arg:
1459 * video : video bus device
1460 * event : Nontify Event
1461 *
1462 * Return:
1463 * < 0 : error
1464 *
1465 * 1. Find out the current active output device.
1466 * 2. Identify the next output device to switch
1467 * 3. call _DSS to do actual switch.
Len Brown4be44fc2005-08-05 00:44:28 -04001468 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001469
Len Brown4be44fc2005-08-05 00:44:28 -04001470static int acpi_video_switch_output(struct acpi_video_bus *video, int event)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001471{
Len Brown4be44fc2005-08-05 00:44:28 -04001472 struct list_head *node, *next;
1473 struct acpi_video_device *dev = NULL;
1474 struct acpi_video_device *dev_next = NULL;
1475 struct acpi_video_device *dev_prev = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001476 unsigned long state;
1477 int status = 0;
1478
Linus Torvalds1da177e2005-04-16 15:20:36 -07001479
1480 list_for_each_safe(node, next, &video->video_device_list) {
Adrian Bunk73345712005-03-30 22:31:35 -05001481 dev = container_of(node, struct acpi_video_device, entry);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001482 status = acpi_video_device_get_state(dev, &state);
Len Brown4be44fc2005-08-05 00:44:28 -04001483 if (state & 0x2) {
1484 dev_next =
1485 container_of(node->next, struct acpi_video_device,
1486 entry);
1487 dev_prev =
1488 container_of(node->prev, struct acpi_video_device,
1489 entry);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001490 goto out;
1491 }
1492 }
1493 dev_next = container_of(node->next, struct acpi_video_device, entry);
1494 dev_prev = container_of(node->prev, struct acpi_video_device, entry);
Len Brown4be44fc2005-08-05 00:44:28 -04001495 out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001496 switch (event) {
1497 case ACPI_VIDEO_NOTIFY_CYCLE:
1498 case ACPI_VIDEO_NOTIFY_NEXT_OUTPUT:
1499 acpi_video_device_set_state(dev, 0);
1500 acpi_video_device_set_state(dev_next, 0x80000001);
1501 break;
1502 case ACPI_VIDEO_NOTIFY_PREV_OUTPUT:
1503 acpi_video_device_set_state(dev, 0);
1504 acpi_video_device_set_state(dev_prev, 0x80000001);
1505 default:
1506 break;
1507 }
1508
Patrick Mocheld550d982006-06-27 00:41:40 -04001509 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001510}
1511
Len Brown4be44fc2005-08-05 00:44:28 -04001512static int
1513acpi_video_get_next_level(struct acpi_video_device *device,
1514 u32 level_current, u32 event)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001515{
Len Brown4be44fc2005-08-05 00:44:28 -04001516 /*Fix me */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001517 return level_current;
1518}
1519
Linus Torvalds1da177e2005-04-16 15:20:36 -07001520static void
Len Brown4be44fc2005-08-05 00:44:28 -04001521acpi_video_switch_brightness(struct acpi_video_device *device, int event)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001522{
1523 unsigned long level_current, level_next;
1524 acpi_video_device_lcd_get_level_current(device, &level_current);
1525 level_next = acpi_video_get_next_level(device, level_current, event);
1526 acpi_video_device_lcd_set_level(device, level_next);
1527}
1528
1529static int
Len Brown4be44fc2005-08-05 00:44:28 -04001530acpi_video_bus_get_devices(struct acpi_video_bus *video,
1531 struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001532{
Len Brown4be44fc2005-08-05 00:44:28 -04001533 int status = 0;
1534 struct list_head *node, *next;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001535
Linus Torvalds1da177e2005-04-16 15:20:36 -07001536
1537 acpi_video_device_enumerate(video);
1538
1539 list_for_each_safe(node, next, &device->children) {
Len Brown4be44fc2005-08-05 00:44:28 -04001540 struct acpi_device *dev =
1541 list_entry(node, struct acpi_device, node);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001542
1543 if (!dev)
1544 continue;
1545
1546 status = acpi_video_bus_get_one_device(dev, video);
1547 if (ACPI_FAILURE(status)) {
Thomas Renningera6fc6722006-06-26 23:58:43 -04001548 ACPI_EXCEPTION((AE_INFO, status, "Cant attach device"));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001549 continue;
1550 }
1551
1552 }
Patrick Mocheld550d982006-06-27 00:41:40 -04001553 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001554}
1555
Len Brown4be44fc2005-08-05 00:44:28 -04001556static int acpi_video_bus_put_one_device(struct acpi_video_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001557{
Karol Kozimor031ec772005-07-30 04:18:00 -04001558 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001559 struct acpi_video_bus *video;
1560
Linus Torvalds1da177e2005-04-16 15:20:36 -07001561
1562 if (!device || !device->video)
Patrick Mocheld550d982006-06-27 00:41:40 -04001563 return -ENOENT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001564
1565 video = device->video;
1566
1567 down(&video->sem);
1568 list_del(&device->entry);
1569 up(&video->sem);
1570 acpi_video_device_remove_fs(device->dev);
1571
Karol Kozimor031ec772005-07-30 04:18:00 -04001572 status = acpi_remove_notify_handler(device->handle,
Len Brown4be44fc2005-08-05 00:44:28 -04001573 ACPI_DEVICE_NOTIFY,
1574 acpi_video_device_notify);
Karol Kozimor031ec772005-07-30 04:18:00 -04001575
Patrick Mocheld550d982006-06-27 00:41:40 -04001576 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001577}
1578
Len Brown4be44fc2005-08-05 00:44:28 -04001579static int acpi_video_bus_put_devices(struct acpi_video_bus *video)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001580{
Len Brown4be44fc2005-08-05 00:44:28 -04001581 int status;
1582 struct list_head *node, *next;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001583
Linus Torvalds1da177e2005-04-16 15:20:36 -07001584
1585 list_for_each_safe(node, next, &video->video_device_list) {
Len Brown4be44fc2005-08-05 00:44:28 -04001586 struct acpi_video_device *data =
1587 list_entry(node, struct acpi_video_device, entry);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001588 if (!data)
1589 continue;
1590
1591 status = acpi_video_bus_put_one_device(data);
Len Brown4be44fc2005-08-05 00:44:28 -04001592 if (ACPI_FAILURE(status))
1593 printk(KERN_WARNING PREFIX
1594 "hhuuhhuu bug in acpi video driver.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001595
Dave Jonesd384ea62006-06-24 00:33:08 -04001596 if (data->brightness)
Yu, Luming973bf492006-04-27 05:25:00 -04001597 kfree(data->brightness->levels);
Jesper Juhl6044ec82005-11-07 01:01:32 -08001598 kfree(data->brightness);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001599 kfree(data);
1600 }
1601
Patrick Mocheld550d982006-06-27 00:41:40 -04001602 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001603}
1604
1605/* acpi_video interface */
1606
Len Brown4be44fc2005-08-05 00:44:28 -04001607static int acpi_video_bus_start_devices(struct acpi_video_bus *video)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001608{
1609 return acpi_video_bus_DOS(video, 1, 0);
1610}
1611
Len Brown4be44fc2005-08-05 00:44:28 -04001612static int acpi_video_bus_stop_devices(struct acpi_video_bus *video)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001613{
1614 return acpi_video_bus_DOS(video, 0, 1);
1615}
1616
Len Brown4be44fc2005-08-05 00:44:28 -04001617static void acpi_video_bus_notify(acpi_handle handle, u32 event, void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001618{
Len Brown4be44fc2005-08-05 00:44:28 -04001619 struct acpi_video_bus *video = (struct acpi_video_bus *)data;
1620 struct acpi_device *device = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001621
Linus Torvalds1da177e2005-04-16 15:20:36 -07001622 printk("video bus notify\n");
1623
1624 if (!video)
Patrick Mocheld550d982006-06-27 00:41:40 -04001625 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001626
1627 if (acpi_bus_get_device(handle, &device))
Patrick Mocheld550d982006-06-27 00:41:40 -04001628 return;
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
1671 if (acpi_bus_get_device(handle, &device))
Patrick Mocheld550d982006-06-27 00:41:40 -04001672 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001673
1674 switch (event) {
Len Brown4be44fc2005-08-05 00:44:28 -04001675 case ACPI_VIDEO_NOTIFY_SWITCH: /* change in status (cycle output device) */
1676 case ACPI_VIDEO_NOTIFY_PROBE: /* change in status (output device status) */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001677 acpi_bus_generate_event(device, event, 0);
1678 break;
Len Brown4be44fc2005-08-05 00:44:28 -04001679 case ACPI_VIDEO_NOTIFY_CYCLE_BRIGHTNESS: /* Cycle brightness */
1680 case ACPI_VIDEO_NOTIFY_INC_BRIGHTNESS: /* Increase brightness */
1681 case ACPI_VIDEO_NOTIFY_DEC_BRIGHTNESS: /* Decrease brightness */
1682 case ACPI_VIDEO_NOTIFY_ZERO_BRIGHTNESS: /* zero brightnesss */
1683 case ACPI_VIDEO_NOTIFY_DISPLAY_OFF: /* display device off */
1684 acpi_video_switch_brightness(video_device, event);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001685 acpi_bus_generate_event(device, event, 0);
1686 break;
1687 default:
1688 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
Len Brown4be44fc2005-08-05 00:44:28 -04001689 "Unsupported event [0x%x]\n", event));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001690 break;
1691 }
Patrick Mocheld550d982006-06-27 00:41:40 -04001692 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001693}
1694
Len Brown4be44fc2005-08-05 00:44:28 -04001695static int acpi_video_bus_add(struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001696{
Len Brown4be44fc2005-08-05 00:44:28 -04001697 int result = 0;
1698 acpi_status status = 0;
1699 struct acpi_video_bus *video = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001700
Len Brown4be44fc2005-08-05 00:44:28 -04001701
Linus Torvalds1da177e2005-04-16 15:20:36 -07001702 if (!device)
Patrick Mocheld550d982006-06-27 00:41:40 -04001703 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001704
1705 video = kmalloc(sizeof(struct acpi_video_bus), GFP_KERNEL);
1706 if (!video)
Patrick Mocheld550d982006-06-27 00:41:40 -04001707 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001708 memset(video, 0, sizeof(struct acpi_video_bus));
1709
1710 video->handle = device->handle;
1711 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);