blob: 00d25b34725549e86b739354cf5f972e6a10831f [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
Yu Luming2f3d0002006-11-11 02:40:34 +080035#include <linux/backlight.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070036#include <asm/uaccess.h>
37
38#include <acpi/acpi_bus.h>
39#include <acpi/acpi_drivers.h>
40
41#define ACPI_VIDEO_COMPONENT 0x08000000
42#define ACPI_VIDEO_CLASS "video"
Linus Torvalds1da177e2005-04-16 15:20:36 -070043#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)
Yu Luming2f3d0002006-11-11 02:40:34 +080059#define MAX_NAME_LEN 20
Linus Torvalds1da177e2005-04-16 15:20:36 -070060
Rui Zhang82cae992007-01-03 23:40:53 -050061#define ACPI_VIDEO_DISPLAY_CRT 1
62#define ACPI_VIDEO_DISPLAY_TV 2
63#define ACPI_VIDEO_DISPLAY_DVI 3
64#define ACPI_VIDEO_DISPLAY_LCD 4
65
Linus Torvalds1da177e2005-04-16 15:20:36 -070066#define _COMPONENT ACPI_VIDEO_COMPONENT
Len Brownf52fd662007-02-12 22:42:12 -050067ACPI_MODULE_NAME("video");
Linus Torvalds1da177e2005-04-16 15:20:36 -070068
Len Brownf52fd662007-02-12 22:42:12 -050069MODULE_AUTHOR("Bruno Ducrot");
Len Brown7cda93e2007-02-12 23:50:02 -050070MODULE_DESCRIPTION("ACPI Video Driver");
Linus Torvalds1da177e2005-04-16 15:20:36 -070071MODULE_LICENSE("GPL");
72
Len Brown4be44fc2005-08-05 00:44:28 -040073static int acpi_video_bus_add(struct acpi_device *device);
74static int acpi_video_bus_remove(struct acpi_device *device, int type);
Linus Torvalds1da177e2005-04-16 15:20:36 -070075
76static struct acpi_driver acpi_video_bus = {
Len Brownc2b67052007-02-12 23:33:40 -050077 .name = "video",
Linus Torvalds1da177e2005-04-16 15:20:36 -070078 .class = ACPI_VIDEO_CLASS,
Zhang Ruiae843332006-12-07 20:57:10 +080079 .ids = ACPI_VIDEO_HID,
Linus Torvalds1da177e2005-04-16 15:20:36 -070080 .ops = {
81 .add = acpi_video_bus_add,
82 .remove = acpi_video_bus_remove,
Len Brown4be44fc2005-08-05 00:44:28 -040083 },
Linus Torvalds1da177e2005-04-16 15:20:36 -070084};
85
86struct acpi_video_bus_flags {
Len Brown4be44fc2005-08-05 00:44:28 -040087 u8 multihead:1; /* can switch video heads */
88 u8 rom:1; /* can retrieve a video rom */
89 u8 post:1; /* can configure the head to */
90 u8 reserved:5;
Linus Torvalds1da177e2005-04-16 15:20:36 -070091};
92
93struct acpi_video_bus_cap {
Len Brown4be44fc2005-08-05 00:44:28 -040094 u8 _DOS:1; /*Enable/Disable output switching */
95 u8 _DOD:1; /*Enumerate all devices attached to display adapter */
96 u8 _ROM:1; /*Get ROM Data */
97 u8 _GPD:1; /*Get POST Device */
98 u8 _SPD:1; /*Set POST Device */
99 u8 _VPO:1; /*Video POST Options */
100 u8 reserved:2;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101};
102
Len Brown4be44fc2005-08-05 00:44:28 -0400103struct acpi_video_device_attrib {
104 u32 display_index:4; /* A zero-based instance of the Display */
Julius Volz98fb8fe2007-02-20 16:38:40 +0100105 u32 display_port_attachment:4; /*This field differentiates the display type */
Len Brown4be44fc2005-08-05 00:44:28 -0400106 u32 display_type:4; /*Describe the specific type in use */
Julius Volz98fb8fe2007-02-20 16:38:40 +0100107 u32 vendor_specific:4; /*Chipset Vendor Specific */
Len Brown4be44fc2005-08-05 00:44:28 -0400108 u32 bios_can_detect:1; /*BIOS can detect the device */
109 u32 depend_on_vga:1; /*Non-VGA output device whose power is related to
110 the VGA device. */
111 u32 pipe_id:3; /*For VGA multiple-head devices. */
112 u32 reserved:10; /*Must be 0 */
113 u32 device_id_scheme:1; /*Device ID Scheme */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114};
115
116struct acpi_video_enumerated_device {
117 union {
118 u32 int_val;
Len Brown4be44fc2005-08-05 00:44:28 -0400119 struct acpi_video_device_attrib attrib;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120 } value;
121 struct acpi_video_device *bind_info;
122};
123
124struct acpi_video_bus {
Patrick Mochele6afa0d2006-05-19 16:54:40 -0400125 struct acpi_device *device;
Len Brown4be44fc2005-08-05 00:44:28 -0400126 u8 dos_setting;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127 struct acpi_video_enumerated_device *attached_array;
Len Brown4be44fc2005-08-05 00:44:28 -0400128 u8 attached_count;
129 struct acpi_video_bus_cap cap;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130 struct acpi_video_bus_flags flags;
Len Brown4be44fc2005-08-05 00:44:28 -0400131 struct semaphore sem;
132 struct list_head video_device_list;
133 struct proc_dir_entry *dir;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134};
135
136struct acpi_video_device_flags {
Len Brown4be44fc2005-08-05 00:44:28 -0400137 u8 crt:1;
138 u8 lcd:1;
139 u8 tvout:1;
Rui Zhang82cae992007-01-03 23:40:53 -0500140 u8 dvi:1;
Len Brown4be44fc2005-08-05 00:44:28 -0400141 u8 bios:1;
142 u8 unknown:1;
Rui Zhang82cae992007-01-03 23:40:53 -0500143 u8 reserved:2;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144};
145
146struct acpi_video_device_cap {
Len Brown4be44fc2005-08-05 00:44:28 -0400147 u8 _ADR:1; /*Return the unique ID */
148 u8 _BCL:1; /*Query list of brightness control levels supported */
149 u8 _BCM:1; /*Set the brightness level */
Yu Luming2f3d0002006-11-11 02:40:34 +0800150 u8 _BQC:1; /* Get current brightness level */
Len Brown4be44fc2005-08-05 00:44:28 -0400151 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 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155};
156
157struct acpi_video_device_brightness {
Len Brown4be44fc2005-08-05 00:44:28 -0400158 int curr;
159 int count;
160 int *levels;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700161};
162
163struct acpi_video_device {
Len Brown4be44fc2005-08-05 00:44:28 -0400164 unsigned long device_id;
165 struct acpi_video_device_flags flags;
166 struct acpi_video_device_cap cap;
167 struct list_head entry;
168 struct acpi_video_bus *video;
169 struct acpi_device *dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700170 struct acpi_video_device_brightness *brightness;
Yu Luming2f3d0002006-11-11 02:40:34 +0800171 struct backlight_device *backlight;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700172};
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);
Yu Luming2f3d0002006-11-11 02:40:34 +0800266static int acpi_video_device_lcd_set_level(struct acpi_video_device *device,
267 int level);
268static int acpi_video_device_lcd_get_level_current(
269 struct acpi_video_device *device,
270 unsigned long *level);
Len Brown4be44fc2005-08-05 00:44:28 -0400271static int acpi_video_get_next_level(struct acpi_video_device *device,
272 u32 level_current, u32 event);
273static void acpi_video_switch_brightness(struct acpi_video_device *device,
274 int event);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700275
Yu Luming2f3d0002006-11-11 02:40:34 +0800276/*backlight device sysfs support*/
277static int acpi_video_get_brightness(struct backlight_device *bd)
278{
279 unsigned long cur_level;
280 struct acpi_video_device *vd =
281 (struct acpi_video_device *)class_get_devdata(&bd->class_dev);
282 acpi_video_device_lcd_get_level_current(vd, &cur_level);
283 return (int) cur_level;
284}
285
286static int acpi_video_set_brightness(struct backlight_device *bd)
287{
Richard Purdie599a52d2007-02-10 23:07:48 +0000288 int request_level = bd->props.brightness;
Yu Luming2f3d0002006-11-11 02:40:34 +0800289 struct acpi_video_device *vd =
290 (struct acpi_video_device *)class_get_devdata(&bd->class_dev);
291 acpi_video_device_lcd_set_level(vd, request_level);
292 return 0;
293}
294
Richard Purdie599a52d2007-02-10 23:07:48 +0000295static struct backlight_ops acpi_backlight_ops = {
296 .get_brightness = acpi_video_get_brightness,
297 .update_status = acpi_video_set_brightness,
298};
299
Linus Torvalds1da177e2005-04-16 15:20:36 -0700300/* --------------------------------------------------------------------------
301 Video Management
302 -------------------------------------------------------------------------- */
303
304/* device */
305
306static int
Len Brown4be44fc2005-08-05 00:44:28 -0400307acpi_video_device_query(struct acpi_video_device *device, unsigned long *state)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700308{
Len Brown4be44fc2005-08-05 00:44:28 -0400309 int status;
Patrick Mochel90130262006-05-19 16:54:48 -0400310
311 status = acpi_evaluate_integer(device->dev->handle, "_DGS", NULL, state);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700312
Patrick Mocheld550d982006-06-27 00:41:40 -0400313 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700314}
315
316static int
Len Brown4be44fc2005-08-05 00:44:28 -0400317acpi_video_device_get_state(struct acpi_video_device *device,
318 unsigned long *state)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700319{
Len Brown4be44fc2005-08-05 00:44:28 -0400320 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700321
Patrick Mochel90130262006-05-19 16:54:48 -0400322 status = acpi_evaluate_integer(device->dev->handle, "_DCS", NULL, state);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700323
Patrick Mocheld550d982006-06-27 00:41:40 -0400324 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700325}
326
327static int
Len Brown4be44fc2005-08-05 00:44:28 -0400328acpi_video_device_set_state(struct acpi_video_device *device, int state)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700329{
Len Brown4be44fc2005-08-05 00:44:28 -0400330 int status;
331 union acpi_object arg0 = { ACPI_TYPE_INTEGER };
332 struct acpi_object_list args = { 1, &arg0 };
Luming Yu824b5582005-08-21 19:17:00 -0400333 unsigned long ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700334
Linus Torvalds1da177e2005-04-16 15:20:36 -0700335
336 arg0.integer.value = state;
Patrick Mochel90130262006-05-19 16:54:48 -0400337 status = acpi_evaluate_integer(device->dev->handle, "_DSS", &args, &ret);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700338
Patrick Mocheld550d982006-06-27 00:41:40 -0400339 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700340}
341
342static int
Len Brown4be44fc2005-08-05 00:44:28 -0400343acpi_video_device_lcd_query_levels(struct acpi_video_device *device,
344 union acpi_object **levels)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700345{
Len Brown4be44fc2005-08-05 00:44:28 -0400346 int status;
347 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
348 union acpi_object *obj;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700349
Linus Torvalds1da177e2005-04-16 15:20:36 -0700350
351 *levels = NULL;
352
Patrick Mochel90130262006-05-19 16:54:48 -0400353 status = acpi_evaluate_object(device->dev->handle, "_BCL", NULL, &buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700354 if (!ACPI_SUCCESS(status))
Patrick Mocheld550d982006-06-27 00:41:40 -0400355 return status;
Len Brown4be44fc2005-08-05 00:44:28 -0400356 obj = (union acpi_object *)buffer.pointer;
Adrian Bunk6665bda2006-03-11 10:12:00 -0500357 if (!obj || (obj->type != ACPI_TYPE_PACKAGE)) {
Len Brown64684632006-06-26 23:41:38 -0400358 printk(KERN_ERR PREFIX "Invalid _BCL data\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700359 status = -EFAULT;
360 goto err;
361 }
362
363 *levels = obj;
364
Patrick Mocheld550d982006-06-27 00:41:40 -0400365 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700366
Len Brown4be44fc2005-08-05 00:44:28 -0400367 err:
Jesper Juhl6044ec82005-11-07 01:01:32 -0800368 kfree(buffer.pointer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700369
Patrick Mocheld550d982006-06-27 00:41:40 -0400370 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700371}
372
373static int
Len Brown4be44fc2005-08-05 00:44:28 -0400374acpi_video_device_lcd_set_level(struct acpi_video_device *device, int level)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700375{
Len Brown4be44fc2005-08-05 00:44:28 -0400376 int status;
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 arg0.integer.value = level;
Patrick Mochel90130262006-05-19 16:54:48 -0400382 status = acpi_evaluate_object(device->dev->handle, "_BCM", &args, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700383
384 printk(KERN_DEBUG "set_level status: %x\n", status);
Patrick Mocheld550d982006-06-27 00:41:40 -0400385 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700386}
387
388static int
Len Brown4be44fc2005-08-05 00:44:28 -0400389acpi_video_device_lcd_get_level_current(struct acpi_video_device *device,
390 unsigned long *level)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700391{
Len Brown4be44fc2005-08-05 00:44:28 -0400392 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700393
Patrick Mochel90130262006-05-19 16:54:48 -0400394 status = acpi_evaluate_integer(device->dev->handle, "_BQC", NULL, level);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700395
Patrick Mocheld550d982006-06-27 00:41:40 -0400396 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700397}
398
399static int
Len Brown4be44fc2005-08-05 00:44:28 -0400400acpi_video_device_EDID(struct acpi_video_device *device,
401 union acpi_object **edid, ssize_t length)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700402{
Len Brown4be44fc2005-08-05 00:44:28 -0400403 int status;
404 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
405 union acpi_object *obj;
406 union acpi_object arg0 = { ACPI_TYPE_INTEGER };
407 struct acpi_object_list args = { 1, &arg0 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700408
Linus Torvalds1da177e2005-04-16 15:20:36 -0700409
410 *edid = NULL;
411
412 if (!device)
Patrick Mocheld550d982006-06-27 00:41:40 -0400413 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700414 if (length == 128)
415 arg0.integer.value = 1;
416 else if (length == 256)
417 arg0.integer.value = 2;
418 else
Patrick Mocheld550d982006-06-27 00:41:40 -0400419 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700420
Patrick Mochel90130262006-05-19 16:54:48 -0400421 status = acpi_evaluate_object(device->dev->handle, "_DDC", &args, &buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700422 if (ACPI_FAILURE(status))
Patrick Mocheld550d982006-06-27 00:41:40 -0400423 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700424
Jan Engelhardt50dd0962006-10-01 00:28:50 +0200425 obj = buffer.pointer;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700426
427 if (obj && obj->type == ACPI_TYPE_BUFFER)
428 *edid = obj;
429 else {
Len Brown64684632006-06-26 23:41:38 -0400430 printk(KERN_ERR PREFIX "Invalid _DDC data\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700431 status = -EFAULT;
432 kfree(obj);
433 }
434
Patrick Mocheld550d982006-06-27 00:41:40 -0400435 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700436}
437
Linus Torvalds1da177e2005-04-16 15:20:36 -0700438/* bus */
439
440static int
Len Brown4be44fc2005-08-05 00:44:28 -0400441acpi_video_bus_set_POST(struct acpi_video_bus *video, unsigned long option)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700442{
Len Brown4be44fc2005-08-05 00:44:28 -0400443 int status;
444 unsigned long tmp;
445 union acpi_object arg0 = { ACPI_TYPE_INTEGER };
446 struct acpi_object_list args = { 1, &arg0 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700447
Linus Torvalds1da177e2005-04-16 15:20:36 -0700448
449 arg0.integer.value = option;
450
Patrick Mochel90130262006-05-19 16:54:48 -0400451 status = acpi_evaluate_integer(video->device->handle, "_SPD", &args, &tmp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700452 if (ACPI_SUCCESS(status))
Len Brown4be44fc2005-08-05 00:44:28 -0400453 status = tmp ? (-EINVAL) : (AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700454
Patrick Mocheld550d982006-06-27 00:41:40 -0400455 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700456}
457
458static int
Len Brown4be44fc2005-08-05 00:44:28 -0400459acpi_video_bus_get_POST(struct acpi_video_bus *video, unsigned long *id)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700460{
461 int status;
462
Patrick Mochel90130262006-05-19 16:54:48 -0400463 status = acpi_evaluate_integer(video->device->handle, "_GPD", NULL, id);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700464
Patrick Mocheld550d982006-06-27 00:41:40 -0400465 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700466}
467
468static int
Len Brown4be44fc2005-08-05 00:44:28 -0400469acpi_video_bus_POST_options(struct acpi_video_bus *video,
470 unsigned long *options)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700471{
Len Brown4be44fc2005-08-05 00:44:28 -0400472 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700473
Patrick Mochel90130262006-05-19 16:54:48 -0400474 status = acpi_evaluate_integer(video->device->handle, "_VPO", NULL, options);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700475 *options &= 3;
476
Patrick Mocheld550d982006-06-27 00:41:40 -0400477 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700478}
479
480/*
481 * Arg:
482 * video : video bus device pointer
483 * bios_flag :
484 * 0. The system BIOS should NOT automatically switch(toggle)
485 * the active display output.
486 * 1. The system BIOS should automatically switch (toggle) the
Julius Volz98fb8fe2007-02-20 16:38:40 +0100487 * active display output. No switch event.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700488 * 2. The _DGS value should be locked.
489 * 3. The system BIOS should not automatically switch (toggle) the
490 * active display output, but instead generate the display switch
491 * event notify code.
492 * lcd_flag :
493 * 0. The system BIOS should automatically control the brightness level
Julius Volz98fb8fe2007-02-20 16:38:40 +0100494 * of the LCD when the power changes from AC to DC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700495 * 1. The system BIOS should NOT automatically control the brightness
Julius Volz98fb8fe2007-02-20 16:38:40 +0100496 * level of the LCD when the power changes from AC to DC.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700497 * Return Value:
498 * -1 wrong arg.
499 */
500
501static int
Len Brown4be44fc2005-08-05 00:44:28 -0400502acpi_video_bus_DOS(struct acpi_video_bus *video, int bios_flag, int lcd_flag)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700503{
Len Brown4be44fc2005-08-05 00:44:28 -0400504 acpi_integer status = 0;
505 union acpi_object arg0 = { ACPI_TYPE_INTEGER };
506 struct acpi_object_list args = { 1, &arg0 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700507
Linus Torvalds1da177e2005-04-16 15:20:36 -0700508
Len Brown4be44fc2005-08-05 00:44:28 -0400509 if (bios_flag < 0 || bios_flag > 3 || lcd_flag < 0 || lcd_flag > 1) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700510 status = -1;
511 goto Failed;
512 }
513 arg0.integer.value = (lcd_flag << 2) | bios_flag;
514 video->dos_setting = arg0.integer.value;
Patrick Mochel90130262006-05-19 16:54:48 -0400515 acpi_evaluate_object(video->device->handle, "_DOS", &args, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700516
Len Brown4be44fc2005-08-05 00:44:28 -0400517 Failed:
Patrick Mocheld550d982006-06-27 00:41:40 -0400518 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700519}
520
521/*
522 * Arg:
523 * device : video output device (LCD, CRT, ..)
524 *
525 * Return Value:
526 * None
527 *
Julius Volz98fb8fe2007-02-20 16:38:40 +0100528 * Find out all required AML methods defined under the output
Linus Torvalds1da177e2005-04-16 15:20:36 -0700529 * device.
530 */
531
Len Brown4be44fc2005-08-05 00:44:28 -0400532static void acpi_video_device_find_cap(struct acpi_video_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700533{
Len Brown4be44fc2005-08-05 00:44:28 -0400534 acpi_integer status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700535 acpi_handle h_dummy1;
536 int i;
Yu Luming2f3d0002006-11-11 02:40:34 +0800537 u32 max_level = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700538 union acpi_object *obj = NULL;
539 struct acpi_video_device_brightness *br = NULL;
540
Linus Torvalds1da177e2005-04-16 15:20:36 -0700541
Len Brown4be44fc2005-08-05 00:44:28 -0400542 memset(&device->cap, 0, 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700543
Patrick Mochel90130262006-05-19 16:54:48 -0400544 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_ADR", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700545 device->cap._ADR = 1;
546 }
Patrick Mochel90130262006-05-19 16:54:48 -0400547 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_BCL", &h_dummy1))) {
Len Brown4be44fc2005-08-05 00:44:28 -0400548 device->cap._BCL = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700549 }
Patrick Mochel90130262006-05-19 16:54:48 -0400550 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_BCM", &h_dummy1))) {
Len Brown4be44fc2005-08-05 00:44:28 -0400551 device->cap._BCM = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700552 }
Yu Luming2f3d0002006-11-11 02:40:34 +0800553 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle,"_BQC",&h_dummy1)))
554 device->cap._BQC = 1;
Patrick Mochel90130262006-05-19 16:54:48 -0400555 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_DDC", &h_dummy1))) {
Len Brown4be44fc2005-08-05 00:44:28 -0400556 device->cap._DDC = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700557 }
Patrick Mochel90130262006-05-19 16:54:48 -0400558 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_DCS", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700559 device->cap._DCS = 1;
560 }
Patrick Mochel90130262006-05-19 16:54:48 -0400561 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_DGS", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700562 device->cap._DGS = 1;
563 }
Patrick Mochel90130262006-05-19 16:54:48 -0400564 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_DSS", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700565 device->cap._DSS = 1;
566 }
567
568 status = acpi_video_device_lcd_query_levels(device, &obj);
569
570 if (obj && obj->type == ACPI_TYPE_PACKAGE && obj->package.count >= 2) {
571 int count = 0;
572 union acpi_object *o;
Len Brown4be44fc2005-08-05 00:44:28 -0400573
Burman Yan36bcbec2006-12-19 12:56:11 -0800574 br = kzalloc(sizeof(*br), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700575 if (!br) {
576 printk(KERN_ERR "can't allocate memory\n");
577 } else {
Paulo Marquesd1dd0c22005-03-30 22:39:49 -0500578 br->levels = kmalloc(obj->package.count *
Len Brown4be44fc2005-08-05 00:44:28 -0400579 sizeof *(br->levels), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700580 if (!br->levels)
581 goto out;
582
583 for (i = 0; i < obj->package.count; i++) {
Len Brown4be44fc2005-08-05 00:44:28 -0400584 o = (union acpi_object *)&obj->package.
585 elements[i];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700586 if (o->type != ACPI_TYPE_INTEGER) {
Len Brown64684632006-06-26 23:41:38 -0400587 printk(KERN_ERR PREFIX "Invalid data\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700588 continue;
589 }
590 br->levels[count] = (u32) o->integer.value;
Yu Luming2f3d0002006-11-11 02:40:34 +0800591 if (br->levels[count] > max_level)
592 max_level = br->levels[count];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700593 count++;
594 }
Len Brown4be44fc2005-08-05 00:44:28 -0400595 out:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700596 if (count < 2) {
Paulo Marquesd1dd0c22005-03-30 22:39:49 -0500597 kfree(br->levels);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700598 kfree(br);
599 } else {
600 br->count = count;
601 device->brightness = br;
Len Brown4be44fc2005-08-05 00:44:28 -0400602 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
603 "found %d brightness levels\n",
604 count));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700605 }
606 }
607 }
608
Paulo Marquesd1dd0c22005-03-30 22:39:49 -0500609 kfree(obj);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700610
Yu Luming2f3d0002006-11-11 02:40:34 +0800611 if (device->cap._BCL && device->cap._BCM && device->cap._BQC){
612 unsigned long tmp;
613 static int count = 0;
614 char *name;
Yu Luming2f3d0002006-11-11 02:40:34 +0800615 name = kzalloc(MAX_NAME_LEN, GFP_KERNEL);
616 if (!name)
617 return;
618
Yu Luming2f3d0002006-11-11 02:40:34 +0800619 sprintf(name, "acpi_video%d", count++);
Yu Luming2f3d0002006-11-11 02:40:34 +0800620 acpi_video_device_lcd_get_level_current(device, &tmp);
Yu Luming2f3d0002006-11-11 02:40:34 +0800621 device->backlight = backlight_device_register(name,
Richard Purdie599a52d2007-02-10 23:07:48 +0000622 NULL, device, &acpi_backlight_ops);
623 device->backlight->props.max_brightness = max_level;
624 device->backlight->props.brightness = (int)tmp;
625 backlight_update_status(device->backlight);
626
Yu Luming2f3d0002006-11-11 02:40:34 +0800627 kfree(name);
628 }
Patrick Mocheld550d982006-06-27 00:41:40 -0400629 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700630}
631
632/*
633 * Arg:
634 * device : video output device (VGA)
635 *
636 * Return Value:
637 * None
638 *
Julius Volz98fb8fe2007-02-20 16:38:40 +0100639 * Find out all required AML methods defined under the video bus device.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700640 */
641
Len Brown4be44fc2005-08-05 00:44:28 -0400642static void acpi_video_bus_find_cap(struct acpi_video_bus *video)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700643{
Len Brown4be44fc2005-08-05 00:44:28 -0400644 acpi_handle h_dummy1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700645
Len Brown4be44fc2005-08-05 00:44:28 -0400646 memset(&video->cap, 0, 4);
Patrick Mochel90130262006-05-19 16:54:48 -0400647 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_DOS", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700648 video->cap._DOS = 1;
649 }
Patrick Mochel90130262006-05-19 16:54:48 -0400650 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_DOD", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700651 video->cap._DOD = 1;
652 }
Patrick Mochel90130262006-05-19 16:54:48 -0400653 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_ROM", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700654 video->cap._ROM = 1;
655 }
Patrick Mochel90130262006-05-19 16:54:48 -0400656 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_GPD", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700657 video->cap._GPD = 1;
658 }
Patrick Mochel90130262006-05-19 16:54:48 -0400659 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_SPD", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700660 video->cap._SPD = 1;
661 }
Patrick Mochel90130262006-05-19 16:54:48 -0400662 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_VPO", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700663 video->cap._VPO = 1;
664 }
665}
666
667/*
668 * Check whether the video bus device has required AML method to
669 * support the desired features
670 */
671
Len Brown4be44fc2005-08-05 00:44:28 -0400672static int acpi_video_bus_check(struct acpi_video_bus *video)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700673{
Len Brown4be44fc2005-08-05 00:44:28 -0400674 acpi_status status = -ENOENT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700675
Linus Torvalds1da177e2005-04-16 15:20:36 -0700676
677 if (!video)
Patrick Mocheld550d982006-06-27 00:41:40 -0400678 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700679
680 /* Since there is no HID, CID and so on for VGA driver, we have
681 * to check well known required nodes.
682 */
683
Julius Volz98fb8fe2007-02-20 16:38:40 +0100684 /* Does this device support video switching? */
Len Brown4be44fc2005-08-05 00:44:28 -0400685 if (video->cap._DOS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700686 video->flags.multihead = 1;
687 status = 0;
688 }
689
Julius Volz98fb8fe2007-02-20 16:38:40 +0100690 /* Does this device support retrieving a video ROM? */
Len Brown4be44fc2005-08-05 00:44:28 -0400691 if (video->cap._ROM) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700692 video->flags.rom = 1;
693 status = 0;
694 }
695
Julius Volz98fb8fe2007-02-20 16:38:40 +0100696 /* Does this device support configuring which video device to POST? */
Len Brown4be44fc2005-08-05 00:44:28 -0400697 if (video->cap._GPD && video->cap._SPD && video->cap._VPO) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700698 video->flags.post = 1;
699 status = 0;
700 }
701
Patrick Mocheld550d982006-06-27 00:41:40 -0400702 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700703}
704
705/* --------------------------------------------------------------------------
706 FS Interface (/proc)
707 -------------------------------------------------------------------------- */
708
Len Brown4be44fc2005-08-05 00:44:28 -0400709static struct proc_dir_entry *acpi_video_dir;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700710
711/* video devices */
712
Len Brown4be44fc2005-08-05 00:44:28 -0400713static int acpi_video_device_info_seq_show(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700714{
Jan Engelhardt50dd0962006-10-01 00:28:50 +0200715 struct acpi_video_device *dev = seq->private;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700716
Linus Torvalds1da177e2005-04-16 15:20:36 -0700717
718 if (!dev)
719 goto end;
720
721 seq_printf(seq, "device_id: 0x%04x\n", (u32) dev->device_id);
722 seq_printf(seq, "type: ");
723 if (dev->flags.crt)
724 seq_printf(seq, "CRT\n");
725 else if (dev->flags.lcd)
726 seq_printf(seq, "LCD\n");
727 else if (dev->flags.tvout)
728 seq_printf(seq, "TVOUT\n");
Rui Zhang82cae992007-01-03 23:40:53 -0500729 else if (dev->flags.dvi)
730 seq_printf(seq, "DVI\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700731 else
732 seq_printf(seq, "UNKNOWN\n");
733
Len Brown4be44fc2005-08-05 00:44:28 -0400734 seq_printf(seq, "known by bios: %s\n", dev->flags.bios ? "yes" : "no");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700735
Len Brown4be44fc2005-08-05 00:44:28 -0400736 end:
Patrick Mocheld550d982006-06-27 00:41:40 -0400737 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700738}
739
740static int
Len Brown4be44fc2005-08-05 00:44:28 -0400741acpi_video_device_info_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700742{
743 return single_open(file, acpi_video_device_info_seq_show,
744 PDE(inode)->data);
745}
746
Len Brown4be44fc2005-08-05 00:44:28 -0400747static int acpi_video_device_state_seq_show(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700748{
Len Brown4be44fc2005-08-05 00:44:28 -0400749 int status;
Jan Engelhardt50dd0962006-10-01 00:28:50 +0200750 struct acpi_video_device *dev = seq->private;
Len Brown4be44fc2005-08-05 00:44:28 -0400751 unsigned long state;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700752
Linus Torvalds1da177e2005-04-16 15:20:36 -0700753
754 if (!dev)
755 goto end;
756
757 status = acpi_video_device_get_state(dev, &state);
758 seq_printf(seq, "state: ");
759 if (ACPI_SUCCESS(status))
760 seq_printf(seq, "0x%02lx\n", state);
761 else
762 seq_printf(seq, "<not supported>\n");
763
764 status = acpi_video_device_query(dev, &state);
765 seq_printf(seq, "query: ");
766 if (ACPI_SUCCESS(status))
767 seq_printf(seq, "0x%02lx\n", state);
768 else
769 seq_printf(seq, "<not supported>\n");
770
Len Brown4be44fc2005-08-05 00:44:28 -0400771 end:
Patrick Mocheld550d982006-06-27 00:41:40 -0400772 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700773}
774
775static int
Len Brown4be44fc2005-08-05 00:44:28 -0400776acpi_video_device_state_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700777{
778 return single_open(file, acpi_video_device_state_seq_show,
779 PDE(inode)->data);
780}
781
782static ssize_t
Len Brown4be44fc2005-08-05 00:44:28 -0400783acpi_video_device_write_state(struct file *file,
784 const char __user * buffer,
785 size_t count, loff_t * data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700786{
Len Brown4be44fc2005-08-05 00:44:28 -0400787 int status;
Jan Engelhardt50dd0962006-10-01 00:28:50 +0200788 struct seq_file *m = file->private_data;
789 struct acpi_video_device *dev = m->private;
Len Brown4be44fc2005-08-05 00:44:28 -0400790 char str[12] = { 0 };
791 u32 state = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700792
Linus Torvalds1da177e2005-04-16 15:20:36 -0700793
794 if (!dev || count + 1 > sizeof str)
Patrick Mocheld550d982006-06-27 00:41:40 -0400795 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700796
797 if (copy_from_user(str, buffer, count))
Patrick Mocheld550d982006-06-27 00:41:40 -0400798 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700799
800 str[count] = 0;
801 state = simple_strtoul(str, NULL, 0);
Len Brown4be44fc2005-08-05 00:44:28 -0400802 state &= ((1ul << 31) | (1ul << 30) | (1ul << 0));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700803
804 status = acpi_video_device_set_state(dev, state);
805
806 if (status)
Patrick Mocheld550d982006-06-27 00:41:40 -0400807 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700808
Patrick Mocheld550d982006-06-27 00:41:40 -0400809 return count;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700810}
811
812static int
Len Brown4be44fc2005-08-05 00:44:28 -0400813acpi_video_device_brightness_seq_show(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700814{
Jan Engelhardt50dd0962006-10-01 00:28:50 +0200815 struct acpi_video_device *dev = seq->private;
Len Brown4be44fc2005-08-05 00:44:28 -0400816 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700817
Linus Torvalds1da177e2005-04-16 15:20:36 -0700818
819 if (!dev || !dev->brightness) {
820 seq_printf(seq, "<not supported>\n");
Patrick Mocheld550d982006-06-27 00:41:40 -0400821 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700822 }
823
824 seq_printf(seq, "levels: ");
825 for (i = 0; i < dev->brightness->count; i++)
826 seq_printf(seq, " %d", dev->brightness->levels[i]);
827 seq_printf(seq, "\ncurrent: %d\n", dev->brightness->curr);
828
Patrick Mocheld550d982006-06-27 00:41:40 -0400829 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700830}
831
832static int
Len Brown4be44fc2005-08-05 00:44:28 -0400833acpi_video_device_brightness_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700834{
835 return single_open(file, acpi_video_device_brightness_seq_show,
836 PDE(inode)->data);
837}
838
839static ssize_t
Len Brown4be44fc2005-08-05 00:44:28 -0400840acpi_video_device_write_brightness(struct file *file,
841 const char __user * buffer,
842 size_t count, loff_t * data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700843{
Jan Engelhardt50dd0962006-10-01 00:28:50 +0200844 struct seq_file *m = file->private_data;
845 struct acpi_video_device *dev = m->private;
Len Brown4be44fc2005-08-05 00:44:28 -0400846 char str[4] = { 0 };
847 unsigned int level = 0;
848 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700849
Linus Torvalds1da177e2005-04-16 15:20:36 -0700850
Thomas Renninger59d399d2005-11-08 05:27:00 -0500851 if (!dev || !dev->brightness || count + 1 > sizeof str)
Patrick Mocheld550d982006-06-27 00:41:40 -0400852 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700853
854 if (copy_from_user(str, buffer, count))
Patrick Mocheld550d982006-06-27 00:41:40 -0400855 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700856
857 str[count] = 0;
858 level = simple_strtoul(str, NULL, 0);
Len Brown4be44fc2005-08-05 00:44:28 -0400859
Linus Torvalds1da177e2005-04-16 15:20:36 -0700860 if (level > 100)
Patrick Mocheld550d982006-06-27 00:41:40 -0400861 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700862
Julius Volz98fb8fe2007-02-20 16:38:40 +0100863 /* validate through the list of available levels */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700864 for (i = 0; i < dev->brightness->count; i++)
865 if (level == dev->brightness->levels[i]) {
Len Brown4be44fc2005-08-05 00:44:28 -0400866 if (ACPI_SUCCESS
867 (acpi_video_device_lcd_set_level(dev, level)))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700868 dev->brightness->curr = level;
869 break;
870 }
871
Patrick Mocheld550d982006-06-27 00:41:40 -0400872 return count;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700873}
874
Len Brown4be44fc2005-08-05 00:44:28 -0400875static int acpi_video_device_EDID_seq_show(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700876{
Jan Engelhardt50dd0962006-10-01 00:28:50 +0200877 struct acpi_video_device *dev = seq->private;
Len Brown4be44fc2005-08-05 00:44:28 -0400878 int status;
879 int i;
880 union acpi_object *edid = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700881
Linus Torvalds1da177e2005-04-16 15:20:36 -0700882
883 if (!dev)
884 goto out;
885
Len Brown4be44fc2005-08-05 00:44:28 -0400886 status = acpi_video_device_EDID(dev, &edid, 128);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700887 if (ACPI_FAILURE(status)) {
Len Brown4be44fc2005-08-05 00:44:28 -0400888 status = acpi_video_device_EDID(dev, &edid, 256);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700889 }
890
891 if (ACPI_FAILURE(status)) {
892 goto out;
893 }
894
895 if (edid && edid->type == ACPI_TYPE_BUFFER) {
896 for (i = 0; i < edid->buffer.length; i++)
897 seq_putc(seq, edid->buffer.pointer[i]);
898 }
899
Len Brown4be44fc2005-08-05 00:44:28 -0400900 out:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700901 if (!edid)
902 seq_printf(seq, "<not supported>\n");
903 else
904 kfree(edid);
905
Patrick Mocheld550d982006-06-27 00:41:40 -0400906 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700907}
908
909static int
Len Brown4be44fc2005-08-05 00:44:28 -0400910acpi_video_device_EDID_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700911{
912 return single_open(file, acpi_video_device_EDID_seq_show,
913 PDE(inode)->data);
914}
915
Len Brown4be44fc2005-08-05 00:44:28 -0400916static int acpi_video_device_add_fs(struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700917{
Len Brown4be44fc2005-08-05 00:44:28 -0400918 struct proc_dir_entry *entry = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700919 struct acpi_video_device *vid_dev;
920
Linus Torvalds1da177e2005-04-16 15:20:36 -0700921
922 if (!device)
Patrick Mocheld550d982006-06-27 00:41:40 -0400923 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700924
Jan Engelhardt50dd0962006-10-01 00:28:50 +0200925 vid_dev = acpi_driver_data(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700926 if (!vid_dev)
Patrick Mocheld550d982006-06-27 00:41:40 -0400927 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700928
929 if (!acpi_device_dir(device)) {
930 acpi_device_dir(device) = proc_mkdir(acpi_device_bid(device),
Len Brown4be44fc2005-08-05 00:44:28 -0400931 vid_dev->video->dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700932 if (!acpi_device_dir(device))
Patrick Mocheld550d982006-06-27 00:41:40 -0400933 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700934 acpi_device_dir(device)->owner = THIS_MODULE;
935 }
936
937 /* 'info' [R] */
938 entry = create_proc_entry("info", S_IRUGO, acpi_device_dir(device));
939 if (!entry)
Patrick Mocheld550d982006-06-27 00:41:40 -0400940 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700941 else {
942 entry->proc_fops = &acpi_video_device_info_fops;
943 entry->data = acpi_driver_data(device);
944 entry->owner = THIS_MODULE;
945 }
946
947 /* 'state' [R/W] */
Len Brown4be44fc2005-08-05 00:44:28 -0400948 entry =
949 create_proc_entry("state", S_IFREG | S_IRUGO | S_IWUSR,
950 acpi_device_dir(device));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700951 if (!entry)
Patrick Mocheld550d982006-06-27 00:41:40 -0400952 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700953 else {
Arjan van de Vend479e902006-01-06 16:47:00 -0500954 acpi_video_device_state_fops.write = acpi_video_device_write_state;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700955 entry->proc_fops = &acpi_video_device_state_fops;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700956 entry->data = acpi_driver_data(device);
957 entry->owner = THIS_MODULE;
958 }
959
960 /* 'brightness' [R/W] */
Len Brown4be44fc2005-08-05 00:44:28 -0400961 entry =
962 create_proc_entry("brightness", S_IFREG | S_IRUGO | S_IWUSR,
963 acpi_device_dir(device));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700964 if (!entry)
Patrick Mocheld550d982006-06-27 00:41:40 -0400965 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700966 else {
Arjan van de Vend479e902006-01-06 16:47:00 -0500967 acpi_video_device_brightness_fops.write = acpi_video_device_write_brightness;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700968 entry->proc_fops = &acpi_video_device_brightness_fops;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700969 entry->data = acpi_driver_data(device);
970 entry->owner = THIS_MODULE;
971 }
972
973 /* 'EDID' [R] */
974 entry = create_proc_entry("EDID", S_IRUGO, acpi_device_dir(device));
975 if (!entry)
Patrick Mocheld550d982006-06-27 00:41:40 -0400976 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700977 else {
978 entry->proc_fops = &acpi_video_device_EDID_fops;
979 entry->data = acpi_driver_data(device);
980 entry->owner = THIS_MODULE;
981 }
982
Patrick Mocheld550d982006-06-27 00:41:40 -0400983 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700984}
985
Len Brown4be44fc2005-08-05 00:44:28 -0400986static int acpi_video_device_remove_fs(struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700987{
988 struct acpi_video_device *vid_dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700989
Jan Engelhardt50dd0962006-10-01 00:28:50 +0200990 vid_dev = acpi_driver_data(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700991 if (!vid_dev || !vid_dev->video || !vid_dev->video->dir)
Patrick Mocheld550d982006-06-27 00:41:40 -0400992 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700993
994 if (acpi_device_dir(device)) {
995 remove_proc_entry("info", acpi_device_dir(device));
996 remove_proc_entry("state", acpi_device_dir(device));
997 remove_proc_entry("brightness", acpi_device_dir(device));
998 remove_proc_entry("EDID", acpi_device_dir(device));
Len Brown4be44fc2005-08-05 00:44:28 -0400999 remove_proc_entry(acpi_device_bid(device), vid_dev->video->dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001000 acpi_device_dir(device) = NULL;
1001 }
1002
Patrick Mocheld550d982006-06-27 00:41:40 -04001003 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001004}
1005
Linus Torvalds1da177e2005-04-16 15:20:36 -07001006/* video bus */
Len Brown4be44fc2005-08-05 00:44:28 -04001007static int acpi_video_bus_info_seq_show(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001008{
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001009 struct acpi_video_bus *video = seq->private;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001010
Linus Torvalds1da177e2005-04-16 15:20:36 -07001011
1012 if (!video)
1013 goto end;
1014
1015 seq_printf(seq, "Switching heads: %s\n",
Len Brown4be44fc2005-08-05 00:44:28 -04001016 video->flags.multihead ? "yes" : "no");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001017 seq_printf(seq, "Video ROM: %s\n",
Len Brown4be44fc2005-08-05 00:44:28 -04001018 video->flags.rom ? "yes" : "no");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001019 seq_printf(seq, "Device to be POSTed on boot: %s\n",
Len Brown4be44fc2005-08-05 00:44:28 -04001020 video->flags.post ? "yes" : "no");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001021
Len Brown4be44fc2005-08-05 00:44:28 -04001022 end:
Patrick Mocheld550d982006-06-27 00:41:40 -04001023 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001024}
1025
Len Brown4be44fc2005-08-05 00:44:28 -04001026static int acpi_video_bus_info_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001027{
Len Brown4be44fc2005-08-05 00:44:28 -04001028 return single_open(file, acpi_video_bus_info_seq_show,
1029 PDE(inode)->data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001030}
1031
Len Brown4be44fc2005-08-05 00:44:28 -04001032static int acpi_video_bus_ROM_seq_show(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001033{
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001034 struct acpi_video_bus *video = seq->private;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001035
Linus Torvalds1da177e2005-04-16 15:20:36 -07001036
1037 if (!video)
1038 goto end;
1039
1040 printk(KERN_INFO PREFIX "Please implement %s\n", __FUNCTION__);
1041 seq_printf(seq, "<TODO>\n");
1042
Len Brown4be44fc2005-08-05 00:44:28 -04001043 end:
Patrick Mocheld550d982006-06-27 00:41:40 -04001044 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001045}
1046
Len Brown4be44fc2005-08-05 00:44:28 -04001047static int acpi_video_bus_ROM_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001048{
1049 return single_open(file, acpi_video_bus_ROM_seq_show, PDE(inode)->data);
1050}
1051
Len Brown4be44fc2005-08-05 00:44:28 -04001052static int acpi_video_bus_POST_info_seq_show(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001053{
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001054 struct acpi_video_bus *video = seq->private;
Len Brown4be44fc2005-08-05 00:44:28 -04001055 unsigned long options;
1056 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001057
Linus Torvalds1da177e2005-04-16 15:20:36 -07001058
1059 if (!video)
1060 goto end;
1061
1062 status = acpi_video_bus_POST_options(video, &options);
1063 if (ACPI_SUCCESS(status)) {
1064 if (!(options & 1)) {
Len Brown4be44fc2005-08-05 00:44:28 -04001065 printk(KERN_WARNING PREFIX
1066 "The motherboard VGA device is not listed as a possible POST device.\n");
1067 printk(KERN_WARNING PREFIX
Julius Volz98fb8fe2007-02-20 16:38:40 +01001068 "This indicates a BIOS bug. Please contact the manufacturer.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001069 }
1070 printk("%lx\n", options);
Julius Volz98fb8fe2007-02-20 16:38:40 +01001071 seq_printf(seq, "can POST: <integrated video>");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001072 if (options & 2)
1073 seq_printf(seq, " <PCI video>");
1074 if (options & 4)
1075 seq_printf(seq, " <AGP video>");
1076 seq_putc(seq, '\n');
1077 } else
1078 seq_printf(seq, "<not supported>\n");
Len Brown4be44fc2005-08-05 00:44:28 -04001079 end:
Patrick Mocheld550d982006-06-27 00:41:40 -04001080 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001081}
1082
1083static int
Len Brown4be44fc2005-08-05 00:44:28 -04001084acpi_video_bus_POST_info_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001085{
Len Brown4be44fc2005-08-05 00:44:28 -04001086 return single_open(file, acpi_video_bus_POST_info_seq_show,
1087 PDE(inode)->data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001088}
1089
Len Brown4be44fc2005-08-05 00:44:28 -04001090static int acpi_video_bus_POST_seq_show(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001091{
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001092 struct acpi_video_bus *video = seq->private;
Len Brown4be44fc2005-08-05 00:44:28 -04001093 int status;
1094 unsigned long id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001095
Linus Torvalds1da177e2005-04-16 15:20:36 -07001096
1097 if (!video)
1098 goto end;
1099
Len Brown4be44fc2005-08-05 00:44:28 -04001100 status = acpi_video_bus_get_POST(video, &id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001101 if (!ACPI_SUCCESS(status)) {
1102 seq_printf(seq, "<not supported>\n");
1103 goto end;
1104 }
Julius Volz98fb8fe2007-02-20 16:38:40 +01001105 seq_printf(seq, "device POSTed is <%s>\n", device_decode[id & 3]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001106
Len Brown4be44fc2005-08-05 00:44:28 -04001107 end:
Patrick Mocheld550d982006-06-27 00:41:40 -04001108 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001109}
1110
Len Brown4be44fc2005-08-05 00:44:28 -04001111static int acpi_video_bus_DOS_seq_show(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001112{
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001113 struct acpi_video_bus *video = seq->private;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001114
Linus Torvalds1da177e2005-04-16 15:20:36 -07001115
Len Brown4be44fc2005-08-05 00:44:28 -04001116 seq_printf(seq, "DOS setting: <%d>\n", video->dos_setting);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001117
Patrick Mocheld550d982006-06-27 00:41:40 -04001118 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001119}
1120
Len Brown4be44fc2005-08-05 00:44:28 -04001121static int acpi_video_bus_POST_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001122{
Len Brown4be44fc2005-08-05 00:44:28 -04001123 return single_open(file, acpi_video_bus_POST_seq_show,
1124 PDE(inode)->data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001125}
1126
Len Brown4be44fc2005-08-05 00:44:28 -04001127static int acpi_video_bus_DOS_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001128{
1129 return single_open(file, acpi_video_bus_DOS_seq_show, PDE(inode)->data);
1130}
1131
1132static ssize_t
Len Brown4be44fc2005-08-05 00:44:28 -04001133acpi_video_bus_write_POST(struct file *file,
1134 const char __user * buffer,
1135 size_t count, loff_t * data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001136{
Len Brown4be44fc2005-08-05 00:44:28 -04001137 int status;
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001138 struct seq_file *m = file->private_data;
1139 struct acpi_video_bus *video = m->private;
Len Brown4be44fc2005-08-05 00:44:28 -04001140 char str[12] = { 0 };
1141 unsigned long opt, options;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001142
Linus Torvalds1da177e2005-04-16 15:20:36 -07001143
Linus Torvalds1da177e2005-04-16 15:20:36 -07001144 if (!video || count + 1 > sizeof str)
Patrick Mocheld550d982006-06-27 00:41:40 -04001145 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001146
1147 status = acpi_video_bus_POST_options(video, &options);
1148 if (!ACPI_SUCCESS(status))
Patrick Mocheld550d982006-06-27 00:41:40 -04001149 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001150
1151 if (copy_from_user(str, buffer, count))
Patrick Mocheld550d982006-06-27 00:41:40 -04001152 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001153
1154 str[count] = 0;
1155 opt = strtoul(str, NULL, 0);
1156 if (opt > 3)
Patrick Mocheld550d982006-06-27 00:41:40 -04001157 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001158
Julius Volz98fb8fe2007-02-20 16:38:40 +01001159 /* just in case an OEM 'forgot' the motherboard... */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001160 options |= 1;
1161
1162 if (options & (1ul << opt)) {
Len Brown4be44fc2005-08-05 00:44:28 -04001163 status = acpi_video_bus_set_POST(video, opt);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001164 if (!ACPI_SUCCESS(status))
Patrick Mocheld550d982006-06-27 00:41:40 -04001165 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001166
1167 }
1168
Patrick Mocheld550d982006-06-27 00:41:40 -04001169 return count;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001170}
1171
1172static ssize_t
Len Brown4be44fc2005-08-05 00:44:28 -04001173acpi_video_bus_write_DOS(struct file *file,
1174 const char __user * buffer,
1175 size_t count, loff_t * data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001176{
Len Brown4be44fc2005-08-05 00:44:28 -04001177 int status;
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001178 struct seq_file *m = file->private_data;
1179 struct acpi_video_bus *video = m->private;
Len Brown4be44fc2005-08-05 00:44:28 -04001180 char str[12] = { 0 };
1181 unsigned long opt;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001182
Linus Torvalds1da177e2005-04-16 15:20:36 -07001183
Linus Torvalds1da177e2005-04-16 15:20:36 -07001184 if (!video || count + 1 > sizeof str)
Patrick Mocheld550d982006-06-27 00:41:40 -04001185 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001186
1187 if (copy_from_user(str, buffer, count))
Patrick Mocheld550d982006-06-27 00:41:40 -04001188 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001189
1190 str[count] = 0;
1191 opt = strtoul(str, NULL, 0);
1192 if (opt > 7)
Patrick Mocheld550d982006-06-27 00:41:40 -04001193 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001194
Len Brown4be44fc2005-08-05 00:44:28 -04001195 status = acpi_video_bus_DOS(video, opt & 0x3, (opt & 0x4) >> 2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001196
1197 if (!ACPI_SUCCESS(status))
Patrick Mocheld550d982006-06-27 00:41:40 -04001198 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001199
Patrick Mocheld550d982006-06-27 00:41:40 -04001200 return count;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001201}
1202
Len Brown4be44fc2005-08-05 00:44:28 -04001203static int acpi_video_bus_add_fs(struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001204{
Len Brown4be44fc2005-08-05 00:44:28 -04001205 struct proc_dir_entry *entry = NULL;
1206 struct acpi_video_bus *video;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001207
Linus Torvalds1da177e2005-04-16 15:20:36 -07001208
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001209 video = acpi_driver_data(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001210
1211 if (!acpi_device_dir(device)) {
1212 acpi_device_dir(device) = proc_mkdir(acpi_device_bid(device),
Len Brown4be44fc2005-08-05 00:44:28 -04001213 acpi_video_dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001214 if (!acpi_device_dir(device))
Patrick Mocheld550d982006-06-27 00:41:40 -04001215 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001216 video->dir = acpi_device_dir(device);
1217 acpi_device_dir(device)->owner = THIS_MODULE;
1218 }
1219
1220 /* 'info' [R] */
1221 entry = create_proc_entry("info", S_IRUGO, acpi_device_dir(device));
1222 if (!entry)
Patrick Mocheld550d982006-06-27 00:41:40 -04001223 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001224 else {
1225 entry->proc_fops = &acpi_video_bus_info_fops;
1226 entry->data = acpi_driver_data(device);
1227 entry->owner = THIS_MODULE;
1228 }
1229
1230 /* 'ROM' [R] */
1231 entry = create_proc_entry("ROM", S_IRUGO, acpi_device_dir(device));
1232 if (!entry)
Patrick Mocheld550d982006-06-27 00:41:40 -04001233 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001234 else {
1235 entry->proc_fops = &acpi_video_bus_ROM_fops;
1236 entry->data = acpi_driver_data(device);
1237 entry->owner = THIS_MODULE;
1238 }
1239
1240 /* 'POST_info' [R] */
Len Brown4be44fc2005-08-05 00:44:28 -04001241 entry =
1242 create_proc_entry("POST_info", S_IRUGO, acpi_device_dir(device));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001243 if (!entry)
Patrick Mocheld550d982006-06-27 00:41:40 -04001244 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001245 else {
1246 entry->proc_fops = &acpi_video_bus_POST_info_fops;
1247 entry->data = acpi_driver_data(device);
1248 entry->owner = THIS_MODULE;
1249 }
1250
1251 /* 'POST' [R/W] */
Len Brown4be44fc2005-08-05 00:44:28 -04001252 entry =
1253 create_proc_entry("POST", S_IFREG | S_IRUGO | S_IRUSR,
1254 acpi_device_dir(device));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001255 if (!entry)
Patrick Mocheld550d982006-06-27 00:41:40 -04001256 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001257 else {
Arjan van de Vend479e902006-01-06 16:47:00 -05001258 acpi_video_bus_POST_fops.write = acpi_video_bus_write_POST;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001259 entry->proc_fops = &acpi_video_bus_POST_fops;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001260 entry->data = acpi_driver_data(device);
1261 entry->owner = THIS_MODULE;
1262 }
1263
1264 /* 'DOS' [R/W] */
Len Brown4be44fc2005-08-05 00:44:28 -04001265 entry =
1266 create_proc_entry("DOS", S_IFREG | S_IRUGO | S_IRUSR,
1267 acpi_device_dir(device));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001268 if (!entry)
Patrick Mocheld550d982006-06-27 00:41:40 -04001269 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001270 else {
Arjan van de Vend479e902006-01-06 16:47:00 -05001271 acpi_video_bus_DOS_fops.write = acpi_video_bus_write_DOS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001272 entry->proc_fops = &acpi_video_bus_DOS_fops;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001273 entry->data = acpi_driver_data(device);
1274 entry->owner = THIS_MODULE;
1275 }
1276
Patrick Mocheld550d982006-06-27 00:41:40 -04001277 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001278}
1279
Len Brown4be44fc2005-08-05 00:44:28 -04001280static int acpi_video_bus_remove_fs(struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001281{
Len Brown4be44fc2005-08-05 00:44:28 -04001282 struct acpi_video_bus *video;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001283
Linus Torvalds1da177e2005-04-16 15:20:36 -07001284
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001285 video = acpi_driver_data(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001286
1287 if (acpi_device_dir(device)) {
1288 remove_proc_entry("info", acpi_device_dir(device));
1289 remove_proc_entry("ROM", acpi_device_dir(device));
1290 remove_proc_entry("POST_info", acpi_device_dir(device));
1291 remove_proc_entry("POST", acpi_device_dir(device));
1292 remove_proc_entry("DOS", acpi_device_dir(device));
Len Brown4be44fc2005-08-05 00:44:28 -04001293 remove_proc_entry(acpi_device_bid(device), acpi_video_dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001294 acpi_device_dir(device) = NULL;
1295 }
1296
Patrick Mocheld550d982006-06-27 00:41:40 -04001297 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001298}
1299
1300/* --------------------------------------------------------------------------
1301 Driver Interface
1302 -------------------------------------------------------------------------- */
1303
1304/* device interface */
Rui Zhang82cae992007-01-03 23:40:53 -05001305static struct acpi_video_device_attrib*
1306acpi_video_get_device_attr(struct acpi_video_bus *video, unsigned long device_id)
1307{
1308 int count;
1309
1310 for(count = 0; count < video->attached_count; count++)
1311 if((video->attached_array[count].value.int_val & 0xffff) == device_id)
1312 return &(video->attached_array[count].value.attrib);
1313 return NULL;
1314}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001315
1316static int
Len Brown4be44fc2005-08-05 00:44:28 -04001317acpi_video_bus_get_one_device(struct acpi_device *device,
1318 struct acpi_video_bus *video)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001319{
Len Brown4be44fc2005-08-05 00:44:28 -04001320 unsigned long device_id;
Yu, Luming973bf492006-04-27 05:25:00 -04001321 int status;
Len Brown4be44fc2005-08-05 00:44:28 -04001322 struct acpi_video_device *data;
Rui Zhang82cae992007-01-03 23:40:53 -05001323 struct acpi_video_device_attrib* attribute;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001324
1325 if (!device || !video)
Patrick Mocheld550d982006-06-27 00:41:40 -04001326 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001327
Len Brown4be44fc2005-08-05 00:44:28 -04001328 status =
1329 acpi_evaluate_integer(device->handle, "_ADR", NULL, &device_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001330 if (ACPI_SUCCESS(status)) {
1331
Burman Yan36bcbec2006-12-19 12:56:11 -08001332 data = kzalloc(sizeof(struct acpi_video_device), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001333 if (!data)
Patrick Mocheld550d982006-06-27 00:41:40 -04001334 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001335
Linus Torvalds1da177e2005-04-16 15:20:36 -07001336 strcpy(acpi_device_name(device), ACPI_VIDEO_DEVICE_NAME);
1337 strcpy(acpi_device_class(device), ACPI_VIDEO_CLASS);
1338 acpi_driver_data(device) = data;
1339
1340 data->device_id = device_id;
1341 data->video = video;
1342 data->dev = device;
1343
Rui Zhang82cae992007-01-03 23:40:53 -05001344 attribute = acpi_video_get_device_attr(video, device_id);
1345
1346 if((attribute != NULL) && attribute->device_id_scheme) {
1347 switch (attribute->display_type) {
1348 case ACPI_VIDEO_DISPLAY_CRT:
1349 data->flags.crt = 1;
1350 break;
1351 case ACPI_VIDEO_DISPLAY_TV:
1352 data->flags.tvout = 1;
1353 break;
1354 case ACPI_VIDEO_DISPLAY_DVI:
1355 data->flags.dvi = 1;
1356 break;
1357 case ACPI_VIDEO_DISPLAY_LCD:
1358 data->flags.lcd = 1;
1359 break;
1360 default:
1361 data->flags.unknown = 1;
1362 break;
1363 }
1364 if(attribute->bios_can_detect)
1365 data->flags.bios = 1;
1366 } else
Linus Torvalds1da177e2005-04-16 15:20:36 -07001367 data->flags.unknown = 1;
Len Brown4be44fc2005-08-05 00:44:28 -04001368
Linus Torvalds1da177e2005-04-16 15:20:36 -07001369 acpi_video_device_bind(video, data);
1370 acpi_video_device_find_cap(data);
1371
Patrick Mochel90130262006-05-19 16:54:48 -04001372 status = acpi_install_notify_handler(device->handle,
Len Brown4be44fc2005-08-05 00:44:28 -04001373 ACPI_DEVICE_NOTIFY,
1374 acpi_video_device_notify,
1375 data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001376 if (ACPI_FAILURE(status)) {
1377 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
Len Brown4be44fc2005-08-05 00:44:28 -04001378 "Error installing notify handler\n"));
Yu, Luming973bf492006-04-27 05:25:00 -04001379 if(data->brightness)
1380 kfree(data->brightness->levels);
1381 kfree(data->brightness);
1382 kfree(data);
1383 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001384 }
1385
1386 down(&video->sem);
1387 list_add_tail(&data->entry, &video->video_device_list);
1388 up(&video->sem);
1389
1390 acpi_video_device_add_fs(device);
1391
Patrick Mocheld550d982006-06-27 00:41:40 -04001392 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001393 }
1394
Patrick Mocheld550d982006-06-27 00:41:40 -04001395 return -ENOENT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001396}
1397
1398/*
1399 * Arg:
1400 * video : video bus device
1401 *
1402 * Return:
1403 * none
1404 *
1405 * Enumerate the video device list of the video bus,
1406 * bind the ids with the corresponding video devices
1407 * under the video bus.
Len Brown4be44fc2005-08-05 00:44:28 -04001408 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001409
Len Brown4be44fc2005-08-05 00:44:28 -04001410static void acpi_video_device_rebind(struct acpi_video_bus *video)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001411{
Len Brown4be44fc2005-08-05 00:44:28 -04001412 struct list_head *node, *next;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001413 list_for_each_safe(node, next, &video->video_device_list) {
Len Brown4be44fc2005-08-05 00:44:28 -04001414 struct acpi_video_device *dev =
1415 container_of(node, struct acpi_video_device, entry);
1416 acpi_video_device_bind(video, dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001417 }
1418}
1419
1420/*
1421 * Arg:
1422 * video : video bus device
1423 * device : video output device under the video
1424 * bus
1425 *
1426 * Return:
1427 * none
1428 *
1429 * Bind the ids with the corresponding video devices
1430 * under the video bus.
Len Brown4be44fc2005-08-05 00:44:28 -04001431 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001432
1433static void
Len Brown4be44fc2005-08-05 00:44:28 -04001434acpi_video_device_bind(struct acpi_video_bus *video,
1435 struct acpi_video_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001436{
Len Brown4be44fc2005-08-05 00:44:28 -04001437 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001438
1439#define IDS_VAL(i) video->attached_array[i].value.int_val
1440#define IDS_BIND(i) video->attached_array[i].bind_info
Len Brown4be44fc2005-08-05 00:44:28 -04001441
1442 for (i = 0; IDS_VAL(i) != ACPI_VIDEO_HEAD_INVALID &&
1443 i < video->attached_count; i++) {
1444 if (device->device_id == (IDS_VAL(i) & 0xffff)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001445 IDS_BIND(i) = device;
1446 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "device_bind %d\n", i));
1447 }
1448 }
1449#undef IDS_VAL
1450#undef IDS_BIND
1451}
1452
1453/*
1454 * Arg:
1455 * video : video bus device
1456 *
1457 * Return:
1458 * < 0 : error
1459 *
1460 * Call _DOD to enumerate all devices attached to display adapter
1461 *
Len Brown4be44fc2005-08-05 00:44:28 -04001462 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001463
1464static int acpi_video_device_enumerate(struct acpi_video_bus *video)
1465{
Len Brown4be44fc2005-08-05 00:44:28 -04001466 int status;
1467 int count;
1468 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001469 struct acpi_video_enumerated_device *active_device_list;
Len Brown4be44fc2005-08-05 00:44:28 -04001470 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
1471 union acpi_object *dod = NULL;
1472 union acpi_object *obj;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001473
Patrick Mochel90130262006-05-19 16:54:48 -04001474 status = acpi_evaluate_object(video->device->handle, "_DOD", NULL, &buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001475 if (!ACPI_SUCCESS(status)) {
Thomas Renningera6fc6722006-06-26 23:58:43 -04001476 ACPI_EXCEPTION((AE_INFO, status, "Evaluating _DOD"));
Patrick Mocheld550d982006-06-27 00:41:40 -04001477 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001478 }
1479
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001480 dod = buffer.pointer;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001481 if (!dod || (dod->type != ACPI_TYPE_PACKAGE)) {
Thomas Renningera6fc6722006-06-26 23:58:43 -04001482 ACPI_EXCEPTION((AE_INFO, status, "Invalid _DOD data"));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001483 status = -EFAULT;
1484 goto out;
1485 }
1486
1487 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found %d video heads in _DOD\n",
Len Brown4be44fc2005-08-05 00:44:28 -04001488 dod->package.count));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001489
Len Brown4be44fc2005-08-05 00:44:28 -04001490 active_device_list = kmalloc((1 +
1491 dod->package.count) *
1492 sizeof(struct
1493 acpi_video_enumerated_device),
1494 GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001495
1496 if (!active_device_list) {
1497 status = -ENOMEM;
1498 goto out;
1499 }
1500
1501 count = 0;
1502 for (i = 0; i < dod->package.count; i++) {
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001503 obj = &dod->package.elements[i];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001504
1505 if (obj->type != ACPI_TYPE_INTEGER) {
Len Brown64684632006-06-26 23:41:38 -04001506 printk(KERN_ERR PREFIX "Invalid _DOD data\n");
Len Brown4be44fc2005-08-05 00:44:28 -04001507 active_device_list[i].value.int_val =
1508 ACPI_VIDEO_HEAD_INVALID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001509 }
1510 active_device_list[i].value.int_val = obj->integer.value;
1511 active_device_list[i].bind_info = NULL;
Len Brown4be44fc2005-08-05 00:44:28 -04001512 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "dod element[%d] = %d\n", i,
1513 (int)obj->integer.value));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001514 count++;
1515 }
1516 active_device_list[count].value.int_val = ACPI_VIDEO_HEAD_END;
1517
Jesper Juhl6044ec82005-11-07 01:01:32 -08001518 kfree(video->attached_array);
Len Brown4be44fc2005-08-05 00:44:28 -04001519
Linus Torvalds1da177e2005-04-16 15:20:36 -07001520 video->attached_array = active_device_list;
1521 video->attached_count = count;
Len Brown4be44fc2005-08-05 00:44:28 -04001522 out:
Len Brown02438d82006-06-30 03:19:10 -04001523 kfree(buffer.pointer);
Patrick Mocheld550d982006-06-27 00:41:40 -04001524 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001525}
1526
1527/*
1528 * Arg:
1529 * video : video bus device
Julius Volz98fb8fe2007-02-20 16:38:40 +01001530 * event : notify event
Linus Torvalds1da177e2005-04-16 15:20:36 -07001531 *
1532 * Return:
1533 * < 0 : error
1534 *
1535 * 1. Find out the current active output device.
Julius Volz98fb8fe2007-02-20 16:38:40 +01001536 * 2. Identify the next output device to switch to.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001537 * 3. call _DSS to do actual switch.
Len Brown4be44fc2005-08-05 00:44:28 -04001538 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001539
Len Brown4be44fc2005-08-05 00:44:28 -04001540static int acpi_video_switch_output(struct acpi_video_bus *video, int event)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001541{
Len Brown4be44fc2005-08-05 00:44:28 -04001542 struct list_head *node, *next;
1543 struct acpi_video_device *dev = NULL;
1544 struct acpi_video_device *dev_next = NULL;
1545 struct acpi_video_device *dev_prev = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001546 unsigned long state;
1547 int status = 0;
1548
Linus Torvalds1da177e2005-04-16 15:20:36 -07001549
1550 list_for_each_safe(node, next, &video->video_device_list) {
Adrian Bunk73345712005-03-30 22:31:35 -05001551 dev = container_of(node, struct acpi_video_device, entry);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001552 status = acpi_video_device_get_state(dev, &state);
Len Brown4be44fc2005-08-05 00:44:28 -04001553 if (state & 0x2) {
1554 dev_next =
1555 container_of(node->next, struct acpi_video_device,
1556 entry);
1557 dev_prev =
1558 container_of(node->prev, struct acpi_video_device,
1559 entry);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001560 goto out;
1561 }
1562 }
1563 dev_next = container_of(node->next, struct acpi_video_device, entry);
1564 dev_prev = container_of(node->prev, struct acpi_video_device, entry);
Len Brown4be44fc2005-08-05 00:44:28 -04001565 out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001566 switch (event) {
1567 case ACPI_VIDEO_NOTIFY_CYCLE:
1568 case ACPI_VIDEO_NOTIFY_NEXT_OUTPUT:
1569 acpi_video_device_set_state(dev, 0);
1570 acpi_video_device_set_state(dev_next, 0x80000001);
1571 break;
1572 case ACPI_VIDEO_NOTIFY_PREV_OUTPUT:
1573 acpi_video_device_set_state(dev, 0);
1574 acpi_video_device_set_state(dev_prev, 0x80000001);
1575 default:
1576 break;
1577 }
1578
Patrick Mocheld550d982006-06-27 00:41:40 -04001579 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001580}
1581
Len Brown4be44fc2005-08-05 00:44:28 -04001582static int
1583acpi_video_get_next_level(struct acpi_video_device *device,
1584 u32 level_current, u32 event)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001585{
Thomas Tuttlef4715182006-12-19 12:56:14 -08001586 int min, max, min_above, max_below, i, l;
1587 max = max_below = 0;
1588 min = min_above = 255;
1589 for (i = 0; i < device->brightness->count; i++) {
1590 l = device->brightness->levels[i];
1591 if (l < min)
1592 min = l;
1593 if (l > max)
1594 max = l;
1595 if (l < min_above && l > level_current)
1596 min_above = l;
1597 if (l > max_below && l < level_current)
1598 max_below = l;
1599 }
1600
1601 switch (event) {
1602 case ACPI_VIDEO_NOTIFY_CYCLE_BRIGHTNESS:
1603 return (level_current < max) ? min_above : min;
1604 case ACPI_VIDEO_NOTIFY_INC_BRIGHTNESS:
1605 return (level_current < max) ? min_above : max;
1606 case ACPI_VIDEO_NOTIFY_DEC_BRIGHTNESS:
1607 return (level_current > min) ? max_below : min;
1608 case ACPI_VIDEO_NOTIFY_ZERO_BRIGHTNESS:
1609 case ACPI_VIDEO_NOTIFY_DISPLAY_OFF:
1610 return 0;
1611 default:
1612 return level_current;
1613 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001614}
1615
Linus Torvalds1da177e2005-04-16 15:20:36 -07001616static void
Len Brown4be44fc2005-08-05 00:44:28 -04001617acpi_video_switch_brightness(struct acpi_video_device *device, int event)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001618{
1619 unsigned long level_current, level_next;
1620 acpi_video_device_lcd_get_level_current(device, &level_current);
1621 level_next = acpi_video_get_next_level(device, level_current, event);
1622 acpi_video_device_lcd_set_level(device, level_next);
1623}
1624
1625static int
Len Brown4be44fc2005-08-05 00:44:28 -04001626acpi_video_bus_get_devices(struct acpi_video_bus *video,
1627 struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001628{
Len Brown4be44fc2005-08-05 00:44:28 -04001629 int status = 0;
1630 struct list_head *node, *next;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001631
Linus Torvalds1da177e2005-04-16 15:20:36 -07001632
1633 acpi_video_device_enumerate(video);
1634
1635 list_for_each_safe(node, next, &device->children) {
Len Brown4be44fc2005-08-05 00:44:28 -04001636 struct acpi_device *dev =
1637 list_entry(node, struct acpi_device, node);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001638
1639 if (!dev)
1640 continue;
1641
1642 status = acpi_video_bus_get_one_device(dev, video);
1643 if (ACPI_FAILURE(status)) {
Thomas Renningera6fc6722006-06-26 23:58:43 -04001644 ACPI_EXCEPTION((AE_INFO, status, "Cant attach device"));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001645 continue;
1646 }
1647
1648 }
Patrick Mocheld550d982006-06-27 00:41:40 -04001649 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001650}
1651
Len Brown4be44fc2005-08-05 00:44:28 -04001652static int acpi_video_bus_put_one_device(struct acpi_video_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001653{
Karol Kozimor031ec772005-07-30 04:18:00 -04001654 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001655 struct acpi_video_bus *video;
1656
Linus Torvalds1da177e2005-04-16 15:20:36 -07001657
1658 if (!device || !device->video)
Patrick Mocheld550d982006-06-27 00:41:40 -04001659 return -ENOENT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001660
1661 video = device->video;
1662
1663 down(&video->sem);
1664 list_del(&device->entry);
1665 up(&video->sem);
1666 acpi_video_device_remove_fs(device->dev);
1667
Patrick Mochel90130262006-05-19 16:54:48 -04001668 status = acpi_remove_notify_handler(device->dev->handle,
Len Brown4be44fc2005-08-05 00:44:28 -04001669 ACPI_DEVICE_NOTIFY,
1670 acpi_video_device_notify);
Richard Purdie599a52d2007-02-10 23:07:48 +00001671 backlight_device_unregister(device->backlight);
Patrick Mocheld550d982006-06-27 00:41:40 -04001672 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001673}
1674
Len Brown4be44fc2005-08-05 00:44:28 -04001675static int acpi_video_bus_put_devices(struct acpi_video_bus *video)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001676{
Len Brown4be44fc2005-08-05 00:44:28 -04001677 int status;
1678 struct list_head *node, *next;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001679
Linus Torvalds1da177e2005-04-16 15:20:36 -07001680
1681 list_for_each_safe(node, next, &video->video_device_list) {
Len Brown4be44fc2005-08-05 00:44:28 -04001682 struct acpi_video_device *data =
1683 list_entry(node, struct acpi_video_device, entry);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001684 if (!data)
1685 continue;
1686
1687 status = acpi_video_bus_put_one_device(data);
Len Brown4be44fc2005-08-05 00:44:28 -04001688 if (ACPI_FAILURE(status))
1689 printk(KERN_WARNING PREFIX
1690 "hhuuhhuu bug in acpi video driver.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001691
Dave Jonesd384ea62006-06-24 00:33:08 -04001692 if (data->brightness)
Yu, Luming973bf492006-04-27 05:25:00 -04001693 kfree(data->brightness->levels);
Jesper Juhl6044ec82005-11-07 01:01:32 -08001694 kfree(data->brightness);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001695 kfree(data);
1696 }
1697
Patrick Mocheld550d982006-06-27 00:41:40 -04001698 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001699}
1700
1701/* acpi_video interface */
1702
Len Brown4be44fc2005-08-05 00:44:28 -04001703static int acpi_video_bus_start_devices(struct acpi_video_bus *video)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001704{
1705 return acpi_video_bus_DOS(video, 1, 0);
1706}
1707
Len Brown4be44fc2005-08-05 00:44:28 -04001708static int acpi_video_bus_stop_devices(struct acpi_video_bus *video)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001709{
1710 return acpi_video_bus_DOS(video, 0, 1);
1711}
1712
Len Brown4be44fc2005-08-05 00:44:28 -04001713static void acpi_video_bus_notify(acpi_handle handle, u32 event, void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001714{
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001715 struct acpi_video_bus *video = data;
Len Brown4be44fc2005-08-05 00:44:28 -04001716 struct acpi_device *device = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001717
Linus Torvalds1da177e2005-04-16 15:20:36 -07001718 printk("video bus notify\n");
1719
1720 if (!video)
Patrick Mocheld550d982006-06-27 00:41:40 -04001721 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001722
Patrick Mochele6afa0d2006-05-19 16:54:40 -04001723 device = video->device;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001724
1725 switch (event) {
Julius Volz98fb8fe2007-02-20 16:38:40 +01001726 case ACPI_VIDEO_NOTIFY_SWITCH: /* User requested a switch,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001727 * most likely via hotkey. */
1728 acpi_bus_generate_event(device, event, 0);
1729 break;
1730
Julius Volz98fb8fe2007-02-20 16:38:40 +01001731 case ACPI_VIDEO_NOTIFY_PROBE: /* User plugged in or removed a video
Linus Torvalds1da177e2005-04-16 15:20:36 -07001732 * connector. */
1733 acpi_video_device_enumerate(video);
1734 acpi_video_device_rebind(video);
1735 acpi_video_switch_output(video, event);
1736 acpi_bus_generate_event(device, event, 0);
1737 break;
1738
Len Brown4be44fc2005-08-05 00:44:28 -04001739 case ACPI_VIDEO_NOTIFY_CYCLE: /* Cycle Display output hotkey pressed. */
1740 case ACPI_VIDEO_NOTIFY_NEXT_OUTPUT: /* Next Display output hotkey pressed. */
1741 case ACPI_VIDEO_NOTIFY_PREV_OUTPUT: /* previous Display output hotkey pressed. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001742 acpi_video_switch_output(video, event);
1743 acpi_bus_generate_event(device, event, 0);
1744 break;
1745
1746 default:
1747 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
Len Brown4be44fc2005-08-05 00:44:28 -04001748 "Unsupported event [0x%x]\n", event));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001749 break;
1750 }
1751
Patrick Mocheld550d982006-06-27 00:41:40 -04001752 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001753}
1754
Len Brown4be44fc2005-08-05 00:44:28 -04001755static void acpi_video_device_notify(acpi_handle handle, u32 event, void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001756{
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001757 struct acpi_video_device *video_device = data;
Len Brown4be44fc2005-08-05 00:44:28 -04001758 struct acpi_device *device = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001759
Linus Torvalds1da177e2005-04-16 15:20:36 -07001760 if (!video_device)
Patrick Mocheld550d982006-06-27 00:41:40 -04001761 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001762
Patrick Mochele6afa0d2006-05-19 16:54:40 -04001763 device = video_device->dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001764
1765 switch (event) {
Len Brown4be44fc2005-08-05 00:44:28 -04001766 case ACPI_VIDEO_NOTIFY_SWITCH: /* change in status (cycle output device) */
1767 case ACPI_VIDEO_NOTIFY_PROBE: /* change in status (output device status) */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001768 acpi_bus_generate_event(device, event, 0);
1769 break;
Len Brown4be44fc2005-08-05 00:44:28 -04001770 case ACPI_VIDEO_NOTIFY_CYCLE_BRIGHTNESS: /* Cycle brightness */
1771 case ACPI_VIDEO_NOTIFY_INC_BRIGHTNESS: /* Increase brightness */
1772 case ACPI_VIDEO_NOTIFY_DEC_BRIGHTNESS: /* Decrease brightness */
1773 case ACPI_VIDEO_NOTIFY_ZERO_BRIGHTNESS: /* zero brightnesss */
1774 case ACPI_VIDEO_NOTIFY_DISPLAY_OFF: /* display device off */
1775 acpi_video_switch_brightness(video_device, event);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001776 acpi_bus_generate_event(device, event, 0);
1777 break;
1778 default:
1779 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
Len Brown4be44fc2005-08-05 00:44:28 -04001780 "Unsupported event [0x%x]\n", event));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001781 break;
1782 }
Patrick Mocheld550d982006-06-27 00:41:40 -04001783 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001784}
1785
Len Brown4be44fc2005-08-05 00:44:28 -04001786static int acpi_video_bus_add(struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001787{
Len Brown4be44fc2005-08-05 00:44:28 -04001788 int result = 0;
1789 acpi_status status = 0;
1790 struct acpi_video_bus *video = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001791
Len Brown4be44fc2005-08-05 00:44:28 -04001792
Linus Torvalds1da177e2005-04-16 15:20:36 -07001793 if (!device)
Patrick Mocheld550d982006-06-27 00:41:40 -04001794 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001795
Burman Yan36bcbec2006-12-19 12:56:11 -08001796 video = kzalloc(sizeof(struct acpi_video_bus), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001797 if (!video)
Patrick Mocheld550d982006-06-27 00:41:40 -04001798 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001799
Patrick Mochele6afa0d2006-05-19 16:54:40 -04001800 video->device = device;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001801 strcpy(acpi_device_name(device), ACPI_VIDEO_BUS_NAME);
1802 strcpy(acpi_device_class(device), ACPI_VIDEO_CLASS);
1803 acpi_driver_data(device) = video;
1804
1805 acpi_video_bus_find_cap(video);
1806 result = acpi_video_bus_check(video);
1807 if (result)
1808 goto end;
1809
1810 result = acpi_video_bus_add_fs(device);
1811 if (result)
1812 goto end;
1813
1814 init_MUTEX(&video->sem);
1815 INIT_LIST_HEAD(&video->video_device_list);
1816
1817 acpi_video_bus_get_devices(video, device);
1818 acpi_video_bus_start_devices(video);
1819
Patrick Mochel90130262006-05-19 16:54:48 -04001820 status = acpi_install_notify_handler(device->handle,
Len Brown4be44fc2005-08-05 00:44:28 -04001821 ACPI_DEVICE_NOTIFY,
1822 acpi_video_bus_notify, video);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001823 if (ACPI_FAILURE(status)) {
1824 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
Len Brown4be44fc2005-08-05 00:44:28 -04001825 "Error installing notify handler\n"));
Yu, Luming973bf492006-04-27 05:25:00 -04001826 acpi_video_bus_stop_devices(video);
1827 acpi_video_bus_put_devices(video);
1828 kfree(video->attached_array);
1829 acpi_video_bus_remove_fs(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001830 result = -ENODEV;
1831 goto end;
1832 }
1833
1834 printk(KERN_INFO PREFIX "%s [%s] (multi-head: %s rom: %s post: %s)\n",
Len Brown4be44fc2005-08-05 00:44:28 -04001835 ACPI_VIDEO_DEVICE_NAME, acpi_device_bid(device),
1836 video->flags.multihead ? "yes" : "no",
1837 video->flags.rom ? "yes" : "no",
1838 video->flags.post ? "yes" : "no");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001839
Len Brown4be44fc2005-08-05 00:44:28 -04001840 end:
Yu, Luming973bf492006-04-27 05:25:00 -04001841 if (result)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001842 kfree(video);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001843
Patrick Mocheld550d982006-06-27 00:41:40 -04001844 return result;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001845}
1846
Len Brown4be44fc2005-08-05 00:44:28 -04001847static int acpi_video_bus_remove(struct acpi_device *device, int type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001848{
Len Brown4be44fc2005-08-05 00:44:28 -04001849 acpi_status status = 0;
1850 struct acpi_video_bus *video = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001851
Linus Torvalds1da177e2005-04-16 15:20:36 -07001852
1853 if (!device || !acpi_driver_data(device))
Patrick Mocheld550d982006-06-27 00:41:40 -04001854 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001855
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001856 video = acpi_driver_data(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001857
1858 acpi_video_bus_stop_devices(video);
1859
Patrick Mochel90130262006-05-19 16:54:48 -04001860 status = acpi_remove_notify_handler(video->device->handle,
Len Brown4be44fc2005-08-05 00:44:28 -04001861 ACPI_DEVICE_NOTIFY,
1862 acpi_video_bus_notify);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001863
1864 acpi_video_bus_put_devices(video);
1865 acpi_video_bus_remove_fs(device);
1866
Jesper Juhl6044ec82005-11-07 01:01:32 -08001867 kfree(video->attached_array);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001868 kfree(video);
1869
Patrick Mocheld550d982006-06-27 00:41:40 -04001870 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001871}
1872
Len Brown4be44fc2005-08-05 00:44:28 -04001873static int __init acpi_video_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001874{
Len Brown4be44fc2005-08-05 00:44:28 -04001875 int result = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001876
Linus Torvalds1da177e2005-04-16 15:20:36 -07001877
1878 /*
Len Brown4be44fc2005-08-05 00:44:28 -04001879 acpi_dbg_level = 0xFFFFFFFF;
1880 acpi_dbg_layer = 0x08000000;
1881 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001882
1883 acpi_video_dir = proc_mkdir(ACPI_VIDEO_CLASS, acpi_root_dir);
1884 if (!acpi_video_dir)
Patrick Mocheld550d982006-06-27 00:41:40 -04001885 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001886 acpi_video_dir->owner = THIS_MODULE;
1887
1888 result = acpi_bus_register_driver(&acpi_video_bus);
1889 if (result < 0) {
1890 remove_proc_entry(ACPI_VIDEO_CLASS, acpi_root_dir);
Patrick Mocheld550d982006-06-27 00:41:40 -04001891 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001892 }
1893
Patrick Mocheld550d982006-06-27 00:41:40 -04001894 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001895}
1896
Len Brown4be44fc2005-08-05 00:44:28 -04001897static void __exit acpi_video_exit(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001898{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001899
1900 acpi_bus_unregister_driver(&acpi_video_bus);
1901
1902 remove_proc_entry(ACPI_VIDEO_CLASS, acpi_root_dir);
1903
Patrick Mocheld550d982006-06-27 00:41:40 -04001904 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001905}
1906
1907module_init(acpi_video_init);
1908module_exit(acpi_video_exit);