blob: bf525cca3b637160a3c1b28f95269ea108c1dfd3 [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 */
105 u32 display_port_attachment:4; /*This field differenates displays type */
106 u32 display_type:4; /*Describe the specific type in use */
107 u32 vendor_specific:4; /*Chipset Vendor Specifi */
108 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;
172 struct backlight_properties *data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700173};
174
Linus Torvalds1da177e2005-04-16 15:20:36 -0700175/* bus */
176static int acpi_video_bus_info_open_fs(struct inode *inode, struct file *file);
177static struct file_operations acpi_video_bus_info_fops = {
Len Brown4be44fc2005-08-05 00:44:28 -0400178 .open = acpi_video_bus_info_open_fs,
179 .read = seq_read,
180 .llseek = seq_lseek,
181 .release = single_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700182};
183
184static int acpi_video_bus_ROM_open_fs(struct inode *inode, struct file *file);
185static struct file_operations acpi_video_bus_ROM_fops = {
Len Brown4be44fc2005-08-05 00:44:28 -0400186 .open = acpi_video_bus_ROM_open_fs,
187 .read = seq_read,
188 .llseek = seq_lseek,
189 .release = single_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700190};
191
Len Brown4be44fc2005-08-05 00:44:28 -0400192static int acpi_video_bus_POST_info_open_fs(struct inode *inode,
193 struct file *file);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700194static struct file_operations acpi_video_bus_POST_info_fops = {
Len Brown4be44fc2005-08-05 00:44:28 -0400195 .open = acpi_video_bus_POST_info_open_fs,
196 .read = seq_read,
197 .llseek = seq_lseek,
198 .release = single_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700199};
200
201static int acpi_video_bus_POST_open_fs(struct inode *inode, struct file *file);
202static struct file_operations acpi_video_bus_POST_fops = {
Len Brown4be44fc2005-08-05 00:44:28 -0400203 .open = acpi_video_bus_POST_open_fs,
204 .read = seq_read,
205 .llseek = seq_lseek,
206 .release = single_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700207};
208
Linus Torvalds1da177e2005-04-16 15:20:36 -0700209static int acpi_video_bus_DOS_open_fs(struct inode *inode, struct file *file);
210static struct file_operations acpi_video_bus_DOS_fops = {
Len Brown4be44fc2005-08-05 00:44:28 -0400211 .open = acpi_video_bus_DOS_open_fs,
212 .read = seq_read,
213 .llseek = seq_lseek,
214 .release = single_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700215};
216
217/* device */
Len Brown4be44fc2005-08-05 00:44:28 -0400218static int acpi_video_device_info_open_fs(struct inode *inode,
219 struct file *file);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700220static struct file_operations acpi_video_device_info_fops = {
Len Brown4be44fc2005-08-05 00:44:28 -0400221 .open = acpi_video_device_info_open_fs,
222 .read = seq_read,
223 .llseek = seq_lseek,
224 .release = single_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700225};
226
Len Brown4be44fc2005-08-05 00:44:28 -0400227static int acpi_video_device_state_open_fs(struct inode *inode,
228 struct file *file);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700229static struct file_operations acpi_video_device_state_fops = {
Len Brown4be44fc2005-08-05 00:44:28 -0400230 .open = acpi_video_device_state_open_fs,
231 .read = seq_read,
232 .llseek = seq_lseek,
233 .release = single_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700234};
235
Len Brown4be44fc2005-08-05 00:44:28 -0400236static int acpi_video_device_brightness_open_fs(struct inode *inode,
237 struct file *file);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700238static struct file_operations acpi_video_device_brightness_fops = {
Len Brown4be44fc2005-08-05 00:44:28 -0400239 .open = acpi_video_device_brightness_open_fs,
240 .read = seq_read,
241 .llseek = seq_lseek,
242 .release = single_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700243};
244
Len Brown4be44fc2005-08-05 00:44:28 -0400245static int acpi_video_device_EDID_open_fs(struct inode *inode,
246 struct file *file);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700247static struct file_operations acpi_video_device_EDID_fops = {
Len Brown4be44fc2005-08-05 00:44:28 -0400248 .open = acpi_video_device_EDID_open_fs,
249 .read = seq_read,
250 .llseek = seq_lseek,
251 .release = single_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700252};
253
Len Brown4be44fc2005-08-05 00:44:28 -0400254static char device_decode[][30] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700255 "motherboard VGA device",
256 "PCI VGA device",
257 "AGP VGA device",
258 "UNKNOWN",
259};
260
Len Brown4be44fc2005-08-05 00:44:28 -0400261static void acpi_video_device_notify(acpi_handle handle, u32 event, void *data);
262static void acpi_video_device_rebind(struct acpi_video_bus *video);
263static void acpi_video_device_bind(struct acpi_video_bus *video,
264 struct acpi_video_device *device);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700265static int acpi_video_device_enumerate(struct acpi_video_bus *video);
Len Brown4be44fc2005-08-05 00:44:28 -0400266static int acpi_video_switch_output(struct acpi_video_bus *video, int event);
Yu Luming2f3d0002006-11-11 02:40:34 +0800267static int acpi_video_device_lcd_set_level(struct acpi_video_device *device,
268 int level);
269static int acpi_video_device_lcd_get_level_current(
270 struct acpi_video_device *device,
271 unsigned long *level);
Len Brown4be44fc2005-08-05 00:44:28 -0400272static int acpi_video_get_next_level(struct acpi_video_device *device,
273 u32 level_current, u32 event);
274static void acpi_video_switch_brightness(struct acpi_video_device *device,
275 int event);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700276
Yu Luming2f3d0002006-11-11 02:40:34 +0800277/*backlight device sysfs support*/
278static int acpi_video_get_brightness(struct backlight_device *bd)
279{
280 unsigned long cur_level;
281 struct acpi_video_device *vd =
282 (struct acpi_video_device *)class_get_devdata(&bd->class_dev);
283 acpi_video_device_lcd_get_level_current(vd, &cur_level);
284 return (int) cur_level;
285}
286
287static int acpi_video_set_brightness(struct backlight_device *bd)
288{
289 int request_level = bd->props->brightness;
290 struct acpi_video_device *vd =
291 (struct acpi_video_device *)class_get_devdata(&bd->class_dev);
292 acpi_video_device_lcd_set_level(vd, request_level);
293 return 0;
294}
295
Linus Torvalds1da177e2005-04-16 15:20:36 -0700296/* --------------------------------------------------------------------------
297 Video Management
298 -------------------------------------------------------------------------- */
299
300/* device */
301
302static int
Len Brown4be44fc2005-08-05 00:44:28 -0400303acpi_video_device_query(struct acpi_video_device *device, unsigned long *state)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700304{
Len Brown4be44fc2005-08-05 00:44:28 -0400305 int status;
Patrick Mochel90130262006-05-19 16:54:48 -0400306
307 status = acpi_evaluate_integer(device->dev->handle, "_DGS", NULL, state);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700308
Patrick Mocheld550d982006-06-27 00:41:40 -0400309 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700310}
311
312static int
Len Brown4be44fc2005-08-05 00:44:28 -0400313acpi_video_device_get_state(struct acpi_video_device *device,
314 unsigned long *state)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700315{
Len Brown4be44fc2005-08-05 00:44:28 -0400316 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700317
Patrick Mochel90130262006-05-19 16:54:48 -0400318 status = acpi_evaluate_integer(device->dev->handle, "_DCS", NULL, state);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700319
Patrick Mocheld550d982006-06-27 00:41:40 -0400320 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700321}
322
323static int
Len Brown4be44fc2005-08-05 00:44:28 -0400324acpi_video_device_set_state(struct acpi_video_device *device, int state)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700325{
Len Brown4be44fc2005-08-05 00:44:28 -0400326 int status;
327 union acpi_object arg0 = { ACPI_TYPE_INTEGER };
328 struct acpi_object_list args = { 1, &arg0 };
Luming Yu824b5582005-08-21 19:17:00 -0400329 unsigned long ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700330
Linus Torvalds1da177e2005-04-16 15:20:36 -0700331
332 arg0.integer.value = state;
Patrick Mochel90130262006-05-19 16:54:48 -0400333 status = acpi_evaluate_integer(device->dev->handle, "_DSS", &args, &ret);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700334
Patrick Mocheld550d982006-06-27 00:41:40 -0400335 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700336}
337
338static int
Len Brown4be44fc2005-08-05 00:44:28 -0400339acpi_video_device_lcd_query_levels(struct acpi_video_device *device,
340 union acpi_object **levels)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700341{
Len Brown4be44fc2005-08-05 00:44:28 -0400342 int status;
343 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
344 union acpi_object *obj;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700345
Linus Torvalds1da177e2005-04-16 15:20:36 -0700346
347 *levels = NULL;
348
Patrick Mochel90130262006-05-19 16:54:48 -0400349 status = acpi_evaluate_object(device->dev->handle, "_BCL", NULL, &buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700350 if (!ACPI_SUCCESS(status))
Patrick Mocheld550d982006-06-27 00:41:40 -0400351 return status;
Len Brown4be44fc2005-08-05 00:44:28 -0400352 obj = (union acpi_object *)buffer.pointer;
Adrian Bunk6665bda2006-03-11 10:12:00 -0500353 if (!obj || (obj->type != ACPI_TYPE_PACKAGE)) {
Len Brown64684632006-06-26 23:41:38 -0400354 printk(KERN_ERR PREFIX "Invalid _BCL data\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700355 status = -EFAULT;
356 goto err;
357 }
358
359 *levels = obj;
360
Patrick Mocheld550d982006-06-27 00:41:40 -0400361 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700362
Len Brown4be44fc2005-08-05 00:44:28 -0400363 err:
Jesper Juhl6044ec82005-11-07 01:01:32 -0800364 kfree(buffer.pointer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700365
Patrick Mocheld550d982006-06-27 00:41:40 -0400366 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700367}
368
369static int
Len Brown4be44fc2005-08-05 00:44:28 -0400370acpi_video_device_lcd_set_level(struct acpi_video_device *device, int level)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700371{
Len Brown4be44fc2005-08-05 00:44:28 -0400372 int status;
373 union acpi_object arg0 = { ACPI_TYPE_INTEGER };
374 struct acpi_object_list args = { 1, &arg0 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700375
Linus Torvalds1da177e2005-04-16 15:20:36 -0700376
377 arg0.integer.value = level;
Patrick Mochel90130262006-05-19 16:54:48 -0400378 status = acpi_evaluate_object(device->dev->handle, "_BCM", &args, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700379
380 printk(KERN_DEBUG "set_level status: %x\n", status);
Patrick Mocheld550d982006-06-27 00:41:40 -0400381 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700382}
383
384static int
Len Brown4be44fc2005-08-05 00:44:28 -0400385acpi_video_device_lcd_get_level_current(struct acpi_video_device *device,
386 unsigned long *level)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700387{
Len Brown4be44fc2005-08-05 00:44:28 -0400388 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700389
Patrick Mochel90130262006-05-19 16:54:48 -0400390 status = acpi_evaluate_integer(device->dev->handle, "_BQC", NULL, level);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700391
Patrick Mocheld550d982006-06-27 00:41:40 -0400392 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700393}
394
395static int
Len Brown4be44fc2005-08-05 00:44:28 -0400396acpi_video_device_EDID(struct acpi_video_device *device,
397 union acpi_object **edid, ssize_t length)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700398{
Len Brown4be44fc2005-08-05 00:44:28 -0400399 int status;
400 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
401 union acpi_object *obj;
402 union acpi_object arg0 = { ACPI_TYPE_INTEGER };
403 struct acpi_object_list args = { 1, &arg0 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700404
Linus Torvalds1da177e2005-04-16 15:20:36 -0700405
406 *edid = NULL;
407
408 if (!device)
Patrick Mocheld550d982006-06-27 00:41:40 -0400409 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700410 if (length == 128)
411 arg0.integer.value = 1;
412 else if (length == 256)
413 arg0.integer.value = 2;
414 else
Patrick Mocheld550d982006-06-27 00:41:40 -0400415 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700416
Patrick Mochel90130262006-05-19 16:54:48 -0400417 status = acpi_evaluate_object(device->dev->handle, "_DDC", &args, &buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700418 if (ACPI_FAILURE(status))
Patrick Mocheld550d982006-06-27 00:41:40 -0400419 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700420
Jan Engelhardt50dd0962006-10-01 00:28:50 +0200421 obj = buffer.pointer;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700422
423 if (obj && obj->type == ACPI_TYPE_BUFFER)
424 *edid = obj;
425 else {
Len Brown64684632006-06-26 23:41:38 -0400426 printk(KERN_ERR PREFIX "Invalid _DDC data\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700427 status = -EFAULT;
428 kfree(obj);
429 }
430
Patrick Mocheld550d982006-06-27 00:41:40 -0400431 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700432}
433
Linus Torvalds1da177e2005-04-16 15:20:36 -0700434/* bus */
435
436static int
Len Brown4be44fc2005-08-05 00:44:28 -0400437acpi_video_bus_set_POST(struct acpi_video_bus *video, unsigned long option)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700438{
Len Brown4be44fc2005-08-05 00:44:28 -0400439 int status;
440 unsigned long tmp;
441 union acpi_object arg0 = { ACPI_TYPE_INTEGER };
442 struct acpi_object_list args = { 1, &arg0 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700443
Linus Torvalds1da177e2005-04-16 15:20:36 -0700444
445 arg0.integer.value = option;
446
Patrick Mochel90130262006-05-19 16:54:48 -0400447 status = acpi_evaluate_integer(video->device->handle, "_SPD", &args, &tmp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700448 if (ACPI_SUCCESS(status))
Len Brown4be44fc2005-08-05 00:44:28 -0400449 status = tmp ? (-EINVAL) : (AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700450
Patrick Mocheld550d982006-06-27 00:41:40 -0400451 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700452}
453
454static int
Len Brown4be44fc2005-08-05 00:44:28 -0400455acpi_video_bus_get_POST(struct acpi_video_bus *video, unsigned long *id)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700456{
457 int status;
458
Patrick Mochel90130262006-05-19 16:54:48 -0400459 status = acpi_evaluate_integer(video->device->handle, "_GPD", NULL, id);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700460
Patrick Mocheld550d982006-06-27 00:41:40 -0400461 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700462}
463
464static int
Len Brown4be44fc2005-08-05 00:44:28 -0400465acpi_video_bus_POST_options(struct acpi_video_bus *video,
466 unsigned long *options)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700467{
Len Brown4be44fc2005-08-05 00:44:28 -0400468 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700469
Patrick Mochel90130262006-05-19 16:54:48 -0400470 status = acpi_evaluate_integer(video->device->handle, "_VPO", NULL, options);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700471 *options &= 3;
472
Patrick Mocheld550d982006-06-27 00:41:40 -0400473 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700474}
475
476/*
477 * Arg:
478 * video : video bus device pointer
479 * bios_flag :
480 * 0. The system BIOS should NOT automatically switch(toggle)
481 * the active display output.
482 * 1. The system BIOS should automatically switch (toggle) the
483 * active display output. No swich event.
484 * 2. The _DGS value should be locked.
485 * 3. The system BIOS should not automatically switch (toggle) the
486 * active display output, but instead generate the display switch
487 * event notify code.
488 * lcd_flag :
489 * 0. The system BIOS should automatically control the brightness level
490 * of the LCD, when the power changes from AC to DC
491 * 1. The system BIOS should NOT automatically control the brightness
492 * level of the LCD, when the power changes from AC to DC.
493 * Return Value:
494 * -1 wrong arg.
495 */
496
497static int
Len Brown4be44fc2005-08-05 00:44:28 -0400498acpi_video_bus_DOS(struct acpi_video_bus *video, int bios_flag, int lcd_flag)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700499{
Len Brown4be44fc2005-08-05 00:44:28 -0400500 acpi_integer status = 0;
501 union acpi_object arg0 = { ACPI_TYPE_INTEGER };
502 struct acpi_object_list args = { 1, &arg0 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700503
Linus Torvalds1da177e2005-04-16 15:20:36 -0700504
Len Brown4be44fc2005-08-05 00:44:28 -0400505 if (bios_flag < 0 || bios_flag > 3 || lcd_flag < 0 || lcd_flag > 1) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700506 status = -1;
507 goto Failed;
508 }
509 arg0.integer.value = (lcd_flag << 2) | bios_flag;
510 video->dos_setting = arg0.integer.value;
Patrick Mochel90130262006-05-19 16:54:48 -0400511 acpi_evaluate_object(video->device->handle, "_DOS", &args, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700512
Len Brown4be44fc2005-08-05 00:44:28 -0400513 Failed:
Patrick Mocheld550d982006-06-27 00:41:40 -0400514 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700515}
516
517/*
518 * Arg:
519 * device : video output device (LCD, CRT, ..)
520 *
521 * Return Value:
522 * None
523 *
524 * Find out all required AML method defined under the output
525 * device.
526 */
527
Len Brown4be44fc2005-08-05 00:44:28 -0400528static void acpi_video_device_find_cap(struct acpi_video_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700529{
Len Brown4be44fc2005-08-05 00:44:28 -0400530 acpi_integer status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700531 acpi_handle h_dummy1;
532 int i;
Yu Luming2f3d0002006-11-11 02:40:34 +0800533 u32 max_level = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700534 union acpi_object *obj = NULL;
535 struct acpi_video_device_brightness *br = NULL;
536
Linus Torvalds1da177e2005-04-16 15:20:36 -0700537
Len Brown4be44fc2005-08-05 00:44:28 -0400538 memset(&device->cap, 0, 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700539
Patrick Mochel90130262006-05-19 16:54:48 -0400540 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_ADR", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700541 device->cap._ADR = 1;
542 }
Patrick Mochel90130262006-05-19 16:54:48 -0400543 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_BCL", &h_dummy1))) {
Len Brown4be44fc2005-08-05 00:44:28 -0400544 device->cap._BCL = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700545 }
Patrick Mochel90130262006-05-19 16:54:48 -0400546 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_BCM", &h_dummy1))) {
Len Brown4be44fc2005-08-05 00:44:28 -0400547 device->cap._BCM = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700548 }
Yu Luming2f3d0002006-11-11 02:40:34 +0800549 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle,"_BQC",&h_dummy1)))
550 device->cap._BQC = 1;
Patrick Mochel90130262006-05-19 16:54:48 -0400551 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_DDC", &h_dummy1))) {
Len Brown4be44fc2005-08-05 00:44:28 -0400552 device->cap._DDC = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700553 }
Patrick Mochel90130262006-05-19 16:54:48 -0400554 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_DCS", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700555 device->cap._DCS = 1;
556 }
Patrick Mochel90130262006-05-19 16:54:48 -0400557 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_DGS", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700558 device->cap._DGS = 1;
559 }
Patrick Mochel90130262006-05-19 16:54:48 -0400560 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_DSS", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700561 device->cap._DSS = 1;
562 }
563
564 status = acpi_video_device_lcd_query_levels(device, &obj);
565
566 if (obj && obj->type == ACPI_TYPE_PACKAGE && obj->package.count >= 2) {
567 int count = 0;
568 union acpi_object *o;
Len Brown4be44fc2005-08-05 00:44:28 -0400569
Burman Yan36bcbec2006-12-19 12:56:11 -0800570 br = kzalloc(sizeof(*br), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700571 if (!br) {
572 printk(KERN_ERR "can't allocate memory\n");
573 } else {
Paulo Marquesd1dd0c22005-03-30 22:39:49 -0500574 br->levels = kmalloc(obj->package.count *
Len Brown4be44fc2005-08-05 00:44:28 -0400575 sizeof *(br->levels), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700576 if (!br->levels)
577 goto out;
578
579 for (i = 0; i < obj->package.count; i++) {
Len Brown4be44fc2005-08-05 00:44:28 -0400580 o = (union acpi_object *)&obj->package.
581 elements[i];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700582 if (o->type != ACPI_TYPE_INTEGER) {
Len Brown64684632006-06-26 23:41:38 -0400583 printk(KERN_ERR PREFIX "Invalid data\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700584 continue;
585 }
586 br->levels[count] = (u32) o->integer.value;
Yu Luming2f3d0002006-11-11 02:40:34 +0800587 if (br->levels[count] > max_level)
588 max_level = br->levels[count];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700589 count++;
590 }
Len Brown4be44fc2005-08-05 00:44:28 -0400591 out:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700592 if (count < 2) {
Paulo Marquesd1dd0c22005-03-30 22:39:49 -0500593 kfree(br->levels);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700594 kfree(br);
595 } else {
596 br->count = count;
597 device->brightness = br;
Len Brown4be44fc2005-08-05 00:44:28 -0400598 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
599 "found %d brightness levels\n",
600 count));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700601 }
602 }
603 }
604
Paulo Marquesd1dd0c22005-03-30 22:39:49 -0500605 kfree(obj);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700606
Yu Luming2f3d0002006-11-11 02:40:34 +0800607 if (device->cap._BCL && device->cap._BCM && device->cap._BQC){
608 unsigned long tmp;
609 static int count = 0;
610 char *name;
611 struct backlight_properties *acpi_video_data;
612
613 name = kzalloc(MAX_NAME_LEN, GFP_KERNEL);
614 if (!name)
615 return;
616
617 acpi_video_data = kzalloc(
618 sizeof(struct backlight_properties),
619 GFP_KERNEL);
620 if (!acpi_video_data){
621 kfree(name);
622 return;
623 }
624 acpi_video_data->owner = THIS_MODULE;
625 acpi_video_data->get_brightness =
626 acpi_video_get_brightness;
627 acpi_video_data->update_status =
628 acpi_video_set_brightness;
629 sprintf(name, "acpi_video%d", count++);
630 device->data = acpi_video_data;
631 acpi_video_data->max_brightness = max_level;
632 acpi_video_device_lcd_get_level_current(device, &tmp);
633 acpi_video_data->brightness = (int)tmp;
634 device->backlight = backlight_device_register(name,
635 NULL, device, acpi_video_data);
636 kfree(name);
637 }
Patrick Mocheld550d982006-06-27 00:41:40 -0400638 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700639}
640
641/*
642 * Arg:
643 * device : video output device (VGA)
644 *
645 * Return Value:
646 * None
647 *
648 * Find out all required AML method defined under the video bus device.
649 */
650
Len Brown4be44fc2005-08-05 00:44:28 -0400651static void acpi_video_bus_find_cap(struct acpi_video_bus *video)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700652{
Len Brown4be44fc2005-08-05 00:44:28 -0400653 acpi_handle h_dummy1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700654
Len Brown4be44fc2005-08-05 00:44:28 -0400655 memset(&video->cap, 0, 4);
Patrick Mochel90130262006-05-19 16:54:48 -0400656 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_DOS", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700657 video->cap._DOS = 1;
658 }
Patrick Mochel90130262006-05-19 16:54:48 -0400659 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_DOD", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700660 video->cap._DOD = 1;
661 }
Patrick Mochel90130262006-05-19 16:54:48 -0400662 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_ROM", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700663 video->cap._ROM = 1;
664 }
Patrick Mochel90130262006-05-19 16:54:48 -0400665 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_GPD", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700666 video->cap._GPD = 1;
667 }
Patrick Mochel90130262006-05-19 16:54:48 -0400668 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_SPD", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700669 video->cap._SPD = 1;
670 }
Patrick Mochel90130262006-05-19 16:54:48 -0400671 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_VPO", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700672 video->cap._VPO = 1;
673 }
674}
675
676/*
677 * Check whether the video bus device has required AML method to
678 * support the desired features
679 */
680
Len Brown4be44fc2005-08-05 00:44:28 -0400681static int acpi_video_bus_check(struct acpi_video_bus *video)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700682{
Len Brown4be44fc2005-08-05 00:44:28 -0400683 acpi_status status = -ENOENT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700684
Linus Torvalds1da177e2005-04-16 15:20:36 -0700685
686 if (!video)
Patrick Mocheld550d982006-06-27 00:41:40 -0400687 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700688
689 /* Since there is no HID, CID and so on for VGA driver, we have
690 * to check well known required nodes.
691 */
692
693 /* Does this device able to support video switching ? */
Len Brown4be44fc2005-08-05 00:44:28 -0400694 if (video->cap._DOS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700695 video->flags.multihead = 1;
696 status = 0;
697 }
698
699 /* Does this device able to retrieve a retrieve a video ROM ? */
Len Brown4be44fc2005-08-05 00:44:28 -0400700 if (video->cap._ROM) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700701 video->flags.rom = 1;
702 status = 0;
703 }
704
705 /* Does this device able to configure which video device to POST ? */
Len Brown4be44fc2005-08-05 00:44:28 -0400706 if (video->cap._GPD && video->cap._SPD && video->cap._VPO) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700707 video->flags.post = 1;
708 status = 0;
709 }
710
Patrick Mocheld550d982006-06-27 00:41:40 -0400711 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700712}
713
714/* --------------------------------------------------------------------------
715 FS Interface (/proc)
716 -------------------------------------------------------------------------- */
717
Len Brown4be44fc2005-08-05 00:44:28 -0400718static struct proc_dir_entry *acpi_video_dir;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700719
720/* video devices */
721
Len Brown4be44fc2005-08-05 00:44:28 -0400722static int acpi_video_device_info_seq_show(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700723{
Jan Engelhardt50dd0962006-10-01 00:28:50 +0200724 struct acpi_video_device *dev = seq->private;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700725
Linus Torvalds1da177e2005-04-16 15:20:36 -0700726
727 if (!dev)
728 goto end;
729
730 seq_printf(seq, "device_id: 0x%04x\n", (u32) dev->device_id);
731 seq_printf(seq, "type: ");
732 if (dev->flags.crt)
733 seq_printf(seq, "CRT\n");
734 else if (dev->flags.lcd)
735 seq_printf(seq, "LCD\n");
736 else if (dev->flags.tvout)
737 seq_printf(seq, "TVOUT\n");
Rui Zhang82cae992007-01-03 23:40:53 -0500738 else if (dev->flags.dvi)
739 seq_printf(seq, "DVI\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700740 else
741 seq_printf(seq, "UNKNOWN\n");
742
Len Brown4be44fc2005-08-05 00:44:28 -0400743 seq_printf(seq, "known by bios: %s\n", dev->flags.bios ? "yes" : "no");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700744
Len Brown4be44fc2005-08-05 00:44:28 -0400745 end:
Patrick Mocheld550d982006-06-27 00:41:40 -0400746 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700747}
748
749static int
Len Brown4be44fc2005-08-05 00:44:28 -0400750acpi_video_device_info_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700751{
752 return single_open(file, acpi_video_device_info_seq_show,
753 PDE(inode)->data);
754}
755
Len Brown4be44fc2005-08-05 00:44:28 -0400756static int acpi_video_device_state_seq_show(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700757{
Len Brown4be44fc2005-08-05 00:44:28 -0400758 int status;
Jan Engelhardt50dd0962006-10-01 00:28:50 +0200759 struct acpi_video_device *dev = seq->private;
Len Brown4be44fc2005-08-05 00:44:28 -0400760 unsigned long state;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700761
Linus Torvalds1da177e2005-04-16 15:20:36 -0700762
763 if (!dev)
764 goto end;
765
766 status = acpi_video_device_get_state(dev, &state);
767 seq_printf(seq, "state: ");
768 if (ACPI_SUCCESS(status))
769 seq_printf(seq, "0x%02lx\n", state);
770 else
771 seq_printf(seq, "<not supported>\n");
772
773 status = acpi_video_device_query(dev, &state);
774 seq_printf(seq, "query: ");
775 if (ACPI_SUCCESS(status))
776 seq_printf(seq, "0x%02lx\n", state);
777 else
778 seq_printf(seq, "<not supported>\n");
779
Len Brown4be44fc2005-08-05 00:44:28 -0400780 end:
Patrick Mocheld550d982006-06-27 00:41:40 -0400781 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700782}
783
784static int
Len Brown4be44fc2005-08-05 00:44:28 -0400785acpi_video_device_state_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700786{
787 return single_open(file, acpi_video_device_state_seq_show,
788 PDE(inode)->data);
789}
790
791static ssize_t
Len Brown4be44fc2005-08-05 00:44:28 -0400792acpi_video_device_write_state(struct file *file,
793 const char __user * buffer,
794 size_t count, loff_t * data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700795{
Len Brown4be44fc2005-08-05 00:44:28 -0400796 int status;
Jan Engelhardt50dd0962006-10-01 00:28:50 +0200797 struct seq_file *m = file->private_data;
798 struct acpi_video_device *dev = m->private;
Len Brown4be44fc2005-08-05 00:44:28 -0400799 char str[12] = { 0 };
800 u32 state = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700801
Linus Torvalds1da177e2005-04-16 15:20:36 -0700802
803 if (!dev || count + 1 > sizeof str)
Patrick Mocheld550d982006-06-27 00:41:40 -0400804 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700805
806 if (copy_from_user(str, buffer, count))
Patrick Mocheld550d982006-06-27 00:41:40 -0400807 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700808
809 str[count] = 0;
810 state = simple_strtoul(str, NULL, 0);
Len Brown4be44fc2005-08-05 00:44:28 -0400811 state &= ((1ul << 31) | (1ul << 30) | (1ul << 0));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700812
813 status = acpi_video_device_set_state(dev, state);
814
815 if (status)
Patrick Mocheld550d982006-06-27 00:41:40 -0400816 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700817
Patrick Mocheld550d982006-06-27 00:41:40 -0400818 return count;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700819}
820
821static int
Len Brown4be44fc2005-08-05 00:44:28 -0400822acpi_video_device_brightness_seq_show(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700823{
Jan Engelhardt50dd0962006-10-01 00:28:50 +0200824 struct acpi_video_device *dev = seq->private;
Len Brown4be44fc2005-08-05 00:44:28 -0400825 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700826
Linus Torvalds1da177e2005-04-16 15:20:36 -0700827
828 if (!dev || !dev->brightness) {
829 seq_printf(seq, "<not supported>\n");
Patrick Mocheld550d982006-06-27 00:41:40 -0400830 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700831 }
832
833 seq_printf(seq, "levels: ");
834 for (i = 0; i < dev->brightness->count; i++)
835 seq_printf(seq, " %d", dev->brightness->levels[i]);
836 seq_printf(seq, "\ncurrent: %d\n", dev->brightness->curr);
837
Patrick Mocheld550d982006-06-27 00:41:40 -0400838 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700839}
840
841static int
Len Brown4be44fc2005-08-05 00:44:28 -0400842acpi_video_device_brightness_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700843{
844 return single_open(file, acpi_video_device_brightness_seq_show,
845 PDE(inode)->data);
846}
847
848static ssize_t
Len Brown4be44fc2005-08-05 00:44:28 -0400849acpi_video_device_write_brightness(struct file *file,
850 const char __user * buffer,
851 size_t count, loff_t * data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700852{
Jan Engelhardt50dd0962006-10-01 00:28:50 +0200853 struct seq_file *m = file->private_data;
854 struct acpi_video_device *dev = m->private;
Len Brown4be44fc2005-08-05 00:44:28 -0400855 char str[4] = { 0 };
856 unsigned int level = 0;
857 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700858
Linus Torvalds1da177e2005-04-16 15:20:36 -0700859
Thomas Renninger59d399d2005-11-08 05:27:00 -0500860 if (!dev || !dev->brightness || count + 1 > sizeof str)
Patrick Mocheld550d982006-06-27 00:41:40 -0400861 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700862
863 if (copy_from_user(str, buffer, count))
Patrick Mocheld550d982006-06-27 00:41:40 -0400864 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700865
866 str[count] = 0;
867 level = simple_strtoul(str, NULL, 0);
Len Brown4be44fc2005-08-05 00:44:28 -0400868
Linus Torvalds1da177e2005-04-16 15:20:36 -0700869 if (level > 100)
Patrick Mocheld550d982006-06-27 00:41:40 -0400870 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700871
872 /* validate though the list of available levels */
873 for (i = 0; i < dev->brightness->count; i++)
874 if (level == dev->brightness->levels[i]) {
Len Brown4be44fc2005-08-05 00:44:28 -0400875 if (ACPI_SUCCESS
876 (acpi_video_device_lcd_set_level(dev, level)))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700877 dev->brightness->curr = level;
878 break;
879 }
880
Patrick Mocheld550d982006-06-27 00:41:40 -0400881 return count;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700882}
883
Len Brown4be44fc2005-08-05 00:44:28 -0400884static int acpi_video_device_EDID_seq_show(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700885{
Jan Engelhardt50dd0962006-10-01 00:28:50 +0200886 struct acpi_video_device *dev = seq->private;
Len Brown4be44fc2005-08-05 00:44:28 -0400887 int status;
888 int i;
889 union acpi_object *edid = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700890
Linus Torvalds1da177e2005-04-16 15:20:36 -0700891
892 if (!dev)
893 goto out;
894
Len Brown4be44fc2005-08-05 00:44:28 -0400895 status = acpi_video_device_EDID(dev, &edid, 128);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700896 if (ACPI_FAILURE(status)) {
Len Brown4be44fc2005-08-05 00:44:28 -0400897 status = acpi_video_device_EDID(dev, &edid, 256);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700898 }
899
900 if (ACPI_FAILURE(status)) {
901 goto out;
902 }
903
904 if (edid && edid->type == ACPI_TYPE_BUFFER) {
905 for (i = 0; i < edid->buffer.length; i++)
906 seq_putc(seq, edid->buffer.pointer[i]);
907 }
908
Len Brown4be44fc2005-08-05 00:44:28 -0400909 out:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700910 if (!edid)
911 seq_printf(seq, "<not supported>\n");
912 else
913 kfree(edid);
914
Patrick Mocheld550d982006-06-27 00:41:40 -0400915 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700916}
917
918static int
Len Brown4be44fc2005-08-05 00:44:28 -0400919acpi_video_device_EDID_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700920{
921 return single_open(file, acpi_video_device_EDID_seq_show,
922 PDE(inode)->data);
923}
924
Len Brown4be44fc2005-08-05 00:44:28 -0400925static int acpi_video_device_add_fs(struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700926{
Len Brown4be44fc2005-08-05 00:44:28 -0400927 struct proc_dir_entry *entry = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700928 struct acpi_video_device *vid_dev;
929
Linus Torvalds1da177e2005-04-16 15:20:36 -0700930
931 if (!device)
Patrick Mocheld550d982006-06-27 00:41:40 -0400932 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700933
Jan Engelhardt50dd0962006-10-01 00:28:50 +0200934 vid_dev = acpi_driver_data(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700935 if (!vid_dev)
Patrick Mocheld550d982006-06-27 00:41:40 -0400936 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700937
938 if (!acpi_device_dir(device)) {
939 acpi_device_dir(device) = proc_mkdir(acpi_device_bid(device),
Len Brown4be44fc2005-08-05 00:44:28 -0400940 vid_dev->video->dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700941 if (!acpi_device_dir(device))
Patrick Mocheld550d982006-06-27 00:41:40 -0400942 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700943 acpi_device_dir(device)->owner = THIS_MODULE;
944 }
945
946 /* 'info' [R] */
947 entry = create_proc_entry("info", S_IRUGO, acpi_device_dir(device));
948 if (!entry)
Patrick Mocheld550d982006-06-27 00:41:40 -0400949 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700950 else {
951 entry->proc_fops = &acpi_video_device_info_fops;
952 entry->data = acpi_driver_data(device);
953 entry->owner = THIS_MODULE;
954 }
955
956 /* 'state' [R/W] */
Len Brown4be44fc2005-08-05 00:44:28 -0400957 entry =
958 create_proc_entry("state", S_IFREG | S_IRUGO | S_IWUSR,
959 acpi_device_dir(device));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700960 if (!entry)
Patrick Mocheld550d982006-06-27 00:41:40 -0400961 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700962 else {
Arjan van de Vend479e902006-01-06 16:47:00 -0500963 acpi_video_device_state_fops.write = acpi_video_device_write_state;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700964 entry->proc_fops = &acpi_video_device_state_fops;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700965 entry->data = acpi_driver_data(device);
966 entry->owner = THIS_MODULE;
967 }
968
969 /* 'brightness' [R/W] */
Len Brown4be44fc2005-08-05 00:44:28 -0400970 entry =
971 create_proc_entry("brightness", S_IFREG | S_IRUGO | S_IWUSR,
972 acpi_device_dir(device));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700973 if (!entry)
Patrick Mocheld550d982006-06-27 00:41:40 -0400974 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700975 else {
Arjan van de Vend479e902006-01-06 16:47:00 -0500976 acpi_video_device_brightness_fops.write = acpi_video_device_write_brightness;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700977 entry->proc_fops = &acpi_video_device_brightness_fops;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700978 entry->data = acpi_driver_data(device);
979 entry->owner = THIS_MODULE;
980 }
981
982 /* 'EDID' [R] */
983 entry = create_proc_entry("EDID", S_IRUGO, acpi_device_dir(device));
984 if (!entry)
Patrick Mocheld550d982006-06-27 00:41:40 -0400985 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700986 else {
987 entry->proc_fops = &acpi_video_device_EDID_fops;
988 entry->data = acpi_driver_data(device);
989 entry->owner = THIS_MODULE;
990 }
991
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_device_remove_fs(struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700996{
997 struct acpi_video_device *vid_dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700998
Jan Engelhardt50dd0962006-10-01 00:28:50 +0200999 vid_dev = acpi_driver_data(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001000 if (!vid_dev || !vid_dev->video || !vid_dev->video->dir)
Patrick Mocheld550d982006-06-27 00:41:40 -04001001 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001002
1003 if (acpi_device_dir(device)) {
1004 remove_proc_entry("info", acpi_device_dir(device));
1005 remove_proc_entry("state", acpi_device_dir(device));
1006 remove_proc_entry("brightness", acpi_device_dir(device));
1007 remove_proc_entry("EDID", acpi_device_dir(device));
Len Brown4be44fc2005-08-05 00:44:28 -04001008 remove_proc_entry(acpi_device_bid(device), vid_dev->video->dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001009 acpi_device_dir(device) = NULL;
1010 }
1011
Patrick Mocheld550d982006-06-27 00:41:40 -04001012 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001013}
1014
Linus Torvalds1da177e2005-04-16 15:20:36 -07001015/* video bus */
Len Brown4be44fc2005-08-05 00:44:28 -04001016static int acpi_video_bus_info_seq_show(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001017{
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001018 struct acpi_video_bus *video = seq->private;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001019
Linus Torvalds1da177e2005-04-16 15:20:36 -07001020
1021 if (!video)
1022 goto end;
1023
1024 seq_printf(seq, "Switching heads: %s\n",
Len Brown4be44fc2005-08-05 00:44:28 -04001025 video->flags.multihead ? "yes" : "no");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001026 seq_printf(seq, "Video ROM: %s\n",
Len Brown4be44fc2005-08-05 00:44:28 -04001027 video->flags.rom ? "yes" : "no");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001028 seq_printf(seq, "Device to be POSTed on boot: %s\n",
Len Brown4be44fc2005-08-05 00:44:28 -04001029 video->flags.post ? "yes" : "no");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001030
Len Brown4be44fc2005-08-05 00:44:28 -04001031 end:
Patrick Mocheld550d982006-06-27 00:41:40 -04001032 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001033}
1034
Len Brown4be44fc2005-08-05 00:44:28 -04001035static int acpi_video_bus_info_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001036{
Len Brown4be44fc2005-08-05 00:44:28 -04001037 return single_open(file, acpi_video_bus_info_seq_show,
1038 PDE(inode)->data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001039}
1040
Len Brown4be44fc2005-08-05 00:44:28 -04001041static int acpi_video_bus_ROM_seq_show(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001042{
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001043 struct acpi_video_bus *video = seq->private;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001044
Linus Torvalds1da177e2005-04-16 15:20:36 -07001045
1046 if (!video)
1047 goto end;
1048
1049 printk(KERN_INFO PREFIX "Please implement %s\n", __FUNCTION__);
1050 seq_printf(seq, "<TODO>\n");
1051
Len Brown4be44fc2005-08-05 00:44:28 -04001052 end:
Patrick Mocheld550d982006-06-27 00:41:40 -04001053 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001054}
1055
Len Brown4be44fc2005-08-05 00:44:28 -04001056static int acpi_video_bus_ROM_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001057{
1058 return single_open(file, acpi_video_bus_ROM_seq_show, PDE(inode)->data);
1059}
1060
Len Brown4be44fc2005-08-05 00:44:28 -04001061static int acpi_video_bus_POST_info_seq_show(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001062{
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001063 struct acpi_video_bus *video = seq->private;
Len Brown4be44fc2005-08-05 00:44:28 -04001064 unsigned long options;
1065 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001066
Linus Torvalds1da177e2005-04-16 15:20:36 -07001067
1068 if (!video)
1069 goto end;
1070
1071 status = acpi_video_bus_POST_options(video, &options);
1072 if (ACPI_SUCCESS(status)) {
1073 if (!(options & 1)) {
Len Brown4be44fc2005-08-05 00:44:28 -04001074 printk(KERN_WARNING PREFIX
1075 "The motherboard VGA device is not listed as a possible POST device.\n");
1076 printk(KERN_WARNING PREFIX
1077 "This indicate a BIOS bug. Please contact the manufacturer.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001078 }
1079 printk("%lx\n", options);
1080 seq_printf(seq, "can POST: <intgrated video>");
1081 if (options & 2)
1082 seq_printf(seq, " <PCI video>");
1083 if (options & 4)
1084 seq_printf(seq, " <AGP video>");
1085 seq_putc(seq, '\n');
1086 } else
1087 seq_printf(seq, "<not supported>\n");
Len Brown4be44fc2005-08-05 00:44:28 -04001088 end:
Patrick Mocheld550d982006-06-27 00:41:40 -04001089 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001090}
1091
1092static int
Len Brown4be44fc2005-08-05 00:44:28 -04001093acpi_video_bus_POST_info_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001094{
Len Brown4be44fc2005-08-05 00:44:28 -04001095 return single_open(file, acpi_video_bus_POST_info_seq_show,
1096 PDE(inode)->data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001097}
1098
Len Brown4be44fc2005-08-05 00:44:28 -04001099static int acpi_video_bus_POST_seq_show(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001100{
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001101 struct acpi_video_bus *video = seq->private;
Len Brown4be44fc2005-08-05 00:44:28 -04001102 int status;
1103 unsigned long id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001104
Linus Torvalds1da177e2005-04-16 15:20:36 -07001105
1106 if (!video)
1107 goto end;
1108
Len Brown4be44fc2005-08-05 00:44:28 -04001109 status = acpi_video_bus_get_POST(video, &id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001110 if (!ACPI_SUCCESS(status)) {
1111 seq_printf(seq, "<not supported>\n");
1112 goto end;
1113 }
Len Brown4be44fc2005-08-05 00:44:28 -04001114 seq_printf(seq, "device posted is <%s>\n", device_decode[id & 3]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001115
Len Brown4be44fc2005-08-05 00:44:28 -04001116 end:
Patrick Mocheld550d982006-06-27 00:41:40 -04001117 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001118}
1119
Len Brown4be44fc2005-08-05 00:44:28 -04001120static int acpi_video_bus_DOS_seq_show(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001121{
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001122 struct acpi_video_bus *video = seq->private;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001123
Linus Torvalds1da177e2005-04-16 15:20:36 -07001124
Len Brown4be44fc2005-08-05 00:44:28 -04001125 seq_printf(seq, "DOS setting: <%d>\n", video->dos_setting);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001126
Patrick Mocheld550d982006-06-27 00:41:40 -04001127 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001128}
1129
Len Brown4be44fc2005-08-05 00:44:28 -04001130static int acpi_video_bus_POST_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001131{
Len Brown4be44fc2005-08-05 00:44:28 -04001132 return single_open(file, acpi_video_bus_POST_seq_show,
1133 PDE(inode)->data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001134}
1135
Len Brown4be44fc2005-08-05 00:44:28 -04001136static int acpi_video_bus_DOS_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001137{
1138 return single_open(file, acpi_video_bus_DOS_seq_show, PDE(inode)->data);
1139}
1140
1141static ssize_t
Len Brown4be44fc2005-08-05 00:44:28 -04001142acpi_video_bus_write_POST(struct file *file,
1143 const char __user * buffer,
1144 size_t count, loff_t * data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001145{
Len Brown4be44fc2005-08-05 00:44:28 -04001146 int status;
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001147 struct seq_file *m = file->private_data;
1148 struct acpi_video_bus *video = m->private;
Len Brown4be44fc2005-08-05 00:44:28 -04001149 char str[12] = { 0 };
1150 unsigned long opt, options;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001151
Linus Torvalds1da177e2005-04-16 15:20:36 -07001152
Linus Torvalds1da177e2005-04-16 15:20:36 -07001153 if (!video || count + 1 > sizeof str)
Patrick Mocheld550d982006-06-27 00:41:40 -04001154 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001155
1156 status = acpi_video_bus_POST_options(video, &options);
1157 if (!ACPI_SUCCESS(status))
Patrick Mocheld550d982006-06-27 00:41:40 -04001158 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001159
1160 if (copy_from_user(str, buffer, count))
Patrick Mocheld550d982006-06-27 00:41:40 -04001161 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001162
1163 str[count] = 0;
1164 opt = strtoul(str, NULL, 0);
1165 if (opt > 3)
Patrick Mocheld550d982006-06-27 00:41:40 -04001166 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001167
1168 /* just in case an OEM 'forget' the motherboard... */
1169 options |= 1;
1170
1171 if (options & (1ul << opt)) {
Len Brown4be44fc2005-08-05 00:44:28 -04001172 status = acpi_video_bus_set_POST(video, opt);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001173 if (!ACPI_SUCCESS(status))
Patrick Mocheld550d982006-06-27 00:41:40 -04001174 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001175
1176 }
1177
Patrick Mocheld550d982006-06-27 00:41:40 -04001178 return count;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001179}
1180
1181static ssize_t
Len Brown4be44fc2005-08-05 00:44:28 -04001182acpi_video_bus_write_DOS(struct file *file,
1183 const char __user * buffer,
1184 size_t count, loff_t * data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001185{
Len Brown4be44fc2005-08-05 00:44:28 -04001186 int status;
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001187 struct seq_file *m = file->private_data;
1188 struct acpi_video_bus *video = m->private;
Len Brown4be44fc2005-08-05 00:44:28 -04001189 char str[12] = { 0 };
1190 unsigned long opt;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001191
Linus Torvalds1da177e2005-04-16 15:20:36 -07001192
Linus Torvalds1da177e2005-04-16 15:20:36 -07001193 if (!video || count + 1 > sizeof str)
Patrick Mocheld550d982006-06-27 00:41:40 -04001194 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001195
1196 if (copy_from_user(str, buffer, count))
Patrick Mocheld550d982006-06-27 00:41:40 -04001197 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001198
1199 str[count] = 0;
1200 opt = strtoul(str, NULL, 0);
1201 if (opt > 7)
Patrick Mocheld550d982006-06-27 00:41:40 -04001202 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001203
Len Brown4be44fc2005-08-05 00:44:28 -04001204 status = acpi_video_bus_DOS(video, opt & 0x3, (opt & 0x4) >> 2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001205
1206 if (!ACPI_SUCCESS(status))
Patrick Mocheld550d982006-06-27 00:41:40 -04001207 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001208
Patrick Mocheld550d982006-06-27 00:41:40 -04001209 return count;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001210}
1211
Len Brown4be44fc2005-08-05 00:44:28 -04001212static int acpi_video_bus_add_fs(struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001213{
Len Brown4be44fc2005-08-05 00:44:28 -04001214 struct proc_dir_entry *entry = NULL;
1215 struct acpi_video_bus *video;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001216
Linus Torvalds1da177e2005-04-16 15:20:36 -07001217
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001218 video = acpi_driver_data(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001219
1220 if (!acpi_device_dir(device)) {
1221 acpi_device_dir(device) = proc_mkdir(acpi_device_bid(device),
Len Brown4be44fc2005-08-05 00:44:28 -04001222 acpi_video_dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001223 if (!acpi_device_dir(device))
Patrick Mocheld550d982006-06-27 00:41:40 -04001224 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001225 video->dir = acpi_device_dir(device);
1226 acpi_device_dir(device)->owner = THIS_MODULE;
1227 }
1228
1229 /* 'info' [R] */
1230 entry = create_proc_entry("info", S_IRUGO, acpi_device_dir(device));
1231 if (!entry)
Patrick Mocheld550d982006-06-27 00:41:40 -04001232 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001233 else {
1234 entry->proc_fops = &acpi_video_bus_info_fops;
1235 entry->data = acpi_driver_data(device);
1236 entry->owner = THIS_MODULE;
1237 }
1238
1239 /* 'ROM' [R] */
1240 entry = create_proc_entry("ROM", S_IRUGO, acpi_device_dir(device));
1241 if (!entry)
Patrick Mocheld550d982006-06-27 00:41:40 -04001242 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001243 else {
1244 entry->proc_fops = &acpi_video_bus_ROM_fops;
1245 entry->data = acpi_driver_data(device);
1246 entry->owner = THIS_MODULE;
1247 }
1248
1249 /* 'POST_info' [R] */
Len Brown4be44fc2005-08-05 00:44:28 -04001250 entry =
1251 create_proc_entry("POST_info", S_IRUGO, acpi_device_dir(device));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001252 if (!entry)
Patrick Mocheld550d982006-06-27 00:41:40 -04001253 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001254 else {
1255 entry->proc_fops = &acpi_video_bus_POST_info_fops;
1256 entry->data = acpi_driver_data(device);
1257 entry->owner = THIS_MODULE;
1258 }
1259
1260 /* 'POST' [R/W] */
Len Brown4be44fc2005-08-05 00:44:28 -04001261 entry =
1262 create_proc_entry("POST", S_IFREG | S_IRUGO | S_IRUSR,
1263 acpi_device_dir(device));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001264 if (!entry)
Patrick Mocheld550d982006-06-27 00:41:40 -04001265 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001266 else {
Arjan van de Vend479e902006-01-06 16:47:00 -05001267 acpi_video_bus_POST_fops.write = acpi_video_bus_write_POST;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001268 entry->proc_fops = &acpi_video_bus_POST_fops;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001269 entry->data = acpi_driver_data(device);
1270 entry->owner = THIS_MODULE;
1271 }
1272
1273 /* 'DOS' [R/W] */
Len Brown4be44fc2005-08-05 00:44:28 -04001274 entry =
1275 create_proc_entry("DOS", S_IFREG | S_IRUGO | S_IRUSR,
1276 acpi_device_dir(device));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001277 if (!entry)
Patrick Mocheld550d982006-06-27 00:41:40 -04001278 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001279 else {
Arjan van de Vend479e902006-01-06 16:47:00 -05001280 acpi_video_bus_DOS_fops.write = acpi_video_bus_write_DOS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001281 entry->proc_fops = &acpi_video_bus_DOS_fops;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001282 entry->data = acpi_driver_data(device);
1283 entry->owner = THIS_MODULE;
1284 }
1285
Patrick Mocheld550d982006-06-27 00:41:40 -04001286 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001287}
1288
Len Brown4be44fc2005-08-05 00:44:28 -04001289static int acpi_video_bus_remove_fs(struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001290{
Len Brown4be44fc2005-08-05 00:44:28 -04001291 struct acpi_video_bus *video;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001292
Linus Torvalds1da177e2005-04-16 15:20:36 -07001293
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001294 video = acpi_driver_data(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001295
1296 if (acpi_device_dir(device)) {
1297 remove_proc_entry("info", acpi_device_dir(device));
1298 remove_proc_entry("ROM", acpi_device_dir(device));
1299 remove_proc_entry("POST_info", acpi_device_dir(device));
1300 remove_proc_entry("POST", acpi_device_dir(device));
1301 remove_proc_entry("DOS", acpi_device_dir(device));
Len Brown4be44fc2005-08-05 00:44:28 -04001302 remove_proc_entry(acpi_device_bid(device), acpi_video_dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001303 acpi_device_dir(device) = NULL;
1304 }
1305
Patrick Mocheld550d982006-06-27 00:41:40 -04001306 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001307}
1308
1309/* --------------------------------------------------------------------------
1310 Driver Interface
1311 -------------------------------------------------------------------------- */
1312
1313/* device interface */
Rui Zhang82cae992007-01-03 23:40:53 -05001314static struct acpi_video_device_attrib*
1315acpi_video_get_device_attr(struct acpi_video_bus *video, unsigned long device_id)
1316{
1317 int count;
1318
1319 for(count = 0; count < video->attached_count; count++)
1320 if((video->attached_array[count].value.int_val & 0xffff) == device_id)
1321 return &(video->attached_array[count].value.attrib);
1322 return NULL;
1323}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001324
1325static int
Len Brown4be44fc2005-08-05 00:44:28 -04001326acpi_video_bus_get_one_device(struct acpi_device *device,
1327 struct acpi_video_bus *video)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001328{
Len Brown4be44fc2005-08-05 00:44:28 -04001329 unsigned long device_id;
Yu, Luming973bf492006-04-27 05:25:00 -04001330 int status;
Len Brown4be44fc2005-08-05 00:44:28 -04001331 struct acpi_video_device *data;
Rui Zhang82cae992007-01-03 23:40:53 -05001332 struct acpi_video_device_attrib* attribute;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001333
1334 if (!device || !video)
Patrick Mocheld550d982006-06-27 00:41:40 -04001335 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001336
Len Brown4be44fc2005-08-05 00:44:28 -04001337 status =
1338 acpi_evaluate_integer(device->handle, "_ADR", NULL, &device_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001339 if (ACPI_SUCCESS(status)) {
1340
Burman Yan36bcbec2006-12-19 12:56:11 -08001341 data = kzalloc(sizeof(struct acpi_video_device), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001342 if (!data)
Patrick Mocheld550d982006-06-27 00:41:40 -04001343 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001344
Linus Torvalds1da177e2005-04-16 15:20:36 -07001345 strcpy(acpi_device_name(device), ACPI_VIDEO_DEVICE_NAME);
1346 strcpy(acpi_device_class(device), ACPI_VIDEO_CLASS);
1347 acpi_driver_data(device) = data;
1348
1349 data->device_id = device_id;
1350 data->video = video;
1351 data->dev = device;
1352
Rui Zhang82cae992007-01-03 23:40:53 -05001353 attribute = acpi_video_get_device_attr(video, device_id);
1354
1355 if((attribute != NULL) && attribute->device_id_scheme) {
1356 switch (attribute->display_type) {
1357 case ACPI_VIDEO_DISPLAY_CRT:
1358 data->flags.crt = 1;
1359 break;
1360 case ACPI_VIDEO_DISPLAY_TV:
1361 data->flags.tvout = 1;
1362 break;
1363 case ACPI_VIDEO_DISPLAY_DVI:
1364 data->flags.dvi = 1;
1365 break;
1366 case ACPI_VIDEO_DISPLAY_LCD:
1367 data->flags.lcd = 1;
1368 break;
1369 default:
1370 data->flags.unknown = 1;
1371 break;
1372 }
1373 if(attribute->bios_can_detect)
1374 data->flags.bios = 1;
1375 } else
Linus Torvalds1da177e2005-04-16 15:20:36 -07001376 data->flags.unknown = 1;
Len Brown4be44fc2005-08-05 00:44:28 -04001377
Linus Torvalds1da177e2005-04-16 15:20:36 -07001378 acpi_video_device_bind(video, data);
1379 acpi_video_device_find_cap(data);
1380
Patrick Mochel90130262006-05-19 16:54:48 -04001381 status = acpi_install_notify_handler(device->handle,
Len Brown4be44fc2005-08-05 00:44:28 -04001382 ACPI_DEVICE_NOTIFY,
1383 acpi_video_device_notify,
1384 data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001385 if (ACPI_FAILURE(status)) {
1386 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
Len Brown4be44fc2005-08-05 00:44:28 -04001387 "Error installing notify handler\n"));
Yu, Luming973bf492006-04-27 05:25:00 -04001388 if(data->brightness)
1389 kfree(data->brightness->levels);
1390 kfree(data->brightness);
1391 kfree(data);
1392 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001393 }
1394
1395 down(&video->sem);
1396 list_add_tail(&data->entry, &video->video_device_list);
1397 up(&video->sem);
1398
1399 acpi_video_device_add_fs(device);
1400
Patrick Mocheld550d982006-06-27 00:41:40 -04001401 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001402 }
1403
Patrick Mocheld550d982006-06-27 00:41:40 -04001404 return -ENOENT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001405}
1406
1407/*
1408 * Arg:
1409 * video : video bus device
1410 *
1411 * Return:
1412 * none
1413 *
1414 * Enumerate the video device list of the video bus,
1415 * bind the ids with the corresponding video devices
1416 * under the video bus.
Len Brown4be44fc2005-08-05 00:44:28 -04001417 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001418
Len Brown4be44fc2005-08-05 00:44:28 -04001419static void acpi_video_device_rebind(struct acpi_video_bus *video)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001420{
Len Brown4be44fc2005-08-05 00:44:28 -04001421 struct list_head *node, *next;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001422 list_for_each_safe(node, next, &video->video_device_list) {
Len Brown4be44fc2005-08-05 00:44:28 -04001423 struct acpi_video_device *dev =
1424 container_of(node, struct acpi_video_device, entry);
1425 acpi_video_device_bind(video, dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001426 }
1427}
1428
1429/*
1430 * Arg:
1431 * video : video bus device
1432 * device : video output device under the video
1433 * bus
1434 *
1435 * Return:
1436 * none
1437 *
1438 * Bind the ids with the corresponding video devices
1439 * under the video bus.
Len Brown4be44fc2005-08-05 00:44:28 -04001440 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001441
1442static void
Len Brown4be44fc2005-08-05 00:44:28 -04001443acpi_video_device_bind(struct acpi_video_bus *video,
1444 struct acpi_video_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001445{
Len Brown4be44fc2005-08-05 00:44:28 -04001446 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001447
1448#define IDS_VAL(i) video->attached_array[i].value.int_val
1449#define IDS_BIND(i) video->attached_array[i].bind_info
Len Brown4be44fc2005-08-05 00:44:28 -04001450
1451 for (i = 0; IDS_VAL(i) != ACPI_VIDEO_HEAD_INVALID &&
1452 i < video->attached_count; i++) {
1453 if (device->device_id == (IDS_VAL(i) & 0xffff)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001454 IDS_BIND(i) = device;
1455 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "device_bind %d\n", i));
1456 }
1457 }
1458#undef IDS_VAL
1459#undef IDS_BIND
1460}
1461
1462/*
1463 * Arg:
1464 * video : video bus device
1465 *
1466 * Return:
1467 * < 0 : error
1468 *
1469 * Call _DOD to enumerate all devices attached to display adapter
1470 *
Len Brown4be44fc2005-08-05 00:44:28 -04001471 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001472
1473static int acpi_video_device_enumerate(struct acpi_video_bus *video)
1474{
Len Brown4be44fc2005-08-05 00:44:28 -04001475 int status;
1476 int count;
1477 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001478 struct acpi_video_enumerated_device *active_device_list;
Len Brown4be44fc2005-08-05 00:44:28 -04001479 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
1480 union acpi_object *dod = NULL;
1481 union acpi_object *obj;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001482
Patrick Mochel90130262006-05-19 16:54:48 -04001483 status = acpi_evaluate_object(video->device->handle, "_DOD", NULL, &buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001484 if (!ACPI_SUCCESS(status)) {
Thomas Renningera6fc6722006-06-26 23:58:43 -04001485 ACPI_EXCEPTION((AE_INFO, status, "Evaluating _DOD"));
Patrick Mocheld550d982006-06-27 00:41:40 -04001486 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001487 }
1488
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001489 dod = buffer.pointer;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001490 if (!dod || (dod->type != ACPI_TYPE_PACKAGE)) {
Thomas Renningera6fc6722006-06-26 23:58:43 -04001491 ACPI_EXCEPTION((AE_INFO, status, "Invalid _DOD data"));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001492 status = -EFAULT;
1493 goto out;
1494 }
1495
1496 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found %d video heads in _DOD\n",
Len Brown4be44fc2005-08-05 00:44:28 -04001497 dod->package.count));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001498
Len Brown4be44fc2005-08-05 00:44:28 -04001499 active_device_list = kmalloc((1 +
1500 dod->package.count) *
1501 sizeof(struct
1502 acpi_video_enumerated_device),
1503 GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001504
1505 if (!active_device_list) {
1506 status = -ENOMEM;
1507 goto out;
1508 }
1509
1510 count = 0;
1511 for (i = 0; i < dod->package.count; i++) {
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001512 obj = &dod->package.elements[i];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001513
1514 if (obj->type != ACPI_TYPE_INTEGER) {
Len Brown64684632006-06-26 23:41:38 -04001515 printk(KERN_ERR PREFIX "Invalid _DOD data\n");
Len Brown4be44fc2005-08-05 00:44:28 -04001516 active_device_list[i].value.int_val =
1517 ACPI_VIDEO_HEAD_INVALID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001518 }
1519 active_device_list[i].value.int_val = obj->integer.value;
1520 active_device_list[i].bind_info = NULL;
Len Brown4be44fc2005-08-05 00:44:28 -04001521 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "dod element[%d] = %d\n", i,
1522 (int)obj->integer.value));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001523 count++;
1524 }
1525 active_device_list[count].value.int_val = ACPI_VIDEO_HEAD_END;
1526
Jesper Juhl6044ec82005-11-07 01:01:32 -08001527 kfree(video->attached_array);
Len Brown4be44fc2005-08-05 00:44:28 -04001528
Linus Torvalds1da177e2005-04-16 15:20:36 -07001529 video->attached_array = active_device_list;
1530 video->attached_count = count;
Len Brown4be44fc2005-08-05 00:44:28 -04001531 out:
Len Brown02438d82006-06-30 03:19:10 -04001532 kfree(buffer.pointer);
Patrick Mocheld550d982006-06-27 00:41:40 -04001533 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001534}
1535
1536/*
1537 * Arg:
1538 * video : video bus device
1539 * event : Nontify Event
1540 *
1541 * Return:
1542 * < 0 : error
1543 *
1544 * 1. Find out the current active output device.
1545 * 2. Identify the next output device to switch
1546 * 3. call _DSS to do actual switch.
Len Brown4be44fc2005-08-05 00:44:28 -04001547 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001548
Len Brown4be44fc2005-08-05 00:44:28 -04001549static int acpi_video_switch_output(struct acpi_video_bus *video, int event)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001550{
Len Brown4be44fc2005-08-05 00:44:28 -04001551 struct list_head *node, *next;
1552 struct acpi_video_device *dev = NULL;
1553 struct acpi_video_device *dev_next = NULL;
1554 struct acpi_video_device *dev_prev = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001555 unsigned long state;
1556 int status = 0;
1557
Linus Torvalds1da177e2005-04-16 15:20:36 -07001558
1559 list_for_each_safe(node, next, &video->video_device_list) {
Adrian Bunk73345712005-03-30 22:31:35 -05001560 dev = container_of(node, struct acpi_video_device, entry);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001561 status = acpi_video_device_get_state(dev, &state);
Len Brown4be44fc2005-08-05 00:44:28 -04001562 if (state & 0x2) {
1563 dev_next =
1564 container_of(node->next, struct acpi_video_device,
1565 entry);
1566 dev_prev =
1567 container_of(node->prev, struct acpi_video_device,
1568 entry);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001569 goto out;
1570 }
1571 }
1572 dev_next = container_of(node->next, struct acpi_video_device, entry);
1573 dev_prev = container_of(node->prev, struct acpi_video_device, entry);
Len Brown4be44fc2005-08-05 00:44:28 -04001574 out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001575 switch (event) {
1576 case ACPI_VIDEO_NOTIFY_CYCLE:
1577 case ACPI_VIDEO_NOTIFY_NEXT_OUTPUT:
1578 acpi_video_device_set_state(dev, 0);
1579 acpi_video_device_set_state(dev_next, 0x80000001);
1580 break;
1581 case ACPI_VIDEO_NOTIFY_PREV_OUTPUT:
1582 acpi_video_device_set_state(dev, 0);
1583 acpi_video_device_set_state(dev_prev, 0x80000001);
1584 default:
1585 break;
1586 }
1587
Patrick Mocheld550d982006-06-27 00:41:40 -04001588 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001589}
1590
Len Brown4be44fc2005-08-05 00:44:28 -04001591static int
1592acpi_video_get_next_level(struct acpi_video_device *device,
1593 u32 level_current, u32 event)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001594{
Thomas Tuttlef4715182006-12-19 12:56:14 -08001595 int min, max, min_above, max_below, i, l;
1596 max = max_below = 0;
1597 min = min_above = 255;
1598 for (i = 0; i < device->brightness->count; i++) {
1599 l = device->brightness->levels[i];
1600 if (l < min)
1601 min = l;
1602 if (l > max)
1603 max = l;
1604 if (l < min_above && l > level_current)
1605 min_above = l;
1606 if (l > max_below && l < level_current)
1607 max_below = l;
1608 }
1609
1610 switch (event) {
1611 case ACPI_VIDEO_NOTIFY_CYCLE_BRIGHTNESS:
1612 return (level_current < max) ? min_above : min;
1613 case ACPI_VIDEO_NOTIFY_INC_BRIGHTNESS:
1614 return (level_current < max) ? min_above : max;
1615 case ACPI_VIDEO_NOTIFY_DEC_BRIGHTNESS:
1616 return (level_current > min) ? max_below : min;
1617 case ACPI_VIDEO_NOTIFY_ZERO_BRIGHTNESS:
1618 case ACPI_VIDEO_NOTIFY_DISPLAY_OFF:
1619 return 0;
1620 default:
1621 return level_current;
1622 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001623}
1624
Linus Torvalds1da177e2005-04-16 15:20:36 -07001625static void
Len Brown4be44fc2005-08-05 00:44:28 -04001626acpi_video_switch_brightness(struct acpi_video_device *device, int event)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001627{
1628 unsigned long level_current, level_next;
1629 acpi_video_device_lcd_get_level_current(device, &level_current);
1630 level_next = acpi_video_get_next_level(device, level_current, event);
1631 acpi_video_device_lcd_set_level(device, level_next);
1632}
1633
1634static int
Len Brown4be44fc2005-08-05 00:44:28 -04001635acpi_video_bus_get_devices(struct acpi_video_bus *video,
1636 struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001637{
Len Brown4be44fc2005-08-05 00:44:28 -04001638 int status = 0;
1639 struct list_head *node, *next;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001640
Linus Torvalds1da177e2005-04-16 15:20:36 -07001641
1642 acpi_video_device_enumerate(video);
1643
1644 list_for_each_safe(node, next, &device->children) {
Len Brown4be44fc2005-08-05 00:44:28 -04001645 struct acpi_device *dev =
1646 list_entry(node, struct acpi_device, node);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001647
1648 if (!dev)
1649 continue;
1650
1651 status = acpi_video_bus_get_one_device(dev, video);
1652 if (ACPI_FAILURE(status)) {
Thomas Renningera6fc6722006-06-26 23:58:43 -04001653 ACPI_EXCEPTION((AE_INFO, status, "Cant attach device"));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001654 continue;
1655 }
1656
1657 }
Patrick Mocheld550d982006-06-27 00:41:40 -04001658 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001659}
1660
Len Brown4be44fc2005-08-05 00:44:28 -04001661static int acpi_video_bus_put_one_device(struct acpi_video_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001662{
Karol Kozimor031ec772005-07-30 04:18:00 -04001663 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001664 struct acpi_video_bus *video;
1665
Linus Torvalds1da177e2005-04-16 15:20:36 -07001666
1667 if (!device || !device->video)
Patrick Mocheld550d982006-06-27 00:41:40 -04001668 return -ENOENT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001669
1670 video = device->video;
1671
1672 down(&video->sem);
1673 list_del(&device->entry);
1674 up(&video->sem);
1675 acpi_video_device_remove_fs(device->dev);
1676
Patrick Mochel90130262006-05-19 16:54:48 -04001677 status = acpi_remove_notify_handler(device->dev->handle,
Len Brown4be44fc2005-08-05 00:44:28 -04001678 ACPI_DEVICE_NOTIFY,
1679 acpi_video_device_notify);
Yu Luming2f3d0002006-11-11 02:40:34 +08001680 if (device->backlight){
1681 backlight_device_unregister(device->backlight);
1682 kfree(device->data);
1683 }
Patrick Mocheld550d982006-06-27 00:41:40 -04001684 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001685}
1686
Len Brown4be44fc2005-08-05 00:44:28 -04001687static int acpi_video_bus_put_devices(struct acpi_video_bus *video)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001688{
Len Brown4be44fc2005-08-05 00:44:28 -04001689 int status;
1690 struct list_head *node, *next;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001691
Linus Torvalds1da177e2005-04-16 15:20:36 -07001692
1693 list_for_each_safe(node, next, &video->video_device_list) {
Len Brown4be44fc2005-08-05 00:44:28 -04001694 struct acpi_video_device *data =
1695 list_entry(node, struct acpi_video_device, entry);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001696 if (!data)
1697 continue;
1698
1699 status = acpi_video_bus_put_one_device(data);
Len Brown4be44fc2005-08-05 00:44:28 -04001700 if (ACPI_FAILURE(status))
1701 printk(KERN_WARNING PREFIX
1702 "hhuuhhuu bug in acpi video driver.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001703
Dave Jonesd384ea62006-06-24 00:33:08 -04001704 if (data->brightness)
Yu, Luming973bf492006-04-27 05:25:00 -04001705 kfree(data->brightness->levels);
Jesper Juhl6044ec82005-11-07 01:01:32 -08001706 kfree(data->brightness);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001707 kfree(data);
1708 }
1709
Patrick Mocheld550d982006-06-27 00:41:40 -04001710 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001711}
1712
1713/* acpi_video interface */
1714
Len Brown4be44fc2005-08-05 00:44:28 -04001715static int acpi_video_bus_start_devices(struct acpi_video_bus *video)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001716{
1717 return acpi_video_bus_DOS(video, 1, 0);
1718}
1719
Len Brown4be44fc2005-08-05 00:44:28 -04001720static int acpi_video_bus_stop_devices(struct acpi_video_bus *video)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001721{
1722 return acpi_video_bus_DOS(video, 0, 1);
1723}
1724
Len Brown4be44fc2005-08-05 00:44:28 -04001725static void acpi_video_bus_notify(acpi_handle handle, u32 event, void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001726{
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001727 struct acpi_video_bus *video = data;
Len Brown4be44fc2005-08-05 00:44:28 -04001728 struct acpi_device *device = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001729
Linus Torvalds1da177e2005-04-16 15:20:36 -07001730 printk("video bus notify\n");
1731
1732 if (!video)
Patrick Mocheld550d982006-06-27 00:41:40 -04001733 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001734
Patrick Mochele6afa0d2006-05-19 16:54:40 -04001735 device = video->device;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001736
1737 switch (event) {
1738 case ACPI_VIDEO_NOTIFY_SWITCH: /* User request that a switch occur,
1739 * most likely via hotkey. */
1740 acpi_bus_generate_event(device, event, 0);
1741 break;
1742
1743 case ACPI_VIDEO_NOTIFY_PROBE: /* User plug or remove a video
1744 * connector. */
1745 acpi_video_device_enumerate(video);
1746 acpi_video_device_rebind(video);
1747 acpi_video_switch_output(video, event);
1748 acpi_bus_generate_event(device, event, 0);
1749 break;
1750
Len Brown4be44fc2005-08-05 00:44:28 -04001751 case ACPI_VIDEO_NOTIFY_CYCLE: /* Cycle Display output hotkey pressed. */
1752 case ACPI_VIDEO_NOTIFY_NEXT_OUTPUT: /* Next Display output hotkey pressed. */
1753 case ACPI_VIDEO_NOTIFY_PREV_OUTPUT: /* previous Display output hotkey pressed. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001754 acpi_video_switch_output(video, event);
1755 acpi_bus_generate_event(device, event, 0);
1756 break;
1757
1758 default:
1759 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
Len Brown4be44fc2005-08-05 00:44:28 -04001760 "Unsupported event [0x%x]\n", event));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001761 break;
1762 }
1763
Patrick Mocheld550d982006-06-27 00:41:40 -04001764 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001765}
1766
Len Brown4be44fc2005-08-05 00:44:28 -04001767static void acpi_video_device_notify(acpi_handle handle, u32 event, void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001768{
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001769 struct acpi_video_device *video_device = data;
Len Brown4be44fc2005-08-05 00:44:28 -04001770 struct acpi_device *device = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001771
Linus Torvalds1da177e2005-04-16 15:20:36 -07001772 if (!video_device)
Patrick Mocheld550d982006-06-27 00:41:40 -04001773 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001774
Patrick Mochele6afa0d2006-05-19 16:54:40 -04001775 device = video_device->dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001776
1777 switch (event) {
Len Brown4be44fc2005-08-05 00:44:28 -04001778 case ACPI_VIDEO_NOTIFY_SWITCH: /* change in status (cycle output device) */
1779 case ACPI_VIDEO_NOTIFY_PROBE: /* change in status (output device status) */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001780 acpi_bus_generate_event(device, event, 0);
1781 break;
Len Brown4be44fc2005-08-05 00:44:28 -04001782 case ACPI_VIDEO_NOTIFY_CYCLE_BRIGHTNESS: /* Cycle brightness */
1783 case ACPI_VIDEO_NOTIFY_INC_BRIGHTNESS: /* Increase brightness */
1784 case ACPI_VIDEO_NOTIFY_DEC_BRIGHTNESS: /* Decrease brightness */
1785 case ACPI_VIDEO_NOTIFY_ZERO_BRIGHTNESS: /* zero brightnesss */
1786 case ACPI_VIDEO_NOTIFY_DISPLAY_OFF: /* display device off */
1787 acpi_video_switch_brightness(video_device, event);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001788 acpi_bus_generate_event(device, event, 0);
1789 break;
1790 default:
1791 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
Len Brown4be44fc2005-08-05 00:44:28 -04001792 "Unsupported event [0x%x]\n", event));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001793 break;
1794 }
Patrick Mocheld550d982006-06-27 00:41:40 -04001795 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001796}
1797
Len Brown4be44fc2005-08-05 00:44:28 -04001798static int acpi_video_bus_add(struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001799{
Len Brown4be44fc2005-08-05 00:44:28 -04001800 int result = 0;
1801 acpi_status status = 0;
1802 struct acpi_video_bus *video = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001803
Len Brown4be44fc2005-08-05 00:44:28 -04001804
Linus Torvalds1da177e2005-04-16 15:20:36 -07001805 if (!device)
Patrick Mocheld550d982006-06-27 00:41:40 -04001806 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001807
Burman Yan36bcbec2006-12-19 12:56:11 -08001808 video = kzalloc(sizeof(struct acpi_video_bus), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001809 if (!video)
Patrick Mocheld550d982006-06-27 00:41:40 -04001810 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001811
Patrick Mochele6afa0d2006-05-19 16:54:40 -04001812 video->device = device;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001813 strcpy(acpi_device_name(device), ACPI_VIDEO_BUS_NAME);
1814 strcpy(acpi_device_class(device), ACPI_VIDEO_CLASS);
1815 acpi_driver_data(device) = video;
1816
1817 acpi_video_bus_find_cap(video);
1818 result = acpi_video_bus_check(video);
1819 if (result)
1820 goto end;
1821
1822 result = acpi_video_bus_add_fs(device);
1823 if (result)
1824 goto end;
1825
1826 init_MUTEX(&video->sem);
1827 INIT_LIST_HEAD(&video->video_device_list);
1828
1829 acpi_video_bus_get_devices(video, device);
1830 acpi_video_bus_start_devices(video);
1831
Patrick Mochel90130262006-05-19 16:54:48 -04001832 status = acpi_install_notify_handler(device->handle,
Len Brown4be44fc2005-08-05 00:44:28 -04001833 ACPI_DEVICE_NOTIFY,
1834 acpi_video_bus_notify, video);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001835 if (ACPI_FAILURE(status)) {
1836 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
Len Brown4be44fc2005-08-05 00:44:28 -04001837 "Error installing notify handler\n"));
Yu, Luming973bf492006-04-27 05:25:00 -04001838 acpi_video_bus_stop_devices(video);
1839 acpi_video_bus_put_devices(video);
1840 kfree(video->attached_array);
1841 acpi_video_bus_remove_fs(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001842 result = -ENODEV;
1843 goto end;
1844 }
1845
1846 printk(KERN_INFO PREFIX "%s [%s] (multi-head: %s rom: %s post: %s)\n",
Len Brown4be44fc2005-08-05 00:44:28 -04001847 ACPI_VIDEO_DEVICE_NAME, acpi_device_bid(device),
1848 video->flags.multihead ? "yes" : "no",
1849 video->flags.rom ? "yes" : "no",
1850 video->flags.post ? "yes" : "no");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001851
Len Brown4be44fc2005-08-05 00:44:28 -04001852 end:
Yu, Luming973bf492006-04-27 05:25:00 -04001853 if (result)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001854 kfree(video);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001855
Patrick Mocheld550d982006-06-27 00:41:40 -04001856 return result;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001857}
1858
Len Brown4be44fc2005-08-05 00:44:28 -04001859static int acpi_video_bus_remove(struct acpi_device *device, int type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001860{
Len Brown4be44fc2005-08-05 00:44:28 -04001861 acpi_status status = 0;
1862 struct acpi_video_bus *video = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001863
Linus Torvalds1da177e2005-04-16 15:20:36 -07001864
1865 if (!device || !acpi_driver_data(device))
Patrick Mocheld550d982006-06-27 00:41:40 -04001866 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001867
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001868 video = acpi_driver_data(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001869
1870 acpi_video_bus_stop_devices(video);
1871
Patrick Mochel90130262006-05-19 16:54:48 -04001872 status = acpi_remove_notify_handler(video->device->handle,
Len Brown4be44fc2005-08-05 00:44:28 -04001873 ACPI_DEVICE_NOTIFY,
1874 acpi_video_bus_notify);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001875
1876 acpi_video_bus_put_devices(video);
1877 acpi_video_bus_remove_fs(device);
1878
Jesper Juhl6044ec82005-11-07 01:01:32 -08001879 kfree(video->attached_array);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001880 kfree(video);
1881
Patrick Mocheld550d982006-06-27 00:41:40 -04001882 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001883}
1884
Len Brown4be44fc2005-08-05 00:44:28 -04001885static int __init acpi_video_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001886{
Len Brown4be44fc2005-08-05 00:44:28 -04001887 int result = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001888
Linus Torvalds1da177e2005-04-16 15:20:36 -07001889
1890 /*
Len Brown4be44fc2005-08-05 00:44:28 -04001891 acpi_dbg_level = 0xFFFFFFFF;
1892 acpi_dbg_layer = 0x08000000;
1893 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001894
1895 acpi_video_dir = proc_mkdir(ACPI_VIDEO_CLASS, acpi_root_dir);
1896 if (!acpi_video_dir)
Patrick Mocheld550d982006-06-27 00:41:40 -04001897 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001898 acpi_video_dir->owner = THIS_MODULE;
1899
1900 result = acpi_bus_register_driver(&acpi_video_bus);
1901 if (result < 0) {
1902 remove_proc_entry(ACPI_VIDEO_CLASS, acpi_root_dir);
Patrick Mocheld550d982006-06-27 00:41:40 -04001903 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001904 }
1905
Patrick Mocheld550d982006-06-27 00:41:40 -04001906 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001907}
1908
Len Brown4be44fc2005-08-05 00:44:28 -04001909static void __exit acpi_video_exit(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001910{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001911
1912 acpi_bus_unregister_driver(&acpi_video_bus);
1913
1914 remove_proc_entry(ACPI_VIDEO_CLASS, acpi_root_dir);
1915
Patrick Mocheld550d982006-06-27 00:41:40 -04001916 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001917}
1918
1919module_init(acpi_video_init);
1920module_exit(acpi_video_exit);