blob: 6f760b51ca2deeafe7f2b571b29c3f51b1c21737 [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
Rui Zhang82cae992007-01-03 23:40:53 -050060#define ACPI_VIDEO_DISPLAY_CRT 1
61#define ACPI_VIDEO_DISPLAY_TV 2
62#define ACPI_VIDEO_DISPLAY_DVI 3
63#define ACPI_VIDEO_DISPLAY_LCD 4
64
Linus Torvalds1da177e2005-04-16 15:20:36 -070065#define _COMPONENT ACPI_VIDEO_COMPONENT
Len Brown4be44fc2005-08-05 00:44:28 -040066ACPI_MODULE_NAME("acpi_video")
Linus Torvalds1da177e2005-04-16 15:20:36 -070067
Len Brown4be44fc2005-08-05 00:44:28 -040068 MODULE_AUTHOR("Bruno Ducrot");
Linus Torvalds1da177e2005-04-16 15:20:36 -070069MODULE_DESCRIPTION(ACPI_VIDEO_DRIVER_NAME);
70MODULE_LICENSE("GPL");
71
Len Brown4be44fc2005-08-05 00:44:28 -040072static int acpi_video_bus_add(struct acpi_device *device);
73static int acpi_video_bus_remove(struct acpi_device *device, int type);
74static int acpi_video_bus_match(struct acpi_device *device,
75 struct acpi_driver *driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -070076
77static struct acpi_driver acpi_video_bus = {
78 .name = ACPI_VIDEO_DRIVER_NAME,
79 .class = ACPI_VIDEO_CLASS,
80 .ops = {
81 .add = acpi_video_bus_add,
82 .remove = acpi_video_bus_remove,
83 .match = acpi_video_bus_match,
Len Brown4be44fc2005-08-05 00:44:28 -040084 },
Linus Torvalds1da177e2005-04-16 15:20:36 -070085};
86
87struct acpi_video_bus_flags {
Len Brown4be44fc2005-08-05 00:44:28 -040088 u8 multihead:1; /* can switch video heads */
89 u8 rom:1; /* can retrieve a video rom */
90 u8 post:1; /* can configure the head to */
91 u8 reserved:5;
Linus Torvalds1da177e2005-04-16 15:20:36 -070092};
93
94struct acpi_video_bus_cap {
Len Brown4be44fc2005-08-05 00:44:28 -040095 u8 _DOS:1; /*Enable/Disable output switching */
96 u8 _DOD:1; /*Enumerate all devices attached to display adapter */
97 u8 _ROM:1; /*Get ROM Data */
98 u8 _GPD:1; /*Get POST Device */
99 u8 _SPD:1; /*Set POST Device */
100 u8 _VPO:1; /*Video POST Options */
101 u8 reserved:2;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102};
103
Len Brown4be44fc2005-08-05 00:44:28 -0400104struct acpi_video_device_attrib {
105 u32 display_index:4; /* A zero-based instance of the Display */
106 u32 display_port_attachment:4; /*This field differenates displays type */
107 u32 display_type:4; /*Describe the specific type in use */
108 u32 vendor_specific:4; /*Chipset Vendor Specifi */
109 u32 bios_can_detect:1; /*BIOS can detect the device */
110 u32 depend_on_vga:1; /*Non-VGA output device whose power is related to
111 the VGA device. */
112 u32 pipe_id:3; /*For VGA multiple-head devices. */
113 u32 reserved:10; /*Must be 0 */
114 u32 device_id_scheme:1; /*Device ID Scheme */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700115};
116
117struct acpi_video_enumerated_device {
118 union {
119 u32 int_val;
Len Brown4be44fc2005-08-05 00:44:28 -0400120 struct acpi_video_device_attrib attrib;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121 } value;
122 struct acpi_video_device *bind_info;
123};
124
125struct acpi_video_bus {
Patrick Mochele6afa0d2006-05-19 16:54:40 -0400126 struct acpi_device *device;
Len Brown4be44fc2005-08-05 00:44:28 -0400127 u8 dos_setting;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128 struct acpi_video_enumerated_device *attached_array;
Len Brown4be44fc2005-08-05 00:44:28 -0400129 u8 attached_count;
130 struct acpi_video_bus_cap cap;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131 struct acpi_video_bus_flags flags;
Len Brown4be44fc2005-08-05 00:44:28 -0400132 struct semaphore sem;
133 struct list_head video_device_list;
134 struct proc_dir_entry *dir;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135};
136
137struct acpi_video_device_flags {
Len Brown4be44fc2005-08-05 00:44:28 -0400138 u8 crt:1;
139 u8 lcd:1;
140 u8 tvout:1;
Rui Zhang82cae992007-01-03 23:40:53 -0500141 u8 dvi:1;
Len Brown4be44fc2005-08-05 00:44:28 -0400142 u8 bios:1;
143 u8 unknown:1;
Rui Zhang82cae992007-01-03 23:40:53 -0500144 u8 reserved:2;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145};
146
147struct acpi_video_device_cap {
Len Brown4be44fc2005-08-05 00:44:28 -0400148 u8 _ADR:1; /*Return the unique ID */
149 u8 _BCL:1; /*Query list of brightness control levels supported */
150 u8 _BCM:1; /*Set the brightness level */
151 u8 _DDC:1; /*Return the EDID for this device */
152 u8 _DCS:1; /*Return status of output device */
153 u8 _DGS:1; /*Query graphics state */
154 u8 _DSS:1; /*Device state set */
155 u8 _reserved:1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156};
157
158struct acpi_video_device_brightness {
Len Brown4be44fc2005-08-05 00:44:28 -0400159 int curr;
160 int count;
161 int *levels;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700162};
163
164struct acpi_video_device {
Len Brown4be44fc2005-08-05 00:44:28 -0400165 unsigned long device_id;
166 struct acpi_video_device_flags flags;
167 struct acpi_video_device_cap cap;
168 struct list_head entry;
169 struct acpi_video_bus *video;
170 struct acpi_device *dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700171 struct acpi_video_device_brightness *brightness;
172};
173
Linus Torvalds1da177e2005-04-16 15:20:36 -0700174/* bus */
175static int acpi_video_bus_info_open_fs(struct inode *inode, struct file *file);
176static struct file_operations acpi_video_bus_info_fops = {
Len Brown4be44fc2005-08-05 00:44:28 -0400177 .open = acpi_video_bus_info_open_fs,
178 .read = seq_read,
179 .llseek = seq_lseek,
180 .release = single_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700181};
182
183static int acpi_video_bus_ROM_open_fs(struct inode *inode, struct file *file);
184static struct file_operations acpi_video_bus_ROM_fops = {
Len Brown4be44fc2005-08-05 00:44:28 -0400185 .open = acpi_video_bus_ROM_open_fs,
186 .read = seq_read,
187 .llseek = seq_lseek,
188 .release = single_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700189};
190
Len Brown4be44fc2005-08-05 00:44:28 -0400191static int acpi_video_bus_POST_info_open_fs(struct inode *inode,
192 struct file *file);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700193static struct file_operations acpi_video_bus_POST_info_fops = {
Len Brown4be44fc2005-08-05 00:44:28 -0400194 .open = acpi_video_bus_POST_info_open_fs,
195 .read = seq_read,
196 .llseek = seq_lseek,
197 .release = single_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700198};
199
200static int acpi_video_bus_POST_open_fs(struct inode *inode, struct file *file);
201static struct file_operations acpi_video_bus_POST_fops = {
Len Brown4be44fc2005-08-05 00:44:28 -0400202 .open = acpi_video_bus_POST_open_fs,
203 .read = seq_read,
204 .llseek = seq_lseek,
205 .release = single_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700206};
207
Linus Torvalds1da177e2005-04-16 15:20:36 -0700208static int acpi_video_bus_DOS_open_fs(struct inode *inode, struct file *file);
209static struct file_operations acpi_video_bus_DOS_fops = {
Len Brown4be44fc2005-08-05 00:44:28 -0400210 .open = acpi_video_bus_DOS_open_fs,
211 .read = seq_read,
212 .llseek = seq_lseek,
213 .release = single_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700214};
215
216/* device */
Len Brown4be44fc2005-08-05 00:44:28 -0400217static int acpi_video_device_info_open_fs(struct inode *inode,
218 struct file *file);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700219static struct file_operations acpi_video_device_info_fops = {
Len Brown4be44fc2005-08-05 00:44:28 -0400220 .open = acpi_video_device_info_open_fs,
221 .read = seq_read,
222 .llseek = seq_lseek,
223 .release = single_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700224};
225
Len Brown4be44fc2005-08-05 00:44:28 -0400226static int acpi_video_device_state_open_fs(struct inode *inode,
227 struct file *file);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700228static struct file_operations acpi_video_device_state_fops = {
Len Brown4be44fc2005-08-05 00:44:28 -0400229 .open = acpi_video_device_state_open_fs,
230 .read = seq_read,
231 .llseek = seq_lseek,
232 .release = single_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700233};
234
Len Brown4be44fc2005-08-05 00:44:28 -0400235static int acpi_video_device_brightness_open_fs(struct inode *inode,
236 struct file *file);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700237static struct file_operations acpi_video_device_brightness_fops = {
Len Brown4be44fc2005-08-05 00:44:28 -0400238 .open = acpi_video_device_brightness_open_fs,
239 .read = seq_read,
240 .llseek = seq_lseek,
241 .release = single_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700242};
243
Len Brown4be44fc2005-08-05 00:44:28 -0400244static int acpi_video_device_EDID_open_fs(struct inode *inode,
245 struct file *file);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700246static struct file_operations acpi_video_device_EDID_fops = {
Len Brown4be44fc2005-08-05 00:44:28 -0400247 .open = acpi_video_device_EDID_open_fs,
248 .read = seq_read,
249 .llseek = seq_lseek,
250 .release = single_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700251};
252
Len Brown4be44fc2005-08-05 00:44:28 -0400253static char device_decode[][30] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700254 "motherboard VGA device",
255 "PCI VGA device",
256 "AGP VGA device",
257 "UNKNOWN",
258};
259
Len Brown4be44fc2005-08-05 00:44:28 -0400260static void acpi_video_device_notify(acpi_handle handle, u32 event, void *data);
261static void acpi_video_device_rebind(struct acpi_video_bus *video);
262static void acpi_video_device_bind(struct acpi_video_bus *video,
263 struct acpi_video_device *device);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700264static int acpi_video_device_enumerate(struct acpi_video_bus *video);
Len Brown4be44fc2005-08-05 00:44:28 -0400265static int acpi_video_switch_output(struct acpi_video_bus *video, int event);
266static int acpi_video_get_next_level(struct acpi_video_device *device,
267 u32 level_current, u32 event);
268static void acpi_video_switch_brightness(struct acpi_video_device *device,
269 int event);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700270
271/* --------------------------------------------------------------------------
272 Video Management
273 -------------------------------------------------------------------------- */
274
275/* device */
276
277static int
Len Brown4be44fc2005-08-05 00:44:28 -0400278acpi_video_device_query(struct acpi_video_device *device, unsigned long *state)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700279{
Len Brown4be44fc2005-08-05 00:44:28 -0400280 int status;
Patrick Mochel90130262006-05-19 16:54:48 -0400281
282 status = acpi_evaluate_integer(device->dev->handle, "_DGS", NULL, state);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700283
Patrick Mocheld550d982006-06-27 00:41:40 -0400284 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700285}
286
287static int
Len Brown4be44fc2005-08-05 00:44:28 -0400288acpi_video_device_get_state(struct acpi_video_device *device,
289 unsigned long *state)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700290{
Len Brown4be44fc2005-08-05 00:44:28 -0400291 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700292
Patrick Mochel90130262006-05-19 16:54:48 -0400293 status = acpi_evaluate_integer(device->dev->handle, "_DCS", NULL, state);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700294
Patrick Mocheld550d982006-06-27 00:41:40 -0400295 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700296}
297
298static int
Len Brown4be44fc2005-08-05 00:44:28 -0400299acpi_video_device_set_state(struct acpi_video_device *device, int state)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700300{
Len Brown4be44fc2005-08-05 00:44:28 -0400301 int status;
302 union acpi_object arg0 = { ACPI_TYPE_INTEGER };
303 struct acpi_object_list args = { 1, &arg0 };
Luming Yu824b5582005-08-21 19:17:00 -0400304 unsigned long ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700305
Linus Torvalds1da177e2005-04-16 15:20:36 -0700306
307 arg0.integer.value = state;
Patrick Mochel90130262006-05-19 16:54:48 -0400308 status = acpi_evaluate_integer(device->dev->handle, "_DSS", &args, &ret);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700309
Patrick Mocheld550d982006-06-27 00:41:40 -0400310 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700311}
312
313static int
Len Brown4be44fc2005-08-05 00:44:28 -0400314acpi_video_device_lcd_query_levels(struct acpi_video_device *device,
315 union acpi_object **levels)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700316{
Len Brown4be44fc2005-08-05 00:44:28 -0400317 int status;
318 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
319 union acpi_object *obj;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700320
Linus Torvalds1da177e2005-04-16 15:20:36 -0700321
322 *levels = NULL;
323
Patrick Mochel90130262006-05-19 16:54:48 -0400324 status = acpi_evaluate_object(device->dev->handle, "_BCL", NULL, &buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700325 if (!ACPI_SUCCESS(status))
Patrick Mocheld550d982006-06-27 00:41:40 -0400326 return status;
Len Brown4be44fc2005-08-05 00:44:28 -0400327 obj = (union acpi_object *)buffer.pointer;
Adrian Bunk6665bda2006-03-11 10:12:00 -0500328 if (!obj || (obj->type != ACPI_TYPE_PACKAGE)) {
Len Brown64684632006-06-26 23:41:38 -0400329 printk(KERN_ERR PREFIX "Invalid _BCL data\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700330 status = -EFAULT;
331 goto err;
332 }
333
334 *levels = obj;
335
Patrick Mocheld550d982006-06-27 00:41:40 -0400336 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700337
Len Brown4be44fc2005-08-05 00:44:28 -0400338 err:
Jesper Juhl6044ec82005-11-07 01:01:32 -0800339 kfree(buffer.pointer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700340
Patrick Mocheld550d982006-06-27 00:41:40 -0400341 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700342}
343
344static int
Len Brown4be44fc2005-08-05 00:44:28 -0400345acpi_video_device_lcd_set_level(struct acpi_video_device *device, int level)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700346{
Len Brown4be44fc2005-08-05 00:44:28 -0400347 int status;
348 union acpi_object arg0 = { ACPI_TYPE_INTEGER };
349 struct acpi_object_list args = { 1, &arg0 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700350
Linus Torvalds1da177e2005-04-16 15:20:36 -0700351
352 arg0.integer.value = level;
Patrick Mochel90130262006-05-19 16:54:48 -0400353 status = acpi_evaluate_object(device->dev->handle, "_BCM", &args, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700354
355 printk(KERN_DEBUG "set_level status: %x\n", status);
Patrick Mocheld550d982006-06-27 00:41:40 -0400356 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700357}
358
359static int
Len Brown4be44fc2005-08-05 00:44:28 -0400360acpi_video_device_lcd_get_level_current(struct acpi_video_device *device,
361 unsigned long *level)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700362{
Len Brown4be44fc2005-08-05 00:44:28 -0400363 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700364
Patrick Mochel90130262006-05-19 16:54:48 -0400365 status = acpi_evaluate_integer(device->dev->handle, "_BQC", NULL, level);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700366
Patrick Mocheld550d982006-06-27 00:41:40 -0400367 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700368}
369
370static int
Len Brown4be44fc2005-08-05 00:44:28 -0400371acpi_video_device_EDID(struct acpi_video_device *device,
372 union acpi_object **edid, ssize_t length)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700373{
Len Brown4be44fc2005-08-05 00:44:28 -0400374 int status;
375 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
376 union acpi_object *obj;
377 union acpi_object arg0 = { ACPI_TYPE_INTEGER };
378 struct acpi_object_list args = { 1, &arg0 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700379
Linus Torvalds1da177e2005-04-16 15:20:36 -0700380
381 *edid = NULL;
382
383 if (!device)
Patrick Mocheld550d982006-06-27 00:41:40 -0400384 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700385 if (length == 128)
386 arg0.integer.value = 1;
387 else if (length == 256)
388 arg0.integer.value = 2;
389 else
Patrick Mocheld550d982006-06-27 00:41:40 -0400390 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700391
Patrick Mochel90130262006-05-19 16:54:48 -0400392 status = acpi_evaluate_object(device->dev->handle, "_DDC", &args, &buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700393 if (ACPI_FAILURE(status))
Patrick Mocheld550d982006-06-27 00:41:40 -0400394 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700395
Jan Engelhardt50dd0962006-10-01 00:28:50 +0200396 obj = buffer.pointer;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700397
398 if (obj && obj->type == ACPI_TYPE_BUFFER)
399 *edid = obj;
400 else {
Len Brown64684632006-06-26 23:41:38 -0400401 printk(KERN_ERR PREFIX "Invalid _DDC data\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700402 status = -EFAULT;
403 kfree(obj);
404 }
405
Patrick Mocheld550d982006-06-27 00:41:40 -0400406 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700407}
408
Linus Torvalds1da177e2005-04-16 15:20:36 -0700409/* bus */
410
411static int
Len Brown4be44fc2005-08-05 00:44:28 -0400412acpi_video_bus_set_POST(struct acpi_video_bus *video, unsigned long option)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700413{
Len Brown4be44fc2005-08-05 00:44:28 -0400414 int status;
415 unsigned long tmp;
416 union acpi_object arg0 = { ACPI_TYPE_INTEGER };
417 struct acpi_object_list args = { 1, &arg0 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700418
Linus Torvalds1da177e2005-04-16 15:20:36 -0700419
420 arg0.integer.value = option;
421
Patrick Mochel90130262006-05-19 16:54:48 -0400422 status = acpi_evaluate_integer(video->device->handle, "_SPD", &args, &tmp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700423 if (ACPI_SUCCESS(status))
Len Brown4be44fc2005-08-05 00:44:28 -0400424 status = tmp ? (-EINVAL) : (AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700425
Patrick Mocheld550d982006-06-27 00:41:40 -0400426 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700427}
428
429static int
Len Brown4be44fc2005-08-05 00:44:28 -0400430acpi_video_bus_get_POST(struct acpi_video_bus *video, unsigned long *id)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700431{
432 int status;
433
Patrick Mochel90130262006-05-19 16:54:48 -0400434 status = acpi_evaluate_integer(video->device->handle, "_GPD", NULL, id);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700435
Patrick Mocheld550d982006-06-27 00:41:40 -0400436 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700437}
438
439static int
Len Brown4be44fc2005-08-05 00:44:28 -0400440acpi_video_bus_POST_options(struct acpi_video_bus *video,
441 unsigned long *options)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700442{
Len Brown4be44fc2005-08-05 00:44:28 -0400443 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700444
Patrick Mochel90130262006-05-19 16:54:48 -0400445 status = acpi_evaluate_integer(video->device->handle, "_VPO", NULL, options);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700446 *options &= 3;
447
Patrick Mocheld550d982006-06-27 00:41:40 -0400448 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700449}
450
451/*
452 * Arg:
453 * video : video bus device pointer
454 * bios_flag :
455 * 0. The system BIOS should NOT automatically switch(toggle)
456 * the active display output.
457 * 1. The system BIOS should automatically switch (toggle) the
458 * active display output. No swich event.
459 * 2. The _DGS value should be locked.
460 * 3. The system BIOS should not automatically switch (toggle) the
461 * active display output, but instead generate the display switch
462 * event notify code.
463 * lcd_flag :
464 * 0. The system BIOS should automatically control the brightness level
465 * of the LCD, when the power changes from AC to DC
466 * 1. The system BIOS should NOT automatically control the brightness
467 * level of the LCD, when the power changes from AC to DC.
468 * Return Value:
469 * -1 wrong arg.
470 */
471
472static int
Len Brown4be44fc2005-08-05 00:44:28 -0400473acpi_video_bus_DOS(struct acpi_video_bus *video, int bios_flag, int lcd_flag)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700474{
Len Brown4be44fc2005-08-05 00:44:28 -0400475 acpi_integer status = 0;
476 union acpi_object arg0 = { ACPI_TYPE_INTEGER };
477 struct acpi_object_list args = { 1, &arg0 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700478
Linus Torvalds1da177e2005-04-16 15:20:36 -0700479
Len Brown4be44fc2005-08-05 00:44:28 -0400480 if (bios_flag < 0 || bios_flag > 3 || lcd_flag < 0 || lcd_flag > 1) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700481 status = -1;
482 goto Failed;
483 }
484 arg0.integer.value = (lcd_flag << 2) | bios_flag;
485 video->dos_setting = arg0.integer.value;
Patrick Mochel90130262006-05-19 16:54:48 -0400486 acpi_evaluate_object(video->device->handle, "_DOS", &args, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700487
Len Brown4be44fc2005-08-05 00:44:28 -0400488 Failed:
Patrick Mocheld550d982006-06-27 00:41:40 -0400489 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700490}
491
492/*
493 * Arg:
494 * device : video output device (LCD, CRT, ..)
495 *
496 * Return Value:
497 * None
498 *
499 * Find out all required AML method defined under the output
500 * device.
501 */
502
Len Brown4be44fc2005-08-05 00:44:28 -0400503static void acpi_video_device_find_cap(struct acpi_video_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700504{
Len Brown4be44fc2005-08-05 00:44:28 -0400505 acpi_integer status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700506 acpi_handle h_dummy1;
507 int i;
508 union acpi_object *obj = NULL;
509 struct acpi_video_device_brightness *br = NULL;
510
Linus Torvalds1da177e2005-04-16 15:20:36 -0700511
Len Brown4be44fc2005-08-05 00:44:28 -0400512 memset(&device->cap, 0, 4);
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, "_ADR", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700515 device->cap._ADR = 1;
516 }
Patrick Mochel90130262006-05-19 16:54:48 -0400517 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_BCL", &h_dummy1))) {
Len Brown4be44fc2005-08-05 00:44:28 -0400518 device->cap._BCL = 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, "_BCM", &h_dummy1))) {
Len Brown4be44fc2005-08-05 00:44:28 -0400521 device->cap._BCM = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700522 }
Patrick Mochel90130262006-05-19 16:54:48 -0400523 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_DDC", &h_dummy1))) {
Len Brown4be44fc2005-08-05 00:44:28 -0400524 device->cap._DDC = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700525 }
Patrick Mochel90130262006-05-19 16:54:48 -0400526 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_DCS", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700527 device->cap._DCS = 1;
528 }
Patrick Mochel90130262006-05-19 16:54:48 -0400529 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_DGS", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700530 device->cap._DGS = 1;
531 }
Patrick Mochel90130262006-05-19 16:54:48 -0400532 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_DSS", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700533 device->cap._DSS = 1;
534 }
535
536 status = acpi_video_device_lcd_query_levels(device, &obj);
537
538 if (obj && obj->type == ACPI_TYPE_PACKAGE && obj->package.count >= 2) {
539 int count = 0;
540 union acpi_object *o;
Len Brown4be44fc2005-08-05 00:44:28 -0400541
Burman Yan36bcbec2006-12-19 12:56:11 -0800542 br = kzalloc(sizeof(*br), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700543 if (!br) {
544 printk(KERN_ERR "can't allocate memory\n");
545 } else {
Paulo Marquesd1dd0c22005-03-30 22:39:49 -0500546 br->levels = kmalloc(obj->package.count *
Len Brown4be44fc2005-08-05 00:44:28 -0400547 sizeof *(br->levels), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700548 if (!br->levels)
549 goto out;
550
551 for (i = 0; i < obj->package.count; i++) {
Len Brown4be44fc2005-08-05 00:44:28 -0400552 o = (union acpi_object *)&obj->package.
553 elements[i];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700554 if (o->type != ACPI_TYPE_INTEGER) {
Len Brown64684632006-06-26 23:41:38 -0400555 printk(KERN_ERR PREFIX "Invalid data\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700556 continue;
557 }
558 br->levels[count] = (u32) o->integer.value;
559 count++;
560 }
Len Brown4be44fc2005-08-05 00:44:28 -0400561 out:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700562 if (count < 2) {
Paulo Marquesd1dd0c22005-03-30 22:39:49 -0500563 kfree(br->levels);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700564 kfree(br);
565 } else {
566 br->count = count;
567 device->brightness = br;
Len Brown4be44fc2005-08-05 00:44:28 -0400568 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
569 "found %d brightness levels\n",
570 count));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700571 }
572 }
573 }
574
Paulo Marquesd1dd0c22005-03-30 22:39:49 -0500575 kfree(obj);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700576
Patrick Mocheld550d982006-06-27 00:41:40 -0400577 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700578}
579
580/*
581 * Arg:
582 * device : video output device (VGA)
583 *
584 * Return Value:
585 * None
586 *
587 * Find out all required AML method defined under the video bus device.
588 */
589
Len Brown4be44fc2005-08-05 00:44:28 -0400590static void acpi_video_bus_find_cap(struct acpi_video_bus *video)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700591{
Len Brown4be44fc2005-08-05 00:44:28 -0400592 acpi_handle h_dummy1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700593
Len Brown4be44fc2005-08-05 00:44:28 -0400594 memset(&video->cap, 0, 4);
Patrick Mochel90130262006-05-19 16:54:48 -0400595 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_DOS", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700596 video->cap._DOS = 1;
597 }
Patrick Mochel90130262006-05-19 16:54:48 -0400598 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_DOD", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700599 video->cap._DOD = 1;
600 }
Patrick Mochel90130262006-05-19 16:54:48 -0400601 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_ROM", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700602 video->cap._ROM = 1;
603 }
Patrick Mochel90130262006-05-19 16:54:48 -0400604 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_GPD", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700605 video->cap._GPD = 1;
606 }
Patrick Mochel90130262006-05-19 16:54:48 -0400607 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_SPD", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700608 video->cap._SPD = 1;
609 }
Patrick Mochel90130262006-05-19 16:54:48 -0400610 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_VPO", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700611 video->cap._VPO = 1;
612 }
613}
614
615/*
616 * Check whether the video bus device has required AML method to
617 * support the desired features
618 */
619
Len Brown4be44fc2005-08-05 00:44:28 -0400620static int acpi_video_bus_check(struct acpi_video_bus *video)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700621{
Len Brown4be44fc2005-08-05 00:44:28 -0400622 acpi_status status = -ENOENT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700623
Linus Torvalds1da177e2005-04-16 15:20:36 -0700624
625 if (!video)
Patrick Mocheld550d982006-06-27 00:41:40 -0400626 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700627
628 /* Since there is no HID, CID and so on for VGA driver, we have
629 * to check well known required nodes.
630 */
631
632 /* Does this device able to support video switching ? */
Len Brown4be44fc2005-08-05 00:44:28 -0400633 if (video->cap._DOS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700634 video->flags.multihead = 1;
635 status = 0;
636 }
637
638 /* Does this device able to retrieve a retrieve a video ROM ? */
Len Brown4be44fc2005-08-05 00:44:28 -0400639 if (video->cap._ROM) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700640 video->flags.rom = 1;
641 status = 0;
642 }
643
644 /* Does this device able to configure which video device to POST ? */
Len Brown4be44fc2005-08-05 00:44:28 -0400645 if (video->cap._GPD && video->cap._SPD && video->cap._VPO) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700646 video->flags.post = 1;
647 status = 0;
648 }
649
Patrick Mocheld550d982006-06-27 00:41:40 -0400650 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700651}
652
653/* --------------------------------------------------------------------------
654 FS Interface (/proc)
655 -------------------------------------------------------------------------- */
656
Len Brown4be44fc2005-08-05 00:44:28 -0400657static struct proc_dir_entry *acpi_video_dir;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700658
659/* video devices */
660
Len Brown4be44fc2005-08-05 00:44:28 -0400661static int acpi_video_device_info_seq_show(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700662{
Jan Engelhardt50dd0962006-10-01 00:28:50 +0200663 struct acpi_video_device *dev = seq->private;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700664
Linus Torvalds1da177e2005-04-16 15:20:36 -0700665
666 if (!dev)
667 goto end;
668
669 seq_printf(seq, "device_id: 0x%04x\n", (u32) dev->device_id);
670 seq_printf(seq, "type: ");
671 if (dev->flags.crt)
672 seq_printf(seq, "CRT\n");
673 else if (dev->flags.lcd)
674 seq_printf(seq, "LCD\n");
675 else if (dev->flags.tvout)
676 seq_printf(seq, "TVOUT\n");
Rui Zhang82cae992007-01-03 23:40:53 -0500677 else if (dev->flags.dvi)
678 seq_printf(seq, "DVI\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700679 else
680 seq_printf(seq, "UNKNOWN\n");
681
Len Brown4be44fc2005-08-05 00:44:28 -0400682 seq_printf(seq, "known by bios: %s\n", dev->flags.bios ? "yes" : "no");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700683
Len Brown4be44fc2005-08-05 00:44:28 -0400684 end:
Patrick Mocheld550d982006-06-27 00:41:40 -0400685 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700686}
687
688static int
Len Brown4be44fc2005-08-05 00:44:28 -0400689acpi_video_device_info_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700690{
691 return single_open(file, acpi_video_device_info_seq_show,
692 PDE(inode)->data);
693}
694
Len Brown4be44fc2005-08-05 00:44:28 -0400695static int acpi_video_device_state_seq_show(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700696{
Len Brown4be44fc2005-08-05 00:44:28 -0400697 int status;
Jan Engelhardt50dd0962006-10-01 00:28:50 +0200698 struct acpi_video_device *dev = seq->private;
Len Brown4be44fc2005-08-05 00:44:28 -0400699 unsigned long state;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700700
Linus Torvalds1da177e2005-04-16 15:20:36 -0700701
702 if (!dev)
703 goto end;
704
705 status = acpi_video_device_get_state(dev, &state);
706 seq_printf(seq, "state: ");
707 if (ACPI_SUCCESS(status))
708 seq_printf(seq, "0x%02lx\n", state);
709 else
710 seq_printf(seq, "<not supported>\n");
711
712 status = acpi_video_device_query(dev, &state);
713 seq_printf(seq, "query: ");
714 if (ACPI_SUCCESS(status))
715 seq_printf(seq, "0x%02lx\n", state);
716 else
717 seq_printf(seq, "<not supported>\n");
718
Len Brown4be44fc2005-08-05 00:44:28 -0400719 end:
Patrick Mocheld550d982006-06-27 00:41:40 -0400720 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700721}
722
723static int
Len Brown4be44fc2005-08-05 00:44:28 -0400724acpi_video_device_state_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700725{
726 return single_open(file, acpi_video_device_state_seq_show,
727 PDE(inode)->data);
728}
729
730static ssize_t
Len Brown4be44fc2005-08-05 00:44:28 -0400731acpi_video_device_write_state(struct file *file,
732 const char __user * buffer,
733 size_t count, loff_t * data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700734{
Len Brown4be44fc2005-08-05 00:44:28 -0400735 int status;
Jan Engelhardt50dd0962006-10-01 00:28:50 +0200736 struct seq_file *m = file->private_data;
737 struct acpi_video_device *dev = m->private;
Len Brown4be44fc2005-08-05 00:44:28 -0400738 char str[12] = { 0 };
739 u32 state = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700740
Linus Torvalds1da177e2005-04-16 15:20:36 -0700741
742 if (!dev || count + 1 > sizeof str)
Patrick Mocheld550d982006-06-27 00:41:40 -0400743 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700744
745 if (copy_from_user(str, buffer, count))
Patrick Mocheld550d982006-06-27 00:41:40 -0400746 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700747
748 str[count] = 0;
749 state = simple_strtoul(str, NULL, 0);
Len Brown4be44fc2005-08-05 00:44:28 -0400750 state &= ((1ul << 31) | (1ul << 30) | (1ul << 0));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700751
752 status = acpi_video_device_set_state(dev, state);
753
754 if (status)
Patrick Mocheld550d982006-06-27 00:41:40 -0400755 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700756
Patrick Mocheld550d982006-06-27 00:41:40 -0400757 return count;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700758}
759
760static int
Len Brown4be44fc2005-08-05 00:44:28 -0400761acpi_video_device_brightness_seq_show(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700762{
Jan Engelhardt50dd0962006-10-01 00:28:50 +0200763 struct acpi_video_device *dev = seq->private;
Len Brown4be44fc2005-08-05 00:44:28 -0400764 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700765
Linus Torvalds1da177e2005-04-16 15:20:36 -0700766
767 if (!dev || !dev->brightness) {
768 seq_printf(seq, "<not supported>\n");
Patrick Mocheld550d982006-06-27 00:41:40 -0400769 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700770 }
771
772 seq_printf(seq, "levels: ");
773 for (i = 0; i < dev->brightness->count; i++)
774 seq_printf(seq, " %d", dev->brightness->levels[i]);
775 seq_printf(seq, "\ncurrent: %d\n", dev->brightness->curr);
776
Patrick Mocheld550d982006-06-27 00:41:40 -0400777 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700778}
779
780static int
Len Brown4be44fc2005-08-05 00:44:28 -0400781acpi_video_device_brightness_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700782{
783 return single_open(file, acpi_video_device_brightness_seq_show,
784 PDE(inode)->data);
785}
786
787static ssize_t
Len Brown4be44fc2005-08-05 00:44:28 -0400788acpi_video_device_write_brightness(struct file *file,
789 const char __user * buffer,
790 size_t count, loff_t * data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700791{
Jan Engelhardt50dd0962006-10-01 00:28:50 +0200792 struct seq_file *m = file->private_data;
793 struct acpi_video_device *dev = m->private;
Len Brown4be44fc2005-08-05 00:44:28 -0400794 char str[4] = { 0 };
795 unsigned int level = 0;
796 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700797
Linus Torvalds1da177e2005-04-16 15:20:36 -0700798
Thomas Renninger59d399d2005-11-08 05:27:00 -0500799 if (!dev || !dev->brightness || count + 1 > sizeof str)
Patrick Mocheld550d982006-06-27 00:41:40 -0400800 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700801
802 if (copy_from_user(str, buffer, count))
Patrick Mocheld550d982006-06-27 00:41:40 -0400803 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700804
805 str[count] = 0;
806 level = simple_strtoul(str, NULL, 0);
Len Brown4be44fc2005-08-05 00:44:28 -0400807
Linus Torvalds1da177e2005-04-16 15:20:36 -0700808 if (level > 100)
Patrick Mocheld550d982006-06-27 00:41:40 -0400809 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700810
811 /* validate though the list of available levels */
812 for (i = 0; i < dev->brightness->count; i++)
813 if (level == dev->brightness->levels[i]) {
Len Brown4be44fc2005-08-05 00:44:28 -0400814 if (ACPI_SUCCESS
815 (acpi_video_device_lcd_set_level(dev, level)))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700816 dev->brightness->curr = level;
817 break;
818 }
819
Patrick Mocheld550d982006-06-27 00:41:40 -0400820 return count;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700821}
822
Len Brown4be44fc2005-08-05 00:44:28 -0400823static int acpi_video_device_EDID_seq_show(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700824{
Jan Engelhardt50dd0962006-10-01 00:28:50 +0200825 struct acpi_video_device *dev = seq->private;
Len Brown4be44fc2005-08-05 00:44:28 -0400826 int status;
827 int i;
828 union acpi_object *edid = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700829
Linus Torvalds1da177e2005-04-16 15:20:36 -0700830
831 if (!dev)
832 goto out;
833
Len Brown4be44fc2005-08-05 00:44:28 -0400834 status = acpi_video_device_EDID(dev, &edid, 128);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700835 if (ACPI_FAILURE(status)) {
Len Brown4be44fc2005-08-05 00:44:28 -0400836 status = acpi_video_device_EDID(dev, &edid, 256);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700837 }
838
839 if (ACPI_FAILURE(status)) {
840 goto out;
841 }
842
843 if (edid && edid->type == ACPI_TYPE_BUFFER) {
844 for (i = 0; i < edid->buffer.length; i++)
845 seq_putc(seq, edid->buffer.pointer[i]);
846 }
847
Len Brown4be44fc2005-08-05 00:44:28 -0400848 out:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700849 if (!edid)
850 seq_printf(seq, "<not supported>\n");
851 else
852 kfree(edid);
853
Patrick Mocheld550d982006-06-27 00:41:40 -0400854 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700855}
856
857static int
Len Brown4be44fc2005-08-05 00:44:28 -0400858acpi_video_device_EDID_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700859{
860 return single_open(file, acpi_video_device_EDID_seq_show,
861 PDE(inode)->data);
862}
863
Len Brown4be44fc2005-08-05 00:44:28 -0400864static int acpi_video_device_add_fs(struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700865{
Len Brown4be44fc2005-08-05 00:44:28 -0400866 struct proc_dir_entry *entry = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700867 struct acpi_video_device *vid_dev;
868
Linus Torvalds1da177e2005-04-16 15:20:36 -0700869
870 if (!device)
Patrick Mocheld550d982006-06-27 00:41:40 -0400871 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700872
Jan Engelhardt50dd0962006-10-01 00:28:50 +0200873 vid_dev = acpi_driver_data(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700874 if (!vid_dev)
Patrick Mocheld550d982006-06-27 00:41:40 -0400875 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700876
877 if (!acpi_device_dir(device)) {
878 acpi_device_dir(device) = proc_mkdir(acpi_device_bid(device),
Len Brown4be44fc2005-08-05 00:44:28 -0400879 vid_dev->video->dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700880 if (!acpi_device_dir(device))
Patrick Mocheld550d982006-06-27 00:41:40 -0400881 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700882 acpi_device_dir(device)->owner = THIS_MODULE;
883 }
884
885 /* 'info' [R] */
886 entry = create_proc_entry("info", S_IRUGO, acpi_device_dir(device));
887 if (!entry)
Patrick Mocheld550d982006-06-27 00:41:40 -0400888 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700889 else {
890 entry->proc_fops = &acpi_video_device_info_fops;
891 entry->data = acpi_driver_data(device);
892 entry->owner = THIS_MODULE;
893 }
894
895 /* 'state' [R/W] */
Len Brown4be44fc2005-08-05 00:44:28 -0400896 entry =
897 create_proc_entry("state", S_IFREG | S_IRUGO | S_IWUSR,
898 acpi_device_dir(device));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700899 if (!entry)
Patrick Mocheld550d982006-06-27 00:41:40 -0400900 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700901 else {
Arjan van de Vend479e902006-01-06 16:47:00 -0500902 acpi_video_device_state_fops.write = acpi_video_device_write_state;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700903 entry->proc_fops = &acpi_video_device_state_fops;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700904 entry->data = acpi_driver_data(device);
905 entry->owner = THIS_MODULE;
906 }
907
908 /* 'brightness' [R/W] */
Len Brown4be44fc2005-08-05 00:44:28 -0400909 entry =
910 create_proc_entry("brightness", S_IFREG | S_IRUGO | S_IWUSR,
911 acpi_device_dir(device));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700912 if (!entry)
Patrick Mocheld550d982006-06-27 00:41:40 -0400913 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700914 else {
Arjan van de Vend479e902006-01-06 16:47:00 -0500915 acpi_video_device_brightness_fops.write = acpi_video_device_write_brightness;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700916 entry->proc_fops = &acpi_video_device_brightness_fops;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700917 entry->data = acpi_driver_data(device);
918 entry->owner = THIS_MODULE;
919 }
920
921 /* 'EDID' [R] */
922 entry = create_proc_entry("EDID", S_IRUGO, acpi_device_dir(device));
923 if (!entry)
Patrick Mocheld550d982006-06-27 00:41:40 -0400924 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700925 else {
926 entry->proc_fops = &acpi_video_device_EDID_fops;
927 entry->data = acpi_driver_data(device);
928 entry->owner = THIS_MODULE;
929 }
930
Patrick Mocheld550d982006-06-27 00:41:40 -0400931 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700932}
933
Len Brown4be44fc2005-08-05 00:44:28 -0400934static int acpi_video_device_remove_fs(struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700935{
936 struct acpi_video_device *vid_dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700937
Jan Engelhardt50dd0962006-10-01 00:28:50 +0200938 vid_dev = acpi_driver_data(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700939 if (!vid_dev || !vid_dev->video || !vid_dev->video->dir)
Patrick Mocheld550d982006-06-27 00:41:40 -0400940 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700941
942 if (acpi_device_dir(device)) {
943 remove_proc_entry("info", acpi_device_dir(device));
944 remove_proc_entry("state", acpi_device_dir(device));
945 remove_proc_entry("brightness", acpi_device_dir(device));
946 remove_proc_entry("EDID", acpi_device_dir(device));
Len Brown4be44fc2005-08-05 00:44:28 -0400947 remove_proc_entry(acpi_device_bid(device), vid_dev->video->dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700948 acpi_device_dir(device) = NULL;
949 }
950
Patrick Mocheld550d982006-06-27 00:41:40 -0400951 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700952}
953
Linus Torvalds1da177e2005-04-16 15:20:36 -0700954/* video bus */
Len Brown4be44fc2005-08-05 00:44:28 -0400955static int acpi_video_bus_info_seq_show(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700956{
Jan Engelhardt50dd0962006-10-01 00:28:50 +0200957 struct acpi_video_bus *video = seq->private;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700958
Linus Torvalds1da177e2005-04-16 15:20:36 -0700959
960 if (!video)
961 goto end;
962
963 seq_printf(seq, "Switching heads: %s\n",
Len Brown4be44fc2005-08-05 00:44:28 -0400964 video->flags.multihead ? "yes" : "no");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700965 seq_printf(seq, "Video ROM: %s\n",
Len Brown4be44fc2005-08-05 00:44:28 -0400966 video->flags.rom ? "yes" : "no");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700967 seq_printf(seq, "Device to be POSTed on boot: %s\n",
Len Brown4be44fc2005-08-05 00:44:28 -0400968 video->flags.post ? "yes" : "no");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700969
Len Brown4be44fc2005-08-05 00:44:28 -0400970 end:
Patrick Mocheld550d982006-06-27 00:41:40 -0400971 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700972}
973
Len Brown4be44fc2005-08-05 00:44:28 -0400974static int acpi_video_bus_info_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700975{
Len Brown4be44fc2005-08-05 00:44:28 -0400976 return single_open(file, acpi_video_bus_info_seq_show,
977 PDE(inode)->data);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700978}
979
Len Brown4be44fc2005-08-05 00:44:28 -0400980static int acpi_video_bus_ROM_seq_show(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700981{
Jan Engelhardt50dd0962006-10-01 00:28:50 +0200982 struct acpi_video_bus *video = seq->private;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700983
Linus Torvalds1da177e2005-04-16 15:20:36 -0700984
985 if (!video)
986 goto end;
987
988 printk(KERN_INFO PREFIX "Please implement %s\n", __FUNCTION__);
989 seq_printf(seq, "<TODO>\n");
990
Len Brown4be44fc2005-08-05 00:44:28 -0400991 end:
Patrick Mocheld550d982006-06-27 00:41:40 -0400992 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700993}
994
Len Brown4be44fc2005-08-05 00:44:28 -0400995static int acpi_video_bus_ROM_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700996{
997 return single_open(file, acpi_video_bus_ROM_seq_show, PDE(inode)->data);
998}
999
Len Brown4be44fc2005-08-05 00:44:28 -04001000static int acpi_video_bus_POST_info_seq_show(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001001{
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001002 struct acpi_video_bus *video = seq->private;
Len Brown4be44fc2005-08-05 00:44:28 -04001003 unsigned long options;
1004 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001005
Linus Torvalds1da177e2005-04-16 15:20:36 -07001006
1007 if (!video)
1008 goto end;
1009
1010 status = acpi_video_bus_POST_options(video, &options);
1011 if (ACPI_SUCCESS(status)) {
1012 if (!(options & 1)) {
Len Brown4be44fc2005-08-05 00:44:28 -04001013 printk(KERN_WARNING PREFIX
1014 "The motherboard VGA device is not listed as a possible POST device.\n");
1015 printk(KERN_WARNING PREFIX
1016 "This indicate a BIOS bug. Please contact the manufacturer.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001017 }
1018 printk("%lx\n", options);
1019 seq_printf(seq, "can POST: <intgrated video>");
1020 if (options & 2)
1021 seq_printf(seq, " <PCI video>");
1022 if (options & 4)
1023 seq_printf(seq, " <AGP video>");
1024 seq_putc(seq, '\n');
1025 } else
1026 seq_printf(seq, "<not supported>\n");
Len Brown4be44fc2005-08-05 00:44:28 -04001027 end:
Patrick Mocheld550d982006-06-27 00:41:40 -04001028 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001029}
1030
1031static int
Len Brown4be44fc2005-08-05 00:44:28 -04001032acpi_video_bus_POST_info_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001033{
Len Brown4be44fc2005-08-05 00:44:28 -04001034 return single_open(file, acpi_video_bus_POST_info_seq_show,
1035 PDE(inode)->data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001036}
1037
Len Brown4be44fc2005-08-05 00:44:28 -04001038static int acpi_video_bus_POST_seq_show(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001039{
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001040 struct acpi_video_bus *video = seq->private;
Len Brown4be44fc2005-08-05 00:44:28 -04001041 int status;
1042 unsigned long id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001043
Linus Torvalds1da177e2005-04-16 15:20:36 -07001044
1045 if (!video)
1046 goto end;
1047
Len Brown4be44fc2005-08-05 00:44:28 -04001048 status = acpi_video_bus_get_POST(video, &id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001049 if (!ACPI_SUCCESS(status)) {
1050 seq_printf(seq, "<not supported>\n");
1051 goto end;
1052 }
Len Brown4be44fc2005-08-05 00:44:28 -04001053 seq_printf(seq, "device posted is <%s>\n", device_decode[id & 3]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001054
Len Brown4be44fc2005-08-05 00:44:28 -04001055 end:
Patrick Mocheld550d982006-06-27 00:41:40 -04001056 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001057}
1058
Len Brown4be44fc2005-08-05 00:44:28 -04001059static int acpi_video_bus_DOS_seq_show(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001060{
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001061 struct acpi_video_bus *video = seq->private;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001062
Linus Torvalds1da177e2005-04-16 15:20:36 -07001063
Len Brown4be44fc2005-08-05 00:44:28 -04001064 seq_printf(seq, "DOS setting: <%d>\n", video->dos_setting);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001065
Patrick Mocheld550d982006-06-27 00:41:40 -04001066 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001067}
1068
Len Brown4be44fc2005-08-05 00:44:28 -04001069static int acpi_video_bus_POST_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001070{
Len Brown4be44fc2005-08-05 00:44:28 -04001071 return single_open(file, acpi_video_bus_POST_seq_show,
1072 PDE(inode)->data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001073}
1074
Len Brown4be44fc2005-08-05 00:44:28 -04001075static int acpi_video_bus_DOS_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001076{
1077 return single_open(file, acpi_video_bus_DOS_seq_show, PDE(inode)->data);
1078}
1079
1080static ssize_t
Len Brown4be44fc2005-08-05 00:44:28 -04001081acpi_video_bus_write_POST(struct file *file,
1082 const char __user * buffer,
1083 size_t count, loff_t * data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001084{
Len Brown4be44fc2005-08-05 00:44:28 -04001085 int status;
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001086 struct seq_file *m = file->private_data;
1087 struct acpi_video_bus *video = m->private;
Len Brown4be44fc2005-08-05 00:44:28 -04001088 char str[12] = { 0 };
1089 unsigned long opt, options;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001090
Linus Torvalds1da177e2005-04-16 15:20:36 -07001091
Linus Torvalds1da177e2005-04-16 15:20:36 -07001092 if (!video || count + 1 > sizeof str)
Patrick Mocheld550d982006-06-27 00:41:40 -04001093 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001094
1095 status = acpi_video_bus_POST_options(video, &options);
1096 if (!ACPI_SUCCESS(status))
Patrick Mocheld550d982006-06-27 00:41:40 -04001097 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001098
1099 if (copy_from_user(str, buffer, count))
Patrick Mocheld550d982006-06-27 00:41:40 -04001100 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001101
1102 str[count] = 0;
1103 opt = strtoul(str, NULL, 0);
1104 if (opt > 3)
Patrick Mocheld550d982006-06-27 00:41:40 -04001105 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001106
1107 /* just in case an OEM 'forget' the motherboard... */
1108 options |= 1;
1109
1110 if (options & (1ul << opt)) {
Len Brown4be44fc2005-08-05 00:44:28 -04001111 status = acpi_video_bus_set_POST(video, opt);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001112 if (!ACPI_SUCCESS(status))
Patrick Mocheld550d982006-06-27 00:41:40 -04001113 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001114
1115 }
1116
Patrick Mocheld550d982006-06-27 00:41:40 -04001117 return count;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001118}
1119
1120static ssize_t
Len Brown4be44fc2005-08-05 00:44:28 -04001121acpi_video_bus_write_DOS(struct file *file,
1122 const char __user * buffer,
1123 size_t count, loff_t * data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001124{
Len Brown4be44fc2005-08-05 00:44:28 -04001125 int status;
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001126 struct seq_file *m = file->private_data;
1127 struct acpi_video_bus *video = m->private;
Len Brown4be44fc2005-08-05 00:44:28 -04001128 char str[12] = { 0 };
1129 unsigned long opt;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001130
Linus Torvalds1da177e2005-04-16 15:20:36 -07001131
Linus Torvalds1da177e2005-04-16 15:20:36 -07001132 if (!video || count + 1 > sizeof str)
Patrick Mocheld550d982006-06-27 00:41:40 -04001133 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001134
1135 if (copy_from_user(str, buffer, count))
Patrick Mocheld550d982006-06-27 00:41:40 -04001136 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001137
1138 str[count] = 0;
1139 opt = strtoul(str, NULL, 0);
1140 if (opt > 7)
Patrick Mocheld550d982006-06-27 00:41:40 -04001141 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001142
Len Brown4be44fc2005-08-05 00:44:28 -04001143 status = acpi_video_bus_DOS(video, opt & 0x3, (opt & 0x4) >> 2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001144
1145 if (!ACPI_SUCCESS(status))
Patrick Mocheld550d982006-06-27 00:41:40 -04001146 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001147
Patrick Mocheld550d982006-06-27 00:41:40 -04001148 return count;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001149}
1150
Len Brown4be44fc2005-08-05 00:44:28 -04001151static int acpi_video_bus_add_fs(struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001152{
Len Brown4be44fc2005-08-05 00:44:28 -04001153 struct proc_dir_entry *entry = NULL;
1154 struct acpi_video_bus *video;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001155
Linus Torvalds1da177e2005-04-16 15:20:36 -07001156
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001157 video = acpi_driver_data(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001158
1159 if (!acpi_device_dir(device)) {
1160 acpi_device_dir(device) = proc_mkdir(acpi_device_bid(device),
Len Brown4be44fc2005-08-05 00:44:28 -04001161 acpi_video_dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001162 if (!acpi_device_dir(device))
Patrick Mocheld550d982006-06-27 00:41:40 -04001163 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001164 video->dir = acpi_device_dir(device);
1165 acpi_device_dir(device)->owner = THIS_MODULE;
1166 }
1167
1168 /* 'info' [R] */
1169 entry = create_proc_entry("info", S_IRUGO, acpi_device_dir(device));
1170 if (!entry)
Patrick Mocheld550d982006-06-27 00:41:40 -04001171 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001172 else {
1173 entry->proc_fops = &acpi_video_bus_info_fops;
1174 entry->data = acpi_driver_data(device);
1175 entry->owner = THIS_MODULE;
1176 }
1177
1178 /* 'ROM' [R] */
1179 entry = create_proc_entry("ROM", S_IRUGO, acpi_device_dir(device));
1180 if (!entry)
Patrick Mocheld550d982006-06-27 00:41:40 -04001181 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001182 else {
1183 entry->proc_fops = &acpi_video_bus_ROM_fops;
1184 entry->data = acpi_driver_data(device);
1185 entry->owner = THIS_MODULE;
1186 }
1187
1188 /* 'POST_info' [R] */
Len Brown4be44fc2005-08-05 00:44:28 -04001189 entry =
1190 create_proc_entry("POST_info", S_IRUGO, acpi_device_dir(device));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001191 if (!entry)
Patrick Mocheld550d982006-06-27 00:41:40 -04001192 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001193 else {
1194 entry->proc_fops = &acpi_video_bus_POST_info_fops;
1195 entry->data = acpi_driver_data(device);
1196 entry->owner = THIS_MODULE;
1197 }
1198
1199 /* 'POST' [R/W] */
Len Brown4be44fc2005-08-05 00:44:28 -04001200 entry =
1201 create_proc_entry("POST", S_IFREG | S_IRUGO | S_IRUSR,
1202 acpi_device_dir(device));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001203 if (!entry)
Patrick Mocheld550d982006-06-27 00:41:40 -04001204 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001205 else {
Arjan van de Vend479e902006-01-06 16:47:00 -05001206 acpi_video_bus_POST_fops.write = acpi_video_bus_write_POST;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001207 entry->proc_fops = &acpi_video_bus_POST_fops;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001208 entry->data = acpi_driver_data(device);
1209 entry->owner = THIS_MODULE;
1210 }
1211
1212 /* 'DOS' [R/W] */
Len Brown4be44fc2005-08-05 00:44:28 -04001213 entry =
1214 create_proc_entry("DOS", S_IFREG | S_IRUGO | S_IRUSR,
1215 acpi_device_dir(device));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001216 if (!entry)
Patrick Mocheld550d982006-06-27 00:41:40 -04001217 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001218 else {
Arjan van de Vend479e902006-01-06 16:47:00 -05001219 acpi_video_bus_DOS_fops.write = acpi_video_bus_write_DOS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001220 entry->proc_fops = &acpi_video_bus_DOS_fops;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001221 entry->data = acpi_driver_data(device);
1222 entry->owner = THIS_MODULE;
1223 }
1224
Patrick Mocheld550d982006-06-27 00:41:40 -04001225 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001226}
1227
Len Brown4be44fc2005-08-05 00:44:28 -04001228static int acpi_video_bus_remove_fs(struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001229{
Len Brown4be44fc2005-08-05 00:44:28 -04001230 struct acpi_video_bus *video;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001231
Linus Torvalds1da177e2005-04-16 15:20:36 -07001232
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001233 video = acpi_driver_data(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001234
1235 if (acpi_device_dir(device)) {
1236 remove_proc_entry("info", acpi_device_dir(device));
1237 remove_proc_entry("ROM", acpi_device_dir(device));
1238 remove_proc_entry("POST_info", acpi_device_dir(device));
1239 remove_proc_entry("POST", acpi_device_dir(device));
1240 remove_proc_entry("DOS", acpi_device_dir(device));
Len Brown4be44fc2005-08-05 00:44:28 -04001241 remove_proc_entry(acpi_device_bid(device), acpi_video_dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001242 acpi_device_dir(device) = NULL;
1243 }
1244
Patrick Mocheld550d982006-06-27 00:41:40 -04001245 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001246}
1247
1248/* --------------------------------------------------------------------------
1249 Driver Interface
1250 -------------------------------------------------------------------------- */
1251
1252/* device interface */
Rui Zhang82cae992007-01-03 23:40:53 -05001253static struct acpi_video_device_attrib*
1254acpi_video_get_device_attr(struct acpi_video_bus *video, unsigned long device_id)
1255{
1256 int count;
1257
1258 for(count = 0; count < video->attached_count; count++)
1259 if((video->attached_array[count].value.int_val & 0xffff) == device_id)
1260 return &(video->attached_array[count].value.attrib);
1261 return NULL;
1262}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001263
1264static int
Len Brown4be44fc2005-08-05 00:44:28 -04001265acpi_video_bus_get_one_device(struct acpi_device *device,
1266 struct acpi_video_bus *video)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001267{
Len Brown4be44fc2005-08-05 00:44:28 -04001268 unsigned long device_id;
Yu, Luming973bf492006-04-27 05:25:00 -04001269 int status;
Len Brown4be44fc2005-08-05 00:44:28 -04001270 struct acpi_video_device *data;
Rui Zhang82cae992007-01-03 23:40:53 -05001271 struct acpi_video_device_attrib* attribute;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001272
1273 if (!device || !video)
Patrick Mocheld550d982006-06-27 00:41:40 -04001274 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001275
Len Brown4be44fc2005-08-05 00:44:28 -04001276 status =
1277 acpi_evaluate_integer(device->handle, "_ADR", NULL, &device_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001278 if (ACPI_SUCCESS(status)) {
1279
Burman Yan36bcbec2006-12-19 12:56:11 -08001280 data = kzalloc(sizeof(struct acpi_video_device), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001281 if (!data)
Patrick Mocheld550d982006-06-27 00:41:40 -04001282 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001283
Linus Torvalds1da177e2005-04-16 15:20:36 -07001284 strcpy(acpi_device_name(device), ACPI_VIDEO_DEVICE_NAME);
1285 strcpy(acpi_device_class(device), ACPI_VIDEO_CLASS);
1286 acpi_driver_data(device) = data;
1287
1288 data->device_id = device_id;
1289 data->video = video;
1290 data->dev = device;
1291
Rui Zhang82cae992007-01-03 23:40:53 -05001292 attribute = acpi_video_get_device_attr(video, device_id);
1293
1294 if((attribute != NULL) && attribute->device_id_scheme) {
1295 switch (attribute->display_type) {
1296 case ACPI_VIDEO_DISPLAY_CRT:
1297 data->flags.crt = 1;
1298 break;
1299 case ACPI_VIDEO_DISPLAY_TV:
1300 data->flags.tvout = 1;
1301 break;
1302 case ACPI_VIDEO_DISPLAY_DVI:
1303 data->flags.dvi = 1;
1304 break;
1305 case ACPI_VIDEO_DISPLAY_LCD:
1306 data->flags.lcd = 1;
1307 break;
1308 default:
1309 data->flags.unknown = 1;
1310 break;
1311 }
1312 if(attribute->bios_can_detect)
1313 data->flags.bios = 1;
1314 } else
Linus Torvalds1da177e2005-04-16 15:20:36 -07001315 data->flags.unknown = 1;
Len Brown4be44fc2005-08-05 00:44:28 -04001316
Linus Torvalds1da177e2005-04-16 15:20:36 -07001317 acpi_video_device_bind(video, data);
1318 acpi_video_device_find_cap(data);
1319
Patrick Mochel90130262006-05-19 16:54:48 -04001320 status = acpi_install_notify_handler(device->handle,
Len Brown4be44fc2005-08-05 00:44:28 -04001321 ACPI_DEVICE_NOTIFY,
1322 acpi_video_device_notify,
1323 data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001324 if (ACPI_FAILURE(status)) {
1325 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
Len Brown4be44fc2005-08-05 00:44:28 -04001326 "Error installing notify handler\n"));
Yu, Luming973bf492006-04-27 05:25:00 -04001327 if(data->brightness)
1328 kfree(data->brightness->levels);
1329 kfree(data->brightness);
1330 kfree(data);
1331 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001332 }
1333
1334 down(&video->sem);
1335 list_add_tail(&data->entry, &video->video_device_list);
1336 up(&video->sem);
1337
1338 acpi_video_device_add_fs(device);
1339
Patrick Mocheld550d982006-06-27 00:41:40 -04001340 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001341 }
1342
Patrick Mocheld550d982006-06-27 00:41:40 -04001343 return -ENOENT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001344}
1345
1346/*
1347 * Arg:
1348 * video : video bus device
1349 *
1350 * Return:
1351 * none
1352 *
1353 * Enumerate the video device list of the video bus,
1354 * bind the ids with the corresponding video devices
1355 * under the video bus.
Len Brown4be44fc2005-08-05 00:44:28 -04001356 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001357
Len Brown4be44fc2005-08-05 00:44:28 -04001358static void acpi_video_device_rebind(struct acpi_video_bus *video)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001359{
Len Brown4be44fc2005-08-05 00:44:28 -04001360 struct list_head *node, *next;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001361 list_for_each_safe(node, next, &video->video_device_list) {
Len Brown4be44fc2005-08-05 00:44:28 -04001362 struct acpi_video_device *dev =
1363 container_of(node, struct acpi_video_device, entry);
1364 acpi_video_device_bind(video, dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001365 }
1366}
1367
1368/*
1369 * Arg:
1370 * video : video bus device
1371 * device : video output device under the video
1372 * bus
1373 *
1374 * Return:
1375 * none
1376 *
1377 * Bind the ids with the corresponding video devices
1378 * under the video bus.
Len Brown4be44fc2005-08-05 00:44:28 -04001379 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001380
1381static void
Len Brown4be44fc2005-08-05 00:44:28 -04001382acpi_video_device_bind(struct acpi_video_bus *video,
1383 struct acpi_video_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001384{
Len Brown4be44fc2005-08-05 00:44:28 -04001385 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001386
1387#define IDS_VAL(i) video->attached_array[i].value.int_val
1388#define IDS_BIND(i) video->attached_array[i].bind_info
Len Brown4be44fc2005-08-05 00:44:28 -04001389
1390 for (i = 0; IDS_VAL(i) != ACPI_VIDEO_HEAD_INVALID &&
1391 i < video->attached_count; i++) {
1392 if (device->device_id == (IDS_VAL(i) & 0xffff)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001393 IDS_BIND(i) = device;
1394 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "device_bind %d\n", i));
1395 }
1396 }
1397#undef IDS_VAL
1398#undef IDS_BIND
1399}
1400
1401/*
1402 * Arg:
1403 * video : video bus device
1404 *
1405 * Return:
1406 * < 0 : error
1407 *
1408 * Call _DOD to enumerate all devices attached to display adapter
1409 *
Len Brown4be44fc2005-08-05 00:44:28 -04001410 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001411
1412static int acpi_video_device_enumerate(struct acpi_video_bus *video)
1413{
Len Brown4be44fc2005-08-05 00:44:28 -04001414 int status;
1415 int count;
1416 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001417 struct acpi_video_enumerated_device *active_device_list;
Len Brown4be44fc2005-08-05 00:44:28 -04001418 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
1419 union acpi_object *dod = NULL;
1420 union acpi_object *obj;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001421
Patrick Mochel90130262006-05-19 16:54:48 -04001422 status = acpi_evaluate_object(video->device->handle, "_DOD", NULL, &buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001423 if (!ACPI_SUCCESS(status)) {
Thomas Renningera6fc6722006-06-26 23:58:43 -04001424 ACPI_EXCEPTION((AE_INFO, status, "Evaluating _DOD"));
Patrick Mocheld550d982006-06-27 00:41:40 -04001425 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001426 }
1427
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001428 dod = buffer.pointer;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001429 if (!dod || (dod->type != ACPI_TYPE_PACKAGE)) {
Thomas Renningera6fc6722006-06-26 23:58:43 -04001430 ACPI_EXCEPTION((AE_INFO, status, "Invalid _DOD data"));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001431 status = -EFAULT;
1432 goto out;
1433 }
1434
1435 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found %d video heads in _DOD\n",
Len Brown4be44fc2005-08-05 00:44:28 -04001436 dod->package.count));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001437
Len Brown4be44fc2005-08-05 00:44:28 -04001438 active_device_list = kmalloc((1 +
1439 dod->package.count) *
1440 sizeof(struct
1441 acpi_video_enumerated_device),
1442 GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001443
1444 if (!active_device_list) {
1445 status = -ENOMEM;
1446 goto out;
1447 }
1448
1449 count = 0;
1450 for (i = 0; i < dod->package.count; i++) {
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001451 obj = &dod->package.elements[i];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001452
1453 if (obj->type != ACPI_TYPE_INTEGER) {
Len Brown64684632006-06-26 23:41:38 -04001454 printk(KERN_ERR PREFIX "Invalid _DOD data\n");
Len Brown4be44fc2005-08-05 00:44:28 -04001455 active_device_list[i].value.int_val =
1456 ACPI_VIDEO_HEAD_INVALID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001457 }
1458 active_device_list[i].value.int_val = obj->integer.value;
1459 active_device_list[i].bind_info = NULL;
Len Brown4be44fc2005-08-05 00:44:28 -04001460 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "dod element[%d] = %d\n", i,
1461 (int)obj->integer.value));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001462 count++;
1463 }
1464 active_device_list[count].value.int_val = ACPI_VIDEO_HEAD_END;
1465
Jesper Juhl6044ec82005-11-07 01:01:32 -08001466 kfree(video->attached_array);
Len Brown4be44fc2005-08-05 00:44:28 -04001467
Linus Torvalds1da177e2005-04-16 15:20:36 -07001468 video->attached_array = active_device_list;
1469 video->attached_count = count;
Len Brown4be44fc2005-08-05 00:44:28 -04001470 out:
Len Brown02438d82006-06-30 03:19:10 -04001471 kfree(buffer.pointer);
Patrick Mocheld550d982006-06-27 00:41:40 -04001472 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001473}
1474
1475/*
1476 * Arg:
1477 * video : video bus device
1478 * event : Nontify Event
1479 *
1480 * Return:
1481 * < 0 : error
1482 *
1483 * 1. Find out the current active output device.
1484 * 2. Identify the next output device to switch
1485 * 3. call _DSS to do actual switch.
Len Brown4be44fc2005-08-05 00:44:28 -04001486 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001487
Len Brown4be44fc2005-08-05 00:44:28 -04001488static int acpi_video_switch_output(struct acpi_video_bus *video, int event)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001489{
Len Brown4be44fc2005-08-05 00:44:28 -04001490 struct list_head *node, *next;
1491 struct acpi_video_device *dev = NULL;
1492 struct acpi_video_device *dev_next = NULL;
1493 struct acpi_video_device *dev_prev = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001494 unsigned long state;
1495 int status = 0;
1496
Linus Torvalds1da177e2005-04-16 15:20:36 -07001497
1498 list_for_each_safe(node, next, &video->video_device_list) {
Adrian Bunk73345712005-03-30 22:31:35 -05001499 dev = container_of(node, struct acpi_video_device, entry);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001500 status = acpi_video_device_get_state(dev, &state);
Len Brown4be44fc2005-08-05 00:44:28 -04001501 if (state & 0x2) {
1502 dev_next =
1503 container_of(node->next, struct acpi_video_device,
1504 entry);
1505 dev_prev =
1506 container_of(node->prev, struct acpi_video_device,
1507 entry);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001508 goto out;
1509 }
1510 }
1511 dev_next = container_of(node->next, struct acpi_video_device, entry);
1512 dev_prev = container_of(node->prev, struct acpi_video_device, entry);
Len Brown4be44fc2005-08-05 00:44:28 -04001513 out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001514 switch (event) {
1515 case ACPI_VIDEO_NOTIFY_CYCLE:
1516 case ACPI_VIDEO_NOTIFY_NEXT_OUTPUT:
1517 acpi_video_device_set_state(dev, 0);
1518 acpi_video_device_set_state(dev_next, 0x80000001);
1519 break;
1520 case ACPI_VIDEO_NOTIFY_PREV_OUTPUT:
1521 acpi_video_device_set_state(dev, 0);
1522 acpi_video_device_set_state(dev_prev, 0x80000001);
1523 default:
1524 break;
1525 }
1526
Patrick Mocheld550d982006-06-27 00:41:40 -04001527 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001528}
1529
Len Brown4be44fc2005-08-05 00:44:28 -04001530static int
1531acpi_video_get_next_level(struct acpi_video_device *device,
1532 u32 level_current, u32 event)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001533{
Thomas Tuttlef4715182006-12-19 12:56:14 -08001534 int min, max, min_above, max_below, i, l;
1535 max = max_below = 0;
1536 min = min_above = 255;
1537 for (i = 0; i < device->brightness->count; i++) {
1538 l = device->brightness->levels[i];
1539 if (l < min)
1540 min = l;
1541 if (l > max)
1542 max = l;
1543 if (l < min_above && l > level_current)
1544 min_above = l;
1545 if (l > max_below && l < level_current)
1546 max_below = l;
1547 }
1548
1549 switch (event) {
1550 case ACPI_VIDEO_NOTIFY_CYCLE_BRIGHTNESS:
1551 return (level_current < max) ? min_above : min;
1552 case ACPI_VIDEO_NOTIFY_INC_BRIGHTNESS:
1553 return (level_current < max) ? min_above : max;
1554 case ACPI_VIDEO_NOTIFY_DEC_BRIGHTNESS:
1555 return (level_current > min) ? max_below : min;
1556 case ACPI_VIDEO_NOTIFY_ZERO_BRIGHTNESS:
1557 case ACPI_VIDEO_NOTIFY_DISPLAY_OFF:
1558 return 0;
1559 default:
1560 return level_current;
1561 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001562}
1563
Linus Torvalds1da177e2005-04-16 15:20:36 -07001564static void
Len Brown4be44fc2005-08-05 00:44:28 -04001565acpi_video_switch_brightness(struct acpi_video_device *device, int event)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001566{
1567 unsigned long level_current, level_next;
1568 acpi_video_device_lcd_get_level_current(device, &level_current);
1569 level_next = acpi_video_get_next_level(device, level_current, event);
1570 acpi_video_device_lcd_set_level(device, level_next);
1571}
1572
1573static int
Len Brown4be44fc2005-08-05 00:44:28 -04001574acpi_video_bus_get_devices(struct acpi_video_bus *video,
1575 struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001576{
Len Brown4be44fc2005-08-05 00:44:28 -04001577 int status = 0;
1578 struct list_head *node, *next;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001579
Linus Torvalds1da177e2005-04-16 15:20:36 -07001580
1581 acpi_video_device_enumerate(video);
1582
1583 list_for_each_safe(node, next, &device->children) {
Len Brown4be44fc2005-08-05 00:44:28 -04001584 struct acpi_device *dev =
1585 list_entry(node, struct acpi_device, node);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001586
1587 if (!dev)
1588 continue;
1589
1590 status = acpi_video_bus_get_one_device(dev, video);
1591 if (ACPI_FAILURE(status)) {
Thomas Renningera6fc6722006-06-26 23:58:43 -04001592 ACPI_EXCEPTION((AE_INFO, status, "Cant attach device"));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001593 continue;
1594 }
1595
1596 }
Patrick Mocheld550d982006-06-27 00:41:40 -04001597 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001598}
1599
Len Brown4be44fc2005-08-05 00:44:28 -04001600static int acpi_video_bus_put_one_device(struct acpi_video_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001601{
Karol Kozimor031ec772005-07-30 04:18:00 -04001602 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001603 struct acpi_video_bus *video;
1604
Linus Torvalds1da177e2005-04-16 15:20:36 -07001605
1606 if (!device || !device->video)
Patrick Mocheld550d982006-06-27 00:41:40 -04001607 return -ENOENT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001608
1609 video = device->video;
1610
1611 down(&video->sem);
1612 list_del(&device->entry);
1613 up(&video->sem);
1614 acpi_video_device_remove_fs(device->dev);
1615
Patrick Mochel90130262006-05-19 16:54:48 -04001616 status = acpi_remove_notify_handler(device->dev->handle,
Len Brown4be44fc2005-08-05 00:44:28 -04001617 ACPI_DEVICE_NOTIFY,
1618 acpi_video_device_notify);
Karol Kozimor031ec772005-07-30 04:18:00 -04001619
Patrick Mocheld550d982006-06-27 00:41:40 -04001620 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001621}
1622
Len Brown4be44fc2005-08-05 00:44:28 -04001623static int acpi_video_bus_put_devices(struct acpi_video_bus *video)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001624{
Len Brown4be44fc2005-08-05 00:44:28 -04001625 int status;
1626 struct list_head *node, *next;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001627
Linus Torvalds1da177e2005-04-16 15:20:36 -07001628
1629 list_for_each_safe(node, next, &video->video_device_list) {
Len Brown4be44fc2005-08-05 00:44:28 -04001630 struct acpi_video_device *data =
1631 list_entry(node, struct acpi_video_device, entry);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001632 if (!data)
1633 continue;
1634
1635 status = acpi_video_bus_put_one_device(data);
Len Brown4be44fc2005-08-05 00:44:28 -04001636 if (ACPI_FAILURE(status))
1637 printk(KERN_WARNING PREFIX
1638 "hhuuhhuu bug in acpi video driver.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001639
Dave Jonesd384ea62006-06-24 00:33:08 -04001640 if (data->brightness)
Yu, Luming973bf492006-04-27 05:25:00 -04001641 kfree(data->brightness->levels);
Jesper Juhl6044ec82005-11-07 01:01:32 -08001642 kfree(data->brightness);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001643 kfree(data);
1644 }
1645
Patrick Mocheld550d982006-06-27 00:41:40 -04001646 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001647}
1648
1649/* acpi_video interface */
1650
Len Brown4be44fc2005-08-05 00:44:28 -04001651static int acpi_video_bus_start_devices(struct acpi_video_bus *video)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001652{
1653 return acpi_video_bus_DOS(video, 1, 0);
1654}
1655
Len Brown4be44fc2005-08-05 00:44:28 -04001656static int acpi_video_bus_stop_devices(struct acpi_video_bus *video)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001657{
1658 return acpi_video_bus_DOS(video, 0, 1);
1659}
1660
Len Brown4be44fc2005-08-05 00:44:28 -04001661static void acpi_video_bus_notify(acpi_handle handle, u32 event, void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001662{
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001663 struct acpi_video_bus *video = data;
Len Brown4be44fc2005-08-05 00:44:28 -04001664 struct acpi_device *device = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001665
Linus Torvalds1da177e2005-04-16 15:20:36 -07001666 printk("video bus notify\n");
1667
1668 if (!video)
Patrick Mocheld550d982006-06-27 00:41:40 -04001669 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001670
Patrick Mochele6afa0d2006-05-19 16:54:40 -04001671 device = video->device;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001672
1673 switch (event) {
1674 case ACPI_VIDEO_NOTIFY_SWITCH: /* User request that a switch occur,
1675 * most likely via hotkey. */
1676 acpi_bus_generate_event(device, event, 0);
1677 break;
1678
1679 case ACPI_VIDEO_NOTIFY_PROBE: /* User plug or remove a video
1680 * connector. */
1681 acpi_video_device_enumerate(video);
1682 acpi_video_device_rebind(video);
1683 acpi_video_switch_output(video, event);
1684 acpi_bus_generate_event(device, event, 0);
1685 break;
1686
Len Brown4be44fc2005-08-05 00:44:28 -04001687 case ACPI_VIDEO_NOTIFY_CYCLE: /* Cycle Display output hotkey pressed. */
1688 case ACPI_VIDEO_NOTIFY_NEXT_OUTPUT: /* Next Display output hotkey pressed. */
1689 case ACPI_VIDEO_NOTIFY_PREV_OUTPUT: /* previous Display output hotkey pressed. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001690 acpi_video_switch_output(video, event);
1691 acpi_bus_generate_event(device, event, 0);
1692 break;
1693
1694 default:
1695 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
Len Brown4be44fc2005-08-05 00:44:28 -04001696 "Unsupported event [0x%x]\n", event));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001697 break;
1698 }
1699
Patrick Mocheld550d982006-06-27 00:41:40 -04001700 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001701}
1702
Len Brown4be44fc2005-08-05 00:44:28 -04001703static void acpi_video_device_notify(acpi_handle handle, u32 event, void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001704{
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001705 struct acpi_video_device *video_device = data;
Len Brown4be44fc2005-08-05 00:44:28 -04001706 struct acpi_device *device = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001707
Linus Torvalds1da177e2005-04-16 15:20:36 -07001708
1709 printk("video device notify\n");
1710 if (!video_device)
Patrick Mocheld550d982006-06-27 00:41:40 -04001711 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001712
Patrick Mochele6afa0d2006-05-19 16:54:40 -04001713 device = video_device->dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001714
1715 switch (event) {
Len Brown4be44fc2005-08-05 00:44:28 -04001716 case ACPI_VIDEO_NOTIFY_SWITCH: /* change in status (cycle output device) */
1717 case ACPI_VIDEO_NOTIFY_PROBE: /* change in status (output device status) */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001718 acpi_bus_generate_event(device, event, 0);
1719 break;
Len Brown4be44fc2005-08-05 00:44:28 -04001720 case ACPI_VIDEO_NOTIFY_CYCLE_BRIGHTNESS: /* Cycle brightness */
1721 case ACPI_VIDEO_NOTIFY_INC_BRIGHTNESS: /* Increase brightness */
1722 case ACPI_VIDEO_NOTIFY_DEC_BRIGHTNESS: /* Decrease brightness */
1723 case ACPI_VIDEO_NOTIFY_ZERO_BRIGHTNESS: /* zero brightnesss */
1724 case ACPI_VIDEO_NOTIFY_DISPLAY_OFF: /* display device off */
1725 acpi_video_switch_brightness(video_device, event);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001726 acpi_bus_generate_event(device, event, 0);
1727 break;
1728 default:
1729 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
Len Brown4be44fc2005-08-05 00:44:28 -04001730 "Unsupported event [0x%x]\n", event));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001731 break;
1732 }
Patrick Mocheld550d982006-06-27 00:41:40 -04001733 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001734}
1735
Len Brown4be44fc2005-08-05 00:44:28 -04001736static int acpi_video_bus_add(struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001737{
Len Brown4be44fc2005-08-05 00:44:28 -04001738 int result = 0;
1739 acpi_status status = 0;
1740 struct acpi_video_bus *video = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001741
Len Brown4be44fc2005-08-05 00:44:28 -04001742
Linus Torvalds1da177e2005-04-16 15:20:36 -07001743 if (!device)
Patrick Mocheld550d982006-06-27 00:41:40 -04001744 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001745
Burman Yan36bcbec2006-12-19 12:56:11 -08001746 video = kzalloc(sizeof(struct acpi_video_bus), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001747 if (!video)
Patrick Mocheld550d982006-06-27 00:41:40 -04001748 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001749
Patrick Mochele6afa0d2006-05-19 16:54:40 -04001750 video->device = device;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001751 strcpy(acpi_device_name(device), ACPI_VIDEO_BUS_NAME);
1752 strcpy(acpi_device_class(device), ACPI_VIDEO_CLASS);
1753 acpi_driver_data(device) = video;
1754
1755 acpi_video_bus_find_cap(video);
1756 result = acpi_video_bus_check(video);
1757 if (result)
1758 goto end;
1759
1760 result = acpi_video_bus_add_fs(device);
1761 if (result)
1762 goto end;
1763
1764 init_MUTEX(&video->sem);
1765 INIT_LIST_HEAD(&video->video_device_list);
1766
1767 acpi_video_bus_get_devices(video, device);
1768 acpi_video_bus_start_devices(video);
1769
Patrick Mochel90130262006-05-19 16:54:48 -04001770 status = acpi_install_notify_handler(device->handle,
Len Brown4be44fc2005-08-05 00:44:28 -04001771 ACPI_DEVICE_NOTIFY,
1772 acpi_video_bus_notify, video);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001773 if (ACPI_FAILURE(status)) {
1774 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
Len Brown4be44fc2005-08-05 00:44:28 -04001775 "Error installing notify handler\n"));
Yu, Luming973bf492006-04-27 05:25:00 -04001776 acpi_video_bus_stop_devices(video);
1777 acpi_video_bus_put_devices(video);
1778 kfree(video->attached_array);
1779 acpi_video_bus_remove_fs(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001780 result = -ENODEV;
1781 goto end;
1782 }
1783
1784 printk(KERN_INFO PREFIX "%s [%s] (multi-head: %s rom: %s post: %s)\n",
Len Brown4be44fc2005-08-05 00:44:28 -04001785 ACPI_VIDEO_DEVICE_NAME, acpi_device_bid(device),
1786 video->flags.multihead ? "yes" : "no",
1787 video->flags.rom ? "yes" : "no",
1788 video->flags.post ? "yes" : "no");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001789
Len Brown4be44fc2005-08-05 00:44:28 -04001790 end:
Yu, Luming973bf492006-04-27 05:25:00 -04001791 if (result)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001792 kfree(video);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001793
Patrick Mocheld550d982006-06-27 00:41:40 -04001794 return result;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001795}
1796
Len Brown4be44fc2005-08-05 00:44:28 -04001797static int acpi_video_bus_remove(struct acpi_device *device, int type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001798{
Len Brown4be44fc2005-08-05 00:44:28 -04001799 acpi_status status = 0;
1800 struct acpi_video_bus *video = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001801
Linus Torvalds1da177e2005-04-16 15:20:36 -07001802
1803 if (!device || !acpi_driver_data(device))
Patrick Mocheld550d982006-06-27 00:41:40 -04001804 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001805
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001806 video = acpi_driver_data(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001807
1808 acpi_video_bus_stop_devices(video);
1809
Patrick Mochel90130262006-05-19 16:54:48 -04001810 status = acpi_remove_notify_handler(video->device->handle,
Len Brown4be44fc2005-08-05 00:44:28 -04001811 ACPI_DEVICE_NOTIFY,
1812 acpi_video_bus_notify);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001813
1814 acpi_video_bus_put_devices(video);
1815 acpi_video_bus_remove_fs(device);
1816
Jesper Juhl6044ec82005-11-07 01:01:32 -08001817 kfree(video->attached_array);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001818 kfree(video);
1819
Patrick Mocheld550d982006-06-27 00:41:40 -04001820 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001821}
1822
Linus Torvalds1da177e2005-04-16 15:20:36 -07001823static int
Len Brown4be44fc2005-08-05 00:44:28 -04001824acpi_video_bus_match(struct acpi_device *device, struct acpi_driver *driver)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001825{
Len Brown4be44fc2005-08-05 00:44:28 -04001826 acpi_handle h_dummy1;
1827 acpi_handle h_dummy2;
1828 acpi_handle h_dummy3;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001829
Linus Torvalds1da177e2005-04-16 15:20:36 -07001830
1831 if (!device || !driver)
Patrick Mocheld550d982006-06-27 00:41:40 -04001832 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001833
1834 /* Since there is no HID, CID for ACPI Video drivers, we have
1835 * to check well known required nodes for each feature we support.
1836 */
1837
1838 /* Does this device able to support video switching ? */
1839 if (ACPI_SUCCESS(acpi_get_handle(device->handle, "_DOD", &h_dummy1)) &&
1840 ACPI_SUCCESS(acpi_get_handle(device->handle, "_DOS", &h_dummy2)))
Patrick Mocheld550d982006-06-27 00:41:40 -04001841 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001842
1843 /* Does this device able to retrieve a video ROM ? */
1844 if (ACPI_SUCCESS(acpi_get_handle(device->handle, "_ROM", &h_dummy1)))
Patrick Mocheld550d982006-06-27 00:41:40 -04001845 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001846
1847 /* Does this device able to configure which video head to be POSTed ? */
1848 if (ACPI_SUCCESS(acpi_get_handle(device->handle, "_VPO", &h_dummy1)) &&
1849 ACPI_SUCCESS(acpi_get_handle(device->handle, "_GPD", &h_dummy2)) &&
1850 ACPI_SUCCESS(acpi_get_handle(device->handle, "_SPD", &h_dummy3)))
Patrick Mocheld550d982006-06-27 00:41:40 -04001851 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001852
Patrick Mocheld550d982006-06-27 00:41:40 -04001853 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001854}
1855
Len Brown4be44fc2005-08-05 00:44:28 -04001856static int __init acpi_video_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001857{
Len Brown4be44fc2005-08-05 00:44:28 -04001858 int result = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001859
Linus Torvalds1da177e2005-04-16 15:20:36 -07001860
1861 /*
Len Brown4be44fc2005-08-05 00:44:28 -04001862 acpi_dbg_level = 0xFFFFFFFF;
1863 acpi_dbg_layer = 0x08000000;
1864 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001865
1866 acpi_video_dir = proc_mkdir(ACPI_VIDEO_CLASS, acpi_root_dir);
1867 if (!acpi_video_dir)
Patrick Mocheld550d982006-06-27 00:41:40 -04001868 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001869 acpi_video_dir->owner = THIS_MODULE;
1870
1871 result = acpi_bus_register_driver(&acpi_video_bus);
1872 if (result < 0) {
1873 remove_proc_entry(ACPI_VIDEO_CLASS, acpi_root_dir);
Patrick Mocheld550d982006-06-27 00:41:40 -04001874 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001875 }
1876
Patrick Mocheld550d982006-06-27 00:41:40 -04001877 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001878}
1879
Len Brown4be44fc2005-08-05 00:44:28 -04001880static void __exit acpi_video_exit(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001881{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001882
1883 acpi_bus_unregister_driver(&acpi_video_bus);
1884
1885 remove_proc_entry(ACPI_VIDEO_CLASS, acpi_root_dir);
1886
Patrick Mocheld550d982006-06-27 00:41:40 -04001887 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001888}
1889
1890module_init(acpi_video_init);
1891module_exit(acpi_video_exit);