blob: 5f014d3764c85b51b3ac3552f0722732254987fe [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>
Luming Yu23b0f012007-05-09 21:07:05 +080036#include <linux/video_output.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070037#include <asm/uaccess.h>
38
39#include <acpi/acpi_bus.h>
40#include <acpi/acpi_drivers.h>
41
42#define ACPI_VIDEO_COMPONENT 0x08000000
43#define ACPI_VIDEO_CLASS "video"
Linus Torvalds1da177e2005-04-16 15:20:36 -070044#define ACPI_VIDEO_BUS_NAME "Video Bus"
45#define ACPI_VIDEO_DEVICE_NAME "Video Device"
46#define ACPI_VIDEO_NOTIFY_SWITCH 0x80
47#define ACPI_VIDEO_NOTIFY_PROBE 0x81
48#define ACPI_VIDEO_NOTIFY_CYCLE 0x82
49#define ACPI_VIDEO_NOTIFY_NEXT_OUTPUT 0x83
50#define ACPI_VIDEO_NOTIFY_PREV_OUTPUT 0x84
51
Thomas Tuttlef4715182006-12-19 12:56:14 -080052#define ACPI_VIDEO_NOTIFY_CYCLE_BRIGHTNESS 0x85
53#define ACPI_VIDEO_NOTIFY_INC_BRIGHTNESS 0x86
54#define ACPI_VIDEO_NOTIFY_DEC_BRIGHTNESS 0x87
55#define ACPI_VIDEO_NOTIFY_ZERO_BRIGHTNESS 0x88
56#define ACPI_VIDEO_NOTIFY_DISPLAY_OFF 0x89
Linus Torvalds1da177e2005-04-16 15:20:36 -070057
Linus Torvalds1da177e2005-04-16 15:20:36 -070058#define ACPI_VIDEO_HEAD_INVALID (~0u - 1)
59#define ACPI_VIDEO_HEAD_END (~0u)
Yu Luming2f3d0002006-11-11 02:40:34 +080060#define MAX_NAME_LEN 20
Linus Torvalds1da177e2005-04-16 15:20:36 -070061
Rui Zhang82cae992007-01-03 23:40:53 -050062#define ACPI_VIDEO_DISPLAY_CRT 1
63#define ACPI_VIDEO_DISPLAY_TV 2
64#define ACPI_VIDEO_DISPLAY_DVI 3
65#define ACPI_VIDEO_DISPLAY_LCD 4
66
Linus Torvalds1da177e2005-04-16 15:20:36 -070067#define _COMPONENT ACPI_VIDEO_COMPONENT
Len Brownf52fd662007-02-12 22:42:12 -050068ACPI_MODULE_NAME("video");
Linus Torvalds1da177e2005-04-16 15:20:36 -070069
Len Brownf52fd662007-02-12 22:42:12 -050070MODULE_AUTHOR("Bruno Ducrot");
Len Brown7cda93e2007-02-12 23:50:02 -050071MODULE_DESCRIPTION("ACPI Video Driver");
Linus Torvalds1da177e2005-04-16 15:20:36 -070072MODULE_LICENSE("GPL");
73
Len Brown4be44fc2005-08-05 00:44:28 -040074static int acpi_video_bus_add(struct acpi_device *device);
75static int acpi_video_bus_remove(struct acpi_device *device, int type);
Linus Torvalds1da177e2005-04-16 15:20:36 -070076
77static struct acpi_driver acpi_video_bus = {
Len Brownc2b67052007-02-12 23:33:40 -050078 .name = "video",
Linus Torvalds1da177e2005-04-16 15:20:36 -070079 .class = ACPI_VIDEO_CLASS,
Zhang Ruiae843332006-12-07 20:57:10 +080080 .ids = ACPI_VIDEO_HID,
Linus Torvalds1da177e2005-04-16 15:20:36 -070081 .ops = {
82 .add = acpi_video_bus_add,
83 .remove = acpi_video_bus_remove,
Len Brown4be44fc2005-08-05 00:44:28 -040084 },
Linus Torvalds1da177e2005-04-16 15:20:36 -070085};
86
87struct acpi_video_bus_flags {
Len Brown4be44fc2005-08-05 00:44:28 -040088 u8 multihead:1; /* can switch video heads */
89 u8 rom:1; /* can retrieve a video rom */
90 u8 post:1; /* can configure the head to */
91 u8 reserved:5;
Linus Torvalds1da177e2005-04-16 15:20:36 -070092};
93
94struct acpi_video_bus_cap {
Len Brown4be44fc2005-08-05 00:44:28 -040095 u8 _DOS:1; /*Enable/Disable output switching */
96 u8 _DOD:1; /*Enumerate all devices attached to display adapter */
97 u8 _ROM:1; /*Get ROM Data */
98 u8 _GPD:1; /*Get POST Device */
99 u8 _SPD:1; /*Set POST Device */
100 u8 _VPO:1; /*Video POST Options */
101 u8 reserved:2;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102};
103
Len Brown4be44fc2005-08-05 00:44:28 -0400104struct acpi_video_device_attrib {
105 u32 display_index:4; /* A zero-based instance of the Display */
Julius Volz98fb8fe2007-02-20 16:38:40 +0100106 u32 display_port_attachment:4; /*This field differentiates the display type */
Len Brown4be44fc2005-08-05 00:44:28 -0400107 u32 display_type:4; /*Describe the specific type in use */
Julius Volz98fb8fe2007-02-20 16:38:40 +0100108 u32 vendor_specific:4; /*Chipset Vendor Specific */
Len Brown4be44fc2005-08-05 00:44:28 -0400109 u32 bios_can_detect:1; /*BIOS can detect the device */
110 u32 depend_on_vga:1; /*Non-VGA output device whose power is related to
111 the VGA device. */
112 u32 pipe_id:3; /*For VGA multiple-head devices. */
113 u32 reserved:10; /*Must be 0 */
114 u32 device_id_scheme:1; /*Device ID Scheme */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700115};
116
117struct acpi_video_enumerated_device {
118 union {
119 u32 int_val;
Len Brown4be44fc2005-08-05 00:44:28 -0400120 struct acpi_video_device_attrib attrib;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121 } value;
122 struct acpi_video_device *bind_info;
123};
124
125struct acpi_video_bus {
Patrick Mochele6afa0d2006-05-19 16:54:40 -0400126 struct acpi_device *device;
Len Brown4be44fc2005-08-05 00:44:28 -0400127 u8 dos_setting;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128 struct acpi_video_enumerated_device *attached_array;
Len Brown4be44fc2005-08-05 00:44:28 -0400129 u8 attached_count;
130 struct acpi_video_bus_cap cap;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131 struct acpi_video_bus_flags flags;
Len Brown4be44fc2005-08-05 00:44:28 -0400132 struct semaphore sem;
133 struct list_head video_device_list;
134 struct proc_dir_entry *dir;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135};
136
137struct acpi_video_device_flags {
Len Brown4be44fc2005-08-05 00:44:28 -0400138 u8 crt:1;
139 u8 lcd:1;
140 u8 tvout:1;
Rui Zhang82cae992007-01-03 23:40:53 -0500141 u8 dvi:1;
Len Brown4be44fc2005-08-05 00:44:28 -0400142 u8 bios:1;
143 u8 unknown:1;
Rui Zhang82cae992007-01-03 23:40:53 -0500144 u8 reserved:2;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145};
146
147struct acpi_video_device_cap {
Len Brown4be44fc2005-08-05 00:44:28 -0400148 u8 _ADR:1; /*Return the unique ID */
149 u8 _BCL:1; /*Query list of brightness control levels supported */
150 u8 _BCM:1; /*Set the brightness level */
Yu Luming2f3d0002006-11-11 02:40:34 +0800151 u8 _BQC:1; /* Get current brightness level */
Len Brown4be44fc2005-08-05 00:44:28 -0400152 u8 _DDC:1; /*Return the EDID for this device */
153 u8 _DCS:1; /*Return status of output device */
154 u8 _DGS:1; /*Query graphics state */
155 u8 _DSS:1; /*Device state set */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156};
157
158struct acpi_video_device_brightness {
Len Brown4be44fc2005-08-05 00:44:28 -0400159 int curr;
160 int count;
161 int *levels;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700162};
163
164struct acpi_video_device {
Len Brown4be44fc2005-08-05 00:44:28 -0400165 unsigned long device_id;
166 struct acpi_video_device_flags flags;
167 struct acpi_video_device_cap cap;
168 struct list_head entry;
169 struct acpi_video_bus *video;
170 struct acpi_device *dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700171 struct acpi_video_device_brightness *brightness;
Yu Luming2f3d0002006-11-11 02:40:34 +0800172 struct backlight_device *backlight;
Luming Yu23b0f012007-05-09 21:07:05 +0800173 struct output_device *output_dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700174};
175
Linus Torvalds1da177e2005-04-16 15:20:36 -0700176/* bus */
177static int acpi_video_bus_info_open_fs(struct inode *inode, struct file *file);
178static struct file_operations acpi_video_bus_info_fops = {
Len Brown4be44fc2005-08-05 00:44:28 -0400179 .open = acpi_video_bus_info_open_fs,
180 .read = seq_read,
181 .llseek = seq_lseek,
182 .release = single_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700183};
184
185static int acpi_video_bus_ROM_open_fs(struct inode *inode, struct file *file);
186static struct file_operations acpi_video_bus_ROM_fops = {
Len Brown4be44fc2005-08-05 00:44:28 -0400187 .open = acpi_video_bus_ROM_open_fs,
188 .read = seq_read,
189 .llseek = seq_lseek,
190 .release = single_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700191};
192
Len Brown4be44fc2005-08-05 00:44:28 -0400193static int acpi_video_bus_POST_info_open_fs(struct inode *inode,
194 struct file *file);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700195static struct file_operations acpi_video_bus_POST_info_fops = {
Len Brown4be44fc2005-08-05 00:44:28 -0400196 .open = acpi_video_bus_POST_info_open_fs,
197 .read = seq_read,
198 .llseek = seq_lseek,
199 .release = single_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700200};
201
202static int acpi_video_bus_POST_open_fs(struct inode *inode, struct file *file);
203static struct file_operations acpi_video_bus_POST_fops = {
Len Brown4be44fc2005-08-05 00:44:28 -0400204 .open = acpi_video_bus_POST_open_fs,
205 .read = seq_read,
206 .llseek = seq_lseek,
207 .release = single_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700208};
209
Linus Torvalds1da177e2005-04-16 15:20:36 -0700210static int acpi_video_bus_DOS_open_fs(struct inode *inode, struct file *file);
211static struct file_operations acpi_video_bus_DOS_fops = {
Len Brown4be44fc2005-08-05 00:44:28 -0400212 .open = acpi_video_bus_DOS_open_fs,
213 .read = seq_read,
214 .llseek = seq_lseek,
215 .release = single_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700216};
217
218/* device */
Len Brown4be44fc2005-08-05 00:44:28 -0400219static int acpi_video_device_info_open_fs(struct inode *inode,
220 struct file *file);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700221static struct file_operations acpi_video_device_info_fops = {
Len Brown4be44fc2005-08-05 00:44:28 -0400222 .open = acpi_video_device_info_open_fs,
223 .read = seq_read,
224 .llseek = seq_lseek,
225 .release = single_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700226};
227
Len Brown4be44fc2005-08-05 00:44:28 -0400228static int acpi_video_device_state_open_fs(struct inode *inode,
229 struct file *file);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700230static struct file_operations acpi_video_device_state_fops = {
Len Brown4be44fc2005-08-05 00:44:28 -0400231 .open = acpi_video_device_state_open_fs,
232 .read = seq_read,
233 .llseek = seq_lseek,
234 .release = single_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700235};
236
Len Brown4be44fc2005-08-05 00:44:28 -0400237static int acpi_video_device_brightness_open_fs(struct inode *inode,
238 struct file *file);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700239static struct file_operations acpi_video_device_brightness_fops = {
Len Brown4be44fc2005-08-05 00:44:28 -0400240 .open = acpi_video_device_brightness_open_fs,
241 .read = seq_read,
242 .llseek = seq_lseek,
243 .release = single_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700244};
245
Len Brown4be44fc2005-08-05 00:44:28 -0400246static int acpi_video_device_EDID_open_fs(struct inode *inode,
247 struct file *file);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700248static struct file_operations acpi_video_device_EDID_fops = {
Len Brown4be44fc2005-08-05 00:44:28 -0400249 .open = acpi_video_device_EDID_open_fs,
250 .read = seq_read,
251 .llseek = seq_lseek,
252 .release = single_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700253};
254
Len Brown4be44fc2005-08-05 00:44:28 -0400255static char device_decode[][30] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700256 "motherboard VGA device",
257 "PCI VGA device",
258 "AGP VGA device",
259 "UNKNOWN",
260};
261
Len Brown4be44fc2005-08-05 00:44:28 -0400262static void acpi_video_device_notify(acpi_handle handle, u32 event, void *data);
263static void acpi_video_device_rebind(struct acpi_video_bus *video);
264static void acpi_video_device_bind(struct acpi_video_bus *video,
265 struct acpi_video_device *device);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700266static int acpi_video_device_enumerate(struct acpi_video_bus *video);
Len Brown4be44fc2005-08-05 00:44:28 -0400267static int acpi_video_switch_output(struct acpi_video_bus *video, int event);
Yu Luming2f3d0002006-11-11 02:40:34 +0800268static int acpi_video_device_lcd_set_level(struct acpi_video_device *device,
269 int level);
270static int acpi_video_device_lcd_get_level_current(
271 struct acpi_video_device *device,
272 unsigned long *level);
Len Brown4be44fc2005-08-05 00:44:28 -0400273static int acpi_video_get_next_level(struct acpi_video_device *device,
274 u32 level_current, u32 event);
275static void acpi_video_switch_brightness(struct acpi_video_device *device,
276 int event);
Luming Yu23b0f012007-05-09 21:07:05 +0800277static int acpi_video_device_get_state(struct acpi_video_device *device,
278 unsigned long *state);
279static int acpi_video_output_get(struct output_device *od);
280static int acpi_video_device_set_state(struct acpi_video_device *device, int state);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700281
Yu Luming2f3d0002006-11-11 02:40:34 +0800282/*backlight device sysfs support*/
283static int acpi_video_get_brightness(struct backlight_device *bd)
284{
285 unsigned long cur_level;
286 struct acpi_video_device *vd =
287 (struct acpi_video_device *)class_get_devdata(&bd->class_dev);
288 acpi_video_device_lcd_get_level_current(vd, &cur_level);
289 return (int) cur_level;
290}
291
292static int acpi_video_set_brightness(struct backlight_device *bd)
293{
Richard Purdie599a52d2007-02-10 23:07:48 +0000294 int request_level = bd->props.brightness;
Yu Luming2f3d0002006-11-11 02:40:34 +0800295 struct acpi_video_device *vd =
296 (struct acpi_video_device *)class_get_devdata(&bd->class_dev);
297 acpi_video_device_lcd_set_level(vd, request_level);
298 return 0;
299}
300
Richard Purdie599a52d2007-02-10 23:07:48 +0000301static struct backlight_ops acpi_backlight_ops = {
302 .get_brightness = acpi_video_get_brightness,
303 .update_status = acpi_video_set_brightness,
304};
305
Luming Yu23b0f012007-05-09 21:07:05 +0800306/*video output device sysfs support*/
307static int acpi_video_output_get(struct output_device *od)
308{
309 unsigned long state;
310 struct acpi_video_device *vd =
311 (struct acpi_video_device *)class_get_devdata(&od->class_dev);
312 acpi_video_device_get_state(vd, &state);
313 return (int)state;
314}
315
316static int acpi_video_output_set(struct output_device *od)
317{
318 unsigned long state = od->request_state;
319 struct acpi_video_device *vd=
320 (struct acpi_video_device *)class_get_devdata(&od->class_dev);
321 return acpi_video_device_set_state(vd, state);
322}
323
324static struct output_properties acpi_output_properties = {
325 .set_state = acpi_video_output_set,
326 .get_status = acpi_video_output_get,
327};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700328/* --------------------------------------------------------------------------
329 Video Management
330 -------------------------------------------------------------------------- */
331
332/* device */
333
334static int
Len Brown4be44fc2005-08-05 00:44:28 -0400335acpi_video_device_query(struct acpi_video_device *device, unsigned long *state)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700336{
Len Brown4be44fc2005-08-05 00:44:28 -0400337 int status;
Patrick Mochel90130262006-05-19 16:54:48 -0400338
339 status = acpi_evaluate_integer(device->dev->handle, "_DGS", NULL, state);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700340
Patrick Mocheld550d982006-06-27 00:41:40 -0400341 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700342}
343
344static int
Len Brown4be44fc2005-08-05 00:44:28 -0400345acpi_video_device_get_state(struct acpi_video_device *device,
346 unsigned long *state)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700347{
Len Brown4be44fc2005-08-05 00:44:28 -0400348 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700349
Patrick Mochel90130262006-05-19 16:54:48 -0400350 status = acpi_evaluate_integer(device->dev->handle, "_DCS", NULL, state);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700351
Patrick Mocheld550d982006-06-27 00:41:40 -0400352 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700353}
354
355static int
Len Brown4be44fc2005-08-05 00:44:28 -0400356acpi_video_device_set_state(struct acpi_video_device *device, int state)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700357{
Len Brown4be44fc2005-08-05 00:44:28 -0400358 int status;
359 union acpi_object arg0 = { ACPI_TYPE_INTEGER };
360 struct acpi_object_list args = { 1, &arg0 };
Luming Yu824b5582005-08-21 19:17:00 -0400361 unsigned long ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700362
Linus Torvalds1da177e2005-04-16 15:20:36 -0700363
364 arg0.integer.value = state;
Patrick Mochel90130262006-05-19 16:54:48 -0400365 status = acpi_evaluate_integer(device->dev->handle, "_DSS", &args, &ret);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700366
Patrick Mocheld550d982006-06-27 00:41:40 -0400367 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700368}
369
370static int
Len Brown4be44fc2005-08-05 00:44:28 -0400371acpi_video_device_lcd_query_levels(struct acpi_video_device *device,
372 union acpi_object **levels)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700373{
Len Brown4be44fc2005-08-05 00:44:28 -0400374 int status;
375 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
376 union acpi_object *obj;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700377
Linus Torvalds1da177e2005-04-16 15:20:36 -0700378
379 *levels = NULL;
380
Patrick Mochel90130262006-05-19 16:54:48 -0400381 status = acpi_evaluate_object(device->dev->handle, "_BCL", NULL, &buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700382 if (!ACPI_SUCCESS(status))
Patrick Mocheld550d982006-06-27 00:41:40 -0400383 return status;
Len Brown4be44fc2005-08-05 00:44:28 -0400384 obj = (union acpi_object *)buffer.pointer;
Adrian Bunk6665bda2006-03-11 10:12:00 -0500385 if (!obj || (obj->type != ACPI_TYPE_PACKAGE)) {
Len Brown64684632006-06-26 23:41:38 -0400386 printk(KERN_ERR PREFIX "Invalid _BCL data\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700387 status = -EFAULT;
388 goto err;
389 }
390
391 *levels = obj;
392
Patrick Mocheld550d982006-06-27 00:41:40 -0400393 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700394
Len Brown4be44fc2005-08-05 00:44:28 -0400395 err:
Jesper Juhl6044ec82005-11-07 01:01:32 -0800396 kfree(buffer.pointer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700397
Patrick Mocheld550d982006-06-27 00:41:40 -0400398 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700399}
400
401static int
Len Brown4be44fc2005-08-05 00:44:28 -0400402acpi_video_device_lcd_set_level(struct acpi_video_device *device, int level)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700403{
Len Brown4be44fc2005-08-05 00:44:28 -0400404 int status;
405 union acpi_object arg0 = { ACPI_TYPE_INTEGER };
406 struct acpi_object_list args = { 1, &arg0 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700407
Linus Torvalds1da177e2005-04-16 15:20:36 -0700408
409 arg0.integer.value = level;
Patrick Mochel90130262006-05-19 16:54:48 -0400410 status = acpi_evaluate_object(device->dev->handle, "_BCM", &args, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700411
412 printk(KERN_DEBUG "set_level status: %x\n", status);
Patrick Mocheld550d982006-06-27 00:41:40 -0400413 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700414}
415
416static int
Len Brown4be44fc2005-08-05 00:44:28 -0400417acpi_video_device_lcd_get_level_current(struct acpi_video_device *device,
418 unsigned long *level)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700419{
Len Brown4be44fc2005-08-05 00:44:28 -0400420 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700421
Patrick Mochel90130262006-05-19 16:54:48 -0400422 status = acpi_evaluate_integer(device->dev->handle, "_BQC", NULL, level);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700423
Patrick Mocheld550d982006-06-27 00:41:40 -0400424 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700425}
426
427static int
Len Brown4be44fc2005-08-05 00:44:28 -0400428acpi_video_device_EDID(struct acpi_video_device *device,
429 union acpi_object **edid, ssize_t length)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700430{
Len Brown4be44fc2005-08-05 00:44:28 -0400431 int status;
432 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
433 union acpi_object *obj;
434 union acpi_object arg0 = { ACPI_TYPE_INTEGER };
435 struct acpi_object_list args = { 1, &arg0 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700436
Linus Torvalds1da177e2005-04-16 15:20:36 -0700437
438 *edid = NULL;
439
440 if (!device)
Patrick Mocheld550d982006-06-27 00:41:40 -0400441 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700442 if (length == 128)
443 arg0.integer.value = 1;
444 else if (length == 256)
445 arg0.integer.value = 2;
446 else
Patrick Mocheld550d982006-06-27 00:41:40 -0400447 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700448
Patrick Mochel90130262006-05-19 16:54:48 -0400449 status = acpi_evaluate_object(device->dev->handle, "_DDC", &args, &buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700450 if (ACPI_FAILURE(status))
Patrick Mocheld550d982006-06-27 00:41:40 -0400451 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700452
Jan Engelhardt50dd0962006-10-01 00:28:50 +0200453 obj = buffer.pointer;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700454
455 if (obj && obj->type == ACPI_TYPE_BUFFER)
456 *edid = obj;
457 else {
Len Brown64684632006-06-26 23:41:38 -0400458 printk(KERN_ERR PREFIX "Invalid _DDC data\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700459 status = -EFAULT;
460 kfree(obj);
461 }
462
Patrick Mocheld550d982006-06-27 00:41:40 -0400463 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700464}
465
Linus Torvalds1da177e2005-04-16 15:20:36 -0700466/* bus */
467
468static int
Len Brown4be44fc2005-08-05 00:44:28 -0400469acpi_video_bus_set_POST(struct acpi_video_bus *video, unsigned long option)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700470{
Len Brown4be44fc2005-08-05 00:44:28 -0400471 int status;
472 unsigned long tmp;
473 union acpi_object arg0 = { ACPI_TYPE_INTEGER };
474 struct acpi_object_list args = { 1, &arg0 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700475
Linus Torvalds1da177e2005-04-16 15:20:36 -0700476
477 arg0.integer.value = option;
478
Patrick Mochel90130262006-05-19 16:54:48 -0400479 status = acpi_evaluate_integer(video->device->handle, "_SPD", &args, &tmp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700480 if (ACPI_SUCCESS(status))
Len Brown4be44fc2005-08-05 00:44:28 -0400481 status = tmp ? (-EINVAL) : (AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700482
Patrick Mocheld550d982006-06-27 00:41:40 -0400483 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700484}
485
486static int
Len Brown4be44fc2005-08-05 00:44:28 -0400487acpi_video_bus_get_POST(struct acpi_video_bus *video, unsigned long *id)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700488{
489 int status;
490
Patrick Mochel90130262006-05-19 16:54:48 -0400491 status = acpi_evaluate_integer(video->device->handle, "_GPD", NULL, id);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700492
Patrick Mocheld550d982006-06-27 00:41:40 -0400493 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700494}
495
496static int
Len Brown4be44fc2005-08-05 00:44:28 -0400497acpi_video_bus_POST_options(struct acpi_video_bus *video,
498 unsigned long *options)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700499{
Len Brown4be44fc2005-08-05 00:44:28 -0400500 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700501
Patrick Mochel90130262006-05-19 16:54:48 -0400502 status = acpi_evaluate_integer(video->device->handle, "_VPO", NULL, options);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700503 *options &= 3;
504
Patrick Mocheld550d982006-06-27 00:41:40 -0400505 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700506}
507
508/*
509 * Arg:
510 * video : video bus device pointer
511 * bios_flag :
512 * 0. The system BIOS should NOT automatically switch(toggle)
513 * the active display output.
514 * 1. The system BIOS should automatically switch (toggle) the
Julius Volz98fb8fe2007-02-20 16:38:40 +0100515 * active display output. No switch event.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700516 * 2. The _DGS value should be locked.
517 * 3. The system BIOS should not automatically switch (toggle) the
518 * active display output, but instead generate the display switch
519 * event notify code.
520 * lcd_flag :
521 * 0. The system BIOS should automatically control the brightness level
Julius Volz98fb8fe2007-02-20 16:38:40 +0100522 * of the LCD when the power changes from AC to DC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700523 * 1. The system BIOS should NOT automatically control the brightness
Julius Volz98fb8fe2007-02-20 16:38:40 +0100524 * level of the LCD when the power changes from AC to DC.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700525 * Return Value:
526 * -1 wrong arg.
527 */
528
529static int
Len Brown4be44fc2005-08-05 00:44:28 -0400530acpi_video_bus_DOS(struct acpi_video_bus *video, int bios_flag, int lcd_flag)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700531{
Len Brown4be44fc2005-08-05 00:44:28 -0400532 acpi_integer status = 0;
533 union acpi_object arg0 = { ACPI_TYPE_INTEGER };
534 struct acpi_object_list args = { 1, &arg0 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700535
Linus Torvalds1da177e2005-04-16 15:20:36 -0700536
Len Brown4be44fc2005-08-05 00:44:28 -0400537 if (bios_flag < 0 || bios_flag > 3 || lcd_flag < 0 || lcd_flag > 1) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700538 status = -1;
539 goto Failed;
540 }
541 arg0.integer.value = (lcd_flag << 2) | bios_flag;
542 video->dos_setting = arg0.integer.value;
Patrick Mochel90130262006-05-19 16:54:48 -0400543 acpi_evaluate_object(video->device->handle, "_DOS", &args, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700544
Len Brown4be44fc2005-08-05 00:44:28 -0400545 Failed:
Patrick Mocheld550d982006-06-27 00:41:40 -0400546 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700547}
548
549/*
550 * Arg:
551 * device : video output device (LCD, CRT, ..)
552 *
553 * Return Value:
554 * None
555 *
Julius Volz98fb8fe2007-02-20 16:38:40 +0100556 * Find out all required AML methods defined under the output
Linus Torvalds1da177e2005-04-16 15:20:36 -0700557 * device.
558 */
559
Len Brown4be44fc2005-08-05 00:44:28 -0400560static void acpi_video_device_find_cap(struct acpi_video_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700561{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700562 acpi_handle h_dummy1;
563 int i;
Yu Luming2f3d0002006-11-11 02:40:34 +0800564 u32 max_level = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700565 union acpi_object *obj = NULL;
566 struct acpi_video_device_brightness *br = NULL;
567
Linus Torvalds1da177e2005-04-16 15:20:36 -0700568
Len Brown4be44fc2005-08-05 00:44:28 -0400569 memset(&device->cap, 0, 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700570
Patrick Mochel90130262006-05-19 16:54:48 -0400571 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_ADR", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700572 device->cap._ADR = 1;
573 }
Patrick Mochel90130262006-05-19 16:54:48 -0400574 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_BCL", &h_dummy1))) {
Len Brown4be44fc2005-08-05 00:44:28 -0400575 device->cap._BCL = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700576 }
Patrick Mochel90130262006-05-19 16:54:48 -0400577 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_BCM", &h_dummy1))) {
Len Brown4be44fc2005-08-05 00:44:28 -0400578 device->cap._BCM = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700579 }
Yu Luming2f3d0002006-11-11 02:40:34 +0800580 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle,"_BQC",&h_dummy1)))
581 device->cap._BQC = 1;
Patrick Mochel90130262006-05-19 16:54:48 -0400582 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_DDC", &h_dummy1))) {
Len Brown4be44fc2005-08-05 00:44:28 -0400583 device->cap._DDC = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700584 }
Patrick Mochel90130262006-05-19 16:54:48 -0400585 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_DCS", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700586 device->cap._DCS = 1;
587 }
Patrick Mochel90130262006-05-19 16:54:48 -0400588 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_DGS", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700589 device->cap._DGS = 1;
590 }
Patrick Mochel90130262006-05-19 16:54:48 -0400591 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_DSS", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700592 device->cap._DSS = 1;
593 }
594
Danny Kukawkaf70ac0e2007-07-03 01:33:53 -0400595 if (ACPI_SUCCESS(acpi_video_device_lcd_query_levels(device, &obj))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700596
Danny Kukawkaf70ac0e2007-07-03 01:33:53 -0400597 if (obj->package.count >= 2) {
598 int count = 0;
599 union acpi_object *o;
Len Brown4be44fc2005-08-05 00:44:28 -0400600
Danny Kukawkaf70ac0e2007-07-03 01:33:53 -0400601 br = kzalloc(sizeof(*br), GFP_KERNEL);
602 if (!br) {
603 printk(KERN_ERR "can't allocate memory\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700604 } else {
Danny Kukawkaf70ac0e2007-07-03 01:33:53 -0400605 br->levels = kmalloc(obj->package.count *
606 sizeof *(br->levels), GFP_KERNEL);
607 if (!br->levels)
608 goto out;
609
610 for (i = 0; i < obj->package.count; i++) {
611 o = (union acpi_object *)&obj->package.
612 elements[i];
613 if (o->type != ACPI_TYPE_INTEGER) {
614 printk(KERN_ERR PREFIX "Invalid data\n");
615 continue;
616 }
617 br->levels[count] = (u32) o->integer.value;
618
619 if (br->levels[count] > max_level)
620 max_level = br->levels[count];
621 count++;
622 }
623 out:
624 if (count < 2) {
625 kfree(br->levels);
626 kfree(br);
627 } else {
628 br->count = count;
629 device->brightness = br;
630 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
631 "found %d brightness levels\n",
632 count));
633 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700634 }
635 }
Danny Kukawkaf70ac0e2007-07-03 01:33:53 -0400636
637 } else {
638 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Could not query available LCD brightness level\n"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700639 }
640
Paulo Marquesd1dd0c22005-03-30 22:39:49 -0500641 kfree(obj);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700642
Danny Kukawkaf70ac0e2007-07-03 01:33:53 -0400643 if (device->cap._BCL && device->cap._BCM && device->cap._BQC && max_level > 0){
Yu Luming2f3d0002006-11-11 02:40:34 +0800644 unsigned long tmp;
645 static int count = 0;
646 char *name;
Yu Luming2f3d0002006-11-11 02:40:34 +0800647 name = kzalloc(MAX_NAME_LEN, GFP_KERNEL);
648 if (!name)
649 return;
650
Yu Luming2f3d0002006-11-11 02:40:34 +0800651 sprintf(name, "acpi_video%d", count++);
Yu Luming2f3d0002006-11-11 02:40:34 +0800652 acpi_video_device_lcd_get_level_current(device, &tmp);
Yu Luming2f3d0002006-11-11 02:40:34 +0800653 device->backlight = backlight_device_register(name,
Richard Purdie599a52d2007-02-10 23:07:48 +0000654 NULL, device, &acpi_backlight_ops);
655 device->backlight->props.max_brightness = max_level;
656 device->backlight->props.brightness = (int)tmp;
657 backlight_update_status(device->backlight);
658
Yu Luming2f3d0002006-11-11 02:40:34 +0800659 kfree(name);
660 }
Luming Yu23b0f012007-05-09 21:07:05 +0800661 if (device->cap._DCS && device->cap._DSS){
662 static int count = 0;
663 char *name;
664 name = kzalloc(MAX_NAME_LEN, GFP_KERNEL);
665 if (!name)
666 return;
667 sprintf(name, "acpi_video%d", count++);
668 device->output_dev = video_output_register(name,
669 NULL, device, &acpi_output_properties);
670 kfree(name);
671 }
Patrick Mocheld550d982006-06-27 00:41:40 -0400672 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700673}
674
675/*
676 * Arg:
677 * device : video output device (VGA)
678 *
679 * Return Value:
680 * None
681 *
Julius Volz98fb8fe2007-02-20 16:38:40 +0100682 * Find out all required AML methods defined under the video bus device.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700683 */
684
Len Brown4be44fc2005-08-05 00:44:28 -0400685static void acpi_video_bus_find_cap(struct acpi_video_bus *video)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700686{
Len Brown4be44fc2005-08-05 00:44:28 -0400687 acpi_handle h_dummy1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700688
Len Brown4be44fc2005-08-05 00:44:28 -0400689 memset(&video->cap, 0, 4);
Patrick Mochel90130262006-05-19 16:54:48 -0400690 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_DOS", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700691 video->cap._DOS = 1;
692 }
Patrick Mochel90130262006-05-19 16:54:48 -0400693 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_DOD", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700694 video->cap._DOD = 1;
695 }
Patrick Mochel90130262006-05-19 16:54:48 -0400696 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_ROM", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700697 video->cap._ROM = 1;
698 }
Patrick Mochel90130262006-05-19 16:54:48 -0400699 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_GPD", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700700 video->cap._GPD = 1;
701 }
Patrick Mochel90130262006-05-19 16:54:48 -0400702 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_SPD", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700703 video->cap._SPD = 1;
704 }
Patrick Mochel90130262006-05-19 16:54:48 -0400705 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_VPO", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700706 video->cap._VPO = 1;
707 }
708}
709
710/*
711 * Check whether the video bus device has required AML method to
712 * support the desired features
713 */
714
Len Brown4be44fc2005-08-05 00:44:28 -0400715static int acpi_video_bus_check(struct acpi_video_bus *video)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700716{
Len Brown4be44fc2005-08-05 00:44:28 -0400717 acpi_status status = -ENOENT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700718
Linus Torvalds1da177e2005-04-16 15:20:36 -0700719
720 if (!video)
Patrick Mocheld550d982006-06-27 00:41:40 -0400721 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700722
723 /* Since there is no HID, CID and so on for VGA driver, we have
724 * to check well known required nodes.
725 */
726
Julius Volz98fb8fe2007-02-20 16:38:40 +0100727 /* Does this device support video switching? */
Len Brown4be44fc2005-08-05 00:44:28 -0400728 if (video->cap._DOS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700729 video->flags.multihead = 1;
730 status = 0;
731 }
732
Julius Volz98fb8fe2007-02-20 16:38:40 +0100733 /* Does this device support retrieving a video ROM? */
Len Brown4be44fc2005-08-05 00:44:28 -0400734 if (video->cap._ROM) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700735 video->flags.rom = 1;
736 status = 0;
737 }
738
Julius Volz98fb8fe2007-02-20 16:38:40 +0100739 /* Does this device support configuring which video device to POST? */
Len Brown4be44fc2005-08-05 00:44:28 -0400740 if (video->cap._GPD && video->cap._SPD && video->cap._VPO) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700741 video->flags.post = 1;
742 status = 0;
743 }
744
Patrick Mocheld550d982006-06-27 00:41:40 -0400745 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700746}
747
748/* --------------------------------------------------------------------------
749 FS Interface (/proc)
750 -------------------------------------------------------------------------- */
751
Len Brown4be44fc2005-08-05 00:44:28 -0400752static struct proc_dir_entry *acpi_video_dir;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700753
754/* video devices */
755
Len Brown4be44fc2005-08-05 00:44:28 -0400756static int acpi_video_device_info_seq_show(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700757{
Jan Engelhardt50dd0962006-10-01 00:28:50 +0200758 struct acpi_video_device *dev = seq->private;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700759
Linus Torvalds1da177e2005-04-16 15:20:36 -0700760
761 if (!dev)
762 goto end;
763
764 seq_printf(seq, "device_id: 0x%04x\n", (u32) dev->device_id);
765 seq_printf(seq, "type: ");
766 if (dev->flags.crt)
767 seq_printf(seq, "CRT\n");
768 else if (dev->flags.lcd)
769 seq_printf(seq, "LCD\n");
770 else if (dev->flags.tvout)
771 seq_printf(seq, "TVOUT\n");
Rui Zhang82cae992007-01-03 23:40:53 -0500772 else if (dev->flags.dvi)
773 seq_printf(seq, "DVI\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700774 else
775 seq_printf(seq, "UNKNOWN\n");
776
Len Brown4be44fc2005-08-05 00:44:28 -0400777 seq_printf(seq, "known by bios: %s\n", dev->flags.bios ? "yes" : "no");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700778
Len Brown4be44fc2005-08-05 00:44:28 -0400779 end:
Patrick Mocheld550d982006-06-27 00:41:40 -0400780 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700781}
782
783static int
Len Brown4be44fc2005-08-05 00:44:28 -0400784acpi_video_device_info_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700785{
786 return single_open(file, acpi_video_device_info_seq_show,
787 PDE(inode)->data);
788}
789
Len Brown4be44fc2005-08-05 00:44:28 -0400790static int acpi_video_device_state_seq_show(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700791{
Len Brown4be44fc2005-08-05 00:44:28 -0400792 int status;
Jan Engelhardt50dd0962006-10-01 00:28:50 +0200793 struct acpi_video_device *dev = seq->private;
Len Brown4be44fc2005-08-05 00:44:28 -0400794 unsigned long state;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700795
Linus Torvalds1da177e2005-04-16 15:20:36 -0700796
797 if (!dev)
798 goto end;
799
800 status = acpi_video_device_get_state(dev, &state);
801 seq_printf(seq, "state: ");
802 if (ACPI_SUCCESS(status))
803 seq_printf(seq, "0x%02lx\n", state);
804 else
805 seq_printf(seq, "<not supported>\n");
806
807 status = acpi_video_device_query(dev, &state);
808 seq_printf(seq, "query: ");
809 if (ACPI_SUCCESS(status))
810 seq_printf(seq, "0x%02lx\n", state);
811 else
812 seq_printf(seq, "<not supported>\n");
813
Len Brown4be44fc2005-08-05 00:44:28 -0400814 end:
Patrick Mocheld550d982006-06-27 00:41:40 -0400815 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700816}
817
818static int
Len Brown4be44fc2005-08-05 00:44:28 -0400819acpi_video_device_state_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700820{
821 return single_open(file, acpi_video_device_state_seq_show,
822 PDE(inode)->data);
823}
824
825static ssize_t
Len Brown4be44fc2005-08-05 00:44:28 -0400826acpi_video_device_write_state(struct file *file,
827 const char __user * buffer,
828 size_t count, loff_t * data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700829{
Len Brown4be44fc2005-08-05 00:44:28 -0400830 int status;
Jan Engelhardt50dd0962006-10-01 00:28:50 +0200831 struct seq_file *m = file->private_data;
832 struct acpi_video_device *dev = m->private;
Len Brown4be44fc2005-08-05 00:44:28 -0400833 char str[12] = { 0 };
834 u32 state = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700835
Linus Torvalds1da177e2005-04-16 15:20:36 -0700836
837 if (!dev || count + 1 > sizeof str)
Patrick Mocheld550d982006-06-27 00:41:40 -0400838 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700839
840 if (copy_from_user(str, buffer, count))
Patrick Mocheld550d982006-06-27 00:41:40 -0400841 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700842
843 str[count] = 0;
844 state = simple_strtoul(str, NULL, 0);
Len Brown4be44fc2005-08-05 00:44:28 -0400845 state &= ((1ul << 31) | (1ul << 30) | (1ul << 0));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700846
847 status = acpi_video_device_set_state(dev, state);
848
849 if (status)
Patrick Mocheld550d982006-06-27 00:41:40 -0400850 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700851
Patrick Mocheld550d982006-06-27 00:41:40 -0400852 return count;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700853}
854
855static int
Len Brown4be44fc2005-08-05 00:44:28 -0400856acpi_video_device_brightness_seq_show(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700857{
Jan Engelhardt50dd0962006-10-01 00:28:50 +0200858 struct acpi_video_device *dev = seq->private;
Len Brown4be44fc2005-08-05 00:44:28 -0400859 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700860
Linus Torvalds1da177e2005-04-16 15:20:36 -0700861
862 if (!dev || !dev->brightness) {
863 seq_printf(seq, "<not supported>\n");
Patrick Mocheld550d982006-06-27 00:41:40 -0400864 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700865 }
866
867 seq_printf(seq, "levels: ");
868 for (i = 0; i < dev->brightness->count; i++)
869 seq_printf(seq, " %d", dev->brightness->levels[i]);
870 seq_printf(seq, "\ncurrent: %d\n", dev->brightness->curr);
871
Patrick Mocheld550d982006-06-27 00:41:40 -0400872 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700873}
874
875static int
Len Brown4be44fc2005-08-05 00:44:28 -0400876acpi_video_device_brightness_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700877{
878 return single_open(file, acpi_video_device_brightness_seq_show,
879 PDE(inode)->data);
880}
881
882static ssize_t
Len Brown4be44fc2005-08-05 00:44:28 -0400883acpi_video_device_write_brightness(struct file *file,
884 const char __user * buffer,
885 size_t count, loff_t * data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700886{
Jan Engelhardt50dd0962006-10-01 00:28:50 +0200887 struct seq_file *m = file->private_data;
888 struct acpi_video_device *dev = m->private;
Len Brown4be44fc2005-08-05 00:44:28 -0400889 char str[4] = { 0 };
890 unsigned int level = 0;
891 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700892
Linus Torvalds1da177e2005-04-16 15:20:36 -0700893
Thomas Renninger59d399d2005-11-08 05:27:00 -0500894 if (!dev || !dev->brightness || count + 1 > sizeof str)
Patrick Mocheld550d982006-06-27 00:41:40 -0400895 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700896
897 if (copy_from_user(str, buffer, count))
Patrick Mocheld550d982006-06-27 00:41:40 -0400898 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700899
900 str[count] = 0;
901 level = simple_strtoul(str, NULL, 0);
Len Brown4be44fc2005-08-05 00:44:28 -0400902
Linus Torvalds1da177e2005-04-16 15:20:36 -0700903 if (level > 100)
Patrick Mocheld550d982006-06-27 00:41:40 -0400904 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700905
Julius Volz98fb8fe2007-02-20 16:38:40 +0100906 /* validate through the list of available levels */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700907 for (i = 0; i < dev->brightness->count; i++)
908 if (level == dev->brightness->levels[i]) {
Len Brown4be44fc2005-08-05 00:44:28 -0400909 if (ACPI_SUCCESS
910 (acpi_video_device_lcd_set_level(dev, level)))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700911 dev->brightness->curr = level;
912 break;
913 }
914
Patrick Mocheld550d982006-06-27 00:41:40 -0400915 return count;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700916}
917
Len Brown4be44fc2005-08-05 00:44:28 -0400918static int acpi_video_device_EDID_seq_show(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700919{
Jan Engelhardt50dd0962006-10-01 00:28:50 +0200920 struct acpi_video_device *dev = seq->private;
Len Brown4be44fc2005-08-05 00:44:28 -0400921 int status;
922 int i;
923 union acpi_object *edid = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700924
Linus Torvalds1da177e2005-04-16 15:20:36 -0700925
926 if (!dev)
927 goto out;
928
Len Brown4be44fc2005-08-05 00:44:28 -0400929 status = acpi_video_device_EDID(dev, &edid, 128);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700930 if (ACPI_FAILURE(status)) {
Len Brown4be44fc2005-08-05 00:44:28 -0400931 status = acpi_video_device_EDID(dev, &edid, 256);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700932 }
933
934 if (ACPI_FAILURE(status)) {
935 goto out;
936 }
937
938 if (edid && edid->type == ACPI_TYPE_BUFFER) {
939 for (i = 0; i < edid->buffer.length; i++)
940 seq_putc(seq, edid->buffer.pointer[i]);
941 }
942
Len Brown4be44fc2005-08-05 00:44:28 -0400943 out:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700944 if (!edid)
945 seq_printf(seq, "<not supported>\n");
946 else
947 kfree(edid);
948
Patrick Mocheld550d982006-06-27 00:41:40 -0400949 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700950}
951
952static int
Len Brown4be44fc2005-08-05 00:44:28 -0400953acpi_video_device_EDID_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700954{
955 return single_open(file, acpi_video_device_EDID_seq_show,
956 PDE(inode)->data);
957}
958
Len Brown4be44fc2005-08-05 00:44:28 -0400959static int acpi_video_device_add_fs(struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700960{
Len Brown4be44fc2005-08-05 00:44:28 -0400961 struct proc_dir_entry *entry = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700962 struct acpi_video_device *vid_dev;
963
Linus Torvalds1da177e2005-04-16 15:20:36 -0700964
965 if (!device)
Patrick Mocheld550d982006-06-27 00:41:40 -0400966 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700967
Jan Engelhardt50dd0962006-10-01 00:28:50 +0200968 vid_dev = acpi_driver_data(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700969 if (!vid_dev)
Patrick Mocheld550d982006-06-27 00:41:40 -0400970 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700971
972 if (!acpi_device_dir(device)) {
973 acpi_device_dir(device) = proc_mkdir(acpi_device_bid(device),
Len Brown4be44fc2005-08-05 00:44:28 -0400974 vid_dev->video->dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700975 if (!acpi_device_dir(device))
Patrick Mocheld550d982006-06-27 00:41:40 -0400976 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700977 acpi_device_dir(device)->owner = THIS_MODULE;
978 }
979
980 /* 'info' [R] */
981 entry = create_proc_entry("info", S_IRUGO, acpi_device_dir(device));
982 if (!entry)
Patrick Mocheld550d982006-06-27 00:41:40 -0400983 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700984 else {
985 entry->proc_fops = &acpi_video_device_info_fops;
986 entry->data = acpi_driver_data(device);
987 entry->owner = THIS_MODULE;
988 }
989
990 /* 'state' [R/W] */
Len Brown4be44fc2005-08-05 00:44:28 -0400991 entry =
992 create_proc_entry("state", S_IFREG | S_IRUGO | S_IWUSR,
993 acpi_device_dir(device));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700994 if (!entry)
Patrick Mocheld550d982006-06-27 00:41:40 -0400995 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700996 else {
Arjan van de Vend479e902006-01-06 16:47:00 -0500997 acpi_video_device_state_fops.write = acpi_video_device_write_state;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700998 entry->proc_fops = &acpi_video_device_state_fops;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700999 entry->data = acpi_driver_data(device);
1000 entry->owner = THIS_MODULE;
1001 }
1002
1003 /* 'brightness' [R/W] */
Len Brown4be44fc2005-08-05 00:44:28 -04001004 entry =
1005 create_proc_entry("brightness", S_IFREG | S_IRUGO | S_IWUSR,
1006 acpi_device_dir(device));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001007 if (!entry)
Patrick Mocheld550d982006-06-27 00:41:40 -04001008 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001009 else {
Arjan van de Vend479e902006-01-06 16:47:00 -05001010 acpi_video_device_brightness_fops.write = acpi_video_device_write_brightness;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001011 entry->proc_fops = &acpi_video_device_brightness_fops;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001012 entry->data = acpi_driver_data(device);
1013 entry->owner = THIS_MODULE;
1014 }
1015
1016 /* 'EDID' [R] */
1017 entry = create_proc_entry("EDID", S_IRUGO, acpi_device_dir(device));
1018 if (!entry)
Patrick Mocheld550d982006-06-27 00:41:40 -04001019 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001020 else {
1021 entry->proc_fops = &acpi_video_device_EDID_fops;
1022 entry->data = acpi_driver_data(device);
1023 entry->owner = THIS_MODULE;
1024 }
1025
Patrick Mocheld550d982006-06-27 00:41:40 -04001026 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001027}
1028
Len Brown4be44fc2005-08-05 00:44:28 -04001029static int acpi_video_device_remove_fs(struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001030{
1031 struct acpi_video_device *vid_dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001032
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001033 vid_dev = acpi_driver_data(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001034 if (!vid_dev || !vid_dev->video || !vid_dev->video->dir)
Patrick Mocheld550d982006-06-27 00:41:40 -04001035 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001036
1037 if (acpi_device_dir(device)) {
1038 remove_proc_entry("info", acpi_device_dir(device));
1039 remove_proc_entry("state", acpi_device_dir(device));
1040 remove_proc_entry("brightness", acpi_device_dir(device));
1041 remove_proc_entry("EDID", acpi_device_dir(device));
Len Brown4be44fc2005-08-05 00:44:28 -04001042 remove_proc_entry(acpi_device_bid(device), vid_dev->video->dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001043 acpi_device_dir(device) = NULL;
1044 }
1045
Patrick Mocheld550d982006-06-27 00:41:40 -04001046 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001047}
1048
Linus Torvalds1da177e2005-04-16 15:20:36 -07001049/* video bus */
Len Brown4be44fc2005-08-05 00:44:28 -04001050static int acpi_video_bus_info_seq_show(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001051{
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001052 struct acpi_video_bus *video = seq->private;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001053
Linus Torvalds1da177e2005-04-16 15:20:36 -07001054
1055 if (!video)
1056 goto end;
1057
1058 seq_printf(seq, "Switching heads: %s\n",
Len Brown4be44fc2005-08-05 00:44:28 -04001059 video->flags.multihead ? "yes" : "no");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001060 seq_printf(seq, "Video ROM: %s\n",
Len Brown4be44fc2005-08-05 00:44:28 -04001061 video->flags.rom ? "yes" : "no");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001062 seq_printf(seq, "Device to be POSTed on boot: %s\n",
Len Brown4be44fc2005-08-05 00:44:28 -04001063 video->flags.post ? "yes" : "no");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001064
Len Brown4be44fc2005-08-05 00:44:28 -04001065 end:
Patrick Mocheld550d982006-06-27 00:41:40 -04001066 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001067}
1068
Len Brown4be44fc2005-08-05 00:44:28 -04001069static int acpi_video_bus_info_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001070{
Len Brown4be44fc2005-08-05 00:44:28 -04001071 return single_open(file, acpi_video_bus_info_seq_show,
1072 PDE(inode)->data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001073}
1074
Len Brown4be44fc2005-08-05 00:44:28 -04001075static int acpi_video_bus_ROM_seq_show(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001076{
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001077 struct acpi_video_bus *video = seq->private;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001078
Linus Torvalds1da177e2005-04-16 15:20:36 -07001079
1080 if (!video)
1081 goto end;
1082
1083 printk(KERN_INFO PREFIX "Please implement %s\n", __FUNCTION__);
1084 seq_printf(seq, "<TODO>\n");
1085
Len Brown4be44fc2005-08-05 00:44:28 -04001086 end:
Patrick Mocheld550d982006-06-27 00:41:40 -04001087 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001088}
1089
Len Brown4be44fc2005-08-05 00:44:28 -04001090static int acpi_video_bus_ROM_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001091{
1092 return single_open(file, acpi_video_bus_ROM_seq_show, PDE(inode)->data);
1093}
1094
Len Brown4be44fc2005-08-05 00:44:28 -04001095static int acpi_video_bus_POST_info_seq_show(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001096{
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001097 struct acpi_video_bus *video = seq->private;
Len Brown4be44fc2005-08-05 00:44:28 -04001098 unsigned long options;
1099 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001100
Linus Torvalds1da177e2005-04-16 15:20:36 -07001101
1102 if (!video)
1103 goto end;
1104
1105 status = acpi_video_bus_POST_options(video, &options);
1106 if (ACPI_SUCCESS(status)) {
1107 if (!(options & 1)) {
Len Brown4be44fc2005-08-05 00:44:28 -04001108 printk(KERN_WARNING PREFIX
1109 "The motherboard VGA device is not listed as a possible POST device.\n");
1110 printk(KERN_WARNING PREFIX
Julius Volz98fb8fe2007-02-20 16:38:40 +01001111 "This indicates a BIOS bug. Please contact the manufacturer.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001112 }
1113 printk("%lx\n", options);
Julius Volz98fb8fe2007-02-20 16:38:40 +01001114 seq_printf(seq, "can POST: <integrated video>");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001115 if (options & 2)
1116 seq_printf(seq, " <PCI video>");
1117 if (options & 4)
1118 seq_printf(seq, " <AGP video>");
1119 seq_putc(seq, '\n');
1120 } else
1121 seq_printf(seq, "<not supported>\n");
Len Brown4be44fc2005-08-05 00:44:28 -04001122 end:
Patrick Mocheld550d982006-06-27 00:41:40 -04001123 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001124}
1125
1126static int
Len Brown4be44fc2005-08-05 00:44:28 -04001127acpi_video_bus_POST_info_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001128{
Len Brown4be44fc2005-08-05 00:44:28 -04001129 return single_open(file, acpi_video_bus_POST_info_seq_show,
1130 PDE(inode)->data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001131}
1132
Len Brown4be44fc2005-08-05 00:44:28 -04001133static int acpi_video_bus_POST_seq_show(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001134{
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001135 struct acpi_video_bus *video = seq->private;
Len Brown4be44fc2005-08-05 00:44:28 -04001136 int status;
1137 unsigned long id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001138
Linus Torvalds1da177e2005-04-16 15:20:36 -07001139
1140 if (!video)
1141 goto end;
1142
Len Brown4be44fc2005-08-05 00:44:28 -04001143 status = acpi_video_bus_get_POST(video, &id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001144 if (!ACPI_SUCCESS(status)) {
1145 seq_printf(seq, "<not supported>\n");
1146 goto end;
1147 }
Julius Volz98fb8fe2007-02-20 16:38:40 +01001148 seq_printf(seq, "device POSTed is <%s>\n", device_decode[id & 3]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001149
Len Brown4be44fc2005-08-05 00:44:28 -04001150 end:
Patrick Mocheld550d982006-06-27 00:41:40 -04001151 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001152}
1153
Len Brown4be44fc2005-08-05 00:44:28 -04001154static int acpi_video_bus_DOS_seq_show(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001155{
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001156 struct acpi_video_bus *video = seq->private;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001157
Linus Torvalds1da177e2005-04-16 15:20:36 -07001158
Len Brown4be44fc2005-08-05 00:44:28 -04001159 seq_printf(seq, "DOS setting: <%d>\n", video->dos_setting);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001160
Patrick Mocheld550d982006-06-27 00:41:40 -04001161 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001162}
1163
Len Brown4be44fc2005-08-05 00:44:28 -04001164static int acpi_video_bus_POST_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001165{
Len Brown4be44fc2005-08-05 00:44:28 -04001166 return single_open(file, acpi_video_bus_POST_seq_show,
1167 PDE(inode)->data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001168}
1169
Len Brown4be44fc2005-08-05 00:44:28 -04001170static int acpi_video_bus_DOS_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001171{
1172 return single_open(file, acpi_video_bus_DOS_seq_show, PDE(inode)->data);
1173}
1174
1175static ssize_t
Len Brown4be44fc2005-08-05 00:44:28 -04001176acpi_video_bus_write_POST(struct file *file,
1177 const char __user * buffer,
1178 size_t count, loff_t * data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001179{
Len Brown4be44fc2005-08-05 00:44:28 -04001180 int status;
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001181 struct seq_file *m = file->private_data;
1182 struct acpi_video_bus *video = m->private;
Len Brown4be44fc2005-08-05 00:44:28 -04001183 char str[12] = { 0 };
1184 unsigned long opt, options;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001185
Linus Torvalds1da177e2005-04-16 15:20:36 -07001186
Linus Torvalds1da177e2005-04-16 15:20:36 -07001187 if (!video || count + 1 > sizeof str)
Patrick Mocheld550d982006-06-27 00:41:40 -04001188 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001189
1190 status = acpi_video_bus_POST_options(video, &options);
1191 if (!ACPI_SUCCESS(status))
Patrick Mocheld550d982006-06-27 00:41:40 -04001192 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001193
1194 if (copy_from_user(str, buffer, count))
Patrick Mocheld550d982006-06-27 00:41:40 -04001195 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001196
1197 str[count] = 0;
1198 opt = strtoul(str, NULL, 0);
1199 if (opt > 3)
Patrick Mocheld550d982006-06-27 00:41:40 -04001200 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001201
Julius Volz98fb8fe2007-02-20 16:38:40 +01001202 /* just in case an OEM 'forgot' the motherboard... */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001203 options |= 1;
1204
1205 if (options & (1ul << opt)) {
Len Brown4be44fc2005-08-05 00:44:28 -04001206 status = acpi_video_bus_set_POST(video, opt);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001207 if (!ACPI_SUCCESS(status))
Patrick Mocheld550d982006-06-27 00:41:40 -04001208 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001209
1210 }
1211
Patrick Mocheld550d982006-06-27 00:41:40 -04001212 return count;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001213}
1214
1215static ssize_t
Len Brown4be44fc2005-08-05 00:44:28 -04001216acpi_video_bus_write_DOS(struct file *file,
1217 const char __user * buffer,
1218 size_t count, loff_t * data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001219{
Len Brown4be44fc2005-08-05 00:44:28 -04001220 int status;
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001221 struct seq_file *m = file->private_data;
1222 struct acpi_video_bus *video = m->private;
Len Brown4be44fc2005-08-05 00:44:28 -04001223 char str[12] = { 0 };
1224 unsigned long opt;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001225
Linus Torvalds1da177e2005-04-16 15:20:36 -07001226
Linus Torvalds1da177e2005-04-16 15:20:36 -07001227 if (!video || count + 1 > sizeof str)
Patrick Mocheld550d982006-06-27 00:41:40 -04001228 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001229
1230 if (copy_from_user(str, buffer, count))
Patrick Mocheld550d982006-06-27 00:41:40 -04001231 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001232
1233 str[count] = 0;
1234 opt = strtoul(str, NULL, 0);
1235 if (opt > 7)
Patrick Mocheld550d982006-06-27 00:41:40 -04001236 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001237
Len Brown4be44fc2005-08-05 00:44:28 -04001238 status = acpi_video_bus_DOS(video, opt & 0x3, (opt & 0x4) >> 2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001239
1240 if (!ACPI_SUCCESS(status))
Patrick Mocheld550d982006-06-27 00:41:40 -04001241 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001242
Patrick Mocheld550d982006-06-27 00:41:40 -04001243 return count;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001244}
1245
Len Brown4be44fc2005-08-05 00:44:28 -04001246static int acpi_video_bus_add_fs(struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001247{
Len Brown4be44fc2005-08-05 00:44:28 -04001248 struct proc_dir_entry *entry = NULL;
1249 struct acpi_video_bus *video;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001250
Linus Torvalds1da177e2005-04-16 15:20:36 -07001251
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001252 video = acpi_driver_data(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001253
1254 if (!acpi_device_dir(device)) {
1255 acpi_device_dir(device) = proc_mkdir(acpi_device_bid(device),
Len Brown4be44fc2005-08-05 00:44:28 -04001256 acpi_video_dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001257 if (!acpi_device_dir(device))
Patrick Mocheld550d982006-06-27 00:41:40 -04001258 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001259 video->dir = acpi_device_dir(device);
1260 acpi_device_dir(device)->owner = THIS_MODULE;
1261 }
1262
1263 /* 'info' [R] */
1264 entry = create_proc_entry("info", S_IRUGO, acpi_device_dir(device));
1265 if (!entry)
Patrick Mocheld550d982006-06-27 00:41:40 -04001266 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001267 else {
1268 entry->proc_fops = &acpi_video_bus_info_fops;
1269 entry->data = acpi_driver_data(device);
1270 entry->owner = THIS_MODULE;
1271 }
1272
1273 /* 'ROM' [R] */
1274 entry = create_proc_entry("ROM", S_IRUGO, acpi_device_dir(device));
1275 if (!entry)
Patrick Mocheld550d982006-06-27 00:41:40 -04001276 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001277 else {
1278 entry->proc_fops = &acpi_video_bus_ROM_fops;
1279 entry->data = acpi_driver_data(device);
1280 entry->owner = THIS_MODULE;
1281 }
1282
1283 /* 'POST_info' [R] */
Len Brown4be44fc2005-08-05 00:44:28 -04001284 entry =
1285 create_proc_entry("POST_info", S_IRUGO, acpi_device_dir(device));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001286 if (!entry)
Patrick Mocheld550d982006-06-27 00:41:40 -04001287 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001288 else {
1289 entry->proc_fops = &acpi_video_bus_POST_info_fops;
1290 entry->data = acpi_driver_data(device);
1291 entry->owner = THIS_MODULE;
1292 }
1293
1294 /* 'POST' [R/W] */
Len Brown4be44fc2005-08-05 00:44:28 -04001295 entry =
1296 create_proc_entry("POST", S_IFREG | S_IRUGO | S_IRUSR,
1297 acpi_device_dir(device));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001298 if (!entry)
Patrick Mocheld550d982006-06-27 00:41:40 -04001299 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001300 else {
Arjan van de Vend479e902006-01-06 16:47:00 -05001301 acpi_video_bus_POST_fops.write = acpi_video_bus_write_POST;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001302 entry->proc_fops = &acpi_video_bus_POST_fops;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001303 entry->data = acpi_driver_data(device);
1304 entry->owner = THIS_MODULE;
1305 }
1306
1307 /* 'DOS' [R/W] */
Len Brown4be44fc2005-08-05 00:44:28 -04001308 entry =
1309 create_proc_entry("DOS", S_IFREG | S_IRUGO | S_IRUSR,
1310 acpi_device_dir(device));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001311 if (!entry)
Patrick Mocheld550d982006-06-27 00:41:40 -04001312 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001313 else {
Arjan van de Vend479e902006-01-06 16:47:00 -05001314 acpi_video_bus_DOS_fops.write = acpi_video_bus_write_DOS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001315 entry->proc_fops = &acpi_video_bus_DOS_fops;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001316 entry->data = acpi_driver_data(device);
1317 entry->owner = THIS_MODULE;
1318 }
1319
Patrick Mocheld550d982006-06-27 00:41:40 -04001320 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001321}
1322
Len Brown4be44fc2005-08-05 00:44:28 -04001323static int acpi_video_bus_remove_fs(struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001324{
Len Brown4be44fc2005-08-05 00:44:28 -04001325 struct acpi_video_bus *video;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001326
Linus Torvalds1da177e2005-04-16 15:20:36 -07001327
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001328 video = acpi_driver_data(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001329
1330 if (acpi_device_dir(device)) {
1331 remove_proc_entry("info", acpi_device_dir(device));
1332 remove_proc_entry("ROM", acpi_device_dir(device));
1333 remove_proc_entry("POST_info", acpi_device_dir(device));
1334 remove_proc_entry("POST", acpi_device_dir(device));
1335 remove_proc_entry("DOS", acpi_device_dir(device));
Len Brown4be44fc2005-08-05 00:44:28 -04001336 remove_proc_entry(acpi_device_bid(device), acpi_video_dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001337 acpi_device_dir(device) = NULL;
1338 }
1339
Patrick Mocheld550d982006-06-27 00:41:40 -04001340 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001341}
1342
1343/* --------------------------------------------------------------------------
1344 Driver Interface
1345 -------------------------------------------------------------------------- */
1346
1347/* device interface */
Rui Zhang82cae992007-01-03 23:40:53 -05001348static struct acpi_video_device_attrib*
1349acpi_video_get_device_attr(struct acpi_video_bus *video, unsigned long device_id)
1350{
1351 int count;
1352
1353 for(count = 0; count < video->attached_count; count++)
1354 if((video->attached_array[count].value.int_val & 0xffff) == device_id)
1355 return &(video->attached_array[count].value.attrib);
1356 return NULL;
1357}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001358
1359static int
Len Brown4be44fc2005-08-05 00:44:28 -04001360acpi_video_bus_get_one_device(struct acpi_device *device,
1361 struct acpi_video_bus *video)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001362{
Len Brown4be44fc2005-08-05 00:44:28 -04001363 unsigned long device_id;
Yu, Luming973bf492006-04-27 05:25:00 -04001364 int status;
Len Brown4be44fc2005-08-05 00:44:28 -04001365 struct acpi_video_device *data;
Rui Zhang82cae992007-01-03 23:40:53 -05001366 struct acpi_video_device_attrib* attribute;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001367
1368 if (!device || !video)
Patrick Mocheld550d982006-06-27 00:41:40 -04001369 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001370
Len Brown4be44fc2005-08-05 00:44:28 -04001371 status =
1372 acpi_evaluate_integer(device->handle, "_ADR", NULL, &device_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001373 if (ACPI_SUCCESS(status)) {
1374
Burman Yan36bcbec2006-12-19 12:56:11 -08001375 data = kzalloc(sizeof(struct acpi_video_device), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001376 if (!data)
Patrick Mocheld550d982006-06-27 00:41:40 -04001377 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001378
Linus Torvalds1da177e2005-04-16 15:20:36 -07001379 strcpy(acpi_device_name(device), ACPI_VIDEO_DEVICE_NAME);
1380 strcpy(acpi_device_class(device), ACPI_VIDEO_CLASS);
1381 acpi_driver_data(device) = data;
1382
1383 data->device_id = device_id;
1384 data->video = video;
1385 data->dev = device;
1386
Rui Zhang82cae992007-01-03 23:40:53 -05001387 attribute = acpi_video_get_device_attr(video, device_id);
1388
1389 if((attribute != NULL) && attribute->device_id_scheme) {
1390 switch (attribute->display_type) {
1391 case ACPI_VIDEO_DISPLAY_CRT:
1392 data->flags.crt = 1;
1393 break;
1394 case ACPI_VIDEO_DISPLAY_TV:
1395 data->flags.tvout = 1;
1396 break;
1397 case ACPI_VIDEO_DISPLAY_DVI:
1398 data->flags.dvi = 1;
1399 break;
1400 case ACPI_VIDEO_DISPLAY_LCD:
1401 data->flags.lcd = 1;
1402 break;
1403 default:
1404 data->flags.unknown = 1;
1405 break;
1406 }
1407 if(attribute->bios_can_detect)
1408 data->flags.bios = 1;
1409 } else
Linus Torvalds1da177e2005-04-16 15:20:36 -07001410 data->flags.unknown = 1;
Len Brown4be44fc2005-08-05 00:44:28 -04001411
Linus Torvalds1da177e2005-04-16 15:20:36 -07001412 acpi_video_device_bind(video, data);
1413 acpi_video_device_find_cap(data);
1414
Patrick Mochel90130262006-05-19 16:54:48 -04001415 status = acpi_install_notify_handler(device->handle,
Len Brown4be44fc2005-08-05 00:44:28 -04001416 ACPI_DEVICE_NOTIFY,
1417 acpi_video_device_notify,
1418 data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001419 if (ACPI_FAILURE(status)) {
1420 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
Len Brown4be44fc2005-08-05 00:44:28 -04001421 "Error installing notify handler\n"));
Yu, Luming973bf492006-04-27 05:25:00 -04001422 if(data->brightness)
1423 kfree(data->brightness->levels);
1424 kfree(data->brightness);
1425 kfree(data);
1426 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001427 }
1428
1429 down(&video->sem);
1430 list_add_tail(&data->entry, &video->video_device_list);
1431 up(&video->sem);
1432
1433 acpi_video_device_add_fs(device);
1434
Patrick Mocheld550d982006-06-27 00:41:40 -04001435 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001436 }
1437
Patrick Mocheld550d982006-06-27 00:41:40 -04001438 return -ENOENT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001439}
1440
1441/*
1442 * Arg:
1443 * video : video bus device
1444 *
1445 * Return:
1446 * none
1447 *
1448 * Enumerate the video device list of the video bus,
1449 * bind the ids with the corresponding video devices
1450 * under the video bus.
Len Brown4be44fc2005-08-05 00:44:28 -04001451 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001452
Len Brown4be44fc2005-08-05 00:44:28 -04001453static void acpi_video_device_rebind(struct acpi_video_bus *video)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001454{
Len Brown4be44fc2005-08-05 00:44:28 -04001455 struct list_head *node, *next;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001456 list_for_each_safe(node, next, &video->video_device_list) {
Len Brown4be44fc2005-08-05 00:44:28 -04001457 struct acpi_video_device *dev =
1458 container_of(node, struct acpi_video_device, entry);
1459 acpi_video_device_bind(video, dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001460 }
1461}
1462
1463/*
1464 * Arg:
1465 * video : video bus device
1466 * device : video output device under the video
1467 * bus
1468 *
1469 * Return:
1470 * none
1471 *
1472 * Bind the ids with the corresponding video devices
1473 * under the video bus.
Len Brown4be44fc2005-08-05 00:44:28 -04001474 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001475
1476static void
Len Brown4be44fc2005-08-05 00:44:28 -04001477acpi_video_device_bind(struct acpi_video_bus *video,
1478 struct acpi_video_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001479{
Len Brown4be44fc2005-08-05 00:44:28 -04001480 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001481
1482#define IDS_VAL(i) video->attached_array[i].value.int_val
1483#define IDS_BIND(i) video->attached_array[i].bind_info
Len Brown4be44fc2005-08-05 00:44:28 -04001484
1485 for (i = 0; IDS_VAL(i) != ACPI_VIDEO_HEAD_INVALID &&
1486 i < video->attached_count; i++) {
1487 if (device->device_id == (IDS_VAL(i) & 0xffff)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001488 IDS_BIND(i) = device;
1489 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "device_bind %d\n", i));
1490 }
1491 }
1492#undef IDS_VAL
1493#undef IDS_BIND
1494}
1495
1496/*
1497 * Arg:
1498 * video : video bus device
1499 *
1500 * Return:
1501 * < 0 : error
1502 *
1503 * Call _DOD to enumerate all devices attached to display adapter
1504 *
Len Brown4be44fc2005-08-05 00:44:28 -04001505 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001506
1507static int acpi_video_device_enumerate(struct acpi_video_bus *video)
1508{
Len Brown4be44fc2005-08-05 00:44:28 -04001509 int status;
1510 int count;
1511 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001512 struct acpi_video_enumerated_device *active_device_list;
Len Brown4be44fc2005-08-05 00:44:28 -04001513 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
1514 union acpi_object *dod = NULL;
1515 union acpi_object *obj;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001516
Patrick Mochel90130262006-05-19 16:54:48 -04001517 status = acpi_evaluate_object(video->device->handle, "_DOD", NULL, &buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001518 if (!ACPI_SUCCESS(status)) {
Thomas Renningera6fc6722006-06-26 23:58:43 -04001519 ACPI_EXCEPTION((AE_INFO, status, "Evaluating _DOD"));
Patrick Mocheld550d982006-06-27 00:41:40 -04001520 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001521 }
1522
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001523 dod = buffer.pointer;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001524 if (!dod || (dod->type != ACPI_TYPE_PACKAGE)) {
Thomas Renningera6fc6722006-06-26 23:58:43 -04001525 ACPI_EXCEPTION((AE_INFO, status, "Invalid _DOD data"));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001526 status = -EFAULT;
1527 goto out;
1528 }
1529
1530 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found %d video heads in _DOD\n",
Len Brown4be44fc2005-08-05 00:44:28 -04001531 dod->package.count));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001532
Len Brown4be44fc2005-08-05 00:44:28 -04001533 active_device_list = kmalloc((1 +
1534 dod->package.count) *
1535 sizeof(struct
1536 acpi_video_enumerated_device),
1537 GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001538
1539 if (!active_device_list) {
1540 status = -ENOMEM;
1541 goto out;
1542 }
1543
1544 count = 0;
1545 for (i = 0; i < dod->package.count; i++) {
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001546 obj = &dod->package.elements[i];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001547
1548 if (obj->type != ACPI_TYPE_INTEGER) {
Len Brown64684632006-06-26 23:41:38 -04001549 printk(KERN_ERR PREFIX "Invalid _DOD data\n");
Len Brown4be44fc2005-08-05 00:44:28 -04001550 active_device_list[i].value.int_val =
1551 ACPI_VIDEO_HEAD_INVALID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001552 }
1553 active_device_list[i].value.int_val = obj->integer.value;
1554 active_device_list[i].bind_info = NULL;
Len Brown4be44fc2005-08-05 00:44:28 -04001555 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "dod element[%d] = %d\n", i,
1556 (int)obj->integer.value));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001557 count++;
1558 }
1559 active_device_list[count].value.int_val = ACPI_VIDEO_HEAD_END;
1560
Jesper Juhl6044ec82005-11-07 01:01:32 -08001561 kfree(video->attached_array);
Len Brown4be44fc2005-08-05 00:44:28 -04001562
Linus Torvalds1da177e2005-04-16 15:20:36 -07001563 video->attached_array = active_device_list;
1564 video->attached_count = count;
Len Brown4be44fc2005-08-05 00:44:28 -04001565 out:
Len Brown02438d82006-06-30 03:19:10 -04001566 kfree(buffer.pointer);
Patrick Mocheld550d982006-06-27 00:41:40 -04001567 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001568}
1569
1570/*
1571 * Arg:
1572 * video : video bus device
Julius Volz98fb8fe2007-02-20 16:38:40 +01001573 * event : notify event
Linus Torvalds1da177e2005-04-16 15:20:36 -07001574 *
1575 * Return:
1576 * < 0 : error
1577 *
1578 * 1. Find out the current active output device.
Julius Volz98fb8fe2007-02-20 16:38:40 +01001579 * 2. Identify the next output device to switch to.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001580 * 3. call _DSS to do actual switch.
Len Brown4be44fc2005-08-05 00:44:28 -04001581 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001582
Len Brown4be44fc2005-08-05 00:44:28 -04001583static int acpi_video_switch_output(struct acpi_video_bus *video, int event)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001584{
Len Brown4be44fc2005-08-05 00:44:28 -04001585 struct list_head *node, *next;
1586 struct acpi_video_device *dev = NULL;
1587 struct acpi_video_device *dev_next = NULL;
1588 struct acpi_video_device *dev_prev = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001589 unsigned long state;
1590 int status = 0;
1591
Linus Torvalds1da177e2005-04-16 15:20:36 -07001592
1593 list_for_each_safe(node, next, &video->video_device_list) {
Adrian Bunk73345712005-03-30 22:31:35 -05001594 dev = container_of(node, struct acpi_video_device, entry);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001595 status = acpi_video_device_get_state(dev, &state);
Len Brown4be44fc2005-08-05 00:44:28 -04001596 if (state & 0x2) {
1597 dev_next =
1598 container_of(node->next, struct acpi_video_device,
1599 entry);
1600 dev_prev =
1601 container_of(node->prev, struct acpi_video_device,
1602 entry);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001603 goto out;
1604 }
1605 }
1606 dev_next = container_of(node->next, struct acpi_video_device, entry);
1607 dev_prev = container_of(node->prev, struct acpi_video_device, entry);
Len Brown4be44fc2005-08-05 00:44:28 -04001608 out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001609 switch (event) {
1610 case ACPI_VIDEO_NOTIFY_CYCLE:
1611 case ACPI_VIDEO_NOTIFY_NEXT_OUTPUT:
1612 acpi_video_device_set_state(dev, 0);
1613 acpi_video_device_set_state(dev_next, 0x80000001);
1614 break;
1615 case ACPI_VIDEO_NOTIFY_PREV_OUTPUT:
1616 acpi_video_device_set_state(dev, 0);
1617 acpi_video_device_set_state(dev_prev, 0x80000001);
1618 default:
1619 break;
1620 }
1621
Patrick Mocheld550d982006-06-27 00:41:40 -04001622 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001623}
1624
Len Brown4be44fc2005-08-05 00:44:28 -04001625static int
1626acpi_video_get_next_level(struct acpi_video_device *device,
1627 u32 level_current, u32 event)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001628{
Thomas Tuttlef4715182006-12-19 12:56:14 -08001629 int min, max, min_above, max_below, i, l;
1630 max = max_below = 0;
1631 min = min_above = 255;
1632 for (i = 0; i < device->brightness->count; i++) {
1633 l = device->brightness->levels[i];
1634 if (l < min)
1635 min = l;
1636 if (l > max)
1637 max = l;
1638 if (l < min_above && l > level_current)
1639 min_above = l;
1640 if (l > max_below && l < level_current)
1641 max_below = l;
1642 }
1643
1644 switch (event) {
1645 case ACPI_VIDEO_NOTIFY_CYCLE_BRIGHTNESS:
1646 return (level_current < max) ? min_above : min;
1647 case ACPI_VIDEO_NOTIFY_INC_BRIGHTNESS:
1648 return (level_current < max) ? min_above : max;
1649 case ACPI_VIDEO_NOTIFY_DEC_BRIGHTNESS:
1650 return (level_current > min) ? max_below : min;
1651 case ACPI_VIDEO_NOTIFY_ZERO_BRIGHTNESS:
1652 case ACPI_VIDEO_NOTIFY_DISPLAY_OFF:
1653 return 0;
1654 default:
1655 return level_current;
1656 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001657}
1658
Linus Torvalds1da177e2005-04-16 15:20:36 -07001659static void
Len Brown4be44fc2005-08-05 00:44:28 -04001660acpi_video_switch_brightness(struct acpi_video_device *device, int event)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001661{
1662 unsigned long level_current, level_next;
1663 acpi_video_device_lcd_get_level_current(device, &level_current);
1664 level_next = acpi_video_get_next_level(device, level_current, event);
1665 acpi_video_device_lcd_set_level(device, level_next);
1666}
1667
1668static int
Len Brown4be44fc2005-08-05 00:44:28 -04001669acpi_video_bus_get_devices(struct acpi_video_bus *video,
1670 struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001671{
Len Brown4be44fc2005-08-05 00:44:28 -04001672 int status = 0;
1673 struct list_head *node, *next;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001674
Linus Torvalds1da177e2005-04-16 15:20:36 -07001675
1676 acpi_video_device_enumerate(video);
1677
1678 list_for_each_safe(node, next, &device->children) {
Len Brown4be44fc2005-08-05 00:44:28 -04001679 struct acpi_device *dev =
1680 list_entry(node, struct acpi_device, node);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001681
1682 if (!dev)
1683 continue;
1684
1685 status = acpi_video_bus_get_one_device(dev, video);
1686 if (ACPI_FAILURE(status)) {
Thomas Renningera6fc6722006-06-26 23:58:43 -04001687 ACPI_EXCEPTION((AE_INFO, status, "Cant attach device"));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001688 continue;
1689 }
1690
1691 }
Patrick Mocheld550d982006-06-27 00:41:40 -04001692 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001693}
1694
Len Brown4be44fc2005-08-05 00:44:28 -04001695static int acpi_video_bus_put_one_device(struct acpi_video_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001696{
Karol Kozimor031ec772005-07-30 04:18:00 -04001697 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001698 struct acpi_video_bus *video;
1699
Linus Torvalds1da177e2005-04-16 15:20:36 -07001700
1701 if (!device || !device->video)
Patrick Mocheld550d982006-06-27 00:41:40 -04001702 return -ENOENT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001703
1704 video = device->video;
1705
1706 down(&video->sem);
1707 list_del(&device->entry);
1708 up(&video->sem);
1709 acpi_video_device_remove_fs(device->dev);
1710
Patrick Mochel90130262006-05-19 16:54:48 -04001711 status = acpi_remove_notify_handler(device->dev->handle,
Len Brown4be44fc2005-08-05 00:44:28 -04001712 ACPI_DEVICE_NOTIFY,
1713 acpi_video_device_notify);
Richard Purdie599a52d2007-02-10 23:07:48 +00001714 backlight_device_unregister(device->backlight);
Luming Yu23b0f012007-05-09 21:07:05 +08001715 video_output_unregister(device->output_dev);
Patrick Mocheld550d982006-06-27 00:41:40 -04001716 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001717}
1718
Len Brown4be44fc2005-08-05 00:44:28 -04001719static int acpi_video_bus_put_devices(struct acpi_video_bus *video)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001720{
Len Brown4be44fc2005-08-05 00:44:28 -04001721 int status;
1722 struct list_head *node, *next;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001723
Linus Torvalds1da177e2005-04-16 15:20:36 -07001724
1725 list_for_each_safe(node, next, &video->video_device_list) {
Len Brown4be44fc2005-08-05 00:44:28 -04001726 struct acpi_video_device *data =
1727 list_entry(node, struct acpi_video_device, entry);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001728 if (!data)
1729 continue;
1730
1731 status = acpi_video_bus_put_one_device(data);
Len Brown4be44fc2005-08-05 00:44:28 -04001732 if (ACPI_FAILURE(status))
1733 printk(KERN_WARNING PREFIX
1734 "hhuuhhuu bug in acpi video driver.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001735
Dave Jonesd384ea62006-06-24 00:33:08 -04001736 if (data->brightness)
Yu, Luming973bf492006-04-27 05:25:00 -04001737 kfree(data->brightness->levels);
Jesper Juhl6044ec82005-11-07 01:01:32 -08001738 kfree(data->brightness);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001739 kfree(data);
1740 }
1741
Patrick Mocheld550d982006-06-27 00:41:40 -04001742 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001743}
1744
1745/* acpi_video interface */
1746
Len Brown4be44fc2005-08-05 00:44:28 -04001747static int acpi_video_bus_start_devices(struct acpi_video_bus *video)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001748{
1749 return acpi_video_bus_DOS(video, 1, 0);
1750}
1751
Len Brown4be44fc2005-08-05 00:44:28 -04001752static int acpi_video_bus_stop_devices(struct acpi_video_bus *video)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001753{
1754 return acpi_video_bus_DOS(video, 0, 1);
1755}
1756
Len Brown4be44fc2005-08-05 00:44:28 -04001757static void acpi_video_bus_notify(acpi_handle handle, u32 event, void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001758{
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001759 struct acpi_video_bus *video = data;
Len Brown4be44fc2005-08-05 00:44:28 -04001760 struct acpi_device *device = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001761
Linus Torvalds1da177e2005-04-16 15:20:36 -07001762 printk("video bus notify\n");
1763
1764 if (!video)
Patrick Mocheld550d982006-06-27 00:41:40 -04001765 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001766
Patrick Mochele6afa0d2006-05-19 16:54:40 -04001767 device = video->device;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001768
1769 switch (event) {
Julius Volz98fb8fe2007-02-20 16:38:40 +01001770 case ACPI_VIDEO_NOTIFY_SWITCH: /* User requested a switch,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001771 * most likely via hotkey. */
1772 acpi_bus_generate_event(device, event, 0);
1773 break;
1774
Julius Volz98fb8fe2007-02-20 16:38:40 +01001775 case ACPI_VIDEO_NOTIFY_PROBE: /* User plugged in or removed a video
Linus Torvalds1da177e2005-04-16 15:20:36 -07001776 * connector. */
1777 acpi_video_device_enumerate(video);
1778 acpi_video_device_rebind(video);
1779 acpi_video_switch_output(video, event);
1780 acpi_bus_generate_event(device, event, 0);
1781 break;
1782
Len Brown4be44fc2005-08-05 00:44:28 -04001783 case ACPI_VIDEO_NOTIFY_CYCLE: /* Cycle Display output hotkey pressed. */
1784 case ACPI_VIDEO_NOTIFY_NEXT_OUTPUT: /* Next Display output hotkey pressed. */
1785 case ACPI_VIDEO_NOTIFY_PREV_OUTPUT: /* previous Display output hotkey pressed. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001786 acpi_video_switch_output(video, event);
1787 acpi_bus_generate_event(device, event, 0);
1788 break;
1789
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 }
1795
Patrick Mocheld550d982006-06-27 00:41:40 -04001796 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001797}
1798
Len Brown4be44fc2005-08-05 00:44:28 -04001799static void acpi_video_device_notify(acpi_handle handle, u32 event, void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001800{
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001801 struct acpi_video_device *video_device = data;
Len Brown4be44fc2005-08-05 00:44:28 -04001802 struct acpi_device *device = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001803
Linus Torvalds1da177e2005-04-16 15:20:36 -07001804 if (!video_device)
Patrick Mocheld550d982006-06-27 00:41:40 -04001805 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001806
Patrick Mochele6afa0d2006-05-19 16:54:40 -04001807 device = video_device->dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001808
1809 switch (event) {
Len Brown4be44fc2005-08-05 00:44:28 -04001810 case ACPI_VIDEO_NOTIFY_SWITCH: /* change in status (cycle output device) */
1811 case ACPI_VIDEO_NOTIFY_PROBE: /* change in status (output device status) */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001812 acpi_bus_generate_event(device, event, 0);
1813 break;
Len Brown4be44fc2005-08-05 00:44:28 -04001814 case ACPI_VIDEO_NOTIFY_CYCLE_BRIGHTNESS: /* Cycle brightness */
1815 case ACPI_VIDEO_NOTIFY_INC_BRIGHTNESS: /* Increase brightness */
1816 case ACPI_VIDEO_NOTIFY_DEC_BRIGHTNESS: /* Decrease brightness */
1817 case ACPI_VIDEO_NOTIFY_ZERO_BRIGHTNESS: /* zero brightnesss */
1818 case ACPI_VIDEO_NOTIFY_DISPLAY_OFF: /* display device off */
1819 acpi_video_switch_brightness(video_device, event);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001820 acpi_bus_generate_event(device, event, 0);
1821 break;
1822 default:
1823 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
Len Brown4be44fc2005-08-05 00:44:28 -04001824 "Unsupported event [0x%x]\n", event));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001825 break;
1826 }
Patrick Mocheld550d982006-06-27 00:41:40 -04001827 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001828}
1829
Len Brown4be44fc2005-08-05 00:44:28 -04001830static int acpi_video_bus_add(struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001831{
Len Brown4be44fc2005-08-05 00:44:28 -04001832 int result = 0;
1833 acpi_status status = 0;
1834 struct acpi_video_bus *video = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001835
Len Brown4be44fc2005-08-05 00:44:28 -04001836
Linus Torvalds1da177e2005-04-16 15:20:36 -07001837 if (!device)
Patrick Mocheld550d982006-06-27 00:41:40 -04001838 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001839
Burman Yan36bcbec2006-12-19 12:56:11 -08001840 video = kzalloc(sizeof(struct acpi_video_bus), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001841 if (!video)
Patrick Mocheld550d982006-06-27 00:41:40 -04001842 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001843
Patrick Mochele6afa0d2006-05-19 16:54:40 -04001844 video->device = device;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001845 strcpy(acpi_device_name(device), ACPI_VIDEO_BUS_NAME);
1846 strcpy(acpi_device_class(device), ACPI_VIDEO_CLASS);
1847 acpi_driver_data(device) = video;
1848
1849 acpi_video_bus_find_cap(video);
1850 result = acpi_video_bus_check(video);
1851 if (result)
1852 goto end;
1853
1854 result = acpi_video_bus_add_fs(device);
1855 if (result)
1856 goto end;
1857
1858 init_MUTEX(&video->sem);
1859 INIT_LIST_HEAD(&video->video_device_list);
1860
1861 acpi_video_bus_get_devices(video, device);
1862 acpi_video_bus_start_devices(video);
1863
Patrick Mochel90130262006-05-19 16:54:48 -04001864 status = acpi_install_notify_handler(device->handle,
Len Brown4be44fc2005-08-05 00:44:28 -04001865 ACPI_DEVICE_NOTIFY,
1866 acpi_video_bus_notify, video);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001867 if (ACPI_FAILURE(status)) {
1868 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
Len Brown4be44fc2005-08-05 00:44:28 -04001869 "Error installing notify handler\n"));
Yu, Luming973bf492006-04-27 05:25:00 -04001870 acpi_video_bus_stop_devices(video);
1871 acpi_video_bus_put_devices(video);
1872 kfree(video->attached_array);
1873 acpi_video_bus_remove_fs(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001874 result = -ENODEV;
1875 goto end;
1876 }
1877
1878 printk(KERN_INFO PREFIX "%s [%s] (multi-head: %s rom: %s post: %s)\n",
Len Brown4be44fc2005-08-05 00:44:28 -04001879 ACPI_VIDEO_DEVICE_NAME, acpi_device_bid(device),
1880 video->flags.multihead ? "yes" : "no",
1881 video->flags.rom ? "yes" : "no",
1882 video->flags.post ? "yes" : "no");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001883
Len Brown4be44fc2005-08-05 00:44:28 -04001884 end:
Yu, Luming973bf492006-04-27 05:25:00 -04001885 if (result)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001886 kfree(video);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001887
Patrick Mocheld550d982006-06-27 00:41:40 -04001888 return result;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001889}
1890
Len Brown4be44fc2005-08-05 00:44:28 -04001891static int acpi_video_bus_remove(struct acpi_device *device, int type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001892{
Len Brown4be44fc2005-08-05 00:44:28 -04001893 acpi_status status = 0;
1894 struct acpi_video_bus *video = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001895
Linus Torvalds1da177e2005-04-16 15:20:36 -07001896
1897 if (!device || !acpi_driver_data(device))
Patrick Mocheld550d982006-06-27 00:41:40 -04001898 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001899
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001900 video = acpi_driver_data(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001901
1902 acpi_video_bus_stop_devices(video);
1903
Patrick Mochel90130262006-05-19 16:54:48 -04001904 status = acpi_remove_notify_handler(video->device->handle,
Len Brown4be44fc2005-08-05 00:44:28 -04001905 ACPI_DEVICE_NOTIFY,
1906 acpi_video_bus_notify);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001907
1908 acpi_video_bus_put_devices(video);
1909 acpi_video_bus_remove_fs(device);
1910
Jesper Juhl6044ec82005-11-07 01:01:32 -08001911 kfree(video->attached_array);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001912 kfree(video);
1913
Patrick Mocheld550d982006-06-27 00:41:40 -04001914 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001915}
1916
Len Brown4be44fc2005-08-05 00:44:28 -04001917static int __init acpi_video_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001918{
Len Brown4be44fc2005-08-05 00:44:28 -04001919 int result = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001920
Linus Torvalds1da177e2005-04-16 15:20:36 -07001921
1922 /*
Len Brown4be44fc2005-08-05 00:44:28 -04001923 acpi_dbg_level = 0xFFFFFFFF;
1924 acpi_dbg_layer = 0x08000000;
1925 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001926
1927 acpi_video_dir = proc_mkdir(ACPI_VIDEO_CLASS, acpi_root_dir);
1928 if (!acpi_video_dir)
Patrick Mocheld550d982006-06-27 00:41:40 -04001929 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001930 acpi_video_dir->owner = THIS_MODULE;
1931
1932 result = acpi_bus_register_driver(&acpi_video_bus);
1933 if (result < 0) {
1934 remove_proc_entry(ACPI_VIDEO_CLASS, acpi_root_dir);
Patrick Mocheld550d982006-06-27 00:41:40 -04001935 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001936 }
1937
Patrick Mocheld550d982006-06-27 00:41:40 -04001938 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001939}
1940
Len Brown4be44fc2005-08-05 00:44:28 -04001941static void __exit acpi_video_exit(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001942{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001943
1944 acpi_bus_unregister_driver(&acpi_video_bus);
1945
1946 remove_proc_entry(ACPI_VIDEO_CLASS, acpi_root_dir);
1947
Patrick Mocheld550d982006-06-27 00:41:40 -04001948 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001949}
1950
1951module_init(acpi_video_init);
1952module_exit(acpi_video_exit);