blob: 3c9bb85a6a93f9465917876a856c42c30e4f15bf [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 =
319 (struct acpi_video_device *)class_get_devdata(&od->class_dev);
320 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=
328 (struct acpi_video_device *)class_get_devdata(&od->class_dev);
329 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{
Len Brown4be44fc2005-08-05 00:44:28 -0400412 int status;
413 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;
Patrick Mochel90130262006-05-19 16:54:48 -0400418 status = acpi_evaluate_object(device->dev->handle, "_BCM", &args, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700419
420 printk(KERN_DEBUG "set_level status: %x\n", status);
Patrick Mocheld550d982006-06-27 00:41:40 -0400421 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700422}
423
424static int
Len Brown4be44fc2005-08-05 00:44:28 -0400425acpi_video_device_lcd_get_level_current(struct acpi_video_device *device,
426 unsigned long *level)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700427{
Len Brown4be44fc2005-08-05 00:44:28 -0400428 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700429
Patrick Mochel90130262006-05-19 16:54:48 -0400430 status = acpi_evaluate_integer(device->dev->handle, "_BQC", NULL, level);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700431
Patrick Mocheld550d982006-06-27 00:41:40 -0400432 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700433}
434
435static int
Len Brown4be44fc2005-08-05 00:44:28 -0400436acpi_video_device_EDID(struct acpi_video_device *device,
437 union acpi_object **edid, ssize_t length)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700438{
Len Brown4be44fc2005-08-05 00:44:28 -0400439 int status;
440 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
441 union acpi_object *obj;
442 union acpi_object arg0 = { ACPI_TYPE_INTEGER };
443 struct acpi_object_list args = { 1, &arg0 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700444
Linus Torvalds1da177e2005-04-16 15:20:36 -0700445
446 *edid = NULL;
447
448 if (!device)
Patrick Mocheld550d982006-06-27 00:41:40 -0400449 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700450 if (length == 128)
451 arg0.integer.value = 1;
452 else if (length == 256)
453 arg0.integer.value = 2;
454 else
Patrick Mocheld550d982006-06-27 00:41:40 -0400455 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700456
Patrick Mochel90130262006-05-19 16:54:48 -0400457 status = acpi_evaluate_object(device->dev->handle, "_DDC", &args, &buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700458 if (ACPI_FAILURE(status))
Patrick Mocheld550d982006-06-27 00:41:40 -0400459 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700460
Jan Engelhardt50dd0962006-10-01 00:28:50 +0200461 obj = buffer.pointer;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700462
463 if (obj && obj->type == ACPI_TYPE_BUFFER)
464 *edid = obj;
465 else {
Len Brown64684632006-06-26 23:41:38 -0400466 printk(KERN_ERR PREFIX "Invalid _DDC data\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700467 status = -EFAULT;
468 kfree(obj);
469 }
470
Patrick Mocheld550d982006-06-27 00:41:40 -0400471 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700472}
473
Linus Torvalds1da177e2005-04-16 15:20:36 -0700474/* bus */
475
476static int
Len Brown4be44fc2005-08-05 00:44:28 -0400477acpi_video_bus_set_POST(struct acpi_video_bus *video, unsigned long option)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700478{
Len Brown4be44fc2005-08-05 00:44:28 -0400479 int status;
480 unsigned long tmp;
481 union acpi_object arg0 = { ACPI_TYPE_INTEGER };
482 struct acpi_object_list args = { 1, &arg0 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700483
Linus Torvalds1da177e2005-04-16 15:20:36 -0700484
485 arg0.integer.value = option;
486
Patrick Mochel90130262006-05-19 16:54:48 -0400487 status = acpi_evaluate_integer(video->device->handle, "_SPD", &args, &tmp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700488 if (ACPI_SUCCESS(status))
Len Brown4be44fc2005-08-05 00:44:28 -0400489 status = tmp ? (-EINVAL) : (AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700490
Patrick Mocheld550d982006-06-27 00:41:40 -0400491 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700492}
493
494static int
Len Brown4be44fc2005-08-05 00:44:28 -0400495acpi_video_bus_get_POST(struct acpi_video_bus *video, unsigned long *id)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700496{
497 int status;
498
Patrick Mochel90130262006-05-19 16:54:48 -0400499 status = acpi_evaluate_integer(video->device->handle, "_GPD", NULL, id);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700500
Patrick Mocheld550d982006-06-27 00:41:40 -0400501 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700502}
503
504static int
Len Brown4be44fc2005-08-05 00:44:28 -0400505acpi_video_bus_POST_options(struct acpi_video_bus *video,
506 unsigned long *options)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700507{
Len Brown4be44fc2005-08-05 00:44:28 -0400508 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700509
Patrick Mochel90130262006-05-19 16:54:48 -0400510 status = acpi_evaluate_integer(video->device->handle, "_VPO", NULL, options);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700511 *options &= 3;
512
Patrick Mocheld550d982006-06-27 00:41:40 -0400513 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700514}
515
516/*
517 * Arg:
518 * video : video bus device pointer
519 * bios_flag :
520 * 0. The system BIOS should NOT automatically switch(toggle)
521 * the active display output.
522 * 1. The system BIOS should automatically switch (toggle) the
Julius Volz98fb8fe2007-02-20 16:38:40 +0100523 * active display output. No switch event.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700524 * 2. The _DGS value should be locked.
525 * 3. The system BIOS should not automatically switch (toggle) the
526 * active display output, but instead generate the display switch
527 * event notify code.
528 * lcd_flag :
529 * 0. The system BIOS should automatically control the brightness level
Julius Volz98fb8fe2007-02-20 16:38:40 +0100530 * of the LCD when the power changes from AC to DC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700531 * 1. The system BIOS should NOT automatically control the brightness
Julius Volz98fb8fe2007-02-20 16:38:40 +0100532 * level of the LCD when the power changes from AC to DC.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700533 * Return Value:
534 * -1 wrong arg.
535 */
536
537static int
Len Brown4be44fc2005-08-05 00:44:28 -0400538acpi_video_bus_DOS(struct acpi_video_bus *video, int bios_flag, int lcd_flag)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700539{
Len Brown4be44fc2005-08-05 00:44:28 -0400540 acpi_integer status = 0;
541 union acpi_object arg0 = { ACPI_TYPE_INTEGER };
542 struct acpi_object_list args = { 1, &arg0 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700543
Linus Torvalds1da177e2005-04-16 15:20:36 -0700544
Len Brown4be44fc2005-08-05 00:44:28 -0400545 if (bios_flag < 0 || bios_flag > 3 || lcd_flag < 0 || lcd_flag > 1) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700546 status = -1;
547 goto Failed;
548 }
549 arg0.integer.value = (lcd_flag << 2) | bios_flag;
550 video->dos_setting = arg0.integer.value;
Patrick Mochel90130262006-05-19 16:54:48 -0400551 acpi_evaluate_object(video->device->handle, "_DOS", &args, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700552
Len Brown4be44fc2005-08-05 00:44:28 -0400553 Failed:
Patrick Mocheld550d982006-06-27 00:41:40 -0400554 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700555}
556
557/*
558 * Arg:
559 * device : video output device (LCD, CRT, ..)
560 *
561 * Return Value:
562 * None
563 *
Julius Volz98fb8fe2007-02-20 16:38:40 +0100564 * Find out all required AML methods defined under the output
Linus Torvalds1da177e2005-04-16 15:20:36 -0700565 * device.
566 */
567
Len Brown4be44fc2005-08-05 00:44:28 -0400568static void acpi_video_device_find_cap(struct acpi_video_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700569{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700570 acpi_handle h_dummy1;
571 int i;
Yu Luming2f3d0002006-11-11 02:40:34 +0800572 u32 max_level = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700573 union acpi_object *obj = NULL;
574 struct acpi_video_device_brightness *br = NULL;
575
Linus Torvalds1da177e2005-04-16 15:20:36 -0700576
Len Brown4be44fc2005-08-05 00:44:28 -0400577 memset(&device->cap, 0, 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700578
Patrick Mochel90130262006-05-19 16:54:48 -0400579 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_ADR", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700580 device->cap._ADR = 1;
581 }
Patrick Mochel90130262006-05-19 16:54:48 -0400582 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_BCL", &h_dummy1))) {
Len Brown4be44fc2005-08-05 00:44:28 -0400583 device->cap._BCL = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700584 }
Patrick Mochel90130262006-05-19 16:54:48 -0400585 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_BCM", &h_dummy1))) {
Len Brown4be44fc2005-08-05 00:44:28 -0400586 device->cap._BCM = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700587 }
Yu Luming2f3d0002006-11-11 02:40:34 +0800588 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle,"_BQC",&h_dummy1)))
589 device->cap._BQC = 1;
Patrick Mochel90130262006-05-19 16:54:48 -0400590 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_DDC", &h_dummy1))) {
Len Brown4be44fc2005-08-05 00:44:28 -0400591 device->cap._DDC = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700592 }
Patrick Mochel90130262006-05-19 16:54:48 -0400593 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_DCS", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700594 device->cap._DCS = 1;
595 }
Patrick Mochel90130262006-05-19 16:54:48 -0400596 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_DGS", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700597 device->cap._DGS = 1;
598 }
Patrick Mochel90130262006-05-19 16:54:48 -0400599 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_DSS", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700600 device->cap._DSS = 1;
601 }
602
Danny Kukawkaf70ac0e2007-07-03 01:33:53 -0400603 if (ACPI_SUCCESS(acpi_video_device_lcd_query_levels(device, &obj))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700604
Danny Kukawkaf70ac0e2007-07-03 01:33:53 -0400605 if (obj->package.count >= 2) {
606 int count = 0;
607 union acpi_object *o;
Len Brown4be44fc2005-08-05 00:44:28 -0400608
Danny Kukawkaf70ac0e2007-07-03 01:33:53 -0400609 br = kzalloc(sizeof(*br), GFP_KERNEL);
610 if (!br) {
611 printk(KERN_ERR "can't allocate memory\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700612 } else {
Danny Kukawkaf70ac0e2007-07-03 01:33:53 -0400613 br->levels = kmalloc(obj->package.count *
614 sizeof *(br->levels), GFP_KERNEL);
615 if (!br->levels)
616 goto out;
617
618 for (i = 0; i < obj->package.count; i++) {
619 o = (union acpi_object *)&obj->package.
620 elements[i];
621 if (o->type != ACPI_TYPE_INTEGER) {
622 printk(KERN_ERR PREFIX "Invalid data\n");
623 continue;
624 }
625 br->levels[count] = (u32) o->integer.value;
626
627 if (br->levels[count] > max_level)
628 max_level = br->levels[count];
629 count++;
630 }
631 out:
632 if (count < 2) {
633 kfree(br->levels);
634 kfree(br);
635 } else {
636 br->count = count;
637 device->brightness = br;
638 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
639 "found %d brightness levels\n",
640 count));
641 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700642 }
643 }
Danny Kukawkaf70ac0e2007-07-03 01:33:53 -0400644
645 } else {
646 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Could not query available LCD brightness level\n"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700647 }
648
Paulo Marquesd1dd0c22005-03-30 22:39:49 -0500649 kfree(obj);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700650
Danny Kukawkaf70ac0e2007-07-03 01:33:53 -0400651 if (device->cap._BCL && device->cap._BCM && device->cap._BQC && max_level > 0){
Yu Luming2f3d0002006-11-11 02:40:34 +0800652 unsigned long tmp;
653 static int count = 0;
654 char *name;
Yu Luming2f3d0002006-11-11 02:40:34 +0800655 name = kzalloc(MAX_NAME_LEN, GFP_KERNEL);
656 if (!name)
657 return;
658
Yu Luming2f3d0002006-11-11 02:40:34 +0800659 sprintf(name, "acpi_video%d", count++);
Yu Luming2f3d0002006-11-11 02:40:34 +0800660 acpi_video_device_lcd_get_level_current(device, &tmp);
Yu Luming2f3d0002006-11-11 02:40:34 +0800661 device->backlight = backlight_device_register(name,
Richard Purdie599a52d2007-02-10 23:07:48 +0000662 NULL, device, &acpi_backlight_ops);
663 device->backlight->props.max_brightness = max_level;
664 device->backlight->props.brightness = (int)tmp;
665 backlight_update_status(device->backlight);
666
Yu Luming2f3d0002006-11-11 02:40:34 +0800667 kfree(name);
668 }
Luming Yu23b0f012007-05-09 21:07:05 +0800669 if (device->cap._DCS && device->cap._DSS){
670 static int count = 0;
671 char *name;
672 name = kzalloc(MAX_NAME_LEN, GFP_KERNEL);
673 if (!name)
674 return;
675 sprintf(name, "acpi_video%d", count++);
676 device->output_dev = video_output_register(name,
677 NULL, device, &acpi_output_properties);
678 kfree(name);
679 }
Patrick Mocheld550d982006-06-27 00:41:40 -0400680 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700681}
682
683/*
684 * Arg:
685 * device : video output device (VGA)
686 *
687 * Return Value:
688 * None
689 *
Julius Volz98fb8fe2007-02-20 16:38:40 +0100690 * Find out all required AML methods defined under the video bus device.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700691 */
692
Len Brown4be44fc2005-08-05 00:44:28 -0400693static void acpi_video_bus_find_cap(struct acpi_video_bus *video)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700694{
Len Brown4be44fc2005-08-05 00:44:28 -0400695 acpi_handle h_dummy1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700696
Len Brown4be44fc2005-08-05 00:44:28 -0400697 memset(&video->cap, 0, 4);
Patrick Mochel90130262006-05-19 16:54:48 -0400698 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_DOS", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700699 video->cap._DOS = 1;
700 }
Patrick Mochel90130262006-05-19 16:54:48 -0400701 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_DOD", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700702 video->cap._DOD = 1;
703 }
Patrick Mochel90130262006-05-19 16:54:48 -0400704 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_ROM", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700705 video->cap._ROM = 1;
706 }
Patrick Mochel90130262006-05-19 16:54:48 -0400707 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_GPD", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700708 video->cap._GPD = 1;
709 }
Patrick Mochel90130262006-05-19 16:54:48 -0400710 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_SPD", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700711 video->cap._SPD = 1;
712 }
Patrick Mochel90130262006-05-19 16:54:48 -0400713 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_VPO", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700714 video->cap._VPO = 1;
715 }
716}
717
718/*
719 * Check whether the video bus device has required AML method to
720 * support the desired features
721 */
722
Len Brown4be44fc2005-08-05 00:44:28 -0400723static int acpi_video_bus_check(struct acpi_video_bus *video)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700724{
Len Brown4be44fc2005-08-05 00:44:28 -0400725 acpi_status status = -ENOENT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700726
Linus Torvalds1da177e2005-04-16 15:20:36 -0700727
728 if (!video)
Patrick Mocheld550d982006-06-27 00:41:40 -0400729 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700730
731 /* Since there is no HID, CID and so on for VGA driver, we have
732 * to check well known required nodes.
733 */
734
Julius Volz98fb8fe2007-02-20 16:38:40 +0100735 /* Does this device support video switching? */
Len Brown4be44fc2005-08-05 00:44:28 -0400736 if (video->cap._DOS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700737 video->flags.multihead = 1;
738 status = 0;
739 }
740
Julius Volz98fb8fe2007-02-20 16:38:40 +0100741 /* Does this device support retrieving a video ROM? */
Len Brown4be44fc2005-08-05 00:44:28 -0400742 if (video->cap._ROM) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700743 video->flags.rom = 1;
744 status = 0;
745 }
746
Julius Volz98fb8fe2007-02-20 16:38:40 +0100747 /* Does this device support configuring which video device to POST? */
Len Brown4be44fc2005-08-05 00:44:28 -0400748 if (video->cap._GPD && video->cap._SPD && video->cap._VPO) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700749 video->flags.post = 1;
750 status = 0;
751 }
752
Patrick Mocheld550d982006-06-27 00:41:40 -0400753 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700754}
755
756/* --------------------------------------------------------------------------
757 FS Interface (/proc)
758 -------------------------------------------------------------------------- */
759
Len Brown4be44fc2005-08-05 00:44:28 -0400760static struct proc_dir_entry *acpi_video_dir;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700761
762/* video devices */
763
Len Brown4be44fc2005-08-05 00:44:28 -0400764static int acpi_video_device_info_seq_show(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700765{
Jan Engelhardt50dd0962006-10-01 00:28:50 +0200766 struct acpi_video_device *dev = seq->private;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700767
Linus Torvalds1da177e2005-04-16 15:20:36 -0700768
769 if (!dev)
770 goto end;
771
772 seq_printf(seq, "device_id: 0x%04x\n", (u32) dev->device_id);
773 seq_printf(seq, "type: ");
774 if (dev->flags.crt)
775 seq_printf(seq, "CRT\n");
776 else if (dev->flags.lcd)
777 seq_printf(seq, "LCD\n");
778 else if (dev->flags.tvout)
779 seq_printf(seq, "TVOUT\n");
Rui Zhang82cae992007-01-03 23:40:53 -0500780 else if (dev->flags.dvi)
781 seq_printf(seq, "DVI\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700782 else
783 seq_printf(seq, "UNKNOWN\n");
784
Len Brown4be44fc2005-08-05 00:44:28 -0400785 seq_printf(seq, "known by bios: %s\n", dev->flags.bios ? "yes" : "no");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700786
Len Brown4be44fc2005-08-05 00:44:28 -0400787 end:
Patrick Mocheld550d982006-06-27 00:41:40 -0400788 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700789}
790
791static int
Len Brown4be44fc2005-08-05 00:44:28 -0400792acpi_video_device_info_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700793{
794 return single_open(file, acpi_video_device_info_seq_show,
795 PDE(inode)->data);
796}
797
Len Brown4be44fc2005-08-05 00:44:28 -0400798static int acpi_video_device_state_seq_show(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700799{
Len Brown4be44fc2005-08-05 00:44:28 -0400800 int status;
Jan Engelhardt50dd0962006-10-01 00:28:50 +0200801 struct acpi_video_device *dev = seq->private;
Len Brown4be44fc2005-08-05 00:44:28 -0400802 unsigned long state;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700803
Linus Torvalds1da177e2005-04-16 15:20:36 -0700804
805 if (!dev)
806 goto end;
807
808 status = acpi_video_device_get_state(dev, &state);
809 seq_printf(seq, "state: ");
810 if (ACPI_SUCCESS(status))
811 seq_printf(seq, "0x%02lx\n", state);
812 else
813 seq_printf(seq, "<not supported>\n");
814
815 status = acpi_video_device_query(dev, &state);
816 seq_printf(seq, "query: ");
817 if (ACPI_SUCCESS(status))
818 seq_printf(seq, "0x%02lx\n", state);
819 else
820 seq_printf(seq, "<not supported>\n");
821
Len Brown4be44fc2005-08-05 00:44:28 -0400822 end:
Patrick Mocheld550d982006-06-27 00:41:40 -0400823 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700824}
825
826static int
Len Brown4be44fc2005-08-05 00:44:28 -0400827acpi_video_device_state_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700828{
829 return single_open(file, acpi_video_device_state_seq_show,
830 PDE(inode)->data);
831}
832
833static ssize_t
Len Brown4be44fc2005-08-05 00:44:28 -0400834acpi_video_device_write_state(struct file *file,
835 const char __user * buffer,
836 size_t count, loff_t * data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700837{
Len Brown4be44fc2005-08-05 00:44:28 -0400838 int status;
Jan Engelhardt50dd0962006-10-01 00:28:50 +0200839 struct seq_file *m = file->private_data;
840 struct acpi_video_device *dev = m->private;
Len Brown4be44fc2005-08-05 00:44:28 -0400841 char str[12] = { 0 };
842 u32 state = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700843
Linus Torvalds1da177e2005-04-16 15:20:36 -0700844
845 if (!dev || count + 1 > sizeof str)
Patrick Mocheld550d982006-06-27 00:41:40 -0400846 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700847
848 if (copy_from_user(str, buffer, count))
Patrick Mocheld550d982006-06-27 00:41:40 -0400849 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700850
851 str[count] = 0;
852 state = simple_strtoul(str, NULL, 0);
Len Brown4be44fc2005-08-05 00:44:28 -0400853 state &= ((1ul << 31) | (1ul << 30) | (1ul << 0));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700854
855 status = acpi_video_device_set_state(dev, state);
856
857 if (status)
Patrick Mocheld550d982006-06-27 00:41:40 -0400858 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700859
Patrick Mocheld550d982006-06-27 00:41:40 -0400860 return count;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700861}
862
863static int
Len Brown4be44fc2005-08-05 00:44:28 -0400864acpi_video_device_brightness_seq_show(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700865{
Jan Engelhardt50dd0962006-10-01 00:28:50 +0200866 struct acpi_video_device *dev = seq->private;
Len Brown4be44fc2005-08-05 00:44:28 -0400867 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700868
Linus Torvalds1da177e2005-04-16 15:20:36 -0700869
870 if (!dev || !dev->brightness) {
871 seq_printf(seq, "<not supported>\n");
Patrick Mocheld550d982006-06-27 00:41:40 -0400872 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700873 }
874
875 seq_printf(seq, "levels: ");
876 for (i = 0; i < dev->brightness->count; i++)
877 seq_printf(seq, " %d", dev->brightness->levels[i]);
878 seq_printf(seq, "\ncurrent: %d\n", dev->brightness->curr);
879
Patrick Mocheld550d982006-06-27 00:41:40 -0400880 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700881}
882
883static int
Len Brown4be44fc2005-08-05 00:44:28 -0400884acpi_video_device_brightness_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700885{
886 return single_open(file, acpi_video_device_brightness_seq_show,
887 PDE(inode)->data);
888}
889
890static ssize_t
Len Brown4be44fc2005-08-05 00:44:28 -0400891acpi_video_device_write_brightness(struct file *file,
892 const char __user * buffer,
893 size_t count, loff_t * data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700894{
Jan Engelhardt50dd0962006-10-01 00:28:50 +0200895 struct seq_file *m = file->private_data;
896 struct acpi_video_device *dev = m->private;
Len Brown4be44fc2005-08-05 00:44:28 -0400897 char str[4] = { 0 };
898 unsigned int level = 0;
899 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700900
Linus Torvalds1da177e2005-04-16 15:20:36 -0700901
Thomas Renninger59d399d2005-11-08 05:27:00 -0500902 if (!dev || !dev->brightness || count + 1 > sizeof str)
Patrick Mocheld550d982006-06-27 00:41:40 -0400903 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700904
905 if (copy_from_user(str, buffer, count))
Patrick Mocheld550d982006-06-27 00:41:40 -0400906 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700907
908 str[count] = 0;
909 level = simple_strtoul(str, NULL, 0);
Len Brown4be44fc2005-08-05 00:44:28 -0400910
Linus Torvalds1da177e2005-04-16 15:20:36 -0700911 if (level > 100)
Patrick Mocheld550d982006-06-27 00:41:40 -0400912 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700913
Julius Volz98fb8fe2007-02-20 16:38:40 +0100914 /* validate through the list of available levels */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700915 for (i = 0; i < dev->brightness->count; i++)
916 if (level == dev->brightness->levels[i]) {
Len Brown4be44fc2005-08-05 00:44:28 -0400917 if (ACPI_SUCCESS
918 (acpi_video_device_lcd_set_level(dev, level)))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700919 dev->brightness->curr = level;
920 break;
921 }
922
Patrick Mocheld550d982006-06-27 00:41:40 -0400923 return count;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700924}
925
Len Brown4be44fc2005-08-05 00:44:28 -0400926static int acpi_video_device_EDID_seq_show(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700927{
Jan Engelhardt50dd0962006-10-01 00:28:50 +0200928 struct acpi_video_device *dev = seq->private;
Len Brown4be44fc2005-08-05 00:44:28 -0400929 int status;
930 int i;
931 union acpi_object *edid = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700932
Linus Torvalds1da177e2005-04-16 15:20:36 -0700933
934 if (!dev)
935 goto out;
936
Len Brown4be44fc2005-08-05 00:44:28 -0400937 status = acpi_video_device_EDID(dev, &edid, 128);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700938 if (ACPI_FAILURE(status)) {
Len Brown4be44fc2005-08-05 00:44:28 -0400939 status = acpi_video_device_EDID(dev, &edid, 256);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700940 }
941
942 if (ACPI_FAILURE(status)) {
943 goto out;
944 }
945
946 if (edid && edid->type == ACPI_TYPE_BUFFER) {
947 for (i = 0; i < edid->buffer.length; i++)
948 seq_putc(seq, edid->buffer.pointer[i]);
949 }
950
Len Brown4be44fc2005-08-05 00:44:28 -0400951 out:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700952 if (!edid)
953 seq_printf(seq, "<not supported>\n");
954 else
955 kfree(edid);
956
Patrick Mocheld550d982006-06-27 00:41:40 -0400957 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700958}
959
960static int
Len Brown4be44fc2005-08-05 00:44:28 -0400961acpi_video_device_EDID_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700962{
963 return single_open(file, acpi_video_device_EDID_seq_show,
964 PDE(inode)->data);
965}
966
Len Brown4be44fc2005-08-05 00:44:28 -0400967static int acpi_video_device_add_fs(struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700968{
Len Brown4be44fc2005-08-05 00:44:28 -0400969 struct proc_dir_entry *entry = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700970 struct acpi_video_device *vid_dev;
971
Linus Torvalds1da177e2005-04-16 15:20:36 -0700972
973 if (!device)
Patrick Mocheld550d982006-06-27 00:41:40 -0400974 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700975
Jan Engelhardt50dd0962006-10-01 00:28:50 +0200976 vid_dev = acpi_driver_data(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700977 if (!vid_dev)
Patrick Mocheld550d982006-06-27 00:41:40 -0400978 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700979
980 if (!acpi_device_dir(device)) {
981 acpi_device_dir(device) = proc_mkdir(acpi_device_bid(device),
Len Brown4be44fc2005-08-05 00:44:28 -0400982 vid_dev->video->dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700983 if (!acpi_device_dir(device))
Patrick Mocheld550d982006-06-27 00:41:40 -0400984 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700985 acpi_device_dir(device)->owner = THIS_MODULE;
986 }
987
988 /* 'info' [R] */
989 entry = create_proc_entry("info", S_IRUGO, acpi_device_dir(device));
990 if (!entry)
Patrick Mocheld550d982006-06-27 00:41:40 -0400991 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700992 else {
993 entry->proc_fops = &acpi_video_device_info_fops;
994 entry->data = acpi_driver_data(device);
995 entry->owner = THIS_MODULE;
996 }
997
998 /* 'state' [R/W] */
Len Brown4be44fc2005-08-05 00:44:28 -0400999 entry =
1000 create_proc_entry("state", S_IFREG | S_IRUGO | S_IWUSR,
1001 acpi_device_dir(device));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001002 if (!entry)
Patrick Mocheld550d982006-06-27 00:41:40 -04001003 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001004 else {
Arjan van de Vend479e902006-01-06 16:47:00 -05001005 acpi_video_device_state_fops.write = acpi_video_device_write_state;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001006 entry->proc_fops = &acpi_video_device_state_fops;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001007 entry->data = acpi_driver_data(device);
1008 entry->owner = THIS_MODULE;
1009 }
1010
1011 /* 'brightness' [R/W] */
Len Brown4be44fc2005-08-05 00:44:28 -04001012 entry =
1013 create_proc_entry("brightness", S_IFREG | S_IRUGO | S_IWUSR,
1014 acpi_device_dir(device));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001015 if (!entry)
Patrick Mocheld550d982006-06-27 00:41:40 -04001016 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001017 else {
Arjan van de Vend479e902006-01-06 16:47:00 -05001018 acpi_video_device_brightness_fops.write = acpi_video_device_write_brightness;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001019 entry->proc_fops = &acpi_video_device_brightness_fops;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001020 entry->data = acpi_driver_data(device);
1021 entry->owner = THIS_MODULE;
1022 }
1023
1024 /* 'EDID' [R] */
1025 entry = create_proc_entry("EDID", S_IRUGO, acpi_device_dir(device));
1026 if (!entry)
Patrick Mocheld550d982006-06-27 00:41:40 -04001027 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001028 else {
1029 entry->proc_fops = &acpi_video_device_EDID_fops;
1030 entry->data = acpi_driver_data(device);
1031 entry->owner = THIS_MODULE;
1032 }
1033
Patrick Mocheld550d982006-06-27 00:41:40 -04001034 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001035}
1036
Len Brown4be44fc2005-08-05 00:44:28 -04001037static int acpi_video_device_remove_fs(struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001038{
1039 struct acpi_video_device *vid_dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001040
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001041 vid_dev = acpi_driver_data(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001042 if (!vid_dev || !vid_dev->video || !vid_dev->video->dir)
Patrick Mocheld550d982006-06-27 00:41:40 -04001043 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001044
1045 if (acpi_device_dir(device)) {
1046 remove_proc_entry("info", acpi_device_dir(device));
1047 remove_proc_entry("state", acpi_device_dir(device));
1048 remove_proc_entry("brightness", acpi_device_dir(device));
1049 remove_proc_entry("EDID", acpi_device_dir(device));
Len Brown4be44fc2005-08-05 00:44:28 -04001050 remove_proc_entry(acpi_device_bid(device), vid_dev->video->dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001051 acpi_device_dir(device) = NULL;
1052 }
1053
Patrick Mocheld550d982006-06-27 00:41:40 -04001054 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001055}
1056
Linus Torvalds1da177e2005-04-16 15:20:36 -07001057/* video bus */
Len Brown4be44fc2005-08-05 00:44:28 -04001058static int acpi_video_bus_info_seq_show(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001059{
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001060 struct acpi_video_bus *video = seq->private;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001061
Linus Torvalds1da177e2005-04-16 15:20:36 -07001062
1063 if (!video)
1064 goto end;
1065
1066 seq_printf(seq, "Switching heads: %s\n",
Len Brown4be44fc2005-08-05 00:44:28 -04001067 video->flags.multihead ? "yes" : "no");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001068 seq_printf(seq, "Video ROM: %s\n",
Len Brown4be44fc2005-08-05 00:44:28 -04001069 video->flags.rom ? "yes" : "no");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001070 seq_printf(seq, "Device to be POSTed on boot: %s\n",
Len Brown4be44fc2005-08-05 00:44:28 -04001071 video->flags.post ? "yes" : "no");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001072
Len Brown4be44fc2005-08-05 00:44:28 -04001073 end:
Patrick Mocheld550d982006-06-27 00:41:40 -04001074 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001075}
1076
Len Brown4be44fc2005-08-05 00:44:28 -04001077static int acpi_video_bus_info_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001078{
Len Brown4be44fc2005-08-05 00:44:28 -04001079 return single_open(file, acpi_video_bus_info_seq_show,
1080 PDE(inode)->data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001081}
1082
Len Brown4be44fc2005-08-05 00:44:28 -04001083static int acpi_video_bus_ROM_seq_show(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001084{
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001085 struct acpi_video_bus *video = seq->private;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001086
Linus Torvalds1da177e2005-04-16 15:20:36 -07001087
1088 if (!video)
1089 goto end;
1090
1091 printk(KERN_INFO PREFIX "Please implement %s\n", __FUNCTION__);
1092 seq_printf(seq, "<TODO>\n");
1093
Len Brown4be44fc2005-08-05 00:44:28 -04001094 end:
Patrick Mocheld550d982006-06-27 00:41:40 -04001095 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001096}
1097
Len Brown4be44fc2005-08-05 00:44:28 -04001098static int acpi_video_bus_ROM_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001099{
1100 return single_open(file, acpi_video_bus_ROM_seq_show, PDE(inode)->data);
1101}
1102
Len Brown4be44fc2005-08-05 00:44:28 -04001103static int acpi_video_bus_POST_info_seq_show(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001104{
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001105 struct acpi_video_bus *video = seq->private;
Len Brown4be44fc2005-08-05 00:44:28 -04001106 unsigned long options;
1107 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001108
Linus Torvalds1da177e2005-04-16 15:20:36 -07001109
1110 if (!video)
1111 goto end;
1112
1113 status = acpi_video_bus_POST_options(video, &options);
1114 if (ACPI_SUCCESS(status)) {
1115 if (!(options & 1)) {
Len Brown4be44fc2005-08-05 00:44:28 -04001116 printk(KERN_WARNING PREFIX
1117 "The motherboard VGA device is not listed as a possible POST device.\n");
1118 printk(KERN_WARNING PREFIX
Julius Volz98fb8fe2007-02-20 16:38:40 +01001119 "This indicates a BIOS bug. Please contact the manufacturer.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001120 }
1121 printk("%lx\n", options);
Julius Volz98fb8fe2007-02-20 16:38:40 +01001122 seq_printf(seq, "can POST: <integrated video>");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001123 if (options & 2)
1124 seq_printf(seq, " <PCI video>");
1125 if (options & 4)
1126 seq_printf(seq, " <AGP video>");
1127 seq_putc(seq, '\n');
1128 } else
1129 seq_printf(seq, "<not supported>\n");
Len Brown4be44fc2005-08-05 00:44:28 -04001130 end:
Patrick Mocheld550d982006-06-27 00:41:40 -04001131 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001132}
1133
1134static int
Len Brown4be44fc2005-08-05 00:44:28 -04001135acpi_video_bus_POST_info_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001136{
Len Brown4be44fc2005-08-05 00:44:28 -04001137 return single_open(file, acpi_video_bus_POST_info_seq_show,
1138 PDE(inode)->data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001139}
1140
Len Brown4be44fc2005-08-05 00:44:28 -04001141static int acpi_video_bus_POST_seq_show(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001142{
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001143 struct acpi_video_bus *video = seq->private;
Len Brown4be44fc2005-08-05 00:44:28 -04001144 int status;
1145 unsigned long id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001146
Linus Torvalds1da177e2005-04-16 15:20:36 -07001147
1148 if (!video)
1149 goto end;
1150
Len Brown4be44fc2005-08-05 00:44:28 -04001151 status = acpi_video_bus_get_POST(video, &id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001152 if (!ACPI_SUCCESS(status)) {
1153 seq_printf(seq, "<not supported>\n");
1154 goto end;
1155 }
Julius Volz98fb8fe2007-02-20 16:38:40 +01001156 seq_printf(seq, "device POSTed is <%s>\n", device_decode[id & 3]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001157
Len Brown4be44fc2005-08-05 00:44:28 -04001158 end:
Patrick Mocheld550d982006-06-27 00:41:40 -04001159 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001160}
1161
Len Brown4be44fc2005-08-05 00:44:28 -04001162static int acpi_video_bus_DOS_seq_show(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001163{
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001164 struct acpi_video_bus *video = seq->private;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001165
Linus Torvalds1da177e2005-04-16 15:20:36 -07001166
Len Brown4be44fc2005-08-05 00:44:28 -04001167 seq_printf(seq, "DOS setting: <%d>\n", video->dos_setting);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001168
Patrick Mocheld550d982006-06-27 00:41:40 -04001169 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001170}
1171
Len Brown4be44fc2005-08-05 00:44:28 -04001172static int acpi_video_bus_POST_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001173{
Len Brown4be44fc2005-08-05 00:44:28 -04001174 return single_open(file, acpi_video_bus_POST_seq_show,
1175 PDE(inode)->data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001176}
1177
Len Brown4be44fc2005-08-05 00:44:28 -04001178static int acpi_video_bus_DOS_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001179{
1180 return single_open(file, acpi_video_bus_DOS_seq_show, PDE(inode)->data);
1181}
1182
1183static ssize_t
Len Brown4be44fc2005-08-05 00:44:28 -04001184acpi_video_bus_write_POST(struct file *file,
1185 const char __user * buffer,
1186 size_t count, loff_t * data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001187{
Len Brown4be44fc2005-08-05 00:44:28 -04001188 int status;
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001189 struct seq_file *m = file->private_data;
1190 struct acpi_video_bus *video = m->private;
Len Brown4be44fc2005-08-05 00:44:28 -04001191 char str[12] = { 0 };
1192 unsigned long opt, options;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001193
Linus Torvalds1da177e2005-04-16 15:20:36 -07001194
Linus Torvalds1da177e2005-04-16 15:20:36 -07001195 if (!video || count + 1 > sizeof str)
Patrick Mocheld550d982006-06-27 00:41:40 -04001196 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001197
1198 status = acpi_video_bus_POST_options(video, &options);
1199 if (!ACPI_SUCCESS(status))
Patrick Mocheld550d982006-06-27 00:41:40 -04001200 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001201
1202 if (copy_from_user(str, buffer, count))
Patrick Mocheld550d982006-06-27 00:41:40 -04001203 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001204
1205 str[count] = 0;
1206 opt = strtoul(str, NULL, 0);
1207 if (opt > 3)
Patrick Mocheld550d982006-06-27 00:41:40 -04001208 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001209
Julius Volz98fb8fe2007-02-20 16:38:40 +01001210 /* just in case an OEM 'forgot' the motherboard... */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001211 options |= 1;
1212
1213 if (options & (1ul << opt)) {
Len Brown4be44fc2005-08-05 00:44:28 -04001214 status = acpi_video_bus_set_POST(video, opt);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001215 if (!ACPI_SUCCESS(status))
Patrick Mocheld550d982006-06-27 00:41:40 -04001216 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001217
1218 }
1219
Patrick Mocheld550d982006-06-27 00:41:40 -04001220 return count;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001221}
1222
1223static ssize_t
Len Brown4be44fc2005-08-05 00:44:28 -04001224acpi_video_bus_write_DOS(struct file *file,
1225 const char __user * buffer,
1226 size_t count, loff_t * data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001227{
Len Brown4be44fc2005-08-05 00:44:28 -04001228 int status;
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001229 struct seq_file *m = file->private_data;
1230 struct acpi_video_bus *video = m->private;
Len Brown4be44fc2005-08-05 00:44:28 -04001231 char str[12] = { 0 };
1232 unsigned long opt;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001233
Linus Torvalds1da177e2005-04-16 15:20:36 -07001234
Linus Torvalds1da177e2005-04-16 15:20:36 -07001235 if (!video || count + 1 > sizeof str)
Patrick Mocheld550d982006-06-27 00:41:40 -04001236 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001237
1238 if (copy_from_user(str, buffer, count))
Patrick Mocheld550d982006-06-27 00:41:40 -04001239 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001240
1241 str[count] = 0;
1242 opt = strtoul(str, NULL, 0);
1243 if (opt > 7)
Patrick Mocheld550d982006-06-27 00:41:40 -04001244 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001245
Len Brown4be44fc2005-08-05 00:44:28 -04001246 status = acpi_video_bus_DOS(video, opt & 0x3, (opt & 0x4) >> 2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001247
1248 if (!ACPI_SUCCESS(status))
Patrick Mocheld550d982006-06-27 00:41:40 -04001249 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001250
Patrick Mocheld550d982006-06-27 00:41:40 -04001251 return count;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001252}
1253
Len Brown4be44fc2005-08-05 00:44:28 -04001254static int acpi_video_bus_add_fs(struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001255{
Len Brown4be44fc2005-08-05 00:44:28 -04001256 struct proc_dir_entry *entry = NULL;
1257 struct acpi_video_bus *video;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001258
Linus Torvalds1da177e2005-04-16 15:20:36 -07001259
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001260 video = acpi_driver_data(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001261
1262 if (!acpi_device_dir(device)) {
1263 acpi_device_dir(device) = proc_mkdir(acpi_device_bid(device),
Len Brown4be44fc2005-08-05 00:44:28 -04001264 acpi_video_dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001265 if (!acpi_device_dir(device))
Patrick Mocheld550d982006-06-27 00:41:40 -04001266 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001267 video->dir = acpi_device_dir(device);
1268 acpi_device_dir(device)->owner = THIS_MODULE;
1269 }
1270
1271 /* 'info' [R] */
1272 entry = create_proc_entry("info", S_IRUGO, acpi_device_dir(device));
1273 if (!entry)
Patrick Mocheld550d982006-06-27 00:41:40 -04001274 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001275 else {
1276 entry->proc_fops = &acpi_video_bus_info_fops;
1277 entry->data = acpi_driver_data(device);
1278 entry->owner = THIS_MODULE;
1279 }
1280
1281 /* 'ROM' [R] */
1282 entry = create_proc_entry("ROM", S_IRUGO, acpi_device_dir(device));
1283 if (!entry)
Patrick Mocheld550d982006-06-27 00:41:40 -04001284 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001285 else {
1286 entry->proc_fops = &acpi_video_bus_ROM_fops;
1287 entry->data = acpi_driver_data(device);
1288 entry->owner = THIS_MODULE;
1289 }
1290
1291 /* 'POST_info' [R] */
Len Brown4be44fc2005-08-05 00:44:28 -04001292 entry =
1293 create_proc_entry("POST_info", S_IRUGO, acpi_device_dir(device));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001294 if (!entry)
Patrick Mocheld550d982006-06-27 00:41:40 -04001295 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001296 else {
1297 entry->proc_fops = &acpi_video_bus_POST_info_fops;
1298 entry->data = acpi_driver_data(device);
1299 entry->owner = THIS_MODULE;
1300 }
1301
1302 /* 'POST' [R/W] */
Len Brown4be44fc2005-08-05 00:44:28 -04001303 entry =
1304 create_proc_entry("POST", S_IFREG | S_IRUGO | S_IRUSR,
1305 acpi_device_dir(device));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001306 if (!entry)
Patrick Mocheld550d982006-06-27 00:41:40 -04001307 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001308 else {
Arjan van de Vend479e902006-01-06 16:47:00 -05001309 acpi_video_bus_POST_fops.write = acpi_video_bus_write_POST;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001310 entry->proc_fops = &acpi_video_bus_POST_fops;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001311 entry->data = acpi_driver_data(device);
1312 entry->owner = THIS_MODULE;
1313 }
1314
1315 /* 'DOS' [R/W] */
Len Brown4be44fc2005-08-05 00:44:28 -04001316 entry =
1317 create_proc_entry("DOS", S_IFREG | S_IRUGO | S_IRUSR,
1318 acpi_device_dir(device));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001319 if (!entry)
Patrick Mocheld550d982006-06-27 00:41:40 -04001320 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001321 else {
Arjan van de Vend479e902006-01-06 16:47:00 -05001322 acpi_video_bus_DOS_fops.write = acpi_video_bus_write_DOS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001323 entry->proc_fops = &acpi_video_bus_DOS_fops;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001324 entry->data = acpi_driver_data(device);
1325 entry->owner = THIS_MODULE;
1326 }
1327
Patrick Mocheld550d982006-06-27 00:41:40 -04001328 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001329}
1330
Len Brown4be44fc2005-08-05 00:44:28 -04001331static int acpi_video_bus_remove_fs(struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001332{
Len Brown4be44fc2005-08-05 00:44:28 -04001333 struct acpi_video_bus *video;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001334
Linus Torvalds1da177e2005-04-16 15:20:36 -07001335
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001336 video = acpi_driver_data(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001337
1338 if (acpi_device_dir(device)) {
1339 remove_proc_entry("info", acpi_device_dir(device));
1340 remove_proc_entry("ROM", acpi_device_dir(device));
1341 remove_proc_entry("POST_info", acpi_device_dir(device));
1342 remove_proc_entry("POST", acpi_device_dir(device));
1343 remove_proc_entry("DOS", acpi_device_dir(device));
Len Brown4be44fc2005-08-05 00:44:28 -04001344 remove_proc_entry(acpi_device_bid(device), acpi_video_dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001345 acpi_device_dir(device) = NULL;
1346 }
1347
Patrick Mocheld550d982006-06-27 00:41:40 -04001348 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001349}
1350
1351/* --------------------------------------------------------------------------
1352 Driver Interface
1353 -------------------------------------------------------------------------- */
1354
1355/* device interface */
Rui Zhang82cae992007-01-03 23:40:53 -05001356static struct acpi_video_device_attrib*
1357acpi_video_get_device_attr(struct acpi_video_bus *video, unsigned long device_id)
1358{
1359 int count;
1360
1361 for(count = 0; count < video->attached_count; count++)
1362 if((video->attached_array[count].value.int_val & 0xffff) == device_id)
1363 return &(video->attached_array[count].value.attrib);
1364 return NULL;
1365}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001366
1367static int
Len Brown4be44fc2005-08-05 00:44:28 -04001368acpi_video_bus_get_one_device(struct acpi_device *device,
1369 struct acpi_video_bus *video)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001370{
Len Brown4be44fc2005-08-05 00:44:28 -04001371 unsigned long device_id;
Yu, Luming973bf492006-04-27 05:25:00 -04001372 int status;
Len Brown4be44fc2005-08-05 00:44:28 -04001373 struct acpi_video_device *data;
Rui Zhang82cae992007-01-03 23:40:53 -05001374 struct acpi_video_device_attrib* attribute;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001375
1376 if (!device || !video)
Patrick Mocheld550d982006-06-27 00:41:40 -04001377 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001378
Len Brown4be44fc2005-08-05 00:44:28 -04001379 status =
1380 acpi_evaluate_integer(device->handle, "_ADR", NULL, &device_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001381 if (ACPI_SUCCESS(status)) {
1382
Burman Yan36bcbec2006-12-19 12:56:11 -08001383 data = kzalloc(sizeof(struct acpi_video_device), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001384 if (!data)
Patrick Mocheld550d982006-06-27 00:41:40 -04001385 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001386
Linus Torvalds1da177e2005-04-16 15:20:36 -07001387 strcpy(acpi_device_name(device), ACPI_VIDEO_DEVICE_NAME);
1388 strcpy(acpi_device_class(device), ACPI_VIDEO_CLASS);
1389 acpi_driver_data(device) = data;
1390
1391 data->device_id = device_id;
1392 data->video = video;
1393 data->dev = device;
1394
Rui Zhang82cae992007-01-03 23:40:53 -05001395 attribute = acpi_video_get_device_attr(video, device_id);
1396
1397 if((attribute != NULL) && attribute->device_id_scheme) {
1398 switch (attribute->display_type) {
1399 case ACPI_VIDEO_DISPLAY_CRT:
1400 data->flags.crt = 1;
1401 break;
1402 case ACPI_VIDEO_DISPLAY_TV:
1403 data->flags.tvout = 1;
1404 break;
1405 case ACPI_VIDEO_DISPLAY_DVI:
1406 data->flags.dvi = 1;
1407 break;
1408 case ACPI_VIDEO_DISPLAY_LCD:
1409 data->flags.lcd = 1;
1410 break;
1411 default:
1412 data->flags.unknown = 1;
1413 break;
1414 }
1415 if(attribute->bios_can_detect)
1416 data->flags.bios = 1;
1417 } else
Linus Torvalds1da177e2005-04-16 15:20:36 -07001418 data->flags.unknown = 1;
Len Brown4be44fc2005-08-05 00:44:28 -04001419
Linus Torvalds1da177e2005-04-16 15:20:36 -07001420 acpi_video_device_bind(video, data);
1421 acpi_video_device_find_cap(data);
1422
Patrick Mochel90130262006-05-19 16:54:48 -04001423 status = acpi_install_notify_handler(device->handle,
Len Brown4be44fc2005-08-05 00:44:28 -04001424 ACPI_DEVICE_NOTIFY,
1425 acpi_video_device_notify,
1426 data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001427 if (ACPI_FAILURE(status)) {
1428 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
Len Brown4be44fc2005-08-05 00:44:28 -04001429 "Error installing notify handler\n"));
Yu, Luming973bf492006-04-27 05:25:00 -04001430 if(data->brightness)
1431 kfree(data->brightness->levels);
1432 kfree(data->brightness);
1433 kfree(data);
1434 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001435 }
1436
1437 down(&video->sem);
1438 list_add_tail(&data->entry, &video->video_device_list);
1439 up(&video->sem);
1440
1441 acpi_video_device_add_fs(device);
1442
Patrick Mocheld550d982006-06-27 00:41:40 -04001443 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001444 }
1445
Patrick Mocheld550d982006-06-27 00:41:40 -04001446 return -ENOENT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001447}
1448
1449/*
1450 * Arg:
1451 * video : video bus device
1452 *
1453 * Return:
1454 * none
1455 *
1456 * Enumerate the video device list of the video bus,
1457 * bind the ids with the corresponding video devices
1458 * under the video bus.
Len Brown4be44fc2005-08-05 00:44:28 -04001459 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001460
Len Brown4be44fc2005-08-05 00:44:28 -04001461static void acpi_video_device_rebind(struct acpi_video_bus *video)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001462{
Len Brown4be44fc2005-08-05 00:44:28 -04001463 struct list_head *node, *next;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001464 list_for_each_safe(node, next, &video->video_device_list) {
Len Brown4be44fc2005-08-05 00:44:28 -04001465 struct acpi_video_device *dev =
1466 container_of(node, struct acpi_video_device, entry);
1467 acpi_video_device_bind(video, dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001468 }
1469}
1470
1471/*
1472 * Arg:
1473 * video : video bus device
1474 * device : video output device under the video
1475 * bus
1476 *
1477 * Return:
1478 * none
1479 *
1480 * Bind the ids with the corresponding video devices
1481 * under the video bus.
Len Brown4be44fc2005-08-05 00:44:28 -04001482 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001483
1484static void
Len Brown4be44fc2005-08-05 00:44:28 -04001485acpi_video_device_bind(struct acpi_video_bus *video,
1486 struct acpi_video_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001487{
Len Brown4be44fc2005-08-05 00:44:28 -04001488 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001489
1490#define IDS_VAL(i) video->attached_array[i].value.int_val
1491#define IDS_BIND(i) video->attached_array[i].bind_info
Len Brown4be44fc2005-08-05 00:44:28 -04001492
1493 for (i = 0; IDS_VAL(i) != ACPI_VIDEO_HEAD_INVALID &&
1494 i < video->attached_count; i++) {
1495 if (device->device_id == (IDS_VAL(i) & 0xffff)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001496 IDS_BIND(i) = device;
1497 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "device_bind %d\n", i));
1498 }
1499 }
1500#undef IDS_VAL
1501#undef IDS_BIND
1502}
1503
1504/*
1505 * Arg:
1506 * video : video bus device
1507 *
1508 * Return:
1509 * < 0 : error
1510 *
1511 * Call _DOD to enumerate all devices attached to display adapter
1512 *
Len Brown4be44fc2005-08-05 00:44:28 -04001513 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001514
1515static int acpi_video_device_enumerate(struct acpi_video_bus *video)
1516{
Len Brown4be44fc2005-08-05 00:44:28 -04001517 int status;
1518 int count;
1519 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001520 struct acpi_video_enumerated_device *active_device_list;
Len Brown4be44fc2005-08-05 00:44:28 -04001521 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
1522 union acpi_object *dod = NULL;
1523 union acpi_object *obj;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001524
Patrick Mochel90130262006-05-19 16:54:48 -04001525 status = acpi_evaluate_object(video->device->handle, "_DOD", NULL, &buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001526 if (!ACPI_SUCCESS(status)) {
Thomas Renningera6fc6722006-06-26 23:58:43 -04001527 ACPI_EXCEPTION((AE_INFO, status, "Evaluating _DOD"));
Patrick Mocheld550d982006-06-27 00:41:40 -04001528 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001529 }
1530
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001531 dod = buffer.pointer;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001532 if (!dod || (dod->type != ACPI_TYPE_PACKAGE)) {
Thomas Renningera6fc6722006-06-26 23:58:43 -04001533 ACPI_EXCEPTION((AE_INFO, status, "Invalid _DOD data"));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001534 status = -EFAULT;
1535 goto out;
1536 }
1537
1538 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found %d video heads in _DOD\n",
Len Brown4be44fc2005-08-05 00:44:28 -04001539 dod->package.count));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001540
Len Brown4be44fc2005-08-05 00:44:28 -04001541 active_device_list = kmalloc((1 +
1542 dod->package.count) *
1543 sizeof(struct
1544 acpi_video_enumerated_device),
1545 GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001546
1547 if (!active_device_list) {
1548 status = -ENOMEM;
1549 goto out;
1550 }
1551
1552 count = 0;
1553 for (i = 0; i < dod->package.count; i++) {
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001554 obj = &dod->package.elements[i];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001555
1556 if (obj->type != ACPI_TYPE_INTEGER) {
Len Brown64684632006-06-26 23:41:38 -04001557 printk(KERN_ERR PREFIX "Invalid _DOD data\n");
Len Brown4be44fc2005-08-05 00:44:28 -04001558 active_device_list[i].value.int_val =
1559 ACPI_VIDEO_HEAD_INVALID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001560 }
1561 active_device_list[i].value.int_val = obj->integer.value;
1562 active_device_list[i].bind_info = NULL;
Len Brown4be44fc2005-08-05 00:44:28 -04001563 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "dod element[%d] = %d\n", i,
1564 (int)obj->integer.value));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001565 count++;
1566 }
1567 active_device_list[count].value.int_val = ACPI_VIDEO_HEAD_END;
1568
Jesper Juhl6044ec82005-11-07 01:01:32 -08001569 kfree(video->attached_array);
Len Brown4be44fc2005-08-05 00:44:28 -04001570
Linus Torvalds1da177e2005-04-16 15:20:36 -07001571 video->attached_array = active_device_list;
1572 video->attached_count = count;
Len Brown4be44fc2005-08-05 00:44:28 -04001573 out:
Len Brown02438d82006-06-30 03:19:10 -04001574 kfree(buffer.pointer);
Patrick Mocheld550d982006-06-27 00:41:40 -04001575 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001576}
1577
1578/*
1579 * Arg:
1580 * video : video bus device
Julius Volz98fb8fe2007-02-20 16:38:40 +01001581 * event : notify event
Linus Torvalds1da177e2005-04-16 15:20:36 -07001582 *
1583 * Return:
1584 * < 0 : error
1585 *
1586 * 1. Find out the current active output device.
Julius Volz98fb8fe2007-02-20 16:38:40 +01001587 * 2. Identify the next output device to switch to.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001588 * 3. call _DSS to do actual switch.
Len Brown4be44fc2005-08-05 00:44:28 -04001589 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001590
Len Brown4be44fc2005-08-05 00:44:28 -04001591static int acpi_video_switch_output(struct acpi_video_bus *video, int event)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001592{
Len Brown4be44fc2005-08-05 00:44:28 -04001593 struct list_head *node, *next;
1594 struct acpi_video_device *dev = NULL;
1595 struct acpi_video_device *dev_next = NULL;
1596 struct acpi_video_device *dev_prev = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001597 unsigned long state;
1598 int status = 0;
1599
Linus Torvalds1da177e2005-04-16 15:20:36 -07001600
1601 list_for_each_safe(node, next, &video->video_device_list) {
Adrian Bunk73345712005-03-30 22:31:35 -05001602 dev = container_of(node, struct acpi_video_device, entry);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001603 status = acpi_video_device_get_state(dev, &state);
Len Brown4be44fc2005-08-05 00:44:28 -04001604 if (state & 0x2) {
1605 dev_next =
1606 container_of(node->next, struct acpi_video_device,
1607 entry);
1608 dev_prev =
1609 container_of(node->prev, struct acpi_video_device,
1610 entry);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001611 goto out;
1612 }
1613 }
1614 dev_next = container_of(node->next, struct acpi_video_device, entry);
1615 dev_prev = container_of(node->prev, struct acpi_video_device, entry);
Len Brown4be44fc2005-08-05 00:44:28 -04001616 out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001617 switch (event) {
1618 case ACPI_VIDEO_NOTIFY_CYCLE:
1619 case ACPI_VIDEO_NOTIFY_NEXT_OUTPUT:
1620 acpi_video_device_set_state(dev, 0);
1621 acpi_video_device_set_state(dev_next, 0x80000001);
1622 break;
1623 case ACPI_VIDEO_NOTIFY_PREV_OUTPUT:
1624 acpi_video_device_set_state(dev, 0);
1625 acpi_video_device_set_state(dev_prev, 0x80000001);
1626 default:
1627 break;
1628 }
1629
Patrick Mocheld550d982006-06-27 00:41:40 -04001630 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001631}
1632
Len Brown4be44fc2005-08-05 00:44:28 -04001633static int
1634acpi_video_get_next_level(struct acpi_video_device *device,
1635 u32 level_current, u32 event)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001636{
Thomas Tuttlef4715182006-12-19 12:56:14 -08001637 int min, max, min_above, max_below, i, l;
1638 max = max_below = 0;
1639 min = min_above = 255;
1640 for (i = 0; i < device->brightness->count; i++) {
1641 l = device->brightness->levels[i];
1642 if (l < min)
1643 min = l;
1644 if (l > max)
1645 max = l;
1646 if (l < min_above && l > level_current)
1647 min_above = l;
1648 if (l > max_below && l < level_current)
1649 max_below = l;
1650 }
1651
1652 switch (event) {
1653 case ACPI_VIDEO_NOTIFY_CYCLE_BRIGHTNESS:
1654 return (level_current < max) ? min_above : min;
1655 case ACPI_VIDEO_NOTIFY_INC_BRIGHTNESS:
1656 return (level_current < max) ? min_above : max;
1657 case ACPI_VIDEO_NOTIFY_DEC_BRIGHTNESS:
1658 return (level_current > min) ? max_below : min;
1659 case ACPI_VIDEO_NOTIFY_ZERO_BRIGHTNESS:
1660 case ACPI_VIDEO_NOTIFY_DISPLAY_OFF:
1661 return 0;
1662 default:
1663 return level_current;
1664 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001665}
1666
Linus Torvalds1da177e2005-04-16 15:20:36 -07001667static void
Len Brown4be44fc2005-08-05 00:44:28 -04001668acpi_video_switch_brightness(struct acpi_video_device *device, int event)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001669{
1670 unsigned long level_current, level_next;
1671 acpi_video_device_lcd_get_level_current(device, &level_current);
1672 level_next = acpi_video_get_next_level(device, level_current, event);
1673 acpi_video_device_lcd_set_level(device, level_next);
1674}
1675
1676static int
Len Brown4be44fc2005-08-05 00:44:28 -04001677acpi_video_bus_get_devices(struct acpi_video_bus *video,
1678 struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001679{
Len Brown4be44fc2005-08-05 00:44:28 -04001680 int status = 0;
1681 struct list_head *node, *next;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001682
Linus Torvalds1da177e2005-04-16 15:20:36 -07001683
1684 acpi_video_device_enumerate(video);
1685
1686 list_for_each_safe(node, next, &device->children) {
Len Brown4be44fc2005-08-05 00:44:28 -04001687 struct acpi_device *dev =
1688 list_entry(node, struct acpi_device, node);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001689
1690 if (!dev)
1691 continue;
1692
1693 status = acpi_video_bus_get_one_device(dev, video);
1694 if (ACPI_FAILURE(status)) {
Thomas Renningera6fc6722006-06-26 23:58:43 -04001695 ACPI_EXCEPTION((AE_INFO, status, "Cant attach device"));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001696 continue;
1697 }
1698
1699 }
Patrick Mocheld550d982006-06-27 00:41:40 -04001700 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001701}
1702
Len Brown4be44fc2005-08-05 00:44:28 -04001703static int acpi_video_bus_put_one_device(struct acpi_video_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001704{
Karol Kozimor031ec772005-07-30 04:18:00 -04001705 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001706 struct acpi_video_bus *video;
1707
Linus Torvalds1da177e2005-04-16 15:20:36 -07001708
1709 if (!device || !device->video)
Patrick Mocheld550d982006-06-27 00:41:40 -04001710 return -ENOENT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001711
1712 video = device->video;
1713
1714 down(&video->sem);
1715 list_del(&device->entry);
1716 up(&video->sem);
1717 acpi_video_device_remove_fs(device->dev);
1718
Patrick Mochel90130262006-05-19 16:54:48 -04001719 status = acpi_remove_notify_handler(device->dev->handle,
Len Brown4be44fc2005-08-05 00:44:28 -04001720 ACPI_DEVICE_NOTIFY,
1721 acpi_video_device_notify);
Richard Purdie599a52d2007-02-10 23:07:48 +00001722 backlight_device_unregister(device->backlight);
Luming Yu23b0f012007-05-09 21:07:05 +08001723 video_output_unregister(device->output_dev);
Patrick Mocheld550d982006-06-27 00:41:40 -04001724 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001725}
1726
Len Brown4be44fc2005-08-05 00:44:28 -04001727static int acpi_video_bus_put_devices(struct acpi_video_bus *video)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001728{
Len Brown4be44fc2005-08-05 00:44:28 -04001729 int status;
1730 struct list_head *node, *next;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001731
Linus Torvalds1da177e2005-04-16 15:20:36 -07001732
1733 list_for_each_safe(node, next, &video->video_device_list) {
Len Brown4be44fc2005-08-05 00:44:28 -04001734 struct acpi_video_device *data =
1735 list_entry(node, struct acpi_video_device, entry);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001736 if (!data)
1737 continue;
1738
1739 status = acpi_video_bus_put_one_device(data);
Len Brown4be44fc2005-08-05 00:44:28 -04001740 if (ACPI_FAILURE(status))
1741 printk(KERN_WARNING PREFIX
1742 "hhuuhhuu bug in acpi video driver.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001743
Dave Jonesd384ea62006-06-24 00:33:08 -04001744 if (data->brightness)
Yu, Luming973bf492006-04-27 05:25:00 -04001745 kfree(data->brightness->levels);
Jesper Juhl6044ec82005-11-07 01:01:32 -08001746 kfree(data->brightness);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001747 kfree(data);
1748 }
1749
Patrick Mocheld550d982006-06-27 00:41:40 -04001750 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001751}
1752
1753/* acpi_video interface */
1754
Len Brown4be44fc2005-08-05 00:44:28 -04001755static int acpi_video_bus_start_devices(struct acpi_video_bus *video)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001756{
1757 return acpi_video_bus_DOS(video, 1, 0);
1758}
1759
Len Brown4be44fc2005-08-05 00:44:28 -04001760static int acpi_video_bus_stop_devices(struct acpi_video_bus *video)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001761{
1762 return acpi_video_bus_DOS(video, 0, 1);
1763}
1764
Len Brown4be44fc2005-08-05 00:44:28 -04001765static void acpi_video_bus_notify(acpi_handle handle, u32 event, void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001766{
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001767 struct acpi_video_bus *video = data;
Len Brown4be44fc2005-08-05 00:44:28 -04001768 struct acpi_device *device = NULL;
Luming Yue9dab192007-08-20 18:23:53 +08001769 struct input_dev *input;
1770 int keycode;
1771
Linus Torvalds1da177e2005-04-16 15:20:36 -07001772
Linus Torvalds1da177e2005-04-16 15:20:36 -07001773 printk("video bus notify\n");
1774
1775 if (!video)
Patrick Mocheld550d982006-06-27 00:41:40 -04001776 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001777
Patrick Mochele6afa0d2006-05-19 16:54:40 -04001778 device = video->device;
Luming Yue9dab192007-08-20 18:23:53 +08001779 input = video->input;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001780
1781 switch (event) {
Julius Volz98fb8fe2007-02-20 16:38:40 +01001782 case ACPI_VIDEO_NOTIFY_SWITCH: /* User requested a switch,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001783 * most likely via hotkey. */
Len Brown14e04fb32007-08-23 15:20:26 -04001784 acpi_bus_generate_proc_event(device, event, 0);
Luming Yue9dab192007-08-20 18:23:53 +08001785 keycode = KEY_SWITCHVIDEOMODE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001786 break;
1787
Julius Volz98fb8fe2007-02-20 16:38:40 +01001788 case ACPI_VIDEO_NOTIFY_PROBE: /* User plugged in or removed a video
Linus Torvalds1da177e2005-04-16 15:20:36 -07001789 * connector. */
1790 acpi_video_device_enumerate(video);
1791 acpi_video_device_rebind(video);
1792 acpi_video_switch_output(video, event);
Len Brown14e04fb32007-08-23 15:20:26 -04001793 acpi_bus_generate_proc_event(device, event, 0);
Luming Yue9dab192007-08-20 18:23:53 +08001794 keycode = KEY_SWITCHVIDEOMODE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001795 break;
1796
Len Brown4be44fc2005-08-05 00:44:28 -04001797 case ACPI_VIDEO_NOTIFY_CYCLE: /* Cycle Display output hotkey pressed. */
Luming Yue9dab192007-08-20 18:23:53 +08001798 acpi_video_switch_output(video, event);
Len Brown25c87f72007-08-25 01:44:01 -04001799 acpi_bus_generate_proc_event(device, event, 0);
Luming Yue9dab192007-08-20 18:23:53 +08001800 keycode = KEY_SWITCHVIDEOMODE;
1801 break;
Len Brown4be44fc2005-08-05 00:44:28 -04001802 case ACPI_VIDEO_NOTIFY_NEXT_OUTPUT: /* Next Display output hotkey pressed. */
Luming Yue9dab192007-08-20 18:23:53 +08001803 acpi_video_switch_output(video, event);
Len Brown25c87f72007-08-25 01:44:01 -04001804 acpi_bus_generate_proc_event(device, event, 0);
Luming Yue9dab192007-08-20 18:23:53 +08001805 keycode = KEY_VIDEO_NEXT;
1806 break;
Len Brown4be44fc2005-08-05 00:44:28 -04001807 case ACPI_VIDEO_NOTIFY_PREV_OUTPUT: /* previous Display output hotkey pressed. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001808 acpi_video_switch_output(video, event);
Len Brown14e04fb32007-08-23 15:20:26 -04001809 acpi_bus_generate_proc_event(device, event, 0);
Luming Yue9dab192007-08-20 18:23:53 +08001810 keycode = KEY_VIDEO_PREV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001811 break;
1812
1813 default:
Luming Yue9dab192007-08-20 18:23:53 +08001814 keycode = KEY_UNKNOWN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001815 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
Len Brown4be44fc2005-08-05 00:44:28 -04001816 "Unsupported event [0x%x]\n", event));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001817 break;
1818 }
1819
Luming Yue9dab192007-08-20 18:23:53 +08001820 input_report_key(input, keycode, 1);
1821 input_sync(input);
1822 input_report_key(input, keycode, 0);
1823 input_sync(input);
1824
Patrick Mocheld550d982006-06-27 00:41:40 -04001825 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001826}
1827
Len Brown4be44fc2005-08-05 00:44:28 -04001828static void acpi_video_device_notify(acpi_handle handle, u32 event, void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001829{
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001830 struct acpi_video_device *video_device = data;
Len Brown4be44fc2005-08-05 00:44:28 -04001831 struct acpi_device *device = NULL;
Luming Yue9dab192007-08-20 18:23:53 +08001832 struct acpi_video_bus *bus;
1833 struct input_dev *input;
1834 int keycode;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001835
Linus Torvalds1da177e2005-04-16 15:20:36 -07001836 if (!video_device)
Patrick Mocheld550d982006-06-27 00:41:40 -04001837 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001838
Patrick Mochele6afa0d2006-05-19 16:54:40 -04001839 device = video_device->dev;
Luming Yue9dab192007-08-20 18:23:53 +08001840 bus = video_device->video;
1841 input = bus->input;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001842
1843 switch (event) {
Len Brown4be44fc2005-08-05 00:44:28 -04001844 case ACPI_VIDEO_NOTIFY_CYCLE_BRIGHTNESS: /* Cycle brightness */
Luming Yue9dab192007-08-20 18:23:53 +08001845 acpi_video_switch_brightness(video_device, event);
Len Brown25c87f72007-08-25 01:44:01 -04001846 acpi_bus_generate_proc_event(device, event, 0);
Luming Yue9dab192007-08-20 18:23:53 +08001847 keycode = KEY_BRIGHTNESS_CYCLE;
1848 break;
Len Brown4be44fc2005-08-05 00:44:28 -04001849 case ACPI_VIDEO_NOTIFY_INC_BRIGHTNESS: /* Increase brightness */
Luming Yue9dab192007-08-20 18:23:53 +08001850 acpi_video_switch_brightness(video_device, event);
Len Brown25c87f72007-08-25 01:44:01 -04001851 acpi_bus_generate_proc_event(device, event, 0);
Luming Yue9dab192007-08-20 18:23:53 +08001852 keycode = KEY_BRIGHTNESSUP;
1853 break;
Len Brown4be44fc2005-08-05 00:44:28 -04001854 case ACPI_VIDEO_NOTIFY_DEC_BRIGHTNESS: /* Decrease brightness */
Luming Yue9dab192007-08-20 18:23:53 +08001855 acpi_video_switch_brightness(video_device, event);
Len Brown25c87f72007-08-25 01:44:01 -04001856 acpi_bus_generate_proc_event(device, event, 0);
Luming Yue9dab192007-08-20 18:23:53 +08001857 keycode = KEY_BRIGHTNESSDOWN;
1858 break;
Len Brown4be44fc2005-08-05 00:44:28 -04001859 case ACPI_VIDEO_NOTIFY_ZERO_BRIGHTNESS: /* zero brightnesss */
Luming Yue9dab192007-08-20 18:23:53 +08001860 acpi_video_switch_brightness(video_device, event);
Len Brown25c87f72007-08-25 01:44:01 -04001861 acpi_bus_generate_proc_event(device, event, 0);
Luming Yue9dab192007-08-20 18:23:53 +08001862 keycode = KEY_BRIGHTNESS_ZERO;
1863 break;
Len Brown4be44fc2005-08-05 00:44:28 -04001864 case ACPI_VIDEO_NOTIFY_DISPLAY_OFF: /* display device off */
1865 acpi_video_switch_brightness(video_device, event);
Len Brown14e04fb32007-08-23 15:20:26 -04001866 acpi_bus_generate_proc_event(device, event, 0);
Luming Yue9dab192007-08-20 18:23:53 +08001867 keycode = KEY_DISPLAY_OFF;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001868 break;
1869 default:
Luming Yue9dab192007-08-20 18:23:53 +08001870 keycode = KEY_UNKNOWN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001871 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
Len Brown4be44fc2005-08-05 00:44:28 -04001872 "Unsupported event [0x%x]\n", event));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001873 break;
1874 }
Luming Yue9dab192007-08-20 18:23:53 +08001875
1876 input_report_key(input, keycode, 1);
1877 input_sync(input);
1878 input_report_key(input, keycode, 0);
1879 input_sync(input);
1880
Patrick Mocheld550d982006-06-27 00:41:40 -04001881 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001882}
1883
Zhang Ruie6d9da12007-08-25 02:23:31 -04001884static int instance;
Len Brown4be44fc2005-08-05 00:44:28 -04001885static int acpi_video_bus_add(struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001886{
Len Brown4be44fc2005-08-05 00:44:28 -04001887 int result = 0;
1888 acpi_status status = 0;
1889 struct acpi_video_bus *video = NULL;
Luming Yue9dab192007-08-20 18:23:53 +08001890 struct input_dev *input;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001891
Len Brown4be44fc2005-08-05 00:44:28 -04001892
Linus Torvalds1da177e2005-04-16 15:20:36 -07001893 if (!device)
Patrick Mocheld550d982006-06-27 00:41:40 -04001894 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001895
Burman Yan36bcbec2006-12-19 12:56:11 -08001896 video = kzalloc(sizeof(struct acpi_video_bus), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001897 if (!video)
Patrick Mocheld550d982006-06-27 00:41:40 -04001898 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001899
Zhang Ruie6d9da12007-08-25 02:23:31 -04001900 /* a hack to fix the duplicate name "VID" problem on T61 */
1901 if (!strcmp(device->pnp.bus_id, "VID")) {
1902 if (instance)
1903 device->pnp.bus_id[3] = '0' + instance;
1904 instance ++;
1905 }
1906
Patrick Mochele6afa0d2006-05-19 16:54:40 -04001907 video->device = device;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001908 strcpy(acpi_device_name(device), ACPI_VIDEO_BUS_NAME);
1909 strcpy(acpi_device_class(device), ACPI_VIDEO_CLASS);
1910 acpi_driver_data(device) = video;
1911
1912 acpi_video_bus_find_cap(video);
1913 result = acpi_video_bus_check(video);
1914 if (result)
1915 goto end;
1916
1917 result = acpi_video_bus_add_fs(device);
1918 if (result)
1919 goto end;
1920
1921 init_MUTEX(&video->sem);
1922 INIT_LIST_HEAD(&video->video_device_list);
1923
1924 acpi_video_bus_get_devices(video, device);
1925 acpi_video_bus_start_devices(video);
1926
Patrick Mochel90130262006-05-19 16:54:48 -04001927 status = acpi_install_notify_handler(device->handle,
Len Brown4be44fc2005-08-05 00:44:28 -04001928 ACPI_DEVICE_NOTIFY,
1929 acpi_video_bus_notify, video);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001930 if (ACPI_FAILURE(status)) {
1931 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
Len Brown4be44fc2005-08-05 00:44:28 -04001932 "Error installing notify handler\n"));
Yu, Luming973bf492006-04-27 05:25:00 -04001933 acpi_video_bus_stop_devices(video);
1934 acpi_video_bus_put_devices(video);
1935 kfree(video->attached_array);
1936 acpi_video_bus_remove_fs(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001937 result = -ENODEV;
1938 goto end;
1939 }
1940
Luming Yue9dab192007-08-20 18:23:53 +08001941
1942 video->input = input = input_allocate_device();
1943
1944 snprintf(video->phys, sizeof(video->phys),
1945 "%s/video/input0", acpi_device_hid(video->device));
1946
1947 input->name = acpi_device_name(video->device);
1948 input->phys = video->phys;
1949 input->id.bustype = BUS_HOST;
1950 input->id.product = 0x06;
1951 input->evbit[0] = BIT(EV_KEY);
1952 set_bit(KEY_SWITCHVIDEOMODE, input->keybit);
1953 set_bit(KEY_VIDEO_NEXT, input->keybit);
1954 set_bit(KEY_VIDEO_PREV, input->keybit);
1955 set_bit(KEY_BRIGHTNESS_CYCLE, input->keybit);
1956 set_bit(KEY_BRIGHTNESSUP, input->keybit);
1957 set_bit(KEY_BRIGHTNESSDOWN, input->keybit);
1958 set_bit(KEY_BRIGHTNESS_ZERO, input->keybit);
1959 set_bit(KEY_DISPLAY_OFF, input->keybit);
1960 set_bit(KEY_UNKNOWN, input->keybit);
1961 result = input_register_device(input);
1962 if (result) {
1963 acpi_remove_notify_handler(video->device->handle,
1964 ACPI_DEVICE_NOTIFY,
1965 acpi_video_bus_notify);
1966 acpi_video_bus_stop_devices(video);
1967 acpi_video_bus_put_devices(video);
1968 kfree(video->attached_array);
1969 acpi_video_bus_remove_fs(device);
1970 goto end;
1971 }
1972
1973
Linus Torvalds1da177e2005-04-16 15:20:36 -07001974 printk(KERN_INFO PREFIX "%s [%s] (multi-head: %s rom: %s post: %s)\n",
Len Brown4be44fc2005-08-05 00:44:28 -04001975 ACPI_VIDEO_DEVICE_NAME, acpi_device_bid(device),
1976 video->flags.multihead ? "yes" : "no",
1977 video->flags.rom ? "yes" : "no",
1978 video->flags.post ? "yes" : "no");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001979
Len Brown4be44fc2005-08-05 00:44:28 -04001980 end:
Yu, Luming973bf492006-04-27 05:25:00 -04001981 if (result)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001982 kfree(video);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001983
Patrick Mocheld550d982006-06-27 00:41:40 -04001984 return result;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001985}
1986
Len Brown4be44fc2005-08-05 00:44:28 -04001987static int acpi_video_bus_remove(struct acpi_device *device, int type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001988{
Len Brown4be44fc2005-08-05 00:44:28 -04001989 acpi_status status = 0;
1990 struct acpi_video_bus *video = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001991
Linus Torvalds1da177e2005-04-16 15:20:36 -07001992
1993 if (!device || !acpi_driver_data(device))
Patrick Mocheld550d982006-06-27 00:41:40 -04001994 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001995
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001996 video = acpi_driver_data(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001997
1998 acpi_video_bus_stop_devices(video);
1999
Patrick Mochel90130262006-05-19 16:54:48 -04002000 status = acpi_remove_notify_handler(video->device->handle,
Len Brown4be44fc2005-08-05 00:44:28 -04002001 ACPI_DEVICE_NOTIFY,
2002 acpi_video_bus_notify);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002003
2004 acpi_video_bus_put_devices(video);
2005 acpi_video_bus_remove_fs(device);
2006
Luming Yue9dab192007-08-20 18:23:53 +08002007 input_unregister_device(video->input);
Jesper Juhl6044ec82005-11-07 01:01:32 -08002008 kfree(video->attached_array);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002009 kfree(video);
2010
Patrick Mocheld550d982006-06-27 00:41:40 -04002011 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002012}
2013
Len Brown4be44fc2005-08-05 00:44:28 -04002014static int __init acpi_video_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002015{
Len Brown4be44fc2005-08-05 00:44:28 -04002016 int result = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002017
Linus Torvalds1da177e2005-04-16 15:20:36 -07002018
2019 /*
Len Brown4be44fc2005-08-05 00:44:28 -04002020 acpi_dbg_level = 0xFFFFFFFF;
2021 acpi_dbg_layer = 0x08000000;
2022 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002023
2024 acpi_video_dir = proc_mkdir(ACPI_VIDEO_CLASS, acpi_root_dir);
2025 if (!acpi_video_dir)
Patrick Mocheld550d982006-06-27 00:41:40 -04002026 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002027 acpi_video_dir->owner = THIS_MODULE;
2028
2029 result = acpi_bus_register_driver(&acpi_video_bus);
2030 if (result < 0) {
2031 remove_proc_entry(ACPI_VIDEO_CLASS, acpi_root_dir);
Patrick Mocheld550d982006-06-27 00:41:40 -04002032 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002033 }
2034
Patrick Mocheld550d982006-06-27 00:41:40 -04002035 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002036}
2037
Len Brown4be44fc2005-08-05 00:44:28 -04002038static void __exit acpi_video_exit(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002039{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002040
2041 acpi_bus_unregister_driver(&acpi_video_bus);
2042
2043 remove_proc_entry(ACPI_VIDEO_CLASS, acpi_root_dir);
2044
Patrick Mocheld550d982006-06-27 00:41:40 -04002045 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002046}
2047
2048module_init(acpi_video_init);
2049module_exit(acpi_video_exit);