blob: bac956b30c57b94fafe71c951331723122bbd926 [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>
Luming Yue9dab192007-08-20 18:23:53 +080034#include <linux/input.h>
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
Thomas Renninger1ba90e32007-07-23 14:44:41 +020077static const struct acpi_device_id video_device_ids[] = {
78 {ACPI_VIDEO_HID, 0},
79 {"", 0},
80};
81MODULE_DEVICE_TABLE(acpi, video_device_ids);
82
Linus Torvalds1da177e2005-04-16 15:20:36 -070083static struct acpi_driver acpi_video_bus = {
Len Brownc2b67052007-02-12 23:33:40 -050084 .name = "video",
Linus Torvalds1da177e2005-04-16 15:20:36 -070085 .class = ACPI_VIDEO_CLASS,
Thomas Renninger1ba90e32007-07-23 14:44:41 +020086 .ids = video_device_ids,
Linus Torvalds1da177e2005-04-16 15:20:36 -070087 .ops = {
88 .add = acpi_video_bus_add,
89 .remove = acpi_video_bus_remove,
Len Brown4be44fc2005-08-05 00:44:28 -040090 },
Linus Torvalds1da177e2005-04-16 15:20:36 -070091};
92
93struct acpi_video_bus_flags {
Len Brown4be44fc2005-08-05 00:44:28 -040094 u8 multihead:1; /* can switch video heads */
95 u8 rom:1; /* can retrieve a video rom */
96 u8 post:1; /* can configure the head to */
97 u8 reserved:5;
Linus Torvalds1da177e2005-04-16 15:20:36 -070098};
99
100struct acpi_video_bus_cap {
Len Brown4be44fc2005-08-05 00:44:28 -0400101 u8 _DOS:1; /*Enable/Disable output switching */
102 u8 _DOD:1; /*Enumerate all devices attached to display adapter */
103 u8 _ROM:1; /*Get ROM Data */
104 u8 _GPD:1; /*Get POST Device */
105 u8 _SPD:1; /*Set POST Device */
106 u8 _VPO:1; /*Video POST Options */
107 u8 reserved:2;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108};
109
Len Brown4be44fc2005-08-05 00:44:28 -0400110struct acpi_video_device_attrib {
111 u32 display_index:4; /* A zero-based instance of the Display */
Julius Volz98fb8fe2007-02-20 16:38:40 +0100112 u32 display_port_attachment:4; /*This field differentiates the display type */
Len Brown4be44fc2005-08-05 00:44:28 -0400113 u32 display_type:4; /*Describe the specific type in use */
Julius Volz98fb8fe2007-02-20 16:38:40 +0100114 u32 vendor_specific:4; /*Chipset Vendor Specific */
Len Brown4be44fc2005-08-05 00:44:28 -0400115 u32 bios_can_detect:1; /*BIOS can detect the device */
116 u32 depend_on_vga:1; /*Non-VGA output device whose power is related to
117 the VGA device. */
118 u32 pipe_id:3; /*For VGA multiple-head devices. */
119 u32 reserved:10; /*Must be 0 */
120 u32 device_id_scheme:1; /*Device ID Scheme */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121};
122
123struct acpi_video_enumerated_device {
124 union {
125 u32 int_val;
Len Brown4be44fc2005-08-05 00:44:28 -0400126 struct acpi_video_device_attrib attrib;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127 } value;
128 struct acpi_video_device *bind_info;
129};
130
131struct acpi_video_bus {
Patrick Mochele6afa0d2006-05-19 16:54:40 -0400132 struct acpi_device *device;
Len Brown4be44fc2005-08-05 00:44:28 -0400133 u8 dos_setting;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134 struct acpi_video_enumerated_device *attached_array;
Len Brown4be44fc2005-08-05 00:44:28 -0400135 u8 attached_count;
136 struct acpi_video_bus_cap cap;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137 struct acpi_video_bus_flags flags;
Len Brown4be44fc2005-08-05 00:44:28 -0400138 struct semaphore sem;
139 struct list_head video_device_list;
140 struct proc_dir_entry *dir;
Luming Yue9dab192007-08-20 18:23:53 +0800141 struct input_dev *input;
142 char phys[32]; /* for input device */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143};
144
145struct acpi_video_device_flags {
Len Brown4be44fc2005-08-05 00:44:28 -0400146 u8 crt:1;
147 u8 lcd:1;
148 u8 tvout:1;
Rui Zhang82cae992007-01-03 23:40:53 -0500149 u8 dvi:1;
Len Brown4be44fc2005-08-05 00:44:28 -0400150 u8 bios:1;
151 u8 unknown:1;
Rui Zhang82cae992007-01-03 23:40:53 -0500152 u8 reserved:2;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700153};
154
155struct acpi_video_device_cap {
Len Brown4be44fc2005-08-05 00:44:28 -0400156 u8 _ADR:1; /*Return the unique ID */
157 u8 _BCL:1; /*Query list of brightness control levels supported */
158 u8 _BCM:1; /*Set the brightness level */
Yu Luming2f3d0002006-11-11 02:40:34 +0800159 u8 _BQC:1; /* Get current brightness level */
Len Brown4be44fc2005-08-05 00:44:28 -0400160 u8 _DDC:1; /*Return the EDID for this device */
161 u8 _DCS:1; /*Return status of output device */
162 u8 _DGS:1; /*Query graphics state */
163 u8 _DSS:1; /*Device state set */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700164};
165
166struct acpi_video_device_brightness {
Len Brown4be44fc2005-08-05 00:44:28 -0400167 int curr;
168 int count;
169 int *levels;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700170};
171
172struct acpi_video_device {
Len Brown4be44fc2005-08-05 00:44:28 -0400173 unsigned long device_id;
174 struct acpi_video_device_flags flags;
175 struct acpi_video_device_cap cap;
176 struct list_head entry;
177 struct acpi_video_bus *video;
178 struct acpi_device *dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700179 struct acpi_video_device_brightness *brightness;
Yu Luming2f3d0002006-11-11 02:40:34 +0800180 struct backlight_device *backlight;
Luming Yu23b0f012007-05-09 21:07:05 +0800181 struct output_device *output_dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700182};
183
Linus Torvalds1da177e2005-04-16 15:20:36 -0700184/* bus */
185static int acpi_video_bus_info_open_fs(struct inode *inode, struct file *file);
186static struct file_operations acpi_video_bus_info_fops = {
Len Brown4be44fc2005-08-05 00:44:28 -0400187 .open = acpi_video_bus_info_open_fs,
188 .read = seq_read,
189 .llseek = seq_lseek,
190 .release = single_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700191};
192
193static int acpi_video_bus_ROM_open_fs(struct inode *inode, struct file *file);
194static struct file_operations acpi_video_bus_ROM_fops = {
Len Brown4be44fc2005-08-05 00:44:28 -0400195 .open = acpi_video_bus_ROM_open_fs,
196 .read = seq_read,
197 .llseek = seq_lseek,
198 .release = single_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700199};
200
Len Brown4be44fc2005-08-05 00:44:28 -0400201static int acpi_video_bus_POST_info_open_fs(struct inode *inode,
202 struct file *file);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700203static struct file_operations acpi_video_bus_POST_info_fops = {
Len Brown4be44fc2005-08-05 00:44:28 -0400204 .open = acpi_video_bus_POST_info_open_fs,
205 .read = seq_read,
206 .llseek = seq_lseek,
207 .release = single_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700208};
209
210static int acpi_video_bus_POST_open_fs(struct inode *inode, struct file *file);
211static struct file_operations acpi_video_bus_POST_fops = {
Len Brown4be44fc2005-08-05 00:44:28 -0400212 .open = acpi_video_bus_POST_open_fs,
213 .read = seq_read,
214 .llseek = seq_lseek,
215 .release = single_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700216};
217
Linus Torvalds1da177e2005-04-16 15:20:36 -0700218static int acpi_video_bus_DOS_open_fs(struct inode *inode, struct file *file);
219static struct file_operations acpi_video_bus_DOS_fops = {
Len Brown4be44fc2005-08-05 00:44:28 -0400220 .open = acpi_video_bus_DOS_open_fs,
221 .read = seq_read,
222 .llseek = seq_lseek,
223 .release = single_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700224};
225
226/* device */
Len Brown4be44fc2005-08-05 00:44:28 -0400227static int acpi_video_device_info_open_fs(struct inode *inode,
228 struct file *file);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700229static struct file_operations acpi_video_device_info_fops = {
Len Brown4be44fc2005-08-05 00:44:28 -0400230 .open = acpi_video_device_info_open_fs,
231 .read = seq_read,
232 .llseek = seq_lseek,
233 .release = single_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700234};
235
Len Brown4be44fc2005-08-05 00:44:28 -0400236static int acpi_video_device_state_open_fs(struct inode *inode,
237 struct file *file);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700238static struct file_operations acpi_video_device_state_fops = {
Len Brown4be44fc2005-08-05 00:44:28 -0400239 .open = acpi_video_device_state_open_fs,
240 .read = seq_read,
241 .llseek = seq_lseek,
242 .release = single_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700243};
244
Len Brown4be44fc2005-08-05 00:44:28 -0400245static int acpi_video_device_brightness_open_fs(struct inode *inode,
246 struct file *file);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700247static struct file_operations acpi_video_device_brightness_fops = {
Len Brown4be44fc2005-08-05 00:44:28 -0400248 .open = acpi_video_device_brightness_open_fs,
249 .read = seq_read,
250 .llseek = seq_lseek,
251 .release = single_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700252};
253
Len Brown4be44fc2005-08-05 00:44:28 -0400254static int acpi_video_device_EDID_open_fs(struct inode *inode,
255 struct file *file);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700256static struct file_operations acpi_video_device_EDID_fops = {
Len Brown4be44fc2005-08-05 00:44:28 -0400257 .open = acpi_video_device_EDID_open_fs,
258 .read = seq_read,
259 .llseek = seq_lseek,
260 .release = single_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700261};
262
Len Brown4be44fc2005-08-05 00:44:28 -0400263static char device_decode[][30] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700264 "motherboard VGA device",
265 "PCI VGA device",
266 "AGP VGA device",
267 "UNKNOWN",
268};
269
Len Brown4be44fc2005-08-05 00:44:28 -0400270static void acpi_video_device_notify(acpi_handle handle, u32 event, void *data);
271static void acpi_video_device_rebind(struct acpi_video_bus *video);
272static void acpi_video_device_bind(struct acpi_video_bus *video,
273 struct acpi_video_device *device);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700274static int acpi_video_device_enumerate(struct acpi_video_bus *video);
Len Brown4be44fc2005-08-05 00:44:28 -0400275static int acpi_video_switch_output(struct acpi_video_bus *video, int event);
Yu Luming2f3d0002006-11-11 02:40:34 +0800276static int acpi_video_device_lcd_set_level(struct acpi_video_device *device,
277 int level);
278static int acpi_video_device_lcd_get_level_current(
279 struct acpi_video_device *device,
280 unsigned long *level);
Len Brown4be44fc2005-08-05 00:44:28 -0400281static int acpi_video_get_next_level(struct acpi_video_device *device,
282 u32 level_current, u32 event);
283static void acpi_video_switch_brightness(struct acpi_video_device *device,
284 int event);
Luming Yu23b0f012007-05-09 21:07:05 +0800285static int acpi_video_device_get_state(struct acpi_video_device *device,
286 unsigned long *state);
287static int acpi_video_output_get(struct output_device *od);
288static int acpi_video_device_set_state(struct acpi_video_device *device, int state);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700289
Yu Luming2f3d0002006-11-11 02:40:34 +0800290/*backlight device sysfs support*/
291static int acpi_video_get_brightness(struct backlight_device *bd)
292{
293 unsigned long cur_level;
294 struct acpi_video_device *vd =
Richard Purdie655bfd72007-07-09 12:17:24 +0100295 (struct acpi_video_device *)bl_get_data(bd);
Yu Luming2f3d0002006-11-11 02:40:34 +0800296 acpi_video_device_lcd_get_level_current(vd, &cur_level);
297 return (int) cur_level;
298}
299
300static int acpi_video_set_brightness(struct backlight_device *bd)
301{
Richard Purdie599a52d2007-02-10 23:07:48 +0000302 int request_level = bd->props.brightness;
Yu Luming2f3d0002006-11-11 02:40:34 +0800303 struct acpi_video_device *vd =
Richard Purdie655bfd72007-07-09 12:17:24 +0100304 (struct acpi_video_device *)bl_get_data(bd);
Yu Luming2f3d0002006-11-11 02:40:34 +0800305 acpi_video_device_lcd_set_level(vd, request_level);
306 return 0;
307}
308
Richard Purdie599a52d2007-02-10 23:07:48 +0000309static struct backlight_ops acpi_backlight_ops = {
310 .get_brightness = acpi_video_get_brightness,
311 .update_status = acpi_video_set_brightness,
312};
313
Luming Yu23b0f012007-05-09 21:07:05 +0800314/*video output device sysfs support*/
315static int acpi_video_output_get(struct output_device *od)
316{
317 unsigned long state;
318 struct acpi_video_device *vd =
tonyj@suse.de60043422007-08-07 22:28:47 -0700319 (struct acpi_video_device *)dev_get_drvdata(&od->dev);
Luming Yu23b0f012007-05-09 21:07:05 +0800320 acpi_video_device_get_state(vd, &state);
321 return (int)state;
322}
323
324static int acpi_video_output_set(struct output_device *od)
325{
326 unsigned long state = od->request_state;
327 struct acpi_video_device *vd=
tonyj@suse.de60043422007-08-07 22:28:47 -0700328 (struct acpi_video_device *)dev_get_drvdata(&od->dev);
Luming Yu23b0f012007-05-09 21:07:05 +0800329 return acpi_video_device_set_state(vd, state);
330}
331
332static struct output_properties acpi_output_properties = {
333 .set_state = acpi_video_output_set,
334 .get_status = acpi_video_output_get,
335};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700336/* --------------------------------------------------------------------------
337 Video Management
338 -------------------------------------------------------------------------- */
339
340/* device */
341
342static int
Len Brown4be44fc2005-08-05 00:44:28 -0400343acpi_video_device_query(struct acpi_video_device *device, unsigned long *state)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700344{
Len Brown4be44fc2005-08-05 00:44:28 -0400345 int status;
Patrick Mochel90130262006-05-19 16:54:48 -0400346
347 status = acpi_evaluate_integer(device->dev->handle, "_DGS", NULL, state);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700348
Patrick Mocheld550d982006-06-27 00:41:40 -0400349 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700350}
351
352static int
Len Brown4be44fc2005-08-05 00:44:28 -0400353acpi_video_device_get_state(struct acpi_video_device *device,
354 unsigned long *state)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700355{
Len Brown4be44fc2005-08-05 00:44:28 -0400356 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700357
Patrick Mochel90130262006-05-19 16:54:48 -0400358 status = acpi_evaluate_integer(device->dev->handle, "_DCS", NULL, state);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700359
Patrick Mocheld550d982006-06-27 00:41:40 -0400360 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700361}
362
363static int
Len Brown4be44fc2005-08-05 00:44:28 -0400364acpi_video_device_set_state(struct acpi_video_device *device, int state)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700365{
Len Brown4be44fc2005-08-05 00:44:28 -0400366 int status;
367 union acpi_object arg0 = { ACPI_TYPE_INTEGER };
368 struct acpi_object_list args = { 1, &arg0 };
Luming Yu824b5582005-08-21 19:17:00 -0400369 unsigned long ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700370
Linus Torvalds1da177e2005-04-16 15:20:36 -0700371
372 arg0.integer.value = state;
Patrick Mochel90130262006-05-19 16:54:48 -0400373 status = acpi_evaluate_integer(device->dev->handle, "_DSS", &args, &ret);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700374
Patrick Mocheld550d982006-06-27 00:41:40 -0400375 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700376}
377
378static int
Len Brown4be44fc2005-08-05 00:44:28 -0400379acpi_video_device_lcd_query_levels(struct acpi_video_device *device,
380 union acpi_object **levels)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700381{
Len Brown4be44fc2005-08-05 00:44:28 -0400382 int status;
383 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
384 union acpi_object *obj;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700385
Linus Torvalds1da177e2005-04-16 15:20:36 -0700386
387 *levels = NULL;
388
Patrick Mochel90130262006-05-19 16:54:48 -0400389 status = acpi_evaluate_object(device->dev->handle, "_BCL", NULL, &buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700390 if (!ACPI_SUCCESS(status))
Patrick Mocheld550d982006-06-27 00:41:40 -0400391 return status;
Len Brown4be44fc2005-08-05 00:44:28 -0400392 obj = (union acpi_object *)buffer.pointer;
Adrian Bunk6665bda2006-03-11 10:12:00 -0500393 if (!obj || (obj->type != ACPI_TYPE_PACKAGE)) {
Len Brown64684632006-06-26 23:41:38 -0400394 printk(KERN_ERR PREFIX "Invalid _BCL data\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700395 status = -EFAULT;
396 goto err;
397 }
398
399 *levels = obj;
400
Patrick Mocheld550d982006-06-27 00:41:40 -0400401 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700402
Len Brown4be44fc2005-08-05 00:44:28 -0400403 err:
Jesper Juhl6044ec82005-11-07 01:01:32 -0800404 kfree(buffer.pointer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700405
Patrick Mocheld550d982006-06-27 00:41:40 -0400406 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700407}
408
409static int
Len Brown4be44fc2005-08-05 00:44:28 -0400410acpi_video_device_lcd_set_level(struct acpi_video_device *device, int level)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700411{
Alexey Starikovskiy4500ca82007-09-03 16:29:58 +0400412 int status = AE_OK;
Len Brown4be44fc2005-08-05 00:44:28 -0400413 union acpi_object arg0 = { ACPI_TYPE_INTEGER };
414 struct acpi_object_list args = { 1, &arg0 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700415
Linus Torvalds1da177e2005-04-16 15:20:36 -0700416
417 arg0.integer.value = level;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700418
Alexey Starikovskiy4500ca82007-09-03 16:29:58 +0400419 if (device->cap._BCM)
420 status = acpi_evaluate_object(device->dev->handle, "_BCM",
421 &args, NULL);
422 device->brightness->curr = level;
Patrick Mocheld550d982006-06-27 00:41:40 -0400423 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700424}
425
426static int
Len Brown4be44fc2005-08-05 00:44:28 -0400427acpi_video_device_lcd_get_level_current(struct acpi_video_device *device,
428 unsigned long *level)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700429{
Alexey Starikovskiy4500ca82007-09-03 16:29:58 +0400430 if (device->cap._BQC)
431 return acpi_evaluate_integer(device->dev->handle, "_BQC", NULL,
432 level);
433 *level = device->brightness->curr;
434 return AE_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700435}
436
437static int
Len Brown4be44fc2005-08-05 00:44:28 -0400438acpi_video_device_EDID(struct acpi_video_device *device,
439 union acpi_object **edid, ssize_t length)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700440{
Len Brown4be44fc2005-08-05 00:44:28 -0400441 int status;
442 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
443 union acpi_object *obj;
444 union acpi_object arg0 = { ACPI_TYPE_INTEGER };
445 struct acpi_object_list args = { 1, &arg0 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700446
Linus Torvalds1da177e2005-04-16 15:20:36 -0700447
448 *edid = NULL;
449
450 if (!device)
Patrick Mocheld550d982006-06-27 00:41:40 -0400451 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700452 if (length == 128)
453 arg0.integer.value = 1;
454 else if (length == 256)
455 arg0.integer.value = 2;
456 else
Patrick Mocheld550d982006-06-27 00:41:40 -0400457 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700458
Patrick Mochel90130262006-05-19 16:54:48 -0400459 status = acpi_evaluate_object(device->dev->handle, "_DDC", &args, &buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700460 if (ACPI_FAILURE(status))
Patrick Mocheld550d982006-06-27 00:41:40 -0400461 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700462
Jan Engelhardt50dd0962006-10-01 00:28:50 +0200463 obj = buffer.pointer;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700464
465 if (obj && obj->type == ACPI_TYPE_BUFFER)
466 *edid = obj;
467 else {
Len Brown64684632006-06-26 23:41:38 -0400468 printk(KERN_ERR PREFIX "Invalid _DDC data\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700469 status = -EFAULT;
470 kfree(obj);
471 }
472
Patrick Mocheld550d982006-06-27 00:41:40 -0400473 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700474}
475
Linus Torvalds1da177e2005-04-16 15:20:36 -0700476/* bus */
477
478static int
Len Brown4be44fc2005-08-05 00:44:28 -0400479acpi_video_bus_set_POST(struct acpi_video_bus *video, unsigned long option)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700480{
Len Brown4be44fc2005-08-05 00:44:28 -0400481 int status;
482 unsigned long tmp;
483 union acpi_object arg0 = { ACPI_TYPE_INTEGER };
484 struct acpi_object_list args = { 1, &arg0 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700485
Linus Torvalds1da177e2005-04-16 15:20:36 -0700486
487 arg0.integer.value = option;
488
Patrick Mochel90130262006-05-19 16:54:48 -0400489 status = acpi_evaluate_integer(video->device->handle, "_SPD", &args, &tmp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700490 if (ACPI_SUCCESS(status))
Len Brown4be44fc2005-08-05 00:44:28 -0400491 status = tmp ? (-EINVAL) : (AE_OK);
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_get_POST(struct acpi_video_bus *video, unsigned long *id)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700498{
499 int status;
500
Patrick Mochel90130262006-05-19 16:54:48 -0400501 status = acpi_evaluate_integer(video->device->handle, "_GPD", NULL, id);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700502
Patrick Mocheld550d982006-06-27 00:41:40 -0400503 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700504}
505
506static int
Len Brown4be44fc2005-08-05 00:44:28 -0400507acpi_video_bus_POST_options(struct acpi_video_bus *video,
508 unsigned long *options)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700509{
Len Brown4be44fc2005-08-05 00:44:28 -0400510 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700511
Patrick Mochel90130262006-05-19 16:54:48 -0400512 status = acpi_evaluate_integer(video->device->handle, "_VPO", NULL, options);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700513 *options &= 3;
514
Patrick Mocheld550d982006-06-27 00:41:40 -0400515 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700516}
517
518/*
519 * Arg:
520 * video : video bus device pointer
521 * bios_flag :
522 * 0. The system BIOS should NOT automatically switch(toggle)
523 * the active display output.
524 * 1. The system BIOS should automatically switch (toggle) the
Julius Volz98fb8fe2007-02-20 16:38:40 +0100525 * active display output. No switch event.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700526 * 2. The _DGS value should be locked.
527 * 3. The system BIOS should not automatically switch (toggle) the
528 * active display output, but instead generate the display switch
529 * event notify code.
530 * lcd_flag :
531 * 0. The system BIOS should automatically control the brightness level
Julius Volz98fb8fe2007-02-20 16:38:40 +0100532 * of the LCD when the power changes from AC to DC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700533 * 1. The system BIOS should NOT automatically control the brightness
Julius Volz98fb8fe2007-02-20 16:38:40 +0100534 * level of the LCD when the power changes from AC to DC.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700535 * Return Value:
536 * -1 wrong arg.
537 */
538
539static int
Len Brown4be44fc2005-08-05 00:44:28 -0400540acpi_video_bus_DOS(struct acpi_video_bus *video, int bios_flag, int lcd_flag)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700541{
Len Brown4be44fc2005-08-05 00:44:28 -0400542 acpi_integer status = 0;
543 union acpi_object arg0 = { ACPI_TYPE_INTEGER };
544 struct acpi_object_list args = { 1, &arg0 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700545
Linus Torvalds1da177e2005-04-16 15:20:36 -0700546
Len Brown4be44fc2005-08-05 00:44:28 -0400547 if (bios_flag < 0 || bios_flag > 3 || lcd_flag < 0 || lcd_flag > 1) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700548 status = -1;
549 goto Failed;
550 }
551 arg0.integer.value = (lcd_flag << 2) | bios_flag;
552 video->dos_setting = arg0.integer.value;
Patrick Mochel90130262006-05-19 16:54:48 -0400553 acpi_evaluate_object(video->device->handle, "_DOS", &args, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700554
Len Brown4be44fc2005-08-05 00:44:28 -0400555 Failed:
Patrick Mocheld550d982006-06-27 00:41:40 -0400556 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700557}
558
559/*
560 * Arg:
561 * device : video output device (LCD, CRT, ..)
562 *
563 * Return Value:
564 * None
565 *
Julius Volz98fb8fe2007-02-20 16:38:40 +0100566 * Find out all required AML methods defined under the output
Linus Torvalds1da177e2005-04-16 15:20:36 -0700567 * device.
568 */
569
Len Brown4be44fc2005-08-05 00:44:28 -0400570static void acpi_video_device_find_cap(struct acpi_video_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700571{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700572 acpi_handle h_dummy1;
573 int i;
Yu Luming2f3d0002006-11-11 02:40:34 +0800574 u32 max_level = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700575 union acpi_object *obj = NULL;
576 struct acpi_video_device_brightness *br = NULL;
577
Linus Torvalds1da177e2005-04-16 15:20:36 -0700578
Len Brown4be44fc2005-08-05 00:44:28 -0400579 memset(&device->cap, 0, 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700580
Patrick Mochel90130262006-05-19 16:54:48 -0400581 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_ADR", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700582 device->cap._ADR = 1;
583 }
Patrick Mochel90130262006-05-19 16:54:48 -0400584 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_BCL", &h_dummy1))) {
Len Brown4be44fc2005-08-05 00:44:28 -0400585 device->cap._BCL = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700586 }
Patrick Mochel90130262006-05-19 16:54:48 -0400587 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_BCM", &h_dummy1))) {
Len Brown4be44fc2005-08-05 00:44:28 -0400588 device->cap._BCM = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700589 }
Yu Luming2f3d0002006-11-11 02:40:34 +0800590 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle,"_BQC",&h_dummy1)))
591 device->cap._BQC = 1;
Patrick Mochel90130262006-05-19 16:54:48 -0400592 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_DDC", &h_dummy1))) {
Len Brown4be44fc2005-08-05 00:44:28 -0400593 device->cap._DDC = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700594 }
Patrick Mochel90130262006-05-19 16:54:48 -0400595 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_DCS", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700596 device->cap._DCS = 1;
597 }
Patrick Mochel90130262006-05-19 16:54:48 -0400598 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_DGS", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700599 device->cap._DGS = 1;
600 }
Patrick Mochel90130262006-05-19 16:54:48 -0400601 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_DSS", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700602 device->cap._DSS = 1;
603 }
604
Danny Kukawkaf70ac0e2007-07-03 01:33:53 -0400605 if (ACPI_SUCCESS(acpi_video_device_lcd_query_levels(device, &obj))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700606
Danny Kukawkaf70ac0e2007-07-03 01:33:53 -0400607 if (obj->package.count >= 2) {
608 int count = 0;
609 union acpi_object *o;
Len Brown4be44fc2005-08-05 00:44:28 -0400610
Danny Kukawkaf70ac0e2007-07-03 01:33:53 -0400611 br = kzalloc(sizeof(*br), GFP_KERNEL);
612 if (!br) {
613 printk(KERN_ERR "can't allocate memory\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700614 } else {
Danny Kukawkaf70ac0e2007-07-03 01:33:53 -0400615 br->levels = kmalloc(obj->package.count *
616 sizeof *(br->levels), GFP_KERNEL);
617 if (!br->levels)
618 goto out;
619
620 for (i = 0; i < obj->package.count; i++) {
621 o = (union acpi_object *)&obj->package.
622 elements[i];
623 if (o->type != ACPI_TYPE_INTEGER) {
624 printk(KERN_ERR PREFIX "Invalid data\n");
625 continue;
626 }
627 br->levels[count] = (u32) o->integer.value;
628
629 if (br->levels[count] > max_level)
630 max_level = br->levels[count];
631 count++;
632 }
633 out:
634 if (count < 2) {
635 kfree(br->levels);
636 kfree(br);
637 } else {
638 br->count = count;
639 device->brightness = br;
640 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
641 "found %d brightness levels\n",
642 count));
643 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700644 }
645 }
Danny Kukawkaf70ac0e2007-07-03 01:33:53 -0400646
647 } else {
648 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Could not query available LCD brightness level\n"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700649 }
650
Paulo Marquesd1dd0c22005-03-30 22:39:49 -0500651 kfree(obj);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700652
Danny Kukawkaf70ac0e2007-07-03 01:33:53 -0400653 if (device->cap._BCL && device->cap._BCM && device->cap._BQC && max_level > 0){
Yu Luming2f3d0002006-11-11 02:40:34 +0800654 unsigned long tmp;
655 static int count = 0;
656 char *name;
Yu Luming2f3d0002006-11-11 02:40:34 +0800657 name = kzalloc(MAX_NAME_LEN, GFP_KERNEL);
658 if (!name)
659 return;
660
Yu Luming2f3d0002006-11-11 02:40:34 +0800661 sprintf(name, "acpi_video%d", count++);
Yu Luming2f3d0002006-11-11 02:40:34 +0800662 acpi_video_device_lcd_get_level_current(device, &tmp);
Yu Luming2f3d0002006-11-11 02:40:34 +0800663 device->backlight = backlight_device_register(name,
Richard Purdie599a52d2007-02-10 23:07:48 +0000664 NULL, device, &acpi_backlight_ops);
665 device->backlight->props.max_brightness = max_level;
666 device->backlight->props.brightness = (int)tmp;
667 backlight_update_status(device->backlight);
668
Yu Luming2f3d0002006-11-11 02:40:34 +0800669 kfree(name);
670 }
Luming Yu23b0f012007-05-09 21:07:05 +0800671 if (device->cap._DCS && device->cap._DSS){
672 static int count = 0;
673 char *name;
674 name = kzalloc(MAX_NAME_LEN, GFP_KERNEL);
675 if (!name)
676 return;
677 sprintf(name, "acpi_video%d", count++);
678 device->output_dev = video_output_register(name,
679 NULL, device, &acpi_output_properties);
680 kfree(name);
681 }
Patrick Mocheld550d982006-06-27 00:41:40 -0400682 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700683}
684
685/*
686 * Arg:
687 * device : video output device (VGA)
688 *
689 * Return Value:
690 * None
691 *
Julius Volz98fb8fe2007-02-20 16:38:40 +0100692 * Find out all required AML methods defined under the video bus device.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700693 */
694
Len Brown4be44fc2005-08-05 00:44:28 -0400695static void acpi_video_bus_find_cap(struct acpi_video_bus *video)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700696{
Len Brown4be44fc2005-08-05 00:44:28 -0400697 acpi_handle h_dummy1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700698
Len Brown4be44fc2005-08-05 00:44:28 -0400699 memset(&video->cap, 0, 4);
Patrick Mochel90130262006-05-19 16:54:48 -0400700 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_DOS", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700701 video->cap._DOS = 1;
702 }
Patrick Mochel90130262006-05-19 16:54:48 -0400703 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_DOD", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700704 video->cap._DOD = 1;
705 }
Patrick Mochel90130262006-05-19 16:54:48 -0400706 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_ROM", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700707 video->cap._ROM = 1;
708 }
Patrick Mochel90130262006-05-19 16:54:48 -0400709 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_GPD", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700710 video->cap._GPD = 1;
711 }
Patrick Mochel90130262006-05-19 16:54:48 -0400712 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_SPD", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700713 video->cap._SPD = 1;
714 }
Patrick Mochel90130262006-05-19 16:54:48 -0400715 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_VPO", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700716 video->cap._VPO = 1;
717 }
718}
719
720/*
721 * Check whether the video bus device has required AML method to
722 * support the desired features
723 */
724
Len Brown4be44fc2005-08-05 00:44:28 -0400725static int acpi_video_bus_check(struct acpi_video_bus *video)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700726{
Len Brown4be44fc2005-08-05 00:44:28 -0400727 acpi_status status = -ENOENT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700728
Linus Torvalds1da177e2005-04-16 15:20:36 -0700729
730 if (!video)
Patrick Mocheld550d982006-06-27 00:41:40 -0400731 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700732
733 /* Since there is no HID, CID and so on for VGA driver, we have
734 * to check well known required nodes.
735 */
736
Julius Volz98fb8fe2007-02-20 16:38:40 +0100737 /* Does this device support video switching? */
Len Brown4be44fc2005-08-05 00:44:28 -0400738 if (video->cap._DOS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700739 video->flags.multihead = 1;
740 status = 0;
741 }
742
Julius Volz98fb8fe2007-02-20 16:38:40 +0100743 /* Does this device support retrieving a video ROM? */
Len Brown4be44fc2005-08-05 00:44:28 -0400744 if (video->cap._ROM) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700745 video->flags.rom = 1;
746 status = 0;
747 }
748
Julius Volz98fb8fe2007-02-20 16:38:40 +0100749 /* Does this device support configuring which video device to POST? */
Len Brown4be44fc2005-08-05 00:44:28 -0400750 if (video->cap._GPD && video->cap._SPD && video->cap._VPO) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700751 video->flags.post = 1;
752 status = 0;
753 }
754
Patrick Mocheld550d982006-06-27 00:41:40 -0400755 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700756}
757
758/* --------------------------------------------------------------------------
759 FS Interface (/proc)
760 -------------------------------------------------------------------------- */
761
Len Brown4be44fc2005-08-05 00:44:28 -0400762static struct proc_dir_entry *acpi_video_dir;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700763
764/* video devices */
765
Len Brown4be44fc2005-08-05 00:44:28 -0400766static int acpi_video_device_info_seq_show(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700767{
Jan Engelhardt50dd0962006-10-01 00:28:50 +0200768 struct acpi_video_device *dev = seq->private;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700769
Linus Torvalds1da177e2005-04-16 15:20:36 -0700770
771 if (!dev)
772 goto end;
773
774 seq_printf(seq, "device_id: 0x%04x\n", (u32) dev->device_id);
775 seq_printf(seq, "type: ");
776 if (dev->flags.crt)
777 seq_printf(seq, "CRT\n");
778 else if (dev->flags.lcd)
779 seq_printf(seq, "LCD\n");
780 else if (dev->flags.tvout)
781 seq_printf(seq, "TVOUT\n");
Rui Zhang82cae992007-01-03 23:40:53 -0500782 else if (dev->flags.dvi)
783 seq_printf(seq, "DVI\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700784 else
785 seq_printf(seq, "UNKNOWN\n");
786
Len Brown4be44fc2005-08-05 00:44:28 -0400787 seq_printf(seq, "known by bios: %s\n", dev->flags.bios ? "yes" : "no");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700788
Len Brown4be44fc2005-08-05 00:44:28 -0400789 end:
Patrick Mocheld550d982006-06-27 00:41:40 -0400790 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700791}
792
793static int
Len Brown4be44fc2005-08-05 00:44:28 -0400794acpi_video_device_info_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700795{
796 return single_open(file, acpi_video_device_info_seq_show,
797 PDE(inode)->data);
798}
799
Len Brown4be44fc2005-08-05 00:44:28 -0400800static int acpi_video_device_state_seq_show(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700801{
Len Brown4be44fc2005-08-05 00:44:28 -0400802 int status;
Jan Engelhardt50dd0962006-10-01 00:28:50 +0200803 struct acpi_video_device *dev = seq->private;
Len Brown4be44fc2005-08-05 00:44:28 -0400804 unsigned long state;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700805
Linus Torvalds1da177e2005-04-16 15:20:36 -0700806
807 if (!dev)
808 goto end;
809
810 status = acpi_video_device_get_state(dev, &state);
811 seq_printf(seq, "state: ");
812 if (ACPI_SUCCESS(status))
813 seq_printf(seq, "0x%02lx\n", state);
814 else
815 seq_printf(seq, "<not supported>\n");
816
817 status = acpi_video_device_query(dev, &state);
818 seq_printf(seq, "query: ");
819 if (ACPI_SUCCESS(status))
820 seq_printf(seq, "0x%02lx\n", state);
821 else
822 seq_printf(seq, "<not supported>\n");
823
Len Brown4be44fc2005-08-05 00:44:28 -0400824 end:
Patrick Mocheld550d982006-06-27 00:41:40 -0400825 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700826}
827
828static int
Len Brown4be44fc2005-08-05 00:44:28 -0400829acpi_video_device_state_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700830{
831 return single_open(file, acpi_video_device_state_seq_show,
832 PDE(inode)->data);
833}
834
835static ssize_t
Len Brown4be44fc2005-08-05 00:44:28 -0400836acpi_video_device_write_state(struct file *file,
837 const char __user * buffer,
838 size_t count, loff_t * data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700839{
Len Brown4be44fc2005-08-05 00:44:28 -0400840 int status;
Jan Engelhardt50dd0962006-10-01 00:28:50 +0200841 struct seq_file *m = file->private_data;
842 struct acpi_video_device *dev = m->private;
Len Brown4be44fc2005-08-05 00:44:28 -0400843 char str[12] = { 0 };
844 u32 state = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700845
Linus Torvalds1da177e2005-04-16 15:20:36 -0700846
847 if (!dev || count + 1 > sizeof str)
Patrick Mocheld550d982006-06-27 00:41:40 -0400848 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700849
850 if (copy_from_user(str, buffer, count))
Patrick Mocheld550d982006-06-27 00:41:40 -0400851 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700852
853 str[count] = 0;
854 state = simple_strtoul(str, NULL, 0);
Len Brown4be44fc2005-08-05 00:44:28 -0400855 state &= ((1ul << 31) | (1ul << 30) | (1ul << 0));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700856
857 status = acpi_video_device_set_state(dev, state);
858
859 if (status)
Patrick Mocheld550d982006-06-27 00:41:40 -0400860 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700861
Patrick Mocheld550d982006-06-27 00:41:40 -0400862 return count;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700863}
864
865static int
Len Brown4be44fc2005-08-05 00:44:28 -0400866acpi_video_device_brightness_seq_show(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700867{
Jan Engelhardt50dd0962006-10-01 00:28:50 +0200868 struct acpi_video_device *dev = seq->private;
Len Brown4be44fc2005-08-05 00:44:28 -0400869 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700870
Linus Torvalds1da177e2005-04-16 15:20:36 -0700871
872 if (!dev || !dev->brightness) {
873 seq_printf(seq, "<not supported>\n");
Patrick Mocheld550d982006-06-27 00:41:40 -0400874 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700875 }
876
877 seq_printf(seq, "levels: ");
878 for (i = 0; i < dev->brightness->count; i++)
879 seq_printf(seq, " %d", dev->brightness->levels[i]);
880 seq_printf(seq, "\ncurrent: %d\n", dev->brightness->curr);
881
Patrick Mocheld550d982006-06-27 00:41:40 -0400882 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700883}
884
885static int
Len Brown4be44fc2005-08-05 00:44:28 -0400886acpi_video_device_brightness_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700887{
888 return single_open(file, acpi_video_device_brightness_seq_show,
889 PDE(inode)->data);
890}
891
892static ssize_t
Len Brown4be44fc2005-08-05 00:44:28 -0400893acpi_video_device_write_brightness(struct file *file,
894 const char __user * buffer,
895 size_t count, loff_t * data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700896{
Jan Engelhardt50dd0962006-10-01 00:28:50 +0200897 struct seq_file *m = file->private_data;
898 struct acpi_video_device *dev = m->private;
Len Brown4be44fc2005-08-05 00:44:28 -0400899 char str[4] = { 0 };
900 unsigned int level = 0;
901 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700902
Linus Torvalds1da177e2005-04-16 15:20:36 -0700903
Thomas Renninger59d399d2005-11-08 05:27:00 -0500904 if (!dev || !dev->brightness || count + 1 > sizeof str)
Patrick Mocheld550d982006-06-27 00:41:40 -0400905 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700906
907 if (copy_from_user(str, buffer, count))
Patrick Mocheld550d982006-06-27 00:41:40 -0400908 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700909
910 str[count] = 0;
911 level = simple_strtoul(str, NULL, 0);
Len Brown4be44fc2005-08-05 00:44:28 -0400912
Linus Torvalds1da177e2005-04-16 15:20:36 -0700913 if (level > 100)
Patrick Mocheld550d982006-06-27 00:41:40 -0400914 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700915
Julius Volz98fb8fe2007-02-20 16:38:40 +0100916 /* validate through the list of available levels */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700917 for (i = 0; i < dev->brightness->count; i++)
918 if (level == dev->brightness->levels[i]) {
Len Brown4be44fc2005-08-05 00:44:28 -0400919 if (ACPI_SUCCESS
920 (acpi_video_device_lcd_set_level(dev, level)))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700921 dev->brightness->curr = level;
922 break;
923 }
924
Patrick Mocheld550d982006-06-27 00:41:40 -0400925 return count;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700926}
927
Len Brown4be44fc2005-08-05 00:44:28 -0400928static int acpi_video_device_EDID_seq_show(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700929{
Jan Engelhardt50dd0962006-10-01 00:28:50 +0200930 struct acpi_video_device *dev = seq->private;
Len Brown4be44fc2005-08-05 00:44:28 -0400931 int status;
932 int i;
933 union acpi_object *edid = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700934
Linus Torvalds1da177e2005-04-16 15:20:36 -0700935
936 if (!dev)
937 goto out;
938
Len Brown4be44fc2005-08-05 00:44:28 -0400939 status = acpi_video_device_EDID(dev, &edid, 128);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700940 if (ACPI_FAILURE(status)) {
Len Brown4be44fc2005-08-05 00:44:28 -0400941 status = acpi_video_device_EDID(dev, &edid, 256);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700942 }
943
944 if (ACPI_FAILURE(status)) {
945 goto out;
946 }
947
948 if (edid && edid->type == ACPI_TYPE_BUFFER) {
949 for (i = 0; i < edid->buffer.length; i++)
950 seq_putc(seq, edid->buffer.pointer[i]);
951 }
952
Len Brown4be44fc2005-08-05 00:44:28 -0400953 out:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700954 if (!edid)
955 seq_printf(seq, "<not supported>\n");
956 else
957 kfree(edid);
958
Patrick Mocheld550d982006-06-27 00:41:40 -0400959 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700960}
961
962static int
Len Brown4be44fc2005-08-05 00:44:28 -0400963acpi_video_device_EDID_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700964{
965 return single_open(file, acpi_video_device_EDID_seq_show,
966 PDE(inode)->data);
967}
968
Len Brown4be44fc2005-08-05 00:44:28 -0400969static int acpi_video_device_add_fs(struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700970{
Len Brown4be44fc2005-08-05 00:44:28 -0400971 struct proc_dir_entry *entry = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700972 struct acpi_video_device *vid_dev;
973
Linus Torvalds1da177e2005-04-16 15:20:36 -0700974
975 if (!device)
Patrick Mocheld550d982006-06-27 00:41:40 -0400976 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700977
Jan Engelhardt50dd0962006-10-01 00:28:50 +0200978 vid_dev = acpi_driver_data(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700979 if (!vid_dev)
Patrick Mocheld550d982006-06-27 00:41:40 -0400980 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700981
982 if (!acpi_device_dir(device)) {
983 acpi_device_dir(device) = proc_mkdir(acpi_device_bid(device),
Len Brown4be44fc2005-08-05 00:44:28 -0400984 vid_dev->video->dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700985 if (!acpi_device_dir(device))
Patrick Mocheld550d982006-06-27 00:41:40 -0400986 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700987 acpi_device_dir(device)->owner = THIS_MODULE;
988 }
989
990 /* 'info' [R] */
991 entry = create_proc_entry("info", S_IRUGO, acpi_device_dir(device));
992 if (!entry)
Patrick Mocheld550d982006-06-27 00:41:40 -0400993 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700994 else {
995 entry->proc_fops = &acpi_video_device_info_fops;
996 entry->data = acpi_driver_data(device);
997 entry->owner = THIS_MODULE;
998 }
999
1000 /* 'state' [R/W] */
Len Brown4be44fc2005-08-05 00:44:28 -04001001 entry =
1002 create_proc_entry("state", S_IFREG | S_IRUGO | S_IWUSR,
1003 acpi_device_dir(device));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001004 if (!entry)
Patrick Mocheld550d982006-06-27 00:41:40 -04001005 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001006 else {
Arjan van de Vend479e902006-01-06 16:47:00 -05001007 acpi_video_device_state_fops.write = acpi_video_device_write_state;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001008 entry->proc_fops = &acpi_video_device_state_fops;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001009 entry->data = acpi_driver_data(device);
1010 entry->owner = THIS_MODULE;
1011 }
1012
1013 /* 'brightness' [R/W] */
Len Brown4be44fc2005-08-05 00:44:28 -04001014 entry =
1015 create_proc_entry("brightness", S_IFREG | S_IRUGO | S_IWUSR,
1016 acpi_device_dir(device));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001017 if (!entry)
Patrick Mocheld550d982006-06-27 00:41:40 -04001018 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001019 else {
Arjan van de Vend479e902006-01-06 16:47:00 -05001020 acpi_video_device_brightness_fops.write = acpi_video_device_write_brightness;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001021 entry->proc_fops = &acpi_video_device_brightness_fops;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001022 entry->data = acpi_driver_data(device);
1023 entry->owner = THIS_MODULE;
1024 }
1025
1026 /* 'EDID' [R] */
1027 entry = create_proc_entry("EDID", S_IRUGO, acpi_device_dir(device));
1028 if (!entry)
Patrick Mocheld550d982006-06-27 00:41:40 -04001029 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001030 else {
1031 entry->proc_fops = &acpi_video_device_EDID_fops;
1032 entry->data = acpi_driver_data(device);
1033 entry->owner = THIS_MODULE;
1034 }
1035
Patrick Mocheld550d982006-06-27 00:41:40 -04001036 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001037}
1038
Len Brown4be44fc2005-08-05 00:44:28 -04001039static int acpi_video_device_remove_fs(struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001040{
1041 struct acpi_video_device *vid_dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001042
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001043 vid_dev = acpi_driver_data(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001044 if (!vid_dev || !vid_dev->video || !vid_dev->video->dir)
Patrick Mocheld550d982006-06-27 00:41:40 -04001045 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001046
1047 if (acpi_device_dir(device)) {
1048 remove_proc_entry("info", acpi_device_dir(device));
1049 remove_proc_entry("state", acpi_device_dir(device));
1050 remove_proc_entry("brightness", acpi_device_dir(device));
1051 remove_proc_entry("EDID", acpi_device_dir(device));
Len Brown4be44fc2005-08-05 00:44:28 -04001052 remove_proc_entry(acpi_device_bid(device), vid_dev->video->dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001053 acpi_device_dir(device) = NULL;
1054 }
1055
Patrick Mocheld550d982006-06-27 00:41:40 -04001056 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001057}
1058
Linus Torvalds1da177e2005-04-16 15:20:36 -07001059/* video bus */
Len Brown4be44fc2005-08-05 00:44:28 -04001060static int acpi_video_bus_info_seq_show(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001061{
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001062 struct acpi_video_bus *video = seq->private;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001063
Linus Torvalds1da177e2005-04-16 15:20:36 -07001064
1065 if (!video)
1066 goto end;
1067
1068 seq_printf(seq, "Switching heads: %s\n",
Len Brown4be44fc2005-08-05 00:44:28 -04001069 video->flags.multihead ? "yes" : "no");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001070 seq_printf(seq, "Video ROM: %s\n",
Len Brown4be44fc2005-08-05 00:44:28 -04001071 video->flags.rom ? "yes" : "no");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001072 seq_printf(seq, "Device to be POSTed on boot: %s\n",
Len Brown4be44fc2005-08-05 00:44:28 -04001073 video->flags.post ? "yes" : "no");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001074
Len Brown4be44fc2005-08-05 00:44:28 -04001075 end:
Patrick Mocheld550d982006-06-27 00:41:40 -04001076 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001077}
1078
Len Brown4be44fc2005-08-05 00:44:28 -04001079static int acpi_video_bus_info_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001080{
Len Brown4be44fc2005-08-05 00:44:28 -04001081 return single_open(file, acpi_video_bus_info_seq_show,
1082 PDE(inode)->data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001083}
1084
Len Brown4be44fc2005-08-05 00:44:28 -04001085static int acpi_video_bus_ROM_seq_show(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001086{
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001087 struct acpi_video_bus *video = seq->private;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001088
Linus Torvalds1da177e2005-04-16 15:20:36 -07001089
1090 if (!video)
1091 goto end;
1092
1093 printk(KERN_INFO PREFIX "Please implement %s\n", __FUNCTION__);
1094 seq_printf(seq, "<TODO>\n");
1095
Len Brown4be44fc2005-08-05 00:44:28 -04001096 end:
Patrick Mocheld550d982006-06-27 00:41:40 -04001097 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001098}
1099
Len Brown4be44fc2005-08-05 00:44:28 -04001100static int acpi_video_bus_ROM_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001101{
1102 return single_open(file, acpi_video_bus_ROM_seq_show, PDE(inode)->data);
1103}
1104
Len Brown4be44fc2005-08-05 00:44:28 -04001105static int acpi_video_bus_POST_info_seq_show(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001106{
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001107 struct acpi_video_bus *video = seq->private;
Len Brown4be44fc2005-08-05 00:44:28 -04001108 unsigned long options;
1109 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001110
Linus Torvalds1da177e2005-04-16 15:20:36 -07001111
1112 if (!video)
1113 goto end;
1114
1115 status = acpi_video_bus_POST_options(video, &options);
1116 if (ACPI_SUCCESS(status)) {
1117 if (!(options & 1)) {
Len Brown4be44fc2005-08-05 00:44:28 -04001118 printk(KERN_WARNING PREFIX
1119 "The motherboard VGA device is not listed as a possible POST device.\n");
1120 printk(KERN_WARNING PREFIX
Julius Volz98fb8fe2007-02-20 16:38:40 +01001121 "This indicates a BIOS bug. Please contact the manufacturer.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001122 }
1123 printk("%lx\n", options);
Julius Volz98fb8fe2007-02-20 16:38:40 +01001124 seq_printf(seq, "can POST: <integrated video>");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001125 if (options & 2)
1126 seq_printf(seq, " <PCI video>");
1127 if (options & 4)
1128 seq_printf(seq, " <AGP video>");
1129 seq_putc(seq, '\n');
1130 } else
1131 seq_printf(seq, "<not supported>\n");
Len Brown4be44fc2005-08-05 00:44:28 -04001132 end:
Patrick Mocheld550d982006-06-27 00:41:40 -04001133 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001134}
1135
1136static int
Len Brown4be44fc2005-08-05 00:44:28 -04001137acpi_video_bus_POST_info_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001138{
Len Brown4be44fc2005-08-05 00:44:28 -04001139 return single_open(file, acpi_video_bus_POST_info_seq_show,
1140 PDE(inode)->data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001141}
1142
Len Brown4be44fc2005-08-05 00:44:28 -04001143static int acpi_video_bus_POST_seq_show(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001144{
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001145 struct acpi_video_bus *video = seq->private;
Len Brown4be44fc2005-08-05 00:44:28 -04001146 int status;
1147 unsigned long id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001148
Linus Torvalds1da177e2005-04-16 15:20:36 -07001149
1150 if (!video)
1151 goto end;
1152
Len Brown4be44fc2005-08-05 00:44:28 -04001153 status = acpi_video_bus_get_POST(video, &id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001154 if (!ACPI_SUCCESS(status)) {
1155 seq_printf(seq, "<not supported>\n");
1156 goto end;
1157 }
Julius Volz98fb8fe2007-02-20 16:38:40 +01001158 seq_printf(seq, "device POSTed is <%s>\n", device_decode[id & 3]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001159
Len Brown4be44fc2005-08-05 00:44:28 -04001160 end:
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_DOS_seq_show(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001165{
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001166 struct acpi_video_bus *video = seq->private;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001167
Linus Torvalds1da177e2005-04-16 15:20:36 -07001168
Len Brown4be44fc2005-08-05 00:44:28 -04001169 seq_printf(seq, "DOS setting: <%d>\n", video->dos_setting);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001170
Patrick Mocheld550d982006-06-27 00:41:40 -04001171 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001172}
1173
Len Brown4be44fc2005-08-05 00:44:28 -04001174static int acpi_video_bus_POST_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001175{
Len Brown4be44fc2005-08-05 00:44:28 -04001176 return single_open(file, acpi_video_bus_POST_seq_show,
1177 PDE(inode)->data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001178}
1179
Len Brown4be44fc2005-08-05 00:44:28 -04001180static int acpi_video_bus_DOS_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001181{
1182 return single_open(file, acpi_video_bus_DOS_seq_show, PDE(inode)->data);
1183}
1184
1185static ssize_t
Len Brown4be44fc2005-08-05 00:44:28 -04001186acpi_video_bus_write_POST(struct file *file,
1187 const char __user * buffer,
1188 size_t count, loff_t * data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001189{
Len Brown4be44fc2005-08-05 00:44:28 -04001190 int status;
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001191 struct seq_file *m = file->private_data;
1192 struct acpi_video_bus *video = m->private;
Len Brown4be44fc2005-08-05 00:44:28 -04001193 char str[12] = { 0 };
1194 unsigned long opt, options;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001195
Linus Torvalds1da177e2005-04-16 15:20:36 -07001196
Linus Torvalds1da177e2005-04-16 15:20:36 -07001197 if (!video || count + 1 > sizeof str)
Patrick Mocheld550d982006-06-27 00:41:40 -04001198 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001199
1200 status = acpi_video_bus_POST_options(video, &options);
1201 if (!ACPI_SUCCESS(status))
Patrick Mocheld550d982006-06-27 00:41:40 -04001202 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001203
1204 if (copy_from_user(str, buffer, count))
Patrick Mocheld550d982006-06-27 00:41:40 -04001205 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001206
1207 str[count] = 0;
1208 opt = strtoul(str, NULL, 0);
1209 if (opt > 3)
Patrick Mocheld550d982006-06-27 00:41:40 -04001210 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001211
Julius Volz98fb8fe2007-02-20 16:38:40 +01001212 /* just in case an OEM 'forgot' the motherboard... */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001213 options |= 1;
1214
1215 if (options & (1ul << opt)) {
Len Brown4be44fc2005-08-05 00:44:28 -04001216 status = acpi_video_bus_set_POST(video, opt);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001217 if (!ACPI_SUCCESS(status))
Patrick Mocheld550d982006-06-27 00:41:40 -04001218 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001219
1220 }
1221
Patrick Mocheld550d982006-06-27 00:41:40 -04001222 return count;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001223}
1224
1225static ssize_t
Len Brown4be44fc2005-08-05 00:44:28 -04001226acpi_video_bus_write_DOS(struct file *file,
1227 const char __user * buffer,
1228 size_t count, loff_t * data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001229{
Len Brown4be44fc2005-08-05 00:44:28 -04001230 int status;
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001231 struct seq_file *m = file->private_data;
1232 struct acpi_video_bus *video = m->private;
Len Brown4be44fc2005-08-05 00:44:28 -04001233 char str[12] = { 0 };
1234 unsigned long opt;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001235
Linus Torvalds1da177e2005-04-16 15:20:36 -07001236
Linus Torvalds1da177e2005-04-16 15:20:36 -07001237 if (!video || count + 1 > sizeof str)
Patrick Mocheld550d982006-06-27 00:41:40 -04001238 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001239
1240 if (copy_from_user(str, buffer, count))
Patrick Mocheld550d982006-06-27 00:41:40 -04001241 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001242
1243 str[count] = 0;
1244 opt = strtoul(str, NULL, 0);
1245 if (opt > 7)
Patrick Mocheld550d982006-06-27 00:41:40 -04001246 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001247
Len Brown4be44fc2005-08-05 00:44:28 -04001248 status = acpi_video_bus_DOS(video, opt & 0x3, (opt & 0x4) >> 2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001249
1250 if (!ACPI_SUCCESS(status))
Patrick Mocheld550d982006-06-27 00:41:40 -04001251 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001252
Patrick Mocheld550d982006-06-27 00:41:40 -04001253 return count;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001254}
1255
Len Brown4be44fc2005-08-05 00:44:28 -04001256static int acpi_video_bus_add_fs(struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001257{
Len Brown4be44fc2005-08-05 00:44:28 -04001258 struct proc_dir_entry *entry = NULL;
1259 struct acpi_video_bus *video;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001260
Linus Torvalds1da177e2005-04-16 15:20:36 -07001261
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001262 video = acpi_driver_data(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001263
1264 if (!acpi_device_dir(device)) {
1265 acpi_device_dir(device) = proc_mkdir(acpi_device_bid(device),
Len Brown4be44fc2005-08-05 00:44:28 -04001266 acpi_video_dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001267 if (!acpi_device_dir(device))
Patrick Mocheld550d982006-06-27 00:41:40 -04001268 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001269 video->dir = acpi_device_dir(device);
1270 acpi_device_dir(device)->owner = THIS_MODULE;
1271 }
1272
1273 /* 'info' [R] */
1274 entry = create_proc_entry("info", 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_info_fops;
1279 entry->data = acpi_driver_data(device);
1280 entry->owner = THIS_MODULE;
1281 }
1282
1283 /* 'ROM' [R] */
1284 entry = create_proc_entry("ROM", S_IRUGO, acpi_device_dir(device));
1285 if (!entry)
Patrick Mocheld550d982006-06-27 00:41:40 -04001286 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001287 else {
1288 entry->proc_fops = &acpi_video_bus_ROM_fops;
1289 entry->data = acpi_driver_data(device);
1290 entry->owner = THIS_MODULE;
1291 }
1292
1293 /* 'POST_info' [R] */
Len Brown4be44fc2005-08-05 00:44:28 -04001294 entry =
1295 create_proc_entry("POST_info", S_IRUGO, acpi_device_dir(device));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001296 if (!entry)
Patrick Mocheld550d982006-06-27 00:41:40 -04001297 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001298 else {
1299 entry->proc_fops = &acpi_video_bus_POST_info_fops;
1300 entry->data = acpi_driver_data(device);
1301 entry->owner = THIS_MODULE;
1302 }
1303
1304 /* 'POST' [R/W] */
Len Brown4be44fc2005-08-05 00:44:28 -04001305 entry =
1306 create_proc_entry("POST", S_IFREG | S_IRUGO | S_IRUSR,
1307 acpi_device_dir(device));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001308 if (!entry)
Patrick Mocheld550d982006-06-27 00:41:40 -04001309 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001310 else {
Arjan van de Vend479e902006-01-06 16:47:00 -05001311 acpi_video_bus_POST_fops.write = acpi_video_bus_write_POST;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001312 entry->proc_fops = &acpi_video_bus_POST_fops;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001313 entry->data = acpi_driver_data(device);
1314 entry->owner = THIS_MODULE;
1315 }
1316
1317 /* 'DOS' [R/W] */
Len Brown4be44fc2005-08-05 00:44:28 -04001318 entry =
1319 create_proc_entry("DOS", S_IFREG | S_IRUGO | S_IRUSR,
1320 acpi_device_dir(device));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001321 if (!entry)
Patrick Mocheld550d982006-06-27 00:41:40 -04001322 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001323 else {
Arjan van de Vend479e902006-01-06 16:47:00 -05001324 acpi_video_bus_DOS_fops.write = acpi_video_bus_write_DOS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001325 entry->proc_fops = &acpi_video_bus_DOS_fops;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001326 entry->data = acpi_driver_data(device);
1327 entry->owner = THIS_MODULE;
1328 }
1329
Patrick Mocheld550d982006-06-27 00:41:40 -04001330 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001331}
1332
Len Brown4be44fc2005-08-05 00:44:28 -04001333static int acpi_video_bus_remove_fs(struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001334{
Len Brown4be44fc2005-08-05 00:44:28 -04001335 struct acpi_video_bus *video;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001336
Linus Torvalds1da177e2005-04-16 15:20:36 -07001337
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001338 video = acpi_driver_data(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001339
1340 if (acpi_device_dir(device)) {
1341 remove_proc_entry("info", acpi_device_dir(device));
1342 remove_proc_entry("ROM", acpi_device_dir(device));
1343 remove_proc_entry("POST_info", acpi_device_dir(device));
1344 remove_proc_entry("POST", acpi_device_dir(device));
1345 remove_proc_entry("DOS", acpi_device_dir(device));
Len Brown4be44fc2005-08-05 00:44:28 -04001346 remove_proc_entry(acpi_device_bid(device), acpi_video_dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001347 acpi_device_dir(device) = NULL;
1348 }
1349
Patrick Mocheld550d982006-06-27 00:41:40 -04001350 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001351}
1352
1353/* --------------------------------------------------------------------------
1354 Driver Interface
1355 -------------------------------------------------------------------------- */
1356
1357/* device interface */
Rui Zhang82cae992007-01-03 23:40:53 -05001358static struct acpi_video_device_attrib*
1359acpi_video_get_device_attr(struct acpi_video_bus *video, unsigned long device_id)
1360{
1361 int count;
1362
1363 for(count = 0; count < video->attached_count; count++)
1364 if((video->attached_array[count].value.int_val & 0xffff) == device_id)
1365 return &(video->attached_array[count].value.attrib);
1366 return NULL;
1367}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001368
1369static int
Len Brown4be44fc2005-08-05 00:44:28 -04001370acpi_video_bus_get_one_device(struct acpi_device *device,
1371 struct acpi_video_bus *video)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001372{
Len Brown4be44fc2005-08-05 00:44:28 -04001373 unsigned long device_id;
Yu, Luming973bf492006-04-27 05:25:00 -04001374 int status;
Len Brown4be44fc2005-08-05 00:44:28 -04001375 struct acpi_video_device *data;
Rui Zhang82cae992007-01-03 23:40:53 -05001376 struct acpi_video_device_attrib* attribute;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001377
1378 if (!device || !video)
Patrick Mocheld550d982006-06-27 00:41:40 -04001379 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001380
Len Brown4be44fc2005-08-05 00:44:28 -04001381 status =
1382 acpi_evaluate_integer(device->handle, "_ADR", NULL, &device_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001383 if (ACPI_SUCCESS(status)) {
1384
Burman Yan36bcbec2006-12-19 12:56:11 -08001385 data = kzalloc(sizeof(struct acpi_video_device), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001386 if (!data)
Patrick Mocheld550d982006-06-27 00:41:40 -04001387 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001388
Linus Torvalds1da177e2005-04-16 15:20:36 -07001389 strcpy(acpi_device_name(device), ACPI_VIDEO_DEVICE_NAME);
1390 strcpy(acpi_device_class(device), ACPI_VIDEO_CLASS);
1391 acpi_driver_data(device) = data;
1392
1393 data->device_id = device_id;
1394 data->video = video;
1395 data->dev = device;
1396
Rui Zhang82cae992007-01-03 23:40:53 -05001397 attribute = acpi_video_get_device_attr(video, device_id);
1398
1399 if((attribute != NULL) && attribute->device_id_scheme) {
1400 switch (attribute->display_type) {
1401 case ACPI_VIDEO_DISPLAY_CRT:
1402 data->flags.crt = 1;
1403 break;
1404 case ACPI_VIDEO_DISPLAY_TV:
1405 data->flags.tvout = 1;
1406 break;
1407 case ACPI_VIDEO_DISPLAY_DVI:
1408 data->flags.dvi = 1;
1409 break;
1410 case ACPI_VIDEO_DISPLAY_LCD:
1411 data->flags.lcd = 1;
1412 break;
1413 default:
1414 data->flags.unknown = 1;
1415 break;
1416 }
1417 if(attribute->bios_can_detect)
1418 data->flags.bios = 1;
1419 } else
Linus Torvalds1da177e2005-04-16 15:20:36 -07001420 data->flags.unknown = 1;
Len Brown4be44fc2005-08-05 00:44:28 -04001421
Linus Torvalds1da177e2005-04-16 15:20:36 -07001422 acpi_video_device_bind(video, data);
1423 acpi_video_device_find_cap(data);
1424
Patrick Mochel90130262006-05-19 16:54:48 -04001425 status = acpi_install_notify_handler(device->handle,
Len Brown4be44fc2005-08-05 00:44:28 -04001426 ACPI_DEVICE_NOTIFY,
1427 acpi_video_device_notify,
1428 data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001429 if (ACPI_FAILURE(status)) {
1430 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
Len Brown4be44fc2005-08-05 00:44:28 -04001431 "Error installing notify handler\n"));
Yu, Luming973bf492006-04-27 05:25:00 -04001432 if(data->brightness)
1433 kfree(data->brightness->levels);
1434 kfree(data->brightness);
1435 kfree(data);
1436 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001437 }
1438
1439 down(&video->sem);
1440 list_add_tail(&data->entry, &video->video_device_list);
1441 up(&video->sem);
1442
1443 acpi_video_device_add_fs(device);
1444
Patrick Mocheld550d982006-06-27 00:41:40 -04001445 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001446 }
1447
Patrick Mocheld550d982006-06-27 00:41:40 -04001448 return -ENOENT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001449}
1450
1451/*
1452 * Arg:
1453 * video : video bus device
1454 *
1455 * Return:
1456 * none
1457 *
1458 * Enumerate the video device list of the video bus,
1459 * bind the ids with the corresponding video devices
1460 * under the video bus.
Len Brown4be44fc2005-08-05 00:44:28 -04001461 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001462
Len Brown4be44fc2005-08-05 00:44:28 -04001463static void acpi_video_device_rebind(struct acpi_video_bus *video)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001464{
Len Brown4be44fc2005-08-05 00:44:28 -04001465 struct list_head *node, *next;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001466 list_for_each_safe(node, next, &video->video_device_list) {
Len Brown4be44fc2005-08-05 00:44:28 -04001467 struct acpi_video_device *dev =
1468 container_of(node, struct acpi_video_device, entry);
1469 acpi_video_device_bind(video, dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001470 }
1471}
1472
1473/*
1474 * Arg:
1475 * video : video bus device
1476 * device : video output device under the video
1477 * bus
1478 *
1479 * Return:
1480 * none
1481 *
1482 * Bind the ids with the corresponding video devices
1483 * under the video bus.
Len Brown4be44fc2005-08-05 00:44:28 -04001484 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001485
1486static void
Len Brown4be44fc2005-08-05 00:44:28 -04001487acpi_video_device_bind(struct acpi_video_bus *video,
1488 struct acpi_video_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001489{
Len Brown4be44fc2005-08-05 00:44:28 -04001490 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001491
1492#define IDS_VAL(i) video->attached_array[i].value.int_val
1493#define IDS_BIND(i) video->attached_array[i].bind_info
Len Brown4be44fc2005-08-05 00:44:28 -04001494
1495 for (i = 0; IDS_VAL(i) != ACPI_VIDEO_HEAD_INVALID &&
1496 i < video->attached_count; i++) {
1497 if (device->device_id == (IDS_VAL(i) & 0xffff)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001498 IDS_BIND(i) = device;
1499 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "device_bind %d\n", i));
1500 }
1501 }
1502#undef IDS_VAL
1503#undef IDS_BIND
1504}
1505
1506/*
1507 * Arg:
1508 * video : video bus device
1509 *
1510 * Return:
1511 * < 0 : error
1512 *
1513 * Call _DOD to enumerate all devices attached to display adapter
1514 *
Len Brown4be44fc2005-08-05 00:44:28 -04001515 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001516
1517static int acpi_video_device_enumerate(struct acpi_video_bus *video)
1518{
Len Brown4be44fc2005-08-05 00:44:28 -04001519 int status;
1520 int count;
1521 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001522 struct acpi_video_enumerated_device *active_device_list;
Len Brown4be44fc2005-08-05 00:44:28 -04001523 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
1524 union acpi_object *dod = NULL;
1525 union acpi_object *obj;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001526
Patrick Mochel90130262006-05-19 16:54:48 -04001527 status = acpi_evaluate_object(video->device->handle, "_DOD", NULL, &buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001528 if (!ACPI_SUCCESS(status)) {
Thomas Renningera6fc6722006-06-26 23:58:43 -04001529 ACPI_EXCEPTION((AE_INFO, status, "Evaluating _DOD"));
Patrick Mocheld550d982006-06-27 00:41:40 -04001530 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001531 }
1532
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001533 dod = buffer.pointer;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001534 if (!dod || (dod->type != ACPI_TYPE_PACKAGE)) {
Thomas Renningera6fc6722006-06-26 23:58:43 -04001535 ACPI_EXCEPTION((AE_INFO, status, "Invalid _DOD data"));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001536 status = -EFAULT;
1537 goto out;
1538 }
1539
1540 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found %d video heads in _DOD\n",
Len Brown4be44fc2005-08-05 00:44:28 -04001541 dod->package.count));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001542
Len Brown4be44fc2005-08-05 00:44:28 -04001543 active_device_list = kmalloc((1 +
1544 dod->package.count) *
1545 sizeof(struct
1546 acpi_video_enumerated_device),
1547 GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001548
1549 if (!active_device_list) {
1550 status = -ENOMEM;
1551 goto out;
1552 }
1553
1554 count = 0;
1555 for (i = 0; i < dod->package.count; i++) {
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001556 obj = &dod->package.elements[i];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001557
1558 if (obj->type != ACPI_TYPE_INTEGER) {
Len Brown64684632006-06-26 23:41:38 -04001559 printk(KERN_ERR PREFIX "Invalid _DOD data\n");
Len Brown4be44fc2005-08-05 00:44:28 -04001560 active_device_list[i].value.int_val =
1561 ACPI_VIDEO_HEAD_INVALID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001562 }
1563 active_device_list[i].value.int_val = obj->integer.value;
1564 active_device_list[i].bind_info = NULL;
Len Brown4be44fc2005-08-05 00:44:28 -04001565 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "dod element[%d] = %d\n", i,
1566 (int)obj->integer.value));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001567 count++;
1568 }
1569 active_device_list[count].value.int_val = ACPI_VIDEO_HEAD_END;
1570
Jesper Juhl6044ec82005-11-07 01:01:32 -08001571 kfree(video->attached_array);
Len Brown4be44fc2005-08-05 00:44:28 -04001572
Linus Torvalds1da177e2005-04-16 15:20:36 -07001573 video->attached_array = active_device_list;
1574 video->attached_count = count;
Len Brown4be44fc2005-08-05 00:44:28 -04001575 out:
Len Brown02438d82006-06-30 03:19:10 -04001576 kfree(buffer.pointer);
Patrick Mocheld550d982006-06-27 00:41:40 -04001577 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001578}
1579
1580/*
1581 * Arg:
1582 * video : video bus device
Julius Volz98fb8fe2007-02-20 16:38:40 +01001583 * event : notify event
Linus Torvalds1da177e2005-04-16 15:20:36 -07001584 *
1585 * Return:
1586 * < 0 : error
1587 *
1588 * 1. Find out the current active output device.
Julius Volz98fb8fe2007-02-20 16:38:40 +01001589 * 2. Identify the next output device to switch to.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001590 * 3. call _DSS to do actual switch.
Len Brown4be44fc2005-08-05 00:44:28 -04001591 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001592
Len Brown4be44fc2005-08-05 00:44:28 -04001593static int acpi_video_switch_output(struct acpi_video_bus *video, int event)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001594{
Len Brown4be44fc2005-08-05 00:44:28 -04001595 struct list_head *node, *next;
1596 struct acpi_video_device *dev = NULL;
1597 struct acpi_video_device *dev_next = NULL;
1598 struct acpi_video_device *dev_prev = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001599 unsigned long state;
1600 int status = 0;
1601
Linus Torvalds1da177e2005-04-16 15:20:36 -07001602
1603 list_for_each_safe(node, next, &video->video_device_list) {
Adrian Bunk73345712005-03-30 22:31:35 -05001604 dev = container_of(node, struct acpi_video_device, entry);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001605 status = acpi_video_device_get_state(dev, &state);
Len Brown4be44fc2005-08-05 00:44:28 -04001606 if (state & 0x2) {
1607 dev_next =
1608 container_of(node->next, struct acpi_video_device,
1609 entry);
1610 dev_prev =
1611 container_of(node->prev, struct acpi_video_device,
1612 entry);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001613 goto out;
1614 }
1615 }
1616 dev_next = container_of(node->next, struct acpi_video_device, entry);
1617 dev_prev = container_of(node->prev, struct acpi_video_device, entry);
Len Brown4be44fc2005-08-05 00:44:28 -04001618 out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001619 switch (event) {
1620 case ACPI_VIDEO_NOTIFY_CYCLE:
1621 case ACPI_VIDEO_NOTIFY_NEXT_OUTPUT:
1622 acpi_video_device_set_state(dev, 0);
1623 acpi_video_device_set_state(dev_next, 0x80000001);
1624 break;
1625 case ACPI_VIDEO_NOTIFY_PREV_OUTPUT:
1626 acpi_video_device_set_state(dev, 0);
1627 acpi_video_device_set_state(dev_prev, 0x80000001);
1628 default:
1629 break;
1630 }
1631
Patrick Mocheld550d982006-06-27 00:41:40 -04001632 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001633}
1634
Len Brown4be44fc2005-08-05 00:44:28 -04001635static int
1636acpi_video_get_next_level(struct acpi_video_device *device,
1637 u32 level_current, u32 event)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001638{
Alexey Starikovskiy63f0edf2007-09-03 16:30:08 +04001639 int min, max, min_above, max_below, i, l, delta = 255;
Thomas Tuttlef4715182006-12-19 12:56:14 -08001640 max = max_below = 0;
1641 min = min_above = 255;
Alexey Starikovskiy63f0edf2007-09-03 16:30:08 +04001642 /* Find closest level to level_current */
1643 for (i = 0; i < device->brightness->count; i++) {
1644 l = device->brightness->levels[i];
1645 if (abs(l - level_current) < abs(delta)) {
1646 delta = l - level_current;
1647 if (!delta)
1648 break;
1649 }
1650 }
1651 /* Ajust level_current to closest available level */
1652 level_current += delta;
Thomas Tuttlef4715182006-12-19 12:56:14 -08001653 for (i = 0; i < device->brightness->count; i++) {
1654 l = device->brightness->levels[i];
1655 if (l < min)
1656 min = l;
1657 if (l > max)
1658 max = l;
1659 if (l < min_above && l > level_current)
1660 min_above = l;
1661 if (l > max_below && l < level_current)
1662 max_below = l;
1663 }
1664
1665 switch (event) {
1666 case ACPI_VIDEO_NOTIFY_CYCLE_BRIGHTNESS:
1667 return (level_current < max) ? min_above : min;
1668 case ACPI_VIDEO_NOTIFY_INC_BRIGHTNESS:
1669 return (level_current < max) ? min_above : max;
1670 case ACPI_VIDEO_NOTIFY_DEC_BRIGHTNESS:
1671 return (level_current > min) ? max_below : min;
1672 case ACPI_VIDEO_NOTIFY_ZERO_BRIGHTNESS:
1673 case ACPI_VIDEO_NOTIFY_DISPLAY_OFF:
1674 return 0;
1675 default:
1676 return level_current;
1677 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001678}
1679
Linus Torvalds1da177e2005-04-16 15:20:36 -07001680static void
Len Brown4be44fc2005-08-05 00:44:28 -04001681acpi_video_switch_brightness(struct acpi_video_device *device, int event)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001682{
1683 unsigned long level_current, level_next;
1684 acpi_video_device_lcd_get_level_current(device, &level_current);
1685 level_next = acpi_video_get_next_level(device, level_current, event);
1686 acpi_video_device_lcd_set_level(device, level_next);
1687}
1688
1689static int
Len Brown4be44fc2005-08-05 00:44:28 -04001690acpi_video_bus_get_devices(struct acpi_video_bus *video,
1691 struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001692{
Len Brown4be44fc2005-08-05 00:44:28 -04001693 int status = 0;
1694 struct list_head *node, *next;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001695
Linus Torvalds1da177e2005-04-16 15:20:36 -07001696
1697 acpi_video_device_enumerate(video);
1698
1699 list_for_each_safe(node, next, &device->children) {
Len Brown4be44fc2005-08-05 00:44:28 -04001700 struct acpi_device *dev =
1701 list_entry(node, struct acpi_device, node);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001702
1703 if (!dev)
1704 continue;
1705
1706 status = acpi_video_bus_get_one_device(dev, video);
1707 if (ACPI_FAILURE(status)) {
Thomas Renningera6fc6722006-06-26 23:58:43 -04001708 ACPI_EXCEPTION((AE_INFO, status, "Cant attach device"));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001709 continue;
1710 }
1711
1712 }
Patrick Mocheld550d982006-06-27 00:41:40 -04001713 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001714}
1715
Len Brown4be44fc2005-08-05 00:44:28 -04001716static int acpi_video_bus_put_one_device(struct acpi_video_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001717{
Karol Kozimor031ec772005-07-30 04:18:00 -04001718 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001719 struct acpi_video_bus *video;
1720
Linus Torvalds1da177e2005-04-16 15:20:36 -07001721
1722 if (!device || !device->video)
Patrick Mocheld550d982006-06-27 00:41:40 -04001723 return -ENOENT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001724
1725 video = device->video;
1726
1727 down(&video->sem);
1728 list_del(&device->entry);
1729 up(&video->sem);
1730 acpi_video_device_remove_fs(device->dev);
1731
Patrick Mochel90130262006-05-19 16:54:48 -04001732 status = acpi_remove_notify_handler(device->dev->handle,
Len Brown4be44fc2005-08-05 00:44:28 -04001733 ACPI_DEVICE_NOTIFY,
1734 acpi_video_device_notify);
Richard Purdie599a52d2007-02-10 23:07:48 +00001735 backlight_device_unregister(device->backlight);
Luming Yu23b0f012007-05-09 21:07:05 +08001736 video_output_unregister(device->output_dev);
Patrick Mocheld550d982006-06-27 00:41:40 -04001737 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001738}
1739
Len Brown4be44fc2005-08-05 00:44:28 -04001740static int acpi_video_bus_put_devices(struct acpi_video_bus *video)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001741{
Len Brown4be44fc2005-08-05 00:44:28 -04001742 int status;
1743 struct list_head *node, *next;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001744
Linus Torvalds1da177e2005-04-16 15:20:36 -07001745
1746 list_for_each_safe(node, next, &video->video_device_list) {
Len Brown4be44fc2005-08-05 00:44:28 -04001747 struct acpi_video_device *data =
1748 list_entry(node, struct acpi_video_device, entry);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001749 if (!data)
1750 continue;
1751
1752 status = acpi_video_bus_put_one_device(data);
Len Brown4be44fc2005-08-05 00:44:28 -04001753 if (ACPI_FAILURE(status))
1754 printk(KERN_WARNING PREFIX
1755 "hhuuhhuu bug in acpi video driver.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001756
Dave Jonesd384ea62006-06-24 00:33:08 -04001757 if (data->brightness)
Yu, Luming973bf492006-04-27 05:25:00 -04001758 kfree(data->brightness->levels);
Jesper Juhl6044ec82005-11-07 01:01:32 -08001759 kfree(data->brightness);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001760 kfree(data);
1761 }
1762
Patrick Mocheld550d982006-06-27 00:41:40 -04001763 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001764}
1765
1766/* acpi_video interface */
1767
Len Brown4be44fc2005-08-05 00:44:28 -04001768static int acpi_video_bus_start_devices(struct acpi_video_bus *video)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001769{
Zhang Ruia21101c2007-09-14 11:46:22 +08001770 return acpi_video_bus_DOS(video, 0, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001771}
1772
Len Brown4be44fc2005-08-05 00:44:28 -04001773static int acpi_video_bus_stop_devices(struct acpi_video_bus *video)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001774{
1775 return acpi_video_bus_DOS(video, 0, 1);
1776}
1777
Len Brown4be44fc2005-08-05 00:44:28 -04001778static void acpi_video_bus_notify(acpi_handle handle, u32 event, void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001779{
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001780 struct acpi_video_bus *video = data;
Len Brown4be44fc2005-08-05 00:44:28 -04001781 struct acpi_device *device = NULL;
Luming Yue9dab192007-08-20 18:23:53 +08001782 struct input_dev *input;
1783 int keycode;
1784
Linus Torvalds1da177e2005-04-16 15:20:36 -07001785
Linus Torvalds1da177e2005-04-16 15:20:36 -07001786 printk("video bus notify\n");
1787
1788 if (!video)
Patrick Mocheld550d982006-06-27 00:41:40 -04001789 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001790
Patrick Mochele6afa0d2006-05-19 16:54:40 -04001791 device = video->device;
Luming Yue9dab192007-08-20 18:23:53 +08001792 input = video->input;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001793
1794 switch (event) {
Julius Volz98fb8fe2007-02-20 16:38:40 +01001795 case ACPI_VIDEO_NOTIFY_SWITCH: /* User requested a switch,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001796 * most likely via hotkey. */
Len Brown14e04fb2007-08-23 15:20:26 -04001797 acpi_bus_generate_proc_event(device, event, 0);
Luming Yue9dab192007-08-20 18:23:53 +08001798 keycode = KEY_SWITCHVIDEOMODE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001799 break;
1800
Julius Volz98fb8fe2007-02-20 16:38:40 +01001801 case ACPI_VIDEO_NOTIFY_PROBE: /* User plugged in or removed a video
Linus Torvalds1da177e2005-04-16 15:20:36 -07001802 * connector. */
1803 acpi_video_device_enumerate(video);
1804 acpi_video_device_rebind(video);
1805 acpi_video_switch_output(video, event);
Len Brown14e04fb2007-08-23 15:20:26 -04001806 acpi_bus_generate_proc_event(device, event, 0);
Luming Yue9dab192007-08-20 18:23:53 +08001807 keycode = KEY_SWITCHVIDEOMODE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001808 break;
1809
Len Brown4be44fc2005-08-05 00:44:28 -04001810 case ACPI_VIDEO_NOTIFY_CYCLE: /* Cycle Display output hotkey pressed. */
Luming Yue9dab192007-08-20 18:23:53 +08001811 acpi_video_switch_output(video, event);
Len Brown25c87f72007-08-25 01:44:01 -04001812 acpi_bus_generate_proc_event(device, event, 0);
Luming Yue9dab192007-08-20 18:23:53 +08001813 keycode = KEY_SWITCHVIDEOMODE;
1814 break;
Len Brown4be44fc2005-08-05 00:44:28 -04001815 case ACPI_VIDEO_NOTIFY_NEXT_OUTPUT: /* Next Display output hotkey pressed. */
Luming Yue9dab192007-08-20 18:23:53 +08001816 acpi_video_switch_output(video, event);
Len Brown25c87f72007-08-25 01:44:01 -04001817 acpi_bus_generate_proc_event(device, event, 0);
Luming Yue9dab192007-08-20 18:23:53 +08001818 keycode = KEY_VIDEO_NEXT;
1819 break;
Len Brown4be44fc2005-08-05 00:44:28 -04001820 case ACPI_VIDEO_NOTIFY_PREV_OUTPUT: /* previous Display output hotkey pressed. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001821 acpi_video_switch_output(video, event);
Len Brown14e04fb2007-08-23 15:20:26 -04001822 acpi_bus_generate_proc_event(device, event, 0);
Luming Yue9dab192007-08-20 18:23:53 +08001823 keycode = KEY_VIDEO_PREV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001824 break;
1825
1826 default:
Luming Yue9dab192007-08-20 18:23:53 +08001827 keycode = KEY_UNKNOWN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001828 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
Len Brown4be44fc2005-08-05 00:44:28 -04001829 "Unsupported event [0x%x]\n", event));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001830 break;
1831 }
1832
Luming Yue9dab192007-08-20 18:23:53 +08001833 input_report_key(input, keycode, 1);
1834 input_sync(input);
1835 input_report_key(input, keycode, 0);
1836 input_sync(input);
1837
Patrick Mocheld550d982006-06-27 00:41:40 -04001838 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001839}
1840
Len Brown4be44fc2005-08-05 00:44:28 -04001841static void acpi_video_device_notify(acpi_handle handle, u32 event, void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001842{
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001843 struct acpi_video_device *video_device = data;
Len Brown4be44fc2005-08-05 00:44:28 -04001844 struct acpi_device *device = NULL;
Luming Yue9dab192007-08-20 18:23:53 +08001845 struct acpi_video_bus *bus;
1846 struct input_dev *input;
1847 int keycode;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001848
Linus Torvalds1da177e2005-04-16 15:20:36 -07001849 if (!video_device)
Patrick Mocheld550d982006-06-27 00:41:40 -04001850 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001851
Patrick Mochele6afa0d2006-05-19 16:54:40 -04001852 device = video_device->dev;
Luming Yue9dab192007-08-20 18:23:53 +08001853 bus = video_device->video;
1854 input = bus->input;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001855
1856 switch (event) {
Len Brown4be44fc2005-08-05 00:44:28 -04001857 case ACPI_VIDEO_NOTIFY_CYCLE_BRIGHTNESS: /* Cycle brightness */
Luming Yue9dab192007-08-20 18:23:53 +08001858 acpi_video_switch_brightness(video_device, event);
Len Brown25c87f72007-08-25 01:44:01 -04001859 acpi_bus_generate_proc_event(device, event, 0);
Luming Yue9dab192007-08-20 18:23:53 +08001860 keycode = KEY_BRIGHTNESS_CYCLE;
1861 break;
Len Brown4be44fc2005-08-05 00:44:28 -04001862 case ACPI_VIDEO_NOTIFY_INC_BRIGHTNESS: /* Increase brightness */
Luming Yue9dab192007-08-20 18:23:53 +08001863 acpi_video_switch_brightness(video_device, event);
Len Brown25c87f72007-08-25 01:44:01 -04001864 acpi_bus_generate_proc_event(device, event, 0);
Luming Yue9dab192007-08-20 18:23:53 +08001865 keycode = KEY_BRIGHTNESSUP;
1866 break;
Len Brown4be44fc2005-08-05 00:44:28 -04001867 case ACPI_VIDEO_NOTIFY_DEC_BRIGHTNESS: /* Decrease brightness */
Luming Yue9dab192007-08-20 18:23:53 +08001868 acpi_video_switch_brightness(video_device, event);
Len Brown25c87f72007-08-25 01:44:01 -04001869 acpi_bus_generate_proc_event(device, event, 0);
Luming Yue9dab192007-08-20 18:23:53 +08001870 keycode = KEY_BRIGHTNESSDOWN;
1871 break;
Len Brown4be44fc2005-08-05 00:44:28 -04001872 case ACPI_VIDEO_NOTIFY_ZERO_BRIGHTNESS: /* zero brightnesss */
Luming Yue9dab192007-08-20 18:23:53 +08001873 acpi_video_switch_brightness(video_device, event);
Len Brown25c87f72007-08-25 01:44:01 -04001874 acpi_bus_generate_proc_event(device, event, 0);
Luming Yue9dab192007-08-20 18:23:53 +08001875 keycode = KEY_BRIGHTNESS_ZERO;
1876 break;
Len Brown4be44fc2005-08-05 00:44:28 -04001877 case ACPI_VIDEO_NOTIFY_DISPLAY_OFF: /* display device off */
1878 acpi_video_switch_brightness(video_device, event);
Len Brown14e04fb2007-08-23 15:20:26 -04001879 acpi_bus_generate_proc_event(device, event, 0);
Luming Yue9dab192007-08-20 18:23:53 +08001880 keycode = KEY_DISPLAY_OFF;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001881 break;
1882 default:
Luming Yue9dab192007-08-20 18:23:53 +08001883 keycode = KEY_UNKNOWN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001884 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
Len Brown4be44fc2005-08-05 00:44:28 -04001885 "Unsupported event [0x%x]\n", event));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001886 break;
1887 }
Luming Yue9dab192007-08-20 18:23:53 +08001888
1889 input_report_key(input, keycode, 1);
1890 input_sync(input);
1891 input_report_key(input, keycode, 0);
1892 input_sync(input);
1893
Patrick Mocheld550d982006-06-27 00:41:40 -04001894 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001895}
1896
Zhang Ruie6d9da12007-08-25 02:23:31 -04001897static int instance;
Len Brown4be44fc2005-08-05 00:44:28 -04001898static int acpi_video_bus_add(struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001899{
Len Brown4be44fc2005-08-05 00:44:28 -04001900 int result = 0;
1901 acpi_status status = 0;
1902 struct acpi_video_bus *video = NULL;
Luming Yue9dab192007-08-20 18:23:53 +08001903 struct input_dev *input;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001904
Len Brown4be44fc2005-08-05 00:44:28 -04001905
Linus Torvalds1da177e2005-04-16 15:20:36 -07001906 if (!device)
Patrick Mocheld550d982006-06-27 00:41:40 -04001907 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001908
Burman Yan36bcbec2006-12-19 12:56:11 -08001909 video = kzalloc(sizeof(struct acpi_video_bus), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001910 if (!video)
Patrick Mocheld550d982006-06-27 00:41:40 -04001911 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001912
Zhang Ruie6d9da12007-08-25 02:23:31 -04001913 /* a hack to fix the duplicate name "VID" problem on T61 */
1914 if (!strcmp(device->pnp.bus_id, "VID")) {
1915 if (instance)
1916 device->pnp.bus_id[3] = '0' + instance;
1917 instance ++;
1918 }
1919
Patrick Mochele6afa0d2006-05-19 16:54:40 -04001920 video->device = device;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001921 strcpy(acpi_device_name(device), ACPI_VIDEO_BUS_NAME);
1922 strcpy(acpi_device_class(device), ACPI_VIDEO_CLASS);
1923 acpi_driver_data(device) = video;
1924
1925 acpi_video_bus_find_cap(video);
1926 result = acpi_video_bus_check(video);
1927 if (result)
1928 goto end;
1929
1930 result = acpi_video_bus_add_fs(device);
1931 if (result)
1932 goto end;
1933
1934 init_MUTEX(&video->sem);
1935 INIT_LIST_HEAD(&video->video_device_list);
1936
1937 acpi_video_bus_get_devices(video, device);
1938 acpi_video_bus_start_devices(video);
1939
Patrick Mochel90130262006-05-19 16:54:48 -04001940 status = acpi_install_notify_handler(device->handle,
Len Brown4be44fc2005-08-05 00:44:28 -04001941 ACPI_DEVICE_NOTIFY,
1942 acpi_video_bus_notify, video);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001943 if (ACPI_FAILURE(status)) {
1944 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
Len Brown4be44fc2005-08-05 00:44:28 -04001945 "Error installing notify handler\n"));
Yu, Luming973bf492006-04-27 05:25:00 -04001946 acpi_video_bus_stop_devices(video);
1947 acpi_video_bus_put_devices(video);
1948 kfree(video->attached_array);
1949 acpi_video_bus_remove_fs(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001950 result = -ENODEV;
1951 goto end;
1952 }
1953
Luming Yue9dab192007-08-20 18:23:53 +08001954
1955 video->input = input = input_allocate_device();
1956
1957 snprintf(video->phys, sizeof(video->phys),
1958 "%s/video/input0", acpi_device_hid(video->device));
1959
1960 input->name = acpi_device_name(video->device);
1961 input->phys = video->phys;
1962 input->id.bustype = BUS_HOST;
1963 input->id.product = 0x06;
1964 input->evbit[0] = BIT(EV_KEY);
1965 set_bit(KEY_SWITCHVIDEOMODE, input->keybit);
1966 set_bit(KEY_VIDEO_NEXT, input->keybit);
1967 set_bit(KEY_VIDEO_PREV, input->keybit);
1968 set_bit(KEY_BRIGHTNESS_CYCLE, input->keybit);
1969 set_bit(KEY_BRIGHTNESSUP, input->keybit);
1970 set_bit(KEY_BRIGHTNESSDOWN, input->keybit);
1971 set_bit(KEY_BRIGHTNESS_ZERO, input->keybit);
1972 set_bit(KEY_DISPLAY_OFF, input->keybit);
1973 set_bit(KEY_UNKNOWN, input->keybit);
1974 result = input_register_device(input);
1975 if (result) {
1976 acpi_remove_notify_handler(video->device->handle,
1977 ACPI_DEVICE_NOTIFY,
1978 acpi_video_bus_notify);
1979 acpi_video_bus_stop_devices(video);
1980 acpi_video_bus_put_devices(video);
1981 kfree(video->attached_array);
1982 acpi_video_bus_remove_fs(device);
1983 goto end;
1984 }
1985
1986
Linus Torvalds1da177e2005-04-16 15:20:36 -07001987 printk(KERN_INFO PREFIX "%s [%s] (multi-head: %s rom: %s post: %s)\n",
Len Brown4be44fc2005-08-05 00:44:28 -04001988 ACPI_VIDEO_DEVICE_NAME, acpi_device_bid(device),
1989 video->flags.multihead ? "yes" : "no",
1990 video->flags.rom ? "yes" : "no",
1991 video->flags.post ? "yes" : "no");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001992
Len Brown4be44fc2005-08-05 00:44:28 -04001993 end:
Yu, Luming973bf492006-04-27 05:25:00 -04001994 if (result)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001995 kfree(video);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001996
Patrick Mocheld550d982006-06-27 00:41:40 -04001997 return result;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001998}
1999
Len Brown4be44fc2005-08-05 00:44:28 -04002000static int acpi_video_bus_remove(struct acpi_device *device, int type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002001{
Len Brown4be44fc2005-08-05 00:44:28 -04002002 acpi_status status = 0;
2003 struct acpi_video_bus *video = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002004
Linus Torvalds1da177e2005-04-16 15:20:36 -07002005
2006 if (!device || !acpi_driver_data(device))
Patrick Mocheld550d982006-06-27 00:41:40 -04002007 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002008
Jan Engelhardt50dd0962006-10-01 00:28:50 +02002009 video = acpi_driver_data(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002010
2011 acpi_video_bus_stop_devices(video);
2012
Patrick Mochel90130262006-05-19 16:54:48 -04002013 status = acpi_remove_notify_handler(video->device->handle,
Len Brown4be44fc2005-08-05 00:44:28 -04002014 ACPI_DEVICE_NOTIFY,
2015 acpi_video_bus_notify);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002016
2017 acpi_video_bus_put_devices(video);
2018 acpi_video_bus_remove_fs(device);
2019
Luming Yue9dab192007-08-20 18:23:53 +08002020 input_unregister_device(video->input);
Jesper Juhl6044ec82005-11-07 01:01:32 -08002021 kfree(video->attached_array);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002022 kfree(video);
2023
Patrick Mocheld550d982006-06-27 00:41:40 -04002024 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002025}
2026
Len Brown4be44fc2005-08-05 00:44:28 -04002027static int __init acpi_video_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002028{
Len Brown4be44fc2005-08-05 00:44:28 -04002029 int result = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002030
Linus Torvalds1da177e2005-04-16 15:20:36 -07002031
2032 /*
Len Brown4be44fc2005-08-05 00:44:28 -04002033 acpi_dbg_level = 0xFFFFFFFF;
2034 acpi_dbg_layer = 0x08000000;
2035 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002036
2037 acpi_video_dir = proc_mkdir(ACPI_VIDEO_CLASS, acpi_root_dir);
2038 if (!acpi_video_dir)
Patrick Mocheld550d982006-06-27 00:41:40 -04002039 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002040 acpi_video_dir->owner = THIS_MODULE;
2041
2042 result = acpi_bus_register_driver(&acpi_video_bus);
2043 if (result < 0) {
2044 remove_proc_entry(ACPI_VIDEO_CLASS, acpi_root_dir);
Patrick Mocheld550d982006-06-27 00:41:40 -04002045 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002046 }
2047
Patrick Mocheld550d982006-06-27 00:41:40 -04002048 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002049}
2050
Len Brown4be44fc2005-08-05 00:44:28 -04002051static void __exit acpi_video_exit(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002052{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002053
2054 acpi_bus_unregister_driver(&acpi_video_bus);
2055
2056 remove_proc_entry(ACPI_VIDEO_CLASS, acpi_root_dir);
2057
Patrick Mocheld550d982006-06-27 00:41:40 -04002058 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002059}
2060
2061module_init(acpi_video_init);
2062module_exit(acpi_video_exit);